0022735: Data races in BRepMesh working in parallel mode
[occt.git] / src / IFSelect / IFSelect_EditForm.cxx
CommitLineData
7fd59977 1#include <IFSelect_EditForm.ixx>
2#include <Interface_TypedValue.hxx>
3#include <Interface_MSG.hxx>
4#include <Message_Messenger.hxx>
5#include <Message.hxx>
6
7 IFSelect_EditForm::IFSelect_EditForm
8 (const Handle(IFSelect_Editor)& editor,
9 const Standard_Boolean readonly, const Standard_Boolean undoable,
10 const Standard_CString label)
11 : thecomplete (Standard_True) ,
12 theloaded (Standard_False) ,
13 thekeepst (Standard_False) ,
14 thelabel (label) ,
15 thenums (0,1) ,
16 theorigs (0, (undoable ? editor->NbValues() : 0) ) ,
17 themodifs (0, (readonly ? 0 : editor->NbValues()) ) ,
18 thestatus (0, (readonly ? 0 : editor->NbValues()) ) ,
19 theeditor (editor) ,
20 thetouched (0) { }
21
22 IFSelect_EditForm::IFSelect_EditForm
23 (const Handle(IFSelect_Editor)& editor,
24 const TColStd_SequenceOfInteger& nums,
25 const Standard_Boolean readonly, const Standard_Boolean undoable,
26 const Standard_CString label)
27 : thecomplete (Standard_False) ,
28 theloaded (Standard_False) ,
29 thekeepst (Standard_False) ,
30 thelabel (label) ,
31 thenums (0,nums.Length()) ,
32 theorigs (0, (undoable ? nums.Length() : 0) ) ,
33 themodifs (0, (readonly ? 0 : nums.Length()) ) ,
34 thestatus (0, (readonly ? 0 : nums.Length()) ) ,
35 theeditor (editor) ,
36 thetouched (0)
37{
38 Standard_Integer i,nb = nums.Length();
39 for (i = 1; i <= nb; i ++) thenums.SetValue (i,nums.Value(i));
40}
41
42 Standard_Boolean& IFSelect_EditForm::EditKeepStatus ()
43 { return thekeepst; }
44
45 Standard_CString IFSelect_EditForm::Label () const
46 { return thelabel.ToCString(); }
47
48 Standard_Boolean IFSelect_EditForm::IsLoaded () const
49 { return theloaded; }
50
51 void IFSelect_EditForm::ClearData ()
52 { theent.Nullify(); themodel.Nullify(); theloaded = Standard_False; }
53
54 void IFSelect_EditForm::SetData
55 (const Handle(Standard_Transient)& ent,
56 const Handle(Interface_InterfaceModel)& model)
57 { theent = ent; themodel = model; }
58
59 void IFSelect_EditForm::SetEntity
60 (const Handle(Standard_Transient)& ent)
61 { theent = ent; }
62
63 void IFSelect_EditForm::SetModel
64 (const Handle(Interface_InterfaceModel)& model)
65 { themodel = model; }
66
67 Handle(Standard_Transient) IFSelect_EditForm::Entity () const
68 { return theent; }
69
70 Handle(Interface_InterfaceModel) IFSelect_EditForm::Model () const
71 { return themodel; }
72
73 Handle(IFSelect_Editor) IFSelect_EditForm::Editor () const
74 { return theeditor; }
75
76 Standard_Boolean IFSelect_EditForm::IsComplete () const
77 { return thecomplete; }
78
79 Standard_Integer IFSelect_EditForm::NbValues
80 (const Standard_Boolean editable) const
81{
82 if (!editable || thecomplete) return theeditor->NbValues();
83 return thenums.Upper();
84}
85
86 Standard_Integer IFSelect_EditForm::NumberFromRank
87 (const Standard_Integer rank) const
88{
89 if (thecomplete) return rank;
90 if (rank < 1 || rank > thenums.Upper()) return 0;
91 return thenums.Value(rank);
92}
93
94 Standard_Integer IFSelect_EditForm::RankFromNumber
95 (const Standard_Integer num) const
96{
97 if (thecomplete) return num;
98 Standard_Integer i, n = thenums.Upper();
99 for (i = 1; i <= n; i ++) {
100 if (thenums.Value(i) == num) return i;
101 }
102 return 0;
103}
104
105 Standard_Integer IFSelect_EditForm::NameNumber
106 (const Standard_CString name) const
107{
108 Standard_Integer res = theeditor->NameNumber(name);
109 if (thecomplete || res == 0) return res;
110// Sinon, chercher res dans thenums
111 Standard_Integer i, nb = thenums.Length();
112 for (i = 1; i <= nb; i ++) {
113 if (res == thenums.Value(i)) return res;
114 }
115 return -res;
116}
117
118 Standard_Integer IFSelect_EditForm::NameRank
119 (const Standard_CString name) const
120{
121 Standard_Integer res = theeditor->NameNumber(name);
122 if (thecomplete || res == 0) return res;
123// Sinon, chercher res dans thenums
124 Standard_Integer i, nb = thenums.Length();
125 for (i = 1; i <= nb; i ++) {
126 if (res == thenums.Value(i)) return i;
127 }
128 return 0;
129}
130
131
132 void IFSelect_EditForm::LoadDefault ()
133{
134 theloaded = Standard_True;
135 thetouched = 0;
136 Standard_Integer i,nb = theorigs.Upper();
137 if (nb == 0) return;
138 for (i = 1; i <= nb; i ++) {
139 Standard_Integer num = NumberFromRank(i);
140 if (num == 0) continue;
141 Handle(TCollection_HAsciiString) str = theeditor->StringValue (this,num);
142 theorigs.SetValue (i,str);
143 }
144}
145
146
147 Standard_Boolean IFSelect_EditForm::LoadData
148 (const Handle(Standard_Transient)& ent,
149 const Handle(Interface_InterfaceModel)& model)
150{
151 thetouched = 0;
152 if (!theeditor->Load (this,ent,model)) return Standard_False;
153 SetData (ent,model);
154 theloaded = Standard_True;
155 return Standard_True;
156}
157
158 Standard_Boolean IFSelect_EditForm::LoadEntity
159 (const Handle(Standard_Transient)& ent)
160{
161 thetouched = 0;
162 Handle(Interface_InterfaceModel) model;
163 if (!theeditor->Load (this,ent,model)) return Standard_False;
164 SetEntity (ent);
165 theloaded = Standard_True;
166 return Standard_True;
167}
168
169 Standard_Boolean IFSelect_EditForm::LoadModel
170 (const Handle(Interface_InterfaceModel)& model)
171{
172 thetouched = 0;
173 Handle(Standard_Transient) ent;
174 if (!theeditor->Load (this,ent,model)) return Standard_False;
175 SetData (ent,model);
176 theloaded = Standard_True;
177 return Standard_True;
178}
179
180 Standard_Boolean IFSelect_EditForm::LoadData ()
181{
182 thetouched = 0;
183 Handle(Interface_InterfaceModel) model;
184 Handle(Standard_Transient) ent;
185 if (!theeditor->Load (this,ent,model)) return Standard_False;
186 theloaded = Standard_True;
187 return Standard_True;
188}
189
190
191// ######## VALUES ########
192
193 Handle(IFSelect_ListEditor) IFSelect_EditForm::ListEditor
194 (const Standard_Integer num) const
195{
196 Standard_Integer n = RankFromNumber(num);
197 Handle(IFSelect_ListEditor) led;
198 if (n <= 0 || n > theorigs.Upper()) return led;
199 if (!theeditor->IsList(n)) return led;
200 led = theeditor->ListEditor (num);
201 Handle(TColStd_HSequenceOfHAsciiString) lis = theeditor->ListValue(this,num);
202 led->LoadModel (themodel);
203 led->LoadValues (lis);
204 return led;
205}
206
207 void IFSelect_EditForm::LoadValue
208 (const Standard_Integer num, const Handle(TCollection_HAsciiString)& val)
209{
210 Standard_Integer n = RankFromNumber(num);
211 if (n <= 0 || n > theorigs.Upper()) return;
212 theorigs.SetValue (n,val);
213}
214
215 void IFSelect_EditForm::LoadList
216 (const Standard_Integer num, const Handle(TColStd_HSequenceOfHAsciiString)& list)
217{
218 Standard_Integer n = RankFromNumber(num);
219 if (n <= 0 || n > theorigs.Upper()) return;
220 theorigs.SetValue (n,list);
221}
222
223
224 Handle(TCollection_HAsciiString) IFSelect_EditForm::OriginalValue
225 (const Standard_Integer num) const
226{
227 Standard_Integer n = RankFromNumber(num);
228 Handle(TCollection_HAsciiString) val;
229 if (theorigs.Upper() == 0) return theeditor->StringValue (this,num);
230 else return Handle(TCollection_HAsciiString)::DownCast(theorigs.Value(n));
231}
232
233 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_EditForm::OriginalList
234 (const Standard_Integer num) const
235{
236 Standard_Integer n = RankFromNumber(num);
237 Handle(TColStd_HSequenceOfHAsciiString) list;
238 if (theorigs.Upper() == 0) return theeditor->ListValue (this,num);
239 else return Handle(TColStd_HSequenceOfHAsciiString)::DownCast(theorigs.Value(n));
240}
241
242 Handle(TCollection_HAsciiString) IFSelect_EditForm::EditedValue
243 (const Standard_Integer num) const
244{
245 if (themodifs.Upper() == 0) return OriginalValue(num);
246 if (!IsModified(num)) return OriginalValue(num);
247 Standard_Integer n = RankFromNumber(num);
248 return Handle(TCollection_HAsciiString)::DownCast(themodifs.Value(n));
249}
250
251 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_EditForm::EditedList
252 (const Standard_Integer num) const
253{
254 if (themodifs.Upper() == 0) return OriginalList(num);
255 if (!IsModified(num)) return OriginalList(num);
256 Standard_Integer n = RankFromNumber(num);
257 return Handle(TColStd_HSequenceOfHAsciiString)::DownCast(themodifs.Value(n));
258}
259
260
261 Standard_Boolean IFSelect_EditForm::IsModified
262 (const Standard_Integer num) const
263{
264 if (thestatus.Upper() == 0) return Standard_False;
265 Standard_Integer n = RankFromNumber(num);
266 return (thestatus.Value(n) != 0);
267}
268
269 Standard_Boolean IFSelect_EditForm::IsTouched
270 (const Standard_Integer num) const
271{
272 if (thestatus.Upper() == 0) return Standard_False;
273 Standard_Integer n = RankFromNumber(num);
274 return (thestatus.Value(n) == 2);
275}
276
277 Standard_Boolean IFSelect_EditForm::Modify
278 (const Standard_Integer num, const Handle(TCollection_HAsciiString)& newval,
279 const Standard_Boolean enforce)
280{
281// Peut-on editer
282 thetouched = 0;
283 if (themodifs.Upper() == 0) return Standard_False;
284 Standard_Integer tnum = RankFromNumber(num);
285 if (tnum == 0) return Standard_False;
286 IFSelect_EditValue acc = theeditor->EditMode (num);
287 if (newval.IsNull() && acc != IFSelect_Optional) return Standard_False;
288 if (!enforce && (acc == IFSelect_EditProtected || acc == IFSelect_EditComputed)) return Standard_False;
289
290// Satisfies ?
291 Handle(Interface_TypedValue) typval = theeditor->TypedValue(num);
292 if (!typval->Satisfies(newval)) return Standard_False;
293 Interface_ParamType pty = typval->Type();
294 if (pty == Interface_ParamIdent && !newval.IsNull()) {
295 if (themodel.IsNull()) return Standard_False;
296 if (themodel->NextNumberForLabel(newval->ToCString(),0,Standard_False) <= 0)
297 return Standard_False;
298 }
299
300// Update ?
301 if (!theeditor->Update(this,num,newval,enforce)) return Standard_False;
302
303 thestatus.SetValue (tnum,1);
304 themodifs.SetValue (tnum,newval);
305 return Standard_True;
306}
307
308 Standard_Boolean IFSelect_EditForm::ModifyList
309 (const Standard_Integer num, const Handle(IFSelect_ListEditor)& edited,
310 const Standard_Boolean enforce)
311{
312// Faut-il prendre
313 if (edited.IsNull()) return Standard_False;
314 if (!edited->IsTouched()) return Standard_False;
315 Handle(TColStd_HSequenceOfHAsciiString) newlist = edited->EditedValues();
316
317// Peut-on editer
318 thetouched = 0;
319 if (themodifs.Upper() == 0) return Standard_False;
320 Standard_Integer tnum = RankFromNumber(num);
321 if (tnum == 0) return Standard_False;
322 IFSelect_EditValue acc = theeditor->EditMode (num);
323 if (acc == IFSelect_EditRead || acc == IFSelect_EditDynamic) return Standard_False;
324 if (newlist.IsNull() && acc != IFSelect_Optional) return Standard_False;
325 if (!enforce && (acc == IFSelect_EditProtected || acc == IFSelect_EditComputed)) return Standard_False;
326
327// Update ?
328 if (!theeditor->UpdateList(this,num,newlist,enforce)) return Standard_False;
329
330 thestatus.SetValue (tnum,1);
331 themodifs.SetValue (tnum,newlist);
332 return Standard_True;
333}
334
335 Standard_Boolean IFSelect_EditForm::ModifyListValue
336 (const Standard_Integer num, const Handle(TColStd_HSequenceOfHAsciiString)& list,
337 const Standard_Boolean enforce)
338{
339 Handle(IFSelect_ListEditor) led = ListEditor (num);
340 if (led.IsNull()) return Standard_False;
341 if (!led->LoadEdited(list)) return Standard_False;
342 return ModifyList (num,led,enforce);
343}
344
345
346 Standard_Boolean IFSelect_EditForm::Touch
347 (const Standard_Integer num, const Handle(TCollection_HAsciiString)& newval)
348{
349 if (themodifs.Upper() == 0) return Standard_False;
350 Standard_Integer tnum = RankFromNumber(num);
351 if (tnum == 0) return Standard_False;
352
353 thestatus.SetValue (tnum,2);
354 themodifs.SetValue (tnum,newval);
355 thetouched ++;
356 return Standard_True;
357}
358
359 Standard_Boolean IFSelect_EditForm::TouchList
360 (const Standard_Integer num, const Handle(TColStd_HSequenceOfHAsciiString)& newlist)
361{
362 if (themodifs.Upper() == 0) return Standard_False;
363 Standard_Integer tnum = RankFromNumber(num);
364 if (tnum == 0) return Standard_False;
365
366 thestatus.SetValue (tnum,2);
367 themodifs.SetValue (tnum,newlist);
368 thetouched ++;
369 return Standard_True;
370}
371
372
373 void IFSelect_EditForm::ClearEdit (const Standard_Integer num)
374{
375 Standard_Integer i, nb = thestatus.Upper();
376 if (num == 0) {
377 for (i = 1; i <= nb; i ++) thestatus.SetValue (i,0);
378 } else {
379 Standard_Integer tnum = RankFromNumber(num);
380 if (tnum > 0 && num <= nb) thestatus.SetValue (tnum,0);
381 }
382}
383
384
385 void IFSelect_EditForm::PrintDefs (const Handle(Message_Messenger)& S) const
386{
387 Standard_Integer iv, nbv = NbValues(Standard_True);
388 S<<"***** EditForm, Label : "<<Label()<<endl;
389 if (IsComplete()) S<<"Complete, "<<nbv<<" Values"<<endl;
390 else {
391 S<<"Extraction on "<<nbv<<" Values : (extracted<-editor)"<<endl;
392 for (iv = 1; iv <= nbv; iv ++) S<<" "<<iv<<"<-"<<NumberFromRank(iv);
393 S<<endl;
394 }
395 S<<"*****"<<endl;
396}
397
398
399static void PrintList
400 (const Handle(TColStd_HSequenceOfHAsciiString)& list,
401 const Handle(Message_Messenger)& S, const Standard_Boolean alsolist)
402{
403 if (list.IsNull()) { S<<"(NULL LIST)"<<endl; return; }
404
405 Standard_Integer i,nb = list->Length();
406 S<<"(List : "<<nb<<" Items)"<<endl;
407 if (!alsolist) return;
408
409 for (i = 1; i <= nb; i ++) {
410 Handle(TCollection_HAsciiString) str = list->Value(i);
411 S<<" ["<<i<<"] "<< (str.IsNull() ? "(NULL)" : str->ToCString())<<endl;
412 }
413}
414
415 void IFSelect_EditForm::PrintValues
416 (const Handle(Message_Messenger)& S, const Standard_Integer what,
417 const Standard_Boolean names, const Standard_Boolean alsolist) const
418{
419 Standard_Integer iv, nbv = NbValues(Standard_True);
420 S<< "****************************************************"<<endl;
421 S<<"***** "<<Label()<<Interface_MSG::Blanks(Label(),40)<<"*****"<<endl;
422 S<<"***** *****"<<endl;
423 if (!theloaded)
424 S<<"***** Values are NOT loaded *****"<<endl;
425
426 else {
427// Donnees sur lesquelles on a travaille
428 if (themodel.IsNull()) {
429 if (theent.IsNull()) S<<"***** No loaded data";
430 else S<<"***** No loaded Model. Loaded object : type "<<theent->DynamicType()->Name();
431 } else {
432 if (theent.IsNull()) S<<"***** No loaded entity";
433 else { S<<"***** Loaded entity : "; themodel->PrintLabel (theent,S); }
434 }
435 }
436 S<<endl<<"****************************************************"<<endl<<endl;
437
438// Affichage des valeurs
439 Standard_Boolean nams = names;
440 Standard_Integer maxnam = theeditor->MaxNameLength (names ? 0 : -1);
441 if (maxnam == 0) { maxnam = theeditor->MaxNameLength (0); nams = Standard_True; }
442 Standard_Integer nbmod = 0;
443 if (what != 0) S<<"Mod N0 Name Value"<<endl;
444 else S<<" N0 Name Value"<<endl;
445
446 for (iv = 1; iv <= nbv; iv ++) {
447 Standard_Integer jv = NumberFromRank(iv);
448 Standard_CString name = theeditor->Name(jv,!nams);
449
450// Original ou Final
451 if (what != 0) {
452 Handle(TCollection_HAsciiString) str;
453 if (IsModified(jv)) S<<"* ";
454 else S<<" ";
455 S <<Interface_MSG::Blanks(iv,3)<<iv<<" "
456 <<name<<Interface_MSG::Blanks(name,maxnam)<<" ";
457
458 if (theeditor->IsList(jv)) {
459 Handle(TColStd_HSequenceOfHAsciiString) list;
460 if (what < 0) list = OriginalList (jv);
461 if (what > 0) list = EditedList (jv);
462 PrintList (list,S,alsolist);
463 continue;
464 }
465
466 if (what < 0) str = OriginalValue (jv);
467 if (what > 0) str = EditedValue (jv);
468
469 S << (str.IsNull() ? "(NULL)" : str->ToCString()) <<endl;
470
471// Modified only
472 } else {
473 if (!IsModified(jv)) continue;
474 nbmod ++;
475 if (theeditor->IsList(jv)) {
476 Handle(TColStd_HSequenceOfHAsciiString) list= OriginalList (jv);
477 S <<Interface_MSG::Blanks(iv,3)<<iv<<" "
478 <<name<<Interface_MSG::Blanks(name,maxnam)<<" ORIG:";
479 PrintList (list,S,alsolist);
480
481 list = EditedList (jv);
482 S<<Interface_MSG::Blanks("",maxnam+5)<<"MOD :";
483 PrintList (list,S,alsolist);
484
485 continue;
486 }
487
488 Handle(TCollection_HAsciiString) str = OriginalValue (jv);
489 S <<Interface_MSG::Blanks(iv,3)<<iv<<" "
490 <<name<<Interface_MSG::Blanks(name,maxnam)<<" ORIG:"
491 << (str.IsNull() ? "(NULL)" : str->ToCString()) <<endl;
492 str = EditedValue (jv);
493 S<<Interface_MSG::Blanks("",maxnam+4)<<" MOD :"<< (str.IsNull() ? "(NULL)" : str->ToCString()) <<endl;
494 }
495 }
496 if (what == 0) S<<"On "<<nbv<<" Values, "<<nbmod<<" Modified"<<endl;
497}
498
499
500 Standard_Boolean IFSelect_EditForm::Apply ()
501{
502 Standard_Boolean stat = ApplyData(theent,themodel);
503 if (stat && !thekeepst) ClearEdit();
504 return stat;
505}
506
507
508 Standard_Boolean IFSelect_EditForm::Recognize () const
509 { return theeditor->Recognize(this); }
510
511 Standard_Boolean IFSelect_EditForm::ApplyData
512 (const Handle(Standard_Transient)& ent,
513 const Handle(Interface_InterfaceModel)& model)
514 { return theeditor->Apply (this,ent,model); }
515
516
517 Standard_Boolean IFSelect_EditForm::Undo ()
518{
519 if (thestatus.Upper() == 0 || theorigs.Upper() == 0) return Standard_False;
520 Standard_Integer i, nb = thestatus.Upper();
521 for (i = 1; i <= nb; i ++) {
522 if (thestatus.Value (i) != 0) themodifs.SetValue (i,theorigs.Value(i));
523 }
524 return Apply ();
525}