Salome HOME
Fix on [Bug PAL7750] Regression of UNDO in GEOM
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Study_i.hxx
1 //  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOMEDS_Study_i.hxx
25 //  Author : Yves FRICAUD
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef __SALOMEDS_STUDY_I_H__
30 #define __SALOMEDS_STUDY_I_H__
31
32 // std C++ headers
33 #include <map>
34 #include <string>
35
36 // IDL headers
37 #include <SALOMEconfig.h>
38 #include CORBA_SERVER_HEADER(SALOMEDS)
39
40 // Cascade headers
41 #include <TDF_Tool.hxx>
42 #include <TDF_Data.hxx>
43 #include <TDF_Label.hxx>
44 #include <TDocStd_Document.hxx>
45 #include <TColStd_SequenceOfInteger.hxx>
46 #include <TColStd_SequenceOfAsciiString.hxx>
47
48 //SALOMEDS headers
49 #include "SALOMEDS_DataMapStringLabel.hxx"
50 #include "SALOMEDS_IORAttribute.hxx"
51
52 #include "SALOMEDS_SComponentIterator_i.hxx"
53 #include "SALOMEDS_ChildIterator_i.hxx"
54
55 class SALOMEDS_StudyManager_i;
56 class SALOMEDS_UseCaseBuilder_i;
57 class SALOMEDS_StudyBuilder_i;
58 class SALOMEDS_SObject_i;
59
60
61 bool operator<(const TDF_Label& theLeft, const TDF_Label& theRight);
62
63
64 class SALOMEDS_Study_i: public virtual POA_SALOMEDS::Study,
65                         public virtual PortableServer::RefCountServantBase 
66 {
67 public:
68   typedef TDF_Label TSObjectID;
69   typedef std::pair<SALOMEDS_SObject_i*,SALOMEDS::SObject_var> TSObjectHolder;
70   typedef std::map<TSObjectID,TSObjectHolder> TSObjectMap;
71
72   SALOMEDS_Study_i(SALOMEDS_StudyManager_i* theStudyManager,
73                    const Handle(TDocStd_Document)& theDoc,
74                    const char* theStudyName);
75   
76   virtual ~SALOMEDS_Study_i(); 
77   
78
79   SALOMEDS_StudyManager_i* GetStudyManager(){ return _StudyManager; }
80
81   Handle(TDocStd_Document) GetDocument(){ return _doc; }
82
83   TSObjectMap& GetSObjectMap(){ return mySObjectMap;}
84
85   CORBA::ORB_var GetORB() const;
86
87   PortableServer::POA_var GetPOA() const;
88
89   SALOMEDS_SObject_i* DownCast(SALOMEDS::SObject_ptr theSObject) const;
90
91   SALOMEDS::Callback_ptr SetOnAddSObject(SALOMEDS::Callback_ptr theCallback);
92
93   SALOMEDS::Callback_ptr SetOnRemoveSObject(SALOMEDS::Callback_ptr theCallback);
94
95   void OnAddSObject(SALOMEDS::SObject_ptr theObject);
96
97   void OnRemoveSObject(SALOMEDS::SObject_ptr theObject);
98
99   void CheckLocked();
100
101
102   virtual char* ConvertObjectToIOR(CORBA::Object_ptr theObject);
103
104   virtual CORBA::Object_ptr ConvertIORToObject(const char* theIOR);
105
106   //! method to Get persistent reference of study (idem URL())
107   /*!
108     \sa URL()
109     \return char* arguments, the persistent reference of the study
110   */  
111   virtual char* GetPersistentReference();
112
113
114   //! method to Get transient reference of study
115   /*!
116     \return char* arguments, the transient reference of the study
117   */  
118   virtual char* GetTransientReference();
119
120   //! method to detect if a study is empty
121   /*!
122     \return bool arguments, true if study is empty
123   */  
124   virtual CORBA::Boolean IsEmpty();
125
126   //! method to Find a Component with ComponentDataType = aComponentName
127   /*!
128     \param aComponentName char* arguments
129     \return SComponent_ptr arguments, the component found
130   */  
131   virtual SALOMEDS::SComponent_ptr FindComponent (const char* aComponentName);
132
133   //! method to Find a Component Find a Component from it's ID
134   /*!
135     \param aComponentID char* arguments
136     \return SComponent_ptr arguments, the component found
137   */  
138   virtual SALOMEDS::SComponent_ptr FindComponentID(const char* aComponentID);
139
140   //! method to  Find an Object with SALOMEDS::Name = anObjectName 
141   /*!
142     \param anObjectName char* arguments
143     \return SObject_ptr arguments, the object found
144   */  
145   virtual SALOMEDS::SObject_ptr FindObject(const char* anObjectName);
146
147
148   //! method to Find Object(s) with SALOMEDS::Name = anObjectName in a component with ComponentDataType = aComponentName
149   /*!
150     \param anObjectName char* arguments
151     \param aComponentName char* arguments
152     \return ListOfSObject_ptr arguments, a list of objects found
153   */  
154   
155   virtual SALOMEDS::Study::ListOfSObject* FindObjectByName( const char* anObjectName, const char* aComponentName ) ;
156   
157   //! method to Find an Object with ID = anObjectID 
158   /*!
159     \param anObjectID char* arguments
160     \return SObject_ptr arguments, the object found
161   */  
162   virtual SALOMEDS::SObject_ptr FindObjectID(const char* anObjectID);
163
164   //! method to Create an Object with ID = anObjectID 
165   /*!
166     \param anObjectID char* arguments
167     \return SObject_ptr arguments, the object found
168   */  
169   virtual SALOMEDS::SObject_ptr CreateObjectID(const char* anObjectID);
170
171   //! method to Find an Object with ID = anObjectIOR 
172   /*!
173     \param anObjectIOR char* arguments
174     \return SObject_ptr arguments, the object found
175   */  
176   virtual SALOMEDS::SObject_ptr FindObjectIOR(const char* anObjectIOR);
177
178   //! method to Find an Object by its path
179   /*!
180     \param thePath char* arguments
181     \return SObject_ptr arguments, the object found
182   */
183   virtual SALOMEDS::SObject_ptr FindObjectByPath(const char* thePath);
184
185   //! method to get a path of SObject
186   /*!
187     \param aSO  SObject_ptr arguments
188     \return char* arguments, the path of the SObject
189   */
190   virtual char* GetObjectPath(CORBA::Object_ptr theObject);
191
192   //! method to set a context: root ('/') is UserData component
193   /*!
194   */
195   virtual void SetContext(const char* thePath);
196
197   //! method to get a context
198   /*!
199   */
200   virtual char* GetContext();  
201
202   //! method to get all object names in the given context (or in the current context, if 'theContext' is empty)
203   /*!
204   */
205   virtual SALOMEDS::ListOfStrings* GetObjectNames(const char* theContext);
206
207   //! method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
208   /*!
209   */
210   virtual SALOMEDS::ListOfStrings* GetDirectoryNames(const char* theContext);
211
212   //! method to get all file names in the given context (or in the current context, if 'theContext' is empty)
213   /*!
214   */
215   virtual SALOMEDS::ListOfStrings* GetFileNames(const char* theContext);
216
217   //! method to get all components names
218   /*!
219   */
220   virtual SALOMEDS::ListOfStrings* GetComponentNames(const char* theContext);
221
222   //! method to Create a ChildIterator from an SObject 
223   /*!
224     \param aSO  SObject_ptr arguments
225     \return ChildIterator_ptr arguments, the created ChildIterator
226   */  
227   virtual SALOMEDS::ChildIterator_ptr NewChildIterator(SALOMEDS::SObject_ptr aSO);
228   SALOMEDS_ChildIterator_i GetChildIterator(SALOMEDS::SObject_ptr theSObject);
229
230   //! method to Create a SComponentIterator 
231   /*!
232     \return SComponentIterator_ptr arguments, the created SComponentIterator
233   */  
234   virtual SALOMEDS::SComponentIterator_ptr NewComponentIterator();
235   SALOMEDS_SComponentIterator_i GetComponentIterator();
236
237   //! method to Create a StudyBuilder
238   /*!
239     \return StudyBuilder_ptr arguments, the created StudyBuilder
240   */  
241   SALOMEDS_StudyBuilder_i* GetBuilder();
242   virtual SALOMEDS::StudyBuilder_ptr NewBuilder();
243  
244   //! method to get study name
245   /*!
246     \return char* arguments, the study name
247   */
248   virtual char* Name();
249
250   //! method to set study name
251   /*!
252     \param name char* arguments, the study name
253   */
254   virtual void  Name(const char* name);
255
256   //! method to get if study has been saved
257   /*!
258     \return bool arguments
259   */
260   virtual CORBA::Boolean IsSaved();
261
262  //! method to set if study has been saved
263   /*!
264     \param save bool arguments
265   */
266   virtual void  IsSaved(CORBA::Boolean save);
267
268  //! method to Detect if a Study has been modified since it has been saved
269   /*!
270     \return bool arguments
271   */
272   virtual CORBA::Boolean IsModified();
273
274   //! method to get URL of the study (idem GetPersistentReference) 
275   /*!
276     \return char* arguments, the study URL 
277   */
278   virtual char* URL();
279
280  //! method to set URL of the study
281   /*!
282     \param url char* arguments, the study URL
283   */
284   virtual void  URL(const char* url);
285
286   virtual CORBA::Short StudyId();
287   virtual void  StudyId(CORBA::Short id);
288
289   void IORUpdated(const Handle(SALOMEDS_IORAttribute) theAttribute);
290
291   virtual void UpdateIORLabelMap(const char* anIOR, const char* aLabel);
292   
293   virtual SALOMEDS::Study::ListOfSObject* FindDependances(SALOMEDS::SObject_ptr anObject);
294
295   virtual SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties();
296
297   virtual char* GetLastModificationDate();
298
299   virtual SALOMEDS::ListOfDates* GetModificationsDate();
300
301   virtual SALOMEDS::UseCaseBuilder_ptr GetUseCaseBuilder();
302
303   virtual void Close();
304
305   void EnableUseCaseAutoFilling(CORBA::Boolean isEnabled) { _autoFill = isEnabled; }
306
307   // postponed destroying of CORBA object functionality
308   virtual void AddPostponed(const char* theIOR);
309
310   virtual void AddCreatedPostponed(const char* theIOR);
311
312   virtual void RemovePostponed(const CORBA::Long theUndoLimit); // removes postponed IORs of old transaction
313                                                         // if theUndoLimit==0, removes all
314   virtual void UndoPostponed(const CORBA::Long theWay); // theWay = 1: resurrect objects,
315                                                 // theWay = -1: get back to the list of postponed
316 private:
317   friend class SALOMEDS_StudyBuilder_i;
318   friend class SALOMEDS_SObject_i;
319  
320   SALOMEDS_StudyManager_i* _StudyManager;
321
322   TSObjectMap mySObjectMap;
323
324   SALOMEDS_UseCaseBuilder_i* _UseCaseBuilder;
325   SALOMEDS_StudyBuilder_i* _Builder;
326   SALOMEDS::Callback_var   _callbackOnAdd;
327   SALOMEDS::Callback_var   _callbackOnRemove;
328
329   char*                    _name;  
330   Handle(TDocStd_Document) _doc;  // OCAF Document
331   CORBA::Boolean           _isSaved; // True if the Study is saved
332   char*                    _URL; //URL of the persistent reference of the study
333   CORBA::Short             _StudyId;
334
335   SALOMEDS_DataMapStringLabel myIORLabels;
336
337   // data structures for postponed destroying of CORBA object functionality
338   TColStd_SequenceOfAsciiString myPostponedIORs; // ordered set of IORs
339   TColStd_SequenceOfInteger myNbPostponed; // number of IOR in the each transaction
340   int myNbUndos; // number of current Undos, made by user
341
342   TDF_Label                _current;
343   bool                     _autoFill;  
344
345   SALOMEDS::SObject_ptr    _FindObject(TDF_Label theLabel,
346                                        const char* theObjectIOR, 
347                                        bool& theIsFound);
348   SALOMEDS::SObject_ptr    _FindObjectIOR(TDF_Label theLabel,
349                                           const char* theObjectIOR, 
350                                           bool& theIsFound);
351
352   SALOMEDS_Study_i(); // Not implemented
353   void operator=(const SALOMEDS_Study_i&); // Not implemented
354
355 };
356
357
358 #endif