1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <IFSelect_ListEditor.ixx>
20 IFSelect_ListEditor::IFSelect_ListEditor ()
21 : themax (0) , thetouc (0) { }
23 IFSelect_ListEditor::IFSelect_ListEditor
24 (const Handle(Interface_TypedValue)& def, const Standard_Integer max)
25 : themax (max) , thedef (def) , thetouc (0) { }
28 void IFSelect_ListEditor::LoadModel (const Handle(Interface_InterfaceModel)& model)
31 void IFSelect_ListEditor::LoadValues (const Handle(TColStd_HSequenceOfHAsciiString)& vals)
38 void IFSelect_ListEditor::SetTouched ()
41 void IFSelect_ListEditor::ClearEdit ()
43 theedit = new TColStd_HSequenceOfHAsciiString();
44 thestat = new TColStd_HSequenceOfInteger();
45 if (theorig.IsNull()) return;
46 Standard_Integer i,nb = theorig->Length();
47 for (i = 1; i <= nb; i ++) {
48 theedit->Append (theorig->Value(i));
54 // ######## CHECK ########
56 static Standard_Boolean CheckValue
57 (const Handle(TCollection_HAsciiString)& val,
58 const Handle(Interface_InterfaceModel)& modl,
59 const Handle(Interface_TypedValue)& thedef)
61 if (val.IsNull() || modl.IsNull() || thedef.IsNull()) return Standard_True;
63 Interface_ParamType pty = thedef->Type();
64 if (!thedef->Satisfies(val)) return Standard_False;
65 if (pty == Interface_ParamIdent && !val.IsNull()) {
66 if (modl->NextNumberForLabel(val->ToCString(),0) <= 0)
67 return Standard_False;
72 // ######## EDITION ########
74 Standard_Boolean IFSelect_ListEditor::LoadEdited
75 (const Handle(TColStd_HSequenceOfHAsciiString)& list)
77 if (list.IsNull()) return Standard_False;
78 Standard_Integer i, nb = list->Length();
79 if (nb > themax) return Standard_False;
80 Interface_ParamType pty = Interface_ParamText;
83 if (!thedef.IsNull()) {
85 for (i = 1; i <= nb; i ++) {
86 Handle(TCollection_HAsciiString) newval = list->Value(i);
87 if (!CheckValue (newval,themodl,thedef)) return Standard_False;
93 thestat = new TColStd_HSequenceOfInteger();
94 for (i = 1; i <= nb; i ++) thestat->Append (1);
101 Standard_Boolean IFSelect_ListEditor::SetValue
102 (const Standard_Integer num, const Handle(TCollection_HAsciiString)& val)
104 if (theedit.IsNull()) return Standard_False;
105 if (num < 1 || num > theedit->Length()) return Standard_False;
108 if (!CheckValue(val,themodl,thedef)) return Standard_False;
111 theedit->SetValue (num,val);
112 thestat->SetValue (num,1);
114 return Standard_True;
118 Standard_Boolean IFSelect_ListEditor::AddValue
119 (const Handle(TCollection_HAsciiString)& val, const Standard_Integer atnum)
121 if (theedit.IsNull()) return Standard_False;
122 if (themax > 0 && theedit->Length() >= themax) return Standard_False;
123 if (!CheckValue (val,themodl,thedef)) return Standard_False;
125 theedit->InsertBefore (atnum,val);
126 thestat->InsertBefore (atnum,2);
128 theedit->Append (val);
132 return Standard_True;
136 Standard_Boolean IFSelect_ListEditor::Remove
137 (const Standard_Integer num, const Standard_Integer howmany)
139 if (theedit.IsNull()) return Standard_False;
140 Standard_Integer nb = theedit->Length();
141 if (num < 0) return Standard_False;
142 if (num == 0) return Remove (nb-howmany,howmany);
144 if ((num+howmany) > nb) return Standard_False;
145 theedit->Remove(num,howmany);
146 thestat->Remove(num,howmany);
148 return Standard_True;
152 // ######## QUERIES ########
154 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_ListEditor::OriginalValues () const
157 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_ListEditor::EditedValues () const
161 Standard_Integer IFSelect_ListEditor::NbValues (const Standard_Boolean edited) const
163 if (edited) return (theedit.IsNull() ? 0 : theedit->Length());
164 return (theorig.IsNull() ? 0 : theorig->Length());
168 Handle(TCollection_HAsciiString) IFSelect_ListEditor::Value
169 (const Standard_Integer num, const Standard_Boolean edited) const
171 Handle(TCollection_HAsciiString) val;
173 if (theedit.IsNull()) return val;
174 if (num < 1 || num > theedit->Length()) return val;
175 val = theedit->Value(num);
177 if (theorig.IsNull()) return val;
178 if (num < 1 || num > theorig->Length()) return val;
179 val = theorig->Value(num);
184 Standard_Boolean IFSelect_ListEditor::IsChanged (const Standard_Integer num) const
186 if (thestat.IsNull()) return Standard_False;
187 if (num < 1 || num > thestat->Length()) return Standard_False;
188 Standard_Integer stat = thestat->Value(num);
192 Standard_Boolean IFSelect_ListEditor::IsModified (const Standard_Integer num) const
194 if (thestat.IsNull()) return Standard_False;
195 if (num < 1 || num > thestat->Length()) return Standard_False;
196 Standard_Integer stat = thestat->Value(num);
200 Standard_Boolean IFSelect_ListEditor::IsAdded (const Standard_Integer num) const
202 if (thestat.IsNull()) return Standard_False;
203 if (num < 1 || num > thestat->Length()) return Standard_False;
204 Standard_Integer stat = thestat->Value(num);
208 Standard_Boolean IFSelect_ListEditor::IsTouched () const
209 { return (thetouc != 0); }