Replacing french comments by english one
[occt.git] / src / SelectMgr / SelectMgr_ViewerSelector.cxx
CommitLineData
7fd59977 1// Copyright: Matra-Datavision 1995
2// File: SelectMgr_ViewerSelector.cxx
3// Created: Wed Feb 15 13:54:24 1995
4// Author: Roberc Coublanc
5// <rob>
6// Modified by ...
7// ROB JAN/07/98 : Improve Storage of detected entities
8// AGV OCT/23/03 : Optimize the method SortResult() (OCC4201)
9
10#include <SelectMgr_ViewerSelector.ixx>
11#include <SelectMgr_CompareResults.hxx>
12#include <gp_Pnt2d.hxx>
13#include <gp_Pnt.hxx>
14#include <gp_Lin.hxx>
15#include <Bnd_HArray1OfBox2d.hxx>
16#include <Bnd_Array1OfBox2d.hxx>
17#include <Precision.hxx>
18#include <TColStd_Array1OfInteger.hxx>
19#include <TCollection_AsciiString.hxx>
20#include <SelectBasics_ListIteratorOfListOfBox2d.hxx>
21#include <SelectBasics_SensitiveEntity.hxx>
22#include <SelectBasics_EntityOwner.hxx>
23#include <SelectBasics_ListOfBox2d.hxx>
24#include <SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive.hxx>
25#include <SelectMgr_DataMapIteratorOfDataMapOfSelectionActivation.hxx>
26#include <SelectMgr_SortCriterion.hxx>
27#include <Select3D_SensitiveEntity.hxx>
28#include <SortTools_QuickSortOfInteger.hxx>
29#include <OSD_Environment.hxx>
30
31static Standard_Boolean SelectDebugModeOnVS()
32{
33 static Standard_Integer isDebugMode( -1 );
34 if ( isDebugMode < 0 ) {
35 isDebugMode = 1;
36 OSD_Environment selectdb("SELDEBUGMODE");
37 if ( selectdb.Value().IsEmpty() )
38 isDebugMode = 0;
39 }
40 return ( isDebugMode != 0 );
41}
42
43//==================================================
44// Function: Initialize
45// Purpose :
46//==================================================
47SelectMgr_ViewerSelector::SelectMgr_ViewerSelector():
48toupdate(Standard_True),
49tosort(Standard_True),
50preferclosest(Standard_True),
51mytolerance(0.),
52myCurRank(0),
53lastx (Precision::Infinite()),
54lasty (Precision::Infinite()),
55myUpdateSortPossible( Standard_True )
56{
57}
58
59
60//==================================================
61// Function: Activate
62// Purpose :
63//==================================================
64void SelectMgr_ViewerSelector::
65Activate (const Handle(SelectMgr_Selection)& aSelection,
66 const Standard_Boolean AutomaticProj)
67{
68 tosort = Standard_True;
69
70 if (!myselections.IsBound(aSelection))
71 {
72 myselections.Bind(aSelection,0);
73 }
74 else if (myselections(aSelection)!=0)
75 {
76 myselections(aSelection)= 0;
77 }
78 if(AutomaticProj)
79 Convert(aSelection);
80}
81
82
83//==================================================
84// Function: Deactivate
85// Purpose :
86//==================================================
87void SelectMgr_ViewerSelector::
88Deactivate (const Handle(SelectMgr_Selection)& aSel)
89{
90 if(myselections.IsBound(aSel))
91 {myselections(aSel)=1;
92 tosort = Standard_True;}
93}
94
95
96
97
98
99//==================================================
100// Function: Sleep
101// Purpose :
102//==================================================
103void SelectMgr_ViewerSelector::Sleep()
104{ SelectMgr_DataMapIteratorOfDataMapOfSelectionActivation It(myselections);
105for (;It.More();It.Next()){
106 if(It.Value()==0) myselections(It.Key())= 2;
107}
108UpdateSort();
109}
110//=======================================================================
111//function : Sleep
112//purpose :
113//=======================================================================
114
115void SelectMgr_ViewerSelector::Sleep(const Handle(SelectMgr_SelectableObject)& SO)
116{
117
118 for(SO->Init();SO->More();SO->Next()){
119 if(myselections.IsBound(SO->CurrentSelection())){
120 myselections(SO->CurrentSelection()) = 2;
121 }
122 }
123 UpdateSort();
124}
125
126
127//==================================================
128// Function: Awake
129// Purpose :
130//==================================================
131void SelectMgr_ViewerSelector::Awake(const Standard_Boolean AutomaticProj)
132{
133 SelectMgr_DataMapIteratorOfDataMapOfSelectionActivation It(myselections);
134 for (;It.More();It.Next()){
135 if(It.Value()==2)
136 myselections(It.Key())=0;
137 if(AutomaticProj)
138 UpdateConversion();
139 UpdateSort();
140 }
141}
142
143void SelectMgr_ViewerSelector::Awake(const Handle(SelectMgr_SelectableObject)& SO,
144 const Standard_Boolean AutomaticProj)
145{
146 for(SO->Init();SO->More();SO->Next()){
147 if(myselections.IsBound(SO->CurrentSelection())){
148 myselections(SO->CurrentSelection()) =0;
149 if(AutomaticProj)
150 Convert(SO->CurrentSelection());
151 }
152 }
153
154}
155//==================================================
156// Function: Clear
157// Purpose :
158//==================================================
159void SelectMgr_ViewerSelector::Clear()
160{
161 myentities.Clear();
162 myselections.Clear();
163 toupdate = Standard_True;
164 tosort = Standard_True;
165 mystored.Clear();
166 lastx = Precision::Infinite();
167 lasty = Precision::Infinite();
168
169}
170
171//==================================================
172// Function: UpdateConversion
173// Purpose :
174//==================================================
175void SelectMgr_ViewerSelector::UpdateConversion()
176{
177 if( SelectDebugModeOnVS() )
178 cout<<"\t\t\t\t\t SelectMgr_VS::UpdateConversion"<<endl;
179
180 SelectMgr_DataMapIteratorOfDataMapOfSelectionActivation It(myselections);
181 for(;It.More();It.Next()){
182 //Convert only if active...
183 if(It.Value()==0)
184 Convert(It.Key());
185 }
186 toupdate = Standard_False;
187 tosort = Standard_True;
188}
189
190
191//==================================================
192// Function: Convert
193// Purpose :
194//==================================================
195void SelectMgr_ViewerSelector::
196Convert (const Handle(SelectMgr_Selection)& /*aSel*/) {tosort=Standard_True;}
197
198
199//==================================================
200// Function: UpdateSort
201// Purpose :
202//==================================================
203void SelectMgr_ViewerSelector::UpdateSort()
204{
205 if( !myUpdateSortPossible )
206 return;
207
208 if( SelectDebugModeOnVS() )
209 cout<<"\t\t\t\t\t SelectMgr_ViewerSelector::UpdateSort()"<<endl;
210 mystored.Clear();
211 myentities.Clear();
212 myactivenb = NbBoxes();
213
214 if(myactivenb > 0) {
215 Standard_Boolean NoClip = myclip.IsVoid();
216 Handle(Bnd_HArray1OfBox2d) refToTab = new Bnd_HArray1OfBox2d(1,myactivenb);
217 Bnd_Array1OfBox2d & tab = refToTab->ChangeArray1();
218 Standard_Real xmin=Precision::Infinite(),ymin=Precision::Infinite(),xmax=-Precision::Infinite(),ymax=-Precision::Infinite();
219 Standard_Real curxmin,curymin,curxmax,curymax;
220 // Standard_Integer boxindex=0,indexsel=0,indexprim=0;
221 Standard_Integer boxindex=0;
222
223 SelectMgr_DataMapIteratorOfDataMapOfSelectionActivation It;
224 SelectBasics_ListIteratorOfListOfBox2d LIt;
225 Handle(SelectMgr_Selection) curEntity;
226 Standard_Real ScaleFactor;
227 for(It.Initialize(myselections);It.More();It.Next()){
228 if(It.Value()== 0)
229 { curEntity = It.Key();
230 for(curEntity->Init();curEntity->More();curEntity->Next())
231 {
232 static SelectBasics_ListOfBox2d BoxList;
233 BoxList.Clear();
234 curEntity->Sensitive()->Areas(BoxList);
235 ScaleFactor = curEntity->Sensitive()->SensitivityFactor();
236
237
238 for(LIt.Initialize(BoxList);LIt.More();LIt.Next()){
239 boxindex++;
240
241 tab.SetValue(boxindex,LIt.Value());
242
243 tab(boxindex).SetGap(mytolerance*ScaleFactor);
244 myentities.Bind(boxindex,curEntity->Sensitive());
245 if(NoClip){
246 if (!tab(boxindex).IsVoid()) {
247 tab(boxindex).Get(curxmin,curymin,curxmax,curymax);
248 if(curxmin<xmin) xmin=curxmin;
249 if(curxmax>xmax) xmax=curxmax;
250 if(curymin<ymin) ymin=curymin;
251 if(curymax>ymax) ymax=curymax;
252 }
253 }
254 }
255 }
256 }
257 }
258
259
260 if(NoClip) {myclip.SetVoid();myclip.Update(xmin,ymin,xmax,ymax);}
261 myselector.Initialize(myclip, mytolerance,refToTab);
262 tosort = Standard_False;
263 if(NoClip) myclip.SetVoid();
264 }
265}
266
267
268//==================================================
269// Function: Remove
270// Purpose :
271//==================================================
272void SelectMgr_ViewerSelector::
273Remove(const Handle(SelectMgr_Selection)& aSel)
274{
275 if (myselections.IsBound(aSel))
276 { myselections.UnBind(aSel);
277 tosort = Standard_True;
278 }
279}
280
281//==================================================
282// Function: SetSensitivity
283// Purpose :
284//==================================================
285void SelectMgr_ViewerSelector::SetSensitivity(const Standard_Real aVal)
286{mytolerance = aVal;
287tosort=Standard_True;}
288
289//==================================================
290// Function: SetClipping
291// Purpose :
292//==================================================
293void SelectMgr_ViewerSelector::SetClipping(const Standard_Real Xc,
294 const Standard_Real Yc,
295 const Standard_Real Height,
296 const Standard_Real Width)
297{
298 Bnd_Box2d aClip;
299 aClip.Set(gp_Pnt2d(Xc-Width/2, Yc-Height/2));
300 aClip.Add(gp_Pnt2d(Xc+Width/2, Yc+Height/2));
301 myclip = aClip;
302 tosort = Standard_True;
303}
304
305
306//==================================================
307// Function: SetClipping
308// Purpose :
309//==================================================
310void SelectMgr_ViewerSelector::SetClipping (const Bnd_Box2d& abox)
311{myclip = abox;
312tosort = Standard_True;
313}
314
315//==================================================
316// Function: InitSelect
317// Purpose :
318//==================================================
319void SelectMgr_ViewerSelector::InitSelect(const Standard_Real Xr,
320 const Standard_Real Yr)
321{
322 Standard_OutOfRange_Raise_if(Abs(Xr-Precision::Infinite())<=Precision::Confusion() ||
323 Abs(Yr-Precision::Infinite())<=Precision::Confusion(),
324 " Infinite values in IniSelect");
325 mystored.Clear();
326 myprim.Clear();
327 if (toupdate) UpdateConversion();
328 if (tosort) UpdateSort();
329 if(myactivenb!=0){
330 myselector.InitSelect(Xr,Yr);
331 if(myselector.More()) {lastx = Xr;lasty=Yr;}
332 LoadResult();
333 }
334}
335
336//==================================================
337// Function: InitSelect
338// Purpose :
339//==================================================
340void SelectMgr_ViewerSelector::InitSelect(const Bnd_Box2d& aBox)
341{
342 mystored.Clear();
343 if(toupdate) UpdateConversion();
344 if (tosort) UpdateSort();
345 if (myactivenb!=0){
346 myselector.InitSelect(aBox);
347 LoadResult(aBox);
348 }
349}
350
351//==================================================
352// Function: InitSelect
353// Purpose :
354//==================================================
355void SelectMgr_ViewerSelector::InitSelect(const Standard_Real Xmin,
356 const Standard_Real Ymin,
357 const Standard_Real Xmax,
358 const Standard_Real Ymax)
359{
360 mystored.Clear();
361
362 if (toupdate) UpdateConversion();
363 if (tosort) UpdateSort();
364 if (myactivenb!=0){
365 Bnd_Box2d aBox;
366 aBox.Update(Xmin,Ymin,Xmax,Ymax);
367 myselector.InitSelect(aBox);
368 LoadResult(aBox);
369 }
370}
371
372//==================================================
373// Function: InitSelect
374// Purpose : Polyline Selection
375//==================================================
376void SelectMgr_ViewerSelector::InitSelect(const TColgp_Array1OfPnt2d& aPoly)
377{
378 mystored.Clear();
379
380 if (toupdate) UpdateConversion();
381 if (tosort) UpdateSort();
382 if (myactivenb!=0){
81bba717 383 // the Bnd boxes are used for the first time
7fd59977 384 Bnd_Box2d aBox;
385 Standard_Integer NbPnt = aPoly.Length();
386 Standard_Integer i;
387 for(i=1;i<=NbPnt;i++) {
388 aBox.Update(aPoly(i).X(),aPoly(i).Y());
389 }
390 myselector.InitSelect(aBox);
391 LoadResult(aPoly);
392 // LoadResult(aBox);
393 }
394}
395
396
397//==================================================
398// Function: LoadResult
81bba717 399// Purpose : for the moment the size of the primitive
400// is not taken into account in the search criteriai...
401// The priority, the depth and the min. distance to CDG or Borders is taken...
7fd59977 402//==================================================
403void SelectMgr_ViewerSelector::
404LoadResult()
405{
406 // Handle(SelectMgr_EntityOwner) OWNR;
407 if(myselector.More())
408 {
409 // Standard_Boolean Found(Standard_False);
410 Standard_Real DMin;
411 Standard_Integer nument;
412 for(;myselector.More();myselector.Next()){
413 nument = myselector.Value();
414 const Handle(SelectBasics_SensitiveEntity)& SE = myentities(nument);
415 if (SE->Matches(lastx,lasty,mytolerance,DMin)) {
416 const Handle(SelectBasics_EntityOwner)& OWNR = SE->OwnerId();
417
418 if(!OWNR.IsNull()){
419 Standard_Real TheDepth = SE->Depth();
420 Standard_Integer Prior = OWNR->Priority();
421
422 SelectMgr_SortCriterion SC(Prior,TheDepth,DMin,mytolerance,preferclosest);
423 if ( mystored.Contains(OWNR) )
424 {
425 SelectMgr_SortCriterion& Crit = mystored.ChangeFromKey(OWNR);
426 if ( SC > Crit )
427 {
428 Crit = SC;
429
430 // update previously recorded entity for this owner
431 for (int i=1; i <= myprim.Length(); i++)
432 if (myentities(myprim(i))->OwnerId() == OWNR) {
433 myprim.SetValue (i, nument);
434 break;
435 }
436 }
437 }
438 else
439 {
440 mystored.Add(OWNR,SC);
441
442 // record entity
443 myprim.Append(nument);
444 }
445 }
446 }
447 }
448 SortResult();
449 }
450 if( SelectDebugModeOnVS() ){
451 cout<<"\tSelectMgr_VS:: Resultat du move"<<endl;
452 cout<<"\tNb Detectes :"<<mystored.Extent()<<endl;
453 for(Standard_Integer i=1;i<=mystored.Extent();i++){
454 const SelectMgr_SortCriterion& Crit = mystored(myIndexes->Value(i));
455 cout<<"\t"<<i<<" - Prior"<<Crit.Priority()<<" - prof :"<<Crit.Depth()<<" - Dist. :"<<Crit.MinDist()<<endl;
456 }
457 }
458}
459//==================================================
460// Function: LoadResult
461// Purpose :
462//==================================================
463void SelectMgr_ViewerSelector::LoadResult(const Bnd_Box2d& abox)
464{
465 mystored.Clear();
466
467 // Handle(SelectMgr_EntityOwner) OWNR;
468 if(myselector.More())
469 { Standard_Real xmin,ymin,xmax,ymax;
470 abox.Get(xmin,ymin,xmax,ymax);
471 // Standard_Boolean Found(Standard_False);
472 // Standard_Real DMin=0.;
473 Standard_Integer nument;
474 for(;myselector.More();myselector.Next()){
475 nument = myselector.Value();
476 const Handle(SelectBasics_SensitiveEntity)& SE = myentities(nument);
477 if (SE->Matches(xmin,ymin,xmax,ymax,0.0)){
478 const Handle(SelectBasics_EntityOwner)& OWNR = SE->OwnerId();
479 if(!OWNR.IsNull()){
480 if(!mystored.Contains(OWNR)){
481 SelectMgr_SortCriterion SC(OWNR->Priority(),Precision::Infinite(),
482 Precision::Infinite(),mytolerance,preferclosest);
483 mystored.Add(OWNR,SC);
484 myprim.Append(nument);
485 }
486 }
487 }
488 }
489
81bba717 490 // do not parse in case of selection by elastic rectangle (BUG ANALYST)
7fd59977 491 if(mystored.IsEmpty()) return;
492 if(myIndexes.IsNull())
493 myIndexes = new TColStd_HArray1OfInteger(1,mystored.Extent());
494 else if(mystored.Extent() !=myIndexes->Length())
495 myIndexes = new TColStd_HArray1OfInteger (1,mystored.Extent());
496
81bba717 497 // to work faster...
7fd59977 498 TColStd_Array1OfInteger& thearr = myIndexes->ChangeArray1();
499 for(Standard_Integer I=1;I<=mystored.Extent();I++)
500 thearr(I)=I;
501 }
502}
503//==================================================
504// Function: LoadResult
505// Purpose :
506//==================================================
507void SelectMgr_ViewerSelector::LoadResult(const TColgp_Array1OfPnt2d& aPoly)
508{
509 mystored.Clear();
510 Bnd_Box2d aBox;
511 Standard_Integer NbPnt = aPoly.Length();
512 Standard_Integer i;
513 for(i=1;i<=NbPnt;i++) {
514 aBox.Update(aPoly(i).X(),aPoly(i).Y());
515 }
516 Standard_Integer NB=0;
517 // Handle(SelectMgr_EntityOwner) OWNR;
518 if(myselector.More())
519 {
520 Standard_Integer nument;
521
522 for(;myselector.More();myselector.Next()){
523 NB++;
524 nument = myselector.Value();
525 const Handle(SelectBasics_SensitiveEntity)& SE = myentities(nument);
526 if (SE->Matches(aPoly,aBox,0.0)){
527 const Handle(SelectBasics_EntityOwner)& OWNR = SE->OwnerId();
528 if(!OWNR.IsNull()){
529 if(!mystored.Contains(OWNR)){
530 SelectMgr_SortCriterion SC(OWNR->Priority(),Precision::Infinite(),
531 Precision::Infinite(),mytolerance,preferclosest);
532 mystored.Add(OWNR,SC);
533 myprim.Append(nument);
534 }
535 }
536 }
537 }
538
539 if(mystored.IsEmpty()) return;
540 if(myIndexes.IsNull())
541 myIndexes = new TColStd_HArray1OfInteger(1,mystored.Extent());
542 else if(mystored.Extent() !=myIndexes->Length())
543 myIndexes = new TColStd_HArray1OfInteger (1,mystored.Extent());
544
81bba717 545 // to work faster...
7fd59977 546 TColStd_Array1OfInteger& thearr = myIndexes->ChangeArray1();
547 for(Standard_Integer I=1;I<=mystored.Extent();I++)
548 thearr(I)=I;
549 }
550}
551
552
553//==================================================
554// Function: HasStored
555// Purpose :
556//==================================================
557Standard_Boolean SelectMgr_ViewerSelector::
558HasStored ()
559{
560 if(Abs(lastx-Precision::Infinite())<=Precision::Confusion()) return Standard_False;
561 if(Abs(lasty-Precision::Infinite())<=Precision::Confusion()) return Standard_False;
562 InitSelect(lastx,lasty);
563 Init();
564 return More();
565}
566
567
568
569
570//==================================================
571// Function: Picked
572// Purpose :
573//==================================================
574Handle(SelectMgr_EntityOwner) SelectMgr_ViewerSelector
575::Picked() const
576{
577 Standard_Integer RankInMap = myIndexes->Value(myCurRank);
578 const Handle(SelectBasics_EntityOwner)& toto = mystored.FindKey(RankInMap);
579 Handle(SelectMgr_EntityOwner) Ownr = *((Handle(SelectMgr_EntityOwner)*) &toto);
580 return Ownr;
581}
582
583
584
585//=======================================================================
586//function : More
587//purpose :
588//=======================================================================
589Standard_Boolean SelectMgr_ViewerSelector::More()
590{
591 if(mystored.Extent()==0) return Standard_False;
592 if(myCurRank==0) return Standard_False;
593 return myCurRank <= myIndexes->Length();
594}
595
596//==================================================
597// Function: OnePicked
598// Purpose : only the best one is chosen
599// depend on priority and mindist...
600//==================================================
601
602Handle(SelectMgr_EntityOwner) SelectMgr_ViewerSelector
603::OnePicked()
604{
605
606 Init();
607 if(More()){
608 Standard_Integer RankInMap = myIndexes->Value(1);
609 const Handle(SelectBasics_EntityOwner)& toto = mystored.FindKey(RankInMap);
610 Handle(SelectMgr_EntityOwner) Ownr = *((Handle(SelectMgr_EntityOwner)*) &toto);
611 return Ownr;
612 }
613
614 Handle (SelectMgr_EntityOwner) NullObj; //returns a null Handle if there was not successfull pick...
615 return NullObj;
616}
617
618
619//=======================================================================
620//function : NbPicked
621//purpose :
622//=======================================================================
623
624Standard_Integer SelectMgr_ViewerSelector::NbPicked() const
625{
626 return mystored.Extent();
627}
628//=======================================================================
629//function : Picked
630//purpose :
631//=======================================================================
632Handle(SelectMgr_EntityOwner) SelectMgr_ViewerSelector::Picked(const Standard_Integer aRank) const
633{
634
635 Handle(SelectMgr_EntityOwner) Own;
636 if (aRank<1 || aRank>NbPicked())
637 return Own;
638 Standard_Integer Indx = myIndexes->Value(aRank);
639
640
641 const Handle(SelectBasics_EntityOwner)& toto = mystored.FindKey(Indx);
642 Own = *((Handle(SelectMgr_EntityOwner)*) &toto);
643 return Own;
644}
645//=======================================================================
646//function : Primitive
647//purpose :
648//=======================================================================
649Handle(SelectBasics_SensitiveEntity) SelectMgr_ViewerSelector::Primitive
650(const Standard_Integer /*Index*/) const
651{
652 return myentities(myprim(myCurRank));
653}
654
655
656//==================================================
657// Function: LastPosition
658// Purpose :
659//==================================================
660void SelectMgr_ViewerSelector::LastPosition(Standard_Real& Xlast,
661 Standard_Real& YLast) const
662{ Xlast = lastx;YLast = lasty;}
663
664
665
666//===================================================
667//
668// INTERNAL METHODS ....
669//
670//==================================================
671
672
673
674
675//==================================================
676// Function: NbBoxes
677// Purpose :
678//==================================================
679Standard_Integer SelectMgr_ViewerSelector::NbBoxes()
680{
681 SelectMgr_DataMapIteratorOfDataMapOfSelectionActivation It(myselections);
682 // Standard_Integer Nbb=0, first,last;
683 Standard_Integer Nbb=0;
684
685 for(;It.More();It.Next()){
686 if(It.Value()==0){
687 for(It.Key()->Init();It.Key()->More();It.Key()->Next())
688 {Nbb+= It.Key()->Sensitive()->MaxBoxes();}
689 }
690 }
691 return Nbb;
692}
693
694
695
696
697//==================================================
698// Function: Contains
699// Purpose :
700//==================================================
701Standard_Boolean SelectMgr_ViewerSelector::
702Contains(const Handle(SelectMgr_SelectableObject)& anObject) const
703{
704 for (anObject->Init();anObject->More();anObject->Next()){
705 if(myselections.IsBound(anObject->CurrentSelection()))
706 return Standard_True;
707 }
708 return Standard_False;
709}
710
711
712
713//==================================================
714// Function: ActiveModes
715// Purpose : return all the modes with a given state for an object
716//==================================================
717
718
719Standard_Boolean SelectMgr_ViewerSelector::
720Modes(const Handle(SelectMgr_SelectableObject)& SO,
721 TColStd_ListOfInteger& TheActiveList,
722 const SelectMgr_StateOfSelection WantedState) const
723{
724 Standard_Boolean Found= Standard_False;
725 for(SO->Init();SO->More();SO->Next()){
726 if(myselections.IsBound(SO->CurrentSelection())){
727 if(WantedState==SelectMgr_SOS_Any)
728 TheActiveList.Append(SO->CurrentSelection()->Mode());
729 else if( myselections(SO->CurrentSelection())==WantedState)
730 TheActiveList.Append(SO->CurrentSelection()->Mode());
731
732 if(!Found) Found=Standard_True;
733 }
734 }
735 return Found;
736}
737
738
739Standard_Boolean SelectMgr_ViewerSelector::
740IsActive(const Handle(SelectMgr_SelectableObject)& SO,
741 const Standard_Integer aMode) const
742{
743 for(SO->Init();SO->More();SO->Next()){
744 if(aMode==SO->CurrentSelection()->Mode()){
745 if(myselections.IsBound(SO->CurrentSelection()) &&
746 myselections(SO->CurrentSelection())==SelectMgr_SOS_Activated)
747 return Standard_True;
748 else return Standard_False;
749 }
750 }
751 return Standard_False;
752}
753
754
755Standard_Boolean SelectMgr_ViewerSelector::
756IsInside(const Handle(SelectMgr_SelectableObject)& SO,
757 const Standard_Integer aMode) const
758{
759 for(SO->Init();SO->More();SO->Next()){
760 if(aMode==SO->CurrentSelection()->Mode()){
761 if(myselections.IsBound(SO->CurrentSelection())) return Standard_True;
762 else return Standard_False;
763
764 }
765 }
766 return Standard_False;
767}
768
769
770//=======================================================================
771//function : Status
772//purpose :
773//=======================================================================
774
775SelectMgr_StateOfSelection SelectMgr_ViewerSelector::Status(const Handle(SelectMgr_Selection)& aSel) const
776{
777 if(!myselections.IsBound(aSel)) return SelectMgr_SOS_Unknown;
778 //JR/Hp
779 Standard_Integer ie = myselections(aSel) ;
780 return SelectMgr_StateOfSelection( ie );
781 // return SelectMgr_StateOfSelection(myselections(aSel));
782
783}
784
785
786
787//=======================================================================
788//function : Dump
789//purpose :
790//=======================================================================
791
792void SelectMgr_ViewerSelector::Dump(Standard_OStream& S) const
793{
794 S<<"=========================="<<endl;
795 S<<" SelectMgr_ViewerSelector "<<endl;
796 S<<"=========================="<<endl;
797 S<<" "<<endl;
798}
799
800
801
802//==================================================
803// Function: Status
804// Purpose : gives Information about selectors
805//==================================================
806
807TCollection_AsciiString SelectMgr_ViewerSelector::
808Status(const Handle(SelectMgr_SelectableObject)& SO) const
809{
81bba717 810 TCollection_AsciiString Status("Status Object :\n\t");
7fd59977 811 Standard_Boolean Found= Standard_False;
812 for(SO->Init();SO->More();SO->Next()){
813 if(myselections.IsBound(SO->CurrentSelection()))
814 {
815 Found = Standard_True;
816 Status = Status + "Mode " +
817 TCollection_AsciiString(SO->CurrentSelection()->Mode()) +
818 " present - " ;
819 if(myselections(SO->CurrentSelection()))
81bba717 820 Status = Status + " Active \n\t";
7fd59977 821 else
81bba717 822 Status = Status + " Inactive \n\t";
7fd59977 823 }
824 }
825
81bba717 826 if(!Found) Status = Status + "Not Present in the selector\n\n";
7fd59977 827 return Status;
828}
829
830
831TCollection_AsciiString SelectMgr_ViewerSelector::
832Status () const
833{
81bba717 834 // sevsitive primitives present
835 //-----------------------------
7fd59977 836 TCollection_AsciiString Status("\t\tSelector Status :\n\t");
81bba717 837 // selections
838 //-----------
7fd59977 839 Standard_Integer NbActive =0,NbPrim=0;
840 Status = Status + "Number of already computed selections : " +
841 TCollection_AsciiString(myselections.Extent());
842
843 SelectMgr_DataMapIteratorOfDataMapOfSelectionActivation It(myselections);
844 for(;It.More();It.Next())
845 {
846 if(It.Value()==0) {NbActive++;
847 for(It.Key()->Init();It.Key()->More();It.Key()->Next()){NbPrim++;}
848 }
849 }
850 Status = Status + " - " + TCollection_AsciiString(NbActive) + " activated ones\n\t";
851 Status = Status + "Number of active sensitive primitives : " +
852 TCollection_AsciiString(NbPrim)+"\n\t";
853 Status = Status + "Real stored Pick Tolerance : " + TCollection_AsciiString(mytolerance) +"\n\t";
854 if(toupdate) {
855 Status = Status + "\nWARNING : those informations will be obsolete for the next Pick\n"
856 +"to get the real status of the selector - make One pick and call Status again\n";
857 }
858 return Status;
859}
860
861//=======================================================================
862//function : SortResult
81bba717 863//purpose : there is a certain number of entities ranged by criteria
864// (depth, size, priority, mouse distance from borders or
865// CDG of the detected primitive. Parsing :
866// maximum priorities .
867// then a reasonable compromise between depth and distance...
868// finally the ranges are stored in myindexes depending on the parsing.
869// so, it is possible to only read
7fd59977 870//=======================================================================
871void SelectMgr_ViewerSelector::SortResult()
872{
873 if(mystored.IsEmpty()) return;
874
875 const Standard_Integer anExtent = mystored.Extent();
876 if(myIndexes.IsNull() || anExtent != myIndexes->Length())
877 myIndexes = new TColStd_HArray1OfInteger (1, anExtent);
878
81bba717 879 // to work faster...
7fd59977 880 TColStd_Array1OfInteger& thearr = myIndexes->ChangeArray1();
881
81bba717 882 // indices from 1 to N are loaded
7fd59977 883 Standard_Integer I ;
884 for (I=1; I <= anExtent; I++)
885 thearr(I)=I;
886
887 // OCC4201 (AGV): This loop is inefficient on large arrays, so I replace it
888 // with a standard sort algo
889 // // on trie suivant les criteres (i) (Owner) (SortCriterion)
890 // Standard_Boolean OKSort;
891 // Standard_Integer temp,indx,indx1;
892 // Standard_Integer tmprim;
893 // // merci lbr...
894 // do{
895 // OKSort =Standard_True;
896 // for(I=1;I<thearr.Length();I++){
897 // indx = thearr(I);
898 // indx1 = thearr(I+1);
899 // if(mystored(indx) < mystored(indx1)){
900 // OKSort = Standard_False;
901 //
902 // temp = thearr(I+1);
903 // thearr(I+1) = thearr (I);
904 // thearr(I) = temp;
905 //
906 // tmprim = myprim(I+1);
907 // myprim(I+1) = myprim(I);
908 // myprim(I) = tmprim;
909 //
910 // }
911 // }
912 // } while (OKSort==Standard_False);
913 //
914 // OCC4201 (AGV): debut
915
916 SortTools_QuickSortOfInteger::Sort (thearr,
917 SelectMgr_CompareResults(mystored));
918 TColStd_Array1OfInteger myPrimArr (1, myprim.Length());
919 for (I = 1; I <= myPrimArr.Length(); I++)
920 myPrimArr (I) = myprim (I);
921 for (I = 1; I <= thearr.Length(); I++) {
922 const Standard_Integer ind = thearr(I);
923 if (ind > 0 && ind <= myPrimArr.Upper())
924 myprim (I) = myPrimArr (ind);
925 }
926 // OCC4201 (AGV): fin
81bba717 927 // it is enough to return owners corresponding to parced indices...
7fd59977 928
929}
930
931
932//=======================================================================
933//function :
934//purpose :
935//=======================================================================
936Standard_Boolean SelectMgr_ViewerSelector::IsUpdateSortPossible() const
937{
938 return myUpdateSortPossible;
939}
940
941//=======================================================================
942//function :
943//purpose :
944//=======================================================================
945void SelectMgr_ViewerSelector::SetUpdateSortPossible( const Standard_Boolean possible )
946{
947 myUpdateSortPossible = possible;
948}