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