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