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"
57 #include "SMESHDS_Document.hxx"
59 #include "Document_Reader.h"
60 #include "DriverMED_W_SMESHDS_Mesh.h"
61 #include "DriverMED_R_SMESHDS_Mesh.h"
62 #include "DriverMED_R_SMESHDS_Document.h"
63 #include "DriverUNV_R_SMESHDS_Document.h"
64 #include "DriverDAT_R_SMESHDS_Document.h"
66 #include "Utils_CorbaException.hxx"
67 #include "utilities.h"
69 #include "SALOMEDS_Tool.hxx"
70 #include "SALOME_NamingService.hxx"
71 #include "SALOME_LifeCycleCORBA.hxx"
72 #include "Utils_SINGLETON.hxx"
75 //#include <TopAbs_ShapeEnum.hxx>
77 #include "GEOM_Client.hxx"
81 #define NUM_TMP_FILES 4
84 long Tag_HypothesisRoot = 1;
85 long Tag_AlgorithmsRoot = 2;
87 long Tag_RefOnShape = 1;
88 long Tag_RefOnAppliedHypothesis = 2;
89 long Tag_RefOnAppliedAlgorithms = 3;
91 long Tag_SubMeshOnVertex = 4;
92 long Tag_SubMeshOnEdge = 5;
93 long Tag_SubMeshOnFace = 6;
94 long Tag_SubMeshOnSolid = 7;
95 long Tag_SubMeshOnCompound = 8;
98 //=============================================================================
100 * default constructor: not for use
102 //=============================================================================
104 SMESH_Gen_i::SMESH_Gen_i()
106 MESSAGE("SMESH_Gen_i default constructor");
110 //=============================================================================
112 * Standard constructor, used with Container.
114 //=============================================================================
116 SMESH_Gen_i::SMESH_Gen_i(CORBA::ORB_ptr orb,
117 PortableServer::POA_ptr poa,
118 PortableServer::ObjectId * contId,
119 const char *instanceName,
120 const char *interfaceName) :
121 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
123 MESSAGE("activate object");
125 _id = _poa->activate_object(_thisObj);
128 _localId = 0; // number of created objects & local id
132 //=============================================================================
134 * Standard destructor
136 //=============================================================================
138 SMESH_Gen_i::~SMESH_Gen_i()
140 MESSAGE("~SMESH_Gen_i");
144 //=============================================================================
148 //=============================================================================
150 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis(const char* anHyp,
152 throw (SALOME::SALOME_Exception)
154 MESSAGE("CreateHypothesis");
156 // create a new hypothesis object servant
158 SMESH_Hypothesis_i* myHypothesis_i = 0;
161 myHypothesis_i = _hypothesisFactory_i.Create(anHyp,
165 catch (SALOME_Exception& S_ex)
167 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
170 // activate the CORBA servant of hypothesis
172 SMESH::SMESH_Hypothesis_var hypothesis_i
173 = SMESH::SMESH_Hypothesis::_narrow(myHypothesis_i->_this());
174 return SMESH::SMESH_Hypothesis::_duplicate(hypothesis_i);
177 //=============================================================================
181 //=============================================================================
183 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Init(GEOM::GEOM_Gen_ptr geomEngine,
185 GEOM::GEOM_Shape_ptr aShape)
186 throw (SALOME::SALOME_Exception)
189 // _narrow() duplicates the reference and checks the type
190 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
191 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
193 if (CORBA::is_nil(geom))
194 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", \
196 if (CORBA::is_nil(myShape))
197 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
200 // Get or create the GEOM_Client instance
202 SMESH_Mesh_i* meshServant = 0;
205 if (! _ShapeReader) _ShapeReader = new GEOM_Client();
206 ASSERT(_ShapeReader);
208 // explore main Shape, get local TopoDS_Shapes of all subShapes
209 // SMESH_topo* myTopo = ExploreMainShape(geom, studyId, myShape);
211 // Get studyContext_i, create it if it does'nt exist
213 if (_mapStudyContext_i.find(studyId) == _mapStudyContext_i.end())
215 _mapStudyContext_i[studyId] = new StudyContext_iStruct;
217 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
219 // create a new mesh object servant, store it in a map in study context
221 meshServant = new SMESH_Mesh_i(this,
225 myStudyContext->mapMesh_i[_localId] = meshServant;
228 // create a new mesh object
230 TopoDS_Shape myLocShape = _ShapeReader->GetShape(geom,myShape);
231 meshServant->SetImpl(_impl.Init(studyId, myLocShape));
233 catch (SALOME_Exception& S_ex)
235 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
238 // activate the CORBA servant of Mesh
240 SMESH::SMESH_Mesh_var mesh
241 = SMESH::SMESH_Mesh::_narrow(meshServant->_this());
243 meshServant->SetIor(mesh);
245 return SMESH::SMESH_Mesh::_duplicate(mesh);
249 //=============================================================================
253 //=============================================================================
255 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute(SMESH::SMESH_Mesh_ptr aMesh,
256 GEOM::GEOM_Shape_ptr aShape)
257 throw (SALOME::SALOME_Exception)
259 MESSAGE("SMESH_Gen_i::IsReadyToCompute");
263 //=============================================================================
267 //=============================================================================
270 SMESH_Gen_i::GetSubShapesId(GEOM::GEOM_Gen_ptr geomEngine,
272 GEOM::GEOM_Shape_ptr mainShape,
273 const SMESH::shape_array& listOfSubShape)
274 throw (SALOME::SALOME_Exception)
276 MESSAGE("SMESH_Gen_i::GetSubShapesId");
277 SMESH::long_array_var shapesId = new SMESH::long_array;
280 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
281 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(mainShape);
283 if (CORBA::is_nil(geom))
284 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", \
286 if (CORBA::is_nil(myShape))
287 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
292 if (! _ShapeReader) _ShapeReader = new GEOM_Client();
293 ASSERT(_ShapeReader);
294 TopoDS_Shape myMainShape = _ShapeReader->GetShape(geom,myShape);
295 TopTools_IndexedMapOfShape myIndexToShape;
296 TopExp::MapShapes(myMainShape,myIndexToShape);
298 for (int i=0; i<listOfSubShape.length(); i++)
300 GEOM::GEOM_Shape_var aShape
301 = GEOM::GEOM_Shape::_narrow(listOfSubShape[i]);
302 if (CORBA::is_nil(aShape))
303 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
305 TopoDS_Shape locShape = _ShapeReader->GetShape(geom,aShape);
306 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
308 const TopoDS_Face& F = TopoDS::Face(exp.Current());
309 setId.insert(myIndexToShape.FindIndex(F));
310 SCRUTE(myIndexToShape.FindIndex(F));
312 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
314 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
315 setId.insert(myIndexToShape.FindIndex(E));
316 SCRUTE(myIndexToShape.FindIndex(E));
318 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
320 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
321 setId.insert(myIndexToShape.FindIndex(V));
322 SCRUTE(myIndexToShape.FindIndex(V));
325 shapesId->length(setId.size());
326 set<int>::iterator iind;
328 for (iind = setId.begin(); iind != setId.end(); iind++)
331 shapesId[i] = (*iind);
336 catch (SALOME_Exception& S_ex)
338 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
341 return shapesId._retn();
344 //=============================================================================
348 //=============================================================================
350 CORBA::Boolean SMESH_Gen_i::Compute(SMESH::SMESH_Mesh_ptr aMesh,
351 GEOM::GEOM_Shape_ptr aShape)
352 throw (SALOME::SALOME_Exception)
354 MESSAGE("SMESH_Gen_i::Compute");
355 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
356 if (CORBA::is_nil(myShape))
357 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
360 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(aMesh);
361 if (CORBA::is_nil(myMesh))
362 THROW_SALOME_CORBA_EXCEPTION("bad Mesh reference", \
369 // get study context from studyId given by CORBA mesh object
371 int studyId = myMesh->GetStudyId();
372 ASSERT(_mapStudyContext_i.find(studyId) != _mapStudyContext_i.end());
373 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
375 // get local Mesh_i object with Id and study context
377 int meshId = myMesh->GetId();
378 ASSERT(myStudyContext->mapMesh_i.find(meshId) != myStudyContext->mapMesh_i.end());
379 SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
382 // get local TopoDS_Shape
384 GEOM::GEOM_Gen_var geom = meshServant->GetGeomEngine();
385 TopoDS_Shape myLocShape = _ShapeReader->GetShape(geom,myShape);
387 // implementation compute
389 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
390 ret = _impl.Compute(myLocMesh, myLocShape);
392 catch (SALOME_Exception& S_ex)
394 MESSAGE("catch exception "<< S_ex.what());
396 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
403 //=============================================================================
407 //=============================================================================
409 SALOMEDS::TMPFile* SMESH_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
413 MESSAGE("SMESH_Gen_i::SAVE");
414 SALOMEDS::Study_var Study = theComponent->GetStudy();
417 // Declare a byte stream
418 SALOMEDS::TMPFile_var aStreamFile;
420 // Obtain a temporary dir
421 TCollection_AsciiString tmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
423 // Create a sequence of files processed
424 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
425 aFileSeq->length(NUM_TMP_FILES);
427 TCollection_AsciiString aStudyName(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
429 // Set names of temporary files
430 TCollection_AsciiString filename = aStudyName + TCollection_AsciiString("SMESH.hdf");
431 TCollection_AsciiString hypofile = aStudyName + TCollection_AsciiString("SMESH_Hypo.txt");
432 TCollection_AsciiString algofile = aStudyName + TCollection_AsciiString("SMESH_Algo.txt");
433 TCollection_AsciiString meshfile = aStudyName + TCollection_AsciiString("SMESH_Mesh.med");
434 aFileSeq[0] = CORBA::string_dup(filename.ToCString());
435 aFileSeq[1] = CORBA::string_dup(hypofile.ToCString());
436 aFileSeq[2] = CORBA::string_dup(algofile.ToCString());
437 aFileSeq[3] = CORBA::string_dup(meshfile.ToCString());
438 filename = tmpDir + filename;
439 hypofile = tmpDir + hypofile;
440 algofile = tmpDir + algofile;
441 meshfile = tmpDir + meshfile;
444 map <int,HDFgroup*> hdf_group, hdf_subgroup;
445 map <int,HDFdataset*> hdf_dataset;
448 SALOMEDS::ChildIterator_var itBig,it,itSM;
449 SALOMEDS::SObject_var mySObject,myBranch,mySObjectChild;
451 int longueur,cmpt_ds = 0,cmpt_it;
452 char *name_group,name_dataset[30],name_meshgroup[30];
454 int cmpt_sm = 0, myTag;
456 //************* HDF file creation
457 hdf_file = new HDFfile(filename.ToCString());
458 hdf_file->CreateOnDisk();
459 //****************************
461 itBig = Study->NewChildIterator(theComponent);
462 for (; itBig->More();itBig->Next()) {
463 SALOMEDS::SObject_var gotBranch = itBig->Value();
465 //************branch 1 : hypothesis
466 if (gotBranch->Tag()==Tag_HypothesisRoot) { //hypothesis = tag 1
468 double length,maxElementsArea;
469 int numberOfSegments;
471 destFile = fopen( hypofile.ToCString() ,"w");
472 it = Study->NewChildIterator(gotBranch);
473 for (; it->More();it->Next()) {
474 mySObject = it->Value();
475 SALOMEDS::GenericAttribute_var anAttr;
476 SALOMEDS::AttributeIOR_var anIOR;
477 if ( mySObject->FindAttribute(anAttr, "AttributeIOR")) {
478 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
480 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
481 fprintf(destFile,"%s\n",myHyp->GetName());
483 if (strcmp(myHyp->GetName(),"LocalLength")==0) {
484 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( myHyp );
485 length = LL->GetLength();
486 fprintf(destFile,"%f\n",length);
488 else if (strcmp(myHyp->GetName(),"NumberOfSegments")==0) {
489 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( myHyp );
490 numberOfSegments = NOS->GetNumberOfSegments();
491 fprintf(destFile,"%d\n",numberOfSegments);
493 else if (strcmp(myHyp->GetName(),"MaxElementArea")==0) {
494 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( myHyp );
495 maxElementsArea = MEA->GetMaxElementArea();
496 fprintf(destFile,"%f\n",maxElementsArea);
502 //writes the file name in the hdf file
503 longueur = hypofile.Length() +1;
504 name_group="Hypothesis";
505 //SCRUTE(name_group);
508 hdf_group[1] = new HDFgroup(name_group,hdf_file);
509 hdf_group[1]->CreateOnDisk();
511 hdf_dataset[cmpt_ds]=new HDFdataset(name_group,hdf_group[1],HDF_STRING,size,1);
512 hdf_dataset[cmpt_ds]->CreateOnDisk();
513 hdf_dataset[cmpt_ds]->WriteOnDisk(hypofile.ToCString());
514 hdf_dataset[cmpt_ds]->CloseOnDisk();
517 hdf_group[1]->CloseOnDisk();
518 MESSAGE("End of Hypothesis Save");
521 //************branch 2 : algorithms
522 else if (gotBranch->Tag()==Tag_AlgorithmsRoot) {//algos = tag 2
524 destFile = fopen( algofile.ToCString() ,"w");
525 it = Study->NewChildIterator(gotBranch);
526 for (; it->More();it->Next()) {
527 mySObject = it->Value();
528 SALOMEDS::GenericAttribute_var anAttr;
529 SALOMEDS::AttributeIOR_var anIOR;
530 if (mySObject->FindAttribute(anAttr, "AttributeIOR")) {
531 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
532 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(anIOR->Value()));
533 fprintf(destFile,"%s\n",myAlgo->GetName());
539 //writes the file name in the hdf file
540 longueur = algofile.Length() +1;
541 name_group="Algorithms";
542 //SCRUTE(name_group);
545 hdf_group[2] = new HDFgroup(name_group,hdf_file);
546 hdf_group[2]->CreateOnDisk();
548 hdf_dataset[cmpt_ds]=new HDFdataset(name_group,hdf_group[2],HDF_STRING,size,1);
549 hdf_dataset[cmpt_ds]->CreateOnDisk();
550 hdf_dataset[cmpt_ds]->WriteOnDisk(algofile.ToCString());
551 hdf_dataset[cmpt_ds]->CloseOnDisk();
554 hdf_group[2]->CloseOnDisk();
555 MESSAGE("End of Algos Save");
558 //************branch 3 : meshes
559 else if (gotBranch->Tag()>=3) {//meshes = tag > 3
561 SALOMEDS::GenericAttribute_var anAttr;
562 SALOMEDS::AttributeIOR_var anIOR;
563 if (gotBranch->FindAttribute(anAttr, "AttributeIOR")) {
564 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
566 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value())) ;
567 studyId = myMesh->GetStudyId();
570 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
571 int meshId = myMesh->GetId();
572 SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
573 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
574 Handle(SMESHDS_Mesh) mySMESHDSMesh = myLocMesh.GetMeshDS();
576 SCRUTE(mySMESHDSMesh->NbNodes());
577 if (mySMESHDSMesh->NbNodes()>0) {//checks if the mesh is not empty
579 DriverMED_W_SMESHDS_Mesh* myWriter = new DriverMED_W_SMESHDS_Mesh;
580 myWriter->SetFile(meshfile.ToCString());
582 myWriter->SetMesh(mySMESHDSMesh);
583 myWriter->SetMeshId(gotBranch->Tag());
586 else meshfile = "No data";
588 //********** opening of the HDF group
589 sprintf(name_meshgroup,"Mesh %d",gotBranch->Tag());
590 SCRUTE(name_meshgroup);
591 hdf_group[gotBranch->Tag()] = new HDFgroup(name_meshgroup,hdf_file);
592 hdf_group[gotBranch->Tag()]->CreateOnDisk();
595 //********** file where the data are stored
596 longueur = strlen(meshfile.ToCString()) +1;
598 strcpy(name_dataset,"Mesh data");
599 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_group[gotBranch->Tag()],HDF_STRING,size,1);
600 hdf_dataset[cmpt_ds]->CreateOnDisk();
601 hdf_dataset[cmpt_ds]->WriteOnDisk(meshfile.ToCString());
602 hdf_dataset[cmpt_ds]->CloseOnDisk();
606 //********** ref on shape
607 Standard_CString myRefOnObject="" ;
608 SALOMEDS::SObject_var myRef,myShape;
609 _found = gotBranch->FindSubObject(Tag_RefOnShape,myRef);
611 ok = myRef->ReferencedObject(myShape);
612 myRefOnObject = myShape->GetID();
613 SCRUTE(myRefOnObject);
615 longueur = strlen(myRefOnObject) +1;
618 strcpy(name_dataset,"Ref on shape");
619 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_group[gotBranch->Tag()],HDF_STRING,size,1);
620 hdf_dataset[cmpt_ds]->CreateOnDisk();
621 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
622 hdf_dataset[cmpt_ds]->CloseOnDisk();
629 //********** ref on applied hypothesis
630 _found = gotBranch->FindSubObject(Tag_RefOnAppliedHypothesis,myBranch);
633 strcpy(name_meshgroup,"Applied Hypothesis");
634 hdf_subgroup[Tag_RefOnAppliedHypothesis] = new HDFgroup(name_meshgroup,hdf_group[gotBranch->Tag()]);
635 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CreateOnDisk();
637 it = Study->NewChildIterator(myBranch);
639 for (; it->More();it->Next()) {
640 mySObject = it->Value();
641 ok = mySObject->ReferencedObject(myRef);
642 myRefOnObject = myRef->GetID();
644 longueur = strlen(myRefOnObject) +1;
647 sprintf(name_dataset,"Hyp %d",cmpt_it);
648 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedHypothesis],HDF_STRING,size,1);
649 hdf_dataset[cmpt_ds]->CreateOnDisk();
650 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
651 hdf_dataset[cmpt_ds]->CloseOnDisk();
656 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CloseOnDisk();
660 //********** ref on applied algorithms
661 _found = gotBranch->FindSubObject(Tag_RefOnAppliedAlgorithms,myBranch);
664 strcpy(name_meshgroup,"Applied Algorithms");
665 hdf_subgroup[Tag_RefOnAppliedAlgorithms] = new HDFgroup(name_meshgroup,hdf_group[gotBranch->Tag()]);
666 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CreateOnDisk();
668 it = Study->NewChildIterator(myBranch);
670 for (; it->More();it->Next()) {
671 mySObject = it->Value();
672 ok = mySObject->ReferencedObject(myRef);
673 myRefOnObject = myRef->GetID();
675 longueur = strlen(myRefOnObject) +1;
678 sprintf(name_dataset,"Algo %d",cmpt_it);
679 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedAlgorithms],HDF_STRING,size,1);
680 hdf_dataset[cmpt_ds]->CreateOnDisk();
681 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
682 hdf_dataset[cmpt_ds]->CloseOnDisk();
687 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CloseOnDisk();
689 MESSAGE("end of algo applied");
692 //********** submeshes on subshapes
694 for (int i=Tag_SubMeshOnVertex;i<=Tag_SubMeshOnCompound;i++) {
695 _found = gotBranch->FindSubObject(i,myBranch);
697 if (i==Tag_SubMeshOnVertex)
698 strcpy(name_meshgroup,"SubMeshes On Vertex");
699 else if (i==Tag_SubMeshOnEdge)
700 strcpy(name_meshgroup,"SubMeshes On Edge");
701 else if (i==Tag_SubMeshOnFace)
702 strcpy(name_meshgroup,"SubMeshes On Face");
703 else if (i==Tag_SubMeshOnSolid)
704 strcpy(name_meshgroup,"SubMeshes On Solid");
705 else if (i==Tag_SubMeshOnCompound)
706 strcpy(name_meshgroup,"SubMeshes On Compound");
709 myLevel1Tag = 10+cmpt_sm;
710 hdf_subgroup[myLevel1Tag] = new HDFgroup(name_meshgroup,hdf_group[gotBranch->Tag()]);
711 hdf_subgroup[myLevel1Tag]->CreateOnDisk();
713 itSM = Study->NewChildIterator(myBranch);
714 for (; itSM->More();itSM->Next()) {//Loop on all submeshes
715 mySObject = itSM->Value();
718 mySObject->FindAttribute(anAttr, "AttributeIOR");
719 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
720 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value())) ;
722 //sprintf(name_meshgroup,"SubMesh %d",myTag);
723 sprintf(name_meshgroup,"SubMesh %d",mySubMesh->GetId());
724 SCRUTE(name_meshgroup);
726 hdf_subgroup[myTag] = new HDFgroup(name_meshgroup,hdf_subgroup[myLevel1Tag]);
727 hdf_subgroup[myTag]->CreateOnDisk();
729 //********** ref on shape
730 Standard_CString myRefOnObject="" ;
731 SALOMEDS::SObject_var myRef,myShape;
733 _found2 = mySObject->FindSubObject(Tag_RefOnShape,myRef);
735 ok = myRef->ReferencedObject(myShape);
736 myRefOnObject = myShape->GetID();
737 SCRUTE(myRefOnObject);
739 longueur = strlen(myRefOnObject) +1;
742 strcpy(name_dataset,"Ref on shape");
743 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[myTag],HDF_STRING,size,1);
744 hdf_dataset[cmpt_ds]->CreateOnDisk();
745 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
746 hdf_dataset[cmpt_ds]->CloseOnDisk();
752 //********** ref on applied hypothesis
753 _found2 = mySObject->FindSubObject(Tag_RefOnAppliedHypothesis,myBranch);
756 strcpy(name_meshgroup,"Applied Hypothesis");
758 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
759 hdf_subgroup[10+cmpt_sm]->CreateOnDisk();
761 it = Study->NewChildIterator(myBranch);
763 for (; it->More();it->Next()) {
764 mySObjectChild = it->Value();
765 ok = mySObjectChild->ReferencedObject(myRef);
766 myRefOnObject = myRef->GetID();
768 longueur = strlen(myRefOnObject) +1;
771 sprintf(name_dataset,"Hyp %d",cmpt_it);
773 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm],HDF_STRING,size,1);
774 hdf_dataset[cmpt_ds]->CreateOnDisk();
775 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
776 hdf_dataset[cmpt_ds]->CloseOnDisk();
781 hdf_subgroup[10+cmpt_sm]->CloseOnDisk();
785 //********** ref on applied algorithms
786 _found2 = mySObject->FindSubObject(Tag_RefOnAppliedAlgorithms,myBranch);
790 strcpy(name_meshgroup,"Applied Algorithms");
792 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
793 hdf_subgroup[10+cmpt_sm]->CreateOnDisk();
795 it = Study->NewChildIterator(myBranch);
797 for (; it->More();it->Next()) {
798 mySObjectChild = it->Value();
799 ok = mySObjectChild->ReferencedObject(myRef);
800 myRefOnObject = myRef->GetID();
802 longueur = strlen(myRefOnObject) +1;
805 sprintf(name_dataset,"Algo %d",cmpt_it);
806 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm],HDF_STRING,size,1);
807 hdf_dataset[cmpt_ds]->CreateOnDisk();
808 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
809 hdf_dataset[cmpt_ds]->CloseOnDisk();
814 hdf_subgroup[10+cmpt_sm]->CloseOnDisk();
816 //MESSAGE("end of algo applied");
819 hdf_subgroup[myTag]->CloseOnDisk();
822 hdf_subgroup[myLevel1Tag]->CloseOnDisk();
828 //********** closing of the HDF group
829 hdf_group[gotBranch->Tag()]->CloseOnDisk();
830 MESSAGE("End of Mesh Save");
834 MESSAGE("End of Meshes Save");
837 hdf_file->CloseOnDisk();
841 // Convert temporary files to stream
842 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.ToCString(), aFileSeq.in(), isMultiFile);
844 // Remove temporary files and directory
845 if (isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(), true);
847 MESSAGE("End SMESH_Gen_i::Save");
849 return aStreamFile._retn();
852 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
855 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
856 return aStreamFile._retn();
859 //=============================================================================
863 //=============================================================================
865 bool SMESH_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
866 const SALOMEDS::TMPFile& theStream,
870 MESSAGE("SMESH_Gen_i::Load\n");
872 // Get temporary files location
873 TCollection_AsciiString tmpDir = isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
875 // Convert the stream into sequence of files to process
876 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
880 // Set names of temporary files
881 TCollection_AsciiString filename = tmpDir + aFileSeq[0];//"SMESH.hdf";
882 TCollection_AsciiString hypofile = tmpDir + aFileSeq[1];//"SMESH_Hypo.txt";
883 TCollection_AsciiString algofile = tmpDir + aFileSeq[2];//"SMESH_Algo.txt";
884 TCollection_AsciiString meshfile = tmpDir + aFileSeq[3];//"SMESH_Mesh.med";
886 SALOMEDS::Study_var Study = theComponent->GetStudy();
887 int studyId = Study->StudyId();
890 SALOMEDS::GenericAttribute_var anAttr;
891 SALOMEDS::AttributeName_var aName;
892 SALOMEDS::AttributeIOR_var anIOR;
894 SALOMEDS::SComponent_var fathergeom = Study->FindComponent("GEOM");
895 SALOMEDS::SComponent_var myGeomSComp = SALOMEDS::SComponent::_narrow( fathergeom );
898 //to get the geom engine !!!
899 //useful to define our new mesh
900 SALOME_NamingService* _NS = SINGLETON_<SALOME_NamingService>::Instance() ;
901 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
902 _NS->init_orb( _orb ) ;
903 SALOME_LifeCycleCORBA* myEnginesLifeCycle = new SALOME_LifeCycleCORBA(_NS);
904 Engines::Component_var geomEngine =
905 myEnginesLifeCycle->FindOrLoad_Component("FactoryServer","GEOM");
906 GEOM::GEOM_Gen_var myGeomEngine = GEOM::GEOM_Gen::_narrow(geomEngine);
911 char objectId[10],name_dataset[10];
912 int nb_datasets,size,cmpt_ds=0;
915 char name[HDF_NAME_MAX_LEN+1];
916 char sgname[HDF_NAME_MAX_LEN+1];
917 char msgname[HDF_NAME_MAX_LEN+1];
918 char name_of_group[HDF_NAME_MAX_LEN+1];
919 char *name_meshgroup;
920 map <int,HDFgroup*> hdf_group, hdf_subgroup;
921 map <int,HDFdataset*> hdf_dataset;
924 //************* HDF file opening
925 HDFfile * hdf_file = new HDFfile(filename.ToCString());
927 hdf_file->OpenOnDisk(HDF_RDONLY);
929 catch (HDFexception) {
930 MESSAGE("Load(): " << filename << " not found!");
934 //****************************
936 int nb_group = hdf_file->nInternalObjects();
938 for (int i=0;i<nb_group;i++)
940 hdf_file->InternalObjectIndentify(i,name);
944 // Loading of the Hypothesis Branch
946 if (strcmp(name,"Hypothesis")==0) {
948 double length,maxElementsArea;
949 int numberOfSegments;
951 hdf_group[Tag_HypothesisRoot] = new HDFgroup(name,hdf_file);
952 hdf_group[Tag_HypothesisRoot]->OpenOnDisk();
954 hdf_group[Tag_HypothesisRoot]->InternalObjectIndentify(0,name_of_group);
955 hdf_dataset[cmpt_ds]=new HDFdataset(name_of_group,hdf_group[Tag_HypothesisRoot]);
956 hdf_dataset[cmpt_ds]->OpenOnDisk();
957 size=hdf_dataset[cmpt_ds]->GetSize();
959 char * name_of_file =new char[size];
960 hdf_dataset[cmpt_ds]->ReadFromDisk(name_of_file);
961 SCRUTE(name_of_file);
962 hdf_dataset[cmpt_ds]->CloseOnDisk();
963 hdf_group[Tag_HypothesisRoot]->CloseOnDisk();
965 delete[] name_of_file;
968 aLine = new char[100];
969 loadedFile = fopen( hypofile.ToCString() ,"r");
970 while (!feof(loadedFile)) {
971 fscanf(loadedFile,"%s",aLine);
973 if (strcmp(aLine,"LocalLength")==0) {
974 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
975 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( myHyp );
976 fscanf(loadedFile,"%s",aLine);
977 length = atof(aLine);
978 LL->SetLength(length);
979 string iorString = _orb->object_to_string(LL);
980 sprintf(objectId,"%d",LL->GetId());
981 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
983 else if (strcmp(aLine,"NumberOfSegments")==0) {
984 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
985 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( myHyp );
986 fscanf(loadedFile,"%s",aLine);
987 numberOfSegments = atoi(aLine);
988 NOS->SetNumberOfSegments(numberOfSegments);
989 string iorString = _orb->object_to_string(NOS);
990 sprintf(objectId,"%d",NOS->GetId());
991 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
993 else if (strcmp(aLine,"MaxElementArea")==0) {
994 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
995 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( myHyp );
996 fscanf(loadedFile,"%s",aLine);
997 maxElementsArea = atof(aLine);
998 MEA->SetMaxElementArea(maxElementsArea);
999 string iorString = _orb->object_to_string(MEA);
1000 sprintf(objectId,"%d",MEA->GetId());
1001 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
1009 MESSAGE("End of Hypos Load");
1013 // Loading of the Algorithms Branch
1015 else if (strcmp(name,"Algorithms")==0) {
1017 hdf_group[Tag_AlgorithmsRoot] = new HDFgroup(name,hdf_file);
1018 hdf_group[Tag_AlgorithmsRoot]->OpenOnDisk();
1020 hdf_group[Tag_AlgorithmsRoot]->InternalObjectIndentify(0,name_of_group);
1021 hdf_dataset[cmpt_ds] = new HDFdataset(name_of_group,hdf_group[Tag_AlgorithmsRoot]);
1022 hdf_dataset[cmpt_ds]->OpenOnDisk();
1023 size=hdf_dataset[cmpt_ds]->GetSize();
1025 char * name_of_file =new char[size];
1026 hdf_dataset[cmpt_ds]->ReadFromDisk(name_of_file);
1027 hdf_dataset[cmpt_ds]->CloseOnDisk();
1028 hdf_group[Tag_AlgorithmsRoot]->CloseOnDisk();
1030 delete[] name_of_file;
1033 aLine = new char[100];
1034 loadedFile = fopen( algofile.ToCString(),"r");
1035 while (!feof(loadedFile)) {
1036 fscanf(loadedFile,"%s\n",aLine);
1038 if (strcmp(aLine,"")!=0) {
1039 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
1040 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1041 string iorString = _orb->object_to_string(myAlgo);
1042 sprintf(objectId,"%d",myAlgo->GetId());
1043 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
1049 MESSAGE("End of Algos Load");
1054 // Loading of the Mesh Branch
1056 else if (string(name).substr(0,4)==string("Mesh")) {
1057 MESSAGE("in mesh load");
1059 Standard_Integer myMeshId = atoi((string(name).substr(5,5)).c_str());
1062 hdf_group[myMeshId] = new HDFgroup(name,hdf_file);
1063 hdf_group[myMeshId]->OpenOnDisk();
1065 int nb_meshsubgroup = hdf_group[myMeshId]->nInternalObjects();
1066 SCRUTE(nb_meshsubgroup);
1068 //********** Loading of the file name where the data are stored
1069 MESSAGE("Mesh data file");
1070 strcpy(name_of_group,"Mesh data");
1071 hdf_dataset[cmpt_ds]=new HDFdataset(name_of_group,hdf_group[myMeshId]);
1072 hdf_dataset[cmpt_ds]->OpenOnDisk();
1073 size=hdf_dataset[cmpt_ds]->GetSize();
1075 char * datafilename =new char[size];
1076 hdf_dataset[cmpt_ds]->ReadFromDisk(datafilename);
1077 hdf_dataset[cmpt_ds]->CloseOnDisk();
1082 //else if (strcmp(msgname,"Ref on shape")==0) {
1084 //********** Loading of the reference on the shape
1085 //********** and mesh initialization
1086 MESSAGE("Ref on shape");
1087 strcpy(name_of_group,"Ref on shape");
1088 hdf_dataset[cmpt_ds] = new HDFdataset(name_of_group,hdf_group[myMeshId]);
1089 hdf_dataset[cmpt_ds]->OpenOnDisk();
1090 size=hdf_dataset[cmpt_ds]->GetSize();
1092 char * refFromFile =new char[size];
1093 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1094 hdf_dataset[cmpt_ds]->CloseOnDisk();
1097 Standard_CString myRefOnShape=""; //look for ref on shape
1099 bool _found = false;
1100 SALOMEDS::SObject_var CSO = Study->FindObjectID(refFromFile);
1101 SMESH::SMESH_Mesh_var myNewMesh;
1102 GEOM::GEOM_Shape_var aShape;
1104 if (!CORBA::is_nil(CSO)) {
1106 CSO->FindAttribute(anAttr, "AttributeIOR");
1107 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1108 char* ShapeIOR = anIOR->Value();
1109 aShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(ShapeIOR));
1111 myNewMesh = this->Init(myGeomEngine,studyId,aShape);
1112 string iorString = _orb->object_to_string(myNewMesh);
1113 sprintf(objectId,"%d",myNewMesh->GetId());
1114 _SMESHCorbaObj[string("Mesh_")+string(objectId)] = iorString;
1117 //********** Loading of mesh data
1118 if (strcmp(datafilename,"No data")!=0) {
1123 //****************************************************************************
1124 //* OUVERTURE DU FICHIER EN LECTURE *
1125 //****************************************************************************
1127 fid = MEDouvrir(datafilename,MED_LECT);
1130 printf(">> ERREUR : ouverture du fichier %s \n",datafilename);
1135 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
1136 int meshId = myNewMesh->GetId();
1137 SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
1138 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1139 Handle(SMESHDS_Mesh) mySMESHDSMesh = myLocMesh.GetMeshDS();
1141 DriverMED_R_SMESHDS_Mesh* myReader = new DriverMED_R_SMESHDS_Mesh;
1143 myReader->SetMesh(mySMESHDSMesh);
1144 myReader->SetMeshId(myMeshId);
1145 myReader->SetFileId(fid);
1146 myReader->ReadMySelf();
1147 //SCRUTE(mySMESHDSMesh->NbNodes());
1148 //myNewMesh->ExportUNV("/tmp/test.unv");//only to check out
1150 //****************************************************************************
1151 //* FERMETURE DU FICHIER *
1152 //****************************************************************************
1153 ret = MEDfermer(fid);
1156 printf(">> ERREUR : erreur a la fermeture du fichier %s\n",datafilename);
1163 //else if (strcmp(msgname,"Applied Hypothesis")==0) {
1164 for (int ii=0;ii<nb_meshsubgroup;ii++)
1166 hdf_group[myMeshId]->InternalObjectIndentify(ii,msgname);
1167 if (strcmp(msgname,"Mesh data")==0) {
1170 else if (strcmp(msgname,"Ref on shape")==0) {
1173 else if (strcmp(msgname,"Applied Hypothesis")==0) {
1174 //********** Loading of the applied hypothesis
1175 strcpy(name_of_group,"Applied Hypothesis");
1176 hdf_subgroup[Tag_RefOnAppliedHypothesis] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1177 hdf_subgroup[Tag_RefOnAppliedHypothesis]->OpenOnDisk();
1179 nb_datasets = hdf_subgroup[Tag_RefOnAppliedHypothesis]->nInternalObjects();
1180 SCRUTE(nb_datasets);
1182 for (int j=0;j<nb_datasets;j++) {
1183 sprintf(name_dataset,"Hyp %d",j);
1184 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedHypothesis]);
1185 hdf_dataset[cmpt_ds]->OpenOnDisk();
1186 size=hdf_dataset[cmpt_ds]->GetSize();
1188 char * refFromFile =new char[size];
1189 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1190 //SCRUTE(refFromFile);
1191 hdf_dataset[cmpt_ds]->CloseOnDisk();
1194 SALOMEDS::SObject_var HypSO = Study->FindObjectID(refFromFile);
1195 if (!CORBA::is_nil(HypSO)) {
1196 HypSO->FindAttribute(anAttr, "AttributeIOR");
1197 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1198 if (!CORBA::is_nil(anIOR)) {
1199 char* HypIOR = anIOR->Value();
1200 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(HypIOR));
1201 if (!CORBA::is_nil(anHyp)) {
1202 myNewMesh->AddHypothesis(aShape,anHyp);
1203 MESSAGE("Hypothesis added ...");
1210 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CloseOnDisk();
1213 else if (strcmp(msgname,"Applied Algorithms")==0) {
1215 //********** Loading of the applied algorithms
1216 strcpy(name_of_group,"Applied Algorithms");
1217 hdf_subgroup[Tag_RefOnAppliedAlgorithms] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1218 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->OpenOnDisk();
1220 nb_datasets = hdf_subgroup[Tag_RefOnAppliedAlgorithms]->nInternalObjects();
1221 SCRUTE(nb_datasets);
1223 for (int j=0;j<nb_datasets;j++) {
1224 sprintf(name_dataset,"Algo %d",j);
1225 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedAlgorithms]);
1226 hdf_dataset[cmpt_ds]->OpenOnDisk();
1227 size=hdf_dataset[cmpt_ds]->GetSize();
1229 char * refFromFile =new char[size];
1230 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1231 hdf_dataset[cmpt_ds]->CloseOnDisk();
1235 SALOMEDS::SObject_var AlgoSO = Study->FindObjectID(refFromFile);
1236 if (!CORBA::is_nil(AlgoSO)) {
1237 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1238 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1239 if (!CORBA::is_nil(anIOR)) {
1240 char* AlgoIOR = anIOR->Value();
1242 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(AlgoIOR));
1243 SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1244 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1245 if (!CORBA::is_nil(anAlgo)) {
1246 myNewMesh->AddHypothesis(aShape,anAlgo);//essayer avec _SMESHCorbaObj
1247 MESSAGE("Algorithms added ...");
1254 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CloseOnDisk();
1258 else if (string(msgname).substr(0,9)==string("SubMeshes")) {
1261 //********** Loading of the submeshes on subshapes
1262 int myLevel1Tag, myTag;
1265 myLevel1Tag = 10+cmpt_sm;
1266 hdf_subgroup[myLevel1Tag] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1267 hdf_subgroup[myLevel1Tag] = new HDFgroup(msgname,hdf_group[myMeshId]);
1268 hdf_subgroup[myLevel1Tag]->OpenOnDisk();
1270 int nb_submeshes = hdf_subgroup[myLevel1Tag]->nInternalObjects();
1271 SCRUTE(nb_submeshes);
1273 for (int j=0;j<nb_submeshes;j++) {
1276 hdf_subgroup[myLevel1Tag]->InternalObjectIndentify(j,name_meshgroup);
1277 SCRUTE(name_meshgroup);
1279 hdf_subgroup[myTag] = new HDFgroup(name_meshgroup,hdf_subgroup[myLevel1Tag]);
1280 hdf_subgroup[myTag]->OpenOnDisk();
1281 int subMeshId = atoi((string(name_meshgroup).substr(8,18)).c_str());
1283 MESSAGE("Ref on shape");
1284 //********** ref on shape
1285 sprintf(name_dataset,"Ref on shape");
1286 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[myTag]);
1287 hdf_dataset[cmpt_ds]->OpenOnDisk();
1288 size=hdf_dataset[cmpt_ds]->GetSize();
1290 char * refFromFile =new char[size];
1291 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1292 hdf_dataset[cmpt_ds]->CloseOnDisk();
1295 bool _found3 = false;
1296 SALOMEDS::SObject_var GSO = Study->FindObjectID(refFromFile);
1297 SMESH::SMESH_subMesh_var aSubMesh;
1298 GEOM::GEOM_Shape_var aSubShape;
1300 if (!CORBA::is_nil(GSO)) {
1301 GSO->FindAttribute(anAttr, "AttributeIOR");
1302 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1303 char* SubShapeIOR = anIOR->Value();
1304 aSubShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(SubShapeIOR));
1306 if (!CORBA::is_nil(aSubShape)) {
1307 aSubMesh = myNewMesh->GetElementsOnShape(aSubShape);
1308 string iorString = _orb->object_to_string(aSubMesh);
1309 sprintf(objectId,"%d",subMeshId);
1310 _SMESHCorbaObj[string("SubMesh_")+string(objectId)] = iorString;
1312 //SCRUTE(aSubMesh->GetNumberOfNodes());
1314 //SCRUTE(aSubMesh->GetNumberOfElements());
1318 int nb_subgroup = hdf_subgroup[myTag]->nInternalObjects();
1319 SCRUTE(nb_subgroup);
1320 for (int k=0;k<nb_subgroup;k++)
1322 hdf_subgroup[myTag]->InternalObjectIndentify(k,sgname);
1323 if (strcmp(sgname,"Ref on shape")==0) {
1326 else if (strcmp(sgname,"Applied Hypothesis")==0) {
1327 //********** ref on applied hypothesis
1328 MESSAGE("Applied Hypothesis");
1329 strcpy(name_meshgroup,"Applied Hypothesis");
1331 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
1332 hdf_subgroup[10+cmpt_sm]->OpenOnDisk();
1333 nb_datasets = hdf_subgroup[10+cmpt_sm]->nInternalObjects();
1334 SCRUTE(nb_datasets);
1336 for (int l=0;l<nb_datasets;l++) {
1337 sprintf(name_dataset,"Hyp %d",l);
1338 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm]);
1339 hdf_dataset[cmpt_ds]->OpenOnDisk();
1340 size=hdf_dataset[cmpt_ds]->GetSize();
1342 char * refFromFile =new char[size];
1343 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1344 hdf_dataset[cmpt_ds]->CloseOnDisk();
1348 SALOMEDS::SObject_var HypSO = Study->FindObjectID(refFromFile);
1349 if (!CORBA::is_nil(HypSO)) {
1350 HypSO->FindAttribute(anAttr, "AttributeIOR");
1351 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1352 if (!CORBA::is_nil(anIOR)) {
1353 char* HypIOR = anIOR->Value();
1354 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(HypIOR));
1355 if (!CORBA::is_nil(anHyp)) {
1356 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1357 aMesh->AddHypothesis(aSubShape,anHyp);//essayer avec _SMESHCorbaObj
1358 MESSAGE("Hypothesis added ...");
1365 else if (strcmp(sgname,"Applied Algorithms")==0) {
1366 //********** ref on applied algorithms
1367 MESSAGE("Applied Algorithms");
1368 strcpy(name_meshgroup,"Applied Algorithms");
1370 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
1371 hdf_subgroup[10+cmpt_sm]->OpenOnDisk();
1372 nb_datasets = hdf_subgroup[10+cmpt_sm]->nInternalObjects();
1373 SCRUTE(nb_datasets);
1375 for (int l=0;l<nb_datasets;l++) {
1376 sprintf(name_dataset,"Algo %d",l);
1377 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm]);
1378 hdf_dataset[cmpt_ds]->OpenOnDisk();
1379 size=hdf_dataset[cmpt_ds]->GetSize();
1381 char * refFromFile =new char[size];
1382 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1383 hdf_dataset[cmpt_ds]->CloseOnDisk();
1387 SALOMEDS::SObject_var AlgoSO = Study->FindObjectID(refFromFile);
1388 if (!CORBA::is_nil(AlgoSO)) {
1389 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1390 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1391 if (!CORBA::is_nil(anIOR)) {
1392 char* AlgoIOR = anIOR->Value();
1394 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(AlgoIOR));
1395 SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1396 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1397 if (!CORBA::is_nil(anAlgo)) {
1398 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1399 aMesh->AddHypothesis(aSubShape,anAlgo);//essayer avec _SMESHCorbaObj
1400 MESSAGE("Algorithms added ...");
1409 hdf_subgroup[myTag]->CloseOnDisk();
1411 hdf_subgroup[myLevel1Tag]->CloseOnDisk();
1414 hdf_group[myMeshId]->CloseOnDisk();
1416 MESSAGE("End of Meshes Load");
1420 MESSAGE("End of SMESH_Gen::Load");
1422 hdf_file->CloseOnDisk();
1426 // Remove temporary files created from the stream
1427 if (isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(), true);
1432 bool SMESH_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
1433 const SALOMEDS::TMPFile& theStream,
1436 return Load(theComponent, theStream, theURL, isMultiFile);
1439 //=============================================================================
1443 //=============================================================================
1445 void SMESH_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
1448 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
1449 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
1450 for (; itBig->More();itBig->Next()) {
1451 SALOMEDS::SObject_var gotBranch = itBig->Value();
1453 // branch 1 : hypothesis
1454 if (gotBranch->Tag()==Tag_HypothesisRoot || gotBranch->Tag()==Tag_AlgorithmsRoot) {
1455 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(gotBranch);
1456 for (; it->More();it->Next()) {
1457 SALOMEDS::SObject_var mySObject = it->Value();
1458 SALOMEDS::GenericAttribute_var anAttr;
1459 SALOMEDS::AttributeIOR_var anIOR;
1460 if ( mySObject->FindAttribute(anAttr, "AttributeIOR")) {
1461 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1462 SMESH::SMESH_Hypothesis_var myHyp =
1463 SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
1465 sprintf(objectId,"%d",myHyp->GetId());
1466 // cout<<"********** delete Hyp "<<objectId<<endl;
1467 _SMESHCorbaObj.erase(string("Hypo_")+string(objectId));
1468 myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
1472 // branch 2 : algorithms
1473 else if (gotBranch->Tag()>=3) {
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_Mesh_var myMesh =
1482 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
1483 if (!myMesh->_is_nil()) {
1485 sprintf(objectId,"%d",myMesh->GetId());
1486 // cout<<"********** delete Mesh "<<objectId<<endl;
1487 _SMESHCorbaObj.erase(string("Mesh_")+string(objectId));
1488 CORBA::release(myMesh);
1491 SMESH::SMESH_subMesh_var mySubMesh =
1492 SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value()));
1493 if (!mySubMesh->_is_nil()) {
1495 sprintf(objectId,"%d",mySubMesh->GetId());
1496 // cout<<"********** delete SubMesh "<<objectId<<endl;
1497 _SMESHCorbaObj.erase(string("SubMesh_")+string(objectId));
1498 CORBA::release(mySubMesh);
1507 //=============================================================================
1511 //=============================================================================
1513 char* SMESH_Gen_i::ComponentDataType()
1515 MESSAGE("SMESH_Gen_i::ComponentDataType");
1516 return strdup("SMESH");
1520 //=============================================================================
1524 //=============================================================================
1526 char* SMESH_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
1527 const char* IORString,
1528 CORBA::Boolean isMultiFile,
1529 CORBA::Boolean isASCII)
1531 MESSAGE("SMESH_Gen_i::IORToLocalPersistentID");
1535 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(IORString));
1536 if (! CORBA::is_nil(myAlgo))
1538 string prefix = "Hypo_";
1539 sprintf(objectId,"%d",myAlgo->GetId());
1540 string lpID = prefix + string(objectId);
1541 return CORBA::string_dup(lpID.c_str());
1544 SMESH::SMESH_Hypothesis_var myHypo = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(IORString));
1545 if (! CORBA::is_nil(myHypo))
1547 string prefix = "Hypo_";
1548 sprintf(objectId,"%d",myHypo->GetId());
1549 string lpID = prefix + string(objectId);
1550 return CORBA::string_dup(lpID.c_str());
1553 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(IORString));
1554 if (! CORBA::is_nil(myMesh))
1556 string prefix = "Mesh_";
1557 sprintf(objectId,"%d",myMesh->GetId());
1558 string lpID = prefix + string(objectId);
1559 return CORBA::string_dup(lpID.c_str());
1562 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(IORString));
1563 if (! CORBA::is_nil(mySubMesh))
1565 string prefix = "SubMesh_";
1566 sprintf(objectId,"%d",mySubMesh->GetId());
1567 string lpID = prefix + string(objectId);
1568 return CORBA::string_dup(lpID.c_str());
1570 else return (strdup("no object"));
1576 //=============================================================================
1580 //=============================================================================
1582 char* SMESH_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
1583 const char* aLocalPersistentID,
1584 CORBA::Boolean isMultiFile,
1585 CORBA::Boolean isASCII)
1587 MESSAGE("SMESH_Gen_i::LocalPersistentIDToIOR");
1588 SCRUTE(aLocalPersistentID);
1589 string clef = string(aLocalPersistentID);
1590 SCRUTE(_SMESHCorbaObj[clef].c_str());
1591 return CORBA::string_dup(_SMESHCorbaObj[clef].c_str());
1594 //=============================================================================
1598 //=============================================================================
1600 SMESH_topo* SMESH_Gen_i::ExploreMainShape(GEOM::GEOM_Gen_ptr geomEngine,
1601 CORBA::Long studyId,
1602 GEOM::GEOM_Shape_ptr aShape)
1604 MESSAGE("SMESH_Mesh_i::ExploreMainShape");
1605 // _narrow() duplicates the reference and check the type
1606 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
1607 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
1609 if (CORBA::is_nil(geom))
1610 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", \
1612 if (CORBA::is_nil(myShape))
1613 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
1616 SCRUTE(myShape->Name());
1617 geom->GetCurrentStudy(studyId);
1619 TopoDS_Shape mainShape = _ShapeReader->GetShape(geom,myShape);
1622 // create an SMESH_topo object for the mainShape
1624 SMESH_topo* myTopo = new SMESH_topo();
1627 // explore local TopoDS_Shape, store reference of local TopoDS subShapes
1629 for (TopExp_Explorer exp(mainShape,TopAbs_COMPOUND); exp.More(); exp.Next())
1631 const TopoDS_Compound& E = TopoDS::Compound(exp.Current());
1632 int i = myTopo->_myShapes[TopAbs_COMPOUND].Add(E);
1635 for (TopExp_Explorer exp(mainShape,TopAbs_COMPSOLID); exp.More(); exp.Next())
1637 const TopoDS_CompSolid& E = TopoDS::CompSolid(exp.Current());
1638 int i = myTopo->_myShapes[TopAbs_COMPSOLID].Add(E);
1641 for (TopExp_Explorer exp(mainShape,TopAbs_SOLID); exp.More(); exp.Next())
1643 const TopoDS_Solid& E = TopoDS::Solid(exp.Current());
1644 int i = myTopo->_myShapes[TopAbs_SOLID].Add(E);
1647 for (TopExp_Explorer exp(mainShape,TopAbs_SHELL); exp.More(); exp.Next())
1649 const TopoDS_Shell& E = TopoDS::Shell(exp.Current());
1650 int i = myTopo->_myShapes[TopAbs_SHELL].Add(E);
1653 for (TopExp_Explorer exp(mainShape,TopAbs_FACE); exp.More(); exp.Next())
1655 const TopoDS_Face& E = TopoDS::Face(exp.Current());
1656 int i = myTopo->_myShapes[TopAbs_FACE].Add(E);
1659 for (TopExp_Explorer exp(mainShape,TopAbs_WIRE); exp.More(); exp.Next())
1661 const TopoDS_Wire& E = TopoDS::Wire(exp.Current());
1662 int i = myTopo->_myShapes[TopAbs_WIRE].Add(E);
1665 for (TopExp_Explorer exp(mainShape,TopAbs_EDGE); exp.More(); exp.Next())
1667 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1668 int i = myTopo->_myShapes[TopAbs_EDGE].Add(E);
1671 for (TopExp_Explorer exp(mainShape,TopAbs_VERTEX); exp.More(); exp.Next())
1673 const TopoDS_Vertex& E = TopoDS::Vertex(exp.Current());
1674 int i = myTopo->_myShapes[TopAbs_VERTEX].Add(E);
1678 // explore subShapes of distant CORBA object,
1679 // associate distant CORBA subShape references
1680 // with local reference to local TopoDS subShape
1682 string filenode = "toposhape.txt";
1683 ofstream fic(filenode.c_str());
1685 for (int shapeType = TopAbs_COMPOUND; shapeType < TopAbs_SHAPE; shapeType++)
1687 fic << "shape type : " << SMESH_shapeTypeNames[shapeType];
1689 GEOM::GEOM_Gen::ListOfGeomShapes_var subShapes
1690 = geom->SubShapeAll(myShape,shapeType);
1691 int nbSubShapes = subShapes->length();
1692 int nbLocal = myTopo->_myShapes[shapeType].Extent();
1693 fic << " - number of elements: " << nbSubShapes << endl;
1694 ASSERT(nbSubShapes == nbLocal);
1696 for (int i=0; i< nbSubShapes; i++)
1698 GEOM::GEOM_Shape_var aSubShape = subShapes[i];
1699 string idShape = SMESH_topo::GetShapeLocalId(aSubShape);
1700 fic << " " << idShape;
1702 TopoDS_Shape aLocShape = _ShapeReader->GetShape(geom,aSubShape);
1703 for (int j=1; j <= nbLocal; j++)
1704 if (aLocShape.IsSame(myTopo->_myShapes[shapeType].FindKey(j)))
1706 MESSAGE(" --- trouve = " << j);
1707 myTopo->_mapIndShapes[shapeType][idShape] = j;
1708 fic << " --- trouve = " << j;
1719 //=============================================================================
1721 * C factory, accessible with dlsym, after dlopen
1723 //=============================================================================
1727 PortableServer::ObjectId * SMESHEngine_factory(
1729 PortableServer::POA_ptr poa,
1730 PortableServer::ObjectId * contId,
1731 const char *instanceName,
1732 const char *interfaceName)
1734 MESSAGE("PortableServer::ObjectId * SMESHEngine_factory()");
1735 SCRUTE(interfaceName);
1736 SMESH_Gen_i * mySMESH_Gen
1737 = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
1738 return mySMESH_Gen->getId() ;