Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/gui.git] / src / GLViewer / GLViewer_Context.h
1 //  Copyright (C) 2005 OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 //  Author : OPEN CASCADE
20 //
21
22 // File:      GLViewer_Context.h
23 // Created:   November, 2004
24
25
26 #ifndef GLVIEWER_CONTEXT_H
27 #define GLVIEWER_CONTEXT_H
28
29 #ifdef WNT
30 #include "windows.h"
31 #endif
32
33 #include "GLViewer_Defs.h"
34 #include "GLViewer_Object.h"
35
36 #include <qrect.h>
37 #include <qobject.h>
38 #include <qregion.h>
39
40 #include <Quantity_NameOfColor.hxx>
41 #include <Quantity_Color.hxx>
42
43 #include <GL/gl.h>
44
45 class GLViewer_Viewer2d;
46
47 #ifdef WNT
48 #pragma warning( disable:4251 )
49 #endif
50
51 /*! \class GLViewer_Context
52  *  Class for manage of presentations in GLViewer
53  */
54 class GLVIEWER_API GLViewer_Context
55 {
56 public:
57   //! A constructor
58   GLViewer_Context( GLViewer_Viewer2d* );
59   //! A desructor
60   ~GLViewer_Context();
61
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; }
66
67   //! Main interactive method. Trace mouse in viewer window
68   /*!
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
73   */
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
78   */
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
84   */
85   int                   SelectByRect( const QRect& theRect, bool Append = FALSE );
86
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; } 
95
96   //! Returns number of objects in current selection
97   int                   NbSelected();
98   //! A function set iterator of selected objects on first object
99   void                  InitSelected();
100   //! Retuns true if iterator of selected objects is not set on last object
101   bool                  MoreSelected();
102   //! Increment of iterator of selected objects 
103   bool                  NextSelected();
104   //! Returns object corresponding the current iterator of selected objects 
105   GLViewer_Object*      SelectedObject();
106
107   //! Returns true if theObject is selected
108   bool                  isSelected( GLViewer_Object* theObject );
109
110   //! Insert new object in context
111   /*!
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
115   */
116   int                   insertObject( GLViewer_Object* theObject, bool display = false, bool isActive = true );
117   //! Replacing objects in context
118   /*!
119   * Function search active and incative objects
120   */
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; }
126
127   //! Returns list of context objects
128   /*!
129   * \return active objects if isActive = true, else inactive objects
130   */
131   const ObjList&        getObjects( bool isActive = true )
132                         { return isActive ? myActiveObjects : myInactiveObjects; }
133
134   //! Returns first active object
135   GLViewer_Object*      getFirstObject() { return *( myActiveObjects.begin() ); }
136
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 );
145
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; }
150
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 );
155
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 );
160
161 protected:
162   //! Flag of updating viewer after highlight
163   /*!
164   * if = true, the viewer update all objects after change of highlight object,
165   * else - only highlight object
166   */
167   bool                  myUpdateAll;
168
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;
174
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;
181
182   //! List of selected objects
183   ObjList               mySelectedObjects;
184   //! Selected object iterator
185   int                   mySelCurIndex;
186
187   //! X coordinate of mouse cursor
188   GLfloat               myXhigh;
189   //! Y coordinate of mouse cursor
190   GLfloat               myYhigh;
191
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
197   GLboolean             myHFlag;
198   //! If = false - select method is not any select
199   GLboolean             mySFlag;
200   //! Tolerance in window pixels for highlghting and selection methods
201   int                   myTolerance;
202 };
203
204 #ifdef WNT
205 #pragma warning ( default:4251 )
206 #endif
207
208 #endif