0028428: BinMNaming_NamedShapeDriver fails if there are no nodes in NamedShape
[occt.git] / src / DDataStd / DDataStd_BasicCommands.cxx
1 // Created on: 1997-07-30
2 // Created by: Denis PASCAL
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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
35 #include <BRep_Tool.hxx>
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>
56 #include <TDataXtd_Triangulation.hxx>
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>
64 #include <TDataStd_BooleanArray.hxx>
65 #include <TDataStd_RealArray.hxx>
66 #include <TDataStd_BooleanList.hxx>
67 #include <TDataStd_IntegerList.hxx>
68 #include <TDataStd_RealList.hxx>
69 #include <TDataStd_Variable.hxx>
70 #include <TDataStd_ExtStringArray.hxx>
71 #include <TDF_ChildIterator.hxx>
72 #include <TDF_Tool.hxx>
73
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>
95 #include <TDataStd_ListIteratorOfListOfByte.hxx>
96 #include <TColStd_ListIteratorOfListOfInteger.hxx>
97 #include <TColStd_ListIteratorOfListOfReal.hxx>
98 #include <TDataStd_ReferenceArray.hxx>
99 #include <TDataStd_ExtStringList.hxx>
100 #include <TDataStd_ReferenceList.hxx>
101 #include <TDF_ListIteratorOfLabelList.hxx>
102 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
103 #define DEB_DDataStd
104
105 //=======================================================================
106 //function : DDataStd_SetInteger
107 //purpose  : SetInteger (DF, entry, value, [,guid])
108 //=======================================================================
109
110 static Standard_Integer DDataStd_SetInteger (Draw_Interpretor& di,
111                                               Standard_Integer nb, 
112                                               const char** arg) 
113 {     
114   if (nb >= 4) {    
115     Handle(TDF_Data) DF;
116     if (!DDF::GetDF(arg[1],DF)) return 1;
117     TDF_Label L;
118     DDF::AddLabel(DF, arg[2], L);
119         if(nb == 4) 
120       TDataStd_Integer::Set(L,Draw::Atoi(arg[3]));  
121         else {  
122           if (!Standard_GUID::CheckGUIDFormat(arg[4])) {
123         di<<"DDataStd_SetInteger: The format of GUID is invalid\n";
124         return 1;
125           }
126           Standard_GUID guid(arg[4]);
127           TDataStd_Integer::Set(L, guid, Draw::Atoi(arg[3]));  
128      }
129     return 0;
130   }
131   di << "DDataStd_SetInteger : Error\n";
132   return 1;
133 }
134
135 //=======================================================================
136 //function : DDataStd_SetReal
137 //purpose  : SetReal (DF, entry, value [,guid])
138 //=======================================================================
139
140 static Standard_Integer DDataStd_SetReal (Draw_Interpretor& di,
141                                            Standard_Integer nb, 
142                                            const char** arg) 
143 {   
144   if (nb >= 4) {    
145     Handle(TDF_Data) DF;
146     if (!DDF::GetDF(arg[1],DF)) return 1;
147     TDF_Label L;
148     DDF::AddLabel(DF, arg[2], L);
149         if(nb == 4) 
150       TDataStd_Real::Set(L,Draw::Atof(arg[3]));  
151         else {  
152           if (!Standard_GUID::CheckGUIDFormat(arg[4])) {
153         di<<"DDataStd_SetReal: The format of GUID is invalid\n";
154         return 1;
155           }
156           Standard_GUID guid(arg[4]); 
157           TDataStd_Real::Set(L, guid, Draw::Atof(arg[3]));  
158      }
159         return 0;
160         }
161   di << "DDataStd_SetReal : Error\n";
162   return 1;
163 }
164
165
166
167 //=======================================================================
168 //function : DDataStd_SetReference
169 //purpose  : SetReference (DF, entry, reference)
170 //=======================================================================
171
172 static Standard_Integer DDataStd_SetReference (Draw_Interpretor& di,
173                                                Standard_Integer nb, 
174                                                const char** arg) 
175 {   
176   if (nb == 4) {    
177     Handle(TDF_Data) DF;
178     if (!DDF::GetDF(arg[1],DF)) return 1;
179     TDF_Label L;
180     DDF::AddLabel(DF, arg[2], L);  
181     TDF_Label LREF;
182     if (!DDF::FindLabel(DF,arg[3],LREF)) return 1;
183     TDF_Reference::Set(L,LREF);  
184     return 0;
185   } 
186   di << "DDataStd_SetReference : Error\n";
187   return 1;
188 }
189
190
191 //=======================================================================
192 //function : DDataStd_SetComment
193 //purpose  : SetComment (DF, entry, Comment)
194 //=======================================================================
195
196 static Standard_Integer DDataStd_SetComment (Draw_Interpretor& di,
197                                                Standard_Integer nb, 
198                                                const char** arg) 
199 {   
200   if (nb == 4) {    
201     Handle(TDF_Data) DF;
202     if (!DDF::GetDF(arg[1],DF)) return 1;
203     TDF_Label L;
204     DDF::AddLabel(DF, arg[2], L);
205     TDataStd_Comment::Set(L,TCollection_ExtendedString(arg[3],Standard_True));  
206     return 0;
207   }
208   di << "DDataStd_SetComment : Error\n";
209   return 1;
210 }
211
212 //=======================================================================
213 //function : DDataStd_GetInteger
214 //purpose  : GetReal (DF, entry, [drawname][, guid])
215 //=======================================================================
216
217 static Standard_Integer DDataStd_GetInteger (Draw_Interpretor& di,
218                                               Standard_Integer nb, 
219                                               const char** arg) 
220 {     
221   if (nb == 3 || nb == 4 || nb == 5) {
222     Handle(TDF_Data) DF;
223     if (!DDF::GetDF(arg[1],DF)) return 1;
224     Handle(TDataStd_Integer) A;
225         Standard_GUID aGuid;
226         Standard_GUID aNullGuid("00000000-0000-0000-0000-000000000000");
227         Standard_Boolean isdrawname(Standard_False);
228         if(nb < 5 ) {
229       if(nb == 4) { //DF, entry, guid
230             if (Standard_GUID::CheckGUIDFormat(arg[3])) 
231           aGuid = Standard_GUID(arg[3]);
232           }
233           if(Standard_GUID::IsEqual(aGuid, aNullGuid)) {
234             isdrawname = Standard_True;
235             aGuid = TDataStd_Integer::GetID();
236           }
237         } else if(nb == 5) {
238           isdrawname = Standard_True; 
239           if (Standard_GUID::CheckGUIDFormat(arg[4])) 
240         aGuid = Standard_GUID(arg[4]);
241           else {
242         di<<"DDataStd_GetInteger: The format of GUID is invalid\n";
243         return 1;
244           }
245         } 
246                   
247     if (!DDF::Find(DF,arg[2],aGuid,A)) return 1;
248     if (nb == 4 && isdrawname) Draw::Set(arg[3],A->Get());
249     else         Draw::Set(arg[2],A->Get());
250     di << A->Get();
251     return 0;
252   }
253   di << "DDataStd_GetInteger : Error\n";
254   return 1;
255 }
256
257 //=======================================================================
258 //function : DDataStd_GetReal
259 //purpose  : GetReal (DF, entry, [drawname][, guid])
260 //=======================================================================
261
262 static Standard_Integer DDataStd_GetReal (Draw_Interpretor& di,
263                                           Standard_Integer nb, 
264                                           const char** arg) 
265 {  
266   if (nb == 3 || nb == 4 || nb == 5) {
267     Handle(TDF_Data) DF;
268     if (!DDF::GetDF(arg[1],DF)) return 1;
269     Handle(TDataStd_Real) A;
270         Standard_GUID aGuid;
271     Standard_GUID aNullGuid("00000000-0000-0000-0000-000000000000");
272         Standard_Boolean isdrawname(Standard_False);
273     if(nb < 5 ) {
274           if(nb == 4) {
275             if (Standard_GUID::CheckGUIDFormat(arg[3])) 
276           aGuid = Standard_GUID(arg[3]);
277           }
278           if(Standard_GUID::IsEqual(aGuid, aNullGuid)) {
279             isdrawname = Standard_True;
280             aGuid = TDataStd_Real::GetID();
281           }
282         }
283         else if(nb == 5) {
284           isdrawname = Standard_True; 
285           if (Standard_GUID::CheckGUIDFormat(arg[4])) 
286         aGuid = Standard_GUID(arg[4]);
287           else {
288         di<<"DDataStd_GetReal: The format of GUID is invalid\n";
289         return 1;
290           }
291         } 
292     if (!DDF::Find(DF,arg[2],aGuid,A)) return 1;
293     if (nb == 4 && isdrawname) Draw::Set(arg[3],A->Get());
294     else         Draw::Set(arg[2],A->Get());
295     di << A->Get();
296     return 0;
297   }
298   di << "DDataStd_GetReal : Error\n";
299   return 1;
300 }
301
302
303 //=======================================================================
304 //function : DDataStd_GetReference
305 //purpose  : GetShape (DF, entry)
306 //=======================================================================
307
308 static Standard_Integer DDataStd_GetReference (Draw_Interpretor& di,
309                                                Standard_Integer nb, 
310                                                const char** arg) 
311 {  
312   if (nb == 3) {
313     Handle(TDF_Data) DF;
314     if (!DDF::GetDF(arg[1],DF)) return 1;
315     Handle(TDF_Reference) REF;
316     if (!DDF::Find(DF,arg[2],TDF_Reference::GetID(),REF)) return 1;
317     TCollection_AsciiString entry; TDF_Tool::Entry(REF->Get(),entry);
318     di << entry.ToCString();
319     return 0;
320   }
321   di << "DDataStd_GetReference : Error\n";
322   return 1;
323 }
324
325 //=======================================================================
326 //function : DDataStd_GetComment
327 //purpose  : GetShape (DF, entry)
328 //=======================================================================
329
330 static Standard_Integer DDataStd_GetComment (Draw_Interpretor& di,
331                                           Standard_Integer nb, 
332                                           const char** arg) 
333
334   if (nb == 3) {
335     Handle(TDF_Data) DF;
336     if (!DDF::GetDF(arg[1],DF)) return 1;
337     Handle(TDataStd_Comment) A;
338     if (!DDF::Find(DF,arg[2],TDataStd_Comment::GetID(),A)) return 1;
339     TCollection_AsciiString s(A->Get(),'?');
340     di << A->Get().ToExtString();
341     return 0;
342   }
343   di << "DDataStd_GetComment : Error\n";
344   return 1;
345 }
346
347
348
349 //=======================================================================
350 //function :
351 //purpose  : Self (document,label)
352 //=======================================================================
353
354 static Standard_Integer DDataStd_Self (Draw_Interpretor& di,
355                                        Standard_Integer nb, 
356                                        const char** arg) 
357 {    
358   TCollection_AsciiString s;  
359   if (nb == 3) {  
360     Handle(TDF_Data) DF;
361     if (!DDF::GetDF(arg[1],DF)) return 1;
362     TDF_Label L;
363     if (!DDF::FindLabel(DF,arg[2],L)) return 1; 
364 //    TDataStd::MakeSelfContained(L,removed);
365 //    if (removed.IsEmpty()) cout << "noone attriburte removed" << endl;
366 //    for (TDF_ListIteratorOfAttributeList it(removed);it.More();it.Next()) {
367 //      TDF_Tool::Entry(it.Value()->Label(),s); cout  << s << " ";
368 //      cout << endl;
369 //    }
370     return 0;
371   } 
372   di << "Self : Error\n";
373   return 0;
374 }
375
376
377
378 //=======================================================================
379 //function : SetUObject (DF, entry, ObjectID)
380 //=======================================================================
381 // static Standard_Integer DDataStd_SetUObject (Draw_Interpretor&,
382 //                                            Standard_Integer nb, 
383 //                                            const char** arg) 
384 // {   
385 //   if( nb == 4 ) {
386 //     Handle(TDF_Data) DF;
387 //     if (!DDF::GetDF(arg[1],DF))  return 1;
388 //     TDF_Label label;
389 //     DDF::AddLabel(DF, arg[2], label);
390
391 //     Standard_GUID guid(arg[3]);  //"00000000-0000-0000-1111-000000000000");
392 //     TDataStd_UObject::Set(label, guid);
393 //     return 0;
394 //   }
395
396 //   cout << "Wrong arguments"  << endl;  
397 //   return 1;
398 // } 
399
400 //=======================================================================
401 //function : SetUAttribute (DF, entry, LocalID)
402 //=======================================================================
403 static Standard_Integer DDataStd_SetUAttribute (Draw_Interpretor& di,
404                                                 Standard_Integer nb, 
405                                                 const char** arg) 
406 {   
407   if( nb == 4 ) { 
408     Handle(TDF_Data) DF;
409     if (!DDF::GetDF(arg[1],DF))  return 1; 
410     TDF_Label label;
411     DDF::AddLabel(DF, arg[2], label);
412
413     Standard_GUID guid(arg[3]);  //"00000000-0000-0000-2222-000000000000");
414     TDataStd_UAttribute::Set(label, guid);
415     return 0; 
416   }
417
418   di << "Wrong arguments"  << "\n";  
419   return 1; 
420
421
422 //=======================================================================
423 //function : GetUAttribute (DF, entry, LoaclID)
424 //=======================================================================
425 static Standard_Integer DDataStd_GetUAttribute (Draw_Interpretor& di,
426                                                 Standard_Integer nb, 
427                                                 const char** arg) 
428 {   
429   if( nb == 4 ) {  
430     Handle(TDF_Data) DF;
431     if (!DDF::GetDF(arg[1],DF)) return 1; 
432     TDF_Label label;
433     if( !DDF::FindLabel(DF, arg[2], label) ) {
434      di << "No label for entry"  << "\n";
435      return 1;
436     }
437     Standard_GUID guid(arg[3]);  //"00000000-0000-0000-2222-000000000000");
438
439     Handle(TDataStd_UAttribute) UA;    
440     if( !label.FindAttribute(guid, UA) ) {
441       di << "No UAttribute Attribute on label"   << "\n";
442     }
443     else {
444       char *aStrGUID = new char[37];
445       UA->ID().ToCString(aStrGUID);
446       di << aStrGUID;
447     }
448     return 0;  
449   }
450
451   di << "Wrong arguments"  << "\n";  
452   return 1;  
453
454
455
456 //=======================================================================
457 //function : CheckUObject (DF, entry, ObjectID)
458 //=======================================================================
459 // static Standard_Integer DDataStd_CheckUObject (Draw_Interpretor&,
460 //                                           Standard_Integer nb, 
461 //                                           const char** arg) 
462 // {   
463 //   if( nb == 4 ) {   
464 //     Handle(TDF_Data) DF;
465 //     if (!DDF::GetDF(arg[1],DF)) return 1;  
466 //     TDF_Label label;
467 //     if( !DDF::FindLabel(DF, arg[2], label) ) { 
468 //      cout << "No label for entry"  << endl;
469 //      return 1; 
470 //     }
471 //     Handle(TDataStd_Object) O;
472 //     Handle(TDataStd_UObject) UO;    
473 //     Standard_GUID guidUO(arg[3]);
474
475 //     if( !label.FindAttribute( TDataStd_Object::GetID(), O) ) {
476 //       cout << "No Object Attribute on label"   << endl;
477 //     }
478 //     else { 
479 //       cout << "UObject is found with ObjectID = ";
480 //       O->Find(label, guidUO, UO);
481 //       UO->ObjectID().ShallowDump(cout);
482 //       cout << endl; 
483 //     }
484 //     return 0;   
485 //   }
486
487 //   cout << "Wrong arguments"  << endl;  
488 //   return 1;  
489 // }
490
491
492 //=======================================================================
493 //function : SetIntArray (DF, entry , isDelta, From, To,  elmt1, elmt2, ...
494 //=======================================================================
495 static Standard_Integer DDataStd_SetIntArray (Draw_Interpretor& di,
496                                               Standard_Integer nb,
497                                               const char** arg) 
498 {
499   Handle(TDF_Data) DF;
500   if (!DDF::GetDF(arg[1],DF))  return 1; 
501   TDF_Label label;
502   DDF::AddLabel(DF, arg[2], label);
503   Standard_Boolean isDelta = Draw::Atoi(arg[3]) != 0;
504   Standard_Integer From = Draw::Atoi(arg[4]), To = Draw::Atoi( arg[5] ), j;
505   di << "Array of Standard_Integer with bounds from = " << From  << " to = " << To  << "\n";
506   Handle(TDataStd_IntegerArray) A = TDataStd_IntegerArray::Set(label, From, To, isDelta);
507   
508   if (nb > 6) {
509     j = 6;
510     for(Standard_Integer i = From; i<=To; i++) {
511       A->SetValue(i, Draw::Atoi(arg[j]) ); 
512       j++;
513     }
514   }
515
516   return 0; 
517
518
519 //=======================================================================
520 //function : SetIntArrayValue (DF, entry, index, value)
521 //=======================================================================
522 static Standard_Integer DDataStd_SetIntArrayValue (Draw_Interpretor&,
523                                                    Standard_Integer,
524                                                    const char** arg) 
525 {
526   // Get document.
527   Handle(TDF_Data) DF;
528   if (!DDF::GetDF(arg[1], DF))
529     return 1;
530
531   // Get label.
532   TDF_Label label; 
533   if (!DDF::AddLabel(DF, arg[2], label))
534     return 1;
535  
536   // Get index and value.
537   Standard_Integer index = Draw::Atoi(arg[3]);
538   Standard_Integer value = Draw::Atoi(arg[4]);
539
540   // Set new value.
541   Handle(TDataStd_IntegerArray) arr;
542   if (label.FindAttribute(TDataStd_IntegerArray::GetID(), arr))
543   {
544     arr->SetValue(index, value); 
545     return 0;
546   }
547
548   return 1;
549
550
551 //=======================================================================
552 //function : GetIntArray (DF, entry )
553 //=======================================================================
554 static Standard_Integer DDataStd_GetIntArray (Draw_Interpretor& di,
555                                               Standard_Integer, 
556                                               const char** arg) 
557 {   
558
559
560   Handle(TDF_Data) DF;
561   if (!DDF::GetDF(arg[1],DF))  return 1;  
562   TDF_Label label;
563   if( !DDF::FindLabel(DF, arg[2], label) ) {
564     di << "No label for entry"  << "\n";
565     return 1;
566   }
567  
568   Handle(TDataStd_IntegerArray) A;
569   if ( !label.FindAttribute(TDataStd_IntegerArray::GetID(), A) ) { 
570     di << "There is no TDataStd_IntegerArray under label"  << "\n";
571     return 1;
572   }
573   
574   for(Standard_Integer i = A->Lower(); i<=A->Upper(); i++){
575     //cout <<  A->Value(i)   << endl;
576     di  <<  A->Value(i);
577     if(i<A->Upper())  
578      di<<" ";
579   }
580   di<<"\n";
581   return 0; 
582
583
584 //=======================================================================
585 //function : GetIntArrayValue (DF, entry, index)
586 //=======================================================================
587 static Standard_Integer DDataStd_GetIntArrayValue (Draw_Interpretor& di,
588                                                    Standard_Integer, 
589                                                    const char** arg) 
590 {
591   Handle(TDF_Data) DF;
592   if (!DDF::GetDF(arg[1],DF))
593       return 1;
594
595   TDF_Label label;
596   if (!DDF::FindLabel(DF, arg[2], label)) {
597     di << "No label for entry"  << "\n";
598     return 1;
599   }
600  
601   Handle(TDataStd_IntegerArray) A;
602   if ( !label.FindAttribute(TDataStd_IntegerArray::GetID(), A) ) { 
603     di << "There is no TDataStd_IntegerArray under label"  << "\n";
604     return 1;
605   }
606   
607   Standard_Integer index = Draw::Atoi(arg[3]);
608   if (index < A->Lower() || index > A->Upper()) {
609     di << "Index is out of range\n";
610     return 1;
611   } else {
612     di << A->Value(index) << "\n";
613   }
614
615   return 0; 
616
617
618 //=======================================================================
619 //function : ChangeIntArray (DF, entry, indx, val )
620 //=======================================================================
621 static Standard_Integer DDataStd_ChangeIntArray (Draw_Interpretor& di,
622                                               Standard_Integer nb, 
623                                               const char** arg) 
624 {   
625
626   if( nb == 5 ) {  
627     Handle(TDF_Data) DF;
628     if (!DDF::GetDF(arg[1],DF))  return 1;  
629     TDF_Label label;
630     if( !DDF::FindLabel(DF, arg[2], label) ) {
631       di << "No label for entry"  << "\n";
632       return 1;
633     }
634  
635     Handle(TDataStd_IntegerArray) A;
636     if ( !label.FindAttribute(TDataStd_IntegerArray::GetID(), A) ) { 
637       di << "There is no TDataStd_IntegerArray at label"  << "\n";
638       return 1;
639     }
640     Standard_Integer indx = Draw::Atoi(arg[3]);
641     Standard_Integer val  = Draw::Atoi(arg[4]);
642     Standard_Integer low = A->Lower(), up = A->Upper();
643     if(low <= indx && indx <= up)
644       A->SetValue(indx, val);
645     else {
646       Handle(TColStd_HArray1OfInteger) Arr = A->Array();
647       Handle(TColStd_HArray1OfInteger) arr;
648       Standard_Integer i;
649       if(indx > up) {
650         up = indx;
651         arr = new TColStd_HArray1OfInteger(low, up);
652         for(i=low; i<= Arr->Upper(); i++)
653           arr->SetValue(i, Arr->Value(i));
654         for(i=Arr->Upper()+1; i<= up; i++) {
655           if(i == up)
656             arr->SetValue(i, val);
657           else
658             arr->SetValue(i, 0);
659         }
660       } else if(indx < up) {//clip array : indx to be negative
661         up = abs(indx);
662         arr = new TColStd_HArray1OfInteger(low, up);
663         for(i=low; i< up; i++)
664           arr->SetValue(i, Arr->Value(i));
665         arr->SetValue(up, val);
666       }
667       A->ChangeArray(arr);
668     }
669     return 0;
670   }
671   di << "DDataStd_ChangeIntArray: Error\n";
672   return 0; 
673
674
675 //=======================================================================
676 //function : SetIntArrayT (DF, entry , isDelta, From, To) - for testing
677 //         : huge arrays
678 //=======================================================================
679 static Standard_Integer DDataStd_SetIntArrayTest (Draw_Interpretor& di,
680                                               Standard_Integer, 
681                                               const char** arg) 
682 {   
683
684
685   Handle(TDF_Data) DF;
686   if (!DDF::GetDF(arg[1],DF))  return 1; 
687   TDF_Label label;
688   DDF::AddLabel(DF, arg[2], label);
689   Standard_Boolean isDelta = Draw::Atoi(arg[3]) != 0;
690   Standard_Integer From = Draw::Atoi(arg[4]), To = Draw::Atoi( arg[5] ), j;
691   di << "Array of Standard_Integer with bounds from = " << From  << " to = " << To  << "\n";
692   Handle(TDataStd_IntegerArray) A = TDataStd_IntegerArray::Set(label, From, To, isDelta);
693   
694   j = 6;
695   Standard_Integer k = 100;
696   for(Standard_Integer i = From; i<=To; i++) {
697     A->SetValue(i, ++k); 
698     j++;
699   }
700
701   return 0; 
702
703
704 //=======================================================================
705 //function : SetRealArray (DF, entry , isDelta, From, To,  elmt1, elmt2, ...
706 //=======================================================================
707 static Standard_Integer DDataStd_SetRealArray (Draw_Interpretor& di,
708                                                Standard_Integer nb, 
709                                                const char** arg) 
710 {   
711
712
713   Handle(TDF_Data) DF;
714   if (!DDF::GetDF(arg[1],DF))  return 1;  
715   TDF_Label label; 
716   DDF::AddLabel(DF, arg[2], label);
717   Standard_Boolean isDelta = Draw::Atoi(arg[3]) != 0;
718  
719   Standard_Integer From = Draw::Atoi(arg[4]), To = Draw::Atoi( arg[5] ), j;
720   di << " Array of Standard_Real with bounds from = " << From  << " to = " << To  << "\n";
721   Handle(TDataStd_RealArray) A = TDataStd_RealArray::Set(label, From, To, isDelta);
722   
723   if (nb > 6) {
724     j = 6;
725     for(Standard_Integer i = From; i<=To; i++) {
726       A->SetValue(i, Draw::Atof(arg[j]) );
727       j++;
728     }
729   }
730
731   return 0;  
732
733
734 //=======================================================================
735 //function : SetRealArrayValue (DF, entry, index value)
736 //=======================================================================
737 static Standard_Integer DDataStd_SetRealArrayValue (Draw_Interpretor&,
738                                                     Standard_Integer, 
739                                                     const char** arg) 
740 {
741   // Get document.
742   Handle(TDF_Data) DF;
743   if (!DDF::GetDF(arg[1], DF))
744     return 1;
745
746   // Get label.
747   TDF_Label label; 
748   if (!DDF::AddLabel(DF, arg[2], label))
749     return 1;
750  
751   // Get index and value.
752   Standard_Integer index = Draw::Atoi(arg[3]);
753   Standard_Real    value = Draw::Atof(arg[4]);
754
755   // Set new value.
756   Handle(TDataStd_RealArray) realArray;
757   if (label.FindAttribute(TDataStd_RealArray::GetID(), realArray))
758   {
759     realArray->SetValue(index, value); 
760     return 0;
761   }
762
763   return 1;
764
765
766 //=======================================================================
767 //function : GetRealArray (DF, entry )
768 //=======================================================================
769 static Standard_Integer DDataStd_GetRealArray (Draw_Interpretor& di,
770                                                Standard_Integer, 
771                                                const char** arg) 
772 {   
773
774   Handle(TDF_Data) DF;
775   if (!DDF::GetDF(arg[1],DF))  return 1;  
776   TDF_Label label;
777   if( !DDF::FindLabel(DF, arg[2], label) ) { 
778     di << "No label for entry"  << "\n";
779     return 1; 
780   }
781  
782   Handle(TDataStd_RealArray) A;
783   if ( !label.FindAttribute(TDataStd_RealArray::GetID(), A) ) { 
784     di << "There is no TDataStd_RealArray under label"  << "\n";
785     return 1; 
786   }
787   
788   for(Standard_Integer i = A->Lower(); i<=A->Upper(); i++){
789     //cout <<  A->Value(i)   << endl; 
790     di   <<  A->Value(i);
791     if(i<A->Upper())  
792      di<<" ";
793   }  
794   di<<"\n";
795
796   return 0;  
797
798
799 //=======================================================================
800 //function : GetRealArrayValue (DF, entry, index)
801 //=======================================================================
802 static Standard_Integer DDataStd_GetRealArrayValue (Draw_Interpretor& di,
803                                                     Standard_Integer, 
804                                                     const char** arg) 
805 {
806   Handle(TDF_Data) DF;
807   if (!DDF::GetDF(arg[1],DF))
808       return 1;
809
810   TDF_Label label;
811   if (!DDF::FindLabel(DF, arg[2], label)) {
812     di << "No label for entry"  << "\n";
813     return 1;
814   }
815  
816   Handle(TDataStd_RealArray) A;
817   if ( !label.FindAttribute(TDataStd_RealArray::GetID(), A) ) { 
818     di << "There is no TDataStd_RealArray under label"  << "\n";
819     return 1;
820   }
821   
822   Standard_Integer index = Draw::Atoi(arg[3]);
823   if (index < A->Lower() || index > A->Upper()) {
824     di << "Index is out of range\n";
825     return 1;
826   } else {
827     di << A->Value(index) << "\n";
828   }
829
830   return 0; 
831
832
833 //=======================================================================
834 //function : ChangeRealArray (DF, entry, indx, val )
835 //=======================================================================
836 static Standard_Integer DDataStd_ChangeRealArray (Draw_Interpretor& di,
837                                                   Standard_Integer nb, 
838                                                   const char** arg) 
839 {   
840
841   if( nb == 5 ) {  
842     Handle(TDF_Data) DF;
843     if (!DDF::GetDF(arg[1],DF))  return 1;  
844     TDF_Label label;
845     if( !DDF::FindLabel(DF, arg[2], label) ) {
846       di << "No label for entry"  << "\n";
847       return 1;
848     }
849  
850     Handle(TDataStd_RealArray) A;
851     if ( !label.FindAttribute(TDataStd_RealArray::GetID(), A) ) { 
852       di << "There is no TDataStd_RealArray at label"  << "\n";
853       return 1;
854     }
855     Standard_Integer indx = Draw::Atoi(arg[3]);
856     Standard_Real val  = Draw::Atof(arg[4]);
857     Standard_Integer low = A->Lower(), up = A->Upper();
858     if(low <= indx && indx <= up)
859       A->SetValue(indx, val);
860     else {
861       Handle(TColStd_HArray1OfReal) Arr = A->Array();
862       Handle(TColStd_HArray1OfReal) arr;
863       Standard_Integer i;
864       if(indx > up) {
865         up = indx;
866         arr = new TColStd_HArray1OfReal(low, up);
867         for(i=low; i<= Arr->Upper(); i++)
868           arr->SetValue(i, Arr->Value(i));
869         for(i=Arr->Upper()+1; i<= up; i++) {
870           if(i == up)
871             arr->SetValue(i, val);
872           else
873             arr->SetValue(i, 0);
874         }
875       } else if(indx < up) {//clip array : indx to be negative
876         up = abs(indx);
877         arr = new TColStd_HArray1OfReal(low, up);
878         for(i=low; i< up; i++)
879           arr->SetValue(i, Arr->Value(i));
880         arr->SetValue(up, val);
881       }
882       A->ChangeArray(arr);
883     }
884     return 0;
885   }
886   di << "DDataStd_ChangeRealArray: Error\n";
887   return 0; 
888
889
890 //=======================================================================
891 //function : SetVariable (DF, entry, isConstant[0/1], units)
892 //=======================================================================
893 static Standard_Integer DDataStd_SetVariable (Draw_Interpretor& di,
894                                               Standard_Integer nb, 
895                                               const char** arg)
896 {
897   if (nb == 5)
898   {
899     Handle(TDF_Data) DF;
900     if (!DDF::GetDF(arg[1],DF))  return 1; 
901     TDF_Label label;
902     DDF::AddLabel(DF, arg[2], label);
903
904     Handle(TDataStd_Variable) aV = TDataStd_Variable::Set(label);
905
906     const char* aUnits = arg[4];
907     aV->Unit(Standard_CString(aUnits));
908
909     aV->Constant (Draw::Atoi(arg[3]) != 0);
910     return 0; 
911   }
912
913   di << "Wrong arguments\n";  
914   return 1; 
915
916
917 //=======================================================================
918 //function : GetVariable (DF, entry, [isConstant], [units])
919 //=======================================================================
920 static Standard_Integer DDataStd_GetVariable (Draw_Interpretor& di,
921                                               Standard_Integer nb, 
922                                               const char** arg)
923 {
924   if (nb == 5)
925   {
926     Handle(TDF_Data) DF;
927     if (!DDF::GetDF(arg[1],DF))  return 1; 
928     TDF_Label label;
929     DDF::AddLabel(DF, arg[2], label);
930
931     Handle(TDataStd_Variable) aV;
932     if (!label.FindAttribute(TDataStd_Variable::GetID(), aV))
933     {
934       di << "TDataStd_Variable: no such attribute\n";
935     }
936
937     Draw::Set(arg[3],TCollection_AsciiString(Standard_Integer(aV->IsConstant())).ToCString());
938     Draw::Set(arg[4],aV->Unit().ToCString());
939     return 0; 
940   }
941
942   di << "Wrong arguments\n";  
943   return 1; 
944
945
946 #include <TDataStd_Relation.hxx>
947 #include <TDataStd_Variable.hxx>
948 //=======================================================================
949 //function : SetRelation (DF, entry, expression, var1[, var2, ...])
950 //=======================================================================
951 static Standard_Integer DDataStd_SetRelation (Draw_Interpretor& di,
952                                               Standard_Integer nb, const char** arg) 
953 {
954   if (nb >= 5)
955   {
956     Handle(TDF_Data) DF;
957     if (!DDF::GetDF(arg[1],DF)) return 1;
958     TDF_Label label;
959     DDF::AddLabel(DF, arg[2], label);
960
961     Standard_CString expr (arg[3]);
962     Handle(TDataStd_Relation) aR = TDataStd_Relation::Set(label);
963     aR->SetRelation(expr);
964     Handle(TDataStd_Variable) aV;
965
966     for (Standard_Integer i = 4; i < nb; i++)
967     {
968       if (!DDF::FindLabel(DF, arg[i], label))
969       {
970         di << "No label for entry" << arg[i] << "\n";
971         return 1;
972       }
973       if (!label.FindAttribute(TDataStd_Variable::GetID(), aV))
974       {
975         di << "No TDataStd_Variable Attribute on label\n";
976         return 1;
977       }
978       aR->GetVariables().Append(aV);
979     }
980     return 0;
981   }
982   di << "Usage: SetRelation (DF, entry, expression, var1[, var2, ...])\n";
983   return 1;
984 }
985
986 //=======================================================================
987 //function : DumpRelation (DF, entry)
988 //=======================================================================
989 static Standard_Integer DDataStd_DumpRelation (Draw_Interpretor& di,
990                                                Standard_Integer nb, const char** arg) 
991 {
992   if (nb == 3)
993   {
994     Handle(TDF_Data) DF;
995     if (!DDF::GetDF(arg[1],DF)) return 1;
996
997     TDF_Label label;
998     if (!DDF::FindLabel(DF, arg[2], label))
999     {
1000       di << "No label for entry " << arg[2] << "\n";
1001       return 1;
1002     }
1003     Handle(TDataStd_Relation) aR;
1004     if (!label.FindAttribute(TDataStd_Relation::GetID(), aR))
1005     {
1006       di << "No TDataStd_Relation Attribute on label " << arg[2] << "\n";
1007       return 1;
1008     }
1009
1010     di << "Relation: expression = \"" << aR->GetRelation()
1011        << "\" variables list = (";
1012
1013     Handle(TDF_Attribute) aV;
1014     TCollection_AsciiString anEntry;
1015
1016     TDF_ListIteratorOfAttributeList it;
1017     for (it.Initialize(aR->GetVariables()); it.More(); it.Next())
1018     {
1019       aV = it.Value(); 
1020       if (!aV.IsNull())
1021       {
1022         label = aV->Label();
1023         TDF_Tool::Entry(label, anEntry);
1024         di << anEntry.ToCString() << " ";
1025       }
1026     }
1027     di << ")";
1028     return 0;
1029   }
1030   di << "Usage: DumpRelation (DF, entry)\n";
1031   return 1;
1032 }
1033
1034 #include <TFunction_Function.hxx>
1035 //=======================================================================
1036 //function : SetFunction (DF, entry, guid, failure)
1037 //=======================================================================
1038 static Standard_Integer DDataStd_SetFunction (Draw_Interpretor& di,
1039                                               Standard_Integer nb, const char** arg)
1040 {
1041   if (nb == 5)
1042   {
1043     Handle(TDF_Data) DF;
1044     if (!DDF::GetDF(arg[1],DF))  return 1;
1045     TDF_Label label;
1046     DDF::AddLabel(DF, arg[2], label);
1047
1048     Standard_GUID guid (arg[3]);
1049     Handle(TFunction_Function) aF = TFunction_Function::Set(label, guid);
1050
1051     int fail = Draw::Atoi(arg[4]);
1052     aF->SetFailure(fail);
1053
1054     return 0;
1055   }
1056
1057   di << "Wrong arguments"  << "\n";
1058   return 1;
1059 }
1060
1061 //=======================================================================
1062 //function : GetFunction (DF, entry, guid(out), failure(out))
1063 //=======================================================================
1064 static Standard_Integer DDataStd_GetFunction (Draw_Interpretor& di,
1065                                               Standard_Integer nb, const char** arg) 
1066 {   
1067   if (nb == 5)
1068   {  
1069     Handle(TDF_Data) DF;
1070     if (!DDF::GetDF(arg[1],DF)) return 1; 
1071     TDF_Label label;
1072     if (!DDF::FindLabel(DF, arg[2], label))
1073     {
1074      di << "No label for entry"  << "\n";
1075      return 1;
1076     }
1077
1078     Handle(TFunction_Function) aF;    
1079     if (!label.FindAttribute(TFunction_Function::GetID(), aF))
1080     {
1081       di << "No TFunction_Function Attribute on label\n";
1082     }
1083     else
1084     {
1085       char *aStrGUID = new char[37];
1086       aF->GetDriverGUID().ToCString(aStrGUID);
1087       Draw::Set(arg[3],aStrGUID);
1088
1089       Draw::Set(arg[4],TCollection_AsciiString(aF->GetFailure()).ToCString());
1090     }
1091     return 0;  
1092   }
1093
1094   di << "Wrong arguments"  << "\n";  
1095   return 1;  
1096
1097
1098 //=======================================================================
1099 //function : SetExtStringArray (DF, entry , isDelta, From, To,  elmt1, elmt2, ...
1100 //=======================================================================
1101 static Standard_Integer DDataStd_SetExtStringArray (Draw_Interpretor& di,
1102                                                                             Standard_Integer nb, 
1103                                                                             const char** arg) 
1104 {   
1105   Handle(TDF_Data) DF;
1106   if (!DDF::GetDF(arg[1],DF))  return 1; 
1107   TDF_Label label;
1108   DDF::AddLabel(DF, arg[2], label);
1109   Standard_Boolean isDelta = Draw::Atoi(arg[3]) != 0;
1110
1111   Standard_Integer From = Draw::Atoi(arg[4]), To = Draw::Atoi( arg[5] ), j;
1112   di << "Array of ExtString with bounds from = " << From  << " to = " << To  << "\n";
1113   Handle(TDataStd_ExtStringArray) A = TDataStd_ExtStringArray::Set(label, From, To, isDelta);
1114   
1115   if (nb > 6) {
1116     j = 6;
1117     for(Standard_Integer i = From; i<=To; i++) {
1118       A->SetValue(i, arg[j] ); 
1119       j++;
1120     }
1121   }
1122
1123   return 0; 
1124
1125
1126 //=======================================================================
1127 //function : SetExtStringArrayValue (DF, entry, index, value)
1128 //=======================================================================
1129 static Standard_Integer DDataStd_SetExtStringArrayValue (Draw_Interpretor&,
1130                                                          Standard_Integer,
1131                                                          const char** arg) 
1132 {
1133   // Get document.
1134   Handle(TDF_Data) DF;
1135   if (!DDF::GetDF(arg[1], DF))
1136     return 1;
1137
1138   // Get label.
1139   TDF_Label label; 
1140   if (!DDF::AddLabel(DF, arg[2], label))
1141     return 1;
1142  
1143   // Get index and value.
1144   Standard_Integer index = Draw::Atoi(arg[3]);
1145
1146   // Set new value.
1147   Handle(TDataStd_ExtStringArray) arr;
1148   if (label.FindAttribute(TDataStd_ExtStringArray::GetID(), arr))
1149   {
1150     arr->SetValue(index, arg[4]); 
1151     return 0;
1152   }
1153
1154   return 1;
1155
1156
1157 //=======================================================================
1158 //function : GetExtStringArray (DF, entry )
1159 //=======================================================================
1160 static Standard_Integer DDataStd_GetExtStringArray (Draw_Interpretor& di,
1161                                                     Standard_Integer, 
1162                                                     const char** arg) 
1163 {   
1164
1165
1166   Handle(TDF_Data) DF;
1167   if (!DDF::GetDF(arg[1],DF))  return 1;  
1168   TDF_Label label;
1169   if( !DDF::FindLabel(DF, arg[2], label) ) {
1170     di << "No label for entry"  << "\n";
1171     return 1;
1172   }
1173  
1174   Handle(TDataStd_ExtStringArray) A;
1175   if ( !label.FindAttribute(TDataStd_ExtStringArray::GetID(), A) ) { 
1176     di << "There is no TDataStd_ExtStringArray under label"  << "\n";
1177     return 1;
1178   }
1179   
1180   for(Standard_Integer i = A->Lower(); i<=A->Upper(); i++){
1181     TCollection_AsciiString anAsciiString(A->Value(i),'?');
1182     di << anAsciiString.ToCString();
1183     if(i<A->Upper())  
1184       di<<" ";
1185   }
1186   di<<"\n";
1187   return 0; 
1188
1189
1190 //=======================================================================
1191 //function : GetExtStringArrayValue (DF, entry, index)
1192 //=======================================================================
1193 static Standard_Integer DDataStd_GetExtStringArrayValue (Draw_Interpretor& di,
1194                                                          Standard_Integer, 
1195                                                          const char** arg) 
1196 {
1197   Handle(TDF_Data) DF;
1198   if (!DDF::GetDF(arg[1],DF))
1199       return 1;
1200
1201   TDF_Label label;
1202   if (!DDF::FindLabel(DF, arg[2], label)) {
1203     di << "No label for entry"  << "\n";
1204     return 1;
1205   }
1206  
1207   Handle(TDataStd_ExtStringArray) A;
1208   if ( !label.FindAttribute(TDataStd_ExtStringArray::GetID(), A) ) { 
1209     di << "There is no TDataStd_ExtStringArray under label"  << "\n";
1210     return 1;
1211   }
1212   
1213   Standard_Integer index = Draw::Atoi(arg[3]);
1214   if (index < A->Lower() || index > A->Upper()) {
1215     di << "Index is out of range\n";
1216     return 1;
1217   } else {
1218     const TCollection_ExtendedString& value = A->Value(index);
1219     di << value ;
1220   }
1221
1222   return 0; 
1223
1224
1225 //=======================================================================
1226 //function : ChangeExtStrArray (DF, entry, indx, val )
1227 //=======================================================================
1228 static Standard_Integer DDataStd_ChangeExtStrArray (Draw_Interpretor& di,
1229                                               Standard_Integer nb, 
1230                                               const char** arg) 
1231 {   
1232
1233   if( nb == 5 ) {  
1234     Handle(TDF_Data) DF;
1235     if (!DDF::GetDF(arg[1],DF))  return 1;  
1236     TDF_Label label;
1237     if( !DDF::FindLabel(DF, arg[2], label) ) {
1238       di << "No label for entry"  << "\n";
1239       return 1;
1240     }
1241  
1242     Handle(TDataStd_ExtStringArray) A;
1243     if ( !label.FindAttribute(TDataStd_ExtStringArray::GetID(), A) ) { 
1244       di << "There is no TDataStd_ExtStringArray at label"  << "\n";
1245       return 1;
1246     }
1247     Standard_Integer indx = Draw::Atoi(arg[3]);
1248     TCollection_ExtendedString val(arg[4]);
1249     Standard_Integer low = A->Lower(), up = A->Upper();
1250     if(low <= indx && indx <= up)
1251       A->SetValue(indx, val);//TColStd_HArray1OfExtendedString
1252     else {
1253       Handle(TColStd_HArray1OfExtendedString) Arr = A->Array();
1254       Handle(TColStd_HArray1OfExtendedString) arr;
1255       Standard_Integer i;
1256       if(indx > up) {
1257         up = indx;
1258         arr = new TColStd_HArray1OfExtendedString(low, up);
1259         for(i=low; i<= Arr->Upper(); i++)
1260           arr->SetValue(i, Arr->Value(i));
1261         for(i=Arr->Upper()+1; i<= up; i++) {
1262           if(i == up)
1263             arr->SetValue(i, val);
1264           else
1265             arr->SetValue(i, 0);
1266         }
1267       } else if(indx < up) {//clip array : indx to be negative
1268         up = abs(indx);
1269         arr = new TColStd_HArray1OfExtendedString(low, up);
1270         for(i=low; i< up; i++)
1271           arr->SetValue(i, Arr->Value(i));
1272         arr->SetValue(up, val);
1273       }
1274       A->ChangeArray(arr);
1275     }    
1276     return 0;
1277   }
1278   di << "DDataStd_ChangeExtStringArray: Error\n";
1279   return 0; 
1280
1281
1282
1283 //=======================================================================
1284 //function : DDataStd_KeepUTF
1285 //purpose  : SetUTFName (DF, fatherEntry, fileName)
1286 //=======================================================================
1287 static Standard_Integer DDataStd_KeepUTF (Draw_Interpretor& di,
1288                                                Standard_Integer nb, 
1289                                                const char** arg) 
1290 {
1291   if (nb == 4) {    
1292     Handle(TDF_Data) DF;
1293     if (!DDF::GetDF(arg[1],DF)) return 1;
1294     TDF_Label L;
1295     DDF::AddLabel(DF, arg[2], L);
1296     Standard_CString aFileName(arg[3]);
1297
1298 #ifdef _MSC_VER
1299       ifstream anIS (aFileName, ios::in | ios::binary);
1300 #else
1301       ifstream anIS (aFileName);
1302 #endif
1303     if (!anIS) {
1304       // Can not open file
1305       cout << "Error: can't open file " << aFileName <<endl;;
1306       return 1;
1307     }
1308     char buf[1024];
1309     char *p;
1310     anIS.getline(buf, 1023,'\n');
1311     //    0xEFBBBF  -  prefix of UTF8 
1312     p = &buf[3]; //skip prefix
1313     TCollection_ExtendedString aES1(p, Standard_True);
1314     TDataStd_Name::Set(L.NewChild(), aES1);
1315  
1316
1317     while (anIS.good() && !anIS.eof()) {
1318       anIS.getline(buf, 1023,'\n');
1319       TCollection_ExtendedString aES2(buf, Standard_True);
1320       const TDF_Label& aLab = L.NewChild();
1321       TDataStd_Name::Set(aLab, aES2);
1322     }
1323     return 0;
1324   }
1325   di << "SetUTFName : String is not kept in DF\n";
1326   return 1;
1327 }
1328
1329 //=======================================================================
1330 //function : DDataStd_GetUTFtoFile
1331 //purpose  : GetUTF (DF, fatherEntry, fileName)
1332 //         : all strings from sub-labels of the <fatherEntry> concatenated
1333 //         : in one, converted to UTF8 and kept in the file
1334 //=======================================================================
1335 static Standard_Integer DDataStd_GetUTFtoFile (Draw_Interpretor& di,
1336                                                Standard_Integer nb, 
1337                                                const char** arg) 
1338 {
1339   if (nb == 4) {    
1340     Handle(TDF_Data) DF;
1341     if (!DDF::GetDF(arg[1],DF)) return 1;
1342     TDF_Label L;
1343     if (!DDF::FindLabel(DF,arg[2],L)) return 1;
1344
1345     TCollection_ExtendedString aES;
1346     Standard_Boolean aF = Standard_False;
1347     TDF_ChildIterator anIt(L);
1348     for(;anIt.More();anIt.Next()) {
1349       const TDF_Label& aLab = anIt.Value();
1350       if(!aLab.IsNull()) {
1351         Handle(TDataStd_Name) anAtt;
1352         if(aLab.FindAttribute(TDataStd_Name::GetID(), anAtt)) {
1353           if(anAtt->Get().Length()) { 
1354             if (aF)
1355               aES +='\n';         
1356             aES +=anAtt->Get(); 
1357             aF = Standard_True;
1358           }
1359         }
1360       }
1361     }
1362
1363     if(!aES.Length()) {
1364       cout << "Data is not found in the Document" <<endl;
1365       return 1;
1366     }
1367
1368     Standard_CString aFileName(arg[3]);
1369
1370 #ifdef _MSC_VER
1371     ofstream anOS (aFileName, ios::in | ios::binary | ios::ate);
1372 #else
1373     ofstream anOS (aFileName, ios::ate);
1374 #endif
1375     if (!anOS) {
1376       // A problem with the stream
1377 #ifdef OCCT_DEBUG
1378       cout << "Error: problem with the file stream, rdstate = " <<anOS.rdstate() <<endl;
1379 #endif
1380     }
1381     unsigned char prefix[4] = {0xEF,0xBB,0xBF, 0x00};
1382     anOS.write( (char*)&prefix[0], 3); 
1383     Standard_Integer  n = aES.LengthOfCString();
1384     Standard_PCharacter aCstr = (Standard_PCharacter) Standard::Allocate(n+1);
1385     n = aES.ToUTF8CString(aCstr);
1386     anOS.write( (char*)&aCstr[0], n); 
1387     anOS.close();
1388     return 0;
1389   }
1390   di << "GetUTF : Data is not extracted to the specified file \n";
1391   return 1;
1392 }
1393
1394 //=======================================================================
1395 //function : SetByteArray (DF, entry, isDelta, From, To, elmt1, elmt2, ...  )
1396 //=======================================================================
1397 static Standard_Integer DDataStd_SetByteArray (Draw_Interpretor& di,
1398                                               Standard_Integer nb, 
1399                                               const char** arg) 
1400 {   
1401   if (nb >= 6) {  
1402     Handle(TDF_Data) DF;
1403     if (!DDF::GetDF(arg[1],DF))  return 1; 
1404     TDF_Label label;
1405     DDF::AddLabel(DF, arg[2], label);
1406     Standard_Boolean isDelta = Draw::Atoi(arg[3]) != 0;
1407     Standard_Integer From = Draw::Atoi(arg[4]), To = Draw::Atoi( arg[5] ), j;
1408     di << "Array of Standard_Byte with bounds from = " << From  << " to = " << To  << "\n";
1409     Handle(TDataStd_ByteArray) A = TDataStd_ByteArray::Set(label, From, To, isDelta);
1410     
1411     if (nb > 6) {
1412       j = 6;
1413       for(Standard_Integer i = From; i<=To; ++i) {
1414         Standard_Integer ival = Draw::Atoi(arg[j]);
1415         if(ival < 0 || 255 < ival) {
1416           cout << "Bad value = " << ival<< endl;
1417           return 1;
1418         }
1419         A->SetValue(i, (Standard_Byte)ival); 
1420         j++;
1421       }
1422     }
1423     return 0; 
1424   }
1425   di << "DDataStd_SetByteArray: Error\n";
1426   return 1; 
1427
1428
1429 //=======================================================================
1430 //function : SetByteArrayValue (DF, entry, index, value)
1431 //=======================================================================
1432 static Standard_Integer DDataStd_SetByteArrayValue (Draw_Interpretor&,
1433                                                     Standard_Integer, 
1434                                                     const char** arg) 
1435 {
1436   // Get document.
1437   Handle(TDF_Data) DF;
1438   if (!DDF::GetDF(arg[1], DF))
1439     return 1;
1440
1441   // Get label.
1442   TDF_Label label; 
1443   if (!DDF::AddLabel(DF, arg[2], label))
1444     return 1;
1445  
1446   // Get index and value.
1447   Standard_Integer index = Draw::Atoi(arg[3]);
1448   Standard_Integer value = Draw::Atoi(arg[4]);
1449
1450   // Check the value.
1451   if(value < 0 || 255 < value) {
1452     cout << "Bad value = " << value << endl;
1453     return 1;
1454   }
1455
1456   // Set new value.
1457   Handle(TDataStd_ByteArray) arr;
1458   if (label.FindAttribute(TDataStd_ByteArray::GetID(), arr))
1459   {
1460     arr->SetValue(index, (Standard_Byte) value); 
1461     return 0;
1462   }
1463
1464   return 1;
1465
1466
1467 //=======================================================================
1468 //function : SetBooleanArray (DF, entry, isDelta, From, To, elmt1, elmt2, ...  )
1469 //=======================================================================
1470 static Standard_Integer DDataStd_SetBooleanArray (Draw_Interpretor& di,
1471                                                   Standard_Integer nb, 
1472                                                   const char** arg) 
1473 {
1474   if (nb >= 6) 
1475   {  
1476     Handle(TDF_Data) DF;
1477     if (!DDF::GetDF(arg[1],DF))
1478         return 1; 
1479
1480     TDF_Label label;
1481     DDF::AddLabel(DF, arg[2], label);
1482     Standard_Integer From = Draw::Atoi(arg[4]), To = Draw::Atoi( arg[5] ), j;
1483     di << "Array of Standard_Boolean with bounds from = " << From  << " to = " << To  << "\n";
1484     Handle(TDataStd_BooleanArray) A = TDataStd_BooleanArray::Set(label, From, To);
1485     
1486     if (nb > 6) {
1487       j = 6;
1488       for(Standard_Integer i = From; i<=To; i++) 
1489       {
1490         Standard_Integer ival = Draw::Atoi(arg[j]);
1491         if(ival > 1) 
1492         {
1493           cout << "Bad value = " << ival<< ". 0 or 1 is expected." << endl;
1494           return 1;
1495         }
1496         A->SetValue(i, ival != 0); 
1497         j++;
1498       }
1499     }
1500     return 0; 
1501   }
1502   di << "DDataStd_SetBooleanArray: Error\n";
1503   return 1; 
1504
1505
1506 //=======================================================================
1507 //function : SetBooleanArrayValue (DF, entry, index, value)
1508 //=======================================================================
1509 static Standard_Integer DDataStd_SetBooleanArrayValue (Draw_Interpretor& di,
1510                                                        Standard_Integer,
1511                                                        const char** arg) 
1512 {
1513   // Get document.
1514   Handle(TDF_Data) DF;
1515   if (!DDF::GetDF(arg[1], DF))
1516     return 1;
1517
1518   // Get label.
1519   TDF_Label label; 
1520   if (!DDF::AddLabel(DF, arg[2], label))
1521     return 1;
1522  
1523   // Get index and value.
1524   Standard_Integer index = Draw::Atoi(arg[3]);
1525   Standard_Integer value = Draw::Atoi(arg[4]);
1526
1527   // Check the value.
1528   if (value != 0 && value != 1) {
1529     di << "DDataStd_SetBooleanArrayValue: Error! The value should be either 0 or 1.\n";
1530     return 1;
1531   }
1532
1533   // Set new value.
1534   Handle(TDataStd_BooleanArray) arr;
1535   if (label.FindAttribute(TDataStd_BooleanArray::GetID(), arr))
1536   {
1537     arr->SetValue(index, value != 0);
1538     return 0;
1539   }
1540
1541   return 1;
1542
1543
1544 //=======================================================================
1545 //function : DDataStd_SetExtStringList (DF, entry, elmt1, elmt2, ...  )
1546 //=======================================================================
1547 static Standard_Integer DDataStd_SetExtStringList (Draw_Interpretor& di,
1548                                                  Standard_Integer nb, 
1549                                                  const char** arg) 
1550 {
1551   if (nb > 2) 
1552   {  
1553     Handle(TDF_Data) DF;
1554     if (!DDF::GetDF(arg[1],DF))
1555         return 1; 
1556
1557     TDF_Label label;
1558     DDF::AddLabel(DF, arg[2], label);
1559     Handle(TDataStd_ExtStringList) A = TDataStd_ExtStringList::Set(label);
1560     for(Standard_Integer i = 3; i <= nb - 1; i++) 
1561     {
1562       TCollection_ExtendedString aValue(arg[i]);     
1563       A->Append(aValue); 
1564     }
1565     return 0; 
1566   }
1567   di << "DDataStd_SetExtStringList: Error\n";
1568   return 1; 
1569
1570 //
1571 //=======================================================================
1572 //function : DDataStd_SetReferenceList (DF, entry, elmt1, elmt2, ...  )
1573 //=======================================================================
1574 static Standard_Integer DDataStd_SetReferenceList (Draw_Interpretor& di,
1575                                                    Standard_Integer nb, 
1576                                                    const char** arg) 
1577 {
1578   if (nb > 2) 
1579   {  
1580     Handle(TDF_Data) DF;
1581     if (!DDF::GetDF(arg[1],DF))
1582         return 1; 
1583
1584     TDF_Label label;
1585     DDF::AddLabel(DF, arg[2], label);
1586     if(!label.IsNull()) {
1587       Handle(TDataStd_ReferenceList) A = TDataStd_ReferenceList::Set(label);
1588       for(Standard_Integer i = 3; i <= nb - 1; i++) 
1589       {
1590         TDF_Label aValueLabel;
1591         DDF::AddLabel(DF, arg[i], aValueLabel);
1592         if(aValueLabel.IsNull()) continue;
1593         A->Append(aValueLabel); 
1594       }
1595       return 0; 
1596     }
1597   }
1598   di << "DDataStd_SetReferenceList: Error\n";
1599   return 1; 
1600
1601
1602
1603 //=======================================================================
1604 //function : SetBooleanList (DF, entry, elmt1, elmt2, ...  )
1605 //=======================================================================
1606 static Standard_Integer DDataStd_SetBooleanList (Draw_Interpretor& di,
1607                                                  Standard_Integer nb, 
1608                                                  const char** arg) 
1609 {
1610   if (nb > 2) 
1611   {  
1612     Handle(TDF_Data) DF;
1613     if (!DDF::GetDF(arg[1],DF))
1614         return 1; 
1615
1616     TDF_Label label;
1617     DDF::AddLabel(DF, arg[2], label);
1618     Handle(TDataStd_BooleanList) A = TDataStd_BooleanList::Set(label);
1619     for(Standard_Integer i = 3; i <= nb - 1; i++) 
1620     {
1621       Standard_Integer ival = Draw::Atoi(arg[i]);
1622       if(ival > 1) 
1623       {
1624         cout << "Bad value = " << ival<< ". 0 or 1 is expected." << endl;
1625         return 1;
1626       }
1627       A->Append (ival != 0);
1628     }
1629     return 0; 
1630   }
1631   di << "DDataStd_SetBooleanList: Error\n";
1632   return 1; 
1633
1634
1635 //=======================================================================
1636 //function : SetIntegerList (DF, entry, elmt1, elmt2, ...  )
1637 //=======================================================================
1638 static Standard_Integer DDataStd_SetIntegerList (Draw_Interpretor& di,
1639                                                  Standard_Integer nb, 
1640                                                  const char** arg) 
1641 {
1642   if (nb > 2) 
1643   {  
1644     Handle(TDF_Data) DF;
1645     if (!DDF::GetDF(arg[1],DF))
1646         return 1; 
1647
1648     TDF_Label label;
1649     DDF::AddLabel(DF, arg[2], label);
1650     Handle(TDataStd_IntegerList) A = TDataStd_IntegerList::Set(label);
1651     for(Standard_Integer i = 3; i <= nb - 1; i++) 
1652     {
1653       Standard_Integer ival = Draw::Atoi(arg[i]);
1654       A->Append(ival); 
1655     }
1656     return 0; 
1657   }
1658   di << "DDataStd_SetIntegerList: Error\n";
1659   return 1; 
1660
1661
1662 //=======================================================================
1663 //function : SetRealList (DF, entry, elmt1, elmt2, ...  )
1664 //=======================================================================
1665 static Standard_Integer DDataStd_SetRealList (Draw_Interpretor& di,
1666                                               Standard_Integer nb, 
1667                                               const char** arg) 
1668 {
1669   if (nb > 2) 
1670   {  
1671     Handle(TDF_Data) DF;
1672     if (!DDF::GetDF(arg[1],DF))
1673         return 1; 
1674
1675     TDF_Label label;
1676     DDF::AddLabel(DF, arg[2], label);
1677     Handle(TDataStd_RealList) A = TDataStd_RealList::Set(label);
1678     for(Standard_Integer i = 3; i <= nb - 1; i++) 
1679     {
1680       Standard_Real fval = Draw::Atof(arg[i]);
1681       A->Append(fval); 
1682     }
1683     return 0; 
1684   }
1685   di << "DDataStd_SetRealList: Error\n";
1686   return 1; 
1687
1688
1689 //=======================================================================
1690 //function : DDataStd_InsertBeforeExtStringList (DF, entry, index, value  )
1691 //=======================================================================
1692 static Standard_Integer DDataStd_InsertBeforeExtStringList (Draw_Interpretor& di,
1693                                                             Standard_Integer nb, 
1694                                                             const char** arg) 
1695 {
1696   if (nb == 5) 
1697   {  
1698     Handle(TDF_Data) DF;
1699     if (!DDF::GetDF(arg[1],DF))
1700         return 1; 
1701
1702     TDF_Label label;
1703     DDF::AddLabel(DF, arg[2], label);
1704     
1705     Handle(TDataStd_ExtStringList) A;
1706     if (!label.FindAttribute(TDataStd_ExtStringList::GetID(), A))
1707         return 1;
1708
1709     Standard_Integer index = Draw::Atoi(arg[3]);
1710     TCollection_ExtendedString value = arg[4];
1711
1712     if (A->InsertBefore(index, value))    
1713       return 0; 
1714     else
1715       return 1;
1716   }
1717   di << "DDataStd_InsertBeforeExtStringList: Error\n";
1718   return 1; 
1719
1720
1721 //=======================================================================
1722 //function : DDataStd_InsertAfterExtStringList (DF, entry, index, value  )
1723 //=======================================================================
1724 static Standard_Integer DDataStd_InsertAfterExtStringList (Draw_Interpretor& di,
1725                                                            Standard_Integer nb, 
1726                                                            const char** arg) 
1727 {
1728   if (nb == 5) 
1729   {  
1730     Handle(TDF_Data) DF;
1731     if (!DDF::GetDF(arg[1],DF))
1732         return 1; 
1733
1734     TDF_Label label;
1735     DDF::AddLabel(DF, arg[2], label);
1736     
1737     Handle(TDataStd_ExtStringList) A;
1738     if (!label.FindAttribute(TDataStd_ExtStringList::GetID(), A))
1739         return 1;
1740
1741     Standard_Integer index = Draw::Atoi(arg[3]);
1742     TCollection_ExtendedString value = arg[4];
1743
1744     if (A->InsertAfter(index, value))    
1745       return 0; 
1746     else
1747       return 1;
1748   }
1749   di << "DDataStd_InsertAfterExtStringList: Error\n";
1750   return 1; 
1751
1752
1753 //=======================================================================
1754 //function : DDataStd_RemoveExtStringList (DF, entry, index )
1755 //=======================================================================
1756 static Standard_Integer DDataStd_RemoveExtStringList (Draw_Interpretor& di,
1757                                                       Standard_Integer nb, 
1758                                                       const char** arg) 
1759 {
1760   if (nb == 4) 
1761   {  
1762     Handle(TDF_Data) DF;
1763     if (!DDF::GetDF(arg[1],DF))
1764         return 1; 
1765
1766     TDF_Label label;
1767     DDF::AddLabel(DF, arg[2], label);
1768     
1769     Handle(TDataStd_ExtStringList) A;
1770     if (!label.FindAttribute(TDataStd_ExtStringList::GetID(), A))
1771         return 1;
1772
1773     Standard_Integer index = Draw::Atoi(arg[3]);
1774
1775     if (A->Remove(index))    
1776       return 0; 
1777     else
1778       return 1;
1779   }
1780   di << "DDataStd_RemoveExtStringList: Error\n";
1781   return 1; 
1782
1783
1784 //=======================================================================
1785 //function : DDataStd_InsertBeforeBooleanList (DF, entry, index, value  )
1786 //=======================================================================
1787 static Standard_Integer DDataStd_InsertBeforeBooleanList (Draw_Interpretor& di,
1788                                                           Standard_Integer nb, 
1789                                                           const char** arg) 
1790 {
1791   if (nb == 5) 
1792   {  
1793     Handle(TDF_Data) DF;
1794     if (!DDF::GetDF(arg[1],DF))
1795         return 1; 
1796
1797     TDF_Label label;
1798     DDF::AddLabel(DF, arg[2], label);
1799     
1800     Handle(TDataStd_BooleanList) A;
1801     if (!label.FindAttribute(TDataStd_BooleanList::GetID(), A))
1802         return 1;
1803
1804     Standard_Integer index = Draw::Atoi(arg[3]);
1805     Standard_Boolean value = Draw::Atoi(arg[4]) != 0;
1806
1807     if (A->InsertBefore(index, value))    
1808       return 0; 
1809     else
1810       return 1;
1811   }
1812   di << "DDataStd_InsertBeforeBooleanList: Error\n";
1813   return 1; 
1814
1815
1816 //=======================================================================
1817 //function : DDataStd_InsertAfterBooleanList (DF, entry, index, value  )
1818 //=======================================================================
1819 static Standard_Integer DDataStd_InsertAfterBooleanList (Draw_Interpretor& di,
1820                                                          Standard_Integer nb, 
1821                                                          const char** arg) 
1822 {
1823   if (nb == 5) 
1824   {  
1825     Handle(TDF_Data) DF;
1826     if (!DDF::GetDF(arg[1],DF))
1827         return 1; 
1828
1829     TDF_Label label;
1830     DDF::AddLabel(DF, arg[2], label);
1831     
1832     Handle(TDataStd_BooleanList) A;
1833     if (!label.FindAttribute(TDataStd_BooleanList::GetID(), A))
1834         return 1;
1835
1836     Standard_Integer index = Draw::Atoi(arg[3]);
1837     Standard_Boolean value = Draw::Atoi(arg[4]) != 0;
1838
1839     if (A->InsertAfter(index, value))    
1840       return 0; 
1841     else
1842       return 1;
1843   }
1844   di << "DDataStd_InsertAfterBooleanList: Error\n";
1845   return 1; 
1846
1847
1848 //=======================================================================
1849 //function : DDataStd_RemoveBooleanList (DF, entry, index )
1850 //=======================================================================
1851 static Standard_Integer DDataStd_RemoveBooleanList (Draw_Interpretor& di,
1852                                                     Standard_Integer nb, 
1853                                                     const char** arg) 
1854 {
1855   if (nb == 4) 
1856   {  
1857     Handle(TDF_Data) DF;
1858     if (!DDF::GetDF(arg[1],DF))
1859         return 1; 
1860
1861     TDF_Label label;
1862     DDF::AddLabel(DF, arg[2], label);
1863     
1864     Handle(TDataStd_BooleanList) A;
1865     if (!label.FindAttribute(TDataStd_BooleanList::GetID(), A))
1866         return 1;
1867
1868     Standard_Integer index = Draw::Atoi(arg[3]);
1869
1870     if (A->Remove(index))    
1871       return 0; 
1872     else
1873       return 1;
1874   }
1875   di << "DDataStd_RemoveBooleanList: Error\n";
1876   return 1; 
1877
1878
1879 //=======================================================================
1880 //function : DDataStd_InsertBeforeIntegerList (DF, entry, index, value  )
1881 //=======================================================================
1882 static Standard_Integer DDataStd_InsertBeforeIntegerList (Draw_Interpretor& di,
1883                                                           Standard_Integer nb, 
1884                                                           const char** arg) 
1885 {
1886   if (nb == 5) 
1887   {  
1888     Handle(TDF_Data) DF;
1889     if (!DDF::GetDF(arg[1],DF))
1890         return 1; 
1891
1892     TDF_Label label;
1893     DDF::AddLabel(DF, arg[2], label);
1894     
1895     Handle(TDataStd_IntegerList) A;
1896     if (!label.FindAttribute(TDataStd_IntegerList::GetID(), A))
1897         return 1;
1898
1899     Standard_Integer index = Draw::Atoi(arg[3]);
1900     Standard_Integer value = (Standard_Integer) Draw::Atoi(arg[4]);
1901
1902     if (A->InsertBeforeByIndex(index, value))    
1903       return 0; 
1904     else
1905       return 1;
1906   }
1907   di << "DDataStd_InsertBeforeIntegerList: Error\n";
1908   return 1; 
1909
1910
1911 //=======================================================================
1912 //function : DDataStd_InsertAfterIntegerList (DF, entry, index, value  )
1913 //=======================================================================
1914 static Standard_Integer DDataStd_InsertAfterIntegerList (Draw_Interpretor& di,
1915                                                          Standard_Integer nb, 
1916                                                          const char** arg) 
1917 {
1918   if (nb == 5) 
1919   {  
1920     Handle(TDF_Data) DF;
1921     if (!DDF::GetDF(arg[1],DF))
1922         return 1; 
1923
1924     TDF_Label label;
1925     DDF::AddLabel(DF, arg[2], label);
1926     
1927     Handle(TDataStd_IntegerList) A;
1928     if (!label.FindAttribute(TDataStd_IntegerList::GetID(), A))
1929         return 1;
1930
1931     Standard_Integer index = Draw::Atoi(arg[3]);
1932     Standard_Integer value = (Standard_Integer) Draw::Atoi(arg[4]);
1933
1934     if (A->InsertAfterByIndex(index, value))    
1935       return 0; 
1936     else
1937       return 1;
1938   }
1939   di << "DDataStd_InsertAfterIntegerList: Error\n";
1940   return 1; 
1941
1942
1943 //=======================================================================
1944 //function : DDataStd_RemoveIntegerList (DF, entry, index )
1945 //=======================================================================
1946 static Standard_Integer DDataStd_RemoveIntegerList (Draw_Interpretor& di,
1947                                                     Standard_Integer nb, 
1948                                                     const char** arg) 
1949 {
1950   if (nb == 4) 
1951   {  
1952     Handle(TDF_Data) DF;
1953     if (!DDF::GetDF(arg[1],DF))
1954         return 1; 
1955
1956     TDF_Label label;
1957     DDF::AddLabel(DF, arg[2], label);
1958     
1959     Handle(TDataStd_IntegerList) A;
1960     if (!label.FindAttribute(TDataStd_IntegerList::GetID(), A))
1961         return 1;
1962
1963     Standard_Integer index = Draw::Atoi(arg[3]);
1964
1965     if (A->RemoveByIndex(index))    
1966       return 0; 
1967     else
1968       return 1;
1969   }
1970   di << "DDataStd_RemoveIntegerList: Error\n";
1971   return 1; 
1972
1973
1974 //=======================================================================
1975 //function : DDataStd_InsertBeforeRealList (DF, entry, index, value  )
1976 //=======================================================================
1977 static Standard_Integer DDataStd_InsertBeforeRealList (Draw_Interpretor& di,
1978                                                        Standard_Integer nb, 
1979                                                        const char** arg) 
1980 {
1981   if (nb == 5) 
1982   {  
1983     Handle(TDF_Data) DF;
1984     if (!DDF::GetDF(arg[1],DF))
1985         return 1; 
1986
1987     TDF_Label label;
1988     DDF::AddLabel(DF, arg[2], label);
1989     
1990     Handle(TDataStd_RealList) A;
1991     if (!label.FindAttribute(TDataStd_RealList::GetID(), A))
1992         return 1;
1993
1994     Standard_Integer index = Draw::Atoi(arg[3]);
1995     Standard_Real value = (Standard_Real) Draw::Atof(arg[4]);
1996
1997     if (A->InsertBeforeByIndex(index, value))    
1998       return 0; 
1999     else
2000       return 1;
2001   }
2002   di << "DDataStd_InsertBeforeRealList: Error\n";
2003   return 1; 
2004
2005
2006 //=======================================================================
2007 //function : DDataStd_InsertAfterRealList (DF, entry, index, value  )
2008 //=======================================================================
2009 static Standard_Integer DDataStd_InsertAfterRealList (Draw_Interpretor& di,
2010                                                       Standard_Integer nb, 
2011                                                       const char** arg) 
2012 {
2013   if (nb == 5) 
2014   {  
2015     Handle(TDF_Data) DF;
2016     if (!DDF::GetDF(arg[1],DF))
2017         return 1; 
2018
2019     TDF_Label label;
2020     DDF::AddLabel(DF, arg[2], label);
2021     
2022     Handle(TDataStd_RealList) A;
2023     if (!label.FindAttribute(TDataStd_RealList::GetID(), A))
2024         return 1;
2025
2026     Standard_Integer index = Draw::Atoi(arg[3]);
2027     Standard_Real value = (Standard_Real) Draw::Atof(arg[4]);
2028
2029     if (A->InsertAfterByIndex(index, value))    
2030       return 0; 
2031     else
2032       return 1;
2033   }
2034   di << "DDataStd_InsertAfterRealList: Error\n";
2035   return 1; 
2036
2037
2038 //=======================================================================
2039 //function : DDataStd_RemoveRealList (DF, entry, index )
2040 //=======================================================================
2041 static Standard_Integer DDataStd_RemoveRealList (Draw_Interpretor& di,
2042                                                  Standard_Integer nb, 
2043                                                  const char** arg) 
2044 {
2045   if (nb == 4) 
2046   {  
2047     Handle(TDF_Data) DF;
2048     if (!DDF::GetDF(arg[1],DF))
2049         return 1; 
2050
2051     TDF_Label label;
2052     DDF::AddLabel(DF, arg[2], label);
2053     
2054     Handle(TDataStd_RealList) A;
2055     if (!label.FindAttribute(TDataStd_RealList::GetID(), A))
2056         return 1;
2057
2058     Standard_Integer index = Draw::Atoi(arg[3]);
2059
2060     if (A->RemoveByIndex(index))    
2061       return 0; 
2062     else
2063       return 1;
2064   }
2065   di << "DDataStd_RemoveRealList: Error\n";
2066   return 1; 
2067
2068
2069 //=======================================================================
2070 //function : DDataStd_InsertBeforeReferenceList (DF, entry, index, value  )
2071 //=======================================================================
2072 static Standard_Integer DDataStd_InsertBeforeReferenceList (Draw_Interpretor& di,
2073                                                             Standard_Integer nb, 
2074                                                             const char** arg) 
2075 {
2076   if (nb == 5) 
2077   {  
2078     Handle(TDF_Data) DF;
2079     if (!DDF::GetDF(arg[1],DF))
2080         return 1; 
2081
2082     TDF_Label label;
2083     DDF::AddLabel(DF, arg[2], label);
2084     
2085     Handle(TDataStd_ReferenceList) A;
2086     if (!label.FindAttribute(TDataStd_ReferenceList::GetID(), A))
2087         return 1;
2088
2089     Standard_Integer index = Draw::Atoi(arg[3]);
2090
2091     TDF_Label refLabel;
2092     if (!DDF::AddLabel(DF, arg[4], refLabel))
2093         return 1;
2094
2095     if (A->InsertBefore(index, refLabel))    
2096       return 0; 
2097     else
2098       return 1;
2099   }
2100   di << "DDataStd_InsertBeforeReferenceList: Error\n";
2101   return 1; 
2102
2103
2104 //=======================================================================
2105 //function : DDataStd_InsertAfterReferenceList (DF, entry, index, value  )
2106 //=======================================================================
2107 static Standard_Integer DDataStd_InsertAfterReferenceList (Draw_Interpretor& di,
2108                                                            Standard_Integer nb, 
2109                                                            const char** arg) 
2110 {
2111   if (nb == 5) 
2112   {  
2113     Handle(TDF_Data) DF;
2114     if (!DDF::GetDF(arg[1],DF))
2115         return 1; 
2116
2117     TDF_Label label;
2118     DDF::AddLabel(DF, arg[2], label);
2119     
2120     Handle(TDataStd_ReferenceList) A;
2121     if (!label.FindAttribute(TDataStd_ReferenceList::GetID(), A))
2122         return 1;
2123
2124     Standard_Integer index = Draw::Atoi(arg[3]);
2125
2126     TDF_Label refLabel;
2127     if (!DDF::AddLabel(DF, arg[4], refLabel))
2128         return 1;
2129
2130     if (A->InsertAfter(index, refLabel))
2131       return 0; 
2132     else
2133       return 1;
2134   }
2135   di << "DDataStd_InsertAfterReferenceList: Error\n";
2136   return 1; 
2137
2138
2139 //=======================================================================
2140 //function : DDataStd_RemoveReferenceList (DF, entry, index )
2141 //=======================================================================
2142 static Standard_Integer DDataStd_RemoveReferenceList (Draw_Interpretor& di,
2143                                                       Standard_Integer nb, 
2144                                                       const char** arg) 
2145 {
2146   if (nb == 4) 
2147   {  
2148     Handle(TDF_Data) DF;
2149     if (!DDF::GetDF(arg[1],DF))
2150         return 1; 
2151
2152     TDF_Label label;
2153     DDF::AddLabel(DF, arg[2], label);
2154     
2155     Handle(TDataStd_ReferenceList) A;
2156     if (!label.FindAttribute(TDataStd_ReferenceList::GetID(), A))
2157         return 1;
2158
2159     Standard_Integer index = Draw::Atoi(arg[3]);
2160
2161     if (A->Remove(index))    
2162       return 0; 
2163     else
2164       return 1;
2165   }
2166   di << "DDataStd_RemoveReferenceList: Error\n";
2167   return 1; 
2168
2169
2170 //=======================================================================
2171 //function : GetByteArray (DF, entry )
2172 //=======================================================================
2173 static Standard_Integer DDataStd_GetByteArray (Draw_Interpretor& di,
2174                                               Standard_Integer, 
2175                                               const char** arg) 
2176 {   
2177
2178
2179   Handle(TDF_Data) DF;
2180   if (!DDF::GetDF(arg[1],DF))  return 1;  
2181   TDF_Label label;
2182   if( !DDF::FindLabel(DF, arg[2], label) ) {
2183     di << "No label for entry"  << "\n";
2184     return 1;
2185   }
2186  
2187   Handle(TDataStd_ByteArray) A;
2188   if ( !label.FindAttribute(TDataStd_ByteArray::GetID(), A) ) { 
2189     di << "There is no TDataStd_ByteArray at label"  << "\n";
2190     return 1;
2191   }
2192   
2193   for(Standard_Integer i = A->Lower(); i<=A->Upper(); i++){
2194     //cout <<  A->Value(i)   << endl;
2195     di  <<  A->Value(i);
2196     if(i<A->Upper())  
2197      di<<" ";
2198   }
2199   di<<"\n";
2200   return 0; 
2201
2202
2203 //=======================================================================
2204 //function : GetByteArrayValue (DF, entry, index)
2205 //=======================================================================
2206 static Standard_Integer DDataStd_GetByteArrayValue (Draw_Interpretor& di,
2207                                                     Standard_Integer, 
2208                                                     const char** arg) 
2209 {
2210   Handle(TDF_Data) DF;
2211   if (!DDF::GetDF(arg[1],DF))
2212       return 1;
2213
2214   TDF_Label label;
2215   if (!DDF::FindLabel(DF, arg[2], label)) {
2216     di << "No label for entry"  << "\n";
2217     return 1;
2218   }
2219  
2220   Handle(TDataStd_ByteArray) A;
2221   if ( !label.FindAttribute(TDataStd_ByteArray::GetID(), A) ) { 
2222     di << "There is no TDataStd_ByteArray under label"  << "\n";
2223     return 1;
2224   }
2225   
2226   Standard_Integer index = Draw::Atoi(arg[3]);
2227   if (index < A->Lower() || index > A->Upper()) {
2228     di << "Index is out of range\n";
2229     return 1;
2230   } else {
2231     di << A->Value(index) << "\n";
2232   }
2233
2234   return 0; 
2235
2236
2237 //=======================================================================
2238 //function : GetBooleanArray (DF, entry )
2239 //=======================================================================
2240 static Standard_Integer DDataStd_GetBooleanArray (Draw_Interpretor& di,
2241                                                   Standard_Integer, 
2242                                                   const char** arg) 
2243 {   
2244   Handle(TDF_Data) DF;
2245   if (!DDF::GetDF(arg[1],DF)) 
2246       return 1;  
2247
2248   TDF_Label label;
2249   if ( !DDF::FindLabel(DF, arg[2], label) ) 
2250   {
2251     di << "No label for entry"  << "\n";
2252     return 1;
2253   }
2254  
2255   Handle(TDataStd_BooleanArray) A;
2256   if ( !label.FindAttribute(TDataStd_BooleanArray::GetID(), A) ) 
2257   {
2258     di << "There is no TDataStd_BooleanArray at label"  << "\n";
2259     return 1;
2260   }
2261   
2262   for (Standard_Integer i = A->Lower(); i<=A->Upper(); i++)
2263   {
2264     di << (Standard_Integer) A->Value(i);
2265     if (i < A->Upper())  
2266      di << " ";
2267   }
2268   di << "\n";
2269   return 0; 
2270 }
2271
2272 //=======================================================================
2273 //function : GetBooleanArrayValue (DF, entry, index)
2274 //=======================================================================
2275 static Standard_Integer DDataStd_GetBooleanArrayValue (Draw_Interpretor& di,
2276                                                        Standard_Integer, 
2277                                                        const char** arg) 
2278 {
2279   Handle(TDF_Data) DF;
2280   if (!DDF::GetDF(arg[1],DF))
2281       return 1;
2282
2283   TDF_Label label;
2284   if (!DDF::FindLabel(DF, arg[2], label)) {
2285     di << "No label for entry"  << "\n";
2286     return 1;
2287   }
2288  
2289   Handle(TDataStd_BooleanArray) A;
2290   if ( !label.FindAttribute(TDataStd_BooleanArray::GetID(), A) ) { 
2291     di << "There is no TDataStd_BooleanArray under label"  << "\n";
2292     return 1;
2293   }
2294   
2295   Standard_Integer index = Draw::Atoi(arg[3]);
2296   if (index < A->Lower() || index > A->Upper()) {
2297     di << "Index is out of range\n";
2298     return 1;
2299   } else {
2300     di << ((A->Value(index) == Standard_True) ? "True" : "False") << "\n";
2301   }
2302
2303   return 0; 
2304
2305
2306 //=======================================================================
2307 //function : ChangeByteArray (DF, entry, indx, val )
2308 //=======================================================================
2309 static Standard_Integer DDataStd_ChangeByteArray (Draw_Interpretor& di,
2310                                               Standard_Integer nb, 
2311                                               const char** arg) 
2312 {   
2313
2314   if( nb == 5 ) {  
2315     Handle(TDF_Data) DF;
2316     if (!DDF::GetDF(arg[1],DF))  return 1;  
2317     TDF_Label label;
2318     if( !DDF::FindLabel(DF, arg[2], label) ) {
2319       di << "No label for entry"  << "\n";
2320       return 1;
2321     }
2322  
2323     Handle(TDataStd_ByteArray) A;
2324     if ( !label.FindAttribute(TDataStd_ByteArray::GetID(), A) ) { 
2325       di << "There is no TDataStd_ByteArray at label"  << "\n";
2326       return 1;
2327     }
2328     Standard_Integer indx = Draw::Atoi(arg[3]);
2329     Standard_Integer ival  = Draw::Atoi(arg[4]);
2330     if (ival > 255 || ival < 0) {
2331         di << "DDataStd_ChangeByteArray: Bad value = " <<ival << "\n";
2332         return 1;
2333       }
2334     Standard_Integer low = A->Lower(), up = A->Upper();
2335     if(low <= indx && indx <= up)
2336       A->SetValue(indx, (Standard_Byte)ival);
2337     else {
2338       Handle(TColStd_HArray1OfByte) Arr = A->InternalArray();
2339       Handle(TColStd_HArray1OfByte) arr;
2340       Standard_Integer i;
2341       if(indx > up) {
2342         up = indx;
2343         arr = new TColStd_HArray1OfByte(low, up);
2344         for(i=low; i<= Arr->Upper(); i++)
2345           arr->SetValue(i, Arr->Value(i));
2346         for(i=Arr->Upper()+1; i<= up; i++) {
2347           if(i == up)
2348             arr->SetValue(i, (Standard_Byte)ival);
2349           else
2350             arr->SetValue(i, 0);
2351         }
2352       } else if(indx < up) {//clip array : indx to be negative
2353         up = abs(indx);
2354         arr = new TColStd_HArray1OfByte(low, up);
2355         for(i=low; i< up; i++)
2356           arr->SetValue(i, Arr->Value(i));
2357         arr->SetValue(up, (Standard_Byte)ival);
2358       }
2359       A->ChangeArray(arr);
2360     }
2361     return 0;
2362   }
2363   di << "DDataStd_ChangeByteArray: Error\n";
2364   return 1; 
2365 }
2366
2367 //=======================================================================
2368 //function : GetBooleanList (DF, entry )
2369 //=======================================================================
2370 static Standard_Integer DDataStd_GetBooleanList (Draw_Interpretor& di,
2371                                                  Standard_Integer nb, 
2372                                                  const char** arg) 
2373 {   
2374   if (nb == 3) {
2375     Handle(TDF_Data) DF;
2376     if (!DDF::GetDF(arg[1],DF)) 
2377       return 1;  
2378
2379     TDF_Label label;
2380     if ( !DDF::FindLabel(DF, arg[2], label) ) 
2381     {
2382       di << "No label for entry"  << "\n";
2383       return 1;
2384     }
2385  
2386     Handle(TDataStd_BooleanList) A;
2387     if ( !label.FindAttribute(TDataStd_BooleanList::GetID(), A) ) 
2388     {
2389       di << "There is no TDataStd_BooleanList at label"  << "\n";
2390       return 1;
2391     }
2392   
2393     const TDataStd_ListOfByte& bList = A->List();
2394     Standard_Boolean isEmpty = (bList.Extent() > 0) ? Standard_False : Standard_True;
2395     if(!isEmpty) {
2396       TDataStd_ListIteratorOfListOfByte itr(bList);
2397       for (; itr.More(); itr.Next())
2398       {
2399         di << (Standard_Integer) itr.Value() << " ";
2400       }
2401       di << "\n";
2402     } else 
2403        di << "List is empty\n";
2404     return 0; 
2405   }
2406   di << "DDataStd_GetBooleanList: Error\n";
2407   return 1; 
2408 }
2409
2410 //=======================================================================
2411 //function : GetIntegerList (DF, entry )
2412 //=======================================================================
2413 static Standard_Integer DDataStd_GetIntegerList (Draw_Interpretor& di,
2414                                                  Standard_Integer nb, 
2415                                                  const char** arg) 
2416
2417   if (nb == 3) {
2418     Handle(TDF_Data) DF;
2419     if (!DDF::GetDF(arg[1],DF)) 
2420       return 1;  
2421
2422     TDF_Label label;
2423     if ( !DDF::FindLabel(DF, arg[2], label) ) 
2424     {
2425       di << "No label for entry"  << "\n";
2426       return 1;
2427     }
2428  
2429     Handle(TDataStd_IntegerList) A;
2430     if ( !label.FindAttribute(TDataStd_IntegerList::GetID(), A) ) 
2431     {
2432       di << "There is no TDataStd_IntegerList at label"  << "\n";
2433       return 1;
2434     }
2435   
2436     const TColStd_ListOfInteger& iList = A->List();
2437     Standard_Boolean isEmpty = (iList.Extent() > 0) ? Standard_False : Standard_True;
2438     if(!isEmpty) {
2439       TColStd_ListIteratorOfListOfInteger itr(iList);
2440       for (; itr.More(); itr.Next())
2441       {
2442         di << itr.Value() << " ";
2443       }
2444       di << "\n";
2445     } else 
2446       di << "List is empty\n";
2447
2448     return 0; 
2449   }
2450   di << "DDataStd_GetIntegerList: Error\n";
2451   return 1; 
2452 }
2453
2454 //=======================================================================
2455 //function : GetRealList (DF, entry )
2456 //=======================================================================
2457 static Standard_Integer DDataStd_GetRealList (Draw_Interpretor& di,
2458                                               Standard_Integer nb, 
2459                                               const char** arg) 
2460 {   
2461   if (nb == 3) {  
2462     Handle(TDF_Data) DF;
2463     if (!DDF::GetDF(arg[1],DF)) 
2464       return 1;  
2465
2466     TDF_Label label;
2467     if ( !DDF::FindLabel(DF, arg[2], label) ) 
2468     {
2469       di << "No label for entry"  << "\n";
2470       return 1;
2471     }
2472  
2473     Handle(TDataStd_RealList) A;
2474     if ( !label.FindAttribute(TDataStd_RealList::GetID(), A) ) 
2475     {
2476       di << "There is no TDataStd_RealList at label"  << "\n";
2477       return 1;
2478     }
2479   
2480     const TColStd_ListOfReal& rList = A->List();
2481     Standard_Boolean isEmpty = (rList.Extent() > 0) ? Standard_False : Standard_True;
2482     if(!isEmpty) {
2483       TColStd_ListIteratorOfListOfReal itr(rList);
2484       for (; itr.More(); itr.Next())
2485       {
2486         di << itr.Value() << " ";
2487       }
2488       di << "\n";
2489     } else
2490       di << "List is empty\n";
2491     return 0; 
2492   }
2493   di << "DDataStd_GetRealList: Error\n";
2494   return 1; 
2495 }
2496
2497 //=======================================================================
2498 //function : DDataStd_GetExtStringList (DF, entry)
2499 //=======================================================================
2500 static Standard_Integer DDataStd_GetExtStringList (Draw_Interpretor& di,
2501                                                  Standard_Integer nb, 
2502                                                  const char** arg) 
2503 {
2504   if (nb == 3) 
2505   {  
2506     Handle(TDF_Data) DF;
2507     if (!DDF::GetDF(arg[1],DF))
2508         return 1; 
2509
2510     TDF_Label label;
2511     if ( !DDF::FindLabel(DF, arg[2], label) ) 
2512     {
2513       di << "No label for entry"  << "\n";
2514       return 1;
2515     }
2516
2517     Handle(TDataStd_ExtStringList) A;
2518     if ( !label.FindAttribute(TDataStd_ExtStringList::GetID(), A) ) 
2519     {
2520       di << "There is no TDataStd_ExtStringList at label"  << "\n";
2521       return 1;
2522     }
2523     
2524     const TDataStd_ListOfExtendedString& aList = A->List();
2525     Standard_Boolean isEmpty = (aList.Extent() > 0) ? Standard_False : Standard_True;
2526     if(!isEmpty) {
2527       TDataStd_ListIteratorOfListOfExtendedString itr(aList);   
2528       for (; itr.More(); itr.Next())
2529       {
2530         const TCollection_ExtendedString& aStr = itr.Value();
2531         di << aStr << " ";      
2532       }
2533       di << "\n";
2534     }
2535     else {
2536       di << "List is empty\n";
2537     }
2538     return 0; 
2539   }
2540   di << "DDataStd_GetExtStringList: Error\n";
2541   return 1; 
2542
2543
2544 //=======================================================================
2545 //function : DDataStd_GetReferenceList (DF, entry )
2546 //=======================================================================
2547 static Standard_Integer DDataStd_GetReferenceList (Draw_Interpretor& di,
2548                                                    Standard_Integer nb, 
2549                                                    const char** arg) 
2550 {
2551   if (nb == 3) 
2552   {  
2553     Handle(TDF_Data) DF;
2554     if (!DDF::GetDF(arg[1],DF))
2555         return 1; 
2556
2557     TDF_Label label;
2558     if ( !DDF::FindLabel(DF, arg[2], label) ) 
2559     {
2560       di << "No label for entry"  << "\n";
2561       return 1;
2562     }
2563     
2564     Handle(TDataStd_ReferenceList) A;
2565     if ( !label.FindAttribute(TDataStd_ReferenceList::GetID(), A) ) 
2566     {
2567       di << "There is no TDataStd_ReferenceList at label"  << "\n";
2568       return 1;
2569     }
2570     
2571     const TDF_LabelList& aList = A->List();
2572     Standard_Boolean isEmpty = (aList.Extent() > 0) ? Standard_False : Standard_True;
2573     if(!isEmpty) {
2574       TDF_ListIteratorOfLabelList itr(aList);
2575       for (; itr.More(); itr.Next())
2576       {
2577         const TDF_Label& aLabel = itr.Value();
2578         if (!aLabel.IsNull()) {
2579           TCollection_AsciiString entry;
2580           TDF_Tool::Entry(aLabel, entry);
2581           di << entry.ToCString() << " ";
2582         }
2583       }
2584       di << "\n";
2585     } else 
2586       di << "List is empty\n";
2587     return 0;
2588   }
2589   di << "DDataStd_GetReferenceList: Error\n";
2590   return 1; 
2591
2592 //
2593 //=======================================================================
2594 //function : SetIntPackedMap (DF, entry, isDelta, key1, key2, ...
2595 //=======================================================================
2596
2597 static Standard_Integer DDataStd_SetIntPackedMap (Draw_Interpretor& di,
2598                                                   Standard_Integer nb, 
2599                                                   const char** arg) 
2600 {   
2601
2602   if (nb > 4) {
2603     Handle(TDF_Data) DF;
2604     if (!DDF::GetDF(arg[1],DF))  return 1; 
2605     TDF_Label aLabel;
2606     DDF::AddLabel(DF, arg[2], aLabel);
2607     Standard_Boolean isDelta = Draw::Atoi(arg[3]) != 0;
2608     Standard_Integer aNum = nb - 4;
2609     Handle(TDataStd_IntPackedMap) anAtt;
2610     if(!aLabel.FindAttribute(TDataStd_IntPackedMap::GetID(), anAtt))
2611       anAtt = TDataStd_IntPackedMap::Set(aLabel, isDelta);
2612     if(anAtt.IsNull()) {
2613       di << "IntPackedMap attribute is not found or not set"  << "\n";
2614       return 1;}
2615     
2616     Standard_Integer j = 4;
2617     TColStd_PackedMapOfInteger aMap;
2618     for(Standard_Integer i = 1; i<=aNum; i++) {
2619       aMap.Add (Draw::Atoi(arg[j]));
2620       j++;
2621     }
2622     const Handle(TColStd_HPackedMapOfInteger)& aHMap = new TColStd_HPackedMapOfInteger(aMap);
2623     anAtt->ChangeMap(aHMap);
2624     cout << "Map extent = " << anAtt->Extent()<<endl;
2625     return 0; 
2626   }
2627   di << "DDataStd_SetIntPackedMap : Error\n";
2628   return 1;
2629
2630
2631 //=======================================================================
2632 //function : GetIntPackedMap (DF, entry )
2633 //=======================================================================
2634
2635 static Standard_Integer DDataStd_GetIntPackedMap (Draw_Interpretor& di,
2636                                                   Standard_Integer nb, 
2637                                                   const char** arg) 
2638 {   
2639
2640   if (nb == 3) {
2641     Handle(TDF_Data) DF;
2642     if (!DDF::GetDF(arg[1],DF))  return 1; 
2643     TDF_Label aLabel;
2644     DDF::AddLabel(DF, arg[2], aLabel);
2645     Handle(TDataStd_IntPackedMap) anAtt;
2646     if(!aLabel.FindAttribute(TDataStd_IntPackedMap::GetID(), anAtt)) {
2647       di << "IntPackedMap attribute is not found or not set"  << "\n";
2648       return 1;}
2649 //
2650     const TColStd_PackedMapOfInteger& aMap = anAtt->GetMap();
2651     TColStd_MapIteratorOfPackedMapOfInteger itr(aMap);
2652     for (Standard_Integer j = 1; itr.More(); itr.Next(),j++){
2653       Standard_Integer aKey(itr.Key());
2654       di << aKey << " ";
2655       }
2656     return 0; 
2657   }
2658   di << "DDataStd_GetIntPackedMap : Error\n";
2659   return 1;
2660
2661
2662
2663 //=======================================================================
2664 //function : ChangeIntPackedMap_Add (DF, entry, Key1, Key2,... )
2665 //=======================================================================
2666 static Standard_Integer DDataStd_ChangeIntPackedMap_Add (Draw_Interpretor& di,
2667                                               Standard_Integer nb, 
2668                                               const char** arg) 
2669 {   
2670
2671   if( nb >= 4 ) {  
2672     Handle(TDF_Data) DF;
2673     if (!DDF::GetDF(arg[1],DF))  return 1;  
2674     TDF_Label label;
2675     if( !DDF::FindLabel(DF, arg[2], label) ) {
2676       di << "No label for entry"  << "\n";
2677       return 1;
2678     }
2679  
2680     Handle(TDataStd_IntPackedMap) A;
2681     if ( !label.FindAttribute(TDataStd_IntPackedMap::GetID(), A) ) { 
2682       di << "There is no TDataStd_IntPackedMap at label"  << "\n";
2683       return 1;
2684     }
2685     
2686     Standard_Integer i, aNum = nb - 3; 
2687     Handle(TColStd_HPackedMapOfInteger) aHMap = A->GetHMap();
2688     Handle(TColStd_HPackedMapOfInteger) ahMap = new TColStd_HPackedMapOfInteger();
2689     if(!aHMap.IsNull()) {
2690       ahMap->ChangeMap().Assign(aHMap->Map());
2691       for(i=1; i<=aNum;i++) {
2692         Standard_Integer val = Draw::Atoi(arg[i+2]);
2693         if(!ahMap->Map().Contains(val))
2694           ahMap->ChangeMap().Add(val);
2695       }
2696       
2697       A->ChangeMap(ahMap);
2698     }
2699     return 0;
2700   }
2701   di << "DDataStd_ChangeIntPackedMap_Add: Error\n";
2702   return 0; 
2703 }
2704
2705
2706 //=======================================================================
2707 //function : ChangeIntPackedMap_Rem (DF, entry, Key1, Key2,... )
2708 //=======================================================================
2709 static Standard_Integer DDataStd_ChangeIntPackedMap_Rem (Draw_Interpretor& di,
2710                                               Standard_Integer nb, 
2711                                               const char** arg) 
2712 {   
2713
2714   if( nb >= 4 ) {  
2715     Handle(TDF_Data) DF;
2716     if (!DDF::GetDF(arg[1],DF))  return 1;  
2717     TDF_Label label;
2718     if( !DDF::FindLabel(DF, arg[2], label) ) {
2719       di << "No label for entry"  << "\n";
2720       return 1;
2721     }
2722  
2723     Handle(TDataStd_IntPackedMap) A;
2724     if ( !label.FindAttribute(TDataStd_IntPackedMap::GetID(), A) ) { 
2725       di << "There is no TDataStd_IntPackedMap at label"  << "\n";
2726       return 1;
2727     }
2728     
2729     Standard_Integer i, aNum = nb - 3; 
2730     Handle(TColStd_HPackedMapOfInteger) aHMap = A->GetHMap();
2731     Handle(TColStd_HPackedMapOfInteger) ahMap = new TColStd_HPackedMapOfInteger();
2732     if(!aHMap.IsNull()) {
2733       ahMap->ChangeMap().Assign(aHMap->Map());
2734       for(i=1; i<=aNum;i++) {
2735         Standard_Integer val = Draw::Atoi(arg[i+2]);
2736         if(ahMap->Map().Contains(val))
2737           ahMap->ChangeMap().Remove(val);
2738       }
2739       
2740       A->ChangeMap(ahMap);
2741     }
2742     return 0;
2743   }
2744   di << "DDataStd_ChangeIntPackedMap_Rem: Error\n";
2745   return 0; 
2746 }
2747
2748 //=======================================================================
2749 //function : ChangeIntPackedMap_AddRem (DF, entry, Key1, Key2,... )
2750 //         : if Keyi exist in map - remove it, if no - add
2751 //=======================================================================
2752 static Standard_Integer DDataStd_ChangeIntPackedMap_AddRem (Draw_Interpretor& di,
2753                                               Standard_Integer nb, 
2754                                               const char** arg) 
2755 {   
2756
2757   if( nb >= 4 ) {  
2758     Handle(TDF_Data) DF;
2759     if (!DDF::GetDF(arg[1],DF))  return 1;  
2760     TDF_Label label;
2761     if( !DDF::FindLabel(DF, arg[2], label) ) {
2762       di << "No label for entry"  << "\n";
2763       return 1;
2764     }
2765  
2766     Handle(TDataStd_IntPackedMap) A;
2767     if ( !label.FindAttribute(TDataStd_IntPackedMap::GetID(), A) ) { 
2768       di << "There is no TDataStd_IntPackedMap at label"  << "\n";
2769       return 1;
2770     }
2771     
2772     Standard_Integer i, aNum = nb - 3; 
2773     Handle(TColStd_HPackedMapOfInteger) aHMap = A->GetHMap();
2774     Handle(TColStd_HPackedMapOfInteger) ahMap = new TColStd_HPackedMapOfInteger();
2775     if(!aHMap.IsNull()) {
2776       ahMap->ChangeMap().Assign(aHMap->Map());
2777       for(i=1; i<=aNum;i++) {
2778         Standard_Integer val = Draw::Atoi(arg[i+2]);
2779         if(!ahMap->Map().Contains(val))
2780           ahMap->ChangeMap().Add(val);
2781         else
2782           ahMap->ChangeMap().Remove(val);
2783       }
2784       
2785       A->ChangeMap(ahMap);
2786     }
2787     return 0;
2788   }
2789   di << "DDataStd_ChangeIntPackedMap_AddRem: Error\n";
2790   return 0; 
2791 }
2792
2793 //=======================================================================
2794 //function : SetIntPHugeMap (DF, entry, isDelta Num)
2795 //=======================================================================
2796
2797 static Standard_Integer DDataStd_SetIntPHugeMap (Draw_Interpretor& di,
2798                                                   Standard_Integer nb, 
2799                                                   const char** arg) 
2800 {   
2801
2802   if (nb > 4) {
2803     Handle(TDF_Data) DF;
2804     if (!DDF::GetDF(arg[1],DF))  return 1; 
2805     TDF_Label aLabel;
2806     DDF::AddLabel(DF, arg[2], aLabel);
2807     Standard_Boolean isDelta = Draw::Atoi(arg[3]) != 0;
2808     Standard_Integer aNum = Draw::Atoi(arg[4]);
2809     Handle(TDataStd_IntPackedMap) anAtt;
2810     if(!aLabel.FindAttribute(TDataStd_IntPackedMap::GetID(), anAtt))
2811       anAtt = TDataStd_IntPackedMap::Set(aLabel, isDelta);
2812     if(anAtt.IsNull()) {
2813       di << "IntPackedMap attribute is not found or not set"  << "\n";
2814       return 1;}
2815     
2816     TColStd_PackedMapOfInteger aMap;
2817     for(Standard_Integer i = 1; i<=aNum; i++) {
2818       aMap.Add (i);
2819     }
2820     const Handle(TColStd_HPackedMapOfInteger)& aHMap = new TColStd_HPackedMapOfInteger(aMap);
2821     anAtt->ChangeMap(aHMap);
2822     cout << "Map extent = " << anAtt->Extent()<<endl;
2823     return 0; 
2824   }
2825   di << "DDataStd_SetIntPHugeMap : Error\n";
2826   return 1;
2827 }
2828
2829 //=======================================================================
2830 //function : SetNDataIntegers (DF, entry , Num
2831 //=======================================================================
2832
2833 static Standard_Integer DDataStd_SetNDataIntegers2 (Draw_Interpretor& di,
2834                                               Standard_Integer nb, 
2835                                               const char** arg) 
2836 {   
2837
2838   if (nb ==4) {
2839     Handle(TDF_Data) DF;
2840     if (!DDF::GetDF(arg[1],DF))  return 1; 
2841     TDF_Label aLabel;
2842     DDF::AddLabel(DF, arg[2], aLabel);
2843     Standard_Integer aNumP = Draw::Atoi(arg[3]), j;
2844     Handle(TDataStd_NamedData) anAtt;
2845     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt))
2846       anAtt = TDataStd_NamedData::Set(aLabel);
2847     if(anAtt.IsNull()) {
2848       di << "NamedData attribute is not found or not set"  << "\n";
2849       return 1;}
2850   
2851     j = 1111;
2852     TCollection_ExtendedString aKey("Key_");
2853     for(Standard_Integer i = 1; i<=aNumP; i++) {
2854       TCollection_ExtendedString key = aKey + i;
2855       Standard_Integer aVal = j+i;
2856       anAtt->SetInteger(key, aVal); 
2857       j +=1;
2858     }    
2859     return 0; 
2860   }
2861   di << "DDataStd_SetNDataIntegers2 : Error\n";
2862   return 1;
2863
2864 //================
2865 //=======================================================================
2866 //function : SetNDataIntArrays2 (DF, entry , key, NumOfArElem )
2867 //=======================================================================
2868
2869 static Standard_Integer DDataStd_SetNDataIntAr2 (Draw_Interpretor& di,
2870                                               Standard_Integer nb, 
2871                                               const char** arg) 
2872 {   
2873
2874   if (nb == 5) {
2875     Handle(TDF_Data) DF;
2876     if (!DDF::GetDF(arg[1],DF))  return 1; 
2877     TDF_Label aLabel;
2878     DDF::AddLabel(DF, arg[2], aLabel);
2879  
2880     Standard_Integer j;
2881     TCollection_ExtendedString aKey(arg[3]);
2882     Standard_Integer aNum = Draw::Atoi(arg[4]);
2883     if (aNum <= 0) return 1;
2884     Handle(TDataStd_NamedData) anAtt;
2885     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt))
2886       anAtt = TDataStd_NamedData::Set(aLabel);
2887     if(anAtt.IsNull()) {
2888       cout<< "NamedData attribute is not found or not set"  << endl;
2889       return 1;}
2890   
2891     j = 15;
2892     Handle(TColStd_HArray1OfInteger) anArr =  new TColStd_HArray1OfInteger(1, aNum);
2893     for(Standard_Integer i = 1; i<=aNum; i++) {
2894       Standard_Integer aVal = j++;
2895       anArr->SetValue(i, aVal);
2896       j++;
2897     }
2898     anAtt->SetArrayOfIntegers(aKey, anArr); 
2899     return 0; 
2900   }
2901   di << "DDataStd_SetNDataIntArrays2 : Error\n";
2902   return 1;
2903
2904
2905
2906 //=======================================================================
2907 //function :  SetAsciiString(DF, entry, String[, guid])
2908 //=======================================================================
2909
2910 static Standard_Integer DDataStd_SetAsciiString (Draw_Interpretor& di,
2911                                               Standard_Integer nb, 
2912                                               const char** arg) 
2913 {   
2914
2915   if (nb == 4 || nb == 5) {
2916     Handle(TDF_Data) DF;
2917     if (!DDF::GetDF(arg[1],DF))  return 1; 
2918     TDF_Label aLabel;
2919     DDF::AddLabel(DF, arg[2], aLabel);
2920     TCollection_AsciiString aString(arg[3]);
2921         Standard_GUID aGuid (TDataStd_AsciiString::GetID());
2922         if(nb == 5) {
2923           if (!Standard_GUID::CheckGUIDFormat(arg[4])) {
2924         di<<"DDataStd_SetAsciiString: The format of GUID is invalid\n";
2925         return 1;
2926           }
2927           aGuid = Standard_GUID (arg[4]);
2928         } 
2929
2930     Handle(TDataStd_AsciiString) anAtt = TDataStd_AsciiString::Set(aLabel, aGuid, aString);
2931     if(anAtt.IsNull()) {
2932       di << "AsciiString attribute is not found or not set"  << "\n";
2933       return 1;
2934         }
2935   
2936     cout << "String = " << anAtt->Get().ToCString() << " is kept in DF" << endl;
2937     return 0; 
2938   }
2939   di << "DDataStd_SetAsciiString : Error\n";
2940   return 1;
2941
2942 //
2943 //=======================================================================
2944 //function :  GetAsciiString(DF, entry[, guid] )
2945 //=======================================================================
2946
2947 static Standard_Integer DDataStd_GetAsciiString (Draw_Interpretor& di,
2948                                               Standard_Integer nb, 
2949                                               const char** arg) 
2950 {   
2951   if (nb == 3 || nb == 4) {
2952     Handle(TDF_Data) DF;
2953     if (!DDF::GetDF(arg[1],DF))  return 1; 
2954     TDF_Label aLabel;           
2955     DDF::FindLabel(DF, arg[2], aLabel);
2956     if(aLabel.IsNull()) di << "Label is not found"   << "\n";
2957     Standard_GUID aGuid (TDataStd_AsciiString::GetID());
2958     if(nb == 4) {
2959       if (!Standard_GUID::CheckGUIDFormat(arg[3])) {
2960         di<<"DDataStd_GetAsciiString: The format of GUID is invalid\n";
2961         return 1;
2962           }
2963           aGuid = Standard_GUID(arg[3]);
2964         }
2965         Handle(TDataStd_AsciiString) anAtt;
2966         if( !aLabel.FindAttribute(aGuid, anAtt) ) {
2967       cout << "AsciiString attribute is not found or not set"  << endl;
2968           return 1;
2969         }
2970
2971 #ifdef DEB_DDataStd
2972       cout << "String = " << anAtt->Get().ToCString()  << endl;
2973 #endif
2974     di << anAtt->Get().ToCString();
2975     return 0; 
2976   }
2977   di << "DDataStd_GetAsciiString : Error\n";
2978   return 1;
2979
2980
2981 //=======================================================================
2982 //function : SetNDataIntegers (DF, entry , Num,  key1, val1, ...
2983 //=======================================================================
2984
2985 static Standard_Integer DDataStd_SetNDataIntegers (Draw_Interpretor& di,
2986                                               Standard_Integer nb, 
2987                                               const char** arg) 
2988 {   
2989
2990   if (nb >=6) {
2991     Handle(TDF_Data) DF;
2992     if (!DDF::GetDF(arg[1],DF))  return 1; 
2993     TDF_Label aLabel;
2994     DDF::AddLabel(DF, arg[2], aLabel);
2995 //
2996 //     TCollection_ExtendedString aString("123456789 0_abcde");
2997 //     Standard_Integer aPos = aString.Search(" ");
2998 //     cout << "From Start = " <<aPos<<endl;
2999 //     aPos = aString.SearchFromEnd(" ");
3000 //     cout << "From Start = " <<aPos<<endl;
3001 //     TCollection_ExtendedString aValue = aString.Split(aPos);
3002 //     cout << "Value = |"<<aValue<<endl;
3003 //     cout << "aKey = " << aString << "|"<<endl;
3004 // 
3005     Standard_Integer aNumP = Draw::Atoi(arg[3]), j;
3006     Handle(TDataStd_NamedData) anAtt;
3007     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt))
3008       anAtt = TDataStd_NamedData::Set(aLabel);
3009     if(anAtt.IsNull()) {
3010       di << "NamedData attribute is not found or not set"  << "\n";
3011       return 1;}
3012   
3013     j = 4;
3014     for(Standard_Integer i = 1; i<=aNumP; i++) {
3015       TCollection_ExtendedString aKey(arg[j]);
3016       Standard_Integer aVal = Draw::Atoi(arg[j+1]);
3017       anAtt->SetInteger(aKey, aVal); 
3018       j +=2;
3019     }    
3020     return 0; 
3021   }
3022   di << "DDataStd_SetNDataIntegers : Error\n";
3023   return 1;
3024
3025
3026
3027 //=======================================================================
3028 //function :  GetNDIntegers(DF, entry )
3029 //=======================================================================
3030 static Standard_Integer DDataStd_GetNDIntegers (Draw_Interpretor& di,
3031                                                 Standard_Integer nb, 
3032                                                 const char** arg) 
3033 {   
3034
3035   if (nb == 3) {
3036     Handle(TDF_Data) DF;
3037     if (!DDF::GetDF(arg[1],DF))  return 1; 
3038     TDF_Label aLabel;
3039     if(!DDF::FindLabel(DF, arg[2], aLabel)) return 1;
3040  
3041
3042     Handle(TDataStd_NamedData) anAtt;
3043     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt)) {
3044       cout << "NamedData attribute is not found or not set"  << endl;
3045       return 1;}
3046     cout <<endl;
3047     cout <<"NamedData attribute at Label = " << arg[2] <<endl;
3048     const TColStd_DataMapOfStringInteger& aMap = anAtt->GetIntegersContainer();
3049     TColStd_DataMapIteratorOfDataMapOfStringInteger itr(aMap);
3050     for (; itr.More(); itr.Next()){
3051       TCollection_ExtendedString aKey(itr.Key());
3052       TCollection_AsciiString aStr(aKey,'?');
3053       Standard_Integer aValue = itr.Value();
3054        cout << "Key = "  << aStr.ToCString() << " Value = " <<aValue<<endl;;
3055       }
3056
3057     return 0; 
3058   }
3059   di << "DDataStd_GetNDIntegers : Error\n";
3060   return 1;
3061
3062
3063 //=======================================================================
3064 //function :  GetNDInteger(DF, entry, key [drawname])
3065 //=======================================================================
3066 static Standard_Integer DDataStd_GetNDInteger (Draw_Interpretor& di,
3067                                                 Standard_Integer nb, 
3068                                                 const char** arg) 
3069 {   
3070
3071   if (nb >=4) {
3072     Handle(TDF_Data) DF;
3073     if (!DDF::GetDF(arg[1],DF))  return 1; 
3074     TDF_Label aLabel;
3075     if(!DDF::FindLabel(DF, arg[2], aLabel)) return 1;
3076  
3077
3078     Handle(TDataStd_NamedData) anAtt;
3079     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt)) {
3080       cout << "NamedData attribute is not found or not set"  << endl;
3081       return 1;}
3082
3083     cout <<endl;
3084     cout <<"NamedData attribute at Label = " << arg[2] <<endl;    
3085     if(!anAtt->HasInteger(arg[3])) {
3086       cout << "There is no data specified by Key = "<< arg[3]  << endl;
3087       return 1;
3088     } else {
3089       cout << "Key = "  << arg[3]  << " Value = " <<anAtt->GetInteger(arg[3])<<endl;
3090       if(nb == 5) 
3091         Draw::Set(arg[4], anAtt->GetInteger(arg[3]));
3092       return 0; 
3093     }
3094   }
3095   di << "DDataStd_SetNDataIntegers : Error\n";
3096   return 1;
3097
3098
3099 //========================== REALS ======================================
3100 //=======================================================================
3101 //function : SetNDataReals (DF, entry , Num,  key1, val1, ...
3102 //=======================================================================
3103
3104 static Standard_Integer DDataStd_SetNDataReals (Draw_Interpretor& di,
3105                                               Standard_Integer nb, 
3106                                               const char** arg) 
3107 {   
3108
3109   if (nb >=6) {
3110     Handle(TDF_Data) DF;
3111     if (!DDF::GetDF(arg[1],DF))  return 1; 
3112     TDF_Label aLabel;
3113     DDF::AddLabel(DF, arg[2], aLabel);
3114  
3115     Standard_Integer aNumP = Draw::Atoi(arg[3]), j;
3116     Handle(TDataStd_NamedData) anAtt;
3117     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt))
3118       anAtt = TDataStd_NamedData::Set(aLabel);
3119     if(anAtt.IsNull()) {
3120       cout << "NamedData attribute is not found or not set"  << endl;;
3121       return 1;}
3122   
3123     j = 4;
3124     for(Standard_Integer i = 1; i<=aNumP; i++) {
3125       TCollection_ExtendedString aKey(arg[j]);
3126       Standard_Real aVal = Draw::Atof(arg[j+1]);
3127       anAtt->SetReal(aKey, aVal); 
3128       j +=2;
3129     }    
3130     return 0; 
3131   }
3132   di << "DDataStd_SetNDataReals : Error\n";
3133   return 1;
3134
3135
3136 //=======================================================================
3137 //function :  GetNDReals(DF, entry )
3138 //=======================================================================
3139 static Standard_Integer DDataStd_GetNDReals (Draw_Interpretor& di,
3140                                                 Standard_Integer nb, 
3141                                                 const char** arg) 
3142 {   
3143
3144   if (nb == 3) {
3145     Handle(TDF_Data) DF;
3146     if (!DDF::GetDF(arg[1],DF))  return 1; 
3147     TDF_Label aLabel;
3148     if(!DDF::FindLabel(DF, arg[2], aLabel)) return 1;
3149  
3150     cout <<endl;
3151     cout <<"NamedData attribute at Label = " << arg[2] <<endl;
3152     Handle(TDataStd_NamedData) anAtt;
3153     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt)) {
3154       cout << "NamedData attribute is not found or not set"  << endl;
3155       return 1;}
3156     
3157     const TDataStd_DataMapOfStringReal& aMap = anAtt->GetRealsContainer();
3158     TDataStd_DataMapIteratorOfDataMapOfStringReal itr(aMap);
3159     for (; itr.More(); itr.Next()){
3160       TCollection_ExtendedString aKey(itr.Key());
3161       TCollection_AsciiString aStr(aKey,'?');
3162       Standard_Real aValue = itr.Value();
3163        cout << "Key = "  << aStr.ToCString() << " Value = " <<aValue<<endl;
3164       }
3165     return 0; 
3166   }
3167   di << "DDataStd_GetNDReals : Error\n";
3168   return 1;
3169
3170
3171 //=======================================================================
3172 //function :  GetNDReal(DF, entry, key [drawname])
3173 //=======================================================================
3174 static Standard_Integer DDataStd_GetNDReal (Draw_Interpretor& di,
3175                                                 Standard_Integer nb, 
3176                                                 const char** arg) 
3177 {   
3178
3179   if (nb >=4) {
3180     Handle(TDF_Data) DF;
3181     if (!DDF::GetDF(arg[1],DF))  return 1; 
3182     TDF_Label aLabel;
3183     if(!DDF::FindLabel(DF, arg[2], aLabel)) return 1;
3184  
3185
3186     Handle(TDataStd_NamedData) anAtt;
3187     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt)) {
3188       cout << "NamedData attribute is not found or not set"  << endl;
3189       return 1;}
3190
3191     cout <<endl;
3192     cout <<"NamedData attribute at Label = " << arg[2] <<endl;    
3193     if(!anAtt->HasReal(arg[3])) {
3194       cout << "There is no data specified by Key = "<< arg[3]  << endl;
3195       return 1;
3196     } else {
3197       cout << "Key = "  << arg[3]  << " Value = " <<anAtt->GetReal(arg[3])<<endl;
3198       if(nb == 5) 
3199         Draw::Set(arg[4], anAtt->GetReal(arg[3]));
3200       return 0; 
3201     }
3202   }
3203   di << "DDataStd_GetNDReal : Error\n";
3204   return 1;
3205
3206
3207 //======================= Strings =======================================
3208 //=======================================================================
3209 //function : SetNDataStrings (DF, entry , Num,  key1, val1, ...
3210 //=======================================================================
3211
3212 static Standard_Integer DDataStd_SetNDataStrings (Draw_Interpretor& di,
3213                                                   Standard_Integer nb, 
3214                                                   const char** arg) 
3215 {   
3216
3217   if (nb >=6) {
3218     Handle(TDF_Data) DF;
3219     if (!DDF::GetDF(arg[1],DF))  return 1; 
3220     TDF_Label aLabel;
3221     DDF::AddLabel(DF, arg[2], aLabel);
3222  
3223     Standard_Integer aNumP = Draw::Atoi(arg[3]), j;
3224     Handle(TDataStd_NamedData) anAtt;
3225     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt))
3226       anAtt = TDataStd_NamedData::Set(aLabel);
3227     if(anAtt.IsNull()) {
3228       di << "NamedData attribute is not found or not set"  << "\n";
3229       return 1;}
3230   
3231     j = 4;
3232     for(Standard_Integer i = 1; i<=aNumP; i++) {
3233       TCollection_ExtendedString aKey(arg[j]);
3234       TCollection_ExtendedString aVal(arg[j+1]);
3235       anAtt->SetString(aKey, aVal); 
3236       j +=2;
3237     }    
3238     return 0; 
3239   }
3240   di << "DDataStd_SetNDataStrings : Error\n";
3241   return 1;
3242
3243
3244 //=======================================================================
3245 //function :  GetNDStrings(DF, entry )
3246 //=======================================================================
3247 static Standard_Integer DDataStd_GetNDStrings (Draw_Interpretor& di,
3248                                                 Standard_Integer nb, 
3249                                                 const char** arg) 
3250 {   
3251
3252   if (nb == 3) {
3253     Handle(TDF_Data) DF;
3254     if (!DDF::GetDF(arg[1],DF))  return 1; 
3255     TDF_Label aLabel;
3256     if(!DDF::FindLabel(DF, arg[2], aLabel)) return 1;
3257  
3258
3259     Handle(TDataStd_NamedData) anAtt;
3260     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt)) {
3261       cout << "NamedData attribute is not found or not set"  << endl;
3262       return 1;}
3263     cout <<endl;
3264     cout <<"NamedData attribute at Label = " << arg[2] <<endl;    
3265     const TDataStd_DataMapOfStringString& aMap = anAtt->GetStringsContainer();
3266     TDataStd_DataMapIteratorOfDataMapOfStringString itr(aMap);
3267     for (; itr.More(); itr.Next()){
3268       TCollection_ExtendedString aKey(itr.Key());
3269       TCollection_AsciiString aStr(aKey,'?');
3270       TCollection_ExtendedString aVal(itr.Value());
3271       TCollection_AsciiString aStrValue(aVal,'?');
3272       cout << "Key = "  << aStr.ToCString() << " Value = " <<aStrValue.ToCString()<< endl;
3273       }
3274     return 0; 
3275   }
3276   di << "DDataStd_GetNDStrings : Error\n";
3277   return 1;
3278
3279
3280 //=======================================================================
3281 //function :  GetNDString(DF, entry, key [drawname])
3282 //=======================================================================
3283 static Standard_Integer DDataStd_GetNDString (Draw_Interpretor& di,
3284                                               Standard_Integer nb, 
3285                                               const char** arg) 
3286 {   
3287
3288   if (nb >=4) {
3289     Handle(TDF_Data) DF;
3290     if (!DDF::GetDF(arg[1],DF))  return 1; 
3291     TDF_Label aLabel;
3292     if(!DDF::FindLabel(DF, arg[2], aLabel)) return 1;
3293  
3294
3295     Handle(TDataStd_NamedData) anAtt;
3296     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt)) {
3297       di << "NamedData attribute is not found or not set"  << "\n";
3298       return 1;}
3299
3300     cout <<endl;
3301     cout <<"NamedData attribute at Label = " << arg[2] <<endl;    
3302     if(!anAtt->HasString(arg[3])) {
3303       cout << "There is no data specified by Key = "<< arg[3]  << endl;
3304       return 1;
3305     } else {
3306       TCollection_AsciiString aValue (anAtt->GetString(arg[3]), '?');
3307       cout << "Key = "  << arg[3]  << " Value = " << aValue.ToCString() << endl;
3308       if(nb == 5) 
3309         Draw::Set(arg[4], aValue.ToCString());
3310       return 0; 
3311     }
3312   }
3313   di << "DDataStd_GetNDString : Error\n";
3314   return 1;
3315
3316
3317 //=========================== Bytes =====================================
3318 //=======================================================================
3319 //function : SetNDataBytes (DF, entry , Num,  key1, val1, ...
3320 //=======================================================================
3321
3322 static Standard_Integer DDataStd_SetNDataBytes (Draw_Interpretor& di,
3323                                                 Standard_Integer nb, 
3324                                                 const char** arg) 
3325 {   
3326
3327   if (nb >=6) {
3328     Handle(TDF_Data) DF;
3329     if (!DDF::GetDF(arg[1],DF))  return 1; 
3330     TDF_Label aLabel;
3331     DDF::AddLabel(DF, arg[2], aLabel);
3332  
3333     Standard_Integer aNumP = Draw::Atoi(arg[3]), j;
3334     Handle(TDataStd_NamedData) anAtt;
3335     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt))
3336       anAtt = TDataStd_NamedData::Set(aLabel);
3337     if(anAtt.IsNull()) {
3338       cout << "NamedData attribute is not found or not set"  << endl;
3339       return 1;}
3340   
3341     j = 4;
3342     for(Standard_Integer i = 1; i<=aNumP; i++) {
3343       TCollection_ExtendedString aKey(arg[j]);
3344       Standard_Byte aVal = (Standard_Byte)Draw::Atoi(arg[j+1]);
3345       anAtt->SetByte(aKey, aVal); 
3346       j +=2;
3347     }    
3348     return 0; 
3349   }
3350   di << "DDataStd_SetNDataBytes : Error\n";
3351   return 1;
3352
3353
3354 //=======================================================================
3355 //function :  GetNDBytes(DF, entry )
3356 //=======================================================================
3357 static Standard_Integer DDataStd_GetNDBytes (Draw_Interpretor& di,
3358                                                 Standard_Integer nb, 
3359                                                 const char** arg) 
3360 {   
3361
3362   if (nb == 3) {
3363     Handle(TDF_Data) DF;
3364     if (!DDF::GetDF(arg[1],DF))  return 1; 
3365     TDF_Label aLabel;
3366     if(!DDF::FindLabel(DF, arg[2], aLabel)) return 1;
3367  
3368
3369     Handle(TDataStd_NamedData) anAtt;
3370     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt)) {
3371       cout << "NamedData attribute is not found or not set"  << endl;
3372       return 1;}
3373     cout <<endl;
3374     cout <<"NamedData attribute at Label = " << arg[2] <<endl;      
3375     const TDataStd_DataMapOfStringByte& aMap = anAtt->GetBytesContainer();
3376     TDataStd_DataMapIteratorOfDataMapOfStringByte itr(aMap);
3377     for (; itr.More(); itr.Next()){
3378       TCollection_ExtendedString aKey(itr.Key());
3379       TCollection_AsciiString aStr(aKey,'?');
3380       Standard_Byte aValue = itr.Value();
3381       cout << "Key = "  << aStr.ToCString() << " Value = " <<aValue<<endl;
3382       }
3383     return 0; 
3384   }
3385   di << "DDataStd_GetNDBytes : Error\n";
3386   return 1;
3387
3388
3389 //=======================================================================
3390 //function :  GetNDByte(DF, entry, key [drawname])
3391 //=======================================================================
3392 static Standard_Integer DDataStd_GetNDByte (Draw_Interpretor& di,
3393                                                 Standard_Integer nb, 
3394                                                 const char** arg) 
3395 {   
3396
3397   if (nb >=4) {
3398     Handle(TDF_Data) DF;
3399     if (!DDF::GetDF(arg[1],DF))  return 1; 
3400     TDF_Label aLabel;
3401     if(!DDF::FindLabel(DF, arg[2], aLabel)) return 1;
3402  
3403
3404     Handle(TDataStd_NamedData) anAtt;
3405     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt)) {
3406       cout << "NamedData attribute is not found or not set"  << endl;
3407       return 1;}
3408
3409     cout <<endl;
3410     cout <<"NamedData attribute at Label = " << arg[2] <<endl;      
3411     if(!anAtt->HasByte(arg[3])) {
3412       cout << "There is no data specified by Key = "<< arg[3]  << endl;
3413       return 1;
3414     } else {
3415       cout << "Key = "  << arg[3]  << " Value = " <<anAtt->GetByte(arg[3])<< endl;
3416       if(nb == 5) 
3417         Draw::Set(arg[4], anAtt->GetByte(arg[3]));
3418       return 0; 
3419     }
3420   }
3421   di << "DDataStd_GetNDByte : Error\n";
3422   return 1;
3423
3424 //======================== IntArrays ====================================
3425 //=======================================================================
3426 //function : SetNDataIntArrays (DF, entry , key, NumOfArElem, val1, val2,...  )
3427 //=======================================================================
3428
3429 static Standard_Integer DDataStd_SetNDataIntAr (Draw_Interpretor& di,
3430                                               Standard_Integer nb, 
3431                                               const char** arg) 
3432 {   
3433
3434   if (nb >=6) {
3435     Handle(TDF_Data) DF;
3436     if (!DDF::GetDF(arg[1],DF))  return 1; 
3437     TDF_Label aLabel;
3438     DDF::AddLabel(DF, arg[2], aLabel);
3439  
3440     Standard_Integer j;
3441     TCollection_ExtendedString aKey(arg[3]);
3442     Standard_Integer aNum = Draw::Atoi(arg[4]);
3443     if (aNum <= 0) return 1;
3444     Handle(TDataStd_NamedData) anAtt;
3445     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt))
3446       anAtt = TDataStd_NamedData::Set(aLabel);
3447     if(anAtt.IsNull()) {
3448       cout<< "NamedData attribute is not found or not set"  << endl;
3449       return 1;}
3450   
3451     j = 5;
3452     Handle(TColStd_HArray1OfInteger) anArr =  new TColStd_HArray1OfInteger(1, aNum);
3453     for(Standard_Integer i = 1; i<=aNum; i++) {
3454       Standard_Integer aVal = Draw::Atoi(arg[j]);
3455       anArr->SetValue(i, aVal);
3456       j++;
3457     }
3458     anAtt->SetArrayOfIntegers(aKey, anArr); 
3459     return 0; 
3460   }
3461   di << "DDataStd_SetNDataIntArrays : Error\n";
3462   return 1;
3463
3464
3465
3466 //=======================================================================
3467 //function :  GetNDIntArrays(DF, entry )
3468 //=======================================================================
3469 static Standard_Integer DDataStd_GetNDIntArrays (Draw_Interpretor& di,
3470                                                  Standard_Integer nb, 
3471                                                  const char** arg) 
3472 {   
3473
3474   if (nb == 3) {
3475     Handle(TDF_Data) DF;
3476     if (!DDF::GetDF(arg[1],DF))  return 1; 
3477     TDF_Label aLabel;
3478     if(!DDF::FindLabel(DF, arg[2], aLabel)) return 1;
3479     
3480     
3481     Handle(TDataStd_NamedData) anAtt;
3482     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt)) {
3483       cout << "NamedData attribute is not found or not set"  << endl;
3484       return 1;}
3485     cout <<endl;
3486     cout <<"NamedData attribute at Label = " << arg[2] <<endl;      
3487     const TDataStd_DataMapOfStringHArray1OfInteger& aMap = anAtt->GetArraysOfIntegersContainer();
3488     TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger itr(aMap);
3489     for (; itr.More(); itr.Next()){
3490       TCollection_ExtendedString aKey(itr.Key());
3491       TCollection_AsciiString aStr(aKey,'?');
3492       cout << "Key = "  << aStr.ToCString()<< endl;
3493       Handle(TColStd_HArray1OfInteger) anArrValue = itr.Value();      
3494       if(!anArrValue.IsNull()) {
3495         Standard_Integer lower = anArrValue->Lower();
3496         Standard_Integer upper = anArrValue->Upper();
3497         for(Standard_Integer i = lower; i<=upper;i++) {
3498           Standard_Integer aValue = anArrValue->Value(i);
3499           cout << "\tValue("<<i<<") = " <<aValue<<endl;
3500         }
3501       } else 
3502          cout << "\tthe specified array is Null "<<endl;
3503     }
3504     return 0; 
3505   }
3506   di << "DDataStd_GetNDIntArrays : Error\n";
3507   return 1;
3508
3509
3510 //=======================================================================
3511 //function :  GetNDIntArray(DF, entry, key )
3512 //=======================================================================
3513 static Standard_Integer DDataStd_GetNDIntArray (Draw_Interpretor& di,
3514                                                 Standard_Integer nb, 
3515                                                 const char** arg) 
3516 {   
3517
3518   if (nb >=4) {
3519     Handle(TDF_Data) DF;
3520     if (!DDF::GetDF(arg[1],DF))  return 1; 
3521     TDF_Label aLabel;
3522     if(!DDF::FindLabel(DF, arg[2], aLabel)) return 1;
3523  
3524
3525     Handle(TDataStd_NamedData) anAtt;
3526     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt)) {
3527       cout << "NamedData attribute is not found or not set"  << endl;
3528       return 1;}
3529
3530     cout <<endl;
3531     cout <<"NamedData attribute at Label = " << arg[2] <<endl;      
3532     if(!anAtt->HasArrayOfIntegers(arg[3])) {
3533       cout << "There is no data specified by Key = "<< arg[3]  << endl;
3534       return 1;
3535     } else {
3536       cout << "Key = "  << arg[3] <<endl;
3537
3538       Handle(TColStd_HArray1OfInteger) anArrValue = anAtt->GetArrayOfIntegers(arg[3]);      
3539       if(!anArrValue.IsNull()) {
3540         Standard_Integer lower = anArrValue->Lower();
3541         Standard_Integer upper = anArrValue->Upper();
3542         for(Standard_Integer i = lower; i<=upper;i++) {
3543           Standard_Integer aValue = anArrValue->Value(i);
3544           cout << "\tValue("<<i<<") = " <<aValue<<endl;
3545         }
3546       } else 
3547         cout << "\tthe specified array is Null or not found"<<endl;
3548       return 0; 
3549     }
3550   }
3551   di << "DDataStd_SetNDataIntArray : Error\n";
3552   return 1;
3553
3554 //============================= RealArrays ==============================
3555 //=======================================================================
3556 //function : SetNDataRealArrays (DF entry key NumOfArElem val1 val2...  )
3557 //=======================================================================
3558
3559 static Standard_Integer DDataStd_SetNDataRealAr (Draw_Interpretor& di,
3560                                               Standard_Integer nb, 
3561                                               const char** arg) 
3562 {   
3563
3564   if (nb >=6) {
3565     Handle(TDF_Data) DF;
3566     if (!DDF::GetDF(arg[1],DF))  return 1; 
3567     TDF_Label aLabel;
3568     DDF::AddLabel(DF, arg[2], aLabel);
3569  
3570     Standard_Integer j;
3571     TCollection_ExtendedString aKey(arg[3]);
3572     Standard_Integer aNum = Draw::Atoi(arg[4]);
3573     if (aNum <= 0) return 1;
3574     Handle(TDataStd_NamedData) anAtt;
3575     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt))
3576       anAtt = TDataStd_NamedData::Set(aLabel);
3577     if(anAtt.IsNull()) {
3578       cout << "NamedData attribute is not found or not set"  << endl;
3579       return 1;}
3580   
3581     j = 5;
3582     Handle(TColStd_HArray1OfReal) anArr =  new TColStd_HArray1OfReal(1, aNum);
3583     for(Standard_Integer i = 1; i<=aNum; i++) {
3584       Standard_Real aVal = Draw::Atof(arg[j]);
3585       anArr->SetValue(i, aVal);
3586       j++;
3587     }
3588     anAtt->SetArrayOfReals(aKey, anArr); 
3589     return 0; 
3590   }
3591   di << "DDataStd_SetNDataRealArrays : Error\n";
3592   return 1;
3593
3594
3595
3596 //=======================================================================
3597 //function :  GetNDRealArrays(DF, entry )
3598 //=======================================================================
3599 static Standard_Integer DDataStd_GetNDRealArrays (Draw_Interpretor& di,
3600                                                   Standard_Integer nb, 
3601                                                   const char** arg) 
3602 {   
3603
3604   if (nb == 3) {
3605     Handle(TDF_Data) DF;
3606     if (!DDF::GetDF(arg[1],DF))  return 1; 
3607     TDF_Label aLabel;
3608     if(!DDF::FindLabel(DF, arg[2], aLabel)) return 1;
3609     
3610     
3611     Handle(TDataStd_NamedData) anAtt;
3612     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt)) {
3613       cout << "NamedData attribute is not found or not set"  << endl;
3614       return 1;}
3615     cout <<endl;
3616     cout <<"NamedData attribute at Label = " << arg[2] <<endl;      
3617     const TDataStd_DataMapOfStringHArray1OfReal& aMap = anAtt->GetArraysOfRealsContainer();
3618     TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal itr(aMap);
3619     for (; itr.More(); itr.Next()){
3620       TCollection_ExtendedString aKey(itr.Key());
3621       TCollection_AsciiString aStr(aKey,'?');
3622       cout << "Key = "  << aStr.ToCString()<<endl;
3623       Handle(TColStd_HArray1OfReal) anArrValue = itr.Value();      
3624       if(!anArrValue.IsNull()) {
3625         Standard_Integer lower = anArrValue->Lower();
3626         Standard_Integer upper = anArrValue->Upper();
3627         for(Standard_Integer i = lower; i<=upper;i++) {
3628           Standard_Real aValue = anArrValue->Value(i);
3629           cout << "\tValue("<<i<<") = " <<aValue<<endl;
3630         }
3631       } else 
3632          cout << "\tthe specified array is Null "<<endl;
3633     }
3634     return 0; 
3635   }
3636   di << "DDataStd_GetNDRealArrays : Error\n";
3637   return 1;
3638
3639
3640 //=======================================================================
3641 //function :  GetNDRealArray(DF, entry, key )
3642 //=======================================================================
3643 static Standard_Integer DDataStd_GetNDRealArray (Draw_Interpretor& di,
3644                                                  Standard_Integer nb, 
3645                                                  const char** arg) 
3646 {   
3647
3648   if (nb >=4) {
3649     Handle(TDF_Data) DF;
3650     if (!DDF::GetDF(arg[1],DF))  return 1; 
3651     TDF_Label aLabel;
3652     if(!DDF::FindLabel(DF, arg[2], aLabel)) return 1;
3653  
3654
3655     Handle(TDataStd_NamedData) anAtt;
3656     if(!aLabel.FindAttribute(TDataStd_NamedData::GetID(), anAtt)) {
3657       di << "NamedData attribute is not found or not set"  << "\n";
3658       return 1;}
3659
3660     cout <<endl;
3661     cout <<"NamedData attribute at Label = " << arg[2] <<endl;      
3662     if(!anAtt->HasArrayOfReals(arg[3])) {
3663       cout << "There is no data specified by Key = "<< arg[3]  << endl;
3664       return 1;
3665     } else {
3666       cout << "Key = "  << arg[3] <<endl;
3667
3668       Handle(TColStd_HArray1OfReal) anArrValue = anAtt->GetArrayOfReals(arg[3]);      
3669       if(!anArrValue.IsNull()) {
3670         Standard_Integer lower = anArrValue->Lower();
3671         Standard_Integer upper = anArrValue->Upper();
3672         for(Standard_Integer i = lower; i<=upper;i++) {
3673           Standard_Real aValue = anArrValue->Value(i);
3674           cout << "\tValue("<<i<<") = " <<aValue<<endl;
3675         }
3676       } else 
3677         cout << "\tthe specified array is Null or not found"<<endl;
3678       return 0; 
3679     }
3680   }
3681   di << "DDataStd_SetNDataRealArray : Error\n";
3682   return 1;
3683 }
3684
3685 //=======================================================================
3686 //function : SetRefArray (DF, entry , From, To,  elmt1, elmt2, ...
3687 //=======================================================================
3688 static Standard_Integer DDataStd_SetRefArray (Draw_Interpretor& di,
3689                                               Standard_Integer nb,
3690                                               const char** arg) 
3691 {
3692   Handle(TDF_Data) DF;
3693   if (!DDF::GetDF(arg[1],DF))  return 1;  
3694   TDF_Label label; 
3695   DDF::AddLabel(DF, arg[2], label);
3696  
3697   Standard_Integer From = Draw::Atoi(arg[3]), To = Draw::Atoi( arg[4] ), j;
3698   di << "RefArray with bounds from = " << From  << " to = " << To  << "\n";
3699
3700   Handle(TDataStd_ReferenceArray) A = TDataStd_ReferenceArray::Set(label, From, To);
3701   
3702   if (nb >= 6) {
3703     j = 5;
3704     for(Standard_Integer i = From; i<=To; i++) { 
3705       TDF_Label aRefLabel; 
3706       DDF::AddLabel(DF, arg[j], aRefLabel);
3707       A->SetValue(i, aRefLabel); 
3708       j++;
3709     }
3710   }
3711   return 0;  
3712
3713
3714 //=======================================================================
3715 //function : SetRefArrayValue (DF, entry, index, value)
3716 //=======================================================================
3717 static Standard_Integer DDataStd_SetRefArrayValue (Draw_Interpretor&,
3718                                                    Standard_Integer,
3719                                                    const char** arg) 
3720 {
3721   // Get document.
3722   Handle(TDF_Data) DF;
3723   if (!DDF::GetDF(arg[1], DF))
3724     return 1;
3725
3726   // Get label.
3727   TDF_Label label; 
3728   if (!DDF::AddLabel(DF, arg[2], label))
3729     return 1;
3730  
3731   // Get index and value.
3732   Standard_Integer index = Draw::Atoi(arg[3]);
3733
3734   // Set new value.
3735   Handle(TDataStd_ReferenceArray) arr;
3736   if (label.FindAttribute(TDataStd_ReferenceArray::GetID(), arr))
3737   {
3738     TDF_Label aRefLabel; 
3739     DDF::AddLabel(DF, arg[4], aRefLabel);
3740     arr->SetValue(index, aRefLabel); 
3741     return 0;
3742   }
3743
3744   return 1;
3745
3746
3747 //=======================================================================
3748 //function : GetRefArray (DF, entry )
3749 //=======================================================================
3750 static Standard_Integer DDataStd_GetRefArray (Draw_Interpretor& di,
3751                                               Standard_Integer, 
3752                                               const char** arg) 
3753 {   
3754
3755   Handle(TDF_Data) DF;
3756   if (!DDF::GetDF(arg[1],DF))  return 1;  
3757   TDF_Label label;
3758   if( !DDF::FindLabel(DF, arg[2], label) ) {
3759     di << "No label for entry"  << "\n";
3760     return 1;
3761   }
3762  
3763   Handle(TDataStd_ReferenceArray) A;
3764   if ( !label.FindAttribute(TDataStd_ReferenceArray::GetID(), A) ) { 
3765     di << "There is no TDataStd_ReferenceArray under label"  << "\n";
3766     return 1;
3767   }
3768   
3769   for(Standard_Integer i = A->Lower(); i<=A->Upper(); i++){ 
3770     const TDF_Label& aLabel = A->Value(i);
3771     TCollection_AsciiString entry;
3772     TDF_Tool::Entry(aLabel, entry);
3773     di  <<  entry.ToCString();
3774     if(i<A->Upper())  
3775       di<<" ";
3776   }
3777   di<<"\n";
3778   return 0; 
3779
3780
3781 //=======================================================================
3782 //function : GetRefArrayValue (DF, entry, index)
3783 //=======================================================================
3784 static Standard_Integer DDataStd_GetRefArrayValue (Draw_Interpretor& di,
3785                                                    Standard_Integer, 
3786                                                    const char** arg) 
3787 {
3788   Handle(TDF_Data) DF;
3789   if (!DDF::GetDF(arg[1],DF))
3790       return 1;
3791
3792   TDF_Label label;
3793   if (!DDF::FindLabel(DF, arg[2], label)) {
3794     di << "No label for entry"  << "\n";
3795     return 1;
3796   }
3797  
3798   Handle(TDataStd_ReferenceArray) A;
3799   if ( !label.FindAttribute(TDataStd_ReferenceArray::GetID(), A) ) { 
3800     di << "There is no TDataStd_ReferenceArray under label"  << "\n";
3801     return 1;
3802   }
3803   
3804   Standard_Integer index = Draw::Atoi(arg[3]);
3805   if (index < A->Lower() || index > A->Upper()) {
3806     di << "Index is out of range\n";
3807     return 1;
3808   } else {
3809     const TDF_Label& value = A->Value(index);
3810     TCollection_AsciiString entry;
3811     TDF_Tool::Entry(value, entry);
3812     di << entry.ToCString() << "\n";
3813   }
3814
3815   return 0; 
3816
3817
3818 //=======================================================================
3819 //function : DDataStd_SetTriangulation
3820 //purpose  : SetTriangulation (DF, entry, face)
3821 //=======================================================================
3822
3823 static Standard_Integer DDataStd_SetTriangulation (Draw_Interpretor& di,
3824                                                    Standard_Integer nb,
3825                                                    const char** arg)
3826 {
3827   if (nb == 4)
3828   {
3829     Handle(TDF_Data) DF;
3830     if (!DDF::GetDF(arg[1],DF))
3831       return 1;
3832
3833     TDF_Label L;
3834     if (!DDF::AddLabel(DF, arg[2], L))
3835       return 1;
3836
3837     // Get face.
3838     TopoDS_Shape face = DBRep::Get(arg[3]);
3839     if (face.IsNull() ||
3840         face.ShapeType() != TopAbs_FACE)
3841     {
3842       di << "The face is null or not a face.\n";
3843       return 1;
3844     }
3845
3846     // Get triangulation of the face.
3847     TopLoc_Location loc;
3848     Handle(Poly_Triangulation) tris = BRep_Tool::Triangulation(TopoDS::Face(face), loc);
3849     if (tris.IsNull())
3850     {
3851       di << "No triangulation in the face.\n";
3852       return 1;
3853     }
3854
3855     // Set the attribute.
3856     TDataXtd_Triangulation::Set(L, tris);
3857     return 0;
3858   }
3859   di << "DDataStd_SetTriangulation : Error\n";
3860   return 1;
3861 }
3862
3863 //=======================================================================
3864 //function : DDataStd_DumpTriangulation
3865 //purpose  : DumpTriangulation (DF, entry)
3866 //=======================================================================
3867
3868 static Standard_Integer DDataStd_DumpMesh (Draw_Interpretor& di,
3869                                            Standard_Integer nb,
3870                                            const char** arg)
3871 {
3872   if (nb == 3)
3873   {
3874     Handle(TDF_Data) DF;
3875     if (!DDF::GetDF(arg[1],DF))
3876       return 1;
3877
3878     Handle(TDataXtd_Triangulation) PT;
3879     if (!DDF::Find(DF,arg[2], TDataXtd_Triangulation::GetID(), PT))
3880     {
3881       di << "The attribute doesn't exist at the label.\n";
3882       return 1;
3883     }
3884
3885     // Dump of the triangulation.
3886     if (PT->Get().IsNull())
3887     {
3888       di << "No triangulation in the attribute.\n";
3889       return 1;
3890     }
3891
3892     di << "Deflection            " << PT->Deflection() <<"\n";
3893     di << "Number of nodes       " << PT->NbNodes() << "\n";
3894     di << "Number of triangles   " << PT->NbTriangles() << "\n";
3895     if (PT->HasUVNodes())
3896         di << "It has 2d-nodes\n";
3897     if (PT->HasNormals())
3898         di << "It has normals\n";
3899
3900     return 0;
3901   }
3902   di << "DDataStd_DumpTriangulation : Error\n";
3903   return 1;
3904 }
3905
3906 //=======================================================================
3907 //function : BasicCommands
3908 //purpose  : 
3909 //=======================================================================
3910
3911 void DDataStd::BasicCommands (Draw_Interpretor& theCommands)
3912 {  
3913
3914   static Standard_Boolean done = Standard_False;
3915   if (done) return;
3916   done = Standard_True;
3917
3918   const char* g = "DData : Standard Attribute Commands";
3919
3920
3921   // SET
3922
3923   theCommands.Add ("SetInteger", 
3924                    "SetInteger (DF, entry, value [,guid])",
3925                    __FILE__, DDataStd_SetInteger, g);
3926
3927   theCommands.Add ("SetIntArray", 
3928                    "SetIntArray (DF, entry, isDelta, From, To, [elmt1, elmt2, ...])",
3929                    __FILE__, DDataStd_SetIntArray, g);
3930
3931   theCommands.Add ("SetIntArrayValue", 
3932                    "SetIntArrayValue (DF, entry, index, value)",
3933                    __FILE__, DDataStd_SetIntArrayValue, g);
3934   
3935   theCommands.Add ("SetReal", 
3936                    "SetReal (DF, entry, value [,guid])",
3937                    __FILE__, DDataStd_SetReal, g); 
3938
3939   theCommands.Add ("SetRealArray", 
3940                    "SetRealArray (DF, entry, isDelta, From, To, [elmt1, elmt2, ...])",
3941                    __FILE__, DDataStd_SetRealArray, g);
3942
3943   theCommands.Add ("SetRealArrayValue", 
3944                    "SetRealArrayValue (DF, entry, index, value)",
3945                    __FILE__, DDataStd_SetRealArrayValue, g);
3946
3947   theCommands.Add ("SetByteArray", 
3948                    "SetByteArray (DF, entry, isDelta, From, To, [elmt1, elmt2, ...])",
3949                    __FILE__, DDataStd_SetByteArray, g);
3950
3951   theCommands.Add ("SetByteArrayValue", 
3952                    "SetByteArrayValue (DF, entry, index, value)",
3953                    __FILE__, DDataStd_SetByteArrayValue, g);
3954
3955   theCommands.Add ("SetExtStringArray", 
3956                    "SetExtStringArray (DF, entry, isDelta, From, To, [elmt1, elmt2, ...])",
3957                    __FILE__, DDataStd_SetExtStringArray, g);
3958
3959   theCommands.Add ("SetExtStringArrayValue", 
3960                    "SetExtStringArrayValue (DF, entry, index, value)",
3961                    __FILE__, DDataStd_SetExtStringArrayValue, g);
3962
3963   theCommands.Add ("SetRefArray", 
3964                    "SetRefArray (DF, entry,  From, To, [lab1, lab2, ...])",
3965                    __FILE__, DDataStd_SetRefArray, g);
3966
3967   theCommands.Add ("SetRefArrayValue", 
3968                    "SetRefArrayValue (DF, entry, index, value)",
3969                    __FILE__, DDataStd_SetRefArrayValue, g);
3970
3971   theCommands.Add ("SetIntPackedMap", 
3972                    "SetIntPackedMap (DF, entry, isDelta, key1, key2, ...  )",
3973                    __FILE__, DDataStd_SetIntPackedMap, g);
3974
3975   theCommands.Add ("SetReference", 
3976                    "SetReference (DF, entry, reference)",
3977                    __FILE__, DDataStd_SetReference, g);  
3978
3979   theCommands.Add ("SetComment", 
3980                    "SetComment (DF, entry, comment)",
3981                    __FILE__, DDataStd_SetComment, g);    
3982   
3983   theCommands.Add ("SetUAttribute", 
3984                    "SetUAttribute (DF, entry, LocalID)",
3985                    __FILE__, DDataStd_SetUAttribute, g);
3986
3987   theCommands.Add ("SetVariable", 
3988                    "SetVariable (DF, entry, isConstant[0/1], units)",
3989                    __FILE__, DDataStd_SetVariable, g);
3990
3991   theCommands.Add ("SetAsciiString", 
3992                    "SetAsciiString (DF, entry, String  )",
3993                    __FILE__, DDataStd_SetAsciiString, g);
3994
3995   theCommands.Add ("SetBooleanArray", 
3996                    "SetBooleanArray (DF, entry, isDelta, From, To, [elmt1, elmt2, ...])",
3997                    __FILE__, DDataStd_SetBooleanArray, g);
3998
3999   theCommands.Add ("SetBooleanArrayValue", 
4000                    "SetBooleanArrayValue (DF, entry, index, value)",
4001                    __FILE__, DDataStd_SetBooleanArrayValue, g);
4002
4003   theCommands.Add ("SetBooleanList", 
4004                    "SetBooleanList (DF, entry, elmt1, elmt2, ...  )",
4005                    __FILE__, DDataStd_SetBooleanList, g);
4006
4007   theCommands.Add ("SetIntegerList", 
4008                    "SetIntegerList (DF, entry, elmt1, elmt2, ...  )",
4009                    __FILE__, DDataStd_SetIntegerList, g);
4010
4011   theCommands.Add ("SetRealList", 
4012                    "SetRealList (DF, entry, elmt1, elmt2, ...  )",
4013                    __FILE__, DDataStd_SetRealList, g);
4014
4015    theCommands.Add ("SetExtStringList", 
4016                    "SetExtStringList (DF, entry, elmt1, elmt2, ...  )",
4017                    __FILE__, DDataStd_SetExtStringList, g);
4018
4019    theCommands.Add ("SetReferenceList", 
4020                    "SetReferenceList (DF, entry, elmt1, elmt2, ...  )",
4021                    __FILE__, DDataStd_SetReferenceList, g);
4022
4023   theCommands.Add ("SetTriangulation", 
4024                    "SetTriangulation (DF, entry, face) - adds label with passed entry to \
4025                     DF and put an attribute with the triangulation from passed face",
4026                    __FILE__, DDataStd_SetTriangulation, g);
4027
4028    // Insert before and after (for lists)
4029
4030    theCommands.Add ("InsertBeforeExtStringList", 
4031                    "InsertBeforeExtStringList (DF, entry, index, value )",
4032                    __FILE__, DDataStd_InsertBeforeExtStringList, g);
4033
4034    theCommands.Add ("InsertAfterExtStringList", 
4035                    "InsertAfterExtStringList (DF, entry, index, value )",
4036                    __FILE__, DDataStd_InsertAfterExtStringList, g);
4037
4038    theCommands.Add ("RemoveExtStringList", 
4039                    "RemoveExtStringList (DF, entry, index )",
4040                    __FILE__, DDataStd_RemoveExtStringList, g);
4041
4042    theCommands.Add ("InsertBeforeBooleanList", 
4043                    "InsertBeforeBooleanList (DF, entry, index, value )",
4044                    __FILE__, DDataStd_InsertBeforeBooleanList, g);
4045
4046    theCommands.Add ("InsertAfterBooleanList", 
4047                    "InsertAfterBooleanList (DF, entry, index, value )",
4048                    __FILE__, DDataStd_InsertAfterBooleanList, g);
4049
4050    theCommands.Add ("RemoveBooleanList", 
4051                    "RemoveBooleanList (DF, entry, index )",
4052                    __FILE__, DDataStd_RemoveBooleanList, g);
4053
4054    theCommands.Add ("InsertBeforeIntegerList", 
4055                    "InsertBeforeIntegerList (DF, entry, index, value )",
4056                    __FILE__, DDataStd_InsertBeforeIntegerList, g);
4057
4058    theCommands.Add ("InsertAfterIntegerList", 
4059                    "InsertAfterIntegerList (DF, entry, index, value )",
4060                    __FILE__, DDataStd_InsertAfterIntegerList, g);
4061
4062    theCommands.Add ("RemoveIntegerList", 
4063                    "RemoveIntegerList (DF, entry, index )",
4064                    __FILE__, DDataStd_RemoveIntegerList, g);
4065
4066    theCommands.Add ("InsertBeforeRealList", 
4067                    "InsertBeforeRealList (DF, entry, index, value )",
4068                    __FILE__, DDataStd_InsertBeforeRealList, g);
4069
4070    theCommands.Add ("InsertAfterRealList", 
4071                    "InsertAfterRealList (DF, entry, index, value )",
4072                    __FILE__, DDataStd_InsertAfterRealList, g);
4073
4074    theCommands.Add ("RemoveRealList", 
4075                    "RemoveRealList (DF, entry, index )",
4076                    __FILE__, DDataStd_RemoveRealList, g);
4077
4078    theCommands.Add ("InsertBeforeReferenceList", 
4079                    "InsertBeforeReferenceList (DF, entry, index, value )",
4080                    __FILE__, DDataStd_InsertBeforeReferenceList, g);
4081
4082    theCommands.Add ("InsertAfterReferenceList", 
4083                    "InsertAfterReferenceList (DF, entry, index, value )",
4084                    __FILE__, DDataStd_InsertAfterReferenceList, g);
4085
4086    theCommands.Add ("RemoveReferenceList", 
4087                    "RemoveReferenceList (DF, entry, index )",
4088                    __FILE__, DDataStd_RemoveReferenceList, g);
4089
4090   // GET
4091
4092   theCommands.Add ("GetAsciiString", 
4093                    "GetAsciiString (DF, entry  )",
4094                    __FILE__, DDataStd_GetAsciiString, g);
4095
4096   theCommands.Add ("GetInteger", 
4097                    "GetInteger (DF, entry, [drawname][, guid])",
4098                     __FILE__, DDataStd_GetInteger, g);
4099
4100   theCommands.Add ("GetIntArray", 
4101                    "GetIntArray (DF, entry )",
4102                    __FILE__, DDataStd_GetIntArray, g);
4103
4104   theCommands.Add ("GetIntArrayValue", 
4105                    "GetIntArrayValue (DF, entry, index)",
4106                    __FILE__, DDataStd_GetIntArrayValue, g);
4107
4108   theCommands.Add ("GetRealArray", 
4109                    "GetRealArray (DF, entry )",
4110                    __FILE__, DDataStd_GetRealArray, g);
4111
4112   theCommands.Add ("GetRealArrayValue", 
4113                    "GetRealArrayValue (DF, entry, index)",
4114                    __FILE__, DDataStd_GetRealArrayValue, g);
4115
4116   theCommands.Add ("GetByteArray", 
4117                    "GetByteArray (DF, entry )",
4118                    __FILE__, DDataStd_GetByteArray, g);
4119
4120   theCommands.Add ("GetByteArrayValue", 
4121                    "GetByteArrayValue (DF, entry, index)",
4122                    __FILE__, DDataStd_GetByteArrayValue, g);
4123
4124   theCommands.Add ("GetExtStringArray", 
4125                    "GetExtStringArray (DF, entry )",
4126                    __FILE__, DDataStd_GetExtStringArray, g);
4127
4128   theCommands.Add ("GetExtStringArrayValue", 
4129                    "GetExtStringArrayValue (DF, entry, index)",
4130                    __FILE__, DDataStd_GetExtStringArrayValue, g);
4131
4132   theCommands.Add ("GetRefArray", 
4133                    "GetRefArray (DF, entry )",
4134                    __FILE__, DDataStd_GetRefArray, g);
4135
4136   theCommands.Add ("GetRefArrayValue", 
4137                    "GetRefArrayValue (DF, entry, index)",
4138                    __FILE__, DDataStd_GetRefArrayValue, g);
4139
4140   theCommands.Add ("GetIntPackedMap", 
4141                    "GetIntPackedMap (DF, entry  )",
4142                    __FILE__, DDataStd_GetIntPackedMap, g);
4143
4144   theCommands.Add ("GetReal", 
4145                    "GetReal (DF, entry, [drawname][, guid])",
4146                     __FILE__, DDataStd_GetReal, g);  
4147
4148   theCommands.Add ("GetReference", 
4149                    "GetReference (DF, entry)",
4150                    __FILE__, DDataStd_GetReference, g);
4151
4152   
4153   theCommands.Add ("GetComment", 
4154                    "GetComment (DF, entry)",
4155                    __FILE__, DDataStd_GetComment, g); 
4156
4157   theCommands.Add("Self", 
4158                   "Self(document, entry)", 
4159                   __FILE__, DDataStd_Self, g);  
4160
4161   theCommands.Add ("GetUAttribute", 
4162                    "GetUAttribute (DF, entry)",
4163                    __FILE__, DDataStd_GetUAttribute, g);
4164
4165   theCommands.Add ("GetVariable", 
4166                    "GetVariable (DF, entry, [isConstant], [units])",
4167                    __FILE__, DDataStd_GetVariable, g);
4168
4169   theCommands.Add ("SetRelation", 
4170                    "SetRelation (DF, entry, expression, var1[, var2, ...])",
4171                    __FILE__, DDataStd_SetRelation, g);
4172
4173   theCommands.Add ("DumpRelation", 
4174                    "DumpRelation (DF, entry)",
4175                    __FILE__, DDataStd_DumpRelation, g);
4176
4177   theCommands.Add ("GetBooleanArray", 
4178                    "GetBooleanArray (DF, entry )",
4179                    __FILE__, DDataStd_GetBooleanArray, g);
4180
4181   theCommands.Add ("GetBooleanArrayValue", 
4182                    "GetBooleanArrayValue (DF, entry, index)",
4183                    __FILE__, DDataStd_GetBooleanArrayValue, g);
4184
4185   theCommands.Add ("GetBooleanList", 
4186                    "GetBooleanList (DF, entry )",
4187                    __FILE__, DDataStd_GetBooleanList, g);
4188
4189   theCommands.Add ("GetIntegerList", 
4190                    "GetIntegerList (DF, entry )",
4191                    __FILE__, DDataStd_GetIntegerList, g);
4192
4193   theCommands.Add ("GetRealList", 
4194                    "GetRealList (DF, entry )",
4195                    __FILE__, DDataStd_GetRealList, g);
4196
4197   theCommands.Add ("GetExtStringList", 
4198                    "GetExtStringList (DF, entry)",
4199                    __FILE__, DDataStd_GetExtStringList, g);
4200
4201    theCommands.Add ("GetReferenceList", 
4202                     "GetReferenceList (DF, entry)",
4203                    __FILE__, DDataStd_GetReferenceList, g);
4204
4205 // ========================= UTF =====================================
4206   const char* ggg = "UTF Commands";
4207
4208   theCommands.Add ("SetUTFName", 
4209                    "SetUTFName (DF, entry, fileName)",
4210                    __FILE__, DDataStd_KeepUTF, ggg);
4211
4212   theCommands.Add ("GetUTF", 
4213                    "GetUTF (DF, entry, fileName)",
4214                    __FILE__, DDataStd_GetUTFtoFile, ggg);
4215
4216  //======================= NData Commands ========================
4217  
4218   const char* gN = "NData Commands";
4219   theCommands.Add ("SetNDataIntegers", 
4220                    "SetNDataIntegers (DF, entry, NumPairs, key1, val1, ...  )",
4221                    __FILE__, DDataStd_SetNDataIntegers, gN);
4222
4223   theCommands.Add ("SetNDataReals", 
4224                    "SetNDataReals (DF, entry, NumPairs, key1, val1, ...  )",
4225                    __FILE__, DDataStd_SetNDataReals, gN);
4226
4227   theCommands.Add ("SetNDataStrings", 
4228                    "SetNDataStrings (DF, entry, NumPairs, key1, val1, ...  )",
4229                    __FILE__, DDataStd_SetNDataStrings, gN);
4230
4231   theCommands.Add ("SetNDataBytes", 
4232                    "SetNDataBytes (DF, entry, NumPairs, key1, val1, ...  )",
4233                    __FILE__, DDataStd_SetNDataBytes, gN);
4234
4235   theCommands.Add ("SetNDataIntArrays", 
4236                    "SetNDataIntArrays (DF entry entry  key NumOfArrElems val1 val2...  )",
4237                    __FILE__, DDataStd_SetNDataIntAr, gN); 
4238
4239   theCommands.Add ("SetNDataRealArrays", 
4240                    "SetNDataRealArrays (DF entry key NumOfArrElems val1 val2...  )",
4241                   __FILE__, DDataStd_SetNDataRealAr, gN); 
4242
4243  // GET
4244
4245   theCommands.Add ("GetNDIntegers", 
4246                    "GetNDIntegers (DF, entry )",
4247                    __FILE__, DDataStd_GetNDIntegers, g);
4248
4249   theCommands.Add ("GetNDInteger", 
4250                    "GetNDInteger (DF entry key [drawname])",
4251                    __FILE__, DDataStd_GetNDInteger, g);
4252
4253   theCommands.Add ("GetNDReals", 
4254                    "GetNDReals (DF entry )",
4255                    __FILE__, DDataStd_GetNDReals, g);
4256
4257   theCommands.Add ("GetNDReal", 
4258                    "GetNDReal (DF entry key [drawname])",
4259                    __FILE__, DDataStd_GetNDReal, g);
4260
4261    theCommands.Add ("GetNDStrings", 
4262                    "GetNDStrings (DF entry )",
4263                    __FILE__, DDataStd_GetNDStrings, g);
4264
4265   theCommands.Add ("GetNDString", 
4266                    "GetNDString (DF entry key [drawname])",
4267                    __FILE__, DDataStd_GetNDString, g);
4268
4269   theCommands.Add ("GetNDBytes", 
4270                    "GetNDBytes (DF entry )",
4271                    __FILE__, DDataStd_GetNDBytes, g);
4272
4273   theCommands.Add ("GetNDByte", 
4274                    "GetNDByte (DF entry key [drawname])",
4275                    __FILE__, DDataStd_GetNDByte, g);
4276
4277   theCommands.Add ("GetNDIntArrays", 
4278                    "GetNDIntArrays (DF, entry )",
4279                    __FILE__, DDataStd_GetNDIntArrays, g);
4280
4281   theCommands.Add ("GetNDIntArray", 
4282                    "GetNDIntArray (DF entry key )",
4283                    __FILE__, DDataStd_GetNDIntArray, g);
4284
4285   theCommands.Add ("GetNDRealArrays", 
4286                    "GetNDRealArrays (DF entry )",
4287                    __FILE__, DDataStd_GetNDRealArrays, g);
4288
4289   theCommands.Add ("GetNDRealArray", 
4290                    "GetNDRealArray (DF entry key )",
4291                    __FILE__, DDataStd_GetNDRealArray, g);
4292   
4293 //====================== Change =======================
4294   theCommands.Add ("ChangeByteArray", 
4295                    "ChangeByteArray (DF, entry, indx, value )",
4296                    __FILE__, DDataStd_ChangeByteArray, g);
4297
4298   theCommands.Add ("ChangeIntArray", 
4299                    "ChangeIntArray (DF, entry, indx, value )",
4300                    __FILE__, DDataStd_ChangeIntArray, g);
4301
4302   theCommands.Add ("ChangeRealArray", 
4303                    "ChangeRealArray (DF, entry, indx, value )",
4304                    __FILE__, DDataStd_ChangeRealArray, g);
4305
4306   theCommands.Add ("ChangeExtStrArray", 
4307                    "ChangeExtStrArray (DF, entry, indx, value )",
4308                    __FILE__, DDataStd_ChangeExtStrArray, g);
4309
4310   theCommands.Add ("ChangeIntPackedMap_Add", 
4311                    "ChangeIntPackedMAp_Add (DF, entry, key[,key [...]] )",
4312                    __FILE__, DDataStd_ChangeIntPackedMap_Add, g);
4313
4314   theCommands.Add ("ChangeIntPackedMap_Rem", 
4315                    "ChangeIntPackedMAp_Rem (DF, entry, key[,key [...]] )",
4316                    __FILE__, DDataStd_ChangeIntPackedMap_Rem, g);
4317
4318   theCommands.Add ("ChangeIntPackedMap_AddRem", 
4319                    "ChangeIntPackedMAp_AddRem (DF, entry, key[,key [...]] )",
4320                    __FILE__, DDataStd_ChangeIntPackedMap_AddRem, g);
4321  
4322 //=========================================================
4323   // TFunction commands
4324   const char* gg = "DFunction Commands";
4325
4326   theCommands.Add ("SetFunction", 
4327                    "SetFunction (DF, entry, guid, failure)",
4328                    __FILE__, DDataStd_SetFunction, gg);
4329
4330   theCommands.Add ("GetFunction", 
4331                    "GetFunction (DF, entry, guid(out), failure(out))",
4332                    __FILE__, DDataStd_GetFunction, gg); 
4333
4334 //=========================================================
4335
4336    theCommands.Add ("DumpTriangulation", 
4337                    "DumpTriangulations (DF, entry) - dumps info about triangulation that \
4338                     stored in DF in triangulation attribute of a label with the passed entry",
4339                     __FILE__, DDataStd_DumpMesh, g);
4340
4341 //======================================================================
4342 //======= for internal use
4343
4344   theCommands.Add ("SetNDataIntegers2", 
4345                    "SetNDataIntegers2 (DF, entry, NumPair  )",
4346                    __FILE__, DDataStd_SetNDataIntegers2, gN);
4347
4348   theCommands.Add ("SetNDataIntArrays2", 
4349                    "SetNDataIntArrays2 (DF entry entry  key NumOfArrElems)",
4350                    __FILE__, DDataStd_SetNDataIntAr2, gN); 
4351   
4352   theCommands.Add ("SetIntArrayT", 
4353                    "SetIntArrayT (DF, entry, isDelta, From, To  )",
4354                    __FILE__, DDataStd_SetIntArrayTest, g);
4355
4356   theCommands.Add ("SetIntPHugeMap", 
4357                     "SetIntPHugeMap (DF, entry, isDelta Num)",
4358                     __FILE__, DDataStd_SetIntPHugeMap, g);
4359
4360 //=======
4361
4362 }