1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_Gen_i.cxx
25 // Author : Paul RASCLE, EDF
31 #include <TopExp_Explorer.hxx>
33 #include <TopoDS_Iterator.hxx>
34 #include <TopoDS_Compound.hxx>
35 #include <TopoDS_CompSolid.hxx>
36 #include <TopoDS_Solid.hxx>
37 #include <TopoDS_Shell.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopoDS_Wire.hxx>
40 #include <TopoDS_Edge.hxx>
41 #include <TopoDS_Vertex.hxx>
42 #include <TopoDS_Shape.hxx>
43 #include <TopTools_MapOfShape.hxx>
45 #include <BRep_Tool.hxx>
46 #include <TCollection_AsciiString.hxx>
51 #include "SMESH_Gen_i.hxx"
52 #include "SMESH_Mesh_i.hxx"
53 #include "SMESH_LocalLength_i.hxx"
54 #include "SMESH_NumberOfSegments_i.hxx"
55 #include "SMESH_MaxElementArea_i.hxx"
56 #include "SMESH_MaxElementVolume_i.hxx"
58 #include "SMESHDS_Document.hxx"
60 #include "Document_Reader.h"
61 #include "DriverMED_W_SMESHDS_Mesh.h"
62 #include "DriverMED_R_SMESHDS_Mesh.h"
63 #include "DriverMED_R_SMESHDS_Document.h"
64 #include "DriverUNV_R_SMESHDS_Document.h"
65 #include "DriverDAT_R_SMESHDS_Document.h"
67 #include "Utils_CorbaException.hxx"
68 #include "utilities.h"
70 #include "SALOMEDS_Tool.hxx"
71 #include "SALOME_NamingService.hxx"
72 #include "SALOME_LifeCycleCORBA.hxx"
73 #include "Utils_SINGLETON.hxx"
76 //#include <TopAbs_ShapeEnum.hxx>
78 #include "GEOM_Client.hxx"
82 #define NUM_TMP_FILES 4
85 long Tag_HypothesisRoot = 1;
86 long Tag_AlgorithmsRoot = 2;
88 long Tag_RefOnShape = 1;
89 long Tag_RefOnAppliedHypothesis = 2;
90 long Tag_RefOnAppliedAlgorithms = 3;
92 long Tag_SubMeshOnVertex = 4;
93 long Tag_SubMeshOnEdge = 5;
94 long Tag_SubMeshOnFace = 6;
95 long Tag_SubMeshOnSolid = 7;
96 long Tag_SubMeshOnCompound = 8;
99 //=============================================================================
101 * default constructor: not for use
103 //=============================================================================
105 SMESH_Gen_i::SMESH_Gen_i()
107 MESSAGE("SMESH_Gen_i default constructor");
111 //=============================================================================
113 * Standard constructor, used with Container.
115 //=============================================================================
117 SMESH_Gen_i::SMESH_Gen_i(CORBA::ORB_ptr orb,
118 PortableServer::POA_ptr poa,
119 PortableServer::ObjectId * contId,
120 const char *instanceName,
121 const char *interfaceName) :
122 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
124 MESSAGE("activate object");
126 _id = _poa->activate_object(_thisObj);
129 _localId = 0; // number of created objects & local id
133 //=============================================================================
135 * Standard destructor
137 //=============================================================================
139 SMESH_Gen_i::~SMESH_Gen_i()
141 MESSAGE("~SMESH_Gen_i");
145 //=============================================================================
149 //=============================================================================
151 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis(const char* anHyp,
153 throw (SALOME::SALOME_Exception)
155 MESSAGE("CreateHypothesis");
157 // create a new hypothesis object servant
159 SMESH_Hypothesis_i* myHypothesis_i = 0;
162 myHypothesis_i = _hypothesisFactory_i.Create(anHyp,
166 catch (SALOME_Exception& S_ex)
168 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
171 // activate the CORBA servant of hypothesis
173 SMESH::SMESH_Hypothesis_var hypothesis_i
174 = SMESH::SMESH_Hypothesis::_narrow(myHypothesis_i->_this());
175 return SMESH::SMESH_Hypothesis::_duplicate(hypothesis_i);
178 //=============================================================================
182 //=============================================================================
184 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Init(GEOM::GEOM_Gen_ptr geomEngine,
186 GEOM::GEOM_Shape_ptr aShape)
187 throw (SALOME::SALOME_Exception)
190 // _narrow() duplicates the reference and checks the type
191 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
192 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
194 if (CORBA::is_nil(geom))
195 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", \
197 if (CORBA::is_nil(myShape))
198 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
201 // Get or create the GEOM_Client instance
203 SMESH_Mesh_i* meshServant = 0;
206 if (! _ShapeReader) _ShapeReader = new GEOM_Client();
207 ASSERT(_ShapeReader);
209 // explore main Shape, get local TopoDS_Shapes of all subShapes
210 // SMESH_topo* myTopo = ExploreMainShape(geom, studyId, myShape);
212 // Get studyContext_i, create it if it does'nt exist
214 if (_mapStudyContext_i.find(studyId) == _mapStudyContext_i.end())
216 _mapStudyContext_i[studyId] = new StudyContext_iStruct;
218 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
220 // create a new mesh object servant, store it in a map in study context
222 meshServant = new SMESH_Mesh_i(this,
226 myStudyContext->mapMesh_i[_localId] = meshServant;
229 // create a new mesh object
231 TopoDS_Shape myLocShape = _ShapeReader->GetShape(geom,myShape);
232 meshServant->SetImpl(_impl.Init(studyId, myLocShape));
234 catch (SALOME_Exception& S_ex)
236 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
239 // activate the CORBA servant of Mesh
241 SMESH::SMESH_Mesh_var mesh
242 = SMESH::SMESH_Mesh::_narrow(meshServant->_this());
244 meshServant->SetIor(mesh);
246 return SMESH::SMESH_Mesh::_duplicate(mesh);
250 //=============================================================================
254 //=============================================================================
256 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute(SMESH::SMESH_Mesh_ptr aMesh,
257 GEOM::GEOM_Shape_ptr aShape)
258 throw (SALOME::SALOME_Exception)
260 MESSAGE("SMESH_Gen_i::IsReadyToCompute");
264 //=============================================================================
268 //=============================================================================
271 SMESH_Gen_i::GetSubShapesId(GEOM::GEOM_Gen_ptr geomEngine,
273 GEOM::GEOM_Shape_ptr mainShape,
274 const SMESH::shape_array& listOfSubShape)
275 throw (SALOME::SALOME_Exception)
277 MESSAGE("SMESH_Gen_i::GetSubShapesId");
278 SMESH::long_array_var shapesId = new SMESH::long_array;
281 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
282 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(mainShape);
284 if (CORBA::is_nil(geom))
285 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", \
287 if (CORBA::is_nil(myShape))
288 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
293 if (! _ShapeReader) _ShapeReader = new GEOM_Client();
294 ASSERT(_ShapeReader);
295 TopoDS_Shape myMainShape = _ShapeReader->GetShape(geom,myShape);
296 TopTools_IndexedMapOfShape myIndexToShape;
297 TopExp::MapShapes(myMainShape,myIndexToShape);
299 for (int i=0; i<listOfSubShape.length(); i++)
301 GEOM::GEOM_Shape_var aShape
302 = GEOM::GEOM_Shape::_narrow(listOfSubShape[i]);
303 if (CORBA::is_nil(aShape))
304 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
306 TopoDS_Shape locShape = _ShapeReader->GetShape(geom,aShape);
307 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
309 const TopoDS_Face& F = TopoDS::Face(exp.Current());
310 setId.insert(myIndexToShape.FindIndex(F));
311 SCRUTE(myIndexToShape.FindIndex(F));
313 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
315 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
316 setId.insert(myIndexToShape.FindIndex(E));
317 SCRUTE(myIndexToShape.FindIndex(E));
319 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
321 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
322 setId.insert(myIndexToShape.FindIndex(V));
323 SCRUTE(myIndexToShape.FindIndex(V));
326 shapesId->length(setId.size());
327 set<int>::iterator iind;
329 for (iind = setId.begin(); iind != setId.end(); iind++)
332 shapesId[i] = (*iind);
337 catch (SALOME_Exception& S_ex)
339 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
342 return shapesId._retn();
345 //=============================================================================
349 //=============================================================================
351 CORBA::Boolean SMESH_Gen_i::Compute(SMESH::SMESH_Mesh_ptr aMesh,
352 GEOM::GEOM_Shape_ptr aShape)
353 throw (SALOME::SALOME_Exception)
355 MESSAGE("SMESH_Gen_i::Compute");
356 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
357 if (CORBA::is_nil(myShape))
358 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
361 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(aMesh);
362 if (CORBA::is_nil(myMesh))
363 THROW_SALOME_CORBA_EXCEPTION("bad Mesh reference", \
370 // get study context from studyId given by CORBA mesh object
372 int studyId = myMesh->GetStudyId();
373 ASSERT(_mapStudyContext_i.find(studyId) != _mapStudyContext_i.end());
374 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
376 // get local Mesh_i object with Id and study context
378 int meshId = myMesh->GetId();
379 ASSERT(myStudyContext->mapMesh_i.find(meshId) != myStudyContext->mapMesh_i.end());
380 SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
383 // get local TopoDS_Shape
385 GEOM::GEOM_Gen_var geom = meshServant->GetGeomEngine();
386 TopoDS_Shape myLocShape = _ShapeReader->GetShape(geom,myShape);
388 // implementation compute
390 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
391 ret = _impl.Compute(myLocMesh, myLocShape);
393 catch (SALOME_Exception& S_ex)
395 MESSAGE("catch exception "<< S_ex.what());
397 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
404 //=============================================================================
408 //=============================================================================
410 SALOMEDS::TMPFile* SMESH_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
414 MESSAGE("SMESH_Gen_i::SAVE");
415 SALOMEDS::Study_var Study = theComponent->GetStudy();
418 // Declare a byte stream
419 SALOMEDS::TMPFile_var aStreamFile;
421 // Obtain a temporary dir
422 TCollection_AsciiString tmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
424 // Create a sequence of files processed
425 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
426 aFileSeq->length(NUM_TMP_FILES);
428 TCollection_AsciiString aStudyName(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
430 // Set names of temporary files
431 TCollection_AsciiString filename = aStudyName + TCollection_AsciiString("SMESH.hdf");
432 TCollection_AsciiString hypofile = aStudyName + TCollection_AsciiString("SMESH_Hypo.txt");
433 TCollection_AsciiString algofile = aStudyName + TCollection_AsciiString("SMESH_Algo.txt");
434 TCollection_AsciiString meshfile = aStudyName + TCollection_AsciiString("SMESH_Mesh.med");
435 aFileSeq[0] = CORBA::string_dup(filename.ToCString());
436 aFileSeq[1] = CORBA::string_dup(hypofile.ToCString());
437 aFileSeq[2] = CORBA::string_dup(algofile.ToCString());
438 aFileSeq[3] = CORBA::string_dup(meshfile.ToCString());
439 filename = tmpDir + filename;
440 hypofile = tmpDir + hypofile;
441 algofile = tmpDir + algofile;
442 meshfile = tmpDir + meshfile;
445 map <int,HDFgroup*> hdf_group, hdf_subgroup;
446 map <int,HDFdataset*> hdf_dataset;
449 SALOMEDS::ChildIterator_var itBig,it,itSM;
450 SALOMEDS::SObject_var mySObject,myBranch,mySObjectChild;
452 int longueur,cmpt_ds = 0,cmpt_it;
453 char *name_group,name_dataset[30],name_meshgroup[30];
455 int cmpt_sm = 0, myTag;
457 //************* HDF file creation
458 hdf_file = new HDFfile(filename.ToCString());
459 hdf_file->CreateOnDisk();
460 //****************************
462 itBig = Study->NewChildIterator(theComponent);
463 for (; itBig->More();itBig->Next()) {
464 SALOMEDS::SObject_var gotBranch = itBig->Value();
466 //************branch 1 : hypothesis
467 if (gotBranch->Tag()==Tag_HypothesisRoot) { //hypothesis = tag 1
469 double length,maxElementsArea,maxElementsVolume;
470 int numberOfSegments;
472 destFile = fopen( hypofile.ToCString() ,"w");
473 it = Study->NewChildIterator(gotBranch);
474 for (; it->More();it->Next()) {
475 mySObject = it->Value();
476 SALOMEDS::GenericAttribute_var anAttr;
477 SALOMEDS::AttributeIOR_var anIOR;
478 if ( mySObject->FindAttribute(anAttr, "AttributeIOR")) {
479 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
481 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
482 fprintf(destFile,"%s\n",myHyp->GetName());
484 if (strcmp(myHyp->GetName(),"LocalLength")==0) {
485 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( myHyp );
486 length = LL->GetLength();
487 fprintf(destFile,"%f\n",length);
489 else if (strcmp(myHyp->GetName(),"NumberOfSegments")==0) {
490 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( myHyp );
491 numberOfSegments = NOS->GetNumberOfSegments();
492 fprintf(destFile,"%d\n",numberOfSegments);
494 else if (strcmp(myHyp->GetName(),"MaxElementArea")==0) {
495 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( myHyp );
496 maxElementsArea = MEA->GetMaxElementArea();
497 fprintf(destFile,"%f\n",maxElementsArea);
499 else if (strcmp(myHyp->GetName(),"MaxElementVolume")==0) {
500 SMESH::SMESH_MaxElementVolume_var MEV = SMESH::SMESH_MaxElementVolume::_narrow( myHyp );
501 maxElementsVolume = MEV->GetMaxElementVolume();
502 fprintf(destFile,"%f\n",maxElementsVolume);
508 //writes the file name in the hdf file
509 longueur = hypofile.Length() +1;
510 name_group="Hypothesis";
511 //SCRUTE(name_group);
514 hdf_group[1] = new HDFgroup(name_group,hdf_file);
515 hdf_group[1]->CreateOnDisk();
517 hdf_dataset[cmpt_ds]=new HDFdataset(name_group,hdf_group[1],HDF_STRING,size,1);
518 hdf_dataset[cmpt_ds]->CreateOnDisk();
519 hdf_dataset[cmpt_ds]->WriteOnDisk(hypofile.ToCString());
520 hdf_dataset[cmpt_ds]->CloseOnDisk();
523 hdf_group[1]->CloseOnDisk();
524 MESSAGE("End of Hypothesis Save");
527 //************branch 2 : algorithms
528 else if (gotBranch->Tag()==Tag_AlgorithmsRoot) {//algos = tag 2
530 destFile = fopen( algofile.ToCString() ,"w");
531 it = Study->NewChildIterator(gotBranch);
532 for (; it->More();it->Next()) {
533 mySObject = it->Value();
534 SALOMEDS::GenericAttribute_var anAttr;
535 SALOMEDS::AttributeIOR_var anIOR;
536 if (mySObject->FindAttribute(anAttr, "AttributeIOR")) {
537 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
538 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(anIOR->Value()));
539 fprintf(destFile,"%s\n",myAlgo->GetName());
545 //writes the file name in the hdf file
546 longueur = algofile.Length() +1;
547 name_group="Algorithms";
548 //SCRUTE(name_group);
551 hdf_group[2] = new HDFgroup(name_group,hdf_file);
552 hdf_group[2]->CreateOnDisk();
554 hdf_dataset[cmpt_ds]=new HDFdataset(name_group,hdf_group[2],HDF_STRING,size,1);
555 hdf_dataset[cmpt_ds]->CreateOnDisk();
556 hdf_dataset[cmpt_ds]->WriteOnDisk(algofile.ToCString());
557 hdf_dataset[cmpt_ds]->CloseOnDisk();
560 hdf_group[2]->CloseOnDisk();
561 MESSAGE("End of Algos Save");
564 //************branch 3 : meshes
565 else if (gotBranch->Tag()>=3) {//meshes = tag > 3
567 SALOMEDS::GenericAttribute_var anAttr;
568 SALOMEDS::AttributeIOR_var anIOR;
569 if (gotBranch->FindAttribute(anAttr, "AttributeIOR")) {
570 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
572 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value())) ;
573 studyId = myMesh->GetStudyId();
576 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
577 int meshId = myMesh->GetId();
578 SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
579 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
580 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
582 SCRUTE(mySMESHDSMesh->NbNodes());
583 if (mySMESHDSMesh->NbNodes()>0) {//checks if the mesh is not empty
585 DriverMED_W_SMESHDS_Mesh* myWriter = new DriverMED_W_SMESHDS_Mesh;
586 myWriter->SetFile(meshfile.ToCString());
588 myWriter->SetMesh(mySMESHDSMesh);
589 myWriter->SetMeshId(gotBranch->Tag());
592 else meshfile = "No data";
594 //********** opening of the HDF group
595 sprintf(name_meshgroup,"Mesh %d",gotBranch->Tag());
596 SCRUTE(name_meshgroup);
597 hdf_group[gotBranch->Tag()] = new HDFgroup(name_meshgroup,hdf_file);
598 hdf_group[gotBranch->Tag()]->CreateOnDisk();
601 //********** file where the data are stored
602 longueur = strlen(meshfile.ToCString()) +1;
604 strcpy(name_dataset,"Mesh data");
605 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_group[gotBranch->Tag()],HDF_STRING,size,1);
606 hdf_dataset[cmpt_ds]->CreateOnDisk();
607 hdf_dataset[cmpt_ds]->WriteOnDisk(meshfile.ToCString());
608 hdf_dataset[cmpt_ds]->CloseOnDisk();
612 //********** ref on shape
613 Standard_CString myRefOnObject="" ;
614 SALOMEDS::SObject_var myRef,myShape;
615 _found = gotBranch->FindSubObject(Tag_RefOnShape,myRef);
617 ok = myRef->ReferencedObject(myShape);
618 myRefOnObject = myShape->GetID();
619 SCRUTE(myRefOnObject);
621 longueur = strlen(myRefOnObject) +1;
624 strcpy(name_dataset,"Ref on shape");
625 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_group[gotBranch->Tag()],HDF_STRING,size,1);
626 hdf_dataset[cmpt_ds]->CreateOnDisk();
627 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
628 hdf_dataset[cmpt_ds]->CloseOnDisk();
635 //********** ref on applied hypothesis
636 _found = gotBranch->FindSubObject(Tag_RefOnAppliedHypothesis,myBranch);
639 strcpy(name_meshgroup,"Applied Hypothesis");
640 hdf_subgroup[Tag_RefOnAppliedHypothesis] = new HDFgroup(name_meshgroup,hdf_group[gotBranch->Tag()]);
641 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CreateOnDisk();
643 it = Study->NewChildIterator(myBranch);
645 for (; it->More();it->Next()) {
646 mySObject = it->Value();
647 ok = mySObject->ReferencedObject(myRef);
648 myRefOnObject = myRef->GetID();
650 longueur = strlen(myRefOnObject) +1;
653 sprintf(name_dataset,"Hyp %d",cmpt_it);
654 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedHypothesis],HDF_STRING,size,1);
655 hdf_dataset[cmpt_ds]->CreateOnDisk();
656 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
657 hdf_dataset[cmpt_ds]->CloseOnDisk();
662 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CloseOnDisk();
666 //********** ref on applied algorithms
667 _found = gotBranch->FindSubObject(Tag_RefOnAppliedAlgorithms,myBranch);
670 strcpy(name_meshgroup,"Applied Algorithms");
671 hdf_subgroup[Tag_RefOnAppliedAlgorithms] = new HDFgroup(name_meshgroup,hdf_group[gotBranch->Tag()]);
672 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CreateOnDisk();
674 it = Study->NewChildIterator(myBranch);
676 for (; it->More();it->Next()) {
677 mySObject = it->Value();
678 ok = mySObject->ReferencedObject(myRef);
679 myRefOnObject = myRef->GetID();
681 longueur = strlen(myRefOnObject) +1;
684 sprintf(name_dataset,"Algo %d",cmpt_it);
685 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedAlgorithms],HDF_STRING,size,1);
686 hdf_dataset[cmpt_ds]->CreateOnDisk();
687 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
688 hdf_dataset[cmpt_ds]->CloseOnDisk();
693 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CloseOnDisk();
695 MESSAGE("end of algo applied");
698 //********** submeshes on subshapes
700 for (int i=Tag_SubMeshOnVertex;i<=Tag_SubMeshOnCompound;i++) {
701 _found = gotBranch->FindSubObject(i,myBranch);
703 if (i==Tag_SubMeshOnVertex)
704 strcpy(name_meshgroup,"SubMeshes On Vertex");
705 else if (i==Tag_SubMeshOnEdge)
706 strcpy(name_meshgroup,"SubMeshes On Edge");
707 else if (i==Tag_SubMeshOnFace)
708 strcpy(name_meshgroup,"SubMeshes On Face");
709 else if (i==Tag_SubMeshOnSolid)
710 strcpy(name_meshgroup,"SubMeshes On Solid");
711 else if (i==Tag_SubMeshOnCompound)
712 strcpy(name_meshgroup,"SubMeshes On Compound");
715 myLevel1Tag = 10+cmpt_sm;
716 hdf_subgroup[myLevel1Tag] = new HDFgroup(name_meshgroup,hdf_group[gotBranch->Tag()]);
717 hdf_subgroup[myLevel1Tag]->CreateOnDisk();
719 itSM = Study->NewChildIterator(myBranch);
720 for (; itSM->More();itSM->Next()) {//Loop on all submeshes
721 mySObject = itSM->Value();
724 mySObject->FindAttribute(anAttr, "AttributeIOR");
725 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
726 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value())) ;
728 //sprintf(name_meshgroup,"SubMesh %d",myTag);
729 sprintf(name_meshgroup,"SubMesh %d",mySubMesh->GetId());
730 SCRUTE(name_meshgroup);
732 hdf_subgroup[myTag] = new HDFgroup(name_meshgroup,hdf_subgroup[myLevel1Tag]);
733 hdf_subgroup[myTag]->CreateOnDisk();
735 //********** ref on shape
736 Standard_CString myRefOnObject="" ;
737 SALOMEDS::SObject_var myRef,myShape;
739 _found2 = mySObject->FindSubObject(Tag_RefOnShape,myRef);
741 ok = myRef->ReferencedObject(myShape);
742 myRefOnObject = myShape->GetID();
743 SCRUTE(myRefOnObject);
745 longueur = strlen(myRefOnObject) +1;
748 strcpy(name_dataset,"Ref on shape");
749 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[myTag],HDF_STRING,size,1);
750 hdf_dataset[cmpt_ds]->CreateOnDisk();
751 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
752 hdf_dataset[cmpt_ds]->CloseOnDisk();
758 //********** ref on applied hypothesis
759 _found2 = mySObject->FindSubObject(Tag_RefOnAppliedHypothesis,myBranch);
762 strcpy(name_meshgroup,"Applied Hypothesis");
764 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
765 hdf_subgroup[10+cmpt_sm]->CreateOnDisk();
767 it = Study->NewChildIterator(myBranch);
769 for (; it->More();it->Next()) {
770 mySObjectChild = it->Value();
771 ok = mySObjectChild->ReferencedObject(myRef);
772 myRefOnObject = myRef->GetID();
774 longueur = strlen(myRefOnObject) +1;
777 sprintf(name_dataset,"Hyp %d",cmpt_it);
779 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm],HDF_STRING,size,1);
780 hdf_dataset[cmpt_ds]->CreateOnDisk();
781 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
782 hdf_dataset[cmpt_ds]->CloseOnDisk();
787 hdf_subgroup[10+cmpt_sm]->CloseOnDisk();
791 //********** ref on applied algorithms
792 _found2 = mySObject->FindSubObject(Tag_RefOnAppliedAlgorithms,myBranch);
796 strcpy(name_meshgroup,"Applied Algorithms");
798 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
799 hdf_subgroup[10+cmpt_sm]->CreateOnDisk();
801 it = Study->NewChildIterator(myBranch);
803 for (; it->More();it->Next()) {
804 mySObjectChild = it->Value();
805 ok = mySObjectChild->ReferencedObject(myRef);
806 myRefOnObject = myRef->GetID();
808 longueur = strlen(myRefOnObject) +1;
811 sprintf(name_dataset,"Algo %d",cmpt_it);
812 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm],HDF_STRING,size,1);
813 hdf_dataset[cmpt_ds]->CreateOnDisk();
814 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
815 hdf_dataset[cmpt_ds]->CloseOnDisk();
820 hdf_subgroup[10+cmpt_sm]->CloseOnDisk();
822 //MESSAGE("end of algo applied");
825 hdf_subgroup[myTag]->CloseOnDisk();
828 hdf_subgroup[myLevel1Tag]->CloseOnDisk();
834 //********** closing of the HDF group
835 hdf_group[gotBranch->Tag()]->CloseOnDisk();
836 MESSAGE("End of Mesh Save");
840 MESSAGE("End of Meshes Save");
843 hdf_file->CloseOnDisk();
847 // Convert temporary files to stream
848 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.ToCString(), aFileSeq.in(), isMultiFile);
850 // Remove temporary files and directory
851 if (isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(), true);
853 MESSAGE("End SMESH_Gen_i::Save");
855 return aStreamFile._retn();
858 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
861 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
862 return aStreamFile._retn();
865 //=============================================================================
869 //=============================================================================
871 bool SMESH_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
872 const SALOMEDS::TMPFile& theStream,
876 MESSAGE("SMESH_Gen_i::Load\n");
878 // Get temporary files location
879 TCollection_AsciiString tmpDir = isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
881 // Convert the stream into sequence of files to process
882 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
886 // Set names of temporary files
887 TCollection_AsciiString filename = tmpDir + aFileSeq[0];//"SMESH.hdf";
888 TCollection_AsciiString hypofile = tmpDir + aFileSeq[1];//"SMESH_Hypo.txt";
889 TCollection_AsciiString algofile = tmpDir + aFileSeq[2];//"SMESH_Algo.txt";
890 TCollection_AsciiString meshfile = tmpDir + aFileSeq[3];//"SMESH_Mesh.med";
892 SALOMEDS::Study_var Study = theComponent->GetStudy();
893 int studyId = Study->StudyId();
896 SALOMEDS::GenericAttribute_var anAttr;
897 SALOMEDS::AttributeName_var aName;
898 SALOMEDS::AttributeIOR_var anIOR;
900 SALOMEDS::SComponent_var fathergeom = Study->FindComponent("GEOM");
901 SALOMEDS::SComponent_var myGeomSComp = SALOMEDS::SComponent::_narrow( fathergeom );
904 //to get the geom engine !!!
905 //useful to define our new mesh
906 SALOME_NamingService* _NS = SINGLETON_<SALOME_NamingService>::Instance() ;
907 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
908 _NS->init_orb( _orb ) ;
909 SALOME_LifeCycleCORBA* myEnginesLifeCycle = new SALOME_LifeCycleCORBA(_NS);
910 Engines::Component_var geomEngine =
911 myEnginesLifeCycle->FindOrLoad_Component("FactoryServer","GEOM");
912 GEOM::GEOM_Gen_var myGeomEngine = GEOM::GEOM_Gen::_narrow(geomEngine);
917 char objectId[10],name_dataset[10];
918 int nb_datasets,size,cmpt_ds=0;
921 char name[HDF_NAME_MAX_LEN+1];
922 char sgname[HDF_NAME_MAX_LEN+1];
923 char msgname[HDF_NAME_MAX_LEN+1];
924 char name_of_group[HDF_NAME_MAX_LEN+1];
925 char *name_meshgroup;
926 map <int,HDFgroup*> hdf_group, hdf_subgroup;
927 map <int,HDFdataset*> hdf_dataset;
930 //************* HDF file opening
931 HDFfile * hdf_file = new HDFfile(filename.ToCString());
933 hdf_file->OpenOnDisk(HDF_RDONLY);
935 catch (HDFexception) {
936 MESSAGE("Load(): " << filename << " not found!");
940 //****************************
942 int nb_group = hdf_file->nInternalObjects();
944 for (int i=0;i<nb_group;i++)
946 hdf_file->InternalObjectIndentify(i,name);
950 // Loading of the Hypothesis Branch
952 if (strcmp(name,"Hypothesis")==0) {
954 double length,maxElementsArea,maxElementsVolume;
955 int numberOfSegments;
957 hdf_group[Tag_HypothesisRoot] = new HDFgroup(name,hdf_file);
958 hdf_group[Tag_HypothesisRoot]->OpenOnDisk();
960 hdf_group[Tag_HypothesisRoot]->InternalObjectIndentify(0,name_of_group);
961 hdf_dataset[cmpt_ds]=new HDFdataset(name_of_group,hdf_group[Tag_HypothesisRoot]);
962 hdf_dataset[cmpt_ds]->OpenOnDisk();
963 size=hdf_dataset[cmpt_ds]->GetSize();
965 char * name_of_file =new char[size];
966 hdf_dataset[cmpt_ds]->ReadFromDisk(name_of_file);
967 SCRUTE(name_of_file);
968 hdf_dataset[cmpt_ds]->CloseOnDisk();
969 hdf_group[Tag_HypothesisRoot]->CloseOnDisk();
971 delete[] name_of_file;
974 aLine = new char[100];
975 loadedFile = fopen( hypofile.ToCString() ,"r");
976 while (!feof(loadedFile)) {
977 fscanf(loadedFile,"%s",aLine);
979 if (strcmp(aLine,"LocalLength")==0) {
980 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
981 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( myHyp );
982 fscanf(loadedFile,"%s",aLine);
983 length = atof(aLine);
984 LL->SetLength(length);
985 string iorString = _orb->object_to_string(LL);
986 sprintf(objectId,"%d",LL->GetId());
987 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
989 else if (strcmp(aLine,"NumberOfSegments")==0) {
990 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
991 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( myHyp );
992 fscanf(loadedFile,"%s",aLine);
993 numberOfSegments = atoi(aLine);
994 NOS->SetNumberOfSegments(numberOfSegments);
995 string iorString = _orb->object_to_string(NOS);
996 sprintf(objectId,"%d",NOS->GetId());
997 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
999 else if (strcmp(aLine,"MaxElementArea")==0) {
1000 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
1001 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( myHyp );
1002 fscanf(loadedFile,"%s",aLine);
1003 maxElementsArea = atof(aLine);
1004 MEA->SetMaxElementArea(maxElementsArea);
1005 string iorString = _orb->object_to_string(MEA);
1006 sprintf(objectId,"%d",MEA->GetId());
1007 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
1009 else if (strcmp(aLine,"MaxElementVolume")==0) {
1010 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
1011 SMESH::SMESH_MaxElementVolume_var MEV = SMESH::SMESH_MaxElementVolume::_narrow( myHyp );
1012 fscanf(loadedFile,"%s",aLine);
1013 maxElementsVolume = atof(aLine);
1014 MEV->SetMaxElementVolume(maxElementsVolume);
1015 string iorString = _orb->object_to_string(MEV);
1016 sprintf(objectId,"%d",MEV->GetId());
1017 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
1025 MESSAGE("End of Hypos Load");
1029 // Loading of the Algorithms Branch
1031 else if (strcmp(name,"Algorithms")==0) {
1033 hdf_group[Tag_AlgorithmsRoot] = new HDFgroup(name,hdf_file);
1034 hdf_group[Tag_AlgorithmsRoot]->OpenOnDisk();
1036 hdf_group[Tag_AlgorithmsRoot]->InternalObjectIndentify(0,name_of_group);
1037 hdf_dataset[cmpt_ds] = new HDFdataset(name_of_group,hdf_group[Tag_AlgorithmsRoot]);
1038 hdf_dataset[cmpt_ds]->OpenOnDisk();
1039 size=hdf_dataset[cmpt_ds]->GetSize();
1041 char * name_of_file =new char[size];
1042 hdf_dataset[cmpt_ds]->ReadFromDisk(name_of_file);
1043 hdf_dataset[cmpt_ds]->CloseOnDisk();
1044 hdf_group[Tag_AlgorithmsRoot]->CloseOnDisk();
1046 delete[] name_of_file;
1049 aLine = new char[100];
1050 loadedFile = fopen( algofile.ToCString(),"r");
1051 while (!feof(loadedFile)) {
1052 fscanf(loadedFile,"%s\n",aLine);
1054 if (strcmp(aLine,"")!=0) {
1055 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
1056 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1057 string iorString = _orb->object_to_string(myAlgo);
1058 sprintf(objectId,"%d",myAlgo->GetId());
1059 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
1065 MESSAGE("End of Algos Load");
1070 // Loading of the Mesh Branch
1072 else if (string(name).substr(0,4)==string("Mesh")) {
1073 MESSAGE("in mesh load");
1075 Standard_Integer myMeshId = atoi((string(name).substr(5,5)).c_str());
1078 hdf_group[myMeshId] = new HDFgroup(name,hdf_file);
1079 hdf_group[myMeshId]->OpenOnDisk();
1081 int nb_meshsubgroup = hdf_group[myMeshId]->nInternalObjects();
1082 SCRUTE(nb_meshsubgroup);
1084 //********** Loading of the file name where the data are stored
1085 MESSAGE("Mesh data file");
1086 strcpy(name_of_group,"Mesh data");
1087 hdf_dataset[cmpt_ds]=new HDFdataset(name_of_group,hdf_group[myMeshId]);
1088 hdf_dataset[cmpt_ds]->OpenOnDisk();
1089 size=hdf_dataset[cmpt_ds]->GetSize();
1091 char * datafilename =new char[size];
1092 hdf_dataset[cmpt_ds]->ReadFromDisk(datafilename);
1093 hdf_dataset[cmpt_ds]->CloseOnDisk();
1098 //else if (strcmp(msgname,"Ref on shape")==0) {
1100 //********** Loading of the reference on the shape
1101 //********** and mesh initialization
1102 MESSAGE("Ref on shape");
1103 strcpy(name_of_group,"Ref on shape");
1104 hdf_dataset[cmpt_ds] = new HDFdataset(name_of_group,hdf_group[myMeshId]);
1105 hdf_dataset[cmpt_ds]->OpenOnDisk();
1106 size=hdf_dataset[cmpt_ds]->GetSize();
1108 char * refFromFile =new char[size];
1109 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1110 hdf_dataset[cmpt_ds]->CloseOnDisk();
1113 Standard_CString myRefOnShape=""; //look for ref on shape
1115 bool _found = false;
1116 SALOMEDS::SObject_var CSO = Study->FindObjectID(refFromFile);
1117 SMESH::SMESH_Mesh_var myNewMesh;
1118 GEOM::GEOM_Shape_var aShape;
1120 if (!CORBA::is_nil(CSO)) {
1122 CSO->FindAttribute(anAttr, "AttributeIOR");
1123 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1124 char* ShapeIOR = anIOR->Value();
1125 aShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(ShapeIOR));
1127 myNewMesh = this->Init(myGeomEngine,studyId,aShape);
1128 string iorString = _orb->object_to_string(myNewMesh);
1129 sprintf(objectId,"%d",myNewMesh->GetId());
1130 _SMESHCorbaObj[string("Mesh_")+string(objectId)] = iorString;
1133 //********** Loading of mesh data
1134 if (strcmp(datafilename,"No data")!=0) {
1139 //****************************************************************************
1140 //* OUVERTURE DU FICHIER EN LECTURE *
1141 //****************************************************************************
1143 fid = MEDouvrir(datafilename,MED_LECT);
1146 printf(">> ERREUR : ouverture du fichier %s \n",datafilename);
1151 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
1152 int meshId = myNewMesh->GetId();
1153 SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
1154 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1155 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
1157 DriverMED_R_SMESHDS_Mesh* myReader = new DriverMED_R_SMESHDS_Mesh;
1159 myReader->SetMesh(mySMESHDSMesh);
1160 myReader->SetMeshId(myMeshId);
1161 myReader->SetFileId(fid);
1162 myReader->ReadMySelf();
1163 //SCRUTE(mySMESHDSMesh->NbNodes());
1164 //myNewMesh->ExportUNV("/tmp/test.unv");//only to check out
1166 //****************************************************************************
1167 //* FERMETURE DU FICHIER *
1168 //****************************************************************************
1169 ret = MEDfermer(fid);
1172 printf(">> ERREUR : erreur a la fermeture du fichier %s\n",datafilename);
1179 //else if (strcmp(msgname,"Applied Hypothesis")==0) {
1180 for (int ii=0;ii<nb_meshsubgroup;ii++)
1182 hdf_group[myMeshId]->InternalObjectIndentify(ii,msgname);
1183 if (strcmp(msgname,"Mesh data")==0) {
1186 else if (strcmp(msgname,"Ref on shape")==0) {
1189 else if (strcmp(msgname,"Applied Hypothesis")==0) {
1190 //********** Loading of the applied hypothesis
1191 strcpy(name_of_group,"Applied Hypothesis");
1192 hdf_subgroup[Tag_RefOnAppliedHypothesis] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1193 hdf_subgroup[Tag_RefOnAppliedHypothesis]->OpenOnDisk();
1195 nb_datasets = hdf_subgroup[Tag_RefOnAppliedHypothesis]->nInternalObjects();
1196 SCRUTE(nb_datasets);
1198 for (int j=0;j<nb_datasets;j++) {
1199 sprintf(name_dataset,"Hyp %d",j);
1200 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedHypothesis]);
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 //SCRUTE(refFromFile);
1207 hdf_dataset[cmpt_ds]->CloseOnDisk();
1210 SALOMEDS::SObject_var HypSO = Study->FindObjectID(refFromFile);
1211 if (!CORBA::is_nil(HypSO)) {
1212 HypSO->FindAttribute(anAttr, "AttributeIOR");
1213 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1214 if (!CORBA::is_nil(anIOR)) {
1215 char* HypIOR = anIOR->Value();
1216 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(HypIOR));
1217 if (!CORBA::is_nil(anHyp)) {
1218 myNewMesh->AddHypothesis(aShape,anHyp);
1219 MESSAGE("Hypothesis added ...");
1226 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CloseOnDisk();
1229 else if (strcmp(msgname,"Applied Algorithms")==0) {
1231 //********** Loading of the applied algorithms
1232 strcpy(name_of_group,"Applied Algorithms");
1233 hdf_subgroup[Tag_RefOnAppliedAlgorithms] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1234 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->OpenOnDisk();
1236 nb_datasets = hdf_subgroup[Tag_RefOnAppliedAlgorithms]->nInternalObjects();
1237 SCRUTE(nb_datasets);
1239 for (int j=0;j<nb_datasets;j++) {
1240 sprintf(name_dataset,"Algo %d",j);
1241 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedAlgorithms]);
1242 hdf_dataset[cmpt_ds]->OpenOnDisk();
1243 size=hdf_dataset[cmpt_ds]->GetSize();
1245 char * refFromFile =new char[size];
1246 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1247 hdf_dataset[cmpt_ds]->CloseOnDisk();
1251 SALOMEDS::SObject_var AlgoSO = Study->FindObjectID(refFromFile);
1252 if (!CORBA::is_nil(AlgoSO)) {
1253 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1254 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1255 if (!CORBA::is_nil(anIOR)) {
1256 char* AlgoIOR = anIOR->Value();
1258 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(AlgoIOR));
1259 SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1260 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1261 if (!CORBA::is_nil(anAlgo)) {
1262 myNewMesh->AddHypothesis(aShape,anAlgo);//essayer avec _SMESHCorbaObj
1263 MESSAGE("Algorithms added ...");
1270 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CloseOnDisk();
1274 else if (string(msgname).substr(0,9)==string("SubMeshes")) {
1277 //********** Loading of the submeshes on subshapes
1278 int myLevel1Tag, myTag;
1281 myLevel1Tag = 10+cmpt_sm;
1282 hdf_subgroup[myLevel1Tag] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1283 hdf_subgroup[myLevel1Tag] = new HDFgroup(msgname,hdf_group[myMeshId]);
1284 hdf_subgroup[myLevel1Tag]->OpenOnDisk();
1286 int nb_submeshes = hdf_subgroup[myLevel1Tag]->nInternalObjects();
1287 SCRUTE(nb_submeshes);
1289 for (int j=0;j<nb_submeshes;j++) {
1292 hdf_subgroup[myLevel1Tag]->InternalObjectIndentify(j,name_meshgroup);
1293 SCRUTE(name_meshgroup);
1295 hdf_subgroup[myTag] = new HDFgroup(name_meshgroup,hdf_subgroup[myLevel1Tag]);
1296 hdf_subgroup[myTag]->OpenOnDisk();
1297 int subMeshId = atoi((string(name_meshgroup).substr(8,18)).c_str());
1299 MESSAGE("Ref on shape");
1300 //********** ref on shape
1301 sprintf(name_dataset,"Ref on shape");
1302 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[myTag]);
1303 hdf_dataset[cmpt_ds]->OpenOnDisk();
1304 size=hdf_dataset[cmpt_ds]->GetSize();
1306 char * refFromFile =new char[size];
1307 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1308 hdf_dataset[cmpt_ds]->CloseOnDisk();
1311 bool _found3 = false;
1312 SALOMEDS::SObject_var GSO = Study->FindObjectID(refFromFile);
1313 SMESH::SMESH_subMesh_var aSubMesh;
1314 GEOM::GEOM_Shape_var aSubShape;
1316 if (!CORBA::is_nil(GSO)) {
1317 GSO->FindAttribute(anAttr, "AttributeIOR");
1318 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1319 char* SubShapeIOR = anIOR->Value();
1320 aSubShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(SubShapeIOR));
1322 if (!CORBA::is_nil(aSubShape)) {
1323 aSubMesh = myNewMesh->GetElementsOnShape(aSubShape);
1324 string iorString = _orb->object_to_string(aSubMesh);
1325 sprintf(objectId,"%d",subMeshId);
1326 _SMESHCorbaObj[string("SubMesh_")+string(objectId)] = iorString;
1328 //SCRUTE(aSubMesh->GetNumberOfNodes());
1330 //SCRUTE(aSubMesh->GetNumberOfElements());
1334 int nb_subgroup = hdf_subgroup[myTag]->nInternalObjects();
1335 SCRUTE(nb_subgroup);
1336 for (int k=0;k<nb_subgroup;k++)
1338 hdf_subgroup[myTag]->InternalObjectIndentify(k,sgname);
1339 if (strcmp(sgname,"Ref on shape")==0) {
1342 else if (strcmp(sgname,"Applied Hypothesis")==0) {
1343 //********** ref on applied hypothesis
1344 MESSAGE("Applied Hypothesis");
1345 strcpy(name_meshgroup,"Applied Hypothesis");
1347 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
1348 hdf_subgroup[10+cmpt_sm]->OpenOnDisk();
1349 nb_datasets = hdf_subgroup[10+cmpt_sm]->nInternalObjects();
1350 SCRUTE(nb_datasets);
1352 for (int l=0;l<nb_datasets;l++) {
1353 sprintf(name_dataset,"Hyp %d",l);
1354 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm]);
1355 hdf_dataset[cmpt_ds]->OpenOnDisk();
1356 size=hdf_dataset[cmpt_ds]->GetSize();
1358 char * refFromFile =new char[size];
1359 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1360 hdf_dataset[cmpt_ds]->CloseOnDisk();
1364 SALOMEDS::SObject_var HypSO = Study->FindObjectID(refFromFile);
1365 if (!CORBA::is_nil(HypSO)) {
1366 HypSO->FindAttribute(anAttr, "AttributeIOR");
1367 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1368 if (!CORBA::is_nil(anIOR)) {
1369 char* HypIOR = anIOR->Value();
1370 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(HypIOR));
1371 if (!CORBA::is_nil(anHyp)) {
1372 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1373 aMesh->AddHypothesis(aSubShape,anHyp);//essayer avec _SMESHCorbaObj
1374 MESSAGE("Hypothesis added ...");
1381 else if (strcmp(sgname,"Applied Algorithms")==0) {
1382 //********** ref on applied algorithms
1383 MESSAGE("Applied Algorithms");
1384 strcpy(name_meshgroup,"Applied Algorithms");
1386 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
1387 hdf_subgroup[10+cmpt_sm]->OpenOnDisk();
1388 nb_datasets = hdf_subgroup[10+cmpt_sm]->nInternalObjects();
1389 SCRUTE(nb_datasets);
1391 for (int l=0;l<nb_datasets;l++) {
1392 sprintf(name_dataset,"Algo %d",l);
1393 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm]);
1394 hdf_dataset[cmpt_ds]->OpenOnDisk();
1395 size=hdf_dataset[cmpt_ds]->GetSize();
1397 char * refFromFile =new char[size];
1398 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1399 hdf_dataset[cmpt_ds]->CloseOnDisk();
1403 SALOMEDS::SObject_var AlgoSO = Study->FindObjectID(refFromFile);
1404 if (!CORBA::is_nil(AlgoSO)) {
1405 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1406 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1407 if (!CORBA::is_nil(anIOR)) {
1408 char* AlgoIOR = anIOR->Value();
1410 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(AlgoIOR));
1411 SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1412 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1413 if (!CORBA::is_nil(anAlgo)) {
1414 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1415 aMesh->AddHypothesis(aSubShape,anAlgo);//essayer avec _SMESHCorbaObj
1416 MESSAGE("Algorithms added ...");
1425 hdf_subgroup[myTag]->CloseOnDisk();
1427 hdf_subgroup[myLevel1Tag]->CloseOnDisk();
1430 hdf_group[myMeshId]->CloseOnDisk();
1432 MESSAGE("End of Meshes Load");
1436 MESSAGE("End of SMESH_Gen::Load");
1438 hdf_file->CloseOnDisk();
1442 // Remove temporary files created from the stream
1443 if (isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(), true);
1448 bool SMESH_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
1449 const SALOMEDS::TMPFile& theStream,
1452 return Load(theComponent, theStream, theURL, isMultiFile);
1455 //=============================================================================
1459 //=============================================================================
1461 void SMESH_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
1464 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
1465 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
1466 for (; itBig->More();itBig->Next()) {
1467 SALOMEDS::SObject_var gotBranch = itBig->Value();
1469 // branch 1 : hypothesis
1470 if (gotBranch->Tag()==Tag_HypothesisRoot || gotBranch->Tag()==Tag_AlgorithmsRoot) {
1471 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(gotBranch);
1472 for (; it->More();it->Next()) {
1473 SALOMEDS::SObject_var mySObject = it->Value();
1474 SALOMEDS::GenericAttribute_var anAttr;
1475 SALOMEDS::AttributeIOR_var anIOR;
1476 if ( mySObject->FindAttribute(anAttr, "AttributeIOR")) {
1477 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1478 SMESH::SMESH_Hypothesis_var myHyp =
1479 SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
1481 sprintf(objectId,"%d",myHyp->GetId());
1482 // cout<<"********** delete Hyp "<<objectId<<endl;
1483 _SMESHCorbaObj.erase(string("Hypo_")+string(objectId));
1484 myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
1488 // branch 2 : algorithms
1489 else if (gotBranch->Tag()>=3) {
1490 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(gotBranch);
1491 for (; it->More();it->Next()) {
1492 SALOMEDS::SObject_var mySObject = it->Value();
1493 SALOMEDS::GenericAttribute_var anAttr;
1494 SALOMEDS::AttributeIOR_var anIOR;
1495 if ( mySObject->FindAttribute(anAttr, "AttributeIOR")) {
1496 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1497 SMESH::SMESH_Mesh_var myMesh =
1498 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
1499 if (!myMesh->_is_nil()) {
1501 sprintf(objectId,"%d",myMesh->GetId());
1502 // cout<<"********** delete Mesh "<<objectId<<endl;
1503 _SMESHCorbaObj.erase(string("Mesh_")+string(objectId));
1504 CORBA::release(myMesh);
1507 SMESH::SMESH_subMesh_var mySubMesh =
1508 SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value()));
1509 if (!mySubMesh->_is_nil()) {
1511 sprintf(objectId,"%d",mySubMesh->GetId());
1512 // cout<<"********** delete SubMesh "<<objectId<<endl;
1513 _SMESHCorbaObj.erase(string("SubMesh_")+string(objectId));
1514 CORBA::release(mySubMesh);
1523 //=============================================================================
1527 //=============================================================================
1529 char* SMESH_Gen_i::ComponentDataType()
1531 MESSAGE("SMESH_Gen_i::ComponentDataType");
1532 return strdup("SMESH");
1536 //=============================================================================
1540 //=============================================================================
1542 char* SMESH_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
1543 const char* IORString,
1544 CORBA::Boolean isMultiFile,
1545 CORBA::Boolean isASCII)
1547 MESSAGE("SMESH_Gen_i::IORToLocalPersistentID");
1551 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(IORString));
1552 if (! CORBA::is_nil(myAlgo))
1554 string prefix = "Hypo_";
1555 sprintf(objectId,"%d",myAlgo->GetId());
1556 string lpID = prefix + string(objectId);
1557 return CORBA::string_dup(lpID.c_str());
1560 SMESH::SMESH_Hypothesis_var myHypo = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(IORString));
1561 if (! CORBA::is_nil(myHypo))
1563 string prefix = "Hypo_";
1564 sprintf(objectId,"%d",myHypo->GetId());
1565 string lpID = prefix + string(objectId);
1566 return CORBA::string_dup(lpID.c_str());
1569 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(IORString));
1570 if (! CORBA::is_nil(myMesh))
1572 string prefix = "Mesh_";
1573 sprintf(objectId,"%d",myMesh->GetId());
1574 string lpID = prefix + string(objectId);
1575 return CORBA::string_dup(lpID.c_str());
1578 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(IORString));
1579 if (! CORBA::is_nil(mySubMesh))
1581 string prefix = "SubMesh_";
1582 sprintf(objectId,"%d",mySubMesh->GetId());
1583 string lpID = prefix + string(objectId);
1584 return CORBA::string_dup(lpID.c_str());
1586 else return (strdup("no object"));
1592 //=============================================================================
1596 //=============================================================================
1598 char* SMESH_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
1599 const char* aLocalPersistentID,
1600 CORBA::Boolean isMultiFile,
1601 CORBA::Boolean isASCII)
1603 MESSAGE("SMESH_Gen_i::LocalPersistentIDToIOR");
1604 SCRUTE(aLocalPersistentID);
1605 string clef = string(aLocalPersistentID);
1606 SCRUTE(_SMESHCorbaObj[clef].c_str());
1607 return CORBA::string_dup(_SMESHCorbaObj[clef].c_str());
1610 //=============================================================================
1614 //=============================================================================
1616 SMESH_topo* SMESH_Gen_i::ExploreMainShape(GEOM::GEOM_Gen_ptr geomEngine,
1617 CORBA::Long studyId,
1618 GEOM::GEOM_Shape_ptr aShape)
1620 MESSAGE("SMESH_Mesh_i::ExploreMainShape");
1621 // _narrow() duplicates the reference and check the type
1622 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
1623 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
1625 if (CORBA::is_nil(geom))
1626 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", \
1628 if (CORBA::is_nil(myShape))
1629 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
1632 SCRUTE(myShape->Name());
1633 geom->GetCurrentStudy(studyId);
1635 TopoDS_Shape mainShape = _ShapeReader->GetShape(geom,myShape);
1638 // create an SMESH_topo object for the mainShape
1640 SMESH_topo* myTopo = new SMESH_topo();
1643 // explore local TopoDS_Shape, store reference of local TopoDS subShapes
1645 for (TopExp_Explorer exp(mainShape,TopAbs_COMPOUND); exp.More(); exp.Next())
1647 const TopoDS_Compound& E = TopoDS::Compound(exp.Current());
1648 int i = myTopo->_myShapes[TopAbs_COMPOUND].Add(E);
1651 for (TopExp_Explorer exp(mainShape,TopAbs_COMPSOLID); exp.More(); exp.Next())
1653 const TopoDS_CompSolid& E = TopoDS::CompSolid(exp.Current());
1654 int i = myTopo->_myShapes[TopAbs_COMPSOLID].Add(E);
1657 for (TopExp_Explorer exp(mainShape,TopAbs_SOLID); exp.More(); exp.Next())
1659 const TopoDS_Solid& E = TopoDS::Solid(exp.Current());
1660 int i = myTopo->_myShapes[TopAbs_SOLID].Add(E);
1663 for (TopExp_Explorer exp(mainShape,TopAbs_SHELL); exp.More(); exp.Next())
1665 const TopoDS_Shell& E = TopoDS::Shell(exp.Current());
1666 int i = myTopo->_myShapes[TopAbs_SHELL].Add(E);
1669 for (TopExp_Explorer exp(mainShape,TopAbs_FACE); exp.More(); exp.Next())
1671 const TopoDS_Face& E = TopoDS::Face(exp.Current());
1672 int i = myTopo->_myShapes[TopAbs_FACE].Add(E);
1675 for (TopExp_Explorer exp(mainShape,TopAbs_WIRE); exp.More(); exp.Next())
1677 const TopoDS_Wire& E = TopoDS::Wire(exp.Current());
1678 int i = myTopo->_myShapes[TopAbs_WIRE].Add(E);
1681 for (TopExp_Explorer exp(mainShape,TopAbs_EDGE); exp.More(); exp.Next())
1683 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1684 int i = myTopo->_myShapes[TopAbs_EDGE].Add(E);
1687 for (TopExp_Explorer exp(mainShape,TopAbs_VERTEX); exp.More(); exp.Next())
1689 const TopoDS_Vertex& E = TopoDS::Vertex(exp.Current());
1690 int i = myTopo->_myShapes[TopAbs_VERTEX].Add(E);
1694 // explore subShapes of distant CORBA object,
1695 // associate distant CORBA subShape references
1696 // with local reference to local TopoDS subShape
1698 string filenode = "toposhape.txt";
1699 ofstream fic(filenode.c_str());
1701 for (int shapeType = TopAbs_COMPOUND; shapeType < TopAbs_SHAPE; shapeType++)
1703 fic << "shape type : " << SMESH_shapeTypeNames[shapeType];
1705 GEOM::GEOM_Gen::ListOfGeomShapes_var subShapes
1706 = geom->SubShapeAll(myShape,shapeType);
1707 int nbSubShapes = subShapes->length();
1708 int nbLocal = myTopo->_myShapes[shapeType].Extent();
1709 fic << " - number of elements: " << nbSubShapes << endl;
1710 ASSERT(nbSubShapes == nbLocal);
1712 for (int i=0; i< nbSubShapes; i++)
1714 GEOM::GEOM_Shape_var aSubShape = subShapes[i];
1715 string idShape = SMESH_topo::GetShapeLocalId(aSubShape);
1716 fic << " " << idShape;
1718 TopoDS_Shape aLocShape = _ShapeReader->GetShape(geom,aSubShape);
1719 for (int j=1; j <= nbLocal; j++)
1720 if (aLocShape.IsSame(myTopo->_myShapes[shapeType].FindKey(j)))
1722 MESSAGE(" --- trouve = " << j);
1723 myTopo->_mapIndShapes[shapeType][idShape] = j;
1724 fic << " --- trouve = " << j;
1735 //=============================================================================
1737 * C factory, accessible with dlsym, after dlopen
1739 //=============================================================================
1743 PortableServer::ObjectId * SMESHEngine_factory(
1745 PortableServer::POA_ptr poa,
1746 PortableServer::ObjectId * contId,
1747 const char *instanceName,
1748 const char *interfaceName)
1750 MESSAGE("PortableServer::ObjectId * SMESHEngine_factory()");
1751 SCRUTE(interfaceName);
1752 SMESH_Gen_i * mySMESH_Gen
1753 = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
1754 return mySMESH_Gen->getId() ;