Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2007-07-06 |
2 | // Created by: Alexander GRIGORIEV | |
3 | // Copyright (c) 2007-2012 OPEN CASCADE SAS | |
4 | // | |
5 | // The content of this file is subject to the Open CASCADE Technology Public | |
6 | // License Version 6.5 (the "License"). You may not use the content of this file | |
7 | // except in compliance with the License. Please obtain a copy of the License | |
8 | // at http://www.opencascade.org and read it completely before using this file. | |
9 | // | |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
12 | // | |
13 | // The Original Code and all software distributed under the License is | |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
15 | // Initial Developer hereby disclaims all such warranties, including without | |
16 | // limitation, any warranties of merchantability, fitness for a particular | |
17 | // purpose or non-infringement. Please see the License for the specific terms | |
18 | // and conditions governing the rights and limitations under the License. | |
19 | ||
7fd59977 | 20 | |
21 | ||
22 | #ifndef NIS_InteractiveContext_HeaderFile | |
23 | #define NIS_InteractiveContext_HeaderFile | |
24 | ||
25 | #include <Handle_NIS_InteractiveObject.hxx> | |
26 | #include <Handle_NIS_View.hxx> | |
7fd59977 | 27 | #include <NCollection_Map.hxx> |
0f524ba0 | 28 | #include <NCollection_SparseArray.hxx> |
ffe2bea7 | 29 | #include <NIS_Allocator.hxx> |
7fd59977 | 30 | #include <NIS_Drawer.hxx> |
31 | #include <NIS_SelectFilter.hxx> | |
32 | ||
33 | #ifdef WNT | |
34 | #ifdef GetObject | |
35 | #undef GetObject | |
36 | #endif | |
37 | #endif | |
38 | ||
39 | class NIS_View; | |
40 | class Bnd_B3f; | |
ffe2bea7 | 41 | class Bnd_B2f; |
7fd59977 | 42 | |
43 | /** | |
44 | * InteractiveContext is the central NIS structure that stores and manages | |
ffe2bea7 | 45 | * all NIS_InteractiveObject instances as well as the Drawers for their |
7fd59977 | 46 | * visualisation. |
47 | * There may be one or more Views referred by an InteractiveContext instance. | |
48 | * Also there may be one or more InteractiveContext instances referring the same | |
49 | * View. However the latter case is not typical (see NIS_View description).<br> | |
50 | * To add or remove a View in a Context, use methods AttachView() and | |
51 | * DetachView(). | |
ffe2bea7 A |
52 | * |
53 | * @section nis_interactivecontext_mgtobjects Management of objects | |
54 | * The main purpose of class NIS_InteractiveContext is allocation and | |
7fd59977 | 55 | * management of NIS_InteractiveObject instances. |
56 | * <p>An InteractiveObject should be added to the Context by a call to method | |
ffe2bea7 | 57 | * Display() or DisplayOnTop(). After that (not before) it becomes possible to: |
7fd59977 | 58 | * <ul> |
59 | * <li>change the presentation of the InteractiveObject (e.g., modify the color) | |
60 | * </li> | |
ffe2bea7 A |
61 | * <li>make the InteractiveObject visible or invisible, selectable or |
62 | * unselectable;</li> | |
7fd59977 | 63 | * <li>set Transparency;</li> |
64 | * <li>select InteractiveObject interactively, including the hilighting and | |
65 | * the dynamic hilighting.</li> | |
66 | * </ul> | |
ffe2bea7 A |
67 | * Methods that add/remove/display/hide NIS_InteractiveObject instances have |
68 | * the optional parameter 'isUpdateViews'. When it is set to True (default), | |
69 | * the modification of the object brings about an immediate update of its | |
70 | * presentation (the corresponding Drawer flagged to recompute presentations). | |
71 | * Normally you do not have to worry about this parameter leaving it assigned to | |
72 | * the default value; use the alternative value 'Standard_False' only for | |
73 | * very special purposes, like animation -- when many updates should be | |
74 | * synchronized in time. For other methods like changing the transparency or | |
75 | * color definition there is no parameter 'isUpdateViews', all changes mark | |
76 | * the corresponding drawers immediately. | |
7fd59977 | 77 | * <p>Typical scheme of usage: |
78 | * @code | |
79 | * const Handle(NIS_InteractiveContext) aContext = new NIS_InteractiveContext; | |
80 | * const Handle(NIS_View) aView = new NIS_View(...); | |
81 | * aContext->AttachView (aView); | |
82 | * .... | |
83 | * for (; ;) { | |
ffe2bea7 A |
84 | * const Handle(MyIOClass) anObject = new MyIOClass(); |
85 | * aContext->Display (anObject); | |
86 | * anObject->SetColor(...); // method of class MyIOClass | |
7fd59977 | 87 | * ... |
88 | * } | |
7fd59977 | 89 | * @endcode |
ffe2bea7 A |
90 | * @section nis_interactivecontext_display Method Display() |
91 | * This method performs three important tasks, when called the first time for | |
92 | * an object: | |
7fd59977 | 93 | * <ul> |
ffe2bea7 A |
94 | * <li>Copy its argument to the memory pool that is managed by the internal |
95 | * Allocator of NIS_InteractiveContext. Then <b>the new instance of | |
96 | * object</b> is returned back in the same argument (in-out parameter);</li> | |
97 | * <li>Store the copied instance in the internal vector of objects, so that | |
98 | * the displayed object receives its ID (sequential address in the vector); | |
99 | * </li> | |
100 | * <li>Create a Drawer instance if necessary; attach the displayed interactive | |
101 | * object to this instance (or to a relevant and already existing Drawer) | |
102 | * </li> | |
7fd59977 | 103 | * </ul> |
ffe2bea7 A |
104 | * Thus any methods dealing with Drawer-related properties like color, line |
105 | * width, polygon offset, etc. can only be called following the necessary call | |
106 | * of method Display(). | |
107 | * <p> | |
108 | * Subsequent calls to Display() just revert previous calls of Erase() without | |
109 | * any re-initialization of interactive object or its drawer. | |
110 | * | |
111 | * @section nis_interactivecontext_memory Using the memory | |
112 | * As described in the sections above, all interactive objects should completely | |
113 | * reside in the special memory pool managed by the InteractiveContext instance. | |
114 | * This is a fast memory (NCollection_IncAllocator is used) but it has the | |
115 | * drawback: when you destroy an object using method Remove() it is detached | |
116 | * from NIS_InteractiveContext and its presentation is removed from all Views. | |
117 | * But the memory allocated for that removed object is not released and it | |
118 | * cannot be reused by new interactive objects. In time there may appear too | |
119 | * many "dead" objects to hinder or even crash the application. | |
120 | * <p> | |
121 | * This problem is resolved by automatic keeping the record of the total size | |
122 | * of both used and unused memory, in the instance of NIS_Allocator. When the | |
123 | * amount of unused memory becomes too big then the method compactObjects() | |
124 | * creates a new NIS_Allocator instance and copies there all interactive | |
125 | * objects that are 'alive' then releasing the previous memory pool. All | |
126 | * object IDs and their drawers remain intact, so nothing is changed except | |
127 | * the greater amount of available memory in the system. | |
128 | * <p> | |
129 | * This mechanism works when either UpdateViews() or RebuildViews() is called | |
130 | * from time to time, only these two methods can call compactObjects(). | |
7fd59977 | 131 | */ |
132 | ||
133 | class NIS_InteractiveContext : public Standard_Transient | |
134 | { | |
135 | public: | |
136 | typedef enum { | |
137 | Mode_NoSelection = 0, ///< Seelction is totally disabled | |
138 | Mode_Normal, ///< Selected are added to or removed from list | |
139 | Mode_Additive, ///< Selected are added to the list of selected | |
140 | Mode_Exclusive ///< Selected are removed from the list | |
141 | } SelectionMode; | |
142 | ||
143 | public: | |
144 | // ---------- PUBLIC METHODS ---------- | |
145 | ||
146 | ||
147 | /** | |
148 | * Empty constructor. | |
149 | */ | |
150 | Standard_EXPORT NIS_InteractiveContext (); | |
151 | ||
152 | /** | |
153 | * Destructor. | |
154 | */ | |
155 | Standard_EXPORT virtual ~NIS_InteractiveContext (); | |
156 | ||
157 | ///@name Management of Views | |
158 | //@{ | |
159 | /** | |
160 | * Associate this Context with the given View. | |
161 | */ | |
162 | Standard_EXPORT void AttachView (const Handle_NIS_View& theView); | |
163 | ||
164 | /** | |
165 | * Stop the association of the Context with the given View. | |
166 | */ | |
167 | Standard_EXPORT void DetachView (const Handle_NIS_View& theView); | |
168 | //@} | |
169 | ||
170 | /** | |
171 | * Query the InteractiveObject instance by its ID. | |
172 | */ | |
0f524ba0 | 173 | Standard_EXPORT const Handle_NIS_InteractiveObject& |
174 | GetObject (const Standard_Integer theID) const; | |
7fd59977 | 175 | |
176 | /** | |
177 | * Query the total number of InteractiveObject instances. This number can be | |
178 | * smaller than the greatest object ID, therefore you should not iterate till | |
179 | * this number using GetObject; use class NIS_ObjectsIterator instead. | |
180 | */ | |
181 | inline Standard_Integer | |
182 | NbObjects () | |
183 | // { return myObjects.Length()-1; } | |
184 | { return (myMapObjects[0].Extent() + myMapObjects[1].Extent() + | |
ffe2bea7 | 185 | myMapObjects[2].Extent()) + myMapObjects[3].Extent(); } |
7fd59977 | 186 | |
187 | /** | |
188 | * Query the total number of Drawers instances. | |
189 | */ | |
190 | inline Standard_Integer | |
191 | NbDrawers () | |
192 | { return myDrawers.Size(); } | |
193 | ||
194 | /** | |
ffe2bea7 A |
195 | * Access to Drawers, can be used for specific operations where it is not |
196 | * desirale to iterate InteractiveObjects. | |
197 | */ | |
198 | inline NCollection_Map<Handle_NIS_Drawer>::Iterator | |
199 | GetDrawers () const | |
200 | { return NCollection_Map<Handle_NIS_Drawer>::Iterator(myDrawers); } | |
7fd59977 | 201 | |
202 | // ================ BEGIN Mangement of Objects ================ | |
203 | ///@name Management of Objects | |
204 | //@{ | |
205 | ||
206 | /** | |
207 | * Make the given interactive object visible in the current context. | |
208 | * If the object is not yet added to this context, it is added. Therefore | |
209 | * this method should follow the creation of an InteractiveObject instance | |
210 | * before it can be displayed. | |
211 | * @param theObj | |
ffe2bea7 A |
212 | * <tt>[in/out]</tt>Interactive object instance. If the object is displayed |
213 | * for the first time then the output value will be a new (cloned) object. | |
7fd59977 | 214 | * @param theDrawer |
215 | * If this parameter is NULL, the default drawer is used for theObj, defined | |
216 | * by the object type. Otherwise the given Drawer (must be present in this | |
217 | * context) is used for theObj. Use the parameter to change the presentation | |
218 | * of theObj. | |
219 | * @param isUpdateViews | |
220 | * If True, the drawer receives isUpdate flag, then it will recompute | |
221 | * the presentations when Redraw event happens. You can leave the parameter | |
222 | * to False if you have to make a number of similar calls, then you would | |
223 | * call UpdateViews() in the end. | |
224 | */ | |
ffe2bea7 | 225 | Standard_EXPORT void Display (Handle_NIS_InteractiveObject& theObj, |
7fd59977 | 226 | const Handle_NIS_Drawer& theDrawer = NULL, |
227 | const Standard_Boolean isUpdateViews | |
228 | = Standard_True); | |
229 | ||
ffe2bea7 A |
230 | /** |
231 | * Make the given interactive object visible on top of other objects in | |
232 | * the current context. | |
233 | * If the object is not yet added to this context, it is added. Therefore | |
234 | * this method should follow the creation of an InteractiveObject instance | |
235 | * before it can be displayed. | |
236 | * @param theObj | |
237 | * Interactive object instance. | |
238 | * @param theDrawer | |
239 | * If this parameter is NULL, the default drawer is used for theObj, defined | |
240 | * by the object type. Otherwise the given Drawer (must be present in this | |
241 | * context) is used for theObj. Use the parameter to change the presentation | |
242 | * of theObj. | |
243 | * @param isUpdateViews | |
244 | * If True, the drawer receives isUpdate flag, then it will recompute | |
245 | * the presentations when Redraw event happens. You can leave the parameter | |
246 | * to False if you have to make a number of similar calls, then you would | |
247 | * call UpdateViews() in the end. | |
248 | */ | |
249 | Standard_EXPORT void DisplayOnTop (Handle_NIS_InteractiveObject& theObj, | |
250 | const Handle_NIS_Drawer& theDrawer = NULL, | |
251 | const Standard_Boolean isUpdateViews | |
252 | = Standard_True); | |
253 | ||
7fd59977 | 254 | /** |
255 | * Make the given object invisible in the current InteractiveContext. | |
256 | * @param theObj | |
257 | * Interactive object instance. Must be already added to this context. | |
258 | * @param isUpdateViews | |
259 | * If True, the drawer receives isUpdate flag, then it will recompute | |
260 | * the presentations when Redraw event happens. You can leave the parameter | |
261 | * to False if you have to make a number of similar calls, then you would | |
262 | * call UpdateViews() in the end. | |
263 | */ | |
264 | Standard_EXPORT void Erase (const Handle_NIS_InteractiveObject& theObj, | |
265 | const Standard_Boolean isUpdateViews | |
266 | = Standard_True); | |
267 | ||
268 | /** | |
269 | * Remove the given object from its Interactive context. | |
270 | * @param theObj | |
271 | * Interactive object instance. Must be already added to this context. | |
272 | * @param isUpdateViews | |
273 | * If True, the drawer receives isUpdate flag, then it will recompute | |
274 | * the presentations when Redraw event happens. You can leave the parameter | |
275 | * to False if you have to make a number of similar calls, then you would | |
276 | * call UpdateViews() in the end. | |
277 | */ | |
278 | Standard_EXPORT void Remove (const Handle_NIS_InteractiveObject& theObj, | |
279 | const Standard_Boolean isUpdateViews | |
280 | = Standard_True); | |
281 | ||
282 | /** | |
283 | * Make all stored InteractiveObject instances visible, equivalent to | |
284 | * calling method Display() for all contained objects. | |
7fd59977 | 285 | */ |
ffe2bea7 | 286 | Standard_EXPORT void DisplayAll (); |
7fd59977 | 287 | |
288 | /** | |
289 | * Make all stored InteractiveObject instances invisible, equivalent to | |
290 | * calling method Erase() for all contained objects. | |
7fd59977 | 291 | */ |
ffe2bea7 | 292 | Standard_EXPORT void EraseAll (); |
7fd59977 | 293 | |
294 | /** | |
ffe2bea7 A |
295 | * Clean the context of its contained objects. Drawers are destroyed |
296 | * and all presentations become empty. | |
7fd59977 | 297 | */ |
ffe2bea7 | 298 | Standard_EXPORT void RemoveAll (); |
7fd59977 | 299 | |
300 | /** | |
ffe2bea7 A |
301 | * This method signals that the presenation should be refreshed in all updated |
302 | * Drawers and in all Views. Calls Redraw() of each view from inside. | |
7fd59977 | 303 | */ |
304 | Standard_EXPORT void UpdateViews (); | |
305 | ||
ffe2bea7 A |
306 | /** |
307 | * Similar to UpdateViews but forces all presentations to be rebuilt whether | |
308 | * the drawers are marked as updated or not. | |
309 | */ | |
310 | Standard_EXPORT void RebuildViews(); | |
311 | ||
7fd59977 | 312 | /** |
313 | * Find the bounding box of all Objects displayed (visible) in the given View. | |
314 | * @param theBox | |
315 | * <tt>[out]</tt> Bounding box, updated (not reinitialized!) by the object | |
316 | * boxes. | |
317 | * @param theView | |
318 | * View instance where the objects are displayed. | |
319 | */ | |
320 | Standard_EXPORT void GetBox (Bnd_B3f& theBox, | |
321 | const NIS_View * theView) const; | |
322 | ||
323 | //@} | |
324 | // ================ END Mangement of Objects ================ | |
325 | ||
326 | // ================ BEGIN Selection API ================ | |
327 | ///@name Selection API | |
328 | //@{ | |
329 | ||
330 | /** | |
331 | * Query the current selection filter. Use the method SetFilter to install it. | |
332 | * By default returns a NULL handle. | |
333 | */ | |
334 | inline const Handle_NIS_SelectFilter& | |
335 | GetFilter () const | |
336 | { return mySelectFilter; } | |
337 | ||
338 | /** | |
339 | * Install a selection filter. | |
340 | */ | |
341 | inline void SetFilter (const Handle_NIS_SelectFilter& theFilter) | |
342 | { mySelectFilter = theFilter; } | |
343 | ||
344 | /** | |
345 | * Query the current selection mode. | |
346 | */ | |
347 | inline SelectionMode GetSelectionMode () const | |
348 | { return mySelectionMode; } | |
349 | ||
350 | /** | |
351 | * Set the selection mode. | |
352 | */ | |
353 | inline void SetSelectionMode (const SelectionMode theMode) | |
354 | { mySelectionMode = theMode; } | |
355 | ||
356 | /** | |
357 | * Set or unset the selected state of the object, also changing its | |
358 | * hilight status.<br> | |
359 | * If mySelectionMode == Mode_NoSelection this method does nothing (returns | |
360 | * False always).<br> | |
361 | * If the given object is NULL (e.g., if the mouse was clicked on empty area), | |
362 | * then the current selection is cleared (modes Normal and Additive only).<br> | |
363 | * The selection algorithm with respect to the given object is defined by | |
364 | * the current selection mode : | |
365 | * <ul> | |
366 | * <li>Mode_Normal - the selection state is toggled</li> | |
367 | * <li>Mode_Additive - the object is always added to the selection</li> | |
368 | * <li>Mode_Exclusive - the object is always removed from the selection</li> | |
369 | * </ul> | |
370 | * This method does not update the views. | |
371 | * @param O | |
372 | * Object to be selected or deselected | |
373 | * @param isMultiple | |
374 | * If True, then the objects are not automatically deselected. | |
375 | * @return | |
376 | * True if the selection status has been changed, False if nothing changed | |
377 | */ | |
378 | Standard_EXPORT Standard_Boolean | |
379 | ProcessSelection(const Handle_NIS_InteractiveObject& O, | |
380 | const Standard_Boolean isMultiple | |
381 | = Standard_False); | |
382 | ||
383 | /** | |
384 | * Process the selection of multiple objects. Equivalent to the other | |
385 | * ProcessSelection method, on a set of objects. Particularly, the current | |
386 | * selection mode is respected. | |
387 | * @param map | |
388 | * Container of IDs of objects to be processed | |
389 | * @param isMultiple | |
390 | * If True, then the objects are not automatically deselected. | |
391 | */ | |
392 | Standard_EXPORT void ProcessSelection(const TColStd_PackedMapOfInteger& map, | |
393 | const Standard_Boolean isMultiple | |
394 | = Standard_False); | |
395 | ||
396 | /** | |
397 | * Set or unset the selected state of the object, also changing its | |
398 | * hilight status.<br> | |
399 | * This method does not update the views. | |
400 | * @param theObj | |
401 | * Object to be selected or deselected | |
402 | * @param isSelected | |
403 | * true if the object should be selected, False - if deselected. | |
404 | * @return | |
405 | * True if the selection status has been changed, False if noithing changed | |
406 | */ | |
407 | Standard_EXPORT Standard_Boolean | |
408 | SetSelected (const Handle_NIS_InteractiveObject& theObj, | |
409 | const Standard_Boolean isSelected | |
410 | = Standard_True); | |
411 | ||
412 | /** | |
413 | * Set the selection. Previously selected objects are deselected if they | |
414 | * are not included in the given map. | |
415 | * @param map | |
416 | * Container of IDs of objects to be selected | |
417 | * @param isAdded | |
418 | * If True, the given IDs are added to the current selection (nothing is | |
419 | * deselected). If False (default) - the previous selection is forgotten. | |
420 | */ | |
421 | Standard_EXPORT void SetSelected (const TColStd_PackedMapOfInteger& map, | |
422 | const Standard_Boolean isAdded | |
423 | = Standard_False); | |
424 | ||
425 | /** | |
426 | * Query if the given object is selected. | |
427 | */ | |
428 | Standard_EXPORT Standard_Boolean | |
429 | IsSelected (const Handle_NIS_InteractiveObject& theOb); | |
430 | ||
431 | /** | |
432 | * Reset all previous selection. | |
433 | */ | |
434 | Standard_EXPORT void ClearSelected (); | |
435 | ||
436 | /** | |
437 | * Query the set of selected objects. | |
438 | * @return | |
439 | * Map of integer IDs of objects. | |
440 | */ | |
441 | inline const TColStd_PackedMapOfInteger& | |
442 | GetSelected () | |
443 | { return myMapObjects[NIS_Drawer::Draw_Hilighted]; } | |
444 | ||
445 | /** | |
446 | * Define objects that can be selected by no means (isSelectable = false), | |
447 | * or make the objects selectable (isSelectable = true). | |
448 | * @param IDs | |
449 | * Container of IDs of objects to be set as selectable or not selectable | |
450 | * @param isSelectable | |
451 | * If False, the given IDs are made non-selectable by SetSelected methods, | |
452 | * If True, the given IDs are made selectable. | |
453 | */ | |
454 | Standard_EXPORT void SetSelectable (const TColStd_PackedMapOfInteger& IDs, | |
455 | const Standard_Boolean isSelectable); | |
456 | ||
457 | /** | |
458 | * Return True if the object can be selected (processing by SetSelected | |
459 | * methods), or False if can not be. | |
460 | * @return | |
461 | * Selectable state of the object. | |
462 | */ | |
463 | inline Standard_Boolean IsSelectable (const Standard_Integer objID) const | |
464 | { return (myMapNonSelectableObjects.Contains( objID ) == Standard_False); } | |
465 | ||
ffe2bea7 A |
466 | /** |
467 | * Set or reset the flag that tells to NIS_Drawer to create shared DrawList. | |
468 | * The default mode (in Constructor) is True. | |
469 | */ | |
470 | inline void SetShareDrawList (Standard_Boolean isShare) | |
471 | { myIsShareDrawList = isShare; } | |
7fd59977 | 472 | |
473 | //@} | |
474 | // ====== END Selection API ================ | |
475 | ||
476 | protected: | |
ffe2bea7 A |
477 | //! Structure referencing one detected (picked) interactive entity. |
478 | struct DetectedEnt | |
479 | { | |
480 | Standard_Real Dist; //!< Distance on the view direction | |
481 | NIS_InteractiveObject* PObj; //!< Pointer to interactive object | |
482 | }; | |
483 | ||
7fd59977 | 484 | // ---------- PROTECTED METHODS ---------- |
485 | ||
486 | Standard_EXPORT void redraw (const Handle_NIS_View& theView, | |
487 | const NIS_Drawer::DrawType theType); | |
488 | ||
7fd59977 | 489 | /** |
490 | * Detect the object selected by the given ray. | |
491 | * @param theSel | |
492 | * <tt>[out]</tt> The selected object that has the lowest ray distance. | |
ffe2bea7 A |
493 | * @param theDet |
494 | * <tt>[out]</tt> Sorted list of all detected objects with ray distances | |
7fd59977 | 495 | * @param theAxis |
496 | * Selection ray | |
497 | * @param theOver | |
498 | * Thickness of the selecting ray | |
499 | * @param isOnlySelectable | |
500 | * If False, any displayed object can be picked, otherwise only selectable | |
501 | * ones. | |
502 | * @return | |
503 | * The ray distance of the intersection point between the ray and theSel. | |
504 | */ | |
505 | Standard_EXPORT Standard_Real | |
506 | selectObject (Handle_NIS_InteractiveObject& theSel, | |
ffe2bea7 | 507 | NCollection_List<DetectedEnt>& theDet, |
7fd59977 | 508 | const gp_Ax1& theAxis, |
509 | const Standard_Real theOver, | |
510 | const Standard_Boolean isOnlySelectable | |
511 | = Standard_True) const; | |
512 | ||
513 | /** | |
514 | * Build a list of objects that are inside or touched by an oriented box. | |
515 | * @param mapObj | |
516 | * <tt>[out]</tt> Container of object IDs, updated by detected objects. | |
517 | * @param theBox | |
518 | * 3D box of selection | |
519 | * @param theTrf | |
520 | * Position/Orientation of the box (for box-box intersections) | |
521 | * @param theTrfInv | |
522 | * Inverted Position/Orientation of the box (for box-object intersections) | |
523 | * @param isFullyIn | |
524 | * True if only those objects are processed that are fully inside the | |
525 | * selection rectangle. False if objects fully or partially included in | |
526 | * the rectangle are processed. | |
527 | * @return | |
528 | * True if at least one object was selected. | |
529 | */ | |
530 | Standard_EXPORT Standard_Boolean | |
531 | selectObjects (TColStd_PackedMapOfInteger& mapObj, | |
532 | const Bnd_B3f& theBox, | |
533 | const gp_Trsf& theTrf, | |
534 | const gp_Trsf& theTrfInv, | |
535 | const Standard_Boolean isFullyIn)const; | |
536 | ||
ffe2bea7 A |
537 | /** |
538 | * Build a list of objects that are inside or touched by a polygon. | |
539 | * @param mapObj | |
540 | * <tt>[out]</tt> Container of object IDs, updated by detected objects. | |
541 | * @param thePolygon | |
542 | * the list of vertices of a free-form closed polygon without | |
543 | * self-intersections. The last point should not coincide with the first | |
544 | * point of the list. Any two neighbor points should not be confused. | |
545 | * @param thePolygonBox | |
546 | * 2D box of selection polygon | |
547 | * @param theTrfInv | |
548 | * Inverted Position/Orientation of the plane where thePolygon is defined | |
549 | * (for polygon-object intersections) | |
550 | * @param isFullyIn | |
551 | * True if only those objects are processed that are fully inside the | |
552 | * selection polygon. False if objects fully or partially included in | |
553 | * the polygon are processed. | |
554 | * @return | |
555 | * True if at least one object was selected. | |
556 | */ | |
557 | Standard_EXPORT Standard_Boolean | |
558 | selectObjects (TColStd_PackedMapOfInteger &mapObj, | |
559 | const NCollection_List<gp_XY> &thePolygon, | |
560 | const Bnd_B2f &thePolygonBox, | |
561 | const gp_Trsf &theTrfInv, | |
562 | const Standard_Boolean isFullyIn) const; | |
563 | ||
564 | private: | |
565 | void deselectObj (const Handle_NIS_InteractiveObject&, | |
566 | const Standard_Integer); | |
567 | ||
568 | void selectObj (const Handle_NIS_InteractiveObject&, | |
569 | const Standard_Integer); | |
570 | ||
571 | const Handle_NIS_Drawer& | |
572 | drawerForDisplay (const Handle_NIS_InteractiveObject&, | |
573 | const Handle_NIS_Drawer&); | |
574 | ||
575 | void objectForDisplay (Handle_NIS_InteractiveObject&, | |
576 | const NIS_Drawer::DrawType); | |
577 | ||
578 | Handle_NIS_Allocator | |
579 | compactObjects (); | |
580 | ||
7fd59977 | 581 | private: |
582 | // ---------- PRIVATE FIELDS ---------- | |
583 | ||
ffe2bea7 A |
584 | /** |
585 | * Allocator for all data associated with objects. | |
586 | */ | |
587 | Handle_NIS_Allocator myAllocator; | |
588 | ||
0f524ba0 | 589 | /** |
590 | * The last added object ID. | |
591 | */ | |
592 | Standard_Integer myLastObjectId; | |
7fd59977 | 593 | /** |
594 | * Container of InteractiveObject instances. | |
595 | */ | |
0f524ba0 | 596 | NCollection_SparseArray <Handle_NIS_InteractiveObject> |
597 | myObjects; | |
7fd59977 | 598 | |
599 | /** | |
600 | * List of Views. | |
601 | */ | |
602 | NCollection_List <Handle_NIS_View> myViews; | |
603 | ||
604 | /** | |
605 | * Container of Drawers. There should be one or more Drawers for each type of | |
606 | * contained InteractiveObject. | |
607 | */ | |
608 | NCollection_Map <Handle_NIS_Drawer> myDrawers; | |
609 | ||
610 | /** | |
611 | * Three maps indicating the state of contained objects: | |
612 | * - #0 - normally presented objects | |
ffe2bea7 A |
613 | * - #1 - top objects |
614 | * - #2 - hilighted objects (i.e., selected) | |
615 | * - #3 - transparent objects | |
7fd59977 | 616 | * <br>Each object can have only one entry in these maps. |
617 | */ | |
ffe2bea7 | 618 | TColStd_PackedMapOfInteger myMapObjects[4]; |
7fd59977 | 619 | |
620 | /** | |
621 | * Objects contained in this map are ignored by SetSelected methods, | |
622 | * these objects are not selectable. | |
623 | */ | |
624 | TColStd_PackedMapOfInteger myMapNonSelectableObjects; | |
625 | ||
626 | /** | |
627 | * Instance of selection filter used for interactive selections. | |
628 | */ | |
629 | Handle_NIS_SelectFilter mySelectFilter; | |
630 | ||
7fd59977 | 631 | /** |
632 | * Current mode of selection. | |
633 | */ | |
634 | SelectionMode mySelectionMode; | |
635 | ||
636 | /** | |
ffe2bea7 | 637 | * Flag that allows to use single draw list for all views. |
7fd59977 | 638 | */ |
ffe2bea7 | 639 | Standard_Boolean myIsShareDrawList; |
7fd59977 | 640 | |
641 | friend class NIS_View; | |
642 | friend class NIS_Drawer; | |
643 | friend class NIS_InteractiveObject; | |
644 | friend class NIS_ObjectsIterator; | |
645 | ||
646 | public: | |
647 | // Declaration of CASCADE RTTI | |
648 | DEFINE_STANDARD_RTTI (NIS_InteractiveContext) | |
649 | }; | |
650 | ||
651 | // Definition of HANDLE object using Standard_DefineHandle.hxx | |
652 | DEFINE_STANDARD_HANDLE (NIS_InteractiveContext, Standard_Transient) | |
653 | ||
654 | ||
655 | #endif |