Commit | Line | Data |
---|---|---|
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 | |
18 | #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx> | |
7fd59977 | 19 | #include <AIS_GlobalStatus.hxx> |
42cf5bc1 | 20 | #include <AIS_InteractiveContext.hxx> |
21 | #include <AIS_InteractiveObject.hxx> | |
42cf5bc1 | 22 | #include <AIS_MapIteratorOfMapOfInteractive.hxx> |
23 | #include <AIS_MapOfInteractive.hxx> | |
24 | #include <AIS_Selection.hxx> | |
7fd59977 | 25 | #include <AIS_Shape.hxx> |
42cf5bc1 | 26 | #include <AIS_StatusOfDetection.hxx> |
27 | #include <AIS_StatusOfPick.hxx> | |
679ecdee | 28 | #include <Aspect_Grid.hxx> |
42cf5bc1 | 29 | #include <Prs3d_BasicAspect.hxx> |
30 | #include <Prs3d_LineAspect.hxx> | |
31 | #include <Prs3d_Presentation.hxx> | |
32 | #include <Quantity_Color.hxx> | |
33 | #include <SelectBasics_SensitiveEntity.hxx> | |
34 | #include <SelectMgr_EntityOwner.hxx> | |
35 | #include <SelectMgr_Filter.hxx> | |
36 | #include <SelectMgr_OrFilter.hxx> | |
37 | #include <SelectMgr_Selection.hxx> | |
38 | #include <SelectMgr_SelectionManager.hxx> | |
39 | #include <Standard_Transient.hxx> | |
c3282ec1 | 40 | #include <StdSelect_BRepOwner.hxx> |
42cf5bc1 | 41 | #include <StdSelect_ViewerSelector3d.hxx> |
42 | #include <TCollection_AsciiString.hxx> | |
43 | #include <TCollection_ExtendedString.hxx> | |
44 | #include <TColStd_ListIteratorOfListOfInteger.hxx> | |
45 | #include <TopLoc_Location.hxx> | |
42cf5bc1 | 46 | #include <V3d_AmbientLight.hxx> |
47 | #include <V3d_DirectionalLight.hxx> | |
7fd59977 | 48 | #include <V3d_Light.hxx> |
49 | #include <V3d_PositionalLight.hxx> | |
50 | #include <V3d_SpotLight.hxx> | |
42cf5bc1 | 51 | #include <V3d_View.hxx> |
52 | #include <V3d_Viewer.hxx> | |
7fd59977 | 53 | |
c3282ec1 | 54 | typedef NCollection_DataMap<Handle(AIS_InteractiveObject), NCollection_Handle<SelectMgr_SequenceOfOwner> > AIS_MapOfObjSelectedOwners; |
55 | ||
016e5959 | 56 | namespace |
57 | { | |
896faa72 | 58 | TopoDS_Shape AIS_InteractiveContext_myDummyShape; |
016e5959 | 59 | } |
60 | ||
c3282ec1 | 61 | //======================================================================= |
62 | //function : highlightWithColor | |
63 | //purpose : | |
64 | //======================================================================= | |
65 | void AIS_InteractiveContext::highlightWithColor (const Handle(SelectMgr_EntityOwner)& theOwner, | |
c3282ec1 | 66 | const Handle(V3d_Viewer)& theViewer) |
67 | { | |
f838dac4 | 68 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()); |
c3282ec1 | 69 | if (anObj.IsNull()) |
f838dac4 | 70 | { |
c3282ec1 | 71 | return; |
f838dac4 | 72 | } |
73 | ||
74 | const Handle(Prs3d_Drawer)& aStyle = getHiStyle (anObj, theOwner); | |
75 | const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1); | |
c3282ec1 | 76 | |
77 | myMainPM->BeginImmediateDraw(); | |
f838dac4 | 78 | theOwner->HilightWithColor (myMainPM, aStyle, aHiMode); |
c3282ec1 | 79 | myMainPM->EndImmediateDraw (theViewer.IsNull() ? myMainVwr : theViewer); |
80 | } | |
81 | ||
82 | //======================================================================= | |
83 | //function : highlightSelected | |
84 | //purpose : | |
85 | //======================================================================= | |
8e5fb5ea | 86 | void AIS_InteractiveContext::highlightSelected (const Handle(SelectMgr_EntityOwner)& theOwner) |
c3282ec1 | 87 | { |
f838dac4 | 88 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()); |
c3282ec1 | 89 | if (anObj.IsNull()) |
f838dac4 | 90 | { |
c3282ec1 | 91 | return; |
f838dac4 | 92 | } |
c3282ec1 | 93 | |
94 | if (!theOwner->IsAutoHilight()) | |
95 | { | |
c3282ec1 | 96 | SelectMgr_SequenceOfOwner aSeq; |
02974a19 | 97 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) |
c3282ec1 | 98 | { |
8e5fb5ea | 99 | if (aSelIter.Value()->IsSameSelectable (anObj)) |
02974a19 | 100 | { |
101 | aSeq.Append (aSelIter.Value()); | |
102 | } | |
c3282ec1 | 103 | } |
104 | anObj->HilightSelected (myMainPM, aSeq); | |
105 | } | |
106 | else | |
107 | { | |
f838dac4 | 108 | const Handle(Prs3d_Drawer)& aStyle = getSelStyle (anObj, theOwner); |
109 | const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1); | |
110 | theOwner->HilightWithColor (myMainPM, aStyle, aHiMode); | |
8e5fb5ea | 111 | } |
112 | } | |
113 | ||
114 | //======================================================================= | |
115 | //function : highlightGlobal | |
116 | //purpose : | |
117 | //======================================================================= | |
118 | void AIS_InteractiveContext::highlightGlobal (const Handle(AIS_InteractiveObject)& theObj, | |
f838dac4 | 119 | const Handle(Prs3d_Drawer)& theStyle, |
120 | const Standard_Integer theDispMode) const | |
8e5fb5ea | 121 | { |
122 | if (theObj.IsNull()) | |
f838dac4 | 123 | { |
8e5fb5ea | 124 | return; |
f838dac4 | 125 | } |
126 | ||
127 | const Standard_Integer aHiMode = getHilightMode (theObj, theStyle, theDispMode); | |
8e5fb5ea | 128 | const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner(); |
129 | ||
130 | if (aGlobOwner.IsNull()) | |
131 | { | |
f838dac4 | 132 | myMainPM->Color (theObj, theStyle, aHiMode); |
8e5fb5ea | 133 | return; |
134 | } | |
135 | ||
136 | if (!aGlobOwner->IsAutoHilight()) | |
137 | { | |
138 | SelectMgr_SequenceOfOwner aSeq; | |
139 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) | |
140 | { | |
141 | if (aSelIter.Value()->IsSameSelectable (theObj)) | |
142 | { | |
143 | aSeq.Append (aSelIter.Value()); | |
144 | } | |
145 | } | |
146 | theObj->HilightSelected (myMainPM, aSeq); | |
147 | } | |
148 | else | |
149 | { | |
f838dac4 | 150 | aGlobOwner->HilightWithColor (myMainPM, theStyle, aHiMode); |
c3282ec1 | 151 | } |
152 | } | |
153 | ||
b4006117 | 154 | //======================================================================= |
155 | //function : unhighlightSelected | |
156 | //purpose : | |
157 | //======================================================================= | |
158 | void AIS_InteractiveContext::unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity) | |
159 | { | |
b4006117 | 160 | NCollection_IndexedMap<Handle(AIS_InteractiveObject)> anObjToClear; |
02974a19 | 161 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) |
b4006117 | 162 | { |
02974a19 | 163 | const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value(); |
164 | const Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); | |
f838dac4 | 165 | Handle(AIS_GlobalStatus) aStatus; |
166 | if (!myObjects.Find (anInteractive, aStatus)) | |
167 | { | |
168 | continue; | |
169 | } | |
170 | ||
b4006117 | 171 | if (anOwner->IsAutoHilight()) |
172 | { | |
f838dac4 | 173 | anOwner->Unhilight (myMainPM); |
b4006117 | 174 | if (theIsToHilightSubIntensity) |
175 | { | |
f838dac4 | 176 | if (aStatus->IsSubIntensityOn()) |
b4006117 | 177 | { |
f838dac4 | 178 | const Standard_Integer aHiMode = getHilightMode (anInteractive, aStatus->HilightStyle(), aStatus->DisplayMode()); |
8e5fb5ea | 179 | highlightWithSubintensity (anOwner, aHiMode); |
b4006117 | 180 | } |
181 | } | |
182 | } | |
183 | else | |
184 | { | |
f838dac4 | 185 | anObjToClear.Add (anInteractive); |
b4006117 | 186 | } |
f838dac4 | 187 | anOwner->SetSelected (Standard_False); |
b4006117 | 188 | if (anOwner == anInteractive->GlobalSelOwner()) |
189 | { | |
190 | myObjects.ChangeFind (anInteractive)->SetHilightStatus (Standard_False); | |
191 | } | |
192 | } | |
193 | for (NCollection_IndexedMap<Handle(AIS_InteractiveObject)>::Iterator anIter (anObjToClear); anIter.More(); anIter.Next()) | |
194 | { | |
195 | const Handle(AIS_InteractiveObject)& anObj = anIter.Value(); | |
f838dac4 | 196 | myMainPM->Unhighlight (anObj); |
b4006117 | 197 | anObj->ClearSelected(); |
198 | } | |
199 | } | |
200 | ||
8e5fb5ea | 201 | //======================================================================= |
202 | //function : unhighlightGlobal | |
203 | //purpose : | |
204 | //======================================================================= | |
f838dac4 | 205 | void AIS_InteractiveContext::unhighlightGlobal (const Handle(AIS_InteractiveObject)& theObj) const |
8e5fb5ea | 206 | { |
207 | if (theObj.IsNull()) | |
f838dac4 | 208 | { |
8e5fb5ea | 209 | return; |
f838dac4 | 210 | } |
8e5fb5ea | 211 | |
f838dac4 | 212 | const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner(); |
8e5fb5ea | 213 | if (aGlobOwner.IsNull()) |
214 | { | |
f838dac4 | 215 | myMainPM->Unhighlight (theObj); |
8e5fb5ea | 216 | return; |
217 | } | |
218 | ||
219 | if (aGlobOwner->IsAutoHilight()) | |
220 | { | |
f838dac4 | 221 | aGlobOwner->Unhilight (myMainPM); |
8e5fb5ea | 222 | } |
223 | else | |
224 | { | |
f838dac4 | 225 | myMainPM->Unhighlight (theObj); |
8e5fb5ea | 226 | theObj->ClearSelected(); |
227 | } | |
228 | } | |
229 | ||
230 | //======================================================================= | |
231 | //function : turnOnSubintensity | |
232 | //purpose : | |
233 | //======================================================================= | |
234 | void AIS_InteractiveContext::turnOnSubintensity (const Handle(AIS_InteractiveObject)& theObject, | |
235 | const Standard_Integer theDispMode, | |
236 | const Standard_Boolean theIsDisplayedOnly) const | |
237 | { | |
f838dac4 | 238 | // the only differ with selection highlight is color, so sync transparency values |
239 | const Handle(Prs3d_Drawer)& aSubStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity]; | |
240 | aSubStyle->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency()); | |
8e5fb5ea | 241 | |
242 | if (theObject.IsNull()) | |
243 | { | |
244 | for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjsIter (myObjects); anObjsIter.More(); anObjsIter.Next()) | |
245 | { | |
246 | const Handle(AIS_GlobalStatus)& aStatus = anObjsIter.Value(); | |
247 | if (aStatus->GraphicStatus() != AIS_DS_Displayed && theIsDisplayedOnly) | |
248 | continue; | |
249 | ||
250 | aStatus->SubIntensityOn(); | |
f838dac4 | 251 | myMainPM->Color (anObjsIter.Key(), aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode()); |
8e5fb5ea | 252 | } |
253 | } | |
254 | else | |
255 | { | |
256 | Handle(AIS_GlobalStatus) aStatus; | |
257 | if (!myObjects.Find (theObject, aStatus)) | |
258 | return; | |
259 | ||
260 | if (aStatus->GraphicStatus() != AIS_DS_Displayed && theIsDisplayedOnly) | |
f838dac4 | 261 | return; |
8e5fb5ea | 262 | |
263 | aStatus->SubIntensityOn(); | |
f838dac4 | 264 | myMainPM->Color (theObject, aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode()); |
8e5fb5ea | 265 | } |
266 | } | |
267 | ||
268 | //======================================================================= | |
269 | //function : highlightWithSubintensity | |
270 | //purpose : | |
271 | //======================================================================= | |
272 | void AIS_InteractiveContext::highlightWithSubintensity (const Handle(AIS_InteractiveObject)& theObject, | |
273 | const Standard_Integer theMode) const | |
274 | { | |
275 | // the only differ with selection highlight is color, so | |
276 | // sync transparency values | |
f838dac4 | 277 | myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency()); |
8e5fb5ea | 278 | |
f838dac4 | 279 | myMainPM->Color (theObject, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode); |
8e5fb5ea | 280 | } |
281 | ||
282 | //======================================================================= | |
283 | //function : highlightWithSubintensity | |
284 | //purpose : | |
285 | //======================================================================= | |
286 | void AIS_InteractiveContext::highlightWithSubintensity (const Handle(SelectMgr_EntityOwner)& theOwner, | |
287 | const Standard_Integer theMode) const | |
288 | { | |
289 | // the only differ with selection highlight is color, so | |
290 | // sync transparency values | |
f838dac4 | 291 | myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency()); |
8e5fb5ea | 292 | |
f838dac4 | 293 | theOwner->HilightWithColor (myMainPM, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode); |
8e5fb5ea | 294 | } |
295 | ||
55c8f0f7 BB |
296 | //======================================================================= |
297 | //function : isSlowHiStyle | |
298 | //purpose : | |
299 | //======================================================================= | |
300 | Standard_Boolean AIS_InteractiveContext::isSlowHiStyle (const Handle(SelectMgr_EntityOwner)& theOwner, | |
301 | const Handle(V3d_Viewer)& theViewer) const | |
302 | { | |
303 | if (const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable())) | |
304 | { | |
305 | const Handle(Prs3d_Drawer)& aHiStyle = getHiStyle (anObj, myLastPicked); | |
306 | return aHiStyle->ZLayer() == Graphic3d_ZLayerId_UNKNOWN | |
307 | || !theViewer->ZLayerSettings (aHiStyle->ZLayer()).IsImmediate(); | |
308 | } | |
309 | return Standard_False; | |
310 | } | |
311 | ||
7fd59977 | 312 | //======================================================================= |
313 | //function : MoveTo | |
679ecdee | 314 | //purpose : |
7fd59977 | 315 | //======================================================================= |
679ecdee | 316 | AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix, |
317 | const Standard_Integer theYPix, | |
318 | const Handle(V3d_View)& theView, | |
319 | const Standard_Boolean theToRedrawOnUpdate) | |
7fd59977 | 320 | { |
8c088c52 | 321 | if (theView->Viewer() != myMainVwr) |
322 | { | |
323 | throw Standard_ProgramError ("AIS_InteractiveContext::MoveTo() - invalid argument"); | |
324 | } | |
325 | ||
f0cddd16 | 326 | myCurDetected = 0; |
327 | myCurHighlighted = 0; | |
328 | myDetectedSeq.Clear(); | |
7fd59977 | 329 | |
679ecdee | 330 | // preliminaires |
331 | myLastPicked = myLastinMain; | |
332 | myWasLastMain = Standard_True; | |
333 | AIS_StatusOfDetection aStatus = AIS_SOD_Nothing; | |
334 | Standard_Boolean toUpdateViewer = Standard_False; | |
335 | ||
a272ed94 | 336 | myFilters->SetDisabledObjects (theView->View()->HiddenObjects()); |
679ecdee | 337 | myMainSel->Pick (theXPix, theYPix, theView); |
338 | ||
339 | // filling of myAISDetectedSeq sequence storing information about detected AIS objects | |
340 | // (the objects must be AIS_Shapes) | |
341 | const Standard_Integer aDetectedNb = myMainSel->NbPicked(); | |
54a16ee4 | 342 | Standard_Integer aNewDetected = 0; |
14c4193d | 343 | Standard_Boolean toIgnoreDetTop = Standard_False; |
679ecdee | 344 | for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter) |
7fd59977 | 345 | { |
679ecdee | 346 | Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter); |
347 | if (anOwner.IsNull() | |
348 | || !myFilters->IsOk (anOwner)) | |
349 | { | |
14c4193d | 350 | if (myPickingStrategy == SelectMgr_PickingStrategy_OnlyTopmost) |
351 | { | |
352 | toIgnoreDetTop = Standard_True; | |
353 | } | |
679ecdee | 354 | continue; |
355 | } | |
356 | ||
14c4193d | 357 | if (aNewDetected < 1 |
358 | && !toIgnoreDetTop) | |
54a16ee4 | 359 | { |
360 | aNewDetected = aDetIter; | |
361 | } | |
f0cddd16 | 362 | |
363 | myDetectedSeq.Append (aDetIter); | |
7fd59977 | 364 | } |
7fd59977 | 365 | |
54a16ee4 | 366 | if (aNewDetected >= 1) |
7fd59977 | 367 | { |
f0cddd16 | 368 | myCurHighlighted = myDetectedSeq.Lower(); |
369 | ||
29627b4c | 370 | // Does nothing if previously detected object is equal to the current one. |
371 | // However in advanced selection modes the owners comparison | |
372 | // is not effective because in that case only one owner manage the | |
373 | // selection in current selection mode. It is necessary to check the current detected | |
374 | // entity and hilight it only if the detected entity is not the same as | |
375 | // previous detected (IsForcedHilight call) | |
54a16ee4 | 376 | Handle(SelectMgr_EntityOwner) aNewPickedOwner = myMainSel->Picked (aNewDetected); |
29627b4c | 377 | if (aNewPickedOwner == myLastPicked && !aNewPickedOwner->IsForcedHilight()) |
eafb234b | 378 | { |
c3282ec1 | 379 | return myLastPicked->IsSelected() |
8abada55 | 380 | ? AIS_SOD_Selected |
381 | : AIS_SOD_OnlyOneDetected; | |
679ecdee | 382 | } |
81bba717 | 383 | |
7fd59977 | 384 | // Previously detected object is unhilighted if it is not selected or hilighted |
385 | // with selection color if it is selected. Such highlighting with selection color | |
386 | // is needed only if myToHilightSelected flag is true. In this case previously detected | |
387 | // object has been already highlighted with myHilightColor during previous MoveTo() | |
388 | // method call. As result it is necessary to rehighligt it with mySelectionColor. | |
c3282ec1 | 389 | if (!myLastPicked.IsNull() && myLastPicked->HasSelectable()) |
7fd59977 | 390 | { |
55c8f0f7 BB |
391 | if (isSlowHiStyle (myLastPicked, theView->Viewer())) |
392 | { | |
393 | theView->Viewer()->Invalidate(); | |
394 | } | |
395 | ||
731c9b5b | 396 | clearDynamicHighlight(); |
397 | toUpdateViewer = Standard_True; | |
7fd59977 | 398 | } |
be6e564e | 399 | |
679ecdee | 400 | // initialize myLastPicked field with currently detected object |
c3282ec1 | 401 | myLastPicked = aNewPickedOwner; |
679ecdee | 402 | myLastinMain = myLastPicked; |
be6e564e | 403 | |
679ecdee | 404 | // highlight detected object if it is not selected or myToHilightSelected flag is true |
c3282ec1 | 405 | if (myLastPicked->HasSelectable()) |
7fd59977 | 406 | { |
be3d8cbc | 407 | if (myAutoHilight |
408 | && (!myLastPicked->IsSelected() | |
409 | || myToHilightSelected)) | |
679ecdee | 410 | { |
55c8f0f7 BB |
411 | if (isSlowHiStyle (myLastPicked, theView->Viewer())) |
412 | { | |
413 | theView->Viewer()->Invalidate(); | |
414 | } | |
415 | ||
8e5fb5ea | 416 | highlightWithColor (myLastPicked, theView->Viewer()); |
679ecdee | 417 | toUpdateViewer = Standard_True; |
418 | } | |
be6e564e | 419 | |
c3282ec1 | 420 | aStatus = myLastPicked->IsSelected() |
8abada55 | 421 | ? AIS_SOD_Selected |
422 | : AIS_SOD_OnlyOneDetected; | |
be6e564e | 423 | } |
7fd59977 | 424 | } |
c3282ec1 | 425 | else |
7fd59977 | 426 | { |
679ecdee | 427 | // previously detected object is unhilighted if it is not selected or hilighted |
428 | // with selection color if it is selected | |
429 | aStatus = AIS_SOD_Nothing; | |
be3d8cbc | 430 | if (myAutoHilight |
431 | && !myLastPicked.IsNull() | |
432 | && myLastPicked->HasSelectable()) | |
7fd59977 | 433 | { |
55c8f0f7 BB |
434 | if (isSlowHiStyle (myLastPicked, theView->Viewer())) |
435 | { | |
436 | theView->Viewer()->Invalidate(); | |
437 | } | |
438 | ||
731c9b5b | 439 | clearDynamicHighlight(); |
440 | toUpdateViewer = Standard_True; | |
7fd59977 | 441 | } |
be6e564e | 442 | |
679ecdee | 443 | myLastinMain.Nullify(); |
8abada55 | 444 | myLastPicked.Nullify(); |
7fd59977 | 445 | } |
679ecdee | 446 | |
2eea6525 | 447 | if (toUpdateViewer |
448 | && theToRedrawOnUpdate) | |
679ecdee | 449 | { |
c29c0ad0 | 450 | if (theView->ComputedMode()) |
451 | { | |
452 | theView->Viewer()->Update(); | |
453 | } | |
454 | else | |
455 | { | |
55c8f0f7 BB |
456 | if (theView->IsInvalidated()) |
457 | { | |
458 | theView->Viewer()->Redraw(); | |
459 | } | |
460 | else | |
461 | { | |
462 | theView->Viewer()->RedrawImmediate(); | |
463 | } | |
c29c0ad0 | 464 | } |
679ecdee | 465 | } |
466 | ||
679ecdee | 467 | return aStatus; |
7fd59977 | 468 | } |
469 | ||
016e5959 | 470 | //======================================================================= |
471 | //function : AddSelect | |
472 | //purpose : | |
473 | //======================================================================= | |
02974a19 | 474 | AIS_StatusOfPick AIS_InteractiveContext::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject) |
016e5959 | 475 | { |
016e5959 | 476 | mySelection->AddSelect (theObject); |
477 | ||
478 | Standard_Integer aSelNum = NbSelected(); | |
479 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
480 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
481 | : AIS_SOP_SeveralSelected; | |
482 | } | |
483 | ||
7fd59977 | 484 | //======================================================================= |
485 | //function : Select | |
486 | //purpose : | |
487 | //======================================================================= | |
c398b00e | 488 | AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin, |
489 | const Standard_Integer theYPMin, | |
490 | const Standard_Integer theXPMax, | |
491 | const Standard_Integer theYPMax, | |
492 | const Handle(V3d_View)& theView, | |
493 | const Standard_Boolean toUpdateViewer) | |
7fd59977 | 494 | { |
8c088c52 | 495 | if (theView->Viewer() != myMainVwr) |
496 | { | |
497 | throw Standard_ProgramError ("AIS_InteractiveContext::Select() - invalid argument"); | |
498 | } | |
499 | ||
81bba717 | 500 | // all objects detected by the selector are taken, previous current objects are emptied, |
501 | // new objects are put... | |
c3282ec1 | 502 | ClearSelected (Standard_False); |
8c088c52 | 503 | myWasLastMain = Standard_True; |
504 | myMainSel->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView); | |
505 | for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter) | |
7fd59977 | 506 | { |
8c088c52 | 507 | const Handle(SelectMgr_EntityOwner)& aCurOwner = myMainSel->Picked (aPickIter); |
c3282ec1 | 508 | if (aCurOwner.IsNull() || !aCurOwner->HasSelectable() || !myFilters->IsOk (aCurOwner)) |
509 | continue; | |
7fd59977 | 510 | |
016e5959 | 511 | mySelection->Select (aCurOwner); |
f838dac4 | 512 | aCurOwner->SetSelected (Standard_True); |
c398b00e | 513 | } |
514 | ||
68dcee02 | 515 | if (myAutoHilight) |
516 | { | |
517 | HilightSelected (toUpdateViewer); | |
518 | } | |
c398b00e | 519 | |
c3282ec1 | 520 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 521 | |
522 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
523 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
524 | : AIS_SOP_SeveralSelected; | |
7fd59977 | 525 | |
526 | } | |
527 | ||
528 | //======================================================================= | |
529 | //function : Select | |
530 | //purpose : Selection by polyline | |
531 | //======================================================================= | |
c398b00e | 532 | AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline, |
533 | const Handle(V3d_View)& theView, | |
534 | const Standard_Boolean toUpdateViewer) | |
7fd59977 | 535 | { |
8c088c52 | 536 | if (theView->Viewer() != myMainVwr) |
537 | { | |
538 | throw Standard_ProgramError ("AIS_InteractiveContext::Select() - invalid argument"); | |
539 | } | |
540 | ||
81bba717 | 541 | // all objects detected by the selector are taken, previous current objects are emptied, |
542 | // new objects are put... | |
c3282ec1 | 543 | ClearSelected (Standard_False); |
8c088c52 | 544 | myWasLastMain = Standard_True; |
545 | myMainSel->Pick (thePolyline, theView); | |
546 | for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter) | |
7fd59977 | 547 | { |
8c088c52 | 548 | const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter); |
c3282ec1 | 549 | if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner)) |
550 | continue; | |
c398b00e | 551 | |
016e5959 | 552 | mySelection->Select (anOwner); |
f838dac4 | 553 | anOwner->SetSelected (Standard_True); |
c398b00e | 554 | } |
555 | ||
68dcee02 | 556 | if (myAutoHilight) |
557 | { | |
558 | HilightSelected (toUpdateViewer); | |
559 | } | |
c398b00e | 560 | |
c3282ec1 | 561 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 562 | |
563 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
564 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
565 | : AIS_SOP_SeveralSelected; | |
7fd59977 | 566 | |
567 | } | |
568 | ||
569 | //======================================================================= | |
570 | //function : Select | |
571 | //purpose : | |
572 | //======================================================================= | |
c398b00e | 573 | AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer) |
7fd59977 | 574 | { |
c398b00e | 575 | if (myWasLastMain && !myLastinMain.IsNull()) |
576 | { | |
be3d8cbc | 577 | if (myAutoHilight) |
578 | { | |
579 | clearDynamicHighlight(); | |
580 | } | |
780ee4e2 | 581 | if (!myLastinMain->IsSelected() |
582 | || myLastinMain->IsForcedHilight() | |
583 | || NbSelected() > 1) | |
c398b00e | 584 | { |
c3282ec1 | 585 | SetSelected (myLastinMain, Standard_False); |
c398b00e | 586 | if(toUpdateViewer) |
7fd59977 | 587 | { |
c398b00e | 588 | UpdateCurrentViewer(); |
7fd59977 | 589 | } |
c398b00e | 590 | } |
7fd59977 | 591 | } |
c398b00e | 592 | else |
593 | { | |
be3d8cbc | 594 | ClearSelected (toUpdateViewer); |
7fd59977 | 595 | } |
c398b00e | 596 | |
c3282ec1 | 597 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 598 | |
599 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
600 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
601 | : AIS_SOP_SeveralSelected; | |
7fd59977 | 602 | } |
603 | ||
604 | //======================================================================= | |
605 | //function : ShiftSelect | |
606 | //purpose : | |
607 | //======================================================================= | |
c398b00e | 608 | AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer) |
7fd59977 | 609 | { |
68dcee02 | 610 | if (myAutoHilight) |
c398b00e | 611 | { |
68dcee02 | 612 | clearDynamicHighlight(); |
7fd59977 | 613 | } |
c398b00e | 614 | if (myWasLastMain && !myLastinMain.IsNull()) |
615 | { | |
c3282ec1 | 616 | AddOrRemoveSelected (myLastinMain, toUpdateViewer); |
c398b00e | 617 | } |
7fd59977 | 618 | |
c3282ec1 | 619 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 620 | |
c3282ec1 | 621 | return (aSelNum == 0) ? AIS_SOP_NothingSelected |
622 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
623 | : AIS_SOP_SeveralSelected; | |
c398b00e | 624 | } |
7fd59977 | 625 | |
626 | //======================================================================= | |
627 | //function : ShiftSelect | |
628 | //purpose : | |
629 | //======================================================================= | |
c398b00e | 630 | AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin, |
631 | const Standard_Integer theYPMin, | |
632 | const Standard_Integer theXPMax, | |
633 | const Standard_Integer theYPMax, | |
634 | const Handle(V3d_View)& theView, | |
635 | const Standard_Boolean toUpdateViewer) | |
7fd59977 | 636 | { |
8c088c52 | 637 | if (theView->Viewer() != myMainVwr) |
638 | { | |
639 | throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument"); | |
640 | } | |
641 | ||
68dcee02 | 642 | if (myAutoHilight) |
c398b00e | 643 | { |
68dcee02 | 644 | UnhilightSelected (Standard_False); |
c398b00e | 645 | } |
8c088c52 | 646 | myWasLastMain = Standard_True; |
647 | myMainSel->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView); | |
648 | for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter) | |
c398b00e | 649 | { |
8c088c52 | 650 | const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter); |
c3282ec1 | 651 | if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner)) |
652 | continue; | |
653 | ||
016e5959 | 654 | AIS_SelectStatus aSelStatus = mySelection->Select (anOwner); |
f838dac4 | 655 | anOwner->SetSelected (aSelStatus == AIS_SS_Added); |
7fd59977 | 656 | } |
c398b00e | 657 | |
68dcee02 | 658 | if (myAutoHilight) |
659 | { | |
660 | HilightSelected (toUpdateViewer); | |
661 | } | |
c398b00e | 662 | |
c3282ec1 | 663 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 664 | |
665 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
666 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
667 | : AIS_SOP_SeveralSelected; | |
668 | ||
7fd59977 | 669 | } |
670 | ||
671 | //======================================================================= | |
672 | //function : ShiftSelect | |
673 | //purpose : | |
674 | //======================================================================= | |
c398b00e | 675 | AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline, |
676 | const Handle(V3d_View)& theView, | |
677 | const Standard_Boolean toUpdateViewer) | |
7fd59977 | 678 | { |
8c088c52 | 679 | if (theView->Viewer() != myMainVwr) |
680 | { | |
681 | throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument"); | |
682 | } | |
683 | ||
68dcee02 | 684 | if (myAutoHilight) |
c398b00e | 685 | { |
68dcee02 | 686 | UnhilightSelected (Standard_False); |
c398b00e | 687 | } |
8c088c52 | 688 | myWasLastMain = Standard_True; |
689 | myMainSel->Pick (thePolyline, theView); | |
690 | for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter) | |
c398b00e | 691 | { |
8c088c52 | 692 | const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter); |
c3282ec1 | 693 | if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner)) |
694 | continue; | |
695 | ||
016e5959 | 696 | AIS_SelectStatus aSelStatus = mySelection->Select (anOwner); |
f838dac4 | 697 | anOwner->SetSelected (aSelStatus == AIS_SS_Added); |
c398b00e | 698 | } |
699 | ||
68dcee02 | 700 | if (myAutoHilight) |
701 | { | |
702 | HilightSelected (toUpdateViewer); | |
703 | } | |
c398b00e | 704 | |
c3282ec1 | 705 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 706 | |
707 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
708 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
709 | : AIS_SOP_SeveralSelected; | |
7fd59977 | 710 | } |
711 | ||
7fd59977 | 712 | //======================================================================= |
713 | //function : HilightSelected | |
c3282ec1 | 714 | //purpose : |
7fd59977 | 715 | //======================================================================= |
c3282ec1 | 716 | void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdateViewer) |
7fd59977 | 717 | { |
c3282ec1 | 718 | // In case of selection without using local context |
731c9b5b | 719 | clearDynamicHighlight(); |
c3282ec1 | 720 | AIS_MapOfObjSelectedOwners anObjOwnerMap; |
02974a19 | 721 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) |
c3282ec1 | 722 | { |
02974a19 | 723 | const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value(); |
724 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); | |
f838dac4 | 725 | const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObj, anOwner); |
726 | Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind(anObj); | |
02974a19 | 727 | if (anOwner == anObj->GlobalSelOwner()) |
c3282ec1 | 728 | { |
02974a19 | 729 | aState->SetHilightStatus (Standard_True); |
8e5fb5ea | 730 | aState->SetHilightStyle (anObjSelStyle); |
02974a19 | 731 | } |
f838dac4 | 732 | anOwner->SetSelected (Standard_True); |
02974a19 | 733 | if (!anOwner->IsAutoHilight()) |
734 | { | |
735 | NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq; | |
736 | if (anObjOwnerMap.Find (anObj, aSeq)) | |
c3282ec1 | 737 | { |
02974a19 | 738 | aSeq->Append (anOwner); |
c3282ec1 | 739 | } |
740 | else | |
741 | { | |
02974a19 | 742 | aSeq = new SelectMgr_SequenceOfOwner(); |
743 | aSeq->Append (anOwner); | |
744 | anObjOwnerMap.Bind (anObj, aSeq); | |
c3282ec1 | 745 | } |
7fd59977 | 746 | } |
02974a19 | 747 | else |
748 | { | |
f838dac4 | 749 | const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, aState->DisplayMode()); |
8e5fb5ea | 750 | anOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode); |
02974a19 | 751 | } |
7fd59977 | 752 | } |
c3282ec1 | 753 | |
754 | if (!anObjOwnerMap.IsEmpty()) | |
755 | { | |
756 | for (AIS_MapOfObjSelectedOwners::Iterator anIter (anObjOwnerMap); anIter.More(); anIter.Next()) | |
7fd59977 | 757 | { |
c3282ec1 | 758 | anIter.Key()->HilightSelected (myMainPM, *anIter.Value()); |
7fd59977 | 759 | } |
c3282ec1 | 760 | anObjOwnerMap.Clear(); |
761 | } | |
762 | ||
763 | if (theToUpdateViewer) | |
7fd59977 | 764 | UpdateCurrentViewer(); |
765 | } | |
766 | ||
767 | //======================================================================= | |
768 | //function : UnhilightSelected | |
c3282ec1 | 769 | //purpose : |
7fd59977 | 770 | //======================================================================= |
c3282ec1 | 771 | void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer) |
7fd59977 | 772 | { |
02974a19 | 773 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) |
c3282ec1 | 774 | { |
02974a19 | 775 | const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value(); |
776 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); | |
777 | if (anOwner == anObj->GlobalSelOwner()) | |
7fd59977 | 778 | { |
02974a19 | 779 | myObjects.ChangeFind (anObj)->SetHilightStatus (Standard_False); |
7fd59977 | 780 | } |
02974a19 | 781 | |
f838dac4 | 782 | anOwner->SetSelected (Standard_False); |
783 | anOwner->Unhilight (myMainPM); | |
c3282ec1 | 784 | } |
785 | ||
786 | if (theToUpdateViewer) | |
787 | UpdateCurrentViewer(); | |
7fd59977 | 788 | } |
789 | ||
790 | ||
791 | //======================================================================= | |
792 | //function : ClearSelected | |
c3282ec1 | 793 | //purpose : |
7fd59977 | 794 | //======================================================================= |
c3282ec1 | 795 | void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateViewer) |
7fd59977 | 796 | { |
c3282ec1 | 797 | if (NbSelected() == 0) |
798 | return; | |
7fd59977 | 799 | |
68dcee02 | 800 | if (myAutoHilight) |
801 | { | |
802 | unhighlightSelected(); | |
803 | } | |
be3d8cbc | 804 | else |
805 | { | |
806 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) | |
807 | { | |
808 | aSelIter.Value()->SetSelected (Standard_False); | |
809 | } | |
810 | } | |
7fd59977 | 811 | |
02974a19 | 812 | mySelection->Clear(); |
68dcee02 | 813 | if (myAutoHilight) |
c3282ec1 | 814 | { |
68dcee02 | 815 | clearDynamicHighlight(); |
c3282ec1 | 816 | } |
7fd59977 | 817 | |
68dcee02 | 818 | if (theToUpdateViewer) |
819 | UpdateCurrentViewer(); | |
c3282ec1 | 820 | } |
821 | ||
822 | //======================================================================= | |
823 | //function : SetSelected | |
824 | //purpose : Sets the whole object as selected and highlights it with selection color | |
825 | //======================================================================= | |
826 | void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& theObject, | |
827 | const Standard_Boolean theToUpdateViewer) | |
7fd59977 | 828 | { |
c3282ec1 | 829 | if (theObject.IsNull()) |
f838dac4 | 830 | { |
7fd59977 | 831 | return; |
f838dac4 | 832 | } |
833 | ||
834 | if (!myObjects.IsBound (theObject)) | |
835 | { | |
c3282ec1 | 836 | Display (theObject, Standard_False); |
f838dac4 | 837 | } |
b5cce1ab | 838 | |
f838dac4 | 839 | Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner(); |
840 | if (anOwner.IsNull()) | |
841 | { | |
842 | return; | |
843 | } | |
c3282ec1 | 844 | |
f838dac4 | 845 | const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (theObject, anOwner); |
68dcee02 | 846 | if (NbSelected() == 1 && myObjects (theObject)->IsHilighted() && myAutoHilight) |
c3282ec1 | 847 | { |
f838dac4 | 848 | Handle(Prs3d_Drawer) aCustomStyle; |
8e5fb5ea | 849 | if (HighlightStyle (theObject, aCustomStyle)) |
c3282ec1 | 850 | { |
8e5fb5ea | 851 | if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle) |
c3282ec1 | 852 | { |
8e5fb5ea | 853 | HilightWithColor (theObject, anObjSelStyle, theToUpdateViewer); |
c3282ec1 | 854 | } |
855 | } | |
856 | return; | |
857 | } | |
858 | ||
b5cce1ab | 859 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) |
c3282ec1 | 860 | { |
b5cce1ab | 861 | const Handle(SelectMgr_EntityOwner)& aSelOwner = aSelIter.Value(); |
f838dac4 | 862 | if (!myFilters->IsOk (aSelOwner)) |
02974a19 | 863 | { |
c3282ec1 | 864 | continue; |
02974a19 | 865 | } |
c3282ec1 | 866 | |
f838dac4 | 867 | Handle(AIS_InteractiveObject) aSelectable = Handle(AIS_InteractiveObject)::DownCast (aSelOwner->Selectable()); |
68dcee02 | 868 | if (myAutoHilight) |
869 | { | |
870 | Unhilight (aSelectable, Standard_False); | |
871 | } | |
f838dac4 | 872 | aSelOwner->SetSelected (Standard_False); |
873 | if (aSelOwner == aSelectable->GlobalSelOwner()) | |
e1b01c73 | 874 | { |
875 | myObjects.ChangeFind (aSelectable)->SetHilightStatus (Standard_False); | |
876 | } | |
c3282ec1 | 877 | } |
878 | ||
879 | // added to avoid untimely viewer update... | |
016e5959 | 880 | mySelection->ClearAndSelect (anOwner); |
0d5880e1 | 881 | |
68dcee02 | 882 | if (myAutoHilight) |
c3282ec1 | 883 | { |
68dcee02 | 884 | Handle(Prs3d_Drawer) aCustomStyle; |
885 | if (HighlightStyle (theObject, aCustomStyle)) | |
886 | { | |
887 | if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle) | |
888 | { | |
889 | HilightWithColor (theObject, anObjSelStyle, Standard_False); | |
890 | } | |
891 | } | |
892 | else | |
c3282ec1 | 893 | { |
8e5fb5ea | 894 | HilightWithColor (theObject, anObjSelStyle, Standard_False); |
c3282ec1 | 895 | } |
7fd59977 | 896 | } |
f838dac4 | 897 | anOwner->SetSelected (Standard_True); |
c3282ec1 | 898 | |
899 | if (theToUpdateViewer) | |
900 | UpdateCurrentViewer(); | |
7fd59977 | 901 | } |
902 | ||
903 | //======================================================================= | |
c3282ec1 | 904 | //function : SetSelected |
905 | //purpose : Sets the whole object as selected and highlights it with selection color | |
7fd59977 | 906 | //======================================================================= |
c3282ec1 | 907 | void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner, |
908 | const Standard_Boolean theToUpdateViewer) | |
7fd59977 | 909 | { |
b4006117 | 910 | if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner)) |
c3282ec1 | 911 | return; |
912 | ||
f838dac4 | 913 | const Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()); |
914 | const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObject, theOwner); | |
731c9b5b | 915 | if (NbSelected() == 1 && theOwner->IsSelected() && !theOwner->IsForcedHilight()) |
c3282ec1 | 916 | { |
f838dac4 | 917 | Handle(Prs3d_Drawer) aCustomStyle; |
68dcee02 | 918 | if (myAutoHilight && HighlightStyle (theOwner, aCustomStyle)) |
c3282ec1 | 919 | { |
8e5fb5ea | 920 | if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle) |
c3282ec1 | 921 | { |
922 | const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0; | |
8e5fb5ea | 923 | theOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode); |
c3282ec1 | 924 | } |
925 | } | |
926 | return; | |
927 | } | |
928 | ||
929 | if (!myObjects.IsBound (anObject)) | |
930 | Display (anObject, Standard_False); | |
931 | ||
68dcee02 | 932 | if (myAutoHilight) |
933 | { | |
934 | unhighlightSelected(); | |
935 | } | |
c3282ec1 | 936 | |
016e5959 | 937 | mySelection->ClearAndSelect (theOwner); |
68dcee02 | 938 | if (myAutoHilight) |
c3282ec1 | 939 | { |
68dcee02 | 940 | Handle(Prs3d_Drawer) aCustomStyle; |
941 | if (!HighlightStyle (theOwner, aCustomStyle) || | |
942 | (!aCustomStyle.IsNull() && aCustomStyle != anObjSelStyle)) | |
943 | { | |
944 | theOwner->SetSelected (Standard_True); | |
945 | highlightSelected (theOwner); | |
946 | } | |
c3282ec1 | 947 | } |
948 | ||
f838dac4 | 949 | theOwner->SetSelected (Standard_True); |
68dcee02 | 950 | if (myAutoHilight && theOwner == anObject->GlobalSelOwner()) |
e1b01c73 | 951 | { |
952 | Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (anObject); | |
953 | aState->SetHilightStatus (Standard_True); | |
8e5fb5ea | 954 | aState->SetHilightStyle (anObjSelStyle); |
e1b01c73 | 955 | } |
956 | ||
c3282ec1 | 957 | if (theToUpdateViewer) |
958 | UpdateCurrentViewer(); | |
7fd59977 | 959 | } |
960 | ||
961 | //======================================================================= | |
962 | //function : AddOrRemoveSelected | |
c3282ec1 | 963 | //purpose : Adds or removes current object from AIS selection and highlights/unhighlights it. |
964 | // Since this method makes sence only for neutral point selection of a whole object, | |
965 | // if 0 selection of the object is empty this method simply does nothing. | |
7fd59977 | 966 | //======================================================================= |
c3282ec1 | 967 | void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& theObject, |
968 | const Standard_Boolean theToUpdateViewer) | |
7fd59977 | 969 | { |
68dcee02 | 970 | if (theObject.IsNull() |
971 | || !myObjects.IsBound (theObject)) | |
b5cce1ab | 972 | { |
c3282ec1 | 973 | return; |
b5cce1ab | 974 | } |
c3282ec1 | 975 | |
7411850a | 976 | const Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner(); |
b5cce1ab | 977 | if (!anOwner.IsNull() |
978 | && anOwner->HasSelectable()) | |
979 | { | |
980 | AddOrRemoveSelected (anOwner, theToUpdateViewer); | |
981 | } | |
7fd59977 | 982 | } |
c3282ec1 | 983 | |
7fd59977 | 984 | //======================================================================= |
985 | //function : AddOrRemoveSelected | |
c3282ec1 | 986 | //purpose : Allows to highlight or unhighlight the owner given depending on |
987 | // its selection status | |
7fd59977 | 988 | //======================================================================= |
c3282ec1 | 989 | void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner, |
990 | const Standard_Boolean theToUpdateViewer) | |
991 | { | |
c3282ec1 | 992 | if (theOwner.IsNull() || !theOwner->HasSelectable()) |
7fd59977 | 993 | return; |
c3282ec1 | 994 | |
4d901cde | 995 | if (!myFilters->IsOk(theOwner) && !theOwner->IsSelected()) |
996 | return; | |
997 | ||
016e5959 | 998 | AIS_SelectStatus aSelStat = mySelection->Select (theOwner); |
f838dac4 | 999 | theOwner->SetSelected (aSelStat == AIS_SS_Added); |
68dcee02 | 1000 | |
1001 | if (myAutoHilight) | |
c3282ec1 | 1002 | { |
68dcee02 | 1003 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()); |
1004 | const Standard_Boolean isGlobal = anObj->GlobalSelOwner() == theOwner; | |
1005 | Handle(AIS_GlobalStatus)& aStatus = myObjects.ChangeFind (anObj); | |
1006 | if (theOwner->IsSelected()) | |
f838dac4 | 1007 | { |
68dcee02 | 1008 | highlightSelected (theOwner); |
1009 | if (isGlobal) | |
1010 | { | |
1011 | aStatus->SetHilightStatus (Standard_True); | |
1012 | aStatus->SetHilightStyle (getSelStyle (anObj, theOwner)); | |
1013 | } | |
f838dac4 | 1014 | } |
c3282ec1 | 1015 | else |
f838dac4 | 1016 | { |
68dcee02 | 1017 | if (theOwner->IsAutoHilight()) |
1018 | { | |
1019 | theOwner->Unhilight (myMainPM); | |
1020 | } | |
1021 | else | |
1022 | { | |
1023 | anObj->ClearSelected(); | |
1024 | } | |
1025 | aStatus->SetHilightStatus (Standard_False); | |
1026 | aStatus->SetHilightStyle (Handle(Prs3d_Drawer)()); | |
f838dac4 | 1027 | } |
7fd59977 | 1028 | } |
7fd59977 | 1029 | |
c3282ec1 | 1030 | if (theToUpdateViewer) |
1031 | UpdateCurrentViewer(); | |
1032 | } | |
7fd59977 | 1033 | |
1034 | ||
1035 | //======================================================================= | |
1036 | //function : IsSelected | |
c3282ec1 | 1037 | //purpose : |
7fd59977 | 1038 | //======================================================================= |
c3282ec1 | 1039 | Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const |
7fd59977 | 1040 | { |
68dcee02 | 1041 | if (theObj.IsNull()) |
1042 | { | |
1043 | return Standard_False; | |
1044 | } | |
c3282ec1 | 1045 | |
68dcee02 | 1046 | const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj); |
1047 | if (aStatus == NULL) | |
1048 | { | |
c3282ec1 | 1049 | return Standard_False; |
68dcee02 | 1050 | } |
c3282ec1 | 1051 | |
1052 | const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode(); | |
68dcee02 | 1053 | const TColStd_ListOfInteger& anActivatedModes = (*aStatus)->SelectionModes(); |
c3282ec1 | 1054 | for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next()) |
1055 | { | |
1056 | if (aModeIter.Value() == aGlobalSelMode) | |
1057 | { | |
b5cce1ab | 1058 | if (Handle(SelectMgr_EntityOwner) aGlobOwner = theObj->GlobalSelOwner()) |
1059 | { | |
1060 | return aGlobOwner->IsSelected(); | |
1061 | } | |
1062 | return Standard_False; | |
c3282ec1 | 1063 | } |
1064 | } | |
b5cce1ab | 1065 | return Standard_False; |
7fd59977 | 1066 | } |
1067 | ||
c3282ec1 | 1068 | //======================================================================= |
68dcee02 | 1069 | //function : FirstSelectedObject |
c3282ec1 | 1070 | //purpose : |
7fd59977 | 1071 | //======================================================================= |
68dcee02 | 1072 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject() const |
7fd59977 | 1073 | { |
68dcee02 | 1074 | return !mySelection->Objects().IsEmpty() |
1075 | ? Handle(AIS_InteractiveObject)::DownCast (mySelection->Objects().First()->Selectable()) | |
1076 | : Handle(AIS_InteractiveObject)(); | |
7fd59977 | 1077 | } |
1078 | ||
1079 | //======================================================================= | |
1080 | //function : HasSelectedShape | |
c3282ec1 | 1081 | //purpose : |
7fd59977 | 1082 | //======================================================================= |
c3282ec1 | 1083 | Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const |
7fd59977 | 1084 | { |
4aaadad7 SS |
1085 | if (!mySelection->More()) |
1086 | return Standard_False; | |
1087 | ||
68dcee02 | 1088 | const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value()); |
4aaadad7 | 1089 | return !anOwner.IsNull() && anOwner->HasShape(); |
7fd59977 | 1090 | } |
1091 | ||
1092 | //======================================================================= | |
1093 | //function : SelectedShape | |
c3282ec1 | 1094 | //purpose : |
7fd59977 | 1095 | //======================================================================= |
c3282ec1 | 1096 | TopoDS_Shape AIS_InteractiveContext::SelectedShape() const |
7fd59977 | 1097 | { |
02974a19 | 1098 | if (!mySelection->More()) |
c3282ec1 | 1099 | return TopoDS_Shape(); |
7fd59977 | 1100 | |
68dcee02 | 1101 | const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value()); |
3475df12 | 1102 | if (anOwner.IsNull() || !anOwner->HasSelectable()) |
c3282ec1 | 1103 | return TopoDS_Shape(); |
1104 | ||
1105 | return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location()); | |
7fd59977 | 1106 | } |
1107 | ||
7fd59977 | 1108 | //======================================================================= |
1109 | //function : EntityOwners | |
1110 | //purpose : | |
1111 | //======================================================================= | |
b586500b | 1112 | void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners, |
7fd59977 | 1113 | const Handle(AIS_InteractiveObject)& theIObj, |
1114 | const Standard_Integer theMode) const | |
1115 | { | |
b5cce1ab | 1116 | if (theIObj.IsNull()) |
1117 | { | |
1118 | return; | |
1119 | } | |
7fd59977 | 1120 | |
1121 | TColStd_ListOfInteger aModes; | |
b5cce1ab | 1122 | if (theMode == -1) |
1123 | { | |
1124 | ActivatedModes (theIObj, aModes); | |
1125 | } | |
7fd59977 | 1126 | else |
b5cce1ab | 1127 | { |
1128 | aModes.Append (theMode); | |
1129 | } | |
7fd59977 | 1130 | |
b586500b | 1131 | if (theOwners.IsNull()) |
b5cce1ab | 1132 | { |
b586500b | 1133 | theOwners = new SelectMgr_IndexedMapOfOwner(); |
b5cce1ab | 1134 | } |
b586500b | 1135 | |
b5cce1ab | 1136 | for (TColStd_ListIteratorOfListOfInteger anItr (aModes); anItr.More(); anItr.Next()) |
7fd59977 | 1137 | { |
b5cce1ab | 1138 | const int aMode = anItr.Value(); |
1139 | const Handle(SelectMgr_Selection)& aSel = theIObj->Selection (aMode); | |
1140 | if (aSel.IsNull()) | |
1141 | { | |
7fd59977 | 1142 | continue; |
b5cce1ab | 1143 | } |
7fd59977 | 1144 | |
b5cce1ab | 1145 | for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSel->Entities()); aSelEntIter.More(); aSelEntIter.Next()) |
7fd59977 | 1146 | { |
b5cce1ab | 1147 | if (Handle(SelectBasics_SensitiveEntity) aEntity = aSelEntIter.Value()->BaseSensitive()) |
1148 | { | |
1149 | if (Handle(SelectMgr_EntityOwner) aOwner = Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId())) | |
1150 | { | |
1151 | theOwners->Add (aOwner); | |
1152 | } | |
1153 | } | |
7fd59977 | 1154 | } |
1155 | } | |
1156 | } | |
1157 | ||
7fd59977 | 1158 | //======================================================================= |
1159 | //function : HasDetectedShape | |
1160 | //purpose : | |
1161 | //======================================================================= | |
7fd59977 | 1162 | Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const |
1163 | { | |
8c088c52 | 1164 | Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked); |
1165 | return !anOwner.IsNull() | |
1166 | && anOwner->HasShape(); | |
7fd59977 | 1167 | } |
1168 | ||
1169 | //======================================================================= | |
1170 | //function : DetectedShape | |
1171 | //purpose : | |
1172 | //======================================================================= | |
8c088c52 | 1173 | const TopoDS_Shape& AIS_InteractiveContext::DetectedShape() const |
7fd59977 | 1174 | { |
8c088c52 | 1175 | Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked); |
1176 | return anOwner->Shape(); | |
1177 | } | |
7fd59977 | 1178 | |
7fd59977 | 1179 | //======================================================================= |
1180 | //function : HilightNextDetected | |
679ecdee | 1181 | //purpose : |
7fd59977 | 1182 | //======================================================================= |
679ecdee | 1183 | Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView, |
1184 | const Standard_Boolean theToRedrawImmediate) | |
7fd59977 | 1185 | { |
f0cddd16 | 1186 | myMainPM->ClearImmediateDraw(); |
1187 | if (myDetectedSeq.IsEmpty()) | |
1188 | { | |
1189 | return 0; | |
1190 | } | |
1191 | ||
1192 | if (++myCurHighlighted > myDetectedSeq.Upper()) | |
1193 | { | |
1194 | myCurHighlighted = myDetectedSeq.Lower(); | |
1195 | } | |
1196 | const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted)); | |
1197 | if (anOwner.IsNull()) | |
1198 | { | |
1199 | return 0; | |
1200 | } | |
1201 | ||
1202 | highlightWithColor (anOwner, theView->Viewer()); | |
1203 | myLastPicked = anOwner; | |
1204 | myLastinMain = myLastPicked; | |
1205 | ||
1206 | if (theToRedrawImmediate) | |
1207 | { | |
1208 | myMainPM->RedrawImmediate (theView->Viewer()); | |
1209 | myMainVwr->RedrawImmediate(); | |
1210 | } | |
1211 | ||
1212 | return myCurHighlighted; | |
7fd59977 | 1213 | } |
1214 | ||
1215 | //======================================================================= | |
f0cddd16 | 1216 | //function : HilightPreviousDetected |
679ecdee | 1217 | //purpose : |
7fd59977 | 1218 | //======================================================================= |
679ecdee | 1219 | Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView, |
1220 | const Standard_Boolean theToRedrawImmediate) | |
7fd59977 | 1221 | { |
f0cddd16 | 1222 | myMainPM->ClearImmediateDraw(); |
1223 | if (myDetectedSeq.IsEmpty()) | |
1224 | { | |
1225 | return 0; | |
1226 | } | |
1227 | ||
1228 | if (--myCurHighlighted < myDetectedSeq.Lower()) | |
1229 | { | |
1230 | myCurHighlighted = myDetectedSeq.Upper(); | |
1231 | } | |
1232 | const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted)); | |
1233 | if (anOwner.IsNull()) | |
1234 | { | |
1235 | return 0; | |
1236 | } | |
1237 | ||
1238 | highlightWithColor (anOwner, theView->Viewer()); | |
1239 | myLastPicked = anOwner; | |
1240 | myLastinMain = myLastPicked; | |
1241 | ||
1242 | if (theToRedrawImmediate) | |
1243 | { | |
1244 | myMainPM->RedrawImmediate (theView->Viewer()); | |
1245 | myMainVwr->RedrawImmediate(); | |
1246 | } | |
1247 | ||
1248 | return myCurHighlighted; | |
7fd59977 | 1249 | } |
1250 | ||
7fd59977 | 1251 | //======================================================================= |
d21ddc4f | 1252 | //function : DetectedCurrentOwner |
1253 | //purpose : | |
1254 | //======================================================================= | |
1255 | Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedCurrentOwner() const | |
1256 | { | |
d21ddc4f | 1257 | return MoreDetected() |
1258 | ? myMainSel->Picked (myDetectedSeq (myCurDetected)) | |
1259 | : Handle(SelectMgr_EntityOwner)(); | |
1260 | } | |
1261 | ||
1262 | //======================================================================= | |
7fd59977 | 1263 | //function : DetectedCurrentShape |
1264 | //purpose : | |
1265 | //======================================================================= | |
7fd59977 | 1266 | const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const |
1267 | { | |
404c8936 | 1268 | Standard_DISABLE_DEPRECATION_WARNINGS |
57ad5cbd | 1269 | Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject()); |
404c8936 | 1270 | Standard_ENABLE_DEPRECATION_WARNINGS |
8c088c52 | 1271 | return !aCurrentShape.IsNull() |
1272 | ? aCurrentShape->Shape() | |
1273 | : AIS_InteractiveContext_myDummyShape; | |
7fd59977 | 1274 | } |
1275 | ||
1276 | //======================================================================= | |
1277 | //function : DetectedCurrentObject | |
1278 | //purpose : | |
1279 | //======================================================================= | |
57ad5cbd | 1280 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const |
1281 | { | |
f0cddd16 | 1282 | return MoreDetected() |
8c088c52 | 1283 | ? Handle(AIS_InteractiveObject)::DownCast (myMainSel->Picked (myDetectedSeq (myCurDetected))->Selectable()) |
1284 | : Handle(AIS_InteractiveObject)(); | |
7fd59977 | 1285 | } |