Test for 0022778: Bug in BRepMesh
[occt.git] / src / Prs2d / Prs2d_SymTotal.cxx
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
18 #include <Prs2d_SymTotal.ixx>
19
20 Prs2d_SymTotal::Prs2d_SymTotal( const Handle(Graphic2d_GraphicObject)& aGO,
21                                 const Standard_Real aX,
22                                 const Standard_Real aY,
23                                 const Standard_Real aLength,
24                                 const Standard_Real anAngle ) 
25
26  : Prs2d_Tolerance( aGO, aX, aY, aLength, anAngle )
27 {         
28 }
29
30 void Prs2d_SymTotal::Draw( const Handle(Graphic2d_Drawer)& aDrawer )  {
31  
32  Standard_Boolean IsIn = Standard_False;    
33   
34   if ( !myGOPtr->IsTransformed() )
35     IsIn = aDrawer->IsIn( myMinX, myMaxX, myMinY, myMaxY );
36   else {
37     Standard_ShortReal minx, miny, maxx, maxy;
38     MinMax( minx, maxx, miny, maxy );
39     IsIn = aDrawer->IsIn( minx, maxx, miny, maxy );
40   }
41
42   if ( IsIn ) {
43     DrawLineAttrib( aDrawer );
44     const Standard_Real alpha = M_PI / 12;
45
46     Standard_ShortReal X1 = myX - myLength/2, 
47                        Y1 = myY - myLength/2, 
48                        X2 = Standard_ShortReal(X1 + myLength * Cos( M_PI / 4 ) ), 
49                        Y2 = myY + myLength/2,
50
51                        X5 = myX,
52                        Y5 = myY - myLength/2,
53                        X6 = Standard_ShortReal(X5 + myLength * Cos( M_PI / 4 ) ), 
54                        Y6 = myY + myLength/2;
55     
56     gp_Pnt2d P1( X2, Y2 );
57     gp_Vec2d V1( P1, gp_Pnt2d(X1, Y1) );
58     gp_Vec2d V2 = V1.Rotated(  alpha );
59     gp_Vec2d V3 = V1.Rotated( -alpha );
60     V2 /= 2;
61     V3 /= 2;
62     gp_Pnt2d P2 = P1.Translated( V2 ), 
63              P3 = P1.Translated( V3 );
64
65     gp_Pnt2d P4( X6, Y6 );
66     gp_Vec2d V4( P4, gp_Pnt2d( X5, Y5 ) );
67     gp_Vec2d V5 = V4.Rotated(  alpha );
68     gp_Vec2d V6 = V4.Rotated( -alpha );
69     V5 /= 2;
70     V6 /= 2;
71     gp_Pnt2d P5 = P4.Translated( V5 ), 
72              P6 = P4.Translated( V6 );
73
74
75    Standard_ShortReal X3 = Standard_ShortReal( P2.X() ), 
76                       Y3 = Standard_ShortReal( P2.Y() ), 
77                       X4 = Standard_ShortReal( P3.X() ), 
78                       Y4 = Standard_ShortReal( P3.Y() ),
79                       X7 = Standard_ShortReal( P5.X() ), 
80                       Y7 = Standard_ShortReal( P5.Y() ), 
81                       X8 = Standard_ShortReal( P6.X() ), 
82                       Y8 = Standard_ShortReal( P6.Y() );
83
84
85     gp_Pnt2d PP1( X1, Y1 ),
86              PP2( X2, Y2 ),
87              PP3( X3, Y3 ),
88              PP4( X4, Y4 ),
89              PP5( X5, Y5 ),
90              PP6( X6, Y6 ),
91              PP7( X7, Y7 ),
92              PP8( X8, Y8 ),
93              PPR( myX, myY );
94     PP1.Rotate( PPR, myAngle );
95     PP2.Rotate( PPR, myAngle );
96     PP3.Rotate( PPR, myAngle );
97     PP4.Rotate( PPR, myAngle );
98     PP5.Rotate( PPR, myAngle );
99     PP6.Rotate( PPR, myAngle );
100     PP7.Rotate( PPR, myAngle );
101     PP8.Rotate( PPR, myAngle );
102
103     X1 = Standard_ShortReal( PP1.X() );
104     Y1 = Standard_ShortReal( PP1.Y() );
105     X2 = Standard_ShortReal( PP2.X() );
106     Y2 = Standard_ShortReal( PP2.Y() );
107     X3 = Standard_ShortReal( PP3.X() );
108     Y3 = Standard_ShortReal( PP3.Y() );
109     X4 = Standard_ShortReal( PP4.X() );
110     Y4 = Standard_ShortReal( PP4.Y() );
111     X5 = Standard_ShortReal( PP5.X() );
112     Y5 = Standard_ShortReal( PP5.Y() );
113     X6 = Standard_ShortReal( PP6.X() );
114     Y6 = Standard_ShortReal( PP6.Y() );
115     X7 = Standard_ShortReal( PP7.X() );
116     Y7 = Standard_ShortReal( PP7.Y() );
117     X8 = Standard_ShortReal( PP8.X() );
118     Y8 = Standard_ShortReal( PP8.Y() );
119
120     
121     if ( myGOPtr->IsTransformed () ) {
122      gp_GTrsf2d aTrsf = myGOPtr->Transform ();
123      Standard_Real a1, b1;
124      a1 = X1;
125          b1 = Y1;
126      aTrsf.Transforms( a1, b1 );
127      X1 = Standard_ShortReal( a1 );
128          Y1 = Standard_ShortReal( b1 );
129      a1 = X2;
130          b1 = Y2;
131      aTrsf.Transforms( a1, b1 );
132      X2 = Standard_ShortReal( a1 );
133          Y2 = Standard_ShortReal( b1 );
134      a1 = X3;
135          b1 = Y3;
136      aTrsf.Transforms( a1, b1 );
137      X3 = Standard_ShortReal( a1 );
138          Y3 = Standard_ShortReal( b1 );
139      a1 = X4;
140          b1 = Y4;
141      aTrsf.Transforms( a1, b1 );
142      X4 = Standard_ShortReal( a1 );
143          Y4 = Standard_ShortReal( b1 );
144      a1 = X5;
145          b1 = Y5;
146      aTrsf.Transforms( a1, b1 );
147      X5 = Standard_ShortReal( a1 );
148          Y5 = Standard_ShortReal( b1 );
149      a1 = X6;
150          b1 = Y6;
151      aTrsf.Transforms( a1, b1 );
152      X6 = Standard_ShortReal( a1 );
153          Y6 = Standard_ShortReal( b1 );
154      a1 = X7;
155          b1 = Y7;
156      aTrsf.Transforms( a1, b1 );
157      X7 = Standard_ShortReal( a1 );
158          Y7 = Standard_ShortReal( b1 );
159      a1 = X8;
160          b1 = Y8;
161      aTrsf.Transforms( a1, b1 );
162      X8 = Standard_ShortReal( a1 );
163          Y8 = Standard_ShortReal( b1 );
164     }
165     aDrawer->MapSegmentFromTo( X1, Y1, X2, Y2 );
166     aDrawer->MapSegmentFromTo( X2, Y2, X3, Y3 );
167     aDrawer->MapSegmentFromTo( X2, Y2, X4, Y4 );
168     aDrawer->MapSegmentFromTo( X4, Y4, X3, Y3 );
169
170     aDrawer->MapSegmentFromTo( X5, Y5, X6, Y6 );
171     aDrawer->MapSegmentFromTo( X6, Y6, X7, Y7 );
172     aDrawer->MapSegmentFromTo( X6, Y6, X8, Y8 );
173     aDrawer->MapSegmentFromTo( X8, Y8, X7, Y7 );
174
175     aDrawer->MapSegmentFromTo( X1, Y1, X5, Y5 );
176  }
177 }
178
179 void Prs2d_SymTotal::Save(Aspect_FStream& aFStream) const
180 {
181 }