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"
31 #include "SMESH_Filter_i.hxx"
32 #include "SMESH_Gen_i.hxx"
33 #include "SMESH_Group_i.hxx"
34 #include "SMESH_MEDMesh_i.hxx"
35 #include "SMESH_MeshEditor_i.hxx"
36 #include "SMESH_PythonDump.hxx"
37 #include "SMESH_subMesh_i.hxx"
39 #include "DriverMED_R_SMESHDS_Mesh.h"
40 #include "DriverMED_W_SMESHDS_Mesh.h"
41 #include "SMDS_VolumeTool.hxx"
42 #include "SMESHDS_Command.hxx"
43 #include "SMESHDS_CommandType.hxx"
44 #include "SMESHDS_GroupOnGeom.hxx"
45 #include "SMESH_Group.hxx"
46 #include "SMESH_MeshEditor.hxx"
47 #include "SMESH_MesherHelper.hxx"
48 #include "SMDS_EdgePosition.hxx"
49 #include "SMDS_FacePosition.hxx"
52 #include "SALOME_NamingService.hxx"
53 #include "Utils_CorbaException.hxx"
54 #include "Utils_ExceptHandlers.hxx"
55 #include "Utils_SINGLETON.hxx"
56 #include "utilities.h"
59 #include <BRep_Builder.hxx>
60 #include <OSD_Directory.hxx>
61 #include <OSD_File.hxx>
62 #include <OSD_Path.hxx>
63 #include <OSD_Protection.hxx>
64 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
65 #include <TColStd_MapOfInteger.hxx>
66 #include <TColStd_SequenceOfInteger.hxx>
67 #include <TCollection_AsciiString.hxx>
68 #include <TopExp_Explorer.hxx>
69 #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() );
121 // this method is colled from destructor of group (PAL6331)
122 //_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);
152 //================================================================================
154 * \brief return true if mesh has a shape to build a shape on
156 //================================================================================
158 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
159 throw (SALOME::SALOME_Exception)
161 Unexpect aCatch(SALOME_SalomeException);
164 res = _impl->HasShapeToMesh();
166 catch(SALOME_Exception & S_ex) {
167 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
172 //=======================================================================
173 //function : GetShapeToMesh
175 //=======================================================================
177 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
178 throw (SALOME::SALOME_Exception)
180 Unexpect aCatch(SALOME_SalomeException);
181 GEOM::GEOM_Object_var aShapeObj;
183 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
185 aShapeObj = _gen_i->ShapeToGeomObject( S );
187 catch(SALOME_Exception & S_ex) {
188 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
190 return aShapeObj._retn();
193 //================================================================================
195 * \brief Remove all nodes and elements
197 //================================================================================
199 void SMESH_Mesh_i::Clear() throw (SALOME::SALOME_Exception)
201 Unexpect aCatch(SALOME_SalomeException);
205 catch(SALOME_Exception & S_ex) {
206 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
208 TPythonDump() << _this() << ".Clear()";
211 //=============================================================================
215 //=============================================================================
217 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
219 SMESH::DriverMED_ReadStatus res;
222 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
223 res = SMESH::DRS_OK; break;
224 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
225 res = SMESH::DRS_EMPTY; break;
226 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
227 res = SMESH::DRS_WARN_RENUMBER; break;
228 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
229 res = SMESH::DRS_WARN_SKIP_ELEM; break;
230 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
232 res = SMESH::DRS_FAIL; break;
237 //=============================================================================
241 * Imports mesh data from MED file
243 //=============================================================================
245 SMESH::DriverMED_ReadStatus
246 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
247 throw ( SALOME::SALOME_Exception )
249 Unexpect aCatch(SALOME_SalomeException);
252 status = _impl->MEDToMesh( theFileName, theMeshName );
254 catch( SALOME_Exception& S_ex ) {
255 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
258 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
261 CreateGroupServants();
263 return ConvertDriverMEDReadStatus(status);
266 //================================================================================
268 * \brief Return string representation of a MED file version comprising nbDigits
270 //================================================================================
272 char* SMESH_Mesh_i::GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits)
274 std::string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(MED::EVersion(version),
276 return CORBA::string_dup( ver.c_str() );
279 //=============================================================================
283 * Imports mesh data from MED file
285 //=============================================================================
287 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
288 throw ( SALOME::SALOME_Exception )
290 // Read mesh with name = <theMeshName> into SMESH_Mesh
291 _impl->UNVToMesh( theFileName );
293 CreateGroupServants();
298 //=============================================================================
302 * Imports mesh data from STL file
304 //=============================================================================
305 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
306 throw ( SALOME::SALOME_Exception )
308 // Read mesh with name = <theMeshName> into SMESH_Mesh
309 _impl->STLToMesh( theFileName );
314 //=============================================================================
318 * Imports mesh data from MED file
320 //=============================================================================
322 // int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
324 // // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
325 // int status = _impl->MEDToMesh( theFileName, theMeshName );
326 // CreateGroupServants();
331 //=============================================================================
335 //=============================================================================
337 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
339 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
340 (SMESH_Hypothesis::Hypothesis_Status theStatus)
343 RETURNCASE( HYP_OK );
344 RETURNCASE( HYP_MISSING );
345 RETURNCASE( HYP_CONCURENT );
346 RETURNCASE( HYP_BAD_PARAMETER );
347 RETURNCASE( HYP_HIDDEN_ALGO );
348 RETURNCASE( HYP_HIDING_ALGO );
349 RETURNCASE( HYP_UNKNOWN_FATAL );
350 RETURNCASE( HYP_INCOMPATIBLE );
351 RETURNCASE( HYP_NOTCONFORM );
352 RETURNCASE( HYP_ALREADY_EXIST );
353 RETURNCASE( HYP_BAD_DIM );
354 RETURNCASE( HYP_BAD_SUBSHAPE );
355 RETURNCASE( HYP_BAD_GEOMETRY );
358 return SMESH::HYP_UNKNOWN_FATAL;
361 //=============================================================================
365 * calls internal addHypothesis() and then adds a reference to <anHyp> under
366 * the SObject actually having a reference to <aSubShape>.
367 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
369 //=============================================================================
371 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
372 SMESH::SMESH_Hypothesis_ptr anHyp)
373 throw(SALOME::SALOME_Exception)
375 Unexpect aCatch(SALOME_SalomeException);
376 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
378 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
379 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
380 aSubShapeObject, anHyp );
382 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
384 // Update Python script
385 if(_impl->HasShapeToMesh()) {
386 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
387 << aSubShapeObject << ", " << anHyp << " )";
390 TPythonDump() << "status = " << _this() << ".AddHypothesis( "<< anHyp << " )";
393 return ConvertHypothesisStatus(status);
396 //=============================================================================
400 //=============================================================================
402 SMESH_Hypothesis::Hypothesis_Status
403 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
404 SMESH::SMESH_Hypothesis_ptr anHyp)
406 if(MYDEBUG) MESSAGE("addHypothesis");
408 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
409 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
412 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
413 if (CORBA::is_nil(myHyp))
414 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
417 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
420 TopoDS_Shape myLocSubShape;
421 //use PseudoShape in case if mesh has no shape
423 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
425 myLocSubShape = _impl->GetShapeToMesh();
427 int hypId = myHyp->GetId();
428 status = _impl->AddHypothesis(myLocSubShape, hypId);
429 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
430 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
431 // assure there is a corresponding submesh
432 if ( !_impl->IsMainShape( myLocSubShape )) {
433 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
434 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
435 createSubMesh( aSubShapeObject );
439 catch(SALOME_Exception & S_ex)
441 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
446 //=============================================================================
450 //=============================================================================
452 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
453 SMESH::SMESH_Hypothesis_ptr anHyp)
454 throw(SALOME::SALOME_Exception)
456 Unexpect aCatch(SALOME_SalomeException);
457 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
459 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
460 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
461 aSubShapeObject, anHyp );
463 // Update Python script
464 // Update Python script
465 if(_impl->HasShapeToMesh()) {
466 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
467 << aSubShapeObject << ", " << anHyp << " )";
470 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
474 return ConvertHypothesisStatus(status);
477 //=============================================================================
481 //=============================================================================
483 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
484 SMESH::SMESH_Hypothesis_ptr anHyp)
486 if(MYDEBUG) MESSAGE("removeHypothesis()");
487 // **** proposer liste de subShape (selection multiple)
489 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
490 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
493 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
494 if (CORBA::is_nil(myHyp))
495 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
498 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
501 TopoDS_Shape myLocSubShape;
502 //use PseudoShape in case if mesh has no shape
504 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
506 myLocSubShape = _impl->GetShapeToMesh();
508 int hypId = myHyp->GetId();
509 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
510 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
511 _mapHypo.erase( hypId );
513 catch(SALOME_Exception & S_ex)
515 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
520 //=============================================================================
524 //=============================================================================
526 SMESH::ListOfHypothesis *
527 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
528 throw(SALOME::SALOME_Exception)
530 Unexpect aCatch(SALOME_SalomeException);
531 if (MYDEBUG) MESSAGE("GetHypothesisList");
532 if (CORBA::is_nil(aSubShapeObject))
533 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
536 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
539 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
540 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
541 int i = 0, n = aLocalList.size();
544 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
545 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
546 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
547 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
552 catch(SALOME_Exception & S_ex) {
553 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
556 return aList._retn();
559 //=============================================================================
563 //=============================================================================
564 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
565 const char* theName )
566 throw(SALOME::SALOME_Exception)
568 Unexpect aCatch(SALOME_SalomeException);
569 MESSAGE("SMESH_Mesh_i::GetSubMesh");
570 if (CORBA::is_nil(aSubShapeObject))
571 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
574 SMESH::SMESH_subMesh_var subMesh;
575 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
577 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
579 //Get or Create the SMESH_subMesh object implementation
581 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
582 subMesh = getSubMesh( subMeshId );
584 // create a new subMesh object servant if there is none for the shape
585 if ( subMesh->_is_nil() )
586 subMesh = createSubMesh( aSubShapeObject );
588 if ( _gen_i->CanPublishInStudy( subMesh )) {
589 SALOMEDS::SObject_var aSO =
590 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
591 subMesh, aSubShapeObject, theName );
592 if ( !aSO->_is_nil()) {
593 // Update Python script
594 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
595 << aSubShapeObject << ", '" << theName << "' )";
599 catch(SALOME_Exception & S_ex) {
600 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
602 return subMesh._retn();
605 //=============================================================================
609 //=============================================================================
611 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
612 throw (SALOME::SALOME_Exception)
614 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
615 if ( theSubMesh->_is_nil() )
618 GEOM::GEOM_Object_var aSubShapeObject;
619 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
620 if ( !aStudy->_is_nil() ) {
621 // Remove submesh's SObject
622 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
623 if ( !anSO->_is_nil() ) {
624 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
625 SALOMEDS::SObject_var anObj, aRef;
626 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
627 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
629 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
631 // Update Python script
632 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
636 removeSubMesh( theSubMesh, aSubShapeObject.in() );
639 //=============================================================================
643 //=============================================================================
644 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
645 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
647 switch (theElemType) {
652 CASE2STRING( VOLUME );
658 //=============================================================================
662 //=============================================================================
664 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
665 const char* theName )
666 throw(SALOME::SALOME_Exception)
668 Unexpect aCatch(SALOME_SalomeException);
669 SMESH::SMESH_Group_var aNewGroup =
670 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
672 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
673 SALOMEDS::SObject_var aSO =
674 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
675 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
676 if ( !aSO->_is_nil()) {
677 // Update Python script
678 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
679 << ElementTypeString(theElemType) << ", '" << theName << "' )";
682 return aNewGroup._retn();
686 //=============================================================================
690 //=============================================================================
691 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
693 GEOM::GEOM_Object_ptr theGeomObj)
694 throw(SALOME::SALOME_Exception)
696 Unexpect aCatch(SALOME_SalomeException);
697 SMESH::SMESH_GroupOnGeom_var aNewGroup;
699 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
700 if ( !aShape.IsNull() ) {
701 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
702 ( createGroup( theElemType, theName, aShape ));
703 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
704 SALOMEDS::SObject_var aSO =
705 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
706 aNewGroup, theGeomObj, theName);
707 if ( !aSO->_is_nil()) {
708 // Update Python script
709 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
710 << ElementTypeString(theElemType) << ", '" << theName << "', "
711 << theGeomObj << " )";
716 return aNewGroup._retn();
719 //=============================================================================
723 //=============================================================================
725 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
726 throw (SALOME::SALOME_Exception)
728 if ( theGroup->_is_nil() )
731 SMESH_GroupBase_i* aGroup =
732 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
736 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
737 if ( !aStudy->_is_nil() ) {
738 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
740 if ( !aGroupSO->_is_nil() ) {
741 // Update Python script
742 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
744 // Remove group's SObject
745 aStudy->NewBuilder()->RemoveObjectWithChildren( aGroupSO );
749 // Remove the group from SMESH data structures
750 removeGroup( aGroup->GetLocalID() );
753 //=============================================================================
754 /*! RemoveGroupWithContents
755 * Remove group with its contents
757 //=============================================================================
758 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
759 throw (SALOME::SALOME_Exception)
761 if ( theGroup->_is_nil() )
764 SMESH_GroupBase_i* aGroup =
765 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
769 SMESH::long_array_var anIds = aGroup->GetListOfID();
770 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
772 // Update Python script
773 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
776 if ( aGroup->GetType() == SMESH::NODE )
777 aMeshEditor->RemoveNodes( anIds );
779 aMeshEditor->RemoveElements( anIds );
782 RemoveGroup( theGroup );
784 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
785 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
786 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
790 //================================================================================
792 * \brief Get the list of groups existing in the mesh
793 * \retval SMESH::ListOfGroups * - list of groups
795 //================================================================================
797 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
799 Unexpect aCatch(SALOME_SalomeException);
800 if (MYDEBUG) MESSAGE("GetGroups");
802 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
805 TPythonDump aPythonDump;
806 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
810 aList->length( _mapGroups.size() );
812 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
813 for ( ; it != _mapGroups.end(); it++ ) {
814 if ( CORBA::is_nil( it->second )) continue;
815 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
817 if (i > 1) aPythonDump << ", ";
818 aPythonDump << it->second;
822 catch(SALOME_Exception & S_ex) {
823 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
826 // Update Python script
827 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
828 aPythonDump << " ] = " << _this() << ".GetGroups()";
830 return aList._retn();
832 //=============================================================================
834 * Get number of groups existing in the mesh
836 //=============================================================================
838 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
840 Unexpect aCatch(SALOME_SalomeException);
841 return _mapGroups.size();
844 //=============================================================================
846 * New group is created. All mesh elements that are
847 * present in initial groups are added to the new one
849 //=============================================================================
850 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
851 SMESH::SMESH_GroupBase_ptr theGroup2,
852 const char* theName )
853 throw (SALOME::SALOME_Exception)
857 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
858 theGroup1->GetType() != theGroup2->GetType() )
859 return SMESH::SMESH_Group::_nil();
862 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
863 if ( aResGrp->_is_nil() )
864 return SMESH::SMESH_Group::_nil();
866 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
867 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
869 TColStd_MapOfInteger aResMap;
871 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
872 aResMap.Add( anIds1[ i1 ] );
874 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
875 aResMap.Add( anIds2[ i2 ] );
877 SMESH::long_array_var aResIds = new SMESH::long_array;
878 aResIds->length( aResMap.Extent() );
881 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
882 for( ; anIter.More(); anIter.Next() )
883 aResIds[ resI++ ] = anIter.Key();
885 aResGrp->Add( aResIds );
887 // Clear python lines, created by CreateGroup() and Add()
888 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
889 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
890 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
892 // Update Python script
893 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
894 << theGroup1 << ", " << theGroup2 << ", '"
897 return aResGrp._retn();
901 return SMESH::SMESH_Group::_nil();
905 //=============================================================================
907 * New group is created. All mesh elements that are
908 * present in both initial groups are added to the new one.
910 //=============================================================================
911 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
912 SMESH::SMESH_GroupBase_ptr theGroup2,
913 const char* theName )
914 throw (SALOME::SALOME_Exception)
916 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
917 theGroup1->GetType() != theGroup2->GetType() )
918 return SMESH::SMESH_Group::_nil();
920 // Create Intersection
921 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
922 if ( aResGrp->_is_nil() )
925 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
926 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
928 TColStd_MapOfInteger aMap1;
930 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
931 aMap1.Add( anIds1[ i1 ] );
933 TColStd_SequenceOfInteger aSeq;
935 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
936 if ( aMap1.Contains( anIds2[ i2 ] ) )
937 aSeq.Append( anIds2[ i2 ] );
939 SMESH::long_array_var aResIds = new SMESH::long_array;
940 aResIds->length( aSeq.Length() );
942 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
943 aResIds[ resI ] = aSeq( resI + 1 );
945 aResGrp->Add( aResIds );
947 // Clear python lines, created by CreateGroup() and Add()
948 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
949 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
950 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
952 // Update Python script
953 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
954 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
956 return aResGrp._retn();
959 //=============================================================================
961 * New group is created. All mesh elements that are present in
962 * main group but do not present in tool group are added to the new one
964 //=============================================================================
965 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
966 SMESH::SMESH_GroupBase_ptr theGroup2,
967 const char* theName )
968 throw (SALOME::SALOME_Exception)
970 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
971 theGroup1->GetType() != theGroup2->GetType() )
972 return SMESH::SMESH_Group::_nil();
975 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
976 if ( aResGrp->_is_nil() )
979 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
980 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
982 TColStd_MapOfInteger aMap2;
984 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
985 aMap2.Add( anIds2[ i2 ] );
988 TColStd_SequenceOfInteger aSeq;
989 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
990 if ( !aMap2.Contains( anIds1[ i1 ] ) )
991 aSeq.Append( anIds1[ i1 ] );
993 SMESH::long_array_var aResIds = new SMESH::long_array;
994 aResIds->length( aSeq.Length() );
996 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
997 aResIds[ resI ] = aSeq( resI + 1 );
999 aResGrp->Add( aResIds );
1001 // Clear python lines, created by CreateGroup() and Add()
1002 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1003 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1004 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1006 // Update Python script
1007 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
1008 << theGroup1 << ", " << theGroup2 << ", '"
1009 << theName << "' )";
1011 return aResGrp._retn();
1014 //================================================================================
1016 * \brief Return group items of a group present in a study
1018 //================================================================================
1020 static GEOM::GEOM_Object_ptr getGroupItemsFromStudy(CORBA::Object_ptr theMesh,
1021 SMESH_Gen_i* theGen,
1022 list<TopoDS_Shape> & theItems)
1024 GEOM::GEOM_Object_var groupObj;
1025 SALOMEDS::Study_var study = theGen->GetCurrentStudy();
1026 GEOM::GEOM_Gen_var geomGen = theGen->GetGeomEngine();
1027 if ( study->_is_nil() || geomGen->_is_nil() )
1028 return groupObj._retn();
1030 GEOM::GEOM_IGroupOperations_var groupOp =
1031 geomGen->GetIGroupOperations( theGen->GetCurrentStudyID() );
1032 GEOM::GEOM_IShapesOperations_var shapeOp =
1033 geomGen->GetIShapesOperations( theGen->GetCurrentStudyID() );
1035 SALOMEDS::SObject_var meshOS = theGen->ObjectToSObject(study, theMesh);
1036 if ( meshOS->_is_nil() || groupOp->_is_nil() || shapeOp->_is_nil() )
1037 return groupObj._retn();
1038 SALOMEDS::SObject_var fatherSO = meshOS->GetFather();
1039 if ( fatherSO->_is_nil() || fatherSO->Tag() != theGen->GetSubMeshOnCompoundTag() )
1040 return groupObj._retn(); // keep only submeshes on groups
1042 SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(meshOS);
1043 if ( anIter->_is_nil() ) return groupObj._retn();
1044 for ( ; anIter->More(); anIter->Next())
1046 SALOMEDS::SObject_var aSObject = anIter->Value();
1047 SALOMEDS::SObject_var aRefSO;
1048 if ( !aSObject->_is_nil() && aSObject->ReferencedObject(aRefSO) )
1050 groupObj = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
1051 if ( groupObj->_is_nil() ) break;
1052 GEOM::ListOfLong_var ids = groupOp->GetObjects( groupObj );
1053 GEOM::GEOM_Object_var mainShape = groupObj->GetMainShape();
1054 for ( int i = 0; i < ids->length(); ++i ) {
1055 GEOM::GEOM_Object_var subShape = shapeOp->GetSubShape( mainShape, ids[i] );
1056 TopoDS_Shape S = theGen->GeomObjectToShape( subShape );
1058 theItems.push_back( S );
1063 return groupObj._retn();
1066 //=============================================================================
1068 * \brief Update hypotheses assigned to geom groups if the latter change
1070 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1072 //=============================================================================
1074 void SMESH_Mesh_i::CheckGeomGroupModif()
1076 if ( !_impl->HasShapeToMesh() ) return;
1078 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1079 if ( study->_is_nil() ) return;
1081 // check if items of groups changed
1082 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
1083 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
1085 const TopoDS_Shape & oldGroupShape = i_sm->second->GetSubShape();
1086 SMESHDS_SubMesh * oldDS = i_sm->second->GetSubMeshDS();
1087 if ( !oldDS /*|| !oldDS->IsComplexSubmesh()*/ )
1089 int oldID = i_sm->first;
1090 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldID );
1091 if ( i_smIor == _mapSubMeshIor.end() )
1093 list< TopoDS_Shape> newItems;
1094 GEOM::GEOM_Object_var groupObj = getGroupItemsFromStudy ( i_smIor->second, _gen_i, newItems );
1095 if ( groupObj->_is_nil() )
1098 int nbOldItems = oldDS->IsComplexSubmesh() ? oldDS->NbSubMeshes() : 1;
1099 int nbNewItems = newItems.size();
1100 bool groupChanged = ( nbOldItems != nbNewItems);
1101 if ( !groupChanged ) {
1102 if ( !oldDS->IsComplexSubmesh() ) { // old group has one item
1103 groupChanged = ( oldGroupShape != newItems.front() );
1106 list<TopoDS_Shape>::iterator item = newItems.begin();
1107 for ( ; item != newItems.end() && !groupChanged; ++item )
1109 SMESHDS_SubMesh * itemDS = _impl->GetMeshDS()->MeshElements( *item );
1110 groupChanged = ( !itemDS || !oldDS->ContainsSubMesh( itemDS ));
1114 // update hypotheses and submeshes if necessary
1117 // get a new group shape
1118 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1119 if ( !geomClient ) continue;
1120 TCollection_AsciiString groupIOR = _gen_i->GetGeomEngine()->GetStringFromIOR( groupObj );
1121 geomClient->RemoveShapeFromBuffer( groupIOR );
1122 TopoDS_Shape newGroupShape = _gen_i->GeomObjectToShape( groupObj );
1123 // update hypotheses
1124 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldGroupShape);
1125 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1126 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1128 _impl->RemoveHypothesis( oldGroupShape, (*hypIt)->GetID());
1129 _impl->AddHypothesis ( newGroupShape, (*hypIt)->GetID());
1131 // care of submeshes
1132 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newGroupShape );
1133 int newID = newSubmesh->GetId();
1134 if ( newID != oldID ) {
1135 _mapSubMesh [ newID ] = newSubmesh;
1136 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1137 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1138 _mapSubMesh.erase (oldID);
1139 _mapSubMesh_i.erase (oldID);
1140 _mapSubMeshIor.erase(oldID);
1141 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1147 //=============================================================================
1151 //=============================================================================
1153 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1155 if(MYDEBUG) MESSAGE( "createSubMesh" );
1156 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1158 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1159 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1160 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1161 SMESH::SMESH_subMesh_var subMesh
1162 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1164 _mapSubMesh[subMeshId] = mySubMesh;
1165 _mapSubMesh_i[subMeshId] = subMeshServant;
1166 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1168 // register CORBA object for persistence
1169 int nextId = _gen_i->RegisterObject( subMesh );
1170 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1172 return subMesh._retn();
1175 //=======================================================================
1176 //function : getSubMesh
1178 //=======================================================================
1180 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1182 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1183 if ( it == _mapSubMeshIor.end() )
1184 return SMESH::SMESH_subMesh::_nil();
1186 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1190 //=============================================================================
1194 //=============================================================================
1196 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1197 GEOM::GEOM_Object_ptr theSubShapeObject )
1199 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1200 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1204 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1205 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1206 removeHypothesis( theSubShapeObject, aHypList[i] );
1209 catch( const SALOME::SALOME_Exception& ) {
1210 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1213 int subMeshId = theSubMesh->GetId();
1215 _mapSubMesh.erase(subMeshId);
1216 _mapSubMesh_i.erase(subMeshId);
1217 _mapSubMeshIor.erase(subMeshId);
1218 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1221 //=============================================================================
1225 //=============================================================================
1227 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1228 const char* theName,
1229 const TopoDS_Shape& theShape )
1232 SMESH::SMESH_GroupBase_var aGroup;
1233 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1234 SMESH_GroupBase_i* aGroupImpl;
1235 if ( !theShape.IsNull() )
1236 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1238 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1240 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1241 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1242 aGroupImpl->Register();
1243 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1245 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1246 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1248 // register CORBA object for persistence
1249 int nextId = _gen_i->RegisterObject( aGroup );
1250 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1252 return aGroup._retn();
1255 //=============================================================================
1257 * SMESH_Mesh_i::removeGroup
1259 * Should be called by ~SMESH_Group_i()
1261 //=============================================================================
1263 void SMESH_Mesh_i::removeGroup( const int theId )
1265 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1266 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1267 _mapGroups.erase( theId );
1268 _impl->RemoveGroup( theId );
1273 //=============================================================================
1277 //=============================================================================
1279 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1280 throw(SALOME::SALOME_Exception)
1282 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1284 SMESH::log_array_var aLog;
1286 list < SMESHDS_Command * >logDS = _impl->GetLog();
1287 aLog = new SMESH::log_array;
1289 int lg = logDS.size();
1292 list < SMESHDS_Command * >::iterator its = logDS.begin();
1293 while(its != logDS.end()){
1294 SMESHDS_Command *com = *its;
1295 int comType = com->GetType();
1297 int lgcom = com->GetNumber();
1299 const list < int >&intList = com->GetIndexes();
1300 int inum = intList.size();
1302 list < int >::const_iterator ii = intList.begin();
1303 const list < double >&coordList = com->GetCoords();
1304 int rnum = coordList.size();
1306 list < double >::const_iterator ir = coordList.begin();
1307 aLog[indexLog].commandType = comType;
1308 aLog[indexLog].number = lgcom;
1309 aLog[indexLog].coords.length(rnum);
1310 aLog[indexLog].indexes.length(inum);
1311 for(int i = 0; i < rnum; i++){
1312 aLog[indexLog].coords[i] = *ir;
1313 //MESSAGE(" "<<i<<" "<<ir.Value());
1316 for(int i = 0; i < inum; i++){
1317 aLog[indexLog].indexes[i] = *ii;
1318 //MESSAGE(" "<<i<<" "<<ii.Value());
1327 catch(SALOME_Exception & S_ex){
1328 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1330 return aLog._retn();
1334 //=============================================================================
1338 //=============================================================================
1340 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1342 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1346 //=============================================================================
1350 //=============================================================================
1352 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1354 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1358 //=============================================================================
1362 //=============================================================================
1364 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1369 //=============================================================================
1373 //=============================================================================
1375 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1377 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1381 //=============================================================================
1385 //=============================================================================
1387 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1389 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1393 //=============================================================================
1395 * Return mesh editor
1397 //=============================================================================
1399 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1401 // Create MeshEditor
1402 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
1403 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1405 // Update Python script
1406 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1408 return aMesh._retn();
1411 //=============================================================================
1413 * Return mesh edition previewer
1415 //=============================================================================
1417 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1419 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
1420 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1421 return aMesh._retn();
1424 //=============================================================================
1428 //=============================================================================
1429 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
1431 Unexpect aCatch(SALOME_SalomeException);
1432 _impl->SetAutoColor(theAutoColor);
1435 //=============================================================================
1439 //=============================================================================
1440 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
1442 Unexpect aCatch(SALOME_SalomeException);
1443 return _impl->GetAutoColor();
1447 //=============================================================================
1449 * Export in different formats
1451 //=============================================================================
1453 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1455 return _impl->HasDuplicatedGroupNamesMED();
1458 void SMESH_Mesh_i::PrepareForWriting (const char* file)
1460 TCollection_AsciiString aFullName ((char*)file);
1461 OSD_Path aPath (aFullName);
1462 OSD_File aFile (aPath);
1463 if (aFile.Exists()) {
1464 // existing filesystem node
1465 if (aFile.KindOfFile() == OSD_FILE) {
1466 if (aFile.IsWriteable()) {
1469 if (aFile.Failed()) {
1470 TCollection_AsciiString msg ("File ");
1471 msg += aFullName + " cannot be replaced.";
1472 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1475 TCollection_AsciiString msg ("File ");
1476 msg += aFullName + " cannot be overwritten.";
1477 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1480 TCollection_AsciiString msg ("Location ");
1481 msg += aFullName + " is not a file.";
1482 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1485 // nonexisting file; check if it can be created
1487 aFile.Build(OSD_WriteOnly, OSD_Protection());
1488 if (aFile.Failed()) {
1489 TCollection_AsciiString msg ("You cannot create the file ");
1490 msg += aFullName + ". Check the directory existance and access rights.";
1491 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1499 void SMESH_Mesh_i::ExportToMED (const char* file,
1500 CORBA::Boolean auto_groups,
1501 SMESH::MED_VERSION theVersion)
1502 throw(SALOME::SALOME_Exception)
1504 Unexpect aCatch(SALOME_SalomeException);
1506 // Update Python script
1507 TPythonDump() << _this() << ".ExportToMED( '"
1508 << file << "', " << auto_groups << ", " << theVersion << " )";
1511 PrepareForWriting(file);
1512 char* aMeshName = "Mesh";
1513 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1514 if ( !aStudy->_is_nil() ) {
1515 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1516 if ( !aMeshSO->_is_nil() ) {
1517 aMeshName = aMeshSO->GetName();
1519 //SCRUTE(aMeshName);
1520 //SCRUTE(aMeshSO->GetID());
1522 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1523 if ( !aStudy->GetProperties()->IsLocked() )
1525 SALOMEDS::GenericAttribute_var anAttr;
1526 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1527 SALOMEDS::AttributeExternalFileDef_var aFileName;
1528 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1529 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1530 ASSERT(!aFileName->_is_nil());
1531 aFileName->SetValue(file);
1532 SALOMEDS::AttributeFileType_var aFileType;
1533 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1534 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1535 ASSERT(!aFileType->_is_nil());
1536 aFileType->SetValue("FICHIERMED");
1540 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1543 void SMESH_Mesh_i::ExportMED (const char* file,
1544 CORBA::Boolean auto_groups)
1545 throw(SALOME::SALOME_Exception)
1547 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1550 void SMESH_Mesh_i::ExportDAT (const char *file)
1551 throw(SALOME::SALOME_Exception)
1553 Unexpect aCatch(SALOME_SalomeException);
1555 // Update Python script
1556 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1559 PrepareForWriting(file);
1560 _impl->ExportDAT(file);
1563 void SMESH_Mesh_i::ExportUNV (const char *file)
1564 throw(SALOME::SALOME_Exception)
1566 Unexpect aCatch(SALOME_SalomeException);
1568 // Update Python script
1569 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1572 PrepareForWriting(file);
1573 _impl->ExportUNV(file);
1576 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1577 throw(SALOME::SALOME_Exception)
1579 Unexpect aCatch(SALOME_SalomeException);
1581 // Update Python script
1582 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1585 PrepareForWriting(file);
1586 _impl->ExportSTL(file, isascii);
1589 //=============================================================================
1593 //=============================================================================
1595 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1597 Unexpect aCatch(SALOME_SalomeException);
1598 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1599 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1600 return aMesh._retn();
1603 //=============================================================================
1607 //=============================================================================
1608 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1610 Unexpect aCatch(SALOME_SalomeException);
1611 return _impl->NbNodes();
1614 //=============================================================================
1618 //=============================================================================
1619 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1621 Unexpect aCatch(SALOME_SalomeException);
1622 return NbEdges() + NbFaces() + NbVolumes();
1625 //=============================================================================
1629 //=============================================================================
1630 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1632 Unexpect aCatch(SALOME_SalomeException);
1633 return _impl->NbEdges();
1636 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1637 throw(SALOME::SALOME_Exception)
1639 Unexpect aCatch(SALOME_SalomeException);
1640 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
1643 //=============================================================================
1647 //=============================================================================
1648 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1650 Unexpect aCatch(SALOME_SalomeException);
1651 return _impl->NbFaces();
1654 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1656 Unexpect aCatch(SALOME_SalomeException);
1657 return _impl->NbTriangles();
1660 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1662 Unexpect aCatch(SALOME_SalomeException);
1663 return _impl->NbQuadrangles();
1666 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1668 Unexpect aCatch(SALOME_SalomeException);
1669 return _impl->NbPolygons();
1672 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1673 throw(SALOME::SALOME_Exception)
1675 Unexpect aCatch(SALOME_SalomeException);
1676 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
1679 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1680 throw(SALOME::SALOME_Exception)
1682 Unexpect aCatch(SALOME_SalomeException);
1683 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
1686 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1687 throw(SALOME::SALOME_Exception)
1689 Unexpect aCatch(SALOME_SalomeException);
1690 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
1693 //=============================================================================
1697 //=============================================================================
1698 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1700 Unexpect aCatch(SALOME_SalomeException);
1701 return _impl->NbVolumes();
1704 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1706 Unexpect aCatch(SALOME_SalomeException);
1707 return _impl->NbTetras();
1710 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1712 Unexpect aCatch(SALOME_SalomeException);
1713 return _impl->NbHexas();
1716 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1718 Unexpect aCatch(SALOME_SalomeException);
1719 return _impl->NbPyramids();
1722 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1724 Unexpect aCatch(SALOME_SalomeException);
1725 return _impl->NbPrisms();
1728 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1730 Unexpect aCatch(SALOME_SalomeException);
1731 return _impl->NbPolyhedrons();
1734 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1735 throw(SALOME::SALOME_Exception)
1737 Unexpect aCatch(SALOME_SalomeException);
1738 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
1741 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1742 throw(SALOME::SALOME_Exception)
1744 Unexpect aCatch(SALOME_SalomeException);
1745 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
1748 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1749 throw(SALOME::SALOME_Exception)
1751 Unexpect aCatch(SALOME_SalomeException);
1752 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
1755 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1756 throw(SALOME::SALOME_Exception)
1758 Unexpect aCatch(SALOME_SalomeException);
1759 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
1762 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1763 throw(SALOME::SALOME_Exception)
1765 Unexpect aCatch(SALOME_SalomeException);
1766 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
1769 //=============================================================================
1773 //=============================================================================
1774 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1776 Unexpect aCatch(SALOME_SalomeException);
1777 return _impl->NbSubMesh();
1780 //=============================================================================
1784 //=============================================================================
1785 char* SMESH_Mesh_i::Dump()
1787 std::ostringstream os;
1789 return CORBA::string_dup( os.str().c_str() );
1792 //=============================================================================
1796 //=============================================================================
1797 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1799 // SMESH::long_array_var aResult = new SMESH::long_array();
1800 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1801 // int aMinId = aSMESHDS_Mesh->MinElementID();
1802 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1804 // aResult->length(aMaxId - aMinId + 1);
1806 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1807 // aResult[i++] = id;
1809 // return aResult._retn();
1811 return GetElementsId();
1814 //=============================================================================
1818 //=============================================================================
1820 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1821 throw (SALOME::SALOME_Exception)
1823 Unexpect aCatch(SALOME_SalomeException);
1824 MESSAGE("SMESH_Mesh_i::GetElementsId");
1825 SMESH::long_array_var aResult = new SMESH::long_array();
1826 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1828 if ( aSMESHDS_Mesh == NULL )
1829 return aResult._retn();
1831 long nbElements = NbElements();
1832 aResult->length( nbElements );
1833 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1834 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1835 aResult[i] = anIt->next()->GetID();
1837 return aResult._retn();
1841 //=============================================================================
1845 //=============================================================================
1847 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1848 throw (SALOME::SALOME_Exception)
1850 Unexpect aCatch(SALOME_SalomeException);
1851 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1852 SMESH::long_array_var aResult = new SMESH::long_array();
1853 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1855 if ( aSMESHDS_Mesh == NULL )
1856 return aResult._retn();
1858 long nbElements = NbElements();
1860 // No sense in returning ids of elements along with ids of nodes:
1861 // when theElemType == SMESH::ALL, return node ids only if
1862 // there are no elements
1863 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1864 return GetNodesId();
1866 aResult->length( nbElements );
1870 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1871 while ( i < nbElements && anIt->more() ) {
1872 const SMDS_MeshElement* anElem = anIt->next();
1873 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1874 aResult[i++] = anElem->GetID();
1877 aResult->length( i );
1879 return aResult._retn();
1882 //=============================================================================
1886 //=============================================================================
1888 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1889 throw (SALOME::SALOME_Exception)
1891 Unexpect aCatch(SALOME_SalomeException);
1892 MESSAGE("SMESH_subMesh_i::GetNodesId");
1893 SMESH::long_array_var aResult = new SMESH::long_array();
1894 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1896 if ( aSMESHDS_Mesh == NULL )
1897 return aResult._retn();
1899 long nbNodes = NbNodes();
1900 aResult->length( nbNodes );
1901 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1902 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1903 aResult[i] = anIt->next()->GetID();
1905 return aResult._retn();
1908 //=============================================================================
1912 //=============================================================================
1914 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1915 throw (SALOME::SALOME_Exception)
1917 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1921 //=============================================================================
1923 * Returns ID of elements for given submesh
1925 //=============================================================================
1926 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1927 throw (SALOME::SALOME_Exception)
1929 SMESH::long_array_var aResult = new SMESH::long_array();
1931 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1932 if(!SM) return aResult._retn();
1934 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1935 if(!SDSM) return aResult._retn();
1937 aResult->length(SDSM->NbElements());
1939 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1941 while ( eIt->more() ) {
1942 aResult[i++] = eIt->next()->GetID();
1945 return aResult._retn();
1949 //=============================================================================
1951 * Returns ID of nodes for given submesh
1952 * If param all==true - returns all nodes, else -
1953 * returns only nodes on shapes.
1955 //=============================================================================
1956 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1957 throw (SALOME::SALOME_Exception)
1959 SMESH::long_array_var aResult = new SMESH::long_array();
1961 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1962 if(!SM) return aResult._retn();
1964 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1965 if(!SDSM) return aResult._retn();
1968 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
1969 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1970 while ( nIt->more() ) {
1971 const SMDS_MeshNode* elem = nIt->next();
1972 theElems.insert( elem->GetID() );
1975 else { // all nodes of submesh elements
1976 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1977 while ( eIt->more() ) {
1978 const SMDS_MeshElement* anElem = eIt->next();
1979 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
1980 while ( nIt->more() ) {
1981 const SMDS_MeshElement* elem = nIt->next();
1982 theElems.insert( elem->GetID() );
1987 aResult->length(theElems.size());
1988 set<int>::iterator itElem;
1990 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
1991 aResult[i++] = *itElem;
1993 return aResult._retn();
1997 //=============================================================================
1999 * Returns type of elements for given submesh
2001 //=============================================================================
2002 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
2003 throw (SALOME::SALOME_Exception)
2005 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2006 if(!SM) return SMESH::ALL;
2008 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2009 if(!SDSM) return SMESH::ALL;
2011 if(SDSM->NbElements()==0)
2012 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
2014 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2015 const SMDS_MeshElement* anElem = eIt->next();
2016 return ( SMESH::ElementType ) anElem->GetType();
2020 //=============================================================================
2024 //=============================================================================
2026 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
2028 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
2029 cerr << "CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() " << pointeur << endl;
2034 //=============================================================================
2036 * Get XYZ coordinates of node as list of double
2037 * If there is not node for given ID - returns empty list
2039 //=============================================================================
2041 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2043 SMESH::double_array_var aResult = new SMESH::double_array();
2044 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2045 if ( aSMESHDS_Mesh == NULL )
2046 return aResult._retn();
2049 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2051 return aResult._retn();
2055 aResult[0] = aNode->X();
2056 aResult[1] = aNode->Y();
2057 aResult[2] = aNode->Z();
2058 return aResult._retn();
2062 //=============================================================================
2064 * For given node returns list of IDs of inverse elements
2065 * If there is not node for given ID - returns empty list
2067 //=============================================================================
2069 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2071 SMESH::long_array_var aResult = new SMESH::long_array();
2072 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2073 if ( aSMESHDS_Mesh == NULL )
2074 return aResult._retn();
2077 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2079 return aResult._retn();
2081 // find inverse elements
2082 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2083 TColStd_SequenceOfInteger IDs;
2084 while(eIt->more()) {
2085 const SMDS_MeshElement* elem = eIt->next();
2086 IDs.Append(elem->GetID());
2088 if(IDs.Length()>0) {
2089 aResult->length(IDs.Length());
2091 for(; i<=IDs.Length(); i++) {
2092 aResult[i-1] = IDs.Value(i);
2095 return aResult._retn();
2098 //=============================================================================
2100 * \brief Return position of a node on shape
2102 //=============================================================================
2104 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
2106 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
2107 aNodePosition->shapeID = 0;
2108 aNodePosition->shapeType = GEOM::SHAPE;
2110 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
2111 if ( !mesh ) return aNodePosition;
2113 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
2115 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
2117 aNodePosition->shapeID = pos->GetShapeId();
2118 switch ( pos->GetTypeOfPosition() ) {
2120 aNodePosition->shapeType = GEOM::EDGE;
2121 aNodePosition->params.length(1);
2122 aNodePosition->params[0] =
2123 static_cast<SMDS_EdgePosition*>( pos.get() )->GetUParameter();
2126 aNodePosition->shapeType = GEOM::FACE;
2127 aNodePosition->params.length(2);
2128 aNodePosition->params[0] =
2129 static_cast<SMDS_FacePosition*>( pos.get() )->GetUParameter();
2130 aNodePosition->params[1] =
2131 static_cast<SMDS_FacePosition*>( pos.get() )->GetVParameter();
2133 case SMDS_TOP_VERTEX:
2134 aNodePosition->shapeType = GEOM::VERTEX;
2136 case SMDS_TOP_3DSPACE:
2137 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
2138 aNodePosition->shapeType = GEOM::SOLID;
2139 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
2140 aNodePosition->shapeType = GEOM::SHELL;
2146 return aNodePosition;
2149 //=============================================================================
2151 * If given element is node returns IDs of shape from position
2152 * If there is not node for given ID - returns -1
2154 //=============================================================================
2156 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2158 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2159 if ( aSMESHDS_Mesh == NULL )
2163 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2165 SMDS_PositionPtr pos = aNode->GetPosition();
2169 return pos->GetShapeId();
2176 //=============================================================================
2178 * For given element returns ID of result shape after
2179 * ::FindShape() from SMESH_MeshEditor
2180 * If there is not element for given ID - returns -1
2182 //=============================================================================
2184 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2186 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2187 if ( aSMESHDS_Mesh == NULL )
2190 // try to find element
2191 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2195 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2196 ::SMESH_MeshEditor aMeshEditor(_impl);
2197 int index = aMeshEditor.FindShape( elem );
2205 //=============================================================================
2207 * Returns number of nodes for given element
2208 * If there is not element for given ID - returns -1
2210 //=============================================================================
2212 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2214 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2215 if ( aSMESHDS_Mesh == NULL ) return -1;
2216 // try to find element
2217 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2218 if(!elem) return -1;
2219 return elem->NbNodes();
2223 //=============================================================================
2225 * Returns ID of node by given index for given element
2226 * If there is not element for given ID - returns -1
2227 * If there is not node for given index - returns -2
2229 //=============================================================================
2231 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2233 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2234 if ( aSMESHDS_Mesh == NULL ) return -1;
2235 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2236 if(!elem) return -1;
2237 if( index>=elem->NbNodes() || index<0 ) return -1;
2238 return elem->GetNode(index)->GetID();
2241 //=============================================================================
2243 * Returns IDs of nodes of given element
2245 //=============================================================================
2247 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2249 SMESH::long_array_var aResult = new SMESH::long_array();
2250 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2252 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2254 aResult->length( elem->NbNodes() );
2255 for ( int i = 0; i < elem->NbNodes(); ++i )
2256 aResult[ i ] = elem->GetNode( i )->GetID();
2259 return aResult._retn();
2262 //=============================================================================
2264 * Returns true if given node is medium node
2265 * in given quadratic element
2267 //=============================================================================
2269 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2271 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2272 if ( aSMESHDS_Mesh == NULL ) return false;
2274 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2275 if(!aNode) return false;
2276 // try to find element
2277 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2278 if(!elem) return false;
2280 return elem->IsMediumNode(aNode);
2284 //=============================================================================
2286 * Returns true if given node is medium node
2287 * in one of quadratic elements
2289 //=============================================================================
2291 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2292 SMESH::ElementType theElemType)
2294 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2295 if ( aSMESHDS_Mesh == NULL ) return false;
2298 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2299 if(!aNode) return false;
2301 SMESH_MesherHelper aHelper( *(_impl) );
2303 SMDSAbs_ElementType aType;
2304 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2305 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2306 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2307 else aType = SMDSAbs_All;
2309 return aHelper.IsMedium(aNode,aType);
2313 //=============================================================================
2315 * Returns number of edges for given element
2317 //=============================================================================
2319 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2321 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2322 if ( aSMESHDS_Mesh == NULL ) return -1;
2323 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2324 if(!elem) return -1;
2325 return elem->NbEdges();
2329 //=============================================================================
2331 * Returns number of faces for given element
2333 //=============================================================================
2335 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2337 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2338 if ( aSMESHDS_Mesh == NULL ) return -1;
2339 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2340 if(!elem) return -1;
2341 return elem->NbFaces();
2345 //=============================================================================
2347 * Returns true if given element is polygon
2349 //=============================================================================
2351 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2353 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2354 if ( aSMESHDS_Mesh == NULL ) return false;
2355 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2356 if(!elem) return false;
2357 return elem->IsPoly();
2361 //=============================================================================
2363 * Returns true if given element is quadratic
2365 //=============================================================================
2367 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2369 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2370 if ( aSMESHDS_Mesh == NULL ) return false;
2371 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2372 if(!elem) return false;
2373 return elem->IsQuadratic();
2377 //=============================================================================
2379 * Returns bary center for given element
2381 //=============================================================================
2383 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2385 SMESH::double_array_var aResult = new SMESH::double_array();
2386 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2387 if ( aSMESHDS_Mesh == NULL )
2388 return aResult._retn();
2390 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2392 return aResult._retn();
2394 if(elem->GetType()==SMDSAbs_Volume) {
2395 SMDS_VolumeTool aTool;
2396 if(aTool.Set(elem)) {
2398 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
2403 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2405 double x=0., y=0., z=0.;
2406 for(; anIt->more(); ) {
2408 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2422 return aResult._retn();
2426 //=============================================================================
2428 * Create and publish group servants if any groups were imported or created anyhow
2430 //=============================================================================
2432 void SMESH_Mesh_i::CreateGroupServants()
2434 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2436 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
2437 while ( groupIt->more() )
2439 ::SMESH_Group* group = groupIt->next();
2440 int anId = group->GetGroupDS()->GetID();
2442 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
2443 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2446 SMESH_GroupBase_i* aGroupImpl;
2448 if ( SMESHDS_GroupOnGeom* groupOnGeom =
2449 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
2451 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
2452 shape = groupOnGeom->GetShape();
2455 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2458 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
2459 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2460 aGroupImpl->Register();
2462 SMESH::SMESH_GroupBase_var groupVar =
2463 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
2464 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
2466 // register CORBA object for persistence
2467 int nextId = _gen_i->RegisterObject( groupVar );
2468 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
2470 // publishing of the groups in the study
2471 if ( !aStudy->_is_nil() ) {
2472 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
2473 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
2478 //=============================================================================
2480 * \brief Return groups cantained in _mapGroups by their IDs
2482 //=============================================================================
2484 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
2486 int nbGroups = groupIDs.size();
2487 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
2488 aList->length( nbGroups );
2490 list<int>::const_iterator ids = groupIDs.begin();
2491 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
2493 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
2494 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2495 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
2497 aList->length( nbGroups );
2498 return aList._retn();