Salome HOME
Merge from V6_main 01/04/2013
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_Builder_4.cxx
1 // Copyright (C) 2007-2013  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   NMTTools_PaveFiller* pPF=myPaveFiller;
55   const Handle(IntTools_Context)& aCtx=pPF->Context();
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   NMTTools_PaveFiller* pPF=myPaveFiller;
109   const Handle(IntTools_Context)& aCtx=pPF->Context();
110   //
111   Standard_Boolean bHasImage, bToReverse;
112   TopAbs_ShapeEnum aType;
113   TopTools_ListIteratorOfListOfShape aIt;
114   //
115   myHistShapes.Clear();
116   //
117   if (theS.IsNull()) {
118     return myHistShapes;
119   }
120   //
121   bHasImage=myImages.HasImage(theS);
122   if (!bHasImage) {
123     return myHistShapes;
124   }
125   //
126   aType=theS.ShapeType();
127   //
128   if (aType==TopAbs_EDGE   || aType==TopAbs_FACE ||
129       aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
130     const TopTools_ListOfShape& aLSp=myImages.Image(theS);
131     aIt.Initialize(aLSp);
132     for (; aIt.More(); aIt.Next()) {
133       TopoDS_Shape aSp=aIt.Value();
134       if (!mySameDomainShapes.Contains(aSp)) {
135         if (myMapShape.Contains(aSp)) {
136           //
137           if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
138             aSp.Orientation(theS.Orientation());
139           }
140           else {
141             bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aSp, theS, aCtx);
142             if (bToReverse) {
143               aSp.Reverse();
144             }
145           }
146           //
147           myHistShapes.Append(aSp);
148         }
149       }
150     }
151   }
152   //
153   return myHistShapes;
154 }
155 //=======================================================================
156 //function : IsDeleted
157 //purpose  :
158 //=======================================================================
159   Standard_Boolean GEOMAlgo_Builder::IsDeleted(const TopoDS_Shape& theS)
160 {
161   Standard_Boolean bRet, bHasImage, bContains;
162   TopAbs_ShapeEnum aType;
163   TopTools_ListIteratorOfListOfShape aIt;
164   //
165   bRet=Standard_False;
166   //
167   if (theS.IsNull()) {
168     return !bRet; //true
169   }
170   //
171   bContains=myMapShape.Contains(theS);
172   if (bContains) {
173     return bRet; //false
174   }
175   //
176   bHasImage=myImages.HasImage(theS);
177   if (!bHasImage) {
178     return !bRet; //true
179   }
180   //
181   aType=theS.ShapeType();
182   if (aType==TopAbs_EDGE   || aType==TopAbs_FACE ||
183       aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
184     const TopTools_ListOfShape& aLSp=myImages.Image(theS);
185     aIt.Initialize(aLSp);
186     for (; aIt.More(); aIt.Next()) {
187       TopoDS_Shape aSp=aIt.Value();
188       //
189       if (!mySameDomainShapes.Contains(aSp)) {
190         if (myMapShape.Contains(aSp)) {
191           return bRet; //false
192         }
193       }
194       else {
195         TopoDS_Shape aSpR=mySameDomainShapes.FindFromKey(aSp);
196         if (myMapShape.Contains(aSpR)) {
197           return bRet; //false
198         }
199       }
200     }
201   }
202   return !bRet; // true
203 }
204 //=======================================================================
205 //function : PrepareHistory
206 //purpose  :
207 //=======================================================================
208   void GEOMAlgo_Builder::PrepareHistory()
209 {
210   if(myShape.IsNull()) {
211     return;
212   }
213   //
214   Standard_Boolean bHasImage, bContainsSD;
215   TopAbs_ShapeEnum aType;
216   TopTools_MapOfShape aMS;
217   TopTools_ListIteratorOfListOfShape aIt;
218   TopTools_MapIteratorOfMapOfShape aItM;
219   //
220   // 1. Clearing
221   GEOMAlgo_BuilderShape::PrepareHistory();
222   //
223   // 2. myMapShape - all shapes of result with theirs sub-shapes
224   MapShapes(myShape, myMapShape);
225   //
226   // 3. MS - all argument shapes with theirs sub-shapes
227   aIt.Initialize(myShapes);
228   for (; aIt.More(); aIt.Next()) {
229     const TopoDS_Shape& aSx=aIt.Value();
230     MapShapes(aSx, aMS);
231   }
232   //
233   // 4. Treatment
234   aItM.Initialize(aMS);
235   for (; aItM.More(); aItM.Next()) {
236     const TopoDS_Shape& aSx=aItM.Key();
237     aType=aSx.ShapeType();
238     //modified by NIZNHY-PKV Thu Dec  7 11:34:05 2006f
239     //
240     // 4.1 .myImagesResult
241     TopTools_ListOfShape aLSx;
242     //
243     bHasImage=myImages.HasImage(aSx);
244     if (!bHasImage) {
245       if (myMapShape.Contains(aSx)) {
246         aLSx.Append(aSx);
247         myImagesResult.Add(aSx, aLSx);
248       }
249     }
250     else {
251       const TopTools_ListOfShape& aLSp=myImages.Image(aSx);
252       aIt.Initialize(aLSp);
253       for (; aIt.More(); aIt.Next()) {
254         const TopoDS_Shape& aSp=aIt.Value();
255         if (myMapShape.Contains(aSp)) {
256           aLSx.Append(aSp);
257         }
258       }
259       myImagesResult.Add(aSx, aLSx);
260     }
261     //
262     //modified by NIZNHY-PKV Thu Dec  7 11:34:10 2006t
263     //
264     // 4.2 As it was
265     if (!myHasDeleted) {
266       myHasDeleted=IsDeleted(aSx);//xx
267     }
268     //
269     if (!myHasGenerated || !myHasModified) {
270       if (aType==TopAbs_EDGE   || aType==TopAbs_FACE ||
271           aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
272         //modified by NIZNHY-PKV Thu Dec  7 11:53:01 2006f
273         //bHasImage=myImages.HasImage(aSx);
274         //modified by NIZNHY-PKV Thu Dec  7 11:53:04 2006t
275         if (bHasImage) {
276           const TopTools_ListOfShape& aLSp=myImages.Image(aSx);
277           aIt.Initialize(aLSp);
278           for (; aIt.More(); aIt.Next()) {
279             const TopoDS_Shape& aSp=aIt.Value();
280             //
281             if (myMapShape.Contains(aSp)) {
282               bContainsSD=mySameDomainShapes.Contains(aSp);
283               //
284               if (!myHasGenerated) {
285                 if (bContainsSD) {
286                   myHasGenerated=Standard_True;
287                 }
288               }
289               if (!myHasModified) {
290                 if (!bContainsSD) {
291                   myHasModified=Standard_True;
292                 }
293               }
294             } // if (myMapShape.Contains(aSp))
295           }
296         }
297       }
298     }
299   }
300
301 }
302 //=======================================================================
303 //function : MapShapes
304 //purpose  :
305 //=======================================================================
306   void MapShapes(const TopoDS_Shape& theS,
307                  TopTools_MapOfShape& theM)
308 {
309   theM.Add(theS);
310   TopoDS_Iterator anIt;
311   anIt.Initialize(theS);
312   for (; anIt.More(); anIt.Next()) {
313     const TopoDS_Shape& aSx=anIt.Value();
314     MapShapes(aSx, theM);
315   }
316 }