Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-27 09:17:16

0001 // Created on: 1997-07-30
0002 // Created by: Jean-Louis Frenkel
0003 // Copyright (c) 1997-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _CDM_Document_HeaderFile
0018 #define _CDM_Document_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_Type.hxx>
0022 
0023 #include <CDM_Reference.hxx>
0024 #include <NCollection_List.hxx>
0025 #include <CDM_CanCloseStatus.hxx>
0026 #include <TCollection_ExtendedString.hxx>
0027 #include <NCollection_Sequence.hxx>
0028 #include <Standard_OStream.hxx>
0029 
0030 class CDM_MetaData;
0031 class CDM_Application;
0032 class CDM_Reference;
0033 class Resource_Manager;
0034 
0035 //! An applicative document is an instance of a class inheriting CDM_Document.
0036 //! These documents have the following properties:
0037 //! - they can have references to other documents.
0038 //! - the modifications of a document are propagated to the referencing
0039 //! documents.
0040 //! - a document can be stored in different formats, with or
0041 //! without a persistent model.
0042 //! - the drivers for storing and retrieving documents are
0043 //! plugged in when necessary.
0044 //! - a document has a modification counter. This counter is
0045 //! incremented when the document is modified. When a document
0046 //! is stored, the current counter value is memorized as the
0047 //! last storage version of the document. A document is
0048 //! considered to be modified when the counter value is
0049 //! different from the storage version. Once the document is
0050 //! saved the storage version and the counter value are
0051 //! identical. The document is now not considered to be
0052 //! modified.
0053 //! - a reference is a link between two documents. A reference has two
0054 //! components: the "From Document" and the "To Document". When
0055 //! a reference is created, an identifier of the reference is generated.
0056 //! This identifier is unique in the scope of the From Document and
0057 //! is conserved during storage and retrieval. This means that the
0058 //! referenced document will be always accessible through this
0059 //! identifier.
0060 //! - a reference memorizes the counter value of the To Document when
0061 //! the reference is created. The From Document is considered to
0062 //! be up to date relative to the To Document when the
0063 //! reference counter value is equal to the To Document counter value.
0064 //! -  retrieval of a document having references does not imply
0065 //! the retrieving of the referenced documents.
0066 class CDM_Document : public Standard_Transient
0067 {
0068 
0069 public:
0070   //! The Update method will be called once for each
0071   //! reference, but it should not perform any computation,
0072   //! to avoid multiple computation of a same document.
0073   Standard_EXPORT virtual void Update(const occ::handle<CDM_Document>& aToDocument,
0074                                       const int                        aReferenceIdentifier,
0075                                       void* const                      aModifContext);
0076 
0077   //! This method Update will be called
0078   //! to signal the end of the modified references list.
0079   //! The document should be recomputed and
0080   //! UpdateFromDocuments should be called. Update should
0081   //! returns True in case of success, false otherwise. In
0082   //! case of Failure, additional information can be given in
0083   //! ErrorString.
0084   Standard_EXPORT virtual bool Update(TCollection_ExtendedString& ErrorString);
0085 
0086   //! The Storage Format is the key which is used to determine in the
0087   //! application resources the storage driver plugin, the file
0088   //! extension and other data used to store the document.
0089   Standard_EXPORT virtual TCollection_ExtendedString StorageFormat() const = 0;
0090 
0091   //! by default empties the extensions.
0092   Standard_EXPORT virtual void Extensions(
0093     NCollection_Sequence<TCollection_ExtendedString>& Extensions) const;
0094 
0095   //! This method can be redefined to extract another document in
0096   //! a different format. For example, to extract a Shape
0097   //! from an applicative document.
0098   Standard_EXPORT virtual bool GetAlternativeDocument(
0099     const TCollection_ExtendedString& aFormat,
0100     occ::handle<CDM_Document>&        anAlternativeDocument);
0101 
0102   //! Creates a reference from this document to {anOtherDocument}.
0103   //! Returns a reference identifier. This reference identifier
0104   //! is unique in the document and will not be used for the
0105   //! next references, even after the storing of the document.
0106   //! If there is already a reference between the two documents,
0107   //! the reference is not created, but its reference identifier
0108   //! is returned.
0109   Standard_EXPORT int CreateReference(const occ::handle<CDM_Document>& anOtherDocument);
0110 
0111   //! Removes the reference between the From Document and the
0112   //! To Document identified by a reference identifier.
0113   Standard_EXPORT void RemoveReference(const int aReferenceIdentifier);
0114 
0115   //! Removes all references having this document for From Document.
0116   Standard_EXPORT void RemoveAllReferences();
0117 
0118   //! Returns the To Document of the reference identified by
0119   //! aReferenceIdentifier. If the ToDocument is stored and
0120   //! has not yet been retrieved, this method will retrieve it.
0121   Standard_EXPORT occ::handle<CDM_Document> Document(const int aReferenceIdentifier) const;
0122 
0123   //! returns True if the To Document of the reference
0124   //! identified by aReferenceIdentifier is in session, False
0125   //! if it corresponds to a not yet retrieved document.
0126   Standard_EXPORT bool IsInSession(const int aReferenceIdentifier) const;
0127 
0128   //! returns True if the To Document of the reference
0129   //! identified by aReferenceIdentifier has already been stored,
0130   //! False otherwise.
0131   Standard_EXPORT bool IsStored(const int aReferenceIdentifier) const;
0132 
0133   //! returns the name of the metadata of the To Document of
0134   //! the reference identified by aReferenceIdentifier.
0135   Standard_EXPORT TCollection_ExtendedString Name(const int aReferenceIdentifier) const;
0136 
0137   //! call virtual method Update on all referencing
0138   //! documents. This method keeps the list of the
0139   //! documents to process. It may be the starting of an
0140   //! update cycle. If not, the reentrant calls made by
0141   //! Update method (without argument) will append the
0142   //! referencing documents to the list and call the Update method
0143   //! (with arguments). Only the first call to UpdateFromDocuments
0144   //! generate call to Update().
0145   Standard_EXPORT void UpdateFromDocuments(void* const aModifContext) const;
0146 
0147   //! returns the number of references having this document as
0148   //! From Document.
0149   Standard_EXPORT int ToReferencesNumber() const;
0150 
0151   //! returns the number of references having this document as
0152   //! To Document.
0153   Standard_EXPORT int FromReferencesNumber() const;
0154 
0155   //! returns True is this document references aDocument;
0156   Standard_EXPORT bool ShallowReferences(const occ::handle<CDM_Document>& aDocument) const;
0157 
0158   //! returns True is this document references aDocument;
0159   Standard_EXPORT bool DeepReferences(const occ::handle<CDM_Document>& aDocument) const;
0160 
0161   //! Copies a reference to this document. This method
0162   //! avoid retrieval of referenced document. The arguments
0163   //! are the original document and a valid reference
0164   //! identifier Returns the local identifier.
0165   Standard_EXPORT int CopyReference(const occ::handle<CDM_Document>& aFromDocument,
0166                                     const int                        aReferenceIdentifier);
0167 
0168   //! indicates that this document cannot be modified.
0169   Standard_EXPORT bool IsReadOnly() const;
0170 
0171   //! indicates that the referenced document cannot be modified,
0172   Standard_EXPORT bool IsReadOnly(const int aReferenceIdentifier) const;
0173 
0174   Standard_EXPORT void SetIsReadOnly();
0175 
0176   Standard_EXPORT void UnsetIsReadOnly();
0177 
0178   //! Indicates that this document has been modified.
0179   //! This method increments the modification counter.
0180   Standard_EXPORT void Modify();
0181 
0182   //! returns the current modification counter.
0183   Standard_EXPORT int Modifications() const;
0184 
0185   Standard_EXPORT void UnModify();
0186 
0187   //! returns true if the modification counter found in the given
0188   //! reference is equal to the actual modification counter of
0189   //! the To Document. This method is able to deal with a reference
0190   //! to a not retrieved document.
0191   Standard_EXPORT bool IsUpToDate(const int aReferenceIdentifier) const;
0192 
0193   //! Resets the modification counter in the given reference
0194   //! to the actual modification counter of its To Document.
0195   //! This method should be called after the application has updated
0196   //! this document.
0197   Standard_EXPORT void SetIsUpToDate(const int aReferenceIdentifier);
0198 
0199   //! associates a comment with this document.
0200   Standard_EXPORT void SetComment(const TCollection_ExtendedString& aComment);
0201 
0202   //! appends a comment into comments of this document.
0203   Standard_EXPORT void AddComment(const TCollection_ExtendedString& aComment);
0204 
0205   //! associates a comments with this document.
0206   Standard_EXPORT void SetComments(
0207     const NCollection_Sequence<TCollection_ExtendedString>& aComments);
0208 
0209   //! returns the associated comments through <aComments>.
0210   //! Returns empty sequence if no comments are associated.
0211   Standard_EXPORT void Comments(NCollection_Sequence<TCollection_ExtendedString>& aComments) const;
0212 
0213   //! Returns the first of associated comments.
0214   //! By default the comment is an empty string.
0215   Standard_EXPORT const char16_t* Comment() const;
0216 
0217   Standard_EXPORT bool IsStored() const;
0218 
0219   //! returns the value of the modification counter at the
0220   //! time of storage. By default returns 0.
0221   Standard_EXPORT int StorageVersion() const;
0222 
0223   //! associates database information to a document which
0224   //! has been stored. The name of the document is now the
0225   //! name which has beenused to store the data.
0226   Standard_EXPORT void SetMetaData(const occ::handle<CDM_MetaData>& aMetaData);
0227 
0228   Standard_EXPORT void UnsetIsStored();
0229 
0230   Standard_EXPORT occ::handle<CDM_MetaData> MetaData() const;
0231 
0232   Standard_EXPORT TCollection_ExtendedString Folder() const;
0233 
0234   //! defines the folder in which the object should be stored.
0235   Standard_EXPORT void SetRequestedFolder(const TCollection_ExtendedString& aFolder);
0236 
0237   Standard_EXPORT TCollection_ExtendedString RequestedFolder() const;
0238 
0239   Standard_EXPORT bool HasRequestedFolder() const;
0240 
0241   //! defines the name under which the object should be stored.
0242   Standard_EXPORT void SetRequestedName(const TCollection_ExtendedString& aName);
0243 
0244   //! Determines under which the document is going to be store.
0245   //! By default the name of the document will be used.
0246   //! If the document has no name its presentation will be used.
0247   Standard_EXPORT TCollection_ExtendedString RequestedName();
0248 
0249   Standard_EXPORT void SetRequestedPreviousVersion(
0250     const TCollection_ExtendedString& aPreviousVersion);
0251 
0252   Standard_EXPORT void UnsetRequestedPreviousVersion();
0253 
0254   Standard_EXPORT bool HasRequestedPreviousVersion() const;
0255 
0256   Standard_EXPORT TCollection_ExtendedString RequestedPreviousVersion() const;
0257 
0258   //! defines the Comment with which the object should be stored.
0259   Standard_EXPORT void SetRequestedComment(const TCollection_ExtendedString& aComment);
0260 
0261   Standard_EXPORT TCollection_ExtendedString RequestedComment() const;
0262 
0263   //! read (or rereads) the following resource.
0264   Standard_EXPORT void LoadResources();
0265 
0266   Standard_EXPORT bool FindFileExtension();
0267 
0268   //! gets the Desktop.Domain.Application.`FileFormat`.FileExtension resource.
0269   Standard_EXPORT TCollection_ExtendedString FileExtension();
0270 
0271   Standard_EXPORT bool FindDescription();
0272 
0273   //! gets the `FileFormat`.Description resource.
0274   Standard_EXPORT TCollection_ExtendedString Description();
0275 
0276   //! returns true if the version is greater than the
0277   //! storage version
0278   Standard_EXPORT bool IsModified() const;
0279 
0280   Standard_EXPORT Standard_OStream& Print(Standard_OStream& anOStream) const;
0281   Standard_OStream&                 operator<<(Standard_OStream& anOStream);
0282 
0283   Standard_EXPORT bool IsOpened() const;
0284 
0285   Standard_EXPORT void Open(const occ::handle<CDM_Application>& anApplication);
0286 
0287   Standard_EXPORT CDM_CanCloseStatus CanClose() const;
0288 
0289   Standard_EXPORT void Close();
0290 
0291   Standard_EXPORT const occ::handle<CDM_Application>& Application() const;
0292 
0293   //! A referenced document may indicate through this
0294   //! virtual method that it does not allow the closing of
0295   //! aDocument which it references through the reference
0296   //! aReferenceIdentifier. By default returns true.
0297   Standard_EXPORT virtual bool CanCloseReference(const occ::handle<CDM_Document>& aDocument,
0298                                                  const int aReferenceIdentifier) const;
0299 
0300   //! A referenced document may update its internal
0301   //! data structure when {aDocument} which it references
0302   //! through the reference {aReferenceIdentifier} is being closed.
0303   //! By default this method does nothing.
0304   Standard_EXPORT virtual void CloseReference(const occ::handle<CDM_Document>& aDocument,
0305                                               const int aReferenceIdentifier);
0306 
0307   //! returns true if the document corresponding to the
0308   //! given reference has been retrieved and opened.
0309   //! Otherwise returns false. This method does not retrieve
0310   //! the referenced document
0311   Standard_EXPORT bool IsOpened(const int aReferenceIdentifier) const;
0312 
0313   Standard_EXPORT void CreateReference(const occ::handle<CDM_MetaData>&    aMetaData,
0314                                        const int                           aReferenceIdentifier,
0315                                        const occ::handle<CDM_Application>& anApplication,
0316                                        const int                           aToDocumentVersion,
0317                                        const bool                          UseStorageConfiguration);
0318 
0319   Standard_EXPORT int CreateReference(const occ::handle<CDM_MetaData>&    aMetaData,
0320                                       const occ::handle<CDM_Application>& anApplication,
0321                                       const int                           aDocumentVersion,
0322                                       const bool                          UseStorageConfiguration);
0323 
0324   Standard_EXPORT int ReferenceCounter() const;
0325 
0326   //! the following method should be used instead:
0327   //!
0328   //! Update(me:mutable; ErrorString: out ExtendedString from TCollection)
0329   //! returns Boolean from Standard
0330   Standard_EXPORT virtual void Update();
0331 
0332   Standard_EXPORT occ::handle<CDM_Reference> Reference(const int aReferenceIdentifier) const;
0333 
0334   Standard_EXPORT void SetModifications(const int Modifications);
0335 
0336   Standard_EXPORT void SetReferenceCounter(const int aReferenceCounter);
0337 
0338   //! Dumps the content of me into the stream
0339   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const;
0340 
0341   friend class CDM_Reference;
0342   friend class CDM_ReferenceIterator;
0343   friend class CDM_Application;
0344 
0345   DEFINE_STANDARD_RTTIEXT(CDM_Document, Standard_Transient)
0346 
0347 protected:
0348   Standard_EXPORT CDM_Document();
0349 
0350   Standard_EXPORT ~CDM_Document() override;
0351 
0352   bool myResourcesAreLoaded;
0353 
0354 private:
0355   //! the manager returned by this method will be
0356   //! used to search for the following resource items.
0357   Standard_EXPORT occ::handle<Resource_Manager> StorageResource();
0358 
0359   Standard_EXPORT void AddToReference(const occ::handle<CDM_Reference>& aReference);
0360 
0361   Standard_EXPORT void AddFromReference(const occ::handle<CDM_Reference>& aReference);
0362 
0363   Standard_EXPORT void RemoveFromReference(const int aReferenceIdentifier);
0364 
0365   NCollection_Sequence<TCollection_ExtendedString> myComments;
0366   NCollection_List<occ::handle<CDM_Reference>>     myFromReferences;
0367   NCollection_List<occ::handle<CDM_Reference>>     myToReferences;
0368   int                                              myVersion;
0369   int                                              myActualReferenceIdentifier;
0370   int                                              myStorageVersion;
0371   occ::handle<CDM_MetaData>                        myMetaData;
0372   TCollection_ExtendedString                       myRequestedComment;
0373   TCollection_ExtendedString                       myRequestedFolder;
0374   bool                                             myRequestedFolderIsDefined;
0375   TCollection_ExtendedString                       myRequestedName;
0376   bool                                             myRequestedNameIsDefined;
0377   bool                                             myRequestedPreviousVersionIsDefined;
0378   TCollection_ExtendedString                       myRequestedPreviousVersion;
0379   TCollection_ExtendedString                       myFileExtension;
0380   TCollection_ExtendedString                       myDescription;
0381   bool                                             myFileExtensionWasFound;
0382   bool                                             myDescriptionWasFound;
0383   occ::handle<CDM_Application>                     myApplication;
0384 };
0385 
0386 #endif // _CDM_Document_HeaderFile