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