Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-25 08:17:42

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