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