Salome HOME
Fix to bug PAL10465.
[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 #ifndef WNT
47 #include <NCollection_DataMap.hxx>
48 #else
49 #include <NCollection_DataMap1.hxx>
50 #endif
51
52 //SALOMEDSImpl headers
53 #include "SALOMEDSImpl_SComponentIterator.hxx"
54 #include "SALOMEDSImpl_SObject.hxx"
55 #include "SALOMEDSImpl_StudyBuilder.hxx"
56 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
57 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
58 #include "SALOMEDSImpl_AttributeIOR.hxx"
59 #include "SALOMEDSImpl_AttributeParameter.hxx"
60 #include "SALOMEDSImpl_Callback.hxx"
61 #include "SALOMEDSImpl_Driver.hxx" 
62 #include "SALOMEDSImpl_ChildIterator.hxx" 
63
64 class SALOMEDSImpl_StudyManager;
65 class SALOMEDSImpl_GenericAttribute;
66
67 #ifndef WNT
68 typedef NCollection_DataMap <TCollection_AsciiString, Handle_Standard_Transient> DataMapOfAsciiStringTransient;
69 typedef NCollection_DataMap <TCollection_AsciiString, TDF_Label> DataMapAsciiStringLabel;
70 #else
71 typedef NCollection_DataMap1 <TCollection_AsciiString, Handle_Standard_Transient> DataMapOfAsciiStringTransient;
72 typedef NCollection_DataMap1 <TCollection_AsciiString, TDF_Label> DataMapAsciiStringLabel;
73 #endif
74
75 class SALOMEDSImpl_Study : public MMgt_TShared 
76 {
77 private:
78   TCollection_AsciiString              _name;  
79   Handle(TDocStd_Document) _doc;  // OCAF Document
80   bool                     _Saved; // True if the Study is saved
81   TCollection_AsciiString  _URL; //URL of the persistent reference of the study
82   int                      _StudyId; 
83   TDF_Label                _current;
84   bool                     _autoFill; 
85   TCollection_AsciiString  _errorCode;
86   Handle(SALOMEDSImpl_Callback)       _cb;
87   Handle(SALOMEDSImpl_StudyBuilder)   _builder;
88   Handle(SALOMEDSImpl_UseCaseBuilder) _useCaseBuilder;
89
90   DataMapOfAsciiStringTransient _mapOfSO;
91   DataMapOfAsciiStringTransient _mapOfSCO;
92
93   // data structures for postponed destroying of object functionality
94   TColStd_SequenceOfAsciiString myPostponedIORs; // ordered set of IORs
95   TColStd_SequenceOfInteger myNbPostponed; // number of IOR in the each transaction
96   int myNbUndos; // number of current Undos, made by user
97   DataMapAsciiStringLabel myIORLabels;
98  
99
100   Handle(SALOMEDSImpl_SObject)    _FindObject(const Handle(SALOMEDSImpl_SObject)& SO,
101                                               const TCollection_AsciiString& anObjectName,
102                                               bool& _find);
103                                        
104   Handle(SALOMEDSImpl_SObject)   _FindObjectIOR(const Handle(SALOMEDSImpl_SObject)& SO,
105                                                 const TCollection_AsciiString& anObjectIOR,
106                                                 bool& _find);
107
108 public:
109
110   Standard_EXPORT static Handle(SALOMEDSImpl_Study) GetStudy(const TDF_Label& theLabel);
111   Standard_EXPORT static Handle(SALOMEDSImpl_SObject) SObject(const TDF_Label& theLabel);
112   Standard_EXPORT static Handle(SALOMEDSImpl_SComponent) SComponent(const TDF_Label& theLabel);
113   Standard_EXPORT static void IORUpdated(const Handle(SALOMEDSImpl_AttributeIOR)& theAttribute);
114
115   //! standard constructor
116   Standard_EXPORT SALOMEDSImpl_Study(const Handle(TDocStd_Document)&, const TCollection_AsciiString& study_name);
117   
118   //! standard destructor
119   Standard_EXPORT virtual ~SALOMEDSImpl_Study(); 
120   
121   //! method to Get persistent reference of study (idem URL())
122   Standard_EXPORT virtual TCollection_AsciiString GetPersistentReference();
123
124   //! method to Get transient reference of study
125   Standard_EXPORT virtual TCollection_AsciiString GetTransientReference();
126
127   Standard_EXPORT virtual void SetTransientReference(const TCollection_AsciiString& theIOR);
128
129   //! method to detect if a study is empty
130   Standard_EXPORT virtual bool IsEmpty();
131
132   //! method to Find a Component with ComponentDataType = aComponentName
133   Standard_EXPORT virtual Handle(SALOMEDSImpl_SComponent) FindComponent (const TCollection_AsciiString& aComponentName);
134
135   //! method to Find a Component Find a Component from it's ID
136   Standard_EXPORT virtual Handle(SALOMEDSImpl_SComponent) FindComponentID(const TCollection_AsciiString& aComponentID);
137
138   //! method to  Find an Object with SALOMEDSImpl::Name = anObjectName 
139   Standard_EXPORT virtual Handle(SALOMEDSImpl_SObject) FindObject(const TCollection_AsciiString& anObjectName);
140
141
142   //! method to Find Object(s) with SALOMEDSImpl::Name=anObjectName in a component with ComponentDataType = aComponentName
143   Standard_EXPORT virtual Handle(TColStd_HSequenceOfTransient) FindObjectByName( const TCollection_AsciiString& anObjectName, 
144                                                                  const TCollection_AsciiString& aComponentName ) ;
145   
146   //! method to Find an Object with ID = anObjectID 
147   Standard_EXPORT virtual Handle(SALOMEDSImpl_SObject) FindObjectID(const TCollection_AsciiString& anObjectID);
148
149   //! method to Create an Object with ID = anObjectID 
150   Standard_EXPORT virtual Handle(SALOMEDSImpl_SObject) CreateObjectID(const TCollection_AsciiString& anObjectID);
151
152   //! method to Find an Object with ID = anObjectIOR 
153   Standard_EXPORT virtual Handle(SALOMEDSImpl_SObject) FindObjectIOR(const TCollection_AsciiString& anObjectIOR);
154
155   //! method to Find an Object by its path
156   Standard_EXPORT virtual Handle(SALOMEDSImpl_SObject) FindObjectByPath(const TCollection_AsciiString& thePath);
157
158   //! method to get a path of SObject
159   Standard_EXPORT virtual TCollection_AsciiString GetObjectPath(const Handle(SALOMEDSImpl_SObject)& theObject);
160
161   Standard_EXPORT TCollection_AsciiString GetObjectPathByIOR(const TCollection_AsciiString& theIOR);
162
163   //! method to set a context: root ('/') is UserData component
164   Standard_EXPORT virtual bool SetContext(const TCollection_AsciiString& thePath);
165
166   //! method to get a context
167   Standard_EXPORT virtual TCollection_AsciiString GetContext();  
168
169   //! method to get all object names in the given context (or in the current context, if 'theContext' is empty)
170   Standard_EXPORT virtual Handle(TColStd_HSequenceOfAsciiString) GetObjectNames(const TCollection_AsciiString& theContext);
171
172   //! method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
173   Standard_EXPORT virtual Handle(TColStd_HSequenceOfAsciiString) GetDirectoryNames(const TCollection_AsciiString& theContext);
174
175   //! method to get all file names in the given context (or in the current context, if 'theContext' is empty)
176   Standard_EXPORT virtual Handle(TColStd_HSequenceOfAsciiString) GetFileNames(const TCollection_AsciiString& theContext);
177
178   //! method to get all components names
179   Standard_EXPORT virtual Handle(TColStd_HSequenceOfAsciiString) GetComponentNames(const TCollection_AsciiString& theContext);
180
181   //! method to Create a ChildIterator from an SObject 
182   Standard_EXPORT virtual Handle(SALOMEDSImpl_ChildIterator) NewChildIterator(const Handle(SALOMEDSImpl_SObject)& aSO);
183
184   //! method to Create a SComponentIterator 
185   Standard_EXPORT virtual SALOMEDSImpl_SComponentIterator NewComponentIterator();
186
187   //! method to Create a StudyBuilder
188   Standard_EXPORT virtual Handle(SALOMEDSImpl_StudyBuilder) NewBuilder();
189  
190   //! method to get study name
191   Standard_EXPORT virtual TCollection_AsciiString Name();
192
193   //! method to set study name
194   Standard_EXPORT virtual void  Name(const TCollection_AsciiString& name);
195
196   //! method to get if study has been saved
197   Standard_EXPORT virtual bool IsSaved();
198
199   //! method to set if study has been saved
200   Standard_EXPORT virtual void  IsSaved(bool save);
201
202   //! method to Detect if a Study has been modified since it has been saved
203   Standard_EXPORT virtual bool IsModified();
204
205   //! method to get URL of the study (idem GetPersistentReference) 
206   Standard_EXPORT virtual TCollection_AsciiString URL();
207
208   //! method to set URL of the study
209   Standard_EXPORT virtual void  URL(const TCollection_AsciiString& url);
210
211   Standard_EXPORT virtual bool IsLocked();
212
213   Standard_EXPORT virtual int StudyId();
214
215   Standard_EXPORT virtual void  StudyId(int id);
216
217   Standard_EXPORT virtual void UpdateIORLabelMap(const TCollection_AsciiString& anIOR, const TCollection_AsciiString& aLabel);
218   
219   Standard_EXPORT virtual Handle(TColStd_HSequenceOfTransient) FindDependances(const Handle(SALOMEDSImpl_SObject)& anObject);
220
221   Standard_EXPORT virtual Handle(SALOMEDSImpl_AttributeStudyProperties) SALOMEDSImpl_Study::GetProperties();
222
223   Standard_EXPORT virtual TCollection_AsciiString GetLastModificationDate();
224
225   Standard_EXPORT virtual Handle(TColStd_HSequenceOfAsciiString) GetModificationsDate();
226
227   Standard_EXPORT virtual Handle(SALOMEDSImpl_UseCaseBuilder) GetUseCaseBuilder();
228
229   Standard_EXPORT virtual void Close();
230
231   Standard_EXPORT void EnableUseCaseAutoFilling(bool isEnabled) { _errorCode = ""; _autoFill = isEnabled; }
232
233   // postponed destroying of object functionality
234   Standard_EXPORT virtual void AddPostponed(const TCollection_AsciiString& theIOR);
235
236   Standard_EXPORT virtual void AddCreatedPostponed(const TCollection_AsciiString& theIOR);
237
238   Standard_EXPORT virtual Handle(TColStd_HSequenceOfAsciiString) RemovePostponed(const int theUndoLimit); 
239                                               // removes postponed IORs of old transaction
240                                               // if theUndoLimit==0, removes all
241   Standard_EXPORT virtual void UndoPostponed(const int theWay); // theWay = 1: resurrect objects,
242                                                 // theWay = -1: get back to the list of postponed
243
244
245   Standard_EXPORT virtual TCollection_AsciiString GetErrorCode() { return _errorCode; }
246   Standard_EXPORT virtual bool IsError() { return _errorCode != ""; }
247
248   Standard_EXPORT virtual Handle(SALOMEDSImpl_SComponent) GetSComponent(const TCollection_AsciiString& theEntry);
249   Standard_EXPORT virtual Handle(SALOMEDSImpl_SComponent) GetSComponent(const TDF_Label& theLabel);
250   Standard_EXPORT virtual Handle(SALOMEDSImpl_SObject) GetSObject(const TCollection_AsciiString& theEntry);
251   Standard_EXPORT virtual Handle(SALOMEDSImpl_SObject) GetSObject(const TDF_Label& theEntryLabel);
252   Standard_EXPORT virtual Handle(TDF_Attribute) GetAttribute(const TCollection_AsciiString& theEntry, 
253                                              const TCollection_AsciiString& theType);
254
255   Standard_EXPORT virtual bool HasCurrentContext() { return !_current.IsNull(); }
256
257   Standard_EXPORT virtual bool DumpStudy(const TCollection_AsciiString& thePath, 
258                                          const TCollection_AsciiString& theBaseName, 
259                                          bool isPublished,
260                                          SALOMEDSImpl_DriverFactory* theFactory);
261
262   Standard_EXPORT static TCollection_AsciiString GetDumpStudyComment(const char* theComponentName = 0);
263
264   Standard_EXPORT virtual Handle(TDocStd_Document) GetDocument() { return _doc; } 
265
266   //The method dump creates a txt file that contain a dump of the study, for debug use
267   Standard_EXPORT void dump(const TCollection_AsciiString& theFileName);
268
269   //This method marks the study as being modified
270   Standard_EXPORT void Modify();
271
272   Standard_EXPORT Handle(SALOMEDSImpl_AttributeParameter) GetCommonParameters(const char* theID, int theSavePoint);
273
274   Standard_EXPORT Handle(SALOMEDSImpl_AttributeParameter) GetModuleParameters(const char* theID, 
275                                                                               const char* theModuleName,
276                                                                               int theSavePoint);
277
278 public:
279   DEFINE_STANDARD_RTTI( SALOMEDSImpl_Study )
280
281 friend class SALOMEDSImpl_StudyManager;    
282 friend class SALOMEDSImpl_GenericAttribute;
283 };
284 #endif