0024023: Revamp the OCCT Handle -- ambiguity
[occt.git] / src / Aspect / Aspect_RectangularGrid.cxx
... / ...
CommitLineData
1// Copyright (c) 1999-2014 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
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
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.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14// Modified 23/02/98 : FMN ; Remplacement PI par Standard_PI
15
16#include <Aspect_RectangularGrid.ixx>
17
18
19Aspect_RectangularGrid::Aspect_RectangularGrid(
20 const Quantity_Length aXStep,
21 const Quantity_Length aYStep,
22 const Quantity_Length anXOrigin,
23 const Quantity_Length anYOrigin,
24 const Quantity_PlaneAngle aFirstAngle,
25 const Quantity_PlaneAngle aSecondAngle,
26 const Quantity_PlaneAngle aRotationAngle)
27:Aspect_Grid(anXOrigin,anYOrigin,aRotationAngle),myXStep(aXStep),myYStep(aYStep),myFirstAngle(aFirstAngle),mySecondAngle(aSecondAngle)
28
29{
30 Standard_NumericError_Raise_if(!CheckAngle (aFirstAngle,mySecondAngle),
31 "networks are parallel");
32
33 Standard_NegativeValue_Raise_if(aXStep < 0. , "invalid x step");
34 Standard_NegativeValue_Raise_if(aYStep < 0. , "invalid y step");
35 Standard_NullValue_Raise_if(aXStep == 0. , "invalid x step");
36 Standard_NullValue_Raise_if(aYStep == 0. , "invalid y step");
37}
38
39
40
41void Aspect_RectangularGrid::SetXStep(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 myXStep = aStep;
45 Init();
46 UpdateDisplay();
47}
48
49void Aspect_RectangularGrid::SetYStep(const Quantity_Length aStep) {
50 Standard_NegativeValue_Raise_if(aStep < 0. , "invalid x step");
51 Standard_NullValue_Raise_if(aStep == 0. , "invalid y step");
52 myYStep = aStep;
53 Init();
54 UpdateDisplay();
55}
56
57void Aspect_RectangularGrid::SetAngle(const Quantity_PlaneAngle anAngle1,
58 const Quantity_PlaneAngle anAngle2){
59
60 Standard_NumericError_Raise_if(!CheckAngle (anAngle1,anAngle2 ),
61 "axis are parallel");
62 myFirstAngle = anAngle1;
63 mySecondAngle = anAngle2;
64 Init();
65 UpdateDisplay();
66}
67
68void Aspect_RectangularGrid::SetGridValues(
69 const Quantity_Length theXOrigin,
70 const Quantity_Length theYOrigin,
71 const Quantity_Length theXStep,
72 const Quantity_Length theYStep,
73 const Quantity_PlaneAngle theRotationAngle) {
74
75 myXOrigin = theXOrigin;
76 myYOrigin = theYOrigin;
77 Standard_NegativeValue_Raise_if(theXStep < 0. , "invalid x step");
78 Standard_NullValue_Raise_if(theXStep == 0. , "invalid x step");
79 myXStep = theXStep;
80 Standard_NegativeValue_Raise_if(theYStep < 0. , "invalid y step");
81 Standard_NullValue_Raise_if(theYStep == 0. , "invalid y step");
82 myYStep = theYStep;
83 myRotationAngle = theRotationAngle;
84 Init();
85 UpdateDisplay();
86}
87
88void Aspect_RectangularGrid::Compute(const Quantity_Length X,
89 const Quantity_Length Y,
90 Quantity_Length& gridX,
91 Quantity_Length& gridY) const {
92 Standard_Real D1 = b1 * X - a1 * Y - c1;
93 Standard_Real D2 = b2 * X - a2 * Y - c2;
94 Standard_Integer n1 = Standard_Integer ( Abs(D1)/myXStep + 0.5);
95 Standard_Integer n2 = Standard_Integer ( Abs(D2)/myYStep + 0.5);
96 Standard_Real offset1 = c1 + Standard_Real(n1) * Sign (myXStep , D1);
97 Standard_Real offset2 = c2 + Standard_Real(n2) * Sign (myYStep , D2);
98 Standard_Real Delta = a1*b2 - b1*a2;
99 gridX = ( offset2*a1 - offset1*a2) /Delta;
100 gridY = ( offset2*b1 - offset1*b2) /Delta;
101}
102
103Quantity_Length Aspect_RectangularGrid::XStep() const {
104 return myXStep;
105}
106
107Quantity_Length Aspect_RectangularGrid::YStep() const {
108 return myYStep;
109}
110
111Quantity_Length Aspect_RectangularGrid::FirstAngle() const {
112 return myFirstAngle;
113}
114
115Quantity_Length Aspect_RectangularGrid::SecondAngle() const {
116 return mySecondAngle;
117}
118
119void Aspect_RectangularGrid::Init () {
120
121//+zov Fixing CTS17856
122// a1 = Cos (myFirstAngle + RotationAngle() );
123// b1 = Sin (myFirstAngle + RotationAngle() );
124// c1 = XOrigin() * b1 - YOrigin() * a1;
125//
126// a2 = Cos (mySecondAngle + RotationAngle() + M_PI / 2.);
127// b2 = Sin (mySecondAngle + RotationAngle() + M_PI / 2.);
128// c2 = XOrigin() * b2 - YOrigin() * a2;
129
130 Standard_Real angle1 = myFirstAngle + RotationAngle();
131 Standard_Real angle2 = mySecondAngle + RotationAngle();
132 if ( angle1 != 0. ) {
133 a1 = -Sin (angle1);
134 b1 = Cos (angle1);
135 c1 = XOrigin() * b1 - YOrigin() * a1;
136 } else {
137 a1 = 0.; b1 = 1.; c1 = XOrigin();
138 }
139
140 if ( angle2 != 0. ) {
141 angle2 += M_PI / 2.;
142 a2 = -Sin (angle2);
143 b2 = Cos (angle2);
144 c2 = XOrigin() * b2 - YOrigin() * a2;
145 } else {
146 a2 = -1.; b2 = 0.; c2 = YOrigin();
147 }
148//-zov
149}
150
151Standard_Boolean Aspect_RectangularGrid::CheckAngle(const Standard_Real alpha,
152 const Standard_Real beta) const {
153 return (Abs( Sin(alpha) * Cos(beta + M_PI / 2.) - Cos(alpha) * Sin(beta + M_PI / 2.)) != 0) ;
154}
155
156