Salome HOME
Internal issue 0022865: Restructurization of Partition packages.
[modules/geom.git] / src / GEOMAlgo_NEW / GEOMAlgo_Gluer2_2.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_Gluer2_2.cxx
23 // Created:     
24 // Author:      Peter KURNEV
25 //              <peter@PREFEX>
26 //
27 #include <GEOMAlgo_Gluer2.hxx>
28
29 #include <TopAbs_ShapeEnum.hxx>
30
31 #include <TopoDS_Iterator.hxx>
32 #include <TopoDS_Shape.hxx>
33
34 #include <GEOMAlgo_BuilderShape.hxx>
35 #include <GEOMAlgo_Tools3D.hxx>
36
37 //=======================================================================
38 //function : PrepareHistory
39 //purpose  : 
40 //=======================================================================
41 void GEOMAlgo_Gluer2::PrepareHistory()
42 {
43   //Standard_Boolean bHasImage, bContainsSD;
44   //
45   // 1. Clearing 
46   GEOMAlgo_BuilderShape::PrepareHistory();
47   //  
48   if(myShape.IsNull()) {
49     return;
50   }
51   //
52   GEOMAlgo_Gluer2::MapShapes(myShape, myMapShape);  
53   //
54 }
55 //=======================================================================
56 //function : Generated
57 //purpose  : 
58 //=======================================================================
59 const TopTools_ListOfShape& GEOMAlgo_Gluer2::Generated(const TopoDS_Shape& )
60 {
61   myHistShapes.Clear();
62   return myHistShapes;
63 }
64 //=======================================================================
65 //function : Modified
66 //purpose  : 
67 //=======================================================================
68 const TopTools_ListOfShape& GEOMAlgo_Gluer2::Modified(const TopoDS_Shape& theS)
69 {
70   Standard_Boolean bIsDeleted, bHasImage, bToReverse;
71   TopAbs_ShapeEnum aType;
72   TopoDS_Shape aSim;
73   //
74   myHistShapes.Clear();
75   //
76   aType=theS.ShapeType();
77   if (!(aType==TopAbs_VERTEX || aType==TopAbs_EDGE || 
78         aType==TopAbs_FACE || aType==TopAbs_SOLID)) { 
79     return myHistShapes;
80   }
81   //
82   bIsDeleted=IsDeleted(theS);
83   if (bIsDeleted) {
84     return myHistShapes;
85   }
86   //
87   bHasImage=myOrigins.IsBound(theS);
88   if (!bHasImage) {
89     return myHistShapes;
90   }
91   //
92   aSim=myOrigins.Find(theS);
93   if (aSim.IsSame(theS)){
94     return myHistShapes;
95   }
96   //
97   if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
98     aSim.Orientation(theS.Orientation());
99   }
100   else {
101     bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aSim, theS, myContext);
102     if (bToReverse) {
103       aSim.Reverse();
104     }
105   }
106   //
107   myHistShapes.Append(aSim);
108   //
109   return myHistShapes;
110 }
111 //=======================================================================
112 //function : IsDeleted
113 //purpose  : 
114 //=======================================================================
115 Standard_Boolean GEOMAlgo_Gluer2::IsDeleted(const TopoDS_Shape& theS)
116 {
117   Standard_Boolean bRet, bContains, bHasImage;
118   //
119   bRet=Standard_False;
120   //
121   if (theS.IsNull()) {
122     return !bRet; //true
123   }
124   //
125   bContains=myMapShape.Contains(theS);
126   if (bContains) {
127     return bRet; //false
128   }
129   //
130   bHasImage=myOrigins.IsBound(theS);
131   if (bHasImage) {
132     const TopoDS_Shape& aSim=myOrigins.Find(theS);
133     bContains=myMapShape.Contains(aSim);
134     if (bContains) {
135       return bRet; //false
136     }
137   }
138   //
139   return !bRet; //true
140 }
141 //=======================================================================
142 //function : MapShapes
143 //purpose  : 
144 //=======================================================================
145 void GEOMAlgo_Gluer2::MapShapes(const TopoDS_Shape& theS,
146                                 TopTools_MapOfShape& theM)
147 {
148   TopoDS_Iterator aIt;
149   //
150   theM.Add(theS);
151   aIt.Initialize(theS);
152   for (; aIt.More(); aIt.Next()) {
153     const TopoDS_Shape& aSx=aIt.Value();
154     GEOMAlgo_Gluer2::MapShapes(aSx, theM);
155   }
156 }