Navigation: Up, Table of Contents, Bibliography, Index, Title Page

Geometry Windows

Definition

An instance of data type GeoWin is an editor for sets of geometric objects. It can be used for the visualization of result and progression of geometric algorithms.

GeoWin manages the geometric objects in so called scenes. A scene contains a container storing geometric objects (the contents of the scene) and provides all operations that GeoWin needs to edit it. Every scene maintains a set of parameters:

There are three kinds of scenes:

  1. Basic scene

    The basic scene type GeoBaseScene<T> works on every container type that provides an interface as the list of the STL library. More precisely, T has to support the following type definitions and operations:

    That means, that LEDA lists can be used as well as containers.

  2. Edit scene

    A scene of type GeoEditScene<T> is a user editable scene. GeoWin is an editor for this kind of containers.

  3. Result scene

    A scene of type GeoResultScene<I,R> is not independently editable. Instead its contents (a container of type R) is computed by a user defined update function or update object with an update function. The update function computes the contents of the result scene every time when another scene (the input scene for the result scene) changes. The update function

    void (*f_update)(const I& input, R& result)

    gets the contents of this input scene (a container input of type I) and computes the contents result of the result scene. We say that the result scene depends on its input scene.

Both Edit and Result scenes are derived from Basic scenes. The geometric objects stored in the containers of the scenes have to support input and output operators for IO-streams and the LEDA window and the output operator to the LEDA class ps_file for Postscript output. Please note that the type geo_scene is the scene item type used in GeoWin. It is a pointer to the base class of all scene types.

Creation

GeoWin gw ( const char* label = "GEOWIN");
creates a GeoWin gw with frame label label.


GeoWin gw ( double x, double y, const char* label = "GEOWIN");
creates a GeoWin gw. gw is constructed with frame label label and physical size x × y.

Operations



a) Main Operations

The new_scene and get_objects operations use member templates. If your compiler does not support member templates, you should use the function templates geowin_new_scene and geowin_get_objects with gw as an additional first parameter.

The following new_scene operation can be used to create edit scenes. The CONTAINER has to be a list<T> (where T is the type of your geometric objects) and must be registered in GeoWin (see Registration of types).

template<class CONTAINER>
geo_scene gw.new_scene ( CONTAINER& c)
creates a new edit scene for c. c will be edited by gw .



The following new_scene operations can be used to create result scenes. Result scenes use the contents of another scene (the input scene) as the input for a function (the update function). This function computes the contents of the result scene. The update function is called every time when the contents of the input scene changes. Instead of using an update function you can use an update object that encapsulates an update function. The type of this update object has to be geowin_update<I,R> (I - type of the container in the input scene, R - type of the container in the result scene) or a class derived from it. A derived class should overwrite the virtual update function

void update(const I& in,R& out)

