]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCK_I/HEXABLOCK.cxx
Salome HOME
8959a5e4245777f197ee79860f802a6c7549245d
[modules/hexablock.git] / src / HEXABLOCK_I / HEXABLOCK.cxx
1 // Copyright (C) 2009-2012  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 using namespace std;
20
21
22 static bool db = false;
23
24
25
26 // #include <Basics_Utils.hxx>
27 // 
28 // #include <TDF_Tool.hxx>
29 // #include <TDF_Data.hxx>
30 // #include <TDF_Reference.hxx>
31 // #include <TDF_LabelSequence.hxx>
32 // #include <TDataStd_Integer.hxx>
33 // #include <TDataStd_ChildNodeIterator.hxx>
34 // #include <TFunction_Driver.hxx>
35 // #include <TFunction_DriverTable.hxx>
36 // #include <TDataStd_HArray1OfByte.hxx>
37 // #include <TDataStd_ByteArray.hxx>
38 // #include <TDataStd_UAttribute.hxx>
39 // #include <TDF_ChildIterator.hxx>
40 // #include <TDataStd_Comment.hxx>
41 // #include <Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString.hxx>
42
43 ////////////
44
45
46
47
48
49
50 #include <TCollection_AsciiString.hxx>
51 #include <TopAbs_ShapeEnum.hxx>
52 #include <TopoDS.hxx>
53 #include <TopoDS_Vertex.hxx>
54 #include <TopoDS_Edge.hxx>
55 #include <TopoDS_Face.hxx>
56
57
58 #include <Geom_Curve.hxx>
59
60 #include <gp_Pnt.hxx>
61 #include <BRep_Builder.hxx>
62 #include <BRep_Tool.hxx>
63 #include <BRepTools.hxx>
64
65 #include "SALOME_NamingService.hxx"
66 #include "SALOME_LifeCycleCORBA.hxx"
67 #include "Utils_SINGLETON.hxx"
68 #include "Utils_ExceptHandlers.hxx"
69 #include "HexElements_grid.cxx"
70
71
72 #include "HEXABLOCK.hxx"
73 #include "utilities.h"
74
75 #include "HexDocument_impl.hxx"
76 #include <string>
77
78 // #include "SALOMEDS_Tool.hxx"
79 // #include "SALOMEDSImpl_TMPFile.hxx"
80
81 using namespace HEXABLOCK_ORB;
82
83
84 // Static variables definition
85 PortableServer::POA_var HEXABLOCK_Gen_i::_poa;
86 HEXABLOCK_Gen_i*        HEXABLOCK_Gen_i::_HEXABLOCKGen = NULL;
87 SALOME_LifeCycleCORBA*  HEXABLOCK_Gen_i::_lcc = NULL;
88 GEOM::GEOM_Gen_var      HEXABLOCK_Gen_i::_geomGen = GEOM::GEOM_Gen::_nil();
89 // GEOM_Client*            HEXABLOCK_Gen_i::_geomClient = NULL;
90 CORBA::ORB_var          HEXABLOCK_Gen_i::_orb;
91 SALOME_NamingService*   HEXABLOCK_Gen_i::_ns = NULL;
92
93 //=============================================================================
94 /*!
95  *  standard constructor
96  */
97 //=============================================================================
98
99 HEXABLOCK_Gen_i::HEXABLOCK_Gen_i(CORBA::ORB_ptr orb,
100         PortableServer::POA_ptr poa,
101         PortableServer::ObjectId * contId, 
102         const char *instanceName, 
103         const char *interfaceName) :
104   Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
105 {
106   MESSAGE("activate object");
107   _thisObj = this ;
108   _poa = PortableServer::POA::_duplicate(poa);
109   _orb = CORBA::ORB::_duplicate(orb);
110   _id = _poa->activate_object(_thisObj);
111   _engine_cpp = new HEXA_NS::Hex;
112   _geomClient = NULL;
113   _HEXABLOCKGen = this;
114   MESSAGE("ALRRRRRIGHTTTTT");
115 }
116
117 //=============================================================================
118 /*!
119  *  GetServant [ static ]
120  *
121  *  Get servant of the CORBA object
122  */
123 //=============================================================================
124
125 PortableServer::ServantBase_var HEXABLOCK_Gen_i::GetServant( CORBA::Object_ptr theObject )
126 {
127   if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
128     return NULL;
129   try {
130     PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
131     return aServant;
132   } 
133   catch (...) {
134     INFOS( "GetServant - Unknown exception was caught!!!" ); 
135     return NULL;
136   }
137 }
138
139
140
141 //=============================================================================
142 //  destructor
143 //=============================================================================
144 HEXABLOCK_Gen_i::~HEXABLOCK_Gen_i()
145 {
146 }
147
148
149
150
151 //=============================================================================
152 /*!
153  *  DumpPython
154  */
155 //=============================================================================
156 Engines::TMPFile* HEXABLOCK_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
157                                               CORBA::Boolean /*isPublished*/,
158                                               CORBA::Boolean /*isMultiFile*/,
159                                               CORBA::Boolean& isValidScript)
160 {
161   MESSAGE("DumpPython DumpPython DumpPython DumpPython");
162   std::cout << "DumpPython DumpPython DumpPython DumpPython" << std::endl;
163   isValidScript = true;  // to avoid dump python operation failing
164   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(0);
165   return aStreamFile._retn(); 
166 }
167 //   SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
168 //   if(CORBA::is_nil(aStudy))
169 //     return new Engines::TMPFile(0);   
170 // 
171 //   SALOMEDS::SObject_var aSO = aStudy->FindComponent(ComponentDataType());
172 //   if(CORBA::is_nil(aSO))
173 //     return new Engines::TMPFile(0);  
174 // 
175 //   TObjectData objData;
176 //   std::vector<TObjectData> objectDataVec;
177 // 
178 //   TVariablesList aVariableMap;
179 // 
180 //   SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
181 //   for(Itr->InitEx(true); Itr->More(); Itr->Next()) {
182 //     SALOMEDS::SObject_var aValue = Itr->Value();
183 //     CORBA::String_var IOR = aValue->GetIOR();
184 //     if(strlen(IOR.in()) > 0) {
185 //       CORBA::Object_var obj = _orb->string_to_object(IOR);
186 //       GEOM::GEOM_Object_var GO = GEOM::GEOM_Object::_narrow(obj);
187 //       if(!CORBA::is_nil(GO)) {
188 //         CORBA::String_var aName       = aValue->GetName();
189 //         CORBA::String_var anEntry     = GO->GetEntry();
190 //         CORBA::String_var aStudyEntry = aValue->GetID();
191 //         objData._name       = aName.in();
192 //         objData._entry      = anEntry.in();
193 //         objData._studyEntry = aStudyEntry.in();
194 //      objectDataVec.push_back( objData );
195 // 
196 //      //Find attribute with list of used notebook variables
197 //      SALOMEDS::GenericAttribute_var anAttr;
198 //      SALOMEDS::AttributeString_var anAttrStr;
199 //      if(aValue->FindAttribute(anAttr,"AttributeString")){
200 //        anAttrStr = SALOMEDS::AttributeString::_narrow(anAttr);
201 //        SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(anAttrStr->Value());
202 //        ObjectStates* aStates = new ObjectStates();
203 //        for(int i = 0; i < aSections->length(); i++) {
204 //          TState aState;
205 //          SALOMEDS::ListOfStrings aListOfVars = aSections[i];
206 //          for(int j = 0; j < aListOfVars.length(); j++) {
207 //            bool isVar = aStudy->IsVariable(aListOfVars[j].in());
208 //            TVariable aVar = TVariable( (char*)aListOfVars[j].in(), isVar );
209 //            aState.push_back(aVar);
210 //          }
211 //          aStates->AddState(aState);
212 //        }
213 //        aVariableMap.insert(std::make_pair(TCollection_AsciiString(anEntry),aStates));
214 //      }
215 //       }
216 //     }
217 //   }
218 //   
219 //   TCollection_AsciiString aScript;
220 //   aScript += _impl->DumpPython(aStudy->StudyId(), objectDataVec, aVariableMap, isPublished, isValidScript);
221 // 
222 //   if (isPublished)
223 //   {
224 //     //Output the script that sets up the visual parameters.
225 //     char* script = aStudy->GetDefaultScript(ComponentDataType(), "\t");
226 //     if (script && strlen(script) > 0) {
227 //       aScript += "\n\t### Store presentation parameters of displayed objects\n";
228 //       aScript += script;
229 //       CORBA::string_free(script);
230 //     }
231 //   }
232 // 
233 //   aScript += "\n\tpass\n";
234 // 
235 //   int aLen = aScript.Length(); 
236 //   unsigned char* aBuffer = new unsigned char[aLen+1];
237 //   strcpy((char*)aBuffer, aScript.ToCString());
238 // 
239 //   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
240 //   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1); 
241 // 
242 //   return aStreamFile._retn(); 
243 // }
244
245
246
247
248 void HEXABLOCK_Gen_i::test()
249 {
250   MESSAGE("HEEEEEEEEEEEEEEYYYYYYYYYYY");
251 }
252
253 CORBA::Long HEXABLOCK_Gen_i::countDocument()
254 {
255     CORBA::Long nbDocument = _engine_cpp->countDocument();
256 //     CORBA::Long nbDocument = 333;
257     return nbDocument;
258 }
259
260 Document_ptr HEXABLOCK_Gen_i::getDocument(CORBA::Long i)
261 {
262     HEXA_NS::Document *doc=_engine_cpp->getDocument(i);
263     if ( doc == NULL ) return Document::_nil();
264     Document_impl *servantCorba = new Document_impl( GetPOA(), doc );
265     return servantCorba->_this();
266 }
267
268 void HEXABLOCK_Gen_i::removeDocument(HEXABLOCK_ORB::Document_ptr docIn)
269 {
270   Document_impl* docServant = ::DownCast<Document_impl*>( docIn );
271   ASSERT( docServant );
272   if ( docServant ) {
273     HEXA_NS::Document* doc = docServant->GetImpl();
274     _engine_cpp->removeDocument( doc );
275   }
276 }
277
278
279 Document_ptr HEXABLOCK_Gen_i::addDocument(const char* name)
280 {
281    // HEXA_NS::Document *doc=_engine_cpp->addDocument (name);
282    // Document_impl *servantCorba=new Document_impl( GetPOA(), doc);
283    // return servantCorba->_this();
284
285    return createDocInStudy(name);
286 }
287
288
289
290 Document_ptr HEXABLOCK_Gen_i::loadDocument(const char* xmlFilename)
291 {
292     HEXA_NS::Document *doc=_engine_cpp->loadDocument(xmlFilename);
293     Document_impl *servantCorba=new Document_impl( GetPOA(), doc );
294     return servantCorba->_this();
295 }
296
297 GEOM_Client* HEXABLOCK_Gen_i::getGeomClient()
298 {
299   // create shape reader if necessary
300   if ( _geomClient == NULL ) 
301     _geomClient = new GEOM_Client(GetContainerRef());
302   ASSERT( _geomClient);
303   return _geomClient;
304 }
305
306
307 TopoDS_Shape HEXABLOCK_Gen_i::geomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
308 {
309   TopoDS_Shape S;
310   if ( !theGeomObject->_is_nil() ){
311     _geomClient = getGeomClient();
312
313     if(CORBA::is_nil(_geomGen)) {
314       Engines::EngineComponent_ptr temp=GetLCC()->FindOrLoad_Component("FactoryServer","GEOM");
315       _geomGen=GEOM::GEOM_Gen::_narrow(temp);
316     }
317     if ( _geomClient != NULL  && !_geomGen->_is_nil () )
318       S = _geomClient->GetShape( _geomGen, theGeomObject );
319   }
320   return S;
321 }
322
323
324
325
326
327 // HEXABLOCK_ORB::GEOM_Object_ptr HEXABLOCK_Gen_i::shapeToGeomObject (const TopoDS_Shape& theShape )
328 // {
329 //   HEXABLOCK_ORB::GEOM_Object_var aShapeObj;
330 //   if ( !theShape.IsNull() ) {
331 //     _geomClient = getGeomClient();//new GEOM_Client(GetContainerRef());
332 //     TCollection_AsciiString IOR;
333 //     bool found = _geomClient->Find(theShape, IOR);
334 //     if (found){
335 //       CORBA::Object_var obj = _orb->string_to_object( IOR.ToCString() );
336 //       aShapeObj = HEXABLOCK_ORB::GEOM_Object::_narrow ( obj );
337 //     }
338 //   }
339 //   return aShapeObj._retn();
340 // }
341
342
343
344 // GEOM::GEOM_Object_ptr HEXABLOCK_Gen_i::_makeFace( const TopoDS_Shape& theShape )
345 // {
346 //   ASSERT ( theShape.ShapeType() == TopAbs_FACE );
347 // 
348 //   int theStudyID = 0;
349 //   GEOM::GEOM_Object_var result; 
350 //   
351 // // PrimOp   = self.GetI3DPrimOperations 
352 // // GEOM_IShapesOperations
353 //   return result._retn();
354 // }
355
356 // GEOM::GEOM_Object_ptr HEXABLOCK_Gen_i::_makeEdge( const TopoDS_Shape& theShape )
357 // {
358 //   ASSERT ( theShape.ShapeType() == TopAbs_EDGE );
359 //   int theStudyID = 0;
360 //   GEOM::GEOM_Object_var result;
361 //   GEOM::GEOM_Object_var p1;
362 //   GEOM::GEOM_Object_var p2;
363 // 
364 //   if ( CORBA::is_nil(_geomGen) ) { //_geomGen->_is_nil() 
365 //     Engines::EngineComponent_ptr temp=GetLCC()->FindOrLoad_Component("FactoryServer","GEOM");
366 //     _geomGen=GEOM::GEOM_Gen::_narrow(temp);
367 //   }
368 //   GEOM::GEOM_IBasicOperations_var     aBasicOp  = _geomGen->GetIBasicOperations(theStudyID);
369 //   GEOM::GEOM_IShapesOperations_var    aShapesOp = _geomGen->GetIShapesOperations(theStudyID);
370 // 
371 //   TopoDS_Edge anEdge = TopoDS::Edge( theShape );
372 //   double f, l;
373 //   Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, f, l);
374 // 
375 //   gp_Pnt aCurveStart = aCurve->Value( f );
376 //   gp_Pnt aCurveEnd   = aCurve->Value( l );
377 // 
378 //   double x1, y1, z1;
379 //   double x2, y2, z2;
380 // 
381 //   x1 = aCurveStart.X(); y1 = aCurveStart.Y(); z1 = aCurveStart.Z();
382 //   x2 = aCurveEnd.X();   y2 = aCurveEnd.Y(); z2 = aCurveEnd.Z();
383 //   p1= aBasicOp->MakePointXYZ(x1, y1, z1);
384 //   p2= aBasicOp->MakePointXYZ(x2, y2, z2);
385 //   result = aShapesOp->MakeEdge(p1, p2);
386 // 
387 //   return result._retn();
388 // }
389
390 // GEOM::GEOM_Object_ptr HEXABLOCK_Gen_i::_makeVertex( const TopoDS_Shape& theShape )
391 // {
392 //   ASSERT ( theShape.ShapeType() == TopAbs_VERTEX );
393 // 
394 //   int theStudyID = 0;
395 //   GEOM::GEOM_Object_var result;
396 // 
397 //   TopoDS_Vertex aPoint;
398 //   aPoint      = TopoDS::Vertex( theShape );
399 //   gp_Pnt aPnt = BRep_Tool::Pnt( aPoint );
400 //   double x = aPnt.X();
401 //   double y = aPnt.Y();
402 //   double z = aPnt.Z();
403 // 
404 //   GEOM::GEOM_IBasicOperations_var aBasicOp = _geomGen->GetIBasicOperations(theStudyID);
405 //   result = aBasicOp->MakePointXYZ(x, y, z);
406 // 
407 //   return result._retn();
408 // }
409
410
411 // GEOM::GEOM_Object_ptr HEXABLOCK_Gen_i::shapeToGeomObject (const TopoDS_Shape& theShape )
412 // {
413 //   std::cout << "XXXXXXXX shapeToGeomObject "<< std::endl;
414 //   GEOM::GEOM_Object_var aShapeObj;
415 //   if ( !theShape.IsNull() ) {
416 //     switch ( theShape.ShapeType() ){
417 //       case TopAbs_VERTEX: aShapeObj = _makeVertex( theShape ); break;
418 // //       case TopAbs_FACE:   aShapeObj = _makeFace( theShape ); break; //CS_TODO
419 //       case TopAbs_EDGE:   aShapeObj = _makeEdge( theShape ); break;
420 //       default: throw (SALOME_Exception(LOCALIZED("shapeToGeomObject : shape type not supported")));
421 //     }
422 //   }
423 //   return aShapeObj._retn();
424 // }
425
426
427
428
429 GEOM::GEOM_Object_ptr HEXABLOCK_Gen_i::brepToGeomObject(const std::string& theBrep)
430 {
431   int theStudyID = 0; //CS_TODO
432   GEOM::GEOM_Object_var aShapeObj;
433
434   if ( CORBA::is_nil(_geomGen) ){
435     Engines::EngineComponent_ptr temp=GetLCC()->FindOrLoad_Component("FactoryServer","GEOM");
436     _geomGen=GEOM::GEOM_Gen::_narrow(temp);
437   }
438   GEOM::GEOM_IInsertOperations_var aInsOp = _geomGen->GetIInsertOperations(theStudyID);
439
440   // char *tmpname = strdup("HexaAssocXXXXXX");   // killed by Abu 
441   char tmpname [32];                              // Abu 11/07
442   sprintf (tmpname, "/tmp/tmpHexaAsso%dXXXXXX", getpid()); // Abu 11/07
443   // strcpy (tmpname, "HexaAssocXXXXXX");   // killed by Abu 
444
445   int fd = mkstemp( tmpname );
446   if ( fd != -1 )
447      {
448      ofstream tmpfile( tmpname );
449      tmpfile << theBrep;
450      tmpfile.close();
451      aShapeObj = aInsOp->ImportFile( tmpname, "BREP" );
452      close(fd);
453      unlink(tmpname);
454      }
455
456   return aShapeObj._retn();
457 }
458
459
460
461
462
463
464 // GEOM::GEOM_Object_ptr HEXABLOCK_Gen_i::shapeToGeomObject (const TopoDS_Shape& theShape )
465 // {
466 //   GEOM::GEOM_Object_var aShapeObj;
467 //   std::cout<<"shapeToGeomObject "<<std::endl;
468 //   if ( !theShape.IsNull() ) {
469 //     std::cout<<"shapeToGeomObject !theShape.IsNull()"<<std::endl;
470 //     _geomClient = getGeomClient();//new GEOM_Client(GetContainerRef());
471 //     TCollection_AsciiString IOR;
472 //     bool found = _geomClient->Find(theShape, IOR);
473 //     std::cout<<"shapeToGeomObject found"<<found<<std::endl;
474 //     if (found){
475 //       CORBA::Object_var obj = _orb->string_to_object( IOR.ToCString() );
476 //       aShapeObj = GEOM::GEOM_Object::_narrow ( obj );
477 //     }
478 //   }
479 //   return aShapeObj._retn();
480 // }
481
482
483 StudyContext* HEXABLOCK_Gen_i::GetCurrentStudyContext()
484 {
485   if ( !CORBA::is_nil( myCurrentStudy ) &&
486       myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
487     return myStudyContextMap[ myCurrentStudy->StudyId() ];
488   else
489     return 0;
490 }
491
492 int HEXABLOCK_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
493 {
494   StudyContext* myStudyContext = GetCurrentStudyContext();
495   if ( myStudyContext && !CORBA::is_nil( theObject )) {
496     CORBA::String_var iorString = GetORB()->object_to_string( theObject );
497     return myStudyContext->addObject( string( iorString.in() ) );
498   }
499   return 0;
500 }
501
502
503 // SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
504 //      throw ( SALOME::SALOME_Exception )
505
506
507 char* HEXABLOCK_Gen_i::ComponentDataType()
508 {
509 //   if(MYDEBUG) MESSAGE( "HEXABLOCK_Gen_i::ComponentDataType" );
510   return CORBA::string_dup( "HEXABLOCK" );
511 }
512
513
514
515 // SMESH_Mesh* SMESH_Gen::CreateMesh(int theStudyId, bool theIsEmbeddedMode)
516 //   throw(SALOME_Exception)
517 // {
518 //   Unexpect aCatch(SalomeException);
519 //   MESSAGE("SMESH_Gen::CreateMesh");
520 // 
521 //   // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
522 //   StudyContextStruct *aStudyContext = GetStudyContext(theStudyId);
523 // 
524 //   // create a new SMESH_mesh object
525 //   SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
526 //                                      theStudyId,
527 //                                      this,
528 //                                      theIsEmbeddedMode,
529 //                                      aStudyContext->myDocument);
530 //   aStudyContext->mapMesh[_localId] = aMesh;
531 // 
532 //   return aMesh;
533 // }
534
535
536
537
538 Document_ptr HEXABLOCK_Gen_i::createDoc (const char* name)
539                               throw ( SALOME::SALOME_Exception )
540 {
541   Unexpect aCatch(SALOME_SalomeException);
542 //   if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
543
544   // Get or create the GEOM_Client instance
545   try {
546     HEXA_NS::Document *d   = _engine_cpp->addDocument (name);
547     Document_impl *docImpl = new Document_impl( GetPOA(), d );
548
549     // activate the CORBA servant of Mesh
550     Document_var docServant = Document::_narrow( docImpl->_this() );
551     /* int nextId = */    RegisterObject( docServant );
552 //     if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId);
553     return docServant._retn();
554   }
555   catch (SALOME_Exception& S_ex) {
556 //     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
557   }
558   return Document::_nil();
559 }
560
561 Document_ptr HEXABLOCK_Gen_i::createDocInStudy (const char* name)
562                               throw ( SALOME::SALOME_Exception )
563 {
564   Unexpect aCatch(SALOME_SalomeException);
565 //   if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
566   // create mesh
567   Document_var doc = this->createDoc (name);
568
569   // publish mesh in the study
570   if ( CanPublishInStudy( doc ) ) {
571     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
572     aStudyBuilder->NewCommand();  // There is a transaction
573     SALOMEDS::SObject_var aSO = PublishDoc( myCurrentStudy, doc.in() );
574     aStudyBuilder->CommitCommand();
575 //     if ( !aSO->_is_nil() ) {
576 //       // Update Python script
577 //       TPythonDump() << aSO << " = " << this << ".CreateEmptyMesh()";
578 //     }
579   }
580
581   return doc._retn();
582 }
583
584
585
586
587 SALOME_LifeCycleCORBA*  HEXABLOCK_Gen_i::GetLCC() {
588   if ( _lcc == NULL ) {
589     _lcc = new SALOME_LifeCycleCORBA( GetNS() );
590   }
591   return _lcc;
592 }
593
594 SALOME_NamingService* HEXABLOCK_Gen_i::GetNS()
595 {
596   if ( _ns == NULL ) {
597     _ns = SINGLETON_<SALOME_NamingService>::Instance();
598     ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
599     _ns->init_orb( _orb );
600   }
601   return _ns;
602 }
603
604
605
606 int HEXABLOCK_Gen_i::GetCurrentStudyID()
607 {
608   return myCurrentStudy->_is_nil() || myCurrentStudy->_non_existent() ? -1 : myCurrentStudy->StudyId();
609 }
610
611
612 void HEXABLOCK_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
613 {
614   /*int curStudyId = */     GetCurrentStudyID();
615   myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
616   // create study context, if it doesn't exist and set current study
617   int studyId = GetCurrentStudyID();
618   if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) {
619     myStudyContextMap[ studyId ] = new StudyContext;
620   }
621
622 //   // myCurrentStudy may be nil
623 //   if ( !CORBA::is_nil( myCurrentStudy ) ) {
624 //     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
625 //     if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
626 //       aStudyBuilder->LoadWith( myCurrentStudy->FindComponent( "GEOM" ), GetGeomEngine() );
627 // 
628 //     // NPAL16168, issue 0020210
629 //     // Let meshes update their data depending on GEOM groups that could change
630 //     if ( curStudyId != studyId )
631 //     {
632 //       //SALOMEDS::SComponent_var me =  PublishComponent( myCurrentStudy );
633 //       SALOMEDS::SComponent_var me = SALOMEDS::SComponent::_narrow
634 //         ( myCurrentStudy->FindComponent( ComponentDataType() ) );
635 //       if ( !me->_is_nil() ) {
636 //         SALOMEDS::ChildIterator_var anIter = myCurrentStudy->NewChildIterator( me );
637 //         for ( ; anIter->More(); anIter->Next() ) {
638 //           SALOMEDS::SObject_var so = anIter->Value();
639 //           CORBA::Object_var    ior = SObjectToObject( so );
640 //           if ( SMESH_Mesh_i*  mesh = SMESH::DownCast<SMESH_Mesh_i*>( ior ))
641 //             mesh->CheckGeomGroupModif();
642 //         }
643 //       }
644 //     }
645 //   }
646 }
647
648
649
650
651
652
653 TopoDS_Shape string2shape( const string& brep )
654 {
655   TopoDS_Shape shape;
656
657 //   istringstream streamBrep(brep.c_str());
658   istringstream streamBrep(brep);
659 //   char* chaine = new char[brep.size()];
660 //   strcpy(chaine, brep.c_str()); 
661 //   istringstream streamBrep( chaine );
662
663   BRep_Builder aBuilder;
664   BRepTools::Read(shape, streamBrep, aBuilder);
665 //   BRepTools::Read(shape, brep, aBuilder);
666   return shape;
667 }
668
669 // TopoDS_Shape STRING_TO_SHAPE( char* buf, int sizebuf )
670 // {
671 //   TopoDS_Shape shape;
672 //   std::istrstream streamBrep(buf,sizebuf);
673 //   BRep_Builder aBuilder;
674 //   BRepTools::Read(shape, streamBrep, aBuilder);
675 //   return(shape);
676 // }
677
678 // ===================================================== shape2string
679 string shape2string( const TopoDS_Shape& aShape )
680 {
681   ostringstream streamShape;
682 //   string  strShape;
683   BRepTools::Write(aShape, streamShape);
684 //   BRepTools::Write(aShape, strShape);
685
686   return streamShape.str();
687 }
688 // ===================================================== HEXABLOCKEngine_factory
689 extern "C"
690 {
691   PortableServer::ObjectId * HEXABLOCKEngine_factory(
692                                CORBA::ORB_ptr orb,
693                                PortableServer::POA_ptr poa, 
694                                PortableServer::ObjectId * contId,
695                                const char *instanceName, 
696                                const char *interfaceName)
697   {
698     MESSAGE("PortableServer::ObjectId * HEXABLOCKEngine_factory()");
699     SCRUTE(interfaceName);
700     HEXABLOCK_Gen_i *myHEXABLOCK 
701       = new HEXABLOCK_Gen_i(orb, poa, contId, instanceName, interfaceName);
702     return myHEXABLOCK->getId() ;
703   }
704 }
705 // ------------------------------------------------------------------------
706 // 
707 //                 Heritage de  SALOMEDSImpl_Driver
708 //
709 // ------------------------------------------------------------------------
710 //
711 /* ***********************************************************************
712 // ========================================================= GetIOR
713 std::string HEXABLOCK_Gen_i::GetIOR()
714 {
715    return "";
716 }
717    *********************************************************************** */
718 // =========================================================== SaveASCII
719 SALOMEDS::TMPFile* HEXABLOCK_Gen_i::SaveASCII (
720                                           const SALOMEDS::SComponent_ptr compo,
721                                           const char* theURL,
722                                           bool isMultiFile)
723 {
724    SALOMEDS::TMPFile* fic =  Save (compo, theURL, isMultiFile);
725    return fic;
726 }
727 // =========================================================== LoadASCII
728 CORBA::Boolean HEXABLOCK_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr compo,
729                            const SALOMEDS::TMPFile& theStream,
730                            const char* theURL,
731                            bool isMultiFile)
732 {
733    bool rep = Load (compo, theStream, theURL, isMultiFile);
734    return rep;
735 }
736 // =========================================================== Close
737 void HEXABLOCK_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
738 {
739    if (db) cout << " +++++++ Je suis passe par  HEXABLOCK_Gen_i::"
740         << "Close" << endl;
741 }
742 // =================================================== IORToLocalPersistentID
743 char* HEXABLOCK_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
744                                const char* IORString,
745                                CORBA::Boolean isMultiFile,
746                                CORBA::Boolean isASCII)
747 {
748    if (db) cout << " +++++++ Je suis passe par  HEXABLOCK_Gen_i::"
749         << "IORToLocalPersistentID" << endl;
750    static char empty [8] = "";
751    return empty;
752 }
753 // =================================================== LocalPersistentIDToIOR
754 char* HEXABLOCK_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
755                                const char* aLocalPersistentID,
756                                CORBA::Boolean isMultiFile,
757                                CORBA::Boolean isASCII)
758 {
759    if (db) cout << " +++++++ Je suis passe par  HEXABLOCK_Gen_i::"
760         << "LocalPersistentIDToIOR" << endl;
761    static char empty [8] = "";
762    return empty;
763 }
764 //   
765 // =========================================================== CanCopy
766 CORBA::Boolean HEXABLOCK_Gen_i::CanCopy (SALOMEDS::SObject_ptr theObject)
767 {
768    if (db) cout << " +++++++ Je suis passe par  HEXABLOCK_Gen_i::"
769         << "CanCopy" << endl;
770    return false;
771 }
772 // =========================================================== CopyFrom
773 SALOMEDS::TMPFile* HEXABLOCK_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, 
774                                              CORBA::Long& theObjectID)
775 {
776    if (db) cout << " +++++++ Je suis passe par  HEXABLOCK_Gen_i::"
777         << "CopyFrom" << endl;
778    return NULL;
779 }
780 // =========================================================== CanPaste
781 CORBA::Boolean HEXABLOCK_Gen_i:: CanPaste (const char* theComponentName, 
782                                            CORBA::Long theObjectID)
783 {
784    if (db) cout << " +++++++ Je suis passe par  HEXABLOCK_Gen_i::"
785         << "CanPaste" << endl;
786    return false;
787 }
788 // =========================================================== PasteInto
789 SALOMEDS::SObject_ptr HEXABLOCK_Gen_i::PasteInto(const SALOMEDS::TMPFile& fic,
790                                   CORBA::Long theObjectID,
791                                   SALOMEDS::SObject_ptr theObject)
792 {
793    if (db) cout << " +++++++ Je suis passe par  HEXABLOCK_Gen_i::"
794         << "PasteInto" << endl;
795    return NULL;
796 }
797 // ======================================================== CanPublishInStudy
798 // bool HEXABLOCK_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
799 // {
800    // return NULL;
801 // }
802 // =========================================================== CanPaste
803 SALOMEDS::SObject_ptr HEXABLOCK_Gen_i::PublishInStudy (SALOMEDS::Study_ptr stud,
804                                        SALOMEDS::SObject_ptr theSObject,
805                                        CORBA::Object_ptr theObject,
806                                        const char* theName) 
807         throw (SALOME::SALOME_Exception) 
808 {
809    if (db) cout << " +++++++ Je suis passe par  HEXABLOCK_Gen_i::"
810         << "PublishInStudy" << endl;
811    return NULL;
812 }
813 // =========================================================== Save
814 SALOMEDS::TMPFile* HEXABLOCK_Gen_i::Save( 
815                                      const SALOMEDS::SComponent_ptr compo,
816                                      const char* theURL,
817                                      bool isMultiFile)
818 {
819    if (db) cout << " +++++++ Je suis passe par  HEXABLOCK_Gen_i::"
820         << "Save" << endl;
821    return NULL;
822 }
823 // =========================================================== Load
824 CORBA::Boolean HEXABLOCK_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
825                       const SALOMEDS::TMPFile& theStream,
826                       const char* theURL,
827                       bool isMultiFile)
828 {
829    if (db) cout << " +++++++ Je suis passe par  HEXABLOCK_Gen_i::"
830         << "Load" << endl;
831
832    return false;
833 }