#include "SMESH_Mesh_i.hxx"
-#include "SMESH_Filter_i.hxx"
-#include "SMESH_Gen_i.hxx"
-#include "SMESH_Group_i.hxx"
-#include "SMESH_MEDMesh_i.hxx"
-#include "SMESH_MeshEditor_i.hxx"
-#include "SMESH_PythonDump.hxx"
-#include "SMESH_subMesh_i.hxx"
-
#include "DriverMED_R_SMESHDS_Mesh.h"
#include "DriverMED_W_SMESHDS_Mesh.h"
#include "SMDS_EdgePosition.hxx"
#include "SMDS_ElemIterator.hxx"
#include "SMDS_FacePosition.hxx"
+#include "SMDS_IteratorOnIterators.hxx"
#include "SMDS_SetIterator.hxx"
#include "SMDS_VolumeTool.hxx"
#include "SMESHDS_Command.hxx"
#include "SMESHDS_CommandType.hxx"
#include "SMESHDS_GroupOnGeom.hxx"
+#include "SMESH_Filter_i.hxx"
+#include "SMESH_Gen_i.hxx"
#include "SMESH_Group.hxx"
+#include "SMESH_Group_i.hxx"
+#include "SMESH_MEDMesh_i.hxx"
#include "SMESH_MeshEditor.hxx"
+#include "SMESH_MeshEditor_i.hxx"
#include "SMESH_MesherHelper.hxx"
+#include "SMESH_PythonDump.hxx"
+#include "SMESH_subMesh_i.hxx"
-#include "OpUtil.hxx"
-#include "SALOME_NamingService.hxx"
-#include "Utils_CorbaException.hxx"
-#include "Utils_ExceptHandlers.hxx"
-#include "Utils_SINGLETON.hxx"
-#include "utilities.h"
-#include "GEOMImpl_Types.hxx"
+#include <OpUtil.hxx>
+#include <SALOME_NamingService.hxx>
+#include <Utils_CorbaException.hxx>
+#include <Utils_ExceptHandlers.hxx>
+#include <Utils_SINGLETON.hxx>
+#include <utilities.h>
+#include <GEOMImpl_Types.hxx>
// OCCT Includes
#include <BRep_Builder.hxx>
return ConvertDriverMEDReadStatus(status);
}
+//================================================================================
+/*!
+ * \brief Imports mesh data from the CGNS file
+ */
+//================================================================================
+
+SMESH::DriverMED_ReadStatus SMESH_Mesh_i::ImportCGNSFile( const char* theFileName,
+ const int theMeshIndex,
+ std::string& theMeshName )
+ throw ( SALOME::SALOME_Exception )
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ int status;
+ try {
+ status = _impl->CGNSToMesh( theFileName, theMeshIndex, theMeshName );
+ }
+ catch( SALOME_Exception& S_ex ) {
+ THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
+ }
+ catch ( ... ) {
+ THROW_SALOME_CORBA_EXCEPTION("ImportCGNSFile(): unknown exception", SALOME::BAD_PARAM);
+ }
+
+ CreateGroupServants();
+
+ return ConvertDriverMEDReadStatus(status);
+}
+
//================================================================================
/*!
* \brief Return string representation of a MED file version comprising nbDigits
return aList._retn();
}
+SMESH::submesh_array* SMESH_Mesh_i::GetSubMeshes() throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if (MYDEBUG) MESSAGE("GetSubMeshes");
+
+ SMESH::submesh_array_var aList = new SMESH::submesh_array();
+
+ // Python Dump
+ TPythonDump aPythonDump;
+ if ( !_mapSubMeshIor.empty() )
+ aPythonDump << "[ ";
+
+ try {
+ aList->length( _mapSubMeshIor.size() );
+ int i = 0;
+ map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.begin();
+ for ( ; it != _mapSubMeshIor.end(); it++ ) {
+ if ( CORBA::is_nil( it->second )) continue;
+ aList[i++] = SMESH::SMESH_subMesh::_duplicate( it->second );
+ // Python Dump
+ if (i > 1) aPythonDump << ", ";
+ aPythonDump << it->second;
+ }
+ aList->length( i );
+ }
+ catch(SALOME_Exception & S_ex) {
+ THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
+ }
+
+ // Update Python script
+ if ( !_mapSubMeshIor.empty() )
+ aPythonDump << " ] = " << _this() << ".GetSubMeshes()";
+
+ return aList._retn();
+}
+
//=============================================================================
/*!
*
removeSubMesh( theSubMesh, aSubShapeObject.in() );
}
-//=============================================================================
-/*!
- * ElementTypeString
- */
-//=============================================================================
-#define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
-inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
-{
- switch (theElemType) {
- CASE2STRING( ALL );
- CASE2STRING( NODE );
- CASE2STRING( EDGE );
- CASE2STRING( FACE );
- CASE2STRING( VOLUME );
- CASE2STRING( ELEM0D );
- default:;
- }
- return "";
-}
-
//=============================================================================
/*!
*
if ( !aSO->_is_nil()) {
// Update Python script
TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
- << ElementTypeString(theElemType) << ", '" << theName << "' )";
+ << theElemType << ", '" << theName << "' )";
}
}
return aNewGroup._retn();
*
*/
//=============================================================================
-SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
- const char* theName,
- GEOM::GEOM_Object_ptr theGeomObj)
+SMESH::SMESH_GroupOnGeom_ptr
+SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
+ const char* theName,
+ GEOM::GEOM_Object_ptr theGeomObj)
throw(SALOME::SALOME_Exception)
{
Unexpect aCatch(SALOME_SalomeException);
if ( !aSO->_is_nil()) {
// Update Python script
TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
- << ElementTypeString(theElemType) << ", '" << theName << "', "
- << theGeomObj << " )";
+ << theElemType << ", '" << theName << "', " << theGeomObj << " )";
}
}
}
return aNewGroup._retn();
}
+//================================================================================
+/*!
+ * \brief Creates a group whose contents is defined by filter
+ * \param theElemType - group type
+ * \param theName - group name
+ * \param theFilter - the filter
+ * \retval SMESH::SMESH_GroupOnFilter_ptr - group defined by filter
+ */
+//================================================================================
+
+SMESH::SMESH_GroupOnFilter_ptr
+SMESH_Mesh_i::CreateGroupFromFilter(SMESH::ElementType theElemType,
+ const char* theName,
+ SMESH::Filter_ptr theFilter )
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ if ( CORBA::is_nil( theFilter ))
+ THROW_SALOME_CORBA_EXCEPTION("NULL filter", SALOME::BAD_PARAM);
+
+ SMESH_PredicatePtr predicate = SMESH_GroupOnFilter_i::GetPredicate( theFilter );
+ if ( !predicate )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid filter", SALOME::BAD_PARAM);
+
+ SMESH::SMESH_GroupOnFilter_var aNewGroup = SMESH::SMESH_GroupOnFilter::_narrow
+ ( createGroup( theElemType, theName, TopoDS_Shape(), predicate ));
+
+ TPythonDump pd;
+ if ( !aNewGroup->_is_nil() )
+ aNewGroup->SetFilter( theFilter );
+
+ if ( _gen_i->CanPublishInStudy( aNewGroup ) )
+ {
+ SALOMEDS::SObject_var aSO =
+ _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(), aNewGroup,
+ GEOM::GEOM_Object::_nil(), theName);
+ if ( !aSO->_is_nil()) {
+ // Update Python script
+ pd << aSO << " = " << _this() << ".CreateGroupFromFilter("
+ << theElemType << ", '" << theName << "', " << theFilter << " )";
+ }
+ }
+
+ return aNewGroup._retn();
+}
+
//=============================================================================
/*!
*
//=============================================================================
/*!
- * \brief Create standalone group instead if group on geometry
+ * \brief Create standalone group from a group on geometry or filter
*/
//=============================================================================
-SMESH::SMESH_Group_ptr SMESH_Mesh_i::ConvertToStandalone( SMESH::SMESH_GroupOnGeom_ptr theGroup )
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::ConvertToStandalone( SMESH::SMESH_GroupBase_ptr theGroup )
{
SMESH::SMESH_Group_var aGroup;
if ( theGroup->_is_nil() )
if ( !aGroupToRem )
return aGroup._retn();
+ const bool isOnFilter = ( SMESH::DownCast< SMESH_GroupOnFilter_i* > ( theGroup ));
+
int anId = aGroupToRem->GetLocalID();
if ( !_impl->ConvertToStandalone( anId ) )
return aGroup._retn();
aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
if ( !aGroupSO->_is_nil() ) {
- // remove reference to geometry
- SALOMEDS::ChildIterator_var chItr = aStudy->NewChildIterator(aGroupSO);
- for ( ; chItr->More(); chItr->Next() )
- // Remove group's child SObject
- builder->RemoveObject( chItr->Value() );
+ // remove reference to geometry
+ SALOMEDS::ChildIterator_var chItr = aStudy->NewChildIterator(aGroupSO);
+ for ( ; chItr->More(); chItr->Next() )
+ // Remove group's child SObject
+ builder->RemoveObject( chItr->Value() );
// Update Python script
TPythonDump() << aGroupSO << " = " << _this() << ".ConvertToStandalone( "
<< aGroupSO << " )";
+
+ // change icon of Group on Filter
+ if ( isOnFilter )
+ {
+ SMESH::array_of_ElementType_var elemTypes = aGroupImpl->GetTypes();
+ const int isEmpty = ( elemTypes->length() == 0 );
+ if ( !isEmpty )
+ {
+ SALOMEDS::GenericAttribute_var anAttr =
+ builder->FindOrCreateAttribute( aGroupSO, "AttributePixMap" );
+ SALOMEDS::AttributePixMap_var pm = SALOMEDS::AttributePixMap::_narrow( anAttr );
+ pm->SetPixMap( "ICON_SMESH_TREE_GROUP" );
+ }
+ }
}
}
*/
//=============================================================================
-SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
- const char* theName,
- const TopoDS_Shape& theShape )
+SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
+ const char* theName,
+ const TopoDS_Shape& theShape,
+ const SMESH_PredicatePtr& thePredicate )
{
std::string newName;
if ( !theName || strlen( theName ) == 0 )
}
int anId;
SMESH::SMESH_GroupBase_var aGroup;
- if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
+ if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape, thePredicate ))
+ {
SMESH_GroupBase_i* aGroupImpl;
if ( !theShape.IsNull() )
aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
+ else if ( thePredicate )
+ aGroupImpl = new SMESH_GroupOnFilter_i( SMESH_Gen_i::GetPOA(), this, anId );
else
aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
<< meshPart<< ", r'" << file << "', " << isascii << ")";
}
+//================================================================================
+/*!
+ * \brief Export a part of mesh to an STL file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file,
+ CORBA::Boolean overwrite)
+ throw (SALOME::SALOME_Exception)
+{
+#ifdef WITH_CGNS
+ Unexpect aCatch(SALOME_SalomeException);
+
+ PrepareForWriting(file,overwrite);
+
+ SMESH_MeshPartDS partDS( meshPart );
+ _impl->ExportCGNS(file, &partDS);
+
+ TPythonDump() << _this() << ".ExportCGNS( "
+ << meshPart<< ", r'" << file << "', " << overwrite << ")";
+#else
+ THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR);
+#endif
+}
+
//=============================================================================
/*!
*
_meshDS = mesh_i->GetImpl().GetMeshDS();
+ SetPersistentId( _meshDS->GetPersistentId() );
+
if ( mesh_i == SMESH::DownCast<SMESH_Mesh_i*>( meshPart ))
{
// <meshPart> is the whole mesh
myInfo = _meshDS->GetMeshInfo(); // copy mesh info;
+ // copy groups
+ set<SMESHDS_GroupBase*>& myGroupSet = const_cast<set<SMESHDS_GroupBase*>&>( GetGroups() );
+ myGroupSet = _meshDS->GetGroups();
}
else
{
SMDS_ElemIteratorPtr SMESH_MeshPartDS::elementsIterator(SMDSAbs_ElementType type) const
{
typedef SMDS_SetIterator<const SMDS_MeshElement*, TIDSortedElemSet::const_iterator > TIter;
+ if ( type == SMDSAbs_All && !_meshDS )
+ {
+ typedef vector< SMDS_ElemIteratorPtr > TIterVec;
+ TIterVec iterVec;
+ for ( int i = 0; i < SMDSAbs_NbElementTypes; ++i )
+ if ( !_elements[i].empty() && i != SMDSAbs_Node )
+ iterVec.push_back
+ ( SMDS_ElemIteratorPtr( new TIter( _elements[i].begin(), _elements[i].end() )));
+
+ typedef SMDS_IteratorOnIterators<const SMDS_MeshElement*, TIterVec > TIterOnIters;
+ return SMDS_ElemIteratorPtr( new TIterOnIters( iterVec ));
+ }
return _meshDS ? _meshDS->elementsIterator(type) : SMDS_ElemIteratorPtr
- ( new TIter( _elements[type].begin(), _elements[type].end() ));
+ ( new TIter( _elements[type].begin(), _elements[type].end() ));
}
#define _GET_ITER_DEFINE( iterType, methName, elem, elemType) \
iterType SMESH_MeshPartDS::methName( bool idInceasingOrder) const \