]> OCCT Git - occt-copy.git/commitdiff
0029822: Make TDocStd_Document extensible
authorvro <vladislav.romashko@opencascade.com>
Thu, 17 Dec 2020 11:34:47 +0000 (14:34 +0300)
committeragv <agv@opencascade.com>
Sun, 24 Jan 2021 15:17:51 +0000 (18:17 +0300)
Two virtual methods NewDocument() and InitDocument() are moved from TDocStd_Application to its parent class CDF_Application. In TDocStd_Application these methods remain redefined. These little changes allow creation of a new document only in one virtual method NewDocument(). The methods CreateDocument() in all retrieval drivers are deleted.

Modified files:
- CDF_Application.hxx and cxx: two virtual methods NewDocument() and InitDocument() are moved from TDocStd_Application. The input parameter TDocStd_Document is changed to parent class CDM_Document.
- TDocStd_Application.hxx and cxx: redefines new virtual methods NewDocument() and InitDocument() of the parent class CDF_Application.
- BinLDrivers_DocumentRetrievalDriver.hxx and cxx, StdLDrivers_DocumentRetrievalDriver.hxx and cxx, XmlLDrivers_DocumentRetrievalDriver.hxx and cxx, PCDM_Reader.hxx: a virtual method CreateDocument() is deleted.
- TObj_Application.cxx, XCAFApp_Application.hxx and cxx: down-casting to a descendant class TDocStd_Document is applied.

Documentation:
- upgrade.md is modified.

14 files changed:
dox/upgrade/upgrade.md
src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx
src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.hxx
src/CDF/CDF_Application.cxx
src/CDF/CDF_Application.hxx
src/PCDM/PCDM_Reader.hxx
src/StdLDrivers/StdLDrivers_DocumentRetrievalDriver.cxx
src/StdLDrivers/StdLDrivers_DocumentRetrievalDriver.hxx
src/TDocStd/TDocStd_Application.cxx
src/TDocStd/TDocStd_Application.hxx
src/XCAFApp/XCAFApp_Application.cxx
src/XCAFApp/XCAFApp_Application.hxx
src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.cxx
src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.hxx

index 80982b5882b9d46528d4f0b775b785533e718e09..52cc8d034b326e02547ef29272a9532759b70e9f 100644 (file)
@@ -2189,3 +2189,7 @@ In order to save a document in an older storage format version, call the method
 This value will be used by storage drivers of a corresponding OCAF file format (XML or binary) and the document will be saved
 following the rules of the specified storage format version (corresponding to an older version of Open CASCADE Technology).
 This way an application based on an old version of Open CASCADE Technology may read documents saved by new applications (based on newer version of Open CASCADE Technology).
+
+@subsection upgrade_760_createdocument New OCAF document
+
+A new OCAF document may be created only by means of the method *NewDocument()* from CDF_Application (redefined in TDocStd_Application). The methods *CreateDocument()* are deleted in all retrieval drivers.
index c8c26991c19b8b33d0e5d9d6964971143827e4d0..686e5853595bde6dac4a3b4bdcd03012f5b67d0a 100644 (file)
@@ -62,16 +62,6 @@ BinLDrivers_DocumentRetrievalDriver::BinLDrivers_DocumentRetrievalDriver ()
   myReaderStatus = PCDM_RS_OK;
 }
 
-//=======================================================================
-//function : CreateDocument
-//purpose  : pure virtual method definition
-//=======================================================================
-
-Handle(CDM_Document) BinLDrivers_DocumentRetrievalDriver::CreateDocument()
-{
-  return new TDocStd_Document(PCDM_RetrievalDriver::GetFormat());
-}
-
 //=======================================================================
 //function : Read
 //purpose  :
index 4a54d016193736db31c65c0bab9705a9fd8efb8f..7b9325af5c04e7c16e3b7d95792cff57782d1e1b 100644 (file)
@@ -55,9 +55,6 @@ public:
   //! Constructor
   Standard_EXPORT BinLDrivers_DocumentRetrievalDriver();
   
