Salome HOME
c4596bdb059128ea8c050507034595e9ccad0537
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_SolidSolid.cxx
1 // File:        GEOMAlgo_SolidSolid.cxx
2 // Created:     Wed Jan 26 12:06:26 2005
3 // Author:      Peter KURNEV
4 //              <pkv@irinox>
5
6
7 #include <GEOMAlgo_SolidSolid.ixx>
8
9 #include <Standard_Failure.hxx>
10
11 #include <TopAbs_State.hxx>
12 #include <TopoDS_Shape.hxx>
13 #include <TopExp.hxx>
14
15 #include <TopTools_ListOfShape.hxx>
16 #include <TopTools_ListIteratorOfListOfShape.hxx>
17 #include <TopTools_IndexedMapOfShape.hxx>
18
19 #include <BooleanOperations_ShapesDataStructure.hxx>
20 #include <BOPTools_DSFiller.hxx>
21
22 #include <GEOMAlgo_IndexedDataMapOfShapeState.hxx>
23
24 //=======================================================================
25 //function : GEOMAlgo_SolidSolid
26 //purpose  : 
27 //=======================================================================
28 GEOMAlgo_SolidSolid::GEOMAlgo_SolidSolid()
29 :
30   GEOMAlgo_ShellSolid()
31 {
32 }
33 //=======================================================================
34 //function : ~
35 //purpose  : 
36 //=======================================================================
37 GEOMAlgo_SolidSolid::~GEOMAlgo_SolidSolid()
38 {
39 }
40 //=======================================================================
41 // function: SetShape2
42 // purpose: 
43 //=======================================================================
44 void GEOMAlgo_SolidSolid::SetShape2(const TopoDS_Shape& aS2)
45 {
46   myS2=aS2;
47
48 //=======================================================================
49 // function: Shape2
50 // purpose: 
51 //=======================================================================
52 const TopoDS_Shape& GEOMAlgo_SolidSolid::Shape2()const
53 {
54   return myS2;
55
56 //=======================================================================
57 // function: Perform
58 // purpose: 
59 //=======================================================================
60 void GEOMAlgo_SolidSolid::Perform() 
61 {
62   myErrorStatus=0;
63   try {
64     if (myDSFiller==NULL) {
65       myErrorStatus=10;
66       return;
67     }
68     if(!myDSFiller->IsDone()) {
69       myErrorStatus=11;
70       return;
71     }
72     //
73     Standard_Boolean bIsNewFiller;
74     //
75     bIsNewFiller=myDSFiller->IsNewFiller();
76     if (bIsNewFiller) {
77       Prepare();
78       myDSFiller->SetNewFiller(!bIsNewFiller);
79     }
80     //
81     myRank=2;
82     BuildResult();
83   }
84   catch (Standard_Failure) {
85     myErrorStatus=12;
86   }
87 }
88 //=================================================================================
89 // function: BuildResult
90 // purpose: 
91 //=================================================================================
92 void GEOMAlgo_SolidSolid::BuildResult() 
93 {
94   myErrorStatus=0;
95   //
96   Standard_Integer i, j, aNbF, aNbS;
97   Standard_Integer aNbFIN, aNbFOUT, aNbFON, aNbFINTR;
98   TopAbs_State aState;
99   TopTools_ListIteratorOfListOfShape aIt;
100   TopTools_IndexedMapOfShape aMF, aMS;
101   GEOMAlgo_IndexedDataMapOfShapeState aMFS;
102   //
103   // 1. classify the faces
104   GEOMAlgo_ShellSolid::BuildResult(); 
105   //
106   // 2. fill Shape-State map
107   aIt.Initialize(myLSIN);
108   for (; aIt.More(); aIt.Next()) {
109     const TopoDS_Shape& aF=aIt.Value();
110     aMFS.Add(aF, TopAbs_IN);
111   }
112   aIt.Initialize(myLSOUT);
113   for (; aIt.More(); aIt.Next()) {
114     const TopoDS_Shape& aF=aIt.Value();
115     aMFS.Add(aF, TopAbs_OUT);
116   }
117   aIt.Initialize(myLSON);
118   for (; aIt.More(); aIt.Next()) {
119     const TopoDS_Shape& aF=aIt.Value();
120     aMFS.Add(aF, TopAbs_ON);
121   }
122   myLSIN.Clear();
123   myLSON.Clear();
124   myLSOUT.Clear();
125   //
126   // 3. fill states for solids
127   TopExp::MapShapes(myS2, TopAbs_SOLID, aMS);
128   //
129   aNbS=aMS.Extent();
130   for (i=1; i<=aNbS; ++i) {
131     const TopoDS_Shape& aSolid=aMS(i);
132     //
133     aMF.Clear();
134     TopExp::MapShapes(aSolid, TopAbs_FACE, aMF);
135     //
136     aNbFIN=0;
137     aNbFOUT=0;
138     aNbFON=0;
139     aNbFINTR=0;
140     //
141     aNbF=aMF.Extent();
142     for(j=1; j<aNbF; ++j) {
143       const TopoDS_Shape& aF=aMF(j);
144       //
145       if (!aMFS.Contains(aF)) {// the face is intesected 
146         ++aNbFINTR;
147         break; 
148       }
149       //
150       aState=aMFS.FindFromKey(aF);
151       switch (aState) {
152         case TopAbs_IN:
153           ++aNbFIN;
154           break;
155         case TopAbs_OUT:
156           ++aNbFOUT;
157           break;
158         case TopAbs_ON:
159           ++aNbFON;
160           break;
161         default:
162           break;
163       }
164       if (aNbFIN && aNbFOUT) {
165         ++aNbFINTR;
166         break;
167       }
168     }
169     //
170     if (!aNbFINTR) {
171       if (aNbFON==aNbF) {
172         myLSON.Append(aSolid);
173       }
174       else if (aNbFIN) {
175         myLSIN.Append(aSolid);
176       }
177       else if (aNbFOUT) {
178         myLSOUT.Append(aSolid);
179       }
180     }
181   }
182 }