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
30 #include "SMESH_Mesh_i.hxx"
31 #include "SMESH_subMesh_i.hxx"
32 #include "SMESH_MEDMesh_i.hxx"
34 #include "Utils_CorbaException.hxx"
35 #include "utilities.h"
37 #include "SALOME_NamingService.hxx"
38 #include "Utils_SINGLETON.hxx"
41 #include "TCollection_AsciiString.hxx"
42 #include "SMESHDS_Command.hxx"
43 #include "SMESHDS_CommandType.hxx"
44 #include "SMESH_MeshEditor_i.hxx"
49 //**** SMESHDS en champ
51 //=============================================================================
55 //=============================================================================
57 SMESH_Mesh_i::SMESH_Mesh_i()
59 MESSAGE("SMESH_Mesh_i: default constructor, not for use");
63 //=============================================================================
67 //=============================================================================
69 SMESH_Mesh_i::SMESH_Mesh_i(SMESH_Gen_i * gen_i,
70 GEOM::GEOM_Gen_ptr geomEngine, CORBA::Long studyId, int localId)
72 MESSAGE("SMESH_Mesh_i");
75 _geom = GEOM::GEOM_Gen::_narrow(geomEngine);
79 //=============================================================================
83 //=============================================================================
85 SMESH_Mesh_i::~SMESH_Mesh_i()
87 MESSAGE("~SMESH_Mesh_i");
91 //=============================================================================
95 //=============================================================================
97 CORBA::Boolean SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
98 SMESH::SMESH_Hypothesis_ptr anHyp) throw(SALOME::SALOME_Exception)
100 MESSAGE("AddHypothesis");
101 // **** proposer liste de subShape (selection multiple)
103 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
104 if (CORBA::is_nil(mySubShape))
105 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
108 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
109 if (CORBA::is_nil(myHyp))
110 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
115 TopoDS_Shape myLocSubShape =
116 _gen_i->_ShapeReader->GetShape(_geom, mySubShape);
117 int hypId = myHyp->GetId();
118 ret = _impl->AddHypothesis(myLocSubShape, hypId);
120 catch(SALOME_Exception & S_ex)
122 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
127 //=============================================================================
131 //=============================================================================
134 SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
135 SMESH::SMESH_Hypothesis_ptr anHyp) throw(SALOME::SALOME_Exception)
137 MESSAGE("RemoveHypothesis");
138 // **** proposer liste de subShape (selection multiple)
140 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
141 if (CORBA::is_nil(mySubShape))
142 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
145 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
146 if (CORBA::is_nil(myHyp))
147 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
153 TopoDS_Shape myLocSubShape =
154 _gen_i->_ShapeReader->GetShape(_geom, mySubShape);
155 int hypId = myHyp->GetId();
156 ret = _impl->RemoveHypothesis(myLocSubShape, hypId);
158 catch(SALOME_Exception & S_ex)
160 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
165 //=============================================================================
169 //=============================================================================
171 SMESH::ListOfHypothesis *
172 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Shape_ptr aSubShape)
173 throw(SALOME::SALOME_Exception)
175 MESSAGE("GetHypothesisList");
179 //=============================================================================
183 //=============================================================================
184 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetElementsOnShape(GEOM::
185 GEOM_Shape_ptr aSubShape) throw(SALOME::SALOME_Exception)
187 MESSAGE("SMESH_Mesh_i::GetElementsOnShape");
188 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
189 if (CORBA::is_nil(mySubShape))
190 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
196 SMESH_subMesh_i *subMeshServant;
197 TopoDS_Shape myLocSubShape
198 = _gen_i->_ShapeReader->GetShape(_geom, mySubShape);
200 //Get or Create the SMESH_subMesh object implementation
202 ::SMESH_subMesh * mySubMesh = _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 list < SMESHDS_Command * >logDS = _impl->GetLog();
248 aLog = new SMESH::log_array;
250 int lg = logDS.size();
253 list < SMESHDS_Command * >::iterator its = logDS.begin();
254 while (its != logDS.end())
256 SMESHDS_Command *com = *its;
257 int comType = com->GetType();
259 int lgcom = com->GetNumber();
261 const list < int >&intList = com->GetIndexes();
262 int inum = intList.size();
264 list < int >::const_iterator ii = intList.begin();
265 const list < double >&coordList = com->GetCoords();
266 int rnum = coordList.size();
268 list < double >::const_iterator ir = coordList.begin();
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;
276 //MESSAGE(" "<<i<<" "<<ir.Value());
279 for (int i = 0; i < inum; i++)
281 aLog[indexLog].indexes[i] = *ii;
282 //MESSAGE(" "<<i<<" "<<ii.Value());
291 catch(SALOME_Exception & S_ex)
293 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
298 // SMESH::string_array* SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
299 // throw (SALOME::SALOME_Exception)
301 // MESSAGE("SMESH_Mesh_i::GetLog");
303 // SMESH::string_array_var aLog;
306 // const SMESHDS_ListOfCommand& logDS =_impl->GetLog();
307 // aLog = new SMESH::string_array;
310 // int lg = logDS.Extent();
312 // SMESHDS_ListIteratorOfListOfCommand its(logDS);
315 // Handle(SMESHDS_Command) com = its.Value();
316 // int comType = com->GetType();
318 // int lgcom = com->GetNumber();
321 // aLog->length(logSize);
323 // const TColStd_ListOfInteger& intList = com->GetIndexes();
324 // TColStd_ListIteratorOfListOfInteger ii(intList);
325 // const TColStd_ListOfReal& coordList = com->GetCoords();
326 // TColStd_ListIteratorOfListOfReal ir(coordList);
327 // for (int icom = 1; icom <= lgcom; icom++)
332 // case SMESHDS_AddNode:
333 // S << "AddNode " << ii.Value(); ii.Next();
334 // S << " " << ir.Value(); ir.Next();
335 // S << " " << ir.Value(); ir.Next();
336 // S << " " << ir.Value(); ir.Next();
338 // case SMESHDS_AddEdge:
339 // S << "AddEdge " << ii.Value(); ii.Next();
340 // S << " " << ii.Value(); ii.Next();
341 // S << " " << ii.Value(); ii.Next();
343 // case SMESHDS_AddTriangle:
344 // S << "AddFace " << ii.Value(); ii.Next();
345 // S << " " << ii.Value(); ii.Next();
346 // S << " " << ii.Value(); ii.Next();
347 // S << " " << ii.Value(); ii.Next();
349 // case SMESHDS_AddQuadrangle:
350 // S << "AddFace " << ii.Value(); ii.Next();
351 // S << " " << ii.Value(); ii.Next();
352 // S << " " << ii.Value(); ii.Next();
353 // S << " " << ii.Value(); ii.Next();
354 // S << " " << ii.Value(); ii.Next();
356 // case SMESHDS_AddTetrahedron:
357 // S << "AddVolume " << ii.Value(); ii.Next();
358 // S << " " << ii.Value(); ii.Next();
359 // S << " " << ii.Value(); ii.Next();
360 // S << " " << ii.Value(); ii.Next();
361 // S << " " << ii.Value(); ii.Next();
363 // case SMESHDS_AddPyramid:
364 // S << "AddVolume " << 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();
369 // S << " " << ii.Value(); ii.Next();
371 // case SMESHDS_AddPrism:
372 // S << "AddVolume " << 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();
378 // S << " " << ii.Value(); ii.Next();
380 // case SMESHDS_AddHexahedron:
381 // S << "AddVolume " << 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();
389 // S << " " << ii.Value(); ii.Next();
391 // case SMESHDS_RemoveNode:
392 // S << "RemoveNode " << ii.Value(); ii.Next();
394 // case SMESHDS_RemoveElement:
395 // S << "RemoveElement " << ii.Value(); ii.Next();
401 // string ch = S.str();
403 // aLog[indexLog++] = CORBA::string_dup(ch.c_str());
407 // if (clearAfterGet) _impl->ClearLog();
409 // catch (SALOME_Exception& S_ex)
411 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
413 // return aLog._retn();
416 //=============================================================================
420 //=============================================================================
422 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
424 MESSAGE("SMESH_Mesh_i::ClearLog");
428 //=============================================================================
432 //=============================================================================
434 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
436 MESSAGE("SMESH_Mesh_i::GetId");
440 //=============================================================================
444 //=============================================================================
446 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
451 //=============================================================================
455 //=============================================================================
457 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
459 MESSAGE("SMESH_Mesh_i::SetImpl");
463 //=============================================================================
467 //=============================================================================
469 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
471 MESSAGE("SMESH_Mesh_i::GetImpl()");
475 //=============================================================================
479 //=============================================================================
481 GEOM::GEOM_Gen_ptr SMESH_Mesh_i::GetGeomEngine()
483 MESSAGE("SMESH_Mesh_i::GetGeomEngine");
484 return GEOM::GEOM_Gen::_duplicate(_geom);
487 //=============================================================================
491 //=============================================================================
493 void SMESH_Mesh_i::SetIor(SMESH::SMESH_Mesh_ptr myIor)
495 MESSAGE("SMESH_Mesh_i::SetIor");
496 _myIor = SMESH::SMESH_Mesh::_duplicate(myIor);
497 ASSERT(!CORBA::is_nil(_myIor));
500 //=============================================================================
504 //=============================================================================
506 SMESH::SMESH_Mesh_ptr SMESH_Mesh_i::GetIor()
508 MESSAGE("SMESH_Mesh_i::GetIor");
509 ASSERT(!CORBA::is_nil(_myIor));
510 return SMESH::SMESH_Mesh::_duplicate(_myIor);
513 //=============================================================================
517 //=============================================================================
519 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
521 SMESH_MeshEditor_i *aMeshEditor =
522 new SMESH_MeshEditor_i(_impl->GetMeshDS());
523 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
524 return aMesh._retn();
527 //=============================================================================
531 //=============================================================================
533 void SMESH_Mesh_i::ExportMED(const char *file) throw(SALOME::SALOME_Exception)
535 _impl->ExportMED(file);
537 void SMESH_Mesh_i::ExportDAT(const char *file) throw(SALOME::SALOME_Exception)
539 _impl->ExportDAT(file);
541 void SMESH_Mesh_i::ExportUNV(const char *file) throw(SALOME::SALOME_Exception)
543 _impl->ExportUNV(file);
546 //=============================================================================
550 //=============================================================================
552 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
554 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
555 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
556 return aMesh._retn();
559 //=============================================================================
563 //=============================================================================
564 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
566 return _impl->NbNodes();
569 //=============================================================================
573 //=============================================================================
574 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
576 return _impl->NbEdges();
579 //=============================================================================
583 //=============================================================================
584 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
586 return _impl->NbFaces();
589 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
591 return _impl->NbTriangles();
594 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
596 return _impl->NbQuadrangles();
599 //=============================================================================
603 //=============================================================================
604 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
606 return _impl->NbVolumes();
609 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
611 return _impl->NbTetras();
614 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
616 return _impl->NbHexas();
619 //=============================================================================
623 //=============================================================================
624 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
626 return _impl->NbSubMesh();