Viewers - Creating graphic objects


Inheriting from Graphics

All graphic objects inherit from the Graphic2D or Graphic3D base classes. They provide the minimum attributes and methods to interact with scenes and viewers. All graphics are created in a scene that is given as a constructor parameter. If no pointer to a scene is given (default null pointer), a default scene is constructed that holds the graphical object.

To automatically set the viewing parameters, the viewer needs to know the center and the radius of the displayed sceen. They are computed from the center and radius of all graphic objects in the scene. The two methods virtual Vec getCenter() const and virtual double getRadius(const Vec& center) const defined in Graphics should be overloaded by the user to return the object center and radius when definning a new graphic class.

There is a notion of a selected object. The user can select a graphic object by setting the viewer "selection mode" and left-clicking near the object. To determine the clicked object, the viewer needs to now the distance between the clicked point and each scene object. This is the duty of the virtual double Graphics::getDistance(const Vec&) const method that should be overloaded. Finally, the selected object might be translated, rotated, and/or rescaled by setting the viewer "object mode". This is the purpose of the virtual void translate(const Vec&), virtual void rotate(const Rotation3&), and virtual void rescale(double) methods that may also be overriden.

The Frame2D and Frame3D classses are provided as 2D and 3D graphic object examples. They represent a 2D frame (x and y axis), and 3D frame (x, y, and z axis) that can be displayed in 2D or 3D viewers.

Viewers and selected objects

When an object is selected in a viewer, you may want to modify the interface accordingly (adding object-specific menu...). In fact, upon object selection, 3 methods of the Graphics object are called:

Each of these function are defined by default: no information function is called, no controls are created and a single menu that allow to detroy the object is created. The user should redefine these function only if he needs to add some object specific informations. Whether the menus, controls and inform1ation are actually displayed depend on the kind of viewer available. A FrameViewer (and its derivatives) own a menu bar and will display object menus. A BaseViewer cannot.

When creating object specific menus, the user should assign them IDs starting from the FrameViewer::freeId integer value. Whenever a menu item is selected, the void Graphics::menuCommand(wxCommandEvent&) get called and the menu ID may be retrieved from the wxCommandEvent parameter. When the menu is posted (i.e. the user click on the menu button to make it appear), the void Graphics::OnMenuHighlight(wxMenuEvent&) method is called to allow menu initialization before it actually appear on the screen. The void Graphics::menuCommand(wxCommandEvent&) function is defined for all graphical objects since a default menu is provided. You can see it for an example, and overload it in your own objects.


Classes documentation