Test for 0022778: Bug in BRepMesh
[occt.git] / src / Prs2d / Prs2d_Flatness.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_Flatness.ixx>
19
20 Prs2d_Flatness::Prs2d_Flatness( 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_Flatness::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     Standard_ShortReal X1 = myX - myLength/2, 
45                        Y1 = myY - myLength/2, 
46                        X4 = myX + myLength/2,
47                        Y4 = Y1,
48                        X2 = X1 + myLength/2, 
49                        Y2 = myY + myLength/2,
50                        X3 = X4 + myLength/2,
51                        Y3 = Y2;
52     gp_Pnt2d P1( X1, Y1 ),
53              P2( X2, Y2 ),
54              P3( X3, Y3 ),
55              P4( X4, Y4 ),
56              PR( myX, myY );
57     P1.Rotate( PR, myAngle );
58     P2.Rotate( PR, myAngle );
59     P3.Rotate( PR, myAngle );
60     P4.Rotate( PR, myAngle );
61
62     X1 = Standard_ShortReal( P1.X() );
63     Y1 = Standard_ShortReal( P1.Y() );
64     X2 = Standard_ShortReal( P2.X() );
65     Y2 = Standard_ShortReal( P2.Y() );
66     X3 = Standard_ShortReal( P3.X() );
67     Y3 = Standard_ShortReal( P3.Y() );
68     X4 = Standard_ShortReal( P4.X() );
69     Y4 = Standard_ShortReal( P4.Y() );
70
71     if ( myGOPtr->IsTransformed () ) {
72      gp_GTrsf2d aTrsf = myGOPtr->Transform ();
73      Standard_Real a1, b1;
74      a1 = X1;
75          b1 = Y1;
76      aTrsf.Transforms( a1, b1 );
77      X1 = Standard_ShortReal( a1 );
78          Y1 = Standard_ShortReal( b1 );
79      a1 = X2;
80          b1 = Y2;
81      aTrsf.Transforms( a1, b1 );
82      X2 = Standard_ShortReal( a1 );
83          Y2 = Standard_ShortReal( b1 );
84      a1 = X3;
85          b1 = Y3;
86      aTrsf.Transforms( a1, b1 );
87      X3 = Standard_ShortReal( a1 );
88          Y3 = Standard_ShortReal( b1 );
89      a1 = X4;
90          b1 = Y4;
91      aTrsf.Transforms( a1, b1 );
92      X4 = Standard_ShortReal( a1 );
93          Y4 = Standard_ShortReal( b1 );
94     }
95     aDrawer->MapSegmentFromTo( X1, Y1, X2, Y2 );
96     aDrawer->MapSegmentFromTo( X2, Y2, X3, Y3 );
97     aDrawer->MapSegmentFromTo( X3, Y3, X4, Y4 );
98     aDrawer->MapSegmentFromTo( X4, Y4, X1, Y1 );
99   }
100 }
101
102 void Prs2d_Flatness::Save(Aspect_FStream& aFStream) const
103 {
104 }