Salome HOME
Base implementation of Notebook
[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
52 class SALOMEDSImpl_StudyManager;
53 class SALOMEDSImpl_GenericAttribute;
54
55
56 class SALOMEDSIMPL_EXPORT SALOMEDSImpl_Study
57 {
58 private:
59   std::string              _name;  
60   DF_Document*             _doc;  // Document
61   bool                     _Saved; // True if the Study is saved
62   std::string              _URL; //URL of the persistent reference of the study
63   int                      _StudyId; 
64   DF_Label                 _current;
65   bool                     _autoFill; 
66   std::string              _errorCode;
67   std::vector<std::string> _lockers;
68   SALOMEDSImpl_Callback*   _cb;
69   SALOMEDSImpl_StudyBuilder*   _builder;
70   SALOMEDSImpl_UseCaseBuilder* _useCaseBuilder;
71
72   std::map<std::string, SALOMEDSImpl_SObject> _mapOfSO;
73   std::map<std::string, SALOMEDSImpl_SComponent> _mapOfSCO;
74   std::map<std::string, DF_Label> myIORLabels;
75
76   SALOMEDSImpl_SObject   _FindObject(const SALOMEDSImpl_SObject& SO,
77     const std::string& anObjectName,
78     bool& _find);
79
80   SALOMEDSImpl_SObject   _FindObjectIOR(const SALOMEDSImpl_SObject& SO,
81     const std::string& anObjectIOR,
82     bool& _find);
83
84 public:
85
86   static SALOMEDSImpl_Study* GetStudy(const DF_Label& theLabel);
87   static SALOMEDSImpl_SObject SObject(const DF_Label& theLabel);
88   static SALOMEDSImpl_SComponent SComponent(const DF_Label& theLabel);
89   static void IORUpdated(const SALOMEDSImpl_AttributeIOR* theAttribute);
90
91    //! standard constructor
92    SALOMEDSImpl_Study(const DF_Document*, const std::string& study_name);
93   
94   //! standard destructor
95   virtual ~SALOMEDSImpl_Study(); 
96   
97   //! method to Get persistent reference of study (idem URL())
98   virtual std::string GetPersistentReference();
99
100   //! method to Get transient reference of study
101   virtual std::string GetTransientReference();
102
103   virtual void SetTransientReference(const std::string& theIOR);
104
105   //! method to detect if a study is empty
106   virtual bool IsEmpty();
107
108   //! method to Find a Component with ComponentDataType = aComponentName
109   virtual SALOMEDSImpl_SComponent FindComponent (const std::string& aComponentName);
110
111   //! method to Find a Component Find a Component from it's ID
112   virtual SALOMEDSImpl_SComponent FindComponentID(const std::string& aComponentID);
113
114   //! method to  Find an Object with SALOMEDSImpl::Name = anObjectName 
115   virtual SALOMEDSImpl_SObject FindObject(const std::string& anObjectName);
116
117
118   //! method to Find Object(s) with SALOMEDSImpl::Name=anObjectName in a component with ComponentDataType = aComponentName
119   virtual std::vector<SALOMEDSImpl_SObject> FindObjectByName( const std::string& anObjectName, 
120                                                                        const std::string& aComponentName ) ;
121   
122   //! method to Find an Object with ID = anObjectID 
123   virtual SALOMEDSImpl_SObject FindObjectID(const std::string& anObjectID);
124   
125   //! method to Create an Object with ID = anObjectID 
126   virtual SALOMEDSImpl_SObject CreateObjectID(const std::string& anObjectID);
127
128   //! method to Find an Object with ID = anObjectIOR 
129   virtual SALOMEDSImpl_SObject FindObjectIOR(const std::string& anObjectIOR);
130
131   //! method to Find an Object by its path
132   virtual SALOMEDSImpl_SObject FindObjectByPath(const std::string& thePath);
133
134   //! method to get a path of SObject
135   virtual std::string GetObjectPath(const SALOMEDSImpl_SObject& theObject);
136
137   std::string GetObjectPathByIOR(const std::string& theIOR);
138
139   //! method to set a context: root ('/') is UserData component
140   virtual bool SetContext(const std::string& thePath);
141
142   //! method to get a context
143   virtual std::string GetContext();  
144
145   //! method to get all object names in the given context (or in the current context, if 'theContext' is empty)
146   virtual std::vector<std::string> GetObjectNames(const std::string& theContext);
147
148   //! method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
149   virtual std::vector<std::string> GetDirectoryNames(const std::string& theContext);
150
151   //! method to get all file names in the given context (or in the current context, if 'theContext' is empty)
152   virtual std::vector<std::string> GetFileNames(const std::string& theContext);
153
154   //! method to get all components names
155   virtual std::vector<std::string> GetComponentNames(const std::string& theContext);
156
157   //! method to Create a ChildIterator from an SObject 
158   virtual SALOMEDSImpl_ChildIterator NewChildIterator(const SALOMEDSImpl_SObject& aSO);
159
160   //! method to Create a SComponentIterator 
161   virtual SALOMEDSImpl_SComponentIterator NewComponentIterator();
162
163   //! method to Create a StudyBuilder
164   virtual SALOMEDSImpl_StudyBuilder* NewBuilder();
165  
166   //! method to get study name
167   virtual std::string Name();
168
169   //! method to set study name
170   virtual void  Name(const std::string& name);
171   
172   //! method to get if study has been saved
173   virtual bool IsSaved();
174
175   //! method to set if study has been saved
176   virtual void  IsSaved(bool save);
177
178   //! method to Detect if a Study has been modified since it has been saved
179   virtual bool IsModified();
180   
181   //! method to get URL of the study (idem GetPersistentReference) 
182   virtual std::string URL();
183
184   //! method to set URL of the study
185   virtual void  URL(const std::string& url);
186
187   virtual bool IsLocked();
188   
189   virtual int StudyId();
190
191   virtual void  StudyId(int id);
192   
193   virtual void DeleteIORLabelMapItem(const std::string& anIOR);
194   virtual void UpdateIORLabelMap(const std::string& anIOR, const std::string& aLabel);
195   
196   virtual std::vector<SALOMEDSImpl_SObject> FindDependances(const SALOMEDSImpl_SObject& anObject);
197   
198   virtual SALOMEDSImpl_AttributeStudyProperties* GetProperties();
199   
200   virtual std::string GetLastModificationDate();
201   
202   virtual std::vector<std::string> GetModificationsDate();
203   
204   virtual SALOMEDSImpl_UseCaseBuilder* GetUseCaseBuilder();
205   
206   virtual void Close();
207   
208   void EnableUseCaseAutoFilling(bool isEnabled);
209   
210   virtual std::string GetErrorCode() { return _errorCode; }
211   virtual bool IsError() { return _errorCode != ""; }
212   
213   virtual SALOMEDSImpl_SComponent GetSComponent(const std::string& theEntry);
214   virtual SALOMEDSImpl_SComponent GetSComponent(const DF_Label& theLabel);
215   virtual SALOMEDSImpl_SObject GetSObject(const std::string& theEntry);
216   virtual SALOMEDSImpl_SObject GetSObject(const DF_Label& theEntryLabel);
217   virtual DF_Attribute* GetAttribute(const std::string& theEntry, 
218                                                      const std::string& theType);
219
220   virtual bool HasCurrentContext() { return !_current.IsNull(); }
221
222   virtual bool DumpStudy(const std::string& thePath, 
223                                          const std::string& theBaseName, 
224                                          bool isPublished,
225                                          SALOMEDSImpl_DriverFactory* theFactory);
226
227   static std::string GetDumpStudyComment(const char* theComponentName = 0);
228   
229   virtual DF_Document* GetDocument() { return _doc; } 
230
231   //The method dump creates a txt file that contain a dump of the study, for debug use
232   void dump(const std::string& theFileName);
233
234   //This method marks the study as being modified
235   void Modify();
236
237   SALOMEDSImpl_AttributeParameter* GetCommonParameters(const char* theID, int theSavePoint);
238
239   SALOMEDSImpl_AttributeParameter* GetModuleParameters(const char* theID, 
240                                                                               const char* theModuleName,
241                                                                               int theSavePoint);
242
243   //Locks the study, theLockerID is identificator of the of the one who locked the study for ex. IOR
244   void SetStudyLock(const char* theLockerID);
245
246   //Returns True if the study is locked
247   bool IsStudyLocked();
248
249   //Unlocks the study
250   void UnLockStudy(const char* theLockerID);
251   
252   //Returns an ID of the study locker
253   std::vector<std::string> GetLockerID();
254
255   //Returns a callback 
256   SALOMEDSImpl_Callback* GetCallback() { return _cb; }
257
258   //Returns a list of IOR's stored in the study
259   std::vector<std::string> GetIORs();
260
261   friend class SALOMEDSImpl_StudyManager;    
262   friend class SALOMEDSImpl_GenericAttribute;
263 };
264 #endif