Salome HOME
182df0d41293af4b2902d1acd028040522295ede
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_VertexSolid.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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.hxx>
29
30 #include <Basics_OCCTVersion.hxx>
31
32 #include <gp_Pnt.hxx>
33
34 #include <TopAbs_ShapeEnum.hxx>
35 #include <TopAbs_State.hxx>
36
37 #include <TopTools_ListIteratorOfListOfShape.hxx>
38 #include <TopTools_ListOfShape.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
40
41 #include <TopoDS.hxx>
42 #include <TopoDS_Solid.hxx>
43 #include <TopoDS_Vertex.hxx>
44
45 #include <TopExp.hxx>
46
47 #include <BRep_Tool.hxx>
48 #include <BRepClass3d_SolidClassifier.hxx>
49 //
50 #include <BOPCol_ListOfShape.hxx>
51 #if OCC_VERSION_LARGE > 0x06070100
52 #include <IntTools_Context.hxx>
53 #else
54 #include <BOPInt_Context.hxx>
55 #endif
56 //
57 #include <BOPDS_DS.hxx>
58 #include <BOPDS_IndexRange.hxx>
59 #include <BOPDS_VectorOfInterfVV.hxx>
60 #include <BOPDS_VectorOfInterfVE.hxx>
61 #include <BOPDS_VectorOfInterfVF.hxx>
62 #include <BOPDS_Interf.hxx>
63
64 //=======================================================================
65 //function : GEOMAlgo_VertexSolid
66 //purpose  :
67 //=======================================================================
68 GEOMAlgo_VertexSolid::GEOMAlgo_VertexSolid()
69 :
70   GEOMAlgo_ShapeSolid()
71 {
72 }
73 //=======================================================================
74 //function : ~
75 //purpose  :
76 //=======================================================================
77 GEOMAlgo_VertexSolid::~GEOMAlgo_VertexSolid()
78 {
79 }
80 //=======================================================================
81 // function: Perform
82 // purpose:
83 //=======================================================================
84 void GEOMAlgo_VertexSolid::Perform()
85 {
86   myErrorStatus=0;
87   //
88   try {
89     if (myDSFiller==NULL) {
90       myErrorStatus=10;
91       return;
92     }
93 #if OCC_VERSION_LARGE > 0x07010000
94     if(myDSFiller->HasErrors()) {
95 #else
96     if(myDSFiller->ErrorStatus()) {
97 #endif
98       myErrorStatus=11;
99       return;
100     }
101     //
102     Standard_Integer aNbF, aNbArgs;
103     TopTools_IndexedMapOfShape aM;
104     //
105     const BOPDS_DS& aDS=myDSFiller->DS();
106     const BOPCol_ListOfShape& aLS=aDS.Arguments();
107     aNbArgs=aLS.Extent();
108     if (aNbArgs!=2) {
109       myErrorStatus=14;
110       return;
111     }
112     
113     const TopoDS_Shape& aObj=aLS.First();
114     //
115     TopExp::MapShapes(aObj, TopAbs_FACE, aM);
116     aNbF=aM.Extent();
117     myRank=(aNbF) ? 1 : 0;
118     //
119     BuildResult();
120   }
121   //
122   catch (Standard_Failure) {
123     myErrorStatus = 12;
124   }
125 }
126 //=======================================================================
127 // function: BuildResult
128 // purpose:
129 //=======================================================================
130 void GEOMAlgo_VertexSolid::BuildResult()
131 {
132   Standard_Integer i, iBeg, iEnd, aNbVV, aNbVE, aNbVF, j, iFound, aNbRanges;
133   Standard_Real aTol;
134   TopAbs_State aSt;
135   TopAbs_ShapeEnum aType;
136   gp_Pnt aP3D;
137   //
138   myLSIN.Clear();
139   myLSOUT.Clear();
140   myLSON.Clear();
141   //
142   const BOPDS_DS& aDS=myDSFiller->DS();
143   BOPDS_DS* pDS=(BOPDS_DS*)&aDS;
144   //
145   BOPDS_VectorOfInterfVV& aVVs=pDS->InterfVV();
146   BOPDS_VectorOfInterfVE& aVEs=pDS->InterfVE();
147   BOPDS_VectorOfInterfVF& aVFs=pDS->InterfVF();
148   //
149   const BOPCol_ListOfShape& aLS=aDS.Arguments();
150   const TopoDS_Shape& aObj=aLS.First();
151   //
152   const TopoDS_Shape& aTool=aLS.Last();
153   const TopoDS_Solid& aSolid=(myRank==0) ? TopoDS::Solid(aTool) : TopoDS::Solid(aObj);
154   //
155 #if OCC_VERSION_LARGE > 0x06070100
156   Handle(IntTools_Context) aCtx=myDSFiller->Context();
157 #else
158   Handle(BOPInt_Context) aCtx=myDSFiller->Context();
159 #endif
160   BRepClass3d_SolidClassifier& aSC=aCtx->SolidClassifier(aSolid);
161   //
162   aNbRanges=aDS.NbRanges();
163   const BOPDS_IndexRange& aRange=aDS.Range(myRank);
164   aRange.Indices(iBeg, iEnd);
165   //
166   for (i=iBeg; i<=iEnd; ++i) {
167     const TopoDS_Shape& aS=aDS.Shape(i);
168     aType=aS.ShapeType();
169     if (aType!=TopAbs_VERTEX) {
170       continue; 
171     }
172     //
173     const TopoDS_Vertex& aV=TopoDS::Vertex(aS);
174     //
175     iFound=0;
176     //
177     // 1
178     aNbVV=aVVs.Extent();
179     for (j=0; j<aNbVV; ++j) {
180       BOPDS_InterfVV& aVV=aVVs(j);
181       if (aVV.Contains(i)) {
182         myLSON.Append(aV);
183         iFound=1;
184         break;
185       }
186     }
187     if (iFound) {
188       continue; 
189     }
190     // 2
191     aNbVE=aVEs.Extent();
192     for (j=0; j<aNbVE; ++j) {
193       BOPDS_InterfVE& aVE=aVEs(j);
194       if (aVE.Contains(i)) {
195         myLSON.Append(aV);
196         iFound=1;
197         break;
198       }
199     }
200     if (iFound) {
201       continue; 
202     }
203     // 3
204     aNbVF=aVFs.Extent();
205     for (j=0; j<aNbVF; ++j) {
206       BOPDS_InterfVF& aVF=aVFs(j);
207       if (aVF.Contains(i)) {
208         myLSON.Append(aV);
209         iFound=1;
210         break;
211       }
212     }
213     if (iFound) {
214       continue; 
215     }
216     //
217     // 4
218     aP3D=BRep_Tool::Pnt(aV);
219     aTol=1.e-7;
220     aSC.Perform(aP3D, aTol);
221     aSt=aSC.State();
222     if (aSt==TopAbs_IN) {
223       myLSIN.Append(aV);
224     }
225     else if (aSt==TopAbs_OUT) {
226       myLSOUT.Append(aV);
227     }
228   }//for (i=iBeg; i<iEnd; ++i) {
229 }