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
29 #include "SMESH_Mesh_i.hxx"
30 #include "SMESH_subMesh_i.hxx"
31 #include "SMESH_MEDMesh_i.hxx"
33 #include "Utils_CorbaException.hxx"
34 #include "utilities.h"
36 #include "SALOME_NamingService.hxx"
37 #include "Utils_SINGLETON.hxx"
40 #include "TCollection_AsciiString.hxx"
41 #include "SMESHDS_Command.hxx"
42 #include "SMESHDS_CommandType.hxx"
43 #include "SMESH_MeshEditor_i.hxx"
49 //=============================================================================
53 //=============================================================================
55 SMESH_Mesh_i::SMESH_Mesh_i(SMESH_Gen_i * gen_i,
56 GEOM::GEOM_Gen_ptr geomEngine, CORBA::Long studyId, ::SMESH_Mesh * impl)
58 MESSAGE("SMESH_Mesh_i");
60 _geom = GEOM::GEOM_Gen::_narrow(geomEngine);
65 //=============================================================================
69 //=============================================================================
71 SMESH_Mesh_i::~SMESH_Mesh_i()
73 MESSAGE("~SMESH_Mesh_i");
77 //=============================================================================
81 //=============================================================================
83 CORBA::Boolean SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
84 SMESH::SMESH_Hypothesis_ptr anHyp) throw(SALOME::SALOME_Exception)
86 MESSAGE("AddHypothesis");
87 // **** proposer liste de subShape (selection multiple)
89 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
90 if (CORBA::is_nil(mySubShape))
91 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
94 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
95 if (CORBA::is_nil(myHyp))
96 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
101 TopoDS_Shape myLocSubShape =
102 _gen_i->_ShapeReader->GetShape(_geom, mySubShape);
103 int hypId = myHyp->GetId();
104 ret = _impl->AddHypothesis(myLocSubShape, hypId);
106 catch(SALOME_Exception & S_ex)
108 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
113 //=============================================================================
117 //=============================================================================
120 SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
121 SMESH::SMESH_Hypothesis_ptr anHyp) throw(SALOME::SALOME_Exception)
123 MESSAGE("RemoveHypothesis");
124 // **** proposer liste de subShape (selection multiple)
126 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
127 if (CORBA::is_nil(mySubShape))
128 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
131 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
132 if (CORBA::is_nil(myHyp))
133 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
139 TopoDS_Shape myLocSubShape =
140 _gen_i->_ShapeReader->GetShape(_geom, mySubShape);
141 int hypId = myHyp->GetId();
142 ret = _impl->RemoveHypothesis(myLocSubShape, hypId);
144 catch(SALOME_Exception & S_ex)
146 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
152 *@TODO Not implemented
154 SMESH::ListOfHypothesis *
155 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Shape_ptr aSubShape)
156 throw(SALOME::SALOME_Exception)
158 MESSAGE("GetHypothesisList: Not implemented");
162 //=============================================================================
166 //=============================================================================
167 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetElementsOnShape(GEOM::
168 GEOM_Shape_ptr aSubShape) throw(SALOME::SALOME_Exception)
170 MESSAGE("SMESH_Mesh_i::GetElementsOnShape");
171 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
172 if (CORBA::is_nil(mySubShape))
173 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
179 SMESH_subMesh_i *subMeshServant;
180 TopoDS_Shape myLocSubShape
181 = _gen_i->_ShapeReader->GetShape(_geom, mySubShape);
183 //Get or Create the SMESH_subMesh object implementation
185 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
186 subMeshId = mySubMesh->GetId();
188 // create a new subMesh object servant if there is none for the shape
190 if (_mapSubMesh.find(subMeshId) != _mapSubMesh.end())
192 ASSERT(_mapSubMesh_i.find(subMeshId) != _mapSubMesh_i.end());
193 subMeshServant = _mapSubMesh_i[subMeshId];
197 // create and activate the CORBA servant of Mesh
198 subMeshServant = new SMESH_subMesh_i(_gen_i, this, subMeshId);
199 SMESH::SMESH_subMesh_var subMesh
200 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
201 _mapSubMesh[subMeshId] = mySubMesh;
202 _mapSubMesh_i[subMeshId] = subMeshServant;
203 _mapSubMeshIor[subMeshId]
204 = SMESH::SMESH_subMesh::_duplicate(subMesh);
207 catch(SALOME_Exception & S_ex)
209 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
212 ASSERT(_mapSubMeshIor.find(subMeshId) != _mapSubMeshIor.end());
213 return SMESH::SMESH_subMesh::_duplicate(_mapSubMeshIor[subMeshId]);
217 * Translate the UpdateAll SMESHDS_Command to a set of SMESH::log_command.
218 * As the input log need to be resized, it is realocated.
219 * @param logBlock The log where to insert created commands
220 * @param index The place where to insert created commands in log. It is updated
221 * with the place to put new elements.
222 * @return The realocated and resized log.
223 * @TODO Add support for other type of elements
225 SMESH::log_array_var SMESH_Mesh_i::
226 createUpdateAllCommand(SMESH::log_array_var log, int * index)
228 MESSAGE("SMESH_Mesh_i::createUpdateAllCommand");
229 SMESH::log_array_var aLog=new SMESH::log_array(log->length()+3);
230 aLog->length(log->length()+3);
232 for(int i=0;i<*index;i++)
240 //Remove all elements
241 aLog[id].commandType=SMESH::REMOVE_ALL;
245 aLog[id].commandType=SMESH::ADD_NODE;
246 aLog[id].number=_impl->GetMeshDS()->NbNodes();
248 double * nodesCoordinates=_impl->GetMeshDS()->getNodesCoordinates();
249 aLog[id].coords=SMESH::double_array(
254 long * nodesID=_impl->GetMeshDS()->getNodesID();
255 aLog[id].indexes=SMESH::long_array(
262 MESSAGE("Export edges");
264 aLog[id].commandType=SMESH::ADD_EDGE;
265 aLog[id].number=_impl->GetMeshDS()->NbEdges();
266 aLog[id].coords.length(0);
268 long * edgesIndices=_impl->GetMeshDS()->getEdgesIndices();
269 aLog[id].indexes=SMESH::long_array(
276 MESSAGE("Export triangles");
278 aLog[id].commandType=SMESH::ADD_TRIANGLE;
279 aLog[id].number=_impl->GetMeshDS()->NbTriangles();
280 aLog[id].coords.length(0);
282 long * triasIndices=_impl->GetMeshDS()->getTrianglesIndices();
283 aLog[id].indexes=SMESH::long_array(
293 * Return the log of the current mesh. CORBA wrap of the SMESH::GetLog method
294 * with a special treatment for SMESHDS_UpdateAll commands
295 * @param clearAfterGet Tell if the log must be cleared after being returned
298 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
299 throw(SALOME::SALOME_Exception)
301 MESSAGE("SMESH_Mesh_i::GetLog");
303 SMESH::log_array_var aLog;
306 list < SMESHDS_Command * >logDS = _impl->GetLog();
307 aLog = new SMESH::log_array;
309 int lg = logDS.size();
310 MESSAGE("Number of command in the log: "<<lg);
312 list < SMESHDS_Command * >::iterator its = logDS.begin();
313 while (its != logDS.end())
315 SMESHDS_Command *com = *its;
316 int comType = com->GetType();
318 int lgcom = com->GetNumber();
320 const list < int >&intList = com->GetIndexes();
321 int inum = intList.size();
323 list < int >::const_iterator ii = intList.begin();
324 const list < double >&coordList = com->GetCoords();
325 int rnum = coordList.size();
327 list < double >::const_iterator ir = coordList.begin();
328 aLog[indexLog].commandType = comType;
329 if(comType==SMESHDS_UpdateAll)
331 aLog=createUpdateAllCommand(aLog, &indexLog);
335 aLog[indexLog].number = lgcom;
336 aLog[indexLog].coords.length(rnum);
337 aLog[indexLog].indexes.length(inum);
338 for (int i = 0; i < rnum; i++)
340 aLog[indexLog].coords[i] = *ir;
341 //MESSAGE(" "<<i<<" "<<ir.Value());
344 for (int i = 0; i < inum; i++)
346 aLog[indexLog].indexes[i] = *ii;
347 //MESSAGE(" "<<i<<" "<<ii.Value());
354 if (clearAfterGet) _impl->ClearLog();
357 catch(SALOME_Exception & S_ex)
359 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
363 // SMESH::string_array* SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
364 // throw (SALOME::SALOME_Exception)
366 // MESSAGE("SMESH_Mesh_i::GetLog");
368 // SMESH::string_array_var aLog;
371 // const SMESHDS_ListOfCommand& logDS =_impl->GetLog();
372 // aLog = new SMESH::string_array;
375 // int lg = logDS.Extent();
377 // SMESHDS_ListIteratorOfListOfCommand its(logDS);
380 // Handle(SMESHDS_Command) com = its.Value();
381 // int comType = com->GetType();
383 // int lgcom = com->GetNumber();
386 // aLog->length(logSize);
388 // const TColStd_ListOfInteger& intList = com->GetIndexes();
389 // TColStd_ListIteratorOfListOfInteger ii(intList);
390 // const TColStd_ListOfReal& coordList = com->GetCoords();
391 // TColStd_ListIteratorOfListOfReal ir(coordList);
392 // for (int icom = 1; icom <= lgcom; icom++)
397 // case SMESHDS_AddNode:
398 // S << "AddNode " << ii.Value(); ii.Next();
399 // S << " " << ir.Value(); ir.Next();
400 // S << " " << ir.Value(); ir.Next();
401 // S << " " << ir.Value(); ir.Next();
403 // case SMESHDS_AddEdge:
404 // S << "AddEdge " << ii.Value(); ii.Next();
405 // S << " " << ii.Value(); ii.Next();
406 // S << " " << ii.Value(); ii.Next();
408 // case SMESHDS_AddTriangle:
409 // S << "AddFace " << ii.Value(); ii.Next();
410 // S << " " << ii.Value(); ii.Next();
411 // S << " " << ii.Value(); ii.Next();
412 // S << " " << ii.Value(); ii.Next();
414 // case SMESHDS_AddQuadrangle:
415 // S << "AddFace " << ii.Value(); ii.Next();
416 // S << " " << ii.Value(); ii.Next();
417 // S << " " << ii.Value(); ii.Next();
418 // S << " " << ii.Value(); ii.Next();
419 // S << " " << ii.Value(); ii.Next();
421 // case SMESHDS_AddTetrahedron:
422 // S << "AddVolume " << ii.Value(); ii.Next();
423 // S << " " << 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_AddPyramid:
429 // S << "AddVolume " << 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();
434 // S << " " << ii.Value(); ii.Next();
436 // case SMESHDS_AddPrism:
437 // S << "AddVolume " << ii.Value(); ii.Next();
438 // S << " " << ii.Value(); ii.Next();
439 // S << " " << ii.Value(); ii.Next();
440 // S << " " << ii.Value(); ii.Next();
441 // S << " " << ii.Value(); ii.Next();
442 // S << " " << ii.Value(); ii.Next();
443 // S << " " << ii.Value(); ii.Next();
445 // case SMESHDS_AddHexahedron:
446 // S << "AddVolume " << ii.Value(); ii.Next();
447 // S << " " << ii.Value(); ii.Next();
448 // S << " " << ii.Value(); ii.Next();
449 // S << " " << ii.Value(); ii.Next();
450 // S << " " << ii.Value(); ii.Next();
451 // S << " " << ii.Value(); ii.Next();
452 // S << " " << ii.Value(); ii.Next();
453 // S << " " << ii.Value(); ii.Next();
454 // S << " " << ii.Value(); ii.Next();
456 // case SMESHDS_RemoveNode:
457 // S << "RemoveNode " << ii.Value(); ii.Next();
459 // case SMESHDS_RemoveElement:
460 // S << "RemoveElement " << ii.Value(); ii.Next();
466 // string ch = S.str();
468 // aLog[indexLog++] = CORBA::string_dup(ch.c_str());
472 // if (clearAfterGet) _impl->ClearLog();
474 // catch (SALOME_Exception& S_ex)
476 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
478 // return aLog._retn();
481 //=============================================================================
485 //=============================================================================
487 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
489 MESSAGE("SMESH_Mesh_i::ClearLog");
493 //=============================================================================
497 //=============================================================================
499 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
501 return _impl->GetId();
504 //=============================================================================
508 //=============================================================================
510 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
515 //=============================================================================
519 //=============================================================================
521 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
523 MESSAGE("SMESH_Mesh_i::GetImpl()");
527 //=============================================================================
531 //=============================================================================
533 GEOM::GEOM_Gen_ptr SMESH_Mesh_i::GetGeomEngine()
535 MESSAGE("SMESH_Mesh_i::GetGeomEngine");
536 return GEOM::GEOM_Gen::_duplicate(_geom);
539 //=============================================================================
543 //=============================================================================
545 void SMESH_Mesh_i::SetIor(SMESH::SMESH_Mesh_ptr myIor)
547 MESSAGE("SMESH_Mesh_i::SetIor");
548 _myIor = SMESH::SMESH_Mesh::_duplicate(myIor);
549 ASSERT(!CORBA::is_nil(_myIor));
552 //=============================================================================
556 //=============================================================================
558 SMESH::SMESH_Mesh_ptr SMESH_Mesh_i::GetIor()
560 MESSAGE("SMESH_Mesh_i::GetIor");
561 ASSERT(!CORBA::is_nil(_myIor));
562 return SMESH::SMESH_Mesh::_duplicate(_myIor);
565 //=============================================================================
569 //=============================================================================
571 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
573 SMESH_MeshEditor_i *aMeshEditor =
574 new SMESH_MeshEditor_i(_impl->GetMeshDS());
575 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
576 return aMesh._retn();
579 //=============================================================================
583 //=============================================================================
585 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
587 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
588 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
589 return aMesh._retn();
592 //=============================================================================
596 //=============================================================================
597 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
599 return _impl->NbNodes();
602 //=============================================================================
606 //=============================================================================
607 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
609 return _impl->NbEdges();
612 //=============================================================================
616 //=============================================================================
617 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
619 return _impl->NbFaces();
622 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
624 return _impl->NbTriangles();
627 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
629 return _impl->NbQuadrangles();
632 //=============================================================================
636 //=============================================================================
637 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
639 return _impl->NbVolumes();
642 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
644 return _impl->NbTetras();
647 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
649 return _impl->NbHexas();
652 //=============================================================================
656 //=============================================================================
657 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
659 return _impl->NbSubMesh();
663 * Export mesh to a file
664 * @param fileName file name where to export the file
665 * @param fileType Currently it could be either "DAT", "UNV" or "MED".
667 void SMESH_Mesh_i::Export(const char* fileName, const char* fileType)
668 throw (SALOME::SALOME_Exception)
670 _impl->Export(fileName, fileType);