0031501: Foundation Classes, Message_Printer - remove theToPutEndl argument -- prepar...
[occt.git] / src / IFSelect / IFSelect_SelectPointed.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14
42cf5bc1 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>
7fd59977 25
92efcf78 26IMPLEMENT_STANDARD_RTTIEXT(IFSelect_SelectPointed,IFSelect_SelectBase)
27
b311480e 28IFSelect_SelectPointed::IFSelect_SelectPointed ()
7fd59977 29 : theset (Standard_False) { }
30
31 void IFSelect_SelectPointed::Clear()
32 { theitems.Clear(); theset = Standard_False; }
33
34 Standard_Boolean IFSelect_SelectPointed::IsSet () const
35 { return theset; }
36
37 void IFSelect_SelectPointed::SetEntity
38 (const Handle(Standard_Transient)& ent)
39{
40 theitems.Clear();
41 theset = Standard_True;
42 if (ent.IsNull()) return;
43 theitems.Append (ent);
44}
45
46 void IFSelect_SelectPointed::SetList
47 (const Handle(TColStd_HSequenceOfTransient)& list)
48{
49 theitems.Clear();
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));
54}
55
56// .... Editions
57
58 Standard_Boolean IFSelect_SelectPointed::Add
59 (const Handle(Standard_Transient)& item)
60{
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;
66 return Standard_True;
67}
68
69 Standard_Boolean IFSelect_SelectPointed::Remove
70 (const Handle(Standard_Transient)& item)
71{
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;}
75 return Standard_True;
76}
77
78 Standard_Boolean IFSelect_SelectPointed::Toggle
79 (const Handle(Standard_Transient)& item)
80{
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);
87 return (num == 0);
88}
89
90 Standard_Boolean IFSelect_SelectPointed::AddList
91 (const Handle(TColStd_HSequenceOfTransient)& list)
92{
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));
99
100 for (i = 1; i <= nl; i ++) {
101 if (!deja.Contains (list->Value(i)) ) theitems.Append (list->Value(i));
102 }
103 theset = Standard_True;
104 return res;
105}
106
107 Standard_Boolean IFSelect_SelectPointed::RemoveList
108 (const Handle(TColStd_HSequenceOfTransient)& list)
109{
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));
114 return res;
115}
116
117 Standard_Boolean IFSelect_SelectPointed::ToggleList
118 (const Handle(TColStd_HSequenceOfTransient)& list)
119{
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));
124 return res;
125}
126
127
128// .... Consultations
129
130 Standard_Integer IFSelect_SelectPointed::Rank
131 (const Handle(Standard_Transient)& item) const
132{
133 if (item.IsNull()) return 0;
134 for (Standard_Integer i = theitems.Length(); i >= 1; i --)
135 if (item == theitems.Value(i)) return i;
136 return 0;
137}
138
139 Standard_Integer IFSelect_SelectPointed::NbItems () const
140 { return theitems.Length(); }
141
142 Handle(Standard_Transient) IFSelect_SelectPointed::Item
143 (const Standard_Integer num) const
144{
145 Handle(Standard_Transient) item;
146 if (num <= 0 || num > theitems.Length()) return item;
147 return theitems.Value(num);
148}
149
150 void IFSelect_SelectPointed::Update
151 (const Handle(Interface_CopyControl)& control)
152{
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);
159 }
160}
161
162 void IFSelect_SelectPointed::Update
163 (const Handle(IFSelect_Transformer)& trf)
164{
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);
171 }
172}
173
174// .... Actions Generales
175
176 Interface_EntityIterator IFSelect_SelectPointed::RootResult
177 (const Interface_Graph& G) const
178{
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);
184 }
185 return result;
186}
187
188 TCollection_AsciiString IFSelect_SelectPointed::Label () const
189 { return TCollection_AsciiString ("Pointed Entities"); }