1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

refs 474:Possibility to create and play animations

This commit is contained in:
ema 2017-10-06 11:30:34 +03:00
parent e8b4130801
commit cf1ae6e9fe
24 changed files with 1766 additions and 0 deletions

View File

@ -42,6 +42,8 @@
#include <BinMXCAFDoc_ViewDriver.hxx>
#include <BinMXCAFDoc_ViewToolDriver.hxx>
#include <BinMXCAFDoc_VolumeDriver.hxx>
#include <BinMXCAFDoc_AnimationDriver.hxx>
#include <BinMXCAFDoc_AnimationToolDriver.hxx>
#include <CDM_MessageDriver.hxx>
#include <TNaming_NamedShape.hxx>
@ -81,6 +83,7 @@ void BinMXCAFDoc::AddDrivers(const Handle(BinMDF_ADriverTable)& theDriverTable,
theDriverTable->AddDriver( new BinMXCAFDoc_NoteBinDataDriver (theMsgDrv));
theDriverTable->AddDriver( new BinMXCAFDoc_NoteCommentDriver (theMsgDrv));
theDriverTable->AddDriver( new BinMXCAFDoc_ViewDriver (theMsgDrv));
theDriverTable->AddDriver( new BinMXCAFDoc_AnimationDriver (theMsgDrv));
theDriverTable->AddDriver( new BinMXCAFDoc_ColorToolDriver (theMsgDrv));
theDriverTable->AddDriver( new BinMXCAFDoc_DocumentToolDriver(theMsgDrv));
@ -90,4 +93,5 @@ void BinMXCAFDoc::AddDrivers(const Handle(BinMDF_ADriverTable)& theDriverTable,
theDriverTable->AddDriver( new BinMXCAFDoc_MaterialToolDriver(theMsgDrv));
theDriverTable->AddDriver( new BinMXCAFDoc_NotesToolDriver (theMsgDrv));
theDriverTable->AddDriver( new BinMXCAFDoc_ViewToolDriver (theMsgDrv));
theDriverTable->AddDriver( new BinMXCAFDoc_AnimationToolDriver(theMsgDrv));
}

View File

@ -45,6 +45,9 @@ class BinMXCAFDoc_DimTolToolDriver;
class BinMXCAFDoc_MaterialToolDriver;
class BinMXCAFDoc_ViewDriver;
class BinMXCAFDoc_ViewToolDriver;
class BinMXCAFDoc_AnimationDriver;
class BinMXCAFDoc_AnimationToolDriver;
@ -92,6 +95,9 @@ friend class BinMXCAFDoc_DimTolToolDriver;
friend class BinMXCAFDoc_MaterialToolDriver;
friend class BinMXCAFDoc_ViewDriver;
friend class BinMXCAFDoc_ViewToolDriver;
friend class BinMXCAFDoc_AnimationDriver;
friend class BinMXCAFDoc_AnimationToolDriver;
};

View File

@ -0,0 +1,112 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <BinMXCAFDoc_AnimationDriver.hxx>
#include <BinObjMgt_Persistent.hxx>
#include <CDM_MessageDriver.hxx>
#include <Standard_Type.hxx>
#include <TCollection_HAsciiString.hxx>
#include <TDF_Attribute.hxx>
#include <XCAFDoc_Animation.hxx>
# include <TColStd_HArray1OfByte.hxx>
IMPLEMENT_STANDARD_RTTIEXT(BinMXCAFDoc_AnimationDriver,BinMDF_ADriver)
static Standard_Boolean getByteArray(const BinObjMgt_Persistent& theSource, Handle(TColStd_HArray1OfByte)& theArray)
{
Standard_Integer aFirstInd, aLastInd;
if (!(theSource >> aFirstInd >> aLastInd))
return Standard_False;
if (aLastInd < aFirstInd)
return Standard_False;
theArray.reset(new TColStd_HArray1OfByte(aFirstInd, aLastInd - aFirstInd + 1));
theSource.GetByteArray(&theArray->ChangeFirst(), aLastInd - aFirstInd + 1);
return Standard_True;
}
static void putByteArray(BinObjMgt_Persistent& theTarget, const Handle(TColStd_HArray1OfByte)& theArray)
{
if (theArray.IsNull())
return;
const Standard_Integer aFirstInd = theArray->Lower();
const Standard_Integer aLastInd = theArray->Upper();
if (aLastInd < aFirstInd)
return;
theTarget << aFirstInd << aLastInd;
theTarget.PutByteArray(&theArray->ChangeFirst(), aLastInd - aFirstInd + 1);
}
//=======================================================================
//function : Constructor
//purpose :
//=======================================================================
BinMXCAFDoc_AnimationDriver::BinMXCAFDoc_AnimationDriver
(const Handle(CDM_MessageDriver)& theMsgDriver)
: BinMDF_ADriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_Animation)->Name())
{
}
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) BinMXCAFDoc_AnimationDriver::NewEmpty() const
{
return new XCAFDoc_Animation();
}
//=======================================================================
//function : Paste
//purpose :
//=======================================================================
Standard_Boolean BinMXCAFDoc_AnimationDriver::Paste(const BinObjMgt_Persistent& theSource,
const Handle(TDF_Attribute)& theTarget,
BinObjMgt_RRelocationTable& /*theRelocTable*/) const
{
Handle(XCAFDoc_Animation) anAtt = Handle(XCAFDoc_Animation)::DownCast(theTarget);
Standard_Real aDensity;
TCollection_AsciiString aName;
if (!(theSource >> aName))
return Standard_False;
Handle(TColStd_HArray1OfByte) anImage, anAnimation;
if (!getByteArray(theSource, anImage) || anImage.IsNull())
return Standard_False;
if (!getByteArray(theSource, anAnimation) || anAnimation.IsNull())
return Standard_False;
anAtt->Set(new TCollection_HAsciiString(aName), anImage, anAnimation);
return Standard_True;
}
//=======================================================================
//function : Paste
//purpose :
//=======================================================================
void BinMXCAFDoc_AnimationDriver::Paste(const Handle(TDF_Attribute)& theSource,
BinObjMgt_Persistent& theTarget,
BinObjMgt_SRelocationTable& /*theRelocTable*/) const
{
Handle(XCAFDoc_Animation) anAtt = Handle(XCAFDoc_Animation)::DownCast(theSource);
Handle(TCollection_HAsciiString) aName = anAtt->GetName();
if (!aName.IsNull())
theTarget << aName->String();
putByteArray(theTarget, anAtt->GetImage());
putByteArray(theTarget, anAtt->GetAnimation());
}

View File

