Salome HOME
First publish of HEXABLOCKcomponant
[modules/hexablock.git] / src / HEXABLOCK_I / HEXABLOCK.hxx
1 #ifndef _HEXABLOCK_HXX_
2 #define _HEXABLOCK_HXX_
3
4 #include <SALOMEconfig.h>
5 #include CORBA_SERVER_HEADER(HEXABLOCK_Gen)
6 #include "SALOME_Component_i.hxx"
7
8
9 #include <sstream>
10 // #include <strstream.h>
11 // #include <iostream.h>
12
13
14 #include <TopoDS_Shape.hxx>
15 #include "GEOM_Client.hxx"
16
17 #include "hexa_base.hxx"
18 #include "Hex.hxx"
19
20 using namespace HEXABLOCK_ORB;
21
22 class SALOME_LifeCycleCORBA;
23 class SALOME_NamingService;
24
25
26 class HEXABLOCK:
27   public POA_HEXABLOCK_ORB::HEXABLOCK_Gen,
28   public Engines_Component_i 
29 {
30
31 public:
32     HEXABLOCK( CORBA::ORB_ptr orb,
33             PortableServer::POA_ptr poa,
34             PortableServer::ObjectId * contId, 
35             const char *instanceName, 
36             const char *interfaceName);
37   // Get object of the CORBA reference
38     static PortableServer::POA_var GetPOA() { return _poa;}
39     static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
40
41     virtual ~HEXABLOCK();
42
43     void test();
44     ::CORBA::Long countDocument();
45     Document_ptr getDocument(::CORBA::Long i);
46     void removeDocument(Document_ptr d); //CS_TODO
47     Document_ptr addDocument();
48     Document_ptr loadDocument(const char* xmlFilename);
49
50     GEOM_Client* getGeomClient();
51     TopoDS_Shape geomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
52     GEOM::GEOM_Object_ptr shapeToGeomObject(const TopoDS_Shape& theShape );
53     static SALOME_LifeCycleCORBA*  GetLCC();
54     static SALOME_NamingService* GetNS();
55     static HEXABLOCK* GetHEXABLOCKGen() { return _HEXABLOCKGen;}
56
57 private:
58    HEXA_NS::Hex* _engine_cpp;
59    GEOM_Client*  _geomClient;
60
61
62   static PortableServer::POA_var _poa;// POA reference
63   static GEOM::GEOM_Gen_var      _geomGen;
64   static SALOME_LifeCycleCORBA*  _lcc;
65   static CORBA::ORB_var          _orb;
66   static SALOME_NamingService*   _ns;
67   static HEXABLOCK*                   _HEXABLOCKGen;
68
69   GEOM::GEOM_Object_ptr _makeVertex( const TopoDS_Shape& theShape );
70
71 };
72
73 extern "C"
74     PortableServer::ObjectId * HEXABLOCKEngine_factory(
75       CORBA::ORB_ptr orb,
76       PortableServer::POA_ptr poa,
77       PortableServer::ObjectId * contId,
78       const char *instanceName,
79       const char *interfaceName
80     );
81
82
83 template<class T>
84   T
85   DownCast(CORBA::Object_ptr theArg)
86   {
87     return dynamic_cast<T>(HEXABLOCK::GetServant(theArg).in());
88   }
89
90
91
92
93
94 TopoDS_Shape string2shape( const string& brep );
95
96
97 string shape2string( const TopoDS_Shape& aShape );
98
99
100
101
102 #endif
103
104
105 // 1) Séquence de code convertissant une chaîne au format BREP vers un TopoDS_Shape
106 // 
107 // TopoDS_Shape STRING_TO_SHAPE( char* buf, int sizebuf )
108 // {
109 //   TopoDS_Shape shape;
110 //   std::istrstream streamBrep(buf,sizebuf);
111 //   BRep_Builder aBuilder;
112 //   BRepTools::Read(shape, streamBrep, aBuilder);
113 //   return(shape);
114 // }
115 // 
116 // 2) Séquence de code convertissant un TopoDS_Shape en une chaîne au format BREP
117 // 
118 // char* SHAPE_TO_STRING( TopoDS_Shape aShape, int& sizebuf )
119 // {
120 //  ostrstream streamShape;
121 //  BRepTools::Write(aShape, streamShape);
122 //  sizebuf = streamShape.pcount();
123 //  char* buf = new char [sizebuf];
124 //  char* valueOfStream = streamShape.str();
125 //  memcpy(buf, valueOfStream, size);
126 //  return buf;
127 // }
128 // 
129 // 3) Séquence de code accédant aux coordonnées d'un TopoDS_Shape qui est un Vertex
130 // 
131 // bool SHAPE_TO_COORD(TopoDS_Shape aShape, double& x, double& y, double& z)
132 // {
133 //   if ( aShape.ShapeType() == TopAbs_VERTEX ) {
134 //       TopoDS_Vertex aPoint;
135 //        aPoint = TopoDS::Vertex( aShape );
136 //       gp_Pnt aPnt = BRep_Tool::Pnt( aPoint );
137 //       x = aPnt.X();
138 //       y = aPnt.Y();
139 //       z = aPnt.Z();
140 //        return(1);
141 //    } else {
142 //        return(0);
143 //   };
144 // }
145 // 
146 // 4) Séquence de code créant un TopoDS_Shape à partir de coordonnées
147 // 
148 // TopoDS_Shape COORD_TO_SHAPE(double x, double y, double z)
149 // {
150 //       gp_Pnt aPnt(x, y, z);
151 //       BRepBuilderAPI_MakeVertex mkVertex (aPnt);
152 //      TopoDS_Vertex aVertex = TopoDS::Vertex(mkVertex.Shape());
153 //       return aVertex;
154 // }