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