Salome HOME
Preparation of intermediate revision
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_VertexSolid.cxx
1 //  Copyright (C) 2007-2008  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 // File:        GEOMAlgo_VertexSolid.cxx
23 // Created:     Wed Jan 12 16:36:40 2005
24 // Author:      Peter KURNEV
25 //              <pkv@irinox>
26 //
27 #include <GEOMAlgo_VertexSolid.ixx>
28
29 #include <gp_Pnt.hxx>
30
31 #include <TopAbs_ShapeEnum.hxx>
32 #include <TopAbs_State.hxx>
33
34 #include <TopTools_ListIteratorOfListOfShape.hxx>
35 #include <TopTools_ListOfShape.hxx>
36 #include <TopTools_IndexedMapOfShape.hxx>
37
38 #include <TopoDS.hxx>
39 #include <TopoDS_Solid.hxx>
40 #include <TopoDS_Vertex.hxx>
41
42 #include <TopExp.hxx>
43
44 #include <BRep_Tool.hxx>
45 #include <BRepClass3d_SolidClassifier.hxx>
46
47 #include <BOPTColStd_Dump.hxx>
48
49 #include <IntTools_Context.hxx>
50
51 #include <BooleanOperations_StateOfShape.hxx>
52 #include <BooleanOperations_ShapesDataStructure.hxx>
53
54 #include <BOPTools_InterferencePool.hxx>
55 #include <BOPTools_CArray1OfVVInterference.hxx>
56 #include <BOPTools_VVInterference.hxx>
57 #include <BOPTools_PaveFiller.hxx>
58 #include <BOPTools_DSFiller.hxx>
59
60 //=======================================================================
61 //function : GEOMAlgo_VertexSolid
62 //purpose  : 
63 //=======================================================================
64 GEOMAlgo_VertexSolid::GEOMAlgo_VertexSolid()
65 :
66   GEOMAlgo_ShapeSolid()
67 {
68 }
69 //=======================================================================
70 //function : ~
71 //purpose  : 
72 //=======================================================================
73 GEOMAlgo_VertexSolid::~GEOMAlgo_VertexSolid()
74 {
75 }
76 //=======================================================================
77 // function: Perform
78 // purpose: 
79 //=======================================================================
80 void GEOMAlgo_VertexSolid::Perform()
81 {
82   myErrorStatus=0;
83   //
84   try {
85     if (myDSFiller==NULL) {
86       myErrorStatus=10;
87       return;
88     }
89     if(!myDSFiller->IsDone()) {
90       myErrorStatus=11;
91       return;
92     }
93     //
94     Standard_Boolean bIsNewFiller;
95     Standard_Integer aNbF;
96     TopTools_IndexedMapOfShape aM;
97     //
98     const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
99     const TopoDS_Shape& aObj=aDS.Object();
100     //
101     TopExp::MapShapes(aObj, TopAbs_FACE, aM);
102     aNbF=aM.Extent();
103     myRank=(aNbF) ? 2 : 1;
104     //
105     bIsNewFiller=myDSFiller->IsNewFiller();
106     
107     if (bIsNewFiller) {
108       Prepare();
109       myDSFiller->SetNewFiller(!bIsNewFiller);
110     }
111     BuildResult();
112   }
113   //
114   catch (Standard_Failure) {
115     myErrorStatus = 12;
116   }
117
118 //=======================================================================
119 // function: Prepare
120 // purpose: 
121 //=======================================================================
122 void GEOMAlgo_VertexSolid::Prepare()
123 {
124   Standard_Integer i, iBeg, iEnd, aNbVV, j, n1, n2, iFound;
125   Standard_Real aTol;
126   TopAbs_State aSt;
127   TopAbs_ShapeEnum aType;
128   BooleanOperations_StateOfShape aState;
129   gp_Pnt aP3D;
130   //
131   const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
132   BooleanOperations_ShapesDataStructure* pDS=(BooleanOperations_ShapesDataStructure*)&aDS;
133   const BOPTools_InterferencePool& aIP=myDSFiller->InterfPool();
134   BOPTools_InterferencePool* pIP=(BOPTools_InterferencePool*) &aIP;
135   BOPTools_CArray1OfVVInterference& aVVs=pIP->VVInterferences();
136   const BOPTools_PaveFiller& aPF=myDSFiller->PaveFiller();
137   BOPTools_PaveFiller* pPF=(BOPTools_PaveFiller*)&aPF; 
138   IntTools_Context& aCtx=pPF->ChangeContext();
139   //
140   const TopoDS_Shape& aObj=aDS.Object();
141   const TopoDS_Shape& aTool=aDS.Tool();
142   //
143   const TopoDS_Solid& aSolid=(myRank==1) ? TopoDS::Solid(aTool) : TopoDS::Solid(aObj);
144   const TopoDS_Shape& aSV   =(myRank==1)? aObj : aTool;
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 }