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