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