Commit | Line | Data |
---|---|---|
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 | // |
d5f74e42 | 5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 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 | |
42cf5bc1 | 14 | #include <Aspect_RectangularGrid.hxx> |
475c2302 | 15 | |
42cf5bc1 | 16 | #include <Standard_NegativeValue.hxx> |
17 | #include <Standard_NullValue.hxx> | |
18 | #include <Standard_NumericError.hxx> | |
7fd59977 | 19 | |
92efcf78 | 20 | IMPLEMENT_STANDARD_RTTIEXT(Aspect_RectangularGrid,Aspect_Grid) |
21 | ||
7fd59977 | 22 | Aspect_RectangularGrid::Aspect_RectangularGrid( |
ee2be2a8 | 23 | const Standard_Real aXStep, |
24 | const Standard_Real aYStep, | |
25 | const Standard_Real anXOrigin, | |
26 | const Standard_Real anYOrigin, | |
27 | const Standard_Real aFirstAngle, | |
28 | const Standard_Real aSecondAngle, | |
29 | const Standard_Real aRotationAngle) | |
7fd59977 | 30 | :Aspect_Grid(anXOrigin,anYOrigin,aRotationAngle),myXStep(aXStep),myYStep(aYStep),myFirstAngle(aFirstAngle),mySecondAngle(aSecondAngle) |
31 | ||
32 | { | |
33 | Standard_NumericError_Raise_if(!CheckAngle (aFirstAngle,mySecondAngle), | |
34 | "networks are parallel"); | |
35 | ||
36 | Standard_NegativeValue_Raise_if(aXStep < 0. , "invalid x step"); | |
37 | Standard_NegativeValue_Raise_if(aYStep < 0. , "invalid y step"); | |
38 | Standard_NullValue_Raise_if(aXStep == 0. , "invalid x step"); | |
39 | Standard_NullValue_Raise_if(aYStep == 0. , "invalid y step"); | |
40 | } | |
41 | ||
42 | ||
43 | ||
ee2be2a8 | 44 | void Aspect_RectangularGrid::SetXStep(const Standard_Real aStep) { |
7fd59977 | 45 | Standard_NegativeValue_Raise_if(aStep < 0. , "invalid x step"); |
46 | Standard_NullValue_Raise_if(aStep == 0. , "invalid y step"); | |
47 | myXStep = aStep; | |
48 | Init(); | |
49 | UpdateDisplay(); | |
50 | } | |
51 | ||
ee2be2a8 | 52 | void Aspect_RectangularGrid::SetYStep(const Standard_Real aStep) { |
7fd59977 | 53 | Standard_NegativeValue_Raise_if(aStep < 0. , "invalid x step"); |
54 | Standard_NullValue_Raise_if(aStep == 0. , "invalid y step"); | |
55 | myYStep = aStep; | |
56 | Init(); | |
57 | UpdateDisplay(); | |
58 | } | |
59 | ||
ee2be2a8 | 60 | void Aspect_RectangularGrid::SetAngle (const Standard_Real anAngle1, |
61 | const Standard_Real anAngle2) | |
62 | { | |
7fd59977 | 63 | Standard_NumericError_Raise_if(!CheckAngle (anAngle1,anAngle2 ), |
64 | "axis are parallel"); | |
65 | myFirstAngle = anAngle1; | |
66 | mySecondAngle = anAngle2; | |
67 | Init(); | |
68 | UpdateDisplay(); | |
69 | } | |
70 | ||
71 | void Aspect_RectangularGrid::SetGridValues( | |
ee2be2a8 | 72 | const Standard_Real theXOrigin, |
73 | const Standard_Real theYOrigin, | |
74 | const Standard_Real theXStep, | |
75 | const Standard_Real theYStep, | |
76 | const Standard_Real theRotationAngle) { | |
7fd59977 | 77 | |
78 | myXOrigin = theXOrigin; | |
79 | myYOrigin = theYOrigin; | |
80 | Standard_NegativeValue_Raise_if(theXStep < 0. , "invalid x step"); | |
81 | Standard_NullValue_Raise_if(theXStep == 0. , "invalid x step"); | |
82 | myXStep = theXStep; | |
83 | Standard_NegativeValue_Raise_if(theYStep < 0. , "invalid y step"); | |
84 | Standard_NullValue_Raise_if(theYStep == 0. , "invalid y step"); | |
85 | myYStep = theYStep; | |
86 | myRotationAngle = theRotationAngle; | |
87 | Init(); | |
88 | UpdateDisplay(); | |
89 | } | |
90 | ||
ee2be2a8 | 91 | void Aspect_RectangularGrid::Compute(const Standard_Real X, |
92 | const Standard_Real Y, | |
93 | Standard_Real& gridX, | |
94 | Standard_Real& gridY) const { | |
7fd59977 | 95 | Standard_Real D1 = b1 * X - a1 * Y - c1; |
96 | Standard_Real D2 = b2 * X - a2 * Y - c2; | |
97 | Standard_Integer n1 = Standard_Integer ( Abs(D1)/myXStep + 0.5); | |
98 | Standard_Integer n2 = Standard_Integer ( Abs(D2)/myYStep + 0.5); | |
99 | Standard_Real offset1 = c1 + Standard_Real(n1) * Sign (myXStep , D1); | |
100 | Standard_Real offset2 = c2 + Standard_Real(n2) * Sign (myYStep , D2); | |
7fd59977 | 101 | Standard_Real Delta = a1*b2 - b1*a2; |
102 | gridX = ( offset2*a1 - offset1*a2) /Delta; | |
103 | gridY = ( offset2*b1 - offset1*b2) /Delta; | |
7fd59977 | 104 | } |
105 | ||
ee2be2a8 | 106 | Standard_Real Aspect_RectangularGrid::XStep() const { |
7fd59977 | 107 | return myXStep; |
108 | } | |
109 | ||
ee2be2a8 | 110 | Standard_Real Aspect_RectangularGrid::YStep() const { |
7fd59977 | 111 | return myYStep; |
112 | } | |
113 | ||
ee2be2a8 | 114 | Standard_Real Aspect_RectangularGrid::FirstAngle() const { |
7fd59977 | 115 | return myFirstAngle; |
116 | } | |
117 | ||
ee2be2a8 | 118 | Standard_Real Aspect_RectangularGrid::SecondAngle() const { |
7fd59977 | 119 | return mySecondAngle; |
120 | } | |
121 | ||
122 | void 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 | // | |
c6541a0c D |
129 | // a2 = Cos (mySecondAngle + RotationAngle() + M_PI / 2.); |
130 | // b2 = Sin (mySecondAngle + RotationAngle() + M_PI / 2.); | |
7fd59977 | 131 | // c2 = XOrigin() * b2 - YOrigin() * a2; |
132 | ||
7fd59977 | 133 | Standard_Real angle1 = myFirstAngle + RotationAngle(); |
134 | Standard_Real angle2 = mySecondAngle + RotationAngle(); | |
135 | if ( angle1 != 0. ) { | |
136 | a1 = -Sin (angle1); | |
137 | b1 = Cos (angle1); | |
138 | c1 = XOrigin() * b1 - YOrigin() * a1; | |
139 | } else { | |
140 | a1 = 0.; b1 = 1.; c1 = XOrigin(); | |
141 | } | |
142 | ||
143 | if ( angle2 != 0. ) { | |
c6541a0c | 144 | angle2 += M_PI / 2.; |
7fd59977 | 145 | a2 = -Sin (angle2); |
146 | b2 = Cos (angle2); | |
147 | c2 = XOrigin() * b2 - YOrigin() * a2; | |
148 | } else { | |
149 | a2 = -1.; b2 = 0.; c2 = YOrigin(); | |
150 | } | |
7fd59977 | 151 | //-zov |
152 | } | |
153 | ||
154 | Standard_Boolean Aspect_RectangularGrid::CheckAngle(const Standard_Real alpha, | |
155 | const Standard_Real beta) const { | |
c6541a0c | 156 | return (Abs( Sin(alpha) * Cos(beta + M_PI / 2.) - Cos(alpha) * Sin(beta + M_PI / 2.)) != 0) ; |
7fd59977 | 157 | } |