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