Salome HOME
Update mail address
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_VertexSolid.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 // File:        GEOMAlgo_VertexSolid.cxx
21 // Created:     Wed Jan 12 16:36:40 2005
22 // Author:      Peter KURNEV
23 //              <pkv@irinox>
24
25
26 #include <GEOMAlgo_VertexSolid.ixx>
27
28 #include <gp_Pnt.hxx>
29
30 #include <TopAbs_ShapeEnum.hxx>
31 #include <TopAbs_State.hxx>
32
33 #include <TopTools_ListIteratorOfListOfShape.hxx>
34 #include <TopTools_ListOfShape.hxx>
35 #include <TopTools_IndexedMapOfShape.hxx>
36
37 #include <TopoDS.hxx>
38 #include <TopoDS_Solid.hxx>
39 #include <TopoDS_Vertex.hxx>
40
41 #include <TopExp.hxx>
42
43 #include <BRep_Tool.hxx>
44 #include <BRepClass3d_SolidClassifier.hxx>
45
46 #include <BOPTColStd_Dump.hxx>
47
48 #include <IntTools_Context.hxx>
49
50 #include <BooleanOperations_StateOfShape.hxx>
51 #include <BooleanOperations_ShapesDataStructure.hxx>
52
53 #include <BOPTools_InterferencePool.hxx>
54 #include <BOPTools_CArray1OfVVInterference.hxx>
55 #include <BOPTools_VVInterference.hxx>
56 #include <BOPTools_PaveFiller.hxx>
57 #include <BOPTools_DSFiller.hxx>
58
59 //=======================================================================
60 //function : GEOMAlgo_VertexSolid
61 //purpose  : 
62 //=======================================================================
63 GEOMAlgo_VertexSolid::GEOMAlgo_VertexSolid()
64 :
65   GEOMAlgo_ShapeSolid()
66 {
67 }
68 //=======================================================================
69 //function : ~
70 //purpose  : 
71 //=======================================================================
72 GEOMAlgo_VertexSolid::~GEOMAlgo_VertexSolid()
73 {
74 }
75 //=======================================================================
76 // function: Perform
77 // purpose: 
78 //=======================================================================
79 void GEOMAlgo_VertexSolid::Perform()
80 {
81   myErrorStatus=0;
82   //
83   try {
84     if (myDSFiller==NULL) {
85       myErrorStatus=10;
86       return;
87     }
88     if(!myDSFiller->IsDone()) {
89       myErrorStatus=11;
90       return;
91     }
92     //
93     Standard_Boolean bIsNewFiller;
94     Standard_Integer aNbF;
95     TopTools_IndexedMapOfShape aM;
96     //
97     const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
98     const TopoDS_Shape& aObj=aDS.Object();
99     //
100     TopExp::MapShapes(aObj, TopAbs_FACE, aM);
101     aNbF=aM.Extent();
102     myRank=(aNbF) ? 2 : 1;
103     //
104     bIsNewFiller=myDSFiller->IsNewFiller();
105     
106     if (bIsNewFiller) {
107       Prepare();
108       myDSFiller->SetNewFiller(!bIsNewFiller);
109     }
110     BuildResult();
111   }
112   //
113   catch (Standard_Failure) {
114     myErrorStatus = 12;
115   }
116
117 //=======================================================================
118 // function: Prepare
119 // purpose: 
120 //=======================================================================
121 void GEOMAlgo_VertexSolid::Prepare()
122 {
123   Standard_Integer i, iBeg, iEnd, aNbVV, j, n1, n2, iFound;
124   Standard_Real aTol;
125   TopAbs_State aSt;
126   TopAbs_ShapeEnum aType;
127   BooleanOperations_StateOfShape aState;
128   gp_Pnt aP3D;
129   //
130   const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
131   BooleanOperations_ShapesDataStructure* pDS=(BooleanOperations_ShapesDataStructure*)&aDS;
132   const BOPTools_InterferencePool& aIP=myDSFiller->InterfPool();
133   BOPTools_InterferencePool* pIP=(BOPTools_InterferencePool*) &aIP;
134   BOPTools_CArray1OfVVInterference& aVVs=pIP->VVInterferences();
135   const BOPTools_PaveFiller& aPF=myDSFiller->PaveFiller();
136   BOPTools_PaveFiller* pPF=(BOPTools_PaveFiller*)&aPF; 
137   IntTools_Context& aCtx=pPF->ChangeContext();
138   //
139   const TopoDS_Shape& aObj=aDS.Object();
140   const TopoDS_Shape& aTool=aDS.Tool();
141   //
142   const TopoDS_Solid& aSolid=(myRank==1) ? TopoDS::Solid(aTool) : TopoDS::Solid(aObj);
143   const TopoDS_Shape& aSV   =(myRank==1)? aObj : aTool;
144   //
145   BRepClass3d_SolidClassifier& aSC=aCtx.SolidClassifier(aSolid);
146   //
147   iBeg=1;
148   iEnd=aDS.NumberOfShapesOfTheObject();
149   if (myRank==2) {
150     iBeg=iEnd+1;
151     iEnd=aDS.NumberOfSourceShapes();
152   }
153   //
154   for (i=iBeg; i<=iEnd; ++i) {
155     aType=aDS.GetShapeType(i);
156     if (aType!=TopAbs_VERTEX) {
157       continue;
158     }
159     //
160     const TopoDS_Vertex& aV=TopoDS::Vertex(aDS.Shape(i));
161     //
162     aState=aDS.GetState(i);
163     if (aState==BooleanOperations_ON ||
164         aState==BooleanOperations_IN ||
165         aState==BooleanOperations_OUT) {
166       continue;
167     }
168     //
169     iFound=0;
170     aNbVV=aVVs.Extent();
171     for (j=1; j<=aNbVV; ++j) {
172       BOPTools_VVInterference& aVV=aVVs(j);
173       aVV.Indices(n1, n2);
174       if (n1==i || n2==i) {
175         pDS->SetState (n1, BooleanOperations_ON);
176         pDS->SetState (n2, BooleanOperations_ON);
177         iFound=1;
178         break;
179       } 
180     }
181     if (iFound) {
182       continue;
183     }
184     // 
185     aP3D=BRep_Tool::Pnt(aV);
186     aTol=1.E-7;
187     aSC.Perform(aP3D, aTol);
188     aSt=aSC.State();
189     if (aSt==TopAbs_IN) {
190       pDS->SetState (i, BooleanOperations_IN);
191     }
192     else if (aSt==TopAbs_OUT) {
193       pDS->SetState (i, BooleanOperations_OUT);
194     }
195   }
196 }
197 //=======================================================================
198 // function: BuildResult
199 // purpose: 
200 //=======================================================================
201 void GEOMAlgo_VertexSolid::BuildResult()
202 {
203   const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
204   //
205   Standard_Integer i, iBeg, iEnd;
206   TopAbs_ShapeEnum aType;
207   BooleanOperations_StateOfShape aState;
208   //
209   myLSIN.Clear();
210   myLSOUT.Clear();
211   myLSON.Clear();
212   //
213   iBeg=1;
214   iEnd=aDS.NumberOfShapesOfTheObject();
215   if (myRank==2) {
216     iBeg=iEnd+1;
217     iEnd=aDS.NumberOfSourceShapes();
218   }
219   //
220   for (i=iBeg; i<=iEnd; ++i) {
221     aType=aDS.GetShapeType(i);
222     if (aType!=TopAbs_VERTEX) {
223       continue;
224     }
225     const TopoDS_Shape& aV=aDS.Shape(i);
226     aState=aDS.GetState(i);
227     //
228     if (aState==BooleanOperations_IN) {
229       myLSIN.Append(aV);
230     }
231     else if (aState==BooleanOperations_OUT) {
232       myLSOUT.Append(aV);
233     }
234     else if (aState==BooleanOperations_ON) {
235       myLSON.Append(aV);
236     }
237   }
238 }