Salome HOME
11a424a15d8311e903ee4d0834b05990aad43d3c
[modules/gui.git] / src / GLViewer / GLViewer_Context.h
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  Author : OPEN CASCADE
24 // File:      GLViewer_Context.h
25 // Created:   November, 2004
26 //
27 #ifndef GLVIEWER_CONTEXT_H
28 #define GLVIEWER_CONTEXT_H
29
30 #ifdef WIN32
31 #include "windows.h"
32 #endif
33
34 #include "GLViewer_Defs.h"
35 #include "GLViewer_Object.h"
36
37 class QRect;
38
39 #include <Quantity_NameOfColor.hxx>
40 #include <Quantity_Color.hxx>
41
42 #ifdef __APPLE__
43 #include <OpenGL/gl.h>
44 #else
45 #include <GL/gl.h>
46 #endif
47
48 class GLViewer_Viewer2d;
49
50 #ifdef WIN32
51 #pragma warning( disable:4251 )
52 #endif
53
54 /*! \class GLViewer_Context
55  *  Class for manage of presentations in GLViewer
56  */
57 class GLVIEWER_API GLViewer_Context
58 {
59 public:
60   //! A constructor
61   GLViewer_Context( GLViewer_Viewer2d* );
62   //! A desructor
63   ~GLViewer_Context();
64
65   //! A function installing update flag in highlighting technology
66   void                  setUpdateAll( bool on ) { myUpdateAll = on; }
67   //! Returns update flag in highlighting technology
68   bool                  isUpdateAll() const { return myUpdateAll; }
69
70   //! Main interactive method. Trace mouse in viewer window
71   /*!
72   *\param x - X coord of mouse cursor
73   *\param y - Y coord of mouse cursor
74   *\paran byCircle - true if needs round sensitive area around mouse cursor, else rectangle
75   *function search object rectangle which intersect with sensitive area and call object highlight method
76   */
77   int                   MoveTo( int x, int y, bool byCircle = false );
78   /*! A function selecting already highlighting object by calling object method select
79   *\param Append - true if new selection will be append to existing selection, false - another
80   *\param byCircle - true if needs round selection area in complex object
81   */
82   int                   Select( bool Append = false, bool byCircle = false );
83   /*! A function selecting objects on scene by rectangle
84   *\param theRect - rectangle of selection
85   *\param Append - true if new selection will be append to existing selection, false - another
86   *function search object rectangle which intersect with theRect and call object select method
87   */
88   int                   SelectByRect( const QRect& theRect, bool Append = false );
89
90   //! A function installing highlight color for all presentation (does not work)
91   void                  SetHighlightColor( Quantity_NameOfColor aCol );
92   //! A function installing select color for all presentation (does not work)
93   void                  SetSelectionColor( Quantity_NameOfColor aCol );
94   //! Returns highlight color
95   Quantity_NameOfColor  HighlightColor() { return myHighlightColor; }
96   //! Returns select color
97   Quantity_NameOfColor  SelectionColor() { return mySelectionColor; } 
98
99   //! Returns number of objects in current selection
100   int                   NbSelected();
101   //! A function set iterator of selected objects on first object
102   void                  InitSelected();
103   //! Retuns true if iterator of selected objects is not set on last object
104   bool                  MoreSelected();
105   //! Increment of iterator of selected objects 
106   bool                  NextSelected();
107   //! Returns object corresponding the current iterator of selected objects 
108   GLViewer_Object*      SelectedObject();
109
110   //! Returns true if theObject is selected
111   bool                  isSelected( GLViewer_Object* theObject );
112
113   //! Insert new object in context
114   /*!
115   *\param theObject - inserting object
116   *\param display - true if needs display object immediatly after inserting, else false
117   *\param isActive - true if needs inserting object in active list
118   */
119   int                   insertObject( GLViewer_Object* theObject, bool display = false, bool isActive = true );
120   //! Replacing objects in context
121   /*!
122   * Function search active and incative objects
123   */
124   bool                  replaceObject( GLViewer_Object* oldObject, GLViewer_Object* newObject );
125   //! A function updating scales of all objects in context
126   void                  updateScales( GLfloat theX, GLfloat theY );
127   //! A function installing tolerance in window pixels for highlghting and selection methods
128   void                  setTolerance( int tol ) { myTolerance = tol; }
129
130   //! Returns list of context objects
131   /*!
132   * \return active objects if isActive = true, else inactive objects
133   */
134   const ObjList&        getObjects( bool isActive = true )
135                         { return isActive ? myActiveObjects : myInactiveObjects; }
136
137   //! Returns first active object
138   GLViewer_Object*      getFirstObject() { return *( myActiveObjects.begin() ); }
139
140   //! A function clear highlighted object information
141   void                  clearHighlighted( bool updateViewer );
142   //! A function clear selection object information
143   void                  clearSelected( bool updateViewer );
144   //! A function make theObject as selected object and update viewer if updateViewer = true
145   void                  setSelected( GLViewer_Object* theObject, bool updateViewer );
146   //! A function make theObject as unselected object and update viewer if updateViewer = true
147   void                  remSelected( GLViewer_Object* theObject, bool updateViewer );
148
149   //! Returns highlighted object
150   GLViewer_Object*      getCurrentObject() { return myLastPicked; }
151   //! Returns true if after last MoveTo method calling highlight object is changed
152   bool                  currentObjectIsChanged() { return myLastPickedChanged; }
153
154   //! A function installing to theObject invisible status and update viewer if updateViewer = true
155   void                  eraseObject( GLViewer_Object* theObject, bool updateViewer = true );
156   //! A function remove theObject from context and update viewer if updateViewer = true
157   void                  deleteObject( GLViewer_Object* theObject, bool updateViewer = true );
158
159   //! A function installing to theObject active status
160   bool                  setActive( GLViewer_Object* theObject );
161   //! A function installing to theObject inactive status
162   bool                  setInactive( GLViewer_Object* theObject );
163
164 protected:
165   //! Flag of updating viewer after highlight
166   /*!
167   * if = true, the viewer update all objects after change of highlight object,
168   * else - only highlight object
169   */
170   bool                  myUpdateAll;
171
172   GLViewer_Viewer2d*    myGLViewer2d;
173   //! Highlighted object
174   GLViewer_Object*      myLastPicked;
175   //! = true if after last MoveTo method calling highlight object is changed
176   bool                  myLastPickedChanged;
177
178   //! List of active object
179   /*!Active objects if consider in highlight and select methods*/
180   ObjList               myActiveObjects;
181   //! List of inactive object
182   /*!Active objects isn't consider in highlight and select methods*/
183   ObjList               myInactiveObjects;
184
185   //! List of selected objects
186   ObjList               mySelectedObjects;
187   //! Selected object iterator
188   int                   mySelCurIndex;
189
190   //! X coordinate of mouse cursor
191   GLfloat               myXhigh;
192   //! Y coordinate of mouse cursor
193   GLfloat               myYhigh;
194
195   //! Color for highlight
196   Quantity_NameOfColor  myHighlightColor;
197   //! Color for selection
198   Quantity_NameOfColor  mySelectionColor;
199   //! If = false - moveTo method is not any highlighting
200   GLboolean             myHFlag;
201   //! If = false - select method is not any select
202   GLboolean             mySFlag;
203   //! Tolerance in window pixels for highlghting and selection methods
204   int                   myTolerance;
205 };
206
207 #ifdef WIN32
208 #pragma warning ( default:4251 )
209 #endif
210
211 #endif