Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_WireSolid.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File:        GEOMAlgo_WireSolid.cxx
24 // Created:     Wed Jan 12 10:19:31 2005
25 // Author:      Peter KURNEV
26 //              <pkv@irinox>
27 //
28 #include <GEOMAlgo_WireSolid.hxx>
29
30 #include <Standard_Failure.hxx>
31
32 #include <TopAbs_ShapeEnum.hxx>
33
34 #include <TopTools_ListIteratorOfListOfShape.hxx>
35
36 #include <BOPTColStd_Dump.hxx>
37
38 #include <BooleanOperations_ShapesDataStructure.hxx>
39 #include <BooleanOperations_StateOfShape.hxx>
40
41 #include <BOPTools_PaveFiller.hxx>
42 #include <BOPTools_SplitShapesPool.hxx>
43 #include <BOPTools_PaveBlock.hxx>
44 #include <BOPTools_ListOfPaveBlock.hxx>
45 #include <BOPTools_DSFiller.hxx>
46 #include <BOPTools_WireStateFiller.hxx>
47
48 //=======================================================================
49 //function : GEOMAlgo_WireSolid
50 //purpose  :
51 //=======================================================================
52 GEOMAlgo_WireSolid::GEOMAlgo_WireSolid()
53 :
54   GEOMAlgo_ShapeSolid()
55 {
56 }
57 //=======================================================================
58 //function : ~
59 //purpose  :
60 //=======================================================================
61 GEOMAlgo_WireSolid::~GEOMAlgo_WireSolid()
62 {
63 }
64 //=======================================================================
65 // function: Perform
66 // purpose:
67 //=======================================================================
68 void GEOMAlgo_WireSolid::Perform()
69 {
70   myErrorStatus=0;
71   //
72   try {
73     if (myDSFiller==NULL) {
74       myErrorStatus=10;
75       return;
76     }
77     if(!myDSFiller->IsDone()) {
78       myErrorStatus=11;
79       return;
80     }
81     //
82     Standard_Boolean bIsNewFiller;
83     //
84     bIsNewFiller=myDSFiller->IsNewFiller();
85
86     if (bIsNewFiller) {
87       Prepare();
88       myDSFiller->SetNewFiller(!bIsNewFiller);
89     }
90     BuildResult();
91   }
92   //
93   catch (Standard_Failure) {
94     myErrorStatus= 12;
95   }
96 }
97 //=======================================================================
98 // function: Prepare
99 // purpose:
100 //=======================================================================
101 void GEOMAlgo_WireSolid::Prepare()
102 {
103   const BOPTools_PaveFiller& aPaveFiller=myDSFiller->PaveFiller();
104   //
105   BOPTools_WireStateFiller aStateFiller(aPaveFiller);
106   aStateFiller.Do();
107   //
108 }
109 //=======================================================================
110 // function: BuildResult
111 // purpose:
112 //=======================================================================
113 void GEOMAlgo_WireSolid::BuildResult()
114 {
115   const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
116   const BOPTools_PaveFiller& aPaveFiller=myDSFiller->PaveFiller();
117   const BOPTools_SplitShapesPool& aSplitShapesPool=aPaveFiller.SplitShapesPool();
118   //
119   Standard_Integer i, aNbPB, nSp, iBeg, iEnd;
120   TopAbs_ShapeEnum aType;
121   BooleanOperations_StateOfShape aState;
122   //
123   myLSIN.Clear();
124   myLSOUT.Clear();
125   myLSON.Clear();
126   //
127   iBeg=1;
128   iEnd=aDS.NumberOfShapesOfTheObject();
129   if (aDS.Tool().ShapeType()==TopAbs_WIRE) {
130     iBeg=iEnd+1;
131     iEnd=aDS.NumberOfSourceShapes();
132   }
133   //
134   for (i=iBeg; i<=iEnd; ++i) {
135     aType=aDS.GetShapeType(i);
136     if (aType==TopAbs_EDGE) {
137       const TopoDS_Shape& aE=aDS.Shape(i);
138       const BOPTools_ListOfPaveBlock& aLPB=aSplitShapesPool(aDS.RefEdge(i));
139       aNbPB=aLPB.Extent();
140       //
141       if (!aNbPB) {
142         aState=aDS.GetState(i);
143         //
144         if (aState==BooleanOperations_IN) {
145           myLSIN.Append(aE);
146         }
147         else if (aState==BooleanOperations_OUT) {
148           myLSOUT.Append(aE);
149         }
150         else if (aState==BooleanOperations_ON) {
151           myLSON.Append(aE);
152         }
153       }
154       //
155       else if (aNbPB==1) {
156         const BOPTools_PaveBlock& aPB=aLPB.First();
157         nSp=aPB.Edge();
158         /*const TopoDS_Shape& aSp=*/aDS.Shape(nSp);
159         aState=aDS.GetState(nSp);
160          //
161         if (aState==BooleanOperations_IN) {
162           myLSIN.Append(aE);
163         }
164         else if (aState==BooleanOperations_OUT) {
165           myLSOUT.Append(aE);
166         }
167         else if (aState==BooleanOperations_ON) {
168           myLSON.Append(aE);
169         }
170       }
171     }
172   }
173 }