Salome HOME
Update copyright
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_VertexSolid.cxx
1 // Copyright (C) 2007-2011  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_VertexSolid.cxx
24 // Created:     Wed Jan 12 16:36:40 2005
25 // Author:      Peter KURNEV
26 //              <pkv@irinox>
27 //
28 #include <GEOMAlgo_VertexSolid.ixx>
29
30 #include <gp_Pnt.hxx>
31
32 #include <TopAbs_ShapeEnum.hxx>
33 #include <TopAbs_State.hxx>
34
35 #include <TopTools_ListIteratorOfListOfShape.hxx>
36 #include <TopTools_ListOfShape.hxx>
37 #include <TopTools_IndexedMapOfShape.hxx>
38
39 #include <TopoDS.hxx>
40 #include <TopoDS_Solid.hxx>
41 #include <TopoDS_Vertex.hxx>
42
43 #include <TopExp.hxx>
44
45 #include <BRep_Tool.hxx>
46 #include <BRepClass3d_SolidClassifier.hxx>
47
48 #include <BOPTColStd_Dump.hxx>
49
50 #include <IntTools_Context.hxx>
51
52 #include <BooleanOperations_StateOfShape.hxx>
53 #include <BooleanOperations_ShapesDataStructure.hxx>
54
55 #include <BOPTools_InterferencePool.hxx>
56 #include <BOPTools_CArray1OfVVInterference.hxx>
57 #include <BOPTools_VVInterference.hxx>
58 #include <BOPTools_PaveFiller.hxx>
59 #include <BOPTools_DSFiller.hxx>
60
61 //=======================================================================
62 //function : GEOMAlgo_VertexSolid
63 //purpose  : 
64 //=======================================================================
65 GEOMAlgo_VertexSolid::GEOMAlgo_VertexSolid()
66 :
67   GEOMAlgo_ShapeSolid()
68 {
69 }
70 //=======================================================================
71 //function : ~
72 //purpose  : 
73 //=======================================================================
74 GEOMAlgo_VertexSolid::~GEOMAlgo_VertexSolid()
75 {
76 }
77 //=======================================================================
78 // function: Perform
79 // purpose: 
80 //=======================================================================
81 void GEOMAlgo_VertexSolid::Perform()
82 {
83   myErrorStatus=0;
84   //
85   try {
86     if (myDSFiller==NULL) {
87       myErrorStatus=10;
88       return;
89     }
90     if(!myDSFiller->IsDone()) {
91       myErrorStatus=11;
92       return;
93     }
94     //
95     Standard_Boolean bIsNewFiller;
96     Standard_Integer aNbF;
97     TopTools_IndexedMapOfShape aM;
98     //
99     const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
100     const TopoDS_Shape& aObj=aDS.Object();
101     //
102     TopExp::MapShapes(aObj, TopAbs_FACE, aM);
103     aNbF=aM.Extent();
104     myRank=(aNbF) ? 2 : 1;
105     //
106     bIsNewFiller=myDSFiller->IsNewFiller();
107     
108     if (bIsNewFiller) {
109       Prepare();
110       myDSFiller->SetNewFiller(!bIsNewFiller);
111     }
112     BuildResult();
113   }
114   //
115   catch (Standard_Failure) {
116     myErrorStatus = 12;
117   }
118
119 //=======================================================================
120 // function: Prepare
121 // purpose: 
122 //=======================================================================
123 void GEOMAlgo_VertexSolid::Prepare()
124 {
125   Standard_Integer i, iBeg, iEnd, aNbVV, j, n1, n2, iFound;
126   Standard_Real aTol;
127   TopAbs_State aSt;
128   TopAbs_ShapeEnum aType;
129   BooleanOperations_StateOfShape aState;
130   gp_Pnt aP3D;
131   //
132   const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
133   BooleanOperations_ShapesDataStructure* pDS=(BooleanOperations_ShapesDataStructure*)&aDS;
134   const BOPTools_InterferencePool& aIP=myDSFiller->InterfPool();
135   BOPTools_InterferencePool* pIP=(BOPTools_InterferencePool*) &aIP;
136   BOPTools_CArray1OfVVInterference& aVVs=pIP->VVInterferences();
137   const BOPTools_PaveFiller& aPF=myDSFiller->PaveFiller();
138   BOPTools_PaveFiller* pPF=(BOPTools_PaveFiller*)&aPF; 
139   IntTools_Context& aCtx=pPF->ChangeContext();
140   //
141   const TopoDS_Shape& aObj=aDS.Object();
142   const TopoDS_Shape& aTool=aDS.Tool();
143   //
144   const TopoDS_Solid& aSolid=(myRank==1) ? TopoDS::Solid(aTool) : TopoDS::Solid(aObj);
145   //
146   BRepClass3d_SolidClassifier& aSC=aCtx.SolidClassifier(aSolid);
147   //
148   iBeg=1;
149   iEnd=aDS.NumberOfShapesOfTheObject();
150   if (myRank==2) {
151     iBeg=iEnd+1;
152     iEnd=aDS.NumberOfSourceShapes();
153   }
154   //
155   for (i=iBeg; i<=iEnd; ++i) {
156     aType=aDS.GetShapeType(i);
157     if (aType!=TopAbs_VERTEX) {
158       continue;
159     }
160     //
161     const TopoDS_Vertex& aV=TopoDS::Vertex(aDS.Shape(i));
162     //
163     aState=aDS.GetState(i);
164     if (aState==BooleanOperations_ON ||
165         aState==BooleanOperations_IN ||
166         aState==BooleanOperations_OUT) {
167       continue;
168     }
169     //
170     iFound=0;
171     aNbVV=aVVs.Extent();
172     for (j=1; j<=aNbVV; ++j) {
173       BOPTools_VVInterference& aVV=aVVs(j);
174       aVV.Indices(n1, n2);
175       if (n1==i || n2==i) {
176         pDS->SetState (n1, BooleanOperations_ON);
177         pDS->SetState (n2, BooleanOperations_ON);
178         iFound=1;
179         break;
180       } 
181     }
182     if (iFound) {
183       continue;
184     }
185     // 
186     aP3D=BRep_Tool::Pnt(aV);
187     aTol=1.E-7;
188     aSC.Perform(aP3D, aTol);
189     aSt=aSC.State();
190     if (aSt==TopAbs_IN) {
191       pDS->SetState (i, BooleanOperations_IN);
192     }
193     else if (aSt==TopAbs_OUT) {
194       pDS->SetState (i, BooleanOperations_OUT);
195     }
196   }
197 }
198 //=======================================================================
199 // function: BuildResult
200 // purpose: 
201 //=======================================================================
202 void GEOMAlgo_VertexSolid::BuildResult()
203 {
204   const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
205   //
206   Standard_Integer i, iBeg, iEnd;
207   TopAbs_ShapeEnum aType;
208   BooleanOperations_StateOfShape aState;
209   //
210   myLSIN.Clear();
211   myLSOUT.Clear();
212   myLSON.Clear();
213   //
214   iBeg=1;
215   iEnd=aDS.NumberOfShapesOfTheObject();
216   if (myRank==2) {
217     iBeg=iEnd+1;
218     iEnd=aDS.NumberOfSourceShapes();
219   }
220   //
221   for (i=iBeg; i<=iEnd; ++i) {
222     aType=aDS.GetShapeType(i);
223     if (aType!=TopAbs_VERTEX) {
224       continue;
225     }
226     const TopoDS_Shape& aV=aDS.Shape(i);
227     aState=aDS.GetState(i);
228     //
229     if (aState==BooleanOperations_IN) {
230       myLSIN.Append(aV);
231     }
232     else if (aState==BooleanOperations_OUT) {
233       myLSOUT.Append(aV);
234     }
235     else if (aState==BooleanOperations_ON) {
236       myLSON.Append(aV);
237     }
238   }
239 }