From: snn Date: Tue, 14 Feb 2017 14:32:19 +0000 (+0300) Subject: XCAF: notes Bin/XML drivers X-Git-Tag: V_01_2017_06_30~22 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=e66ddc4babf4bfce7fdf220b1daa4749648c0516;p=occt-copy.git XCAF: notes Bin/XML drivers # Conflicts: # src/XmlMXCAFDoc/XmlMXCAFDoc.hxx --- diff --git a/src/BinMXCAFDoc/BinMXCAFDoc.cxx b/src/BinMXCAFDoc/BinMXCAFDoc.cxx index 5a97870657..8c55dfbe94 100644 --- a/src/BinMXCAFDoc/BinMXCAFDoc.cxx +++ b/src/BinMXCAFDoc/BinMXCAFDoc.cxx @@ -74,7 +74,6 @@ void BinMXCAFDoc::AddDrivers(const Handle(BinMDF_ADriverTable)& theDriverTable, theDriverTable->AddDriver( new BinMXCAFDoc_DimensionDriver (theMsgDrv)); theDriverTable->AddDriver( new BinMXCAFDoc_DimTolDriver (theMsgDrv)); theDriverTable->AddDriver( new BinMXCAFDoc_MaterialDriver (theMsgDrv)); - theDriverTable->AddDriver( new BinMXCAFDoc_NoteDriver (theMsgDrv)); theDriverTable->AddDriver( new BinMXCAFDoc_NoteBinDataDriver (theMsgDrv)); theDriverTable->AddDriver( new BinMXCAFDoc_NoteCommentDriver (theMsgDrv)); theDriverTable->AddDriver (new BinMXCAFDoc_ViewDriver (theMsgDrv)); diff --git a/src/BinMXCAFDoc/BinMXCAFDoc.hxx b/src/BinMXCAFDoc/BinMXCAFDoc.hxx index d18a4ce1b2..0ef404e9b7 100644 --- a/src/BinMXCAFDoc/BinMXCAFDoc.hxx +++ b/src/BinMXCAFDoc/BinMXCAFDoc.hxx @@ -34,6 +34,9 @@ class BinMXCAFDoc_GeomToleranceDriver; class BinMXCAFDoc_DimensionDriver; class BinMXCAFDoc_DimTolDriver; class BinMXCAFDoc_MaterialDriver; +class BinMXCAFDoc_NoteCommentDriver; +class BinMXCAFDoc_NoteBinDataDriver; +class BinMXCAFDoc_NotesToolDriver; class BinMXCAFDoc_ColorToolDriver; class BinMXCAFDoc_DocumentToolDriver; class BinMXCAFDoc_LayerToolDriver; diff --git a/src/BinMXCAFDoc/BinMXCAFDoc_NoteBinDataDriver.cxx b/src/BinMXCAFDoc/BinMXCAFDoc_NoteBinDataDriver.cxx index f7dce26f75..707bb5d9ce 100644 --- a/src/BinMXCAFDoc/BinMXCAFDoc_NoteBinDataDriver.cxx +++ b/src/BinMXCAFDoc/BinMXCAFDoc_NoteBinDataDriver.cxx @@ -17,7 +17,8 @@ #include #include #include -#include +#include +#include #include #include @@ -52,14 +53,16 @@ Standard_Boolean BinMXCAFDoc_NoteBinDataDriver::Paste(const BinObjMgt_Persistent if (!BinMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable)) return Standard_False; - Handle(XCAFDoc_NoteBinData) aNoteBinData = Handle(XCAFDoc_NoteBinData)::DownCast(theTarget); + Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theTarget); + if (aNote.IsNull()) + return Standard_False; + TCollection_ExtendedString aTitle; TCollection_AsciiString aData, aMIMEtype; - if (!(theSource >> aData >> aMIMEtype)) + if (!(theSource >> aTitle >> aData >> aMIMEtype)) return Standard_False; - aNoteBinData->Set(new TCollection_HAsciiString(aData), - new TCollection_HAsciiString(aMIMEtype)); + aNote->Set(aTitle, aData, aMIMEtype); return Standard_True; } @@ -74,12 +77,13 @@ void BinMXCAFDoc_NoteBinDataDriver::Paste(const Handle(TDF_Attribute)& theSource { 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("")) - ; + Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theSource); + if (!aNote.IsNull()) + { + theTarget + << aNote->Title() + << aNote->MIMEtype() + << aNote->Data() + ; + } } diff --git a/src/BinMXCAFDoc/BinMXCAFDoc_NoteCommentDriver.cxx b/src/BinMXCAFDoc/BinMXCAFDoc_NoteCommentDriver.cxx index d1e9fc1265..9ffadce007 100644 --- a/src/BinMXCAFDoc/BinMXCAFDoc_NoteCommentDriver.cxx +++ b/src/BinMXCAFDoc/BinMXCAFDoc_NoteCommentDriver.cxx @@ -51,13 +51,15 @@ Standard_Boolean BinMXCAFDoc_NoteCommentDriver::Paste(const BinObjMgt_Persistent if (!BinMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable)) return Standard_False; - Handle(XCAFDoc_NoteComment) aNoteComment = Handle(XCAFDoc_NoteComment)::DownCast(theTarget); + Handle(XCAFDoc_NoteComment) aNote = Handle(XCAFDoc_NoteComment)::DownCast(theTarget); + if (aNote.IsNull()) + return Standard_False; TCollection_ExtendedString aComment; if (!(theSource >> aComment)) return Standard_False; - aNoteComment->Set(new TCollection_HExtendedString(aComment)); + aNote->Set(aComment); return Standard_True; } @@ -72,10 +74,7 @@ void BinMXCAFDoc_NoteCommentDriver::Paste(const Handle(TDF_Attribute)& theSource { 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("")) - ; + Handle(XCAFDoc_NoteComment) aNote = Handle(XCAFDoc_NoteComment)::DownCast(theSource); + if (!aNote.IsNull()) + theTarget << aNote->Comment(); } diff --git a/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.cxx b/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.cxx index 64e3a55bd8..fc00d0b83c 100644 --- a/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.cxx +++ b/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.cxx @@ -22,15 +22,6 @@ IMPLEMENT_STANDARD_RTTIEXT(BinMXCAFDoc_NoteDriver, BinMDF_ADriver) -//======================================================================= -//function : -//purpose : -//======================================================================= -BinMXCAFDoc_NoteDriver::BinMXCAFDoc_NoteDriver(const Handle(CDM_MessageDriver)& theMsgDriver) - : BinMDF_ADriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_Note)->Name()) -{ -} - //======================================================================= //function : //purpose : @@ -42,15 +33,6 @@ BinMXCAFDoc_NoteDriver::BinMXCAFDoc_NoteDriver(const Handle(CDM_MessageDriver)& } -//======================================================================= -//function : -//purpose : -//======================================================================= -Handle(TDF_Attribute) BinMXCAFDoc_NoteDriver::NewEmpty() const -{ - return new XCAFDoc_Note(); -} - //======================================================================= //function : //purpose : @@ -60,13 +42,14 @@ Standard_Boolean BinMXCAFDoc_NoteDriver::Paste(const BinObjMgt_Persistent& theS BinObjMgt_RRelocationTable& /*theRelocTable*/) const { Handle(XCAFDoc_Note) aNote = Handle(XCAFDoc_Note)::DownCast(theTarget); + if (aNote.IsNull()) + return Standard_False; TCollection_ExtendedString aUserName, aTimeStamp; if (!(theSource >> aUserName >> aTimeStamp)) return Standard_False; - aNote->Set(new TCollection_HExtendedString(aUserName), - new TCollection_HExtendedString(aTimeStamp)); + aNote->Set(aUserName, aTimeStamp); return Standard_True; } @@ -80,10 +63,6 @@ void BinMXCAFDoc_NoteDriver::Paste(const Handle(TDF_Attribute)& theSource, 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("")) - ; + if (!aNote.IsNull()) + theTarget << aNote->UserName() << aNote->TimeStamp(); } diff --git a/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.hxx b/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.hxx index 8dc1b75c2d..f20fd6d187 100644 --- a/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.hxx +++ b/src/BinMXCAFDoc/BinMXCAFDoc_NoteDriver.hxx @@ -35,10 +35,6 @@ class BinMXCAFDoc_NoteDriver : public BinMDF_ADriver { public: - Standard_EXPORT BinMXCAFDoc_NoteDriver(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; diff --git a/src/XCAFDoc/XCAFDoc_Note.cxx b/src/XCAFDoc/XCAFDoc_Note.cxx index 2fe5b76623..42f16ad6a6 100644 --- a/src/XCAFDoc/XCAFDoc_Note.cxx +++ b/src/XCAFDoc/XCAFDoc_Note.cxx @@ -15,42 +15,33 @@ #include #include -#include +#include +#include +#include +#include IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_Note, TDF_Attribute) -const Standard_GUID& XCAFDoc_Note::GetID() +Standard_Boolean XCAFDoc_Note::IsMine(const TDF_Label& theLabel) { - static Standard_GUID s_ID("FDC0AF06-C4AC-468a-ACFB-4C9388C76D9E"); - return s_ID; + return !Get(theLabel).IsNull(); } -Standard_Boolean XCAFDoc_Note::IsMine(const TDF_Label& theLabel) +XCAFDoc_Note::XCAFDoc_Note() { - 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) XCAFDoc_Note::Get(const TDF_Label& theLabel) { Handle(XCAFDoc_Note) aNote; - if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_Note::GetID(), aNote)) - { - aNote = new XCAFDoc_Note(); - aNote->Set(theUserName, theTimeStamp); - theLabel.AddAttribute(aNote); - } + if (theLabel.FindAttribute(XCAFDoc_NoteComment::GetID(), aNote) || + theLabel.FindAttribute(XCAFDoc_NoteBinData::GetID(), aNote)) + return aNote; return aNote; } -XCAFDoc_Note::XCAFDoc_Note() -{ -} - -void XCAFDoc_Note::Set(const Handle(TCollection_HExtendedString)& theUserName, - const Handle(TCollection_HExtendedString)& theTimeStamp) +void XCAFDoc_Note::Set(const TCollection_ExtendedString& theUserName, + const TCollection_ExtendedString& theTimeStamp) { Backup(); @@ -58,24 +49,85 @@ void XCAFDoc_Note::Set(const Handle(TCollection_HExtendedString)& theUserName, myTimeStamp = theTimeStamp; } -Handle(TCollection_HExtendedString) XCAFDoc_Note::UserName() const +const TCollection_ExtendedString& XCAFDoc_Note::UserName() const { return myUserName; } -Handle(TCollection_HExtendedString) XCAFDoc_Note::TimeStamp() const +const TCollection_ExtendedString& XCAFDoc_Note::TimeStamp() const { return myTimeStamp; } -const Standard_GUID& XCAFDoc_Note::ID() const +Standard_Boolean XCAFDoc_Note::IsAttached() const +{ + if (!IsMine(Label())) + return Standard_False; + + Handle(XCAFDoc_GraphNode) aFather; + return Label().FindAttribute(XCAFDoc::NoteRefGUID(), aFather) && + (aFather->NbChildren() > 0); +} + +void XCAFDoc_Note::Attach(const TDF_LabelSequence& theLabels) { - return GetID(); + if (!IsMine(Label()) || theLabels.Length() == 0) + return; + + Handle(XCAFDoc_GraphNode) aFather = XCAFDoc_GraphNode::Set(Label(), XCAFDoc::NoteRefGUID()); + + for (Standard_Integer i = theLabels.Lower(); i <= theLabels.Upper(); i++) + { + Handle(XCAFDoc_GraphNode) aChild = XCAFDoc_GraphNode::Set(theLabels.Value(i), XCAFDoc::NoteRefGUID()); + aChild->SetFather(aFather); + aFather->SetChild(aChild); + } } -Handle(TDF_Attribute) XCAFDoc_Note::NewEmpty() const +void XCAFDoc_Note::Detach(const TDF_LabelSequence& theLabels) { - return new XCAFDoc_Note(); + if (!IsMine(Label()) || theLabels.Length() == 0) + return; + + Handle(XCAFDoc_GraphNode) aFather; + if (Label().FindAttribute(XCAFDoc::NoteRefGUID(), aFather)) + { + for (Standard_Integer i = theLabels.Lower(); i <= theLabels.Upper(); i++) + { + Handle(XCAFDoc_GraphNode) aChild; + if (theLabels.Value(i).FindAttribute(XCAFDoc::NoteRefGUID(), aChild)) + { + Standard_Integer iFather = aChild->FatherIndex(aFather); + if (iFather > 0) + aChild->UnSetFather(iFather); + if (aChild->NbFathers() == 0) + theLabels.Value(i).ForgetAttribute(aChild); + } + } + if (aFather->NbChildren() == 0) + Label().ForgetAttribute(aFather); + } +} + +void XCAFDoc_Note::DetachAll() +{ + if (!IsMine(Label())) + return; + + Handle(XCAFDoc_GraphNode) aFather; + if (Label().FindAttribute(XCAFDoc::NoteRefGUID(), aFather)) + { + Standard_Integer nbChildren = aFather->NbChildren(); + for (Standard_Integer iChild = 1; iChild <= nbChildren; ++iChild) + { + Handle(XCAFDoc_GraphNode) aChild = aFather->GetChild(iChild); + aFather->UnSetChild(iChild); + if (aChild->NbFathers() == 0) + aChild->Label().ForgetAttribute(aChild); + } + if (aFather->NbChildren() == 0) + Label().ForgetAttribute(aFather); + } } void XCAFDoc_Note::Restore(const Handle(TDF_Attribute)& theAttr) @@ -94,9 +146,9 @@ Standard_OStream& XCAFDoc_Note::Dump(Standard_OStream& theOS) const { theOS << "Note : " - << (myUserName ? myUserName->String() : "") + << (myUserName.IsEmpty() ? myUserName : "") << " on " - << (myTimeStamp ? myTimeStamp->String() : "") + << (myTimeStamp.IsEmpty() ? myTimeStamp : "") ; return theOS; } diff --git a/src/XCAFDoc/XCAFDoc_Note.hxx b/src/XCAFDoc/XCAFDoc_Note.hxx index 3102721411..f8febfc7e1 100644 --- a/src/XCAFDoc/XCAFDoc_Note.hxx +++ b/src/XCAFDoc/XCAFDoc_Note.hxx @@ -18,9 +18,10 @@ #include #include -#include +#include #include #include +#include class Standard_GUID; class TDF_RelocationTable; @@ -34,28 +35,25 @@ public: DEFINE_STANDARD_RTTIEXT(XCAFDoc_Note, TDF_Attribute) - Standard_EXPORT static const Standard_GUID& GetID(); - 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); + Standard_EXPORT static Handle(XCAFDoc_Note) Get(const TDF_Label& theLabel); - Standard_EXPORT XCAFDoc_Note(); + Standard_EXPORT void Set(const TCollection_ExtendedString& theUserName, + const TCollection_ExtendedString& theTimeStamp); - Standard_EXPORT void Set(const Handle(TCollection_HExtendedString)& theUserName, - const Handle(TCollection_HExtendedString)& theTimeStamp); + Standard_EXPORT const TCollection_ExtendedString& UserName() const; - Standard_EXPORT Handle(TCollection_HExtendedString) UserName() const; + Standard_EXPORT const TCollection_ExtendedString& TimeStamp() const; - Standard_EXPORT Handle(TCollection_HExtendedString) TimeStamp() const; + Standard_EXPORT Standard_Boolean IsAttached() const; -public: + Standard_EXPORT void Attach(const TDF_LabelSequence& theLabels); - Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE; + Standard_EXPORT void Detach(const TDF_LabelSequence& theLabels); + Standard_EXPORT void DetachAll(); - Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE; +public: Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theAttrFrom) Standard_OVERRIDE; @@ -66,8 +64,12 @@ public: protected: - Handle(TCollection_HExtendedString) myUserName; - Handle(TCollection_HExtendedString) myTimeStamp; + Standard_EXPORT XCAFDoc_Note(); + +private: + + TCollection_ExtendedString myUserName; + TCollection_ExtendedString myTimeStamp; }; #endif // _XCAFDoc_Note_HeaderFile diff --git a/src/XCAFDoc/XCAFDoc_NoteBinData.cxx b/src/XCAFDoc/XCAFDoc_NoteBinData.cxx index d4875e51a3..f45c546aa1 100644 --- a/src/XCAFDoc/XCAFDoc_NoteBinData.cxx +++ b/src/XCAFDoc/XCAFDoc_NoteBinData.cxx @@ -33,18 +33,19 @@ Standard_Boolean XCAFDoc_NoteBinData::IsMine(const TDF_Label& theLabel) 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) XCAFDoc_NoteBinData::Set(const TDF_Label& theLabel, + const TCollection_ExtendedString& theUserName, + const TCollection_ExtendedString& theTimeStamp, + const TCollection_ExtendedString& theTitle, + OSD_File& theFile, + const TCollection_AsciiString& theMIMEtype) { Handle(XCAFDoc_NoteBinData) aNoteBinData; - if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_Note::GetID(), aNoteBinData)) + if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_NoteBinData::GetID(), aNoteBinData)) { aNoteBinData = new XCAFDoc_NoteBinData(); aNoteBinData->XCAFDoc_Note::Set(theUserName, theTimeStamp); - aNoteBinData->Set(theFile, theMIMEtype); + aNoteBinData->Set(theTitle, theFile, theMIMEtype); theLabel.AddAttribute(aNoteBinData); } return aNoteBinData; @@ -54,36 +55,44 @@ XCAFDoc_NoteBinData::XCAFDoc_NoteBinData() { } -void XCAFDoc_NoteBinData::Set(OSD_File& theFile, - const Handle(TCollection_HAsciiString)& theMIMEtype) +void XCAFDoc_NoteBinData::Set(const TCollection_ExtendedString& theTitle, + OSD_File& theFile, + const TCollection_AsciiString& theMIMEtype) { if (!theFile.IsOpen() || !theFile.IsReadable()) return; - TCollection_AsciiString aStr; - theFile.Read(aStr, theFile.Size()); - Backup(); - myData.reset(new TCollection_HAsciiString(aStr)); + TCollection_AsciiString myData; + theFile.Read(myData, theFile.Size()); + + myTitle = theTitle; myMIMEtype = theMIMEtype; } -void XCAFDoc_NoteBinData::Set(const Handle(TCollection_HAsciiString)& theData, - const Handle(TCollection_HAsciiString)& theMIMEtype) +void XCAFDoc_NoteBinData::Set(const TCollection_ExtendedString& theTitle, + const TCollection_AsciiString& theData, + const TCollection_AsciiString& theMIMEtype) { Backup(); myData = theData; + myTitle = theTitle; myMIMEtype = theMIMEtype; } -Handle(TCollection_HAsciiString) XCAFDoc_NoteBinData::Data() const +const TCollection_ExtendedString& XCAFDoc_NoteBinData::Title() const +{ + return myTitle; +} + +const TCollection_AsciiString& XCAFDoc_NoteBinData::Data() const { return myData; } -Handle(TCollection_HAsciiString) XCAFDoc_NoteBinData::MIMEtype() const +const TCollection_AsciiString& XCAFDoc_NoteBinData::MIMEtype() const { return myMIMEtype; } @@ -95,34 +104,40 @@ const Standard_GUID& XCAFDoc_NoteBinData::ID() const Handle(TDF_Attribute) XCAFDoc_NoteBinData::NewEmpty() const { - return new XCAFDoc_Note(); + return new XCAFDoc_NoteBinData(); } 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; + + Handle(XCAFDoc_NoteBinData) aMine = Handle(XCAFDoc_NoteBinData)::DownCast(theAttr); + if (!aMine.IsNull()) + { + myData = aMine->myData; + myTitle = aMine->myTitle; + myMIMEtype = aMine->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); + + Handle(XCAFDoc_NoteBinData) aMine = Handle(XCAFDoc_NoteBinData)::DownCast(theAttrInto); + if (!aMine.IsNull()) + aMine->Set(myTitle, 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() : "") - << "" + theOS << "\n" + << "Title : " << (!myTitle.IsEmpty() ? myMIMEtype : "") << "\n" + << "MIME type : " << (!myMIMEtype.IsEmpty() ? myMIMEtype : "") << "\n" + << "Size : " << myData.Length() << " bytes" << "\n" + << myData ; return theOS; } diff --git a/src/XCAFDoc/XCAFDoc_NoteBinData.hxx b/src/XCAFDoc/XCAFDoc_NoteBinData.hxx index 64c6ce7fde..a508a36d2a 100644 --- a/src/XCAFDoc/XCAFDoc_NoteBinData.hxx +++ b/src/XCAFDoc/XCAFDoc_NoteBinData.hxx @@ -19,7 +19,8 @@ #include class OSD_File; -class TCollection_HAsciiString; +class TCollection_AsciiString; +class TCollection_ExtendedString; class XCAFDoc_NoteBinData; DEFINE_STANDARD_HANDLE(XCAFDoc_NoteBinData, XCAFDoc_Note) @@ -34,22 +35,26 @@ public: 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 static Handle(XCAFDoc_NoteBinData) Set(const TDF_Label& theLabel, + const TCollection_ExtendedString& theUserName, + const TCollection_ExtendedString& theTimeStamp, + const TCollection_ExtendedString& theTitle, + OSD_File& theFile, + const TCollection_AsciiString& theMIMEtype); Standard_EXPORT XCAFDoc_NoteBinData(); - Standard_EXPORT void Set(OSD_File& theFile, - const Handle(TCollection_HAsciiString)& theMIMEtype); + Standard_EXPORT void Set(const TCollection_ExtendedString& theTitle, + OSD_File& theFile, + const TCollection_AsciiString& theMIMEtype); - Standard_EXPORT void Set(const Handle(TCollection_HAsciiString)& theData, - const Handle(TCollection_HAsciiString)& theMIMEtype); + Standard_EXPORT void Set(const TCollection_ExtendedString& theTitle, + const TCollection_AsciiString& theData, + const TCollection_AsciiString& theMIMEtype); - Standard_EXPORT Handle(TCollection_HAsciiString) Data() const; - Standard_EXPORT Handle(TCollection_HAsciiString) MIMEtype() const; + Standard_EXPORT const TCollection_ExtendedString& Title() const; + Standard_EXPORT const TCollection_AsciiString& Data() const; + Standard_EXPORT const TCollection_AsciiString& MIMEtype() const; public: @@ -66,8 +71,9 @@ public: protected: - Handle(TCollection_HAsciiString) myData; - Handle(TCollection_HAsciiString) myMIMEtype; + TCollection_ExtendedString myTitle; + TCollection_AsciiString myData; + TCollection_AsciiString myMIMEtype; }; #endif // _XCAFDoc_NoteBinData_HeaderFile diff --git a/src/XCAFDoc/XCAFDoc_NoteComment.cxx b/src/XCAFDoc/XCAFDoc_NoteComment.cxx index 23e9f56834..3e6f2d68f9 100644 --- a/src/XCAFDoc/XCAFDoc_NoteComment.cxx +++ b/src/XCAFDoc/XCAFDoc_NoteComment.cxx @@ -31,13 +31,13 @@ Standard_Boolean XCAFDoc_NoteComment::IsMine(const TDF_Label& theLabel) 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) XCAFDoc_NoteComment::Set(const TDF_Label& theLabel, + const TCollection_ExtendedString& theUserName, + const TCollection_ExtendedString& theTimeStamp, + const TCollection_ExtendedString& theComment) { Handle(XCAFDoc_NoteComment) aNoteComment; - if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_Note::GetID(), aNoteComment)) + if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_NoteComment::GetID(), aNoteComment)) { aNoteComment = new XCAFDoc_NoteComment(); aNoteComment->XCAFDoc_Note::Set(theUserName, theTimeStamp); @@ -51,14 +51,14 @@ XCAFDoc_NoteComment::XCAFDoc_NoteComment() { } -void XCAFDoc_NoteComment::Set(const Handle(TCollection_HExtendedString)& theComment) +void XCAFDoc_NoteComment::Set(const TCollection_ExtendedString& theComment) { Backup(); myComment = theComment; } -Handle(TCollection_HExtendedString) XCAFDoc_NoteComment::Comment() const +const TCollection_ExtendedString& XCAFDoc_NoteComment::Comment() const { return myComment; } @@ -70,29 +70,33 @@ const Standard_GUID& XCAFDoc_NoteComment::ID() const Handle(TDF_Attribute) XCAFDoc_NoteComment::NewEmpty() const { - return new XCAFDoc_Note(); + return new XCAFDoc_NoteComment(); } void XCAFDoc_NoteComment::Restore(const Handle(TDF_Attribute)& theAttr) { XCAFDoc_Note::Restore(theAttr); - myComment = Handle(XCAFDoc_NoteComment)::DownCast(theAttr)->myComment; + + Handle(XCAFDoc_NoteComment) aMine = Handle(XCAFDoc_NoteComment)::DownCast(theAttr); + if (!aMine.IsNull()) + myComment = aMine->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); + + Handle(XCAFDoc_NoteComment) aMine = Handle(XCAFDoc_NoteComment)::DownCast(theAttrInto); + if (!aMine.IsNull()) + aMine->Set(myComment); } Standard_OStream& XCAFDoc_NoteComment::Dump(Standard_OStream& theOS) const { XCAFDoc_Note::Dump(theOS); - theOS - << "\n" - << "Comment : " - << (myComment ? myComment->String() : "") + theOS << "\n" + << "Comment : " << (!myComment.IsEmpty() ? myComment : "") ; return theOS; } diff --git a/src/XCAFDoc/XCAFDoc_NoteComment.hxx b/src/XCAFDoc/XCAFDoc_NoteComment.hxx index 99c9363fb2..04f6a15865 100644 --- a/src/XCAFDoc/XCAFDoc_NoteComment.hxx +++ b/src/XCAFDoc/XCAFDoc_NoteComment.hxx @@ -31,16 +31,16 @@ public: 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 static Handle(XCAFDoc_NoteComment) Set(const TDF_Label& theLabel, + const TCollection_ExtendedString& theUserName, + const TCollection_ExtendedString& theTimeStamp, + const TCollection_ExtendedString& theComment); Standard_EXPORT XCAFDoc_NoteComment(); - Standard_EXPORT void Set(const Handle(TCollection_HExtendedString)& theComment); + Standard_EXPORT void Set(const TCollection_ExtendedString& theComment); - Standard_EXPORT Handle(TCollection_HExtendedString) Comment() const; + Standard_EXPORT const TCollection_ExtendedString& Comment() const; public: @@ -57,7 +57,7 @@ public: protected: - Handle(TCollection_HExtendedString) myComment; + TCollection_ExtendedString myComment; }; #endif // _XCAFDoc_NoteComment_HeaderFile diff --git a/src/XCAFDoc/XCAFDoc_NotesTool.cxx b/src/XCAFDoc/XCAFDoc_NotesTool.cxx index 6dfcb387bd..4d5d4b32ca 100644 --- a/src/XCAFDoc/XCAFDoc_NotesTool.cxx +++ b/src/XCAFDoc/XCAFDoc_NotesTool.cxx @@ -20,7 +20,8 @@ #include #include #include -#include +#include +#include IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_NotesTool, TDF_Attribute) @@ -45,6 +46,20 @@ XCAFDoc_NotesTool::XCAFDoc_NotesTool() { } +Standard_Integer XCAFDoc_NotesTool::NbNotes() const +{ + Standard_Integer nbNotes = 0; + for (TDF_ChildIterator anIter(Label()); anIter.More(); anIter.Next()) + { + const TDF_Label aLabel = anIter.Value(); + if (XCAFDoc_Note::IsMine(aLabel)) + { + ++nbNotes; + } + } + return nbNotes; +} + void XCAFDoc_NotesTool::GetNotes(TDF_LabelSequence& theNoteLabels) const { theNoteLabels.Clear(); @@ -58,13 +73,117 @@ void XCAFDoc_NotesTool::GetNotes(TDF_LabelSequence& theNoteLabels) const } } -Handle(XCAFDoc_Note) XCAFDoc_NotesTool::AddNote(const Handle(TCollection_HExtendedString)& theUserName, - const Handle(TCollection_HExtendedString)& theTimeStamp) +Handle(XCAFDoc_Note) +XCAFDoc_NotesTool::AddComment(const TCollection_ExtendedString& theUserName, + const TCollection_ExtendedString& theTimeStamp, + const TCollection_ExtendedString& theComment) { TDF_Label aNoteLabel; TDF_TagSource aTag; aNoteLabel = aTag.NewChild(Label()); - return XCAFDoc_Note::Set(aNoteLabel, theUserName, theTimeStamp); + return XCAFDoc_NoteComment::Set(aNoteLabel, theUserName, theTimeStamp, theComment); +} + +Handle(XCAFDoc_Note) +XCAFDoc_NotesTool::AddBinData(const TCollection_ExtendedString& theUserName, + const TCollection_ExtendedString& theTimeStamp, + const TCollection_ExtendedString& theTitle, + OSD_File& theFile, + const TCollection_AsciiString& theMIMEtype) +{ + TDF_Label aNoteLabel; + TDF_TagSource aTag; + aNoteLabel = aTag.NewChild(Label()); + return XCAFDoc_NoteBinData::Set(aNoteLabel, theUserName, theTimeStamp, theTitle, theFile, theMIMEtype); +} + +Standard_Boolean XCAFDoc_NotesTool::HasAttachedNotes(const TDF_Label& theLabel) const +{ + Handle(XCAFDoc_GraphNode) aChild; + return !theLabel.IsNull() && + theLabel.FindAttribute(XCAFDoc::NoteRefGUID(), aChild) && + (aChild->NbFathers() > 0); +} + +void XCAFDoc_NotesTool::GetAttachedNotes(const TDF_Label& theLabel, + TDF_LabelSequence& theNoteLabels) const +{ + theNoteLabels.Clear(); + + Handle(XCAFDoc_GraphNode) aChild; + if (!theLabel.IsNull() && theLabel.FindAttribute(XCAFDoc::NoteRefGUID(), aChild)) + { + Standard_Integer nbNotes = aChild->NbFathers(); + for (Standard_Integer iNote = 1; iNote <= nbNotes; ++iNote) + { + Handle(XCAFDoc_GraphNode) aNote = aChild->GetFather(iNote); + if (XCAFDoc_Note::IsMine(aNote->Label())) + theNoteLabels.Append(aNote->Label()); + } + } +} + +Standard_Integer XCAFDoc_NotesTool::DetachAllNotes(const TDF_Label& theLabel) const +{ + Standard_Integer nbNotes = 0; + Handle(XCAFDoc_GraphNode) aChild; + if (!theLabel.IsNull() && theLabel.FindAttribute(XCAFDoc::NoteRefGUID(), aChild)) + { + Standard_Integer nbNotes = aChild->NbFathers(); + for (Standard_Integer iNote = 1; iNote <= nbNotes; ++iNote) + { + aChild->UnSetFather(iNote); + ++nbNotes; + } + } + theLabel.ForgetAttribute(aChild); + return nbNotes; +} + +Standard_Boolean XCAFDoc_NotesTool::RemoveNote(const TDF_Label& theNoteLabel) +{ + Handle(XCAFDoc_Note) aNote = XCAFDoc_Note::Get(theNoteLabel); + if (!aNote.IsNull()) + { + aNote->DetachAll(); + theNoteLabel.ForgetAllAttributes(Standard_True); + return Standard_True; + } + return Standard_False; +} + +Standard_Integer XCAFDoc_NotesTool::RemoveNotes(TDF_LabelSequence& theNoteLabels) +{ + Standard_Integer nbNotes = 0; + for (TDF_LabelSequence::Iterator anIter(theNoteLabels); anIter.More(); anIter.Next()) + { + if (RemoveNote(anIter.Value())) + ++nbNotes; + } + return nbNotes; +} + +Standard_Integer XCAFDoc_NotesTool::RemoveDetachedNotes() +{ + Standard_Integer nbNotes = 0; + for (TDF_ChildIterator anIter(Label()); anIter.More(); anIter.Next()) + { + Handle(XCAFDoc_Note) aNote = XCAFDoc_Note::Get(anIter.Value()); + if (!aNote.IsNull() && !aNote->IsAttached() && RemoveNote(anIter.Value())) + ++nbNotes; + } + return nbNotes; +} + +Standard_Integer XCAFDoc_NotesTool::RemoveAllNotes() +{ + Standard_Integer nbNotes = 0; + for (TDF_ChildIterator anIter(Label()); anIter.More(); anIter.Next()) + { + if (RemoveNote(anIter.Value())) + ++nbNotes; + } + return nbNotes; } const Standard_GUID& XCAFDoc_NotesTool::ID() const diff --git a/src/XCAFDoc/XCAFDoc_NotesTool.hxx b/src/XCAFDoc/XCAFDoc_NotesTool.hxx index 0ba2e14d2a..19702f5d9b 100644 --- a/src/XCAFDoc/XCAFDoc_NotesTool.hxx +++ b/src/XCAFDoc/XCAFDoc_NotesTool.hxx @@ -21,8 +21,10 @@ #include #include +class OSD_File; class Standard_GUID; -class TCollection_HExtendedString; +class TCollection_AsciiString; +class TCollection_ExtendedString; class TDF_RelocationTable; class XCAFDoc_Note; @@ -37,18 +39,34 @@ public: Standard_EXPORT static const Standard_GUID& GetID(); - //! Create (if not exist) NotesTool from XCAFDoc on . Standard_EXPORT static Handle(XCAFDoc_NotesTool) Set(const TDF_Label& theLabel); - //! Creates an empty tool Standard_EXPORT XCAFDoc_NotesTool(); - //! Returns a sequence of note labels currently stored in the tool table + Standard_EXPORT Standard_Integer NbNotes() const; + 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); + Standard_EXPORT Handle(XCAFDoc_Note) AddComment(const TCollection_ExtendedString& theUserName, + const TCollection_ExtendedString& theTimeStamp, + const TCollection_ExtendedString& theComment); + + Standard_EXPORT Handle(XCAFDoc_Note) AddBinData(const TCollection_ExtendedString& theUserName, + const TCollection_ExtendedString& theTimeStamp, + const TCollection_ExtendedString& theTitle, + OSD_File& theFile, + const TCollection_AsciiString& theMIMEtype); + + Standard_EXPORT Standard_Boolean HasAttachedNotes(const TDF_Label& theLabel) const; + + Standard_EXPORT void GetAttachedNotes(const TDF_Label& theLabel, + TDF_LabelSequence& theNoteLabels) const; + Standard_EXPORT Standard_Integer DetachAllNotes(const TDF_Label& theLabel) const; + + Standard_EXPORT Standard_Boolean RemoveNote(const TDF_Label& theNoteLabel); + Standard_EXPORT Standard_Integer RemoveNotes(TDF_LabelSequence& theNoteLabels); + Standard_EXPORT Standard_Integer RemoveDetachedNotes(); + Standard_EXPORT Standard_Integer RemoveAllNotes(); public: diff --git a/src/XmlMXCAFDoc/FILES b/src/XmlMXCAFDoc/FILES index d93ba3b27c..d56d8aea6c 100644 --- a/src/XmlMXCAFDoc/FILES +++ b/src/XmlMXCAFDoc/FILES @@ -29,6 +29,14 @@ XmlMXCAFDoc_MaterialDriver.cxx XmlMXCAFDoc_MaterialDriver.hxx XmlMXCAFDoc_MaterialToolDriver.cxx XmlMXCAFDoc_MaterialToolDriver.hxx +XmlMXCAFDoc_NoteDriver.cxx +XmlMXCAFDoc_NoteDriver.hxx +XmlMXCAFDoc_NoteCommentDriver.cxx +XmlMXCAFDoc_NoteCommentDriver.hxx +XmlMXCAFDoc_NoteBinDataDriver.cxx +XmlMXCAFDoc_NoteBinDataDriver.hxx +XmlMXCAFDoc_NotesToolDriver.cxx +XmlMXCAFDoc_NotesToolDriver.hxx XmlMXCAFDoc_ShapeToolDriver.cxx XmlMXCAFDoc_ShapeToolDriver.hxx XmlMXCAFDoc_ViewToolDriver.cxx diff --git a/src/XmlMXCAFDoc/XmlMXCAFDoc.cxx b/src/XmlMXCAFDoc/XmlMXCAFDoc.cxx index fe596313b0..7c959f9ee9 100644 --- a/src/XmlMXCAFDoc/XmlMXCAFDoc.cxx +++ b/src/XmlMXCAFDoc/XmlMXCAFDoc.cxx @@ -32,6 +32,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -66,6 +69,8 @@ void XmlMXCAFDoc::AddDrivers (const Handle(XmlMDF_ADriverTable)& aDriverTable, aDriverTable -> AddDriver (new XmlMXCAFDoc_DatumDriver (anMsgDrv)); aDriverTable -> AddDriver (new XmlMXCAFDoc_DimTolDriver (anMsgDrv)); aDriverTable -> AddDriver (new XmlMXCAFDoc_MaterialDriver (anMsgDrv)); + aDriverTable -> AddDriver (new XmlMXCAFDoc_NoteCommentDriver(anMsgDrv)); + aDriverTable -> AddDriver (new XmlMXCAFDoc_NoteBinDataDriver(anMsgDrv)); aDriverTable -> AddDriver (new XmlMXCAFDoc_ColorToolDriver (anMsgDrv)); aDriverTable -> AddDriver (new XmlMXCAFDoc_DocumentToolDriver (anMsgDrv)); @@ -73,6 +78,7 @@ void XmlMXCAFDoc::AddDrivers (const Handle(XmlMDF_ADriverTable)& aDriverTable, aDriverTable -> AddDriver (new XmlMXCAFDoc_ShapeToolDriver (anMsgDrv)); aDriverTable -> AddDriver (new XmlMXCAFDoc_DimTolToolDriver (anMsgDrv)); aDriverTable -> AddDriver (new XmlMXCAFDoc_MaterialToolDriver (anMsgDrv)); + aDriverTable -> AddDriver (new XmlMXCAFDoc_NotesToolDriver (anMsgDrv)); aDriverTable -> AddDriver (new XmlMXCAFDoc_ViewToolDriver (anMsgDrv)); aDriverTable -> AddDriver (new XmlMXCAFDoc_ClippingPlaneToolDriver(anMsgDrv)); } diff --git a/src/XmlMXCAFDoc/XmlMXCAFDoc.hxx b/src/XmlMXCAFDoc/XmlMXCAFDoc.hxx index 1d9fb8545f..0bf1036945 100644 --- a/src/XmlMXCAFDoc/XmlMXCAFDoc.hxx +++ b/src/XmlMXCAFDoc/XmlMXCAFDoc.hxx @@ -32,6 +32,11 @@ class XmlMXCAFDoc_VolumeDriver; class XmlMXCAFDoc_DatumDriver; class XmlMXCAFDoc_DimTolDriver; class XmlMXCAFDoc_MaterialDriver; +class XmlMXCAFDoc_NotesToolDriver; +class XmlMXCAFDoc_NoteDriver; +class XmlMXCAFDoc_NoteCommentDriver; +class XmlMXCAFDoc_NoteBinDataDriver; +class XmlMXCAFDoc_ClippingPlaneToolDriver; class XmlMXCAFDoc_ColorToolDriver; class XmlMXCAFDoc_DocumentToolDriver; class XmlMXCAFDoc_LayerToolDriver; @@ -77,6 +82,7 @@ friend class XmlMXCAFDoc_VolumeDriver; friend class XmlMXCAFDoc_DatumDriver; friend class XmlMXCAFDoc_DimTolDriver; friend class XmlMXCAFDoc_MaterialDriver; +friend class XmlMXCAFDoc_ClippingPlaneToolDriver; friend class XmlMXCAFDoc_ColorToolDriver; friend class XmlMXCAFDoc_DocumentToolDriver; friend class XmlMXCAFDoc_LayerToolDriver; diff --git a/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteBinDataDriver.cxx b/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteBinDataDriver.cxx new file mode 100644 index 0000000000..b53d3bc552 --- /dev/null +++ b/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteBinDataDriver.cxx @@ -0,0 +1,92 @@ +// Created on: 2017-02-14 +// Created by: Sergey NIKONOV +// Copyright (c) 2008-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(XmlMXCAFDoc_NoteBinDataDriver, XmlMXCAFDoc_NoteDriver) +IMPLEMENT_DOMSTRING(Title, "title") +IMPLEMENT_DOMSTRING(MIMEtype, "mime_type") +IMPLEMENT_DOMSTRING(Data, "data") + +//======================================================================= +//function : +//purpose : +//======================================================================= +XmlMXCAFDoc_NoteBinDataDriver::XmlMXCAFDoc_NoteBinDataDriver(const Handle(CDM_MessageDriver)& theMsgDriver) + : XmlMXCAFDoc_NoteDriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_NoteBinData)->Name()) +{ +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +Handle(TDF_Attribute) XmlMXCAFDoc_NoteBinDataDriver::NewEmpty() const +{ + return new XCAFDoc_NoteBinData(); +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +Standard_Boolean XmlMXCAFDoc_NoteBinDataDriver::Paste(const XmlObjMgt_Persistent& theSource, + const Handle(TDF_Attribute)& theTarget, + XmlObjMgt_RRelocationTable& theRelocTable) const +{ + XmlMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable); + + const XmlObjMgt_Element& anElement = theSource; + + XmlObjMgt_DOMString aTitle = anElement.getAttribute(::Title()); + XmlObjMgt_DOMString aMIMEtype = anElement.getAttribute(::MIMEtype()); + XmlObjMgt_DOMString aData = anElement.getAttribute(::Data()); + if (aTitle == NULL || aMIMEtype == NULL || aData == NULL) + return Standard_False; + + Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theTarget); + if (aNote.IsNull()) + return Standard_False; + + aNote->Set(aTitle.GetString(), aData.GetString(), aMIMEtype.GetString()); + + return Standard_True; +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +void XmlMXCAFDoc_NoteBinDataDriver::Paste(const Handle(TDF_Attribute)& theSource, + XmlObjMgt_Persistent& theTarget, + XmlObjMgt_SRelocationTable& theRelocTable) const +{ + XmlMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable); + + Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theSource); + + XmlObjMgt_DOMString aTitle(TCollection_AsciiString(aNote->Title()).ToCString()); + XmlObjMgt_DOMString aMIMEtype(aNote->MIMEtype().ToCString()); + XmlObjMgt_DOMString aData(aNote->Data().ToCString()); + + theTarget.Element().setAttribute(::Title(), aTitle); + theTarget.Element().setAttribute(::MIMEtype(), aMIMEtype); + theTarget.Element().setAttribute(::Data(), aData); +} diff --git a/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteBinDataDriver.hxx b/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteBinDataDriver.hxx new file mode 100644 index 0000000000..cca07af0bb --- /dev/null +++ b/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteBinDataDriver.hxx @@ -0,0 +1,45 @@ +// Created on: 2017-02-14 +// Created by: Sergey NIKONOV +// Copyright (c) 2008-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 _XmlMXCAFDoc_NoteBinDataDriver_HeaderFile +#define _XmlMXCAFDoc_NoteBinDataDriver_HeaderFile + +#include + +class XmlMXCAFDoc_NoteBinDataDriver; +DEFINE_STANDARD_HANDLE(XmlMXCAFDoc_NoteBinDataDriver, XmlMXCAFDoc_NoteDriver) + +//! Attribute Driver. +class XmlMXCAFDoc_NoteBinDataDriver : public XmlMXCAFDoc_NoteDriver +{ +public: + + Standard_EXPORT XmlMXCAFDoc_NoteBinDataDriver(const Handle(CDM_MessageDriver)& theMessageDriver); + + Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE; + + Standard_EXPORT Standard_Boolean Paste(const XmlObjMgt_Persistent& theSource, + const Handle(TDF_Attribute)& theTarget, + XmlObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE; + + Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theSource, + XmlObjMgt_Persistent& theTarget, + XmlObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE; + + DEFINE_STANDARD_RTTIEXT(XmlMXCAFDoc_NoteBinDataDriver, XmlMXCAFDoc_NoteDriver) + +}; + +#endif // _XmlMXCAFDoc_NoteBinDataDriver_HeaderFile diff --git a/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteCommentDriver.cxx b/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteCommentDriver.cxx new file mode 100644 index 0000000000..c32baf6ee5 --- /dev/null +++ b/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteCommentDriver.cxx @@ -0,0 +1,84 @@ +// Created on: 2017-02-14 +// Created by: Sergey NIKONOV +// Copyright (c) 2008-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(XmlMXCAFDoc_NoteCommentDriver, XmlMXCAFDoc_NoteDriver) +IMPLEMENT_DOMSTRING(Comment, "comment") + +//======================================================================= +//function : +//purpose : +//======================================================================= +XmlMXCAFDoc_NoteCommentDriver::XmlMXCAFDoc_NoteCommentDriver(const Handle(CDM_MessageDriver)& theMsgDriver) + : XmlMXCAFDoc_NoteDriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_NoteComment)->Name()) +{ +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +Handle(TDF_Attribute) XmlMXCAFDoc_NoteCommentDriver::NewEmpty() const +{ + return new XCAFDoc_NoteComment(); +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +Standard_Boolean XmlMXCAFDoc_NoteCommentDriver::Paste(const XmlObjMgt_Persistent& theSource, + const Handle(TDF_Attribute)& theTarget, + XmlObjMgt_RRelocationTable& theRelocTable) const +{ + XmlMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable); + + const XmlObjMgt_Element& anElement = theSource; + + XmlObjMgt_DOMString aComment = anElement.getAttribute(::Comment()); + if (aComment == NULL) + return Standard_False; + + Handle(XCAFDoc_NoteComment) aNote = Handle(XCAFDoc_NoteComment)::DownCast(theTarget); + if (aNote.IsNull()) + return Standard_False; + + aNote->Set(aComment.GetString()); + + return Standard_True; +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +void XmlMXCAFDoc_NoteCommentDriver::Paste(const Handle(TDF_Attribute)& theSource, + XmlObjMgt_Persistent& theTarget, + XmlObjMgt_SRelocationTable& theRelocTable) const +{ + XmlMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable); + + Handle(XCAFDoc_NoteComment) aNote = Handle(XCAFDoc_NoteComment)::DownCast(theSource); + + XmlObjMgt_DOMString aComment(TCollection_AsciiString(aNote->TimeStamp()).ToCString()); + + theTarget.Element().setAttribute(::Comment(), aComment); +} diff --git a/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteCommentDriver.hxx b/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteCommentDriver.hxx new file mode 100644 index 0000000000..fd478cfd6d --- /dev/null +++ b/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteCommentDriver.hxx @@ -0,0 +1,45 @@ +// Created on: 2017-02-14 +// Created by: Sergey NIKONOV +// Copyright (c) 2008-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 _XmlMXCAFDoc_NoteCommentDriver_HeaderFile +#define _XmlMXCAFDoc_NoteCommentDriver_HeaderFile + +#include + +class XmlMXCAFDoc_NoteCommentDriver; +DEFINE_STANDARD_HANDLE(XmlMXCAFDoc_NoteCommentDriver, XmlMXCAFDoc_NoteDriver) + +//! Attribute Driver. +class XmlMXCAFDoc_NoteCommentDriver : public XmlMXCAFDoc_NoteDriver +{ +public: + + Standard_EXPORT XmlMXCAFDoc_NoteCommentDriver(const Handle(CDM_MessageDriver)& theMessageDriver); + + Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE; + + Standard_EXPORT Standard_Boolean Paste(const XmlObjMgt_Persistent& theSource, + const Handle(TDF_Attribute)& theTarget, + XmlObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE; + + Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theSource, + XmlObjMgt_Persistent& theTarget, + XmlObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE; + + DEFINE_STANDARD_RTTIEXT(XmlMXCAFDoc_NoteCommentDriver, XmlMXCAFDoc_NoteDriver) + +}; + +#endif // _XmlMXCAFDoc_NoteCommentDriver_HeaderFile diff --git a/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteDriver.cxx b/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteDriver.cxx new file mode 100644 index 0000000000..63b2b8d18b --- /dev/null +++ b/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteDriver.cxx @@ -0,0 +1,78 @@ +// Created on: 2017-02-14 +// Created by: Sergey NIKONOV +// Copyright (c) 2008-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(XmlMXCAFDoc_NoteDriver, XmlMDF_ADriver) +IMPLEMENT_DOMSTRING(UserName, "user_name") +IMPLEMENT_DOMSTRING(TimeStamp, "time_stamp") + +//======================================================================= +//function : +//purpose : +//======================================================================= +XmlMXCAFDoc_NoteDriver::XmlMXCAFDoc_NoteDriver(const Handle(CDM_MessageDriver)& theMsgDriver, + Standard_CString theName) + : XmlMDF_ADriver(theMsgDriver, theName) +{ +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +Standard_Boolean XmlMXCAFDoc_NoteDriver::Paste(const XmlObjMgt_Persistent& theSource, + const Handle(TDF_Attribute)& theTarget, + XmlObjMgt_RRelocationTable& /*theRelocTable*/) const +{ + const XmlObjMgt_Element& anElement = theSource; + + XmlObjMgt_DOMString aUserName = anElement.getAttribute(::UserName()); + XmlObjMgt_DOMString aTimeStamp = anElement.getAttribute(::TimeStamp()); + if (aUserName == NULL || aTimeStamp == NULL) + return Standard_False; + + Handle(XCAFDoc_Note) aNote = Handle(XCAFDoc_Note)::DownCast(theTarget); + if (aNote.IsNull()) + return Standard_False; + + aNote->Set(aUserName.GetString(), aTimeStamp.GetString()); + + return Standard_True; +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +void XmlMXCAFDoc_NoteDriver::Paste(const Handle(TDF_Attribute)& theSource, + XmlObjMgt_Persistent& theTarget, + XmlObjMgt_SRelocationTable& /*theRelocTable*/) const +{ + Handle(XCAFDoc_Note) aNote = Handle(XCAFDoc_Note)::DownCast(theSource); + if (aNote.IsNull()) + return; + + XmlObjMgt_DOMString aUserName(TCollection_AsciiString(aNote->UserName()).ToCString()); + XmlObjMgt_DOMString aTimeStamp(TCollection_AsciiString(aNote->TimeStamp()).ToCString()); + + theTarget.Element().setAttribute(::UserName(), aUserName); + theTarget.Element().setAttribute(::TimeStamp(), aTimeStamp); +} diff --git a/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteDriver.hxx b/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteDriver.hxx new file mode 100644 index 0000000000..c5578f72a3 --- /dev/null +++ b/src/XmlMXCAFDoc/XmlMXCAFDoc_NoteDriver.hxx @@ -0,0 +1,56 @@ +// Created on: 2017-02-14 +// Created by: Sergey NIKONOV +// Copyright (c) 2008-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 _XmlMXCAFDoc_NoteDriver_HeaderFile +#define _XmlMXCAFDoc_NoteDriver_HeaderFile + +#include +#include + +#include +#include +#include +#include + +class CDM_MessageDriver; +class TDF_Attribute; +class XmlObjMgt_Persistent; + +class XmlMXCAFDoc_NoteDriver; +DEFINE_STANDARD_HANDLE(XmlMXCAFDoc_NoteDriver, XmlMDF_ADriver) + +//! Attribute Driver. +class XmlMXCAFDoc_NoteDriver : public XmlMDF_ADriver +{ +public: + + Standard_EXPORT Standard_Boolean Paste(const XmlObjMgt_Persistent& theSource, + const Handle(TDF_Attribute)& theTarget, + XmlObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE; + + Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theSource, + XmlObjMgt_Persistent& theTarget, + XmlObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE; + + DEFINE_STANDARD_RTTIEXT(XmlMXCAFDoc_NoteDriver, XmlMDF_ADriver) + +protected: + + Standard_EXPORT XmlMXCAFDoc_NoteDriver(const Handle(CDM_MessageDriver)& theMsgDriver, + Standard_CString theName); + +}; + +#endif // _XmlMXCAFDoc_NoteDriver_HeaderFile diff --git a/src/XmlMXCAFDoc/XmlMXCAFDoc_NotesToolDriver.cxx b/src/XmlMXCAFDoc/XmlMXCAFDoc_NotesToolDriver.cxx new file mode 100644 index 0000000000..dd946f5034 --- /dev/null +++ b/src/XmlMXCAFDoc/XmlMXCAFDoc_NotesToolDriver.cxx @@ -0,0 +1,62 @@ +// Created on: 2017-02-14 +// Created by: Sergey NIKONOV +// Copyright (c) 2008-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(XmlMXCAFDoc_NotesToolDriver, XmlMDF_ADriver) + +//======================================================================= +//function : +//purpose : +//======================================================================= +XmlMXCAFDoc_NotesToolDriver::XmlMXCAFDoc_NotesToolDriver(const Handle(CDM_MessageDriver)& theMsgDriver) + : XmlMDF_ADriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_NotesTool)->Name()) +{ +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +Handle(TDF_Attribute) XmlMXCAFDoc_NotesToolDriver::NewEmpty() const +{ + return new XCAFDoc_NotesTool(); +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +Standard_Boolean XmlMXCAFDoc_NotesToolDriver::Paste(const XmlObjMgt_Persistent& /*theSource*/, + const Handle(TDF_Attribute)& /*theTarget*/, + XmlObjMgt_RRelocationTable& /*theRelocTable*/) const +{ + return Standard_True; +} + +//======================================================================= +//function : +//purpose : +//======================================================================= +void XmlMXCAFDoc_NotesToolDriver::Paste(const Handle(TDF_Attribute)& /*theSource*/, + XmlObjMgt_Persistent& /*theTarget*/, + XmlObjMgt_SRelocationTable& /*theRelocTable*/) const +{ +} diff --git a/src/XmlMXCAFDoc/XmlMXCAFDoc_NotesToolDriver.hxx b/src/XmlMXCAFDoc/XmlMXCAFDoc_NotesToolDriver.hxx new file mode 100644 index 0000000000..6de16cbe54 --- /dev/null +++ b/src/XmlMXCAFDoc/XmlMXCAFDoc_NotesToolDriver.hxx @@ -0,0 +1,55 @@ +// Created on: 2017-02-14 +// Created by: Sergey NIKONOV +// Copyright (c) 2008-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 _XmlMXCAFDoc_NotesToolDriver_HeaderFile +#define _XmlMXCAFDoc_NotesToolDriver_HeaderFile + +#include +#include + +#include +#include +#include +#include + +class CDM_MessageDriver; +class TDF_Attribute; +class XmlObjMgt_Persistent; + +class XmlMXCAFDoc_NotesToolDriver; +DEFINE_STANDARD_HANDLE(XmlMXCAFDoc_NotesToolDriver, XmlMDF_ADriver) + +//! Attribute Driver. +class XmlMXCAFDoc_NotesToolDriver : public XmlMDF_ADriver +{ +public: + + Standard_EXPORT XmlMXCAFDoc_NotesToolDriver(const Handle(CDM_MessageDriver)& theMsgDriver); + + Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE; + + Standard_EXPORT Standard_Boolean Paste(const XmlObjMgt_Persistent& theSource, + const Handle(TDF_Attribute)& theTarget, + XmlObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE; + + Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theSource, + XmlObjMgt_Persistent& theTarget, + XmlObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE; + + DEFINE_STANDARD_RTTIEXT(XmlMXCAFDoc_NotesToolDriver, XmlMDF_ADriver) + +}; + +#endif // _XmlMXCAFDoc_NotesToolDriver_HeaderFile