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();
1151 SALOMEDS::SObject_var AlgoSO =
1152 Study->FindObjectID(refFromFile);
1153 if (!CORBA::is_nil(AlgoSO))
1155 SALOMEDS::GenericAttribute_var anAttr;
1156 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1157 SALOMEDS::AttributeIOR_var anIOR =
1158 SALOMEDS::AttributeIOR::_narrow(anAttr);
1159 if (!CORBA::is_nil(anIOR))
1161 char *AlgoIOR = anIOR->Value();
1163 SMESH::SMESH_Hypothesis_var myHyp =
1164 SMESH::SMESH_Hypothesis::_narrow(_orb->
1165 string_to_object(AlgoIOR));
1166 SMESH::SMESH_Algo_var anAlgo =
1167 SMESH::SMESH_Algo::_narrow(myHyp);
1169 if (!CORBA::is_nil(anAlgo))
1171 myNewMesh->AddHypothesis(aShape, anAlgo); //essayer avec _SMESHCorbaObj
1172 MESSAGE("Algorithms added ...");
1178 hdf_subgroup->CloseOnDisk();
1182 * @param hdfGroupMeshId The group where to read the hypothesis
1183 * @param msgname ???
1184 * @param Study The study where to create the hypothesis
1185 * @param myNewMesh The mesh on which the hypothesis is applied
1187 void SMESH_Gen_i::loadSubMeshes(HDFgroup * hdfGroupMeshId, char * msgname,
1188 SALOMEDS::Study_var Study, SMESH::SMESH_Mesh_var myNewMesh)
1190 MESSAGE("SMESH_Gen_i::loadSubMeshes");
1191 HDFgroup * hdf_subgroupmyLevel1Tag = new HDFgroup(msgname, hdfGroupMeshId);
1192 hdf_subgroupmyLevel1Tag->OpenOnDisk();
1194 int nb_submeshes = hdf_subgroupmyLevel1Tag->nInternalObjects();
1195 char name_meshgroup[30];
1196 //SCRUTE(nb_submeshes);
1198 for (int j = 0; j < nb_submeshes; j++)
1201 //myTag = 10 + cmpt_sm;
1202 hdf_subgroupmyLevel1Tag->InternalObjectIndentify(j, name_meshgroup);
1204 HDFgroup * hdf_subgroupmyTag = new HDFgroup(name_meshgroup,
1205 hdf_subgroupmyLevel1Tag);
1206 hdf_subgroupmyTag->OpenOnDisk();
1207 int subMeshId = atoi((string(name_meshgroup).substr(8, 18)).c_str());
1209 MESSAGE("Ref on shape");
1210 //********** ref on shape
1211 HDFdataset * hdf_dataset =
1212 new HDFdataset("Ref on shape", hdf_subgroupmyTag);
1213 hdf_dataset->OpenOnDisk();
1215 char *refFromFile = new char[hdf_dataset->GetSize()];
1216 hdf_dataset->ReadFromDisk(refFromFile);
1217 hdf_dataset->CloseOnDisk();
1219 bool _found3 = false;
1220 SALOMEDS::SObject_var GSO = Study->FindObjectID(refFromFile);
1221 SMESH::SMESH_subMesh_var aSubMesh;
1222 GEOM::GEOM_Shape_var aSubShape;
1224 if (!CORBA::is_nil(GSO))
1226 SALOMEDS::GenericAttribute_var anAttr;
1227 GSO->FindAttribute(anAttr, "AttributeIOR");
1228 SALOMEDS::AttributeIOR_var anIOR =
1229 SALOMEDS::AttributeIOR::_narrow(anAttr);
1231 char *SubShapeIOR = anIOR->Value();
1233 GEOM::GEOM_Shape::_narrow(_orb-> string_to_object(SubShapeIOR));
1235 if (!CORBA::is_nil(aSubShape))
1237 aSubMesh = myNewMesh->GetElementsOnShape(aSubShape);
1238 string iorString = _orb->object_to_string(aSubMesh);
1240 sprintf(objectId, "%d", subMeshId);
1241 _SMESHCorbaObj[string("SubMesh_") + string(objectId)] =
1247 int nb_subgroup = hdf_subgroupmyTag->nInternalObjects();
1248 SCRUTE(nb_subgroup);
1249 char sgname[HDF_NAME_MAX_LEN + 1];
1250 for (int k = 0; k < nb_subgroup; k++)
1252 hdf_subgroupmyTag->InternalObjectIndentify(k, sgname);
1253 if (strcmp(sgname, "Ref on shape") == 0)
1257 else if (strcmp(sgname, "Applied Hypothesis") == 0)
1259 //********** ref on applied hypothesis
1260 MESSAGE("Applied Hypothesis");
1261 strcpy(name_meshgroup, "Applied Hypothesis");
1263 HDFgroup * hdf_subgroup10cmpt_sm = new HDFgroup(name_meshgroup,
1266 hdf_subgroup10cmpt_sm->OpenOnDisk();
1267 int nb_datasets = hdf_subgroup10cmpt_sm->nInternalObjects();
1268 // SCRUTE(nb_datasets);
1270 char name_dataset[30];
1271 for (int l = 0; l < nb_datasets; l++)
1273 sprintf(name_dataset, "Hyp %d", l);
1274 HDFdataset * hdf_datasetcmpt_ds =
1275 new HDFdataset(name_dataset, hdf_subgroup10cmpt_sm);
1276 hdf_datasetcmpt_ds->OpenOnDisk();
1277 int size = hdf_datasetcmpt_ds->GetSize();
1279 char *refFromFile = new char[size];
1280 hdf_datasetcmpt_ds->ReadFromDisk(refFromFile);
1281 hdf_datasetcmpt_ds->CloseOnDisk();
1286 SALOMEDS::SObject_var HypSO =
1287 Study->FindObjectID(refFromFile);
1288 if (!CORBA::is_nil(HypSO))
1290 SALOMEDS::GenericAttribute_var anAttr;
1291 SALOMEDS::AttributeIOR_var anIOR;
1292 HypSO->FindAttribute(anAttr, "AttributeIOR");
1293 anIOR = SALOMEDS::AttributeIOR:: _narrow(anAttr);
1294 if (!CORBA::is_nil(anIOR))
1296 char *HypIOR = anIOR->Value();
1297 SMESH::SMESH_Hypothesis_var anHyp =
1298 SMESH::SMESH_Hypothesis::_narrow(_orb->
1299 string_to_object(HypIOR));
1300 if (!CORBA::is_nil(anHyp))
1302 SMESH::SMESH_Mesh_var aMesh =
1303 aSubMesh->GetFather();
1304 aMesh->AddHypothesis(aSubShape, anHyp); //essayer avec _SMESHCorbaObj
1305 MESSAGE("Hypothesis added ...");
1312 else if (strcmp(sgname, "Applied Algorithms") == 0)
1314 //********** ref on applied algorithms
1315 MESSAGE("Applied Algorithms");
1316 strcpy(name_meshgroup, "Applied Algorithms");
1318 HDFgroup * hdf_subgroup10cmpt_sm = new HDFgroup(name_meshgroup,
1320 hdf_subgroup10cmpt_sm->OpenOnDisk();
1321 int nb_datasets = hdf_subgroup10cmpt_sm->nInternalObjects();
1322 SCRUTE(nb_datasets);
1324 char name_dataset[30];
1325 for (int l = 0; l < nb_datasets; l++)
1327 sprintf(name_dataset, "Algo %d", l);
1328 HDFdataset * hdf_datasetcmpt_ds = new HDFdataset(
1329 name_dataset, hdf_subgroup10cmpt_sm);
1330 hdf_datasetcmpt_ds->OpenOnDisk();
1331 int size = hdf_datasetcmpt_ds->GetSize();
1333 char *refFromFile = new char[size];
1334 hdf_datasetcmpt_ds->ReadFromDisk(refFromFile);
1335 hdf_datasetcmpt_ds->CloseOnDisk();
1336 delete hdf_datasetcmpt_ds;
1341 SALOMEDS::SObject_var AlgoSO =
1342 Study->FindObjectID(refFromFile);
1343 if (!CORBA::is_nil(AlgoSO))
1345 SALOMEDS::GenericAttribute_var anAttr;
1346 SALOMEDS::AttributeIOR_var anIOR;
1347 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1348 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1349 if (!CORBA::is_nil(anIOR))
1351 char *AlgoIOR = anIOR->Value();
1353 SMESH::SMESH_Hypothesis_var myHyp =
1354 SMESH::SMESH_Hypothesis::_narrow(_orb->
1355 string_to_object(AlgoIOR));
1356 SMESH::SMESH_Algo_var anAlgo =
1357 SMESH::SMESH_Algo::_narrow(myHyp);
1358 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1359 if (!CORBA::is_nil(anAlgo))
1361 SMESH::SMESH_Mesh_var aMesh =
1362 aSubMesh->GetFather();
1363 aMesh->AddHypothesis(aSubShape, anAlgo); //essayer avec _SMESHCorbaObj
1364 MESSAGE("Algorithms added ...");
1372 hdf_subgroupmyTag->CloseOnDisk();
1374 hdf_subgroupmyLevel1Tag->CloseOnDisk();
1377 GEOM::GEOM_Gen_var SMESH_Gen_i::getGeomEngine()
1379 MESSAGE("SMESH_Gen_i::getGeomEngine");
1380 SALOME_NamingService *_NS = SINGLETON_ < SALOME_NamingService >::Instance();
1381 ASSERT(SINGLETON_ < SALOME_NamingService >::IsAlreadyExisting());
1382 _NS->init_orb(_orb);
1383 SALOME_LifeCycleCORBA *myEnginesLifeCycle = new SALOME_LifeCycleCORBA(_NS);
1384 Engines::Component_var geomEngine =
1385 myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", "GEOM");
1386 GEOM::GEOM_Gen_var myGeomEngine = GEOM::GEOM_Gen::_narrow(geomEngine);
1387 return myGeomEngine;
1390 GEOM::GEOM_Shape_var SMESH_Gen_i::getShape(SALOMEDS::Study_var Study, char * refFromFile)
1392 MESSAGE("SMESH_Gen_i::getShape("<<Study<<","<<refFromFile<<")");
1393 SCRUTE(CORBA::is_nil(Study));
1394 SALOMEDS::SObject_var CSO = Study->FindObjectID(refFromFile);
1395 GEOM::GEOM_Shape_var aShape;
1397 if (!CORBA::is_nil(CSO))
1399 SALOMEDS::GenericAttribute_var anAttr;
1400 CSO->FindAttribute(anAttr, "AttributeIOR");
1401 if (!CORBA::is_nil(CSO))
1403 MESSAGE("The shape was not loaded. Try to load it.");
1404 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(getGeomEngine());
1405 SALOMEDS::SComponent_var SCO = SALOMEDS::SComponent::_narrow(Study->FindObject("Geometry"));
1406 SALOMEDS::StudyBuilder_var B = Study->NewBuilder();
1407 B->LoadWith(SCO,driver);
1408 CSO->FindAttribute(anAttr, "AttributeIOR");
1411 SALOMEDS::AttributeIOR_var anIOR =
1412 SALOMEDS::AttributeIOR::_narrow(anAttr);
1414 char *ShapeIOR = anIOR->Value();
1416 GEOM::GEOM_Shape::_narrow(_orb->string_to_object(ShapeIOR));
1421 void SMESH_Gen_i::loadMesh(char * name, HDFfile * hdf_file,
1422 char* meshfile, SALOMEDS::Study_var Study)
1424 MESSAGE("in mesh load");
1425 char msgname[HDF_NAME_MAX_LEN + 1];
1427 char name_of_group[HDF_NAME_MAX_LEN + 1];
1430 atoi((string(name).substr(5, 5)).c_str());
1433 HDFgroup * hdfGroupMeshId = new HDFgroup(name, hdf_file);
1434 hdfGroupMeshId->OpenOnDisk();
1436 int nb_meshsubgroup = hdfGroupMeshId->nInternalObjects();
1437 SCRUTE(nb_meshsubgroup);
1439 //********** Loading of the file name where the data are stored
1440 MESSAGE("Mesh data file");
1441 strcpy(name_of_group, "Mesh data");
1442 HDFdataset * dataset =
1443 new HDFdataset(name_of_group, hdfGroupMeshId);
1444 dataset->OpenOnDisk();
1446 char *datafilename = new char[dataset->GetSize()];
1447 dataset->ReadFromDisk(datafilename);
1448 dataset->CloseOnDisk();
1449 MESSAGE("datafilename="<<datafilename<<" but this is ignored. We will read from "<<meshfile);
1450 datafilename=meshfile;
1452 //********** Loading of the reference on the shape
1453 //********** and mesh initialization
1454 MESSAGE("Ref on shape");
1455 strcpy(name_of_group, "Ref on shape");
1457 new HDFdataset(name_of_group, hdfGroupMeshId);
1458 dataset->OpenOnDisk();
1460 char *refFromFile = new char[dataset->GetSize()];
1461 dataset->ReadFromDisk(refFromFile);
1462 dataset->CloseOnDisk();
1464 bool _found = false;
1465 SCRUTE(refFromFile);
1466 SMESH::SMESH_Mesh_var myNewMesh;
1467 GEOM::GEOM_Shape_var aShape=getShape(Study, refFromFile);
1469 if (!CORBA::is_nil(aShape))
1472 myNewMesh = this->Init(getGeomEngine(), Study->StudyId(), aShape);
1473 string iorString = _orb->object_to_string(myNewMesh);
1474 sprintf(objectId, "%ld", myNewMesh->GetId());
1475 _SMESHCorbaObj[string("Mesh_") + string(objectId)] = iorString;
1479 //********** Loading of mesh data
1480 if (strcmp(datafilename, "No data") != 0)
1482 StudyContext_iStruct *myStudyContext =
1483 _mapStudyContext_i[Study->StudyId()];
1484 int meshId = myNewMesh->GetId();
1485 SMESH_Mesh_i *meshServant =
1486 myStudyContext->mapMesh_i[meshId];
1487 ::SMESH_Mesh & myLocMesh = meshServant->GetImpl();
1488 SMESHDS_Mesh *mySMESHDSMesh = myLocMesh.GetMeshDS();
1490 Mesh_Reader *myReader = SMESHDriver::GetMeshReader("MED");
1491 myReader->SetMesh(mySMESHDSMesh);
1492 myReader->SetMeshId(myMeshId);
1493 myReader->SetFile(datafilename);
1495 mySMESHDSMesh->logFullUpdate();
1496 MESSAGE("Loaded a mesh with " << mySMESHDSMesh->NbNodes() <<" nodes");
1501 //else if (strcmp(msgname,"Applied Hypothesis")==0) {
1502 for (int ii = 0; ii < nb_meshsubgroup; ii++)
1504 hdfGroupMeshId->InternalObjectIndentify(ii, msgname);
1505 if (strcmp(msgname, "Mesh data") == 0)
1509 else if (strcmp(msgname, "Ref on shape") == 0)
1513 else if (strcmp(msgname, "Applied Hypothesis") == 0)
1515 loadAppliedHypothesis(hdfGroupMeshId, _found, Study, myNewMesh,
1518 else if (strcmp(msgname, "Applied Algorithms") == 0)
1520 loadAppliedAlgorithms(hdfGroupMeshId, _found, Study, myNewMesh,
1523 else if (string(msgname).substr(0, 9) == string("SubMeshes"))
1525 loadSubMeshes(hdfGroupMeshId, msgname, Study, myNewMesh);
1528 hdfGroupMeshId->CloseOnDisk();
1529 MESSAGE("End of Meshes Load");
1533 * Load the part of the study related to SMESH.
1535 bool SMESH_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
1536 const SALOMEDS::TMPFile & theStream, const char *theURL, bool isMultiFile)
1538 MESSAGE("SMESH_Gen_i::Load");
1539 // Get temporary files location
1540 TCollection_AsciiString tmpDir =
1541 isMultiFile ? TCollection_AsciiString((char *)theURL) : SALOMEDS_Tool::
1544 // Convert the stream into sequence of files to process
1545 SALOMEDS::ListOfFileNames_var aFileSeq =
1546 SALOMEDS_Tool::PutStreamToFiles(theStream, tmpDir.ToCString(),
1549 TCollection_AsciiString aStudyName("");
1552 (SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
1554 // Set names of temporary files
1555 TCollection_AsciiString filename =
1556 tmpDir + aStudyName + TCollection_AsciiString("_SMESH.hdf");
1557 TCollection_AsciiString hypofile =
1558 tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Hypo.txt");
1559 TCollection_AsciiString algofile =
1560 tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Algo.txt");
1561 TCollection_AsciiString meshfile =
1562 tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Mesh.med");
1564 SALOMEDS::Study_var Study = theComponent->GetStudy();
1565 int studyId = Study->StudyId();
1568 SALOMEDS::AttributeName_var aName;
1570 SALOMEDS::SComponent_var fathergeom = Study->FindComponent("GEOM");
1571 SALOMEDS::SComponent_var myGeomSComp =
1572 SALOMEDS::SComponent::_narrow(fathergeom);
1575 char name[HDF_NAME_MAX_LEN + 1];
1576 map < int, HDFgroup * > hdf_subgroup;
1579 //************* HDF file opening
1580 HDFfile *hdf_file = new HDFfile(filename.ToCString());
1583 hdf_file->OpenOnDisk(HDF_RDONLY);
1587 MESSAGE("Load(): " << filename << " not found!");
1591 //****************************
1593 int nb_group = hdf_file->nInternalObjects();
1595 for (int i = 0; i < nb_group; i++)
1597 hdf_file->InternalObjectIndentify(i, name);
1598 if (strcmp(name, "Hypothesis") == 0)
1599 loadHypothesis(name, hdf_file, hypofile.ToCString(), studyId);
1600 else if (strcmp(name, "Algorithms") == 0)
1601 loadAlgorithms(name, hdf_file, algofile.ToCString(), studyId);
1602 else if (string(name).substr(0, 4) == string("Mesh"))
1603 loadMesh(name, hdf_file, meshfile.ToCString(), Study);
1606 MESSAGE("End of SMESH_Gen::Load");
1608 hdf_file->CloseOnDisk();
1610 // Remove temporary files created from the stream
1612 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(),
1618 bool SMESH_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
1619 const SALOMEDS::TMPFile & theStream, const char *theURL, bool isMultiFile)
1621 return Load(theComponent, theStream, theURL, isMultiFile);
1624 //=============================================================================
1628 //=============================================================================
1630 void SMESH_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
1633 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
1634 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
1635 for (; itBig->More(); itBig->Next())
1637 SALOMEDS::SObject_var gotBranch = itBig->Value();
1639 // branch 1 : hypothesis
1640 if (gotBranch->Tag() == Tag_HypothesisRoot ||
1641 gotBranch->Tag() == Tag_AlgorithmsRoot)
1643 SALOMEDS::ChildIterator_var it =
1644 aStudy->NewChildIterator(gotBranch);
1645 for (; it->More(); it->Next())
1647 SALOMEDS::SObject_var mySObject = it->Value();
1648 SALOMEDS::GenericAttribute_var anAttr;
1649 SALOMEDS::AttributeIOR_var anIOR;
1650 if (mySObject->FindAttribute(anAttr, "AttributeIOR"))
1652 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1653 SMESH::SMESH_Hypothesis_var myHyp =
1654 SMESH::SMESH_Hypothesis::_narrow(_orb->
1655 string_to_object(anIOR->Value()));
1657 sprintf(objectId, "%ld", myHyp->GetId());
1658 // cout<<"********** delete Hyp "<<objectId<<endl;
1659 _SMESHCorbaObj.erase(string("Hypo_") + string(objectId));
1661 SMESH::SMESH_Hypothesis::_narrow(_orb->
1662 string_to_object(anIOR->Value()));
1666 // branch 2 : algorithms
1667 else if (gotBranch->Tag() >= 3)
1669 SALOMEDS::ChildIterator_var it =
1670 aStudy->NewChildIterator(gotBranch);
1671 for (; it->More(); it->Next())
1673 SALOMEDS::SObject_var mySObject = it->Value();
1674 SALOMEDS::GenericAttribute_var anAttr;
1675 SALOMEDS::AttributeIOR_var anIOR;
1676 if (mySObject->FindAttribute(anAttr, "AttributeIOR"))
1678 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1679 SMESH::SMESH_Mesh_var myMesh =
1680 SMESH::SMESH_Mesh::_narrow(_orb->
1681 string_to_object(anIOR->Value()));
1682 if (!myMesh->_is_nil())
1685 sprintf(objectId, "%ld", myMesh->GetId());
1686 // cout<<"********** delete Mesh "<<objectId<<endl;
1687 _SMESHCorbaObj.erase(string("Mesh_") +
1689 CORBA::release(myMesh);
1693 SMESH::SMESH_subMesh_var mySubMesh =
1694 SMESH::SMESH_subMesh::_narrow(_orb->
1695 string_to_object(anIOR->Value()));
1696 if (!mySubMesh->_is_nil())
1699 sprintf(objectId, "%ld", mySubMesh->GetId());
1700 // cout<<"********** delete SubMesh "<<objectId<<endl;
1701 _SMESHCorbaObj.erase(string("SubMesh_") +
1703 CORBA::release(mySubMesh);
1712 //=============================================================================
1716 //=============================================================================
1718 char *SMESH_Gen_i::ComponentDataType()
1720 MESSAGE("SMESH_Gen_i::ComponentDataType");
1721 return strdup("SMESH");
1724 //=============================================================================
1728 //=============================================================================
1730 char *SMESH_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
1731 const char *IORString, CORBA::Boolean isMultiFile, CORBA::Boolean isASCII)
1733 MESSAGE("SMESH_Gen_i::IORToLocalPersistentID");
1737 SMESH::SMESH_Algo_var myAlgo =
1738 SMESH::SMESH_Algo::_narrow(_orb->string_to_object(IORString));
1739 if (!CORBA::is_nil(myAlgo))
1741 string prefix = "Hypo_";
1742 sprintf(objectId, "%ld", myAlgo->GetId());
1743 string lpID = prefix + string(objectId);
1744 return CORBA::string_dup(lpID.c_str());
1748 SMESH::SMESH_Hypothesis_var myHypo =
1749 SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(IORString));
1750 if (!CORBA::is_nil(myHypo))
1752 string prefix = "Hypo_";
1753 sprintf(objectId, "%ld", myHypo->GetId());
1754 string lpID = prefix + string(objectId);
1755 return CORBA::string_dup(lpID.c_str());
1759 SMESH::SMESH_Mesh_var myMesh =
1760 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(IORString));
1761 if (!CORBA::is_nil(myMesh))
1763 string prefix = "Mesh_";
1764 sprintf(objectId, "%ld", myMesh->GetId());
1765 string lpID = prefix + string(objectId);
1766 return CORBA::string_dup(lpID.c_str());
1770 SMESH::SMESH_subMesh_var mySubMesh =
1771 SMESH::SMESH_subMesh::_narrow(_orb->
1772 string_to_object(IORString));
1773 if (!CORBA::is_nil(mySubMesh))
1775 string prefix = "SubMesh_";
1776 sprintf(objectId, "%ld", mySubMesh->GetId());
1777 string lpID = prefix + string(objectId);
1778 return CORBA::string_dup(lpID.c_str());
1781 return (strdup("no object"));
1787 //=============================================================================
1791 //=============================================================================
1793 char *SMESH_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
1794 const char *aLocalPersistentID,
1795 CORBA::Boolean isMultiFile, CORBA::Boolean isASCII)
1797 MESSAGE("SMESH_Gen_i::LocalPersistentIDToIOR");
1798 SCRUTE(aLocalPersistentID);
1799 string clef = string(aLocalPersistentID);
1800 SCRUTE(_SMESHCorbaObj[clef].c_str());
1801 return CORBA::string_dup(_SMESHCorbaObj[clef].c_str());
1804 //=============================================================================
1808 //=============================================================================
1810 SMESH_topo *SMESH_Gen_i::ExploreMainShape(GEOM::GEOM_Gen_ptr geomEngine,
1811 CORBA::Long studyId, GEOM::GEOM_Shape_ptr aShape)
1813 MESSAGE("SMESH_Mesh_i::ExploreMainShape");
1814 // _narrow() duplicates the reference and check the type
1815 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
1816 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
1818 if (CORBA::is_nil(geom))
1819 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", SALOME::BAD_PARAM);
1820 if (CORBA::is_nil(myShape))
1821 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", SALOME::BAD_PARAM);
1823 SCRUTE(myShape->Name());
1824 geom->GetCurrentStudy(studyId);
1826 TopoDS_Shape mainShape = _ShapeReader->GetShape(geom, myShape);
1829 // create an SMESH_topo object for the mainShape
1831 SMESH_topo *myTopo = new SMESH_topo();
1834 // explore local TopoDS_Shape, store reference of local TopoDS subShapes
1836 for (TopExp_Explorer exp(mainShape, TopAbs_COMPOUND); exp.More();
1839 const TopoDS_Compound & E = TopoDS::Compound(exp.Current());
1840 int i = myTopo->_myShapes[TopAbs_COMPOUND].Add(E);
1843 for (TopExp_Explorer exp(mainShape, TopAbs_COMPSOLID); exp.More();
1846 const TopoDS_CompSolid & E = TopoDS::CompSolid(exp.Current());
1847 int i = myTopo->_myShapes[TopAbs_COMPSOLID].Add(E);
1850 for (TopExp_Explorer exp(mainShape, TopAbs_SOLID); exp.More(); exp.Next())
1852 const TopoDS_Solid & E = TopoDS::Solid(exp.Current());
1853 int i = myTopo->_myShapes[TopAbs_SOLID].Add(E);
1856 for (TopExp_Explorer exp(mainShape, TopAbs_SHELL); exp.More(); exp.Next())
1858 const TopoDS_Shell & E = TopoDS::Shell(exp.Current());
1859 int i = myTopo->_myShapes[TopAbs_SHELL].Add(E);
1862 for (TopExp_Explorer exp(mainShape, TopAbs_FACE); exp.More(); exp.Next())
1864 const TopoDS_Face & E = TopoDS::Face(exp.Current());
1865 int i = myTopo->_myShapes[TopAbs_FACE].Add(E);
1868 for (TopExp_Explorer exp(mainShape, TopAbs_WIRE); exp.More(); exp.Next())
1870 const TopoDS_Wire & E = TopoDS::Wire(exp.Current());
1871 int i = myTopo->_myShapes[TopAbs_WIRE].Add(E);
1874 for (TopExp_Explorer exp(mainShape, TopAbs_EDGE); exp.More(); exp.Next())
1876 const TopoDS_Edge & E = TopoDS::Edge(exp.Current());
1877 int i = myTopo->_myShapes[TopAbs_EDGE].Add(E);
1880 for (TopExp_Explorer exp(mainShape, TopAbs_VERTEX); exp.More(); exp.Next())
1882 const TopoDS_Vertex & E = TopoDS::Vertex(exp.Current());
1883 int i = myTopo->_myShapes[TopAbs_VERTEX].Add(E);
1887 // explore subShapes of distant CORBA object,
1888 // associate distant CORBA subShape references
1889 // with local reference to local TopoDS subShape
1891 string filenode = "toposhape.txt";
1892 ofstream fic(filenode.c_str());
1894 for (int shapeType = TopAbs_COMPOUND; shapeType < TopAbs_SHAPE; shapeType++)
1896 fic << "shape type : " << SMESH_shapeTypeNames[shapeType];
1898 GEOM::GEOM_Gen::ListOfGeomShapes_var subShapes
1899 = geom->SubShapeAll(myShape, shapeType);
1900 int nbSubShapes = subShapes->length();
1901 int nbLocal = myTopo->_myShapes[shapeType].Extent();
1902 fic << " - number of elements: " << nbSubShapes << endl;
1903 ASSERT(nbSubShapes == nbLocal);
1905 for (int i = 0; i < nbSubShapes; i++)
1907 GEOM::GEOM_Shape_var aSubShape = subShapes[i];
1908 string idShape = SMESH_topo::GetShapeLocalId(aSubShape);
1909 fic << " " << idShape;
1911 TopoDS_Shape aLocShape = _ShapeReader->GetShape(geom, aSubShape);
1912 for (int j = 1; j <= nbLocal; j++)
1913 if (aLocShape.IsSame(myTopo->_myShapes[shapeType].FindKey(j)))
1915 MESSAGE(" --- trouve = " << j);
1916 myTopo->_mapIndShapes[shapeType][idShape] = j;
1917 fic << " --- trouve = " << j;
1929 * Import a mesh from a file
1930 * @param fileName file name to be imported
1931 * @param fileType Currently it could be either "DAT", "UNV" or "MED".
1933 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Import(CORBA::Long studyId,
1934 const char *fileName, const char *fileType)
1936 MESSAGE("SMESH_Gen_I::Import");
1937 SMESH_Mesh_i *meshServant;
1940 if (_mapStudyContext_i.find(studyId) == _mapStudyContext_i.end())
1942 _mapStudyContext_i[studyId] = new StudyContext_iStruct;
1944 StudyContext_iStruct *myStudyContext = _mapStudyContext_i[studyId];
1946 // create a new mesh object servant, store it in a map in study context
1947 meshServant = new SMESH_Mesh_i(this, NULL, studyId, _localId);
1948 myStudyContext->mapMesh_i[_localId] = meshServant;
1951 // create a new mesh object
1952 meshServant->SetImpl(_impl.Import(studyId, fileName, fileType));
1954 catch(SALOME_Exception & S_ex)
1956 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1959 // activate the CORBA servant of Mesh
1961 SMESH::SMESH_Mesh_var mesh
1962 = SMESH::SMESH_Mesh::_narrow(meshServant->_this());
1964 meshServant->SetIor(mesh);
1965 return SMESH::SMESH_Mesh::_duplicate(mesh);
1968 //=============================================================================
1970 * C factory, accessible with dlsym, after dlopen
1972 //=============================================================================
1976 PortableServer::ObjectId * SMESHEngine_factory(CORBA::ORB_ptr orb,
1977 PortableServer::POA_ptr poa,
1978 PortableServer::ObjectId * contId,
1979 const char *instanceName, const char *interfaceName)
1981 MESSAGE("PortableServer::ObjectId * SMESHEngine_factory()");
1982 SCRUTE(interfaceName);
1983 SMESH_Gen_i *mySMESH_Gen
1984 = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
1985 return mySMESH_Gen->getId();