0025867: Visualization, TKOpenGl - fix misprint in transformation persistence math
[occt.git] / src / AIS / AIS_LocalContext_1.cxx
CommitLineData
b311480e 1// Created on: 1996-10-30
2// Created by: Robert COUBLANC
3// Copyright (c) 1996-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.
b311480e 16
7fd59977 17// Modified by rob Thu Apr 02 1998
18// - use of optimisation in SelectMgr_ViewerSelector
19// -> Best management in detected entities...
20
7fd59977 21#include <AIS_LocalContext.jxx>
22#include <StdSelect_BRepOwner.hxx>
bc677575 23#include <TColStd_ListOfInteger.hxx>
24#include <TColStd_ListIteratorOfListOfInteger.hxx>
7fd59977 25#include <TColStd_MapOfTransient.hxx>
26#include <TColStd_MapIteratorOfMapOfTransient.hxx>
27#include <Prs3d_Presentation.hxx>
28#include <Prs3d_Drawer.hxx>
29#include <Prs3d_ShadingAspect.hxx>
30#include <AIS_LocalStatus.hxx>
31#include <StdPrs_WFShape.hxx>
b8ddfc2f 32#include <Graphic3d_ArrayOfTriangles.hxx>
7fd59977 33#include <Graphic3d_Group.hxx>
34#include <Select3D_SensitiveTriangulation.hxx>
35#include <SelectBasics_SensitiveEntity.hxx>
36#include <TCollection_AsciiString.hxx>
e3a6386d 37#include <NCollection_Map.hxx>
38
7fd59977 39#include <SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive.hxx>
7fd59977 40#include <SelectMgr_Selection.hxx>
e3a6386d 41#include <SelectMgr_SequenceOfOwner.hxx>
7fd59977 42#include <OSD_Environment.hxx>
7fd59977 43
44#include <Geom_Transformation.hxx>
45#include <AIS_Selection.hxx>
679ecdee 46#include <Aspect_Grid.hxx>
7fd59977 47#include <AIS_Shape.hxx>
7fd59977 48
49static Standard_Integer GetHiMod(const Handle(AIS_InteractiveObject)& IO)
50{
51 return IO->HasHilightMode() ? IO->HilightMode():0;
52}
53
54//==================================================
679ecdee 55// Function: MoveTo
7fd59977 56// Purpose :
57//==================================================
679ecdee 58AIS_StatusOfDetection AIS_LocalContext::MoveTo (const Standard_Integer theXpix,
59 const Standard_Integer theYpix,
60 const Handle(V3d_View)& theView,
61 const Standard_Boolean theToRedrawImmediate)
7fd59977 62{
679ecdee 63 // check that ViewerSelector gives
64 if (theView->Viewer() != myCTX->CurrentViewer())
65 {
66 return AIS_SOD_Error;
67 }
68
69 myAISCurDetected = 0;
70 myAISDetectedSeq.Clear();
71
72 myCurDetected = 0;
73 myDetectedSeq.Clear();
74 myMainVS->Pick (theXpix, theYpix, theView);
75
76 const Standard_Integer aDetectedNb = myMainVS->NbPicked();
77 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
78 {
79 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (aDetIter);
80 if (anOwner.IsNull()
81 || !myFilters->IsOk (anOwner))
82 {
83 continue;
7fd59977 84 }
679ecdee 85
57ad5cbd 86 myDetectedSeq.Append (aDetIter); // normally they are already arranged in correct order...
679ecdee 87 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
57ad5cbd 88 if (!anObj.IsNull())
679ecdee 89 {
90 myAISDetectedSeq.Append (anObj);
7fd59977 91 }
679ecdee 92 }
7fd59977 93
679ecdee 94 // result of courses..
95 if (aDetectedNb == 0 || myDetectedSeq.IsEmpty())
96 {
97 if (mylastindex != 0 && mylastindex <= myMapOfOwner.Extent())
98 {
63d907e7 99 myMainPM->ClearImmediateDraw();
679ecdee 100 Unhilight (myMapOfOwner (mylastindex), theView);
101 if (theToRedrawImmediate)
102 {
103 theView->RedrawImmediate();
7fd59977 104 }
7fd59977 105 }
679ecdee 106
107 mylastindex = 0;
108 return aDetectedNb == 0
109 ? AIS_SOD_Nothing
110 : AIS_SOD_AllBad;
111 }
112
113 // all owners detected by the selector are passed to the
114 // filters and correct ones are preserved...
115 myCurDetected = 1;
116 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected));
117 manageDetected (anOwner, theView, theToRedrawImmediate);
118 if (myDetectedSeq.Length() == 1)
119 {
120 return aDetectedNb == 1
121 ? AIS_SOD_OnlyOneDetected
122 : AIS_SOD_OnlyOneGood;
123 }
124 else
125 {
126 return AIS_SOD_SeveralGood;
7fd59977 127 }
7fd59977 128}
129
c398b00e 130//=======================================================================
131//function : Select
132//purpose :
133//=======================================================================
134AIS_StatusOfPick AIS_LocalContext::Select (const Standard_Boolean toUpdateViewer)
7fd59977 135{
c398b00e 136 if (myAutoHilight)
137 {
138 UnhilightPicked (Standard_False);
139 }
7fd59977 140
c398b00e 141 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
142
143 Standard_Integer aDetIndex = DetectedIndex();
144 if (aDetIndex <= 0)
145 {
146 ClearSelected (toUpdateViewer);
147 return (AIS_Selection::Extent() == 0) ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
7fd59977 148 }
149
c398b00e 150 const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (aDetIndex);
7fd59977 151
c398b00e 152 ClearSelected (Standard_False);
153
154 if (!anOwner->IsSelected()) // anOwner is not selected
155 {
156 anOwner->SetSelected (Standard_True);
157 AIS_Selection::Select (anOwner);
7fd59977 158 }
c398b00e 159
679ecdee 160 if (myAutoHilight)
161 {
7fd59977 162 const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
679ecdee 163 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
164 {
c398b00e 165 Unhilight (anOwner, aViewer->ActiveView());
7fd59977 166 }
167
679ecdee 168 // advanced selection highlighting mechanism
c398b00e 169 if (!anOwner->IsAutoHilight() && anOwner->HasSelectable())
679ecdee 170 {
c398b00e 171 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
679ecdee 172 UpdateSelected (anIO, Standard_False);
173 }
174
c398b00e 175 if (toUpdateViewer)
679ecdee 176 {
177 myCTX->CurrentViewer()->Update();
178 }
7fd59977 179 }
c398b00e 180
181 return (AIS_Selection::Extent() == 1) ? AIS_SOP_OneSelected : AIS_SOP_SeveralSelected;
7fd59977 182}
c398b00e 183
184//=======================================================================
185//function : Select
186//purpose :
187//=======================================================================
188AIS_StatusOfPick AIS_LocalContext::Select (const Standard_Integer theXPMin,
189 const Standard_Integer theYPMin,
190 const Standard_Integer theXPMax,
191 const Standard_Integer theYPMax,
192 const Handle(V3d_View)& theView,
193 const Standard_Boolean toUpdateViewer)
7fd59977 194{
c398b00e 195 if (theView->Viewer() == myCTX->CurrentViewer())
196 {
197 myMainVS->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
198 if (myAutoHilight)
199 {
200 UnhilightPicked (Standard_False);
201 }
202
203 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
204 Standard_Integer aSelNum = AIS_Selection::Extent();
205
7fd59977 206 myMainVS->Init();
c398b00e 207 if (!myMainVS->More())
208 {
209 ClearSelected (toUpdateViewer);
210 mylastindex = 0;
211 return aSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
7fd59977 212 }
213
c398b00e 214 ClearSelected (Standard_False);
215
216 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
217 {
218 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
219 if (myFilters->IsOk (anOwner))
220 {
221 // it can be helpful to classify this owner immediately...
222 if (!anOwner->IsSelected())
223 {
224 anOwner->SetSelected (Standard_True);
225 AIS_Selection::Select (anOwner);
226 }
7fd59977 227 }
228 }
c398b00e 229
230 if (myAutoHilight)
231 {
232 HilightPicked (toUpdateViewer);
233 }
7fd59977 234 }
7fd59977 235
c398b00e 236 Standard_Integer aSelNum = AIS_Selection::Extent();
7fd59977 237
c398b00e 238 return (aSelNum == 1) ? AIS_SOP_OneSelected
239 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
240 : AIS_SOP_Error;
241}
7fd59977 242
243//==================================================
c398b00e 244// Function: Select
245// Purpose : Selection by polyline
7fd59977 246//==================================================
c398b00e 247AIS_StatusOfPick AIS_LocalContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
248 const Handle(V3d_View)& theView,
249 const Standard_Boolean toUpdateViewer)
7fd59977 250{
c398b00e 251 if (theView->Viewer() == myCTX->CurrentViewer())
252 {
253 myMainVS->Pick (thePolyline, theView);
7fd59977 254
c398b00e 255 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
256
257 Standard_Integer aLastSelNum = AIS_Selection::Extent();
258 myMainVS->Init();
259 if (!myMainVS->More())
260 {
261 // Nothing is selected clear selection.
262 ClearSelected (toUpdateViewer);
263 mylastindex = 0;
264
265 // Return state to know if something was unselected
266 return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
267 }
268
269 if (myAutoHilight)
270 {
271 UnhilightPicked (Standard_False);
272 }
273
274 // Clear previous selection without update to process this selection
275 ClearSelected (Standard_False);
276
277 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
278 {
279 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
280 if (myFilters->IsOk (anOwner))
281 {
282 // it can be helpful to classify this owner immediately...
283 if (!anOwner->IsSelected())
284 {
285 AIS_Selection::AddSelect (anOwner);
286 anOwner->SetSelected (Standard_True);
287 }
288 }
289 }
290
291 if (myAutoHilight)
292 {
293 HilightPicked (toUpdateViewer);
294 }
295 }
296
297 Standard_Integer aSelNum = AIS_Selection::Extent();
298 return (aSelNum == 1) ? AIS_SOP_OneSelected
299 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
300 : AIS_SOP_Error;
301}
302
303//=======================================================================
304//function : ShiftSelect
305//purpose :
306//=======================================================================
307AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
308{
309 Standard_Integer aDetIndex = DetectedIndex();
310 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
311
312 if(aDetIndex > 0)
313 {
314 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
315 Standard_Integer aSelNum = AIS_Selection::Extent();
316 const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (aDetIndex);
317 Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True;
318 AIS_Selection::Select (anOwner);
319 anOwner->SetSelected (toSelect);
7fd59977 320
679ecdee 321 if(myAutoHilight)
322 {
63d907e7 323 myMainPM->ClearImmediateDraw();
7fd59977 324 const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
679ecdee 325 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
326 {
c398b00e 327 Unhilight (anOwner, aViewer->ActiveView());
679ecdee 328 }
329
330 // advanced selection highlighting mechanism
c398b00e 331 if (!anOwner->IsAutoHilight() && anOwner->HasSelectable())
679ecdee 332 {
c398b00e 333 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
679ecdee 334 UpdateSelected (anIO, Standard_False);
7fd59977 335 }
336
c398b00e 337 if (toUpdateViewer)
679ecdee 338 {
7fd59977 339 myCTX->CurrentViewer()->Update();
679ecdee 340 }
7fd59977 341 }
c398b00e 342
7fd59977 343 Standard_Integer NS = AIS_Selection::Extent();
344 if( NS == 1 ) return AIS_SOP_OneSelected;
345 else if( NS > 1 ) return AIS_SOP_SeveralSelected;
c398b00e 346 return aSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
7fd59977 347 }
348 return AIS_SOP_Error;
349}
c398b00e 350
351//=======================================================================
352//function : ShiftSelect
353//purpose :
354//=======================================================================
355AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const Standard_Integer theXPMin,
356 const Standard_Integer theYPMin,
357 const Standard_Integer theXPMax,
358 const Standard_Integer theYPMax,
359 const Handle(V3d_View)& theView,
360 const Standard_Boolean toUpdateViewer)
7fd59977 361{
679ecdee 362 myMainPM->ClearImmediateDraw();
363
c398b00e 364 if (theView->Viewer() == myCTX->CurrentViewer())
365 {
366 myMainVS->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
367
368 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
369 Standard_Integer aLastSelNum = AIS_Selection::Extent();
370
7fd59977 371 myMainVS->Init();
c398b00e 372 if (!myMainVS->More())
373 {
374 // Nothing is selected clear selection, but don't clear the selection
375 // as it is shift selection and previous selection matters.
376 // Return state to know if something was unselected
377 return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
378 }
7fd59977 379
c398b00e 380 if (myAutoHilight)
381 {
382 UnhilightPicked (Standard_False);
383 }
7fd59977 384
c398b00e 385 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
386 {
387 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
388 if(myFilters->IsOk (anOwner))
389 {
390 Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True;
391 AIS_Selection::Select (anOwner);
392 anOwner->SetSelected (toSelect);
7fd59977 393 }
394 }
c398b00e 395
396 if (myAutoHilight)
397 {
398 HilightPicked (toUpdateViewer);
399 }
7fd59977 400 }
c398b00e 401
402 Standard_Integer aSelNum = AIS_Selection::Extent();
403
404 return (aSelNum == 1) ? AIS_SOP_OneSelected
405 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
406 : AIS_SOP_Error;
7fd59977 407}
408
409//==================================================
410// Function: Select
411// Purpose : Selection by polyline
412//==================================================
c398b00e 413AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
414 const Handle(V3d_View)& theView,
415 const Standard_Boolean toUpdateViewer)
7fd59977 416{
c398b00e 417 if (theView->Viewer() == myCTX->CurrentViewer())
418 {
419 myMainVS->Pick (thePolyline, theView);
420
421 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
422
423 Standard_Integer aLastSelNum = AIS_Selection::Extent();
7fd59977 424 myMainVS->Init();
c398b00e 425 if(!myMainVS->More())
426 {
427 // Nothing is selected clear selection, but don't clear the selection
428 // as it is shift selection and previous selection matters.
429 // Return state to know if something was unselected
430 return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
7fd59977 431 }
432
c398b00e 433 if (myAutoHilight)
434 {
435 UnhilightPicked (Standard_False);
7fd59977 436 }
437
c398b00e 438 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
439 {
440 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
441 if (myFilters->IsOk (anOwner))
442 {
443 Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True;
444 AIS_Selection::Select (anOwner);
445 anOwner->SetSelected (toSelect);
446 }
447 }
448 if (myAutoHilight)
449 {
450 HilightPicked (toUpdateViewer);
451 }
7fd59977 452 }
7fd59977 453
c398b00e 454 Standard_Integer aSelNum = AIS_Selection::Extent();
455
456 return (aSelNum == 1) ? AIS_SOP_OneSelected
457 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
458 : AIS_SOP_Error;
7fd59977 459}
460
461//==================================================
679ecdee 462// Function: Hilight
7fd59977 463// Purpose :
464//==================================================
679ecdee 465void AIS_LocalContext::Hilight (const Handle(SelectMgr_EntityOwner)& theOwner,
466 const Handle(V3d_View)& theView)
7fd59977 467{
679ecdee 468 if (theView.IsNull())
469 {
470 return;
471 }
7fd59977 472
679ecdee 473 const Standard_Integer aHilightMode = GetHiMod (Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()));
474 myMainPM->BeginImmediateDraw();
475 theOwner->HilightWithColor (myMainPM, myCTX->HilightColor(), aHilightMode);
476 myMainPM->EndImmediateDraw (theView);
7fd59977 477}
478
479//==================================================
679ecdee 480// Function: Unhilight
7fd59977 481// Purpose :
482//==================================================
679ecdee 483void AIS_LocalContext::Unhilight (const Handle(SelectMgr_EntityOwner)& theOwner,
484 const Handle(V3d_View)& theView)
7fd59977 485{
679ecdee 486 if (theView.IsNull())
487 {
488 return;
489 }
7fd59977 490
679ecdee 491 const Standard_Integer aHilightMode = GetHiMod (Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()));
492 if (IsSelected (theOwner))
7fd59977 493 {
679ecdee 494 if (theOwner->IsAutoHilight())
495 {
496 theOwner->HilightWithColor (myMainPM, myCTX->SelectionColor(), aHilightMode);
497 }
498 }
499 else
500 {
501 theOwner->Unhilight (myMainPM, aHilightMode);
7fd59977 502 }
7fd59977 503}
504
505//=======================================================================
506//function : HilightPicked
507//purpose :
508//=======================================================================
509void AIS_LocalContext::HilightPicked(const Standard_Boolean updateviewer)
510{
7fd59977 511 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
7fd59977 512 if( Sel.IsNull() ) return;
7fd59977 513
e3a6386d 514 typedef NCollection_DataMap <Handle(SelectMgr_SelectableObject), NCollection_Handle<SelectMgr_SequenceOfOwner> > SelectMgr_DataMapOfObjectOwners;
7fd59977 515 SelectMgr_DataMapOfObjectOwners aMap;
e3a6386d 516
517 Handle (PrsMgr_PresentationManager3d) PM = myMainPM;
7fd59977 518
81bba717 519 // to avoid problems when there is a loop searching for selected objects...
7fd59977 520 const AIS_NListTransient& Obj = Sel->Objects();
521 AIS_NListTransient::Iterator anIter( Obj );
522 for(; anIter.More(); anIter.Next())
523 {
524 const Handle(Standard_Transient)& Tr = anIter.Value();
7fd59977 525 if(!Tr.IsNull()){
526 const Handle(SelectMgr_EntityOwner)& Ownr =
527 *((const Handle(SelectMgr_EntityOwner)*) &Tr);
528 Handle(AIS_InteractiveObject) IO;
529 if(Ownr->HasSelectable()){
530 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr);
531 if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){
532 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
533 IO = *((Handle(AIS_InteractiveObject)*)&SO);
7fd59977 534 }
7fd59977 535 }
7fd59977 536 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
537 Standard_Integer HM = GetHiMod(*((Handle(AIS_InteractiveObject)*)&SO));
538 if ( Ownr->IsAutoHilight() )
539 Ownr->HilightWithColor(PM,myCTX->SelectionColor(),HM);
540 else if ( aMap.IsBound (SO) )
e3a6386d 541 aMap(SO)->Append ( Ownr );
7fd59977 542 else {
e3a6386d 543 NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq = new SelectMgr_SequenceOfOwner;
544 aSeq->Append ( Ownr );
7fd59977 545 aMap.Bind ( SO, aSeq );
546 }
547 }
548 }
549
e3a6386d 550 for ( SelectMgr_DataMapOfObjectOwners::Iterator aMapIter(aMap);
7fd59977 551 aMapIter.More(); aMapIter.Next() )
e3a6386d 552 {
553 aMapIter.Key()->HilightSelected (myMainPM, *aMapIter.Value());
554 }
7fd59977 555
679ecdee 556 if (updateviewer)
557 {
558 myCTX->CurrentViewer()->Update();
7fd59977 559 }
560}
561
562//==================================================
563// Function:
564// Purpose :
565//==================================================
679ecdee 566void AIS_LocalContext::UnhilightPicked (const Standard_Boolean updateviewer)
7fd59977 567{
679ecdee 568 myMainPM->ClearImmediateDraw();
569
7fd59977 570 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
7fd59977 571 if( Sel.IsNull() ) return;
7fd59977 572 Handle (PrsMgr_PresentationManager3d) PM = myMainPM;
e3a6386d 573 NCollection_Map<Handle(SelectMgr_SelectableObject)> anObjMap;
7fd59977 574
7fd59977 575 const AIS_NListTransient& Obj = Sel->Objects();
576 AIS_NListTransient::Iterator anIter( Obj );
577 for(; anIter.More(); anIter.Next()){
578 const Handle(Standard_Transient)& Tr = anIter.Value();
7fd59977 579 if(!Tr.IsNull()){
580 const Handle(SelectMgr_EntityOwner)& Ownr =
581 *((const Handle(SelectMgr_EntityOwner)*) &Tr);
582 Standard_Integer HM(0);
583 if(Ownr->HasSelectable()){
7fd59977 584 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
585 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&SO);
e3a6386d 586 anObjMap.Add (IO);
7fd59977 587
e3a6386d 588 HM = GetHiMod(IO);
7fd59977 589 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr);
590 if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){
7fd59977 591 }
7fd59977 592 }
593 Ownr->Unhilight(PM,HM);
594 }
595 }
596
e3a6386d 597 for (NCollection_Map<Handle(SelectMgr_SelectableObject)>::Iterator anIter1 ( anObjMap );
7fd59977 598 anIter1.More(); anIter1.Next() )
e3a6386d 599 {
7fd59977 600 if ( !anIter1.Key()->IsAutoHilight() )
601 anIter1.Key()->ClearSelected();
e3a6386d 602 }
7fd59977 603
bcf50875 604 if(updateviewer)
7fd59977 605 myCTX->CurrentViewer()->Update();
7fd59977 606}
607
608//=======================================================================
609//function : IsSelected
610//purpose :
611//=======================================================================
612Standard_Boolean AIS_LocalContext::IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
613{
614 return (!FindSelectedOwnerFromIO(anIObj).IsNull());
615}
616
617//=======================================================================
618//function : IsSelected
619//purpose :
620//=======================================================================
621
c398b00e 622Standard_Boolean AIS_LocalContext::IsSelected (const Handle(SelectMgr_EntityOwner)& theOwner) const
7fd59977 623{
c398b00e 624 return !theOwner.IsNull() && theOwner->IsSelected();
7fd59977 625}
626
627//==================================================
628// Function:
629// Purpose :
630//==================================================
631void AIS_LocalContext::
632InitSelected()
633{
634 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
635 AIS_Selection::CurrentSelection()->Init();
636}
637
638//==================================================
639// Function:
640// Purpose :
641//==================================================
642Standard_Boolean AIS_LocalContext::
643MoreSelected() const
644{
645 return AIS_Selection::CurrentSelection()->More();
646}
647
648//==================================================
649// Function:
650// Purpose :
651//==================================================
652void AIS_LocalContext::
653NextSelected()
654{
655 AIS_Selection::CurrentSelection()->Next();
656}
657
658//==================================================
659// Function:
660// Purpose :
661//==================================================
662Standard_Boolean AIS_LocalContext::
663HasShape() const
664{
665 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
666 if( Tr.IsNull() ) return Standard_False;
667 Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
668 Handle(StdSelect_BRepOwner) BRO = Handle(StdSelect_BRepOwner)::DownCast(EO);
669 if(BRO.IsNull()) return Standard_False;
670 Standard_Boolean hasshape = BRO->HasShape();
671 Standard_Boolean comes = BRO->ComesFromDecomposition();
672 return (hasshape&&comes);
673}
674
51023771 675//================================================================
676// Function : HasSelectedShape
677// Purpose : Checks if there is a selected shape regardless of its decomposition status
678//================================================================
679Standard_Boolean AIS_LocalContext::HasSelectedShape() const
680{
681 if (AIS_Selection::CurrentSelection()->Extent() == 0)
682 return Standard_False;
683
684 Handle(Standard_Transient) aCurSelection = AIS_Selection::CurrentSelection()->Value();
685 if (aCurSelection.IsNull())
686 return Standard_False;
687
688 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (aCurSelection);
689 Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
690 if (aBrepOwner.IsNull())
691 {
692 return Standard_False;
693 }
694 return aBrepOwner->HasShape();
695}
696
7fd59977 697//==================================================
698// Function:
699// Purpose :
700//==================================================
0717ddc1 701TopoDS_Shape AIS_LocalContext::SelectedShape() const
7fd59977 702{
d8110103 703 Handle(Standard_Transient) aTr = AIS_Selection::CurrentSelection()->Value();
704 Handle(SelectMgr_EntityOwner) anEO = *((Handle(SelectMgr_EntityOwner)*)&aTr);
705 Handle(StdSelect_BRepOwner) aBRO = Handle(StdSelect_BRepOwner)::DownCast(anEO);
706 if( aBRO.IsNull() )
7fd59977 707 {
d8110103 708 return TopoDS_Shape();
7fd59977 709 }
51023771 710
d8110103 711 return aBRO->Shape().Located (aBRO->Location() * aBRO->Shape().Location());
7fd59977 712}
713
714//==================================================
715// Function:
716// Purpose :
717//==================================================
718Handle(AIS_InteractiveObject) AIS_LocalContext::
719SelectedInteractive() const
720{
721 Handle(AIS_InteractiveObject) IO;
722 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
723 if( !Tr.IsNull() ) {
724 Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
725 Handle(SelectMgr_SelectableObject) SO;
726 if(EO->HasSelectable()){
727 SO = EO->Selectable();
728 IO = *((Handle(AIS_InteractiveObject)*)&SO);
729 }
730 }
731 return IO;
732}
733//==================================================
734// Function:
735// Purpose :
736//==================================================
737Handle(SelectMgr_EntityOwner) AIS_LocalContext::
738SelectedOwner() const
739{
740 Handle(SelectMgr_EntityOwner) EO;
741 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
742 if( !Tr.IsNull() )
743 EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
744 return EO;
745}
746
747//==================================================
748// Function:
749// Purpose :
750//==================================================
751Standard_Boolean AIS_LocalContext::
752HasApplicative() const
753{
754 Handle(AIS_InteractiveObject) IO = SelectedInteractive();
755 if( IO.IsNull() ) return Standard_False;
756 return IO->HasOwner();
757}
758
759//==================================================
760// Function:
761// Purpose :
762//==================================================
763const Handle(Standard_Transient)& AIS_LocalContext::
764SelectedApplicative() const
765{
766 return SelectedInteractive()->GetOwner();
767}
768
769
770
771//=======================================================================
772//function : UpdateSelection
81bba717 773//purpose : should disappear...
7fd59977 774//=======================================================================
775void AIS_LocalContext::UpdateSelected(const Standard_Boolean updateviewer)
776{
777 UnhilightPicked(Standard_False);
778 HilightPicked(updateviewer);
779}
780
781//================================================================
782// Function : UpdateSelected
783// Purpose : Part of advanced selection mechanism.
784// Highlightes or clears selection presentation for the given IO
785//================================================================
786void AIS_LocalContext::UpdateSelected(const Handle(AIS_InteractiveObject)& anobj,
787 const Standard_Boolean updateviewer)
788{
789 if (anobj.IsNull() || anobj->IsAutoHilight())
790 return;
791
792 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
793 Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection();
794
795 SelectMgr_SequenceOfOwner aSeq;
796 for ( Sel->Init(); Sel->More(); Sel->Next() ){
797 Handle(SelectMgr_EntityOwner) aOwner = Handle(SelectMgr_EntityOwner)::DownCast(Sel->Value());
798
799 if ( !aOwner.IsNull() && aOwner->HasSelectable() && aOwner->Selectable() == anobj )
800 aSeq.Append( aOwner );
801 }
802
803 if ( aSeq.Length() )
804 anobj->HilightSelected( myMainPM, aSeq );
805 else
806 anobj->ClearSelected();
807
808 if(updateviewer){
809 myCTX->CurrentViewer()->Update();
810 }
811}
812
813//==================================================
814// Function: ClearSelected
815// Purpose :
816//==================================================
c398b00e 817void AIS_LocalContext::ClearSelected (const Standard_Boolean updateviewer)
7fd59977 818{
819 UnhilightPicked(updateviewer);
820 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
821
822 Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection();
7fd59977 823 const AIS_NListTransient& Obj = Sel->Objects();
824 AIS_NListTransient::Iterator anIter( Obj );
825 for(; anIter.More(); anIter.Next()){
826 const Handle(Standard_Transient)& Tr = anIter.Value();
c398b00e 827 if(!Tr.IsNull())
828 {
829 (*((const Handle(SelectMgr_EntityOwner)*)&Tr))->SetSelected (Standard_False);
7fd59977 830 }
831 }
832 AIS_Selection::Select();
833 mylastindex = 0;
834}
835
fb4b684a 836//==================================================
bc677575 837// Function: ClearOutdatedSelection
fb4b684a 838// Purpose :
839//==================================================
bc677575 840void AIS_LocalContext::ClearOutdatedSelection (const Handle(AIS_InteractiveObject)& theIO,
841 const Standard_Boolean toClearDeactivated)
fb4b684a 842{
bc677575 843 // 1. Collect selectable entities
844 SelectMgr_IndexedMapOfOwner aValidOwners;
845
846 const TColStd_ListOfInteger& aModes = SelectionModes (theIO);
847
848 TColStd_ListIteratorOfListOfInteger aModeIter (aModes);
849 for (; aModeIter.More(); aModeIter.Next())
850 {
851 int aMode = aModeIter.Value();
852 if (!theIO->HasSelection(aMode))
853 {
854 continue;
855 }
856
857 if (toClearDeactivated && !mySM->IsActivated (theIO, myMainVS, aMode))
858 {
859 continue;
860 }
861
862 Handle(SelectMgr_Selection) aSelection = theIO->Selection(aMode);
863 for (aSelection->Init(); aSelection->More(); aSelection->Next())
864 {
865 Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive();
866 if (anEntity.IsNull())
867 {
868 continue;
869 }
870
871 Handle(SelectMgr_EntityOwner) anOwner =
872 Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
873
874 if (anOwner.IsNull())
875 {
876 continue;
877 }
878
879 aValidOwners.Add(anOwner);
880 }
881 }
882
883 // 2. Refresh context's detection and selection and keep only active owners
fb4b684a 884 // Keep last detected object for lastindex initialization.
885 Handle(SelectMgr_EntityOwner) aLastPicked = myMainVS->OnePicked();
886
bc677575 887 // Remove entity owners from detected sequences
888 for (Standard_Integer anIdx = 1; anIdx <= myDetectedSeq.Length(); ++anIdx)
fb4b684a 889 {
bc677575 890 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (anIdx));
891 if (anOwner.IsNull() || anOwner->Selectable() != theIO || aValidOwners.Contains (anOwner))
fb4b684a 892 {
bc677575 893 continue;
894 }
895
896 myDetectedSeq.Remove (anIdx--);
897
898 if (anIdx < myCurDetected)
899 {
900 myCurDetected--;
fb4b684a 901 }
902 }
bc677575 903 myCurDetected = Max (myCurDetected, 1);
fb4b684a 904
bc677575 905 Standard_Boolean isAISRemainsDetected = Standard_False;
fb4b684a 906
bc677575 907 // 3. Remove entity owners from AIS_Selection
908 const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
fb4b684a 909 Handle(AIS_Selection) aSelection = AIS_Selection::Selection (mySelName.ToCString());
910 AIS_NListTransient::Iterator anIter (aSelection->Objects());
911 AIS_NListTransient aRemoveEntites;
912 for (; anIter.More(); anIter.Next())
913 {
914 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anIter.Value());
915 if (anOwner.IsNull() || anOwner->Selectable() != theIO)
916 {
917 continue;
918 }
919
bc677575 920 if (aValidOwners.Contains (anOwner))
921 {
922 isAISRemainsDetected = Standard_True;
923 }
fb4b684a 924
bc677575 925 aRemoveEntites.Append (anOwner);
926 anOwner->SetSelected (Standard_False);
927 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
fb4b684a 928 {
bc677575 929 Unhilight (anOwner, aViewer->ActiveView());
fb4b684a 930 }
931 }
bc677575 932
fb4b684a 933 AIS_NListTransient::Iterator anIterRemove (aRemoveEntites);
934 for (; anIterRemove.More(); anIterRemove.Next())
935 {
936 aSelection->Select (anIterRemove.Value());
937 }
938
bc677575 939 // 4. Remove entity owners from myMapOfOwner
fb4b684a 940 SelectMgr_IndexedMapOfOwner anOwnersToKeep;
fb4b684a 941 for (Standard_Integer anIdx = 1; anIdx <= myMapOfOwner.Extent(); anIdx++)
942 {
943 Handle(SelectMgr_EntityOwner) anOwner = myMapOfOwner (anIdx);
944 if (anOwner.IsNull())
945 {
946 continue;
947 }
948
bc677575 949 if (anOwner->Selectable() != theIO || aValidOwners.Contains (anOwner))
fb4b684a 950 {
951 anOwnersToKeep.Add (anOwner);
952 }
953 else
954 {
955 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
956 {
957 Unhilight (anOwner, aViewer->ActiveView());
958 }
959 }
960 }
961 myMapOfOwner.Clear();
962 myMapOfOwner.Assign (anOwnersToKeep);
963 mylastindex = myMapOfOwner.FindIndex (aLastPicked);
63d907e7 964 if (!IsValidIndex (mylastindex))
965 {
966 myMainPM->ClearImmediateDraw();
967 }
fb4b684a 968
bc677575 969 if (!isAISRemainsDetected)
fb4b684a 970 {
bc677575 971 // Remove the interactive object from detected sequences
972 for (Standard_Integer anIdx = 1; anIdx <= myAISDetectedSeq.Length(); ++anIdx)
973 {
974 Handle(AIS_InteractiveObject) aDetectedIO = myAISDetectedSeq.Value (anIdx);
975 if (aDetectedIO.IsNull() || aDetectedIO != theIO)
976 {
977 continue;
978 }
979
980 myAISDetectedSeq.Remove (anIdx--);
981
982 if (anIdx < myAISCurDetected)
983 {
984 myAISCurDetected--;
985 }
986 }
987 myAISCurDetected = Max (myAISCurDetected, 1);
fb4b684a 988 }
989}
7fd59977 990
991//=======================================================================
992//function : SetSelected
993//purpose :
994//=======================================================================
995void AIS_LocalContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,
996 const Standard_Boolean updateviewer)
997{
998 if(!IsValidForSelection(anIObj)) return;
999 UnhilightPicked(Standard_False);
1000
81bba717 1001 //1st case, owner already <anIObj> as owner
1002 // and not separated is found...
7fd59977 1003
1004 Handle(AIS_Selection) sel = AIS_Selection::Selection(mySelName.ToCString());
1005 //Standard_Boolean found(Standard_False);
1006 Handle(Standard_Transient) Tr;
1007 Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromIO(anIObj);
1008 if(EO.IsNull()){
81bba717 1009 //check if in selection number 0 there is an owner that can be triturated...
7fd59977 1010 if(anIObj->HasSelection(0)){
1011 const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
1012 SIOBJ->Init();
1013 if(SIOBJ->More()){
1014 Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId();
1015 EO = *((Handle(SelectMgr_EntityOwner)*)&BO);
1016 }
1017 }
1018 if(EO.IsNull())
1019 EO = new SelectMgr_EntityOwner(anIObj);
1020 }
1021
1022 ClearSelected(Standard_False);
c398b00e 1023
7fd59977 1024 AIS_Selection::Select(EO);
c398b00e 1025 EO->SetSelected (Standard_True);
1026
7fd59977 1027 HilightPicked(updateviewer);
1028}
1029
1030//=======================================================================
1031//function : AddOrRemoveSelected
1032//purpose :
1033//=======================================================================
1034
1035void AIS_LocalContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
1036 const Standard_Boolean updateviewer)
1037{
1038 if(!IsValidForSelection(anIObj)) return;
1039 UnhilightPicked(Standard_False);
81bba717 1040 // first check if it is selected...
7fd59977 1041 Handle(SelectMgr_EntityOwner) EO;
1042
1043 EO = FindSelectedOwnerFromIO(anIObj);
c398b00e 1044
1045 if (EO.IsNull())
1046 {
1047 if(anIObj->HasSelection(0))
1048 {
7fd59977 1049 const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
1050 SIOBJ->Init();
c398b00e 1051 if(SIOBJ->More())
1052 {
1053 Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId();
1054 EO = *((Handle(SelectMgr_EntityOwner)*)&BO);
7fd59977 1055 }
1056 }
c398b00e 1057 if(EO.IsNull())
1058 {
7fd59977 1059 EO = new SelectMgr_EntityOwner(anIObj);
c398b00e 1060 }
7fd59977 1061 }
1062
1063// cout<<"AIS_LocalContext::AddOrRemoveSelected : Selection = "<<mySelName<<endl;
1064 const Handle(AIS_Selection)& S = AIS_Selection::Selection(mySelName.ToCString());
c398b00e 1065
1066 if (!S.IsNull())
1067 {
7fd59977 1068 AIS_SelectStatus aStatus = S->Select(EO);
c398b00e 1069 EO->SetSelected (aStatus == AIS_SS_Added);
7fd59977 1070 }
c398b00e 1071
7fd59977 1072 HilightPicked(updateviewer);
1073}
1074
1075//=======================================================================
1076//function : AddOrRemoveSelected
81bba717 1077//purpose : To check...
7fd59977 1078//=======================================================================
1079void AIS_LocalContext::AddOrRemoveSelected(const TopoDS_Shape& Sh,
1080 const Standard_Boolean updateviewer)
1081{
c398b00e 1082 UnhilightPicked (Standard_False);
7fd59977 1083 Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromShape(Sh);
c398b00e 1084 if (!EO.IsNull())
1085 {
7fd59977 1086 AIS_Selection::Selection(mySelName.ToCString())->Select(EO);
c398b00e 1087 EO->SetSelected (Standard_True);
7fd59977 1088 }
c398b00e 1089 HilightPicked (updateviewer);
7fd59977 1090}
1091
c398b00e 1092void AIS_LocalContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
1093 const Standard_Boolean toUpdateViewer)
1094{
7fd59977 1095 if(myAutoHilight)
c398b00e 1096 {
1097 UnhilightPicked (Standard_False);
1098 }
7fd59977 1099
c398b00e 1100 Standard_Boolean toSelect = theOwner->IsSelected() ? Standard_False : Standard_True;
1101
1102 AIS_Selection::Selection (mySelName.ToCString())->Select (theOwner);
1103 theOwner->SetSelected (toSelect);
7fd59977 1104
7fd59977 1105 if(myAutoHilight)
c398b00e 1106 {
1107 HilightPicked (toUpdateViewer);
1108 }
7fd59977 1109}
1110
1111//==================================================
679ecdee 1112// Function: manageDetected
7fd59977 1113// Purpose :
1114//==================================================
679ecdee 1115void AIS_LocalContext::manageDetected (const Handle(SelectMgr_EntityOwner)& thePickOwner,
1116 const Handle(V3d_View)& theView,
1117 const Standard_Boolean theToRedrawImmediate)
7fd59977 1118{
679ecdee 1119 if (thePickOwner.IsNull())
1120 {
63d907e7 1121 myMainPM->ClearImmediateDraw();
679ecdee 1122 if (theToRedrawImmediate)
1123 {
1124 theView->RedrawImmediate();
1125 }
1126 return;
1127 }
7fd59977 1128
679ecdee 1129 if (!myFilters->IsOk (thePickOwner))
1130 {
1131 if (mylastindex != 0)
1132 {
1133 mylastgood = mylastindex;
1134 }
1135 if (theToRedrawImmediate)
1136 {
1137 theView->RedrawImmediate();
1138 }
1139 return;
1140 }
7fd59977 1141
679ecdee 1142 //=======================================================================================================
1143 // 2 cases : a- object is in the map of picks:
1144 // 1. this is the same index as the last detected: -> Do nothing
1145 // 2. otherwise :
1146 // - if lastindex = 0 (no object was detected at the last step)
1147 // the object presentation is highlighted and lastindex = index(objet)
1148 // - othrwise :
1149 // the presentation of the object corresponding to lastindex is "unhighlighted"
1150 // it is removed if the object is not visualized but only active
1151 // then the presentation of the detected object is highlighted and lastindex = index(objet)
1152 // b- the object is not in the map of picked objects
1153 // - if lastindex != 0 (object detected at the last step) it is unhighlighted ...
1154 // if the object was decomposed, presentation is created for the detected shape and the couple
1155 // (Proprietaire,Prs)is added in the map.
1156 // otherwise the couple(proprietaire, NullPrs) is placed in the map and the interactive object
1157 // itself is highlighted.
1158 //
1159 //=======================================================================================================
1160
1161 const Standard_Integer aNewIndex = myMapOfOwner.Contains (thePickOwner)
1162 ? myMapOfOwner.FindIndex (thePickOwner)
1163 : myMapOfOwner.Add (thePickOwner);
1164
1165 // For the advanced mesh selection mode the owner indices comparison
1166 // is not effective because in that case only one owner manage the
1167 // selection in current selection mode. It is necessary to check the current detected
1168 // entity and hilight it only if the detected entity is not the same as
1169 // previous detected (IsForcedHilight call)
1170 if (aNewIndex != mylastindex
1171 || thePickOwner->IsForcedHilight())
1172 {
63d907e7 1173 myMainPM->ClearImmediateDraw();
679ecdee 1174 if (mylastindex != 0
1175 && mylastindex <= myMapOfOwner.Extent())
1176 {
1177 const Handle(SelectMgr_EntityOwner)& aLastOwner = myMapOfOwner (mylastindex);
1178 Unhilight (aLastOwner, theView);
1179 }
7fd59977 1180
679ecdee 1181 if (myAutoHilight)
1182 {
c398b00e 1183 if (!thePickOwner->IsSelected() || myCTX->ToHilightSelected())
679ecdee 1184 {
1185 Hilight (thePickOwner, theView);
7fd59977 1186 }
679ecdee 1187 if (theToRedrawImmediate)
1188 {
1189 theView->RedrawImmediate();
7fd59977 1190 }
7fd59977 1191 }
679ecdee 1192
1193 mylastindex = aNewIndex;
7fd59977 1194 }
1195
63d907e7 1196 if (mylastindex != 0)
679ecdee 1197 {
1198 mylastgood = mylastindex;
1199 }
7fd59977 1200}
1201
7fd59977 1202//=======================================================================
1203//function : HasDetectedShape
1204//purpose :
1205//=======================================================================
1206
1207Standard_Boolean AIS_LocalContext::HasDetectedShape() const
1208{
1209 if(mylastindex==0) return Standard_False;
1210 return IsShape(mylastindex);
1211}
1212
1213//=======================================================================
1214//function : DetectedShape
1215//purpose :
1216//=======================================================================
1217
1218const TopoDS_Shape&
1219AIS_LocalContext::DetectedShape() const
1220{
1221 static TopoDS_Shape bidsh;
1222 if(mylastindex != 0)
1223 {
1224 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner(mylastindex));
1225 if(BROwnr.IsNull()) return bidsh;
1226 return BROwnr->Shape();
1227 }
1228 return bidsh;
1229}
1230
1231//=======================================================================
1232//function : DetectedInteractive
1233//purpose :
1234//=======================================================================
1235
1236Handle(AIS_InteractiveObject)
1237AIS_LocalContext::DetectedInteractive() const
1238{
1239 Handle(AIS_InteractiveObject) Iobj;
1240 if(IsValidIndex(mylastindex)){
1241 Handle(SelectMgr_SelectableObject) SO = myMapOfOwner.FindKey(mylastindex)->Selectable();
1242 Iobj = *((Handle(AIS_InteractiveObject)*) &SO);
1243 }
1244 return Iobj;
1245}
1246//=======================================================================
1247//function : DetectedInteractive
1248//purpose :
1249//=======================================================================
1250Handle(SelectMgr_EntityOwner) AIS_LocalContext::DetectedOwner() const
1251{
1252 Handle(SelectMgr_EntityOwner) bid;
1253 if(!IsValidIndex(mylastindex)) return bid;
1254 return myMapOfOwner.FindKey(mylastindex);
1255}
1256
1257
1258//=======================================================================
1259//function : ComesFromDecomposition
1260//purpose :
1261//=======================================================================
1262
1263Standard_Boolean AIS_LocalContext::ComesFromDecomposition(const Standard_Integer PickedIndex) const
1264{
1265 const Handle(SelectMgr_EntityOwner)& OWN = myMapOfOwner.FindKey(PickedIndex);
1266 Handle(SelectMgr_SelectableObject) aSel = OWN->Selectable();
81bba717 1267 if (myActiveObjects.IsBound (aSel)) { // debug of jmi
7fd59977 1268 const Handle(AIS_LocalStatus)& Stat = myActiveObjects(aSel);
1269 return Stat->Decomposed();
1270 }
1271 return Standard_False;
1272}
1273
1274
1275//=======================================================================
1276//function : DisplayAreas
1277//purpose :
1278//=======================================================================
1279
1280void AIS_LocalContext::DisplayAreas(const Handle(V3d_View)& aviou)
1281{
1282 myMainVS->DisplayAreas(aviou);
1283}
1284
1285//=======================================================================
1286//function : ClearAreas
1287//purpose :
1288//=======================================================================
1289
1290void AIS_LocalContext::ClearAreas(const Handle(V3d_View)& aviou)
1291{
1292 myMainVS->ClearAreas(aviou);
1293}
1294
1295//=======================================================================
1296//function : DisplaySensitive
1297//purpose :
1298//=======================================================================
1299
1300void AIS_LocalContext::DisplaySensitive(const Handle(V3d_View)& aviou)
1301{
1302 myMainVS->DisplaySensitive(aviou);
1303}
1304
1305//=======================================================================
1306//function : ClearSensitive
1307//purpose :
1308//=======================================================================
1309
1310void AIS_LocalContext::ClearSensitive(const Handle(V3d_View)& aviou)
1311{
1312 myMainVS->ClearSensitive(aviou);
1313}
1314
1315
1316//=======================================================================
1317//function : IsShape
1318//purpose :
1319//=======================================================================
1320Standard_Boolean AIS_LocalContext::IsShape(const Standard_Integer Index) const
1321{
1322
1323 if(Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner.FindKey(Index)).IsNull())
1324 return Standard_False;
1325 return
1326 ComesFromDecomposition(Index);
1327}
1328
1329Standard_Boolean AIS_LocalContext::IsValidForSelection(const Handle(AIS_InteractiveObject)& anIObj) const
1330{
1331
7fd59977 1332 // Shape was not transfered from AIS_Shape to EntityOwner
1333 Handle(AIS_Shape) shape = Handle(AIS_Shape)::DownCast(anIObj);
1334 if( !shape.IsNull() )
1335 return myFilters->IsOk(new StdSelect_BRepOwner(shape->Shape(),shape));
7fd59977 1336 return myFilters->IsOk(new SelectMgr_EntityOwner(anIObj));
1337}
1338
1339
1340//=======================================================================
1341//function : HilightNextDetected
679ecdee 1342//purpose :
7fd59977 1343//=======================================================================
679ecdee 1344Standard_Integer AIS_LocalContext::HilightNextDetected (const Handle(V3d_View)& theView,
1345 const Standard_Boolean theToRedrawImmediate)
7fd59977 1346{
81bba717 1347 // go to the next owner
679ecdee 1348 if (myDetectedSeq.IsEmpty())
1349 {
1350 return 0;
1351 }
7fd59977 1352
679ecdee 1353 const Standard_Integer aLen = myDetectedSeq.Length();
1354 if (++myCurDetected > aLen)
1355 {
7fd59977 1356 myCurDetected = 1;
7fd59977 1357 }
bc677575 1358 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected));
679ecdee 1359 if (anOwner.IsNull())
1360 {
1361 return 0;
1362 }
1363 manageDetected (anOwner, theView, theToRedrawImmediate);
7fd59977 1364 return myCurDetected;
1365}
1366
1367//=======================================================================
1368//function : HilightPreviousDetected
679ecdee 1369//purpose :
7fd59977 1370//=======================================================================
679ecdee 1371Standard_Integer AIS_LocalContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1372 const Standard_Boolean theToRedrawImmediate)
7fd59977 1373{
679ecdee 1374 if (myDetectedSeq.IsEmpty())
1375 {
1376 return 0;
1377 }
7fd59977 1378
4ca4bbe8 1379 const Standard_Integer aLen = myDetectedSeq.Length();
679ecdee 1380 if (--myCurDetected < 1)
1381 {
4ca4bbe8 1382 myCurDetected = aLen;
679ecdee 1383 }
bc677575 1384 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected));
679ecdee 1385 if (anOwner.IsNull())
1386 {
1387 return 0;
7fd59977 1388 }
1389
679ecdee 1390 manageDetected (anOwner, theView, theToRedrawImmediate);
7fd59977 1391 return myCurDetected;
1392}
1393
1394//=======================================================================
1395//function : UnhilightLastDetected
679ecdee 1396//purpose :
7fd59977 1397//=======================================================================
679ecdee 1398Standard_Boolean AIS_LocalContext::UnhilightLastDetected (const Handle(V3d_View)& theView)
7fd59977 1399{
679ecdee 1400 if (!IsValidIndex (mylastindex))
1401 {
1402 return Standard_False;
7fd59977 1403 }
7fd59977 1404
679ecdee 1405 myMainPM->BeginImmediateDraw();
1406 const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (mylastindex);
1407 const Standard_Integer aHilightMode = anOwner->HasSelectable()
1408 ? GetHiMod (Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()))
1409 : 0;
7fd59977 1410
679ecdee 1411 myMapOfOwner (mylastindex)->Unhilight (myMainPM, aHilightMode);
1412 myMainPM->EndImmediateDraw (theView);
1413 mylastindex = 0;
1414 return Standard_True;
7fd59977 1415}
1416
1417//=======================================================================
1418//function : FindSelectedOwnerFromIO
81bba717 1419//purpose : it is checked if one of the selected owners really presents IObj
7fd59977 1420//=======================================================================
1421Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromIO
1422 (const Handle(AIS_InteractiveObject)& anIObj) const
1423{
1424 Handle(SelectMgr_EntityOwner) EO,bid;
1425 if (anIObj.IsNull()) return EO;
1426
1427 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
1428 if(Sel.IsNull()) {
0797d9d3 1429#ifdef OCCT_DEBUG
7fd59977 1430 cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection "
1431 <<mySelName<<" Nulle "<<endl;
1432#endif
1433 return EO;
1434 }
1435 Standard_Boolean found(Standard_False);
7fd59977 1436 const AIS_NListTransient& Obj = Sel->Objects();
1437 AIS_NListTransient::Iterator anIter( Obj );
1438 for(; anIter.More(); anIter.Next()){
1439 const Handle(Standard_Transient)& Tr = anIter.Value();
7fd59977 1440 if(!Tr.IsNull()){
1441 EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
1442 if(EO->HasSelectable()){
1443 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO);
1444 if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){
1445 if (anIObj == EO->Selectable()){
1446 found =Standard_True;
1447 break;
1448 }
1449 }
1450 }
1451 }
1452 }
1453 if(found) return EO;
1454 return bid;
1455}
1456
1457//=======================================================================
1458//function : FindSelectedOwnerFromShape
81bba717 1459//purpose : it is checked if one of the selected owners really presents IObj
7fd59977 1460//=======================================================================
1461Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromShape(const TopoDS_Shape& sh) const
1462{
7fd59977 1463 Handle(SelectMgr_EntityOwner) EO, bid;
7fd59977 1464 if (sh.IsNull()) return EO;
1465
1466 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
1467 if(Sel.IsNull()) {
0797d9d3 1468#ifdef OCCT_DEBUG
7fd59977 1469 cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection "<<mySelName<<" Nulle "<<endl;
1470#endif
1471 return EO;
1472 }
1473
1474 Standard_Boolean found(Standard_False);
1475
7fd59977 1476 if (!found) {
7fd59977 1477 SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive aSensitiveIt (myMainVS->Primitives());
1478 for (; aSensitiveIt.More(); aSensitiveIt.Next()) {
1479 EO = Handle(SelectMgr_EntityOwner)::DownCast (aSensitiveIt.Value()->OwnerId());
1480 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO);
1481 if (!BROwnr.IsNull() && BROwnr->HasShape() && BROwnr->Shape() == sh) {
1482 found = Standard_True;
1483 break;
1484 }
1485 }
1486 }
7fd59977 1487
1488 if(found) return EO;
1489 return bid;
1490}
1491
7fd59977 1492//=======================================================================
1493//function : AIS_LocalContext::InitDetected
1494//purpose :
1495//=======================================================================
7fd59977 1496void AIS_LocalContext::InitDetected()
1497{
1498 myAISCurDetected = myAISDetectedSeq.Length()? 1 : 0;
1499}
1500
1501//=======================================================================
1502//function : AIS_LocalContext::MoreDetected
1503//purpose :
1504//=======================================================================
7fd59977 1505Standard_Boolean AIS_LocalContext::MoreDetected() const
1506{
1507 return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length());
1508}
1509
7fd59977 1510//=======================================================================
1511//function : AIS_LocalContext::NextDetected
1512//purpose :
1513//=======================================================================
7fd59977 1514void AIS_LocalContext::NextDetected()
1515{
57ad5cbd 1516 myAISCurDetected++;
7fd59977 1517}
1518
1519//=======================================================================
1520//function : DetectedCurrentShape
1521//purpose :
1522//=======================================================================
7fd59977 1523const TopoDS_Shape& AIS_LocalContext::DetectedCurrentShape() const
1524{
57ad5cbd 1525 static TopoDS_Shape aDummyShape;
7fd59977 1526
57ad5cbd 1527 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1528
1529 if (aCurrentShape.IsNull())
1530 {
1531 return aDummyShape;
1532 }
1533
1534 return aCurrentShape->Shape();
1535}
7fd59977 1536//=======================================================================
1537//function : DetectedCurrentObject
1538//purpose :
1539//=======================================================================
7fd59977 1540Handle(AIS_InteractiveObject) AIS_LocalContext::DetectedCurrentObject() const
1541{
57ad5cbd 1542 return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL;
7fd59977 1543}