Salome HOME
796f6ec4db621ff8b7c5b9040c03528f39481df3
[modules/geom.git] / src / GEOMClient / GEOM_Client.hxx
1 //  Copyright (C) 2007-2010  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 //  GEOM GEOMClient : tool to transfer BREP files from GEOM server to GEOM client
23 //  File   : GEOM_Client.hxx
24 //  Author : Yves FRICAUD
25 //  Module : GEOM
26
27 #ifndef _GEOM_Client_HeaderFile
28 #define _GEOM_Client_HeaderFile
29
30 #include <SALOMEconfig.h>
31 #include CORBA_SERVER_HEADER(GEOM_Gen)
32
33 #ifdef HAVE_FINITE
34 #undef HAVE_FINITE // E.A. fix a warning about redefinition of HAVE_FINITE in re-inclusion of Standard_values.h
35 #endif
36 #ifndef _TColStd_SequenceOfAsciiString_HeaderFile
37 #include <TColStd_SequenceOfAsciiString.hxx>
38 #endif
39 #ifndef _TopTools_SequenceOfShape_HeaderFile
40 #include <TopTools_SequenceOfShape.hxx>
41 #endif
42 #ifndef _Standard_Integer_HeaderFile
43 #include <Standard_Integer.hxx>
44 #endif
45
46 class TCollection_AsciiString;
47 class TopoDS_Shape;
48
49 #ifndef _Standard_HeaderFile
50 #include <Standard.hxx>
51 #endif
52 #ifndef _Standard_Macro_HeaderFile
53 #include <Standard_Macro.hxx>
54 #endif
55
56 #ifdef WNT
57  #if defined GEOMCLIENT_EXPORTS || defined GEOMClient_EXPORTS
58   #if defined WIN32
59    #define GEOMCLIENT_EXPORT __declspec( dllexport )
60   #else
61    #define GEOMCLIENT_EXPORT
62   #endif
63  #else
64   #if defined WIN32
65    #define GEOMCLIENT_EXPORT __declspec( dllimport )
66   #else
67    #define GEOMCLIENT_EXPORT
68   #endif
69  #endif
70 #else
71  #define GEOMCLIENT_EXPORT
72 #endif
73
74 #include <TCollection_AsciiString.hxx>
75 #include <TopoDS_Shape.hxx>
76 #include <map>
77 #include <vector>
78
79 /*
80  * if define SINGLE_CLIENT is not commented, the method get_client always returns the same GEOM_Client object (singleton object)
81  * and the SHAPE_READER macro can be used to define an object that is always this singleton object
82  * if define SINGLE_CLIENT is commented, we get the old way to define the GEOM_Client objects : get_client returns a new object
83  * and the SHAPE_READER macro defines also a new object
84  */
85 #define SINGLE_CLIENT
86
87 //=====================================================================
88 // GEOM_Client : class definition
89 //=====================================================================
90 class GEOMCLIENT_EXPORT GEOM_Client  {
91
92  public:
93
94   inline void* operator new(size_t,void* anAddress)
95   {
96     return anAddress;
97   }
98   inline void* operator new(size_t size)
99   {
100     return Standard::Allocate(size);
101   }
102   inline void  operator delete(void *anAddress)
103   {
104     if (anAddress) Standard::Free((Standard_Address&)anAddress);
105   }
106   // Methods PUBLIC
107   //
108   //Standard_EXPORT
109   GEOM_Client();
110   //Standard_EXPORT
111   GEOM_Client(Engines::Container_ptr client);
112   //Standard_EXPORT
113   GEOM_Client(const GEOM_Client& client);
114   //Standard_EXPORT
115   Standard_Integer Find( const TCollection_AsciiString& IOR, TopoDS_Shape& S ) ;
116   //Standard_EXPORT
117   Standard_Integer Find( const TopoDS_Shape& S, TCollection_AsciiString& IOR ) ;
118   //Standard_EXPORT
119   void Bind( const TCollection_AsciiString& IOR, const TopoDS_Shape& S ) ;
120   //Standard_EXPORT
121   TopoDS_Shape GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape );
122   //Standard_EXPORT
123   void RemoveShapeFromBuffer( const TCollection_AsciiString& IOR ) ;
124   //Standard_EXPORT
125   void ClearClientBuffer() ;
126   //Standard_EXPORT
127   unsigned int BufferLength() ;
128   TopoDS_Shape Load( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape);
129 #ifdef SINGLE_CLIENT
130   static GEOM_Client& get_client();
131 #else
132   static GEOM_Client get_client();
133 #endif
134
135  private:
136   // Fields PRIVATE
137   //
138   TColStd_SequenceOfAsciiString myIORs ;
139   TopTools_SequenceOfShape myShapes ;
140   std::map< TCollection_AsciiString , int > _myIndexes;
141   std::map< TCollection_AsciiString , std::vector<TopoDS_Shape> > _mySubShapes;
142   long  pid_client;
143 };
144
145 #ifdef SINGLE_CLIENT
146 #define SHAPE_READER(obj) GEOM_Client& obj=GEOM_Client::get_client()
147 #else
148 #define SHAPE_READER(obj) GEOM_Client obj
149 #endif
150
151 #endif