0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / STEPCAFControl / STEPCAFControl_GDTProperty.cxx
1 // Created on: 2015-09-10
2 // Created by: Irina Krylova
3 // Copyright (c) 1999-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 <BRep_Tool.hxx>
17 #include <Geom_BSplineCurve.hxx>
18 #include <Geom_Curve.hxx>
19 #include <Geom_Line.hxx>
20 #include <ShapeConstruct_Curve.hxx>
21 #include <STEPCAFControl_GDTProperty.hxx>
22 #include <StepBasic_MeasureValueMember.hxx>
23 #include <StepGeom_CartesianPoint.hxx>
24 #include <StepGeom_Direction.hxx>
25 #include <StepDimTol_CylindricityTolerance.hxx>
26 #include <StepDimTol_FlatnessTolerance.hxx>
27 #include <StepDimTol_LineProfileTolerance.hxx>
28 #include <StepDimTol_PositionTolerance.hxx>
29 #include <StepDimTol_RoundnessTolerance.hxx>
30 #include <StepDimTol_StraightnessTolerance.hxx>
31 #include <StepDimTol_SurfaceProfileTolerance.hxx>
32 #include <StepRepr_DescriptiveRepresentationItem.hxx>
33 #include <StepVisual_CoordinatesList.hxx>
34 #include <StepVisual_TessellatedCurveSet.hxx>
35 #include <TopExp_Explorer.hxx>
36 #include <TopoDS.hxx>
37 #include <TopoDS_Shape.hxx>
38 #include <XCAFDimTolObjects_DatumModifiersSequence.hxx>
39 #include <XCAFDimTolObjects_DatumModifWithValue.hxx>
40
41 //=======================================================================
42 //function : STEPCAFControl_GDTProperty
43 //purpose  : 
44 //=======================================================================
45
46 STEPCAFControl_GDTProperty::STEPCAFControl_GDTProperty ()
47 {
48 }
49
50 //=======================================================================
51 //function : getDimModifiers
52 //purpose  : 
53 //=======================================================================
54 void STEPCAFControl_GDTProperty::GetDimModifiers(const Handle(StepRepr_CompoundRepresentationItem)& theCRI,
55                             XCAFDimTolObjects_DimensionModifiersSequence& theModifiers)
56 {
57   for (Standard_Integer l = 1; l <= theCRI->ItemElement()->Length(); l++)
58   {
59     Handle(StepRepr_DescriptiveRepresentationItem) aDRI =
60       Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(theCRI->ItemElement()->Value(l));
61     if(aDRI.IsNull()) continue;
62     XCAFDimTolObjects_DimensionModif aModifier = XCAFDimTolObjects_DimensionModif_ControlledRadius;
63     const TCollection_AsciiString aModifStr = aDRI->Description()->String();
64     Standard_Boolean aFound = Standard_False;
65     if(aModifStr.IsEqual("controlled radius"))
66     {
67       aFound = Standard_True;
68       aModifier = XCAFDimTolObjects_DimensionModif_ControlledRadius;
69     }
70     else if(aModifStr.IsEqual("square"))
71     {
72       aFound = Standard_True;
73       aModifier = XCAFDimTolObjects_DimensionModif_Square;
74     }
75     else if(aModifStr.IsEqual("statistical"))
76     {
77       aFound = Standard_True;
78       aModifier = XCAFDimTolObjects_DimensionModif_StatisticalTolerance;
79     }
80     else if(aModifStr.IsEqual("continuous feature"))
81     {
82       aFound = Standard_True;
83       aModifier = XCAFDimTolObjects_DimensionModif_ContinuousFeature;
84     }
85     else if(aModifStr.IsEqual("two point size"))
86     {
87       aFound = Standard_True;
88       aModifier = XCAFDimTolObjects_DimensionModif_TwoPointSize;
89     }
90     else if(aModifStr.IsEqual("local size defined by a sphere"))
91     {
92       aFound = Standard_True;
93       aModifier = XCAFDimTolObjects_DimensionModif_LocalSizeDefinedBySphere;
94     }
95     else if(aModifStr.IsEqual("least squares association criteria"))
96     {
97       aFound = Standard_True;
98       aModifier = XCAFDimTolObjects_DimensionModif_LeastSquaresAssociationCriterion;
99     }
100     else if(aModifStr.IsEqual("maximum inscribed association criteria"))
101     {
102       aFound = Standard_True;
103       aModifier = XCAFDimTolObjects_DimensionModif_MaximumInscribedAssociation;
104     }
105     else if(aModifStr.IsEqual("minimum circumscribed association criteria"))
106     {
107       aFound = Standard_True;
108       aModifier = XCAFDimTolObjects_DimensionModif_MinimumCircumscribedAssociation;
109     }
110     else if(aModifStr.IsEqual("circumference diameter calculated size"))
111     {
112       aFound = Standard_True;
113       aModifier = XCAFDimTolObjects_DimensionModif_CircumferenceDiameter;
114     }
115     else if(aModifStr.IsEqual("area diameter calculated size"))
116     {
117       aFound = Standard_True;
118       aModifier = XCAFDimTolObjects_DimensionModif_AreaDiameter;
119     }
120     else if(aModifStr.IsEqual("volume diameter calculated size"))
121     {
122       aFound = Standard_True;
123       aModifier = XCAFDimTolObjects_DimensionModif_VolumeDiameter;
124     }
125     else if(aModifStr.IsEqual("maximum rank order size"))
126     {
127       aFound = Standard_True;
128       aModifier = XCAFDimTolObjects_DimensionModif_MaximumSize;
129     }
130     else if(aModifStr.IsEqual("minimum rank order size"))
131     {
132       aFound = Standard_True;
133       aModifier = XCAFDimTolObjects_DimensionModif_MinimumSize;
134     }
135     else if(aModifStr.IsEqual("average rank order size"))
136     {
137       aFound = Standard_True;
138       aModifier = XCAFDimTolObjects_DimensionModif_AverageSize;
139     }
140     else if(aModifStr.IsEqual("median rank order size"))
141     {
142       aFound = Standard_True;
143       aModifier = XCAFDimTolObjects_DimensionModif_MedianSize;
144     }
145     else if(aModifStr.IsEqual("mid range rank order size"))
146     {
147       aFound = Standard_True;
148       aModifier = XCAFDimTolObjects_DimensionModif_MidRangeSize;
149     }
150     else if(aModifStr.IsEqual("range rank order size"))
151     {
152       aFound = Standard_True;
153       aModifier = XCAFDimTolObjects_DimensionModif_RangeOfSizes;
154     }
155     else if(aModifStr.IsEqual("any part of the feature"))
156     {
157       aFound = Standard_True;
158       aModifier = XCAFDimTolObjects_DimensionModif_AnyRestrictedPortionOfFeature;
159     }
160     else if(aModifStr.IsEqual("any cross section"))
161     {
162       aFound = Standard_True;
163       aModifier = XCAFDimTolObjects_DimensionModif_AnyCrossSection;
164     }
165     else if(aModifStr.IsEqual("specific fixed cross section"))
166     {
167       aFound = Standard_True;
168       aModifier = XCAFDimTolObjects_DimensionModif_SpecificFixedCrossSection;
169     }           
170     else if(aModifStr.IsEqual("common tolerance"))
171     {
172       aFound = Standard_True;
173       aModifier = XCAFDimTolObjects_DimensionModif_CommonTolerance;
174     }             
175     else if(aModifStr.IsEqual("free state condition"))
176     {
177       aFound = Standard_True;
178       aModifier = XCAFDimTolObjects_DimensionModif_FreeStateCondition;
179     }
180     if (aFound)
181       theModifiers.Append(aModifier);
182   }
183 }
184
185 //=======================================================================
186 //function : getClassOfTolerance
187 //purpose  : 
188 //=======================================================================
189 void STEPCAFControl_GDTProperty::GetDimClassOfTolerance(const Handle(StepShape_LimitsAndFits)& theLAF,
190                                    Standard_Boolean& theHolle,
191                                    XCAFDimTolObjects_DimensionFormVariance& theFV,
192                                    XCAFDimTolObjects_DimensionGrade& theG)
193 {
194   Handle(TCollection_HAsciiString) aFormV = theLAF->FormVariance();
195   Handle(TCollection_HAsciiString) aGrade = theLAF->Grade();
196   theFV = XCAFDimTolObjects_DimensionFormVariance_None;
197   Standard_Boolean aFound;
198   theHolle = Standard_False;
199   //it is not verified information
200   for(Standard_Integer c = 0; c <= 1; c++)
201   {
202     aFound = Standard_False;
203     Standard_Boolean aCaseSens = Standard_False;
204     if (c == 1)
205       aCaseSens = Standard_True;
206     Handle(TCollection_HAsciiString) aStr = new TCollection_HAsciiString("a");
207     if(aFormV->IsSameString(aStr, aCaseSens))
208     {
209       aFound = Standard_True;
210       theFV = XCAFDimTolObjects_DimensionFormVariance_A;
211       continue;
212     }
213     aStr = new TCollection_HAsciiString("b");
214     if(aFormV->IsSameString(aStr, aCaseSens))
215     {
216       aFound = Standard_True;
217       theFV = XCAFDimTolObjects_DimensionFormVariance_B;
218       continue;
219     }
220     aStr = new TCollection_HAsciiString("c");
221     if(aFormV->IsSameString(aStr, aCaseSens))
222     {
223       aFound = Standard_True;
224       theFV = XCAFDimTolObjects_DimensionFormVariance_C;
225       continue;
226     }
227     aStr = new TCollection_HAsciiString("cd");
228     if(aFormV->IsSameString(aStr, aCaseSens))
229     {
230       aFound = Standard_True;
231       theFV = XCAFDimTolObjects_DimensionFormVariance_CD;
232       continue;
233     }
234     aStr = new TCollection_HAsciiString("d");
235     if(aFormV->IsSameString(aStr, aCaseSens))
236     {
237       aFound = Standard_True;
238       theFV = XCAFDimTolObjects_DimensionFormVariance_D;
239       continue;
240     }
241     aStr = new TCollection_HAsciiString("e");
242     if(aFormV->IsSameString(aStr, aCaseSens))
243     {
244       aFound = Standard_True;
245       theFV = XCAFDimTolObjects_DimensionFormVariance_E;
246       continue;
247     }
248     aStr = new TCollection_HAsciiString("ef");
249     if(aFormV->IsSameString(aStr, aCaseSens))
250     {
251       aFound = Standard_True;
252       theFV = XCAFDimTolObjects_DimensionFormVariance_EF;
253       continue;
254     }
255     aStr = new TCollection_HAsciiString("f");
256     if(aFormV->IsSameString(aStr, aCaseSens))
257     {
258       aFound = Standard_True;
259       theFV = XCAFDimTolObjects_DimensionFormVariance_F;
260       continue;
261     }
262     aStr = new TCollection_HAsciiString("fg");
263     if(aFormV->IsSameString(aStr, aCaseSens))
264     {
265       aFound = Standard_True;
266       theFV = XCAFDimTolObjects_DimensionFormVariance_FG;
267       continue;
268     }
269     aStr = new TCollection_HAsciiString("g");
270     if(aFormV->IsSameString(aStr, aCaseSens))
271     {
272       aFound = Standard_True;
273       theFV = XCAFDimTolObjects_DimensionFormVariance_G;
274       continue;
275     }
276     aStr = new TCollection_HAsciiString("h");
277     if(aFormV->IsSameString(aStr, aCaseSens))
278     {
279       aFound = Standard_True;
280       theFV = XCAFDimTolObjects_DimensionFormVariance_H;
281       continue;
282     }
283     aStr = new TCollection_HAsciiString("js");
284     if(aFormV->IsSameString(aStr, aCaseSens))
285     {
286       aFound = Standard_True;
287       theFV = XCAFDimTolObjects_DimensionFormVariance_JS;
288       continue;
289     }
290     aStr = new TCollection_HAsciiString("k");
291     if(aFormV->IsSameString(aStr, aCaseSens))
292     {
293       aFound = Standard_True;
294       theFV = XCAFDimTolObjects_DimensionFormVariance_K;
295       continue;
296     }
297     aStr = new TCollection_HAsciiString("m");
298     if(aFormV->IsSameString(aStr, aCaseSens))
299     {
300       aFound = Standard_True;
301       theFV = XCAFDimTolObjects_DimensionFormVariance_M;
302       continue;
303     }
304     aStr = new TCollection_HAsciiString("n");
305     if(aFormV->IsSameString(aStr, aCaseSens))
306     {
307       aFound = Standard_True;
308       theFV = XCAFDimTolObjects_DimensionFormVariance_N;
309       continue;
310     }
311     aStr = new TCollection_HAsciiString("p");
312     if(aFormV->IsSameString(aStr, aCaseSens))
313     {
314       aFound = Standard_True;
315       theFV = XCAFDimTolObjects_DimensionFormVariance_P;
316       continue;
317     }
318     aStr = new TCollection_HAsciiString("r");
319     if(aFormV->IsSameString(aStr, aCaseSens))
320     {
321       aFound = Standard_True;
322       theFV = XCAFDimTolObjects_DimensionFormVariance_R;
323       continue;
324     }
325     aStr = new TCollection_HAsciiString("s");
326     if(aFormV->IsSameString(aStr, aCaseSens))
327     {
328       aFound = Standard_True;
329       theFV = XCAFDimTolObjects_DimensionFormVariance_S;
330       continue;
331     }
332     aStr = new TCollection_HAsciiString("t");
333     if(aFormV->IsSameString(aStr, aCaseSens))
334     {
335       aFound = Standard_True;
336       theFV = XCAFDimTolObjects_DimensionFormVariance_T;
337       continue;
338     }
339     aStr = new TCollection_HAsciiString("u");
340     if(aFormV->IsSameString(aStr, aCaseSens))
341     {
342       aFound = Standard_True;
343       theFV = XCAFDimTolObjects_DimensionFormVariance_U;
344       continue;
345     }
346     aStr = new TCollection_HAsciiString("v");
347     if(aFormV->IsSameString(aStr, aCaseSens))
348     {
349       aFound = Standard_True;
350       theFV = XCAFDimTolObjects_DimensionFormVariance_V;
351       continue;
352     }
353     aStr = new TCollection_HAsciiString("x");
354     if(aFormV->IsSameString(aStr, aCaseSens))
355     {
356       aFound = Standard_True;
357       theFV = XCAFDimTolObjects_DimensionFormVariance_X;
358       continue;
359     }
360     aStr = new TCollection_HAsciiString("y");
361     if(aFormV->IsSameString(aStr, aCaseSens))
362     {
363       aFound = Standard_True;
364       theFV = XCAFDimTolObjects_DimensionFormVariance_Y;
365       continue;
366     }
367     aStr = new TCollection_HAsciiString("b");
368     if(aFormV->IsSameString(aStr, aCaseSens))
369     {
370       aFound = Standard_True;
371       theFV = XCAFDimTolObjects_DimensionFormVariance_B;
372       continue;
373     }
374     aStr = new TCollection_HAsciiString("z");
375     if(aFormV->IsSameString(aStr, aCaseSens))
376     {
377       aFound = Standard_True;
378       theFV = XCAFDimTolObjects_DimensionFormVariance_Z;
379       continue;
380     }
381     aStr = new TCollection_HAsciiString("za");
382     if(aFormV->IsSameString(aStr, aCaseSens))
383     {
384       aFound = Standard_True;
385       theFV = XCAFDimTolObjects_DimensionFormVariance_ZA;
386       continue;
387     }
388     aStr = new TCollection_HAsciiString("zb");
389     if(aFormV->IsSameString(aStr, aCaseSens))
390     {
391       aFound = Standard_True;
392       theFV = XCAFDimTolObjects_DimensionFormVariance_ZB;
393       continue;
394     }
395     aStr = new TCollection_HAsciiString("zc");
396     if(aFormV->IsSameString(aStr, aCaseSens))
397     {
398       aFound = Standard_True;
399       theFV = XCAFDimTolObjects_DimensionFormVariance_ZC;
400       continue;
401     }
402
403     if (c == 1 && !aFound)
404       theHolle = Standard_True;
405   }
406   Handle(TCollection_HAsciiString) aStr = new TCollection_HAsciiString("01");
407   if(aGrade->IsSameString(aStr))
408   {
409     theG = XCAFDimTolObjects_DimensionGrade_IT01;
410   }
411   else
412   {
413     theG = (XCAFDimTolObjects_DimensionGrade)(aGrade->IntegerValue()+1);
414   }
415 }
416
417 //=======================================================================
418 //function : getDimType
419 //purpose  : 
420 //=======================================================================
421 Standard_Boolean STEPCAFControl_GDTProperty::GetDimType(const Handle(TCollection_HAsciiString)& theName,
422                        XCAFDimTolObjects_DimensionType& theType)
423 {
424     TCollection_AsciiString aName = theName->String();
425     aName.LowerCase();
426     theType = XCAFDimTolObjects_DimensionType_Location_None;
427     if(aName.IsEqual("curve length"))
428     {
429       theType = XCAFDimTolObjects_DimensionType_Size_CurveLength;
430     }
431     else if(aName.IsEqual("diameter"))
432     {
433       theType = XCAFDimTolObjects_DimensionType_Size_Diameter;
434     }
435     else if(aName.IsEqual("spherical diameter"))
436     {
437       theType = XCAFDimTolObjects_DimensionType_Size_SphericalDiameter;
438     }
439     else if(aName.IsEqual("radius"))
440     {
441       theType = XCAFDimTolObjects_DimensionType_Size_Radius;
442     }
443     else if(aName.IsEqual("spherical radius"))
444     {
445       theType = XCAFDimTolObjects_DimensionType_Size_SphericalRadius;
446     }
447     else if(aName.IsEqual("toroidal minor diameter"))
448     {
449       theType = XCAFDimTolObjects_DimensionType_Size_ToroidalMinorDiameter;
450     }
451     else if(aName.IsEqual("toroidal major diameter"))
452     {
453       theType = XCAFDimTolObjects_DimensionType_Size_ToroidalMajorDiameter;
454     }
455     else if(aName.IsEqual("toroidal minor radius"))
456     {
457       theType = XCAFDimTolObjects_DimensionType_Size_ToroidalMinorRadius;
458     }
459     else if(aName.IsEqual("toroidal major radius"))
460     {
461       theType = XCAFDimTolObjects_DimensionType_Size_ToroidalMajorRadius;
462     }
463     else if(aName.IsEqual("toroidal high major diameter"))
464     {
465       theType = XCAFDimTolObjects_DimensionType_Size_ToroidalHighMajorDiameter;
466     }
467     else if(aName.IsEqual("toroidal low major diameter"))
468     {
469       theType = XCAFDimTolObjects_DimensionType_Size_ToroidalLowMajorDiameter;
470     }
471     else if(aName.IsEqual("toroidal high major radius"))
472     {
473       theType = XCAFDimTolObjects_DimensionType_Size_ToroidalHighMajorRadius;
474     }
475     else if(aName.IsEqual("toroidal low major radius"))
476     {
477       theType = XCAFDimTolObjects_DimensionType_Size_ToroidalLowMajorRadius;
478     }
479     else if(aName.IsEqual("thickness"))
480     {
481       theType = XCAFDimTolObjects_DimensionType_Size_Thickness;
482     }
483     else if(aName.IsEqual("curved distance"))
484     {
485       theType = XCAFDimTolObjects_DimensionType_Location_CurvedDistance;
486     }
487     else if(aName.IsEqual("linear distance"))
488     {
489       theType = XCAFDimTolObjects_DimensionType_Location_LinearDistance;
490     }
491     else if(aName.IsEqual("linear distance centre outer"))
492     {
493       theType = XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromCenterToOuter;
494     }
495     else if(aName.IsEqual("linear distance centre inner"))
496     {
497       theType = XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromCenterToInner;
498     }
499     else if(aName.IsEqual("linear distance outer centre"))
500     {
501       theType = XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromOuterToCenter;
502     }
503     else if(aName.IsEqual("linear distance outer outer"))
504     {
505       theType = XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromOuterToOuter;
506     }
507     else if(aName.IsEqual("linear distance outer inner"))
508     {
509       theType = XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromOuterToInner;
510     }
511     else if(aName.IsEqual("linear distance inner centre"))
512     {
513       theType = XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromInnerToCenter;
514     }
515     else if(aName.IsEqual("linear distance inner outer"))
516     {
517       theType = XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromInnerToOuter;
518     }
519     else if(aName.IsEqual("linear distance inner inner"))
520     {
521       theType = XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromInnerToInner;
522     }
523
524     if(theType != XCAFDimTolObjects_DimensionType_Location_None &&
525        theType != XCAFDimTolObjects_DimensionType_CommonLabel)
526     {
527       return Standard_True;
528     }
529     return Standard_False;
530 }
531
532
533 //=======================================================================
534 //function : DatumTargetType
535 //purpose  : 
536 //=======================================================================
537 Standard_Boolean STEPCAFControl_GDTProperty::GetDatumTargetType(const Handle(TCollection_HAsciiString)& theDescription,
538                        XCAFDimTolObjects_DatumTargetType& theType)
539 {
540     TCollection_AsciiString aName = theDescription->String();
541     aName.LowerCase();
542     if(aName.IsEqual("area"))
543     {
544       theType = XCAFDimTolObjects_DatumTargetType_Area;
545       return Standard_True;
546     }
547     else if(aName.IsEqual("line"))
548     {
549       theType = XCAFDimTolObjects_DatumTargetType_Line;
550       return Standard_True;
551     }
552     else if(aName.IsEqual("circle"))
553     {
554       theType = XCAFDimTolObjects_DatumTargetType_Circle;
555       return Standard_True;
556     }
557     else if(aName.IsEqual("rectangle"))
558     {
559       theType = XCAFDimTolObjects_DatumTargetType_Rectangle;
560       return Standard_True;
561     }
562     else if(aName.IsEqual("point"))
563     {
564       theType = XCAFDimTolObjects_DatumTargetType_Point;
565       return Standard_True;
566     }
567     return Standard_False;
568 }
569
570 //=======================================================================
571 //function : GetDimQualifierType
572 //purpose  : 
573 //=======================================================================
574 Standard_Boolean STEPCAFControl_GDTProperty::GetDimQualifierType(const Handle(TCollection_HAsciiString)& theDescription,
575                        XCAFDimTolObjects_DimensionQualifier& theType)
576 {
577     TCollection_AsciiString aName = theDescription->String();
578     aName.LowerCase();
579     theType = XCAFDimTolObjects_DimensionQualifier_None;
580     if(aName.IsEqual("maximum"))
581     {
582       theType = XCAFDimTolObjects_DimensionQualifier_Max;
583     }
584     else if(aName.IsEqual("minimum"))
585     {
586       theType = XCAFDimTolObjects_DimensionQualifier_Min;
587     }
588     else if(aName.IsEqual("average"))
589     {
590       theType = XCAFDimTolObjects_DimensionQualifier_Avg;
591     }
592     if(theType != XCAFDimTolObjects_DimensionQualifier_None)
593     {
594       return Standard_True;
595     }
596     return Standard_False;
597 }
598
599 //=======================================================================
600 //function : GetTolValueType
601 //purpose  : 
602 //=======================================================================
603 Standard_Boolean STEPCAFControl_GDTProperty::GetTolValueType(const Handle(TCollection_HAsciiString)& theDescription,
604                        XCAFDimTolObjects_GeomToleranceTypeValue& theType)
605 {
606     TCollection_AsciiString aName = theDescription->String();
607     aName.LowerCase();
608     theType = XCAFDimTolObjects_GeomToleranceTypeValue_None;
609     if(aName.IsEqual("cylindrical or circular"))
610     {
611       theType = XCAFDimTolObjects_GeomToleranceTypeValue_Diameter;
612     }
613     else if(aName.IsEqual("spherical"))
614     {
615       theType = XCAFDimTolObjects_GeomToleranceTypeValue_SphericalDiameter;
616     }
617     if(theType != XCAFDimTolObjects_GeomToleranceTypeValue_None)
618     {
619       return Standard_True;
620     }
621     return Standard_False;
622 }
623
624
625 //=======================================================================
626 //function : GetDimTypeName
627 //purpose  : 
628 //=======================================================================
629 Handle(TCollection_HAsciiString) STEPCAFControl_GDTProperty::GetDimTypeName(const XCAFDimTolObjects_DimensionType theType)
630 {
631   Handle(TCollection_HAsciiString) aName;
632         switch (theType) {
633         // Dimensional_Location
634         case XCAFDimTolObjects_DimensionType_Location_CurvedDistance:
635           aName = new TCollection_HAsciiString("curved distance");
636           break;
637         case XCAFDimTolObjects_DimensionType_Location_LinearDistance:
638           aName = new TCollection_HAsciiString("linear distance");
639           break;
640         case XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromCenterToOuter:
641           aName = new TCollection_HAsciiString("linear distance centre outer");
642           break;
643         case XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromCenterToInner:
644           aName = new TCollection_HAsciiString("linear distance centre inner");
645           break;
646         case XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromOuterToCenter:
647           aName = new TCollection_HAsciiString("linear distance outer centre");
648           break;
649         case XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromOuterToOuter:
650           aName = new TCollection_HAsciiString("linear distance outer outer");
651           break;
652         case XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromOuterToInner:
653           aName = new TCollection_HAsciiString("linear distance outer inner");
654           break;
655         case XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromInnerToCenter:
656           aName = new TCollection_HAsciiString("linear distance inner centre");
657           break;
658         case XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromInnerToOuter:
659           aName = new TCollection_HAsciiString("linear distance inner outer");
660           break;
661         case XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromInnerToInner:
662           aName = new TCollection_HAsciiString("linear distance inner inner");
663           break;
664         //Dimensional_Size
665         case XCAFDimTolObjects_DimensionType_Size_CurveLength:
666           aName = new TCollection_HAsciiString("curve length");
667           break;
668         case XCAFDimTolObjects_DimensionType_Size_Diameter:
669           aName = new TCollection_HAsciiString("diameter");
670           break;
671         case XCAFDimTolObjects_DimensionType_Size_SphericalDiameter:
672           aName = new TCollection_HAsciiString("spherical diameter");
673           break;
674         case XCAFDimTolObjects_DimensionType_Size_Radius:
675           aName = new TCollection_HAsciiString("radius");
676           break;
677         case XCAFDimTolObjects_DimensionType_Size_SphericalRadius:
678           aName = new TCollection_HAsciiString("spherical radius");
679           break;
680         case XCAFDimTolObjects_DimensionType_Size_ToroidalMinorDiameter:
681           aName = new TCollection_HAsciiString("toroidal minor diameter");
682           break;
683         case XCAFDimTolObjects_DimensionType_Size_ToroidalMajorDiameter:
684           aName = new TCollection_HAsciiString("toroidal major diameter");
685           break;
686         case XCAFDimTolObjects_DimensionType_Size_ToroidalMinorRadius:
687           aName = new TCollection_HAsciiString("toroidal minor radius");
688           break;
689         case XCAFDimTolObjects_DimensionType_Size_ToroidalMajorRadius:
690           aName = new TCollection_HAsciiString("toroidal major radius");
691           break;
692         case XCAFDimTolObjects_DimensionType_Size_ToroidalHighMajorDiameter:
693           aName = new TCollection_HAsciiString("toroidal high major diameter");
694           break;
695         case XCAFDimTolObjects_DimensionType_Size_ToroidalLowMajorDiameter:
696           aName = new TCollection_HAsciiString("toroidal low major diameter");
697           break;
698         case XCAFDimTolObjects_DimensionType_Size_ToroidalHighMajorRadius:
699           aName = new TCollection_HAsciiString("toroidal high major radius");
700           break;
701         case XCAFDimTolObjects_DimensionType_Size_ToroidalLowMajorRadius:
702           aName = new TCollection_HAsciiString("toroidal low major radius");
703           break;
704         case XCAFDimTolObjects_DimensionType_Size_Thickness:
705           aName = new TCollection_HAsciiString("thickness");
706           break;
707         // Other entities
708         default:
709           aName = new TCollection_HAsciiString();
710       }
711   return aName;
712 }
713
714 //=======================================================================
715 //function : GetDimQualifierName
716 //purpose  : 
717 //=======================================================================
718 Handle(TCollection_HAsciiString) STEPCAFControl_GDTProperty::GetDimQualifierName(const XCAFDimTolObjects_DimensionQualifier theQualifier)
719 {
720   Handle(TCollection_HAsciiString) aName;
721   switch (theQualifier) {
722     case XCAFDimTolObjects_DimensionQualifier_Min:
723       aName = new TCollection_HAsciiString("minimum");
724       break;
725     case XCAFDimTolObjects_DimensionQualifier_Avg:
726       aName = new TCollection_HAsciiString("average");
727       break;
728     case XCAFDimTolObjects_DimensionQualifier_Max:
729       aName = new TCollection_HAsciiString("maximum");
730       break;
731     default:
732       aName = new TCollection_HAsciiString();
733   }
734   return aName;
735 }
736
737 //=======================================================================
738 //function : GetDimModifierName
739 //purpose  : 
740 //=======================================================================
741 Handle(TCollection_HAsciiString) STEPCAFControl_GDTProperty::GetDimModifierName(const XCAFDimTolObjects_DimensionModif theModifier)
742 {
743   Handle(TCollection_HAsciiString) aName;
744   switch (theModifier) {
745     case XCAFDimTolObjects_DimensionModif_ControlledRadius:
746       aName = new TCollection_HAsciiString("controlled radius");
747       break;
748     case XCAFDimTolObjects_DimensionModif_Square:
749       aName = new TCollection_HAsciiString("square");
750       break;
751     case XCAFDimTolObjects_DimensionModif_StatisticalTolerance:
752       aName = new TCollection_HAsciiString("statistical");
753       break;
754     case XCAFDimTolObjects_DimensionModif_ContinuousFeature:
755       aName = new TCollection_HAsciiString("continuous feature");
756       break;
757     case XCAFDimTolObjects_DimensionModif_TwoPointSize:
758       aName = new TCollection_HAsciiString("two point size");
759       break;
760     case XCAFDimTolObjects_DimensionModif_LocalSizeDefinedBySphere:
761       aName = new TCollection_HAsciiString("local size defined by a sphere");
762       break;
763     case XCAFDimTolObjects_DimensionModif_LeastSquaresAssociationCriterion:
764       aName = new TCollection_HAsciiString("least squares association criteria");
765       break;
766     case XCAFDimTolObjects_DimensionModif_MaximumInscribedAssociation:
767       aName = new TCollection_HAsciiString("maximum inscribed association criteria");
768       break;
769     case XCAFDimTolObjects_DimensionModif_MinimumCircumscribedAssociation:
770       aName = new TCollection_HAsciiString("minimum circumscribed association criteria");
771       break;
772     case XCAFDimTolObjects_DimensionModif_CircumferenceDiameter:
773       aName = new TCollection_HAsciiString("circumference diameter calculated size");
774       break;
775     case XCAFDimTolObjects_DimensionModif_AreaDiameter:
776       aName = new TCollection_HAsciiString("area diameter calculated size");
777       break;
778     case XCAFDimTolObjects_DimensionModif_VolumeDiameter:
779       aName = new TCollection_HAsciiString("volume diameter calculated size");
780       break;
781     case XCAFDimTolObjects_DimensionModif_MaximumSize:
782       aName = new TCollection_HAsciiString("maximum rank order size");
783       break;
784     case XCAFDimTolObjects_DimensionModif_MinimumSize:
785       aName = new TCollection_HAsciiString("minimum rank order size");
786       break;
787     case XCAFDimTolObjects_DimensionModif_AverageSize:
788       aName = new TCollection_HAsciiString("average rank order size");
789       break;
790     case XCAFDimTolObjects_DimensionModif_MedianSize:
791       aName = new TCollection_HAsciiString("median rank order size");
792       break;
793     case XCAFDimTolObjects_DimensionModif_MidRangeSize:
794       aName = new TCollection_HAsciiString("mid range rank order size");
795       break;
796     case XCAFDimTolObjects_DimensionModif_RangeOfSizes:
797       aName = new TCollection_HAsciiString("range rank order size");
798       break;
799     case XCAFDimTolObjects_DimensionModif_AnyRestrictedPortionOfFeature:
800       aName = new TCollection_HAsciiString("any part of the feature");
801       break;
802     case XCAFDimTolObjects_DimensionModif_AnyCrossSection:
803       aName = new TCollection_HAsciiString("any cross section");
804       break;
805     case XCAFDimTolObjects_DimensionModif_SpecificFixedCrossSection:
806       aName = new TCollection_HAsciiString("specific fixed cross section");
807       break;
808     case XCAFDimTolObjects_DimensionModif_CommonTolerance:
809       aName = new TCollection_HAsciiString("common tolerance");
810       break;
811     case XCAFDimTolObjects_DimensionModif_FreeStateCondition:
812       aName = new TCollection_HAsciiString("free state condition");
813       break;
814     default: aName = new TCollection_HAsciiString();
815   }
816   return aName;
817 }
818
819 //=======================================================================
820 //function : GetLimitsAndFits
821 //purpose  : 
822 //=======================================================================
823 Handle(StepShape_LimitsAndFits) STEPCAFControl_GDTProperty::GetLimitsAndFits(Standard_Boolean theHole,
824                        XCAFDimTolObjects_DimensionFormVariance theFormVariance,
825                        XCAFDimTolObjects_DimensionGrade theGrade)
826 {
827   Handle(StepShape_LimitsAndFits) aLAF = new StepShape_LimitsAndFits();
828   Handle(TCollection_HAsciiString) aGradeStr, aFormStr, aHoleStr;
829   
830   if (theGrade == XCAFDimTolObjects_DimensionGrade_IT01)
831       aGradeStr = new TCollection_HAsciiString("01");
832     else
833       aGradeStr = new TCollection_HAsciiString((Standard_Integer)theGrade + 1);
834   
835   switch (theFormVariance) {
836     case XCAFDimTolObjects_DimensionFormVariance_None:
837       aFormStr = new TCollection_HAsciiString("");
838       break;
839     case XCAFDimTolObjects_DimensionFormVariance_A:
840       aFormStr = new TCollection_HAsciiString("A");
841       break;
842     case XCAFDimTolObjects_DimensionFormVariance_B:
843       aFormStr = new TCollection_HAsciiString("B");
844       break;
845     case XCAFDimTolObjects_DimensionFormVariance_C:
846       aFormStr = new TCollection_HAsciiString("C");
847       break;
848     case XCAFDimTolObjects_DimensionFormVariance_CD:
849       aFormStr = new TCollection_HAsciiString("CD");
850       break;
851     case XCAFDimTolObjects_DimensionFormVariance_D:
852       aFormStr = new TCollection_HAsciiString("D");
853       break;
854     case XCAFDimTolObjects_DimensionFormVariance_E:
855       aFormStr = new TCollection_HAsciiString("E");
856       break;
857     case XCAFDimTolObjects_DimensionFormVariance_EF:
858       aFormStr = new TCollection_HAsciiString("EF");
859       break;
860     case XCAFDimTolObjects_DimensionFormVariance_F:
861       aFormStr = new TCollection_HAsciiString("F");
862       break;
863     case XCAFDimTolObjects_DimensionFormVariance_FG:
864       aFormStr = new TCollection_HAsciiString("FG");
865       break;
866     case XCAFDimTolObjects_DimensionFormVariance_G:
867       aFormStr = new TCollection_HAsciiString("G");
868       break;
869     case XCAFDimTolObjects_DimensionFormVariance_H:
870       aFormStr = new TCollection_HAsciiString("H");
871       break;
872     case XCAFDimTolObjects_DimensionFormVariance_JS:
873       aFormStr = new TCollection_HAsciiString("JS");
874       break;
875     case XCAFDimTolObjects_DimensionFormVariance_J:
876       aFormStr = new TCollection_HAsciiString("J");
877       break;
878     case XCAFDimTolObjects_DimensionFormVariance_K:
879       aFormStr = new TCollection_HAsciiString("K");
880       break;
881     case XCAFDimTolObjects_DimensionFormVariance_M:
882       aFormStr = new TCollection_HAsciiString("M");
883       break;
884     case XCAFDimTolObjects_DimensionFormVariance_N:
885       aFormStr = new TCollection_HAsciiString("N");
886       break;
887     case XCAFDimTolObjects_DimensionFormVariance_P:
888       aFormStr = new TCollection_HAsciiString("P");
889       break;
890     case XCAFDimTolObjects_DimensionFormVariance_R:
891       aFormStr = new TCollection_HAsciiString("R");
892       break;
893     case XCAFDimTolObjects_DimensionFormVariance_S:
894       aFormStr = new TCollection_HAsciiString("S");
895       break;
896     case XCAFDimTolObjects_DimensionFormVariance_T:
897       aFormStr = new TCollection_HAsciiString("T");
898       break;
899     case XCAFDimTolObjects_DimensionFormVariance_U:
900       aFormStr = new TCollection_HAsciiString("U");
901       break;
902     case XCAFDimTolObjects_DimensionFormVariance_V:
903       aFormStr = new TCollection_HAsciiString("V");
904       break;
905     case XCAFDimTolObjects_DimensionFormVariance_X:
906       aFormStr = new TCollection_HAsciiString("X");
907       break;
908     case XCAFDimTolObjects_DimensionFormVariance_Y:
909       aFormStr = new TCollection_HAsciiString("Y");
910       break;
911     case XCAFDimTolObjects_DimensionFormVariance_Z:
912       aFormStr = new TCollection_HAsciiString("Z");
913       break;
914     case XCAFDimTolObjects_DimensionFormVariance_ZA:
915       aFormStr = new TCollection_HAsciiString("ZA");
916       break;
917     case XCAFDimTolObjects_DimensionFormVariance_ZB:
918       aFormStr = new TCollection_HAsciiString("ZB");
919       break;
920     case XCAFDimTolObjects_DimensionFormVariance_ZC:
921       aFormStr = new TCollection_HAsciiString("ZC");
922       break;
923   }
924
925   if (theHole) {
926     aHoleStr = new TCollection_HAsciiString("hole");
927   }
928   else {
929     aHoleStr = new TCollection_HAsciiString("shaft");
930     aFormStr->LowerCase();
931   }
932   aLAF->Init(aFormStr, aHoleStr, aGradeStr, new TCollection_HAsciiString);
933   return aLAF;
934 }
935
936 //=======================================================================
937 //function : GetDatumTargetName
938 //purpose  : 
939 //=======================================================================
940 Handle(TCollection_HAsciiString) STEPCAFControl_GDTProperty::GetDatumTargetName(const XCAFDimTolObjects_DatumTargetType theDatumType)
941 {
942   Handle(TCollection_HAsciiString) aName;
943   switch (theDatumType) {
944     case XCAFDimTolObjects_DatumTargetType_Point:
945       aName = new TCollection_HAsciiString("point");
946       break;
947     case XCAFDimTolObjects_DatumTargetType_Line:
948       aName = new TCollection_HAsciiString("line");
949       break;
950     case XCAFDimTolObjects_DatumTargetType_Rectangle:
951       aName = new TCollection_HAsciiString("rectangle");
952       break;
953     case XCAFDimTolObjects_DatumTargetType_Circle:
954       aName = new TCollection_HAsciiString("circle");
955       break;
956     case XCAFDimTolObjects_DatumTargetType_Area:
957       aName = new TCollection_HAsciiString("area");
958       break;
959     default: aName = new TCollection_HAsciiString();
960   }
961   return aName;
962 }
963
964 //=======================================================================
965 //function : IsDimensionalSize
966 //purpose  : 
967 //=======================================================================
968 Standard_Boolean STEPCAFControl_GDTProperty::IsDimensionalLocation(const XCAFDimTolObjects_DimensionType theType)
969 {
970   if (theType == XCAFDimTolObjects_DimensionType_Location_None ||
971       theType == XCAFDimTolObjects_DimensionType_Location_CurvedDistance  ||
972       theType == XCAFDimTolObjects_DimensionType_Location_LinearDistance ||
973       theType == XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromCenterToOuter ||
974       theType == XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromCenterToInner ||
975       theType == XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromOuterToCenter ||
976       theType == XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromOuterToOuter ||
977       theType == XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromOuterToInner ||
978       theType == XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromInnerToCenter ||
979       theType == XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromInnerToOuter ||
980       theType == XCAFDimTolObjects_DimensionType_Location_LinearDistance_FromInnerToInner ||
981       theType == XCAFDimTolObjects_DimensionType_Location_Oriented)
982     return Standard_True;
983   return Standard_False;
984 }
985
986 //=======================================================================
987 //function : IsDimensionalSize
988 //purpose  : 
989 //=======================================================================
990 Standard_Boolean STEPCAFControl_GDTProperty::IsDimensionalSize(const XCAFDimTolObjects_DimensionType theType)
991 {
992   if (theType == XCAFDimTolObjects_DimensionType_Size_CurveLength ||
993       theType == XCAFDimTolObjects_DimensionType_Size_Diameter ||
994       theType == XCAFDimTolObjects_DimensionType_Size_SphericalDiameter ||
995       theType == XCAFDimTolObjects_DimensionType_Size_Radius ||
996       theType == XCAFDimTolObjects_DimensionType_Size_SphericalRadius ||
997       theType == XCAFDimTolObjects_DimensionType_Size_ToroidalMinorDiameter ||
998       theType == XCAFDimTolObjects_DimensionType_Size_ToroidalMajorDiameter ||
999       theType == XCAFDimTolObjects_DimensionType_Size_ToroidalMinorRadius ||
1000       theType == XCAFDimTolObjects_DimensionType_Size_ToroidalMajorRadius ||
1001       theType == XCAFDimTolObjects_DimensionType_Size_ToroidalHighMajorDiameter ||
1002       theType == XCAFDimTolObjects_DimensionType_Size_ToroidalLowMajorDiameter ||
1003       theType == XCAFDimTolObjects_DimensionType_Size_ToroidalHighMajorRadius ||
1004       theType == XCAFDimTolObjects_DimensionType_Size_ToroidalLowMajorRadius ||
1005       theType == XCAFDimTolObjects_DimensionType_Size_Thickness)
1006     return Standard_True;
1007   return Standard_False;
1008 }
1009
1010 //=======================================================================
1011 //function : GetGeomToleranceType
1012 //purpose  : 
1013 //=======================================================================
1014 StepDimTol_GeometricToleranceType STEPCAFControl_GDTProperty::GetGeomToleranceType(const XCAFDimTolObjects_GeomToleranceType theType)
1015 {
1016   switch (theType) {
1017     case XCAFDimTolObjects_GeomToleranceType_Angularity:
1018       return StepDimTol_GTTAngularityTolerance;
1019     case XCAFDimTolObjects_GeomToleranceType_CircularRunout:
1020       return StepDimTol_GTTCircularRunoutTolerance;
1021     case XCAFDimTolObjects_GeomToleranceType_CircularityOrRoundness:
1022       return StepDimTol_GTTRoundnessTolerance;
1023     case XCAFDimTolObjects_GeomToleranceType_Coaxiality:
1024       return StepDimTol_GTTCoaxialityTolerance;
1025     case XCAFDimTolObjects_GeomToleranceType_Concentricity:
1026       return StepDimTol_GTTConcentricityTolerance;
1027     case XCAFDimTolObjects_GeomToleranceType_Cylindricity:
1028       return StepDimTol_GTTCylindricityTolerance;
1029     case XCAFDimTolObjects_GeomToleranceType_Flatness:
1030       return StepDimTol_GTTFlatnessTolerance;
1031     case XCAFDimTolObjects_GeomToleranceType_Parallelism:
1032       return StepDimTol_GTTParallelismTolerance;
1033     case XCAFDimTolObjects_GeomToleranceType_Perpendicularity:
1034       return StepDimTol_GTTPerpendicularityTolerance;
1035     case XCAFDimTolObjects_GeomToleranceType_Position:
1036       return StepDimTol_GTTPositionTolerance;
1037     case XCAFDimTolObjects_GeomToleranceType_ProfileOfLine:
1038       return StepDimTol_GTTLineProfileTolerance;
1039     case XCAFDimTolObjects_GeomToleranceType_ProfileOfSurface:
1040       return StepDimTol_GTTSurfaceProfileTolerance;
1041     case XCAFDimTolObjects_GeomToleranceType_Straightness:
1042       return StepDimTol_GTTStraightnessTolerance;
1043     case XCAFDimTolObjects_GeomToleranceType_Symmetry:
1044       return StepDimTol_GTTSymmetryTolerance;
1045     case XCAFDimTolObjects_GeomToleranceType_TotalRunout:
1046       return StepDimTol_GTTTotalRunoutTolerance;
1047     default:
1048       return StepDimTol_GTTPositionTolerance;
1049   }
1050 }
1051
1052 //=======================================================================
1053 //function : GetGeomToleranceType
1054 //purpose  : 
1055 //=======================================================================
1056 XCAFDimTolObjects_GeomToleranceType STEPCAFControl_GDTProperty::GetGeomToleranceType(const StepDimTol_GeometricToleranceType theType)
1057 {
1058   switch (theType) {
1059     case StepDimTol_GTTAngularityTolerance:
1060       return XCAFDimTolObjects_GeomToleranceType_Angularity;
1061     case StepDimTol_GTTCircularRunoutTolerance:
1062       return XCAFDimTolObjects_GeomToleranceType_CircularRunout;
1063     case StepDimTol_GTTRoundnessTolerance:
1064       return XCAFDimTolObjects_GeomToleranceType_CircularityOrRoundness;
1065     case StepDimTol_GTTCoaxialityTolerance:
1066       return XCAFDimTolObjects_GeomToleranceType_Coaxiality;
1067     case StepDimTol_GTTConcentricityTolerance:
1068       return XCAFDimTolObjects_GeomToleranceType_Concentricity;
1069     case StepDimTol_GTTCylindricityTolerance:
1070       return XCAFDimTolObjects_GeomToleranceType_Cylindricity;
1071     case StepDimTol_GTTFlatnessTolerance:
1072       return XCAFDimTolObjects_GeomToleranceType_Flatness;
1073     case StepDimTol_GTTParallelismTolerance:
1074       return XCAFDimTolObjects_GeomToleranceType_Parallelism;
1075     case StepDimTol_GTTPerpendicularityTolerance:
1076       return XCAFDimTolObjects_GeomToleranceType_Perpendicularity;
1077     case StepDimTol_GTTPositionTolerance:
1078       return XCAFDimTolObjects_GeomToleranceType_Position;
1079     case StepDimTol_GTTLineProfileTolerance:
1080       return XCAFDimTolObjects_GeomToleranceType_ProfileOfLine;
1081     case StepDimTol_GTTSurfaceProfileTolerance:
1082       return XCAFDimTolObjects_GeomToleranceType_ProfileOfSurface;
1083     case StepDimTol_GTTStraightnessTolerance:
1084       return XCAFDimTolObjects_GeomToleranceType_Straightness;
1085     case StepDimTol_GTTSymmetryTolerance:
1086       return XCAFDimTolObjects_GeomToleranceType_Symmetry;
1087     case StepDimTol_GTTTotalRunoutTolerance:
1088       return XCAFDimTolObjects_GeomToleranceType_TotalRunout;
1089     default:
1090       return XCAFDimTolObjects_GeomToleranceType_Position;
1091   }
1092 }
1093
1094 //=======================================================================
1095 //function : GetGeomTolerance
1096 //purpose  : 
1097 //=======================================================================
1098 Handle(StepDimTol_GeometricTolerance) STEPCAFControl_GDTProperty::
1099   GetGeomTolerance(const XCAFDimTolObjects_GeomToleranceType theType)
1100 {
1101   switch (theType) {
1102     case XCAFDimTolObjects_GeomToleranceType_CircularityOrRoundness:
1103       return new StepDimTol_RoundnessTolerance();
1104     case XCAFDimTolObjects_GeomToleranceType_Cylindricity:
1105       return new StepDimTol_CylindricityTolerance();
1106     case XCAFDimTolObjects_GeomToleranceType_Flatness:
1107       return new StepDimTol_FlatnessTolerance();
1108     case XCAFDimTolObjects_GeomToleranceType_Position:
1109       return new StepDimTol_PositionTolerance();
1110     case XCAFDimTolObjects_GeomToleranceType_ProfileOfLine:
1111       return new StepDimTol_LineProfileTolerance();
1112     case XCAFDimTolObjects_GeomToleranceType_ProfileOfSurface:
1113       return new StepDimTol_SurfaceProfileTolerance();
1114     case XCAFDimTolObjects_GeomToleranceType_Straightness:
1115       return new StepDimTol_StraightnessTolerance();
1116     default:
1117       return NULL;
1118   }
1119 }
1120
1121 //=======================================================================
1122 //function : GetGeomToleranceModifier
1123 //purpose  : 
1124 //=======================================================================
1125 StepDimTol_GeometricToleranceModifier STEPCAFControl_GDTProperty::
1126   GetGeomToleranceModifier(const XCAFDimTolObjects_GeomToleranceModif theModifier)
1127 {
1128   switch (theModifier) {
1129     case XCAFDimTolObjects_GeomToleranceModif_Any_Cross_Section:
1130       return StepDimTol_GTMAnyCrossSection;
1131     case XCAFDimTolObjects_GeomToleranceModif_Common_Zone:
1132       return StepDimTol_GTMCommonZone;
1133     case XCAFDimTolObjects_GeomToleranceModif_Each_Radial_Element:
1134       return StepDimTol_GTMEachRadialElement;
1135     case XCAFDimTolObjects_GeomToleranceModif_Free_State:
1136       return StepDimTol_GTMFreeState;
1137     case XCAFDimTolObjects_GeomToleranceModif_Least_Material_Requirement:
1138       return StepDimTol_GTMLeastMaterialRequirement;
1139     case XCAFDimTolObjects_GeomToleranceModif_Line_Element:
1140       return StepDimTol_GTMLineElement;
1141     case XCAFDimTolObjects_GeomToleranceModif_Major_Diameter:
1142       return StepDimTol_GTMMajorDiameter;
1143     case XCAFDimTolObjects_GeomToleranceModif_Maximum_Material_Requirement:
1144       return StepDimTol_GTMMaximumMaterialRequirement;
1145     case XCAFDimTolObjects_GeomToleranceModif_Minor_Diameter:
1146       return StepDimTol_GTMMinorDiameter;
1147     case XCAFDimTolObjects_GeomToleranceModif_Not_Convex:
1148       return StepDimTol_GTMNotConvex;
1149     case XCAFDimTolObjects_GeomToleranceModif_Pitch_Diameter:
1150       return StepDimTol_GTMPitchDiameter;
1151     case XCAFDimTolObjects_GeomToleranceModif_Reciprocity_Requirement:
1152       return StepDimTol_GTMReciprocityRequirement;
1153     case XCAFDimTolObjects_GeomToleranceModif_Separate_Requirement:
1154       return StepDimTol_GTMSeparateRequirement;
1155     case XCAFDimTolObjects_GeomToleranceModif_Statistical_Tolerance:
1156       return StepDimTol_GTMStatisticalTolerance;
1157     case XCAFDimTolObjects_GeomToleranceModif_Tangent_Plane:
1158       return StepDimTol_GTMTangentPlane;
1159     default:
1160       return StepDimTol_GTMMaximumMaterialRequirement;
1161   }
1162 }
1163
1164 //=======================================================================
1165 //function : GetDatumRefModifiers
1166 //purpose  : Note: this function does not add anything to model
1167 //=======================================================================
1168 Handle(StepDimTol_HArray1OfDatumReferenceModifier) STEPCAFControl_GDTProperty::
1169   GetDatumRefModifiers(const XCAFDimTolObjects_DatumModifiersSequence theModifiers,
1170                        const XCAFDimTolObjects_DatumModifWithValue theModifWithVal,
1171                        const Standard_Real theValue,
1172                        const StepBasic_Unit theUnit)
1173 {
1174   if ((theModifiers.Length() == 0) && (theModifWithVal == XCAFDimTolObjects_DatumModifWithValue_None))
1175     return NULL;
1176   Standard_Integer aModifNb = theModifiers.Length();
1177   if (theModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
1178     aModifNb++;
1179   Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifiers =
1180     new StepDimTol_HArray1OfDatumReferenceModifier(1, aModifNb);
1181
1182   // Modifier with value
1183   if (theModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None) {
1184     StepDimTol_DatumReferenceModifierType aType;
1185     switch (theModifWithVal) {
1186       case XCAFDimTolObjects_DatumModifWithValue_CircularOrCylindrical:
1187         aType = StepDimTol_CircularOrCylindrical;
1188         break;
1189       case XCAFDimTolObjects_DatumModifWithValue_Distance:
1190         aType = StepDimTol_Distance;
1191         break;
1192       case XCAFDimTolObjects_DatumModifWithValue_Projected:
1193         aType = StepDimTol_Projected;
1194         break;
1195       case XCAFDimTolObjects_DatumModifWithValue_Spherical:
1196         aType = StepDimTol_Spherical;
1197         break;
1198       default:
1199         aType = StepDimTol_Distance;
1200     }
1201     Handle(StepBasic_LengthMeasureWithUnit) aLMWU = new StepBasic_LengthMeasureWithUnit();
1202     Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
1203     aValueMember->SetName("LENGTH_MEASURE");
1204     aValueMember->SetReal(theValue);
1205     aLMWU->Init(aValueMember, theUnit);
1206     Handle(StepDimTol_DatumReferenceModifierWithValue) aModifWithVal = new StepDimTol_DatumReferenceModifierWithValue();
1207     aModifWithVal->Init(aType, aLMWU);
1208     StepDimTol_DatumReferenceModifier aModif;
1209     aModif.SetValue(aModifWithVal);
1210     aModifiers->SetValue(aModifNb, aModif);
1211   }
1212
1213   // Simple modifiers
1214   for (Standard_Integer i = 1; i <= theModifiers.Length(); i++) {
1215     Handle(StepDimTol_SimpleDatumReferenceModifierMember) aSimpleModifMember = 
1216       new StepDimTol_SimpleDatumReferenceModifierMember();
1217     switch (theModifiers.Value(i)) {
1218       case XCAFDimTolObjects_DatumSingleModif_AnyCrossSection:
1219         aSimpleModifMember->SetEnumText(0, ".ANY_CROSS_SECTION.");
1220         break;
1221       case XCAFDimTolObjects_DatumSingleModif_Any_LongitudinalSection:
1222         aSimpleModifMember->SetEnumText(0, ".ANY_LONGITUDINAL_SECTION.");
1223         break;
1224       case XCAFDimTolObjects_DatumSingleModif_Basic:
1225         aSimpleModifMember->SetEnumText(0, ".BASIC.");
1226         break;
1227       case XCAFDimTolObjects_DatumSingleModif_ContactingFeature:
1228         aSimpleModifMember->SetEnumText(0, ".CONTACTING_FEATURE.");
1229         break;
1230       case XCAFDimTolObjects_DatumSingleModif_DegreeOfFreedomConstraintU:
1231         aSimpleModifMember->SetEnumText(0, ".DEGREE_OF_FREEDOM_CONSTRAINT_U.");
1232         break;
1233       case XCAFDimTolObjects_DatumSingleModif_DegreeOfFreedomConstraintV:
1234         aSimpleModifMember->SetEnumText(0, ".DEGREE_OF_FREEDOM_CONSTRAINT_V.");
1235         break;
1236       case XCAFDimTolObjects_DatumSingleModif_DegreeOfFreedomConstraintW:
1237         aSimpleModifMember->SetEnumText(0, ".DEGREE_OF_FREEDOM_CONSTRAINT_W.");
1238         break;
1239       case XCAFDimTolObjects_DatumSingleModif_DegreeOfFreedomConstraintX:
1240         aSimpleModifMember->SetEnumText(0, ".DEGREE_OF_FREEDOM_CONSTRAINT_X.");
1241         break;
1242       case XCAFDimTolObjects_DatumSingleModif_DegreeOfFreedomConstraintY:
1243         aSimpleModifMember->SetEnumText(0, ".DEGREE_OF_FREEDOM_CONSTRAINT_Y.");
1244         break;
1245       case XCAFDimTolObjects_DatumSingleModif_DegreeOfFreedomConstraintZ:
1246         aSimpleModifMember->SetEnumText(0, ".DEGREE_OF_FREEDOM_CONSTRAINT_Z.");
1247         break;
1248       case XCAFDimTolObjects_DatumSingleModif_DistanceVariable:
1249         aSimpleModifMember->SetEnumText(0, ".DISTANCE_VARIABLE.");
1250         break;
1251       case XCAFDimTolObjects_DatumSingleModif_FreeState:
1252         aSimpleModifMember->SetEnumText(0, ".FREE_STATE.");
1253         break;
1254       case XCAFDimTolObjects_DatumSingleModif_LeastMaterialRequirement:
1255         aSimpleModifMember->SetEnumText(0, ".LEAST_MATERIAL_REQUIREMENT.");
1256         break;
1257       case XCAFDimTolObjects_DatumSingleModif_Line:
1258         aSimpleModifMember->SetEnumText(0, ".LINE.");
1259         break;
1260       case XCAFDimTolObjects_DatumSingleModif_MajorDiameter:
1261         aSimpleModifMember->SetEnumText(0, ".MAJOR_DIAMETER.");
1262         break;
1263       case XCAFDimTolObjects_DatumSingleModif_MaximumMaterialRequirement:
1264         aSimpleModifMember->SetEnumText(0, ".MAXIMUM_MATERIAL_REQUIREMENT.");
1265         break;
1266       case XCAFDimTolObjects_DatumSingleModif_MinorDiameter:
1267         aSimpleModifMember->SetEnumText(0, ".MINOR_DIAMETER.");
1268         break;
1269       case XCAFDimTolObjects_DatumSingleModif_Orientation:
1270         aSimpleModifMember->SetEnumText(0, ".ORIENTATION.");
1271         break;
1272       case XCAFDimTolObjects_DatumSingleModif_PitchDiameter:
1273         aSimpleModifMember->SetEnumText(0, ".PITCH_DIAMETER.");
1274         break;
1275       case XCAFDimTolObjects_DatumSingleModif_Plane:
1276         aSimpleModifMember->SetEnumText(0, ".PLANE.");
1277         break;
1278       case XCAFDimTolObjects_DatumSingleModif_Point:
1279         aSimpleModifMember->SetEnumText(0, ".POINT.");
1280         break;
1281       case XCAFDimTolObjects_DatumSingleModif_Translation:
1282         aSimpleModifMember->SetEnumText(0, ".TRANSLATION.");
1283         break;
1284     }
1285     StepDimTol_DatumReferenceModifier aModif;
1286     aModif.SetValue(aSimpleModifMember);
1287     aModifiers->SetValue(i, aModif);
1288   }
1289
1290   return aModifiers;
1291 }
1292
1293 //=======================================================================
1294 //function : GetTolValueType
1295 //purpose  : 
1296 //=======================================================================
1297 Handle(TCollection_HAsciiString) STEPCAFControl_GDTProperty::GetTolValueType(const XCAFDimTolObjects_GeomToleranceTypeValue& theType)
1298 {
1299   switch (theType) {
1300     case XCAFDimTolObjects_GeomToleranceTypeValue_Diameter:
1301       return new TCollection_HAsciiString("cylindrical or circular");
1302     case XCAFDimTolObjects_GeomToleranceTypeValue_SphericalDiameter:
1303       return new TCollection_HAsciiString("spherical");
1304     default:
1305       return new TCollection_HAsciiString("unknown");
1306   }
1307 }
1308
1309 //=======================================================================
1310 //function : GetTessellation
1311 //purpose  : 
1312 //=======================================================================
1313 Handle(StepVisual_TessellatedGeometricSet) STEPCAFControl_GDTProperty::GetTessellation(const TopoDS_Shape theShape)
1314 {
1315   // Build coordinate list and curves
1316   NCollection_Handle<StepVisual_VectorOfHSequenceOfInteger> aCurves = new StepVisual_VectorOfHSequenceOfInteger;
1317   NCollection_Vector<gp_XYZ> aCoords;
1318   Standard_Integer aPntNb = 1;
1319   for (TopExp_Explorer aCurveIt(theShape, TopAbs_EDGE); aCurveIt.More(); aCurveIt.Next()) {
1320     Handle(TColStd_HSequenceOfInteger) aCurve = new TColStd_HSequenceOfInteger;
1321     // Find out type of edge curve
1322     Standard_Real aFirst = 0, aLast = 0;
1323     Handle(Geom_Curve) anEdgeCurve = BRep_Tool::Curve(TopoDS::Edge(aCurveIt.Current()), aFirst, aLast);
1324     if (anEdgeCurve.IsNull())
1325       continue;
1326     // Line
1327     if (anEdgeCurve->IsKind(STANDARD_TYPE(Geom_Line))) {
1328       for (TopExp_Explorer aVertIt(aCurveIt.Current(), TopAbs_VERTEX); aVertIt.More(); aVertIt.Next()) {
1329         aCoords.Append(BRep_Tool::Pnt(TopoDS::Vertex(aVertIt.Current())).XYZ());
1330         aCurve->Append(aPntNb);
1331         aPntNb++;
1332       }
1333     }
1334     // BSpline
1335     else {
1336       ShapeConstruct_Curve aSCC;
1337       Handle(Geom_BSplineCurve) aBSCurve = aSCC.ConvertToBSpline(anEdgeCurve,
1338           aFirst, aLast, Precision::Confusion());
1339       for (Standard_Integer i = 1; i <= aBSCurve->NbPoles(); i++) {
1340         aCoords.Append(aBSCurve->Pole(i).XYZ());
1341         aCurve->Append(aPntNb);
1342         aPntNb++;
1343       }
1344     }
1345     aCurves->Append(aCurve);
1346   }
1347
1348   Handle(TColgp_HArray1OfXYZ) aPoints = new TColgp_HArray1OfXYZ(1, aCoords.Length());
1349   for (Standard_Integer i = 1; i <= aPoints->Length(); i++) {
1350     aPoints->SetValue(i, aCoords.Value(i - 1));
1351   }
1352   // STEP entities
1353   Handle(StepVisual_CoordinatesList) aCoordList = new StepVisual_CoordinatesList();
1354   aCoordList->Init(new TCollection_HAsciiString(), aPoints);
1355   Handle(StepVisual_TessellatedCurveSet) aCurveSet = new StepVisual_TessellatedCurveSet();
1356   aCurveSet->Init(new TCollection_HAsciiString(), aCoordList, aCurves);
1357   NCollection_Handle<StepVisual_Array1OfTessellatedItem> aTessItems = new StepVisual_Array1OfTessellatedItem(1, 1);
1358   aTessItems->SetValue(1, aCurveSet);
1359   Handle(StepVisual_TessellatedGeometricSet) aGeomSet = new StepVisual_TessellatedGeometricSet();
1360   aGeomSet->Init(new TCollection_HAsciiString(), aTessItems);
1361   return aGeomSet;
1362 }