@ -0,0 +1,72 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _BinMXCAFDoc_AnimationDriver_HeaderFile
#define _BinMXCAFDoc_AnimationDriver_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <BinMDF_ADriver.hxx>
#include <Standard_Boolean.hxx>
#include <BinObjMgt_RRelocationTable.hxx>
#include <BinObjMgt_SRelocationTable.hxx>
class CDM_MessageDriver;
class TDF_Attribute;
class BinObjMgt_Persistent;
class BinMXCAFDoc_AnimationDriver;
DEFINE_STANDARD_HANDLE(BinMXCAFDoc_AnimationDriver, BinMDF_ADriver)
class BinMXCAFDoc_AnimationDriver : public BinMDF_ADriver
{
public:
Standard_EXPORT BinMXCAFDoc_AnimationDriver(const Handle(CDM_MessageDriver)& theMsgDriver);
Standard_EXPORT virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean Paste (const BinObjMgt_Persistent& theSource, const Handle(TDF_Attribute)& theTarget, BinObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE;
Standard_EXPORT virtual void Paste (const Handle(TDF_Attribute)& theSource, BinObjMgt_Persistent& theTarget, BinObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(BinMXCAFDoc_AnimationDriver,BinMDF_ADriver)
protected:
private:
};
#endif // _BinMXCAFDoc_AnimationDriver_HeaderFile

View File

@ -0,0 +1,65 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <BinMXCAFDoc_AnimationToolDriver.hxx>
#include <BinObjMgt_Persistent.hxx>
#include <CDM_MessageDriver.hxx>
#include <Standard_Type.hxx>
#include <TDF_Attribute.hxx>
#include <XCAFDoc_AnimationTool.hxx>
IMPLEMENT_STANDARD_RTTIEXT(BinMXCAFDoc_AnimationToolDriver, BinMDF_ADriver)
//=======================================================================
//function :
//purpose :
//=======================================================================
BinMXCAFDoc_AnimationToolDriver::BinMXCAFDoc_AnimationToolDriver
(const Handle(CDM_MessageDriver)& theMsgDriver)
: BinMDF_ADriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_AnimationTool)->Name())
{
}
//=======================================================================
//function :
//purpose :
//=======================================================================
Handle(TDF_Attribute) BinMXCAFDoc_AnimationToolDriver::NewEmpty() const
{
return new XCAFDoc_AnimationTool();
}
//=======================================================================
//function :
//purpose :
//=======================================================================
Standard_Boolean BinMXCAFDoc_AnimationToolDriver::Paste
(const BinObjMgt_Persistent& /*theSource*/,
const Handle(TDF_Attribute)& /*theTarget*/,
BinObjMgt_RRelocationTable& /*theRelocTable*/) const
{
return Standard_True;
}
//=======================================================================
//function :
//purpose :
//=======================================================================
void BinMXCAFDoc_AnimationToolDriver::Paste
(const Handle(TDF_Attribute)& /*theSource*/,
BinObjMgt_Persistent& /*theTarget*/,
BinObjMgt_SRelocationTable& /*theRelocTable*/) const {
}

View File

