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);
166 *@TODO Not implemented
168 SMESH::ListOfHypothesis *
169 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Shape_ptr aSubShape)
170 throw(SALOME::SALOME_Exception)
172 MESSAGE("GetHypothesisList: Not implemented");
176 //=============================================================================
180 //=============================================================================
181 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetElementsOnShape(GEOM::
182 GEOM_Shape_ptr aSubShape) throw(SALOME::SALOME_Exception)
184 MESSAGE("SMESH_Mesh_i::GetElementsOnShape");
185 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
186 if (CORBA::is_nil(mySubShape))
187 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
193 SMESH_subMesh_i *subMeshServant;
194 TopoDS_Shape myLocSubShape
195 = _gen_i->_ShapeReader->GetShape(_geom, mySubShape);
197 //Get or Create the SMESH_subMesh object implementation
199 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
200 subMeshId = mySubMesh->GetId();
202 // create a new subMesh object servant if there is none for the shape
204 if (_mapSubMesh.find(subMeshId) != _mapSubMesh.end())
206 ASSERT(_mapSubMesh_i.find(subMeshId) != _mapSubMesh_i.end());
207 subMeshServant = _mapSubMesh_i[subMeshId];
211 // create and activate the CORBA servant of Mesh
212 subMeshServant = new SMESH_subMesh_i(_gen_i, this, subMeshId);
213 SMESH::SMESH_subMesh_var subMesh
214 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
215 _mapSubMesh[subMeshId] = mySubMesh;
216 _mapSubMesh_i[subMeshId] = subMeshServant;
217 _mapSubMeshIor[subMeshId]
218 = SMESH::SMESH_subMesh::_duplicate(subMesh);
221 catch(SALOME_Exception & S_ex)
223 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
226 ASSERT(_mapSubMeshIor.find(subMeshId) != _mapSubMeshIor.end());
227 return SMESH::SMESH_subMesh::_duplicate(_mapSubMeshIor[subMeshId]);
231 * Translate the UpdateAll SMESHDS_Command to a set of SMESH::log_command.
232 * As the input log need to be resized, it is realocated.
233 * @param logBlock The log where to insert created commands
234 * @param index The place where to insert created commands in log. It is updated
235 * with the place to put new elements.
236 * @return The realocated and resized log.
237 * @TODO Add support for other type of elements
239 SMESH::log_array_var SMESH_Mesh_i::
240 createUpdateAllCommand(SMESH::log_array_var log, int * index)
242 MESSAGE("SMESH_Mesh_i::createUpdateAllCommand");
243 SMESH::log_array_var aLog=new SMESH::log_array(log->length()+3);
244 aLog->length(log->length()+3);
246 for(int i=0;i<*index;i++)
254 //Remove all elements
255 aLog[id].commandType=SMESH::REMOVE_ALL;
259 aLog[id].commandType=SMESH::ADD_NODE;
260 aLog[id].number=_impl->GetMeshDS()->NbNodes();
262 double * nodesCoordinates=_impl->GetMeshDS()->getNodesCoordinates();
263 aLog[id].coords=SMESH::double_array(
268 long * nodesID=_impl->GetMeshDS()->getNodesID();
269 aLog[id].indexes=SMESH::long_array(
276 MESSAGE("Export edges");
278 aLog[id].commandType=SMESH::ADD_EDGE;
279 aLog[id].number=_impl->GetMeshDS()->NbEdges();
280 aLog[id].coords.length(0);
282 long * edgesIndices=_impl->GetMeshDS()->getEdgesIndices();
283 aLog[id].indexes=SMESH::long_array(
290 MESSAGE("Export triangles");
292 aLog[id].commandType=SMESH::ADD_TRIANGLE;
293 aLog[id].number=_impl->GetMeshDS()->NbTriangles();
294 aLog[id].coords.length(0);
296 long * triasIndices=_impl->GetMeshDS()->getTrianglesIndices();
297 aLog[id].indexes=SMESH::long_array(
307 * Return the log of the current mesh. CORBA wrap of the SMESH::GetLog method
308 * with a special treatment for SMESHDS_UpdateAll commands
309 * @param clearAfterGet Tell if the log must be cleared after being returned
312 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
313 throw(SALOME::SALOME_Exception)
315 MESSAGE("SMESH_Mesh_i::GetLog");
317 SMESH::log_array_var aLog;
320 list < SMESHDS_Command * >logDS = _impl->GetLog();
321 aLog = new SMESH::log_array;
323 int lg = logDS.size();
324 MESSAGE("Number of command in the log: "<<lg);
326 list < SMESHDS_Command * >::iterator its = logDS.begin();
327 while (its != logDS.end())
329 SMESHDS_Command *com = *its;
330 int comType = com->GetType();
332 int lgcom = com->GetNumber();
334 const list < int >&intList = com->GetIndexes();
335 int inum = intList.size();
337 list < int >::const_iterator ii = intList.begin();
338 const list < double >&coordList = com->GetCoords();
339 int rnum = coordList.size();
341 list < double >::const_iterator ir = coordList.begin();
342 aLog[indexLog].commandType = comType;
343 if(comType==SMESHDS_UpdateAll)
345 aLog=createUpdateAllCommand(aLog, &indexLog);
349 aLog[indexLog].number = lgcom;
350 aLog[indexLog].coords.length(rnum);
351 aLog[indexLog].indexes.length(inum);
352 for (int i = 0; i < rnum; i++)
354 aLog[indexLog].coords[i] = *ir;
355 //MESSAGE(" "<<i<<" "<<ir.Value());
358 for (int i = 0; i < inum; i++)
360 aLog[indexLog].indexes[i] = *ii;
361 //MESSAGE(" "<<i<<" "<<ii.Value());
368 if (clearAfterGet) _impl->ClearLog();
371 catch(SALOME_Exception & S_ex)
373 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
377 // SMESH::string_array* SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
378 // throw (SALOME::SALOME_Exception)
380 // MESSAGE("SMESH_Mesh_i::GetLog");
382 // SMESH::string_array_var aLog;
385 // const SMESHDS_ListOfCommand& logDS =_impl->GetLog();
386 // aLog = new SMESH::string_array;
389 // int lg = logDS.Extent();
391 // SMESHDS_ListIteratorOfListOfCommand its(logDS);
394 // Handle(SMESHDS_Command) com = its.Value();
395 // int comType = com->GetType();
397 // int lgcom = com->GetNumber();
400 // aLog->length(logSize);
402 // const TColStd_ListOfInteger& intList = com->GetIndexes();
403 // TColStd_ListIteratorOfListOfInteger ii(intList);
404 // const TColStd_ListOfReal& coordList = com->GetCoords();
405 // TColStd_ListIteratorOfListOfReal ir(coordList);
406 // for (int icom = 1; icom <= lgcom; icom++)
411 // case SMESHDS_AddNode:
412 // S << "AddNode " << ii.Value(); ii.Next();
413 // S << " " << ir.Value(); ir.Next();
414 // S << " " << ir.Value(); ir.Next();
415 // S << " " << ir.Value(); ir.Next();
417 // case SMESHDS_AddEdge:
418 // S << "AddEdge " << ii.Value(); ii.Next();
419 // S << " " << ii.Value(); ii.Next();
420 // S << " " << ii.Value(); ii.Next();
422 // case SMESHDS_AddTriangle:
423 // S << "AddFace " << ii.Value(); ii.Next();
424 // S << " " << ii.Value(); ii.Next();
425 // S << " " << ii.Value(); ii.Next();
426 // S << " " << ii.Value(); ii.Next();
428 // case SMESHDS_AddQuadrangle:
429 // S << "AddFace " << ii.Value(); ii.Next();
430 // S << " " << ii.Value(); ii.Next();
431 // S << " " << ii.Value(); ii.Next();
432 // S << " " << ii.Value(); ii.Next();
433 // S << " " << ii.Value(); ii.Next();
435 // case SMESHDS_AddTetrahedron:
436 // S << "AddVolume " << ii.Value(); ii.Next();
437 // S << " " << ii.Value(); ii.Next();
438 // S << " " << ii.Value(); ii.Next();
439 // S << " " << ii.Value(); ii.Next();
440 // S << " " << ii.Value(); ii.Next();
442 // case SMESHDS_AddPyramid:
443 // S << "AddVolume " << ii.Value(); ii.Next();
444 // S << " " << ii.Value(); ii.Next();
445 // S << " " << ii.Value(); ii.Next();
446 // S << " " << ii.Value(); ii.Next();
447 // S << " " << ii.Value(); ii.Next();
448 // S << " " << ii.Value(); ii.Next();
450 // case SMESHDS_AddPrism:
451 // S << "AddVolume " << ii.Value(); ii.Next();
452 // S << " " << ii.Value(); ii.Next();
453 // S << " " << ii.Value(); ii.Next();
454 // S << " " << ii.Value(); ii.Next();
455 // S << " " << ii.Value(); ii.Next();
456 // S << " " << ii.Value(); ii.Next();
457 // S << " " << ii.Value(); ii.Next();
459 // case SMESHDS_AddHexahedron:
460 // S << "AddVolume " << ii.Value(); ii.Next();
461 // S << " " << ii.Value(); ii.Next();
462 // S << " " << ii.Value(); ii.Next();
463 // S << " " << ii.Value(); ii.Next();
464 // S << " " << ii.Value(); ii.Next();
465 // S << " " << ii.Value(); ii.Next();
466 // S << " " << ii.Value(); ii.Next();
467 // S << " " << ii.Value(); ii.Next();
468 // S << " " << ii.Value(); ii.Next();
470 // case SMESHDS_RemoveNode:
471 // S << "RemoveNode " << ii.Value(); ii.Next();
473 // case SMESHDS_RemoveElement:
474 // S << "RemoveElement " << ii.Value(); ii.Next();
480 // string ch = S.str();
482 // aLog[indexLog++] = CORBA::string_dup(ch.c_str());
486 // if (clearAfterGet) _impl->ClearLog();
488 // catch (SALOME_Exception& S_ex)
490 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
492 // return aLog._retn();
495 //=============================================================================
499 //=============================================================================
501 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
503 MESSAGE("SMESH_Mesh_i::ClearLog");
507 //=============================================================================
511 //=============================================================================
513 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
515 MESSAGE("SMESH_Mesh_i::GetId");
519 //=============================================================================
523 //=============================================================================
525 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
530 //=============================================================================
534 //=============================================================================
536 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
538 MESSAGE("SMESH_Mesh_i::SetImpl");
542 //=============================================================================
546 //=============================================================================
548 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
550 MESSAGE("SMESH_Mesh_i::GetImpl()");
554 //=============================================================================
558 //=============================================================================
560 GEOM::GEOM_Gen_ptr SMESH_Mesh_i::GetGeomEngine()
562 MESSAGE("SMESH_Mesh_i::GetGeomEngine");
563 return GEOM::GEOM_Gen::_duplicate(_geom);
566 //=============================================================================
570 //=============================================================================
572 void SMESH_Mesh_i::SetIor(SMESH::SMESH_Mesh_ptr myIor)
574 MESSAGE("SMESH_Mesh_i::SetIor");
575 _myIor = SMESH::SMESH_Mesh::_duplicate(myIor);
576 ASSERT(!CORBA::is_nil(_myIor));
579 //=============================================================================
583 //=============================================================================
585 SMESH::SMESH_Mesh_ptr SMESH_Mesh_i::GetIor()
587 MESSAGE("SMESH_Mesh_i::GetIor");
588 ASSERT(!CORBA::is_nil(_myIor));
589 return SMESH::SMESH_Mesh::_duplicate(_myIor);
592 //=============================================================================
596 //=============================================================================
598 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
600 SMESH_MeshEditor_i *aMeshEditor =
601 new SMESH_MeshEditor_i(_impl->GetMeshDS());
602 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
603 return aMesh._retn();
606 //=============================================================================
610 //=============================================================================
612 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
614 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
615 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
616 return aMesh._retn();
619 //=============================================================================
623 //=============================================================================
624 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
626 return _impl->NbNodes();
629 //=============================================================================
633 //=============================================================================
634 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
636 return _impl->NbEdges();
639 //=============================================================================
643 //=============================================================================
644 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
646 return _impl->NbFaces();
649 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
651 return _impl->NbTriangles();
654 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
656 return _impl->NbQuadrangles();
659 //=============================================================================
663 //=============================================================================
664 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
666 return _impl->NbVolumes();
669 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
671 return _impl->NbTetras();
674 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
676 return _impl->NbHexas();
679 //=============================================================================
683 //=============================================================================
684 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
686 return _impl->NbSubMesh();
690 * Export mesh to a file
691 * @param fileName file name where to export the file
692 * @param fileType Currently it could be either "DAT", "UNV" or "MED".
694 void SMESH_Mesh_i::Export(const char* fileName, const char* fileType)
695 throw (SALOME::SALOME_Exception)
697 _impl->Export(fileName, fileType);