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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <IFSelect_ListEditor.ixx>
16 IFSelect_ListEditor::IFSelect_ListEditor ()
17 : themax (0) , thetouc (0) { }
19 IFSelect_ListEditor::IFSelect_ListEditor
20 (const Handle(Interface_TypedValue)& def, const Standard_Integer max)
21 : themax (max) , thedef (def) , thetouc (0) { }
24 void IFSelect_ListEditor::LoadModel (const Handle(Interface_InterfaceModel)& model)
27 void IFSelect_ListEditor::LoadValues (const Handle(TColStd_HSequenceOfHAsciiString)& vals)
34 void IFSelect_ListEditor::SetTouched ()
37 void IFSelect_ListEditor::ClearEdit ()
39 theedit = new TColStd_HSequenceOfHAsciiString();
40 thestat = new TColStd_HSequenceOfInteger();
41 if (theorig.IsNull()) return;
42 Standard_Integer i,nb = theorig->Length();
43 for (i = 1; i <= nb; i ++) {
44 theedit->Append (theorig->Value(i));
50 // ######## CHECK ########
52 static Standard_Boolean CheckValue
53 (const Handle(TCollection_HAsciiString)& val,
54 const Handle(Interface_InterfaceModel)& modl,
55 const Handle(Interface_TypedValue)& thedef)
57 if (val.IsNull() || modl.IsNull() || thedef.IsNull()) return Standard_True;
59 Interface_ParamType pty = thedef->Type();
60 if (!thedef->Satisfies(val)) return Standard_False;
61 if (pty == Interface_ParamIdent && !val.IsNull()) {
62 if (modl->NextNumberForLabel(val->ToCString(),0) <= 0)
63 return Standard_False;
68 // ######## EDITION ########
70 Standard_Boolean IFSelect_ListEditor::LoadEdited
71 (const Handle(TColStd_HSequenceOfHAsciiString)& list)
73 if (list.IsNull()) return Standard_False;
74 Standard_Integer i, nb = list->Length();
75 if (nb > themax) return Standard_False;
78 if (!thedef.IsNull()) {
79 for (i = 1; i <= nb; i ++) {
80 Handle(TCollection_HAsciiString) newval = list->Value(i);
81 if (!CheckValue (newval,themodl,thedef)) return Standard_False;
87 thestat = new TColStd_HSequenceOfInteger();
88 for (i = 1; i <= nb; i ++) thestat->Append (1);
95 Standard_Boolean IFSelect_ListEditor::SetValue
96 (const Standard_Integer num, const Handle(TCollection_HAsciiString)& val)
98 if (theedit.IsNull()) return Standard_False;
99 if (num < 1 || num > theedit->Length()) return Standard_False;
102 if (!CheckValue(val,themodl,thedef)) return Standard_False;
105 theedit->SetValue (num,val);
106 thestat->SetValue (num,1);
108 return Standard_True;
112 Standard_Boolean IFSelect_ListEditor::AddValue
113 (const Handle(TCollection_HAsciiString)& val, const Standard_Integer atnum)
115 if (theedit.IsNull()) return Standard_False;
116 if (themax > 0 && theedit->Length() >= themax) return Standard_False;
117 if (!CheckValue (val,themodl,thedef)) return Standard_False;
119 theedit->InsertBefore (atnum,val);
120 thestat->InsertBefore (atnum,2);
122 theedit->Append (val);
126 return Standard_True;
130 Standard_Boolean IFSelect_ListEditor::Remove
131 (const Standard_Integer num, const Standard_Integer howmany)
133 if (theedit.IsNull()) return Standard_False;
134 Standard_Integer nb = theedit->Length();
135 if (num < 0) return Standard_False;
136 if (num == 0) return Remove (nb-howmany,howmany);
138 if ((num+howmany) > nb) return Standard_False;
139 theedit->Remove(num,howmany);
140 thestat->Remove(num,howmany);
142 return Standard_True;
146 // ######## QUERIES ########
148 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_ListEditor::OriginalValues () const
151 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_ListEditor::EditedValues () const
155 Standard_Integer IFSelect_ListEditor::NbValues (const Standard_Boolean edited) const
157 if (edited) return (theedit.IsNull() ? 0 : theedit->Length());
158 return (theorig.IsNull() ? 0 : theorig->Length());
162 Handle(TCollection_HAsciiString) IFSelect_ListEditor::Value
163 (const Standard_Integer num, const Standard_Boolean edited) const
165 Handle(TCollection_HAsciiString) val;
167 if (theedit.IsNull()) return val;
168 if (num < 1 || num > theedit->Length()) return val;
169 val = theedit->Value(num);
171 if (theorig.IsNull()) return val;
172 if (num < 1 || num > theorig->Length()) return val;
173 val = theorig->Value(num);
178 Standard_Boolean IFSelect_ListEditor::IsChanged (const Standard_Integer num) const
180 if (thestat.IsNull()) return Standard_False;
181 if (num < 1 || num > thestat->Length()) return Standard_False;
182 Standard_Integer stat = thestat->Value(num);
186 Standard_Boolean IFSelect_ListEditor::IsModified (const Standard_Integer num) const
188 if (thestat.IsNull()) return Standard_False;
189 if (num < 1 || num > thestat->Length()) return Standard_False;
190 Standard_Integer stat = thestat->Value(num);
194 Standard_Boolean IFSelect_ListEditor::IsAdded (const Standard_Integer num) const
196 if (thestat.IsNull()) return Standard_False;
197 if (num < 1 || num > thestat->Length()) return Standard_False;
198 Standard_Integer stat = thestat->Value(num);
202 Standard_Boolean IFSelect_ListEditor::IsTouched () const
203 { return (thetouc != 0); }