0022627: Change OCCT memory management defaults
[occt.git] / src / StdSelect / StdSelect_ViewerSelector2d.cxx
1 // Copyright:   Matra-Datavision 1995
2 // File:        StdSelect_ViewerSelector2d.cxx
3 // Created:     Thu Feb 23 17:10:14 1995
4 // Author:      Mister rmi
5 //              <rmi>
6
7
8
9 #include <StdSelect_ViewerSelector2d.ixx>
10 #include <Graphic2d_Array1OfVertex.hxx>
11 #include <Graphic2d_GraphicObject.hxx>
12 #include <SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive.hxx>
13 #include <Select2D_SensitiveEntity.hxx>
14 #include <StdSelect_TextProjector2d.hxx>
15 #include <SelectBasics_ListOfBox2d.hxx>
16 #include <Bnd_Box2d.hxx>
17 #include <Graphic2d_Vertex.hxx>
18 #include <Graphic2d_Polyline.hxx>
19 #include <Graphic2d_Array1OfVertex.hxx>
20 #include <SelectBasics_ListIteratorOfListOfBox2d.hxx>
21
22 //==================================================
23 // Function: 
24 // Purpose :
25 //==================================================
26
27 StdSelect_ViewerSelector2d::StdSelect_ViewerSelector2d():
28 mypixtol(2)
29 {}
30
31 StdSelect_ViewerSelector2d::StdSelect_ViewerSelector2d(const Handle(Select2D_Projector)& aPrj):
32 myprj(aPrj),
33 mypixtol(2)
34 {}
35
36 //==================================================
37 // Function: Set
38 // Purpose :
39 //==================================================
40
41 void StdSelect_ViewerSelector2d::Set(const Standard_Integer apixtol)
42 {mypixtol = apixtol;
43  tosort = Standard_True;
44 }
45
46 //==================================================
47 // Function: Set
48 // Purpose :
49 //==================================================
50
51 void StdSelect_ViewerSelector2d::Set(const Handle(Select2D_Projector)& aPrj)
52 {myprj = aPrj;
53  UpdateConversion();
54 }
55
56 //==================================================
57 // Function: Convert
58 // Purpose :
59 //==================================================
60
61 void StdSelect_ViewerSelector2d::Convert(const Handle(SelectMgr_Selection)& aSel) 
62 {
63   for(aSel->Init();aSel->More();aSel->Next())
64     {
65       if(aSel->Sensitive()->NeedsConversion()) 
66         Handle(Select2D_SensitiveEntity)::
67       DownCast(aSel->Sensitive())->Convert(myprj);
68     }
69   tosort = Standard_True;
70 }
71
72
73 void StdSelect_ViewerSelector2d::Pick(const Standard_Integer XPix,
74                                       const Standard_Integer YPix,
75                                       const Handle(V2d_View)& aViou)
76 {
77   Standard_Real Xr,Yr;
78   aViou->Convert(XPix,YPix,Xr,Yr);
79   InitSelect(Xr,Yr);
80 }
81
82
83
84 void StdSelect_ViewerSelector2d::Pick(const Standard_Integer XPMin,
85                                       const Standard_Integer YPMin,
86                                       const Standard_Integer XPMax,
87                                       const Standard_Integer YPMax,
88                                       const Handle(V2d_View)& aViou)
89 {
90   if(mypixtol!=0) mytolerance = aViou->Convert(mypixtol);
91   Standard_Real X1,Y1,X2,Y2;
92   aViou->Convert(XPMin,YPMin,X1,Y1);
93   aViou->Convert(XPMax,YPMax,X2,Y2);
94   InitSelect(Min(X1,X2),
95              Min(Y1,Y2),
96              Max(X1,X2),
97              Max(Y1,Y2));
98 }
99
100 //==================================================
101 // Function: DisplayAreas
102 // Purpose :
103 //==================================================
104 void StdSelect_ViewerSelector2d::
105 DisplayAreas(const Handle(V2d_View)& aViou)
106 {
107   mygo = new Graphic2d_GraphicObject(aViou->View());
108   
109   Graphic2d_Array1OfVertex Av1 (1,5);
110   SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive It(myentities);  
111   SelectBasics_ListOfBox2d BoxList;
112   Standard_Real xmin,ymin,xmax,ymax;
113   Handle(Graphic2d_Polyline) pol;
114
115   for(;It.More();It.Next())
116     {
117       It.Value()->Areas(BoxList);
118       // DEN 
119       SelectBasics_ListIteratorOfListOfBox2d anIterator(BoxList); 
120       for (;anIterator.More();anIterator.Next()) 
121         { 
122           anIterator.Value().Get(xmin,ymin,xmax,ymax); 
123
124       // FIN DEN 
125       // BY DEN BoxList.Last().Get(xmin,ymin,xmax,ymax); 
126       // construction des vertex graphiques 
127       Av1.SetValue(1,Graphic2d_Vertex(xmin-mytolerance,ymin-mytolerance)); 
128       Av1.SetValue(2,Graphic2d_Vertex(xmax+mytolerance,ymin-mytolerance)); 
129       Av1.SetValue(3,Graphic2d_Vertex(xmax+mytolerance,ymax+mytolerance)); 
130       Av1.SetValue(4,Graphic2d_Vertex(xmin-mytolerance,ymax+mytolerance)); 
131       Av1.SetValue(5,Graphic2d_Vertex(xmin-mytolerance,ymin-mytolerance)); 
132   
133       pol = new Graphic2d_Polyline(mygo,Av1); 
134       pol ->SetColorIndex(4); //vert 
135       pol->SetTypeIndex(2); 
136       // DEN 
137       } 
138     // FIN DEN 
139     }
140   mygo->Display();
141   aViou->Update();
142   
143 }
144
145 //================================================
146 // function : ClearAreas
147 // purpose  :
148 //================================================
149
150 void StdSelect_ViewerSelector2d::ClearAreas ()
151 {
152   if (mygo.IsNull()) return; 
153   mygo->RemovePrimitives(); 
154   mygo->Display();
155   mygo->Remove();
156 }
157
158