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