0024510: Remove unused local variables
[occt.git] / src / IFSelect / IFSelect_SelectPointed.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and / or modify it
6 // under the terms of the GNU Lesser General Public version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <IFSelect_SelectPointed.ixx>
15 #include <TColStd_MapOfTransient.hxx>
16
17
18
19 IFSelect_SelectPointed::IFSelect_SelectPointed ()
20     : theset (Standard_False)    {  }
21
22     void  IFSelect_SelectPointed::Clear()
23       {  theitems.Clear();  theset = Standard_False;  }
24
25     Standard_Boolean  IFSelect_SelectPointed::IsSet () const
26       {  return theset;  }
27
28     void  IFSelect_SelectPointed::SetEntity
29   (const Handle(Standard_Transient)& ent)
30 {
31   theitems.Clear();
32   theset = Standard_True;
33   if (ent.IsNull()) return;
34   theitems.Append (ent);
35 }
36
37     void  IFSelect_SelectPointed::SetList
38   (const Handle(TColStd_HSequenceOfTransient)& list)
39 {
40   theitems.Clear();
41   theset = Standard_True;
42   if (list.IsNull()) return;
43   Standard_Integer i,nb = list->Length();
44   for (i = 1; i <= nb; i ++)  theitems.Append (list->Value(i));
45 }
46
47 //  ....    Editions
48
49     Standard_Boolean  IFSelect_SelectPointed::Add
50   (const Handle(Standard_Transient)& item)
51 {
52   if (item.IsNull()) return Standard_False;
53   for (Standard_Integer i = theitems.Length(); i >= 1; i --)
54     if (item == theitems.Value(i)) return Standard_False;
55   theitems.Append(item);
56   theset = Standard_True;
57   return Standard_True;
58 }
59
60     Standard_Boolean  IFSelect_SelectPointed::Remove
61   (const Handle(Standard_Transient)& item)
62 {
63   if (item.IsNull()) return Standard_False;
64   for (Standard_Integer i = theitems.Length(); i >= 1; i --)
65     if (item == theitems.Value(i)) { theitems.Remove(i); return Standard_True;}
66   return Standard_True;
67 }
68
69     Standard_Boolean  IFSelect_SelectPointed::Toggle
70   (const Handle(Standard_Transient)& item)
71 {
72   if (item.IsNull()) return Standard_False;
73   Standard_Integer num = 0;
74   for (Standard_Integer i = theitems.Length(); i >= 1; i --)
75     if (item == theitems.Value(i)) num = i;
76   if (num == 0) theitems.Append(item);
77   else          theitems.Remove(num);
78   return (num == 0);
79 }
80
81     Standard_Boolean  IFSelect_SelectPointed::AddList
82   (const Handle(TColStd_HSequenceOfTransient)& list)
83 {
84 //   Optimise avec une Map
85   Standard_Boolean res = Standard_False;
86   if (list.IsNull()) return res;
87   Standard_Integer i, nb = theitems.Length(), nl = list->Length();
88   TColStd_MapOfTransient deja (nb+nl+1);
89   for (i = 1; i <= nb; i ++) deja.Add (theitems.Value(i));
90
91   for (i = 1; i <= nl; i ++) {
92     if (!deja.Contains (list->Value(i)) ) theitems.Append (list->Value(i));
93   }
94   theset = Standard_True;
95   return res;
96 }
97
98     Standard_Boolean  IFSelect_SelectPointed::RemoveList
99   (const Handle(TColStd_HSequenceOfTransient)& list)
100 {
101   Standard_Boolean res = Standard_False;
102   if (list.IsNull()) return res;
103   Standard_Integer i, nb = list->Length();
104   for (i = 1; i <= nb; i ++) res |= Remove (list->Value(i));
105   return res;
106 }
107
108     Standard_Boolean  IFSelect_SelectPointed::ToggleList
109   (const Handle(TColStd_HSequenceOfTransient)& list)
110 {
111   Standard_Boolean res = Standard_True;
112   if (list.IsNull()) return res;
113   Standard_Integer i, nb = list->Length();
114   for (i = 1; i <= nb; i ++) res |= Toggle (list->Value(i));
115   return res;
116 }
117
118
119 //  ....   Consultations
120
121     Standard_Integer  IFSelect_SelectPointed::Rank
122   (const Handle(Standard_Transient)& item) const
123 {
124   if (item.IsNull()) return 0;
125   for (Standard_Integer i = theitems.Length(); i >= 1; i --)
126     if (item == theitems.Value(i)) return i;
127   return 0;
128 }
129
130     Standard_Integer  IFSelect_SelectPointed::NbItems () const
131       {  return theitems.Length();  }
132
133     Handle(Standard_Transient)  IFSelect_SelectPointed::Item
134   (const Standard_Integer num) const
135 {
136   Handle(Standard_Transient) item;
137   if (num <= 0 || num > theitems.Length()) return item;
138   return theitems.Value(num);
139 }
140
141     void  IFSelect_SelectPointed::Update
142   (const Handle(Interface_CopyControl)& control)
143 {
144   Standard_Integer nb = theitems.Length();
145   for (Standard_Integer i = nb; i > 0; i --) {
146     Handle(Standard_Transient) enfr, ento;
147     enfr = theitems.Value(i);
148     if (!control->Search(enfr,ento)) theitems.Remove(i);
149     else  theitems.SetValue(i,ento);
150   }
151 }
152
153     void  IFSelect_SelectPointed::Update
154   (const Handle(IFSelect_Transformer)& trf)
155 {
156   Standard_Integer nb = theitems.Length();
157   for (Standard_Integer i = nb; i > 0; i --) {
158     Handle(Standard_Transient) enfr, ento;
159     enfr = theitems.Value(i);
160     if (!trf->Updated(enfr,ento)) theitems.Remove(i);
161     else  theitems.SetValue(i,ento);
162   }
163 }
164
165 //  ....  Actions Generales
166
167     Interface_EntityIterator  IFSelect_SelectPointed::RootResult
168   (const Interface_Graph& G) const
169 {
170   Interface_EntityIterator result;
171   Standard_Integer nb = theitems.Length();
172   for (Standard_Integer i = 1; i <= nb; i ++) {
173     Handle(Standard_Transient) item = theitems.Value(i);
174     if (G.EntityNumber(item) > 0) result.GetOneItem(item);
175   }
176   return result;
177 }
178
179     TCollection_AsciiString  IFSelect_SelectPointed::Label () const
180       {  return TCollection_AsciiString ("Pointed Entities");  }