0026905: Visualization - cosmetic fixes in selection methods of AIS_InteractiveContext
[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 {
c3282ec1 392 const Handle(SelectMgr_EntityOwner) anOwner =
393 Handle(SelectMgr_EntityOwner)::DownCast (aSelector->Picked());
394 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
395 continue;
c398b00e 396
c3282ec1 397 AIS_Selection::Select (anOwner);
398 anOwner->State (1);
c398b00e 399 }
400
c3282ec1 401 HilightSelected (toUpdateViewer);
c398b00e 402
c3282ec1 403 Standard_Integer aSelNum = NbSelected();
c398b00e 404
405 return (aSelNum == 0) ? AIS_SOP_NothingSelected
406 : (aSelNum == 1) ? AIS_SOP_OneSelected
407 : AIS_SOP_SeveralSelected;
7fd59977 408
409}
410
411//=======================================================================
412//function : Select
413//purpose :
414//=======================================================================
c398b00e 415AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer)
7fd59977 416{
c398b00e 417 if (HasOpenedContext())
418 {
7fd59977 419 if(myWasLastMain)
c398b00e 420 {
421 return myLocalContexts(myCurLocalIndex)->Select (toUpdateViewer);
422 }
7fd59977 423 else
c398b00e 424 {
c3282ec1 425 myLocalContexts(myCurLocalIndex)->SetSelected (Handle(AIS_InteractiveObject)::DownCast (myLastPicked->Selectable()), toUpdateViewer);
c398b00e 426 return AIS_SOP_OneSelected;
427 }
428 }
429
c3282ec1 430 myMainPM->ClearImmediateDraw();
c398b00e 431 if (myWasLastMain && !myLastinMain.IsNull())
432 {
c3282ec1 433 if(!myLastinMain->IsSelected())
c398b00e 434 {
c3282ec1 435 SetSelected (myLastinMain, Standard_False);
c398b00e 436 if(toUpdateViewer)
7fd59977 437 {
c398b00e 438 UpdateCurrentViewer();
7fd59977 439 }
c398b00e 440 }
7fd59977 441 }
c398b00e 442 else
443 {
b4006117 444 unhighlightSelected (Standard_True);
c398b00e 445
7fd59977 446 AIS_Selection::Select();
c398b00e 447 if (toUpdateViewer && myWasLastMain)
448 {
eb4320f2 449 UpdateCurrentViewer();
7fd59977 450 }
451 }
c398b00e 452
c3282ec1 453 Standard_Integer aSelNum = NbSelected();
c398b00e 454
455 return (aSelNum == 0) ? AIS_SOP_NothingSelected
456 : (aSelNum == 1) ? AIS_SOP_OneSelected
457 : AIS_SOP_SeveralSelected;
7fd59977 458}
459
460//=======================================================================
461//function : ShiftSelect
462//purpose :
463//=======================================================================
c398b00e 464AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
7fd59977 465{
c398b00e 466 if (HasOpenedContext())
467 {
7fd59977 468 if(myWasLastMain)
c398b00e 469 {
470 return myLocalContexts (myCurLocalIndex)->ShiftSelect (toUpdateViewer);
471 }
472 else
473 {
474 myLocalContexts (myCurLocalIndex)->AddOrRemoveSelected (myLastPicked, toUpdateViewer);
475
476 Standard_Integer aSelNum = NbSelected();
477 return (aSelNum == 0) ? AIS_SOP_NothingSelected
478 : (aSelNum == 1) ? AIS_SOP_OneSelected
479 : AIS_SOP_SeveralSelected;
7fd59977 480 }
481 }
eb4320f2 482
c3282ec1 483 myMainPM->ClearImmediateDraw();
c398b00e 484 if (myWasLastMain && !myLastinMain.IsNull())
485 {
c3282ec1 486 AddOrRemoveSelected (myLastinMain, toUpdateViewer);
c398b00e 487 }
7fd59977 488
c3282ec1 489 Standard_Integer aSelNum = NbSelected();
c398b00e 490
c3282ec1 491 return (aSelNum == 0) ? AIS_SOP_NothingSelected
492 : (aSelNum == 1) ? AIS_SOP_OneSelected
493 : AIS_SOP_SeveralSelected;
c398b00e 494}
7fd59977 495
496//=======================================================================
497//function : ShiftSelect
498//purpose :
499//=======================================================================
c398b00e 500AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
501 const Standard_Integer theYPMin,
502 const Standard_Integer theXPMax,
503 const Standard_Integer theYPMax,
504 const Handle(V3d_View)& theView,
505 const Standard_Boolean toUpdateViewer)
7fd59977 506{
c398b00e 507 if (HasOpenedContext())
508 {
509 return myLocalContexts(myCurLocalIndex)->ShiftSelect (theXPMin, theYPMin, theXPMax, theYPMax,
510 theView, toUpdateViewer);
511 }
512
c3282ec1 513 UnhilightSelected (Standard_False);
c398b00e 514
515 Handle(StdSelect_ViewerSelector3d) aSelector;
516 if (theView->Viewer() == myMainVwr)
517 {
518 aSelector = myMainSel;
519 myWasLastMain = Standard_True;
520 }
7fd59977 521 else
c398b00e 522 {
7fd59977 523 return AIS_SOP_NothingSelected;
c398b00e 524 }
525
526 aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
527 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
528 for (aSelector->Init(); aSelector->More(); aSelector->Next())
529 {
c3282ec1 530 const Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (aSelector->Picked());
531 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
532 continue;
533
534 AIS_SelectStatus aSelStatus = AIS_Selection::Select (anOwner);
535 Standard_Integer aState = (aSelStatus == AIS_SS_Added) ? 1 : 0;
536 anOwner->State (aState);
7fd59977 537 }
c398b00e 538
c3282ec1 539 HilightSelected (toUpdateViewer);
c398b00e 540
c3282ec1 541 Standard_Integer aSelNum = NbSelected();
c398b00e 542
543 return (aSelNum == 0) ? AIS_SOP_NothingSelected
544 : (aSelNum == 1) ? AIS_SOP_OneSelected
545 : AIS_SOP_SeveralSelected;
546
7fd59977 547}
548
549//=======================================================================
550//function : ShiftSelect
551//purpose :
552//=======================================================================
c398b00e 553AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
554 const Handle(V3d_View)& theView,
555 const Standard_Boolean toUpdateViewer)
7fd59977 556{
c398b00e 557 if (HasOpenedContext())
558 {
559 return myLocalContexts(myCurLocalIndex)->ShiftSelect (thePolyline, theView, toUpdateViewer);
560 }
7fd59977 561
c3282ec1 562 UnhilightSelected (Standard_False);
c398b00e 563
564 Handle(StdSelect_ViewerSelector3d) aSelector;
565
566 if (theView->Viewer() == myMainVwr)
567 {
568 aSelector= myMainSel;
569 myWasLastMain = Standard_True;
570 }
571 else
572 {
573 return AIS_SOP_NothingSelected;
574 }
575
576 aSelector->Pick (thePolyline, theView);
577
578 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
579 for (aSelector->Init(); aSelector->More(); aSelector->Next())
580 {
c3282ec1 581 const Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (aSelector->Picked());
582 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
583 continue;
584
585 AIS_SelectStatus aSelStatus = AIS_Selection::Select (anOwner);
586 Standard_Integer aState = (aSelStatus == AIS_SS_Added) ? 1 : 0;
587 anOwner->State (aState);
c398b00e 588 }
589
c3282ec1 590 HilightSelected (toUpdateViewer);
c398b00e 591
c3282ec1 592 Standard_Integer aSelNum = NbSelected();
c398b00e 593
594 return (aSelNum == 0) ? AIS_SOP_NothingSelected
595 : (aSelNum == 1) ? AIS_SOP_OneSelected
596 : AIS_SOP_SeveralSelected;
7fd59977 597}
598
599//=======================================================================
600//function : SetCurrentObject
c3282ec1 601//purpose : OBSOLETE, please use SetSelected() instead
602//TODO : Remove in process of local context deletion
7fd59977 603//=======================================================================
c3282ec1 604void AIS_InteractiveContext::SetCurrentObject (const Handle(AIS_InteractiveObject)& theObject,
605 const Standard_Boolean theToUpdateViewer)
7fd59977 606{
c3282ec1 607 if (HasOpenedContext())
7fd59977 608 return;
7fd59977 609
c3282ec1 610 SetSelected (theObject, theToUpdateViewer);
7fd59977 611}
612
613//=======================================================================
614//function : AddOrRemoveCurrentObject
c3282ec1 615//purpose : OBSOLETE, please use AddOrRemoveSelected() instead
616//TODO : Remove in process of local context deletion
7fd59977 617//=======================================================================
c3282ec1 618void AIS_InteractiveContext::AddOrRemoveCurrentObject (const Handle(AIS_InteractiveObject)& theObj,
619 const Standard_Boolean theIsToUpdateViewer)
7fd59977 620{
c3282ec1 621 if (HasOpenedContext())
622 return;
7fd59977 623
c3282ec1 624 AddOrRemoveSelected (theObj, theIsToUpdateViewer);
7fd59977 625}
626//=======================================================================
627//function : UpdateCurrent
c3282ec1 628//purpose : OBSOLETE, please use UpdateSelected() instead
629//TODO : Remove in process of local context deletion
7fd59977 630//=======================================================================
7fd59977 631void AIS_InteractiveContext::UpdateCurrent()
632{
c3282ec1 633 UpdateSelected();
7fd59977 634}
635
636//=======================================================================
637//function : IsCurrent
c3282ec1 638//purpose : OBSOLETE, please use IsSelected() instead
639//TODO : Remove in process of local context deletion
7fd59977 640//=======================================================================
c3282ec1 641Standard_Boolean AIS_InteractiveContext::IsCurrent (const Handle(AIS_InteractiveObject)& theObject) const
7fd59977 642{
c3282ec1 643 return IsSelected (theObject);
7fd59977 644}
645
646//=======================================================================
647//function : InitCurrent
c3282ec1 648//purpose : OBSOLETE, please use InitSelected() instead
649//TODO : Remove in process of local context deletion
7fd59977 650//=======================================================================
7fd59977 651void AIS_InteractiveContext::InitCurrent()
652{
c3282ec1 653 if (HasOpenedContext())
654 return;
655
656 InitSelected();
7fd59977 657}
658
659//=======================================================================
660//function : MoreCurrent
c3282ec1 661//purpose : OBSOLETE, please use MoreSelected() instead
662//TODO : Remove in process of local context deletion
7fd59977 663//=======================================================================
7fd59977 664Standard_Boolean AIS_InteractiveContext::MoreCurrent() const
665{
c3282ec1 666 return !HasOpenedContext() && MoreSelected();
7fd59977 667}
668
669//=======================================================================
670//function : NextCurrent
c3282ec1 671//purpose : OBSOLETE, please use NextSelected() instead
672//TODO : Remove in process of local context deletion
7fd59977 673//=======================================================================
7fd59977 674void AIS_InteractiveContext::NextCurrent()
675{
c3282ec1 676 if (HasOpenedContext())
677 return;
678
679 NextSelected();
7fd59977 680}
681
682//=======================================================================
683//function : Current
c3282ec1 684//purpose : OBSOLETE, please use SelectedInteractive() instead
685//TODO : Remove in process of local context deletion
7fd59977 686//=======================================================================
7fd59977 687Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const
688{
c3282ec1 689 return HasOpenedContext() ? NULL : SelectedInteractive();
7fd59977 690}
691
692//=======================================================================
693//function : NbCurrents
c3282ec1 694//purpose : OBSOLETE, please use NbSelected() instead
695//TODO : Remove in process of local context deletion
7fd59977 696//=======================================================================
697Standard_Integer AIS_InteractiveContext::NbCurrents()
698{
c3282ec1 699 return HasOpenedContext() ? -1 : NbSelected();
7fd59977 700}
701
702//=======================================================================
703//function : HilightCurrents
c3282ec1 704//purpose : OBSOLETE, please use HilightSelected() instead
705//TODO : Remove in process of local context deletion
7fd59977 706//=======================================================================
c3282ec1 707void AIS_InteractiveContext::HilightCurrents (const Standard_Boolean theToUpdateViewer)
7fd59977 708{
c3282ec1 709 if (HasOpenedContext())
710 return;
711
712 HilightSelected (theToUpdateViewer);
7fd59977 713}
714
715//=======================================================================
716//function : UnhilightCurrents
c3282ec1 717//purpose : OBSOLETE, please use UnhilightSelected() instead
718//TODO : Remove in process of local context deletion
7fd59977 719//=======================================================================
c3282ec1 720void AIS_InteractiveContext::UnhilightCurrents (const Standard_Boolean theToUpdateViewer)
7fd59977 721{
c3282ec1 722 if (HasOpenedContext())
723 return;
724
725 UnhilightSelected (theToUpdateViewer);
7fd59977 726}
727
728//=======================================================================
729//function : ClearCurrents
c3282ec1 730//purpose : OBSOLETE, please use ClearCurrents() instead
731//TODO : Remove in process of local context deletion
7fd59977 732//=======================================================================
c3282ec1 733void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean theToUpdateViewer)
7fd59977 734{
c3282ec1 735 if (HasOpenedContext())
736 return;
737
738 ClearSelected (theToUpdateViewer);
7fd59977 739}
740
741
742//=======================================================================
743//function : HilightSelected
c3282ec1 744//purpose :
7fd59977 745//=======================================================================
c3282ec1 746void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdateViewer)
7fd59977 747{
c3282ec1 748 if (HasOpenedContext())
749 {
750 return myLocalContexts (myCurLocalIndex)->HilightPicked (theToUpdateViewer);
751 }
752
753 // In case of selection without using local context
754 myMainPM->ClearImmediateDraw();
755 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
756 Handle(AIS_Selection) aSel = AIS_Selection::Selection (myCurrentName.ToCString());
757 AIS_MapOfObjSelectedOwners anObjOwnerMap;
758 for (aSel->Init(); aSel->More(); aSel->Next())
759 {
760 const Handle(SelectMgr_EntityOwner) anOwner =
761 Handle(SelectMgr_EntityOwner)::DownCast (aSel->Value());
762 if (!anOwner.IsNull() && anOwner->HasSelectable())
763 {
764 const Handle(AIS_InteractiveObject) anObj =
765 Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
766 if (anOwner == anObj->GlobalSelOwner())
767 {
e1b01c73 768 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (anObj);
769 aState->SetHilightStatus (Standard_True);
770 aState->SetHilightColor (mySelectionColor);
c3282ec1 771 }
772 anOwner->State (1);
773 if (!anOwner->IsAutoHilight())
774 {
775 NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq;
776 if (anObjOwnerMap.Find (anObj, aSeq))
777 {
778 aSeq->Append (anOwner);
779 }
780 else
781 {
782 aSeq = new SelectMgr_SequenceOfOwner();
783 aSeq->Append (anOwner);
784 anObjOwnerMap.Bind (anObj, aSeq);
785 }
786 }
787 else
788 {
789 const Standard_Integer aHiMode = anObj->HasHilightMode() ? anObj->HilightMode() : 0;
790 anOwner->HilightWithColor (myMainPM, mySelectionColor, aHiMode);
791 }
7fd59977 792 }
793 }
c3282ec1 794
795 if (!anObjOwnerMap.IsEmpty())
796 {
797 for (AIS_MapOfObjSelectedOwners::Iterator anIter (anObjOwnerMap); anIter.More(); anIter.Next())
7fd59977 798 {
c3282ec1 799 anIter.Key()->HilightSelected (myMainPM, *anIter.Value());
7fd59977 800 }
c3282ec1 801 anObjOwnerMap.Clear();
802 }
803
804 if (theToUpdateViewer)
7fd59977 805 UpdateCurrentViewer();
806}
807
808//=======================================================================
809//function : UnhilightSelected
c3282ec1 810//purpose :
7fd59977 811//=======================================================================
c3282ec1 812void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer)
7fd59977 813{
c3282ec1 814 if (HasOpenedContext())
815 {
816 return myLocalContexts (myCurLocalIndex)->UnhilightPicked (theToUpdateViewer);
7fd59977 817 }
c3282ec1 818
819 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
820 Handle(AIS_Selection) aSel = AIS_Selection::Selection (myCurrentName.ToCString());
821 for (aSel->Init(); aSel->More(); aSel->Next())
822 {
823 const Handle(SelectMgr_EntityOwner) anOwner =
824 Handle(SelectMgr_EntityOwner)::DownCast (aSel->Value());
825 if (!anOwner.IsNull() && anOwner->HasSelectable())
7fd59977 826 {
c3282ec1 827 const Handle(AIS_InteractiveObject) anObj =
828 Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
829 if (anOwner == anObj->GlobalSelOwner())
830 {
e1b01c73 831 myObjects.ChangeFind (anObj)->SetHilightStatus (Standard_False);
c3282ec1 832 }
833 anOwner->State (0);
834 const Standard_Integer aHiMode = anObj->HasHilightMode() ? anObj->HasHilightMode() : 0;
835 anOwner->Unhilight (myMainPM, aHiMode);
7fd59977 836 }
c3282ec1 837 }
838
839 if (theToUpdateViewer)
840 UpdateCurrentViewer();
7fd59977 841}
842
843
844//=======================================================================
845//function : ClearSelected
c3282ec1 846//purpose :
7fd59977 847//=======================================================================
c3282ec1 848void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateViewer)
7fd59977 849{
c3282ec1 850 if (HasOpenedContext())
851 return myLocalContexts (myCurLocalIndex)->ClearSelected (theToUpdateViewer);
7fd59977 852
c3282ec1 853 if (NbSelected() == 0)
854 return;
7fd59977 855
b4006117 856 unhighlightSelected();
7fd59977 857
c3282ec1 858 AIS_Selection::Select();
859 myMainPM->ClearImmediateDraw();
7fd59977 860
c3282ec1 861 if (theToUpdateViewer)
862 UpdateCurrentViewer();
7fd59977 863}
864
865//=======================================================================
c3282ec1 866//function : UpdateSelected
867//purpose :
7fd59977 868//=======================================================================
c3282ec1 869void AIS_InteractiveContext::UpdateSelected (const Standard_Boolean theToUpdateViewer)
870{
871 if (HasOpenedContext())
872 {
873 return myLocalContexts(myCurLocalIndex)->UpdateSelected (theToUpdateViewer);
874 }
7fd59977 875
c3282ec1 876 HilightSelected (theToUpdateViewer);
877}
878
879//=======================================================================
880//function : SetSelected
881//purpose : Sets the whole object as selected and highlights it with selection color
882//=======================================================================
883void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& theObject,
884 const Standard_Boolean theToUpdateViewer)
7fd59977 885{
c3282ec1 886 if(HasOpenedContext())
887 {
888 return myLocalContexts (myCurLocalIndex)->SetSelected (theObject, theToUpdateViewer);
889 }
890
891 if (theObject.IsNull())
7fd59977 892 return;
c3282ec1 893 if(!myObjects.IsBound (theObject))
894 Display (theObject, Standard_False);
895 if (theObject->HasSelection (0))
896 return;
897
e1b01c73 898 if (NbSelected() == 1 && myObjects (theObject)->IsHilighted())
c3282ec1 899 {
900 Quantity_NameOfColor aHiCol;
901 Standard_Boolean hasHiCol = Standard_False;
902 if (IsHilighted (theObject, hasHiCol, aHiCol))
903 {
904 if (hasHiCol && aHiCol!= mySelectionColor)
905 {
906 HilightWithColor (theObject, mySelectionColor, theToUpdateViewer);
907 }
908 }
909 return;
910 }
911
912 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
913 Handle(AIS_Selection) aCurSel = AIS_Selection::Selection (myCurrentName.ToCString());
914 for (aCurSel->Init(); aCurSel->More(); aCurSel->Next())
915 {
916 const Handle(SelectMgr_EntityOwner) anOwner =
917 Handle(SelectMgr_EntityOwner)::DownCast (aCurSel->Value());
b4006117 918 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
c3282ec1 919 continue;
920
921 Handle(AIS_InteractiveObject) aSelectable =
922 Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
923 Unhilight (aSelectable, Standard_False);
924 anOwner->State (0);
e1b01c73 925 if (anOwner == aSelectable->GlobalSelOwner())
926 {
927 myObjects.ChangeFind (aSelectable)->SetHilightStatus (Standard_False);
928 }
c3282ec1 929 }
930
931 // added to avoid untimely viewer update...
932 const Handle(SelectMgr_Selection)& aSel = theObject->Selection (0);
933 if (aSel->IsEmpty())
934 return;
935 aSel->Init();
936 Handle(SelectMgr_EntityOwner) anOwner =
937 Handle(SelectMgr_EntityOwner)::DownCast (aSel->Sensitive()->BaseSensitive()->OwnerId());
938 AIS_Selection::ClearAndSelect (anOwner);
c3282ec1 939 anOwner->State (1);
e1b01c73 940 if (anOwner == theObject->GlobalSelOwner())
941 {
942 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (theObject);
943 aState->SetHilightStatus (Standard_True);
944 aState->SetHilightColor (mySelectionColor);
945 }
c3282ec1 946 Quantity_NameOfColor aHiCol;
947 Standard_Boolean hasHiCol = Standard_False;
948 if (IsHilighted (theObject, hasHiCol, aHiCol))
949 {
950 if (hasHiCol && aHiCol!= mySelectionColor)
951 {
952 HilightWithColor (theObject, mySelectionColor, Standard_False);
953 }
7fd59977 954 }
c3282ec1 955 else
956 {
957 HilightWithColor (theObject, mySelectionColor, Standard_False);
958 }
959
960 if (theToUpdateViewer)
961 UpdateCurrentViewer();
7fd59977 962}
963
964//=======================================================================
c3282ec1 965//function : SetSelected
966//purpose : Sets the whole object as selected and highlights it with selection color
7fd59977 967//=======================================================================
c3282ec1 968void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
969 const Standard_Boolean theToUpdateViewer)
7fd59977 970{
b4006117 971 if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner))
c3282ec1 972 return;
973
974 const Handle(AIS_InteractiveObject) anObject =
975 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
976
977 if (NbSelected() == 1 && theOwner->IsSelected())
978 {
979 Quantity_NameOfColor aCustomColor;
980 Standard_Boolean isCustomColorSet;
981 if (IsHilighted (theOwner, isCustomColorSet, aCustomColor))
982 {
983 if (isCustomColorSet && aCustomColor != mySelectionColor)
984 {
985 const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0;
986 theOwner->HilightWithColor (myMainPM, mySelectionColor, aHiMode);
987 }
988 }
989 return;
990 }
991
992 if (!myObjects.IsBound (anObject))
993 Display (anObject, Standard_False);
994
b4006117 995 unhighlightSelected();
c3282ec1 996
997 AIS_Selection::ClearAndSelect (theOwner);
998 theOwner->State (1);
999 Quantity_NameOfColor aCustomColor;
1000 Standard_Boolean isCustomColorSet;
1001 if (!IsHilighted (theOwner, isCustomColorSet, aCustomColor) || (isCustomColorSet && aCustomColor!= mySelectionColor))
1002 {
1003 highlightSelected (theOwner, mySelectionColor);
1004 }
1005
e1b01c73 1006 if (theOwner == anObject->GlobalSelOwner())
1007 {
1008 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (anObject);
1009 aState->SetHilightStatus (Standard_True);
1010 aState->SetHilightColor (mySelectionColor);
1011 }
1012
c3282ec1 1013 if (theToUpdateViewer)
1014 UpdateCurrentViewer();
7fd59977 1015}
1016
1017//=======================================================================
1018//function : AddOrRemoveSelected
c3282ec1 1019//purpose : Adds or removes current object from AIS selection and highlights/unhighlights it.
1020// Since this method makes sence only for neutral point selection of a whole object,
1021// if 0 selection of the object is empty this method simply does nothing.
7fd59977 1022//=======================================================================
c3282ec1 1023void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& theObject,
1024 const Standard_Boolean theToUpdateViewer)
7fd59977 1025{
95081657 1026 if (theObject.IsNull())
1027 return;
c3282ec1 1028
1029 if (HasOpenedContext())
1030 return myLocalContexts (myCurLocalIndex)->AddOrRemoveSelected (theObject, theToUpdateViewer);
1031
95081657 1032 const Standard_Integer aGlobalSelMode = theObject->GlobalSelectionMode();
1033 if (!myObjects.IsBound (theObject) || !theObject->HasSelection (aGlobalSelMode))
c3282ec1 1034 return;
1035
95081657 1036 if (!theObject->HasInteractiveContext())
1037 theObject->SetContext (this);
1038
1039 const Handle(SelectMgr_Selection)& aSel = theObject->Selection (aGlobalSelMode);
c3282ec1 1040
1041 if (aSel->IsEmpty())
1042 return;
1043
1044 aSel->Init();
1045 const Handle(SelectMgr_EntityOwner) anOwner =
1046 Handle(SelectMgr_EntityOwner)::DownCast (aSel->Sensitive()->BaseSensitive()->OwnerId());
1047
1048 if (anOwner.IsNull() || !anOwner->HasSelectable())
1049 return;
1050
1051 AddOrRemoveSelected (anOwner, theToUpdateViewer);
7fd59977 1052}
1053//=======================================================================
1054//function : AddOrRemoveSelected
1055//purpose :
1056//=======================================================================
1057
c3282ec1 1058void AIS_InteractiveContext::AddOrRemoveSelected (const TopoDS_Shape& aShap,
7fd59977 1059 const Standard_Boolean updateviewer)
1060{
1061 if(!HasOpenedContext()) {
0797d9d3 1062#ifdef OCCT_DEBUG
7fd59977 1063 cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
1064#endif
1065 return;
1066 }
1067
1068 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
1069 if(updateviewer) UpdateCurrentViewer();
1070
1071}
c3282ec1 1072
7fd59977 1073//=======================================================================
1074//function : AddOrRemoveSelected
c3282ec1 1075//purpose : Allows to highlight or unhighlight the owner given depending on
1076// its selection status
7fd59977 1077//=======================================================================
c3282ec1 1078void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
1079 const Standard_Boolean theToUpdateViewer)
1080{
1081 if (HasOpenedContext())
1082 return myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected (theOwner, theToUpdateViewer);
7fd59977 1083
c3282ec1 1084 if (theOwner.IsNull() || !theOwner->HasSelectable())
7fd59977 1085 return;
c3282ec1 1086
1087 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
1088 Handle(AIS_Selection) aCurSel = AIS_Selection::Selection (myCurrentName.ToCString());
1089
1090 AIS_SelectStatus aSelStat = AIS_Selection::Select (theOwner);
1091
1092 Standard_Integer aState = aSelStat == AIS_SS_Added ? 1 : 0;
1093 theOwner->State (aState);
1094 const Handle(AIS_InteractiveObject) anObj =
1095 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1096 const Standard_Boolean isGlobal = anObj->GlobalSelOwner() == theOwner;
e1b01c73 1097 Handle(AIS_GlobalStatus)& aStatus = myObjects.ChangeFind (anObj);
c3282ec1 1098 const Standard_Integer aHiMode = anObj->HasHilightMode() ? anObj->HilightMode() : 0;
1099 if (aState == 1)
1100 {
1101 highlightSelected (theOwner, mySelectionColor);
1102 if (isGlobal)
1103 {
1104 aStatus->SetHilightStatus (Standard_True);
1105 aStatus->SetHilightColor (mySelectionColor);
1106 }
1107 }
1108 else
1109 {
1110 if (theOwner->IsAutoHilight())
1111 theOwner->Unhilight (myMainPM, aHiMode);
1112 else
1113 anObj->ClearSelected();
1114 aStatus->SetHilightStatus (Standard_False);
1115 aStatus->SetHilightColor (Quantity_NOC_WHITE);
7fd59977 1116 }
7fd59977 1117
c3282ec1 1118 if (theToUpdateViewer)
1119 UpdateCurrentViewer();
1120}
7fd59977 1121
1122
1123//=======================================================================
1124//function : IsSelected
c3282ec1 1125//purpose :
7fd59977 1126//=======================================================================
c3282ec1 1127Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const
7fd59977 1128{
c3282ec1 1129 if(HasOpenedContext())
1130 return myLocalContexts(myCurLocalIndex)->IsSelected (theObj);
1131
1132 if (theObj.IsNull() || !myObjects.IsBound (theObj))
1133 return Standard_False;
1134
1135 const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode();
1136 const TColStd_ListOfInteger& anActivatedModes = myObjects (theObj)->SelectionModes();
1137 Standard_Boolean isGlobalModeActivated = Standard_False;
1138 for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
1139 {
1140 if (aModeIter.Value() == aGlobalSelMode)
1141 {
1142 isGlobalModeActivated = Standard_True;
1143 break;
1144 }
1145 }
95081657 1146 if (!theObj->HasSelection (aGlobalSelMode) || !isGlobalModeActivated || theObj->GlobalSelOwner().IsNull())
c3282ec1 1147 return Standard_False;
1148
95081657 1149 return theObj->GlobalSelOwner()->State() == 1;
7fd59977 1150}
1151
c3282ec1 1152//=======================================================================
1153//function : IsSelected
1154//purpose : Returns true is the owner given is selected
1155//=======================================================================
1156Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(SelectMgr_EntityOwner)& theOwner) const
1157{
1158 if (HasOpenedContext())
1159 return myLocalContexts(myCurLocalIndex)->IsSelected (theOwner);
1160
1161 if (theOwner.IsNull())
1162 return Standard_False;
1163
1164 return theOwner->IsSelected();
1165}
7fd59977 1166
1167//=======================================================================
1168//function : InitSelected
c3282ec1 1169//purpose :
7fd59977 1170//=======================================================================
7fd59977 1171void AIS_InteractiveContext::InitSelected()
1172{
c3282ec1 1173 if (HasOpenedContext())
1174 {
1175 myLocalContexts (myCurLocalIndex)->InitSelected();
1176 return;
1177 }
1178
1179 AIS_Selection::Selection (myCurrentName.ToCString())->Init();
7fd59977 1180}
1181
1182//=======================================================================
1183//function : MoreSelected
c3282ec1 1184//purpose :
7fd59977 1185//=======================================================================
c3282ec1 1186Standard_Boolean AIS_InteractiveContext::MoreSelected() const
7fd59977 1187{
c3282ec1 1188 if (HasOpenedContext())
1189 return myLocalContexts (myCurLocalIndex)->MoreSelected();
1190
1191 return AIS_Selection::Selection (myCurrentName.ToCString())->More();
7fd59977 1192}
1193
1194//=======================================================================
1195//function : NextSelected
c3282ec1 1196//purpose :
7fd59977 1197//=======================================================================
7fd59977 1198void AIS_InteractiveContext::NextSelected()
1199{
c3282ec1 1200 if(HasOpenedContext())
1201 {
1202 return myLocalContexts (myCurLocalIndex)->NextSelected();
1203 return;
1204 }
1205
1206 AIS_Selection::Selection (myCurrentName.ToCString())->Next();
7fd59977 1207}
1208
1209//=======================================================================
1210//function : HasSelectedShape
c3282ec1 1211//purpose :
7fd59977 1212//=======================================================================
c3282ec1 1213Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
7fd59977 1214{
c3282ec1 1215 if(HasOpenedContext())
1216 {
1217 return myLocalContexts(myCurLocalIndex)->HasSelectedShape();
7fd59977 1218 }
c3282ec1 1219
1220 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (SelectedInteractive());
1221 return !aShape.IsNull();
7fd59977 1222}
1223
1224//=======================================================================
1225//function : SelectedShape
c3282ec1 1226//purpose :
7fd59977 1227//=======================================================================
c3282ec1 1228TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
7fd59977 1229{
c3282ec1 1230 if (HasOpenedContext())
0717ddc1 1231 {
1232 return myLocalContexts (myCurLocalIndex)->SelectedShape();
1233 }
7fd59977 1234
c3282ec1 1235 if (AIS_Selection::Selection (myCurrentName.ToCString())->Extent() == 0)
1236 return TopoDS_Shape();
7fd59977 1237
c3282ec1 1238 const Handle(StdSelect_BRepOwner) anOwner =
1239 Handle(StdSelect_BRepOwner)::DownCast (AIS_Selection::Selection (myCurrentName.ToCString())->Value());
1240 if (!anOwner->HasSelectable())
1241 return TopoDS_Shape();
1242
1243 return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location());
7fd59977 1244}
1245
c3282ec1 1246//=======================================================================
1247//function : SelectedInteractive
1248//purpose :
1249//=======================================================================
7fd59977 1250Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const
1251{
c3282ec1 1252 if (HasOpenedContext())
1253 {
1254 return myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1255 }
1256
1257 const Handle(SelectMgr_EntityOwner) anOwner =
1258 Handle(SelectMgr_EntityOwner)::DownCast (AIS_Selection::Selection (myCurrentName.ToCString())->Value());
1259 if (anOwner.IsNull() || !anOwner->HasSelectable())
1260 return NULL;
1261
1262 return Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
7fd59977 1263}
1264//=======================================================================
c3282ec1 1265//function : SelectedOwner
1266//purpose :
7fd59977 1267//=======================================================================
c3282ec1 1268Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
7fd59977 1269{
c3282ec1 1270 if(HasOpenedContext())
1271 {
1272 return myLocalContexts(myCurLocalIndex)->SelectedOwner();
7fd59977 1273 }
c3282ec1 1274
1275 Handle(AIS_Selection) aCurSel = AIS_Selection::Selection (myCurrentName.ToCString());
1276
1277 return aCurSel->Extent() > 0 ?
1278 Handle(SelectMgr_EntityOwner)::DownCast (aCurSel->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 static TopoDS_Shape aDummyShape;
1513
1514 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1515
1516 if (aCurrentShape.IsNull())
1517 {
1518 return aDummyShape;
1519 }
1520
1521 return aCurrentShape->Shape();
7fd59977 1522}
1523
1524//=======================================================================
1525//function : DetectedCurrentObject
1526//purpose :
1527//=======================================================================
57ad5cbd 1528Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1529{
1530 if (HasOpenedContext())
1531 {
7fd59977 1532 return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
57ad5cbd 1533 }
7fd59977 1534
57ad5cbd 1535 return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL;
7fd59977 1536}
c3282ec1 1537
1538//=======================================================================
1539//function : FirstSelectedObject
1540//purpose :
1541//=======================================================================
1542Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject()
1543{
1544 Handle(AIS_InteractiveObject) anObject;
1545
1546 if (HasOpenedContext())
1547 return anObject;
1548
1549 InitSelected();
1550 if (MoreSelected())
1551 {
1552 return SelectedInteractive();
1553 }
1554 return anObject;
1555}
1556
1557//=======================================================================
1558//function : RedrawImmediate
1559//purpose : Redisplays immediate strucures of the viewer given according to their visibility
1560//=======================================================================
1561void AIS_InteractiveContext::RedrawImmediate (const Handle(V3d_Viewer)& theViewer)
1562{
1563 myMainPM->RedrawImmediate (theViewer);
1564}