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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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"
32 #include "SMESH_Group_i.hxx"
33 #include "SMESH_Filter_i.hxx"
34 #include "SMESH_PythonDump.hxx"
36 #include "Utils_CorbaException.hxx"
37 #include "Utils_ExceptHandlers.hxx"
38 #include "utilities.h"
40 #include "SALOME_NamingService.hxx"
41 #include "Utils_SINGLETON.hxx"
44 #include "SMESHDS_Command.hxx"
45 #include "SMESHDS_CommandType.hxx"
46 #include "SMESH_MeshEditor_i.hxx"
47 #include "SMESH_Gen_i.hxx"
48 #include "DriverMED_R_SMESHDS_Mesh.h"
49 //#include "SMDS_ElemIterator.hxx"
50 #include "SMDS_VolumeTool.hxx"
51 #include "SMESH_MesherHelper.hxx"
52 #include "SMESH_MeshEditor.hxx"
55 #include <BRep_Builder.hxx>
56 #include <OSD_Path.hxx>
57 #include <OSD_File.hxx>
58 #include <OSD_Directory.hxx>
59 #include <OSD_Protection.hxx>
60 #include <TColStd_MapOfInteger.hxx>
61 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
62 #include <TColStd_SequenceOfInteger.hxx>
63 #include <TCollection_AsciiString.hxx>
64 #include <TopoDS_Compound.hxx>
72 static int MYDEBUG = 0;
74 static int MYDEBUG = 0;
78 using SMESH::TPythonDump;
80 int SMESH_Mesh_i::myIdGenerator = 0;
84 //=============================================================================
88 //=============================================================================
90 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
93 : SALOME::GenericObj_i( thePOA )
95 MESSAGE("SMESH_Mesh_i");
98 _id = myIdGenerator++;
102 //=============================================================================
106 //=============================================================================
108 SMESH_Mesh_i::~SMESH_Mesh_i()
110 INFOS("~SMESH_Mesh_i");
111 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
112 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
113 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
116 // this method is colled from destructor of group (PAL6331)
117 //_impl->RemoveGroup( aGroup->GetLocalID() );
125 //=============================================================================
129 * Associates <this> mesh with <theShape> and puts a reference
130 * to <theShape> into the current study;
131 * the previous shape is substituted by the new one.
133 //=============================================================================
135 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
136 throw (SALOME::SALOME_Exception)
138 Unexpect aCatch(SALOME_SalomeException);
140 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
142 catch(SALOME_Exception & S_ex) {
143 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
147 //================================================================================
149 * \brief return true if mesh has a shape to build a shape on
151 //================================================================================
153 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
154 throw (SALOME::SALOME_Exception)
156 Unexpect aCatch(SALOME_SalomeException);
159 res = _impl->HasShapeToMesh();
161 catch(SALOME_Exception & S_ex) {
162 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
167 //=======================================================================
168 //function : GetShapeToMesh
170 //=======================================================================
172 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
173 throw (SALOME::SALOME_Exception)
175 Unexpect aCatch(SALOME_SalomeException);
176 GEOM::GEOM_Object_var aShapeObj;
178 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
180 aShapeObj = _gen_i->ShapeToGeomObject( S );
182 catch(SALOME_Exception & S_ex) {
183 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
185 return aShapeObj._retn();
188 //=============================================================================
192 //=============================================================================
194 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
196 SMESH::DriverMED_ReadStatus res;
199 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
200 res = SMESH::DRS_OK; break;
201 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
202 res = SMESH::DRS_EMPTY; break;
203 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
204 res = SMESH::DRS_WARN_RENUMBER; break;
205 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
206 res = SMESH::DRS_WARN_SKIP_ELEM; break;
207 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
209 res = SMESH::DRS_FAIL; break;
214 //=============================================================================
218 * Imports mesh data from MED file
220 //=============================================================================
222 SMESH::DriverMED_ReadStatus
223 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
224 throw ( SALOME::SALOME_Exception )
226 Unexpect aCatch(SALOME_SalomeException);
229 status = importMEDFile( theFileName, theMeshName );
231 catch( SALOME_Exception& S_ex ) {
232 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
235 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
238 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
239 if ( !aStudy->_is_nil() ) {
240 // publishing of the groups in the study (sub-meshes are out of scope of MED import)
241 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
242 for (; it != _mapGroups.end(); it++ ) {
243 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
244 _gen_i->PublishGroup( aStudy, _this(), aGroup,
245 GEOM::GEOM_Object::_nil(), aGroup->GetName());
248 return ConvertDriverMEDReadStatus(status);
251 //=============================================================================
255 * Imports mesh data from MED file
257 //=============================================================================
259 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
260 throw ( SALOME::SALOME_Exception )
262 // Read mesh with name = <theMeshName> into SMESH_Mesh
263 _impl->UNVToMesh( theFileName );
265 CreateGroupServants();
267 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
268 if ( !aStudy->_is_nil() ) {
269 // publishing of the groups in the study (sub-meshes are out of scope of UNV import)
270 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
271 for (; it != _mapGroups.end(); it++ ) {
272 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
273 _gen_i->PublishGroup( aStudy, _this(), aGroup,
274 GEOM::GEOM_Object::_nil(), aGroup->GetName());
280 //=============================================================================
284 * Imports mesh data from STL file
286 //=============================================================================
287 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
288 throw ( SALOME::SALOME_Exception )
290 // Read mesh with name = <theMeshName> into SMESH_Mesh
291 _impl->STLToMesh( theFileName );
296 //=============================================================================
300 * Imports mesh data from MED file
302 //=============================================================================
304 int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
306 // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
307 int status = _impl->MEDToMesh( theFileName, theMeshName );
308 CreateGroupServants();
313 //=============================================================================
317 //=============================================================================
319 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
321 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
322 (SMESH_Hypothesis::Hypothesis_Status theStatus)
325 RETURNCASE( HYP_OK );
326 RETURNCASE( HYP_MISSING );
327 RETURNCASE( HYP_CONCURENT );
328 RETURNCASE( HYP_BAD_PARAMETER );
329 RETURNCASE( HYP_HIDDEN_ALGO );
330 RETURNCASE( HYP_HIDING_ALGO );
331 RETURNCASE( HYP_UNKNOWN_FATAL );
332 RETURNCASE( HYP_INCOMPATIBLE );
333 RETURNCASE( HYP_NOTCONFORM );
334 RETURNCASE( HYP_ALREADY_EXIST );
335 RETURNCASE( HYP_BAD_DIM );
336 RETURNCASE( HYP_BAD_SUBSHAPE );
337 RETURNCASE( HYP_BAD_GEOMETRY );
340 return SMESH::HYP_UNKNOWN_FATAL;
343 //=============================================================================
347 * calls internal addHypothesis() and then adds a reference to <anHyp> under
348 * the SObject actually having a reference to <aSubShape>.
349 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
351 //=============================================================================
353 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
354 SMESH::SMESH_Hypothesis_ptr anHyp)
355 throw(SALOME::SALOME_Exception)
357 Unexpect aCatch(SALOME_SalomeException);
358 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
360 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
361 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
362 aSubShapeObject, anHyp );
364 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
366 // Update Python script
367 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
368 << aSubShapeObject << ", " << anHyp << " )";
370 return ConvertHypothesisStatus(status);
373 //=============================================================================
377 //=============================================================================
379 SMESH_Hypothesis::Hypothesis_Status
380 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
381 SMESH::SMESH_Hypothesis_ptr anHyp)
383 if(MYDEBUG) MESSAGE("addHypothesis");
385 if (CORBA::is_nil(aSubShapeObject))
386 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
389 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
390 if (CORBA::is_nil(myHyp))
391 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
394 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
397 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
398 int hypId = myHyp->GetId();
399 status = _impl->AddHypothesis(myLocSubShape, hypId);
400 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
401 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
402 // assure there is a corresponding submesh
403 if ( !_impl->IsMainShape( myLocSubShape )) {
404 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
405 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
406 createSubMesh( aSubShapeObject );
410 catch(SALOME_Exception & S_ex)
412 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
417 //=============================================================================
421 //=============================================================================
423 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
424 SMESH::SMESH_Hypothesis_ptr anHyp)
425 throw(SALOME::SALOME_Exception)
427 Unexpect aCatch(SALOME_SalomeException);
428 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
430 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
431 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
432 aSubShapeObject, anHyp );
434 // Update Python script
435 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
436 << aSubShapeObject << ", " << anHyp << " )";
438 return ConvertHypothesisStatus(status);
441 //=============================================================================
445 //=============================================================================
447 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
448 SMESH::SMESH_Hypothesis_ptr anHyp)
450 if(MYDEBUG) MESSAGE("removeHypothesis()");
451 // **** proposer liste de subShape (selection multiple)
453 if (CORBA::is_nil(aSubShapeObject))
454 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
457 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
458 if (CORBA::is_nil(myHyp))
459 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
462 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
465 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
466 int hypId = myHyp->GetId();
467 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
468 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
469 _mapHypo.erase( hypId );
471 catch(SALOME_Exception & S_ex)
473 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
478 //=============================================================================
482 //=============================================================================
484 SMESH::ListOfHypothesis *
485 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
486 throw(SALOME::SALOME_Exception)
488 Unexpect aCatch(SALOME_SalomeException);
489 if (MYDEBUG) MESSAGE("GetHypothesisList");
490 if (CORBA::is_nil(aSubShapeObject))
491 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
494 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
497 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
498 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
499 int i = 0, n = aLocalList.size();
502 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
503 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
504 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
505 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
510 catch(SALOME_Exception & S_ex) {
511 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
514 return aList._retn();
517 //=============================================================================
521 //=============================================================================
522 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
523 const char* theName )
524 throw(SALOME::SALOME_Exception)
526 Unexpect aCatch(SALOME_SalomeException);
527 MESSAGE("SMESH_Mesh_i::GetSubMesh");
528 if (CORBA::is_nil(aSubShapeObject))
529 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
532 SMESH::SMESH_subMesh_var subMesh;
533 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
535 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
537 //Get or Create the SMESH_subMesh object implementation
539 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
540 subMesh = getSubMesh( subMeshId );
542 // create a new subMesh object servant if there is none for the shape
543 if ( subMesh->_is_nil() )
544 subMesh = createSubMesh( aSubShapeObject );
546 if ( _gen_i->CanPublishInStudy( subMesh )) {
547 SALOMEDS::SObject_var aSO =
548 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
549 subMesh, aSubShapeObject, theName );
550 if ( !aSO->_is_nil()) {
551 // Update Python script
552 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
553 << aSubShapeObject << ", '" << theName << "' )";
557 catch(SALOME_Exception & S_ex) {
558 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
560 return subMesh._retn();
563 //=============================================================================
567 //=============================================================================
569 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
570 throw (SALOME::SALOME_Exception)
572 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
573 if ( theSubMesh->_is_nil() )
576 GEOM::GEOM_Object_var aSubShapeObject;
577 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
578 if ( !aStudy->_is_nil() ) {
579 // Remove submesh's SObject
580 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
581 if ( !anSO->_is_nil() ) {
582 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
583 SALOMEDS::SObject_var anObj, aRef;
584 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
585 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
587 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
589 // Update Python script
590 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
594 removeSubMesh( theSubMesh, aSubShapeObject.in() );
597 //=============================================================================
601 //=============================================================================
602 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
603 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
605 switch (theElemType) {
610 CASE2STRING( VOLUME );
616 //=============================================================================
620 //=============================================================================
622 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
623 const char* theName )
624 throw(SALOME::SALOME_Exception)
626 Unexpect aCatch(SALOME_SalomeException);
627 SMESH::SMESH_Group_var aNewGroup =
628 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
630 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
631 SALOMEDS::SObject_var aSO =
632 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
633 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
634 if ( !aSO->_is_nil()) {
635 // Update Python script
636 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
637 << ElementTypeString(theElemType) << ", '" << theName << "' )";
640 return aNewGroup._retn();
644 //=============================================================================
648 //=============================================================================
649 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
651 GEOM::GEOM_Object_ptr theGeomObj)
652 throw(SALOME::SALOME_Exception)
654 Unexpect aCatch(SALOME_SalomeException);
655 SMESH::SMESH_GroupOnGeom_var aNewGroup;
657 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
658 if ( !aShape.IsNull() ) {
659 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
660 ( createGroup( theElemType, theName, aShape ));
661 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
662 SALOMEDS::SObject_var aSO =
663 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
664 aNewGroup, theGeomObj, theName);
665 if ( !aSO->_is_nil()) {
666 // Update Python script
667 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
668 << ElementTypeString(theElemType) << ", '" << theName << "', "
669 << theGeomObj << " )";
674 return aNewGroup._retn();
677 //=============================================================================
681 //=============================================================================
683 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
684 throw (SALOME::SALOME_Exception)
686 if ( theGroup->_is_nil() )
689 SMESH_GroupBase_i* aGroup =
690 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
694 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
695 if ( !aStudy->_is_nil() ) {
696 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
698 if ( !aGroupSO->_is_nil() ) {
699 // Update Python script
700 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
702 // Remove group's SObject
703 aStudy->NewBuilder()->RemoveObject( aGroupSO );
707 // Remove the group from SMESH data structures
708 removeGroup( aGroup->GetLocalID() );
711 //=============================================================================
712 /*! RemoveGroupWithContents
713 * Remove group with its contents
715 //=============================================================================
716 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
717 throw (SALOME::SALOME_Exception)
719 if ( theGroup->_is_nil() )
722 SMESH_GroupBase_i* aGroup =
723 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
727 SMESH::long_array_var anIds = aGroup->GetListOfID();
728 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
730 // Update Python script
731 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
734 if ( aGroup->GetType() == SMESH::NODE )
735 aMeshEditor->RemoveNodes( anIds );
737 aMeshEditor->RemoveElements( anIds );
740 RemoveGroup( theGroup );
742 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
743 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
744 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
748 //================================================================================
750 * \brief Get the list of groups existing in the mesh
751 * \retval SMESH::ListOfGroups * - list of groups
753 //================================================================================
755 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
757 Unexpect aCatch(SALOME_SalomeException);
758 if (MYDEBUG) MESSAGE("GetGroups");
760 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
763 TPythonDump aPythonDump;
764 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
768 aList->length( _mapGroups.size() );
770 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
771 for ( ; it != _mapGroups.end(); it++ ) {
772 if ( CORBA::is_nil( it->second )) continue;
773 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
775 if (i > 1) aPythonDump << ", ";
776 aPythonDump << it->second;
780 catch(SALOME_Exception & S_ex) {
781 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
784 // Update Python script
785 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
786 aPythonDump << " ] = " << _this() << ".GetGroups()";
788 return aList._retn();
791 //=============================================================================
793 * New group is created. All mesh elements that are
794 * present in initial groups are added to the new one
796 //=============================================================================
797 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
798 SMESH::SMESH_GroupBase_ptr theGroup2,
799 const char* theName )
800 throw (SALOME::SALOME_Exception)
804 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
805 theGroup1->GetType() != theGroup2->GetType() )
806 return SMESH::SMESH_Group::_nil();
809 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
810 if ( aResGrp->_is_nil() )
811 return SMESH::SMESH_Group::_nil();
813 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
814 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
816 TColStd_MapOfInteger aResMap;
818 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
819 aResMap.Add( anIds1[ i1 ] );
821 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
822 aResMap.Add( anIds2[ i2 ] );
824 SMESH::long_array_var aResIds = new SMESH::long_array;
825 aResIds->length( aResMap.Extent() );
828 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
829 for( ; anIter.More(); anIter.Next() )
830 aResIds[ resI++ ] = anIter.Key();
832 aResGrp->Add( aResIds );
834 // Clear python lines, created by CreateGroup() and Add()
835 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
836 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
837 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
839 // Update Python script
840 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
841 << theGroup1 << ", " << theGroup2 << ", '"
844 return aResGrp._retn();
848 return SMESH::SMESH_Group::_nil();
852 //=============================================================================
854 * New group is created. All mesh elements that are
855 * present in both initial groups are added to the new one.
857 //=============================================================================
858 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
859 SMESH::SMESH_GroupBase_ptr theGroup2,
860 const char* theName )
861 throw (SALOME::SALOME_Exception)
863 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
864 theGroup1->GetType() != theGroup2->GetType() )
865 return SMESH::SMESH_Group::_nil();
867 // Create Intersection
868 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
869 if ( aResGrp->_is_nil() )
872 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
873 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
875 TColStd_MapOfInteger aMap1;
877 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
878 aMap1.Add( anIds1[ i1 ] );
880 TColStd_SequenceOfInteger aSeq;
882 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
883 if ( aMap1.Contains( anIds2[ i2 ] ) )
884 aSeq.Append( anIds2[ i2 ] );
886 SMESH::long_array_var aResIds = new SMESH::long_array;
887 aResIds->length( aSeq.Length() );
889 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
890 aResIds[ resI ] = aSeq( resI + 1 );
892 aResGrp->Add( aResIds );
894 // Clear python lines, created by CreateGroup() and Add()
895 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
896 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
897 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
899 // Update Python script
900 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
901 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
903 return aResGrp._retn();
906 //=============================================================================
908 * New group is created. All mesh elements that are present in
909 * main group but do not present in tool group are added to the new one
911 //=============================================================================
912 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
913 SMESH::SMESH_GroupBase_ptr theGroup2,
914 const char* theName )
915 throw (SALOME::SALOME_Exception)
917 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
918 theGroup1->GetType() != theGroup2->GetType() )
919 return SMESH::SMESH_Group::_nil();
922 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
923 if ( aResGrp->_is_nil() )
926 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
927 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
929 TColStd_MapOfInteger aMap2;
931 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
932 aMap2.Add( anIds2[ i2 ] );
935 TColStd_SequenceOfInteger aSeq;
936 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
937 if ( !aMap2.Contains( anIds1[ i1 ] ) )
938 aSeq.Append( anIds1[ i1 ] );
940 SMESH::long_array_var aResIds = new SMESH::long_array;
941 aResIds->length( aSeq.Length() );
943 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
944 aResIds[ resI ] = aSeq( resI + 1 );
946 aResGrp->Add( aResIds );
948 // Clear python lines, created by CreateGroup() and Add()
949 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
950 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
951 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
953 // Update Python script
954 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
955 << theGroup1 << ", " << theGroup2 << ", '"
958 return aResGrp._retn();
961 //================================================================================
963 * \brief Return group items of a group present in a study
965 //================================================================================
967 static GEOM::GEOM_Object_ptr getGroupItemsFromStudy(CORBA::Object_ptr theMesh,
969 list<TopoDS_Shape> & theItems)
971 GEOM::GEOM_Object_var groupObj;
972 SALOMEDS::Study_var study = theGen->GetCurrentStudy();
973 GEOM::GEOM_Gen_var geomGen = theGen->GetGeomEngine();
974 if ( study->_is_nil() || geomGen->_is_nil() )
975 return groupObj._retn();
977 GEOM::GEOM_IGroupOperations_var groupOp =
978 geomGen->GetIGroupOperations( theGen->GetCurrentStudyID() );
979 GEOM::GEOM_IShapesOperations_var shapeOp =
980 geomGen->GetIShapesOperations( theGen->GetCurrentStudyID() );
982 SALOMEDS::SObject_var meshOS = theGen->ObjectToSObject(study, theMesh);
983 if ( meshOS->_is_nil() || groupOp->_is_nil() || shapeOp->_is_nil() )
984 return groupObj._retn();
985 SALOMEDS::SObject_var fatherSO = meshOS->GetFather();
986 if ( fatherSO->_is_nil() || fatherSO->Tag() != theGen->GetSubMeshOnCompoundTag() )
987 return groupObj._retn(); // keep only submeshes on groups
989 SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(meshOS);
990 if ( anIter->_is_nil() ) return groupObj._retn();
991 for ( ; anIter->More(); anIter->Next())
993 SALOMEDS::SObject_var aSObject = anIter->Value();
994 SALOMEDS::SObject_var aRefSO;
995 if ( !aSObject->_is_nil() && aSObject->ReferencedObject(aRefSO) )
997 groupObj = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
998 if ( groupObj->_is_nil() ) break;
999 GEOM::ListOfLong_var ids = groupOp->GetObjects( groupObj );
1000 GEOM::GEOM_Object_var mainShape = groupObj->GetMainShape();
1001 for ( int i = 0; i < ids->length(); ++i ) {
1002 GEOM::GEOM_Object_var subShape = shapeOp->GetSubShape( mainShape, ids[i] );
1003 TopoDS_Shape S = theGen->GeomObjectToShape( subShape );
1005 theItems.push_back( S );
1010 return groupObj._retn();
1013 //=============================================================================
1015 * \brief Update hypotheses assigned to geom groups if the latter change
1017 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1019 //=============================================================================
1021 void SMESH_Mesh_i::CheckGeomGroupModif()
1023 if ( !_impl->HasShapeToMesh() ) return;
1025 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1026 if ( study->_is_nil() ) return;
1028 // check if items of groups changed
1029 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
1030 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
1032 const TopoDS_Shape & oldGroupShape = i_sm->second->GetSubShape();
1033 SMESHDS_SubMesh * oldDS = i_sm->second->GetSubMeshDS();
1034 if ( !oldDS /*|| !oldDS->IsComplexSubmesh()*/ )
1036 int oldID = i_sm->first;
1037 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldID );
1038 if ( i_smIor == _mapSubMeshIor.end() )
1040 list< TopoDS_Shape> newItems;
1041 GEOM::GEOM_Object_var groupObj = getGroupItemsFromStudy ( i_smIor->second, _gen_i, newItems );
1042 if ( groupObj->_is_nil() )
1045 int nbOldItems = oldDS->IsComplexSubmesh() ? oldDS->NbSubMeshes() : 1;
1046 int nbNewItems = newItems.size();
1047 bool groupChanged = ( nbOldItems != nbNewItems);
1048 if ( !groupChanged ) {
1049 if ( !oldDS->IsComplexSubmesh() ) { // old group has one item
1050 groupChanged = ( oldGroupShape != newItems.front() );
1053 list<TopoDS_Shape>::iterator item = newItems.begin();
1054 for ( ; item != newItems.end() && !groupChanged; ++item )
1056 SMESHDS_SubMesh * itemDS = _impl->GetMeshDS()->MeshElements( *item );
1057 groupChanged = ( !itemDS || !oldDS->ContainsSubMesh( itemDS ));
1061 // update hypotheses and submeshes if necessary
1064 // get a new group shape
1065 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1066 if ( !geomClient ) continue;
1067 TCollection_AsciiString groupIOR = _gen_i->GetGeomEngine()->GetStringFromIOR( groupObj );
1068 geomClient->RemoveShapeFromBuffer( groupIOR );
1069 TopoDS_Shape newGroupShape = _gen_i->GeomObjectToShape( groupObj );
1070 // update hypotheses
1071 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldGroupShape);
1072 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1073 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1075 _impl->RemoveHypothesis( oldGroupShape, (*hypIt)->GetID());
1076 _impl->AddHypothesis ( newGroupShape, (*hypIt)->GetID());
1078 // care of submeshes
1079 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newGroupShape );
1080 int newID = newSubmesh->GetId();
1081 if ( newID != oldID ) {
1082 _mapSubMesh [ newID ] = newSubmesh;
1083 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1084 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1085 _mapSubMesh.erase (oldID);
1086 _mapSubMesh_i.erase (oldID);
1087 _mapSubMeshIor.erase(oldID);
1088 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1094 //=============================================================================
1098 //=============================================================================
1100 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1102 if(MYDEBUG) MESSAGE( "createSubMesh" );
1103 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1105 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1106 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1107 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1108 SMESH::SMESH_subMesh_var subMesh
1109 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1111 _mapSubMesh[subMeshId] = mySubMesh;
1112 _mapSubMesh_i[subMeshId] = subMeshServant;
1113 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1115 // register CORBA object for persistence
1116 int nextId = _gen_i->RegisterObject( subMesh );
1117 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1119 return subMesh._retn();
1122 //=======================================================================
1123 //function : getSubMesh
1125 //=======================================================================
1127 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1129 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1130 if ( it == _mapSubMeshIor.end() )
1131 return SMESH::SMESH_subMesh::_nil();
1133 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1137 //=============================================================================
1141 //=============================================================================
1143 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1144 GEOM::GEOM_Object_ptr theSubShapeObject )
1146 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1147 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1151 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1152 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1153 removeHypothesis( theSubShapeObject, aHypList[i] );
1156 catch( const SALOME::SALOME_Exception& ) {
1157 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1160 int subMeshId = theSubMesh->GetId();
1162 _mapSubMesh.erase(subMeshId);
1163 _mapSubMesh_i.erase(subMeshId);
1164 _mapSubMeshIor.erase(subMeshId);
1165 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1168 //=============================================================================
1172 //=============================================================================
1174 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1175 const char* theName,
1176 const TopoDS_Shape& theShape )
1179 SMESH::SMESH_GroupBase_var aGroup;
1180 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1181 SMESH_GroupBase_i* aGroupImpl;
1182 if ( !theShape.IsNull() )
1183 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1185 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1187 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1188 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1189 aGroupImpl->Register();
1190 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1192 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1193 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1195 // register CORBA object for persistence
1196 int nextId = _gen_i->RegisterObject( aGroup );
1197 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1199 return aGroup._retn();
1202 //=============================================================================
1204 * SMESH_Mesh_i::removeGroup
1206 * Should be called by ~SMESH_Group_i()
1208 //=============================================================================
1210 void SMESH_Mesh_i::removeGroup( const int theId )
1212 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1213 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1214 _mapGroups.erase( theId );
1215 _impl->RemoveGroup( theId );
1220 //=============================================================================
1224 //=============================================================================
1226 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1227 throw(SALOME::SALOME_Exception)
1229 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1231 SMESH::log_array_var aLog;
1233 list < SMESHDS_Command * >logDS = _impl->GetLog();
1234 aLog = new SMESH::log_array;
1236 int lg = logDS.size();
1239 list < SMESHDS_Command * >::iterator its = logDS.begin();
1240 while(its != logDS.end()){
1241 SMESHDS_Command *com = *its;
1242 int comType = com->GetType();
1244 int lgcom = com->GetNumber();
1246 const list < int >&intList = com->GetIndexes();
1247 int inum = intList.size();
1249 list < int >::const_iterator ii = intList.begin();
1250 const list < double >&coordList = com->GetCoords();
1251 int rnum = coordList.size();
1253 list < double >::const_iterator ir = coordList.begin();
1254 aLog[indexLog].commandType = comType;
1255 aLog[indexLog].number = lgcom;
1256 aLog[indexLog].coords.length(rnum);
1257 aLog[indexLog].indexes.length(inum);
1258 for(int i = 0; i < rnum; i++){
1259 aLog[indexLog].coords[i] = *ir;
1260 //MESSAGE(" "<<i<<" "<<ir.Value());
1263 for(int i = 0; i < inum; i++){
1264 aLog[indexLog].indexes[i] = *ii;
1265 //MESSAGE(" "<<i<<" "<<ii.Value());
1274 catch(SALOME_Exception & S_ex){
1275 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1277 return aLog._retn();
1281 //=============================================================================
1285 //=============================================================================
1287 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1289 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1293 //=============================================================================
1297 //=============================================================================
1299 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1301 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1305 //=============================================================================
1309 //=============================================================================
1311 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1316 //=============================================================================
1320 //=============================================================================
1322 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1324 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1328 //=============================================================================
1332 //=============================================================================
1334 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1336 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1340 //=============================================================================
1342 * Return mesh editor
1344 //=============================================================================
1346 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1348 // Create MeshEditor
1349 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl, false );
1350 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1352 // Update Python script
1353 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1355 return aMesh._retn();
1358 //=============================================================================
1360 * Return mesh edition previewer
1362 //=============================================================================
1364 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1366 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl, true );
1367 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1368 return aMesh._retn();
1371 //=============================================================================
1373 * Export in different formats
1375 //=============================================================================
1377 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1379 return _impl->HasDuplicatedGroupNamesMED();
1382 static void PrepareForWriting (const char* file)
1384 TCollection_AsciiString aFullName ((char*)file);
1385 OSD_Path aPath (aFullName);
1386 OSD_File aFile (aPath);
1387 if (aFile.Exists()) {
1388 // existing filesystem node
1389 if (aFile.KindOfFile() == OSD_FILE) {
1390 if (aFile.IsWriteable()) {
1393 if (aFile.Failed()) {
1394 TCollection_AsciiString msg ("File ");
1395 msg += aFullName + " cannot be replaced.";
1396 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1399 TCollection_AsciiString msg ("File ");
1400 msg += aFullName + " cannot be overwritten.";
1401 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1404 TCollection_AsciiString msg ("Location ");
1405 msg += aFullName + " is not a file.";
1406 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1409 // nonexisting file; check if it can be created
1411 aFile.Build(OSD_WriteOnly, OSD_Protection());
1412 if (aFile.Failed()) {
1413 TCollection_AsciiString msg ("You cannot create the file ");
1414 msg += aFullName + ". Check the directory existance and access rights.";
1415 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1423 void SMESH_Mesh_i::ExportToMED (const char* file,
1424 CORBA::Boolean auto_groups,
1425 SMESH::MED_VERSION theVersion)
1426 throw(SALOME::SALOME_Exception)
1428 Unexpect aCatch(SALOME_SalomeException);
1430 // Update Python script
1431 TPythonDump() << _this() << ".ExportToMED( '"
1432 << file << "', " << auto_groups << ", " << theVersion << " )";
1435 PrepareForWriting(file);
1436 char* aMeshName = "Mesh";
1437 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1438 if ( !aStudy->_is_nil() ) {
1439 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1440 if ( !aMeshSO->_is_nil() ) {
1441 aMeshName = aMeshSO->GetName();
1443 //SCRUTE(aMeshName);
1444 //SCRUTE(aMeshSO->GetID());
1446 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1447 if ( !aStudy->GetProperties()->IsLocked() )
1449 SALOMEDS::GenericAttribute_var anAttr;
1450 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1451 SALOMEDS::AttributeExternalFileDef_var aFileName;
1452 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1453 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1454 ASSERT(!aFileName->_is_nil());
1455 aFileName->SetValue(file);
1456 SALOMEDS::AttributeFileType_var aFileType;
1457 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1458 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1459 ASSERT(!aFileType->_is_nil());
1460 aFileType->SetValue("FICHIERMED");
1464 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1467 void SMESH_Mesh_i::ExportMED (const char* file,
1468 CORBA::Boolean auto_groups)
1469 throw(SALOME::SALOME_Exception)
1471 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1474 void SMESH_Mesh_i::ExportDAT (const char *file)
1475 throw(SALOME::SALOME_Exception)
1477 Unexpect aCatch(SALOME_SalomeException);
1479 // Update Python script
1480 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1483 PrepareForWriting(file);
1484 _impl->ExportDAT(file);
1487 void SMESH_Mesh_i::ExportUNV (const char *file)
1488 throw(SALOME::SALOME_Exception)
1490 Unexpect aCatch(SALOME_SalomeException);
1492 // Update Python script
1493 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1496 PrepareForWriting(file);
1497 _impl->ExportUNV(file);
1500 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1501 throw(SALOME::SALOME_Exception)
1503 Unexpect aCatch(SALOME_SalomeException);
1505 // Update Python script
1506 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1509 PrepareForWriting(file);
1510 _impl->ExportSTL(file, isascii);
1513 //=============================================================================
1517 //=============================================================================
1519 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1521 Unexpect aCatch(SALOME_SalomeException);
1522 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1523 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1524 return aMesh._retn();
1527 //=============================================================================
1531 //=============================================================================
1532 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1534 Unexpect aCatch(SALOME_SalomeException);
1535 return _impl->NbNodes();
1538 //=============================================================================
1542 //=============================================================================
1543 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1545 Unexpect aCatch(SALOME_SalomeException);
1546 return NbEdges() + NbFaces() + NbVolumes();
1549 //=============================================================================
1553 //=============================================================================
1554 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1556 Unexpect aCatch(SALOME_SalomeException);
1557 return _impl->NbEdges();
1560 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1561 throw(SALOME::SALOME_Exception)
1563 Unexpect aCatch(SALOME_SalomeException);
1564 return _impl->NbEdges( (::SMESH_Mesh::ElementOrder) order);
1567 //=============================================================================
1571 //=============================================================================
1572 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1574 Unexpect aCatch(SALOME_SalomeException);
1575 return _impl->NbFaces();
1578 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1580 Unexpect aCatch(SALOME_SalomeException);
1581 return _impl->NbTriangles();
1584 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1586 Unexpect aCatch(SALOME_SalomeException);
1587 return _impl->NbQuadrangles();
1590 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1592 Unexpect aCatch(SALOME_SalomeException);
1593 return _impl->NbPolygons();
1596 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1597 throw(SALOME::SALOME_Exception)
1599 Unexpect aCatch(SALOME_SalomeException);
1600 return _impl->NbFaces( (::SMESH_Mesh::ElementOrder) order);
1603 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1604 throw(SALOME::SALOME_Exception)
1606 Unexpect aCatch(SALOME_SalomeException);
1607 return _impl->NbTriangles( (::SMESH_Mesh::ElementOrder) order);
1610 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1611 throw(SALOME::SALOME_Exception)
1613 Unexpect aCatch(SALOME_SalomeException);
1614 return _impl->NbQuadrangles( (::SMESH_Mesh::ElementOrder) order);
1617 //=============================================================================
1621 //=============================================================================
1622 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1624 Unexpect aCatch(SALOME_SalomeException);
1625 return _impl->NbVolumes();
1628 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1630 Unexpect aCatch(SALOME_SalomeException);
1631 return _impl->NbTetras();
1634 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1636 Unexpect aCatch(SALOME_SalomeException);
1637 return _impl->NbHexas();
1640 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1642 Unexpect aCatch(SALOME_SalomeException);
1643 return _impl->NbPyramids();
1646 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1648 Unexpect aCatch(SALOME_SalomeException);
1649 return _impl->NbPrisms();
1652 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1654 Unexpect aCatch(SALOME_SalomeException);
1655 return _impl->NbPolyhedrons();
1658 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1659 throw(SALOME::SALOME_Exception)
1661 Unexpect aCatch(SALOME_SalomeException);
1662 return _impl->NbVolumes( (::SMESH_Mesh::ElementOrder) order);
1665 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1666 throw(SALOME::SALOME_Exception)
1668 Unexpect aCatch(SALOME_SalomeException);
1669 return _impl->NbTetras( (::SMESH_Mesh::ElementOrder) order);
1672 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1673 throw(SALOME::SALOME_Exception)
1675 Unexpect aCatch(SALOME_SalomeException);
1676 return _impl->NbHexas( (::SMESH_Mesh::ElementOrder) order);
1679 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1680 throw(SALOME::SALOME_Exception)
1682 Unexpect aCatch(SALOME_SalomeException);
1683 return _impl->NbPyramids( (::SMESH_Mesh::ElementOrder) order);
1686 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1687 throw(SALOME::SALOME_Exception)
1689 Unexpect aCatch(SALOME_SalomeException);
1690 return _impl->NbPrisms( (::SMESH_Mesh::ElementOrder) order);
1693 //=============================================================================
1697 //=============================================================================
1698 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1700 Unexpect aCatch(SALOME_SalomeException);
1701 return _impl->NbSubMesh();
1704 //=============================================================================
1708 //=============================================================================
1709 char* SMESH_Mesh_i::Dump()
1711 std::ostringstream os;
1713 return CORBA::string_dup( os.str().c_str() );
1716 //=============================================================================
1720 //=============================================================================
1721 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1723 // SMESH::long_array_var aResult = new SMESH::long_array();
1724 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1725 // int aMinId = aSMESHDS_Mesh->MinElementID();
1726 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1728 // aResult->length(aMaxId - aMinId + 1);
1730 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1731 // aResult[i++] = id;
1733 // return aResult._retn();
1735 return GetElementsId();
1738 //=============================================================================
1742 //=============================================================================
1744 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1745 throw (SALOME::SALOME_Exception)
1747 Unexpect aCatch(SALOME_SalomeException);
1748 MESSAGE("SMESH_Mesh_i::GetElementsId");
1749 SMESH::long_array_var aResult = new SMESH::long_array();
1750 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1752 if ( aSMESHDS_Mesh == NULL )
1753 return aResult._retn();
1755 long nbElements = NbElements();
1756 aResult->length( nbElements );
1757 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1758 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1759 aResult[i] = anIt->next()->GetID();
1761 return aResult._retn();
1765 //=============================================================================
1769 //=============================================================================
1771 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1772 throw (SALOME::SALOME_Exception)
1774 Unexpect aCatch(SALOME_SalomeException);
1775 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1776 SMESH::long_array_var aResult = new SMESH::long_array();
1777 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1779 if ( aSMESHDS_Mesh == NULL )
1780 return aResult._retn();
1782 long nbElements = NbElements();
1784 // No sense in returning ids of elements along with ids of nodes:
1785 // when theElemType == SMESH::ALL, return node ids only if
1786 // there are no elements
1787 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1788 return GetNodesId();
1790 aResult->length( nbElements );
1794 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1795 while ( i < nbElements && anIt->more() ) {
1796 const SMDS_MeshElement* anElem = anIt->next();
1797 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1798 aResult[i++] = anElem->GetID();
1801 aResult->length( i );
1803 return aResult._retn();
1806 //=============================================================================
1810 //=============================================================================
1812 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1813 throw (SALOME::SALOME_Exception)
1815 Unexpect aCatch(SALOME_SalomeException);
1816 MESSAGE("SMESH_subMesh_i::GetNodesId");
1817 SMESH::long_array_var aResult = new SMESH::long_array();
1818 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1820 if ( aSMESHDS_Mesh == NULL )
1821 return aResult._retn();
1823 long nbNodes = NbNodes();
1824 aResult->length( nbNodes );
1825 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1826 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1827 aResult[i] = anIt->next()->GetID();
1829 return aResult._retn();
1832 //=============================================================================
1836 //=============================================================================
1838 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1839 throw (SALOME::SALOME_Exception)
1841 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1845 //=============================================================================
1847 * Returns ID of elements for given submesh
1849 //=============================================================================
1850 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1851 throw (SALOME::SALOME_Exception)
1853 SMESH::long_array_var aResult = new SMESH::long_array();
1855 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1856 if(!SM) return aResult._retn();
1858 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1859 if(!SDSM) return aResult._retn();
1861 aResult->length(SDSM->NbElements());
1863 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1865 while ( eIt->more() ) {
1866 aResult[i++] = eIt->next()->GetID();
1869 return aResult._retn();
1873 //=============================================================================
1875 * Returns ID of nodes for given submesh
1876 * If param all==true - returns all nodes, else -
1877 * returns only nodes on shapes.
1879 //=============================================================================
1880 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1881 throw (SALOME::SALOME_Exception)
1883 SMESH::long_array_var aResult = new SMESH::long_array();
1885 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1886 if(!SM) return aResult._retn();
1888 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1889 if(!SDSM) return aResult._retn();
1891 map<int,const SMDS_MeshElement*> theElems;
1892 if( !all || (SDSM->NbElements()==0 && SDSM->NbNodes()==1) ) {
1893 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1894 while ( nIt->more() ) {
1895 const SMDS_MeshNode* elem = nIt->next();
1896 theElems.insert( make_pair(elem->GetID(),elem) );
1899 else { // all nodes of submesh elements
1900 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1901 while ( eIt->more() ) {
1902 const SMDS_MeshElement* anElem = eIt->next();
1903 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
1904 while ( nIt->more() ) {
1905 const SMDS_MeshElement* elem = nIt->next();
1906 theElems.insert( make_pair(elem->GetID(),elem) );
1911 aResult->length(theElems.size());
1912 map<int, const SMDS_MeshElement * >::iterator itElem;
1914 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
1915 aResult[i++] = (*itElem).first;
1917 return aResult._retn();
1921 //=============================================================================
1923 * Returns type of elements for given submesh
1925 //=============================================================================
1926 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
1927 throw (SALOME::SALOME_Exception)
1929 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1930 if(!SM) return SMESH::ALL;
1932 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1933 if(!SDSM) return SMESH::ALL;
1935 if(SDSM->NbElements()==0)
1936 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
1938 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1939 const SMDS_MeshElement* anElem = eIt->next();
1940 return ( SMESH::ElementType ) anElem->GetType();
1944 //=============================================================================
1948 //=============================================================================
1950 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
1952 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
1953 cerr << "CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() " << pointeur << endl;
1958 //=============================================================================
1960 * Get XYZ coordinates of node as list of double
1961 * If there is not node for given ID - returns empty list
1963 //=============================================================================
1965 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
1967 SMESH::double_array_var aResult = new SMESH::double_array();
1968 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1969 if ( aSMESHDS_Mesh == NULL )
1970 return aResult._retn();
1973 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1975 return aResult._retn();
1979 aResult[0] = aNode->X();
1980 aResult[1] = aNode->Y();
1981 aResult[2] = aNode->Z();
1982 return aResult._retn();
1986 //=============================================================================
1988 * For given node returns list of IDs of inverse elements
1989 * If there is not node for given ID - returns empty list
1991 //=============================================================================
1993 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
1995 SMESH::long_array_var aResult = new SMESH::long_array();
1996 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1997 if ( aSMESHDS_Mesh == NULL )
1998 return aResult._retn();
2001 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2003 return aResult._retn();
2005 // find inverse elements
2006 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2007 TColStd_SequenceOfInteger IDs;
2008 while(eIt->more()) {
2009 const SMDS_MeshElement* elem = eIt->next();
2010 IDs.Append(elem->GetID());
2012 if(IDs.Length()>0) {
2013 aResult->length(IDs.Length());
2015 for(; i<=IDs.Length(); i++) {
2016 aResult[i-1] = IDs.Value(i);
2019 return aResult._retn();
2023 //=============================================================================
2025 * If given element is node returns IDs of shape from position
2026 * If there is not node for given ID - returns -1
2028 //=============================================================================
2030 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2032 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2033 if ( aSMESHDS_Mesh == NULL )
2037 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2039 SMDS_PositionPtr pos = aNode->GetPosition();
2043 return pos->GetShapeId();
2050 //=============================================================================
2052 * For given element returns ID of result shape after
2053 * ::FindShape() from SMESH_MeshEditor
2054 * If there is not element for given ID - returns -1
2056 //=============================================================================
2058 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2060 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2061 if ( aSMESHDS_Mesh == NULL )
2064 // try to find element
2065 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2069 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2070 ::SMESH_MeshEditor aMeshEditor(_impl);
2071 int index = aMeshEditor.FindShape( elem );
2079 //=============================================================================
2081 * Returns number of nodes for given element
2082 * If there is not element for given ID - returns -1
2084 //=============================================================================
2086 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2088 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2089 if ( aSMESHDS_Mesh == NULL ) return -1;
2090 // try to find element
2091 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2092 if(!elem) return -1;
2093 return elem->NbNodes();
2097 //=============================================================================
2099 * Returns ID of node by given index for given element
2100 * If there is not element for given ID - returns -1
2101 * If there is not node for given index - returns -2
2103 //=============================================================================
2105 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2107 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2108 if ( aSMESHDS_Mesh == NULL ) return -1;
2109 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2110 if(!elem) return -1;
2111 if( index>=elem->NbNodes() || index<0 ) return -1;
2112 return elem->GetNode(index)->GetID();
2115 //=============================================================================
2117 * Returns IDs of nodes of given element
2119 //=============================================================================
2121 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2123 SMESH::long_array_var aResult = new SMESH::long_array();
2124 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2126 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2128 aResult->length( elem->NbNodes() );
2129 for ( int i = 0; i < elem->NbNodes(); ++i )
2130 aResult[ i ] = elem->GetNode( i )->GetID();
2133 return aResult._retn();
2136 //=============================================================================
2138 * Returns true if given node is medium node
2139 * in given quadratic element
2141 //=============================================================================
2143 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2145 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2146 if ( aSMESHDS_Mesh == NULL ) return false;
2148 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2149 if(!aNode) return false;
2150 // try to find element
2151 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2152 if(!elem) return false;
2154 return elem->IsMediumNode(aNode);
2158 //=============================================================================
2160 * Returns true if given node is medium node
2161 * in one of quadratic elements
2163 //=============================================================================
2165 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2166 SMESH::ElementType theElemType)
2168 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2169 if ( aSMESHDS_Mesh == NULL ) return false;
2172 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2173 if(!aNode) return false;
2175 SMESH_MesherHelper aHelper( *(_impl) );
2177 SMDSAbs_ElementType aType;
2178 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2179 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2180 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2181 else aType = SMDSAbs_All;
2183 return aHelper.IsMedium(aNode,aType);
2187 //=============================================================================
2189 * Returns number of edges for given element
2191 //=============================================================================
2193 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2195 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2196 if ( aSMESHDS_Mesh == NULL ) return -1;
2197 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2198 if(!elem) return -1;
2199 return elem->NbEdges();
2203 //=============================================================================
2205 * Returns number of faces for given element
2207 //=============================================================================
2209 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2211 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2212 if ( aSMESHDS_Mesh == NULL ) return -1;
2213 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2214 if(!elem) return -1;
2215 return elem->NbFaces();
2219 //=============================================================================
2221 * Returns true if given element is polygon
2223 //=============================================================================
2225 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2227 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2228 if ( aSMESHDS_Mesh == NULL ) return false;
2229 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2230 if(!elem) return false;
2231 return elem->IsPoly();
2235 //=============================================================================
2237 * Returns true if given element is quadratic
2239 //=============================================================================
2241 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2243 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2244 if ( aSMESHDS_Mesh == NULL ) return false;
2245 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2246 if(!elem) return false;
2247 return elem->IsQuadratic();
2251 //=============================================================================
2253 * Returns bary center for given element
2255 //=============================================================================
2257 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2259 SMESH::double_array_var aResult = new SMESH::double_array();
2260 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2261 if ( aSMESHDS_Mesh == NULL )
2262 return aResult._retn();
2264 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2266 return aResult._retn();
2268 if(elem->GetType()==SMDSAbs_Volume) {
2269 // use SMDS_VolumeTool
2270 SMDS_VolumeTool aTool;
2271 if(aTool.Set(elem)) {
2272 double x=0., y=0., z=0.;
2273 if(aTool.GetBaryCenter(x,y,z)) {
2283 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2285 double x=0., y=0., z=0.;
2286 for(; anIt->more(); ) {
2288 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2302 return aResult._retn();
2306 //=============================================================================
2310 //=============================================================================
2311 void SMESH_Mesh_i::CreateGroupServants()
2313 // Create group servants, if any groups were imported
2314 list<int> aGroupIds = _impl->GetGroupIds();
2315 for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
2316 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
2318 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2319 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2320 aGroupImpl->Register();
2321 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2323 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
2324 _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
2326 // register CORBA object for persistence
2327 int nextId = _gen_i->RegisterObject( aGroup );
2328 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);