1 #include <Prs2d_RadiusIndep.ixx>
4 #define DEFAULTMARKERSIZE 3.0
6 Prs2d_RadiusIndep::Prs2d_RadiusIndep( const Handle(Graphic2d_GraphicObject) & aGO,
7 const gp_Pnt2d & anAttachPnt,
8 const gp_Pnt2d & aCenter,
9 const Standard_Real aRad,
10 const TCollection_ExtendedString & aText,
11 const Standard_Real aLength,
12 const Prs2d_TypeOfRadius aTypeRad,
13 const Standard_Real aTxtScale )
15 : Graphic2d_Line( aGO ),
17 myX1( Standard_ShortReal( anAttachPnt.X() ) ),
18 myY1( Standard_ShortReal( anAttachPnt.Y() ) ),
19 myX2( Standard_ShortReal( aCenter.X() ) ),
20 myY2( Standard_ShortReal( aCenter.Y() ) ),
21 myTextScale( Standard_ShortReal( aTxtScale ) ),
25 myIsSymbol( Standard_False ),
29 myAttPnt( anAttachPnt ),
36 gp_Vec2d theVec1( gp_Pnt2d( myX2, myY2 ), gp_Pnt2d( myX1, myY1 ) );
37 gp_Vec2d theUnVec( 1., 0. );
38 myTextAng = Standard_ShortReal( theUnVec.Angle( theVec1 ) );
39 Standard_Real theLen = sqrt( (myX2-myX1)*(myX2-myX1) + (myY2-myY1)*(myY2-myY1) );
40 gp_Vec2d VecAdd = theVec1.Normalized();
42 theVec1 *= ( theLen + aLength );
43 gp_Pnt2d P1 = aCenter.Translated( theVec1 );
44 myTextX = Standard_ShortReal( P1.X() );
45 myTextY = Standard_ShortReal( P1.Y() );
46 gp_Pnt2d PArr( myX1, myY1 );
48 if ( ( theLen + aLength ) > theLen )
49 myInside = Standard_False;
51 myInside = Standard_True;
55 case Prs2d_TOR_STANDARD : {
57 myX2 = Standard_ShortReal( P1.X() );
58 myY2 = Standard_ShortReal( P1.Y() );
59 if ( ( theLen + aLength ) > theLen ) {
64 case Prs2d_TOR_CENTER : {
66 if ( aLength > 0.0 ) {
67 myX1 = Standard_ShortReal( P1.X() );
68 myY1 = Standard_ShortReal( P1.Y() );
73 case Prs2d_TOR_REVARROW : {
75 myX2 = Standard_ShortReal( P1.X() );
76 myY2 = Standard_ShortReal( P1.Y() );
77 if ( ( theLen + aLength ) <= theLen )
81 Standard_Real Dt = sqrt( ( myX2 - myX1 )*( myX2 - myX1 ) + ( myY2 - myY1 )*( myY2 - myY1 ) );
83 gp_Pnt2d PTmpn = PArr.Translated( VecAdd );
84 myX1 = Standard_ShortReal( PTmpn.X() );
85 myY1 = Standard_ShortReal( PTmpn.Y() );
89 case Prs2d_TOR_CENTREV : {
91 if ( aLength > 0.0 ) {
92 myX1 = Standard_ShortReal( P1.X() );
93 myY1 = Standard_ShortReal( P1.Y() );
96 Standard_Real Dt = sqrt( ( myX2 - myX1 )*( myX2 - myX1 ) + ( myY2 - myY1 )*( myY2 - myY1 ) );
98 gp_Pnt2d PTmpn = PArr.Translated( VecAdd );
99 myX1 = Standard_ShortReal( PTmpn.X() );
100 myY1 = Standard_ShortReal( PTmpn.Y() );
111 if ( myX2 < myMinX ) myMinX = myX2;
112 if ( myY2 < myMinY ) myMinY = myY2;
113 if ( myX2 > myMaxX ) myMaxX = myX2;
114 if ( myY2 > myMaxY ) myMaxY = myY2;
116 Standard_Real ArrANG = M_PI / 6., theArrLN = aRad/5., theANG;
117 gp_Pnt2d theOrig( 0., 0. ), P2, P3;
118 gp_Vec2d VX( 1., 0. );
120 P2 = gp_Pnt2d( theArrLN, theArrLN*Tan( ArrANG/2. ) );
121 P3 = gp_Pnt2d( theArrLN, -theArrLN*Tan( ArrANG/2. ) );
123 theANG = VX.Angle( theVec1 );
124 P2.Rotate( theOrig, theANG );
125 P3.Rotate( theOrig, theANG );
127 P2.Translate( gp_Vec2d( theOrig, PArr ) );
128 P3.Translate( gp_Vec2d( theOrig, PArr ) );
130 myXVert(1) = Standard_ShortReal( P2.X() );
131 myYVert(1) = Standard_ShortReal( P2.Y() );
132 myXVert(2) = Standard_ShortReal( PArr.X() );
133 myYVert(2) = Standard_ShortReal( PArr.Y() );
134 myXVert(3) = Standard_ShortReal( P3.X() );
135 myYVert(3) = Standard_ShortReal( P3.Y() );
137 for ( Standard_Integer i = 1; i <= 3; i++ ) {
139 if ( myXVert(i) < myMinX ) myMinX = myXVert(i);
140 if ( myYVert(i) < myMinY ) myMinY = myYVert(i);
141 if ( myXVert(i) > myMaxX ) myMaxX = myXVert(i);
142 if ( myYVert(i) > myMaxY ) myMaxY = myYVert(i);
147 void Prs2d_RadiusIndep::Values(gp_Pnt2d& anAttPnt,
150 TCollection_ExtendedString& aText,
151 Standard_Real& aLength,
152 Prs2d_TypeOfRadius& aTypeRad,
153 Standard_Real& aTxtScale) const {
160 aTypeRad = myRadType;
161 aTxtScale = myTextScale;
164 void Prs2d_RadiusIndep::Draw( const Handle(Graphic2d_Drawer)& aDrawer ) {
166 Standard_Boolean IsIn = Standard_False;
168 if ( ! myGOPtr->IsTransformed() )
169 IsIn = aDrawer->IsIn (myMinX,myMaxX,myMinY,myMaxY);
171 Standard_ShortReal minx, miny, maxx, maxy;
172 MinMax(minx,maxx,miny,maxy);
173 IsIn = aDrawer->IsIn (minx,maxx,miny,maxy);
178 DrawLineAttrib(aDrawer);
179 aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0, Standard_ShortReal( myTextScale*aDrawer->Scale() ),
180 Standard_ShortReal( myTextScale*aDrawer->Scale()), Standard_False );
182 Standard_ShortReal aWidth, aHeight;
183 aDrawer->GetTextSize( myText, aWidth, aHeight );
184 Standard_ShortReal Xt = myTextX, Yt = myTextY;
186 gp_Pnt2d P1( myX1, myY1 ), P2( myX2, myY2 ),
187 PT( myTextX, myTextY ), PTMP;
188 ( PT.IsEqual( P1, 0. ) )
189 ? PTMP.SetCoord( P2.X(), P2.Y() )
190 : PTMP.SetCoord( P1.X(), P1.Y() );
191 gp_Vec2d theVec1( PT, PTMP );
194 gp_Pnt2d PTT = PT.Translated( theVec1 );
195 Xt = Standard_ShortReal( PTT.X() );
196 Yt = Standard_ShortReal( PTT.Y() );
199 Standard_Real theSmbX = 0., theSmbY = 0.;
202 aDrawer->SetTextAttrib( myColorIndex, mySymbFont, 0, Standard_ShortReal(myTextScale*aDrawer->Scale()),
203 Standard_ShortReal(myTextScale*aDrawer->Scale()), Standard_False );
204 TCollection_ExtendedString txtSymb = TCollection_ExtendedString( char( mySymbCode ) );
205 theSmbX = Xt; theSmbY = Yt;
206 gp_Pnt2d pntText( Xt, Yt );
207 Standard_ShortReal ws, hs;
208 aDrawer->GetTextSize( txtSymb, ws, hs );
209 Standard_ShortReal ddd = aDrawer->Convert(2);
210 gp_Vec2d VX( 1., 0. ), theVec;
211 theVec = VX.Rotated( myTextAng );
212 theVec *= ( ws + ddd );
213 gp_Pnt2d pntSymb = pntText.Translated( theVec );
214 Standard_Real txtX, txtY;
215 pntSymb.Coord( txtX, txtY );
216 Xt = Standard_ShortReal( txtX );
217 Yt = Standard_ShortReal( txtY );
220 Standard_ShortReal a = myX1, b = myY1,
223 w = 0., h = Standard_ShortReal( aHeight/5 ),
224 ts1 = Standard_ShortReal( theSmbX ),
225 ts2 = Standard_ShortReal( theSmbY );
227 TShort_Array1OfShortReal Xpoint( 1, 3 ), Ypoint( 1, 3 );
228 Xpoint.Assign( myXVert );
229 Ypoint.Assign( myYVert );
231 if ( myGOPtr->IsTransformed() ) {
233 gp_GTrsf2d aTrsf = myGOPtr->Transform();
234 Standard_Real A1, B1;
235 A1 = Standard_Real( a ); B1 = Standard_Real( b );
236 aTrsf.Transforms( A1, B1 );
237 a = Standard_ShortReal( A1 ); b = Standard_ShortReal( B1 );
238 A1 = Standard_Real( c ); B1 = Standard_Real( d );
239 aTrsf.Transforms( A1, B1 );
240 c = Standard_ShortReal( A1 ); d = Standard_ShortReal( B1 );
241 A1 = Standard_Real( e ); B1 = Standard_Real( f );
242 aTrsf.Transforms( A1, B1 );
243 e = Standard_ShortReal( A1 ); f = Standard_ShortReal( B1 );
244 A1 = Standard_Real( w ); B1 = Standard_Real( h );
245 aTrsf.Transforms( A1, B1 );
246 w = Standard_ShortReal( A1 ); h = Standard_ShortReal( B1 );
247 A1 = Standard_Real( ts1 ); B1 = Standard_Real( ts2 );
248 aTrsf.Transforms( A1, B1 );
249 ts1 = Standard_ShortReal( A1 ); ts2 = Standard_ShortReal( B1 );
251 for ( int j = 1; j <= 3; j++ ) {
252 A1 = Standard_Real( myXVert(j) );
253 B1 = Standard_Real( myYVert(j) );
254 aTrsf.Transforms( A1, B1 );
255 Xpoint(j) = Standard_ShortReal(A1);
256 Ypoint(j) = Standard_ShortReal(B1);
261 DrawLineAttrib( aDrawer );
262 aDrawer->MapSegmentFromTo( a, b, c, d );
263 aDrawer->MapPolygonFromTo( Xpoint, Ypoint);
265 aDrawer->SetTextAttrib( myColorIndex, mySymbFont, 0, Standard_ShortReal(myTextScale*aDrawer->Scale()),
266 Standard_ShortReal(myTextScale*aDrawer->Scale()), Standard_False );
267 TCollection_ExtendedString txtSymb = TCollection_ExtendedString( char( mySymbCode ) );
268 aDrawer->MapTextFromTo( txtSymb, ts1, ts2, myTextAng, 0., 0., Aspect_TOT_SOLID );
271 aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0, Standard_ShortReal( myTextScale*aDrawer->Scale() ),
272 Standard_ShortReal( myTextScale*aDrawer->Scale()), Standard_False );
274 aDrawer->MapTextFromTo( myText, e, f, myTextAng, 0., 0., Aspect_TOT_SOLID );
279 void Prs2d_RadiusIndep::DrawElement( const Handle(Graphic2d_Drawer)& /*aDrawer*/,
280 const Standard_Integer /*anIndex*/ ) {
284 void Prs2d_RadiusIndep::DrawVertex( const Handle(Graphic2d_Drawer)& /*aDrawer*/,
285 const Standard_Integer /*anIndex*/ ) {
288 Standard_Boolean Prs2d_RadiusIndep::Pick( const Standard_ShortReal X,
289 const Standard_ShortReal Y,
290 const Standard_ShortReal aPrecision,
291 const Handle(Graphic2d_Drawer)& /*aDrawer*/) {
292 Standard_ShortReal SRX = X, SRY = Y;
293 Standard_Boolean Result = Standard_False;
295 if ( IsInMinMax( X, Y, aPrecision ) ) {
296 if ( myGOPtr->IsTransformed () ) {
297 gp_GTrsf2d aTrsf = ( myGOPtr->Transform() ).Inverted();
298 Standard_Real RX = Standard_Real(SRX), RY = Standard_Real(SRY);
299 aTrsf.Transforms(RX, RY);
300 SRX = Standard_ShortReal(RX);
301 SRY = Standard_ShortReal(RY);
303 Result = IsOn( SRX, SRY, myX1, myY1, myX2, myY2, aPrecision );
309 void Prs2d_RadiusIndep::SetTextScale( const Standard_Real aTxtScale ) {
310 myTextScale = Standard_ShortReal( aTxtScale );
313 void Prs2d_RadiusIndep::SetText( const TCollection_ExtendedString & aText ) {
317 void Prs2d_RadiusIndep::DrawSymbol(const Standard_Boolean isDraw ) {
321 void Prs2d_RadiusIndep::SetSymbolCode( const Standard_Integer aCode ) {
325 void Prs2d_RadiusIndep::SetTextFont(const Standard_Integer aTF) {
329 void Prs2d_RadiusIndep::SetFontOfSymb(const Standard_Integer aFS) {
333 Standard_Boolean Prs2d_RadiusIndep::IsDrawSymbol() const {
337 Standard_Integer Prs2d_RadiusIndep::SymbolCode() const {
342 Standard_Integer Prs2d_RadiusIndep::TextFont() const {
346 Standard_Integer Prs2d_RadiusIndep::FontOfSymb() const {
350 void Prs2d_RadiusIndep::Save(Aspect_FStream& aFStream) const