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() );
120 // this method is colled from destructor of group (PAL6331)
121 //_impl->RemoveGroup( aGroup->GetLocalID() );
130 //=============================================================================
134 * Associates <this> mesh with <theShape> and puts a reference
135 * to <theShape> into the current study;
136 * the previous shape is substituted by the new one.
138 //=============================================================================
140 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
141 throw (SALOME::SALOME_Exception)
143 Unexpect aCatch(SALOME_SalomeException);
145 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
147 catch(SALOME_Exception & S_ex) {
148 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
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 //=============================================================================
197 //=============================================================================
199 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
201 SMESH::DriverMED_ReadStatus res;
204 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
205 res = SMESH::DRS_OK; break;
206 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
207 res = SMESH::DRS_EMPTY; break;
208 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
209 res = SMESH::DRS_WARN_RENUMBER; break;
210 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
211 res = SMESH::DRS_WARN_SKIP_ELEM; break;
212 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
214 res = SMESH::DRS_FAIL; break;
219 //=============================================================================
223 * Imports mesh data from MED file
225 //=============================================================================
227 SMESH::DriverMED_ReadStatus
228 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
229 throw ( SALOME::SALOME_Exception )
231 Unexpect aCatch(SALOME_SalomeException);
234 status = _impl->MEDToMesh( theFileName, theMeshName );
236 catch( SALOME_Exception& S_ex ) {
237 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
240 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
243 myFile = theFileName;
244 CreateGroupServants();
246 return ConvertDriverMEDReadStatus(status);
249 //================================================================================
251 * \brief Return string representation of a MED file version comprising nbDigits
253 //================================================================================
255 char* SMESH_Mesh_i::GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits)
257 std::string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(MED::EVersion(version),
259 return CORBA::string_dup( ver.c_str() );
262 //=============================================================================
266 * Imports mesh data from MED file
268 //=============================================================================
270 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
271 throw ( SALOME::SALOME_Exception )
273 // Read mesh with name = <theMeshName> into SMESH_Mesh
274 _impl->UNVToMesh( theFileName );
276 CreateGroupServants();
281 //=============================================================================
285 * Imports mesh data from STL file
287 //=============================================================================
288 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
289 throw ( SALOME::SALOME_Exception )
291 // Read mesh with name = <theMeshName> into SMESH_Mesh
292 _impl->STLToMesh( theFileName );
297 //=============================================================================
301 * Imports mesh data from MED file
303 //=============================================================================
305 // int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
307 // // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
308 // int status = _impl->MEDToMesh( theFileName, theMeshName );
309 // CreateGroupServants();
314 //=============================================================================
318 //=============================================================================
320 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
322 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
323 (SMESH_Hypothesis::Hypothesis_Status theStatus)
326 RETURNCASE( HYP_OK );
327 RETURNCASE( HYP_MISSING );
328 RETURNCASE( HYP_CONCURENT );
329 RETURNCASE( HYP_BAD_PARAMETER );
330 RETURNCASE( HYP_HIDDEN_ALGO );
331 RETURNCASE( HYP_HIDING_ALGO );
332 RETURNCASE( HYP_UNKNOWN_FATAL );
333 RETURNCASE( HYP_INCOMPATIBLE );
334 RETURNCASE( HYP_NOTCONFORM );
335 RETURNCASE( HYP_ALREADY_EXIST );
336 RETURNCASE( HYP_BAD_DIM );
337 RETURNCASE( HYP_BAD_SUBSHAPE );
338 RETURNCASE( HYP_BAD_GEOMETRY );
341 return SMESH::HYP_UNKNOWN_FATAL;
344 //=============================================================================
348 * calls internal addHypothesis() and then adds a reference to <anHyp> under
349 * the SObject actually having a reference to <aSubShape>.
350 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
352 //=============================================================================
354 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
355 SMESH::SMESH_Hypothesis_ptr anHyp)
356 throw(SALOME::SALOME_Exception)
358 Unexpect aCatch(SALOME_SalomeException);
359 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
361 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
362 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
363 aSubShapeObject, anHyp );
365 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
367 // Update Python script
368 if(_impl->HasShapeToMesh()) {
369 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
370 << aSubShapeObject << ", " << anHyp << " )";
373 TPythonDump() << "status = " << _this() << ".AddHypothesis( "<< anHyp << " )";
376 return ConvertHypothesisStatus(status);
379 //=============================================================================
383 //=============================================================================
385 SMESH_Hypothesis::Hypothesis_Status
386 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
387 SMESH::SMESH_Hypothesis_ptr anHyp)
389 if(MYDEBUG) MESSAGE("addHypothesis");
391 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
392 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
395 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
396 if (CORBA::is_nil(myHyp))
397 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
400 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
403 TopoDS_Shape myLocSubShape;
404 //use PseudoShape in case if mesh has no shape
406 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
408 myLocSubShape = _impl->GetShapeToMesh();
410 int hypId = myHyp->GetId();
411 status = _impl->AddHypothesis(myLocSubShape, hypId);
412 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
413 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
414 // assure there is a corresponding submesh
415 if ( !_impl->IsMainShape( myLocSubShape )) {
416 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
417 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
418 createSubMesh( aSubShapeObject );
422 catch(SALOME_Exception & S_ex)
424 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
429 //=============================================================================
433 //=============================================================================
435 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
436 SMESH::SMESH_Hypothesis_ptr anHyp)
437 throw(SALOME::SALOME_Exception)
439 Unexpect aCatch(SALOME_SalomeException);
440 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
442 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
443 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
444 aSubShapeObject, anHyp );
446 // Update Python script
447 // Update Python script
448 if(_impl->HasShapeToMesh()) {
449 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
450 << aSubShapeObject << ", " << anHyp << " )";
453 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
457 return ConvertHypothesisStatus(status);
460 //=============================================================================
464 //=============================================================================
466 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
467 SMESH::SMESH_Hypothesis_ptr anHyp)
469 if(MYDEBUG) MESSAGE("removeHypothesis()");
470 // **** proposer liste de subShape (selection multiple)
472 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
473 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
476 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
477 if (CORBA::is_nil(myHyp))
478 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
481 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
484 TopoDS_Shape myLocSubShape;
485 //use PseudoShape in case if mesh has no shape
487 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
489 myLocSubShape = _impl->GetShapeToMesh();
491 int hypId = myHyp->GetId();
492 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
493 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
494 _mapHypo.erase( hypId );
496 catch(SALOME_Exception & S_ex)
498 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
503 //=============================================================================
507 //=============================================================================
509 SMESH::ListOfHypothesis *
510 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
511 throw(SALOME::SALOME_Exception)
513 Unexpect aCatch(SALOME_SalomeException);
514 if (MYDEBUG) MESSAGE("GetHypothesisList");
515 if (CORBA::is_nil(aSubShapeObject))
516 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
519 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
522 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
523 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
524 int i = 0, n = aLocalList.size();
527 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
528 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
529 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
530 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
535 catch(SALOME_Exception & S_ex) {
536 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
539 return aList._retn();
542 //=============================================================================
546 //=============================================================================
547 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
548 const char* theName )
549 throw(SALOME::SALOME_Exception)
551 Unexpect aCatch(SALOME_SalomeException);
552 MESSAGE("SMESH_Mesh_i::GetSubMesh");
553 if (CORBA::is_nil(aSubShapeObject))
554 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
557 SMESH::SMESH_subMesh_var subMesh;
558 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
560 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
562 //Get or Create the SMESH_subMesh object implementation
564 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
565 subMesh = getSubMesh( subMeshId );
567 // create a new subMesh object servant if there is none for the shape
568 if ( subMesh->_is_nil() )
569 subMesh = createSubMesh( aSubShapeObject );
571 if ( _gen_i->CanPublishInStudy( subMesh )) {
572 SALOMEDS::SObject_var aSO =
573 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
574 subMesh, aSubShapeObject, theName );
575 if ( !aSO->_is_nil()) {
576 // Update Python script
577 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
578 << aSubShapeObject << ", '" << theName << "' )";
582 catch(SALOME_Exception & S_ex) {
583 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
585 return subMesh._retn();
588 //=============================================================================
592 //=============================================================================
594 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
595 throw (SALOME::SALOME_Exception)
597 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
598 if ( theSubMesh->_is_nil() )
601 GEOM::GEOM_Object_var aSubShapeObject;
602 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
603 if ( !aStudy->_is_nil() ) {
604 // Remove submesh's SObject
605 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
606 if ( !anSO->_is_nil() ) {
607 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
608 SALOMEDS::SObject_var anObj, aRef;
609 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
610 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
612 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
614 // Update Python script
615 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
619 removeSubMesh( theSubMesh, aSubShapeObject.in() );
622 //=============================================================================
626 //=============================================================================
627 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
628 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
630 switch (theElemType) {
635 CASE2STRING( VOLUME );
641 //=============================================================================
645 //=============================================================================
647 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
648 const char* theName )
649 throw(SALOME::SALOME_Exception)
651 Unexpect aCatch(SALOME_SalomeException);
652 SMESH::SMESH_Group_var aNewGroup =
653 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
655 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
656 SALOMEDS::SObject_var aSO =
657 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
658 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
659 if ( !aSO->_is_nil()) {
660 // Update Python script
661 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
662 << ElementTypeString(theElemType) << ", '" << theName << "' )";
665 return aNewGroup._retn();
669 //=============================================================================
673 //=============================================================================
674 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
676 GEOM::GEOM_Object_ptr theGeomObj)
677 throw(SALOME::SALOME_Exception)
679 Unexpect aCatch(SALOME_SalomeException);
680 SMESH::SMESH_GroupOnGeom_var aNewGroup;
682 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
683 if ( !aShape.IsNull() ) {
684 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
685 ( createGroup( theElemType, theName, aShape ));
686 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
687 SALOMEDS::SObject_var aSO =
688 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
689 aNewGroup, theGeomObj, theName);
690 if ( !aSO->_is_nil()) {
691 // Update Python script
692 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
693 << ElementTypeString(theElemType) << ", '" << theName << "', "
694 << theGeomObj << " )";
699 return aNewGroup._retn();
702 //=============================================================================
706 //=============================================================================
708 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
709 throw (SALOME::SALOME_Exception)
711 if ( theGroup->_is_nil() )
714 SMESH_GroupBase_i* aGroup =
715 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
719 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
720 if ( !aStudy->_is_nil() ) {
721 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
723 if ( !aGroupSO->_is_nil() ) {
724 // Update Python script
725 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
727 // Remove group's SObject
728 aStudy->NewBuilder()->RemoveObject( aGroupSO );
732 // Remove the group from SMESH data structures
733 removeGroup( aGroup->GetLocalID() );
736 //=============================================================================
737 /*! RemoveGroupWithContents
738 * Remove group with its contents
740 //=============================================================================
741 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
742 throw (SALOME::SALOME_Exception)
744 if ( theGroup->_is_nil() )
747 SMESH_GroupBase_i* aGroup =
748 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
752 SMESH::long_array_var anIds = aGroup->GetListOfID();
753 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
755 // Update Python script
756 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
759 if ( aGroup->GetType() == SMESH::NODE )
760 aMeshEditor->RemoveNodes( anIds );
762 aMeshEditor->RemoveElements( anIds );
765 RemoveGroup( theGroup );
767 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
768 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
769 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
773 //================================================================================
775 * \brief Get the list of groups existing in the mesh
776 * \retval SMESH::ListOfGroups * - list of groups
778 //================================================================================
780 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
782 Unexpect aCatch(SALOME_SalomeException);
783 if (MYDEBUG) MESSAGE("GetGroups");
785 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
788 TPythonDump aPythonDump;
789 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
793 aList->length( _mapGroups.size() );
795 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
796 for ( ; it != _mapGroups.end(); it++ ) {
797 if ( CORBA::is_nil( it->second )) continue;
798 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
800 if (i > 1) aPythonDump << ", ";
801 aPythonDump << it->second;
805 catch(SALOME_Exception & S_ex) {
806 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
809 // Update Python script
810 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
811 aPythonDump << " ] = " << _this() << ".GetGroups()";
813 return aList._retn();
815 //=============================================================================
817 * Get number of groups existing in the mesh
819 //=============================================================================
821 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
823 Unexpect aCatch(SALOME_SalomeException);
824 return _mapGroups.size();
827 //=============================================================================
829 * New group is created. All mesh elements that are
830 * present in initial groups are added to the new one
832 //=============================================================================
833 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
834 SMESH::SMESH_GroupBase_ptr theGroup2,
835 const char* theName )
836 throw (SALOME::SALOME_Exception)
840 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
841 theGroup1->GetType() != theGroup2->GetType() )
842 return SMESH::SMESH_Group::_nil();
845 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
846 if ( aResGrp->_is_nil() )
847 return SMESH::SMESH_Group::_nil();
849 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
850 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
852 TColStd_MapOfInteger aResMap;
854 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
855 aResMap.Add( anIds1[ i1 ] );
857 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
858 aResMap.Add( anIds2[ i2 ] );
860 SMESH::long_array_var aResIds = new SMESH::long_array;
861 aResIds->length( aResMap.Extent() );
864 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
865 for( ; anIter.More(); anIter.Next() )
866 aResIds[ resI++ ] = anIter.Key();
868 aResGrp->Add( aResIds );
870 // Clear python lines, created by CreateGroup() and Add()
871 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
872 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
873 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
875 // Update Python script
876 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
877 << theGroup1 << ", " << theGroup2 << ", '"
880 return aResGrp._retn();
884 return SMESH::SMESH_Group::_nil();
888 //=============================================================================
890 * New group is created. All mesh elements that are
891 * present in both initial groups are added to the new one.
893 //=============================================================================
894 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
895 SMESH::SMESH_GroupBase_ptr theGroup2,
896 const char* theName )
897 throw (SALOME::SALOME_Exception)
899 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
900 theGroup1->GetType() != theGroup2->GetType() )
901 return SMESH::SMESH_Group::_nil();
903 // Create Intersection
904 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
905 if ( aResGrp->_is_nil() )
908 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
909 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
911 TColStd_MapOfInteger aMap1;
913 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
914 aMap1.Add( anIds1[ i1 ] );
916 TColStd_SequenceOfInteger aSeq;
918 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
919 if ( aMap1.Contains( anIds2[ i2 ] ) )
920 aSeq.Append( anIds2[ i2 ] );
922 SMESH::long_array_var aResIds = new SMESH::long_array;
923 aResIds->length( aSeq.Length() );
925 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
926 aResIds[ resI ] = aSeq( resI + 1 );
928 aResGrp->Add( aResIds );
930 // Clear python lines, created by CreateGroup() and Add()
931 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
932 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
933 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
935 // Update Python script
936 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
937 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
939 return aResGrp._retn();
942 //=============================================================================
944 * New group is created. All mesh elements that are present in
945 * main group but do not present in tool group are added to the new one
947 //=============================================================================
948 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
949 SMESH::SMESH_GroupBase_ptr theGroup2,
950 const char* theName )
951 throw (SALOME::SALOME_Exception)
953 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
954 theGroup1->GetType() != theGroup2->GetType() )
955 return SMESH::SMESH_Group::_nil();
958 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
959 if ( aResGrp->_is_nil() )
962 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
963 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
965 TColStd_MapOfInteger aMap2;
967 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
968 aMap2.Add( anIds2[ i2 ] );
971 TColStd_SequenceOfInteger aSeq;
972 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
973 if ( !aMap2.Contains( anIds1[ i1 ] ) )
974 aSeq.Append( anIds1[ i1 ] );
976 SMESH::long_array_var aResIds = new SMESH::long_array;
977 aResIds->length( aSeq.Length() );
979 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
980 aResIds[ resI ] = aSeq( resI + 1 );
982 aResGrp->Add( aResIds );
984 // Clear python lines, created by CreateGroup() and Add()
985 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
986 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
987 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
989 // Update Python script
990 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
991 << theGroup1 << ", " << theGroup2 << ", '"
994 return aResGrp._retn();
997 //================================================================================
999 * \brief Return group items of a group present in a study
1001 //================================================================================
1003 static GEOM::GEOM_Object_ptr getGroupItemsFromStudy(CORBA::Object_ptr theMesh,
1004 SMESH_Gen_i* theGen,
1005 list<TopoDS_Shape> & theItems)
1007 GEOM::GEOM_Object_var groupObj;
1008 SALOMEDS::Study_var study = theGen->GetCurrentStudy();
1009 GEOM::GEOM_Gen_var geomGen = theGen->GetGeomEngine();
1010 if ( study->_is_nil() || geomGen->_is_nil() )
1011 return groupObj._retn();
1013 GEOM::GEOM_IGroupOperations_var groupOp =
1014 geomGen->GetIGroupOperations( theGen->GetCurrentStudyID() );
1015 GEOM::GEOM_IShapesOperations_var shapeOp =
1016 geomGen->GetIShapesOperations( theGen->GetCurrentStudyID() );
1018 SALOMEDS::SObject_var meshOS = theGen->ObjectToSObject(study, theMesh);
1019 if ( meshOS->_is_nil() || groupOp->_is_nil() || shapeOp->_is_nil() )
1020 return groupObj._retn();
1021 SALOMEDS::SObject_var fatherSO = meshOS->GetFather();
1022 if ( fatherSO->_is_nil() || fatherSO->Tag() != theGen->GetSubMeshOnCompoundTag() )
1023 return groupObj._retn(); // keep only submeshes on groups
1025 SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(meshOS);
1026 if ( anIter->_is_nil() ) return groupObj._retn();
1027 for ( ; anIter->More(); anIter->Next())
1029 SALOMEDS::SObject_var aSObject = anIter->Value();
1030 SALOMEDS::SObject_var aRefSO;
1031 if ( !aSObject->_is_nil() && aSObject->ReferencedObject(aRefSO) )
1033 groupObj = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
1034 if ( groupObj->_is_nil() ) break;
1035 GEOM::ListOfLong_var ids = groupOp->GetObjects( groupObj );
1036 GEOM::GEOM_Object_var mainShape = groupObj->GetMainShape();
1037 for ( int i = 0; i < ids->length(); ++i ) {
1038 GEOM::GEOM_Object_var subShape = shapeOp->GetSubShape( mainShape, ids[i] );
1039 TopoDS_Shape S = theGen->GeomObjectToShape( subShape );
1041 theItems.push_back( S );
1046 return groupObj._retn();
1049 //=============================================================================
1051 * \brief Update hypotheses assigned to geom groups if the latter change
1053 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1055 //=============================================================================
1057 void SMESH_Mesh_i::CheckGeomGroupModif()
1059 if ( !_impl->HasShapeToMesh() ) return;
1061 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1062 if ( study->_is_nil() ) return;
1064 // check if items of groups changed
1065 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
1066 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
1068 const TopoDS_Shape & oldGroupShape = i_sm->second->GetSubShape();
1069 SMESHDS_SubMesh * oldDS = i_sm->second->GetSubMeshDS();
1070 if ( !oldDS /*|| !oldDS->IsComplexSubmesh()*/ )
1072 int oldID = i_sm->first;
1073 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldID );
1074 if ( i_smIor == _mapSubMeshIor.end() )
1076 list< TopoDS_Shape> newItems;
1077 GEOM::GEOM_Object_var groupObj = getGroupItemsFromStudy ( i_smIor->second, _gen_i, newItems );
1078 if ( groupObj->_is_nil() )
1081 int nbOldItems = oldDS->IsComplexSubmesh() ? oldDS->NbSubMeshes() : 1;
1082 int nbNewItems = newItems.size();
1083 bool groupChanged = ( nbOldItems != nbNewItems);
1084 if ( !groupChanged ) {
1085 if ( !oldDS->IsComplexSubmesh() ) { // old group has one item
1086 groupChanged = ( oldGroupShape != newItems.front() );
1089 list<TopoDS_Shape>::iterator item = newItems.begin();
1090 for ( ; item != newItems.end() && !groupChanged; ++item )
1092 SMESHDS_SubMesh * itemDS = _impl->GetMeshDS()->MeshElements( *item );
1093 groupChanged = ( !itemDS || !oldDS->ContainsSubMesh( itemDS ));
1097 // update hypotheses and submeshes if necessary
1100 // get a new group shape
1101 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1102 if ( !geomClient ) continue;
1103 TCollection_AsciiString groupIOR = _gen_i->GetGeomEngine()->GetStringFromIOR( groupObj );
1104 geomClient->RemoveShapeFromBuffer( groupIOR );
1105 TopoDS_Shape newGroupShape = _gen_i->GeomObjectToShape( groupObj );
1106 // update hypotheses
1107 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldGroupShape);
1108 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1109 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1111 _impl->RemoveHypothesis( oldGroupShape, (*hypIt)->GetID());
1112 _impl->AddHypothesis ( newGroupShape, (*hypIt)->GetID());
1114 // care of submeshes
1115 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newGroupShape );
1116 int newID = newSubmesh->GetId();
1117 if ( newID != oldID ) {
1118 _mapSubMesh [ newID ] = newSubmesh;
1119 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1120 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1121 _mapSubMesh.erase (oldID);
1122 _mapSubMesh_i.erase (oldID);
1123 _mapSubMeshIor.erase(oldID);
1124 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1130 //=============================================================================
1134 //=============================================================================
1136 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1138 if(MYDEBUG) MESSAGE( "createSubMesh" );
1139 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1141 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1142 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1143 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1144 SMESH::SMESH_subMesh_var subMesh
1145 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1147 _mapSubMesh[subMeshId] = mySubMesh;
1148 _mapSubMesh_i[subMeshId] = subMeshServant;
1149 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1151 // register CORBA object for persistence
1152 int nextId = _gen_i->RegisterObject( subMesh );
1153 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1155 return subMesh._retn();
1158 //=======================================================================
1159 //function : getSubMesh
1161 //=======================================================================
1163 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1165 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1166 if ( it == _mapSubMeshIor.end() )
1167 return SMESH::SMESH_subMesh::_nil();
1169 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1173 //=============================================================================
1177 //=============================================================================
1179 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1180 GEOM::GEOM_Object_ptr theSubShapeObject )
1182 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1183 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1187 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1188 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1189 removeHypothesis( theSubShapeObject, aHypList[i] );
1192 catch( const SALOME::SALOME_Exception& ) {
1193 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1196 int subMeshId = theSubMesh->GetId();
1198 _mapSubMesh.erase(subMeshId);
1199 _mapSubMesh_i.erase(subMeshId);
1200 _mapSubMeshIor.erase(subMeshId);
1201 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1204 //=============================================================================
1208 //=============================================================================
1210 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1211 const char* theName,
1212 const TopoDS_Shape& theShape )
1215 SMESH::SMESH_GroupBase_var aGroup;
1216 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1217 SMESH_GroupBase_i* aGroupImpl;
1218 if ( !theShape.IsNull() )
1219 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1221 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1223 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1224 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1225 aGroupImpl->Register();
1226 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1228 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1229 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1231 // register CORBA object for persistence
1232 int nextId = _gen_i->RegisterObject( aGroup );
1233 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1235 return aGroup._retn();
1238 //=============================================================================
1240 * SMESH_Mesh_i::removeGroup
1242 * Should be called by ~SMESH_Group_i()
1244 //=============================================================================
1246 void SMESH_Mesh_i::removeGroup( const int theId )
1248 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1249 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1250 _mapGroups.erase( theId );
1251 _impl->RemoveGroup( theId );
1256 //=============================================================================
1260 //=============================================================================
1262 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1263 throw(SALOME::SALOME_Exception)
1265 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1267 SMESH::log_array_var aLog;
1269 list < SMESHDS_Command * >logDS = _impl->GetLog();
1270 aLog = new SMESH::log_array;
1272 int lg = logDS.size();
1275 list < SMESHDS_Command * >::iterator its = logDS.begin();
1276 while(its != logDS.end()){
1277 SMESHDS_Command *com = *its;
1278 int comType = com->GetType();
1280 int lgcom = com->GetNumber();
1282 const list < int >&intList = com->GetIndexes();
1283 int inum = intList.size();
1285 list < int >::const_iterator ii = intList.begin();
1286 const list < double >&coordList = com->GetCoords();
1287 int rnum = coordList.size();
1289 list < double >::const_iterator ir = coordList.begin();
1290 aLog[indexLog].commandType = comType;
1291 aLog[indexLog].number = lgcom;
1292 aLog[indexLog].coords.length(rnum);
1293 aLog[indexLog].indexes.length(inum);
1294 for(int i = 0; i < rnum; i++){
1295 aLog[indexLog].coords[i] = *ir;
1296 //MESSAGE(" "<<i<<" "<<ir.Value());
1299 for(int i = 0; i < inum; i++){
1300 aLog[indexLog].indexes[i] = *ii;
1301 //MESSAGE(" "<<i<<" "<<ii.Value());
1310 catch(SALOME_Exception & S_ex){
1311 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1313 return aLog._retn();
1317 //=============================================================================
1321 //=============================================================================
1323 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1325 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1329 //=============================================================================
1333 //=============================================================================
1335 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1337 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1341 //=============================================================================
1345 //=============================================================================
1347 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1352 //=============================================================================
1356 //=============================================================================
1358 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1360 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1364 //=============================================================================
1368 //=============================================================================
1370 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1372 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1376 //=============================================================================
1378 * Return mesh editor
1380 //=============================================================================
1382 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1384 // Create MeshEditor
1385 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
1386 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1388 // Update Python script
1389 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1391 return aMesh._retn();
1394 //=============================================================================
1396 * Return mesh edition previewer
1398 //=============================================================================
1400 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1402 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
1403 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1404 return aMesh._retn();
1407 //=============================================================================
1411 //=============================================================================
1412 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
1414 Unexpect aCatch(SALOME_SalomeException);
1415 _impl->SetAutoColor(theAutoColor);
1418 //=============================================================================
1422 //=============================================================================
1423 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
1425 Unexpect aCatch(SALOME_SalomeException);
1426 return _impl->GetAutoColor();
1430 //=============================================================================
1432 * Export in different formats
1434 //=============================================================================
1436 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1438 return _impl->HasDuplicatedGroupNamesMED();
1441 static void PrepareForWriting (const char* file)
1443 TCollection_AsciiString aFullName ((char*)file);
1444 OSD_Path aPath (aFullName);
1445 OSD_File aFile (aPath);
1446 if (aFile.Exists()) {
1447 // existing filesystem node
1448 if (aFile.KindOfFile() == OSD_FILE) {
1449 if (aFile.IsWriteable()) {
1452 if (aFile.Failed()) {
1453 TCollection_AsciiString msg ("File ");
1454 msg += aFullName + " cannot be replaced.";
1455 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1458 TCollection_AsciiString msg ("File ");
1459 msg += aFullName + " cannot be overwritten.";
1460 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1463 TCollection_AsciiString msg ("Location ");
1464 msg += aFullName + " is not a file.";
1465 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1468 // nonexisting file; check if it can be created
1470 aFile.Build(OSD_WriteOnly, OSD_Protection());
1471 if (aFile.Failed()) {
1472 TCollection_AsciiString msg ("You cannot create the file ");
1473 msg += aFullName + ". Check the directory existance and access rights.";
1474 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1482 void SMESH_Mesh_i::ExportToMED (const char* file,
1483 CORBA::Boolean auto_groups,
1484 SMESH::MED_VERSION theVersion)
1485 throw(SALOME::SALOME_Exception)
1487 Unexpect aCatch(SALOME_SalomeException);
1489 // Update Python script
1490 TPythonDump() << _this() << ".ExportToMED( '"
1491 << file << "', " << auto_groups << ", " << theVersion << " )";
1494 PrepareForWriting(file);
1495 char* aMeshName = "Mesh";
1496 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1497 if ( !aStudy->_is_nil() ) {
1498 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1499 if ( !aMeshSO->_is_nil() ) {
1500 aMeshName = aMeshSO->GetName();
1502 //SCRUTE(aMeshName);
1503 //SCRUTE(aMeshSO->GetID());
1505 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1506 if ( !aStudy->GetProperties()->IsLocked() )
1508 SALOMEDS::GenericAttribute_var anAttr;
1509 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1510 SALOMEDS::AttributeExternalFileDef_var aFileName;
1511 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1512 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1513 ASSERT(!aFileName->_is_nil());
1514 aFileName->SetValue(file);
1515 SALOMEDS::AttributeFileType_var aFileType;
1516 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1517 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1518 ASSERT(!aFileType->_is_nil());
1519 aFileType->SetValue("FICHIERMED");
1523 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1526 void SMESH_Mesh_i::ExportMED (const char* file,
1527 CORBA::Boolean auto_groups)
1528 throw(SALOME::SALOME_Exception)
1530 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1533 void SMESH_Mesh_i::ExportDAT (const char *file)
1534 throw(SALOME::SALOME_Exception)
1536 Unexpect aCatch(SALOME_SalomeException);
1538 // Update Python script
1539 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1542 PrepareForWriting(file);
1543 _impl->ExportDAT(file);
1546 void SMESH_Mesh_i::ExportUNV (const char *file)
1547 throw(SALOME::SALOME_Exception)
1549 Unexpect aCatch(SALOME_SalomeException);
1551 // Update Python script
1552 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1555 PrepareForWriting(file);
1556 _impl->ExportUNV(file);
1559 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1560 throw(SALOME::SALOME_Exception)
1562 Unexpect aCatch(SALOME_SalomeException);
1564 // Update Python script
1565 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1568 PrepareForWriting(file);
1569 _impl->ExportSTL(file, isascii);
1572 //=============================================================================
1576 //=============================================================================
1578 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1580 Unexpect aCatch(SALOME_SalomeException);
1581 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1582 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1583 return aMesh._retn();
1586 //=============================================================================
1590 //=============================================================================
1591 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1593 Unexpect aCatch(SALOME_SalomeException);
1594 return _impl->NbNodes();
1597 //=============================================================================
1601 //=============================================================================
1602 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1604 Unexpect aCatch(SALOME_SalomeException);
1605 return NbEdges() + NbFaces() + NbVolumes();
1608 //=============================================================================
1612 //=============================================================================
1613 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1615 Unexpect aCatch(SALOME_SalomeException);
1616 return _impl->NbEdges();
1619 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1620 throw(SALOME::SALOME_Exception)
1622 Unexpect aCatch(SALOME_SalomeException);
1623 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
1626 //=============================================================================
1630 //=============================================================================
1631 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1633 Unexpect aCatch(SALOME_SalomeException);
1634 return _impl->NbFaces();
1637 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1639 Unexpect aCatch(SALOME_SalomeException);
1640 return _impl->NbTriangles();
1643 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1645 Unexpect aCatch(SALOME_SalomeException);
1646 return _impl->NbQuadrangles();
1649 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1651 Unexpect aCatch(SALOME_SalomeException);
1652 return _impl->NbPolygons();
1655 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1656 throw(SALOME::SALOME_Exception)
1658 Unexpect aCatch(SALOME_SalomeException);
1659 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
1662 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1663 throw(SALOME::SALOME_Exception)
1665 Unexpect aCatch(SALOME_SalomeException);
1666 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
1669 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1670 throw(SALOME::SALOME_Exception)
1672 Unexpect aCatch(SALOME_SalomeException);
1673 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
1676 //=============================================================================
1680 //=============================================================================
1681 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1683 Unexpect aCatch(SALOME_SalomeException);
1684 return _impl->NbVolumes();
1687 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1689 Unexpect aCatch(SALOME_SalomeException);
1690 return _impl->NbTetras();
1693 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1695 Unexpect aCatch(SALOME_SalomeException);
1696 return _impl->NbHexas();
1699 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1701 Unexpect aCatch(SALOME_SalomeException);
1702 return _impl->NbPyramids();
1705 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1707 Unexpect aCatch(SALOME_SalomeException);
1708 return _impl->NbPrisms();
1711 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1713 Unexpect aCatch(SALOME_SalomeException);
1714 return _impl->NbPolyhedrons();
1717 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1718 throw(SALOME::SALOME_Exception)
1720 Unexpect aCatch(SALOME_SalomeException);
1721 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
1724 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1725 throw(SALOME::SALOME_Exception)
1727 Unexpect aCatch(SALOME_SalomeException);
1728 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
1731 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1732 throw(SALOME::SALOME_Exception)
1734 Unexpect aCatch(SALOME_SalomeException);
1735 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
1738 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1739 throw(SALOME::SALOME_Exception)
1741 Unexpect aCatch(SALOME_SalomeException);
1742 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
1745 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1746 throw(SALOME::SALOME_Exception)
1748 Unexpect aCatch(SALOME_SalomeException);
1749 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
1752 //=============================================================================
1756 //=============================================================================
1757 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1759 Unexpect aCatch(SALOME_SalomeException);
1760 return _impl->NbSubMesh();
1763 //=============================================================================
1767 //=============================================================================
1768 char* SMESH_Mesh_i::Dump()
1770 std::ostringstream os;
1772 return CORBA::string_dup( os.str().c_str() );
1775 //=============================================================================
1779 //=============================================================================
1780 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1782 // SMESH::long_array_var aResult = new SMESH::long_array();
1783 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1784 // int aMinId = aSMESHDS_Mesh->MinElementID();
1785 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1787 // aResult->length(aMaxId - aMinId + 1);
1789 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1790 // aResult[i++] = id;
1792 // return aResult._retn();
1794 return GetElementsId();
1797 //=============================================================================
1801 //=============================================================================
1803 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1804 throw (SALOME::SALOME_Exception)
1806 Unexpect aCatch(SALOME_SalomeException);
1807 MESSAGE("SMESH_Mesh_i::GetElementsId");
1808 SMESH::long_array_var aResult = new SMESH::long_array();
1809 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1811 if ( aSMESHDS_Mesh == NULL )
1812 return aResult._retn();
1814 long nbElements = NbElements();
1815 aResult->length( nbElements );
1816 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1817 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1818 aResult[i] = anIt->next()->GetID();
1820 return aResult._retn();
1824 //=============================================================================
1828 //=============================================================================
1830 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1831 throw (SALOME::SALOME_Exception)
1833 Unexpect aCatch(SALOME_SalomeException);
1834 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1835 SMESH::long_array_var aResult = new SMESH::long_array();
1836 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1838 if ( aSMESHDS_Mesh == NULL )
1839 return aResult._retn();
1841 long nbElements = NbElements();
1843 // No sense in returning ids of elements along with ids of nodes:
1844 // when theElemType == SMESH::ALL, return node ids only if
1845 // there are no elements
1846 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1847 return GetNodesId();
1849 aResult->length( nbElements );
1853 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1854 while ( i < nbElements && anIt->more() ) {
1855 const SMDS_MeshElement* anElem = anIt->next();
1856 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1857 aResult[i++] = anElem->GetID();
1860 aResult->length( i );
1862 return aResult._retn();
1865 //=============================================================================
1869 //=============================================================================
1871 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1872 throw (SALOME::SALOME_Exception)
1874 Unexpect aCatch(SALOME_SalomeException);
1875 MESSAGE("SMESH_subMesh_i::GetNodesId");
1876 SMESH::long_array_var aResult = new SMESH::long_array();
1877 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1879 if ( aSMESHDS_Mesh == NULL )
1880 return aResult._retn();
1882 long nbNodes = NbNodes();
1883 aResult->length( nbNodes );
1884 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1885 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1886 aResult[i] = anIt->next()->GetID();
1888 return aResult._retn();
1891 //=============================================================================
1895 //=============================================================================
1897 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1898 throw (SALOME::SALOME_Exception)
1900 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1904 //=============================================================================
1906 * Returns ID of elements for given submesh
1908 //=============================================================================
1909 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1910 throw (SALOME::SALOME_Exception)
1912 SMESH::long_array_var aResult = new SMESH::long_array();
1914 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1915 if(!SM) return aResult._retn();
1917 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1918 if(!SDSM) return aResult._retn();
1920 aResult->length(SDSM->NbElements());
1922 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1924 while ( eIt->more() ) {
1925 aResult[i++] = eIt->next()->GetID();
1928 return aResult._retn();
1932 //=============================================================================
1934 * Returns ID of nodes for given submesh
1935 * If param all==true - returns all nodes, else -
1936 * returns only nodes on shapes.
1938 //=============================================================================
1939 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1940 throw (SALOME::SALOME_Exception)
1942 SMESH::long_array_var aResult = new SMESH::long_array();
1944 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1945 if(!SM) return aResult._retn();
1947 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1948 if(!SDSM) return aResult._retn();
1951 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
1952 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1953 while ( nIt->more() ) {
1954 const SMDS_MeshNode* elem = nIt->next();
1955 theElems.insert( elem->GetID() );
1958 else { // all nodes of submesh elements
1959 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1960 while ( eIt->more() ) {
1961 const SMDS_MeshElement* anElem = eIt->next();
1962 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
1963 while ( nIt->more() ) {
1964 const SMDS_MeshElement* elem = nIt->next();
1965 theElems.insert( elem->GetID() );
1970 aResult->length(theElems.size());
1971 set<int>::iterator itElem;
1973 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
1974 aResult[i++] = *itElem;
1976 return aResult._retn();
1980 //=============================================================================
1982 * Returns type of elements for given submesh
1984 //=============================================================================
1985 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
1986 throw (SALOME::SALOME_Exception)
1988 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1989 if(!SM) return SMESH::ALL;
1991 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1992 if(!SDSM) return SMESH::ALL;
1994 if(SDSM->NbElements()==0)
1995 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
1997 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1998 const SMDS_MeshElement* anElem = eIt->next();
1999 return ( SMESH::ElementType ) anElem->GetType();
2003 //=============================================================================
2007 //=============================================================================
2009 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
2011 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
2012 cerr << "CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() " << pointeur << endl;
2017 //=============================================================================
2019 * Get XYZ coordinates of node as list of double
2020 * If there is not node for given ID - returns empty list
2022 //=============================================================================
2024 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2026 SMESH::double_array_var aResult = new SMESH::double_array();
2027 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2028 if ( aSMESHDS_Mesh == NULL )
2029 return aResult._retn();
2032 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2034 return aResult._retn();
2038 aResult[0] = aNode->X();
2039 aResult[1] = aNode->Y();
2040 aResult[2] = aNode->Z();
2041 return aResult._retn();
2045 //=============================================================================
2047 * For given node returns list of IDs of inverse elements
2048 * If there is not node for given ID - returns empty list
2050 //=============================================================================
2052 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2054 SMESH::long_array_var aResult = new SMESH::long_array();
2055 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2056 if ( aSMESHDS_Mesh == NULL )
2057 return aResult._retn();
2060 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2062 return aResult._retn();
2064 // find inverse elements
2065 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2066 TColStd_SequenceOfInteger IDs;
2067 while(eIt->more()) {
2068 const SMDS_MeshElement* elem = eIt->next();
2069 IDs.Append(elem->GetID());
2071 if(IDs.Length()>0) {
2072 aResult->length(IDs.Length());
2074 for(; i<=IDs.Length(); i++) {
2075 aResult[i-1] = IDs.Value(i);
2078 return aResult._retn();
2081 //=============================================================================
2083 * \brief Return position of a node on shape
2085 //=============================================================================
2087 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
2089 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
2090 aNodePosition->shapeID = 0;
2091 aNodePosition->shapeType = GEOM::SHAPE;
2093 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
2094 if ( !mesh ) return aNodePosition;
2096 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
2098 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
2100 aNodePosition->shapeID = pos->GetShapeId();
2101 switch ( pos->GetTypeOfPosition() ) {
2103 aNodePosition->shapeType = GEOM::EDGE;
2104 aNodePosition->params.length(1);
2105 aNodePosition->params[0] =
2106 static_cast<SMDS_EdgePosition*>( pos.get() )->GetUParameter();
2109 aNodePosition->shapeType = GEOM::FACE;
2110 aNodePosition->params.length(2);
2111 aNodePosition->params[0] =
2112 static_cast<SMDS_FacePosition*>( pos.get() )->GetUParameter();
2113 aNodePosition->params[1] =
2114 static_cast<SMDS_FacePosition*>( pos.get() )->GetVParameter();
2116 case SMDS_TOP_VERTEX:
2117 aNodePosition->shapeType = GEOM::VERTEX;
2119 case SMDS_TOP_3DSPACE:
2120 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
2121 aNodePosition->shapeType = GEOM::SOLID;
2122 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
2123 aNodePosition->shapeType = GEOM::SHELL;
2129 return aNodePosition;
2132 //=============================================================================
2134 * If given element is node returns IDs of shape from position
2135 * If there is not node for given ID - returns -1
2137 //=============================================================================
2139 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2141 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2142 if ( aSMESHDS_Mesh == NULL )
2146 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2148 SMDS_PositionPtr pos = aNode->GetPosition();
2152 return pos->GetShapeId();
2159 //=============================================================================
2161 * For given element returns ID of result shape after
2162 * ::FindShape() from SMESH_MeshEditor
2163 * If there is not element for given ID - returns -1
2165 //=============================================================================
2167 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2169 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2170 if ( aSMESHDS_Mesh == NULL )
2173 // try to find element
2174 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2178 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2179 ::SMESH_MeshEditor aMeshEditor(_impl);
2180 int index = aMeshEditor.FindShape( elem );
2188 //=============================================================================
2190 * Returns number of nodes for given element
2191 * If there is not element for given ID - returns -1
2193 //=============================================================================
2195 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2197 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2198 if ( aSMESHDS_Mesh == NULL ) return -1;
2199 // try to find element
2200 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2201 if(!elem) return -1;
2202 return elem->NbNodes();
2206 //=============================================================================
2208 * Returns ID of node by given index for given element
2209 * If there is not element for given ID - returns -1
2210 * If there is not node for given index - returns -2
2212 //=============================================================================
2214 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2216 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2217 if ( aSMESHDS_Mesh == NULL ) return -1;
2218 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2219 if(!elem) return -1;
2220 if( index>=elem->NbNodes() || index<0 ) return -1;
2221 return elem->GetNode(index)->GetID();
2224 //=============================================================================
2226 * Returns IDs of nodes of given element
2228 //=============================================================================
2230 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2232 SMESH::long_array_var aResult = new SMESH::long_array();
2233 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2235 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2237 aResult->length( elem->NbNodes() );
2238 for ( int i = 0; i < elem->NbNodes(); ++i )
2239 aResult[ i ] = elem->GetNode( i )->GetID();
2242 return aResult._retn();
2245 //=============================================================================
2247 * Returns true if given node is medium node
2248 * in given quadratic element
2250 //=============================================================================
2252 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2254 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2255 if ( aSMESHDS_Mesh == NULL ) return false;
2257 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2258 if(!aNode) return false;
2259 // try to find element
2260 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2261 if(!elem) return false;
2263 return elem->IsMediumNode(aNode);
2267 //=============================================================================
2269 * Returns true if given node is medium node
2270 * in one of quadratic elements
2272 //=============================================================================
2274 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2275 SMESH::ElementType theElemType)
2277 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2278 if ( aSMESHDS_Mesh == NULL ) return false;
2281 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2282 if(!aNode) return false;
2284 SMESH_MesherHelper aHelper( *(_impl) );
2286 SMDSAbs_ElementType aType;
2287 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2288 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2289 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2290 else aType = SMDSAbs_All;
2292 return aHelper.IsMedium(aNode,aType);
2296 //=============================================================================
2298 * Returns number of edges for given element
2300 //=============================================================================
2302 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2304 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2305 if ( aSMESHDS_Mesh == NULL ) return -1;
2306 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2307 if(!elem) return -1;
2308 return elem->NbEdges();
2312 //=============================================================================
2314 * Returns number of faces for given element
2316 //=============================================================================
2318 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2320 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2321 if ( aSMESHDS_Mesh == NULL ) return -1;
2322 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2323 if(!elem) return -1;
2324 return elem->NbFaces();
2328 //=============================================================================
2330 * Returns true if given element is polygon
2332 //=============================================================================
2334 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2336 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2337 if ( aSMESHDS_Mesh == NULL ) return false;
2338 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2339 if(!elem) return false;
2340 return elem->IsPoly();
2344 //=============================================================================
2346 * Returns true if given element is quadratic
2348 //=============================================================================
2350 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2352 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2353 if ( aSMESHDS_Mesh == NULL ) return false;
2354 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2355 if(!elem) return false;
2356 return elem->IsQuadratic();
2360 //=============================================================================
2362 * Returns bary center for given element
2364 //=============================================================================
2366 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2368 SMESH::double_array_var aResult = new SMESH::double_array();
2369 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2370 if ( aSMESHDS_Mesh == NULL )
2371 return aResult._retn();
2373 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2375 return aResult._retn();
2377 if(elem->GetType()==SMDSAbs_Volume) {
2378 SMDS_VolumeTool aTool;
2379 if(aTool.Set(elem)) {
2381 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
2386 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2388 double x=0., y=0., z=0.;
2389 for(; anIt->more(); ) {
2391 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2405 return aResult._retn();
2409 //=============================================================================
2411 * Create and publish group servants if any groups were imported or created anyhow
2413 //=============================================================================
2415 void SMESH_Mesh_i::CreateGroupServants()
2417 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2419 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
2420 while ( groupIt->more() )
2422 ::SMESH_Group* group = groupIt->next();
2423 int anId = group->GetGroupDS()->GetID();
2425 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
2426 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2429 SMESH_GroupBase_i* aGroupImpl;
2431 if ( SMESHDS_GroupOnGeom* groupOnGeom =
2432 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
2434 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
2435 shape = groupOnGeom->GetShape();
2438 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2441 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
2442 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2443 aGroupImpl->Register();
2445 SMESH::SMESH_GroupBase_var groupVar =
2446 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
2447 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
2449 // register CORBA object for persistence
2450 int nextId = _gen_i->RegisterObject( groupVar );
2451 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
2453 // publishing of the groups in the study
2454 if ( !aStudy->_is_nil() ) {
2455 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
2456 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
2461 //=============================================================================
2463 * \brief Return groups cantained in _mapGroups by their IDs
2465 //=============================================================================
2467 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
2469 int nbGroups = groupIDs.size();
2470 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
2471 aList->length( nbGroups );
2473 list<int>::const_iterator ids = groupIDs.begin();
2474 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
2476 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
2477 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2478 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
2480 aList->length( nbGroups );
2481 return aList._retn();
2484 //=============================================================================
2486 * \brief Return information about imported file
2488 //=============================================================================
2489 SALOME_MED::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
2491 SALOME_MED::MedFileInfo_var res = new SALOME_MED::MedFileInfo();
2493 const char* name = myFile.c_str();
2494 res->fileName = name;
2495 res->fileSize = 0;//myFileInfo.size();
2496 int major, minor, release;
2497 if( !MED::getMEDVersion( name, major, minor, release ) )
2505 res->release = release;