1 // Copyright (C) 2009-2012 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
22 static bool db = false;
24 // #include <Basics_Utils.hxx>
26 // #include <TDF_Tool.hxx>
27 // #include <TDF_Data.hxx>
28 // #include <TDF_Reference.hxx>
29 // #include <TDF_LabelSequence.hxx>
30 // #include <TDataStd_Integer.hxx>
31 // #include <TDataStd_ChildNodeIterator.hxx>
32 // #include <TFunction_Driver.hxx>
33 // #include <TFunction_DriverTable.hxx>
34 // #include <TDataStd_HArray1OfByte.hxx>
35 // #include <TDataStd_ByteArray.hxx>
36 // #include <TDataStd_UAttribute.hxx>
37 // #include <TDF_ChildIterator.hxx>
38 // #include <TDataStd_Comment.hxx>
39 // #include <Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString.hxx>
43 #include <TCollection_AsciiString.hxx>
44 #include <TopAbs_ShapeEnum.hxx>
46 #include <TopoDS_Vertex.hxx>
47 #include <TopoDS_Edge.hxx>
48 #include <TopoDS_Face.hxx>
51 #include <Geom_Curve.hxx>
54 #include <BRep_Builder.hxx>
55 #include <BRep_Tool.hxx>
56 #include <BRepTools.hxx>
58 #include "SALOME_NamingService.hxx"
59 #include "SALOME_LifeCycleCORBA.hxx"
60 #include "Utils_SINGLETON.hxx"
61 #include "Utils_ExceptHandlers.hxx"
62 #include "HexElements_grid.cxx"
65 #include "HEXABLOCK.hxx"
66 #include "HEXABLOCK_version.h"
67 #include "utilities.h"
69 #include "HexDocument_impl.hxx"
72 #include "SALOMEDS_Tool.hxx"
73 // #include "SALOMEDSImpl_TMPFile.hxx"
75 using namespace HEXABLOCK_ORB;
78 // Static variables definition
79 PortableServer::POA_var HEXABLOCK_Gen_i::_poa;
80 HEXABLOCK_Gen_i* HEXABLOCK_Gen_i::_HEXABLOCKGen = NULL;
81 SALOME_LifeCycleCORBA* HEXABLOCK_Gen_i::_lcc = NULL;
82 GEOM::GEOM_Gen_var HEXABLOCK_Gen_i::_geomGen = GEOM::GEOM_Gen::_nil();
83 // GEOM_Client* HEXABLOCK_Gen_i::_geomClient = NULL;
84 CORBA::ORB_var HEXABLOCK_Gen_i::_orb;
85 SALOME_NamingService* HEXABLOCK_Gen_i::_ns = NULL;
87 //=============================================================================
89 * standard constructor
91 //=============================================================================
93 HEXABLOCK_Gen_i::HEXABLOCK_Gen_i(CORBA::ORB_ptr orb,
94 PortableServer::POA_ptr poa,
95 PortableServer::ObjectId * contId,
96 const char *instanceName,
97 const char *interfaceName) :
98 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
101 _poa = PortableServer::POA::_duplicate(poa);
102 _orb = CORBA::ORB::_duplicate(orb);
103 _id = _poa->activate_object(_thisObj);
104 //_engine_cpp = new HEXA_NS::Hex;
105 _engine_cpp = HEXA_NS::Hex::getInstance ();
107 _HEXABLOCKGen = this;
110 //=============================================================================
112 * GetServant [ static ]
114 * Get servant of the CORBA object
116 //=============================================================================
118 PortableServer::ServantBase_var HEXABLOCK_Gen_i::GetServant( CORBA::Object_ptr theObject )
120 if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
123 PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
127 INFOS( "GetServant - Unknown exception was caught!!!" );
134 //=============================================================================
136 //=============================================================================
137 HEXABLOCK_Gen_i::~HEXABLOCK_Gen_i()
141 //=============================================================================
145 //=============================================================================
146 Engines::TMPFile* HEXABLOCK_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
147 CORBA::Boolean /*isPublished*/,
148 CORBA::Boolean /*isMultiFile*/,
149 CORBA::Boolean& isValidScript)
151 std::cout << "DumpPython DumpPython DumpPython DumpPython" << std::endl;
152 isValidScript = true; // to avoid dump python operation failing
153 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(0);
154 return aStreamFile._retn();
156 // SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
157 // if(CORBA::is_nil(aStudy))
158 // return new Engines::TMPFile(0);
160 // SALOMEDS::SObject_var aSO = aStudy->FindComponent(ComponentDataType());
161 // if(CORBA::is_nil(aSO))
162 // return new Engines::TMPFile(0);
164 // TObjectData objData;
165 // std::vector<TObjectData> objectDataVec;
167 // TVariablesList aVariableMap;
169 // SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
170 // for(Itr->InitEx(true); Itr->More(); Itr->Next()) {
171 // SALOMEDS::SObject_var aValue = Itr->Value();
172 // CORBA::String_var IOR = aValue->GetIOR();
173 // if(strlen(IOR.in()) > 0) {
174 // CORBA::Object_var obj = _orb->string_to_object(IOR);
175 // GEOM::GEOM_Object_var GO = GEOM::GEOM_Object::_narrow(obj);
176 // if(!CORBA::is_nil(GO)) {
177 // CORBA::String_var aName = aValue->GetName();
178 // CORBA::String_var anEntry = GO->GetEntry();
179 // CORBA::String_var aStudyEntry = aValue->GetID();
180 // objData._name = aName.in();
181 // objData._entry = anEntry.in();
182 // objData._studyEntry = aStudyEntry.in();
183 // objectDataVec.push_back( objData );
185 // //Find attribute with list of used notebook variables
186 // SALOMEDS::GenericAttribute_var anAttr;
187 // SALOMEDS::AttributeString_var anAttrStr;
188 // if(aValue->FindAttribute(anAttr,"AttributeString")){
189 // anAttrStr = SALOMEDS::AttributeString::_narrow(anAttr);
190 // SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(anAttrStr->Value());
191 // ObjectStates* aStates = new ObjectStates();
192 // for(int i = 0; i < aSections->length(); i++) {
194 // SALOMEDS::ListOfStrings aListOfVars = aSections[i];
195 // for(int j = 0; j < aListOfVars.length(); j++) {
196 // bool isVar = aStudy->IsVariable(aListOfVars[j].in());
197 // TVariable aVar = TVariable( (char*)aListOfVars[j].in(), isVar );
198 // aState.push_back(aVar);
200 // aStates->AddState(aState);
202 // aVariableMap.insert(std::make_pair(TCollection_AsciiString(anEntry),aStates));
208 // TCollection_AsciiString aScript;
209 // aScript += _impl->DumpPython(aStudy->StudyId(), objectDataVec, aVariableMap, isPublished, isValidScript);
213 // //Output the script that sets up the visual parameters.
214 // char* script = aStudy->GetDefaultScript(ComponentDataType(), "\t");
215 // if (script && strlen(script) > 0) {
216 // aScript += "\n\t### Store presentation parameters of displayed objects\n";
217 // aScript += script;
218 // CORBA::string_free(script);
222 // aScript += "\n\tpass\n";
224 // int aLen = aScript.Length();
225 // unsigned char* aBuffer = new unsigned char[aLen+1];
226 // strcpy((char*)aBuffer, aScript.ToCString());
228 // CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
229 // Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
231 // return aStreamFile._retn();
237 void HEXABLOCK_Gen_i::test()
241 CORBA::Long HEXABLOCK_Gen_i::countDocument()
243 CORBA::Long nbDocument = _engine_cpp->countDocument();
244 // CORBA::Long nbDocument = 333;
248 Document_ptr HEXABLOCK_Gen_i::getDocument(CORBA::Long i)
250 HEXA_NS::Document *doc=_engine_cpp->getDocument(i);
252 return Document::_nil();
254 Document_impl *servantCorba = new Document_impl( GetPOA(), doc );
255 return servantCorba->_this();
258 void HEXABLOCK_Gen_i::removeDocument(HEXABLOCK_ORB::Document_ptr docIn)
260 Document_impl* docServant = ::DownCast<Document_impl*>( docIn );
261 ASSERT( docServant );
263 HEXA_NS::Document* doc = docServant->GetImpl();
264 _engine_cpp->removeDocument( doc );
268 Document_ptr HEXABLOCK_Gen_i::findDocument(const char* name)
270 HEXA_NS::Document *doc=_engine_cpp->findDocument (name);
273 return Document::_nil();
275 Document_impl *servantCorba=new Document_impl( GetPOA(), doc);
276 return servantCorba->_this();
279 Document_ptr HEXABLOCK_Gen_i::addDocument(const char* name)
281 // HEXA_NS::Document *doc=_engine_cpp->addDocument (name);
282 // Document_impl *servantCorba=new Document_impl( GetPOA(), doc);
283 // return servantCorba->_this();
285 return createDocInStudy(name);
290 Document_ptr HEXABLOCK_Gen_i::loadDocument(const char* xmlFilename)
292 HEXA_NS::Document *doc=_engine_cpp->loadDocument(xmlFilename);
293 Document_impl *servantCorba=new Document_impl( GetPOA(), doc );
294 return servantCorba->_this();
297 GEOM_Client* HEXABLOCK_Gen_i::getGeomClient()
299 // create shape reader if necessary
300 if ( _geomClient == NULL )
301 _geomClient = new GEOM_Client(GetContainerRef());
302 ASSERT( _geomClient);
307 TopoDS_Shape HEXABLOCK_Gen_i::geomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
310 if ( !theGeomObject->_is_nil() ){
311 _geomClient = getGeomClient();
313 if(CORBA::is_nil(_geomGen)) {
314 Engines::EngineComponent_ptr temp=GetLCC()->FindOrLoad_Component("FactoryServer","GEOM");
315 _geomGen=GEOM::GEOM_Gen::_narrow(temp);
317 if ( _geomClient != NULL && !_geomGen->_is_nil () )
318 S = _geomClient->GetShape( _geomGen, theGeomObject );
327 // HEXABLOCK_ORB::GEOM_Object_ptr HEXABLOCK_Gen_i::shapeToGeomObject (const TopoDS_Shape& theShape )
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);
335 // CORBA::Object_var obj = _orb->string_to_object( IOR.ToCString() );
336 // aShapeObj = HEXABLOCK_ORB::GEOM_Object::_narrow ( obj );
339 // return aShapeObj._retn();
344 // GEOM::GEOM_Object_ptr HEXABLOCK_Gen_i::_makeFace( const TopoDS_Shape& theShape )
346 // ASSERT ( theShape.ShapeType() == TopAbs_FACE );
348 // int theStudyID = 0;
349 // GEOM::GEOM_Object_var result;
351 // // PrimOp = self.GetI3DPrimOperations
352 // // GEOM_IShapesOperations
353 // return result._retn();
356 // GEOM::GEOM_Object_ptr HEXABLOCK_Gen_i::_makeEdge( const TopoDS_Shape& theShape )
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;
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);
368 // GEOM::GEOM_IBasicOperations_var aBasicOp = _geomGen->GetIBasicOperations(theStudyID);
369 // GEOM::GEOM_IShapesOperations_var aShapesOp = _geomGen->GetIShapesOperations(theStudyID);
371 // TopoDS_Edge anEdge = TopoDS::Edge( theShape );
373 // Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, f, l);
375 // gp_Pnt aCurveStart = aCurve->Value( f );
376 // gp_Pnt aCurveEnd = aCurve->Value( l );
378 // double x1, y1, z1;
379 // double x2, y2, z2;
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);
387 // return result._retn();
390 // GEOM::GEOM_Object_ptr HEXABLOCK_Gen_i::_makeVertex( const TopoDS_Shape& theShape )
392 // ASSERT ( theShape.ShapeType() == TopAbs_VERTEX );
394 // int theStudyID = 0;
395 // GEOM::GEOM_Object_var result;
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();
404 // GEOM::GEOM_IBasicOperations_var aBasicOp = _geomGen->GetIBasicOperations(theStudyID);
405 // result = aBasicOp->MakePointXYZ(x, y, z);
407 // return result._retn();
411 // GEOM::GEOM_Object_ptr HEXABLOCK_Gen_i::shapeToGeomObject (const TopoDS_Shape& theShape )
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")));
423 // return aShapeObj._retn();
429 GEOM::GEOM_Object_ptr HEXABLOCK_Gen_i::brepToGeomObject(const std::string& theBrep)
431 int theStudyID = 0; //CS_TODO
432 GEOM::GEOM_Object_var aShapeObj;
434 if ( CORBA::is_nil(_geomGen) ){
435 Engines::EngineComponent_ptr temp=GetLCC()->FindOrLoad_Component("FactoryServer","GEOM");
436 _geomGen=GEOM::GEOM_Gen::_narrow(temp);
438 GEOM::GEOM_IInsertOperations_var aInsOp = _geomGen->GetIInsertOperations(theStudyID);
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
445 int fd = mkstemp( tmpname );
448 ofstream tmpfile( tmpname );
451 aShapeObj = aInsOp->ImportFile( tmpname, "BREP" );
456 return aShapeObj._retn();
464 // GEOM::GEOM_Object_ptr HEXABLOCK_Gen_i::shapeToGeomObject (const TopoDS_Shape& theShape )
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;
475 // CORBA::Object_var obj = _orb->string_to_object( IOR.ToCString() );
476 // aShapeObj = GEOM::GEOM_Object::_narrow ( obj );
479 // return aShapeObj._retn();
483 StudyContext* HEXABLOCK_Gen_i::GetCurrentStudyContext()
485 if ( !CORBA::is_nil( myCurrentStudy ) &&
486 myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
487 return myStudyContextMap[ myCurrentStudy->StudyId() ];
492 int HEXABLOCK_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
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() ) );
503 char* HEXABLOCK_Gen_i::ComponentDataType()
505 return CORBA::string_dup( "HEXABLOCK" );
509 Document_ptr HEXABLOCK_Gen_i::createDoc (const char* name)
510 throw ( SALOME::SALOME_Exception )
512 Unexpect aCatch(SALOME_SalomeException);
514 // Get or create the GEOM_Client instance
516 HEXA_NS::Document *doc = NULL;
517 doc = _engine_cpp->addDocument (name);
518 Document_impl *docImpl = new Document_impl( GetPOA(), doc );
520 // activate the CORBA servant of Mesh
521 Document_var docServant = Document::_narrow( docImpl->_this() );
522 /* int nextId = */ RegisterObject( docServant );
524 return docServant._retn();
526 catch (SALOME_Exception& S_ex) {
528 return Document::_nil();
531 Document_ptr HEXABLOCK_Gen_i::createDocInStudy (const char* name)
532 throw ( SALOME::SALOME_Exception )
534 Unexpect aCatch(SALOME_SalomeException);
536 Document_var doc = this->createDoc (name);
538 // publish mesh in the study
539 if ( CanPublishInStudy( doc ) ) {
540 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
541 aStudyBuilder->NewCommand(); // There is a transaction
542 SALOMEDS::SObject_var aSO = PublishDoc( myCurrentStudy, doc.in() );
543 aStudyBuilder->CommitCommand();
552 SALOME_LifeCycleCORBA* HEXABLOCK_Gen_i::GetLCC() {
553 if ( _lcc == NULL ) {
554 _lcc = new SALOME_LifeCycleCORBA( GetNS() );
559 SALOME_NamingService* HEXABLOCK_Gen_i::GetNS()
562 _ns = SINGLETON_<SALOME_NamingService>::Instance();
563 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
564 _ns->init_orb( _orb );
571 int HEXABLOCK_Gen_i::GetCurrentStudyID()
573 return myCurrentStudy->_is_nil() || myCurrentStudy->_non_existent() ? -1 : myCurrentStudy->StudyId();
577 void HEXABLOCK_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
579 /*int curStudyId = */ GetCurrentStudyID();
580 myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
581 // create study context, if it doesn't exist and set current study
582 int studyId = GetCurrentStudyID();
583 if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) {
584 myStudyContextMap[ studyId ] = new StudyContext;
587 // // myCurrentStudy may be nil
588 // if ( !CORBA::is_nil( myCurrentStudy ) ) {
589 // SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
590 // if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
591 // aStudyBuilder->LoadWith( myCurrentStudy->FindComponent( "GEOM" ), GetGeomEngine() );
593 // // NPAL16168, issue 0020210
594 // // Let meshes update their data depending on GEOM groups that could change
595 // if ( curStudyId != studyId )
597 // //SALOMEDS::SComponent_var me = PublishComponent( myCurrentStudy );
598 // SALOMEDS::SComponent_var me = SALOMEDS::SComponent::_narrow
599 // ( myCurrentStudy->FindComponent( ComponentDataType() ) );
600 // if ( !me->_is_nil() ) {
601 // SALOMEDS::ChildIterator_var anIter = myCurrentStudy->NewChildIterator( me );
602 // for ( ; anIter->More(); anIter->Next() ) {
603 // SALOMEDS::SObject_var so = anIter->Value();
604 // CORBA::Object_var ior = SObjectToObject( so );
605 // if ( SMESH_Mesh_i* mesh = SMESH::DownCast<SMESH_Mesh_i*>( ior ))
606 // mesh->CheckGeomGroupModif();
614 TopoDS_Shape string2shape( const string& brep )
618 istringstream streamBrep(brep);
620 BRep_Builder aBuilder;
621 BRepTools::Read(shape, streamBrep, aBuilder);
625 // TopoDS_Shape STRING_TO_SHAPE( char* buf, int sizebuf )
627 // TopoDS_Shape shape;
628 // std::istrstream streamBrep(buf,sizebuf);
629 // BRep_Builder aBuilder;
630 // BRepTools::Read(shape, streamBrep, aBuilder);
634 // ===================================================== shape2string
635 string shape2string( const TopoDS_Shape& aShape )
637 ostringstream streamShape;
638 BRepTools::Write(aShape, streamShape);
640 return streamShape.str();
642 // ===================================================== HEXABLOCKEngine_factory
645 PortableServer::ObjectId * HEXABLOCKEngine_factory(
647 PortableServer::POA_ptr poa,
648 PortableServer::ObjectId * contId,
649 const char *instanceName,
650 const char *interfaceName)
652 SCRUTE(interfaceName);
653 HEXABLOCK_Gen_i *myHEXABLOCK
654 = new HEXABLOCK_Gen_i(orb, poa, contId, instanceName, interfaceName);
655 return myHEXABLOCK->getId() ;
658 // ------------------------------------------------------------------------
660 // Heritage de SALOMEDSImpl_Driver
662 // ------------------------------------------------------------------------
664 /* ***********************************************************************
665 // ========================================================= GetIOR
666 std::string HEXABLOCK_Gen_i::GetIOR()
670 *********************************************************************** */
671 // =========================================================== SaveASCII
672 SALOMEDS::TMPFile* HEXABLOCK_Gen_i::SaveASCII (
673 const SALOMEDS::SComponent_ptr compo,
677 SALOMEDS::TMPFile* fic = Save (compo, theURL, isMultiFile);
680 // =========================================================== LoadASCII
681 CORBA::Boolean HEXABLOCK_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr compo,
682 const SALOMEDS::TMPFile& theStream,
686 bool rep = Load (compo, theStream, theURL, isMultiFile);
689 // =========================================================== Close
690 void HEXABLOCK_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
692 if (db) cout << " +++++++ Je suis passe par HEXABLOCK_Gen_i::"
695 // =================================================== IORToLocalPersistentID
696 char* HEXABLOCK_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
697 const char* IORString,
698 CORBA::Boolean isMultiFile,
699 CORBA::Boolean isASCII)
701 if (db) cout << " +++++++ Je suis passe par HEXABLOCK_Gen_i::"
702 << "IORToLocalPersistentID" << endl;
703 const char* empty = "";
704 return CORBA::string_dup (empty);
706 // =================================================== LocalPersistentIDToIOR
707 char* HEXABLOCK_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
708 const char* aLocalPersistentID,
709 CORBA::Boolean isMultiFile,
710 CORBA::Boolean isASCII)
712 if (db) cout << " +++++++ Je suis passe par HEXABLOCK_Gen_i::"
713 << "LocalPersistentIDToIOR" << endl;
715 const char* empty = "";
716 return CORBA::string_dup (empty);
719 // =========================================================== CanCopy
720 CORBA::Boolean HEXABLOCK_Gen_i::CanCopy (SALOMEDS::SObject_ptr theObject)
722 if (db) cout << " +++++++ Je suis passe par HEXABLOCK_Gen_i::"
723 << "CanCopy" << endl;
726 // =========================================================== CopyFrom
727 SALOMEDS::TMPFile* HEXABLOCK_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
728 CORBA::Long& theObjectID)
730 if (db) cout << " +++++++ Je suis passe par HEXABLOCK_Gen_i::"
731 << "CopyFrom" << endl;
734 // =========================================================== CanPaste
735 CORBA::Boolean HEXABLOCK_Gen_i:: CanPaste (const char* theComponentName,
736 CORBA::Long theObjectID)
738 if (db) cout << " +++++++ Je suis passe par HEXABLOCK_Gen_i::"
739 << "CanPaste" << endl;
742 // =========================================================== PasteInto
743 SALOMEDS::SObject_ptr HEXABLOCK_Gen_i::PasteInto(const SALOMEDS::TMPFile& fic,
744 CORBA::Long theObjectID,
745 SALOMEDS::SObject_ptr theObject)
747 if (db) cout << " +++++++ Je suis passe par HEXABLOCK_Gen_i::"
748 << "PasteInto" << endl;
751 // =========================================================== CanPaste
752 SALOMEDS::SObject_ptr HEXABLOCK_Gen_i::PublishInStudy (SALOMEDS::Study_ptr stud,
753 SALOMEDS::SObject_ptr theSObject,
754 CORBA::Object_ptr theObject,
756 throw (SALOME::SALOME_Exception)
758 if (db) cout << " +++++++ Je suis passe par HEXABLOCK_Gen_i::"
759 << "PublishInStudy" << endl;
762 // =========================================================== Save
763 SALOMEDS::TMPFile* HEXABLOCK_Gen_i::Save(const SALOMEDS::SComponent_ptr compo,
767 if (db) cout << " +++++++ Je suis passe par HEXABLOCK_Gen_i::"
770 string tmp_fic = SALOMEDS_Tool::GetTmpDir();
771 // tmp_fic += "hexablock.xml";
772 tmp_fic = "hexablock.xml";
773 cpchar fic_study = tmp_fic.c_str();
776 char* ch_buffer = NULL;
777 int ier = _engine_cpp->saveAllDocs (fic_study);
779 ch_buffer = Hex::read_file (fic_study, len_buffer);
781 ch_buffer = strdup ("<0>");
783 CORBA::Octet* oct_buffer = (CORBA::Octet*) ch_buffer;
784 SALOMEDS::TMPFile* oct_stream = new SALOMEDS::TMPFile (len_buffer,
785 len_buffer, oct_buffer, 1);
788 // =========================================================== Load
789 CORBA::Boolean HEXABLOCK_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
790 const SALOMEDS::TMPFile& stream,
794 if (db) cout << " +++++++ Je suis passe par HEXABLOCK_Gen_i::"
797 char *ch_buffer = (char*) stream.NP_data();
799 int ier = _engine_cpp->loadAllDocs (ch_buffer);
803 // =========================================================== addDocInStudy
804 CORBA::Long HEXABLOCK_Gen_i::addDocInStudy (Document_ptr doc_in)
805 throw ( SALOME::SALOME_Exception )
807 if (CORBA::is_nil(myCurrentStudy))
810 Document_impl* doc_servant = ::DownCast <Document_impl*> (doc_in);
811 if (doc_servant == NULL)
814 HEXA_NS::Document* doc = doc_servant->GetImpl();
818 cpchar name = doc->getName();
821 SALOMEDS::StudyBuilder_var study_builder = myCurrentStudy->NewBuilder();
822 // study_builder->NewCommand(); // There is a transaction ???
825 SALOMEDS::SObject_var obj = ObjectToSObject( myCurrentStudy, doc_in );
826 if ( obj->_is_nil() )
828 SALOMEDS::SComponent_var father = PublishComponent( myCurrentStudy );
829 if ( father->_is_nil() )
832 // SALOMEDS::SObject_var
833 // s_obj = HEXABLOCK_Gen_i::ObjectToSObject( my_current_study, doc_in ); ???
834 // if ( obj->_is_nil() ) --> C'est le cas
836 SALOMEDS::SObject_var s_obj = study_builder->NewObject (father);
838 if ( obj->_is_nil() )
842 SALOMEDS::GenericAttribute_var attrib;
843 SALOMEDS::AttributeName_var attname;
845 attrib = study_builder->FindOrCreateAttribute( obj, "AttributeName" );
846 attname = SALOMEDS::AttributeName::_narrow( attrib );
847 attname->SetValue (name);
848 /// ----------- Fin de SetName
849 // study_builder->CommitCommand(); ???
852 // =========================================================== Version information
854 char* HEXABLOCK_Gen_i::getVersion()
856 #if HEXABLOCK_DEVELOPMENT
857 return CORBA::string_dup(HEXABLOCK_VERSION_STR"dev");
859 return CORBA::string_dup(HEXABLOCK_VERSION_STR);