0030180: Data Exchange - VrmlAPI_Writer is expected to return export state
[occt.git] / src / XDEDRAW / XDEDRAW_GDTs.cxx
1 // Created on: 2015-06-18
2 // Created by: Ilya Novikov
3 // Copyright (c) 2000-2015 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <XDEDRAW_GDTs.hxx>
17
18 #include <Draw.hxx>
19 #include <DBRep.hxx>
20 #include <DDocStd.hxx>
21 #include <DrawTrSurf.hxx>
22 #include <Geom_Plane.hxx>
23
24 #include <STEPCAFControl_GDTProperty.hxx>
25
26 #include <TDF_Tool.hxx>
27 #include <TDF_Label.hxx>
28 #include <TDF_LabelSequence.hxx>
29 #include <TDocStd_Document.hxx>
30 #include <XCAFDoc_GraphNode.hxx>
31
32 #include <XCAFDoc.hxx>
33 #include <XCAFDoc_DocumentTool.hxx>
34 #include <XCAFDoc_ShapeTool.hxx>
35 #include <XCAFDoc_DimTol.hxx>
36 #include <XCAFDoc_Dimension.hxx>
37 #include <XCAFDimTolObjects_DimensionObject.hxx>
38 #include <XCAFDoc_Datum.hxx>
39 #include <XCAFDimTolObjects_DatumObject.hxx>
40 #include <XCAFDoc_GeomTolerance.hxx>
41 #include <XCAFDimTolObjects_GeomToleranceObject.hxx>
42 #include <XCAFDoc_DimTolTool.hxx>
43 #include <XCAFDimTolObjects_DimensionObjectSequence.hxx>
44 #include <XCAFDimTolObjects_DatumObjectSequence.hxx>
45 #include <XCAFDimTolObjects_GeomToleranceObjectSequence.hxx>
46 #include <XCAFDimTolObjects_DatumSingleModif.hxx>
47 #include <XCAFDimTolObjects_DimensionModif.hxx>
48 #include <XCAFDimTolObjects_GeomToleranceModif.hxx>
49 #include <XCAFDimTolObjects_DatumModifiersSequence.hxx>
50 #include <XCAFDimTolObjects_DatumObject.hxx>
51 #include <XCAFDimTolObjects_Tool.hxx>
52
53 #include <TCollection_AsciiString.hxx>
54 #include <TCollection_HAsciiString.hxx>
55 #include <TColStd_HArray1OfReal.hxx>
56 #include <TColgp_HArray1OfPnt.hxx>
57
58 #include <TopoDS.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <TopoDS_Edge.hxx>
61 #include <TopoDS_Vertex.hxx>
62 #include <BRep_Tool.hxx>
63
64
65
66 static Standard_Integer DumpDGTs (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
67 {
68   if (argc < 3) {
69     di<<"Use: XDumpDGTs Doc shape/label/all\n";
70     return 1;
71   }
72   Handle(TDocStd_Document) Doc;
73   DDocStd::GetDocument(argv[1], Doc);
74   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
75   Handle(XCAFDoc_DimTolTool) aDimTolTool= XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
76   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
77
78   TCollection_AsciiString name = argv[2];
79   TDF_LabelSequence aLabels;
80   if(name.IsEqual("all"))
81   {
82     aShapeTool->GetShapes(aLabels);
83     for ( Standard_Integer i=1; i <= aLabels.Length(); i++ )
84     {
85       aShapeTool->GetSubShapes(aLabels.Value(i), aLabels);
86     }
87   }
88   else
89   {
90     TDF_Label aLabel;
91     TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
92     if ( !aLabel.IsNull() ) {
93       aLabels.Append(aLabel);
94       aShapeTool->GetSubShapes(aLabel, aLabels);
95     }
96     else
97     {
98       TopoDS_Shape aShape= DBRep::Get(argv[2]);
99       if ( !aShape.IsNull() )
100       {
101         aShapeTool->Search(aShape, aLabel);
102         if ( !aLabel.IsNull() ) {
103           aLabels.Append(aLabel);
104           aShapeTool->GetSubShapes(aLabel, aLabels);
105         }
106         else
107         {
108           di<<"Shape "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
109           return 1;
110         }
111       }
112     }
113   }
114
115   for ( Standard_Integer i=1; i <= aLabels.Length(); i++ )
116   {
117     Standard_Boolean flag = Standard_True;
118     TDF_LabelSequence aGDTs;
119     aDimTolTool->GetRefDimensionLabels(aLabels.Value(i), aGDTs);
120     for ( Standard_Integer j=1; j <= aGDTs.Length(); j++ )
121     {
122       Handle(XCAFDoc_Dimension) aDimTol;
123       if(aGDTs.Value(j).FindAttribute(XCAFDoc_Dimension::GetID(), aDimTol))
124       {
125         Handle(XCAFDimTolObjects_DimensionObject) aDimTolObj = aDimTol->GetObject();
126         if(flag)
127         {
128           TCollection_AsciiString Entry;
129           TDF_Tool::Entry(aLabels.Value(i), Entry);
130           di << "\n " << Entry << " Shape."<< i;
131           flag = Standard_False;
132         }
133         TCollection_AsciiString Entry;
134         TDF_Tool::Entry(aGDTs.Value(j), Entry);
135         di << "\n \t " << Entry;
136         flag = Standard_False;
137
138         di << " Dimension."<< i << "."<< j;
139         if (argc > 3)
140         {
141           di <<" (";
142           if (aDimTolObj->GetSemanticName())
143           {
144             di << " N \"" << aDimTolObj->GetSemanticName()->String() << "\"";
145           }
146           di << " T " << aDimTolObj->GetType();
147           if(aDimTolObj->IsDimWithRange())
148           {
149             di << ", LB " << aDimTolObj->GetLowerBound();
150             di << ", UB " << aDimTolObj->GetUpperBound();
151           }
152           else
153           {
154             di << ", V " << aDimTolObj->GetValue();
155             if (aDimTolObj->IsDimWithPlusMinusTolerance())
156             {
157               di << ", VL " << aDimTolObj->GetLowerTolValue();
158               di << ", VU " << aDimTolObj->GetUpperTolValue();
159             }
160             else if (aDimTolObj->IsDimWithClassOfTolerance())
161             {
162               Standard_Boolean isH;
163               XCAFDimTolObjects_DimensionFormVariance aFV;
164               XCAFDimTolObjects_DimensionGrade aG;
165               aDimTolObj->GetClassOfTolerance(isH, aFV, aG);
166               di << ", H " << (Standard_Integer)isH<< " F " << aFV << " G " << aG;
167             }
168           }
169           if (aDimTolObj->HasQualifier())
170             di << ", Q " << aDimTolObj->GetQualifier();
171           if (aDimTolObj->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented)
172           {
173             gp_Dir aD;
174             aDimTolObj->GetDirection(aD);
175             di << ", D (" << aD.X() << ", " << aD.Y() << ", " << aD.Z() << ")";
176           }
177           XCAFDimTolObjects_DimensionModifiersSequence aModif = 
178             aDimTolObj->GetModifiers();
179           if (!aModif.IsEmpty())
180           {
181             di << ",";
182             for (Standard_Integer k = aModif.Lower(); k <= aModif.Upper(); k++)
183             {
184               di << " M " << aModif.Value(k);
185             }
186           }
187           di << ", P " << (Standard_Integer)!aDimTolObj->GetPath().IsNull();
188           di << " )";
189         }
190       }
191     }
192     aGDTs.Clear();
193     aDimTolTool->GetRefGeomToleranceLabels(aLabels.Value(i), aGDTs);
194     for ( Standard_Integer j=1; j <= aGDTs.Length(); j++ )
195     {
196       Handle(XCAFDoc_GeomTolerance) aDimTol;
197       if(aGDTs.Value(j).FindAttribute(XCAFDoc_GeomTolerance::GetID(), aDimTol))
198       {
199         Handle(XCAFDimTolObjects_GeomToleranceObject) aDimTolObj = aDimTol->GetObject();
200         if(flag)
201         {
202           TCollection_AsciiString Entry;
203           TDF_Tool::Entry(aLabels.Value(i), Entry);
204           di << "\n " << Entry << " Shape."<< i;
205           flag = Standard_False;
206         }
207         TCollection_AsciiString Entry;
208         TDF_Tool::Entry(aGDTs.Value(j), Entry);
209         di << "\n \t " << Entry;
210         flag = Standard_False;
211
212         di << " GeomTolerance."<< i << "."<< j;
213         if (argc > 3)
214         {
215           di <<" (";
216           if (aDimTolObj->GetSemanticName())
217           {
218             di << " N \"" << aDimTolObj->GetSemanticName()->String() << "\"";
219           }
220           di << " T " << aDimTolObj->GetType();
221           di << " TV " << aDimTolObj->GetTypeOfValue();
222           di << ", V " << aDimTolObj->GetValue();
223
224           if (aDimTolObj->HasAxis())
225           {
226             gp_Ax2 anAx = aDimTolObj->GetAxis();
227             di << ", A ( L (" << anAx.Location().X() << anAx.Location().Y() << anAx.Location().Z()
228               << "), XD (" << anAx.XDirection().X() << anAx.XDirection().Y() << anAx.XDirection().Z()
229               << "), RD (" << anAx.YDirection().X() << anAx.YDirection().Y() << anAx.YDirection().Z() << "))";
230           }
231           XCAFDimTolObjects_GeomToleranceModifiersSequence aModif = 
232             aDimTolObj->GetModifiers();
233           if (!aModif.IsEmpty())
234           {
235             di << ",";
236             for (Standard_Integer k = aModif.Lower(); k <= aModif.Upper(); k++)
237             {
238               di << " M " << aModif.Value(k);
239             }
240           }
241           if (aDimTolObj->GetMaterialRequirementModifier() != XCAFDimTolObjects_GeomToleranceMatReqModif_None)
242           {
243             di << ", MR " << aDimTolObj->GetMaterialRequirementModifier();
244           }
245           if (aDimTolObj->GetMaxValueModifier() > 0)
246           {
247             di << "MaxV " << aDimTolObj->GetMaxValueModifier();
248           }
249           if ( aDimTolObj->GetZoneModifier() != XCAFDimTolObjects_GeomToleranceZoneModif_None)
250           {
251             di << ", ZM " << aDimTolObj->GetZoneModifier();
252             if (aDimTolObj->GetValueOfZoneModifier() > 0)
253             {
254               di << " ZMV " <<aDimTolObj->GetValueOfZoneModifier();
255             }
256           }
257           di << " )";
258         }
259         Handle(XCAFDoc_GraphNode) aNode;
260         if(aGDTs.Value(j).FindAttribute(XCAFDoc::DatumTolRefGUID(), aNode) && aNode->NbChildren() > 0)
261         {
262           for(Standard_Integer k = 1; k<=aNode->NbChildren(); k++)
263           {
264             Handle(XCAFDoc_Datum) aDatum;
265             if(aNode->GetChild(k)->Label().FindAttribute(XCAFDoc_Datum::GetID(), aDatum))
266             {
267               Handle(XCAFDimTolObjects_DatumObject) aDatumObj = aDatum->GetObject();
268               TCollection_AsciiString anEntry;
269               TDF_Tool::Entry(aNode->GetChild(k)->Label(), anEntry);
270               di << "\n \t \t " << anEntry;
271               di << " Datum."<< i << "."<< j << "."<< k;
272               if (argc > 3)
273               {
274                 di << " (";
275                 if (aDimTolObj->GetSemanticName())
276                 {
277                   di << " N \"" << aDimTolObj->GetSemanticName()->String() << "\"";
278                 }
279                 XCAFDimTolObjects_DatumModifiersSequence aModif = 
280                   aDatumObj->GetModifiers();
281                 if (!aModif.IsEmpty())
282                 {
283                   di << ",";
284                   for (Standard_Integer iModif = aModif.Lower(); iModif <= aModif.Upper(); iModif++)
285                   {
286                     di << " M " << aModif.Value(iModif);
287                   }
288                 }
289                 XCAFDimTolObjects_DatumModifWithValue aM;
290                 Standard_Real aV;
291                 aDatumObj->GetModifierWithValue(aM, aV);
292                 if (aM != XCAFDimTolObjects_DatumModifWithValue_None)
293                 {
294                   di << ", MV" << aM << " " << aV; 
295                 }
296                 di << " )";
297               }
298             }
299           }
300         }
301       }
302     }
303     TDF_LabelSequence aDatumL;
304     if (aDimTolTool->GetRefDatumLabel(aLabels.Value(i), aDatumL))
305     {
306       for(Standard_Integer j = aDatumL.Lower(); j <= aDatumL.Upper(); j++)
307       {
308         Handle(XCAFDoc_Datum) aDatum;
309         if(aDatumL.Value(j).FindAttribute(XCAFDoc_Datum::GetID(), aDatum) && 
310            aDatum->GetObject()->IsDatumTarget())
311         {
312           Handle(XCAFDimTolObjects_DatumObject) aDatumObj = aDatum->GetObject();
313           if(flag)
314           {
315             TCollection_AsciiString Entry;
316             TDF_Tool::Entry(aLabels.Value(i), Entry);
317             di << "\n " << Entry << " Shape."<< i;
318             flag = Standard_False;
319           }
320           TCollection_AsciiString Entry;
321           TDF_Tool::Entry(aDatumL.First(), Entry);
322           di << "\n \t " << Entry;
323           flag = Standard_False;
324
325           di << " Datum target."<< i << "."<< j;
326           if (argc > 3)
327           {
328             di <<" (";
329             if (aDatumObj->GetSemanticName())
330             {
331               di << " N \"" << aDatumObj->GetSemanticName()->String() << "\"";
332             }
333             di << " T " << aDatumObj->GetDatumTargetType();
334             if (aDatumObj->GetDatumTargetType() != XCAFDimTolObjects_DatumTargetType_Area)
335             {
336               gp_Ax2 anAx = aDatumObj->GetDatumTargetAxis();
337                di << ", A ( L (" << anAx.Location().X() << anAx.Location().Y() << anAx.Location().Z()
338                 << "), XD (" << anAx.XDirection().X() << anAx.XDirection().Y() << anAx.XDirection().Z()
339                 << "), RD (" << anAx.YDirection().X() << anAx.YDirection().Y() << anAx.YDirection().Z() << "))";
340               if (aDatumObj->GetDatumTargetType() != XCAFDimTolObjects_DatumTargetType_Point)
341               {
342                 di << ", L " << aDatumObj->GetDatumTargetLength() ;
343                 if (aDatumObj->GetDatumTargetType() == XCAFDimTolObjects_DatumTargetType_Rectangle)
344                 {
345                   di << ", W " << aDatumObj->GetDatumTargetWidth() ;
346                 }
347               }
348             }
349             di << " )";
350           }
351         }
352       }
353     }
354   }
355   return 0;
356 }
357
358 static Standard_Integer DumpNbDGTs (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
359 {
360   if (argc < 2) {
361     di<<"Use: XDumpNbDGTs Doc";
362     return 1;
363   }
364
365   Standard_Boolean isFull = Standard_False;
366   if (argc == 3) {
367     char aChar = argv[2][0];
368     if (aChar == 'f')
369       isFull = Standard_True;
370   }
371   Handle(TDocStd_Document) Doc;
372   DDocStd::GetDocument(argv[1], Doc);
373   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
374   Handle(XCAFDoc_DimTolTool) aDimTolTool= XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
375   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
376
377   TDF_LabelSequence aLabels;
378   aShapeTool->GetShapes(aLabels);
379   for ( Standard_Integer i=1; i <= aLabels.Length(); i++ )
380   {
381     aShapeTool->GetSubShapes(aLabels.Value(i), aLabels);
382   }
383
384   TDF_LabelSequence aGDTs;
385   aDimTolTool->GetDimensionLabels(aGDTs);
386   di << "\n NbOfDimensions          : " << aGDTs.Length();
387   if (isFull) {
388     Standard_Integer nbSize = 0,
389                      nbLocation = 0,
390                      nbAngular = 0,
391                      nbWithPath = 0,
392                      nbCommon = 0;
393     for (Standard_Integer i = 1; i <= aGDTs.Length(); i++) {
394       Handle(XCAFDoc_Dimension) aDimAttr;
395       if (!aGDTs.Value(i).FindAttribute(XCAFDoc_Dimension::GetID(),aDimAttr)) 
396         continue;
397       Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimAttr->GetObject();
398       if (anObject.IsNull())
399         continue;
400       XCAFDimTolObjects_DimensionType aDimType = anObject->GetType();
401       if (aDimType == XCAFDimTolObjects_DimensionType_CommonLabel) {
402         nbCommon++;
403       }
404       else if (STEPCAFControl_GDTProperty::IsDimensionalLocation(aDimType)) {
405         nbLocation++;
406       }
407       else if (aDimType == XCAFDimTolObjects_DimensionType_Location_Angular) {
408         nbAngular++;
409         nbLocation++;
410       }
411       else if (aDimType == XCAFDimTolObjects_DimensionType_Location_WithPath) {
412         nbLocation++;
413         nbWithPath++;
414       }
415       else if (STEPCAFControl_GDTProperty::IsDimensionalSize(aDimType)) {
416         nbSize++;
417       }
418       else if (aDimType == XCAFDimTolObjects_DimensionType_Size_Angular) {
419         nbSize++;
420         nbAngular++;
421       }
422       else if (aDimType == XCAFDimTolObjects_DimensionType_Size_WithPath) {
423         nbSize++;
424         nbWithPath++;
425       }
426     }
427     di << "\n  NbOfDimensionalSize    : " << nbSize;
428     di << "\n  NbOfDimensionalLocation: " << nbLocation;
429     di << "\n  NbOfAngular            : " << nbAngular;
430     di << "\n  NbOfWithPath           : " << nbWithPath;
431     di << "\n  NbOfCommonLabels       : " << nbCommon;
432   }
433
434   aGDTs.Clear();
435   aDimTolTool->GetGeomToleranceLabels(aGDTs);
436   di << "\n NbOfTolerances          : " << aGDTs.Length();
437   if (isFull) {
438     Standard_Integer nbWithModif = 0,
439                      nbWithMaxTol = 0,
440                      nbWithDatumRef = 0;
441     for (Standard_Integer i = 1; i <= aGDTs.Length(); i++) {
442       Handle(XCAFDoc_GeomTolerance) aGTAttr;
443       if (!aGDTs.Value(i).FindAttribute(XCAFDoc_GeomTolerance::GetID(),aGTAttr)) 
444         continue;
445       Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject();
446       if (anObject.IsNull())
447         continue;
448       if (anObject->GetMaterialRequirementModifier() != XCAFDimTolObjects_GeomToleranceMatReqModif_None) {
449         nbWithModif++;
450       }
451       else if (anObject->GetModifiers().Length() > 0) {
452         Standard_Boolean isHasModif = Standard_False;
453         for (Standard_Integer j = 1; j <= anObject->GetModifiers().Length(); j++)
454           if (anObject->GetModifiers().Value(j) != XCAFDimTolObjects_GeomToleranceModif_All_Around &&
455             anObject->GetModifiers().Value(j) != XCAFDimTolObjects_GeomToleranceModif_All_Over) {
456             isHasModif = Standard_True;
457             break;
458           }
459         if (isHasModif)
460           nbWithModif++;
461       }
462       if (anObject->GetMaxValueModifier() != 0) {
463         nbWithMaxTol++;
464       }
465       TDF_LabelSequence aDatumSeq;
466       aDimTolTool->GetDatumWithObjectOfTolerLabels(aGDTs.Value(i), aDatumSeq);
467       if (aDatumSeq.Length() > 0) {
468         nbWithDatumRef++;
469       }
470     }
471     di << "\n  NbOfGTWithModifiers    : " << nbWithModif;
472     di << "\n  NbOfGTWithMaxTolerance : " << nbWithMaxTol;
473     di << "\n  NbOfGTWithDatums       : " << nbWithDatumRef;
474   }
475
476   Standard_Integer aCounter = 0;
477   Standard_Integer aCounter1 = 0;
478    Standard_Integer aCounter2 = 0;
479
480   for ( Standard_Integer i=1; i <= aLabels.Length(); i++ )
481   {
482     Standard_Boolean isDatum = Standard_False;
483     TDF_LabelSequence aDatL;
484     if(aDimTolTool->GetRefDatumLabel(aLabels.Value(i), aDatL))
485     {
486       for(Standard_Integer j = aDatL.Lower(); j <= aDatL.Upper(); j++)
487       {
488         Handle(XCAFDoc_Datum) aDat;
489         if(aDatL.Value(j).FindAttribute(XCAFDoc_Datum::GetID(), aDat))
490         {
491           if(aDat->GetObject()->IsDatumTarget())
492           {
493             aCounter1++;
494           }
495           else
496           {
497             aCounter2++;
498             isDatum = Standard_True;
499           }
500         }
501       }
502       if(isDatum)
503         aCounter++;
504     }
505   }
506   di << "\n NbOfDatumFeature        : " << aCounter;
507   di << "\n NbOfAttachedDatum       : " << aCounter2;
508   di << "\n NbOfDatumTarget         : " << aCounter1;
509
510   return 0;
511 }
512
513 static Standard_Integer addDim (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
514 {
515   if (argc < 3) {
516     di<<"Use: XAddDimension Doc shape/label [shape/label]\n";
517     return 1;
518   }
519   Handle(TDocStd_Document) Doc;
520   DDocStd::GetDocument(argv[1], Doc);
521   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
522   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
523   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
524
525   TDF_Label aLabel;
526   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
527   if ( aLabel.IsNull() ) 
528   {
529     TopoDS_Shape aShape= DBRep::Get(argv[2]);
530     if ( !aShape.IsNull() )
531     {
532       aShapeTool->Search(aShape, aLabel);
533       if ( aLabel.IsNull() )
534       {
535         di<<"Shape "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
536         return 1;
537       }
538     }
539   }
540   TDF_Label aLabel1;
541   if(argc == 4)
542   {
543     TDF_Tool::Label(Doc->GetData(), argv[3], aLabel1);
544     if ( aLabel1.IsNull() ) 
545     {
546       TopoDS_Shape aShape= DBRep::Get(argv[3]);
547       if ( !aShape.IsNull() )
548       {
549         aShapeTool->Search(aShape, aLabel1);
550         if ( aLabel1.IsNull() )
551         {
552           di<<"Shape "<<argv[3]<<" is absent in "<<argv[1]<<"\n";
553           return 1;
554         }
555       }
556     }
557   }
558
559   TDF_Label aDimL = aDimTolTool->AddDimension();
560   if(aLabel1.IsNull())
561     aDimTolTool->SetDimension(aLabel, aDimL);
562   else
563     aDimTolTool->SetDimension(aLabel, aLabel1, aDimL);
564   TCollection_AsciiString Entry;
565   TDF_Tool::Entry(aDimL, Entry);
566   di << Entry;
567   return 0;
568 }
569
570 static Standard_Integer addGTol (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
571 {
572   if (argc < 3) {
573     di<<"Use: XAddGeomTolerance Doc shape/label\n";
574     return 1;
575   }
576   Handle(TDocStd_Document) Doc;
577   DDocStd::GetDocument(argv[1], Doc);
578   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
579   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
580   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
581
582   TDF_Label aLabel;
583   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
584   if ( aLabel.IsNull() ) 
585   {
586     TopoDS_Shape aShape= DBRep::Get(argv[2]);
587     if ( !aShape.IsNull() )
588     {
589       aShapeTool->Search(aShape, aLabel);
590       if ( aLabel.IsNull() )
591       {
592         di<<"Shape "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
593         return 1;
594       }
595     }
596   }
597
598   TDF_Label aTolL = aDimTolTool->AddGeomTolerance();
599   aDimTolTool->SetGeomTolerance(aLabel, aTolL);
600   TCollection_AsciiString Entry;
601   TDF_Tool::Entry(aTolL, Entry);
602   di << Entry;
603   return 0;
604 }
605
606 static Standard_Integer addDatum (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
607 {
608   if (argc < 3) {
609     di<<"Use: XAddDatum Doc shape1/label1 ... shapeN/labelN\n";
610     return 1;
611   }
612   Handle(TDocStd_Document) Doc;
613   DDocStd::GetDocument(argv[1], Doc);
614   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
615   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
616   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
617
618   TDF_LabelSequence aLabelSeq;
619   for (Standard_Integer i = 2; i < argc; i++) {
620     TDF_Label aLabel;
621     TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
622     if (aLabel.IsNull()) {
623       TopoDS_Shape aShape = DBRep::Get(argv[i]);
624       if (!aShape.IsNull())
625         aShapeTool->Search(aShape, aLabel);
626       if (aLabel.IsNull())
627         continue;
628     }
629     aLabelSeq.Append(aLabel);
630   }
631
632   TDF_Label aDatumL = aDimTolTool->AddDatum();
633   aDimTolTool->SetDatum(aLabelSeq, aDatumL);
634   TCollection_AsciiString Entry;
635   TDF_Tool::Entry(aDatumL, Entry);
636   di << Entry;
637   return 0;
638 }
639
640 static Standard_Integer setDatum (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
641 {
642   if (argc < 4) {
643     di<<"Use: XSetDatum Doc Datum_Label GeomTol_Label\n";
644     return 1;
645   }
646   Handle(TDocStd_Document) Doc;
647   DDocStd::GetDocument(argv[1], Doc);
648   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
649   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
650   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
651
652   TDF_Label aLabel;
653   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
654   if ( aLabel.IsNull() ) 
655   {
656     di<<"Datum "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
657     return 1;
658   }
659
660   TDF_Label aTol;
661   TDF_Tool::Label(Doc->GetData(), argv[3], aTol);
662   if ( aTol.IsNull() ) 
663   {
664     di<<"GeomTolerance "<<argv[3]<<" is absent in "<<argv[1]<<"\n";
665     return 1;
666   }
667
668   // check datum position number
669   Handle(XCAFDoc_Datum) aDatumAttr;
670   if (!aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr))
671   {
672     di<<"Invalid datum object\n";
673     return 1;
674   }
675   Handle(XCAFDimTolObjects_DatumObject) aDatumObj = aDatumAttr->GetObject();
676   if (aDatumObj.IsNull())
677   {
678     di<<"Invalid datum object\n";
679     return 1;
680   }
681
682   if (aDatumObj->GetPosition() < 1 || aDatumObj->GetPosition() > 3)
683   {
684     di<<"Invalid datum position number: use XSetDatumPosition\n";
685     return 1;
686   }
687
688   aDimTolTool->SetDatumToGeomTol(aLabel, aTol);
689   return 0;
690 }
691
692 static Standard_Integer setDatumPosition (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
693 {
694   if (argc < 4) {
695     di<<"Use: XSetDatumPosition Doc Datum_Label position[1-3]\n";
696     return 1;
697   }
698
699   if (Draw::Atoi(argv[3]) < 1 || Draw::Atoi(argv[3]) > 3) {
700     di<<"Datum position should be 1, 2 or 3\n";
701     return 1;
702   }
703
704   Handle(TDocStd_Document) Doc;
705   DDocStd::GetDocument(argv[1], Doc);
706   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
707   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
708   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
709
710   TDF_Label aLabel;
711   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
712   if ( aLabel.IsNull() ) 
713   {
714     di<<"Datum "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
715     return 1;
716   }
717   Handle(XCAFDoc_Datum) aDatum;
718   if(aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum))
719   {
720     Handle(XCAFDimTolObjects_DatumObject) anObj = aDatum->GetObject();
721     anObj->SetPosition(Draw::Atoi(argv[3]));
722     aDatum->SetObject(anObj);
723   }
724   return 0;
725 }
726
727 static Standard_Integer getDatumPosition (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
728 {
729   if (argc < 3) {
730     di<<"Use: XGetDatumPosition Doc Datum_Label\n";
731     return 1;
732   }
733   Handle(TDocStd_Document) Doc;
734   DDocStd::GetDocument(argv[1], Doc);
735   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
736   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
737   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
738
739   TDF_Label aLabel;
740   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
741   if ( aLabel.IsNull() ) 
742   {
743     di<<"Datum "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
744     return 1;
745   }
746   Handle(XCAFDoc_Datum) aDatum;
747   if(aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum))
748   {
749     di << aDatum->GetObject()->GetPosition();
750   }
751   return 0;
752 }
753
754
755 static Standard_Integer getDatum (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
756 {
757   if (argc < 3) {
758     di<<"Use: XGetDatum Doc GeomTol_Label/Shape_Label\n";
759     return 1;
760   }
761   Handle(TDocStd_Document) Doc;
762   DDocStd::GetDocument(argv[1], Doc);
763   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
764   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
765   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
766
767   TDF_Label aLabel;
768   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
769   if ( aLabel.IsNull() ) 
770   {
771     di<<"Label "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
772     return 1;
773   }
774
775   TDF_LabelSequence aD;
776   if(!aDimTolTool->GetRefDatumLabel(aLabel, aD))
777   {
778     aDimTolTool->GetDatumOfTolerLabels(aLabel, aD);
779   }
780   for(Standard_Integer i = aD.Lower(); i <= aD.Upper(); i++)
781   {
782     if(i>1) di<<", ";
783     TCollection_AsciiString Entry;
784     TDF_Tool::Entry(aD.Value(i), Entry);
785     di<<Entry;
786   }
787   return 0;
788 }
789
790 static Standard_Integer addDatumModif (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
791 {
792   if (argc < 4) {
793     di<<"Use: XAddDatumModifier Doc Datum_Label mod1 mod2 ...\n";
794     return 1;
795   }
796   Handle(TDocStd_Document) Doc;
797   DDocStd::GetDocument(argv[1], Doc);
798   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
799   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
800   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
801
802   TDF_Label aLabel;
803   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
804   if ( aLabel.IsNull() ) 
805   {
806     di<<"Datum "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
807     return 1;
808   }
809   Handle(XCAFDoc_Datum) aDatum;
810   if(aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum))
811   {
812     for(Standard_Integer i = 3; i < argc; i++)
813     {
814       if(Draw::Atoi(argv[i]) < 22 && Draw::Atoi(argv[i]) > -1)
815       {
816         Handle(XCAFDimTolObjects_DatumObject) anObj = aDatum->GetObject();
817         anObj->AddModifier((XCAFDimTolObjects_DatumSingleModif)Draw::Atoi(argv[i]));
818         aDatum->SetObject(anObj);
819       }
820     }
821   }
822   return 0;
823 }
824
825 static Standard_Integer getDatumModif (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
826 {
827   if (argc < 3) {
828     di<<"Use: XGetDatumModifiers Doc Datum_Label\n";
829     return 1;
830   }
831   Handle(TDocStd_Document) Doc;
832   DDocStd::GetDocument(argv[1], Doc);
833   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
834   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
835   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
836
837   TDF_Label aLabel;
838   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
839   if ( aLabel.IsNull() ) 
840   {
841     di<<"Datum "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
842     return 1;
843   }
844   Handle(XCAFDoc_Datum) aDatum;
845   if(aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum))
846   {
847     XCAFDimTolObjects_DatumModifiersSequence aS = aDatum->GetObject()->GetModifiers();
848     for(Standard_Integer i = 1; i<=aS.Length();i++)
849     {
850       if (i > 1) di<<", ";
851       switch(aS.Value(i)){
852       case 0  : di<<"AnyCrossSection"; break;
853       case 1  : di<<"AnyLongitudinalSection"; break;
854       case 2  : di<<"Basic"; break;
855       case 3  : di<<"ContactingFeature\n"; break;
856       case 4  : di<<"DegreeOfFreedomConstraintU"; break;
857       case 5  : di<<"DegreeOfFreedomConstraintV"; break;
858       case 6  : di<<"DegreeOfFreedomConstraintW"; break;
859       case 7  : di<<"DegreeOfFreedomConstraintX"; break;
860       case 8  : di<<"DegreeOfFreedomConstraintY"; break;
861       case 9  : di<<"DegreeOfFreedomConstraintZ"; break;
862       case 10 : di<<"DistanceVariable"; break;
863       case 11 : di<<"FreeState"; break;
864       case 12 : di<<"LeastMaterialRequirement"; break;
865       case 13 : di<<"Line"; break;
866       case 14 : di<<"MajorDiameter"; break;
867       case 15 : di<<"MaximumMaterialRequirement"; break;
868       case 16 : di<<"MinorDiameter"; break;
869       case 17 : di<<"Orientation"; break;
870       case 18 : di<<"PitchDiameter"; break;
871       case 19 : di<<"Plane"; break;
872       case 20 : di<<"Point"; break;
873       case 21 : di<<"Translation"; break;
874       default : break;
875       }
876     }
877   }
878   return 0;
879 }
880
881 static Standard_Integer setDatumName (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
882 {
883   if (argc < 4) {
884     di<<"Use: XSetDatumName Doc Datum_Label name\n";
885     return 1;
886   }
887   Handle(TDocStd_Document) Doc;
888   DDocStd::GetDocument(argv[1], Doc);
889   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
890   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
891   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
892
893   TDF_Label aLabel;
894   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
895   if ( aLabel.IsNull() ) 
896   {
897     di<<"Datum "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
898     return 1;
899   }
900   Handle(XCAFDoc_Datum) aDatum;
901   if(aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum))
902   {
903     Handle(XCAFDimTolObjects_DatumObject) anObj = aDatum->GetObject();
904     anObj->SetName(new TCollection_HAsciiString(argv[3]));
905     aDatum->SetObject(anObj);
906   }
907   return 0;
908 }
909
910 static Standard_Integer getDatumName (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
911 {
912   if (argc < 3) {
913     di<<"Use: XGetDatumName Doc Datum_Label\n";
914     return 1;
915   }
916   Handle(TDocStd_Document) Doc;
917   DDocStd::GetDocument(argv[1], Doc);
918   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
919   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
920   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
921
922   TDF_Label aLabel;
923   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
924   if ( aLabel.IsNull() ) 
925   {
926     di<<"Datum "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
927     return 1;
928   }
929   Handle(XCAFDoc_Datum) aDatum;
930   if(aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum))
931   {
932     di<<aDatum->GetObject()->GetName()->ToCString();
933   }
934   return 0;
935 }
936
937 static Standard_Integer setTypeOfTol (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
938 {
939   if (argc < 4) {
940     di<<"Use: XSetTypeOfTolerance Doc GTol_Label type\n";
941     return 1;
942   }
943   Handle(TDocStd_Document) Doc;
944   DDocStd::GetDocument(argv[1], Doc);
945   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
946   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
947   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
948
949   TDF_Label aLabel;
950   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
951   if ( aLabel.IsNull() ) 
952   {
953     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
954     return 1;
955   }
956   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
957   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
958   {
959     if(Draw::Atoi(argv[3]) > -1 && Draw::Atoi(argv[3]) < 16)
960     {
961       Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
962       anObj->SetType((XCAFDimTolObjects_GeomToleranceType)Draw::Atoi(argv[3]));
963       aGeomTolerance->SetObject(anObj);
964     }
965   }
966   return 0;
967 }
968
969 static Standard_Integer getTypeOfTol (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
970 {
971   if (argc < 3) {
972     di<<"Use: XGetTypeOfTolerance Doc GTol_Label\n";
973     return 1;
974   }
975   Handle(TDocStd_Document) Doc;
976   DDocStd::GetDocument(argv[1], Doc);
977   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
978   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
979   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
980
981   TDF_Label aLabel;
982   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
983   if ( aLabel.IsNull() ) 
984   {
985     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
986     return 1;
987   }
988   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
989   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
990   {
991       switch(aGeomTolerance->GetObject()->GetType()){
992       case 0  : di<<"type is absent"; break;
993       case 1  : di<<"Angularity"; break;
994       case 2  : di<<"CircularRunout"; break;
995       case 3  : di<<"CircularityOrRoundness"; break;
996       case 4  : di<<"Coaxiality"; break;
997       case 5  : di<<"Concentricity"; break;
998       case 6  : di<<"Cylindricity"; break;
999       case 7  : di<<"Flatness"; break;
1000       case 8  : di<<"Parallelism"; break;
1001       case 9  : di<<"Perpendicularity"; break;
1002       case 10 : di<<"Position"; break;
1003       case 11 : di<<"ProfileOfLine"; break;
1004       case 12 : di<<"ProfileOfSurface"; break;
1005       case 13 : di<<"Straightness"; break;
1006       case 14 : di<<"Symmetry"; break;
1007       case 15 : di<<"TotalRunout"; break;
1008       default : break;
1009       }
1010   }
1011   return 0;
1012 }
1013
1014 static Standard_Integer setTypeOfTolVal (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1015 {
1016   if (argc < 4) {
1017     di<<"Use: XSetTypeOfToleranceValue Doc GTol_Label type\n";
1018     return 1;
1019   }
1020   Handle(TDocStd_Document) Doc;
1021   DDocStd::GetDocument(argv[1], Doc);
1022   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1023   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1024   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1025
1026   TDF_Label aLabel;
1027   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1028   if ( aLabel.IsNull() ) 
1029   {
1030     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1031     return 1;
1032   }
1033   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
1034   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
1035   {
1036     if(Draw::Atoi(argv[3]) > -1 && Draw::Atoi(argv[3]) < 3)
1037     {
1038       Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
1039       anObj->SetTypeOfValue((XCAFDimTolObjects_GeomToleranceTypeValue)Draw::Atoi(argv[3]));
1040       aGeomTolerance->SetObject(anObj);
1041     }
1042   }
1043   return 0;
1044 }
1045
1046 static Standard_Integer getTypeOfTolVal (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1047 {
1048   if (argc < 3) {
1049     di<<"Use: XGetTypeOfToleranceValue Doc GTol_Label\n";
1050     return 1;
1051   }
1052   Handle(TDocStd_Document) Doc;
1053   DDocStd::GetDocument(argv[1], Doc);
1054   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1055   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1056   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1057
1058   TDF_Label aLabel;
1059   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1060   if ( aLabel.IsNull() ) 
1061   {
1062     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1063     return 1;
1064   }
1065   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
1066   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
1067   {
1068     switch(aGeomTolerance->GetObject()->GetTypeOfValue()){
1069       case 0  : di<<"type is absent"; break;
1070       case 1  : di<<"Diameter"; break;
1071       case 2  : di<<"SphericalDiameter"; break;
1072       default : break;
1073       }
1074   }
1075   return 0;
1076 }
1077
1078 static Standard_Integer setTolVal (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1079 {
1080   if (argc < 4) {
1081     di<<"Use: XSetToleranceValue Doc GTol_Label value\n";
1082     return 1;
1083   }
1084   Handle(TDocStd_Document) Doc;
1085   DDocStd::GetDocument(argv[1], Doc);
1086   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1087   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1088   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1089
1090   TDF_Label aLabel;
1091   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1092   if ( aLabel.IsNull() ) 
1093   {
1094     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1095     return 1;
1096   }
1097   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
1098   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
1099   {
1100     Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
1101     anObj->SetValue(Draw::Atof(argv[3]));
1102     aGeomTolerance->SetObject(anObj);
1103   }
1104   return 0;
1105 }
1106
1107 static Standard_Integer getTolVal (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1108 {
1109   if (argc < 3) {
1110     di<<"Use: XGetToleranceValue Doc GTol_Label\n";
1111     return 1;
1112   }
1113   Handle(TDocStd_Document) Doc;
1114   DDocStd::GetDocument(argv[1], Doc);
1115   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1116   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1117   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1118
1119   TDF_Label aLabel;
1120   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1121   if ( aLabel.IsNull() ) 
1122   {
1123     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1124     return 1;
1125   }
1126   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
1127   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
1128   {
1129     di << aGeomTolerance->GetObject()->GetValue();
1130   }
1131   return 0;
1132 }
1133
1134 static Standard_Integer setMatReq (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1135 {
1136   if (argc < 4) {
1137     di<<"Use: XSetTolMaterialReq Doc GTol_Label mod\n";
1138     return 1;
1139   }
1140   Handle(TDocStd_Document) Doc;
1141   DDocStd::GetDocument(argv[1], Doc);
1142   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1143   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1144   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1145
1146   TDF_Label aLabel;
1147   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1148   if ( aLabel.IsNull() ) 
1149   {
1150     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1151     return 1;
1152   }
1153   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
1154   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
1155   {
1156     if(Draw::Atoi(argv[3]) > -1 && Draw::Atoi(argv[3]) < 3)
1157     {
1158       Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
1159       anObj->SetMaterialRequirementModifier((XCAFDimTolObjects_GeomToleranceMatReqModif)Draw::Atoi(argv[3]));
1160       aGeomTolerance->SetObject(anObj);
1161     }
1162   }
1163   return 0;
1164 }
1165
1166 static Standard_Integer getMatReq (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1167 {
1168   if (argc < 3) {
1169     di<<"Use: XGetTolMaterialReq Doc GTol_Label\n";
1170     return 1;
1171   }
1172   Handle(TDocStd_Document) Doc;
1173   DDocStd::GetDocument(argv[1], Doc);
1174   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1175   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1176   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1177
1178   TDF_Label aLabel;
1179   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1180   if ( aLabel.IsNull() ) 
1181   {
1182     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1183     return 1;
1184   }
1185   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
1186   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
1187   {
1188       switch(aGeomTolerance->GetObject()->GetMaterialRequirementModifier()){
1189       case 0  : di<<"modifier is absent"; break;
1190       case 1  : di<<"M"; break;
1191       case 2  : di<<"L"; break;
1192       default : break;
1193       }
1194   }
1195   return 0;
1196 }
1197
1198 static Standard_Integer setZoneMod (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1199 {
1200   if (argc < 4) {
1201     di<<"Use: XSetTolZoneMod Doc GTol_Label mod\n";
1202     return 1;
1203   }
1204   Handle(TDocStd_Document) Doc;
1205   DDocStd::GetDocument(argv[1], Doc);
1206   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1207   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1208   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1209
1210   TDF_Label aLabel;
1211   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1212   if ( aLabel.IsNull() ) 
1213   {
1214     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1215     return 1;
1216   }
1217   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
1218   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
1219   {
1220     if(Draw::Atoi(argv[3]) > -1 && Draw::Atoi(argv[3]) < 3)
1221     {
1222       Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
1223       anObj->SetZoneModifier((XCAFDimTolObjects_GeomToleranceZoneModif)Draw::Atoi(argv[3]));
1224       aGeomTolerance->SetObject(anObj);
1225     }
1226   }
1227   return 0;
1228 }
1229
1230 static Standard_Integer getZoneMod (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1231 {
1232   if (argc < 3) {
1233     di<<"Use: XGetTolZoneMod Doc GTol_Label\n";
1234     return 1;
1235   }
1236   Handle(TDocStd_Document) Doc;
1237   DDocStd::GetDocument(argv[1], Doc);
1238   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1239   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1240   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1241
1242   TDF_Label aLabel;
1243   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1244   if ( aLabel.IsNull() ) 
1245   {
1246     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1247     return 1;
1248   }
1249   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
1250   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
1251   {
1252       switch(aGeomTolerance->GetObject()->GetZoneModifier()){
1253       case 0  : di<<"modifier is absent"; break;
1254       case 1  : di<<"P"; break;
1255       case 2  : di<<"NonUniform"; break;
1256       default : break;
1257       }
1258   }
1259   return 0;
1260 }
1261
1262 static Standard_Integer setZoneModVal (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1263 {
1264   if (argc < 4) {
1265     di<<"Use: XSetTolZoneModValue Doc GTol_Label val\n";
1266     return 1;
1267   }
1268   Handle(TDocStd_Document) Doc;
1269   DDocStd::GetDocument(argv[1], Doc);
1270   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1271   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1272   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1273
1274   TDF_Label aLabel;
1275   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1276   if ( aLabel.IsNull() ) 
1277   {
1278     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1279     return 1;
1280   }
1281   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
1282   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
1283   {
1284     Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
1285     anObj->SetValueOfZoneModifier(Draw::Atof(argv[3]));
1286     aGeomTolerance->SetObject(anObj);
1287   }
1288   return 0;
1289 }
1290
1291 static Standard_Integer getZoneModVal (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1292 {
1293   if (argc < 3) {
1294     di<<"Use: XGetTolZoneModValue Doc GTol_Label\n";
1295     return 1;
1296   }
1297   Handle(TDocStd_Document) Doc;
1298   DDocStd::GetDocument(argv[1], Doc);
1299   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1300   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1301   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1302
1303   TDF_Label aLabel;
1304   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1305   if ( aLabel.IsNull() ) 
1306   {
1307     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1308     return 1;
1309   }
1310   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
1311   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
1312   {
1313     di << aGeomTolerance->GetObject()->GetValueOfZoneModifier();
1314   }
1315   return 0;
1316 }
1317
1318 static Standard_Integer addTolModif (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1319 {
1320   if (argc < 4) {
1321     di<<"Use: XAddTolModifier Doc Tol_Label mod1 mod2 ...\n";
1322     return 1;
1323   }
1324   Handle(TDocStd_Document) Doc;
1325   DDocStd::GetDocument(argv[1], Doc);
1326   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1327   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1328   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1329
1330   TDF_Label aLabel;
1331   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1332   if ( aLabel.IsNull() ) 
1333   {
1334     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1335     return 1;
1336   }
1337   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
1338   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
1339   {
1340     for(Standard_Integer i = 3; i < argc; i++)
1341     {
1342       if(Draw::Atoi(argv[i]) > -1 && Draw::Atoi(argv[i]) < 17)
1343       {
1344         Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
1345         anObj->AddModifier((XCAFDimTolObjects_GeomToleranceModif)Draw::Atoi(argv[i]));
1346         aGeomTolerance->SetObject(anObj);
1347       }
1348     }
1349   }
1350   return 0;
1351 }
1352
1353 static Standard_Integer getTolModif (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1354 {
1355   if (argc < 3) {
1356     di<<"Use: XGetTolModifiers Doc Tol_Label\n";
1357     return 1;
1358   }
1359   Handle(TDocStd_Document) Doc;
1360   DDocStd::GetDocument(argv[1], Doc);
1361   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1362   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1363   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1364
1365   TDF_Label aLabel;
1366   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1367   if ( aLabel.IsNull() ) 
1368   {
1369     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1370     return 1;
1371   }
1372   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
1373   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
1374   {
1375     XCAFDimTolObjects_GeomToleranceModifiersSequence aS  = aGeomTolerance->GetObject()->GetModifiers();
1376     for(Standard_Integer i = 1; i <= aS.Length(); i++)
1377     {
1378       if (i > 1) di<<", ";
1379       switch(aS.Value(i)){
1380       case 0  : di<<"Any_Cross_Section"; break;
1381       case 1  : di<<"Common_Zone"; break;
1382       case 2  : di<<"Each_Radial_Element"; break;
1383       case 3  : di<<"Free_State"; break;
1384       case 4  : di<<"Least_Material_Requirement"; break;
1385       case 5  : di<<"Line_Element"; break;
1386       case 6  : di<<"Major_Diameter"; break;
1387       case 7  : di<<"Maximum_Material_Requirement"; break;
1388       case 8  : di<<"Minor_Diameter"; break;
1389       case 9  : di<<"Not_Convex"; break;
1390       case 10 : di<<"Pitch_Diameter"; break;
1391       case 11 : di<<"Reciprocity_Requirement"; break;
1392       case 12 : di<<"Separate_Requirement"; break;
1393       case 13 : di<<"Statistical_Tolerance"; break;
1394       case 14 : di<<"Tangent_Plane"; break;
1395       default : break;
1396       }
1397     }
1398   }
1399   return 0;
1400 }
1401
1402 static Standard_Integer setTolMaxVal (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1403 {
1404   if (argc < 4) {
1405     di<<"Use: XSetTolMaxValue Doc Dim_Label val\n";
1406     return 1;
1407   }
1408   Handle(TDocStd_Document) Doc;
1409   DDocStd::GetDocument(argv[1], Doc);
1410   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1411   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1412   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1413
1414   TDF_Label aLabel;
1415   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1416   if ( aLabel.IsNull() ) 
1417   {
1418     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1419     return 1;
1420   }
1421   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
1422   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
1423   {
1424     Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
1425     anObj->SetMaxValueModifier(Draw::Atof(argv[3]));
1426     aGeomTolerance->SetObject(anObj);
1427   }
1428   return 0;
1429 }
1430
1431 static Standard_Integer getTolMaxVal (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1432 {
1433   if (argc < 3) {
1434     di<<"Use: XGetTolMaxValue Doc Dim_Label\n";
1435     return 1;
1436   }
1437   Handle(TDocStd_Document) Doc;
1438   DDocStd::GetDocument(argv[1], Doc);
1439   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1440   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1441   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1442
1443   TDF_Label aLabel;
1444   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1445   if ( aLabel.IsNull() ) 
1446   {
1447     di<<"GeomTolerance "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1448     return 1;
1449   }
1450   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
1451   if(aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
1452   {
1453     di << aGeomTolerance->GetObject()->GetMaxValueModifier();
1454   }
1455   return 0;
1456 }
1457
1458 static Standard_Integer setDimType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1459 {
1460   if (argc < 4) {
1461     di<<"Use: XSetDimensionType Doc Dim_Label type\n";
1462     return 1;
1463   }
1464   Handle(TDocStd_Document) Doc;
1465   DDocStd::GetDocument(argv[1], Doc);
1466   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1467   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1468   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1469
1470   TDF_Label aLabel;
1471   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1472   if ( aLabel.IsNull() ) 
1473   {
1474     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1475     return 1;
1476   }
1477   Handle(XCAFDoc_Dimension) aDimension;
1478   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
1479   {
1480     if(Draw::Atoi(argv[3]) > -1 && Draw::Atoi(argv[3]) < 30)
1481     {
1482       Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
1483       anObj->SetType((XCAFDimTolObjects_DimensionType)Draw::Atoi(argv[3]));
1484       aDimension->SetObject(anObj);
1485     }
1486   }
1487   return 0;
1488 }
1489
1490 static Standard_Integer getDimType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1491 {
1492   if (argc < 3) {
1493     di<<"Use: XGetDimensionType Doc Dim_Label\n";
1494     return 1;
1495   }
1496   Handle(TDocStd_Document) Doc;
1497   DDocStd::GetDocument(argv[1], Doc);
1498   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1499   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1500   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1501
1502   TDF_Label aLabel;
1503   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1504   if ( aLabel.IsNull() ) 
1505   {
1506     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1507     return 1;
1508   }
1509   Handle(XCAFDoc_Dimension) aDimension;
1510   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
1511   {
1512       switch(aDimension->GetObject()->GetType()){
1513       case 0  : di<<"type is absent"; break;
1514       case 1  : di<<"Location_CurvedDistance"; break;
1515       case 2  : di<<"Location_LinearDistance"; break;
1516       case 3  : di<<"Location_LinearDistance_FromCenterToOuter"; break;
1517       case 4  : di<<"Location_LinearDistance_FromCenterToInner"; break;
1518       case 5  : di<<"Location_LinearDistance_FromOuterToCenter"; break;
1519       case 6  : di<<"Location_LinearDistance_FromOuterToOuter"; break;
1520       case 7  : di<<"Location_LinearDistance_FromOuterToInner"; break;
1521       case 8  : di<<"Location_LinearDistance_FromInnerToCenter"; break;
1522       case 9  : di<<"Location_LinearDistance_FromInnerToOuter"; break;
1523       case 10 : di<<"Location_LinearDistance_FromInnerToInner"; break;
1524       case 11 : di<<"Location_Angular"; break;
1525       case 12 : di<<"Location_Oriented"; break;
1526       case 13 : di<<"Location_WithPath"; break;
1527       case 14 : di<<"Size_CurveLength"; break;
1528       case 15 : di<<"Size_Diameter"; break;
1529       case 16 : di<<"Size_SphericalDiameter"; break;
1530       case 17 : di<<"Size_Radius"; break;
1531       case 18 : di<<"Size_SphericalRadius"; break;
1532       case 19 : di<<"Size_ToroidalMinorDiameter"; break;
1533       case 20 : di<<"Size_ToroidalMajorDiameter"; break;
1534       case 21 : di<<"Size_ToroidalMinorRadius"; break;
1535       case 22 : di<<"Size_ToroidalMajorRadius"; break;
1536       case 23 : di<<"Size_ToroidalHighMajorDiameter"; break;
1537       case 24 : di<<"Size_ToroidalLowMajorDiameter"; break;
1538       case 25 : di<<"Size_ToroidalHighMajorRadius"; break;
1539       case 26 : di<<"Size_ToroidalLowMajorRadius"; break;
1540       case 27 : di<<"Size_Thickness"; break;
1541       case 28 : di<<"Size_Angular"; break;
1542       case 29 : di<<"Size_WithPath"; break;
1543       default : break;
1544       }
1545   }
1546   return 0;
1547 }
1548
1549 static Standard_Integer setDimVal (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1550 {
1551   if (argc < 4) {
1552     di<<"Use: XSetDimensionValue Doc Dim_Label val\n";
1553     return 1;
1554   }
1555   Handle(TDocStd_Document) Doc;
1556   DDocStd::GetDocument(argv[1], Doc);
1557   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1558   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1559   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1560
1561   TDF_Label aLabel;
1562   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1563   if ( aLabel.IsNull() ) 
1564   {
1565     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1566     return 1;
1567   }
1568   Handle(XCAFDoc_Dimension) aDimension;
1569   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
1570   {
1571     Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
1572     anObj->SetValue(Draw::Atof(argv[3]));
1573     aDimension->SetObject(anObj);
1574   }
1575   return 0;
1576 }
1577
1578 static Standard_Integer getDimVal (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1579 {
1580   if (argc < 3) {
1581     di<<"Use: XGetDimensionValue Doc Dim_Label\n";
1582     return 1;
1583   }
1584   Handle(TDocStd_Document) Doc;
1585   DDocStd::GetDocument(argv[1], Doc);
1586   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1587   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1588   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1589
1590   TDF_Label aLabel;
1591   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1592   if ( aLabel.IsNull() ) 
1593   {
1594     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1595     return 1;
1596   }
1597   Handle(XCAFDoc_Dimension) aDimension;
1598   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
1599   {
1600     di << aDimension->GetObject()->GetValue();
1601   }
1602   return 0;
1603 }
1604
1605 static Standard_Integer setDimQalif (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1606 {
1607   if (argc < 4) {
1608     di<<"Use: XSetDimensionQualifier Doc Dim_Label val\n";
1609     return 1;
1610   }
1611   Handle(TDocStd_Document) Doc;
1612   DDocStd::GetDocument(argv[1], Doc);
1613   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1614   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1615   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1616
1617   TDF_Label aLabel;
1618   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1619   if ( aLabel.IsNull() ) 
1620   {
1621     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1622     return 1;
1623   }
1624   Handle(XCAFDoc_Dimension) aDimension;
1625   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
1626   {
1627     if(Draw::Atoi(argv[3]) > -1 && Draw::Atoi(argv[3]) < 4)
1628     {
1629       Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
1630       anObj->SetQualifier((XCAFDimTolObjects_DimensionQualifier)Draw::Atoi(argv[3]));
1631       aDimension->SetObject(anObj);
1632     }
1633   }
1634   return 0;
1635 }
1636
1637 static Standard_Integer getDimQalif (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1638 {
1639   if (argc < 3) {
1640     di<<"Use: XGetDimensionQualifier Doc Dim_Label\n";
1641     return 1;
1642   }
1643   Handle(TDocStd_Document) Doc;
1644   DDocStd::GetDocument(argv[1], Doc);
1645   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1646   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1647   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1648
1649   TDF_Label aLabel;
1650   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1651   if ( aLabel.IsNull() ) 
1652   {
1653     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1654     return 1;
1655   }
1656   Handle(XCAFDoc_Dimension) aDimension;
1657   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
1658   {
1659     
1660     switch(aDimension->GetObject()->GetQualifier()){
1661       case 0  : di<<"type is absent"; break;
1662       case 1  : di<<"Min"; break;
1663       case 2  : di<<"Max"; break;
1664       case 3  : di<<"Avg"; break;
1665       default : break;
1666       }
1667   }
1668   return 0;
1669 }
1670
1671 static Standard_Integer setDimRange (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1672 {
1673   if (argc < 5) {
1674     di<<"Use: XSetDimensionRange Doc Dim_Label low_val up_val\n";
1675     return 1;
1676   }
1677   Handle(TDocStd_Document) Doc;
1678   DDocStd::GetDocument(argv[1], Doc);
1679   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1680   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1681   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1682
1683   TDF_Label aLabel;
1684   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1685   if ( aLabel.IsNull() ) 
1686   {
1687     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1688     return 1;
1689   }
1690   Handle(XCAFDoc_Dimension) aDimension;
1691   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
1692   {
1693     if(Draw::Atof(argv[3]) < Draw::Atof(argv[4]))
1694     {
1695       Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
1696       anObj->SetLowerBound(Draw::Atof(argv[3]));
1697       anObj->SetUpperBound(Draw::Atof(argv[4]));
1698       aDimension->SetObject(anObj);
1699     }
1700   }
1701   return 0;
1702 }
1703
1704 static Standard_Integer getDimRange (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1705 {
1706   if (argc < 3) {
1707     di<<"Use: XGetDimensionRange Doc Dim_Label\n";
1708     return 1;
1709   }
1710   Handle(TDocStd_Document) Doc;
1711   DDocStd::GetDocument(argv[1], Doc);
1712   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1713   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1714   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1715
1716   TDF_Label aLabel;
1717   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1718   if ( aLabel.IsNull() ) 
1719   {
1720     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1721     return 1;
1722   }
1723   Handle(XCAFDoc_Dimension) aDimension;
1724   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
1725   {
1726     di << "lower " << aDimension->GetObject()->GetLowerBound();
1727     di << " upper " << aDimension->GetObject()->GetUpperBound();
1728   }
1729   return 0;
1730 }
1731
1732 static Standard_Integer setDimPlusMinusTol (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1733 {
1734   if (argc < 5) {
1735     di<<"Use: XSetDimensionPlusMinusTol Doc Dim_Label low_val up_val\n";
1736     return 1;
1737   }
1738   Handle(TDocStd_Document) Doc;
1739   DDocStd::GetDocument(argv[1], Doc);
1740   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1741   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1742   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1743
1744   TDF_Label aLabel;
1745   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1746   if ( aLabel.IsNull() ) 
1747   {
1748     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1749     return 1;
1750   }
1751   Handle(XCAFDoc_Dimension) aDimension;
1752   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
1753   {
1754     if(Draw::Atof(argv[3]) < Draw::Atof(argv[4]))
1755     {
1756       Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
1757       anObj->SetLowerTolValue(Draw::Atof(argv[3]));
1758       anObj->SetUpperTolValue(Draw::Atof(argv[4]));
1759       aDimension->SetObject(anObj);
1760     }
1761   }
1762   return 0;
1763 }
1764
1765 static Standard_Integer getDimPlusMinusTol (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1766 {
1767   if (argc < 3) {
1768     di<<"Use: XGetDimensionPlusMinusTol Doc Dim_Label\n";
1769     return 1;
1770   }
1771   Handle(TDocStd_Document) Doc;
1772   DDocStd::GetDocument(argv[1], Doc);
1773   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1774   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1775   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1776
1777   TDF_Label aLabel;
1778   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1779   if ( aLabel.IsNull() ) 
1780   {
1781     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1782     return 1;
1783   }
1784   Handle(XCAFDoc_Dimension) aDimension;
1785   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
1786   {
1787     di << "lower " << aDimension->GetObject()->GetLowerTolValue();
1788     di << " upper " << aDimension->GetObject()->GetUpperTolValue();
1789   }
1790   return 0;
1791 }
1792
1793 static Standard_Integer setDimClassTol (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1794 {
1795   if (argc < 6) {
1796     di<<"Use: XSetDimensionClassOfTol Doc Dim_Label ishole[1/0] formVar grade\n";
1797     return 1;
1798   }
1799   Handle(TDocStd_Document) Doc;
1800   DDocStd::GetDocument(argv[1], Doc);
1801   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1802   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1803   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1804
1805   TDF_Label aLabel;
1806   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1807   if ( aLabel.IsNull() ) 
1808   {
1809     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1810     return 1;
1811   }
1812   Handle(XCAFDoc_Dimension) aDimension;
1813   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
1814   {
1815     if(Draw::Atoi(argv[4]) > 0 && Draw::Atoi(argv[4]) < 29 && Draw::Atoi(argv[5]) > -1 && Draw::Atoi(argv[5]) < 20)
1816     {
1817       Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
1818       anObj->SetClassOfTolerance((Draw::Atoi(argv[3]) != 0), (XCAFDimTolObjects_DimensionFormVariance)Draw::Atoi(argv[4]), (XCAFDimTolObjects_DimensionGrade)Draw::Atoi(argv[5]));
1819       aDimension->SetObject(anObj);
1820     }
1821   }
1822   return 0;
1823 }
1824
1825 static Standard_Integer getDimClassTol (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1826 {
1827   if (argc < 3) {
1828     di<<"Use: XGetDimensionClassOfTol Doc Dim_Label\n";
1829     return 1;
1830   }
1831   Handle(TDocStd_Document) Doc;
1832   DDocStd::GetDocument(argv[1], Doc);
1833   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1834   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1835   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1836
1837   TDF_Label aLabel;
1838   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1839   if ( aLabel.IsNull() ) 
1840   {
1841     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1842     return 1;
1843   }
1844   Handle(XCAFDoc_Dimension) aDimension;
1845   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
1846   {
1847     Standard_Boolean h;
1848     XCAFDimTolObjects_DimensionFormVariance f;
1849     XCAFDimTolObjects_DimensionGrade g;
1850     if(aDimension->GetObject()->GetClassOfTolerance(h ,f, g))
1851     {
1852       if(h)
1853       {
1854         switch(f){
1855         case 1  : di<<"a";break;
1856         case 2  : di<<"b";break;
1857         case 3  : di<<"c";break;
1858         case 4  : di<<"cd";break;
1859         case 5  : di<<"d";break;
1860         case 6  : di<<"e";break;
1861         case 7  : di<<"ef";break;
1862         case 8  : di<<"f";break;
1863         case 9  : di<<"fg";break;
1864         case 10 : di<<"g";break;
1865         case 11 : di<<"h";break;
1866         case 12 : di<<"js";break;
1867         case 13 : di<<"j";break;
1868         case 14 : di<<"k";break;
1869         case 15 : di<<"m";break;
1870         case 16 : di<<"n";break;
1871         case 17 : di<<"p";break;
1872         case 18 : di<<"r";break;
1873         case 19 : di<<"s";break;
1874         case 20 : di<<"t";break;
1875         case 21 : di<<"u";break;
1876         case 22 : di<<"v";break;
1877         case 23 : di<<"x";break;
1878         case 24 : di<<"y";break;
1879         case 25 : di<<"z";break;
1880         case 26 : di<<"a";break;
1881         case 27 : di<<"zb";break;
1882         case 28 : di<<"zc";break;
1883         default : break;
1884         }
1885       }
1886       else
1887       {
1888         switch(f){
1889         case 1  : di<<"A";break;
1890         case 2  : di<<"B";break;
1891         case 3  : di<<"C";break;
1892         case 4  : di<<"CD";break;
1893         case 5  : di<<"D";break;
1894         case 6  : di<<"E";break;
1895         case 7  : di<<"EF";break;
1896         case 8  : di<<"F";break;
1897         case 9  : di<<"FG";break;
1898         case 10 : di<<"G";break;
1899         case 11 : di<<"H";break;
1900         case 12 : di<<"JS";break;
1901         case 13 : di<<"J";break;
1902         case 14 : di<<"K";break;
1903         case 15 : di<<"M";break;
1904         case 16 : di<<"N";break;
1905         case 17 : di<<"P";break;
1906         case 18 : di<<"R";break;
1907         case 19 : di<<"S";break;
1908         case 20 : di<<"T";break;
1909         case 21 : di<<"U";break;
1910         case 22 : di<<"V";break;
1911         case 23 : di<<"X";break;
1912         case 24 : di<<"Y";break;
1913         case 25 : di<<"Z";break;
1914         case 26 : di<<"ZA";break;
1915         case 27 : di<<"ZB";break;
1916         case 28 : di<<"ZC";break;
1917         default : break;
1918         }
1919       }
1920       switch(g){
1921       case 0  : di<<"01"; break;
1922       case 1  : di<<"0"; break;
1923       case 2  : di<<"1"; break;
1924       case 3  : di<<"2"; break;
1925       case 4  : di<<"3"; break;
1926       case 5  : di<<"4"; break;
1927       case 6  : di<<"5"; break;
1928       case 7  : di<<"6"; break;
1929       case 8  : di<<"7"; break;
1930       case 9  : di<<"8"; break;
1931       case 10 : di<<"9"; break;
1932       case 11 : di<<"10"; break;
1933       case 12 : di<<"11"; break;
1934       case 13 : di<<"12"; break;
1935       case 14 : di<<"13"; break;
1936       case 15 : di<<"14"; break;
1937       case 16 : di<<"15"; break;
1938       case 17 : di<<"16"; break;
1939       case 18 : di<<"17"; break;
1940       case 19 : di<<"18"; break;
1941       default : break;
1942       }
1943     }
1944   }
1945   return 0;
1946 }
1947
1948 static Standard_Integer setDimNbOfDecimalPlaces (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1949 {
1950   if (argc < 5) {
1951     di<<"Use: XSetDimensionNbOfDecimalPlaces Doc Dim_Label l_val r_val\n";
1952     return 1;
1953   }
1954   Handle(TDocStd_Document) Doc;
1955   DDocStd::GetDocument(argv[1], Doc);
1956   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1957   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1958   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1959
1960   TDF_Label aLabel;
1961   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1962   if ( aLabel.IsNull() ) 
1963   {
1964     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1965     return 1;
1966   }
1967   Handle(XCAFDoc_Dimension) aDimension;
1968   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
1969   {
1970     Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
1971     anObj->SetNbOfDecimalPlaces(Draw::Atoi(argv[3]), Draw::Atoi(argv[4]));
1972     aDimension->SetObject(anObj);
1973   }
1974   return 0;
1975 }
1976
1977 static Standard_Integer getDimNbOfDecimalPlaces (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1978 {
1979   if (argc < 3) {
1980     di<<"Use: XGetDimensionNbOfDecimalPlaces Doc Dim_Label\n";
1981     return 1;
1982   }
1983   Handle(TDocStd_Document) Doc;
1984   DDocStd::GetDocument(argv[1], Doc);
1985   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1986   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
1987   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1988
1989   TDF_Label aLabel;
1990   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
1991   if ( aLabel.IsNull() ) 
1992   {
1993     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
1994     return 1;
1995   }
1996   Handle(XCAFDoc_Dimension) aDimension;
1997   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
1998   {
1999     Standard_Integer l, r;
2000     aDimension->GetObject()->GetNbOfDecimalPlaces(l,r);
2001     di << l << "." << r;
2002   }
2003   return 0;
2004 }
2005
2006 static Standard_Integer addDimModifier (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2007 {
2008   if (argc < 4) {
2009     di<<"Use: XAddDimensionModifiers Doc Dim_Label mod1 mod2 ...\n";
2010     return 1;
2011   }
2012   Handle(TDocStd_Document) Doc;
2013   DDocStd::GetDocument(argv[1], Doc);
2014   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
2015   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
2016   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
2017
2018   TDF_Label aLabel;
2019   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2020   if ( aLabel.IsNull() ) 
2021   {
2022     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
2023     return 1;
2024   }
2025   Handle(XCAFDoc_Dimension) aDimension;
2026   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
2027   {
2028     for(Standard_Integer i = 3; i < argc; i++)
2029     {
2030       if(Draw::Atoi(argv[i]) > -1 && Draw::Atoi(argv[i]) < 24)
2031       {
2032         Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
2033         anObj->AddModifier((XCAFDimTolObjects_DimensionModif)Draw::Atoi(argv[i]));
2034         aDimension->SetObject(anObj);
2035       }
2036     }
2037   }
2038   return 0;
2039 }
2040
2041 static Standard_Integer getDimModifier (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2042 {
2043   if (argc < 3) {
2044     di<<"Use: XGetDimensionModifiers Doc Dim_Label\n";
2045     return 1;
2046   }
2047   Handle(TDocStd_Document) Doc;
2048   DDocStd::GetDocument(argv[1], Doc);
2049   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
2050   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
2051   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
2052
2053   TDF_Label aLabel;
2054   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2055   if ( aLabel.IsNull() ) 
2056   {
2057     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
2058     return 1;
2059   }
2060   Handle(XCAFDoc_Dimension) aDimension;
2061   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
2062   {
2063     XCAFDimTolObjects_DimensionModifiersSequence aS = aDimension->GetObject()->GetModifiers();
2064     for(Standard_Integer i = 1; i <= aS.Length(); i++)
2065     {
2066       if (i > 1) di<<", ";
2067       switch(aS.Value(i)){
2068       case 0  : di<<"ControlledRadius"; break;
2069       case 1  : di<<"Square"; break;
2070       case 2  : di<<"StatisticalTolerance"; break;
2071       case 3  : di<<"ContinuousFeature"; break;
2072       case 4  : di<<"TwoPointSize"; break;
2073       case 5  : di<<"LocalSizeDefinedBySphere"; break;
2074       case 6  : di<<"LeastSquaresAssociationCriterion"; break;
2075       case 7  : di<<"MaximumInscribedAssociation"; break;
2076       case 8  : di<<"MinimumCircumscribedAssociation"; break;
2077       case 9  : di<<"CircumferenceDiameter"; break;
2078       case 10 : di<<"AreaDiameter"; break;
2079       case 11 : di<<"VolumeDiameter"; break;
2080       case 12 : di<<"MaximumSize"; break;
2081       case 13 : di<<"MinimumSize"; break;
2082       case 14 : di<<"AverageSize"; break;
2083       case 15 : di<<"MedianSize"; break;
2084       case 16 : di<<"MidRangeSize"; break;
2085       case 17 : di<<"RangeOfSizes"; break;
2086       case 18 : di<<"AnyRestrictedPortionOfFeature"; break;
2087       case 19 : di<<"AnyCrossSection"; break;
2088       case 20 : di<<"SpecificFixedCrossSection"; break;
2089       case 21 : di<<"CommonTolerance"; break;
2090       case 22 : di<<"FreeStateCondition"; break;
2091       case 23 : di<<"Between"; break;
2092       default : break;
2093       }
2094     }
2095   }
2096   return 0;
2097 }
2098
2099 static Standard_Integer addDimPath (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2100 {
2101   if (argc < 4) {
2102     di<<"Use: XSetDimensionPath Doc Dim_Label path(edge)\n";
2103     return 1;
2104   }
2105   Handle(TDocStd_Document) Doc;
2106   DDocStd::GetDocument(argv[1], Doc);
2107   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
2108   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
2109   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
2110
2111   TDF_Label aLabel;
2112   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2113   if ( aLabel.IsNull() ) 
2114   {
2115     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
2116     return 1;
2117   }
2118   Handle(XCAFDoc_Dimension) aDimension;
2119   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
2120   {
2121     TopoDS_Edge aE = TopoDS::Edge(DBRep::Get(argv[3],TopAbs_EDGE));
2122     if(!aE.IsNull())
2123     {
2124       Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
2125       anObj->SetPath(aE);
2126       aDimension->SetObject(anObj);
2127     }
2128   }
2129   return 0;
2130 }
2131
2132 static Standard_Integer addDimPoints (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2133 {
2134   if (argc < 4) {
2135     di<<"Use: XSetDimensionPoints Doc Dim_Label v1 [v2]\n";
2136     return 1;
2137   }
2138   Handle(TDocStd_Document) Doc;
2139   DDocStd::GetDocument(argv[1], Doc);
2140   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
2141   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
2142   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
2143
2144   TDF_Label aLabel;
2145   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2146   if ( aLabel.IsNull() ) 
2147   {
2148     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
2149     return 1;
2150   }
2151   Handle(XCAFDoc_Dimension) aDimension;
2152   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
2153   {
2154     Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
2155
2156     TopoDS_Vertex aV1 = TopoDS::Vertex(DBRep::Get(argv[3],TopAbs_VERTEX));
2157     if(!aV1.IsNull()) {
2158       anObj->SetPoint(BRep_Tool::Pnt(aV1));
2159     }
2160     if (argc == 5) {
2161       TopoDS_Vertex aV2 = TopoDS::Vertex(DBRep::Get(argv[4],TopAbs_VERTEX));
2162       if(!aV2.IsNull()) {
2163         anObj->SetPoint2(BRep_Tool::Pnt(aV2));
2164       }
2165     }
2166     aDimension->SetObject(anObj);
2167   }
2168   return 0;
2169 }
2170
2171 static Standard_Integer getDimPoints (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2172 {
2173   if (argc < 3) {
2174     di<<"Use: XGetDimensionPoints Doc Dim_Label\n";
2175     return 1;
2176   }
2177   Handle(TDocStd_Document) Doc;
2178   DDocStd::GetDocument(argv[1], Doc);
2179   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
2180   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
2181   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
2182
2183   TDF_Label aLabel;
2184   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2185   if ( aLabel.IsNull() ) 
2186   {
2187     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
2188     return 1;
2189   }
2190   Handle(XCAFDoc_Dimension) aDimension;
2191   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
2192   {
2193     Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
2194     if(anObj->HasPoint()) {
2195       di << anObj->GetPoint().X() << ";" << anObj->GetPoint().Y() << ";" << anObj->GetPoint().Z() << " ";
2196     }
2197     if(anObj->HasPoint2()) {
2198       di << anObj->GetPoint2().X() << ";" << anObj->GetPoint2().Y() << ";" << anObj->GetPoint2().Z();
2199     }
2200  }
2201   return 0;
2202 }
2203
2204 static Standard_Integer addDimDir (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2205 {
2206   if (argc < 6) {
2207     di<<"Use: XSetDimensionDir Doc Dim_Label x y z\n";
2208     return 1;
2209   }
2210   Handle(TDocStd_Document) Doc;
2211   DDocStd::GetDocument(argv[1], Doc);
2212   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
2213   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
2214   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
2215
2216   TDF_Label aLabel;
2217   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2218   if ( aLabel.IsNull() ) 
2219   {
2220     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
2221     return 1;
2222   }
2223   Handle(XCAFDoc_Dimension) aDimension;
2224   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
2225   {
2226     Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
2227     anObj->SetDirection(gp_Dir(Draw::Atof(argv[3]),Draw::Atof(argv[4]),Draw::Atof(argv[5])));
2228     aDimension->SetObject(anObj);
2229   }
2230   return 0;
2231 }
2232
2233 static Standard_Integer getDimDir (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2234 {
2235   if (argc < 3) {
2236     di<<"Use: XGetDimensionDir Doc Dim_Label\n";
2237     return 1;
2238   }
2239   Handle(TDocStd_Document) Doc;
2240   DDocStd::GetDocument(argv[1], Doc);
2241   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
2242   Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main());
2243   Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
2244
2245   TDF_Label aLabel;
2246   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2247   if ( aLabel.IsNull() ) 
2248   {
2249     di<<"Dimension "<<argv[2]<<" is absent in "<<argv[1]<<"\n";
2250     return 1;
2251   }
2252   Handle(XCAFDoc_Dimension) aDimension;
2253   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
2254   {
2255     gp_Dir dir;
2256     if(aDimension->GetObject()->GetDirection(dir))
2257     {
2258       di << dir.X()<< ";"<< dir.Y()<< ";"<<dir.Z(); 
2259     }
2260   }
2261   return 0;
2262 }
2263
2264 static Standard_Integer addDimDescr (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2265 {
2266   if (argc < 4) {
2267     di<<"Use: XAddDimensionDescr Doc Dim_Label Description [DescriptionName]\n";
2268     return 1;
2269   }
2270   Handle(TDocStd_Document) Doc;
2271   DDocStd::GetDocument(argv[1], Doc);
2272   if ( Doc.IsNull() ) {
2273     di << argv[1] << " is not a document\n";
2274     return 1;
2275   }
2276
2277   TDF_Label aLabel;
2278   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2279   if ( aLabel.IsNull() ) 
2280   {
2281     di << "Dimension "<< argv[2] << " is absent in " << argv[1] << "\n";
2282     return 1;
2283   }
2284   Handle(XCAFDoc_Dimension) aDimension;
2285   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
2286   {
2287     Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
2288     Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString(argv[3]);
2289     Handle(TCollection_HAsciiString) aDescrName = (argc == 4) ? new TCollection_HAsciiString()
2290         : new TCollection_HAsciiString(argv[4]);
2291     anObj->AddDescription(aDescription, aDescrName);
2292     aDimension->SetObject(anObj);
2293   }
2294   return 0;
2295 }
2296
2297 static Standard_Integer getDimDescr (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2298 {
2299   if (argc < 3) {
2300     di << "Use: XGetDimensionDescr Doc Dim_Label\n";
2301     return 1;
2302   }
2303   Handle(TDocStd_Document) Doc;
2304   DDocStd::GetDocument(argv[1], Doc);
2305   if ( Doc.IsNull() ) {
2306     di << argv[1] << " is not a document\n";
2307     return 1;
2308   }
2309
2310   TDF_Label aLabel;
2311   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2312   if ( aLabel.IsNull() ) 
2313   {
2314     di << "Dimension "<< argv[2] << " is absent in " << argv[1] << "\n";
2315     return 1;
2316   }
2317   Handle(XCAFDoc_Dimension) aDimension;
2318   if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
2319   {
2320     Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimension->GetObject();
2321     for (Standard_Integer i = 0; i < anObject->NbDescriptions(); i++) {
2322       Handle(TCollection_HAsciiString) aDescription = anObject->GetDescription(i);
2323       Handle(TCollection_HAsciiString) aDescrName = anObject->GetDescriptionName(i);
2324       di << "name: " << aDescrName->ToCString() << " description: " << aDescription->ToCString() << "\n";
2325     }
2326   }
2327   return 0;
2328 }
2329
2330 static Standard_Integer addGDTPosition (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2331 {
2332   if (argc < 12) {
2333     di << "Use: XSetGDTPosition Doc GDT_Label loc_x loc_y loc_z normal_x normal_y normal_z xdir_x xdir_y xdir_z\n";
2334     return 1;
2335   }
2336   Handle(TDocStd_Document) Doc;
2337   DDocStd::GetDocument(argv[1], Doc);
2338   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
2339
2340   TDF_Label aLabel;
2341   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2342   if ( aLabel.IsNull() ) 
2343   {
2344     di << "GDT " << argv[2] << " is absent in " << argv[1] << "\n";
2345     return 1;
2346   }
2347   
2348   gp_Pnt aPoint(Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5]));
2349   gp_Dir aNormal(Draw::Atof(argv[6]), Draw::Atof(argv[7]), Draw::Atof(argv[8]));
2350   gp_Dir aDir(Draw::Atof(argv[9]), Draw::Atof(argv[10]), Draw::Atof(argv[11]));
2351   gp_Ax2 aPlane(aPoint, aNormal, aDir);
2352   // Dimension
2353   Handle(XCAFDoc_Dimension) aDimension;
2354   if (aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
2355   {
2356     Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
2357     anObj->SetPlane(aPlane);
2358     anObj->SetPointTextAttach(aPoint);
2359     aDimension->SetObject(anObj);
2360   }
2361   // Geometric Tolerance
2362   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
2363   if (aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
2364   {
2365     Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
2366     anObj->SetPlane(aPlane);
2367     anObj->SetPointTextAttach(aPoint);
2368     aGeomTolerance->SetObject(anObj);
2369   }
2370   // Datum
2371   Handle(XCAFDoc_Datum) aDatum;
2372   if (aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum))
2373   {
2374     Handle(XCAFDimTolObjects_DatumObject) anObj = aDatum->GetObject();
2375     anObj->SetPlane(aPlane);
2376     anObj->SetPointTextAttach(aPoint);
2377     aDatum->SetObject(anObj);
2378   }
2379   return 0;
2380 }
2381
2382 static Standard_Integer getGDTPosition (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2383 {
2384   if (argc < 3) {
2385     di << "Use: XGetGDTPosition Doc GDT_Label\n";
2386     return 1;
2387   }
2388   Handle(TDocStd_Document) Doc;
2389   DDocStd::GetDocument(argv[1], Doc);
2390   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
2391
2392   TDF_Label aLabel;
2393   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2394   if ( aLabel.IsNull() ) 
2395   {
2396     di << "GDT " << argv[2] << " is absent in " << argv[1] << "\n";
2397     return 1;
2398   }
2399   gp_Pnt aPoint;
2400   gp_Dir aNormal, aDir;
2401   // Dimension
2402   Handle(XCAFDoc_Dimension) aDimension;
2403   if (aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
2404   {
2405     Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
2406     aPoint = anObj->GetPointTextAttach();
2407     aNormal = anObj->GetPlane().Direction();
2408     aDir = anObj->GetPlane().XDirection();
2409   }
2410   // Geometric Tolerance
2411   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
2412   if (aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
2413   {
2414     Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
2415     aPoint = anObj->GetPointTextAttach();
2416     aNormal = anObj->GetPlane().Direction();
2417     aDir = anObj->GetPlane().XDirection();
2418   }
2419   // Datum
2420   Handle(XCAFDoc_Datum) aDatum;
2421   if (aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum))
2422   {
2423     Handle(XCAFDimTolObjects_DatumObject) anObj = aDatum->GetObject();
2424     aPoint = anObj->GetPointTextAttach();
2425     aNormal = anObj->GetPlane().Direction();
2426     aDir = anObj->GetPlane().XDirection();
2427   }
2428
2429   di << "position: " << aPoint.X() << " " << aPoint.Y() << " " << aPoint.Z() << "\n";
2430   di << "normal: " << aNormal.X() << " " << aNormal.Y() << " " << aNormal.Z() << "\n";
2431   di << "x_direction: " << aDir.X() << " " << aDir.Y() << " " << aDir.Z() << "\n";
2432   return 0;
2433 }
2434
2435 static Standard_Integer addGDTPresentation (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2436 {
2437   if (argc < 5) {
2438     di << "Use: XSetGDTPresentation Doc GDT_Label Shape Name\n";
2439     return 1;
2440   }
2441   Handle(TDocStd_Document) Doc;
2442   DDocStd::GetDocument(argv[1], Doc);
2443   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
2444
2445   TDF_Label aLabel;
2446   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2447   if ( aLabel.IsNull() ) 
2448   {
2449     di << "GDT " << argv[2] << " is absent in " << argv[1] << "\n";
2450     return 1;
2451   }
2452   
2453   TopoDS_Shape aPresentation= DBRep::Get(argv[3]);
2454   Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(argv[4]);
2455   // Dimension
2456   Handle(XCAFDoc_Dimension) aDimension;
2457   if (aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
2458   {
2459     Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
2460     anObj->SetPresentation(aPresentation, aName);
2461     aDimension->SetObject(anObj);
2462   }
2463   // Geometric Tolerance
2464   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
2465   if (aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
2466   {
2467     Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
2468     anObj->SetPresentation(aPresentation, aName);
2469     aGeomTolerance->SetObject(anObj);
2470   }
2471   // Datum
2472   Handle(XCAFDoc_Datum) aDatum;
2473   if (aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum))
2474   {
2475     Handle(XCAFDimTolObjects_DatumObject) anObj = aDatum->GetObject();
2476     anObj->SetPresentation(aPresentation, aName);
2477     aDatum->SetObject(anObj);
2478   }
2479   return 0;
2480 }
2481
2482 static Standard_Integer getGDTPresentation (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2483 {
2484   if (argc < 3) {
2485     di << "Use: XGetGDTPresentation Doc GDT_Label Shape\n";
2486     return 1;
2487   }
2488   Handle(TDocStd_Document) Doc;
2489   DDocStd::GetDocument(argv[1], Doc);
2490   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
2491
2492   TDF_Label aLabel;
2493   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2494   if ( aLabel.IsNull() ) 
2495   {
2496     di << "GDT " << argv[2] << " is absent in " << argv[1] << "\n";
2497     return 1;
2498   }
2499   TopoDS_Shape aPresentation;
2500   // Dimension
2501   Handle(XCAFDoc_Dimension) aDimension;
2502   if (aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
2503   {
2504     Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
2505     aPresentation = anObj->GetPresentation();
2506   }
2507   // Geometric Tolerance
2508   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
2509   if (aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
2510   {
2511     Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
2512     aPresentation = anObj->GetPresentation();
2513   }
2514   // Datum
2515   Handle(XCAFDoc_Datum) aDatum;
2516   if (aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum))
2517   {
2518     Handle(XCAFDimTolObjects_DatumObject) anObj = aDatum->GetObject();
2519     aPresentation = anObj->GetPresentation();
2520   }
2521
2522   DBRep::Set (argv[3], aPresentation);
2523   return 0;
2524 }
2525
2526 static Standard_Integer addGDTAffectedPlane(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2527 {
2528   if (argc != 5) {
2529     di << "Use: XSetGDTAffectedPlane Doc GDT_Label plane type[1 - intersection/ 2 - orientation]\n";
2530     return 1;
2531   }
2532   Handle(TDocStd_Document) Doc;
2533   DDocStd::GetDocument(argv[1], Doc);
2534   if (Doc.IsNull()) { di << argv[1] << " is not a document\n"; return 1; }
2535
2536   TDF_Label aLabel;
2537   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2538   if (aLabel.IsNull())
2539   {
2540     di << "GDT " << argv[2] << " is absent in " << argv[1] << "\n";
2541     return 1;
2542   }
2543
2544   Handle(Geom_Surface) aSurf = DrawTrSurf::GetSurface(argv[3]);
2545   Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf);
2546   if (aPlane.IsNull())
2547   {
2548     di << "Invalid plane\n";
2549     return 1;
2550   }
2551   Standard_Integer aType = Draw::Atoi(argv[4]);
2552
2553   // Geometric Tolerance
2554   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
2555   if (!aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
2556   {
2557     di << "Geometric tolerance is abcent on label" << argv[2] << "\n";
2558     return 1;
2559   }
2560
2561   Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
2562   anObj->SetAffectedPlane(aPlane->Pln(), (XCAFDimTolObjects_ToleranceZoneAffectedPlane)aType);
2563   aGeomTolerance->SetObject(anObj);
2564   return 0;
2565 }
2566
2567 static Standard_Integer getGDTAffectedPlane(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2568 {
2569   if (argc != 4) {
2570     di << "Use: XGetGDTAffectedPlane Doc GDT_Label Plane\n";
2571     return 1;
2572   }
2573   Handle(TDocStd_Document) Doc;
2574   DDocStd::GetDocument(argv[1], Doc);
2575   if (Doc.IsNull()) { di << argv[1] << " is not a document\n"; return 1; }
2576
2577   TDF_Label aLabel;
2578   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2579   if (aLabel.IsNull())
2580   {
2581     di << "GDT " << argv[2] << " is absent in " << argv[1] << "\n";
2582     return 1;
2583   }
2584
2585   // Geometric Tolerance
2586   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
2587   Handle(Geom_Plane) aPlane;
2588   if (aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
2589   {
2590     Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
2591     if (anObj->GetAffectedPlaneType() == XCAFDimTolObjects_ToleranceZoneAffectedPlane_None)
2592     {
2593       di << "No affected plane\n";
2594       return 0;
2595     }
2596     gp_Pln aPln = anObj->GetAffectedPlane();
2597     aPlane = new Geom_Plane(aPln);
2598     if (anObj->GetAffectedPlaneType() == XCAFDimTolObjects_ToleranceZoneAffectedPlane_Intersection)
2599       di << "intersection plane\n";
2600     if (anObj->GetAffectedPlaneType() == XCAFDimTolObjects_ToleranceZoneAffectedPlane_Orientation)
2601       di << "orientation plane\n";
2602     DrawTrSurf::Set(argv[3], aPlane);
2603   }
2604
2605   return 0;
2606 }
2607
2608 static Standard_Integer getGDTSemanticName(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2609 {
2610   if (argc < 3) {
2611     di << "Use: XGetGDTSemanticName Doc GDT_Label\n";
2612     return 1;
2613   }
2614   Handle(TDocStd_Document) Doc;
2615   DDocStd::GetDocument(argv[1], Doc);
2616   if (Doc.IsNull()) { di << argv[1] << " is not a document\n"; return 1; }
2617
2618   TDF_Label aLabel;
2619   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2620   if (aLabel.IsNull())
2621   {
2622     di << "GDT " << argv[2] << " is absent in " << argv[1] << "\n";
2623     return 1;
2624   }
2625   Handle(TCollection_HAsciiString) aSemanticName;
2626   // Dimension
2627   Handle(XCAFDoc_Dimension) aDimension;
2628   if (aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
2629   {
2630     Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
2631     aSemanticName = anObj->GetSemanticName();
2632   }
2633   // Geometric Tolerance
2634   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
2635   if (aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
2636   {
2637     Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
2638     aSemanticName = anObj->GetSemanticName();
2639   }
2640   // Datum
2641   Handle(XCAFDoc_Datum) aDatum;
2642   if (aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum))
2643   {
2644     Handle(XCAFDimTolObjects_DatumObject) anObj = aDatum->GetObject();
2645     aSemanticName = anObj->GetSemanticName();
2646   }
2647   if (aSemanticName)
2648   {
2649     di << aSemanticName->String();
2650   }
2651   return 0;
2652 }
2653
2654 static Standard_Integer setGDTSemanticName(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2655 {
2656   if (argc < 3) {
2657     di << "Use: XSetGDTSemanticName Doc GDT_Label Name\n";
2658     return 1;
2659   }
2660   Handle(TDocStd_Document) Doc;
2661   DDocStd::GetDocument(argv[1], Doc);
2662   if (Doc.IsNull()) { di << argv[1] << " is not a document\n"; return 1; }
2663
2664   TDF_Label aLabel;
2665   TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
2666   if (aLabel.IsNull())
2667   {
2668     di << "GDT " << argv[2] << " is absent in " << argv[1] << "\n";
2669     return 1;
2670   }
2671   Handle(TCollection_HAsciiString) aSemanticName = new TCollection_HAsciiString(argv[3]);
2672   // Dimension
2673   Handle(XCAFDoc_Dimension) aDimension;
2674   if (aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
2675   {
2676     Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
2677     anObj->SetSemanticName(aSemanticName);
2678     aDimension->SetObject(anObj);
2679   }
2680   // Geometric Tolerance
2681   Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
2682   if (aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
2683   {
2684     Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
2685     anObj->SetSemanticName(aSemanticName);
2686     aGeomTolerance->SetObject(anObj);
2687   }
2688   // Datum
2689   Handle(XCAFDoc_Datum) aDatum;
2690   if (aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum))
2691   {
2692     Handle(XCAFDimTolObjects_DatumObject) anObj = aDatum->GetObject();
2693     anObj->SetSemanticName(aSemanticName);
2694     aDatum->SetObject(anObj);
2695   }
2696   return 0;
2697 }
2698
2699 //=======================================================================
2700 //function : InitCommands
2701 //purpose  : 
2702 //=======================================================================
2703
2704 void XDEDRAW_GDTs::InitCommands(Draw_Interpretor& di) 
2705 {
2706   static Standard_Boolean initactor = Standard_False;
2707   if (initactor)
2708   {
2709     return;
2710   }
2711   initactor = Standard_True;
2712   
2713   Standard_CString g = "XDE G&DTs commands";
2714
2715   di.Add ("XDumpDGTs","XDumpDGTs Doc shape/label/all ",
2716     __FILE__, DumpDGTs, g);
2717
2718   di.Add ("XDumpNbDGTs","XDumpNbDGTs Doc [f (full dumping)]",
2719     __FILE__, DumpNbDGTs, g);
2720
2721   di.Add ("XAddDimension","XAddDimension Doc shape/label [shape/label]",
2722     __FILE__, addDim, g);
2723
2724   di.Add ("XAddGeomTolerance","XAddGeomTolerance Doc shape/label",
2725     __FILE__, addGTol, g);
2726
2727   di.Add ("XAddDatum","XAddDatum Doc shape1/label1 ... shapeN/labelN",
2728     __FILE__, addDatum, g);
2729
2730   di.Add ("XSetDatum","XSetDatum Doc Datum_Label GeomTol_Label",
2731     __FILE__, setDatum, g);
2732
2733   di.Add ("XGetDatum","XGetDatum Doc GeomTol_Label/Shape_Label",
2734     __FILE__, getDatum, g);
2735
2736   di.Add ("XAddDatumModifier","XAddDatumModifier Doc Datum_Label mod1 mod2 ...\n"
2737     "Values:"
2738     "\n  0 AnyCrossSection"
2739     "\n  1 Any_LongitudinalSection"
2740     "\n  2 Basic"
2741     "\n  3 ContactingFeature"
2742     "\n  4 DegreeOfFreedomConstraintU"
2743     "\n  5 DegreeOfFreedomConstraintV"
2744     "\n  6 DegreeOfFreedomConstraintW"
2745     "\n  7 DegreeOfFreedomConstraintX"
2746     "\n  8 DegreeOfFreedomConstraintY"
2747     "\n  9 DegreeOfFreedomConstraintZ"
2748     "\n 10 DistanceVariable"
2749     "\n 11 FreeState"
2750     "\n 12 LeastMaterialRequirement"
2751     "\n 13 Line"
2752     "\n 14 MajorDiameter"
2753     "\n 15 MaximumMaterialRequirement"
2754     "\n 16 MinorDiameter"
2755     "\n 17 Orientation"
2756     "\n 18 PitchDiameter"
2757     "\n 19 Plane"
2758     "\n 20 Point"
2759     "\n 21 Translation",
2760     __FILE__, addDatumModif, g);
2761
2762   di.Add ("XGetDatumModifiers","XGetDatumModifiers Doc Datum_Label",
2763     __FILE__, getDatumModif, g);
2764
2765   di.Add ("XSetDatumName","XSetDatumName Doc Datum_Label name",
2766     __FILE__, setDatumName, g);
2767
2768   di.Add ("XGetDatumName","XGetDatumName Doc Datum_Label",
2769     __FILE__, getDatumName, g);
2770
2771   di.Add ("XSetDatumPosition","XSetDatumPosition Doc Datum_Label position[1-3]"
2772       "Set datum position number in geometric tolerance datum system",
2773     __FILE__, setDatumPosition, g);
2774
2775   di.Add ("XGetDatumPosition","XGetDatumPosition Doc Datum_Label",
2776     __FILE__, getDatumPosition, g);
2777
2778   di.Add ("XSetTypeOfTolerance","XSetTypeOfTolerance Doc GTol_Label type"
2779         "Values:\n"
2780       "\t  0 type is absent\n"
2781       "\t  1 Angularity\n"
2782       "\t  2 CircularRunout\n"
2783       "\t  3 CircularityOrRoundness\n"
2784       "\t  4 Coaxiality\n"
2785       "\t  5 Concentricity\n"
2786       "\t  6 Cylindricity\n"
2787       "\t  7 Flatness\n"
2788       "\t  8 Parallelism\n"
2789       "\t  9 Perpendicularity\n"
2790       "\t 10 Position\n"
2791       "\t 11 ProfileOfLine\n"
2792       "\t 12 ProfileOfSurface\n"
2793       "\t 13 Straightness\n"
2794       "\t 14 Symmetry\n"
2795       "\t 15 TotalRunout\n",
2796     __FILE__, setTypeOfTol, g);
2797
2798   di.Add ("XGetTypeOfTolerance","XGetTypeOfTolerance Doc GTol_Label",
2799     __FILE__, getTypeOfTol, g);
2800
2801   di.Add ("XSetTypeOfToleranceValue","XSetTypeOfToleranceValue Doc GTol_Label type"
2802         "Values:"
2803     "\n  0 none"
2804     "\n  1 Diameter"
2805     "\n  2 SphericalDiameter",
2806     __FILE__, setTypeOfTolVal, g);
2807
2808   di.Add ("XGetTypeOfToleranceValue","XGetTypeOfToleranceValue Doc GTol_Label",
2809     __FILE__, getTypeOfTolVal, g);
2810
2811   di.Add ("XSetToleranceValue","XSetToleranceValue Doc GTol_Label value",
2812     __FILE__, setTolVal, g);
2813
2814   di.Add ("XGetToleranceValue","XGetToleranceValue Doc GTol_Label",
2815     __FILE__, getTolVal, g);
2816
2817   di.Add ("XSetTolMaterialReq","XSetTolMaterialReq Doc GTol_Label mod"
2818         "Values:"
2819     "\n  0 none"
2820     "\n  1 M"
2821     "\n  2 L",
2822     __FILE__, setMatReq, g);
2823
2824   di.Add ("XGetTolMaterialReq","XGetTolMaterialReq Doc GTol_Label",
2825     __FILE__, getMatReq, g);
2826
2827   di.Add ("XSetTolZoneMod","XSetTolZoneMod Doc GTol_Label mod"
2828         "Values:"
2829     "\n  0 none"
2830     "\n  1 P"
2831     "\n  2 NonUniform",
2832     __FILE__, setZoneMod, g);
2833
2834   di.Add ("XGetTolZoneMod","XGetTolZoneMod Doc GTol_Label",
2835     __FILE__, getZoneMod, g);
2836
2837   di.Add ("XSetTolZoneModValue","XSetTolZoneModValue Doc GTol_Label val",
2838     __FILE__, setZoneModVal, g);
2839
2840   di.Add ("XGetTolZoneModValue","XGetTolZoneModValue Doc GTol_Label",
2841     __FILE__, getZoneModVal, g);
2842   
2843   di.Add ("XAddTolModifier","XAddTolModifier Doc Tol_Label mod1 mod2 ..."
2844         "Values:\n"
2845       "\t  0 Any_Cross_Section\n"
2846       "\t  1 Common_Zone\n"
2847       "\t  2 Each_Radial_Element\n"
2848       "\t  3 Free_State\n"
2849       "\t  4 Least_Material_Requirement\n"
2850       "\t  5 Line_Element\n"
2851       "\t  6 Major_Diameter\n"
2852       "\t  7 Maximum_Material_Requirement\n"
2853       "\t  8 Minor_Diameter\n"
2854       "\t  9 Not_Convex\n"
2855       "\t 10 Pitch_Diameter\n"
2856       "\t 11 Reciprocity_Requirement\n"
2857       "\t 12 Separate_Requirement\n"
2858       "\t 13 Statistical_Tolerance\n"
2859       "\t 14 Tangent_Plane\n",
2860     __FILE__, addTolModif, g);
2861
2862   di.Add ("XGetTolModifier","XGetTolModifier Doc Tol_Label",
2863     __FILE__, getTolModif, g);
2864
2865   di.Add ("XSetTolMaxValue","XSetTolMaxValue Doc Dim_Label val",
2866     __FILE__, setTolMaxVal, g);
2867
2868   di.Add ("XGetTolMaxValue","XGetTolMaxValue Doc Dim_Label val",
2869     __FILE__, getTolMaxVal, g);
2870
2871   di.Add ("XSetDimensionType","XSetDimensionType Doc Dim_Label type"
2872         "Values:"
2873       "\t  0 type is absent\n"
2874       "\t  1 Location_CurvedDistance\n"
2875       "\t  2 Location_LinearDistance\n"
2876       "\t  3 Location_LinearDistance_FromCenterToOuter\n"
2877       "\t  4 Location_LinearDistance_FromCenterToInner\n"
2878       "\t  5 Location_LinearDistance_FromOuterToCenter\n"
2879       "\t  6 Location_LinearDistance_FromOuterToOuter\n"
2880       "\t  7 Location_LinearDistance_FromOuterToInner\n"
2881       "\t  8 Location_LinearDistance_FromInnerToCenter\n"
2882       "\t  9 Location_LinearDistance_FromInnerToOuter\n"
2883       "\t 10 Location_LinearDistance_FromInnerToInner\n"
2884       "\t 11 Location_Angular\n"
2885       "\t 12 Location_Oriented\n"
2886       "\t 13 Location_WithPath\n"
2887       "\t 14 Size_CurveLength\n"
2888       "\t 15 Size_Diameter\n"
2889       "\t 16 Size_SphericalDiameter\n"
2890       "\t 17 Size_Radius\n"
2891       "\t 18 Size_SphericalRadius\n"
2892       "\t 19 Size_ToroidalMinorDiameter\n"
2893       "\t 20 Size_ToroidalMajorDiameter\n"
2894       "\t 21 Size_ToroidalMinorRadius\n"
2895       "\t 22 Size_ToroidalMajorRadius\n"
2896       "\t 23 Size_ToroidalHighMajorDiameter\n"
2897       "\t 24 Size_ToroidalLowMajorDiameter\n"
2898       "\t 25 Size_ToroidalHighMajorRadius\n"
2899       "\t 26 Size_ToroidalLowMajorRadius\n"
2900       "\t 27 Size_Thickness\n"
2901       "\t 28 Size_Angular\n"
2902       "\t 29 Size_WithPath\n",
2903     __FILE__, setDimType, g);
2904
2905   di.Add ("XGetDimensionType","XGetDimensionType Doc Dim_Label",
2906     __FILE__, getDimType, g);
2907
2908   di.Add ("XSetDimensionValue","XSetDimensionValue Doc Dim_Label val",
2909     __FILE__, setDimVal, g);
2910
2911   di.Add ("XGetDimensionValue","XGetDimensionValue Doc Dim_Label",
2912     __FILE__, getDimVal, g);
2913
2914   di.Add ("XSetDimensionQualifier","XSetDimensionQualifier Doc Dim_Label val"
2915         "Values:"
2916     "\n  0 none"
2917     "\n  1 Min"
2918     "\n  2 Max"
2919     "\n  3 Avg",
2920     __FILE__, setDimQalif, g);
2921   
2922   di.Add ("XGetDimensionQualifier","XGetDimensionQualifier Doc Dim_Label",
2923     __FILE__, getDimQalif, g);
2924
2925   di.Add ("XSetDimensionRange","XSetDimensionRange Doc Dim_Label low_val up_val",
2926     __FILE__, setDimRange, g);
2927
2928   di.Add ("XGetDimensionRange","XGetDimensionRange Doc Dim_Label",
2929     __FILE__, getDimRange, g);
2930
2931   di.Add ("XSetDimensionPlusMinusTol","XSetDimensionPlusMinusTol Doc Dim_Label low_val up_val",
2932     __FILE__, setDimPlusMinusTol, g);
2933
2934   di.Add ("XGetDimensionPlusMinusTol","XGetDimensionPlusMinusTol Doc Dim_Label",
2935     __FILE__, getDimPlusMinusTol, g);
2936
2937   di.Add ("XSetDimensionClassOfTol","XSetDimensionClassOfTol Doc Dim_Label ishole[1/0] formVar grade"
2938         "Values of formVar:"
2939         "\t 1 a\n"
2940         "\t 2 b\n"
2941         "\t 3 c\n"
2942         "\t 4 cd\n"
2943         "\t 5 d\n"
2944         "\t 6 e\n"
2945         "\t 7 ef\n"
2946         "\t 8 f\n"
2947         "\t 9 fg\n"
2948         "\t10 g\n"
2949         "\t11 h\n"
2950         "\t12 js\n"
2951         "\t13 j\n"
2952         "\t14 k\n"
2953         "\t15 m\n"
2954         "\t16 n\n"
2955         "\t17 p\n"
2956         "\t18 r\n"
2957         "\t19 s\n"
2958         "\t20 t\n"
2959         "\t21 u\n"
2960         "\t22 v\n"
2961         "\t23 x\n"
2962         "\t24 y\n"
2963         "\t25 z\n"
2964         "\t26 za\n"
2965         "\t27 zb\n"
2966         "\t28 zc\n\n"
2967         "Values of grade:"
2968         "\t 0 01\n"
2969         "\t 1 0\n"
2970         "\t 2 1\n"
2971         "\t 3 2d\n"
2972         "\t 4 3\n"
2973         "\t 5 4\n"
2974         "\t 6 5f\n"
2975         "\t 7 76\n"
2976         "\t 8 7g\n"
2977         "\t 9 8\n"
2978         "\t10 9\n"
2979         "\t11 10js\n"
2980         "\t12 11j\n"
2981         "\t13 12k\n"
2982         "\t14 13m\n"
2983         "\t15 14n\n"
2984         "\t16 15p\n"
2985         "\t17 16r\n"
2986         "\t18 17s\n"
2987         "\t19 18t\n",
2988     __FILE__, setDimClassTol, g);
2989
2990   di.Add ("XGetDimensionClassOfTol","XGetDimensionClassOfTol Doc Dim_Label",
2991     __FILE__, getDimClassTol, g);
2992
2993   di.Add ("XSetDimensionNbOfDecimalPlaces","XSetDimensionNbOfDecimalPlaces Doc Dim_Label l_val r_val",
2994     __FILE__, setDimNbOfDecimalPlaces, g);
2995
2996   di.Add ("XGetDimensionNbOfDecimalPlaces","XGetDimensionNbOfDecimalPlaces Doc Dim_Label",
2997     __FILE__, getDimNbOfDecimalPlaces, g);
2998
2999   di.Add ("XAddDimensionModifiers","XAddDimensionModifiers Doc Dim_Label mod1 mod2 ..."
3000         "Values:"
3001       "\t 0 ControlledRadius\n"
3002       "\t 1 Square\n"
3003       "\t 2 StatisticalTolerance\n"
3004       "\t 3 ContinuousFeature\n"
3005       "\t 4 TwoPointSize\n"
3006       "\t 5 LocalSizeDefinedBySphere\n"
3007       "\t 6 LeastSquaresAssociationCriterion\n"
3008       "\t 7 MaximumInscribedAssociation\n"
3009       "\t 8 MinimumCircumscribedAssociation\n"
3010       "\t 9 CircumferenceDiameter\n"
3011       "\t10 AreaDiameter\n"
3012       "\t11 VolumeDiameter\n"
3013       "\t12 MaximumSize\n"
3014       "\t13 MinimumSize\n"
3015       "\t14 AverageSize\n"
3016       "\t15 MedianSize\n"
3017       "\t16 MidRangeSize\n"
3018       "\t17 RangeOfSizes\n"
3019       "\t18 AnyRestrictedPortionOfFeature\n"
3020       "\t19 AnyCrossSection\n"
3021       "\t20 SpecificFixedCrossSection\n"
3022       "\t21 CommonTolerance\n"
3023       "\t22 FreeStateCondition\n"
3024       "\t23 Between\n",
3025     __FILE__, addDimModifier, g);
3026
3027   di.Add ("XGetDimensionModifiers","XGetDimensionModifiers Doc Dim_Label",
3028     __FILE__, getDimModifier, g);
3029   
3030   di.Add ("XSetDimensionPath","XSetDimensionPath Doc Dim_Label path(edge)",
3031     __FILE__, addDimPath, g);
3032
3033   di.Add ("XSetDimensionPoints","XSetDimensionPoints Doc Dim_Label v1 [v2]",
3034     __FILE__, addDimPoints, g);
3035
3036   di.Add ("XGetDimensionPoints","XGetDimensionPoints Doc Dim_Label",
3037     __FILE__, getDimPoints, g);
3038
3039   di.Add ("XSetDimensionDir","XSetDimensionDir Doc Dim_Label x y z",
3040     __FILE__, addDimDir, g);
3041
3042   di.Add ("XGetDimensionDir","XGetDimensionDir Doc Dim_Label",
3043     __FILE__, getDimDir, g);
3044
3045   di.Add ("XAddDimensionDescr","XAddDimensionDescr Doc Dim_Label Description [DescriptionName]\n"
3046     "Add named text description to given Dimension, if DescriptionName is missed"
3047     "name will be an empty string.",
3048     __FILE__, addDimDescr, g);
3049
3050   di.Add ("XGetDimensionDescr","XGetDimensionDescr Doc Dim_Label\n"
3051     "Return all descriptions of given Dimension.",
3052     __FILE__, getDimDescr, g);
3053
3054   di.Add ("XSetGDTPosition","XSetGDTPosition Doc GDT_Label loc_x loc_y loc_z normal_x normal_y normal_z xdir_x xdir_y xdir_z"
3055     "Set plane to display dimension parallel to and point to display text (loc)",
3056     __FILE__, addGDTPosition, g);
3057
3058   di.Add ("XGetGDTPosition","XGetGDTPosition Doc GDT_Label"
3059     "Returns text position and plane, parallel to which dimension is displayed",
3060     __FILE__, getGDTPosition, g);
3061
3062   di.Add ("XSetGDTPresentation","XSetGDTPresentation Doc GDT_Label Shape Name"
3063     "Set presentation with given name for dimension",
3064     __FILE__, addGDTPresentation, g);
3065
3066   di.Add ("XGetGDTPresentation","XGetGDTPresentation Doc GDT_Label Shape"
3067     "Returns Presentation into Shape",
3068     __FILE__, getGDTPresentation, g);
3069   di.Add("XSetGDTAffectedPlane", "XSetGDTAffectedPlane Doc GDT_Label Plane type[1 - intersection/ 2 - orientation]"
3070     "Set affectedP plane for geometric tolerance",
3071     __FILE__, addGDTAffectedPlane, g);
3072
3073   di.Add("XGetGDTAffectedPlane", "XGetGDTAffectedPlane Doc GDT_Label Plane"
3074     "Returns affected plane into Plane",
3075     __FILE__, getGDTAffectedPlane, g);
3076   di.Add("XGetGDTSemanticName", "XGetGDTSemanticName Doc GDT_Label"
3077     __FILE__, getGDTSemanticName, g);
3078
3079   di.Add("XSetGDTSemanticName", "XSetGDTSemanticName Doc GDT_Label Name"
3080     "Set semantic name",
3081     __FILE__, setGDTSemanticName, g);
3082 }