1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
18 #include <Prs2d_Repere.ixx>
21 Prs2d_Repere::Prs2d_Repere( const Handle(Graphic2d_GraphicObject)& aGO,
22 const gp_Pnt2d& aPnt1,
23 const gp_Pnt2d& aPnt2,
24 const Standard_Real aLenBase,
25 const TCollection_ExtendedString& aText,
26 const Standard_Real aTxtScale,
27 const Standard_Boolean aDrawArrow,
28 const Standard_Real anArrAngle,
29 const Standard_Real anArrLength,
30 const Prs2d_TypeOfArrow anArrType,
31 const Prs2d_ArrowSide anArrow,
32 const Standard_Boolean IsRevArrow )
34 : Prs2d_Dimension( aGO, aText, aTxtScale, anArrAngle,
35 anArrLength, anArrType, anArrow, IsRevArrow ),
38 myObtuse( Standard_False ),
39 myDrawArrow( aDrawArrow )
43 myXVert(1) = Standard_ShortReal( aPnt1.X() );
44 myXVert(2) = Standard_ShortReal( aPnt2.X() );
45 myYVert(1) = Standard_ShortReal( aPnt1.Y() );
46 myYVert(2) = Standard_ShortReal( aPnt2.Y() );
48 gp_Vec2d theVec( aPnt2, aPnt1 );
49 gp_Vec2d theVecX( 1., 0. );
50 Standard_Real theAng = theVecX.Angle(theVec);
51 Standard_Real nX = aPnt2.X();
52 // Standard_Boolean isObtuse = Standard_False;
57 gp_Pnt2d theOrig( 0., 0. ), P1, P2, P3;
58 gp_Vec2d VX( 1., 0. ), VDir( aPnt1, aPnt2 );
59 Standard_Real alpha = M_PI - anArrAngle;
61 P2 = gp_Pnt2d( anArrLength, anArrLength*Tan( alpha/2. ) );
62 P3 = gp_Pnt2d( anArrLength, -anArrLength*Tan( alpha/2. ) );
63 if ( IsRevArrow ) VDir.Reverse();
65 Standard_Real theAngle = VX.Angle( VDir );
67 P2.Rotate( theOrig, theAngle );
68 P3.Rotate( theOrig, theAngle );
70 P2.Translate( gp_Vec2d( theOrig, P1 ) );
71 P3.Translate( gp_Vec2d( theOrig, P1 ) );
73 myXVert1(1) = Standard_ShortReal( P2.X() );
74 myYVert1(1) = Standard_ShortReal( P2.Y() );
75 myXVert1(2) = Standard_ShortReal( P1.X() );
76 myYVert1(2) = Standard_ShortReal( P1.Y() );
77 myXVert1(3) = Standard_ShortReal( P3.X() );
78 myYVert1(3) = Standard_ShortReal( P3.Y() );
80 for ( i = 1; i <= 3; i++ ) {
82 if ( myXVert1(i) < myMinX ) myMinX = myXVert1(i);
83 if ( myYVert1(i) < myMinY ) myMinY = myYVert1(i);
84 if ( myXVert1(i) > myMaxX ) myMaxX = myXVert1(i);
85 if ( myYVert1(i) > myMaxY ) myMaxY = myYVert1(i);
91 if ( theAng >= 0. && theAng < M_PI/2) {
93 } else if ( theAng >= M_PI/2 && theAng <= M_PI ) {
95 myObtuse = Standard_True;
96 } else if ( theAng >= -M_PI && theAng < -M_PI/2) {
98 myObtuse = Standard_True;
99 } else if ( theAng >= -M_PI/2 && theAng < 0. )
102 myXVert(3) = Standard_ShortReal( nX );
103 myYVert(3) = Standard_ShortReal( aPnt2.Y() );
105 for ( i = 1; i <= 3; i++ ) {
106 if ( myXVert(i) < myMinX ) myMinX = myXVert(i);
107 if ( myYVert(i) < myMinY ) myMinY = myYVert(i);
108 if ( myXVert(i) > myMaxX ) myMaxX = myXVert(i);
109 if ( myYVert(i) > myMaxY ) myMaxY = myYVert(i);
114 void Prs2d_Repere::Draw(const Handle(Graphic2d_Drawer)& aDrawer) {
116 Standard_Boolean IsIn = Standard_False;
118 if ( ! myGOPtr->IsTransformed() )
119 IsIn = aDrawer->IsIn (myMinX,myMaxX,myMinY,myMaxY);
121 Standard_ShortReal minx, miny, maxx, maxy;
122 MinMax(minx,maxx,miny,maxy);
123 IsIn = aDrawer->IsIn (minx,maxx,miny,maxy);
128 DrawLineAttrib(aDrawer);
130 Standard_ShortReal dxx = aDrawer->Convert(ADDPIX);
131 Standard_ShortReal t1 = Standard_ShortReal( myXVert(3) + dxx ),
132 t2 = Standard_ShortReal( myYVert(3) + dxx );
134 t1 = Standard_ShortReal( myXVert(2) + dxx );
135 t2 = Standard_ShortReal( myYVert(2) + dxx );
137 Standard_Real theSmbX = t1, theSmbY = t2;
140 aDrawer->SetTextAttrib( myColorIndex, mySymbFont, 0, Standard_ShortReal(myTextScale*aDrawer->Scale()),
141 Standard_ShortReal(myTextScale*aDrawer->Scale()), Standard_False );
142 // TCollection_ExtendedString txtSymb( char( SymbolCode() ) );
143 Standard_Character code = SymbolCode();
144 TCollection_ExtendedString txtSymb( code );
145 Standard_ShortReal ws=0., hs=0.;
146 aDrawer->GetTextSize( txtSymb, ws, hs );
147 Standard_ShortReal ddd = aDrawer->Convert( 2 );
150 Standard_ShortReal ts1 = Standard_ShortReal( theSmbX ),
151 ts2 = Standard_ShortReal( theSmbY );
153 TShort_Array1OfShortReal Xpoint( 1, 3 ), Ypoint( 1, 3 ),
154 Xpoint1( 1, 3 ), Ypoint1( 1, 3 );
156 if ( myGOPtr->IsTransformed() ) {
158 gp_GTrsf2d aTrsf = myGOPtr->Transform ();
160 for ( Standard_Integer j = 1; j <= 3; j++ ) {
161 a = Standard_Real( myXVert(j) );
162 b = Standard_Real( myYVert(j) );
163 aTrsf.Transforms( a, b );
164 Xpoint(j) = Standard_ShortReal( a );
165 Ypoint(j) = Standard_ShortReal( b );
167 a = Standard_Real( t1 );
168 b = Standard_Real( t2 );
169 aTrsf.Transforms( a, b );
170 t1 = Standard_ShortReal( a );
171 t2 = Standard_ShortReal( b );
172 a = Standard_Real( ts1 );
173 b = Standard_Real( ts2 );
174 aTrsf.Transforms( a, b );
175 ts1 = Standard_ShortReal( a );
176 ts2 = Standard_ShortReal( b );
178 for ( Standard_Integer i = 1; i <= 3; i++ ) {
179 a = Standard_Real( myXVert1(i) );
180 b = Standard_Real( myYVert1(i) );
181 aTrsf.Transforms(a, b);
182 Xpoint1(i) = Standard_ShortReal(a);
183 Ypoint1(i) = Standard_ShortReal(b);
187 Xpoint.Assign( myXVert );
188 Ypoint.Assign( myYVert );
190 Xpoint1.Assign( myXVert1 );
191 Ypoint1.Assign( myYVert1 );
195 aDrawer->MapPolylineFromTo( Xpoint, Ypoint );
198 // TCollection_ExtendedString txtSymb( char( SymbolCode() ) );
199 Standard_Character code = SymbolCode();
200 TCollection_ExtendedString txtSymb( code );
201 Standard_ShortReal angle=0.,dx=0.,dy=0.;
202 aDrawer->MapTextFromTo( txtSymb, ts1, ts2, angle, dx, dy, Aspect_TOT_SOLID);
204 aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0, Standard_ShortReal(myTextScale*aDrawer->Scale()),
205 Standard_ShortReal(myTextScale*aDrawer->Scale()), Standard_False );
207 aDrawer->MapTextFromTo( myText, t1, t2, 0., 0., 0., Aspect_TOT_SOLID );
210 if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) {
211 aDrawer->MapPolygonFromTo( Xpoint1, Ypoint1 );
213 aDrawer->MapPolylineFromTo( Xpoint1, Ypoint1 );
219 void Prs2d_Repere::DrawElement( const Handle(Graphic2d_Drawer)& /*aDrawer*/,
220 const Standard_Integer /*anIndex*/ ) {
223 void Prs2d_Repere::DrawVertex( const Handle(Graphic2d_Drawer)& /*aDrawer*/,
224 const Standard_Integer /*anIndex*/ ) {
227 Standard_Boolean Prs2d_Repere::Pick( const Standard_ShortReal X,
228 const Standard_ShortReal Y,
229 const Standard_ShortReal aPrecision,
230 const Handle(Graphic2d_Drawer)& /*aDrawer*/ ) {
232 Standard_ShortReal SRX = X, SRY = Y;
234 Standard_Integer Lower = myXVert.Lower(), Upper = myXVert.Upper();
236 if ( IsInMinMax( X, Y, aPrecision ) ) {
238 if ( myGOPtr->IsTransformed() ) {
239 gp_GTrsf2d aTrsf = (myGOPtr->Transform ()).Inverted ();
240 Standard_Real RX = Standard_Real (SRX), RY = Standard_Real (SRY);
241 aTrsf.Transforms (RX, RY);
242 SRX = Standard_ShortReal (RX); SRY = Standard_ShortReal (RY);
244 for ( int i = Lower; i < Upper; i++ )
245 if ( IsOn( SRX, SRY, myXVert (i), myYVert(i),
246 myXVert( i + 1 ), myYVert( i + 1 ), aPrecision ) )
247 return Standard_True;
252 return Standard_False;
255 void Prs2d_Repere::Save(Aspect_FStream& aFStream) const