Salome HOME
b64df9d55204cd30f6a9e68279664500ed27d747
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_SolidSolid.cxx
1 //  Copyright (C) 2007-2008  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 // File:        GEOMAlgo_SolidSolid.cxx
23 // Created:     Wed Jan 26 12:06:26 2005
24 // Author:      Peter KURNEV
25 //              <pkv@irinox>
26 //
27 #include <GEOMAlgo_SolidSolid.ixx>
28
29 #include <Standard_Failure.hxx>
30
31 #include <TopAbs_State.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopExp.hxx>
34
35 #include <TopTools_ListOfShape.hxx>
36 #include <TopTools_ListIteratorOfListOfShape.hxx>
37 #include <TopTools_IndexedMapOfShape.hxx>
38
39 #include <BooleanOperations_ShapesDataStructure.hxx>
40 #include <BOPTools_DSFiller.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(!myDSFiller->IsDone()) {
89       myErrorStatus=11;
90       return;
91     }
92     //
93     Standard_Boolean bIsNewFiller;
94     //
95     bIsNewFiller=myDSFiller->IsNewFiller();
96     if (bIsNewFiller) {
97       Prepare();
98       myDSFiller->SetNewFiller(!bIsNewFiller);
99     }
100     //
101     myRank=2;
102     BuildResult();
103   }
104   catch (Standard_Failure) {
105     myErrorStatus=12;
106   }
107 }
108 //=================================================================================
109 // function: BuildResult
110 // purpose: 
111 //=================================================================================
112 void GEOMAlgo_SolidSolid::BuildResult() 
113 {
114   myErrorStatus=0;
115   //
116   Standard_Integer i, j, aNbF, aNbS;
117   Standard_Integer aNbFIN, aNbFOUT, aNbFON, aNbFINTR;
118   TopAbs_State aState;
119   TopTools_ListIteratorOfListOfShape aIt;
120   TopTools_IndexedMapOfShape aMF, aMS;
121   GEOMAlgo_IndexedDataMapOfShapeState aMFS;
122   //
123   // 1. classify the faces
124   GEOMAlgo_ShellSolid::BuildResult(); 
125   //
126   // 2. fill Shape-State map
127   aIt.Initialize(myLSIN);
128   for (; aIt.More(); aIt.Next()) {
129     const TopoDS_Shape& aF=aIt.Value();
130     aMFS.Add(aF, TopAbs_IN);
131   }
132   aIt.Initialize(myLSOUT);
133   for (; aIt.More(); aIt.Next()) {
134     const TopoDS_Shape& aF=aIt.Value();
135     aMFS.Add(aF, TopAbs_OUT);
136   }
137   aIt.Initialize(myLSON);
138   for (; aIt.More(); aIt.Next()) {
139     const TopoDS_Shape& aF=aIt.Value();
140     aMFS.Add(aF, TopAbs_ON);
141   }
142   myLSIN.Clear();
143   myLSON.Clear();
144   myLSOUT.Clear();
145   //
146   // 3. fill states for solids
147   TopExp::MapShapes(myS2, TopAbs_SOLID, aMS);
148   //
149   aNbS=aMS.Extent();
150   for (i=1; i<=aNbS; ++i) {
151     const TopoDS_Shape& aSolid=aMS(i);
152     //
153     aMF.Clear();
154     TopExp::MapShapes(aSolid, TopAbs_FACE, aMF);
155     //
156     aNbFIN=0;
157     aNbFOUT=0;
158     aNbFON=0;
159     aNbFINTR=0;
160     //
161     aNbF=aMF.Extent();
162     for(j=1; j<aNbF; ++j) {
163       const TopoDS_Shape& aF=aMF(j);
164       //
165       if (!aMFS.Contains(aF)) {// the face is intesected 
166         ++aNbFINTR;
167         break; 
168       }
169       //
170       aState=aMFS.FindFromKey(aF);
171       switch (aState) {
172         case TopAbs_IN:
173           ++aNbFIN;
174           break;
175         case TopAbs_OUT:
176           ++aNbFOUT;
177           break;
178         case TopAbs_ON:
179           ++aNbFON;
180           break;
181         default:
182           break;
183       }
184       if (aNbFIN && aNbFOUT) {
185         ++aNbFINTR;
186         break;
187       }
188     }
189     //
190     if (!aNbFINTR) {
191       if (aNbFON==aNbF) {
192         myLSON.Append(aSolid);
193       }
194       else if (aNbFIN) {
195         myLSIN.Append(aSolid);
196       }
197       else if (aNbFOUT) {
198         myLSOUT.Append(aSolid);
199       }
200     }
201   }
202 }