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