]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx
Salome HOME
Merge 'master' branch into 'V9_dev' branch
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_Study.hxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 HDFgroup;
55 class SALOMEDSImpl_GenericAttribute;
56
57
58 class SALOMEDSIMPL_EXPORT SALOMEDSImpl_Study
59 {
60 private:
61   std::string              _name;  
62   DF_Application*          _appli;
63   DF_Document*             _doc;  // Document
64   DF_Document*             _clipboard;
65   bool                     _Saved; // True if the Study is saved
66   std::string              _URL; //URL of the persistent reference of the study
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   SALOMEDSImpl_AbstractCallback* _notifier;
74   SALOMEDSImpl_AbstractCallback* _genObjRegister;
75
76   std::map<std::string, SALOMEDSImpl_SObject> _mapOfSO;
77   std::map<std::string, SALOMEDSImpl_SComponent> _mapOfSCO;
78   std::map<std::string, DF_Label> myIORLabels;
79   std::vector<SALOMEDSImpl_GenericVariable*> myNoteBookVars;
80
81   SALOMEDSImpl_SObject   _FindObject(const SALOMEDSImpl_SObject& SO,
82     const std::string& anObjectName,
83     bool& _find);
84
85   SALOMEDSImpl_SObject   _FindObjectIOR(const SALOMEDSImpl_SObject& SO,
86     const std::string& anObjectIOR,
87     bool& _find);
88
89   std::string _GetStudyVariablesScript();
90   std::string _GetNoteBookAccessor();
91   std::string _GetNoteBookAccess();
92
93 public:
94
95   static SALOMEDSImpl_Study* GetStudyImpl(const DF_Label& theLabel);
96   static SALOMEDSImpl_SObject SObject(const DF_Label& theLabel);
97   static SALOMEDSImpl_SComponent SComponent(const DF_Label& theLabel);
98   static void IORUpdated(const SALOMEDSImpl_AttributeIOR* theAttribute);
99
100    //! standard constructor
101    SALOMEDSImpl_Study();
102   
103   //! standard destructor
104   virtual ~SALOMEDSImpl_Study(); 
105   
106   virtual void Init();
107   virtual void Clear();
108
109   //! method to Open a Study from it's persistent reference
110   virtual bool Open(const std::string& aStudyUrl);
111
112   //! method to save a Study
113   virtual bool Save(SALOMEDSImpl_DriverFactory* aFactory,
114                     bool theMultiFile,
115                     bool theASCII);
116
117   //! method to save a Study to the persistent reference aUrl
118   virtual bool SaveAs(const std::string& aUrl,
119                       SALOMEDSImpl_DriverFactory* aFactory,
120                       bool theMultiFile,
121                       bool theASCII);
122
123   bool CopyLabel(SALOMEDSImpl_Driver* theEngine,
124                  const int theSourceStartDepth,
125                  const DF_Label& theSource,
126                  const DF_Label& theDestinationMain);
127
128   DF_Label PasteLabel(SALOMEDSImpl_Driver* theEngine,
129                       const DF_Label& theSource,
130                       const DF_Label& theDestinationStart,
131                       const bool isFirstElement);
132
133   virtual bool CanCopy(const SALOMEDSImpl_SObject& theObject, SALOMEDSImpl_Driver* Engine);
134   virtual bool Copy(const SALOMEDSImpl_SObject& theObject, SALOMEDSImpl_Driver* Engine);
135   virtual bool CanPaste(const SALOMEDSImpl_SObject& theObject, SALOMEDSImpl_Driver* Engine);
136   virtual SALOMEDSImpl_SObject Paste(const SALOMEDSImpl_SObject& theObject, SALOMEDSImpl_Driver* Engine);
137
138   // _SaveAs private function called by Save and SaveAs
139   virtual bool Impl_SaveAs(const std::string& aUrl,
140                            SALOMEDSImpl_DriverFactory* aFactory,
141                            bool theMultiFile,
142                            bool theASCII);
143
144   // _SaveObject private function called by _SaveAs
145   virtual bool Impl_SaveObject(const SALOMEDSImpl_SObject& SC, HDFgroup *hdf_group_datatype);
146
147   virtual bool Impl_SaveProperties(HDFgroup *hdf_group);
148
149
150   //! method to Get persistent reference of study (idem URL())
151   virtual std::string GetPersistentReference();
152
153   //! method to detect if a study is empty
154   virtual bool IsEmpty();
155
156   //! method to Find a Component with ComponentDataType = aComponentName
157   virtual SALOMEDSImpl_SComponent FindComponent (const std::string& aComponentName);
158
159   //! method to Find a Component Find a Component from it's ID
160   virtual SALOMEDSImpl_SComponent FindComponentID(const std::string& aComponentID);
161
162   //! method to  Find an Object with SALOMEDSImpl::Name = anObjectName 
163   virtual SALOMEDSImpl_SObject FindObject(const std::string& anObjectName);
164
165
166   //! method to Find Object(s) with SALOMEDSImpl::Name=anObjectName in a component with ComponentDataType = aComponentName
167   virtual std::vector<SALOMEDSImpl_SObject> FindObjectByName( const std::string& anObjectName, 
168                                                                        const std::string& aComponentName ) ;
169   
170   //! method to Find an Object with ID = anObjectID 
171   virtual SALOMEDSImpl_SObject FindObjectID(const std::string& anObjectID);
172   
173   //! method to Create an Object with ID = anObjectID 
174   virtual SALOMEDSImpl_SObject CreateObjectID(const std::string& anObjectID);
175
176   //! method to Find an Object with ID = anObjectIOR 
177   virtual SALOMEDSImpl_SObject FindObjectIOR(const std::string& anObjectIOR);
178
179   //! method to Find an Object by its path
180   virtual SALOMEDSImpl_SObject FindObjectByPath(const std::string& thePath);
181
182   //! method to get a path of SObject
183   virtual std::string GetObjectPath(const SALOMEDSImpl_SObject& theObject);
184
185   std::string GetObjectPathByIOR(const std::string& theIOR);
186
187   //! method to Create a ChildIterator from an SObject 
188   virtual SALOMEDSImpl_ChildIterator NewChildIterator(const SALOMEDSImpl_SObject& aSO);
189
190   //! method to Create a SComponentIterator 
191   virtual SALOMEDSImpl_SComponentIterator NewComponentIterator();
192
193   //! method to Create a StudyBuilder
194   virtual SALOMEDSImpl_StudyBuilder* NewBuilder();
195  
196   //! method to get study name
197   virtual std::string Name();
198
199   //! method to set study name
200   virtual void  Name(const std::string& name);
201   
202   //! method to get if study has been saved
203   virtual bool IsSaved();
204
205   //! method to set if study has been saved
206   virtual void  IsSaved(bool save);
207
208   //! method to Detect if a Study has been modified since it has been saved
209   virtual bool IsModified();
210   
211   //! method to get URL of the study (idem GetPersistentReference) 
212   virtual std::string URL();
213
214   //! method to set URL of the study
215   virtual void  URL(const std::string& url);
216
217   virtual bool IsLocked();
218   
219   virtual void DeleteIORLabelMapItem(const std::string& anIOR);
220   virtual void UpdateIORLabelMap(const std::string& anIOR, const std::string& aLabel);
221   
222   virtual std::vector<SALOMEDSImpl_SObject> FindDependances(const SALOMEDSImpl_SObject& anObject);
223   
224   virtual SALOMEDSImpl_AttributeStudyProperties* GetProperties();
225   
226   virtual std::string GetLastModificationDate();
227   
228   virtual std::vector<std::string> GetModificationsDate();
229   
230   virtual SALOMEDSImpl_UseCaseBuilder* GetUseCaseBuilder();
231   
232   void EnableUseCaseAutoFilling(bool isEnabled);
233   
234   virtual std::string GetErrorCode() { return _errorCode; }
235   virtual bool IsError() { return _errorCode != ""; }
236   
237   virtual SALOMEDSImpl_SComponent GetSComponent(const std::string& theEntry);
238   virtual SALOMEDSImpl_SComponent GetSComponent(const DF_Label& theLabel);
239   virtual SALOMEDSImpl_SObject GetSObject(const std::string& theEntry);
240   virtual SALOMEDSImpl_SObject GetSObject(const DF_Label& theEntryLabel);
241   virtual DF_Attribute* GetAttribute(const std::string& theEntry, 
242                                                      const std::string& theType);
243
244   virtual bool DumpStudy(const std::string& thePath, 
245                          const std::string& theBaseName, 
246                          bool isPublished,
247                          bool isMultiFile,
248                          SALOMEDSImpl_DriverFactory* theFactory);
249
250   static std::string GetDumpStudyComment(const char* theComponentName = 0);
251   
252   virtual DF_Document* GetDocument() { return _doc; } 
253
254   //The method dump creates a txt file that contain a dump of the study, for debug use
255   void dump(const std::string& theFileName);
256
257   //This method marks the study as being modified
258   void Modify();
259
260   SALOMEDSImpl_AttributeParameter* GetCommonParameters(const char* theID, int theSavePoint);
261
262   SALOMEDSImpl_AttributeParameter* GetModuleParameters(const char* theID, 
263                                                                               const char* theModuleName,
264                                                                               int theSavePoint);
265
266   //Locks the study, theLockerID is identificator of the of the one who locked the study for ex. IOR
267   void SetStudyLock(const char* theLockerID);
268
269   //Returns True if the study is locked
270   bool IsStudyLocked();
271
272   //Unlocks the study
273   void UnLockStudy(const char* theLockerID);
274   
275   //Returns an ID of the study locker
276   std::vector<std::string> GetLockerID();
277
278   //Managing of variables
279   void SetVariable(const std::string& theVarName,
280                    const double theValue, 
281                    const SALOMEDSImpl_GenericVariable::VariableTypes);
282
283   void SetStringVariable(const std::string& theVarName,
284                          const std::string& theValue, 
285                          const SALOMEDSImpl_GenericVariable::VariableTypes);
286
287   void SetStringVariableAsDouble(const std::string& theVarName,
288                                  const double theValue, 
289                                  const SALOMEDSImpl_GenericVariable::VariableTypes);
290   
291   double GetVariableValue(const std::string& theVarName);
292
293   std::string GetStringVariableValue(const std::string& theVarName);
294
295   bool IsTypeOf(const std::string& theVarName,
296                 SALOMEDSImpl_GenericVariable::VariableTypes theType) const;
297         
298   bool IsVariable(const std::string& theVarName) const;
299
300
301   std::vector<std::string> GetVariableNames() const;
302
303   void AddVariable(SALOMEDSImpl_GenericVariable* theVariable);
304
305   SALOMEDSImpl_GenericVariable* GetVariable(const std::string& theName) const;
306
307   bool RemoveVariable(const std::string& theVarName);
308
309   bool RenameVariable(const std::string& theVarName, const std::string& theNewVarName);
310
311   bool IsVariableUsed(const std::string& theVarName);
312
313   bool FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
314                              SALOMEDSImpl_SObject theSObject,
315                              const std::string& theName);
316   bool FindVariableAttribute(const std::string& theName);
317
318   void ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
319                                 SALOMEDSImpl_SObject theSObject,
320                                 const std::string& theSource,
321                                 const std::string& theDest);
322   void ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest);
323
324   std::vector< std::vector<std::string> > ParseVariables(const std::string& theVariables) const;
325
326   //Returns a callback 
327   SALOMEDSImpl_Callback* GetCallback() { return _cb; }
328
329   //Returns a list of IOR's stored in the study
330   std::vector<std::string> GetIORs();
331
332   // Notification mechanism
333   virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject);
334   virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject);
335   virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason);
336   virtual void setNotifier(SALOMEDSImpl_AbstractCallback* notifier);
337
338   static void RegisterGenObj  (const std::string& theIOR, DF_Label label);
339   static void UnRegisterGenObj(const std::string& theIOR, DF_Label label);
340   void setGenObjRegister(SALOMEDSImpl_AbstractCallback* theRegister);
341
342   friend class SALOMEDSImpl_GenericAttribute;
343   friend class SALOMEDSImpl_GenericVariable;
344 };
345 #endif