From 359d02b15f4adf94a3b1b084fe2dc1d060fe2add Mon Sep 17 00:00:00 2001 From: dpasukhi Date: Tue, 11 Jul 2023 08:51:44 +0100 Subject: [PATCH] // implement scale attribute into ShapeTool --- src/XCAFDoc/XCAFDoc_ShapeTool.cxx | 101 +++++++++++++++++++++++++----- src/XCAFDoc/XCAFDoc_ShapeTool.hxx | 28 +++++++++ 2 files changed, 114 insertions(+), 15 deletions(-) diff --git a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx index b226c6f133..430c9e021d 100644 --- a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx +++ b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,21 @@ IMPLEMENT_DERIVED_ATTRIBUTE_WITH_TYPE(XCAFDoc_ShapeTool,TDataStd_GenericEmpty,"xcaf","ShapeTool") -static Standard_Boolean theAutoNaming = Standard_True; +namespace +{ + static Standard_Boolean THE_AUTO_NAMING_FLAG = Standard_True; + static Standard_Boolean THE_UNIFORM_SCALING_SUPPORT_FLAG = Standard_False; + + //======================================================================= + //function : GetUniformScaleGUID + //purpose : + //======================================================================= + const Standard_GUID& GetUniformScaleGUID() + { + static Standard_GUID anUniformScaleID("D4DA66EA-EBAD-4775-ACEC-1A018C6A4501"); + return anUniformScaleID; + } +} // attribute methods ////////////////////////////////////////////////// @@ -412,7 +427,7 @@ void XCAFDoc_ShapeTool::MakeReference (const TDF_Label &L, refNode->Remove(); // abv: fix against bug in TreeNode::Append() mainNode->Append(refNode); - if (theAutoNaming) + if (THE_AUTO_NAMING_FLAG) SetLabelNameByLink(L); } @@ -487,7 +502,7 @@ TDF_Label XCAFDoc_ShapeTool::addShape (const TopoDS_Shape& S, const Standard_Boo // } A->SetShape(S); - if (theAutoNaming) + if (THE_AUTO_NAMING_FLAG) SetLabelNameByShape(ShapeLabel); // if shape is Compound and flag is set, create assembly @@ -495,7 +510,7 @@ TDF_Label XCAFDoc_ShapeTool::addShape (const TopoDS_Shape& S, const Standard_Boo // mark assembly by assigning UAttribute Handle(TDataStd_UAttribute) Uattr; Uattr = TDataStd_UAttribute::Set ( ShapeLabel, XCAFDoc::AssemblyGUID() ); - if (theAutoNaming) + if (THE_AUTO_NAMING_FLAG) TDataStd_Name::Set(ShapeLabel, TCollection_ExtendedString("ASSEMBLY")); // iterate on components @@ -644,31 +659,87 @@ void XCAFDoc_ShapeTool::Init() //======================================================================= //function : SetAutoNaming -//purpose : +//purpose : //======================================================================= - void XCAFDoc_ShapeTool::SetAutoNaming (const Standard_Boolean V) { - theAutoNaming = V; + THE_AUTO_NAMING_FLAG = V; } - //======================================================================= //function : AutoNaming -//purpose : +//purpose : //======================================================================= - Standard_Boolean XCAFDoc_ShapeTool::AutoNaming() { - return theAutoNaming; + return THE_AUTO_NAMING_FLAG; } +//======================================================================= +//function : SetUniformScalingSupport +//purpose : +//======================================================================= +void XCAFDoc_ShapeTool::SetUniformScalingSupport(const Standard_Boolean theSupportFlag) +{ + THE_UNIFORM_SCALING_SUPPORT_FLAG = theSupportFlag; +} + +//======================================================================= +//function : UniformScalingSupport +//purpose : +//======================================================================= +Standard_Boolean XCAFDoc_ShapeTool::UniformScalingSupport() +{ + return THE_UNIFORM_SCALING_SUPPORT_FLAG; +} + +//======================================================================= +//function : GetShapeUniformScale +//purpose : +//======================================================================= +Standard_Boolean XCAFDoc_ShapeTool::GetShapeUniformScale(const TDF_Label& theShLabel, + double& theDX, + double& theDY, + double& theDZ) +{ + if (theShLabel.IsNull()) + { + return Standard_False; + } + Handle(TDataStd_RealArray) anArrAttr; + if (!theShLabel.FindAttribute(GetUniformScaleGUID(), anArrAttr) || + anArrAttr->Length() != 3) + { + return Standard_False; + } + theDX = anArrAttr->Value(1); + theDY = anArrAttr->Value(2); + theDZ = anArrAttr->Value(3); +} + +//======================================================================= +//function : SetShapeUniformScale +//purpose : +//======================================================================= +Standard_Boolean XCAFDoc_ShapeTool::SetShapeUniformScale(const TDF_Label& theShLabel, + const double theDX, + const double theDY, + const double theDZ) +{ + if (!IsShape(theShLabel)) + { + return Standard_False; + } + Handle(TDataStd_RealArray) anArray = TDataStd_RealArray::Set(theShLabel, GetUniformScaleGUID(), 1, 3); + anArray->SetValue(1, theDX); + anArray->SetValue(2, theDY); + anArray->SetValue(3, theDZ); +} //======================================================================= //function : ComputeShapes -//purpose : +//purpose : //======================================================================= - void XCAFDoc_ShapeTool::ComputeShapes(const TDF_Label& L) { TDF_ChildIterator it(L); @@ -1522,7 +1593,7 @@ Standard_Boolean XCAFDoc_ShapeTool::SetSHUO (const TDF_LabelSequence& labels, TDF_TagSource aTag; TDF_Label UpperSubL = aTag.NewChild( labels( 1 ) ); - if (theAutoNaming) { + if (THE_AUTO_NAMING_FLAG) { TCollection_ExtendedString Entry("SHUO"); TDataStd_Name::Set(UpperSubL, TCollection_ExtendedString( Entry )); } @@ -1533,7 +1604,7 @@ Standard_Boolean XCAFDoc_ShapeTool::SetSHUO (const TDF_LabelSequence& labels, // add other next_usage occurrences. for (i = 2; i <= labels.Length(); i++) { TDF_Label NextSubL = aTag.NewChild( labels( i ) ); - if (theAutoNaming) { + if (THE_AUTO_NAMING_FLAG) { TCollection_ExtendedString EntrySub("SHUO-"); EntrySub += i; TDataStd_Name::Set(NextSubL, TCollection_ExtendedString( EntrySub )); diff --git a/src/XCAFDoc/XCAFDoc_ShapeTool.hxx b/src/XCAFDoc/XCAFDoc_ShapeTool.hxx index 100b0f6b10..39f35e12b9 100644 --- a/src/XCAFDoc/XCAFDoc_ShapeTool.hxx +++ b/src/XCAFDoc/XCAFDoc_ShapeTool.hxx @@ -238,6 +238,34 @@ public: //! Returns current auto-naming mode. See SetAutoNaming() for //! description. Standard_EXPORT static Standard_Boolean AutoNaming(); + + //! Sets uniform scaling support mode to . + //! If True then some DataExchange components be able to keep + //! uniform scale information into special XCAF attribute. + //! + //! This setting is global; it cannot be made a member function + //! as it is used by static methods as well. + //! By default, uniform scaling support is disable. + //! See also UniformScalingSupport(). + Standard_EXPORT static void SetUniformScalingSupport (const Standard_Boolean theSupportFlag); + + //! Returns current niform scaling support mode. + //! See SetUniformScalingSupport() for description. + Standard_EXPORT static Standard_Boolean UniformScalingSupport(); + + //! Gets uniform scale values from the label. + //! @return true if scaling is support and attribute is exist + Standard_EXPORT static Standard_Boolean GetShapeUniformScale(const TDF_Label& theShLabel, + double& theDX, + double& theDY, + double& theDZ); + + //! Sets uniform scale values on the label. + //! @return true if scaling is support and label contains shape + Standard_EXPORT static Standard_Boolean SetShapeUniformScale(const TDF_Label& theShLabel, + const double theDX, + const double theDY, + const double theDZ); //! recursive Standard_EXPORT void ComputeShapes (const TDF_Label& L);