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_Mesh_i.cxx
25 // Author : Paul RASCLE, EDF
31 #include "SMESH_Mesh_i.hxx"
32 #include "SMESH_subMesh_i.hxx"
33 #include "SMESH_MEDMesh_i.hxx"
35 #include "Utils_CorbaException.hxx"
36 #include "utilities.h"
38 #include "SALOME_NamingService.hxx"
39 #include "Utils_SINGLETON.hxx"
42 #include "TCollection_AsciiString.hxx"
43 // #include "SMESHDS_ListOfAsciiString.hxx"
44 // #include "SMESHDS_ListIteratorOfListOfAsciiString.hxx"
45 #include "TColStd_ListOfInteger.hxx"
46 #include "TColStd_ListOfReal.hxx"
47 #include "TColStd_ListIteratorOfListOfInteger.hxx"
48 #include "TColStd_ListIteratorOfListOfReal.hxx"
49 #include "SMESHDS_Command.hxx"
50 #include "SMESHDS_CommandType.hxx"
51 #include "SMESHDS_ListOfCommand.hxx"
52 #include "SMESHDS_ListIteratorOfListOfCommand.hxx"
53 #include "Handle_SMESHDS_Command.hxx"
55 #include "SMESH_MeshEditor_i.hxx"
60 //**** SMESHDS en champ
62 //=============================================================================
66 //=============================================================================
68 SMESH_Mesh_i::SMESH_Mesh_i()
70 MESSAGE("SMESH_Mesh_i: default constructor, not for use");
74 //=============================================================================
78 //=============================================================================
80 SMESH_Mesh_i::SMESH_Mesh_i(SMESH_Gen_i* gen_i,
81 GEOM::GEOM_Gen_ptr geomEngine,
85 MESSAGE("SMESH_Mesh_i");
88 _geom = GEOM::GEOM_Gen::_narrow(geomEngine);
92 //=============================================================================
96 //=============================================================================
98 SMESH_Mesh_i::~SMESH_Mesh_i()
100 MESSAGE("~SMESH_Mesh_i");
105 //=============================================================================
109 //=============================================================================
111 CORBA::Boolean SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
112 SMESH::SMESH_Hypothesis_ptr anHyp)
113 throw (SALOME::SALOME_Exception)
115 MESSAGE("AddHypothesis");
116 // **** proposer liste de subShape (selection multiple)
118 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
119 if (CORBA::is_nil(mySubShape))
120 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference", \
123 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
124 if (CORBA::is_nil(myHyp))
125 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference", \
130 TopoDS_Shape myLocSubShape=
131 _gen_i->_ShapeReader->GetShape(_geom,mySubShape);
132 int hypId = myHyp->GetId();
133 ret = _impl->AddHypothesis(myLocSubShape, hypId);
135 catch (SALOME_Exception& S_ex)
137 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), \
143 //=============================================================================
147 //=============================================================================
150 SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
151 SMESH::SMESH_Hypothesis_ptr anHyp)
152 throw (SALOME::SALOME_Exception)
154 MESSAGE("RemoveHypothesis");
155 // **** proposer liste de subShape (selection multiple)
157 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
158 if (CORBA::is_nil(mySubShape))
159 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference", \
162 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
163 if (CORBA::is_nil(myHyp))
164 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference", \
170 TopoDS_Shape myLocSubShape=
171 _gen_i->_ShapeReader->GetShape(_geom,mySubShape);
172 int hypId = myHyp->GetId();
173 ret = _impl->RemoveHypothesis(myLocSubShape, hypId);
175 catch (SALOME_Exception& S_ex)
177 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), \
183 //=============================================================================
187 //=============================================================================
189 SMESH::ListOfHypothesis*
190 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Shape_ptr aSubShape)
191 throw (SALOME::SALOME_Exception)
193 MESSAGE("GetHypothesisList");
197 //=============================================================================
201 //=============================================================================
202 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetElementsOnShape(GEOM::GEOM_Shape_ptr aSubShape)
203 throw (SALOME::SALOME_Exception)
205 MESSAGE("SMESH_Mesh_i::GetElementsOnShape");
206 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
207 if (CORBA::is_nil(mySubShape))
208 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference", \
214 SMESH_subMesh_i* subMeshServant;
215 TopoDS_Shape myLocSubShape
216 = _gen_i->_ShapeReader->GetShape(_geom,mySubShape);
218 //Get or Create the SMESH_subMesh object implementation
220 ::SMESH_subMesh * mySubMesh
221 = _impl->GetSubMesh(myLocSubShape);
222 subMeshId = mySubMesh->GetId();
224 // create a new subMesh object servant if there is none for the shape
226 if (_mapSubMesh.find(subMeshId) != _mapSubMesh.end())
228 ASSERT(_mapSubMesh_i.find(subMeshId) != _mapSubMesh_i.end());
229 subMeshServant = _mapSubMesh_i[subMeshId];
233 // create and activate the CORBA servant of Mesh
234 subMeshServant = new SMESH_subMesh_i(_gen_i, this, subMeshId);
235 SMESH::SMESH_subMesh_var subMesh
236 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
237 _mapSubMesh[subMeshId] = mySubMesh;
238 _mapSubMesh_i[subMeshId] = subMeshServant;
239 _mapSubMeshIor[subMeshId]
240 = SMESH::SMESH_subMesh::_duplicate(subMesh);
243 catch (SALOME_Exception& S_ex)
245 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
248 ASSERT(_mapSubMeshIor.find(subMeshId) != _mapSubMeshIor.end());
249 return SMESH::SMESH_subMesh::_duplicate(_mapSubMeshIor[subMeshId]);
252 //=============================================================================
256 //=============================================================================
258 SMESH::log_array* SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
259 throw (SALOME::SALOME_Exception)
261 MESSAGE("SMESH_Mesh_i::GetLog");
263 SMESH::log_array_var aLog;
266 const SMESHDS_ListOfCommand& logDS =_impl->GetLog();
267 aLog = new SMESH::log_array;
269 int lg = logDS.Extent();
272 SMESHDS_ListIteratorOfListOfCommand its(logDS);
275 Handle(SMESHDS_Command) com = its.Value();
276 int comType = com->GetType();
278 int lgcom = com->GetNumber();
280 const TColStd_ListOfInteger& intList = com->GetIndexes();
281 int inum = intList.Extent();
283 TColStd_ListIteratorOfListOfInteger ii(intList);
284 const TColStd_ListOfReal& coordList = com->GetCoords();
285 int rnum = coordList.Extent();
287 TColStd_ListIteratorOfListOfReal ir(coordList);
288 aLog[indexLog].commandType = comType;
289 aLog[indexLog].number = lgcom;
290 aLog[indexLog].coords.length(rnum);
291 aLog[indexLog].indexes.length(inum);
292 for (int i=0; i<rnum; i++)
294 aLog[indexLog].coords[i] = ir.Value();
295 //MESSAGE(" "<<i<<" "<<ir.Value());
298 for (int i=0; i<inum; i++)
300 aLog[indexLog].indexes[i] = ii.Value();
301 //MESSAGE(" "<<i<<" "<<ii.Value());
307 if (clearAfterGet) _impl->ClearLog();
309 catch (SALOME_Exception& S_ex)
311 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
316 // SMESH::string_array* SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
317 // throw (SALOME::SALOME_Exception)
319 // MESSAGE("SMESH_Mesh_i::GetLog");
321 // SMESH::string_array_var aLog;
324 // const SMESHDS_ListOfCommand& logDS =_impl->GetLog();
325 // aLog = new SMESH::string_array;
328 // int lg = logDS.Extent();
330 // SMESHDS_ListIteratorOfListOfCommand its(logDS);
333 // Handle(SMESHDS_Command) com = its.Value();
334 // int comType = com->GetType();
336 // int lgcom = com->GetNumber();
339 // aLog->length(logSize);
341 // const TColStd_ListOfInteger& intList = com->GetIndexes();
342 // TColStd_ListIteratorOfListOfInteger ii(intList);
343 // const TColStd_ListOfReal& coordList = com->GetCoords();
344 // TColStd_ListIteratorOfListOfReal ir(coordList);
345 // for (int icom = 1; icom <= lgcom; icom++)
350 // case SMESHDS_AddNode:
351 // S << "AddNode " << ii.Value(); ii.Next();
352 // S << " " << ir.Value(); ir.Next();
353 // S << " " << ir.Value(); ir.Next();
354 // S << " " << ir.Value(); ir.Next();
356 // case SMESHDS_AddEdge:
357 // S << "AddEdge " << ii.Value(); ii.Next();
358 // S << " " << ii.Value(); ii.Next();
359 // S << " " << ii.Value(); ii.Next();
361 // case SMESHDS_AddTriangle:
362 // S << "AddFace " << ii.Value(); ii.Next();
363 // S << " " << ii.Value(); ii.Next();
364 // S << " " << ii.Value(); ii.Next();
365 // S << " " << ii.Value(); ii.Next();
367 // case SMESHDS_AddQuadrangle:
368 // S << "AddFace " << ii.Value(); ii.Next();
369 // S << " " << ii.Value(); ii.Next();
370 // S << " " << ii.Value(); ii.Next();
371 // S << " " << ii.Value(); ii.Next();
372 // S << " " << ii.Value(); ii.Next();
374 // case SMESHDS_AddTetrahedron:
375 // S << "AddVolume " << ii.Value(); ii.Next();
376 // S << " " << ii.Value(); ii.Next();
377 // S << " " << ii.Value(); ii.Next();
378 // S << " " << ii.Value(); ii.Next();
379 // S << " " << ii.Value(); ii.Next();
381 // case SMESHDS_AddPyramid:
382 // S << "AddVolume " << 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();
389 // case SMESHDS_AddPrism:
390 // S << "AddVolume " << ii.Value(); ii.Next();
391 // S << " " << ii.Value(); ii.Next();
392 // S << " " << ii.Value(); ii.Next();
393 // S << " " << ii.Value(); ii.Next();
394 // S << " " << ii.Value(); ii.Next();
395 // S << " " << ii.Value(); ii.Next();
396 // S << " " << ii.Value(); ii.Next();
398 // case SMESHDS_AddHexahedron:
399 // S << "AddVolume " << ii.Value(); ii.Next();
400 // S << " " << ii.Value(); ii.Next();
401 // S << " " << ii.Value(); ii.Next();
402 // S << " " << ii.Value(); ii.Next();
403 // S << " " << ii.Value(); ii.Next();
404 // S << " " << ii.Value(); ii.Next();
405 // S << " " << ii.Value(); ii.Next();
406 // S << " " << ii.Value(); ii.Next();
407 // S << " " << ii.Value(); ii.Next();
409 // case SMESHDS_RemoveNode:
410 // S << "RemoveNode " << ii.Value(); ii.Next();
412 // case SMESHDS_RemoveElement:
413 // S << "RemoveElement " << ii.Value(); ii.Next();
419 // string ch = S.str();
421 // aLog[indexLog++] = CORBA::string_dup(ch.c_str());
425 // if (clearAfterGet) _impl->ClearLog();
427 // catch (SALOME_Exception& S_ex)
429 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
431 // return aLog._retn();
434 //=============================================================================
438 //=============================================================================
440 void SMESH_Mesh_i::ClearLog()
441 throw (SALOME::SALOME_Exception)
443 MESSAGE("SMESH_Mesh_i::ClearLog");
447 //=============================================================================
451 //=============================================================================
453 CORBA::Long SMESH_Mesh_i::GetId()
454 throw (SALOME::SALOME_Exception)
456 MESSAGE("SMESH_Mesh_i::GetId");
460 //=============================================================================
464 //=============================================================================
466 CORBA::Long SMESH_Mesh_i::GetStudyId()
467 throw (SALOME::SALOME_Exception)
471 //=============================================================================
475 //=============================================================================
477 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh* impl)
479 MESSAGE("SMESH_Mesh_i::SetImpl");
483 //=============================================================================
487 //=============================================================================
489 ::SMESH_Mesh& SMESH_Mesh_i::GetImpl()
491 MESSAGE("SMESH_Mesh_i::GetImpl()");
495 //=============================================================================
499 //=============================================================================
501 GEOM::GEOM_Gen_ptr SMESH_Mesh_i::GetGeomEngine()
503 MESSAGE("SMESH_Mesh_i::GetGeomEngine");
504 return GEOM::GEOM_Gen::_duplicate(_geom);
507 //=============================================================================
511 //=============================================================================
513 void SMESH_Mesh_i::SetIor(SMESH::SMESH_Mesh_ptr myIor)
515 MESSAGE("SMESH_Mesh_i::SetIor");
516 _myIor = SMESH::SMESH_Mesh::_duplicate(myIor);
517 ASSERT(! CORBA::is_nil(_myIor));
520 //=============================================================================
524 //=============================================================================
526 SMESH::SMESH_Mesh_ptr SMESH_Mesh_i::GetIor()
528 MESSAGE("SMESH_Mesh_i::GetIor");
529 ASSERT(! CORBA::is_nil(_myIor));
530 return SMESH::SMESH_Mesh::_duplicate(_myIor);
532 //=============================================================================
536 //=============================================================================
538 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
540 SMESH_MeshEditor_i* aMeshEditor = new SMESH_MeshEditor_i(_impl->GetMeshDS());
541 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
542 return aMesh._retn();
545 //=============================================================================
549 //=============================================================================
551 void SMESH_Mesh_i::ExportMED( const char* file )
552 throw (SALOME::SALOME_Exception)
554 _impl->ExportMED( file );
556 void SMESH_Mesh_i::ExportDAT( const char* file )
557 throw (SALOME::SALOME_Exception)
559 _impl->ExportDAT( file );
561 void SMESH_Mesh_i::ExportUNV( const char* file )
562 throw (SALOME::SALOME_Exception)
564 _impl->ExportUNV( file );
568 //=============================================================================
572 //=============================================================================
574 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()
575 throw (SALOME::SALOME_Exception)
577 SMESH_MEDMesh_i* aMedMesh = new SMESH_MEDMesh_i( this );
578 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
579 return aMesh._retn();
582 //=============================================================================
586 //=============================================================================
587 CORBA::Long SMESH_Mesh_i::NbNodes()
588 throw (SALOME::SALOME_Exception)
590 return _impl->NbNodes();
593 //=============================================================================
597 //=============================================================================
598 CORBA::Long SMESH_Mesh_i::NbEdges()
599 throw (SALOME::SALOME_Exception)
601 return _impl->NbEdges();
604 //=============================================================================
608 //=============================================================================
609 CORBA::Long SMESH_Mesh_i::NbFaces()
610 throw (SALOME::SALOME_Exception)
612 return _impl->NbFaces();
614 CORBA::Long SMESH_Mesh_i::NbTriangles()
615 throw (SALOME::SALOME_Exception)
617 return _impl->NbTriangles();
619 CORBA::Long SMESH_Mesh_i::NbQuadrangles()
620 throw (SALOME::SALOME_Exception)
622 return _impl->NbQuadrangles();
625 //=============================================================================
629 //=============================================================================
630 CORBA::Long SMESH_Mesh_i::NbVolumes()
631 throw (SALOME::SALOME_Exception)
633 return _impl->NbVolumes();
635 CORBA::Long SMESH_Mesh_i::NbTetras()
636 throw (SALOME::SALOME_Exception)
638 return _impl->NbTetras();
640 CORBA::Long SMESH_Mesh_i::NbHexas()
641 throw (SALOME::SALOME_Exception)
643 return _impl->NbHexas();
646 //=============================================================================
650 //=============================================================================
651 CORBA::Long SMESH_Mesh_i::NbSubMesh()
652 throw (SALOME::SALOME_Exception)
654 return _impl->NbSubMesh();