Salome HOME
9b94938f1115ef3bf5ee8420bf621ce300227039
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_Builder_4.cxx
1 //  Copyright (C) 2007-2010  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_Builder_4.cxx
24 // Created:     
25 // Author:      Peter KURNEV 
26 //
27 #include <GEOMAlgo_Builder.hxx>
28
29 #include <TopoDS_Iterator.hxx>
30
31 #include <TopTools_ListOfShape.hxx>
32 #include <TopTools_ListIteratorOfListOfShape.hxx>
33 #include <TopTools_MapOfShape.hxx>
34 #include <TopTools_MapIteratorOfMapOfShape.hxx>
35
36 #include <IntTools_Context.hxx>
37
38 #include <NMTDS_ShapesDataStructure.hxx>
39
40 #include <NMTTools_PaveFiller.hxx>
41
42 #include <GEOMAlgo_Tools3D.hxx>
43
44 static
45   void MapShapes(const TopoDS_Shape& aS,
46                  TopTools_MapOfShape& aM);
47
48 //=======================================================================
49 //function : Generated
50 //purpose  : 
51 //=======================================================================
52   const TopTools_ListOfShape& GEOMAlgo_Builder::Generated(const TopoDS_Shape& theS)
53 {
54   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
55   NMTTools_PaveFiller* pPF=myPaveFiller;
56   IntTools_Context& aCtx=pPF->ChangeContext();
57   //
58   Standard_Boolean bHasImage, bToReverse;
59   TopAbs_ShapeEnum aType;
60   TopTools_ListIteratorOfListOfShape aIt;
61   //
62   myHistShapes.Clear();
63   //
64   if (theS.IsNull()) {
65     return myHistShapes;
66   }
67   //
68   bHasImage=myImages.HasImage(theS);
69   if (!bHasImage) {
70     return myHistShapes;
71   }
72   //
73   aType=theS.ShapeType();
74   //
75   if (aType==TopAbs_EDGE   || aType==TopAbs_FACE || 
76       aType==TopAbs_VERTEX || aType==TopAbs_SOLID) { 
77     const TopTools_ListOfShape& aLSp=myImages.Image(theS);
78     aIt.Initialize(aLSp);
79     for (; aIt.More(); aIt.Next()) {
80       const TopoDS_Shape& aSp=aIt.Value();
81       if (mySameDomainShapes.Contains(aSp)) {
82         if (myMapShape.Contains(aSp)) {
83           TopoDS_Shape aSpR=mySameDomainShapes.FindFromKey(aSp);
84           //
85           if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
86             aSpR.Orientation(theS.Orientation());
87           }
88           else {
89             bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aSpR, theS, aCtx);
90             if (bToReverse) {
91               aSpR.Reverse();
92             }
93           }
94           //
95           myHistShapes.Append(aSpR);
96         }
97       }
98     }
99   }
100   //
101   return myHistShapes;
102 }
103 //=======================================================================
104 //function : Modified
105 //purpose  : 
106 //=======================================================================
107   const TopTools_ListOfShape& GEOMAlgo_Builder::Modified(const TopoDS_Shape& theS)
108 {
109   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
110   NMTTools_PaveFiller* pPF=myPaveFiller;
111   IntTools_Context& aCtx=pPF->ChangeContext();
112   //
113   Standard_Boolean bHasImage, bToReverse;
114   TopAbs_ShapeEnum aType;
115   TopTools_ListIteratorOfListOfShape aIt;
116   //
117   myHistShapes.Clear();
118   //
119   if (theS.IsNull()) {
120     return myHistShapes;
121   }
122   //
123   bHasImage=myImages.HasImage(theS);
124   if (!bHasImage) {
125     return myHistShapes;
126   }
127   //
128   aType=theS.ShapeType();
129   //
130   if (aType==TopAbs_EDGE   || aType==TopAbs_FACE || 
131       aType==TopAbs_VERTEX || aType==TopAbs_SOLID) { 
132     const TopTools_ListOfShape& aLSp=myImages.Image(theS);
133     aIt.Initialize(aLSp);
134     for (; aIt.More(); aIt.Next()) {
135       TopoDS_Shape aSp=aIt.Value();
136       if (!mySameDomainShapes.Contains(aSp)) {
137         if (myMapShape.Contains(aSp)) {
138           //
139           if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
140             aSp.Orientation(theS.Orientation());
141           }
142           else {
143             bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aSp, theS, aCtx);
144             if (bToReverse) {
145               aSp.Reverse();
146             }
147           }
148           //
149           myHistShapes.Append(aSp);
150         }
151       }
152     }
153   }
154   //
155   return myHistShapes;
156 }
157 //=======================================================================
158 //function : IsDeleted
159 //purpose  : 
160 //=======================================================================
161   Standard_Boolean GEOMAlgo_Builder::IsDeleted(const TopoDS_Shape& theS)
162 {
163   Standard_Boolean bRet, bHasImage, bContains;
164   TopAbs_ShapeEnum aType;
165   TopTools_ListIteratorOfListOfShape aIt;
166   //
167   bRet=Standard_False;
168   //
169   if (theS.IsNull()) {
170     return !bRet; //true
171   }
172   //
173   bContains=myMapShape.Contains(theS);
174   if (bContains) {
175     return bRet; //false
176   }
177   //
178   bHasImage=myImages.HasImage(theS);
179   if (!bHasImage) {
180     return !bRet; //true
181   }
182   //
183   aType=theS.ShapeType();
184   if (aType==TopAbs_EDGE   || aType==TopAbs_FACE || 
185       aType==TopAbs_VERTEX || aType==TopAbs_SOLID) { 
186     const TopTools_ListOfShape& aLSp=myImages.Image(theS);
187     aIt.Initialize(aLSp);
188     for (; aIt.More(); aIt.Next()) {
189       TopoDS_Shape aSp=aIt.Value();
190       //
191       if (!mySameDomainShapes.Contains(aSp)) {
192         if (myMapShape.Contains(aSp)) {
193           return bRet; //false
194         }
195       }
196       else {
197         TopoDS_Shape aSpR=mySameDomainShapes.FindFromKey(aSp);
198         if (myMapShape.Contains(aSpR)) {
199           return bRet; //false
200         }
201       }
202     }
203   }
204   return !bRet; // true
205 }
206 //=======================================================================
207 //function : PrepareHistory
208 //purpose  : 
209 //=======================================================================
210   void GEOMAlgo_Builder::PrepareHistory()
211 {
212   if(myShape.IsNull()) {
213     return;
214   }
215   //
216   Standard_Boolean bHasImage, bContainsSD;
217   TopAbs_ShapeEnum aType;
218   TopTools_MapOfShape aMS;
219   TopTools_ListIteratorOfListOfShape aIt;
220   TopTools_MapIteratorOfMapOfShape aItM;
221   //
222   // 1. Clearing 
223   GEOMAlgo_BuilderShape::PrepareHistory();
224   //
225   // 2. myMapShape - all shapes of result with theirs sub-shapes 
226   MapShapes(myShape, myMapShape);
227   //
228   // 3. MS - all argument shapes with theirs sub-shapes
229   aIt.Initialize(myShapes);
230   for (; aIt.More(); aIt.Next()) {
231     const TopoDS_Shape& aSx=aIt.Value();
232     MapShapes(aSx, aMS);
233   }
234   //
235   // 4. Treatment
236   aItM.Initialize(aMS);
237   for (; aItM.More(); aItM.Next()) {
238     const TopoDS_Shape& aSx=aItM.Key();
239     aType=aSx.ShapeType();
240     //modified by NIZNHY-PKV Thu Dec  7 11:34:05 2006f
241     //
242     // 4.1 .myImagesResult
243     TopTools_ListOfShape aLSx;
244     //
245     bHasImage=myImages.HasImage(aSx);
246     if (!bHasImage) {
247       if (myMapShape.Contains(aSx)) {
248         aLSx.Append(aSx);
249         myImagesResult.Add(aSx, aLSx);
250       }
251     }
252     else {
253       const TopTools_ListOfShape& aLSp=myImages.Image(aSx);
254       aIt.Initialize(aLSp);
255       for (; aIt.More(); aIt.Next()) {
256         const TopoDS_Shape& aSp=aIt.Value();
257         if (myMapShape.Contains(aSp)) {
258           aLSx.Append(aSp);
259         }
260       }
261       myImagesResult.Add(aSx, aLSx);
262     }
263     //
264     //modified by NIZNHY-PKV Thu Dec  7 11:34:10 2006t
265     //
266     // 4.2 As it was 
267     if (!myHasDeleted) {
268       myHasDeleted=IsDeleted(aSx);//xx
269     }
270     //
271     if (!myHasGenerated || !myHasModified) {
272       if (aType==TopAbs_EDGE   || aType==TopAbs_FACE || 
273           aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
274         //modified by NIZNHY-PKV Thu Dec  7 11:53:01 2006f
275         //bHasImage=myImages.HasImage(aSx);
276         //modified by NIZNHY-PKV Thu Dec  7 11:53:04 2006t
277         if (bHasImage) {
278           const TopTools_ListOfShape& aLSp=myImages.Image(aSx);
279           aIt.Initialize(aLSp);
280           for (; aIt.More(); aIt.Next()) {
281             const TopoDS_Shape& aSp=aIt.Value();
282             //
283             if (myMapShape.Contains(aSp)) {
284               bContainsSD=mySameDomainShapes.Contains(aSp);
285               //
286               if (!myHasGenerated) {
287                 if (bContainsSD) {
288                   myHasGenerated=Standard_True;
289                 }
290               }
291               if (!myHasModified) {
292                 if (!bContainsSD) {
293                   myHasModified=Standard_True;
294                 }
295               }
296             } // if (myMapShape.Contains(aSp))
297           }
298         }
299       } 
300     }
301   }
302   
303 }
304 //=======================================================================
305 //function : MapShapes
306 //purpose  : 
307 //=======================================================================
308   void MapShapes(const TopoDS_Shape& theS,
309                  TopTools_MapOfShape& theM)
310 {
311   theM.Add(theS);
312   TopoDS_Iterator anIt;
313   anIt.Initialize(theS);
314   for (; anIt.More(); anIt.Next()) {
315     const TopoDS_Shape& aSx=anIt.Value();
316     MapShapes(aSx, theM);
317   }
318 }