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