7fd59977 |
1 | // File: BRepTools_GTrsfModification.cxx |
2 | // Created: Mon Dec 30 16:01:13 1996 |
3 | // Author: Stagiaire Mary FABIEN |
4 | // <fbi@zozox.paris1.matra-dtv.fr> |
5 | |
6 | |
7 | #include <BRepTools_GTrsfModification.ixx> |
8 | |
9 | #include <Geom_Plane.hxx> |
10 | #include <Geom_Line.hxx> |
11 | #include <Geom_TrimmedCurve.hxx> |
12 | #include <Geom2d_TrimmedCurve.hxx> |
13 | #include <Geom_BSplineSurface.hxx> |
14 | #include <Geom_BezierSurface.hxx> |
15 | #include <Geom_BSplineCurve.hxx> |
16 | #include <Geom_BezierCurve.hxx> |
17 | #include <Standard_Type.hxx> |
18 | #include <BRep_Tool.hxx> |
19 | #include <gp_GTrsf2d.hxx> |
20 | #include <gp_XYZ.hxx> |
21 | #include <gp_TrsfForm.hxx> |
22 | #include <Standard_NoSuchObject.hxx> |
23 | |
24 | #include <gp.hxx> |
25 | #include <GeomLib.hxx> |
26 | #include <TopAbs.hxx> |
27 | |
28 | //======================================================================= |
29 | //function : BRepTools_GTrsfModification |
30 | //purpose : |
31 | //======================================================================= |
32 | |
33 | BRepTools_GTrsfModification::BRepTools_GTrsfModification(const gp_GTrsf& T) : |
34 | myGTrsf(T) |
35 | { |
36 | // on prend comme dilatation maximale pour la tolerance la norme sup |
37 | Standard_Real loc1, loc2, loc3, loc4; |
38 | |
39 | loc1 = Max(Abs(T.Value(1,1)), Abs(T.Value(1,2))); |
40 | loc2 = Max(Abs(T.Value(2,1)), Abs(T.Value(2,2))); |
41 | loc3 = Max(Abs(T.Value(3,1)), Abs(T.Value(3,2))); |
42 | loc4 = Max(Abs(T.Value(1,3)), Abs(T.Value(2,3))); |
43 | |
44 | loc1 = Max(loc1, loc2); |
45 | loc2 = Max(loc3, loc4); |
46 | |
47 | loc1 = Max(loc1, loc2); |
48 | |
49 | myGScale = Max(loc1, Abs(T.Value(3,3))); |
50 | } |
51 | |
52 | |
53 | //======================================================================= |
54 | //function : GTrsf |
55 | //purpose : |
56 | //======================================================================= |
57 | |
58 | gp_GTrsf& BRepTools_GTrsfModification::GTrsf () |
59 | { |
60 | return myGTrsf; |
61 | } |
62 | |
63 | //======================================================================= |
64 | //function : NewSurface |
65 | //purpose : |
66 | //======================================================================= |
67 | |
68 | Standard_Boolean BRepTools_GTrsfModification::NewSurface |
69 | (const TopoDS_Face& F, |
70 | Handle(Geom_Surface)& S, |
71 | TopLoc_Location& L, |
72 | Standard_Real& Tol, |
73 | Standard_Boolean& RevWires, |
74 | Standard_Boolean& RevFace) |
75 | { |
76 | gp_GTrsf gtrsf; |
77 | gtrsf.SetVectorialPart(myGTrsf.VectorialPart()); |
78 | gtrsf.SetTranslationPart(myGTrsf.TranslationPart()); |
79 | S = Handle(Geom_Surface)::DownCast(BRep_Tool::Surface(F,L)->Copy()); |
80 | |
81 | Tol = BRep_Tool::Tolerance(F); |
82 | Tol *= myGScale; |
83 | RevWires = Standard_False; |
84 | RevFace = myGTrsf.IsNegative(); |
85 | S = Handle(Geom_Surface)::DownCast(S->Transformed(L.Transformation())); |
86 | |
87 | Handle(Standard_Type) TheTypeS = S->DynamicType(); |
88 | if (TheTypeS == STANDARD_TYPE(Geom_BSplineSurface)) { |
89 | Handle(Geom_BSplineSurface) S2 = Handle(Geom_BSplineSurface)::DownCast(S); |
90 | for(Standard_Integer i = 1; i <= S2->NbUPoles(); i++) |
91 | for(Standard_Integer j = 1; j <= S2->NbVPoles(); j++) { |
92 | gp_XYZ coor(S2->Pole(i, j).Coord()); |
93 | gtrsf.Transforms(coor); |
94 | gp_Pnt P(coor); |
95 | S2->SetPole(i, j, P); |
96 | } |
97 | } |
98 | else |
99 | if (TheTypeS == STANDARD_TYPE(Geom_BezierSurface)) { |
100 | Handle(Geom_BezierSurface) S2 = Handle(Geom_BezierSurface)::DownCast(S); |
101 | for(Standard_Integer i = 1; i <= S2->NbUPoles(); i++) |
102 | for(Standard_Integer j = 1; j <= S2->NbVPoles(); j++) { |
103 | gp_XYZ coor(S2->Pole(i, j).Coord()); |
104 | gtrsf.Transforms(coor); |
105 | gp_Pnt P(coor); |
106 | S2->SetPole(i, j, P); |
107 | } |
108 | } |
109 | else |
110 | Standard_NoSuchObject_Raise_if(1,"BRepTools_GTrsfModification : Pb no BSpline/Bezier Type Surface"); |
111 | |
112 | L.Identity(); |
113 | return Standard_True; |
114 | } |
115 | |
116 | |
117 | //======================================================================= |
118 | //function : NewCurve |
119 | //purpose : |
120 | //======================================================================= |
121 | |
122 | Standard_Boolean BRepTools_GTrsfModification::NewCurve |
123 | (const TopoDS_Edge& E, |
124 | Handle(Geom_Curve)& C, |
125 | TopLoc_Location& L, |
126 | Standard_Real& Tol) |
127 | { |
128 | Standard_Real f,l; |
129 | gp_GTrsf gtrsf; |
130 | gtrsf.SetVectorialPart(myGTrsf.VectorialPart()); |
131 | gtrsf.SetTranslationPart(myGTrsf.TranslationPart()); |
132 | Tol = BRep_Tool::Tolerance(E)*myGScale; |
133 | C = BRep_Tool::Curve(E, L, f, l); |
134 | |
135 | if (!C.IsNull()) { |
136 | C = Handle(Geom_Curve)::DownCast(C->Copy()->Transformed(L.Transformation())); |
137 | Handle(Standard_Type) TheTypeC = C->DynamicType(); |
138 | if (TheTypeC == STANDARD_TYPE(Geom_BSplineCurve)) { |
139 | Handle(Geom_BSplineCurve) C2 = Handle(Geom_BSplineCurve)::DownCast(C); |
140 | for(Standard_Integer i = 1; i <= C2->NbPoles(); i++) { |
141 | gp_XYZ coor(C2->Pole(i).Coord()); |
142 | gtrsf.Transforms(coor); |
143 | gp_Pnt P(coor); |
144 | C2->SetPole(i, P); |
145 | } |
146 | } |
147 | else |
148 | if(TheTypeC == STANDARD_TYPE(Geom_BezierCurve)) { |
149 | Handle(Geom_BezierCurve) C2 = Handle(Geom_BezierCurve)::DownCast(C); |
150 | for(Standard_Integer i = 1; i <= C2->NbPoles(); i++) { |
151 | gp_XYZ coor(C2->Pole(i).Coord()); |
152 | gtrsf.Transforms(coor); |
153 | gp_Pnt P(coor); |
154 | C2->SetPole(i, P); |
155 | } |
156 | } |
157 | else |
158 | Standard_NoSuchObject_Raise_if(1,"BRepTools_GTrsfModification : Pb no BSpline/Bezier Type Curve"); |
159 | C = new Geom_TrimmedCurve(C, f, l); |
160 | } |
161 | L.Identity() ; |
162 | return Standard_True; |
163 | } |
164 | |
165 | //======================================================================= |
166 | //function : NewPoint |
167 | //purpose : |
168 | //======================================================================= |
169 | |
170 | Standard_Boolean BRepTools_GTrsfModification::NewPoint |
171 | (const TopoDS_Vertex& V, |
172 | gp_Pnt& P, |
173 | Standard_Real& Tol) |
174 | { |
175 | gp_Pnt Pnt = BRep_Tool::Pnt(V); |
176 | Tol = BRep_Tool::Tolerance(V); |
177 | Tol *= myGScale; |
178 | gp_XYZ coor(Pnt.Coord()); |
179 | myGTrsf.Transforms(coor); |
180 | P.SetXYZ(coor); |
181 | |
182 | return Standard_True; |
183 | } |
184 | |
185 | //======================================================================= |
186 | //function : NewCurve2d |
187 | //purpose : |
188 | //======================================================================= |
189 | |
190 | Standard_Boolean BRepTools_GTrsfModification::NewCurve2d |
191 | (const TopoDS_Edge& E, |
192 | const TopoDS_Face& F, |
193 | const TopoDS_Edge&, |
194 | const TopoDS_Face&, |
195 | Handle(Geom2d_Curve)& C, |
196 | Standard_Real& Tol) |
197 | { |
198 | TopLoc_Location loc; |
199 | Tol = BRep_Tool::Tolerance(E); |
200 | Tol *= myGScale; |
201 | Standard_Real f,l; |
202 | C = BRep_Tool::CurveOnSurface(E,F,f,l); |
203 | C = new Geom2d_TrimmedCurve(C, f, l); |
204 | return Standard_True; |
205 | } |
206 | |
207 | //======================================================================= |
208 | //function : NewParameter |
209 | //purpose : |
210 | //======================================================================= |
211 | |
212 | Standard_Boolean BRepTools_GTrsfModification::NewParameter |
213 | (const TopoDS_Vertex& V, |
214 | const TopoDS_Edge& E, |
215 | Standard_Real& P, |
216 | Standard_Real& Tol) |
217 | { |
218 | Tol = BRep_Tool::Tolerance(V); |
219 | Tol *= myGScale; |
220 | P = BRep_Tool::Parameter(V,E); |
221 | return Standard_True; |
222 | } |
223 | |
224 | //======================================================================= |
225 | //function : Continuity |
226 | //purpose : |
227 | //======================================================================= |
228 | |
229 | GeomAbs_Shape BRepTools_GTrsfModification::Continuity |
230 | (const TopoDS_Edge& E, |
231 | const TopoDS_Face& F1, |
232 | const TopoDS_Face& F2, |
233 | const TopoDS_Edge&, |
234 | const TopoDS_Face&, |
235 | const TopoDS_Face&) |
236 | { |
237 | return BRep_Tool::Continuity(E,F1,F2); |
238 | } |
239 | |
240 | |