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
30 #include <TopExp_Explorer.hxx>
32 #include <TopoDS_Iterator.hxx>
33 #include <TopoDS_Compound.hxx>
34 #include <TopoDS_CompSolid.hxx>
35 #include <TopoDS_Solid.hxx>
36 #include <TopoDS_Shell.hxx>
37 #include <TopoDS_Face.hxx>
38 #include <TopoDS_Wire.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Vertex.hxx>
41 #include <TopoDS_Shape.hxx>
42 #include <TopTools_MapOfShape.hxx>
44 #include <BRep_Tool.hxx>
45 #include <TCollection_AsciiString.hxx>
47 #include "SMESH_Gen_i.hxx"
48 #include "SMESH_Mesh_i.hxx"
49 #include "SMESH_LocalLength_i.hxx"
50 #include "SMESH_NumberOfSegments_i.hxx"
51 #include "SMESH_MaxElementArea_i.hxx"
52 #include "SMESH_MaxElementVolume_i.hxx"
54 #include "SMESHDriver.h"
56 #include "Utils_CorbaException.hxx"
57 #include "utilities.h"
59 #include "SALOMEDS_Tool.hxx"
60 #include "SALOME_NamingService.hxx"
61 #include "SALOME_LifeCycleCORBA.hxx"
62 #include "Utils_SINGLETON.hxx"
65 //#include <TopAbs_ShapeEnum.hxx>
67 #include "GEOM_Client.hxx"
74 #define NUM_TMP_FILES 4
77 long Tag_HypothesisRoot = 1;
78 long Tag_AlgorithmsRoot = 2;
80 long Tag_RefOnShape = 1;
81 long Tag_RefOnAppliedHypothesis = 2;
82 long Tag_RefOnAppliedAlgorithms = 3;
84 long Tag_SubMeshOnVertex = 4;
85 long Tag_SubMeshOnEdge = 5;
86 long Tag_SubMeshOnFace = 6;
87 long Tag_SubMeshOnSolid = 7;
88 long Tag_SubMeshOnCompound = 8;
90 //=============================================================================
92 * default constructor: not for use
94 //=============================================================================
96 SMESH_Gen_i::SMESH_Gen_i()
98 MESSAGE("SMESH_Gen_i default constructor");
102 //=============================================================================
104 * Standard constructor, used with Container.
106 //=============================================================================
108 SMESH_Gen_i::SMESH_Gen_i(CORBA::ORB_ptr orb,
109 PortableServer::POA_ptr poa,
110 PortableServer::ObjectId * contId,
111 const char *instanceName,
112 const char *interfaceName):Engines_Component_i(orb, poa, contId,
113 instanceName, interfaceName)
115 MESSAGE("activate object");
117 _id = _poa->activate_object(_thisObj);
123 //=============================================================================
125 * Standard destructor
127 //=============================================================================
129 SMESH_Gen_i::~SMESH_Gen_i()
131 MESSAGE("~SMESH_Gen_i");
135 //=============================================================================
139 //=============================================================================
141 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis(const char *anHyp,
142 CORBA::Long studyId) throw(SALOME::SALOME_Exception)
144 MESSAGE("CreateHypothesis");
146 // create a new hypothesis object servant
148 SMESH_Hypothesis_i *myHypothesis_i = 0;
151 myHypothesis_i = _hypothesisFactory_i.Create(anHyp, studyId, &_impl);
153 catch(SALOME_Exception & S_ex)
155 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
158 // activate the CORBA servant of hypothesis
160 SMESH::SMESH_Hypothesis_var hypothesis_i
161 = SMESH::SMESH_Hypothesis::_narrow(myHypothesis_i->_this());
162 return SMESH::SMESH_Hypothesis::_duplicate(hypothesis_i);
166 * CORBA implementation of SMESH_Gen::Init. See SMESH_Gen.idl.
168 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Init(GEOM::GEOM_Gen_ptr geomEngine,
170 GEOM::GEOM_Shape_ptr aShape) throw(SALOME::SALOME_Exception)
172 return Init(geomEngine, studyId, aShape, -1);
176 * This is NOT a CORBA implementation. Differ from the Init CORBA method
177 * by allowing to specify the ID of the created mesh.
179 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Init(GEOM::GEOM_Gen_ptr geomEngine,
180 CORBA::Long studyId, GEOM::GEOM_Shape_ptr aShape, int meshID)
181 throw(SALOME::SALOME_Exception)
184 // _narrow() duplicates the reference and checks the type
185 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
186 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
188 if (CORBA::is_nil(geom))
189 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", SALOME::BAD_PARAM);
190 if (CORBA::is_nil(myShape))
191 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", SALOME::BAD_PARAM);
193 // Get or create the GEOM_Client instance
195 SMESH_Mesh_i *meshServant = 0;
199 _ShapeReader = new GEOM_Client();
200 ASSERT(_ShapeReader);
202 // explore main Shape, get local TopoDS_Shapes of all subShapes
203 // SMESH_topo* myTopo = ExploreMainShape(geom, studyId, myShape);
205 // Get studyContext_i, create it if it does'nt exist
207 if (_mapStudyContext_i.find(studyId) == _mapStudyContext_i.end())
209 _mapStudyContext_i[studyId] = new StudyContext_iStruct;
211 StudyContext_iStruct *myStudyContext = _mapStudyContext_i[studyId];
213 // create a new mesh object
214 TopoDS_Shape myLocShape = _ShapeReader->GetShape(geom, myShape);
215 SMESH_Mesh * meshImpl=_impl.Init(studyId, myLocShape, meshID);
217 // create a new mesh object servant, store it in a map in study context
218 meshServant = new SMESH_Mesh_i(this, geom, studyId, meshImpl);
219 myStudyContext->mapMesh_i[meshServant->GetId()] = meshServant;
221 catch(SALOME_Exception & S_ex)
223 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
226 // activate the CORBA servant of Mesh
228 SMESH::SMESH_Mesh_var mesh
229 = SMESH::SMESH_Mesh::_narrow(meshServant->_this());
231 meshServant->SetIor(mesh);
233 return SMESH::SMESH_Mesh::_duplicate(mesh);
236 //=============================================================================
240 //=============================================================================
242 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute(SMESH::SMESH_Mesh_ptr aMesh,
243 GEOM::GEOM_Shape_ptr aShape) throw(SALOME::SALOME_Exception)
245 MESSAGE("SMESH_Gen_i::IsReadyToCompute");
249 //=============================================================================
253 //=============================================================================
256 SMESH_Gen_i::GetSubShapesId(GEOM::GEOM_Gen_ptr geomEngine,
258 GEOM::GEOM_Shape_ptr mainShape,
259 const SMESH::shape_array & listOfSubShape)throw(SALOME::SALOME_Exception)
261 MESSAGE("SMESH_Gen_i::GetSubShapesId");
262 SMESH::long_array_var shapesId = new SMESH::long_array;
265 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
266 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(mainShape);
268 if (CORBA::is_nil(geom))
269 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", SALOME::BAD_PARAM);
270 if (CORBA::is_nil(myShape))
271 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", SALOME::BAD_PARAM);
276 _ShapeReader = new GEOM_Client();
277 ASSERT(_ShapeReader);
278 TopoDS_Shape myMainShape = _ShapeReader->GetShape(geom, myShape);
279 TopTools_IndexedMapOfShape myIndexToShape;
280 TopExp::MapShapes(myMainShape, myIndexToShape);
282 for (unsigned int i = 0; i < listOfSubShape.length(); i++)
284 GEOM::GEOM_Shape_var aShape
285 = GEOM::GEOM_Shape::_narrow(listOfSubShape[i]);
286 if (CORBA::is_nil(aShape))
287 THROW_SALOME_CORBA_EXCEPTION("bad shape reference",
289 TopoDS_Shape locShape = _ShapeReader->GetShape(geom, aShape);
290 for (TopExp_Explorer exp(locShape, TopAbs_FACE); exp.More();
293 const TopoDS_Face & F = TopoDS::Face(exp.Current());
294 setId.insert(myIndexToShape.FindIndex(F));
295 SCRUTE(myIndexToShape.FindIndex(F));
297 for (TopExp_Explorer exp(locShape, TopAbs_EDGE); exp.More();
300 const TopoDS_Edge & E = TopoDS::Edge(exp.Current());
301 setId.insert(myIndexToShape.FindIndex(E));
302 SCRUTE(myIndexToShape.FindIndex(E));
304 for (TopExp_Explorer exp(locShape, TopAbs_VERTEX); exp.More();
307 const TopoDS_Vertex & V = TopoDS::Vertex(exp.Current());
308 setId.insert(myIndexToShape.FindIndex(V));
309 SCRUTE(myIndexToShape.FindIndex(V));
312 shapesId->length(setId.size());
313 set < int >::iterator iind;
315 for (iind = setId.begin(); iind != setId.end(); iind++)
318 shapesId[i] = (*iind);
323 catch(SALOME_Exception & S_ex)
325 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
328 return shapesId._retn();
331 //=============================================================================
335 //=============================================================================
337 CORBA::Boolean SMESH_Gen_i::Compute(SMESH::SMESH_Mesh_ptr aMesh,
338 GEOM::GEOM_Shape_ptr aShape) throw(SALOME::SALOME_Exception)
340 MESSAGE("SMESH_Gen_i::Compute");
341 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
342 if (CORBA::is_nil(myShape))
343 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", SALOME::BAD_PARAM);
345 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow(aMesh);
346 if (CORBA::is_nil(myMesh))
347 THROW_SALOME_CORBA_EXCEPTION("bad Mesh reference", SALOME::BAD_PARAM);
353 // get study context from studyId given by CORBA mesh object
355 int studyId = myMesh->GetStudyId();
356 ASSERT(_mapStudyContext_i.find(studyId) != _mapStudyContext_i.end());
357 StudyContext_iStruct *myStudyContext = _mapStudyContext_i[studyId];
359 // get local Mesh_i object with Id and study context
361 int meshId = myMesh->GetId();
362 ASSERT(myStudyContext->mapMesh_i.find(meshId) !=
363 myStudyContext->mapMesh_i.end());
364 SMESH_Mesh_i *meshServant = myStudyContext->mapMesh_i[meshId];
367 // get local TopoDS_Shape
369 GEOM::GEOM_Gen_var geom = meshServant->GetGeomEngine();
370 TopoDS_Shape myLocShape = _ShapeReader->GetShape(geom, myShape);
372 // implementation compute
374 ::SMESH_Mesh & myLocMesh = meshServant->GetImpl();
375 ret = _impl.Compute(myLocMesh, myLocShape);
377 catch(SALOME_Exception & S_ex)
379 MESSAGE("catch exception " << S_ex.what());
381 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
387 //=============================================================================
391 //=============================================================================
393 SALOMEDS::TMPFile * SMESH_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
394 const char *theURL, bool isMultiFile)
396 MESSAGE("SMESH_Gen_i::SAVE");
397 SALOMEDS::Study_var Study = theComponent->GetStudy();
400 // Declare a byte stream
401 SALOMEDS::TMPFile_var aStreamFile;
403 // Obtain a temporary dir
404 TCollection_AsciiString tmpDir =
405 (isMultiFile) ? TCollection_AsciiString((char *)theURL) :
406 SALOMEDS_Tool::GetTmpDir();
408 // Create a sequence of files processed
409 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
410 aFileSeq->length(NUM_TMP_FILES);
412 TCollection_AsciiString aStudyName("");
416 (SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
418 // Set names of temporary files
419 TCollection_AsciiString filename =
420 aStudyName + TCollection_AsciiString("_SMESH.hdf");
421 TCollection_AsciiString hypofile =
422 aStudyName + TCollection_AsciiString("_SMESH_Hypo.txt");
423 TCollection_AsciiString algofile =
424 aStudyName + TCollection_AsciiString("_SMESH_Algo.txt");
425 TCollection_AsciiString meshfile =
426 aStudyName + TCollection_AsciiString("_SMESH_Mesh.med");
427 aFileSeq[0] = CORBA::string_dup(filename.ToCString());
428 aFileSeq[1] = CORBA::string_dup(hypofile.ToCString());
429 aFileSeq[2] = CORBA::string_dup(algofile.ToCString());
430 aFileSeq[3] = CORBA::string_dup(meshfile.ToCString());
431 filename = tmpDir + filename;
432 hypofile = tmpDir + hypofile;
433 algofile = tmpDir + algofile;
434 meshfile = tmpDir + meshfile;
437 map < int, HDFgroup * >hdf_group, hdf_subgroup;
438 map < int, HDFdataset * >hdf_dataset;
441 SALOMEDS::ChildIterator_var itBig, it, itSM;
442 SALOMEDS::SObject_var mySObject, myBranch, mySObjectChild;
444 int longueur, cmpt_ds = 0, cmpt_it;
445 char *name_group, name_dataset[30], name_meshgroup[30];
447 int cmpt_sm = 0, myTag;
449 //************* HDF file creation
450 hdf_file = new HDFfile(filename.ToCString());
451 hdf_file->CreateOnDisk();
452 //****************************
454 itBig = Study->NewChildIterator(theComponent);
455 SCRUTE(Tag_HypothesisRoot);
456 SCRUTE(Tag_AlgorithmsRoot);
457 for (; itBig->More(); itBig->Next())
459 SALOMEDS::SObject_var gotBranch = itBig->Value();
460 SCRUTE(gotBranch->Name());
461 SCRUTE(gotBranch->Tag());
462 SCRUTE(gotBranch->GetID());
464 //************branch 1 : hypothesis
465 if (gotBranch->Tag() == Tag_HypothesisRoot)
466 { //hypothesis = tag 1
467 double length, maxElementsArea, maxElementsVolume;
468 int numberOfSegments;
470 destFile = fopen(hypofile.ToCString(), "w");
471 it = Study->NewChildIterator(gotBranch);
472 for (; it->More(); it->Next())
474 mySObject = it->Value();
475 SALOMEDS::GenericAttribute_var anAttr;
476 SALOMEDS::AttributeIOR_var anIOR;
477 if (mySObject->FindAttribute(anAttr, "AttributeIOR"))
479 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
481 SMESH::SMESH_Hypothesis_var myHyp =
482 SMESH::SMESH_Hypothesis::_narrow(_orb->
483 string_to_object(anIOR->Value()));
484 SCRUTE(myHyp->GetName());
485 fprintf(destFile, "%li\n", myHyp->GetId());
486 fprintf(destFile, "%s\n", myHyp->GetName());
487 if (strcmp(myHyp->GetName(), "LocalLength") == 0)
489 SMESH::SMESH_LocalLength_var LL =
490 SMESH::SMESH_LocalLength::_narrow(myHyp);
491 length = LL->GetLength();
492 fprintf(destFile, "%f\n", length);
494 else if (strcmp(myHyp->GetName(), "NumberOfSegments") == 0)
496 SMESH::SMESH_NumberOfSegments_var NOS =
497 SMESH::SMESH_NumberOfSegments::_narrow(myHyp);
498 numberOfSegments = NOS->GetNumberOfSegments();
499 fprintf(destFile, "%d\n", numberOfSegments);
501 else if (strcmp(myHyp->GetName(), "MaxElementArea") == 0)
503 SMESH::SMESH_MaxElementArea_var MEA =
504 SMESH::SMESH_MaxElementArea::_narrow(myHyp);
505 maxElementsArea = MEA->GetMaxElementArea();
506 fprintf(destFile, "%f\n", maxElementsArea);
508 else if (strcmp(myHyp->GetName(), "MaxElementVolume") == 0)
510 SMESH::SMESH_MaxElementVolume_var MEV =
511 SMESH::SMESH_MaxElementVolume::_narrow(myHyp);
512 maxElementsVolume = MEV->GetMaxElementVolume();
513 fprintf(destFile, "%f\n", maxElementsVolume);
519 //writes the file name in the hdf file
520 longueur = hypofile.Length() + 1;
521 name_group = "Hypothesis";
522 //SCRUTE(name_group);
525 hdf_group[1] = new HDFgroup(name_group, hdf_file);
526 hdf_group[1]->CreateOnDisk();
528 hdf_dataset[cmpt_ds] =
529 new HDFdataset(name_group, hdf_group[1], HDF_STRING, size, 1);
530 hdf_dataset[cmpt_ds]->CreateOnDisk();
531 hdf_dataset[cmpt_ds]->WriteOnDisk(hypofile.ToCString());
532 hdf_dataset[cmpt_ds]->CloseOnDisk();
535 hdf_group[1]->CloseOnDisk();
536 MESSAGE("End of Hypothesis Save");
539 //************branch 2 : algorithms
540 else if (gotBranch->Tag() == Tag_AlgorithmsRoot)
542 destFile = fopen(algofile.ToCString(), "w");
543 it = Study->NewChildIterator(gotBranch);
544 for (; it->More(); it->Next())
546 mySObject = it->Value();
547 SALOMEDS::GenericAttribute_var anAttr;
548 SALOMEDS::AttributeIOR_var anIOR;
549 if (mySObject->FindAttribute(anAttr, "AttributeIOR"))
551 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
552 SMESH::SMESH_Algo_var myAlgo =
553 SMESH::SMESH_Algo::_narrow(_orb->
554 string_to_object(anIOR->Value()));
555 SCRUTE(anIOR->Value());
556 SCRUTE(myAlgo->_is_nil());
557 fprintf(destFile, "%li\n", myAlgo->GetId());
558 fprintf(destFile, "%s\n", myAlgo->GetName());
564 //writes the file name in the hdf file
565 longueur = algofile.Length() + 1;
566 name_group = "Algorithms";
567 //SCRUTE(name_group);
570 hdf_group[2] = new HDFgroup(name_group, hdf_file);
571 hdf_group[2]->CreateOnDisk();
573 hdf_dataset[cmpt_ds] =
574 new HDFdataset(name_group, hdf_group[2], HDF_STRING, size, 1);
575 hdf_dataset[cmpt_ds]->CreateOnDisk();
576 hdf_dataset[cmpt_ds]->WriteOnDisk(algofile.ToCString());
577 hdf_dataset[cmpt_ds]->CloseOnDisk();
580 hdf_group[2]->CloseOnDisk();
581 MESSAGE("End of Algos Save");
584 //************branch 3 : meshes
585 else if (gotBranch->Tag() >= 3)
588 SALOMEDS::GenericAttribute_var anAttr;
589 SALOMEDS::AttributeIOR_var anIOR;
590 if (gotBranch->FindAttribute(anAttr, "AttributeIOR"))
592 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
594 SMESH::SMESH_Mesh_var myMesh =
595 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->
597 studyId = myMesh->GetStudyId();
600 StudyContext_iStruct *myStudyContext =
601 _mapStudyContext_i[studyId];
602 int meshId = myMesh->GetId();
603 SMESH_Mesh_i *meshServant = myStudyContext->mapMesh_i[meshId];
604 ::SMESH_Mesh & myLocMesh = meshServant->GetImpl();
605 SMESHDS_Mesh *mySMESHDSMesh = myLocMesh.GetMeshDS();
607 SCRUTE(mySMESHDSMesh->NbNodes());
608 if (mySMESHDSMesh->NbNodes() > 0)
610 //checks if the mesh is not empty
611 Mesh_Writer *myWriter = SMESHDriver::GetMeshWriter("MED");
612 myWriter->SetFile(meshfile.ToCString());
613 myWriter->SetMesh(mySMESHDSMesh);
614 myWriter->SetMeshId(gotBranch->Tag());
618 meshfile = "No data";
620 //********** opening of the HDF group
621 sprintf(name_meshgroup, "Mesh %d", meshId);
622 SCRUTE(name_meshgroup);
623 hdf_group[gotBranch->Tag()] =
624 new HDFgroup(name_meshgroup, hdf_file);
625 hdf_group[gotBranch->Tag()]->CreateOnDisk();
628 //********** file where the data are stored
629 longueur = strlen(meshfile.ToCString()) + 1;
631 strcpy(name_dataset, "Mesh data");
632 hdf_dataset[cmpt_ds] =
633 new HDFdataset(name_dataset, hdf_group[gotBranch->Tag()],
634 HDF_STRING, size, 1);
635 hdf_dataset[cmpt_ds]->CreateOnDisk();
636 hdf_dataset[cmpt_ds]->WriteOnDisk(meshfile.ToCString());
637 hdf_dataset[cmpt_ds]->CloseOnDisk();
641 //********** ref on shape
642 Standard_CString myRefOnObject = "";
643 SALOMEDS::SObject_var myRef, myShape;
644 _found = gotBranch->FindSubObject(Tag_RefOnShape, myRef);
647 ok = myRef->ReferencedObject(myShape);
648 myRefOnObject = myShape->GetID();
649 SCRUTE(myRefOnObject);
651 longueur = strlen(myRefOnObject) + 1;
655 strcpy(name_dataset, "Ref on shape");
656 hdf_dataset[cmpt_ds] =
657 new HDFdataset(name_dataset,
658 hdf_group[gotBranch->Tag()], HDF_STRING, size, 1);
659 hdf_dataset[cmpt_ds]->CreateOnDisk();
660 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
661 hdf_dataset[cmpt_ds]->CloseOnDisk();
668 //********** ref on applied hypothesis
670 gotBranch->FindSubObject(Tag_RefOnAppliedHypothesis,
675 strcpy(name_meshgroup, "Applied Hypothesis");
676 hdf_subgroup[Tag_RefOnAppliedHypothesis] =
677 new HDFgroup(name_meshgroup,
678 hdf_group[gotBranch->Tag()]);
679 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CreateOnDisk();
681 it = Study->NewChildIterator(myBranch);
683 for (; it->More(); it->Next())
685 mySObject = it->Value();
686 ok = mySObject->ReferencedObject(myRef);
687 myRefOnObject = myRef->GetID();
689 longueur = strlen(myRefOnObject) + 1;
693 sprintf(name_dataset, "Hyp %d", cmpt_it);
694 hdf_dataset[cmpt_ds] =
695 new HDFdataset(name_dataset,
696 hdf_subgroup[Tag_RefOnAppliedHypothesis],
697 HDF_STRING, size, 1);
698 hdf_dataset[cmpt_ds]->CreateOnDisk();
699 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
700 hdf_dataset[cmpt_ds]->CloseOnDisk();
705 hdf_subgroup[Tag_RefOnAppliedHypothesis]->CloseOnDisk();
709 //********** ref on applied algorithms
711 gotBranch->FindSubObject(Tag_RefOnAppliedAlgorithms,
716 strcpy(name_meshgroup, "Applied Algorithms");
717 hdf_subgroup[Tag_RefOnAppliedAlgorithms] =
718 new HDFgroup(name_meshgroup,
719 hdf_group[gotBranch->Tag()]);
720 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CreateOnDisk();
722 it = Study->NewChildIterator(myBranch);
724 for (; it->More(); it->Next())
726 mySObject = it->Value();
727 ok = mySObject->ReferencedObject(myRef);
728 myRefOnObject = myRef->GetID();
730 longueur = strlen(myRefOnObject) + 1;
734 sprintf(name_dataset, "Algo %d", cmpt_it);
735 hdf_dataset[cmpt_ds] =
736 new HDFdataset(name_dataset,
737 hdf_subgroup[Tag_RefOnAppliedAlgorithms],
738 HDF_STRING, size, 1);
739 hdf_dataset[cmpt_ds]->CreateOnDisk();
740 hdf_dataset[cmpt_ds]->WriteOnDisk(myRefOnObject);
741 hdf_dataset[cmpt_ds]->CloseOnDisk();
746 hdf_subgroup[Tag_RefOnAppliedAlgorithms]->CloseOnDisk();
748 MESSAGE("end of algo applied");
751 //********** submeshes on subshapes
753 for (int i = Tag_SubMeshOnVertex; i <= Tag_SubMeshOnCompound;
756 _found = gotBranch->FindSubObject(i, myBranch);
759 if (i == Tag_SubMeshOnVertex)
760 strcpy(name_meshgroup, "SubMeshes On Vertex");
761 else if (i == Tag_SubMeshOnEdge)
762 strcpy(name_meshgroup, "SubMeshes On Edge");
763 else if (i == Tag_SubMeshOnFace)
764 strcpy(name_meshgroup, "SubMeshes On Face");
765 else if (i == Tag_SubMeshOnSolid)
766 strcpy(name_meshgroup, "SubMeshes On Solid");
767 else if (i == Tag_SubMeshOnCompound)
768 strcpy(name_meshgroup, "SubMeshes On Compound");
771 myLevel1Tag = 10 + cmpt_sm;
772 hdf_subgroup[myLevel1Tag] =
773 new HDFgroup(name_meshgroup,
774 hdf_group[gotBranch->Tag()]);
775 hdf_subgroup[myLevel1Tag]->CreateOnDisk();
777 itSM = Study->NewChildIterator(myBranch);
778 for (; itSM->More(); itSM->Next())
779 { //Loop on all submeshes
780 mySObject = itSM->Value();
782 myTag = 10 + cmpt_sm;
783 mySObject->FindAttribute(anAttr, "AttributeIOR");
784 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
785 SMESH::SMESH_subMesh_var mySubMesh =
786 SMESH::SMESH_subMesh::_narrow(_orb->
787 string_to_object(anIOR->Value()));
789 //sprintf(name_meshgroup,"SubMesh %d",myTag);
790 sprintf(name_meshgroup, "SubMesh %ld",
792 SCRUTE(name_meshgroup);
794 hdf_subgroup[myTag] =
795 new HDFgroup(name_meshgroup,
796 hdf_subgroup[myLevel1Tag]);
797 hdf_subgroup[myTag]->CreateOnDisk();
799 //********** ref on shape
800 Standard_CString myRefOnObject = "";
801 SALOMEDS::SObject_var myRef, myShape;
804 mySObject->FindSubObject(Tag_RefOnShape, myRef);
807 ok = myRef->ReferencedObject(myShape);
808 myRefOnObject = myShape->GetID();
809 SCRUTE(myRefOnObject);
811 longueur = strlen(myRefOnObject) + 1;
815 strcpy(name_dataset, "Ref on shape");
816 hdf_dataset[cmpt_ds] =
817 new HDFdataset(name_dataset,
818 hdf_subgroup[myTag], HDF_STRING, size,
820 hdf_dataset[cmpt_ds]->CreateOnDisk();
821 hdf_dataset[cmpt_ds]->
822 WriteOnDisk(myRefOnObject);
823 hdf_dataset[cmpt_ds]->CloseOnDisk();
829 //********** ref on applied hypothesis
832 FindSubObject(Tag_RefOnAppliedHypothesis,
837 strcpy(name_meshgroup, "Applied Hypothesis");
839 hdf_subgroup[10 + cmpt_sm] =
840 new HDFgroup(name_meshgroup,
841 hdf_subgroup[myTag]);
842 hdf_subgroup[10 + cmpt_sm]->CreateOnDisk();
844 it = Study->NewChildIterator(myBranch);
846 for (; it->More(); it->Next())
848 mySObjectChild = it->Value();
849 ok = mySObjectChild->
850 ReferencedObject(myRef);
851 myRefOnObject = myRef->GetID();
853 longueur = strlen(myRefOnObject) + 1;
857 sprintf(name_dataset, "Hyp %d",
860 hdf_dataset[cmpt_ds] =
861 new HDFdataset(name_dataset,
862 hdf_subgroup[10 + cmpt_sm],
863 HDF_STRING, size, 1);
864 hdf_dataset[cmpt_ds]->CreateOnDisk();
865 hdf_dataset[cmpt_ds]->
866 WriteOnDisk(myRefOnObject);
867 hdf_dataset[cmpt_ds]->CloseOnDisk();
872 hdf_subgroup[10 + cmpt_sm]->CloseOnDisk();
876 //********** ref on applied algorithms
879 FindSubObject(Tag_RefOnAppliedAlgorithms,
885 strcpy(name_meshgroup, "Applied Algorithms");
887 hdf_subgroup[10 + cmpt_sm] =
888 new HDFgroup(name_meshgroup,
889 hdf_subgroup[myTag]);
890 hdf_subgroup[10 + cmpt_sm]->CreateOnDisk();
892 it = Study->NewChildIterator(myBranch);
894 for (; it->More(); it->Next())
896 mySObjectChild = it->Value();
897 ok = mySObjectChild->
898 ReferencedObject(myRef);
899 myRefOnObject = myRef->GetID();
901 longueur = strlen(myRefOnObject) + 1;
905 sprintf(name_dataset, "Algo %d",
907 hdf_dataset[cmpt_ds] =
908 new HDFdataset(name_dataset,
909 hdf_subgroup[10 + cmpt_sm],
910 HDF_STRING, size, 1);
911 hdf_dataset[cmpt_ds]->CreateOnDisk();
912 hdf_dataset[cmpt_ds]->
913 WriteOnDisk(myRefOnObject);
914 hdf_dataset[cmpt_ds]->CloseOnDisk();
919 hdf_subgroup[10 + cmpt_sm]->CloseOnDisk();
921 //MESSAGE("end of algo applied");
924 hdf_subgroup[myTag]->CloseOnDisk();
927 hdf_subgroup[myLevel1Tag]->CloseOnDisk();
933 //********** closing of the HDF group
934 hdf_group[gotBranch->Tag()]->CloseOnDisk();
935 MESSAGE("End of Mesh Save");
939 MESSAGE("End of Meshes Save");
942 MESSAGE("hdf_file->CloseOnDisk()");
943 hdf_file->CloseOnDisk();
945 MESSAGE("delete hdf_file");
949 // Convert temporary files to stream
950 MESSAGE("Convert temporary files to stream");
952 SALOMEDS_Tool::PutFilesToStream(tmpDir.ToCString(), aFileSeq.in(),
955 // Remove temporary files and directory
956 MESSAGE("Remove temporary files and directory");
958 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(),
961 MESSAGE("End SMESH_Gen_i::Save");
963 return aStreamFile._retn();
967 SMESH_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
968 const char *theURL, bool isMultiFile)
970 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
971 return aStreamFile._retn();
974 void SMESH_Gen_i::loadHypothesis(char * name, HDFfile * hdf_file,
975 char * hypofile, int studyId)
977 char name_of_group[HDF_NAME_MAX_LEN + 1];
980 HDFgroup * hdfGroup = new HDFgroup(name, hdf_file);
981 hdfGroup->OpenOnDisk();
983 hdfGroup->InternalObjectIndentify(0, name_of_group);
984 HDFdataset * dataset = new HDFdataset(name_of_group, hdfGroup);
985 dataset->OpenOnDisk();
986 char *name_of_file = new char[dataset->GetSize()];
987 dataset->ReadFromDisk(name_of_file);
988 SCRUTE(name_of_file);
989 dataset->CloseOnDisk();
990 hdfGroup->CloseOnDisk();
991 delete[]name_of_file;
993 ifstream loadedFile(hypofile);
994 while (!loadedFile.eof())
997 string hypothesisName;
998 loadedFile >> hypothesisID;
999 loadedFile >> hypothesisName;
1000 if(hypothesisName.length()==0) break;
1001 SMESH_Hypothesis_i * corbaHyp =
1002 _hypothesisFactory_i.Create(hypothesisName.c_str(), studyId, &_impl);
1003 SMESH_Hypothesis * localHyp = corbaHyp->getImpl();
1004 localHyp->SetID(hypothesisID);
1005 localHyp->LoadFrom(loadedFile);
1007 SMESH::SMESH_Hypothesis_var varHyp = corbaHyp->_this();
1008 string iorString = _orb->object_to_string(varHyp);
1009 sprintf(objectId, "%ld", varHyp->GetId());
1010 _SMESHCorbaObj[string("Hypo_") + string(objectId)] =
1013 MESSAGE("End of Hypos Load");
1016 void SMESH_Gen_i::loadAlgorithms(char * name, HDFfile * hdf_file,
1017 char* algofile, int studyId)
1019 char name_of_group[HDF_NAME_MAX_LEN + 1];
1021 HDFgroup * hdfGroup = new HDFgroup(name, hdf_file);
1022 hdfGroup->OpenOnDisk();
1024 hdfGroup->InternalObjectIndentify(0, name_of_group);
1025 HDFdataset * dataset =
1026 new HDFdataset(name_of_group, hdfGroup);
1027 dataset->OpenOnDisk();
1029 char *name_of_file = new char[dataset->GetSize()];
1030 dataset->ReadFromDisk(name_of_file);
1031 dataset->CloseOnDisk();
1032 hdfGroup->CloseOnDisk();
1033 delete[]name_of_file;
1035 char * aLine = new char[100];
1036 FILE * loadedFile = fopen(algofile, "r");
1037 while (!feof(loadedFile))
1040 fscanf(loadedFile, "%i", &hypothesisID);
1041 fscanf(loadedFile, "%s\n", aLine);
1043 if (strcmp(aLine, "") != 0)
1045 SMESH_Hypothesis_i * corbaHyp =
1046 _hypothesisFactory_i.Create(aLine, studyId, &_impl);
1047 SMESH_Hypothesis * localHyp = corbaHyp->getImpl();
1048 localHyp->SetID(hypothesisID);
1050 SMESH::SMESH_Hypothesis_var myHyp = corbaHyp->_this();
1052 SMESH::SMESH_Algo_var myAlgo =
1053 SMESH::SMESH_Algo::_narrow(myHyp);
1054 string iorString = _orb->object_to_string(myAlgo);
1055 sprintf(objectId, "%ld", myAlgo->GetId());
1056 _SMESHCorbaObj[string("Hypo_") + string(objectId)] =
1063 MESSAGE("End of Algos Load");
1067 * @param hdfGroupMeshId The group where to read the hypothesis
1069 * @param Study The study where to create the hypothesis
1070 * @param myNewMesh The mesh on which the hypothesis is applied
1071 * @param aShape The shape with which this mesh is linked
1073 void SMESH_Gen_i::loadAppliedHypothesis(HDFgroup * hdfGroupMeshId,
1074 bool _found, SALOMEDS::Study_var Study, SMESH::SMESH_Mesh_var myNewMesh,
1075 GEOM::GEOM_Shape_var aShape)
1077 HDFgroup * hdf_subgroup = new HDFgroup("Applied Hypothesis", hdfGroupMeshId);
1078 hdf_subgroup->OpenOnDisk();
1079 int nb_datasets = hdf_subgroup->nInternalObjects();
1080 char name_dataset[10];
1082 for (int j = 0; j < nb_datasets; j++)
1084 sprintf(name_dataset, "Hyp %d", j);
1085 HDFdataset * hdf_dataset = new HDFdataset(name_dataset, hdf_subgroup);
1086 hdf_dataset->OpenOnDisk();
1088 char *refFromFile = new char[hdf_dataset->GetSize()];
1089 hdf_dataset->ReadFromDisk(refFromFile);
1090 hdf_dataset->CloseOnDisk();
1095 SALOMEDS::SObject_var HypSO =
1096 Study->FindObjectID(refFromFile);
1097 if (!CORBA::is_nil(HypSO))
1099 SALOMEDS::GenericAttribute_var anAttr;
1100 HypSO->FindAttribute(anAttr, "AttributeIOR");
1101 SALOMEDS::AttributeIOR_var anIOR =
1102 SALOMEDS::AttributeIOR::_narrow(anAttr);
1103 if (!CORBA::is_nil(anIOR))
1105 char *HypIOR = anIOR->Value();
1106 SMESH::SMESH_Hypothesis_var anHyp =
1107 SMESH::SMESH_Hypothesis::_narrow(_orb->
1108 string_to_object(HypIOR));
1109 if (!CORBA::is_nil(anHyp))
1111 myNewMesh->AddHypothesis(aShape, anHyp);
1112 MESSAGE("Hypothesis added ...");
1118 hdf_subgroup->CloseOnDisk();
1122 * @param hdfGroupMeshId The group where to read the hypothesis
1124 * @param Study The study where to create the hypothesis
1125 * @param myNewMesh The mesh on which the hypothesis is applied
1126 * @param aShape The shape with which this mesh is linked
1128 void SMESH_Gen_i::loadAppliedAlgorithms(HDFgroup * hdfGroupMeshId,
1129 bool _found, SALOMEDS::Study_var Study, SMESH::SMESH_Mesh_var myNewMesh,
1130 GEOM::GEOM_Shape_var aShape)
1132 HDFgroup * hdf_subgroup = new HDFgroup("Applied Algorithms", hdfGroupMeshId);
1133 hdf_subgroup->OpenOnDisk();
1135 int nb_datasets = hdf_subgroup->nInternalObjects();
1136 SCRUTE(nb_datasets);
1137 char name_dataset[10];
1139 for (int j = 0; j < nb_datasets; j++)
1141 sprintf(name_dataset, "Algo %d", j);
1142 HDFdataset * dataset =
1143 new HDFdataset(name_dataset, hdf_subgroup);
1144 dataset->OpenOnDisk();
1146 char *refFromFile = new char[dataset->GetSize()];
1147 dataset->ReadFromDisk(refFromFile);
1148 dataset->CloseOnDisk();
1152 SALOMEDS::SObject_var AlgoSO =
1153 Study->FindObjectID(refFromFile);
1154 if (!CORBA::is_nil(AlgoSO))
1156 SALOMEDS::GenericAttribute_var anAttr;
1157 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1158 SALOMEDS::AttributeIOR_var anIOR =
1159 SALOMEDS::AttributeIOR::_narrow(anAttr);
1160 if (!CORBA::is_nil(anIOR))
1162 char *AlgoIOR = anIOR->Value();
1164 SMESH::SMESH_Hypothesis_var myHyp =
1165 SMESH::SMESH_Hypothesis::_narrow(_orb->
1166 string_to_object(AlgoIOR));
1167 SMESH::SMESH_Algo_var anAlgo =
1168 SMESH::SMESH_Algo::_narrow(myHyp);
1170 if (!CORBA::is_nil(anAlgo))
1172 myNewMesh->AddHypothesis(aShape, anAlgo); //essayer avec _SMESHCorbaObj
1173 MESSAGE("Algorithms added ...");
1179 hdf_subgroup->CloseOnDisk();
1183 * @param hdfGroupMeshId The group where to read the hypothesis
1184 * @param msgname ???
1185 * @param Study The study where to create the hypothesis
1186 * @param myNewMesh The mesh on which the hypothesis is applied
1188 void SMESH_Gen_i::loadSubMeshes(HDFgroup * hdfGroupMeshId, char * msgname,
1189 SALOMEDS::Study_var Study, SMESH::SMESH_Mesh_var myNewMesh)
1191 MESSAGE("SMESH_Gen_i::loadSubMeshes");
1192 HDFgroup * hdf_subgroupmyLevel1Tag = new HDFgroup(msgname, hdfGroupMeshId);
1193 hdf_subgroupmyLevel1Tag->OpenOnDisk();
1195 int nb_submeshes = hdf_subgroupmyLevel1Tag->nInternalObjects();
1196 char name_meshgroup[30];
1197 //SCRUTE(nb_submeshes);
1199 for (int j = 0; j < nb_submeshes; j++)
1202 //myTag = 10 + cmpt_sm;
1203 hdf_subgroupmyLevel1Tag->InternalObjectIndentify(j, name_meshgroup);
1205 HDFgroup * hdf_subgroupmyTag = new HDFgroup(name_meshgroup,
1206 hdf_subgroupmyLevel1Tag);
1207 hdf_subgroupmyTag->OpenOnDisk();
1208 int subMeshId = atoi((string(name_meshgroup).substr(8, 18)).c_str());
1210 MESSAGE("Ref on shape");
1211 //********** ref on shape
1212 HDFdataset * hdf_dataset =
1213 new HDFdataset("Ref on shape", hdf_subgroupmyTag);
1214 hdf_dataset->OpenOnDisk();
1216 char *refFromFile = new char[hdf_dataset->GetSize()];
1217 hdf_dataset->ReadFromDisk(refFromFile);
1218 hdf_dataset->CloseOnDisk();
1220 bool _found3 = false;
1221 SALOMEDS::SObject_var GSO = Study->FindObjectID(refFromFile);
1222 SMESH::SMESH_subMesh_var aSubMesh;
1223 GEOM::GEOM_Shape_var aSubShape;
1225 if (!CORBA::is_nil(GSO))
1227 SALOMEDS::GenericAttribute_var anAttr;
1228 GSO->FindAttribute(anAttr, "AttributeIOR");
1229 SALOMEDS::AttributeIOR_var anIOR =
1230 SALOMEDS::AttributeIOR::_narrow(anAttr);
1232 char *SubShapeIOR = anIOR->Value();
1234 GEOM::GEOM_Shape::_narrow(_orb-> string_to_object(SubShapeIOR));
1236 if (!CORBA::is_nil(aSubShape))
1238 aSubMesh = myNewMesh->GetElementsOnShape(aSubShape);
1239 string iorString = _orb->object_to_string(aSubMesh);
1241 sprintf(objectId, "%d", subMeshId);
1242 _SMESHCorbaObj[string("SubMesh_") + string(objectId)] =
1248 int nb_subgroup = hdf_subgroupmyTag->nInternalObjects();
1249 SCRUTE(nb_subgroup);
1250 char sgname[HDF_NAME_MAX_LEN + 1];
1251 for (int k = 0; k < nb_subgroup; k++)
1253 hdf_subgroupmyTag->InternalObjectIndentify(k, sgname);
1254 if (strcmp(sgname, "Ref on shape") == 0)
1258 else if (strcmp(sgname, "Applied Hypothesis") == 0)
1260 //********** ref on applied hypothesis
1261 MESSAGE("Applied Hypothesis");
1262 strcpy(name_meshgroup, "Applied Hypothesis");
1264 HDFgroup * hdf_subgroup10cmpt_sm = new HDFgroup(name_meshgroup,
1267 hdf_subgroup10cmpt_sm->OpenOnDisk();
1268 int nb_datasets = hdf_subgroup10cmpt_sm->nInternalObjects();
1269 // SCRUTE(nb_datasets);
1271 char name_dataset[30];
1272 for (int l = 0; l < nb_datasets; l++)
1274 sprintf(name_dataset, "Hyp %d", l);
1275 HDFdataset * hdf_datasetcmpt_ds =
1276 new HDFdataset(name_dataset, hdf_subgroup10cmpt_sm);
1277 hdf_datasetcmpt_ds->OpenOnDisk();
1278 int size = hdf_datasetcmpt_ds->GetSize();
1280 char *refFromFile = new char[size];
1281 hdf_datasetcmpt_ds->ReadFromDisk(refFromFile);
1282 hdf_datasetcmpt_ds->CloseOnDisk();
1287 SALOMEDS::SObject_var HypSO =
1288 Study->FindObjectID(refFromFile);
1289 if (!CORBA::is_nil(HypSO))
1291 SALOMEDS::GenericAttribute_var anAttr;
1292 SALOMEDS::AttributeIOR_var anIOR;
1293 HypSO->FindAttribute(anAttr, "AttributeIOR");
1294 anIOR = SALOMEDS::AttributeIOR:: _narrow(anAttr);
1295 if (!CORBA::is_nil(anIOR))
1297 char *HypIOR = anIOR->Value();
1298 SMESH::SMESH_Hypothesis_var anHyp =
1299 SMESH::SMESH_Hypothesis::_narrow(_orb->
1300 string_to_object(HypIOR));
1301 if (!CORBA::is_nil(anHyp))
1303 SMESH::SMESH_Mesh_var aMesh =
1304 aSubMesh->GetFather();
1305 aMesh->AddHypothesis(aSubShape, anHyp); //essayer avec _SMESHCorbaObj
1306 MESSAGE("Hypothesis added ...");
1313 else if (strcmp(sgname, "Applied Algorithms") == 0)
1315 //********** ref on applied algorithms
1316 MESSAGE("Applied Algorithms");
1317 strcpy(name_meshgroup, "Applied Algorithms");
1319 HDFgroup * hdf_subgroup10cmpt_sm = new HDFgroup(name_meshgroup,
1321 hdf_subgroup10cmpt_sm->OpenOnDisk();
1322 int nb_datasets = hdf_subgroup10cmpt_sm->nInternalObjects();
1323 SCRUTE(nb_datasets);
1325 char name_dataset[30];
1326 for (int l = 0; l < nb_datasets; l++)
1328 sprintf(name_dataset, "Algo %d", l);
1329 HDFdataset * hdf_datasetcmpt_ds = new HDFdataset(
1330 name_dataset, hdf_subgroup10cmpt_sm);
1331 hdf_datasetcmpt_ds->OpenOnDisk();
1332 int size = hdf_datasetcmpt_ds->GetSize();
1334 char *refFromFile = new char[size];
1335 hdf_datasetcmpt_ds->ReadFromDisk(refFromFile);
1336 hdf_datasetcmpt_ds->CloseOnDisk();
1337 delete hdf_datasetcmpt_ds;
1342 SALOMEDS::SObject_var AlgoSO =
1343 Study->FindObjectID(refFromFile);
1344 if (!CORBA::is_nil(AlgoSO))
1346 SALOMEDS::GenericAttribute_var anAttr;
1347 SALOMEDS::AttributeIOR_var anIOR;
1348 AlgoSO->FindAttribute(anAttr, "AttributeIOR");
1349 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1350 if (!CORBA::is_nil(anIOR))
1352 char *AlgoIOR = anIOR->Value();
1354 SMESH::SMESH_Hypothesis_var myHyp =
1355 SMESH::SMESH_Hypothesis::_narrow(_orb->
1356 string_to_object(AlgoIOR));
1357 SMESH::SMESH_Algo_var anAlgo =
1358 SMESH::SMESH_Algo::_narrow(myHyp);
1359 //SMESH::SMESH_Algo_var anAlgo = SMESH::SMESH_Algo::_narrow(_orb->string_to_object(AlgoIOR));
1360 if (!CORBA::is_nil(anAlgo))
1362 SMESH::SMESH_Mesh_var aMesh =
1363 aSubMesh->GetFather();
1364 aMesh->AddHypothesis(aSubShape, anAlgo); //essayer avec _SMESHCorbaObj
1365 MESSAGE("Algorithms added ...");
1373 hdf_subgroupmyTag->CloseOnDisk();
1375 hdf_subgroupmyLevel1Tag->CloseOnDisk();
1378 GEOM::GEOM_Gen_var SMESH_Gen_i::getGeomEngine()
1380 MESSAGE("SMESH_Gen_i::getGeomEngine");
1381 SALOME_NamingService *_NS = SINGLETON_ < SALOME_NamingService >::Instance();
1382 ASSERT(SINGLETON_ < SALOME_NamingService >::IsAlreadyExisting());
1383 _NS->init_orb(_orb);
1384 SALOME_LifeCycleCORBA *myEnginesLifeCycle = new SALOME_LifeCycleCORBA(_NS);
1385 Engines::Component_var geomEngine =
1386 myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", "GEOM");
1387 GEOM::GEOM_Gen_var myGeomEngine = GEOM::GEOM_Gen::_narrow(geomEngine);
1388 return myGeomEngine;
1391 GEOM::GEOM_Shape_var SMESH_Gen_i::getShape(SALOMEDS::Study_var Study, char * refFromFile)
1393 MESSAGE("SMESH_Gen_i::getShape("<<Study<<","<<refFromFile<<")");
1394 SCRUTE(CORBA::is_nil(Study));
1395 SALOMEDS::SObject_var CSO = Study->FindObjectID(refFromFile);
1396 GEOM::GEOM_Shape_var aShape;
1398 if (!CORBA::is_nil(CSO))
1400 SALOMEDS::GenericAttribute_var anAttr;
1401 CSO->FindAttribute(anAttr, "AttributeIOR");
1402 if (!CORBA::is_nil(CSO))
1404 MESSAGE("The shape was not loaded. Try to load it.");
1405 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(getGeomEngine());
1406 SALOMEDS::SComponent_var SCO = SALOMEDS::SComponent::_narrow(Study->FindObject("Geometry"));
1407 SALOMEDS::StudyBuilder_var B = Study->NewBuilder();
1408 B->LoadWith(SCO,driver);
1409 CSO->FindAttribute(anAttr, "AttributeIOR");
1412 SALOMEDS::AttributeIOR_var anIOR =
1413 SALOMEDS::AttributeIOR::_narrow(anAttr);
1415 char *ShapeIOR = anIOR->Value();
1417 GEOM::GEOM_Shape::_narrow(_orb->string_to_object(ShapeIOR));
1422 void SMESH_Gen_i::loadMesh(char * name, HDFfile * hdf_file,
1423 char* meshfile, SALOMEDS::Study_var Study)
1425 MESSAGE("SMESH_Gen_i::loadMesh("<<name<<","<<meshfile<<")");
1427 char msgname[HDF_NAME_MAX_LEN + 1];
1429 char name_of_group[HDF_NAME_MAX_LEN + 1];
1432 atoi((string(name).substr(5, 5)).c_str());
1435 HDFgroup * hdfGroupMeshId = new HDFgroup(name, hdf_file);
1436 hdfGroupMeshId->OpenOnDisk();
1438 int nb_meshsubgroup = hdfGroupMeshId->nInternalObjects();
1439 SCRUTE(nb_meshsubgroup);
1441 //********** Loading of the file name where the data are stored
1442 strcpy(name_of_group, "Mesh data");
1443 HDFdataset * dataset =
1444 new HDFdataset(name_of_group, hdfGroupMeshId);
1445 dataset->OpenOnDisk();
1447 char *datafilename = new char[dataset->GetSize()];
1448 dataset->ReadFromDisk(datafilename);
1449 dataset->CloseOnDisk();
1450 MESSAGE("datafilename="<<datafilename<<" but this is ignored. We will read from "<<meshfile);
1451 datafilename=meshfile;
1453 //********** Loading of the reference on the shape
1454 //********** and mesh initialization
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 = Init(getGeomEngine(), Study->StudyId(), aShape, myMeshId);
1473 string iorString = _orb->object_to_string(myNewMesh);
1474 sprintf(objectId, "%ld", myNewMesh->GetId());
1475 string key=string("Mesh_")+string(objectId);
1476 MESSAGE("IOR of "<<key<<" is "<< iorString)
1477 _SMESHCorbaObj[key] = iorString;
1481 //********** Loading of mesh data
1482 if (strcmp(datafilename, "No data") != 0)
1484 StudyContext_iStruct *myStudyContext =
1485 _mapStudyContext_i[Study->StudyId()];
1486 int meshId = myNewMesh->GetId();
1487 SMESH_Mesh_i *meshServant =
1488 myStudyContext->mapMesh_i[meshId];
1489 ::SMESH_Mesh & myLocMesh = meshServant->GetImpl();
1490 SMESHDS_Mesh *mySMESHDSMesh = myLocMesh.GetMeshDS();
1492 Mesh_Reader *myReader = SMESHDriver::GetMeshReader("MED");
1493 myReader->SetMesh(mySMESHDSMesh);
1494 myReader->SetMeshId(myMeshId);
1495 myReader->SetFile(datafilename);
1497 mySMESHDSMesh->logFullUpdate();
1498 MESSAGE("Loaded a mesh with " << mySMESHDSMesh->NbNodes() <<" nodes");
1503 //else if (strcmp(msgname,"Applied Hypothesis")==0) {
1504 for (int ii = 0; ii < nb_meshsubgroup; ii++)
1506 hdfGroupMeshId->InternalObjectIndentify(ii, msgname);
1507 if (strcmp(msgname, "Mesh data") == 0)
1511 else if (strcmp(msgname, "Ref on shape") == 0)
1515 else if (strcmp(msgname, "Applied Hypothesis") == 0)
1517 loadAppliedHypothesis(hdfGroupMeshId, _found, Study, myNewMesh,
1520 else if (strcmp(msgname, "Applied Algorithms") == 0)
1522 loadAppliedAlgorithms(hdfGroupMeshId, _found, Study, myNewMesh,
1525 else if (string(msgname).substr(0, 9) == string("SubMeshes"))
1527 loadSubMeshes(hdfGroupMeshId, msgname, Study, myNewMesh);
1530 hdfGroupMeshId->CloseOnDisk();
1534 * Load the part of the study related to SMESH.
1536 bool SMESH_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
1537 const SALOMEDS::TMPFile & theStream, const char *theURL, bool isMultiFile)
1539 MESSAGE("SMESH_Gen_i::Load");
1540 // Get temporary files location
1541 TCollection_AsciiString tmpDir =
1542 isMultiFile ? TCollection_AsciiString((char *)theURL) : SALOMEDS_Tool::
1545 // Convert the stream into sequence of files to process
1546 SALOMEDS::ListOfFileNames_var aFileSeq =
1547 SALOMEDS_Tool::PutStreamToFiles(theStream, tmpDir.ToCString(),
1550 TCollection_AsciiString aStudyName("");
1553 (SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
1555 // Set names of temporary files
1556 TCollection_AsciiString filename =
1557 tmpDir + aStudyName + TCollection_AsciiString("_SMESH.hdf");
1558 TCollection_AsciiString hypofile =
1559 tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Hypo.txt");
1560 TCollection_AsciiString algofile =
1561 tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Algo.txt");
1562 TCollection_AsciiString meshfile =
1563 tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Mesh.med");
1565 SALOMEDS::Study_var Study = theComponent->GetStudy();
1566 int studyId = Study->StudyId();
1569 SALOMEDS::AttributeName_var aName;
1571 SALOMEDS::SComponent_var fathergeom = Study->FindComponent("GEOM");
1572 SALOMEDS::SComponent_var myGeomSComp =
1573 SALOMEDS::SComponent::_narrow(fathergeom);
1576 char name[HDF_NAME_MAX_LEN + 1];
1577 map < int, HDFgroup * > hdf_subgroup;
1580 //************* HDF file opening
1581 HDFfile *hdf_file = new HDFfile(filename.ToCString());
1584 hdf_file->OpenOnDisk(HDF_RDONLY);
1588 MESSAGE("Load(): " << filename << " not found!");
1592 //****************************
1594 int nb_group = hdf_file->nInternalObjects();
1596 for (int i = 0; i < nb_group; i++)
1598 hdf_file->InternalObjectIndentify(i, name);
1599 if (strcmp(name, "Hypothesis") == 0)
1600 loadHypothesis(name, hdf_file, hypofile.ToCString(), studyId);
1601 else if (strcmp(name, "Algorithms") == 0)
1602 loadAlgorithms(name, hdf_file, algofile.ToCString(), studyId);
1603 else if (string(name).substr(0, 4) == string("Mesh"))
1604 loadMesh(name, hdf_file, meshfile.ToCString(), Study);
1607 MESSAGE("End of SMESH_Gen::Load");
1609 hdf_file->CloseOnDisk();
1611 // Remove temporary files created from the stream
1613 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(),
1619 bool SMESH_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
1620 const SALOMEDS::TMPFile & theStream, const char *theURL, bool isMultiFile)
1622 return Load(theComponent, theStream, theURL, isMultiFile);
1625 //=============================================================================
1629 //=============================================================================
1631 void SMESH_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
1634 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
1635 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
1636 for (; itBig->More(); itBig->Next())
1638 SALOMEDS::SObject_var gotBranch = itBig->Value();
1640 // branch 1 : hypothesis
1641 if (gotBranch->Tag() == Tag_HypothesisRoot ||
1642 gotBranch->Tag() == Tag_AlgorithmsRoot)
1644 SALOMEDS::ChildIterator_var it =
1645 aStudy->NewChildIterator(gotBranch);
1646 for (; it->More(); it->Next())
1648 SALOMEDS::SObject_var mySObject = it->Value();
1649 SALOMEDS::GenericAttribute_var anAttr;
1650 SALOMEDS::AttributeIOR_var anIOR;
1651 if (mySObject->FindAttribute(anAttr, "AttributeIOR"))
1653 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1654 SMESH::SMESH_Hypothesis_var myHyp =
1655 SMESH::SMESH_Hypothesis::_narrow(_orb->
1656 string_to_object(anIOR->Value()));
1658 sprintf(objectId, "%ld", myHyp->GetId());
1659 // cout<<"********** delete Hyp "<<objectId<<endl;
1660 _SMESHCorbaObj.erase(string("Hypo_") + string(objectId));
1662 SMESH::SMESH_Hypothesis::_narrow(_orb->
1663 string_to_object(anIOR->Value()));
1667 // branch 2 : algorithms
1668 else if (gotBranch->Tag() >= 3)
1670 SALOMEDS::ChildIterator_var it =
1671 aStudy->NewChildIterator(gotBranch);
1672 for (; it->More(); it->Next())
1674 SALOMEDS::SObject_var mySObject = it->Value();
1675 SALOMEDS::GenericAttribute_var anAttr;
1676 SALOMEDS::AttributeIOR_var anIOR;
1677 if (mySObject->FindAttribute(anAttr, "AttributeIOR"))
1679 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1680 SMESH::SMESH_Mesh_var myMesh =
1681 SMESH::SMESH_Mesh::_narrow(_orb->
1682 string_to_object(anIOR->Value()));
1683 if (!myMesh->_is_nil())
1686 sprintf(objectId, "%ld", myMesh->GetId());
1687 // cout<<"********** delete Mesh "<<objectId<<endl;
1688 _SMESHCorbaObj.erase(string("Mesh_") +
1690 CORBA::release(myMesh);
1694 SMESH::SMESH_subMesh_var mySubMesh =
1695 SMESH::SMESH_subMesh::_narrow(_orb->
1696 string_to_object(anIOR->Value()));
1697 if (!mySubMesh->_is_nil())
1700 sprintf(objectId, "%ld", mySubMesh->GetId());
1701 // cout<<"********** delete SubMesh "<<objectId<<endl;
1702 _SMESHCorbaObj.erase(string("SubMesh_") +
1704 CORBA::release(mySubMesh);
1713 //=============================================================================
1717 //=============================================================================
1719 char *SMESH_Gen_i::ComponentDataType()
1721 MESSAGE("SMESH_Gen_i::ComponentDataType");
1722 return strdup("SMESH");
1725 //=============================================================================
1729 //=============================================================================
1731 char *SMESH_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
1732 const char *IORString, CORBA::Boolean isMultiFile, CORBA::Boolean isASCII)
1734 MESSAGE("SMESH_Gen_i::IORToLocalPersistentID");
1738 SMESH::SMESH_Algo_var myAlgo =
1739 SMESH::SMESH_Algo::_narrow(_orb->string_to_object(IORString));
1740 if (!CORBA::is_nil(myAlgo))
1742 string prefix = "Hypo_";
1743 sprintf(objectId, "%ld", myAlgo->GetId());
1744 string lpID = prefix + string(objectId);
1745 return CORBA::string_dup(lpID.c_str());
1749 SMESH::SMESH_Hypothesis_var myHypo =
1750 SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(IORString));
1751 if (!CORBA::is_nil(myHypo))
1753 string prefix = "Hypo_";
1754 sprintf(objectId, "%ld", myHypo->GetId());
1755 string lpID = prefix + string(objectId);
1756 return CORBA::string_dup(lpID.c_str());
1760 SMESH::SMESH_Mesh_var myMesh =
1761 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(IORString));
1762 if (!CORBA::is_nil(myMesh))
1764 string prefix = "Mesh_";
1765 sprintf(objectId, "%ld", myMesh->GetId());
1766 string lpID = prefix + string(objectId);
1767 return CORBA::string_dup(lpID.c_str());
1771 SMESH::SMESH_subMesh_var mySubMesh =
1772 SMESH::SMESH_subMesh::_narrow(_orb->
1773 string_to_object(IORString));
1774 if (!CORBA::is_nil(mySubMesh))
1776 string prefix = "SubMesh_";
1777 sprintf(objectId, "%ld", mySubMesh->GetId());
1778 string lpID = prefix + string(objectId);
1779 return CORBA::string_dup(lpID.c_str());
1782 return (strdup("no object"));
1788 //=============================================================================
1792 //=============================================================================
1794 char *SMESH_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
1795 const char *aLocalPersistentID,
1796 CORBA::Boolean isMultiFile, CORBA::Boolean isASCII)
1798 MESSAGE("SMESH_Gen_i::LocalPersistentIDToIOR");
1799 SCRUTE(aLocalPersistentID);
1800 string clef = string(aLocalPersistentID);
1801 SCRUTE(_SMESHCorbaObj[clef].c_str());
1802 return CORBA::string_dup(_SMESHCorbaObj[clef].c_str());
1805 //=============================================================================
1809 //=============================================================================
1811 SMESH_topo *SMESH_Gen_i::ExploreMainShape(GEOM::GEOM_Gen_ptr geomEngine,
1812 CORBA::Long studyId, GEOM::GEOM_Shape_ptr aShape)
1814 MESSAGE("SMESH_Mesh_i::ExploreMainShape");
1815 // _narrow() duplicates the reference and check the type
1816 GEOM::GEOM_Gen_var geom = GEOM::GEOM_Gen::_narrow(geomEngine);
1817 GEOM::GEOM_Shape_var myShape = GEOM::GEOM_Shape::_narrow(aShape);
1819 if (CORBA::is_nil(geom))
1820 THROW_SALOME_CORBA_EXCEPTION("bad geom reference", SALOME::BAD_PARAM);
1821 if (CORBA::is_nil(myShape))
1822 THROW_SALOME_CORBA_EXCEPTION("bad shape reference", SALOME::BAD_PARAM);
1824 SCRUTE(myShape->Name());
1825 geom->GetCurrentStudy(studyId);
1827 TopoDS_Shape mainShape = _ShapeReader->GetShape(geom, myShape);
1830 // create an SMESH_topo object for the mainShape
1832 SMESH_topo *myTopo = new SMESH_topo();
1835 // explore local TopoDS_Shape, store reference of local TopoDS subShapes
1837 for (TopExp_Explorer exp(mainShape, TopAbs_COMPOUND); exp.More();
1840 const TopoDS_Compound & E = TopoDS::Compound(exp.Current());
1841 int i = myTopo->_myShapes[TopAbs_COMPOUND].Add(E);
1844 for (TopExp_Explorer exp(mainShape, TopAbs_COMPSOLID); exp.More();
1847 const TopoDS_CompSolid & E = TopoDS::CompSolid(exp.Current());
1848 int i = myTopo->_myShapes[TopAbs_COMPSOLID].Add(E);
1851 for (TopExp_Explorer exp(mainShape, TopAbs_SOLID); exp.More(); exp.Next())
1853 const TopoDS_Solid & E = TopoDS::Solid(exp.Current());
1854 int i = myTopo->_myShapes[TopAbs_SOLID].Add(E);
1857 for (TopExp_Explorer exp(mainShape, TopAbs_SHELL); exp.More(); exp.Next())
1859 const TopoDS_Shell & E = TopoDS::Shell(exp.Current());
1860 int i = myTopo->_myShapes[TopAbs_SHELL].Add(E);
1863 for (TopExp_Explorer exp(mainShape, TopAbs_FACE); exp.More(); exp.Next())
1865 const TopoDS_Face & E = TopoDS::Face(exp.Current());
1866 int i = myTopo->_myShapes[TopAbs_FACE].Add(E);
1869 for (TopExp_Explorer exp(mainShape, TopAbs_WIRE); exp.More(); exp.Next())
1871 const TopoDS_Wire & E = TopoDS::Wire(exp.Current());
1872 int i = myTopo->_myShapes[TopAbs_WIRE].Add(E);
1875 for (TopExp_Explorer exp(mainShape, TopAbs_EDGE); exp.More(); exp.Next())
1877 const TopoDS_Edge & E = TopoDS::Edge(exp.Current());
1878 int i = myTopo->_myShapes[TopAbs_EDGE].Add(E);
1881 for (TopExp_Explorer exp(mainShape, TopAbs_VERTEX); exp.More(); exp.Next())
1883 const TopoDS_Vertex & E = TopoDS::Vertex(exp.Current());
1884 int i = myTopo->_myShapes[TopAbs_VERTEX].Add(E);
1888 // explore subShapes of distant CORBA object,
1889 // associate distant CORBA subShape references
1890 // with local reference to local TopoDS subShape
1892 string filenode = "toposhape.txt";
1893 ofstream fic(filenode.c_str());
1895 for (int shapeType = TopAbs_COMPOUND; shapeType < TopAbs_SHAPE; shapeType++)
1897 fic << "shape type : " << SMESH_shapeTypeNames[shapeType];
1899 GEOM::GEOM_Gen::ListOfGeomShapes_var subShapes
1900 = geom->SubShapeAll(myShape, shapeType);
1901 int nbSubShapes = subShapes->length();
1902 int nbLocal = myTopo->_myShapes[shapeType].Extent();
1903 fic << " - number of elements: " << nbSubShapes << endl;
1904 ASSERT(nbSubShapes == nbLocal);
1906 for (int i = 0; i < nbSubShapes; i++)
1908 GEOM::GEOM_Shape_var aSubShape = subShapes[i];
1909 string idShape = SMESH_topo::GetShapeLocalId(aSubShape);
1910 fic << " " << idShape;
1912 TopoDS_Shape aLocShape = _ShapeReader->GetShape(geom, aSubShape);
1913 for (int j = 1; j <= nbLocal; j++)
1914 if (aLocShape.IsSame(myTopo->_myShapes[shapeType].FindKey(j)))
1916 MESSAGE(" --- trouve = " << j);
1917 myTopo->_mapIndShapes[shapeType][idShape] = j;
1918 fic << " --- trouve = " << j;
1930 * Import a mesh from a file
1931 * @param fileName file name to be imported
1932 * @param fileType Currently it could be either "DAT", "UNV" or "MED".
1934 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Import(CORBA::Long studyId,
1935 const char *fileName, const char *fileType)
1937 MESSAGE("SMESH_Gen_I::Import");
1938 SMESH_Mesh_i *meshServant;
1941 if (_mapStudyContext_i.find(studyId) == _mapStudyContext_i.end())
1943 _mapStudyContext_i[studyId] = new StudyContext_iStruct;
1945 StudyContext_iStruct *myStudyContext = _mapStudyContext_i[studyId];
1947 // create a new mesh object
1948 SMESH_Mesh * meshImpl=_impl.Import(studyId, fileName, fileType);
1950 // create a new mesh object servant, store it in a map in study context
1951 meshServant = new SMESH_Mesh_i(this, NULL, studyId, meshImpl);
1952 myStudyContext->mapMesh_i[meshImpl->GetId()] = meshServant;
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();