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