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 for (; itBig->More(); itBig->Next())
454 SALOMEDS::SObject_var gotBranch = itBig->Value();
456 //************branch 1 : hypothesis
457 if (gotBranch->Tag() == Tag_HypothesisRoot)
458 { //hypothesis = tag 1
460 double length, maxElementsArea, maxElementsVolume;
461 int numberOfSegments;
463 destFile = fopen(hypofile.ToCString(), "w");
464 it = Study->NewChildIterator(gotBranch);
465 for (; it->More(); it->Next())
467 mySObject = it->Value();
468 SALOMEDS::GenericAttribute_var anAttr;
469 SALOMEDS::AttributeIOR_var anIOR;
470 if (mySObject->FindAttribute(anAttr, "AttributeIOR"))
472 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
474 SMESH::SMESH_Hypothesis_var myHyp =
475 SMESH::SMESH_Hypothesis::_narrow(_orb->
476 string_to_object(anIOR->Value()));
477 fprintf(destFile, "%s\n", myHyp->GetName());
479 if (strcmp(myHyp->GetName(), "LocalLength") == 0)
481 SMESH::SMESH_LocalLength_var LL =
482 SMESH::SMESH_LocalLength::_narrow(myHyp);
483 length = LL->GetLength();
484 fprintf(destFile, "%f\n", length);
486 else if (strcmp(myHyp->GetName(), "NumberOfSegments") == 0)
488 SMESH::SMESH_NumberOfSegments_var NOS =
489 SMESH::SMESH_NumberOfSegments::_narrow(myHyp);
490 numberOfSegments = NOS->GetNumberOfSegments();
491 fprintf(destFile, "%d\n", numberOfSegments);
493 else if (strcmp(myHyp->GetName(), "MaxElementArea") == 0)
495 SMESH::SMESH_MaxElementArea_var MEA =
496 SMESH::SMESH_MaxElementArea::_narrow(myHyp);
497 maxElementsArea = MEA->GetMaxElementArea();
498 fprintf(destFile, "%f\n", maxElementsArea);
500 else if (strcmp(myHyp->GetName(), "MaxElementVolume") == 0)
502 SMESH::SMESH_MaxElementVolume_var MEV =
503 SMESH::SMESH_MaxElementVolume::_narrow(myHyp);
504 maxElementsVolume = MEV->GetMaxElementVolume();
505 fprintf(destFile, "%f\n", maxElementsVolume);
511 //writes the file name in the hdf file
512 longueur = hypofile.Length() + 1;
513 name_group = "Hypothesis";
514 //SCRUTE(name_group);
517 hdf_group[1] = new HDFgroup(name_group, hdf_file);
518 hdf_group[1]->CreateOnDisk();
520 hdf_dataset[cmpt_ds] =
521 new HDFdataset(name_group, hdf_group[1], HDF_STRING, size, 1);
522 hdf_dataset[cmpt_ds]->CreateOnDisk();
523 hdf_dataset[cmpt_ds]->WriteOnDisk(hypofile.ToCString());
524 hdf_dataset[cmpt_ds]->CloseOnDisk();
527 hdf_group[1]->CloseOnDisk();
528 MESSAGE("End of Hypothesis Save");
531 //************branch 2 : algorithms
532 else if (gotBranch->Tag() == Tag_AlgorithmsRoot)
535 destFile = fopen(algofile.ToCString(), "w");
536 it = Study->NewChildIterator(gotBranch);
537 for (; it->More(); it->Next())
539 mySObject = it->Value();
540 SALOMEDS::GenericAttribute_var anAttr;
541 SALOMEDS::AttributeIOR_var anIOR;
542 if (mySObject->FindAttribute(anAttr, "AttributeIOR"))
544 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
545 SMESH::SMESH_Algo_var myAlgo =
546 SMESH::SMESH_Algo::_narrow(_orb->
547 string_to_object(anIOR->Value()));
548 fprintf(destFile, "%s\n", myAlgo->GetName());
554 //writes the file name in the hdf file
555 longueur = algofile.Length() + 1;
556 name_group = "Algorithms";
557 //SCRUTE(name_group);
560 hdf_group[2] = new HDFgroup(name_group, hdf_file);
561 hdf_group[2]->CreateOnDisk();
563 hdf_dataset[cmpt_ds] =
564 new HDFdataset(name_group, hdf_group[2], HDF_STRING, size, 1);
565 hdf_dataset[cmpt_ds]->CreateOnDisk();
566 hdf_dataset[cmpt_ds]->WriteOnDisk(algofile.ToCString());
567 hdf_dataset[cmpt_ds]->CloseOnDisk();
570 hdf_group[2]->CloseOnDisk();
571 MESSAGE("End of Algos Save");
574 //************branch 3 : meshes
575 else if (gotBranch->Tag() >= 3)
578 SALOMEDS::GenericAttribute_var anAttr;
579 SALOMEDS::AttributeIOR_var anIOR;
580 if (gotBranch->FindAttribute(anAttr, "AttributeIOR"))
582 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
584 SMESH::SMESH_Mesh_var myMesh =
585 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->
587 studyId = myMesh->GetStudyId();
590 StudyContext_iStruct *myStudyContext =
591 _mapStudyContext_i[studyId];
592 int meshId = myMesh->GetId();
593 SMESH_Mesh_i *meshServant = myStudyContext->mapMesh_i[meshId];
594 ::SMESH_Mesh & myLocMesh = meshServant->GetImpl();
595 SMESHDS_Mesh *mySMESHDSMesh = myLocMesh.GetMeshDS();
597 SCRUTE(mySMESHDSMesh->NbNodes());
598 if (mySMESHDSMesh->NbNodes() > 0)
600 //checks if the mesh is not empty
601 Mesh_Writer *myWriter = SMESHDriver::GetMeshWriter("MED");
602 myWriter->SetFile(meshfile.ToCString());
603 myWriter->SetMesh(mySMESHDSMesh);
604 myWriter->SetMeshId(gotBranch->Tag());
608 meshfile = "No data";
610 //********** opening of the HDF group
611 sprintf(name_meshgroup, "Mesh %d", gotBranch->Tag());
612 SCRUTE(name_meshgroup);
613 hdf_group[gotBranch->Tag()] =
614 new HDFgroup(name_meshgroup, hdf_file);
615 hdf_group[gotBranch->Tag()]->CreateOnDisk();
618 //********** file where the data are stored
619 longueur = strlen(meshfile.ToCString()) + 1;
621 strcpy(name_dataset, "Mesh data");
622 hdf_dataset[cmpt_ds] =
623 new HDFdataset(name_dataset, hdf_group[gotBranch->Tag()],
624 HDF_STRING, size, 1);
625 hdf_dataset[cmpt_ds]->CreateOnDisk();
626 hdf_dataset[cmpt_ds]->WriteOnDisk(meshfile.ToCString());
627 hdf_dataset[cmpt_ds]->CloseOnDisk();
631 //********** ref on shape
632 Standard_CString myRefOnObject = "";
633 SALOMEDS::SObject_var myRef, myShape;
634 _found = gotBranch->FindSubObject(Tag_RefOnShape, myRef);
637 ok = myRef->ReferencedObject(myShape);
638 myRefOnObject = myShape->GetID();
639 SCRUTE(myRefOnObject);
641 longueur = strlen(myRefOnObject) + 1;
645 strcpy(name_dataset, "Ref on shape");
646 hdf_dataset[cmpt_ds] =
647 new HDFdataset(name_dataset,
648 hdf_group[gotBranch->Tag()], HDF_STRING, size, 1);
649 hdf_dataset[cmpt_ds]->CreateOnDisk();
650 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
651 hdf_dataset[cmpt_ds]->CloseOnDisk();
658 //********** ref on applied hypothesis
660 gotBranch->FindSubObject(Tag_RefOnAppliedHypothesis,
665 strcpy(name_meshgroup, "Applied Hypothesis");
666 hdf_subgroup[Tag_RefOnAppliedHypothesis] =
667 new HDFgroup(name_meshgroup,
668 hdf_group[gotBranch->Tag()]);
669 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CreateOnDisk();
671 it = Study->NewChildIterator(myBranch);
673 for (; it->More(); it->Next())
675 mySObject = it->Value();
676 ok = mySObject->ReferencedObject(myRef);
677 myRefOnObject = myRef->GetID();
679 longueur = strlen(myRefOnObject) + 1;
683 sprintf(name_dataset, "Hyp %d", cmpt_it);
684 hdf_dataset[cmpt_ds] =
685 new HDFdataset(name_dataset,
686 hdf_subgroup[Tag_RefOnAppliedHypothesis],
687 HDF_STRING, size, 1);
688 hdf_dataset[cmpt_ds]->CreateOnDisk();
689 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
690 hdf_dataset[cmpt_ds]->CloseOnDisk();
695 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CloseOnDisk();
699 //********** ref on applied algorithms
701 gotBranch->FindSubObject(Tag_RefOnAppliedAlgorithms,
706 strcpy(name_meshgroup, "Applied Algorithms");
707 hdf_subgroup[Tag_RefOnAppliedAlgorithms] =
708 new HDFgroup(name_meshgroup,
709 hdf_group[gotBranch->Tag()]);
710 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CreateOnDisk();
712 it = Study->NewChildIterator(myBranch);
714 for (; it->More(); it->Next())
716 mySObject = it->Value();
717 ok = mySObject->ReferencedObject(myRef);
718 myRefOnObject = myRef->GetID();
720 longueur = strlen(myRefOnObject) + 1;
724 sprintf(name_dataset, "Algo %d", cmpt_it);
725 hdf_dataset[cmpt_ds] =
726 new HDFdataset(name_dataset,
727 hdf_subgroup[Tag_RefOnAppliedAlgorithms],
728 HDF_STRING, size, 1);
729 hdf_dataset[cmpt_ds]->CreateOnDisk();
730 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
731 hdf_dataset[cmpt_ds]->CloseOnDisk();
736 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CloseOnDisk();
738 MESSAGE("end of algo applied");
741 //********** submeshes on subshapes
743 for (int i = Tag_SubMeshOnVertex; i <= Tag_SubMeshOnCompound;
746 _found = gotBranch->FindSubObject(i, myBranch);
749 if (i == Tag_SubMeshOnVertex)
750 strcpy(name_meshgroup, "SubMeshes On Vertex");
751 else if (i == Tag_SubMeshOnEdge)
752 strcpy(name_meshgroup, "SubMeshes On Edge");
753 else if (i == Tag_SubMeshOnFace)
754 strcpy(name_meshgroup, "SubMeshes On Face");
755 else if (i == Tag_SubMeshOnSolid)
756 strcpy(name_meshgroup, "SubMeshes On Solid");
757 else if (i == Tag_SubMeshOnCompound)
758 strcpy(name_meshgroup, "SubMeshes On Compound");
761 myLevel1Tag = 10 + cmpt_sm;
762 hdf_subgroup[myLevel1Tag] =
763 new HDFgroup(name_meshgroup,
764 hdf_group[gotBranch->Tag()]);
765 hdf_subgroup[myLevel1Tag]->CreateOnDisk();
767 itSM = Study->NewChildIterator(myBranch);
768 for (; itSM->More(); itSM->Next())
769 { //Loop on all submeshes
770 mySObject = itSM->Value();
772 myTag = 10 + cmpt_sm;
773 mySObject->FindAttribute(anAttr, "AttributeIOR");
774 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
775 SMESH::SMESH_subMesh_var mySubMesh =
776 SMESH::SMESH_subMesh::_narrow(_orb->
777 string_to_object(anIOR->Value()));
779 //sprintf(name_meshgroup,"SubMesh %d",myTag);
780 sprintf(name_meshgroup, "SubMesh %ld",
782 SCRUTE(name_meshgroup);
784 hdf_subgroup[myTag] =
785 new HDFgroup(name_meshgroup,
786 hdf_subgroup[myLevel1Tag]);
787 hdf_subgroup[myTag]->CreateOnDisk();
789 //********** ref on shape
790 Standard_CString myRefOnObject = "";
791 SALOMEDS::SObject_var myRef, myShape;
794 mySObject->FindSubObject(Tag_RefOnShape, myRef);
797 ok = myRef->ReferencedObject(myShape);
798 myRefOnObject = myShape->GetID();
799 SCRUTE(myRefOnObject);
801 longueur = strlen(myRefOnObject) + 1;
805 strcpy(name_dataset, "Ref on shape");
806 hdf_dataset[cmpt_ds] =
807 new HDFdataset(name_dataset,
808 hdf_subgroup[myTag], HDF_STRING, size,
810 hdf_dataset[cmpt_ds]->CreateOnDisk();
811 hdf_dataset[cmpt_ds]->
812 WriteOnDisk(myRefOnObject);
813 hdf_dataset[cmpt_ds]->CloseOnDisk();
819 //********** ref on applied hypothesis
822 FindSubObject(Tag_RefOnAppliedHypothesis,
827 strcpy(name_meshgroup, "Applied Hypothesis");
829 hdf_subgroup[10 + cmpt_sm] =
830 new HDFgroup(name_meshgroup,
831 hdf_subgroup[myTag]);
832 hdf_subgroup[10 + cmpt_sm]->CreateOnDisk();
834 it = Study->NewChildIterator(myBranch);
836 for (; it->More(); it->Next())
838 mySObjectChild = it->Value();
839 ok = mySObjectChild->
840 ReferencedObject(myRef);
841 myRefOnObject = myRef->GetID();
843 longueur = strlen(myRefOnObject) + 1;
847 sprintf(name_dataset, "Hyp %d",
850 hdf_dataset[cmpt_ds] =
851 new HDFdataset(name_dataset,
852 hdf_subgroup[10 + cmpt_sm],
853 HDF_STRING, size, 1);
854 hdf_dataset[cmpt_ds]->CreateOnDisk();
855 hdf_dataset[cmpt_ds]->
856 WriteOnDisk(myRefOnObject);
857 hdf_dataset[cmpt_ds]->CloseOnDisk();
862 hdf_subgroup[10 + cmpt_sm]->CloseOnDisk();
866 //********** ref on applied algorithms
869 FindSubObject(Tag_RefOnAppliedAlgorithms,
875 strcpy(name_meshgroup, "Applied Algorithms");
877 hdf_subgroup[10 + cmpt_sm] =
878 new HDFgroup(name_meshgroup,
879 hdf_subgroup[myTag]);
880 hdf_subgroup[10 + cmpt_sm]->CreateOnDisk();
882 it = Study->NewChildIterator(myBranch);
884 for (; it->More(); it->Next())
886 mySObjectChild = it->Value();
887 ok = mySObjectChild->
888 ReferencedObject(myRef);
889 myRefOnObject = myRef->GetID();
891 longueur = strlen(myRefOnObject) + 1;
895 sprintf(name_dataset, "Algo %d",
897 hdf_dataset[cmpt_ds] =
898 new HDFdataset(name_dataset,
899 hdf_subgroup[10 + cmpt_sm],
900 HDF_STRING, size, 1);
901 hdf_dataset[cmpt_ds]->CreateOnDisk();
902 hdf_dataset[cmpt_ds]->
903 WriteOnDisk(myRefOnObject);
904 hdf_dataset[cmpt_ds]->CloseOnDisk();
909 hdf_subgroup[10 + cmpt_sm]->CloseOnDisk();
911 //MESSAGE("end of algo applied");
914 hdf_subgroup[myTag]->CloseOnDisk();
917 hdf_subgroup[myLevel1Tag]->CloseOnDisk();
923 //********** closing of the HDF group
924 hdf_group[gotBranch->Tag()]->CloseOnDisk();
925 MESSAGE("End of Mesh Save");
929 MESSAGE("End of Meshes Save");
932 hdf_file->CloseOnDisk();
936 // Convert temporary files to stream
938 SALOMEDS_Tool::PutFilesToStream(tmpDir.ToCString(), aFileSeq.in(),
941 // Remove temporary files and directory
943 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(),
946 MESSAGE("End SMESH_Gen_i::Save");
948 return aStreamFile._retn();
952 SMESH_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
953 const char *theURL, bool isMultiFile)
955 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
956 return aStreamFile._retn();
959 void SMESH_Gen_i::loadHypothesis(char * name, HDFfile * hdf_file,
960 char * hypofile, int studyId)
962 char name_of_group[HDF_NAME_MAX_LEN + 1];
964 double length, maxElementsArea, maxElementsVolume;
965 int numberOfSegments;
967 HDFgroup * hdfGroup = new HDFgroup(name, hdf_file);
968 hdfGroup->OpenOnDisk();
970 hdfGroup->InternalObjectIndentify(0, name_of_group);
971 HDFdataset * dataset = new HDFdataset(name_of_group, hdfGroup);
972 dataset->OpenOnDisk();
973 char *name_of_file = new char[dataset->GetSize()];
974 dataset->ReadFromDisk(name_of_file);
975 SCRUTE(name_of_file);
976 dataset->CloseOnDisk();
977 hdfGroup->CloseOnDisk();
978 delete[]name_of_file;
980 char * aLine = new char[100];
981 FILE * loadedFile = fopen(hypofile, "r");
982 while (!feof(loadedFile))
984 fscanf(loadedFile, "%s", aLine);
986 if (strcmp(aLine, "LocalLength") == 0)
988 SMESH::SMESH_Hypothesis_var myHyp =
989 this->CreateHypothesis(aLine, studyId);
990 SMESH::SMESH_LocalLength_var LL =
991 SMESH::SMESH_LocalLength::_narrow(myHyp);
992 fscanf(loadedFile, "%s", aLine);
993 length = atof(aLine);
994 LL->SetLength(length);
995 string iorString = _orb->object_to_string(LL);
996 sprintf(objectId, "%ld", LL->GetId());
997 _SMESHCorbaObj[string("Hypo_") + string(objectId)] =
1000 else if (strcmp(aLine, "NumberOfSegments") == 0)
1002 SMESH::SMESH_Hypothesis_var myHyp =
1003 this->CreateHypothesis(aLine, studyId);
1004 SMESH::SMESH_NumberOfSegments_var NOS =
1005 SMESH::SMESH_NumberOfSegments::_narrow(myHyp);
1006 fscanf(loadedFile, "%s", aLine);
1007 numberOfSegments = atoi(aLine);
1008 NOS->SetNumberOfSegments(numberOfSegments);
1009 string iorString = _orb->object_to_string(NOS);
1010 sprintf(objectId, "%ld", NOS->GetId());
1011 _SMESHCorbaObj[string("Hypo_") + string(objectId)] =
1014 else if (strcmp(aLine, "MaxElementArea") == 0)
1016 SMESH::SMESH_Hypothesis_var myHyp =
1017 this->CreateHypothesis(aLine, studyId);
1018 SMESH::SMESH_MaxElementArea_var MEA =
1019 SMESH::SMESH_MaxElementArea::_narrow(myHyp);
1020 fscanf(loadedFile, "%s", aLine);
1021 maxElementsArea = atof(aLine);
1022 MEA->SetMaxElementArea(maxElementsArea);
1023 string iorString = _orb->object_to_string(MEA);
1024 sprintf(objectId, "%ld", MEA->GetId());
1025 _SMESHCorbaObj[string("Hypo_") + string(objectId)] =
1028 else if (strcmp(aLine, "MaxElementVolume") == 0)
1030 SMESH::SMESH_Hypothesis_var myHyp =
1031 this->CreateHypothesis(aLine, studyId);
1032 SMESH::SMESH_MaxElementVolume_var MEV =
1033 SMESH::SMESH_MaxElementVolume::_narrow(myHyp);
1034 fscanf(loadedFile, "%s", aLine);
1035 maxElementsVolume = atof(aLine);
1036 MEV->SetMaxElementVolume(maxElementsVolume);
1037 string iorString = _orb->object_to_string(MEV);
1038 sprintf(objectId, "%ld", MEV->GetId());
1039 _SMESHCorbaObj[string("Hypo_") + string(objectId)] =
1046 MESSAGE("End of Hypos Load");
1049 void SMESH_Gen_i::loadAlgorithms(char * name, HDFfile * hdf_file,
1050 char* algofile, int studyId)
1052 char name_of_group[HDF_NAME_MAX_LEN + 1];
1054 HDFgroup * hdfGroup = new HDFgroup(name, hdf_file);
1055 hdfGroup->OpenOnDisk();
1057 hdfGroup->InternalObjectIndentify(0, name_of_group);
1058 HDFdataset * dataset =
1059 new HDFdataset(name_of_group, hdfGroup);
1060 dataset->OpenOnDisk();
1062 char *name_of_file = new char[dataset->GetSize()];
1063 dataset->ReadFromDisk(name_of_file);
1064 dataset->CloseOnDisk();
1065 hdfGroup->CloseOnDisk();
1066 delete[]name_of_file;
1068 char * aLine = new char[100];
1069 FILE * loadedFile = fopen(algofile, "r");
1070 while (!feof(loadedFile))
1072 fscanf(loadedFile, "%s\n", aLine);
1074 if (strcmp(aLine, "") != 0)
1076 SMESH::SMESH_Hypothesis_var myHyp =
1077 this->CreateHypothesis(aLine, studyId);
1078 SMESH::SMESH_Algo_var myAlgo =
1079 SMESH::SMESH_Algo::_narrow(myHyp);
1080 string iorString = _orb->object_to_string(myAlgo);
1081 sprintf(objectId, "%ld", myAlgo->GetId());
1082 _SMESHCorbaObj[string("Hypo_") + string(objectId)] =
1089 MESSAGE("End of Algos Load");
1093 * @param hdfGroupMeshId The group where to read the hypothesis
1095 * @param Study The study where to create the hypothesis
1096 * @param myNewMesh The mesh on which the hypothesis is applied
1097 * @param aShape The shape with which this mesh is linked
1099 void SMESH_Gen_i::loadAppliedHypothesis(HDFgroup * hdfGroupMeshId,
1100 bool _found, SALOMEDS::Study_var Study, SMESH::SMESH_Mesh_var myNewMesh,
1101 GEOM::GEOM_Shape_var aShape)
1103 HDFgroup * hdf_subgroup = new HDFgroup("Applied Hypothesis", hdfGroupMeshId);
1104 hdf_subgroup->OpenOnDisk();
1105 int nb_datasets = hdf_subgroup->nInternalObjects();
1106 char name_dataset[10];
1108 for (int j = 0; j < nb_datasets; j++)
1110 sprintf(name_dataset, "Hyp %d", j);
1111 HDFdataset * hdf_dataset = new HDFdataset(name_dataset, hdf_subgroup);
1112 hdf_dataset->OpenOnDisk();
1114 char *refFromFile = new char[hdf_dataset->GetSize()];
1115 hdf_dataset->ReadFromDisk(refFromFile);
1116 hdf_dataset->CloseOnDisk();
1121 SALOMEDS::SObject_var HypSO =
1122 Study->FindObjectID(refFromFile);
1123 if (!CORBA::is_nil(HypSO))
1125 SALOMEDS::GenericAttribute_var anAttr;
1126 HypSO->FindAttribute(anAttr, "AttributeIOR");
1127 SALOMEDS::AttributeIOR_var anIOR =
1128 SALOMEDS::AttributeIOR::_narrow(anAttr);
1129 if (!CORBA::is_nil(anIOR))
1131 char *HypIOR = anIOR->Value();
1132 SMESH::SMESH_Hypothesis_var anHyp =
1133 SMESH::SMESH_Hypothesis::_narrow(_orb->
1134 string_to_object(HypIOR));
1135 if (!CORBA::is_nil(anHyp))
1137 myNewMesh->AddHypothesis(aShape, anHyp);
1138 MESSAGE("Hypothesis added ...");
1144 hdf_subgroup->CloseOnDisk();
1148 * @param hdfGroupMeshId The group where to read the hypothesis
1150 * @param Study The study where to create the hypothesis
1151 * @param myNewMesh The mesh on which the hypothesis is applied
1152 * @param aShape The shape with which this mesh is linked
1154 void SMESH_Gen_i::loadAppliedAlgorithms(HDFgroup * hdfGroupMeshId,
1155 bool _found, SALOMEDS::Study_var Study, SMESH::SMESH_Mesh_var myNewMesh,
1156 GEOM::GEOM_Shape_var aShape)
1158 HDFgroup * hdf_subgroup = new HDFgroup("Applied Algorithms", hdfGroupMeshId);
1159 hdf_subgroup->OpenOnDisk();
1161 int nb_datasets = hdf_subgroup->nInternalObjects();
1162 SCRUTE(nb_datasets);
1163 char name_dataset[10];
1165 for (int j = 0; j < nb_datasets; j++)
1167 sprintf(name_dataset, "Algo %d", j);
1168 HDFdataset * dataset =
1169 new HDFdataset(name_dataset, hdf_subgroup);
1170 dataset->OpenOnDisk();
1172 char *refFromFile = new char[dataset->GetSize()];
1173 dataset->ReadFromDisk(refFromFile);
1174 dataset->CloseOnDisk();
1179 SALOMEDS::SObject_var AlgoSO =
1180 Study->FindObjectID(refFromFile);
1181 if (!CORBA::is_nil(AlgoSO))
1183 SALOMEDS::GenericAttribute_var anAttr;
1184 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1185 SALOMEDS::AttributeIOR_var anIOR =
1186 SALOMEDS::AttributeIOR::_narrow(anAttr);
1187 if (!CORBA::is_nil(anIOR))
1189 char *AlgoIOR = anIOR->Value();
1191 SMESH::SMESH_Hypothesis_var myHyp =
1192 SMESH::SMESH_Hypothesis::_narrow(_orb->
1193 string_to_object(AlgoIOR));
1194 SMESH::SMESH_Algo_var anAlgo =
1195 SMESH::SMESH_Algo::_narrow(myHyp);
1197 if (!CORBA::is_nil(anAlgo))
1199 myNewMesh->AddHypothesis(aShape, anAlgo); //essayer avec _SMESHCorbaObj
1200 MESSAGE("Algorithms added ...");
1206 hdf_subgroup->CloseOnDisk();
1210 * @param hdfGroupMeshId The group where to read the hypothesis
1211 * @param msgname ???
1212 * @param Study The study where to create the hypothesis
1213 * @param myNewMesh The mesh on which the hypothesis is applied
1215 void SMESH_Gen_i::loadSubMeshes(HDFgroup * hdfGroupMeshId, char * msgname,
1216 SALOMEDS::Study_var Study, SMESH::SMESH_Mesh_var myNewMesh)
1218 MESSAGE("SMESH_Gen_i::loadSubMeshes");
1219 HDFgroup * hdf_subgroupmyLevel1Tag = new HDFgroup(msgname, hdfGroupMeshId);
1220 hdf_subgroupmyLevel1Tag->OpenOnDisk();
1222 int nb_submeshes = hdf_subgroupmyLevel1Tag->nInternalObjects();
1223 char name_meshgroup[30];
1224 //SCRUTE(nb_submeshes);
1226 for (int j = 0; j < nb_submeshes; j++)
1229 //myTag = 10 + cmpt_sm;
1230 hdf_subgroupmyLevel1Tag->InternalObjectIndentify(j, name_meshgroup);
1232 HDFgroup * hdf_subgroupmyTag = new HDFgroup(name_meshgroup,
1233 hdf_subgroupmyLevel1Tag);
1234 hdf_subgroupmyTag->OpenOnDisk();
1235 int subMeshId = atoi((string(name_meshgroup).substr(8, 18)).c_str());
1237 MESSAGE("Ref on shape");
1238 //********** ref on shape
1239 HDFdataset * hdf_dataset =
1240 new HDFdataset("Ref on shape", hdf_subgroupmyTag);
1241 hdf_dataset->OpenOnDisk();
1243 char *refFromFile = new char[hdf_dataset->GetSize()];
1244 hdf_dataset->ReadFromDisk(refFromFile);
1245 hdf_dataset->CloseOnDisk();
1248 bool _found3 = false;
1249 SALOMEDS::SObject_var GSO = Study->FindObjectID(refFromFile);
1250 SMESH::SMESH_subMesh_var aSubMesh;
1251 GEOM::GEOM_Shape_var aSubShape;
1253 if (!CORBA::is_nil(GSO))
1255 SALOMEDS::GenericAttribute_var anAttr;
1256 GSO->FindAttribute(anAttr, "AttributeIOR");
1257 SALOMEDS::AttributeIOR_var anIOR =
1258 SALOMEDS::AttributeIOR::_narrow(anAttr);
1260 char *SubShapeIOR = anIOR->Value();
1262 GEOM::GEOM_Shape::_narrow(_orb-> string_to_object(SubShapeIOR));
1264 if (!CORBA::is_nil(aSubShape))
1266 aSubMesh = myNewMesh->GetElementsOnShape(aSubShape);
1267 string iorString = _orb->object_to_string(aSubMesh);
1269 sprintf(objectId, "%d", subMeshId);
1270 _SMESHCorbaObj[string("SubMesh_") + string(objectId)] =
1276 int nb_subgroup = hdf_subgroupmyTag->nInternalObjects();
1277 SCRUTE(nb_subgroup);
1278 char sgname[HDF_NAME_MAX_LEN + 1];
1279 for (int k = 0; k < nb_subgroup; k++)
1281 hdf_subgroupmyTag->InternalObjectIndentify(k, sgname);
1282 if (strcmp(sgname, "Ref on shape") == 0)
1286 else if (strcmp(sgname, "Applied Hypothesis") == 0)
1288 //********** ref on applied hypothesis
1289 MESSAGE("Applied Hypothesis");
1290 strcpy(name_meshgroup, "Applied Hypothesis");
1292 HDFgroup * hdf_subgroup10cmpt_sm = new HDFgroup(name_meshgroup,
1295 hdf_subgroup10cmpt_sm->OpenOnDisk();
1296 int nb_datasets = hdf_subgroup10cmpt_sm->nInternalObjects();
1297 // SCRUTE(nb_datasets);
1299 char name_dataset[30];
1300 for (int l = 0; l < nb_datasets; l++)
1302 sprintf(name_dataset, "Hyp %d", l);
1303 HDFdataset * hdf_datasetcmpt_ds =
1304 new HDFdataset(name_dataset, hdf_subgroup10cmpt_sm);
1305 hdf_datasetcmpt_ds->OpenOnDisk();
1306 int size = hdf_datasetcmpt_ds->GetSize();
1308 char *refFromFile = new char[size];
1309 hdf_datasetcmpt_ds->ReadFromDisk(refFromFile);
1310 hdf_datasetcmpt_ds->CloseOnDisk();
1315 SALOMEDS::SObject_var HypSO =
1316 Study->FindObjectID(refFromFile);
1317 if (!CORBA::is_nil(HypSO))
1319 SALOMEDS::GenericAttribute_var anAttr;
1320 SALOMEDS::AttributeIOR_var anIOR;
1321 HypSO->FindAttribute(anAttr, "AttributeIOR");
1322 anIOR = SALOMEDS::AttributeIOR:: _narrow(anAttr);
1323 if (!CORBA::is_nil(anIOR))
1325 char *HypIOR = anIOR->Value();
1326 SMESH::SMESH_Hypothesis_var anHyp =
1327 SMESH::SMESH_Hypothesis::_narrow(_orb->
1328 string_to_object(HypIOR));
1329 if (!CORBA::is_nil(anHyp))
1331 SMESH::SMESH_Mesh_var aMesh =
1332 aSubMesh->GetFather();
1333 aMesh->AddHypothesis(aSubShape, anHyp); //essayer avec _SMESHCorbaObj
1334 MESSAGE("Hypothesis added ...");
1341 else if (strcmp(sgname, "Applied Algorithms") == 0)
1343 //********** ref on applied algorithms
1344 MESSAGE("Applied Algorithms");
1345 strcpy(name_meshgroup, "Applied Algorithms");
1347 HDFgroup * hdf_subgroup10cmpt_sm = new HDFgroup(name_meshgroup,
1349 hdf_subgroup10cmpt_sm->OpenOnDisk();
1350 int nb_datasets = hdf_subgroup10cmpt_sm->nInternalObjects();
1351 SCRUTE(nb_datasets);
1353 char name_dataset[30];
1354 for (int l = 0; l < nb_datasets; l++)
1356 sprintf(name_dataset, "Algo %d", l);
1357 HDFdataset * hdf_datasetcmpt_ds = new HDFdataset(
1358 name_dataset, hdf_subgroup10cmpt_sm);
1359 hdf_datasetcmpt_ds->OpenOnDisk();
1360 int size = hdf_datasetcmpt_ds->GetSize();
1362 char *refFromFile = new char[size];
1363 hdf_datasetcmpt_ds->ReadFromDisk(refFromFile);
1364 hdf_datasetcmpt_ds->CloseOnDisk();
1365 delete hdf_datasetcmpt_ds;
1370 SALOMEDS::SObject_var AlgoSO =
1371 Study->FindObjectID(refFromFile);
1372 if (!CORBA::is_nil(AlgoSO))
1374 SALOMEDS::GenericAttribute_var anAttr;
1375 SALOMEDS::AttributeIOR_var anIOR;
1376 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1377 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1378 if (!CORBA::is_nil(anIOR))
1380 char *AlgoIOR = anIOR->Value();
1382 SMESH::SMESH_Hypothesis_var myHyp =
1383 SMESH::SMESH_Hypothesis::_narrow(_orb->
1384 string_to_object(AlgoIOR));
1385 SMESH::SMESH_Algo_var anAlgo =
1386 SMESH::SMESH_Algo::_narrow(myHyp);
1387 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1388 if (!CORBA::is_nil(anAlgo))
1390 SMESH::SMESH_Mesh_var aMesh =
1391 aSubMesh->GetFather();
1392 aMesh->AddHypothesis(aSubShape, anAlgo); //essayer avec _SMESHCorbaObj
1393 MESSAGE("Algorithms added ...");
1401 hdf_subgroupmyTag->CloseOnDisk();
1402 delete hdf_subgroupmyTag;
1404 hdf_subgroupmyLevel1Tag->CloseOnDisk();
1405 delete hdf_subgroupmyLevel1Tag;
1408 GEOM::GEOM_Gen_var SMESH_Gen_i::getGeomEngine()
1410 MESSAGE("SMESH_Gen_i::getGeomEngine");
1411 SALOME_NamingService *_NS = SINGLETON_ < SALOME_NamingService >::Instance();
1412 ASSERT(SINGLETON_ < SALOME_NamingService >::IsAlreadyExisting());
1413 _NS->init_orb(_orb);
1414 SALOME_LifeCycleCORBA *myEnginesLifeCycle = new SALOME_LifeCycleCORBA(_NS);
1415 Engines::Component_var geomEngine =
1416 myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", "GEOM");
1417 GEOM::GEOM_Gen_var myGeomEngine = GEOM::GEOM_Gen::_narrow(geomEngine);
1418 return myGeomEngine;
1421 GEOM::GEOM_Shape_var SMESH_Gen_i::getShape(SALOMEDS::Study_var Study, char * refFromFile)
1423 MESSAGE("SMESH_Gen_i::getShape("<<Study<<","<<refFromFile<<")");
1424 SCRUTE(CORBA::is_nil(Study));
1425 SALOMEDS::SObject_var CSO = Study->FindObjectID(refFromFile);
1426 GEOM::GEOM_Shape_var aShape;
1428 if (!CORBA::is_nil(CSO))
1430 SALOMEDS::GenericAttribute_var anAttr;
1431 CSO->FindAttribute(anAttr, "AttributeIOR");
1432 if (!CORBA::is_nil(CSO))
1434 MESSAGE("The shape was not loaded. Try to load it.");
1435 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(getGeomEngine());
1436 SALOMEDS::SComponent_var SCO = SALOMEDS::SComponent::_narrow(Study->FindObject("Geometry"));
1437 SALOMEDS::StudyBuilder_var B = Study->NewBuilder();
1438 B->LoadWith(SCO,driver);
1439 CSO->FindAttribute(anAttr, "AttributeIOR");
1442 SALOMEDS::AttributeIOR_var anIOR =
1443 SALOMEDS::AttributeIOR::_narrow(anAttr);
1445 char *ShapeIOR = anIOR->Value();
1447 GEOM::GEOM_Shape::_narrow(_orb->string_to_object(ShapeIOR));
1452 void SMESH_Gen_i::loadMesh(char * name, HDFfile * hdf_file,
1453 char* meshfile, SALOMEDS::Study_var Study)
1455 MESSAGE("in mesh load");
1456 char msgname[HDF_NAME_MAX_LEN + 1];
1458 char name_of_group[HDF_NAME_MAX_LEN + 1];
1461 atoi((string(name).substr(5, 5)).c_str());
1464 HDFgroup * hdfGroupMeshId = new HDFgroup(name, hdf_file);
1465 hdfGroupMeshId->OpenOnDisk();
1467 int nb_meshsubgroup = hdfGroupMeshId->nInternalObjects();
1468 SCRUTE(nb_meshsubgroup);
1470 //********** Loading of the file name where the data are stored
1471 MESSAGE("Mesh data file");
1472 strcpy(name_of_group, "Mesh data");
1473 HDFdataset * dataset =
1474 new HDFdataset(name_of_group, hdfGroupMeshId);
1475 dataset->OpenOnDisk();
1477 char *datafilename = new char[dataset->GetSize()];
1478 dataset->ReadFromDisk(datafilename);
1479 dataset->CloseOnDisk();
1481 //********** Loading of the reference on the shape
1482 //********** and mesh initialization
1483 MESSAGE("Ref on shape");
1484 strcpy(name_of_group, "Ref on shape");
1486 new HDFdataset(name_of_group, hdfGroupMeshId);
1487 dataset->OpenOnDisk();
1489 char *refFromFile = new char[dataset->GetSize()];
1490 dataset->ReadFromDisk(refFromFile);
1491 dataset->CloseOnDisk();
1493 bool _found = false;
1494 SCRUTE(refFromFile);
1495 SMESH::SMESH_Mesh_var myNewMesh;
1496 GEOM::GEOM_Shape_var aShape=getShape(Study, refFromFile);
1498 if (!CORBA::is_nil(aShape))
1501 myNewMesh = this->Init(getGeomEngine(), Study->StudyId(), aShape);
1502 string iorString = _orb->object_to_string(myNewMesh);
1503 sprintf(objectId, "%ld", myNewMesh->GetId());
1504 _SMESHCorbaObj[string("Mesh_") + string(objectId)] = iorString;
1506 SCRUTE(datafilename);
1508 //********** Loading of mesh data
1509 if (strcmp(datafilename, "No data") != 0)
1511 StudyContext_iStruct *myStudyContext =
1512 _mapStudyContext_i[Study->StudyId()];
1513 int meshId = myNewMesh->GetId();
1514 SMESH_Mesh_i *meshServant =
1515 myStudyContext->mapMesh_i[meshId];
1516 ::SMESH_Mesh & myLocMesh = meshServant->GetImpl();
1517 SMESHDS_Mesh *mySMESHDSMesh = myLocMesh.GetMeshDS();
1519 Mesh_Reader *myReader = SMESHDriver::GetMeshReader("MED");
1520 myReader->SetMesh(mySMESHDSMesh);
1521 myReader->SetMeshId(myMeshId);
1522 myReader->SetFile(datafilename);
1524 MESSAGE("Loaded a mesh with " << mySMESHDSMesh->NbNodes() <<" nodes");
1529 //else if (strcmp(msgname,"Applied Hypothesis")==0) {
1530 for (int ii = 0; ii < nb_meshsubgroup; ii++)
1532 hdfGroupMeshId->InternalObjectIndentify(ii, msgname);
1533 if (strcmp(msgname, "Mesh data") == 0)
1537 else if (strcmp(msgname, "Ref on shape") == 0)
1541 else if (strcmp(msgname, "Applied Hypothesis") == 0)
1543 loadAppliedHypothesis(hdfGroupMeshId, _found, Study, myNewMesh,
1546 else if (strcmp(msgname, "Applied Algorithms") == 0)
1548 loadAppliedAlgorithms(hdfGroupMeshId, _found, Study, myNewMesh,
1551 else if (string(msgname).substr(0, 9) == string("SubMeshes"))
1553 loadSubMeshes(hdfGroupMeshId, msgname, Study, myNewMesh);
1556 hdfGroupMeshId->CloseOnDisk();
1557 MESSAGE("End of Meshes Load");
1561 * Load the part of the study related to SMESH.
1563 bool SMESH_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
1564 const SALOMEDS::TMPFile & theStream, const char *theURL, bool isMultiFile)
1566 MESSAGE("SMESH_Gen_i::Load");
1567 // Get temporary files location
1568 TCollection_AsciiString tmpDir =
1569 isMultiFile ? TCollection_AsciiString((char *)theURL) : SALOMEDS_Tool::
1572 // Convert the stream into sequence of files to process
1573 SALOMEDS::ListOfFileNames_var aFileSeq =
1574 SALOMEDS_Tool::PutStreamToFiles(theStream, tmpDir.ToCString(),
1577 TCollection_AsciiString aStudyName("");
1580 (SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
1582 // Set names of temporary files
1583 TCollection_AsciiString filename =
1584 tmpDir + aStudyName + TCollection_AsciiString("_SMESH.hdf");
1585 TCollection_AsciiString hypofile =
1586 tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Hypo.txt");
1587 TCollection_AsciiString algofile =
1588 tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Algo.txt");
1589 TCollection_AsciiString meshfile =
1590 tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Mesh.med");
1592 SALOMEDS::Study_var Study = theComponent->GetStudy();
1593 int studyId = Study->StudyId();
1596 SALOMEDS::AttributeName_var aName;
1598 SALOMEDS::SComponent_var fathergeom = Study->FindComponent("GEOM");
1599 SALOMEDS::SComponent_var myGeomSComp =
1600 SALOMEDS::SComponent::_narrow(fathergeom);
1603 char name[HDF_NAME_MAX_LEN + 1];
1604 map < int, HDFgroup * > hdf_subgroup;
1607 //************* HDF file opening
1608 HDFfile *hdf_file = new HDFfile(filename.ToCString());
1611 hdf_file->OpenOnDisk(HDF_RDONLY);
1615 MESSAGE("Load(): " << filename << " not found!");
1619 //****************************
1621 int nb_group = hdf_file->nInternalObjects();
1623 for (int i = 0; i < nb_group; i++)
1625 hdf_file->InternalObjectIndentify(i, name);
1626 if (strcmp(name, "Hypothesis") == 0)
1627 loadHypothesis(name, hdf_file, hypofile.ToCString(), studyId);
1628 else if (strcmp(name, "Algorithms") == 0)
1629 loadAlgorithms(name, hdf_file, algofile.ToCString(), studyId);
1630 else if (string(name).substr(0, 4) == string("Mesh"))
1631 loadMesh(name, hdf_file, meshfile.ToCString(), Study);
1634 MESSAGE("End of SMESH_Gen::Load");
1636 hdf_file->CloseOnDisk();
1638 // Remove temporary files created from the stream
1640 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(),
1646 bool SMESH_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
1647 const SALOMEDS::TMPFile & theStream, const char *theURL, bool isMultiFile)
1649 return Load(theComponent, theStream, theURL, isMultiFile);
1652 //=============================================================================
1656 //=============================================================================
1658 void SMESH_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
1661 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
1662 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
1663 for (; itBig->More(); itBig->Next())
1665 SALOMEDS::SObject_var gotBranch = itBig->Value();
1667 // branch 1 : hypothesis
1668 if (gotBranch->Tag() == Tag_HypothesisRoot ||
1669 gotBranch->Tag() == Tag_AlgorithmsRoot)
1671 SALOMEDS::ChildIterator_var it =
1672 aStudy->NewChildIterator(gotBranch);
1673 for (; it->More(); it->Next())
1675 SALOMEDS::SObject_var mySObject = it->Value();
1676 SALOMEDS::GenericAttribute_var anAttr;
1677 SALOMEDS::AttributeIOR_var anIOR;
1678 if (mySObject->FindAttribute(anAttr, "AttributeIOR"))
1680 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1681 SMESH::SMESH_Hypothesis_var myHyp =
1682 SMESH::SMESH_Hypothesis::_narrow(_orb->
1683 string_to_object(anIOR->Value()));
1685 sprintf(objectId, "%ld", myHyp->GetId());
1686 // cout<<"********** delete Hyp "<<objectId<<endl;
1687 _SMESHCorbaObj.erase(string("Hypo_") + string(objectId));
1689 SMESH::SMESH_Hypothesis::_narrow(_orb->
1690 string_to_object(anIOR->Value()));
1694 // branch 2 : algorithms
1695 else if (gotBranch->Tag() >= 3)
1697 SALOMEDS::ChildIterator_var it =
1698 aStudy->NewChildIterator(gotBranch);
1699 for (; it->More(); it->Next())
1701 SALOMEDS::SObject_var mySObject = it->Value();
1702 SALOMEDS::GenericAttribute_var anAttr;
1703 SALOMEDS::AttributeIOR_var anIOR;
1704 if (mySObject->FindAttribute(anAttr, "AttributeIOR"))
1706 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1707 SMESH::SMESH_Mesh_var myMesh =
1708 SMESH::SMESH_Mesh::_narrow(_orb->
1709 string_to_object(anIOR->Value()));
1710 if (!myMesh->_is_nil())
1713 sprintf(objectId, "%ld", myMesh->GetId());
1714 // cout<<"********** delete Mesh "<<objectId<<endl;
1715 _SMESHCorbaObj.erase(string("Mesh_") +
1717 CORBA::release(myMesh);
1721 SMESH::SMESH_subMesh_var mySubMesh =
1722 SMESH::SMESH_subMesh::_narrow(_orb->
1723 string_to_object(anIOR->Value()));
1724 if (!mySubMesh->_is_nil())
1727 sprintf(objectId, "%ld", mySubMesh->GetId());
1728 // cout<<"********** delete SubMesh "<<objectId<<endl;
1729 _SMESHCorbaObj.erase(string("SubMesh_") +
1731 CORBA::release(mySubMesh);
1740 //=============================================================================
1744 //=============================================================================
1746 char *SMESH_Gen_i::ComponentDataType()
1748 MESSAGE("SMESH_Gen_i::ComponentDataType");
1749 return strdup("SMESH");
1752 //=============================================================================
1756 //=============================================================================
1758 char *SMESH_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
1759 const char *IORString, CORBA::Boolean isMultiFile, CORBA::Boolean isASCII)
1761 MESSAGE("SMESH_Gen_i::IORToLocalPersistentID");
1765 SMESH::SMESH_Algo_var myAlgo =
1766 SMESH::SMESH_Algo::_narrow(_orb->string_to_object(IORString));
1767 if (!CORBA::is_nil(myAlgo))
1769 string prefix = "Hypo_";
1770 sprintf(objectId, "%ld", myAlgo->GetId());
1771 string lpID = prefix + string(objectId);
1772 return CORBA::string_dup(lpID.c_str());
1776 SMESH::SMESH_Hypothesis_var myHypo =
1777 SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(IORString));
1778 if (!CORBA::is_nil(myHypo))
1780 string prefix = "Hypo_";
1781 sprintf(objectId, "%ld", myHypo->GetId());
1782 string lpID = prefix + string(objectId);
1783 return CORBA::string_dup(lpID.c_str());
1787 SMESH::SMESH_Mesh_var myMesh =
1788 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(IORString));
1789 if (!CORBA::is_nil(myMesh))
1791 string prefix = "Mesh_";
1792 sprintf(objectId, "%ld", myMesh->GetId());
1793 string lpID = prefix + string(objectId);
1794 return CORBA::string_dup(lpID.c_str());
1798 SMESH::SMESH_subMesh_var mySubMesh =
1799 SMESH::SMESH_subMesh::_narrow(_orb->
1800 string_to_object(IORString));
1801 if (!CORBA::is_nil(mySubMesh))
1803 string prefix = "SubMesh_";
1804 sprintf(objectId, "%ld", mySubMesh->GetId());
1805 string lpID = prefix + string(objectId);
1806 return CORBA::string_dup(lpID.c_str());
1809 return (strdup("no object"));
1815 //=============================================================================
1819 //=============================================================================
1821 char *SMESH_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
1822 const char *aLocalPersistentID,
1823 CORBA::Boolean isMultiFile, CORBA::Boolean isASCII)
1825 MESSAGE("SMESH_Gen_i::LocalPersistentIDToIOR");
1826 SCRUTE(aLocalPersistentID);
1827 string clef = string(aLocalPersistentID);
1828 SCRUTE(_SMESHCorbaObj[clef].c_str());
1829 return CORBA::string_dup(_SMESHCorbaObj[clef].c_str());
1832 //=============================================================================
1836 //=============================================================================
1838 SMESH_topo *SMESH_Gen_i::ExploreMainShape(GEOM::GEOM_Gen_ptr geomEngine,
1839 CORBA::Long studyId, GEOM::GEOM_Shape_ptr aShape)
1841 MESSAGE("SMESH_Mesh_i::ExploreMainShape");
1842 // _narrow() duplicates the reference and check the type
1843 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
1844 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
1846 if (CORBA::is_nil(geom))
1847 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", SALOME::BAD_PARAM);
1848 if (CORBA::is_nil(myShape))
1849 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", SALOME::BAD_PARAM);
1851 SCRUTE(myShape->Name());
1852 geom->GetCurrentStudy(studyId);
1854 TopoDS_Shape mainShape = _ShapeReader->GetShape(geom, myShape);
1857 // create an SMESH_topo object for the mainShape
1859 SMESH_topo *myTopo = new SMESH_topo();
1862 // explore local TopoDS_Shape, store reference of local TopoDS subShapes
1864 for (TopExp_Explorer exp(mainShape, TopAbs_COMPOUND); exp.More();
1867 const TopoDS_Compound & E = TopoDS::Compound(exp.Current());
1868 int i = myTopo->_myShapes[TopAbs_COMPOUND].Add(E);
1871 for (TopExp_Explorer exp(mainShape, TopAbs_COMPSOLID); exp.More();
1874 const TopoDS_CompSolid & E = TopoDS::CompSolid(exp.Current());
1875 int i = myTopo->_myShapes[TopAbs_COMPSOLID].Add(E);
1878 for (TopExp_Explorer exp(mainShape, TopAbs_SOLID); exp.More(); exp.Next())
1880 const TopoDS_Solid & E = TopoDS::Solid(exp.Current());
1881 int i = myTopo->_myShapes[TopAbs_SOLID].Add(E);
1884 for (TopExp_Explorer exp(mainShape, TopAbs_SHELL); exp.More(); exp.Next())
1886 const TopoDS_Shell & E = TopoDS::Shell(exp.Current());
1887 int i = myTopo->_myShapes[TopAbs_SHELL].Add(E);
1890 for (TopExp_Explorer exp(mainShape, TopAbs_FACE); exp.More(); exp.Next())
1892 const TopoDS_Face & E = TopoDS::Face(exp.Current());
1893 int i = myTopo->_myShapes[TopAbs_FACE].Add(E);
1896 for (TopExp_Explorer exp(mainShape, TopAbs_WIRE); exp.More(); exp.Next())
1898 const TopoDS_Wire & E = TopoDS::Wire(exp.Current());
1899 int i = myTopo->_myShapes[TopAbs_WIRE].Add(E);
1902 for (TopExp_Explorer exp(mainShape, TopAbs_EDGE); exp.More(); exp.Next())
1904 const TopoDS_Edge & E = TopoDS::Edge(exp.Current());
1905 int i = myTopo->_myShapes[TopAbs_EDGE].Add(E);
1908 for (TopExp_Explorer exp(mainShape, TopAbs_VERTEX); exp.More(); exp.Next())
1910 const TopoDS_Vertex & E = TopoDS::Vertex(exp.Current());
1911 int i = myTopo->_myShapes[TopAbs_VERTEX].Add(E);
1915 // explore subShapes of distant CORBA object,
1916 // associate distant CORBA subShape references
1917 // with local reference to local TopoDS subShape
1919 string filenode = "toposhape.txt";
1920 ofstream fic(filenode.c_str());
1922 for (int shapeType = TopAbs_COMPOUND; shapeType < TopAbs_SHAPE; shapeType++)
1924 fic << "shape type : " << SMESH_shapeTypeNames[shapeType];
1926 GEOM::GEOM_Gen::ListOfGeomShapes_var subShapes
1927 = geom->SubShapeAll(myShape, shapeType);
1928 int nbSubShapes = subShapes->length();
1929 int nbLocal = myTopo->_myShapes[shapeType].Extent();
1930 fic << " - number of elements: " << nbSubShapes << endl;
1931 ASSERT(nbSubShapes == nbLocal);
1933 for (int i = 0; i < nbSubShapes; i++)
1935 GEOM::GEOM_Shape_var aSubShape = subShapes[i];
1936 string idShape = SMESH_topo::GetShapeLocalId(aSubShape);
1937 fic << " " << idShape;
1939 TopoDS_Shape aLocShape = _ShapeReader->GetShape(geom, aSubShape);
1940 for (int j = 1; j <= nbLocal; j++)
1941 if (aLocShape.IsSame(myTopo->_myShapes[shapeType].FindKey(j)))
1943 MESSAGE(" --- trouve = " << j);
1944 myTopo->_mapIndShapes[shapeType][idShape] = j;
1945 fic << " --- trouve = " << j;
1957 * Import a mesh from a file
1958 * @param fileName file name to be imported
1959 * @param fileType Currently it could be either "DAT", "UNV" or "MED".
1961 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Import(CORBA::Long studyId,
1962 const char *fileName, const char *fileType)
1964 MESSAGE("SMESH_Gen_I::Import");
1965 SMESH_Mesh_i *meshServant;
1968 if (_mapStudyContext_i.find(studyId) == _mapStudyContext_i.end())
1970 _mapStudyContext_i[studyId] = new StudyContext_iStruct;
1972 StudyContext_iStruct *myStudyContext = _mapStudyContext_i[studyId];
1974 // create a new mesh object servant, store it in a map in study context
1975 meshServant = new SMESH_Mesh_i(this, NULL, studyId, _localId);
1976 myStudyContext->mapMesh_i[_localId] = meshServant;
1979 // create a new mesh object
1980 meshServant->SetImpl(_impl.Import(studyId, fileName, fileType));
1982 catch(SALOME_Exception & S_ex)
1984 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1987 // activate the CORBA servant of Mesh
1989 SMESH::SMESH_Mesh_var mesh
1990 = SMESH::SMESH_Mesh::_narrow(meshServant->_this());
1992 meshServant->SetIor(mesh);
1993 return SMESH::SMESH_Mesh::_duplicate(mesh);
1996 //=============================================================================
1998 * C factory, accessible with dlsym, after dlopen
2000 //=============================================================================
2004 PortableServer::ObjectId * SMESHEngine_factory(CORBA::ORB_ptr orb,
2005 PortableServer::POA_ptr poa,
2006 PortableServer::ObjectId * contId,
2007 const char *instanceName, const char *interfaceName)
2009 MESSAGE("PortableServer::ObjectId * SMESHEngine_factory()");
2010 SCRUTE(interfaceName);
2011 SMESH_Gen_i *mySMESH_Gen
2012 = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
2013 return mySMESH_Gen->getId();