3 #include <TCollection_AsciiString.hxx>
4 #include <TopAbs_ShapeEnum.hxx>
6 #include <TopoDS_Vertex.hxx>
7 #include <TopoDS_Edge.hxx>
8 #include <TopoDS_Face.hxx>
11 #include <Geom_Curve.hxx>
14 #include <BRep_Builder.hxx>
15 #include <BRep_Tool.hxx>
16 #include <BRepTools.hxx>
18 #include "SALOME_NamingService.hxx"
19 #include "SALOME_LifeCycleCORBA.hxx"
20 #include "Utils_SINGLETON.hxx"
22 #include "HexElements_grid.cxx"
25 #include "HEXABLOCK.hxx"
26 #include "utilities.h"
28 #include "HexDocument_impl.hxx"
31 using namespace HEXABLOCK_ORB;
34 // Static variables definition
35 PortableServer::POA_var HEXABLOCK::_poa;
36 HEXABLOCK* HEXABLOCK::_HEXABLOCKGen = NULL;
37 SALOME_LifeCycleCORBA* HEXABLOCK::_lcc = NULL;
38 GEOM::GEOM_Gen_var HEXABLOCK::_geomGen = GEOM::GEOM_Gen::_nil();
39 // GEOM_Client* HEXABLOCK::_geomClient = NULL;
40 CORBA::ORB_var HEXABLOCK::_orb;
41 SALOME_NamingService* HEXABLOCK::_ns = NULL;
43 //=============================================================================
45 * standard constructor
47 //=============================================================================
49 HEXABLOCK::HEXABLOCK(CORBA::ORB_ptr orb,
50 PortableServer::POA_ptr poa,
51 PortableServer::ObjectId * contId,
52 const char *instanceName,
53 const char *interfaceName) :
54 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
56 MESSAGE("activate object");
58 _poa = PortableServer::POA::_duplicate(poa);
59 _orb = CORBA::ORB::_duplicate(orb);
60 _id = _poa->activate_object(_thisObj);
61 _engine_cpp = new HEXA_NS::Hex;
64 MESSAGE("ALRRRRRIGHTTTTT");
67 //=============================================================================
69 * GetServant [ static ]
71 * Get servant of the CORBA object
73 //=============================================================================
75 PortableServer::ServantBase_var HEXABLOCK::GetServant( CORBA::Object_ptr theObject )
77 if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
80 PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
84 INFOS( "GetServant - Unknown exception was caught!!!" );
91 //=============================================================================
93 //=============================================================================
94 HEXABLOCK::~HEXABLOCK()
99 void HEXABLOCK::test()
101 MESSAGE("HEEEEEEEEEEEEEEYYYYYYYYYYY");
104 CORBA::Long HEXABLOCK::countDocument()
106 CORBA::Long nbDocument = _engine_cpp->countDocument();
107 // CORBA::Long nbDocument = 333;
111 Document_ptr HEXABLOCK::getDocument(CORBA::Long i)
113 HEXA_NS::Document *doc=_engine_cpp->getDocument(i);
114 Document_impl *servantCorba=new Document_impl(doc);
115 return servantCorba->_this();
118 void HEXABLOCK::removeDocument(HEXABLOCK_ORB::Document_ptr docIn)
120 Document_impl* docServant = ::DownCast<Document_impl*>( docIn );
121 ASSERT( docServant );
123 HEXA_NS::Document* doc = docServant->GetImpl();
124 _engine_cpp->removeDocument( doc );
129 Document_ptr HEXABLOCK::addDocument()
132 HEXA_NS::Document *doc=_engine_cpp->addDocument();
134 Document_impl *servantCorba=new Document_impl(doc);
136 return servantCorba->_this();
141 Document_ptr HEXABLOCK::loadDocument(const char* xmlFilename)
143 HEXA_NS::Document *doc=_engine_cpp->loadDocument(xmlFilename);
144 Document_impl *servantCorba=new Document_impl(doc);
145 return servantCorba->_this();
148 GEOM_Client* HEXABLOCK::getGeomClient()
150 // create shape reader if necessary
151 if ( _geomClient == NULL )
152 _geomClient = new GEOM_Client(GetContainerRef());
153 ASSERT( _geomClient);
158 TopoDS_Shape HEXABLOCK::geomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
161 if ( !theGeomObject->_is_nil() ){
162 _geomClient = getGeomClient();
164 if(CORBA::is_nil(_geomGen)) {
165 Engines::Component_ptr temp=GetLCC()->FindOrLoad_Component("FactoryServer","GEOM");
166 _geomGen=GEOM::GEOM_Gen::_narrow(temp);
168 if ( _geomClient != NULL && !_geomGen->_is_nil () )
169 S = _geomClient->GetShape( _geomGen, theGeomObject );
178 // HEXABLOCK_ORB::GEOM_Object_ptr HEXABLOCK::shapeToGeomObject (const TopoDS_Shape& theShape )
180 // HEXABLOCK_ORB::GEOM_Object_var aShapeObj;
181 // if ( !theShape.IsNull() ) {
182 // _geomClient = getGeomClient();//new GEOM_Client(GetContainerRef());
183 // TCollection_AsciiString IOR;
184 // bool found = _geomClient->Find(theShape, IOR);
186 // CORBA::Object_var obj = _orb->string_to_object( IOR.ToCString() );
187 // aShapeObj = HEXABLOCK_ORB::GEOM_Object::_narrow ( obj );
190 // return aShapeObj._retn();
195 // GEOM::GEOM_Object_ptr HEXABLOCK::_makeFace( const TopoDS_Shape& theShape )
197 // ASSERT ( theShape.ShapeType() == TopAbs_FACE );
199 // int theStudyID = 0;
200 // GEOM::GEOM_Object_var result;
202 // // PrimOp = self.GetI3DPrimOperations
203 // // GEOM_IShapesOperations
204 // return result._retn();
207 // GEOM::GEOM_Object_ptr HEXABLOCK::_makeEdge( const TopoDS_Shape& theShape )
209 // ASSERT ( theShape.ShapeType() == TopAbs_EDGE );
210 // int theStudyID = 0;
211 // GEOM::GEOM_Object_var result;
212 // GEOM::GEOM_Object_var p1;
213 // GEOM::GEOM_Object_var p2;
215 // GEOM::GEOM_IBasicOperations_var aBasicOp = _geomGen->GetIBasicOperations(theStudyID);
216 // GEOM::GEOM_IShapesOperations_var aShapesOp = _geomGen->GetIShapesOperations(theStudyID);
218 // TopoDS_Edge anEdge = TopoDS::Edge( theShape );
220 // Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, f, l);
222 // gp_Pnt aCurveStart = aCurve->Value( f );
223 // gp_Pnt aCurveEnd = aCurve->Value( l );
225 // double x1, y1, z1;
226 // double x2, y2, z2;
228 // x1 = aCurveStart.X(); y1 = aCurveStart.Y(); z1 = aCurveStart.Z();
229 // x2 = aCurveEnd.X(); y2 = aCurveEnd.Y(); z2 = aCurveEnd.Z();
230 // p1= aBasicOp->MakePointXYZ(x1, y1, z1);
231 // p2= aBasicOp->MakePointXYZ(x2, y2, z2);
232 // result = aShapesOp->MakeEdge(p1, p2);
234 // return result._retn();
237 GEOM::GEOM_Object_ptr HEXABLOCK::_makeVertex( const TopoDS_Shape& theShape )
239 ASSERT ( theShape.ShapeType() == TopAbs_VERTEX );
242 GEOM::GEOM_Object_var result;
244 TopoDS_Vertex aPoint;
245 aPoint = TopoDS::Vertex( theShape );
246 gp_Pnt aPnt = BRep_Tool::Pnt( aPoint );
251 GEOM::GEOM_IBasicOperations_var aBasicOp = _geomGen->GetIBasicOperations(theStudyID);
252 result = aBasicOp->MakePointXYZ(x, y, z);
254 return result._retn();
258 GEOM::GEOM_Object_ptr HEXABLOCK::shapeToGeomObject (const TopoDS_Shape& theShape )
260 GEOM::GEOM_Object_var aShapeObj;
261 if ( !theShape.IsNull() ) {
262 switch ( theShape.ShapeType() ){
263 case TopAbs_VERTEX: aShapeObj = _makeVertex( theShape ); break;
264 // case TopAbs_FACE: aShapeObj = _makeFace( theShape ); break;
265 // case TopAbs_EDGE: aShapeObj = _makeEdge( theShape ); break;
266 default: throw (SALOME_Exception(LOCALIZED("shapeToGeomObject : shape type not supported")));
269 return aShapeObj._retn();
273 // GEOM::GEOM_Object_ptr HEXABLOCK::shapeToGeomObject (const TopoDS_Shape& theShape )
275 // GEOM::GEOM_Object_var aShapeObj;
276 // std::cout<<"shapeToGeomObject "<<std::endl;
277 // if ( !theShape.IsNull() ) {
278 // std::cout<<"shapeToGeomObject !theShape.IsNull()"<<std::endl;
279 // _geomClient = getGeomClient();//new GEOM_Client(GetContainerRef());
280 // TCollection_AsciiString IOR;
281 // bool found = _geomClient->Find(theShape, IOR);
282 // std::cout<<"shapeToGeomObject found"<<found<<std::endl;
284 // CORBA::Object_var obj = _orb->string_to_object( IOR.ToCString() );
285 // aShapeObj = GEOM::GEOM_Object::_narrow ( obj );
288 // return aShapeObj._retn();
298 SALOME_LifeCycleCORBA* HEXABLOCK::GetLCC() {
299 if ( _lcc == NULL ) {
300 _lcc = new SALOME_LifeCycleCORBA( GetNS() );
305 SALOME_NamingService* HEXABLOCK::GetNS()
308 _ns = SINGLETON_<SALOME_NamingService>::Instance();
309 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
310 _ns->init_orb( _orb );
317 TopoDS_Shape string2shape( const string& brep )
321 // istringstream streamBrep(brep.c_str());
322 istringstream streamBrep(brep);
323 // char* chaine = new char[brep.size()];
324 // strcpy(chaine, brep.c_str());
325 // istringstream streamBrep( chaine );
327 BRep_Builder aBuilder;
328 BRepTools::Read(shape, streamBrep, aBuilder);
329 // BRepTools::Read(shape, brep, aBuilder);
333 // TopoDS_Shape STRING_TO_SHAPE( char* buf, int sizebuf )
335 // TopoDS_Shape shape;
336 // std::istrstream streamBrep(buf,sizebuf);
337 // BRep_Builder aBuilder;
338 // BRepTools::Read(shape, streamBrep, aBuilder);
345 string shape2string( const TopoDS_Shape& aShape )
347 ostringstream streamShape;
349 BRepTools::Write(aShape, streamShape);
350 // BRepTools::Write(aShape, strShape);
352 return streamShape.str();
358 PortableServer::ObjectId * HEXABLOCKEngine_factory(
360 PortableServer::POA_ptr poa,
361 PortableServer::ObjectId * contId,
362 const char *instanceName,
363 const char *interfaceName)
365 MESSAGE("PortableServer::ObjectId * HEXABLOCKEngine_factory()");
366 SCRUTE(interfaceName);
367 HEXABLOCK * myHEXABLOCK
368 = new HEXABLOCK(orb, poa, contId, instanceName, interfaceName);
369 return myHEXABLOCK->getId() ;
374 // //================= Primitives Construction : BasicOperations =================
375 // //=============================================================================
376 // // makeBanner: renvoie un message
377 // //=============================================================================
380 // #include "Vertex_impl.hxx"
381 // #include "Edge_impl.hh"
382 // char* HEXABLOCK::makeBanner(const char* name)
384 // string banner="Pourquoi?, ";
386 // return CORBA::string_dup(banner.c_str());
389 // //=============================================================================
390 // // makeVertex: construit un sommet
391 // //=============================================================================
393 // HEXABLOCK_ORB::Vertex_ptr HEXABLOCK::makeVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z)
395 // Vertex *vert=_engine_cpp->makeVertex(x,y,z);
396 // Vertex_impl *servantCorba=new Vertex_impl(vert);
397 // return servantCorba->_this();
400 // //=============================================================================
401 // // makeEdge: construit une arrĂȘte
402 // //=============================================================================
404 // HEXABLOCK_ORB::Edge_ptr HEXABLOCK::makeEdge(HEXABLOCK_ORB::Vertex_ptr va, HEXABLOCK_ORB::Vertex_ptr vb)
406 // Edge *edg=_engine_cpp->makeEdge(va,vb);
407 // Edge_impl *servantCorba=new Edge_impl(edg);
408 // return servantCorba->_this();
410 // //=============================================================================
412 // //=============================================================================