Salome HOME
Update mail address
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_SolidSolid.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 // File:        GEOMAlgo_SolidSolid.cxx
21 // Created:     Wed Jan 26 12:06:26 2005
22 // Author:      Peter KURNEV
23 //              <pkv@irinox>
24
25
26 #include <GEOMAlgo_SolidSolid.ixx>
27
28 #include <Standard_Failure.hxx>
29
30 #include <TopAbs_State.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopExp.hxx>
33
34 #include <TopTools_ListOfShape.hxx>
35 #include <TopTools_ListIteratorOfListOfShape.hxx>
36 #include <TopTools_IndexedMapOfShape.hxx>
37
38 #include <BooleanOperations_ShapesDataStructure.hxx>
39 #include <BOPTools_DSFiller.hxx>
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->IsDone()) {
88       myErrorStatus=11;
89       return;
90     }
91     //
92     Standard_Boolean bIsNewFiller;
93     //
94     bIsNewFiller=myDSFiller->IsNewFiller();
95     if (bIsNewFiller) {
96       Prepare();
97       myDSFiller->SetNewFiller(!bIsNewFiller);
98     }
99     //
100     myRank=2;
101     BuildResult();
102   }
103   catch (Standard_Failure) {
104     myErrorStatus=12;
105   }
106 }
107 //=================================================================================
108 // function: BuildResult
109 // purpose: 
110 //=================================================================================
111 void GEOMAlgo_SolidSolid::BuildResult() 
112 {
113   myErrorStatus=0;
114   //
115   Standard_Integer i, j, aNbF, aNbS;
116   Standard_Integer aNbFIN, aNbFOUT, aNbFON, aNbFINTR;
117   TopAbs_State aState;
118   TopTools_ListIteratorOfListOfShape aIt;
119   TopTools_IndexedMapOfShape aMF, aMS;
120   GEOMAlgo_IndexedDataMapOfShapeState aMFS;
121   //
122   // 1. classify the faces
123   GEOMAlgo_ShellSolid::BuildResult(); 
124   //
125   // 2. fill Shape-State map
126   aIt.Initialize(myLSIN);
127   for (; aIt.More(); aIt.Next()) {
128     const TopoDS_Shape& aF=aIt.Value();
129     aMFS.Add(aF, TopAbs_IN);
130   }
131   aIt.Initialize(myLSOUT);
132   for (; aIt.More(); aIt.Next()) {
133     const TopoDS_Shape& aF=aIt.Value();
134     aMFS.Add(aF, TopAbs_OUT);
135   }
136   aIt.Initialize(myLSON);
137   for (; aIt.More(); aIt.Next()) {
138     const TopoDS_Shape& aF=aIt.Value();
139     aMFS.Add(aF, TopAbs_ON);
140   }
141   myLSIN.Clear();
142   myLSON.Clear();
143   myLSOUT.Clear();
144   //
145   // 3. fill states for solids
146   TopExp::MapShapes(myS2, TopAbs_SOLID, aMS);
147   //
148   aNbS=aMS.Extent();
149   for (i=1; i<=aNbS; ++i) {
150     const TopoDS_Shape& aSolid=aMS(i);
151     //
152     aMF.Clear();
153     TopExp::MapShapes(aSolid, TopAbs_FACE, aMF);
154     //
155     aNbFIN=0;
156     aNbFOUT=0;
157     aNbFON=0;
158     aNbFINTR=0;
159     //
160     aNbF=aMF.Extent();
161     for(j=1; j<aNbF; ++j) {
162       const TopoDS_Shape& aF=aMF(j);
163       //
164       if (!aMFS.Contains(aF)) {// the face is intesected 
165         ++aNbFINTR;
166         break; 
167       }
168       //
169       aState=aMFS.FindFromKey(aF);
170       switch (aState) {
171         case TopAbs_IN:
172           ++aNbFIN;
173           break;
174         case TopAbs_OUT:
175           ++aNbFOUT;
176           break;
177         case TopAbs_ON:
178           ++aNbFON;
179           break;
180         default:
181           break;
182       }
183       if (aNbFIN && aNbFOUT) {
184         ++aNbFINTR;
185         break;
186       }
187     }
188     //
189     if (!aNbFINTR) {
190       if (aNbFON==aNbF) {
191         myLSON.Append(aSolid);
192       }
193       else if (aNbFIN) {
194         myLSIN.Append(aSolid);
195       }
196       else if (aNbFOUT) {
197         myLSOUT.Append(aSolid);
198       }
199     }
200   }
201 }