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