1 // Created on: 2007-07-06
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and / or modify it
8 // under the terms of the GNU Lesser General Public 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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef NIS_View_HeaderFile
17 #define NIS_View_HeaderFile
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>
28 class NIS_InteractiveContext;
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:
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>
52 * The list of associated NIS_InteractiveContext can be modified by methods
53 * AddContext and RemoveContext.
56 class NIS_View : public V3d_View
59 // ---------- PUBLIC METHODS ----------
63 * Attach the view to the window.
65 Standard_EXPORT NIS_View (const Handle_V3d_Viewer& theViewer,
66 const Handle_Aspect_Window& theWindow = NULL);
69 * Attach the view to the window.
71 Standard_EXPORT void SetWindow(const Handle_Aspect_Window &theWindow);
74 * Indicate whether to draw hilighted objects on top of all other ones
76 inline void SetHilightOnTop(const Standard_Boolean theTop = Standard_True)
77 { myIsTopHilight = theTop; }
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
88 inline void SetDynHilightSelected (const Standard_Boolean
89 theHilight = Standard_True)
90 { myDoHilightSelected = theHilight; }
93 * Zoom the view to fit to visible objects size and positions.
95 * Relative margin in both X and Y dimensions. For example, value 1.0
96 * will fit to twice the actual size.
98 * True if operation performed, False if failed (most likely because of
99 * very big actual scale)
101 Standard_EXPORT Standard_Boolean FitAll3d (const Quantity_Coefficient theCoef
105 * Gets bounding box covering objects displayed in viewer.
107 Standard_EXPORT Bnd_B3f GetBndBox() const;
110 * Gets bounding box covering objects displayed in viewer.
111 * If operation is fails when Xmax < Xmin abd Ymax < Ymin
113 Standard_EXPORT void GetBndBox(Standard_Integer& theXMin,
114 Standard_Integer& theXMax,
115 Standard_Integer& theYMin,
116 Standard_Integer& theYMax ) const;
121 // Standard_EXPORT virtual ~NIS_View ();
124 * Set or unset the dynamically hilighted object, depending on the
125 * given mouse coordinates.
127 Standard_EXPORT void DynamicHilight (const Standard_Integer theX,
128 const Standard_Integer theY);
131 * Unhilights the hilighted object if it coincides with the given
134 Standard_EXPORT void DynamicUnhilight(const Handle_NIS_InteractiveObject&);
137 * Unhilights the currently hilighted object.
139 inline void DynamicUnhilight() { DynamicUnhilight(myDynHilighted); }
142 * Set or unset the selected (hilighted) state of the object that is under
143 * the coordinates theX, theY.
145 * X coordinate of the view window
147 * X coordinate of the view window
149 * True if the effect of multi-Selection should be forced (e.g., when Shift
152 * True to redraw view automatically (default value).
154 Standard_EXPORT void Select (const Standard_Integer theX,
155 const Standard_Integer theY,
156 const Standard_Boolean isForceMult
158 const Standard_Boolean theRedraw
162 * Set or unset the selected (hilighted) state of the objects that are
163 * intersected by 2D box in the view
165 * left X coordinate of the view window
167 * lower Y coordinate of the view window
169 * right X coordinate of the view window
171 * upper Y coordinate of the view window
173 * True if the effect of multi-Selection should be forced (e.g., when Shift
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.
180 * True to redraw view automatically (default value).
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
188 const Standard_Boolean isFullyIncluded
190 const Standard_Boolean theRedraw
194 * Set or unset the selected (hilighted) state of the objects that are
195 * intersected by 2D polygon in the view
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.
202 * True if the effect of multi-Selection should be forced (e.g., when Shift
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.
209 * True to redraw view automatically (default value).
211 Standard_EXPORT void Select (const NCollection_List<gp_XY> &thePolygon,
212 const Standard_Boolean isForceMult
214 const Standard_Boolean isFullyIncluded
216 const Standard_Boolean theRedraw
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.
224 * X coordinate of mouse pointer in the window.
226 * Y coordinate of mouse pointer in the window.
228 * the selected object picked by the minimal intersection distance among
229 * all contexts attached to this View.
231 Standard_EXPORT Handle_NIS_InteractiveObject
232 Pick (const Standard_Integer theX,
233 const Standard_Integer theY);
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.
240 * 3D axis for objects selection
242 * Overlap for the selecting axis
244 * If False, any displayed object can be picked, otherwise only selectable
247 * the selected object picked by the minimal intersection distance among
248 * all contexts attached to this View.
250 Standard_EXPORT Handle_NIS_InteractiveObject
251 Pick (const gp_Ax1& theAxis,
252 const Standard_Real theOver,
253 const Standard_Boolean isOnlySel);
256 * Gets all objects detected by last call of Pick() method
258 inline NCollection_Vector<NIS_InteractiveObject *> GetDetected() const
259 { return myDetected; }
262 * Obtain the IDs of ex-lists.
264 inline TColStd_PackedMapOfInteger& GetExListId ()
265 { return myExListId; }
268 // ---------- PROTECTED METHODS ----------
270 static int MyCallback (Aspect_Drawable /* Window ID */,
271 void* /* user data */,
272 Aspect_GraphicCallbackStruct* /* call data */);
275 * Register an interactive context for this view.
277 Standard_EXPORT void AddContext (NIS_InteractiveContext *);
280 * Detach an interactive context from this view.
282 Standard_EXPORT void RemoveContext (NIS_InteractiveContext *);
285 // ---------- PRIVATE FIELDS ----------
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;
294 friend class NIS_InteractiveContext;
297 // Declaration of CASCADE RTTI
298 DEFINE_STANDARD_RTTI (NIS_View)
301 // Definition of HANDLE object using Standard_DefineHandle.hxx
302 //DEFINE_STANDARD_HANDLE (NIS_View, V3d_OrthographicView)
304 #include <Handle_NIS_View.hxx>