1 // Copyright (C) 2005 OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19 // Author : OPEN CASCADE
22 // File: GLViewer_Context.h
23 // Created: November, 2004
26 #ifndef GLVIEWER_CONTEXT_H
27 #define GLVIEWER_CONTEXT_H
33 #include "GLViewer_Defs.h"
34 #include "GLViewer_Object.h"
40 #include <Quantity_NameOfColor.hxx>
41 #include <Quantity_Color.hxx>
45 class GLViewer_Viewer2d;
48 #pragma warning( disable:4251 )
51 /*! \class GLViewer_Context
52 * Class for manage of presentations in GLViewer
54 class GLVIEWER_API GLViewer_Context
58 GLViewer_Context( GLViewer_Viewer2d* );
62 //! A function installing update flag in highlighting technology
63 void setUpdateAll( bool on ) { myUpdateAll = on; }
64 //! Returns update flag in highlighting technology
65 bool isUpdateAll() const { return myUpdateAll; }
67 //! Main interactive method. Trace mouse in viewer window
69 *\param x - X coord of mouse cursor
70 *\param y - Y coord of mouse cursor
71 *\paran byCircle - true if needs round sensitive area around mouse cursor, else rectangle
72 *function search object rectangle which intersect with sensitive area and call object highlight method
74 int MoveTo( int x, int y, bool byCircle = FALSE );
75 /*! A function selecting already highlighting object by calling object method select
76 *\param Append - true if new selection will be append to existing selection, false - another
77 *\param byCircle - true if needs round selection area in complex object
79 int Select( bool Append = FALSE, bool byCircle = FALSE );
80 /*! A function selecting objects on scene by rectangle
81 *\param theRect - rectangle of selection
82 *\param Append - true if new selection will be append to existing selection, false - another
83 *function search object rectangle which intersect with theRect and call object select method
85 int SelectByRect( const QRect& theRect, bool Append = FALSE );
87 //! A function installing highlight color for all presentation (does not work)
88 void SetHighlightColor( Quantity_NameOfColor aCol );
89 //! A function installing select color for all presentation (does not work)
90 void SetSelectionColor( Quantity_NameOfColor aCol );
91 //! Returns highlight color
92 Quantity_NameOfColor HighlightColor() { return myHighlightColor; }
93 //! Returns select color
94 Quantity_NameOfColor SelectionColor() { return mySelectionColor; }
96 //! Returns number of objects in current selection
98 //! A function set iterator of selected objects on first object
100 //! Retuns true if iterator of selected objects is not set on last object
102 //! Increment of iterator of selected objects
104 //! Returns object corresponding the current iterator of selected objects
105 GLViewer_Object* SelectedObject();
107 //! Returns true if theObject is selected
108 bool isSelected( GLViewer_Object* theObject );
110 //! Insert new object in context
112 *\param theObject - inserting object
113 *\param display - true if needs display object immediatly after inserting, else false
114 *\param isActive - true if needs inserting object in active list
116 int insertObject( GLViewer_Object* theObject, bool display = false, bool isActive = true );
117 //! Replacing objects in context
119 * Function search active and incative objects
121 bool replaceObject( GLViewer_Object* oldObject, GLViewer_Object* newObject );
122 //! A function updating scales of all objects in context
123 void updateScales( GLfloat theX, GLfloat theY );
124 //! A function installing tolerance in window pixels for highlghting and selection methods
125 void setTolerance( int tol ) { myTolerance = tol; }
127 //! Returns list of context objects
129 * \return active objects if isActive = true, else inactive objects
131 const ObjList& getObjects( bool isActive = true )
132 { return isActive ? myActiveObjects : myInactiveObjects; }
134 //! Returns first active object
135 GLViewer_Object* getFirstObject() { return *( myActiveObjects.begin() ); }
137 //! A function clear highlighted object information
138 void clearHighlighted( bool updateViewer );
139 //! A function clear selection object information
140 void clearSelected( bool updateViewer );
141 //! A function make theObject as selected object and update viewer if updateViewer = true
142 void setSelected( GLViewer_Object* theObject, bool updateViewer );
143 //! A function make theObject as unselected object and update viewer if updateViewer = true
144 void remSelected( GLViewer_Object* theObject, bool updateViewer );
146 //! Returns highlighted object
147 GLViewer_Object* getCurrentObject() { return myLastPicked; }
148 //! Returns true if after last MoveTo method calling highlight object is changed
149 bool currentObjectIsChanged() { return myLastPickedChanged; }
151 //! A function installing to theObject invisible status and update viewer if updateViewer = true
152 void eraseObject( GLViewer_Object* theObject, bool updateViewer = true );
153 //! A function remove theObject from context and update viewer if updateViewer = true
154 void deleteObject( GLViewer_Object* theObject, bool updateViewer = true );
156 //! A function installing to theObject active status
157 bool setActive( GLViewer_Object* theObject );
158 //! A function installing to theObject inactive status
159 bool setInactive( GLViewer_Object* theObject );
162 //! Flag of updating viewer after highlight
164 * if = true, the viewer update all objects after change of highlight object,
165 * else - only highlight object
169 GLViewer_Viewer2d* myGLViewer2d;
170 //! Highlighted object
171 GLViewer_Object* myLastPicked;
172 //! = true if after last MoveTo method calling highlight object is changed
173 bool myLastPickedChanged;
175 //! List of active object
176 /*!Active objects if consider in highlight and select methods*/
177 ObjList myActiveObjects;
178 //! List of inactive object
179 /*!Active objects isn't consider in highlight and select methods*/
180 ObjList myInactiveObjects;
182 //! List of selected objects
183 ObjList mySelectedObjects;
184 //! Selected object iterator
187 //! X coordinate of mouse cursor
189 //! Y coordinate of mouse cursor
192 //! Color for highlight
193 Quantity_NameOfColor myHighlightColor;
194 //! Color for selection
195 Quantity_NameOfColor mySelectionColor;
196 //! If = false - moveTo method is not any highlighting
198 //! If = false - select method is not any select
200 //! Tolerance in window pixels for highlghting and selection methods
205 #pragma warning ( default:4251 )