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"
55 #include "GEOMImpl_Types.hxx"
58 #include <BRep_Builder.hxx>
59 #include <OSD_Directory.hxx>
60 #include <OSD_File.hxx>
61 #include <OSD_Path.hxx>
62 #include <OSD_Protection.hxx>
63 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
64 #include <TColStd_MapOfInteger.hxx>
65 #include <TColStd_SequenceOfInteger.hxx>
66 #include <TCollection_AsciiString.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <TopoDS_Compound.hxx>
77 static int MYDEBUG = 0;
79 static int MYDEBUG = 0;
83 using SMESH::TPythonDump;
85 int SMESH_Mesh_i::myIdGenerator = 0;
89 //=============================================================================
93 //=============================================================================
95 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
98 : SALOME::GenericObj_i( thePOA )
100 MESSAGE("SMESH_Mesh_i");
103 _id = myIdGenerator++;
107 //=============================================================================
111 //=============================================================================
113 SMESH_Mesh_i::~SMESH_Mesh_i()
115 INFOS("~SMESH_Mesh_i");
116 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
117 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
118 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
120 // this method is colled from destructor of group (PAL6331)
121 //_impl->RemoveGroup( aGroup->GetLocalID() );
130 //=============================================================================
134 * Associates <this> mesh with <theShape> and puts a reference
135 * to <theShape> into the current study;
136 * the previous shape is substituted by the new one.
138 //=============================================================================
140 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
141 throw (SALOME::SALOME_Exception)
143 Unexpect aCatch(SALOME_SalomeException);
145 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
147 catch(SALOME_Exception & S_ex) {
148 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
150 // to track changes of GEOM groups
151 addGeomGroupData( theShapeObject, _this() );
154 //================================================================================
156 * \brief return true if mesh has a shape to build a shape on
158 //================================================================================
160 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
161 throw (SALOME::SALOME_Exception)
163 Unexpect aCatch(SALOME_SalomeException);
166 res = _impl->HasShapeToMesh();
168 catch(SALOME_Exception & S_ex) {
169 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
174 //=======================================================================
175 //function : GetShapeToMesh
177 //=======================================================================
179 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
180 throw (SALOME::SALOME_Exception)
182 Unexpect aCatch(SALOME_SalomeException);
183 GEOM::GEOM_Object_var aShapeObj;
185 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
187 aShapeObj = _gen_i->ShapeToGeomObject( S );
189 catch(SALOME_Exception & S_ex) {
190 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
192 return aShapeObj._retn();
195 //================================================================================
197 * \brief Remove all nodes and elements
199 //================================================================================
201 void SMESH_Mesh_i::Clear() throw (SALOME::SALOME_Exception)
203 Unexpect aCatch(SALOME_SalomeException);
207 catch(SALOME_Exception & S_ex) {
208 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
210 TPythonDump() << _this() << ".Clear()";
213 //================================================================================
215 * \brief Remove all nodes and elements for indicated shape
217 //================================================================================
219 void SMESH_Mesh_i::ClearSubMesh(CORBA::Long ShapeID)
220 throw (SALOME::SALOME_Exception)
222 Unexpect aCatch(SALOME_SalomeException);
224 _impl->ClearSubMesh( ShapeID );
226 catch(SALOME_Exception & S_ex) {
227 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
231 //=============================================================================
235 //=============================================================================
237 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
239 SMESH::DriverMED_ReadStatus res;
242 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
243 res = SMESH::DRS_OK; break;
244 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
245 res = SMESH::DRS_EMPTY; break;
246 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
247 res = SMESH::DRS_WARN_RENUMBER; break;
248 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
249 res = SMESH::DRS_WARN_SKIP_ELEM; break;
250 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
252 res = SMESH::DRS_FAIL; break;
257 //=============================================================================
261 * Imports mesh data from MED file
263 //=============================================================================
265 SMESH::DriverMED_ReadStatus
266 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
267 throw ( SALOME::SALOME_Exception )
269 Unexpect aCatch(SALOME_SalomeException);
272 status = _impl->MEDToMesh( theFileName, theMeshName );
274 catch( SALOME_Exception& S_ex ) {
275 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
278 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
281 CreateGroupServants();
283 int major, minor, release;
284 if( !MED::getMEDVersion( theFileName, major, minor, release ) )
285 major = minor = release = -1;
286 myFileInfo = new SALOME_MED::MedFileInfo();
287 myFileInfo->fileName = theFileName;
288 myFileInfo->fileSize = 0;
291 if ( ::_stati64( theFileName, &d ) != -1 )
294 if ( ::stat64( theFileName, &d ) != -1 )
296 myFileInfo->fileSize = d.st_size;
297 myFileInfo->major = major;
298 myFileInfo->minor = minor;
299 myFileInfo->release = release;
301 return ConvertDriverMEDReadStatus(status);
304 //================================================================================
306 * \brief Return string representation of a MED file version comprising nbDigits
308 //================================================================================
310 char* SMESH_Mesh_i::GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits)
312 std::string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(MED::EVersion(version),
314 return CORBA::string_dup( ver.c_str() );
317 //=============================================================================
321 * Imports mesh data from MED file
323 //=============================================================================
325 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
326 throw ( SALOME::SALOME_Exception )
328 // Read mesh with name = <theMeshName> into SMESH_Mesh
329 _impl->UNVToMesh( theFileName );
331 CreateGroupServants();
336 //=============================================================================
340 * Imports mesh data from STL file
342 //=============================================================================
343 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
344 throw ( SALOME::SALOME_Exception )
346 // Read mesh with name = <theMeshName> into SMESH_Mesh
347 _impl->STLToMesh( theFileName );
352 //=============================================================================
356 * Imports mesh data from MED file
358 //=============================================================================
360 // int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
362 // // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
363 // int status = _impl->MEDToMesh( theFileName, theMeshName );
364 // CreateGroupServants();
369 //=============================================================================
373 //=============================================================================
375 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
377 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
378 (SMESH_Hypothesis::Hypothesis_Status theStatus)
381 RETURNCASE( HYP_OK );
382 RETURNCASE( HYP_MISSING );
383 RETURNCASE( HYP_CONCURENT );
384 RETURNCASE( HYP_BAD_PARAMETER );
385 RETURNCASE( HYP_HIDDEN_ALGO );
386 RETURNCASE( HYP_HIDING_ALGO );
387 RETURNCASE( HYP_UNKNOWN_FATAL );
388 RETURNCASE( HYP_INCOMPATIBLE );
389 RETURNCASE( HYP_NOTCONFORM );
390 RETURNCASE( HYP_ALREADY_EXIST );
391 RETURNCASE( HYP_BAD_DIM );
392 RETURNCASE( HYP_BAD_SUBSHAPE );
393 RETURNCASE( HYP_BAD_GEOMETRY );
394 RETURNCASE( HYP_NEED_SHAPE );
397 return SMESH::HYP_UNKNOWN_FATAL;
400 //=============================================================================
404 * calls internal addHypothesis() and then adds a reference to <anHyp> under
405 * the SObject actually having a reference to <aSubShape>.
406 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
408 //=============================================================================
410 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
411 SMESH::SMESH_Hypothesis_ptr anHyp)
412 throw(SALOME::SALOME_Exception)
414 Unexpect aCatch(SALOME_SalomeException);
415 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
417 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
418 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
419 aSubShapeObject, anHyp );
421 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
423 // Update Python script
424 if(_impl->HasShapeToMesh()) {
425 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
426 << aSubShapeObject << ", " << anHyp << " )";
429 TPythonDump() << "status = " << _this() << ".AddHypothesis( "<< anHyp << " )";
432 return ConvertHypothesisStatus(status);
435 //=============================================================================
439 //=============================================================================
441 SMESH_Hypothesis::Hypothesis_Status
442 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
443 SMESH::SMESH_Hypothesis_ptr anHyp)
445 if(MYDEBUG) MESSAGE("addHypothesis");
447 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
448 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
451 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
452 if (CORBA::is_nil(myHyp))
453 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
456 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
459 TopoDS_Shape myLocSubShape;
460 //use PseudoShape in case if mesh has no shape
462 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
464 myLocSubShape = _impl->GetShapeToMesh();
466 int hypId = myHyp->GetId();
467 status = _impl->AddHypothesis(myLocSubShape, hypId);
468 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
469 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
470 // assure there is a corresponding submesh
471 if ( !_impl->IsMainShape( myLocSubShape )) {
472 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
473 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
474 createSubMesh( aSubShapeObject );
478 catch(SALOME_Exception & S_ex)
480 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
485 //=============================================================================
489 //=============================================================================
491 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
492 SMESH::SMESH_Hypothesis_ptr anHyp)
493 throw(SALOME::SALOME_Exception)
495 Unexpect aCatch(SALOME_SalomeException);
496 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
498 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
499 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
500 aSubShapeObject, anHyp );
502 // Update Python script
503 // Update Python script
504 if(_impl->HasShapeToMesh()) {
505 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
506 << aSubShapeObject << ", " << anHyp << " )";
509 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
513 return ConvertHypothesisStatus(status);
516 //=============================================================================
520 //=============================================================================
522 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
523 SMESH::SMESH_Hypothesis_ptr anHyp)
525 if(MYDEBUG) MESSAGE("removeHypothesis()");
526 // **** proposer liste de subShape (selection multiple)
528 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
529 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
532 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
533 if (CORBA::is_nil(myHyp))
534 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
537 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
540 TopoDS_Shape myLocSubShape;
541 //use PseudoShape in case if mesh has no shape
543 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
545 myLocSubShape = _impl->GetShapeToMesh();
547 int hypId = myHyp->GetId();
548 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
549 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
550 _mapHypo.erase( hypId );
552 catch(SALOME_Exception & S_ex)
554 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
559 //=============================================================================
563 //=============================================================================
565 SMESH::ListOfHypothesis *
566 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
567 throw(SALOME::SALOME_Exception)
569 Unexpect aCatch(SALOME_SalomeException);
570 if (MYDEBUG) MESSAGE("GetHypothesisList");
571 if (_impl->HasShapeToMesh() && CORBA::is_nil(aSubShapeObject))
572 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
575 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
578 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
579 if ( myLocSubShape.IsNull() && !_impl->HasShapeToMesh() )
580 myLocSubShape = _impl->GetShapeToMesh();
581 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
582 int i = 0, n = aLocalList.size();
585 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
586 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
587 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
588 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
593 catch(SALOME_Exception & S_ex) {
594 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
597 return aList._retn();
600 //=============================================================================
604 //=============================================================================
605 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
606 const char* theName )
607 throw(SALOME::SALOME_Exception)
609 Unexpect aCatch(SALOME_SalomeException);
610 MESSAGE("SMESH_Mesh_i::GetSubMesh");
611 if (CORBA::is_nil(aSubShapeObject))
612 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
615 SMESH::SMESH_subMesh_var subMesh;
616 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
618 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
620 //Get or Create the SMESH_subMesh object implementation
622 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
623 subMesh = getSubMesh( subMeshId );
625 // create a new subMesh object servant if there is none for the shape
626 if ( subMesh->_is_nil() )
627 subMesh = createSubMesh( aSubShapeObject );
628 if ( _gen_i->CanPublishInStudy( subMesh )) {
629 SALOMEDS::SObject_var aSO =
630 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
631 subMesh, aSubShapeObject, theName );
632 if ( !aSO->_is_nil()) {
633 // Update Python script
634 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
635 << aSubShapeObject << ", '" << theName << "' )";
639 catch(SALOME_Exception & S_ex) {
640 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
642 return subMesh._retn();
645 //=============================================================================
649 //=============================================================================
651 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
652 throw (SALOME::SALOME_Exception)
654 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
655 if ( theSubMesh->_is_nil() )
658 GEOM::GEOM_Object_var aSubShapeObject;
659 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
660 if ( !aStudy->_is_nil() ) {
661 // Remove submesh's SObject
662 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
663 if ( !anSO->_is_nil() ) {
664 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
665 SALOMEDS::SObject_var anObj, aRef;
666 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
667 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
669 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
671 // Update Python script
672 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
676 removeSubMesh( theSubMesh, aSubShapeObject.in() );
679 //=============================================================================
683 //=============================================================================
684 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
685 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
687 switch (theElemType) {
692 CASE2STRING( VOLUME );
698 //=============================================================================
702 //=============================================================================
704 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
705 const char* theName )
706 throw(SALOME::SALOME_Exception)
708 Unexpect aCatch(SALOME_SalomeException);
709 SMESH::SMESH_Group_var aNewGroup =
710 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
712 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
713 SALOMEDS::SObject_var aSO =
714 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
715 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
716 if ( !aSO->_is_nil()) {
717 // Update Python script
718 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
719 << ElementTypeString(theElemType) << ", '" << theName << "' )";
722 return aNewGroup._retn();
726 //=============================================================================
730 //=============================================================================
731 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
733 GEOM::GEOM_Object_ptr theGeomObj)
734 throw(SALOME::SALOME_Exception)
736 Unexpect aCatch(SALOME_SalomeException);
737 SMESH::SMESH_GroupOnGeom_var aNewGroup;
739 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
740 if ( !aShape.IsNull() )
742 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
743 ( createGroup( theElemType, theName, aShape ));
745 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
746 SALOMEDS::SObject_var aSO =
747 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
748 aNewGroup, theGeomObj, theName);
749 if ( !aSO->_is_nil()) {
750 // Update Python script
751 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
752 << ElementTypeString(theElemType) << ", '" << theName << "', "
753 << theGeomObj << " )";
758 return aNewGroup._retn();
761 //=============================================================================
765 //=============================================================================
767 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
768 throw (SALOME::SALOME_Exception)
770 if ( theGroup->_is_nil() )
773 SMESH_GroupBase_i* aGroup =
774 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
778 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
779 if ( !aStudy->_is_nil() ) {
780 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
782 if ( !aGroupSO->_is_nil() ) {
783 // Update Python script
784 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
786 // Remove group's SObject
787 aStudy->NewBuilder()->RemoveObjectWithChildren( aGroupSO );
791 // Remove the group from SMESH data structures
792 removeGroup( aGroup->GetLocalID() );
795 //=============================================================================
796 /*! RemoveGroupWithContents
797 * Remove group with its contents
799 //=============================================================================
800 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
801 throw (SALOME::SALOME_Exception)
803 if ( theGroup->_is_nil() )
806 SMESH_GroupBase_i* aGroup =
807 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
811 SMESH::long_array_var anIds = aGroup->GetListOfID();
812 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
814 // Update Python script
815 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
818 if ( aGroup->GetType() == SMESH::NODE )
819 aMeshEditor->RemoveNodes( anIds );
821 aMeshEditor->RemoveElements( anIds );
824 RemoveGroup( theGroup );
826 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
827 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
828 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
832 //================================================================================
834 * \brief Get the list of groups existing in the mesh
835 * \retval SMESH::ListOfGroups * - list of groups
837 //================================================================================
839 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
841 Unexpect aCatch(SALOME_SalomeException);
842 if (MYDEBUG) MESSAGE("GetGroups");
844 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
847 TPythonDump aPythonDump;
848 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
852 aList->length( _mapGroups.size() );
854 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
855 for ( ; it != _mapGroups.end(); it++ ) {
856 if ( CORBA::is_nil( it->second )) continue;
857 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
859 if (i > 1) aPythonDump << ", ";
860 aPythonDump << it->second;
864 catch(SALOME_Exception & S_ex) {
865 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
868 // Update Python script
869 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
870 aPythonDump << " ] = " << _this() << ".GetGroups()";
872 return aList._retn();
874 //=============================================================================
876 * Get number of groups existing in the mesh
878 //=============================================================================
880 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
882 Unexpect aCatch(SALOME_SalomeException);
883 return _mapGroups.size();
886 //=============================================================================
888 * New group is created. All mesh elements that are
889 * present in initial groups are added to the new one
891 //=============================================================================
892 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
893 SMESH::SMESH_GroupBase_ptr theGroup2,
894 const char* theName )
895 throw (SALOME::SALOME_Exception)
899 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
900 theGroup1->GetType() != theGroup2->GetType() )
901 return SMESH::SMESH_Group::_nil();
904 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
905 if ( aResGrp->_is_nil() )
906 return SMESH::SMESH_Group::_nil();
908 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
909 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
911 TColStd_MapOfInteger aResMap;
913 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
914 aResMap.Add( anIds1[ i1 ] );
916 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
917 aResMap.Add( anIds2[ i2 ] );
919 SMESH::long_array_var aResIds = new SMESH::long_array;
920 aResIds->length( aResMap.Extent() );
923 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
924 for( ; anIter.More(); anIter.Next() )
925 aResIds[ resI++ ] = anIter.Key();
927 aResGrp->Add( aResIds );
929 // Clear python lines, created by CreateGroup() and Add()
930 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
931 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
932 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
934 // Update Python script
935 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
936 << theGroup1 << ", " << theGroup2 << ", '"
939 return aResGrp._retn();
943 return SMESH::SMESH_Group::_nil();
947 //=============================================================================
949 \brief Union list of groups. New group is created. All mesh elements that are
950 present in initial groups are added to the new one.
951 \param theGroups list of groups
952 \param theName name of group to be created
953 \return pointer on the group
955 //=============================================================================
956 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionListOfGroups(const SMESH::ListOfGroups& theGroups,
957 const char* theName )
958 throw (SALOME::SALOME_Exception)
961 return SMESH::SMESH_Group::_nil();
965 NCollection_Map< int > anIds;
966 SMESH::ElementType aType = SMESH::ALL;
967 for ( int g = 0, n = theGroups.length(); g < n; g++ )
969 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
970 if ( CORBA::is_nil( aGrp ) )
974 SMESH::ElementType aCurrType = aGrp->GetType();
975 if ( aType == SMESH::ALL )
979 if ( aType != aCurrType )
980 return SMESH::SMESH_Group::_nil();
984 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
985 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
987 int aCurrId = aCurrIds[ i ];
988 anIds.Add( aCurrId );
993 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
994 if ( aResGrp->_is_nil() )
995 return SMESH::SMESH_Group::_nil();
997 // Create array of identifiers
998 SMESH::long_array_var aResIds = new SMESH::long_array;
999 aResIds->length( anIds.Extent() );
1001 NCollection_Map< int >::Iterator anIter( anIds );
1002 for ( int i = 0; anIter.More(); anIter.Next(), i++ )
1004 aResIds[ i ] = anIter.Value();
1006 aResGrp->Add( aResIds );
1008 // Clear python lines, created by CreateGroup() and Add()
1009 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1010 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1011 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1013 // Update Python script
1015 TPythonDump() << aResGrp << " = " << _this() << ".UnionListOfGroups( "
1016 << &theGroups << ", '" << theName << "' )";
1018 return aResGrp._retn();
1022 return SMESH::SMESH_Group::_nil();
1026 //=============================================================================
1028 * New group is created. All mesh elements that are
1029 * present in both initial groups are added to the new one.
1031 //=============================================================================
1032 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1033 SMESH::SMESH_GroupBase_ptr theGroup2,
1034 const char* theName )
1035 throw (SALOME::SALOME_Exception)
1037 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
1038 theGroup1->GetType() != theGroup2->GetType() )
1039 return SMESH::SMESH_Group::_nil();
1041 // Create Intersection
1042 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
1043 if ( aResGrp->_is_nil() )
1046 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
1047 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1049 TColStd_MapOfInteger aMap1;
1051 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1052 aMap1.Add( anIds1[ i1 ] );
1054 TColStd_SequenceOfInteger aSeq;
1056 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1057 if ( aMap1.Contains( anIds2[ i2 ] ) )
1058 aSeq.Append( anIds2[ i2 ] );
1060 SMESH::long_array_var aResIds = new SMESH::long_array;
1061 aResIds->length( aSeq.Length() );
1063 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1064 aResIds[ resI ] = aSeq( resI + 1 );
1066 aResGrp->Add( aResIds );
1068 // Clear python lines, created by CreateGroup() and Add()
1069 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1070 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1071 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1073 // Update Python script
1074 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
1075 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
1077 return aResGrp._retn();
1080 //=============================================================================
1082 \brief Intersect list of groups. New group is created. All mesh elements that
1083 are present in all initial groups simultaneously are added to the new one.
1084 \param theGroups list of groups
1085 \param theName name of group to be created
1086 \return pointer on the group
1088 //=============================================================================
1089 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectListOfGroups(
1090 const SMESH::ListOfGroups& theGroups, const char* theName )
1091 throw (SALOME::SALOME_Exception)
1094 return SMESH::SMESH_Group::_nil();
1098 NCollection_DataMap< int, int > anIdToCount;
1099 SMESH::ElementType aType = SMESH::ALL;
1100 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1102 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1103 if ( CORBA::is_nil( aGrp ) )
1107 SMESH::ElementType aCurrType = aGrp->GetType();
1108 if ( aType == SMESH::ALL )
1112 if ( aType != aCurrType )
1113 return SMESH::SMESH_Group::_nil();
1116 // calculates number of occurance ids in groups
1117 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1118 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1120 int aCurrId = aCurrIds[ i ];
1121 if ( !anIdToCount.IsBound( aCurrId ) )
1122 anIdToCount.Bind( aCurrId, 1 );
1124 anIdToCount( aCurrId ) = anIdToCount( aCurrId ) + 1;
1128 // create map of ids
1129 int nbGrp = theGroups.length();
1130 NCollection_Map< int > anIds;
1131 NCollection_DataMap< int, int >::Iterator anIter( anIdToCount );
1132 for ( ; anIter.More(); anIter.Next() )
1134 int aCurrId = anIter.Key();
1135 int aCurrNb = anIter.Value();
1136 if ( aCurrNb == nbGrp )
1137 anIds.Add( aCurrId );
1141 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
1142 if ( aResGrp->_is_nil() )
1143 return SMESH::SMESH_Group::_nil();
1145 // Create array of identifiers
1146 SMESH::long_array_var aResIds = new SMESH::long_array;
1147 aResIds->length( anIds.Extent() );
1149 NCollection_Map< int >::Iterator aListIter( anIds );
1150 for ( int i = 0; aListIter.More(); aListIter.Next(), i++ )
1152 aResIds[ i ] = aListIter.Value();
1154 aResGrp->Add( aResIds );
1156 // Clear python lines, created by CreateGroup() and Add()
1157 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1158 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1159 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1161 // Update Python script
1163 TPythonDump() << aResGrp << " = " << _this() << ".IntersectListOfGroups( "
1164 << &theGroups << ", '" << theName << "' )";
1166 return aResGrp._retn();
1170 return SMESH::SMESH_Group::_nil();
1174 //=============================================================================
1176 * New group is created. All mesh elements that are present in
1177 * main group but do not present in tool group are added to the new one
1179 //=============================================================================
1180 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1181 SMESH::SMESH_GroupBase_ptr theGroup2,
1182 const char* theName )
1183 throw (SALOME::SALOME_Exception)
1185 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
1186 theGroup1->GetType() != theGroup2->GetType() )
1187 return SMESH::SMESH_Group::_nil();
1190 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
1191 if ( aResGrp->_is_nil() )
1194 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
1195 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1197 TColStd_MapOfInteger aMap2;
1199 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1200 aMap2.Add( anIds2[ i2 ] );
1202 TColStd_SequenceOfInteger aSeq;
1203 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1204 if ( !aMap2.Contains( anIds1[ i1 ] ) )
1205 aSeq.Append( anIds1[ i1 ] );
1207 SMESH::long_array_var aResIds = new SMESH::long_array;
1208 aResIds->length( aSeq.Length() );
1210 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1211 aResIds[ resI ] = aSeq( resI + 1 );
1213 aResGrp->Add( aResIds );
1215 // Clear python lines, created by CreateGroup() and Add()
1216 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1217 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1218 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1220 // Update Python script
1221 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
1222 << theGroup1 << ", " << theGroup2 << ", '"
1223 << theName << "' )";
1225 return aResGrp._retn();
1228 //=============================================================================
1230 \brief Cut lists of groups. New group is created. All mesh elements that are
1231 present in main groups but do not present in tool groups are added to the new one
1232 \param theMainGroups list of main groups
1233 \param theToolGroups list of tool groups
1234 \param theName name of group to be created
1235 \return pointer on the group
1237 //=============================================================================
1238 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutListOfGroups(
1239 const SMESH::ListOfGroups& theMainGroups,
1240 const SMESH::ListOfGroups& theToolGroups,
1241 const char* theName )
1242 throw (SALOME::SALOME_Exception)
1245 return SMESH::SMESH_Group::_nil();
1249 NCollection_Map< int > aToolIds;
1250 SMESH::ElementType aType = SMESH::ALL;
1252 // iterate through tool groups
1253 for ( g = 0, n = theToolGroups.length(); g < n; g++ )
1255 SMESH::SMESH_GroupBase_var aGrp = theToolGroups[ g ];
1256 if ( CORBA::is_nil( aGrp ) )
1260 SMESH::ElementType aCurrType = aGrp->GetType();
1261 if ( aType == SMESH::ALL )
1265 if ( aType != aCurrType )
1266 return SMESH::SMESH_Group::_nil();
1270 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1271 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1273 int aCurrId = aCurrIds[ i ];
1274 aToolIds.Add( aCurrId );
1278 NCollection_Map< int > anIds; // result
1280 // Iterate through main group
1281 for ( g = 0, n = theMainGroups.length(); g < n; g++ )
1283 SMESH::SMESH_GroupBase_var aGrp = theMainGroups[ g ];
1284 if ( CORBA::is_nil( aGrp ) )
1288 SMESH::ElementType aCurrType = aGrp->GetType();
1289 if ( aType == SMESH::ALL )
1293 if ( aType != aCurrType )
1294 return SMESH::SMESH_Group::_nil();
1298 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1299 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1301 int aCurrId = aCurrIds[ i ];
1302 if ( !aToolIds.Contains( aCurrId ) )
1303 anIds.Add( aCurrId );
1308 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
1309 if ( aResGrp->_is_nil() )
1310 return SMESH::SMESH_Group::_nil();
1312 // Create array of identifiers
1313 SMESH::long_array_var aResIds = new SMESH::long_array;
1314 aResIds->length( anIds.Extent() );
1316 NCollection_Map< int >::Iterator anIter( anIds );
1317 for ( int i = 0; anIter.More(); anIter.Next(), i++ )
1319 aResIds[ i ] = anIter.Value();
1321 aResGrp->Add( aResIds );
1323 // Clear python lines, created by CreateGroup() and Add()
1324 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1325 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1326 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1328 // Update Python script
1330 TPythonDump() << aResGrp << " = " << _this() << ".CutListOfGroups( "
1331 << &theMainGroups << ", " << &theToolGroups << ", '"
1332 << theName << "' )";
1334 return aResGrp._retn();
1338 return SMESH::SMESH_Group::_nil();
1342 //=============================================================================
1344 \brief Create groups of entities from existing groups of superior dimensions
1346 1) extract all nodes from each group,
1347 2) combine all elements of specified dimension laying on these nodes.
1348 \param theGroups list of source groups
1349 \param theElemType dimension of elements
1350 \param theName name of new group
1351 \return pointer on new group
1353 //=============================================================================
1354 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateDimGroup(
1355 const SMESH::ListOfGroups& theGroups,
1356 SMESH::ElementType theElemType,
1357 const char* theName )
1358 throw (SALOME::SALOME_Exception)
1360 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
1362 if ( !theName || !aMeshDS )
1363 return SMESH::SMESH_Group::_nil();
1365 SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)theElemType;
1369 // Create map of nodes from all groups
1371 NCollection_Map< int > aNodeMap;
1373 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1375 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1376 if ( CORBA::is_nil( aGrp ) )
1379 SMESH::ElementType aType = aGrp->GetType();
1380 if ( aType == SMESH::ALL )
1382 else if ( aType == SMESH::NODE )
1384 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1385 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1387 int aCurrId = aCurrIds[ i ];
1388 const SMDS_MeshNode* aNode = aMeshDS->FindNode( aCurrId );
1390 aNodeMap.Add( aNode->GetID() );
1395 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1396 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1398 int aCurrId = aCurrIds[ i ];
1399 const SMDS_MeshElement* anElem = aMeshDS->FindElement( aCurrId );
1402 SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator();
1403 while( aNodeIter->more() )
1405 const SMDS_MeshNode* aNode =
1406 dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() );
1408 aNodeMap.Add( aNode->GetID() );
1414 // Get result identifiers
1416 NCollection_Map< int > aResultIds;
1417 if ( theElemType == SMESH::NODE )
1419 NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
1420 for ( ; aNodeIter.More(); aNodeIter.Next() )
1421 aResultIds.Add( aNodeIter.Value() );
1425 // Create list of elements of given dimension constructed on the nodes
1426 NCollection_Map< int > anElemList;
1427 NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
1428 for ( ; aNodeIter.More(); aNodeIter.Next() )
1430 const SMDS_MeshElement* aNode =
1431 dynamic_cast<const SMDS_MeshElement*>( aMeshDS->FindNode( aNodeIter.Value() ) );
1435 SMDS_ElemIteratorPtr anElemIter = aNode->elementsIterator( anElemType );
1436 while( anElemIter->more() )
1438 const SMDS_MeshElement* anElem =
1439 dynamic_cast<const SMDS_MeshElement*>( anElemIter->next() );
1440 if ( anElem && anElem->GetType() == anElemType )
1441 anElemList.Add( anElem->GetID() );
1445 // check whether all nodes of elements are present in nodes map
1446 NCollection_Map< int >::Iterator anIter( anElemList );
1447 for ( ; anIter.More(); anIter.Next() )
1449 const SMDS_MeshElement* anElem = aMeshDS->FindElement( anIter.Value() );
1454 SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator();
1455 while( aNodeIter->more() )
1457 const SMDS_MeshNode* aNode =
1458 dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() );
1459 if ( !aNode || !aNodeMap.Contains( aNode->GetID() ) )
1466 aResultIds.Add( anElem->GetID() );
1472 SMESH::SMESH_Group_var aResGrp = CreateGroup( theElemType, theName );
1473 if ( aResGrp->_is_nil() )
1474 return SMESH::SMESH_Group::_nil();
1476 // Create array of identifiers
1477 SMESH::long_array_var aResIds = new SMESH::long_array;
1478 aResIds->length( aResultIds.Extent() );
1480 NCollection_Map< int >::Iterator aResIter( aResultIds );
1481 for ( int i = 0; aResIter.More(); aResIter.Next(), i++ )
1482 aResIds[ i ] = aResIter.Value();
1483 aResGrp->Add( aResIds );
1485 // Remove strings corresponding to group creation
1486 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1487 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1488 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1490 // Update Python script
1492 TPythonDump() << aResGrp << " = " << _this() << ".CreateDimGroup( "
1493 << &theGroups << ", " << theElemType << ", '" << theName << "' )";
1495 return aResGrp._retn();
1499 return SMESH::SMESH_Group::_nil();
1503 //================================================================================
1505 * \brief Remember GEOM group data
1507 //================================================================================
1509 void SMESH_Mesh_i::addGeomGroupData(GEOM::GEOM_Object_ptr theGeomObj,
1510 CORBA::Object_ptr theSmeshObj)
1512 if ( CORBA::is_nil( theGeomObj ) || theGeomObj->GetType() != GEOM_GROUP )
1515 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1516 SALOMEDS::SObject_var groupSO = _gen_i->ObjectToSObject( study, theGeomObj );
1517 if ( groupSO->_is_nil() )
1520 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
1521 GEOM::GEOM_IGroupOperations_var groupOp =
1522 geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
1523 GEOM::ListOfLong_var ids = groupOp->GetObjects( theGeomObj );
1526 _geomGroupData.push_back( TGeomGroupData() );
1527 TGeomGroupData & groupData = _geomGroupData.back();
1529 CORBA::String_var entry = groupSO->GetID();
1530 groupData._groupEntry = entry.in();
1532 for ( int i = 0; i < ids->length(); ++i )
1533 groupData._indices.insert( ids[i] );
1535 groupData._smeshObject = theSmeshObj;
1538 //================================================================================
1540 * Remove GEOM group data relating to removed smesh object
1542 //================================================================================
1544 void SMESH_Mesh_i::removeGeomGroupData(CORBA::Object_ptr theSmeshObj)
1546 list<TGeomGroupData>::iterator
1547 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
1548 for ( ; data != dataEnd; ++data ) {
1549 if ( theSmeshObj->_is_equivalent( data->_smeshObject )) {
1550 _geomGroupData.erase( data );
1556 //================================================================================
1558 * \brief Return new group contents if it has been changed and update group data
1560 //================================================================================
1562 TopoDS_Shape SMESH_Mesh_i::newGroupShape( TGeomGroupData & groupData)
1564 TopoDS_Shape newShape;
1567 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1568 if ( study->_is_nil() ) return newShape; // means "not changed"
1569 SALOMEDS::SObject_var groupSO = study->FindObjectID( groupData._groupEntry.c_str() );
1570 if ( !groupSO->_is_nil() )
1572 CORBA::Object_var groupObj = _gen_i->SObjectToObject( groupSO );
1573 if ( CORBA::is_nil( groupObj )) return newShape;
1574 GEOM::GEOM_Object_var geomGroup = GEOM::GEOM_Object::_narrow( groupObj );
1576 // get indices of group items
1577 set<int> curIndices;
1578 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
1579 GEOM::GEOM_IGroupOperations_var groupOp =
1580 geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
1581 GEOM::ListOfLong_var ids = groupOp->GetObjects( geomGroup );
1582 for ( int i = 0; i < ids->length(); ++i )
1583 curIndices.insert( ids[i] );
1585 if ( groupData._indices == curIndices )
1586 return newShape; // group not changed
1589 groupData._indices = curIndices;
1591 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1592 if ( !geomClient ) return newShape;
1593 TCollection_AsciiString groupIOR = geomGen->GetStringFromIOR( geomGroup );
1594 geomClient->RemoveShapeFromBuffer( groupIOR );
1595 newShape = _gen_i->GeomObjectToShape( geomGroup );
1598 if ( newShape.IsNull() ) {
1599 // geom group becomes empty - return empty compound
1600 TopoDS_Compound compound;
1601 BRep_Builder builder;
1602 builder.MakeCompound(compound);
1603 newShape = compound;
1608 //=============================================================================
1610 * \brief Update objects depending on changed geom groups
1612 * NPAL16168: geometrical group edition from a submesh don't modifiy mesh computation
1613 * issue 0020210: Update of a smesh group after modification of the associated geom group
1615 //=============================================================================
1617 void SMESH_Mesh_i::CheckGeomGroupModif()
1619 if ( !_impl->HasShapeToMesh() ) return;
1621 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1622 if ( study->_is_nil() ) return;
1624 CORBA::Long nbEntities = NbNodes() + NbElements();
1626 // Check if group contents changed
1628 typedef map< string, TopoDS_Shape > TEntry2Geom;
1629 TEntry2Geom newGroupContents;
1631 list<TGeomGroupData>::iterator
1632 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
1633 for ( ; data != dataEnd; ++data )
1635 pair< TEntry2Geom::iterator, bool > it_new =
1636 newGroupContents.insert( make_pair( data->_groupEntry, TopoDS_Shape() ));
1637 bool processedGroup = !it_new.second;
1638 TopoDS_Shape& newShape = it_new.first->second;
1639 if ( !processedGroup )
1640 newShape = newGroupShape( *data );
1641 if ( newShape.IsNull() )
1642 continue; // no changes
1644 if ( processedGroup ) { // update group indices
1645 list<TGeomGroupData>::iterator data2 = data;
1646 for ( --data2; data2->_groupEntry != data->_groupEntry; --data2)
1647 data->_indices = data2->_indices;
1650 // Update SMESH objects according to new GEOM group contents
1652 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( data->_smeshObject );
1653 if ( !mesh->_is_nil() ) // -------------- MESH ----------------------------
1659 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( data->_smeshObject );
1660 if ( !submesh->_is_nil() ) // -------------- Sub mesh ---------------------
1662 int oldID = submesh->GetId();
1663 if ( _mapSubMeshIor.find( oldID ) == _mapSubMeshIor.end() )
1665 TopoDS_Shape oldShape = _mapSubMesh[oldID]->GetSubShape();
1667 // update hypotheses
1668 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldShape);
1669 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1670 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1672 _impl->RemoveHypothesis( oldShape, (*hypIt)->GetID());
1673 _impl->AddHypothesis ( newShape, (*hypIt)->GetID());
1675 // care of submeshes
1676 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newShape );
1677 int newID = newSubmesh->GetId();
1678 if ( newID != oldID ) {
1679 _mapSubMesh [ newID ] = newSubmesh;
1680 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1681 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1682 _mapSubMesh. erase(oldID);
1683 _mapSubMesh_i. erase(oldID);
1684 _mapSubMeshIor.erase(oldID);
1685 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1690 SMESH::SMESH_GroupOnGeom_var smeshGroup =
1691 SMESH::SMESH_GroupOnGeom::_narrow( data->_smeshObject );
1692 if ( !smeshGroup->_is_nil() ) // ------------ GROUP -----------------------
1694 SMESH_GroupOnGeom_i* group_i = SMESH::DownCast<SMESH_GroupOnGeom_i*>( smeshGroup );
1696 ::SMESH_Group* group = _impl->GetGroup( group_i->GetLocalID() );
1697 SMESHDS_GroupOnGeom* ds = static_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() );
1698 ds->SetShape( newShape );
1706 CORBA::Long newNbEntities = NbNodes() + NbElements();
1707 list< SALOMEDS::SObject_var > soToUpdateIcons;
1708 if ( newNbEntities != nbEntities )
1710 // Add all SObjects with icons
1711 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, _this() )); // mesh
1713 for (map<int, SMESH::SMESH_subMesh_ptr>::iterator i_sm = _mapSubMeshIor.begin();
1714 i_sm != _mapSubMeshIor.end(); ++i_sm ) // submeshes
1715 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_sm->second ));
1717 for ( map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_gr = _mapGroups.begin();
1718 i_gr != _mapGroups.end(); ++i_gr ) // groups
1719 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_gr->second ));
1722 list< SALOMEDS::SObject_var >::iterator so = soToUpdateIcons.begin();
1723 for ( ; so != soToUpdateIcons.end(); ++so )
1724 _gen_i->SetPixMap( *so, "ICON_SMESH_TREE_MESH_WARN" );
1727 //=============================================================================
1729 * \brief Create standalone group instead if group on geometry
1732 //=============================================================================
1734 SMESH::SMESH_Group_ptr SMESH_Mesh_i::ConvertToStandalone( SMESH::SMESH_GroupOnGeom_ptr theGroup )
1736 SMESH::SMESH_Group_var aGroup;
1737 if ( theGroup->_is_nil() )
1738 return aGroup._retn();
1740 Unexpect aCatch(SALOME_SalomeException);
1742 SMESH_GroupBase_i* aGroupToRem =
1743 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
1745 return aGroup._retn();
1747 int anId = aGroupToRem->GetLocalID();
1748 if ( !_impl->ConvertToStandalone( anId ) )
1749 return aGroup._retn();
1750 removeGeomGroupData( theGroup );
1752 SMESH_GroupBase_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1754 // remove old instance of group from own map
1755 _mapGroups.erase( anId );
1757 SALOMEDS::StudyBuilder_var builder;
1758 SALOMEDS::SObject_var aGroupSO;
1759 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1760 if ( !aStudy->_is_nil() ) {
1761 builder = aStudy->NewBuilder();
1762 aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
1763 if ( !aGroupSO->_is_nil() ) {
1765 // remove reference to geometry
1766 SALOMEDS::ChildIterator_var chItr = aStudy->NewChildIterator(aGroupSO);
1767 for ( ; chItr->More(); chItr->Next() )
1768 // Remove group's child SObject
1769 builder->RemoveObject( chItr->Value() );
1771 // Update Python script
1772 TPythonDump() << aGroupSO << " = " << _this() << ".ConvertToStandalone( "
1773 << aGroupSO << " )";
1777 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1778 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1779 aGroupImpl->Register();
1780 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1782 // remember new group in own map
1783 aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
1784 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1786 // register CORBA object for persistence
1787 //int nextId = _gen_i->RegisterObject( aGroup );
1788 //if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1789 builder->SetIOR( aGroupSO, _gen_i->GetORB()->object_to_string( aGroup ) );
1791 return aGroup._retn();
1794 //=============================================================================
1798 //=============================================================================
1800 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1802 if(MYDEBUG) MESSAGE( "createSubMesh" );
1803 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1805 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1806 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1807 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1808 SMESH::SMESH_subMesh_var subMesh
1809 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1811 _mapSubMesh[subMeshId] = mySubMesh;
1812 _mapSubMesh_i[subMeshId] = subMeshServant;
1813 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1815 // register CORBA object for persistence
1816 int nextId = _gen_i->RegisterObject( subMesh );
1817 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1819 // to track changes of GEOM groups
1820 addGeomGroupData( theSubShapeObject, subMesh );
1822 return subMesh._retn();
1825 //=======================================================================
1826 //function : getSubMesh
1828 //=======================================================================
1830 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1832 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1833 if ( it == _mapSubMeshIor.end() )
1834 return SMESH::SMESH_subMesh::_nil();
1836 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1840 //=============================================================================
1844 //=============================================================================
1846 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1847 GEOM::GEOM_Object_ptr theSubShapeObject )
1849 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1850 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1854 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1855 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1856 removeHypothesis( theSubShapeObject, aHypList[i] );
1859 catch( const SALOME::SALOME_Exception& ) {
1860 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1862 removeGeomGroupData( theSubShapeObject );
1864 int subMeshId = theSubMesh->GetId();
1866 _mapSubMesh.erase(subMeshId);
1867 _mapSubMesh_i.erase(subMeshId);
1868 _mapSubMeshIor.erase(subMeshId);
1869 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1872 //=============================================================================
1876 //=============================================================================
1878 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1879 const char* theName,
1880 const TopoDS_Shape& theShape )
1883 SMESH::SMESH_GroupBase_var aGroup;
1884 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1885 SMESH_GroupBase_i* aGroupImpl;
1886 if ( !theShape.IsNull() )
1887 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1889 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1891 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1892 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1893 aGroupImpl->Register();
1894 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1896 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1897 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1899 // register CORBA object for persistence
1900 int nextId = _gen_i->RegisterObject( aGroup );
1901 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1903 // to track changes of GEOM groups
1904 if ( !theShape.IsNull() ) {
1905 GEOM::GEOM_Object_var geom = _gen_i->ShapeToGeomObject( theShape );
1906 addGeomGroupData( geom, aGroup );
1909 return aGroup._retn();
1912 //=============================================================================
1914 * SMESH_Mesh_i::removeGroup
1916 * Should be called by ~SMESH_Group_i()
1918 //=============================================================================
1920 void SMESH_Mesh_i::removeGroup( const int theId )
1922 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1923 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1924 removeGeomGroupData( _mapGroups[theId] );
1925 _mapGroups.erase( theId );
1926 _impl->RemoveGroup( theId );
1931 //=============================================================================
1935 //=============================================================================
1937 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1938 throw(SALOME::SALOME_Exception)
1940 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1942 SMESH::log_array_var aLog;
1944 list < SMESHDS_Command * >logDS = _impl->GetLog();
1945 aLog = new SMESH::log_array;
1947 int lg = logDS.size();
1950 list < SMESHDS_Command * >::iterator its = logDS.begin();
1951 while(its != logDS.end()){
1952 SMESHDS_Command *com = *its;
1953 int comType = com->GetType();
1955 int lgcom = com->GetNumber();
1957 const list < int >&intList = com->GetIndexes();
1958 int inum = intList.size();
1960 list < int >::const_iterator ii = intList.begin();
1961 const list < double >&coordList = com->GetCoords();
1962 int rnum = coordList.size();
1964 list < double >::const_iterator ir = coordList.begin();
1965 aLog[indexLog].commandType = comType;
1966 aLog[indexLog].number = lgcom;
1967 aLog[indexLog].coords.length(rnum);
1968 aLog[indexLog].indexes.length(inum);
1969 for(int i = 0; i < rnum; i++){
1970 aLog[indexLog].coords[i] = *ir;
1971 //MESSAGE(" "<<i<<" "<<ir.Value());
1974 for(int i = 0; i < inum; i++){
1975 aLog[indexLog].indexes[i] = *ii;
1976 //MESSAGE(" "<<i<<" "<<ii.Value());
1985 catch(SALOME_Exception & S_ex){
1986 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1988 return aLog._retn();
1992 //=============================================================================
1996 //=============================================================================
1998 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
2000 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
2004 //=============================================================================
2008 //=============================================================================
2010 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
2012 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
2016 //=============================================================================
2020 //=============================================================================
2022 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
2027 //=============================================================================
2031 //=============================================================================
2033 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
2035 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
2039 //=============================================================================
2043 //=============================================================================
2045 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
2047 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
2051 //=============================================================================
2053 * Return mesh editor
2055 //=============================================================================
2057 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
2059 // Create MeshEditor
2060 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
2061 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
2063 // Update Python script
2064 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
2066 return aMesh._retn();
2069 //=============================================================================
2071 * Return mesh edition previewer
2073 //=============================================================================
2075 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
2077 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
2078 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
2079 return aMesh._retn();
2082 //=============================================================================
2086 //=============================================================================
2087 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
2089 Unexpect aCatch(SALOME_SalomeException);
2090 _impl->SetAutoColor(theAutoColor);
2093 //=============================================================================
2097 //=============================================================================
2098 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
2100 Unexpect aCatch(SALOME_SalomeException);
2101 return _impl->GetAutoColor();
2105 //=============================================================================
2107 * Export in different formats
2109 //=============================================================================
2111 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
2113 return _impl->HasDuplicatedGroupNamesMED();
2116 void SMESH_Mesh_i::PrepareForWriting (const char* file)
2118 TCollection_AsciiString aFullName ((char*)file);
2119 OSD_Path aPath (aFullName);
2120 OSD_File aFile (aPath);
2121 if (aFile.Exists()) {
2122 // existing filesystem node
2123 if (aFile.KindOfFile() == OSD_FILE) {
2124 if (aFile.IsWriteable()) {
2127 if (aFile.Failed()) {
2128 TCollection_AsciiString msg ("File ");
2129 msg += aFullName + " cannot be replaced.";
2130 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2133 TCollection_AsciiString msg ("File ");
2134 msg += aFullName + " cannot be overwritten.";
2135 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2138 TCollection_AsciiString msg ("Location ");
2139 msg += aFullName + " is not a file.";
2140 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2143 // nonexisting file; check if it can be created
2145 aFile.Build(OSD_WriteOnly, OSD_Protection());
2146 if (aFile.Failed()) {
2147 TCollection_AsciiString msg ("You cannot create the file ");
2148 msg += aFullName + ". Check the directory existance and access rights.";
2149 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2157 void SMESH_Mesh_i::ExportToMED (const char* file,
2158 CORBA::Boolean auto_groups,
2159 SMESH::MED_VERSION theVersion)
2160 throw(SALOME::SALOME_Exception)
2162 Unexpect aCatch(SALOME_SalomeException);
2165 PrepareForWriting(file);
2166 const char* aMeshName = "Mesh";
2167 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2168 if ( !aStudy->_is_nil() ) {
2169 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
2170 if ( !aMeshSO->_is_nil() ) {
2171 aMeshName = aMeshSO->GetName();
2172 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
2173 if ( !aStudy->GetProperties()->IsLocked() )
2175 SALOMEDS::GenericAttribute_var anAttr;
2176 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2177 SALOMEDS::AttributeExternalFileDef_var aFileName;
2178 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
2179 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
2180 ASSERT(!aFileName->_is_nil());
2181 aFileName->SetValue(file);
2182 SALOMEDS::AttributeFileType_var aFileType;
2183 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
2184 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
2185 ASSERT(!aFileType->_is_nil());
2186 aFileType->SetValue("FICHIERMED");
2190 // Update Python script
2191 // set name of mesh before export
2192 TPythonDump() << _gen_i << ".SetName(" << _this() << ", '" << aMeshName << "')";
2194 // check names of groups
2197 TPythonDump() << _this() << ".ExportToMED( '"
2198 << file << "', " << auto_groups << ", " << theVersion << " )";
2200 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
2203 void SMESH_Mesh_i::ExportMED (const char* file,
2204 CORBA::Boolean auto_groups)
2205 throw(SALOME::SALOME_Exception)
2207 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
2210 void SMESH_Mesh_i::ExportDAT (const char *file)
2211 throw(SALOME::SALOME_Exception)
2213 Unexpect aCatch(SALOME_SalomeException);
2215 // Update Python script
2216 // check names of groups
2218 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
2221 PrepareForWriting(file);
2222 _impl->ExportDAT(file);
2225 void SMESH_Mesh_i::ExportUNV (const char *file)
2226 throw(SALOME::SALOME_Exception)
2228 Unexpect aCatch(SALOME_SalomeException);
2230 // Update Python script
2231 // check names of groups
2233 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
2236 PrepareForWriting(file);
2237 _impl->ExportUNV(file);
2240 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
2241 throw(SALOME::SALOME_Exception)
2243 Unexpect aCatch(SALOME_SalomeException);
2245 // Update Python script
2246 // check names of groups
2248 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
2251 PrepareForWriting(file);
2252 _impl->ExportSTL(file, isascii);
2255 //=============================================================================
2259 //=============================================================================
2261 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
2263 Unexpect aCatch(SALOME_SalomeException);
2264 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
2265 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
2266 return aMesh._retn();
2269 //=============================================================================
2273 //=============================================================================
2274 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
2276 Unexpect aCatch(SALOME_SalomeException);
2277 return _impl->NbNodes();
2280 //=============================================================================
2284 //=============================================================================
2285 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
2287 Unexpect aCatch(SALOME_SalomeException);
2288 return NbEdges() + NbFaces() + NbVolumes();
2291 //=============================================================================
2295 //=============================================================================
2296 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
2298 Unexpect aCatch(SALOME_SalomeException);
2299 return _impl->NbEdges();
2302 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
2303 throw(SALOME::SALOME_Exception)
2305 Unexpect aCatch(SALOME_SalomeException);
2306 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
2309 //=============================================================================
2313 //=============================================================================
2314 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
2316 Unexpect aCatch(SALOME_SalomeException);
2317 return _impl->NbFaces();
2320 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
2322 Unexpect aCatch(SALOME_SalomeException);
2323 return _impl->NbTriangles();
2326 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
2328 Unexpect aCatch(SALOME_SalomeException);
2329 return _impl->NbQuadrangles();
2332 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
2334 Unexpect aCatch(SALOME_SalomeException);
2335 return _impl->NbPolygons();
2338 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
2339 throw(SALOME::SALOME_Exception)
2341 Unexpect aCatch(SALOME_SalomeException);
2342 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
2345 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
2346 throw(SALOME::SALOME_Exception)
2348 Unexpect aCatch(SALOME_SalomeException);
2349 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
2352 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
2353 throw(SALOME::SALOME_Exception)
2355 Unexpect aCatch(SALOME_SalomeException);
2356 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
2359 //=============================================================================
2363 //=============================================================================
2364 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
2366 Unexpect aCatch(SALOME_SalomeException);
2367 return _impl->NbVolumes();
2370 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
2372 Unexpect aCatch(SALOME_SalomeException);
2373 return _impl->NbTetras();
2376 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
2378 Unexpect aCatch(SALOME_SalomeException);
2379 return _impl->NbHexas();
2382 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
2384 Unexpect aCatch(SALOME_SalomeException);
2385 return _impl->NbPyramids();
2388 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
2390 Unexpect aCatch(SALOME_SalomeException);
2391 return _impl->NbPrisms();
2394 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
2396 Unexpect aCatch(SALOME_SalomeException);
2397 return _impl->NbPolyhedrons();
2400 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
2401 throw(SALOME::SALOME_Exception)
2403 Unexpect aCatch(SALOME_SalomeException);
2404 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
2407 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
2408 throw(SALOME::SALOME_Exception)
2410 Unexpect aCatch(SALOME_SalomeException);
2411 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
2414 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
2415 throw(SALOME::SALOME_Exception)
2417 Unexpect aCatch(SALOME_SalomeException);
2418 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
2421 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
2422 throw(SALOME::SALOME_Exception)
2424 Unexpect aCatch(SALOME_SalomeException);
2425 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
2428 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
2429 throw(SALOME::SALOME_Exception)
2431 Unexpect aCatch(SALOME_SalomeException);
2432 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
2435 //=============================================================================
2439 //=============================================================================
2440 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
2442 Unexpect aCatch(SALOME_SalomeException);
2443 return _mapSubMesh_i.size();
2446 //=============================================================================
2450 //=============================================================================
2451 char* SMESH_Mesh_i::Dump()
2453 std::ostringstream os;
2455 return CORBA::string_dup( os.str().c_str() );
2458 //=============================================================================
2462 //=============================================================================
2463 SMESH::long_array* SMESH_Mesh_i::GetIDs()
2465 // SMESH::long_array_var aResult = new SMESH::long_array();
2466 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2467 // int aMinId = aSMESHDS_Mesh->MinElementID();
2468 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
2470 // aResult->length(aMaxId - aMinId + 1);
2472 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
2473 // aResult[i++] = id;
2475 // return aResult._retn();
2477 return GetElementsId();
2480 //=============================================================================
2484 //=============================================================================
2486 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
2487 throw (SALOME::SALOME_Exception)
2489 Unexpect aCatch(SALOME_SalomeException);
2490 MESSAGE("SMESH_Mesh_i::GetElementsId");
2491 SMESH::long_array_var aResult = new SMESH::long_array();
2492 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2494 if ( aSMESHDS_Mesh == NULL )
2495 return aResult._retn();
2497 long nbElements = NbElements();
2498 aResult->length( nbElements );
2499 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
2500 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
2501 aResult[i] = anIt->next()->GetID();
2503 return aResult._retn();
2507 //=============================================================================
2511 //=============================================================================
2513 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
2514 throw (SALOME::SALOME_Exception)
2516 Unexpect aCatch(SALOME_SalomeException);
2517 MESSAGE("SMESH_subMesh_i::GetElementsByType");
2518 SMESH::long_array_var aResult = new SMESH::long_array();
2519 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2521 if ( aSMESHDS_Mesh == NULL )
2522 return aResult._retn();
2524 long nbElements = NbElements();
2526 // No sense in returning ids of elements along with ids of nodes:
2527 // when theElemType == SMESH::ALL, return node ids only if
2528 // there are no elements
2529 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
2530 return GetNodesId();
2532 aResult->length( nbElements );
2536 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
2537 while ( i < nbElements && anIt->more() ) {
2538 const SMDS_MeshElement* anElem = anIt->next();
2539 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
2540 aResult[i++] = anElem->GetID();
2543 aResult->length( i );
2545 return aResult._retn();
2548 //=============================================================================
2552 //=============================================================================
2554 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
2555 throw (SALOME::SALOME_Exception)
2557 Unexpect aCatch(SALOME_SalomeException);
2558 MESSAGE("SMESH_subMesh_i::GetNodesId");
2559 SMESH::long_array_var aResult = new SMESH::long_array();
2560 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2562 if ( aSMESHDS_Mesh == NULL )
2563 return aResult._retn();
2565 long nbNodes = NbNodes();
2566 aResult->length( nbNodes );
2567 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
2568 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
2569 aResult[i] = anIt->next()->GetID();
2571 return aResult._retn();
2574 //=============================================================================
2578 //=============================================================================
2580 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
2581 throw (SALOME::SALOME_Exception)
2583 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
2587 //=============================================================================
2589 * Returns ID of elements for given submesh
2591 //=============================================================================
2592 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
2593 throw (SALOME::SALOME_Exception)
2595 SMESH::long_array_var aResult = new SMESH::long_array();
2597 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2598 if(!SM) return aResult._retn();
2600 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2601 if(!SDSM) return aResult._retn();
2603 aResult->length(SDSM->NbElements());
2605 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2607 while ( eIt->more() ) {
2608 aResult[i++] = eIt->next()->GetID();
2611 return aResult._retn();
2615 //=============================================================================
2617 * Returns ID of nodes for given submesh
2618 * If param all==true - returns all nodes, else -
2619 * returns only nodes on shapes.
2621 //=============================================================================
2622 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
2623 throw (SALOME::SALOME_Exception)
2625 SMESH::long_array_var aResult = new SMESH::long_array();
2627 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2628 if(!SM) return aResult._retn();
2630 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2631 if(!SDSM) return aResult._retn();
2634 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
2635 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
2636 while ( nIt->more() ) {
2637 const SMDS_MeshNode* elem = nIt->next();
2638 theElems.insert( elem->GetID() );
2641 else { // all nodes of submesh elements
2642 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2643 while ( eIt->more() ) {
2644 const SMDS_MeshElement* anElem = eIt->next();
2645 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
2646 while ( nIt->more() ) {
2647 const SMDS_MeshElement* elem = nIt->next();
2648 theElems.insert( elem->GetID() );
2653 aResult->length(theElems.size());
2654 set<int>::iterator itElem;
2656 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
2657 aResult[i++] = *itElem;
2659 return aResult._retn();
2663 //=============================================================================
2665 * Returns type of elements for given submesh
2667 //=============================================================================
2668 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
2669 throw (SALOME::SALOME_Exception)
2671 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2672 if(!SM) return SMESH::ALL;
2674 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2675 if(!SDSM) return SMESH::ALL;
2677 if(SDSM->NbElements()==0)
2678 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
2680 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2681 const SMDS_MeshElement* anElem = eIt->next();
2682 return ( SMESH::ElementType ) anElem->GetType();
2686 //=============================================================================
2690 //=============================================================================
2692 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
2694 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
2696 MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
2701 //=============================================================================
2703 * Get XYZ coordinates of node as list of double
2704 * If there is not node for given ID - returns empty list
2706 //=============================================================================
2708 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2710 SMESH::double_array_var aResult = new SMESH::double_array();
2711 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2712 if ( aSMESHDS_Mesh == NULL )
2713 return aResult._retn();
2716 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2718 return aResult._retn();
2722 aResult[0] = aNode->X();
2723 aResult[1] = aNode->Y();
2724 aResult[2] = aNode->Z();
2725 return aResult._retn();
2729 //=============================================================================
2731 * For given node returns list of IDs of inverse elements
2732 * If there is not node for given ID - returns empty list
2734 //=============================================================================
2736 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2738 SMESH::long_array_var aResult = new SMESH::long_array();
2739 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2740 if ( aSMESHDS_Mesh == NULL )
2741 return aResult._retn();
2744 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2746 return aResult._retn();
2748 // find inverse elements
2749 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2750 TColStd_SequenceOfInteger IDs;
2751 while(eIt->more()) {
2752 const SMDS_MeshElement* elem = eIt->next();
2753 IDs.Append(elem->GetID());
2755 if(IDs.Length()>0) {
2756 aResult->length(IDs.Length());
2758 for(; i<=IDs.Length(); i++) {
2759 aResult[i-1] = IDs.Value(i);
2762 return aResult._retn();
2765 //=============================================================================
2767 * \brief Return position of a node on shape
2769 //=============================================================================
2771 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
2773 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
2774 aNodePosition->shapeID = 0;
2775 aNodePosition->shapeType = GEOM::SHAPE;
2777 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
2778 if ( !mesh ) return aNodePosition;
2780 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
2782 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
2784 aNodePosition->shapeID = pos->GetShapeId();
2785 switch ( pos->GetTypeOfPosition() ) {
2787 aNodePosition->shapeType = GEOM::EDGE;
2788 aNodePosition->params.length(1);
2789 aNodePosition->params[0] =
2790 static_cast<SMDS_EdgePosition*>( pos.get() )->GetUParameter();
2793 aNodePosition->shapeType = GEOM::FACE;
2794 aNodePosition->params.length(2);
2795 aNodePosition->params[0] =
2796 static_cast<SMDS_FacePosition*>( pos.get() )->GetUParameter();
2797 aNodePosition->params[1] =
2798 static_cast<SMDS_FacePosition*>( pos.get() )->GetVParameter();
2800 case SMDS_TOP_VERTEX:
2801 aNodePosition->shapeType = GEOM::VERTEX;
2803 case SMDS_TOP_3DSPACE:
2804 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
2805 aNodePosition->shapeType = GEOM::SOLID;
2806 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
2807 aNodePosition->shapeType = GEOM::SHELL;
2813 return aNodePosition;
2816 //=============================================================================
2818 * If given element is node returns IDs of shape from position
2819 * If there is not node for given ID - returns -1
2821 //=============================================================================
2823 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2825 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2826 if ( aSMESHDS_Mesh == NULL )
2830 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2832 SMDS_PositionPtr pos = aNode->GetPosition();
2836 return pos->GetShapeId();
2843 //=============================================================================
2845 * For given element returns ID of result shape after
2846 * ::FindShape() from SMESH_MeshEditor
2847 * If there is not element for given ID - returns -1
2849 //=============================================================================
2851 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2853 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2854 if ( aSMESHDS_Mesh == NULL )
2857 // try to find element
2858 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2862 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2863 ::SMESH_MeshEditor aMeshEditor(_impl);
2864 int index = aMeshEditor.FindShape( elem );
2872 //=============================================================================
2874 * Returns number of nodes for given element
2875 * If there is not element for given ID - returns -1
2877 //=============================================================================
2879 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2881 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2882 if ( aSMESHDS_Mesh == NULL ) return -1;
2883 // try to find element
2884 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2885 if(!elem) return -1;
2886 return elem->NbNodes();
2890 //=============================================================================
2892 * Returns ID of node by given index for given element
2893 * If there is not element for given ID - returns -1
2894 * If there is not node for given index - returns -2
2896 //=============================================================================
2898 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2900 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2901 if ( aSMESHDS_Mesh == NULL ) return -1;
2902 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2903 if(!elem) return -1;
2904 if( index>=elem->NbNodes() || index<0 ) return -1;
2905 return elem->GetNode(index)->GetID();
2908 //=============================================================================
2910 * Returns IDs of nodes of given element
2912 //=============================================================================
2914 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2916 SMESH::long_array_var aResult = new SMESH::long_array();
2917 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2919 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2921 aResult->length( elem->NbNodes() );
2922 for ( int i = 0; i < elem->NbNodes(); ++i )
2923 aResult[ i ] = elem->GetNode( i )->GetID();
2926 return aResult._retn();
2929 //=============================================================================
2931 * Returns true if given node is medium node
2932 * in given quadratic element
2934 //=============================================================================
2936 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2938 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2939 if ( aSMESHDS_Mesh == NULL ) return false;
2941 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2942 if(!aNode) return false;
2943 // try to find element
2944 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2945 if(!elem) return false;
2947 return elem->IsMediumNode(aNode);
2951 //=============================================================================
2953 * Returns true if given node is medium node
2954 * in one of quadratic elements
2956 //=============================================================================
2958 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2959 SMESH::ElementType theElemType)
2961 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2962 if ( aSMESHDS_Mesh == NULL ) return false;
2965 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2966 if(!aNode) return false;
2968 SMESH_MesherHelper aHelper( *(_impl) );
2970 SMDSAbs_ElementType aType;
2971 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2972 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2973 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2974 else aType = SMDSAbs_All;
2976 return aHelper.IsMedium(aNode,aType);
2980 //=============================================================================
2982 * Returns number of edges for given element
2984 //=============================================================================
2986 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2988 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2989 if ( aSMESHDS_Mesh == NULL ) return -1;
2990 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2991 if(!elem) return -1;
2992 return elem->NbEdges();
2996 //=============================================================================
2998 * Returns number of faces for given element
3000 //=============================================================================
3002 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
3004 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3005 if ( aSMESHDS_Mesh == NULL ) return -1;
3006 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3007 if(!elem) return -1;
3008 return elem->NbFaces();
3012 //=============================================================================
3014 * Returns true if given element is polygon
3016 //=============================================================================
3018 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
3020 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3021 if ( aSMESHDS_Mesh == NULL ) return false;
3022 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3023 if(!elem) return false;
3024 return elem->IsPoly();
3028 //=============================================================================
3030 * Returns true if given element is quadratic
3032 //=============================================================================
3034 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
3036 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3037 if ( aSMESHDS_Mesh == NULL ) return false;
3038 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3039 if(!elem) return false;
3040 return elem->IsQuadratic();
3044 //=============================================================================
3046 * Returns bary center for given element
3048 //=============================================================================
3050 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
3052 SMESH::double_array_var aResult = new SMESH::double_array();
3053 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3054 if ( aSMESHDS_Mesh == NULL )
3055 return aResult._retn();
3057 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3059 return aResult._retn();
3061 if(elem->GetType()==SMDSAbs_Volume) {
3062 SMDS_VolumeTool aTool;
3063 if(aTool.Set(elem)) {
3065 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
3070 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
3072 double x=0., y=0., z=0.;
3073 for(; anIt->more(); ) {
3075 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
3089 return aResult._retn();
3093 //=============================================================================
3095 * Create and publish group servants if any groups were imported or created anyhow
3097 //=============================================================================
3099 void SMESH_Mesh_i::CreateGroupServants()
3101 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
3103 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
3104 while ( groupIt->more() )
3106 ::SMESH_Group* group = groupIt->next();
3107 int anId = group->GetGroupDS()->GetID();
3109 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
3110 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
3113 SMESH_GroupBase_i* aGroupImpl;
3115 if ( SMESHDS_GroupOnGeom* groupOnGeom =
3116 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
3118 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
3119 shape = groupOnGeom->GetShape();
3122 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
3125 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
3126 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
3127 aGroupImpl->Register();
3129 SMESH::SMESH_GroupBase_var groupVar =
3130 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
3131 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
3133 // register CORBA object for persistence
3134 int nextId = _gen_i->RegisterObject( groupVar );
3135 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
3137 // publishing of the groups in the study
3138 if ( !aStudy->_is_nil() ) {
3139 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
3140 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
3145 //=============================================================================
3147 * \brief Return groups cantained in _mapGroups by their IDs
3149 //=============================================================================
3151 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
3153 int nbGroups = groupIDs.size();
3154 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
3155 aList->length( nbGroups );
3157 list<int>::const_iterator ids = groupIDs.begin();
3158 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
3160 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
3161 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
3162 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
3164 aList->length( nbGroups );
3165 return aList._retn();
3168 //=============================================================================
3170 * \brief Return information about imported file
3172 //=============================================================================
3174 SALOME_MED::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
3176 SALOME_MED::MedFileInfo_var res( myFileInfo );
3177 if ( !res.operator->() ) {
3178 res = new SALOME_MED::MedFileInfo;
3180 res->fileSize = res->major = res->minor = res->release = -1;
3185 //=============================================================================
3187 * \brief Check and correct names of mesh groups
3189 //=============================================================================
3191 void SMESH_Mesh_i::checkGroupNames()
3193 int nbGrp = NbGroups();
3197 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
3198 if ( aStudy->_is_nil() )
3199 return; // nothing to do
3201 SMESH::ListOfGroups* grpList = 0;
3202 // avoid dump of "GetGroups"
3204 // store python dump into a local variable inside local scope
3205 SMESH::TPythonDump pDump; // do not delete this line of code
3206 grpList = GetGroups();
3209 for ( int gIndx = 0; gIndx < nbGrp; gIndx++ ) {
3210 SMESH::SMESH_GroupBase_ptr aGrp = (*grpList)[ gIndx ];
3213 SALOMEDS::SObject_var aGrpSO = _gen_i->ObjectToSObject( aStudy, aGrp );
3214 if ( aGrpSO->_is_nil() )
3216 // correct name of the mesh group if necessary
3217 const char* guiName = aGrpSO->GetName();
3218 if ( strcmp(guiName, aGrp->GetName()) )
3219 aGrp->SetName( guiName );
3223 //=============================================================================
3225 * \brief Sets list of notebook variables used for Mesh operations separated by ":" symbol
3227 //=============================================================================
3228 void SMESH_Mesh_i::SetParameters(const char* theParameters)
3230 SMESH_Gen_i::GetSMESHGen()->UpdateParameters(SMESH::SMESH_Mesh::_narrow(_this()),
3231 CORBA::string_dup(theParameters));
3234 //=============================================================================
3236 * \brief Returns list of notebook variables used for Mesh operations separated by ":" symbol
3238 //=============================================================================
3239 char* SMESH_Mesh_i::GetParameters()
3241 SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
3242 return CORBA::string_dup(gen->GetParameters(SMESH::SMESH_Mesh::_narrow(_this())));
3245 //=============================================================================
3247 * \brief Returns list of notebook variables used for last Mesh operation
3249 //=============================================================================
3250 SMESH::string_array* SMESH_Mesh_i::GetLastParameters()
3252 SMESH::string_array_var aResult = new SMESH::string_array();
3253 SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
3255 char *aParameters = GetParameters();
3256 SALOMEDS::Study_ptr aStudy = gen->GetCurrentStudy();
3257 if(!aStudy->_is_nil()) {
3258 SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters);
3259 if(aSections->length() > 0) {
3260 SALOMEDS::ListOfStrings aVars = aSections[aSections->length()-1];
3261 aResult->length(aVars.length());
3262 for(int i = 0;i < aVars.length();i++)
3263 aResult[i] = CORBA::string_dup( aVars[i]);
3267 return aResult._retn();