From c640cafb8ba289a7e4aec5bf793de1cad62c96f7 Mon Sep 17 00:00:00 2001 From: ikochetkova Date: Fri, 31 Oct 2025 10:45:32 +0000 Subject: [PATCH] Data Exchange, Step Import - Add import of coordinate system connection points for dimensions (#779) Add possibility to retrieve and save the whole coordinate system as a connection point for dimensions. Refactor reading of connection points from STEP. Refactor Set and Get methods of Dimension XCAF object. Add new exporting data to the test method XDumpDGTs and update the test cases respectively. --- .../STEPCAFControl/STEPCAFControl_Reader.cxx | 124 ++++---- .../XCAFDimTolObjects_DimensionObject.cxx | 66 +++-- .../XCAFDimTolObjects_DimensionObject.hxx | 76 ++++- .../TKXCAF/XCAFDoc/XCAFDoc_Dimension.cxx | 280 ++++++++++-------- src/Draw/TKXDEDRAW/XDEDRAW/XDEDRAW_GDTs.cxx | 22 ++ tests/gdt/import/A4 | 8 +- 6 files changed, 348 insertions(+), 228 deletions(-) diff --git a/src/DataExchange/TKDESTEP/STEPCAFControl/STEPCAFControl_Reader.cxx b/src/DataExchange/TKDESTEP/STEPCAFControl/STEPCAFControl_Reader.cxx index 52e992b6fa..a7b5a44f56 100644 --- a/src/DataExchange/TKDESTEP/STEPCAFControl/STEPCAFControl_Reader.cxx +++ b/src/DataExchange/TKDESTEP/STEPCAFControl/STEPCAFControl_Reader.cxx @@ -2586,6 +2586,49 @@ void readAnnotation(const Handle(XSControl_TransferReader)& theTR, return; } +//======================================================================= +// function : retrieveConnectionPointFromGISU +// purpose : auxiliary method for reading connection points +//======================================================================= +static bool retrieveConnectionPointFromGISU( + const Handle(StepAP242_GeometricItemSpecificUsage)& theGISU, + const Standard_Real theFact, + gp_Ax2& theConnectionCS, + bool& theIsPoint, + Handle(TCollection_HAsciiString)& theConnName) +{ + if (theGISU.IsNull() || theGISU->NbIdentifiedItem() == 0) + return false; + + Handle(StepGeom_CartesianPoint) aPoint = + Handle(StepGeom_CartesianPoint)::DownCast(theGISU->IdentifiedItem()->Value(1)); + if (!aPoint.IsNull()) + { + theIsPoint = true; + theConnName = aPoint->Name(); + gp_Pnt aLoc(aPoint->CoordinatesValue(1) * theFact, + aPoint->CoordinatesValue(2) * theFact, + aPoint->CoordinatesValue(3) * theFact); + theConnectionCS.SetLocation(aLoc); + return true; + } + else + { + // try Axis2Placement3d.location instead of CartesianPoint + Handle(StepGeom_Axis2Placement3d) anA2P3D = + Handle(StepGeom_Axis2Placement3d)::DownCast(theGISU->IdentifiedItem()->Value(1)); + if (anA2P3D.IsNull()) + return false; + theIsPoint = false; + theConnName = anA2P3D->Name(); + Handle(Geom_Axis2Placement) anAxis = + StepToGeom::MakeAxis2Placement(anA2P3D, StepData_Factors()); + theConnectionCS = anAxis->Ax2(); + return true; + } + return false; +} + //======================================================================= // function : readConnectionPoints // purpose : read connection points for given dimension @@ -2636,25 +2679,17 @@ void readConnectionPoints(const Handle(XSControl_TransferReader)& theTR { aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value()); } - if (aGISU.IsNull() || aGISU->NbIdentifiedItem() == 0) - return; - Handle(StepGeom_CartesianPoint) aPoint = - Handle(StepGeom_CartesianPoint)::DownCast(aGISU->IdentifiedItem()->Value(1)); - if (aPoint.IsNull()) - { - // try Axis2Placement3d.location instead of CartesianPoint - Handle(StepGeom_Axis2Placement3d) anA2P3D = - Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU->IdentifiedItem()->Value(1)); - if (anA2P3D.IsNull()) - return; - aPoint = anA2P3D->Location(); + gp_Ax2 aCS; + bool aIsPoint = false; + Handle(TCollection_HAsciiString) aConnName; + if (retrieveConnectionPointFromGISU(aGISU, aFact, aCS, aIsPoint, aConnName)) + { + if (aIsPoint) + theDimObject->SetPoint(aCS.Location()); + else + theDimObject->SetConnectionAxis(aCS); + theDimObject->SetConnectionName(aConnName); } - - // set connection point to object - gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, - aPoint->CoordinatesValue(2) * aFact, - aPoint->CoordinatesValue(3) * aFact); - theDimObject->SetPoint(aPnt); } else if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) { @@ -2686,48 +2721,25 @@ void readConnectionPoints(const Handle(XSControl_TransferReader)& theTR } } // first point - if (!aGISU1.IsNull() && aGISU1->NbIdentifiedItem() > 0) + gp_Ax2 aCS; + bool aIsPoint = false; + Handle(TCollection_HAsciiString) aConnName; + if (retrieveConnectionPointFromGISU(aGISU1, aFact, aCS, aIsPoint, aConnName)) { - Handle(StepGeom_CartesianPoint) aPoint = - Handle(StepGeom_CartesianPoint)::DownCast(aGISU1->IdentifiedItem()->Value(1)); - if (aPoint.IsNull()) - { - // try Axis2Placement3d.location instead of CartesianPoint - Handle(StepGeom_Axis2Placement3d) anA2P3D = - Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU1->IdentifiedItem()->Value(1)); - if (!anA2P3D.IsNull()) - aPoint = anA2P3D->Location(); - } - if (!aPoint.IsNull()) - { - // set connection point to object - gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, - aPoint->CoordinatesValue(2) * aFact, - aPoint->CoordinatesValue(3) * aFact); - theDimObject->SetPoint(aPnt); - } + if (aIsPoint) + theDimObject->SetPoint(aCS.Location()); + else + theDimObject->SetConnectionAxis(aCS); + theDimObject->SetConnectionName(aConnName); } // second point - if (!aGISU2.IsNull() && aGISU2->NbIdentifiedItem() > 0) + if (retrieveConnectionPointFromGISU(aGISU2, aFact, aCS, aIsPoint, aConnName)) { - Handle(StepGeom_CartesianPoint) aPoint = - Handle(StepGeom_CartesianPoint)::DownCast(aGISU2->IdentifiedItem()->Value(1)); - if (aPoint.IsNull()) - { - // try Axis2Placement3d.location instead of CartesianPoint - Handle(StepGeom_Axis2Placement3d) anA2P3D = - Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU2->IdentifiedItem()->Value(1)); - if (!anA2P3D.IsNull()) - aPoint = anA2P3D->Location(); - } - if (!aPoint.IsNull()) - { - // set connection point to object - gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, - aPoint->CoordinatesValue(2) * aFact, - aPoint->CoordinatesValue(3) * aFact); - theDimObject->SetPoint2(aPnt); - } + if (aIsPoint) + theDimObject->SetPoint2(aCS.Location()); + else + theDimObject->SetConnectionAxis2(aCS); + theDimObject->SetConnectionName2(aConnName); } } } diff --git a/src/DataExchange/TKXCAF/XCAFDimTolObjects/XCAFDimTolObjects_DimensionObject.cxx b/src/DataExchange/TKXCAF/XCAFDimTolObjects/XCAFDimTolObjects_DimensionObject.cxx index ee3093d141..a818fcbb26 100644 --- a/src/DataExchange/TKXCAF/XCAFDimTolObjects/XCAFDimTolObjects_DimensionObject.cxx +++ b/src/DataExchange/TKXCAF/XCAFDimTolObjects/XCAFDimTolObjects_DimensionObject.cxx @@ -21,10 +21,10 @@ IMPLEMENT_STANDARD_RTTIEXT(XCAFDimTolObjects_DimensionObject, Standard_Transient XCAFDimTolObjects_DimensionObject::XCAFDimTolObjects_DimensionObject() { - myHasPlane = Standard_False; - myHasPntText = Standard_False; - myHasPoint1 = Standard_False; - myHasPoint2 = Standard_False; + myHasPlane = Standard_False; + myHasPntText = Standard_False; + myHasConnection1 = Standard_False; + myHasConnection2 = Standard_False; } //================================================================================================= @@ -32,29 +32,33 @@ XCAFDimTolObjects_DimensionObject::XCAFDimTolObjects_DimensionObject() XCAFDimTolObjects_DimensionObject::XCAFDimTolObjects_DimensionObject( const Handle(XCAFDimTolObjects_DimensionObject)& theObj) { - myType = theObj->myType; - myVal = theObj->myVal; - myQualifier = theObj->myQualifier; - myAngularQualifier = theObj->myAngularQualifier; - myIsHole = theObj->myIsHole; - myFormVariance = theObj->myFormVariance; - myGrade = theObj->myGrade; - myL = theObj->myL; - myR = theObj->myR; - myModifiers = theObj->myModifiers; - myPath = theObj->myPath; - myDir = theObj->myDir; - myHasPoint1 = theObj->myHasPoint1; - myPnt1 = theObj->myPnt1; - myHasPoint2 = theObj->myHasPoint2; - myPnt2 = theObj->myPnt2; - myPntText = theObj->myPntText; - myHasPlane = theObj->myHasPlane; - myPlane = theObj->myPlane; - myHasPntText = theObj->myHasPntText; - mySemanticName = theObj->mySemanticName; - myPresentation = theObj->myPresentation; - myPresentationName = theObj->myPresentationName; + myType = theObj->myType; + myVal = theObj->myVal; + myQualifier = theObj->myQualifier; + myAngularQualifier = theObj->myAngularQualifier; + myIsHole = theObj->myIsHole; + myFormVariance = theObj->myFormVariance; + myGrade = theObj->myGrade; + myL = theObj->myL; + myR = theObj->myR; + myModifiers = theObj->myModifiers; + myPath = theObj->myPath; + myDir = theObj->myDir; + myHasConnection1 = theObj->myHasConnection1; + myHasConnection2 = theObj->myHasConnection2; + myConnection1 = theObj->myConnection1; + myConnection2 = theObj->myConnection2; + myConnectionName1 = theObj->myConnectionName1; + myConnectionName2 = theObj->myConnectionName2; + myConnectionIsPoint1 = theObj->myConnectionIsPoint1; + myConnectionIsPoint2 = theObj->myConnectionIsPoint2; + myPntText = theObj->myPntText; + myHasPlane = theObj->myHasPlane; + myPlane = theObj->myPlane; + myHasPntText = theObj->myHasPntText; + mySemanticName = theObj->mySemanticName; + myPresentation = theObj->myPresentation; + myPresentationName = theObj->myPresentationName; for (int i = 0; i < theObj->myDescriptions.Length(); i++) { myDescriptions.Append(theObj->myDescriptions(i)); @@ -520,14 +524,14 @@ void XCAFDimTolObjects_DimensionObject::DumpJson(Standard_OStream& theOStream, } OCCT_DUMP_FIELD_VALUES_DUMPED(theOStream, theDepth, &myDir) - if (myHasPoint1) + if (myHasConnection1) { - OCCT_DUMP_FIELD_VALUES_DUMPED(theOStream, theDepth, &myPnt1) + OCCT_DUMP_FIELD_VALUES_DUMPED(theOStream, theDepth, &myConnection1) } - if (myHasPoint2) + if (myHasConnection2) { - OCCT_DUMP_FIELD_VALUES_DUMPED(theOStream, theDepth, &myPnt2) + OCCT_DUMP_FIELD_VALUES_DUMPED(theOStream, theDepth, &myConnection2) } if (myHasPlane) diff --git a/src/DataExchange/TKXCAF/XCAFDimTolObjects/XCAFDimTolObjects_DimensionObject.hxx b/src/DataExchange/TKXCAF/XCAFDimTolObjects/XCAFDimTolObjects_DimensionObject.hxx index 8f78fe04cc..0768c14b3e 100644 --- a/src/DataExchange/TKXCAF/XCAFDimTolObjects/XCAFDimTolObjects_DimensionObject.hxx +++ b/src/DataExchange/TKXCAF/XCAFDimTolObjects/XCAFDimTolObjects_DimensionObject.hxx @@ -215,32 +215,86 @@ public: //! Returns true, if connection point exists (for dimensional_size), //! if connection point for the first shape exists (for dimensional_location). - Standard_Boolean HasPoint() const { return myHasPoint1; } + Standard_Boolean HasPoint() const { return myHasConnection1; } // Returns true, if connection point for the second shape exists (for dimensional_location only). - Standard_Boolean HasPoint2() const { return myHasPoint2; } + Standard_Boolean HasPoint2() const { return myHasConnection2; } + + //! Returns true, if the connection is a point not coordinate system (for dimensional_size), + //! if connection point for the first shape exists (for dimensional_location). + Standard_Boolean IsPointConnection() const { return myConnectionIsPoint1; } + + // Returns true, if the connection for the second shape is a point not coordinate system (for + // dimensional_location only). + Standard_Boolean IsPointConnection2() const { return myConnectionIsPoint2; } //! Set connection point (for dimensional_size), //! Set connection point for the first shape (for dimensional_location). void SetPoint(const gp_Pnt& thePnt) { - myPnt1 = thePnt; - myHasPoint1 = Standard_True; + myConnection1.SetLocation(thePnt); + myHasConnection1 = Standard_True; + myConnectionIsPoint1 = Standard_True; } // Set connection point for the second shape (for dimensional_location only). void SetPoint2(const gp_Pnt& thePnt) { - myPnt2 = thePnt; - myHasPoint2 = Standard_True; + myConnection2.SetLocation(thePnt); + myHasConnection2 = Standard_True; + myConnectionIsPoint2 = Standard_True; + } + + //! Set connection point as a coordinate system (for dimensional_size), + //! Set connection point as a coordinate system for the first shape (for dimensional_location). + void SetConnectionAxis(const gp_Ax2& theAxis) + { + myConnection1 = theAxis; + myHasConnection1 = Standard_True; + myConnectionIsPoint1 = Standard_False; + } + + // Set connection point as a coordinate system for the second shape (for dimensional_location + // only). + void SetConnectionAxis2(const gp_Ax2& theAxis) + { + myConnection2 = theAxis; + myHasConnection2 = Standard_True; + myConnectionIsPoint2 = Standard_False; } //! Get connection point (for dimensional_size), //! Get connection point for the first shape (for dimensional_location). - gp_Pnt GetPoint() const { return myPnt1; } + gp_Pnt GetPoint() const { return myConnection1.Location(); } // Get connection point for the second shape (for dimensional_location only). - gp_Pnt GetPoint2() const { return myPnt2; } + gp_Pnt GetPoint2() const { return myConnection2.Location(); } + + //! Get connection point as a coordinate system (for dimensional_size), + //! Get connection point as a coordinate system for the first shape (for dimensional_location). + gp_Ax2 GetConnectionAxis() const { return myConnection1; } + + // Get connection point as a coordinate system for the second shape (for dimensional_location + // only). + gp_Ax2 GetConnectionAxis2() const { return myConnection2; } + + //! Returns connection name of the object. + Handle(TCollection_HAsciiString) GetConnectionName() const { return myConnectionName1; } + + //! Returns 2nd connection name of the object. + Handle(TCollection_HAsciiString) GetConnectionName2() const { return myConnectionName2; } + + //! Sets connection name of the object. + void SetConnectionName(const Handle(TCollection_HAsciiString)& theName) + { + myConnectionName1 = theName; + } + + //! Sets 2nd connection name of the object. + void SetConnectionName2(const Handle(TCollection_HAsciiString)& theName) + { + myConnectionName2 = theName; + } //! Set graphical presentation for the object. void SetPresentation(const TopoDS_Shape& thePresentation, @@ -318,8 +372,10 @@ private: XCAFDimTolObjects_DimensionModifiersSequence myModifiers; TopoDS_Edge myPath; gp_Dir myDir; - gp_Pnt myPnt1, myPnt2; - Standard_Boolean myHasPoint1, myHasPoint2; + gp_Ax2 myConnection1, myConnection2; + Standard_Boolean myHasConnection1, myHasConnection2; + Standard_Boolean myConnectionIsPoint1, myConnectionIsPoint2; + Handle(TCollection_HAsciiString) myConnectionName1, myConnectionName2; gp_Ax2 myPlane; Standard_Boolean myHasPlane; Standard_Boolean myHasPntText; diff --git a/src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_Dimension.cxx b/src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_Dimension.cxx index b870043073..4149e3d1a6 100644 --- a/src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_Dimension.cxx +++ b/src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_Dimension.cxx @@ -53,6 +53,8 @@ enum ChildLab ChildLab_Descriptions, ChildLab_DescriptionNames, ChildLab_AngularQualifier, + ChildLab_ConnectionAxis1, + ChildLab_ConnectionAxis2, ChildLab_End }; @@ -85,15 +87,66 @@ Handle(XCAFDoc_Dimension) XCAFDoc_Dimension::Set(const TDF_Label& theLabel) //================================================================================================= -void XCAFDoc_Dimension::SetObject(const Handle(XCAFDimTolObjects_DimensionObject)& theObject) +static void setString(const TDF_Label& theLabel, const Handle(TCollection_HAsciiString)& theStr) { - Backup(); + if (theStr.IsNull()) + return; + + TCollection_ExtendedString aStr(theStr->String()); + TDataStd_Name::Set(theLabel, aStr); +} + +//================================================================================================= + +static void setRealArrayXYZ(const TDF_Label& theLabel, const gp_XYZ& theArr) +{ + Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1, 3); + anArr->SetValue(1, theArr.X()); + anArr->SetValue(2, theArr.Y()); + anArr->SetValue(3, theArr.Z()); + Handle(TDataStd_RealArray) anArrayAttr = TDataStd_RealArray::Set(theLabel, 1, 3); + if (!anArrayAttr.IsNull()) + anArrayAttr->ChangeArray(anArr); +} + +//================================================================================================= + +static Handle(TCollection_HAsciiString) getString(const TDF_Label& theLabel) +{ + Handle(TDataStd_Name) aStrAttr; + Handle(TCollection_HAsciiString) aStr; + if (theLabel.FindAttribute(TDataStd_Name::GetID(), aStrAttr)) + { + const TCollection_ExtendedString& aName = aStrAttr->Get(); + if (!aName.IsEmpty()) + aStr = new TCollection_HAsciiString(aName); + } + return aStr; +} + +//================================================================================================= - if (theObject->GetSemanticName()) +static bool getRealArrayXYZ(const TDF_Label& theLabel, gp_XYZ& theXYZ) +{ + Handle(TDataStd_RealArray) anArrayAttr; + if (theLabel.FindAttribute(TDataStd_RealArray::GetID(), anArrayAttr) && !anArrayAttr.IsNull() + && anArrayAttr->Length() == 3) { - TCollection_ExtendedString str(theObject->GetSemanticName()->String()); - TDataStd_Name::Set(Label(), str); + theXYZ.SetX(anArrayAttr->Value(1)); + theXYZ.SetY(anArrayAttr->Value(2)); + theXYZ.SetZ(anArrayAttr->Value(3)); + return true; } + return false; +} + +//================================================================================================= + +void XCAFDoc_Dimension::SetObject(const Handle(XCAFDimTolObjects_DimensionObject)& theObject) +{ + Backup(); + + setString(Label(), theObject->GetSemanticName()); for (int aChild = ChildLab_Begin; aChild < ChildLab_End; aChild++) { @@ -168,87 +221,72 @@ void XCAFDoc_Dimension::SetObject(const Handle(XCAFDimTolObjects_DimensionObject tnBuild.Generated(theObject->GetPath()); } - Handle(TColStd_HArray1OfReal) anArrR; if (theObject->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented) { gp_Dir aD; theObject->GetDirection(aD); - anArrR = new TColStd_HArray1OfReal(1, 3); - anArrR->SetValue(1, aD.X()); - anArrR->SetValue(2, aD.Y()); - anArrR->SetValue(3, aD.Z()); - Handle(TDataStd_RealArray) aDir = - TDataStd_RealArray::Set(Label().FindChild(ChildLab_Dir), 1, 3); - if (!aDir.IsNull()) - aDir->ChangeArray(anArrR); + setRealArrayXYZ(Label().FindChild(ChildLab_Dir), aD.XYZ()); } if (theObject->HasPoint()) { - gp_Pnt aPnt1 = theObject->GetPoint(); - - Handle(TColStd_HArray1OfReal) aPntArr = new TColStd_HArray1OfReal(1, 3); - for (Standard_Integer i = 1; i <= 3; i++) - aPntArr->SetValue(i, aPnt1.Coord(i)); - Handle(TDataStd_RealArray) aPnt = - TDataStd_RealArray::Set(Label().FindChild(ChildLab_Pnt1), 1, 3); - if (!aPnt.IsNull()) - aPnt->ChangeArray(aPntArr); + // put point + setRealArrayXYZ(Label().FindChild(ChildLab_Pnt1), theObject->GetPoint().XYZ()); + setString(Label().FindChild(ChildLab_Pnt1), theObject->GetConnectionName()); + + if (!theObject->IsPointConnection()) + { + // put additional info about axis + gp_Ax2 anAxis1 = theObject->GetConnectionAxis(); + + Handle(TColStd_HArray1OfReal) aAxisArr = new TColStd_HArray1OfReal(1, 6); + for (Standard_Integer i = 1; i <= 3; i++) + { + aAxisArr->SetValue(i, anAxis1.Direction().Coord(i)); + aAxisArr->SetValue(i + 3, anAxis1.XDirection().Coord(i)); + } + Handle(TDataStd_RealArray) aAxis = + TDataStd_RealArray::Set(Label().FindChild(ChildLab_ConnectionAxis1), 1, 6); + if (!aAxis.IsNull()) + aAxis->ChangeArray(aAxisArr); + } } if (theObject->HasPoint2()) { - gp_Pnt aPnt2 = theObject->GetPoint2(); - - Handle(TColStd_HArray1OfReal) aPntArr = new TColStd_HArray1OfReal(1, 3); - for (Standard_Integer i = 1; i <= 3; i++) - aPntArr->SetValue(i, aPnt2.Coord(i)); - Handle(TDataStd_RealArray) aPnt = - TDataStd_RealArray::Set(Label().FindChild(ChildLab_Pnt2), 1, 3); - if (!aPnt.IsNull()) - aPnt->ChangeArray(aPntArr); + setRealArrayXYZ(Label().FindChild(ChildLab_Pnt2), theObject->GetPoint2().XYZ()); + setString(Label().FindChild(ChildLab_Pnt2), theObject->GetConnectionName2()); + + if (!theObject->IsPointConnection2()) + { + // put additional info about axis + gp_Ax2 anAxis2 = theObject->GetConnectionAxis2(); + + Handle(TColStd_HArray1OfReal) aAxisArr = new TColStd_HArray1OfReal(1, 6); + for (Standard_Integer i = 1; i <= 3; i++) + { + aAxisArr->SetValue(i, anAxis2.Direction().Coord(i)); + aAxisArr->SetValue(i + 3, anAxis2.XDirection().Coord(i)); + } + Handle(TDataStd_RealArray) aAxis = + TDataStd_RealArray::Set(Label().FindChild(ChildLab_ConnectionAxis2), 1, 6); + if (!aAxis.IsNull()) + aAxis->ChangeArray(aAxisArr); + } } if (theObject->HasPlane()) { gp_Ax2 anAx = theObject->GetPlane(); - - Handle(TColStd_HArray1OfReal) aLocArr = new TColStd_HArray1OfReal(1, 3); - for (Standard_Integer i = 1; i <= 3; i++) - aLocArr->SetValue(i, anAx.Location().Coord(i)); - Handle(TDataStd_RealArray) aLoc = - TDataStd_RealArray::Set(Label().FindChild(ChildLab_PlaneLoc), 1, 3); - if (!aLoc.IsNull()) - aLoc->ChangeArray(aLocArr); - - Handle(TColStd_HArray1OfReal) aNArr = new TColStd_HArray1OfReal(1, 3); - for (Standard_Integer i = 1; i <= 3; i++) - aNArr->SetValue(i, anAx.Direction().Coord(i)); - Handle(TDataStd_RealArray) aN = - TDataStd_RealArray::Set(Label().FindChild(ChildLab_PlaneN), 1, 3); - if (!aN.IsNull()) - aN->ChangeArray(aNArr); - - Handle(TColStd_HArray1OfReal) aRArr = new TColStd_HArray1OfReal(1, 3); - for (Standard_Integer i = 1; i <= 3; i++) - aRArr->SetValue(i, anAx.XDirection().Coord(i)); - Handle(TDataStd_RealArray) aRAtt = - TDataStd_RealArray::Set(Label().FindChild(ChildLab_PlaneRef), 1, 3); - if (!aRAtt.IsNull()) - aRAtt->ChangeArray(aRArr); + setRealArrayXYZ(Label().FindChild(ChildLab_PlaneLoc), anAx.Location().XYZ()); + setRealArrayXYZ(Label().FindChild(ChildLab_PlaneN), anAx.Direction().XYZ()); + setRealArrayXYZ(Label().FindChild(ChildLab_PlaneRef), anAx.XDirection().XYZ()); } if (theObject->HasTextPoint()) { gp_Pnt aPntText = theObject->GetPointTextAttach(); - - Handle(TColStd_HArray1OfReal) aLocArr = new TColStd_HArray1OfReal(1, 3); - for (Standard_Integer i = 1; i <= 3; i++) - aLocArr->SetValue(i, aPntText.Coord(i)); - Handle(TDataStd_RealArray) aLoc = - TDataStd_RealArray::Set(Label().FindChild(ChildLab_PntText), 1, 3); - if (!aLoc.IsNull()) - aLoc->ChangeArray(aLocArr); + setRealArrayXYZ(Label().FindChild(ChildLab_PntText), aPntText.XYZ()); } TopoDS_Shape aPresentation = theObject->GetPresentation(); @@ -257,12 +295,7 @@ void XCAFDoc_Dimension::SetObject(const Handle(XCAFDimTolObjects_DimensionObject TDF_Label aLPres = Label().FindChild(ChildLab_Presentation); TNaming_Builder tnBuild(aLPres); tnBuild.Generated(aPresentation); - Handle(TCollection_HAsciiString) aName = theObject->GetPresentationName(); - if (!aName.IsNull()) - { - TCollection_ExtendedString str(aName->String()); - TDataStd_Name::Set(aLPres, str); - } + setString(aLPres, theObject->GetPresentationName()); } if (theObject->HasDescriptions()) @@ -298,16 +331,9 @@ void XCAFDoc_Dimension::SetObject(const Handle(XCAFDimTolObjects_DimensionObject Handle(XCAFDimTolObjects_DimensionObject) XCAFDoc_Dimension::GetObject() const { Handle(XCAFDimTolObjects_DimensionObject) anObj = new XCAFDimTolObjects_DimensionObject(); + gp_XYZ aXYZValue; - Handle(TDataStd_Name) aSemanticNameAttr; - Handle(TCollection_HAsciiString) aSemanticName; - if (Label().FindAttribute(TDataStd_Name::GetID(), aSemanticNameAttr)) - { - const TCollection_ExtendedString& aName = aSemanticNameAttr->Get(); - if (!aName.IsEmpty()) - aSemanticName = new TCollection_HAsciiString(aName); - } - anObj->SetSemanticName(aSemanticName); + anObj->SetSemanticName(getString(Label())); Handle(TDataStd_Integer) aType; if (Label().FindChild(ChildLab_Type).FindAttribute(TDataStd_Integer::GetID(), aType)) @@ -371,59 +397,67 @@ Handle(XCAFDimTolObjects_DimensionObject) XCAFDoc_Dimension::GetObject() const anObj->SetPath(TopoDS::Edge(aShape->Get())); } - Handle(TDataStd_RealArray) aDir; - if (Label().FindChild(ChildLab_Dir).FindAttribute(TDataStd_RealArray::GetID(), aDir) - && !aDir->Array().IsNull() && aDir->Array()->Length() > 0) + if (getRealArrayXYZ(Label().FindChild(ChildLab_Dir), aXYZValue)) { - gp_Dir aD(aDir->Array()->Value(1), aDir->Array()->Value(2), aDir->Array()->Value(3)); - anObj->SetDirection(aD); + anObj->SetDirection(aXYZValue); } - Handle(TDataStd_RealArray) aPnt1; - if (Label().FindChild(ChildLab_Pnt1).FindAttribute(TDataStd_RealArray::GetID(), aPnt1) - && aPnt1->Length() == 3) + Handle(TDataStd_RealArray) anAxis1; + if (getRealArrayXYZ(Label().FindChild(ChildLab_Pnt1), aXYZValue)) { - gp_Pnt aP(aPnt1->Value(aPnt1->Lower()), - aPnt1->Value(aPnt1->Lower() + 1), - aPnt1->Value(aPnt1->Lower() + 2)); - anObj->SetPoint(aP); + gp_Pnt aP(aXYZValue); + anObj->SetConnectionName(getString(Label().FindChild(ChildLab_Pnt1))); + + if (Label() + .FindChild(ChildLab_ConnectionAxis1) + .FindAttribute(TDataStd_RealArray::GetID(), anAxis1) + && anAxis1->Length() == 6) + { + gp_Ax2 anAx1(aP, + gp_Dir(anAxis1->Value(1), anAxis1->Value(2), anAxis1->Value(3)), + gp_Dir(anAxis1->Value(4), anAxis1->Value(5), anAxis1->Value(6))); + anObj->SetConnectionAxis(anAx1); + } + else + { + anObj->SetPoint(aP); + } } - Handle(TDataStd_RealArray) aPnt2; - if (Label().FindChild(ChildLab_Pnt2).FindAttribute(TDataStd_RealArray::GetID(), aPnt2) - && aPnt2->Length() == 3) + Handle(TDataStd_RealArray) anAxis2; + if (getRealArrayXYZ(Label().FindChild(ChildLab_Pnt2), aXYZValue)) { - gp_Pnt aP(aPnt2->Value(aPnt2->Lower()), - aPnt2->Value(aPnt2->Lower() + 1), - aPnt2->Value(aPnt2->Lower() + 2)); - anObj->SetPoint2(aP); + gp_Pnt aP(aXYZValue); + anObj->SetConnectionName2(getString(Label().FindChild(ChildLab_Pnt2))); + + if (Label() + .FindChild(ChildLab_ConnectionAxis2) + .FindAttribute(TDataStd_RealArray::GetID(), anAxis2) + && anAxis2->Length() == 6) + { + gp_Ax2 anAx2(aP, + gp_Dir(anAxis2->Value(1), anAxis2->Value(2), anAxis2->Value(3)), + gp_Dir(anAxis2->Value(4), anAxis2->Value(5), anAxis2->Value(6))); + anObj->SetConnectionAxis2(anAx2); + } + else + { + anObj->SetPoint2(aP); + } } - Handle(TDataStd_RealArray) aLoc, aN, aR; - if (Label().FindChild(ChildLab_PlaneLoc).FindAttribute(TDataStd_RealArray::GetID(), aLoc) - && aLoc->Length() == 3 - && Label().FindChild(ChildLab_PlaneN).FindAttribute(TDataStd_RealArray::GetID(), aN) - && aN->Length() == 3 - && Label().FindChild(ChildLab_PlaneRef).FindAttribute(TDataStd_RealArray::GetID(), aR) - && aR->Length() == 3) + gp_XYZ aLoc, aN, aR; + if (getRealArrayXYZ(Label().FindChild(ChildLab_PlaneLoc), aLoc) + && getRealArrayXYZ(Label().FindChild(ChildLab_PlaneN), aN) + && getRealArrayXYZ(Label().FindChild(ChildLab_PlaneRef), aR)) { - gp_Pnt aL(aLoc->Value(aLoc->Lower()), - aLoc->Value(aLoc->Lower() + 1), - aLoc->Value(aLoc->Lower() + 2)); - gp_Dir aD(aN->Value(aN->Lower()), aN->Value(aN->Lower() + 1), aN->Value(aN->Lower() + 2)); - gp_Dir aDR(aR->Value(aR->Lower()), aR->Value(aR->Lower() + 1), aR->Value(aR->Lower() + 2)); - gp_Ax2 anAx(aL, aD, aDR); + gp_Ax2 anAx(aLoc, aN, aR); anObj->SetPlane(anAx); } - Handle(TDataStd_RealArray) aPntText; - if (Label().FindChild(ChildLab_PntText).FindAttribute(TDataStd_RealArray::GetID(), aPntText) - && aPntText->Length() == 3) + if (getRealArrayXYZ(Label().FindChild(ChildLab_PntText), aXYZValue)) { - gp_Pnt aP(aPntText->Value(aPntText->Lower()), - aPntText->Value(aPntText->Lower() + 1), - aPntText->Value(aPntText->Lower() + 2)); - anObj->SetPointTextAttach(aP); + anObj->SetPointTextAttach(aXYZValue); } Handle(TNaming_NamedShape) aNS; @@ -433,15 +467,7 @@ Handle(XCAFDimTolObjects_DimensionObject) XCAFDoc_Dimension::GetObject() const TopoDS_Shape aPresentation = TNaming_Tool::GetShape(aNS); if (!aPresentation.IsNull()) { - Handle(TDataStd_Name) aNameAtrr; - Handle(TCollection_HAsciiString) aPresentName; - if (aLPres.FindAttribute(TDataStd_Name::GetID(), aNameAtrr)) - { - const TCollection_ExtendedString& aName = aNameAtrr->Get(); - if (!aName.IsEmpty()) - aPresentName = new TCollection_HAsciiString(aName); - } - anObj->SetPresentation(aPresentation, aPresentName); + anObj->SetPresentation(aPresentation, getString(aLPres)); } } diff --git a/src/Draw/TKXDEDRAW/XDEDRAW/XDEDRAW_GDTs.cxx b/src/Draw/TKXDEDRAW/XDEDRAW/XDEDRAW_GDTs.cxx index 0f5b00d59c..b14a18ae15 100644 --- a/src/Draw/TKXDEDRAW/XDEDRAW/XDEDRAW_GDTs.cxx +++ b/src/Draw/TKXDEDRAW/XDEDRAW/XDEDRAW_GDTs.cxx @@ -177,6 +177,28 @@ static Standard_Integer DumpDGTs(Draw_Interpretor& di, Standard_Integer argc, co } } di << ", P " << (Standard_Integer)!aDimTolObj->GetPath().IsNull(); + if (aDimTolObj->HasPoint()) + { + TCollection_AsciiString aName; + if (!aDimTolObj->GetConnectionName().IsNull()) + aName = aDimTolObj->GetConnectionName()->String(); + di << " Conn1 \"" << aName << "\" "; + if (aDimTolObj->IsPointConnection()) + di << "P,"; + else + di << "CS,"; + } + if (aDimTolObj->HasPoint2()) + { + TCollection_AsciiString aName; + if (!aDimTolObj->GetConnectionName2().IsNull()) + aName = aDimTolObj->GetConnectionName2()->String(); + di << " Conn2 \"" << aName << "\" "; + if (aDimTolObj->IsPointConnection2()) + di << "P,"; + else + di << "CS,"; + } di << " )"; } } diff --git a/tests/gdt/import/A4 b/tests/gdt/import/A4 index d40802f95c..725643d9ee 100644 --- a/tests/gdt/import/A4 +++ b/tests/gdt/import/A4 @@ -174,16 +174,16 @@ set ref_data { 0:1:4:25 Dimension.42.1 ( N "diameter" T 15, V 14, VL 0.10000000000000001, VU 0.10000000000000001, P 0 ) 0:1:1:2:40 Shape.43 0:1:4:25 Dimension.43.1 ( N "diameter" T 15, V 14, VL 0.10000000000000001, VU 0.10000000000000001, P 0 ) - 0:1:4:27 Dimension.43.2 ( N "linear distance" T 2, V 75, P 0 ) + 0:1:4:27 Dimension.43.2 ( N "linear distance" T 2, V 75, P 0 Conn1 "" CS, Conn2 "" CS, ) 0:1:1:2:41 Shape.44 0:1:4:25 Dimension.44.1 ( N "diameter" T 15, V 14, VL 0.10000000000000001, VU 0.10000000000000001, P 0 ) - 0:1:4:27 Dimension.44.2 ( N "linear distance" T 2, V 75, P 0 ) + 0:1:4:27 Dimension.44.2 ( N "linear distance" T 2, V 75, P 0 Conn1 "" CS, Conn2 "" CS, ) 0:1:1:2:42 Shape.45 0:1:4:25 Dimension.45.1 ( N "diameter" T 15, V 14, VL 0.10000000000000001, VU 0.10000000000000001, P 0 ) - 0:1:4:27 Dimension.45.2 ( N "linear distance" T 2, V 75, P 0 ) + 0:1:4:27 Dimension.45.2 ( N "linear distance" T 2, V 75, P 0 Conn1 "" CS, Conn2 "" CS, ) 0:1:1:2:43 Shape.46 0:1:4:25 Dimension.46.1 ( N "diameter" T 15, V 14, VL 0.10000000000000001, VU 0.10000000000000001, P 0 ) - 0:1:4:27 Dimension.46.2 ( N "linear distance" T 2, V 75, P 0 ) + 0:1:4:27 Dimension.46.2 ( N "linear distance" T 2, V 75, P 0 Conn1 "" CS, Conn2 "" CS, ) 0:1:1:2:44 Shape.47 0:1:4:25 Dimension.47.1 ( N "diameter" T 15, V 14, VL 0.10000000000000001, VU 0.10000000000000001, P 0 ) 0:1:1:2:45 Shape.48 -- 2.39.5