b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | #include <Prs2d_RadiusIndep.ixx> |
19 | |
20 | #define VERTEXMARKER 2 |
21 | #define DEFAULTMARKERSIZE 3.0 |
22 | |
23 | Prs2d_RadiusIndep::Prs2d_RadiusIndep( const Handle(Graphic2d_GraphicObject) & aGO, |
24 | const gp_Pnt2d & anAttachPnt, |
25 | const gp_Pnt2d & aCenter, |
26 | const Standard_Real aRad, |
27 | const TCollection_ExtendedString & aText, |
28 | const Standard_Real aLength, |
29 | const Prs2d_TypeOfRadius aTypeRad, |
30 | const Standard_Real aTxtScale ) |
31 | |
32 | : Graphic2d_Line( aGO ), |
33 | |
34 | myX1( Standard_ShortReal( anAttachPnt.X() ) ), |
35 | myY1( Standard_ShortReal( anAttachPnt.Y() ) ), |
36 | myX2( Standard_ShortReal( aCenter.X() ) ), |
37 | myY2( Standard_ShortReal( aCenter.Y() ) ), |
38 | myTextScale( Standard_ShortReal( aTxtScale ) ), |
39 | myText( aText ), |
40 | myXVert( 1, 3 ), |
41 | myYVert( 1, 3 ), |
42 | myIsSymbol( Standard_False ), |
43 | mySymbCode( 198 ), |
44 | myTextFont( 0 ), |
45 | mySymbFont( 0 ), |
46 | myAttPnt( anAttachPnt ), |
47 | myCenter( aCenter ), |
48 | myRadius( aRad ), |
49 | myLength( aLength ), |
50 | myRadType( aTypeRad ) |
51 | |
52 | { |
53 | gp_Vec2d theVec1( gp_Pnt2d( myX2, myY2 ), gp_Pnt2d( myX1, myY1 ) ); |
54 | gp_Vec2d theUnVec( 1., 0. ); |
55 | myTextAng = Standard_ShortReal( theUnVec.Angle( theVec1 ) ); |
56 | Standard_Real theLen = sqrt( (myX2-myX1)*(myX2-myX1) + (myY2-myY1)*(myY2-myY1) ); |
57 | gp_Vec2d VecAdd = theVec1.Normalized(); |
58 | theVec1.Normalize(); |
59 | theVec1 *= ( theLen + aLength ); |
60 | gp_Pnt2d P1 = aCenter.Translated( theVec1 ); |
61 | myTextX = Standard_ShortReal( P1.X() ); |
62 | myTextY = Standard_ShortReal( P1.Y() ); |
63 | gp_Pnt2d PArr( myX1, myY1 ); |
64 | |
65 | if ( ( theLen + aLength ) > theLen ) |
66 | myInside = Standard_False; |
67 | else |
68 | myInside = Standard_True; |
69 | |
70 | switch( aTypeRad ) { |
71 | default: |
72 | case Prs2d_TOR_STANDARD : { |
73 | |
74 | myX2 = Standard_ShortReal( P1.X() ); |
75 | myY2 = Standard_ShortReal( P1.Y() ); |
76 | if ( ( theLen + aLength ) > theLen ) { |
77 | theVec1.Reverse(); |
78 | } |
79 | } |
80 | break; |
81 | case Prs2d_TOR_CENTER : { |
82 | |
83 | if ( aLength > 0.0 ) { |
84 | myX1 = Standard_ShortReal( P1.X() ); |
85 | myY1 = Standard_ShortReal( P1.Y() ); |
86 | theVec1.Reverse(); |
87 | } |
88 | } |
89 | break; |
90 | case Prs2d_TOR_REVARROW : { |
91 | |
92 | myX2 = Standard_ShortReal( P1.X() ); |
93 | myY2 = Standard_ShortReal( P1.Y() ); |
94 | if ( ( theLen + aLength ) <= theLen ) |
95 | theVec1.Reverse(); |
96 | else |
97 | VecAdd.Reverse(); |
98 | Standard_Real Dt = sqrt( ( myX2 - myX1 )*( myX2 - myX1 ) + ( myY2 - myY1 )*( myY2 - myY1 ) ); |
99 | VecAdd *= Dt/2; |
100 | gp_Pnt2d PTmpn = PArr.Translated( VecAdd ); |
101 | myX1 = Standard_ShortReal( PTmpn.X() ); |
102 | myY1 = Standard_ShortReal( PTmpn.Y() ); |
103 | } |
104 | |
105 | break; |
106 | case Prs2d_TOR_CENTREV : { |
107 | |
108 | if ( aLength > 0.0 ) { |
109 | myX1 = Standard_ShortReal( P1.X() ); |
110 | myY1 = Standard_ShortReal( P1.Y() ); |
111 | } else { |
112 | theVec1.Reverse(); |
113 | Standard_Real Dt = sqrt( ( myX2 - myX1 )*( myX2 - myX1 ) + ( myY2 - myY1 )*( myY2 - myY1 ) ); |
114 | VecAdd *= Dt/2; |
115 | gp_Pnt2d PTmpn = PArr.Translated( VecAdd ); |
116 | myX1 = Standard_ShortReal( PTmpn.X() ); |
117 | myY1 = Standard_ShortReal( PTmpn.Y() ); |
118 | } |
119 | } |
120 | break; |
121 | } // end switch |
122 | |
123 | myMinX = myX1; |
124 | myMinY = myY1; |
125 | myMaxX = myX1; |
126 | myMaxY = myY1; |
127 | |
128 | if ( myX2 < myMinX ) myMinX = myX2; |
129 | if ( myY2 < myMinY ) myMinY = myY2; |
130 | if ( myX2 > myMaxX ) myMaxX = myX2; |
131 | if ( myY2 > myMaxY ) myMaxY = myY2; |
132 | |
c6541a0c |
133 | Standard_Real ArrANG = M_PI / 6., theArrLN = aRad/5., theANG; |
7fd59977 |
134 | gp_Pnt2d theOrig( 0., 0. ), P2, P3; |
135 | gp_Vec2d VX( 1., 0. ); |
136 | |
137 | P2 = gp_Pnt2d( theArrLN, theArrLN*Tan( ArrANG/2. ) ); |
138 | P3 = gp_Pnt2d( theArrLN, -theArrLN*Tan( ArrANG/2. ) ); |
139 | theVec1.Reverse(); |
140 | theANG = VX.Angle( theVec1 ); |
141 | P2.Rotate( theOrig, theANG ); |
142 | P3.Rotate( theOrig, theANG ); |
143 | |
144 | P2.Translate( gp_Vec2d( theOrig, PArr ) ); |
145 | P3.Translate( gp_Vec2d( theOrig, PArr ) ); |
146 | |
147 | myXVert(1) = Standard_ShortReal( P2.X() ); |
148 | myYVert(1) = Standard_ShortReal( P2.Y() ); |
149 | myXVert(2) = Standard_ShortReal( PArr.X() ); |
150 | myYVert(2) = Standard_ShortReal( PArr.Y() ); |
151 | myXVert(3) = Standard_ShortReal( P3.X() ); |
152 | myYVert(3) = Standard_ShortReal( P3.Y() ); |
153 | |
154 | for ( Standard_Integer i = 1; i <= 3; i++ ) { |
155 | |
156 | if ( myXVert(i) < myMinX ) myMinX = myXVert(i); |
157 | if ( myYVert(i) < myMinY ) myMinY = myYVert(i); |
158 | if ( myXVert(i) > myMaxX ) myMaxX = myXVert(i); |
159 | if ( myYVert(i) > myMaxY ) myMaxY = myYVert(i); |
160 | |
161 | } |
162 | } |
163 | |
164 | void Prs2d_RadiusIndep::Values(gp_Pnt2d& anAttPnt, |
165 | gp_Pnt2d& aCenter, |
166 | Standard_Real& aRad, |
167 | TCollection_ExtendedString& aText, |
168 | Standard_Real& aLength, |
169 | Prs2d_TypeOfRadius& aTypeRad, |
170 | Standard_Real& aTxtScale) const { |
171 | |
172 | anAttPnt = myAttPnt; |
173 | aCenter = myCenter; |
174 | aRad = myRadius; |
175 | aText = myText; |
176 | aLength = myLength; |
177 | aTypeRad = myRadType; |
178 | aTxtScale = myTextScale; |
179 | } |
180 | |
181 | void Prs2d_RadiusIndep::Draw( const Handle(Graphic2d_Drawer)& aDrawer ) { |
182 | |
183 | Standard_Boolean IsIn = Standard_False; |
184 | |
185 | if ( ! myGOPtr->IsTransformed() ) |
186 | IsIn = aDrawer->IsIn (myMinX,myMaxX,myMinY,myMaxY); |
187 | else { |
188 | Standard_ShortReal minx, miny, maxx, maxy; |
189 | MinMax(minx,maxx,miny,maxy); |
190 | IsIn = aDrawer->IsIn (minx,maxx,miny,maxy); |
191 | } |
192 | |
193 | if ( IsIn ) { |
194 | |
195 | DrawLineAttrib(aDrawer); |
196 | aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0, Standard_ShortReal( myTextScale*aDrawer->Scale() ), |
197 | Standard_ShortReal( myTextScale*aDrawer->Scale()), Standard_False ); |
198 | |
199 | Standard_ShortReal aWidth, aHeight; |
200 | aDrawer->GetTextSize( myText, aWidth, aHeight ); |
201 | Standard_ShortReal Xt = myTextX, Yt = myTextY; |
202 | if ( !myInside ) { |
203 | gp_Pnt2d P1( myX1, myY1 ), P2( myX2, myY2 ), |
204 | PT( myTextX, myTextY ), PTMP; |
205 | ( PT.IsEqual( P1, 0. ) ) |
206 | ? PTMP.SetCoord( P2.X(), P2.Y() ) |
207 | : PTMP.SetCoord( P1.X(), P1.Y() ); |
208 | gp_Vec2d theVec1( PT, PTMP ); |
209 | theVec1.Normalize(); |
210 | theVec1 *= aWidth; |
211 | gp_Pnt2d PTT = PT.Translated( theVec1 ); |
212 | Xt = Standard_ShortReal( PTT.X() ); |
213 | Yt = Standard_ShortReal( PTT.Y() ); |
214 | } |
215 | |
216 | Standard_Real theSmbX = 0., theSmbY = 0.; |
217 | |
218 | if ( myIsSymbol ) { |
219 | aDrawer->SetTextAttrib( myColorIndex, mySymbFont, 0, Standard_ShortReal(myTextScale*aDrawer->Scale()), |
220 | Standard_ShortReal(myTextScale*aDrawer->Scale()), Standard_False ); |
221 | TCollection_ExtendedString txtSymb = TCollection_ExtendedString( char( mySymbCode ) ); |
222 | theSmbX = Xt; theSmbY = Yt; |
223 | gp_Pnt2d pntText( Xt, Yt ); |
224 | Standard_ShortReal ws, hs; |
225 | aDrawer->GetTextSize( txtSymb, ws, hs ); |
226 | Standard_ShortReal ddd = aDrawer->Convert(2); |
227 | gp_Vec2d VX( 1., 0. ), theVec; |
228 | theVec = VX.Rotated( myTextAng ); |
229 | theVec *= ( ws + ddd ); |
230 | gp_Pnt2d pntSymb = pntText.Translated( theVec ); |
231 | Standard_Real txtX, txtY; |
232 | pntSymb.Coord( txtX, txtY ); |
233 | Xt = Standard_ShortReal( txtX ); |
234 | Yt = Standard_ShortReal( txtY ); |
235 | } |
236 | |
237 | Standard_ShortReal a = myX1, b = myY1, |
238 | c = myX2, d = myY2, |
239 | e = Xt, f = Yt, |
240 | w = 0., h = Standard_ShortReal( aHeight/5 ), |
241 | ts1 = Standard_ShortReal( theSmbX ), |
242 | ts2 = Standard_ShortReal( theSmbY ); |
243 | |
244 | TShort_Array1OfShortReal Xpoint( 1, 3 ), Ypoint( 1, 3 ); |
245 | Xpoint.Assign( myXVert ); |
246 | Ypoint.Assign( myYVert ); |
247 | |
248 | if ( myGOPtr->IsTransformed() ) { |
249 | |
250 | gp_GTrsf2d aTrsf = myGOPtr->Transform(); |
251 | Standard_Real A1, B1; |
252 | A1 = Standard_Real( a ); B1 = Standard_Real( b ); |
253 | aTrsf.Transforms( A1, B1 ); |
254 | a = Standard_ShortReal( A1 ); b = Standard_ShortReal( B1 ); |
255 | A1 = Standard_Real( c ); B1 = Standard_Real( d ); |
256 | aTrsf.Transforms( A1, B1 ); |
257 | c = Standard_ShortReal( A1 ); d = Standard_ShortReal( B1 ); |
258 | A1 = Standard_Real( e ); B1 = Standard_Real( f ); |
259 | aTrsf.Transforms( A1, B1 ); |
260 | e = Standard_ShortReal( A1 ); f = Standard_ShortReal( B1 ); |
261 | A1 = Standard_Real( w ); B1 = Standard_Real( h ); |
262 | aTrsf.Transforms( A1, B1 ); |
263 | w = Standard_ShortReal( A1 ); h = Standard_ShortReal( B1 ); |
264 | A1 = Standard_Real( ts1 ); B1 = Standard_Real( ts2 ); |
265 | aTrsf.Transforms( A1, B1 ); |
266 | ts1 = Standard_ShortReal( A1 ); ts2 = Standard_ShortReal( B1 ); |
267 | |
268 | for ( int j = 1; j <= 3; j++ ) { |
269 | A1 = Standard_Real( myXVert(j) ); |
270 | B1 = Standard_Real( myYVert(j) ); |
271 | aTrsf.Transforms( A1, B1 ); |
272 | Xpoint(j) = Standard_ShortReal(A1); |
273 | Ypoint(j) = Standard_ShortReal(B1); |
274 | } |
275 | |
276 | } |
277 | |
278 | DrawLineAttrib( aDrawer ); |
279 | aDrawer->MapSegmentFromTo( a, b, c, d ); |
280 | aDrawer->MapPolygonFromTo( Xpoint, Ypoint); |
281 | if ( myIsSymbol ) { |
282 | aDrawer->SetTextAttrib( myColorIndex, mySymbFont, 0, Standard_ShortReal(myTextScale*aDrawer->Scale()), |
283 | Standard_ShortReal(myTextScale*aDrawer->Scale()), Standard_False ); |
284 | TCollection_ExtendedString txtSymb = TCollection_ExtendedString( char( mySymbCode ) ); |
285 | aDrawer->MapTextFromTo( txtSymb, ts1, ts2, myTextAng, 0., 0., Aspect_TOT_SOLID ); |
286 | } |
287 | |
288 | aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0, Standard_ShortReal( myTextScale*aDrawer->Scale() ), |
289 | Standard_ShortReal( myTextScale*aDrawer->Scale()), Standard_False ); |
290 | |
291 | aDrawer->MapTextFromTo( myText, e, f, myTextAng, 0., 0., Aspect_TOT_SOLID ); |
292 | |
293 | } |
294 | } |
295 | |
296 | void Prs2d_RadiusIndep::DrawElement( const Handle(Graphic2d_Drawer)& /*aDrawer*/, |
297 | const Standard_Integer /*anIndex*/ ) { |
298 | |
299 | } |
300 | |
301 | void Prs2d_RadiusIndep::DrawVertex( const Handle(Graphic2d_Drawer)& /*aDrawer*/, |
302 | const Standard_Integer /*anIndex*/ ) { |
303 | } |
304 | |
305 | Standard_Boolean Prs2d_RadiusIndep::Pick( const Standard_ShortReal X, |
306 | const Standard_ShortReal Y, |
307 | const Standard_ShortReal aPrecision, |
308 | const Handle(Graphic2d_Drawer)& /*aDrawer*/) { |
309 | Standard_ShortReal SRX = X, SRY = Y; |
310 | Standard_Boolean Result = Standard_False; |
311 | |
312 | if ( IsInMinMax( X, Y, aPrecision ) ) { |
313 | if ( myGOPtr->IsTransformed () ) { |
314 | gp_GTrsf2d aTrsf = ( myGOPtr->Transform() ).Inverted(); |
315 | Standard_Real RX = Standard_Real(SRX), RY = Standard_Real(SRY); |
316 | aTrsf.Transforms(RX, RY); |
317 | SRX = Standard_ShortReal(RX); |
318 | SRY = Standard_ShortReal(RY); |
319 | } |
320 | Result = IsOn( SRX, SRY, myX1, myY1, myX2, myY2, aPrecision ); |
321 | } |
322 | return Result; |
323 | |
324 | } |
325 | |
326 | void Prs2d_RadiusIndep::SetTextScale( const Standard_Real aTxtScale ) { |
327 | myTextScale = Standard_ShortReal( aTxtScale ); |
328 | } |
329 | |
330 | void Prs2d_RadiusIndep::SetText( const TCollection_ExtendedString & aText ) { |
331 | myText = aText; |
332 | } |
333 | |
334 | void Prs2d_RadiusIndep::DrawSymbol(const Standard_Boolean isDraw ) { |
335 | myIsSymbol = isDraw; |
336 | } |
337 | |
338 | void Prs2d_RadiusIndep::SetSymbolCode( const Standard_Integer aCode ) { |
339 | mySymbCode = aCode; |
340 | } |
341 | |
342 | void Prs2d_RadiusIndep::SetTextFont(const Standard_Integer aTF) { |
343 | myTextFont = aTF; |
344 | } |
345 | |
346 | void Prs2d_RadiusIndep::SetFontOfSymb(const Standard_Integer aFS) { |
347 | mySymbFont = aFS; |
348 | } |
349 | |
350 | Standard_Boolean Prs2d_RadiusIndep::IsDrawSymbol() const { |
351 | return myIsSymbol; |
352 | } |
353 | |
354 | Standard_Integer Prs2d_RadiusIndep::SymbolCode() const { |
355 | return mySymbCode; |
356 | |
357 | } |
358 | |
359 | Standard_Integer Prs2d_RadiusIndep::TextFont() const { |
360 | return myTextFont; |
361 | } |
362 | |
363 | Standard_Integer Prs2d_RadiusIndep::FontOfSymb() const { |
364 | return mySymbFont; |
365 | } |
366 | |
367 | void Prs2d_RadiusIndep::Save(Aspect_FStream& aFStream) const |
368 | { |
369 | } |