1 // File: GEOMAlgo_ShellSolid.cxx
2 // Created: Wed Jan 12 12:49:45 2005
3 // Author: Peter KURNEV
7 #include <GEOMAlgo_ShellSolid.ixx>
9 #include <Standard_Failure.hxx>
11 #include <gp_Pnt2d.hxx>
16 #include <TopoDS_Face.hxx>
17 #include <TopoDS_Edge.hxx>
18 #include <TopoDS_Shape.hxx>
19 #include <TopoDS_Solid.hxx>
21 #include <BRep_Tool.hxx>
22 #include <BRepTools.hxx>
24 #include <TopTools_ListOfShape.hxx>
25 #include <TopTools_ListIteratorOfListOfShape.hxx>
26 #include <TopExp_Explorer.hxx>
28 #include <BRepClass3d_SolidClassifier.hxx>
30 #include <IntTools_Context.hxx>
31 #include <BOPTColStd_Dump.hxx>
32 #include <BooleanOperations_ShapesDataStructure.hxx>
34 #include <BOPTools_PaveFiller.hxx>
35 #include <BOPTools_SolidStateFiller.hxx>
36 #include <BOPTools_PCurveMaker.hxx>
37 #include <BOPTools_DEProcessor.hxx>
38 #include <BOPTools_InterferencePool.hxx>
39 #include <BOPTools_CArray1OfSSInterference.hxx>
40 #include <BOPTools_ListOfPaveBlock.hxx>
41 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
42 #include <BOPTools_PaveBlock.hxx>
43 #include <BOPTools_SSInterference.hxx>
44 #include <BOPTools_SequenceOfCurves.hxx>
45 #include <BOPTools_Curve.hxx>
46 #include <BOPTools_PaveFiller.hxx>
47 #include <BOPTools_SplitShapesPool.hxx>
48 #include <BOPTools_Tools3D.hxx>
49 #include <BOPTools_DSFiller.hxx>
51 #include <BOP_WireEdgeSet.hxx>
52 #include <BOP_SDFWESFiller.hxx>
53 #include <BOP_FaceBuilder.hxx>
55 //=======================================================================
56 //function : GEOMAlgo_ShellSolid
58 //=======================================================================
59 GEOMAlgo_ShellSolid::GEOMAlgo_ShellSolid()
64 //=======================================================================
67 //=======================================================================
68 GEOMAlgo_ShellSolid::~GEOMAlgo_ShellSolid()
71 //=======================================================================
74 //=======================================================================
75 void GEOMAlgo_ShellSolid::Perform()
80 if (myDSFiller==NULL) {
84 if(!myDSFiller->IsDone()) {
89 Standard_Boolean bIsNewFiller;
91 bIsNewFiller=myDSFiller->IsNewFiller();
94 myDSFiller->SetNewFiller(!bIsNewFiller);
97 myRank=(myDSFiller->DS().Object().ShapeType()==TopAbs_SHELL) ? 1 : 2;
100 catch (Standard_Failure) {
104 //=======================================================================
107 //=======================================================================
108 void GEOMAlgo_ShellSolid::Prepare()
110 const BOPTools_PaveFiller& aPaveFiller=myDSFiller->PaveFiller();
113 BOPTools_SolidStateFiller aStateFiller(aPaveFiller);
116 // 2 Project section edges on corresp. faces -> P-Curves on edges.
117 BOPTools_PCurveMaker aPCurveMaker(aPaveFiller);
120 // 3. Degenerated Edges Processing
121 BOPTools_DEProcessor aDEProcessor(aPaveFiller);
124 // 4. Detect Same Domain Faces
127 //=================================================================================
128 // function: BuildResult
130 //=================================================================================
131 void GEOMAlgo_ShellSolid::BuildResult()
133 Standard_Boolean bIsTouchCase;
134 Standard_Integer i, j, nF1, nF2, aNbFFs, aNbS, aNbCurves, nSp, iRank1;
135 Standard_Integer nE, nF, aNbPB, iBeg, iEnd;
136 BooleanOperations_StateOfShape aState;
137 TopExp_Explorer anExp;
138 TopAbs_ShapeEnum aType;
142 const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
143 const BOPTools_InterferencePool& anInterfPool=myDSFiller->InterfPool();
144 BOPTools_InterferencePool* pInterfPool=(BOPTools_InterferencePool*) &anInterfPool;
145 BOPTools_CArray1OfSSInterference& aFFs=pInterfPool->SSInterferences();
146 const BOPTools_PaveFiller& aPaveFiller=myDSFiller->PaveFiller();
147 const BOPTools_SplitShapesPool& aSplitShapesPool=aPaveFiller.SplitShapesPool();
149 // 1. process pf non-interferring faces
151 iEnd=aDS.NumberOfShapesOfTheObject();
154 iEnd=aDS.NumberOfSourceShapes();
157 for (i=iBeg; i<=iEnd; ++i) {
158 aType=aDS.GetShapeType(i);
159 if (aType!=TopAbs_FACE) {
163 const TopoDS_Face& aF1=TopoDS::Face(aDS.Shape(i));
164 aState=aDS.GetState(i);
165 if (aState==BooleanOperations_IN) {
168 else if (aState==BooleanOperations_OUT) {
173 // 2. process pf interferred faces
174 aNbFFs=aFFs.Extent();
175 for (i=1; i<=aNbFFs; ++i) {
176 BOPTools_SSInterference& aFFi=aFFs(i);
180 iRank1=aDS.Rank(nF1);
181 nF=(iRank1==myRank) ? nF1 : nF2;
182 const TopoDS_Face& aF1=TopoDS::Face(aDS.Shape(nF));
184 bIsTouchCase=aFFi.IsTangentFaces();
191 // Has section edges ?
193 BOPTools_SequenceOfCurves& aBCurves=aFFi.Curves();
194 aNbCurves=aBCurves.Length();
195 for (j=1; j<=aNbCurves; j++) {
196 BOPTools_Curve& aBC=aBCurves(j);
197 const BOPTools_ListOfPaveBlock& aSectEdges=aBC.NewPaveBlocks();
198 aNbS=aSectEdges.Extent();
204 if (aNbS) { // it has
208 anExp.Init(aF1, TopAbs_EDGE);
209 for (; anExp.More(); anExp.Next()) {
210 const TopoDS_Edge& aE=TopoDS::Edge(anExp.Current());
211 if (BRep_Tool::Degenerated(aE)) {
215 nE=aDS.ShapeIndex(aE, myRank);
216 const BOPTools_ListOfPaveBlock& aLPB=aSplitShapesPool(aDS.RefEdge(nE));
222 const BOPTools_PaveBlock& aPB=aLPB.First();
225 const TopoDS_Shape& aSp=aDS.Shape(nSp);
227 aState=aDS.GetState(nSp);
228 if (aState==BooleanOperations_IN) {
231 else if (aState==BooleanOperations_OUT) {
234 else if (aState==BooleanOperations_ON) {
238 //const TopoDS_Face& aF2=TopoDS::Face(aDS.Shape((iRank1==myRank)? nF2 : nF1));
239 //aTol=BRep_Tool::Tolerance(aF2);
242 BOPTools_Tools3D::PointNearEdge(aE, aF1, aP2D, aP3D);
243 const TopoDS_Solid& aRefSolid=(myRank==1) ?
244 TopoDS::Solid(aDS.Tool()) : TopoDS::Solid(aDS.Object());
246 BOPTools_PaveFiller* pPF=(BOPTools_PaveFiller*)& aPaveFiller;
247 IntTools_Context& aCtx=pPF->ChangeContext();
249 BRepClass3d_SolidClassifier& aSC=aCtx.SolidClassifier(aRefSolid);
250 aSC.Perform(aP3D, aTol);
252 if (aSt==TopAbs_IN) {
255 else if (aSt==TopAbs_OUT) {
261 } //for (; anExp.More(); anExp.Next())
264 //=======================================================================
265 // function: DetectSDFaces
267 //=======================================================================
268 void GEOMAlgo_ShellSolid::DetectSDFaces()
270 const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
271 BOPTools_InterferencePool* pIntrPool=(BOPTools_InterferencePool*)&myDSFiller->InterfPool();
272 BOPTools_CArray1OfSSInterference& aFFs=pIntrPool->SSInterferences();
274 Standard_Boolean bFlag;
275 Standard_Integer i, aNb, nF1, nF2, iZone, aNbSps, iSenseFlag;
279 for (i=1; i<=aNb; i++) {
280 bFlag=Standard_False;
282 BOPTools_SSInterference& aFF=aFFs(i);
286 const TopoDS_Face& aF1=TopoDS::Face(aDS.Shape(nF1));
287 const TopoDS_Face& aF2=TopoDS::Face(aDS.Shape(nF2));
290 const BOPTools_ListOfPaveBlock& aLPB=aFF.PaveBlocks();
291 aNbSps=aLPB.Extent();
297 const BOPTools_PaveBlock& aPB=aLPB.First();
298 const TopoDS_Edge& aSpE=TopoDS::Edge(aDS.Shape(aPB.Edge()));
300 BOPTools_Tools3D::GetNormalToFaceOnEdge (aSpE, aF1, aDNF1);
301 BOPTools_Tools3D::GetNormalToFaceOnEdge (aSpE, aF2, aDNF2);
302 iSenseFlag=BOPTools_Tools3D::SenseFlag (aDNF1, aDNF2);
304 if (iSenseFlag==1 || iSenseFlag==-1) {
307 TopoDS_Face aF1FWD=aF1;
308 aF1FWD.Orientation (TopAbs_FORWARD);
310 BOP_WireEdgeSet aWES (aF1FWD);
311 BOP_SDFWESFiller aWESFiller(nF1, nF2, *myDSFiller);
312 aWESFiller.SetSenseFlag(iSenseFlag);
313 aWESFiller.SetOperation(BOP_COMMON);
318 const TopTools_ListOfShape& aLF=aFB.NewFaces();
321 TopTools_ListIteratorOfListOfShape anIt(aLF);
322 for (; anIt.More(); anIt.Next()) {
323 const TopoDS_Shape& aFR=anIt.Value();
325 if (aFR.ShapeType()==TopAbs_FACE) {
326 const TopoDS_Face& aFaceResult=TopoDS::Face(aFR);
328 Standard_Boolean bIsValidIn2D, bNegativeFlag;
329 bIsValidIn2D=BOPTools_Tools3D::IsValidArea (aFaceResult, bNegativeFlag);
331 //if(CheckSameDomainFaceInside(aFaceResult, aF2)) {
342 aFF.SetStatesMap(aWESFiller.StatesMap());
347 aFF.SetTangentFacesFlag(bFlag);
348 aFF.SetSenseFlag (iSenseFlag);
349 }// end of for (i=1; i<=aNb; i++)