0026871: [Regression in 6.9.0] Projecting a curve hangs inside Approx_FitAndDivide2d
[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{
c3282ec1 1026 if (!theObject->HasInteractiveContext())
1027 theObject->SetContext (this);
1028
1029 if (HasOpenedContext())
1030 return myLocalContexts (myCurLocalIndex)->AddOrRemoveSelected (theObject, theToUpdateViewer);
1031
1032 if (theObject.IsNull() || !myObjects.IsBound (theObject) || !theObject->HasSelection (0))
1033 return;
1034
1035 const Handle(SelectMgr_Selection)& aSel = theObject->Selection (0);
1036
1037 if (aSel->IsEmpty())
1038 return;
1039
1040 aSel->Init();
1041 const Handle(SelectMgr_EntityOwner) anOwner =
1042 Handle(SelectMgr_EntityOwner)::DownCast (aSel->Sensitive()->BaseSensitive()->OwnerId());
1043
1044 if (anOwner.IsNull() || !anOwner->HasSelectable())
1045 return;
1046
1047 AddOrRemoveSelected (anOwner, theToUpdateViewer);
7fd59977 1048}
1049//=======================================================================
1050//function : AddOrRemoveSelected
1051//purpose :
1052//=======================================================================
1053
c3282ec1 1054void AIS_InteractiveContext::AddOrRemoveSelected (const TopoDS_Shape& aShap,
7fd59977 1055 const Standard_Boolean updateviewer)
1056{
1057 if(!HasOpenedContext()) {
0797d9d3 1058#ifdef OCCT_DEBUG
7fd59977 1059 cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
1060#endif
1061 return;
1062 }
1063
1064 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
1065 if(updateviewer) UpdateCurrentViewer();
1066
1067}
c3282ec1 1068
7fd59977 1069//=======================================================================
1070//function : AddOrRemoveSelected
c3282ec1 1071//purpose : Allows to highlight or unhighlight the owner given depending on
1072// its selection status
7fd59977 1073//=======================================================================
c3282ec1 1074void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
1075 const Standard_Boolean theToUpdateViewer)
1076{
1077 if (HasOpenedContext())
1078 return myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected (theOwner, theToUpdateViewer);
7fd59977 1079
c3282ec1 1080 if (theOwner.IsNull() || !theOwner->HasSelectable())
7fd59977 1081 return;
c3282ec1 1082
1083 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
1084 Handle(AIS_Selection) aCurSel = AIS_Selection::Selection (myCurrentName.ToCString());
1085
1086 AIS_SelectStatus aSelStat = AIS_Selection::Select (theOwner);
1087
1088 Standard_Integer aState = aSelStat == AIS_SS_Added ? 1 : 0;
1089 theOwner->State (aState);
1090 const Handle(AIS_InteractiveObject) anObj =
1091 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1092 const Standard_Boolean isGlobal = anObj->GlobalSelOwner() == theOwner;
e1b01c73 1093 Handle(AIS_GlobalStatus)& aStatus = myObjects.ChangeFind (anObj);
c3282ec1 1094 const Standard_Integer aHiMode = anObj->HasHilightMode() ? anObj->HilightMode() : 0;
1095 if (aState == 1)
1096 {
1097 highlightSelected (theOwner, mySelectionColor);
1098 if (isGlobal)
1099 {
1100 aStatus->SetHilightStatus (Standard_True);
1101 aStatus->SetHilightColor (mySelectionColor);
1102 }
1103 }
1104 else
1105 {
1106 if (theOwner->IsAutoHilight())
1107 theOwner->Unhilight (myMainPM, aHiMode);
1108 else
1109 anObj->ClearSelected();
1110 aStatus->SetHilightStatus (Standard_False);
1111 aStatus->SetHilightColor (Quantity_NOC_WHITE);
7fd59977 1112 }
7fd59977 1113
c3282ec1 1114 if (theToUpdateViewer)
1115 UpdateCurrentViewer();
1116}
7fd59977 1117
1118
1119//=======================================================================
1120//function : IsSelected
c3282ec1 1121//purpose :
7fd59977 1122//=======================================================================
c3282ec1 1123Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const
7fd59977 1124{
c3282ec1 1125 if(HasOpenedContext())
1126 return myLocalContexts(myCurLocalIndex)->IsSelected (theObj);
1127
1128 if (theObj.IsNull() || !myObjects.IsBound (theObj))
1129 return Standard_False;
1130
1131 const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode();
1132 const TColStd_ListOfInteger& anActivatedModes = myObjects (theObj)->SelectionModes();
1133 Standard_Boolean isGlobalModeActivated = Standard_False;
1134 for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
1135 {
1136 if (aModeIter.Value() == aGlobalSelMode)
1137 {
1138 isGlobalModeActivated = Standard_True;
1139 break;
1140 }
1141 }
1142 if (!theObj->HasSelection (aGlobalSelMode) || !isGlobalModeActivated)
1143 return Standard_False;
1144
e1b01c73 1145 return myObjects (theObj)->IsHilighted();
7fd59977 1146}
1147
c3282ec1 1148//=======================================================================
1149//function : IsSelected
1150//purpose : Returns true is the owner given is selected
1151//=======================================================================
1152Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(SelectMgr_EntityOwner)& theOwner) const
1153{
1154 if (HasOpenedContext())
1155 return myLocalContexts(myCurLocalIndex)->IsSelected (theOwner);
1156
1157 if (theOwner.IsNull())
1158 return Standard_False;
1159
1160 return theOwner->IsSelected();
1161}
7fd59977 1162
1163//=======================================================================
1164//function : InitSelected
c3282ec1 1165//purpose :
7fd59977 1166//=======================================================================
7fd59977 1167void AIS_InteractiveContext::InitSelected()
1168{
c3282ec1 1169 if (HasOpenedContext())
1170 {
1171 myLocalContexts (myCurLocalIndex)->InitSelected();
1172 return;
1173 }
1174
1175 AIS_Selection::Selection (myCurrentName.ToCString())->Init();
7fd59977 1176}
1177
1178//=======================================================================
1179//function : MoreSelected
c3282ec1 1180//purpose :
7fd59977 1181//=======================================================================
c3282ec1 1182Standard_Boolean AIS_InteractiveContext::MoreSelected() const
7fd59977 1183{
c3282ec1 1184 if (HasOpenedContext())
1185 return myLocalContexts (myCurLocalIndex)->MoreSelected();
1186
1187 return AIS_Selection::Selection (myCurrentName.ToCString())->More();
7fd59977 1188}
1189
1190//=======================================================================
1191//function : NextSelected
c3282ec1 1192//purpose :
7fd59977 1193//=======================================================================
7fd59977 1194void AIS_InteractiveContext::NextSelected()
1195{
c3282ec1 1196 if(HasOpenedContext())
1197 {
1198 return myLocalContexts (myCurLocalIndex)->NextSelected();
1199 return;
1200 }
1201
1202 AIS_Selection::Selection (myCurrentName.ToCString())->Next();
7fd59977 1203}
1204
1205//=======================================================================
1206//function : HasSelectedShape
c3282ec1 1207//purpose :
7fd59977 1208//=======================================================================
c3282ec1 1209Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
7fd59977 1210{
c3282ec1 1211 if(HasOpenedContext())
1212 {
1213 return myLocalContexts(myCurLocalIndex)->HasSelectedShape();
7fd59977 1214 }
c3282ec1 1215
1216 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (SelectedInteractive());
1217 return !aShape.IsNull();
7fd59977 1218}
1219
1220//=======================================================================
1221//function : SelectedShape
c3282ec1 1222//purpose :
7fd59977 1223//=======================================================================
c3282ec1 1224TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
7fd59977 1225{
c3282ec1 1226 if (HasOpenedContext())
0717ddc1 1227 {
1228 return myLocalContexts (myCurLocalIndex)->SelectedShape();
1229 }
7fd59977 1230
c3282ec1 1231 if (AIS_Selection::Selection (myCurrentName.ToCString())->Extent() == 0)
1232 return TopoDS_Shape();
7fd59977 1233
c3282ec1 1234 const Handle(StdSelect_BRepOwner) anOwner =
1235 Handle(StdSelect_BRepOwner)::DownCast (AIS_Selection::Selection (myCurrentName.ToCString())->Value());
1236 if (!anOwner->HasSelectable())
1237 return TopoDS_Shape();
1238
1239 return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location());
7fd59977 1240}
1241
c3282ec1 1242//=======================================================================
1243//function : SelectedInteractive
1244//purpose :
1245//=======================================================================
7fd59977 1246Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const
1247{
c3282ec1 1248 if (HasOpenedContext())
1249 {
1250 return myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1251 }
1252
1253 const Handle(SelectMgr_EntityOwner) anOwner =
1254 Handle(SelectMgr_EntityOwner)::DownCast (AIS_Selection::Selection (myCurrentName.ToCString())->Value());
1255 if (anOwner.IsNull() || !anOwner->HasSelectable())
1256 return NULL;
1257
1258 return Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
7fd59977 1259}
1260//=======================================================================
c3282ec1 1261//function : SelectedOwner
1262//purpose :
7fd59977 1263//=======================================================================
c3282ec1 1264Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
7fd59977 1265{
c3282ec1 1266 if(HasOpenedContext())
1267 {
1268 return myLocalContexts(myCurLocalIndex)->SelectedOwner();
7fd59977 1269 }
c3282ec1 1270
1271 Handle(AIS_Selection) aCurSel = AIS_Selection::Selection (myCurrentName.ToCString());
1272
1273 return aCurSel->Extent() > 0 ?
1274 Handle(SelectMgr_EntityOwner)::DownCast (aCurSel->Value()) : NULL;
7fd59977 1275}
1276
1277//=======================================================================
1278//function : EntityOwners
1279//purpose :
1280//=======================================================================
b586500b 1281void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
7fd59977 1282 const Handle(AIS_InteractiveObject)& theIObj,
1283 const Standard_Integer theMode) const
1284{
1285 if ( theIObj.IsNull() )
1286 return;
1287
1288 TColStd_ListOfInteger aModes;
1289 if ( theMode == -1 )
1290 ActivatedModes( theIObj, aModes );
1291 else
1292 aModes.Append( theMode );
1293
b586500b 1294 if (theOwners.IsNull())
1295 theOwners = new SelectMgr_IndexedMapOfOwner();
1296
7fd59977 1297 TColStd_ListIteratorOfListOfInteger anItr( aModes );
1298 for (; anItr.More(); anItr.Next() )
1299 {
1300 int aMode = anItr.Value();
1301 if ( !theIObj->HasSelection( aMode ) )
1302 continue;
1303
f751596e 1304 Handle(SelectMgr_Selection) aSel = theIObj->Selection(aMode);
7fd59977 1305
1306 for ( aSel->Init(); aSel->More(); aSel->Next() )
1307 {
f751596e 1308 Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive()->BaseSensitive();
7fd59977 1309 if ( aEntity.IsNull() )
1310 continue;
1311
1312 Handle(SelectMgr_EntityOwner) aOwner =
1313 Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1314 if ( !aOwner.IsNull() )
b586500b 1315 theOwners->Add( aOwner );
7fd59977 1316 }
1317 }
1318}
1319
c3282ec1 1320//=======================================================================
1321//function : NbSelected
1322//purpose :
1323//=======================================================================
1324Standard_Integer AIS_InteractiveContext::NbSelected()
7fd59977 1325{
c3282ec1 1326 Standard_Integer aNbSelected = 0;
1327 for (InitSelected(); MoreSelected(); NextSelected())
1328 {
1329 aNbSelected++;
1330 }
1331
1332 return aNbSelected;
7fd59977 1333}
1334
1335//=======================================================================
1336//function : HasApplicative
c3282ec1 1337//purpose :
7fd59977 1338//=======================================================================
7fd59977 1339 Standard_Boolean AIS_InteractiveContext::HasApplicative() const
1340{
c3282ec1 1341 return SelectedInteractive()->HasOwner();
7fd59977 1342}
1343
1344//=======================================================================
1345//function : Applicative
c3282ec1 1346//purpose :
7fd59977 1347//=======================================================================
7fd59977 1348Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const
1349{
c3282ec1 1350 return SelectedInteractive()->GetOwner();
7fd59977 1351}
1352
7fd59977 1353//==================================================
c3282ec1 1354// Function: HasDetected
7fd59977 1355// Purpose :
1356//==================================================
c3282ec1 1357Standard_Boolean AIS_InteractiveContext::HasDetected() const
7fd59977 1358{
1359 if(HasOpenedContext())
1360 return myLocalContexts(myCurLocalIndex)->HasDetected();
c3282ec1 1361
1362 return !myLastPicked.IsNull();
7fd59977 1363}
1364
1365//=======================================================================
1366//function : HasDetectedShape
1367//purpose :
1368//=======================================================================
1369
1370Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1371{
1372 if(HasOpenedContext())
1373 return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1374 return Standard_False;
1375}
1376
1377//=======================================================================
1378//function : DetectedShape
1379//purpose :
1380//=======================================================================
1381
1382const TopoDS_Shape&
1383AIS_InteractiveContext::DetectedShape() const
1384{
1385 return myLocalContexts(myCurLocalIndex)->DetectedShape();
1386}
1387
1388//=======================================================================
1389//function : DetectedInteractive
c3282ec1 1390//purpose :
7fd59977 1391//=======================================================================
c3282ec1 1392Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedInteractive() const
7fd59977 1393{
c3282ec1 1394 if (HasOpenedContext())
7fd59977 1395 return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
c3282ec1 1396
1397 return Handle(AIS_InteractiveObject)::DownCast (myLastPicked->Selectable());
7fd59977 1398}
1399
1400
1401Standard_Boolean AIS_InteractiveContext::HasNextDetected() const
1402{
1403 if(!HasOpenedContext())
1404 return Standard_False; // temporaire
1405 else
1406 return myLocalContexts(myCurLocalIndex)->HasNextDetected();
1407
1408}
1409
1410
1411//=======================================================================
1412//function : DetectedOwner
1413//purpose :
1414//=======================================================================
1415Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1416{
c3282ec1 1417 if (HasOpenedContext())
7fd59977 1418 return myLocalContexts(myCurLocalIndex)->DetectedOwner();
7fd59977 1419
c3282ec1 1420 return myLastPicked;
1421}
7fd59977 1422
1423//=======================================================================
1424//function : HilightNextDetected
679ecdee 1425//purpose :
7fd59977 1426//=======================================================================
679ecdee 1427Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1428 const Standard_Boolean theToRedrawImmediate)
7fd59977 1429{
679ecdee 1430 return HasOpenedContext()
1431 ? myLocalContexts (myCurLocalIndex)->HilightNextDetected (theView, theToRedrawImmediate)
1432 : 0;
7fd59977 1433
1434}
1435
1436//=======================================================================
1437//function : HilightNextDetected
679ecdee 1438//purpose :
7fd59977 1439//=======================================================================
679ecdee 1440Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1441 const Standard_Boolean theToRedrawImmediate)
7fd59977 1442{
679ecdee 1443 return HasOpenedContext()
1444 ? myLocalContexts (myCurLocalIndex)->HilightPreviousDetected (theView, theToRedrawImmediate)
1445 : 0;
7fd59977 1446
1447}
1448
7fd59977 1449//=======================================================================
1450//function : InitDetected
1451//purpose :
1452//=======================================================================
1453void AIS_InteractiveContext::InitDetected()
1454{
57ad5cbd 1455 if (HasOpenedContext())
7fd59977 1456 {
1457 myLocalContexts(myCurLocalIndex)->InitDetected();
1458 return;
1459 }
1460
1461 if(myAISDetectedSeq.Length() != 0)
57ad5cbd 1462 {
7fd59977 1463 myAISCurDetected = 1;
57ad5cbd 1464 }
7fd59977 1465}
1466
1467//=======================================================================
1468//function : MoreDetected
1469//purpose :
1470//=======================================================================
1471Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1472{
57ad5cbd 1473 if (HasOpenedContext())
1474 {
7fd59977 1475 return myLocalContexts(myCurLocalIndex)->MoreDetected();
57ad5cbd 1476 }
7fd59977 1477
57ad5cbd 1478 return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length()) ?
7fd59977 1479 Standard_True : Standard_False;
1480}
1481
1482//=======================================================================
1483//function : NextDetected
1484//purpose :
1485//=======================================================================
1486void AIS_InteractiveContext::NextDetected()
1487{
1488 if(HasOpenedContext())
1489 {
1490 myLocalContexts(myCurLocalIndex)->NextDetected();
1491 return;
1492 }
1493
1494 myAISCurDetected++;
1495}
1496
1497//=======================================================================
1498//function : DetectedCurrentShape
1499//purpose :
1500//=======================================================================
7fd59977 1501const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1502{
57ad5cbd 1503 if (HasOpenedContext())
1504 {
7fd59977 1505 return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
57ad5cbd 1506 }
7fd59977 1507
57ad5cbd 1508 static TopoDS_Shape aDummyShape;
1509
1510 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1511
1512 if (aCurrentShape.IsNull())
1513 {
1514 return aDummyShape;
1515 }
1516
1517 return aCurrentShape->Shape();
7fd59977 1518}
1519
1520//=======================================================================
1521//function : DetectedCurrentObject
1522//purpose :
1523//=======================================================================
57ad5cbd 1524Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1525{
1526 if (HasOpenedContext())
1527 {
7fd59977 1528 return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
57ad5cbd 1529 }
7fd59977 1530
57ad5cbd 1531 return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL;
7fd59977 1532}
c3282ec1 1533
1534//=======================================================================
1535//function : FirstSelectedObject
1536//purpose :
1537//=======================================================================
1538Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject()
1539{
1540 Handle(AIS_InteractiveObject) anObject;
1541
1542 if (HasOpenedContext())
1543 return anObject;
1544
1545 InitSelected();
1546 if (MoreSelected())
1547 {
1548 return SelectedInteractive();
1549 }
1550 return anObject;
1551}
1552
1553//=======================================================================
1554//function : RedrawImmediate
1555//purpose : Redisplays immediate strucures of the viewer given according to their visibility
1556//=======================================================================
1557void AIS_InteractiveContext::RedrawImmediate (const Handle(V3d_Viewer)& theViewer)
1558{
1559 myMainPM->RedrawImmediate (theViewer);
1560}