Salome HOME
Fix RemoveExtraEdges() to obtain valid shapes. Fix done by SKL.
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_WireSolid.cxx
1 // File:        GEOMAlgo_WireSolid.cxx
2 // Created:     Wed Jan 12 10:19:31 2005
3 // Author:      Peter KURNEV
4 //              <pkv@irinox>
5
6
7 #include <GEOMAlgo_WireSolid.ixx>
8
9 #include <Standard_Failure.hxx>
10
11 #include <TopAbs_ShapeEnum.hxx>
12
13 #include <TopTools_ListIteratorOfListOfShape.hxx>
14
15 #include <BOPTColStd_Dump.hxx>
16
17 #include <BooleanOperations_ShapesDataStructure.hxx>
18 #include <BooleanOperations_StateOfShape.hxx>
19
20 #include <BOPTools_PaveFiller.hxx>
21 #include <BOPTools_SplitShapesPool.hxx>
22 #include <BOPTools_PaveBlock.hxx>
23 #include <BOPTools_ListOfPaveBlock.hxx>
24 #include <BOPTools_DSFiller.hxx>
25 #include <BOPTools_WireStateFiller.hxx>
26
27 //=======================================================================
28 //function : GEOMAlgo_WireSolid
29 //purpose  : 
30 //=======================================================================
31 GEOMAlgo_WireSolid::GEOMAlgo_WireSolid()
32
33   GEOMAlgo_ShapeSolid()
34 {
35 }
36 //=======================================================================
37 //function : ~
38 //purpose  : 
39 //=======================================================================
40 GEOMAlgo_WireSolid::~GEOMAlgo_WireSolid()
41 {
42 }
43 //=======================================================================
44 // function: Perform
45 // purpose: 
46 //=======================================================================
47 void GEOMAlgo_WireSolid::Perform()
48 {
49   myErrorStatus=0;
50   //
51   try {
52     if (myDSFiller==NULL) {
53       myErrorStatus=10;
54       return;
55     }
56     if(!myDSFiller->IsDone()) {
57       myErrorStatus=11;
58       return;
59     }
60     //
61     Standard_Boolean bIsNewFiller;
62     //
63     bIsNewFiller=myDSFiller->IsNewFiller();
64     
65     if (bIsNewFiller) {
66       Prepare();
67       myDSFiller->SetNewFiller(!bIsNewFiller);
68     }
69     BuildResult();
70   }
71   //
72   catch (Standard_Failure) {
73     myErrorStatus= 12;
74   }
75
76 //=======================================================================
77 // function: Prepare
78 // purpose: 
79 //=======================================================================
80 void GEOMAlgo_WireSolid::Prepare()
81 {
82   const BOPTools_PaveFiller& aPaveFiller=myDSFiller->PaveFiller();
83   //
84   BOPTools_WireStateFiller aStateFiller(aPaveFiller);
85   aStateFiller.Do();
86   //
87 }
88 //=======================================================================
89 // function: BuildResult
90 // purpose: 
91 //=======================================================================
92 void GEOMAlgo_WireSolid::BuildResult()
93 {
94   const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
95   const BOPTools_PaveFiller& aPaveFiller=myDSFiller->PaveFiller();
96   const BOPTools_SplitShapesPool& aSplitShapesPool=aPaveFiller.SplitShapesPool();
97   //
98   Standard_Integer i, aNbPB, nSp, iBeg, iEnd;
99   TopAbs_ShapeEnum aType;
100   BooleanOperations_StateOfShape aState;
101   //
102   myLSIN.Clear();
103   myLSOUT.Clear();
104   myLSON.Clear();
105   //
106   iBeg=1;
107   iEnd=aDS.NumberOfShapesOfTheObject();
108   if (aDS.Tool().ShapeType()==TopAbs_WIRE) {
109     iBeg=iEnd+1;
110     iEnd=aDS.NumberOfSourceShapes();
111   }
112   //
113   for (i=iBeg; i<=iEnd; ++i) {
114     aType=aDS.GetShapeType(i);
115     if (aType==TopAbs_EDGE) {
116       const TopoDS_Shape& aE=aDS.Shape(i);
117       const BOPTools_ListOfPaveBlock& aLPB=aSplitShapesPool(aDS.RefEdge(i));
118       aNbPB=aLPB.Extent();
119       //
120       if (!aNbPB) {
121         aState=aDS.GetState(i);
122         //
123         if (aState==BooleanOperations_IN) {
124           myLSIN.Append(aE);
125         }
126         else if (aState==BooleanOperations_OUT) {
127           myLSOUT.Append(aE);
128         }
129         else if (aState==BooleanOperations_ON) {
130           myLSON.Append(aE);
131         }
132       }
133       //
134       else if (aNbPB==1) {
135         const BOPTools_PaveBlock& aPB=aLPB.First();
136         nSp=aPB.Edge();
137         const TopoDS_Shape& aSp=aDS.Shape(nSp);
138         aState=aDS.GetState(nSp);
139          //
140         if (aState==BooleanOperations_IN) {
141           myLSIN.Append(aE);
142         }
143         else if (aState==BooleanOperations_OUT) {
144           myLSOUT.Append(aE);
145         }
146         else if (aState==BooleanOperations_ON) {
147           myLSON.Append(aE);
148         } 
149       }
150     }
151   }
152 }