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> | |
22 | #include <AIS_LocalContext.hxx> | |
23 | #include <AIS_MapIteratorOfMapOfInteractive.hxx> | |
24 | #include <AIS_MapOfInteractive.hxx> | |
25 | #include <AIS_Selection.hxx> | |
7fd59977 | 26 | #include <AIS_Shape.hxx> |
42cf5bc1 | 27 | #include <AIS_StatusOfDetection.hxx> |
28 | #include <AIS_StatusOfPick.hxx> | |
679ecdee | 29 | #include <Aspect_Grid.hxx> |
42cf5bc1 | 30 | #include <Prs3d_BasicAspect.hxx> |
31 | #include <Prs3d_LineAspect.hxx> | |
32 | #include <Prs3d_Presentation.hxx> | |
33 | #include <Quantity_Color.hxx> | |
34 | #include <SelectBasics_SensitiveEntity.hxx> | |
35 | #include <SelectMgr_EntityOwner.hxx> | |
36 | #include <SelectMgr_Filter.hxx> | |
37 | #include <SelectMgr_OrFilter.hxx> | |
38 | #include <SelectMgr_Selection.hxx> | |
39 | #include <SelectMgr_SelectionManager.hxx> | |
40 | #include <Standard_Transient.hxx> | |
c3282ec1 | 41 | #include <StdSelect_BRepOwner.hxx> |
42cf5bc1 | 42 | #include <StdSelect_ViewerSelector3d.hxx> |
43 | #include <TCollection_AsciiString.hxx> | |
44 | #include <TCollection_ExtendedString.hxx> | |
45 | #include <TColStd_ListIteratorOfListOfInteger.hxx> | |
46 | #include <TopLoc_Location.hxx> | |
42cf5bc1 | 47 | #include <V3d_AmbientLight.hxx> |
48 | #include <V3d_DirectionalLight.hxx> | |
7fd59977 | 49 | #include <V3d_Light.hxx> |
50 | #include <V3d_PositionalLight.hxx> | |
51 | #include <V3d_SpotLight.hxx> | |
42cf5bc1 | 52 | #include <V3d_View.hxx> |
53 | #include <V3d_Viewer.hxx> | |
7fd59977 | 54 | |
c3282ec1 | 55 | typedef NCollection_DataMap<Handle(AIS_InteractiveObject), NCollection_Handle<SelectMgr_SequenceOfOwner> > AIS_MapOfObjSelectedOwners; |
56 | ||
016e5959 | 57 | namespace |
58 | { | |
59 | TopoDS_Shape AIS_myDummyShape; | |
60 | } | |
61 | ||
c3282ec1 | 62 | //======================================================================= |
63 | //function : highlightWithColor | |
64 | //purpose : | |
65 | //======================================================================= | |
66 | void AIS_InteractiveContext::highlightWithColor (const Handle(SelectMgr_EntityOwner)& theOwner, | |
c3282ec1 | 67 | const Handle(V3d_Viewer)& theViewer) |
68 | { | |
f838dac4 | 69 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()); |
c3282ec1 | 70 | if (anObj.IsNull()) |
f838dac4 | 71 | { |
c3282ec1 | 72 | return; |
f838dac4 | 73 | } |
74 | ||
75 | const Handle(Prs3d_Drawer)& aStyle = getHiStyle (anObj, theOwner); | |
76 | const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1); | |
c3282ec1 | 77 | |
78 | myMainPM->BeginImmediateDraw(); | |
f838dac4 | 79 | theOwner->HilightWithColor (myMainPM, aStyle, aHiMode); |
c3282ec1 | 80 | myMainPM->EndImmediateDraw (theViewer.IsNull() ? myMainVwr : theViewer); |
81 | } | |
82 | ||
83 | //======================================================================= | |
84 | //function : highlightSelected | |
85 | //purpose : | |
86 | //======================================================================= | |
8e5fb5ea | 87 | void AIS_InteractiveContext::highlightSelected (const Handle(SelectMgr_EntityOwner)& theOwner) |
c3282ec1 | 88 | { |
f838dac4 | 89 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()); |
c3282ec1 | 90 | if (anObj.IsNull()) |
f838dac4 | 91 | { |
c3282ec1 | 92 | return; |
f838dac4 | 93 | } |
c3282ec1 | 94 | |
95 | if (!theOwner->IsAutoHilight()) | |
96 | { | |
c3282ec1 | 97 | SelectMgr_SequenceOfOwner aSeq; |
02974a19 | 98 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) |
c3282ec1 | 99 | { |
8e5fb5ea | 100 | if (aSelIter.Value()->IsSameSelectable (anObj)) |
02974a19 | 101 | { |
102 | aSeq.Append (aSelIter.Value()); | |
103 | } | |
c3282ec1 | 104 | } |
105 | anObj->HilightSelected (myMainPM, aSeq); | |
106 | } | |
107 | else | |
108 | { | |
f838dac4 | 109 | const Handle(Prs3d_Drawer)& aStyle = getSelStyle (anObj, theOwner); |
110 | const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1); | |
111 | theOwner->HilightWithColor (myMainPM, aStyle, aHiMode); | |
8e5fb5ea | 112 | } |
113 | } | |
114 | ||
115 | //======================================================================= | |
116 | //function : highlightGlobal | |
117 | //purpose : | |
118 | //======================================================================= | |
119 | void AIS_InteractiveContext::highlightGlobal (const Handle(AIS_InteractiveObject)& theObj, | |
f838dac4 | 120 | const Handle(Prs3d_Drawer)& theStyle, |
121 | const Standard_Integer theDispMode) const | |
8e5fb5ea | 122 | { |
123 | if (theObj.IsNull()) | |
f838dac4 | 124 | { |
8e5fb5ea | 125 | return; |
f838dac4 | 126 | } |
127 | ||
128 | const Standard_Integer aHiMode = getHilightMode (theObj, theStyle, theDispMode); | |
8e5fb5ea | 129 | const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner(); |
130 | ||
131 | if (aGlobOwner.IsNull()) | |
132 | { | |
f838dac4 | 133 | myMainPM->Color (theObj, theStyle, aHiMode); |
8e5fb5ea | 134 | return; |
135 | } | |
136 | ||
137 | if (!aGlobOwner->IsAutoHilight()) | |
138 | { | |
139 | SelectMgr_SequenceOfOwner aSeq; | |
140 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) | |
141 | { | |
142 | if (aSelIter.Value()->IsSameSelectable (theObj)) | |
143 | { | |
144 | aSeq.Append (aSelIter.Value()); | |
145 | } | |
146 | } | |
147 | theObj->HilightSelected (myMainPM, aSeq); | |
148 | } | |
149 | else | |
150 | { | |
f838dac4 | 151 | aGlobOwner->HilightWithColor (myMainPM, theStyle, aHiMode); |
c3282ec1 | 152 | } |
153 | } | |
154 | ||
b4006117 | 155 | //======================================================================= |
156 | //function : unhighlightSelected | |
157 | //purpose : | |
158 | //======================================================================= | |
159 | void AIS_InteractiveContext::unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity) | |
160 | { | |
b4006117 | 161 | NCollection_IndexedMap<Handle(AIS_InteractiveObject)> anObjToClear; |
02974a19 | 162 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) |
b4006117 | 163 | { |
02974a19 | 164 | const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value(); |
165 | const Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); | |
f838dac4 | 166 | Handle(AIS_GlobalStatus) aStatus; |
167 | if (!myObjects.Find (anInteractive, aStatus)) | |
168 | { | |
169 | continue; | |
170 | } | |
171 | ||
b4006117 | 172 | if (anOwner->IsAutoHilight()) |
173 | { | |
f838dac4 | 174 | anOwner->Unhilight (myMainPM); |
b4006117 | 175 | if (theIsToHilightSubIntensity) |
176 | { | |
f838dac4 | 177 | if (aStatus->IsSubIntensityOn()) |
b4006117 | 178 | { |
f838dac4 | 179 | const Standard_Integer aHiMode = getHilightMode (anInteractive, aStatus->HilightStyle(), aStatus->DisplayMode()); |
8e5fb5ea | 180 | highlightWithSubintensity (anOwner, aHiMode); |
b4006117 | 181 | } |
182 | } | |
183 | } | |
184 | else | |
185 | { | |
f838dac4 | 186 | anObjToClear.Add (anInteractive); |
b4006117 | 187 | } |
f838dac4 | 188 | anOwner->SetSelected (Standard_False); |
b4006117 | 189 | if (anOwner == anInteractive->GlobalSelOwner()) |
190 | { | |
191 | myObjects.ChangeFind (anInteractive)->SetHilightStatus (Standard_False); | |
192 | } | |
193 | } | |
194 | for (NCollection_IndexedMap<Handle(AIS_InteractiveObject)>::Iterator anIter (anObjToClear); anIter.More(); anIter.Next()) | |
195 | { | |
196 | const Handle(AIS_InteractiveObject)& anObj = anIter.Value(); | |
f838dac4 | 197 | myMainPM->Unhighlight (anObj); |
b4006117 | 198 | anObj->ClearSelected(); |
199 | } | |
200 | } | |
201 | ||
8e5fb5ea | 202 | //======================================================================= |
203 | //function : unhighlightGlobal | |
204 | //purpose : | |
205 | //======================================================================= | |
f838dac4 | 206 | void AIS_InteractiveContext::unhighlightGlobal (const Handle(AIS_InteractiveObject)& theObj) const |
8e5fb5ea | 207 | { |
208 | if (theObj.IsNull()) | |
f838dac4 | 209 | { |
8e5fb5ea | 210 | return; |
f838dac4 | 211 | } |
8e5fb5ea | 212 | |
f838dac4 | 213 | const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner(); |
8e5fb5ea | 214 | if (aGlobOwner.IsNull()) |
215 | { | |
f838dac4 | 216 | myMainPM->Unhighlight (theObj); |
8e5fb5ea | 217 | return; |
218 | } | |
219 | ||
220 | if (aGlobOwner->IsAutoHilight()) | |
221 | { | |
f838dac4 | 222 | aGlobOwner->Unhilight (myMainPM); |
8e5fb5ea | 223 | } |
224 | else | |
225 | { | |
f838dac4 | 226 | myMainPM->Unhighlight (theObj); |
8e5fb5ea | 227 | theObj->ClearSelected(); |
228 | } | |
229 | } | |
230 | ||
231 | //======================================================================= | |
232 | //function : turnOnSubintensity | |
233 | //purpose : | |
234 | //======================================================================= | |
235 | void AIS_InteractiveContext::turnOnSubintensity (const Handle(AIS_InteractiveObject)& theObject, | |
236 | const Standard_Integer theDispMode, | |
237 | const Standard_Boolean theIsDisplayedOnly) const | |
238 | { | |
f838dac4 | 239 | // the only differ with selection highlight is color, so sync transparency values |
240 | const Handle(Prs3d_Drawer)& aSubStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity]; | |
241 | aSubStyle->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency()); | |
8e5fb5ea | 242 | |
243 | if (theObject.IsNull()) | |
244 | { | |
245 | for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjsIter (myObjects); anObjsIter.More(); anObjsIter.Next()) | |
246 | { | |
247 | const Handle(AIS_GlobalStatus)& aStatus = anObjsIter.Value(); | |
248 | if (aStatus->GraphicStatus() != AIS_DS_Displayed && theIsDisplayedOnly) | |
249 | continue; | |
250 | ||
251 | aStatus->SubIntensityOn(); | |
f838dac4 | 252 | myMainPM->Color (anObjsIter.Key(), aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode()); |
8e5fb5ea | 253 | } |
254 | } | |
255 | else | |
256 | { | |
257 | Handle(AIS_GlobalStatus) aStatus; | |
258 | if (!myObjects.Find (theObject, aStatus)) | |
259 | return; | |
260 | ||
261 | if (aStatus->GraphicStatus() != AIS_DS_Displayed && theIsDisplayedOnly) | |
f838dac4 | 262 | return; |
8e5fb5ea | 263 | |
264 | aStatus->SubIntensityOn(); | |
f838dac4 | 265 | myMainPM->Color (theObject, aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode()); |
8e5fb5ea | 266 | } |
267 | } | |
268 | ||
269 | //======================================================================= | |
270 | //function : highlightWithSubintensity | |
271 | //purpose : | |
272 | //======================================================================= | |
273 | void AIS_InteractiveContext::highlightWithSubintensity (const Handle(AIS_InteractiveObject)& theObject, | |
274 | const Standard_Integer theMode) const | |
275 | { | |
276 | // the only differ with selection highlight is color, so | |
277 | // sync transparency values | |
f838dac4 | 278 | myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency()); |
8e5fb5ea | 279 | |
f838dac4 | 280 | myMainPM->Color (theObject, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode); |
8e5fb5ea | 281 | } |
282 | ||
283 | //======================================================================= | |
284 | //function : highlightWithSubintensity | |
285 | //purpose : | |
286 | //======================================================================= | |
287 | void AIS_InteractiveContext::highlightWithSubintensity (const Handle(SelectMgr_EntityOwner)& theOwner, | |
288 | const Standard_Integer theMode) const | |
289 | { | |
290 | // the only differ with selection highlight is color, so | |
291 | // sync transparency values | |
f838dac4 | 292 | myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency()); |
8e5fb5ea | 293 | |
f838dac4 | 294 | theOwner->HilightWithColor (myMainPM, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode); |
8e5fb5ea | 295 | } |
296 | ||
7fd59977 | 297 | //======================================================================= |
298 | //function : MoveTo | |
679ecdee | 299 | //purpose : |
7fd59977 | 300 | //======================================================================= |
679ecdee | 301 | AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix, |
302 | const Standard_Integer theYPix, | |
303 | const Handle(V3d_View)& theView, | |
304 | const Standard_Boolean theToRedrawOnUpdate) | |
7fd59977 | 305 | { |
679ecdee | 306 | if (HasOpenedContext()) |
307 | { | |
7fd59977 | 308 | myWasLastMain = Standard_True; |
679ecdee | 309 | return myLocalContexts (myCurLocalIndex)->MoveTo (theXPix, theYPix, theView, theToRedrawOnUpdate); |
7fd59977 | 310 | } |
311 | ||
f0cddd16 | 312 | myCurDetected = 0; |
313 | myCurHighlighted = 0; | |
314 | myDetectedSeq.Clear(); | |
7fd59977 | 315 | |
679ecdee | 316 | if (theView->Viewer() != myMainVwr) |
317 | { | |
7fd59977 | 318 | return AIS_SOD_Error; |
679ecdee | 319 | } |
320 | ||
321 | // preliminaires | |
322 | myLastPicked = myLastinMain; | |
323 | myWasLastMain = Standard_True; | |
324 | AIS_StatusOfDetection aStatus = AIS_SOD_Nothing; | |
325 | Standard_Boolean toUpdateViewer = Standard_False; | |
326 | ||
a272ed94 | 327 | myFilters->SetDisabledObjects (theView->View()->HiddenObjects()); |
679ecdee | 328 | myMainSel->Pick (theXPix, theYPix, theView); |
329 | ||
330 | // filling of myAISDetectedSeq sequence storing information about detected AIS objects | |
331 | // (the objects must be AIS_Shapes) | |
332 | const Standard_Integer aDetectedNb = myMainSel->NbPicked(); | |
54a16ee4 | 333 | Standard_Integer aNewDetected = 0; |
14c4193d | 334 | Standard_Boolean toIgnoreDetTop = Standard_False; |
679ecdee | 335 | for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter) |
7fd59977 | 336 | { |
679ecdee | 337 | Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter); |
338 | if (anOwner.IsNull() | |
339 | || !myFilters->IsOk (anOwner)) | |
340 | { | |
14c4193d | 341 | if (myPickingStrategy == SelectMgr_PickingStrategy_OnlyTopmost) |
342 | { | |
343 | toIgnoreDetTop = Standard_True; | |
344 | } | |
679ecdee | 345 | continue; |
346 | } | |
347 | ||
14c4193d | 348 | if (aNewDetected < 1 |
349 | && !toIgnoreDetTop) | |
54a16ee4 | 350 | { |
351 | aNewDetected = aDetIter; | |
352 | } | |
f0cddd16 | 353 | |
354 | myDetectedSeq.Append (aDetIter); | |
7fd59977 | 355 | } |
7fd59977 | 356 | |
54a16ee4 | 357 | if (aNewDetected >= 1) |
7fd59977 | 358 | { |
f0cddd16 | 359 | myCurHighlighted = myDetectedSeq.Lower(); |
360 | ||
29627b4c | 361 | // Does nothing if previously detected object is equal to the current one. |
362 | // However in advanced selection modes the owners comparison | |
363 | // is not effective because in that case only one owner manage the | |
364 | // selection in current selection mode. It is necessary to check the current detected | |
365 | // entity and hilight it only if the detected entity is not the same as | |
366 | // previous detected (IsForcedHilight call) | |
54a16ee4 | 367 | Handle(SelectMgr_EntityOwner) aNewPickedOwner = myMainSel->Picked (aNewDetected); |
29627b4c | 368 | if (aNewPickedOwner == myLastPicked && !aNewPickedOwner->IsForcedHilight()) |
eafb234b | 369 | { |
c3282ec1 | 370 | return myLastPicked->IsSelected() |
8abada55 | 371 | ? AIS_SOD_Selected |
372 | : AIS_SOD_OnlyOneDetected; | |
679ecdee | 373 | } |
81bba717 | 374 | |
7fd59977 | 375 | // Previously detected object is unhilighted if it is not selected or hilighted |
376 | // with selection color if it is selected. Such highlighting with selection color | |
377 | // is needed only if myToHilightSelected flag is true. In this case previously detected | |
378 | // object has been already highlighted with myHilightColor during previous MoveTo() | |
379 | // method call. As result it is necessary to rehighligt it with mySelectionColor. | |
c3282ec1 | 380 | if (!myLastPicked.IsNull() && myLastPicked->HasSelectable()) |
7fd59977 | 381 | { |
731c9b5b | 382 | clearDynamicHighlight(); |
383 | toUpdateViewer = Standard_True; | |
7fd59977 | 384 | } |
be6e564e | 385 | |
679ecdee | 386 | // initialize myLastPicked field with currently detected object |
c3282ec1 | 387 | myLastPicked = aNewPickedOwner; |
679ecdee | 388 | myLastinMain = myLastPicked; |
be6e564e | 389 | |
679ecdee | 390 | // highlight detected object if it is not selected or myToHilightSelected flag is true |
c3282ec1 | 391 | if (myLastPicked->HasSelectable()) |
7fd59977 | 392 | { |
c3282ec1 | 393 | if (!myLastPicked->IsSelected() || myToHilightSelected) |
679ecdee | 394 | { |
8e5fb5ea | 395 | highlightWithColor (myLastPicked, theView->Viewer()); |
679ecdee | 396 | toUpdateViewer = Standard_True; |
397 | } | |
be6e564e | 398 | |
c3282ec1 | 399 | aStatus = myLastPicked->IsSelected() |
8abada55 | 400 | ? AIS_SOD_Selected |
401 | : AIS_SOD_OnlyOneDetected; | |
be6e564e | 402 | } |
7fd59977 | 403 | } |
c3282ec1 | 404 | else |
7fd59977 | 405 | { |
679ecdee | 406 | // previously detected object is unhilighted if it is not selected or hilighted |
407 | // with selection color if it is selected | |
408 | aStatus = AIS_SOD_Nothing; | |
c3282ec1 | 409 | if (!myLastPicked.IsNull() && myLastPicked->HasSelectable()) |
7fd59977 | 410 | { |
731c9b5b | 411 | clearDynamicHighlight(); |
412 | toUpdateViewer = Standard_True; | |
7fd59977 | 413 | } |
be6e564e | 414 | |
679ecdee | 415 | myLastinMain.Nullify(); |
8abada55 | 416 | myLastPicked.Nullify(); |
7fd59977 | 417 | } |
679ecdee | 418 | |
2eea6525 | 419 | if (toUpdateViewer |
420 | && theToRedrawOnUpdate) | |
679ecdee | 421 | { |
2eea6525 | 422 | theView->Viewer()->Update(); |
679ecdee | 423 | } |
424 | ||
679ecdee | 425 | mylastmoveview = theView; |
426 | return aStatus; | |
7fd59977 | 427 | } |
428 | ||
016e5959 | 429 | //======================================================================= |
430 | //function : AddSelect | |
431 | //purpose : | |
432 | //======================================================================= | |
02974a19 | 433 | AIS_StatusOfPick AIS_InteractiveContext::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject) |
016e5959 | 434 | { |
435 | if (HasOpenedContext()) | |
436 | { | |
437 | return myLocalContexts(myCurLocalIndex)->AddSelect (theObject); | |
438 | } | |
439 | mySelection->AddSelect (theObject); | |
440 | ||
441 | Standard_Integer aSelNum = NbSelected(); | |
442 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
443 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
444 | : AIS_SOP_SeveralSelected; | |
445 | } | |
446 | ||
7fd59977 | 447 | //======================================================================= |
448 | //function : Select | |
449 | //purpose : | |
450 | //======================================================================= | |
c398b00e | 451 | AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin, |
452 | const Standard_Integer theYPMin, | |
453 | const Standard_Integer theXPMax, | |
454 | const Standard_Integer theYPMax, | |
455 | const Handle(V3d_View)& theView, | |
456 | const Standard_Boolean toUpdateViewer) | |
7fd59977 | 457 | { |
81bba717 | 458 | // all objects detected by the selector are taken, previous current objects are emptied, |
459 | // new objects are put... | |
7fd59977 | 460 | |
c398b00e | 461 | if (HasOpenedContext()) |
462 | { | |
463 | return myLocalContexts(myCurLocalIndex)->Select (theXPMin, theYPMin, | |
464 | theXPMax, theYPMax, | |
465 | theView, toUpdateViewer); | |
466 | } | |
7fd59977 | 467 | |
c3282ec1 | 468 | ClearSelected (Standard_False); |
eb4320f2 | 469 | |
c398b00e | 470 | Handle(StdSelect_ViewerSelector3d) aSelector; |
7fd59977 | 471 | |
c398b00e | 472 | if (theView->Viewer() == myMainVwr) |
7fd59977 | 473 | { |
c398b00e | 474 | aSelector = myMainSel; |
475 | myWasLastMain = Standard_True; | |
7fd59977 | 476 | } |
c398b00e | 477 | |
478 | aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView); | |
aa75c0cf | 479 | for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter) |
7fd59977 | 480 | { |
aa75c0cf | 481 | const Handle(SelectMgr_EntityOwner)& aCurOwner = aSelector->Picked (aPickIter); |
c3282ec1 | 482 | if (aCurOwner.IsNull() || !aCurOwner->HasSelectable() || !myFilters->IsOk (aCurOwner)) |
483 | continue; | |
7fd59977 | 484 | |
016e5959 | 485 | mySelection->Select (aCurOwner); |
f838dac4 | 486 | aCurOwner->SetSelected (Standard_True); |
c398b00e | 487 | } |
488 | ||
c3282ec1 | 489 | HilightSelected (toUpdateViewer); |
c398b00e | 490 | |
c3282ec1 | 491 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 492 | |
493 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
494 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
495 | : AIS_SOP_SeveralSelected; | |
7fd59977 | 496 | |
497 | } | |
498 | ||
499 | //======================================================================= | |
500 | //function : Select | |
501 | //purpose : Selection by polyline | |
502 | //======================================================================= | |
c398b00e | 503 | AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline, |
504 | const Handle(V3d_View)& theView, | |
505 | const Standard_Boolean toUpdateViewer) | |
7fd59977 | 506 | { |
81bba717 | 507 | // all objects detected by the selector are taken, previous current objects are emptied, |
508 | // new objects are put... | |
7fd59977 | 509 | |
c398b00e | 510 | if (HasOpenedContext()) |
511 | { | |
512 | return myLocalContexts(myCurLocalIndex)->Select (thePolyline, theView, toUpdateViewer); | |
513 | } | |
eb4320f2 | 514 | |
c3282ec1 | 515 | ClearSelected (Standard_False); |
7fd59977 | 516 | |
c398b00e | 517 | Handle(StdSelect_ViewerSelector3d) aSelector; |
7fd59977 | 518 | |
c398b00e | 519 | if (theView->Viewer() == myMainVwr) |
7fd59977 | 520 | { |
c398b00e | 521 | aSelector = myMainSel; |
522 | myWasLastMain = Standard_True; | |
7fd59977 | 523 | } |
c398b00e | 524 | |
525 | aSelector->Pick (thePolyline, theView); | |
aa75c0cf | 526 | for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter) |
7fd59977 | 527 | { |
aa75c0cf | 528 | const Handle(SelectMgr_EntityOwner) anOwner = aSelector->Picked (aPickIter); |
c3282ec1 | 529 | if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner)) |
530 | continue; | |
c398b00e | 531 | |
016e5959 | 532 | mySelection->Select (anOwner); |
f838dac4 | 533 | anOwner->SetSelected (Standard_True); |
c398b00e | 534 | } |
535 | ||
c3282ec1 | 536 | HilightSelected (toUpdateViewer); |
c398b00e | 537 | |
c3282ec1 | 538 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 539 | |
540 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
541 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
542 | : AIS_SOP_SeveralSelected; | |
7fd59977 | 543 | |
544 | } | |
545 | ||
546 | //======================================================================= | |
547 | //function : Select | |
548 | //purpose : | |
549 | //======================================================================= | |
c398b00e | 550 | AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer) |
7fd59977 | 551 | { |
c398b00e | 552 | if (HasOpenedContext()) |
553 | { | |
7fd59977 | 554 | if(myWasLastMain) |
c398b00e | 555 | { |
556 | return myLocalContexts(myCurLocalIndex)->Select (toUpdateViewer); | |
557 | } | |
7fd59977 | 558 | else |
c398b00e | 559 | { |
c3282ec1 | 560 | myLocalContexts(myCurLocalIndex)->SetSelected (Handle(AIS_InteractiveObject)::DownCast (myLastPicked->Selectable()), toUpdateViewer); |
c398b00e | 561 | return AIS_SOP_OneSelected; |
562 | } | |
563 | } | |
564 | ||
731c9b5b | 565 | clearDynamicHighlight(); |
c398b00e | 566 | if (myWasLastMain && !myLastinMain.IsNull()) |
567 | { | |
731c9b5b | 568 | if (!myLastinMain->IsSelected() || myLastinMain->IsForcedHilight()) |
c398b00e | 569 | { |
c3282ec1 | 570 | SetSelected (myLastinMain, Standard_False); |
c398b00e | 571 | if(toUpdateViewer) |
7fd59977 | 572 | { |
c398b00e | 573 | UpdateCurrentViewer(); |
7fd59977 | 574 | } |
c398b00e | 575 | } |
7fd59977 | 576 | } |
c398b00e | 577 | else |
578 | { | |
b4006117 | 579 | unhighlightSelected (Standard_True); |
c398b00e | 580 | |
02974a19 | 581 | mySelection->Clear(); |
c398b00e | 582 | if (toUpdateViewer && myWasLastMain) |
583 | { | |
eb4320f2 | 584 | UpdateCurrentViewer(); |
7fd59977 | 585 | } |
586 | } | |
c398b00e | 587 | |
c3282ec1 | 588 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 589 | |
590 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
591 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
592 | : AIS_SOP_SeveralSelected; | |
7fd59977 | 593 | } |
594 | ||
595 | //======================================================================= | |
596 | //function : ShiftSelect | |
597 | //purpose : | |
598 | //======================================================================= | |
c398b00e | 599 | AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer) |
7fd59977 | 600 | { |
c398b00e | 601 | if (HasOpenedContext()) |
602 | { | |
7fd59977 | 603 | if(myWasLastMain) |
c398b00e | 604 | { |
605 | return myLocalContexts (myCurLocalIndex)->ShiftSelect (toUpdateViewer); | |
606 | } | |
607 | else | |
608 | { | |
609 | myLocalContexts (myCurLocalIndex)->AddOrRemoveSelected (myLastPicked, toUpdateViewer); | |
610 | ||
611 | Standard_Integer aSelNum = NbSelected(); | |
612 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
613 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
614 | : AIS_SOP_SeveralSelected; | |
7fd59977 | 615 | } |
616 | } | |
eb4320f2 | 617 | |
731c9b5b | 618 | clearDynamicHighlight(); |
c398b00e | 619 | if (myWasLastMain && !myLastinMain.IsNull()) |
620 | { | |
c3282ec1 | 621 | AddOrRemoveSelected (myLastinMain, toUpdateViewer); |
c398b00e | 622 | } |
7fd59977 | 623 | |
c3282ec1 | 624 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 625 | |
c3282ec1 | 626 | return (aSelNum == 0) ? AIS_SOP_NothingSelected |
627 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
628 | : AIS_SOP_SeveralSelected; | |
c398b00e | 629 | } |
7fd59977 | 630 | |
631 | //======================================================================= | |
632 | //function : ShiftSelect | |
633 | //purpose : | |
634 | //======================================================================= | |
c398b00e | 635 | AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin, |
636 | const Standard_Integer theYPMin, | |
637 | const Standard_Integer theXPMax, | |
638 | const Standard_Integer theYPMax, | |
639 | const Handle(V3d_View)& theView, | |
640 | const Standard_Boolean toUpdateViewer) | |
7fd59977 | 641 | { |
c398b00e | 642 | if (HasOpenedContext()) |
643 | { | |
644 | return myLocalContexts(myCurLocalIndex)->ShiftSelect (theXPMin, theYPMin, theXPMax, theYPMax, | |
645 | theView, toUpdateViewer); | |
646 | } | |
647 | ||
c3282ec1 | 648 | UnhilightSelected (Standard_False); |
c398b00e | 649 | |
650 | Handle(StdSelect_ViewerSelector3d) aSelector; | |
651 | if (theView->Viewer() == myMainVwr) | |
652 | { | |
653 | aSelector = myMainSel; | |
654 | myWasLastMain = Standard_True; | |
655 | } | |
7fd59977 | 656 | else |
c398b00e | 657 | { |
7fd59977 | 658 | return AIS_SOP_NothingSelected; |
c398b00e | 659 | } |
660 | ||
661 | aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView); | |
aa75c0cf | 662 | for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter) |
c398b00e | 663 | { |
aa75c0cf | 664 | const Handle(SelectMgr_EntityOwner) anOwner = aSelector->Picked (aPickIter); |
c3282ec1 | 665 | if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner)) |
666 | continue; | |
667 | ||
016e5959 | 668 | AIS_SelectStatus aSelStatus = mySelection->Select (anOwner); |
f838dac4 | 669 | anOwner->SetSelected (aSelStatus == AIS_SS_Added); |
7fd59977 | 670 | } |
c398b00e | 671 | |
c3282ec1 | 672 | HilightSelected (toUpdateViewer); |
c398b00e | 673 | |
c3282ec1 | 674 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 675 | |
676 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
677 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
678 | : AIS_SOP_SeveralSelected; | |
679 | ||
7fd59977 | 680 | } |
681 | ||
682 | //======================================================================= | |
683 | //function : ShiftSelect | |
684 | //purpose : | |
685 | //======================================================================= | |
c398b00e | 686 | AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline, |
687 | const Handle(V3d_View)& theView, | |
688 | const Standard_Boolean toUpdateViewer) | |
7fd59977 | 689 | { |
c398b00e | 690 | if (HasOpenedContext()) |
691 | { | |
692 | return myLocalContexts(myCurLocalIndex)->ShiftSelect (thePolyline, theView, toUpdateViewer); | |
693 | } | |
7fd59977 | 694 | |
c3282ec1 | 695 | UnhilightSelected (Standard_False); |
c398b00e | 696 | |
697 | Handle(StdSelect_ViewerSelector3d) aSelector; | |
698 | ||
699 | if (theView->Viewer() == myMainVwr) | |
700 | { | |
701 | aSelector= myMainSel; | |
702 | myWasLastMain = Standard_True; | |
703 | } | |
704 | else | |
705 | { | |
706 | return AIS_SOP_NothingSelected; | |
707 | } | |
708 | ||
709 | aSelector->Pick (thePolyline, theView); | |
aa75c0cf | 710 | for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter) |
c398b00e | 711 | { |
aa75c0cf | 712 | const Handle(SelectMgr_EntityOwner) anOwner = aSelector->Picked (aPickIter); |
c3282ec1 | 713 | if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner)) |
714 | continue; | |
715 | ||
016e5959 | 716 | AIS_SelectStatus aSelStatus = mySelection->Select (anOwner); |
f838dac4 | 717 | anOwner->SetSelected (aSelStatus == AIS_SS_Added); |
c398b00e | 718 | } |
719 | ||
c3282ec1 | 720 | HilightSelected (toUpdateViewer); |
c398b00e | 721 | |
c3282ec1 | 722 | Standard_Integer aSelNum = NbSelected(); |
c398b00e | 723 | |
724 | return (aSelNum == 0) ? AIS_SOP_NothingSelected | |
725 | : (aSelNum == 1) ? AIS_SOP_OneSelected | |
726 | : AIS_SOP_SeveralSelected; | |
7fd59977 | 727 | } |
728 | ||
729 | //======================================================================= | |
730 | //function : SetCurrentObject | |
c3282ec1 | 731 | //purpose : OBSOLETE, please use SetSelected() instead |
732 | //TODO : Remove in process of local context deletion | |
7fd59977 | 733 | //======================================================================= |
c3282ec1 | 734 | void AIS_InteractiveContext::SetCurrentObject (const Handle(AIS_InteractiveObject)& theObject, |
735 | const Standard_Boolean theToUpdateViewer) | |
7fd59977 | 736 | { |
c3282ec1 | 737 | if (HasOpenedContext()) |
7fd59977 | 738 | return; |
7fd59977 | 739 | |
c3282ec1 | 740 | SetSelected (theObject, theToUpdateViewer); |
7fd59977 | 741 | } |
742 | ||
743 | //======================================================================= | |
744 | //function : AddOrRemoveCurrentObject | |
c3282ec1 | 745 | //purpose : OBSOLETE, please use AddOrRemoveSelected() instead |
746 | //TODO : Remove in process of local context deletion | |
7fd59977 | 747 | //======================================================================= |
c3282ec1 | 748 | void AIS_InteractiveContext::AddOrRemoveCurrentObject (const Handle(AIS_InteractiveObject)& theObj, |
749 | const Standard_Boolean theIsToUpdateViewer) | |
7fd59977 | 750 | { |
c3282ec1 | 751 | if (HasOpenedContext()) |
752 | return; | |
7fd59977 | 753 | |
c3282ec1 | 754 | AddOrRemoveSelected (theObj, theIsToUpdateViewer); |
7fd59977 | 755 | } |
756 | //======================================================================= | |
757 | //function : UpdateCurrent | |
c3282ec1 | 758 | //purpose : OBSOLETE, please use UpdateSelected() instead |
759 | //TODO : Remove in process of local context deletion | |
7fd59977 | 760 | //======================================================================= |
7fd59977 | 761 | void AIS_InteractiveContext::UpdateCurrent() |
762 | { | |
0577ae8c | 763 | UpdateSelected (Standard_True); |
7fd59977 | 764 | } |
765 | ||
766 | //======================================================================= | |
767 | //function : IsCurrent | |
c3282ec1 | 768 | //purpose : OBSOLETE, please use IsSelected() instead |
769 | //TODO : Remove in process of local context deletion | |
7fd59977 | 770 | //======================================================================= |
c3282ec1 | 771 | Standard_Boolean AIS_InteractiveContext::IsCurrent (const Handle(AIS_InteractiveObject)& theObject) const |
7fd59977 | 772 | { |
c3282ec1 | 773 | return IsSelected (theObject); |
7fd59977 | 774 | } |
775 | ||
776 | //======================================================================= | |
777 | //function : InitCurrent | |
c3282ec1 | 778 | //purpose : OBSOLETE, please use InitSelected() instead |
779 | //TODO : Remove in process of local context deletion | |
7fd59977 | 780 | //======================================================================= |
7fd59977 | 781 | void AIS_InteractiveContext::InitCurrent() |
782 | { | |
c3282ec1 | 783 | if (HasOpenedContext()) |
784 | return; | |
785 | ||
786 | InitSelected(); | |
7fd59977 | 787 | } |
788 | ||
789 | //======================================================================= | |
790 | //function : MoreCurrent | |
c3282ec1 | 791 | //purpose : OBSOLETE, please use MoreSelected() instead |
792 | //TODO : Remove in process of local context deletion | |
7fd59977 | 793 | //======================================================================= |
7fd59977 | 794 | Standard_Boolean AIS_InteractiveContext::MoreCurrent() const |
795 | { | |
c3282ec1 | 796 | return !HasOpenedContext() && MoreSelected(); |
7fd59977 | 797 | } |
798 | ||
799 | //======================================================================= | |
800 | //function : NextCurrent | |
c3282ec1 | 801 | //purpose : OBSOLETE, please use NextSelected() instead |
802 | //TODO : Remove in process of local context deletion | |
7fd59977 | 803 | //======================================================================= |
7fd59977 | 804 | void AIS_InteractiveContext::NextCurrent() |
805 | { | |
c3282ec1 | 806 | if (HasOpenedContext()) |
807 | return; | |
808 | ||
809 | NextSelected(); | |
7fd59977 | 810 | } |
811 | ||
812 | //======================================================================= | |
813 | //function : Current | |
c3282ec1 | 814 | //purpose : OBSOLETE, please use SelectedInteractive() instead |
815 | //TODO : Remove in process of local context deletion | |
7fd59977 | 816 | //======================================================================= |
7fd59977 | 817 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const |
818 | { | |
c3282ec1 | 819 | return HasOpenedContext() ? NULL : SelectedInteractive(); |
7fd59977 | 820 | } |
821 | ||
822 | //======================================================================= | |
823 | //function : NbCurrents | |
c3282ec1 | 824 | //purpose : OBSOLETE, please use NbSelected() instead |
825 | //TODO : Remove in process of local context deletion | |
7fd59977 | 826 | //======================================================================= |
827 | Standard_Integer AIS_InteractiveContext::NbCurrents() | |
828 | { | |
c3282ec1 | 829 | return HasOpenedContext() ? -1 : NbSelected(); |
7fd59977 | 830 | } |
831 | ||
832 | //======================================================================= | |
833 | //function : HilightCurrents | |
c3282ec1 | 834 | //purpose : OBSOLETE, please use HilightSelected() instead |
835 | //TODO : Remove in process of local context deletion | |
7fd59977 | 836 | //======================================================================= |
c3282ec1 | 837 | void AIS_InteractiveContext::HilightCurrents (const Standard_Boolean theToUpdateViewer) |
7fd59977 | 838 | { |
c3282ec1 | 839 | if (HasOpenedContext()) |
840 | return; | |
841 | ||
842 | HilightSelected (theToUpdateViewer); | |
7fd59977 | 843 | } |
844 | ||
845 | //======================================================================= | |
846 | //function : UnhilightCurrents | |
c3282ec1 | 847 | //purpose : OBSOLETE, please use UnhilightSelected() instead |
848 | //TODO : Remove in process of local context deletion | |
7fd59977 | 849 | //======================================================================= |
c3282ec1 | 850 | void AIS_InteractiveContext::UnhilightCurrents (const Standard_Boolean theToUpdateViewer) |
7fd59977 | 851 | { |
c3282ec1 | 852 | if (HasOpenedContext()) |
853 | return; | |
854 | ||
855 | UnhilightSelected (theToUpdateViewer); | |
7fd59977 | 856 | } |
857 | ||
858 | //======================================================================= | |
859 | //function : ClearCurrents | |
c3282ec1 | 860 | //purpose : OBSOLETE, please use ClearCurrents() instead |
861 | //TODO : Remove in process of local context deletion | |
7fd59977 | 862 | //======================================================================= |
c3282ec1 | 863 | void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean theToUpdateViewer) |
7fd59977 | 864 | { |
c3282ec1 | 865 | if (HasOpenedContext()) |
866 | return; | |
867 | ||
868 | ClearSelected (theToUpdateViewer); | |
7fd59977 | 869 | } |
870 | ||
871 | ||
872 | //======================================================================= | |
873 | //function : HilightSelected | |
c3282ec1 | 874 | //purpose : |
7fd59977 | 875 | //======================================================================= |
c3282ec1 | 876 | void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdateViewer) |
7fd59977 | 877 | { |
c3282ec1 | 878 | if (HasOpenedContext()) |
879 | { | |
880 | return myLocalContexts (myCurLocalIndex)->HilightPicked (theToUpdateViewer); | |
881 | } | |
882 | ||
883 | // In case of selection without using local context | |
731c9b5b | 884 | clearDynamicHighlight(); |
c3282ec1 | 885 | AIS_MapOfObjSelectedOwners anObjOwnerMap; |
02974a19 | 886 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) |
c3282ec1 | 887 | { |
02974a19 | 888 | const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value(); |
889 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); | |
f838dac4 | 890 | const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObj, anOwner); |
891 | Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind(anObj); | |
02974a19 | 892 | if (anOwner == anObj->GlobalSelOwner()) |
c3282ec1 | 893 | { |
02974a19 | 894 | aState->SetHilightStatus (Standard_True); |
8e5fb5ea | 895 | aState->SetHilightStyle (anObjSelStyle); |
02974a19 | 896 | } |
f838dac4 | 897 | anOwner->SetSelected (Standard_True); |
02974a19 | 898 | if (!anOwner->IsAutoHilight()) |
899 | { | |
900 | NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq; | |
901 | if (anObjOwnerMap.Find (anObj, aSeq)) | |
c3282ec1 | 902 | { |
02974a19 | 903 | aSeq->Append (anOwner); |
c3282ec1 | 904 | } |
905 | else | |
906 | { | |
02974a19 | 907 | aSeq = new SelectMgr_SequenceOfOwner(); |
908 | aSeq->Append (anOwner); | |
909 | anObjOwnerMap.Bind (anObj, aSeq); | |
c3282ec1 | 910 | } |
7fd59977 | 911 | } |
02974a19 | 912 | else |
913 | { | |
f838dac4 | 914 | const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, aState->DisplayMode()); |
8e5fb5ea | 915 | anOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode); |
02974a19 | 916 | } |
7fd59977 | 917 | } |
c3282ec1 | 918 | |
919 | if (!anObjOwnerMap.IsEmpty()) | |
920 | { | |
921 | for (AIS_MapOfObjSelectedOwners::Iterator anIter (anObjOwnerMap); anIter.More(); anIter.Next()) | |
7fd59977 | 922 | { |
c3282ec1 | 923 | anIter.Key()->HilightSelected (myMainPM, *anIter.Value()); |
7fd59977 | 924 | } |
c3282ec1 | 925 | anObjOwnerMap.Clear(); |
926 | } | |
927 | ||
928 | if (theToUpdateViewer) | |
7fd59977 | 929 | UpdateCurrentViewer(); |
930 | } | |
931 | ||
932 | //======================================================================= | |
933 | //function : UnhilightSelected | |
c3282ec1 | 934 | //purpose : |
7fd59977 | 935 | //======================================================================= |
c3282ec1 | 936 | void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer) |
7fd59977 | 937 | { |
c3282ec1 | 938 | if (HasOpenedContext()) |
939 | { | |
940 | return myLocalContexts (myCurLocalIndex)->UnhilightPicked (theToUpdateViewer); | |
7fd59977 | 941 | } |
c3282ec1 | 942 | |
02974a19 | 943 | for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) |
c3282ec1 | 944 | { |
02974a19 | 945 | const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value(); |
946 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); | |
947 | if (anOwner == anObj->GlobalSelOwner()) | |
7fd59977 | 948 | { |
02974a19 | 949 | myObjects.ChangeFind (anObj)->SetHilightStatus (Standard_False); |
7fd59977 | 950 | } |
02974a19 | 951 | |
f838dac4 | 952 | anOwner->SetSelected (Standard_False); |
953 | anOwner->Unhilight (myMainPM); | |
c3282ec1 | 954 | } |
955 | ||
956 | if (theToUpdateViewer) | |
957 | UpdateCurrentViewer(); | |
7fd59977 | 958 | } |
959 | ||
960 | ||
961 | //======================================================================= | |
962 | //function : ClearSelected | |
c3282ec1 | 963 | //purpose : |
7fd59977 | 964 | //======================================================================= |
c3282ec1 | 965 | void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateViewer) |
7fd59977 | 966 | { |
c3282ec1 | 967 | if (HasOpenedContext()) |
968 | return myLocalContexts (myCurLocalIndex)->ClearSelected (theToUpdateViewer); | |
7fd59977 | 969 | |
c3282ec1 | 970 | if (NbSelected() == 0) |
971 | return; | |
7fd59977 | 972 | |
b4006117 | 973 | unhighlightSelected(); |
7fd59977 | 974 | |
02974a19 | 975 | mySelection->Clear(); |
731c9b5b | 976 | clearDynamicHighlight(); |
7fd59977 | 977 | |
c3282ec1 | 978 | if (theToUpdateViewer) |
979 | UpdateCurrentViewer(); | |
7fd59977 | 980 | } |
981 | ||
982 | //======================================================================= | |
c3282ec1 | 983 | //function : UpdateSelected |
984 | //purpose : | |
7fd59977 | 985 | //======================================================================= |
c3282ec1 | 986 | void AIS_InteractiveContext::UpdateSelected (const Standard_Boolean theToUpdateViewer) |
987 | { | |
988 | if (HasOpenedContext()) | |
989 | { | |
990 | return myLocalContexts(myCurLocalIndex)->UpdateSelected (theToUpdateViewer); | |
991 | } | |
7fd59977 | 992 | |
c3282ec1 | 993 | HilightSelected (theToUpdateViewer); |
994 | } | |
995 | ||
996 | //======================================================================= | |
997 | //function : SetSelected | |
998 | //purpose : Sets the whole object as selected and highlights it with selection color | |
999 | //======================================================================= | |
1000 | void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& theObject, | |
1001 | const Standard_Boolean theToUpdateViewer) | |
7fd59977 | 1002 | { |
f838dac4 | 1003 | if (HasOpenedContext()) |
c3282ec1 | 1004 | { |
1005 | return myLocalContexts (myCurLocalIndex)->SetSelected (theObject, theToUpdateViewer); | |
1006 | } | |
1007 | ||
1008 | if (theObject.IsNull()) | |
f838dac4 | 1009 | { |
7fd59977 | 1010 | return; |
f838dac4 | 1011 | } |
1012 | ||
1013 | if (!myObjects.IsBound (theObject)) | |
1014 | { | |
c3282ec1 | 1015 | Display (theObject, Standard_False); |
f838dac4 | 1016 | } |
0d5880e1 | 1017 | if (!theObject->HasSelection (theObject->GlobalSelectionMode())) |
f838dac4 | 1018 | { |
c3282ec1 | 1019 | return; |
f838dac4 | 1020 | } |
1021 | Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner(); | |
1022 | if (anOwner.IsNull()) | |
1023 | { | |
1024 | return; | |
1025 | } | |
c3282ec1 | 1026 | |
f838dac4 | 1027 | const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (theObject, anOwner); |
e1b01c73 | 1028 | if (NbSelected() == 1 && myObjects (theObject)->IsHilighted()) |
c3282ec1 | 1029 | { |
f838dac4 | 1030 | Handle(Prs3d_Drawer) aCustomStyle; |
8e5fb5ea | 1031 | if (HighlightStyle (theObject, aCustomStyle)) |
c3282ec1 | 1032 | { |
8e5fb5ea | 1033 | if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle) |
c3282ec1 | 1034 | { |
8e5fb5ea | 1035 | HilightWithColor (theObject, anObjSelStyle, theToUpdateViewer); |
c3282ec1 | 1036 | } |
1037 | } | |
1038 | return; | |
1039 | } | |
1040 | ||
016e5959 | 1041 | for (mySelection->Init(); mySelection->More(); mySelection->Next()) |
c3282ec1 | 1042 | { |
f838dac4 | 1043 | const Handle(SelectMgr_EntityOwner) aSelOwner = mySelection->Value(); |
1044 | if (!myFilters->IsOk (aSelOwner)) | |
02974a19 | 1045 | { |
c3282ec1 | 1046 | continue; |
02974a19 | 1047 | } |
c3282ec1 | 1048 | |
f838dac4 | 1049 | Handle(AIS_InteractiveObject) aSelectable = Handle(AIS_InteractiveObject)::DownCast (aSelOwner->Selectable()); |
c3282ec1 | 1050 | Unhilight (aSelectable, Standard_False); |
f838dac4 | 1051 | aSelOwner->SetSelected (Standard_False); |
1052 | if (aSelOwner == aSelectable->GlobalSelOwner()) | |
e1b01c73 | 1053 | { |
1054 | myObjects.ChangeFind (aSelectable)->SetHilightStatus (Standard_False); | |
1055 | } | |
c3282ec1 | 1056 | } |
1057 | ||
1058 | // added to avoid untimely viewer update... | |
016e5959 | 1059 | mySelection->ClearAndSelect (anOwner); |
0d5880e1 | 1060 | |
f838dac4 | 1061 | Handle(Prs3d_Drawer) aCustomStyle; |
8e5fb5ea | 1062 | if (HighlightStyle (theObject, aCustomStyle)) |
c3282ec1 | 1063 | { |
8e5fb5ea | 1064 | if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle) |
c3282ec1 | 1065 | { |
8e5fb5ea | 1066 | HilightWithColor (theObject, anObjSelStyle, Standard_False); |
c3282ec1 | 1067 | } |
7fd59977 | 1068 | } |
c3282ec1 | 1069 | else |
1070 | { | |
8e5fb5ea | 1071 | HilightWithColor (theObject, anObjSelStyle, Standard_False); |
c3282ec1 | 1072 | } |
f838dac4 | 1073 | anOwner->SetSelected (Standard_True); |
c3282ec1 | 1074 | |
1075 | if (theToUpdateViewer) | |
1076 | UpdateCurrentViewer(); | |
7fd59977 | 1077 | } |
1078 | ||
1079 | //======================================================================= | |
c3282ec1 | 1080 | //function : SetSelected |
1081 | //purpose : Sets the whole object as selected and highlights it with selection color | |
7fd59977 | 1082 | //======================================================================= |
c3282ec1 | 1083 | void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner, |
1084 | const Standard_Boolean theToUpdateViewer) | |
7fd59977 | 1085 | { |
b4006117 | 1086 | if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner)) |
c3282ec1 | 1087 | return; |
1088 | ||
f838dac4 | 1089 | const Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()); |
1090 | const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObject, theOwner); | |
731c9b5b | 1091 | if (NbSelected() == 1 && theOwner->IsSelected() && !theOwner->IsForcedHilight()) |
c3282ec1 | 1092 | { |
f838dac4 | 1093 | Handle(Prs3d_Drawer) aCustomStyle; |
8e5fb5ea | 1094 | if (HighlightStyle (theOwner, aCustomStyle)) |
c3282ec1 | 1095 | { |
8e5fb5ea | 1096 | if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle) |
c3282ec1 | 1097 | { |
1098 | const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0; | |
8e5fb5ea | 1099 | theOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode); |
c3282ec1 | 1100 | } |
1101 | } | |
1102 | return; | |
1103 | } | |
1104 | ||
1105 | if (!myObjects.IsBound (anObject)) | |
1106 | Display (anObject, Standard_False); | |
1107 | ||
b4006117 | 1108 | unhighlightSelected(); |
c3282ec1 | 1109 | |
016e5959 | 1110 | mySelection->ClearAndSelect (theOwner); |
f838dac4 | 1111 | Handle(Prs3d_Drawer) aCustomStyle; |
8e5fb5ea | 1112 | if (!HighlightStyle (theOwner, aCustomStyle) || |
1113 | (!aCustomStyle.IsNull() && aCustomStyle != anObjSelStyle)) | |
c3282ec1 | 1114 | { |
f838dac4 | 1115 | theOwner->SetSelected (Standard_True); |
8e5fb5ea | 1116 | highlightSelected (theOwner); |
c3282ec1 | 1117 | } |
1118 | ||
f838dac4 | 1119 | theOwner->SetSelected (Standard_True); |
e1b01c73 | 1120 | if (theOwner == anObject->GlobalSelOwner()) |
1121 | { | |
1122 | Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (anObject); | |
1123 | aState->SetHilightStatus (Standard_True); | |
8e5fb5ea | 1124 | aState->SetHilightStyle (anObjSelStyle); |
e1b01c73 | 1125 | } |
1126 | ||
c3282ec1 | 1127 | if (theToUpdateViewer) |
1128 | UpdateCurrentViewer(); | |
7fd59977 | 1129 | } |
1130 | ||
1131 | //======================================================================= | |
1132 | //function : AddOrRemoveSelected | |
c3282ec1 | 1133 | //purpose : Adds or removes current object from AIS selection and highlights/unhighlights it. |
1134 | // Since this method makes sence only for neutral point selection of a whole object, | |
1135 | // if 0 selection of the object is empty this method simply does nothing. | |
7fd59977 | 1136 | //======================================================================= |
c3282ec1 | 1137 | void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& theObject, |
1138 | const Standard_Boolean theToUpdateViewer) | |
7fd59977 | 1139 | { |
95081657 | 1140 | if (theObject.IsNull()) |
1141 | return; | |
c3282ec1 | 1142 | |
1143 | if (HasOpenedContext()) | |
1144 | return myLocalContexts (myCurLocalIndex)->AddOrRemoveSelected (theObject, theToUpdateViewer); | |
1145 | ||
95081657 | 1146 | const Standard_Integer aGlobalSelMode = theObject->GlobalSelectionMode(); |
1147 | if (!myObjects.IsBound (theObject) || !theObject->HasSelection (aGlobalSelMode)) | |
c3282ec1 | 1148 | return; |
1149 | ||
2ec85268 | 1150 | setContextToObject (theObject); |
7411850a | 1151 | const Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner(); |
c3282ec1 | 1152 | |
1153 | if (anOwner.IsNull() || !anOwner->HasSelectable()) | |
1154 | return; | |
1155 | ||
1156 | AddOrRemoveSelected (anOwner, theToUpdateViewer); | |
7fd59977 | 1157 | } |
1158 | //======================================================================= | |
1159 | //function : AddOrRemoveSelected | |
1160 | //purpose : | |
1161 | //======================================================================= | |
1162 | ||
c3282ec1 | 1163 | void AIS_InteractiveContext::AddOrRemoveSelected (const TopoDS_Shape& aShap, |
7fd59977 | 1164 | const Standard_Boolean updateviewer) |
1165 | { | |
1166 | if(!HasOpenedContext()) { | |
0797d9d3 | 1167 | #ifdef OCCT_DEBUG |
7fd59977 | 1168 | cout<<" Attempt to remove a selected shape with no opened local context"<<endl; |
1169 | #endif | |
1170 | return; | |
1171 | } | |
1172 | ||
1173 | myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer); | |
1174 | if(updateviewer) UpdateCurrentViewer(); | |
1175 | ||
1176 | } | |
c3282ec1 | 1177 | |
7fd59977 | 1178 | //======================================================================= |
1179 | //function : AddOrRemoveSelected | |
c3282ec1 | 1180 | //purpose : Allows to highlight or unhighlight the owner given depending on |
1181 | // its selection status | |
7fd59977 | 1182 | //======================================================================= |
c3282ec1 | 1183 | void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner, |
1184 | const Standard_Boolean theToUpdateViewer) | |
1185 | { | |
1186 | if (HasOpenedContext()) | |
1187 | return myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected (theOwner, theToUpdateViewer); | |
7fd59977 | 1188 | |
c3282ec1 | 1189 | if (theOwner.IsNull() || !theOwner->HasSelectable()) |
7fd59977 | 1190 | return; |
c3282ec1 | 1191 | |
4d901cde | 1192 | if (!myFilters->IsOk(theOwner) && !theOwner->IsSelected()) |
1193 | return; | |
1194 | ||
016e5959 | 1195 | AIS_SelectStatus aSelStat = mySelection->Select (theOwner); |
f838dac4 | 1196 | theOwner->SetSelected (aSelStat == AIS_SS_Added); |
c3282ec1 | 1197 | const Handle(AIS_InteractiveObject) anObj = |
1198 | Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()); | |
1199 | const Standard_Boolean isGlobal = anObj->GlobalSelOwner() == theOwner; | |
e1b01c73 | 1200 | Handle(AIS_GlobalStatus)& aStatus = myObjects.ChangeFind (anObj); |
f838dac4 | 1201 | if (theOwner->IsSelected()) |
c3282ec1 | 1202 | { |
8e5fb5ea | 1203 | highlightSelected (theOwner); |
c3282ec1 | 1204 | if (isGlobal) |
1205 | { | |
1206 | aStatus->SetHilightStatus (Standard_True); | |
f838dac4 | 1207 | aStatus->SetHilightStyle (getSelStyle (anObj, theOwner)); |
c3282ec1 | 1208 | } |
1209 | } | |
1210 | else | |
1211 | { | |
1212 | if (theOwner->IsAutoHilight()) | |
f838dac4 | 1213 | { |
1214 | theOwner->Unhilight (myMainPM); | |
1215 | } | |
c3282ec1 | 1216 | else |
f838dac4 | 1217 | { |
c3282ec1 | 1218 | anObj->ClearSelected(); |
f838dac4 | 1219 | } |
c3282ec1 | 1220 | aStatus->SetHilightStatus (Standard_False); |
f838dac4 | 1221 | aStatus->SetHilightStyle (Handle(Prs3d_Drawer)()); |
7fd59977 | 1222 | } |
7fd59977 | 1223 | |
c3282ec1 | 1224 | if (theToUpdateViewer) |
1225 | UpdateCurrentViewer(); | |
1226 | } | |
7fd59977 | 1227 | |
1228 | ||
1229 | //======================================================================= | |
1230 | //function : IsSelected | |
c3282ec1 | 1231 | //purpose : |
7fd59977 | 1232 | //======================================================================= |
c3282ec1 | 1233 | Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const |
7fd59977 | 1234 | { |
c3282ec1 | 1235 | if(HasOpenedContext()) |
1236 | return myLocalContexts(myCurLocalIndex)->IsSelected (theObj); | |
1237 | ||
1238 | if (theObj.IsNull() || !myObjects.IsBound (theObj)) | |
1239 | return Standard_False; | |
1240 | ||
1241 | const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode(); | |
1242 | const TColStd_ListOfInteger& anActivatedModes = myObjects (theObj)->SelectionModes(); | |
1243 | Standard_Boolean isGlobalModeActivated = Standard_False; | |
1244 | for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next()) | |
1245 | { | |
1246 | if (aModeIter.Value() == aGlobalSelMode) | |
1247 | { | |
1248 | isGlobalModeActivated = Standard_True; | |
1249 | break; | |
1250 | } | |
1251 | } | |
95081657 | 1252 | if (!theObj->HasSelection (aGlobalSelMode) || !isGlobalModeActivated || theObj->GlobalSelOwner().IsNull()) |
c3282ec1 | 1253 | return Standard_False; |
1254 | ||
f838dac4 | 1255 | return theObj->GlobalSelOwner()->IsSelected(); |
7fd59977 | 1256 | } |
1257 | ||
c3282ec1 | 1258 | //======================================================================= |
1259 | //function : IsSelected | |
1260 | //purpose : Returns true is the owner given is selected | |
1261 | //======================================================================= | |
1262 | Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(SelectMgr_EntityOwner)& theOwner) const | |
1263 | { | |
1264 | if (HasOpenedContext()) | |
1265 | return myLocalContexts(myCurLocalIndex)->IsSelected (theOwner); | |
1266 | ||
1267 | if (theOwner.IsNull()) | |
1268 | return Standard_False; | |
1269 | ||
1270 | return theOwner->IsSelected(); | |
1271 | } | |
7fd59977 | 1272 | |
1273 | //======================================================================= | |
1274 | //function : InitSelected | |
c3282ec1 | 1275 | //purpose : |
7fd59977 | 1276 | //======================================================================= |
7fd59977 | 1277 | void AIS_InteractiveContext::InitSelected() |
1278 | { | |
c3282ec1 | 1279 | if (HasOpenedContext()) |
1280 | { | |
1281 | myLocalContexts (myCurLocalIndex)->InitSelected(); | |
1282 | return; | |
1283 | } | |
1284 | ||
016e5959 | 1285 | mySelection->Init(); |
7fd59977 | 1286 | } |
1287 | ||
1288 | //======================================================================= | |
1289 | //function : MoreSelected | |
c3282ec1 | 1290 | //purpose : |
7fd59977 | 1291 | //======================================================================= |
c3282ec1 | 1292 | Standard_Boolean AIS_InteractiveContext::MoreSelected() const |
7fd59977 | 1293 | { |
c3282ec1 | 1294 | if (HasOpenedContext()) |
1295 | return myLocalContexts (myCurLocalIndex)->MoreSelected(); | |
1296 | ||
016e5959 | 1297 | return mySelection->More(); |
7fd59977 | 1298 | } |
1299 | ||
1300 | //======================================================================= | |
1301 | //function : NextSelected | |
c3282ec1 | 1302 | //purpose : |
7fd59977 | 1303 | //======================================================================= |
7fd59977 | 1304 | void AIS_InteractiveContext::NextSelected() |
1305 | { | |
c3282ec1 | 1306 | if(HasOpenedContext()) |
1307 | { | |
1308 | return myLocalContexts (myCurLocalIndex)->NextSelected(); | |
c3282ec1 | 1309 | } |
1310 | ||
016e5959 | 1311 | mySelection->Next(); |
7fd59977 | 1312 | } |
1313 | ||
1314 | //======================================================================= | |
1315 | //function : HasSelectedShape | |
c3282ec1 | 1316 | //purpose : |
7fd59977 | 1317 | //======================================================================= |
c3282ec1 | 1318 | Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const |
7fd59977 | 1319 | { |
c3282ec1 | 1320 | if(HasOpenedContext()) |
1321 | { | |
1322 | return myLocalContexts(myCurLocalIndex)->HasSelectedShape(); | |
7fd59977 | 1323 | } |
4aaadad7 SS |
1324 | if (!mySelection->More()) |
1325 | return Standard_False; | |
1326 | ||
1327 | const Handle(StdSelect_BRepOwner) anOwner = | |
1328 | Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value()); | |
c3282ec1 | 1329 | |
4aaadad7 | 1330 | return !anOwner.IsNull() && anOwner->HasShape(); |
7fd59977 | 1331 | } |
1332 | ||
1333 | //======================================================================= | |
1334 | //function : SelectedShape | |
c3282ec1 | 1335 | //purpose : |
7fd59977 | 1336 | //======================================================================= |
c3282ec1 | 1337 | TopoDS_Shape AIS_InteractiveContext::SelectedShape() const |
7fd59977 | 1338 | { |
c3282ec1 | 1339 | if (HasOpenedContext()) |
0717ddc1 | 1340 | { |
1341 | return myLocalContexts (myCurLocalIndex)->SelectedShape(); | |
1342 | } | |
7fd59977 | 1343 | |
02974a19 | 1344 | if (!mySelection->More()) |
c3282ec1 | 1345 | return TopoDS_Shape(); |
7fd59977 | 1346 | |
c3282ec1 | 1347 | const Handle(StdSelect_BRepOwner) anOwner = |
016e5959 | 1348 | Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value()); |
3475df12 | 1349 | if (anOwner.IsNull() || !anOwner->HasSelectable()) |
c3282ec1 | 1350 | return TopoDS_Shape(); |
1351 | ||
1352 | return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location()); | |
7fd59977 | 1353 | } |
1354 | ||
c3282ec1 | 1355 | //======================================================================= |
1356 | //function : SelectedInteractive | |
1357 | //purpose : | |
1358 | //======================================================================= | |
7fd59977 | 1359 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const |
1360 | { | |
c3282ec1 | 1361 | if (HasOpenedContext()) |
1362 | { | |
1363 | return myLocalContexts(myCurLocalIndex)->SelectedInteractive(); | |
1364 | } | |
1365 | ||
02974a19 | 1366 | return !mySelection->More() |
1367 | ? Handle(AIS_InteractiveObject)() | |
1368 | : Handle(AIS_InteractiveObject)::DownCast (mySelection->Value()->Selectable()); | |
7fd59977 | 1369 | } |
1370 | //======================================================================= | |
c3282ec1 | 1371 | //function : SelectedOwner |
1372 | //purpose : | |
7fd59977 | 1373 | //======================================================================= |
c3282ec1 | 1374 | Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const |
7fd59977 | 1375 | { |
c3282ec1 | 1376 | if(HasOpenedContext()) |
1377 | { | |
1378 | return myLocalContexts(myCurLocalIndex)->SelectedOwner(); | |
7fd59977 | 1379 | } |
c3282ec1 | 1380 | |
02974a19 | 1381 | return !mySelection->More() |
1382 | ? Handle(SelectMgr_EntityOwner)() | |
1383 | : mySelection->Value(); | |
7fd59977 | 1384 | } |
1385 | ||
1386 | //======================================================================= | |
1387 | //function : EntityOwners | |
1388 | //purpose : | |
1389 | //======================================================================= | |
b586500b | 1390 | void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners, |
7fd59977 | 1391 | const Handle(AIS_InteractiveObject)& theIObj, |
1392 | const Standard_Integer theMode) const | |
1393 | { | |
1394 | if ( theIObj.IsNull() ) | |
1395 | return; | |
1396 | ||
1397 | TColStd_ListOfInteger aModes; | |
1398 | if ( theMode == -1 ) | |
1399 | ActivatedModes( theIObj, aModes ); | |
1400 | else | |
1401 | aModes.Append( theMode ); | |
1402 | ||
b586500b | 1403 | if (theOwners.IsNull()) |
1404 | theOwners = new SelectMgr_IndexedMapOfOwner(); | |
1405 | ||
7fd59977 | 1406 | TColStd_ListIteratorOfListOfInteger anItr( aModes ); |
1407 | for (; anItr.More(); anItr.Next() ) | |
1408 | { | |
1409 | int aMode = anItr.Value(); | |
1410 | if ( !theIObj->HasSelection( aMode ) ) | |
1411 | continue; | |
1412 | ||
f751596e | 1413 | Handle(SelectMgr_Selection) aSel = theIObj->Selection(aMode); |
7fd59977 | 1414 | |
1415 | for ( aSel->Init(); aSel->More(); aSel->Next() ) | |
1416 | { | |
f751596e | 1417 | Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive()->BaseSensitive(); |
7fd59977 | 1418 | if ( aEntity.IsNull() ) |
1419 | continue; | |
1420 | ||
1421 | Handle(SelectMgr_EntityOwner) aOwner = | |
1422 | Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId()); | |
1423 | if ( !aOwner.IsNull() ) | |
b586500b | 1424 | theOwners->Add( aOwner ); |
7fd59977 | 1425 | } |
1426 | } | |
1427 | } | |
1428 | ||
c3282ec1 | 1429 | //======================================================================= |
1430 | //function : NbSelected | |
1431 | //purpose : | |
1432 | //======================================================================= | |
1433 | Standard_Integer AIS_InteractiveContext::NbSelected() | |
7fd59977 | 1434 | { |
c3282ec1 | 1435 | Standard_Integer aNbSelected = 0; |
1436 | for (InitSelected(); MoreSelected(); NextSelected()) | |
1437 | { | |
1438 | aNbSelected++; | |
1439 | } | |
1440 | ||
1441 | return aNbSelected; | |
7fd59977 | 1442 | } |
1443 | ||
1444 | //======================================================================= | |
1445 | //function : HasApplicative | |
c3282ec1 | 1446 | //purpose : |
7fd59977 | 1447 | //======================================================================= |
7fd59977 | 1448 | Standard_Boolean AIS_InteractiveContext::HasApplicative() const |
1449 | { | |
c3282ec1 | 1450 | return SelectedInteractive()->HasOwner(); |
7fd59977 | 1451 | } |
1452 | ||
1453 | //======================================================================= | |
1454 | //function : Applicative | |
c3282ec1 | 1455 | //purpose : |
7fd59977 | 1456 | //======================================================================= |
7fd59977 | 1457 | Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const |
1458 | { | |
c3282ec1 | 1459 | return SelectedInteractive()->GetOwner(); |
7fd59977 | 1460 | } |
1461 | ||
7fd59977 | 1462 | //================================================== |
c3282ec1 | 1463 | // Function: HasDetected |
7fd59977 | 1464 | // Purpose : |
1465 | //================================================== | |
c3282ec1 | 1466 | Standard_Boolean AIS_InteractiveContext::HasDetected() const |
7fd59977 | 1467 | { |
1468 | if(HasOpenedContext()) | |
1469 | return myLocalContexts(myCurLocalIndex)->HasDetected(); | |
c3282ec1 | 1470 | |
1471 | return !myLastPicked.IsNull(); | |
7fd59977 | 1472 | } |
1473 | ||
1474 | //======================================================================= | |
1475 | //function : HasDetectedShape | |
1476 | //purpose : | |
1477 | //======================================================================= | |
1478 | ||
1479 | Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const | |
1480 | { | |
1481 | if(HasOpenedContext()) | |
1482 | return myLocalContexts(myCurLocalIndex)->HasDetectedShape(); | |
1483 | return Standard_False; | |
1484 | } | |
1485 | ||
1486 | //======================================================================= | |
1487 | //function : DetectedShape | |
1488 | //purpose : | |
1489 | //======================================================================= | |
1490 | ||
1491 | const TopoDS_Shape& | |
1492 | AIS_InteractiveContext::DetectedShape() const | |
1493 | { | |
1494 | return myLocalContexts(myCurLocalIndex)->DetectedShape(); | |
1495 | } | |
1496 | ||
1497 | //======================================================================= | |
1498 | //function : DetectedInteractive | |
c3282ec1 | 1499 | //purpose : |
7fd59977 | 1500 | //======================================================================= |
c3282ec1 | 1501 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedInteractive() const |
7fd59977 | 1502 | { |
c3282ec1 | 1503 | if (HasOpenedContext()) |
7fd59977 | 1504 | return myLocalContexts(myCurLocalIndex)->DetectedInteractive(); |
c3282ec1 | 1505 | |
1506 | return Handle(AIS_InteractiveObject)::DownCast (myLastPicked->Selectable()); | |
7fd59977 | 1507 | } |
1508 | ||
f0cddd16 | 1509 | //======================================================================= |
1510 | //function : HasNextDetected | |
1511 | //purpose : | |
1512 | //======================================================================= | |
7fd59977 | 1513 | Standard_Boolean AIS_InteractiveContext::HasNextDetected() const |
1514 | { | |
f0cddd16 | 1515 | if (HasOpenedContext()) |
1516 | { | |
7fd59977 | 1517 | return myLocalContexts(myCurLocalIndex)->HasNextDetected(); |
f0cddd16 | 1518 | } |
1519 | ||
1520 | return !myDetectedSeq.IsEmpty() && myCurHighlighted <= myDetectedSeq.Upper(); | |
7fd59977 | 1521 | } |
1522 | ||
1523 | ||
1524 | //======================================================================= | |
1525 | //function : DetectedOwner | |
1526 | //purpose : | |
1527 | //======================================================================= | |
1528 | Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const | |
1529 | { | |
c3282ec1 | 1530 | if (HasOpenedContext()) |
7fd59977 | 1531 | return myLocalContexts(myCurLocalIndex)->DetectedOwner(); |
7fd59977 | 1532 | |
c3282ec1 | 1533 | return myLastPicked; |
1534 | } | |
7fd59977 | 1535 | |
1536 | //======================================================================= | |
1537 | //function : HilightNextDetected | |
679ecdee | 1538 | //purpose : |
7fd59977 | 1539 | //======================================================================= |
679ecdee | 1540 | Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView, |
1541 | const Standard_Boolean theToRedrawImmediate) | |
7fd59977 | 1542 | { |
f0cddd16 | 1543 | if (HasOpenedContext()) |
1544 | { | |
1545 | return myLocalContexts (myCurLocalIndex)->HilightNextDetected (theView, theToRedrawImmediate); | |
1546 | } | |
1547 | ||
1548 | myMainPM->ClearImmediateDraw(); | |
1549 | if (myDetectedSeq.IsEmpty()) | |
1550 | { | |
1551 | return 0; | |
1552 | } | |
1553 | ||
1554 | if (++myCurHighlighted > myDetectedSeq.Upper()) | |
1555 | { | |
1556 | myCurHighlighted = myDetectedSeq.Lower(); | |
1557 | } | |
1558 | const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted)); | |
1559 | if (anOwner.IsNull()) | |
1560 | { | |
1561 | return 0; | |
1562 | } | |
1563 | ||
1564 | highlightWithColor (anOwner, theView->Viewer()); | |
1565 | myLastPicked = anOwner; | |
1566 | myLastinMain = myLastPicked; | |
1567 | ||
1568 | if (theToRedrawImmediate) | |
1569 | { | |
1570 | myMainPM->RedrawImmediate (theView->Viewer()); | |
1571 | myMainVwr->RedrawImmediate(); | |
1572 | } | |
1573 | ||
1574 | return myCurHighlighted; | |
7fd59977 | 1575 | } |
1576 | ||
1577 | //======================================================================= | |
f0cddd16 | 1578 | //function : HilightPreviousDetected |
679ecdee | 1579 | //purpose : |
7fd59977 | 1580 | //======================================================================= |
679ecdee | 1581 | Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView, |
1582 | const Standard_Boolean theToRedrawImmediate) | |
7fd59977 | 1583 | { |
f0cddd16 | 1584 | if (HasOpenedContext()) |
1585 | { | |
1586 | return myLocalContexts (myCurLocalIndex)->HilightPreviousDetected (theView, theToRedrawImmediate); | |
1587 | } | |
1588 | ||
1589 | myMainPM->ClearImmediateDraw(); | |
1590 | if (myDetectedSeq.IsEmpty()) | |
1591 | { | |
1592 | return 0; | |
1593 | } | |
1594 | ||
1595 | if (--myCurHighlighted < myDetectedSeq.Lower()) | |
1596 | { | |
1597 | myCurHighlighted = myDetectedSeq.Upper(); | |
1598 | } | |
1599 | const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted)); | |
1600 | if (anOwner.IsNull()) | |
1601 | { | |
1602 | return 0; | |
1603 | } | |
1604 | ||
1605 | highlightWithColor (anOwner, theView->Viewer()); | |
1606 | myLastPicked = anOwner; | |
1607 | myLastinMain = myLastPicked; | |
1608 | ||
1609 | if (theToRedrawImmediate) | |
1610 | { | |
1611 | myMainPM->RedrawImmediate (theView->Viewer()); | |
1612 | myMainVwr->RedrawImmediate(); | |
1613 | } | |
1614 | ||
1615 | return myCurHighlighted; | |
7fd59977 | 1616 | } |
1617 | ||
7fd59977 | 1618 | //======================================================================= |
1619 | //function : InitDetected | |
1620 | //purpose : | |
1621 | //======================================================================= | |
1622 | void AIS_InteractiveContext::InitDetected() | |
1623 | { | |
57ad5cbd | 1624 | if (HasOpenedContext()) |
7fd59977 | 1625 | { |
f0cddd16 | 1626 | myLocalContexts (myCurLocalIndex)->InitDetected(); |
7fd59977 | 1627 | return; |
1628 | } | |
1629 | ||
f0cddd16 | 1630 | if (!myDetectedSeq.IsEmpty()) |
57ad5cbd | 1631 | { |
f0cddd16 | 1632 | myCurDetected = myDetectedSeq.Lower(); |
57ad5cbd | 1633 | } |
7fd59977 | 1634 | } |
1635 | ||
1636 | //======================================================================= | |
1637 | //function : MoreDetected | |
1638 | //purpose : | |
1639 | //======================================================================= | |
1640 | Standard_Boolean AIS_InteractiveContext::MoreDetected() const | |
1641 | { | |
57ad5cbd | 1642 | if (HasOpenedContext()) |
1643 | { | |
f0cddd16 | 1644 | return myLocalContexts (myCurLocalIndex)->MoreDetected(); |
57ad5cbd | 1645 | } |
7fd59977 | 1646 | |
f0cddd16 | 1647 | return myCurDetected >= myDetectedSeq.Lower() && myCurDetected <= myDetectedSeq.Upper(); |
7fd59977 | 1648 | } |
1649 | ||
1650 | //======================================================================= | |
1651 | //function : NextDetected | |
1652 | //purpose : | |
1653 | //======================================================================= | |
1654 | void AIS_InteractiveContext::NextDetected() | |
1655 | { | |
f0cddd16 | 1656 | if (HasOpenedContext()) |
7fd59977 | 1657 | { |
f0cddd16 | 1658 | myLocalContexts (myCurLocalIndex)->NextDetected(); |
7fd59977 | 1659 | return; |
1660 | } | |
1661 | ||
f0cddd16 | 1662 | myCurDetected++; |
7fd59977 | 1663 | } |
1664 | ||
1665 | //======================================================================= | |
1666 | //function : DetectedCurrentShape | |
1667 | //purpose : | |
1668 | //======================================================================= | |
7fd59977 | 1669 | const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const |
1670 | { | |
57ad5cbd | 1671 | if (HasOpenedContext()) |
1672 | { | |
7fd59977 | 1673 | return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape(); |
57ad5cbd | 1674 | } |
7fd59977 | 1675 | |
404c8936 | 1676 | Standard_DISABLE_DEPRECATION_WARNINGS |
57ad5cbd | 1677 | Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject()); |
404c8936 | 1678 | Standard_ENABLE_DEPRECATION_WARNINGS |
57ad5cbd | 1679 | |
1680 | if (aCurrentShape.IsNull()) | |
1681 | { | |
016e5959 | 1682 | return AIS_myDummyShape; |
57ad5cbd | 1683 | } |
1684 | ||
1685 | return aCurrentShape->Shape(); | |
7fd59977 | 1686 | } |
1687 | ||
1688 | //======================================================================= | |
1689 | //function : DetectedCurrentObject | |
1690 | //purpose : | |
1691 | //======================================================================= | |
57ad5cbd | 1692 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const |
1693 | { | |
1694 | if (HasOpenedContext()) | |
1695 | { | |
7fd59977 | 1696 | return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject(); |
57ad5cbd | 1697 | } |
7fd59977 | 1698 | |
f0cddd16 | 1699 | return MoreDetected() |
1700 | ? Handle(AIS_InteractiveObject)::DownCast (myMainSel->Picked (myDetectedSeq (myCurDetected))->Selectable()) | |
1701 | : NULL; | |
7fd59977 | 1702 | } |
c3282ec1 | 1703 | |
1704 | //======================================================================= | |
1705 | //function : FirstSelectedObject | |
1706 | //purpose : | |
1707 | //======================================================================= | |
1708 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject() | |
1709 | { | |
1710 | Handle(AIS_InteractiveObject) anObject; | |
1711 | ||
1712 | if (HasOpenedContext()) | |
1713 | return anObject; | |
1714 | ||
1715 | InitSelected(); | |
1716 | if (MoreSelected()) | |
1717 | { | |
1718 | return SelectedInteractive(); | |
1719 | } | |
1720 | return anObject; | |
1721 | } | |
1722 | ||
1723 | //======================================================================= | |
1724 | //function : RedrawImmediate | |
1725 | //purpose : Redisplays immediate strucures of the viewer given according to their visibility | |
1726 | //======================================================================= | |
1727 | void AIS_InteractiveContext::RedrawImmediate (const Handle(V3d_Viewer)& theViewer) | |
1728 | { | |
1729 | myMainPM->RedrawImmediate (theViewer); | |
1730 | } |