Integration of OCCT 6.5.0 from SVN
[occt.git] / src / IFSelect / IFSelect_SelectPointed.cxx
CommitLineData
7fd59977 1#include <IFSelect_SelectPointed.ixx>
2#include <TColStd_MapOfTransient.hxx>
3
4
5
6 IFSelect_SelectPointed::IFSelect_SelectPointed ()
7 : theset (Standard_False) { }
8
9 void IFSelect_SelectPointed::Clear()
10 { theitems.Clear(); theset = Standard_False; }
11
12 Standard_Boolean IFSelect_SelectPointed::IsSet () const
13 { return theset; }
14
15 void IFSelect_SelectPointed::SetEntity
16 (const Handle(Standard_Transient)& ent)
17{
18 theitems.Clear();
19 theset = Standard_True;
20 if (ent.IsNull()) return;
21 theitems.Append (ent);
22}
23
24 void IFSelect_SelectPointed::SetList
25 (const Handle(TColStd_HSequenceOfTransient)& list)
26{
27 theitems.Clear();
28 theset = Standard_True;
29 if (list.IsNull()) return;
30 Standard_Integer i,nb = list->Length();
31 for (i = 1; i <= nb; i ++) theitems.Append (list->Value(i));
32}
33
34// .... Editions
35
36 Standard_Boolean IFSelect_SelectPointed::Add
37 (const Handle(Standard_Transient)& item)
38{
39 if (item.IsNull()) return Standard_False;
40 for (Standard_Integer i = theitems.Length(); i >= 1; i --)
41 if (item == theitems.Value(i)) return Standard_False;
42 theitems.Append(item);
43 theset = Standard_True;
44 return Standard_True;
45}
46
47 Standard_Boolean IFSelect_SelectPointed::Remove
48 (const Handle(Standard_Transient)& item)
49{
50 if (item.IsNull()) return Standard_False;
51 for (Standard_Integer i = theitems.Length(); i >= 1; i --)
52 if (item == theitems.Value(i)) { theitems.Remove(i); return Standard_True;}
53 return Standard_True;
54}
55
56 Standard_Boolean IFSelect_SelectPointed::Toggle
57 (const Handle(Standard_Transient)& item)
58{
59 if (item.IsNull()) return Standard_False;
60 Standard_Integer num = 0;
61 for (Standard_Integer i = theitems.Length(); i >= 1; i --)
62 if (item == theitems.Value(i)) num = i;
63 if (num == 0) theitems.Append(item);
64 else theitems.Remove(num);
65 return (num == 0);
66}
67
68 Standard_Boolean IFSelect_SelectPointed::AddList
69 (const Handle(TColStd_HSequenceOfTransient)& list)
70{
71// Optimise avec une Map
72 Standard_Boolean res = Standard_False;
73 if (list.IsNull()) return res;
74 Standard_Integer i, nb = theitems.Length(), nl = list->Length();
75 TColStd_MapOfTransient deja (nb+nl+1);
76 for (i = 1; i <= nb; i ++) deja.Add (theitems.Value(i));
77
78 for (i = 1; i <= nl; i ++) {
79 if (!deja.Contains (list->Value(i)) ) theitems.Append (list->Value(i));
80 }
81 theset = Standard_True;
82 return res;
83}
84
85 Standard_Boolean IFSelect_SelectPointed::RemoveList
86 (const Handle(TColStd_HSequenceOfTransient)& list)
87{
88 Standard_Boolean res = Standard_False;
89 if (list.IsNull()) return res;
90 Standard_Integer i, nb = list->Length();
91 for (i = 1; i <= nb; i ++) res |= Remove (list->Value(i));
92 return res;
93}
94
95 Standard_Boolean IFSelect_SelectPointed::ToggleList
96 (const Handle(TColStd_HSequenceOfTransient)& list)
97{
98 Standard_Boolean res = Standard_True;
99 if (list.IsNull()) return res;
100 Standard_Integer i, nb = list->Length();
101 for (i = 1; i <= nb; i ++) res |= Toggle (list->Value(i));
102 return res;
103}
104
105
106// .... Consultations
107
108 Standard_Integer IFSelect_SelectPointed::Rank
109 (const Handle(Standard_Transient)& item) const
110{
111 if (item.IsNull()) return 0;
112 for (Standard_Integer i = theitems.Length(); i >= 1; i --)
113 if (item == theitems.Value(i)) return i;
114 return 0;
115}
116
117 Standard_Integer IFSelect_SelectPointed::NbItems () const
118 { return theitems.Length(); }
119
120 Handle(Standard_Transient) IFSelect_SelectPointed::Item
121 (const Standard_Integer num) const
122{
123 Handle(Standard_Transient) item;
124 if (num <= 0 || num > theitems.Length()) return item;
125 return theitems.Value(num);
126}
127
128 void IFSelect_SelectPointed::Update
129 (const Handle(Interface_CopyControl)& control)
130{
131 Standard_Integer nb = theitems.Length();
132 for (Standard_Integer i = nb; i > 0; i --) {
133 Handle(Standard_Transient) enfr, ento;
134 enfr = theitems.Value(i);
135 if (!control->Search(enfr,ento)) theitems.Remove(i);
136 else theitems.SetValue(i,ento);
137 }
138}
139
140 void IFSelect_SelectPointed::Update
141 (const Handle(IFSelect_Transformer)& trf)
142{
143 Standard_Integer nb = theitems.Length();
144 for (Standard_Integer i = nb; i > 0; i --) {
145 Handle(Standard_Transient) enfr, ento;
146 enfr = theitems.Value(i);
147 if (!trf->Updated(enfr,ento)) theitems.Remove(i);
148 else theitems.SetValue(i,ento);
149 }
150}
151
152// .... Actions Generales
153
154 Interface_EntityIterator IFSelect_SelectPointed::RootResult
155 (const Interface_Graph& G) const
156{
157 Interface_EntityIterator result;
158 Standard_Integer nb = theitems.Length();
159 for (Standard_Integer i = 1; i <= nb; i ++) {
160 Handle(Standard_Transient) item = theitems.Value(i);
161 if (G.EntityNumber(item) > 0) result.GetOneItem(item);
162 }
163 return result;
164}
165
166 TCollection_AsciiString IFSelect_SelectPointed::Label () const
167 { return TCollection_AsciiString ("Pointed Entities"); }