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 myFile = theFileName;
262 CreateGroupServants();
264 return ConvertDriverMEDReadStatus(status);
267 //================================================================================
269 * \brief Return string representation of a MED file version comprising nbDigits
271 //================================================================================
273 char* SMESH_Mesh_i::GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits)
275 std::string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(MED::EVersion(version),
277 return CORBA::string_dup( ver.c_str() );
280 //=============================================================================
284 * Imports mesh data from MED file
286 //=============================================================================
288 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
289 throw ( SALOME::SALOME_Exception )
291 // Read mesh with name = <theMeshName> into SMESH_Mesh
292 _impl->UNVToMesh( theFileName );
294 CreateGroupServants();
299 //=============================================================================
303 * Imports mesh data from STL file
305 //=============================================================================
306 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
307 throw ( SALOME::SALOME_Exception )
309 // Read mesh with name = <theMeshName> into SMESH_Mesh
310 _impl->STLToMesh( theFileName );
315 //=============================================================================
319 * Imports mesh data from MED file
321 //=============================================================================
323 // int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
325 // // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
326 // int status = _impl->MEDToMesh( theFileName, theMeshName );
327 // CreateGroupServants();
332 //=============================================================================
336 //=============================================================================
338 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
340 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
341 (SMESH_Hypothesis::Hypothesis_Status theStatus)
344 RETURNCASE( HYP_OK );
345 RETURNCASE( HYP_MISSING );
346 RETURNCASE( HYP_CONCURENT );
347 RETURNCASE( HYP_BAD_PARAMETER );
348 RETURNCASE( HYP_HIDDEN_ALGO );
349 RETURNCASE( HYP_HIDING_ALGO );
350 RETURNCASE( HYP_UNKNOWN_FATAL );
351 RETURNCASE( HYP_INCOMPATIBLE );
352 RETURNCASE( HYP_NOTCONFORM );
353 RETURNCASE( HYP_ALREADY_EXIST );
354 RETURNCASE( HYP_BAD_DIM );
355 RETURNCASE( HYP_BAD_SUBSHAPE );
356 RETURNCASE( HYP_BAD_GEOMETRY );
359 return SMESH::HYP_UNKNOWN_FATAL;
362 //=============================================================================
366 * calls internal addHypothesis() and then adds a reference to <anHyp> under
367 * the SObject actually having a reference to <aSubShape>.
368 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
370 //=============================================================================
372 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
373 SMESH::SMESH_Hypothesis_ptr anHyp)
374 throw(SALOME::SALOME_Exception)
376 Unexpect aCatch(SALOME_SalomeException);
377 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
379 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
380 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
381 aSubShapeObject, anHyp );
383 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
385 // Update Python script
386 if(_impl->HasShapeToMesh()) {
387 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
388 << aSubShapeObject << ", " << anHyp << " )";
391 TPythonDump() << "status = " << _this() << ".AddHypothesis( "<< anHyp << " )";
394 return ConvertHypothesisStatus(status);
397 //=============================================================================
401 //=============================================================================
403 SMESH_Hypothesis::Hypothesis_Status
404 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
405 SMESH::SMESH_Hypothesis_ptr anHyp)
407 if(MYDEBUG) MESSAGE("addHypothesis");
409 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
410 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
413 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
414 if (CORBA::is_nil(myHyp))
415 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
418 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
421 TopoDS_Shape myLocSubShape;
422 //use PseudoShape in case if mesh has no shape
424 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
426 myLocSubShape = _impl->GetShapeToMesh();
428 int hypId = myHyp->GetId();
429 status = _impl->AddHypothesis(myLocSubShape, hypId);
430 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
431 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
432 // assure there is a corresponding submesh
433 if ( !_impl->IsMainShape( myLocSubShape )) {
434 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
435 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
436 createSubMesh( aSubShapeObject );
440 catch(SALOME_Exception & S_ex)
442 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
447 //=============================================================================
451 //=============================================================================
453 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
454 SMESH::SMESH_Hypothesis_ptr anHyp)
455 throw(SALOME::SALOME_Exception)
457 Unexpect aCatch(SALOME_SalomeException);
458 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
460 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
461 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
462 aSubShapeObject, anHyp );
464 // Update Python script
465 // Update Python script
466 if(_impl->HasShapeToMesh()) {
467 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
468 << aSubShapeObject << ", " << anHyp << " )";
471 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
475 return ConvertHypothesisStatus(status);
478 //=============================================================================
482 //=============================================================================
484 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
485 SMESH::SMESH_Hypothesis_ptr anHyp)
487 if(MYDEBUG) MESSAGE("removeHypothesis()");
488 // **** proposer liste de subShape (selection multiple)
490 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
491 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
494 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
495 if (CORBA::is_nil(myHyp))
496 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
499 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
502 TopoDS_Shape myLocSubShape;
503 //use PseudoShape in case if mesh has no shape
505 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
507 myLocSubShape = _impl->GetShapeToMesh();
509 int hypId = myHyp->GetId();
510 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
511 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
512 _mapHypo.erase( hypId );
514 catch(SALOME_Exception & S_ex)
516 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
521 //=============================================================================
525 //=============================================================================
527 SMESH::ListOfHypothesis *
528 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
529 throw(SALOME::SALOME_Exception)
531 Unexpect aCatch(SALOME_SalomeException);
532 if (MYDEBUG) MESSAGE("GetHypothesisList");
533 if (CORBA::is_nil(aSubShapeObject))
534 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
537 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
540 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
541 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
542 int i = 0, n = aLocalList.size();
545 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
546 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
547 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
548 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
553 catch(SALOME_Exception & S_ex) {
554 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
557 return aList._retn();
560 //=============================================================================
564 //=============================================================================
565 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
566 const char* theName )
567 throw(SALOME::SALOME_Exception)
569 Unexpect aCatch(SALOME_SalomeException);
570 MESSAGE("SMESH_Mesh_i::GetSubMesh");
571 if (CORBA::is_nil(aSubShapeObject))
572 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
575 SMESH::SMESH_subMesh_var subMesh;
576 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
578 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
580 //Get or Create the SMESH_subMesh object implementation
582 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
583 subMesh = getSubMesh( subMeshId );
585 // create a new subMesh object servant if there is none for the shape
586 if ( subMesh->_is_nil() )
587 subMesh = createSubMesh( aSubShapeObject );
589 if ( _gen_i->CanPublishInStudy( subMesh )) {
590 SALOMEDS::SObject_var aSO =
591 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
592 subMesh, aSubShapeObject, theName );
593 if ( !aSO->_is_nil()) {
594 // Update Python script
595 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
596 << aSubShapeObject << ", '" << theName << "' )";
600 catch(SALOME_Exception & S_ex) {
601 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
603 return subMesh._retn();
606 //=============================================================================
610 //=============================================================================
612 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
613 throw (SALOME::SALOME_Exception)
615 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
616 if ( theSubMesh->_is_nil() )
619 GEOM::GEOM_Object_var aSubShapeObject;
620 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
621 if ( !aStudy->_is_nil() ) {
622 // Remove submesh's SObject
623 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
624 if ( !anSO->_is_nil() ) {
625 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
626 SALOMEDS::SObject_var anObj, aRef;
627 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
628 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
630 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
632 // Update Python script
633 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
637 removeSubMesh( theSubMesh, aSubShapeObject.in() );
640 //=============================================================================
644 //=============================================================================
645 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
646 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
648 switch (theElemType) {
653 CASE2STRING( VOLUME );
659 //=============================================================================
663 //=============================================================================
665 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
666 const char* theName )
667 throw(SALOME::SALOME_Exception)
669 Unexpect aCatch(SALOME_SalomeException);
670 SMESH::SMESH_Group_var aNewGroup =
671 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
673 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
674 SALOMEDS::SObject_var aSO =
675 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
676 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
677 if ( !aSO->_is_nil()) {
678 // Update Python script
679 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
680 << ElementTypeString(theElemType) << ", '" << theName << "' )";
683 return aNewGroup._retn();
687 //=============================================================================
691 //=============================================================================
692 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
694 GEOM::GEOM_Object_ptr theGeomObj)
695 throw(SALOME::SALOME_Exception)
697 Unexpect aCatch(SALOME_SalomeException);
698 SMESH::SMESH_GroupOnGeom_var aNewGroup;
700 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
701 if ( !aShape.IsNull() ) {
702 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
703 ( createGroup( theElemType, theName, aShape ));
704 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
705 SALOMEDS::SObject_var aSO =
706 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
707 aNewGroup, theGeomObj, theName);
708 if ( !aSO->_is_nil()) {
709 // Update Python script
710 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
711 << ElementTypeString(theElemType) << ", '" << theName << "', "
712 << theGeomObj << " )";
717 return aNewGroup._retn();
720 //=============================================================================
724 //=============================================================================
726 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
727 throw (SALOME::SALOME_Exception)
729 if ( theGroup->_is_nil() )
732 SMESH_GroupBase_i* aGroup =
733 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
737 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
738 if ( !aStudy->_is_nil() ) {
739 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
741 if ( !aGroupSO->_is_nil() ) {
742 // Update Python script
743 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
745 // Remove group's SObject
746 aStudy->NewBuilder()->RemoveObjectWithChildren( aGroupSO );
750 // Remove the group from SMESH data structures
751 removeGroup( aGroup->GetLocalID() );
754 //=============================================================================
755 /*! RemoveGroupWithContents
756 * Remove group with its contents
758 //=============================================================================
759 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
760 throw (SALOME::SALOME_Exception)
762 if ( theGroup->_is_nil() )
765 SMESH_GroupBase_i* aGroup =
766 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
770 SMESH::long_array_var anIds = aGroup->GetListOfID();
771 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
773 // Update Python script
774 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
777 if ( aGroup->GetType() == SMESH::NODE )
778 aMeshEditor->RemoveNodes( anIds );
780 aMeshEditor->RemoveElements( anIds );
783 RemoveGroup( theGroup );
785 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
786 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
787 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
791 //================================================================================
793 * \brief Get the list of groups existing in the mesh
794 * \retval SMESH::ListOfGroups * - list of groups
796 //================================================================================
798 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
800 Unexpect aCatch(SALOME_SalomeException);
801 if (MYDEBUG) MESSAGE("GetGroups");
803 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
806 TPythonDump aPythonDump;
807 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
811 aList->length( _mapGroups.size() );
813 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
814 for ( ; it != _mapGroups.end(); it++ ) {
815 if ( CORBA::is_nil( it->second )) continue;
816 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
818 if (i > 1) aPythonDump << ", ";
819 aPythonDump << it->second;
823 catch(SALOME_Exception & S_ex) {
824 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
827 // Update Python script
828 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
829 aPythonDump << " ] = " << _this() << ".GetGroups()";
831 return aList._retn();
833 //=============================================================================
835 * Get number of groups existing in the mesh
837 //=============================================================================
839 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
841 Unexpect aCatch(SALOME_SalomeException);
842 return _mapGroups.size();
845 //=============================================================================
847 * New group is created. All mesh elements that are
848 * present in initial groups are added to the new one
850 //=============================================================================
851 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
852 SMESH::SMESH_GroupBase_ptr theGroup2,
853 const char* theName )
854 throw (SALOME::SALOME_Exception)
858 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
859 theGroup1->GetType() != theGroup2->GetType() )
860 return SMESH::SMESH_Group::_nil();
863 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
864 if ( aResGrp->_is_nil() )
865 return SMESH::SMESH_Group::_nil();
867 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
868 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
870 TColStd_MapOfInteger aResMap;
872 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
873 aResMap.Add( anIds1[ i1 ] );
875 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
876 aResMap.Add( anIds2[ i2 ] );
878 SMESH::long_array_var aResIds = new SMESH::long_array;
879 aResIds->length( aResMap.Extent() );
882 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
883 for( ; anIter.More(); anIter.Next() )
884 aResIds[ resI++ ] = anIter.Key();
886 aResGrp->Add( aResIds );
888 // Clear python lines, created by CreateGroup() and Add()
889 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
890 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
891 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
893 // Update Python script
894 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
895 << theGroup1 << ", " << theGroup2 << ", '"
898 return aResGrp._retn();
902 return SMESH::SMESH_Group::_nil();
906 //=============================================================================
908 * New group is created. All mesh elements that are
909 * present in both initial groups are added to the new one.
911 //=============================================================================
912 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
913 SMESH::SMESH_GroupBase_ptr theGroup2,
914 const char* theName )
915 throw (SALOME::SALOME_Exception)
917 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
918 theGroup1->GetType() != theGroup2->GetType() )
919 return SMESH::SMESH_Group::_nil();
921 // Create Intersection
922 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
923 if ( aResGrp->_is_nil() )
926 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
927 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
929 TColStd_MapOfInteger aMap1;
931 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
932 aMap1.Add( anIds1[ i1 ] );
934 TColStd_SequenceOfInteger aSeq;
936 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
937 if ( aMap1.Contains( anIds2[ i2 ] ) )
938 aSeq.Append( anIds2[ i2 ] );
940 SMESH::long_array_var aResIds = new SMESH::long_array;
941 aResIds->length( aSeq.Length() );
943 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
944 aResIds[ resI ] = aSeq( resI + 1 );
946 aResGrp->Add( aResIds );
948 // Clear python lines, created by CreateGroup() and Add()
949 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
950 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
951 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
953 // Update Python script
954 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
955 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
957 return aResGrp._retn();
960 //=============================================================================
962 * New group is created. All mesh elements that are present in
963 * main group but do not present in tool group are added to the new one
965 //=============================================================================
966 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
967 SMESH::SMESH_GroupBase_ptr theGroup2,
968 const char* theName )
969 throw (SALOME::SALOME_Exception)
971 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
972 theGroup1->GetType() != theGroup2->GetType() )
973 return SMESH::SMESH_Group::_nil();
976 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
977 if ( aResGrp->_is_nil() )
980 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
981 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
983 TColStd_MapOfInteger aMap2;
985 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
986 aMap2.Add( anIds2[ i2 ] );
989 TColStd_SequenceOfInteger aSeq;
990 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
991 if ( !aMap2.Contains( anIds1[ i1 ] ) )
992 aSeq.Append( anIds1[ i1 ] );
994 SMESH::long_array_var aResIds = new SMESH::long_array;
995 aResIds->length( aSeq.Length() );
997 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
998 aResIds[ resI ] = aSeq( resI + 1 );
1000 aResGrp->Add( aResIds );
1002 // Clear python lines, created by CreateGroup() and Add()
1003 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1004 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1005 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1007 // Update Python script
1008 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
1009 << theGroup1 << ", " << theGroup2 << ", '"
1010 << theName << "' )";
1012 return aResGrp._retn();
1015 //================================================================================
1017 * \brief Return group items of a group present in a study
1019 //================================================================================
1021 static GEOM::GEOM_Object_ptr getGroupItemsFromStudy(CORBA::Object_ptr theMesh,
1022 SMESH_Gen_i* theGen,
1023 list<TopoDS_Shape> & theItems)
1025 GEOM::GEOM_Object_var groupObj;
1026 SALOMEDS::Study_var study = theGen->GetCurrentStudy();
1027 GEOM::GEOM_Gen_var geomGen = theGen->GetGeomEngine();
1028 if ( study->_is_nil() || geomGen->_is_nil() )
1029 return groupObj._retn();
1031 GEOM::GEOM_IGroupOperations_var groupOp =
1032 geomGen->GetIGroupOperations( theGen->GetCurrentStudyID() );
1033 GEOM::GEOM_IShapesOperations_var shapeOp =
1034 geomGen->GetIShapesOperations( theGen->GetCurrentStudyID() );
1036 SALOMEDS::SObject_var meshOS = theGen->ObjectToSObject(study, theMesh);
1037 if ( meshOS->_is_nil() || groupOp->_is_nil() || shapeOp->_is_nil() )
1038 return groupObj._retn();
1039 SALOMEDS::SObject_var fatherSO = meshOS->GetFather();
1040 if ( fatherSO->_is_nil() || fatherSO->Tag() != theGen->GetSubMeshOnCompoundTag() )
1041 return groupObj._retn(); // keep only submeshes on groups
1043 SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(meshOS);
1044 if ( anIter->_is_nil() ) return groupObj._retn();
1045 for ( ; anIter->More(); anIter->Next())
1047 SALOMEDS::SObject_var aSObject = anIter->Value();
1048 SALOMEDS::SObject_var aRefSO;
1049 if ( !aSObject->_is_nil() && aSObject->ReferencedObject(aRefSO) )
1051 groupObj = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
1052 if ( groupObj->_is_nil() ) break;
1053 GEOM::ListOfLong_var ids = groupOp->GetObjects( groupObj );
1054 GEOM::GEOM_Object_var mainShape = groupObj->GetMainShape();
1055 for ( int i = 0; i < ids->length(); ++i ) {
1056 GEOM::GEOM_Object_var subShape = shapeOp->GetSubShape( mainShape, ids[i] );
1057 TopoDS_Shape S = theGen->GeomObjectToShape( subShape );
1059 theItems.push_back( S );
1064 return groupObj._retn();
1067 //=============================================================================
1069 * \brief Update hypotheses assigned to geom groups if the latter change
1071 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1073 //=============================================================================
1075 void SMESH_Mesh_i::CheckGeomGroupModif()
1077 if ( !_impl->HasShapeToMesh() ) return;
1079 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1080 if ( study->_is_nil() ) return;
1082 // check if items of groups changed
1083 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
1084 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
1086 const TopoDS_Shape & oldGroupShape = i_sm->second->GetSubShape();
1087 SMESHDS_SubMesh * oldDS = i_sm->second->GetSubMeshDS();
1088 if ( !oldDS /*|| !oldDS->IsComplexSubmesh()*/ )
1090 int oldID = i_sm->first;
1091 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldID );
1092 if ( i_smIor == _mapSubMeshIor.end() )
1094 list< TopoDS_Shape> newItems;
1095 GEOM::GEOM_Object_var groupObj = getGroupItemsFromStudy ( i_smIor->second, _gen_i, newItems );
1096 if ( groupObj->_is_nil() )
1099 int nbOldItems = oldDS->IsComplexSubmesh() ? oldDS->NbSubMeshes() : 1;
1100 int nbNewItems = newItems.size();
1101 bool groupChanged = ( nbOldItems != nbNewItems);
1102 if ( !groupChanged ) {
1103 if ( !oldDS->IsComplexSubmesh() ) { // old group has one item
1104 groupChanged = ( oldGroupShape != newItems.front() );
1107 list<TopoDS_Shape>::iterator item = newItems.begin();
1108 for ( ; item != newItems.end() && !groupChanged; ++item )
1110 SMESHDS_SubMesh * itemDS = _impl->GetMeshDS()->MeshElements( *item );
1111 groupChanged = ( !itemDS || !oldDS->ContainsSubMesh( itemDS ));
1115 // update hypotheses and submeshes if necessary
1118 // get a new group shape
1119 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1120 if ( !geomClient ) continue;
1121 TCollection_AsciiString groupIOR = _gen_i->GetGeomEngine()->GetStringFromIOR( groupObj );
1122 geomClient->RemoveShapeFromBuffer( groupIOR );
1123 TopoDS_Shape newGroupShape = _gen_i->GeomObjectToShape( groupObj );
1124 // update hypotheses
1125 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldGroupShape);
1126 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1127 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1129 _impl->RemoveHypothesis( oldGroupShape, (*hypIt)->GetID());
1130 _impl->AddHypothesis ( newGroupShape, (*hypIt)->GetID());
1132 // care of submeshes
1133 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newGroupShape );
1134 int newID = newSubmesh->GetId();
1135 if ( newID != oldID ) {
1136 _mapSubMesh [ newID ] = newSubmesh;
1137 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1138 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1139 _mapSubMesh.erase (oldID);
1140 _mapSubMesh_i.erase (oldID);
1141 _mapSubMeshIor.erase(oldID);
1142 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1148 //=============================================================================
1152 //=============================================================================
1154 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1156 if(MYDEBUG) MESSAGE( "createSubMesh" );
1157 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1159 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1160 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1161 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1162 SMESH::SMESH_subMesh_var subMesh
1163 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1165 _mapSubMesh[subMeshId] = mySubMesh;
1166 _mapSubMesh_i[subMeshId] = subMeshServant;
1167 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1169 // register CORBA object for persistence
1170 int nextId = _gen_i->RegisterObject( subMesh );
1171 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1173 return subMesh._retn();
1176 //=======================================================================
1177 //function : getSubMesh
1179 //=======================================================================
1181 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1183 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1184 if ( it == _mapSubMeshIor.end() )
1185 return SMESH::SMESH_subMesh::_nil();
1187 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1191 //=============================================================================
1195 //=============================================================================
1197 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1198 GEOM::GEOM_Object_ptr theSubShapeObject )
1200 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1201 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1205 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1206 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1207 removeHypothesis( theSubShapeObject, aHypList[i] );
1210 catch( const SALOME::SALOME_Exception& ) {
1211 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1214 int subMeshId = theSubMesh->GetId();
1216 _mapSubMesh.erase(subMeshId);
1217 _mapSubMesh_i.erase(subMeshId);
1218 _mapSubMeshIor.erase(subMeshId);
1219 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1222 //=============================================================================
1226 //=============================================================================
1228 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1229 const char* theName,
1230 const TopoDS_Shape& theShape )
1233 SMESH::SMESH_GroupBase_var aGroup;
1234 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1235 SMESH_GroupBase_i* aGroupImpl;
1236 if ( !theShape.IsNull() )
1237 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1239 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1241 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1242 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1243 aGroupImpl->Register();
1244 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1246 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1247 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1249 // register CORBA object for persistence
1250 int nextId = _gen_i->RegisterObject( aGroup );
1251 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1253 return aGroup._retn();
1256 //=============================================================================
1258 * SMESH_Mesh_i::removeGroup
1260 * Should be called by ~SMESH_Group_i()
1262 //=============================================================================
1264 void SMESH_Mesh_i::removeGroup( const int theId )
1266 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1267 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1268 _mapGroups.erase( theId );
1269 _impl->RemoveGroup( theId );
1274 //=============================================================================
1278 //=============================================================================
1280 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1281 throw(SALOME::SALOME_Exception)
1283 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1285 SMESH::log_array_var aLog;
1287 list < SMESHDS_Command * >logDS = _impl->GetLog();
1288 aLog = new SMESH::log_array;
1290 int lg = logDS.size();
1293 list < SMESHDS_Command * >::iterator its = logDS.begin();
1294 while(its != logDS.end()){
1295 SMESHDS_Command *com = *its;
1296 int comType = com->GetType();
1298 int lgcom = com->GetNumber();
1300 const list < int >&intList = com->GetIndexes();
1301 int inum = intList.size();
1303 list < int >::const_iterator ii = intList.begin();
1304 const list < double >&coordList = com->GetCoords();
1305 int rnum = coordList.size();
1307 list < double >::const_iterator ir = coordList.begin();
1308 aLog[indexLog].commandType = comType;
1309 aLog[indexLog].number = lgcom;
1310 aLog[indexLog].coords.length(rnum);
1311 aLog[indexLog].indexes.length(inum);
1312 for(int i = 0; i < rnum; i++){
1313 aLog[indexLog].coords[i] = *ir;
1314 //MESSAGE(" "<<i<<" "<<ir.Value());
1317 for(int i = 0; i < inum; i++){
1318 aLog[indexLog].indexes[i] = *ii;
1319 //MESSAGE(" "<<i<<" "<<ii.Value());
1328 catch(SALOME_Exception & S_ex){
1329 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1331 return aLog._retn();
1335 //=============================================================================
1339 //=============================================================================
1341 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1343 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1347 //=============================================================================
1351 //=============================================================================
1353 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1355 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1359 //=============================================================================
1363 //=============================================================================
1365 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1370 //=============================================================================
1374 //=============================================================================
1376 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1378 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1382 //=============================================================================
1386 //=============================================================================
1388 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1390 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1394 //=============================================================================
1396 * Return mesh editor
1398 //=============================================================================
1400 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1402 // Create MeshEditor
1403 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
1404 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1406 // Update Python script
1407 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1409 return aMesh._retn();
1412 //=============================================================================
1414 * Return mesh edition previewer
1416 //=============================================================================
1418 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1420 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
1421 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1422 return aMesh._retn();
1425 //=============================================================================
1429 //=============================================================================
1430 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
1432 Unexpect aCatch(SALOME_SalomeException);
1433 _impl->SetAutoColor(theAutoColor);
1436 //=============================================================================
1440 //=============================================================================
1441 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
1443 Unexpect aCatch(SALOME_SalomeException);
1444 return _impl->GetAutoColor();
1448 //=============================================================================
1450 * Export in different formats
1452 //=============================================================================
1454 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1456 return _impl->HasDuplicatedGroupNamesMED();
1459 void SMESH_Mesh_i::PrepareForWriting (const char* file)
1461 TCollection_AsciiString aFullName ((char*)file);
1462 OSD_Path aPath (aFullName);
1463 OSD_File aFile (aPath);
1464 if (aFile.Exists()) {
1465 // existing filesystem node
1466 if (aFile.KindOfFile() == OSD_FILE) {
1467 if (aFile.IsWriteable()) {
1470 if (aFile.Failed()) {
1471 TCollection_AsciiString msg ("File ");
1472 msg += aFullName + " cannot be replaced.";
1473 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1476 TCollection_AsciiString msg ("File ");
1477 msg += aFullName + " cannot be overwritten.";
1478 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1481 TCollection_AsciiString msg ("Location ");
1482 msg += aFullName + " is not a file.";
1483 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1486 // nonexisting file; check if it can be created
1488 aFile.Build(OSD_WriteOnly, OSD_Protection());
1489 if (aFile.Failed()) {
1490 TCollection_AsciiString msg ("You cannot create the file ");
1491 msg += aFullName + ". Check the directory existance and access rights.";
1492 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1500 void SMESH_Mesh_i::ExportToMED (const char* file,
1501 CORBA::Boolean auto_groups,
1502 SMESH::MED_VERSION theVersion)
1503 throw(SALOME::SALOME_Exception)
1505 Unexpect aCatch(SALOME_SalomeException);
1507 // Update Python script
1508 TPythonDump() << _this() << ".ExportToMED( '"
1509 << file << "', " << auto_groups << ", " << theVersion << " )";
1512 PrepareForWriting(file);
1513 char* aMeshName = "Mesh";
1514 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1515 if ( !aStudy->_is_nil() ) {
1516 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1517 if ( !aMeshSO->_is_nil() ) {
1518 aMeshName = aMeshSO->GetName();
1520 //SCRUTE(aMeshName);
1521 //SCRUTE(aMeshSO->GetID());
1523 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1524 if ( !aStudy->GetProperties()->IsLocked() )
1526 SALOMEDS::GenericAttribute_var anAttr;
1527 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1528 SALOMEDS::AttributeExternalFileDef_var aFileName;
1529 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1530 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1531 ASSERT(!aFileName->_is_nil());
1532 aFileName->SetValue(file);
1533 SALOMEDS::AttributeFileType_var aFileType;
1534 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1535 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1536 ASSERT(!aFileType->_is_nil());
1537 aFileType->SetValue("FICHIERMED");
1541 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1544 void SMESH_Mesh_i::ExportMED (const char* file,
1545 CORBA::Boolean auto_groups)
1546 throw(SALOME::SALOME_Exception)
1548 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1551 void SMESH_Mesh_i::ExportDAT (const char *file)
1552 throw(SALOME::SALOME_Exception)
1554 Unexpect aCatch(SALOME_SalomeException);
1556 // Update Python script
1557 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1560 PrepareForWriting(file);
1561 _impl->ExportDAT(file);
1564 void SMESH_Mesh_i::ExportUNV (const char *file)
1565 throw(SALOME::SALOME_Exception)
1567 Unexpect aCatch(SALOME_SalomeException);
1569 // Update Python script
1570 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1573 PrepareForWriting(file);
1574 _impl->ExportUNV(file);
1577 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1578 throw(SALOME::SALOME_Exception)
1580 Unexpect aCatch(SALOME_SalomeException);
1582 // Update Python script
1583 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1586 PrepareForWriting(file);
1587 _impl->ExportSTL(file, isascii);
1590 //=============================================================================
1594 //=============================================================================
1596 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1598 Unexpect aCatch(SALOME_SalomeException);
1599 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1600 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1601 return aMesh._retn();
1604 //=============================================================================
1608 //=============================================================================
1609 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1611 Unexpect aCatch(SALOME_SalomeException);
1612 return _impl->NbNodes();
1615 //=============================================================================
1619 //=============================================================================
1620 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1622 Unexpect aCatch(SALOME_SalomeException);
1623 return NbEdges() + NbFaces() + NbVolumes();
1626 //=============================================================================
1630 //=============================================================================
1631 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1633 Unexpect aCatch(SALOME_SalomeException);
1634 return _impl->NbEdges();
1637 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1638 throw(SALOME::SALOME_Exception)
1640 Unexpect aCatch(SALOME_SalomeException);
1641 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
1644 //=============================================================================
1648 //=============================================================================
1649 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1651 Unexpect aCatch(SALOME_SalomeException);
1652 return _impl->NbFaces();
1655 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1657 Unexpect aCatch(SALOME_SalomeException);
1658 return _impl->NbTriangles();
1661 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1663 Unexpect aCatch(SALOME_SalomeException);
1664 return _impl->NbQuadrangles();
1667 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1669 Unexpect aCatch(SALOME_SalomeException);
1670 return _impl->NbPolygons();
1673 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1674 throw(SALOME::SALOME_Exception)
1676 Unexpect aCatch(SALOME_SalomeException);
1677 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
1680 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1681 throw(SALOME::SALOME_Exception)
1683 Unexpect aCatch(SALOME_SalomeException);
1684 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
1687 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1688 throw(SALOME::SALOME_Exception)
1690 Unexpect aCatch(SALOME_SalomeException);
1691 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
1694 //=============================================================================
1698 //=============================================================================
1699 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1701 Unexpect aCatch(SALOME_SalomeException);
1702 return _impl->NbVolumes();
1705 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1707 Unexpect aCatch(SALOME_SalomeException);
1708 return _impl->NbTetras();
1711 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1713 Unexpect aCatch(SALOME_SalomeException);
1714 return _impl->NbHexas();
1717 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1719 Unexpect aCatch(SALOME_SalomeException);
1720 return _impl->NbPyramids();
1723 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1725 Unexpect aCatch(SALOME_SalomeException);
1726 return _impl->NbPrisms();
1729 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1731 Unexpect aCatch(SALOME_SalomeException);
1732 return _impl->NbPolyhedrons();
1735 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1736 throw(SALOME::SALOME_Exception)
1738 Unexpect aCatch(SALOME_SalomeException);
1739 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
1742 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1743 throw(SALOME::SALOME_Exception)
1745 Unexpect aCatch(SALOME_SalomeException);
1746 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
1749 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1750 throw(SALOME::SALOME_Exception)
1752 Unexpect aCatch(SALOME_SalomeException);
1753 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
1756 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1757 throw(SALOME::SALOME_Exception)
1759 Unexpect aCatch(SALOME_SalomeException);
1760 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
1763 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1764 throw(SALOME::SALOME_Exception)
1766 Unexpect aCatch(SALOME_SalomeException);
1767 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
1770 //=============================================================================
1774 //=============================================================================
1775 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1777 Unexpect aCatch(SALOME_SalomeException);
1778 return _impl->NbSubMesh();
1781 //=============================================================================
1785 //=============================================================================
1786 char* SMESH_Mesh_i::Dump()
1788 std::ostringstream os;
1790 return CORBA::string_dup( os.str().c_str() );
1793 //=============================================================================
1797 //=============================================================================
1798 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1800 // SMESH::long_array_var aResult = new SMESH::long_array();
1801 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1802 // int aMinId = aSMESHDS_Mesh->MinElementID();
1803 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1805 // aResult->length(aMaxId - aMinId + 1);
1807 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1808 // aResult[i++] = id;
1810 // return aResult._retn();
1812 return GetElementsId();
1815 //=============================================================================
1819 //=============================================================================
1821 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1822 throw (SALOME::SALOME_Exception)
1824 Unexpect aCatch(SALOME_SalomeException);
1825 MESSAGE("SMESH_Mesh_i::GetElementsId");
1826 SMESH::long_array_var aResult = new SMESH::long_array();
1827 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1829 if ( aSMESHDS_Mesh == NULL )
1830 return aResult._retn();
1832 long nbElements = NbElements();
1833 aResult->length( nbElements );
1834 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1835 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1836 aResult[i] = anIt->next()->GetID();
1838 return aResult._retn();
1842 //=============================================================================
1846 //=============================================================================
1848 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1849 throw (SALOME::SALOME_Exception)
1851 Unexpect aCatch(SALOME_SalomeException);
1852 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1853 SMESH::long_array_var aResult = new SMESH::long_array();
1854 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1856 if ( aSMESHDS_Mesh == NULL )
1857 return aResult._retn();
1859 long nbElements = NbElements();
1861 // No sense in returning ids of elements along with ids of nodes:
1862 // when theElemType == SMESH::ALL, return node ids only if
1863 // there are no elements
1864 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1865 return GetNodesId();
1867 aResult->length( nbElements );
1871 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1872 while ( i < nbElements && anIt->more() ) {
1873 const SMDS_MeshElement* anElem = anIt->next();
1874 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1875 aResult[i++] = anElem->GetID();
1878 aResult->length( i );
1880 return aResult._retn();
1883 //=============================================================================
1887 //=============================================================================
1889 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1890 throw (SALOME::SALOME_Exception)
1892 Unexpect aCatch(SALOME_SalomeException);
1893 MESSAGE("SMESH_subMesh_i::GetNodesId");
1894 SMESH::long_array_var aResult = new SMESH::long_array();
1895 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1897 if ( aSMESHDS_Mesh == NULL )
1898 return aResult._retn();
1900 long nbNodes = NbNodes();
1901 aResult->length( nbNodes );
1902 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1903 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1904 aResult[i] = anIt->next()->GetID();
1906 return aResult._retn();
1909 //=============================================================================
1913 //=============================================================================
1915 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1916 throw (SALOME::SALOME_Exception)
1918 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1922 //=============================================================================
1924 * Returns ID of elements for given submesh
1926 //=============================================================================
1927 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1928 throw (SALOME::SALOME_Exception)
1930 SMESH::long_array_var aResult = new SMESH::long_array();
1932 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1933 if(!SM) return aResult._retn();
1935 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1936 if(!SDSM) return aResult._retn();
1938 aResult->length(SDSM->NbElements());
1940 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1942 while ( eIt->more() ) {
1943 aResult[i++] = eIt->next()->GetID();
1946 return aResult._retn();
1950 //=============================================================================
1952 * Returns ID of nodes for given submesh
1953 * If param all==true - returns all nodes, else -
1954 * returns only nodes on shapes.
1956 //=============================================================================
1957 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1958 throw (SALOME::SALOME_Exception)
1960 SMESH::long_array_var aResult = new SMESH::long_array();
1962 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1963 if(!SM) return aResult._retn();
1965 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1966 if(!SDSM) return aResult._retn();
1969 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
1970 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1971 while ( nIt->more() ) {
1972 const SMDS_MeshNode* elem = nIt->next();
1973 theElems.insert( elem->GetID() );
1976 else { // all nodes of submesh elements
1977 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1978 while ( eIt->more() ) {
1979 const SMDS_MeshElement* anElem = eIt->next();
1980 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
1981 while ( nIt->more() ) {
1982 const SMDS_MeshElement* elem = nIt->next();
1983 theElems.insert( elem->GetID() );
1988 aResult->length(theElems.size());
1989 set<int>::iterator itElem;
1991 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
1992 aResult[i++] = *itElem;
1994 return aResult._retn();
1998 //=============================================================================
2000 * Returns type of elements for given submesh
2002 //=============================================================================
2003 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
2004 throw (SALOME::SALOME_Exception)
2006 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2007 if(!SM) return SMESH::ALL;
2009 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2010 if(!SDSM) return SMESH::ALL;
2012 if(SDSM->NbElements()==0)
2013 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
2015 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2016 const SMDS_MeshElement* anElem = eIt->next();
2017 return ( SMESH::ElementType ) anElem->GetType();
2021 //=============================================================================
2025 //=============================================================================
2027 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
2029 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
2030 cerr << "CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() " << pointeur << endl;
2035 //=============================================================================
2037 * Get XYZ coordinates of node as list of double
2038 * If there is not node for given ID - returns empty list
2040 //=============================================================================
2042 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2044 SMESH::double_array_var aResult = new SMESH::double_array();
2045 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2046 if ( aSMESHDS_Mesh == NULL )
2047 return aResult._retn();
2050 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2052 return aResult._retn();
2056 aResult[0] = aNode->X();
2057 aResult[1] = aNode->Y();
2058 aResult[2] = aNode->Z();
2059 return aResult._retn();
2063 //=============================================================================
2065 * For given node returns list of IDs of inverse elements
2066 * If there is not node for given ID - returns empty list
2068 //=============================================================================
2070 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2072 SMESH::long_array_var aResult = new SMESH::long_array();
2073 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2074 if ( aSMESHDS_Mesh == NULL )
2075 return aResult._retn();
2078 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2080 return aResult._retn();
2082 // find inverse elements
2083 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2084 TColStd_SequenceOfInteger IDs;
2085 while(eIt->more()) {
2086 const SMDS_MeshElement* elem = eIt->next();
2087 IDs.Append(elem->GetID());
2089 if(IDs.Length()>0) {
2090 aResult->length(IDs.Length());
2092 for(; i<=IDs.Length(); i++) {
2093 aResult[i-1] = IDs.Value(i);
2096 return aResult._retn();
2099 //=============================================================================
2101 * \brief Return position of a node on shape
2103 //=============================================================================
2105 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
2107 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
2108 aNodePosition->shapeID = 0;
2109 aNodePosition->shapeType = GEOM::SHAPE;
2111 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
2112 if ( !mesh ) return aNodePosition;
2114 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
2116 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
2118 aNodePosition->shapeID = pos->GetShapeId();
2119 switch ( pos->GetTypeOfPosition() ) {
2121 aNodePosition->shapeType = GEOM::EDGE;
2122 aNodePosition->params.length(1);
2123 aNodePosition->params[0] =
2124 static_cast<SMDS_EdgePosition*>( pos.get() )->GetUParameter();
2127 aNodePosition->shapeType = GEOM::FACE;
2128 aNodePosition->params.length(2);
2129 aNodePosition->params[0] =
2130 static_cast<SMDS_FacePosition*>( pos.get() )->GetUParameter();
2131 aNodePosition->params[1] =
2132 static_cast<SMDS_FacePosition*>( pos.get() )->GetVParameter();
2134 case SMDS_TOP_VERTEX:
2135 aNodePosition->shapeType = GEOM::VERTEX;
2137 case SMDS_TOP_3DSPACE:
2138 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
2139 aNodePosition->shapeType = GEOM::SOLID;
2140 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
2141 aNodePosition->shapeType = GEOM::SHELL;
2147 return aNodePosition;
2150 //=============================================================================
2152 * If given element is node returns IDs of shape from position
2153 * If there is not node for given ID - returns -1
2155 //=============================================================================
2157 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2159 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2160 if ( aSMESHDS_Mesh == NULL )
2164 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2166 SMDS_PositionPtr pos = aNode->GetPosition();
2170 return pos->GetShapeId();
2177 //=============================================================================
2179 * For given element returns ID of result shape after
2180 * ::FindShape() from SMESH_MeshEditor
2181 * If there is not element for given ID - returns -1
2183 //=============================================================================
2185 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2187 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2188 if ( aSMESHDS_Mesh == NULL )
2191 // try to find element
2192 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2196 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2197 ::SMESH_MeshEditor aMeshEditor(_impl);
2198 int index = aMeshEditor.FindShape( elem );
2206 //=============================================================================
2208 * Returns number of nodes for given element
2209 * If there is not element for given ID - returns -1
2211 //=============================================================================
2213 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2215 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2216 if ( aSMESHDS_Mesh == NULL ) return -1;
2217 // try to find element
2218 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2219 if(!elem) return -1;
2220 return elem->NbNodes();
2224 //=============================================================================
2226 * Returns ID of node by given index for given element
2227 * If there is not element for given ID - returns -1
2228 * If there is not node for given index - returns -2
2230 //=============================================================================
2232 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2234 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2235 if ( aSMESHDS_Mesh == NULL ) return -1;
2236 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2237 if(!elem) return -1;
2238 if( index>=elem->NbNodes() || index<0 ) return -1;
2239 return elem->GetNode(index)->GetID();
2242 //=============================================================================
2244 * Returns IDs of nodes of given element
2246 //=============================================================================
2248 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2250 SMESH::long_array_var aResult = new SMESH::long_array();
2251 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2253 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2255 aResult->length( elem->NbNodes() );
2256 for ( int i = 0; i < elem->NbNodes(); ++i )
2257 aResult[ i ] = elem->GetNode( i )->GetID();
2260 return aResult._retn();
2263 //=============================================================================
2265 * Returns true if given node is medium node
2266 * in given quadratic element
2268 //=============================================================================
2270 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2272 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2273 if ( aSMESHDS_Mesh == NULL ) return false;
2275 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2276 if(!aNode) return false;
2277 // try to find element
2278 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2279 if(!elem) return false;
2281 return elem->IsMediumNode(aNode);
2285 //=============================================================================
2287 * Returns true if given node is medium node
2288 * in one of quadratic elements
2290 //=============================================================================
2292 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2293 SMESH::ElementType theElemType)
2295 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2296 if ( aSMESHDS_Mesh == NULL ) return false;
2299 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2300 if(!aNode) return false;
2302 SMESH_MesherHelper aHelper( *(_impl) );
2304 SMDSAbs_ElementType aType;
2305 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2306 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2307 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2308 else aType = SMDSAbs_All;
2310 return aHelper.IsMedium(aNode,aType);
2314 //=============================================================================
2316 * Returns number of edges for given element
2318 //=============================================================================
2320 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2322 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2323 if ( aSMESHDS_Mesh == NULL ) return -1;
2324 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2325 if(!elem) return -1;
2326 return elem->NbEdges();
2330 //=============================================================================
2332 * Returns number of faces for given element
2334 //=============================================================================
2336 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2338 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2339 if ( aSMESHDS_Mesh == NULL ) return -1;
2340 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2341 if(!elem) return -1;
2342 return elem->NbFaces();
2346 //=============================================================================
2348 * Returns true if given element is polygon
2350 //=============================================================================
2352 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2354 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2355 if ( aSMESHDS_Mesh == NULL ) return false;
2356 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2357 if(!elem) return false;
2358 return elem->IsPoly();
2362 //=============================================================================
2364 * Returns true if given element is quadratic
2366 //=============================================================================
2368 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2370 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2371 if ( aSMESHDS_Mesh == NULL ) return false;
2372 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2373 if(!elem) return false;
2374 return elem->IsQuadratic();
2378 //=============================================================================
2380 * Returns bary center for given element
2382 //=============================================================================
2384 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2386 SMESH::double_array_var aResult = new SMESH::double_array();
2387 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2388 if ( aSMESHDS_Mesh == NULL )
2389 return aResult._retn();
2391 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2393 return aResult._retn();
2395 if(elem->GetType()==SMDSAbs_Volume) {
2396 SMDS_VolumeTool aTool;
2397 if(aTool.Set(elem)) {
2399 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
2404 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2406 double x=0., y=0., z=0.;
2407 for(; anIt->more(); ) {
2409 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2423 return aResult._retn();
2427 //=============================================================================
2429 * Create and publish group servants if any groups were imported or created anyhow
2431 //=============================================================================
2433 void SMESH_Mesh_i::CreateGroupServants()
2435 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2437 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
2438 while ( groupIt->more() )
2440 ::SMESH_Group* group = groupIt->next();
2441 int anId = group->GetGroupDS()->GetID();
2443 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
2444 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2447 SMESH_GroupBase_i* aGroupImpl;
2449 if ( SMESHDS_GroupOnGeom* groupOnGeom =
2450 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
2452 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
2453 shape = groupOnGeom->GetShape();
2456 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2459 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
2460 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2461 aGroupImpl->Register();
2463 SMESH::SMESH_GroupBase_var groupVar =
2464 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
2465 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
2467 // register CORBA object for persistence
2468 int nextId = _gen_i->RegisterObject( groupVar );
2469 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
2471 // publishing of the groups in the study
2472 if ( !aStudy->_is_nil() ) {
2473 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
2474 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
2479 //=============================================================================
2481 * \brief Return groups cantained in _mapGroups by their IDs
2483 //=============================================================================
2485 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
2487 int nbGroups = groupIDs.size();
2488 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
2489 aList->length( nbGroups );
2491 list<int>::const_iterator ids = groupIDs.begin();
2492 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
2494 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
2495 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2496 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
2498 aList->length( nbGroups );
2499 return aList._retn();
2502 //=============================================================================
2504 * \brief Return information about imported file
2506 //=============================================================================
2507 SALOME_MED::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
2509 SALOME_MED::MedFileInfo_var res = new SALOME_MED::MedFileInfo();
2511 const char* name = myFile.c_str();
2512 res->fileName = name;
2513 res->fileSize = 0;//myFileInfo.size();
2514 int major, minor, release;
2515 if( !MED::getMEDVersion( name, major, minor, release ) )
2523 res->release = release;