@ -0,0 +1,50 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _BinMXCAFDoc_AnimationToolDriver_HeaderFile
#define _BinMXCAFDoc_AnimationToolDriver_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <BinMDF_ADriver.hxx>
#include <Standard_Boolean.hxx>
#include <BinObjMgt_RRelocationTable.hxx>
#include <BinObjMgt_SRelocationTable.hxx>
class CDM_MessageDriver;
class TDF_Attribute;
class BinObjMgt_Persistent;
class BinMXCAFDoc_AnimationToolDriver;
DEFINE_STANDARD_HANDLE(BinMXCAFDoc_AnimationToolDriver, BinMDF_ADriver)
class BinMXCAFDoc_AnimationToolDriver : public BinMDF_ADriver
{
public:
Standard_EXPORT BinMXCAFDoc_AnimationToolDriver(const Handle(CDM_MessageDriver)& theMsgDriver);
Standard_EXPORT virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean Paste(const BinObjMgt_Persistent& theSource, const Handle(TDF_Attribute)& theTarget, BinObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE;
Standard_EXPORT virtual void Paste(const Handle(TDF_Attribute)& theSource, BinObjMgt_Persistent& theTarget, BinObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(BinMXCAFDoc_AnimationToolDriver, BinMDF_ADriver)
};
#endif // _BinMXCAFDoc_AnimationToolDriver_HeaderFile

View File

@ -53,3 +53,7 @@ BinMXCAFDoc_ViewToolDriver.cxx
BinMXCAFDoc_ViewToolDriver.hxx
BinMXCAFDoc_VolumeDriver.cxx
BinMXCAFDoc_VolumeDriver.hxx
BinMXCAFDoc_AnimationDriver.cxx
BinMXCAFDoc_AnimationDriver.hxx
BinMXCAFDoc_AnimationToolDriver.cxx
BinMXCAFDoc_AnimationToolDriver.hxx

View File

@ -65,3 +65,8 @@ XCAFDoc_ViewTool.cxx
XCAFDoc_ViewTool.hxx
XCAFDoc_Volume.cxx
XCAFDoc_Volume.hxx
XCAFDoc_Animation.cxx
XCAFDoc_Animation.hxx
XCAFDoc_AnimationTool.cxx
XCAFDoc_AnimationTool.hxx

View File

@ -0,0 +1,214 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Standard_GUID.hxx>
#include <Standard_Type.hxx>
#include <TCollection_HAsciiString.hxx>
#include <TDF_Attribute.hxx>
#include <TDF_Label.hxx>
#include <TDF_RelocationTable.hxx>
#include <XCAFDoc_Animation.hxx>
#include <TColStd_HArray1OfByte.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_Animation, TDF_Attribute)
//=======================================================================
//function : XCAFDoc_Animation
//purpose :
//=======================================================================
XCAFDoc_Animation::XCAFDoc_Animation()
{
}
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
const Standard_GUID& XCAFDoc_Animation::GetID()
{
static Standard_GUID MatID("431A3BB7-7113-45C4-8653-AED7CC0012E1");
return MatID;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
Handle(XCAFDoc_Animation) XCAFDoc_Animation::Set(const TDF_Label& theLabel,
const Handle(TCollection_HAsciiString)& theName,
const Handle(TColStd_HArray1OfByte)& theImage,
const Handle(TColStd_HArray1OfByte)& theAnimation)
{
Handle(XCAFDoc_Animation) A;
if (!theLabel.FindAttribute(XCAFDoc_Animation::GetID(), A))
{
A = new XCAFDoc_Animation();
theLabel.AddAttribute(A);
}
A->Set(theName, theImage, theAnimation);
return A;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
Handle(XCAFDoc_Animation) XCAFDoc_Animation::Set(const TDF_Label& theLabel,
const Handle(TCollection_HAsciiString)& theName,
OSD_File& theImageFile, OSD_File& theAnimationFile)
{
Handle(XCAFDoc_Animation) anAnimation;
if (!theLabel.FindAttribute(XCAFDoc_Animation::GetID(), anAnimation))
{
anAnimation = new XCAFDoc_Animation();
if (anAnimation->Set(theName, theImageFile, theAnimationFile))
theLabel.AddAttribute(anAnimation);
else
anAnimation.Nullify();
}
else
anAnimation->Set(theName, theImageFile, theAnimationFile);
return anAnimation;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
Standard_Boolean XCAFDoc_Animation::Set(const Handle(TCollection_HAsciiString)& theName, OSD_File& theImageFile, OSD_File& theAnimationFile)
{
if (!theImageFile.IsOpen() || !theImageFile.IsReadable() || !theAnimationFile.IsOpen() || !theAnimationFile.IsReadable())
return Standard_False;
if (theImageFile.Size() > (Standard_Size)IntegerLast() || theAnimationFile.Size() > (Standard_Size)IntegerLast())
return Standard_False;
myImage.reset(new TColStd_HArray1OfByte(1, static_cast<Standard_Integer>(theImageFile.Size())));
Standard_Integer nbReadBytes = 0;
theImageFile.Read((Standard_Address)&myImage->First(), myImage->Length(), nbReadBytes);
if (nbReadBytes < myImage->Length())
return Standard_False;
myAnimation.reset(new TColStd_HArray1OfByte(1, static_cast<Standard_Integer>(theAnimationFile.Size())));
nbReadBytes = 0;
theAnimationFile.Read((Standard_Address)&myAnimation->First(), myAnimation->Length(), nbReadBytes);
if (nbReadBytes < myAnimation->Length())
return Standard_False;
myName = theName;
return Standard_True;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
void XCAFDoc_Animation::Set(const Handle(TCollection_HAsciiString)& theName,
const Handle(TColStd_HArray1OfByte)& theImage,
const Handle(TColStd_HArray1OfByte)& theAnimation)
{
myName = theName;
myImage = theImage;
myAnimation = theAnimation;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
void XCAFDoc_Animation::Set(const Handle(TCollection_HAsciiString)& theName)
{
myName = theName;
}
//=======================================================================
//function : GetName
//purpose :
//=======================================================================
Handle(TCollection_HAsciiString) XCAFDoc_Animation::GetName() const
{
return myName;
}
//=======================================================================
//function : GetImage
//purpose :
//=======================================================================
Handle(TColStd_HArray1OfByte) XCAFDoc_Animation::GetImage() const
{
return myImage;
}
//=======================================================================
//function : GetAnimation
//purpose :
//=======================================================================
Handle(TColStd_HArray1OfByte) XCAFDoc_Animation::GetAnimation() const
{
return myAnimation;
}
//=======================================================================
//function : ID
//purpose :
//=======================================================================
const Standard_GUID& XCAFDoc_Animation::ID() const
{
return GetID();
}
//=======================================================================
//function : Restore
//purpose :
//=======================================================================
void XCAFDoc_Animation::Restore(const Handle(TDF_Attribute)& With)
{
myName = Handle(XCAFDoc_Animation)::DownCast(With)->GetName();
myImage = Handle(XCAFDoc_Animation)::DownCast(With)->GetImage();
myAnimation = Handle(XCAFDoc_Animation)::DownCast(With)->GetAnimation();
}
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) XCAFDoc_Animation::NewEmpty() const
{
return new XCAFDoc_Animation();
}
//=======================================================================
//function : Paste
//purpose :
//=======================================================================
void XCAFDoc_Animation::Paste(const Handle(TDF_Attribute)& Into,
const Handle(TDF_RelocationTable)& /*RT*/) const
{
Handle(XCAFDoc_Animation)::DownCast(Into)->Set(myName, myImage, myAnimation);
}

View File

@ -0,0 +1,82 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XCAFDoc_Animation_HeaderFile
#define _XCAFDoc_Animation_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <OSD_File.hxx>
#include <TDF_Attribute.hxx>
class Standard_GUID;
class TDF_Label;
class TDF_Attribute;
class TDF_RelocationTable;
class XCAFView_Object;
class XCAFDoc_Animation;
class TCollection_HAsciiString;
class TColStd_HArray1OfByte;
DEFINE_STANDARD_HANDLE(XCAFDoc_Animation, TDF_Attribute)
//! attribute to store animation
class XCAFDoc_Animation : public TDF_Attribute
{
public:
Standard_EXPORT XCAFDoc_Animation();
Standard_EXPORT static const Standard_GUID& GetID();
Standard_EXPORT static Handle(XCAFDoc_Animation) Set(const TDF_Label& label, const Handle(TCollection_HAsciiString)& theName, const Handle(TColStd_HArray1OfByte)& theImage, const Handle(TColStd_HArray1OfByte)& theAnimation);
Standard_EXPORT static Handle(XCAFDoc_Animation) Set(const TDF_Label& theLabel, const Handle(TCollection_HAsciiString)& theName, OSD_File& theImageFile, OSD_File& theAnimationFile);
Standard_EXPORT void Set(const Handle(TCollection_HAsciiString)& theName, const Handle(TColStd_HArray1OfByte)& theImage, const Handle(TColStd_HArray1OfByte)& theAnimation);
Standard_EXPORT Standard_Boolean Set(const Handle(TCollection_HAsciiString)& aName, OSD_File& theImageFile, OSD_File& theAnimationFile);
Standard_EXPORT void Set(const Handle(TCollection_HAsciiString)& theName);
Standard_EXPORT Handle(TCollection_HAsciiString) GetName() const;
Standard_EXPORT Handle(TColStd_HArray1OfByte) GetImage() const;
Standard_EXPORT Handle(TColStd_HArray1OfByte) GetAnimation() const;
Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
Standard_EXPORT void Restore(const Handle(TDF_Attribute)& With) Standard_OVERRIDE;
Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT void Paste(const Handle(TDF_Attribute)& Into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(XCAFDoc_Animation, TDF_Attribute)
private:
Handle(TCollection_HAsciiString) myName;
Handle(TColStd_HArray1OfByte) myImage;
Handle(TColStd_HArray1OfByte) myAnimation;
};
#endif

View File

@ -0,0 +1,236 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <TCollection_HAsciiString.hxx>
#include <TDataStd_Integer.hxx>
#include <TDataStd_Name.hxx>
#include <TDataStd_TreeNode.hxx>
#include <TDataXtd_Geometry.hxx>
#include <TDataXtd_Plane.hxx>
#include <TDF_Attribute.hxx>
#include <TDF_ChildIDIterator.hxx>
#include <XCAFDoc.hxx>
#include <XCAFDoc_Animation.hxx>
#include <XCAFDoc_AnimationTool.hxx>
#include <TDF_AttributeIterator.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_AnimationTool, TDF_Attribute)
//=======================================================================
//function : BaseLabel
//purpose :
//=======================================================================
TDF_Label XCAFDoc_AnimationTool::BaseLabel() const
{
return Label();
}
//=======================================================================
//function : IsAnimation
//purpose :
//=======================================================================
Standard_Boolean XCAFDoc_AnimationTool::IsAnimation(const TDF_Label& theLabel) const
{
if (theLabel.Father() != Label())
return Standard_False;
Handle(XCAFDoc_Animation) anAnimAttribute;
if (!theLabel.FindAttribute(XCAFDoc_Animation::GetID(), anAnimAttribute))
return Standard_False;
return Standard_True;
}
//=======================================================================
//function : GetAnimation
//purpose :
//=======================================================================
Standard_Boolean XCAFDoc_AnimationTool::GetAnimation(const TDF_Label& theLabel,
Handle(TCollection_HAsciiString)& theName,
Handle(TColStd_HArray1OfByte)& theImage,
Handle(TColStd_HArray1OfByte)& theAnimation) const
{
if (theLabel.Father() != Label())
return Standard_False;
Handle(XCAFDoc_Animation) animAttr;
if (!theLabel.FindAttribute(XCAFDoc_Animation::GetID(), animAttr)) {
return Standard_False;
}
theName = animAttr->GetName();
theImage = animAttr->GetImage();
theAnimation = animAttr->GetAnimation();
return Standard_True;
}
//=======================================================================
//function : AddAnimation
//purpose :
//=======================================================================
TDF_Label XCAFDoc_AnimationTool::AddAnimation(const Handle(TCollection_HAsciiString)& theName,
const Handle(TColStd_HArray1OfByte)& theImage,
const Handle(TColStd_HArray1OfByte)& theAnimation )
{
TDF_Label animL;
TDF_TagSource aTag;
animL = aTag.NewChild(Label());
XCAFDoc_Animation::Set(animL, theName, theImage, theAnimation);
TDataStd_Name::Set(animL, TCollection_AsciiString(theName->ToCString()));
return animL;
}
//=======================================================================
//function : AddAnimation
//purpose :
//=======================================================================
TDF_Label XCAFDoc_AnimationTool::AddAnimation(const Handle(TCollection_HAsciiString)& theName,
OSD_File& theImageFile, OSD_File& theAnimationFile)
{
TDF_Label animL;
TDF_TagSource aTag;
animL = aTag.NewChild(Label());
TDataStd_Name::Set(animL, TCollection_AsciiString(theName->ToCString()));
XCAFDoc_Animation::Set(animL, theName, theImageFile, theAnimationFile);
return animL;
}
//=======================================================================
//function : RemoveAnimation
//purpose :
//=======================================================================
Standard_Boolean XCAFDoc_AnimationTool::RemoveAnimation(const TDF_Label& theLabel) const
{
Handle(XCAFDoc_Animation)anAnimAttr;
if (!IsAnimation(theLabel) || !theLabel.FindAttribute(XCAFDoc_Animation::GetID(), anAnimAttr))
return Standard_False;
theLabel.ForgetAllAttributes(Standard_True);
return Standard_True;
}
//=======================================================================
//function : GetAnimationLabels
//purpose :
//=======================================================================
void XCAFDoc_AnimationTool::GetAnimationLabels(TDF_LabelSequence& theLabels) const
{
theLabels.Clear();
TDF_ChildIterator aChildIterator(Label());
for (; aChildIterator.More(); aChildIterator.Next()) {
TDF_Label aLabel = aChildIterator.Value();
if (IsAnimation(aLabel)) theLabels.Append(aLabel);
}
}
//=======================================================================
//function : SetName
//purpose :
//=======================================================================
void XCAFDoc_AnimationTool::SetName(const TDF_Label& theLabel,
const Handle(TCollection_HAsciiString)& theName) const
{
if (theLabel.Father() != Label())
return;
Handle(XCAFDoc_Animation)anAnimAttr;
if (!theLabel.FindAttribute(XCAFDoc_Animation::GetID(), anAnimAttr))
return;
anAnimAttr->Set(theName);
}
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
const Standard_GUID& XCAFDoc_AnimationTool::GetID()
{
static Standard_GUID AnimationID("7261F539-43AD-4544-8419-AE63C6ED4A41");
return AnimationID;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
Handle(XCAFDoc_AnimationTool) XCAFDoc_AnimationTool::Set(const TDF_Label& L)
{
Handle(XCAFDoc_AnimationTool) A;
if (!L.FindAttribute(XCAFDoc_AnimationTool::GetID(), A)) {
A = new XCAFDoc_AnimationTool();
L.AddAttribute(A);
}
return A;
}
//=======================================================================
//function : ID
//purpose :
//=======================================================================
const Standard_GUID& XCAFDoc_AnimationTool::ID() const
{
return GetID();
}
//=======================================================================
//function : Restore
//purpose :
//=======================================================================
void XCAFDoc_AnimationTool::Restore(const Handle(TDF_Attribute)& /*with*/)
{
}
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) XCAFDoc_AnimationTool::NewEmpty() const
{
return new XCAFDoc_AnimationTool;
}
//=======================================================================
//function : Paste
//purpose :
//=======================================================================
void XCAFDoc_AnimationTool::Paste(const Handle(TDF_Attribute)& /*into*/,
const Handle(TDF_RelocationTable)& /*RT*/) const
{
}
//=======================================================================
//function : XCAFDoc_AnimationTool
//purpose :
//=======================================================================
XCAFDoc_AnimationTool::XCAFDoc_AnimationTool()
{
}

View File

@ -0,0 +1,85 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// 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
#include <TDF_LabelSequence.hxx>
#include <TColStd_HArray1OfByte.hxx>
#include <OSD_File.hxx>
class XCAFDoc_AnimationTool;
DEFINE_STANDARD_HANDLE(XCAFDoc_AnimationToolTool, TDF_Attribute)
//! Provide tool for management of Animations section of document.
//! Provide tool to store, retrieve, remove and modify animations.
//! Each animation has a name and binary data of screenshot and animation.
class XCAFDoc_AnimationTool : public TDF_Attribute
{
public:
Standard_EXPORT XCAFDoc_AnimationTool();
//! Creates (if not exist) Animation tool.
Standard_EXPORT static Handle(XCAFDoc_AnimationTool) Set(const TDF_Label& theLabel);
Standard_EXPORT static const Standard_GUID& GetID();
//! returns the label under which Animations are stored
Standard_EXPORT TDF_Label BaseLabel() const;
//! Returns True if label belongs to a Animations table and
//! is a animation definition
Standard_EXPORT Standard_Boolean IsAnimation (const TDF_Label& theLabel) const;
//! Returns animation defined by label theLabel
//! Returns False if the label is not in Animations table
Standard_EXPORT Standard_Boolean GetAnimation(const TDF_Label& theLabel, Handle(TCollection_HAsciiString)& theName, Handle(TColStd_HArray1OfByte)& theImage, Handle(TColStd_HArray1OfByte)& theAnimation) const;
//! Adds an animation definition to a Animations table
//! Returns created label
Standard_EXPORT TDF_Label AddAnimation(const Handle(TCollection_HAsciiString)& theName, const Handle(TColStd_HArray1OfByte)& theImage, const Handle(TColStd_HArray1OfByte)& theAnimation);
//! Adds an animation definition to a Animations table
//! Returns created label
Standard_EXPORT TDF_Label AddAnimation(const Handle(TCollection_HAsciiString)& theName, OSD_File& theImageFile, OSD_File& theAnimationFile);
//! Removes animation from the Animations table
Standard_EXPORT Standard_Boolean RemoveAnimation(const TDF_Label& theLabel) const;
//! Returns a sequence of animations currently stored
//! in the Animations table
Standard_EXPORT void GetAnimationLabels(TDF_LabelSequence& Labels) const;
//! Rename animation
Standard_EXPORT void SetName(const TDF_Label& theLabelL, const Handle(TCollection_HAsciiString)& theName) const;
Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
Standard_EXPORT void Restore (const Handle(TDF_Attribute)& with) Standard_OVERRIDE;
Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT void Paste (const Handle(TDF_Attribute)& into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(XCAFDoc_AnimationTool, TDF_Attribute)
};
#endif // _XCAFDoc_ClippingPlaneTool_HeaderFile

View File

@ -0,0 +1,65 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XCAFDoc_View_HeaderFile
#define _XCAFDoc_View_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <TDF_Attribute.hxx>
class Standard_GUID;
class TDF_Label;
class TDF_Attribute;
class TDF_RelocationTable;
class XCAFView_Object;
// resolve name collisions with WinAPI headers
#ifdef GetObject
#undef GetObject
#endif
class XCAFDoc_View;
DEFINE_STANDARD_HANDLE(XCAFDoc_View, TDF_Attribute)
//! attribute to store view
class XCAFDoc_View : public TDF_Attribute
{
public:
Standard_EXPORT XCAFDoc_View();
Standard_EXPORT static const Standard_GUID& GetID();
Standard_EXPORT static Handle(XCAFDoc_View) Set (const TDF_Label& theLabel);
Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
Standard_EXPORT void Restore (const Handle(TDF_Attribute)& With) Standard_OVERRIDE;
Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT void Paste (const Handle(TDF_Attribute)& Into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
Standard_EXPORT void SetObject (const Handle(XCAFView_Object)& theViewObject);
Standard_EXPORT Handle(XCAFView_Object) GetObject() const;
DEFINE_STANDARD_RTTIEXT(XCAFDoc_View, TDF_Attribute)
};
#endif

View File

@ -33,6 +33,7 @@
#include <XCAFDoc_NotesTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFDoc_ViewTool.hxx>
#include <XCAFDoc_AnimationTool.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_DocumentTool,TDF_Attribute)
@ -87,6 +88,7 @@ Handle(XCAFDoc_DocumentTool) XCAFDoc_DocumentTool::Set(const TDF_Label& L,
XCAFDoc_NotesTool::Set(NotesLabel(L));
XCAFDoc_ViewTool::Set(ViewsLabel(L));
XCAFDoc_ClippingPlaneTool::Set(ClippingPlanesLabel(L));
XCAFDoc_AnimationTool::Set(AnimationsLabel(L));
}
return A;
}
@ -224,7 +226,17 @@ TDF_Label XCAFDoc_DocumentTool::NotesLabel(const TDF_Label& acces)
TDataStd_Name::Set(L, "Notes");
return L;
}
//=======================================================================
//function : AnimationsLabel
//purpose :
//=======================================================================
TDF_Label XCAFDoc_DocumentTool::AnimationsLabel(const TDF_Label& acces)
{
TDF_Label L = DocLabel(acces).FindChild(10, Standard_True);
TDataStd_Name::Set(L, "Animations");
return L;
}
//=======================================================================
//function : ShapeTool
//purpose :
@ -308,7 +320,15 @@ Handle(XCAFDoc_NotesTool) XCAFDoc_DocumentTool::NotesTool(const TDF_Label& acces
{
return XCAFDoc_NotesTool::Set(NotesLabel(acces));
}
//=======================================================================
//function : AnimationTool
//purpose :
//=======================================================================
Handle(XCAFDoc_AnimationTool) XCAFDoc_DocumentTool::AnimationTool(const TDF_Label& acces)
{
return XCAFDoc_AnimationTool::Set(AnimationsLabel(acces));
}
//=======================================================================
//function : ID
//purpose :

View File

@ -34,6 +34,7 @@ class XCAFDoc_NotesTool;
class XCAFDoc_ViewTool;
class TDF_Attribute;
class TDF_RelocationTable;
class XCAFDoc_AnimationTool;
class XCAFDoc_DocumentTool;
@ -88,6 +89,9 @@ public:
//! Returns sub-label of DocLabel() with tag 9.
Standard_EXPORT static TDF_Label NotesLabel(const TDF_Label& acces);
//! Returns sub-label of DocLabel() with tag 10.
Standard_EXPORT static TDF_Label AnimationsLabel(const TDF_Label& acces);
//! Creates (if it does not exist) ShapeTool attribute on ShapesLabel().
Standard_EXPORT static Handle(XCAFDoc_ShapeTool) ShapeTool (const TDF_Label& acces);
@ -112,6 +116,9 @@ public:
//! Creates (if it does not exist) NotesTool attribute on NotesLabel().
Standard_EXPORT static Handle(XCAFDoc_NotesTool) NotesTool(const TDF_Label& acces);
//! Creates (if it does not exist) AnimationTool attribute on NotesLabel().
Standard_EXPORT static Handle(XCAFDoc_AnimationTool) AnimationTool(const TDF_Label& acces);
Standard_EXPORT XCAFDoc_DocumentTool();

View File

@ -16,3 +16,6 @@ XDEDRAW_Views.cxx
XDEDRAW_Views.hxx
XDEDRAW_Notes.cxx
XDEDRAW_Notes.hxx
XDEDRAW_Animations.cxx
XDEDRAW_Animations.hxx

View File

@ -88,6 +88,7 @@
#include <XDEDRAW_GDTs.hxx>
#include <XDEDRAW_Views.hxx>
#include <XDEDRAW_Notes.hxx>
#include <XDEDRAW_Animations.hxx>
#include <XSDRAW.hxx>
#include <XSDRAWIGES.hxx>
#include <XSDRAWSTEP.hxx>
@ -1173,6 +1174,7 @@ void XDEDRAW::Init(Draw_Interpretor& di)
XDEDRAW_GDTs::InitCommands ( di );
XDEDRAW_Views::InitCommands(di);
XDEDRAW_Notes::InitCommands(di);
XDEDRAW_Animations::InitCommands( di );
XDEDRAW_Common::InitCommands ( di );//moved from EXE
}

View File

@ -0,0 +1,376 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <DDocStd.hxx>
#include <OSD_File.hxx>
#include <OSD_Protection.hxx>
#include <TDocStd_Document.hxx>
#include <TDF_Tool.hxx>
#include <TCollection_HAsciiString.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_AnimationTool.hxx>
#include <XDEDRAW_Animations.hxx>
#include <XCAFDoc_Animation.hxx>
struct cmd
{
const char* name;
Standard_Integer nargsreq;
const char* use;
};
//=======================================================================
//function : animations
//purpose : returns list of all animations
//=======================================================================
static const cmd XAnimations = {
"XAnimations", 2, "XAnimations Doc"
};
static Standard_Integer
animations(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
static const cmd& myCommand = XAnimations;
if (argc < myCommand.nargsreq)
{
di << "Use: " << myCommand.use << "\n";
return 1;
}
Handle(TDocStd_Document) aDoc;
DDocStd::GetDocument(argv[1], aDoc);
if (aDoc.IsNull())
{
return 1;
}
Handle(XCAFDoc_AnimationTool) anAnimTool = XCAFDoc_DocumentTool::AnimationTool(aDoc->Main());
TDF_LabelSequence anAnimations;
anAnimTool->GetAnimationLabels(anAnimations);
for (TDF_LabelSequence::Iterator anIt(anAnimations); anIt.More(); anIt.Next())
{
TCollection_AsciiString anEntry;
TDF_Tool::Entry(anIt.Value(), anEntry);
di << anEntry << " ";
}
return 0;
}
//=======================================================================
//function : addAnimation
//purpose : add animation
//=======================================================================
static const cmd XAnimationAdd = {
"XAnimationAdd", 6, "XAnimationAdd Doc name --file image_path animation_path | --data image_data animation_data"
};
static Standard_Integer
addAnimation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
static const cmd& myCommand = XAnimationAdd;
if (argc < myCommand.nargsreq)
{
di << "Use: " << myCommand.use << "\n";
return 1;
}
Standard_Integer iarg = 0;
Handle(TDocStd_Document) aDoc;
DDocStd::GetDocument(argv[++iarg], aDoc);
if (aDoc.IsNull())
{
return 1;
}
TCollection_ExtendedString aName = argv[++iarg];
Standard_Boolean aFromFile = Standard_False;
Standard_Boolean aFromData = Standard_False;
TCollection_ExtendedString anImageFileStr;
TCollection_ExtendedString anAnimationFileStr;
Handle(TColStd_HArray1OfByte) anImage;
Handle(TColStd_HArray1OfByte) anAnimation;
for (++iarg; iarg < argc; ++iarg)
{
TCollection_AsciiString opt = argv[iarg];
if (opt == "--file")
{
if (aFromData)
{
di << "Error: data can be taken either from a file or a data array.\n";
di << "Use: " << myCommand.use << "\n";
return 1;
}
if (++iarg >= argc)
{
di << "Error: file image path is expected.\n";
di << "Use: " << myCommand.use << "\n";
return 1;
}
anImageFileStr = argv[iarg];
if (++iarg >= argc)
{
di << "Error: file animation path is expected.\n";
di << "Use: " << myCommand.use << "\n";
return 1;
}
anAnimationFileStr = argv[iarg];
aFromFile = Standard_True;
}
else if (opt == "--data")
{
if (aFromFile)
{
di << "Error: data can be taken either from a file or a data array.\n";
di << "Use: " << myCommand.use << "\n";
return 1;
}
if (++iarg >= argc)
{
di << "Error: image data array is expected.\n";
di << "Use: " << myCommand.use << "\n";
return 1;
}
Standard_SStream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
ss << argv[iarg];
Standard_Integer len = static_cast<Standard_Integer>(ss.tellp());
anImage = new TColStd_HArray1OfByte(1, len);
for (Standard_Integer i = 1; i <= len && !ss.eof(); ++i)
{
ss >> anImage->ChangeValue(i);
}
if (++iarg >= argc)
{
di << "Error: animation data array is expected.\n";
di << "Use: " << myCommand.use << "\n";
return 1;
}
Standard_SStream ssAn(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
ssAn << argv[iarg];
len = static_cast<Standard_Integer>(ss.tellp());
anAnimation = new TColStd_HArray1OfByte(1, len);
for (Standard_Integer i = 1; i <= len && !ss.eof(); ++i)
{
ssAn >> anAnimation->ChangeValue(i);
}
aFromData = Standard_True;
}
}
Handle(XCAFDoc_AnimationTool) anAnimationTool = XCAFDoc_DocumentTool::AnimationTool(aDoc->Main());
TDF_Label aLabel;
if (aFromFile)
{
OSD_Path anImagePath(anImageFileStr);
OSD_File anImageFile(anImagePath);
anImageFile.Open(OSD_ReadOnly, OSD_Protection());
OSD_Path anAnimPath(anAnimationFileStr);
OSD_File anAnimFile(anAnimPath);
anAnimFile.Open(OSD_ReadOnly, OSD_Protection());
aLabel = anAnimationTool->AddAnimation(new TCollection_HAsciiString(aName), anImageFile, anAnimFile);
}
else if (aFromData)
{
aLabel = anAnimationTool->AddAnimation(new TCollection_HAsciiString(aName), anImage, anAnimation);
}
else
{
di << "Error: data can be taken either from a file or a data array.\n";
di << "Use: " << myCommand.use << "\n";
return 1;
}
TCollection_AsciiString anEntry;
TDF_Tool::Entry(aLabel, anEntry);
di << anEntry;
return 0;
}
//=======================================================================
//function : removeAnimation
//purpose : deletes an animation
//=======================================================================
static const cmd XAnimationRemove = {
"XAnimationRemove", 3, "XAnimationRemove Doc animation"
};
static Standard_Integer
removeAnimation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
static const cmd& myCommand = XAnimationRemove;
if (argc < myCommand.nargsreq)
{
di << "Use: " << myCommand.use << "\n";
return 1;
}
Handle(TDocStd_Document) aDoc;
DDocStd::GetDocument(argv[1], aDoc);
if (aDoc.IsNull())
{
return 1;
}
TCollection_ExtendedString anEntry = argv[2];
TDF_Label aLabel;
TDF_Tool::Label(aDoc->GetData(), anEntry, aLabel);
if (aLabel.IsNull())
{
di << anEntry << ": invalid animation entry.\n";
return 1;
}
Handle(XCAFDoc_AnimationTool) anAnimationTool = XCAFDoc_DocumentTool::AnimationTool(aDoc->Main());
if (!anAnimationTool->RemoveAnimation(aLabel))
{
di << "Error: couldn't remove animation.\n";
return 1;
}
return 0;
}
//=======================================================================
//function : animationDump
//purpose : dump an animation
//=======================================================================
static const cmd XAnimationDump = {
"XAnimationDump", 3, "XAnimationDump Doc animation"
};
static Standard_Integer
animationDump(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
static const cmd& myCommand = XAnimationDump;
if (argc < myCommand.nargsreq)
{
di << "Use: " << myCommand.use << "\n";
return 1;
}
Standard_Integer iarg = 0;
Handle(TDocStd_Document) aDoc;
DDocStd::GetDocument(argv[++iarg], aDoc);
if (aDoc.IsNull())
{
return 1;
}
TCollection_AsciiString anEntry = argv[++iarg];
TDF_Label aLabel;
TDF_Tool::Label(aDoc->GetData(), anEntry, aLabel);
if (aLabel.IsNull())
{
TCollection_AsciiString anEntry;
TDF_Tool::Entry(aLabel, anEntry);
di << anEntry << ": invalid animation entry.\n";
return 1;
}
Handle(XCAFDoc_AnimationTool) anAnimTool = XCAFDoc_DocumentTool::AnimationTool(aDoc->Main());
Handle(TCollection_HAsciiString) aName;
Handle(TColStd_HArray1OfByte) anImage, anAnimation;
anAnimTool->GetAnimation(aLabel, aName, anImage, anAnimation);
if (!aName.IsNull())
{
di <<"Name : " << aName->ToCString() << "\n";
}
static Standard_Integer theMaxLen = 64;
if (!anImage.IsNull())
{
di << "Image size : " << anImage->Length()<<"\n";
}
else
{
di << "Image is NULL \n ";
}
if (!anAnimation.IsNull())
{
di << "Animation size : " << anAnimation->Length()<<"\n";
}
else
{
di << "Animation is NULL \n ";
}
return 0;
}
//=======================================================================
//function : setName
//purpose : rename animation
//=======================================================================
static const cmd XAnimationSetName = {
"XAnimationSetName", 4, "XAnimationSetName Doc animation new_name"
};
static Standard_Integer
setName(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
static const cmd& myCommand = XAnimationSetName;
if (argc < myCommand.nargsreq)
{
di << "Use: " << myCommand.use << "\n";
return 1;
}
Handle(TDocStd_Document) aDoc;
DDocStd::GetDocument(argv[1], aDoc);
if (aDoc.IsNull())
{
return 1;
}
TCollection_ExtendedString anEntry = argv[2];
TDF_Label aLabel;
TDF_Tool::Label(aDoc->GetData(), anEntry, aLabel);
if (aLabel.IsNull())
{
di << anEntry << ": invalid animation entry.\n";
return 1;
}
Handle(XCAFDoc_AnimationTool) anAnimTool = XCAFDoc_DocumentTool::AnimationTool(aDoc->Main());
anAnimTool->SetName(aLabel, new TCollection_HAsciiString(argv[3]));
return 0;
}
//=======================================================================
//function : InitCommands
//purpose :
//=======================================================================
void XDEDRAW_Animations::InitCommands(Draw_Interpretor& di)
{
static Standard_Boolean initialized = Standard_False;
if (initialized)
{
return;
}
initialized = Standard_True;
Standard_CString g = "XDE Animations commands";
di.Add(XAnimations.name, XAnimations.use, __FILE__, animations, g);
di.Add(XAnimationAdd.name, XAnimationAdd.use, __FILE__, addAnimation, g);
di.Add(XAnimationRemove.name, XAnimationRemove.use, __FILE__, removeAnimation, g);
di.Add(XAnimationDump.name, XAnimationDump.use, __FILE__, animationDump, g);
di.Add(XAnimationSetName.name, XAnimationSetName.use, __FILE__, setName, g);
}

View File

@ -0,0 +1,35 @@
// Created on: 2017-10-02
// Created by: Elena Mozokhina
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XDEDRAW_Animations_HeaderFile
#define _XDEDRAW_Animations_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Draw_Interpretor.hxx>
//! Contains commands to work with notes
class XDEDRAW_Animations
{
public:
DEFINE_STANDARD_ALLOC
Standard_EXPORT static void InitCommands (Draw_Interpretor& theCommands);
};
#endif // _XDEDRAW_Animations_HeaderFile

View File

@ -47,3 +47,8 @@ XmlMXCAFDoc_ViewToolDriver.cxx
XmlMXCAFDoc_ViewToolDriver.hxx
XmlMXCAFDoc_VolumeDriver.cxx
XmlMXCAFDoc_VolumeDriver.hxx
XmlMXCAFDoc_AnimationDriver.cxx
XmlMXCAFDoc_AnimationDriver.hxx
XmlMXCAFDoc_AnimationToolDriver.cxx
XmlMXCAFDoc_AnimationToolDriver.hxx

View File

@ -0,0 +1,152 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <CDM_MessageDriver.hxx>
#include <Standard_Type.hxx>
#include <TCollection_HAsciiString.hxx>
#include <TColStd_HArray1OfByte.hxx>
#include <TDF_Attribute.hxx>
#include <XCAFDoc_Animation.hxx>
#include <XmlMXCAFDoc_AnimationDriver.hxx>
#include <XmlObjMgt.hxx>
#include <XmlObjMgt_Persistent.hxx>
#include <LDOM_OSStream.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_AnimationDriver,XmlMDF_ADriver)
IMPLEMENT_DOMSTRING (AnimationName, "name")
IMPLEMENT_DOMSTRING (ImageFirstIdx, "image_first_idx")
IMPLEMENT_DOMSTRING (ImageLastIdx, "image_last_idx")
IMPLEMENT_DOMSTRING(AnimationFirstIdx, "animation_first_idx")
IMPLEMENT_DOMSTRING(AnimationLastIdx, "animation_last_idx")
//=======================================================================
//function : XmlMXCAFDoc_AnimationDriver
//purpose : Constructor
//=======================================================================
XmlMXCAFDoc_AnimationDriver::XmlMXCAFDoc_AnimationDriver
(const Handle(CDM_MessageDriver)& theMsgDriver)
: XmlMDF_ADriver (theMsgDriver, "xcaf", "Animation")
{}
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) XmlMXCAFDoc_AnimationDriver::NewEmpty() const
{
return (new XCAFDoc_Animation());
}
//=======================================================================
//function : Paste
//purpose : persistent -> transient (retrieve)
//=======================================================================
Standard_Boolean XmlMXCAFDoc_AnimationDriver::Paste
(const XmlObjMgt_Persistent& theSource,
const Handle(TDF_Attribute)& theTarget,
XmlObjMgt_RRelocationTable& ) const
{
const XmlObjMgt_Element& anElement = theSource;
Handle(XCAFDoc_Animation) aTarget = Handle(XCAFDoc_Animation)::DownCast(theTarget);
if (aTarget.IsNull())
return Standard_False;
XmlObjMgt_DOMString aNameStr = anElement.getAttribute(::AnimationName());
XmlObjMgt_DOMString anImageFirstIdxStr = anElement.getAttribute(::ImageFirstIdx());
XmlObjMgt_DOMString anImageLastIdxStr = anElement.getAttribute(::ImageLastIdx());
XmlObjMgt_DOMString anAnimFirstIdxStr = anElement.getAttribute(::AnimationFirstIdx());
XmlObjMgt_DOMString anAnimLastIdxStr = anElement.getAttribute(::AnimationLastIdx());
if (aNameStr == NULL || anImageFirstIdxStr == NULL || anImageLastIdxStr == NULL ||
anAnimFirstIdxStr == NULL || anAnimLastIdxStr == NULL)
return Standard_False;
Standard_Integer anImageFirstIdx = 0;
Standard_Integer anImageLastIdx = 0;
if (!anImageFirstIdxStr.GetInteger(anImageFirstIdx) || !anImageLastIdxStr.GetInteger(anImageLastIdx))
return Standard_False;
Handle(TColStd_HArray1OfByte) anImage = new TColStd_HArray1OfByte(anImageFirstIdx, anImageLastIdx);
Standard_Integer anAnimFirstIdx = 0;
Standard_Integer anAnimLastIdx = 0;
if (!anAnimFirstIdxStr.GetInteger(anAnimFirstIdx) || !anAnimLastIdxStr.GetInteger(anAnimLastIdx))
return Standard_False;
Handle(TColStd_HArray1OfByte) anAnim = new TColStd_HArray1OfByte(anAnimFirstIdx, anAnimLastIdx);
const Standard_Integer aMaxSize = anImageLastIdx - anImageFirstIdx + anAnimLastIdx - anAnimFirstIdx + 2;
XmlObjMgt_DOMString aDataStr = XmlObjMgt::GetStringValue(theSource);
Standard_SStream anSS(aDataStr.GetString());
Standard_Byte aValue;
for (Standard_Integer i = anImageFirstIdx; i <= anImageLastIdx; ++i)
{
anSS >> aValue;
anImage->ChangeValue(i) = aValue;
}
for (Standard_Integer i = anAnimFirstIdx; i <= anAnimLastIdx; ++i)
{
anSS >> aValue;
anAnim->ChangeValue(i) = aValue;
}
aTarget->Set(new TCollection_HAsciiString(aNameStr.GetString()), anImage, anImage);
return Standard_True;
}
//=======================================================================
//function : Paste
//purpose : transient -> persistent (store)
//=======================================================================
void XmlMXCAFDoc_AnimationDriver::Paste(const Handle(TDF_Attribute)& theSource,
XmlObjMgt_Persistent& theTarget,
XmlObjMgt_SRelocationTable&) const
{
Handle(XCAFDoc_Animation) anAnimation = Handle(XCAFDoc_Animation)::DownCast(theSource);
if (anAnimation.IsNull())
return;
XmlObjMgt_DOMString aName = anAnimation->GetName()->String().ToCString();
theTarget.Element().setAttribute(::AnimationName(), aName);
Handle(TColStd_HArray1OfByte) anImage = anAnimation->GetImage();
Handle(TColStd_HArray1OfByte) anAnim = anAnimation->GetAnimation();
if (anImage.IsNull() || anAnim.IsNull())
{
return;
}
const Standard_Integer anImageFirstInd = anImage->Lower();
const Standard_Integer anImageLastInd = anAnim->Upper();
const Standard_Integer anAnimFirstInd = anAnim->Lower();
const Standard_Integer anAnimLastInd = anAnim->Upper();
const Standard_Integer aMaxSize = anImageLastInd - anImageFirstInd + anAnimLastInd - anAnimFirstInd + 2;
LDOM_OSStream anOSS(aMaxSize);
for (Standard_Integer i = anImageFirstInd; i <= anImageLastInd; ++i)
{
anOSS << std::hex << anImage->Value(i);
}
for (Standard_Integer i = anAnimFirstInd; i <= anAnimLastInd; ++i)
{
anOSS << std::hex << anAnim->Value(i);
}
Standard_Character* dump = (Standard_Character*)anOSS.str(); // copying! Don't forget to delete it.
XmlObjMgt::SetStringValue(theTarget, dump, Standard_True);
delete[] dump;
}

View File

@ -0,0 +1,51 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XmlMXCAFDoc_AnimationDriver_HeaderFile
#define _XmlMXCAFDoc_AnimationDriver_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <XmlMDF_ADriver.hxx>
#include <Standard_Boolean.hxx>
#include <XmlObjMgt_RRelocationTable.hxx>
#include <XmlObjMgt_SRelocationTable.hxx>
class CDM_MessageDriver;
class TDF_Attribute;
class XmlObjMgt_Persistent;
class XmlMXCAFDoc_AnimationDriver;
DEFINE_STANDARD_HANDLE(XmlMXCAFDoc_AnimationDriver, XmlMDF_ADriver)
//! Attribute Driver.
class XmlMXCAFDoc_AnimationDriver : public XmlMDF_ADriver
{
public:
Standard_EXPORT XmlMXCAFDoc_AnimationDriver(const Handle(CDM_MessageDriver)& theMessageDriver);
Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT Standard_Boolean Paste (const XmlObjMgt_Persistent& Source, const Handle(TDF_Attribute)& Target, XmlObjMgt_RRelocationTable& RelocTable) const Standard_OVERRIDE;
Standard_EXPORT void Paste (const Handle(TDF_Attribute)& Source, XmlObjMgt_Persistent& Target, XmlObjMgt_SRelocationTable& RelocTable) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(XmlMXCAFDoc_AnimationDriver,XmlMDF_ADriver)
};
#endif // _XmlMXCAFDoc_AnimationDriver_HeaderFile

View File

@ -0,0 +1,63 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <CDM_MessageDriver.hxx>
#include <Standard_Type.hxx>
#include <TDF_Attribute.hxx>
#include <XCAFDoc_AnimationTool.hxx>
#include <XmlMXCAFDoc_AnimationToolDriver.hxx>
#include <XmlObjMgt_Persistent.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_AnimationToolDriver,XmlMDF_ADriver)
//=======================================================================
//function :
//purpose :
//=======================================================================
XmlMXCAFDoc_AnimationToolDriver::XmlMXCAFDoc_AnimationToolDriver
(const Handle(CDM_MessageDriver)& theMsgDriver)
: XmlMDF_ADriver (theMsgDriver, "xcaf", "AnimationTool")
{
}
//=======================================================================
//function :
//purpose :
//=======================================================================
Handle(TDF_Attribute) XmlMXCAFDoc_AnimationToolDriver::NewEmpty() const
{
return new XCAFDoc_AnimationTool();
}
//=======================================================================
//function :
//purpose :
//=======================================================================
Standard_Boolean XmlMXCAFDoc_AnimationToolDriver::Paste(const XmlObjMgt_Persistent& ,
const Handle(TDF_Attribute)& ,
XmlObjMgt_RRelocationTable& ) const
{
return Standard_True;
}
//=======================================================================
//function :
//purpose :
//=======================================================================
void XmlMXCAFDoc_AnimationToolDriver::Paste(const Handle(TDF_Attribute)& ,
XmlObjMgt_Persistent& ,
XmlObjMgt_SRelocationTable& ) const
{
}

View File

@ -0,0 +1,52 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XmlMXCAFDoc_AnimationToolDriver_HeaderFile
#define _XmlMXCAFDoc_AnimationToolDriver_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <XmlMDF_ADriver.hxx>
#include <Standard_Boolean.hxx>
#include <XmlObjMgt_RRelocationTable.hxx>
#include <XmlObjMgt_SRelocationTable.hxx>
class CDM_MessageDriver;
class TDF_Attribute;
class XmlObjMgt_Persistent;
class XmlMXCAFDoc_AnimationToolDriver;
DEFINE_STANDARD_HANDLE(XmlMXCAFDoc_AnimationToolDriver, XmlMDF_ADriver)
//! Attribute Driver.
class XmlMXCAFDoc_AnimationToolDriver : public XmlMDF_ADriver
{
public:
Standard_EXPORT XmlMXCAFDoc_AnimationToolDriver(const Handle(CDM_MessageDriver)& theMsgDriver);
Standard_EXPORT virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean Paste (const XmlObjMgt_Persistent& theSource, const Handle(TDF_Attribute)& theTarget, XmlObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE;
Standard_EXPORT virtual void Paste (const Handle(TDF_Attribute)& theSource, XmlObjMgt_Persistent& theTarget, XmlObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(XmlMXCAFDoc_AnimationToolDriver,XmlMDF_ADriver)
};
#endif // _XmlMXCAFDoc_AnimationToolDriver_HeaderFile