2 //=============================================================================
3 // File : SMESH_Mesh_i.cxx
4 // Created : lun mai 6 13:41:55 CEST 2002
5 // Author : Paul RASCLE, EDF
7 // Copyright : EDF 2002
9 //=============================================================================
12 #include "SMESH_Mesh_i.hxx"
13 #include "SMESH_subMesh_i.hxx"
14 #include "SMESH_MEDMesh_i.hxx"
16 #include "Utils_CorbaException.hxx"
17 #include "utilities.h"
19 #include "SALOME_NamingService.hxx"
20 #include "Utils_SINGLETON.hxx"
23 #include "TCollection_AsciiString.hxx"
24 // #include "SMESHDS_ListOfAsciiString.hxx"
25 // #include "SMESHDS_ListIteratorOfListOfAsciiString.hxx"
26 #include "TColStd_ListOfInteger.hxx"
27 #include "TColStd_ListOfReal.hxx"
28 #include "TColStd_ListIteratorOfListOfInteger.hxx"
29 #include "TColStd_ListIteratorOfListOfReal.hxx"
30 #include "SMESHDS_Command.hxx"
31 #include "SMESHDS_CommandType.hxx"
32 #include "SMESHDS_ListOfCommand.hxx"
33 #include "SMESHDS_ListIteratorOfListOfCommand.hxx"
34 #include "Handle_SMESHDS_Command.hxx"
36 #include "SMESH_MeshEditor_i.hxx"
41 //**** SMESHDS en champ
43 //=============================================================================
47 //=============================================================================
49 SMESH_Mesh_i::SMESH_Mesh_i()
51 MESSAGE("SMESH_Mesh_i: default constructor, not for use");
55 //=============================================================================
59 //=============================================================================
61 SMESH_Mesh_i::SMESH_Mesh_i(SMESH_Gen_i* gen_i,
62 GEOM::GEOM_Gen_ptr geomEngine,
66 MESSAGE("SMESH_Mesh_i");
69 _geom = GEOM::GEOM_Gen::_narrow(geomEngine);
73 //=============================================================================
77 //=============================================================================
79 SMESH_Mesh_i::~SMESH_Mesh_i()
81 MESSAGE("~SMESH_Mesh_i");
86 //=============================================================================
90 //=============================================================================
92 CORBA::Boolean SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
93 SMESH::SMESH_Hypothesis_ptr anHyp)
94 throw (SALOME::SALOME_Exception)
96 MESSAGE("AddHypothesis");
97 // **** proposer liste de subShape (selection multiple)
99 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
100 if (CORBA::is_nil(mySubShape))
101 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference", \
104 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
105 if (CORBA::is_nil(myHyp))
106 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference", \
111 TopoDS_Shape myLocSubShape=
112 _gen_i->_ShapeReader->GetShape(_geom,mySubShape);
113 int hypId = myHyp->GetId();
114 ret = _impl->AddHypothesis(myLocSubShape, hypId);
116 catch (SALOME_Exception& S_ex)
118 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), \
124 //=============================================================================
128 //=============================================================================
131 SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
132 SMESH::SMESH_Hypothesis_ptr anHyp)
133 throw (SALOME::SALOME_Exception)
135 MESSAGE("RemoveHypothesis");
136 // **** proposer liste de subShape (selection multiple)
138 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
139 if (CORBA::is_nil(mySubShape))
140 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference", \
143 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
144 if (CORBA::is_nil(myHyp))
145 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference", \
151 TopoDS_Shape myLocSubShape=
152 _gen_i->_ShapeReader->GetShape(_geom,mySubShape);
153 int hypId = myHyp->GetId();
154 ret = _impl->RemoveHypothesis(myLocSubShape, hypId);
156 catch (SALOME_Exception& S_ex)
158 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), \
164 //=============================================================================
168 //=============================================================================
170 SMESH::ListOfHypothesis*
171 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Shape_ptr aSubShape)
172 throw (SALOME::SALOME_Exception)
174 MESSAGE("GetHypothesisList");
178 //=============================================================================
182 //=============================================================================
183 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetElementsOnShape(GEOM::GEOM_Shape_ptr aSubShape)
184 throw (SALOME::SALOME_Exception)
186 MESSAGE("SMESH_Mesh_i::GetElementsOnShape");
187 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
188 if (CORBA::is_nil(mySubShape))
189 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference", \
195 SMESH_subMesh_i* subMeshServant;
196 TopoDS_Shape myLocSubShape
197 = _gen_i->_ShapeReader->GetShape(_geom,mySubShape);
199 //Get or Create the SMESH_subMesh object implementation
201 ::SMESH_subMesh * mySubMesh
202 = _impl->GetSubMesh(myLocSubShape);
203 subMeshId = mySubMesh->GetId();
205 // create a new subMesh object servant if there is none for the shape
207 if (_mapSubMesh.find(subMeshId) != _mapSubMesh.end())
209 ASSERT(_mapSubMesh_i.find(subMeshId) != _mapSubMesh_i.end());
210 subMeshServant = _mapSubMesh_i[subMeshId];
214 // create and activate the CORBA servant of Mesh
215 subMeshServant = new SMESH_subMesh_i(_gen_i, this, subMeshId);
216 SMESH::SMESH_subMesh_var subMesh
217 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
218 _mapSubMesh[subMeshId] = mySubMesh;
219 _mapSubMesh_i[subMeshId] = subMeshServant;
220 _mapSubMeshIor[subMeshId]
221 = SMESH::SMESH_subMesh::_duplicate(subMesh);
224 catch (SALOME_Exception& S_ex)
226 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
229 ASSERT(_mapSubMeshIor.find(subMeshId) != _mapSubMeshIor.end());
230 return SMESH::SMESH_subMesh::_duplicate(_mapSubMeshIor[subMeshId]);
233 //=============================================================================
237 //=============================================================================
239 SMESH::log_array* SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
240 throw (SALOME::SALOME_Exception)
242 MESSAGE("SMESH_Mesh_i::GetLog");
244 SMESH::log_array_var aLog;
247 const SMESHDS_ListOfCommand& logDS =_impl->GetLog();
248 aLog = new SMESH::log_array;
250 int lg = logDS.Extent();
253 SMESHDS_ListIteratorOfListOfCommand its(logDS);
256 Handle(SMESHDS_Command) com = its.Value();
257 int comType = com->GetType();
259 int lgcom = com->GetNumber();
261 const TColStd_ListOfInteger& intList = com->GetIndexes();
262 int inum = intList.Extent();
264 TColStd_ListIteratorOfListOfInteger ii(intList);
265 const TColStd_ListOfReal& coordList = com->GetCoords();
266 int rnum = coordList.Extent();
268 TColStd_ListIteratorOfListOfReal ir(coordList);
269 aLog[indexLog].commandType = comType;
270 aLog[indexLog].number = lgcom;
271 aLog[indexLog].coords.length(rnum);
272 aLog[indexLog].indexes.length(inum);
273 for (int i=0; i<rnum; i++)
275 aLog[indexLog].coords[i] = ir.Value();
276 //MESSAGE(" "<<i<<" "<<ir.Value());
279 for (int i=0; i<inum; i++)
281 aLog[indexLog].indexes[i] = ii.Value();
282 //MESSAGE(" "<<i<<" "<<ii.Value());
288 if (clearAfterGet) _impl->ClearLog();
290 catch (SALOME_Exception& S_ex)
292 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
297 // SMESH::string_array* SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
298 // throw (SALOME::SALOME_Exception)
300 // MESSAGE("SMESH_Mesh_i::GetLog");
302 // SMESH::string_array_var aLog;
305 // const SMESHDS_ListOfCommand& logDS =_impl->GetLog();
306 // aLog = new SMESH::string_array;
309 // int lg = logDS.Extent();
311 // SMESHDS_ListIteratorOfListOfCommand its(logDS);
314 // Handle(SMESHDS_Command) com = its.Value();
315 // int comType = com->GetType();
317 // int lgcom = com->GetNumber();
320 // aLog->length(logSize);
322 // const TColStd_ListOfInteger& intList = com->GetIndexes();
323 // TColStd_ListIteratorOfListOfInteger ii(intList);
324 // const TColStd_ListOfReal& coordList = com->GetCoords();
325 // TColStd_ListIteratorOfListOfReal ir(coordList);
326 // for (int icom = 1; icom <= lgcom; icom++)
331 // case SMESHDS_AddNode:
332 // S << "AddNode " << ii.Value(); ii.Next();
333 // S << " " << ir.Value(); ir.Next();
334 // S << " " << ir.Value(); ir.Next();
335 // S << " " << ir.Value(); ir.Next();
337 // case SMESHDS_AddEdge:
338 // S << "AddEdge " << ii.Value(); ii.Next();
339 // S << " " << ii.Value(); ii.Next();
340 // S << " " << ii.Value(); ii.Next();
342 // case SMESHDS_AddTriangle:
343 // S << "AddFace " << ii.Value(); ii.Next();
344 // S << " " << ii.Value(); ii.Next();
345 // S << " " << ii.Value(); ii.Next();
346 // S << " " << ii.Value(); ii.Next();
348 // case SMESHDS_AddQuadrangle:
349 // S << "AddFace " << ii.Value(); ii.Next();
350 // S << " " << ii.Value(); ii.Next();
351 // S << " " << ii.Value(); ii.Next();
352 // S << " " << ii.Value(); ii.Next();
353 // S << " " << ii.Value(); ii.Next();
355 // case SMESHDS_AddTetrahedron:
356 // S << "AddVolume " << ii.Value(); ii.Next();
357 // S << " " << ii.Value(); ii.Next();
358 // S << " " << ii.Value(); ii.Next();
359 // S << " " << ii.Value(); ii.Next();
360 // S << " " << ii.Value(); ii.Next();
362 // case SMESHDS_AddPyramid:
363 // S << "AddVolume " << ii.Value(); ii.Next();
364 // S << " " << ii.Value(); ii.Next();
365 // S << " " << ii.Value(); ii.Next();
366 // S << " " << ii.Value(); ii.Next();
367 // S << " " << ii.Value(); ii.Next();
368 // S << " " << ii.Value(); ii.Next();
370 // case SMESHDS_AddPrism:
371 // S << "AddVolume " << ii.Value(); ii.Next();
372 // S << " " << ii.Value(); ii.Next();
373 // S << " " << ii.Value(); ii.Next();
374 // S << " " << ii.Value(); ii.Next();
375 // S << " " << ii.Value(); ii.Next();
376 // S << " " << ii.Value(); ii.Next();
377 // S << " " << ii.Value(); ii.Next();
379 // case SMESHDS_AddHexahedron:
380 // S << "AddVolume " << ii.Value(); ii.Next();
381 // S << " " << ii.Value(); ii.Next();
382 // S << " " << ii.Value(); ii.Next();
383 // S << " " << ii.Value(); ii.Next();
384 // S << " " << ii.Value(); ii.Next();
385 // S << " " << ii.Value(); ii.Next();
386 // S << " " << ii.Value(); ii.Next();
387 // S << " " << ii.Value(); ii.Next();
388 // S << " " << ii.Value(); ii.Next();
390 // case SMESHDS_RemoveNode:
391 // S << "RemoveNode " << ii.Value(); ii.Next();
393 // case SMESHDS_RemoveElement:
394 // S << "RemoveElement " << ii.Value(); ii.Next();
400 // string ch = S.str();
402 // aLog[indexLog++] = CORBA::string_dup(ch.c_str());
406 // if (clearAfterGet) _impl->ClearLog();
408 // catch (SALOME_Exception& S_ex)
410 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
412 // return aLog._retn();
415 //=============================================================================
419 //=============================================================================
421 void SMESH_Mesh_i::ClearLog()
422 throw (SALOME::SALOME_Exception)
424 MESSAGE("SMESH_Mesh_i::ClearLog");
428 //=============================================================================
432 //=============================================================================
434 CORBA::Long SMESH_Mesh_i::GetId()
435 throw (SALOME::SALOME_Exception)
437 MESSAGE("SMESH_Mesh_i::GetId");
441 //=============================================================================
445 //=============================================================================
447 CORBA::Long SMESH_Mesh_i::GetStudyId()
448 throw (SALOME::SALOME_Exception)
452 //=============================================================================
456 //=============================================================================
458 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh* impl)
460 MESSAGE("SMESH_Mesh_i::SetImpl");
464 //=============================================================================
468 //=============================================================================
470 ::SMESH_Mesh& SMESH_Mesh_i::GetImpl()
472 MESSAGE("SMESH_Mesh_i::GetImpl()");
476 //=============================================================================
480 //=============================================================================
482 GEOM::GEOM_Gen_ptr SMESH_Mesh_i::GetGeomEngine()
484 MESSAGE("SMESH_Mesh_i::GetGeomEngine");
485 return GEOM::GEOM_Gen::_duplicate(_geom);
488 //=============================================================================
492 //=============================================================================
494 void SMESH_Mesh_i::SetIor(SMESH::SMESH_Mesh_ptr myIor)
496 MESSAGE("SMESH_Mesh_i::SetIor");
497 _myIor = SMESH::SMESH_Mesh::_duplicate(myIor);
498 ASSERT(! CORBA::is_nil(_myIor));
501 //=============================================================================
505 //=============================================================================
507 SMESH::SMESH_Mesh_ptr SMESH_Mesh_i::GetIor()
509 MESSAGE("SMESH_Mesh_i::GetIor");
510 ASSERT(! CORBA::is_nil(_myIor));
511 return SMESH::SMESH_Mesh::_duplicate(_myIor);
513 //=============================================================================
517 //=============================================================================
519 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
521 SMESH_MeshEditor_i* aMeshEditor = new SMESH_MeshEditor_i(_impl->GetMeshDS());
522 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
523 return aMesh._retn();
526 //=============================================================================
530 //=============================================================================
532 void SMESH_Mesh_i::ExportMED( const char* file )
533 throw (SALOME::SALOME_Exception)
535 _impl->ExportMED( file );
537 void SMESH_Mesh_i::ExportDAT( const char* file )
538 throw (SALOME::SALOME_Exception)
540 _impl->ExportDAT( file );
542 void SMESH_Mesh_i::ExportUNV( const char* file )
543 throw (SALOME::SALOME_Exception)
545 _impl->ExportUNV( file );
549 //=============================================================================
553 //=============================================================================
555 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()
556 throw (SALOME::SALOME_Exception)
558 SMESH_MEDMesh_i* aMedMesh = new SMESH_MEDMesh_i( this );
559 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
560 return aMesh._retn();
563 //=============================================================================
567 //=============================================================================
568 CORBA::Long SMESH_Mesh_i::NbNodes()
569 throw (SALOME::SALOME_Exception)
571 return _impl->NbNodes();
574 //=============================================================================
578 //=============================================================================
579 CORBA::Long SMESH_Mesh_i::NbEdges()
580 throw (SALOME::SALOME_Exception)
582 return _impl->NbEdges();
585 //=============================================================================
589 //=============================================================================
590 CORBA::Long SMESH_Mesh_i::NbFaces()
591 throw (SALOME::SALOME_Exception)
593 return _impl->NbFaces();
595 CORBA::Long SMESH_Mesh_i::NbTriangles()
596 throw (SALOME::SALOME_Exception)
598 return _impl->NbTriangles();
600 CORBA::Long SMESH_Mesh_i::NbQuadrangles()
601 throw (SALOME::SALOME_Exception)
603 return _impl->NbQuadrangles();
606 //=============================================================================
610 //=============================================================================
611 CORBA::Long SMESH_Mesh_i::NbVolumes()
612 throw (SALOME::SALOME_Exception)
614 return _impl->NbVolumes();
616 CORBA::Long SMESH_Mesh_i::NbTetras()
617 throw (SALOME::SALOME_Exception)
619 return _impl->NbTetras();
621 CORBA::Long SMESH_Mesh_i::NbHexas()
622 throw (SALOME::SALOME_Exception)
624 return _impl->NbHexas();
627 //=============================================================================
631 //=============================================================================
632 CORBA::Long SMESH_Mesh_i::NbSubMesh()
633 throw (SALOME::SALOME_Exception)
635 return _impl->NbSubMesh();