0027818: Visualization - provide an interface to define highlight presentation properties
[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
7fd59977 310 myAISCurDetected = 0;
311 myAISDetectedSeq.Clear();
7fd59977 312
679ecdee 313 if (theView->Viewer() != myMainVwr)
314 {
7fd59977 315 return AIS_SOD_Error;
679ecdee 316 }
317
318 // preliminaires
319 myLastPicked = myLastinMain;
320 myWasLastMain = Standard_True;
321 AIS_StatusOfDetection aStatus = AIS_SOD_Nothing;
322 Standard_Boolean toUpdateViewer = Standard_False;
323
a272ed94 324 myFilters->SetDisabledObjects (theView->View()->HiddenObjects());
679ecdee 325 myMainSel->Pick (theXPix, theYPix, theView);
326
327 // filling of myAISDetectedSeq sequence storing information about detected AIS objects
328 // (the objects must be AIS_Shapes)
329 const Standard_Integer aDetectedNb = myMainSel->NbPicked();
54a16ee4 330 Standard_Integer aNewDetected = 0;
679ecdee 331 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
7fd59977 332 {
679ecdee 333 Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter);
334 if (anOwner.IsNull()
335 || !myFilters->IsOk (anOwner))
336 {
337 continue;
338 }
339
54a16ee4 340 if (aNewDetected < 1)
341 {
342 aNewDetected = aDetIter;
343 }
679ecdee 344 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
57ad5cbd 345 if (!anObj.IsNull())
679ecdee 346 {
347 myAISDetectedSeq.Append (anObj);
348 }
7fd59977 349 }
7fd59977 350
54a16ee4 351 if (aNewDetected >= 1)
7fd59977 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);
1032 if (theObject->HasSelection (0))
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...
1070 const Handle(SelectMgr_Selection)& aSel = theObject->Selection (0);
1071 if (aSel->IsEmpty())
1072 return;
1073 aSel->Init();
1074 Handle(SelectMgr_EntityOwner) anOwner =
1075 Handle(SelectMgr_EntityOwner)::DownCast (aSel->Sensitive()->BaseSensitive()->OwnerId());
016e5959 1076 mySelection->ClearAndSelect (anOwner);
c3282ec1 1077 anOwner->State (1);
e1b01c73 1078 if (anOwner == theObject->GlobalSelOwner())
1079 {
1080 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (theObject);
1081 aState->SetHilightStatus (Standard_True);
8e5fb5ea 1082 aState->SetHilightStyle (anObjSelStyle);
e1b01c73 1083 }
8e5fb5ea 1084 Handle(Graphic3d_HighlightStyle) aCustomStyle;
1085 if (HighlightStyle (theObject, aCustomStyle))
c3282ec1 1086 {
8e5fb5ea 1087 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
c3282ec1 1088 {
8e5fb5ea 1089 HilightWithColor (theObject, anObjSelStyle, Standard_False);
c3282ec1 1090 }
7fd59977 1091 }
c3282ec1 1092 else
1093 {
8e5fb5ea 1094 HilightWithColor (theObject, anObjSelStyle, Standard_False);
c3282ec1 1095 }
1096
1097 if (theToUpdateViewer)
1098 UpdateCurrentViewer();
7fd59977 1099}
1100
1101//=======================================================================
c3282ec1 1102//function : SetSelected
1103//purpose : Sets the whole object as selected and highlights it with selection color
7fd59977 1104//=======================================================================
c3282ec1 1105void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
1106 const Standard_Boolean theToUpdateViewer)
7fd59977 1107{
b4006117 1108 if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner))
c3282ec1 1109 return;
1110
1111 const Handle(AIS_InteractiveObject) anObject =
1112 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
8e5fb5ea 1113 const Handle(Graphic3d_HighlightStyle)& anObjSelStyle =
1114 getSelStyle (anObject);
c3282ec1 1115
1116 if (NbSelected() == 1 && theOwner->IsSelected())
1117 {
8e5fb5ea 1118 Handle(Graphic3d_HighlightStyle) aCustomStyle;
1119 if (HighlightStyle (theOwner, aCustomStyle))
c3282ec1 1120 {
8e5fb5ea 1121 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
c3282ec1 1122 {
1123 const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0;
8e5fb5ea 1124 theOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
c3282ec1 1125 }
1126 }
1127 return;
1128 }
1129
1130 if (!myObjects.IsBound (anObject))
1131 Display (anObject, Standard_False);
1132
b4006117 1133 unhighlightSelected();
c3282ec1 1134
016e5959 1135 mySelection->ClearAndSelect (theOwner);
8e5fb5ea 1136 Handle(Graphic3d_HighlightStyle) aCustomStyle;
1137 if (!HighlightStyle (theOwner, aCustomStyle) ||
1138 (!aCustomStyle.IsNull() && aCustomStyle != anObjSelStyle))
c3282ec1 1139 {
8e5fb5ea 1140 highlightSelected (theOwner);
c3282ec1 1141 }
1142
8e5fb5ea 1143 theOwner->State (1);
e1b01c73 1144 if (theOwner == anObject->GlobalSelOwner())
1145 {
1146 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (anObject);
1147 aState->SetHilightStatus (Standard_True);
8e5fb5ea 1148 aState->SetHilightStyle (anObjSelStyle);
e1b01c73 1149 }
1150
c3282ec1 1151 if (theToUpdateViewer)
1152 UpdateCurrentViewer();
7fd59977 1153}
1154
1155//=======================================================================
1156//function : AddOrRemoveSelected
c3282ec1 1157//purpose : Adds or removes current object from AIS selection and highlights/unhighlights it.
1158// Since this method makes sence only for neutral point selection of a whole object,
1159// if 0 selection of the object is empty this method simply does nothing.
7fd59977 1160//=======================================================================
c3282ec1 1161void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& theObject,
1162 const Standard_Boolean theToUpdateViewer)
7fd59977 1163{
95081657 1164 if (theObject.IsNull())
1165 return;
c3282ec1 1166
1167 if (HasOpenedContext())
1168 return myLocalContexts (myCurLocalIndex)->AddOrRemoveSelected (theObject, theToUpdateViewer);
1169
95081657 1170 const Standard_Integer aGlobalSelMode = theObject->GlobalSelectionMode();
1171 if (!myObjects.IsBound (theObject) || !theObject->HasSelection (aGlobalSelMode))
c3282ec1 1172 return;
1173
95081657 1174 if (!theObject->HasInteractiveContext())
1175 theObject->SetContext (this);
1176
7411850a 1177 const Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
c3282ec1 1178
1179 if (anOwner.IsNull() || !anOwner->HasSelectable())
1180 return;
1181
1182 AddOrRemoveSelected (anOwner, theToUpdateViewer);
7fd59977 1183}
1184//=======================================================================
1185//function : AddOrRemoveSelected
1186//purpose :
1187//=======================================================================
1188
c3282ec1 1189void AIS_InteractiveContext::AddOrRemoveSelected (const TopoDS_Shape& aShap,
7fd59977 1190 const Standard_Boolean updateviewer)
1191{
1192 if(!HasOpenedContext()) {
0797d9d3 1193#ifdef OCCT_DEBUG
7fd59977 1194 cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
1195#endif
1196 return;
1197 }
1198
1199 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
1200 if(updateviewer) UpdateCurrentViewer();
1201
1202}
c3282ec1 1203
7fd59977 1204//=======================================================================
1205//function : AddOrRemoveSelected
c3282ec1 1206//purpose : Allows to highlight or unhighlight the owner given depending on
1207// its selection status
7fd59977 1208//=======================================================================
c3282ec1 1209void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
1210 const Standard_Boolean theToUpdateViewer)
1211{
1212 if (HasOpenedContext())
1213 return myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected (theOwner, theToUpdateViewer);
7fd59977 1214
c3282ec1 1215 if (theOwner.IsNull() || !theOwner->HasSelectable())
7fd59977 1216 return;
c3282ec1 1217
016e5959 1218 AIS_SelectStatus aSelStat = mySelection->Select (theOwner);
c3282ec1 1219
1220 Standard_Integer aState = aSelStat == AIS_SS_Added ? 1 : 0;
1221 theOwner->State (aState);
1222 const Handle(AIS_InteractiveObject) anObj =
1223 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1224 const Standard_Boolean isGlobal = anObj->GlobalSelOwner() == theOwner;
e1b01c73 1225 Handle(AIS_GlobalStatus)& aStatus = myObjects.ChangeFind (anObj);
c3282ec1 1226 const Standard_Integer aHiMode = anObj->HasHilightMode() ? anObj->HilightMode() : 0;
1227 if (aState == 1)
1228 {
8e5fb5ea 1229 highlightSelected (theOwner);
c3282ec1 1230 if (isGlobal)
1231 {
1232 aStatus->SetHilightStatus (Standard_True);
8e5fb5ea 1233 aStatus->SetHilightStyle (getSelStyle (anObj));
c3282ec1 1234 }
1235 }
1236 else
1237 {
1238 if (theOwner->IsAutoHilight())
1239 theOwner->Unhilight (myMainPM, aHiMode);
1240 else
1241 anObj->ClearSelected();
1242 aStatus->SetHilightStatus (Standard_False);
8e5fb5ea 1243 aStatus->SetHilightStyle (new Graphic3d_HighlightStyle());
7fd59977 1244 }
7fd59977 1245
c3282ec1 1246 if (theToUpdateViewer)
1247 UpdateCurrentViewer();
1248}
7fd59977 1249
1250
1251//=======================================================================
1252//function : IsSelected
c3282ec1 1253//purpose :
7fd59977 1254//=======================================================================
c3282ec1 1255Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const
7fd59977 1256{
c3282ec1 1257 if(HasOpenedContext())
1258 return myLocalContexts(myCurLocalIndex)->IsSelected (theObj);
1259
1260 if (theObj.IsNull() || !myObjects.IsBound (theObj))
1261 return Standard_False;
1262
1263 const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode();
1264 const TColStd_ListOfInteger& anActivatedModes = myObjects (theObj)->SelectionModes();
1265 Standard_Boolean isGlobalModeActivated = Standard_False;
1266 for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
1267 {
1268 if (aModeIter.Value() == aGlobalSelMode)
1269 {
1270 isGlobalModeActivated = Standard_True;
1271 break;
1272 }
1273 }
95081657 1274 if (!theObj->HasSelection (aGlobalSelMode) || !isGlobalModeActivated || theObj->GlobalSelOwner().IsNull())
c3282ec1 1275 return Standard_False;
1276
95081657 1277 return theObj->GlobalSelOwner()->State() == 1;
7fd59977 1278}
1279
c3282ec1 1280//=======================================================================
1281//function : IsSelected
1282//purpose : Returns true is the owner given is selected
1283//=======================================================================
1284Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(SelectMgr_EntityOwner)& theOwner) const
1285{
1286 if (HasOpenedContext())
1287 return myLocalContexts(myCurLocalIndex)->IsSelected (theOwner);
1288
1289 if (theOwner.IsNull())
1290 return Standard_False;
1291
1292 return theOwner->IsSelected();
1293}
7fd59977 1294
1295//=======================================================================
1296//function : InitSelected
c3282ec1 1297//purpose :
7fd59977 1298//=======================================================================
7fd59977 1299void AIS_InteractiveContext::InitSelected()
1300{
c3282ec1 1301 if (HasOpenedContext())
1302 {
1303 myLocalContexts (myCurLocalIndex)->InitSelected();
1304 return;
1305 }
1306
016e5959 1307 mySelection->Init();
7fd59977 1308}
1309
1310//=======================================================================
1311//function : MoreSelected
c3282ec1 1312//purpose :
7fd59977 1313//=======================================================================
c3282ec1 1314Standard_Boolean AIS_InteractiveContext::MoreSelected() const
7fd59977 1315{
c3282ec1 1316 if (HasOpenedContext())
1317 return myLocalContexts (myCurLocalIndex)->MoreSelected();
1318
016e5959 1319 return mySelection->More();
7fd59977 1320}
1321
1322//=======================================================================
1323//function : NextSelected
c3282ec1 1324//purpose :
7fd59977 1325//=======================================================================
7fd59977 1326void AIS_InteractiveContext::NextSelected()
1327{
c3282ec1 1328 if(HasOpenedContext())
1329 {
1330 return myLocalContexts (myCurLocalIndex)->NextSelected();
c3282ec1 1331 }
1332
016e5959 1333 mySelection->Next();
7fd59977 1334}
1335
1336//=======================================================================
1337//function : HasSelectedShape
c3282ec1 1338//purpose :
7fd59977 1339//=======================================================================
c3282ec1 1340Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
7fd59977 1341{
c3282ec1 1342 if(HasOpenedContext())
1343 {
1344 return myLocalContexts(myCurLocalIndex)->HasSelectedShape();
7fd59977 1345 }
4aaadad7
SS
1346 if (!mySelection->More())
1347 return Standard_False;
1348
1349 const Handle(StdSelect_BRepOwner) anOwner =
1350 Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
c3282ec1 1351
4aaadad7 1352 return !anOwner.IsNull() && anOwner->HasShape();
7fd59977 1353}
1354
1355//=======================================================================
1356//function : SelectedShape
c3282ec1 1357//purpose :
7fd59977 1358//=======================================================================
c3282ec1 1359TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
7fd59977 1360{
c3282ec1 1361 if (HasOpenedContext())
0717ddc1 1362 {
1363 return myLocalContexts (myCurLocalIndex)->SelectedShape();
1364 }
7fd59977 1365
02974a19 1366 if (!mySelection->More())
c3282ec1 1367 return TopoDS_Shape();
7fd59977 1368
c3282ec1 1369 const Handle(StdSelect_BRepOwner) anOwner =
016e5959 1370 Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
3475df12 1371 if (anOwner.IsNull() || !anOwner->HasSelectable())
c3282ec1 1372 return TopoDS_Shape();
1373
1374 return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location());
7fd59977 1375}
1376
c3282ec1 1377//=======================================================================
1378//function : SelectedInteractive
1379//purpose :
1380//=======================================================================
7fd59977 1381Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const
1382{
c3282ec1 1383 if (HasOpenedContext())
1384 {
1385 return myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1386 }
1387
02974a19 1388 return !mySelection->More()
1389 ? Handle(AIS_InteractiveObject)()
1390 : Handle(AIS_InteractiveObject)::DownCast (mySelection->Value()->Selectable());
7fd59977 1391}
1392//=======================================================================
c3282ec1 1393//function : SelectedOwner
1394//purpose :
7fd59977 1395//=======================================================================
c3282ec1 1396Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
7fd59977 1397{
c3282ec1 1398 if(HasOpenedContext())
1399 {
1400 return myLocalContexts(myCurLocalIndex)->SelectedOwner();
7fd59977 1401 }
c3282ec1 1402
02974a19 1403 return !mySelection->More()
1404 ? Handle(SelectMgr_EntityOwner)()
1405 : mySelection->Value();
7fd59977 1406}
1407
1408//=======================================================================
1409//function : EntityOwners
1410//purpose :
1411//=======================================================================
b586500b 1412void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
7fd59977 1413 const Handle(AIS_InteractiveObject)& theIObj,
1414 const Standard_Integer theMode) const
1415{
1416 if ( theIObj.IsNull() )
1417 return;
1418
1419 TColStd_ListOfInteger aModes;
1420 if ( theMode == -1 )
1421 ActivatedModes( theIObj, aModes );
1422 else
1423 aModes.Append( theMode );
1424
b586500b 1425 if (theOwners.IsNull())
1426 theOwners = new SelectMgr_IndexedMapOfOwner();
1427
7fd59977 1428 TColStd_ListIteratorOfListOfInteger anItr( aModes );
1429 for (; anItr.More(); anItr.Next() )
1430 {
1431 int aMode = anItr.Value();
1432 if ( !theIObj->HasSelection( aMode ) )
1433 continue;
1434
f751596e 1435 Handle(SelectMgr_Selection) aSel = theIObj->Selection(aMode);
7fd59977 1436
1437 for ( aSel->Init(); aSel->More(); aSel->Next() )
1438 {
f751596e 1439 Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive()->BaseSensitive();
7fd59977 1440 if ( aEntity.IsNull() )
1441 continue;
1442
1443 Handle(SelectMgr_EntityOwner) aOwner =
1444 Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1445 if ( !aOwner.IsNull() )
b586500b 1446 theOwners->Add( aOwner );
7fd59977 1447 }
1448 }
1449}
1450
c3282ec1 1451//=======================================================================
1452//function : NbSelected
1453//purpose :
1454//=======================================================================
1455Standard_Integer AIS_InteractiveContext::NbSelected()
7fd59977 1456{
c3282ec1 1457 Standard_Integer aNbSelected = 0;
1458 for (InitSelected(); MoreSelected(); NextSelected())
1459 {
1460 aNbSelected++;
1461 }
1462
1463 return aNbSelected;
7fd59977 1464}
1465
1466//=======================================================================
1467//function : HasApplicative
c3282ec1 1468//purpose :
7fd59977 1469//=======================================================================
7fd59977 1470 Standard_Boolean AIS_InteractiveContext::HasApplicative() const
1471{
c3282ec1 1472 return SelectedInteractive()->HasOwner();
7fd59977 1473}
1474
1475//=======================================================================
1476//function : Applicative
c3282ec1 1477//purpose :
7fd59977 1478//=======================================================================
7fd59977 1479Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const
1480{
c3282ec1 1481 return SelectedInteractive()->GetOwner();
7fd59977 1482}
1483
7fd59977 1484//==================================================
c3282ec1 1485// Function: HasDetected
7fd59977 1486// Purpose :
1487//==================================================
c3282ec1 1488Standard_Boolean AIS_InteractiveContext::HasDetected() const
7fd59977 1489{
1490 if(HasOpenedContext())
1491 return myLocalContexts(myCurLocalIndex)->HasDetected();
c3282ec1 1492
1493 return !myLastPicked.IsNull();
7fd59977 1494}
1495
1496//=======================================================================
1497//function : HasDetectedShape
1498//purpose :
1499//=======================================================================
1500
1501Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1502{
1503 if(HasOpenedContext())
1504 return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1505 return Standard_False;
1506}
1507
1508//=======================================================================
1509//function : DetectedShape
1510//purpose :
1511//=======================================================================
1512
1513const TopoDS_Shape&
1514AIS_InteractiveContext::DetectedShape() const
1515{
1516 return myLocalContexts(myCurLocalIndex)->DetectedShape();
1517}
1518
1519//=======================================================================
1520//function : DetectedInteractive
c3282ec1 1521//purpose :
7fd59977 1522//=======================================================================
c3282ec1 1523Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedInteractive() const
7fd59977 1524{
c3282ec1 1525 if (HasOpenedContext())
7fd59977 1526 return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
c3282ec1 1527
1528 return Handle(AIS_InteractiveObject)::DownCast (myLastPicked->Selectable());
7fd59977 1529}
1530
1531
1532Standard_Boolean AIS_InteractiveContext::HasNextDetected() const
1533{
1534 if(!HasOpenedContext())
1535 return Standard_False; // temporaire
1536 else
1537 return myLocalContexts(myCurLocalIndex)->HasNextDetected();
1538
1539}
1540
1541
1542//=======================================================================
1543//function : DetectedOwner
1544//purpose :
1545//=======================================================================
1546Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1547{
c3282ec1 1548 if (HasOpenedContext())
7fd59977 1549 return myLocalContexts(myCurLocalIndex)->DetectedOwner();
7fd59977 1550
c3282ec1 1551 return myLastPicked;
1552}
7fd59977 1553
1554//=======================================================================
1555//function : HilightNextDetected
679ecdee 1556//purpose :
7fd59977 1557//=======================================================================
679ecdee 1558Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1559 const Standard_Boolean theToRedrawImmediate)
7fd59977 1560{
679ecdee 1561 return HasOpenedContext()
1562 ? myLocalContexts (myCurLocalIndex)->HilightNextDetected (theView, theToRedrawImmediate)
1563 : 0;
7fd59977 1564
1565}
1566
1567//=======================================================================
1568//function : HilightNextDetected
679ecdee 1569//purpose :
7fd59977 1570//=======================================================================
679ecdee 1571Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1572 const Standard_Boolean theToRedrawImmediate)
7fd59977 1573{
679ecdee 1574 return HasOpenedContext()
1575 ? myLocalContexts (myCurLocalIndex)->HilightPreviousDetected (theView, theToRedrawImmediate)
1576 : 0;
7fd59977 1577
1578}
1579
7fd59977 1580//=======================================================================
1581//function : InitDetected
1582//purpose :
1583//=======================================================================
1584void AIS_InteractiveContext::InitDetected()
1585{
57ad5cbd 1586 if (HasOpenedContext())
7fd59977 1587 {
1588 myLocalContexts(myCurLocalIndex)->InitDetected();
1589 return;
1590 }
1591
1592 if(myAISDetectedSeq.Length() != 0)
57ad5cbd 1593 {
7fd59977 1594 myAISCurDetected = 1;
57ad5cbd 1595 }
7fd59977 1596}
1597
1598//=======================================================================
1599//function : MoreDetected
1600//purpose :
1601//=======================================================================
1602Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1603{
57ad5cbd 1604 if (HasOpenedContext())
1605 {
7fd59977 1606 return myLocalContexts(myCurLocalIndex)->MoreDetected();
57ad5cbd 1607 }
7fd59977 1608
57ad5cbd 1609 return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length()) ?
7fd59977 1610 Standard_True : Standard_False;
1611}
1612
1613//=======================================================================
1614//function : NextDetected
1615//purpose :
1616//=======================================================================
1617void AIS_InteractiveContext::NextDetected()
1618{
1619 if(HasOpenedContext())
1620 {
1621 myLocalContexts(myCurLocalIndex)->NextDetected();
1622 return;
1623 }
1624
1625 myAISCurDetected++;
1626}
1627
1628//=======================================================================
1629//function : DetectedCurrentShape
1630//purpose :
1631//=======================================================================
7fd59977 1632const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1633{
57ad5cbd 1634 if (HasOpenedContext())
1635 {
7fd59977 1636 return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
57ad5cbd 1637 }
7fd59977 1638
57ad5cbd 1639 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1640
1641 if (aCurrentShape.IsNull())
1642 {
016e5959 1643 return AIS_myDummyShape;
57ad5cbd 1644 }
1645
1646 return aCurrentShape->Shape();
7fd59977 1647}
1648
1649//=======================================================================
1650//function : DetectedCurrentObject
1651//purpose :
1652//=======================================================================
57ad5cbd 1653Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1654{
1655 if (HasOpenedContext())
1656 {
7fd59977 1657 return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
57ad5cbd 1658 }
7fd59977 1659
57ad5cbd 1660 return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL;
7fd59977 1661}
c3282ec1 1662
1663//=======================================================================
1664//function : FirstSelectedObject
1665//purpose :
1666//=======================================================================
1667Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject()
1668{
1669 Handle(AIS_InteractiveObject) anObject;
1670
1671 if (HasOpenedContext())
1672 return anObject;
1673
1674 InitSelected();
1675 if (MoreSelected())
1676 {
1677 return SelectedInteractive();
1678 }
1679 return anObject;
1680}
1681
1682//=======================================================================
1683//function : RedrawImmediate
1684//purpose : Redisplays immediate strucures of the viewer given according to their visibility
1685//=======================================================================
1686void AIS_InteractiveContext::RedrawImmediate (const Handle(V3d_Viewer)& theViewer)
1687{
1688 myMainPM->RedrawImmediate (theViewer);
1689}