0028417: Using PRECOMPILED HEADER to speed up compilation time
[occt.git] / src / DDataStd / DDataStd_BasicCommands.cxx
CommitLineData
b311480e 1// Created on: 1997-07-30
2// Created by: Denis PASCAL
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <DDataStd.hxx>
18
19#include <Standard_PCharacter.hxx>
20
21#include <DDF.hxx>
22#include <Draw_Interpretor.hxx>
23#include <Draw_Appli.hxx>
24#include <DrawTrSurf.hxx>
25
26#include <DDF.hxx>
27
28#include <TDF_Data.hxx>
29#include <TDF_Label.hxx>
30#include <TDF_Tool.hxx>
31#include <TDF_AttributeSequence.hxx>
32#include <TDF_AttributeList.hxx>
33#include <TDF_ListIteratorOfAttributeList.hxx>
34
624f732f 35#include <BRep_Tool.hxx>
7fd59977 36#include <DBRep.hxx>
37#include <TopAbs.hxx>
38#include <TopoDS.hxx>
39#include <TopoDS_Vertex.hxx>
40#include <TopoDS_Edge.hxx>
41#include <TopoDS_Wire.hxx>
42#include <TopoDS_Face.hxx>
43#include <TopoDS_Shell.hxx>
44#include <TopoDS_Solid.hxx>
45#include <TopoDS_Shape.hxx>
46
47#include <gp_Pnt.hxx>
48#include <gp_Dir.hxx>
49#include <gp_Pln.hxx>
50
51#include <TCollection_AsciiString.hxx>
52#include <TColStd_HArray1OfReal.hxx>
53
54// LES ATTRIBUTES
55#include <TDataStd.hxx>
624f732f 56#include <TDataXtd_Triangulation.hxx>
7fd59977 57#include <TDataStd_Comment.hxx>
58#include <TDataStd_Name.hxx>
59#include <TDataStd_Integer.hxx>
60#include <TDataStd_Real.hxx>
61#include <TDF_Reference.hxx>
62#include <TDataStd_UAttribute.hxx>
63#include <TDataStd_IntegerArray.hxx>
f7b4312f 64#include <TDataStd_BooleanArray.hxx>
7fd59977 65#include <TDataStd_RealArray.hxx>
f7b4312f 66#include <TDataStd_BooleanList.hxx>
67#include <TDataStd_IntegerList.hxx>
68#include <TDataStd_RealList.hxx>
7fd59977 69#include <TDataStd_Variable.hxx>
70#include <TDataStd_ExtStringArray.hxx>
71#include <TDF_ChildIterator.hxx>
72#include <TDF_Tool.hxx>
73
7fd59977 74#include <TDataStd_NamedData.hxx>
75#include <TColStd_DataMapOfStringInteger.hxx>
76#include <TColStd_DataMapIteratorOfDataMapOfStringInteger.hxx>
77#include <TDataStd_DataMapOfStringReal.hxx>
78#include <TDataStd_DataMapIteratorOfDataMapOfStringReal.hxx>
79#include <TDataStd_DataMapOfStringByte.hxx>
80#include <TDataStd_DataMapIteratorOfDataMapOfStringByte.hxx>
81#include <TDataStd_DataMapOfStringString.hxx>
82#include <TDataStd_DataMapIteratorOfDataMapOfStringString.hxx>
83#include <TDataStd_DataMapOfStringHArray1OfInteger.hxx>
84#include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger.hxx>
85#include <TDataStd_DataMapOfStringHArray1OfReal.hxx>
86#include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal.hxx>
87#include <TColStd_HArray1OfInteger.hxx>
88#include <TColStd_HArray1OfReal.hxx>
89#include <TDataStd_AsciiString.hxx>
90#include <TDataStd_IntPackedMap.hxx>
91#include <TColStd_HPackedMapOfInteger.hxx>
92#include <TColStd_PackedMapOfInteger.hxx>
93#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
94#include <TDataStd_ByteArray.hxx>
f7b4312f 95#include <TDataStd_ListIteratorOfListOfByte.hxx>
96#include <TColStd_ListIteratorOfListOfInteger.hxx>
97#include <TColStd_ListIteratorOfListOfReal.hxx>
1c9cffdb 98#include <TDataStd_ReferenceArray.hxx>
d585e74e 99#include <TDataStd_ExtStringList.hxx>
100#include <TDataStd_ReferenceList.hxx>
101#include <TDF_ListIteratorOfLabelList.hxx>
102#include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
5a1271c8 103#define MAXLENGTH 10
104//#define DEB_DDataStd
7fd59977 105
7fd59977 106//=======================================================================
107//function : DDataStd_SetInteger
fa53efef 108//purpose : SetInteger (DF, entry, value, [,guid])
7fd59977 109//=======================================================================
110
111static Standard_Integer DDataStd_SetInteger (Draw_Interpretor& di,
112 Standard_Integer nb,
113 const char** arg)
114{
fa53efef 115 if (nb >= 4) {
7fd59977 116 Handle(TDF_Data) DF;
117 if (!DDF::GetDF(arg[1],DF)) return 1;
118 TDF_Label L;
119 DDF::AddLabel(DF, arg[2], L);
5a1271c8 120 if(nb == 4)
fa53efef 121 TDataStd_Integer::Set(L,Draw::Atoi(arg[3]));
5a1271c8 122 else {
123 if (!Standard_GUID::CheckGUIDFormat(arg[4])) {
fa53efef 124 di<<"DDataStd_SetInteger: The format of GUID is invalid\n";
125 return 1;
5a1271c8 126 }
127 Standard_GUID guid(arg[4]);
128 TDataStd_Integer::Set(L, guid, Draw::Atoi(arg[3]));
129 }
7fd59977 130 return 0;
131 }
586db386 132 di << "DDataStd_SetInteger : Error\n";
7fd59977 133 return 1;
134}
135
136//=======================================================================
137//function : DDataStd_SetReal
fa53efef 138//purpose : SetReal (DF, entry, value [,guid])
7fd59977 139//=======================================================================
140
141static Standard_Integer DDataStd_SetReal (Draw_Interpretor& di,
142 Standard_Integer nb,
143 const char** arg)
144{
fa53efef 145 if (nb >= 4) {
7fd59977 146 Handle(TDF_Data) DF;
147 if (!DDF::GetDF(arg[1],DF)) return 1;
148 TDF_Label L;
149 DDF::AddLabel(DF, arg[2], L);
5a1271c8 150 if(nb == 4)
fa53efef 151 TDataStd_Real::Set(L,Draw::Atof(arg[3]));
5a1271c8 152 else {
153 if (!Standard_GUID::CheckGUIDFormat(arg[4])) {
fa53efef 154 di<<"DDataStd_SetReal: The format of GUID is invalid\n";
155 return 1;
5a1271c8 156 }
157 Standard_GUID guid(arg[4]);
158 TDataStd_Real::Set(L, guid, Draw::Atof(arg[3]));
159 }
160 return 0;
161 }
586db386 162 di << "DDataStd_SetReal : Error\n";
7fd59977 163 return 1;
164}
165
166
167
168//=======================================================================
169//function : DDataStd_SetReference
170//purpose : SetReference (DF, entry, reference)
171//=======================================================================
172
173static Standard_Integer DDataStd_SetReference (Draw_Interpretor& di,
174 Standard_Integer nb,
175 const char** arg)
176{
177 if (nb == 4) {
178 Handle(TDF_Data) DF;
179 if (!DDF::GetDF(arg[1],DF)) return 1;
180 TDF_Label L;
181 DDF::AddLabel(DF, arg[2], L);
182 TDF_Label LREF;
183 if (!DDF::FindLabel(DF,arg[3],LREF)) return 1;
184 TDF_Reference::Set(L,LREF);
185 return 0;
186 }
586db386 187 di << "DDataStd_SetReference : Error\n";
7fd59977 188 return 1;
189}
190
191
192//=======================================================================
193//function : DDataStd_SetComment
194//purpose : SetComment (DF, entry, Comment)
195//=======================================================================
196
197static Standard_Integer DDataStd_SetComment (Draw_Interpretor& di,
198 Standard_Integer nb,
199 const char** arg)
200{
201 if (nb == 4) {
202 Handle(TDF_Data) DF;
203 if (!DDF::GetDF(arg[1],DF)) return 1;
204 TDF_Label L;
205 DDF::AddLabel(DF, arg[2], L);
d9ff84e8 206 TDataStd_Comment::Set(L,TCollection_ExtendedString(arg[3],Standard_True));
7fd59977 207 return 0;
208 }
586db386 209 di << "DDataStd_SetComment : Error\n";
7fd59977 210 return 1;
211}
212
7fd59977 213//=======================================================================
214//function : DDataStd_GetInteger
fa53efef 215//purpose : GetReal (DF, entry, [drawname][, guid])
7fd59977 216//=======================================================================
217
218static Standard_Integer DDataStd_GetInteger (Draw_Interpretor& di,
219 Standard_Integer nb,
220 const char** arg)
221{
fa53efef 222 if (nb == 3 || nb == 4 || nb == 5) {
7fd59977 223 Handle(TDF_Data) DF;
224 if (!DDF::GetDF(arg[1],DF)) return 1;
225 Handle(TDataStd_Integer) A;
5a1271c8 226 Standard_GUID aGuid;
227 Standard_GUID aNullGuid("00000000-0000-0000-0000-000000000000");
228 Standard_Boolean isdrawname(Standard_False);
229 if(nb < 5 ) {
fa53efef 230 if(nb == 4) { //DF, entry, guid
5a1271c8 231 if (Standard_GUID::CheckGUIDFormat(arg[3]))
fa53efef 232 aGuid = Standard_GUID(arg[3]);
5a1271c8 233 }
234 if(Standard_GUID::IsEqual(aGuid, aNullGuid)) {
235 isdrawname = Standard_True;
236 aGuid = TDataStd_Integer::GetID();
237 }
238 } else if(nb == 5) {
239 isdrawname = Standard_True;
240 if (Standard_GUID::CheckGUIDFormat(arg[4]))
fa53efef 241 aGuid = Standard_GUID(arg[4]);
5a1271c8 242 else {
fa53efef 243 di<<"DDataStd_GetInteger: The format of GUID is invalid\n";
244 return 1;
5a1271c8 245 }
246 }
247
fa53efef 248 if (!DDF::Find(DF,arg[2],aGuid,A)) return 1;
249 if (nb == 4 && isdrawname) Draw::Set(arg[3],A->Get());
7fd59977 250 else Draw::Set(arg[2],A->Get());
251 di << A->Get();
252 return 0;
253 }
586db386 254 di << "DDataStd_GetInteger : Error\n";
7fd59977 255 return 1;
256}
257
258//=======================================================================
259//function : DDataStd_GetReal
fa53efef 260//purpose : GetReal (DF, entry, [drawname][, guid])
7fd59977 261//=======================================================================
262
263static Standard_Integer DDataStd_GetReal (Draw_Interpretor& di,
264 Standard_Integer nb,
265 const char** arg)
266{
fa53efef 267 if (nb == 3 || nb == 4 || nb == 5) {
7fd59977 268 Handle(TDF_Data) DF;
269 if (!DDF::GetDF(arg[1],DF)) return 1;
270 Handle(TDataStd_Real) A;
5a1271c8 271 Standard_GUID aGuid;
fa53efef 272 Standard_GUID aNullGuid("00000000-0000-0000-0000-000000000000");
5a1271c8 273 Standard_Boolean isdrawname(Standard_False);
fa53efef 274 if(nb < 5 ) {
5a1271c8 275 if(nb == 4) {
276 if (Standard_GUID::CheckGUIDFormat(arg[3]))
fa53efef 277 aGuid = Standard_GUID(arg[3]);
5a1271c8 278 }
279 if(Standard_GUID::IsEqual(aGuid, aNullGuid)) {
280 isdrawname = Standard_True;
281 aGuid = TDataStd_Real::GetID();
282 }
283 }
284 else if(nb == 5) {
285 isdrawname = Standard_True;
286 if (Standard_GUID::CheckGUIDFormat(arg[4]))
fa53efef 287 aGuid = Standard_GUID(arg[4]);
5a1271c8 288 else {
fa53efef 289 di<<"DDataStd_GetReal: The format of GUID is invalid\n";
290 return 1;
5a1271c8 291 }
292 }
fa53efef 293 if (!DDF::Find(DF,arg[2],aGuid,A)) return 1;
294 if (nb == 4 && isdrawname) Draw::Set(arg[3],A->Get());
7fd59977 295 else Draw::Set(arg[2],A->Get());
296 di << A->Get();
297 return 0;
298 }
586db386 299 di << "DDataStd_GetReal : Error\n";
7fd59977 300 return 1;
301}
302
303
304//=======================================================================
305//function : DDataStd_GetReference
306//purpose : GetShape (DF, entry)
307//=======================================================================
308
309static Standard_Integer DDataStd_GetReference (Draw_Interpretor& di,
310 Standard_Integer nb,
311 const char** arg)
312{
313 if (nb == 3) {
314 Handle(TDF_Data) DF;
315 if (!DDF::GetDF(arg[1],DF)) return 1;
316 Handle(TDF_Reference) REF;
317 if (!DDF::Find(DF,arg[2],TDF_Reference::GetID(),REF)) return 1;
318 TCollection_AsciiString entry; TDF_Tool::Entry(REF->Get(),entry);
319 di << entry.ToCString();
320 return 0;
321 }
586db386 322 di << "DDataStd_GetReference : Error\n";
7fd59977 323 return 1;
324}
325
326//=======================================================================
327//function : DDataStd_GetComment
328//purpose : GetShape (DF, entry)
329//=======================================================================
330
331static Standard_Integer DDataStd_GetComment (Draw_Interpretor& di,
332 Standard_Integer nb,
333 const char** arg)
334{
335 if (nb == 3) {
336 Handle(TDF_Data) DF;
337 if (!DDF::GetDF(arg[1],DF)) return 1;
338 Handle(TDataStd_Comment) A;
339 if (!DDF::Find(DF,arg[2],TDataStd_Comment::GetID(),A)) return 1;
340 TCollection_AsciiString s(A->Get(),'?');
d9ff84e8 341 di << A->Get().ToExtString();
7fd59977 342 return 0;
343 }
586db386 344 di << "DDataStd_GetComment : Error\n";
7fd59977 345 return 1;
346}
347
348
349
350//=======================================================================
351//function :
352//purpose : Self (document,label)
353//=======================================================================
354
355static Standard_Integer DDataStd_Self (Draw_Interpretor& di,
356 Standard_Integer nb,
357 const char** arg)
358{
359 TCollection_AsciiString s;
360 if (nb == 3) {
361 Handle(TDF_Data) DF;
362 if (!DDF::GetDF(arg[1],DF)) return 1;
363 TDF_Label L;
364 if (!DDF::FindLabel(DF,arg[2],L)) return 1;
365// TDataStd::MakeSelfContained(L,removed);
366// if (removed.IsEmpty()) cout << "noone attriburte removed" << endl;
367// for (TDF_ListIteratorOfAttributeList it(removed);it.More();it.Next()) {
368// TDF_Tool::Entry(it.Value()->Label(),s); cout << s << " ";
369// cout << endl;
370// }
371 return 0;
372 }
586db386 373 di << "Self : Error\n";
7fd59977 374 return 0;
375}
376
377
378
379//=======================================================================
380//function : SetUObject (DF, entry, ObjectID)
381//=======================================================================
382// static Standard_Integer DDataStd_SetUObject (Draw_Interpretor&,
383// Standard_Integer nb,
384// const char** arg)
385// {
386// if( nb == 4 ) {
387// Handle(TDF_Data) DF;
388// if (!DDF::GetDF(arg[1],DF)) return 1;
389// TDF_Label label;
390// DDF::AddLabel(DF, arg[2], label);
391
392// Standard_GUID guid(arg[3]); //"00000000-0000-0000-1111-000000000000");
393// TDataStd_UObject::Set(label, guid);
394// return 0;
395// }
396
397// cout << "Wrong arguments" << endl;
398// return 1;
399// }
400
401//=======================================================================
402//function : SetUAttribute (DF, entry, LocalID)
403//=======================================================================
404static Standard_Integer DDataStd_SetUAttribute (Draw_Interpretor& di,
405 Standard_Integer nb,
406 const char** arg)
407{
408 if( nb == 4 ) {
409 Handle(TDF_Data) DF;
410 if (!DDF::GetDF(arg[1],DF)) return 1;
411 TDF_Label label;
412 DDF::AddLabel(DF, arg[2], label);
413
414 Standard_GUID guid(arg[3]); //"00000000-0000-0000-2222-000000000000");
415 TDataStd_UAttribute::Set(label, guid);
416 return 0;
417 }
418
419 di << "Wrong arguments" << "\n";
420 return 1;
421}
422
423//=======================================================================
424//function : GetUAttribute (DF, entry, LoaclID)
425//=======================================================================
426static Standard_Integer DDataStd_GetUAttribute (Draw_Interpretor& di,
427 Standard_Integer nb,
428 const char** arg)
429{
430 if( nb == 4 ) {
431 Handle(TDF_Data) DF;
432 if (!DDF::GetDF(arg[1],DF)) return 1;
433 TDF_Label label;
434 if( !DDF::FindLabel(DF, arg[2], label) ) {
435 di << "No label for entry" << "\n";
436 return 1;
437 }
438 Standard_GUID guid(arg[3]); //"00000000-0000-0000-2222-000000000000");
439
440 Handle(TDataStd_UAttribute) UA;
441 if( !label.FindAttribute(guid, UA) ) {
442 di << "No UAttribute Attribute on label" << "\n";
443 }
444 else {
7fd59977 445 char *aStrGUID = new char[37];
446 UA->ID().ToCString(aStrGUID);
447 di << aStrGUID;
448 }
449 return 0;
450 }
451
452 di << "Wrong arguments" << "\n";
453 return 1;
454}
455
456
457//=======================================================================
458//function : CheckUObject (DF, entry, ObjectID)
459//=======================================================================
460// static Standard_Integer DDataStd_CheckUObject (Draw_Interpretor&,
461// Standard_Integer nb,
462// const char** arg)
463// {
464// if( nb == 4 ) {
465// Handle(TDF_Data) DF;
466// if (!DDF::GetDF(arg[1],DF)) return 1;
467// TDF_Label label;
468// if( !DDF::FindLabel(DF, arg[2], label) ) {
469// cout << "No label for entry" << endl;
470// return 1;
471// }
472// Handle(TDataStd_Object) O;
473// Handle(TDataStd_UObject) UO;
474// Standard_GUID guidUO(arg[3]);
475
476// if( !label.FindAttribute( TDataStd_Object::GetID(), O) ) {
477// cout << "No Object Attribute on label" << endl;
478// }
479// else {
480// cout << "UObject is found with ObjectID = ";
481// O->Find(label, guidUO, UO);
482// UO->ObjectID().ShallowDump(cout);
483// cout << endl;
484// }
485// return 0;
486// }
487
488// cout << "Wrong arguments" << endl;
489// return 1;
490// }
491
492
493//=======================================================================
5a1271c8 494//function : SetIntArray (DF, entry , isDelta, [-g Guid,] From, To, elmt1, elmt2, ...
7fd59977 495//=======================================================================
496static Standard_Integer DDataStd_SetIntArray (Draw_Interpretor& di,
8e1e79f0 497 Standard_Integer nb,
7fd59977 498 const char** arg)
8e1e79f0 499{
5a1271c8 500 if (nb >= 6) {
501 Handle(TDF_Data) DF;
502 if (!DDF::GetDF(arg[1],DF)) return 1;
503 TDF_Label label;
504 DDF::AddLabel(DF, arg[2], label);
505 Standard_Boolean isDelta = Draw::Atoi(arg[3]) != 0;
506 Standard_GUID guid;
507 Standard_Boolean isGuid(Standard_False);
508 Standard_Character c1(arg[4][0]), c2(arg[4][1]);
509 if(c1 == '-' && c2 == 'g') { //guid
510 if (!Standard_GUID::CheckGUIDFormat(arg[5])) {
511 di<<"DDataStd_SetIntArray: The format of GUID is invalid\n";
512 return 1;
513 }
514 guid = Standard_GUID (arg[5]);
515 isGuid = Standard_True;
8e1e79f0 516 }
5a1271c8 517 Standard_Integer j(4);
518 if(isGuid) j = 6;
519 if((strlen(arg[j]) > MAXLENGTH || strlen(arg[j+1]) > MAXLENGTH) ||
520 !TCollection_AsciiString (arg[j]).IsIntegerValue() ||
521 !TCollection_AsciiString (arg[j+1]).IsIntegerValue())
522 {
523 di << "DDataStd_SetIntArray: From, To may be wrong\n";
524 return 1;
525 }
526 Standard_Integer From = Draw::Atoi(arg[j]), To = Draw::Atoi( arg[j+1] );
527 di << "Array of Standard_Integer with bounds from = " << From << " to = " << To << "\n";
528 Handle(TDataStd_IntegerArray) A;
529 if(!isGuid)
530 A = TDataStd_IntegerArray::Set(label, From, To, isDelta);
531 else
532 A = TDataStd_IntegerArray::Set(label, guid, From, To, isDelta);
533
534 if ((!isGuid && nb > 6) || (isGuid && nb > 8)) {
535 j = j + 2;
536 for(Standard_Integer i = From; i<=To; i++) {
537 A->SetValue(i, Draw::Atoi(arg[j]) );
538 j++;
539 }
540 }
541 return 0;
542 }
543 di << "DDataStd_SetIntArray: Error\n";
544 return 1;
7fd59977 545}
546
547//=======================================================================
8e1e79f0 548//function : SetIntArrayValue (DF, entry, index, value)
549//=======================================================================
550static Standard_Integer DDataStd_SetIntArrayValue (Draw_Interpretor&,
551 Standard_Integer,
552 const char** arg)
553{
554 // Get document.
555 Handle(TDF_Data) DF;
556 if (!DDF::GetDF(arg[1], DF))
557 return 1;
558
559 // Get label.
560 TDF_Label label;
561 if (!DDF::AddLabel(DF, arg[2], label))
562 return 1;
563
564 // Get index and value.
565 Standard_Integer index = Draw::Atoi(arg[3]);
566 Standard_Integer value = Draw::Atoi(arg[4]);
567
568 // Set new value.
569 Handle(TDataStd_IntegerArray) arr;
570 if (label.FindAttribute(TDataStd_IntegerArray::GetID(), arr))
571 {
572 arr->SetValue(index, value);
573 return 0;
574 }
575
576 return 1;
577}
578
579//=======================================================================
5a1271c8 580//function : GetIntArray (DF, entry [, guid] )
7fd59977 581//=======================================================================
582static Standard_Integer DDataStd_GetIntArray (Draw_Interpretor& di,
5a1271c8 583 Standard_Integer nb,
7fd59977 584 const char** arg)
585{
586
5a1271c8 587 if (nb >= 3)
588 {
589 Handle(TDF_Data) DF;
590 if (!DDF::GetDF(arg[1],DF)) return 1;
591 TDF_Label label;
592 if( !DDF::FindLabel(DF, arg[2], label) ) {
593 di << "No label for entry" << "\n";
594 return 1;
595 }
596 Standard_GUID aGuid;
597 if(nb == 4) {
598 if (Standard_GUID::CheckGUIDFormat(arg[3]))
599 aGuid = Standard_GUID(arg[3]);
600 else {
601 di << "Wrong GUID format" << "\n";
602 return 1;
603 }
604 } else
605 aGuid = TDataStd_IntegerArray::GetID();
606 Handle(TDataStd_IntegerArray) A;
607 if ( !label.FindAttribute(aGuid, A) ) {
608 di << "There is no TDataStd_IntegerArray with the specified GUID under label" << "\n";
609 return 1;
610 }
7fd59977 611
5a1271c8 612 for(Standard_Integer i = A->Lower(); i<=A->Upper(); i++){
613 //cout << A->Value(i) << endl;
614 di << A->Value(i);
615 if(i<A->Upper())
616 di<<" ";
617 }
618 di<<"\n";
619 return 0;
620 }
621 di << "DDataStd_GetIntArray: Error\n";
622 return 1;
7fd59977 623}
8e1e79f0 624//=======================================================================
625//function : GetIntArrayValue (DF, entry, index)
626//=======================================================================
627static Standard_Integer DDataStd_GetIntArrayValue (Draw_Interpretor& di,
628 Standard_Integer,
629 const char** arg)
630{
631 Handle(TDF_Data) DF;
632 if (!DDF::GetDF(arg[1],DF))
5a1271c8 633 return 1;
8e1e79f0 634
635 TDF_Label label;
636 if (!DDF::FindLabel(DF, arg[2], label)) {
637 di << "No label for entry" << "\n";
638 return 1;
639 }
5a1271c8 640
8e1e79f0 641 Handle(TDataStd_IntegerArray) A;
642 if ( !label.FindAttribute(TDataStd_IntegerArray::GetID(), A) ) {
643 di << "There is no TDataStd_IntegerArray under label" << "\n";
644 return 1;
645 }
5a1271c8 646
8e1e79f0 647 Standard_Integer index = Draw::Atoi(arg[3]);
648 if (index < A->Lower() || index > A->Upper()) {
586db386 649 di << "Index is out of range\n";
8e1e79f0 650 return 1;
651 } else {
652 di << A->Value(index) << "\n";
653 }
654
655 return 0;
656}
657
7fd59977 658//=======================================================================
659//function : ChangeIntArray (DF, entry, indx, val )
660//=======================================================================
661static Standard_Integer DDataStd_ChangeIntArray (Draw_Interpretor& di,
662 Standard_Integer nb,
663 const char** arg)
664{
665
666 if( nb == 5 ) {
667 Handle(TDF_Data) DF;
668 if (!DDF::GetDF(arg[1],DF)) return 1;
669 TDF_Label label;
670 if( !DDF::FindLabel(DF, arg[2], label) ) {
671 di << "No label for entry" << "\n";
672 return 1;
673 }
674
675 Handle(TDataStd_IntegerArray) A;
676 if ( !label.FindAttribute(TDataStd_IntegerArray::GetID(), A) ) {
677 di << "There is no TDataStd_IntegerArray at label" << "\n";
678 return 1;
679 }
91322f44 680 Standard_Integer indx = Draw::Atoi(arg[3]);
681 Standard_Integer val = Draw::Atoi(arg[4]);
7fd59977 682 Standard_Integer low = A->Lower(), up = A->Upper();
683 if(low <= indx && indx <= up)
684 A->SetValue(indx, val);
685 else {
686 Handle(TColStd_HArray1OfInteger) Arr = A->Array();
687 Handle(TColStd_HArray1OfInteger) arr;
688 Standard_Integer i;
689 if(indx > up) {
5a1271c8 690 up = indx;
691 arr = new TColStd_HArray1OfInteger(low, up);
692 for(i=low; i<= Arr->Upper(); i++)
693 arr->SetValue(i, Arr->Value(i));
694 for(i=Arr->Upper()+1; i<= up; i++) {
695 if(i == up)
696 arr->SetValue(i, val);
697 else
698 arr->SetValue(i, 0);
699 }
7fd59977 700 } else if(indx < up) {//clip array : indx to be negative
5a1271c8 701 up = abs(indx);
702 arr = new TColStd_HArray1OfInteger(low, up);
703 for(i=low; i< up; i++)
704 arr->SetValue(i, Arr->Value(i));
705 arr->SetValue(up, val);
7fd59977 706 }
707 A->ChangeArray(arr);
708 }
709 return 0;
710 }
586db386 711 di << "DDataStd_ChangeIntArray: Error\n";
7fd59977 712 return 0;
713}
714
715//=======================================================================
716//function : SetIntArrayT (DF, entry , isDelta, From, To) - for testing
717// : huge arrays
718//=======================================================================
719static Standard_Integer DDataStd_SetIntArrayTest (Draw_Interpretor& di,
720 Standard_Integer,
721 const char** arg)
722{
723
724
725 Handle(TDF_Data) DF;
726 if (!DDF::GetDF(arg[1],DF)) return 1;
727 TDF_Label label;
728 DDF::AddLabel(DF, arg[2], label);
dde68833 729 Standard_Boolean isDelta = Draw::Atoi(arg[3]) != 0;
91322f44 730 Standard_Integer From = Draw::Atoi(arg[4]), To = Draw::Atoi( arg[5] ), j;
7fd59977 731 di << "Array of Standard_Integer with bounds from = " << From << " to = " << To << "\n";
732 Handle(TDataStd_IntegerArray) A = TDataStd_IntegerArray::Set(label, From, To, isDelta);
733
734 j = 6;
735 Standard_Integer k = 100;
736 for(Standard_Integer i = From; i<=To; i++) {
737 A->SetValue(i, ++k);
738 j++;
739 }
740
741 return 0;
742}
743
744//=======================================================================
5a1271c8 745//function : SetRealArray (DF, entry , isDelta, [-g Guid,] From, To, elmt1, elmt2, ...
7fd59977 746//=======================================================================
747static Standard_Integer DDataStd_SetRealArray (Draw_Interpretor& di,
8e1e79f0 748 Standard_Integer nb,
7fd59977 749 const char** arg)
750{
5a1271c8 751 if (nb >= 6) {
752 Handle(TDF_Data) DF;
753 if (!DDF::GetDF(arg[1],DF)) return 1;
754 TDF_Label label;
755 DDF::AddLabel(DF, arg[2], label);
756 Standard_Boolean isDelta = Draw::Atoi(arg[3]) != 0;
757 Standard_GUID guid;
758 Standard_Boolean isGuid(Standard_False);
759 Standard_Character c1(arg[4][0]), c2(arg[4][1]);
760 if(c1 == '-' && c2 == 'g') { //guid
761 if (!Standard_GUID::CheckGUIDFormat(arg[5])) {
762 di<<"DDataStd_SetRealArray: The format of GUID is invalid\n";
763 return 1;
764 }
765 guid = Standard_GUID (arg[5]);
766 isGuid = Standard_True;
8e1e79f0 767 }
5a1271c8 768 Standard_Integer j(4);
769 if(isGuid) j = 6;
770 if((strlen(arg[j]) > MAXLENGTH || strlen(arg[j+1]) > MAXLENGTH) ||
771 !TCollection_AsciiString (arg[j]).IsIntegerValue() ||
772 !TCollection_AsciiString (arg[j+1]).IsIntegerValue())
773 {
774 di << "DDataStd_SetRealArray: From, To may be wrong\n";
775 return 1;
776 }
777 Standard_Integer From = Draw::Atoi(arg[j]), To = Draw::Atoi( arg[j+1] );
778 di << " Array of Standard_Real with bounds from = " << From << " to = " << To << "\n";
779 Handle(TDataStd_RealArray) A;
780 if(!isGuid)
781 A = TDataStd_RealArray::Set(label, From, To, isDelta);
782 else
783 A = TDataStd_RealArray::Set(label, guid, From, To, isDelta);
784 if ((!isGuid && nb > 6) || (isGuid && nb > 8)) {
785 j = j + 2;
786 for(Standard_Integer i = From; i<=To; i++) {
787 A->SetValue(i, Draw::Atof(arg[j]) );
788 j++;
789 }
790 }
791 return 0;
792 }
793 di << "DDataStd_SetRealArray: Error\n";
794 return 1;
7fd59977 795}
7fd59977 796//=======================================================================
8e1e79f0 797//function : SetRealArrayValue (DF, entry, index value)
798//=======================================================================
799static Standard_Integer DDataStd_SetRealArrayValue (Draw_Interpretor&,
800 Standard_Integer,
801 const char** arg)
802{
803 // Get document.
804 Handle(TDF_Data) DF;
805 if (!DDF::GetDF(arg[1], DF))
806 return 1;
807
808 // Get label.
809 TDF_Label label;
810 if (!DDF::AddLabel(DF, arg[2], label))
811 return 1;
812
813 // Get index and value.
814 Standard_Integer index = Draw::Atoi(arg[3]);
815 Standard_Real value = Draw::Atof(arg[4]);
816
817 // Set new value.
818 Handle(TDataStd_RealArray) realArray;
819 if (label.FindAttribute(TDataStd_RealArray::GetID(), realArray))
820 {
821 realArray->SetValue(index, value);
822 return 0;
823 }
824
825 return 1;
826}
827
828//=======================================================================
5a1271c8 829//function : GetRealArray (DF, entry [, guid])
7fd59977 830//=======================================================================
831static Standard_Integer DDataStd_GetRealArray (Draw_Interpretor& di,
5a1271c8 832 Standard_Integer nb,
7fd59977 833 const char** arg)
834{
5a1271c8 835 if (nb >= 3)
836 {
837 Handle(TDF_Data) DF;
838 if (!DDF::GetDF(arg[1],DF)) return 1;
839 TDF_Label label;
840 if( !DDF::FindLabel(DF, arg[2], label) ) {
841 di << "No label for entry" << "\n";
842 return 1;
843 }
844 Standard_GUID aGuid;
845 if(nb == 4) {
846 if (Standard_GUID::CheckGUIDFormat(arg[3]))
847 aGuid = Standard_GUID(arg[3]);
848 else {
849 di << "Wrong GUID format" << "\n";
850 return 1;
851 }
852 } else
853 aGuid = TDataStd_RealArray::GetID();
7fd59977 854
5a1271c8 855 Handle(TDataStd_RealArray) A;
856 if ( !label.FindAttribute(aGuid, A) ) {
857 di << "There is no TDataStd_RealArray with the specified GUID at the label" << "\n";
858#ifdef DEB_DDataStd
859 aGuid.ShallowDump(cout);
860#endif
861 return 1;
862 }
7fd59977 863
5a1271c8 864 for(Standard_Integer i = A->Lower(); i<=A->Upper(); i++){
865#ifdef DEB_DDataStd
866 cout << A->Value(i) << endl;
867#endif
868 di << A->Value(i);
869 if(i<A->Upper())
870 di<<" ";
871 }
872 di<<"\n";
873 return 0;
874 }
875 di << "TDataStd_RealArray: Error\n";
876 return 1;
877}
8e1e79f0 878//=======================================================================
879//function : GetRealArrayValue (DF, entry, index)
880//=======================================================================
881static Standard_Integer DDataStd_GetRealArrayValue (Draw_Interpretor& di,
882 Standard_Integer,
883 const char** arg)
884{
885 Handle(TDF_Data) DF;
886 if (!DDF::GetDF(arg[1],DF))
5a1271c8 887 return 1;
8e1e79f0 888
889 TDF_Label label;
890 if (!DDF::FindLabel(DF, arg[2], label)) {
891 di << "No label for entry" << "\n";
892 return 1;
893 }
5a1271c8 894
8e1e79f0 895 Handle(TDataStd_RealArray) A;
896 if ( !label.FindAttribute(TDataStd_RealArray::GetID(), A) ) {
897 di << "There is no TDataStd_RealArray under label" << "\n";
898 return 1;
899 }
5a1271c8 900
8e1e79f0 901 Standard_Integer index = Draw::Atoi(arg[3]);
902 if (index < A->Lower() || index > A->Upper()) {
586db386 903 di << "Index is out of range\n";
8e1e79f0 904 return 1;
905 } else {
906 di << A->Value(index) << "\n";
907 }
908
909 return 0;
910}
911
7fd59977 912//=======================================================================
913//function : ChangeRealArray (DF, entry, indx, val )
914//=======================================================================
915static Standard_Integer DDataStd_ChangeRealArray (Draw_Interpretor& di,
916 Standard_Integer nb,
917 const char** arg)
918{
919
920 if( nb == 5 ) {
921 Handle(TDF_Data) DF;
922 if (!DDF::GetDF(arg[1],DF)) return 1;
923 TDF_Label label;
924 if( !DDF::FindLabel(DF, arg[2], label) ) {
925 di << "No label for entry" << "\n";
926 return 1;
927 }
928
929 Handle(TDataStd_RealArray) A;
930 if ( !label.FindAttribute(TDataStd_RealArray::GetID(), A) ) {
931 di << "There is no TDataStd_RealArray at label" << "\n";
932 return 1;
933 }
91322f44 934 Standard_Integer indx = Draw::Atoi(arg[3]);
935 Standard_Real val = Draw::Atof(arg[4]);
7fd59977 936 Standard_Integer low = A->Lower(), up = A->Upper();
937 if(low <= indx && indx <= up)
938 A->SetValue(indx, val);
939 else {
940 Handle(TColStd_HArray1OfReal) Arr = A->Array();
941 Handle(TColStd_HArray1OfReal) arr;
942 Standard_Integer i;
943 if(indx > up) {
5a1271c8 944 up = indx;
945 arr = new TColStd_HArray1OfReal(low, up);
946 for(i=low; i<= Arr->Upper(); i++)
947 arr->SetValue(i, Arr->Value(i));
948 for(i=Arr->Upper()+1; i<= up; i++) {
949 if(i == up)
950 arr->SetValue(i, val);
951 else
952 arr->SetValue(i, 0);
953 }
7fd59977 954 } else if(indx < up) {//clip array : indx to be negative
5a1271c8 955 up = abs(indx);
956 arr = new TColStd_HArray1OfReal(low, up);
957 for(i=low; i< up; i++)
958 arr->SetValue(i, Arr->Value(i));
959 arr->SetValue(up, val);
7fd59977 960 }
961 A->ChangeArray(arr);
962 }
963 return 0;
964 }
586db386 965 di << "DDataStd_ChangeRealArray: Error\n";
7fd59977 966 return 0;
967}
968
969//=======================================================================
970//function : SetVariable (DF, entry, isConstant[0/1], units)
971//=======================================================================
972static Standard_Integer DDataStd_SetVariable (Draw_Interpretor& di,
973 Standard_Integer nb,
974 const char** arg)
975{
976 if (nb == 5)
977 {
978 Handle(TDF_Data) DF;
979 if (!DDF::GetDF(arg[1],DF)) return 1;
980 TDF_Label label;
981 DDF::AddLabel(DF, arg[2], label);
982
983 Handle(TDataStd_Variable) aV = TDataStd_Variable::Set(label);
984
985 const char* aUnits = arg[4];
986 aV->Unit(Standard_CString(aUnits));
987
dde68833 988 aV->Constant (Draw::Atoi(arg[3]) != 0);
7fd59977 989 return 0;
990 }
991
586db386 992 di << "Wrong arguments\n";
7fd59977 993 return 1;
994}
995
996//=======================================================================
997//function : GetVariable (DF, entry, [isConstant], [units])
998//=======================================================================
999static Standard_Integer DDataStd_GetVariable (Draw_Interpretor& di,
1000 Standard_Integer nb,
1001 const char** arg)
1002{
1003 if (nb == 5)
1004 {
1005 Handle(TDF_Data) DF;
1006 if (!DDF::GetDF(arg[1],DF)) return 1;
1007 TDF_Label label;
1008 DDF::AddLabel(DF, arg[2], label);
1009
1010 Handle(TDataStd_Variable) aV;
1011 if (!label.FindAttribute(TDataStd_Variable::GetID(), aV))
1012 {
586db386 1013 di << "TDataStd_Variable: no such attribute\n";
7fd59977 1014 }
1015
1016 Draw::Set(arg[3],TCollection_AsciiString(Standard_Integer(aV->IsConstant())).ToCString());
1017 Draw::Set(arg[4],aV->Unit().ToCString());
1018 return 0;
1019 }
1020
586db386 1021 di << "Wrong arguments\n";
7fd59977 1022 return 1;
1023}
1024
1025#include <TDataStd_Relation.hxx>
1026#include <TDataStd_Variable.hxx>
1027//=======================================================================
1028//function : SetRelation (DF, entry, expression, var1[, var2, ...])
1029//=======================================================================
1030static Standard_Integer DDataStd_SetRelation (Draw_Interpretor& di,
1031 Standard_Integer nb, const char** arg)
1032{
1033 if (nb >= 5)
1034 {
1035 Handle(TDF_Data) DF;
1036 if (!DDF::GetDF(arg[1],DF)) return 1;
1037 TDF_Label label;
1038 DDF::AddLabel(DF, arg[2], label);
1039
1040 Standard_CString expr (arg[3]);
1041 Handle(TDataStd_Relation) aR = TDataStd_Relation::Set(label);
1042 aR->SetRelation(expr);
1043 Handle(TDataStd_Variable) aV;
1044
1045 for (Standard_Integer i = 4; i < nb; i++)
1046 {
1047 if (!DDF::FindLabel(DF, arg[i], label))
1048 {
1049 di << "No label for entry" << arg[i] << "\n";
1050 return 1;
1051 }
1052 if (!label.FindAttribute(TDataStd_Variable::GetID(), aV))
1053 {
586db386 1054 di << "No TDataStd_Variable Attribute on label\n";
7fd59977 1055 return 1;
1056 }
1057 aR->GetVariables().Append(aV);
1058 }
1059 return 0;
1060 }
586db386 1061 di << "Usage: SetRelation (DF, entry, expression, var1[, var2, ...])\n";
7fd59977 1062 return 1;
1063}
1064
1065//=======================================================================
1066//function : DumpRelation (DF, entry)
1067//=======================================================================
1068static Standard_Integer DDataStd_DumpRelation (Draw_Interpretor& di,
1069 Standard_Integer nb, const char** arg)
1070{
1071 if (nb == 3)
1072 {
1073 Handle(TDF_Data) DF;
1074 if (!DDF::GetDF(arg[1],DF)) return 1;
1075
1076 TDF_Label label;
1077 if (!DDF::FindLabel(DF, arg[2], label))
1078 {
1079 di << "No label for entry " << arg[2] << "\n";
1080 return 1;
1081 }
1082 Handle(TDataStd_Relation) aR;
1083 if (!label.FindAttribute(TDataStd_Relation::GetID(), aR))
1084 {
1085 di << "No TDataStd_Relation Attribute on label " << arg[2] << "\n";
1086 return 1;
1087 }
1088
1089 di << "Relation: expression = \"" << aR->GetRelation()
1090 << "\" variables list = (";
1091
1092 Handle(TDF_Attribute) aV;
1093 TCollection_AsciiString anEntry;
1094
1095 TDF_ListIteratorOfAttributeList it;
1096 for (it.Initialize(aR->GetVariables()); it.More(); it.Next())
1097 {
1098 aV = it.Value();
1099 if (!aV.IsNull())
1100 {
1101 label = aV->Label();
1102 TDF_Tool::Entry(label, anEntry);
1103 di << anEntry.ToCString() << " ";
1104 }
1105 }
1106 di << ")";
1107 return 0;
1108 }
586db386 1109 di << "Usage: DumpRelation (DF, entry)\n";
7fd59977 1110 return 1;
1111}
1112
1113#include <TFunction_Function.hxx>
1114//=======================================================================
1115//function : SetFunction (DF, entry, guid, failure)
1116//=======================================================================
1117static Standard_Integer DDataStd_SetFunction (Draw_Interpretor& di,
1118 Standard_Integer nb, const char** arg)
1119{
1120 if (nb == 5)
1121 {
1122 Handle(TDF_Data) DF;
1123 if (!DDF::GetDF(arg[1],DF)) return 1;
1124 TDF_Label label;
1125 DDF::AddLabel(DF, arg[2], label);
1126
1127 Standard_GUID guid (arg[3]);
1128 Handle(TFunction_Function) aF = TFunction_Function::Set(label, guid);
1129
91322f44 1130 int fail = Draw::Atoi(arg[4]);
7fd59977 1131 aF->SetFailure(fail);
1132
1133 return 0;
1134 }
1135
1136 di << "Wrong arguments" << "\n";
1137 return 1;
1138}
1139
1140//=======================================================================
1141//function : GetFunction (DF, entry, guid(out), failure(out))
1142//=======================================================================
1143static Standard_Integer DDataStd_GetFunction (Draw_Interpretor& di,
1144 Standard_Integer nb, const char** arg)
1145{
1146 if (nb == 5)
1147 {
1148 Handle(TDF_Data) DF;
1149 if (!DDF::GetDF(arg[1],DF)) return 1;
1150 TDF_Label label;
1151 if (!DDF::FindLabel(DF, arg[2], label))
1152 {
1153 di << "No label for entry" << "\n";
1154 return 1;
1155 }
1156
1157 Handle(TFunction_Function) aF;
1158 if (!label.FindAttribute(TFunction_Function::GetID(), aF))
1159 {
586db386 1160 di << "No TFunction_Function Attribute on label\n";
7fd59977 1161 }
1162 else
1163 {
1164 char *aStrGUID = new char[37];
1165 aF->GetDriverGUID().ToCString(aStrGUID);
1166 Draw::Set(arg[3],aStrGUID);
1167
1168 Draw::Set(arg[4],TCollection_AsciiString(aF->GetFailure()).ToCString());
1169 }
1170 return 0;
1171 }
1172
1173 di << "Wrong arguments" << "\n";
1174 return 1;
1175}
1176
1177//=======================================================================
5a1271c8 1178//function : SetExtStringArray (DF, entry , isDelta, [-g Guid, ]From, To, elmt1, elmt2, ...
7fd59977 1179//=======================================================================
1180static Standard_Integer DDataStd_SetExtStringArray (Draw_Interpretor& di,
5a1271c8 1181 Standard_Integer nb,
1182 const char** arg)
1183{
1184 if (nb >= 6) {
1185 Handle(TDF_Data) DF;
1186 if (!DDF::GetDF(arg[1],DF)) return 1;
1187 TDF_Label label;
1188 DDF::AddLabel(DF, arg[2], label);
1189 Standard_Boolean isDelta = Draw::Atoi(arg[3]) != 0;
7fd59977 1190
5a1271c8 1191 Standard_GUID guid;
1192 Standard_Boolean isGuid(Standard_False);
1193 Standard_Character c1(arg[4][0]), c2(arg[4][1]);
1194 if(c1 == '-' && c2 == 'g') { //guid
1195 if (!Standard_GUID::CheckGUIDFormat(arg[5])) {
1196 di<<"DDataStd_SetExtStringArray: The format of GUID is invalid\n";
1197 return 1;
1198 }
1199 guid = Standard_GUID (arg[5]);
1200 isGuid = Standard_True;
8e1e79f0 1201 }
5a1271c8 1202 Standard_Integer j(4);
1203 if(isGuid) j = 6;
1204 if((strlen(arg[j]) > MAXLENGTH || strlen(arg[j+1]) > MAXLENGTH) ||
1205 !TCollection_AsciiString (arg[j]).IsIntegerValue() ||
1206 !TCollection_AsciiString (arg[j+1]).IsIntegerValue())
1207 {
1208 di << "DDataStd_SetExtStringArray: From, To may be wrong\n";
1209 return 1;
1210 }
1211 Standard_Integer From = Draw::Atoi(arg[j]), To = Draw::Atoi( arg[j+1] );
1212 di << "Array of ExtString with bounds from = " << From << " to = " << To << "\n";
1213 Handle(TDataStd_ExtStringArray) A;
1214 if(!isGuid)
1215 A = TDataStd_ExtStringArray::Set(label, From, To, isDelta);
1216 else
1217 A = TDataStd_ExtStringArray::Set(label, guid, From, To, isDelta);
7fd59977 1218
5a1271c8 1219 if ((!isGuid && nb > 6) || (isGuid && nb > 8)) {
1220 j = j + 2;
1221 for(Standard_Integer i = From; i<=To; ++i) {
1222 A->SetValue(i, arg[j] );
1223 j++;
1224 }
1225 }
1226 return 0;
1227 }
1228 di << "TDataStd_ExtStringArray: Error\n";
1229 return 1;
7fd59977 1230}
1231
1232//=======================================================================
8e1e79f0 1233//function : SetExtStringArrayValue (DF, entry, index, value)
1234//=======================================================================
1235static Standard_Integer DDataStd_SetExtStringArrayValue (Draw_Interpretor&,
1236 Standard_Integer,
1237 const char** arg)
1238{
1239 // Get document.
1240 Handle(TDF_Data) DF;
1241 if (!DDF::GetDF(arg[1], DF))
1242 return 1;
1243
1244 // Get label.
1245 TDF_Label label;
1246 if (!DDF::AddLabel(DF, arg[2], label))
1247 return 1;
1248
1249 // Get index and value.
1250 Standard_Integer index = Draw::Atoi(arg[3]);
1251
1252 // Set new value.
1253 Handle(TDataStd_ExtStringArray) arr;
1254 if (label.FindAttribute(TDataStd_ExtStringArray::GetID(), arr))
1255 {
1256 arr->SetValue(index, arg[4]);
1257 return 0;
1258 }
1259
1260 return 1;
1261}
1262
1263//=======================================================================
7fd59977 1264//function : GetExtStringArray (DF, entry )
1265//=======================================================================
1266static Standard_Integer DDataStd_GetExtStringArray (Draw_Interpretor& di,
5a1271c8 1267 Standard_Integer nb,
1268 const char** arg)
7fd59977 1269{
5a1271c8 1270 if (nb >= 3)
1271 {
7fd59977 1272
5a1271c8 1273 Handle(TDF_Data) DF;
1274 if (!DDF::GetDF(arg[1],DF)) return 1;
1275 TDF_Label label;
1276 if( !DDF::FindLabel(DF, arg[2], label) ) {
1277 di << "No label for entry" << "\n";
1278 return 1;
1279 }
1280 Standard_GUID aGuid;
1281 if(nb == 4) {
1282 if (Standard_GUID::CheckGUIDFormat(arg[3]))
1283 aGuid = Standard_GUID(arg[3]);
1284 else {
1285 di << "Wrong GUID format" << "\n";
1286 return 1;
1287 }
1288 } else
1289 aGuid = TDataStd_ExtStringArray::GetID();
1290 Handle(TDataStd_ExtStringArray) A;
1291 if ( !label.FindAttribute(aGuid, A) ) {
1292 di << "There is no TDataStd_ExtStringArray with the specified GUID at the label" << "\n";
1293 return 1;
1294 }
7fd59977 1295
5a1271c8 1296 for(Standard_Integer i = A->Lower(); i<=A->Upper(); i++){
1297 TCollection_AsciiString anAsciiString(A->Value(i),'?');
1298 di << anAsciiString.ToCString();
1299 if(i<A->Upper())
1300 di<<" ";
1301 }
1302 di<<"\n";
1303 return 0;
1304 }
1305 di << "DDataStd_GetExtStringArray: Error\n";
1306 return 1;
7fd59977 1307}
1308
1309//=======================================================================
8e1e79f0 1310//function : GetExtStringArrayValue (DF, entry, index)
1311//=======================================================================
1312static Standard_Integer DDataStd_GetExtStringArrayValue (Draw_Interpretor& di,
1313 Standard_Integer,
1314 const char** arg)
1315{
1316 Handle(TDF_Data) DF;
1317 if (!DDF::GetDF(arg[1],DF))
1318 return 1;
1319
1320 TDF_Label label;
1321 if (!DDF::FindLabel(DF, arg[2], label)) {
1322 di << "No label for entry" << "\n";
1323 return 1;
1324 }
1325
1326 Handle(TDataStd_ExtStringArray) A;
1327 if ( !label.FindAttribute(TDataStd_ExtStringArray::GetID(), A) ) {
1328 di << "There is no TDataStd_ExtStringArray under label" << "\n";
1329 return 1;
1330 }
1331
1332 Standard_Integer index = Draw::Atoi(arg[3]);
1333 if (index < A->Lower() || index > A->Upper()) {
586db386 1334 di << "Index is out of range\n";
8e1e79f0 1335 return 1;
1336 } else {
1337 const TCollection_ExtendedString& value = A->Value(index);
e9947e12 1338 di << value ;
8e1e79f0 1339 }
1340
1341 return 0;
1342}
1343
1344//=======================================================================
7fd59977 1345//function : ChangeExtStrArray (DF, entry, indx, val )
1346//=======================================================================
1347static Standard_Integer DDataStd_ChangeExtStrArray (Draw_Interpretor& di,
1348 Standard_Integer nb,
1349 const char** arg)
1350{
1351
1352 if( nb == 5 ) {
1353 Handle(TDF_Data) DF;
1354 if (!DDF::GetDF(arg[1],DF)) return 1;
1355 TDF_Label label;
1356 if( !DDF::FindLabel(DF, arg[2], label) ) {
1357 di << "No label for entry" << "\n";
1358 return 1;
1359 }
1360
1361 Handle(TDataStd_ExtStringArray) A;
1362 if ( !label.FindAttribute(TDataStd_ExtStringArray::GetID(), A) ) {
1363 di << "There is no TDataStd_ExtStringArray at label" << "\n";
1364 return 1;
1365 }
91322f44 1366 Standard_Integer indx = Draw::Atoi(arg[3]);
7fd59977 1367 TCollection_ExtendedString val(arg[4]);
1368 Standard_Integer low = A->Lower(), up = A->Upper();
1369 if(low <= indx && indx <= up)
1370 A->SetValue(indx, val);//TColStd_HArray1OfExtendedString
1371 else {
1372 Handle(TColStd_HArray1OfExtendedString) Arr = A->Array();
1373 Handle(TColStd_HArray1OfExtendedString) arr;
1374 Standard_Integer i;
1375 if(indx > up) {
5a1271c8 1376 up = indx;
1377 arr = new TColStd_HArray1OfExtendedString(low, up);
1378 for(i=low; i<= Arr->Upper(); i++)
1379 arr->SetValue(i, Arr->Value(i));
1380 for(i=Arr->Upper()+1; i<= up; i++) {
1381 if(i == up)
1382 arr->SetValue(i, val);
1383 else
1384 arr->SetValue(i, 0);
1385 }
7fd59977 1386 } else if(indx < up) {//clip array : indx to be negative
5a1271c8 1387 up = abs(indx);
1388 arr = new TColStd_HArray1OfExtendedString(low, up);
1389 for(i=low; i< up; i++)
1390 arr->SetValue(i, Arr->Value(i));
1391 arr->SetValue(up, val);
7fd59977 1392 }
1393 A->ChangeArray(arr);
1394 }
1395 return 0;
1396 }
586db386 1397 di << "DDataStd_ChangeExtStringArray: Error\n";
7fd59977 1398 return 0;
1399}
1400
1401
1402//=======================================================================
1403//function : DDataStd_KeepUTF
1404//purpose : SetUTFName (DF, fatherEntry, fileName)
1405//=======================================================================
1406static Standard_Integer DDataStd_KeepUTF (Draw_Interpretor& di,
1407 Standard_Integer nb,
1408 const char** arg)
1409{
1410 if (nb == 4) {
1411 Handle(TDF_Data) DF;
1412 if (!DDF::GetDF(arg[1],DF)) return 1;
1413 TDF_Label L;
1414 DDF::AddLabel(DF, arg[2], L);
1415 Standard_CString aFileName(arg[3]);
1416
57c28b61 1417#ifdef _MSC_VER
7fd59977 1418 ifstream anIS (aFileName, ios::in | ios::binary);
1419#else
1420 ifstream anIS (aFileName);
1421#endif
1422 if (!anIS) {
1423 // Can not open file
1424 cout << "Error: can't open file " << aFileName <<endl;;
1425 return 1;
1426 }
1427 char buf[1024];
1428 char *p;
1429 anIS.getline(buf, 1023,'\n');
1430 // 0xEFBBBF - prefix of UTF8
1431 p = &buf[3]; //skip prefix
1432 TCollection_ExtendedString aES1(p, Standard_True);
1433 TDataStd_Name::Set(L.NewChild(), aES1);
1434
1435
1436 while (anIS.good() && !anIS.eof()) {
1437 anIS.getline(buf, 1023,'\n');
1438 TCollection_ExtendedString aES2(buf, Standard_True);
1439 const TDF_Label& aLab = L.NewChild();
1440 TDataStd_Name::Set(aLab, aES2);
1441 }
1442 return 0;
1443 }
586db386 1444 di << "SetUTFName : String is not kept in DF\n";
7fd59977 1445 return 1;
1446}
1447
1448//=======================================================================
1449//function : DDataStd_GetUTFtoFile
1450//purpose : GetUTF (DF, fatherEntry, fileName)
1451// : all strings from sub-labels of the <fatherEntry> concatenated
1452// : in one, converted to UTF8 and kept in the file
1453//=======================================================================
1454static Standard_Integer DDataStd_GetUTFtoFile (Draw_Interpretor& di,
1455 Standard_Integer nb,
1456 const char** arg)
1457{
1458 if (nb == 4) {
1459 Handle(TDF_Data) DF;
1460 if (!DDF::GetDF(arg[1],DF)) return 1;
1461 TDF_Label L;
1462 if (!DDF::FindLabel(DF,arg[2],L)) return 1;
1463
1464 TCollection_ExtendedString aES;
1465 Standard_Boolean aF = Standard_False;
1466 TDF_ChildIterator anIt(L);
1467 for(;anIt.More();anIt.Next()) {
1468 const TDF_Label& aLab = anIt.Value();
1469 if(!aLab.IsNull()) {
5a1271c8 1470 Handle(TDataStd_Name) anAtt;
1471 if(aLab.FindAttribute(TDataStd_Name::GetID(), anAtt)) {
1472 if(anAtt->Get().Length()) {
1473 if (aF)
1474 aES +='\n';
1475 aES +=anAtt->Get();
1476 aF = Standard_True;
1477 }
1478 }
7fd59977 1479 }
1480 }
1481
1482 if(!aES.Length()) {
1483 cout << "Data is not found in the Document" <<endl;
1484 return 1;
1485 }
1486
1487 Standard_CString aFileName(arg[3]);
1488
57c28b61 1489#ifdef _MSC_VER
7fd59977 1490 ofstream anOS (aFileName, ios::in | ios::binary | ios::ate);
1491#else
1492 ofstream anOS (aFileName, ios::ate);
1493#endif
1494 if (!anOS) {
1495 // A problem with the stream
0797d9d3 1496#ifdef OCCT_DEBUG
7fd59977 1497 cout << "Error: problem with the file stream, rdstate = " <<anOS.rdstate() <<endl;
1498#endif
1499 }
91322f44 1500 unsigned char prefix[4] = {0xEF,0xBB,0xBF, 0x00};
7fd59977 1501 anOS.write( (char*)&prefix[0], 3);
1502 Standard_Integer n = aES.LengthOfCString();
29cb310a 1503 Standard_PCharacter aCstr = (Standard_PCharacter) Standard::Allocate(n+1);
7fd59977 1504 n = aES.ToUTF8CString(aCstr);
1505 anOS.write( (char*)&aCstr[0], n);
1506 anOS.close();
1507 return 0;
1508 }
586db386 1509 di << "GetUTF : Data is not extracted to the specified file \n";
7fd59977 1510 return 1;
1511}
1512
1513//=======================================================================
5a1271c8 1514//function : SetByteArray (DF, entry, isDelta, [-g Guid,] From, To, elmt1, elmt2, ... )
7fd59977 1515//=======================================================================
1516static Standard_Integer DDataStd_SetByteArray (Draw_Interpretor& di,
1517 Standard_Integer nb,
1518 const char** arg)
1519{
8e1e79f0 1520 if (nb >= 6) {
7fd59977 1521 Handle(TDF_Data) DF;
1522 if (!DDF::GetDF(arg[1],DF)) return 1;
1523 TDF_Label label;
1524 DDF::AddLabel(DF, arg[2], label);
dde68833 1525 Standard_Boolean isDelta = Draw::Atoi(arg[3]) != 0;
5a1271c8 1526 Standard_GUID guid;
1527 Standard_Boolean isGuid(Standard_False);
1528 Standard_Character c1(arg[4][0]), c2(arg[4][1]);
1529 if(c1 == '-' && c2 == 'g') { //guid
1530 if (!Standard_GUID::CheckGUIDFormat(arg[5])) {
1531 di<<"DDataStd_SetByteArray: The format of GUID is invalid\n";
1532 return 1;
1533 }
1534 guid = Standard_GUID (arg[5]);
1535 isGuid = Standard_True;
1536 }
1537 Standard_Integer j(4);
1538 if(isGuid) j = 6;
1539 if((strlen(arg[j]) > MAXLENGTH || strlen(arg[j+1]) > MAXLENGTH) ||
1540 !TCollection_AsciiString (arg[j]).IsIntegerValue() ||
1541 !TCollection_AsciiString (arg[j+1]).IsIntegerValue())
1542 {
1543 di << "DDataStd_SetByteArray: From, To may be wrong\n";
1544 return 1;
1545 }
1546 Standard_Integer From = Draw::Atoi(arg[j]), To = Draw::Atoi( arg[j+1] );
8e1e79f0 1547 di << "Array of Standard_Byte with bounds from = " << From << " to = " << To << "\n";
5a1271c8 1548 Handle(TDataStd_ByteArray) A;
1549 if(!isGuid)
1550 A = TDataStd_ByteArray::Set(label, From, To, isDelta);
1551 else
1552 A = TDataStd_ByteArray::Set(label, guid, From, To, isDelta);
1553
1554 if ((!isGuid && nb > 6) || (isGuid && nb > 8)) {
1555 j = j + 2;
8e1e79f0 1556 for(Standard_Integer i = From; i<=To; ++i) {
1557 Standard_Integer ival = Draw::Atoi(arg[j]);
1558 if(ival < 0 || 255 < ival) {
1559 cout << "Bad value = " << ival<< endl;
1560 return 1;
1561 }
1562 A->SetValue(i, (Standard_Byte)ival);
1563 j++;
7fd59977 1564 }
7fd59977 1565 }
1566 return 0;
1567 }
586db386 1568 di << "DDataStd_SetByteArray: Error\n";
7fd59977 1569 return 1;
1570}
1571
1572//=======================================================================
8e1e79f0 1573//function : SetByteArrayValue (DF, entry, index, value)
1574//=======================================================================
1575static Standard_Integer DDataStd_SetByteArrayValue (Draw_Interpretor&,
1576 Standard_Integer,
1577 const char** arg)
1578{
1579 // Get document.
1580 Handle(TDF_Data) DF;
1581 if (!DDF::GetDF(arg[1], DF))
1582 return 1;
1583
1584 // Get label.
1585 TDF_Label label;
1586 if (!DDF::AddLabel(DF, arg[2], label))
1587 return 1;
1588
1589 // Get index and value.
1590 Standard_Integer index = Draw::Atoi(arg[3]);
1591 Standard_Integer value = Draw::Atoi(arg[4]);
1592
1593 // Check the value.
1594 if(value < 0 || 255 < value) {
1595 cout << "Bad value = " << value << endl;
1596 return 1;
1597 }
1598
1599 // Set new value.
1600 Handle(TDataStd_ByteArray) arr;
1601 if (label.FindAttribute(TDataStd_ByteArray::GetID(), arr))
1602 {
1603 arr->SetValue(index, (Standard_Byte) value);
1604 return 0;
1605 }
1606
1607 return 1;
1608}
1609
1610//=======================================================================
5a1271c8 1611//function : SetBooleanArray (DF, entry, [-g Guid,] From, To, elmt1, elmt2, ... )
f7b4312f 1612//=======================================================================
1613static Standard_Integer DDataStd_SetBooleanArray (Draw_Interpretor& di,
1614 Standard_Integer nb,
1615 const char** arg)
1616{
5a1271c8 1617 if (nb >= 5)
f7b4312f 1618 {
1619 Handle(TDF_Data) DF;
1620 if (!DDF::GetDF(arg[1],DF))
5a1271c8 1621 return 1;
f7b4312f 1622
1623 TDF_Label label;
1624 DDF::AddLabel(DF, arg[2], label);
5a1271c8 1625 Standard_GUID guid;
1626 Standard_Boolean isGuid(Standard_False);
1627 Standard_Character c1(arg[3][0]), c2(arg[3][1]);
1628 if(c1 == '-' && c2 == 'g') { //guid
1629 if (!Standard_GUID::CheckGUIDFormat(arg[4])) {
1630 di<<"DDataStd_SetBooleanArray: The format of GUID is invalid\n";
1631 return 1;
1632 }
1633 guid = Standard_GUID (arg[4]);
1634 isGuid = Standard_True;
1635 }
1636 Standard_Integer j(3);
1637 if(isGuid) j = 5;
1638 if((strlen(arg[j]) > MAXLENGTH || strlen(arg[j+1]) > MAXLENGTH) ||
1639 !TCollection_AsciiString (arg[j]).IsIntegerValue() ||
1640 !TCollection_AsciiString (arg[j+1]).IsIntegerValue())
1641 {
1642 di << "DDataStd_SetBooleanArray: From, To may be wrong\n";
1643 return 1;
1644 }
1645 Standard_Integer From = Draw::Atoi(arg[j]), To = Draw::Atoi( arg[j+1] );
f7b4312f 1646 di << "Array of Standard_Boolean with bounds from = " << From << " to = " << To << "\n";
5a1271c8 1647 Handle(TDataStd_BooleanArray) A;
1648 if(!isGuid)
1649 A = TDataStd_BooleanArray::Set(label, From, To);
1650 else
1651 A = TDataStd_BooleanArray::Set(label, guid, From, To);
1652
1653 if ((!isGuid && nb > 5) || (isGuid && nb > 7)) {
1654 j = j + 2;
8e1e79f0 1655 for(Standard_Integer i = From; i<=To; i++)
f7b4312f 1656 {
8e1e79f0 1657 Standard_Integer ival = Draw::Atoi(arg[j]);
1658 if(ival > 1)
1659 {
5a1271c8 1660 cout << "Bad value (" <<i <<") = " << ival<< ". 0 or 1 is expected." << endl;
8e1e79f0 1661 return 1;
1662 }
dde68833 1663 A->SetValue(i, ival != 0);
8e1e79f0 1664 j++;
f7b4312f 1665 }
f7b4312f 1666 }
1667 return 0;
1668 }
586db386 1669 di << "DDataStd_SetBooleanArray: Error\n";
f7b4312f 1670 return 1;
1671}
1672
1673//=======================================================================
8e1e79f0 1674//function : SetBooleanArrayValue (DF, entry, index, value)
1675//=======================================================================
1676static Standard_Integer DDataStd_SetBooleanArrayValue (Draw_Interpretor& di,
1677 Standard_Integer,
1678 const char** arg)
1679{
1680 // Get document.
1681 Handle(TDF_Data) DF;
1682 if (!DDF::GetDF(arg[1], DF))
1683 return 1;
1684
1685 // Get label.
1686 TDF_Label label;
1687 if (!DDF::AddLabel(DF, arg[2], label))
1688 return 1;
1689
1690 // Get index and value.
1691 Standard_Integer index = Draw::Atoi(arg[3]);
1692 Standard_Integer value = Draw::Atoi(arg[4]);
1693
1694 // Check the value.
1695 if (value != 0 && value != 1) {
586db386 1696 di << "DDataStd_SetBooleanArrayValue: Error! The value should be either 0 or 1.\n";
8e1e79f0 1697 return 1;
1698 }
1699
1700 // Set new value.
1701 Handle(TDataStd_BooleanArray) arr;
1702 if (label.FindAttribute(TDataStd_BooleanArray::GetID(), arr))
1703 {
dde68833 1704 arr->SetValue(index, value != 0);
8e1e79f0 1705 return 0;
1706 }
1707
1708 return 1;
1709}
1710
1711//=======================================================================
5a1271c8 1712//function : DDataStd_SetExtStringList (DF, entry, [-g guid,] elmt1, elmt2, ... )
d585e74e 1713//=======================================================================
1714static Standard_Integer DDataStd_SetExtStringList (Draw_Interpretor& di,
1715 Standard_Integer nb,
1716 const char** arg)
1717{
1718 if (nb > 2)
1719 {
1720 Handle(TDF_Data) DF;
1721 if (!DDF::GetDF(arg[1],DF))
5a1271c8 1722 return 1;
d585e74e 1723
1724 TDF_Label label;
1725 DDF::AddLabel(DF, arg[2], label);
5a1271c8 1726 Standard_GUID guid;
1727 Standard_Boolean isGuid(Standard_False);
1728 if(nb > 4) {
1729 Standard_Character c1(arg[3][0]), c2(arg[3][1]);
1730 if(c1 == '-' && c2 == 'g') { //guid
1731 if (!Standard_GUID::CheckGUIDFormat(arg[4])) {
1732 di<<"DDataStd_SetExtStringList: The format of GUID is invalid\n";
1733 return 1;
1734 }
1735 guid = Standard_GUID (arg[4]);
1736 isGuid = Standard_True;
1737 }
1738 }
1739 Standard_Integer j(0);
1740 Handle(TDataStd_ExtStringList) A;
1741 if(!isGuid) {
1742 A = TDataStd_ExtStringList::Set(label);
1743 j = 3;
1744 }
1745 else {
1746 A = TDataStd_ExtStringList::Set(label, guid);
1747 j = 5;
1748 }
1749 for(Standard_Integer i = j; i <= nb - 1; i++)
d585e74e 1750 {
1751 TCollection_ExtendedString aValue(arg[i]);
1752 A->Append(aValue);
1753 }
1754 return 0;
1755 }
586db386 1756 di << "DDataStd_SetExtStringList: Error\n";
d585e74e 1757 return 1;
1758}
1759//
1760//=======================================================================
5a1271c8 1761//function : DDataStd_SetReferenceList (DF, entry, [-g guid] elmt1, elmt2, ... )
d585e74e 1762//=======================================================================
1763static Standard_Integer DDataStd_SetReferenceList (Draw_Interpretor& di,
1764 Standard_Integer nb,
1765 const char** arg)
1766{
1767 if (nb > 2)
1768 {
1769 Handle(TDF_Data) DF;
1770 if (!DDF::GetDF(arg[1],DF))
5a1271c8 1771 return 1;
d585e74e 1772
1773 TDF_Label label;
1774 DDF::AddLabel(DF, arg[2], label);
5a1271c8 1775 Standard_GUID guid;
1776 Standard_Boolean isGuid(Standard_False);
1777 if(nb > 4) {
1778 Standard_Character c1(arg[3][0]), c2(arg[3][1]);
1779 if(c1 == '-' && c2 == 'g') { //guid
1780 if (!Standard_GUID::CheckGUIDFormat(arg[4])) {
1781 di<<"DDataStd_SetReferenceList: The format of GUID is invalid\n";
1782 return 1;
1783 }
1784 guid = Standard_GUID (arg[4]);
1785 isGuid = Standard_True;
d585e74e 1786 }
d585e74e 1787 }
5a1271c8 1788 Standard_Integer j(0);
1789 Handle(TDataStd_ReferenceList) A;
1790 if(!isGuid) {
1791 A = TDataStd_ReferenceList::Set(label);
1792 j = 3;
1793 }
1794 else {
1795 A = TDataStd_ReferenceList::Set(label, guid);
1796 j = 5;
1797 }
1798 for(Standard_Integer i = j; i <= nb - 1; i++)
1799 {
1800 TDF_Label aValueLabel;
1801 DDF::AddLabel(DF, arg[i], aValueLabel);
1802 if(aValueLabel.IsNull()) continue;
1803 A->Append(aValueLabel);
1804 }
1805 return 0;
d585e74e 1806 }
586db386 1807 di << "DDataStd_SetReferenceList: Error\n";
d585e74e 1808 return 1;
1809}
1810
1811
1812//=======================================================================
5a1271c8 1813//function : SetBooleanList (DF, entry, [-g Guid,] elmt1, elmt2, ... )
f7b4312f 1814//=======================================================================
1815static Standard_Integer DDataStd_SetBooleanList (Draw_Interpretor& di,
1816 Standard_Integer nb,
1817 const char** arg)
1818{
1819 if (nb > 2)
1820 {
1821 Handle(TDF_Data) DF;
1822 if (!DDF::GetDF(arg[1],DF))
1823 return 1;
1824
1825 TDF_Label label;
1826 DDF::AddLabel(DF, arg[2], label);
5a1271c8 1827 Standard_GUID guid;
1828 Standard_Boolean isGuid(Standard_False);
1829 if(nb > 4) {
1830 Standard_Character c1(arg[3][0]), c2(arg[3][1]);
1831 if(c1 == '-' && c2 == 'g') { //guid
1832 if (!Standard_GUID::CheckGUIDFormat(arg[4])) {
1833 di<<"DDataStd_SetBooleanList: The format of GUID is invalid\n";
1834 return 1;
1835 }
1836 guid = Standard_GUID (arg[4]);
1837 isGuid = Standard_True;
1838 }
1839 }
1840 Standard_Integer j(0);
1841 Handle(TDataStd_BooleanList) A;
1842 if(!isGuid) {
1843 A = TDataStd_BooleanList::Set(label);
1844 j = 3;
1845 }
1846 else {
1847 A = TDataStd_BooleanList::Set(label, guid);
1848 j = 5;
1849 }
1850 for(Standard_Integer i = j; i <= nb - 1; i++)
f7b4312f 1851 {
1852 Standard_Integer ival = Draw::Atoi(arg[i]);
1853 if(ival > 1)
1854 {
1855 cout << "Bad value = " << ival<< ". 0 or 1 is expected." << endl;
1856 return 1;
1857 }
dde68833 1858 A->Append (ival != 0);
f7b4312f 1859 }
1860 return 0;
1861 }
586db386 1862 di << "DDataStd_SetBooleanList: Error\n";
f7b4312f 1863 return 1;
1864}
1865
1866//=======================================================================
5a1271c8 1867//function : SetIntegerList (DF, entry, [-g guid] elmt1, elmt2, ... )
f7b4312f 1868//=======================================================================
1869static Standard_Integer DDataStd_SetIntegerList (Draw_Interpretor& di,
1870 Standard_Integer nb,
1871 const char** arg)
1872{
1873 if (nb > 2)
1874 {
1875 Handle(TDF_Data) DF;
1876 if (!DDF::GetDF(arg[1],DF))
5a1271c8 1877 return 1;
f7b4312f 1878
1879 TDF_Label label;
1880 DDF::AddLabel(DF, arg[2], label);
5a1271c8 1881 Standard_GUID guid;
1882 Standard_Boolean isGuid(Standard_False);
1883 if(nb > 4) {
1884 Standard_Character c1(arg[3][0]), c2(arg[3][1]);
1885 if(c1 == '-' && c2 == 'g') { //guid
1886 if (!Standard_GUID::CheckGUIDFormat(arg[4])) {
1887 di<<"DDataStd_SetIntegerList: The format of GUID is invalid\n";
1888 return 1;
1889 }
1890 guid = Standard_GUID (arg[4]);
1891 isGuid = Standard_True;
1892 }
1893 }
1894 Standard_Integer j(0);
1895 Handle(TDataStd_IntegerList) A;
1896 if(!isGuid) {
1897 A = TDataStd_IntegerList::Set(label);
1898 j = 3;
1899 }
1900 else {
1901 A = TDataStd_IntegerList::Set(label, guid);
1902 j = 5;
1903 }
1904 for(Standard_Integer i = j; i <= nb - 1; i++)
f7b4312f 1905 {
1906 Standard_Integer ival = Draw::Atoi(arg[i]);
1907 A->Append(ival);
1908 }
1909 return 0;
1910 }
586db386 1911 di << "DDataStd_SetIntegerList: Error\n";
f7b4312f 1912 return 1;
1913}
1914
1915//=======================================================================
5a1271c8 1916//function : SetRealList (DF, entry, [-g guid,] elmt1, elmt2, ... )
f7b4312f 1917//=======================================================================
1918static Standard_Integer DDataStd_SetRealList (Draw_Interpretor& di,
1919 Standard_Integer nb,
1920 const char** arg)
1921{
1922 if (nb > 2)
1923 {
1924 Handle(TDF_Data) DF;
1925 if (!DDF::GetDF(arg[1],DF))
5a1271c8 1926 return 1;
f7b4312f 1927
1928 TDF_Label label;
1929 DDF::AddLabel(DF, arg[2], label);
5a1271c8 1930 Standard_GUID guid;
1931 Standard_Boolean isGuid(Standard_False);
1932 if(nb > 4) {
1933 Standard_Character c1(arg[3][0]), c2(arg[3][1]);
1934 if(c1 == '-' && c2 == 'g') { //guid
1935 if (!Standard_GUID::CheckGUIDFormat(arg[4])) {
1936 di<<"DDataStd_SetRealList: The format of GUID is invalid\n";
1937 return 1;
1938 }
1939 guid = Standard_GUID (arg[4]);
1940 isGuid = Standard_True;
1941 }
1942 }
1943 Standard_Integer j(0);
1944 Handle(TDataStd_RealList) A;
1945 if(!isGuid) {
1946 A = TDataStd_RealList::Set(label);
1947 j = 3;
1948 }
1949 else {
1950 A = TDataStd_RealList::Set(label, guid);
1951 j = 5;
1952 }
1953 for(Standard_Integer i = j; i <= nb - 1; i++)
f7b4312f 1954 {
1955 Standard_Real fval = Draw::Atof(arg[i]);
1956 A->Append(fval);
1957 }
1958 return 0;
1959 }
586db386 1960 di << "DDataStd_SetRealList: Error\n";
f7b4312f 1961 return 1;
1962}
1963
1964//=======================================================================
1ff07227 1965//function : DDataStd_InsertBeforeExtStringList (DF, entry, index, value )
1966//=======================================================================
1967static Standard_Integer DDataStd_InsertBeforeExtStringList (Draw_Interpretor& di,
1968 Standard_Integer nb,
1969 const char** arg)
1970{
1971 if (nb == 5)
1972 {
1973 Handle(TDF_Data) DF;
1974 if (!DDF::GetDF(arg[1],DF))
1975 return 1;
1976
1977 TDF_Label label;
1978 DDF::AddLabel(DF, arg[2], label);
1979
1980 Handle(TDataStd_ExtStringList) A;
1981 if (!label.FindAttribute(TDataStd_ExtStringList::GetID(), A))
1982 return 1;
1983
1984 Standard_Integer index = Draw::Atoi(arg[3]);
1985 TCollection_ExtendedString value = arg[4];
1986
1987 if (A->InsertBefore(index, value))
1988 return 0;
1989 else
1990 return 1;
1991 }
1992 di << "DDataStd_InsertBeforeExtStringList: Error\n";
1993 return 1;
1994}
1995
1996//=======================================================================
1997//function : DDataStd_InsertAfterExtStringList (DF, entry, index, value )
1998//=======================================================================
1999static Standard_Integer DDataStd_InsertAfterExtStringList (Draw_Interpretor& di,
2000 Standard_Integer nb,
2001 const char** arg)
2002{
2003 if (nb == 5)
2004 {
2005 Handle(TDF_Data) DF;
2006 if (!DDF::GetDF(arg[1],DF))
2007 return 1;
2008
2009 TDF_Label label;
2010 DDF::AddLabel(DF, arg[2], label);
2011
2012 Handle(TDataStd_ExtStringList) A;
2013 if (!label.FindAttribute(TDataStd_ExtStringList::GetID(), A))
2014 return 1;
2015
2016 Standard_Integer index = Draw::Atoi(arg[3]);
2017 TCollection_ExtendedString value = arg[4];
2018
2019 if (A->InsertAfter(index, value))
2020 return 0;
2021 else
2022 return 1;
2023 }
2024 di << "DDataStd_InsertAfterExtStringList: Error\n";
2025 return 1;
2026}
2027
2028//=======================================================================
2029//function : DDataStd_RemoveExtStringList (DF, entry, index )
2030//=======================================================================
2031static Standard_Integer DDataStd_RemoveExtStringList (Draw_Interpretor& di,
2032 Standard_Integer nb,
2033 const char** arg)
2034{
2035 if (nb == 4)
2036 {
2037 Handle(TDF_Data) DF;
2038 if (!DDF::GetDF(arg[1],DF))
2039 return 1;
2040
2041 TDF_Label label;
2042 DDF::AddLabel(DF, arg[2], label);
2043
2044 Handle(TDataStd_ExtStringList) A;
2045 if (!label.FindAttribute(TDataStd_ExtStringList::GetID(), A))
2046 return 1;
2047
2048 Standard_Integer index = Draw::Atoi(arg[3]);
2049
2050 if (A->Remove(index))
2051 return 0;
2052 else
2053 return 1;
2054 }
2055 di << "DDataStd_RemoveExtStringList: Error\n";
2056 return 1;
2057}
2058
2059//=======================================================================
2060//function : DDataStd_InsertBeforeBooleanList (DF, entry, index, value )
2061//=======================================================================
2062static Standard_Integer DDataStd_InsertBeforeBooleanList (Draw_Interpretor& di,
2063 Standard_Integer nb,
2064 const char** arg)
2065{
2066 if (nb == 5)
2067 {
2068 Handle(TDF_Data) DF;
2069 if (!DDF::GetDF(arg[1],DF))
2070 return 1;
2071
2072 TDF_Label label;
2073 DDF::AddLabel(DF, arg[2], label);
2074
2075 Handle(TDataStd_BooleanList) A;
2076 if (!label.FindAttribute(TDataStd_BooleanList::GetID(), A))
2077 return 1;
2078
2079 Standard_Integer index = Draw::Atoi(arg[3]);
dde68833 2080 Standard_Boolean value = Draw::Atoi(arg[4]) != 0;
1ff07227 2081
2082 if (A->InsertBefore(index, value))
2083 return 0;
2084 else
2085 return 1;
2086 }
2087 di << "DDataStd_InsertBeforeBooleanList: Error\n";
2088 return 1;
2089}
2090
2091//=======================================================================
2092//function : DDataStd_InsertAfterBooleanList (DF, entry, index, value )
2093//=======================================================================
2094static Standard_Integer DDataStd_InsertAfterBooleanList (Draw_Interpretor& di,
2095 Standard_Integer nb,
2096 const char** arg)
2097{
2098 if (nb == 5)
2099 {
2100 Handle(TDF_Data) DF;
2101 if (!DDF::GetDF(arg[1],DF))
2102 return 1;
2103
2104 TDF_Label label;
2105 DDF::AddLabel(DF, arg[2], label);
2106
2107 Handle(TDataStd_BooleanList) A;
2108 if (!label.FindAttribute(TDataStd_BooleanList::GetID(), A))
2109 return 1;
2110
2111 Standard_Integer index = Draw::Atoi(arg[3]);
dde68833 2112 Standard_Boolean value = Draw::Atoi(arg[4]) != 0;
1ff07227 2113
2114 if (A->InsertAfter(index, value))
2115 return 0;
2116 else
2117 return 1;
2118 }
2119 di << "DDataStd_InsertAfterBooleanList: Error\n";
2120 return 1;
2121}
2122
2123//=======================================================================
2124//function : DDataStd_RemoveBooleanList (DF, entry, index )
2125//=======================================================================
2126static Standard_Integer DDataStd_RemoveBooleanList (Draw_Interpretor& di,
2127 Standard_Integer nb,
2128 const char** arg)
2129{
2130 if (nb == 4)
2131 {
2132 Handle(TDF_Data) DF;
2133 if (!DDF::GetDF(arg[1],DF))
2134 return 1;
2135
2136 TDF_Label label;
2137 DDF::AddLabel(DF, arg[2], label);
2138
2139 Handle(TDataStd_BooleanList) A;
2140 if (!label.FindAttribute(TDataStd_BooleanList::GetID(), A))
2141 return 1;
2142
2143 Standard_Integer index = Draw::Atoi(arg[3]);
2144
2145 if (A->Remove(index))
2146 return 0;
2147 else
2148 return 1;
2149 }
2150 di << "DDataStd_RemoveBooleanList: Error\n";
2151 return 1;
2152}
2153
2154//=======================================================================
2155//function : DDataStd_InsertBeforeIntegerList (DF, entry, index, value )
2156//=======================================================================
2157static Standard_Integer DDataStd_InsertBeforeIntegerList (Draw_Interpretor& di,
2158 Standard_Integer nb,
2159 const char** arg)
2160{
2161 if (nb == 5)
2162 {
2163 Handle(TDF_Data) DF;
2164 if (!DDF::GetDF(arg[1],DF))
2165 return 1;
2166
2167 TDF_Label label;
2168 DDF::AddLabel(DF, arg[2], label);
2169
2170 Handle(TDataStd_IntegerList) A;
2171 if (!label.FindAttribute(TDataStd_IntegerList::GetID(), A))
2172 return 1;
2173
2174 Standard_Integer index = Draw::Atoi(arg[3]);
2175 Standard_Integer value = (Standard_Integer) Draw::Atoi(arg[4]);
2176
2177 if (A->InsertBeforeByIndex(index, value))
2178 return 0;
2179 else
2180 return 1;
2181 }
2182 di << "DDataStd_InsertBeforeIntegerList: Error\n";
2183 return 1;
2184}
2185
2186//=======================================================================
2187//function : DDataStd_InsertAfterIntegerList (DF, entry, index, value )
2188//=======================================================================
2189static Standard_Integer DDataStd_InsertAfterIntegerList (Draw_Interpretor& di,
2190 Standard_Integer nb,
2191 const char** arg)
2192{
2193 if (nb == 5)
2194 {
2195 Handle(TDF_Data) DF;
2196 if (!DDF::GetDF(arg[1],DF))
2197 return 1;
2198
2199 TDF_Label label;
2200 DDF::AddLabel(DF, arg[2], label);
2201
2202 Handle(TDataStd_IntegerList) A;
2203 if (!label.FindAttribute(TDataStd_IntegerList::GetID(), A))
2204 return 1;
2205
2206 Standard_Integer index = Draw::Atoi(arg[3]);
2207 Standard_Integer value = (Standard_Integer) Draw::Atoi(arg[4]);
2208
2209 if (A->InsertAfterByIndex(index, value))
2210 return 0;
2211 else
2212 return 1;
2213 }
2214 di << "DDataStd_InsertAfterIntegerList: Error\n";
2215 return 1;
2216}
2217
2218//=======================================================================
2219//function : DDataStd_RemoveIntegerList (DF, entry, index )
2220//=======================================================================
2221static Standard_Integer DDataStd_RemoveIntegerList (Draw_Interpretor& di,
2222 Standard_Integer nb,
2223 const char** arg)
2224{
2225 if (nb == 4)
2226 {
2227 Handle(TDF_Data) DF;
2228 if (!DDF::GetDF(arg[1],DF))
2229 return 1;
2230
2231 TDF_Label label;
2232 DDF::AddLabel(DF, arg[2], label);
2233
2234 Handle(TDataStd_IntegerList) A;
2235 if (!label.FindAttribute(TDataStd_IntegerList::GetID(), A))
2236 return 1;
2237
2238 Standard_Integer index = Draw::Atoi(arg[3]);
2239
2240 if (A->RemoveByIndex(index))
2241 return 0;
2242 else
2243 return 1;
2244 }
2245 di << "DDataStd_RemoveIntegerList: Error\n";
2246 return 1;
2247}
2248
2249//=======================================================================
2250//function : DDataStd_InsertBeforeRealList (DF, entry, index, value )
2251//=======================================================================
2252static Standard_Integer DDataStd_InsertBeforeRealList (Draw_Interpretor& di,
2253 Standard_Integer nb,
2254 const char** arg)
2255{
2256 if (nb == 5)
2257 {
2258 Handle(TDF_Data) DF;
2259 if (!DDF::GetDF(arg[1],DF))
2260 return 1;
2261
2262 TDF_Label label;
2263 DDF::AddLabel(DF, arg[2], label);
2264
2265 Handle(TDataStd_RealList) A;
2266 if (!label.FindAttribute(TDataStd_RealList::GetID(), A))
2267 return 1;
2268
2269 Standard_Integer index = Draw::Atoi(arg[3]);
2270 Standard_Real value = (Standard_Real) Draw::Atof(arg[4]);
2271
2272 if (A->InsertBeforeByIndex(index, value))
2273 return 0;
2274 else
2275 return 1;
2276 }
2277 di << "DDataStd_InsertBeforeRealList: Error\n";
2278 return 1;
2279}
2280
2281//=======================================================================
2282//function : DDataStd_InsertAfterRealList (DF, entry, index, value )
2283//=======================================================================
2284static Standard_Integer DDataStd_InsertAfterRealList (Draw_Interpretor& di,
2285 Standard_Integer nb,
2286 const char** arg)
2287{
2288 if (nb == 5)
2289 {
2290 Handle(TDF_Data) DF;
2291 if (!DDF::GetDF(arg[1],DF))
2292 return 1;
2293
2294 TDF_Label label;
2295 DDF::AddLabel(DF, arg[2], label);
2296
2297 Handle(TDataStd_RealList) A;
2298 if (!label.FindAttribute(TDataStd_RealList::GetID(), A))
2299 return 1;
2300
2301 Standard_Integer index = Draw::Atoi(arg[3]);
2302 Standard_Real value = (Standard_Real) Draw::Atof(arg[4]);
2303
2304 if (A->InsertAfterByIndex(index, value))
2305 return 0;
2306 else
2307 return 1;
2308 }
2309 di << "DDataStd_InsertAfterRealList: Error\n";
2310 return 1;
2311}
2312
2313//=======================================================================
2314//function : DDataStd_RemoveRealList (DF, entry, index )
2315//=======================================================================
2316static Standard_Integer DDataStd_RemoveRealList (Draw_Interpretor& di,
2317 Standard_Integer nb,
2318 const char** arg)
2319{
2320 if (nb == 4)
2321 {
2322 Handle(TDF_Data) DF;
2323 if (!DDF::GetDF(arg[1],DF))
2324 return 1;
2325
2326 TDF_Label label;
2327 DDF::AddLabel(DF, arg[2], label);
2328
2329 Handle(TDataStd_RealList) A;
2330 if (!label.FindAttribute(TDataStd_RealList::GetID(), A))
2331 return 1;
2332
2333 Standard_Integer index = Draw::Atoi(arg[3]);
2334
2335 if (A->RemoveByIndex(index))
2336 return 0;
2337 else
2338 return 1;
2339 }
2340 di << "DDataStd_RemoveRealList: Error\n";
2341 return 1;
2342}
2343
2344//=======================================================================
2345//function : DDataStd_InsertBeforeReferenceList (DF, entry, index, value )
2346//=======================================================================
2347static Standard_Integer DDataStd_InsertBeforeReferenceList (Draw_Interpretor& di,
2348 Standard_Integer nb,
2349 const char** arg)
2350{
2351 if (nb == 5)
2352 {
2353 Handle(TDF_Data) DF;
2354 if (!DDF::GetDF(arg[1],DF))
2355 return 1;
2356
2357 TDF_Label label;
2358 DDF::AddLabel(DF, arg[2], label);
2359
2360 Handle(TDataStd_ReferenceList) A;
2361 if (!label.FindAttribute(TDataStd_ReferenceList::GetID(), A))
2362 return 1;
2363
2364 Standard_Integer index = Draw::Atoi(arg[3]);
2365
2366 TDF_Label refLabel;
2367 if (!DDF::AddLabel(DF, arg[4], refLabel))
2368 return 1;
2369
2370 if (A->InsertBefore(index, refLabel))
2371 return 0;
2372 else
2373 return 1;
2374 }
2375 di << "DDataStd_InsertBeforeReferenceList: Error\n";
2376 return 1;
2377}
2378
2379//=======================================================================
2380//function : DDataStd_InsertAfterReferenceList (DF, entry, index, value )
2381//=======================================================================
2382static Standard_Integer DDataStd_InsertAfterReferenceList (Draw_Interpretor& di,
2383 Standard_Integer nb,
2384 const char** arg)
2385{
2386 if (nb == 5)
2387 {
2388 Handle(TDF_Data) DF;
2389 if (!DDF::GetDF(arg[1],DF))
2390 return 1;
2391
2392 TDF_Label label;
2393 DDF::AddLabel(DF, arg[2], label);
2394
2395 Handle(TDataStd_ReferenceList) A;
2396 if (!label.FindAttribute(TDataStd_ReferenceList::GetID(), A))
2397 return 1;
2398
2399 Standard_Integer index = Draw::Atoi(arg[3]);
2400
2401 TDF_Label refLabel;
2402 if (!DDF::AddLabel(DF, arg[4], refLabel))
2403 return 1;
2404
2405 if (A->InsertAfter(index, refLabel))
2406 return 0;
2407 else
2408 return 1;
2409 }
2410 di << "DDataStd_InsertAfterReferenceList: Error\n";
2411 return 1;
2412}
2413
2414//=======================================================================
2415//function : DDataStd_RemoveReferenceList (DF, entry, index )
2416//=======================================================================
2417static Standard_Integer DDataStd_RemoveReferenceList (Draw_Interpretor& di,
2418 Standard_Integer nb,
2419 const char** arg)
2420{
2421 if (nb == 4)
2422 {
2423 Handle(TDF_Data) DF;
2424 if (!DDF::GetDF(arg[1],DF))
2425 return 1;
2426
2427 TDF_Label label;
2428 DDF::AddLabel(DF, arg[2], label);
2429
2430 Handle(TDataStd_ReferenceList) A;
2431 if (!label.FindAttribute(TDataStd_ReferenceList::GetID(), A))
2432 return 1;
2433
2434 Standard_Integer index = Draw::Atoi(arg[3]);
2435
2436 if (A->Remove(index))
2437 return 0;
2438 else
2439 return 1;
2440 }
2441 di << "DDataStd_RemoveReferenceList: Error\n";
2442 return 1;
2443}
2444
2445//=======================================================================
5a1271c8 2446//function : GetByteArray (DF, entry [, guid] )
7fd59977 2447//=======================================================================
2448static Standard_Integer DDataStd_GetByteArray (Draw_Interpretor& di,
5a1271c8 2449 Standard_Integer nb,
7fd59977 2450 const char** arg)
2451{
5a1271c8 2452 if (nb >= 3)
2453 {
2454 Handle(TDF_Data) DF;
2455 if (!DDF::GetDF(arg[1],DF)) return 1;
2456 TDF_Label label;
2457 if( !DDF::FindLabel(DF, arg[2], label) ) {
2458 di << "No label for entry" << "\n";
2459 return 1;
2460 }
2461 Standard_GUID aGuid;
2462 if(nb == 4) {
2463 if (Standard_GUID::CheckGUIDFormat(arg[3]))
2464 aGuid = Standard_GUID(arg[3]);
2465 else {
2466 di << "Wrong GUID format" << "\n";
2467 return 1;
2468 }
2469 } else
2470 aGuid = TDataStd_ByteArray::GetID();
2471 Handle(TDataStd_ByteArray) A;
2472 if ( !label.FindAttribute(aGuid, A) ) {
2473 di << "There is no TDataStd_ByteArray with the specified GUID at the label" << "\n";
2474 return 1;
2475 }
7fd59977 2476
5a1271c8 2477 for(Standard_Integer i = A->Lower(); i<=A->Upper(); i++){
2478 //cout << A->Value(i) << endl;
2479 di << A->Value(i);
2480 if(i<A->Upper())
2481 di<<" ";
2482 }
2483 di<<"\n";
2484 return 0;
7fd59977 2485 }
5a1271c8 2486 di << "DDataStd_GetByteArray: Error\n";
2487 return 1;
7fd59977 2488}
2489
2490//=======================================================================
8e1e79f0 2491//function : GetByteArrayValue (DF, entry, index)
2492//=======================================================================
2493static Standard_Integer DDataStd_GetByteArrayValue (Draw_Interpretor& di,
2494 Standard_Integer,
2495 const char** arg)
2496{
2497 Handle(TDF_Data) DF;
2498 if (!DDF::GetDF(arg[1],DF))
2499 return 1;
2500
2501 TDF_Label label;
2502 if (!DDF::FindLabel(DF, arg[2], label)) {
2503 di << "No label for entry" << "\n";
2504 return 1;
2505 }
2506
2507 Handle(TDataStd_ByteArray) A;
2508 if ( !label.FindAttribute(TDataStd_ByteArray::GetID(), A) ) {
2509 di << "There is no TDataStd_ByteArray under label" << "\n";
2510 return 1;
2511 }
2512
2513 Standard_Integer index = Draw::Atoi(arg[3]);
2514 if (index < A->Lower() || index > A->Upper()) {
586db386 2515 di << "Index is out of range\n";
8e1e79f0 2516 return 1;
2517 } else {
2518 di << A->Value(index) << "\n";
2519 }
2520
2521 return 0;
2522}
2523
2524//=======================================================================
5a1271c8 2525//function : GetBooleanArray (DF, entry [, guid] )
f7b4312f 2526//=======================================================================
2527static Standard_Integer DDataStd_GetBooleanArray (Draw_Interpretor& di,
5a1271c8 2528 Standard_Integer nb,
f7b4312f 2529 const char** arg)
2530{
5a1271c8 2531 if (nb >= 3)
2532 {
2533 Handle(TDF_Data) DF;
2534 if (!DDF::GetDF(arg[1],DF))
f7b4312f 2535 return 1;
2536
5a1271c8 2537 TDF_Label label;
2538 if ( !DDF::FindLabel(DF, arg[2], label) )
2539 {
2540 di << "No label for entry" << "\n";
2541 return 1;
2542 }
2543 Standard_GUID aGuid;
2544 if(nb == 4) {
2545 if (Standard_GUID::CheckGUIDFormat(arg[3]))
2546 aGuid = Standard_GUID(arg[3]);
2547 else {
2548 di << "Wrong GUID format" << "\n";
2549 return 1;
2550 }
2551 } else
2552 aGuid = TDataStd_BooleanArray::GetID();
2553
2554 Handle(TDataStd_BooleanArray) A;
2555 if ( !label.FindAttribute(aGuid, A) )
2556 {
2557 di << "There is no TDataStd_BooleanArray at label" << "\n";
2558 return 1;
2559 }
2560
2561 for (Standard_Integer i = A->Lower(); i<=A->Upper(); i++)
2562 {
2563 di << (Standard_Integer) A->Value(i);
2564 if (i < A->Upper())
2565 di << " ";
2566 }
2567 di << "\n";
2568 return 0;
f7b4312f 2569 }
5a1271c8 2570 di << "DDataStd_GetBooleanArray: Error\n";
2571 return 1;
f7b4312f 2572}
2573
2574//=======================================================================
8e1e79f0 2575//function : GetBooleanArrayValue (DF, entry, index)
2576//=======================================================================
2577static Standard_Integer DDataStd_GetBooleanArrayValue (Draw_Interpretor& di,
2578 Standard_Integer,
2579 const char** arg)
2580{
2581 Handle(TDF_Data) DF;
2582 if (!DDF::GetDF(arg[1],DF))
2583 return 1;
2584
2585 TDF_Label label;
2586 if (!DDF::FindLabel(DF, arg[2], label)) {
2587 di << "No label for entry" << "\n";
2588 return 1;
2589 }
2590
2591 Handle(TDataStd_BooleanArray) A;
2592 if ( !label.FindAttribute(TDataStd_BooleanArray::GetID(), A) ) {
2593 di << "There is no TDataStd_BooleanArray under label" << "\n";
2594 return 1;
2595 }
2596
2597 Standard_Integer index = Draw::Atoi(arg[3]);
2598 if (index < A->Lower() || index > A->Upper()) {
586db386 2599 di << "Index is out of range\n";
8e1e79f0 2600 return 1;
2601 } else {
2602 di << ((A->Value(index) == Standard_True) ? "True" : "False") << "\n";
2603 }
2604
2605 return 0;
2606}
2607
2608//=======================================================================
7fd59977 2609//function : ChangeByteArray (DF, entry, indx, val )
2610//=======================================================================
2611static Standard_Integer DDataStd_ChangeByteArray (Draw_Interpretor& di,
2612 Standard_Integer nb,
2613 const char** arg)
2614{
2615
2616 if( nb == 5 ) {
2617 Handle(TDF_Data) DF;
2618 if (!DDF::GetDF(arg[1],DF)) return 1;
2619 TDF_Label label;
2620 if( !DDF::FindLabel(DF, arg[2], label) ) {
2621 di << "No label for entry" << "\n";
2622 return 1;
2623 }
2624
2625 Handle(TDataStd_ByteArray) A;
2626 if ( !label.FindAttribute(TDataStd_ByteArray::GetID(), A) ) {
2627 di << "There is no TDataStd_ByteArray at label" << "\n";
2628 return 1;
2629 }
91322f44 2630 Standard_Integer indx = Draw::Atoi(arg[3]);
2631 Standard_Integer ival = Draw::Atoi(arg[4]);
7fd59977 2632 if (ival > 255 || ival < 0) {
2633 di << "DDataStd_ChangeByteArray: Bad value = " <<ival << "\n";
5a1271c8 2634 return 1;
7fd59977 2635 }
2636 Standard_Integer low = A->Lower(), up = A->Upper();
2637 if(low <= indx && indx <= up)
8263fcd3 2638 A->SetValue(indx, (Standard_Byte)ival);
7fd59977 2639 else {
2640 Handle(TColStd_HArray1OfByte) Arr = A->InternalArray();
2641 Handle(TColStd_HArray1OfByte) arr;
2642 Standard_Integer i;
2643 if(indx > up) {
5a1271c8 2644 up = indx;
2645 arr = new TColStd_HArray1OfByte(low, up);
2646 for(i=low; i<= Arr->Upper(); i++)
2647 arr->SetValue(i, Arr->Value(i));
2648 for(i=Arr->Upper()+1; i<= up; i++) {
2649 if(i == up)
2650 arr->SetValue(i, (Standard_Byte)ival);
2651 else
2652 arr->SetValue(i, 0);
2653 }
7fd59977 2654 } else if(indx < up) {//clip array : indx to be negative
5a1271c8 2655 up = abs(indx);
2656 arr = new TColStd_HArray1OfByte(low, up);
2657 for(i=low; i< up; i++)
2658 arr->SetValue(i, Arr->Value(i));
2659 arr->SetValue(up, (Standard_Byte)ival);
7fd59977 2660 }
2661 A->ChangeArray(arr);
2662 }
2663 return 0;
2664 }
586db386 2665 di << "DDataStd_ChangeByteArray: Error\n";
7fd59977 2666 return 1;
2667}
f7b4312f 2668
2669//=======================================================================
5a1271c8 2670//function : GetBooleanList (DF, entry [, guid])
f7b4312f 2671//=======================================================================
2672static Standard_Integer DDataStd_GetBooleanList (Draw_Interpretor& di,
d585e74e 2673 Standard_Integer nb,
f7b4312f 2674 const char** arg)
2675{
5a1271c8 2676 if (nb >= 3) {
d585e74e 2677 Handle(TDF_Data) DF;
2678 if (!DDF::GetDF(arg[1],DF))
f7b4312f 2679 return 1;
2680
d585e74e 2681 TDF_Label label;
2682 if ( !DDF::FindLabel(DF, arg[2], label) )
2683 {
2684 di << "No label for entry" << "\n";
2685 return 1;
2686 }
5a1271c8 2687 Standard_GUID aGuid;
2688 if(nb == 4) {
2689 if (Standard_GUID::CheckGUIDFormat(arg[3]))
2690 aGuid = Standard_GUID(arg[3]);
2691 else {
2692 di << "Wrong GUID format" << "\n";
2693 return 1;
2694 }
2695 } else
2696 aGuid = TDataStd_BooleanList::GetID();
2697
d585e74e 2698 Handle(TDataStd_BooleanList) A;
5a1271c8 2699 if ( !label.FindAttribute(aGuid, A) )
d585e74e 2700 {
5a1271c8 2701 di << "There is no TDataStd_BooleanList with the specified Guid at the label" << "\n";
d585e74e 2702 return 1;
2703 }
5a1271c8 2704
d585e74e 2705 const TDataStd_ListOfByte& bList = A->List();
2706 Standard_Boolean isEmpty = (bList.Extent() > 0) ? Standard_False : Standard_True;
2707 if(!isEmpty) {
2708 TDataStd_ListIteratorOfListOfByte itr(bList);
2709 for (; itr.More(); itr.Next())
2710 {
2711 di << (Standard_Integer) itr.Value() << " ";
2712 }
2713 di << "\n";
2714 } else
5a1271c8 2715 di << "List is empty\n";
d585e74e 2716 return 0;
f7b4312f 2717 }
586db386 2718 di << "DDataStd_GetBooleanList: Error\n";
d585e74e 2719 return 1;
f7b4312f 2720}
2721
2722//=======================================================================
5a1271c8 2723//function : GetIntegerList (DF, entry [, guid])
f7b4312f 2724//=======================================================================
2725static Standard_Integer DDataStd_GetIntegerList (Draw_Interpretor& di,
d585e74e 2726 Standard_Integer nb,
f7b4312f 2727 const char** arg)
d585e74e 2728{
5a1271c8 2729 if (nb >= 3) {
d585e74e 2730 Handle(TDF_Data) DF;
2731 if (!DDF::GetDF(arg[1],DF))
f7b4312f 2732 return 1;
2733
d585e74e 2734 TDF_Label label;
2735 if ( !DDF::FindLabel(DF, arg[2], label) )
2736 {
2737 di << "No label for entry" << "\n";
2738 return 1;
2739 }
5a1271c8 2740 Standard_GUID aGuid;
2741 if(nb == 4) {
2742 if (Standard_GUID::CheckGUIDFormat(arg[3]))
2743 aGuid = Standard_GUID(arg[3]);
2744 else {
2745 di << "Wrong GUID format" << "\n";
2746 return 1;
2747 }
2748 } else
2749 aGuid = TDataStd_IntegerList::GetID();
2750
d585e74e 2751 Handle(TDataStd_IntegerList) A;
5a1271c8 2752 if ( !label.FindAttribute(aGuid, A) )
d585e74e 2753 {
5a1271c8 2754 di << "There is no TDataStd_IntegerList with the specified GUID at the label" << "\n";
d585e74e 2755 return 1;
2756 }
5a1271c8 2757
d585e74e 2758 const TColStd_ListOfInteger& iList = A->List();
2759 Standard_Boolean isEmpty = (iList.Extent() > 0) ? Standard_False : Standard_True;
2760 if(!isEmpty) {
2761 TColStd_ListIteratorOfListOfInteger itr(iList);
2762 for (; itr.More(); itr.Next())
2763 {
2764 di << itr.Value() << " ";
2765 }
2766 di << "\n";
2767 } else
586db386 2768 di << "List is empty\n";
d585e74e 2769
2770 return 0;
f7b4312f 2771 }
586db386 2772 di << "DDataStd_GetIntegerList: Error\n";
d585e74e 2773 return 1;
f7b4312f 2774}
2775
2776//=======================================================================
5a1271c8 2777//function : GetRealList (DF, entry [, guid])
f7b4312f 2778//=======================================================================
2779static Standard_Integer DDataStd_GetRealList (Draw_Interpretor& di,
d585e74e 2780 Standard_Integer nb,
f7b4312f 2781 const char** arg)
2782{
5a1271c8 2783 if (nb >= 3) {
d585e74e 2784 Handle(TDF_Data) DF;
2785 if (!DDF::GetDF(arg[1],DF))
f7b4312f 2786 return 1;
2787
d585e74e 2788 TDF_Label label;
2789 if ( !DDF::FindLabel(DF, arg[2], label) )
2790 {
2791 di << "No label for entry" << "\n";
2792 return 1;
2793 }
5a1271c8 2794 Standard_GUID aGuid;
2795 if(nb == 4) {
2796 if (Standard_GUID::CheckGUIDFormat(arg[3]))
2797 aGuid = Standard_GUID(arg[3]);
2798 else {
2799 di << "Wrong GUID format" << "\n";
2800 return 1;
2801 }
2802 } else
2803 aGuid = TDataStd_RealList::GetID();
2804
d585e74e 2805 Handle(TDataStd_RealList) A;
5a1271c8 2806 if ( !label.FindAttribute(aGuid, A) )
d585e74e 2807 {
5a1271c8 2808 di << "There is no TDataStd_RealList with the specified GUID at the label" << "\n";
d585e74e 2809 return 1;
2810 }
5a1271c8 2811
d585e74e 2812 const TColStd_ListOfReal& rList = A->List();
2813 Standard_Boolean isEmpty = (rList.Extent() > 0) ? Standard_False : Standard_True;
2814 if(!isEmpty) {
2815 TColStd_ListIteratorOfListOfReal itr(rList);
2816 for (; itr.More(); itr.Next())
2817 {
2818 di << itr.Value() << " ";
2819 }
2820 di << "\n";
2821 } else
586db386 2822 di << "List is empty\n";
d585e74e 2823 return 0;
f7b4312f 2824 }
586db386 2825 di << "DDataStd_GetRealList: Error\n";
d585e74e 2826 return 1;
f7b4312f 2827}
2828
7fd59977 2829//=======================================================================
5a1271c8 2830//function : DDataStd_GetExtStringList (DF, entry [, guid])
d585e74e 2831//=======================================================================
2832static Standard_Integer DDataStd_GetExtStringList (Draw_Interpretor& di,
2833 Standard_Integer nb,
2834 const char** arg)
2835{
5a1271c8 2836 if (nb >= 3)
d585e74e 2837 {
2838 Handle(TDF_Data) DF;
2839 if (!DDF::GetDF(arg[1],DF))
2840 return 1;
2841
2842 TDF_Label label;
2843 if ( !DDF::FindLabel(DF, arg[2], label) )
2844 {
2845 di << "No label for entry" << "\n";
2846 return 1;
2847 }
5a1271c8 2848 Standard_GUID aGuid;
2849 if(nb == 4) {
2850 if (Standard_GUID::CheckGUIDFormat(arg[3]))
2851 aGuid = Standard_GUID(arg[3]);
2852 else {
2853 di << "Wrong GUID format" << "\n";
2854 return 1;
2855 }
2856 } else
2857 aGuid = TDataStd_ExtStringList::GetID();
d585e74e 2858
2859 Handle(TDataStd_ExtStringList) A;
5a1271c8 2860 if ( !label.FindAttribute(aGuid, A) )
d585e74e 2861 {
2862 di << "There is no TDataStd_ExtStringList at label" << "\n";
2863 return 1;
2864 }
2865
2866 const TDataStd_ListOfExtendedString& aList = A->List();
2867 Standard_Boolean isEmpty = (aList.Extent() > 0) ? Standard_False : Standard_True;
2868 if(!isEmpty) {
2869 TDataStd_ListIteratorOfListOfExtendedString itr(aList);
2870 for (; itr.More(); itr.Next())
2871 {
2872 const TCollection_ExtendedString& aStr = itr.Value();
2873 di << aStr << " ";
2874 }
2875 di << "\n";
2876 }
2877 else {
586db386 2878 di << "List is empty\n";
d585e74e 2879 }
2880 return 0;
2881 }
586db386 2882 di << "DDataStd_GetExtStringList: Error\n";
d585e74e 2883 return 1;
2884}
2885
2886//=======================================================================
5a1271c8 2887//function : DDataStd_GetReferenceList (DF, entry [, guid])
d585e74e 2888//=======================================================================
2889static Standard_Integer DDataStd_GetReferenceList (Draw_Interpretor& di,
2890 Standard_Integer nb,
2891 const char** arg)
2892{
5a1271c8 2893 if (nb >= 3)
d585e74e 2894 {
2895 Handle(TDF_Data) DF;
2896 if (!DDF::GetDF(arg[1],DF))
5a1271c8 2897 return 1;
d585e74e 2898
2899 TDF_Label label;
2900 if ( !DDF::FindLabel(DF, arg[2], label) )
2901 {
2902 di << "No label for entry" << "\n";
2903 return 1;
2904 }
5a1271c8 2905 Standard_GUID aGuid;
2906 if(nb == 4) {
2907 if (Standard_GUID::CheckGUIDFormat(arg[3]))
2908 aGuid = Standard_GUID(arg[3]);
2909 else {
2910 di << "Wrong GUID format" << "\n";
2911 return 1;
2912 }
2913 } else
2914 aGuid = TDataStd_ReferenceList::GetID();
2915
d585e74e 2916 Handle(TDataStd_ReferenceList) A;
5a1271c8 2917 if ( !label.FindAttribute(aGuid, A) )
d585e74e 2918 {
5a1271c8 2919 di << "There is no TDataStd_ReferenceList [with the specified guid] at the label" << "\n";
d585e74e 2920 return 1;
2921 }
5a1271c8 2922
d585e74e 2923 const TDF_LabelList& aList = A->List();
2924 Standard_Boolean isEmpty = (aList.Extent() > 0) ? Standard_False : Standard_True;
2925 if(!isEmpty) {
2926 TDF_ListIteratorOfLabelList itr(aList);
2927 for (; itr.More(); itr.Next())
2928 {
2929 const TDF_Label& aLabel = itr.Value();
2930 if (!aLabel.IsNull()) {
2931 TCollection_AsciiString entry;
2932 TDF_Tool::Entry(aLabel, entry);
2933 di << entry.ToCString() << " ";
2934 }
2935 }
2936 di << "\n";
2937 } else
586db386 2938 di << "List is empty\n";
d585e74e 2939 return 0;
2940 }
586db386 2941 di << "DDataStd_GetReferenceList: Error\n";
d585e74e 2942 return 1;
2943}
2944//
2945//=======================================================================
7fd59977 2946//function : SetIntPackedMap (DF, entry, isDelta, key1, key2, ...
2947//=======================================================================
2948
2949static Standard_Integer DDataStd_SetIntPackedMap (Draw_Interpretor& di,
2950 Standard_Integer nb,
2951 const char** arg)
2952{
2953
2954 if (nb > 4) {
2955 Handle(TDF_Data) DF;
2956 if (!DDF::GetDF(arg[1],DF)) return 1;
2957 TDF_Label aLabel;
2958 DDF::AddLabel(DF, arg[2], aLabel);
dde68833 2959 Standard_Boolean isDelta = Draw::Atoi(arg[3]) != 0;
7fd59977 2960 Standard_Integer aNum = nb - 4;
2961 Handle(TDataStd_IntPackedMap) anAtt;
2962 if(!aLabel.FindAttribute(TDataStd_IntPackedMap::GetID(), anAtt))
2963 anAtt = TDataStd_IntPackedMap::Set(aLabel, isDelta);
2964 if(anAtt.IsNull()) {
2965 di << "IntPackedMap attribute is not found or not set" << "\n";
2966 return 1;}
2967
2968 Standard_Integer j = 4;
2969 TColStd_PackedMapOfInteger aMap;
2970 for(Standard_Integer i = 1; i<=aNum; i++) {
91322f44 2971 aMap.Add (Draw::Atoi(arg[j]));
7fd59977 2972 j++;
2973 }
2974 const Handle(TColStd_HPackedMapOfInteger)& aHMap = new TColStd_HPackedMapOfInteger(aMap);
2975 anAtt->ChangeMap(aHMap);
2976 cout << "Map extent = " << anAtt->Extent()<<endl;
2977 return 0;
2978 }
586db386 2979 di << "DDataStd_SetIntPackedMap : Error\n";
7fd59977 2980 return 1;
2981}
2982
2983//=======================================================================
2984//function : GetIntPackedMap (DF, entry )
2985//=======================================================================
2986
2987static Standard_Integer DDataStd_GetIntPackedMap (Draw_Interpretor& di,
2988 Standard_Integer nb,
2989 const char** arg)
2990{
2991
2992 if (nb == 3) {
2993 Handle(TDF_Data) DF;
2994 if (!DDF::GetDF(arg[1],DF)) return 1;
2995 TDF_Label aLabel;
2996 DDF::AddLabel(DF, arg[2], aLabel);
2997 Handle(TDataStd_IntPackedMap) anAtt;
2998 if(!aLabel.FindAttribute(TDataStd_IntPackedMap::GetID(), anAtt)) {
2999 di << "IntPackedMap attribute is not found or not set" << "\n";
3000 return 1;}
3001//
3002 const TColStd_PackedMapOfInteger& aMap = anAtt->GetMap();
3003 TColStd_MapIteratorOfPackedMapOfInteger itr(aMap);
3004 for (Standard_Integer j = 1; itr.More(); itr.Next(),j++){
3005 Standard_Integer aKey(itr.Key());
f7b4312f 3006 di << aKey << " ";
7fd59977 3007 }
3008 return 0;
3009 }
586db386 3010 di << "DDataStd_GetIntPackedMap : Error\n";
7fd59977 3011 return 1;
3012}
3013
3014
3015//=======================================================================
3016//function : ChangeIntPackedMap_Add (DF, entry, Key1, Key2,... )
3017//=======================================================================
3018static Standard_Integer DDataStd_ChangeIntPackedMap_Add (Draw_Interpretor& di,
3019 Standard_Integer nb,
3020 const char** arg)
3021{
3022
3023 if( nb >= 4 ) {
3024 Handle(TDF_Data) DF;
3025 if (!DDF::GetDF(arg[1],DF)) return 1;
3026 TDF_Label label;
3027 if( !DDF::FindLabel(DF, arg[2], label) ) {
3028 di << "No label for entry" << "\n";
3029 return 1;
3030 }
3031
3032 Handle(TDataStd_IntPackedMap) A;
3033 if ( !label.FindAttribute(TDataStd_IntPackedMap::GetID(), A) ) {
3034 di << "There is no TDataStd_IntPackedMap at label" << "\n";
3035 return 1;
3036 }
3037
3038 Standard_Integer i, aNum = nb - 3;
3039 Handle(TColStd_HPackedMapOfInteger) aHMap = A->GetHMap();
3040 Handle(TColStd_HPackedMapOfInteger) ahMap = new TColStd_HPackedMapOfInteger();
3041 if(!aHMap.IsNull()) {
3042 ahMap->ChangeMap().Assign(aHMap->Map());
3043 for(i=1; i<=aNum;i++) {
5a1271c8 3044 Standard_Integer val = Draw::Atoi(arg[i+2]);
3045 if(!ahMap->Map().Contains(val))
3046 ahMap->ChangeMap().Add(val);
7fd59977 3047 }
3048
3049 A->ChangeMap(ahMap);
3050 }
3051 return 0;
3052 }
586db386 3053 di << "DDataStd_ChangeIntPackedMap_Add: Error\n";
7fd59977 3054 return 0;
3055}
3056
3057
3058//=======================================================================
3059//function : ChangeIntPackedMap_Rem (DF, entry, Key1, Key2,... )
3060//=======================================================================
3061static Standard_Integer DDataStd_ChangeIntPackedMap_Rem (Draw_Interpretor& di,
3062 Standard_Integer nb,
3063 const char** arg)
3064{
3065
3066 if( nb >= 4 ) {
3067 Handle(TDF_Data) DF;
3068 if (!DDF::GetDF(arg[1],DF)) return 1;
3069 TDF_Label label;
3070 if( !DDF::FindLabel(DF, arg[2], label) ) {
3071 di << "No label for entry" << "\n";
3072 return 1;
3073 }
3074
3075 Handle(TDataStd_IntPackedMap) A;
3076 if ( !label.FindAttribute(TDataStd_IntPackedMap::GetID(), A) ) {
3077 di << "There is no TDataStd_IntPackedMap at label" << "\n";
3078 return 1;
3079 }
3080
3081 Standard_Integer i, aNum = nb - 3;
3082 Handle(TColStd_HPackedMapOfInteger) aHMap = A->GetHMap();
3083 Handle(TColStd_HPackedMapOfInteger) ahMap = new TColStd_HPackedMapOfInteger();
3084 if(!aHMap.IsNull()) {
3085 ahMap->ChangeMap().Assign(aHMap->Map());
3086 for(i=1; i<=aNum;i++) {
5a1271c8 3087 Standard_Integer val = Draw::Atoi(arg[i+2]);
3088 if(ahMap->Map().Contains(val))
3089 ahMap->ChangeMap().Remove(val);
7fd59977 3090 }
3091
3092 A->ChangeMap(ahMap);
3093 }
3094 return 0;
3095 }
586db386 3096 di << "DDataStd_ChangeIntPackedMap_Rem: Error\n";
7fd59977 3097 return 0;
3098}
3099
3100//=======================================================================
3101//function : ChangeIntPackedMap_AddRem (DF, entry, Key1, Key2,... )
3102// : if Keyi exist in map - remove it, if no - add
3103//=======================================================================
3104static Standard_Integer DDataStd_ChangeIntPackedMap_AddRem (Draw_Interpretor& di,
3105 Standard_Integer nb,
3106 const char** arg)
3107{
3108
3109 if( nb >= 4 ) {
3110 Handle(TDF_Data) DF;
3111 if (!DDF::GetDF(arg[1],DF)) return 1;
3112 TDF_Label label;
3113 if( !DDF::FindLabel(DF, arg[2], label) ) {
3114 di << "No label for entry" << "\n";
3115 return 1;
3116 }
3117
3118 Handle(TDataStd_IntPackedMap) A;
3119 if ( !label.FindAttribute(TDataStd_IntPackedMap::GetID(), A) ) {
3120 di << "There is no TDataStd_IntPackedMap at label" << "\n";
3121 return 1;
3122 }
3123
3124 Standard_Integer i, aNum = nb - 3;
3125 Handle(TColStd_HPackedMapOfInteger) aHMap = A->GetHMap();
3126 Handle(TColStd_HPackedMapOfInteger) ahMap = new TColStd_HPackedMapOfInteger();
3127 if(!aHMap.IsNull()) {
3128 ahMap->ChangeMap().Assign(aHMap->Map());
3129 for(i=1; i<=aNum;i++) {
5a1271c8 3130 Standard_Integer val = Draw::Atoi(arg[i+2]);
3131 if(!ahMap->Map().Contains(val))
3132 ahMap->ChangeMap().Add(val);
3133 else
3134 ahMap->ChangeMap().Remove(val);
7fd59977 3135 }
3136
3137 A->ChangeMap(ahMap);
3138 }
3139 return 0;
3140 }
586db386 3141 di << "DDataStd_ChangeIntPackedMap_AddRem: Error\n";
7fd59977 3142 return 0;
3143}
3144
3145//=======================================================================
3146//function : SetIntPHugeMap (DF, entry, isDelta Num)
3147//=======================================================================
3148
3149static Standard_Integer DDataStd_SetIntPHugeMap (Draw_Interpretor& di,
3150 Standard_Integer nb,
3151 const char** arg)
3152{
3153
3154 if (nb > 4) {
3155 Handle(TDF_Data) DF;
3156 if (!DDF::GetDF(arg[1],DF)) return 1;
3157 TDF_Label aLabel;
3158 DDF::AddLabel(DF, arg[2], aLabel);
dde68833 3159 Standard_Boolean isDelta = Draw::Atoi(arg[3]) != 0;
91322f44 3160 Standard_Integer aNum = Draw::Atoi(arg[4]);
7fd59977 3161 Handle(TDataStd_IntPackedMap) anAtt;
3162 if(!aLabel.FindAttribute(TDataStd_IntPackedMap::GetID(), anAtt))
3163 anAtt = TDataStd_IntPackedMap::Set(aLabel, isDelta);
3164 if(anAtt.IsNull()) {
3165 di << "IntPackedMap attribute is not found or not set" << "\n";
3166 return 1;}
3167
3168 TColStd_PackedMapOfInteger aMap;
3169 for(Standard_Integer i = 1; i<=aNum; i++) {
3170 aMap.Add (i);
3171 }
3172 const Handle(TColStd_HPackedMapOfInteger)& aHMap = new TColStd_HPackedMapOfInteger(aMap);
3173 anAtt->ChangeMap(aHMap);
3174 cout << "Map extent = " << anAtt->Extent()<<endl;
3175 return 0;
3176 }
586db386 3177 di << "DDataStd_SetIntPHugeMap : Error\n";
7fd59977 3178 return 1;
3179}
3180
3181//=======================================================================
3182//function : SetNDataIntegers (DF, entry , Num
3183//=======================================================================
3184
3185static Standard_Integer DDataStd_SetNDataIntegers2 (Draw_Interpretor& di,
3186 Standard_Integer nb,
3187 const char** arg)
3188{
3189
3190 if (nb ==4) {
3191 Handle(TDF_Data) DF;
3192 if (!DDF::GetDF(arg[1],DF)) return 1;
3193 TDF_Label aLabel;
3194 DDF::AddLabel(DF, arg[2], aLabel);
91322f44 3195 Standard_Integer aNumP = Draw::Atoi(arg[3]), j;
7fd59977 3196 Handle(TDataStd_NamedData) anAtt;
3197 if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt))
3198 anAtt = TDataStd_NamedData::Set(aLabel);
3199 if(anAtt.IsNull()) {
3200 di << "NamedData attribute is not found or not set" << "\n";
3201 return 1;}
3202
3203 j = 1111;
3204 TCollection_ExtendedString aKey("Key_");
3205 for(Standard_Integer i = 1; i<=aNumP; i++) {
3206 TCollection_ExtendedString key = aKey + i;
3207 Standard_Integer aVal = j+i;
3208 anAtt->SetInteger(key, aVal);
3209 j +=1;
3210 }
3211 return 0;
3212 }
586db386 3213 di << "DDataStd_SetNDataIntegers2 : Error\n";
7fd59977 3214 return 1;
3215}
3216//================
3217//=======================================================================
3218//function : SetNDataIntArrays2 (DF, entry , key, NumOfArElem )
3219//=======================================================================
3220
3221static Standard_Integer DDataStd_SetNDataIntAr2 (Draw_Interpretor& di,
3222 Standard_Integer nb,
3223 const char** arg)
3224{
3225
3226 if (nb == 5) {
3227 Handle(TDF_Data) DF;
3228 if (!DDF::GetDF(arg[1],DF)) return 1;
3229 TDF_Label aLabel;
3230 DDF::AddLabel(DF, arg[2], aLabel);
3231
3232 Standard_Integer j;
3233 TCollection_ExtendedString aKey(arg[3]);
91322f44 3234 Standard_Integer aNum = Draw::Atoi(arg[4]);
7fd59977 3235 if (aNum <= 0) return 1;
3236 Handle(TDataStd_NamedData) anAtt;
3237 if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt))
3238 anAtt = TDataStd_NamedData::Set(aLabel);
3239 if(anAtt.IsNull()) {
3240 cout<< "NamedData attribute is not found or not set" << endl;
3241 return 1;}
3242
3243 j = 15;
3244 Handle(TColStd_HArray1OfInteger) anArr = new TColStd_HArray1OfInteger(1, aNum);
3245 for(Standard_Integer i = 1; i<=aNum; i++) {
3246 Standard_Integer aVal = j++;
3247 anArr->SetValue(i, aVal);
3248 j++;
3249 }
3250 anAtt->SetArrayOfIntegers(aKey, anArr);
3251 return 0;
3252 }
586db386 3253 di << "DDataStd_SetNDataIntArrays2 : Error\n";
7fd59977 3254 return 1;
3255}
3256
3257
3258//=======================================================================
fa53efef 3259//function : SetAsciiString(DF, entry, String[, guid])
7fd59977 3260//=======================================================================
3261
3262static Standard_Integer DDataStd_SetAsciiString (Draw_Interpretor& di,
3263 Standard_Integer nb,
3264 const char** arg)
3265{
3266
fa53efef 3267 if (nb == 4 || nb == 5) {
7fd59977 3268 Handle(TDF_Data) DF;
3269 if (!DDF::GetDF(arg[1],DF)) return 1;
3270 TDF_Label aLabel;
3271 DDF::AddLabel(DF, arg[2], aLabel);
3272 TCollection_AsciiString aString(arg[3]);
5a1271c8 3273 Standard_GUID aGuid (TDataStd_AsciiString::GetID());
3274 if(nb == 5) {
3275 if (!Standard_GUID::CheckGUIDFormat(arg[4])) {
fa53efef 3276 di<<"DDataStd_SetAsciiString: The format of GUID is invalid\n";
3277 return 1;
5a1271c8 3278 }
3279 aGuid = Standard_GUID (arg[4]);
3280 }
fa53efef 3281
3282 Handle(TDataStd_AsciiString) anAtt = TDataStd_AsciiString::Set(aLabel, aGuid, aString);
7fd59977 3283 if(anAtt.IsNull()) {
3284 di << "AsciiString attribute is not found or not set" << "\n";
fa53efef 3285 return 1;
5a1271c8 3286 }
7fd59977 3287
7fd59977 3288 cout << "String = " << anAtt->Get().ToCString() << " is kept in DF" << endl;
3289 return 0;
3290 }
586db386 3291 di << "DDataStd_SetAsciiString : Error\n";
7fd59977 3292 return 1;
3293}
3294//
3295//=======================================================================
fa53efef 3296//function : GetAsciiString(DF, entry[, guid] )
7fd59977 3297//=======================================================================
3298
3299static Standard_Integer DDataStd_GetAsciiString (Draw_Interpretor& di,
3300 Standard_Integer nb,
3301 const char** arg)
3302{
fa53efef 3303 if (nb == 3 || nb == 4) {
7fd59977 3304 Handle(TDF_Data) DF;
3305 if (!DDF::GetDF(arg[1],DF)) return 1;
fa53efef 3306 TDF_Label aLabel;
3307 DDF::FindLabel(DF, arg[2], aLabel);
3308 if(aLabel.IsNull()) di << "Label is not found" << "\n";
3309 Standard_GUID aGuid (TDataStd_AsciiString::GetID());
3310 if(nb == 4) {
3311 if (!Standard_GUID::CheckGUIDFormat(arg[3])) {
3312 di<<"DDataStd_GetAsciiString: The format of GUID is invalid\n";
3313 return 1;
5a1271c8 3314 }
3315 aGuid = Standard_GUID(arg[3]);
3316 }
3317 Handle(TDataStd_AsciiString) anAtt;
3318 if( !aLabel.FindAttribute(aGuid, anAtt) ) {
7fd59977 3319 cout << "AsciiString attribute is not found or not set" << endl;
5a1271c8 3320 return 1;
3321 }
fa53efef 3322
3323#ifdef DEB_DDataStd
3324 cout << "String = " << anAtt->Get().ToCString() << endl;
3325#endif
3326 di << anAtt->Get().ToCString();
7fd59977 3327 return 0;
3328 }
586db386 3329 di << "DDataStd_GetAsciiString : Error\n";
7fd59977 3330 return 1;
3331}
3332
3333//=======================================================================
3334//function : SetNDataIntegers (DF, entry , Num, key1, val1, ...
3335//=======================================================================
3336
3337static Standard_Integer DDataStd_SetNDataIntegers (Draw_Interpretor& di,
3338 Standard_Integer nb,
3339 const char** arg)
3340{
3341
3342 if (nb >=6) {
3343 Handle(TDF_Data) DF;
3344 if (!DDF::GetDF(arg[1],DF)) return 1;
3345 TDF_Label aLabel;
3346 DDF::AddLabel(DF, arg[2], aLabel);
3347//
3348// TCollection_ExtendedString aString("123456789 0_abcde");
3349// Standard_Integer aPos = aString.Search(" ");
3350// cout << "From Start = " <<aPos<<endl;
3351// aPos = aString.SearchFromEnd(" ");
3352// cout << "From Start = " <<aPos<<endl;
3353// TCollection_ExtendedString aValue = aString.Split(aPos);
3354// cout << "Value = |"<<aValue<<endl;
3355// cout << "aKey = " << aString << "|"<<endl;
3356//
91322f44 3357 Standard_Integer aNumP = Draw::Atoi(arg[3]), j;
7fd59977 3358 Handle(TDataStd_NamedData) anAtt;
3359 if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt))
3360 anAtt = TDataStd_NamedData::Set(aLabel);
3361 if(anAtt.IsNull()) {
3362 di << "NamedData attribute is not found or not set" << "\n";
3363 return 1;}
3364
3365 j = 4;
3366 for(Standard_Integer i = 1; i<=aNumP; i++) {
3367 TCollection_ExtendedString aKey(arg[j]);
91322f44 3368 Standard_Integer aVal = Draw::Atoi(arg[j+1]);
7fd59977 3369 anAtt->SetInteger(aKey, aVal);
3370 j +=2;
3371 }
3372 return 0;
3373 }
586db386 3374 di << "DDataStd_SetNDataIntegers : Error\n";
7fd59977 3375 return 1;
3376}
3377
3378
3379//=======================================================================
3380//function : GetNDIntegers(DF, entry )
3381//=======================================================================
3382static Standard_Integer DDataStd_GetNDIntegers (Draw_Interpretor& di,
3383 Standard_Integer nb,
3384 const char** arg)
3385{
3386
3387 if (nb == 3) {
3388 Handle(TDF_Data) DF;
3389 if (!DDF::GetDF(arg[1],DF)) return 1;
3390 TDF_Label aLabel;
3391 if(!DDF::FindLabel(DF, arg[2], aLabel)) return 1;
3392
3393
3394 Handle(TDataStd_NamedData) anAtt;
3395 if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt)) {
3396 cout << "NamedData attribute is not found or not set" << endl;
3397 return 1;}
3398 cout <<endl;
3399 cout <<"NamedData attribute at Label = " << arg[2] <<endl;
3400 const TColStd_DataMapOfStringInteger& aMap = anAtt->GetIntegersContainer();
3401 TColStd_DataMapIteratorOfDataMapOfStringInteger itr(aMap);
3402 for (; itr.More(); itr.Next()){
3403 TCollection_ExtendedString aKey(itr.Key());
3404 TCollection_AsciiString aStr(aKey,'?');
3405 Standard_Integer aValue = itr.Value();
3406 cout << "Key = " << aStr.ToCString() << " Value = " <<aValue<<endl;;
3407 }
3408
3409 return 0;
3410 }
586db386 3411 di << "DDataStd_GetNDIntegers : Error\n";
7fd59977 3412 return 1;
3413}
3414
3415//=======================================================================
3416//function : GetNDInteger(DF, entry, key [drawname])
3417//=======================================================================
3418static Standard_Integer DDataStd_GetNDInteger (Draw_Interpretor& di,
5a1271c8 3419 Standard_Integer nb,
3420 const char** arg)
3421{
7fd59977 3422
3423 if (nb >=4) {
3424 Handle(TDF_Data) DF;
3425 if (!DDF::GetDF(arg[1],DF)) return 1;
3426 TDF_Label aLabel;
3427 if(!DDF::FindLabel(DF, arg[2], aLabel)) return 1;
3428
3429
3430 Handle(TDataStd_NamedData) anAtt;
3431 if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt)) {
3432 cout << "NamedData attribute is not found or not set" << endl;
3433 return 1;}
3434