Salome HOME
This commit was generated by cvs2git to create tag 'StableState1'.
[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 #include <NMTTools_DSFiller.hxx>
39
40 #include <GEOMAlgo_Tools3D.hxx>
41
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=myDSFiller->DS();
54   NMTTools_PaveFiller* pPF=(NMTTools_PaveFiller*)&(myDSFiller->PaveFiller());
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=myDSFiller->DS();
109   NMTTools_PaveFiller* pPF=(NMTTools_PaveFiller*)&(myDSFiller->PaveFiller());
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   myHistShapes.Clear();
212   myMapShape.Clear();
213   myHasDeleted=Standard_False;
214   myHasGenerated=Standard_False;
215   myHasModified=Standard_False;
216   //
217   if(myShape.IsNull()) {
218     return;
219   }
220   //
221   MapShapes(myShape, myMapShape);
222   //
223   Standard_Boolean bHasImage, bContainsSD;
224   TopAbs_ShapeEnum aType;
225   TopTools_MapOfShape aMS;
226   TopTools_ListIteratorOfListOfShape aIt;
227   TopTools_MapIteratorOfMapOfShape aItM;
228   //
229   aIt.Initialize(myShapes);
230   for (; aIt.More(); aIt.Next()) {
231     const TopoDS_Shape& aS=aIt.Value();
232     MapShapes(aS, aMS);
233   }
234   //
235   aItM.Initialize(aMS);
236   for (; aItM.More(); aItM.Next()) {
237     const TopoDS_Shape& aSx=aItM.Key();
238     aType=aSx.ShapeType();
239     //
240     if (!myHasDeleted) {
241       myHasDeleted=IsDeleted(aSx);//xx
242     }
243     //
244     if (!myHasGenerated || !myHasModified) {
245       if (aType==TopAbs_EDGE   || aType==TopAbs_FACE || 
246           aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
247         bHasImage=myImages.HasImage(aSx);
248         if (bHasImage) {
249           const TopTools_ListOfShape& aLSp=myImages.Image(aSx);
250           aIt.Initialize(aLSp);
251           for (; aIt.More(); aIt.Next()) {
252             const TopoDS_Shape& aSp=aIt.Value();
253             //
254             if (myMapShape.Contains(aSp)) {
255               bContainsSD=mySameDomainShapes.Contains(aSp);
256               //
257               if (!myHasGenerated) {
258                 if (bContainsSD) {
259                   myHasGenerated=Standard_True;
260                 }
261               }
262               if (!myHasModified) {
263                 if (!bContainsSD) {
264                   myHasModified=Standard_True;
265                 }
266               }
267             } // if (myMapShape.Contains(aSp))
268           }
269         }
270       } 
271     }
272   }
273   
274 }
275 //=======================================================================
276 //function : MapShapes
277 //purpose  : 
278 //=======================================================================
279   void MapShapes(const TopoDS_Shape& theS,
280                  TopTools_MapOfShape& theM)
281 {
282   theM.Add(theS);
283   TopoDS_Iterator anIt;
284   anIt.Initialize(theS);
285   for (; anIt.More(); anIt.Next()) {
286     const TopoDS_Shape& aSx=anIt.Value();
287     MapShapes(aSx, theM);
288   }
289 }