0022807: Loading of STEP entities in model during reading of STEP file requires redun...
[occt.git] / src / Aspect / Aspect_RectangularGrid.cxx
CommitLineData
7fd59977 1// Modified 23/02/98 : FMN ; Remplacement PI par Standard_PI
2
3#define CSR577 //GG 25/09/00 Avoid to have unaccuracy coordinates computation
4// when the grid is activated.
5
6#define xTRACE
7
8#include <Aspect_RectangularGrid.ixx>
9
10
11Aspect_RectangularGrid::Aspect_RectangularGrid(
12 const Quantity_Length aXStep,
13 const Quantity_Length aYStep,
14 const Quantity_Length anXOrigin,
15 const Quantity_Length anYOrigin,
16 const Quantity_PlaneAngle aFirstAngle,
17 const Quantity_PlaneAngle aSecondAngle,
18 const Quantity_PlaneAngle aRotationAngle)
19:Aspect_Grid(anXOrigin,anYOrigin,aRotationAngle),myXStep(aXStep),myYStep(aYStep),myFirstAngle(aFirstAngle),mySecondAngle(aSecondAngle)
20
21{
22 Standard_NumericError_Raise_if(!CheckAngle (aFirstAngle,mySecondAngle),
23 "networks are parallel");
24
25 Standard_NegativeValue_Raise_if(aXStep < 0. , "invalid x step");
26 Standard_NegativeValue_Raise_if(aYStep < 0. , "invalid y step");
27 Standard_NullValue_Raise_if(aXStep == 0. , "invalid x step");
28 Standard_NullValue_Raise_if(aYStep == 0. , "invalid y step");
29}
30
31
32
33void Aspect_RectangularGrid::SetXStep(const Quantity_Length aStep) {
34 Standard_NegativeValue_Raise_if(aStep < 0. , "invalid x step");
35 Standard_NullValue_Raise_if(aStep == 0. , "invalid y step");
36 myXStep = aStep;
37 Init();
38 UpdateDisplay();
39}
40
41void Aspect_RectangularGrid::SetYStep(const Quantity_Length aStep) {
42 Standard_NegativeValue_Raise_if(aStep < 0. , "invalid x step");
43 Standard_NullValue_Raise_if(aStep == 0. , "invalid y step");
44 myYStep = aStep;
45 Init();
46 UpdateDisplay();
47}
48
49void Aspect_RectangularGrid::SetAngle(const Quantity_PlaneAngle anAngle1,
50 const Quantity_PlaneAngle anAngle2){
51
52 Standard_NumericError_Raise_if(!CheckAngle (anAngle1,anAngle2 ),
53 "axis are parallel");
54 myFirstAngle = anAngle1;
55 mySecondAngle = anAngle2;
56 Init();
57 UpdateDisplay();
58}
59
60void Aspect_RectangularGrid::SetGridValues(
61 const Quantity_Length theXOrigin,
62 const Quantity_Length theYOrigin,
63 const Quantity_Length theXStep,
64 const Quantity_Length theYStep,
65 const Quantity_PlaneAngle theRotationAngle) {
66
67 myXOrigin = theXOrigin;
68 myYOrigin = theYOrigin;
69 Standard_NegativeValue_Raise_if(theXStep < 0. , "invalid x step");
70 Standard_NullValue_Raise_if(theXStep == 0. , "invalid x step");
71 myXStep = theXStep;
72 Standard_NegativeValue_Raise_if(theYStep < 0. , "invalid y step");
73 Standard_NullValue_Raise_if(theYStep == 0. , "invalid y step");
74 myYStep = theYStep;
75 myRotationAngle = theRotationAngle;
76 Init();
77 UpdateDisplay();
78}
79
80void Aspect_RectangularGrid::Compute(const Quantity_Length X,
81 const Quantity_Length Y,
82 Quantity_Length& gridX,
83 Quantity_Length& gridY) const {
84 Standard_Real D1 = b1 * X - a1 * Y - c1;
85 Standard_Real D2 = b2 * X - a2 * Y - c2;
86 Standard_Integer n1 = Standard_Integer ( Abs(D1)/myXStep + 0.5);
87 Standard_Integer n2 = Standard_Integer ( Abs(D2)/myYStep + 0.5);
88 Standard_Real offset1 = c1 + Standard_Real(n1) * Sign (myXStep , D1);
89 Standard_Real offset2 = c2 + Standard_Real(n2) * Sign (myYStep , D2);
90#ifdef CSR577
91 Standard_Real Delta = a1*b2 - b1*a2;
92 gridX = ( offset2*a1 - offset1*a2) /Delta;
93 gridY = ( offset2*b1 - offset1*b2) /Delta;
94#else
95 Standard_Real Delta = b1*a2 - a1*b2;
96 gridX = ( offset1*a2 - offset2*a1) /Delta;
97 gridY = ( offset1*b2 - offset2*b1) /Delta;
98#endif
99#ifdef TRACE
100 cout << "Aspect_RectangularGrid::Compute (" << Quantity_Length (X) << ", "
101 << Quantity_Length (Y) << ", " << Quantity_Length (gridX) << ", "
102 << Quantity_Length (gridY) << ")" << endl;
103#endif
104}
105
106Quantity_Length Aspect_RectangularGrid::XStep() const {
107 return myXStep;
108}
109
110Quantity_Length Aspect_RectangularGrid::YStep() const {
111 return myYStep;
112}
113
114Quantity_Length Aspect_RectangularGrid::FirstAngle() const {
115 return myFirstAngle;
116}
117
118Quantity_Length Aspect_RectangularGrid::SecondAngle() const {
119 return mySecondAngle;
120}
121
122void Aspect_RectangularGrid::Init () {
123
124//+zov Fixing CTS17856
125// a1 = Cos (myFirstAngle + RotationAngle() );
126// b1 = Sin (myFirstAngle + RotationAngle() );
127// c1 = XOrigin() * b1 - YOrigin() * a1;
128//
129// a2 = Cos (mySecondAngle + RotationAngle() + Standard_PI/2.);
130// b2 = Sin (mySecondAngle + RotationAngle() + Standard_PI/2.);
131// c2 = XOrigin() * b2 - YOrigin() * a2;
132
133#ifdef CSR577
134 Standard_Real angle1 = myFirstAngle + RotationAngle();
135 Standard_Real angle2 = mySecondAngle + RotationAngle();
136 if ( angle1 != 0. ) {
137 a1 = -Sin (angle1);
138 b1 = Cos (angle1);
139 c1 = XOrigin() * b1 - YOrigin() * a1;
140 } else {
141 a1 = 0.; b1 = 1.; c1 = XOrigin();
142 }
143
144 if ( angle2 != 0. ) {
145 angle2 += Standard_PI/2.;
146 a2 = -Sin (angle2);
147 b2 = Cos (angle2);
148 c2 = XOrigin() * b2 - YOrigin() * a2;
149 } else {
150 a2 = -1.; b2 = 0.; c2 = YOrigin();
151 }
152#else
153 a1 = -Sin (myFirstAngle + RotationAngle());
154 b1 = Cos (myFirstAngle + RotationAngle());
155 c1 = XOrigin() * b1 - YOrigin() * a1;
156
157 a2 = -Sin (mySecondAngle + RotationAngle() + Standard_PI/2.);
158 b2 = Cos (mySecondAngle + RotationAngle() + Standard_PI/2.);
159 c2 = XOrigin() * b2 - YOrigin() * a2;
160#endif
161//-zov
162}
163
164Standard_Boolean Aspect_RectangularGrid::CheckAngle(const Standard_Real alpha,
165 const Standard_Real beta) const {
82ac7cbb 166 return (Abs( Sin(alpha) * Cos(beta+Standard_PI/2.) - Cos(alpha) * Sin(beta+Standard_PI/2.)) != 0) ;
7fd59977 167}
168
169