0028449: Data Exchange - Wrong orientation of Annotation Plane in GD&T
[occt.git] / src / STEPCAFControl / STEPCAFControl_Reader.cxx
index 674093f..70d3988 100644 (file)
@@ -1948,7 +1948,6 @@ Standard_Boolean readAnnotationPlane(const Handle(StepVisual_AnnotationPlane) th
 {
   if (theAnnotationPlane.IsNull())
     return Standard_False;
-  gp_Ax2 aPlaneAxes;
   Handle(StepRepr_RepresentationItem) aPlaneItem = theAnnotationPlane->Item();
   if (aPlaneItem.IsNull())
     return Standard_False;
@@ -1965,23 +1964,11 @@ Standard_Boolean readAnnotationPlane(const Handle(StepVisual_AnnotationPlane) th
   if (aA2P3D.IsNull())
     return Standard_False;
 
-  // build gp_Ax2 from axes
-  Handle(StepGeom_Direction) anAxis = aA2P3D->Axis(),
-    aRefDir = aA2P3D->RefDirection();
-  if (anAxis.IsNull() || aRefDir.IsNull())
-    return Standard_False;
-
-  Handle(TColStd_HArray1OfReal) aCoords;
-  aCoords = anAxis->DirectionRatios();
-  gp_Dir aXDir(aCoords->Value(1), aCoords->Value(2), aCoords->Value(3));
-  aCoords = aRefDir->DirectionRatios();
-  gp_Dir aYDir(aCoords->Value(1), aCoords->Value(2), aCoords->Value(3));
-  aPlaneAxes.SetDirection(aXDir.Crossed(aYDir));
-  aPlaneAxes.SetYDirection(aYDir);
-  //set location of the annotation plane
-  Handle(TColStd_HArray1OfReal) aLocCoords;
-  Handle(StepGeom_CartesianPoint) aLoc = aA2P3D->Location();
-  gp_Pnt aLocPos(aLoc->CoordinatesValue(1) * theFact, aLoc->CoordinatesValue(2) * theFact, aLoc->CoordinatesValue(3) * theFact);
+  gp_Ax2 aPlaneAxes;
+  Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aA2P3D);
+  aPlaneAxes = anAxis->Ax2();
+  gp_XYZ aLocPos = aPlaneAxes.Location().XYZ();
+  aLocPos *= theFact;
   aPlaneAxes.SetLocation(aLocPos);
   thePlane = aPlaneAxes;
   return Standard_True;
@@ -2577,6 +2564,13 @@ Standard_Boolean STEPCAFControl_Reader::setDatumToXCAF(const Handle(StepDimTol_D
     // Create object for datum
     TDF_Label aDatL = aDGTTool->AddDatum();
     myGDTMap.Bind(theDat, aDatL);
+    // bind datum label with all reference datum_feature entities
+    for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
+      Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i);
+      if (aSA.IsNull() || aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
+        continue;
+      myGDTMap.Bind(aSA, aDatL);
+    }
     aDGTTool->Lock(aDatL);
     aDat = XCAFDoc_Datum::Set(aDatL);
     aDGTTool->SetDatum(aShapeLabels, aDatL);
@@ -4311,13 +4305,16 @@ Standard_Boolean STEPCAFControl_Reader::ReadViews(const Handle(XSControl_WorkSes
             Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value());
           TDF_Label aGDTL;
           Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL);
+          if (!isFind) {
+            isFind = myGDTMap.Find(anIter.Value(), aGDTL);
+          }
           if (isFind)
             aGDTs.Append(aGDTL);
         }
       }
       else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationPlane))) {
         Handle(StepVisual_AnnotationPlane) aPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
-        for (Standard_Integer i = 1; i <= aPlane->NbElements(); i++) {
+        for (Standard_Integer j = 1; j <= aPlane->NbElements(); j++) {
           Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value());
           for (; aDMIAIter.More(); aDMIAIter.Next()) {
             if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))