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