1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Mesh_i.cxx
25 // Author : Paul RASCLE, EDF
29 #include "SMESH_Mesh_i.hxx"
30 #include "SMESH_subMesh_i.hxx"
31 #include "SMESH_MEDMesh_i.hxx"
32 #include "SMESH_Group_i.hxx"
33 #include "SMESH_Filter_i.hxx"
34 #include "SMESH_PythonDump.hxx"
36 #include "Utils_CorbaException.hxx"
37 #include "Utils_ExceptHandlers.hxx"
38 #include "utilities.h"
40 #include "SALOME_NamingService.hxx"
41 #include "Utils_SINGLETON.hxx"
44 #include "SMESHDS_Command.hxx"
45 #include "SMESHDS_CommandType.hxx"
46 #include "SMESH_MeshEditor_i.hxx"
47 #include "SMESH_Gen_i.hxx"
48 #include "DriverMED_R_SMESHDS_Mesh.h"
49 //#include "SMDS_ElemIterator.hxx"
50 #include "SMDS_VolumeTool.hxx"
51 #include "SMESH_MesherHelper.hxx"
52 #include "SMESH_MeshEditor.hxx"
55 #include <BRep_Builder.hxx>
56 #include <OSD_Path.hxx>
57 #include <OSD_File.hxx>
58 #include <OSD_Directory.hxx>
59 #include <OSD_Protection.hxx>
60 #include <TColStd_MapOfInteger.hxx>
61 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
62 #include <TColStd_SequenceOfInteger.hxx>
63 #include <TCollection_AsciiString.hxx>
64 #include <TopoDS_Compound.hxx>
72 static int MYDEBUG = 0;
74 static int MYDEBUG = 0;
78 using SMESH::TPythonDump;
80 int SMESH_Mesh_i::myIdGenerator = 0;
84 //=============================================================================
88 //=============================================================================
90 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
93 : SALOME::GenericObj_i( thePOA )
95 MESSAGE("SMESH_Mesh_i");
98 _id = myIdGenerator++;
102 //=============================================================================
106 //=============================================================================
108 SMESH_Mesh_i::~SMESH_Mesh_i()
110 INFOS("~SMESH_Mesh_i");
111 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
112 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
113 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
116 // this method is colled from destructor of group (PAL6331)
117 //_impl->RemoveGroup( aGroup->GetLocalID() );
125 //=============================================================================
129 * Associates <this> mesh with <theShape> and puts a reference
130 * to <theShape> into the current study;
131 * the previous shape is substituted by the new one.
133 //=============================================================================
135 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
136 throw (SALOME::SALOME_Exception)
138 Unexpect aCatch(SALOME_SalomeException);
140 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
142 catch(SALOME_Exception & S_ex) {
143 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
147 //================================================================================
149 * \brief return true if mesh has a shape to build a shape on
151 //================================================================================
153 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
154 throw (SALOME::SALOME_Exception)
156 Unexpect aCatch(SALOME_SalomeException);
159 res = _impl->HasShapeToMesh();
161 catch(SALOME_Exception & S_ex) {
162 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
167 //=======================================================================
168 //function : GetShapeToMesh
170 //=======================================================================
172 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
173 throw (SALOME::SALOME_Exception)
175 Unexpect aCatch(SALOME_SalomeException);
176 GEOM::GEOM_Object_var aShapeObj;
178 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
180 aShapeObj = _gen_i->ShapeToGeomObject( S );
182 catch(SALOME_Exception & S_ex) {
183 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
185 return aShapeObj._retn();
188 //=============================================================================
192 //=============================================================================
194 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
196 SMESH::DriverMED_ReadStatus res;
199 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
200 res = SMESH::DRS_OK; break;
201 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
202 res = SMESH::DRS_EMPTY; break;
203 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
204 res = SMESH::DRS_WARN_RENUMBER; break;
205 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
206 res = SMESH::DRS_WARN_SKIP_ELEM; break;
207 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
209 res = SMESH::DRS_FAIL; break;
214 //=============================================================================
218 * Imports mesh data from MED file
220 //=============================================================================
222 SMESH::DriverMED_ReadStatus
223 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
224 throw ( SALOME::SALOME_Exception )
226 Unexpect aCatch(SALOME_SalomeException);
229 status = importMEDFile( theFileName, theMeshName );
231 catch( SALOME_Exception& S_ex ) {
232 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
235 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
238 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
239 if ( !aStudy->_is_nil() ) {
240 // publishing of the groups in the study (sub-meshes are out of scope of MED import)
241 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
242 for (; it != _mapGroups.end(); it++ ) {
243 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
244 _gen_i->PublishGroup( aStudy, _this(), aGroup,
245 GEOM::GEOM_Object::_nil(), aGroup->GetName());
248 return ConvertDriverMEDReadStatus(status);
251 //=============================================================================
255 * Imports mesh data from MED file
257 //=============================================================================
259 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
260 throw ( SALOME::SALOME_Exception )
262 // Read mesh with name = <theMeshName> into SMESH_Mesh
263 _impl->UNVToMesh( theFileName );
265 CreateGroupServants();
267 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
268 if ( !aStudy->_is_nil() ) {
269 // publishing of the groups in the study (sub-meshes are out of scope of UNV import)
270 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
271 for (; it != _mapGroups.end(); it++ ) {
272 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
273 _gen_i->PublishGroup( aStudy, _this(), aGroup,
274 GEOM::GEOM_Object::_nil(), aGroup->GetName());
280 //=============================================================================
284 * Imports mesh data from STL file
286 //=============================================================================
287 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
288 throw ( SALOME::SALOME_Exception )
290 // Read mesh with name = <theMeshName> into SMESH_Mesh
291 _impl->STLToMesh( theFileName );
296 //=============================================================================
300 * Imports mesh data from MED file
302 //=============================================================================
304 int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
306 // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
307 int status = _impl->MEDToMesh( theFileName, theMeshName );
308 CreateGroupServants();
313 //=============================================================================
317 //=============================================================================
319 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
321 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
322 (SMESH_Hypothesis::Hypothesis_Status theStatus)
325 RETURNCASE( HYP_OK );
326 RETURNCASE( HYP_MISSING );
327 RETURNCASE( HYP_CONCURENT );
328 RETURNCASE( HYP_BAD_PARAMETER );
329 RETURNCASE( HYP_HIDDEN_ALGO );
330 RETURNCASE( HYP_HIDING_ALGO );
331 RETURNCASE( HYP_UNKNOWN_FATAL );
332 RETURNCASE( HYP_INCOMPATIBLE );
333 RETURNCASE( HYP_NOTCONFORM );
334 RETURNCASE( HYP_ALREADY_EXIST );
335 RETURNCASE( HYP_BAD_DIM );
336 RETURNCASE( HYP_BAD_SUBSHAPE );
337 RETURNCASE( HYP_BAD_GEOMETRY );
340 return SMESH::HYP_UNKNOWN_FATAL;
343 //=============================================================================
347 * calls internal addHypothesis() and then adds a reference to <anHyp> under
348 * the SObject actually having a reference to <aSubShape>.
349 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
351 //=============================================================================
353 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
354 SMESH::SMESH_Hypothesis_ptr anHyp)
355 throw(SALOME::SALOME_Exception)
357 Unexpect aCatch(SALOME_SalomeException);
358 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
360 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
361 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
362 aSubShapeObject, anHyp );
364 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
366 // Update Python script
367 if(_impl->HasShapeToMesh()) {
368 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
369 << aSubShapeObject << ", " << anHyp << " )";
372 TPythonDump() << "status = " << _this() << ".AddHypothesis( "<< anHyp << " )";
375 return ConvertHypothesisStatus(status);
378 //=============================================================================
382 //=============================================================================
384 SMESH_Hypothesis::Hypothesis_Status
385 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
386 SMESH::SMESH_Hypothesis_ptr anHyp)
388 if(MYDEBUG) MESSAGE("addHypothesis");
390 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
391 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
394 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
395 if (CORBA::is_nil(myHyp))
396 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
399 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
402 TopoDS_Shape myLocSubShape;
403 //use PseudoShape in case if mesh has no shape
405 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
407 myLocSubShape = _impl->GetShapeToMesh();
409 int hypId = myHyp->GetId();
410 status = _impl->AddHypothesis(myLocSubShape, hypId);
411 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
412 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
413 // assure there is a corresponding submesh
414 if ( !_impl->IsMainShape( myLocSubShape )) {
415 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
416 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
417 createSubMesh( aSubShapeObject );
421 catch(SALOME_Exception & S_ex)
423 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
428 //=============================================================================
432 //=============================================================================
434 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
435 SMESH::SMESH_Hypothesis_ptr anHyp)
436 throw(SALOME::SALOME_Exception)
438 Unexpect aCatch(SALOME_SalomeException);
439 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
441 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
442 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
443 aSubShapeObject, anHyp );
445 // Update Python script
446 // Update Python script
447 if(_impl->HasShapeToMesh()) {
448 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
449 << aSubShapeObject << ", " << anHyp << " )";
452 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
456 return ConvertHypothesisStatus(status);
459 //=============================================================================
463 //=============================================================================
465 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
466 SMESH::SMESH_Hypothesis_ptr anHyp)
468 if(MYDEBUG) MESSAGE("removeHypothesis()");
469 // **** proposer liste de subShape (selection multiple)
471 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
472 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
475 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
476 if (CORBA::is_nil(myHyp))
477 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
480 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
483 TopoDS_Shape myLocSubShape;
484 //use PseudoShape in case if mesh has no shape
486 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
488 myLocSubShape = _impl->GetShapeToMesh();
490 int hypId = myHyp->GetId();
491 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
492 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
493 _mapHypo.erase( hypId );
495 catch(SALOME_Exception & S_ex)
497 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
502 //=============================================================================
506 //=============================================================================
508 SMESH::ListOfHypothesis *
509 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
510 throw(SALOME::SALOME_Exception)
512 Unexpect aCatch(SALOME_SalomeException);
513 if (MYDEBUG) MESSAGE("GetHypothesisList");
514 if (CORBA::is_nil(aSubShapeObject))
515 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
518 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
521 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
522 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
523 int i = 0, n = aLocalList.size();
526 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
527 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
528 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
529 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
534 catch(SALOME_Exception & S_ex) {
535 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
538 return aList._retn();
541 //=============================================================================
545 //=============================================================================
546 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
547 const char* theName )
548 throw(SALOME::SALOME_Exception)
550 Unexpect aCatch(SALOME_SalomeException);
551 MESSAGE("SMESH_Mesh_i::GetSubMesh");
552 if (CORBA::is_nil(aSubShapeObject))
553 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
556 SMESH::SMESH_subMesh_var subMesh;
557 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
559 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
561 //Get or Create the SMESH_subMesh object implementation
563 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
564 subMesh = getSubMesh( subMeshId );
566 // create a new subMesh object servant if there is none for the shape
567 if ( subMesh->_is_nil() )
568 subMesh = createSubMesh( aSubShapeObject );
570 if ( _gen_i->CanPublishInStudy( subMesh )) {
571 SALOMEDS::SObject_var aSO =
572 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
573 subMesh, aSubShapeObject, theName );
574 if ( !aSO->_is_nil()) {
575 // Update Python script
576 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
577 << aSubShapeObject << ", '" << theName << "' )";
581 catch(SALOME_Exception & S_ex) {
582 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
584 return subMesh._retn();
587 //=============================================================================
591 //=============================================================================
593 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
594 throw (SALOME::SALOME_Exception)
596 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
597 if ( theSubMesh->_is_nil() )
600 GEOM::GEOM_Object_var aSubShapeObject;
601 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
602 if ( !aStudy->_is_nil() ) {
603 // Remove submesh's SObject
604 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
605 if ( !anSO->_is_nil() ) {
606 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
607 SALOMEDS::SObject_var anObj, aRef;
608 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
609 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
611 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
613 // Update Python script
614 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
618 removeSubMesh( theSubMesh, aSubShapeObject.in() );
621 //=============================================================================
625 //=============================================================================
626 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
627 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
629 switch (theElemType) {
634 CASE2STRING( VOLUME );
640 //=============================================================================
644 //=============================================================================
646 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
647 const char* theName )
648 throw(SALOME::SALOME_Exception)
650 Unexpect aCatch(SALOME_SalomeException);
651 SMESH::SMESH_Group_var aNewGroup =
652 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
654 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
655 SALOMEDS::SObject_var aSO =
656 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
657 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
658 if ( !aSO->_is_nil()) {
659 // Update Python script
660 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
661 << ElementTypeString(theElemType) << ", '" << theName << "' )";
664 return aNewGroup._retn();
668 //=============================================================================
672 //=============================================================================
673 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
675 GEOM::GEOM_Object_ptr theGeomObj)
676 throw(SALOME::SALOME_Exception)
678 Unexpect aCatch(SALOME_SalomeException);
679 SMESH::SMESH_GroupOnGeom_var aNewGroup;
681 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
682 if ( !aShape.IsNull() ) {
683 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
684 ( createGroup( theElemType, theName, aShape ));
685 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
686 SALOMEDS::SObject_var aSO =
687 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
688 aNewGroup, theGeomObj, theName);
689 if ( !aSO->_is_nil()) {
690 // Update Python script
691 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
692 << ElementTypeString(theElemType) << ", '" << theName << "', "
693 << theGeomObj << " )";
698 return aNewGroup._retn();
701 //=============================================================================
705 //=============================================================================
707 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
708 throw (SALOME::SALOME_Exception)
710 if ( theGroup->_is_nil() )
713 SMESH_GroupBase_i* aGroup =
714 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
718 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
719 if ( !aStudy->_is_nil() ) {
720 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
722 if ( !aGroupSO->_is_nil() ) {
723 // Update Python script
724 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
726 // Remove group's SObject
727 aStudy->NewBuilder()->RemoveObject( aGroupSO );
731 // Remove the group from SMESH data structures
732 removeGroup( aGroup->GetLocalID() );
735 //=============================================================================
736 /*! RemoveGroupWithContents
737 * Remove group with its contents
739 //=============================================================================
740 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
741 throw (SALOME::SALOME_Exception)
743 if ( theGroup->_is_nil() )
746 SMESH_GroupBase_i* aGroup =
747 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
751 SMESH::long_array_var anIds = aGroup->GetListOfID();
752 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
754 // Update Python script
755 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
758 if ( aGroup->GetType() == SMESH::NODE )
759 aMeshEditor->RemoveNodes( anIds );
761 aMeshEditor->RemoveElements( anIds );
764 RemoveGroup( theGroup );
766 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
767 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
768 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
772 //================================================================================
774 * \brief Get the list of groups existing in the mesh
775 * \retval SMESH::ListOfGroups * - list of groups
777 //================================================================================
779 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
781 Unexpect aCatch(SALOME_SalomeException);
782 if (MYDEBUG) MESSAGE("GetGroups");
784 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
787 TPythonDump aPythonDump;
788 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
792 aList->length( _mapGroups.size() );
794 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
795 for ( ; it != _mapGroups.end(); it++ ) {
796 if ( CORBA::is_nil( it->second )) continue;
797 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
799 if (i > 1) aPythonDump << ", ";
800 aPythonDump << it->second;
804 catch(SALOME_Exception & S_ex) {
805 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
808 // Update Python script
809 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
810 aPythonDump << " ] = " << _this() << ".GetGroups()";
812 return aList._retn();
815 //=============================================================================
817 * New group is created. All mesh elements that are
818 * present in initial groups are added to the new one
820 //=============================================================================
821 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
822 SMESH::SMESH_GroupBase_ptr theGroup2,
823 const char* theName )
824 throw (SALOME::SALOME_Exception)
828 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
829 theGroup1->GetType() != theGroup2->GetType() )
830 return SMESH::SMESH_Group::_nil();
833 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
834 if ( aResGrp->_is_nil() )
835 return SMESH::SMESH_Group::_nil();
837 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
838 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
840 TColStd_MapOfInteger aResMap;
842 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
843 aResMap.Add( anIds1[ i1 ] );
845 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
846 aResMap.Add( anIds2[ i2 ] );
848 SMESH::long_array_var aResIds = new SMESH::long_array;
849 aResIds->length( aResMap.Extent() );
852 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
853 for( ; anIter.More(); anIter.Next() )
854 aResIds[ resI++ ] = anIter.Key();
856 aResGrp->Add( aResIds );
858 // Clear python lines, created by CreateGroup() and Add()
859 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
860 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
861 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
863 // Update Python script
864 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
865 << theGroup1 << ", " << theGroup2 << ", '"
868 return aResGrp._retn();
872 return SMESH::SMESH_Group::_nil();
876 //=============================================================================
878 * New group is created. All mesh elements that are
879 * present in both initial groups are added to the new one.
881 //=============================================================================
882 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
883 SMESH::SMESH_GroupBase_ptr theGroup2,
884 const char* theName )
885 throw (SALOME::SALOME_Exception)
887 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
888 theGroup1->GetType() != theGroup2->GetType() )
889 return SMESH::SMESH_Group::_nil();
891 // Create Intersection
892 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
893 if ( aResGrp->_is_nil() )
896 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
897 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
899 TColStd_MapOfInteger aMap1;
901 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
902 aMap1.Add( anIds1[ i1 ] );
904 TColStd_SequenceOfInteger aSeq;
906 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
907 if ( aMap1.Contains( anIds2[ i2 ] ) )
908 aSeq.Append( anIds2[ i2 ] );
910 SMESH::long_array_var aResIds = new SMESH::long_array;
911 aResIds->length( aSeq.Length() );
913 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
914 aResIds[ resI ] = aSeq( resI + 1 );
916 aResGrp->Add( aResIds );
918 // Clear python lines, created by CreateGroup() and Add()
919 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
920 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
921 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
923 // Update Python script
924 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
925 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
927 return aResGrp._retn();
930 //=============================================================================
932 * New group is created. All mesh elements that are present in
933 * main group but do not present in tool group are added to the new one
935 //=============================================================================
936 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
937 SMESH::SMESH_GroupBase_ptr theGroup2,
938 const char* theName )
939 throw (SALOME::SALOME_Exception)
941 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
942 theGroup1->GetType() != theGroup2->GetType() )
943 return SMESH::SMESH_Group::_nil();
946 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
947 if ( aResGrp->_is_nil() )
950 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
951 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
953 TColStd_MapOfInteger aMap2;
955 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
956 aMap2.Add( anIds2[ i2 ] );
959 TColStd_SequenceOfInteger aSeq;
960 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
961 if ( !aMap2.Contains( anIds1[ i1 ] ) )
962 aSeq.Append( anIds1[ i1 ] );
964 SMESH::long_array_var aResIds = new SMESH::long_array;
965 aResIds->length( aSeq.Length() );
967 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
968 aResIds[ resI ] = aSeq( resI + 1 );
970 aResGrp->Add( aResIds );
972 // Clear python lines, created by CreateGroup() and Add()
973 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
974 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
975 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
977 // Update Python script
978 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
979 << theGroup1 << ", " << theGroup2 << ", '"
982 return aResGrp._retn();
985 //================================================================================
987 * \brief Return group items of a group present in a study
989 //================================================================================
991 static GEOM::GEOM_Object_ptr getGroupItemsFromStudy(CORBA::Object_ptr theMesh,
993 list<TopoDS_Shape> & theItems)
995 GEOM::GEOM_Object_var groupObj;
996 SALOMEDS::Study_var study = theGen->GetCurrentStudy();
997 GEOM::GEOM_Gen_var geomGen = theGen->GetGeomEngine();
998 if ( study->_is_nil() || geomGen->_is_nil() )
999 return groupObj._retn();
1001 GEOM::GEOM_IGroupOperations_var groupOp =
1002 geomGen->GetIGroupOperations( theGen->GetCurrentStudyID() );
1003 GEOM::GEOM_IShapesOperations_var shapeOp =
1004 geomGen->GetIShapesOperations( theGen->GetCurrentStudyID() );
1006 SALOMEDS::SObject_var meshOS = theGen->ObjectToSObject(study, theMesh);
1007 if ( meshOS->_is_nil() || groupOp->_is_nil() || shapeOp->_is_nil() )
1008 return groupObj._retn();
1009 SALOMEDS::SObject_var fatherSO = meshOS->GetFather();
1010 if ( fatherSO->_is_nil() || fatherSO->Tag() != theGen->GetSubMeshOnCompoundTag() )
1011 return groupObj._retn(); // keep only submeshes on groups
1013 SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(meshOS);
1014 if ( anIter->_is_nil() ) return groupObj._retn();
1015 for ( ; anIter->More(); anIter->Next())
1017 SALOMEDS::SObject_var aSObject = anIter->Value();
1018 SALOMEDS::SObject_var aRefSO;
1019 if ( !aSObject->_is_nil() && aSObject->ReferencedObject(aRefSO) )
1021 groupObj = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
1022 if ( groupObj->_is_nil() ) break;
1023 GEOM::ListOfLong_var ids = groupOp->GetObjects( groupObj );
1024 GEOM::GEOM_Object_var mainShape = groupObj->GetMainShape();
1025 for ( int i = 0; i < ids->length(); ++i ) {
1026 GEOM::GEOM_Object_var subShape = shapeOp->GetSubShape( mainShape, ids[i] );
1027 TopoDS_Shape S = theGen->GeomObjectToShape( subShape );
1029 theItems.push_back( S );
1034 return groupObj._retn();
1037 //=============================================================================
1039 * \brief Update hypotheses assigned to geom groups if the latter change
1041 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1043 //=============================================================================
1045 void SMESH_Mesh_i::CheckGeomGroupModif()
1047 if ( !_impl->HasShapeToMesh() ) return;
1049 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1050 if ( study->_is_nil() ) return;
1052 // check if items of groups changed
1053 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
1054 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
1056 const TopoDS_Shape & oldGroupShape = i_sm->second->GetSubShape();
1057 SMESHDS_SubMesh * oldDS = i_sm->second->GetSubMeshDS();
1058 if ( !oldDS /*|| !oldDS->IsComplexSubmesh()*/ )
1060 int oldID = i_sm->first;
1061 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldID );
1062 if ( i_smIor == _mapSubMeshIor.end() )
1064 list< TopoDS_Shape> newItems;
1065 GEOM::GEOM_Object_var groupObj = getGroupItemsFromStudy ( i_smIor->second, _gen_i, newItems );
1066 if ( groupObj->_is_nil() )
1069 int nbOldItems = oldDS->IsComplexSubmesh() ? oldDS->NbSubMeshes() : 1;
1070 int nbNewItems = newItems.size();
1071 bool groupChanged = ( nbOldItems != nbNewItems);
1072 if ( !groupChanged ) {
1073 if ( !oldDS->IsComplexSubmesh() ) { // old group has one item
1074 groupChanged = ( oldGroupShape != newItems.front() );
1077 list<TopoDS_Shape>::iterator item = newItems.begin();
1078 for ( ; item != newItems.end() && !groupChanged; ++item )
1080 SMESHDS_SubMesh * itemDS = _impl->GetMeshDS()->MeshElements( *item );
1081 groupChanged = ( !itemDS || !oldDS->ContainsSubMesh( itemDS ));
1085 // update hypotheses and submeshes if necessary
1088 // get a new group shape
1089 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1090 if ( !geomClient ) continue;
1091 TCollection_AsciiString groupIOR = _gen_i->GetGeomEngine()->GetStringFromIOR( groupObj );
1092 geomClient->RemoveShapeFromBuffer( groupIOR );
1093 TopoDS_Shape newGroupShape = _gen_i->GeomObjectToShape( groupObj );
1094 // update hypotheses
1095 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldGroupShape);
1096 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1097 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1099 _impl->RemoveHypothesis( oldGroupShape, (*hypIt)->GetID());
1100 _impl->AddHypothesis ( newGroupShape, (*hypIt)->GetID());
1102 // care of submeshes
1103 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newGroupShape );
1104 int newID = newSubmesh->GetId();
1105 if ( newID != oldID ) {
1106 _mapSubMesh [ newID ] = newSubmesh;
1107 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1108 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1109 _mapSubMesh.erase (oldID);
1110 _mapSubMesh_i.erase (oldID);
1111 _mapSubMeshIor.erase(oldID);
1112 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1118 //=============================================================================
1122 //=============================================================================
1124 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1126 if(MYDEBUG) MESSAGE( "createSubMesh" );
1127 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1129 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1130 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1131 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1132 SMESH::SMESH_subMesh_var subMesh
1133 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1135 _mapSubMesh[subMeshId] = mySubMesh;
1136 _mapSubMesh_i[subMeshId] = subMeshServant;
1137 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1139 // register CORBA object for persistence
1140 int nextId = _gen_i->RegisterObject( subMesh );
1141 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1143 return subMesh._retn();
1146 //=======================================================================
1147 //function : getSubMesh
1149 //=======================================================================
1151 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1153 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1154 if ( it == _mapSubMeshIor.end() )
1155 return SMESH::SMESH_subMesh::_nil();
1157 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1161 //=============================================================================
1165 //=============================================================================
1167 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1168 GEOM::GEOM_Object_ptr theSubShapeObject )
1170 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1171 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1175 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1176 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1177 removeHypothesis( theSubShapeObject, aHypList[i] );
1180 catch( const SALOME::SALOME_Exception& ) {
1181 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1184 int subMeshId = theSubMesh->GetId();
1186 _mapSubMesh.erase(subMeshId);
1187 _mapSubMesh_i.erase(subMeshId);
1188 _mapSubMeshIor.erase(subMeshId);
1189 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1192 //=============================================================================
1196 //=============================================================================
1198 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1199 const char* theName,
1200 const TopoDS_Shape& theShape )
1203 SMESH::SMESH_GroupBase_var aGroup;
1204 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1205 SMESH_GroupBase_i* aGroupImpl;
1206 if ( !theShape.IsNull() )
1207 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1209 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1211 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1212 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1213 aGroupImpl->Register();
1214 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1216 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1217 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1219 // register CORBA object for persistence
1220 int nextId = _gen_i->RegisterObject( aGroup );
1221 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1223 return aGroup._retn();
1226 //=============================================================================
1228 * SMESH_Mesh_i::removeGroup
1230 * Should be called by ~SMESH_Group_i()
1232 //=============================================================================
1234 void SMESH_Mesh_i::removeGroup( const int theId )
1236 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1237 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1238 _mapGroups.erase( theId );
1239 _impl->RemoveGroup( theId );
1244 //=============================================================================
1248 //=============================================================================
1250 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1251 throw(SALOME::SALOME_Exception)
1253 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1255 SMESH::log_array_var aLog;
1257 list < SMESHDS_Command * >logDS = _impl->GetLog();
1258 aLog = new SMESH::log_array;
1260 int lg = logDS.size();
1263 list < SMESHDS_Command * >::iterator its = logDS.begin();
1264 while(its != logDS.end()){
1265 SMESHDS_Command *com = *its;
1266 int comType = com->GetType();
1268 int lgcom = com->GetNumber();
1270 const list < int >&intList = com->GetIndexes();
1271 int inum = intList.size();
1273 list < int >::const_iterator ii = intList.begin();
1274 const list < double >&coordList = com->GetCoords();
1275 int rnum = coordList.size();
1277 list < double >::const_iterator ir = coordList.begin();
1278 aLog[indexLog].commandType = comType;
1279 aLog[indexLog].number = lgcom;
1280 aLog[indexLog].coords.length(rnum);
1281 aLog[indexLog].indexes.length(inum);
1282 for(int i = 0; i < rnum; i++){
1283 aLog[indexLog].coords[i] = *ir;
1284 //MESSAGE(" "<<i<<" "<<ir.Value());
1287 for(int i = 0; i < inum; i++){
1288 aLog[indexLog].indexes[i] = *ii;
1289 //MESSAGE(" "<<i<<" "<<ii.Value());
1298 catch(SALOME_Exception & S_ex){
1299 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1301 return aLog._retn();
1305 //=============================================================================
1309 //=============================================================================
1311 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1313 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1317 //=============================================================================
1321 //=============================================================================
1323 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1325 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1329 //=============================================================================
1333 //=============================================================================
1335 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1340 //=============================================================================
1344 //=============================================================================
1346 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1348 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1352 //=============================================================================
1356 //=============================================================================
1358 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1360 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1364 //=============================================================================
1366 * Return mesh editor
1368 //=============================================================================
1370 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1372 // Create MeshEditor
1373 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl, false );
1374 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1376 // Update Python script
1377 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1379 return aMesh._retn();
1382 //=============================================================================
1384 * Return mesh edition previewer
1386 //=============================================================================
1388 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1390 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl, true );
1391 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1392 return aMesh._retn();
1395 //=============================================================================
1399 //=============================================================================
1400 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
1402 Unexpect aCatch(SALOME_SalomeException);
1403 _impl->SetAutoColor(theAutoColor);
1406 //=============================================================================
1410 //=============================================================================
1411 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
1413 Unexpect aCatch(SALOME_SalomeException);
1414 return _impl->GetAutoColor();
1418 //=============================================================================
1420 * Export in different formats
1422 //=============================================================================
1424 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1426 return _impl->HasDuplicatedGroupNamesMED();
1429 static void PrepareForWriting (const char* file)
1431 TCollection_AsciiString aFullName ((char*)file);
1432 OSD_Path aPath (aFullName);
1433 OSD_File aFile (aPath);
1434 if (aFile.Exists()) {
1435 // existing filesystem node
1436 if (aFile.KindOfFile() == OSD_FILE) {
1437 if (aFile.IsWriteable()) {
1440 if (aFile.Failed()) {
1441 TCollection_AsciiString msg ("File ");
1442 msg += aFullName + " cannot be replaced.";
1443 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1446 TCollection_AsciiString msg ("File ");
1447 msg += aFullName + " cannot be overwritten.";
1448 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1451 TCollection_AsciiString msg ("Location ");
1452 msg += aFullName + " is not a file.";
1453 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1456 // nonexisting file; check if it can be created
1458 aFile.Build(OSD_WriteOnly, OSD_Protection());
1459 if (aFile.Failed()) {
1460 TCollection_AsciiString msg ("You cannot create the file ");
1461 msg += aFullName + ". Check the directory existance and access rights.";
1462 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1470 void SMESH_Mesh_i::ExportToMED (const char* file,
1471 CORBA::Boolean auto_groups,
1472 SMESH::MED_VERSION theVersion)
1473 throw(SALOME::SALOME_Exception)
1475 Unexpect aCatch(SALOME_SalomeException);
1477 // Update Python script
1478 TPythonDump() << _this() << ".ExportToMED( '"
1479 << file << "', " << auto_groups << ", " << theVersion << " )";
1482 PrepareForWriting(file);
1483 char* aMeshName = "Mesh";
1484 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1485 if ( !aStudy->_is_nil() ) {
1486 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1487 if ( !aMeshSO->_is_nil() ) {
1488 aMeshName = aMeshSO->GetName();
1490 //SCRUTE(aMeshName);
1491 //SCRUTE(aMeshSO->GetID());
1493 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1494 if ( !aStudy->GetProperties()->IsLocked() )
1496 SALOMEDS::GenericAttribute_var anAttr;
1497 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1498 SALOMEDS::AttributeExternalFileDef_var aFileName;
1499 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1500 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1501 ASSERT(!aFileName->_is_nil());
1502 aFileName->SetValue(file);
1503 SALOMEDS::AttributeFileType_var aFileType;
1504 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1505 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1506 ASSERT(!aFileType->_is_nil());
1507 aFileType->SetValue("FICHIERMED");
1511 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1514 void SMESH_Mesh_i::ExportMED (const char* file,
1515 CORBA::Boolean auto_groups)
1516 throw(SALOME::SALOME_Exception)
1518 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1521 void SMESH_Mesh_i::ExportDAT (const char *file)
1522 throw(SALOME::SALOME_Exception)
1524 Unexpect aCatch(SALOME_SalomeException);
1526 // Update Python script
1527 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1530 PrepareForWriting(file);
1531 _impl->ExportDAT(file);
1534 void SMESH_Mesh_i::ExportUNV (const char *file)
1535 throw(SALOME::SALOME_Exception)
1537 Unexpect aCatch(SALOME_SalomeException);
1539 // Update Python script
1540 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1543 PrepareForWriting(file);
1544 _impl->ExportUNV(file);
1547 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1548 throw(SALOME::SALOME_Exception)
1550 Unexpect aCatch(SALOME_SalomeException);
1552 // Update Python script
1553 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1556 PrepareForWriting(file);
1557 _impl->ExportSTL(file, isascii);
1560 //=============================================================================
1564 //=============================================================================
1566 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1568 Unexpect aCatch(SALOME_SalomeException);
1569 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1570 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1571 return aMesh._retn();
1574 //=============================================================================
1578 //=============================================================================
1579 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1581 Unexpect aCatch(SALOME_SalomeException);
1582 return _impl->NbNodes();
1585 //=============================================================================
1589 //=============================================================================
1590 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1592 Unexpect aCatch(SALOME_SalomeException);
1593 return NbEdges() + NbFaces() + NbVolumes();
1596 //=============================================================================
1600 //=============================================================================
1601 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1603 Unexpect aCatch(SALOME_SalomeException);
1604 return _impl->NbEdges();
1607 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1608 throw(SALOME::SALOME_Exception)
1610 Unexpect aCatch(SALOME_SalomeException);
1611 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
1614 //=============================================================================
1618 //=============================================================================
1619 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1621 Unexpect aCatch(SALOME_SalomeException);
1622 return _impl->NbFaces();
1625 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1627 Unexpect aCatch(SALOME_SalomeException);
1628 return _impl->NbTriangles();
1631 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1633 Unexpect aCatch(SALOME_SalomeException);
1634 return _impl->NbQuadrangles();
1637 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1639 Unexpect aCatch(SALOME_SalomeException);
1640 return _impl->NbPolygons();
1643 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1644 throw(SALOME::SALOME_Exception)
1646 Unexpect aCatch(SALOME_SalomeException);
1647 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
1650 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1651 throw(SALOME::SALOME_Exception)
1653 Unexpect aCatch(SALOME_SalomeException);
1654 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
1657 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1658 throw(SALOME::SALOME_Exception)
1660 Unexpect aCatch(SALOME_SalomeException);
1661 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
1664 //=============================================================================
1668 //=============================================================================
1669 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1671 Unexpect aCatch(SALOME_SalomeException);
1672 return _impl->NbVolumes();
1675 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1677 Unexpect aCatch(SALOME_SalomeException);
1678 return _impl->NbTetras();
1681 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1683 Unexpect aCatch(SALOME_SalomeException);
1684 return _impl->NbHexas();
1687 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1689 Unexpect aCatch(SALOME_SalomeException);
1690 return _impl->NbPyramids();
1693 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1695 Unexpect aCatch(SALOME_SalomeException);
1696 return _impl->NbPrisms();
1699 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1701 Unexpect aCatch(SALOME_SalomeException);
1702 return _impl->NbPolyhedrons();
1705 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1706 throw(SALOME::SALOME_Exception)
1708 Unexpect aCatch(SALOME_SalomeException);
1709 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
1712 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1713 throw(SALOME::SALOME_Exception)
1715 Unexpect aCatch(SALOME_SalomeException);
1716 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
1719 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1720 throw(SALOME::SALOME_Exception)
1722 Unexpect aCatch(SALOME_SalomeException);
1723 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
1726 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1727 throw(SALOME::SALOME_Exception)
1729 Unexpect aCatch(SALOME_SalomeException);
1730 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
1733 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1734 throw(SALOME::SALOME_Exception)
1736 Unexpect aCatch(SALOME_SalomeException);
1737 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
1740 //=============================================================================
1744 //=============================================================================
1745 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1747 Unexpect aCatch(SALOME_SalomeException);
1748 return _impl->NbSubMesh();
1751 //=============================================================================
1755 //=============================================================================
1756 char* SMESH_Mesh_i::Dump()
1758 std::ostringstream os;
1760 return CORBA::string_dup( os.str().c_str() );
1763 //=============================================================================
1767 //=============================================================================
1768 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1770 // SMESH::long_array_var aResult = new SMESH::long_array();
1771 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1772 // int aMinId = aSMESHDS_Mesh->MinElementID();
1773 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1775 // aResult->length(aMaxId - aMinId + 1);
1777 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1778 // aResult[i++] = id;
1780 // return aResult._retn();
1782 return GetElementsId();
1785 //=============================================================================
1789 //=============================================================================
1791 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1792 throw (SALOME::SALOME_Exception)
1794 Unexpect aCatch(SALOME_SalomeException);
1795 MESSAGE("SMESH_Mesh_i::GetElementsId");
1796 SMESH::long_array_var aResult = new SMESH::long_array();
1797 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1799 if ( aSMESHDS_Mesh == NULL )
1800 return aResult._retn();
1802 long nbElements = NbElements();
1803 aResult->length( nbElements );
1804 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1805 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1806 aResult[i] = anIt->next()->GetID();
1808 return aResult._retn();
1812 //=============================================================================
1816 //=============================================================================
1818 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1819 throw (SALOME::SALOME_Exception)
1821 Unexpect aCatch(SALOME_SalomeException);
1822 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1823 SMESH::long_array_var aResult = new SMESH::long_array();
1824 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1826 if ( aSMESHDS_Mesh == NULL )
1827 return aResult._retn();
1829 long nbElements = NbElements();
1831 // No sense in returning ids of elements along with ids of nodes:
1832 // when theElemType == SMESH::ALL, return node ids only if
1833 // there are no elements
1834 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1835 return GetNodesId();
1837 aResult->length( nbElements );
1841 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1842 while ( i < nbElements && anIt->more() ) {
1843 const SMDS_MeshElement* anElem = anIt->next();
1844 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1845 aResult[i++] = anElem->GetID();
1848 aResult->length( i );
1850 return aResult._retn();
1853 //=============================================================================
1857 //=============================================================================
1859 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1860 throw (SALOME::SALOME_Exception)
1862 Unexpect aCatch(SALOME_SalomeException);
1863 MESSAGE("SMESH_subMesh_i::GetNodesId");
1864 SMESH::long_array_var aResult = new SMESH::long_array();
1865 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1867 if ( aSMESHDS_Mesh == NULL )
1868 return aResult._retn();
1870 long nbNodes = NbNodes();
1871 aResult->length( nbNodes );
1872 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1873 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1874 aResult[i] = anIt->next()->GetID();
1876 return aResult._retn();
1879 //=============================================================================
1883 //=============================================================================
1885 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1886 throw (SALOME::SALOME_Exception)
1888 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1892 //=============================================================================
1894 * Returns ID of elements for given submesh
1896 //=============================================================================
1897 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1898 throw (SALOME::SALOME_Exception)
1900 SMESH::long_array_var aResult = new SMESH::long_array();
1902 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1903 if(!SM) return aResult._retn();
1905 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1906 if(!SDSM) return aResult._retn();
1908 aResult->length(SDSM->NbElements());
1910 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1912 while ( eIt->more() ) {
1913 aResult[i++] = eIt->next()->GetID();
1916 return aResult._retn();
1920 //=============================================================================
1922 * Returns ID of nodes for given submesh
1923 * If param all==true - returns all nodes, else -
1924 * returns only nodes on shapes.
1926 //=============================================================================
1927 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1928 throw (SALOME::SALOME_Exception)
1930 SMESH::long_array_var aResult = new SMESH::long_array();
1932 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1933 if(!SM) return aResult._retn();
1935 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1936 if(!SDSM) return aResult._retn();
1938 map<int,const SMDS_MeshElement*> theElems;
1939 if( !all || (SDSM->NbElements()==0 && SDSM->NbNodes()==1) ) {
1940 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1941 while ( nIt->more() ) {
1942 const SMDS_MeshNode* elem = nIt->next();
1943 theElems.insert( make_pair(elem->GetID(),elem) );
1946 else { // all nodes of submesh elements
1947 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1948 while ( eIt->more() ) {
1949 const SMDS_MeshElement* anElem = eIt->next();
1950 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
1951 while ( nIt->more() ) {
1952 const SMDS_MeshElement* elem = nIt->next();
1953 theElems.insert( make_pair(elem->GetID(),elem) );
1958 aResult->length(theElems.size());
1959 map<int, const SMDS_MeshElement * >::iterator itElem;
1961 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
1962 aResult[i++] = (*itElem).first;
1964 return aResult._retn();
1968 //=============================================================================
1970 * Returns type of elements for given submesh
1972 //=============================================================================
1973 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
1974 throw (SALOME::SALOME_Exception)
1976 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1977 if(!SM) return SMESH::ALL;
1979 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1980 if(!SDSM) return SMESH::ALL;
1982 if(SDSM->NbElements()==0)
1983 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
1985 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1986 const SMDS_MeshElement* anElem = eIt->next();
1987 return ( SMESH::ElementType ) anElem->GetType();
1991 //=============================================================================
1995 //=============================================================================
1997 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
1999 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
2000 cerr << "CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() " << pointeur << endl;
2005 //=============================================================================
2007 * Get XYZ coordinates of node as list of double
2008 * If there is not node for given ID - returns empty list
2010 //=============================================================================
2012 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2014 SMESH::double_array_var aResult = new SMESH::double_array();
2015 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2016 if ( aSMESHDS_Mesh == NULL )
2017 return aResult._retn();
2020 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2022 return aResult._retn();
2026 aResult[0] = aNode->X();
2027 aResult[1] = aNode->Y();
2028 aResult[2] = aNode->Z();
2029 return aResult._retn();
2033 //=============================================================================
2035 * For given node returns list of IDs of inverse elements
2036 * If there is not node for given ID - returns empty list
2038 //=============================================================================
2040 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2042 SMESH::long_array_var aResult = new SMESH::long_array();
2043 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2044 if ( aSMESHDS_Mesh == NULL )
2045 return aResult._retn();
2048 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2050 return aResult._retn();
2052 // find inverse elements
2053 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2054 TColStd_SequenceOfInteger IDs;
2055 while(eIt->more()) {
2056 const SMDS_MeshElement* elem = eIt->next();
2057 IDs.Append(elem->GetID());
2059 if(IDs.Length()>0) {
2060 aResult->length(IDs.Length());
2062 for(; i<=IDs.Length(); i++) {
2063 aResult[i-1] = IDs.Value(i);
2066 return aResult._retn();
2070 //=============================================================================
2072 * If given element is node returns IDs of shape from position
2073 * If there is not node for given ID - returns -1
2075 //=============================================================================
2077 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2079 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2080 if ( aSMESHDS_Mesh == NULL )
2084 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2086 SMDS_PositionPtr pos = aNode->GetPosition();
2090 return pos->GetShapeId();
2097 //=============================================================================
2099 * For given element returns ID of result shape after
2100 * ::FindShape() from SMESH_MeshEditor
2101 * If there is not element for given ID - returns -1
2103 //=============================================================================
2105 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2107 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2108 if ( aSMESHDS_Mesh == NULL )
2111 // try to find element
2112 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2116 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2117 ::SMESH_MeshEditor aMeshEditor(_impl);
2118 int index = aMeshEditor.FindShape( elem );
2126 //=============================================================================
2128 * Returns number of nodes for given element
2129 * If there is not element for given ID - returns -1
2131 //=============================================================================
2133 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2135 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2136 if ( aSMESHDS_Mesh == NULL ) return -1;
2137 // try to find element
2138 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2139 if(!elem) return -1;
2140 return elem->NbNodes();
2144 //=============================================================================
2146 * Returns ID of node by given index for given element
2147 * If there is not element for given ID - returns -1
2148 * If there is not node for given index - returns -2
2150 //=============================================================================
2152 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2154 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2155 if ( aSMESHDS_Mesh == NULL ) return -1;
2156 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2157 if(!elem) return -1;
2158 if( index>=elem->NbNodes() || index<0 ) return -1;
2159 return elem->GetNode(index)->GetID();
2162 //=============================================================================
2164 * Returns IDs of nodes of given element
2166 //=============================================================================
2168 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2170 SMESH::long_array_var aResult = new SMESH::long_array();
2171 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2173 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2175 aResult->length( elem->NbNodes() );
2176 for ( int i = 0; i < elem->NbNodes(); ++i )
2177 aResult[ i ] = elem->GetNode( i )->GetID();
2180 return aResult._retn();
2183 //=============================================================================
2185 * Returns true if given node is medium node
2186 * in given quadratic element
2188 //=============================================================================
2190 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2192 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2193 if ( aSMESHDS_Mesh == NULL ) return false;
2195 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2196 if(!aNode) return false;
2197 // try to find element
2198 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2199 if(!elem) return false;
2201 return elem->IsMediumNode(aNode);
2205 //=============================================================================
2207 * Returns true if given node is medium node
2208 * in one of quadratic elements
2210 //=============================================================================
2212 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2213 SMESH::ElementType theElemType)
2215 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2216 if ( aSMESHDS_Mesh == NULL ) return false;
2219 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2220 if(!aNode) return false;
2222 SMESH_MesherHelper aHelper( *(_impl) );
2224 SMDSAbs_ElementType aType;
2225 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2226 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2227 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2228 else aType = SMDSAbs_All;
2230 return aHelper.IsMedium(aNode,aType);
2234 //=============================================================================
2236 * Returns number of edges for given element
2238 //=============================================================================
2240 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2242 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2243 if ( aSMESHDS_Mesh == NULL ) return -1;
2244 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2245 if(!elem) return -1;
2246 return elem->NbEdges();
2250 //=============================================================================
2252 * Returns number of faces for given element
2254 //=============================================================================
2256 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2258 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2259 if ( aSMESHDS_Mesh == NULL ) return -1;
2260 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2261 if(!elem) return -1;
2262 return elem->NbFaces();
2266 //=============================================================================
2268 * Returns true if given element is polygon
2270 //=============================================================================
2272 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2274 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2275 if ( aSMESHDS_Mesh == NULL ) return false;
2276 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2277 if(!elem) return false;
2278 return elem->IsPoly();
2282 //=============================================================================
2284 * Returns true if given element is quadratic
2286 //=============================================================================
2288 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2290 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2291 if ( aSMESHDS_Mesh == NULL ) return false;
2292 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2293 if(!elem) return false;
2294 return elem->IsQuadratic();
2298 //=============================================================================
2300 * Returns bary center for given element
2302 //=============================================================================
2304 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2306 SMESH::double_array_var aResult = new SMESH::double_array();
2307 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2308 if ( aSMESHDS_Mesh == NULL )
2309 return aResult._retn();
2311 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2313 return aResult._retn();
2315 if(elem->GetType()==SMDSAbs_Volume) {
2316 // use SMDS_VolumeTool
2317 SMDS_VolumeTool aTool;
2318 if(aTool.Set(elem)) {
2319 double x=0., y=0., z=0.;
2320 if(aTool.GetBaryCenter(x,y,z)) {
2330 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2332 double x=0., y=0., z=0.;
2333 for(; anIt->more(); ) {
2335 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2349 return aResult._retn();
2353 //=============================================================================
2357 //=============================================================================
2358 void SMESH_Mesh_i::CreateGroupServants()
2360 // Create group servants, if any groups were imported
2361 list<int> aGroupIds = _impl->GetGroupIds();
2362 for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
2363 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
2365 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2366 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2367 aGroupImpl->Register();
2368 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2370 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
2371 _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
2373 // register CORBA object for persistence
2374 int nextId = _gen_i->RegisterObject( aGroup );
2375 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);