0027818: Visualization - provide an interface to define highlight presentation properties
[occt.git] / src / AIS / AIS_LocalContext.hxx
CommitLineData
42cf5bc1 1// Created on: 1996-09-04
2// Created by: Robert COUBLANC
3// Copyright (c) 1996-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _AIS_LocalContext_HeaderFile
18#define _AIS_LocalContext_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_Type.hxx>
22
23#include <Standard_Boolean.hxx>
24#include <StdSelect_ViewerSelector3d.hxx>
25#include <PrsMgr_PresentationManager3d.hxx>
26#include <TCollection_AsciiString.hxx>
27#include <AIS_DataMapOfSelStat.hxx>
28#include <TColStd_ListOfInteger.hxx>
29#include <SelectMgr_IndexedMapOfOwner.hxx>
30#include <Standard_Integer.hxx>
31#include <TColStd_SequenceOfInteger.hxx>
32#include <AIS_SequenceOfInteractive.hxx>
33#include <MMgt_TShared.hxx>
34#include <AIS_ClearMode.hxx>
35#include <TopAbs_ShapeEnum.hxx>
36#include <SelectMgr_ListOfFilter.hxx>
37#include <AIS_StatusOfDetection.hxx>
38#include <AIS_StatusOfPick.hxx>
39#include <TColgp_Array1OfPnt2d.hxx>
40#include <TColStd_MapOfTransient.hxx>
41#include <Quantity_NameOfColor.hxx>
42#include <Standard_Real.hxx>
016e5959 43#include <AIS_Selection.hxx>
42cf5bc1 44class AIS_InteractiveContext;
45class SelectMgr_SelectionManager;
46class SelectMgr_OrFilter;
47class SelectMgr_Filter;
48class TCollection_AsciiString;
49class AIS_InteractiveObject;
50class V3d_View;
c3282ec1 51class V3d_Viewer;
42cf5bc1 52class TopoDS_Shape;
53class SelectMgr_EntityOwner;
54class Standard_Transient;
55class AIS_LocalStatus;
56class SelectMgr_SelectableObject;
57
58
59class AIS_LocalContext;
60DEFINE_STANDARD_HANDLE(AIS_LocalContext, MMgt_TShared)
61
62//! Defines a specific context for selection.
63//! It becomes possible to:
64//! + Load InteractiveObjects with a mode to be
65//! activated + associate InteractiveObjects with a
66//! set of temporary selectable Objects.... + +
67//! activate StandardMode of selection for Entities
68//! inheriting BasicShape from AIS (Selection Of
69//! vertices, edges, wires,faces... + Add Filters
70//! acting on detected owners of sensitive primitives
71//!
72//! - automatically highlight shapes and
73//! InteractiveObjects (highlight of detected shape +
74//! highlight of detected selectable...
75class AIS_LocalContext : public MMgt_TShared
76{
77
78public:
79
80
81 Standard_EXPORT AIS_LocalContext();
82
83 //! Constructor By Default, the displayed objects are
84 //! automatically loaded.
85 Standard_EXPORT AIS_LocalContext(const Handle(AIS_InteractiveContext)& aCtx, const Standard_Integer anIndex, const Standard_Boolean LoadDisplayed = Standard_True, const Standard_Boolean AcceptStandardModes = Standard_True, const Standard_Boolean AcceptErase = Standard_False, const Standard_Boolean UseBothViewers = Standard_False);
86
87 //! authorize or not others contexts to erase
88 //! temporary displayed objects here;
89 void AcceptErase (const Standard_Boolean aStatus);
90
91 Standard_Boolean AcceptErase() const;
92
93 Standard_EXPORT void SetContext (const Handle(AIS_InteractiveContext)& aCtx);
94
016e5959 95 const Handle(AIS_Selection) Selection() const;
42cf5bc1 96
97 Standard_EXPORT void Terminate (const Standard_Boolean updateviewer = Standard_True);
98
42cf5bc1 99 //! returns true if done...
100 Standard_EXPORT Standard_Boolean Display (const Handle(AIS_InteractiveObject)& anInteractive, const Standard_Integer DisplayMode = 0, const Standard_Boolean AllowShapeDecomposition = Standard_True, const Standard_Integer ActivationMode = 0);
101
102 //! loads <anInteractive> with nodisplay...
103 //! returns true if done
104 Standard_EXPORT Standard_Boolean Load (const Handle(AIS_InteractiveObject)& anInteractive, const Standard_Boolean AllowShapeDecomposition = Standard_True, const Standard_Integer ActivationMode = 0);
105
106 //! returns true if done...
107 Standard_EXPORT Standard_Boolean Erase (const Handle(AIS_InteractiveObject)& anInteractive);
108
109 Standard_EXPORT Standard_Boolean Remove (const Handle(AIS_InteractiveObject)& aSelectable);
110
111 Standard_EXPORT Standard_Boolean ClearPrs (const Handle(AIS_InteractiveObject)& anInteractive, const Standard_Integer aMode);
112
113 //! allows or forbids the shape decomposition into
114 //! Activated Standard Mode for <aStoredObject>
115 //! does nothing if the object doesn't inherits
116 //! BasicShape from AIS
117 Standard_EXPORT void SetShapeDecomposition (const Handle(AIS_InteractiveObject)& aStoredObject, const Standard_Boolean aStatus);
118
119 //! according to <atype> , clears the different parts of
120 //! the selector (filters, modeof activation, objects...)
121 Standard_EXPORT void Clear (const AIS_ClearMode atype = AIS_CM_All);
122
123 //! optional : activation of a mode which is not 0 for a selectable...
124 Standard_EXPORT void ActivateMode (const Handle(AIS_InteractiveObject)& aSelectable, const Standard_Integer aMode);
125
126 Standard_EXPORT void DeactivateMode (const Handle(AIS_InteractiveObject)& aSelectable, const Standard_Integer aMode);
127
128 Standard_EXPORT void Deactivate (const Handle(AIS_InteractiveObject)& aSelectable);
129
130 //! decomposition of shapes into <aType>
131 Standard_EXPORT void ActivateStandardMode (const TopAbs_ShapeEnum aType);
132
133 Standard_EXPORT void DeactivateStandardMode (const TopAbs_ShapeEnum aType);
134
135 const TColStd_ListOfInteger& StandardModes() const;
136
137 Standard_EXPORT void AddFilter (const Handle(SelectMgr_Filter)& aFilter);
138
139 Standard_EXPORT void RemoveFilter (const Handle(SelectMgr_Filter)& aFilter);
140
141 const SelectMgr_ListOfFilter& ListOfFilter() const;
142
143 const Handle(SelectMgr_OrFilter)& Filter() const;
144
145 //! if <aStatus> = True , the shapes or subshapes detected
146 //! by the selector will be automatically hilighted in the
147 //! main viewer.
148 //! Else the user has to manage the detected shape outside the
149 //! Shape Selector....
150 void SetAutomaticHilight (const Standard_Boolean aStatus);
151
152 Standard_Boolean AutomaticHilight() const;
153
154 Standard_EXPORT AIS_StatusOfDetection MoveTo (const Standard_Integer theXpix, const Standard_Integer theYpix, const Handle(V3d_View)& theView, const Standard_Boolean theToRedrawImmediate);
155
156 //! returns True if more than one entity
157 //! was detected at the last Mouse position.
158 Standard_Boolean HasNextDetected() const;
159
160 //! returns True if last detected. the next detected will
161 //! be first one (endless loop)
162 Standard_EXPORT Standard_Integer HilightNextDetected (const Handle(V3d_View)& theView, const Standard_Boolean theToRedrawImmediate);
163
164 Standard_EXPORT Standard_Integer HilightPreviousDetected (const Handle(V3d_View)& theView, const Standard_Boolean theToRedrawImmediate);
165
166 //! returns True if something was done...
167 Standard_EXPORT Standard_Boolean UnhilightLastDetected (const Handle(V3d_View)& aView);
168
169 //! returns the number of selected
02974a19 170 Standard_EXPORT AIS_StatusOfPick AddSelect (const Handle(SelectMgr_EntityOwner)& theObject);
016e5959 171
42cf5bc1 172 Standard_EXPORT AIS_StatusOfPick Select (const Standard_Boolean updateviewer = Standard_True);
173
174 Standard_EXPORT AIS_StatusOfPick ShiftSelect (const Standard_Boolean updateviewer = Standard_True);
175
176 Standard_EXPORT AIS_StatusOfPick Select (const Standard_Integer XPMin, const Standard_Integer YPMin, const Standard_Integer XPMax, const Standard_Integer YPMax, const Handle(V3d_View)& aView, const Standard_Boolean updateviewer = Standard_True);
177
178 Standard_EXPORT AIS_StatusOfPick ShiftSelect (const Standard_Integer XPMin, const Standard_Integer YPMin, const Standard_Integer XPMax, const Standard_Integer YPMax, const Handle(V3d_View)& aView, const Standard_Boolean updateviewer = Standard_True);
179
180 Standard_EXPORT AIS_StatusOfPick Select (const TColgp_Array1OfPnt2d& Polyline, const Handle(V3d_View)& aView, const Standard_Boolean updateviewer = Standard_True);
181
182 Standard_EXPORT AIS_StatusOfPick ShiftSelect (const TColgp_Array1OfPnt2d& Polyline, const Handle(V3d_View)& aView, const Standard_Boolean updateviewer = Standard_True);
183
184 Standard_EXPORT void HilightPicked (const Standard_Boolean updateviewer = Standard_True);
185
186 Standard_EXPORT void UnhilightPicked (const Standard_Boolean updateviewer = Standard_True);
187
188 Standard_EXPORT void UpdateSelected (const Standard_Boolean updateviewer = Standard_True);
189
190 //! Part of advanced selection highlighting mechanism.
191 //! If no owners belonging to anobj are selected, calls anobj->ClearSelected(),
192 //! otherwise calls anobj->HilightSelected(). This method can be used to avoid
193 //! redrawing the whole selection belonging to several Selectable Objects.
194 Standard_EXPORT void UpdateSelected (const Handle(AIS_InteractiveObject)& anobj, const Standard_Boolean updateviewer = Standard_True);
195
196 //! useful to update selection with objects coming from
197 //! Collector or stack
198 Standard_EXPORT void SetSelected (const Handle(AIS_InteractiveObject)& anobj, const Standard_Boolean updateviewer = Standard_True);
199
200 //! useful to update selection with objects coming from
201 //! Collector or stack
202 Standard_EXPORT void AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& anobj, const Standard_Boolean updateviewer = Standard_True);
203
204 Standard_EXPORT void AddOrRemoveSelected (const TopoDS_Shape& aShape, const Standard_Boolean updateviewer = Standard_True);
205
206 Standard_EXPORT void AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner, const Standard_Boolean toUpdateViewer = Standard_True);
207
208 //! Clears local context selection.
209 //! @param toUpdateViewer [in] if TRUE the viewer will be updated.
210 Standard_EXPORT void ClearSelected (const Standard_Boolean toUpdateViewer = Standard_True);
211
212 //! Clears outdated selection and detection of owners for the
213 //! interactive object. Use this method if selection structures
214 //! of the interactive object have changed. The method unhilights
215 //! and removes outdated entity owners from lists of selected
216 //! and detected owners.
217 //! @param theIO [in] the interactive object.
218 //! @param toClearDeactivated [in] pass TRUE to treat deactivated
219 //! entity owners as 'outdated' when clearing the selection.
220 Standard_EXPORT void ClearOutdatedSelection (const Handle(AIS_InteractiveObject)& theIO, const Standard_Boolean toClearDeactivated);
221
222 Standard_Boolean HasDetected() const;
223
224
225 //! Initialization for iteration through mouse-detected objects in local context.
226 Standard_EXPORT void InitDetected();
227
228
229 //! @return true if there is more mouse-detected objects after the current one
230 //! during iteration through mouse-detected interactive objects.
231 Standard_EXPORT Standard_Boolean MoreDetected() const;
232
233
234 //! Gets next current object during iteration through mouse-detected
235 //! interactive objects.
236 Standard_EXPORT void NextDetected();
237
238
239 //! @return current mouse-detected shape or empty (null) shape, if current interactive object
240 //! is not a shape (AIS_Shape) or there is no current mouse-detected interactive object at all.
241 Standard_EXPORT const TopoDS_Shape& DetectedCurrentShape() const;
242
243
244 //! @return current mouse-detected interactive object or null object if there is no current detected.
245 Standard_EXPORT Handle(AIS_InteractiveObject) DetectedCurrentObject() const;
246
247 Standard_EXPORT Standard_Boolean HasDetectedShape() const;
248
249 Standard_EXPORT const TopoDS_Shape& DetectedShape() const;
250
251 Standard_EXPORT Handle(AIS_InteractiveObject) DetectedInteractive() const;
252
253 Standard_EXPORT Handle(SelectMgr_EntityOwner) DetectedOwner() const;
254
255 Standard_EXPORT void InitSelected();
256
257 Standard_EXPORT Standard_Boolean MoreSelected() const;
258
259 Standard_EXPORT void NextSelected();
260
261 //! returns TRUE if the detected entity is a shape
262 //! coming from a Decomposition of an element.
263 Standard_EXPORT Standard_Boolean HasShape() const;
264
265 //! returns true if current selection is not empty
266 //! and the owner of selected object contains a shape.
267 //! This method does not take into account decomposition
268 //! status of detected shape.
269 Standard_EXPORT Standard_Boolean HasSelectedShape() const;
270
271 Standard_EXPORT TopoDS_Shape SelectedShape() const;
272
273 Standard_EXPORT Handle(SelectMgr_EntityOwner) SelectedOwner() const;
274
275 Standard_EXPORT Standard_Boolean IsSelected (const Handle(AIS_InteractiveObject)& aniobj) const;
276
277 Standard_EXPORT Standard_Boolean IsSelected (const Handle(SelectMgr_EntityOwner)& anOwner) const;
278
279 Standard_EXPORT Handle(AIS_InteractiveObject) SelectedInteractive() const;
280
281 //! returns TRUE if an interactive element
282 //! was associated with the current picked entity.
283 Standard_EXPORT Standard_Boolean HasApplicative() const;
284
285 Standard_EXPORT const Handle(Standard_Transient)& SelectedApplicative() const;
286
287 Standard_EXPORT void SetDisplayPriority (const Handle(AIS_InteractiveObject)& anObject, const Standard_Integer Prior);
288
289 Standard_EXPORT Standard_Integer DisplayedObjects (TColStd_MapOfTransient& theMapToFill) const;
290
291 Standard_EXPORT Standard_Boolean IsIn (const Handle(AIS_InteractiveObject)& anObject) const;
292
293 Standard_EXPORT Standard_Boolean IsDisplayed (const Handle(AIS_InteractiveObject)& anObject) const;
294
295 Standard_EXPORT Standard_Boolean IsDisplayed (const Handle(AIS_InteractiveObject)& anObject, const Standard_Integer aMode) const;
296
297 Standard_EXPORT const TColStd_ListOfInteger& SelectionModes (const Handle(AIS_InteractiveObject)& anObject) const;
298
299 Standard_EXPORT void SubIntensityOn (const Handle(AIS_InteractiveObject)& anObject);
300
301 Standard_EXPORT void SubIntensityOff (const Handle(AIS_InteractiveObject)& anObject);
302
303 Standard_EXPORT void Hilight (const Handle(AIS_InteractiveObject)& anObject);
304
8e5fb5ea 305 Standard_EXPORT void Hilight (const Handle(AIS_InteractiveObject)& theObj,
306 const Handle(Graphic3d_HighlightStyle)& theStyle);
42cf5bc1 307
308 Standard_EXPORT void Unhilight (const Handle(AIS_InteractiveObject)& anObject);
309
310 Standard_EXPORT Standard_Boolean IsHilighted (const Handle(AIS_InteractiveObject)& anObject) const;
311
8e5fb5ea 312 Standard_EXPORT Standard_Boolean HighlightStyle (const Handle(AIS_InteractiveObject)& theObject,
313 Handle(Graphic3d_HighlightStyle)& theStyle) const;
42cf5bc1 314
315 //! Define the current selection sensitivity for
316 //! this local context according to the view size.
3bf9a45f 317 Standard_EXPORT void SetPixelTolerance (const Standard_Integer aPrecision = 2);
42cf5bc1 318
319 //! Returns the pixel tolerance.
3bf9a45f 320 Standard_EXPORT Standard_Integer PixelTolerance() const;
8a1170ad 321
322 //! Allows to manage sensitivity of a particular selection of interactive object theObject
323 //! and changes previous sensitivity value of all sensitive entities in selection with theMode
324 //! to the given theNewSensitivity.
325 Standard_EXPORT void SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
326 const Standard_Integer theMode,
327 const Standard_Integer theNewSensitivity);
328
42cf5bc1 329 //! Resets the transient list of presentations previously displayed in immediate mode
330 //! and begins accumulation of new list by following AddToImmediateList()/Color()/Highlight() calls.
331 Standard_EXPORT Standard_Boolean BeginImmediateDraw();
332
333 //! Resets the transient list of presentations previously displayed in immediate mode.
334 Standard_EXPORT virtual void ClearImmediateDraw();
335
336 //! Stores presentation theMode of object theObj in the transient list of presentations to be displayed in immediate mode.
337 //! Will be taken in account in EndImmediateDraw method.
338 Standard_EXPORT Standard_Boolean ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj, const Standard_Integer theMode = 0);
339
340 //! Allows rapid drawing of the view theView by avoiding an update of the whole background.
c3282ec1 341 Standard_EXPORT Standard_Boolean EndImmediateDraw (const Handle(V3d_Viewer)& theViewer);
42cf5bc1 342
343 //! Returns true if Presentation Manager is accumulating transient list of presentations to be displayed in immediate mode.
344 Standard_EXPORT Standard_Boolean IsImmediateModeOn() const;
345
346 Standard_EXPORT TCollection_AsciiString Status() const;
347
348 Standard_EXPORT const Handle(AIS_LocalStatus)& Status (const Handle(AIS_InteractiveObject)& anObject) const;
349
350 Standard_EXPORT void LoadContextObjects();
351
352 Standard_EXPORT void UnloadContextObjects();
353
354 Standard_EXPORT void DisplaySensitive (const Handle(V3d_View)& aView);
355
356 Standard_EXPORT void ClearSensitive (const Handle(V3d_View)& aView);
357
358 const Handle(StdSelect_ViewerSelector3d)& MainSelector() const;
359
360 Standard_EXPORT Handle(SelectMgr_EntityOwner) FindSelectedOwnerFromIO (const Handle(AIS_InteractiveObject)& anIObj) const;
361
362 Standard_EXPORT Handle(SelectMgr_EntityOwner) FindSelectedOwnerFromShape (const TopoDS_Shape& aShape) const;
363
325e442b 364 //! Iterates through all interactive objects of local context and activates selection modes
365 //! stored in local status
366 Standard_EXPORT void RestoreActivatedModes() const;
367
42cf5bc1 368
369
370
92efcf78 371 DEFINE_STANDARD_RTTIEXT(AIS_LocalContext,MMgt_TShared)
42cf5bc1 372
373protected:
374
8e5fb5ea 375 //! Helper function that returns correct dynamic highlight style for the object:
376 //! if custom style is defined via object's highlight drawer, it will be used. Otherwise,
377 //! dynamic highlight style of interactive context will be returned.
378 //! @param theObj [in] the object to check
379 Standard_EXPORT const Handle(Graphic3d_HighlightStyle)& getHiStyle (const Handle(SelectMgr_SelectableObject)& theObj) const;
42cf5bc1 380
8e5fb5ea 381 //! Helper function that returns correct selection style for the object:
382 //! if custom style is defined via object's highlight drawer, it will be used. Otherwise,
383 //! selection style of interactive context will be returned.
384 //! @param theObj [in] the object to check
385 Standard_EXPORT const Handle(Graphic3d_HighlightStyle)& getSelStyle (const Handle(AIS_InteractiveObject)& theObj) const;
42cf5bc1 386
387private:
388
389
390 Standard_EXPORT void Process (const Handle(SelectMgr_SelectableObject)& anObject);
391
392 Standard_EXPORT void Process();
393
394 Standard_EXPORT void ActivateStandardModes (const Handle(SelectMgr_SelectableObject)& anObject);
395
396 Standard_EXPORT void manageDetected (const Handle(SelectMgr_EntityOwner)& thePickOwner, const Handle(V3d_View)& theView, const Standard_Boolean theToRedrawImmediate);
397
398 //! returns 0 if the detected entity was Not FilterOK...
399 Standard_Integer DetectedIndex();
400
401 Standard_EXPORT void Hilight (const Handle(SelectMgr_EntityOwner)& Own, const Handle(V3d_View)& aview);
402
403 Standard_EXPORT void Unhilight (const Handle(SelectMgr_EntityOwner)& Ownr, const Handle(V3d_View)& aview);
404
405 Standard_EXPORT void ClearObjects();
406
407 Standard_EXPORT void ClearDetected();
408
409 Standard_EXPORT Standard_Boolean IsDecompositionOn() const;
410
411 Standard_EXPORT Standard_Boolean IsShape (const Standard_Integer anIndex) const;
412
413 Standard_EXPORT Standard_Boolean IsValidForSelection (const Handle(AIS_InteractiveObject)& anIObj) const;
414
415 Standard_Boolean IsValidIndex (const Standard_Integer anIndex) const;
416
417 Standard_EXPORT Standard_Boolean ComesFromDecomposition (const Standard_Integer aPickedIndex) const;
418
419 Standard_EXPORT Standard_Boolean HasFilters (const TopAbs_ShapeEnum aType) const;
420
421 Handle(AIS_InteractiveContext) myCTX;
422 Standard_Boolean myLoadDisplayed;
423 Standard_Boolean myAcceptStdMode;
424 Standard_Boolean myAcceptErase;
425 Handle(SelectMgr_SelectionManager) mySM;
426 Handle(StdSelect_ViewerSelector3d) myMainVS;
427 Handle(PrsMgr_PresentationManager3d) myMainPM;
42cf5bc1 428 Handle(StdSelect_ViewerSelector3d) myCollVS;
429 AIS_DataMapOfSelStat myActiveObjects;
430 Handle(SelectMgr_OrFilter) myFilters;
431 TColStd_ListOfInteger myListOfStandardMode;
432 Handle(SelectMgr_Filter) myStdFilters[9];
433 Standard_Boolean myAutoHilight;
434 Handle(SelectMgr_IndexedMapOfOwner) myMapOfOwner;
016e5959 435 Handle(AIS_Selection) mySelection;
42cf5bc1 436 Standard_Integer mylastindex;
437 Standard_Integer mylastgood;
438 Standard_Integer myCurrentOwner;
439 TColStd_SequenceOfInteger myDetectedSeq;
440 Standard_Integer myCurDetected;
441 AIS_SequenceOfInteractive myAISDetectedSeq;
442 Standard_Integer myAISCurDetected;
8e5fb5ea 443 Handle(Graphic3d_HighlightStyle) mySubintStyle;
42cf5bc1 444
445};
446
447
448#include <AIS_LocalContext.lxx>
449
450
451
452
453
454#endif // _AIS_LocalContext_HeaderFile