b311480e |
1 | // Created on: 1994-02-18 |
2 | // Created by: Remi LEQUETTE |
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 | // |
973c2be1 |
8 | // This library is free software; you can redistribute it and / or modify it |
9 | // under the terms of the GNU Lesser General Public version 2.1 as published |
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 <BRepAlgo_Section.ixx> |
18 | #include <BRepBuilderAPI_MakeShell.hxx> |
19 | #include <BRepBuilderAPI_MakeFace.hxx> |
20 | #include <TopoDS.hxx> |
21 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
22 | #include <TopOpeBRepDS_HDataStructure.hxx> |
23 | #include <Geom_Plane.hxx> |
24 | #include <Geom_Surface.hxx> |
25 | #include <BRep_Builder.hxx> |
26 | #include <BRep_Tool.hxx> |
27 | #include <TopOpeBRepBuild_HBuilder.hxx> |
28 | #include <TopOpeBRepDS_BuildTool.hxx> |
29 | #include <Geom2d_TrimmedCurve.hxx> |
30 | #include <TopOpeBRepBuild_Tools.hxx> |
31 | |
32 | static TopoDS_Shape MakeShape(const Handle(Geom_Surface)& ); |
33 | |
34 | //======================================================================= |
35 | //function : BRepAlgo_Section |
36 | //purpose : |
37 | //======================================================================= |
38 | BRepAlgo_Section::BRepAlgo_Section(const TopoDS_Shape& S1, |
39 | const TopoDS_Shape& S2, |
40 | const Standard_Boolean PerformNow) |
41 | : BRepAlgo_BooleanOperation(S1, S2) |
42 | { |
43 | InitParameters(); |
44 | myS1Changed = Standard_True; |
45 | myS2Changed = Standard_True; |
46 | if(myS1.IsNull() || S2.IsNull()) { |
47 | myshapeisnull = Standard_True; |
48 | } |
49 | if (PerformNow) |
50 | Build(); |
51 | } |
52 | |
53 | //======================================================================= |
54 | //function : BRepAlgo_Section |
55 | //purpose : |
56 | //======================================================================= |
57 | BRepAlgo_Section::BRepAlgo_Section(const TopoDS_Shape& S1, |
58 | const gp_Pln& Pl, |
59 | const Standard_Boolean PerformNow) |
60 | : BRepAlgo_BooleanOperation(S1, MakeShape(new Geom_Plane(Pl))) |
61 | { |
62 | InitParameters(); |
63 | myS1Changed = Standard_True; |
64 | myS2Changed = Standard_True; |
65 | if(S1.IsNull() || myS2.IsNull()) { |
66 | myshapeisnull = Standard_True; |
67 | } |
68 | if (PerformNow) |
69 | Build(); |
70 | } |
71 | |
72 | //======================================================================= |
73 | //function : BRepAlgo_Section |
74 | //purpose : |
75 | //======================================================================= |
76 | BRepAlgo_Section::BRepAlgo_Section(const TopoDS_Shape& S1, |
77 | const Handle(Geom_Surface)& Sf, |
78 | const Standard_Boolean PerformNow) |
79 | : BRepAlgo_BooleanOperation(S1, MakeShape(Sf)) |
80 | { |
81 | InitParameters(); |
82 | myS1Changed = Standard_True; |
83 | myS2Changed = Standard_True; |
84 | if(S1.IsNull() || myS2.IsNull()) { |
85 | myshapeisnull = Standard_True; |
86 | } |
87 | if (PerformNow) |
88 | Build(); |
89 | } |
90 | |
91 | //======================================================================= |
92 | //function : BRepAlgo_Section |
93 | //purpose : |
94 | //======================================================================= |
95 | BRepAlgo_Section::BRepAlgo_Section(const Handle(Geom_Surface)& Sf, |
96 | const TopoDS_Shape& S2, |
97 | const Standard_Boolean PerformNow) |
98 | : BRepAlgo_BooleanOperation(MakeShape(Sf), S2) |
99 | { |
100 | InitParameters(); |
101 | myS1Changed = Standard_True; |
102 | myS2Changed = Standard_True; |
103 | if(myS1.IsNull() || S2.IsNull()) { |
104 | myshapeisnull = Standard_True; |
105 | } |
106 | if (PerformNow) |
107 | Build(); |
108 | } |
109 | |
110 | //======================================================================= |
111 | //function : BRepAlgo_Section |
112 | //purpose : |
113 | //======================================================================= |
114 | BRepAlgo_Section::BRepAlgo_Section(const Handle(Geom_Surface)& Sf1, |
115 | const Handle(Geom_Surface)& Sf2, |
116 | const Standard_Boolean PerformNow) |
117 | : BRepAlgo_BooleanOperation(MakeShape(Sf1), MakeShape(Sf2)) |
118 | { |
119 | InitParameters(); |
120 | myS1Changed = Standard_True; |
121 | myS2Changed = Standard_True; |
122 | if(myS1.IsNull() || myS2.IsNull()) { |
123 | myshapeisnull = Standard_True; |
124 | } |
125 | if (PerformNow) |
126 | Build(); |
127 | } |
128 | |
129 | //======================================================================= |
130 | //function : Init1 |
131 | //purpose : initialize the first Shape |
132 | //======================================================================= |
133 | void BRepAlgo_Section::Init1(const TopoDS_Shape& S1) |
134 | { |
135 | if(!S1.IsNull()) { |
136 | if (!S1.IsEqual(myS1)) { |
137 | myS1 = S1; |
138 | myS1Changed = Standard_True; |
139 | } |
140 | } else { |
141 | if(!myS1.IsNull()) { |
142 | myS1 = S1; |
143 | myS1Changed = Standard_True; |
144 | } |
145 | } |
146 | if (myS1Changed || myS2Changed) |
147 | NotDone(); |
148 | } |
149 | |
150 | //======================================================================= |
151 | //function : Init1 |
152 | //purpose : initialize the first Shape |
153 | //======================================================================= |
154 | void BRepAlgo_Section::Init1(const gp_Pln& Pl) |
155 | { |
156 | Init1(MakeShape(new Geom_Plane(Pl))); |
157 | } |
158 | |
159 | //======================================================================= |
160 | //function : Init1 |
161 | //purpose : initialize the first Shape |
162 | //======================================================================= |
163 | void BRepAlgo_Section::Init1(const Handle(Geom_Surface)& Sf) |
164 | { |
165 | Init1(MakeShape(Sf)); |
166 | } |
167 | |
168 | //======================================================================= |
169 | //function : Init2 |
170 | //purpose : initialize the second Shape |
171 | //======================================================================= |
172 | void BRepAlgo_Section::Init2(const TopoDS_Shape& S2) |
173 | { |
174 | if(!S2.IsNull()) { |
175 | if (!S2.IsEqual(myS2)) { |
176 | myS2 = S2; |
177 | myS2Changed = Standard_True; |
178 | } |
179 | } else { |
180 | if(!myS2.IsNull()) { |
181 | myS2 = S2; |
182 | myS2Changed = Standard_True; |
183 | } |
184 | } |
185 | if (myS1Changed || myS2Changed) |
186 | NotDone(); |
187 | } |
188 | |
189 | //======================================================================= |
190 | //function : Init2 |
191 | //purpose : initialize the second Shape |
192 | //======================================================================= |
193 | void BRepAlgo_Section::Init2(const gp_Pln& Pl) |
194 | { |
195 | Init2(MakeShape(new Geom_Plane(Pl))); |
196 | } |
197 | |
198 | //======================================================================= |
199 | //function : Init2 |
200 | //purpose : initialize the second Shape |
201 | //======================================================================= |
202 | void BRepAlgo_Section::Init2(const Handle(Geom_Surface)& Sf) |
203 | { |
204 | Init2(MakeShape(Sf)); |
205 | } |
206 | |
207 | //======================================================================= |
208 | //function : Approximation |
209 | //purpose : To learn if an approximation of the geometry is calculated |
210 | //======================================================================= |
211 | void BRepAlgo_Section::Approximation(const Standard_Boolean Approx) |
212 | { |
213 | TopOpeBRepDS_BuildTool& BTofBuilder = myHBuilder->ChangeBuildTool(); |
214 | TopOpeBRepTool_GeomTool& GTofBTofBuilder = BTofBuilder.ChangeGeomTool(); |
215 | |
216 | TopOpeBRepTool_OutCurveType OCT = |
217 | (Approx) ? TopOpeBRepTool_APPROX :TopOpeBRepTool_BSPLINE1; |
218 | if (GTofBTofBuilder.TypeC3D() != OCT) { |
219 | myApproxChanged = Standard_True; |
220 | GTofBTofBuilder.Define(OCT); |
221 | } |
222 | |
223 | if (myApproxChanged) |
224 | NotDone(); |
225 | } |
226 | |
227 | //======================================================================= |
228 | //function : ComputePCurveOn1 |
229 | //purpose : To learn if PCurves are calculated on the faces of the 1st Shape |
230 | //======================================================================= |
231 | void BRepAlgo_Section::ComputePCurveOn1(const Standard_Boolean ComputePCurve1) |
232 | { |
233 | TopOpeBRepDS_BuildTool& BTofBuilder = myHBuilder->ChangeBuildTool(); |
234 | TopOpeBRepTool_GeomTool& GTofBTofBuilder = BTofBuilder.ChangeGeomTool(); |
235 | |
236 | if( GTofBTofBuilder.CompPC1() != ComputePCurve1) { |
237 | GTofBTofBuilder.DefinePCurves1(ComputePCurve1); |
238 | myPCurve1Changed = Standard_True; |
239 | } |
240 | |
241 | if(myPCurve1Changed) |
242 | NotDone(); |
243 | } |
244 | |
245 | //======================================================================= |
246 | //function : ComputePCurve2 |
247 | //purpose : To learn if PCurves are calculated on the faces of the 2nd Shape |
248 | //======================================================================= |
249 | void BRepAlgo_Section::ComputePCurveOn2(const Standard_Boolean ComputePCurve2) |
250 | { |
251 | TopOpeBRepDS_BuildTool& BTofBuilder = myHBuilder->ChangeBuildTool(); |
252 | TopOpeBRepTool_GeomTool& GTofBTofBuilder = BTofBuilder.ChangeGeomTool(); |
253 | |
254 | if( GTofBTofBuilder.CompPC2() != ComputePCurve2) { |
255 | GTofBTofBuilder.DefinePCurves2(ComputePCurve2); |
256 | myPCurve2Changed = Standard_True; |
257 | } |
258 | |
259 | if(myPCurve2Changed) |
260 | NotDone(); |
261 | } |
262 | |
263 | //======================================================================= |
264 | //function : Build |
265 | //purpose : compute the section |
266 | //======================================================================= |
267 | void BRepAlgo_Section::Build() |
268 | { |
269 | if (myS1Changed || |
270 | myS2Changed || |
271 | myApproxChanged || |
272 | myPCurve1Changed || |
273 | myPCurve2Changed) { |
274 | PerformDS(); |
275 | Standard_Boolean bcw = BuilderCanWork(); |
276 | if ( ! bcw || myshapeisnull) return; |
277 | BRep_Builder BB; |
278 | BB.MakeCompound(TopoDS::Compound(myShape)); |
279 | Handle(TopOpeBRepBuild_HBuilder) HB = Builder(); |
280 | TopTools_ListIteratorOfListOfShape itloe = HB->Section(); |
281 | for(; itloe.More(); itloe.Next()) BB.Add(myShape,itloe.Value()); |
282 | |
283 | TopOpeBRepBuild_Tools::CorrectTolerances(myShape); |
284 | |
285 | |
286 | Done(); |
287 | } |
288 | |
289 | |
290 | } |
291 | |
292 | //======================================================================= |
293 | //function : HasAncestorFaceOn1 |
294 | //purpose : |
295 | //======================================================================= |
296 | Standard_Boolean BRepAlgo_Section::HasAncestorFaceOn1(const TopoDS_Shape& E, |
297 | TopoDS_Shape& F)const |
298 | { |
299 | TopoDS_Shape F1,F2; Standard_Integer iC; |
300 | Standard_Boolean res = myHBuilder->EdgeCurveAncestors(E,F1,F2,iC); |
301 | if ( res ) F = F1; |
302 | return res; |
303 | } |
304 | |
305 | //======================================================================= |
306 | //function : HasAncestorFaceOn2 |
307 | //purpose : |
308 | //======================================================================= |
309 | Standard_Boolean BRepAlgo_Section::HasAncestorFaceOn2(const TopoDS_Shape& E, |
310 | TopoDS_Shape& F)const |
311 | { |
312 | TopoDS_Shape F1,F2; Standard_Integer iC; |
313 | Standard_Boolean res = myHBuilder->EdgeCurveAncestors(E,F1,F2,iC); |
314 | if ( res ) F = F2; |
315 | return res; |
316 | } |
317 | |
7fd59977 |
318 | //======================================================================= |
319 | //function : InitParameters |
320 | //purpose : initialize the fields of the class |
321 | //======================================================================= |
322 | void BRepAlgo_Section::InitParameters() |
323 | { |
324 | TopOpeBRepDS_BuildTool& BTofBuilder = myHBuilder->ChangeBuildTool(); |
325 | TopOpeBRepTool_GeomTool& GTofBTofBuilder = BTofBuilder.ChangeGeomTool(); |
326 | |
327 | GTofBTofBuilder.Define(TopOpeBRepTool_BSPLINE1); |
328 | GTofBTofBuilder.DefineCurves(Standard_True); |
329 | GTofBTofBuilder.DefinePCurves1(Standard_False); |
330 | GTofBTofBuilder.DefinePCurves2(Standard_False); |
331 | |
332 | myS1Changed = Standard_False; |
333 | myS2Changed = Standard_False; |
334 | // |
335 | myApproxChanged = Standard_False; |
336 | // |
337 | myPCurve1Changed = Standard_False; |
338 | // |
339 | myPCurve2Changed = Standard_False; |
340 | myshapeisnull = Standard_False; |
341 | } |
342 | //======================================================================= |
343 | //function : MakeShape |
344 | //purpose : |
345 | //======================================================================= |
346 | TopoDS_Shape MakeShape(const Handle(Geom_Surface)& S) |
347 | { |
348 | GeomAbs_Shape c = S->Continuity(); |
1c72dff6 |
349 | if (c >= GeomAbs_C2) return BRepBuilderAPI_MakeFace(S, Precision::Confusion()); |
7fd59977 |
350 | else return BRepBuilderAPI_MakeShell(S); |
351 | } |