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