-  //! pure virtual method definition
-  Standard_EXPORT virtual Handle(CDM_Document) CreateDocument() Standard_OVERRIDE;
-  
   //! retrieves the content of the file into a new Document.
   Standard_EXPORT virtual void Read (const TCollection_ExtendedString& theFileName,
                                      const Handle(CDM_Document)& theNewDocument, 
index a1c16d87e68f89c669bc9b8169f4af2833c93769..3fbbd92e5eeceb1b35a7f8e8efe6638175803434 100644 (file)
@@ -52,6 +52,24 @@ Handle(CDF_Application) CDF_Application::Load(const Standard_GUID& aGUID) {
   return Handle(CDF_Application)::DownCast(Plugin::Load(aGUID));
 }
 
+//=======================================================================
+//function : NewDocument
+//purpose  :
+//=======================================================================
+
+void CDF_Application::NewDocument(const TCollection_ExtendedString& /*theFormat*/, Handle(CDM_Document)& /*theDoc*/)
+{
+}
+
+//=======================================================================
+//function : InitDocument
+//purpose  : do nothing
+//=======================================================================
+
+void CDF_Application::InitDocument(const Handle(CDM_Document)& /*theDoc*/) const
+{
+}
+
 //=======================================================================
 //function : Open
 //purpose  : 
@@ -264,7 +282,7 @@ Handle(CDM_Document) CDF_Application::Retrieve (const Handle(CDM_MetaData)& aMet
       theDocument->RemoveAllReferences();
     }
     else
-      theDocument=theReader->CreateDocument();
+      NewDocument(aFormat, theDocument);
     
     SetReferenceCounter(theDocument,PCDM_RetrievalDriver::ReferenceCounter(aMetaData->FileName(), MessageDriver()));
     
@@ -362,7 +380,7 @@ Handle(CDM_Document) CDF_Application::Read (Standard_IStream& theIStream,
   Handle(PCDM_Reader) aReader = ReaderFromFormat (aFormat);
 
   // 2. create document with the detected reader
-  aDoc = aReader->CreateDocument();
+  NewDocument(aFormat, aDoc);
 
   // 3. read the content of theIStream to aDoc
   try
index 3a979fb4f9c556d41f1aaceac7124d330fbeba73..d8ab7573b7bdb936cf9e153b72cd9b0a8be6122c 100644 (file)
@@ -58,7 +58,19 @@ public:
   //! opened by an application since the application resources are
   //! needed to store it.
   Standard_EXPORT static Handle(CDF_Application) Load (const Standard_GUID& aGUID);
-  
+
+  //! Constructs an new empty document.
+  //! This document will have the specified format.
+  //! If InitDocument() is redefined for a specific
+  //! application, the new document is handled by the
+  //! applicative session.
+  Standard_EXPORT virtual void NewDocument(const TCollection_ExtendedString& theFormat, Handle(CDM_Document)& theDoc);
+
+  //! Initialize a document for the applicative session.
+  //! This virtual function is called by NewDocument
+  //! and should be redefined for each specific application.
+  Standard_EXPORT virtual void InitDocument(const Handle(CDM_Document)& theDoc) const;
+
   //! puts the document in the current session directory
   //! and calls the virtual method Activate on it.
   Standard_EXPORT void Open (const Handle(CDM_Document)& aDocument);
index beeb7dd789e98d0171534b25927ada93b2de8e59..4a751de4d31a879eb8b398e2cad2a6498c83b454 100644 (file)
@@ -41,10 +41,6 @@ class PCDM_Reader : public Standard_Transient
 
 public:
 
-  
-  //! this method is called by the framework before the read method.
-  Standard_EXPORT virtual Handle(CDM_Document) CreateDocument() = 0;
-  
   //! retrieves the content of the file into a new Document.
   Standard_EXPORT virtual void Read (const TCollection_ExtendedString& aFileName, 
                                      const Handle(CDM_Document)& aNewDocument, 
index 8f8f752988a88ca272ba7514cc1510d124f37dc6..7ef95c85f5b330b634ccc338e55dcc8264838f47 100644 (file)
 
 IMPLEMENT_STANDARD_RTTIEXT (StdLDrivers_DocumentRetrievalDriver, PCDM_RetrievalDriver)
 
-//=======================================================================
-//function : CreateDocument
-//purpose  : Create an empty TDocStd_Document
-//=======================================================================
-Handle(CDM_Document) StdLDrivers_DocumentRetrievalDriver::CreateDocument()
-{
-  return new TDocStd_Document (PCDM_RetrievalDriver::GetFormat());
-}
-
 //=======================================================================
 //function : Read
 //purpose  : Retrieve the content of a file into a new document
index 100d568ac64be6be94a4734abcdb50f37f5981f2..c8e498ee8b89ddc6a3c17a29237f29ffd036df2e 100644 (file)
@@ -24,8 +24,6 @@ class StdObjMgt_Persistent;
 class StdLDrivers_DocumentRetrievalDriver : public PCDM_RetrievalDriver
 {
 public:
-  //! Create an empty TDocStd_Document.
-  Standard_EXPORT virtual Handle(CDM_Document) CreateDocument() Standard_OVERRIDE;
 
   //! Retrieve the content of a file into a new document.
   Standard_EXPORT virtual void Read (const TCollection_ExtendedString& theFileName,
index cd9d0f37c8d4e922c21d99bea333d29e4329a938..27f77042ad35df8c70cab37458f9b866114b0237 100644 (file)
@@ -181,7 +181,7 @@ void TDocStd_Application::GetDocument(const Standard_Integer index,Handle(TDocSt
 //purpose  :
 //=======================================================================
 
-void TDocStd_Application::NewDocument(const TCollection_ExtendedString& format,Handle(TDocStd_Document)& aDoc)
+void TDocStd_Application::NewDocument(const TCollection_ExtendedString& format, Handle(CDM_Document)& aDoc)
 {
   Handle(TDocStd_Document) D = new TDocStd_Document(format);
   InitDocument (D);
@@ -189,12 +189,25 @@ void TDocStd_Application::NewDocument(const TCollection_ExtendedString& format,H
   aDoc = D;
 }
 
+//=======================================================================
+//function : NewDocument
+//purpose  : A non-virtual method taking a TDocStd_Documment object as an input.
+//         : Internally it calls a virtual method NewDocument() with CDM_Document object.
+//=======================================================================
+
+void TDocStd_Application::NewDocument (const TCollection_ExtendedString& format, Handle(TDocStd_Document)& aDoc)
+{
+  Handle(CDM_Document) aCDMDoc;
+  NewDocument (format, aCDMDoc);
+  aDoc = Handle(TDocStd_Document)::DownCast (aCDMDoc);
+}
+
 //=======================================================================
 //function : InitDocument
 //purpose  : do nothing
 //=======================================================================
 
-void TDocStd_Application::InitDocument(const Handle(TDocStd_Document)& /*aDoc*/) const
+void TDocStd_Application::InitDocument(const Handle(CDM_Document)& /*aDoc*/) const
 {
 }
 
index e0d421e9d56d2ce7f8ba1cbf1242337be57b465a..bc28787000483a474ccbcf0eb112797aedbb447e 100644 (file)
 #include <TColStd_SequenceOfAsciiString.hxx>
 #include <PCDM_ReaderStatus.hxx>
 #include <PCDM_StoreStatus.hxx>
+#include <TDocStd_Document.hxx>
 
 class Resource_Manager;
 class Standard_NoSuchObject;
-class TDocStd_Document;
+class CDM_Document;
 class TCollection_ExtendedString;
 
 class TDocStd_Application;
@@ -180,7 +181,11 @@ public:
   //! If InitDocument is redefined for a specific
   //! application, the new document is handled by the
   //! applicative session.
-  Standard_EXPORT virtual void NewDocument (const TCollection_ExtendedString& format, Handle(TDocStd_Document)& aDoc);
+  Standard_EXPORT virtual void NewDocument (const TCollection_ExtendedString& format, Handle(CDM_Document)& aDoc) Standard_OVERRIDE;
+
+  //! A non-virtual method taking a TDocStd_Documment object as an input.
+  //! Internally it calls a virtual method NewDocument() with CDM_Document object.
+  Standard_EXPORT void NewDocument (const TCollection_ExtendedString& format, Handle(TDocStd_Document)& aDoc);
   
   //! Initialize the document aDoc for the applicative session.
   //! This virtual function is called by NewDocument
@@ -189,7 +194,7 @@ public:
   //! =============
   //! to open/save a document
   //! =======================
-  Standard_EXPORT virtual void InitDocument (const Handle(TDocStd_Document)& aDoc) const;
+  Standard_EXPORT virtual void InitDocument (const Handle(CDM_Document)& aDoc) const Standard_OVERRIDE;
   
   //! Close the given document. the document is not any more
   //! handled by the applicative session.
index 6e5e32a069bf5f50d757c575f0e98a7aa12b2f55..05c305b72cc16293d8191e3097370e344c5a1de7 100644 (file)
@@ -64,9 +64,9 @@ Standard_CString XCAFApp_Application::ResourcesName()
 //purpose  : 
 //=======================================================================
 
-void XCAFApp_Application::InitDocument(const Handle(TDocStd_Document)& aDoc) const
+void XCAFApp_Application::InitDocument(const Handle(CDM_Document)& aDoc) const
 {
-  XCAFDoc_DocumentTool::Set(aDoc->Main());
+  XCAFDoc_DocumentTool::Set(Handle(TDocStd_Document)::DownCast(aDoc)->Main());
 }
 
 //=======================================================================
index 05067f69c55913f324953e95fad7a8ebc066a240..18522711c650eff71e59fbd30f9476d8bb784209 100644 (file)
@@ -39,7 +39,7 @@ public:
   Standard_EXPORT virtual Standard_CString ResourcesName() Standard_OVERRIDE;
   
   //! Set XCAFDoc_DocumentTool attribute
-  Standard_EXPORT virtual void InitDocument (const Handle(TDocStd_Document)& aDoc) const Standard_OVERRIDE;
+  Standard_EXPORT virtual void InitDocument (const Handle(CDM_Document)& aDoc) const Standard_OVERRIDE;
   
   //! Initializes (for the first time) and returns the
   //! static object (XCAFApp_Application)
index fa8784f69b8bfa925b8050b2f9ea5029d15590bf..af8426a971fdb7df0ba8a44e5ab58cd0d23a0321 100644 (file)
@@ -161,15 +161,6 @@ XmlLDrivers_DocumentRetrievalDriver::XmlLDrivers_DocumentRetrievalDriver()
   myReaderStatus = PCDM_RS_OK;
 }
 
-//=======================================================================
-//function : CreateDocument
-//purpose  : pure virtual method definition
-//=======================================================================
-Handle(CDM_Document) XmlLDrivers_DocumentRetrievalDriver::CreateDocument()
-{
-  return new TDocStd_Document(PCDM_RetrievalDriver::GetFormat());
-}
-
 //=======================================================================
 //function : Read
 //purpose  : 
index 37904ebcb32687ab0a3f33fad912c3059499d8c6..6617c9cb5a0b08b5a258d89b8d17923c13f19026 100644 (file)
@@ -47,8 +47,6 @@ public:
   
   Standard_EXPORT XmlLDrivers_DocumentRetrievalDriver();
   
-  Standard_EXPORT virtual Handle(CDM_Document) CreateDocument() Standard_OVERRIDE;
-  
   Standard_EXPORT virtual void Read (const TCollection_ExtendedString& theFileName, 
                                      const Handle(CDM_Document)& theNewDocument,
                                      const Handle(CDM_Application)& theApplication,