1 // Created on: 1997-01-29
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
19 #include <AIS_GlobalStatus.hxx>
20 #include <AIS_InteractiveContext.hxx>
21 #include <AIS_InteractiveObject.hxx>
22 #include <AIS_Selection.hxx>
23 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
24 #include <Graphic3d_MapOfStructure.hxx>
25 #include <Graphic3d_Structure.hxx>
26 #include <Graphic3d_StructureManager.hxx>
27 #include <Prs3d_BasicAspect.hxx>
28 #include <Prs3d_LineAspect.hxx>
29 #include <Quantity_Color.hxx>
30 #include <SelectMgr_EntityOwner.hxx>
31 #include <SelectMgr_Filter.hxx>
32 #include <SelectMgr_OrFilter.hxx>
33 #include <SelectMgr_SelectionManager.hxx>
34 #include <Standard_Transient.hxx>
35 #include <StdSelect_ViewerSelector3d.hxx>
36 #include <TCollection_AsciiString.hxx>
37 #include <TCollection_ExtendedString.hxx>
38 #include <TColStd_ListIteratorOfListOfInteger.hxx>
39 #include <TopLoc_Location.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <V3d_View.hxx>
42 #include <V3d_Viewer.hxx>
44 //=======================================================================
45 //function : SetSelectionModeActive
47 //=======================================================================
48 void AIS_InteractiveContext::SetSelectionModeActive (const Handle(AIS_InteractiveObject)& theObj,
49 const Standard_Integer theMode,
50 const Standard_Boolean theIsActive,
51 const AIS_SelectionModesConcurrency theActiveFilter,
52 const Standard_Boolean theIsForce)
59 const Handle(AIS_GlobalStatus)* aStat = myObjects.Seek (theObj);
67 && theActiveFilter == AIS_SelectionModesConcurrency_Single))
69 if ((*aStat)->GraphicStatus() == AIS_DS_Displayed
74 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
76 mgrSelector->Deactivate (theObj, aModeIter.Value());
81 mgrSelector->Deactivate (theObj, theMode);
87 (*aStat)->ClearSelectionModes();
91 (*aStat)->RemoveSelectionMode (theMode);
95 else if (theMode == -1)
100 if ((*aStat)->SelectionModes().Size() == 1
101 && (*aStat)->SelectionModes().First() == theMode)
106 if ((*aStat)->GraphicStatus() == AIS_DS_Displayed
109 switch (theActiveFilter)
111 case AIS_SelectionModesConcurrency_Single:
113 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
115 mgrSelector->Deactivate (theObj, aModeIter.Value());
117 (*aStat)->ClearSelectionModes();
120 case AIS_SelectionModesConcurrency_GlobalOrLocal:
122 const Standard_Integer aGlobSelMode = theObj->GlobalSelectionMode();
123 TColStd_ListOfInteger aRemovedModes;
124 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
126 if ((theMode == aGlobSelMode && aModeIter.Value() != aGlobSelMode)
127 || (theMode != aGlobSelMode && aModeIter.Value() == aGlobSelMode))
129 mgrSelector->Deactivate (theObj, aModeIter.Value());
130 aRemovedModes.Append (aModeIter.Value());
133 if (aRemovedModes.Size() == (*aStat)->SelectionModes().Size())
135 (*aStat)->ClearSelectionModes();
139 for (TColStd_ListIteratorOfListOfInteger aModeIter (aRemovedModes); aModeIter.More(); aModeIter.Next())
141 (*aStat)->RemoveSelectionMode (aModeIter.Value());
146 case AIS_SelectionModesConcurrency_Multiple:
151 mgrSelector->Activate (theObj, theMode);
153 (*aStat)->AddSelectionMode (theMode);
156 // ============================================================================
157 // function : Activate
159 // ============================================================================
160 void AIS_InteractiveContext::Activate (const Standard_Integer theMode,
161 const Standard_Boolean theIsForce)
163 AIS_ListOfInteractive aDisplayedObjects;
164 DisplayedObjects (aDisplayedObjects);
166 for (AIS_ListIteratorOfListOfInteractive anIter (aDisplayedObjects); anIter.More(); anIter.Next())
168 Load (anIter.Value(), -1);
169 Activate (anIter.Value(), theMode, theIsForce);
174 // ============================================================================
175 // function : Deactivate
177 // ============================================================================
178 void AIS_InteractiveContext::Deactivate (const Standard_Integer theMode)
180 AIS_ListOfInteractive aDisplayedObjects;
181 DisplayedObjects (aDisplayedObjects);
183 for (AIS_ListIteratorOfListOfInteractive anIter (aDisplayedObjects); anIter.More(); anIter.Next())
185 Deactivate (anIter.Value(), theMode);
189 // ============================================================================
190 // function : Deactivate
192 // ============================================================================
193 void AIS_InteractiveContext::Deactivate()
195 AIS_ListOfInteractive aDisplayedObjects;
196 DisplayedObjects (aDisplayedObjects);
198 for (AIS_ListIteratorOfListOfInteractive anIter (aDisplayedObjects); anIter.More(); anIter.Next())
200 Deactivate (anIter.Value());
204 //=======================================================================
205 //function : ActivatedModes
207 //=======================================================================
208 void AIS_InteractiveContext::ActivatedModes (const Handle(AIS_InteractiveObject)& theObj,
209 TColStd_ListOfInteger& theList) const
211 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
214 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStatus)->SelectionModes()); aModeIter.More(); aModeIter.Next())
216 theList.Append (aModeIter.Value());
221 //=======================================================================
222 //function : SubIntensityOn
224 //=======================================================================
225 void AIS_InteractiveContext::
226 SubIntensityOn(const Handle(AIS_InteractiveObject)& anIObj,
227 const Standard_Boolean updateviewer)
229 turnOnSubintensity (anIObj);
233 //=======================================================================
234 //function : SubIntensityOff
236 //=======================================================================
238 void AIS_InteractiveContext::SubIntensityOff (const Handle(AIS_InteractiveObject)& theObj,
239 const Standard_Boolean theToUpdateViewer)
241 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
243 || !(*aStatus)->IsSubIntensityOn())
248 (*aStatus)->SubIntensityOff();
249 Standard_Boolean toUpdateMain = Standard_False;
250 if ((*aStatus)->GraphicStatus() == AIS_DS_Displayed)
252 myMainPM->Unhighlight (theObj);
253 toUpdateMain = Standard_True;
256 if (IsSelected (theObj))
258 highlightSelected (theObj->GlobalSelOwner());
261 if (theToUpdateViewer && toUpdateMain)
267 //=======================================================================
268 //function : AddFilter
270 //=======================================================================
271 void AIS_InteractiveContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter)
273 myFilters->Add(aFilter);
276 //=======================================================================
277 //function : RemoveFilter
279 //=======================================================================
280 void AIS_InteractiveContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter)
282 myFilters->Remove(aFilter);
285 //=======================================================================
286 //function : RemoveFilters
288 //=======================================================================
290 void AIS_InteractiveContext::RemoveFilters()
295 //=======================================================================
298 //=======================================================================
299 const SelectMgr_ListOfFilter& AIS_InteractiveContext::Filters() const
301 return myFilters->StoredFilters();
304 //=======================================================================
305 //function : DisplayActiveSensitive
307 //=======================================================================
308 void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(V3d_View)& aviou)
310 myMainSel->DisplaySensitive(aviou);
312 //=======================================================================
313 //function : DisplayActiveSensitive
315 //=======================================================================
317 void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(AIS_InteractiveObject)& theObj,
318 const Handle(V3d_View)& theView)
320 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
326 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStatus)->SelectionModes()); aModeIter.More(); aModeIter.Next())
328 const Handle(SelectMgr_Selection)& aSel = theObj->Selection (aModeIter.Value());
329 myMainSel->DisplaySensitive (aSel, theObj->Transformation(), theView, Standard_False);
333 //=======================================================================
334 //function : ClearActiveSensitive
336 //=======================================================================
337 void AIS_InteractiveContext::ClearActiveSensitive (const Handle(V3d_View)& theView)
339 myMainSel->ClearSensitive (theView);
342 //=======================================================================
343 //function : PurgeDisplay
345 //=======================================================================
347 Standard_Integer AIS_InteractiveContext::PurgeDisplay()
349 Standard_Integer NbStr = PurgeViewer(myMainVwr);
355 //=======================================================================
356 //function : PurgeViewer
358 //=======================================================================
359 Standard_Integer AIS_InteractiveContext::PurgeViewer(const Handle(V3d_Viewer)& Vwr)
361 Handle(Graphic3d_StructureManager) GSM = Vwr->StructureManager();
362 Standard_Integer NbCleared(0);
363 Graphic3d_MapOfStructure SOS;
364 GSM->DisplayedStructures(SOS);
366 Handle(Graphic3d_Structure) G;
367 for(Graphic3d_MapIteratorOfMapOfStructure It(SOS); It.More();It.Next()){
369 Standard_Address Add = G->Owner();
372 G->Clear();// it means that it is not referenced as a presentation of InterfactiveObject...
375 Handle(AIS_InteractiveObject) IO = (AIS_InteractiveObject*)Add;
376 if(!myObjects.IsBound(IO)){
384 //=======================================================================
385 //function : IsImmediateModeOn
387 //=======================================================================
389 Standard_Boolean AIS_InteractiveContext::IsImmediateModeOn() const
391 return myMainPM->IsImmediateModeOn();
394 //=======================================================================
395 //function : BeginImmediateDraw
397 //=======================================================================
399 Standard_Boolean AIS_InteractiveContext::BeginImmediateDraw()
401 if (myMainPM->IsImmediateModeOn())
403 myMainPM->BeginImmediateDraw();
404 return Standard_True;
406 return Standard_False;
409 //=======================================================================
410 //function : ImmediateAdd
412 //=======================================================================
414 Standard_Boolean AIS_InteractiveContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj,
415 const Standard_Integer theMode)
417 if (!myMainPM->IsImmediateModeOn())
419 return Standard_False;
422 myMainPM->AddToImmediateList (myMainPM->Presentation (theObj, theMode));
423 return Standard_True;
426 //=======================================================================
427 //function : EndImmediateDraw
429 //=======================================================================
431 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw (const Handle(V3d_View)& theView)
433 if (!myMainPM->IsImmediateModeOn())
435 return Standard_False;
438 myMainPM->EndImmediateDraw (theView->Viewer());
439 return Standard_True;
442 //=======================================================================
443 //function : EndImmediateDraw
445 //=======================================================================
447 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw()
449 if (!myMainPM->IsImmediateModeOn())
451 return Standard_False;
454 myMainPM->EndImmediateDraw (myMainVwr);
455 return Standard_True;