1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License 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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <IFSelect_SelectPointed.hxx>
16 #include <IFSelect_Transformer.hxx>
17 #include <Interface_CopyControl.hxx>
18 #include <Interface_EntityIterator.hxx>
19 #include <Interface_Graph.hxx>
20 #include <Interface_InterfaceError.hxx>
21 #include <Standard_Transient.hxx>
22 #include <Standard_Type.hxx>
23 #include <TCollection_AsciiString.hxx>
24 #include <TColStd_MapOfTransient.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(IFSelect_SelectPointed,IFSelect_SelectBase)
28 IFSelect_SelectPointed::IFSelect_SelectPointed ()
29 : theset (Standard_False) { }
31 void IFSelect_SelectPointed::Clear()
32 { theitems.Clear(); theset = Standard_False; }
34 Standard_Boolean IFSelect_SelectPointed::IsSet () const
37 void IFSelect_SelectPointed::SetEntity
38 (const Handle(Standard_Transient)& ent)
41 theset = Standard_True;
42 if (ent.IsNull()) return;
43 theitems.Append (ent);
46 void IFSelect_SelectPointed::SetList
47 (const Handle(TColStd_HSequenceOfTransient)& list)
50 theset = Standard_True;
51 if (list.IsNull()) return;
52 Standard_Integer i,nb = list->Length();
53 for (i = 1; i <= nb; i ++) theitems.Append (list->Value(i));
58 Standard_Boolean IFSelect_SelectPointed::Add
59 (const Handle(Standard_Transient)& item)
61 if (item.IsNull()) return Standard_False;
62 for (Standard_Integer i = theitems.Length(); i >= 1; i --)
63 if (item == theitems.Value(i)) return Standard_False;
64 theitems.Append(item);
65 theset = Standard_True;
69 Standard_Boolean IFSelect_SelectPointed::Remove
70 (const Handle(Standard_Transient)& item)
72 if (item.IsNull()) return Standard_False;
73 for (Standard_Integer i = theitems.Length(); i >= 1; i --)
74 if (item == theitems.Value(i)) { theitems.Remove(i); return Standard_True;}
78 Standard_Boolean IFSelect_SelectPointed::Toggle
79 (const Handle(Standard_Transient)& item)
81 if (item.IsNull()) return Standard_False;
82 Standard_Integer num = 0;
83 for (Standard_Integer i = theitems.Length(); i >= 1; i --)
84 if (item == theitems.Value(i)) num = i;
85 if (num == 0) theitems.Append(item);
86 else theitems.Remove(num);
90 Standard_Boolean IFSelect_SelectPointed::AddList
91 (const Handle(TColStd_HSequenceOfTransient)& list)
93 // Optimise avec une Map
94 Standard_Boolean res = Standard_False;
95 if (list.IsNull()) return res;
96 Standard_Integer i, nb = theitems.Length(), nl = list->Length();
97 TColStd_MapOfTransient deja (nb+nl+1);
98 for (i = 1; i <= nb; i ++) deja.Add (theitems.Value(i));
100 for (i = 1; i <= nl; i ++) {
101 if (!deja.Contains (list->Value(i)) ) theitems.Append (list->Value(i));
103 theset = Standard_True;
107 Standard_Boolean IFSelect_SelectPointed::RemoveList
108 (const Handle(TColStd_HSequenceOfTransient)& list)
110 Standard_Boolean res = Standard_False;
111 if (list.IsNull()) return res;
112 Standard_Integer i, nb = list->Length();
113 for (i = 1; i <= nb; i ++) res |= Remove (list->Value(i));
117 Standard_Boolean IFSelect_SelectPointed::ToggleList
118 (const Handle(TColStd_HSequenceOfTransient)& list)
120 Standard_Boolean res = Standard_True;
121 if (list.IsNull()) return res;
122 Standard_Integer i, nb = list->Length();
123 for (i = 1; i <= nb; i ++) res |= Toggle (list->Value(i));
128 // .... Consultations
130 Standard_Integer IFSelect_SelectPointed::Rank
131 (const Handle(Standard_Transient)& item) const
133 if (item.IsNull()) return 0;
134 for (Standard_Integer i = theitems.Length(); i >= 1; i --)
135 if (item == theitems.Value(i)) return i;
139 Standard_Integer IFSelect_SelectPointed::NbItems () const
140 { return theitems.Length(); }
142 Handle(Standard_Transient) IFSelect_SelectPointed::Item
143 (const Standard_Integer num) const
145 Handle(Standard_Transient) item;
146 if (num <= 0 || num > theitems.Length()) return item;
147 return theitems.Value(num);
150 void IFSelect_SelectPointed::Update
151 (const Handle(Interface_CopyControl)& control)
153 Standard_Integer nb = theitems.Length();
154 for (Standard_Integer i = nb; i > 0; i --) {
155 Handle(Standard_Transient) enfr, ento;
156 enfr = theitems.Value(i);
157 if (!control->Search(enfr,ento)) theitems.Remove(i);
158 else theitems.SetValue(i,ento);
162 void IFSelect_SelectPointed::Update
163 (const Handle(IFSelect_Transformer)& trf)
165 Standard_Integer nb = theitems.Length();
166 for (Standard_Integer i = nb; i > 0; i --) {
167 Handle(Standard_Transient) enfr, ento;
168 enfr = theitems.Value(i);
169 if (!trf->Updated(enfr,ento)) theitems.Remove(i);
170 else theitems.SetValue(i,ento);
174 // .... Actions Generales
176 Interface_EntityIterator IFSelect_SelectPointed::RootResult
177 (const Interface_Graph& G) const
179 Interface_EntityIterator result;
180 Standard_Integer nb = theitems.Length();
181 for (Standard_Integer i = 1; i <= nb; i ++) {
182 Handle(Standard_Transient) item = theitems.Value(i);
183 if (G.EntityNumber(item) > 0) result.GetOneItem(item);
188 TCollection_AsciiString IFSelect_SelectPointed::Label () const
189 { return TCollection_AsciiString ("Pointed Entities"); }