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