]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMAlgo/GEOMAlgo_SolidSolid.cxx
Salome HOME
Porting to OCCT dev version: update version 0x07010000 -> 0x07010001
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_SolidSolid.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_SolidSolid.cxx
24 // Created:     Wed Jan 26 12:06:26 2005
25 // Author:      Peter KURNEV
26 //              <pkv@irinox>
27 //
28 #include <GEOMAlgo_SolidSolid.hxx>
29
30 #include <Standard_Failure.hxx>
31
32 #include <TopAbs_State.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopExp.hxx>
35
36 #include <TopTools_ListOfShape.hxx>
37 #include <TopTools_ListIteratorOfListOfShape.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
39
40 #include <Basics_OCCTVersion.hxx>
41
42 #include <GEOMAlgo_IndexedDataMapOfShapeState.hxx>
43
44 //=======================================================================
45 //function : GEOMAlgo_SolidSolid
46 //purpose  :
47 //=======================================================================
48 GEOMAlgo_SolidSolid::GEOMAlgo_SolidSolid()
49 :
50   GEOMAlgo_ShellSolid()
51 {
52 }
53 //=======================================================================
54 //function : ~
55 //purpose  :
56 //=======================================================================
57 GEOMAlgo_SolidSolid::~GEOMAlgo_SolidSolid()
58 {
59 }
60 //=======================================================================
61 // function: SetShape2
62 // purpose:
63 //=======================================================================
64 void GEOMAlgo_SolidSolid::SetShape2(const TopoDS_Shape& aS2)
65 {
66   myS2=aS2;
67 }
68 //=======================================================================
69 // function: Shape2
70 // purpose:
71 //=======================================================================
72 const TopoDS_Shape& GEOMAlgo_SolidSolid::Shape2()const
73 {
74   return myS2;
75 }
76 //=======================================================================
77 // function: Perform
78 // purpose:
79 //=======================================================================
80 void GEOMAlgo_SolidSolid::Perform()
81 {
82   myErrorStatus=0;
83   try {
84     if (myDSFiller==NULL) {
85       myErrorStatus=10;
86       return;
87     }
88 #if OCC_VERSION_LARGE > 0x07010001
89     if(myDSFiller->HasErrors()) {
90 #else
91     if(myDSFiller->ErrorStatus()) {
92 #endif
93       myErrorStatus=11;
94       return;
95     }
96     //
97     myRank=2;
98     BuildResult();
99   }
100   catch (Standard_Failure) {
101     myErrorStatus=12;
102   }
103 }
104 //=================================================================================
105 // function: BuildResult
106 // purpose:
107 //=================================================================================
108 void GEOMAlgo_SolidSolid::BuildResult()
109 {
110   myErrorStatus=0;
111   //
112   Standard_Integer i, j, aNbF, aNbS;
113   Standard_Integer aNbFIN, aNbFOUT, aNbFON, aNbFINTR;
114   TopAbs_State aState;
115   TopTools_ListIteratorOfListOfShape aIt;
116   TopTools_IndexedMapOfShape aMF, aMS;
117   GEOMAlgo_IndexedDataMapOfShapeState aMFS;
118   //
119   // 1. classify the faces
120   GEOMAlgo_ShellSolid::Perform();
121   //
122   // 2. fill Shape-State map
123   aIt.Initialize(myLSIN);
124   for (; aIt.More(); aIt.Next()) {
125     const TopoDS_Shape& aF=aIt.Value();
126     aMFS.Add(aF, TopAbs_IN);
127   }
128   aIt.Initialize(myLSOUT);
129   for (; aIt.More(); aIt.Next()) {
130     const TopoDS_Shape& aF=aIt.Value();
131     aMFS.Add(aF, TopAbs_OUT);
132   }
133   aIt.Initialize(myLSON);
134   for (; aIt.More(); aIt.Next()) {
135     const TopoDS_Shape& aF=aIt.Value();
136     aMFS.Add(aF, TopAbs_ON);
137   }
138   //
139   myLSIN.Clear();
140   myLSON.Clear();
141   myLSOUT.Clear();
142   //
143   // 3. fill states for solids
144   TopExp::MapShapes(myS2, TopAbs_SOLID, aMS);
145   //
146   aNbS=aMS.Extent();
147   for (i=1; i<=aNbS; ++i) {
148     const TopoDS_Shape& aSolid=aMS(i);
149     //
150     aMF.Clear();
151     TopExp::MapShapes(aSolid, TopAbs_FACE, aMF);
152     //
153     aNbFIN=0;
154     aNbFOUT=0;
155     aNbFON=0;
156     aNbFINTR=0;
157     //
158     aNbF=aMF.Extent();
159     for(j=1; j<aNbF; ++j) {
160       const TopoDS_Shape& aF=aMF(j);
161       //
162       if (!aMFS.Contains(aF)) {// the face is intesected
163         ++aNbFINTR;
164         break;
165       }
166       //
167       aState=aMFS.FindFromKey(aF);
168       switch (aState) {
169         case TopAbs_IN:
170           ++aNbFIN;
171           break;
172         case TopAbs_OUT:
173           ++aNbFOUT;
174           break;
175         case TopAbs_ON:
176           ++aNbFON;
177           break;
178         default:
179           break;
180       }
181       if (aNbFIN && aNbFOUT) {
182         ++aNbFINTR;
183         break;
184       }
185     }
186     //
187     if (!aNbFINTR) {
188       if (aNbFON==aNbF) {
189         myLSON.Append(aSolid);
190       }
191       else if (aNbFIN) {
192         myLSIN.Append(aSolid);
193       }
194       else if (aNbFOUT) {
195         myLSOUT.Append(aSolid);
196       }
197     }
198   }
199 }