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 (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 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
580 int i = 0, n = aLocalList.size();
583 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
584 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
585 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
586 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
591 catch(SALOME_Exception & S_ex) {
592 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
595 return aList._retn();
598 //=============================================================================
602 //=============================================================================
603 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
604 const char* theName )
605 throw(SALOME::SALOME_Exception)
607 Unexpect aCatch(SALOME_SalomeException);
608 MESSAGE("SMESH_Mesh_i::GetSubMesh");
609 if (CORBA::is_nil(aSubShapeObject))
610 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
613 SMESH::SMESH_subMesh_var subMesh;
614 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
616 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
618 //Get or Create the SMESH_subMesh object implementation
620 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
621 subMesh = getSubMesh( subMeshId );
623 // create a new subMesh object servant if there is none for the shape
624 if ( subMesh->_is_nil() )
625 subMesh = createSubMesh( aSubShapeObject );
626 if ( _gen_i->CanPublishInStudy( subMesh )) {
627 SALOMEDS::SObject_var aSO =
628 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
629 subMesh, aSubShapeObject, theName );
630 if ( !aSO->_is_nil()) {
631 // Update Python script
632 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
633 << aSubShapeObject << ", '" << theName << "' )";
637 catch(SALOME_Exception & S_ex) {
638 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
640 return subMesh._retn();
643 //=============================================================================
647 //=============================================================================
649 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
650 throw (SALOME::SALOME_Exception)
652 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
653 if ( theSubMesh->_is_nil() )
656 GEOM::GEOM_Object_var aSubShapeObject;
657 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
658 if ( !aStudy->_is_nil() ) {
659 // Remove submesh's SObject
660 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
661 if ( !anSO->_is_nil() ) {
662 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
663 SALOMEDS::SObject_var anObj, aRef;
664 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
665 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
667 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
669 // Update Python script
670 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
674 removeSubMesh( theSubMesh, aSubShapeObject.in() );
677 //=============================================================================
681 //=============================================================================
682 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
683 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
685 switch (theElemType) {
690 CASE2STRING( VOLUME );
696 //=============================================================================
700 //=============================================================================
702 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
703 const char* theName )
704 throw(SALOME::SALOME_Exception)
706 Unexpect aCatch(SALOME_SalomeException);
707 SMESH::SMESH_Group_var aNewGroup =
708 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
710 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
711 SALOMEDS::SObject_var aSO =
712 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
713 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
714 if ( !aSO->_is_nil()) {
715 // Update Python script
716 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
717 << ElementTypeString(theElemType) << ", '" << theName << "' )";
720 return aNewGroup._retn();
724 //=============================================================================
728 //=============================================================================
729 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
731 GEOM::GEOM_Object_ptr theGeomObj)
732 throw(SALOME::SALOME_Exception)
734 Unexpect aCatch(SALOME_SalomeException);
735 SMESH::SMESH_GroupOnGeom_var aNewGroup;
737 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
738 if ( !aShape.IsNull() )
740 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
741 ( createGroup( theElemType, theName, aShape ));
743 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
744 SALOMEDS::SObject_var aSO =
745 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
746 aNewGroup, theGeomObj, theName);
747 if ( !aSO->_is_nil()) {
748 // Update Python script
749 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
750 << ElementTypeString(theElemType) << ", '" << theName << "', "
751 << theGeomObj << " )";
756 return aNewGroup._retn();
759 //=============================================================================
763 //=============================================================================
765 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
766 throw (SALOME::SALOME_Exception)
768 if ( theGroup->_is_nil() )
771 SMESH_GroupBase_i* aGroup =
772 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
776 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
777 if ( !aStudy->_is_nil() ) {
778 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
780 if ( !aGroupSO->_is_nil() ) {
781 // Update Python script
782 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
784 // Remove group's SObject
785 aStudy->NewBuilder()->RemoveObjectWithChildren( aGroupSO );
789 // Remove the group from SMESH data structures
790 removeGroup( aGroup->GetLocalID() );
793 //=============================================================================
794 /*! RemoveGroupWithContents
795 * Remove group with its contents
797 //=============================================================================
798 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
799 throw (SALOME::SALOME_Exception)
801 if ( theGroup->_is_nil() )
804 SMESH_GroupBase_i* aGroup =
805 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
809 SMESH::long_array_var anIds = aGroup->GetListOfID();
810 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
812 // Update Python script
813 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
816 if ( aGroup->GetType() == SMESH::NODE )
817 aMeshEditor->RemoveNodes( anIds );
819 aMeshEditor->RemoveElements( anIds );
822 RemoveGroup( theGroup );
824 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
825 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
826 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
830 //================================================================================
832 * \brief Get the list of groups existing in the mesh
833 * \retval SMESH::ListOfGroups * - list of groups
835 //================================================================================
837 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
839 Unexpect aCatch(SALOME_SalomeException);
840 if (MYDEBUG) MESSAGE("GetGroups");
842 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
845 TPythonDump aPythonDump;
846 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
850 aList->length( _mapGroups.size() );
852 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
853 for ( ; it != _mapGroups.end(); it++ ) {
854 if ( CORBA::is_nil( it->second )) continue;
855 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
857 if (i > 1) aPythonDump << ", ";
858 aPythonDump << it->second;
862 catch(SALOME_Exception & S_ex) {
863 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
866 // Update Python script
867 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
868 aPythonDump << " ] = " << _this() << ".GetGroups()";
870 return aList._retn();
872 //=============================================================================
874 * Get number of groups existing in the mesh
876 //=============================================================================
878 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
880 Unexpect aCatch(SALOME_SalomeException);
881 return _mapGroups.size();
884 //=============================================================================
886 * New group is created. All mesh elements that are
887 * present in initial groups are added to the new one
889 //=============================================================================
890 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
891 SMESH::SMESH_GroupBase_ptr theGroup2,
892 const char* theName )
893 throw (SALOME::SALOME_Exception)
897 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
898 theGroup1->GetType() != theGroup2->GetType() )
899 return SMESH::SMESH_Group::_nil();
902 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
903 if ( aResGrp->_is_nil() )
904 return SMESH::SMESH_Group::_nil();
906 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
907 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
909 TColStd_MapOfInteger aResMap;
911 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
912 aResMap.Add( anIds1[ i1 ] );
914 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
915 aResMap.Add( anIds2[ i2 ] );
917 SMESH::long_array_var aResIds = new SMESH::long_array;
918 aResIds->length( aResMap.Extent() );
921 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
922 for( ; anIter.More(); anIter.Next() )
923 aResIds[ resI++ ] = anIter.Key();
925 aResGrp->Add( aResIds );
927 // Clear python lines, created by CreateGroup() and Add()
928 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
929 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
930 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
932 // Update Python script
933 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
934 << theGroup1 << ", " << theGroup2 << ", '"
937 return aResGrp._retn();
941 return SMESH::SMESH_Group::_nil();
945 //=============================================================================
947 \brief Union list of groups. New group is created. All mesh elements that are
948 present in initial groups are added to the new one.
949 \param theGroups list of groups
950 \param theName name of group to be created
951 \return pointer on the group
953 //=============================================================================
954 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionListOfGroups(const SMESH::ListOfGroups& theGroups,
955 const char* theName )
956 throw (SALOME::SALOME_Exception)
959 return SMESH::SMESH_Group::_nil();
963 NCollection_Map< int > anIds;
964 SMESH::ElementType aType = SMESH::ALL;
965 for ( int g = 0, n = theGroups.length(); g < n; g++ )
967 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
968 if ( CORBA::is_nil( aGrp ) )
972 SMESH::ElementType aCurrType = aGrp->GetType();
973 if ( aType == SMESH::ALL )
977 if ( aType != aCurrType )
978 return SMESH::SMESH_Group::_nil();
982 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
983 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
985 int aCurrId = aCurrIds[ i ];
986 anIds.Add( aCurrId );
991 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
992 if ( aResGrp->_is_nil() )
993 return SMESH::SMESH_Group::_nil();
995 // Create array of identifiers
996 SMESH::long_array_var aResIds = new SMESH::long_array;
997 aResIds->length( anIds.Extent() );
999 NCollection_Map< int >::Iterator anIter( anIds );
1000 for ( int i = 0; anIter.More(); anIter.Next(), i++ )
1002 aResIds[ i ] = anIter.Value();
1004 aResGrp->Add( aResIds );
1006 // Clear python lines, created by CreateGroup() and Add()
1007 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1008 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1009 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1011 // Update Python script
1013 TPythonDump() << aResGrp << " = " << _this() << ".UnionListOfGroups( "
1014 << &theGroups << ", '" << theName << "' )";
1016 return aResGrp._retn();
1020 return SMESH::SMESH_Group::_nil();
1024 //=============================================================================
1026 * New group is created. All mesh elements that are
1027 * present in both initial groups are added to the new one.
1029 //=============================================================================
1030 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1031 SMESH::SMESH_GroupBase_ptr theGroup2,
1032 const char* theName )
1033 throw (SALOME::SALOME_Exception)
1035 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
1036 theGroup1->GetType() != theGroup2->GetType() )
1037 return SMESH::SMESH_Group::_nil();
1039 // Create Intersection
1040 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
1041 if ( aResGrp->_is_nil() )
1044 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
1045 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1047 TColStd_MapOfInteger aMap1;
1049 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1050 aMap1.Add( anIds1[ i1 ] );
1052 TColStd_SequenceOfInteger aSeq;
1054 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1055 if ( aMap1.Contains( anIds2[ i2 ] ) )
1056 aSeq.Append( anIds2[ i2 ] );
1058 SMESH::long_array_var aResIds = new SMESH::long_array;
1059 aResIds->length( aSeq.Length() );
1061 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1062 aResIds[ resI ] = aSeq( resI + 1 );
1064 aResGrp->Add( aResIds );
1066 // Clear python lines, created by CreateGroup() and Add()
1067 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1068 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1069 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1071 // Update Python script
1072 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
1073 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
1075 return aResGrp._retn();
1078 //=============================================================================
1080 \brief Intersect list of groups. New group is created. All mesh elements that
1081 are present in all initial groups simultaneously are added to the new one.
1082 \param theGroups list of groups
1083 \param theName name of group to be created
1084 \return pointer on the group
1086 //=============================================================================
1087 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectListOfGroups(
1088 const SMESH::ListOfGroups& theGroups, const char* theName )
1089 throw (SALOME::SALOME_Exception)
1092 return SMESH::SMESH_Group::_nil();
1096 NCollection_DataMap< int, int > anIdToCount;
1097 SMESH::ElementType aType = SMESH::ALL;
1098 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1100 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1101 if ( CORBA::is_nil( aGrp ) )
1105 SMESH::ElementType aCurrType = aGrp->GetType();
1106 if ( aType == SMESH::ALL )
1110 if ( aType != aCurrType )
1111 return SMESH::SMESH_Group::_nil();
1114 // calculates number of occurance ids in groups
1115 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1116 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1118 int aCurrId = aCurrIds[ i ];
1119 if ( !anIdToCount.IsBound( aCurrId ) )
1120 anIdToCount.Bind( aCurrId, 1 );
1122 anIdToCount( aCurrId ) = anIdToCount( aCurrId ) + 1;
1126 // create map of ids
1127 int nbGrp = theGroups.length();
1128 NCollection_Map< int > anIds;
1129 NCollection_DataMap< int, int >::Iterator anIter( anIdToCount );
1130 for ( ; anIter.More(); anIter.Next() )
1132 int aCurrId = anIter.Key();
1133 int aCurrNb = anIter.Value();
1134 if ( aCurrNb == nbGrp )
1135 anIds.Add( aCurrId );
1139 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
1140 if ( aResGrp->_is_nil() )
1141 return SMESH::SMESH_Group::_nil();
1143 // Create array of identifiers
1144 SMESH::long_array_var aResIds = new SMESH::long_array;
1145 aResIds->length( anIds.Extent() );
1147 NCollection_Map< int >::Iterator aListIter( anIds );
1148 for ( int i = 0; aListIter.More(); aListIter.Next(), i++ )
1150 aResIds[ i ] = aListIter.Value();
1152 aResGrp->Add( aResIds );
1154 // Clear python lines, created by CreateGroup() and Add()
1155 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1156 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1157 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1159 // Update Python script
1161 TPythonDump() << aResGrp << " = " << _this() << ".IntersectListOfGroups( "
1162 << &theGroups << ", '" << theName << "' )";
1164 return aResGrp._retn();
1168 return SMESH::SMESH_Group::_nil();
1172 //=============================================================================
1174 * New group is created. All mesh elements that are present in
1175 * main group but do not present in tool group are added to the new one
1177 //=============================================================================
1178 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1179 SMESH::SMESH_GroupBase_ptr theGroup2,
1180 const char* theName )
1181 throw (SALOME::SALOME_Exception)
1183 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
1184 theGroup1->GetType() != theGroup2->GetType() )
1185 return SMESH::SMESH_Group::_nil();
1188 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
1189 if ( aResGrp->_is_nil() )
1192 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
1193 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1195 TColStd_MapOfInteger aMap2;
1197 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1198 aMap2.Add( anIds2[ i2 ] );
1200 TColStd_SequenceOfInteger aSeq;
1201 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1202 if ( !aMap2.Contains( anIds1[ i1 ] ) )
1203 aSeq.Append( anIds1[ i1 ] );
1205 SMESH::long_array_var aResIds = new SMESH::long_array;
1206 aResIds->length( aSeq.Length() );
1208 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1209 aResIds[ resI ] = aSeq( resI + 1 );
1211 aResGrp->Add( aResIds );
1213 // Clear python lines, created by CreateGroup() and Add()
1214 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1215 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1216 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1218 // Update Python script
1219 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
1220 << theGroup1 << ", " << theGroup2 << ", '"
1221 << theName << "' )";
1223 return aResGrp._retn();
1226 //=============================================================================
1228 \brief Cut lists of groups. New group is created. All mesh elements that are
1229 present in main groups but do not present in tool groups are added to the new one
1230 \param theMainGroups list of main groups
1231 \param theToolGroups list of tool groups
1232 \param theName name of group to be created
1233 \return pointer on the group
1235 //=============================================================================
1236 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutListOfGroups(
1237 const SMESH::ListOfGroups& theMainGroups,
1238 const SMESH::ListOfGroups& theToolGroups,
1239 const char* theName )
1240 throw (SALOME::SALOME_Exception)
1243 return SMESH::SMESH_Group::_nil();
1247 NCollection_Map< int > aToolIds;
1248 SMESH::ElementType aType = SMESH::ALL;
1250 // iterate through tool groups
1251 for ( g = 0, n = theToolGroups.length(); g < n; g++ )
1253 SMESH::SMESH_GroupBase_var aGrp = theToolGroups[ g ];
1254 if ( CORBA::is_nil( aGrp ) )
1258 SMESH::ElementType aCurrType = aGrp->GetType();
1259 if ( aType == SMESH::ALL )
1263 if ( aType != aCurrType )
1264 return SMESH::SMESH_Group::_nil();
1268 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1269 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1271 int aCurrId = aCurrIds[ i ];
1272 aToolIds.Add( aCurrId );
1276 NCollection_Map< int > anIds; // result
1278 // Iterate through main group
1279 for ( g = 0, n = theMainGroups.length(); g < n; g++ )
1281 SMESH::SMESH_GroupBase_var aGrp = theMainGroups[ g ];
1282 if ( CORBA::is_nil( aGrp ) )
1286 SMESH::ElementType aCurrType = aGrp->GetType();
1287 if ( aType == SMESH::ALL )
1291 if ( aType != aCurrType )
1292 return SMESH::SMESH_Group::_nil();
1296 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1297 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1299 int aCurrId = aCurrIds[ i ];
1300 if ( !aToolIds.Contains( aCurrId ) )
1301 anIds.Add( aCurrId );
1306 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
1307 if ( aResGrp->_is_nil() )
1308 return SMESH::SMESH_Group::_nil();
1310 // Create array of identifiers
1311 SMESH::long_array_var aResIds = new SMESH::long_array;
1312 aResIds->length( anIds.Extent() );
1314 NCollection_Map< int >::Iterator anIter( anIds );
1315 for ( int i = 0; anIter.More(); anIter.Next(), i++ )
1317 aResIds[ i ] = anIter.Value();
1319 aResGrp->Add( aResIds );
1321 // Clear python lines, created by CreateGroup() and Add()
1322 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1323 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1324 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1326 // Update Python script
1328 TPythonDump() << aResGrp << " = " << _this() << ".CutListOfGroups( "
1329 << &theMainGroups << ", " << &theToolGroups << ", '"
1330 << theName << "' )";
1332 return aResGrp._retn();
1336 return SMESH::SMESH_Group::_nil();
1340 //=============================================================================
1342 \brief Create groups of entities from existing groups of superior dimensions
1344 1) extract all nodes from each group,
1345 2) combine all elements of specified dimension laying on these nodes.
1346 \param theGroups list of source groups
1347 \param theElemType dimension of elements
1348 \param theName name of new group
1349 \return pointer on new group
1351 //=============================================================================
1352 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateDimGroup(
1353 const SMESH::ListOfGroups& theGroups,
1354 SMESH::ElementType theElemType,
1355 const char* theName )
1356 throw (SALOME::SALOME_Exception)
1358 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
1360 if ( !theName || !aMeshDS )
1361 return SMESH::SMESH_Group::_nil();
1363 SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)theElemType;
1367 // Create map of nodes from all groups
1369 NCollection_Map< int > aNodeMap;
1371 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1373 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1374 if ( CORBA::is_nil( aGrp ) )
1377 SMESH::ElementType aType = aGrp->GetType();
1378 if ( aType == SMESH::ALL )
1380 else if ( aType == SMESH::NODE )
1382 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1383 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1385 int aCurrId = aCurrIds[ i ];
1386 const SMDS_MeshNode* aNode = aMeshDS->FindNode( aCurrId );
1388 aNodeMap.Add( aNode->GetID() );
1393 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1394 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1396 int aCurrId = aCurrIds[ i ];
1397 const SMDS_MeshElement* anElem = aMeshDS->FindElement( aCurrId );
1400 SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator();
1401 while( aNodeIter->more() )
1403 const SMDS_MeshNode* aNode =
1404 dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() );
1406 aNodeMap.Add( aNode->GetID() );
1412 // Get result identifiers
1414 NCollection_Map< int > aResultIds;
1415 if ( theElemType == SMESH::NODE )
1417 NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
1418 for ( ; aNodeIter.More(); aNodeIter.Next() )
1419 aResultIds.Add( aNodeIter.Value() );
1423 // Create list of elements of given dimension constructed on the nodes
1424 NCollection_Map< int > anElemList;
1425 NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
1426 for ( ; aNodeIter.More(); aNodeIter.Next() )
1428 const SMDS_MeshElement* aNode =
1429 dynamic_cast<const SMDS_MeshElement*>( aMeshDS->FindNode( aNodeIter.Value() ) );
1433 SMDS_ElemIteratorPtr anElemIter = aNode->elementsIterator( anElemType );
1434 while( anElemIter->more() )
1436 const SMDS_MeshElement* anElem =
1437 dynamic_cast<const SMDS_MeshElement*>( anElemIter->next() );
1438 if ( anElem && anElem->GetType() == anElemType )
1439 anElemList.Add( anElem->GetID() );
1443 // check whether all nodes of elements are present in nodes map
1444 NCollection_Map< int >::Iterator anIter( anElemList );
1445 for ( ; anIter.More(); anIter.Next() )
1447 const SMDS_MeshElement* anElem = aMeshDS->FindElement( anIter.Value() );
1452 SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator();
1453 while( aNodeIter->more() )
1455 const SMDS_MeshNode* aNode =
1456 dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() );
1457 if ( !aNode || !aNodeMap.Contains( aNode->GetID() ) )
1464 aResultIds.Add( anElem->GetID() );
1470 SMESH::SMESH_Group_var aResGrp = CreateGroup( theElemType, theName );
1471 if ( aResGrp->_is_nil() )
1472 return SMESH::SMESH_Group::_nil();
1474 // Create array of identifiers
1475 SMESH::long_array_var aResIds = new SMESH::long_array;
1476 aResIds->length( aResultIds.Extent() );
1478 NCollection_Map< int >::Iterator aResIter( aResultIds );
1479 for ( int i = 0; aResIter.More(); aResIter.Next(), i++ )
1480 aResIds[ i ] = aResIter.Value();
1481 aResGrp->Add( aResIds );
1483 // Remove strings corresponding to group creation
1484 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1485 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1486 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1488 // Update Python script
1490 TPythonDump() << aResGrp << " = " << _this() << ".CreateDimGroup( "
1491 << &theGroups << ", " << theElemType << ", '" << theName << "' )";
1493 return aResGrp._retn();
1497 return SMESH::SMESH_Group::_nil();
1501 //================================================================================
1503 * \brief Remember GEOM group data
1505 //================================================================================
1507 void SMESH_Mesh_i::addGeomGroupData(GEOM::GEOM_Object_ptr theGeomObj,
1508 CORBA::Object_ptr theSmeshObj)
1510 if ( CORBA::is_nil( theGeomObj ) || theGeomObj->GetType() != GEOM_GROUP )
1513 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1514 SALOMEDS::SObject_var groupSO = _gen_i->ObjectToSObject( study, theGeomObj );
1515 if ( groupSO->_is_nil() )
1518 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
1519 GEOM::GEOM_IGroupOperations_var groupOp =
1520 geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
1521 GEOM::ListOfLong_var ids = groupOp->GetObjects( theGeomObj );
1524 _geomGroupData.push_back( TGeomGroupData() );
1525 TGeomGroupData & groupData = _geomGroupData.back();
1527 CORBA::String_var entry = groupSO->GetID();
1528 groupData._groupEntry = entry.in();
1530 for ( int i = 0; i < ids->length(); ++i )
1531 groupData._indices.insert( ids[i] );
1533 groupData._smeshObject = theSmeshObj;
1536 //================================================================================
1538 * Remove GEOM group data relating to removed smesh object
1540 //================================================================================
1542 void SMESH_Mesh_i::removeGeomGroupData(CORBA::Object_ptr theSmeshObj)
1544 list<TGeomGroupData>::iterator
1545 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
1546 for ( ; data != dataEnd; ++data ) {
1547 if ( theSmeshObj->_is_equivalent( data->_smeshObject )) {
1548 _geomGroupData.erase( data );
1554 //================================================================================
1556 * \brief Return new group contents if it has been changed and update group data
1558 //================================================================================
1560 TopoDS_Shape SMESH_Mesh_i::newGroupShape( TGeomGroupData & groupData)
1562 TopoDS_Shape newShape;
1565 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1566 if ( study->_is_nil() ) return newShape; // means "not changed"
1567 SALOMEDS::SObject_var groupSO = study->FindObjectID( groupData._groupEntry.c_str() );
1568 if ( !groupSO->_is_nil() )
1570 CORBA::Object_var groupObj = _gen_i->SObjectToObject( groupSO );
1571 if ( CORBA::is_nil( groupObj )) return newShape;
1572 GEOM::GEOM_Object_var geomGroup = GEOM::GEOM_Object::_narrow( groupObj );
1574 // get indices of group items
1575 set<int> curIndices;
1576 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
1577 GEOM::GEOM_IGroupOperations_var groupOp =
1578 geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
1579 GEOM::ListOfLong_var ids = groupOp->GetObjects( geomGroup );
1580 for ( int i = 0; i < ids->length(); ++i )
1581 curIndices.insert( ids[i] );
1583 if ( groupData._indices == curIndices )
1584 return newShape; // group not changed
1587 groupData._indices = curIndices;
1589 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1590 if ( !geomClient ) return newShape;
1591 TCollection_AsciiString groupIOR = geomGen->GetStringFromIOR( geomGroup );
1592 geomClient->RemoveShapeFromBuffer( groupIOR );
1593 newShape = _gen_i->GeomObjectToShape( geomGroup );
1596 if ( newShape.IsNull() ) {
1597 // geom group becomes empty - return empty compound
1598 TopoDS_Compound compound;
1599 BRep_Builder builder;
1600 builder.MakeCompound(compound);
1601 newShape = compound;
1606 //=============================================================================
1608 * \brief Update objects depending on changed geom groups
1610 * NPAL16168: geometrical group edition from a submesh don't modifiy mesh computation
1611 * issue 0020210: Update of a smesh group after modification of the associated geom group
1613 //=============================================================================
1615 void SMESH_Mesh_i::CheckGeomGroupModif()
1617 if ( !_impl->HasShapeToMesh() ) return;
1619 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1620 if ( study->_is_nil() ) return;
1622 CORBA::Long nbEntities = NbNodes() + NbElements();
1624 // Check if group contents changed
1626 typedef map< string, TopoDS_Shape > TEntry2Geom;
1627 TEntry2Geom newGroupContents;
1629 list<TGeomGroupData>::iterator
1630 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
1631 for ( ; data != dataEnd; ++data )
1633 pair< TEntry2Geom::iterator, bool > it_new =
1634 newGroupContents.insert( make_pair( data->_groupEntry, TopoDS_Shape() ));
1635 bool processedGroup = !it_new.second;
1636 TopoDS_Shape& newShape = it_new.first->second;
1637 if ( !processedGroup )
1638 newShape = newGroupShape( *data );
1639 if ( newShape.IsNull() )
1640 continue; // no changes
1642 if ( processedGroup ) { // update group indices
1643 list<TGeomGroupData>::iterator data2 = data;
1644 for ( --data2; data2->_groupEntry != data->_groupEntry; --data2)
1645 data->_indices = data2->_indices;
1648 // Update SMESH objects according to new GEOM group contents
1650 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( data->_smeshObject );
1651 if ( !mesh->_is_nil() ) // -------------- MESH ----------------------------
1657 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( data->_smeshObject );
1658 if ( !submesh->_is_nil() ) // -------------- Sub mesh ---------------------
1660 int oldID = submesh->GetId();
1661 if ( _mapSubMeshIor.find( oldID ) == _mapSubMeshIor.end() )
1663 TopoDS_Shape oldShape = _mapSubMesh[oldID]->GetSubShape();
1665 // update hypotheses
1666 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldShape);
1667 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1668 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1670 _impl->RemoveHypothesis( oldShape, (*hypIt)->GetID());
1671 _impl->AddHypothesis ( newShape, (*hypIt)->GetID());
1673 // care of submeshes
1674 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newShape );
1675 int newID = newSubmesh->GetId();
1676 if ( newID != oldID ) {
1677 _mapSubMesh [ newID ] = newSubmesh;
1678 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1679 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1680 _mapSubMesh. erase(oldID);
1681 _mapSubMesh_i. erase(oldID);
1682 _mapSubMeshIor.erase(oldID);
1683 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1688 SMESH::SMESH_GroupOnGeom_var smeshGroup =
1689 SMESH::SMESH_GroupOnGeom::_narrow( data->_smeshObject );
1690 if ( !smeshGroup->_is_nil() ) // ------------ GROUP -----------------------
1692 SMESH_GroupOnGeom_i* group_i = SMESH::DownCast<SMESH_GroupOnGeom_i*>( smeshGroup );
1694 ::SMESH_Group* group = _impl->GetGroup( group_i->GetLocalID() );
1695 SMESHDS_GroupOnGeom* ds = static_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() );
1696 ds->SetShape( newShape );
1704 CORBA::Long newNbEntities = NbNodes() + NbElements();
1705 list< SALOMEDS::SObject_var > soToUpdateIcons;
1706 if ( newNbEntities != nbEntities )
1708 // Add all SObjects with icons
1709 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, _this() )); // mesh
1711 for (map<int, SMESH::SMESH_subMesh_ptr>::iterator i_sm = _mapSubMeshIor.begin();
1712 i_sm != _mapSubMeshIor.end(); ++i_sm ) // submeshes
1713 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_sm->second ));
1715 for ( map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_gr = _mapGroups.begin();
1716 i_gr != _mapGroups.end(); ++i_gr ) // groups
1717 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_gr->second ));
1720 list< SALOMEDS::SObject_var >::iterator so = soToUpdateIcons.begin();
1721 for ( ; so != soToUpdateIcons.end(); ++so )
1722 _gen_i->SetPixMap( *so, "ICON_SMESH_TREE_MESH_WARN" );
1725 //=============================================================================
1727 * \brief Create standalone group instead if group on geometry
1730 //=============================================================================
1732 SMESH::SMESH_Group_ptr SMESH_Mesh_i::ConvertToStandalone( SMESH::SMESH_GroupOnGeom_ptr theGroup )
1734 SMESH::SMESH_Group_var aGroup;
1735 if ( theGroup->_is_nil() )
1736 return aGroup._retn();
1738 Unexpect aCatch(SALOME_SalomeException);
1740 SMESH_GroupBase_i* aGroupToRem =
1741 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
1743 return aGroup._retn();
1745 int anId = aGroupToRem->GetLocalID();
1746 if ( !_impl->ConvertToStandalone( anId ) )
1747 return aGroup._retn();
1748 removeGeomGroupData( theGroup );
1750 SMESH_GroupBase_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1752 // remove old instance of group from own map
1753 _mapGroups.erase( anId );
1755 SALOMEDS::StudyBuilder_var builder;
1756 SALOMEDS::SObject_var aGroupSO;
1757 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1758 if ( !aStudy->_is_nil() ) {
1759 builder = aStudy->NewBuilder();
1760 aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
1761 if ( !aGroupSO->_is_nil() ) {
1763 // remove reference to geometry
1764 SALOMEDS::ChildIterator_var chItr = aStudy->NewChildIterator(aGroupSO);
1765 for ( ; chItr->More(); chItr->Next() )
1766 // Remove group's child SObject
1767 builder->RemoveObject( chItr->Value() );
1769 // Update Python script
1770 TPythonDump() << aGroupSO << " = " << _this() << ".ConvertToStandalone( "
1771 << aGroupSO << " )";
1775 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1776 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1777 aGroupImpl->Register();
1778 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1780 // remember new group in own map
1781 aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
1782 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1784 // register CORBA object for persistence
1785 //int nextId = _gen_i->RegisterObject( aGroup );
1786 //if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1787 builder->SetIOR( aGroupSO, _gen_i->GetORB()->object_to_string( aGroup ) );
1789 return aGroup._retn();
1792 //=============================================================================
1796 //=============================================================================
1798 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1800 if(MYDEBUG) MESSAGE( "createSubMesh" );
1801 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1803 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1804 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1805 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1806 SMESH::SMESH_subMesh_var subMesh
1807 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1809 _mapSubMesh[subMeshId] = mySubMesh;
1810 _mapSubMesh_i[subMeshId] = subMeshServant;
1811 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1813 // register CORBA object for persistence
1814 int nextId = _gen_i->RegisterObject( subMesh );
1815 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1817 // to track changes of GEOM groups
1818 addGeomGroupData( theSubShapeObject, subMesh );
1820 return subMesh._retn();
1823 //=======================================================================
1824 //function : getSubMesh
1826 //=======================================================================
1828 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1830 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1831 if ( it == _mapSubMeshIor.end() )
1832 return SMESH::SMESH_subMesh::_nil();
1834 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1838 //=============================================================================
1842 //=============================================================================
1844 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1845 GEOM::GEOM_Object_ptr theSubShapeObject )
1847 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1848 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1852 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1853 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1854 removeHypothesis( theSubShapeObject, aHypList[i] );
1857 catch( const SALOME::SALOME_Exception& ) {
1858 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1860 removeGeomGroupData( theSubShapeObject );
1862 int subMeshId = theSubMesh->GetId();
1864 _mapSubMesh.erase(subMeshId);
1865 _mapSubMesh_i.erase(subMeshId);
1866 _mapSubMeshIor.erase(subMeshId);
1867 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1870 //=============================================================================
1874 //=============================================================================
1876 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1877 const char* theName,
1878 const TopoDS_Shape& theShape )
1881 SMESH::SMESH_GroupBase_var aGroup;
1882 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1883 SMESH_GroupBase_i* aGroupImpl;
1884 if ( !theShape.IsNull() )
1885 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1887 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1889 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1890 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1891 aGroupImpl->Register();
1892 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1894 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1895 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1897 // register CORBA object for persistence
1898 int nextId = _gen_i->RegisterObject( aGroup );
1899 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1901 // to track changes of GEOM groups
1902 if ( !theShape.IsNull() ) {
1903 GEOM::GEOM_Object_var geom = _gen_i->ShapeToGeomObject( theShape );
1904 addGeomGroupData( geom, aGroup );
1907 return aGroup._retn();
1910 //=============================================================================
1912 * SMESH_Mesh_i::removeGroup
1914 * Should be called by ~SMESH_Group_i()
1916 //=============================================================================
1918 void SMESH_Mesh_i::removeGroup( const int theId )
1920 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1921 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1922 removeGeomGroupData( _mapGroups[theId] );
1923 _mapGroups.erase( theId );
1924 _impl->RemoveGroup( theId );
1929 //=============================================================================
1933 //=============================================================================
1935 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1936 throw(SALOME::SALOME_Exception)
1938 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1940 SMESH::log_array_var aLog;
1942 list < SMESHDS_Command * >logDS = _impl->GetLog();
1943 aLog = new SMESH::log_array;
1945 int lg = logDS.size();
1948 list < SMESHDS_Command * >::iterator its = logDS.begin();
1949 while(its != logDS.end()){
1950 SMESHDS_Command *com = *its;
1951 int comType = com->GetType();
1953 int lgcom = com->GetNumber();
1955 const list < int >&intList = com->GetIndexes();
1956 int inum = intList.size();
1958 list < int >::const_iterator ii = intList.begin();
1959 const list < double >&coordList = com->GetCoords();
1960 int rnum = coordList.size();
1962 list < double >::const_iterator ir = coordList.begin();
1963 aLog[indexLog].commandType = comType;
1964 aLog[indexLog].number = lgcom;
1965 aLog[indexLog].coords.length(rnum);
1966 aLog[indexLog].indexes.length(inum);
1967 for(int i = 0; i < rnum; i++){
1968 aLog[indexLog].coords[i] = *ir;
1969 //MESSAGE(" "<<i<<" "<<ir.Value());
1972 for(int i = 0; i < inum; i++){
1973 aLog[indexLog].indexes[i] = *ii;
1974 //MESSAGE(" "<<i<<" "<<ii.Value());
1983 catch(SALOME_Exception & S_ex){
1984 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1986 return aLog._retn();
1990 //=============================================================================
1994 //=============================================================================
1996 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1998 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
2002 //=============================================================================
2006 //=============================================================================
2008 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
2010 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
2014 //=============================================================================
2018 //=============================================================================
2020 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
2025 //=============================================================================
2029 //=============================================================================
2031 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
2033 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
2037 //=============================================================================
2041 //=============================================================================
2043 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
2045 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
2049 //=============================================================================
2051 * Return mesh editor
2053 //=============================================================================
2055 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
2057 // Create MeshEditor
2058 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
2059 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
2061 // Update Python script
2062 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
2064 return aMesh._retn();
2067 //=============================================================================
2069 * Return mesh edition previewer
2071 //=============================================================================
2073 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
2075 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
2076 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
2077 return aMesh._retn();
2080 //=============================================================================
2084 //=============================================================================
2085 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
2087 Unexpect aCatch(SALOME_SalomeException);
2088 _impl->SetAutoColor(theAutoColor);
2091 //=============================================================================
2095 //=============================================================================
2096 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
2098 Unexpect aCatch(SALOME_SalomeException);
2099 return _impl->GetAutoColor();
2103 //=============================================================================
2105 * Export in different formats
2107 //=============================================================================
2109 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
2111 return _impl->HasDuplicatedGroupNamesMED();
2114 void SMESH_Mesh_i::PrepareForWriting (const char* file)
2116 TCollection_AsciiString aFullName ((char*)file);
2117 OSD_Path aPath (aFullName);
2118 OSD_File aFile (aPath);
2119 if (aFile.Exists()) {
2120 // existing filesystem node
2121 if (aFile.KindOfFile() == OSD_FILE) {
2122 if (aFile.IsWriteable()) {
2125 if (aFile.Failed()) {
2126 TCollection_AsciiString msg ("File ");
2127 msg += aFullName + " cannot be replaced.";
2128 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2131 TCollection_AsciiString msg ("File ");
2132 msg += aFullName + " cannot be overwritten.";
2133 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2136 TCollection_AsciiString msg ("Location ");
2137 msg += aFullName + " is not a file.";
2138 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2141 // nonexisting file; check if it can be created
2143 aFile.Build(OSD_WriteOnly, OSD_Protection());
2144 if (aFile.Failed()) {
2145 TCollection_AsciiString msg ("You cannot create the file ");
2146 msg += aFullName + ". Check the directory existance and access rights.";
2147 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2155 void SMESH_Mesh_i::ExportToMED (const char* file,
2156 CORBA::Boolean auto_groups,
2157 SMESH::MED_VERSION theVersion)
2158 throw(SALOME::SALOME_Exception)
2160 Unexpect aCatch(SALOME_SalomeException);
2163 PrepareForWriting(file);
2164 const char* aMeshName = "Mesh";
2165 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2166 if ( !aStudy->_is_nil() ) {
2167 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
2168 if ( !aMeshSO->_is_nil() ) {
2169 aMeshName = aMeshSO->GetName();
2170 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
2171 if ( !aStudy->GetProperties()->IsLocked() )
2173 SALOMEDS::GenericAttribute_var anAttr;
2174 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2175 SALOMEDS::AttributeExternalFileDef_var aFileName;
2176 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
2177 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
2178 ASSERT(!aFileName->_is_nil());
2179 aFileName->SetValue(file);
2180 SALOMEDS::AttributeFileType_var aFileType;
2181 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
2182 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
2183 ASSERT(!aFileType->_is_nil());
2184 aFileType->SetValue("FICHIERMED");
2188 // Update Python script
2189 // set name of mesh before export
2190 TPythonDump() << _gen_i << ".SetName(" << _this() << ", '" << aMeshName << "')";
2192 // check names of groups
2195 TPythonDump() << _this() << ".ExportToMED( '"
2196 << file << "', " << auto_groups << ", " << theVersion << " )";
2198 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
2201 void SMESH_Mesh_i::ExportMED (const char* file,
2202 CORBA::Boolean auto_groups)
2203 throw(SALOME::SALOME_Exception)
2205 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
2208 void SMESH_Mesh_i::ExportDAT (const char *file)
2209 throw(SALOME::SALOME_Exception)
2211 Unexpect aCatch(SALOME_SalomeException);
2213 // Update Python script
2214 // check names of groups
2216 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
2219 PrepareForWriting(file);
2220 _impl->ExportDAT(file);
2223 void SMESH_Mesh_i::ExportUNV (const char *file)
2224 throw(SALOME::SALOME_Exception)
2226 Unexpect aCatch(SALOME_SalomeException);
2228 // Update Python script
2229 // check names of groups
2231 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
2234 PrepareForWriting(file);
2235 _impl->ExportUNV(file);
2238 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
2239 throw(SALOME::SALOME_Exception)
2241 Unexpect aCatch(SALOME_SalomeException);
2243 // Update Python script
2244 // check names of groups
2246 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
2249 PrepareForWriting(file);
2250 _impl->ExportSTL(file, isascii);
2253 //=============================================================================
2257 //=============================================================================
2259 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
2261 Unexpect aCatch(SALOME_SalomeException);
2262 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
2263 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
2264 return aMesh._retn();
2267 //=============================================================================
2271 //=============================================================================
2272 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
2274 Unexpect aCatch(SALOME_SalomeException);
2275 return _impl->NbNodes();
2278 //=============================================================================
2282 //=============================================================================
2283 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
2285 Unexpect aCatch(SALOME_SalomeException);
2286 return NbEdges() + NbFaces() + NbVolumes();
2289 //=============================================================================
2293 //=============================================================================
2294 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
2296 Unexpect aCatch(SALOME_SalomeException);
2297 return _impl->NbEdges();
2300 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
2301 throw(SALOME::SALOME_Exception)
2303 Unexpect aCatch(SALOME_SalomeException);
2304 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
2307 //=============================================================================
2311 //=============================================================================
2312 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
2314 Unexpect aCatch(SALOME_SalomeException);
2315 return _impl->NbFaces();
2318 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
2320 Unexpect aCatch(SALOME_SalomeException);
2321 return _impl->NbTriangles();
2324 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
2326 Unexpect aCatch(SALOME_SalomeException);
2327 return _impl->NbQuadrangles();
2330 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
2332 Unexpect aCatch(SALOME_SalomeException);
2333 return _impl->NbPolygons();
2336 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
2337 throw(SALOME::SALOME_Exception)
2339 Unexpect aCatch(SALOME_SalomeException);
2340 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
2343 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
2344 throw(SALOME::SALOME_Exception)
2346 Unexpect aCatch(SALOME_SalomeException);
2347 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
2350 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
2351 throw(SALOME::SALOME_Exception)
2353 Unexpect aCatch(SALOME_SalomeException);
2354 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
2357 //=============================================================================
2361 //=============================================================================
2362 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
2364 Unexpect aCatch(SALOME_SalomeException);
2365 return _impl->NbVolumes();
2368 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
2370 Unexpect aCatch(SALOME_SalomeException);
2371 return _impl->NbTetras();
2374 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
2376 Unexpect aCatch(SALOME_SalomeException);
2377 return _impl->NbHexas();
2380 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
2382 Unexpect aCatch(SALOME_SalomeException);
2383 return _impl->NbPyramids();
2386 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
2388 Unexpect aCatch(SALOME_SalomeException);
2389 return _impl->NbPrisms();
2392 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
2394 Unexpect aCatch(SALOME_SalomeException);
2395 return _impl->NbPolyhedrons();
2398 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
2399 throw(SALOME::SALOME_Exception)
2401 Unexpect aCatch(SALOME_SalomeException);
2402 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
2405 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
2406 throw(SALOME::SALOME_Exception)
2408 Unexpect aCatch(SALOME_SalomeException);
2409 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
2412 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
2413 throw(SALOME::SALOME_Exception)
2415 Unexpect aCatch(SALOME_SalomeException);
2416 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
2419 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
2420 throw(SALOME::SALOME_Exception)
2422 Unexpect aCatch(SALOME_SalomeException);
2423 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
2426 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
2427 throw(SALOME::SALOME_Exception)
2429 Unexpect aCatch(SALOME_SalomeException);
2430 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
2433 //=============================================================================
2437 //=============================================================================
2438 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
2440 Unexpect aCatch(SALOME_SalomeException);
2441 return _mapSubMesh_i.size();
2444 //=============================================================================
2448 //=============================================================================
2449 char* SMESH_Mesh_i::Dump()
2451 std::ostringstream os;
2453 return CORBA::string_dup( os.str().c_str() );
2456 //=============================================================================
2460 //=============================================================================
2461 SMESH::long_array* SMESH_Mesh_i::GetIDs()
2463 // SMESH::long_array_var aResult = new SMESH::long_array();
2464 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2465 // int aMinId = aSMESHDS_Mesh->MinElementID();
2466 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
2468 // aResult->length(aMaxId - aMinId + 1);
2470 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
2471 // aResult[i++] = id;
2473 // return aResult._retn();
2475 return GetElementsId();
2478 //=============================================================================
2482 //=============================================================================
2484 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
2485 throw (SALOME::SALOME_Exception)
2487 Unexpect aCatch(SALOME_SalomeException);
2488 MESSAGE("SMESH_Mesh_i::GetElementsId");
2489 SMESH::long_array_var aResult = new SMESH::long_array();
2490 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2492 if ( aSMESHDS_Mesh == NULL )
2493 return aResult._retn();
2495 long nbElements = NbElements();
2496 aResult->length( nbElements );
2497 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
2498 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
2499 aResult[i] = anIt->next()->GetID();
2501 return aResult._retn();
2505 //=============================================================================
2509 //=============================================================================
2511 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
2512 throw (SALOME::SALOME_Exception)
2514 Unexpect aCatch(SALOME_SalomeException);
2515 MESSAGE("SMESH_subMesh_i::GetElementsByType");
2516 SMESH::long_array_var aResult = new SMESH::long_array();
2517 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2519 if ( aSMESHDS_Mesh == NULL )
2520 return aResult._retn();
2522 long nbElements = NbElements();
2524 // No sense in returning ids of elements along with ids of nodes:
2525 // when theElemType == SMESH::ALL, return node ids only if
2526 // there are no elements
2527 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
2528 return GetNodesId();
2530 aResult->length( nbElements );
2534 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
2535 while ( i < nbElements && anIt->more() ) {
2536 const SMDS_MeshElement* anElem = anIt->next();
2537 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
2538 aResult[i++] = anElem->GetID();
2541 aResult->length( i );
2543 return aResult._retn();
2546 //=============================================================================
2550 //=============================================================================
2552 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
2553 throw (SALOME::SALOME_Exception)
2555 Unexpect aCatch(SALOME_SalomeException);
2556 MESSAGE("SMESH_subMesh_i::GetNodesId");
2557 SMESH::long_array_var aResult = new SMESH::long_array();
2558 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2560 if ( aSMESHDS_Mesh == NULL )
2561 return aResult._retn();
2563 long nbNodes = NbNodes();
2564 aResult->length( nbNodes );
2565 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
2566 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
2567 aResult[i] = anIt->next()->GetID();
2569 return aResult._retn();
2572 //=============================================================================
2576 //=============================================================================
2578 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
2579 throw (SALOME::SALOME_Exception)
2581 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
2585 //=============================================================================
2587 * Returns ID of elements for given submesh
2589 //=============================================================================
2590 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
2591 throw (SALOME::SALOME_Exception)
2593 SMESH::long_array_var aResult = new SMESH::long_array();
2595 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2596 if(!SM) return aResult._retn();
2598 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2599 if(!SDSM) return aResult._retn();
2601 aResult->length(SDSM->NbElements());
2603 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2605 while ( eIt->more() ) {
2606 aResult[i++] = eIt->next()->GetID();
2609 return aResult._retn();
2613 //=============================================================================
2615 * Returns ID of nodes for given submesh
2616 * If param all==true - returns all nodes, else -
2617 * returns only nodes on shapes.
2619 //=============================================================================
2620 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
2621 throw (SALOME::SALOME_Exception)
2623 SMESH::long_array_var aResult = new SMESH::long_array();
2625 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2626 if(!SM) return aResult._retn();
2628 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2629 if(!SDSM) return aResult._retn();
2632 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
2633 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
2634 while ( nIt->more() ) {
2635 const SMDS_MeshNode* elem = nIt->next();
2636 theElems.insert( elem->GetID() );
2639 else { // all nodes of submesh elements
2640 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2641 while ( eIt->more() ) {
2642 const SMDS_MeshElement* anElem = eIt->next();
2643 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
2644 while ( nIt->more() ) {
2645 const SMDS_MeshElement* elem = nIt->next();
2646 theElems.insert( elem->GetID() );
2651 aResult->length(theElems.size());
2652 set<int>::iterator itElem;
2654 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
2655 aResult[i++] = *itElem;
2657 return aResult._retn();
2661 //=============================================================================
2663 * Returns type of elements for given submesh
2665 //=============================================================================
2666 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
2667 throw (SALOME::SALOME_Exception)
2669 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2670 if(!SM) return SMESH::ALL;
2672 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2673 if(!SDSM) return SMESH::ALL;
2675 if(SDSM->NbElements()==0)
2676 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
2678 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2679 const SMDS_MeshElement* anElem = eIt->next();
2680 return ( SMESH::ElementType ) anElem->GetType();
2684 //=============================================================================
2688 //=============================================================================
2690 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
2692 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
2694 MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
2699 //=============================================================================
2701 * Get XYZ coordinates of node as list of double
2702 * If there is not node for given ID - returns empty list
2704 //=============================================================================
2706 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2708 SMESH::double_array_var aResult = new SMESH::double_array();
2709 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2710 if ( aSMESHDS_Mesh == NULL )
2711 return aResult._retn();
2714 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2716 return aResult._retn();
2720 aResult[0] = aNode->X();
2721 aResult[1] = aNode->Y();
2722 aResult[2] = aNode->Z();
2723 return aResult._retn();
2727 //=============================================================================
2729 * For given node returns list of IDs of inverse elements
2730 * If there is not node for given ID - returns empty list
2732 //=============================================================================
2734 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2736 SMESH::long_array_var aResult = new SMESH::long_array();
2737 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2738 if ( aSMESHDS_Mesh == NULL )
2739 return aResult._retn();
2742 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2744 return aResult._retn();
2746 // find inverse elements
2747 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2748 TColStd_SequenceOfInteger IDs;
2749 while(eIt->more()) {
2750 const SMDS_MeshElement* elem = eIt->next();
2751 IDs.Append(elem->GetID());
2753 if(IDs.Length()>0) {
2754 aResult->length(IDs.Length());
2756 for(; i<=IDs.Length(); i++) {
2757 aResult[i-1] = IDs.Value(i);
2760 return aResult._retn();
2763 //=============================================================================
2765 * \brief Return position of a node on shape
2767 //=============================================================================
2769 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
2771 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
2772 aNodePosition->shapeID = 0;
2773 aNodePosition->shapeType = GEOM::SHAPE;
2775 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
2776 if ( !mesh ) return aNodePosition;
2778 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
2780 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
2782 aNodePosition->shapeID = pos->GetShapeId();
2783 switch ( pos->GetTypeOfPosition() ) {
2785 aNodePosition->shapeType = GEOM::EDGE;
2786 aNodePosition->params.length(1);
2787 aNodePosition->params[0] =
2788 static_cast<SMDS_EdgePosition*>( pos.get() )->GetUParameter();
2791 aNodePosition->shapeType = GEOM::FACE;
2792 aNodePosition->params.length(2);
2793 aNodePosition->params[0] =
2794 static_cast<SMDS_FacePosition*>( pos.get() )->GetUParameter();
2795 aNodePosition->params[1] =
2796 static_cast<SMDS_FacePosition*>( pos.get() )->GetVParameter();
2798 case SMDS_TOP_VERTEX:
2799 aNodePosition->shapeType = GEOM::VERTEX;
2801 case SMDS_TOP_3DSPACE:
2802 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
2803 aNodePosition->shapeType = GEOM::SOLID;
2804 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
2805 aNodePosition->shapeType = GEOM::SHELL;
2811 return aNodePosition;
2814 //=============================================================================
2816 * If given element is node returns IDs of shape from position
2817 * If there is not node for given ID - returns -1
2819 //=============================================================================
2821 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2823 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2824 if ( aSMESHDS_Mesh == NULL )
2828 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2830 SMDS_PositionPtr pos = aNode->GetPosition();
2834 return pos->GetShapeId();
2841 //=============================================================================
2843 * For given element returns ID of result shape after
2844 * ::FindShape() from SMESH_MeshEditor
2845 * If there is not element for given ID - returns -1
2847 //=============================================================================
2849 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2851 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2852 if ( aSMESHDS_Mesh == NULL )
2855 // try to find element
2856 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2860 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2861 ::SMESH_MeshEditor aMeshEditor(_impl);
2862 int index = aMeshEditor.FindShape( elem );
2870 //=============================================================================
2872 * Returns number of nodes for given element
2873 * If there is not element for given ID - returns -1
2875 //=============================================================================
2877 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2879 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2880 if ( aSMESHDS_Mesh == NULL ) return -1;
2881 // try to find element
2882 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2883 if(!elem) return -1;
2884 return elem->NbNodes();
2888 //=============================================================================
2890 * Returns ID of node by given index for given element
2891 * If there is not element for given ID - returns -1
2892 * If there is not node for given index - returns -2
2894 //=============================================================================
2896 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2898 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2899 if ( aSMESHDS_Mesh == NULL ) return -1;
2900 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2901 if(!elem) return -1;
2902 if( index>=elem->NbNodes() || index<0 ) return -1;
2903 return elem->GetNode(index)->GetID();
2906 //=============================================================================
2908 * Returns IDs of nodes of given element
2910 //=============================================================================
2912 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2914 SMESH::long_array_var aResult = new SMESH::long_array();
2915 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2917 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2919 aResult->length( elem->NbNodes() );
2920 for ( int i = 0; i < elem->NbNodes(); ++i )
2921 aResult[ i ] = elem->GetNode( i )->GetID();
2924 return aResult._retn();
2927 //=============================================================================
2929 * Returns true if given node is medium node
2930 * in given quadratic element
2932 //=============================================================================
2934 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2936 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2937 if ( aSMESHDS_Mesh == NULL ) return false;
2939 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2940 if(!aNode) return false;
2941 // try to find element
2942 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2943 if(!elem) return false;
2945 return elem->IsMediumNode(aNode);
2949 //=============================================================================
2951 * Returns true if given node is medium node
2952 * in one of quadratic elements
2954 //=============================================================================
2956 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2957 SMESH::ElementType theElemType)
2959 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2960 if ( aSMESHDS_Mesh == NULL ) return false;
2963 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2964 if(!aNode) return false;
2966 SMESH_MesherHelper aHelper( *(_impl) );
2968 SMDSAbs_ElementType aType;
2969 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2970 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2971 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2972 else aType = SMDSAbs_All;
2974 return aHelper.IsMedium(aNode,aType);
2978 //=============================================================================
2980 * Returns number of edges for given element
2982 //=============================================================================
2984 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2986 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2987 if ( aSMESHDS_Mesh == NULL ) return -1;
2988 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2989 if(!elem) return -1;
2990 return elem->NbEdges();
2994 //=============================================================================
2996 * Returns number of faces for given element
2998 //=============================================================================
3000 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
3002 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3003 if ( aSMESHDS_Mesh == NULL ) return -1;
3004 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3005 if(!elem) return -1;
3006 return elem->NbFaces();
3010 //=============================================================================
3012 * Returns true if given element is polygon
3014 //=============================================================================
3016 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
3018 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3019 if ( aSMESHDS_Mesh == NULL ) return false;
3020 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3021 if(!elem) return false;
3022 return elem->IsPoly();
3026 //=============================================================================
3028 * Returns true if given element is quadratic
3030 //=============================================================================
3032 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
3034 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3035 if ( aSMESHDS_Mesh == NULL ) return false;
3036 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3037 if(!elem) return false;
3038 return elem->IsQuadratic();
3042 //=============================================================================
3044 * Returns bary center for given element
3046 //=============================================================================
3048 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
3050 SMESH::double_array_var aResult = new SMESH::double_array();
3051 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3052 if ( aSMESHDS_Mesh == NULL )
3053 return aResult._retn();
3055 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3057 return aResult._retn();
3059 if(elem->GetType()==SMDSAbs_Volume) {
3060 SMDS_VolumeTool aTool;
3061 if(aTool.Set(elem)) {
3063 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
3068 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
3070 double x=0., y=0., z=0.;
3071 for(; anIt->more(); ) {
3073 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
3087 return aResult._retn();
3091 //=============================================================================
3093 * Create and publish group servants if any groups were imported or created anyhow
3095 //=============================================================================
3097 void SMESH_Mesh_i::CreateGroupServants()
3099 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
3101 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
3102 while ( groupIt->more() )
3104 ::SMESH_Group* group = groupIt->next();
3105 int anId = group->GetGroupDS()->GetID();
3107 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
3108 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
3111 SMESH_GroupBase_i* aGroupImpl;
3113 if ( SMESHDS_GroupOnGeom* groupOnGeom =
3114 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
3116 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
3117 shape = groupOnGeom->GetShape();
3120 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
3123 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
3124 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
3125 aGroupImpl->Register();
3127 SMESH::SMESH_GroupBase_var groupVar =
3128 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
3129 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
3131 // register CORBA object for persistence
3132 int nextId = _gen_i->RegisterObject( groupVar );
3133 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
3135 // publishing of the groups in the study
3136 if ( !aStudy->_is_nil() ) {
3137 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
3138 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
3143 //=============================================================================
3145 * \brief Return groups cantained in _mapGroups by their IDs
3147 //=============================================================================
3149 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
3151 int nbGroups = groupIDs.size();
3152 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
3153 aList->length( nbGroups );
3155 list<int>::const_iterator ids = groupIDs.begin();
3156 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
3158 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
3159 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
3160 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
3162 aList->length( nbGroups );
3163 return aList._retn();
3166 //=============================================================================
3168 * \brief Return information about imported file
3170 //=============================================================================
3172 SALOME_MED::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
3174 SALOME_MED::MedFileInfo_var res( myFileInfo );
3175 if ( !res.operator->() ) {
3176 res = new SALOME_MED::MedFileInfo;
3178 res->fileSize = res->major = res->minor = res->release = -1;
3183 //=============================================================================
3185 * \brief Check and correct names of mesh groups
3187 //=============================================================================
3189 void SMESH_Mesh_i::checkGroupNames()
3191 int nbGrp = NbGroups();
3195 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
3196 if ( aStudy->_is_nil() )
3197 return; // nothing to do
3199 SMESH::ListOfGroups* grpList = 0;
3200 // avoid dump of "GetGroups"
3202 // store python dump into a local variable inside local scope
3203 SMESH::TPythonDump pDump; // do not delete this line of code
3204 grpList = GetGroups();
3207 for ( int gIndx = 0; gIndx < nbGrp; gIndx++ ) {
3208 SMESH::SMESH_GroupBase_ptr aGrp = (*grpList)[ gIndx ];
3211 SALOMEDS::SObject_var aGrpSO = _gen_i->ObjectToSObject( aStudy, aGrp );
3212 if ( aGrpSO->_is_nil() )
3214 // correct name of the mesh group if necessary
3215 const char* guiName = aGrpSO->GetName();
3216 if ( strcmp(guiName, aGrp->GetName()) )
3217 aGrp->SetName( guiName );
3221 //=============================================================================
3223 * \brief Sets list of notebook variables used for Mesh operations separated by ":" symbol
3225 //=============================================================================
3226 void SMESH_Mesh_i::SetParameters(const char* theParameters)
3228 SMESH_Gen_i::GetSMESHGen()->UpdateParameters(SMESH::SMESH_Mesh::_narrow(_this()),
3229 CORBA::string_dup(theParameters));
3232 //=============================================================================
3234 * \brief Returns list of notebook variables used for Mesh operations separated by ":" symbol
3236 //=============================================================================
3237 char* SMESH_Mesh_i::GetParameters()
3239 SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
3240 return CORBA::string_dup(gen->GetParameters(SMESH::SMESH_Mesh::_narrow(_this())));
3243 //=============================================================================
3245 * \brief Returns list of notebook variables used for last Mesh operation
3247 //=============================================================================
3248 SMESH::string_array* SMESH_Mesh_i::GetLastParameters()
3250 SMESH::string_array_var aResult = new SMESH::string_array();
3251 SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
3253 char *aParameters = GetParameters();
3254 SALOMEDS::Study_ptr aStudy = gen->GetCurrentStudy();
3255 if(!aStudy->_is_nil()) {
3256 SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters);
3257 if(aSections->length() > 0) {
3258 SALOMEDS::ListOfStrings aVars = aSections[aSections->length()-1];
3259 aResult->length(aVars.length());
3260 for(int i = 0;i < aVars.length();i++)
3261 aResult[i] = CORBA::string_dup( aVars[i]);
3265 return aResult._retn();