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;
91 //=============================================================================
93 * default constructor: not for use
95 //=============================================================================
97 SMESH_Gen_i::SMESH_Gen_i()
99 MESSAGE("SMESH_Gen_i default constructor");
103 //=============================================================================
105 * Standard constructor, used with Container.
107 //=============================================================================
109 SMESH_Gen_i::SMESH_Gen_i(CORBA::ORB_ptr orb,
110 PortableServer::POA_ptr poa,
111 PortableServer::ObjectId * contId,
112 const char *instanceName,
113 const char *interfaceName):Engines_Component_i(orb, poa, contId,
114 instanceName, interfaceName)
116 MESSAGE("activate object");
118 _id = _poa->activate_object(_thisObj);
121 _localId = 0; // number of created objects & local id
125 //=============================================================================
127 * Standard destructor
129 //=============================================================================
131 SMESH_Gen_i::~SMESH_Gen_i()
133 MESSAGE("~SMESH_Gen_i");
137 //=============================================================================
141 //=============================================================================
143 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis(const char *anHyp,
144 CORBA::Long studyId) throw(SALOME::SALOME_Exception)
146 MESSAGE("CreateHypothesis");
148 // create a new hypothesis object servant
150 SMESH_Hypothesis_i *myHypothesis_i = 0;
153 myHypothesis_i = _hypothesisFactory_i.Create(anHyp, studyId, &_impl);
155 catch(SALOME_Exception & S_ex)
157 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
160 // activate the CORBA servant of hypothesis
162 SMESH::SMESH_Hypothesis_var hypothesis_i
163 = SMESH::SMESH_Hypothesis::_narrow(myHypothesis_i->_this());
164 return SMESH::SMESH_Hypothesis::_duplicate(hypothesis_i);
167 //=============================================================================
171 //=============================================================================
173 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Init(GEOM::GEOM_Gen_ptr geomEngine,
175 GEOM::GEOM_Shape_ptr aShape) throw(SALOME::SALOME_Exception)
178 // _narrow() duplicates the reference and checks the type
179 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
180 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
182 if (CORBA::is_nil(geom))
183 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", SALOME::BAD_PARAM);
184 if (CORBA::is_nil(myShape))
185 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", SALOME::BAD_PARAM);
187 // Get or create the GEOM_Client instance
189 SMESH_Mesh_i *meshServant = 0;
193 _ShapeReader = new GEOM_Client();
194 ASSERT(_ShapeReader);
196 // explore main Shape, get local TopoDS_Shapes of all subShapes
197 // SMESH_topo* myTopo = ExploreMainShape(geom, studyId, myShape);
199 // Get studyContext_i, create it if it does'nt exist
201 if (_mapStudyContext_i.find(studyId) == _mapStudyContext_i.end())
203 _mapStudyContext_i[studyId] = new StudyContext_iStruct;
205 StudyContext_iStruct *myStudyContext = _mapStudyContext_i[studyId];
207 // create a new mesh object servant, store it in a map in study context
209 meshServant = new SMESH_Mesh_i(this, geom, studyId, _localId);
210 myStudyContext->mapMesh_i[_localId] = meshServant;
213 // create a new mesh object
215 TopoDS_Shape myLocShape = _ShapeReader->GetShape(geom, myShape);
216 meshServant->SetImpl(_impl.Init(studyId, myLocShape));
218 catch(SALOME_Exception & S_ex)
220 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
223 // activate the CORBA servant of Mesh
225 SMESH::SMESH_Mesh_var mesh
226 = SMESH::SMESH_Mesh::_narrow(meshServant->_this());
228 meshServant->SetIor(mesh);
230 return SMESH::SMESH_Mesh::_duplicate(mesh);
233 //=============================================================================
237 //=============================================================================
239 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute(SMESH::SMESH_Mesh_ptr aMesh,
240 GEOM::GEOM_Shape_ptr aShape) throw(SALOME::SALOME_Exception)
242 MESSAGE("SMESH_Gen_i::IsReadyToCompute");
246 //=============================================================================
250 //=============================================================================
253 SMESH_Gen_i::GetSubShapesId(GEOM::GEOM_Gen_ptr geomEngine,
255 GEOM::GEOM_Shape_ptr mainShape,
256 const SMESH::shape_array & listOfSubShape)throw(SALOME::SALOME_Exception)
258 MESSAGE("SMESH_Gen_i::GetSubShapesId");
259 SMESH::long_array_var shapesId = new SMESH::long_array;
262 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
263 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(mainShape);
265 if (CORBA::is_nil(geom))
266 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", SALOME::BAD_PARAM);
267 if (CORBA::is_nil(myShape))
268 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", SALOME::BAD_PARAM);
273 _ShapeReader = new GEOM_Client();
274 ASSERT(_ShapeReader);
275 TopoDS_Shape myMainShape = _ShapeReader->GetShape(geom, myShape);
276 TopTools_IndexedMapOfShape myIndexToShape;
277 TopExp::MapShapes(myMainShape, myIndexToShape);
279 for (unsigned int i = 0; i < listOfSubShape.length(); i++)
281 GEOM::GEOM_Shape_var aShape
282 = GEOM::GEOM_Shape::_narrow(listOfSubShape[i]);
283 if (CORBA::is_nil(aShape))
284 THROW_SALOME_CORBA_EXCEPTION("bad shape reference",
286 TopoDS_Shape locShape = _ShapeReader->GetShape(geom, aShape);
287 for (TopExp_Explorer exp(locShape, TopAbs_FACE); exp.More();
290 const TopoDS_Face & F = TopoDS::Face(exp.Current());
291 setId.insert(myIndexToShape.FindIndex(F));
292 SCRUTE(myIndexToShape.FindIndex(F));
294 for (TopExp_Explorer exp(locShape, TopAbs_EDGE); exp.More();
297 const TopoDS_Edge & E = TopoDS::Edge(exp.Current());
298 setId.insert(myIndexToShape.FindIndex(E));
299 SCRUTE(myIndexToShape.FindIndex(E));
301 for (TopExp_Explorer exp(locShape, TopAbs_VERTEX); exp.More();
304 const TopoDS_Vertex & V = TopoDS::Vertex(exp.Current());
305 setId.insert(myIndexToShape.FindIndex(V));
306 SCRUTE(myIndexToShape.FindIndex(V));
309 shapesId->length(setId.size());
310 set < int >::iterator iind;
312 for (iind = setId.begin(); iind != setId.end(); iind++)
315 shapesId[i] = (*iind);
320 catch(SALOME_Exception & S_ex)
322 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
325 return shapesId._retn();
328 //=============================================================================
332 //=============================================================================
334 CORBA::Boolean SMESH_Gen_i::Compute(SMESH::SMESH_Mesh_ptr aMesh,
335 GEOM::GEOM_Shape_ptr aShape) throw(SALOME::SALOME_Exception)
337 MESSAGE("SMESH_Gen_i::Compute");
338 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
339 if (CORBA::is_nil(myShape))
340 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", SALOME::BAD_PARAM);
342 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(aMesh);
343 if (CORBA::is_nil(myMesh))
344 THROW_SALOME_CORBA_EXCEPTION("bad Mesh reference", SALOME::BAD_PARAM);
350 // get study context from studyId given by CORBA mesh object
352 int studyId = myMesh->GetStudyId();
353 ASSERT(_mapStudyContext_i.find(studyId) != _mapStudyContext_i.end());
354 StudyContext_iStruct *myStudyContext = _mapStudyContext_i[studyId];
356 // get local Mesh_i object with Id and study context
358 int meshId = myMesh->GetId();
359 ASSERT(myStudyContext->mapMesh_i.find(meshId) !=
360 myStudyContext->mapMesh_i.end());
361 SMESH_Mesh_i *meshServant = myStudyContext->mapMesh_i[meshId];
364 // get local TopoDS_Shape
366 GEOM::GEOM_Gen_var geom = meshServant->GetGeomEngine();
367 TopoDS_Shape myLocShape = _ShapeReader->GetShape(geom, myShape);
369 // implementation compute
371 ::SMESH_Mesh & myLocMesh = meshServant->GetImpl();
372 ret = _impl.Compute(myLocMesh, myLocShape);
374 catch(SALOME_Exception & S_ex)
376 MESSAGE("catch exception " << S_ex.what());
378 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
384 //=============================================================================
388 //=============================================================================
390 SALOMEDS::TMPFile * SMESH_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
391 const char *theURL, bool isMultiFile)
393 MESSAGE("SMESH_Gen_i::SAVE");
394 SALOMEDS::Study_var Study = theComponent->GetStudy();
397 // Declare a byte stream
398 SALOMEDS::TMPFile_var aStreamFile;
400 // Obtain a temporary dir
401 TCollection_AsciiString tmpDir =
402 (isMultiFile) ? TCollection_AsciiString((char *)theURL) :
403 SALOMEDS_Tool::GetTmpDir();
405 // Create a sequence of files processed
406 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
407 aFileSeq->length(NUM_TMP_FILES);
409 TCollection_AsciiString aStudyName("");
413 (SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
415 // Set names of temporary files
416 TCollection_AsciiString filename =
417 aStudyName + TCollection_AsciiString("_SMESH.hdf");
418 TCollection_AsciiString hypofile =
419 aStudyName + TCollection_AsciiString("_SMESH_Hypo.txt");
420 TCollection_AsciiString algofile =
421 aStudyName + TCollection_AsciiString("_SMESH_Algo.txt");
422 TCollection_AsciiString meshfile =
423 aStudyName + TCollection_AsciiString("_SMESH_Mesh.med");
424 aFileSeq[0] = CORBA::string_dup(filename.ToCString());
425 aFileSeq[1] = CORBA::string_dup(hypofile.ToCString());
426 aFileSeq[2] = CORBA::string_dup(algofile.ToCString());
427 aFileSeq[3] = CORBA::string_dup(meshfile.ToCString());
428 filename = tmpDir + filename;
429 hypofile = tmpDir + hypofile;
430 algofile = tmpDir + algofile;
431 meshfile = tmpDir + meshfile;
434 map < int, HDFgroup * >hdf_group, hdf_subgroup;
435 map < int, HDFdataset * >hdf_dataset;
438 SALOMEDS::ChildIterator_var itBig, it, itSM;
439 SALOMEDS::SObject_var mySObject, myBranch, mySObjectChild;
441 int longueur, cmpt_ds = 0, cmpt_it;
442 char *name_group, name_dataset[30], name_meshgroup[30];
444 int cmpt_sm = 0, myTag;
446 //************* HDF file creation
447 hdf_file = new HDFfile(filename.ToCString());
448 hdf_file->CreateOnDisk();
449 //****************************
451 itBig = Study->NewChildIterator(theComponent);
452 SCRUTE(Tag_HypothesisRoot);
453 SCRUTE(Tag_AlgorithmsRoot);
454 for (; itBig->More(); itBig->Next())
456 SALOMEDS::SObject_var gotBranch = itBig->Value();
457 SCRUTE(gotBranch->Name());
458 SCRUTE(gotBranch->Tag());
459 SCRUTE(gotBranch->GetID());
461 //************branch 1 : hypothesis
462 if (gotBranch->Tag() == Tag_HypothesisRoot)
463 { //hypothesis = tag 1
464 double length, maxElementsArea, maxElementsVolume;
465 int numberOfSegments;
467 destFile = fopen(hypofile.ToCString(), "w");
468 it = Study->NewChildIterator(gotBranch);
469 for (; it->More(); it->Next())
471 mySObject = it->Value();
472 SALOMEDS::GenericAttribute_var anAttr;
473 SALOMEDS::AttributeIOR_var anIOR;
474 if (mySObject->FindAttribute(anAttr, "AttributeIOR"))
476 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
478 SMESH::SMESH_Hypothesis_var myHyp =
479 SMESH::SMESH_Hypothesis::_narrow(_orb->
480 string_to_object(anIOR->Value()));
481 SCRUTE(myHyp->GetName());
482 fprintf(destFile, "%li\n", myHyp->GetId());
483 fprintf(destFile, "%s\n", myHyp->GetName());
484 if (strcmp(myHyp->GetName(), "LocalLength") == 0)
486 SMESH::SMESH_LocalLength_var LL =
487 SMESH::SMESH_LocalLength::_narrow(myHyp);
488 length = LL->GetLength();
489 fprintf(destFile, "%f\n", length);
491 else if (strcmp(myHyp->GetName(), "NumberOfSegments") == 0)
493 SMESH::SMESH_NumberOfSegments_var NOS =
494 SMESH::SMESH_NumberOfSegments::_narrow(myHyp);
495 numberOfSegments = NOS->GetNumberOfSegments();
496 fprintf(destFile, "%d\n", numberOfSegments);
498 else if (strcmp(myHyp->GetName(), "MaxElementArea") == 0)
500 SMESH::SMESH_MaxElementArea_var MEA =
501 SMESH::SMESH_MaxElementArea::_narrow(myHyp);
502 maxElementsArea = MEA->GetMaxElementArea();
503 fprintf(destFile, "%f\n", maxElementsArea);
505 else if (strcmp(myHyp->GetName(), "MaxElementVolume") == 0)
507 SMESH::SMESH_MaxElementVolume_var MEV =
508 SMESH::SMESH_MaxElementVolume::_narrow(myHyp);
509 maxElementsVolume = MEV->GetMaxElementVolume();
510 fprintf(destFile, "%f\n", maxElementsVolume);
516 //writes the file name in the hdf file
517 longueur = hypofile.Length() + 1;
518 name_group = "Hypothesis";
519 //SCRUTE(name_group);
522 hdf_group[1] = new HDFgroup(name_group, hdf_file);
523 hdf_group[1]->CreateOnDisk();
525 hdf_dataset[cmpt_ds] =
526 new HDFdataset(name_group, hdf_group[1], HDF_STRING, size, 1);
527 hdf_dataset[cmpt_ds]->CreateOnDisk();
528 hdf_dataset[cmpt_ds]->WriteOnDisk(hypofile.ToCString());
529 hdf_dataset[cmpt_ds]->CloseOnDisk();
532 hdf_group[1]->CloseOnDisk();
533 MESSAGE("End of Hypothesis Save");
536 //************branch 2 : algorithms
537 else if (gotBranch->Tag() == Tag_AlgorithmsRoot)
539 destFile = fopen(algofile.ToCString(), "w");
540 it = Study->NewChildIterator(gotBranch);
541 for (; it->More(); it->Next())
543 mySObject = it->Value();
544 SALOMEDS::GenericAttribute_var anAttr;
545 SALOMEDS::AttributeIOR_var anIOR;
546 if (mySObject->FindAttribute(anAttr, "AttributeIOR"))
548 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
549 SMESH::SMESH_Algo_var myAlgo =
550 SMESH::SMESH_Algo::_narrow(_orb->
551 string_to_object(anIOR->Value()));
552 SCRUTE(anIOR->Value());
553 SCRUTE(myAlgo->_is_nil());
554 fprintf(destFile, "%i\n", myAlgo->GetId());
555 fprintf(destFile, "%s\n", myAlgo->GetName());
561 //writes the file name in the hdf file
562 longueur = algofile.Length() + 1;
563 name_group = "Algorithms";
564 //SCRUTE(name_group);
567 hdf_group[2] = new HDFgroup(name_group, hdf_file);
568 hdf_group[2]->CreateOnDisk();
570 hdf_dataset[cmpt_ds] =
571 new HDFdataset(name_group, hdf_group[2], HDF_STRING, size, 1);
572 hdf_dataset[cmpt_ds]->CreateOnDisk();
573 hdf_dataset[cmpt_ds]->WriteOnDisk(algofile.ToCString());
574 hdf_dataset[cmpt_ds]->CloseOnDisk();
577 hdf_group[2]->CloseOnDisk();
578 MESSAGE("End of Algos Save");
581 //************branch 3 : meshes
582 else if (gotBranch->Tag() >= 3)
585 SALOMEDS::GenericAttribute_var anAttr;
586 SALOMEDS::AttributeIOR_var anIOR;
587 if (gotBranch->FindAttribute(anAttr, "AttributeIOR"))
589 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
591 SMESH::SMESH_Mesh_var myMesh =
592 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->
594 studyId = myMesh->GetStudyId();
597 StudyContext_iStruct *myStudyContext =
598 _mapStudyContext_i[studyId];
599 int meshId = myMesh->GetId();
600 SMESH_Mesh_i *meshServant = myStudyContext->mapMesh_i[meshId];
601 ::SMESH_Mesh & myLocMesh = meshServant->GetImpl();
602 SMESHDS_Mesh *mySMESHDSMesh = myLocMesh.GetMeshDS();
604 SCRUTE(mySMESHDSMesh->NbNodes());
605 if (mySMESHDSMesh->NbNodes() > 0)
607 //checks if the mesh is not empty
608 Mesh_Writer *myWriter = SMESHDriver::GetMeshWriter("MED");
609 myWriter->SetFile(meshfile.ToCString());
610 myWriter->SetMesh(mySMESHDSMesh);
611 myWriter->SetMeshId(gotBranch->Tag());
615 meshfile = "No data";
617 //********** opening of the HDF group
618 sprintf(name_meshgroup, "Mesh %d", gotBranch->Tag());
619 SCRUTE(name_meshgroup);
620 hdf_group[gotBranch->Tag()] =
621 new HDFgroup(name_meshgroup, hdf_file);
622 hdf_group[gotBranch->Tag()]->CreateOnDisk();
625 //********** file where the data are stored
626 longueur = strlen(meshfile.ToCString()) + 1;
628 strcpy(name_dataset, "Mesh data");
629 hdf_dataset[cmpt_ds] =
630 new HDFdataset(name_dataset, hdf_group[gotBranch->Tag()],
631 HDF_STRING, size, 1);
632 hdf_dataset[cmpt_ds]->CreateOnDisk();
633 hdf_dataset[cmpt_ds]->WriteOnDisk(meshfile.ToCString());
634 hdf_dataset[cmpt_ds]->CloseOnDisk();
638 //********** ref on shape
639 Standard_CString myRefOnObject = "";
640 SALOMEDS::SObject_var myRef, myShape;
641 _found = gotBranch->FindSubObject(Tag_RefOnShape, myRef);
644 ok = myRef->ReferencedObject(myShape);
645 myRefOnObject = myShape->GetID();
646 SCRUTE(myRefOnObject);
648 longueur = strlen(myRefOnObject) + 1;
652 strcpy(name_dataset, "Ref on shape");
653 hdf_dataset[cmpt_ds] =
654 new HDFdataset(name_dataset,
655 hdf_group[gotBranch->Tag()], HDF_STRING, size, 1);
656 hdf_dataset[cmpt_ds]->CreateOnDisk();
657 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
658 hdf_dataset[cmpt_ds]->CloseOnDisk();
665 //********** ref on applied hypothesis
667 gotBranch->FindSubObject(Tag_RefOnAppliedHypothesis,
672 strcpy(name_meshgroup, "Applied Hypothesis");
673 hdf_subgroup[Tag_RefOnAppliedHypothesis] =
674 new HDFgroup(name_meshgroup,
675 hdf_group[gotBranch->Tag()]);
676 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CreateOnDisk();
678 it = Study->NewChildIterator(myBranch);
680 for (; it->More(); it->Next())
682 mySObject = it->Value();
683 ok = mySObject->ReferencedObject(myRef);
684 myRefOnObject = myRef->GetID();
686 longueur = strlen(myRefOnObject) + 1;
690 sprintf(name_dataset, "Hyp %d", cmpt_it);
691 hdf_dataset[cmpt_ds] =
692 new HDFdataset(name_dataset,
693 hdf_subgroup[Tag_RefOnAppliedHypothesis],
694 HDF_STRING, size, 1);
695 hdf_dataset[cmpt_ds]->CreateOnDisk();
696 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
697 hdf_dataset[cmpt_ds]->CloseOnDisk();
702 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CloseOnDisk();
706 //********** ref on applied algorithms
708 gotBranch->FindSubObject(Tag_RefOnAppliedAlgorithms,
713 strcpy(name_meshgroup, "Applied Algorithms");
714 hdf_subgroup[Tag_RefOnAppliedAlgorithms] =
715 new HDFgroup(name_meshgroup,
716 hdf_group[gotBranch->Tag()]);
717 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CreateOnDisk();
719 it = Study->NewChildIterator(myBranch);
721 for (; it->More(); it->Next())
723 mySObject = it->Value();
724 ok = mySObject->ReferencedObject(myRef);
725 myRefOnObject = myRef->GetID();
727 longueur = strlen(myRefOnObject) + 1;
731 sprintf(name_dataset, "Algo %d", cmpt_it);
732 hdf_dataset[cmpt_ds] =
733 new HDFdataset(name_dataset,
734 hdf_subgroup[Tag_RefOnAppliedAlgorithms],
735 HDF_STRING, size, 1);
736 hdf_dataset[cmpt_ds]->CreateOnDisk();
737 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
738 hdf_dataset[cmpt_ds]->CloseOnDisk();
743 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CloseOnDisk();
745 MESSAGE("end of algo applied");
748 //********** submeshes on subshapes
750 for (int i = Tag_SubMeshOnVertex; i <= Tag_SubMeshOnCompound;
753 _found = gotBranch->FindSubObject(i, myBranch);
756 if (i == Tag_SubMeshOnVertex)
757 strcpy(name_meshgroup, "SubMeshes On Vertex");
758 else if (i == Tag_SubMeshOnEdge)
759 strcpy(name_meshgroup, "SubMeshes On Edge");
760 else if (i == Tag_SubMeshOnFace)
761 strcpy(name_meshgroup, "SubMeshes On Face");
762 else if (i == Tag_SubMeshOnSolid)
763 strcpy(name_meshgroup, "SubMeshes On Solid");
764 else if (i == Tag_SubMeshOnCompound)
765 strcpy(name_meshgroup, "SubMeshes On Compound");
768 myLevel1Tag = 10 + cmpt_sm;
769 hdf_subgroup[myLevel1Tag] =
770 new HDFgroup(name_meshgroup,
771 hdf_group[gotBranch->Tag()]);
772 hdf_subgroup[myLevel1Tag]->CreateOnDisk();
774 itSM = Study->NewChildIterator(myBranch);
775 for (; itSM->More(); itSM->Next())
776 { //Loop on all submeshes
777 mySObject = itSM->Value();
779 myTag = 10 + cmpt_sm;
780 mySObject->FindAttribute(anAttr, "AttributeIOR");
781 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
782 SMESH::SMESH_subMesh_var mySubMesh =
783 SMESH::SMESH_subMesh::_narrow(_orb->
784 string_to_object(anIOR->Value()));
786 //sprintf(name_meshgroup,"SubMesh %d",myTag);
787 sprintf(name_meshgroup, "SubMesh %ld",
789 SCRUTE(name_meshgroup);
791 hdf_subgroup[myTag] =
792 new HDFgroup(name_meshgroup,
793 hdf_subgroup[myLevel1Tag]);
794 hdf_subgroup[myTag]->CreateOnDisk();
796 //********** ref on shape
797 Standard_CString myRefOnObject = "";
798 SALOMEDS::SObject_var myRef, myShape;
801 mySObject->FindSubObject(Tag_RefOnShape, myRef);
804 ok = myRef->ReferencedObject(myShape);
805 myRefOnObject = myShape->GetID();
806 SCRUTE(myRefOnObject);
808 longueur = strlen(myRefOnObject) + 1;
812 strcpy(name_dataset, "Ref on shape");
813 hdf_dataset[cmpt_ds] =
814 new HDFdataset(name_dataset,
815 hdf_subgroup[myTag], HDF_STRING, size,
817 hdf_dataset[cmpt_ds]->CreateOnDisk();
818 hdf_dataset[cmpt_ds]->
819 WriteOnDisk(myRefOnObject);
820 hdf_dataset[cmpt_ds]->CloseOnDisk();
826 //********** ref on applied hypothesis
829 FindSubObject(Tag_RefOnAppliedHypothesis,
834 strcpy(name_meshgroup, "Applied Hypothesis");
836 hdf_subgroup[10 + cmpt_sm] =
837 new HDFgroup(name_meshgroup,
838 hdf_subgroup[myTag]);
839 hdf_subgroup[10 + cmpt_sm]->CreateOnDisk();
841 it = Study->NewChildIterator(myBranch);
843 for (; it->More(); it->Next())
845 mySObjectChild = it->Value();
846 ok = mySObjectChild->
847 ReferencedObject(myRef);
848 myRefOnObject = myRef->GetID();
850 longueur = strlen(myRefOnObject) + 1;
854 sprintf(name_dataset, "Hyp %d",
857 hdf_dataset[cmpt_ds] =
858 new HDFdataset(name_dataset,
859 hdf_subgroup[10 + cmpt_sm],
860 HDF_STRING, size, 1);
861 hdf_dataset[cmpt_ds]->CreateOnDisk();
862 hdf_dataset[cmpt_ds]->
863 WriteOnDisk(myRefOnObject);
864 hdf_dataset[cmpt_ds]->CloseOnDisk();
869 hdf_subgroup[10 + cmpt_sm]->CloseOnDisk();
873 //********** ref on applied algorithms
876 FindSubObject(Tag_RefOnAppliedAlgorithms,
882 strcpy(name_meshgroup, "Applied Algorithms");
884 hdf_subgroup[10 + cmpt_sm] =
885 new HDFgroup(name_meshgroup,
886 hdf_subgroup[myTag]);
887 hdf_subgroup[10 + cmpt_sm]->CreateOnDisk();
889 it = Study->NewChildIterator(myBranch);
891 for (; it->More(); it->Next())
893 mySObjectChild = it->Value();
894 ok = mySObjectChild->
895 ReferencedObject(myRef);
896 myRefOnObject = myRef->GetID();
898 longueur = strlen(myRefOnObject) + 1;
902 sprintf(name_dataset, "Algo %d",
904 hdf_dataset[cmpt_ds] =
905 new HDFdataset(name_dataset,
906 hdf_subgroup[10 + cmpt_sm],
907 HDF_STRING, size, 1);
908 hdf_dataset[cmpt_ds]->CreateOnDisk();
909 hdf_dataset[cmpt_ds]->
910 WriteOnDisk(myRefOnObject);
911 hdf_dataset[cmpt_ds]->CloseOnDisk();
916 hdf_subgroup[10 + cmpt_sm]->CloseOnDisk();
918 //MESSAGE("end of algo applied");
921 hdf_subgroup[myTag]->CloseOnDisk();
924 hdf_subgroup[myLevel1Tag]->CloseOnDisk();
930 //********** closing of the HDF group
931 hdf_group[gotBranch->Tag()]->CloseOnDisk();
932 MESSAGE("End of Mesh Save");
936 MESSAGE("End of Meshes Save");
939 MESSAGE("hdf_file->CloseOnDisk()");
940 hdf_file->CloseOnDisk();
942 MESSAGE("delete hdf_file");
946 // Convert temporary files to stream
947 MESSAGE("Convert temporary files to stream");
949 SALOMEDS_Tool::PutFilesToStream(tmpDir.ToCString(), aFileSeq.in(),
952 // Remove temporary files and directory
953 MESSAGE("Remove temporary files and directory");
955 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(),
958 MESSAGE("End SMESH_Gen_i::Save");
960 return aStreamFile._retn();
964 SMESH_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
965 const char *theURL, bool isMultiFile)
967 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
968 return aStreamFile._retn();
971 void SMESH_Gen_i::loadHypothesis(char * name, HDFfile * hdf_file,
972 char * hypofile, int studyId)
974 char name_of_group[HDF_NAME_MAX_LEN + 1];
976 double length, maxElementsArea, maxElementsVolume;
977 int numberOfSegments;
979 HDFgroup * hdfGroup = new HDFgroup(name, hdf_file);
980 hdfGroup->OpenOnDisk();
982 hdfGroup->InternalObjectIndentify(0, name_of_group);
983 HDFdataset * dataset = new HDFdataset(name_of_group, hdfGroup);
984 dataset->OpenOnDisk();
985 char *name_of_file = new char[dataset->GetSize()];
986 dataset->ReadFromDisk(name_of_file);
987 SCRUTE(name_of_file);
988 dataset->CloseOnDisk();
989 hdfGroup->CloseOnDisk();
990 delete[]name_of_file;
992 ifstream loadedFile(hypofile);
993 while (!loadedFile.eof())
996 string hypothesisName;
997 loadedFile >> hypothesisID;
998 loadedFile >> hypothesisName;
999 if(hypothesisName.length()==0) break;
1000 SMESH_Hypothesis_i * corbaHyp =
1001 _hypothesisFactory_i.Create(hypothesisName.c_str(), studyId, &_impl);
1002 SMESH_Hypothesis * localHyp = corbaHyp->getImpl();
1003 localHyp->SetID(hypothesisID);
1004 localHyp->LoadFrom(loadedFile);
1006 SMESH::SMESH_Hypothesis_var varHyp = corbaHyp->_this();
1007 string iorString = _orb->object_to_string(varHyp);
1008 sprintf(objectId, "%ld", varHyp->GetId());
1009 _SMESHCorbaObj[string("Hypo_") + string(objectId)] =
1012 MESSAGE("End of Hypos Load");
1015 void SMESH_Gen_i::loadAlgorithms(char * name, HDFfile * hdf_file,
1016 char* algofile, int studyId)
1018 char name_of_group[HDF_NAME_MAX_LEN + 1];
1020 HDFgroup * hdfGroup = new HDFgroup(name, hdf_file);
1021 hdfGroup->OpenOnDisk();
1023 hdfGroup->InternalObjectIndentify(0, name_of_group);
1024 HDFdataset * dataset =
1025 new HDFdataset(name_of_group, hdfGroup);
1026 dataset->OpenOnDisk();
1028 char *name_of_file = new char[dataset->GetSize()];
1029 dataset->ReadFromDisk(name_of_file);
1030 dataset->CloseOnDisk();
1031 hdfGroup->CloseOnDisk();
1032 delete[]name_of_file;
1034 char * aLine = new char[100];
1035 FILE * loadedFile = fopen(algofile, "r");
1036 while (!feof(loadedFile))
1039 fscanf(loadedFile, "%i", &hypothesisID);
1040 fscanf(loadedFile, "%s\n", aLine);
1042 if (strcmp(aLine, "") != 0)
1044 SMESH_Hypothesis_i * corbaHyp =
1045 _hypothesisFactory_i.Create(aLine, studyId, &_impl);
1046 SMESH_Hypothesis * localHyp = corbaHyp->getImpl();
1047 localHyp->SetID(hypothesisID);
1049 SMESH::SMESH_Hypothesis_var myHyp = corbaHyp->_this();
1051 SMESH::SMESH_Algo_var myAlgo =
1052 SMESH::SMESH_Algo::_narrow(myHyp);
1053 string iorString = _orb->object_to_string(myAlgo);
1054 sprintf(objectId, "%ld", myAlgo->GetId());
1055 _SMESHCorbaObj[string("Hypo_") + string(objectId)] =
1062 MESSAGE("End of Algos Load");
1066 * @param hdfGroupMeshId The group where to read the hypothesis
1068 * @param Study The study where to create the hypothesis
1069 * @param myNewMesh The mesh on which the hypothesis is applied
1070 * @param aShape The shape with which this mesh is linked
1072 void SMESH_Gen_i::loadAppliedHypothesis(HDFgroup * hdfGroupMeshId,
1073 bool _found, SALOMEDS::Study_var Study, SMESH::SMESH_Mesh_var myNewMesh,
1074 GEOM::GEOM_Shape_var aShape)
1076 HDFgroup * hdf_subgroup = new HDFgroup("Applied Hypothesis", hdfGroupMeshId);
1077 hdf_subgroup->OpenOnDisk();
1078 int nb_datasets = hdf_subgroup->nInternalObjects();
1079 char name_dataset[10];
1081 for (int j = 0; j < nb_datasets; j++)
1083 sprintf(name_dataset, "Hyp %d", j);
1084 HDFdataset * hdf_dataset = new HDFdataset(name_dataset, hdf_subgroup);
1085 hdf_dataset->OpenOnDisk();
1087 char *refFromFile = new char[hdf_dataset->GetSize()];
1088 hdf_dataset->ReadFromDisk(refFromFile);
1089 hdf_dataset->CloseOnDisk();
1094 SALOMEDS::SObject_var HypSO =
1095 Study->FindObjectID(refFromFile);
1096 if (!CORBA::is_nil(HypSO))
1098 SALOMEDS::GenericAttribute_var anAttr;
1099 HypSO->FindAttribute(anAttr, "AttributeIOR");
1100 SALOMEDS::AttributeIOR_var anIOR =
1101 SALOMEDS::AttributeIOR::_narrow(anAttr);
1102 if (!CORBA::is_nil(anIOR))
1104 char *HypIOR = anIOR->Value();
1105 SMESH::SMESH_Hypothesis_var anHyp =
1106 SMESH::SMESH_Hypothesis::_narrow(_orb->
1107 string_to_object(HypIOR));
1108 if (!CORBA::is_nil(anHyp))
1110 myNewMesh->AddHypothesis(aShape, anHyp);
1111 MESSAGE("Hypothesis added ...");
1117 hdf_subgroup->CloseOnDisk();
1121 * @param hdfGroupMeshId The group where to read the hypothesis
1123 * @param Study The study where to create the hypothesis
1124 * @param myNewMesh The mesh on which the hypothesis is applied
1125 * @param aShape The shape with which this mesh is linked
1127 void SMESH_Gen_i::loadAppliedAlgorithms(HDFgroup * hdfGroupMeshId,
1128 bool _found, SALOMEDS::Study_var Study, SMESH::SMESH_Mesh_var myNewMesh,
1129 GEOM::GEOM_Shape_var aShape)
1131 HDFgroup * hdf_subgroup = new HDFgroup("Applied Algorithms", hdfGroupMeshId);
1132 hdf_subgroup->OpenOnDisk();
1134 int nb_datasets = hdf_subgroup->nInternalObjects();
1135 SCRUTE(nb_datasets);
1136 char name_dataset[10];
1138 for (int j = 0; j < nb_datasets; j++)
1140 sprintf(name_dataset, "Algo %d", j);
1141 HDFdataset * dataset =
1142 new HDFdataset(name_dataset, hdf_subgroup);
1143 dataset->OpenOnDisk();
1145 char *refFromFile = new char[dataset->GetSize()];
1146 dataset->ReadFromDisk(refFromFile);
1147 dataset->CloseOnDisk();
1152 SALOMEDS::SObject_var AlgoSO =
1153 Study->FindObjectID(refFromFile);
1154 if (!CORBA::is_nil(AlgoSO))
1156 SALOMEDS::GenericAttribute_var anAttr;
1157 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1158 SALOMEDS::AttributeIOR_var anIOR =
1159 SALOMEDS::AttributeIOR::_narrow(anAttr);
1160 if (!CORBA::is_nil(anIOR))
1162 char *AlgoIOR = anIOR->Value();
1164 SMESH::SMESH_Hypothesis_var myHyp =
1165 SMESH::SMESH_Hypothesis::_narrow(_orb->
1166 string_to_object(AlgoIOR));
1167 SMESH::SMESH_Algo_var anAlgo =
1168 SMESH::SMESH_Algo::_narrow(myHyp);
1170 if (!CORBA::is_nil(anAlgo))
1172 myNewMesh->AddHypothesis(aShape, anAlgo); //essayer avec _SMESHCorbaObj
1173 MESSAGE("Algorithms added ...");
1179 hdf_subgroup->CloseOnDisk();
1183 * @param hdfGroupMeshId The group where to read the hypothesis
1184 * @param msgname ???
1185 * @param Study The study where to create the hypothesis
1186 * @param myNewMesh The mesh on which the hypothesis is applied
1188 void SMESH_Gen_i::loadSubMeshes(HDFgroup * hdfGroupMeshId, char * msgname,
1189 SALOMEDS::Study_var Study, SMESH::SMESH_Mesh_var myNewMesh)
1191 MESSAGE("SMESH_Gen_i::loadSubMeshes");
1192 HDFgroup * hdf_subgroupmyLevel1Tag = new HDFgroup(msgname, hdfGroupMeshId);
1193 hdf_subgroupmyLevel1Tag->OpenOnDisk();
1195 int nb_submeshes = hdf_subgroupmyLevel1Tag->nInternalObjects();
1196 char name_meshgroup[30];
1197 //SCRUTE(nb_submeshes);
1199 for (int j = 0; j < nb_submeshes; j++)
1202 //myTag = 10 + cmpt_sm;
1203 hdf_subgroupmyLevel1Tag->InternalObjectIndentify(j, name_meshgroup);
1205 HDFgroup * hdf_subgroupmyTag = new HDFgroup(name_meshgroup,
1206 hdf_subgroupmyLevel1Tag);
1207 hdf_subgroupmyTag->OpenOnDisk();
1208 int subMeshId = atoi((string(name_meshgroup).substr(8, 18)).c_str());
1210 MESSAGE("Ref on shape");
1211 //********** ref on shape
1212 HDFdataset * hdf_dataset =
1213 new HDFdataset("Ref on shape", hdf_subgroupmyTag);
1214 hdf_dataset->OpenOnDisk();
1216 char *refFromFile = new char[hdf_dataset->GetSize()];
1217 hdf_dataset->ReadFromDisk(refFromFile);
1218 hdf_dataset->CloseOnDisk();
1221 bool _found3 = false;
1222 SALOMEDS::SObject_var GSO = Study->FindObjectID(refFromFile);
1223 SMESH::SMESH_subMesh_var aSubMesh;
1224 GEOM::GEOM_Shape_var aSubShape;
1226 if (!CORBA::is_nil(GSO))
1228 SALOMEDS::GenericAttribute_var anAttr;
1229 GSO->FindAttribute(anAttr, "AttributeIOR");
1230 SALOMEDS::AttributeIOR_var anIOR =
1231 SALOMEDS::AttributeIOR::_narrow(anAttr);
1233 char *SubShapeIOR = anIOR->Value();
1235 GEOM::GEOM_Shape::_narrow(_orb-> string_to_object(SubShapeIOR));
1237 if (!CORBA::is_nil(aSubShape))
1239 aSubMesh = myNewMesh->GetElementsOnShape(aSubShape);
1240 string iorString = _orb->object_to_string(aSubMesh);
1242 sprintf(objectId, "%d", subMeshId);
1243 _SMESHCorbaObj[string("SubMesh_") + string(objectId)] =
1249 int nb_subgroup = hdf_subgroupmyTag->nInternalObjects();
1250 SCRUTE(nb_subgroup);
1251 char sgname[HDF_NAME_MAX_LEN + 1];
1252 for (int k = 0; k < nb_subgroup; k++)
1254 hdf_subgroupmyTag->InternalObjectIndentify(k, sgname);
1255 if (strcmp(sgname, "Ref on shape") == 0)
1259 else if (strcmp(sgname, "Applied Hypothesis") == 0)
1261 //********** ref on applied hypothesis
1262 MESSAGE("Applied Hypothesis");
1263 strcpy(name_meshgroup, "Applied Hypothesis");
1265 HDFgroup * hdf_subgroup10cmpt_sm = new HDFgroup(name_meshgroup,
1268 hdf_subgroup10cmpt_sm->OpenOnDisk();
1269 int nb_datasets = hdf_subgroup10cmpt_sm->nInternalObjects();
1270 // SCRUTE(nb_datasets);
1272 char name_dataset[30];
1273 for (int l = 0; l < nb_datasets; l++)
1275 sprintf(name_dataset, "Hyp %d", l);
1276 HDFdataset * hdf_datasetcmpt_ds =
1277 new HDFdataset(name_dataset, hdf_subgroup10cmpt_sm);
1278 hdf_datasetcmpt_ds->OpenOnDisk();
1279 int size = hdf_datasetcmpt_ds->GetSize();
1281 char *refFromFile = new char[size];
1282 hdf_datasetcmpt_ds->ReadFromDisk(refFromFile);
1283 hdf_datasetcmpt_ds->CloseOnDisk();
1288 SALOMEDS::SObject_var HypSO =
1289 Study->FindObjectID(refFromFile);
1290 if (!CORBA::is_nil(HypSO))
1292 SALOMEDS::GenericAttribute_var anAttr;
1293 SALOMEDS::AttributeIOR_var anIOR;
1294 HypSO->FindAttribute(anAttr, "AttributeIOR");
1295 anIOR = SALOMEDS::AttributeIOR:: _narrow(anAttr);
1296 if (!CORBA::is_nil(anIOR))
1298 char *HypIOR = anIOR->Value();
1299 SMESH::SMESH_Hypothesis_var anHyp =
1300 SMESH::SMESH_Hypothesis::_narrow(_orb->
1301 string_to_object(HypIOR));
1302 if (!CORBA::is_nil(anHyp))
1304 SMESH::SMESH_Mesh_var aMesh =
1305 aSubMesh->GetFather();
1306 aMesh->AddHypothesis(aSubShape, anHyp); //essayer avec _SMESHCorbaObj
1307 MESSAGE("Hypothesis added ...");
1314 else if (strcmp(sgname, "Applied Algorithms") == 0)
1316 //********** ref on applied algorithms
1317 MESSAGE("Applied Algorithms");
1318 strcpy(name_meshgroup, "Applied Algorithms");
1320 HDFgroup * hdf_subgroup10cmpt_sm = new HDFgroup(name_meshgroup,
1322 hdf_subgroup10cmpt_sm->OpenOnDisk();
1323 int nb_datasets = hdf_subgroup10cmpt_sm->nInternalObjects();
1324 SCRUTE(nb_datasets);
1326 char name_dataset[30];
1327 for (int l = 0; l < nb_datasets; l++)
1329 sprintf(name_dataset, "Algo %d", l);
1330 HDFdataset * hdf_datasetcmpt_ds = new HDFdataset(
1331 name_dataset, hdf_subgroup10cmpt_sm);
1332 hdf_datasetcmpt_ds->OpenOnDisk();
1333 int size = hdf_datasetcmpt_ds->GetSize();
1335 char *refFromFile = new char[size];
1336 hdf_datasetcmpt_ds->ReadFromDisk(refFromFile);
1337 hdf_datasetcmpt_ds->CloseOnDisk();
1338 delete hdf_datasetcmpt_ds;
1343 SALOMEDS::SObject_var AlgoSO =
1344 Study->FindObjectID(refFromFile);
1345 if (!CORBA::is_nil(AlgoSO))
1347 SALOMEDS::GenericAttribute_var anAttr;
1348 SALOMEDS::AttributeIOR_var anIOR;
1349 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1350 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1351 if (!CORBA::is_nil(anIOR))
1353 char *AlgoIOR = anIOR->Value();
1355 SMESH::SMESH_Hypothesis_var myHyp =
1356 SMESH::SMESH_Hypothesis::_narrow(_orb->
1357 string_to_object(AlgoIOR));
1358 SMESH::SMESH_Algo_var anAlgo =
1359 SMESH::SMESH_Algo::_narrow(myHyp);
1360 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1361 if (!CORBA::is_nil(anAlgo))
1363 SMESH::SMESH_Mesh_var aMesh =
1364 aSubMesh->GetFather();
1365 aMesh->AddHypothesis(aSubShape, anAlgo); //essayer avec _SMESHCorbaObj
1366 MESSAGE("Algorithms added ...");
1374 hdf_subgroupmyTag->CloseOnDisk();
1375 delete hdf_subgroupmyTag;
1377 hdf_subgroupmyLevel1Tag->CloseOnDisk();
1378 delete hdf_subgroupmyLevel1Tag;
1381 GEOM::GEOM_Gen_var SMESH_Gen_i::getGeomEngine()
1383 MESSAGE("SMESH_Gen_i::getGeomEngine");
1384 SALOME_NamingService *_NS = SINGLETON_ < SALOME_NamingService >::Instance();
1385 ASSERT(SINGLETON_ < SALOME_NamingService >::IsAlreadyExisting());
1386 _NS->init_orb(_orb);
1387 SALOME_LifeCycleCORBA *myEnginesLifeCycle = new SALOME_LifeCycleCORBA(_NS);
1388 Engines::Component_var geomEngine =
1389 myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", "GEOM");
1390 GEOM::GEOM_Gen_var myGeomEngine = GEOM::GEOM_Gen::_narrow(geomEngine);
1391 return myGeomEngine;
1394 GEOM::GEOM_Shape_var SMESH_Gen_i::getShape(SALOMEDS::Study_var Study, char * refFromFile)
1396 MESSAGE("SMESH_Gen_i::getShape("<<Study<<","<<refFromFile<<")");
1397 SCRUTE(CORBA::is_nil(Study));
1398 SALOMEDS::SObject_var CSO = Study->FindObjectID(refFromFile);
1399 GEOM::GEOM_Shape_var aShape;
1401 if (!CORBA::is_nil(CSO))
1403 SALOMEDS::GenericAttribute_var anAttr;
1404 CSO->FindAttribute(anAttr, "AttributeIOR");
1405 if (!CORBA::is_nil(CSO))
1407 MESSAGE("The shape was not loaded. Try to load it.");
1408 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(getGeomEngine());
1409 SALOMEDS::SComponent_var SCO = SALOMEDS::SComponent::_narrow(Study->FindObject("Geometry"));
1410 SALOMEDS::StudyBuilder_var B = Study->NewBuilder();
1411 B->LoadWith(SCO,driver);
1412 CSO->FindAttribute(anAttr, "AttributeIOR");
1415 SALOMEDS::AttributeIOR_var anIOR =
1416 SALOMEDS::AttributeIOR::_narrow(anAttr);
1418 char *ShapeIOR = anIOR->Value();
1420 GEOM::GEOM_Shape::_narrow(_orb->string_to_object(ShapeIOR));
1425 void SMESH_Gen_i::loadMesh(char * name, HDFfile * hdf_file,
1426 char* meshfile, SALOMEDS::Study_var Study)
1428 MESSAGE("in mesh load");
1429 char msgname[HDF_NAME_MAX_LEN + 1];
1431 char name_of_group[HDF_NAME_MAX_LEN + 1];
1434 atoi((string(name).substr(5, 5)).c_str());
1437 HDFgroup * hdfGroupMeshId = new HDFgroup(name, hdf_file);
1438 hdfGroupMeshId->OpenOnDisk();
1440 int nb_meshsubgroup = hdfGroupMeshId->nInternalObjects();
1441 SCRUTE(nb_meshsubgroup);
1443 //********** Loading of the file name where the data are stored
1444 MESSAGE("Mesh data file");
1445 strcpy(name_of_group, "Mesh data");
1446 HDFdataset * dataset =
1447 new HDFdataset(name_of_group, hdfGroupMeshId);
1448 dataset->OpenOnDisk();
1450 char *datafilename = new char[dataset->GetSize()];
1451 dataset->ReadFromDisk(datafilename);
1452 dataset->CloseOnDisk();
1453 MESSAGE("datafilename="<<datafilename<<" but this is ignored. We will read from "<<meshfile);
1454 datafilename=meshfile;
1456 //********** Loading of the reference on the shape
1457 //********** and mesh initialization
1458 MESSAGE("Ref on shape");
1459 strcpy(name_of_group, "Ref on shape");
1461 new HDFdataset(name_of_group, hdfGroupMeshId);
1462 dataset->OpenOnDisk();
1464 char *refFromFile = new char[dataset->GetSize()];
1465 dataset->ReadFromDisk(refFromFile);
1466 dataset->CloseOnDisk();
1468 bool _found = false;
1469 SCRUTE(refFromFile);
1470 SMESH::SMESH_Mesh_var myNewMesh;
1471 GEOM::GEOM_Shape_var aShape=getShape(Study, refFromFile);
1473 if (!CORBA::is_nil(aShape))
1476 myNewMesh = this->Init(getGeomEngine(), Study->StudyId(), aShape);
1477 string iorString = _orb->object_to_string(myNewMesh);
1478 sprintf(objectId, "%ld", myNewMesh->GetId());
1479 _SMESHCorbaObj[string("Mesh_") + string(objectId)] = iorString;
1483 //********** Loading of mesh data
1484 if (strcmp(datafilename, "No data") != 0)
1486 StudyContext_iStruct *myStudyContext =
1487 _mapStudyContext_i[Study->StudyId()];
1488 int meshId = myNewMesh->GetId();
1489 SMESH_Mesh_i *meshServant =
1490 myStudyContext->mapMesh_i[meshId];
1491 ::SMESH_Mesh & myLocMesh = meshServant->GetImpl();
1492 SMESHDS_Mesh *mySMESHDSMesh = myLocMesh.GetMeshDS();
1494 Mesh_Reader *myReader = SMESHDriver::GetMeshReader("MED");
1495 myReader->SetMesh(mySMESHDSMesh);
1496 myReader->SetMeshId(myMeshId);
1497 myReader->SetFile(datafilename);
1499 mySMESHDSMesh->logFullUpdate();
1500 MESSAGE("Loaded a mesh with " << mySMESHDSMesh->NbNodes() <<" nodes");
1505 //else if (strcmp(msgname,"Applied Hypothesis")==0) {
1506 for (int ii = 0; ii < nb_meshsubgroup; ii++)
1508 hdfGroupMeshId->InternalObjectIndentify(ii, msgname);
1509 if (strcmp(msgname, "Mesh data") == 0)
1513 else if (strcmp(msgname, "Ref on shape") == 0)
1517 else if (strcmp(msgname, "Applied Hypothesis") == 0)
1519 loadAppliedHypothesis(hdfGroupMeshId, _found, Study, myNewMesh,
1522 else if (strcmp(msgname, "Applied Algorithms") == 0)
1524 loadAppliedAlgorithms(hdfGroupMeshId, _found, Study, myNewMesh,
1527 else if (string(msgname).substr(0, 9) == string("SubMeshes"))
1529 loadSubMeshes(hdfGroupMeshId, msgname, Study, myNewMesh);
1532 hdfGroupMeshId->CloseOnDisk();
1533 MESSAGE("End of Meshes Load");
1537 * Load the part of the study related to SMESH.
1539 bool SMESH_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
1540 const SALOMEDS::TMPFile & theStream, const char *theURL, bool isMultiFile)
1542 MESSAGE("SMESH_Gen_i::Load");
1543 // Get temporary files location
1544 TCollection_AsciiString tmpDir =
1545 isMultiFile ? TCollection_AsciiString((char *)theURL) : SALOMEDS_Tool::
1548 // Convert the stream into sequence of files to process
1549 SALOMEDS::ListOfFileNames_var aFileSeq =
1550 SALOMEDS_Tool::PutStreamToFiles(theStream, tmpDir.ToCString(),
1553 TCollection_AsciiString aStudyName("");
1556 (SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
1558 // Set names of temporary files
1559 TCollection_AsciiString filename =
1560 tmpDir + aStudyName + TCollection_AsciiString("_SMESH.hdf");
1561 TCollection_AsciiString hypofile =
1562 tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Hypo.txt");
1563 TCollection_AsciiString algofile =
1564 tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Algo.txt");
1565 TCollection_AsciiString meshfile =
1566 tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Mesh.med");
1568 SALOMEDS::Study_var Study = theComponent->GetStudy();
1569 int studyId = Study->StudyId();
1572 SALOMEDS::AttributeName_var aName;
1574 SALOMEDS::SComponent_var fathergeom = Study->FindComponent("GEOM");
1575 SALOMEDS::SComponent_var myGeomSComp =
1576 SALOMEDS::SComponent::_narrow(fathergeom);
1579 char name[HDF_NAME_MAX_LEN + 1];
1580 map < int, HDFgroup * > hdf_subgroup;
1583 //************* HDF file opening
1584 HDFfile *hdf_file = new HDFfile(filename.ToCString());
1587 hdf_file->OpenOnDisk(HDF_RDONLY);
1591 MESSAGE("Load(): " << filename << " not found!");
1595 //****************************
1597 int nb_group = hdf_file->nInternalObjects();
1599 for (int i = 0; i < nb_group; i++)
1601 hdf_file->InternalObjectIndentify(i, name);
1602 if (strcmp(name, "Hypothesis") == 0)
1603 loadHypothesis(name, hdf_file, hypofile.ToCString(), studyId);
1604 else if (strcmp(name, "Algorithms") == 0)
1605 loadAlgorithms(name, hdf_file, algofile.ToCString(), studyId);
1606 else if (string(name).substr(0, 4) == string("Mesh"))
1607 loadMesh(name, hdf_file, meshfile.ToCString(), Study);
1610 MESSAGE("End of SMESH_Gen::Load");
1612 hdf_file->CloseOnDisk();
1614 // Remove temporary files created from the stream
1616 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(),
1622 bool SMESH_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
1623 const SALOMEDS::TMPFile & theStream, const char *theURL, bool isMultiFile)
1625 return Load(theComponent, theStream, theURL, isMultiFile);
1628 //=============================================================================
1632 //=============================================================================
1634 void SMESH_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
1637 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
1638 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
1639 for (; itBig->More(); itBig->Next())
1641 SALOMEDS::SObject_var gotBranch = itBig->Value();
1643 // branch 1 : hypothesis
1644 if (gotBranch->Tag() == Tag_HypothesisRoot ||
1645 gotBranch->Tag() == Tag_AlgorithmsRoot)
1647 SALOMEDS::ChildIterator_var it =
1648 aStudy->NewChildIterator(gotBranch);
1649 for (; it->More(); it->Next())
1651 SALOMEDS::SObject_var mySObject = it->Value();
1652 SALOMEDS::GenericAttribute_var anAttr;
1653 SALOMEDS::AttributeIOR_var anIOR;
1654 if (mySObject->FindAttribute(anAttr, "AttributeIOR"))
1656 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1657 SMESH::SMESH_Hypothesis_var myHyp =
1658 SMESH::SMESH_Hypothesis::_narrow(_orb->
1659 string_to_object(anIOR->Value()));
1661 sprintf(objectId, "%ld", myHyp->GetId());
1662 // cout<<"********** delete Hyp "<<objectId<<endl;
1663 _SMESHCorbaObj.erase(string("Hypo_") + string(objectId));
1665 SMESH::SMESH_Hypothesis::_narrow(_orb->
1666 string_to_object(anIOR->Value()));
1670 // branch 2 : algorithms
1671 else if (gotBranch->Tag() >= 3)
1673 SALOMEDS::ChildIterator_var it =
1674 aStudy->NewChildIterator(gotBranch);
1675 for (; it->More(); it->Next())
1677 SALOMEDS::SObject_var mySObject = it->Value();
1678 SALOMEDS::GenericAttribute_var anAttr;
1679 SALOMEDS::AttributeIOR_var anIOR;
1680 if (mySObject->FindAttribute(anAttr, "AttributeIOR"))
1682 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1683 SMESH::SMESH_Mesh_var myMesh =
1684 SMESH::SMESH_Mesh::_narrow(_orb->
1685 string_to_object(anIOR->Value()));
1686 if (!myMesh->_is_nil())
1689 sprintf(objectId, "%ld", myMesh->GetId());
1690 // cout<<"********** delete Mesh "<<objectId<<endl;
1691 _SMESHCorbaObj.erase(string("Mesh_") +
1693 CORBA::release(myMesh);
1697 SMESH::SMESH_subMesh_var mySubMesh =
1698 SMESH::SMESH_subMesh::_narrow(_orb->
1699 string_to_object(anIOR->Value()));
1700 if (!mySubMesh->_is_nil())
1703 sprintf(objectId, "%ld", mySubMesh->GetId());
1704 // cout<<"********** delete SubMesh "<<objectId<<endl;
1705 _SMESHCorbaObj.erase(string("SubMesh_") +
1707 CORBA::release(mySubMesh);
1716 //=============================================================================
1720 //=============================================================================
1722 char *SMESH_Gen_i::ComponentDataType()
1724 MESSAGE("SMESH_Gen_i::ComponentDataType");
1725 return strdup("SMESH");
1728 //=============================================================================
1732 //=============================================================================
1734 char *SMESH_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
1735 const char *IORString, CORBA::Boolean isMultiFile, CORBA::Boolean isASCII)
1737 MESSAGE("SMESH_Gen_i::IORToLocalPersistentID");
1741 SMESH::SMESH_Algo_var myAlgo =
1742 SMESH::SMESH_Algo::_narrow(_orb->string_to_object(IORString));
1743 if (!CORBA::is_nil(myAlgo))
1745 string prefix = "Hypo_";
1746 sprintf(objectId, "%ld", myAlgo->GetId());
1747 string lpID = prefix + string(objectId);
1748 return CORBA::string_dup(lpID.c_str());
1752 SMESH::SMESH_Hypothesis_var myHypo =
1753 SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(IORString));
1754 if (!CORBA::is_nil(myHypo))
1756 string prefix = "Hypo_";
1757 sprintf(objectId, "%ld", myHypo->GetId());
1758 string lpID = prefix + string(objectId);
1759 return CORBA::string_dup(lpID.c_str());
1763 SMESH::SMESH_Mesh_var myMesh =
1764 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(IORString));
1765 if (!CORBA::is_nil(myMesh))
1767 string prefix = "Mesh_";
1768 sprintf(objectId, "%ld", myMesh->GetId());
1769 string lpID = prefix + string(objectId);
1770 return CORBA::string_dup(lpID.c_str());
1774 SMESH::SMESH_subMesh_var mySubMesh =
1775 SMESH::SMESH_subMesh::_narrow(_orb->
1776 string_to_object(IORString));
1777 if (!CORBA::is_nil(mySubMesh))
1779 string prefix = "SubMesh_";
1780 sprintf(objectId, "%ld", mySubMesh->GetId());
1781 string lpID = prefix + string(objectId);
1782 return CORBA::string_dup(lpID.c_str());
1785 return (strdup("no object"));
1791 //=============================================================================
1795 //=============================================================================
1797 char *SMESH_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
1798 const char *aLocalPersistentID,
1799 CORBA::Boolean isMultiFile, CORBA::Boolean isASCII)
1801 MESSAGE("SMESH_Gen_i::LocalPersistentIDToIOR");
1802 SCRUTE(aLocalPersistentID);
1803 string clef = string(aLocalPersistentID);
1804 SCRUTE(_SMESHCorbaObj[clef].c_str());
1805 return CORBA::string_dup(_SMESHCorbaObj[clef].c_str());
1808 //=============================================================================
1812 //=============================================================================
1814 SMESH_topo *SMESH_Gen_i::ExploreMainShape(GEOM::GEOM_Gen_ptr geomEngine,
1815 CORBA::Long studyId, GEOM::GEOM_Shape_ptr aShape)
1817 MESSAGE("SMESH_Mesh_i::ExploreMainShape");
1818 // _narrow() duplicates the reference and check the type
1819 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
1820 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
1822 if (CORBA::is_nil(geom))
1823 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", SALOME::BAD_PARAM);
1824 if (CORBA::is_nil(myShape))
1825 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", SALOME::BAD_PARAM);
1827 SCRUTE(myShape->Name());
1828 geom->GetCurrentStudy(studyId);
1830 TopoDS_Shape mainShape = _ShapeReader->GetShape(geom, myShape);
1833 // create an SMESH_topo object for the mainShape
1835 SMESH_topo *myTopo = new SMESH_topo();
1838 // explore local TopoDS_Shape, store reference of local TopoDS subShapes
1840 for (TopExp_Explorer exp(mainShape, TopAbs_COMPOUND); exp.More();
1843 const TopoDS_Compound & E = TopoDS::Compound(exp.Current());
1844 int i = myTopo->_myShapes[TopAbs_COMPOUND].Add(E);
1847 for (TopExp_Explorer exp(mainShape, TopAbs_COMPSOLID); exp.More();
1850 const TopoDS_CompSolid & E = TopoDS::CompSolid(exp.Current());
1851 int i = myTopo->_myShapes[TopAbs_COMPSOLID].Add(E);
1854 for (TopExp_Explorer exp(mainShape, TopAbs_SOLID); exp.More(); exp.Next())
1856 const TopoDS_Solid & E = TopoDS::Solid(exp.Current());
1857 int i = myTopo->_myShapes[TopAbs_SOLID].Add(E);
1860 for (TopExp_Explorer exp(mainShape, TopAbs_SHELL); exp.More(); exp.Next())
1862 const TopoDS_Shell & E = TopoDS::Shell(exp.Current());
1863 int i = myTopo->_myShapes[TopAbs_SHELL].Add(E);
1866 for (TopExp_Explorer exp(mainShape, TopAbs_FACE); exp.More(); exp.Next())
1868 const TopoDS_Face & E = TopoDS::Face(exp.Current());
1869 int i = myTopo->_myShapes[TopAbs_FACE].Add(E);
1872 for (TopExp_Explorer exp(mainShape, TopAbs_WIRE); exp.More(); exp.Next())
1874 const TopoDS_Wire & E = TopoDS::Wire(exp.Current());
1875 int i = myTopo->_myShapes[TopAbs_WIRE].Add(E);
1878 for (TopExp_Explorer exp(mainShape, TopAbs_EDGE); exp.More(); exp.Next())
1880 const TopoDS_Edge & E = TopoDS::Edge(exp.Current());
1881 int i = myTopo->_myShapes[TopAbs_EDGE].Add(E);
1884 for (TopExp_Explorer exp(mainShape, TopAbs_VERTEX); exp.More(); exp.Next())
1886 const TopoDS_Vertex & E = TopoDS::Vertex(exp.Current());
1887 int i = myTopo->_myShapes[TopAbs_VERTEX].Add(E);
1891 // explore subShapes of distant CORBA object,
1892 // associate distant CORBA subShape references
1893 // with local reference to local TopoDS subShape
1895 string filenode = "toposhape.txt";
1896 ofstream fic(filenode.c_str());
1898 for (int shapeType = TopAbs_COMPOUND; shapeType < TopAbs_SHAPE; shapeType++)
1900 fic << "shape type : " << SMESH_shapeTypeNames[shapeType];
1902 GEOM::GEOM_Gen::ListOfGeomShapes_var subShapes
1903 = geom->SubShapeAll(myShape, shapeType);
1904 int nbSubShapes = subShapes->length();
1905 int nbLocal = myTopo->_myShapes[shapeType].Extent();
1906 fic << " - number of elements: " << nbSubShapes << endl;
1907 ASSERT(nbSubShapes == nbLocal);
1909 for (int i = 0; i < nbSubShapes; i++)
1911 GEOM::GEOM_Shape_var aSubShape = subShapes[i];
1912 string idShape = SMESH_topo::GetShapeLocalId(aSubShape);
1913 fic << " " << idShape;
1915 TopoDS_Shape aLocShape = _ShapeReader->GetShape(geom, aSubShape);
1916 for (int j = 1; j <= nbLocal; j++)
1917 if (aLocShape.IsSame(myTopo->_myShapes[shapeType].FindKey(j)))
1919 MESSAGE(" --- trouve = " << j);
1920 myTopo->_mapIndShapes[shapeType][idShape] = j;
1921 fic << " --- trouve = " << j;
1933 * Import a mesh from a file
1934 * @param fileName file name to be imported
1935 * @param fileType Currently it could be either "DAT", "UNV" or "MED".
1937 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Import(CORBA::Long studyId,
1938 const char *fileName, const char *fileType)
1940 MESSAGE("SMESH_Gen_I::Import");
1941 SMESH_Mesh_i *meshServant;
1944 if (_mapStudyContext_i.find(studyId) == _mapStudyContext_i.end())
1946 _mapStudyContext_i[studyId] = new StudyContext_iStruct;
1948 StudyContext_iStruct *myStudyContext = _mapStudyContext_i[studyId];
1950 // create a new mesh object servant, store it in a map in study context
1951 meshServant = new SMESH_Mesh_i(this, NULL, studyId, _localId);
1952 myStudyContext->mapMesh_i[_localId] = meshServant;
1955 // create a new mesh object
1956 meshServant->SetImpl(_impl.Import(studyId, fileName, fileType));
1958 catch(SALOME_Exception & S_ex)
1960 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1963 // activate the CORBA servant of Mesh
1965 SMESH::SMESH_Mesh_var mesh
1966 = SMESH::SMESH_Mesh::_narrow(meshServant->_this());
1968 meshServant->SetIor(mesh);
1969 return SMESH::SMESH_Mesh::_duplicate(mesh);
1972 //=============================================================================
1974 * C factory, accessible with dlsym, after dlopen
1976 //=============================================================================
1980 PortableServer::ObjectId * SMESHEngine_factory(CORBA::ORB_ptr orb,
1981 PortableServer::POA_ptr poa,
1982 PortableServer::ObjectId * contId,
1983 const char *instanceName, const char *interfaceName)
1985 MESSAGE("PortableServer::ObjectId * SMESHEngine_factory()");
1986 SCRUTE(interfaceName);
1987 SMESH_Gen_i *mySMESH_Gen
1988 = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
1989 return mySMESH_Gen->getId();