b311480e |
1 | // Created on: 1997-01-29 |
2 | // Created by: Robert COUBLANC |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx> |
19 | #include <AIS_GlobalStatus.hxx> |
20 | #include <AIS_InteractiveContext.hxx> |
21 | #include <AIS_InteractiveObject.hxx> |
7fd59977 |
22 | #include <AIS_Selection.hxx> |
42cf5bc1 |
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> |
f751596e |
35 | #include <StdSelect_ViewerSelector3d.hxx> |
42cf5bc1 |
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> |
f751596e |
43 | |
7fd59977 |
44 | //======================================================================= |
f47849f4 |
45 | //function : SetSelectionModeActive |
46 | //purpose : |
7fd59977 |
47 | //======================================================================= |
f47849f4 |
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) |
7fd59977 |
53 | { |
f47849f4 |
54 | if (theObj.IsNull()) |
55 | { |
56 | return; |
57 | } |
f47849f4 |
58 | |
59 | const Handle(AIS_GlobalStatus)* aStat = myObjects.Seek (theObj); |
60 | if (aStat == NULL) |
61 | { |
62 | return; |
7fd59977 |
63 | } |
f47849f4 |
64 | |
65 | if (!theIsActive |
66 | || (theMode == -1 |
67 | && theActiveFilter == AIS_SelectionModesConcurrency_Single)) |
68 | { |
69 | if ((*aStat)->GraphicStatus() == AIS_DS_Displayed |
70 | || theIsForce) |
71 | { |
72 | if (theMode == -1) |
73 | { |
74 | for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next()) |
75 | { |
68dcee02 |
76 | mgrSelector->Deactivate (theObj, aModeIter.Value()); |
f47849f4 |
77 | } |
78 | } |
79 | else |
80 | { |
68dcee02 |
81 | mgrSelector->Deactivate (theObj, theMode); |
f47849f4 |
82 | } |
83 | } |
84 | |
85 | if (theMode == -1) |
86 | { |
87 | (*aStat)->ClearSelectionModes(); |
88 | } |
89 | else |
90 | { |
91 | (*aStat)->RemoveSelectionMode (theMode); |
92 | } |
93 | return; |
94 | } |
95 | else if (theMode == -1) |
96 | { |
97 | return; |
98 | } |
99 | |
100 | if ((*aStat)->SelectionModes().Size() == 1 |
101 | && (*aStat)->SelectionModes().First() == theMode) |
102 | { |
103 | return; |
104 | } |
105 | |
106 | if ((*aStat)->GraphicStatus() == AIS_DS_Displayed |
107 | || theIsForce) |
108 | { |
109 | switch (theActiveFilter) |
110 | { |
111 | case AIS_SelectionModesConcurrency_Single: |
112 | { |
113 | for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next()) |
114 | { |
68dcee02 |
115 | mgrSelector->Deactivate (theObj, aModeIter.Value()); |
f47849f4 |
116 | } |
117 | (*aStat)->ClearSelectionModes(); |
118 | break; |
119 | } |
120 | case AIS_SelectionModesConcurrency_GlobalOrLocal: |
121 | { |
122 | const Standard_Integer aGlobSelMode = theObj->GlobalSelectionMode(); |
123 | TColStd_ListOfInteger aRemovedModes; |
124 | for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next()) |
125 | { |
126 | if ((theMode == aGlobSelMode && aModeIter.Value() != aGlobSelMode) |
127 | || (theMode != aGlobSelMode && aModeIter.Value() == aGlobSelMode)) |
128 | { |
68dcee02 |
129 | mgrSelector->Deactivate (theObj, aModeIter.Value()); |
f47849f4 |
130 | aRemovedModes.Append (aModeIter.Value()); |
131 | } |
132 | } |
133 | if (aRemovedModes.Size() == (*aStat)->SelectionModes().Size()) |
134 | { |
135 | (*aStat)->ClearSelectionModes(); |
136 | } |
137 | else |
138 | { |
139 | for (TColStd_ListIteratorOfListOfInteger aModeIter (aRemovedModes); aModeIter.More(); aModeIter.Next()) |
140 | { |
141 | (*aStat)->RemoveSelectionMode (aModeIter.Value()); |
142 | } |
143 | } |
144 | break; |
145 | } |
146 | case AIS_SelectionModesConcurrency_Multiple: |
147 | { |
148 | break; |
149 | } |
150 | } |
68dcee02 |
151 | mgrSelector->Activate (theObj, theMode); |
f47849f4 |
152 | } |
153 | (*aStat)->AddSelectionMode (theMode); |
7fd59977 |
154 | } |
155 | |
404c8936 |
156 | // ============================================================================ |
157 | // function : Activate |
158 | // purpose : |
159 | // ============================================================================ |
160 | void AIS_InteractiveContext::Activate (const Standard_Integer theMode, |
161 | const Standard_Boolean theIsForce) |
162 | { |
163 | AIS_ListOfInteractive aDisplayedObjects; |
164 | DisplayedObjects (aDisplayedObjects); |
165 | |
166 | for (AIS_ListIteratorOfListOfInteractive anIter (aDisplayedObjects); anIter.More(); anIter.Next()) |
167 | { |
68dcee02 |
168 | Load (anIter.Value(), -1); |
404c8936 |
169 | Activate (anIter.Value(), theMode, theIsForce); |
170 | } |
171 | |
172 | } |
173 | |
404c8936 |
174 | // ============================================================================ |
175 | // function : Deactivate |
176 | // purpose : |
177 | // ============================================================================ |
178 | void AIS_InteractiveContext::Deactivate (const Standard_Integer theMode) |
179 | { |
180 | AIS_ListOfInteractive aDisplayedObjects; |
181 | DisplayedObjects (aDisplayedObjects); |
182 | |
183 | for (AIS_ListIteratorOfListOfInteractive anIter (aDisplayedObjects); anIter.More(); anIter.Next()) |
184 | { |
185 | Deactivate (anIter.Value(), theMode); |
186 | } |
187 | } |
188 | |
189 | // ============================================================================ |
190 | // function : Deactivate |
191 | // purpose : |
192 | // ============================================================================ |
193 | void AIS_InteractiveContext::Deactivate() |
194 | { |
195 | AIS_ListOfInteractive aDisplayedObjects; |
196 | DisplayedObjects (aDisplayedObjects); |
197 | |
198 | for (AIS_ListIteratorOfListOfInteractive anIter (aDisplayedObjects); anIter.More(); anIter.Next()) |
199 | { |
200 | Deactivate (anIter.Value()); |
201 | } |
202 | } |
203 | |
7fd59977 |
204 | //======================================================================= |
205 | //function : ActivatedModes |
68dcee02 |
206 | //purpose : |
7fd59977 |
207 | //======================================================================= |
68dcee02 |
208 | void AIS_InteractiveContext::ActivatedModes (const Handle(AIS_InteractiveObject)& theObj, |
209 | TColStd_ListOfInteger& theList) const |
7fd59977 |
210 | { |
68dcee02 |
211 | const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj); |
212 | if (aStatus != NULL) |
213 | { |
214 | for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStatus)->SelectionModes()); aModeIter.More(); aModeIter.Next()) |
215 | { |
216 | theList.Append (aModeIter.Value()); |
7fd59977 |
217 | } |
218 | } |
219 | } |
220 | |
7fd59977 |
221 | //======================================================================= |
222 | //function : SubIntensityOn |
223 | //purpose : |
224 | //======================================================================= |
225 | void AIS_InteractiveContext:: |
226 | SubIntensityOn(const Handle(AIS_InteractiveObject)& anIObj, |
227 | const Standard_Boolean updateviewer) |
228 | { |
68dcee02 |
229 | turnOnSubintensity (anIObj); |
8e5fb5ea |
230 | if (updateviewer) |
231 | myMainVwr->Update(); |
7fd59977 |
232 | } |
233 | //======================================================================= |
234 | //function : SubIntensityOff |
235 | //purpose : |
236 | //======================================================================= |
237 | |
68dcee02 |
238 | void AIS_InteractiveContext::SubIntensityOff (const Handle(AIS_InteractiveObject)& theObj, |
239 | const Standard_Boolean theToUpdateViewer) |
7fd59977 |
240 | { |
68dcee02 |
241 | const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj); |
242 | if (aStatus == NULL |
243 | || !(*aStatus)->IsSubIntensityOn()) |
244 | { |
245 | return; |
246 | } |
247 | |
248 | (*aStatus)->SubIntensityOff(); |
249 | Standard_Boolean toUpdateMain = Standard_False; |
250 | if ((*aStatus)->GraphicStatus() == AIS_DS_Displayed) |
251 | { |
252 | myMainPM->Unhighlight (theObj); |
253 | toUpdateMain = Standard_True; |
7fd59977 |
254 | } |
7fd59977 |
255 | |
68dcee02 |
256 | if (IsSelected (theObj)) |
257 | { |
258 | highlightSelected (theObj->GlobalSelOwner()); |
7fd59977 |
259 | } |
7fd59977 |
260 | |
68dcee02 |
261 | if (theToUpdateViewer && toUpdateMain) |
262 | { |
8e5fb5ea |
263 | myMainVwr->Update(); |
7fd59977 |
264 | } |
7fd59977 |
265 | } |
266 | |
267 | //======================================================================= |
268 | //function : AddFilter |
269 | //purpose : |
270 | //======================================================================= |
271 | void AIS_InteractiveContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter) |
272 | { |
68dcee02 |
273 | myFilters->Add(aFilter); |
7fd59977 |
274 | } |
275 | |
276 | //======================================================================= |
277 | //function : RemoveFilter |
278 | //purpose : |
279 | //======================================================================= |
280 | void AIS_InteractiveContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter) |
281 | { |
68dcee02 |
282 | myFilters->Remove(aFilter); |
7fd59977 |
283 | } |
284 | |
285 | //======================================================================= |
286 | //function : RemoveFilters |
287 | //purpose : |
288 | //======================================================================= |
289 | |
290 | void AIS_InteractiveContext::RemoveFilters() |
291 | { |
68dcee02 |
292 | myFilters->Clear(); |
7fd59977 |
293 | } |
294 | |
295 | //======================================================================= |
296 | //function : Filters |
297 | //purpose : |
298 | //======================================================================= |
299 | const SelectMgr_ListOfFilter& AIS_InteractiveContext::Filters() const |
300 | { |
7fd59977 |
301 | return myFilters->StoredFilters(); |
302 | } |
303 | |
7fd59977 |
304 | //======================================================================= |
305 | //function : DisplayActiveSensitive |
306 | //purpose : |
307 | //======================================================================= |
308 | void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(V3d_View)& aviou) |
309 | { |
68dcee02 |
310 | myMainSel->DisplaySensitive(aviou); |
7fd59977 |
311 | } |
312 | //======================================================================= |
313 | //function : DisplayActiveSensitive |
314 | //purpose : |
315 | //======================================================================= |
316 | |
68dcee02 |
317 | void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(AIS_InteractiveObject)& theObj, |
318 | const Handle(V3d_View)& theView) |
7fd59977 |
319 | { |
68dcee02 |
320 | const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj); |
321 | if (aStatus == NULL) |
322 | { |
323 | return; |
7fd59977 |
324 | } |
68dcee02 |
325 | |
326 | for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStatus)->SelectionModes()); aModeIter.More(); aModeIter.Next()) |
327 | { |
328 | const Handle(SelectMgr_Selection)& aSel = theObj->Selection (aModeIter.Value()); |
329 | myMainSel->DisplaySensitive (aSel, theObj->Transformation(), theView, Standard_False); |
7fd59977 |
330 | } |
7fd59977 |
331 | } |
332 | |
7fd59977 |
333 | //======================================================================= |
334 | //function : ClearActiveSensitive |
335 | //purpose : |
336 | //======================================================================= |
68dcee02 |
337 | void AIS_InteractiveContext::ClearActiveSensitive (const Handle(V3d_View)& theView) |
7fd59977 |
338 | { |
68dcee02 |
339 | myMainSel->ClearSensitive (theView); |
7fd59977 |
340 | } |
341 | |
7fd59977 |
342 | //======================================================================= |
343 | //function : PurgeDisplay |
344 | //purpose : |
345 | //======================================================================= |
346 | |
eb4320f2 |
347 | Standard_Integer AIS_InteractiveContext::PurgeDisplay() |
7fd59977 |
348 | { |
7fd59977 |
349 | Standard_Integer NbStr = PurgeViewer(myMainVwr); |
7fd59977 |
350 | myMainVwr->Update(); |
351 | return NbStr; |
7fd59977 |
352 | } |
353 | |
354 | |
355 | //======================================================================= |
356 | //function : PurgeViewer |
357 | //purpose : |
358 | //======================================================================= |
359 | Standard_Integer AIS_InteractiveContext::PurgeViewer(const Handle(V3d_Viewer)& Vwr) |
360 | { |
c357e426 |
361 | Handle(Graphic3d_StructureManager) GSM = Vwr->StructureManager(); |
7fd59977 |
362 | Standard_Integer NbCleared(0); |
363 | Graphic3d_MapOfStructure SOS; |
364 | GSM->DisplayedStructures(SOS); |
365 | |
366 | Handle(Graphic3d_Structure) G; |
367 | for(Graphic3d_MapIteratorOfMapOfStructure It(SOS); It.More();It.Next()){ |
368 | G = It.Key(); |
369 | Standard_Address Add = G->Owner(); |
370 | if(Add==NULL){ |
371 | G->Erase(); |
81bba717 |
372 | G->Clear();// it means that it is not referenced as a presentation of InterfactiveObject... |
7fd59977 |
373 | NbCleared++; |
374 | } |
375 | Handle(AIS_InteractiveObject) IO = (AIS_InteractiveObject*)Add; |
376 | if(!myObjects.IsBound(IO)){ |
377 | G->Erase(); |
378 | NbCleared++; |
379 | } |
380 | } |
381 | return NbCleared; |
382 | } |
383 | |
7fd59977 |
384 | //======================================================================= |
385 | //function : IsImmediateModeOn |
679ecdee |
386 | //purpose : |
7fd59977 |
387 | //======================================================================= |
679ecdee |
388 | |
7fd59977 |
389 | Standard_Boolean AIS_InteractiveContext::IsImmediateModeOn() const |
390 | { |
8c088c52 |
391 | return myMainPM->IsImmediateModeOn(); |
7fd59977 |
392 | } |
393 | |
7fd59977 |
394 | //======================================================================= |
679ecdee |
395 | //function : BeginImmediateDraw |
396 | //purpose : |
7fd59977 |
397 | //======================================================================= |
398 | |
679ecdee |
399 | Standard_Boolean AIS_InteractiveContext::BeginImmediateDraw() |
400 | { |
8c088c52 |
401 | if (myMainPM->IsImmediateModeOn()) |
402 | { |
403 | myMainPM->BeginImmediateDraw(); |
404 | return Standard_True; |
405 | } |
406 | return Standard_False; |
7fd59977 |
407 | } |
408 | |
409 | //======================================================================= |
679ecdee |
410 | //function : ImmediateAdd |
411 | //purpose : |
7fd59977 |
412 | //======================================================================= |
413 | |
679ecdee |
414 | Standard_Boolean AIS_InteractiveContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj, |
415 | const Standard_Integer theMode) |
7fd59977 |
416 | { |
8c088c52 |
417 | if (!myMainPM->IsImmediateModeOn()) |
418 | { |
419 | return Standard_False; |
420 | } |
421 | |
7dd7c146 |
422 | myMainPM->AddToImmediateList (myMainPM->Presentation (theObj, theMode)); |
8c088c52 |
423 | return Standard_True; |
7fd59977 |
424 | } |
425 | |
426 | //======================================================================= |
427 | //function : EndImmediateDraw |
679ecdee |
428 | //purpose : |
7fd59977 |
429 | //======================================================================= |
430 | |
679ecdee |
431 | Standard_Boolean AIS_InteractiveContext::EndImmediateDraw (const Handle(V3d_View)& theView) |
7fd59977 |
432 | { |
8c088c52 |
433 | if (!myMainPM->IsImmediateModeOn()) |
434 | { |
435 | return Standard_False; |
436 | } |
437 | |
438 | myMainPM->EndImmediateDraw (theView->Viewer()); |
439 | return Standard_True; |
7fd59977 |
440 | } |
441 | |
442 | //======================================================================= |
443 | //function : EndImmediateDraw |
679ecdee |
444 | //purpose : |
7fd59977 |
445 | //======================================================================= |
446 | |
679ecdee |
447 | Standard_Boolean AIS_InteractiveContext::EndImmediateDraw() |
7fd59977 |
448 | { |
8c088c52 |
449 | if (!myMainPM->IsImmediateModeOn()) |
679ecdee |
450 | { |
451 | return Standard_False; |
7fd59977 |
452 | } |
679ecdee |
453 | |
8c088c52 |
454 | myMainPM->EndImmediateDraw (myMainVwr); |
455 | return Standard_True; |
7fd59977 |
456 | } |