1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_Mesh_i.cxx
24 // Author : Paul RASCLE, EDF
27 #include "SMESH_Mesh_i.hxx"
29 #include "SMESH_Filter_i.hxx"
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_Group_i.hxx"
32 #include "SMESH_MEDMesh_i.hxx"
33 #include "SMESH_MeshEditor_i.hxx"
34 #include "SMESH_PythonDump.hxx"
35 #include "SMESH_subMesh_i.hxx"
37 #include "DriverMED_R_SMESHDS_Mesh.h"
38 #include "DriverMED_W_SMESHDS_Mesh.h"
39 #include "SMDS_VolumeTool.hxx"
40 #include "SMESHDS_Command.hxx"
41 #include "SMESHDS_CommandType.hxx"
42 #include "SMESHDS_GroupOnGeom.hxx"
43 #include "SMESH_Group.hxx"
44 #include "SMESH_MeshEditor.hxx"
45 #include "SMESH_MesherHelper.hxx"
46 #include "SMDS_EdgePosition.hxx"
47 #include "SMDS_FacePosition.hxx"
50 #include "SALOME_NamingService.hxx"
51 #include "Utils_CorbaException.hxx"
52 #include "Utils_ExceptHandlers.hxx"
53 #include "Utils_SINGLETON.hxx"
54 #include "utilities.h"
57 #include <BRep_Builder.hxx>
58 #include <OSD_Directory.hxx>
59 #include <OSD_File.hxx>
60 #include <OSD_Path.hxx>
61 #include <OSD_Protection.hxx>
62 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
63 #include <TColStd_MapOfInteger.hxx>
64 #include <TColStd_SequenceOfInteger.hxx>
65 #include <TCollection_AsciiString.hxx>
66 #include <TopExp_Explorer.hxx>
67 #include <TopoDS_Compound.hxx>
76 static int MYDEBUG = 0;
78 static int MYDEBUG = 0;
82 using SMESH::TPythonDump;
84 int SMESH_Mesh_i::myIdGenerator = 0;
88 //=============================================================================
92 //=============================================================================
94 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
97 : SALOME::GenericObj_i( thePOA )
99 MESSAGE("SMESH_Mesh_i");
102 _id = myIdGenerator++;
106 //=============================================================================
110 //=============================================================================
112 SMESH_Mesh_i::~SMESH_Mesh_i()
114 INFOS("~SMESH_Mesh_i");
115 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
116 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
117 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
119 // this method is colled from destructor of group (PAL6331)
120 //_impl->RemoveGroup( aGroup->GetLocalID() );
129 //=============================================================================
133 * Associates <this> mesh with <theShape> and puts a reference
134 * to <theShape> into the current study;
135 * the previous shape is substituted by the new one.
137 //=============================================================================
139 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
140 throw (SALOME::SALOME_Exception)
142 Unexpect aCatch(SALOME_SalomeException);
144 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
146 catch(SALOME_Exception & S_ex) {
147 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
151 //================================================================================
153 * \brief return true if mesh has a shape to build a shape on
155 //================================================================================
157 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
158 throw (SALOME::SALOME_Exception)
160 Unexpect aCatch(SALOME_SalomeException);
163 res = _impl->HasShapeToMesh();
165 catch(SALOME_Exception & S_ex) {
166 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
171 //=======================================================================
172 //function : GetShapeToMesh
174 //=======================================================================
176 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
177 throw (SALOME::SALOME_Exception)
179 Unexpect aCatch(SALOME_SalomeException);
180 GEOM::GEOM_Object_var aShapeObj;
182 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
184 aShapeObj = _gen_i->ShapeToGeomObject( S );
186 catch(SALOME_Exception & S_ex) {
187 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
189 return aShapeObj._retn();
192 //================================================================================
194 * \brief Remove all nodes and elements
196 //================================================================================
198 void SMESH_Mesh_i::Clear() throw (SALOME::SALOME_Exception)
200 Unexpect aCatch(SALOME_SalomeException);
204 catch(SALOME_Exception & S_ex) {
205 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
207 TPythonDump() << _this() << ".Clear()";
210 //================================================================================
212 * \brief Remove all nodes and elements for indicated shape
214 //================================================================================
216 void SMESH_Mesh_i::ClearSubMesh(CORBA::Long ShapeID)
217 throw (SALOME::SALOME_Exception)
219 Unexpect aCatch(SALOME_SalomeException);
221 _impl->ClearSubMesh( ShapeID );
223 catch(SALOME_Exception & S_ex) {
224 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
228 //=============================================================================
232 //=============================================================================
234 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
236 SMESH::DriverMED_ReadStatus res;
239 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
240 res = SMESH::DRS_OK; break;
241 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
242 res = SMESH::DRS_EMPTY; break;
243 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
244 res = SMESH::DRS_WARN_RENUMBER; break;
245 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
246 res = SMESH::DRS_WARN_SKIP_ELEM; break;
247 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
249 res = SMESH::DRS_FAIL; break;
254 //=============================================================================
258 * Imports mesh data from MED file
260 //=============================================================================
262 SMESH::DriverMED_ReadStatus
263 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
264 throw ( SALOME::SALOME_Exception )
266 Unexpect aCatch(SALOME_SalomeException);
269 status = _impl->MEDToMesh( theFileName, theMeshName );
271 catch( SALOME_Exception& S_ex ) {
272 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
275 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
278 CreateGroupServants();
280 int major, minor, release;
281 if( !MED::getMEDVersion( theFileName, major, minor, release ) )
282 major = minor = release = -1;
283 myFileInfo = new SALOME_MED::MedFileInfo();
284 myFileInfo->fileName = theFileName;
285 myFileInfo->fileSize = 0;
288 if ( ::_stati64( theFileName, &d ) != -1 )
291 if ( ::stat64( theFileName, &d ) != -1 )
293 myFileInfo->fileSize = d.st_size;
294 myFileInfo->major = major;
295 myFileInfo->minor = minor;
296 myFileInfo->release = release;
298 return ConvertDriverMEDReadStatus(status);
301 //================================================================================
303 * \brief Return string representation of a MED file version comprising nbDigits
305 //================================================================================
307 char* SMESH_Mesh_i::GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits)
309 std::string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(MED::EVersion(version),
311 return CORBA::string_dup( ver.c_str() );
314 //=============================================================================
318 * Imports mesh data from MED file
320 //=============================================================================
322 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
323 throw ( SALOME::SALOME_Exception )
325 // Read mesh with name = <theMeshName> into SMESH_Mesh
326 _impl->UNVToMesh( theFileName );
328 CreateGroupServants();
333 //=============================================================================
337 * Imports mesh data from STL file
339 //=============================================================================
340 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
341 throw ( SALOME::SALOME_Exception )
343 // Read mesh with name = <theMeshName> into SMESH_Mesh
344 _impl->STLToMesh( theFileName );
349 //=============================================================================
353 * Imports mesh data from MED file
355 //=============================================================================
357 // int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
359 // // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
360 // int status = _impl->MEDToMesh( theFileName, theMeshName );
361 // CreateGroupServants();
366 //=============================================================================
370 //=============================================================================
372 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
374 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
375 (SMESH_Hypothesis::Hypothesis_Status theStatus)
378 RETURNCASE( HYP_OK );
379 RETURNCASE( HYP_MISSING );
380 RETURNCASE( HYP_CONCURENT );
381 RETURNCASE( HYP_BAD_PARAMETER );
382 RETURNCASE( HYP_HIDDEN_ALGO );
383 RETURNCASE( HYP_HIDING_ALGO );
384 RETURNCASE( HYP_UNKNOWN_FATAL );
385 RETURNCASE( HYP_INCOMPATIBLE );
386 RETURNCASE( HYP_NOTCONFORM );
387 RETURNCASE( HYP_ALREADY_EXIST );
388 RETURNCASE( HYP_BAD_DIM );
389 RETURNCASE( HYP_BAD_SUBSHAPE );
390 RETURNCASE( HYP_BAD_GEOMETRY );
391 RETURNCASE( HYP_NEED_SHAPE );
394 return SMESH::HYP_UNKNOWN_FATAL;
397 //=============================================================================
401 * calls internal addHypothesis() and then adds a reference to <anHyp> under
402 * the SObject actually having a reference to <aSubShape>.
403 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
405 //=============================================================================
407 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
408 SMESH::SMESH_Hypothesis_ptr anHyp)
409 throw(SALOME::SALOME_Exception)
411 Unexpect aCatch(SALOME_SalomeException);
412 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
414 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
415 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
416 aSubShapeObject, anHyp );
418 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
420 // Update Python script
421 if(_impl->HasShapeToMesh()) {
422 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
423 << aSubShapeObject << ", " << anHyp << " )";
426 TPythonDump() << "status = " << _this() << ".AddHypothesis( "<< anHyp << " )";
429 return ConvertHypothesisStatus(status);
432 //=============================================================================
436 //=============================================================================
438 SMESH_Hypothesis::Hypothesis_Status
439 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
440 SMESH::SMESH_Hypothesis_ptr anHyp)
442 if(MYDEBUG) MESSAGE("addHypothesis");
444 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
445 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
448 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
449 if (CORBA::is_nil(myHyp))
450 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
453 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
456 TopoDS_Shape myLocSubShape;
457 //use PseudoShape in case if mesh has no shape
459 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
461 myLocSubShape = _impl->GetShapeToMesh();
463 int hypId = myHyp->GetId();
464 status = _impl->AddHypothesis(myLocSubShape, hypId);
465 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
466 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
467 // assure there is a corresponding submesh
468 if ( !_impl->IsMainShape( myLocSubShape )) {
469 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
470 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
471 createSubMesh( aSubShapeObject );
475 catch(SALOME_Exception & S_ex)
477 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
482 //=============================================================================
486 //=============================================================================
488 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
489 SMESH::SMESH_Hypothesis_ptr anHyp)
490 throw(SALOME::SALOME_Exception)
492 Unexpect aCatch(SALOME_SalomeException);
493 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
495 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
496 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
497 aSubShapeObject, anHyp );
499 // Update Python script
500 // Update Python script
501 if(_impl->HasShapeToMesh()) {
502 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
503 << aSubShapeObject << ", " << anHyp << " )";
506 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
510 return ConvertHypothesisStatus(status);
513 //=============================================================================
517 //=============================================================================
519 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
520 SMESH::SMESH_Hypothesis_ptr anHyp)
522 if(MYDEBUG) MESSAGE("removeHypothesis()");
523 // **** proposer liste de subShape (selection multiple)
525 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
526 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
529 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
530 if (CORBA::is_nil(myHyp))
531 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
534 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
537 TopoDS_Shape myLocSubShape;
538 //use PseudoShape in case if mesh has no shape
540 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
542 myLocSubShape = _impl->GetShapeToMesh();
544 int hypId = myHyp->GetId();
545 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
546 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
547 _mapHypo.erase( hypId );
549 catch(SALOME_Exception & S_ex)
551 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
556 //=============================================================================
560 //=============================================================================
562 SMESH::ListOfHypothesis *
563 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
564 throw(SALOME::SALOME_Exception)
566 Unexpect aCatch(SALOME_SalomeException);
567 if (MYDEBUG) MESSAGE("GetHypothesisList");
568 if (CORBA::is_nil(aSubShapeObject))
569 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
572 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
575 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
576 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
577 int i = 0, n = aLocalList.size();
580 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
581 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
582 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
583 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
588 catch(SALOME_Exception & S_ex) {
589 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
592 return aList._retn();
595 //=============================================================================
599 //=============================================================================
600 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
601 const char* theName )
602 throw(SALOME::SALOME_Exception)
604 Unexpect aCatch(SALOME_SalomeException);
605 MESSAGE("SMESH_Mesh_i::GetSubMesh");
606 if (CORBA::is_nil(aSubShapeObject))
607 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
610 SMESH::SMESH_subMesh_var subMesh;
611 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
613 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
615 //Get or Create the SMESH_subMesh object implementation
617 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
618 subMesh = getSubMesh( subMeshId );
620 // create a new subMesh object servant if there is none for the shape
621 if ( subMesh->_is_nil() )
622 subMesh = createSubMesh( aSubShapeObject );
624 if ( _gen_i->CanPublishInStudy( subMesh )) {
625 SALOMEDS::SObject_var aSO =
626 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
627 subMesh, aSubShapeObject, theName );
628 if ( !aSO->_is_nil()) {
629 // Update Python script
630 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
631 << aSubShapeObject << ", '" << theName << "' )";
635 catch(SALOME_Exception & S_ex) {
636 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
638 return subMesh._retn();
641 //=============================================================================
645 //=============================================================================
647 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
648 throw (SALOME::SALOME_Exception)
650 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
651 if ( theSubMesh->_is_nil() )
654 GEOM::GEOM_Object_var aSubShapeObject;
655 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
656 if ( !aStudy->_is_nil() ) {
657 // Remove submesh's SObject
658 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
659 if ( !anSO->_is_nil() ) {
660 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
661 SALOMEDS::SObject_var anObj, aRef;
662 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
663 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
665 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
667 // Update Python script
668 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
672 removeSubMesh( theSubMesh, aSubShapeObject.in() );
675 //=============================================================================
679 //=============================================================================
680 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
681 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
683 switch (theElemType) {
688 CASE2STRING( VOLUME );
694 //=============================================================================
698 //=============================================================================
700 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
701 const char* theName )
702 throw(SALOME::SALOME_Exception)
704 Unexpect aCatch(SALOME_SalomeException);
705 SMESH::SMESH_Group_var aNewGroup =
706 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
708 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
709 SALOMEDS::SObject_var aSO =
710 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
711 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
712 if ( !aSO->_is_nil()) {
713 // Update Python script
714 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
715 << ElementTypeString(theElemType) << ", '" << theName << "' )";
718 return aNewGroup._retn();
722 //=============================================================================
726 //=============================================================================
727 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
729 GEOM::GEOM_Object_ptr theGeomObj)
730 throw(SALOME::SALOME_Exception)
732 Unexpect aCatch(SALOME_SalomeException);
733 SMESH::SMESH_GroupOnGeom_var aNewGroup;
735 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
736 if ( !aShape.IsNull() ) {
737 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
738 ( createGroup( theElemType, theName, aShape ));
739 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
740 SALOMEDS::SObject_var aSO =
741 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
742 aNewGroup, theGeomObj, theName);
743 if ( !aSO->_is_nil()) {
744 // Update Python script
745 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
746 << ElementTypeString(theElemType) << ", '" << theName << "', "
747 << theGeomObj << " )";
752 return aNewGroup._retn();
755 //=============================================================================
759 //=============================================================================
761 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
762 throw (SALOME::SALOME_Exception)
764 if ( theGroup->_is_nil() )
767 SMESH_GroupBase_i* aGroup =
768 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
772 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
773 if ( !aStudy->_is_nil() ) {
774 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
776 if ( !aGroupSO->_is_nil() ) {
777 // Update Python script
778 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
780 // Remove group's SObject
781 aStudy->NewBuilder()->RemoveObjectWithChildren( aGroupSO );
785 // Remove the group from SMESH data structures
786 removeGroup( aGroup->GetLocalID() );
789 //=============================================================================
790 /*! RemoveGroupWithContents
791 * Remove group with its contents
793 //=============================================================================
794 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
795 throw (SALOME::SALOME_Exception)
797 if ( theGroup->_is_nil() )
800 SMESH_GroupBase_i* aGroup =
801 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
805 SMESH::long_array_var anIds = aGroup->GetListOfID();
806 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
808 // Update Python script
809 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
812 if ( aGroup->GetType() == SMESH::NODE )
813 aMeshEditor->RemoveNodes( anIds );
815 aMeshEditor->RemoveElements( anIds );
818 RemoveGroup( theGroup );
820 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
821 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
822 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
826 //================================================================================
828 * \brief Get the list of groups existing in the mesh
829 * \retval SMESH::ListOfGroups * - list of groups
831 //================================================================================
833 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
835 Unexpect aCatch(SALOME_SalomeException);
836 if (MYDEBUG) MESSAGE("GetGroups");
838 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
841 TPythonDump aPythonDump;
842 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
846 aList->length( _mapGroups.size() );
848 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
849 for ( ; it != _mapGroups.end(); it++ ) {
850 if ( CORBA::is_nil( it->second )) continue;
851 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
853 if (i > 1) aPythonDump << ", ";
854 aPythonDump << it->second;
858 catch(SALOME_Exception & S_ex) {
859 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
862 // Update Python script
863 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
864 aPythonDump << " ] = " << _this() << ".GetGroups()";
866 return aList._retn();
868 //=============================================================================
870 * Get number of groups existing in the mesh
872 //=============================================================================
874 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
876 Unexpect aCatch(SALOME_SalomeException);
877 return _mapGroups.size();
880 //=============================================================================
882 * New group is created. All mesh elements that are
883 * present in initial groups are added to the new one
885 //=============================================================================
886 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
887 SMESH::SMESH_GroupBase_ptr theGroup2,
888 const char* theName )
889 throw (SALOME::SALOME_Exception)
893 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
894 theGroup1->GetType() != theGroup2->GetType() )
895 return SMESH::SMESH_Group::_nil();
898 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
899 if ( aResGrp->_is_nil() )
900 return SMESH::SMESH_Group::_nil();
902 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
903 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
905 TColStd_MapOfInteger aResMap;
907 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
908 aResMap.Add( anIds1[ i1 ] );
910 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
911 aResMap.Add( anIds2[ i2 ] );
913 SMESH::long_array_var aResIds = new SMESH::long_array;
914 aResIds->length( aResMap.Extent() );
917 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
918 for( ; anIter.More(); anIter.Next() )
919 aResIds[ resI++ ] = anIter.Key();
921 aResGrp->Add( aResIds );
923 // Clear python lines, created by CreateGroup() and Add()
924 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
925 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
926 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
928 // Update Python script
929 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
930 << theGroup1 << ", " << theGroup2 << ", '"
933 return aResGrp._retn();
937 return SMESH::SMESH_Group::_nil();
941 //=============================================================================
943 \brief Union list of groups. New group is created. All mesh elements that are
944 present in initial groups are added to the new one.
945 \param theGroups list of groups
946 \param theName name of group to be created
947 \return pointer on the group
949 //=============================================================================
950 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionListOfGroups(const SMESH::ListOfGroups& theGroups,
951 const char* theName )
952 throw (SALOME::SALOME_Exception)
955 return SMESH::SMESH_Group::_nil();
959 NCollection_Map< int > anIds;
960 SMESH::ElementType aType = SMESH::ALL;
961 for ( int g = 0, n = theGroups.length(); g < n; g++ )
963 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
964 if ( CORBA::is_nil( aGrp ) )
968 SMESH::ElementType aCurrType = aGrp->GetType();
969 if ( aType == SMESH::ALL )
973 if ( aType != aCurrType )
974 return SMESH::SMESH_Group::_nil();
978 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
979 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
981 int aCurrId = aCurrIds[ i ];
982 anIds.Add( aCurrId );
987 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
988 if ( aResGrp->_is_nil() )
989 return SMESH::SMESH_Group::_nil();
991 // Create array of identifiers
992 SMESH::long_array_var aResIds = new SMESH::long_array;
993 aResIds->length( anIds.Extent() );
995 NCollection_Map< int >::Iterator anIter( anIds );
996 for ( int i = 0; anIter.More(); anIter.Next(), i++ )
998 aResIds[ i ] = anIter.Value();
1000 aResGrp->Add( aResIds );
1002 // Clear python lines, created by CreateGroup() and Add()
1003 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1004 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1005 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1007 // Update Python script
1009 TPythonDump() << aResGrp << " = " << _this() << ".UnionListOfGroups( "
1010 << &theGroups << ", '" << theName << "' )";
1012 return aResGrp._retn();
1016 return SMESH::SMESH_Group::_nil();
1020 //=============================================================================
1022 * New group is created. All mesh elements that are
1023 * present in both initial groups are added to the new one.
1025 //=============================================================================
1026 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1027 SMESH::SMESH_GroupBase_ptr theGroup2,
1028 const char* theName )
1029 throw (SALOME::SALOME_Exception)
1031 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
1032 theGroup1->GetType() != theGroup2->GetType() )
1033 return SMESH::SMESH_Group::_nil();
1035 // Create Intersection
1036 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
1037 if ( aResGrp->_is_nil() )
1040 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
1041 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1043 TColStd_MapOfInteger aMap1;
1045 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1046 aMap1.Add( anIds1[ i1 ] );
1048 TColStd_SequenceOfInteger aSeq;
1050 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1051 if ( aMap1.Contains( anIds2[ i2 ] ) )
1052 aSeq.Append( anIds2[ i2 ] );
1054 SMESH::long_array_var aResIds = new SMESH::long_array;
1055 aResIds->length( aSeq.Length() );
1057 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1058 aResIds[ resI ] = aSeq( resI + 1 );
1060 aResGrp->Add( aResIds );
1062 // Clear python lines, created by CreateGroup() and Add()
1063 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1064 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1065 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1067 // Update Python script
1068 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
1069 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
1071 return aResGrp._retn();
1074 //=============================================================================
1076 \brief Intersect list of groups. New group is created. All mesh elements that
1077 are present in all initial groups simultaneously are added to the new one.
1078 \param theGroups list of groups
1079 \param theName name of group to be created
1080 \return pointer on the group
1082 //=============================================================================
1083 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectListOfGroups(
1084 const SMESH::ListOfGroups& theGroups, const char* theName )
1085 throw (SALOME::SALOME_Exception)
1088 return SMESH::SMESH_Group::_nil();
1092 NCollection_DataMap< int, int > anIdToCount;
1093 SMESH::ElementType aType = SMESH::ALL;
1094 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1096 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1097 if ( CORBA::is_nil( aGrp ) )
1101 SMESH::ElementType aCurrType = aGrp->GetType();
1102 if ( aType == SMESH::ALL )
1106 if ( aType != aCurrType )
1107 return SMESH::SMESH_Group::_nil();
1110 // calculates number of occurance ids in groups
1111 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1112 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1114 int aCurrId = aCurrIds[ i ];
1115 if ( !anIdToCount.IsBound( aCurrId ) )
1116 anIdToCount.Bind( aCurrId, 1 );
1118 anIdToCount( aCurrId ) = anIdToCount( aCurrId ) + 1;
1122 // create map of ids
1123 int nbGrp = theGroups.length();
1124 NCollection_Map< int > anIds;
1125 NCollection_DataMap< int, int >::Iterator anIter( anIdToCount );
1126 for ( ; anIter.More(); anIter.Next() )
1128 int aCurrId = anIter.Key();
1129 int aCurrNb = anIter.Value();
1130 if ( aCurrNb == nbGrp )
1131 anIds.Add( aCurrId );
1135 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
1136 if ( aResGrp->_is_nil() )
1137 return SMESH::SMESH_Group::_nil();
1139 // Create array of identifiers
1140 SMESH::long_array_var aResIds = new SMESH::long_array;
1141 aResIds->length( anIds.Extent() );
1143 NCollection_Map< int >::Iterator aListIter( anIds );
1144 for ( int i = 0; aListIter.More(); aListIter.Next(), i++ )
1146 aResIds[ i ] = aListIter.Value();
1148 aResGrp->Add( aResIds );
1150 // Clear python lines, created by CreateGroup() and Add()
1151 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1152 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1153 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1155 // Update Python script
1157 TPythonDump() << aResGrp << " = " << _this() << ".IntersectListOfGroups( "
1158 << &theGroups << ", '" << theName << "' )";
1160 return aResGrp._retn();
1164 return SMESH::SMESH_Group::_nil();
1168 //=============================================================================
1170 * New group is created. All mesh elements that are present in
1171 * main group but do not present in tool group are added to the new one
1173 //=============================================================================
1174 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1175 SMESH::SMESH_GroupBase_ptr theGroup2,
1176 const char* theName )
1177 throw (SALOME::SALOME_Exception)
1179 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
1180 theGroup1->GetType() != theGroup2->GetType() )
1181 return SMESH::SMESH_Group::_nil();
1184 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
1185 if ( aResGrp->_is_nil() )
1188 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
1189 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1191 TColStd_MapOfInteger aMap2;
1193 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1194 aMap2.Add( anIds2[ i2 ] );
1196 TColStd_SequenceOfInteger aSeq;
1197 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1198 if ( !aMap2.Contains( anIds1[ i1 ] ) )
1199 aSeq.Append( anIds1[ i1 ] );
1201 SMESH::long_array_var aResIds = new SMESH::long_array;
1202 aResIds->length( aSeq.Length() );
1204 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1205 aResIds[ resI ] = aSeq( resI + 1 );
1207 aResGrp->Add( aResIds );
1209 // Clear python lines, created by CreateGroup() and Add()
1210 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1211 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1212 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1214 // Update Python script
1215 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
1216 << theGroup1 << ", " << theGroup2 << ", '"
1217 << theName << "' )";
1219 return aResGrp._retn();
1222 //=============================================================================
1224 \brief Cut lists of groups. New group is created. All mesh elements that are
1225 present in main groups but do not present in tool groups are added to the new one
1226 \param theMainGroups list of main groups
1227 \param theToolGroups list of tool groups
1228 \param theName name of group to be created
1229 \return pointer on the group
1231 //=============================================================================
1232 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutListOfGroups(
1233 const SMESH::ListOfGroups& theMainGroups,
1234 const SMESH::ListOfGroups& theToolGroups,
1235 const char* theName )
1236 throw (SALOME::SALOME_Exception)
1239 return SMESH::SMESH_Group::_nil();
1243 NCollection_Map< int > aToolIds;
1244 SMESH::ElementType aType = SMESH::ALL;
1246 // iterate through tool groups
1247 for ( g = 0, n = theToolGroups.length(); g < n; g++ )
1249 SMESH::SMESH_GroupBase_var aGrp = theToolGroups[ g ];
1250 if ( CORBA::is_nil( aGrp ) )
1254 SMESH::ElementType aCurrType = aGrp->GetType();
1255 if ( aType == SMESH::ALL )
1259 if ( aType != aCurrType )
1260 return SMESH::SMESH_Group::_nil();
1264 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1265 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1267 int aCurrId = aCurrIds[ i ];
1268 aToolIds.Add( aCurrId );
1272 NCollection_Map< int > anIds; // result
1274 // Iterate through main group
1275 for ( g = 0, n = theMainGroups.length(); g < n; g++ )
1277 SMESH::SMESH_GroupBase_var aGrp = theMainGroups[ g ];
1278 if ( CORBA::is_nil( aGrp ) )
1282 SMESH::ElementType aCurrType = aGrp->GetType();
1283 if ( aType == SMESH::ALL )
1287 if ( aType != aCurrType )
1288 return SMESH::SMESH_Group::_nil();
1292 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1293 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1295 int aCurrId = aCurrIds[ i ];
1296 if ( !aToolIds.Contains( aCurrId ) )
1297 anIds.Add( aCurrId );
1302 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
1303 if ( aResGrp->_is_nil() )
1304 return SMESH::SMESH_Group::_nil();
1306 // Create array of identifiers
1307 SMESH::long_array_var aResIds = new SMESH::long_array;
1308 aResIds->length( anIds.Extent() );
1310 NCollection_Map< int >::Iterator anIter( anIds );
1311 for ( int i = 0; anIter.More(); anIter.Next(), i++ )
1313 aResIds[ i ] = anIter.Value();
1315 aResGrp->Add( aResIds );
1317 // Clear python lines, created by CreateGroup() and Add()
1318 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1319 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1320 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1322 // Update Python script
1324 TPythonDump() << aResGrp << " = " << _this() << ".CutListOfGroups( "
1325 << &theMainGroups << ", " << &theToolGroups << ", '"
1326 << theName << "' )";
1328 return aResGrp._retn();
1332 return SMESH::SMESH_Group::_nil();
1336 //=============================================================================
1338 \brief Create groups of entities from existing groups of superior dimensions
1340 1) extract all nodes from each group,
1341 2) combine all elements of specified dimension laying on these nodes.
1342 \param theGroups list of source groups
1343 \param theElemType dimension of elements
1344 \param theName name of new group
1345 \return pointer on new group
1347 //=============================================================================
1348 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateDimGroup(
1349 const SMESH::ListOfGroups& theGroups,
1350 SMESH::ElementType theElemType,
1351 const char* theName )
1352 throw (SALOME::SALOME_Exception)
1354 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
1356 if ( !theName || !aMeshDS )
1357 return SMESH::SMESH_Group::_nil();
1359 SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)theElemType;
1363 // Create map of nodes from all groups
1365 NCollection_Map< int > aNodeMap;
1367 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1369 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1370 if ( CORBA::is_nil( aGrp ) )
1373 SMESH::ElementType aType = aGrp->GetType();
1374 if ( aType == SMESH::ALL )
1376 else if ( aType == SMESH::NODE )
1378 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1379 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1381 int aCurrId = aCurrIds[ i ];
1382 const SMDS_MeshNode* aNode = aMeshDS->FindNode( aCurrId );
1384 aNodeMap.Add( aNode->GetID() );
1389 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1390 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1392 int aCurrId = aCurrIds[ i ];
1393 const SMDS_MeshElement* anElem = aMeshDS->FindElement( aCurrId );
1396 SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator();
1397 while( aNodeIter->more() )
1399 const SMDS_MeshNode* aNode =
1400 dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() );
1402 aNodeMap.Add( aNode->GetID() );
1408 // Get result identifiers
1410 NCollection_Map< int > aResultIds;
1411 if ( theElemType == SMESH::NODE )
1413 NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
1414 for ( ; aNodeIter.More(); aNodeIter.Next() )
1415 aResultIds.Add( aNodeIter.Value() );
1419 // Create list of elements of given dimension constructed on the nodes
1420 NCollection_Map< int > anElemList;
1421 NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
1422 for ( ; aNodeIter.More(); aNodeIter.Next() )
1424 const SMDS_MeshElement* aNode =
1425 dynamic_cast<const SMDS_MeshElement*>( aMeshDS->FindNode( aNodeIter.Value() ) );
1429 SMDS_ElemIteratorPtr anElemIter = aNode->elementsIterator( anElemType );
1430 while( anElemIter->more() )
1432 const SMDS_MeshElement* anElem =
1433 dynamic_cast<const SMDS_MeshElement*>( anElemIter->next() );
1434 if ( anElem && anElem->GetType() == anElemType )
1435 anElemList.Add( anElem->GetID() );
1439 // check whether all nodes of elements are present in nodes map
1440 NCollection_Map< int >::Iterator anIter( anElemList );
1441 for ( ; anIter.More(); anIter.Next() )
1443 const SMDS_MeshElement* anElem = aMeshDS->FindElement( anIter.Value() );
1448 SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator();
1449 while( aNodeIter->more() )
1451 const SMDS_MeshNode* aNode =
1452 dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() );
1453 if ( !aNode || !aNodeMap.Contains( aNode->GetID() ) )
1460 aResultIds.Add( anElem->GetID() );
1466 SMESH::SMESH_Group_var aResGrp = CreateGroup( theElemType, theName );
1467 if ( aResGrp->_is_nil() )
1468 return SMESH::SMESH_Group::_nil();
1470 // Create array of identifiers
1471 SMESH::long_array_var aResIds = new SMESH::long_array;
1472 aResIds->length( aResultIds.Extent() );
1474 NCollection_Map< int >::Iterator aResIter( aResultIds );
1475 for ( int i = 0; aResIter.More(); aResIter.Next(), i++ )
1476 aResIds[ i ] = aResIter.Value();
1477 aResGrp->Add( aResIds );
1479 // Remove strings corresponding to group creation
1480 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1481 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1482 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1484 // Update Python script
1486 TPythonDump() << aResGrp << " = " << _this() << ".CreateDimGroup( "
1487 << &theGroups << ", " << theElemType << ", '" << theName << "' )";
1489 return aResGrp._retn();
1493 return SMESH::SMESH_Group::_nil();
1497 //================================================================================
1499 * \brief Return group items of a group present in a study
1501 //================================================================================
1503 static GEOM::GEOM_Object_ptr getGroupItemsFromStudy(CORBA::Object_ptr theMesh,
1504 SMESH_Gen_i* theGen,
1505 list<TopoDS_Shape> & theItems)
1507 GEOM::GEOM_Object_var groupObj;
1508 SALOMEDS::Study_var study = theGen->GetCurrentStudy();
1509 GEOM::GEOM_Gen_var geomGen = theGen->GetGeomEngine();
1510 if ( study->_is_nil() || geomGen->_is_nil() )
1511 return groupObj._retn();
1513 GEOM::GEOM_IGroupOperations_var groupOp =
1514 geomGen->GetIGroupOperations( theGen->GetCurrentStudyID() );
1515 GEOM::GEOM_IShapesOperations_var shapeOp =
1516 geomGen->GetIShapesOperations( theGen->GetCurrentStudyID() );
1518 SALOMEDS::SObject_var meshOS = theGen->ObjectToSObject(study, theMesh);
1519 if ( meshOS->_is_nil() || groupOp->_is_nil() || shapeOp->_is_nil() )
1520 return groupObj._retn();
1521 SALOMEDS::SObject_var fatherSO = meshOS->GetFather();
1522 if ( fatherSO->_is_nil() || fatherSO->Tag() != theGen->GetSubMeshOnCompoundTag() )
1523 return groupObj._retn(); // keep only submeshes on groups
1525 SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(meshOS);
1526 if ( anIter->_is_nil() ) return groupObj._retn();
1527 for ( ; anIter->More(); anIter->Next())
1529 SALOMEDS::SObject_var aSObject = anIter->Value();
1530 SALOMEDS::SObject_var aRefSO;
1531 if ( !aSObject->_is_nil() && aSObject->ReferencedObject(aRefSO) )
1533 groupObj = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
1534 if ( groupObj->_is_nil() ) break;
1535 GEOM::ListOfLong_var ids = groupOp->GetObjects( groupObj );
1536 GEOM::GEOM_Object_var mainShape = groupObj->GetMainShape();
1537 for ( int i = 0; i < ids->length(); ++i ) {
1538 GEOM::GEOM_Object_var subShape = shapeOp->GetSubShape( mainShape, ids[i] );
1539 TopoDS_Shape S = theGen->GeomObjectToShape( subShape );
1541 theItems.push_back( S );
1546 return groupObj._retn();
1549 //=============================================================================
1551 * \brief Update hypotheses assigned to geom groups if the latter change
1553 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1555 //=============================================================================
1557 void SMESH_Mesh_i::CheckGeomGroupModif()
1559 if ( !_impl->HasShapeToMesh() ) return;
1561 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1562 if ( study->_is_nil() ) return;
1564 // check if items of groups changed
1565 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
1566 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
1568 const TopoDS_Shape & oldGroupShape = i_sm->second->GetSubShape();
1569 SMESHDS_SubMesh * oldDS = i_sm->second->GetSubMeshDS();
1570 if ( !oldDS /*|| !oldDS->IsComplexSubmesh()*/ )
1572 int oldID = i_sm->first;
1573 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldID );
1574 if ( i_smIor == _mapSubMeshIor.end() )
1576 list< TopoDS_Shape> newItems;
1577 GEOM::GEOM_Object_var groupObj = getGroupItemsFromStudy ( i_smIor->second, _gen_i, newItems );
1578 if ( groupObj->_is_nil() )
1581 int nbOldItems = oldDS->IsComplexSubmesh() ? oldDS->NbSubMeshes() : 1;
1582 int nbNewItems = newItems.size();
1583 bool groupChanged = ( nbOldItems != nbNewItems);
1584 if ( !groupChanged ) {
1585 if ( !oldDS->IsComplexSubmesh() ) { // old group has one item
1586 groupChanged = ( oldGroupShape != newItems.front() );
1589 list<TopoDS_Shape>::iterator item = newItems.begin();
1590 for ( ; item != newItems.end() && !groupChanged; ++item )
1592 SMESHDS_SubMesh * itemDS = _impl->GetMeshDS()->MeshElements( *item );
1593 groupChanged = ( !itemDS || !oldDS->ContainsSubMesh( itemDS ));
1597 // update hypotheses and submeshes if necessary
1600 // get a new group shape
1601 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1602 if ( !geomClient ) continue;
1603 TCollection_AsciiString groupIOR = _gen_i->GetGeomEngine()->GetStringFromIOR( groupObj );
1604 geomClient->RemoveShapeFromBuffer( groupIOR );
1605 TopoDS_Shape newGroupShape = _gen_i->GeomObjectToShape( groupObj );
1606 // update hypotheses
1607 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldGroupShape);
1608 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1609 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1611 _impl->RemoveHypothesis( oldGroupShape, (*hypIt)->GetID());
1612 _impl->AddHypothesis ( newGroupShape, (*hypIt)->GetID());
1614 // care of submeshes
1615 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newGroupShape );
1616 int newID = newSubmesh->GetId();
1617 if ( newID != oldID ) {
1618 _mapSubMesh [ newID ] = newSubmesh;
1619 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1620 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1621 _mapSubMesh.erase (oldID);
1622 _mapSubMesh_i.erase (oldID);
1623 _mapSubMeshIor.erase(oldID);
1624 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1630 //=============================================================================
1632 * \brief Create standalone group instead if group on geometry
1635 //=============================================================================
1637 SMESH::SMESH_Group_ptr SMESH_Mesh_i::ConvertToStandalone( SMESH::SMESH_GroupOnGeom_ptr theGroup )
1639 SMESH::SMESH_Group_var aGroup;
1640 if ( theGroup->_is_nil() )
1641 return aGroup._retn();
1643 Unexpect aCatch(SALOME_SalomeException);
1645 SMESH_GroupBase_i* aGroupToRem =
1646 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
1648 return aGroup._retn();
1650 int anId = aGroupToRem->GetLocalID();
1651 if ( !_impl->ConvertToStandalone( anId ) )
1652 return aGroup._retn();
1654 SMESH_GroupBase_i* aGroupImpl;
1655 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1658 // remove old instance of group from own map
1659 _mapGroups.erase( anId );
1661 SALOMEDS::StudyBuilder_var builder;
1662 SALOMEDS::SObject_var aGroupSO;
1663 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1664 if ( !aStudy->_is_nil() ) {
1665 builder = aStudy->NewBuilder();
1666 aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
1667 if ( !aGroupSO->_is_nil() ) {
1669 // remove reference to geometry
1670 SALOMEDS::ChildIterator_var chItr = aStudy->NewChildIterator(aGroupSO);
1671 for ( ; chItr->More(); chItr->Next() )
1672 // Remove group's child SObject
1673 builder->RemoveObject( chItr->Value() );
1675 // Update Python script
1676 TPythonDump() << aGroupSO << " = " << _this() << ".ConvertToStandalone( "
1677 << aGroupSO << " )";
1681 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1682 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1683 aGroupImpl->Register();
1684 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1686 // remember new group in own map
1687 aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
1688 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1690 // register CORBA object for persistence
1691 //int nextId = _gen_i->RegisterObject( aGroup );
1692 //if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1693 builder->SetIOR( aGroupSO, _gen_i->GetORB()->object_to_string( aGroup ) );
1695 return aGroup._retn();
1698 //=============================================================================
1702 //=============================================================================
1704 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1706 if(MYDEBUG) MESSAGE( "createSubMesh" );
1707 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1709 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1710 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1711 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1712 SMESH::SMESH_subMesh_var subMesh
1713 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1715 _mapSubMesh[subMeshId] = mySubMesh;
1716 _mapSubMesh_i[subMeshId] = subMeshServant;
1717 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1719 // register CORBA object for persistence
1720 int nextId = _gen_i->RegisterObject( subMesh );
1721 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1723 return subMesh._retn();
1726 //=======================================================================
1727 //function : getSubMesh
1729 //=======================================================================
1731 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1733 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1734 if ( it == _mapSubMeshIor.end() )
1735 return SMESH::SMESH_subMesh::_nil();
1737 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1741 //=============================================================================
1745 //=============================================================================
1747 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1748 GEOM::GEOM_Object_ptr theSubShapeObject )
1750 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1751 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1755 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1756 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1757 removeHypothesis( theSubShapeObject, aHypList[i] );
1760 catch( const SALOME::SALOME_Exception& ) {
1761 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1764 int subMeshId = theSubMesh->GetId();
1766 _mapSubMesh.erase(subMeshId);
1767 _mapSubMesh_i.erase(subMeshId);
1768 _mapSubMeshIor.erase(subMeshId);
1769 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1772 //=============================================================================
1776 //=============================================================================
1778 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1779 const char* theName,
1780 const TopoDS_Shape& theShape )
1783 SMESH::SMESH_GroupBase_var aGroup;
1784 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1785 SMESH_GroupBase_i* aGroupImpl;
1786 if ( !theShape.IsNull() )
1787 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1789 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1791 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1792 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1793 aGroupImpl->Register();
1794 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1796 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1797 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1799 // register CORBA object for persistence
1800 int nextId = _gen_i->RegisterObject( aGroup );
1801 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1803 return aGroup._retn();
1806 //=============================================================================
1808 * SMESH_Mesh_i::removeGroup
1810 * Should be called by ~SMESH_Group_i()
1812 //=============================================================================
1814 void SMESH_Mesh_i::removeGroup( const int theId )
1816 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1817 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1818 _mapGroups.erase( theId );
1819 _impl->RemoveGroup( theId );
1824 //=============================================================================
1828 //=============================================================================
1830 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1831 throw(SALOME::SALOME_Exception)
1833 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1835 SMESH::log_array_var aLog;
1837 list < SMESHDS_Command * >logDS = _impl->GetLog();
1838 aLog = new SMESH::log_array;
1840 int lg = logDS.size();
1843 list < SMESHDS_Command * >::iterator its = logDS.begin();
1844 while(its != logDS.end()){
1845 SMESHDS_Command *com = *its;
1846 int comType = com->GetType();
1848 int lgcom = com->GetNumber();
1850 const list < int >&intList = com->GetIndexes();
1851 int inum = intList.size();
1853 list < int >::const_iterator ii = intList.begin();
1854 const list < double >&coordList = com->GetCoords();
1855 int rnum = coordList.size();
1857 list < double >::const_iterator ir = coordList.begin();
1858 aLog[indexLog].commandType = comType;
1859 aLog[indexLog].number = lgcom;
1860 aLog[indexLog].coords.length(rnum);
1861 aLog[indexLog].indexes.length(inum);
1862 for(int i = 0; i < rnum; i++){
1863 aLog[indexLog].coords[i] = *ir;
1864 //MESSAGE(" "<<i<<" "<<ir.Value());
1867 for(int i = 0; i < inum; i++){
1868 aLog[indexLog].indexes[i] = *ii;
1869 //MESSAGE(" "<<i<<" "<<ii.Value());
1878 catch(SALOME_Exception & S_ex){
1879 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1881 return aLog._retn();
1885 //=============================================================================
1889 //=============================================================================
1891 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1893 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1897 //=============================================================================
1901 //=============================================================================
1903 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1905 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1909 //=============================================================================
1913 //=============================================================================
1915 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1920 //=============================================================================
1924 //=============================================================================
1926 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1928 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1932 //=============================================================================
1936 //=============================================================================
1938 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1940 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1944 //=============================================================================
1946 * Return mesh editor
1948 //=============================================================================
1950 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1952 // Create MeshEditor
1953 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
1954 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1956 // Update Python script
1957 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1959 return aMesh._retn();
1962 //=============================================================================
1964 * Return mesh edition previewer
1966 //=============================================================================
1968 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1970 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
1971 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1972 return aMesh._retn();
1975 //=============================================================================
1979 //=============================================================================
1980 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
1982 Unexpect aCatch(SALOME_SalomeException);
1983 _impl->SetAutoColor(theAutoColor);
1986 //=============================================================================
1990 //=============================================================================
1991 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
1993 Unexpect aCatch(SALOME_SalomeException);
1994 return _impl->GetAutoColor();
1998 //=============================================================================
2000 * Export in different formats
2002 //=============================================================================
2004 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
2006 return _impl->HasDuplicatedGroupNamesMED();
2009 void SMESH_Mesh_i::PrepareForWriting (const char* file)
2011 TCollection_AsciiString aFullName ((char*)file);
2012 OSD_Path aPath (aFullName);
2013 OSD_File aFile (aPath);
2014 if (aFile.Exists()) {
2015 // existing filesystem node
2016 if (aFile.KindOfFile() == OSD_FILE) {
2017 if (aFile.IsWriteable()) {
2020 if (aFile.Failed()) {
2021 TCollection_AsciiString msg ("File ");
2022 msg += aFullName + " cannot be replaced.";
2023 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2026 TCollection_AsciiString msg ("File ");
2027 msg += aFullName + " cannot be overwritten.";
2028 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2031 TCollection_AsciiString msg ("Location ");
2032 msg += aFullName + " is not a file.";
2033 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2036 // nonexisting file; check if it can be created
2038 aFile.Build(OSD_WriteOnly, OSD_Protection());
2039 if (aFile.Failed()) {
2040 TCollection_AsciiString msg ("You cannot create the file ");
2041 msg += aFullName + ". Check the directory existance and access rights.";
2042 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2050 void SMESH_Mesh_i::ExportToMED (const char* file,
2051 CORBA::Boolean auto_groups,
2052 SMESH::MED_VERSION theVersion)
2053 throw(SALOME::SALOME_Exception)
2055 Unexpect aCatch(SALOME_SalomeException);
2058 PrepareForWriting(file);
2059 const char* aMeshName = "Mesh";
2060 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2061 if ( !aStudy->_is_nil() ) {
2062 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
2063 if ( !aMeshSO->_is_nil() ) {
2064 aMeshName = aMeshSO->GetName();
2065 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
2066 if ( !aStudy->GetProperties()->IsLocked() )
2068 SALOMEDS::GenericAttribute_var anAttr;
2069 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2070 SALOMEDS::AttributeExternalFileDef_var aFileName;
2071 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
2072 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
2073 ASSERT(!aFileName->_is_nil());
2074 aFileName->SetValue(file);
2075 SALOMEDS::AttributeFileType_var aFileType;
2076 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
2077 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
2078 ASSERT(!aFileType->_is_nil());
2079 aFileType->SetValue("FICHIERMED");
2083 // Update Python script
2084 // set name of mesh before export
2085 TPythonDump() << _gen_i << ".SetName(" << _this() << ", '" << aMeshName << "')";
2087 // check names of groups
2090 TPythonDump() << _this() << ".ExportToMED( '"
2091 << file << "', " << auto_groups << ", " << theVersion << " )";
2093 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
2096 void SMESH_Mesh_i::ExportMED (const char* file,
2097 CORBA::Boolean auto_groups)
2098 throw(SALOME::SALOME_Exception)
2100 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
2103 void SMESH_Mesh_i::ExportDAT (const char *file)
2104 throw(SALOME::SALOME_Exception)
2106 Unexpect aCatch(SALOME_SalomeException);
2108 // Update Python script
2109 // check names of groups
2111 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
2114 PrepareForWriting(file);
2115 _impl->ExportDAT(file);
2118 void SMESH_Mesh_i::ExportUNV (const char *file)
2119 throw(SALOME::SALOME_Exception)
2121 Unexpect aCatch(SALOME_SalomeException);
2123 // Update Python script
2124 // check names of groups
2126 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
2129 PrepareForWriting(file);
2130 _impl->ExportUNV(file);
2133 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
2134 throw(SALOME::SALOME_Exception)
2136 Unexpect aCatch(SALOME_SalomeException);
2138 // Update Python script
2139 // check names of groups
2141 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
2144 PrepareForWriting(file);
2145 _impl->ExportSTL(file, isascii);
2148 //=============================================================================
2152 //=============================================================================
2154 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
2156 Unexpect aCatch(SALOME_SalomeException);
2157 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
2158 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
2159 return aMesh._retn();
2162 //=============================================================================
2166 //=============================================================================
2167 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
2169 Unexpect aCatch(SALOME_SalomeException);
2170 return _impl->NbNodes();
2173 //=============================================================================
2177 //=============================================================================
2178 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
2180 Unexpect aCatch(SALOME_SalomeException);
2181 return NbEdges() + NbFaces() + NbVolumes();
2184 //=============================================================================
2188 //=============================================================================
2189 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
2191 Unexpect aCatch(SALOME_SalomeException);
2192 return _impl->NbEdges();
2195 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
2196 throw(SALOME::SALOME_Exception)
2198 Unexpect aCatch(SALOME_SalomeException);
2199 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
2202 //=============================================================================
2206 //=============================================================================
2207 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
2209 Unexpect aCatch(SALOME_SalomeException);
2210 return _impl->NbFaces();
2213 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
2215 Unexpect aCatch(SALOME_SalomeException);
2216 return _impl->NbTriangles();
2219 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
2221 Unexpect aCatch(SALOME_SalomeException);
2222 return _impl->NbQuadrangles();
2225 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
2227 Unexpect aCatch(SALOME_SalomeException);
2228 return _impl->NbPolygons();
2231 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
2232 throw(SALOME::SALOME_Exception)
2234 Unexpect aCatch(SALOME_SalomeException);
2235 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
2238 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
2239 throw(SALOME::SALOME_Exception)
2241 Unexpect aCatch(SALOME_SalomeException);
2242 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
2245 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
2246 throw(SALOME::SALOME_Exception)
2248 Unexpect aCatch(SALOME_SalomeException);
2249 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
2252 //=============================================================================
2256 //=============================================================================
2257 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
2259 Unexpect aCatch(SALOME_SalomeException);
2260 return _impl->NbVolumes();
2263 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
2265 Unexpect aCatch(SALOME_SalomeException);
2266 return _impl->NbTetras();
2269 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
2271 Unexpect aCatch(SALOME_SalomeException);
2272 return _impl->NbHexas();
2275 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
2277 Unexpect aCatch(SALOME_SalomeException);
2278 return _impl->NbPyramids();
2281 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
2283 Unexpect aCatch(SALOME_SalomeException);
2284 return _impl->NbPrisms();
2287 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
2289 Unexpect aCatch(SALOME_SalomeException);
2290 return _impl->NbPolyhedrons();
2293 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
2294 throw(SALOME::SALOME_Exception)
2296 Unexpect aCatch(SALOME_SalomeException);
2297 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
2300 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
2301 throw(SALOME::SALOME_Exception)
2303 Unexpect aCatch(SALOME_SalomeException);
2304 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
2307 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
2308 throw(SALOME::SALOME_Exception)
2310 Unexpect aCatch(SALOME_SalomeException);
2311 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
2314 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
2315 throw(SALOME::SALOME_Exception)
2317 Unexpect aCatch(SALOME_SalomeException);
2318 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
2321 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
2322 throw(SALOME::SALOME_Exception)
2324 Unexpect aCatch(SALOME_SalomeException);
2325 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
2328 //=============================================================================
2332 //=============================================================================
2333 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
2335 Unexpect aCatch(SALOME_SalomeException);
2336 return _mapSubMesh_i.size();
2339 //=============================================================================
2343 //=============================================================================
2344 char* SMESH_Mesh_i::Dump()
2346 std::ostringstream os;
2348 return CORBA::string_dup( os.str().c_str() );
2351 //=============================================================================
2355 //=============================================================================
2356 SMESH::long_array* SMESH_Mesh_i::GetIDs()
2358 // SMESH::long_array_var aResult = new SMESH::long_array();
2359 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2360 // int aMinId = aSMESHDS_Mesh->MinElementID();
2361 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
2363 // aResult->length(aMaxId - aMinId + 1);
2365 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
2366 // aResult[i++] = id;
2368 // return aResult._retn();
2370 return GetElementsId();
2373 //=============================================================================
2377 //=============================================================================
2379 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
2380 throw (SALOME::SALOME_Exception)
2382 Unexpect aCatch(SALOME_SalomeException);
2383 MESSAGE("SMESH_Mesh_i::GetElementsId");
2384 SMESH::long_array_var aResult = new SMESH::long_array();
2385 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2387 if ( aSMESHDS_Mesh == NULL )
2388 return aResult._retn();
2390 long nbElements = NbElements();
2391 aResult->length( nbElements );
2392 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
2393 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
2394 aResult[i] = anIt->next()->GetID();
2396 return aResult._retn();
2400 //=============================================================================
2404 //=============================================================================
2406 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
2407 throw (SALOME::SALOME_Exception)
2409 Unexpect aCatch(SALOME_SalomeException);
2410 MESSAGE("SMESH_subMesh_i::GetElementsByType");
2411 SMESH::long_array_var aResult = new SMESH::long_array();
2412 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2414 if ( aSMESHDS_Mesh == NULL )
2415 return aResult._retn();
2417 long nbElements = NbElements();
2419 // No sense in returning ids of elements along with ids of nodes:
2420 // when theElemType == SMESH::ALL, return node ids only if
2421 // there are no elements
2422 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
2423 return GetNodesId();
2425 aResult->length( nbElements );
2429 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
2430 while ( i < nbElements && anIt->more() ) {
2431 const SMDS_MeshElement* anElem = anIt->next();
2432 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
2433 aResult[i++] = anElem->GetID();
2436 aResult->length( i );
2438 return aResult._retn();
2441 //=============================================================================
2445 //=============================================================================
2447 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
2448 throw (SALOME::SALOME_Exception)
2450 Unexpect aCatch(SALOME_SalomeException);
2451 MESSAGE("SMESH_subMesh_i::GetNodesId");
2452 SMESH::long_array_var aResult = new SMESH::long_array();
2453 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2455 if ( aSMESHDS_Mesh == NULL )
2456 return aResult._retn();
2458 long nbNodes = NbNodes();
2459 aResult->length( nbNodes );
2460 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
2461 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
2462 aResult[i] = anIt->next()->GetID();
2464 return aResult._retn();
2467 //=============================================================================
2471 //=============================================================================
2473 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
2474 throw (SALOME::SALOME_Exception)
2476 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
2480 //=============================================================================
2482 * Returns ID of elements for given submesh
2484 //=============================================================================
2485 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
2486 throw (SALOME::SALOME_Exception)
2488 SMESH::long_array_var aResult = new SMESH::long_array();
2490 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2491 if(!SM) return aResult._retn();
2493 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2494 if(!SDSM) return aResult._retn();
2496 aResult->length(SDSM->NbElements());
2498 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2500 while ( eIt->more() ) {
2501 aResult[i++] = eIt->next()->GetID();
2504 return aResult._retn();
2508 //=============================================================================
2510 * Returns ID of nodes for given submesh
2511 * If param all==true - returns all nodes, else -
2512 * returns only nodes on shapes.
2514 //=============================================================================
2515 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
2516 throw (SALOME::SALOME_Exception)
2518 SMESH::long_array_var aResult = new SMESH::long_array();
2520 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2521 if(!SM) return aResult._retn();
2523 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2524 if(!SDSM) return aResult._retn();
2527 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
2528 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
2529 while ( nIt->more() ) {
2530 const SMDS_MeshNode* elem = nIt->next();
2531 theElems.insert( elem->GetID() );
2534 else { // all nodes of submesh elements
2535 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2536 while ( eIt->more() ) {
2537 const SMDS_MeshElement* anElem = eIt->next();
2538 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
2539 while ( nIt->more() ) {
2540 const SMDS_MeshElement* elem = nIt->next();
2541 theElems.insert( elem->GetID() );
2546 aResult->length(theElems.size());
2547 set<int>::iterator itElem;
2549 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
2550 aResult[i++] = *itElem;
2552 return aResult._retn();
2556 //=============================================================================
2558 * Returns type of elements for given submesh
2560 //=============================================================================
2561 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
2562 throw (SALOME::SALOME_Exception)
2564 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2565 if(!SM) return SMESH::ALL;
2567 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2568 if(!SDSM) return SMESH::ALL;
2570 if(SDSM->NbElements()==0)
2571 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
2573 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2574 const SMDS_MeshElement* anElem = eIt->next();
2575 return ( SMESH::ElementType ) anElem->GetType();
2579 //=============================================================================
2583 //=============================================================================
2585 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
2587 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
2589 MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
2594 //=============================================================================
2596 * Get XYZ coordinates of node as list of double
2597 * If there is not node for given ID - returns empty list
2599 //=============================================================================
2601 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2603 SMESH::double_array_var aResult = new SMESH::double_array();
2604 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2605 if ( aSMESHDS_Mesh == NULL )
2606 return aResult._retn();
2609 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2611 return aResult._retn();
2615 aResult[0] = aNode->X();
2616 aResult[1] = aNode->Y();
2617 aResult[2] = aNode->Z();
2618 return aResult._retn();
2622 //=============================================================================
2624 * For given node returns list of IDs of inverse elements
2625 * If there is not node for given ID - returns empty list
2627 //=============================================================================
2629 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2631 SMESH::long_array_var aResult = new SMESH::long_array();
2632 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2633 if ( aSMESHDS_Mesh == NULL )
2634 return aResult._retn();
2637 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2639 return aResult._retn();
2641 // find inverse elements
2642 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2643 TColStd_SequenceOfInteger IDs;
2644 while(eIt->more()) {
2645 const SMDS_MeshElement* elem = eIt->next();
2646 IDs.Append(elem->GetID());
2648 if(IDs.Length()>0) {
2649 aResult->length(IDs.Length());
2651 for(; i<=IDs.Length(); i++) {
2652 aResult[i-1] = IDs.Value(i);
2655 return aResult._retn();
2658 //=============================================================================
2660 * \brief Return position of a node on shape
2662 //=============================================================================
2664 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
2666 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
2667 aNodePosition->shapeID = 0;
2668 aNodePosition->shapeType = GEOM::SHAPE;
2670 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
2671 if ( !mesh ) return aNodePosition;
2673 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
2675 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
2677 aNodePosition->shapeID = pos->GetShapeId();
2678 switch ( pos->GetTypeOfPosition() ) {
2680 aNodePosition->shapeType = GEOM::EDGE;
2681 aNodePosition->params.length(1);
2682 aNodePosition->params[0] =
2683 static_cast<SMDS_EdgePosition*>( pos.get() )->GetUParameter();
2686 aNodePosition->shapeType = GEOM::FACE;
2687 aNodePosition->params.length(2);
2688 aNodePosition->params[0] =
2689 static_cast<SMDS_FacePosition*>( pos.get() )->GetUParameter();
2690 aNodePosition->params[1] =
2691 static_cast<SMDS_FacePosition*>( pos.get() )->GetVParameter();
2693 case SMDS_TOP_VERTEX:
2694 aNodePosition->shapeType = GEOM::VERTEX;
2696 case SMDS_TOP_3DSPACE:
2697 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
2698 aNodePosition->shapeType = GEOM::SOLID;
2699 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
2700 aNodePosition->shapeType = GEOM::SHELL;
2706 return aNodePosition;
2709 //=============================================================================
2711 * If given element is node returns IDs of shape from position
2712 * If there is not node for given ID - returns -1
2714 //=============================================================================
2716 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2718 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2719 if ( aSMESHDS_Mesh == NULL )
2723 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2725 SMDS_PositionPtr pos = aNode->GetPosition();
2729 return pos->GetShapeId();
2736 //=============================================================================
2738 * For given element returns ID of result shape after
2739 * ::FindShape() from SMESH_MeshEditor
2740 * If there is not element for given ID - returns -1
2742 //=============================================================================
2744 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2746 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2747 if ( aSMESHDS_Mesh == NULL )
2750 // try to find element
2751 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2755 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2756 ::SMESH_MeshEditor aMeshEditor(_impl);
2757 int index = aMeshEditor.FindShape( elem );
2765 //=============================================================================
2767 * Returns number of nodes for given element
2768 * If there is not element for given ID - returns -1
2770 //=============================================================================
2772 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2774 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2775 if ( aSMESHDS_Mesh == NULL ) return -1;
2776 // try to find element
2777 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2778 if(!elem) return -1;
2779 return elem->NbNodes();
2783 //=============================================================================
2785 * Returns ID of node by given index for given element
2786 * If there is not element for given ID - returns -1
2787 * If there is not node for given index - returns -2
2789 //=============================================================================
2791 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2793 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2794 if ( aSMESHDS_Mesh == NULL ) return -1;
2795 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2796 if(!elem) return -1;
2797 if( index>=elem->NbNodes() || index<0 ) return -1;
2798 return elem->GetNode(index)->GetID();
2801 //=============================================================================
2803 * Returns IDs of nodes of given element
2805 //=============================================================================
2807 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2809 SMESH::long_array_var aResult = new SMESH::long_array();
2810 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2812 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2814 aResult->length( elem->NbNodes() );
2815 for ( int i = 0; i < elem->NbNodes(); ++i )
2816 aResult[ i ] = elem->GetNode( i )->GetID();
2819 return aResult._retn();
2822 //=============================================================================
2824 * Returns true if given node is medium node
2825 * in given quadratic element
2827 //=============================================================================
2829 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2831 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2832 if ( aSMESHDS_Mesh == NULL ) return false;
2834 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2835 if(!aNode) return false;
2836 // try to find element
2837 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2838 if(!elem) return false;
2840 return elem->IsMediumNode(aNode);
2844 //=============================================================================
2846 * Returns true if given node is medium node
2847 * in one of quadratic elements
2849 //=============================================================================
2851 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2852 SMESH::ElementType theElemType)
2854 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2855 if ( aSMESHDS_Mesh == NULL ) return false;
2858 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2859 if(!aNode) return false;
2861 SMESH_MesherHelper aHelper( *(_impl) );
2863 SMDSAbs_ElementType aType;
2864 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2865 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2866 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2867 else aType = SMDSAbs_All;
2869 return aHelper.IsMedium(aNode,aType);
2873 //=============================================================================
2875 * Returns number of edges for given element
2877 //=============================================================================
2879 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2881 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2882 if ( aSMESHDS_Mesh == NULL ) return -1;
2883 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2884 if(!elem) return -1;
2885 return elem->NbEdges();
2889 //=============================================================================
2891 * Returns number of faces for given element
2893 //=============================================================================
2895 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2897 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2898 if ( aSMESHDS_Mesh == NULL ) return -1;
2899 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2900 if(!elem) return -1;
2901 return elem->NbFaces();
2905 //=============================================================================
2907 * Returns true if given element is polygon
2909 //=============================================================================
2911 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2913 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2914 if ( aSMESHDS_Mesh == NULL ) return false;
2915 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2916 if(!elem) return false;
2917 return elem->IsPoly();
2921 //=============================================================================
2923 * Returns true if given element is quadratic
2925 //=============================================================================
2927 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2929 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2930 if ( aSMESHDS_Mesh == NULL ) return false;
2931 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2932 if(!elem) return false;
2933 return elem->IsQuadratic();
2937 //=============================================================================
2939 * Returns bary center for given element
2941 //=============================================================================
2943 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2945 SMESH::double_array_var aResult = new SMESH::double_array();
2946 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2947 if ( aSMESHDS_Mesh == NULL )
2948 return aResult._retn();
2950 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2952 return aResult._retn();
2954 if(elem->GetType()==SMDSAbs_Volume) {
2955 SMDS_VolumeTool aTool;
2956 if(aTool.Set(elem)) {
2958 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
2963 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2965 double x=0., y=0., z=0.;
2966 for(; anIt->more(); ) {
2968 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2982 return aResult._retn();
2986 //=============================================================================
2988 * Create and publish group servants if any groups were imported or created anyhow
2990 //=============================================================================
2992 void SMESH_Mesh_i::CreateGroupServants()
2994 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2996 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
2997 while ( groupIt->more() )
2999 ::SMESH_Group* group = groupIt->next();
3000 int anId = group->GetGroupDS()->GetID();
3002 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
3003 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
3006 SMESH_GroupBase_i* aGroupImpl;
3008 if ( SMESHDS_GroupOnGeom* groupOnGeom =
3009 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
3011 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
3012 shape = groupOnGeom->GetShape();
3015 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
3018 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
3019 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
3020 aGroupImpl->Register();
3022 SMESH::SMESH_GroupBase_var groupVar =
3023 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
3024 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
3026 // register CORBA object for persistence
3027 int nextId = _gen_i->RegisterObject( groupVar );
3028 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
3030 // publishing of the groups in the study
3031 if ( !aStudy->_is_nil() ) {
3032 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
3033 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
3038 //=============================================================================
3040 * \brief Return groups cantained in _mapGroups by their IDs
3042 //=============================================================================
3044 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
3046 int nbGroups = groupIDs.size();
3047 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
3048 aList->length( nbGroups );
3050 list<int>::const_iterator ids = groupIDs.begin();
3051 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
3053 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
3054 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
3055 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
3057 aList->length( nbGroups );
3058 return aList._retn();
3061 //=============================================================================
3063 * \brief Return information about imported file
3065 //=============================================================================
3067 SALOME_MED::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
3069 SALOME_MED::MedFileInfo_var res( myFileInfo );
3070 if ( !res.operator->() ) {
3071 res = new SALOME_MED::MedFileInfo;
3073 res->fileSize = res->major = res->minor = res->release = -1;
3078 //=============================================================================
3080 * \brief Check and correct names of mesh groups
3082 //=============================================================================
3084 void SMESH_Mesh_i::checkGroupNames()
3086 int nbGrp = NbGroups();
3090 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
3091 if ( aStudy->_is_nil() )
3092 return; // nothing to do
3094 SMESH::ListOfGroups* grpList = 0;
3095 // avoid dump of "GetGroups"
3097 // store python dump into a local variable inside local scope
3098 SMESH::TPythonDump pDump; // do not delete this line of code
3099 grpList = GetGroups();
3102 for ( int gIndx = 0; gIndx < nbGrp; gIndx++ ) {
3103 SMESH::SMESH_GroupBase_ptr aGrp = (*grpList)[ gIndx ];
3106 SALOMEDS::SObject_var aGrpSO = _gen_i->ObjectToSObject( aStudy, aGrp );
3107 if ( aGrpSO->_is_nil() )
3109 // correct name of the mesh group if necessary
3110 const char* guiName = aGrpSO->GetName();
3111 if ( strcmp(guiName, aGrp->GetName()) )
3112 aGrp->SetName( guiName );
3116 //=============================================================================
3118 * \brief Sets list of notebook variables used for Mesh operations separated by ":" symbol
3120 //=============================================================================
3121 void SMESH_Mesh_i::SetParameters(const char* theParameters)
3123 SMESH_Gen_i::GetSMESHGen()->UpdateParameters(SMESH::SMESH_Mesh::_narrow(_this()),
3124 CORBA::string_dup(theParameters));
3127 //=============================================================================
3129 * \brief Returns list of notebook variables used for Mesh operations separated by ":" symbol
3131 //=============================================================================
3132 char* SMESH_Mesh_i::GetParameters()
3134 SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
3135 return CORBA::string_dup(gen->GetParameters(SMESH::SMESH_Mesh::_narrow(_this())));
3138 //=============================================================================
3140 * \brief Returns list of notebook variables used for last Mesh operation
3142 //=============================================================================
3143 SMESH::string_array* SMESH_Mesh_i::GetLastParameters()
3145 SMESH::string_array_var aResult = new SMESH::string_array();
3146 SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
3148 char *aParameters = GetParameters();
3149 SALOMEDS::Study_ptr aStudy = gen->GetCurrentStudy();
3150 if(!aStudy->_is_nil()) {
3151 SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters);
3152 if(aSections->length() > 0) {
3153 SALOMEDS::ListOfStrings aVars = aSections[aSections->length()-1];
3154 aResult->length(aVars.length());
3155 for(int i = 0;i < aVars.length();i++)
3156 aResult[i] = CORBA::string_dup( aVars[i]);
3160 return aResult._retn();