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