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