3 // S3569 //Gestion des zones cachantes
5 #define G002 //GG_140400
6 // Manage highlighting.
8 #include <Graphic2d_HidingGraphicObject.ixx>
9 #include <Graphic2d_Vertex.hxx>
12 #define BASE_PRIORITY 1000
13 #define MAX_PRIORITY 999
14 #define MAX_POINTS 1024
16 Graphic2d_HidingGraphicObject::Graphic2d_HidingGraphicObject
17 (const Handle(Graphic2d_View)& aView,
18 const Graphic2d_Array1OfVertex& aFrame) :
19 Graphic2d_GraphicObject(aView) ,
20 myXmin(RealLast()),myYmin(RealLast()),myXmax(RealFirst()),myYmax(RealFirst())
24 SetHidingColorIndex();
31 Graphic2d_HidingGraphicObject::Graphic2d_HidingGraphicObject
32 (const Handle(Graphic2d_View)& aView,
33 const Graphic2d_TypeOfFrame aType,
34 const Quantity_Length aMargin1,
35 const Quantity_Length aMargin2) :
36 Graphic2d_GraphicObject(aView),
37 myXmin(RealLast()),myYmin(RealLast()),myXmax(RealFirst()),myYmax(RealFirst())
40 SetFrame(aType,aMargin1,aMargin2);
41 SetHidingColorIndex();
48 void Graphic2d_HidingGraphicObject::SetFrame(const Graphic2d_Array1OfVertex& aFrame) {
49 static Graphic2d_Vertex v;
50 Standard_Integer l = aFrame.Length();
53 myFrame = new Graphic2d_HArray1OfVertex(1,l);
54 for( Standard_Integer i=1,j=aFrame.Lower() ; i<=l ; i++,j++) {
55 v = aFrame.Value(j); v.Coord(x,y);
56 myXmin = Min(myXmin,x); myYmin = Min(myYmin,y);
57 myXmax = Max(myXmax,x); myYmax = Max(myYmax,y);
58 myFrame->SetValue(i,v);
60 myTypeOfFrame = Graphic2d_TOF_UNKNOWN;
61 myIsComputed = Standard_True;
64 void Graphic2d_HidingGraphicObject::SetFrame(
65 const Graphic2d_TypeOfFrame aType,
66 const Quantity_Length aMargin1,
67 const Quantity_Length aMargin2) {
69 myTypeOfFrame = aType;
70 myFrameMargin1 = aMargin1;
71 myFrameMargin2 = aMargin2;
72 if( myTypeOfFrame != Graphic2d_TOF_UNKNOWN )
73 myIsComputed = Standard_False;
74 else myIsComputed = Standard_True;
77 void Graphic2d_HidingGraphicObject::SetHidingColorIndex(const Standard_Integer anIndex) {
78 myHidingColorIndex = anIndex;
81 void Graphic2d_HidingGraphicObject::SetFrameColorIndex(const Standard_Integer anIndex) {
82 myFrameColorIndex = anIndex;
85 void Graphic2d_HidingGraphicObject::SetFrameTypeIndex(const Standard_Integer anIndex) {
86 myFrameTypeIndex = anIndex;
89 void Graphic2d_HidingGraphicObject::SetFrameWidthIndex(const Standard_Integer anIndex) {
90 myFrameWidthIndex = anIndex;
93 Standard_Integer Graphic2d_HidingGraphicObject::BasePriority () const {
99 Standard_Integer Graphic2d_HidingGraphicObject::MaxPriority () const {
105 void Graphic2d_HidingGraphicObject::Draw (const Handle(Graphic2d_Drawer)& aDrawer, const Standard_Boolean Reset) {
107 if( !IsDrawable() ) return;
109 if( !IsDisplayed() && !IsHighlighted() ) return;
111 if( !myIsUpToDate || !myIsComputed ) {
112 static Graphic2d_Vertex v;
114 Graphic2d_GraphicObject::MinMax(myXmin,myXmax,myYmin,myYmax);
116 if( myIsComputed ) switch (myTypeOfFrame) {
117 case Graphic2d_TOF_RECTANGULAR :
118 myXmin -= myFrameMargin1; myYmin -= myFrameMargin2;
119 myXmax += myFrameMargin1; myYmax += myFrameMargin2;
120 if( myFrame.IsNull() || (myFrame->Length() != 4) ) {
121 myFrame = new Graphic2d_HArray1OfVertex(1,4);
123 v.SetCoord(myXmin,myYmin);
124 myFrame->SetValue(1,v);
125 v.SetCoord(myXmin,myYmax);
126 myFrame->SetValue(2,v);
127 v.SetCoord(myXmax,myYmax);
128 myFrame->SetValue(3,v);
129 v.SetCoord(myXmax,myYmin);
130 myFrame->SetValue(4,v);
132 case Graphic2d_TOF_CIRCULAR :
134 Standard_ShortReal precis,coef,radius;
135 radius = Standard_ShortReal(Sqrt( (myXmax - myXmin) * (myXmax - myXmin) +
136 (myYmax - myYmin) * (myYmax - myYmin) ) / 2.);
137 radius += Standard_ShortReal(myFrameMargin1);
138 Standard_ShortReal x0 = Standard_ShortReal((myXmax + myXmin)/2.);
139 Standard_ShortReal y0 = Standard_ShortReal((myYmax + myYmin)/2.);
140 myXmin = x0 - radius;
141 myYmin = y0 - radius;
142 myXmax = x0 + radius;
143 myYmax = y0 + radius;
144 Aspect_TypeOfDeflection type;
145 aDrawer->DrawPrecision(precis,coef,type);
146 if( type == Aspect_TOD_RELATIVE) {
147 precis = radius * coef;
149 Standard_ShortReal value = Standard_ShortReal(Standard_PI/4.);
150 if( radius > precis )
151 value = Standard_ShortReal(Max( 0.0044 ,
152 Min (0.7854 , 2. * ACos(1.-precis/radius))));
153 Standard_Integer n = Min(MAX_POINTS,
154 Standard_Integer(2.*Standard_PI/value)+2);
155 Standard_ShortReal da = Standard_ShortReal(2.*Standard_PI/n);
156 Standard_ShortReal cosin = Standard_ShortReal(Cos(da));
157 Standard_ShortReal x1 = radius;
158 Standard_ShortReal y1 = 0.;
159 Standard_ShortReal x2 = radius * cosin;
160 Standard_ShortReal y2 = Standard_ShortReal(radius * Sin(da));
161 Standard_ShortReal x,y;
163 if( myFrame.IsNull() || (myFrame->Length() != n) ) {
164 myFrame = new Graphic2d_HArray1OfVertex(1,n);
166 v.SetCoord(x0+x1,y0+y1);
167 myFrame->SetValue(1,v);
168 v.SetCoord(x0+x2,y0+y2);
169 myFrame->SetValue(2,v);
170 for (Standard_Integer i=3; i<=n; i++) {
171 x = Standard_ShortReal(2.*x2*cosin - x1); x1 = x2; x2 = x;
172 y = Standard_ShortReal(2.*y2*cosin - y1); y1 = y2; y2 = y;
173 v.SetCoord(x0+x,y0+y);
174 myFrame->SetValue(i,v);
183 myXmin = myYmin = RealLast();
184 myXmax = myYmax = RealFirst();
188 if( !myFrame.IsNull() && (myXmax > myXmin) && (myYmax > myYmin) ) {
189 Standard_Real xmin,ymin,xmax,ymax;
190 Standard_Boolean transform = Standard_False;
192 xmin = myXmin; ymin = myYmin;
193 xmax = myXmax; ymax = myYmax;
194 if( IsTransformed() ) {
195 transform = Standard_True;
196 theTrsf = Transform();
197 TransformMinMax(theTrsf,xmin,xmax,ymin,ymax);
201 Standard_ShortReal(xmin), Standard_ShortReal(xmax),
202 Standard_ShortReal(ymin),Standard_ShortReal(ymax)) ) {
203 if( IsHighlighted() ) {
204 aDrawer->SetOverride ( Standard_True );
205 aDrawer->SetOverrideColor ( myOverrideColor );
207 aDrawer->SetOffSet ( myOffSet );
210 aDrawer->SetHidingPolyAttrib (myHidingColorIndex,
211 myFrameColorIndex,myFrameTypeIndex,myFrameWidthIndex);
214 Standard_Integer i,l = myFrame->Length(),mode = l;
215 for( i=1 ; i<=l ; i++ ) {
216 (myFrame->Value(i)).Coord(x,y);
218 theTrsf.Transforms(x,y);
220 if( i >= l ) mode = -1;
222 cout << " Graphic2d_HidingGraphicObject::Draw(" << x << "," << y << "," << mode << endl;
224 aDrawer->MapPolygonFromTo(Standard_ShortReal(x),
225 Standard_ShortReal(y),mode);
231 Graphic2d_GraphicObject::Draw(aDrawer,Reset);
234 void Graphic2d_HidingGraphicObject::Draw(const Handle_Graphic2d_Drawer& aDrawer, const Handle_Graphic2d_Primitive& aPrim)
236 Graphic2d_GraphicObject::Draw(aDrawer,aPrim);
239 Standard_Boolean Graphic2d_HidingGraphicObject::Pick (const Standard_Real X, const Standard_Real Y, const Standard_Real aPrecision, const Handle(Graphic2d_Drawer)& aDrawer) {
240 Standard_Boolean status = Standard_False;
245 if( IsPickable() && (IsDisplayed() || IsHighlighted()) ) {
248 Standard_Real xx = X, yy = Y;
249 Standard_Real xmin = myXmin - aPrecision;
250 Standard_Real ymin = myYmin - aPrecision;
251 Standard_Real xmax = myXmax + aPrecision;
252 Standard_Real ymax = myYmax + aPrecision;
253 if( IsTransformed() ) {
254 gp_GTrsf2d aTrsf = (Transform ()).Inverted ();
255 aTrsf.Transforms (xx, yy);
257 if( (xx > xmin) && (xx < xmax) &&
258 (yy > ymin) && (yy < ymax) ) {
259 switch (myTypeOfFrame) {
260 case Graphic2d_TOF_UNKNOWN :
261 status = (myFrame.IsNull()) ? Standard_False : Standard_True;
264 case Graphic2d_TOF_RECTANGULAR :
265 status = Standard_True;
268 case Graphic2d_TOF_CIRCULAR :
270 Standard_Real x = (xmin + xmax)/2.;
271 Standard_Real y = (ymin + ymax)/2.;
272 Standard_Real r = xmax - x;
273 if( Sqrt ((x - xx)*(x - xx) + (y - yy)*(y - yy)) < r )
274 status = Standard_True;
282 status = Graphic2d_GraphicObject::Pick(X,Y,aPrecision,aDrawer);
284 else SetPickedIndex(0);
291 Standard_Boolean Graphic2d_HidingGraphicObject::FrameMinMax (Quantity_Length & Minx, Quantity_Length &Maxx, Quantity_Length & Miny, Quantity_Length & Maxy) const {
292 Standard_Boolean status = Standard_False;
294 if( !myFrame.IsNull() && (myXmax > myXmin) && (myYmax > myYmin) ) {
295 Standard_Real xmin,ymin,xmax,ymax;
296 xmin = myXmin; ymin = myYmin;
297 xmax = myXmax; ymax = myYmax;
298 if( IsTransformed() ) {
299 gp_GTrsf2d theTrsf = Transform();
300 TransformMinMax(theTrsf,xmin,xmax,ymin,ymax);
302 status = Standard_True;
317 Standard_Boolean Graphic2d_HidingGraphicObject::MinMax (Quantity_Length & Minx, Quantity_Length &Maxx, Quantity_Length & Miny, Quantity_Length & Maxy) const {
319 Standard_Boolean status =
320 Graphic2d_GraphicObject::MinMax(Minx,Maxx,Miny,Maxy);
322 Standard_Real xmin,ymin,xmax,ymax;
323 if( this->FrameMinMax(xmin,ymin,xmax,ymax) ) {
325 Minx = Min(Minx,xmin);
326 Miny = Min(Miny,ymin);
327 Maxx = Min(Maxx,xmax);
328 Maxy = Min(Maxy,ymax);
330 status = Standard_True;
341 Graphic2d_TypeOfFrame Graphic2d_HidingGraphicObject::Frame( Graphic2d_Array1OfVertex& aFrame) const {
342 //Graphic2d_Vertex v;
345 aFrame = myFrame->Array1();
346 return myTypeOfFrame;
349 Standard_Integer Graphic2d_HidingGraphicObject::HidingColorIndex() const {
351 return myHidingColorIndex;
354 Standard_Integer Graphic2d_HidingGraphicObject::FrameColorIndex() const {
356 return myFrameColorIndex;
359 Standard_Integer Graphic2d_HidingGraphicObject::FrameTypeIndex() const {
361 return myFrameTypeIndex;
364 Standard_Integer Graphic2d_HidingGraphicObject::FrameWidthIndex() const {
366 return myFrameWidthIndex;
369 void Graphic2d_HidingGraphicObject::TransformMinMax (const gp_GTrsf2d& aTrsf,Standard_Real & Minx, Standard_Real &Maxx, Standard_Real & Miny, Standard_Real & Maxy) const {
371 Standard_Real xx,yy,xmin,ymin,xmax,ymax;
372 xmin = ymin = RealLast();
373 xmax = ymax = RealFirst();
375 xx = Minx; yy = Miny;
376 aTrsf.Transforms (xx,yy);
377 xmin = Min(xmin,xx) ;
379 xmax = Max(xmax,xx) ;
382 xx = Minx; yy = Maxy;
383 aTrsf.Transforms (xx,yy);
384 xmin = Min(xmin,xx) ;
386 xmax = Max(xmax,xx) ;
389 xx = Maxx; yy = Maxy;
390 aTrsf.Transforms (xx,yy);
391 xmin = Min(xmin,xx) ;
393 xmax = Max(xmax,xx) ;
396 xx = Maxx; yy = Miny;
397 aTrsf.Transforms (xx,yy);
398 Minx = Min(xmin,xx) ;
400 Maxx = Max(xmax,xx) ;