Salome HOME
Merge from V6_main 01/04/2013
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_ShapeSet.cxx
1 // Copyright (C) 2007-2013  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
23 // File:        GEOMAlgo_ShapeSet.cxx
24 // Created:
25 // Author:      Peter KURNEV
26 //
27 #include <GEOMAlgo_ShapeSet.hxx>
28
29 #include <TopExp_Explorer.hxx>
30
31 #include <TopTools_ListIteratorOfListOfShape.hxx>
32 #include <TopTools_MapIteratorOfMapOfOrientedShape.hxx>
33
34 //=======================================================================
35 //function :
36 //purpose  :
37 //=======================================================================
38   GEOMAlgo_ShapeSet::GEOMAlgo_ShapeSet()
39 {
40 }
41 //=======================================================================
42 //function : Clear
43 //purpose  :
44 //=======================================================================
45   void GEOMAlgo_ShapeSet::Clear()
46 {
47   myMap.Clear();
48   myList.Clear();
49 }
50 //=======================================================================
51 //function : Add
52 //purpose  :
53 //=======================================================================
54   void GEOMAlgo_ShapeSet::Add(const TopoDS_Shape& theShape)
55 {
56   if (myMap.Add(theShape)) {
57     myList.Append(theShape);
58   }
59 }
60 //=======================================================================
61 //function : Add
62 //purpose  :
63 //=======================================================================
64   void GEOMAlgo_ShapeSet::Add(const TopoDS_Shape& theShape,
65                               const TopAbs_ShapeEnum theType)
66 {
67   TopExp_Explorer aExp;
68   //
69   aExp.Init(theShape, theType);
70   for (; aExp.More(); aExp.Next()) {
71     const TopoDS_Shape& aS=aExp.Current();
72     if (myMap.Add(aS)) {
73       myList.Append(aS);
74     }
75   }
76 }
77 //=======================================================================
78 //function : Add
79 //purpose  :
80 //=======================================================================
81   void GEOMAlgo_ShapeSet::Add(const TopTools_ListOfShape& theLS)
82 {
83   TopTools_ListIteratorOfListOfShape aIt;
84   //
85   aIt.Initialize(theLS);
86   for (; aIt.More(); aIt.Next()) {
87     const TopoDS_Shape& aS=aIt.Value();
88     if (myMap.Add(aS)) {
89       myList.Append(aS);
90     }
91   }
92 }
93 //=======================================================================
94 //function :GetSet
95 //purpose  :
96 //=======================================================================
97   const TopTools_ListOfShape& GEOMAlgo_ShapeSet::GetSet()const
98 {
99   return myList;
100 }
101 //=======================================================================
102 //function : Contains
103 //purpose  :
104 //=======================================================================
105   Standard_Boolean GEOMAlgo_ShapeSet::Contains(const GEOMAlgo_ShapeSet& theOther)const
106 {
107   Standard_Boolean bRet;
108   TopAbs_Orientation aOr;
109   TopTools_ListIteratorOfListOfShape aIt;
110   //
111   bRet=Standard_True;
112   const TopTools_ListOfShape& aLS=theOther.GetSet();
113   aIt.Initialize(aLS);
114   for (; aIt.More(); aIt.Next()) {
115     const TopoDS_Shape& aF=aIt.Value();
116     aOr=aF.Orientation();
117     if (aOr==TopAbs_FORWARD || aOr==TopAbs_REVERSED) {
118       bRet=myMap.Contains(aF);
119       if (!bRet) {
120         break;
121       }
122     }
123   }
124   return bRet;
125 }
126 //=======================================================================
127 //function : Subtract
128 //purpose  :
129 //=======================================================================
130   void GEOMAlgo_ShapeSet::Subtract(const GEOMAlgo_ShapeSet& theOther)
131 {
132   TopTools_ListIteratorOfListOfShape aIt;
133   TopTools_ListOfShape aLS;
134   //
135   myMap.Clear();
136   aIt.Initialize(myList);
137   for (; aIt.More(); aIt.Next()) {
138     const TopoDS_Shape& aS=aIt.Value();
139     if (!theOther.myMap.Contains(aS)) {
140       if(myMap.Add(aS)){
141         aLS.Append(aS);
142       }
143     }
144   }
145   //
146   myList=aLS;
147 }
148 //modified by NIZNHY-PKV Wed Oct 28 13:51:36 2010f
149 //=======================================================================
150 //function : IsEqual
151 //purpose  :
152 //=======================================================================
153   Standard_Boolean GEOMAlgo_ShapeSet::IsEqual(const GEOMAlgo_ShapeSet& theOther)const
154 {
155   Standard_Boolean bRet;
156   Standard_Integer aNb1, aNb2;
157   TopTools_ListIteratorOfListOfShape aIt;
158   //
159   bRet=Standard_True;
160   aNb1=myList.Extent();
161   const TopTools_ListOfShape& aLS2=theOther.GetSet();
162   aNb2=aLS2.Extent();
163   if (aNb1!=aNb2) {
164     return !bRet;
165   }
166   //
167   aIt.Initialize(myList);
168   for (; aIt.More(); aIt.Next()) {
169     const TopoDS_Shape& aS=aIt.Value();
170     if(!theOther.myMap.Contains(aS)) {
171       bRet=!bRet;
172       break;
173     }
174   }
175   return bRet;
176 }
177 //modified by NIZNHY-PKV Wed Oct 28 13:51:38 2010t