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