1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SALOMEDSImpl_Study.hxx
24 // Author : Sergey RUIN
27 #ifndef __SALOMEDSIMPL_STUDY_I_H__
28 #define __SALOMEDSIMPL_STUDY_I_H__
36 #include "DF_Document.hxx"
37 #include "DF_Label.hxx"
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"
54 class SALOMEDSImpl_StudyManager;
55 class SALOMEDSImpl_GenericAttribute;
58 class SALOMEDSIMPL_EXPORT SALOMEDSImpl_Study
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
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;
75 std::map<std::string, SALOMEDSImpl_SObject> _mapOfSO;
76 std::map<std::string, SALOMEDSImpl_SComponent> _mapOfSCO;
77 std::map<std::string, DF_Label> myIORLabels;
78 std::vector<SALOMEDSImpl_GenericVariable*> myNoteBookVars;
80 SALOMEDSImpl_SObject _FindObject(const SALOMEDSImpl_SObject& SO,
81 const std::string& anObjectName,
84 SALOMEDSImpl_SObject _FindObjectIOR(const SALOMEDSImpl_SObject& SO,
85 const std::string& anObjectIOR,
88 std::string _GetStudyVariablesScript();
89 std::string _GetNoteBookAccessor();
90 std::string _GetNoteBookAccess();
94 static SALOMEDSImpl_Study* GetStudy(const DF_Label& theLabel);
95 static SALOMEDSImpl_SObject SObject(const DF_Label& theLabel);
96 static SALOMEDSImpl_SComponent SComponent(const DF_Label& theLabel);
97 static void IORUpdated(const SALOMEDSImpl_AttributeIOR* theAttribute);
99 //! standard constructor
100 SALOMEDSImpl_Study(const DF_Document*, const std::string& study_name);
102 //! standard destructor
103 virtual ~SALOMEDSImpl_Study();
105 //! method to Get persistent reference of study (idem URL())
106 virtual std::string GetPersistentReference();
108 //! method to Get transient reference of study
109 virtual std::string GetTransientReference();
111 virtual void SetTransientReference(const std::string& theIOR);
113 //! method to detect if a study is empty
114 virtual bool IsEmpty();
116 //! method to Find a Component with ComponentDataType = aComponentName
117 virtual SALOMEDSImpl_SComponent FindComponent (const std::string& aComponentName);
119 //! method to Find a Component Find a Component from it's ID
120 virtual SALOMEDSImpl_SComponent FindComponentID(const std::string& aComponentID);
122 //! method to Find an Object with SALOMEDSImpl::Name = anObjectName
123 virtual SALOMEDSImpl_SObject FindObject(const std::string& anObjectName);
126 //! method to Find Object(s) with SALOMEDSImpl::Name=anObjectName in a component with ComponentDataType = aComponentName
127 virtual std::vector<SALOMEDSImpl_SObject> FindObjectByName( const std::string& anObjectName,
128 const std::string& aComponentName ) ;
130 //! method to Find an Object with ID = anObjectID
131 virtual SALOMEDSImpl_SObject FindObjectID(const std::string& anObjectID);
133 //! method to Create an Object with ID = anObjectID
134 virtual SALOMEDSImpl_SObject CreateObjectID(const std::string& anObjectID);
136 //! method to Find an Object with ID = anObjectIOR
137 virtual SALOMEDSImpl_SObject FindObjectIOR(const std::string& anObjectIOR);
139 //! method to Find an Object by its path
140 virtual SALOMEDSImpl_SObject FindObjectByPath(const std::string& thePath);
142 //! method to get a path of SObject
143 virtual std::string GetObjectPath(const SALOMEDSImpl_SObject& theObject);
145 std::string GetObjectPathByIOR(const std::string& theIOR);
147 //! method to set a context: root ('/') is UserData component
148 virtual bool SetContext(const std::string& thePath);
150 //! method to get a context
151 virtual std::string GetContext();
153 //! method to get all object names in the given context (or in the current context, if 'theContext' is empty)
154 virtual std::vector<std::string> GetObjectNames(const std::string& theContext);
156 //! method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
157 virtual std::vector<std::string> GetDirectoryNames(const std::string& theContext);
159 //! method to get all file names in the given context (or in the current context, if 'theContext' is empty)
160 virtual std::vector<std::string> GetFileNames(const std::string& theContext);
162 //! method to get all components names
163 virtual std::vector<std::string> GetComponentNames(const std::string& theContext);
165 //! method to Create a ChildIterator from an SObject
166 virtual SALOMEDSImpl_ChildIterator NewChildIterator(const SALOMEDSImpl_SObject& aSO);
168 //! method to Create a SComponentIterator
169 virtual SALOMEDSImpl_SComponentIterator NewComponentIterator();
171 //! method to Create a StudyBuilder
172 virtual SALOMEDSImpl_StudyBuilder* NewBuilder();
174 //! method to get study name
175 virtual std::string Name();
177 //! method to set study name
178 virtual void Name(const std::string& name);
180 //! method to get if study has been saved
181 virtual bool IsSaved();
183 //! method to set if study has been saved
184 virtual void IsSaved(bool save);
186 //! method to Detect if a Study has been modified since it has been saved
187 virtual bool IsModified();
189 //! method to get URL of the study (idem GetPersistentReference)
190 virtual std::string URL();
192 //! method to set URL of the study
193 virtual void URL(const std::string& url);
195 virtual bool IsLocked();
197 virtual int StudyId();
199 virtual void StudyId(int id);
201 virtual void DeleteIORLabelMapItem(const std::string& anIOR);
202 virtual void UpdateIORLabelMap(const std::string& anIOR, const std::string& aLabel);
204 virtual std::vector<SALOMEDSImpl_SObject> FindDependances(const SALOMEDSImpl_SObject& anObject);
206 virtual SALOMEDSImpl_AttributeStudyProperties* GetProperties();
208 virtual std::string GetLastModificationDate();
210 virtual std::vector<std::string> GetModificationsDate();
212 virtual SALOMEDSImpl_UseCaseBuilder* GetUseCaseBuilder();
214 virtual void Close();
216 void EnableUseCaseAutoFilling(bool isEnabled);
218 virtual std::string GetErrorCode() { return _errorCode; }
219 virtual bool IsError() { return _errorCode != ""; }
221 virtual SALOMEDSImpl_SComponent GetSComponent(const std::string& theEntry);
222 virtual SALOMEDSImpl_SComponent GetSComponent(const DF_Label& theLabel);
223 virtual SALOMEDSImpl_SObject GetSObject(const std::string& theEntry);
224 virtual SALOMEDSImpl_SObject GetSObject(const DF_Label& theEntryLabel);
225 virtual DF_Attribute* GetAttribute(const std::string& theEntry,
226 const std::string& theType);
228 virtual bool HasCurrentContext() { return !_current.IsNull(); }
230 virtual bool DumpStudy(const std::string& thePath,
231 const std::string& theBaseName,
234 SALOMEDSImpl_DriverFactory* theFactory);
236 static std::string GetDumpStudyComment(const char* theComponentName = 0);
238 virtual DF_Document* GetDocument() { return _doc; }
240 //The method dump creates a txt file that contain a dump of the study, for debug use
241 void dump(const std::string& theFileName);
243 //This method marks the study as being modified
246 SALOMEDSImpl_AttributeParameter* GetCommonParameters(const char* theID, int theSavePoint);
248 SALOMEDSImpl_AttributeParameter* GetModuleParameters(const char* theID,
249 const char* theModuleName,
252 //Locks the study, theLockerID is identificator of the of the one who locked the study for ex. IOR
253 void SetStudyLock(const char* theLockerID);
255 //Returns True if the study is locked
256 bool IsStudyLocked();
259 void UnLockStudy(const char* theLockerID);
261 //Returns an ID of the study locker
262 std::vector<std::string> GetLockerID();
264 //Managing of variables
265 void SetVariable(const std::string& theVarName,
266 const double theValue,
267 const SALOMEDSImpl_GenericVariable::VariableTypes);
269 void SetStringVariable(const std::string& theVarName,
270 const std::string& theValue,
271 const SALOMEDSImpl_GenericVariable::VariableTypes);
273 void SetStringVariableAsDouble(const std::string& theVarName,
274 const double theValue,
275 const SALOMEDSImpl_GenericVariable::VariableTypes);
277 double GetVariableValue(const std::string& theVarName);
279 std::string GetStringVariableValue(const std::string& theVarName);
281 bool IsTypeOf(const std::string& theVarName,
282 SALOMEDSImpl_GenericVariable::VariableTypes theType) const;
284 bool IsVariable(const std::string& theVarName) const;
287 std::vector<std::string> GetVariableNames() const;
289 void AddVariable(SALOMEDSImpl_GenericVariable* theVariable);
291 SALOMEDSImpl_GenericVariable* GetVariable(const std::string& theName) const;
293 bool RemoveVariable(const std::string& theVarName);
295 bool RenameVariable(const std::string& theVarName, const std::string& theNewVarName);
297 bool IsVariableUsed(const std::string& theVarName);
299 bool FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
300 SALOMEDSImpl_SObject theSObject,
301 const std::string& theName);
302 bool FindVariableAttribute(const std::string& theName);
304 void ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
305 SALOMEDSImpl_SObject theSObject,
306 const std::string& theSource,
307 const std::string& theDest);
308 void ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest);
310 std::vector< std::vector<std::string> > ParseVariables(const std::string& theVariables) const;
313 SALOMEDSImpl_Callback* GetCallback() { return _cb; }
315 //Returns a list of IOR's stored in the study
316 std::vector<std::string> GetIORs();
318 // Notification mechanism
319 virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject);
320 virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject);
321 virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason);
322 virtual void setNotifier(SALOMEDSImpl_AbstractCallback* notifier);
325 friend class SALOMEDSImpl_StudyManager;
326 friend class SALOMEDSImpl_GenericAttribute;
327 friend class SALOMEDSImpl_GenericVariable;