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 "SMESHDriver.h"
60 #include "Utils_CorbaException.hxx"
61 #include "utilities.h"
63 #include "SALOMEDS_Tool.hxx"
64 #include "SALOME_NamingService.hxx"
65 #include "SALOME_LifeCycleCORBA.hxx"
66 #include "Utils_SINGLETON.hxx"
69 //#include <TopAbs_ShapeEnum.hxx>
71 #include "GEOM_Client.hxx"
75 #define NUM_TMP_FILES 4
78 long Tag_HypothesisRoot = 1;
79 long Tag_AlgorithmsRoot = 2;
81 long Tag_RefOnShape = 1;
82 long Tag_RefOnAppliedHypothesis = 2;
83 long Tag_RefOnAppliedAlgorithms = 3;
85 long Tag_SubMeshOnVertex = 4;
86 long Tag_SubMeshOnEdge = 5;
87 long Tag_SubMeshOnFace = 6;
88 long Tag_SubMeshOnSolid = 7;
89 long Tag_SubMeshOnCompound = 8;
92 //=============================================================================
94 * default constructor: not for use
96 //=============================================================================
98 SMESH_Gen_i::SMESH_Gen_i()
100 MESSAGE("SMESH_Gen_i default constructor");
104 //=============================================================================
106 * Standard constructor, used with Container.
108 //=============================================================================
110 SMESH_Gen_i::SMESH_Gen_i(CORBA::ORB_ptr orb,
111 PortableServer::POA_ptr poa,
112 PortableServer::ObjectId * contId,
113 const char *instanceName,
114 const char *interfaceName) :
115 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
117 MESSAGE("activate object");
119 _id = _poa->activate_object(_thisObj);
122 _localId = 0; // number of created objects & local id
126 //=============================================================================
128 * Standard destructor
130 //=============================================================================
132 SMESH_Gen_i::~SMESH_Gen_i()
134 MESSAGE("~SMESH_Gen_i");
138 //=============================================================================
142 //=============================================================================
144 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis(const char* anHyp,
146 throw (SALOME::SALOME_Exception)
148 MESSAGE("CreateHypothesis");
150 // create a new hypothesis object servant
152 SMESH_Hypothesis_i* myHypothesis_i = 0;
155 myHypothesis_i = _hypothesisFactory_i.Create(anHyp,
159 catch (SALOME_Exception& S_ex)
161 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
164 // activate the CORBA servant of hypothesis
166 SMESH::SMESH_Hypothesis_var hypothesis_i
167 = SMESH::SMESH_Hypothesis::_narrow(myHypothesis_i->_this());
168 return SMESH::SMESH_Hypothesis::_duplicate(hypothesis_i);
171 //=============================================================================
175 //=============================================================================
177 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Init(GEOM::GEOM_Gen_ptr geomEngine,
179 GEOM::GEOM_Shape_ptr aShape)
180 throw (SALOME::SALOME_Exception)
183 // _narrow() duplicates the reference and checks the type
184 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
185 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
187 if (CORBA::is_nil(geom))
188 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", \
190 if (CORBA::is_nil(myShape))
191 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
194 // Get or create the GEOM_Client instance
196 SMESH_Mesh_i* meshServant = 0;
199 if (! _ShapeReader) _ShapeReader = new GEOM_Client();
200 ASSERT(_ShapeReader);
202 // explore main Shape, get local TopoDS_Shapes of all subShapes
203 // SMESH_topo* myTopo = ExploreMainShape(geom, studyId, myShape);
205 // Get studyContext_i, create it if it does'nt exist
207 if (_mapStudyContext_i.find(studyId) == _mapStudyContext_i.end())
209 _mapStudyContext_i[studyId] = new StudyContext_iStruct;
211 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
213 // create a new mesh object servant, store it in a map in study context
215 meshServant = new SMESH_Mesh_i(this,
219 myStudyContext->mapMesh_i[_localId] = meshServant;
222 // create a new mesh object
224 TopoDS_Shape myLocShape = _ShapeReader->GetShape(geom,myShape);
225 meshServant->SetImpl(_impl.Init(studyId, myLocShape));
227 catch (SALOME_Exception& S_ex)
229 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
232 // activate the CORBA servant of Mesh
234 SMESH::SMESH_Mesh_var mesh
235 = SMESH::SMESH_Mesh::_narrow(meshServant->_this());
237 meshServant->SetIor(mesh);
239 return SMESH::SMESH_Mesh::_duplicate(mesh);
243 //=============================================================================
247 //=============================================================================
249 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute(SMESH::SMESH_Mesh_ptr aMesh,
250 GEOM::GEOM_Shape_ptr aShape)
251 throw (SALOME::SALOME_Exception)
253 MESSAGE("SMESH_Gen_i::IsReadyToCompute");
257 //=============================================================================
261 //=============================================================================
264 SMESH_Gen_i::GetSubShapesId(GEOM::GEOM_Gen_ptr geomEngine,
266 GEOM::GEOM_Shape_ptr mainShape,
267 const SMESH::shape_array& listOfSubShape)
268 throw (SALOME::SALOME_Exception)
270 MESSAGE("SMESH_Gen_i::GetSubShapesId");
271 SMESH::long_array_var shapesId = new SMESH::long_array;
274 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
275 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(mainShape);
277 if (CORBA::is_nil(geom))
278 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", \
280 if (CORBA::is_nil(myShape))
281 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
286 if (! _ShapeReader) _ShapeReader = new GEOM_Client();
287 ASSERT(_ShapeReader);
288 TopoDS_Shape myMainShape = _ShapeReader->GetShape(geom,myShape);
289 TopTools_IndexedMapOfShape myIndexToShape;
290 TopExp::MapShapes(myMainShape,myIndexToShape);
292 for (int i=0; i<listOfSubShape.length(); i++)
294 GEOM::GEOM_Shape_var aShape
295 = GEOM::GEOM_Shape::_narrow(listOfSubShape[i]);
296 if (CORBA::is_nil(aShape))
297 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
299 TopoDS_Shape locShape = _ShapeReader->GetShape(geom,aShape);
300 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
302 const TopoDS_Face& F = TopoDS::Face(exp.Current());
303 setId.insert(myIndexToShape.FindIndex(F));
304 SCRUTE(myIndexToShape.FindIndex(F));
306 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
308 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
309 setId.insert(myIndexToShape.FindIndex(E));
310 SCRUTE(myIndexToShape.FindIndex(E));
312 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
314 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
315 setId.insert(myIndexToShape.FindIndex(V));
316 SCRUTE(myIndexToShape.FindIndex(V));
319 shapesId->length(setId.size());
320 set<int>::iterator iind;
322 for (iind = setId.begin(); iind != setId.end(); iind++)
325 shapesId[i] = (*iind);
330 catch (SALOME_Exception& S_ex)
332 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
335 return shapesId._retn();
338 //=============================================================================
342 //=============================================================================
344 CORBA::Boolean SMESH_Gen_i::Compute(SMESH::SMESH_Mesh_ptr aMesh,
345 GEOM::GEOM_Shape_ptr aShape)
346 throw (SALOME::SALOME_Exception)
348 MESSAGE("SMESH_Gen_i::Compute");
349 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
350 if (CORBA::is_nil(myShape))
351 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
354 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(aMesh);
355 if (CORBA::is_nil(myMesh))
356 THROW_SALOME_CORBA_EXCEPTION("bad Mesh reference", \
363 // get study context from studyId given by CORBA mesh object
365 int studyId = myMesh->GetStudyId();
366 ASSERT(_mapStudyContext_i.find(studyId) != _mapStudyContext_i.end());
367 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
369 // get local Mesh_i object with Id and study context
371 int meshId = myMesh->GetId();
372 ASSERT(myStudyContext->mapMesh_i.find(meshId) != myStudyContext->mapMesh_i.end());
373 SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
376 // get local TopoDS_Shape
378 GEOM::GEOM_Gen_var geom = meshServant->GetGeomEngine();
379 TopoDS_Shape myLocShape = _ShapeReader->GetShape(geom,myShape);
381 // implementation compute
383 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
384 ret = _impl.Compute(myLocMesh, myLocShape);
386 catch (SALOME_Exception& S_ex)
388 MESSAGE("catch exception "<< S_ex.what());
390 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
397 //=============================================================================
401 //=============================================================================
403 SALOMEDS::TMPFile* SMESH_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
407 MESSAGE("SMESH_Gen_i::SAVE");
408 SALOMEDS::Study_var Study = theComponent->GetStudy();
411 // Declare a byte stream
412 SALOMEDS::TMPFile_var aStreamFile;
414 // Obtain a temporary dir
415 TCollection_AsciiString tmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
417 // Create a sequence of files processed
418 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
419 aFileSeq->length(NUM_TMP_FILES);
421 TCollection_AsciiString aStudyName("");
423 // Set names of temporary files
424 TCollection_AsciiString filename = aStudyName + TCollection_AsciiString("_SMESH.hdf");
425 TCollection_AsciiString hypofile = aStudyName + TCollection_AsciiString("_SMESH_Hypo.txt");
426 TCollection_AsciiString algofile = aStudyName + TCollection_AsciiString("_SMESH_Algo.txt");
427 TCollection_AsciiString meshfile = aStudyName + TCollection_AsciiString("_SMESH_Mesh.med");
428 aFileSeq[0] = CORBA::string_dup(filename.ToCString());
429 aFileSeq[1] = CORBA::string_dup(hypofile.ToCString());
430 aFileSeq[2] = CORBA::string_dup(algofile.ToCString());
431 aFileSeq[3] = CORBA::string_dup(meshfile.ToCString());
432 filename = tmpDir + filename;
433 hypofile = tmpDir + hypofile;
434 algofile = tmpDir + algofile;
435 meshfile = tmpDir + meshfile;
438 map <int,HDFgroup*> hdf_group, hdf_subgroup;
439 map <int,HDFdataset*> hdf_dataset;
442 SALOMEDS::ChildIterator_var itBig,it,itSM;
443 SALOMEDS::SObject_var mySObject,myBranch,mySObjectChild;
445 int longueur,cmpt_ds = 0,cmpt_it;
446 char *name_group,name_dataset[30],name_meshgroup[30];
448 int cmpt_sm = 0, myTag;
450 //************* HDF file creation
451 hdf_file = new HDFfile(filename.ToCString());
452 hdf_file->CreateOnDisk();
453 //****************************
455 itBig = Study->NewChildIterator(theComponent);
456 for (; itBig->More();itBig->Next()) {
457 SALOMEDS::SObject_var gotBranch = itBig->Value();
459 //************branch 1 : hypothesis
460 if (gotBranch->Tag()==Tag_HypothesisRoot) { //hypothesis = tag 1
462 double length,maxElementsArea,maxElementsVolume;
463 int numberOfSegments;
465 destFile = fopen( hypofile.ToCString() ,"w");
466 it = Study->NewChildIterator(gotBranch);
467 for (; it->More();it->Next()) {
468 mySObject = it->Value();
469 SALOMEDS::GenericAttribute_var anAttr;
470 SALOMEDS::AttributeIOR_var anIOR;
471 if ( mySObject->FindAttribute(anAttr, "AttributeIOR")) {
472 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
474 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
475 fprintf(destFile,"%s\n",myHyp->GetName());
477 if (strcmp(myHyp->GetName(),"LocalLength")==0) {
478 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( myHyp );
479 length = LL->GetLength();
480 fprintf(destFile,"%f\n",length);
482 else if (strcmp(myHyp->GetName(),"NumberOfSegments")==0) {
483 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( myHyp );
484 numberOfSegments = NOS->GetNumberOfSegments();
485 fprintf(destFile,"%d\n",numberOfSegments);
487 else if (strcmp(myHyp->GetName(),"MaxElementArea")==0) {
488 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( myHyp );
489 maxElementsArea = MEA->GetMaxElementArea();
490 fprintf(destFile,"%f\n",maxElementsArea);
492 else if (strcmp(myHyp->GetName(),"MaxElementVolume")==0) {
493 SMESH::SMESH_MaxElementVolume_var MEV = SMESH::SMESH_MaxElementVolume::_narrow( myHyp );
494 maxElementsVolume = MEV->GetMaxElementVolume();
495 fprintf(destFile,"%f\n",maxElementsVolume);
501 //writes the file name in the hdf file
502 longueur = hypofile.Length() +1;
503 name_group="Hypothesis";
504 //SCRUTE(name_group);
507 hdf_group[1] = new HDFgroup(name_group,hdf_file);
508 hdf_group[1]->CreateOnDisk();
510 hdf_dataset[cmpt_ds]=new HDFdataset(name_group,hdf_group[1],HDF_STRING,size,1);
511 hdf_dataset[cmpt_ds]->CreateOnDisk();
512 hdf_dataset[cmpt_ds]->WriteOnDisk(hypofile.ToCString());
513 hdf_dataset[cmpt_ds]->CloseOnDisk();
516 hdf_group[1]->CloseOnDisk();
517 MESSAGE("End of Hypothesis Save");
520 //************branch 2 : algorithms
521 else if (gotBranch->Tag()==Tag_AlgorithmsRoot) {//algos = tag 2
523 destFile = fopen( algofile.ToCString() ,"w");
524 it = Study->NewChildIterator(gotBranch);
525 for (; it->More();it->Next()) {
526 mySObject = it->Value();
527 SALOMEDS::GenericAttribute_var anAttr;
528 SALOMEDS::AttributeIOR_var anIOR;
529 if (mySObject->FindAttribute(anAttr, "AttributeIOR")) {
530 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
531 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(anIOR->Value()));
532 fprintf(destFile,"%s\n",myAlgo->GetName());
538 //writes the file name in the hdf file
539 longueur = algofile.Length() +1;
540 name_group="Algorithms";
541 //SCRUTE(name_group);
544 hdf_group[2] = new HDFgroup(name_group,hdf_file);
545 hdf_group[2]->CreateOnDisk();
547 hdf_dataset[cmpt_ds]=new HDFdataset(name_group,hdf_group[2],HDF_STRING,size,1);
548 hdf_dataset[cmpt_ds]->CreateOnDisk();
549 hdf_dataset[cmpt_ds]->WriteOnDisk(algofile.ToCString());
550 hdf_dataset[cmpt_ds]->CloseOnDisk();
553 hdf_group[2]->CloseOnDisk();
554 MESSAGE("End of Algos Save");
557 //************branch 3 : meshes
558 else if (gotBranch->Tag()>=3) {//meshes = tag > 3
560 SALOMEDS::GenericAttribute_var anAttr;
561 SALOMEDS::AttributeIOR_var anIOR;
562 if (gotBranch->FindAttribute(anAttr, "AttributeIOR")) {
563 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
565 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value())) ;
566 studyId = myMesh->GetStudyId();
569 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
570 int meshId = myMesh->GetId();
571 SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
572 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
573 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
575 SCRUTE(mySMESHDSMesh->NbNodes());
576 if (mySMESHDSMesh->NbNodes()>0)
578 //checks if the mesh is not empty
579 Mesh_Writer * myWriter = SMESHDriver::GetMeshWriter("MED");
580 myWriter->SetFile(meshfile.ToCString());
581 myWriter->SetMesh(mySMESHDSMesh);
582 myWriter->SetMeshId(gotBranch->Tag());
585 else meshfile = "No data";
587 //********** opening of the HDF group
588 sprintf(name_meshgroup,"Mesh %d",gotBranch->Tag());
589 SCRUTE(name_meshgroup);
590 hdf_group[gotBranch->Tag()] = new HDFgroup(name_meshgroup,hdf_file);
591 hdf_group[gotBranch->Tag()]->CreateOnDisk();
594 //********** file where the data are stored
595 longueur = strlen(meshfile.ToCString()) +1;
597 strcpy(name_dataset,"Mesh data");
598 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_group[gotBranch->Tag()],HDF_STRING,size,1);
599 hdf_dataset[cmpt_ds]->CreateOnDisk();
600 hdf_dataset[cmpt_ds]->WriteOnDisk(meshfile.ToCString());
601 hdf_dataset[cmpt_ds]->CloseOnDisk();
605 //********** ref on shape
606 Standard_CString myRefOnObject="" ;
607 SALOMEDS::SObject_var myRef,myShape;
608 _found = gotBranch->FindSubObject(Tag_RefOnShape,myRef);
610 ok = myRef->ReferencedObject(myShape);
611 myRefOnObject = myShape->GetID();
612 SCRUTE(myRefOnObject);
614 longueur = strlen(myRefOnObject) +1;
617 strcpy(name_dataset,"Ref on shape");
618 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_group[gotBranch->Tag()],HDF_STRING,size,1);
619 hdf_dataset[cmpt_ds]->CreateOnDisk();
620 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
621 hdf_dataset[cmpt_ds]->CloseOnDisk();
628 //********** ref on applied hypothesis
629 _found = gotBranch->FindSubObject(Tag_RefOnAppliedHypothesis,myBranch);
632 strcpy(name_meshgroup,"Applied Hypothesis");
633 hdf_subgroup[Tag_RefOnAppliedHypothesis] = new HDFgroup(name_meshgroup,hdf_group[gotBranch->Tag()]);
634 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CreateOnDisk();
636 it = Study->NewChildIterator(myBranch);
638 for (; it->More();it->Next()) {
639 mySObject = it->Value();
640 ok = mySObject->ReferencedObject(myRef);
641 myRefOnObject = myRef->GetID();
643 longueur = strlen(myRefOnObject) +1;
646 sprintf(name_dataset,"Hyp %d",cmpt_it);
647 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedHypothesis],HDF_STRING,size,1);
648 hdf_dataset[cmpt_ds]->CreateOnDisk();
649 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
650 hdf_dataset[cmpt_ds]->CloseOnDisk();
655 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CloseOnDisk();
659 //********** ref on applied algorithms
660 _found = gotBranch->FindSubObject(Tag_RefOnAppliedAlgorithms,myBranch);
663 strcpy(name_meshgroup,"Applied Algorithms");
664 hdf_subgroup[Tag_RefOnAppliedAlgorithms] = new HDFgroup(name_meshgroup,hdf_group[gotBranch->Tag()]);
665 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CreateOnDisk();
667 it = Study->NewChildIterator(myBranch);
669 for (; it->More();it->Next()) {
670 mySObject = it->Value();
671 ok = mySObject->ReferencedObject(myRef);
672 myRefOnObject = myRef->GetID();
674 longueur = strlen(myRefOnObject) +1;
677 sprintf(name_dataset,"Algo %d",cmpt_it);
678 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedAlgorithms],HDF_STRING,size,1);
679 hdf_dataset[cmpt_ds]->CreateOnDisk();
680 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
681 hdf_dataset[cmpt_ds]->CloseOnDisk();
686 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CloseOnDisk();
688 MESSAGE("end of algo applied");
691 //********** submeshes on subshapes
693 for (int i=Tag_SubMeshOnVertex;i<=Tag_SubMeshOnCompound;i++) {
694 _found = gotBranch->FindSubObject(i,myBranch);
696 if (i==Tag_SubMeshOnVertex)
697 strcpy(name_meshgroup,"SubMeshes On Vertex");
698 else if (i==Tag_SubMeshOnEdge)
699 strcpy(name_meshgroup,"SubMeshes On Edge");
700 else if (i==Tag_SubMeshOnFace)
701 strcpy(name_meshgroup,"SubMeshes On Face");
702 else if (i==Tag_SubMeshOnSolid)
703 strcpy(name_meshgroup,"SubMeshes On Solid");
704 else if (i==Tag_SubMeshOnCompound)
705 strcpy(name_meshgroup,"SubMeshes On Compound");
708 myLevel1Tag = 10+cmpt_sm;
709 hdf_subgroup[myLevel1Tag] = new HDFgroup(name_meshgroup,hdf_group[gotBranch->Tag()]);
710 hdf_subgroup[myLevel1Tag]->CreateOnDisk();
712 itSM = Study->NewChildIterator(myBranch);
713 for (; itSM->More();itSM->Next()) {//Loop on all submeshes
714 mySObject = itSM->Value();
717 mySObject->FindAttribute(anAttr, "AttributeIOR");
718 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
719 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value())) ;
721 //sprintf(name_meshgroup,"SubMesh %d",myTag);
722 sprintf(name_meshgroup,"SubMesh %d",mySubMesh->GetId());
723 SCRUTE(name_meshgroup);
725 hdf_subgroup[myTag] = new HDFgroup(name_meshgroup,hdf_subgroup[myLevel1Tag]);
726 hdf_subgroup[myTag]->CreateOnDisk();
728 //********** ref on shape
729 Standard_CString myRefOnObject="" ;
730 SALOMEDS::SObject_var myRef,myShape;
732 _found2 = mySObject->FindSubObject(Tag_RefOnShape,myRef);
734 ok = myRef->ReferencedObject(myShape);
735 myRefOnObject = myShape->GetID();
736 SCRUTE(myRefOnObject);
738 longueur = strlen(myRefOnObject) +1;
741 strcpy(name_dataset,"Ref on shape");
742 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[myTag],HDF_STRING,size,1);
743 hdf_dataset[cmpt_ds]->CreateOnDisk();
744 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
745 hdf_dataset[cmpt_ds]->CloseOnDisk();
751 //********** ref on applied hypothesis
752 _found2 = mySObject->FindSubObject(Tag_RefOnAppliedHypothesis,myBranch);
755 strcpy(name_meshgroup,"Applied Hypothesis");
757 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
758 hdf_subgroup[10+cmpt_sm]->CreateOnDisk();
760 it = Study->NewChildIterator(myBranch);
762 for (; it->More();it->Next()) {
763 mySObjectChild = it->Value();
764 ok = mySObjectChild->ReferencedObject(myRef);
765 myRefOnObject = myRef->GetID();
767 longueur = strlen(myRefOnObject) +1;
770 sprintf(name_dataset,"Hyp %d",cmpt_it);
772 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm],HDF_STRING,size,1);
773 hdf_dataset[cmpt_ds]->CreateOnDisk();
774 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
775 hdf_dataset[cmpt_ds]->CloseOnDisk();
780 hdf_subgroup[10+cmpt_sm]->CloseOnDisk();
784 //********** ref on applied algorithms
785 _found2 = mySObject->FindSubObject(Tag_RefOnAppliedAlgorithms,myBranch);
789 strcpy(name_meshgroup,"Applied Algorithms");
791 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
792 hdf_subgroup[10+cmpt_sm]->CreateOnDisk();
794 it = Study->NewChildIterator(myBranch);
796 for (; it->More();it->Next()) {
797 mySObjectChild = it->Value();
798 ok = mySObjectChild->ReferencedObject(myRef);
799 myRefOnObject = myRef->GetID();
801 longueur = strlen(myRefOnObject) +1;
804 sprintf(name_dataset,"Algo %d",cmpt_it);
805 hdf_dataset[cmpt_ds]=new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm],HDF_STRING,size,1);
806 hdf_dataset[cmpt_ds]->CreateOnDisk();
807 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
808 hdf_dataset[cmpt_ds]->CloseOnDisk();
813 hdf_subgroup[10+cmpt_sm]->CloseOnDisk();
815 //MESSAGE("end of algo applied");
818 hdf_subgroup[myTag]->CloseOnDisk();
821 hdf_subgroup[myLevel1Tag]->CloseOnDisk();
827 //********** closing of the HDF group
828 hdf_group[gotBranch->Tag()]->CloseOnDisk();
829 MESSAGE("End of Mesh Save");
833 MESSAGE("End of Meshes Save");
836 hdf_file->CloseOnDisk();
840 // Convert temporary files to stream
841 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.ToCString(), aFileSeq.in(), isMultiFile);
843 // Remove temporary files and directory
844 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(), true);
846 MESSAGE("End SMESH_Gen_i::Save");
848 return aStreamFile._retn();
851 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
854 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
855 return aStreamFile._retn();
858 //=============================================================================
862 //=============================================================================
864 bool SMESH_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
865 const SALOMEDS::TMPFile& theStream,
869 MESSAGE("SMESH_Gen_i::Load\n");
871 // Get temporary files location
872 TCollection_AsciiString tmpDir = isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
874 // Convert the stream into sequence of files to process
875 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
879 TCollection_AsciiString aStudyName("");
880 if (isMultiFile) aStudyName = (SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
882 // Set names of temporary files
883 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString("_SMESH.hdf");
884 TCollection_AsciiString hypofile = tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Hypo.txt");
885 TCollection_AsciiString algofile = tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Algo.txt");
886 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Mesh.med");
888 SALOMEDS::Study_var Study = theComponent->GetStudy();
889 int studyId = Study->StudyId();
892 SALOMEDS::GenericAttribute_var anAttr;
893 SALOMEDS::AttributeName_var aName;
894 SALOMEDS::AttributeIOR_var anIOR;
896 SALOMEDS::SComponent_var fathergeom = Study->FindComponent("GEOM");
897 SALOMEDS::SComponent_var myGeomSComp = SALOMEDS::SComponent::_narrow( fathergeom );
900 //to get the geom engine !!!
901 //useful to define our new mesh
902 SALOME_NamingService* _NS = SINGLETON_<SALOME_NamingService>::Instance() ;
903 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
904 _NS->init_orb( _orb ) ;
905 SALOME_LifeCycleCORBA* myEnginesLifeCycle = new SALOME_LifeCycleCORBA(_NS);
906 Engines::Component_var geomEngine =
907 myEnginesLifeCycle->FindOrLoad_Component("FactoryServer","GEOM");
908 GEOM::GEOM_Gen_var myGeomEngine = GEOM::GEOM_Gen::_narrow(geomEngine);
913 char objectId[10],name_dataset[10];
914 int nb_datasets,size,cmpt_ds=0;
917 char name[HDF_NAME_MAX_LEN+1];
918 char sgname[HDF_NAME_MAX_LEN+1];
919 char msgname[HDF_NAME_MAX_LEN+1];
920 char name_of_group[HDF_NAME_MAX_LEN+1];
921 char *name_meshgroup;
922 map <int,HDFgroup*> hdf_group, hdf_subgroup;
923 map <int,HDFdataset*> hdf_dataset;
926 //************* HDF file opening
927 HDFfile * hdf_file = new HDFfile(filename.ToCString());
929 hdf_file->OpenOnDisk(HDF_RDONLY);
931 catch (HDFexception) {
932 MESSAGE("Load(): " << filename << " not found!");
936 //****************************
938 int nb_group = hdf_file->nInternalObjects();
940 for (int i=0;i<nb_group;i++)
942 hdf_file->InternalObjectIndentify(i,name);
946 // Loading of the Hypothesis Branch
948 if (strcmp(name,"Hypothesis")==0) {
950 double length,maxElementsArea,maxElementsVolume;
951 int numberOfSegments;
953 hdf_group[Tag_HypothesisRoot] = new HDFgroup(name,hdf_file);
954 hdf_group[Tag_HypothesisRoot]->OpenOnDisk();
956 hdf_group[Tag_HypothesisRoot]->InternalObjectIndentify(0,name_of_group);
957 hdf_dataset[cmpt_ds]=new HDFdataset(name_of_group,hdf_group[Tag_HypothesisRoot]);
958 hdf_dataset[cmpt_ds]->OpenOnDisk();
959 size=hdf_dataset[cmpt_ds]->GetSize();
961 char * name_of_file =new char[size];
962 hdf_dataset[cmpt_ds]->ReadFromDisk(name_of_file);
963 SCRUTE(name_of_file);
964 hdf_dataset[cmpt_ds]->CloseOnDisk();
965 hdf_group[Tag_HypothesisRoot]->CloseOnDisk();
967 delete[] name_of_file;
970 aLine = new char[100];
971 loadedFile = fopen( hypofile.ToCString() ,"r");
972 while (!feof(loadedFile)) {
973 fscanf(loadedFile,"%s",aLine);
975 if (strcmp(aLine,"LocalLength")==0) {
976 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
977 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( myHyp );
978 fscanf(loadedFile,"%s",aLine);
979 length = atof(aLine);
980 LL->SetLength(length);
981 string iorString = _orb->object_to_string(LL);
982 sprintf(objectId,"%d",LL->GetId());
983 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
985 else if (strcmp(aLine,"NumberOfSegments")==0) {
986 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
987 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( myHyp );
988 fscanf(loadedFile,"%s",aLine);
989 numberOfSegments = atoi(aLine);
990 NOS->SetNumberOfSegments(numberOfSegments);
991 string iorString = _orb->object_to_string(NOS);
992 sprintf(objectId,"%d",NOS->GetId());
993 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
995 else if (strcmp(aLine,"MaxElementArea")==0) {
996 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
997 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( myHyp );
998 fscanf(loadedFile,"%s",aLine);
999 maxElementsArea = atof(aLine);
1000 MEA->SetMaxElementArea(maxElementsArea);
1001 string iorString = _orb->object_to_string(MEA);
1002 sprintf(objectId,"%d",MEA->GetId());
1003 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
1005 else if (strcmp(aLine,"MaxElementVolume")==0) {
1006 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
1007 SMESH::SMESH_MaxElementVolume_var MEV = SMESH::SMESH_MaxElementVolume::_narrow( myHyp );
1008 fscanf(loadedFile,"%s",aLine);
1009 maxElementsVolume = atof(aLine);
1010 MEV->SetMaxElementVolume(maxElementsVolume);
1011 string iorString = _orb->object_to_string(MEV);
1012 sprintf(objectId,"%d",MEV->GetId());
1013 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
1021 MESSAGE("End of Hypos Load");
1025 // Loading of the Algorithms Branch
1027 else if (strcmp(name,"Algorithms")==0) {
1029 hdf_group[Tag_AlgorithmsRoot] = new HDFgroup(name,hdf_file);
1030 hdf_group[Tag_AlgorithmsRoot]->OpenOnDisk();
1032 hdf_group[Tag_AlgorithmsRoot]->InternalObjectIndentify(0,name_of_group);
1033 hdf_dataset[cmpt_ds] = new HDFdataset(name_of_group,hdf_group[Tag_AlgorithmsRoot]);
1034 hdf_dataset[cmpt_ds]->OpenOnDisk();
1035 size=hdf_dataset[cmpt_ds]->GetSize();
1037 char * name_of_file =new char[size];
1038 hdf_dataset[cmpt_ds]->ReadFromDisk(name_of_file);
1039 hdf_dataset[cmpt_ds]->CloseOnDisk();
1040 hdf_group[Tag_AlgorithmsRoot]->CloseOnDisk();
1042 delete[] name_of_file;
1045 aLine = new char[100];
1046 loadedFile = fopen( algofile.ToCString(),"r");
1047 while (!feof(loadedFile)) {
1048 fscanf(loadedFile,"%s\n",aLine);
1050 if (strcmp(aLine,"")!=0) {
1051 SMESH::SMESH_Hypothesis_var myHyp = this->CreateHypothesis(aLine,studyId);
1052 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1053 string iorString = _orb->object_to_string(myAlgo);
1054 sprintf(objectId,"%d",myAlgo->GetId());
1055 _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
1061 MESSAGE("End of Algos Load");
1066 // Loading of the Mesh Branch
1068 else if (string(name).substr(0,4)==string("Mesh")) {
1069 MESSAGE("in mesh load");
1071 Standard_Integer myMeshId = atoi((string(name).substr(5,5)).c_str());
1074 hdf_group[myMeshId] = new HDFgroup(name,hdf_file);
1075 hdf_group[myMeshId]->OpenOnDisk();
1077 int nb_meshsubgroup = hdf_group[myMeshId]->nInternalObjects();
1078 SCRUTE(nb_meshsubgroup);
1080 //********** Loading of the file name where the data are stored
1081 MESSAGE("Mesh data file");
1082 strcpy(name_of_group,"Mesh data");
1083 hdf_dataset[cmpt_ds]=new HDFdataset(name_of_group,hdf_group[myMeshId]);
1084 hdf_dataset[cmpt_ds]->OpenOnDisk();
1085 size=hdf_dataset[cmpt_ds]->GetSize();
1087 char * datafilename =new char[size];
1088 hdf_dataset[cmpt_ds]->ReadFromDisk(datafilename);
1089 hdf_dataset[cmpt_ds]->CloseOnDisk();
1094 //else if (strcmp(msgname,"Ref on shape")==0) {
1096 //********** Loading of the reference on the shape
1097 //********** and mesh initialization
1098 MESSAGE("Ref on shape");
1099 strcpy(name_of_group,"Ref on shape");
1100 hdf_dataset[cmpt_ds] = new HDFdataset(name_of_group,hdf_group[myMeshId]);
1101 hdf_dataset[cmpt_ds]->OpenOnDisk();
1102 size=hdf_dataset[cmpt_ds]->GetSize();
1104 char * refFromFile =new char[size];
1105 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1106 hdf_dataset[cmpt_ds]->CloseOnDisk();
1109 Standard_CString myRefOnShape=""; //look for ref on shape
1111 bool _found = false;
1112 SALOMEDS::SObject_var CSO = Study->FindObjectID(refFromFile);
1113 SMESH::SMESH_Mesh_var myNewMesh;
1114 GEOM::GEOM_Shape_var aShape;
1116 if (!CORBA::is_nil(CSO)) {
1118 CSO->FindAttribute(anAttr, "AttributeIOR");
1119 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1120 char* ShapeIOR = anIOR->Value();
1121 aShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(ShapeIOR));
1123 myNewMesh = this->Init(myGeomEngine,studyId,aShape);
1124 string iorString = _orb->object_to_string(myNewMesh);
1125 sprintf(objectId,"%d",myNewMesh->GetId());
1126 _SMESHCorbaObj[string("Mesh_")+string(objectId)] = iorString;
1129 //********** Loading of mesh data
1130 if (strcmp(datafilename,"No data")!=0)
1133 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
1134 int meshId = myNewMesh->GetId();
1135 SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
1136 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1137 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
1139 Mesh_Reader* myReader = SMESHDriver::GetMeshReader("MED");
1140 myReader->SetMesh(mySMESHDSMesh);
1141 myReader->SetMeshId(myMeshId);
1142 myReader->SetFile(datafilename);
1144 //SCRUTE(mySMESHDSMesh->NbNodes());
1145 //myNewMesh->ExportUNV("/tmp/test.unv");//only to check out
1150 //else if (strcmp(msgname,"Applied Hypothesis")==0) {
1151 for (int ii=0;ii<nb_meshsubgroup;ii++)
1153 hdf_group[myMeshId]->InternalObjectIndentify(ii,msgname);
1154 if (strcmp(msgname,"Mesh data")==0) {
1157 else if (strcmp(msgname,"Ref on shape")==0) {
1160 else if (strcmp(msgname,"Applied Hypothesis")==0) {
1161 //********** Loading of the applied hypothesis
1162 strcpy(name_of_group,"Applied Hypothesis");
1163 hdf_subgroup[Tag_RefOnAppliedHypothesis] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1164 hdf_subgroup[Tag_RefOnAppliedHypothesis]->OpenOnDisk();
1166 nb_datasets = hdf_subgroup[Tag_RefOnAppliedHypothesis]->nInternalObjects();
1167 SCRUTE(nb_datasets);
1169 for (int j=0;j<nb_datasets;j++) {
1170 sprintf(name_dataset,"Hyp %d",j);
1171 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedHypothesis]);
1172 hdf_dataset[cmpt_ds]->OpenOnDisk();
1173 size=hdf_dataset[cmpt_ds]->GetSize();
1175 char * refFromFile =new char[size];
1176 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1177 //SCRUTE(refFromFile);
1178 hdf_dataset[cmpt_ds]->CloseOnDisk();
1181 SALOMEDS::SObject_var HypSO = Study->FindObjectID(refFromFile);
1182 if (!CORBA::is_nil(HypSO)) {
1183 HypSO->FindAttribute(anAttr, "AttributeIOR");
1184 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1185 if (!CORBA::is_nil(anIOR)) {
1186 char* HypIOR = anIOR->Value();
1187 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(HypIOR));
1188 if (!CORBA::is_nil(anHyp)) {
1189 myNewMesh->AddHypothesis(aShape,anHyp);
1190 MESSAGE("Hypothesis added ...");
1197 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CloseOnDisk();
1200 else if (strcmp(msgname,"Applied Algorithms")==0) {
1202 //********** Loading of the applied algorithms
1203 strcpy(name_of_group,"Applied Algorithms");
1204 hdf_subgroup[Tag_RefOnAppliedAlgorithms] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1205 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->OpenOnDisk();
1207 nb_datasets = hdf_subgroup[Tag_RefOnAppliedAlgorithms]->nInternalObjects();
1208 SCRUTE(nb_datasets);
1210 for (int j=0;j<nb_datasets;j++) {
1211 sprintf(name_dataset,"Algo %d",j);
1212 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[Tag_RefOnAppliedAlgorithms]);
1213 hdf_dataset[cmpt_ds]->OpenOnDisk();
1214 size=hdf_dataset[cmpt_ds]->GetSize();
1216 char * refFromFile =new char[size];
1217 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1218 hdf_dataset[cmpt_ds]->CloseOnDisk();
1222 SALOMEDS::SObject_var AlgoSO = Study->FindObjectID(refFromFile);
1223 if (!CORBA::is_nil(AlgoSO)) {
1224 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1225 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1226 if (!CORBA::is_nil(anIOR)) {
1227 char* AlgoIOR = anIOR->Value();
1229 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(AlgoIOR));
1230 SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1231 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1232 if (!CORBA::is_nil(anAlgo)) {
1233 myNewMesh->AddHypothesis(aShape,anAlgo);//essayer avec _SMESHCorbaObj
1234 MESSAGE("Algorithms added ...");
1241 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CloseOnDisk();
1245 else if (string(msgname).substr(0,9)==string("SubMeshes")) {
1248 //********** Loading of the submeshes on subshapes
1249 int myLevel1Tag, myTag;
1252 myLevel1Tag = 10+cmpt_sm;
1253 hdf_subgroup[myLevel1Tag] = new HDFgroup(name_of_group,hdf_group[myMeshId]);
1254 hdf_subgroup[myLevel1Tag] = new HDFgroup(msgname,hdf_group[myMeshId]);
1255 hdf_subgroup[myLevel1Tag]->OpenOnDisk();
1257 int nb_submeshes = hdf_subgroup[myLevel1Tag]->nInternalObjects();
1258 SCRUTE(nb_submeshes);
1260 for (int j=0;j<nb_submeshes;j++) {
1263 hdf_subgroup[myLevel1Tag]->InternalObjectIndentify(j,name_meshgroup);
1264 SCRUTE(name_meshgroup);
1266 hdf_subgroup[myTag] = new HDFgroup(name_meshgroup,hdf_subgroup[myLevel1Tag]);
1267 hdf_subgroup[myTag]->OpenOnDisk();
1268 int subMeshId = atoi((string(name_meshgroup).substr(8,18)).c_str());
1270 MESSAGE("Ref on shape");
1271 //********** ref on shape
1272 sprintf(name_dataset,"Ref on shape");
1273 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[myTag]);
1274 hdf_dataset[cmpt_ds]->OpenOnDisk();
1275 size=hdf_dataset[cmpt_ds]->GetSize();
1277 char * refFromFile =new char[size];
1278 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1279 hdf_dataset[cmpt_ds]->CloseOnDisk();
1282 bool _found3 = false;
1283 SALOMEDS::SObject_var GSO = Study->FindObjectID(refFromFile);
1284 SMESH::SMESH_subMesh_var aSubMesh;
1285 GEOM::GEOM_Shape_var aSubShape;
1287 if (!CORBA::is_nil(GSO)) {
1288 GSO->FindAttribute(anAttr, "AttributeIOR");
1289 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1290 char* SubShapeIOR = anIOR->Value();
1291 aSubShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(SubShapeIOR));
1293 if (!CORBA::is_nil(aSubShape)) {
1294 aSubMesh = myNewMesh->GetElementsOnShape(aSubShape);
1295 string iorString = _orb->object_to_string(aSubMesh);
1296 sprintf(objectId,"%d",subMeshId);
1297 _SMESHCorbaObj[string("SubMesh_")+string(objectId)] = iorString;
1299 //SCRUTE(aSubMesh->GetNumberOfNodes());
1301 //SCRUTE(aSubMesh->GetNumberOfElements());
1305 int nb_subgroup = hdf_subgroup[myTag]->nInternalObjects();
1306 SCRUTE(nb_subgroup);
1307 for (int k=0;k<nb_subgroup;k++)
1309 hdf_subgroup[myTag]->InternalObjectIndentify(k,sgname);
1310 if (strcmp(sgname,"Ref on shape")==0) {
1313 else if (strcmp(sgname,"Applied Hypothesis")==0) {
1314 //********** ref on applied hypothesis
1315 MESSAGE("Applied Hypothesis");
1316 strcpy(name_meshgroup,"Applied Hypothesis");
1318 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
1319 hdf_subgroup[10+cmpt_sm]->OpenOnDisk();
1320 nb_datasets = hdf_subgroup[10+cmpt_sm]->nInternalObjects();
1321 SCRUTE(nb_datasets);
1323 for (int l=0;l<nb_datasets;l++) {
1324 sprintf(name_dataset,"Hyp %d",l);
1325 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm]);
1326 hdf_dataset[cmpt_ds]->OpenOnDisk();
1327 size=hdf_dataset[cmpt_ds]->GetSize();
1329 char * refFromFile =new char[size];
1330 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1331 hdf_dataset[cmpt_ds]->CloseOnDisk();
1335 SALOMEDS::SObject_var HypSO = Study->FindObjectID(refFromFile);
1336 if (!CORBA::is_nil(HypSO)) {
1337 HypSO->FindAttribute(anAttr, "AttributeIOR");
1338 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1339 if (!CORBA::is_nil(anIOR)) {
1340 char* HypIOR = anIOR->Value();
1341 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(HypIOR));
1342 if (!CORBA::is_nil(anHyp)) {
1343 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1344 aMesh->AddHypothesis(aSubShape,anHyp);//essayer avec _SMESHCorbaObj
1345 MESSAGE("Hypothesis added ...");
1352 else if (strcmp(sgname,"Applied Algorithms")==0) {
1353 //********** ref on applied algorithms
1354 MESSAGE("Applied Algorithms");
1355 strcpy(name_meshgroup,"Applied Algorithms");
1357 hdf_subgroup[10+cmpt_sm] = new HDFgroup(name_meshgroup,hdf_subgroup[myTag]);
1358 hdf_subgroup[10+cmpt_sm]->OpenOnDisk();
1359 nb_datasets = hdf_subgroup[10+cmpt_sm]->nInternalObjects();
1360 SCRUTE(nb_datasets);
1362 for (int l=0;l<nb_datasets;l++) {
1363 sprintf(name_dataset,"Algo %d",l);
1364 hdf_dataset[cmpt_ds] = new HDFdataset(name_dataset,hdf_subgroup[10+cmpt_sm]);
1365 hdf_dataset[cmpt_ds]->OpenOnDisk();
1366 size=hdf_dataset[cmpt_ds]->GetSize();
1368 char * refFromFile =new char[size];
1369 hdf_dataset[cmpt_ds]->ReadFromDisk(refFromFile);
1370 hdf_dataset[cmpt_ds]->CloseOnDisk();
1374 SALOMEDS::SObject_var AlgoSO = Study->FindObjectID(refFromFile);
1375 if (!CORBA::is_nil(AlgoSO)) {
1376 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1377 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1378 if (!CORBA::is_nil(anIOR)) {
1379 char* AlgoIOR = anIOR->Value();
1381 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(AlgoIOR));
1382 SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(myHyp);
1383 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1384 if (!CORBA::is_nil(anAlgo)) {
1385 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1386 aMesh->AddHypothesis(aSubShape,anAlgo);//essayer avec _SMESHCorbaObj
1387 MESSAGE("Algorithms added ...");
1396 hdf_subgroup[myTag]->CloseOnDisk();
1398 hdf_subgroup[myLevel1Tag]->CloseOnDisk();
1401 hdf_group[myMeshId]->CloseOnDisk();
1403 MESSAGE("End of Meshes Load");
1407 MESSAGE("End of SMESH_Gen::Load");
1409 hdf_file->CloseOnDisk();
1413 // Remove temporary files created from the stream
1414 if (isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(), true);
1419 bool SMESH_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
1420 const SALOMEDS::TMPFile& theStream,
1423 return Load(theComponent, theStream, theURL, isMultiFile);
1426 //=============================================================================
1430 //=============================================================================
1432 void SMESH_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
1435 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
1436 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
1437 for (; itBig->More();itBig->Next()) {
1438 SALOMEDS::SObject_var gotBranch = itBig->Value();
1440 // branch 1 : hypothesis
1441 if (gotBranch->Tag()==Tag_HypothesisRoot || gotBranch->Tag()==Tag_AlgorithmsRoot) {
1442 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(gotBranch);
1443 for (; it->More();it->Next()) {
1444 SALOMEDS::SObject_var mySObject = it->Value();
1445 SALOMEDS::GenericAttribute_var anAttr;
1446 SALOMEDS::AttributeIOR_var anIOR;
1447 if ( mySObject->FindAttribute(anAttr, "AttributeIOR")) {
1448 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1449 SMESH::SMESH_Hypothesis_var myHyp =
1450 SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
1452 sprintf(objectId,"%d",myHyp->GetId());
1453 // cout<<"********** delete Hyp "<<objectId<<endl;
1454 _SMESHCorbaObj.erase(string("Hypo_")+string(objectId));
1455 myHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
1459 // branch 2 : algorithms
1460 else if (gotBranch->Tag()>=3) {
1461 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(gotBranch);
1462 for (; it->More();it->Next()) {
1463 SALOMEDS::SObject_var mySObject = it->Value();
1464 SALOMEDS::GenericAttribute_var anAttr;
1465 SALOMEDS::AttributeIOR_var anIOR;
1466 if ( mySObject->FindAttribute(anAttr, "AttributeIOR")) {
1467 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1468 SMESH::SMESH_Mesh_var myMesh =
1469 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
1470 if (!myMesh->_is_nil()) {
1472 sprintf(objectId,"%d",myMesh->GetId());
1473 // cout<<"********** delete Mesh "<<objectId<<endl;
1474 _SMESHCorbaObj.erase(string("Mesh_")+string(objectId));
1475 CORBA::release(myMesh);
1478 SMESH::SMESH_subMesh_var mySubMesh =
1479 SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value()));
1480 if (!mySubMesh->_is_nil()) {
1482 sprintf(objectId,"%d",mySubMesh->GetId());
1483 // cout<<"********** delete SubMesh "<<objectId<<endl;
1484 _SMESHCorbaObj.erase(string("SubMesh_")+string(objectId));
1485 CORBA::release(mySubMesh);
1494 //=============================================================================
1498 //=============================================================================
1500 char* SMESH_Gen_i::ComponentDataType()
1502 MESSAGE("SMESH_Gen_i::ComponentDataType");
1503 return strdup("SMESH");
1507 //=============================================================================
1511 //=============================================================================
1513 char* SMESH_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
1514 const char* IORString,
1515 CORBA::Boolean isMultiFile,
1516 CORBA::Boolean isASCII)
1518 MESSAGE("SMESH_Gen_i::IORToLocalPersistentID");
1522 SMESH::SMESH_Algo_var myAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(IORString));
1523 if (! CORBA::is_nil(myAlgo))
1525 string prefix = "Hypo_";
1526 sprintf(objectId,"%d",myAlgo->GetId());
1527 string lpID = prefix + string(objectId);
1528 return CORBA::string_dup(lpID.c_str());
1531 SMESH::SMESH_Hypothesis_var myHypo = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(IORString));
1532 if (! CORBA::is_nil(myHypo))
1534 string prefix = "Hypo_";
1535 sprintf(objectId,"%d",myHypo->GetId());
1536 string lpID = prefix + string(objectId);
1537 return CORBA::string_dup(lpID.c_str());
1540 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(IORString));
1541 if (! CORBA::is_nil(myMesh))
1543 string prefix = "Mesh_";
1544 sprintf(objectId,"%d",myMesh->GetId());
1545 string lpID = prefix + string(objectId);
1546 return CORBA::string_dup(lpID.c_str());
1549 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(IORString));
1550 if (! CORBA::is_nil(mySubMesh))
1552 string prefix = "SubMesh_";
1553 sprintf(objectId,"%d",mySubMesh->GetId());
1554 string lpID = prefix + string(objectId);
1555 return CORBA::string_dup(lpID.c_str());
1557 else return (strdup("no object"));
1563 //=============================================================================
1567 //=============================================================================
1569 char* SMESH_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
1570 const char* aLocalPersistentID,
1571 CORBA::Boolean isMultiFile,
1572 CORBA::Boolean isASCII)
1574 MESSAGE("SMESH_Gen_i::LocalPersistentIDToIOR");
1575 SCRUTE(aLocalPersistentID);
1576 string clef = string(aLocalPersistentID);
1577 SCRUTE(_SMESHCorbaObj[clef].c_str());
1578 return CORBA::string_dup(_SMESHCorbaObj[clef].c_str());
1581 //=============================================================================
1585 //=============================================================================
1587 SMESH_topo* SMESH_Gen_i::ExploreMainShape(GEOM::GEOM_Gen_ptr geomEngine,
1588 CORBA::Long studyId,
1589 GEOM::GEOM_Shape_ptr aShape)
1591 MESSAGE("SMESH_Mesh_i::ExploreMainShape");
1592 // _narrow() duplicates the reference and check the type
1593 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
1594 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
1596 if (CORBA::is_nil(geom))
1597 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", \
1599 if (CORBA::is_nil(myShape))
1600 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
1603 SCRUTE(myShape->Name());
1604 geom->GetCurrentStudy(studyId);
1606 TopoDS_Shape mainShape = _ShapeReader->GetShape(geom,myShape);
1609 // create an SMESH_topo object for the mainShape
1611 SMESH_topo* myTopo = new SMESH_topo();
1614 // explore local TopoDS_Shape, store reference of local TopoDS subShapes
1616 for (TopExp_Explorer exp(mainShape,TopAbs_COMPOUND); exp.More(); exp.Next())
1618 const TopoDS_Compound& E = TopoDS::Compound(exp.Current());
1619 int i = myTopo->_myShapes[TopAbs_COMPOUND].Add(E);
1622 for (TopExp_Explorer exp(mainShape,TopAbs_COMPSOLID); exp.More(); exp.Next())
1624 const TopoDS_CompSolid& E = TopoDS::CompSolid(exp.Current());
1625 int i = myTopo->_myShapes[TopAbs_COMPSOLID].Add(E);
1628 for (TopExp_Explorer exp(mainShape,TopAbs_SOLID); exp.More(); exp.Next())
1630 const TopoDS_Solid& E = TopoDS::Solid(exp.Current());
1631 int i = myTopo->_myShapes[TopAbs_SOLID].Add(E);
1634 for (TopExp_Explorer exp(mainShape,TopAbs_SHELL); exp.More(); exp.Next())
1636 const TopoDS_Shell& E = TopoDS::Shell(exp.Current());
1637 int i = myTopo->_myShapes[TopAbs_SHELL].Add(E);
1640 for (TopExp_Explorer exp(mainShape,TopAbs_FACE); exp.More(); exp.Next())
1642 const TopoDS_Face& E = TopoDS::Face(exp.Current());
1643 int i = myTopo->_myShapes[TopAbs_FACE].Add(E);
1646 for (TopExp_Explorer exp(mainShape,TopAbs_WIRE); exp.More(); exp.Next())
1648 const TopoDS_Wire& E = TopoDS::Wire(exp.Current());
1649 int i = myTopo->_myShapes[TopAbs_WIRE].Add(E);
1652 for (TopExp_Explorer exp(mainShape,TopAbs_EDGE); exp.More(); exp.Next())
1654 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1655 int i = myTopo->_myShapes[TopAbs_EDGE].Add(E);
1658 for (TopExp_Explorer exp(mainShape,TopAbs_VERTEX); exp.More(); exp.Next())
1660 const TopoDS_Vertex& E = TopoDS::Vertex(exp.Current());
1661 int i = myTopo->_myShapes[TopAbs_VERTEX].Add(E);
1665 // explore subShapes of distant CORBA object,
1666 // associate distant CORBA subShape references
1667 // with local reference to local TopoDS subShape
1669 string filenode = "toposhape.txt";
1670 ofstream fic(filenode.c_str());
1672 for (int shapeType = TopAbs_COMPOUND; shapeType < TopAbs_SHAPE; shapeType++)
1674 fic << "shape type : " << SMESH_shapeTypeNames[shapeType];
1676 GEOM::GEOM_Gen::ListOfGeomShapes_var subShapes
1677 = geom->SubShapeAll(myShape,shapeType);
1678 int nbSubShapes = subShapes->length();
1679 int nbLocal = myTopo->_myShapes[shapeType].Extent();
1680 fic << " - number of elements: " << nbSubShapes << endl;
1681 ASSERT(nbSubShapes == nbLocal);
1683 for (int i=0; i< nbSubShapes; i++)
1685 GEOM::GEOM_Shape_var aSubShape = subShapes[i];
1686 string idShape = SMESH_topo::GetShapeLocalId(aSubShape);
1687 fic << " " << idShape;
1689 TopoDS_Shape aLocShape = _ShapeReader->GetShape(geom,aSubShape);
1690 for (int j=1; j <= nbLocal; j++)
1691 if (aLocShape.IsSame(myTopo->_myShapes[shapeType].FindKey(j)))
1693 MESSAGE(" --- trouve = " << j);
1694 myTopo->_mapIndShapes[shapeType][idShape] = j;
1695 fic << " --- trouve = " << j;
1707 * Import a mesh from a file
1708 * @param fileName file name to be imported
1709 * @param fileType Currently it could be either "DAT", "UNV" or "MED".
1711 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Import(CORBA::Long studyId,
1712 const char* fileName, const char* fileType)
1714 MESSAGE("SMESH_Gen_I::Import");
1715 SMESH_Mesh_i* meshServant;
1718 if (_mapStudyContext_i.find(studyId) == _mapStudyContext_i.end())
1720 _mapStudyContext_i[studyId] = new StudyContext_iStruct;
1722 StudyContext_iStruct* myStudyContext = _mapStudyContext_i[studyId];
1724 // create a new mesh object servant, store it in a map in study context
1725 meshServant = new SMESH_Mesh_i(this, NULL, studyId, _localId);
1726 myStudyContext->mapMesh_i[_localId] = meshServant;
1729 // create a new mesh object
1730 meshServant->SetImpl(_impl.Import(studyId, fileName, fileType));
1732 catch (SALOME_Exception& S_ex)
1734 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1737 // activate the CORBA servant of Mesh
1739 SMESH::SMESH_Mesh_var mesh
1740 = SMESH::SMESH_Mesh::_narrow(meshServant->_this());
1742 meshServant->SetIor(mesh);
1743 return SMESH::SMESH_Mesh::_duplicate(mesh);
1746 //=============================================================================
1748 * C factory, accessible with dlsym, after dlopen
1750 //=============================================================================
1754 PortableServer::ObjectId * SMESHEngine_factory(
1756 PortableServer::POA_ptr poa,
1757 PortableServer::ObjectId * contId,
1758 const char *instanceName,
1759 const char *interfaceName)
1761 MESSAGE("PortableServer::ObjectId * SMESHEngine_factory()");
1762 SCRUTE(interfaceName);
1763 SMESH_Gen_i * mySMESH_Gen
1764 = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
1765 return mySMESH_Gen->getId() ;