2 //=============================================================================
3 // File : SMESH_Gen_i.cxx
4 // Created : lun mai 6 13:41:35 CEST 2002
5 // Author : Paul RASCLE, EDF
7 // Copyright : EDF 2002
9 //=============================================================================
13 #include <TopExp_Explorer.hxx>
15 #include <TopoDS_Iterator.hxx>
16 #include <TopoDS_Compound.hxx>
17 #include <TopoDS_CompSolid.hxx>
18 #include <TopoDS_Solid.hxx>
19 #include <TopoDS_Shell.hxx>
20 #include <TopoDS_Face.hxx>
21 #include <TopoDS_Wire.hxx>
22 #include <TopoDS_Edge.hxx>
23 #include <TopoDS_Vertex.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <TopTools_MapOfShape.hxx>
27 #include <BRep_Tool.hxx>
28 #include <TCollection_AsciiString.hxx>
33 #include "SMESH_Gen_i.hxx"
34 #include "SMESH_Mesh_i.hxx"
35 #include "SMESH_LocalLength_i.hxx"
36 #include "SMESH_NumberOfSegments_i.hxx"
37 #include "SMESH_MaxElementArea_i.hxx"
39 #include "SMESHDS_Document.hxx"
41 #include "Document_Reader.h"
42 #include "DriverMED_W_SMESHDS_Mesh.h"
43 #include "DriverMED_R_SMESHDS_Mesh.h"
44 #include "DriverMED_R_SMESHDS_Document.h"
45 #include "DriverUNV_R_SMESHDS_Document.h"
46 #include "DriverDAT_R_SMESHDS_Document.h"
48 #include "Utils_CorbaException.hxx"
49 #include "utilities.h"
51 #include "SALOMEDS_Tool.hxx"
52 #include "SALOME_NamingService.hxx"
53 #include "SALOME_LifeCycleCORBA.hxx"
54 #include "Utils_SINGLETON.hxx"
57 //#include <TopAbs_ShapeEnum.hxx>
59 #include "GEOM_Client.hxx"
63 #define NUM_TMP_FILES 4
66 long Tag_HypothesisRoot = 1;
67 long Tag_AlgorithmsRoot = 2;
69 long Tag_RefOnShape = 1;
70 long Tag_RefOnAppliedHypothesis = 2;
71 long Tag_RefOnAppliedAlgorithms = 3;
73 long Tag_SubMeshOnVertex = 4;
74 long Tag_SubMeshOnEdge = 5;
75 long Tag_SubMeshOnFace = 6;
76 long Tag_SubMeshOnSolid = 7;
77 long Tag_SubMeshOnCompound = 8;
80 //=============================================================================
82 * default constructor: not for use
84 //=============================================================================
86 SMESH_Gen_i::SMESH_Gen_i()
88 MESSAGE("SMESH_Gen_i default constructor");
92 //=============================================================================
94 * Standard constructor, used with Container.
96 //=============================================================================
98 SMESH_Gen_i::SMESH_Gen_i(CORBA::ORB_ptr orb,
99 PortableServer::POA_ptr poa,
100 PortableServer::ObjectId * contId,
101 const char *instanceName,
102 const char *interfaceName) :
103 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
105 MESSAGE("activate object");
107 _id = _poa->activate_object(_thisObj);
110 _localId = 0; // number of created objects & local id
114 //=============================================================================
116 * Standard destructor
118 //=============================================================================
120 SMESH_Gen_i::~SMESH_Gen_i()
122 MESSAGE("~SMESH_Gen_i");
126 //=============================================================================
130 //=============================================================================
132 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis(const char* anHyp,
134 throw (SALOME::SALOME_Exception)
136 MESSAGE("CreateHypothesis");
138 // create a new hypothesis object servant
140 SMESH_Hypothesis_i* myHypothesis_i = 0;
143 myHypothesis_i = _hypothesisFactory_i.Create(anHyp,
147 catch (SALOME_Exception& S_ex)
149 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
152 // activate the CORBA servant of hypothesis
154 SMESH::SMESH_Hypothesis_var hypothesis_i
155 = SMESH::SMESH_Hypothesis::_narrow(myHypothesis_i->_this());
156 return SMESH::SMESH_Hypothesis::_duplicate(hypothesis_i);
159 //=============================================================================
163 //=============================================================================
165 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Init(GEOM::GEOM_Gen_ptr geomEngine,
167 GEOM::GEOM_Shape_ptr aShape)
168 throw (SALOME::SALOME_Exception)
171 // _narrow() duplicates the reference and checks the type
172 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
173 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
175 if (CORBA::is_nil(geom))
176 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", \
178 if (CORBA::is_nil(myShape))
179 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
182 // Get or create the GEOM_Client instance
184 SMESH_Mesh_i* meshServant = 0;
187 if (! _ShapeReader) _ShapeReader = new GEOM_Client();
188 ASSERT(_ShapeReader);
190 // explore main Shape, get local TopoDS_Shapes of all subShapes
191 // SMESH_topo* myTopo = ExploreMainShape(geom, studyId, myShape);
193 // Get studyContext_i, create it if it does'nt exist
195 if (_mapStudyContext_i.find(studyId) == _mapStudyContext_i.end())
197 _mapStudyContext_i[studyId] = new StudyContext_iStruct;
199 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
201 // create a new mesh object servant, store it in a map in study context
203 meshServant = new SMESH_Mesh_i(this,
207 myStudyContext->mapMesh_i[_localId] = meshServant;
210 // create a new mesh object
212 TopoDS_Shape myLocShape = _ShapeReader->GetShape(geom,myShape);
213 meshServant->SetImpl(_impl.Init(studyId, myLocShape));
215 catch (SALOME_Exception& S_ex)
217 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
220 // activate the CORBA servant of Mesh
222 SMESH::SMESH_Mesh_var mesh
223 = SMESH::SMESH_Mesh::_narrow(meshServant->_this());
225 meshServant->SetIor(mesh);
227 return SMESH::SMESH_Mesh::_duplicate(mesh);
231 //=============================================================================
235 //=============================================================================
237 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute(SMESH::SMESH_Mesh_ptr aMesh,
238 GEOM::GEOM_Shape_ptr aShape)
239 throw (SALOME::SALOME_Exception)
241 MESSAGE("SMESH_Gen_i::IsReadyToCompute");
245 //=============================================================================
249 //=============================================================================
252 SMESH_Gen_i::GetSubShapesId(GEOM::GEOM_Gen_ptr geomEngine,
254 GEOM::GEOM_Shape_ptr mainShape,
255 const SMESH::shape_array& listOfSubShape)
256 throw (SALOME::SALOME_Exception)
258 MESSAGE("SMESH_Gen_i::GetSubShapesId");
259 SMESH::long_array_var shapesId = new SMESH::long_array;
262 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
263 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(mainShape);
265 if (CORBA::is_nil(geom))
266 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", \
268 if (CORBA::is_nil(myShape))
269 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
274 if (! _ShapeReader) _ShapeReader = new GEOM_Client();
275 ASSERT(_ShapeReader);
276 TopoDS_Shape myMainShape = _ShapeReader->GetShape(geom,myShape);
277 TopTools_IndexedMapOfShape myIndexToShape;
278 TopExp::MapShapes(myMainShape,myIndexToShape);
280 for (int i=0; i<listOfSubShape.length(); i++)
282 GEOM::GEOM_Shape_var aShape
283 = GEOM::GEOM_Shape::_narrow(listOfSubShape[i]);
284 if (CORBA::is_nil(aShape))
285 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
287 TopoDS_Shape locShape = _ShapeReader->GetShape(geom,aShape);
288 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
290 const TopoDS_Face& F = TopoDS::Face(exp.Current());
291 setId.insert(myIndexToShape.FindIndex(F));
292 SCRUTE(myIndexToShape.FindIndex(F));
294 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
296 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
297 setId.insert(myIndexToShape.FindIndex(E));
298 SCRUTE(myIndexToShape.FindIndex(E));
300 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
302 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
303 setId.insert(myIndexToShape.FindIndex(V));
304 SCRUTE(myIndexToShape.FindIndex(V));
307 shapesId->length(setId.size());
308 set<int>::iterator iind;
310 for (iind = setId.begin(); iind != setId.end(); iind++)
313 shapesId[i] = (*iind);
318 catch (SALOME_Exception& S_ex)
320 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
323 return shapesId._retn();
326 //=============================================================================
330 //=============================================================================
332 CORBA::Boolean SMESH_Gen_i::Compute(SMESH::SMESH_Mesh_ptr aMesh,
333 GEOM::GEOM_Shape_ptr aShape)
334 throw (SALOME::SALOME_Exception)
336 MESSAGE("SMESH_Gen_i::Compute");
337 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
338 if (CORBA::is_nil(myShape))
339 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
342 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(aMesh);
343 if (CORBA::is_nil(myMesh))
344 THROW_SALOME_CORBA_EXCEPTION("bad Mesh reference", \
351 // get study context from studyId given by CORBA mesh object
353 int studyId = myMesh->GetStudyId();
354 ASSERT(_mapStudyContext_i.find(studyId) != _mapStudyContext_i.end());
355 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
357 // get local Mesh_i object with Id and study context
359 int meshId = myMesh->GetId();
360 ASSERT(myStudyContext->mapMesh_i.find(meshId) != myStudyContext->mapMesh_i.end());
361 SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
364 // get local TopoDS_Shape
366 GEOM::GEOM_Gen_var geom = meshServant->GetGeomEngine();
367 TopoDS_Shape myLocShape = _ShapeReader->GetShape(geom,myShape);
369 // implementation compute
371 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
372 ret = _impl.Compute(myLocMesh, myLocShape);
374 catch (SALOME_Exception& S_ex)
376 MESSAGE("catch exception "<< S_ex.what());
378 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
385 //=============================================================================
389 //=============================================================================
391 SALOMEDS::TMPFile* SMESH_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
395 MESSAGE("SMESH_Gen_i::SAVE");
396 SALOMEDS::Study_var Study = theComponent->GetStudy();
399 // Declare a byte stream
400 SALOMEDS::TMPFile_var aStreamFile;
402 // Obtain a temporary dir
403 TCollection_AsciiString tmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
405 // Create a sequence of files processed
406 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
407 aFileSeq->length(NUM_TMP_FILES);
409 TCollection_AsciiString aStudyName(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
411 // Set names of temporary files
412 TCollection_AsciiString filename = aStudyName + TCollection_AsciiString("SMESH.hdf");
413 TCollection_AsciiString hypofile = aStudyName + TCollection_AsciiString("SMESH_Hypo.txt");
414 TCollection_AsciiString algofile = aStudyName + TCollection_AsciiString("SMESH_Algo.txt");
415 TCollection_AsciiString meshfile = aStudyName + TCollection_AsciiString("SMESH_Mesh.med");
416 aFileSeq[0] = CORBA::string_dup(filename.ToCString());
417 aFileSeq[1] = CORBA::string_dup(hypofile.ToCString());
418 aFileSeq[2] = CORBA::string_dup(algofile.ToCString());
419 aFileSeq[3] = CORBA::string_dup(meshfile.ToCString());
420 filename = tmpDir + filename;
421 hypofile = tmpDir + hypofile;
422 algofile = tmpDir + algofile;
423 meshfile = tmpDir + meshfile;
426 map <int,HDFgroup*> hdf_group, hdf_subgroup;
427 map <int,HDFdataset*> hdf_dataset;
430 SALOMEDS::ChildIterator_var itBig,it,itSM;
431 SALOMEDS::SObject_var mySObject,myBranch,mySObjectChild;
433 int longueur,cmpt_ds = 0,cmpt_it;
434 char *name_group,name_dataset[30],name_meshgroup[30];
436 int cmpt_sm = 0, myTag;
438 //************* HDF file creation
439 hdf_file = new HDFfile(filename.ToCString());
440 hdf_file->CreateOnDisk();
441 //****************************
443 itBig = Study->NewChildIterator(theComponent);
444 for (; itBig->More();itBig->Next()) {
445 SALOMEDS::SObject_var gotBranch = itBig->Value();
447 //************branch 1 : hypothesis
448 if (gotBranch->Tag()==Tag_HypothesisRoot) { //hypothesis = tag 1
450 double length,maxElementsArea;
451 int numberOfSegments;
453 destFile = fopen( hypofile.ToCString() ,"w");
454 it = Study->NewChildIterator(gotBranch);
455 for (; it->More();it->Next()) {
456 mySObject = it->Value();
457 SALOMEDS::GenericAttribute_var anAttr;
458 SALOMEDS::AttributeIOR_var anIOR;
459 if ( mySObject->FindAttribute(anAttr, "AttributeIOR")) {
460 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
462 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
463 fprintf(destFile,"%s\n",myHyp->GetName());
465 if (strcmp(myHyp->GetName(),"LocalLength")==0) {
466 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( myHyp );
467 length = LL->GetLength();
468 fprintf(destFile,"%f\n",length);
470 else if (strcmp(myHyp->GetName(),"NumberOfSegments")==0) {
471 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( myHyp );
472 numberOfSegments = NOS->GetNumberOfSegments();
473 fprintf(destFile,"%d\n",numberOfSegments);
475 else if (strcmp(myHyp->GetName(),"MaxElementArea")==0) {
476 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( myHyp );
477 maxElementsArea = MEA->GetMaxElementArea();
478 fprintf(destFile,"%f\n",maxElementsArea);
484 //writes the file name in the hdf file
485 longueur = hypofile.Length() +1;
486 name_group="Hypothesis";
487 //SCRUTE(name_group);
490 hdf_group[1] = new HDFgroup(name_group,hdf_file);
491 hdf_group[1]->CreateOnDisk();
493 hdf_dataset[cmpt_ds]=new HDFdataset(name_group,hdf_group[1],HDF_STRING,size,1);
494 hdf_dataset[cmpt_ds]->CreateOnDisk();
495 hdf_dataset[cmpt_ds]->WriteOnDisk(hypofile.ToCString());
496 hdf_dataset[cmpt_ds]->CloseOnDisk();
499 hdf_group[1]->CloseOnDisk();
500 MESSAGE("End of Hypothesis Save");
503 //************branch 2 : algorithms
504 else if (gotBranch->Tag()==Tag_AlgorithmsRoot) {//algos = tag 2
506 destFile = fopen( algofile.ToCString() ,"w");
507 it = Study->NewChildIterator(gotBranch);
508 for (; it->More();it->Next()) {
509 mySObject = it->Value();
510 SALOMEDS::GenericAttribute_var anAttr;
511 SALOMEDS::AttributeIOR_var anIOR;
512 if (mySObject->FindAttribute(anAttr, "AttributeIOR")) {
513 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
514 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(anIOR->Value()));
515 fprintf(destFile,"%s\n",myAlgo->GetName());
521 //writes the file name in the hdf file
522 longueur = algofile.Length() +1;
523 name_group="Algorithms";
524 //SCRUTE(name_group);
527 hdf_group[2] = new HDFgroup(name_group,hdf_file);
528 hdf_group[2]->CreateOnDisk();
530 hdf_dataset[cmpt_ds]=new HDFdataset(name_group,hdf_group[2],HDF_STRING,size,1);
531 hdf_dataset[cmpt_ds]->CreateOnDisk();
532 hdf_dataset[cmpt_ds]->WriteOnDisk(algofile.ToCString());
533 hdf_dataset[cmpt_ds]->CloseOnDisk();
536 hdf_group[2]->CloseOnDisk();
537 MESSAGE("End of Algos Save");
540 //************branch 3 : meshes
541 else if (gotBranch->Tag()>=3) {//meshes = tag > 3
543 SALOMEDS::GenericAttribute_var anAttr;
544 SALOMEDS::AttributeIOR_var anIOR;
545 if (gotBranch->FindAttribute(anAttr, "AttributeIOR")) {
546 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
548 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value())) ;
549 studyId = myMesh->GetStudyId();
552 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
553 int meshId = myMesh->GetId();
554 SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
555 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
556 Handle(SMESHDS_Mesh) mySMESHDSMesh = myLocMesh.GetMeshDS();
558 SCRUTE(mySMESHDSMesh->NbNodes());
559 if (mySMESHDSMesh->NbNodes()>0) {//checks if the mesh is not empty
561 DriverMED_W_SMESHDS_Mesh* myWriter = new DriverMED_W_SMESHDS_Mesh;
562 myWriter->SetFile(meshfile.ToCString());
564 myWriter->SetMesh(mySMESHDSMesh);
565 myWriter->SetMeshId(gotBranch->Tag());
568 else meshfile = "No data";
570 //********** opening of the HDF group
571 sprintf(name_meshgroup,"Mesh %d",gotBranch->Tag());
572 SCRUTE(name_meshgroup);
573 hdf_group[gotBranch->Tag()] = new HDFgroup(name_meshgroup,hdf_file);
574 hdf_group[gotBranch->Tag()]->CreateOnDisk();
577 //********** file where the data are stored
578 longueur = strlen(meshfile.ToCString()) +1;
580 strcpy(name_dataset,"Mesh data");
581 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_group[gotBranch->Tag()],HDF_STRING,size,1);
582 hdf_dataset[cmpt_ds]->CreateOnDisk();
583 hdf_dataset[cmpt_ds]->WriteOnDisk(meshfile.ToCString());
584 hdf_dataset[cmpt_ds]->CloseOnDisk();
588 //********** ref on shape
589 Standard_CString myRefOnObject="" ;
590 SALOMEDS::SObject_var myRef,myShape;
591 _found = gotBranch->FindSubObject(Tag_RefOnShape,myRef);
593 ok = myRef->ReferencedObject(myShape);
594 myRefOnObject = myShape->GetID();
595 SCRUTE(myRefOnObject);
597 longueur = strlen(myRefOnObject) +1;
600 strcpy(name_dataset,"Ref on shape");
601 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_group[gotBranch->Tag()],HDF_STRING,size,1);
602 hdf_dataset[cmpt_ds]->CreateOnDisk();
603 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
604 hdf_dataset[cmpt_ds]->CloseOnDisk();
611 //********** ref on applied hypothesis
612 _found = gotBranch->FindSubObject(Tag_RefOnAppliedHypothesis,myBranch);
615 strcpy(name_meshgroup,"Applied Hypothesis");
616 hdf_subgroup[Tag_RefOnAppliedHypothesis] = new HDFgroup(name_meshgroup,hdf_group[gotBranch->Tag()]);
617 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CreateOnDisk();
619 it = Study->NewChildIterator(myBranch);
621 for (; it->More();it->Next()) {
622 mySObject = it->Value();
623 ok = mySObject->ReferencedObject(myRef);
624 myRefOnObject = myRef->GetID();
626 longueur = strlen(myRefOnObject) +1;
629 sprintf(name_dataset,"Hyp %d",cmpt_it);
630 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedHypothesis],HDF_STRING,size,1);
631 hdf_dataset[cmpt_ds]->CreateOnDisk();
632 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
633 hdf_dataset[cmpt_ds]->CloseOnDisk();
638 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CloseOnDisk();
642 //********** ref on applied algorithms
643 _found = gotBranch->FindSubObject(Tag_RefOnAppliedAlgorithms,myBranch);
646 strcpy(name_meshgroup,"Applied Algorithms");
647 hdf_subgroup[Tag_RefOnAppliedAlgorithms] = new HDFgroup(name_meshgroup,hdf_group[gotBranch->Tag()]);
648 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CreateOnDisk();
650 it = Study->NewChildIterator(myBranch);
652 for (; it->More();it->Next()) {
653 mySObject = it->Value();
654 ok = mySObject->ReferencedObject(myRef);
655 myRefOnObject = myRef->GetID();
657 longueur = strlen(myRefOnObject) +1;
660 sprintf(name_dataset,"Algo %d",cmpt_it);
661 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedAlgorithms],HDF_STRING,size,1);
662 hdf_dataset[cmpt_ds]->CreateOnDisk();
663 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
664 hdf_dataset[cmpt_ds]->CloseOnDisk();
669 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CloseOnDisk();
671 MESSAGE("end of algo applied");
674 //********** submeshes on subshapes
676 for (int i=Tag_SubMeshOnVertex;i<=Tag_SubMeshOnCompound;i++) {
677 _found = gotBranch->FindSubObject(i,myBranch);
679 if (i==Tag_SubMeshOnVertex)
680 strcpy(name_meshgroup,"SubMeshes On Vertex");
681 else if (i==Tag_SubMeshOnEdge)
682 strcpy(name_meshgroup,"SubMeshes On Edge");
683 else if (i==Tag_SubMeshOnFace)
684 strcpy(name_meshgroup,"SubMeshes On Face");
685 else if (i==Tag_SubMeshOnSolid)
686 strcpy(name_meshgroup,"SubMeshes On Solid");
687 else if (i==Tag_SubMeshOnCompound)
688 strcpy(name_meshgroup,"SubMeshes On Compound");
691 myLevel1Tag = 10+cmpt_sm;
692 hdf_subgroup[myLevel1Tag] = new HDFgroup(name_meshgroup,hdf_group[gotBranch->Tag()]);
693 hdf_subgroup[myLevel1Tag]->CreateOnDisk();
695 itSM = Study->NewChildIterator(myBranch);
696 for (; itSM->More();itSM->Next()) {//Loop on all submeshes
697 mySObject = itSM->Value();
700 mySObject->FindAttribute(anAttr, "AttributeIOR");
701 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
702 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value())) ;
704 //sprintf(name_meshgroup,"SubMesh %d",myTag);
705 sprintf(name_meshgroup,"SubMesh %d",mySubMesh->GetId());
706 SCRUTE(name_meshgroup);
708 hdf_subgroup[myTag] = new HDFgroup(name_meshgroup,hdf_subgroup[myLevel1Tag]);
709 hdf_subgroup[myTag]->CreateOnDisk();
711 //********** ref on shape
712 Standard_CString myRefOnObject="" ;
713 SALOMEDS::SObject_var myRef,myShape;
715 _found2 = mySObject->FindSubObject(Tag_RefOnShape,myRef);
717 ok = myRef->ReferencedObject(myShape);
718 myRefOnObject = myShape->GetID();
719 SCRUTE(myRefOnObject);
721 longueur = strlen(myRefOnObject) +1;
724 strcpy(name_dataset,"Ref on shape");
725 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[myTag],HDF_STRING,size,1);
726 hdf_dataset[cmpt_ds]->CreateOnDisk();
727 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
728 hdf_dataset[cmpt_ds]->CloseOnDisk();
734 //********** ref on applied hypothesis
735 _found2 = mySObject->FindSubObject(Tag_RefOnAppliedHypothesis,myBranch);
738 strcpy(name_meshgroup,"Applied Hypothesis");
740 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
741 hdf_subgroup[10+cmpt_sm]->CreateOnDisk();
743 it = Study->NewChildIterator(myBranch);
745 for (; it->More();it->Next()) {
746 mySObjectChild = it->Value();
747 ok = mySObjectChild->ReferencedObject(myRef);
748 myRefOnObject = myRef->GetID();
750 longueur = strlen(myRefOnObject) +1;
753 sprintf(name_dataset,"Hyp %d",cmpt_it);
755 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm],HDF_STRING,size,1);
756 hdf_dataset[cmpt_ds]->CreateOnDisk();
757 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
758 hdf_dataset[cmpt_ds]->CloseOnDisk();
763 hdf_subgroup[10+cmpt_sm]->CloseOnDisk();
767 //********** ref on applied algorithms
768 _found2 = mySObject->FindSubObject(Tag_RefOnAppliedAlgorithms,myBranch);
772 strcpy(name_meshgroup,"Applied Algorithms");
774 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
775 hdf_subgroup[10+cmpt_sm]->CreateOnDisk();
777 it = Study->NewChildIterator(myBranch);
779 for (; it->More();it->Next()) {
780 mySObjectChild = it->Value();
781 ok = mySObjectChild->ReferencedObject(myRef);
782 myRefOnObject = myRef->GetID();
784 longueur = strlen(myRefOnObject) +1;
787 sprintf(name_dataset,"Algo %d",cmpt_it);
788 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm],HDF_STRING,size,1);
789 hdf_dataset[cmpt_ds]->CreateOnDisk();
790 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
791 hdf_dataset[cmpt_ds]->CloseOnDisk();
796 hdf_subgroup[10+cmpt_sm]->CloseOnDisk();
798 //MESSAGE("end of algo applied");
801 hdf_subgroup[myTag]->CloseOnDisk();
804 hdf_subgroup[myLevel1Tag]->CloseOnDisk();
810 //********** closing of the HDF group
811 hdf_group[gotBranch->Tag()]->CloseOnDisk();
812 MESSAGE("End of Mesh Save");
816 MESSAGE("End of Meshes Save");
819 hdf_file->CloseOnDisk();
823 // Convert temporary files to stream
824 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.ToCString(), aFileSeq.in(), isMultiFile);
826 // Remove temporary files and directory
827 if (isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(), true);
829 MESSAGE("End SMESH_Gen_i::Save");
831 return aStreamFile._retn();
834 //=============================================================================
838 //=============================================================================
840 bool SMESH_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
841 const SALOMEDS::TMPFile& theStream,
845 MESSAGE("SMESH_Gen_i::Load\n");
847 // Get temporary files location
848 TCollection_AsciiString tmpDir = isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
850 // Convert the stream into sequence of files to process
851 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
855 // Set names of temporary files
856 TCollection_AsciiString filename = tmpDir + aFileSeq[0];//"SMESH.hdf";
857 TCollection_AsciiString hypofile = tmpDir + aFileSeq[1];//"SMESH_Hypo.txt";
858 TCollection_AsciiString algofile = tmpDir + aFileSeq[2];//"SMESH_Algo.txt";
859 TCollection_AsciiString meshfile = tmpDir + aFileSeq[3];//"SMESH_Mesh.med";
861 SALOMEDS::Study_var Study = theComponent->GetStudy();
862 int studyId = Study->StudyId();
865 SALOMEDS::GenericAttribute_var anAttr;
866 SALOMEDS::AttributeName_var aName;
867 SALOMEDS::AttributeIOR_var anIOR;
869 SALOMEDS::SComponent_var fathergeom = Study->FindComponent("GEOM");
870 SALOMEDS::SComponent_var myGeomSComp = SALOMEDS::SComponent::_narrow( fathergeom );
873 //to get the geom engine !!!
874 //useful to define our new mesh
875 SALOME_NamingService* _NS = SINGLETON_<SALOME_NamingService>::Instance() ;
876 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
877 _NS->init_orb( _orb ) ;
878 SALOME_LifeCycleCORBA* myEnginesLifeCycle = new SALOME_LifeCycleCORBA(_NS);
879 Engines::Component_var geomEngine =
880 myEnginesLifeCycle->FindOrLoad_Component("FactoryServer","GEOM");
881 GEOM::GEOM_Gen_var myGeomEngine = GEOM::GEOM_Gen::_narrow(geomEngine);
886 char objectId[10],name_dataset[10];
887 int nb_datasets,size,cmpt_ds=0;
890 char name[HDF_NAME_MAX_LEN+1];
891 char sgname[HDF_NAME_MAX_LEN+1];
892 char msgname[HDF_NAME_MAX_LEN+1];
893 char name_of_group[HDF_NAME_MAX_LEN+1];
894 char *name_meshgroup;
895 map <int,HDFgroup*> hdf_group, hdf_subgroup;
896 map <int,HDFdataset*> hdf_dataset;
899 //************* HDF file opening
900 HDFfile * hdf_file = new HDFfile(filename.ToCString());
902 hdf_file->OpenOnDisk(HDF_RDONLY);
904 catch (HDFexception) {
905 MESSAGE("Load(): " << filename << " not found!");
909 //****************************
911 int nb_group = hdf_file->nInternalObjects();
913 for (int i=0;i<nb_group;i++)
915 hdf_file->InternalObjectIndentify(i,name);
919 // Loading of the Hypothesis Branch
921 if (strcmp(name,"Hypothesis")==0) {
923 double length,maxElementsArea;
924 int numberOfSegments;
926 hdf_group[Tag_HypothesisRoot] = new HDFgroup(name,hdf_file);
927 hdf_group[Tag_HypothesisRoot]->OpenOnDisk();
929 hdf_group[Tag_HypothesisRoot]->InternalObjectIndentify(0,name_of_group);
930 hdf_dataset[cmpt_ds]=new HDFdataset(name_of_group,hdf_group[Tag_HypothesisRoot]);
931 hdf_dataset[cmpt_ds]->OpenOnDisk();
932 size=hdf_dataset[cmpt_ds]->GetSize();
934 char * name_of_file =new char[size];
935 hdf_dataset[cmpt_ds]->ReadFromDisk(name_of_file);
936 SCRUTE(name_of_file);
937 hdf_dataset[cmpt_ds]->CloseOnDisk();
938 hdf_group[Tag_HypothesisRoot]->CloseOnDisk();
940 delete[] name_of_file;
943 aLine = new char[100];
944 loadedFile = fopen( hypofile.ToCString() ,"r");
945 while (!feof(loadedFile)) {
946 fscanf(loadedFile,"%s",aLine);
948 if (strcmp(aLine,"LocalLength")==0) {
949 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
950 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( myHyp );
951 fscanf(loadedFile,"%s",aLine);
952 length = atof(aLine);
953 LL->SetLength(length);
954 string iorString = _orb->object_to_string(LL);
955 sprintf(objectId,"%d",LL->GetId());
956 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
958 else if (strcmp(aLine,"NumberOfSegments")==0) {
959 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
960 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( myHyp );
961 fscanf(loadedFile,"%s",aLine);
962 numberOfSegments = atoi(aLine);
963 NOS->SetNumberOfSegments(numberOfSegments);
964 string iorString = _orb->object_to_string(NOS);
965 sprintf(objectId,"%d",NOS->GetId());
966 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
968 else if (strcmp(aLine,"MaxElementArea")==0) {
969 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
970 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( myHyp );
971 fscanf(loadedFile,"%s",aLine);
972 maxElementsArea = atof(aLine);
973 MEA->SetMaxElementArea(maxElementsArea);
974 string iorString = _orb->object_to_string(MEA);
975 sprintf(objectId,"%d",MEA->GetId());
976 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
984 MESSAGE("End of Hypos Load");
988 // Loading of the Algorithms Branch
990 else if (strcmp(name,"Algorithms")==0) {
992 hdf_group[Tag_AlgorithmsRoot] = new HDFgroup(name,hdf_file);
993 hdf_group[Tag_AlgorithmsRoot]->OpenOnDisk();
995 hdf_group[Tag_AlgorithmsRoot]->InternalObjectIndentify(0,name_of_group);
996 hdf_dataset[cmpt_ds] = new HDFdataset(name_of_group,hdf_group[Tag_AlgorithmsRoot]);
997 hdf_dataset[cmpt_ds]->OpenOnDisk();
998 size=hdf_dataset[cmpt_ds]->GetSize();
1000 char * name_of_file =new char[size];
1001 hdf_dataset[cmpt_ds]->ReadFromDisk(name_of_file);
1002 hdf_dataset[cmpt_ds]->CloseOnDisk();
1003 hdf_group[Tag_AlgorithmsRoot]->CloseOnDisk();
1005 delete[] name_of_file;
1008 aLine = new char[100];
1009 loadedFile = fopen( algofile.ToCString(),"r");
1010 while (!feof(loadedFile)) {
1011 fscanf(loadedFile,"%s\n",aLine);
1013 if (strcmp(aLine,"")!=0) {
1014 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
1015 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1016 string iorString = _orb->object_to_string(myAlgo);
1017 sprintf(objectId,"%d",myAlgo->GetId());
1018 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
1024 MESSAGE("End of Algos Load");
1029 // Loading of the Mesh Branch
1031 else if (string(name).substr(0,4)==string("Mesh")) {
1032 MESSAGE("in mesh load");
1034 Standard_Integer myMeshId = atoi((string(name).substr(5,5)).c_str());
1037 hdf_group[myMeshId] = new HDFgroup(name,hdf_file);
1038 hdf_group[myMeshId]->OpenOnDisk();
1040 int nb_meshsubgroup = hdf_group[myMeshId]->nInternalObjects();
1041 SCRUTE(nb_meshsubgroup);
1043 //********** Loading of the file name where the data are stored
1044 MESSAGE("Mesh data file");
1045 strcpy(name_of_group,"Mesh data");
1046 hdf_dataset[cmpt_ds]=new HDFdataset(name_of_group,hdf_group[myMeshId]);
1047 hdf_dataset[cmpt_ds]->OpenOnDisk();
1048 size=hdf_dataset[cmpt_ds]->GetSize();
1050 char * datafilename =new char[size];
1051 hdf_dataset[cmpt_ds]->ReadFromDisk(datafilename);
1052 hdf_dataset[cmpt_ds]->CloseOnDisk();
1057 //else if (strcmp(msgname,"Ref on shape")==0) {
1059 //********** Loading of the reference on the shape
1060 //********** and mesh initialization
1061 MESSAGE("Ref on shape");
1062 strcpy(name_of_group,"Ref on shape");
1063 hdf_dataset[cmpt_ds] = new HDFdataset(name_of_group,hdf_group[myMeshId]);
1064 hdf_dataset[cmpt_ds]->OpenOnDisk();
1065 size=hdf_dataset[cmpt_ds]->GetSize();
1067 char * refFromFile =new char[size];
1068 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1069 hdf_dataset[cmpt_ds]->CloseOnDisk();
1072 Standard_CString myRefOnShape=""; //look for ref on shape
1074 bool _found = false;
1075 SALOMEDS::SObject_var CSO = Study->FindObjectID(refFromFile);
1076 SMESH::SMESH_Mesh_var myNewMesh;
1077 GEOM::GEOM_Shape_var aShape;
1079 if (!CORBA::is_nil(CSO)) {
1081 CSO->FindAttribute(anAttr, "AttributeIOR");
1082 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1083 char* ShapeIOR = anIOR->Value();
1084 aShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(ShapeIOR));
1086 myNewMesh = this->Init(myGeomEngine,studyId,aShape);
1087 string iorString = _orb->object_to_string(myNewMesh);
1088 sprintf(objectId,"%d",myNewMesh->GetId());
1089 _SMESHCorbaObj[string("Mesh_")+string(objectId)] = iorString;
1092 //********** Loading of mesh data
1093 if (strcmp(datafilename,"No data")!=0) {
1098 //****************************************************************************
1099 //* OUVERTURE DU FICHIER EN LECTURE *
1100 //****************************************************************************
1102 fid = MEDouvrir(datafilename,MED_LECT);
1105 printf(">> ERREUR : ouverture du fichier %s \n",datafilename);
1110 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
1111 int meshId = myNewMesh->GetId();
1112 SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
1113 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1114 Handle(SMESHDS_Mesh) mySMESHDSMesh = myLocMesh.GetMeshDS();
1116 DriverMED_R_SMESHDS_Mesh* myReader = new DriverMED_R_SMESHDS_Mesh;
1118 myReader->SetMesh(mySMESHDSMesh);
1119 myReader->SetMeshId(myMeshId);
1120 myReader->SetFileId(fid);
1121 myReader->ReadMySelf();
1122 //SCRUTE(mySMESHDSMesh->NbNodes());
1123 //myNewMesh->ExportUNV("/tmp/test.unv");//only to check out
1125 //****************************************************************************
1126 //* FERMETURE DU FICHIER *
1127 //****************************************************************************
1128 ret = MEDfermer(fid);
1131 printf(">> ERREUR : erreur a la fermeture du fichier %s\n",datafilename);
1138 //else if (strcmp(msgname,"Applied Hypothesis")==0) {
1139 for (int ii=0;ii<nb_meshsubgroup;ii++)
1141 hdf_group[myMeshId]->InternalObjectIndentify(ii,msgname);
1142 if (strcmp(msgname,"Mesh data")==0) {
1145 else if (strcmp(msgname,"Ref on shape")==0) {
1148 else if (strcmp(msgname,"Applied Hypothesis")==0) {
1149 //********** Loading of the applied hypothesis
1150 strcpy(name_of_group,"Applied Hypothesis");
1151 hdf_subgroup[Tag_RefOnAppliedHypothesis] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1152 hdf_subgroup[Tag_RefOnAppliedHypothesis]->OpenOnDisk();
1154 nb_datasets = hdf_subgroup[Tag_RefOnAppliedHypothesis]->nInternalObjects();
1155 SCRUTE(nb_datasets);
1157 for (int j=0;j<nb_datasets;j++) {
1158 sprintf(name_dataset,"Hyp %d",j);
1159 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedHypothesis]);
1160 hdf_dataset[cmpt_ds]->OpenOnDisk();
1161 size=hdf_dataset[cmpt_ds]->GetSize();
1163 char * refFromFile =new char[size];
1164 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1165 //SCRUTE(refFromFile);
1166 hdf_dataset[cmpt_ds]->CloseOnDisk();
1169 SALOMEDS::SObject_var HypSO = Study->FindObjectID(refFromFile);
1170 if (!CORBA::is_nil(HypSO)) {
1171 HypSO->FindAttribute(anAttr, "AttributeIOR");
1172 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1173 if (!CORBA::is_nil(anIOR)) {
1174 char* HypIOR = anIOR->Value();
1175 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(HypIOR));
1176 if (!CORBA::is_nil(anHyp)) {
1177 myNewMesh->AddHypothesis(aShape,anHyp);
1178 MESSAGE("Hypothesis added ...");
1185 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CloseOnDisk();
1188 else if (strcmp(msgname,"Applied Algorithms")==0) {
1190 //********** Loading of the applied algorithms
1191 strcpy(name_of_group,"Applied Algorithms");
1192 hdf_subgroup[Tag_RefOnAppliedAlgorithms] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1193 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->OpenOnDisk();
1195 nb_datasets = hdf_subgroup[Tag_RefOnAppliedAlgorithms]->nInternalObjects();
1196 SCRUTE(nb_datasets);
1198 for (int j=0;j<nb_datasets;j++) {
1199 sprintf(name_dataset,"Algo %d",j);
1200 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedAlgorithms]);
1201 hdf_dataset[cmpt_ds]->OpenOnDisk();
1202 size=hdf_dataset[cmpt_ds]->GetSize();
1204 char * refFromFile =new char[size];
1205 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1206 hdf_dataset[cmpt_ds]->CloseOnDisk();
1210 SALOMEDS::SObject_var AlgoSO = Study->FindObjectID(refFromFile);
1211 if (!CORBA::is_nil(AlgoSO)) {
1212 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1213 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1214 if (!CORBA::is_nil(anIOR)) {
1215 char* AlgoIOR = anIOR->Value();
1217 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(AlgoIOR));
1218 SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1219 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1220 if (!CORBA::is_nil(anAlgo)) {
1221 myNewMesh->AddHypothesis(aShape,anAlgo);//essayer avec _SMESHCorbaObj
1222 MESSAGE("Algorithms added ...");
1229 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CloseOnDisk();
1233 else if (string(msgname).substr(0,9)==string("SubMeshes")) {
1236 //********** Loading of the submeshes on subshapes
1237 int myLevel1Tag, myTag;
1240 myLevel1Tag = 10+cmpt_sm;
1241 hdf_subgroup[myLevel1Tag] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1242 hdf_subgroup[myLevel1Tag] = new HDFgroup(msgname,hdf_group[myMeshId]);
1243 hdf_subgroup[myLevel1Tag]->OpenOnDisk();
1245 int nb_submeshes = hdf_subgroup[myLevel1Tag]->nInternalObjects();
1246 SCRUTE(nb_submeshes);
1248 for (int j=0;j<nb_submeshes;j++) {
1251 hdf_subgroup[myLevel1Tag]->InternalObjectIndentify(j,name_meshgroup);
1252 SCRUTE(name_meshgroup);
1254 hdf_subgroup[myTag] = new HDFgroup(name_meshgroup,hdf_subgroup[myLevel1Tag]);
1255 hdf_subgroup[myTag]->OpenOnDisk();
1256 int subMeshId = atoi((string(name_meshgroup).substr(8,18)).c_str());
1258 MESSAGE("Ref on shape");
1259 //********** ref on shape
1260 sprintf(name_dataset,"Ref on shape");
1261 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[myTag]);
1262 hdf_dataset[cmpt_ds]->OpenOnDisk();
1263 size=hdf_dataset[cmpt_ds]->GetSize();
1265 char * refFromFile =new char[size];
1266 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1267 hdf_dataset[cmpt_ds]->CloseOnDisk();
1270 bool _found3 = false;
1271 SALOMEDS::SObject_var GSO = Study->FindObjectID(refFromFile);
1272 SMESH::SMESH_subMesh_var aSubMesh;
1273 GEOM::GEOM_Shape_var aSubShape;
1275 if (!CORBA::is_nil(GSO)) {
1276 GSO->FindAttribute(anAttr, "AttributeIOR");
1277 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1278 char* SubShapeIOR = anIOR->Value();
1279 aSubShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(SubShapeIOR));
1281 if (!CORBA::is_nil(aSubShape)) {
1282 aSubMesh = myNewMesh->GetElementsOnShape(aSubShape);
1283 string iorString = _orb->object_to_string(aSubMesh);
1284 sprintf(objectId,"%d",subMeshId);
1285 _SMESHCorbaObj[string("SubMesh_")+string(objectId)] = iorString;
1287 //SCRUTE(aSubMesh->GetNumberOfNodes());
1289 //SCRUTE(aSubMesh->GetNumberOfElements());
1293 int nb_subgroup = hdf_subgroup[myTag]->nInternalObjects();
1294 SCRUTE(nb_subgroup);
1295 for (int k=0;k<nb_subgroup;k++)
1297 hdf_subgroup[myTag]->InternalObjectIndentify(k,sgname);
1298 if (strcmp(sgname,"Ref on shape")==0) {
1301 else if (strcmp(sgname,"Applied Hypothesis")==0) {
1302 //********** ref on applied hypothesis
1303 MESSAGE("Applied Hypothesis");
1304 strcpy(name_meshgroup,"Applied Hypothesis");
1306 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
1307 hdf_subgroup[10+cmpt_sm]->OpenOnDisk();
1308 nb_datasets = hdf_subgroup[10+cmpt_sm]->nInternalObjects();
1309 SCRUTE(nb_datasets);
1311 for (int l=0;l<nb_datasets;l++) {
1312 sprintf(name_dataset,"Hyp %d",l);
1313 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm]);
1314 hdf_dataset[cmpt_ds]->OpenOnDisk();
1315 size=hdf_dataset[cmpt_ds]->GetSize();
1317 char * refFromFile =new char[size];
1318 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1319 hdf_dataset[cmpt_ds]->CloseOnDisk();
1323 SALOMEDS::SObject_var HypSO = Study->FindObjectID(refFromFile);
1324 if (!CORBA::is_nil(HypSO)) {
1325 HypSO->FindAttribute(anAttr, "AttributeIOR");
1326 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1327 if (!CORBA::is_nil(anIOR)) {
1328 char* HypIOR = anIOR->Value();
1329 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(HypIOR));
1330 if (!CORBA::is_nil(anHyp)) {
1331 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1332 aMesh->AddHypothesis(aSubShape,anHyp);//essayer avec _SMESHCorbaObj
1333 MESSAGE("Hypothesis added ...");
1340 else if (strcmp(sgname,"Applied Algorithms")==0) {
1341 //********** ref on applied algorithms
1342 MESSAGE("Applied Algorithms");
1343 strcpy(name_meshgroup,"Applied Algorithms");
1345 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
1346 hdf_subgroup[10+cmpt_sm]->OpenOnDisk();
1347 nb_datasets = hdf_subgroup[10+cmpt_sm]->nInternalObjects();
1348 SCRUTE(nb_datasets);
1350 for (int l=0;l<nb_datasets;l++) {
1351 sprintf(name_dataset,"Algo %d",l);
1352 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm]);
1353 hdf_dataset[cmpt_ds]->OpenOnDisk();
1354 size=hdf_dataset[cmpt_ds]->GetSize();
1356 char * refFromFile =new char[size];
1357 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1358 hdf_dataset[cmpt_ds]->CloseOnDisk();
1362 SALOMEDS::SObject_var AlgoSO = Study->FindObjectID(refFromFile);
1363 if (!CORBA::is_nil(AlgoSO)) {
1364 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1365 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1366 if (!CORBA::is_nil(anIOR)) {
1367 char* AlgoIOR = anIOR->Value();
1369 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(AlgoIOR));
1370 SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1371 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1372 if (!CORBA::is_nil(anAlgo)) {
1373 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1374 aMesh->AddHypothesis(aSubShape,anAlgo);//essayer avec _SMESHCorbaObj
1375 MESSAGE("Algorithms added ...");
1384 hdf_subgroup[myTag]->CloseOnDisk();
1386 hdf_subgroup[myLevel1Tag]->CloseOnDisk();
1389 hdf_group[myMeshId]->CloseOnDisk();
1391 MESSAGE("End of Meshes Load");
1395 MESSAGE("End of SMESH_Gen::Load");
1397 hdf_file->CloseOnDisk();
1401 // Remove temporary files created from the stream
1402 if (isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(), true);
1407 //=============================================================================
1411 //=============================================================================
1413 void SMESH_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
1416 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
1417 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
1418 for (; itBig->More();itBig->Next()) {
1419 SALOMEDS::SObject_var gotBranch = itBig->Value();
1421 // branch 1 : hypothesis
1422 if (gotBranch->Tag()==Tag_HypothesisRoot || gotBranch->Tag()==Tag_AlgorithmsRoot) {
1423 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(gotBranch);
1424 for (; it->More();it->Next()) {
1425 SALOMEDS::SObject_var mySObject = it->Value();
1426 SALOMEDS::GenericAttribute_var anAttr;
1427 SALOMEDS::AttributeIOR_var anIOR;
1428 if ( mySObject->FindAttribute(anAttr, "AttributeIOR")) {
1429 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1430 SMESH::SMESH_Hypothesis_var myHyp =
1431 SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
1433 sprintf(objectId,"%d",myHyp->GetId());
1434 // cout<<"********** delete Hyp "<<objectId<<endl;
1435 _SMESHCorbaObj.erase(string("Hypo_")+string(objectId));
1436 myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
1440 // branch 2 : algorithms
1441 else if (gotBranch->Tag()>=3) {
1442 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(gotBranch);
1443 for (; it->More();it->Next()) {
1444 SALOMEDS::SObject_var mySObject = it->Value();
1445 SALOMEDS::GenericAttribute_var anAttr;
1446 SALOMEDS::AttributeIOR_var anIOR;
1447 if ( mySObject->FindAttribute(anAttr, "AttributeIOR")) {
1448 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1449 SMESH::SMESH_Mesh_var myMesh =
1450 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
1451 if (!myMesh->_is_nil()) {
1453 sprintf(objectId,"%d",myMesh->GetId());
1454 // cout<<"********** delete Mesh "<<objectId<<endl;
1455 _SMESHCorbaObj.erase(string("Mesh_")+string(objectId));
1456 CORBA::release(myMesh);
1459 SMESH::SMESH_subMesh_var mySubMesh =
1460 SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value()));
1461 if (!mySubMesh->_is_nil()) {
1463 sprintf(objectId,"%d",mySubMesh->GetId());
1464 // cout<<"********** delete SubMesh "<<objectId<<endl;
1465 _SMESHCorbaObj.erase(string("SubMesh_")+string(objectId));
1466 CORBA::release(mySubMesh);
1475 //=============================================================================
1479 //=============================================================================
1481 char* SMESH_Gen_i::ComponentDataType()
1483 MESSAGE("SMESH_Gen_i::ComponentDataType");
1484 return strdup("SMESH");
1488 //=============================================================================
1492 //=============================================================================
1494 char* SMESH_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
1495 const char* IORString,
1496 CORBA::Boolean isMultiFile)
1498 MESSAGE("SMESH_Gen_i::IORToLocalPersistentID");
1502 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(IORString));
1503 if (! CORBA::is_nil(myAlgo))
1505 string prefix = "Hypo_";
1506 sprintf(objectId,"%d",myAlgo->GetId());
1507 string lpID = prefix + string(objectId);
1508 return CORBA::string_dup(lpID.c_str());
1511 SMESH::SMESH_Hypothesis_var myHypo = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(IORString));
1512 if (! CORBA::is_nil(myHypo))
1514 string prefix = "Hypo_";
1515 sprintf(objectId,"%d",myHypo->GetId());
1516 string lpID = prefix + string(objectId);
1517 return CORBA::string_dup(lpID.c_str());
1520 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(IORString));
1521 if (! CORBA::is_nil(myMesh))
1523 string prefix = "Mesh_";
1524 sprintf(objectId,"%d",myMesh->GetId());
1525 string lpID = prefix + string(objectId);
1526 return CORBA::string_dup(lpID.c_str());
1529 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(IORString));
1530 if (! CORBA::is_nil(mySubMesh))
1532 string prefix = "SubMesh_";
1533 sprintf(objectId,"%d",mySubMesh->GetId());
1534 string lpID = prefix + string(objectId);
1535 return CORBA::string_dup(lpID.c_str());
1537 else return (strdup("no object"));
1543 //=============================================================================
1547 //=============================================================================
1549 char* SMESH_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
1550 const char* aLocalPersistentID,
1551 CORBA::Boolean isMultiFile)
1553 MESSAGE("SMESH_Gen_i::LocalPersistentIDToIOR");
1554 SCRUTE(aLocalPersistentID);
1555 string clef = string(aLocalPersistentID);
1556 SCRUTE(_SMESHCorbaObj[clef].c_str());
1557 return CORBA::string_dup(_SMESHCorbaObj[clef].c_str());
1560 //=============================================================================
1564 //=============================================================================
1566 SMESH_topo* SMESH_Gen_i::ExploreMainShape(GEOM::GEOM_Gen_ptr geomEngine,
1567 CORBA::Long studyId,
1568 GEOM::GEOM_Shape_ptr aShape)
1570 MESSAGE("SMESH_Mesh_i::ExploreMainShape");
1571 // _narrow() duplicates the reference and check the type
1572 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
1573 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
1575 if (CORBA::is_nil(geom))
1576 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", \
1578 if (CORBA::is_nil(myShape))
1579 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
1582 SCRUTE(myShape->Name());
1583 geom->GetCurrentStudy(studyId);
1585 TopoDS_Shape mainShape = _ShapeReader->GetShape(geom,myShape);
1588 // create an SMESH_topo object for the mainShape
1590 SMESH_topo* myTopo = new SMESH_topo();
1593 // explore local TopoDS_Shape, store reference of local TopoDS subShapes
1595 for (TopExp_Explorer exp(mainShape,TopAbs_COMPOUND); exp.More(); exp.Next())
1597 const TopoDS_Compound& E = TopoDS::Compound(exp.Current());
1598 int i = myTopo->_myShapes[TopAbs_COMPOUND].Add(E);
1601 for (TopExp_Explorer exp(mainShape,TopAbs_COMPSOLID); exp.More(); exp.Next())
1603 const TopoDS_CompSolid& E = TopoDS::CompSolid(exp.Current());
1604 int i = myTopo->_myShapes[TopAbs_COMPSOLID].Add(E);
1607 for (TopExp_Explorer exp(mainShape,TopAbs_SOLID); exp.More(); exp.Next())
1609 const TopoDS_Solid& E = TopoDS::Solid(exp.Current());
1610 int i = myTopo->_myShapes[TopAbs_SOLID].Add(E);
1613 for (TopExp_Explorer exp(mainShape,TopAbs_SHELL); exp.More(); exp.Next())
1615 const TopoDS_Shell& E = TopoDS::Shell(exp.Current());
1616 int i = myTopo->_myShapes[TopAbs_SHELL].Add(E);
1619 for (TopExp_Explorer exp(mainShape,TopAbs_FACE); exp.More(); exp.Next())
1621 const TopoDS_Face& E = TopoDS::Face(exp.Current());
1622 int i = myTopo->_myShapes[TopAbs_FACE].Add(E);
1625 for (TopExp_Explorer exp(mainShape,TopAbs_WIRE); exp.More(); exp.Next())
1627 const TopoDS_Wire& E = TopoDS::Wire(exp.Current());
1628 int i = myTopo->_myShapes[TopAbs_WIRE].Add(E);
1631 for (TopExp_Explorer exp(mainShape,TopAbs_EDGE); exp.More(); exp.Next())
1633 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1634 int i = myTopo->_myShapes[TopAbs_EDGE].Add(E);
1637 for (TopExp_Explorer exp(mainShape,TopAbs_VERTEX); exp.More(); exp.Next())
1639 const TopoDS_Vertex& E = TopoDS::Vertex(exp.Current());
1640 int i = myTopo->_myShapes[TopAbs_VERTEX].Add(E);
1644 // explore subShapes of distant CORBA object,
1645 // associate distant CORBA subShape references
1646 // with local reference to local TopoDS subShape
1648 string filenode = "toposhape.txt";
1649 ofstream fic(filenode.c_str());
1651 for (int shapeType = TopAbs_COMPOUND; shapeType < TopAbs_SHAPE; shapeType++)
1653 fic << "shape type : " << SMESH_shapeTypeNames[shapeType];
1655 GEOM::GEOM_Gen::ListOfGeomShapes_var subShapes
1656 = geom->SubShapeAll(myShape,shapeType);
1657 int nbSubShapes = subShapes->length();
1658 int nbLocal = myTopo->_myShapes[shapeType].Extent();
1659 fic << " - number of elements: " << nbSubShapes << endl;
1660 ASSERT(nbSubShapes == nbLocal);
1662 for (int i=0; i< nbSubShapes; i++)
1664 GEOM::GEOM_Shape_var aSubShape = subShapes[i];
1665 string idShape = SMESH_topo::GetShapeLocalId(aSubShape);
1666 fic << " " << idShape;
1668 TopoDS_Shape aLocShape = _ShapeReader->GetShape(geom,aSubShape);
1669 for (int j=1; j <= nbLocal; j++)
1670 if (aLocShape.IsSame(myTopo->_myShapes[shapeType].FindKey(j)))
1672 MESSAGE(" --- trouve = " << j);
1673 myTopo->_mapIndShapes[shapeType][idShape] = j;
1674 fic << " --- trouve = " << j;
1685 //=============================================================================
1687 * C factory, accessible with dlsym, after dlopen
1689 //=============================================================================
1693 PortableServer::ObjectId * SMESHEngine_factory(
1695 PortableServer::POA_ptr poa,
1696 PortableServer::ObjectId * contId,
1697 const char *instanceName,
1698 const char *interfaceName)
1700 MESSAGE("PortableServer::ObjectId * SMESHEngine_factory()");
1701 SCRUTE(interfaceName);
1702 SMESH_Gen_i * mySMESH_Gen
1703 = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
1704 return mySMESH_Gen->getId() ;