0028782: Shape sewing behavior not consistent for the same CAD file
[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//
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
7fd59977 14// Modified 23/02/98 : FMN ; Remplacement PI par Standard_PI
15
42cf5bc1 16#include <Aspect_RectangularGrid.hxx>
17#include <Standard_NegativeValue.hxx>
18#include <Standard_NullValue.hxx>
19#include <Standard_NumericError.hxx>
20#include <Standard_Type.hxx>
7fd59977 21
92efcf78 22IMPLEMENT_STANDARD_RTTIEXT(Aspect_RectangularGrid,Aspect_Grid)
23
7fd59977 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);
7fd59977 103 Standard_Real Delta = a1*b2 - b1*a2;
104 gridX = ( offset2*a1 - offset1*a2) /Delta;
105 gridY = ( offset2*b1 - offset1*b2) /Delta;
7fd59977 106}
107
108Quantity_Length Aspect_RectangularGrid::XStep() const {
109 return myXStep;
110}
111
112Quantity_Length Aspect_RectangularGrid::YStep() const {
113 return myYStep;
114}
115
116Quantity_Length Aspect_RectangularGrid::FirstAngle() const {
117 return myFirstAngle;
118}
119
120Quantity_Length Aspect_RectangularGrid::SecondAngle() const {
121 return mySecondAngle;
122}
123
124void Aspect_RectangularGrid::Init () {
125
126//+zov Fixing CTS17856
127// a1 = Cos (myFirstAngle + RotationAngle() );
128// b1 = Sin (myFirstAngle + RotationAngle() );
129// c1 = XOrigin() * b1 - YOrigin() * a1;
130//
c6541a0c
D
131// a2 = Cos (mySecondAngle + RotationAngle() + M_PI / 2.);
132// b2 = Sin (mySecondAngle + RotationAngle() + M_PI / 2.);
7fd59977 133// c2 = XOrigin() * b2 - YOrigin() * a2;
134
7fd59977 135 Standard_Real angle1 = myFirstAngle + RotationAngle();
136 Standard_Real angle2 = mySecondAngle + RotationAngle();
137 if ( angle1 != 0. ) {
138 a1 = -Sin (angle1);
139 b1 = Cos (angle1);
140 c1 = XOrigin() * b1 - YOrigin() * a1;
141 } else {
142 a1 = 0.; b1 = 1.; c1 = XOrigin();
143 }
144
145 if ( angle2 != 0. ) {
c6541a0c 146 angle2 += M_PI / 2.;
7fd59977 147 a2 = -Sin (angle2);
148 b2 = Cos (angle2);
149 c2 = XOrigin() * b2 - YOrigin() * a2;
150 } else {
151 a2 = -1.; b2 = 0.; c2 = YOrigin();
152 }
7fd59977 153//-zov
154}
155
156Standard_Boolean Aspect_RectangularGrid::CheckAngle(const Standard_Real alpha,
157 const Standard_Real beta) const {
c6541a0c 158 return (Abs( Sin(alpha) * Cos(beta + M_PI / 2.) - Cos(alpha) * Sin(beta + M_PI / 2.)) != 0) ;
7fd59977 159}
160
161