0024530: TKMesh - remove unused package IntPoly
[occt.git] / src / Aspect / Aspect_RectangularGrid.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
973c2be1 5// This library is free software; you can redistribute it and / or modify it
6// under the terms of the GNU Lesser General Public version 2.1 as published
7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14// Modified 23/02/98 : FMN ; Remplacement PI par Standard_PI
15
16#define CSR577 //GG 25/09/00 Avoid to have unaccuracy coordinates computation
17// when the grid is activated.
18
19#define xTRACE
20
21#include <Aspect_RectangularGrid.ixx>
22
23
24Aspect_RectangularGrid::Aspect_RectangularGrid(
25 const Quantity_Length aXStep,
26 const Quantity_Length aYStep,
27 const Quantity_Length anXOrigin,
28 const Quantity_Length anYOrigin,
29 const Quantity_PlaneAngle aFirstAngle,
30 const Quantity_PlaneAngle aSecondAngle,
31 const Quantity_PlaneAngle aRotationAngle)
32:Aspect_Grid(anXOrigin,anYOrigin,aRotationAngle),myXStep(aXStep),myYStep(aYStep),myFirstAngle(aFirstAngle),mySecondAngle(aSecondAngle)
33
34{
35 Standard_NumericError_Raise_if(!CheckAngle (aFirstAngle,mySecondAngle),
36 "networks are parallel");
37
38 Standard_NegativeValue_Raise_if(aXStep < 0. , "invalid x step");
39 Standard_NegativeValue_Raise_if(aYStep < 0. , "invalid y step");
40 Standard_NullValue_Raise_if(aXStep == 0. , "invalid x step");
41 Standard_NullValue_Raise_if(aYStep == 0. , "invalid y step");
42}
43
44
45
46void Aspect_RectangularGrid::SetXStep(const Quantity_Length aStep) {
47 Standard_NegativeValue_Raise_if(aStep < 0. , "invalid x step");
48 Standard_NullValue_Raise_if(aStep == 0. , "invalid y step");
49 myXStep = aStep;
50 Init();
51 UpdateDisplay();
52}
53
54void Aspect_RectangularGrid::SetYStep(const Quantity_Length aStep) {
55 Standard_NegativeValue_Raise_if(aStep < 0. , "invalid x step");
56 Standard_NullValue_Raise_if(aStep == 0. , "invalid y step");
57 myYStep = aStep;
58 Init();
59 UpdateDisplay();
60}
61
62void Aspect_RectangularGrid::SetAngle(const Quantity_PlaneAngle anAngle1,
63 const Quantity_PlaneAngle anAngle2){
64
65 Standard_NumericError_Raise_if(!CheckAngle (anAngle1,anAngle2 ),
66 "axis are parallel");
67 myFirstAngle = anAngle1;
68 mySecondAngle = anAngle2;
69 Init();
70 UpdateDisplay();
71}
72
73void Aspect_RectangularGrid::SetGridValues(
74 const Quantity_Length theXOrigin,
75 const Quantity_Length theYOrigin,
76 const Quantity_Length theXStep,
77 const Quantity_Length theYStep,
78 const Quantity_PlaneAngle theRotationAngle) {
79
80 myXOrigin = theXOrigin;
81 myYOrigin = theYOrigin;
82 Standard_NegativeValue_Raise_if(theXStep < 0. , "invalid x step");
83 Standard_NullValue_Raise_if(theXStep == 0. , "invalid x step");
84 myXStep = theXStep;
85 Standard_NegativeValue_Raise_if(theYStep < 0. , "invalid y step");
86 Standard_NullValue_Raise_if(theYStep == 0. , "invalid y step");
87 myYStep = theYStep;
88 myRotationAngle = theRotationAngle;
89 Init();
90 UpdateDisplay();
91}
92
93void Aspect_RectangularGrid::Compute(const Quantity_Length X,
94 const Quantity_Length Y,
95 Quantity_Length& gridX,
96 Quantity_Length& gridY) const {
97 Standard_Real D1 = b1 * X - a1 * Y - c1;
98 Standard_Real D2 = b2 * X - a2 * Y - c2;
99 Standard_Integer n1 = Standard_Integer ( Abs(D1)/myXStep + 0.5);
100 Standard_Integer n2 = Standard_Integer ( Abs(D2)/myYStep + 0.5);
101 Standard_Real offset1 = c1 + Standard_Real(n1) * Sign (myXStep , D1);
102 Standard_Real offset2 = c2 + Standard_Real(n2) * Sign (myYStep , D2);
103#ifdef CSR577
104 Standard_Real Delta = a1*b2 - b1*a2;
105 gridX = ( offset2*a1 - offset1*a2) /Delta;
106 gridY = ( offset2*b1 - offset1*b2) /Delta;
107#else
108 Standard_Real Delta = b1*a2 - a1*b2;
109 gridX = ( offset1*a2 - offset2*a1) /Delta;
110 gridY = ( offset1*b2 - offset2*b1) /Delta;
111#endif
112#ifdef TRACE
113 cout << "Aspect_RectangularGrid::Compute (" << Quantity_Length (X) << ", "
114 << Quantity_Length (Y) << ", " << Quantity_Length (gridX) << ", "
115 << Quantity_Length (gridY) << ")" << endl;
116#endif
117}
118
119Quantity_Length Aspect_RectangularGrid::XStep() const {
120 return myXStep;
121}
122
123Quantity_Length Aspect_RectangularGrid::YStep() const {
124 return myYStep;
125}
126
127Quantity_Length Aspect_RectangularGrid::FirstAngle() const {
128 return myFirstAngle;
129}
130
131Quantity_Length Aspect_RectangularGrid::SecondAngle() const {
132 return mySecondAngle;
133}
134
135void Aspect_RectangularGrid::Init () {
136
137//+zov Fixing CTS17856
138// a1 = Cos (myFirstAngle + RotationAngle() );
139// b1 = Sin (myFirstAngle + RotationAngle() );
140// c1 = XOrigin() * b1 - YOrigin() * a1;
141//
c6541a0c
D
142// a2 = Cos (mySecondAngle + RotationAngle() + M_PI / 2.);
143// b2 = Sin (mySecondAngle + RotationAngle() + M_PI / 2.);
7fd59977 144// c2 = XOrigin() * b2 - YOrigin() * a2;
145
146#ifdef CSR577
147 Standard_Real angle1 = myFirstAngle + RotationAngle();
148 Standard_Real angle2 = mySecondAngle + RotationAngle();
149 if ( angle1 != 0. ) {
150 a1 = -Sin (angle1);
151 b1 = Cos (angle1);
152 c1 = XOrigin() * b1 - YOrigin() * a1;
153 } else {
154 a1 = 0.; b1 = 1.; c1 = XOrigin();
155 }
156
157 if ( angle2 != 0. ) {
c6541a0c 158 angle2 += M_PI / 2.;
7fd59977 159 a2 = -Sin (angle2);
160 b2 = Cos (angle2);
161 c2 = XOrigin() * b2 - YOrigin() * a2;
162 } else {
163 a2 = -1.; b2 = 0.; c2 = YOrigin();
164 }
165#else
166 a1 = -Sin (myFirstAngle + RotationAngle());
167 b1 = Cos (myFirstAngle + RotationAngle());
168 c1 = XOrigin() * b1 - YOrigin() * a1;
169
c6541a0c
D
170 a2 = -Sin (mySecondAngle + RotationAngle() + M_PI / 2.);
171 b2 = Cos (mySecondAngle + RotationAngle() + M_PI / 2.);
7fd59977 172 c2 = XOrigin() * b2 - YOrigin() * a2;
173#endif
174//-zov
175}
176
177Standard_Boolean Aspect_RectangularGrid::CheckAngle(const Standard_Real alpha,
178 const Standard_Real beta) const {
c6541a0c 179 return (Abs( Sin(alpha) * Cos(beta + M_PI / 2.) - Cos(alpha) * Sin(beta + M_PI / 2.)) != 0) ;
7fd59977 180}
181
182