Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-28 09:20:01

0001 // Created on: 1999-04-07
0002 // Created by: Denis PASCAL
0003 // Copyright (c) 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 _TDocStd_Document_HeaderFile
0018 #define _TDocStd_Document_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 
0022 #include <Standard_Integer.hxx>
0023 #include <TDF_Transaction.hxx>
0024 #include <TDF_DeltaList.hxx>
0025 #include <CDM_Document.hxx>
0026 #include <TDF_LabelMap.hxx>
0027 #include <TDocStd_FormatVersion.hxx>
0028 class TDF_Data;
0029 class TDF_Delta;
0030 class TDF_Label;
0031 class TCollection_AsciiString;
0032 class TDocStd_CompoundDelta;
0033 
0034 class TDocStd_Document;
0035 DEFINE_STANDARD_HANDLE(TDocStd_Document, CDM_Document)
0036 
0037 //! The contents of a TDocStd_Application, a
0038 //! document is a container for a data framework
0039 //! composed of labels and attributes. As such,
0040 //! TDocStd_Document is the entry point into the data framework.
0041 //! To gain access to the data, you create a document as follows:
0042 //! Handle(TDocStd_Document) MyDF = new TDocStd_Document
0043 //! The document also allows you to manage:
0044 //! -   modifications, providing Undo and Redo functions.
0045 //! -   command transactions.
0046 //! Warning: The only data saved is the framework (TDF_Data)
0047 class TDocStd_Document : public CDM_Document
0048 {
0049 
0050 public:
0051   //! Will Abort any execution, clear fields
0052   //! returns the    document which contains <L>.  raises  an
0053   //! exception if the document is not found.
0054   Standard_EXPORT static Handle(TDocStd_Document) Get(const TDF_Label& L);
0055 
0056   //! Constructs a document object defined by the
0057   //! string astorageformat.
0058   //! If a document is created outside of an application using this constructor, it must be
0059   //! managed by a Handle. Otherwise memory problems could appear: call of
0060   //! TDocStd_Owner::GetDocument creates a Handle(TDocStd_Document), so, releasing it will produce a
0061   //! crash.
0062   Standard_EXPORT TDocStd_Document(const TCollection_ExtendedString& astorageformat);
0063 
0064   //! the document is saved in a file.
0065   Standard_EXPORT Standard_Boolean IsSaved() const;
0066 
0067   //! returns True if document differs from the state of last saving.
0068   //! this method have to be called only working in the transaction mode
0069   Standard_Boolean IsChanged() const;
0070 
0071   //! This method have to be called to show document that it has been saved
0072   void SetSaved();
0073 
0074   //! Say to document what it is not saved.
0075   //! Use value, returned earlier by GetSavedTime().
0076   void SetSavedTime(const Standard_Integer theTime);
0077 
0078   //! Returns value of <mySavedTime> to be used later in SetSavedTime()
0079   Standard_Integer GetSavedTime() const;
0080 
0081   //! raise if <me> is not saved.
0082   Standard_EXPORT TCollection_ExtendedString GetName() const;
0083 
0084   //! returns the OS  path of the  file, in which one <me> is
0085   //! saved. Raise an exception if <me> is not saved.
0086   Standard_EXPORT TCollection_ExtendedString GetPath() const;
0087 
0088   Standard_EXPORT void SetData(const Handle(TDF_Data)& data);
0089 
0090   Standard_EXPORT Handle(TDF_Data) GetData() const;
0091 
0092   //! Returns the main label in this data framework.
0093   //! By definition, this is the label with the entry 0:1.
0094   Standard_EXPORT TDF_Label Main() const;
0095 
0096   //! Returns True if the main label has no attributes
0097   Standard_EXPORT Standard_Boolean IsEmpty() const;
0098 
0099   //! Returns False if the document has been modified
0100   //! but not recomputed.
0101   Standard_EXPORT Standard_Boolean IsValid() const;
0102 
0103   //! Notify the label as modified, the Document becomes UnValid.
0104   //! returns True if <L> has been notified as modified.
0105   Standard_EXPORT void SetModified(const TDF_Label& L);
0106 
0107   //! Remove all modifications. After this call The document
0108   //! becomesagain Valid.
0109   Standard_EXPORT void PurgeModified();
0110 
0111   //! Returns the labels which have been modified in
0112   //! this document.
0113   Standard_EXPORT const TDF_LabelMap& GetModified() const;
0114 
0115   //! Launches a new command. This command may be undone.
0116   Standard_EXPORT void NewCommand();
0117 
0118   //! returns True if a Command transaction is open in the current .
0119   Standard_EXPORT Standard_Boolean HasOpenCommand() const;
0120 
0121   //! Opens a new command transaction in this document.
0122   //! You can use HasOpenCommand to see whether a command is already open.
0123   //! Exceptions
0124   //! Standard_DomainError if a command is already open in this document.
0125   Standard_EXPORT void OpenCommand();
0126 
0127   //! Commits documents transactions and fills the
0128   //! transaction manager with documents that have
0129   //! been changed during the transaction.
0130   //! If no command transaction is open, nothing is done.
0131   //! Returns True if a new delta has been added to myUndos.
0132   Standard_EXPORT Standard_Boolean CommitCommand();
0133 
0134   //! Abort the  Command  transaction. Does nothing If there is
0135   //! no Command transaction open.
0136   Standard_EXPORT void AbortCommand();
0137 
0138   //! The current limit on the number of undos
0139   Standard_EXPORT Standard_Integer GetUndoLimit() const;
0140 
0141   //! Set the  limit on  the number of  Undo Delta  stored 0
0142   //! will disable  Undo  on the  document A negative  value
0143   //! means no limit. Note that by default Undo is disabled.
0144   //! Enabling  it will  take effect with  the next  call to
0145   //! NewCommand. Of course this limit is the same for Redo
0146   Standard_EXPORT void SetUndoLimit(const Standard_Integer L);
0147 
0148   //! Remove all stored Undos and Redos
0149   Standard_EXPORT void ClearUndos();
0150 
0151   //! Remove all stored Redos
0152   Standard_EXPORT void ClearRedos();
0153 
0154   //! Returns the number of undos stored in this
0155   //! document. If this figure is greater than 0, the method Undo
0156   //! can be used.
0157   Standard_EXPORT Standard_Integer GetAvailableUndos() const;
0158 
0159   //! Will UNDO  one step, returns  False if no undo was
0160   //! done (Undos == 0).
0161   //! Otherwise, true is returned and one step in the
0162   //! list of undoes is undone.
0163   Standard_EXPORT Standard_Boolean Undo();
0164 
0165   //! Returns the number of redos stored in this
0166   //! document. If this figure is greater than 0, the method Redo
0167   //! can be used.
0168   Standard_EXPORT Standard_Integer GetAvailableRedos() const;
0169 
0170   //! Will REDO  one step, returns  False if no redo was
0171   //! done (Redos == 0).
0172   //! Otherwise, true is returned, and one step in the list of redoes is done again.
0173   Standard_EXPORT Standard_Boolean Redo();
0174 
0175   Standard_EXPORT const TDF_DeltaList& GetUndos() const;
0176 
0177   Standard_EXPORT const TDF_DeltaList& GetRedos() const;
0178 
0179   //! Removes the first undo in the list of document undos.
0180   //! It is used in the application when the undo limit is exceed.
0181   Standard_EXPORT void RemoveFirstUndo();
0182 
0183   //! Initializes the procedure of delta compaction
0184   //! Returns false if there is no delta to compact
0185   //! Marks the last delta as a "from" delta
0186   Standard_EXPORT Standard_Boolean InitDeltaCompaction();
0187 
0188   //! Performs the procedure of delta compaction
0189   //! Makes all deltas starting from "from" delta
0190   //! till the last one to be one delta.
0191   Standard_EXPORT Standard_Boolean PerformDeltaCompaction();
0192 
0193   //! Set   modifications on  labels  impacted  by  external
0194   //! references to the entry.  The document becomes invalid
0195   //! and must be recomputed.
0196   Standard_EXPORT void UpdateReferences(const TCollection_AsciiString& aDocEntry);
0197 
0198   //! Recompute if the document was  not valid and propagate
0199   //! the recorded modification.
0200   Standard_EXPORT void Recompute();
0201 
0202   //! This method Update   will be called
0203   //! to signal the end   of the modified references list.
0204   //! The    document     should    be  recomputed     and
0205   //! UpdateFromDocuments  should be called.  Update should
0206   //! returns True in case  of success, false otherwise.  In
0207   //! case of Failure, additional information can be given in
0208   //! ErrorString.
0209   //! Update the document by propagation
0210   //! ==================================
0211   //! Update   the    document    from   internal   stored
0212   //! modifications.   If   you   want  to   undoing  this
0213   //! operation, please call NewCommand before.
0214   //! to change format (advanced programming)
0215   //! ================
0216   Standard_EXPORT virtual void Update(const Handle(CDM_Document)& aToDocument,
0217                                       const Standard_Integer      aReferenceIdentifier,
0218                                       const Standard_Address      aModifContext) Standard_OVERRIDE;
0219 
0220   Standard_EXPORT virtual TCollection_ExtendedString StorageFormat() const Standard_OVERRIDE;
0221 
0222   //! Sets saving mode for empty labels. If Standard_True, empty labels will be saved.
0223   void SetEmptyLabelsSavingMode(const Standard_Boolean isAllowed);
0224 
0225   //! Returns saving mode for empty labels.
0226   Standard_Boolean EmptyLabelsSavingMode() const;
0227 
0228   //! methods for the nested transaction mode
0229   Standard_EXPORT virtual void ChangeStorageFormat(
0230     const TCollection_ExtendedString& newStorageFormat);
0231 
0232   //! Sets nested transaction mode if isAllowed == Standard_True
0233   void SetNestedTransactionMode(const Standard_Boolean isAllowed = Standard_True);
0234 
0235   //! Returns Standard_True if mode is set
0236   Standard_Boolean IsNestedTransactionMode() const;
0237 
0238   //! if theTransactionOnly is True changes is denied outside transactions
0239   void SetModificationMode(const Standard_Boolean theTransactionOnly);
0240 
0241   //! returns True if changes allowed only inside transactions
0242   Standard_Boolean ModificationMode() const;
0243 
0244   //! Prepares document for closing
0245   Standard_EXPORT virtual void BeforeClose();
0246 
0247   //! Returns version of the format to be used to store the document
0248   Standard_EXPORT TDocStd_FormatVersion StorageFormatVersion() const;
0249 
0250   //! Sets version of the format to be used to store the document
0251   Standard_EXPORT void ChangeStorageFormatVersion(const TDocStd_FormatVersion theVersion);
0252 
0253   //! Returns current storage format version of the document.
0254   Standard_EXPORT static TDocStd_FormatVersion CurrentStorageFormatVersion();
0255 
0256   //! Dumps the content of me into the stream
0257   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0258 
0259   DEFINE_STANDARD_RTTIEXT(TDocStd_Document, CDM_Document)
0260 
0261 protected:
0262   //! Returns Standard_True done
0263   Standard_EXPORT virtual Standard_Boolean CommitTransaction();
0264 
0265   Standard_EXPORT virtual void AbortTransaction();
0266 
0267   //! methods for protection of changes outside transactions
0268   Standard_EXPORT virtual void OpenTransaction();
0269 
0270   TCollection_ExtendedString myStorageFormat;
0271   TDF_DeltaList              myUndos;
0272   TDF_DeltaList              myRedos;
0273 
0274 private:
0275   //! Appends delta to the first delta in the myUndoFILO
0276   //! private methods
0277   //! ===============
0278   Standard_EXPORT static void AppendDeltaToTheFirst(const Handle(TDocStd_CompoundDelta)& theDelta1,
0279                                                     const Handle(TDF_Delta)&             theDelta2);
0280 
0281   Handle(TDF_Data)      myData;
0282   Standard_Integer      myUndoLimit;
0283   TDF_Transaction       myUndoTransaction;
0284   Handle(TDF_Delta)     myFromUndo;
0285   Handle(TDF_Delta)     myFromRedo;
0286   Standard_Integer      mySaveTime;
0287   Standard_Boolean      myIsNestedTransactionMode;
0288   TDF_DeltaList         myUndoFILO;
0289   Standard_Boolean      myOnlyTransactionModification;
0290   Standard_Boolean      mySaveEmptyLabels;
0291   TDocStd_FormatVersion myStorageFormatVersion;
0292 };
0293 
0294 #include <TDocStd_Document.lxx>
0295 
0296 #endif // _TDocStd_Document_HeaderFile