1 // Copyright (C) 2009-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef _HEXABLOCK_HXX_
20 #define _HEXABLOCK_HXX_
22 #include <SALOMEconfig.h>
23 #include CORBA_SERVER_HEADER(HEXABLOCK_Gen)
24 #include "SALOME_Component_i.hxx"
25 // #include "SALOMEDSImpl_TMPFile.hxx"
26 // #include "SALOMEDSImpl_SComponent.hxx"
33 #include <TopoDS_Shape.hxx>
34 #include "GEOM_Client.hxx"
36 #include "hexa_base.hxx"
39 using namespace HEXABLOCK_ORB;
41 class SALOME_LifeCycleCORBA;
42 class SALOME_NamingService;
48 // ===========================================================
49 // Study context - stores study-connected objects references
50 // ==========================================================
62 // register object in the internal map and return its id
63 int addObject( string theIOR )
65 int nextId = getNextId();
66 mapIdToIOR[ nextId ] = theIOR;
69 // find the object id in the internal map by the IOR
70 int findId( string theIOR )
72 map<int, string>::iterator imap;
73 for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
74 if ( imap->second == theIOR )
79 // get object's IOR by id
80 string getIORbyId( const int theId )
82 if ( mapIdToIOR.find( theId ) != mapIdToIOR.end() )
83 return mapIdToIOR[ theId ];
86 // get object's IOR by old id
87 string getIORbyOldId( const int theOldId )
89 if ( mapIdToId.find( theOldId ) != mapIdToId.end() )
90 return getIORbyId( mapIdToId[ theOldId ] );
93 // maps old object id to the new one (used when restoring data)
94 void mapOldToNew( const int oldId, const int newId ) {
95 mapIdToId[ oldId ] = newId;
97 // get old id by a new one
98 int getOldId( const int newId ) {
99 map<int, int>::iterator imap;
100 for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) {
101 if ( imap->second == newId )
108 // get next free object identifier
112 while( mapIdToIOR.find( id ) != mapIdToIOR.end() )
117 map<int, string> mapIdToIOR; // persistent-to-transient map
118 map<int, int> mapIdToId; // used to translate object from persistent to transient form
123 class HEXABLOCK_Gen_i: public POA_HEXABLOCK_ORB::HEXABLOCK_Gen,
124 public Engines_Component_i
127 HEXABLOCK_Gen_i( CORBA::ORB_ptr orb,
128 PortableServer::POA_ptr poa,
129 PortableServer::ObjectId * contId,
130 const char *instanceName,
131 const char *interfaceName);
132 // Get object of the CORBA reference
133 static CORBA::ORB_var GetORB() { return _orb;}
134 static PortableServer::POA_var GetPOA() { return _poa;}
135 static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
137 virtual ~HEXABLOCK_Gen_i();
140 ::CORBA::Long countDocument();
141 Document_ptr getDocument(::CORBA::Long i);
142 void removeDocument(Document_ptr d); //CS_TODO
143 Document_ptr addDocument (const char* name);
144 Document_ptr findDocument (const char* name);
145 Document_ptr loadDocument (const char* xmlFilename);
147 GEOM_Client* getGeomClient();
148 TopoDS_Shape geomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
149 // GEOM::GEOM_Object_ptr shapeToGeomObject(const TopoDS_Shape& theShape );
150 GEOM::GEOM_Object_ptr brepToGeomObject(const std::string& theBrep);
151 static SALOME_LifeCycleCORBA* GetLCC();
152 static SALOME_NamingService* GetNS();
153 static HEXABLOCK_Gen_i* GetHEXABLOCKGen() { return _HEXABLOCKGen;}
156 virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
157 CORBA::Boolean isPublished,
158 CORBA::Boolean isMultiFile,
159 CORBA::Boolean& isValidScript);
161 void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
162 int GetCurrentStudyID();
163 StudyContext* GetCurrentStudyContext();
164 std::string /*void */SetName( SALOMEDS::SObject_ptr theSObject,
166 const char* theDefaultName );
167 int RegisterObject(CORBA::Object_ptr theObject);
168 // SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh() throw ( SALOME::SALOME_Exception )
169 char* ComponentDataType();
172 bool CanPublishInStudy(CORBA::Object_ptr theIOR);
173 SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
174 static SALOMEDS::SObject_ptr ObjectToSObject(SALOMEDS::Study_ptr theStudy, CORBA::Object_ptr theObject);
176 SALOMEDS::SObject_ptr PublishDoc( SALOMEDS::Study_ptr theStudy,
178 const char* theName = 0);
182 Document_ptr createDoc (const char* name)
183 throw ( SALOME::SALOME_Exception );
184 Document_ptr createDocInStudy (const char* name)
185 throw ( SALOME::SALOME_Exception );
186 CORBA::Long addDocInStudy (Document_ptr doc)
187 throw ( SALOME::SALOME_Exception );
189 //-----------------------------------------------------------------------//
190 // Inherited methods from SALOMEDS::Driver //
191 //-----------------------------------------------------------------------//
194 SALOMEDS::TMPFile* Save(SALOMEDS::SComponent_ptr theComponent,
198 SALOMEDS::TMPFile* SaveASCII(SALOMEDS::SComponent_ptr theComponent,
202 CORBA::Boolean Load(SALOMEDS::SComponent_ptr theComponent,
203 const SALOMEDS::TMPFile& theStream,
207 CORBA::Boolean LoadASCII(SALOMEDS::SComponent_ptr theComponent,
208 const SALOMEDS::TMPFile& theStream,
212 void Close(SALOMEDS::SComponent_ptr theComponent);
213 // char* ComponentDataType(); Deja la
215 CORBA::Boolean CanCopy (SALOMEDS::SObject_ptr theObject);
216 CORBA::Boolean CanPaste (const char* theComponentName,
217 CORBA::Long theObjectID);
219 SALOMEDS::TMPFile* CopyFrom(SALOMEDS::SObject_ptr theObject,
220 CORBA::Long& theObjectID);
222 SALOMEDS::SObject_ptr PasteInto(const SALOMEDS::TMPFile& theStream,
223 CORBA::Long theObjectID,
224 SALOMEDS::SObject_ptr theObject);
225 SALOMEDS::SObject_ptr PublishInStudy(SALOMEDS::Study_ptr theStudy,
226 SALOMEDS::SObject_ptr theSObject,
227 CORBA::Object_ptr theObject,
228 const char* theName) throw (SALOME::SALOME_Exception) ;
231 char* IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
232 const char* IORString,
233 CORBA::Boolean isMultiFile,
234 CORBA::Boolean isASCII);
235 char* LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
236 const char* aLocalPersistentID,
237 CORBA::Boolean isMultiFile,
238 CORBA::Boolean isASCII);
243 virtual std::string GetIOR();
246 virtual SALOMEDSImpl_TMPFile* Save(const SALOMEDSImpl_SComponent& compo,
247 const std::string& theURL,
248 long& theStreamLength,
251 virtual SALOMEDSImpl_TMPFile* SaveASCII(const SALOMEDSImpl_SComponent& compo,
252 const std::string& theURL,
253 long& theStreamLength,
255 *********************/
257 virtual SALOMEDS::TMPFile* Save(SALOMEDS::SComponent_ptr theComponent,
262 virtual SALOMEDS::TMPFile* SaveASCII(SALOMEDS::SComponent_ptr theComponent,
268 virtual bool Load(const SALOMEDSImpl_SComponent& compo,
269 const unsigned char* theStream,
270 const long theStreamLength,
271 const std::string& theURL,
274 virtual bool LoadASCII(const SALOMEDSImpl_SComponent& theComponent,
275 const unsigned char* theStream,
276 const long theStreamLength,
277 const std::string& theURL,
280 virtual void Close(const SALOMEDSImpl_SComponent& theComponent);
282 // virtual std::string ComponentDataType();
284 virtual std::string IORToLocalPersistentID(const SALOMEDSImpl_SObject& theSObject,
285 const std::string& IORString,
289 virtual std::string LocalPersistentIDToIOR(const SALOMEDSImpl_SObject& theSObject,
290 const std::string& aLocalPersistentID,
294 virtual bool CanCopy(const SALOMEDSImpl_SObject& theObject);
296 virtual SALOMEDSImpl_TMPFile* CopyFrom(const SALOMEDSImpl_SObject& theObject,
298 long& theStreamLength);
300 virtual bool CanPaste(const std::string& theComponentName, int theObjectID);
302 virtual std::string PasteInto(const unsigned char* theStream,
303 const long theStreamLength,
305 const SALOMEDSImpl_SObject& theObject);
307 virtual SALOMEDSImpl_TMPFile* DumpPython(SALOMEDSImpl_Study* theStudy,
311 long& theStreamLength);
314 HEXA_NS::Hex* _engine_cpp;
315 GEOM_Client* _geomClient;
318 static PortableServer::POA_var _poa;// POA reference
319 static GEOM::GEOM_Gen_var _geomGen;
320 static SALOME_LifeCycleCORBA* _lcc;
321 static CORBA::ORB_var _orb;
322 static SALOME_NamingService* _ns;
323 static HEXABLOCK_Gen_i* _HEXABLOCKGen;
326 GEOM::GEOM_Object_ptr _makeVertex( const TopoDS_Shape& theShape );
327 GEOM::GEOM_Object_ptr _makeEdge( const TopoDS_Shape& theShape );
329 map<int, StudyContext*> myStudyContextMap; // Map of study context objects
330 SALOMEDS::Study_var myCurrentStudy; // Current study
337 PortableServer::ObjectId * HEXABLOCKEngine_factory(
339 PortableServer::POA_ptr poa,
340 PortableServer::ObjectId * contId,
341 const char *instanceName,
342 const char *interfaceName
348 DownCast(CORBA::Object_ptr theArg)
350 return dynamic_cast<T>(HEXABLOCK_Gen_i::GetServant(theArg).in());
357 TopoDS_Shape string2shape( const string& brep );
360 string shape2string( const TopoDS_Shape& aShape );
368 // 1) Séquence de code convertissant une chaîne au format BREP vers un TopoDS_Shape
370 // TopoDS_Shape STRING_TO_SHAPE( char* buf, int sizebuf )
372 // TopoDS_Shape shape;
373 // std::istrstream streamBrep(buf,sizebuf);
374 // BRep_Builder aBuilder;
375 // BRepTools::Read(shape, streamBrep, aBuilder);
379 // 2) Séquence de code convertissant un TopoDS_Shape en une chaîne au format BREP
381 // char* SHAPE_TO_STRING( TopoDS_Shape aShape, int& sizebuf )
383 // ostrstream streamShape;
384 // BRepTools::Write(aShape, streamShape);
385 // sizebuf = streamShape.pcount();
386 // char* buf = new char [sizebuf];
387 // char* valueOfStream = streamShape.str();
388 // memcpy(buf, valueOfStream, size);
392 // 3) Séquence de code accédant aux coordonnées d'un TopoDS_Shape qui est un Vertex
394 // bool SHAPE_TO_COORD(TopoDS_Shape aShape, double& x, double& y, double& z)
396 // if ( aShape.ShapeType() == TopAbs_VERTEX ) {
397 // TopoDS_Vertex aPoint;
398 // aPoint = TopoDS::Vertex( aShape );
399 // gp_Pnt aPnt = BRep_Tool::Pnt( aPoint );
409 // 4) Séquence de code créant un TopoDS_Shape à partir de coordonnées
411 // TopoDS_Shape COORD_TO_SHAPE(double x, double y, double z)
413 // gp_Pnt aPnt(x, y, z);
414 // BRepBuilderAPI_MakeVertex mkVertex (aPnt);
415 // TopoDS_Vertex aVertex = TopoDS::Vertex(mkVertex.Shape());