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