From b87a2fa42c83a24e49d1228ebe3dcdd036405968 Mon Sep 17 00:00:00 2001 From: snn Date: Mon, 13 Feb 2017 17:38:09 +0300 Subject: [PATCH] XCAF: comment and bin data note attributes added --- src/BinMXCAFDoc/BinMXCAFDoc.cxx | 6 +- .../BinMXCAFDoc_NoteBinDataDriver.cxx | 85 ++++++++++++ .../BinMXCAFDoc_NoteBinDataDriver.hxx | 44 ++++++ .../BinMXCAFDoc_NoteCommentDriver.cxx | 81 +++++++++++ .../BinMXCAFDoc_NoteCommentDriver.hxx | 44 ++++++ src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.cxx | 35 ++++- src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.hxx | 5 + src/BinMXCAFDoc/FILES | 4 + src/XCAFDoc/FILES | 4 + src/XCAFDoc/XCAFDoc.cxx | 11 ++ src/XCAFDoc/XCAFDoc.hxx | 5 +- src/XCAFDoc/XCAFDoc_Note.cxx | 58 ++++++-- src/XCAFDoc/XCAFDoc_Note.hxx | 25 +++- src/XCAFDoc/XCAFDoc_NoteBinData.cxx | 128 ++++++++++++++++++ src/XCAFDoc/XCAFDoc_NoteBinData.hxx | 73 ++++++++++ src/XCAFDoc/XCAFDoc_NoteComment.cxx | 98 ++++++++++++++ src/XCAFDoc/XCAFDoc_NoteComment.hxx | 63 +++++++++ src/XCAFDoc/XCAFDoc_NotesTool.cxx | 27 ++++ src/XCAFDoc/XCAFDoc_NotesTool.hxx | 14 +- 19 files changed, 789 insertions(+), 21 deletions(-) create mode 100644 src/BinMXCAFDoc/BinMXCAFDoc_NoteBinDataDriver.cxx create mode 100644 src/BinMXCAFDoc/BinMXCAFDoc_NoteBinDataDriver.hxx create mode 100644 src/BinMXCAFDoc/BinMXCAFDoc_NoteCommentDriver.cxx create mode 100644 src/BinMXCAFDoc/BinMXCAFDoc_NoteCommentDriver.hxx create mode 100644 src/XCAFDoc/XCAFDoc_NoteBinData.cxx create mode 100644 src/XCAFDoc/XCAFDoc_NoteBinData.hxx create mode 100644 src/XCAFDoc/XCAFDoc_NoteComment.cxx create mode 100644 src/XCAFDoc/XCAFDoc_NoteComment.hxx diff --git a/src/BinMXCAFDoc/BinMXCAFDoc.cxx b/src/BinMXCAFDoc/BinMXCAFDoc.cxx index 5e9c340dc6..5a97870657 100644 --- a/src/BinMXCAFDoc/BinMXCAFDoc.cxx +++ b/src/BinMXCAFDoc/BinMXCAFDoc.cxx @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include #include #include @@ -73,7 +75,9 @@ void BinMXCAFDoc::AddDrivers(const Handle(BinMDF_ADriverTable)& theDriverTable, theDriverTable->AddDriver( new BinMXCAFDoc_DimTolDriver (theMsgDrv)); theDriverTable->AddDriver( new BinMXCAFDoc_MaterialDriver (theMsgDrv)); theDriverTable->AddDriver( new BinMXCAFDoc_NoteDriver (theMsgDrv)); - theDriverTable->AddDriver(new BinMXCAFDoc_ViewDriver (theMsgDrv)); + theDriverTable->AddDriver( new BinMXCAFDoc_NoteBinDataDriver (theMsgDrv)); + theDriverTable->AddDriver( new BinMXCAFDoc_NoteCommentDriver (theMsgDrv)); + theDriverTable->AddDriver (new BinMXCAFDoc_ViewDriver (theMsgDrv)); theDriverTable->AddDriver( new BinMXCAFDoc_ColorToolDriver (theMsgDrv)); theDriverTable->AddDriver( new BinMXCAFDoc_DocumentToolDriver(theMsgDrv)); diff --git a/src/BinMXCAFDoc/BinMXCAFDoc_NoteBinDataDriver.cxx b/src/BinMXCAFDoc/BinMXCAFDoc_NoteBinDataDriver.cxx new file mode 100644 index 0000000000..f7dce26f75 --- /dev/null +++ b/src/BinMXCAFDoc/BinMXCAFDoc_NoteBinDataDriver.cxx @@ -0,0 +1,85 @@ +// Created on: 2017-02-13 +// Created by: Eugeny NIKONOV +// Copyright (c) 2005-2017 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 +#include +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(BinMXCAFDoc_NoteBinDataDriver, BinMXCAFDoc_NoteDriver) + +//======================================================================= +//function : +//purpose : +//======================================================================= +BinMXCAFDoc_NoteBinDataDriver::BinMXCAFDoc_NoteBinDataDriver(const Handle(CDM_MessageDriver)& theMsgDriver) + : BinMXCAFDoc_NoteDriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_NoteBinData)->Name()) +{ +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +Handle(TDF_Attribute) BinMXCAFDoc_NoteBinDataDriver::NewEmpty() const +{ + return new XCAFDoc_NoteBinData(); +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +Standard_Boolean BinMXCAFDoc_NoteBinDataDriver::Paste(const BinObjMgt_Persistent& theSource, + const Handle(TDF_Attribute)& theTarget, + BinObjMgt_RRelocationTable& theRelocTable) const +{ + if (!BinMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable)) + return Standard_False; + + Handle(XCAFDoc_NoteBinData) aNoteBinData = Handle(XCAFDoc_NoteBinData)::DownCast(theTarget); + + TCollection_AsciiString aData, aMIMEtype; + if (!(theSource >> aData >> aMIMEtype)) + return Standard_False; + + aNoteBinData->Set(new TCollection_HAsciiString(aData), + new TCollection_HAsciiString(aMIMEtype)); + + return Standard_True; +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +void BinMXCAFDoc_NoteBinDataDriver::Paste(const Handle(TDF_Attribute)& theSource, + BinObjMgt_Persistent& theTarget, + BinObjMgt_SRelocationTable& theRelocTable) const +{ + BinMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable); + + Handle(XCAFDoc_NoteBinData) aNoteBinData = Handle(XCAFDoc_NoteBinData)::DownCast(theSource); + + Handle(TCollection_HAsciiString) aData = aNoteBinData->Data(); + Handle(TCollection_HAsciiString) aMIMEtype = aNoteBinData->MIMEtype(); + theTarget + << (aData ? aData->String() : TCollection_AsciiString("")) + << (aMIMEtype ? aMIMEtype->String() : TCollection_AsciiString("")) + ; +} diff --git a/src/BinMXCAFDoc/BinMXCAFDoc_NoteBinDataDriver.hxx b/src/BinMXCAFDoc/BinMXCAFDoc_NoteBinDataDriver.hxx new file mode 100644 index 0000000000..422f79784d --- /dev/null +++ b/src/BinMXCAFDoc/BinMXCAFDoc_NoteBinDataDriver.hxx @@ -0,0 +1,44 @@ +// Created on: 2017-02-13 +// Created by: Sergey NIKONOV +// Copyright (c) 2005-2017 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_NoteBinDataDriver_HeaderFile +#define _BinMXCAFDoc_NoteBinDataDriver_HeaderFile + +#include + +class BinMXCAFDoc_NoteBinDataDriver; +DEFINE_STANDARD_HANDLE(BinMXCAFDoc_NoteBinDataDriver, BinMXCAFDoc_NoteDriver) + +class BinMXCAFDoc_NoteBinDataDriver : public BinMXCAFDoc_NoteDriver +{ +public: + + Standard_EXPORT BinMXCAFDoc_NoteBinDataDriver(const Handle(CDM_MessageDriver)& theMsgDriver); + + Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE; + + Standard_EXPORT Standard_Boolean Paste (const BinObjMgt_Persistent& theSource, + const Handle(TDF_Attribute)& theTarget, + BinObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE; + + Standard_EXPORT void Paste (const Handle(TDF_Attribute)& theSource, + BinObjMgt_Persistent& theTarget, + BinObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE; + + DEFINE_STANDARD_RTTIEXT(BinMXCAFDoc_NoteBinDataDriver, BinMXCAFDoc_NoteDriver) + +}; + +#endif // _BinMXCAFDoc_NoteBinDataDriver_HeaderFile diff --git a/src/BinMXCAFDoc/BinMXCAFDoc_NoteCommentDriver.cxx b/src/BinMXCAFDoc/BinMXCAFDoc_NoteCommentDriver.cxx new file mode 100644 index 0000000000..d1e9fc1265 --- /dev/null +++ b/src/BinMXCAFDoc/BinMXCAFDoc_NoteCommentDriver.cxx @@ -0,0 +1,81 @@ +// Created on: 2017-02-13 +// Created by: Eugeny NIKONOV +// Copyright (c) 2005-2017 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 +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(BinMXCAFDoc_NoteCommentDriver, BinMXCAFDoc_NoteDriver) + +//======================================================================= +//function : +//purpose : +//======================================================================= +BinMXCAFDoc_NoteCommentDriver::BinMXCAFDoc_NoteCommentDriver(const Handle(CDM_MessageDriver)& theMsgDriver) + : BinMXCAFDoc_NoteDriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_NoteComment)->Name()) +{ +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +Handle(TDF_Attribute) BinMXCAFDoc_NoteCommentDriver::NewEmpty() const +{ + return new XCAFDoc_NoteComment(); +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +Standard_Boolean BinMXCAFDoc_NoteCommentDriver::Paste(const BinObjMgt_Persistent& theSource, + const Handle(TDF_Attribute)& theTarget, + BinObjMgt_RRelocationTable& theRelocTable) const +{ + if (!BinMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable)) + return Standard_False; + + Handle(XCAFDoc_NoteComment) aNoteComment = Handle(XCAFDoc_NoteComment)::DownCast(theTarget); + + TCollection_ExtendedString aComment; + if (!(theSource >> aComment)) + return Standard_False; + + aNoteComment->Set(new TCollection_HExtendedString(aComment)); + + return Standard_True; +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +void BinMXCAFDoc_NoteCommentDriver::Paste(const Handle(TDF_Attribute)& theSource, + BinObjMgt_Persistent& theTarget, + BinObjMgt_SRelocationTable& theRelocTable) const +{ + BinMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable); + + Handle(XCAFDoc_NoteComment) aNoteComment = Handle(XCAFDoc_NoteComment)::DownCast(theSource); + + Handle(TCollection_HExtendedString) aComment = aNoteComment->TimeStamp(); + theTarget + << (aComment ? aComment->String() : TCollection_ExtendedString("")) + ; +} diff --git a/src/BinMXCAFDoc/BinMXCAFDoc_NoteCommentDriver.hxx b/src/BinMXCAFDoc/BinMXCAFDoc_NoteCommentDriver.hxx new file mode 100644 index 0000000000..730735e278 --- /dev/null +++ b/src/BinMXCAFDoc/BinMXCAFDoc_NoteCommentDriver.hxx @@ -0,0 +1,44 @@ +// Created on: 2017-02-13 +// Created by: Sergey NIKONOV +// Copyright (c) 2005-2017 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_NoteCommentDriver_HeaderFile +#define _BinMXCAFDoc_NoteCommentDriver_HeaderFile + +#include + +class BinMXCAFDoc_NoteCommentDriver; +DEFINE_STANDARD_HANDLE(BinMXCAFDoc_NoteCommentDriver, BinMXCAFDoc_NoteDriver) + +class BinMXCAFDoc_NoteCommentDriver : public BinMXCAFDoc_NoteDriver +{ +public: + + Standard_EXPORT BinMXCAFDoc_NoteCommentDriver(const Handle(CDM_MessageDriver)& theMsgDriver); + + Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE; + + Standard_EXPORT Standard_Boolean Paste (const BinObjMgt_Persistent& theSource, + const Handle(TDF_Attribute)& theTarget, + BinObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE; + + Standard_EXPORT void Paste (const Handle(TDF_Attribute)& theSource, + BinObjMgt_Persistent& theTarget, + BinObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE; + + DEFINE_STANDARD_RTTIEXT(BinMXCAFDoc_NoteCommentDriver, BinMXCAFDoc_NoteDriver) + +}; + +#endif // _BinMXCAFDoc_NoteCommentDriver_HeaderFile diff --git a/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.cxx b/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.cxx index c950ecca65..64e3a55bd8 100644 --- a/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.cxx +++ b/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.cxx @@ -31,6 +31,17 @@ BinMXCAFDoc_NoteDriver::BinMXCAFDoc_NoteDriver(const Handle(CDM_MessageDriver)& { } +//======================================================================= +//function : +//purpose : +//======================================================================= +BinMXCAFDoc_NoteDriver::BinMXCAFDoc_NoteDriver(const Handle(CDM_MessageDriver)& theMsgDriver, + Standard_CString theName) + : BinMDF_ADriver(theMsgDriver, theName) +{ + +} + //======================================================================= //function : //purpose : @@ -44,10 +55,19 @@ Handle(TDF_Attribute) BinMXCAFDoc_NoteDriver::NewEmpty() const //function : //purpose : //======================================================================= -Standard_Boolean BinMXCAFDoc_NoteDriver::Paste(const BinObjMgt_Persistent& /*theSource*/, - const Handle(TDF_Attribute)& /*theTarget*/, +Standard_Boolean BinMXCAFDoc_NoteDriver::Paste(const BinObjMgt_Persistent& theSource, + const Handle(TDF_Attribute)& theTarget, BinObjMgt_RRelocationTable& /*theRelocTable*/) const { + Handle(XCAFDoc_Note) aNote = Handle(XCAFDoc_Note)::DownCast(theTarget); + + TCollection_ExtendedString aUserName, aTimeStamp; + if (!(theSource >> aUserName >> aTimeStamp)) + return Standard_False; + + aNote->Set(new TCollection_HExtendedString(aUserName), + new TCollection_HExtendedString(aTimeStamp)); + return Standard_True; } @@ -55,8 +75,15 @@ Standard_Boolean BinMXCAFDoc_NoteDriver::Paste(const BinObjMgt_Persistent& /*th //function : //purpose : //======================================================================= -void BinMXCAFDoc_NoteDriver::Paste(const Handle(TDF_Attribute)& /*theSource*/, - BinObjMgt_Persistent& /*theTarget*/, +void BinMXCAFDoc_NoteDriver::Paste(const Handle(TDF_Attribute)& theSource, + BinObjMgt_Persistent& theTarget, BinObjMgt_SRelocationTable& /*theRelocTable*/) const { + Handle(XCAFDoc_Note) aNote = Handle(XCAFDoc_Note)::DownCast(theSource); + Handle(TCollection_HExtendedString) aUserName = aNote->UserName(); + Handle(TCollection_HExtendedString) aTimeStamp = aNote->TimeStamp(); + theTarget + << (aUserName ? aUserName->String() : TCollection_ExtendedString("")) + << (aTimeStamp ? aTimeStamp->String() : TCollection_ExtendedString("")) + ; } diff --git a/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.hxx b/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.hxx index 18b94160c5..8dc1b75c2d 100644 --- a/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.hxx +++ b/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.hxx @@ -49,6 +49,11 @@ public: DEFINE_STANDARD_RTTIEXT(BinMXCAFDoc_NoteDriver, BinMDF_ADriver) +protected: + + Standard_EXPORT BinMXCAFDoc_NoteDriver(const Handle(CDM_MessageDriver)& theMsgDriver, + Standard_CString theName); + }; #endif // _BinMXCAFDoc_NoteDriver_HeaderFile diff --git a/src/BinMXCAFDoc/FILES b/src/BinMXCAFDoc/FILES index aa1a13087e..2e3210ec57 100644 --- a/src/BinMXCAFDoc/FILES +++ b/src/BinMXCAFDoc/FILES @@ -35,6 +35,10 @@ BinMXCAFDoc_MaterialToolDriver.cxx BinMXCAFDoc_MaterialToolDriver.hxx BinMXCAFDoc_NoteDriver.cxx BinMXCAFDoc_NoteDriver.hxx +BinMXCAFDoc_NoteCommentDriver.cxx +BinMXCAFDoc_NoteCommentDriver.hxx +BinMXCAFDoc_NoteBinDataDriver.cxx +BinMXCAFDoc_NoteBinDataDriver.hxx BinMXCAFDoc_NotesToolDriver.cxx BinMXCAFDoc_NotesToolDriver.hxx BinMXCAFDoc_ShapeToolDriver.cxx diff --git a/src/XCAFDoc/FILES b/src/XCAFDoc/FILES index 820b8ef31f..eb566e35be 100755 --- a/src/XCAFDoc/FILES +++ b/src/XCAFDoc/FILES @@ -42,6 +42,10 @@ XCAFDoc_MaterialTool.cxx XCAFDoc_MaterialTool.hxx XCAFDoc_Note.cxx XCAFDoc_Note.hxx +XCAFDoc_NoteComment.cxx +XCAFDoc_NoteComment.hxx +XCAFDoc_NoteBinData.cxx +XCAFDoc_NoteBinData.hxx XCAFDoc_NotesTool.cxx XCAFDoc_NotesTool.hxx XCAFDoc_ShapeMapTool.cxx diff --git a/src/XCAFDoc/XCAFDoc.cxx b/src/XCAFDoc/XCAFDoc.cxx index 2299ae3293..37490006d5 100644 --- a/src/XCAFDoc/XCAFDoc.cxx +++ b/src/XCAFDoc/XCAFDoc.cxx @@ -172,6 +172,17 @@ Standard_GUID XCAFDoc::MaterialRefGUID () } +//======================================================================= +//function : NoteRefGUID +//purpose : +//======================================================================= + +Standard_GUID XCAFDoc::NoteRefGUID() +{ + static Standard_GUID ID ("F3599E50-F84A-493e-8D1B-1284E79322F1"); + return ID; +} + //======================================================================= //function : InvisibleGUID //purpose : diff --git a/src/XCAFDoc/XCAFDoc.hxx b/src/XCAFDoc/XCAFDoc.hxx index 1812029d9e..9532983eb1 100644 --- a/src/XCAFDoc/XCAFDoc.hxx +++ b/src/XCAFDoc/XCAFDoc.hxx @@ -97,7 +97,10 @@ public: Standard_EXPORT static Standard_GUID LayerRefGUID(); Standard_EXPORT static Standard_GUID MaterialRefGUID(); - + + //! Return GUIDs for TreeNode representing types of Note + Standard_EXPORT static Standard_GUID NoteRefGUID(); + Standard_EXPORT static Standard_GUID InvisibleGUID(); //! Returns GUID for UAttribute identifying external reference on no-step file diff --git a/src/XCAFDoc/XCAFDoc_Note.cxx b/src/XCAFDoc/XCAFDoc_Note.cxx index f912eea9f9..2fe5b76623 100644 --- a/src/XCAFDoc/XCAFDoc_Note.cxx +++ b/src/XCAFDoc/XCAFDoc_Note.cxx @@ -25,21 +25,49 @@ const Standard_GUID& XCAFDoc_Note::GetID() return s_ID; } -Handle(XCAFDoc_Note) XCAFDoc_Note::Set(const TDF_Label& theLabel) +Standard_Boolean XCAFDoc_Note::IsMine(const TDF_Label& theLabel) { - Handle(XCAFDoc_Note) aTool; - if (!theLabel.FindAttribute(XCAFDoc_Note::GetID(), aTool)) + Handle(XCAFDoc_Note) anAttr; + return (!theLabel.IsNull() && theLabel.FindAttribute(XCAFDoc_Note::GetID(), anAttr)); +} + +Handle(XCAFDoc_Note) XCAFDoc_Note::Set(const TDF_Label& theLabel, + const Handle(TCollection_HExtendedString)& theUserName, + const Handle(TCollection_HExtendedString)& theTimeStamp) +{ + Handle(XCAFDoc_Note) aNote; + if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_Note::GetID(), aNote)) { - aTool = new XCAFDoc_Note(); - theLabel.AddAttribute(aTool); + aNote = new XCAFDoc_Note(); + aNote->Set(theUserName, theTimeStamp); + theLabel.AddAttribute(aNote); } - return aTool; + return aNote; } XCAFDoc_Note::XCAFDoc_Note() { } +void XCAFDoc_Note::Set(const Handle(TCollection_HExtendedString)& theUserName, + const Handle(TCollection_HExtendedString)& theTimeStamp) +{ + Backup(); + + myUserName = theUserName; + myTimeStamp = theTimeStamp; +} + +Handle(TCollection_HExtendedString) XCAFDoc_Note::UserName() const +{ + return myUserName; +} + +Handle(TCollection_HExtendedString) XCAFDoc_Note::TimeStamp() const +{ + return myTimeStamp; +} + const Standard_GUID& XCAFDoc_Note::ID() const { return GetID(); @@ -50,11 +78,25 @@ Handle(TDF_Attribute) XCAFDoc_Note::NewEmpty() const return new XCAFDoc_Note(); } -void XCAFDoc_Note::Restore(const Handle(TDF_Attribute)& /*theAttr*/) +void XCAFDoc_Note::Restore(const Handle(TDF_Attribute)& theAttr) { + myUserName = Handle(XCAFDoc_Note)::DownCast(theAttr)->myUserName; + myTimeStamp = Handle(XCAFDoc_Note)::DownCast(theAttr)->myTimeStamp; } -void XCAFDoc_Note::Paste(const Handle(TDF_Attribute)& /*theAttrInto*/, +void XCAFDoc_Note::Paste(const Handle(TDF_Attribute)& theAttrInto, const Handle(TDF_RelocationTable)& /*theRT*/) const { + Handle(XCAFDoc_Note)::DownCast(theAttrInto)->Set(myUserName, myTimeStamp); +} + +Standard_OStream& XCAFDoc_Note::Dump(Standard_OStream& theOS) const +{ + theOS + << "Note : " + << (myUserName ? myUserName->String() : "") + << " on " + << (myTimeStamp ? myTimeStamp->String() : "") + ; + return theOS; } diff --git a/src/XCAFDoc/XCAFDoc_Note.hxx b/src/XCAFDoc/XCAFDoc_Note.hxx index c23e29ce60..3102721411 100644 --- a/src/XCAFDoc/XCAFDoc_Note.hxx +++ b/src/XCAFDoc/XCAFDoc_Note.hxx @@ -18,6 +18,8 @@ #include #include +#include +#include #include class Standard_GUID; @@ -32,14 +34,23 @@ public: DEFINE_STANDARD_RTTIEXT(XCAFDoc_Note, TDF_Attribute) - Standard_EXPORT static const Standard_GUID& GetID(); + Standard_EXPORT static const Standard_GUID& GetID(); - //! Create (if not exist) NotesTool from XCAFDoc on . - Standard_EXPORT static Handle(XCAFDoc_Note) Set(const TDF_Label& theLabel); + Standard_EXPORT static Standard_Boolean IsMine(const TDF_Label& theLabel); + + Standard_EXPORT static Handle(XCAFDoc_Note) Set(const TDF_Label& theLabel, + const Handle(TCollection_HExtendedString)& theUserName, + const Handle(TCollection_HExtendedString)& theTimeStamp); - //! Creates an empty tool Standard_EXPORT XCAFDoc_Note(); + Standard_EXPORT void Set(const Handle(TCollection_HExtendedString)& theUserName, + const Handle(TCollection_HExtendedString)& theTimeStamp); + + Standard_EXPORT Handle(TCollection_HExtendedString) UserName() const; + + Standard_EXPORT Handle(TCollection_HExtendedString) TimeStamp() const; + public: Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE; @@ -51,6 +62,12 @@ public: Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theAttrInto, const Handle(TDF_RelocationTable)& theRT) const Standard_OVERRIDE; + Standard_EXPORT Standard_OStream& Dump(Standard_OStream& theOS) const Standard_OVERRIDE; + +protected: + + Handle(TCollection_HExtendedString) myUserName; + Handle(TCollection_HExtendedString) myTimeStamp; }; #endif // _XCAFDoc_Note_HeaderFile diff --git a/src/XCAFDoc/XCAFDoc_NoteBinData.cxx b/src/XCAFDoc/XCAFDoc_NoteBinData.cxx new file mode 100644 index 0000000000..d4875e51a3 --- /dev/null +++ b/src/XCAFDoc/XCAFDoc_NoteBinData.cxx @@ -0,0 +1,128 @@ +// Created on: 2017-02-13 +// Created by: Sergey NIKONOV +// Copyright (c) 2000-2017 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 +#include +#include +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_NoteBinData, XCAFDoc_Note) + +const Standard_GUID& XCAFDoc_NoteBinData::GetID() +{ + static Standard_GUID s_ID("E9055501-F0FC-4864-BE4B-284FDA7DDEAC"); + return s_ID; +} + +Standard_Boolean XCAFDoc_NoteBinData::IsMine(const TDF_Label& theLabel) +{ + Handle(XCAFDoc_NoteBinData) anAttr; + return (!theLabel.IsNull() && theLabel.FindAttribute(XCAFDoc_NoteBinData::GetID(), anAttr)); +} + +Handle(XCAFDoc_NoteBinData) XCAFDoc_NoteBinData::Set(const TDF_Label& theLabel, + const Handle(TCollection_HExtendedString)& theUserName, + const Handle(TCollection_HExtendedString)& theTimeStamp, + OSD_File& theFile, + const Handle(TCollection_HAsciiString)& theMIMEtype) +{ + Handle(XCAFDoc_NoteBinData) aNoteBinData; + if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_Note::GetID(), aNoteBinData)) + { + aNoteBinData = new XCAFDoc_NoteBinData(); + aNoteBinData->XCAFDoc_Note::Set(theUserName, theTimeStamp); + aNoteBinData->Set(theFile, theMIMEtype); + theLabel.AddAttribute(aNoteBinData); + } + return aNoteBinData; +} + +XCAFDoc_NoteBinData::XCAFDoc_NoteBinData() +{ +} + +void XCAFDoc_NoteBinData::Set(OSD_File& theFile, + const Handle(TCollection_HAsciiString)& theMIMEtype) +{ + if (!theFile.IsOpen() || !theFile.IsReadable()) + return; + + TCollection_AsciiString aStr; + theFile.Read(aStr, theFile.Size()); + + Backup(); + + myData.reset(new TCollection_HAsciiString(aStr)); + myMIMEtype = theMIMEtype; +} + +void XCAFDoc_NoteBinData::Set(const Handle(TCollection_HAsciiString)& theData, + const Handle(TCollection_HAsciiString)& theMIMEtype) +{ + Backup(); + + myData = theData; + myMIMEtype = theMIMEtype; +} + +Handle(TCollection_HAsciiString) XCAFDoc_NoteBinData::Data() const +{ + return myData; +} + +Handle(TCollection_HAsciiString) XCAFDoc_NoteBinData::MIMEtype() const +{ + return myMIMEtype; +} + +const Standard_GUID& XCAFDoc_NoteBinData::ID() const +{ + return GetID(); +} + +Handle(TDF_Attribute) XCAFDoc_NoteBinData::NewEmpty() const +{ + return new XCAFDoc_Note(); +} + +void XCAFDoc_NoteBinData::Restore(const Handle(TDF_Attribute)& theAttr) +{ + XCAFDoc_Note::Restore(theAttr); + myData = Handle(XCAFDoc_NoteBinData)::DownCast(theAttr)->myData; + myMIMEtype = Handle(XCAFDoc_NoteBinData)::DownCast(theAttr)->myMIMEtype; +} + +void XCAFDoc_NoteBinData::Paste(const Handle(TDF_Attribute)& theAttrInto, + const Handle(TDF_RelocationTable)& theRT) const +{ + XCAFDoc_Note::Paste(theAttrInto, theRT); + Handle(XCAFDoc_NoteBinData)::DownCast(theAttrInto)->Set(myData, myMIMEtype); +} + +Standard_OStream& XCAFDoc_NoteBinData::Dump(Standard_OStream& theOS) const +{ + XCAFDoc_Note::Dump(theOS); + theOS + << "\n" + << "MIME type : " + << (myMIMEtype ? myMIMEtype->String() : "") + << "\n" + << "" + << (myData ? myData->String() : "") + << "" + ; + return theOS; +} diff --git a/src/XCAFDoc/XCAFDoc_NoteBinData.hxx b/src/XCAFDoc/XCAFDoc_NoteBinData.hxx new file mode 100644 index 0000000000..64c6ce7fde --- /dev/null +++ b/src/XCAFDoc/XCAFDoc_NoteBinData.hxx @@ -0,0 +1,73 @@ +// Created on: 2017-02-13 +// Created by: Sergey NIKONOV +// Copyright (c) 2000-2017 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_NoteBinData_HeaderFile +#define _XCAFDoc_NoteBinData_HeaderFile + +#include + +class OSD_File; +class TCollection_HAsciiString; + +class XCAFDoc_NoteBinData; +DEFINE_STANDARD_HANDLE(XCAFDoc_NoteBinData, XCAFDoc_Note) + +class XCAFDoc_NoteBinData : public XCAFDoc_Note +{ +public: + + DEFINE_STANDARD_RTTIEXT(XCAFDoc_NoteBinData, XCAFDoc_Note) + + Standard_EXPORT static const Standard_GUID& GetID(); + + Standard_EXPORT static Standard_Boolean IsMine(const TDF_Label& theLabel); + + Standard_EXPORT static Handle(XCAFDoc_NoteBinData) Set(const TDF_Label& theLabel, + const Handle(TCollection_HExtendedString)& theUserName, + const Handle(TCollection_HExtendedString)& theTimeStamp, + OSD_File& theFile, + const Handle(TCollection_HAsciiString)& theMIMEtype); + + Standard_EXPORT XCAFDoc_NoteBinData(); + + Standard_EXPORT void Set(OSD_File& theFile, + const Handle(TCollection_HAsciiString)& theMIMEtype); + + Standard_EXPORT void Set(const Handle(TCollection_HAsciiString)& theData, + const Handle(TCollection_HAsciiString)& theMIMEtype); + + Standard_EXPORT Handle(TCollection_HAsciiString) Data() const; + Standard_EXPORT Handle(TCollection_HAsciiString) MIMEtype() const; + +public: + + Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE; + + Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE; + + Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theAttrFrom) Standard_OVERRIDE; + + Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theAttrInto, + const Handle(TDF_RelocationTable)& theRT) const Standard_OVERRIDE; + + Standard_EXPORT Standard_OStream& Dump(Standard_OStream& theOS) const Standard_OVERRIDE; + +protected: + + Handle(TCollection_HAsciiString) myData; + Handle(TCollection_HAsciiString) myMIMEtype; +}; + +#endif // _XCAFDoc_NoteBinData_HeaderFile diff --git a/src/XCAFDoc/XCAFDoc_NoteComment.cxx b/src/XCAFDoc/XCAFDoc_NoteComment.cxx new file mode 100644 index 0000000000..23e9f56834 --- /dev/null +++ b/src/XCAFDoc/XCAFDoc_NoteComment.cxx @@ -0,0 +1,98 @@ +// Created on: 2017-02-13 +// Created by: Sergey NIKONOV +// Copyright (c) 2000-2017 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 +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_NoteComment, XCAFDoc_Note) + +const Standard_GUID& XCAFDoc_NoteComment::GetID() +{ + static Standard_GUID s_ID("FDEA4C52-0F54-484c-B590-579E18F7B5D4"); + return s_ID; +} + +Standard_Boolean XCAFDoc_NoteComment::IsMine(const TDF_Label& theLabel) +{ + Handle(XCAFDoc_NoteComment) anAttr; + return (!theLabel.IsNull() && theLabel.FindAttribute(XCAFDoc_NoteComment::GetID(), anAttr)); +} + +Handle(XCAFDoc_NoteComment) XCAFDoc_NoteComment::Set(const TDF_Label& theLabel, + const Handle(TCollection_HExtendedString)& theUserName, + const Handle(TCollection_HExtendedString)& theTimeStamp, + const Handle(TCollection_HExtendedString)& theComment) +{ + Handle(XCAFDoc_NoteComment) aNoteComment; + if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_Note::GetID(), aNoteComment)) + { + aNoteComment = new XCAFDoc_NoteComment(); + aNoteComment->XCAFDoc_Note::Set(theUserName, theTimeStamp); + aNoteComment->Set(theComment); + theLabel.AddAttribute(aNoteComment); + } + return aNoteComment; +} + +XCAFDoc_NoteComment::XCAFDoc_NoteComment() +{ +} + +void XCAFDoc_NoteComment::Set(const Handle(TCollection_HExtendedString)& theComment) +{ + Backup(); + + myComment = theComment; +} + +Handle(TCollection_HExtendedString) XCAFDoc_NoteComment::Comment() const +{ + return myComment; +} + +const Standard_GUID& XCAFDoc_NoteComment::ID() const +{ + return GetID(); +} + +Handle(TDF_Attribute) XCAFDoc_NoteComment::NewEmpty() const +{ + return new XCAFDoc_Note(); +} + +void XCAFDoc_NoteComment::Restore(const Handle(TDF_Attribute)& theAttr) +{ + XCAFDoc_Note::Restore(theAttr); + myComment = Handle(XCAFDoc_NoteComment)::DownCast(theAttr)->myComment; +} + +void XCAFDoc_NoteComment::Paste(const Handle(TDF_Attribute)& theAttrInto, + const Handle(TDF_RelocationTable)& theRT) const +{ + XCAFDoc_Note::Paste(theAttrInto, theRT); + Handle(XCAFDoc_NoteComment)::DownCast(theAttrInto)->Set(myComment); +} + +Standard_OStream& XCAFDoc_NoteComment::Dump(Standard_OStream& theOS) const +{ + XCAFDoc_Note::Dump(theOS); + theOS + << "\n" + << "Comment : " + << (myComment ? myComment->String() : "") + ; + return theOS; +} diff --git a/src/XCAFDoc/XCAFDoc_NoteComment.hxx b/src/XCAFDoc/XCAFDoc_NoteComment.hxx new file mode 100644 index 0000000000..99c9363fb2 --- /dev/null +++ b/src/XCAFDoc/XCAFDoc_NoteComment.hxx @@ -0,0 +1,63 @@ +// Created on: 2017-02-13 +// Created by: Sergey NIKONOV +// Copyright (c) 2000-2017 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_NoteComment_HeaderFile +#define _XCAFDoc_NoteComment_HeaderFile + +#include + +class XCAFDoc_NoteComment; +DEFINE_STANDARD_HANDLE(XCAFDoc_NoteComment, XCAFDoc_Note) + +class XCAFDoc_NoteComment : public XCAFDoc_Note +{ +public: + + DEFINE_STANDARD_RTTIEXT(XCAFDoc_NoteComment, XCAFDoc_Note) + + Standard_EXPORT static const Standard_GUID& GetID(); + + Standard_EXPORT static Standard_Boolean IsMine(const TDF_Label& theLabel); + + Standard_EXPORT static Handle(XCAFDoc_NoteComment) Set(const TDF_Label& theLabel, + const Handle(TCollection_HExtendedString)& theUserName, + const Handle(TCollection_HExtendedString)& theTimeStamp, + const Handle(TCollection_HExtendedString)& theComment); + + Standard_EXPORT XCAFDoc_NoteComment(); + + Standard_EXPORT void Set(const Handle(TCollection_HExtendedString)& theComment); + + Standard_EXPORT Handle(TCollection_HExtendedString) Comment() const; + +public: + + Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE; + + Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE; + + Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theAttrFrom) Standard_OVERRIDE; + + Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theAttrInto, + const Handle(TDF_RelocationTable)& theRT) const Standard_OVERRIDE; + + Standard_EXPORT Standard_OStream& Dump(Standard_OStream& theOS) const Standard_OVERRIDE; + +protected: + + Handle(TCollection_HExtendedString) myComment; +}; + +#endif // _XCAFDoc_NoteComment_HeaderFile diff --git a/src/XCAFDoc/XCAFDoc_NotesTool.cxx b/src/XCAFDoc/XCAFDoc_NotesTool.cxx index df087fc303..6dfcb387bd 100644 --- a/src/XCAFDoc/XCAFDoc_NotesTool.cxx +++ b/src/XCAFDoc/XCAFDoc_NotesTool.cxx @@ -15,7 +15,12 @@ #include #include +#include +#include +#include +#include #include +#include IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_NotesTool, TDF_Attribute) @@ -40,6 +45,28 @@ XCAFDoc_NotesTool::XCAFDoc_NotesTool() { } +void XCAFDoc_NotesTool::GetNotes(TDF_LabelSequence& theNoteLabels) const +{ + theNoteLabels.Clear(); + for (TDF_ChildIterator anIter(Label()); anIter.More(); anIter.Next()) + { + const TDF_Label aLabel = anIter.Value(); + if (XCAFDoc_Note::IsMine(aLabel)) + { + theNoteLabels.Append(aLabel); + } + } +} + +Handle(XCAFDoc_Note) XCAFDoc_NotesTool::AddNote(const Handle(TCollection_HExtendedString)& theUserName, + const Handle(TCollection_HExtendedString)& theTimeStamp) +{ + TDF_Label aNoteLabel; + TDF_TagSource aTag; + aNoteLabel = aTag.NewChild(Label()); + return XCAFDoc_Note::Set(aNoteLabel, theUserName, theTimeStamp); +} + const Standard_GUID& XCAFDoc_NotesTool::ID() const { return GetID(); diff --git a/src/XCAFDoc/XCAFDoc_NotesTool.hxx b/src/XCAFDoc/XCAFDoc_NotesTool.hxx index 78521cb746..0ba2e14d2a 100644 --- a/src/XCAFDoc/XCAFDoc_NotesTool.hxx +++ b/src/XCAFDoc/XCAFDoc_NotesTool.hxx @@ -19,9 +19,12 @@ #include #include #include +#include class Standard_GUID; +class TCollection_HExtendedString; class TDF_RelocationTable; +class XCAFDoc_Note; class XCAFDoc_NotesTool; DEFINE_STANDARD_HANDLE(XCAFDoc_NotesTool, TDF_Attribute) @@ -40,14 +43,19 @@ public: //! Creates an empty tool Standard_EXPORT XCAFDoc_NotesTool(); + //! Returns a sequence of note labels currently stored in the tool table + Standard_EXPORT void GetNotes(TDF_LabelSequence& theNoteLabels) const; + + //! Adds a new note and returns a handle to it + Standard_EXPORT Handle(XCAFDoc_Note) AddNote(const Handle(TCollection_HExtendedString)& theUserName, + const Handle(TCollection_HExtendedString)& theTimeStamp); + public: + // Overrides TDF_Attribute pure virtuals Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE; - Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE; - Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theAttrFrom) Standard_OVERRIDE; - Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theAttrInto, const Handle(TDF_RelocationTable)& theRT) const Standard_OVERRIDE;