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