Salome HOME
Merging from V3_2_6pre4
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_Study.hxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : SALOMEDSImpl_Study.hxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24 #ifndef __SALOMEDSIMPL_STUDY_I_H__
25 #define __SALOMEDSIMPL_STUDY_I_H__
26
27 //Handle definition
28 #include <Handle_MMgt_TShared.hxx>
29 #include <Standard_DefineHandle.hxx>
30 DEFINE_STANDARD_HANDLE( SALOMEDSImpl_Study, MMgt_TShared )
31
32 // std C++ headers
33 #include <iostream>
34
35 // Cascade headers
36 #include <TDocStd_Document.hxx>
37 #include <TDF_Tool.hxx>
38 #include <TDF_Data.hxx>
39 #include <TDF_Label.hxx>
40 #include <stdio.h>
41 #include <TCollection_AsciiString.hxx>
42 #include <TColStd_SequenceOfInteger.hxx>
43 #include <TColStd_SequenceOfAsciiString.hxx>
44 #include <TColStd_HSequenceOfAsciiString.hxx>
45 #include <TColStd_HSequenceOfTransient.hxx>
46 #include <NCollection_DataMap.hxx>
47
48 //SALOMEDSImpl headers
49 #include "SALOMEDSImpl_SComponentIterator.hxx"
50 #include "SALOMEDSImpl_SObject.hxx"
51 #include "SALOMEDSImpl_StudyBuilder.hxx"
52 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
53 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
54 #include "SALOMEDSImpl_AttributeIOR.hxx"
55 #include "SALOMEDSImpl_AttributeParameter.hxx"
56 #include "SALOMEDSImpl_Callback.hxx"
57 #include "SALOMEDSImpl_Driver.hxx" 
58 #include "SALOMEDSImpl_ChildIterator.hxx" 
59
60 class SALOMEDSImpl_StudyManager;
61 class SALOMEDSImpl_GenericAttribute;
62
63 typedef NCollection_DataMap <TCollection_AsciiString, Handle_Standard_Transient> DataMapOfAsciiStringTransient;
64 typedef NCollection_DataMap <TCollection_AsciiString, TDF_Label> DataMapAsciiStringLabel;
65
66 class SALOMEDSImpl_Study : public MMgt_TShared 
67 {
68 private:
69   TCollection_AsciiString              _name;  
70   Handle(TDocStd_Document) _doc;  // OCAF Document
71   bool                     _Saved; // True if the Study is saved
72   TCollection_AsciiString  _URL; //URL of the persistent reference of the study
73   int                      _StudyId; 
74   TDF_Label                _current;
75   bool                     _autoFill; 
76   TCollection_AsciiString  _errorCode;
77   Handle(TColStd_HSequenceOfAsciiString) _lockers;
78   Handle(SALOMEDSImpl_Callback)          _cb;
79   Handle(SALOMEDSImpl_StudyBuilder)      _builder;
80   Handle(SALOMEDSImpl_UseCaseBuilder)    _useCaseBuilder;
81
82   DataMapOfAsciiStringTransient _mapOfSO;
83   DataMapOfAsciiStringTransient _mapOfSCO;
84
85   // data structures for postponed destroying of object functionality
86   TColStd_SequenceOfAsciiString myPostponedIORs; // ordered set of IORs
87   TColStd_SequenceOfInteger myNbPostponed; // number of IOR in the each transaction
88   int myNbUndos; // number of current Undos, made by user
89   DataMapAsciiStringLabel myIORLabels;
90  
91
92   Handle(SALOMEDSImpl_SObject)    _FindObject(const Handle(SALOMEDSImpl_SObject)& SO,
93                                               const TCollection_AsciiString& anObjectName,
94                                               bool& _find);
95                                        
96   Handle(SALOMEDSImpl_SObject)   _FindObjectIOR(const Handle(SALOMEDSImpl_SObject)& SO,
97                                                 const TCollection_AsciiString& anObjectIOR,
98                                                 bool& _find);
99
100 public:
101
102   Standard_EXPORT static Handle(SALOMEDSImpl_Study) GetStudy(const TDF_Label& theLabel);
103   Standard_EXPORT static Handle(SALOMEDSImpl_SObject) SObject(const TDF_Label& theLabel);
104   Standard_EXPORT static Handle(SALOMEDSImpl_SComponent) SComponent(const TDF_Label& theLabel);
105   Standard_EXPORT static void IORUpdated(const Handle(SALOMEDSImpl_AttributeIOR)& theAttribute);
106
107   //! standard constructor
108   Standard_EXPORT SALOMEDSImpl_Study(const Handle(TDocStd_Document)&, const TCollection_AsciiString& study_name);
109   
110   //! standard destructor
111   Standard_EXPORT virtual ~SALOMEDSImpl_Study(); 
112   
113   //! method to Get persistent reference of study (idem URL())
114   Standard_EXPORT virtual TCollection_AsciiString GetPersistentReference();
115
116   //! method to Get transient reference of study
117   Standard_EXPORT virtual TCollection_AsciiString GetTransientReference();
118
119   Standard_EXPORT virtual void SetTransientReference(const TCollection_AsciiString& theIOR);
120
121   //! method to detect if a study is empty
122   Standard_EXPORT virtual bool IsEmpty();
123
124   //! method to Find a Component with ComponentDataType = aComponentName
125   Standard_EXPORT virtual Handle(SALOMEDSImpl_SComponent) FindComponent (const TCollection_AsciiString& aComponentName);
126
127   //! method to Find a Component Find a Component from it's ID
128   Standard_EXPORT virtual Handle(SALOMEDSImpl_SComponent) FindComponentID(const TCollection_AsciiString& aComponentID);
129
130   //! method to  Find an Object with SALOMEDSImpl::Name = anObjectName 
131   Standard_EXPORT virtual Handle(SALOMEDSImpl_SObject) FindObject(const TCollection_AsciiString& anObjectName);
132
133
134   //! method to Find Object(s) with SALOMEDSImpl::Name=anObjectName in a component with ComponentDataType = aComponentName
135   Standard_EXPORT virtual Handle(TColStd_HSequenceOfTransient) FindObjectByName( const TCollection_AsciiString& anObjectName, 
136                                                                  const TCollection_AsciiString& aComponentName ) ;
137   
138   //! method to Find an Object with ID = anObjectID 
139   Standard_EXPORT virtual Handle(SALOMEDSImpl_SObject) FindObjectID(const TCollection_AsciiString& anObjectID);
140
141   //! method to Create an Object with ID = anObjectID 
142   Standard_EXPORT virtual Handle(SALOMEDSImpl_SObject) CreateObjectID(const TCollection_AsciiString& anObjectID);
143
144   //! method to Find an Object with ID = anObjectIOR 
145   Standard_EXPORT virtual Handle(SALOMEDSImpl_SObject) FindObjectIOR(const TCollection_AsciiString& anObjectIOR);
146
147   //! method to Find an Object by its path
148   Standard_EXPORT virtual Handle(SALOMEDSImpl_SObject) FindObjectByPath(const TCollection_AsciiString& thePath);
149
150   //! method to get a path of SObject
151   Standard_EXPORT virtual TCollection_AsciiString GetObjectPath(const Handle(SALOMEDSImpl_SObject)& theObject);
152
153   Standard_EXPORT TCollection_AsciiString GetObjectPathByIOR(const TCollection_AsciiString& theIOR);
154
155   //! method to set a context: root ('/') is UserData component
156   Standard_EXPORT virtual bool SetContext(const TCollection_AsciiString& thePath);
157
158   //! method to get a context
159   Standard_EXPORT virtual TCollection_AsciiString GetContext();  
160
161   //! method to get all object names in the given context (or in the current context, if 'theContext' is empty)
162   Standard_EXPORT virtual Handle(TColStd_HSequenceOfAsciiString) GetObjectNames(const TCollection_AsciiString& theContext);
163
164   //! method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
165   Standard_EXPORT virtual Handle(TColStd_HSequenceOfAsciiString) GetDirectoryNames(const TCollection_AsciiString& theContext);
166
167   //! method to get all file names in the given context (or in the current context, if 'theContext' is empty)
168   Standard_EXPORT virtual Handle(TColStd_HSequenceOfAsciiString) GetFileNames(const TCollection_AsciiString& theContext);
169
170   //! method to get all components names
171   Standard_EXPORT virtual Handle(TColStd_HSequenceOfAsciiString) GetComponentNames(const TCollection_AsciiString& theContext);
172
173   //! method to Create a ChildIterator from an SObject 
174   Standard_EXPORT virtual Handle(SALOMEDSImpl_ChildIterator) NewChildIterator(const Handle(SALOMEDSImpl_SObject)& aSO);
175
176   //! method to Create a SComponentIterator 
177   Standard_EXPORT virtual SALOMEDSImpl_SComponentIterator NewComponentIterator();
178
179   //! method to Create a StudyBuilder
180   Standard_EXPORT virtual Handle(SALOMEDSImpl_StudyBuilder) NewBuilder();
181  
182   //! method to get study name
183   Standard_EXPORT virtual TCollection_AsciiString Name();
184
185   //! method to set study name
186   Standard_EXPORT virtual void  Name(const TCollection_AsciiString& name);
187
188   //! method to get if study has been saved
189   Standard_EXPORT virtual bool IsSaved();
190
191   //! method to set if study has been saved
192   Standard_EXPORT virtual void  IsSaved(bool save);
193
194   //! method to Detect if a Study has been modified since it has been saved
195   Standard_EXPORT virtual bool IsModified();
196
197   //! method to get URL of the study (idem GetPersistentReference) 
198   Standard_EXPORT virtual TCollection_AsciiString URL();
199
200   //! method to set URL of the study
201   Standard_EXPORT virtual void  URL(const TCollection_AsciiString& url);
202
203   Standard_EXPORT virtual bool IsLocked();
204
205   Standard_EXPORT virtual int StudyId();
206
207   Standard_EXPORT virtual void  StudyId(int id);
208
209   Standard_EXPORT virtual void UpdateIORLabelMap(const TCollection_AsciiString& anIOR, const TCollection_AsciiString& aLabel);
210   
211   Standard_EXPORT virtual Handle(TColStd_HSequenceOfTransient) FindDependances(const Handle(SALOMEDSImpl_SObject)& anObject);
212
213   Standard_EXPORT virtual Handle(SALOMEDSImpl_AttributeStudyProperties) GetProperties();
214
215   Standard_EXPORT virtual TCollection_AsciiString GetLastModificationDate();
216
217   Standard_EXPORT virtual Handle(TColStd_HSequenceOfAsciiString) GetModificationsDate();
218
219   Standard_EXPORT virtual Handle(SALOMEDSImpl_UseCaseBuilder) GetUseCaseBuilder();
220
221   Standard_EXPORT virtual void Close();
222
223   Standard_EXPORT void EnableUseCaseAutoFilling(bool isEnabled);
224
225   // postponed destroying of object functionality
226   Standard_EXPORT virtual void AddPostponed(const TCollection_AsciiString& theIOR);
227
228   Standard_EXPORT virtual void AddCreatedPostponed(const TCollection_AsciiString& theIOR);
229
230   Standard_EXPORT virtual Handle(TColStd_HSequenceOfAsciiString) RemovePostponed(const int theUndoLimit); 
231                                               // removes postponed IORs of old transaction
232                                               // if theUndoLimit==0, removes all
233   Standard_EXPORT virtual void UndoPostponed(const int theWay); // theWay = 1: resurrect objects,
234                                                 // theWay = -1: get back to the list of postponed
235
236
237   Standard_EXPORT virtual TCollection_AsciiString GetErrorCode() { return _errorCode; }
238   Standard_EXPORT virtual bool IsError() { return _errorCode != ""; }
239
240   Standard_EXPORT virtual Handle(SALOMEDSImpl_SComponent) GetSComponent(const TCollection_AsciiString& theEntry);
241   Standard_EXPORT virtual Handle(SALOMEDSImpl_SComponent) GetSComponent(const TDF_Label& theLabel);
242   Standard_EXPORT virtual Handle(SALOMEDSImpl_SObject) GetSObject(const TCollection_AsciiString& theEntry);
243   Standard_EXPORT virtual Handle(SALOMEDSImpl_SObject) GetSObject(const TDF_Label& theEntryLabel);
244   Standard_EXPORT virtual Handle(TDF_Attribute) GetAttribute(const TCollection_AsciiString& theEntry, 
245                                              const TCollection_AsciiString& theType);
246
247   Standard_EXPORT virtual bool HasCurrentContext() { return !_current.IsNull(); }
248
249   Standard_EXPORT virtual bool DumpStudy(const TCollection_AsciiString& thePath, 
250                                          const TCollection_AsciiString& theBaseName, 
251                                          bool isPublished,
252                                          SALOMEDSImpl_DriverFactory* theFactory);
253
254   Standard_EXPORT static TCollection_AsciiString GetDumpStudyComment(const char* theComponentName = 0);
255
256   Standard_EXPORT virtual Handle(TDocStd_Document) GetDocument() { return _doc; } 
257
258   //The method dump creates a txt file that contain a dump of the study, for debug use
259   Standard_EXPORT void dump(const TCollection_AsciiString& theFileName);
260
261   //This method marks the study as being modified
262   Standard_EXPORT void Modify();
263
264   Standard_EXPORT Handle(SALOMEDSImpl_AttributeParameter) GetCommonParameters(const char* theID, int theSavePoint);
265
266   Standard_EXPORT Handle(SALOMEDSImpl_AttributeParameter) GetModuleParameters(const char* theID, 
267                                                                               const char* theModuleName,
268                                                                               int theSavePoint);
269
270   //Locks the study, theLockerID is identificator of the of the one who locked the study for ex. IOR
271   Standard_EXPORT void SetStudyLock(const char* theLockerID);
272
273   //Returns True if the study is locked
274   Standard_EXPORT bool IsStudyLocked();
275
276   //Unlocks the study
277   Standard_EXPORT void UnLockStudy(const char* theLockerID);
278   
279   //Returns an ID of the study locker
280   Standard_EXPORT Handle(TColStd_HSequenceOfAsciiString) GetLockerID();
281
282   //Returns a callback 
283   Standard_EXPORT Handle(SALOMEDSImpl_Callback) GetCallback() { return _cb; }
284
285
286 public:
287   DEFINE_STANDARD_RTTI( SALOMEDSImpl_Study )
288
289 friend class SALOMEDSImpl_StudyManager;    
290 friend class SALOMEDSImpl_GenericAttribute;
291 };
292 #endif