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