1 #include <IFSelect_ListEditor.ixx>
3 IFSelect_ListEditor::IFSelect_ListEditor ()
4 : themax (0) , thetouc (0) { }
6 IFSelect_ListEditor::IFSelect_ListEditor
7 (const Handle(Interface_TypedValue)& def, const Standard_Integer max)
8 : themax (max) , thedef (def) , thetouc (0) { }
11 void IFSelect_ListEditor::LoadModel (const Handle(Interface_InterfaceModel)& model)
14 void IFSelect_ListEditor::LoadValues (const Handle(TColStd_HSequenceOfHAsciiString)& vals)
21 void IFSelect_ListEditor::SetTouched ()
24 void IFSelect_ListEditor::ClearEdit ()
26 theedit = new TColStd_HSequenceOfHAsciiString();
27 thestat = new TColStd_HSequenceOfInteger();
28 if (theorig.IsNull()) return;
29 Standard_Integer i,nb = theorig->Length();
30 for (i = 1; i <= nb; i ++) {
31 theedit->Append (theorig->Value(i));
37 // ######## CHECK ########
39 static Standard_Boolean CheckValue
40 (const Handle(TCollection_HAsciiString)& val,
41 const Handle(Interface_InterfaceModel)& modl,
42 const Handle(Interface_TypedValue)& thedef)
44 if (val.IsNull() || modl.IsNull() || thedef.IsNull()) return Standard_True;
46 Interface_ParamType pty = thedef->Type();
47 if (!thedef->Satisfies(val)) return Standard_False;
48 if (pty == Interface_ParamIdent && !val.IsNull()) {
49 if (modl->NextNumberForLabel(val->ToCString(),0) <= 0)
50 return Standard_False;
55 // ######## EDITION ########
57 Standard_Boolean IFSelect_ListEditor::LoadEdited
58 (const Handle(TColStd_HSequenceOfHAsciiString)& list)
60 if (list.IsNull()) return Standard_False;
61 Standard_Integer i, nb = list->Length();
62 if (nb > themax) return Standard_False;
63 Interface_ParamType pty = Interface_ParamText;
66 if (!thedef.IsNull()) {
68 for (i = 1; i <= nb; i ++) {
69 Handle(TCollection_HAsciiString) newval = list->Value(i);
70 if (!CheckValue (newval,themodl,thedef)) return Standard_False;
76 thestat = new TColStd_HSequenceOfInteger();
77 for (i = 1; i <= nb; i ++) thestat->Append (1);
84 Standard_Boolean IFSelect_ListEditor::SetValue
85 (const Standard_Integer num, const Handle(TCollection_HAsciiString)& val)
87 if (theedit.IsNull()) return Standard_False;
88 if (num < 1 || num > theedit->Length()) return Standard_False;
91 if (!CheckValue(val,themodl,thedef)) return Standard_False;
94 theedit->SetValue (num,val);
95 thestat->SetValue (num,1);
101 Standard_Boolean IFSelect_ListEditor::AddValue
102 (const Handle(TCollection_HAsciiString)& val, const Standard_Integer atnum)
104 if (theedit.IsNull()) return Standard_False;
105 if (themax > 0 && theedit->Length() >= themax) return Standard_False;
106 if (!CheckValue (val,themodl,thedef)) return Standard_False;
108 theedit->InsertBefore (atnum,val);
109 thestat->InsertBefore (atnum,2);
111 theedit->Append (val);
115 return Standard_True;
119 Standard_Boolean IFSelect_ListEditor::Remove
120 (const Standard_Integer num, const Standard_Integer howmany)
122 if (theedit.IsNull()) return Standard_False;
123 Standard_Integer nb = theedit->Length();
124 if (num < 0) return Standard_False;
125 if (num == 0) return Remove (nb-howmany,howmany);
127 if ((num+howmany) > nb) return Standard_False;
128 theedit->Remove(num,howmany);
129 thestat->Remove(num,howmany);
131 return Standard_True;
135 // ######## QUERIES ########
137 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_ListEditor::OriginalValues () const
140 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_ListEditor::EditedValues () const
144 Standard_Integer IFSelect_ListEditor::NbValues (const Standard_Boolean edited) const
146 if (edited) return (theedit.IsNull() ? 0 : theedit->Length());
147 return (theorig.IsNull() ? 0 : theorig->Length());
151 Handle(TCollection_HAsciiString) IFSelect_ListEditor::Value
152 (const Standard_Integer num, const Standard_Boolean edited) const
154 Handle(TCollection_HAsciiString) val;
156 if (theedit.IsNull()) return val;
157 if (num < 1 || num > theedit->Length()) return val;
158 val = theedit->Value(num);
160 if (theorig.IsNull()) return val;
161 if (num < 1 || num > theorig->Length()) return val;
162 val = theorig->Value(num);
167 Standard_Boolean IFSelect_ListEditor::IsChanged (const Standard_Integer num) const
169 if (thestat.IsNull()) return Standard_False;
170 if (num < 1 || num > thestat->Length()) return Standard_False;
171 Standard_Integer stat = thestat->Value(num);
175 Standard_Boolean IFSelect_ListEditor::IsModified (const Standard_Integer num) const
177 if (thestat.IsNull()) return Standard_False;
178 if (num < 1 || num > thestat->Length()) return Standard_False;
179 Standard_Integer stat = thestat->Value(num);
183 Standard_Boolean IFSelect_ListEditor::IsAdded (const Standard_Integer num) const
185 if (thestat.IsNull()) return Standard_False;
186 if (num < 1 || num > thestat->Length()) return Standard_False;
187 Standard_Integer stat = thestat->Value(num);
191 Standard_Boolean IFSelect_ListEditor::IsTouched () const
192 { return (thetouc != 0); }