of the base class to provide a user defined update function. The class geowin_update<I,R> has 3 constructors getting function pointers as arguments:

  1. geowin_update(void (*f)(const I& in, R& res)

  2. geowin_update(void (*f)(const I& in, R::value_type& obj)

  3. geowin_update(R::value_type (*f)(const I& in)

These functions will be called in the update function of the update object. The first is the normal update function that gets the contents in of the input scene and computes the contents res of the output scene. In the second variant the contents of the result scene will first be cleared, then the update function will be called and obj will be inserted in the result scene. In the third variant the contents of the result scene will be cleared, and then the object returned by the update function will be inserted in the result scene.

It is also possible to provide user defined redraw for a scene. For this purpose we use redraw objects derived from class geowin_redraw . The derived class has to overwrite the virtual redraw function

void draw(leda_window& W,leda_color c1,leda_color c2,double x1,double y1,double x2,double y2)

of the base class to provide a user defined redraw function. The first three parameters of this function are the redraw window and the first and second drawing color (color and color2) of the scene. If you want user defined postscript output, the derived class has to overwrite the virtual function

bool write_postscript(ps_file& PS,leda_color c1,leda_color c2)

of the base class. The first parameter of this function is the output Postscript file (see Manual/contrib in your LEDA distribution for a documentation of the ps_file class), the other parameters are the first and second drawing color (color and color2) of the scene. The function has to return false, if the contents of the scene should be drawn to the Postscript output file too, true otherwise.

In the following member-templates I and R have to be a list<T>, where T is the type of your geometric objects. I is the type of the contents of the input scene, R the type of the contents of the created result scene.

template<class I, class R>
geo_scene
gw.new_scene ( F f_update,
geo_scene sc,
leda_string str)
where F is the type void (*)(const I&, R&), creates a new result scene with name str. The input scene for this new result scene will be sc. The update function will be f_update . Note that this member-template does not work with Visual C++. You should use there one of the other member templates for creating result scenes.

template<class I,class R>
geo_scene
gw.new_scene ( geowin_update<I,R>& up,
geo_scene sc_input,
leda_string str)
creates a new result scene with name str. The input scene for this new result scene will be sc_input. The update object will be up.

template<class I,class R>
geo_scene
gw.new_scene ( geowin_update<I,R>& up,
geowin_redraw& rd,
geo_scene sc_input,
leda_string str)
creates a new result scene with name str. The input scene for this new result scene will be sc_input. The update object will be up. The redraw object will be rd.

template<class CONTAINER>
bool gw.get_objects ( geo_scene sc, CONTAINER& c)
If the contents of scene sc matches type CONTAINER, then the contents of scene sc is copied to c.

void gw.edit () starts the interactive mode of gw . The operation returns if either the Done or Quit button was pressed.

bool gw.edit ( geo_scene sc)
edits scene sc. Returns false when the Quit Button was pressed, true otherwise. Precondition: sc must be an edit scene.



b) Window Operations

void gw.close () closes gw .

double gw.get_xmin () returns the minimal x-coordinate of the drawing area.

double gw.get_ymin () returns the minimal y-coordinate of the drawing area.

double gw.get_xmax () returns the maximal x-coordinate of the drawing area.

double gw.get_ymax () returns the maximal y-coordinate of the drawing area.

void gw.display ( int x, int y)
opens gw at (x,y).

leda_window& gw.get_window () returns a reference to the drawing window.

void gw.init ( double xmin, double xmax, double ymin)
same as leda_window::init(xmin, xmax, ymin).

void
gw.init ( double x1,
double x2,
double y1,
double y2,
int r)
initializes the window so that the rectangle with lower left corner (x1-r,y1-r) and upper right corner (x2+r,y2+r) is visible at whole. The window must be open.

void gw.redraw () redraws the contents of gw (all visible scenes).

int gw.set_cursor ( int cursor_id = -1)
sets the mouse cursor to cursor_id.



c) Scene Operations

geo_scene gw.get_scene_with_name ( leda_string nm)
returns the scene named nm or nil if there is no scene named nm.

void gw.activate ( geo_scene sc)
makes scene sc the active scene of gw.

geo_scene gw.get_active_scene ()
returns the active scene of gw.

bool gw.is_active ( geo_scene sc)
returns true if sc is an active scene in a GeoWin.



The following get and set operations can be used for retrieving and changing scene parameters. All set operations return the previous value.

leda_string gw.get_name ( geo_scene sc)
returns the name of scene sc.

leda_string gw.set_name ( geo_scene sc, leda_string nm)
gives scene sc the name nm. If there is already a scene with name nm, another name is constructed based on nm and is given to sc. The operation will return the given name.

leda_color gw.get_color ( geo_scene sc)
returns the boundary drawing color of scene sc.

leda_color gw.set_color ( geo_scene sc, leda_color c)
sets the boundary drawing color of scene sc to c.

leda_color gw.get_selection_color ( geo_scene sc)
returns the second drawing color (used for selected boundaries) of scene sc.

leda_color gw.set_selection_color ( geo_scene sc, leda_color c)
sets the second drawing color of scene sc (used for selected boundaries) to c.

leda_color gw.get_fill_color ( geo_scene sc)
returns the fill color of sc.

leda_color gw.set_fill_color ( geo_scene sc, leda_color c)
sets the fill color of sc to c. Use color leda_invisible for disable filling.

int gw.get_line_width ( geo_scene sc)
returns the line width of sc.

int gw.get_active_line_width ( geo_scene sc)
returns the active line width of sc.

int gw.set_line_width ( geo_scene sc, int w)
sets the line width for scene sc to w.

int gw.set_active_line_width ( geo_scene sc, int w)
sets the active line width for scene sc to w.

leda_line_style gw.get_line_style ( geo_scene sc)
returns the line style of sc .

leda_line_style gw.set_line_style ( geo_scene sc, leda_line_style l)
sets the line style of scene sc to l.

bool gw.get_visible ( geo_scene sc)
returns the visible flag of scene sc.

bool gw.set_visible ( geo_scene sc, bool v)
sets the visible flag of scene sc to v.

void gw.set_all_visible ( bool v)
sets the visible flag of all scenes that are currently in gw to v.

leda_point_style gw.get_point_style ( geo_scene sc)
returns the point style of sc.

leda_point_style gw.set_point_style ( geo_scene sc, leda_point_style p)
sets the point style of sc to p.


begin of advanced section



The following operations can be used to set/get individual attributes of objects in scenes. All set operations return the previous value. The first parameter is the scene, where the object belongs to. The second parameter is a generic pointer to the object. Precondition: the object belongs to the scene (is in the container of the scene). Note that the following operations are member templates.

template<class T>
leda_color gw.get_obj_color ( GeoBaseScene<T>* sc, void* adr)
returns the boundary color of the object at (*adr).

template<class T>
leda_color
gw.set_obj_color ( GeoBaseScene<T>* sc,
void* adr,
leda_color c)
sets the boundary color of the object at (*adr) to c.

template<class T>
leda_color gw.get_obj_fill_color ( GeoBaseScene<T>* sc, void* adr)
returns the interior color of the object at (*adr).

template<class T>
leda_color
gw.set_obj_fill_color ( GeoBaseScene<T>* sc,
void* adr,
leda_color c)
sets the interior color of the object at (*adr) to c.

template<class T>
leda_line_style gw.get_obj_line_style ( GeoBaseScene<T>* sc, void* adr)
returns the line style of the object at (*adr).

template<class T>
leda_line_style
gw.set_obj_line_style ( GeoBaseScene<T>* sc,
void* adr,
leda_line_style l)
sets the line style of the object at (*adr) to l.


end of advanced section



d) Input and Output Operations

