Salome HOME
Integration next version of GEOM packages from PKV.
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_Builder_4.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 // File:        GEOMAlgo_Builder_4.cxx
21 // Created:     
22 // Author:      Peter KURNEV 
23
24 #include <GEOMAlgo_Builder.hxx>
25
26 #include <TopoDS_Iterator.hxx>
27
28 #include <TopTools_ListOfShape.hxx>
29 #include <TopTools_ListIteratorOfListOfShape.hxx>
30 #include <TopTools_MapOfShape.hxx>
31 #include <TopTools_MapIteratorOfMapOfShape.hxx>
32
33 #include <IntTools_Context.hxx>
34
35 #include <NMTDS_ShapesDataStructure.hxx>
36
37 #include <NMTTools_PaveFiller.hxx>
38
39 #include <GEOMAlgo_Tools3D.hxx>
40
41 static
42   void MapShapes(const TopoDS_Shape& aS,
43                  TopTools_MapOfShape& aM);
44
45 //=======================================================================
46 //function : Generated
47 //purpose  : 
48 //=======================================================================
49   const TopTools_ListOfShape& GEOMAlgo_Builder::Generated(const TopoDS_Shape& theS)
50 {
51   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
52   NMTTools_PaveFiller* pPF=myPaveFiller;
53   IntTools_Context& aCtx=pPF->ChangeContext();
54   //
55   Standard_Boolean bHasImage, bToReverse;
56   TopAbs_ShapeEnum aType;
57   TopTools_ListIteratorOfListOfShape aIt;
58   //
59   myHistShapes.Clear();
60   //
61   if (theS.IsNull()) {
62     return myHistShapes;
63   }
64   //
65   bHasImage=myImages.HasImage(theS);
66   if (!bHasImage) {
67     return myHistShapes;
68   }
69   //
70   aType=theS.ShapeType();
71   //
72   if (aType==TopAbs_EDGE   || aType==TopAbs_FACE || 
73       aType==TopAbs_VERTEX || aType==TopAbs_SOLID) { 
74     const TopTools_ListOfShape& aLSp=myImages.Image(theS);
75     aIt.Initialize(aLSp);
76     for (; aIt.More(); aIt.Next()) {
77       const TopoDS_Shape& aSp=aIt.Value();
78       if (mySameDomainShapes.Contains(aSp)) {
79         if (myMapShape.Contains(aSp)) {
80           TopoDS_Shape aSpR=mySameDomainShapes.FindFromKey(aSp);
81           //
82           if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
83             aSpR.Orientation(theS.Orientation());
84           }
85           else {
86             bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aSpR, theS, aCtx);
87             if (bToReverse) {
88               aSpR.Reverse();
89             }
90           }
91           //
92           myHistShapes.Append(aSpR);
93         }
94       }
95     }
96   }
97   //
98   return myHistShapes;
99 }
100 //=======================================================================
101 //function : Modified
102 //purpose  : 
103 //=======================================================================
104   const TopTools_ListOfShape& GEOMAlgo_Builder::Modified(const TopoDS_Shape& theS)
105 {
106   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
107   NMTTools_PaveFiller* pPF=myPaveFiller;
108   IntTools_Context& aCtx=pPF->ChangeContext();
109   //
110   Standard_Boolean bHasImage, bToReverse;
111   TopAbs_ShapeEnum aType;
112   TopTools_ListIteratorOfListOfShape aIt;
113   //
114   myHistShapes.Clear();
115   //
116   if (theS.IsNull()) {
117     return myHistShapes;
118   }
119   //
120   bHasImage=myImages.HasImage(theS);
121   if (!bHasImage) {
122     return myHistShapes;
123   }
124   //
125   aType=theS.ShapeType();
126   //
127   if (aType==TopAbs_EDGE   || aType==TopAbs_FACE || 
128       aType==TopAbs_VERTEX || aType==TopAbs_SOLID) { 
129     const TopTools_ListOfShape& aLSp=myImages.Image(theS);
130     aIt.Initialize(aLSp);
131     for (; aIt.More(); aIt.Next()) {
132       TopoDS_Shape aSp=aIt.Value();
133       if (!mySameDomainShapes.Contains(aSp)) {
134         if (myMapShape.Contains(aSp)) {
135           //
136           if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
137             aSp.Orientation(theS.Orientation());
138           }
139           else {
140             bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aSp, theS, aCtx);
141             if (bToReverse) {
142               aSp.Reverse();
143             }
144           }
145           //
146           myHistShapes.Append(aSp);
147         }
148       }
149     }
150   }
151   //
152   return myHistShapes;
153 }
154 //=======================================================================
155 //function : IsDeleted
156 //purpose  : 
157 //=======================================================================
158   Standard_Boolean GEOMAlgo_Builder::IsDeleted(const TopoDS_Shape& theS)
159 {
160   Standard_Boolean bRet, bHasImage, bContains;
161   TopAbs_ShapeEnum aType;
162   TopTools_ListIteratorOfListOfShape aIt;
163   //
164   bRet=Standard_False;
165   //
166   if (theS.IsNull()) {
167     return !bRet; //true
168   }
169   //
170   bContains=myMapShape.Contains(theS);
171   if (bContains) {
172     return bRet; //false
173   }
174   //
175   bHasImage=myImages.HasImage(theS);
176   if (!bHasImage) {
177     return !bRet; //true
178   }
179   //
180   aType=theS.ShapeType();
181   if (aType==TopAbs_EDGE   || aType==TopAbs_FACE || 
182       aType==TopAbs_VERTEX || aType==TopAbs_SOLID) { 
183     const TopTools_ListOfShape& aLSp=myImages.Image(theS);
184     aIt.Initialize(aLSp);
185     for (; aIt.More(); aIt.Next()) {
186       TopoDS_Shape aSp=aIt.Value();
187       //
188       if (!mySameDomainShapes.Contains(aSp)) {
189         if (myMapShape.Contains(aSp)) {
190           return bRet; //false
191         }
192       }
193       else {
194         TopoDS_Shape aSpR=mySameDomainShapes.FindFromKey(aSp);
195         if (myMapShape.Contains(aSpR)) {
196           return bRet; //false
197         }
198       }
199     }
200   }
201   return !bRet; // true
202 }
203 //=======================================================================
204 //function : PrepareHistory
205 //purpose  : 
206 //=======================================================================
207   void GEOMAlgo_Builder::PrepareHistory()
208 {
209   if(myShape.IsNull()) {
210     return;
211   }
212   //
213   Standard_Boolean bHasImage, bContainsSD;
214   TopAbs_ShapeEnum aType;
215   TopTools_MapOfShape aMS;
216   TopTools_ListIteratorOfListOfShape aIt;
217   TopTools_MapIteratorOfMapOfShape aItM;
218   //
219   // 1. Clearing 
220   GEOMAlgo_BuilderShape::PrepareHistory();
221   //
222   // 2. myMapShape - all shapes of result with theirs sub-shapes 
223   MapShapes(myShape, myMapShape);
224   //
225   // 3. MS - all argument shapes with theirs sub-shapes
226   aIt.Initialize(myShapes);
227   for (; aIt.More(); aIt.Next()) {
228     const TopoDS_Shape& aSx=aIt.Value();
229     MapShapes(aSx, aMS);
230   }
231   //
232   // 4. Treatment
233   aItM.Initialize(aMS);
234   for (; aItM.More(); aItM.Next()) {
235     const TopoDS_Shape& aSx=aItM.Key();
236     aType=aSx.ShapeType();
237     //modified by NIZNHY-PKV Thu Dec  7 11:34:05 2006f
238     //
239     // 4.1 .myImagesResult
240     TopTools_ListOfShape aLSx;
241     //
242     bHasImage=myImages.HasImage(aSx);
243     if (!bHasImage) {
244       if (myMapShape.Contains(aSx)) {
245         aLSx.Append(aSx);
246         myImagesResult.Add(aSx, aLSx);
247       }
248     }
249     else {
250       const TopTools_ListOfShape& aLSp=myImages.Image(aSx);
251       aIt.Initialize(aLSp);
252       for (; aIt.More(); aIt.Next()) {
253         const TopoDS_Shape& aSp=aIt.Value();
254         if (myMapShape.Contains(aSp)) {
255           aLSx.Append(aSp);
256         }
257       }
258       myImagesResult.Add(aSx, aLSx);
259     }
260     //
261     //modified by NIZNHY-PKV Thu Dec  7 11:34:10 2006t
262     //
263     // 4.2 As it was 
264     if (!myHasDeleted) {
265       myHasDeleted=IsDeleted(aSx);//xx
266     }
267     //
268     if (!myHasGenerated || !myHasModified) {
269       if (aType==TopAbs_EDGE   || aType==TopAbs_FACE || 
270           aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
271         //modified by NIZNHY-PKV Thu Dec  7 11:53:01 2006f
272         //bHasImage=myImages.HasImage(aSx);
273         //modified by NIZNHY-PKV Thu Dec  7 11:53:04 2006t
274         if (bHasImage) {
275           const TopTools_ListOfShape& aLSp=myImages.Image(aSx);
276           aIt.Initialize(aLSp);
277           for (; aIt.More(); aIt.Next()) {
278             const TopoDS_Shape& aSp=aIt.Value();
279             //
280             if (myMapShape.Contains(aSp)) {
281               bContainsSD=mySameDomainShapes.Contains(aSp);
282               //
283               if (!myHasGenerated) {
284                 if (bContainsSD) {
285                   myHasGenerated=Standard_True;
286                 }
287               }
288               if (!myHasModified) {
289                 if (!bContainsSD) {
290                   myHasModified=Standard_True;
291                 }
292               }
293             } // if (myMapShape.Contains(aSp))
294           }
295         }
296       } 
297     }
298   }
299   
300 }
301 //=======================================================================
302 //function : MapShapes
303 //purpose  : 
304 //=======================================================================
305   void MapShapes(const TopoDS_Shape& theS,
306                  TopTools_MapOfShape& theM)
307 {
308   theM.Add(theS);
309   TopoDS_Iterator anIt;
310   anIt.Initialize(theS);
311   for (; anIt.More(); anIt.Next()) {
312     const TopoDS_Shape& aSx=anIt.Value();
313     MapShapes(aSx, theM);
314   }
315 }