0024947: Redesign OCCT legacy type system -- automatic
[occt.git] / src / TObj / TObj_Model.hxx
CommitLineData
b311480e 1// Created on: 2004-11-23
2// Created by: Pavel TELKOV
973c2be1 3// Copyright (c) 2004-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
7fd59977 16// The original implementation Copyright: (C) RINA S.p.A
17
18#ifndef TObj_Model_HeaderFile
19#define TObj_Model_HeaderFile
20
21#include <Handle_TObj_Model.hxx>
22
23#include <TDF_Label.hxx>
24#include <TObj_Partition.hxx>
7fd59977 25#include <Message_Messenger.hxx>
26
27class Handle(TObj_Application);
28class Handle(TObj_TNameContainer);
29class Handle(TObj_Object);
30class Handle(TObj_Partition);
31class Handle(TObj_CheckModel);
32
33class Handle(TCollection_HExtendedString);
34class Handle(TDocStd_Document);
35
36/**
37* Base class for OCAF based models.
38* Defines common behaviour for all models based on TObject
39* classes, basic services to access model objects and common
40* operations with the model.
41* Provides default implementation for many methods.
42*/
43
44class TObj_Model : public MMgt_TShared
45{
46 protected:
47
48 //! Model may store some data on the data labels of its main partition
49 //! See TObj_Object for
50 enum DataTag
51 {
52 DataTag_FormatVersion = TObj_Partition::DataTag_Last,
53 DataTag_Last
54 };
55
56 protected:
57 /**
58 * Constructors and Persistence
59 */
60
61 //! Empty constructor
62 Standard_EXPORT TObj_Model ();
63
64 //! Destructor closes the model
65 Standard_EXPORT ~TObj_Model ();
66
67 //! Check whether the document contains the OCAF data.
68 //! This implementation checks theFile on NULL only.
69 Standard_EXPORT virtual Standard_Boolean checkDocumentEmpty (const char* theFile);
70
71 public:
72 /**
73 * Messages mechanism
74 */
75
76 //! Set messenger to use for messages output
77 Standard_EXPORT void SetMessenger (const Handle(Message_Messenger) &theMsgr) { myMessenger = theMsgr; }
78
79 //! Get messenger used for messages output (by default, the messenger from
80 //! application is used)
81 Standard_EXPORT Handle(Message_Messenger) Messenger () const { return myMessenger; }
82
83 public:
84 /**
85 * Implementation of Load/Save for OCAF based models
86 */
87
88 //! Load the OCAF model from a file
89 virtual Standard_EXPORT Standard_Boolean Load (const char* theFile);
90
91 //! Save the model to a file
92 virtual Standard_EXPORT Standard_Boolean SaveAs (const char* theFile);
93
94 //! Save the model to the same file
95 Standard_EXPORT Standard_Boolean Save ();
96
97 public:
98 /**
99 * Work with document
100 */
101
102 //! Close the model
103 virtual Standard_EXPORT Standard_Boolean Close();
104
105 //! Close Free OCAF document
106 Standard_EXPORT void CloseDocument (const Handle(TDocStd_Document)& theDoc);
107
108 //! Returns model which contains a document with the label,
109 //! or NULL handle if label is NULL
110 static Standard_EXPORT Handle(TObj_Model) GetDocumentModel (const TDF_Label& theLabel);
111
112 //! Returns the full file name this model is to be saved to,
113 //! or null if the model was not saved yet
114 virtual Standard_EXPORT Handle(TCollection_HAsciiString) GetFile() const;
115
116 public:
117 /**
118 * Access to the objects in the model
119 */
120
121 //! Returns an Iterator on all objects in the Model
122 virtual Standard_EXPORT Handle(TObj_ObjectIterator) GetObjects () const;
123
124 //! Returns an Iterator on objects in the main partition
125 virtual Standard_EXPORT Handle(TObj_ObjectIterator) GetChildren () const;
126
127 //! Returns an Object by given Name (or Null if not found).
128 virtual Standard_EXPORT Handle(TObj_Object) FindObject
129 (const Handle(TCollection_HExtendedString)& theName,
130 const Handle(TObj_TNameContainer)& theDictionary ) const;
131
132 //! Returns the tool checking model consistency.
133 //! Descendant may redefine it to return its own tool.
134 virtual Standard_EXPORT Handle(TObj_CheckModel) GetChecker() const;
135
136 public:
137 /**
138 * Methods for iteration on the model
139 */
140
141 //! Returns root object of model
142 virtual Standard_EXPORT Handle(TObj_Object) GetRoot() const;
143
144 //! Returns root object of model
145 Standard_EXPORT Handle(TObj_Partition) GetMainPartition() const;
146
147 public:
148 /**
149 * OCAF methods
150 */
151
152 //! Returns OCAF label on which model data are stored.
153 TDF_Label GetLabel() const { return myLabel; }
154
155 public:
156 /**
157 * Methods for supporting unique naming of the objects in model
158 */
159
160 //! Returns the name of the model
161 virtual Standard_EXPORT Handle(TCollection_HExtendedString) GetModelName() const;
162
163 //! Sets new unique name for the object
164 static Standard_EXPORT void SetNewName
165 (const Handle(TObj_Object)& theObject);
166
167 //! Returns True is name is registered in the names map
168 //! The input argument may be NULL handle, then model check in own global container
169 Standard_EXPORT Standard_Boolean IsRegisteredName
170 (const Handle(TCollection_HExtendedString)& theName,
171 const Handle(TObj_TNameContainer)& theDictionary ) const;
172
173 //! Register name in the map
174 //! The input argument may be NULL handle, then model check in own global container
175 Standard_EXPORT void RegisterName
176 (const Handle(TCollection_HExtendedString)& theName,
177 const TDF_Label& theLabel,
178 const Handle(TObj_TNameContainer)& theDictionary ) const;
179
180 //! Unregisters name from the map
181 //! The input argument may be NULL handle, then model check in own global container
182 Standard_EXPORT void UnRegisterName
183 (const Handle(TCollection_HExtendedString)& theName,
184 const Handle(TObj_TNameContainer)& theDictionary ) const;
185
186 public:
187 /**
188 * API for transaction mechanism
189 */
190
191 //! Returns True if a Command transaction is open
192 //! Starting, finishing the transaction
193 Standard_EXPORT Standard_Boolean HasOpenCommand() const;
194
195 //! Open a new command transaction.
196 Standard_EXPORT void OpenCommand() const;
197
198 //! Commit the Command transaction. Do nothing If there is no Command
199 //! transaction open.
200 Standard_EXPORT void CommitCommand() const;
201
202 //! Abort the Command transaction. Do nothing If there is no Command
203 //! transaction open.
204 Standard_EXPORT void AbortCommand() const;
205
206 //! Modification status
207 virtual Standard_EXPORT Standard_Boolean IsModified () const;
208
209 //! Sets modification status
210 Standard_EXPORT void SetModified (const Standard_Boolean theModified);
211
212 public:
213 /**
214 * Methods for obtaining application
215 */
216
217 //! Returns handle to static instance of the relevant application class
218 virtual Standard_EXPORT const Handle(TObj_Application) GetApplication();
219
220 public:
221 /**
222 * Methods for obtaining the version of Format
223 */
224
225 //! Returns the format for save/restore.
226 //! This implementation returns "BinOcaf". The method should be redefined
227 //! for those models that should use another format.
228 virtual Standard_EXPORT TCollection_ExtendedString GetFormat() const;
229
230 //! Returns the version of format stored in TObj file
231 Standard_EXPORT Standard_Integer GetFormatVersion() const;
232
233 protected:
234 /**
235 * Methods for handling the version of the Format
236 */
237
238 //! Sets the format version to save
239 Standard_EXPORT void SetFormatVersion(const Standard_Integer theVersion);
240
241 public:
242 /**
243 * Methods for updating model
244 */
245
246 //! this method is called before activating this model
247 virtual Standard_EXPORT Standard_Boolean Update ();
248
249 public:
250 /**
251 * Definition of interface GUID
252 */
253
254 //! Defines interface GUID for TObj_Model
255 virtual Standard_EXPORT Standard_GUID GetGUID () const;
256
257 public:
258 /**
259 * Internal methods
260 */
261
262 //! Returns the map of names of the objects
263 Standard_EXPORT Handle(TObj_TNameContainer) GetDictionary() const;
264
265 protected:
266 /**
267 * Internal methods
268 */
269
270 //! Returns (or creates a new) partition on a given label
271 Standard_EXPORT Handle(TObj_Partition) getPartition
272 (const TDF_Label& theLabel,
273 const Standard_Boolean theHidden=Standard_False) const;
274
275 //! Returns Partition specified by its index number on a given label
276 //! If not exists, creates anew with specified name
277 Standard_EXPORT Handle(TObj_Partition) getPartition
278 (const TDF_Label& theLabel,
279 const Standard_Integer theIndex,
280 const TCollection_ExtendedString& theName,
281 const Standard_Boolean theHidden=Standard_False) const;
282
283 //! Returns Partition specified by its index number
284 //! If not exists, creates anew with specified name
285 Standard_EXPORT Handle(TObj_Partition) getPartition
286 (const Standard_Integer theIndex,
287 const TCollection_ExtendedString& theName,
288 const Standard_Boolean theHidden=Standard_False) const;
289
290 public:
291
292 //! Returns OCAF document of Model
293 Standard_EXPORT Handle(TDocStd_Document) GetDocument() const;
294
295 protected:
296 // all that labels is sublabels of main partition
297
298 //! Returns the labels under which the data is stored.
299 //! the data stored from the third sublabel of this one.
300 Standard_EXPORT TDF_Label GetDataLabel() const;
301
302 public:
303
304 //! Sets OCAF label on which model data are stored.
305 //! Used by persistence mechanism.
306 void Standard_EXPORT SetLabel(const TDF_Label& theLabel) { myLabel = theLabel; }
307
308 protected:
309
310 //! Do the necessary initialisations after creation of a new model.
311 //! This function is called by LoadModel after creation of OCAF document
312 //! and setting myModel on its main label.
313 //! Default implementation does nothing.
314 //! Returns True is model sucsesfully initialized
315 virtual Standard_EXPORT Standard_Boolean initNewModel
316 (const Standard_Boolean IsNew);
317
318 //! Updates back references of object
319 //! Recursive method.
320 virtual Standard_EXPORT void updateBackReferences
321 (const Handle(TObj_Object)& theObject);
322
323 //! Returns boolean value is to check model in Init new model
324 //! The check could be useful if version of model changed
325 //! Default implementation returns FALSE (check turned OFF)
326 virtual Standard_EXPORT Standard_Boolean isToCheck() const
327 { return Standard_True; }
328
329 public:
330 /**
331 * Methods for clone model
332 */
333
334 //! Pastes me to the new model
335 //! references will not be copied if theRelocTable is not 0
336 //! if theRelocTable is not NULL theRelocTable is filled by objects
337 virtual Standard_EXPORT Standard_Boolean Paste
338 (Handle(TObj_Model) theModel,
339 Handle(TDF_RelocationTable) theRelocTable = 0);
340
341 //! This function have to create a new model with type like me
342 virtual Standard_EXPORT Handle(TObj_Model) NewEmpty() = 0;
343
344 //! Copy references from me to the other
345 Standard_EXPORT void CopyReferences
346 (const Handle(TObj_Model)& theTarget,
347 const Handle(TDF_RelocationTable)& theRelocTable);
348
349 private:
350 /**
351 * Fields
352 */
353
354 TDF_Label myLabel; //!< Root label of the model in OCAF document
355 Handle(Message_Messenger) myMessenger; //!< Messenger object
356
357 public:
358 //! CASCADE RTTI
ec357c5c 359 DEFINE_STANDARD_RTTI(TObj_Model, MMgt_TShared)
7fd59977 360};
361
362//! The Model Handle is defined in a separate header file
363
364#endif