]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISUConfig.hh
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VISU_I / VISUConfig.hh
1 //  VISU OBJECT : interactive object for VISU entities implementation
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //  File   : VISUConfig.hh
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #ifndef __VISU_CONFIG_H__
28 #define __VISU_CONFIG_H__
29
30 #include "VISU_I.hxx"
31
32 // IDL headers
33 #include "SALOMEconfig.h"
34 #include CORBA_SERVER_HEADER(VISU_Gen)
35 #include CORBA_SERVER_HEADER(MED)
36 #include CORBA_SERVER_HEADER(SALOMEDS)
37 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
38
39 #include "SALOME_NamingService.hxx"
40 #include "SALOME_LifeCycleCORBA.hxx"
41 #include "Utils_CorbaException.hxx"
42 #include "utilities.h"
43
44 #include "SALOMEDSClient_SObject.hxx"
45 #include "SALOMEDSClient_Study.hxx"
46
47 // QT headers
48 #include <qstring.h>
49 #include <qthread.h>
50 #include <qfileinfo.h>
51 #include <qapplication.h>
52
53 // standard C++ headers
54 #include <stdio.h>
55
56 // STL headers
57 #include <map>
58 #include <deque>
59 #include <string>
60 #include <sstream>
61 #include <iostream>
62 #include <stdexcept>
63
64 class SUIT_Session;
65 class SUIT_ResourceMgr;
66 class SalomeApp_Study;
67
68
69 namespace VISU
70 {
71
72   VISU_I_EXPORT SUIT_Session *GetSession();
73   VISU_I_EXPORT SUIT_ResourceMgr *GetResourceMgr();
74
75   //===========================================================================
76
77   class VISU_Gen_i;
78
79   class VISU_I_EXPORT Base_i : public virtual POA_VISU::Base,
80                                public virtual PortableServer::RefCountServantBase
81   {
82   public:
83     typedef VISU::Base TInterface;
84
85     Base_i();
86     virtual ~Base_i();
87     virtual char* GetID();
88     virtual VISU::VISUType GetType() = 0;
89
90   protected:
91     std::string myID;
92
93   protected:
94     static QMutex* myMutex;
95     static CORBA::ORB_var myOrb;
96     static PortableServer::POA_var myPoa;
97     static SALOME_NamingService* myNamingService;
98     static VISU_Gen_i* myVisuGenImpl;
99     static SALOME_LifeCycleCORBA* myEnginesLifeCycle;
100
101   public:
102     static CORBA::ORB_var GetORB() { return myOrb;}
103     static PortableServer::POA_var GetPOA() { return myPoa;}
104     static SALOME_NamingService* GetNS() { return myNamingService;}
105     static SALOME_LifeCycleCORBA* GetLCC() { return myEnginesLifeCycle;}
106     static VISU_Gen_i* GetVisuGenImpl() { return myVisuGenImpl;}
107   };
108
109
110   //===========================================================================
111   class VISU_I_EXPORT Mutex
112   {
113     QMutex* myMutex;
114     int isQAppLocked;
115   public:
116     Mutex(QMutex* theMutex);
117     ~Mutex();
118   };
119
120
121   //===========================================================================
122   class VISU_I_EXPORT Storable : public virtual Base_i 
123   {
124   public:
125     std::string
126     ToString();
127
128     virtual
129     const char* 
130     GetComment() const = 0;
131
132
133     //---------------------------------------------------------------
134     typedef std::map<std::string, QString> TRestoringMap;
135
136     typedef Storable* (*TStorableEngine)(SALOMEDS::SObject_ptr theSObject,
137                                          const TRestoringMap& theMap,
138                                          const std::string& thePrefix,
139                                          CORBA::Boolean theIsMultiFile);
140
141     typedef std::map<std::string, TStorableEngine> TStorableEngineMap;
142
143     static 
144     void
145     RegistryStorableEngine(const std::string& theComment, 
146                            TStorableEngine theEngine);
147
148     static
149     Storable* 
150     Create(SALOMEDS::SObject_ptr theSObject,
151            const std::string& theLocalPersistentID, 
152            const std::string& thePrefix,
153            CORBA::Boolean theIsMultiFile);
154
155
156     //---------------------------------------------------------------
157     static 
158     VISU::VISUType
159     Comment2Type(const std::string& theComment);
160
161     static 
162     VISU::VISUType
163     RestoringMap2Type(const TRestoringMap& theRestoringMap);
164
165     static 
166     VISU::VISUType
167     Stream2Type(const std::string& thePersistentString);
168
169     static 
170     VISU::VISUType
171     SObject2Type(const _PTR(SObject)& theSObject);
172
173     static 
174     std::string
175     CorrectPersistentString(const std::string& thePersistentString);
176
177     static 
178     std::string 
179     FindEntry(SALOMEDS::Study_ptr theStudyDocument, 
180               const std::string& theStartEntry,
181               const TRestoringMap& theRestoringMap, 
182               int IsAllLevels = true);
183   
184     static 
185     QString 
186     FindValue(const TRestoringMap& theMap, 
187               const std::string& theArg, 
188               bool* theIsFind = NULL);
189
190     static 
191     QString
192     FindValue(const TRestoringMap& theMap, 
193               const std::string& theArg, 
194               const QString& theDefaultValue);
195
196     static
197     void
198     StringToMap(const QString& theString, 
199                 TRestoringMap& theMap);
200
201     static
202     TRestoringMap
203     GetStorableMap(_PTR(SObject) theSObject);
204
205     static
206     SALOMEDS::SObject_ptr 
207     GetResultSO(SALOMEDS::SObject_ptr theSObject);
208
209     static
210     void
211     DataToStream(std::ostringstream& theStr, 
212                  const QString& theName, 
213                  const QString& theVal);
214
215     static 
216     void
217     DataToStream(std::ostringstream& theStr, 
218                  const QString& theName, 
219                  int theVal);
220
221     static 
222     void
223     DataToStream(std::ostringstream& theStr, 
224                  const QString& theName, 
225                  long theVal);
226
227     static
228     void
229     DataToStream(std::ostringstream& theStr, 
230                  const QString& theName, 
231                  double theVal);
232
233     //---------------------------------------------------------------
234     virtual 
235     CORBA::Boolean 
236     CanCopy(SALOMEDS::SObject_ptr theObject);
237
238     typedef std::string TFileName;
239     typedef std::vector<TFileName> TFileNames;
240
241     virtual 
242     bool 
243     CopyFrom(SALOMEDS::SObject_ptr theObject, 
244              CORBA::Long& theObjectID,
245              const std::string& theTmpDir,
246              TFileNames& theFileNames);
247
248
249     //---------------------------------------------------------------
250   protected:
251     virtual 
252     void 
253     ToStream(std::ostringstream& theStr) = 0;
254
255   private:
256     static TStorableEngineMap myStorableEngineMap;
257   };
258
259   //===========================================================================
260   VISU_I_EXPORT
261   QString
262   GenerateName(const std::string& theFmt, int theId);
263
264   VISU_I_EXPORT 
265   PortableServer::ServantBase_var 
266   GetServant(CORBA::Object_ptr theObject);
267
268   VISU_I_EXPORT
269   CORBA::Object_var
270   ClientSObjectToObject(_PTR(SObject) theSObject);
271
272   VISU_I_EXPORT
273   CORBA::Object_var
274   SObjectToObject(SALOMEDS::SObject_ptr);
275
276   VISU_I_EXPORT
277   _PTR(SComponent) 
278   ClientFindOrCreateVisuComponent(_PTR(Study) theStudyDocument);
279
280   VISU_I_EXPORT 
281   SALOMEDS::SComponent_var 
282   FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument);
283
284   const char* const NO_ICON = "";
285   const char* const NO_IOR = "";
286   const char* const NO_NAME = "";
287   const char* const NO_PERFSITENT_REF = "";
288   const char* const NO_COMMENT = "";
289
290   VISU_I_EXPORT
291   std::string 
292   CreateAttributes(SALOMEDS::Study_ptr theStudyDocument,
293                    const std::string& theFatherEntry, 
294                    const std::string& theIconName,
295                    const std::string& theIOR, 
296                    const std::string& theName,
297                    const std::string& thePersistentRef, 
298                    const std::string& theComment,
299                    CORBA::Boolean theCreateNew = true);
300
301   VISU_I_EXPORT
302   std::string 
303   CreateAttributes(_PTR(Study) theStudyDocument,
304                    const std::string& theFatherEntry, 
305                    const std::string& theIconName,
306                    const std::string& theIOR, 
307                    const std::string& theName,
308                    const std::string& thePersistentRef, 
309                    const std::string& theComment,
310                    CORBA::Boolean theCreateNew = true);
311
312   VISU_I_EXPORT
313   SALOMEDS::SObject_var
314   GetSObject(_PTR(SObject));
315
316   VISU_I_EXPORT
317   _PTR(SObject) 
318   GetClientSObject(SALOMEDS::SObject_ptr theSObject, 
319                    _PTR(Study) theStudy);
320
321   VISU_I_EXPORT
322   SALOMEDS::Study_var 
323   GetDSStudy(_PTR(Study) theStudy);
324
325   VISU_I_EXPORT
326   SalomeApp_Study* 
327   GetGUIStudy(SALOMEDS::Study_ptr theStudy);
328
329   VISU_I_EXPORT
330   _PTR(Study) 
331   GetStudy(SALOMEDS::Study_ptr theStudy);
332
333   VISU_I_EXPORT
334   void
335   RemoveFromStudy(SALOMEDS::SObject_ptr theSObject,
336                   bool theIsAttrOnly = true,
337                   bool theDestroySubObjects = false);
338   VISU_I_EXPORT
339   void 
340   RemoveFromStudy(_PTR(SObject) theSObject,
341                   bool theIsAttrOnly = true,
342                   bool theDestroySubObjects = false);
343 }
344
345 #endif