Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 // IDL headers
31 #include "SALOMEconfig.h"
32 #include CORBA_SERVER_HEADER(VISU_Gen)
33 #include CORBA_SERVER_HEADER(MED)
34 #include CORBA_SERVER_HEADER(SALOMEDS)
35 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
36
37 #include "SALOME_NamingService.hxx"
38 #include "SALOME_LifeCycleCORBA.hxx"
39 #include "Utils_CorbaException.hxx"
40 #include "utilities.h"
41
42 #include "SALOMEDSClient_SObject.hxx"
43 #include "SALOMEDSClient_Study.hxx"
44
45 // QT headers
46 #include <qstring.h>
47 #include <qthread.h>
48 #include <qfileinfo.h>
49 #include <qapplication.h>
50
51 // standard C++ headers
52 #include <stdio.h>
53
54 // STL headers
55 #include <map>
56 #include <string>
57 #include <sstream>
58 #include <iostream>
59 #include <stdexcept>
60
61 class SUIT_Session;
62 class SUIT_ResourceMgr;
63
64 namespace VISU
65 {
66
67   SUIT_Session *GetSession();
68   SUIT_ResourceMgr *GetResourceMgr();
69
70   //===========================================================================
71
72   class VISU_Gen_i;
73
74   class Base_i : public virtual POA_VISU::Base,
75                  public virtual PortableServer::RefCountServantBase
76   {
77   public:
78     Base_i();
79     virtual ~Base_i();
80     virtual char* GetID();
81     virtual VISU::VISUType GetType() = 0;
82
83   protected:
84     std::string myID;
85
86   protected:
87     static QMutex* myMutex;
88     static CORBA::ORB_var myOrb;
89     static PortableServer::POA_var myPoa;
90     static SALOME_NamingService* myNamingService;
91     static VISU_Gen_i* myVisuGenImpl;
92     static SALOME_LifeCycleCORBA* myEnginesLifeCycle;
93
94   public:
95     static CORBA::ORB_var GetORB() { return myOrb;}
96     static PortableServer::POA_var GetPOA() { return myPoa;}
97     static SALOME_NamingService* GetNS() { return myNamingService;}
98     static SALOME_LifeCycleCORBA* GetLCC() { return myEnginesLifeCycle;}
99     static VISU_Gen_i* GetVisuGenImpl() { return myVisuGenImpl;}
100   };
101
102
103   //===========================================================================
104   class Mutex{
105     QMutex* myMutex;
106     int isQAppLocked;
107   public:
108     Mutex(QMutex* theMutex);
109     ~Mutex();
110   };
111
112
113   //===========================================================================
114   class Storable : public virtual Base_i {
115   protected:
116     virtual void ToStream(std::ostringstream& theStr) = 0;
117   public:
118     std::string ToString();
119     virtual const char* GetComment() const = 0;
120     typedef std::map<std::string,QString> TRestoringMap;
121     typedef Storable* (*TStorableEngine)(SALOMEDS::SObject_ptr theSObject,
122                                          const std::string& thePrefix, const TRestoringMap& theMap);
123     typedef std::map<std::string,TStorableEngine> TCallbackMap;
124     static void Registry(const char* theComment, TStorableEngine theEngine);
125     static Storable* Create(SALOMEDS::SObject_ptr, const std::string& thePrefix, const std::string& theString);
126     static QString FindValue(const TRestoringMap& theMap, const std::string& theArg, bool* isFind = NULL);
127     static QString FindValue(const TRestoringMap& theMap, const std::string& theArg, const QString& theDefaultValue);
128     static void StrToMap(const QString& theStr, VISU::Storable::TRestoringMap& theMap);
129     static SALOMEDS::SObject_ptr GetResultSO(SALOMEDS::SObject_ptr theSObject);
130     static void DataToStream(std::ostringstream& theStr, const QString& theName, const QString& theVal);
131     static void DataToStream(std::ostringstream& theStr, const QString& theName, const int theVal);
132     static void DataToStream(std::ostringstream& theStr, const QString& theName, const double theVal);
133   };
134
135   //===========================================================================
136   class RemovableObject_i : public virtual POA_VISU::RemovableObject,
137                             public virtual Storable
138   {
139   public:
140     virtual void RemoveFromStudy() = 0;
141   };
142
143   //===========================================================================
144   const CORBA::Boolean IsMultifile();
145   QString GenerateName(const std::string& theFmt, int theId);
146
147   PortableServer::ServantBase_var GetServant(CORBA::Object_ptr theObject);
148   CORBA::Object_var ClientSObjectToObject(_PTR(SObject) theSObject);
149   CORBA::Object_var SObjectToObject(SALOMEDS::SObject_ptr);
150
151   _PTR(SComponent) ClientFindOrCreateVisuComponent(_PTR(Study) theStudyDocument);
152   SALOMEDS::SComponent_var FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument);
153
154   std::string CreateAttributes(SALOMEDS::Study_ptr theStudyDocument,
155                                const char* theFatherEntry, const char* theRefFatherEntry,
156                                const char* theIOR, const char* theName,
157                                const char* thePersistentRef, const char* theComment,
158                                CORBA::Boolean theCreateNew = true);
159
160   std::string CreateAttributes(_PTR(Study) theStudyDocument,
161                                const char* theFatherEntry, const char* theRefFatherEntry,
162                                const char* theIOR, const char* theName,
163                                const char* thePersistentRef, const char* theComment,
164                                CORBA::Boolean theCreateNew = true);
165
166   std::string FindEntryWithComment(SALOMEDS::Study_ptr theStudyDocument, const char* theStartEntry,
167                                    const char* theComment, int IsAllLevels = true);
168
169   SALOMEDS::SObject_var GetSObject(_PTR(SObject));
170   _PTR(SObject) GetClientSObject(SALOMEDS::SObject_var, _PTR(Study));
171
172   SALOMEDS::Study_var GetDSStudy(_PTR(Study));
173
174   void RemoveFromStudy(SALOMEDS::SObject_ptr theSObject,
175                        bool theIsAttrOnly = true,
176                        bool theDestroySubObjects = false);
177   void RemoveFromStudy(_PTR(SObject) theSObject,
178                        bool theIsAttrOnly = true,
179                        bool theDestroySubObjects = false);
180 }
181
182 #endif