1 // File: GLViewer_Context.h
2 // Created: November, 2004
4 // Copyright (C) CEA 2004
7 /*! Class GLViewer_Context
8 * Class for manage of presentations in GLViewer
11 #ifndef GLVIEWER_CONTEXT_H
12 #define GLVIEWER_CONTEXT_H
18 #include "GLViewer_Defs.h"
19 #include "GLViewer_Object.h"
25 #include <Quantity_NameOfColor.hxx>
26 #include <Quantity_Color.hxx>
30 class GLViewer_Viewer2d;
33 #pragma warning( disable:4251 )
36 class GLVIEWER_API GLViewer_Context
40 GLViewer_Context( GLViewer_Viewer2d* );
44 //! A function installing update flag in highlighting technology
45 void setUpdateAll( bool on ) { myUpdateAll = on; }
46 //! Returns update flag in highlighting technology
47 bool isUpdateAll() const { return myUpdateAll; }
49 //! Main interactive method. Trace mouse in viewer window
51 *\param x - X coord of mouse cursor
52 *\param y - Y coord of mouse cursor
53 *\paran byCircle - true if needs round sensitive area around mouse cursor, else rectangle
54 *function search object rectangle which intersect with sensitive area and call object highlight method
56 int MoveTo( int x, int y, bool byCircle = FALSE );
57 //! A function selecting already highlighting object by calling object method select
59 *\param Append - true if new selection will be append to existing selection, false - another
60 *\param byCircle - true if needs round selection area in complex object
62 int Select( bool Append = FALSE, bool byCircle = FALSE );
63 //! A function selecting objects on scene by rectangle
65 *\param theRect - rectangle of selection
66 *\param Append - true if new selection will be append to existing selection, false - another
67 *function search object rectangle which intersect with theRect and call object select method
69 int SelectByRect( const QRect& theRect, bool Append = FALSE );
71 //! A function installing highlight color for all presentation (does not work)
72 void SetHighlightColor( Quantity_NameOfColor aCol );
73 //! A function installing select color for all presentation (does not work)
74 void SetSelectionColor( Quantity_NameOfColor aCol );
75 //! Returns highlight color
76 Quantity_NameOfColor HighlightColor() { return myHighlightColor; }
77 //! Returns select color
78 Quantity_NameOfColor SelectionColor() { return mySelectionColor; }
80 //! Returns number of objects in current selection
82 //! A function set iterator of selected objects on first object
84 //! Retuns true if iterator of selected objects is not set on last object
86 //! Increment of iterator of selected objects
88 //! Returns object corresponding the current iterator of selected objects
89 GLViewer_Object* SelectedObject();
91 //! Returns true if theObject is selected
92 bool isSelected( GLViewer_Object* theObject );
94 //! Insert new object in context
96 *\param theObject - inserting object
97 *\param display - true if needs display object immediatly after inserting, else false
98 *\param isActive - true if needs inserting object in active list
100 int insertObject( GLViewer_Object* theObject, bool display = false, bool isActive = true );
101 //! Replacing objects in context
103 * Function search activ and incative objects
105 bool replaceObject( GLViewer_Object* oldObject, GLViewer_Object* newObject );
106 //! A function updating scales of all objects in context
107 void updateScales( GLfloat theX, GLfloat theY );
108 //! A function installing tolerance in window pixels for highlghting and selection methods
109 void setTolerance( int tol ) { myTolerance = tol; }
111 //! Returns list of context objects
113 * Returns active objects if isActive = true, else inactive objects
115 const ObjList& getObjects( bool isActive = true )
116 { return isActive ? myActiveObjects : myInactiveObjects; }
118 //! Returns first active object
119 GLViewer_Object* getFirstObject() { return *( myActiveObjects.begin() ); }
121 //! A function clear highlighted object information
122 void clearHighlighted();
123 //! A function clear selection object information
124 void clearSelected( bool updateViewer );
125 //! A function make theObject as selected object and update viewer if updateViewer = true
126 void setSelected( GLViewer_Object* theObject, bool updateViewer );
127 //! A function make theObject as unselected object and update viewer if updateViewer = true
128 void remSelected( GLViewer_Object* theObject, bool updateViewer );
130 //! Returns highlighted object
131 GLViewer_Object* getCurrentObject() { return myLastPicked; }
132 //! Returns true if after last MoveTo method calling highlight object is changed
133 bool currentObjectIsChanged() { return myLastPickedChanged; }
135 //! A function installing to theObject invisible status and update viewer if updateViewer = true
136 void eraseObject( GLViewer_Object* theObject, bool updateViewer = true );
137 //! A function remove theObject from context and update viewer if updateViewer = true
138 void deleteObject( GLViewer_Object* theObject, bool updateViewer = true );
140 //! A function installing to theObject active status
141 bool setActive( GLViewer_Object* theObject );
142 //! A function installing to theObject inactive status
143 bool setInactive( GLViewer_Object* theObject );
146 //! Flag of updating viewer after highlight
148 * if = true, the viewer update all objects after change of highlight object,
149 * else - only highlight object
153 GLViewer_Viewer2d* myGLViewer2d;
154 //! Highlighted object
155 GLViewer_Object* myLastPicked;
156 //! = true if after last MoveTo method calling highlight object is changed
157 bool myLastPickedChanged;
159 //! List of active object
160 /*!Active objects if consider in highlight and select methods*/
161 ObjList myActiveObjects;
162 //! List of inactive object
163 /*!Active objects isn't consider in highlight and select methods*/
164 ObjList myInactiveObjects;
166 //! List of selected objects
167 ObjList mySelectedObjects;
168 //! Selected object iterator
171 //! X coordinate of mouse cursor
173 //! Y coordinate of mouse cursor
176 //! Color for highlight
177 Quantity_NameOfColor myHighlightColor;
178 //! Color for selection
179 Quantity_NameOfColor mySelectionColor;
180 //! If = false - moveTo method is not any highlighting
182 //! If = false - select method is not any select
184 //! Tolerance in window pixels for highlghting and selection methods
189 #pragma warning ( default:4251 )