Salome HOME
Merge from V5_1_main 14/05/2010
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_ShapeSet.cxx
1 //  Copyright (C) 2007-2010  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.ixx>
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   /*
100   TopTools_ListOfShape *pL;
101   TopTools_MapIteratorOfMapOfOrientedShape aIt;
102   //
103   pL=(TopTools_ListOfShape *)&myList;
104   pL->Clear();
105   aIt.Initialize(myMap);
106   for (; aIt.More(); aIt.Next()) {
107     pL->Append(aIt.Key());
108   }
109   */
110   return myList;
111 }
112 //=======================================================================
113 //function : Contains
114 //purpose  : 
115 //=======================================================================
116   Standard_Boolean GEOMAlgo_ShapeSet::Contains(const GEOMAlgo_ShapeSet& theOther)const
117 {
118   Standard_Boolean bRet;
119   TopAbs_Orientation aOr;
120   TopTools_ListIteratorOfListOfShape aIt;
121   //
122   bRet=Standard_True;
123   const TopTools_ListOfShape& aLS=theOther.GetSet();
124   aIt.Initialize(aLS);
125   for (; aIt.More(); aIt.Next()) {
126     const TopoDS_Shape& aF=aIt.Value();
127     aOr=aF.Orientation();
128     if (aOr==TopAbs_FORWARD || aOr==TopAbs_REVERSED) {
129       bRet=myMap.Contains(aF);
130       if (!bRet) {
131         break;
132       }
133     }
134   }
135   return bRet;
136 }
137 //=======================================================================
138 //function : Subtract
139 //purpose  : 
140 //=======================================================================
141   void GEOMAlgo_ShapeSet::Subtract(const GEOMAlgo_ShapeSet& theOther)
142 {
143   /*
144   TopTools_MapIteratorOfMapOfOrientedShape aIt;
145   //
146   aIt.Initialize(theOther.myMap);
147   for (; aIt.More(); aIt.Next()) {
148     const TopoDS_Shape& aS=aIt.Key();
149     myMap.Remove(aS);
150   }
151   */
152   //
153   TopTools_ListIteratorOfListOfShape aIt;
154   TopTools_ListOfShape aLS;
155   //
156   myMap.Clear();
157   aIt.Initialize(myList);
158   for (; aIt.More(); aIt.Next()) {
159     const TopoDS_Shape& aS=aIt.Value();
160     if (!theOther.myMap.Contains(aS)) {
161       if(myMap.Add(aS)){
162         aLS.Append(aS);
163       }
164     }
165   }
166   //
167   myList=aLS;
168 }