diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_AnimObject.cxx b/src/XCAFAnimObjects/XCAFAnimObjects_AnimObject.cxx index 81462a47a4..2ccd75712b 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_AnimObject.cxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_AnimObject.cxx @@ -11,122 +11,23 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -IMPLEMENT_DERIVED_ATTRIBUTE_WITH_TYPE(XCAFDoc_AnimationTool, TDataStd_GenericEmpty, "xcaf", "AnimationTool") +IMPLEMENT_STANDARD_RTTIEXT(XCAFAnimObjects_AnimObject, Standard_Transient) //======================================================================= -//function : GetID +//function : XCAFAnimObjects_AnimObject //purpose : //======================================================================= -const Standard_GUID& XCAFDoc_AnimationTool::GetID() -{ - static Standard_GUID ShapeToolID("9E9914DD-154A-4E17-B89B-3E33CCF67BD0"); - return ShapeToolID; -} - -//======================================================================= -//function : Set -//purpose : -//======================================================================= -Handle(XCAFDoc_AnimationTool) XCAFDoc_AnimationTool::Set(const TDF_Label& theLabel) -{ - Handle(XCAFDoc_AnimationTool) anAnimTool; - if (!theLabel.FindAttribute(XCAFDoc_AnimationTool::GetID(), anAnimTool)) { - anAnimTool = new XCAFDoc_AnimationTool(); - theLabel.AddAttribute(anAnimTool); - } - return anAnimTool; -} - -//======================================================================= -//function : Constructor -//purpose : -//======================================================================= -XCAFDoc_AnimationTool::XCAFDoc_AnimationTool() +XCAFAnimObjects_AnimObject::XCAFAnimObjects_AnimObject() : + myInterpolationType(XCAFAnimObjects_InterpolationType_Step) {} //======================================================================= -//function : ID +//function : XCAFAnimObjects_AnimObject //purpose : //======================================================================= -const Standard_GUID& XCAFDoc_AnimationTool::ID() const -{ - return GetID(); -} - -//======================================================================= -//function : BaseLabel -//purpose : -//======================================================================= -TDF_Label XCAFDoc_AnimationTool::BaseLabel() const -{ - return Label(); -} - -//======================================================================= -//function : Dump -//purpose : -//======================================================================= -Standard_OStream& XCAFDoc_AnimationTool::Dump(Standard_OStream& theOStream, - const Standard_Boolean theDepth) const -{ - (void)theOStream; - (void)theDepth; -} - -//======================================================================= -//function : Dump -//purpose : -//======================================================================= -Standard_OStream& XCAFDoc_AnimationTool::Dump(Standard_OStream& theDumpLog) const -{ - TDF_Attribute::Dump(theDumpLog); - Dump(theDumpLog, Standard_False); - return theDumpLog; -} - -//======================================================================= -//function : DumpJson -//purpose : -//======================================================================= -void XCAFDoc_AnimationTool::DumpJson(Standard_OStream& theOStream, - Standard_Integer theDepth) const -{ - (void)theOStream; - (void)theDepth; -} +XCAFAnimObjects_AnimObject::XCAFAnimObjects_AnimObject(const Handle(XCAFAnimObjects_AnimObject)& theObject) : + myInterpolationType(XCAFAnimObjects_InterpolationType_Step), + myOrderedOperations(theObject->myOrderedOperations) +{} diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_AnimObject.hxx b/src/XCAFAnimObjects/XCAFAnimObjects_AnimObject.hxx index 93a3dc1163..ea58f74be7 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_AnimObject.hxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_AnimObject.hxx @@ -11,73 +11,49 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifndef _XCAFDoc_AnimationTool_HeaderFile -#define _XCAFDoc_AnimationTool_HeaderFile +#ifndef _XCAFAnimObjects_AnimObject_HeaderFile +#define _XCAFAnimObjects_AnimObject_HeaderFile -#include +#include +#include +#include +#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +class XCAFAnimObjects_Operation; -class Standard_GUID; -class TDF_Label; -class TopoDS_Shape; -class TopLoc_Location; -class XCAFDoc_GraphNode; - -//! A tool to store shapes in an XDE -//! document in the form of assembly structure, and to maintain this structure. -//! Attribute containing Shapes section of DECAF document. -//! Provide tools for management of Shapes section. -//! The API provided by this class allows to work with this -//! structure regardless of its low-level implementation. -//! All the shapes are stored on child labels of a main label which is -//! XCAFDoc_DocumentTool::LabelShapes(). The label for assembly also has -//! sub-labels, each of which represents the instance of -//! another shape in that assembly (component). Such sub-label -//! stores reference to the label of the original shape in the form -//! of TDataStd_TreeNode with GUID XCAFDoc::ShapeRefGUID(), and its -//! location encapsulated into the NamedShape. -//! For correct work with an XDE document, it is necessary to use -//! methods for analysis and methods for working with shapes. -class XCAFDoc_AnimationTool : public TDataStd_GenericEmpty +//! +class XCAFAnimObjects_AnimObject : public Standard_Transient { +public: + DEFINE_STANDARD_RTTIEXT(XCAFAnimObjects_AnimObject, Standard_Transient) public: - Standard_EXPORT static const Standard_GUID& GetID(); - - //! Create (if not exist) ShapeTool from XCAFDoc on . - Standard_EXPORT static Handle(XCAFDoc_AnimationTool) Set (const TDF_Label& theLabel); - - //! Creates an empty tool - //! Creates a tool to work with a document - //! Attaches to label XCAFDoc::LabelShapes() - Standard_EXPORT XCAFDoc_AnimationTool(); - - //! returns the label under which shapes are stored - Standard_EXPORT TDF_Label BaseLabel() const; - - Standard_EXPORT Standard_OStream& Dump (Standard_OStream& theOStream, const Standard_Boolean theDepth) const; + //! + Standard_EXPORT XCAFAnimObjects_AnimObject(); - Standard_EXPORT virtual Standard_OStream& Dump (Standard_OStream& theOStream) const Standard_OVERRIDE; - - Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE; - - //! Dumps the content of me into the stream - Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE; + //! + Standard_EXPORT XCAFAnimObjects_AnimObject(const Handle(XCAFAnimObjects_AnimObject)& theObject); - DEFINE_DERIVED_ATTRIBUTE(XCAFDoc_AnimationTool,TDataStd_GenericEmpty) + //! + void AppendNewOperation(const Handle(XCAFAnimObjects_Operation)& theOperation) { myOrderedOperations.Append(theOperation); } + //! + XCAFAnimObjects_InterpolationType GetInterpolationType() const { return myInterpolationType; } + + //! + void SetInterpolationType(const XCAFAnimObjects_InterpolationType theType) { myInterpolationType = theType; } + + //! + const NCollection_List& GetOrderedOperations() const { return myOrderedOperations; } + + //! + NCollection_List& ChangeOrderedOperations() { return myOrderedOperations; } + +private: + + XCAFAnimObjects_InterpolationType myInterpolationType; + NCollection_List myOrderedOperations; }; -#endif // _XCAFDoc_AnimationTool_HeaderFile +#endif // _XCAFAnimObjects_AnimObject_HeaderFile diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_CustomOperation.cxx b/src/XCAFAnimObjects/XCAFAnimObjects_CustomOperation.cxx index 86be349ccb..8c0ca84586 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_CustomOperation.cxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_CustomOperation.cxx @@ -40,3 +40,13 @@ XCAFAnimObjects_CustomOperation::XCAFAnimObjects_CustomOperation(const NCollecti myTypeName(theCustomTypeName), myPresentation(thePresentation) {} + +//======================================================================= +//function : XCAFAnimObjects_CustomOperation +//purpose : +//======================================================================= +XCAFAnimObjects_CustomOperation::XCAFAnimObjects_CustomOperation(const Handle(XCAFAnimObjects_CustomOperation)& theOperation) : + XCAFAnimObjects_Operation(theOperation), + myTypeName(theOperation->myTypeName), + myPresentation(theOperation->myPresentation) +{} diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_CustomOperation.hxx b/src/XCAFAnimObjects/XCAFAnimObjects_CustomOperation.hxx index 9fe53c6632..0b9de85557 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_CustomOperation.hxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_CustomOperation.hxx @@ -32,6 +32,9 @@ public: const NCollection_Array1& theTimeStamps, const TCollection_AsciiString& theCustomTypeName); + //! + Standard_EXPORT XCAFAnimObjects_CustomOperation(const Handle(XCAFAnimObjects_CustomOperation)& theOperation); + //! XCAFAnimObjects_OperationType GetType() const Standard_OVERRIDE { return XCAFAnimObjects_OperationType_Custom; } diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_Operation.cxx b/src/XCAFAnimObjects/XCAFAnimObjects_Operation.cxx index 5bf1ee7b3c..b745640f8d 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_Operation.cxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_Operation.cxx @@ -13,6 +13,8 @@ #include +IMPLEMENT_STANDARD_RTTIEXT(XCAFAnimObjects_Operation, Standard_Transient) + //======================================================================= //function : XCAFAnimObjects_Operation //purpose : @@ -30,3 +32,12 @@ XCAFAnimObjects_Operation::XCAFAnimObjects_Operation(const NCollection_Array1myIsInverse), + myTimeStamps(theOperation->myTimeStamps) +{} diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_Operation.hxx b/src/XCAFAnimObjects/XCAFAnimObjects_Operation.hxx index a550b46708..6ffc4de710 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_Operation.hxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_Operation.hxx @@ -14,13 +14,15 @@ #ifndef _XCAFAnimObjects_Operation_HeaderFile #define _XCAFAnimObjects_Operation_HeaderFile +#include +#include #include #include #include #include //! -class XCAFAnimObjects_Operation +class XCAFAnimObjects_Operation : public Standard_Transient { public: @@ -31,6 +33,9 @@ public: Standard_EXPORT XCAFAnimObjects_Operation(const NCollection_Array1& theTimeStamps, const bool theIsInverse = false); + //! + Standard_EXPORT XCAFAnimObjects_Operation(const Handle(XCAFAnimObjects_Operation)& theOperation); + //! const NCollection_Array1& TimeStamps() const { return myTimeStamps; } @@ -52,6 +57,8 @@ public: //! Standard_EXPORT virtual NCollection_Array2 GeneralPresentation() const = 0; + DEFINE_STANDARD_RTTIEXT(XCAFAnimObjects_Operation, Standard_Transient) + private: bool myIsInverse; //! NCollection_Array1 myTimeStamps; //!< diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_Orient.cxx b/src/XCAFAnimObjects/XCAFAnimObjects_Orient.cxx index 1a36a7b707..9375fa9236 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_Orient.cxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_Orient.cxx @@ -61,6 +61,15 @@ XCAFAnimObjects_Orient::XCAFAnimObjects_Orient(const NCollection_Array2& } } +//======================================================================= +//function : XCAFAnimObjects_Orient +//purpose : +//======================================================================= +XCAFAnimObjects_Orient::XCAFAnimObjects_Orient(const Handle(XCAFAnimObjects_Orient)& theOperation) : + XCAFAnimObjects_Operation(theOperation), + myOrientPresentation(theOperation->myOrientPresentation) +{} + //======================================================================= //function : GeneralPresentation //purpose : diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_Orient.hxx b/src/XCAFAnimObjects/XCAFAnimObjects_Orient.hxx index 7549ba2651..98993f46c8 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_Orient.hxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_Orient.hxx @@ -33,6 +33,9 @@ public: Standard_EXPORT XCAFAnimObjects_Orient(const NCollection_Array2& theGeneralPresentation, const NCollection_Array1& theTimeStamps); + //! + Standard_EXPORT XCAFAnimObjects_Orient(const Handle(XCAFAnimObjects_Orient)& theOperation); + //! XCAFAnimObjects_OperationType GetType() const Standard_OVERRIDE { return XCAFAnimObjects_OperationType_Orient; } diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_Rotate.cxx b/src/XCAFAnimObjects/XCAFAnimObjects_Rotate.cxx index 7a7c85ac9e..f6c2d89737 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_Rotate.cxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_Rotate.cxx @@ -19,80 +19,68 @@ //function : XCAFAnimObjects_Rotate //purpose : //======================================================================= -XCAFAnimObjects_Rotate::XCAFAnimObjects_Rotate(const gp_Quaternion& theRotate) : +XCAFAnimObjects_Rotate::XCAFAnimObjects_Rotate(const NCollection_Array1& theRotate, + const NCollection_Array1& theTimeStamps, + const XCAFAnimObjects_Rotate_Type theRotateType) : XCAFAnimObjects_Operation(false), - myRotatePresentation(1, 1) + myRotateType(theRotateType), + myRotatePresentation(1, 1, theRotate.Lower(), theRotate.Upper()) { - myRotatePresentation.SetValue(1, theRotate); + for (int anInd = theRotate.Lower(); anInd <= theRotate.Upper(); anInd++) + { + myRotatePresentation.SetValue(1, anInd, theRotate.Value(anInd)); + } + Standard_Integer aNbDouble = 3; + if (theRotateType >= XCAFAnimObjects_Rotate_Type_XY && + theRotateType <= XCAFAnimObjects_Rotate_Type_ZY) + { + aNbDouble = 2; + } + if (theRotateType >= XCAFAnimObjects_Rotate_Type_X && + theRotateType <= XCAFAnimObjects_Rotate_Type_Z) + { + aNbDouble = 1; + } + if (theRotate.Length() != aNbDouble) + { + Message::SendWarning() << "Warning: XCAFAnimObjects_Rotate: Incorrect Rotate presentation"; + } } -//======================================================================= -//function : XCAFAnimObjects_Rotate -//purpose : -//======================================================================= -XCAFAnimObjects_Rotate::XCAFAnimObjects_Rotate(const gp_XYZ& theRotate) : - XCAFAnimObjects_Operation(false), - myRotatePresentation(1, 1) -{ - // Convert angles from degrees to radians and create quaternions for each rotation. - gp_Quaternion aQuaternionX(gp_Dir(1, 0, 0), theRotate.X() * M_PI / 180.0); - gp_Quaternion aQuaternionY(gp_Dir(0, 1, 0), theRotate.Y() * M_PI / 180.0); - gp_Quaternion aQuaternionZ(gp_Dir(0, 0, 1), theRotate.Z() * M_PI / 180.0); - - // Combine the rotations. The order depends on the rotation order in the original Euler angles. - gp_Quaternion aCombinedQuaternion = aQuaternionX * aQuaternionY * aQuaternionZ; - - myRotatePresentation.SetValue(1, aCombinedQuaternion); -} - -//======================================================================= -//function : XCAFAnimObjects_Rotate -//purpose : -//======================================================================= -XCAFAnimObjects_Rotate::XCAFAnimObjects_Rotate(const NCollection_Array1& theRotate, - const NCollection_Array1& theTimeStamps) : - XCAFAnimObjects_Operation(theTimeStamps), - myRotatePresentation(theRotate) -{} - //======================================================================= //function : XCAFAnimObjects_Rotate //purpose : //======================================================================= XCAFAnimObjects_Rotate::XCAFAnimObjects_Rotate(const NCollection_Array2& theGeneralPresentation, - const NCollection_Array1& theTimeStamps) : + const NCollection_Array1& theTimeStamps, + const XCAFAnimObjects_Rotate_Type theRotateType) : XCAFAnimObjects_Operation(false), - myRotatePresentation(1, theGeneralPresentation.RowLength()) + myRotateType(theRotateType), + myRotatePresentation(theGeneralPresentation) { - if (theGeneralPresentation.ColLength() != 4) + Standard_Integer aNbDouble = 3; + if (theRotateType >= XCAFAnimObjects_Rotate_Type_XY && + theRotateType <= XCAFAnimObjects_Rotate_Type_ZY) { - Message::SendWarning() << "Warning: XCAFAnimObjects_Rotate: Incorrect Quaternion general presentation"; - return; + aNbDouble = 2; } - for (int aRowInd = 1; aRowInd <= theGeneralPresentation.RowLength(); aRowInd++) + if (theRotateType >= XCAFAnimObjects_Rotate_Type_X && + theRotateType <= XCAFAnimObjects_Rotate_Type_Z) { - gp_Quaternion aQuat(theGeneralPresentation.Value(aRowInd, 1), - theGeneralPresentation.Value(aRowInd, 2), - theGeneralPresentation.Value(aRowInd, 3), - theGeneralPresentation.Value(aRowInd, 4)); - myRotatePresentation.SetValue(aRowInd, aQuat); + aNbDouble = 1; + } + if (theGeneralPresentation.ColLength() != aNbDouble) + { + Message::SendWarning() << "Warning: XCAFAnimObjects_Rotate: Incorrect Rotate presentation"; } } //======================================================================= -//function : GeneralPresentation +//function : XCAFAnimObjects_Rotate //purpose : //======================================================================= -NCollection_Array2 XCAFAnimObjects_Rotate::GeneralPresentation() const -{ - NCollection_Array2 aRes(1, myRotatePresentation.Length(), 1, 4); - for (int aRowInd = 1; aRowInd <= myRotatePresentation.Length(); aRowInd++) - { - const gp_Quaternion& aQuat = myRotatePresentation.Value(aRowInd); - - aRes.SetValue(aRowInd, 1, aQuat.X()); - aRes.SetValue(aRowInd, 2, aQuat.Y()); - aRes.SetValue(aRowInd, 3, aQuat.Z()); - aRes.SetValue(aRowInd, 4, aQuat.W()); - } -} +XCAFAnimObjects_Rotate::XCAFAnimObjects_Rotate(const Handle(XCAFAnimObjects_Rotate)& theOperation) : + XCAFAnimObjects_Operation(theOperation), + myRotateType(theOperation->myRotateType), + myRotatePresentation(theOperation->myRotatePresentation) +{} diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_Rotate.hxx b/src/XCAFAnimObjects/XCAFAnimObjects_Rotate.hxx index e7483dd366..70b4610ead 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_Rotate.hxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_Rotate.hxx @@ -23,34 +23,62 @@ class XCAFAnimObjects_Rotate : public XCAFAnimObjects_Operation public: //! - Standard_EXPORT XCAFAnimObjects_Rotate(const gp_Quaternion& theRotate); + enum XCAFAnimObjects_Rotate_Type + { + XCAFAnimObjects_Rotate_Type_XYZ = 0, + XCAFAnimObjects_Rotate_Type_XZY, + XCAFAnimObjects_Rotate_Type_YZX, + XCAFAnimObjects_Rotate_Type_YXZ, + XCAFAnimObjects_Rotate_Type_ZXY, + XCAFAnimObjects_Rotate_Type_ZYX, + XCAFAnimObjects_Rotate_Type_XY, + XCAFAnimObjects_Rotate_Type_XZ, + XCAFAnimObjects_Rotate_Type_YX, + XCAFAnimObjects_Rotate_Type_YZ, + XCAFAnimObjects_Rotate_Type_ZX, + XCAFAnimObjects_Rotate_Type_ZY, + XCAFAnimObjects_Rotate_Type_X, + XCAFAnimObjects_Rotate_Type_Y, + XCAFAnimObjects_Rotate_Type_Z + }; + +public: //! - Standard_EXPORT XCAFAnimObjects_Rotate(const gp_XYZ& theRotate); - - //! - Standard_EXPORT XCAFAnimObjects_Rotate(const NCollection_Array1& theRotate, - const NCollection_Array1& theTimeStamps); + Standard_EXPORT XCAFAnimObjects_Rotate(const NCollection_Array1& theRotate, + const NCollection_Array1& theTimeStamps, + const XCAFAnimObjects_Rotate_Type theRotateType = XCAFAnimObjects_Rotate_Type_XYZ); //! Standard_EXPORT XCAFAnimObjects_Rotate(const NCollection_Array2& theGeneralPresentation, - const NCollection_Array1& theTimeStamps); + const NCollection_Array1& theTimeStamps, + const XCAFAnimObjects_Rotate_Type theRotateType = XCAFAnimObjects_Rotate_Type_XYZ); + + //! + Standard_EXPORT XCAFAnimObjects_Rotate(const Handle(XCAFAnimObjects_Rotate)& theOperation); //! XCAFAnimObjects_OperationType GetType() const Standard_OVERRIDE { return XCAFAnimObjects_OperationType_Rotate; } + //! + XCAFAnimObjects_Rotate_Type GetRotateType() const { return myRotateType; } + + //! + void SetRotateType(const XCAFAnimObjects_Rotate_Type theRotateType) { myRotateType = theRotateType; } + //! TCollection_AsciiString GetTypeName() const Standard_OVERRIDE { return "Rotate"; } //! - Standard_EXPORT NCollection_Array2 GeneralPresentation() const Standard_OVERRIDE; + NCollection_Array2 GeneralPresentation() const { return myRotatePresentation; } //! - const NCollection_Array1& RotatePresentation() const { return myRotatePresentation; } + const NCollection_Array2& RotatePresentation() const { return myRotatePresentation; } private: - NCollection_Array1 myRotatePresentation; //!< + XCAFAnimObjects_Rotate_Type myRotateType; //!< + NCollection_Array2 myRotatePresentation; //!< }; #endif // _XCAFAnimObjects_Rotate_HeaderFile diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_Scale.cxx b/src/XCAFAnimObjects/XCAFAnimObjects_Scale.cxx index 0a4e61d17d..56903d97ac 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_Scale.cxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_Scale.cxx @@ -59,6 +59,15 @@ XCAFAnimObjects_Scale::XCAFAnimObjects_Scale(const NCollection_Array2& t } } +//======================================================================= +//function : XCAFAnimObjects_Scale +//purpose : +//======================================================================= +XCAFAnimObjects_Scale::XCAFAnimObjects_Scale(const Handle(XCAFAnimObjects_Scale)& theOperation) : + XCAFAnimObjects_Operation(theOperation), + myScalePresentation(theOperation->myScalePresentation) +{} + //======================================================================= //function : GeneralPresentation //purpose : diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_Scale.hxx b/src/XCAFAnimObjects/XCAFAnimObjects_Scale.hxx index 9e4250349e..05ca6d1e5a 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_Scale.hxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_Scale.hxx @@ -33,6 +33,9 @@ public: Standard_EXPORT XCAFAnimObjects_Scale(const NCollection_Array2& theGeneralPresentation, const NCollection_Array1& theTimeStamps); + //! + Standard_EXPORT XCAFAnimObjects_Scale(const Handle(XCAFAnimObjects_Scale)& theOperation); + //! XCAFAnimObjects_OperationType GetType() const Standard_OVERRIDE { return XCAFAnimObjects_OperationType_Scale; } diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_Skew.cxx b/src/XCAFAnimObjects/XCAFAnimObjects_Skew.cxx index 09a8586f62..694927f92c 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_Skew.cxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_Skew.cxx @@ -63,6 +63,15 @@ XCAFAnimObjects_Skew::XCAFAnimObjects_Skew(const NCollection_Array2& the } } +//======================================================================= +//function : XCAFAnimObjects_Skew +//purpose : +//======================================================================= +XCAFAnimObjects_Skew::XCAFAnimObjects_Skew(const Handle(XCAFAnimObjects_Skew)& theOperation) : + XCAFAnimObjects_Operation(theOperation), + mySkewPresentation(theOperation->mySkewPresentation) +{} + //======================================================================= //function : GeneralPresentation //purpose : diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_Skew.hxx b/src/XCAFAnimObjects/XCAFAnimObjects_Skew.hxx index b08728874c..844c6794ed 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_Skew.hxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_Skew.hxx @@ -42,6 +42,9 @@ public: Standard_EXPORT XCAFAnimObjects_Skew(const NCollection_Array2& theGeneralPresentation, const NCollection_Array1& theTimeStamps); + //! + Standard_EXPORT XCAFAnimObjects_Skew(const Handle(XCAFAnimObjects_Skew)& theOperation); + //! XCAFAnimObjects_OperationType GetType() const Standard_OVERRIDE { return XCAFAnimObjects_OperationType_Skew; } diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_Transform.cxx b/src/XCAFAnimObjects/XCAFAnimObjects_Transform.cxx index ca0e5d3c05..e14ae4f02d 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_Transform.cxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_Transform.cxx @@ -74,6 +74,15 @@ XCAFAnimObjects_Transform::XCAFAnimObjects_Transform(const NCollection_Array2myTransformPresentation) +{} + //======================================================================= //function : GeneralPresentation //purpose : diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_Transform.hxx b/src/XCAFAnimObjects/XCAFAnimObjects_Transform.hxx index c23b54e35e..53aa252bbf 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_Transform.hxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_Transform.hxx @@ -33,6 +33,9 @@ public: Standard_EXPORT XCAFAnimObjects_Transform(const NCollection_Array2& theGeneralPresentation, const NCollection_Array1& theTimeStamps); + //! + Standard_EXPORT XCAFAnimObjects_Transform(const Handle(XCAFAnimObjects_Transform)& theOperation); + //! XCAFAnimObjects_OperationType GetType() const Standard_OVERRIDE { return XCAFAnimObjects_OperationType_Transform; } diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_Translate.cxx b/src/XCAFAnimObjects/XCAFAnimObjects_Translate.cxx index d5484eabbb..8a001f38de 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_Translate.cxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_Translate.cxx @@ -60,6 +60,15 @@ XCAFAnimObjects_Translate::XCAFAnimObjects_Translate(const NCollection_Array2myTranslatePresentation) +{} + //======================================================================= //function : GeneralPresentation //purpose : diff --git a/src/XCAFAnimObjects/XCAFAnimObjects_Translate.hxx b/src/XCAFAnimObjects/XCAFAnimObjects_Translate.hxx index 3988505fec..4d43d140ec 100644 --- a/src/XCAFAnimObjects/XCAFAnimObjects_Translate.hxx +++ b/src/XCAFAnimObjects/XCAFAnimObjects_Translate.hxx @@ -33,6 +33,9 @@ public: Standard_EXPORT XCAFAnimObjects_Translate(const NCollection_Array2& theGeneralPresentation, const NCollection_Array1& theTimeStamps); + //! + Standard_EXPORT XCAFAnimObjects_Translate(const Handle(XCAFAnimObjects_Translate)& theOperation); + //! XCAFAnimObjects_OperationType GetType() const Standard_OVERRIDE { return XCAFAnimObjects_OperationType_Translate; } diff --git a/src/XCAFDoc/XCAFDoc.cxx b/src/XCAFDoc/XCAFDoc.cxx index 9faf73353c..d39cea97f2 100644 --- a/src/XCAFDoc/XCAFDoc.cxx +++ b/src/XCAFDoc/XCAFDoc.cxx @@ -322,6 +322,16 @@ const Standard_GUID& XCAFDoc::LockGUID() return ID; } +//======================================================================= +//function : AnimRefShapeGUID +//purpose : +//======================================================================= +const Standard_GUID& XCAFDoc::AnimRefShapeGUID() +{ + static const Standard_GUID ID("0BE692B6-2E38-4FDC-A349-27615CF8784F"); + return ID; +} + //======================================================================= //function : AttributeInfo //purpose : diff --git a/src/XCAFDoc/XCAFDoc.hxx b/src/XCAFDoc/XCAFDoc.hxx index 442c060ac0..5ee9ab4552 100644 --- a/src/XCAFDoc/XCAFDoc.hxx +++ b/src/XCAFDoc/XCAFDoc.hxx @@ -114,6 +114,9 @@ public: //! Returns GUID for UAttribute identifying lock flag Standard_EXPORT static const Standard_GUID& LockGUID(); + //! Return GUIDs for TreeNode representing connections Animation-Shape + Standard_EXPORT static const Standard_GUID& AnimRefShapeGUID(); + //! Prints attribute information into a string. //! @param theAtt an XDE attribute //! @return the generated info value diff --git a/src/XCAFDoc/XCAFDoc_Animation.cxx b/src/XCAFDoc/XCAFDoc_Animation.cxx index b82722b8a2..d5ad8aac77 100644 --- a/src/XCAFDoc/XCAFDoc_Animation.cxx +++ b/src/XCAFDoc/XCAFDoc_Animation.cxx @@ -13,92 +13,384 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include IMPLEMENT_DERIVED_ATTRIBUTE(XCAFDoc_Animation, TDataStd_GenericEmpty) -enum ChildLab -{ - ChildLab_Begin = 1, - ChildLab_Type = ChildLab_Begin, - ChildLab_End -}; - -//======================================================================= -//function : XCAFDoc_Animation -//purpose : -//======================================================================= -XCAFDoc_Animation::XCAFDoc_Animation() +namespace { + //======================================================================= + //function : AnimRotateRefGUID + //purpose : + //======================================================================= + const Standard_GUID& AnimRotateRefGUID() + { + static const Standard_GUID ID("09135874-3B7E-4379-8BDB-E781422B8DD7"); + return ID; + } + + //======================================================================= + //function : AnimCustomRefGUID + //purpose : + //======================================================================= + const Standard_GUID& AnimCustomRefGUID() + { + static const Standard_GUID ID("1D0BC396-328D-45CC-B968-FD58DB7109A0"); + return ID; + } + + //======================================================================= + //function : AnimOrientRefGUID + //purpose : + //======================================================================= + const Standard_GUID& AnimOrientRefGUID() + { + static const Standard_GUID ID("F601BE38-D3F8-4594-90C8-04B790ACD08A"); + return ID; + } + + //======================================================================= + //function : AnimScaleRefGUID + //purpose : + //======================================================================= + const Standard_GUID& AnimScaleRefGUID() + { + static const Standard_GUID ID("40602308-A430-4912-A480-66DF8788338B"); + return ID; + } + + //======================================================================= + //function : AnimSkewRefGUID + //purpose : + //======================================================================= + const Standard_GUID& AnimSkewRefGUID() + { + static const Standard_GUID ID("9A260C95-B2D6-472D-AEB4-D802C7528FEE"); + return ID; + } + + //======================================================================= + //function : AnimTransformRefGUID + //purpose : + //======================================================================= + const Standard_GUID& AnimTransformRefGUID() + { + static const Standard_GUID ID("F26898A6-C7A8-4FC8-B328-4B442F935E7A"); + return ID; + } + + //======================================================================= + //function : AnimTranslateRefGUID + //purpose : + //======================================================================= + const Standard_GUID& AnimTranslateRefGUID() + { + static const Standard_GUID ID("A8777A51-B13E-417A-82A0-6176246DD441"); + return ID; + } + + //======================================================================= + //function : AnimInterpolationRefGUID + //purpose : + //======================================================================= + const Standard_GUID& AnimInterpolationRefGUID() + { + static const Standard_GUID ID("4C565EBB-70C2-4934-B451-0B45C3460412"); + return ID; + } + + //======================================================================= + //function : AnimInvertRefGUID + //purpose : + //======================================================================= + const Standard_GUID& AnimInvertRefGUID() + { + static const Standard_GUID ID("7898D79A-6CCE-434C-A494-A37FC1931CC2"); + return ID; + } + + //======================================================================= + //function : AnimInvertRefGUID + //purpose : + //======================================================================= + const Standard_GUID& AnimValuesDimensionGUID() + { + static const Standard_GUID ID("95CBDC47-5A79-4229-9851-B6F04EAEE482"); + return ID; + } + + //======================================================================= + //function : AnimValuesGUID + //purpose : + //======================================================================= + const Standard_GUID& AnimValuesGUID() + { + static const Standard_GUID ID("C3CDFA73-1C9B-4674-BCAA-D1B7038AFE86"); + return ID; + } + + //======================================================================= + //function : AnimValuesGUID + //purpose : + //======================================================================= + const Standard_GUID& AnimTimeStampsValuesGUID() + { + static const Standard_GUID ID("AAF6F1A2-F764-4A4B-8984-BF7CF09B7646"); + return ID; + } + + //======================================================================= + //function : AnimValuesGUID + //purpose : + //======================================================================= + const Standard_GUID& AnimRotateSubTypeGUID() + { + static const Standard_GUID ID("A1E22D67-CD3E-4F8D-BD75-1DF04EF45266"); + return ID; + } } +//======================================================================= +//function : XCAFDoc_Animation +//purpose : +//======================================================================= +XCAFDoc_Animation::XCAFDoc_Animation() +{} + //======================================================================= //function : GetID -//purpose : +//purpose : //======================================================================= const Standard_GUID& XCAFDoc_Animation::GetID() { - static Standard_GUID DGTID("58ed092c-44de-11d8-8776-001083004c77"); - //static Standard_GUID ID("efd212e9-6dfd-11d4-b9c8-0060b0ee281b"); + static Standard_GUID DGTID("D755686B-872E-421E-8871-E98BE8051644"); return DGTID; - //return ID; } //======================================================================= //function : Set -//purpose : +//purpose : //======================================================================= Handle(XCAFDoc_Animation) XCAFDoc_Animation::Set(const TDF_Label& theLabel) { - Handle(XCAFDoc_Animation) A; - if (!theLabel.FindAttribute(XCAFDoc_Animation::GetID(), A)) { - A = new XCAFDoc_Animation(); - theLabel.AddAttribute(A); + Handle(XCAFDoc_Animation) anAnimAttr; + if (!theLabel.FindAttribute(XCAFDoc_Animation::GetID(), anAnimAttr)) { + anAnimAttr = new XCAFDoc_Animation(); + theLabel.AddAttribute(anAnimAttr); } - return A; + return anAnimAttr; } //======================================================================= //function : SetObject -//purpose : +//purpose : //======================================================================= void XCAFDoc_Animation::SetObject(const Handle(XCAFAnimObjects_AnimObject)& theObject) { Backup(); + // Setting name + const static TCollection_ExtendedString anObjName("Animation"); + TDataStd_Name::Set(Label(), anObjName); + + // Setting Interpolation type + TDataStd_Integer::Set(Label(), AnimInterpolationRefGUID(), theObject->GetInterpolationType()); + + Standard_Integer anOperInd = 1; + // Setting ordered operations + for (NCollection_List::Iterator anIter(theObject->GetOrderedOperations()); + anIter.More(); anIter.Next(), anOperInd++) + { + const TDF_Label aChild = Label().FindChild(anOperInd, true); + aChild.ForgetAllAttributes(); // Clear old values + + const Handle(XCAFAnimObjects_Operation)& anOperation = anIter.Value(); + // Setting inverse flag + if (anOperation->IsInverse()) + { + TDataStd_UAttribute::Set(aChild, AnimInvertRefGUID()); + } + // Setting operation type and name + TDataStd_Name::Set(aChild, anOperation->GetTypeName()); + switch (anOperation->GetType()) + { + case XCAFAnimObjects_OperationType_Custom: + TDataStd_UAttribute::Set(aChild, AnimCustomRefGUID()); + break; + case XCAFAnimObjects_OperationType_Orient: + TDataStd_UAttribute::Set(aChild, AnimOrientRefGUID()); + break; + case XCAFAnimObjects_OperationType_Rotate: + { + TDataStd_UAttribute::Set(aChild, AnimRotateRefGUID()); + const Handle(XCAFAnimObjects_Rotate) aRotate = Handle(XCAFAnimObjects_Rotate)::DownCast(anOperation); + TDataStd_Integer::Set(aChild, AnimRotateSubTypeGUID(), aRotate->GetRotateType()); + break; + } + case XCAFAnimObjects_OperationType_Scale: + TDataStd_UAttribute::Set(aChild, AnimScaleRefGUID()); + break; + case XCAFAnimObjects_OperationType_Skew: + TDataStd_UAttribute::Set(aChild, AnimSkewRefGUID()); + break; + case XCAFAnimObjects_OperationType_Transform: + TDataStd_UAttribute::Set(aChild, AnimTransformRefGUID()); + break; + case XCAFAnimObjects_OperationType_Translate: + TDataStd_UAttribute::Set(aChild, AnimTranslateRefGUID()); + break; + } + // Setting operation values + const NCollection_Array2 anOperPresentation = anOperation->GeneralPresentation(); + Handle(TDataStd_IntegerArray) aDimArr = TDataStd_IntegerArray::Set(aChild, AnimValuesDimensionGUID(), 1, 2); + aDimArr->SetValue(1, anOperPresentation.RowLength()); + aDimArr->SetValue(2, anOperPresentation.ColLength()); + const int aNbValues = anOperPresentation.Length(); + Handle(TDataStd_RealArray) aValuesArr = TDataStd_RealArray::Set(aChild, AnimValuesGUID(), 1, aNbValues); + int anOperValueInd = 1; + for (NCollection_Array2::Iterator aOperValIter(anOperPresentation); + aOperValIter.More(); aOperValIter.Next()) + { + aValuesArr->SetValue(anOperValueInd++, aOperValIter.Value()); + } + if (anOperation->HasTimeStamps()) + { + const NCollection_Array1& aTimeStamps = anOperation->TimeStamps(); + Handle(TDataStd_RealArray) aTimeStampsAttr = + TDataStd_RealArray::Set(aChild, AnimTimeStampsValuesGUID(), aTimeStamps.Lower(), aTimeStamps.Upper()); + for (int aTimeStampInd = 1; aTimeStampInd <= aTimeStamps.Length(); aTimeStampInd++) + { + aTimeStampsAttr->SetValue(aTimeStampInd, aTimeStamps.Value(aTimeStampInd)); + } + } + } } //======================================================================= //function : GetObject -//purpose : +//purpose : //======================================================================= Handle(XCAFAnimObjects_AnimObject) XCAFDoc_Animation::GetObject() const { Handle(XCAFAnimObjects_AnimObject) anObj = new XCAFAnimObjects_AnimObject(); - + Handle(TDataStd_Integer) anIntType; + if (Label().FindAttribute(AnimInterpolationRefGUID(), anIntType)) + { + const XCAFAnimObjects_InterpolationType aType = + static_cast(anIntType->Get()); + anObj->SetInterpolationType(aType); + } + NCollection_List anOrderedOperations; + for (TDF_ChildIterator aChildIterator(Label()); + aChildIterator.More(); aChildIterator.Next()) + { + const TDF_Label& anOperL = aChildIterator.Value(); + XCAFAnimObjects_OperationType anOperType = XCAFAnimObjects_OperationType_Custom; + Handle(TDataStd_UAttribute) anOperTypeAttr; + if (anOperL.FindAttribute(AnimCustomRefGUID(), anOperTypeAttr)) + { + anOperType = XCAFAnimObjects_OperationType_Custom; + } + else if (anOperL.FindAttribute(AnimOrientRefGUID(), anOperTypeAttr)) + { + anOperType = XCAFAnimObjects_OperationType_Orient; + } + else if (anOperL.FindAttribute(AnimRotateRefGUID(), anOperTypeAttr)) + { + anOperType = XCAFAnimObjects_OperationType_Rotate; + } + else if (anOperL.FindAttribute(AnimScaleRefGUID(), anOperTypeAttr)) + { + anOperType = XCAFAnimObjects_OperationType_Scale; + } + else if (anOperL.FindAttribute(AnimSkewRefGUID(), anOperTypeAttr)) + { + anOperType = XCAFAnimObjects_OperationType_Skew; + } + else if (anOperL.FindAttribute(AnimTransformRefGUID(), anOperTypeAttr)) + { + anOperType = XCAFAnimObjects_OperationType_Transform; + } + else if (anOperL.FindAttribute(AnimTranslateRefGUID(), anOperTypeAttr)) + { + anOperType = XCAFAnimObjects_OperationType_Translate; + } + if (anOperTypeAttr.IsNull()) + { + continue; + } + Handle(TDataStd_IntegerArray) aDimArr; + if (!anOperL.FindAttribute(AnimValuesDimensionGUID(), aDimArr)) + { + continue; + } + Handle(TDataStd_RealArray) aTimeStampsAttr; + anOperL.FindAttribute(AnimTimeStampsValuesGUID(), aTimeStampsAttr); + Handle(TDataStd_UAttribute) anInvertAttr; + const bool anIsInvert = anOperL.FindAttribute(AnimInvertRefGUID(), anInvertAttr); + Handle(XCAFAnimObjects_Operation) aNewOperObj; + switch (anOperType) + { + case XCAFAnimObjects_OperationType_Custom: + { + Handle(TDataStd_Name) aOperNameAttr; + if (!anOperL.FindAttribute(TDataStd_Name::GetID(), aOperNameAttr)) + { + continue; + } + TCollection_AsciiString aOperName = aOperNameAttr->Get(); + break; + } + case XCAFAnimObjects_OperationType_Orient: + { + break; + } + case XCAFAnimObjects_OperationType_Rotate: + { + Handle(TDataStd_Integer) aRotateTypeAttr; + if (!anOperL.FindAttribute(AnimRotateSubTypeGUID(), aRotateTypeAttr)) + { + continue; + } + const XCAFAnimObjects_Rotate::XCAFAnimObjects_Rotate_Type aRotateType = + static_cast(aRotateTypeAttr->Get()); + break; + } + case XCAFAnimObjects_OperationType_Scale: + { + break; + } + case XCAFAnimObjects_OperationType_Skew: + { + break; + } + case XCAFAnimObjects_OperationType_Transform: + { + break; + } + case XCAFAnimObjects_OperationType_Translate: + { + break; + } + } + } return anObj; } //======================================================================= //function : ID -//purpose : +//purpose : //======================================================================= - const Standard_GUID& XCAFDoc_Animation::ID() const { return GetID(); @@ -110,5 +402,6 @@ const Standard_GUID& XCAFDoc_Animation::ID() const //======================================================================= void XCAFDoc_Animation::DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth) const { - + (void)theOStream; + (void)theDepth; } diff --git a/src/XCAFDoc/XCAFDoc_AnimationTool.cxx b/src/XCAFDoc/XCAFDoc_AnimationTool.cxx index 81462a47a4..6f6927a6fa 100644 --- a/src/XCAFDoc/XCAFDoc_AnimationTool.cxx +++ b/src/XCAFDoc/XCAFDoc_AnimationTool.cxx @@ -13,50 +13,39 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include +#include #include -#include -#include +#include +#include +#include > IMPLEMENT_DERIVED_ATTRIBUTE_WITH_TYPE(XCAFDoc_AnimationTool, TDataStd_GenericEmpty, "xcaf", "AnimationTool") +namespace +{ + //======================================================================= + //function : GetGlobalFPSGUID + //purpose : + //======================================================================= + const Standard_GUID& GetGlobalFPSGUID() + { + static Standard_GUID aGlobalFPSID("C7E7AF70-2FB3-40FD-BD38-CC79D9343D7A"); + return aGlobalFPSID; + } +} + //======================================================================= //function : GetID //purpose : //======================================================================= const Standard_GUID& XCAFDoc_AnimationTool::GetID() { - static Standard_GUID ShapeToolID("9E9914DD-154A-4E17-B89B-3E33CCF67BD0"); - return ShapeToolID; + static Standard_GUID anAnimationToolID("9E9914DD-154A-4E17-B89B-3E33CCF67BD0"); + return anAnimationToolID; } //======================================================================= @@ -66,7 +55,8 @@ const Standard_GUID& XCAFDoc_AnimationTool::GetID() Handle(XCAFDoc_AnimationTool) XCAFDoc_AnimationTool::Set(const TDF_Label& theLabel) { Handle(XCAFDoc_AnimationTool) anAnimTool; - if (!theLabel.FindAttribute(XCAFDoc_AnimationTool::GetID(), anAnimTool)) { + if (!theLabel.FindAttribute(XCAFDoc_AnimationTool::GetID(), anAnimTool)) + { anAnimTool = new XCAFDoc_AnimationTool(); theLabel.AddAttribute(anAnimTool); } @@ -98,12 +88,166 @@ TDF_Label XCAFDoc_AnimationTool::BaseLabel() const return Label(); } +//======================================================================= +//function : IsAnimation +//purpose : +//======================================================================= +bool XCAFDoc_AnimationTool::IsAnimation(const TDF_Label& theLabel) const +{ + Handle(XCAFDoc_Animation) anAnimAtr; + if (theLabel.FindAttribute(XCAFDoc_Animation::GetID(), anAnimAtr)) + { + return true; + } + return false; +} + +//======================================================================= +//function : SetAnimation +//purpose : +//======================================================================= +void XCAFDoc_AnimationTool::SetAnimation(const TDF_Label& theShLabel, + const TDF_Label& theAnimLabel) const +{ + // set reference + Handle(TDataStd_TreeNode) aRefNode, aMainNode; + aMainNode = TDataStd_TreeNode::Set(theAnimLabel, XCAFDoc::AnimRefShapeGUID()); + aRefNode = TDataStd_TreeNode::Set(theShLabel, XCAFDoc::AnimRefShapeGUID()); + aRefNode->Remove(); + aMainNode->Prepend(aRefNode); +} + +//======================================================================= +//function : GetGlobalFPS +//purpose : +//======================================================================= +bool XCAFDoc_AnimationTool::GetGlobalFPS(double& theFPS) const +{ + Handle(TDataStd_Real) aFPSAttr; + if (BaseLabel().FindAttribute(GetGlobalFPSGUID(), aFPSAttr)) + { + theFPS = aFPSAttr->Get(); + return true; + } + return false; +} + +//======================================================================= +//function : SetGlobalFPS +//purpose : +//======================================================================= +void XCAFDoc_AnimationTool::SetGlobalFPS(const double theFPS) const +{ + Handle(TDataStd_Real) aFPSAttr; + if (BaseLabel().FindAttribute(GetGlobalFPSGUID(), aFPSAttr)) + { + aFPSAttr->Set(theFPS); + return; + } + TDataStd_Real::Set(BaseLabel(), GetGlobalFPSGUID(), theFPS); +} + +//======================================================================= +//function : GetAnimationLabels +//purpose : +//======================================================================= +void XCAFDoc_AnimationTool::GetAnimationLabels(TDF_LabelSequence& theLabels) const +{ + theLabels.Clear(); + for (TDF_ChildIterator aChildIterator(Label()); + aChildIterator.More(); aChildIterator.Next()) + { + TDF_Label aL = aChildIterator.Value(); + if (IsAnimation(aL)) + { + theLabels.Append(aL); + } + } +} + +//======================================================================= +//function : GetRefAnimationLabels +//purpose : +//======================================================================= +bool XCAFDoc_AnimationTool::GetRefAnimationLabel(const TDF_Label& theShLabel, + TDF_Label& theAnimLabel) const +{ + Handle(TDataStd_TreeNode) aNode; + if (!theShLabel.FindAttribute(XCAFDoc::AnimRefShapeGUID(), aNode) || + !aNode->HasFather()) + { + return false; + } + theAnimLabel = aNode->Father()->Label(); + return true; +} + +//======================================================================= +//function : GetRefShapeLabel +//purpose : +//======================================================================= +bool XCAFDoc_AnimationTool::GetRefShapeLabel(const TDF_Label& theAnimLabel, + TDF_Label& theShLabel) const +{ + Handle(TDataStd_TreeNode) aNode; + if (!theAnimLabel.FindAttribute(XCAFDoc::AnimRefShapeGUID(), aNode) || + !aNode->Label().IsNull()) + { + return false; + } + theShLabel = aNode->Label(); + return true; +} + +//======================================================================= +//function : AddAnimation +//purpose : +//======================================================================= +TDF_Label XCAFDoc_AnimationTool::AddAnimation() const +{ + TDF_Label anAnimL; + TDF_TagSource aTag; + anAnimL = aTag.NewChild(Label()); + Handle(XCAFDoc_Animation) aTol = XCAFDoc_Animation::Set(anAnimL); + TCollection_AsciiString aStr = "Animation"; + TDataStd_Name::Set(anAnimL, aStr); + return anAnimL; +} + +//======================================================================= +//function : IsLocked +//purpose : +//======================================================================= +bool XCAFDoc_AnimationTool::IsLocked(const TDF_Label& theAnimLabel) const +{ + Handle(TDataStd_UAttribute) anAttr; + return theAnimLabel.FindAttribute(XCAFDoc::LockGUID(), anAttr); +} + +//======================================================================= +//function : Unlock +//purpose : +//======================================================================= +void XCAFDoc_AnimationTool::Lock(const TDF_Label& theAnimLabel) const +{ + TDataStd_UAttribute::Set(theAnimLabel, XCAFDoc::LockGUID()); +} + +//======================================================================= +//function : Unlock +//purpose : +//======================================================================= +void XCAFDoc_AnimationTool::Unlock(const TDF_Label& theAnimLabel) const +{ + theAnimLabel.ForgetAttribute(XCAFDoc::LockGUID()); +} + //======================================================================= //function : Dump //purpose : //======================================================================= Standard_OStream& XCAFDoc_AnimationTool::Dump(Standard_OStream& theOStream, - const Standard_Boolean theDepth) const + const bool theDepth) const { (void)theOStream; (void)theDepth; @@ -116,7 +260,7 @@ Standard_OStream& XCAFDoc_AnimationTool::Dump(Standard_OStream& theOStream, Standard_OStream& XCAFDoc_AnimationTool::Dump(Standard_OStream& theDumpLog) const { TDF_Attribute::Dump(theDumpLog); - Dump(theDumpLog, Standard_False); + Dump(theDumpLog, false); return theDumpLog; } diff --git a/src/XCAFDoc/XCAFDoc_AnimationTool.hxx b/src/XCAFDoc/XCAFDoc_AnimationTool.hxx index 93a3dc1163..f67809d02f 100644 --- a/src/XCAFDoc/XCAFDoc_AnimationTool.hxx +++ b/src/XCAFDoc/XCAFDoc_AnimationTool.hxx @@ -1,4 +1,5 @@ // Copyright (c) 2023 OPEN CASCADE SAS +// Copyright (c) 2023 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // @@ -14,25 +15,8 @@ #ifndef _XCAFDoc_AnimationTool_HeaderFile #define _XCAFDoc_AnimationTool_HeaderFile -#include - -#include -#include -#include #include -#include #include -#include -#include -#include -#include -#include - -class Standard_GUID; -class TDF_Label; -class TopoDS_Shape; -class TopLoc_Location; -class XCAFDoc_GraphNode; //! A tool to store shapes in an XDE //! document in the form of assembly structure, and to maintain this structure. @@ -55,28 +39,67 @@ class XCAFDoc_AnimationTool : public TDataStd_GenericEmpty public: Standard_EXPORT static const Standard_GUID& GetID(); - + //! Create (if not exist) ShapeTool from XCAFDoc on . - Standard_EXPORT static Handle(XCAFDoc_AnimationTool) Set (const TDF_Label& theLabel); - + Standard_EXPORT static Handle(XCAFDoc_AnimationTool) Set(const TDF_Label& theLabel); + //! Creates an empty tool //! Creates a tool to work with a document //! Attaches to label XCAFDoc::LabelShapes() Standard_EXPORT XCAFDoc_AnimationTool(); - + //! returns the label under which shapes are stored Standard_EXPORT TDF_Label BaseLabel() const; - - Standard_EXPORT Standard_OStream& Dump (Standard_OStream& theOStream, const Standard_Boolean theDepth) const; - Standard_EXPORT virtual Standard_OStream& Dump (Standard_OStream& theOStream) const Standard_OVERRIDE; - + //! + Standard_EXPORT bool IsAnimation(const TDF_Label& theLabel) const; + + //! + Standard_EXPORT void SetAnimation(const TDF_Label& theShLabel, + const TDF_Label& theAnimLabel) const; + + //! + Standard_EXPORT bool GetGlobalFPS(double& theFPS) const; + + //! + Standard_EXPORT void SetGlobalFPS(const double theFPS) const; + + //! Returns a sequence of Animation labels currently stored + //! in the Animation table. + Standard_EXPORT void GetAnimationLabels(TDF_LabelSequence& theLabels) const; + + //! Returns Animation label defined for shape. + Standard_EXPORT bool GetRefAnimationLabel(const TDF_Label& theShLabel, + TDF_Label& theAnimLabel) const; + + //! Returns Animation label defined for shape. + Standard_EXPORT bool GetRefShapeLabel(const TDF_Label& theAnimLabel, + TDF_Label& theShLabel) const; + + //! Adds a animation definition to the Animation table and returns its label. + Standard_EXPORT TDF_Label AddAnimation() const; + + //! Returns true if the given Animation is marked as locked. + Standard_EXPORT bool IsLocked(const TDF_Label& theAnimLabel) const; + + //! Mark the given Animation as locked. + Standard_EXPORT void Lock(const TDF_Label& theAnimLabel) const; + + //! Unlock the given Animation. + Standard_EXPORT void Unlock(const TDF_Label& theAnimLabel) const; + + Standard_EXPORT Standard_OStream& Dump(Standard_OStream& theOStream, const bool theDepth) const; + + Standard_EXPORT virtual Standard_OStream& Dump(Standard_OStream& theOStream) const Standard_OVERRIDE; + Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE; - - //! Dumps the content of me into the stream - Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE; - DEFINE_DERIVED_ATTRIBUTE(XCAFDoc_AnimationTool,TDataStd_GenericEmpty) + //! Dumps the content of me into the stream + Standard_EXPORT virtual void DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE; + + DEFINE_DERIVED_ATTRIBUTE(XCAFDoc_AnimationTool, TDataStd_GenericEmpty) + +private: }; diff --git a/src/XCAFDoc/XCAFDoc_Area.cxx b/src/XCAFDoc/XCAFDoc_Area.cxx index 725b51805a..47d05bc156 100644 --- a/src/XCAFDoc/XCAFDoc_Area.cxx +++ b/src/XCAFDoc/XCAFDoc_Area.cxx @@ -1,4 +1,6 @@ -// Copyright (c) 2000-2023 OPEN CASCADE SAS +// Created on: 2000-09-08 +// Created by: data exchange team +// Copyright (c) 2000-2014 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. //