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