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("");
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 TCollection_AsciiString aStudyName("");
887 if (isMultiFile) aStudyName = (SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
889 // Set names of temporary files
890 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString("_SMESH.hdf");
891 TCollection_AsciiString hypofile = tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Hypo.txt");
892 TCollection_AsciiString algofile = tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Algo.txt");
893 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Mesh.med");
895 SALOMEDS::Study_var Study = theComponent->GetStudy();
896 int studyId = Study->StudyId();
899 SALOMEDS::GenericAttribute_var anAttr;
900 SALOMEDS::AttributeName_var aName;
901 SALOMEDS::AttributeIOR_var anIOR;
903 SALOMEDS::SComponent_var fathergeom = Study->FindComponent("GEOM");
904 SALOMEDS::SComponent_var myGeomSComp = SALOMEDS::SComponent::_narrow( fathergeom );
907 //to get the geom engine !!!
908 //useful to define our new mesh
909 SALOME_NamingService* _NS = SINGLETON_<SALOME_NamingService>::Instance() ;
910 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
911 _NS->init_orb( _orb ) ;
912 SALOME_LifeCycleCORBA* myEnginesLifeCycle = new SALOME_LifeCycleCORBA(_NS);
913 Engines::Component_var geomEngine =
914 myEnginesLifeCycle->FindOrLoad_Component("FactoryServer","GEOM");
915 GEOM::GEOM_Gen_var myGeomEngine = GEOM::GEOM_Gen::_narrow(geomEngine);
920 char objectId[10],name_dataset[10];
921 int nb_datasets,size,cmpt_ds=0;
924 char name[HDF_NAME_MAX_LEN+1];
925 char sgname[HDF_NAME_MAX_LEN+1];
926 char msgname[HDF_NAME_MAX_LEN+1];
927 char name_of_group[HDF_NAME_MAX_LEN+1];
928 char *name_meshgroup;
929 map <int,HDFgroup*> hdf_group, hdf_subgroup;
930 map <int,HDFdataset*> hdf_dataset;
933 //************* HDF file opening
934 HDFfile * hdf_file = new HDFfile(filename.ToCString());
936 hdf_file->OpenOnDisk(HDF_RDONLY);
938 catch (HDFexception) {
939 MESSAGE("Load(): " << filename << " not found!");
943 //****************************
945 int nb_group = hdf_file->nInternalObjects();
947 for (int i=0;i<nb_group;i++)
949 hdf_file->InternalObjectIndentify(i,name);
953 // Loading of the Hypothesis Branch
955 if (strcmp(name,"Hypothesis")==0) {
957 double length,maxElementsArea,maxElementsVolume;
958 int numberOfSegments;
960 hdf_group[Tag_HypothesisRoot] = new HDFgroup(name,hdf_file);
961 hdf_group[Tag_HypothesisRoot]->OpenOnDisk();
963 hdf_group[Tag_HypothesisRoot]->InternalObjectIndentify(0,name_of_group);
964 hdf_dataset[cmpt_ds]=new HDFdataset(name_of_group,hdf_group[Tag_HypothesisRoot]);
965 hdf_dataset[cmpt_ds]->OpenOnDisk();
966 size=hdf_dataset[cmpt_ds]->GetSize();
968 char * name_of_file =new char[size];
969 hdf_dataset[cmpt_ds]->ReadFromDisk(name_of_file);
970 SCRUTE(name_of_file);
971 hdf_dataset[cmpt_ds]->CloseOnDisk();
972 hdf_group[Tag_HypothesisRoot]->CloseOnDisk();
974 delete[] name_of_file;
977 aLine = new char[100];
978 loadedFile = fopen( hypofile.ToCString() ,"r");
979 while (!feof(loadedFile)) {
980 fscanf(loadedFile,"%s",aLine);
982 if (strcmp(aLine,"LocalLength")==0) {
983 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
984 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( myHyp );
985 fscanf(loadedFile,"%s",aLine);
986 length = atof(aLine);
987 LL->SetLength(length);
988 string iorString = _orb->object_to_string(LL);
989 sprintf(objectId,"%d",LL->GetId());
990 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
992 else if (strcmp(aLine,"NumberOfSegments")==0) {
993 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
994 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( myHyp );
995 fscanf(loadedFile,"%s",aLine);
996 numberOfSegments = atoi(aLine);
997 NOS->SetNumberOfSegments(numberOfSegments);
998 string iorString = _orb->object_to_string(NOS);
999 sprintf(objectId,"%d",NOS->GetId());
1000 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
1002 else if (strcmp(aLine,"MaxElementArea")==0) {
1003 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
1004 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( myHyp );
1005 fscanf(loadedFile,"%s",aLine);
1006 maxElementsArea = atof(aLine);
1007 MEA->SetMaxElementArea(maxElementsArea);
1008 string iorString = _orb->object_to_string(MEA);
1009 sprintf(objectId,"%d",MEA->GetId());
1010 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
1012 else if (strcmp(aLine,"MaxElementVolume")==0) {
1013 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
1014 SMESH::SMESH_MaxElementVolume_var MEV = SMESH::SMESH_MaxElementVolume::_narrow( myHyp );
1015 fscanf(loadedFile,"%s",aLine);
1016 maxElementsVolume = atof(aLine);
1017 MEV->SetMaxElementVolume(maxElementsVolume);
1018 string iorString = _orb->object_to_string(MEV);
1019 sprintf(objectId,"%d",MEV->GetId());
1020 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
1028 MESSAGE("End of Hypos Load");
1032 // Loading of the Algorithms Branch
1034 else if (strcmp(name,"Algorithms")==0) {
1036 hdf_group[Tag_AlgorithmsRoot] = new HDFgroup(name,hdf_file);
1037 hdf_group[Tag_AlgorithmsRoot]->OpenOnDisk();
1039 hdf_group[Tag_AlgorithmsRoot]->InternalObjectIndentify(0,name_of_group);
1040 hdf_dataset[cmpt_ds] = new HDFdataset(name_of_group,hdf_group[Tag_AlgorithmsRoot]);
1041 hdf_dataset[cmpt_ds]->OpenOnDisk();
1042 size=hdf_dataset[cmpt_ds]->GetSize();
1044 char * name_of_file =new char[size];
1045 hdf_dataset[cmpt_ds]->ReadFromDisk(name_of_file);
1046 hdf_dataset[cmpt_ds]->CloseOnDisk();
1047 hdf_group[Tag_AlgorithmsRoot]->CloseOnDisk();
1049 delete[] name_of_file;
1052 aLine = new char[100];
1053 loadedFile = fopen( algofile.ToCString(),"r");
1054 while (!feof(loadedFile)) {
1055 fscanf(loadedFile,"%s\n",aLine);
1057 if (strcmp(aLine,"")!=0) {
1058 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
1059 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1060 string iorString = _orb->object_to_string(myAlgo);
1061 sprintf(objectId,"%d",myAlgo->GetId());
1062 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
1068 MESSAGE("End of Algos Load");
1073 // Loading of the Mesh Branch
1075 else if (string(name).substr(0,4)==string("Mesh")) {
1076 MESSAGE("in mesh load");
1078 Standard_Integer myMeshId = atoi((string(name).substr(5,5)).c_str());
1081 hdf_group[myMeshId] = new HDFgroup(name,hdf_file);
1082 hdf_group[myMeshId]->OpenOnDisk();
1084 int nb_meshsubgroup = hdf_group[myMeshId]->nInternalObjects();
1085 SCRUTE(nb_meshsubgroup);
1087 //********** Loading of the file name where the data are stored
1088 MESSAGE("Mesh data file");
1089 strcpy(name_of_group,"Mesh data");
1090 hdf_dataset[cmpt_ds]=new HDFdataset(name_of_group,hdf_group[myMeshId]);
1091 hdf_dataset[cmpt_ds]->OpenOnDisk();
1092 size=hdf_dataset[cmpt_ds]->GetSize();
1094 char * datafilename =new char[size];
1095 hdf_dataset[cmpt_ds]->ReadFromDisk(datafilename);
1096 hdf_dataset[cmpt_ds]->CloseOnDisk();
1101 //else if (strcmp(msgname,"Ref on shape")==0) {
1103 //********** Loading of the reference on the shape
1104 //********** and mesh initialization
1105 MESSAGE("Ref on shape");
1106 strcpy(name_of_group,"Ref on shape");
1107 hdf_dataset[cmpt_ds] = new HDFdataset(name_of_group,hdf_group[myMeshId]);
1108 hdf_dataset[cmpt_ds]->OpenOnDisk();
1109 size=hdf_dataset[cmpt_ds]->GetSize();
1111 char * refFromFile =new char[size];
1112 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1113 hdf_dataset[cmpt_ds]->CloseOnDisk();
1116 Standard_CString myRefOnShape=""; //look for ref on shape
1118 bool _found = false;
1119 SALOMEDS::SObject_var CSO = Study->FindObjectID(refFromFile);
1120 SMESH::SMESH_Mesh_var myNewMesh;
1121 GEOM::GEOM_Shape_var aShape;
1123 if (!CORBA::is_nil(CSO)) {
1125 CSO->FindAttribute(anAttr, "AttributeIOR");
1126 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1127 char* ShapeIOR = anIOR->Value();
1128 aShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(ShapeIOR));
1130 myNewMesh = this->Init(myGeomEngine,studyId,aShape);
1131 string iorString = _orb->object_to_string(myNewMesh);
1132 sprintf(objectId,"%d",myNewMesh->GetId());
1133 _SMESHCorbaObj[string("Mesh_")+string(objectId)] = iorString;
1136 //********** Loading of mesh data
1137 if (strcmp(datafilename,"No data")!=0) {
1142 //****************************************************************************
1143 //* OUVERTURE DU FICHIER EN LECTURE *
1144 //****************************************************************************
1146 fid = MEDouvrir(datafilename,MED_LECT);
1149 printf(">> ERREUR : ouverture du fichier %s \n",datafilename);
1154 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
1155 int meshId = myNewMesh->GetId();
1156 SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
1157 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1158 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
1160 DriverMED_R_SMESHDS_Mesh* myReader = new DriverMED_R_SMESHDS_Mesh;
1162 myReader->SetMesh(mySMESHDSMesh);
1163 myReader->SetMeshId(myMeshId);
1164 myReader->SetFileId(fid);
1165 myReader->ReadMySelf();
1166 //SCRUTE(mySMESHDSMesh->NbNodes());
1167 //myNewMesh->ExportUNV("/tmp/test.unv");//only to check out
1169 //****************************************************************************
1170 //* FERMETURE DU FICHIER *
1171 //****************************************************************************
1172 ret = MEDfermer(fid);
1175 printf(">> ERREUR : erreur a la fermeture du fichier %s\n",datafilename);
1182 //else if (strcmp(msgname,"Applied Hypothesis")==0) {
1183 for (int ii=0;ii<nb_meshsubgroup;ii++)
1185 hdf_group[myMeshId]->InternalObjectIndentify(ii,msgname);
1186 if (strcmp(msgname,"Mesh data")==0) {
1189 else if (strcmp(msgname,"Ref on shape")==0) {
1192 else if (strcmp(msgname,"Applied Hypothesis")==0) {
1193 //********** Loading of the applied hypothesis
1194 strcpy(name_of_group,"Applied Hypothesis");
1195 hdf_subgroup[Tag_RefOnAppliedHypothesis] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1196 hdf_subgroup[Tag_RefOnAppliedHypothesis]->OpenOnDisk();
1198 nb_datasets = hdf_subgroup[Tag_RefOnAppliedHypothesis]->nInternalObjects();
1199 SCRUTE(nb_datasets);
1201 for (int j=0;j<nb_datasets;j++) {
1202 sprintf(name_dataset,"Hyp %d",j);
1203 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedHypothesis]);
1204 hdf_dataset[cmpt_ds]->OpenOnDisk();
1205 size=hdf_dataset[cmpt_ds]->GetSize();
1207 char * refFromFile =new char[size];
1208 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1209 //SCRUTE(refFromFile);
1210 hdf_dataset[cmpt_ds]->CloseOnDisk();
1213 SALOMEDS::SObject_var HypSO = Study->FindObjectID(refFromFile);
1214 if (!CORBA::is_nil(HypSO)) {
1215 HypSO->FindAttribute(anAttr, "AttributeIOR");
1216 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1217 if (!CORBA::is_nil(anIOR)) {
1218 char* HypIOR = anIOR->Value();
1219 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(HypIOR));
1220 if (!CORBA::is_nil(anHyp)) {
1221 myNewMesh->AddHypothesis(aShape,anHyp);
1222 MESSAGE("Hypothesis added ...");
1229 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CloseOnDisk();
1232 else if (strcmp(msgname,"Applied Algorithms")==0) {
1234 //********** Loading of the applied algorithms
1235 strcpy(name_of_group,"Applied Algorithms");
1236 hdf_subgroup[Tag_RefOnAppliedAlgorithms] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1237 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->OpenOnDisk();
1239 nb_datasets = hdf_subgroup[Tag_RefOnAppliedAlgorithms]->nInternalObjects();
1240 SCRUTE(nb_datasets);
1242 for (int j=0;j<nb_datasets;j++) {
1243 sprintf(name_dataset,"Algo %d",j);
1244 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedAlgorithms]);
1245 hdf_dataset[cmpt_ds]->OpenOnDisk();
1246 size=hdf_dataset[cmpt_ds]->GetSize();
1248 char * refFromFile =new char[size];
1249 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1250 hdf_dataset[cmpt_ds]->CloseOnDisk();
1254 SALOMEDS::SObject_var AlgoSO = Study->FindObjectID(refFromFile);
1255 if (!CORBA::is_nil(AlgoSO)) {
1256 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1257 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1258 if (!CORBA::is_nil(anIOR)) {
1259 char* AlgoIOR = anIOR->Value();
1261 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(AlgoIOR));
1262 SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1263 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1264 if (!CORBA::is_nil(anAlgo)) {
1265 myNewMesh->AddHypothesis(aShape,anAlgo);//essayer avec _SMESHCorbaObj
1266 MESSAGE("Algorithms added ...");
1273 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CloseOnDisk();
1277 else if (string(msgname).substr(0,9)==string("SubMeshes")) {
1280 //********** Loading of the submeshes on subshapes
1281 int myLevel1Tag, myTag;
1284 myLevel1Tag = 10+cmpt_sm;
1285 hdf_subgroup[myLevel1Tag] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1286 hdf_subgroup[myLevel1Tag] = new HDFgroup(msgname,hdf_group[myMeshId]);
1287 hdf_subgroup[myLevel1Tag]->OpenOnDisk();
1289 int nb_submeshes = hdf_subgroup[myLevel1Tag]->nInternalObjects();
1290 SCRUTE(nb_submeshes);
1292 for (int j=0;j<nb_submeshes;j++) {
1295 hdf_subgroup[myLevel1Tag]->InternalObjectIndentify(j,name_meshgroup);
1296 SCRUTE(name_meshgroup);
1298 hdf_subgroup[myTag] = new HDFgroup(name_meshgroup,hdf_subgroup[myLevel1Tag]);
1299 hdf_subgroup[myTag]->OpenOnDisk();
1300 int subMeshId = atoi((string(name_meshgroup).substr(8,18)).c_str());
1302 MESSAGE("Ref on shape");
1303 //********** ref on shape
1304 sprintf(name_dataset,"Ref on shape");
1305 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[myTag]);
1306 hdf_dataset[cmpt_ds]->OpenOnDisk();
1307 size=hdf_dataset[cmpt_ds]->GetSize();
1309 char * refFromFile =new char[size];
1310 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1311 hdf_dataset[cmpt_ds]->CloseOnDisk();
1314 bool _found3 = false;
1315 SALOMEDS::SObject_var GSO = Study->FindObjectID(refFromFile);
1316 SMESH::SMESH_subMesh_var aSubMesh;
1317 GEOM::GEOM_Shape_var aSubShape;
1319 if (!CORBA::is_nil(GSO)) {
1320 GSO->FindAttribute(anAttr, "AttributeIOR");
1321 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1322 char* SubShapeIOR = anIOR->Value();
1323 aSubShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(SubShapeIOR));
1325 if (!CORBA::is_nil(aSubShape)) {
1326 aSubMesh = myNewMesh->GetElementsOnShape(aSubShape);
1327 string iorString = _orb->object_to_string(aSubMesh);
1328 sprintf(objectId,"%d",subMeshId);
1329 _SMESHCorbaObj[string("SubMesh_")+string(objectId)] = iorString;
1331 //SCRUTE(aSubMesh->GetNumberOfNodes());
1333 //SCRUTE(aSubMesh->GetNumberOfElements());
1337 int nb_subgroup = hdf_subgroup[myTag]->nInternalObjects();
1338 SCRUTE(nb_subgroup);
1339 for (int k=0;k<nb_subgroup;k++)
1341 hdf_subgroup[myTag]->InternalObjectIndentify(k,sgname);
1342 if (strcmp(sgname,"Ref on shape")==0) {
1345 else if (strcmp(sgname,"Applied Hypothesis")==0) {
1346 //********** ref on applied hypothesis
1347 MESSAGE("Applied Hypothesis");
1348 strcpy(name_meshgroup,"Applied Hypothesis");
1350 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
1351 hdf_subgroup[10+cmpt_sm]->OpenOnDisk();
1352 nb_datasets = hdf_subgroup[10+cmpt_sm]->nInternalObjects();
1353 SCRUTE(nb_datasets);
1355 for (int l=0;l<nb_datasets;l++) {
1356 sprintf(name_dataset,"Hyp %d",l);
1357 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm]);
1358 hdf_dataset[cmpt_ds]->OpenOnDisk();
1359 size=hdf_dataset[cmpt_ds]->GetSize();
1361 char * refFromFile =new char[size];
1362 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1363 hdf_dataset[cmpt_ds]->CloseOnDisk();
1367 SALOMEDS::SObject_var HypSO = Study->FindObjectID(refFromFile);
1368 if (!CORBA::is_nil(HypSO)) {
1369 HypSO->FindAttribute(anAttr, "AttributeIOR");
1370 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1371 if (!CORBA::is_nil(anIOR)) {
1372 char* HypIOR = anIOR->Value();
1373 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(HypIOR));
1374 if (!CORBA::is_nil(anHyp)) {
1375 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1376 aMesh->AddHypothesis(aSubShape,anHyp);//essayer avec _SMESHCorbaObj
1377 MESSAGE("Hypothesis added ...");
1384 else if (strcmp(sgname,"Applied Algorithms")==0) {
1385 //********** ref on applied algorithms
1386 MESSAGE("Applied Algorithms");
1387 strcpy(name_meshgroup,"Applied Algorithms");
1389 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
1390 hdf_subgroup[10+cmpt_sm]->OpenOnDisk();
1391 nb_datasets = hdf_subgroup[10+cmpt_sm]->nInternalObjects();
1392 SCRUTE(nb_datasets);
1394 for (int l=0;l<nb_datasets;l++) {
1395 sprintf(name_dataset,"Algo %d",l);
1396 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm]);
1397 hdf_dataset[cmpt_ds]->OpenOnDisk();
1398 size=hdf_dataset[cmpt_ds]->GetSize();
1400 char * refFromFile =new char[size];
1401 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1402 hdf_dataset[cmpt_ds]->CloseOnDisk();
1406 SALOMEDS::SObject_var AlgoSO = Study->FindObjectID(refFromFile);
1407 if (!CORBA::is_nil(AlgoSO)) {
1408 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1409 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1410 if (!CORBA::is_nil(anIOR)) {
1411 char* AlgoIOR = anIOR->Value();
1413 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(AlgoIOR));
1414 SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1415 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1416 if (!CORBA::is_nil(anAlgo)) {
1417 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1418 aMesh->AddHypothesis(aSubShape,anAlgo);//essayer avec _SMESHCorbaObj
1419 MESSAGE("Algorithms added ...");
1428 hdf_subgroup[myTag]->CloseOnDisk();
1430 hdf_subgroup[myLevel1Tag]->CloseOnDisk();
1433 hdf_group[myMeshId]->CloseOnDisk();
1435 MESSAGE("End of Meshes Load");
1439 MESSAGE("End of SMESH_Gen::Load");
1441 hdf_file->CloseOnDisk();
1445 // Remove temporary files created from the stream
1446 if (isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(), true);
1451 bool SMESH_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
1452 const SALOMEDS::TMPFile& theStream,
1455 return Load(theComponent, theStream, theURL, isMultiFile);
1458 //=============================================================================
1462 //=============================================================================
1464 void SMESH_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
1467 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
1468 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
1469 for (; itBig->More();itBig->Next()) {
1470 SALOMEDS::SObject_var gotBranch = itBig->Value();
1472 // branch 1 : hypothesis
1473 if (gotBranch->Tag()==Tag_HypothesisRoot || gotBranch->Tag()==Tag_AlgorithmsRoot) {
1474 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(gotBranch);
1475 for (; it->More();it->Next()) {
1476 SALOMEDS::SObject_var mySObject = it->Value();
1477 SALOMEDS::GenericAttribute_var anAttr;
1478 SALOMEDS::AttributeIOR_var anIOR;
1479 if ( mySObject->FindAttribute(anAttr, "AttributeIOR")) {
1480 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1481 SMESH::SMESH_Hypothesis_var myHyp =
1482 SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
1484 sprintf(objectId,"%d",myHyp->GetId());
1485 // cout<<"********** delete Hyp "<<objectId<<endl;
1486 _SMESHCorbaObj.erase(string("Hypo_")+string(objectId));
1487 myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
1491 // branch 2 : algorithms
1492 else if (gotBranch->Tag()>=3) {
1493 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(gotBranch);
1494 for (; it->More();it->Next()) {
1495 SALOMEDS::SObject_var mySObject = it->Value();
1496 SALOMEDS::GenericAttribute_var anAttr;
1497 SALOMEDS::AttributeIOR_var anIOR;
1498 if ( mySObject->FindAttribute(anAttr, "AttributeIOR")) {
1499 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1500 SMESH::SMESH_Mesh_var myMesh =
1501 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
1502 if (!myMesh->_is_nil()) {
1504 sprintf(objectId,"%d",myMesh->GetId());
1505 // cout<<"********** delete Mesh "<<objectId<<endl;
1506 _SMESHCorbaObj.erase(string("Mesh_")+string(objectId));
1507 CORBA::release(myMesh);
1510 SMESH::SMESH_subMesh_var mySubMesh =
1511 SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value()));
1512 if (!mySubMesh->_is_nil()) {
1514 sprintf(objectId,"%d",mySubMesh->GetId());
1515 // cout<<"********** delete SubMesh "<<objectId<<endl;
1516 _SMESHCorbaObj.erase(string("SubMesh_")+string(objectId));
1517 CORBA::release(mySubMesh);
1526 //=============================================================================
1530 //=============================================================================
1532 char* SMESH_Gen_i::ComponentDataType()
1534 MESSAGE("SMESH_Gen_i::ComponentDataType");
1535 return strdup("SMESH");
1539 //=============================================================================
1543 //=============================================================================
1545 char* SMESH_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
1546 const char* IORString,
1547 CORBA::Boolean isMultiFile,
1548 CORBA::Boolean isASCII)
1550 MESSAGE("SMESH_Gen_i::IORToLocalPersistentID");
1554 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(IORString));
1555 if (! CORBA::is_nil(myAlgo))
1557 string prefix = "Hypo_";
1558 sprintf(objectId,"%d",myAlgo->GetId());
1559 string lpID = prefix + string(objectId);
1560 return CORBA::string_dup(lpID.c_str());
1563 SMESH::SMESH_Hypothesis_var myHypo = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(IORString));
1564 if (! CORBA::is_nil(myHypo))
1566 string prefix = "Hypo_";
1567 sprintf(objectId,"%d",myHypo->GetId());
1568 string lpID = prefix + string(objectId);
1569 return CORBA::string_dup(lpID.c_str());
1572 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(IORString));
1573 if (! CORBA::is_nil(myMesh))
1575 string prefix = "Mesh_";
1576 sprintf(objectId,"%d",myMesh->GetId());
1577 string lpID = prefix + string(objectId);
1578 return CORBA::string_dup(lpID.c_str());
1581 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(IORString));
1582 if (! CORBA::is_nil(mySubMesh))
1584 string prefix = "SubMesh_";
1585 sprintf(objectId,"%d",mySubMesh->GetId());
1586 string lpID = prefix + string(objectId);
1587 return CORBA::string_dup(lpID.c_str());
1589 else return (strdup("no object"));
1595 //=============================================================================
1599 //=============================================================================
1601 char* SMESH_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
1602 const char* aLocalPersistentID,
1603 CORBA::Boolean isMultiFile,
1604 CORBA::Boolean isASCII)
1606 MESSAGE("SMESH_Gen_i::LocalPersistentIDToIOR");
1607 SCRUTE(aLocalPersistentID);
1608 string clef = string(aLocalPersistentID);
1609 SCRUTE(_SMESHCorbaObj[clef].c_str());
1610 return CORBA::string_dup(_SMESHCorbaObj[clef].c_str());
1613 //=============================================================================
1617 //=============================================================================
1619 SMESH_topo* SMESH_Gen_i::ExploreMainShape(GEOM::GEOM_Gen_ptr geomEngine,
1620 CORBA::Long studyId,
1621 GEOM::GEOM_Shape_ptr aShape)
1623 MESSAGE("SMESH_Mesh_i::ExploreMainShape");
1624 // _narrow() duplicates the reference and check the type
1625 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
1626 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
1628 if (CORBA::is_nil(geom))
1629 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", \
1631 if (CORBA::is_nil(myShape))
1632 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
1635 SCRUTE(myShape->Name());
1636 geom->GetCurrentStudy(studyId);
1638 TopoDS_Shape mainShape = _ShapeReader->GetShape(geom,myShape);
1641 // create an SMESH_topo object for the mainShape
1643 SMESH_topo* myTopo = new SMESH_topo();
1646 // explore local TopoDS_Shape, store reference of local TopoDS subShapes
1648 for (TopExp_Explorer exp(mainShape,TopAbs_COMPOUND); exp.More(); exp.Next())
1650 const TopoDS_Compound& E = TopoDS::Compound(exp.Current());
1651 int i = myTopo->_myShapes[TopAbs_COMPOUND].Add(E);
1654 for (TopExp_Explorer exp(mainShape,TopAbs_COMPSOLID); exp.More(); exp.Next())
1656 const TopoDS_CompSolid& E = TopoDS::CompSolid(exp.Current());
1657 int i = myTopo->_myShapes[TopAbs_COMPSOLID].Add(E);
1660 for (TopExp_Explorer exp(mainShape,TopAbs_SOLID); exp.More(); exp.Next())
1662 const TopoDS_Solid& E = TopoDS::Solid(exp.Current());
1663 int i = myTopo->_myShapes[TopAbs_SOLID].Add(E);
1666 for (TopExp_Explorer exp(mainShape,TopAbs_SHELL); exp.More(); exp.Next())
1668 const TopoDS_Shell& E = TopoDS::Shell(exp.Current());
1669 int i = myTopo->_myShapes[TopAbs_SHELL].Add(E);
1672 for (TopExp_Explorer exp(mainShape,TopAbs_FACE); exp.More(); exp.Next())
1674 const TopoDS_Face& E = TopoDS::Face(exp.Current());
1675 int i = myTopo->_myShapes[TopAbs_FACE].Add(E);
1678 for (TopExp_Explorer exp(mainShape,TopAbs_WIRE); exp.More(); exp.Next())
1680 const TopoDS_Wire& E = TopoDS::Wire(exp.Current());
1681 int i = myTopo->_myShapes[TopAbs_WIRE].Add(E);
1684 for (TopExp_Explorer exp(mainShape,TopAbs_EDGE); exp.More(); exp.Next())
1686 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1687 int i = myTopo->_myShapes[TopAbs_EDGE].Add(E);
1690 for (TopExp_Explorer exp(mainShape,TopAbs_VERTEX); exp.More(); exp.Next())
1692 const TopoDS_Vertex& E = TopoDS::Vertex(exp.Current());
1693 int i = myTopo->_myShapes[TopAbs_VERTEX].Add(E);
1697 // explore subShapes of distant CORBA object,
1698 // associate distant CORBA subShape references
1699 // with local reference to local TopoDS subShape
1701 string filenode = "toposhape.txt";
1702 ofstream fic(filenode.c_str());
1704 for (int shapeType = TopAbs_COMPOUND; shapeType < TopAbs_SHAPE; shapeType++)
1706 fic << "shape type : " << SMESH_shapeTypeNames[shapeType];
1708 GEOM::GEOM_Gen::ListOfGeomShapes_var subShapes
1709 = geom->SubShapeAll(myShape,shapeType);
1710 int nbSubShapes = subShapes->length();
1711 int nbLocal = myTopo->_myShapes[shapeType].Extent();
1712 fic << " - number of elements: " << nbSubShapes << endl;
1713 ASSERT(nbSubShapes == nbLocal);
1715 for (int i=0; i< nbSubShapes; i++)
1717 GEOM::GEOM_Shape_var aSubShape = subShapes[i];
1718 string idShape = SMESH_topo::GetShapeLocalId(aSubShape);
1719 fic << " " << idShape;
1721 TopoDS_Shape aLocShape = _ShapeReader->GetShape(geom,aSubShape);
1722 for (int j=1; j <= nbLocal; j++)
1723 if (aLocShape.IsSame(myTopo->_myShapes[shapeType].FindKey(j)))
1725 MESSAGE(" --- trouve = " << j);
1726 myTopo->_mapIndShapes[shapeType][idShape] = j;
1727 fic << " --- trouve = " << j;
1738 //=============================================================================
1740 * C factory, accessible with dlsym, after dlopen
1742 //=============================================================================
1746 PortableServer::ObjectId * SMESHEngine_factory(
1748 PortableServer::POA_ptr poa,
1749 PortableServer::ObjectId * contId,
1750 const char *instanceName,
1751 const char *interfaceName)
1753 MESSAGE("PortableServer::ObjectId * SMESHEngine_factory()");
1754 SCRUTE(interfaceName);
1755 SMESH_Gen_i * mySMESH_Gen
1756 = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
1757 return mySMESH_Gen->getId() ;