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