Salome HOME
PAL10125 - by double click on reference original object becomes selected
[modules/gui.git] / src / GLViewer / GLViewer_Context.h
1 // File:      GLViewer_Context.h
2 // Created:   November, 2004
3 // Author:    OCC team
4 // Copyright (C) CEA 2004
5
6
7 /*! Class GLViewer_Context
8  *  Class for manage of presentations in GLViewer
9  */
10
11 #ifndef GLVIEWER_CONTEXT_H
12 #define GLVIEWER_CONTEXT_H
13
14 #ifdef WNT
15 #include "windows.h"
16 #endif
17
18 #include "GLViewer_Defs.h"
19 #include "GLViewer_Object.h"
20
21 #include <qrect.h>
22 #include <qobject.h>
23 #include <qregion.h>
24
25 #include <Quantity_NameOfColor.hxx>
26 #include <Quantity_Color.hxx>
27
28 #include <GL/gl.h>
29
30 class GLViewer_Viewer2d;
31
32 #ifdef WNT
33 #pragma warning( disable:4251 )
34 #endif
35
36 class GLVIEWER_API GLViewer_Context
37 {
38 public:
39   //! A constructor
40   GLViewer_Context( GLViewer_Viewer2d* );
41   //! A desructor
42   ~GLViewer_Context();
43
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; }
48
49   //! Main interactive method. Trace mouse in viewer window
50   /*!
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
55   */
56   int                   MoveTo( int x, int y, bool byCircle = FALSE );
57   //! A function selecting already highlighting object by calling object method select
58   /*!
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
61   */
62   int                   Select( bool Append = FALSE, bool byCircle = FALSE );
63   //! A function selecting objects on scene by rectangle
64   /*!
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
68   */
69   int                   SelectByRect( const QRect& theRect, bool Append = FALSE );
70
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; } 
79
80   //! Returns number of objects in current selection
81   int                   NbSelected();
82   //! A function set iterator of selected objects on first object
83   void                  InitSelected();
84   //! Retuns true if iterator of selected objects is not set on last object
85   bool                  MoreSelected();
86   //! Increment of iterator of selected objects 
87   bool                  NextSelected();
88   //! Returns object corresponding the current iterator of selected objects 
89   GLViewer_Object*      SelectedObject();
90
91   //! Returns true if theObject is selected
92   bool                  isSelected( GLViewer_Object* theObject );
93
94   //! Insert new object in context
95   /*!
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
99   */
100   int                   insertObject( GLViewer_Object* theObject, bool display = false, bool isActive = true );
101   //! Replacing objects in context
102   /*!
103   * Function search activ and incative objects
104   */
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; }
110
111   //! Returns list of context objects
112   /*!
113   * Returns active objects if isActive = true, else inactive objects
114   */
115   const ObjList&        getObjects( bool isActive = true )
116                         { return isActive ? myActiveObjects : myInactiveObjects; }
117
118   //! Returns first active object
119   GLViewer_Object*      getFirstObject() { return *( myActiveObjects.begin() ); }
120
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 );
129
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; }
134
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 );
139
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 );
144
145 protected:
146   //! Flag of updating viewer after highlight
147   /*!
148   * if = true, the viewer update all objects after change of highlight object,
149   * else - only highlight object
150   */
151   bool                  myUpdateAll;
152
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;
158
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;
165
166   //! List of selected objects
167   ObjList               mySelectedObjects;
168   //! Selected object iterator
169   int                   mySelCurIndex;
170
171   //! X coordinate of mouse cursor
172   GLfloat               myXhigh;
173   //! Y coordinate of mouse cursor
174   GLfloat               myYhigh;
175
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
181   GLboolean             myHFlag;
182   //! If = false - select method is not any select
183   GLboolean             mySFlag;
184   //! Tolerance in window pixels for highlghting and selection methods
185   int                   myTolerance;
186 };
187
188 #ifdef WNT
189 #pragma warning ( default:4251 )
190 #endif
191
192 #endif