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