void gw.read ( geo_scene sc, istream& is)
reads the contents of sc from input stream is. The contents of sc is cleared before.

void gw.write ( geo_scene sc, ostream& os)
writes the contents of sc to output stream os.

void gw.write_active_scene ( ostream& os)
writes the contents of the active scene of gw to output stream os .



e) View Operations

void gw.zoom_up () The visible range is reduced to the half.

void gw.zoom_down () The visible range is doubled.

void gw.zoom_area () reads a rectangle from the drawing window and makes it the visible range.

void gw.fill_window () changes window coordinate system, so that the objects of the currently active scene fill the window.


begin of advanced section
leda_string gw.get_bg_pixmap ()
returns the name of the current background pixmap.

leda_string gw.set_bg_pixmap ( leda_string pix_name)
changes the window background pixmap to pixmap with name pix_name. For the names of supported pixmaps see /pixmaps in your LEDA include directory. The function returns the name of the previous background pixmap.

end of advanced section


begin of advanced section


f) Event Handling

gw provides operations for changing its default handling of events. As in the LEDA class GraphWin the user can define what action should follow a mouse or key event. Constants are defined as in the LEDA class GraphWin :

and can be combined with OR ( ).

void gw.set_action ( long mask, geo_action f=0)
Set action on condition mask to f. geo_action is a function of type void (*)(GeoWin&, const leda_point&) . For f == 0 the corresponding action is deleted.

geo_action gw.get_action ( long mask)
Get action defined for condition mask.

void gw.reset_actions ()
Set all actions to their default values.



Default values are defined as follows :

void gw.clear_actions ()
clears all actions.



Scene events

The following event handling functions can be set for edit scenes:

The add handlers will be called when a user tries to add an object to an edit scene in GeoWin, the delete handlers will be called when the user tries to delete an object and the change handlers will be called when the user tries to change an object (for instance by moving or rotating it). The templated set operations for setting handlers uses member templates. If your compiler does not support member templates, you should use instead the templated functions geowin_set_HANDLER, where HANDLER is one the following handlers. All handling functions get as the first parameter a reference to the GeoWin, where the scene belongs to.

template<class T,class F>
bool
gw.set_pre_add_handler ( GeoEditScene<T>* sc,
F handler)
sets the handler that is called before an object is added to (*sc). handler must have type bool (*handler)(GeoWin&, const T::value_type &). handler gets a reference to the added object. If handler returns false, the object will not be added to the scene.

template<class T,class F>
bool
gw.set_post_add_handler ( GeoEditScene<T>* sc,
F handler)
sets the handler that is called after an object is added to (*sc). handler must have type void (*handler)(GeoWin&, const T::value_type &). handler gets a reference to the added object.

template<class T,class F>
bool
gw.set_pre_del_handler ( GeoEditScene<T>* sc,
F handler)
sets the handler that is called before an object is deleted from (*sc). handler must have type bool (*handler)(GeoWin&, const T::value_type &). handler gets a reference to the added object. If handler returns true, the object will be deleted, if handler returns false, the object will not be deleted.

template<class T,class F>
bool
gw.set_post_del_handler ( GeoEditScene<T>* sc,
F handler)
sets the handler that is called after an object is deleted from (*sc). handler must have type void (*handler)(GeoWin&, const T::value_type &).

template<class T,class F>
bool
gw.set_start_change_handler ( GeoEditScene<T>* sc,
F handler)
sets the handler that is called when a geometric object from (*sc) starts changing (for instance when you move it or rotate it). handler must have type bool (*handler)(GeoWin&, const T::value_type &). The handler function gets a reference to the object.

