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
235 * @return The realocated and resized log.
236 * @TODO Add support for other type of elements
238 SMESH::log_array_var SMESH_Mesh_i::
239 createUpdateAllCommand(SMESH::log_array_var log, int * index)
241 MESSAGE("SMESH_Mesh_i::createUpdateAllCommand");
242 SMESH::log_array_var aLog=new SMESH::log_array(log->length()+4);
243 aLog->length(log->length()+4);
245 for(int i=0;i<*index;i++)
253 //Remove all elements
254 aLog[id].commandType=SMESH::REMOVE_ALL;
258 aLog[id].commandType=SMESH::ADD_NODE;
259 aLog[id].number=_impl->GetMeshDS()->NbNodes();
261 double * nodesCoordinates=_impl->GetMeshDS()->getNodesCoordinates();
262 aLog[id].coords=SMESH::double_array(
267 long * nodesID=_impl->GetMeshDS()->getNodesID();
268 aLog[id].indexes=SMESH::long_array(
275 MESSAGE("Export edges");
277 aLog[id].commandType=SMESH::ADD_EDGE;
278 aLog[id].number=_impl->GetMeshDS()->NbEdges();
279 aLog[id].coords.length(0);
281 long * edgesIndices=_impl->GetMeshDS()->getEdgesIndices();
282 aLog[id].indexes=SMESH::long_array(
289 MESSAGE("Export triangles");
291 aLog[id].commandType=SMESH::ADD_TRIANGLE;
292 aLog[id].number=_impl->GetMeshDS()->NbTriangles();
293 aLog[id].coords.length(0);
295 long * triasIndices=_impl->GetMeshDS()->getTrianglesIndices();
296 aLog[id].indexes=SMESH::long_array(
306 * Return the log of the current mesh. CORBA wrap of the SMESH::GetLog method
307 * with a special treatment for SMESHDS_UpdateAll commands
308 * @param clearAfterGet Tell if the log must be cleared after being returned
311 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
312 throw(SALOME::SALOME_Exception)
314 MESSAGE("SMESH_Mesh_i::GetLog");
316 SMESH::log_array_var aLog;
319 list < SMESHDS_Command * >logDS = _impl->GetLog();
320 aLog = new SMESH::log_array;
322 int lg = logDS.size();
323 MESSAGE("Number of command in the log: "<<lg);
325 list < SMESHDS_Command * >::iterator its = logDS.begin();
326 while (its != logDS.end())
328 SMESHDS_Command *com = *its;
329 int comType = com->GetType();
331 int lgcom = com->GetNumber();
333 const list < int >&intList = com->GetIndexes();
334 int inum = intList.size();
336 list < int >::const_iterator ii = intList.begin();
337 const list < double >&coordList = com->GetCoords();
338 int rnum = coordList.size();
340 list < double >::const_iterator ir = coordList.begin();
341 aLog[indexLog].commandType = comType;
342 if(comType==SMESHDS_UpdateAll)
344 aLog=createUpdateAllCommand(aLog, &indexLog);
348 aLog[indexLog].number = lgcom;
349 aLog[indexLog].coords.length(rnum);
350 aLog[indexLog].indexes.length(inum);
351 for (int i = 0; i < rnum; i++)
353 aLog[indexLog].coords[i] = *ir;
354 //MESSAGE(" "<<i<<" "<<ir.Value());
357 for (int i = 0; i < inum; i++)
359 aLog[indexLog].indexes[i] = *ii;
360 //MESSAGE(" "<<i<<" "<<ii.Value());
367 if (clearAfterGet) _impl->ClearLog();
370 catch(SALOME_Exception & S_ex)
372 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
376 // SMESH::string_array* SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
377 // throw (SALOME::SALOME_Exception)
379 // MESSAGE("SMESH_Mesh_i::GetLog");
381 // SMESH::string_array_var aLog;
384 // const SMESHDS_ListOfCommand& logDS =_impl->GetLog();
385 // aLog = new SMESH::string_array;
388 // int lg = logDS.Extent();
390 // SMESHDS_ListIteratorOfListOfCommand its(logDS);
393 // Handle(SMESHDS_Command) com = its.Value();
394 // int comType = com->GetType();
396 // int lgcom = com->GetNumber();
399 // aLog->length(logSize);
401 // const TColStd_ListOfInteger& intList = com->GetIndexes();
402 // TColStd_ListIteratorOfListOfInteger ii(intList);
403 // const TColStd_ListOfReal& coordList = com->GetCoords();
404 // TColStd_ListIteratorOfListOfReal ir(coordList);
405 // for (int icom = 1; icom <= lgcom; icom++)
410 // case SMESHDS_AddNode:
411 // S << "AddNode " << ii.Value(); ii.Next();
412 // S << " " << ir.Value(); ir.Next();
413 // S << " " << ir.Value(); ir.Next();
414 // S << " " << ir.Value(); ir.Next();
416 // case SMESHDS_AddEdge:
417 // S << "AddEdge " << ii.Value(); ii.Next();
418 // S << " " << ii.Value(); ii.Next();
419 // S << " " << ii.Value(); ii.Next();
421 // case SMESHDS_AddTriangle:
422 // S << "AddFace " << ii.Value(); ii.Next();
423 // S << " " << ii.Value(); ii.Next();
424 // S << " " << ii.Value(); ii.Next();
425 // S << " " << ii.Value(); ii.Next();
427 // case SMESHDS_AddQuadrangle:
428 // S << "AddFace " << ii.Value(); ii.Next();
429 // S << " " << ii.Value(); ii.Next();
430 // S << " " << ii.Value(); ii.Next();
431 // S << " " << ii.Value(); ii.Next();
432 // S << " " << ii.Value(); ii.Next();
434 // case SMESHDS_AddTetrahedron:
435 // S << "AddVolume " << ii.Value(); ii.Next();
436 // S << " " << ii.Value(); ii.Next();
437 // S << " " << ii.Value(); ii.Next();
438 // S << " " << ii.Value(); ii.Next();
439 // S << " " << ii.Value(); ii.Next();
441 // case SMESHDS_AddPyramid:
442 // S << "AddVolume " << ii.Value(); ii.Next();
443 // S << " " << 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();
449 // case SMESHDS_AddPrism:
450 // S << "AddVolume " << 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();
455 // S << " " << ii.Value(); ii.Next();
456 // S << " " << ii.Value(); ii.Next();
458 // case SMESHDS_AddHexahedron:
459 // S << "AddVolume " << ii.Value(); ii.Next();
460 // S << " " << 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();
469 // case SMESHDS_RemoveNode:
470 // S << "RemoveNode " << ii.Value(); ii.Next();
472 // case SMESHDS_RemoveElement:
473 // S << "RemoveElement " << ii.Value(); ii.Next();
479 // string ch = S.str();
481 // aLog[indexLog++] = CORBA::string_dup(ch.c_str());
485 // if (clearAfterGet) _impl->ClearLog();
487 // catch (SALOME_Exception& S_ex)
489 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
491 // return aLog._retn();
494 //=============================================================================
498 //=============================================================================
500 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
502 MESSAGE("SMESH_Mesh_i::ClearLog");
506 //=============================================================================
510 //=============================================================================
512 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
514 MESSAGE("SMESH_Mesh_i::GetId");
518 //=============================================================================
522 //=============================================================================
524 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
529 //=============================================================================
533 //=============================================================================
535 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
537 MESSAGE("SMESH_Mesh_i::SetImpl");
541 //=============================================================================
545 //=============================================================================
547 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
549 MESSAGE("SMESH_Mesh_i::GetImpl()");
553 //=============================================================================
557 //=============================================================================
559 GEOM::GEOM_Gen_ptr SMESH_Mesh_i::GetGeomEngine()
561 MESSAGE("SMESH_Mesh_i::GetGeomEngine");
562 return GEOM::GEOM_Gen::_duplicate(_geom);
565 //=============================================================================
569 //=============================================================================
571 void SMESH_Mesh_i::SetIor(SMESH::SMESH_Mesh_ptr myIor)
573 MESSAGE("SMESH_Mesh_i::SetIor");
574 _myIor = SMESH::SMESH_Mesh::_duplicate(myIor);
575 ASSERT(!CORBA::is_nil(_myIor));
578 //=============================================================================
582 //=============================================================================
584 SMESH::SMESH_Mesh_ptr SMESH_Mesh_i::GetIor()
586 MESSAGE("SMESH_Mesh_i::GetIor");
587 ASSERT(!CORBA::is_nil(_myIor));
588 return SMESH::SMESH_Mesh::_duplicate(_myIor);
591 //=============================================================================
595 //=============================================================================
597 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
599 SMESH_MeshEditor_i *aMeshEditor =
600 new SMESH_MeshEditor_i(_impl->GetMeshDS());
601 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
602 return aMesh._retn();
605 //=============================================================================
609 //=============================================================================
611 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
613 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
614 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
615 return aMesh._retn();
618 //=============================================================================
622 //=============================================================================
623 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
625 return _impl->NbNodes();
628 //=============================================================================
632 //=============================================================================
633 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
635 return _impl->NbEdges();
638 //=============================================================================
642 //=============================================================================
643 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
645 return _impl->NbFaces();
648 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
650 return _impl->NbTriangles();
653 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
655 return _impl->NbQuadrangles();
658 //=============================================================================
662 //=============================================================================
663 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
665 return _impl->NbVolumes();
668 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
670 return _impl->NbTetras();
673 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
675 return _impl->NbHexas();
678 //=============================================================================
682 //=============================================================================
683 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
685 return _impl->NbSubMesh();
689 * Export mesh to a file
690 * @param fileName file name where to export the file
691 * @param fileType Currently it could be either "DAT", "UNV" or "MED".
693 void SMESH_Mesh_i::Export(const char* fileName, const char* fileType)
694 throw (SALOME::SALOME_Exception)
696 _impl->Export(fileName, fileType);