Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-21 10:22:11

0001 // Created on: 2004-11-23
0002 // Created by: Pavel TELKOV
0003 // Copyright (c) 2004-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 // The original implementation Copyright: (C) RINA S.p.A
0017 
0018 #ifndef TObj_Model_HeaderFile
0019 #define TObj_Model_HeaderFile
0020 
0021 #include <Message_Messenger.hxx>
0022 #include <TObj_Partition.hxx>
0023 #include <TCollection_ExtendedString.hxx>
0024 
0025 class TObj_TNameContainer;
0026 class TCollection_HExtendedString;
0027 class TDocStd_Document;
0028 class TObj_CheckModel;
0029 class TObj_Application;
0030 
0031 /**
0032  * Base class for OCAF based models.
0033  * Defines common behaviour for all models based on TObject
0034  * classes, basic services to access model objects and common
0035  * operations with the model.
0036  * Provides default implementation for many methods.
0037  */
0038 
0039 class TObj_Model : public Standard_Transient
0040 {
0041 protected:
0042   //! Model may store some data on the data labels of its main partition
0043   //! See TObj_Object for
0044   enum DataTag
0045   {
0046     DataTag_FormatVersion = TObj_Partition::DataTag_Last,
0047     DataTag_Last
0048   };
0049 
0050 protected:
0051   /**
0052    * Constructors and Persistence
0053    */
0054 
0055   //! Empty constructor
0056   Standard_EXPORT TObj_Model();
0057 
0058   //! Destructor closes the model
0059   Standard_EXPORT ~TObj_Model() override;
0060 
0061   //! Check whether the document contains the OCAF data.
0062   Standard_EXPORT virtual bool checkDocumentEmpty(const TCollection_ExtendedString& theFile);
0063 
0064 public:
0065   /**
0066    * Messages mechanism
0067    */
0068 
0069   //! Set messenger to use for messages output
0070   void SetMessenger(const occ::handle<Message_Messenger>& theMsgr) { myMessenger = theMsgr; }
0071 
0072   //! Get messenger used for messages output (by default, the messenger from
0073   //! application is used)
0074   occ::handle<Message_Messenger> Messenger() const { return myMessenger; }
0075 
0076 public:
0077   /**
0078    * Implementation of Load/Save for OCAF based models
0079    */
0080 
0081   //! Load the OCAF model from a file. If the filename is empty or file does
0082   //! not exists, it just initializes model by empty data.
0083   Standard_EXPORT virtual bool Load(const TCollection_ExtendedString& theFile);
0084 
0085   //! Load the OCAF model from a stream. If case of failure,
0086   //! it initializes the model by empty data.
0087   Standard_EXPORT virtual bool Load(Standard_IStream& theIStream);
0088 
0089   //! Save the model to a file
0090   Standard_EXPORT virtual bool SaveAs(const TCollection_ExtendedString& theFile);
0091 
0092   //! Save the model to a stream
0093   Standard_EXPORT virtual bool SaveAs(Standard_OStream& theOStream);
0094 
0095   //! Save the model to the same file
0096   Standard_EXPORT bool Save();
0097 
0098 public:
0099   /**
0100    * Work with document
0101    */
0102 
0103   //! Close the model
0104   virtual Standard_EXPORT bool Close();
0105 
0106   //! Close Free OCAF document
0107   Standard_EXPORT void CloseDocument(const occ::handle<TDocStd_Document>& theDoc);
0108 
0109   //! Returns model which contains a document with the label,
0110   //! or NULL handle if label is NULL
0111   static Standard_EXPORT occ::handle<TObj_Model> GetDocumentModel(const TDF_Label& theLabel);
0112 
0113   //! Returns the full file name this model is to be saved to,
0114   //! or null if the model was not saved yet
0115   virtual Standard_EXPORT occ::handle<TCollection_HExtendedString> GetFile() const;
0116 
0117 public:
0118   /**
0119    * Access to the objects in the model
0120    */
0121 
0122   //! Returns an Iterator on all objects in the Model
0123   virtual Standard_EXPORT occ::handle<TObj_ObjectIterator> GetObjects() const;
0124 
0125   //! Returns an Iterator on objects in the main partition
0126   virtual Standard_EXPORT occ::handle<TObj_ObjectIterator> GetChildren() const;
0127 
0128   //! Returns an Object by given Name (or Null if not found).
0129   virtual Standard_EXPORT occ::handle<TObj_Object> FindObject(
0130     const occ::handle<TCollection_HExtendedString>& theName,
0131     const occ::handle<TObj_TNameContainer>&         theDictionary) const;
0132 
0133   //! Returns the tool checking model consistency.
0134   //! Descendant may redefine it to return its own tool.
0135   virtual Standard_EXPORT occ::handle<TObj_CheckModel> GetChecker() const;
0136 
0137 public:
0138   /**
0139    * Methods for iteration on the model
0140    */
0141 
0142   //! Returns root object of model
0143   virtual Standard_EXPORT occ::handle<TObj_Object> GetRoot() const;
0144 
0145   //! Returns root object of model
0146   Standard_EXPORT occ::handle<TObj_Partition> GetMainPartition() const;
0147 
0148 public:
0149   /**
0150    * OCAF methods
0151    */
0152 
0153   //! Returns OCAF label on which model data are stored.
0154   TDF_Label GetLabel() const { return myLabel; }
0155 
0156 public:
0157   /**
0158    * Methods for supporting unique naming of the objects in model
0159    */
0160 
0161   //! Returns the name of the model
0162   virtual Standard_EXPORT occ::handle<TCollection_HExtendedString> GetModelName() const;
0163 
0164   //! Sets new unique name for the object
0165   static Standard_EXPORT void SetNewName(const occ::handle<TObj_Object>& theObject);
0166 
0167   //! Returns True is name is registered in the names map
0168   //! The input argument may be NULL handle, then model check in own global container
0169   Standard_EXPORT bool IsRegisteredName(
0170     const occ::handle<TCollection_HExtendedString>& theName,
0171     const occ::handle<TObj_TNameContainer>&         theDictionary) const;
0172 
0173   //! Register name in the map
0174   //! The input argument may be NULL handle, then model check in own global container
0175   Standard_EXPORT void RegisterName(const occ::handle<TCollection_HExtendedString>& theName,
0176                                     const TDF_Label&                                theLabel,
0177                                     const occ::handle<TObj_TNameContainer>& theDictionary) const;
0178 
0179   //! Unregisters name from the map
0180   //! The input argument may be NULL handle, then model check in own global container
0181   Standard_EXPORT void UnRegisterName(const occ::handle<TCollection_HExtendedString>& theName,
0182                                       const occ::handle<TObj_TNameContainer>& theDictionary) const;
0183 
0184 public:
0185   /**
0186    * API for transaction mechanism
0187    */
0188 
0189   //! Returns True if a Command transaction is open
0190   //! Starting, finishing the transaction
0191   Standard_EXPORT bool HasOpenCommand() const;
0192 
0193   //! Open a new command transaction.
0194   Standard_EXPORT void OpenCommand() const;
0195 
0196   //! Commit the Command transaction. Do nothing If there is no Command
0197   //! transaction open.
0198   Standard_EXPORT void CommitCommand() const;
0199 
0200   //! Abort the Command transaction. Do nothing If there is no Command
0201   //! transaction open.
0202   Standard_EXPORT void AbortCommand() const;
0203 
0204   //! Modification status
0205   virtual Standard_EXPORT bool IsModified() const;
0206 
0207   //! Sets modification status
0208   Standard_EXPORT void SetModified(const bool theModified);
0209 
0210 public:
0211   /**
0212    * Methods for obtaining application
0213    */
0214 
0215   //! Returns handle to static instance of the relevant application class
0216   virtual Standard_EXPORT const occ::handle<TObj_Application> GetApplication();
0217 
0218 public:
0219   /**
0220    * Methods for obtaining the version of Format
0221    */
0222 
0223   //! Returns the format for save/restore.
0224   //! This implementation returns "BinOcaf". The method should be redefined
0225   //! for those models that should use another format.
0226   virtual Standard_EXPORT TCollection_ExtendedString GetFormat() const;
0227 
0228   //! Returns the version of format stored in TObj file
0229   Standard_EXPORT int GetFormatVersion() const;
0230 
0231 protected:
0232   /**
0233    * Methods for handling the version of the Format
0234    */
0235 
0236   //! Sets the format version to save
0237   Standard_EXPORT void SetFormatVersion(const int theVersion);
0238 
0239 public:
0240   /**
0241    * Methods for updating model
0242    */
0243 
0244   //! this method is called before activating this model
0245   virtual Standard_EXPORT bool Update();
0246 
0247 public:
0248   /**
0249    * Definition of interface GUID
0250    */
0251 
0252   //! Defines interface GUID for TObj_Model
0253   virtual Standard_EXPORT Standard_GUID GetGUID() const;
0254 
0255 public:
0256   /**
0257    * Internal methods
0258    */
0259 
0260   //! Returns the map of names of the objects
0261   Standard_EXPORT occ::handle<TObj_TNameContainer> GetDictionary() const;
0262 
0263 protected:
0264   /**
0265    * Internal methods
0266    */
0267 
0268   //! Returns (or creates a new) partition on a given label
0269   Standard_EXPORT occ::handle<TObj_Partition> getPartition(const TDF_Label& theLabel,
0270                                                            const bool theHidden = false) const;
0271 
0272   //! Returns Partition specified by its index number on a given label
0273   //! If not exists, creates anew with specified name
0274   Standard_EXPORT occ::handle<TObj_Partition> getPartition(
0275     const TDF_Label&                  theLabel,
0276     const int                         theIndex,
0277     const TCollection_ExtendedString& theName,
0278     const bool                        theHidden = false) const;
0279 
0280   //! Returns Partition specified by its index number
0281   //! If not exists, creates anew with specified name
0282   Standard_EXPORT occ::handle<TObj_Partition> getPartition(
0283     const int                         theIndex,
0284     const TCollection_ExtendedString& theName,
0285     const bool                        theHidden = false) const;
0286 
0287 public:
0288   //! Returns OCAF document of Model
0289   Standard_EXPORT occ::handle<TDocStd_Document> GetDocument() const;
0290 
0291 protected:
0292   // all that labels is sublabels of main partition
0293 
0294   //! Returns the labels under which the data is stored.
0295   //! the data stored from the third sublabel of this one.
0296   Standard_EXPORT TDF_Label GetDataLabel() const;
0297 
0298 public:
0299   //! Sets OCAF label on which model data are stored.
0300   //! Used by persistence mechanism.
0301   void SetLabel(const TDF_Label& theLabel) { myLabel = theLabel; }
0302 
0303 protected:
0304   //! Do the necessary initialisations after creation of a new model.
0305   //! This function is called by LoadModel after creation of OCAF document
0306   //! and setting myModel on its main label.
0307   //! Default implementation does nothing.
0308   //! Returns True is model sucsesfully initialized
0309   virtual Standard_EXPORT bool initNewModel(const bool IsNew);
0310 
0311   //! Updates back references of object
0312   //! Recursive method.
0313   virtual Standard_EXPORT void updateBackReferences(const occ::handle<TObj_Object>& theObject);
0314 
0315   //! Returns boolean value is to check model in Init new model
0316   //! The check could be useful if version of model changed
0317   //! Default implementation returns FALSE (check turned OFF)
0318   virtual bool isToCheck() const { return true; }
0319 
0320 public:
0321   /**
0322    * Methods for clone model
0323    */
0324 
0325   //! Pastes me to the new model
0326   //! references will not be copied if theRelocTable is not 0
0327   //! if theRelocTable is not NULL theRelocTable is filled by objects
0328   virtual Standard_EXPORT bool Paste(occ::handle<TObj_Model>          theModel,
0329                                      occ::handle<TDF_RelocationTable> theRelocTable = nullptr);
0330 
0331   //! This function have to create a new model with type like me
0332   virtual Standard_EXPORT occ::handle<TObj_Model> NewEmpty() = 0;
0333 
0334   //! Copy references from me to the other
0335   Standard_EXPORT void CopyReferences(const occ::handle<TObj_Model>&          theTarget,
0336                                       const occ::handle<TDF_RelocationTable>& theRelocTable);
0337 
0338 private:
0339   /**
0340    * Fields
0341    */
0342 
0343   TDF_Label                      myLabel;     //!< Root label of the model in OCAF document
0344   occ::handle<Message_Messenger> myMessenger; //!< Messenger object
0345 
0346 public:
0347   //! CASCADE RTTI
0348   DEFINE_STANDARD_RTTIEXT(TObj_Model, Standard_Transient)
0349 };
0350 
0351 //! The Model Handle is defined in a separate header file
0352 
0353 #endif