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