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 | ||
7fd59977 | 296 | //======================================================================= |
297 | //function : MoveTo | |
679ecdee | 298 | //purpose : |
7fd59977 | 299 | //======================================================================= |
679ecdee | 300 | AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix, |
301 | const Standard_Integer theYPix, | |
302 | const Handle(V3d_View)& theView, | |
303 | const Standard_Boolean theToRedrawOnUpdate) | |
7fd59977 | 304 | { |
8c088c52 | 305 | if (theView->Viewer() != myMainVwr) |
306 | { | |
307 | throw Standard_ProgramError ("AIS_InteractiveContext::MoveTo() - invalid argument"); | |
308 | } | |
309 | ||
f0cddd16 | 310 | myCurDetected = 0; |
311 | myCurHighlighted = 0; | |
312 | myDetectedSeq.Clear(); | |
7fd59977 | 313 | |
679ecdee | 314 | // preliminaires |
315 | myLastPicked = myLastinMain; | |
316 | myWasLastMain = Standard_True; | |
317 | AIS_StatusOfDetection aStatus = AIS_SOD_Nothing; | |
318 | Standard_Boolean toUpdateViewer = Standard_False; | |
319 | ||
a272ed94 | 320 | myFilters->SetDisabledObjects (theView->View()->HiddenObjects()); |
679ecdee | 321 | myMainSel->Pick (theXPix, theYPix, theView); |
322 | ||
323 | // filling of myAISDetectedSeq sequence storing information about detected AIS objects | |
324 | // (the objects must be AIS_Shapes) | |
325 | const Standard_Integer aDetectedNb = myMainSel->NbPicked(); | |
54a16ee4 | 326 | Standard_Integer aNewDetected = 0; |
14c4193d | 327 | Standard_Boolean toIgnoreDetTop = Standard_False; |
679ecdee | 328 | for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter) |
7fd59977 | 329 | { |
679ecdee | 330 | Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter); |
331 | if (anOwner.IsNull() | |
332 | || !myFilters->IsOk (anOwner)) | |
333 | { | |
14c4193d | 334 | if (myPickingStrategy == SelectMgr_PickingStrategy_OnlyTopmost) |
335 | { | |
336 | toIgnoreDetTop = Standard_True; | |
337 | } | |
679ecdee | 338 | continue; |
339 | } | |
340 | ||
14c4193d | 341 | if (aNewDetected < 1 |
342 | && !toIgnoreDetTop) | |
54a16ee4 | 343 | { |
344 | aNewDetected = aDetIter; | |
345 | } | |
f0cddd16 | 346 | |
347 | myDetectedSeq.Append (aDetIter); | |
7fd59977 | 348 | } |
7fd59977 | 349 | |
54a16ee4 | 350 | if (aNewDetected >= 1) |
7fd59977 | 351 | { |
f0cddd16 | 352 | myCurHighlighted = myDetectedSeq.Lower(); |
353 | ||
29627b4c | 354 | // Does nothing if previously detected object is equal to the current one. |
355 | // However in advanced selection modes the owners comparison | |
356 | // is not effective because in that case only one owner manage the | |
357 | // selection in current selection mode. It is necessary to check the current detected | |
358 | // entity and hilight it only if the detected entity is not the same as | |
359 | // previous detected (IsForcedHilight call) | |
54a16ee4 | 360 | Handle(SelectMgr_EntityOwner) aNewPickedOwner = myMainSel->Picked (aNewDetected); |
29627b4c | 361 | if (aNewPickedOwner == myLastPicked && !aNewPickedOwner->IsForcedHilight()) |
eafb234b | 362 | { |
c3282ec1 | 363 | return myLastPicked->IsSelected() |
8abada55 | 364 | ? AIS_SOD_Selected |
365 | : AIS_SOD_OnlyOneDetected; | |
679ecdee | 366 | } |
81bba717 | 367 | |
7fd59977 | 368 | // Previously detected object is unhilighted if it is not selected or hilighted |
369 | // with selection color if it is selected. Such highlighting with selection color | |
370 | // is needed only if myToHilightSelected flag is true. In this case previously detected | |
371 | // object has been already highlighted with myHilightColor during previous MoveTo() | |
372 | // method call. As result it is necessary to rehighligt it with mySelectionColor. | |
c3282ec1 | 373 | if (!myLastPicked.IsNull() && myLastPicked->HasSelectable()) |
7fd59977 | 374 | { |
731c9b5b | 375 | clearDynamicHighlight(); |
376 | toUpdateViewer = Standard_True; | |
7fd59977 | 377 | } |
be6e564e | 378 | |
679ecdee | 379 | // initialize myLastPicked field with currently detected object |
c3282ec1 | 380 | myLastPicked = aNewPickedOwner; |
679ecdee | 381 | myLastinMain = myLastPicked; |
be6e564e | 382 | |
679ecdee | 383 | // highlight detected object if it is not selected or myToHilightSelected flag is true |
c3282ec1 | 384 | if (myLastPicked->HasSelectable()) |
7fd59977 | 385 | { |
be3d8cbc | 386 | if (myAutoHilight |
387 | && (!myLastPicked->IsSelected() | |
388 | || myToHilightSelected)) | |
679ecdee | 389 | { |
8e5fb5ea | 390 | highlightWithColor (myLastPicked, theView->Viewer()); |
679ecdee | 391 | toUpdateViewer = Standard_True; |
392 | } | |
be6e564e | 393 | |
c3282ec1 | 394 | aStatus = myLastPicked->IsSelected() |
8abada55 | 395 | ? AIS_SOD_Selected |
396 | : AIS_SOD_OnlyOneDetected; | |
be6e564e | 397 | } |
7fd59977 | 398 | } |
c3282ec1 | 399 | else |
7fd59977 | 400 | { |
679ecdee | 401 | // previously detected object is unhilighted if it is not selected or hilighted |
402 | // with selection color if it is selected | |
403 | aStatus = AIS_SOD_Nothing; | |
be3d8cbc | 404 | if (myAutoHilight |
405 | && !myLastPicked.IsNull() | |
406 | && myLastPicked->HasSelectable()) | |
7fd59977 | 407 | { |
731c9b5b | 408 | clearDynamicHighlight(); |
409 | toUpdateViewer = Standard_True; | |
7fd59977 | 410 | } |
be6e564e | 411 | |
679ecdee | 412 | myLastinMain.Nullify(); |
8abada55 | 413 | myLastPicked.Nullify(); |
7fd59977 | 414 | } |
679ecdee | 415 | |
2eea6525 | 416 | if (toUpdateViewer |
417 | && theToRedrawOnUpdate) | |
679ecdee | 418 | { |
2eea6525 | 419 | theView->Viewer()->Update(); |
679ecdee | 420 | } |
421 | ||
679ecdee | 422 | return aStatus; |
7fd59977 | 423 | } |
424 | ||
016e5959 | 425 | //======================================================================= |
426 | //function : AddSelect | |
427 | //purpose : | |
428 | //======================================================================= | |
02974a19 | 429 | AIS_StatusOfPick AIS_InteractiveContext::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject) |
016e5959 | 430 | { |
016e5959 | 431 | mySelection->AddSelect (theObject); |
432 | ||
433 | Standard_Integer aSelNum = NbSelected(); | |
434 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
435 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
436 | : AIS_SOP_SeveralSelected; | |
437 | } | |
438 | ||
7fd59977 | 439 | //======================================================================= |
440 | //function : Select | |
441 | //purpose : | |
442 | //======================================================================= | |
c398b00e | 443 | AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin, |
444 | const Standard_Integer theYPMin, | |
445 | const Standard_Integer theXPMax, | |
446 | const Standard_Integer theYPMax, | |
447 | const Handle(V3d_View)& theView, | |
448 | const Standard_Boolean toUpdateViewer) | |
7fd59977 | 449 | { |
8c088c52 | 450 | if (theView->Viewer() != myMainVwr) |
451 | { | |
452 | throw Standard_ProgramError ("AIS_InteractiveContext::Select() - invalid argument"); | |
453 | } | |
454 | ||
81bba717 | 455 | // all objects detected by the selector are taken, previous current objects are emptied, |
456 | // new objects are put... | |
c3282ec1 | 457 | ClearSelected (Standard_False); |
8c088c52 | 458 | myWasLastMain = Standard_True; |
459 | myMainSel->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView); | |
460 | for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter) | |
7fd59977 | 461 | { |
8c088c52 | 462 | const Handle(SelectMgr_EntityOwner)& aCurOwner = myMainSel->Picked (aPickIter); |
c3282ec1 | 463 | if (aCurOwner.IsNull() || !aCurOwner->HasSelectable() || !myFilters->IsOk (aCurOwner)) |
464 | continue; | |
7fd59977 | 465 | |
016e5959 | 466 | mySelection->Select (aCurOwner); |
f838dac4 | 467 | aCurOwner->SetSelected (Standard_True); |
c398b00e | 468 | } |
469 | ||
68dcee02 | 470 | if (myAutoHilight) |
471 | { | |
472 | HilightSelected (toUpdateViewer); | |
473 | } | |
c398b00e | 474 | |
c3282ec1 | 475 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 476 | |
477 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
478 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
479 | : AIS_SOP_SeveralSelected; | |
7fd59977 | 480 | |
481 | } | |
482 | ||
483 | //======================================================================= | |
484 | //function : Select | |
485 | //purpose : Selection by polyline | |
486 | //======================================================================= | |
c398b00e | 487 | AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline, |
488 | const Handle(V3d_View)& theView, | |
489 | const Standard_Boolean toUpdateViewer) | |
7fd59977 | 490 | { |
8c088c52 | 491 | if (theView->Viewer() != myMainVwr) |
492 | { | |
493 | throw Standard_ProgramError ("AIS_InteractiveContext::Select() - invalid argument"); | |
494 | } | |
495 | ||
81bba717 | 496 | // all objects detected by the selector are taken, previous current objects are emptied, |
497 | // new objects are put... | |
c3282ec1 | 498 | ClearSelected (Standard_False); |
8c088c52 | 499 | myWasLastMain = Standard_True; |
500 | myMainSel->Pick (thePolyline, theView); | |
501 | for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter) | |
7fd59977 | 502 | { |
8c088c52 | 503 | const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter); |
c3282ec1 | 504 | if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner)) |
505 | continue; | |
c398b00e | 506 | |
016e5959 | 507 | mySelection->Select (anOwner); |
f838dac4 | 508 | anOwner->SetSelected (Standard_True); |
c398b00e | 509 | } |
510 | ||
68dcee02 | 511 | if (myAutoHilight) |
512 | { | |
513 | HilightSelected (toUpdateViewer); | |
514 | } | |
c398b00e | 515 | |
c3282ec1 | 516 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 517 | |
518 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
519 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
520 | : AIS_SOP_SeveralSelected; | |
7fd59977 | 521 | |
522 | } | |
523 | ||
524 | //======================================================================= | |
525 | //function : Select | |
526 | //purpose : | |
527 | //======================================================================= | |
c398b00e | 528 | AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer) |
7fd59977 | 529 | { |
c398b00e | 530 | if (myWasLastMain && !myLastinMain.IsNull()) |
531 | { | |
be3d8cbc | 532 | if (myAutoHilight) |
533 | { | |
534 | clearDynamicHighlight(); | |
535 | } | |
780ee4e2 | 536 | if (!myLastinMain->IsSelected() |
537 | || myLastinMain->IsForcedHilight() | |
538 | || NbSelected() > 1) | |
c398b00e | 539 | { |
c3282ec1 | 540 | SetSelected (myLastinMain, Standard_False); |
c398b00e | 541 | if(toUpdateViewer) |
7fd59977 | 542 | { |
c398b00e | 543 | UpdateCurrentViewer(); |
7fd59977 | 544 | } |
c398b00e | 545 | } |
7fd59977 | 546 | } |
c398b00e | 547 | else |
548 | { | |
be3d8cbc | 549 | ClearSelected (toUpdateViewer); |
7fd59977 | 550 | } |
c398b00e | 551 | |
c3282ec1 | 552 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 553 | |
554 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
555 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
556 | : AIS_SOP_SeveralSelected; | |
7fd59977 | 557 | } |
558 | ||
559 | //======================================================================= | |
560 | //function : ShiftSelect | |
561 | //purpose : | |
562 | //======================================================================= | |
c398b00e | 563 | AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer) |
7fd59977 | 564 | { |
68dcee02 | 565 | if (myAutoHilight) |
c398b00e | 566 | { |
68dcee02 | 567 | clearDynamicHighlight(); |
7fd59977 | 568 | } |
c398b00e | 569 | if (myWasLastMain && !myLastinMain.IsNull()) |
570 | { | |
c3282ec1 | 571 | AddOrRemoveSelected (myLastinMain, toUpdateViewer); |
c398b00e | 572 | } |
7fd59977 | 573 | |
c3282ec1 | 574 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 575 | |
c3282ec1 | 576 | return (aSelNum == 0) ? AIS_SOP_NothingSelected |
577 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
578 | : AIS_SOP_SeveralSelected; | |
c398b00e | 579 | } |
7fd59977 | 580 | |
581 | //======================================================================= | |
582 | //function : ShiftSelect | |
583 | //purpose : | |
584 | //======================================================================= | |
c398b00e | 585 | AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin, |
586 | const Standard_Integer theYPMin, | |
587 | const Standard_Integer theXPMax, | |
588 | const Standard_Integer theYPMax, | |
589 | const Handle(V3d_View)& theView, | |
590 | const Standard_Boolean toUpdateViewer) | |
7fd59977 | 591 | { |
8c088c52 | 592 | if (theView->Viewer() != myMainVwr) |
593 | { | |
594 | throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument"); | |
595 | } | |
596 | ||
68dcee02 | 597 | if (myAutoHilight) |
c398b00e | 598 | { |
68dcee02 | 599 | UnhilightSelected (Standard_False); |
c398b00e | 600 | } |
8c088c52 | 601 | myWasLastMain = Standard_True; |
602 | myMainSel->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView); | |
603 | for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter) | |
c398b00e | 604 | { |
8c088c52 | 605 | const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter); |
c3282ec1 | 606 | if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner)) |
607 | continue; | |
608 | ||
016e5959 | 609 | AIS_SelectStatus aSelStatus = mySelection->Select (anOwner); |
f838dac4 | 610 | anOwner->SetSelected (aSelStatus == AIS_SS_Added); |
7fd59977 | 611 | } |
c398b00e | 612 | |
68dcee02 | 613 | if (myAutoHilight) |
614 | { | |
615 | HilightSelected (toUpdateViewer); | |
616 | } | |
c398b00e | 617 | |
c3282ec1 | 618 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 619 | |
620 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
621 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
622 | : AIS_SOP_SeveralSelected; | |
623 | ||
7fd59977 | 624 | } |
625 | ||
626 | //======================================================================= | |
627 | //function : ShiftSelect | |
628 | //purpose : | |
629 | //======================================================================= | |
c398b00e | 630 | AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline, |
631 | const Handle(V3d_View)& theView, | |
632 | const Standard_Boolean toUpdateViewer) | |
7fd59977 | 633 | { |
8c088c52 | 634 | if (theView->Viewer() != myMainVwr) |
635 | { | |
636 | throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument"); | |
637 | } | |
638 | ||
68dcee02 | 639 | if (myAutoHilight) |
c398b00e | 640 | { |
68dcee02 | 641 | UnhilightSelected (Standard_False); |
c398b00e | 642 | } |
8c088c52 | 643 | myWasLastMain = Standard_True; |
644 | myMainSel->Pick (thePolyline, theView); | |
645 | for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter) | |
c398b00e | 646 | { |
8c088c52 | 647 | const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter); |
c3282ec1 | 648 | if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner)) |
649 | continue; | |
650 | ||
016e5959 | 651 | AIS_SelectStatus aSelStatus = mySelection->Select (anOwner); |
f838dac4 | 652 | anOwner->SetSelected (aSelStatus == AIS_SS_Added); |
c398b00e | 653 | } |
654 | ||
68dcee02 | 655 | if (myAutoHilight) |
656 | { | |
657 | HilightSelected (toUpdateViewer); | |
658 | } | |
c398b00e | 659 | |
c3282ec1 | 660 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 661 | |
662 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
663 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
664 | : AIS_SOP_SeveralSelected; | |
7fd59977 | 665 | } |
666 | ||
7fd59977 | 667 | //======================================================================= |
668 | //function : HilightSelected | |
c3282ec1 | 669 | //purpose : |
7fd59977 | 670 | //======================================================================= |
c3282ec1 | 671 | void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdateViewer) |
7fd59977 | 672 | { |
c3282ec1 | 673 | // In case of selection without using local context |
731c9b5b | 674 | clearDynamicHighlight(); |
c3282ec1 | 675 | AIS_MapOfObjSelectedOwners anObjOwnerMap; |
02974a19 | 676 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) |
c3282ec1 | 677 | { |
02974a19 | 678 | const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value(); |
679 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); | |
f838dac4 | 680 | const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObj, anOwner); |
681 | Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind(anObj); | |
02974a19 | 682 | if (anOwner == anObj->GlobalSelOwner()) |
c3282ec1 | 683 | { |
02974a19 | 684 | aState->SetHilightStatus (Standard_True); |
8e5fb5ea | 685 | aState->SetHilightStyle (anObjSelStyle); |
02974a19 | 686 | } |
f838dac4 | 687 | anOwner->SetSelected (Standard_True); |
02974a19 | 688 | if (!anOwner->IsAutoHilight()) |
689 | { | |
690 | NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq; | |
691 | if (anObjOwnerMap.Find (anObj, aSeq)) | |
c3282ec1 | 692 | { |
02974a19 | 693 | aSeq->Append (anOwner); |
c3282ec1 | 694 | } |
695 | else | |
696 | { | |
02974a19 | 697 | aSeq = new SelectMgr_SequenceOfOwner(); |
698 | aSeq->Append (anOwner); | |
699 | anObjOwnerMap.Bind (anObj, aSeq); | |
c3282ec1 | 700 | } |
7fd59977 | 701 | } |
02974a19 | 702 | else |
703 | { | |
f838dac4 | 704 | const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, aState->DisplayMode()); |
8e5fb5ea | 705 | anOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode); |
02974a19 | 706 | } |
7fd59977 | 707 | } |
c3282ec1 | 708 | |
709 | if (!anObjOwnerMap.IsEmpty()) | |
710 | { | |
711 | for (AIS_MapOfObjSelectedOwners::Iterator anIter (anObjOwnerMap); anIter.More(); anIter.Next()) | |
7fd59977 | 712 | { |
c3282ec1 | 713 | anIter.Key()->HilightSelected (myMainPM, *anIter.Value()); |
7fd59977 | 714 | } |
c3282ec1 | 715 | anObjOwnerMap.Clear(); |
716 | } | |
717 | ||
718 | if (theToUpdateViewer) | |
7fd59977 | 719 | UpdateCurrentViewer(); |
720 | } | |
721 | ||
722 | //======================================================================= | |
723 | //function : UnhilightSelected | |
c3282ec1 | 724 | //purpose : |
7fd59977 | 725 | //======================================================================= |
c3282ec1 | 726 | void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer) |
7fd59977 | 727 | { |
02974a19 | 728 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) |
c3282ec1 | 729 | { |
02974a19 | 730 | const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value(); |
731 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); | |
732 | if (anOwner == anObj->GlobalSelOwner()) | |
7fd59977 | 733 | { |
02974a19 | 734 | myObjects.ChangeFind (anObj)->SetHilightStatus (Standard_False); |
7fd59977 | 735 | } |
02974a19 | 736 | |
f838dac4 | 737 | anOwner->SetSelected (Standard_False); |
738 | anOwner->Unhilight (myMainPM); | |
c3282ec1 | 739 | } |
740 | ||
741 | if (theToUpdateViewer) | |
742 | UpdateCurrentViewer(); | |
7fd59977 | 743 | } |
744 | ||
745 | ||
746 | //======================================================================= | |
747 | //function : ClearSelected | |
c3282ec1 | 748 | //purpose : |
7fd59977 | 749 | //======================================================================= |
c3282ec1 | 750 | void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateViewer) |
7fd59977 | 751 | { |
c3282ec1 | 752 | if (NbSelected() == 0) |
753 | return; | |
7fd59977 | 754 | |
68dcee02 | 755 | if (myAutoHilight) |
756 | { | |
757 | unhighlightSelected(); | |
758 | } | |
be3d8cbc | 759 | else |
760 | { | |
761 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) | |
762 | { | |
763 | aSelIter.Value()->SetSelected (Standard_False); | |
764 | } | |
765 | } | |
7fd59977 | 766 | |
02974a19 | 767 | mySelection->Clear(); |
68dcee02 | 768 | if (myAutoHilight) |
c3282ec1 | 769 | { |
68dcee02 | 770 | clearDynamicHighlight(); |
c3282ec1 | 771 | } |
7fd59977 | 772 | |
68dcee02 | 773 | if (theToUpdateViewer) |
774 | UpdateCurrentViewer(); | |
c3282ec1 | 775 | } |
776 | ||
777 | //======================================================================= | |
778 | //function : SetSelected | |
779 | //purpose : Sets the whole object as selected and highlights it with selection color | |
780 | //======================================================================= | |
781 | void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& theObject, | |
782 | const Standard_Boolean theToUpdateViewer) | |
7fd59977 | 783 | { |
c3282ec1 | 784 | if (theObject.IsNull()) |
f838dac4 | 785 | { |
7fd59977 | 786 | return; |
f838dac4 | 787 | } |
788 | ||
789 | if (!myObjects.IsBound (theObject)) | |
790 | { | |
c3282ec1 | 791 | Display (theObject, Standard_False); |
f838dac4 | 792 | } |
b5cce1ab | 793 | |
f838dac4 | 794 | Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner(); |
795 | if (anOwner.IsNull()) | |
796 | { | |
797 | return; | |
798 | } | |
c3282ec1 | 799 | |
f838dac4 | 800 | const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (theObject, anOwner); |
68dcee02 | 801 | if (NbSelected() == 1 && myObjects (theObject)->IsHilighted() && myAutoHilight) |
c3282ec1 | 802 | { |
f838dac4 | 803 | Handle(Prs3d_Drawer) aCustomStyle; |
8e5fb5ea | 804 | if (HighlightStyle (theObject, aCustomStyle)) |
c3282ec1 | 805 | { |
8e5fb5ea | 806 | if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle) |
c3282ec1 | 807 | { |
8e5fb5ea | 808 | HilightWithColor (theObject, anObjSelStyle, theToUpdateViewer); |
c3282ec1 | 809 | } |
810 | } | |
811 | return; | |
812 | } | |
813 | ||
b5cce1ab | 814 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) |
c3282ec1 | 815 | { |
b5cce1ab | 816 | const Handle(SelectMgr_EntityOwner)& aSelOwner = aSelIter.Value(); |
f838dac4 | 817 | if (!myFilters->IsOk (aSelOwner)) |
02974a19 | 818 | { |
c3282ec1 | 819 | continue; |
02974a19 | 820 | } |
c3282ec1 | 821 | |
f838dac4 | 822 | Handle(AIS_InteractiveObject) aSelectable = Handle(AIS_InteractiveObject)::DownCast (aSelOwner->Selectable()); |
68dcee02 | 823 | if (myAutoHilight) |
824 | { | |
825 | Unhilight (aSelectable, Standard_False); | |
826 | } | |
f838dac4 | 827 | aSelOwner->SetSelected (Standard_False); |
828 | if (aSelOwner == aSelectable->GlobalSelOwner()) | |
e1b01c73 | 829 | { |
830 | myObjects.ChangeFind (aSelectable)->SetHilightStatus (Standard_False); | |
831 | } | |
c3282ec1 | 832 | } |
833 | ||
834 | // added to avoid untimely viewer update... | |
016e5959 | 835 | mySelection->ClearAndSelect (anOwner); |
0d5880e1 | 836 | |
68dcee02 | 837 | if (myAutoHilight) |
c3282ec1 | 838 | { |
68dcee02 | 839 | Handle(Prs3d_Drawer) aCustomStyle; |
840 | if (HighlightStyle (theObject, aCustomStyle)) | |
841 | { | |
842 | if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle) | |
843 | { | |
844 | HilightWithColor (theObject, anObjSelStyle, Standard_False); | |
845 | } | |
846 | } | |
847 | else | |
c3282ec1 | 848 | { |
8e5fb5ea | 849 | HilightWithColor (theObject, anObjSelStyle, Standard_False); |
c3282ec1 | 850 | } |
7fd59977 | 851 | } |
f838dac4 | 852 | anOwner->SetSelected (Standard_True); |
c3282ec1 | 853 | |
854 | if (theToUpdateViewer) | |
855 | UpdateCurrentViewer(); | |
7fd59977 | 856 | } |
857 | ||
858 | //======================================================================= | |
c3282ec1 | 859 | //function : SetSelected |
860 | //purpose : Sets the whole object as selected and highlights it with selection color | |
7fd59977 | 861 | //======================================================================= |
c3282ec1 | 862 | void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner, |
863 | const Standard_Boolean theToUpdateViewer) | |
7fd59977 | 864 | { |
b4006117 | 865 | if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner)) |
c3282ec1 | 866 | return; |
867 | ||
f838dac4 | 868 | const Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()); |
869 | const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObject, theOwner); | |
731c9b5b | 870 | if (NbSelected() == 1 && theOwner->IsSelected() && !theOwner->IsForcedHilight()) |
c3282ec1 | 871 | { |
f838dac4 | 872 | Handle(Prs3d_Drawer) aCustomStyle; |
68dcee02 | 873 | if (myAutoHilight && HighlightStyle (theOwner, aCustomStyle)) |
c3282ec1 | 874 | { |
8e5fb5ea | 875 | if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle) |
c3282ec1 | 876 | { |
877 | const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0; | |
8e5fb5ea | 878 | theOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode); |
c3282ec1 | 879 | } |
880 | } | |
881 | return; | |
882 | } | |
883 | ||
884 | if (!myObjects.IsBound (anObject)) | |
885 | Display (anObject, Standard_False); | |
886 | ||
68dcee02 | 887 | if (myAutoHilight) |
888 | { | |
889 | unhighlightSelected(); | |
890 | } | |
c3282ec1 | 891 | |
016e5959 | 892 | mySelection->ClearAndSelect (theOwner); |
68dcee02 | 893 | if (myAutoHilight) |
c3282ec1 | 894 | { |
68dcee02 | 895 | Handle(Prs3d_Drawer) aCustomStyle; |
896 | if (!HighlightStyle (theOwner, aCustomStyle) || | |
897 | (!aCustomStyle.IsNull() && aCustomStyle != anObjSelStyle)) | |
898 | { | |
899 | theOwner->SetSelected (Standard_True); | |
900 | highlightSelected (theOwner); | |
901 | } | |
c3282ec1 | 902 | } |
903 | ||
f838dac4 | 904 | theOwner->SetSelected (Standard_True); |
68dcee02 | 905 | if (myAutoHilight && theOwner == anObject->GlobalSelOwner()) |
e1b01c73 | 906 | { |
907 | Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (anObject); | |
908 | aState->SetHilightStatus (Standard_True); | |
8e5fb5ea | 909 | aState->SetHilightStyle (anObjSelStyle); |
e1b01c73 | 910 | } |
911 | ||
c3282ec1 | 912 | if (theToUpdateViewer) |
913 | UpdateCurrentViewer(); | |
7fd59977 | 914 | } |
915 | ||
916 | //======================================================================= | |
917 | //function : AddOrRemoveSelected | |
c3282ec1 | 918 | //purpose : Adds or removes current object from AIS selection and highlights/unhighlights it. |
919 | // Since this method makes sence only for neutral point selection of a whole object, | |
920 | // if 0 selection of the object is empty this method simply does nothing. | |
7fd59977 | 921 | //======================================================================= |
c3282ec1 | 922 | void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& theObject, |
923 | const Standard_Boolean theToUpdateViewer) | |
7fd59977 | 924 | { |
68dcee02 | 925 | if (theObject.IsNull() |
926 | || !myObjects.IsBound (theObject)) | |
b5cce1ab | 927 | { |
c3282ec1 | 928 | return; |
b5cce1ab | 929 | } |
c3282ec1 | 930 | |
7411850a | 931 | const Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner(); |
b5cce1ab | 932 | if (!anOwner.IsNull() |
933 | && anOwner->HasSelectable()) | |
934 | { | |
935 | AddOrRemoveSelected (anOwner, theToUpdateViewer); | |
936 | } | |
7fd59977 | 937 | } |
c3282ec1 | 938 | |
7fd59977 | 939 | //======================================================================= |
940 | //function : AddOrRemoveSelected | |
c3282ec1 | 941 | //purpose : Allows to highlight or unhighlight the owner given depending on |
942 | // its selection status | |
7fd59977 | 943 | //======================================================================= |
c3282ec1 | 944 | void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner, |
945 | const Standard_Boolean theToUpdateViewer) | |
946 | { | |
c3282ec1 | 947 | if (theOwner.IsNull() || !theOwner->HasSelectable()) |
7fd59977 | 948 | return; |
c3282ec1 | 949 | |
4d901cde | 950 | if (!myFilters->IsOk(theOwner) && !theOwner->IsSelected()) |
951 | return; | |
952 | ||
016e5959 | 953 | AIS_SelectStatus aSelStat = mySelection->Select (theOwner); |
f838dac4 | 954 | theOwner->SetSelected (aSelStat == AIS_SS_Added); |
68dcee02 | 955 | |
956 | if (myAutoHilight) | |
c3282ec1 | 957 | { |
68dcee02 | 958 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()); |
959 | const Standard_Boolean isGlobal = anObj->GlobalSelOwner() == theOwner; | |
960 | Handle(AIS_GlobalStatus)& aStatus = myObjects.ChangeFind (anObj); | |
961 | if (theOwner->IsSelected()) | |
f838dac4 | 962 | { |
68dcee02 | 963 | highlightSelected (theOwner); |
964 | if (isGlobal) | |
965 | { | |
966 | aStatus->SetHilightStatus (Standard_True); | |
967 | aStatus->SetHilightStyle (getSelStyle (anObj, theOwner)); | |
968 | } | |
f838dac4 | 969 | } |
c3282ec1 | 970 | else |
f838dac4 | 971 | { |
68dcee02 | 972 | if (theOwner->IsAutoHilight()) |
973 | { | |
974 | theOwner->Unhilight (myMainPM); | |
975 | } | |
976 | else | |
977 | { | |
978 | anObj->ClearSelected(); | |
979 | } | |
980 | aStatus->SetHilightStatus (Standard_False); | |
981 | aStatus->SetHilightStyle (Handle(Prs3d_Drawer)()); | |
f838dac4 | 982 | } |
7fd59977 | 983 | } |
7fd59977 | 984 | |
c3282ec1 | 985 | if (theToUpdateViewer) |
986 | UpdateCurrentViewer(); | |
987 | } | |
7fd59977 | 988 | |
989 | ||
990 | //======================================================================= | |
991 | //function : IsSelected | |
c3282ec1 | 992 | //purpose : |
7fd59977 | 993 | //======================================================================= |
c3282ec1 | 994 | Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const |
7fd59977 | 995 | { |
68dcee02 | 996 | if (theObj.IsNull()) |
997 | { | |
998 | return Standard_False; | |
999 | } | |
c3282ec1 | 1000 | |
68dcee02 | 1001 | const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj); |
1002 | if (aStatus == NULL) | |
1003 | { | |
c3282ec1 | 1004 | return Standard_False; |
68dcee02 | 1005 | } |
c3282ec1 | 1006 | |
1007 | const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode(); | |
68dcee02 | 1008 | const TColStd_ListOfInteger& anActivatedModes = (*aStatus)->SelectionModes(); |
c3282ec1 | 1009 | for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next()) |
1010 | { | |
1011 | if (aModeIter.Value() == aGlobalSelMode) | |
1012 | { | |
b5cce1ab | 1013 | if (Handle(SelectMgr_EntityOwner) aGlobOwner = theObj->GlobalSelOwner()) |
1014 | { | |
1015 | return aGlobOwner->IsSelected(); | |
1016 | } | |
1017 | return Standard_False; | |
c3282ec1 | 1018 | } |
1019 | } | |
b5cce1ab | 1020 | return Standard_False; |
7fd59977 | 1021 | } |
1022 | ||
c3282ec1 | 1023 | //======================================================================= |
68dcee02 | 1024 | //function : FirstSelectedObject |
c3282ec1 | 1025 | //purpose : |
7fd59977 | 1026 | //======================================================================= |
68dcee02 | 1027 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject() const |
7fd59977 | 1028 | { |
68dcee02 | 1029 | return !mySelection->Objects().IsEmpty() |
1030 | ? Handle(AIS_InteractiveObject)::DownCast (mySelection->Objects().First()->Selectable()) | |
1031 | : Handle(AIS_InteractiveObject)(); | |
7fd59977 | 1032 | } |
1033 | ||
1034 | //======================================================================= | |
1035 | //function : HasSelectedShape | |
c3282ec1 | 1036 | //purpose : |
7fd59977 | 1037 | //======================================================================= |
c3282ec1 | 1038 | Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const |
7fd59977 | 1039 | { |
4aaadad7 SS |
1040 | if (!mySelection->More()) |
1041 | return Standard_False; | |
1042 | ||
68dcee02 | 1043 | const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value()); |
4aaadad7 | 1044 | return !anOwner.IsNull() && anOwner->HasShape(); |
7fd59977 | 1045 | } |
1046 | ||
1047 | //======================================================================= | |
1048 | //function : SelectedShape | |
c3282ec1 | 1049 | //purpose : |
7fd59977 | 1050 | //======================================================================= |
c3282ec1 | 1051 | TopoDS_Shape AIS_InteractiveContext::SelectedShape() const |
7fd59977 | 1052 | { |
02974a19 | 1053 | if (!mySelection->More()) |
c3282ec1 | 1054 | return TopoDS_Shape(); |
7fd59977 | 1055 | |
68dcee02 | 1056 | const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value()); |
3475df12 | 1057 | if (anOwner.IsNull() || !anOwner->HasSelectable()) |
c3282ec1 | 1058 | return TopoDS_Shape(); |
1059 | ||
1060 | return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location()); | |
7fd59977 | 1061 | } |
1062 | ||
7fd59977 | 1063 | //======================================================================= |
1064 | //function : EntityOwners | |
1065 | //purpose : | |
1066 | //======================================================================= | |
b586500b | 1067 | void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners, |
7fd59977 | 1068 | const Handle(AIS_InteractiveObject)& theIObj, |
1069 | const Standard_Integer theMode) const | |
1070 | { | |
b5cce1ab | 1071 | if (theIObj.IsNull()) |
1072 | { | |
1073 | return; | |
1074 | } | |
7fd59977 | 1075 | |
1076 | TColStd_ListOfInteger aModes; | |
b5cce1ab | 1077 | if (theMode == -1) |
1078 | { | |
1079 | ActivatedModes (theIObj, aModes); | |
1080 | } | |
7fd59977 | 1081 | else |
b5cce1ab | 1082 | { |
1083 | aModes.Append (theMode); | |
1084 | } | |
7fd59977 | 1085 | |
b586500b | 1086 | if (theOwners.IsNull()) |
b5cce1ab | 1087 | { |
b586500b | 1088 | theOwners = new SelectMgr_IndexedMapOfOwner(); |
b5cce1ab | 1089 | } |
b586500b | 1090 | |
b5cce1ab | 1091 | for (TColStd_ListIteratorOfListOfInteger anItr (aModes); anItr.More(); anItr.Next()) |
7fd59977 | 1092 | { |
b5cce1ab | 1093 | const int aMode = anItr.Value(); |
1094 | const Handle(SelectMgr_Selection)& aSel = theIObj->Selection (aMode); | |
1095 | if (aSel.IsNull()) | |
1096 | { | |
7fd59977 | 1097 | continue; |
b5cce1ab | 1098 | } |
7fd59977 | 1099 | |
b5cce1ab | 1100 | for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSel->Entities()); aSelEntIter.More(); aSelEntIter.Next()) |
7fd59977 | 1101 | { |
b5cce1ab | 1102 | if (Handle(SelectBasics_SensitiveEntity) aEntity = aSelEntIter.Value()->BaseSensitive()) |
1103 | { | |
1104 | if (Handle(SelectMgr_EntityOwner) aOwner = Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId())) | |
1105 | { | |
1106 | theOwners->Add (aOwner); | |
1107 | } | |
1108 | } | |
7fd59977 | 1109 | } |
1110 | } | |
1111 | } | |
1112 | ||
7fd59977 | 1113 | //======================================================================= |
1114 | //function : HasDetectedShape | |
1115 | //purpose : | |
1116 | //======================================================================= | |
7fd59977 | 1117 | Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const |
1118 | { | |
8c088c52 | 1119 | Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked); |
1120 | return !anOwner.IsNull() | |
1121 | && anOwner->HasShape(); | |
7fd59977 | 1122 | } |
1123 | ||
1124 | //======================================================================= | |
1125 | //function : DetectedShape | |
1126 | //purpose : | |
1127 | //======================================================================= | |
8c088c52 | 1128 | const TopoDS_Shape& AIS_InteractiveContext::DetectedShape() const |
7fd59977 | 1129 | { |
8c088c52 | 1130 | Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked); |
1131 | return anOwner->Shape(); | |
1132 | } | |
7fd59977 | 1133 | |
7fd59977 | 1134 | //======================================================================= |
1135 | //function : HilightNextDetected | |
679ecdee | 1136 | //purpose : |
7fd59977 | 1137 | //======================================================================= |
679ecdee | 1138 | Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView, |
1139 | const Standard_Boolean theToRedrawImmediate) | |
7fd59977 | 1140 | { |
f0cddd16 | 1141 | myMainPM->ClearImmediateDraw(); |
1142 | if (myDetectedSeq.IsEmpty()) | |
1143 | { | |
1144 | return 0; | |
1145 | } | |
1146 | ||
1147 | if (++myCurHighlighted > myDetectedSeq.Upper()) | |
1148 | { | |
1149 | myCurHighlighted = myDetectedSeq.Lower(); | |
1150 | } | |
1151 | const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted)); | |
1152 | if (anOwner.IsNull()) | |
1153 | { | |
1154 | return 0; | |
1155 | } | |
1156 | ||
1157 | highlightWithColor (anOwner, theView->Viewer()); | |
1158 | myLastPicked = anOwner; | |
1159 | myLastinMain = myLastPicked; | |
1160 | ||
1161 | if (theToRedrawImmediate) | |
1162 | { | |
1163 | myMainPM->RedrawImmediate (theView->Viewer()); | |
1164 | myMainVwr->RedrawImmediate(); | |
1165 | } | |
1166 | ||
1167 | return myCurHighlighted; | |
7fd59977 | 1168 | } |
1169 | ||
1170 | //======================================================================= | |
f0cddd16 | 1171 | //function : HilightPreviousDetected |
679ecdee | 1172 | //purpose : |
7fd59977 | 1173 | //======================================================================= |
679ecdee | 1174 | Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView, |
1175 | const Standard_Boolean theToRedrawImmediate) | |
7fd59977 | 1176 | { |
f0cddd16 | 1177 | myMainPM->ClearImmediateDraw(); |
1178 | if (myDetectedSeq.IsEmpty()) | |
1179 | { | |
1180 | return 0; | |
1181 | } | |
1182 | ||
1183 | if (--myCurHighlighted < myDetectedSeq.Lower()) | |
1184 | { | |
1185 | myCurHighlighted = myDetectedSeq.Upper(); | |
1186 | } | |
1187 | const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted)); | |
1188 | if (anOwner.IsNull()) | |
1189 | { | |
1190 | return 0; | |
1191 | } | |
1192 | ||
1193 | highlightWithColor (anOwner, theView->Viewer()); | |
1194 | myLastPicked = anOwner; | |
1195 | myLastinMain = myLastPicked; | |
1196 | ||
1197 | if (theToRedrawImmediate) | |
1198 | { | |
1199 | myMainPM->RedrawImmediate (theView->Viewer()); | |
1200 | myMainVwr->RedrawImmediate(); | |
1201 | } | |
1202 | ||
1203 | return myCurHighlighted; | |
7fd59977 | 1204 | } |
1205 | ||
7fd59977 | 1206 | //======================================================================= |
d21ddc4f | 1207 | //function : DetectedCurrentOwner |
1208 | //purpose : | |
1209 | //======================================================================= | |
1210 | Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedCurrentOwner() const | |
1211 | { | |
d21ddc4f | 1212 | return MoreDetected() |
1213 | ? myMainSel->Picked (myDetectedSeq (myCurDetected)) | |
1214 | : Handle(SelectMgr_EntityOwner)(); | |
1215 | } | |
1216 | ||
1217 | //======================================================================= | |
7fd59977 | 1218 | //function : DetectedCurrentShape |
1219 | //purpose : | |
1220 | //======================================================================= | |
7fd59977 | 1221 | const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const |
1222 | { | |
404c8936 | 1223 | Standard_DISABLE_DEPRECATION_WARNINGS |
57ad5cbd | 1224 | Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject()); |
404c8936 | 1225 | Standard_ENABLE_DEPRECATION_WARNINGS |
8c088c52 | 1226 | return !aCurrentShape.IsNull() |
1227 | ? aCurrentShape->Shape() | |
1228 | : AIS_InteractiveContext_myDummyShape; | |
7fd59977 | 1229 | } |
1230 | ||
1231 | //======================================================================= | |
1232 | //function : DetectedCurrentObject | |
1233 | //purpose : | |
1234 | //======================================================================= | |
57ad5cbd | 1235 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const |
1236 | { | |
f0cddd16 | 1237 | return MoreDetected() |
8c088c52 | 1238 | ? Handle(AIS_InteractiveObject)::DownCast (myMainSel->Picked (myDetectedSeq (myCurDetected))->Selectable()) |
1239 | : Handle(AIS_InteractiveObject)(); | |
7fd59977 | 1240 | } |