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