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