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