0026203: Foundation Classes - provide method ::Swap() for NCollection_IndexedMap...
[occt.git] / src / NIS / NIS_View.hxx
1 // Created on: 2007-07-06
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef NIS_View_HeaderFile
17 #define NIS_View_HeaderFile
18
19 #include <Handle_NIS_InteractiveObject.hxx>
20 #include <V3d_View.hxx>
21 #include <Standard_DefineHandle.hxx>
22 #include <NCollection_List.hxx>
23 #include <NCollection_Vector.hxx>
24 #include <Bnd_B3f.hxx>
25 #include <TColStd_PackedMapOfInteger.hxx>
26 #include <gp_XY.hxx>
27
28 class NIS_InteractiveContext;
29 class gp_Ax1;
30
31 /**
32  * Manager of a single window with OpenGL context, used by one or more
33  * NIS_InteractiveContext instances.
34  * This class inherits V3d_View therefore its instances can be used
35  * to display any object that is normally handled by Graphic3d/V3d/AIS classes.
36  * Also the standard view operations: Pan, Rotate, Zoom, mouse API, etc. are
37  * supported due to this inheritance.<p>
38  * The new services added by this class is the visualisation of
39  * NIS_InteractiveObject (i.e., accommodation of NIS_InteractiveContext
40  * instances). This visualisation is done by the method MyCallback that is
41  * called just before redrawing the scene by Graphic3d/OpenGl drivers.<p>
42  * The View instance can be understood as a collector of several interactive
43  * contexts that exist independently (do not interfere) though they output
44  * into the same OpenGL context. The contexts are:
45  * <ul>
46  *  <li>AIS_InteractiveContext associated with the view by means of V3d_Viewer
47  *  instance (the traditional AIS architecture);</li>
48  *  <li>1st associated NIS_InteractiveContext</li>
49  *  <li>2nd associated NIS_InteractiveContext</li>
50  *  <li>...</li>
51  * </ul>
52  * The list of associated NIS_InteractiveContext can be modified by methods
53  * AddContext and RemoveContext.
54  */
55
56 class NIS_View : public V3d_View
57 {
58  public:
59   // ---------- PUBLIC METHODS ----------
60
61
62   /**
63    * Attach the view to the window.
64    */
65   Standard_EXPORT NIS_View (const Handle(V3d_Viewer)&    theViewer,
66                             const Handle(Aspect_Window)& theWindow = NULL);
67
68   /**
69    * Attach the view to the window.
70    */
71   Standard_EXPORT void SetWindow(const Handle(Aspect_Window) &theWindow);
72
73   /**
74    * Indicate whether to draw hilighted objects on top of all other ones
75    */
76   inline void SetHilightOnTop(const Standard_Boolean theTop = Standard_True)
77   { myIsTopHilight = theTop; }
78
79   /**
80    * Indicate whether to hilight selected object dynamically
81    * By default dynamic hilight works on all objects independently on its
82    * selected/non-selected state.
83    * This behaviour differs from the behaviour of AIS interactive context,
84    * that doesn't hilight dynamically (on mouse movements) selected objects. 
85    * In the case both context are used in the same view the behaviour of both
86    * context can be made consistent by setting this flag to False
87    */
88   inline void SetDynHilightSelected     (const Standard_Boolean
89                                          theHilight = Standard_True)
90   { myDoHilightSelected = theHilight; }
91
92   /**
93    * Zoom the view to fit to visible objects size and positions.
94    * @param theCoef
95    *   Relative margin in both X and Y dimensions. For example, value 1.0
96    *   will fit to twice the actual size.
97    * @return
98    *   True if operation performed, False if failed (most likely because of
99    *   very big actual scale)
100    */
101   Standard_EXPORT Standard_Boolean FitAll3d (const Quantity_Coefficient theCoef
102                                              = 0.01);
103
104   /**
105    * Gets bounding box covering objects displayed in viewer.
106    */
107   Standard_EXPORT Bnd_B3f GetBndBox() const;
108
109   /**
110    * Gets bounding box covering objects displayed in viewer.
111    * If operation is fails when Xmax < Xmin abd Ymax < Ymin
112    */
113   Standard_EXPORT void GetBndBox(Standard_Integer& theXMin,
114                                  Standard_Integer& theXMax, 
115                                  Standard_Integer& theYMin,
116                                  Standard_Integer& theYMax ) const;
117
118 //   /**
119 //    * Destructor.
120 //    */
121 //   Standard_EXPORT virtual ~NIS_View ();
122
123   /**
124    * Set or unset the dynamically hilighted object, depending on the
125    * given mouse coordinates.
126    */
127   Standard_EXPORT void  DynamicHilight  (const Standard_Integer theX,
128                                          const Standard_Integer theY);
129
130   /**
131    * Unhilights the hilighted object if it coincides with the given
132    * object instance.
133    */
134   Standard_EXPORT void  DynamicUnhilight(const Handle(NIS_InteractiveObject)&);
135
136   /**
137    * Unhilights the currently hilighted object.
138    */
139   inline void  DynamicUnhilight()  { DynamicUnhilight(myDynHilighted); }
140
141   /**
142    * Set or unset the selected (hilighted) state of the object that is under
143    * the coordinates theX, theY.
144    * @param theX
145    *   X coordinate of the view window
146    * @param theY
147    *   X coordinate of the view window
148    * @param isForceMult
149    *   True if the effect of multi-Selection should be forced (e.g., when Shift
150    *   is pressed).
151    * @param theRedraw
152    *   True to redraw view automatically (default value).
153    */
154   Standard_EXPORT void  Select          (const Standard_Integer theX,
155                                          const Standard_Integer theY,
156                                          const Standard_Boolean isForceMult
157                                                          = Standard_False,
158                                          const Standard_Boolean theRedraw
159                                                          = Standard_True);
160
161   /**
162    * Set or unset the selected (hilighted) state of the objects that are
163    * intersected by 2D box in the view
164    * @param theXmin
165    *   left X coordinate of the view window
166    * @param theYmin
167    *   lower Y coordinate of the view window
168    * @param theXmax
169    *   right X coordinate of the view window
170    * @param theYmax
171    *   upper Y coordinate of the view window
172    * @param isForceMult
173    *   True if the effect of multi-Selection should be forced (e.g., when Shift
174    *   is pressed).
175    * @param isFullyIncluded
176    *   True if only those objects are processed that are fully inside the
177    *   selection rectangle. False if objects fully or partially included in
178    *   the rectangle are processed. 
179    * @param theRedraw
180    *   True to redraw view automatically (default value).
181    */
182   Standard_EXPORT void  Select          (const Standard_Integer  theXmin,
183                                          const Standard_Integer  theYmin,
184                                          const Standard_Integer  theXmax,
185                                          const Standard_Integer  theYmax,
186                                          const Standard_Boolean  isForceMult
187                                                          = Standard_False,
188                                          const Standard_Boolean isFullyIncluded
189                                                          = Standard_False,
190                                          const Standard_Boolean theRedraw
191                                                          = Standard_True);
192
193   /**
194    * Set or unset the selected (hilighted) state of the objects that are
195    * intersected by 2D polygon in the view
196    * @param thePolygon
197    *   defines the vertices of a free-form closed polygon without
198    *   self-intersections. The last point should not coincide with the first
199    *   point of the list. Points are interpreted as X and Y integer coordinates
200    *   of the view window. Any two neighbor points should not be confused.
201    * @param isForceMult
202    *   True if the effect of multi-Selection should be forced (e.g., when Shift
203    *   is pressed).
204    * @param isFullyIncluded
205    *   True if only those objects are processed that are fully inside the
206    *   selection rectangle. False if objects fully or partially included in
207    *   the rectangle are processed. 
208    * @param theRedraw
209    *   True to redraw view automatically (default value).
210    */
211   Standard_EXPORT void  Select   (const NCollection_List<gp_XY> &thePolygon,
212                                   const Standard_Boolean         isForceMult
213                                                          = Standard_False,
214                                   const Standard_Boolean         isFullyIncluded
215                                                          = Standard_False,
216                                   const Standard_Boolean theRedraw
217                                                          = Standard_True);
218
219   /**
220    * Interactive selection by mouse click. Selection itself is performed in each
221    * Interactive Context attached to this View, accordingto the local parameters
222    * (mode, filter) of selection in each context. 
223    * @param theX
224    *   X coordinate of mouse pointer in the window.
225    * @param theY
226    *   Y coordinate of mouse pointer in the window.
227    * @return
228    *   the selected object picked by the minimal intersection distance among
229    *   all contexts attached to this View.
230    */
231   Standard_EXPORT Handle(NIS_InteractiveObject)
232                         Pick            (const Standard_Integer theX,
233                                          const Standard_Integer theY);
234
235   /**
236    * Interactive selection by mouse click. Selection itself is performed in each
237    * Interactive Context attached to this View, accordingto the local parameters
238    * (mode, filter) of selection in each context. 
239    * @param theAxis
240    *   3D axis for objects selection
241    * @param theOver
242    *   Overlap for the selecting axis
243    * @param isOnlySel
244    *   If False, any displayed object can be picked, otherwise only selectable
245    *   ones.
246    * @return
247    *   the selected object picked by the minimal intersection distance among
248    *   all contexts attached to this View.
249    */
250   Standard_EXPORT Handle(NIS_InteractiveObject)
251                         Pick            (const gp_Ax1&          theAxis,
252                                          const Standard_Real    theOver,
253                                          const Standard_Boolean isOnlySel);
254
255   /**
256    * Gets all objects detected by last call of Pick() method
257    */
258   inline NCollection_Vector<NIS_InteractiveObject *> GetDetected() const
259   { return myDetected; }
260
261   /**
262    * Obtain the IDs of ex-lists.
263    */
264   inline TColStd_PackedMapOfInteger& GetExListId ()
265   { return myExListId; }
266
267  protected:
268   // ---------- PROTECTED METHODS ----------
269
270   static int MyCallback (Aspect_Drawable                /* Window ID */,
271                          void*                          /* user data */, 
272                          Aspect_GraphicCallbackStruct*  /* call data */);
273
274   /**
275    * Register an interactive context for this view.
276    */
277   Standard_EXPORT void  AddContext      (NIS_InteractiveContext *);
278
279   /**
280    * Detach an interactive context from this view.
281    */
282   Standard_EXPORT void  RemoveContext   (NIS_InteractiveContext *);
283
284  private:
285   // ---------- PRIVATE FIELDS ----------
286
287   NCollection_List<NIS_InteractiveContext *>       myContexts;
288   Handle(NIS_InteractiveObject)                     myDynHilighted;
289   Standard_Boolean                                 myIsTopHilight      : 1;
290   Standard_Boolean                                 myDoHilightSelected : 1;
291   NCollection_Vector<NIS_InteractiveObject *>      myDetected;
292   TColStd_PackedMapOfInteger                       myExListId;
293
294   friend class NIS_InteractiveContext;
295
296  public:
297 // Declaration of CASCADE RTTI
298 DEFINE_STANDARD_RTTI (NIS_View)
299 };
300
301 // Definition of HANDLE object using Standard_DefineHandle.hxx
302 //DEFINE_STANDARD_HANDLE (NIS_View, V3d_OrthographicView)
303
304 #include <Handle_NIS_View.hxx>
305
306 #endif