0024157: Parallelization of assembly part of BO
[occt.git] / src / IFSelect / IFSelect_ListEditor.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
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.
7//
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.
10//
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.
17
7fd59977 18#include <IFSelect_ListEditor.ixx>
19
20IFSelect_ListEditor::IFSelect_ListEditor ()
21: themax (0) , thetouc (0) { }
22
23 IFSelect_ListEditor::IFSelect_ListEditor
24 (const Handle(Interface_TypedValue)& def, const Standard_Integer max)
25: themax (max) , thedef (def) , thetouc (0) { }
26
27
28void IFSelect_ListEditor::LoadModel (const Handle(Interface_InterfaceModel)& model)
29{ themodl = model; }
30
31void IFSelect_ListEditor::LoadValues (const Handle(TColStd_HSequenceOfHAsciiString)& vals)
32{
33 theorig = vals;
34 ClearEdit();
35}
36
37
38void IFSelect_ListEditor::SetTouched ()
39{ thetouc = 1; }
40
41void IFSelect_ListEditor::ClearEdit ()
42{
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));
49 thestat->Append (0);
50 }
51 thetouc = 0;
52}
53
54// ######## CHECK ########
55
56static Standard_Boolean CheckValue
57 (const Handle(TCollection_HAsciiString)& val,
58 const Handle(Interface_InterfaceModel)& modl,
59 const Handle(Interface_TypedValue)& thedef)
60{
61 if (val.IsNull() || modl.IsNull() || thedef.IsNull()) return Standard_True;
62
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;
68 }
69 return Standard_True;
70}
71
72// ######## EDITION ########
73
74Standard_Boolean IFSelect_ListEditor::LoadEdited
75 (const Handle(TColStd_HSequenceOfHAsciiString)& list)
76{
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;
81
82// check values
83 if (!thedef.IsNull()) {
84 pty = thedef->Type();
85 for (i = 1; i <= nb; i ++) {
86 Handle(TCollection_HAsciiString) newval = list->Value(i);
87 if (!CheckValue (newval,themodl,thedef)) return Standard_False;
88 }
89 }
90
91// OK
92 theedit = list;
93 thestat = new TColStd_HSequenceOfInteger();
94 for (i = 1; i <= nb; i ++) thestat->Append (1);
95 thetouc = 1;
96
97 return Standard_True;
98}
99
100
101Standard_Boolean IFSelect_ListEditor::SetValue
102 (const Standard_Integer num, const Handle(TCollection_HAsciiString)& val)
103{
104 if (theedit.IsNull()) return Standard_False;
105 if (num < 1 || num > theedit->Length()) return Standard_False;
106
107// check value
108 if (!CheckValue(val,themodl,thedef)) return Standard_False;
109
110// OK
111 theedit->SetValue (num,val);
112 thestat->SetValue (num,1);
113 thetouc = 1;
114 return Standard_True;
115}
116
117
118Standard_Boolean IFSelect_ListEditor::AddValue
119 (const Handle(TCollection_HAsciiString)& val, const Standard_Integer atnum)
120{
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;
124 if (atnum > 0) {
125 theedit->InsertBefore (atnum,val);
126 thestat->InsertBefore (atnum,2);
127 } else {
128 theedit->Append (val);
129 thestat->Append (2);
130 }
131 thetouc = 2;
132 return Standard_True;
133}
134
135
136Standard_Boolean IFSelect_ListEditor::Remove
137 (const Standard_Integer num, const Standard_Integer howmany)
138{
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);
143
144 if ((num+howmany) > nb) return Standard_False;
145 theedit->Remove(num,howmany);
146 thestat->Remove(num,howmany);
147 thetouc = 3;
148 return Standard_True;
149}
150
151
152// ######## QUERIES ########
153
154Handle(TColStd_HSequenceOfHAsciiString) IFSelect_ListEditor::OriginalValues () const
155{ return theorig; }
156
157Handle(TColStd_HSequenceOfHAsciiString) IFSelect_ListEditor::EditedValues () const
158{ return theedit; }
159
160
161Standard_Integer IFSelect_ListEditor::NbValues (const Standard_Boolean edited) const
162{
163 if (edited) return (theedit.IsNull() ? 0 : theedit->Length());
164 return (theorig.IsNull() ? 0 : theorig->Length());
165}
166
167
168Handle(TCollection_HAsciiString) IFSelect_ListEditor::Value
169 (const Standard_Integer num, const Standard_Boolean edited) const
170{
171 Handle(TCollection_HAsciiString) val;
172 if (edited) {
173 if (theedit.IsNull()) return val;
174 if (num < 1 || num > theedit->Length()) return val;
175 val = theedit->Value(num);
176 } else {
177 if (theorig.IsNull()) return val;
178 if (num < 1 || num > theorig->Length()) return val;
179 val = theorig->Value(num);
180 }
181 return val;
182}
183
184Standard_Boolean IFSelect_ListEditor::IsChanged (const Standard_Integer num) const
185{
186 if (thestat.IsNull()) return Standard_False;
187 if (num < 1 || num > thestat->Length()) return Standard_False;
188 Standard_Integer stat = thestat->Value(num);
189 return (stat != 0);
190}
191
192Standard_Boolean IFSelect_ListEditor::IsModified (const Standard_Integer num) const
193{
194 if (thestat.IsNull()) return Standard_False;
195 if (num < 1 || num > thestat->Length()) return Standard_False;
196 Standard_Integer stat = thestat->Value(num);
197 return (stat == 1);
198}
199
200Standard_Boolean IFSelect_ListEditor::IsAdded (const Standard_Integer num) const
201{
202 if (thestat.IsNull()) return Standard_False;
203 if (num < 1 || num > thestat->Length()) return Standard_False;
204 Standard_Integer stat = thestat->Value(num);
205 return (stat == 2);
206}
207
208Standard_Boolean IFSelect_ListEditor::IsTouched () const
209 { return (thetouc != 0); }