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