1 // Created on: 1994-02-18
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRep_Builder.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepAlgo_Section.hxx>
21 #include <BRepBuilderAPI_MakeFace.hxx>
22 #include <BRepBuilderAPI_MakeShell.hxx>
23 #include <Geom2d_TrimmedCurve.hxx>
24 #include <Geom_Plane.hxx>
25 #include <Geom_Surface.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TopOpeBRepBuild_HBuilder.hxx>
30 #include <TopOpeBRepBuild_Tools.hxx>
31 #include <TopOpeBRepDS_BuildTool.hxx>
32 #include <TopOpeBRepDS_HDataStructure.hxx>
33 #include <TopTools_ListIteratorOfListOfShape.hxx>
35 static TopoDS_Shape MakeShape(const Handle(Geom_Surface)& );
37 Standard_DISABLE_DEPRECATION_WARNINGS
39 //=======================================================================
40 //function : BRepAlgo_Section
42 //=======================================================================
43 BRepAlgo_Section::BRepAlgo_Section(const TopoDS_Shape& S1,
44 const TopoDS_Shape& S2,
45 const Standard_Boolean PerformNow)
46 : BRepAlgo_BooleanOperation(S1, S2)
49 myS1Changed = Standard_True;
50 myS2Changed = Standard_True;
51 if(myS1.IsNull() || S2.IsNull()) {
52 myshapeisnull = Standard_True;
58 //=======================================================================
59 //function : BRepAlgo_Section
61 //=======================================================================
62 BRepAlgo_Section::BRepAlgo_Section(const TopoDS_Shape& S1,
64 const Standard_Boolean PerformNow)
65 : BRepAlgo_BooleanOperation(S1, MakeShape(new Geom_Plane(Pl)))
68 myS1Changed = Standard_True;
69 myS2Changed = Standard_True;
70 if(S1.IsNull() || myS2.IsNull()) {
71 myshapeisnull = Standard_True;
77 //=======================================================================
78 //function : BRepAlgo_Section
80 //=======================================================================
81 BRepAlgo_Section::BRepAlgo_Section(const TopoDS_Shape& S1,
82 const Handle(Geom_Surface)& Sf,
83 const Standard_Boolean PerformNow)
84 : BRepAlgo_BooleanOperation(S1, MakeShape(Sf))
87 myS1Changed = Standard_True;
88 myS2Changed = Standard_True;
89 if(S1.IsNull() || myS2.IsNull()) {
90 myshapeisnull = Standard_True;
96 //=======================================================================
97 //function : BRepAlgo_Section
99 //=======================================================================
100 BRepAlgo_Section::BRepAlgo_Section(const Handle(Geom_Surface)& Sf,
101 const TopoDS_Shape& S2,
102 const Standard_Boolean PerformNow)
103 : BRepAlgo_BooleanOperation(MakeShape(Sf), S2)
106 myS1Changed = Standard_True;
107 myS2Changed = Standard_True;
108 if(myS1.IsNull() || S2.IsNull()) {
109 myshapeisnull = Standard_True;
115 //=======================================================================
116 //function : BRepAlgo_Section
118 //=======================================================================
119 BRepAlgo_Section::BRepAlgo_Section(const Handle(Geom_Surface)& Sf1,
120 const Handle(Geom_Surface)& Sf2,
121 const Standard_Boolean PerformNow)
122 : BRepAlgo_BooleanOperation(MakeShape(Sf1), MakeShape(Sf2))
125 myS1Changed = Standard_True;
126 myS2Changed = Standard_True;
127 if(myS1.IsNull() || myS2.IsNull()) {
128 myshapeisnull = Standard_True;
134 //=======================================================================
136 //purpose : initialize the first Shape
137 //=======================================================================
138 void BRepAlgo_Section::Init1(const TopoDS_Shape& S1)
141 if (!S1.IsEqual(myS1)) {
143 myS1Changed = Standard_True;
148 myS1Changed = Standard_True;
151 if (myS1Changed || myS2Changed)
155 //=======================================================================
157 //purpose : initialize the first Shape
158 //=======================================================================
159 void BRepAlgo_Section::Init1(const gp_Pln& Pl)
161 Init1(MakeShape(new Geom_Plane(Pl)));
164 //=======================================================================
166 //purpose : initialize the first Shape
167 //=======================================================================
168 void BRepAlgo_Section::Init1(const Handle(Geom_Surface)& Sf)
170 Init1(MakeShape(Sf));
173 //=======================================================================
175 //purpose : initialize the second Shape
176 //=======================================================================
177 void BRepAlgo_Section::Init2(const TopoDS_Shape& S2)
180 if (!S2.IsEqual(myS2)) {
182 myS2Changed = Standard_True;
187 myS2Changed = Standard_True;
190 if (myS1Changed || myS2Changed)
194 //=======================================================================
196 //purpose : initialize the second Shape
197 //=======================================================================
198 void BRepAlgo_Section::Init2(const gp_Pln& Pl)
200 Init2(MakeShape(new Geom_Plane(Pl)));
203 //=======================================================================
205 //purpose : initialize the second Shape
206 //=======================================================================
207 void BRepAlgo_Section::Init2(const Handle(Geom_Surface)& Sf)
209 Init2(MakeShape(Sf));
212 //=======================================================================
213 //function : Approximation
214 //purpose : To learn if an approximation of the geometry is calculated
215 //=======================================================================
216 void BRepAlgo_Section::Approximation(const Standard_Boolean Approx)
218 TopOpeBRepDS_BuildTool& BTofBuilder = myHBuilder->ChangeBuildTool();
219 TopOpeBRepTool_GeomTool& GTofBTofBuilder = BTofBuilder.ChangeGeomTool();
221 TopOpeBRepTool_OutCurveType OCT =
222 (Approx) ? TopOpeBRepTool_APPROX :TopOpeBRepTool_BSPLINE1;
223 if (GTofBTofBuilder.TypeC3D() != OCT) {
224 myApproxChanged = Standard_True;
225 GTofBTofBuilder.Define(OCT);
232 //=======================================================================
233 //function : ComputePCurveOn1
234 //purpose : To learn if PCurves are calculated on the faces of the 1st Shape
235 //=======================================================================
236 void BRepAlgo_Section::ComputePCurveOn1(const Standard_Boolean ComputePCurve1)
238 TopOpeBRepDS_BuildTool& BTofBuilder = myHBuilder->ChangeBuildTool();
239 TopOpeBRepTool_GeomTool& GTofBTofBuilder = BTofBuilder.ChangeGeomTool();
241 if( GTofBTofBuilder.CompPC1() != ComputePCurve1) {
242 GTofBTofBuilder.DefinePCurves1(ComputePCurve1);
243 myPCurve1Changed = Standard_True;
250 //=======================================================================
251 //function : ComputePCurve2
252 //purpose : To learn if PCurves are calculated on the faces of the 2nd Shape
253 //=======================================================================
254 void BRepAlgo_Section::ComputePCurveOn2(const Standard_Boolean ComputePCurve2)
256 TopOpeBRepDS_BuildTool& BTofBuilder = myHBuilder->ChangeBuildTool();
257 TopOpeBRepTool_GeomTool& GTofBTofBuilder = BTofBuilder.ChangeGeomTool();
259 if( GTofBTofBuilder.CompPC2() != ComputePCurve2) {
260 GTofBTofBuilder.DefinePCurves2(ComputePCurve2);
261 myPCurve2Changed = Standard_True;
268 //=======================================================================
270 //purpose : compute the section
271 //=======================================================================
272 void BRepAlgo_Section::Build()
280 Standard_Boolean bcw = BuilderCanWork();
281 if ( ! bcw || myshapeisnull) return;
283 BB.MakeCompound(TopoDS::Compound(myShape));
284 Handle(TopOpeBRepBuild_HBuilder) HB = Builder();
285 TopTools_ListIteratorOfListOfShape itloe = HB->Section();
286 for(; itloe.More(); itloe.Next()) BB.Add(myShape,itloe.Value());
288 TopOpeBRepBuild_Tools::CorrectTolerances(myShape);
297 //=======================================================================
298 //function : HasAncestorFaceOn1
300 //=======================================================================
301 Standard_Boolean BRepAlgo_Section::HasAncestorFaceOn1(const TopoDS_Shape& E,
302 TopoDS_Shape& F)const
304 TopoDS_Shape F1,F2; Standard_Integer iC;
305 Standard_Boolean res = myHBuilder->EdgeCurveAncestors(E,F1,F2,iC);
310 //=======================================================================
311 //function : HasAncestorFaceOn2
313 //=======================================================================
314 Standard_Boolean BRepAlgo_Section::HasAncestorFaceOn2(const TopoDS_Shape& E,
315 TopoDS_Shape& F)const
317 TopoDS_Shape F1,F2; Standard_Integer iC;
318 Standard_Boolean res = myHBuilder->EdgeCurveAncestors(E,F1,F2,iC);
323 //=======================================================================
324 //function : InitParameters
325 //purpose : initialize the fields of the class
326 //=======================================================================
327 void BRepAlgo_Section::InitParameters()
329 TopOpeBRepDS_BuildTool& BTofBuilder = myHBuilder->ChangeBuildTool();
330 TopOpeBRepTool_GeomTool& GTofBTofBuilder = BTofBuilder.ChangeGeomTool();
332 GTofBTofBuilder.Define(TopOpeBRepTool_BSPLINE1);
333 GTofBTofBuilder.DefineCurves(Standard_True);
334 GTofBTofBuilder.DefinePCurves1(Standard_False);
335 GTofBTofBuilder.DefinePCurves2(Standard_False);
337 myS1Changed = Standard_False;
338 myS2Changed = Standard_False;
340 myApproxChanged = Standard_False;
342 myPCurve1Changed = Standard_False;
344 myPCurve2Changed = Standard_False;
345 myshapeisnull = Standard_False;
347 //=======================================================================
348 //function : MakeShape
350 //=======================================================================
351 TopoDS_Shape MakeShape(const Handle(Geom_Surface)& S)
353 GeomAbs_Shape c = S->Continuity();
354 if (c >= GeomAbs_C2) return BRepBuilderAPI_MakeFace(S, Precision::Confusion());
355 else return BRepBuilderAPI_MakeShell(S);
358 Standard_ENABLE_DEPRECATION_WARNINGS