Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:22

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 
0046   //! Model may store some data on the data labels of its main partition
0047   //! See TObj_Object for 
0048   enum DataTag
0049   {
0050     DataTag_FormatVersion = TObj_Partition::DataTag_Last,
0051     DataTag_Last
0052   };
0053 
0054  protected:
0055   /**
0056   * Constructors and Persistence
0057   */
0058 
0059   //! Empty constructor
0060   Standard_EXPORT TObj_Model ();
0061 
0062   //! Destructor closes the model
0063   Standard_EXPORT ~TObj_Model ();
0064 
0065   //! Check whether the document contains the OCAF data.
0066   Standard_EXPORT virtual Standard_Boolean checkDocumentEmpty(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
0170                         (const Handle(TObj_Object)& theObject);
0171 
0172   //! Returns True is name is registered in the names map
0173   //! The input argument may be NULL handle, then model check in own global container
0174   Standard_EXPORT Standard_Boolean IsRegisteredName
0175                         (const Handle(TCollection_HExtendedString)& theName,
0176                          const Handle(TObj_TNameContainer)& theDictionary ) const;
0177 
0178   //! Register name in the map
0179   //! The input argument may be NULL handle, then model check in own global container
0180   Standard_EXPORT void RegisterName
0181                         (const Handle(TCollection_HExtendedString)& theName,
0182                          const TDF_Label& theLabel,
0183                          const Handle(TObj_TNameContainer)& theDictionary ) const;
0184 
0185   //! Unregisters name from the map
0186   //! The input argument may be NULL handle, then model check in own global container
0187   Standard_EXPORT void UnRegisterName
0188                         (const Handle(TCollection_HExtendedString)& theName,
0189                          const Handle(TObj_TNameContainer)& theDictionary ) const;
0190 
0191  public:
0192   /**
0193   * API for transaction mechanism
0194   */
0195 
0196   //! Returns True if a Command transaction is open
0197   //! Starting, finishing the transaction
0198   Standard_EXPORT Standard_Boolean HasOpenCommand() const;
0199 
0200   //! Open a new command transaction.
0201   Standard_EXPORT void OpenCommand() const;
0202 
0203   //! Commit the Command transaction. Do nothing If there is no Command
0204   //! transaction open.
0205   Standard_EXPORT void CommitCommand() const;
0206 
0207   //! Abort the  Command  transaction. Do nothing If there is no Command
0208   //! transaction open.
0209   Standard_EXPORT void AbortCommand() const;
0210 
0211   //! Modification status
0212   virtual Standard_EXPORT Standard_Boolean IsModified () const;
0213 
0214   //! Sets modification status
0215   Standard_EXPORT void SetModified (const Standard_Boolean theModified);
0216 
0217  public:
0218   /**
0219   * Methods for obtaining application
0220   */
0221 
0222   //! Returns handle to static instance of the relevant application class
0223   virtual Standard_EXPORT const Handle(TObj_Application) GetApplication();
0224 
0225  public:
0226   /**
0227   * Methods for obtaining the version of Format
0228   */
0229 
0230   //! Returns the format for save/restore.
0231   //! This implementation returns "BinOcaf". The method should be redefined
0232   //! for those models that should use another format.
0233   virtual Standard_EXPORT TCollection_ExtendedString GetFormat() const;
0234 
0235   //! Returns the version of format stored in TObj file
0236   Standard_EXPORT Standard_Integer GetFormatVersion() const;
0237 
0238  protected:
0239   /**
0240   * Methods for handling the version of the Format
0241   */
0242 
0243   //! Sets the format version to save
0244   Standard_EXPORT void SetFormatVersion(const Standard_Integer theVersion);
0245 
0246  public:
0247   /**
0248   * Methods for updating model
0249   */
0250 
0251   //! this method is called before activating this model
0252   virtual Standard_EXPORT Standard_Boolean Update ();
0253 
0254  public:
0255   /**
0256   * Definition of interface GUID
0257   */
0258 
0259   //! Defines interface GUID for TObj_Model
0260   virtual Standard_EXPORT Standard_GUID GetGUID () const;
0261 
0262  public:
0263   /**
0264   * Internal methods
0265   */
0266 
0267   //! Returns the map of names of the objects
0268   Standard_EXPORT Handle(TObj_TNameContainer) GetDictionary() const;
0269 
0270  protected:
0271   /**
0272   * Internal methods
0273   */
0274 
0275   //! Returns (or creates a new) partition on a given label
0276   Standard_EXPORT Handle(TObj_Partition) getPartition
0277                          (const TDF_Label&       theLabel,
0278                           const Standard_Boolean theHidden=Standard_False) const;
0279 
0280   //! Returns Partition specified by its index number on a given label
0281   //! If not exists, creates anew with specified name
0282   Standard_EXPORT Handle(TObj_Partition) getPartition
0283               (const TDF_Label&                  theLabel,
0284                const Standard_Integer            theIndex,
0285                const TCollection_ExtendedString& theName,
0286                const Standard_Boolean            theHidden=Standard_False) const;
0287 
0288   //! Returns Partition specified by its index number
0289   //! If not exists, creates anew with specified name
0290   Standard_EXPORT Handle(TObj_Partition) getPartition
0291               (const Standard_Integer            theIndex,
0292                const TCollection_ExtendedString& theName,
0293                const Standard_Boolean            theHidden=Standard_False) const;
0294 
0295  public:
0296 
0297   //! Returns OCAF document of Model
0298   Standard_EXPORT Handle(TDocStd_Document) GetDocument() const;
0299 
0300  protected:
0301    // all that labels is sublabels of main partition
0302 
0303   //! Returns the labels under which the data is stored.
0304   //! the data stored from the third sublabel of this one.
0305   Standard_EXPORT TDF_Label GetDataLabel() const;
0306 
0307  public:
0308 
0309   //! Sets OCAF label on which model data are stored.
0310   //! Used by persistence mechanism.
0311   void SetLabel(const TDF_Label& theLabel) { myLabel = theLabel; }
0312 
0313  protected:
0314 
0315   //! Do the necessary initialisations after creation of a new model.
0316   //! This function is called by LoadModel after creation of OCAF document
0317   //! and setting myModel on its main label.
0318   //! Default implementation does nothing.
0319   //! Returns True is model sucsesfully initialized
0320   virtual Standard_EXPORT Standard_Boolean initNewModel
0321                         (const Standard_Boolean IsNew);
0322 
0323   //! Updates back references of object
0324   //! Recursive method.
0325   virtual Standard_EXPORT void updateBackReferences
0326                         (const Handle(TObj_Object)& theObject);
0327 
0328   //! Returns boolean value is to check model in Init new model
0329   //! The check could be useful if version of model changed
0330   //! Default implementation returns FALSE (check turned OFF)
0331   virtual Standard_Boolean isToCheck() const
0332   { return Standard_True; }
0333 
0334  public:
0335   /**
0336   * Methods for clone model
0337   */
0338 
0339   //! Pastes me to the new model
0340   //! references will not be copied if theRelocTable is not 0
0341   //! if theRelocTable is not NULL theRelocTable is filled by objects
0342   virtual Standard_EXPORT Standard_Boolean Paste 
0343                          (Handle(TObj_Model) theModel,
0344                           Handle(TDF_RelocationTable) theRelocTable = 0);
0345 
0346   //! This function have to create a new model with type like me
0347   virtual Standard_EXPORT Handle(TObj_Model) NewEmpty() = 0;
0348 
0349   //! Copy references from me to the other
0350   Standard_EXPORT void CopyReferences
0351     (const Handle(TObj_Model)& theTarget,
0352      const Handle(TDF_RelocationTable)& theRelocTable);
0353 
0354  private:
0355   /**
0356   * Fields
0357   */
0358 
0359   TDF_Label myLabel;                     //!< Root label of the model in OCAF document
0360   Handle(Message_Messenger) myMessenger; //!< Messenger object
0361 
0362  public:
0363   //! CASCADE RTTI
0364   DEFINE_STANDARD_RTTIEXT(TObj_Model,Standard_Transient)
0365 };
0366 
0367 //! The Model Handle is defined in a separate header file
0368 
0369 #endif