Salome HOME
Merge branch V7_3_1_BR
[modules/gui.git] / src / GLViewer / GLViewer_Context.h
1 // Copyright (C) 2007-2014  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 #include <GL/gl.h>
43
44 class GLViewer_Viewer2d;
45
46 #ifdef WIN32
47 #pragma warning( disable:4251 )
48 #endif
49
50 /*! \class GLViewer_Context
51  *  Class for manage of presentations in GLViewer
52  */
53 class GLVIEWER_API GLViewer_Context
54 {
55 public:
56   //! A constructor
57   GLViewer_Context( GLViewer_Viewer2d* );
58   //! A desructor
59   ~GLViewer_Context();
60
61   //! A function installing update flag in highlighting technology
62   void                  setUpdateAll( bool on ) { myUpdateAll = on; }
63   //! Returns update flag in highlighting technology
64   bool                  isUpdateAll() const { return myUpdateAll; }
65
66   //! Main interactive method. Trace mouse in viewer window
67   /*!
68   *\param x - X coord of mouse cursor
69   *\param y - Y coord of mouse cursor
70   *\paran byCircle - true if needs round sensitive area around mouse cursor, else rectangle
71   *function search object rectangle which intersect with sensitive area and call object highlight method
72   */
73   int                   MoveTo( int x, int y, bool byCircle = FALSE );
74   /*! A function selecting already highlighting object by calling object method select
75   *\param Append - true if new selection will be append to existing selection, false - another
76   *\param byCircle - true if needs round selection area in complex object
77   */
78   int                   Select( bool Append = FALSE, bool byCircle = FALSE );
79   /*! A function selecting objects on scene by rectangle
80   *\param theRect - rectangle of selection
81   *\param Append - true if new selection will be append to existing selection, false - another
82   *function search object rectangle which intersect with theRect and call object select method
83   */
84   int                   SelectByRect( const QRect& theRect, bool Append = FALSE );
85
86   //! A function installing highlight color for all presentation (does not work)
87   void                  SetHighlightColor( Quantity_NameOfColor aCol );
88   //! A function installing select color for all presentation (does not work)
89   void                  SetSelectionColor( Quantity_NameOfColor aCol );
90   //! Returns highlight color
91   Quantity_NameOfColor  HighlightColor() { return myHighlightColor; }
92   //! Returns select color
93   Quantity_NameOfColor  SelectionColor() { return mySelectionColor; } 
94
95   //! Returns number of objects in current selection
96   int                   NbSelected();
97   //! A function set iterator of selected objects on first object
98   void                  InitSelected();
99   //! Retuns true if iterator of selected objects is not set on last object
100   bool                  MoreSelected();
101   //! Increment of iterator of selected objects 
102   bool                  NextSelected();
103   //! Returns object corresponding the current iterator of selected objects 
104   GLViewer_Object*      SelectedObject();
105
106   //! Returns true if theObject is selected
107   bool                  isSelected( GLViewer_Object* theObject );
108
109   //! Insert new object in context
110   /*!
111   *\param theObject - inserting object
112   *\param display - true if needs display object immediatly after inserting, else false
113   *\param isActive - true if needs inserting object in active list
114   */
115   int                   insertObject( GLViewer_Object* theObject, bool display = false, bool isActive = true );
116   //! Replacing objects in context
117   /*!
118   * Function search active and incative objects
119   */
120   bool                  replaceObject( GLViewer_Object* oldObject, GLViewer_Object* newObject );
121   //! A function updating scales of all objects in context
122   void                  updateScales( GLfloat theX, GLfloat theY );
123   //! A function installing tolerance in window pixels for highlghting and selection methods
124   void                  setTolerance( int tol ) { myTolerance = tol; }
125
126   //! Returns list of context objects
127   /*!
128   * \return active objects if isActive = true, else inactive objects
129   */
130   const ObjList&        getObjects( bool isActive = true )
131                         { return isActive ? myActiveObjects : myInactiveObjects; }
132
133   //! Returns first active object
134   GLViewer_Object*      getFirstObject() { return *( myActiveObjects.begin() ); }
135
136   //! A function clear highlighted object information
137   void                  clearHighlighted( bool updateViewer );
138   //! A function clear selection object information
139   void                  clearSelected( bool updateViewer );
140   //! A function make theObject as selected object and update viewer if updateViewer = true
141   void                  setSelected( GLViewer_Object* theObject, bool updateViewer );
142   //! A function make theObject as unselected object and update viewer if updateViewer = true
143   void                  remSelected( GLViewer_Object* theObject, bool updateViewer );
144
145   //! Returns highlighted object
146   GLViewer_Object*      getCurrentObject() { return myLastPicked; }
147   //! Returns true if after last MoveTo method calling highlight object is changed
148   bool                  currentObjectIsChanged() { return myLastPickedChanged; }
149
150   //! A function installing to theObject invisible status and update viewer if updateViewer = true
151   void                  eraseObject( GLViewer_Object* theObject, bool updateViewer = true );
152   //! A function remove theObject from context and update viewer if updateViewer = true
153   void                  deleteObject( GLViewer_Object* theObject, bool updateViewer = true );
154
155   //! A function installing to theObject active status
156   bool                  setActive( GLViewer_Object* theObject );
157   //! A function installing to theObject inactive status
158   bool                  setInactive( GLViewer_Object* theObject );
159
160 protected:
161   //! Flag of updating viewer after highlight
162   /*!
163   * if = true, the viewer update all objects after change of highlight object,
164   * else - only highlight object
165   */
166   bool                  myUpdateAll;
167
168   GLViewer_Viewer2d*    myGLViewer2d;
169   //! Highlighted object
170   GLViewer_Object*      myLastPicked;
171   //! = true if after last MoveTo method calling highlight object is changed
172   bool                  myLastPickedChanged;
173
174   //! List of active object
175   /*!Active objects if consider in highlight and select methods*/
176   ObjList               myActiveObjects;
177   //! List of inactive object
178   /*!Active objects isn't consider in highlight and select methods*/
179   ObjList               myInactiveObjects;
180
181   //! List of selected objects
182   ObjList               mySelectedObjects;
183   //! Selected object iterator
184   int                   mySelCurIndex;
185
186   //! X coordinate of mouse cursor
187   GLfloat               myXhigh;
188   //! Y coordinate of mouse cursor
189   GLfloat               myYhigh;
190
191   //! Color for highlight
192   Quantity_NameOfColor  myHighlightColor;
193   //! Color for selection
194   Quantity_NameOfColor  mySelectionColor;
195   //! If = false - moveTo method is not any highlighting
196   GLboolean             myHFlag;
197   //! If = false - select method is not any select
198   GLboolean             mySFlag;
199   //! Tolerance in window pixels for highlghting and selection methods
200   int                   myTolerance;
201 };
202
203 #ifdef WIN32
204 #pragma warning ( default:4251 )
205 #endif
206
207 #endif