b311480e |
1 | // Created on: 1994-08-25 |
2 | // Created by: Jacques GOUSSARD |
3 | // Copyright (c) 1994-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <BRep_Tool.hxx> |
19 | #include <BRepTools_TrsfModification.hxx> |
20 | #include <Geom2d_Curve.hxx> |
21 | #include <Geom2d_TrimmedCurve.hxx> |
22 | #include <Geom_Curve.hxx> |
7fd59977 |
23 | #include <Geom_Line.hxx> |
42cf5bc1 |
24 | #include <Geom_Surface.hxx> |
7fd59977 |
25 | #include <Geom_TrimmedCurve.hxx> |
42cf5bc1 |
26 | #include <GeomAdaptor_Surface.hxx> |
27 | #include <GeomLib.hxx> |
28 | #include <gp.hxx> |
7fd59977 |
29 | #include <gp_GTrsf2d.hxx> |
42cf5bc1 |
30 | #include <gp_Pnt.hxx> |
31 | #include <gp_Trsf.hxx> |
7fd59977 |
32 | #include <gp_TrsfForm.hxx> |
42cf5bc1 |
33 | #include <Precision.hxx> |
34 | #include <Standard_Type.hxx> |
7fd59977 |
35 | #include <TopAbs.hxx> |
36 | #include <TopExp.hxx> |
42cf5bc1 |
37 | #include <TopLoc_Location.hxx> |
7fd59977 |
38 | #include <TopoDS.hxx> |
42cf5bc1 |
39 | #include <TopoDS_Edge.hxx> |
40 | #include <TopoDS_Face.hxx> |
41 | #include <TopoDS_Vertex.hxx> |
7fd59977 |
42 | |
92efcf78 |
43 | IMPLEMENT_STANDARD_RTTIEXT(BRepTools_TrsfModification,BRepTools_Modification) |
44 | |
7fd59977 |
45 | //======================================================================= |
46 | //function : BRepTools_TrsfModification |
47 | //purpose : |
48 | //======================================================================= |
7fd59977 |
49 | BRepTools_TrsfModification::BRepTools_TrsfModification(const gp_Trsf& T) : |
50 | myTrsf(T) |
51 | { |
52 | } |
53 | |
54 | |
55 | //======================================================================= |
56 | //function : Trsf |
57 | //purpose : |
58 | //======================================================================= |
59 | |
60 | gp_Trsf& BRepTools_TrsfModification::Trsf () |
61 | { |
62 | return myTrsf; |
63 | } |
64 | |
65 | //======================================================================= |
66 | //function : NewSurface |
67 | //purpose : |
68 | //======================================================================= |
69 | |
70 | Standard_Boolean BRepTools_TrsfModification::NewSurface |
71 | (const TopoDS_Face& F, |
72 | Handle(Geom_Surface)& S, |
73 | TopLoc_Location& L, |
74 | Standard_Real& Tol, |
75 | Standard_Boolean& RevWires, |
76 | Standard_Boolean& RevFace) |
77 | { |
78 | S = BRep_Tool::Surface(F,L); |
79 | Tol = BRep_Tool::Tolerance(F); |
80 | Tol *= Abs(myTrsf.ScaleFactor()); |
81 | RevWires = Standard_False; |
82 | RevFace = myTrsf.IsNegative(); |
83 | |
84 | gp_Trsf LT = L.Transformation(); |
85 | LT.Invert(); |
86 | LT.Multiply(myTrsf); |
87 | LT.Multiply(L.Transformation()); |
88 | |
89 | S = Handle(Geom_Surface)::DownCast(S->Transformed(LT)); |
90 | |
91 | return Standard_True; |
92 | } |
93 | |
94 | |
95 | //======================================================================= |
96 | //function : NewCurve |
97 | //purpose : |
98 | //======================================================================= |
99 | |
100 | Standard_Boolean BRepTools_TrsfModification::NewCurve |
101 | (const TopoDS_Edge& E, |
102 | Handle(Geom_Curve)& C, |
103 | TopLoc_Location& L, |
104 | Standard_Real& Tol) |
105 | { |
106 | Standard_Real f,l; |
107 | C = BRep_Tool::Curve(E,L,f,l); |
108 | |
109 | Tol = BRep_Tool::Tolerance(E); |
110 | Tol *= Abs(myTrsf.ScaleFactor()); |
111 | |
112 | gp_Trsf LT = L.Transformation(); |
113 | LT.Invert(); |
114 | LT.Multiply(myTrsf); |
115 | LT.Multiply(L.Transformation()); |
116 | |
117 | if (!C.IsNull()) { |
118 | C = Handle(Geom_Curve)::DownCast(C->Transformed(LT)); |
119 | } |
120 | |
121 | return Standard_True; |
122 | } |
123 | |
124 | //======================================================================= |
125 | //function : NewPoint |
126 | //purpose : |
127 | //======================================================================= |
128 | |
129 | Standard_Boolean BRepTools_TrsfModification::NewPoint |
130 | (const TopoDS_Vertex& V, |
131 | gp_Pnt& P, |
132 | Standard_Real& Tol) |
133 | { |
134 | P = BRep_Tool::Pnt(V); |
135 | Tol = BRep_Tool::Tolerance(V); |
136 | Tol *= Abs(myTrsf.ScaleFactor()); |
137 | P.Transform(myTrsf); |
138 | |
139 | return Standard_True; |
140 | } |
141 | |
142 | //======================================================================= |
143 | //function : NewCurve2d |
144 | //purpose : |
145 | //======================================================================= |
146 | |
147 | Standard_Boolean BRepTools_TrsfModification::NewCurve2d |
148 | (const TopoDS_Edge& E, |
149 | const TopoDS_Face& F, |
150 | const TopoDS_Edge&, |
151 | const TopoDS_Face&, |
152 | Handle(Geom2d_Curve)& C, |
153 | Standard_Real& Tol) |
154 | { |
155 | TopLoc_Location loc; |
156 | Tol = BRep_Tool::Tolerance(E); |
157 | Standard_Real scale = myTrsf.ScaleFactor(); |
158 | Tol *= Abs(scale); |
159 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,loc); |
c8ea5b8e |
160 | GeomAdaptor_Surface GAsurf(S); |
161 | if (GAsurf.GetType() == GeomAbs_Plane) |
162 | return Standard_False; |
7fd59977 |
163 | |
164 | Standard_Real f,l; |
165 | Handle(Geom2d_Curve) NewC = BRep_Tool::CurveOnSurface(E,F,f,l); |
166 | if (NewC.IsNull()) |
167 | return Standard_False; |
168 | |
169 | Standard_Real newf,newl; |
170 | |
171 | Handle(Standard_Type) TheType = NewC->DynamicType(); |
172 | |
173 | if ( TheType == STANDARD_TYPE(Geom2d_TrimmedCurve)) { |
174 | Handle(Geom2d_TrimmedCurve) TC = Handle(Geom2d_TrimmedCurve)::DownCast(NewC); |
175 | NewC = TC->BasisCurve(); |
176 | } |
177 | |
178 | Standard_Real fc = NewC->FirstParameter(), lc = NewC->LastParameter(); |
179 | |
180 | if(!NewC->IsPeriodic()) { |
181 | if(fc - f > Precision::PConfusion()) f = fc; |
182 | if(l - lc > Precision::PConfusion()) l = lc; |
183 | } |
184 | |
185 | newf = f; |
186 | newl = l; |
187 | if (Abs(scale) != 1.) { |
188 | |
189 | NewC = new Geom2d_TrimmedCurve(NewC,f,l); |
190 | gp_GTrsf2d gtrsf = S->ParametricTransformation(myTrsf); |
191 | |
192 | if ( gtrsf.Form() != gp_Identity) { |
193 | NewC = GeomLib::GTransform(NewC,gtrsf); |
194 | if (NewC.IsNull()) { |
9775fa61 |
195 | throw Standard_DomainError("TrsfModification:Error in NewCurve2d"); |
7fd59977 |
196 | } |
197 | newf = NewC->FirstParameter(); |
198 | newl = NewC->LastParameter(); |
199 | } |
200 | } |
201 | // il faut parfois recadrer les ranges 3d / 2d |
202 | TopoDS_Vertex V1, V2; |
203 | TopExp::Vertices(E,V1,V2); |
204 | TopoDS_Shape initEFOR = E.Oriented(TopAbs_FORWARD); // skl |
205 | TopoDS_Edge EFOR = TopoDS::Edge(initEFOR/*E.Oriented(TopAbs_FORWARD)*/); //skl |
9c189bd8 |
206 | Standard_Real aTolV; |
207 | NewParameter(V1, EFOR, f, aTolV); |
208 | NewParameter(V2, EFOR, l, aTolV); |
209 | GeomLib::SameRange(Precision::PConfusion(), NewC, newf, newl, f, l, C); |
7fd59977 |
210 | |
211 | return Standard_True; |
212 | } |
213 | |
214 | //======================================================================= |
215 | //function : NewParameter |
216 | //purpose : |
217 | //======================================================================= |
218 | |
219 | Standard_Boolean BRepTools_TrsfModification::NewParameter |
220 | (const TopoDS_Vertex& V, |
221 | const TopoDS_Edge& E, |
222 | Standard_Real& P, |
223 | Standard_Real& Tol) |
224 | { |
225 | if (V.IsNull()) return Standard_False; // infinite edge may have Null vertex |
226 | |
227 | TopLoc_Location loc; |
228 | Tol = BRep_Tool::Tolerance(V); |
229 | Tol *= Abs(myTrsf.ScaleFactor()); |
230 | P = BRep_Tool::Parameter(V,E); |
231 | |
232 | Standard_Real f,l; |
233 | |
234 | Handle(Geom_Curve) C = BRep_Tool::Curve(E,loc,f,l); |
235 | if (!C.IsNull()) { |
236 | P = C->TransformedParameter(P,myTrsf); |
237 | } |
238 | |
239 | return Standard_True; |
240 | } |
241 | |
242 | //======================================================================= |
243 | //function : Continuity |
244 | //purpose : |
245 | //======================================================================= |
246 | |
247 | GeomAbs_Shape BRepTools_TrsfModification::Continuity |
248 | (const TopoDS_Edge& E, |
249 | const TopoDS_Face& F1, |
250 | const TopoDS_Face& F2, |
251 | const TopoDS_Edge&, |
252 | const TopoDS_Face&, |
253 | const TopoDS_Face&) |
254 | { |
255 | return BRep_Tool::Continuity(E,F1,F2); |
256 | } |
257 | |
258 | |