template<class T,class F>
bool
gw.set_pre_move_handler ( GeoEditScene<T>* sc,
F handler)
sets the handler that is called before every move operation. handler must have type bool (*handler)(GeoWin&, const T::value_type &, double x, double y). The handler gets as the second parameter a reference to the object, as the third parameter and fourth parameter the move vector. If the handler returns true, the change operation will be executed, if the handler returns false, it will not be executed.

template<class T,class F>
bool
gw.set_post_move_handler ( GeoEditScene<T>* sc,
F handler)
sets the handler that is called after every move operation. handler must have type void (*handler)(GeoWin&, const T::value_type &, double x, double y). The handler gets as the second parameter a reference to the object, as the third parameter and fourth parameter the move vector.

template<class T,class F>
bool
gw.set_pre_rotate_handler ( GeoEditScene<T>* sc,
F handler)
sets the handler that is called before every rotate operation. handler must have type bool (*handler)(GeoWin&, const T::value_type &, double x, double y, double a). The handler gets as the second parameter a reference to the object, as the 3., 4. and 5. parameter the rotation parameters. If the handler returns true, the rotate operation will be executed, if the handler returns false, it will not be executed.

template<class T,class F>
bool
gw.set_post_rotate_handler ( GeoEditScene<T>* sc,
F handler)
sets the handler that is called after every rotate operation. handler must have type void (*handler)(GeoWin&, const T::value_type &, double x, double y, double a).

template<class T,class F>
bool
gw.set_end_change_handler ( GeoEditScene<T>* sc,
F handler)
sets the handler that is called when a geometric object from (*sc) ends changing. handler gets the object as the second parameter. handler must have type void (*handler)(GeoWin&, const T::value_type &).


end of advanced section



Generator functions: The following operation can be used to set a generator function for an edit scene. The operation uses member templates. If your compiler does not support member templates, you should use instead the templated function geowin_set_generate_fcn instead.

template<class T>
bool gw.set_generate_fcn ( GeoEditScene<T>* sc, F f)
(where F is the type void (*)(GeoWin& gw,T& L) ), sets the generator function for edit scene (*sc). The function f gets the GeoWin where (*sc) belongs to and a reference to the container L of (*sc). The function should write the generated objects to L.

void gw.set_quit_handler ( F f)
(where F is the type bool (*)(const GeoWin& gw) ), sets a handler function f that is called when the user clicks the quit menu button. f should return true for allowing quiting, false otherwise.

void gw.set_done_handler ( F f)
(where F is the type bool (*)(const GeoWin& gw) ), sets a handler function f that is called when the user clicks the done menu button. f should return true for allowing quiting, false otherwise.



g) Further Operations

void gw.add_dependence ( geo_scene sc1, geo_scene sc2)
makes scene sc2 dependent from sc1. That means that sc2 will be updated when the contents of sc1 changes.

void gw.del_dependence ( geo_scene sc1, geo_scene sc2)
deletes the dependence of scene sc2 from sc1.

void gw.set_frame_label ( const char* label)
makes label the frame label of gw.

double gw.version () returns the GeoWin version number.

void gw.message ( leda_string msg)
displays message msg on top of the drawing area. If msg is the empty string, a previously written message is deleted.

void gw.msg_open ( leda_string msg)
displays message msg in the message window of gw. If the message window is not open, it will be opened.

void gw.msg_close () closes the message window.

void gw.msg_clear () clears the message window.


begin of advanced section

void
gw.set_d3_fcn ( geo_scene sc,
void (*f)(geo_scene gs, leda_d3_window& W, GRAPH<leda_d3_point,int>& H))
sets a function for computing 3d output. The parameters of the function are the geo_scene for that it will be set and a function pointer. The function f will get the scene for that it was set, a reference to a LEDA d3_window that will be the output window and a parametrized LEDA GRAPH that will be used for visualization.


end of advanced section



gw can be pined at a point in the plane. As standard behavior it is defined that moves of geometric objects will be rotations around the pin point.

bool gw.get_pin_point ( leda_point& p)
returns the pin point in p if it is set.

void gw.set_pin_point ( leda_point p)
sets the pin point to p.

void gw.del_pin_point ()
deletes the pin point.

void gw.add_help_text ( leda_string name)
adds the help text contained in name.hlp with label name to the help menu of the main window. The file name.hlp must exist either in the current working directory or in $LEDAROOT/incl/Help. Note that this operation must be called before gw.display().



The templated add_user_call operation uses member templates. If your compiler does not support member templates, you should use the templated function geowin_add_user_call with gw as an additional first parameter.

template<class F>
void gw.add_user_call ( leda_string label, F f)
adds a menu item label to the "User" menu of gw.
The user defined function
geo_call(GeoWin& gw, F f, leda_string label) is called whenever this menu button was pressed. This menu definition has to be finished before gw is opened.


Next: Class declaration of geo_scene_traits<CONTAINER>
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The GALIA project. Jan 18, 2000.