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
32 #include <TopExp_Explorer.hxx>
34 #include <TopoDS_Iterator.hxx>
35 #include <TopoDS_Compound.hxx>
36 #include <TopoDS_CompSolid.hxx>
37 #include <TopoDS_Solid.hxx>
38 #include <TopoDS_Shell.hxx>
39 #include <TopoDS_Face.hxx>
40 #include <TopoDS_Wire.hxx>
41 #include <TopoDS_Edge.hxx>
42 #include <TopoDS_Vertex.hxx>
43 #include <TopoDS_Shape.hxx>
44 #include <TopTools_MapOfShape.hxx>
46 #include <BRep_Tool.hxx>
47 #include <TCollection_AsciiString.hxx>
52 #include "SMESH_Gen_i.hxx"
53 #include "SMESH_Mesh_i.hxx"
54 #include "SMESH_LocalLength_i.hxx"
55 #include "SMESH_NumberOfSegments_i.hxx"
56 #include "SMESH_MaxElementArea_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;
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);
503 //writes the file name in the hdf file
504 longueur = hypofile.Length() +1;
505 name_group="Hypothesis";
506 //SCRUTE(name_group);
509 hdf_group[1] = new HDFgroup(name_group,hdf_file);
510 hdf_group[1]->CreateOnDisk();
512 hdf_dataset[cmpt_ds]=new HDFdataset(name_group,hdf_group[1],HDF_STRING,size,1);
513 hdf_dataset[cmpt_ds]->CreateOnDisk();
514 hdf_dataset[cmpt_ds]->WriteOnDisk(hypofile.ToCString());
515 hdf_dataset[cmpt_ds]->CloseOnDisk();
518 hdf_group[1]->CloseOnDisk();
519 MESSAGE("End of Hypothesis Save");
522 //************branch 2 : algorithms
523 else if (gotBranch->Tag()==Tag_AlgorithmsRoot) {//algos = tag 2
525 destFile = fopen( algofile.ToCString() ,"w");
526 it = Study->NewChildIterator(gotBranch);
527 for (; it->More();it->Next()) {
528 mySObject = it->Value();
529 SALOMEDS::GenericAttribute_var anAttr;
530 SALOMEDS::AttributeIOR_var anIOR;
531 if (mySObject->FindAttribute(anAttr, "AttributeIOR")) {
532 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
533 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(anIOR->Value()));
534 fprintf(destFile,"%s\n",myAlgo->GetName());
540 //writes the file name in the hdf file
541 longueur = algofile.Length() +1;
542 name_group="Algorithms";
543 //SCRUTE(name_group);
546 hdf_group[2] = new HDFgroup(name_group,hdf_file);
547 hdf_group[2]->CreateOnDisk();
549 hdf_dataset[cmpt_ds]=new HDFdataset(name_group,hdf_group[2],HDF_STRING,size,1);
550 hdf_dataset[cmpt_ds]->CreateOnDisk();
551 hdf_dataset[cmpt_ds]->WriteOnDisk(algofile.ToCString());
552 hdf_dataset[cmpt_ds]->CloseOnDisk();
555 hdf_group[2]->CloseOnDisk();
556 MESSAGE("End of Algos Save");
559 //************branch 3 : meshes
560 else if (gotBranch->Tag()>=3) {//meshes = tag > 3
562 SALOMEDS::GenericAttribute_var anAttr;
563 SALOMEDS::AttributeIOR_var anIOR;
564 if (gotBranch->FindAttribute(anAttr, "AttributeIOR")) {
565 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
567 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value())) ;
568 studyId = myMesh->GetStudyId();
571 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
572 int meshId = myMesh->GetId();
573 SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
574 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
575 Handle(SMESHDS_Mesh) mySMESHDSMesh = myLocMesh.GetMeshDS();
577 SCRUTE(mySMESHDSMesh->NbNodes());
578 if (mySMESHDSMesh->NbNodes()>0) {//checks if the mesh is not empty
580 DriverMED_W_SMESHDS_Mesh* myWriter = new DriverMED_W_SMESHDS_Mesh;
581 myWriter->SetFile(meshfile.ToCString());
583 myWriter->SetMesh(mySMESHDSMesh);
584 myWriter->SetMeshId(gotBranch->Tag());
587 else meshfile = "No data";
589 //********** opening of the HDF group
590 sprintf(name_meshgroup,"Mesh %d",gotBranch->Tag());
591 SCRUTE(name_meshgroup);
592 hdf_group[gotBranch->Tag()] = new HDFgroup(name_meshgroup,hdf_file);
593 hdf_group[gotBranch->Tag()]->CreateOnDisk();
596 //********** file where the data are stored
597 longueur = strlen(meshfile.ToCString()) +1;
599 strcpy(name_dataset,"Mesh data");
600 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_group[gotBranch->Tag()],HDF_STRING,size,1);
601 hdf_dataset[cmpt_ds]->CreateOnDisk();
602 hdf_dataset[cmpt_ds]->WriteOnDisk(meshfile.ToCString());
603 hdf_dataset[cmpt_ds]->CloseOnDisk();
607 //********** ref on shape
608 Standard_CString myRefOnObject="" ;
609 SALOMEDS::SObject_var myRef,myShape;
610 _found = gotBranch->FindSubObject(Tag_RefOnShape,myRef);
612 ok = myRef->ReferencedObject(myShape);
613 myRefOnObject = myShape->GetID();
614 SCRUTE(myRefOnObject);
616 longueur = strlen(myRefOnObject) +1;
619 strcpy(name_dataset,"Ref on shape");
620 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_group[gotBranch->Tag()],HDF_STRING,size,1);
621 hdf_dataset[cmpt_ds]->CreateOnDisk();
622 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
623 hdf_dataset[cmpt_ds]->CloseOnDisk();
630 //********** ref on applied hypothesis
631 _found = gotBranch->FindSubObject(Tag_RefOnAppliedHypothesis,myBranch);
634 strcpy(name_meshgroup,"Applied Hypothesis");
635 hdf_subgroup[Tag_RefOnAppliedHypothesis] = new HDFgroup(name_meshgroup,hdf_group[gotBranch->Tag()]);
636 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CreateOnDisk();
638 it = Study->NewChildIterator(myBranch);
640 for (; it->More();it->Next()) {
641 mySObject = it->Value();
642 ok = mySObject->ReferencedObject(myRef);
643 myRefOnObject = myRef->GetID();
645 longueur = strlen(myRefOnObject) +1;
648 sprintf(name_dataset,"Hyp %d",cmpt_it);
649 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedHypothesis],HDF_STRING,size,1);
650 hdf_dataset[cmpt_ds]->CreateOnDisk();
651 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
652 hdf_dataset[cmpt_ds]->CloseOnDisk();
657 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CloseOnDisk();
661 //********** ref on applied algorithms
662 _found = gotBranch->FindSubObject(Tag_RefOnAppliedAlgorithms,myBranch);
665 strcpy(name_meshgroup,"Applied Algorithms");
666 hdf_subgroup[Tag_RefOnAppliedAlgorithms] = new HDFgroup(name_meshgroup,hdf_group[gotBranch->Tag()]);
667 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CreateOnDisk();
669 it = Study->NewChildIterator(myBranch);
671 for (; it->More();it->Next()) {
672 mySObject = it->Value();
673 ok = mySObject->ReferencedObject(myRef);
674 myRefOnObject = myRef->GetID();
676 longueur = strlen(myRefOnObject) +1;
679 sprintf(name_dataset,"Algo %d",cmpt_it);
680 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedAlgorithms],HDF_STRING,size,1);
681 hdf_dataset[cmpt_ds]->CreateOnDisk();
682 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
683 hdf_dataset[cmpt_ds]->CloseOnDisk();
688 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CloseOnDisk();
690 MESSAGE("end of algo applied");
693 //********** submeshes on subshapes
695 for (int i=Tag_SubMeshOnVertex;i<=Tag_SubMeshOnCompound;i++) {
696 _found = gotBranch->FindSubObject(i,myBranch);
698 if (i==Tag_SubMeshOnVertex)
699 strcpy(name_meshgroup,"SubMeshes On Vertex");
700 else if (i==Tag_SubMeshOnEdge)
701 strcpy(name_meshgroup,"SubMeshes On Edge");
702 else if (i==Tag_SubMeshOnFace)
703 strcpy(name_meshgroup,"SubMeshes On Face");
704 else if (i==Tag_SubMeshOnSolid)
705 strcpy(name_meshgroup,"SubMeshes On Solid");
706 else if (i==Tag_SubMeshOnCompound)
707 strcpy(name_meshgroup,"SubMeshes On Compound");
710 myLevel1Tag = 10+cmpt_sm;
711 hdf_subgroup[myLevel1Tag] = new HDFgroup(name_meshgroup,hdf_group[gotBranch->Tag()]);
712 hdf_subgroup[myLevel1Tag]->CreateOnDisk();
714 itSM = Study->NewChildIterator(myBranch);
715 for (; itSM->More();itSM->Next()) {//Loop on all submeshes
716 mySObject = itSM->Value();
719 mySObject->FindAttribute(anAttr, "AttributeIOR");
720 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
721 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value())) ;
723 //sprintf(name_meshgroup,"SubMesh %d",myTag);
724 sprintf(name_meshgroup,"SubMesh %d",mySubMesh->GetId());
725 SCRUTE(name_meshgroup);
727 hdf_subgroup[myTag] = new HDFgroup(name_meshgroup,hdf_subgroup[myLevel1Tag]);
728 hdf_subgroup[myTag]->CreateOnDisk();
730 //********** ref on shape
731 Standard_CString myRefOnObject="" ;
732 SALOMEDS::SObject_var myRef,myShape;
734 _found2 = mySObject->FindSubObject(Tag_RefOnShape,myRef);
736 ok = myRef->ReferencedObject(myShape);
737 myRefOnObject = myShape->GetID();
738 SCRUTE(myRefOnObject);
740 longueur = strlen(myRefOnObject) +1;
743 strcpy(name_dataset,"Ref on shape");
744 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[myTag],HDF_STRING,size,1);
745 hdf_dataset[cmpt_ds]->CreateOnDisk();
746 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
747 hdf_dataset[cmpt_ds]->CloseOnDisk();
753 //********** ref on applied hypothesis
754 _found2 = mySObject->FindSubObject(Tag_RefOnAppliedHypothesis,myBranch);
757 strcpy(name_meshgroup,"Applied Hypothesis");
759 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
760 hdf_subgroup[10+cmpt_sm]->CreateOnDisk();
762 it = Study->NewChildIterator(myBranch);
764 for (; it->More();it->Next()) {
765 mySObjectChild = it->Value();
766 ok = mySObjectChild->ReferencedObject(myRef);
767 myRefOnObject = myRef->GetID();
769 longueur = strlen(myRefOnObject) +1;
772 sprintf(name_dataset,"Hyp %d",cmpt_it);
774 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm],HDF_STRING,size,1);
775 hdf_dataset[cmpt_ds]->CreateOnDisk();
776 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
777 hdf_dataset[cmpt_ds]->CloseOnDisk();
782 hdf_subgroup[10+cmpt_sm]->CloseOnDisk();
786 //********** ref on applied algorithms
787 _found2 = mySObject->FindSubObject(Tag_RefOnAppliedAlgorithms,myBranch);
791 strcpy(name_meshgroup,"Applied Algorithms");
793 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
794 hdf_subgroup[10+cmpt_sm]->CreateOnDisk();
796 it = Study->NewChildIterator(myBranch);
798 for (; it->More();it->Next()) {
799 mySObjectChild = it->Value();
800 ok = mySObjectChild->ReferencedObject(myRef);
801 myRefOnObject = myRef->GetID();
803 longueur = strlen(myRefOnObject) +1;
806 sprintf(name_dataset,"Algo %d",cmpt_it);
807 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm],HDF_STRING,size,1);
808 hdf_dataset[cmpt_ds]->CreateOnDisk();
809 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
810 hdf_dataset[cmpt_ds]->CloseOnDisk();
815 hdf_subgroup[10+cmpt_sm]->CloseOnDisk();
817 //MESSAGE("end of algo applied");
820 hdf_subgroup[myTag]->CloseOnDisk();
823 hdf_subgroup[myLevel1Tag]->CloseOnDisk();
829 //********** closing of the HDF group
830 hdf_group[gotBranch->Tag()]->CloseOnDisk();
831 MESSAGE("End of Mesh Save");
835 MESSAGE("End of Meshes Save");
838 hdf_file->CloseOnDisk();
842 // Convert temporary files to stream
843 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.ToCString(), aFileSeq.in(), isMultiFile);
845 // Remove temporary files and directory
846 if (isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(), true);
848 MESSAGE("End SMESH_Gen_i::Save");
850 return aStreamFile._retn();
853 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
856 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
857 return aStreamFile._retn();
860 //=============================================================================
864 //=============================================================================
866 bool SMESH_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
867 const SALOMEDS::TMPFile& theStream,
871 MESSAGE("SMESH_Gen_i::Load\n");
873 // Get temporary files location
874 TCollection_AsciiString tmpDir = isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
876 // Convert the stream into sequence of files to process
877 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
881 // Set names of temporary files
882 TCollection_AsciiString filename = tmpDir + aFileSeq[0];//"SMESH.hdf";
883 TCollection_AsciiString hypofile = tmpDir + aFileSeq[1];//"SMESH_Hypo.txt";
884 TCollection_AsciiString algofile = tmpDir + aFileSeq[2];//"SMESH_Algo.txt";
885 TCollection_AsciiString meshfile = tmpDir + aFileSeq[3];//"SMESH_Mesh.med";
887 SALOMEDS::Study_var Study = theComponent->GetStudy();
888 int studyId = Study->StudyId();
891 SALOMEDS::GenericAttribute_var anAttr;
892 SALOMEDS::AttributeName_var aName;
893 SALOMEDS::AttributeIOR_var anIOR;
895 SALOMEDS::SComponent_var fathergeom = Study->FindComponent("GEOM");
896 SALOMEDS::SComponent_var myGeomSComp = SALOMEDS::SComponent::_narrow( fathergeom );
899 //to get the geom engine !!!
900 //useful to define our new mesh
901 SALOME_NamingService* _NS = SINGLETON_<SALOME_NamingService>::Instance() ;
902 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
903 _NS->init_orb( _orb ) ;
904 SALOME_LifeCycleCORBA* myEnginesLifeCycle = new SALOME_LifeCycleCORBA(_NS);
905 Engines::Component_var geomEngine =
906 myEnginesLifeCycle->FindOrLoad_Component("FactoryServer","Geometry");
907 GEOM::GEOM_Gen_var myGeomEngine = GEOM::GEOM_Gen::_narrow(geomEngine);
912 char objectId[10],name_dataset[10];
913 int nb_datasets,size,cmpt_ds=0;
916 char name[HDF_NAME_MAX_LEN+1];
917 char sgname[HDF_NAME_MAX_LEN+1];
918 char msgname[HDF_NAME_MAX_LEN+1];
919 char name_of_group[HDF_NAME_MAX_LEN+1];
920 char *name_meshgroup;
921 map <int,HDFgroup*> hdf_group, hdf_subgroup;
922 map <int,HDFdataset*> hdf_dataset;
925 //************* HDF file opening
926 HDFfile * hdf_file = new HDFfile(filename.ToCString());
928 hdf_file->OpenOnDisk(HDF_RDONLY);
930 catch (HDFexception) {
931 MESSAGE("Load(): " << filename << " not found!");
935 //****************************
937 int nb_group = hdf_file->nInternalObjects();
939 for (int i=0;i<nb_group;i++)
941 hdf_file->InternalObjectIndentify(i,name);
945 // Loading of the Hypothesis Branch
947 if (strcmp(name,"Hypothesis")==0) {
949 double length,maxElementsArea;
950 int numberOfSegments;
952 hdf_group[Tag_HypothesisRoot] = new HDFgroup(name,hdf_file);
953 hdf_group[Tag_HypothesisRoot]->OpenOnDisk();
955 hdf_group[Tag_HypothesisRoot]->InternalObjectIndentify(0,name_of_group);
956 hdf_dataset[cmpt_ds]=new HDFdataset(name_of_group,hdf_group[Tag_HypothesisRoot]);
957 hdf_dataset[cmpt_ds]->OpenOnDisk();
958 size=hdf_dataset[cmpt_ds]->GetSize();
960 char * name_of_file =new char[size];
961 hdf_dataset[cmpt_ds]->ReadFromDisk(name_of_file);
962 SCRUTE(name_of_file);
963 hdf_dataset[cmpt_ds]->CloseOnDisk();
964 hdf_group[Tag_HypothesisRoot]->CloseOnDisk();
966 delete[] name_of_file;
969 aLine = new char[100];
970 loadedFile = fopen( hypofile.ToCString() ,"r");
971 while (!feof(loadedFile)) {
972 fscanf(loadedFile,"%s",aLine);
974 if (strcmp(aLine,"LocalLength")==0) {
975 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
976 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( myHyp );
977 fscanf(loadedFile,"%s",aLine);
978 length = atof(aLine);
979 LL->SetLength(length);
980 string iorString = _orb->object_to_string(LL);
981 sprintf(objectId,"%d",LL->GetId());
982 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
984 else if (strcmp(aLine,"NumberOfSegments")==0) {
985 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
986 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( myHyp );
987 fscanf(loadedFile,"%s",aLine);
988 numberOfSegments = atoi(aLine);
989 NOS->SetNumberOfSegments(numberOfSegments);
990 string iorString = _orb->object_to_string(NOS);
991 sprintf(objectId,"%d",NOS->GetId());
992 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
994 else if (strcmp(aLine,"MaxElementArea")==0) {
995 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
996 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( myHyp );
997 fscanf(loadedFile,"%s",aLine);
998 maxElementsArea = atof(aLine);
999 MEA->SetMaxElementArea(maxElementsArea);
1000 string iorString = _orb->object_to_string(MEA);
1001 sprintf(objectId,"%d",MEA->GetId());
1002 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
1010 MESSAGE("End of Hypos Load");
1014 // Loading of the Algorithms Branch
1016 else if (strcmp(name,"Algorithms")==0) {
1018 hdf_group[Tag_AlgorithmsRoot] = new HDFgroup(name,hdf_file);
1019 hdf_group[Tag_AlgorithmsRoot]->OpenOnDisk();
1021 hdf_group[Tag_AlgorithmsRoot]->InternalObjectIndentify(0,name_of_group);
1022 hdf_dataset[cmpt_ds] = new HDFdataset(name_of_group,hdf_group[Tag_AlgorithmsRoot]);
1023 hdf_dataset[cmpt_ds]->OpenOnDisk();
1024 size=hdf_dataset[cmpt_ds]->GetSize();
1026 char * name_of_file =new char[size];
1027 hdf_dataset[cmpt_ds]->ReadFromDisk(name_of_file);
1028 hdf_dataset[cmpt_ds]->CloseOnDisk();
1029 hdf_group[Tag_AlgorithmsRoot]->CloseOnDisk();
1031 delete[] name_of_file;
1034 aLine = new char[100];
1035 loadedFile = fopen( algofile.ToCString(),"r");
1036 while (!feof(loadedFile)) {
1037 fscanf(loadedFile,"%s\n",aLine);
1039 if (strcmp(aLine,"")!=0) {
1040 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
1041 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1042 string iorString = _orb->object_to_string(myAlgo);
1043 sprintf(objectId,"%d",myAlgo->GetId());
1044 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
1050 MESSAGE("End of Algos Load");
1055 // Loading of the Mesh Branch
1057 else if (string(name).substr(0,4)==string("Mesh")) {
1058 MESSAGE("in mesh load");
1060 Standard_Integer myMeshId = atoi((string(name).substr(5,5)).c_str());
1063 hdf_group[myMeshId] = new HDFgroup(name,hdf_file);
1064 hdf_group[myMeshId]->OpenOnDisk();
1066 int nb_meshsubgroup = hdf_group[myMeshId]->nInternalObjects();
1067 SCRUTE(nb_meshsubgroup);
1069 //********** Loading of the file name where the data are stored
1070 MESSAGE("Mesh data file");
1071 strcpy(name_of_group,"Mesh data");
1072 hdf_dataset[cmpt_ds]=new HDFdataset(name_of_group,hdf_group[myMeshId]);
1073 hdf_dataset[cmpt_ds]->OpenOnDisk();
1074 size=hdf_dataset[cmpt_ds]->GetSize();
1076 char * datafilename =new char[size];
1077 hdf_dataset[cmpt_ds]->ReadFromDisk(datafilename);
1078 hdf_dataset[cmpt_ds]->CloseOnDisk();
1083 //else if (strcmp(msgname,"Ref on shape")==0) {
1085 //********** Loading of the reference on the shape
1086 //********** and mesh initialization
1087 MESSAGE("Ref on shape");
1088 strcpy(name_of_group,"Ref on shape");
1089 hdf_dataset[cmpt_ds] = new HDFdataset(name_of_group,hdf_group[myMeshId]);
1090 hdf_dataset[cmpt_ds]->OpenOnDisk();
1091 size=hdf_dataset[cmpt_ds]->GetSize();
1093 char * refFromFile =new char[size];
1094 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1095 hdf_dataset[cmpt_ds]->CloseOnDisk();
1098 Standard_CString myRefOnShape=""; //look for ref on shape
1100 bool _found = false;
1101 SALOMEDS::SObject_var CSO = Study->FindObjectID(refFromFile);
1102 SMESH::SMESH_Mesh_var myNewMesh;
1103 GEOM::GEOM_Shape_var aShape;
1105 if (!CORBA::is_nil(CSO)) {
1107 CSO->FindAttribute(anAttr, "AttributeIOR");
1108 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1109 char* ShapeIOR = anIOR->Value();
1110 aShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(ShapeIOR));
1112 myNewMesh = this->Init(myGeomEngine,studyId,aShape);
1113 string iorString = _orb->object_to_string(myNewMesh);
1114 sprintf(objectId,"%d",myNewMesh->GetId());
1115 _SMESHCorbaObj[string("Mesh_")+string(objectId)] = iorString;
1118 //********** Loading of mesh data
1119 if (strcmp(datafilename,"No data")!=0) {
1124 //****************************************************************************
1125 //* OUVERTURE DU FICHIER EN LECTURE *
1126 //****************************************************************************
1128 fid = MEDouvrir(datafilename,MED_LECT);
1131 printf(">> ERREUR : ouverture du fichier %s \n",datafilename);
1136 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
1137 int meshId = myNewMesh->GetId();
1138 SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
1139 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1140 Handle(SMESHDS_Mesh) mySMESHDSMesh = myLocMesh.GetMeshDS();
1142 DriverMED_R_SMESHDS_Mesh* myReader = new DriverMED_R_SMESHDS_Mesh;
1144 myReader->SetMesh(mySMESHDSMesh);
1145 myReader->SetMeshId(myMeshId);
1146 myReader->SetFileId(fid);
1147 myReader->ReadMySelf();
1148 //SCRUTE(mySMESHDSMesh->NbNodes());
1149 //myNewMesh->ExportUNV("/tmp/test.unv");//only to check out
1151 //****************************************************************************
1152 //* FERMETURE DU FICHIER *
1153 //****************************************************************************
1154 ret = MEDfermer(fid);
1157 printf(">> ERREUR : erreur a la fermeture du fichier %s\n",datafilename);
1164 //else if (strcmp(msgname,"Applied Hypothesis")==0) {
1165 for (int ii=0;ii<nb_meshsubgroup;ii++)
1167 hdf_group[myMeshId]->InternalObjectIndentify(ii,msgname);
1168 if (strcmp(msgname,"Mesh data")==0) {
1171 else if (strcmp(msgname,"Ref on shape")==0) {
1174 else if (strcmp(msgname,"Applied Hypothesis")==0) {
1175 //********** Loading of the applied hypothesis
1176 strcpy(name_of_group,"Applied Hypothesis");
1177 hdf_subgroup[Tag_RefOnAppliedHypothesis] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1178 hdf_subgroup[Tag_RefOnAppliedHypothesis]->OpenOnDisk();
1180 nb_datasets = hdf_subgroup[Tag_RefOnAppliedHypothesis]->nInternalObjects();
1181 SCRUTE(nb_datasets);
1183 for (int j=0;j<nb_datasets;j++) {
1184 sprintf(name_dataset,"Hyp %d",j);
1185 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedHypothesis]);
1186 hdf_dataset[cmpt_ds]->OpenOnDisk();
1187 size=hdf_dataset[cmpt_ds]->GetSize();
1189 char * refFromFile =new char[size];
1190 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1191 //SCRUTE(refFromFile);
1192 hdf_dataset[cmpt_ds]->CloseOnDisk();
1195 SALOMEDS::SObject_var HypSO = Study->FindObjectID(refFromFile);
1196 if (!CORBA::is_nil(HypSO)) {
1197 HypSO->FindAttribute(anAttr, "AttributeIOR");
1198 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1199 if (!CORBA::is_nil(anIOR)) {
1200 char* HypIOR = anIOR->Value();
1201 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(HypIOR));
1202 if (!CORBA::is_nil(anHyp)) {
1203 myNewMesh->AddHypothesis(aShape,anHyp);
1204 MESSAGE("Hypothesis added ...");
1211 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CloseOnDisk();
1214 else if (strcmp(msgname,"Applied Algorithms")==0) {
1216 //********** Loading of the applied algorithms
1217 strcpy(name_of_group,"Applied Algorithms");
1218 hdf_subgroup[Tag_RefOnAppliedAlgorithms] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1219 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->OpenOnDisk();
1221 nb_datasets = hdf_subgroup[Tag_RefOnAppliedAlgorithms]->nInternalObjects();
1222 SCRUTE(nb_datasets);
1224 for (int j=0;j<nb_datasets;j++) {
1225 sprintf(name_dataset,"Algo %d",j);
1226 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedAlgorithms]);
1227 hdf_dataset[cmpt_ds]->OpenOnDisk();
1228 size=hdf_dataset[cmpt_ds]->GetSize();
1230 char * refFromFile =new char[size];
1231 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1232 hdf_dataset[cmpt_ds]->CloseOnDisk();
1236 SALOMEDS::SObject_var AlgoSO = Study->FindObjectID(refFromFile);
1237 if (!CORBA::is_nil(AlgoSO)) {
1238 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1239 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1240 if (!CORBA::is_nil(anIOR)) {
1241 char* AlgoIOR = anIOR->Value();
1243 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(AlgoIOR));
1244 SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1245 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1246 if (!CORBA::is_nil(anAlgo)) {
1247 myNewMesh->AddHypothesis(aShape,anAlgo);//essayer avec _SMESHCorbaObj
1248 MESSAGE("Algorithms added ...");
1255 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CloseOnDisk();
1259 else if (string(msgname).substr(0,9)==string("SubMeshes")) {
1262 //********** Loading of the submeshes on subshapes
1263 int myLevel1Tag, myTag;
1266 myLevel1Tag = 10+cmpt_sm;
1267 hdf_subgroup[myLevel1Tag] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1268 hdf_subgroup[myLevel1Tag] = new HDFgroup(msgname,hdf_group[myMeshId]);
1269 hdf_subgroup[myLevel1Tag]->OpenOnDisk();
1271 int nb_submeshes = hdf_subgroup[myLevel1Tag]->nInternalObjects();
1272 SCRUTE(nb_submeshes);
1274 for (int j=0;j<nb_submeshes;j++) {
1277 hdf_subgroup[myLevel1Tag]->InternalObjectIndentify(j,name_meshgroup);
1278 SCRUTE(name_meshgroup);
1280 hdf_subgroup[myTag] = new HDFgroup(name_meshgroup,hdf_subgroup[myLevel1Tag]);
1281 hdf_subgroup[myTag]->OpenOnDisk();
1282 int subMeshId = atoi((string(name_meshgroup).substr(8,18)).c_str());
1284 MESSAGE("Ref on shape");
1285 //********** ref on shape
1286 sprintf(name_dataset,"Ref on shape");
1287 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[myTag]);
1288 hdf_dataset[cmpt_ds]->OpenOnDisk();
1289 size=hdf_dataset[cmpt_ds]->GetSize();
1291 char * refFromFile =new char[size];
1292 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1293 hdf_dataset[cmpt_ds]->CloseOnDisk();
1296 bool _found3 = false;
1297 SALOMEDS::SObject_var GSO = Study->FindObjectID(refFromFile);
1298 SMESH::SMESH_subMesh_var aSubMesh;
1299 GEOM::GEOM_Shape_var aSubShape;
1301 if (!CORBA::is_nil(GSO)) {
1302 GSO->FindAttribute(anAttr, "AttributeIOR");
1303 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1304 char* SubShapeIOR = anIOR->Value();
1305 aSubShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(SubShapeIOR));
1307 if (!CORBA::is_nil(aSubShape)) {
1308 aSubMesh = myNewMesh->GetElementsOnShape(aSubShape);
1309 string iorString = _orb->object_to_string(aSubMesh);
1310 sprintf(objectId,"%d",subMeshId);
1311 _SMESHCorbaObj[string("SubMesh_")+string(objectId)] = iorString;
1313 //SCRUTE(aSubMesh->GetNumberOfNodes());
1315 //SCRUTE(aSubMesh->GetNumberOfElements());
1319 int nb_subgroup = hdf_subgroup[myTag]->nInternalObjects();
1320 SCRUTE(nb_subgroup);
1321 for (int k=0;k<nb_subgroup;k++)
1323 hdf_subgroup[myTag]->InternalObjectIndentify(k,sgname);
1324 if (strcmp(sgname,"Ref on shape")==0) {
1327 else if (strcmp(sgname,"Applied Hypothesis")==0) {
1328 //********** ref on applied hypothesis
1329 MESSAGE("Applied Hypothesis");
1330 strcpy(name_meshgroup,"Applied Hypothesis");
1332 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
1333 hdf_subgroup[10+cmpt_sm]->OpenOnDisk();
1334 nb_datasets = hdf_subgroup[10+cmpt_sm]->nInternalObjects();
1335 SCRUTE(nb_datasets);
1337 for (int l=0;l<nb_datasets;l++) {
1338 sprintf(name_dataset,"Hyp %d",l);
1339 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm]);
1340 hdf_dataset[cmpt_ds]->OpenOnDisk();
1341 size=hdf_dataset[cmpt_ds]->GetSize();
1343 char * refFromFile =new char[size];
1344 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1345 hdf_dataset[cmpt_ds]->CloseOnDisk();
1349 SALOMEDS::SObject_var HypSO = Study->FindObjectID(refFromFile);
1350 if (!CORBA::is_nil(HypSO)) {
1351 HypSO->FindAttribute(anAttr, "AttributeIOR");
1352 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1353 if (!CORBA::is_nil(anIOR)) {
1354 char* HypIOR = anIOR->Value();
1355 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(HypIOR));
1356 if (!CORBA::is_nil(anHyp)) {
1357 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1358 aMesh->AddHypothesis(aSubShape,anHyp);//essayer avec _SMESHCorbaObj
1359 MESSAGE("Hypothesis added ...");
1366 else if (strcmp(sgname,"Applied Algorithms")==0) {
1367 //********** ref on applied algorithms
1368 MESSAGE("Applied Algorithms");
1369 strcpy(name_meshgroup,"Applied Algorithms");
1371 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
1372 hdf_subgroup[10+cmpt_sm]->OpenOnDisk();
1373 nb_datasets = hdf_subgroup[10+cmpt_sm]->nInternalObjects();
1374 SCRUTE(nb_datasets);
1376 for (int l=0;l<nb_datasets;l++) {
1377 sprintf(name_dataset,"Algo %d",l);
1378 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm]);
1379 hdf_dataset[cmpt_ds]->OpenOnDisk();
1380 size=hdf_dataset[cmpt_ds]->GetSize();
1382 char * refFromFile =new char[size];
1383 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1384 hdf_dataset[cmpt_ds]->CloseOnDisk();
1388 SALOMEDS::SObject_var AlgoSO = Study->FindObjectID(refFromFile);
1389 if (!CORBA::is_nil(AlgoSO)) {
1390 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1391 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1392 if (!CORBA::is_nil(anIOR)) {
1393 char* AlgoIOR = anIOR->Value();
1395 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(AlgoIOR));
1396 SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1397 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1398 if (!CORBA::is_nil(anAlgo)) {
1399 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1400 aMesh->AddHypothesis(aSubShape,anAlgo);//essayer avec _SMESHCorbaObj
1401 MESSAGE("Algorithms added ...");
1410 hdf_subgroup[myTag]->CloseOnDisk();
1412 hdf_subgroup[myLevel1Tag]->CloseOnDisk();
1415 hdf_group[myMeshId]->CloseOnDisk();
1417 MESSAGE("End of Meshes Load");
1421 MESSAGE("End of SMESH_Gen::Load");
1423 hdf_file->CloseOnDisk();
1427 // Remove temporary files created from the stream
1428 if (isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(), true);
1433 bool SMESH_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
1434 const SALOMEDS::TMPFile& theStream,
1437 return Load(theComponent, theStream, theURL, isMultiFile);
1440 //=============================================================================
1444 //=============================================================================
1446 void SMESH_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
1449 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
1450 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
1451 for (; itBig->More();itBig->Next()) {
1452 SALOMEDS::SObject_var gotBranch = itBig->Value();
1454 // branch 1 : hypothesis
1455 if (gotBranch->Tag()==Tag_HypothesisRoot || gotBranch->Tag()==Tag_AlgorithmsRoot) {
1456 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(gotBranch);
1457 for (; it->More();it->Next()) {
1458 SALOMEDS::SObject_var mySObject = it->Value();
1459 SALOMEDS::GenericAttribute_var anAttr;
1460 SALOMEDS::AttributeIOR_var anIOR;
1461 if ( mySObject->FindAttribute(anAttr, "AttributeIOR")) {
1462 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1463 SMESH::SMESH_Hypothesis_var myHyp =
1464 SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
1466 sprintf(objectId,"%d",myHyp->GetId());
1467 // cout<<"********** delete Hyp "<<objectId<<endl;
1468 _SMESHCorbaObj.erase(string("Hypo_")+string(objectId));
1469 myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
1473 // branch 2 : algorithms
1474 else if (gotBranch->Tag()>=3) {
1475 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(gotBranch);
1476 for (; it->More();it->Next()) {
1477 SALOMEDS::SObject_var mySObject = it->Value();
1478 SALOMEDS::GenericAttribute_var anAttr;
1479 SALOMEDS::AttributeIOR_var anIOR;
1480 if ( mySObject->FindAttribute(anAttr, "AttributeIOR")) {
1481 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1482 SMESH::SMESH_Mesh_var myMesh =
1483 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
1484 if (!myMesh->_is_nil()) {
1486 sprintf(objectId,"%d",myMesh->GetId());
1487 // cout<<"********** delete Mesh "<<objectId<<endl;
1488 _SMESHCorbaObj.erase(string("Mesh_")+string(objectId));
1489 CORBA::release(myMesh);
1492 SMESH::SMESH_subMesh_var mySubMesh =
1493 SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value()));
1494 if (!mySubMesh->_is_nil()) {
1496 sprintf(objectId,"%d",mySubMesh->GetId());
1497 // cout<<"********** delete SubMesh "<<objectId<<endl;
1498 _SMESHCorbaObj.erase(string("SubMesh_")+string(objectId));
1499 CORBA::release(mySubMesh);
1508 //=============================================================================
1512 //=============================================================================
1514 char* SMESH_Gen_i::ComponentDataType()
1516 MESSAGE("SMESH_Gen_i::ComponentDataType");
1517 return strdup("SMESH");
1521 //=============================================================================
1525 //=============================================================================
1527 char* SMESH_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
1528 const char* IORString,
1529 CORBA::Boolean isMultiFile,
1530 CORBA::Boolean isASCII)
1532 MESSAGE("SMESH_Gen_i::IORToLocalPersistentID");
1536 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(IORString));
1537 if (! CORBA::is_nil(myAlgo))
1539 string prefix = "Hypo_";
1540 sprintf(objectId,"%d",myAlgo->GetId());
1541 string lpID = prefix + string(objectId);
1542 return CORBA::string_dup(lpID.c_str());
1545 SMESH::SMESH_Hypothesis_var myHypo = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(IORString));
1546 if (! CORBA::is_nil(myHypo))
1548 string prefix = "Hypo_";
1549 sprintf(objectId,"%d",myHypo->GetId());
1550 string lpID = prefix + string(objectId);
1551 return CORBA::string_dup(lpID.c_str());
1554 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(IORString));
1555 if (! CORBA::is_nil(myMesh))
1557 string prefix = "Mesh_";
1558 sprintf(objectId,"%d",myMesh->GetId());
1559 string lpID = prefix + string(objectId);
1560 return CORBA::string_dup(lpID.c_str());
1563 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(IORString));
1564 if (! CORBA::is_nil(mySubMesh))
1566 string prefix = "SubMesh_";
1567 sprintf(objectId,"%d",mySubMesh->GetId());
1568 string lpID = prefix + string(objectId);
1569 return CORBA::string_dup(lpID.c_str());
1571 else return (strdup("no object"));
1577 //=============================================================================
1581 //=============================================================================
1583 char* SMESH_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
1584 const char* aLocalPersistentID,
1585 CORBA::Boolean isMultiFile,
1586 CORBA::Boolean isASCII)
1588 MESSAGE("SMESH_Gen_i::LocalPersistentIDToIOR");
1589 SCRUTE(aLocalPersistentID);
1590 string clef = string(aLocalPersistentID);
1591 SCRUTE(_SMESHCorbaObj[clef].c_str());
1592 return CORBA::string_dup(_SMESHCorbaObj[clef].c_str());
1595 //=============================================================================
1599 //=============================================================================
1601 SMESH_topo* SMESH_Gen_i::ExploreMainShape(GEOM::GEOM_Gen_ptr geomEngine,
1602 CORBA::Long studyId,
1603 GEOM::GEOM_Shape_ptr aShape)
1605 MESSAGE("SMESH_Mesh_i::ExploreMainShape");
1606 // _narrow() duplicates the reference and check the type
1607 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
1608 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
1610 if (CORBA::is_nil(geom))
1611 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", \
1613 if (CORBA::is_nil(myShape))
1614 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
1617 SCRUTE(myShape->Name());
1618 geom->GetCurrentStudy(studyId);
1620 TopoDS_Shape mainShape = _ShapeReader->GetShape(geom,myShape);
1623 // create an SMESH_topo object for the mainShape
1625 SMESH_topo* myTopo = new SMESH_topo();
1628 // explore local TopoDS_Shape, store reference of local TopoDS subShapes
1630 for (TopExp_Explorer exp(mainShape,TopAbs_COMPOUND); exp.More(); exp.Next())
1632 const TopoDS_Compound& E = TopoDS::Compound(exp.Current());
1633 int i = myTopo->_myShapes[TopAbs_COMPOUND].Add(E);
1636 for (TopExp_Explorer exp(mainShape,TopAbs_COMPSOLID); exp.More(); exp.Next())
1638 const TopoDS_CompSolid& E = TopoDS::CompSolid(exp.Current());
1639 int i = myTopo->_myShapes[TopAbs_COMPSOLID].Add(E);
1642 for (TopExp_Explorer exp(mainShape,TopAbs_SOLID); exp.More(); exp.Next())
1644 const TopoDS_Solid& E = TopoDS::Solid(exp.Current());
1645 int i = myTopo->_myShapes[TopAbs_SOLID].Add(E);
1648 for (TopExp_Explorer exp(mainShape,TopAbs_SHELL); exp.More(); exp.Next())
1650 const TopoDS_Shell& E = TopoDS::Shell(exp.Current());
1651 int i = myTopo->_myShapes[TopAbs_SHELL].Add(E);
1654 for (TopExp_Explorer exp(mainShape,TopAbs_FACE); exp.More(); exp.Next())
1656 const TopoDS_Face& E = TopoDS::Face(exp.Current());
1657 int i = myTopo->_myShapes[TopAbs_FACE].Add(E);
1660 for (TopExp_Explorer exp(mainShape,TopAbs_WIRE); exp.More(); exp.Next())
1662 const TopoDS_Wire& E = TopoDS::Wire(exp.Current());
1663 int i = myTopo->_myShapes[TopAbs_WIRE].Add(E);
1666 for (TopExp_Explorer exp(mainShape,TopAbs_EDGE); exp.More(); exp.Next())
1668 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1669 int i = myTopo->_myShapes[TopAbs_EDGE].Add(E);
1672 for (TopExp_Explorer exp(mainShape,TopAbs_VERTEX); exp.More(); exp.Next())
1674 const TopoDS_Vertex& E = TopoDS::Vertex(exp.Current());
1675 int i = myTopo->_myShapes[TopAbs_VERTEX].Add(E);
1679 // explore subShapes of distant CORBA object,
1680 // associate distant CORBA subShape references
1681 // with local reference to local TopoDS subShape
1683 string filenode = "toposhape.txt";
1684 ofstream fic(filenode.c_str());
1686 for (int shapeType = TopAbs_COMPOUND; shapeType < TopAbs_SHAPE; shapeType++)
1688 fic << "shape type : " << SMESH_shapeTypeNames[shapeType];
1690 GEOM::GEOM_Gen::ListOfGeomShapes_var subShapes
1691 = geom->SubShapeAll(myShape,shapeType);
1692 int nbSubShapes = subShapes->length();
1693 int nbLocal = myTopo->_myShapes[shapeType].Extent();
1694 fic << " - number of elements: " << nbSubShapes << endl;
1695 ASSERT(nbSubShapes == nbLocal);
1697 for (int i=0; i< nbSubShapes; i++)
1699 GEOM::GEOM_Shape_var aSubShape = subShapes[i];
1700 string idShape = SMESH_topo::GetShapeLocalId(aSubShape);
1701 fic << " " << idShape;
1703 TopoDS_Shape aLocShape = _ShapeReader->GetShape(geom,aSubShape);
1704 for (int j=1; j <= nbLocal; j++)
1705 if (aLocShape.IsSame(myTopo->_myShapes[shapeType].FindKey(j)))
1707 MESSAGE(" --- trouve = " << j);
1708 myTopo->_mapIndShapes[shapeType][idShape] = j;
1709 fic << " --- trouve = " << j;
1720 //=============================================================================
1722 * C factory, accessible with dlsym, after dlopen
1724 //=============================================================================
1728 PortableServer::ObjectId * SMESHEngine_factory(
1730 PortableServer::POA_ptr poa,
1731 PortableServer::ObjectId * contId,
1732 const char *instanceName,
1733 const char *interfaceName)
1735 MESSAGE("PortableServer::ObjectId * SMESHEngine_factory()");
1736 SCRUTE(interfaceName);
1737 SMESH_Gen_i * mySMESH_Gen
1738 = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
1739 return mySMESH_Gen->getId() ;