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 | |
17 | #include <BRepTools_TrsfModification.ixx> |
18 | |
19 | #include <Geom_Line.hxx> |
20 | #include <Geom_TrimmedCurve.hxx> |
21 | #include <Geom2d_TrimmedCurve.hxx> |
22 | #include <BRep_Tool.hxx> |
23 | #include <gp_GTrsf2d.hxx> |
24 | #include <gp_TrsfForm.hxx> |
25 | |
26 | #include <gp.hxx> |
27 | #include <GeomLib.hxx> |
28 | #include <TopAbs.hxx> |
29 | #include <TopExp.hxx> |
30 | |
31 | #include <TopoDS.hxx> |
32 | #include <Precision.hxx> |
c8ea5b8e |
33 | #include <GeomAdaptor_Surface.hxx> |
ec357c5c |
34 | #include <Geom_Surface.hxx> |
35 | #include <Geom_Curve.hxx> |
7fd59977 |
36 | |
37 | //======================================================================= |
38 | //function : BRepTools_TrsfModification |
39 | //purpose : |
40 | //======================================================================= |
41 | |
42 | BRepTools_TrsfModification::BRepTools_TrsfModification(const gp_Trsf& T) : |
43 | myTrsf(T) |
44 | { |
45 | } |
46 | |
47 | |
48 | //======================================================================= |
49 | //function : Trsf |
50 | //purpose : |
51 | //======================================================================= |
52 | |
53 | gp_Trsf& BRepTools_TrsfModification::Trsf () |
54 | { |
55 | return myTrsf; |
56 | } |
57 | |
58 | //======================================================================= |
59 | //function : NewSurface |
60 | //purpose : |
61 | //======================================================================= |
62 | |
63 | Standard_Boolean BRepTools_TrsfModification::NewSurface |
64 | (const TopoDS_Face& F, |
65 | Handle(Geom_Surface)& S, |
66 | TopLoc_Location& L, |
67 | Standard_Real& Tol, |
68 | Standard_Boolean& RevWires, |
69 | Standard_Boolean& RevFace) |
70 | { |
71 | S = BRep_Tool::Surface(F,L); |
72 | Tol = BRep_Tool::Tolerance(F); |
73 | Tol *= Abs(myTrsf.ScaleFactor()); |
74 | RevWires = Standard_False; |
75 | RevFace = myTrsf.IsNegative(); |
76 | |
77 | gp_Trsf LT = L.Transformation(); |
78 | LT.Invert(); |
79 | LT.Multiply(myTrsf); |
80 | LT.Multiply(L.Transformation()); |
81 | |
82 | S = Handle(Geom_Surface)::DownCast(S->Transformed(LT)); |
83 | |
84 | return Standard_True; |
85 | } |
86 | |
87 | |
88 | //======================================================================= |
89 | //function : NewCurve |
90 | //purpose : |
91 | //======================================================================= |
92 | |
93 | Standard_Boolean BRepTools_TrsfModification::NewCurve |
94 | (const TopoDS_Edge& E, |
95 | Handle(Geom_Curve)& C, |
96 | TopLoc_Location& L, |
97 | Standard_Real& Tol) |
98 | { |
99 | Standard_Real f,l; |
100 | C = BRep_Tool::Curve(E,L,f,l); |
101 | |
102 | Tol = BRep_Tool::Tolerance(E); |
103 | Tol *= Abs(myTrsf.ScaleFactor()); |
104 | |
105 | gp_Trsf LT = L.Transformation(); |
106 | LT.Invert(); |
107 | LT.Multiply(myTrsf); |
108 | LT.Multiply(L.Transformation()); |
109 | |
110 | if (!C.IsNull()) { |
111 | C = Handle(Geom_Curve)::DownCast(C->Transformed(LT)); |
112 | } |
113 | |
114 | return Standard_True; |
115 | } |
116 | |
117 | //======================================================================= |
118 | //function : NewPoint |
119 | //purpose : |
120 | //======================================================================= |
121 | |
122 | Standard_Boolean BRepTools_TrsfModification::NewPoint |
123 | (const TopoDS_Vertex& V, |
124 | gp_Pnt& P, |
125 | Standard_Real& Tol) |
126 | { |
127 | P = BRep_Tool::Pnt(V); |
128 | Tol = BRep_Tool::Tolerance(V); |
129 | Tol *= Abs(myTrsf.ScaleFactor()); |
130 | P.Transform(myTrsf); |
131 | |
132 | return Standard_True; |
133 | } |
134 | |
135 | //======================================================================= |
136 | //function : NewCurve2d |
137 | //purpose : |
138 | //======================================================================= |
139 | |
140 | Standard_Boolean BRepTools_TrsfModification::NewCurve2d |
141 | (const TopoDS_Edge& E, |
142 | const TopoDS_Face& F, |
143 | const TopoDS_Edge&, |
144 | const TopoDS_Face&, |
145 | Handle(Geom2d_Curve)& C, |
146 | Standard_Real& Tol) |
147 | { |
148 | TopLoc_Location loc; |
149 | Tol = BRep_Tool::Tolerance(E); |
150 | Standard_Real scale = myTrsf.ScaleFactor(); |
151 | Tol *= Abs(scale); |
152 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,loc); |
c8ea5b8e |
153 | GeomAdaptor_Surface GAsurf(S); |
154 | if (GAsurf.GetType() == GeomAbs_Plane) |
155 | return Standard_False; |
7fd59977 |
156 | |
157 | Standard_Real f,l; |
158 | Handle(Geom2d_Curve) NewC = BRep_Tool::CurveOnSurface(E,F,f,l); |
159 | if (NewC.IsNull()) |
160 | return Standard_False; |
161 | |
162 | Standard_Real newf,newl; |
163 | |
164 | Handle(Standard_Type) TheType = NewC->DynamicType(); |
165 | |
166 | if ( TheType == STANDARD_TYPE(Geom2d_TrimmedCurve)) { |
167 | Handle(Geom2d_TrimmedCurve) TC = Handle(Geom2d_TrimmedCurve)::DownCast(NewC); |
168 | NewC = TC->BasisCurve(); |
169 | } |
170 | |
171 | Standard_Real fc = NewC->FirstParameter(), lc = NewC->LastParameter(); |
172 | |
173 | if(!NewC->IsPeriodic()) { |
174 | if(fc - f > Precision::PConfusion()) f = fc; |
175 | if(l - lc > Precision::PConfusion()) l = lc; |
176 | } |
177 | |
178 | newf = f; |
179 | newl = l; |
180 | if (Abs(scale) != 1.) { |
181 | |
182 | NewC = new Geom2d_TrimmedCurve(NewC,f,l); |
183 | gp_GTrsf2d gtrsf = S->ParametricTransformation(myTrsf); |
184 | |
185 | if ( gtrsf.Form() != gp_Identity) { |
186 | NewC = GeomLib::GTransform(NewC,gtrsf); |
187 | if (NewC.IsNull()) { |
188 | Standard_DomainError::Raise("TrsfModification:Error in NewCurve2d"); |
189 | return Standard_False; |
190 | } |
191 | newf = NewC->FirstParameter(); |
192 | newl = NewC->LastParameter(); |
193 | } |
194 | } |
195 | // il faut parfois recadrer les ranges 3d / 2d |
196 | TopoDS_Vertex V1, V2; |
197 | TopExp::Vertices(E,V1,V2); |
198 | TopoDS_Shape initEFOR = E.Oriented(TopAbs_FORWARD); // skl |
199 | TopoDS_Edge EFOR = TopoDS::Edge(initEFOR/*E.Oriented(TopAbs_FORWARD)*/); //skl |
200 | NewParameter(V1,EFOR,f,Tol); |
201 | NewParameter(V2,EFOR,l,Tol); |
202 | GeomLib::SameRange(Tol,NewC,newf,newl,f,l,C); |
203 | |
204 | return Standard_True; |
205 | } |
206 | |
207 | //======================================================================= |
208 | //function : NewParameter |
209 | //purpose : |
210 | //======================================================================= |
211 | |
212 | Standard_Boolean BRepTools_TrsfModification::NewParameter |
213 | (const TopoDS_Vertex& V, |
214 | const TopoDS_Edge& E, |
215 | Standard_Real& P, |
216 | Standard_Real& Tol) |
217 | { |
218 | if (V.IsNull()) return Standard_False; // infinite edge may have Null vertex |
219 | |
220 | TopLoc_Location loc; |
221 | Tol = BRep_Tool::Tolerance(V); |
222 | Tol *= Abs(myTrsf.ScaleFactor()); |
223 | P = BRep_Tool::Parameter(V,E); |
224 | |
225 | Standard_Real f,l; |
226 | |
227 | Handle(Geom_Curve) C = BRep_Tool::Curve(E,loc,f,l); |
228 | if (!C.IsNull()) { |
229 | P = C->TransformedParameter(P,myTrsf); |
230 | } |
231 | |
232 | return Standard_True; |
233 | } |
234 | |
235 | //======================================================================= |
236 | //function : Continuity |
237 | //purpose : |
238 | //======================================================================= |
239 | |
240 | GeomAbs_Shape BRepTools_TrsfModification::Continuity |
241 | (const TopoDS_Edge& E, |
242 | const TopoDS_Face& F1, |
243 | const TopoDS_Face& F2, |
244 | const TopoDS_Edge&, |
245 | const TopoDS_Face&, |
246 | const TopoDS_Face&) |
247 | { |
248 | return BRep_Tool::Continuity(E,F1,F2); |
249 | } |
250 | |
251 | |