-// Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#include "SMESH_PreMeshInfo.hxx"
#include "SMESH_PythonDump.hxx"
#include "SMESH_subMesh_i.hxx"
+#include "SMESH_Meshio.h"
#include <SALOMEDS_Attributes_wrap.hxx>
#include <SALOMEDS_wrap.hxx>
#include "SMESH_TryCatch.hxx" // include after OCCT headers!
-#ifdef _DEBUG_
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
-
using namespace std;
using SMESH::TPythonDump;
using SMESH::TVar;
if ( prevNbMeshEnt > 0 /*newNbMeshEnt != prevNbMeshEnt*/ )
_gen_i->UpdateIcons( mesh );
}
- if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
+ MESSAGE( " AddHypothesis(): status = " << status );
// Update Python script
TPythonDump() << "status = " << mesh << ".AddHypothesis( "
SMESH::SMESH_Hypothesis_ptr anHyp,
std::string* anErrorText)
{
- if(MYDEBUG) MESSAGE("addHypothesis");
+ MESSAGE("addHypothesis");
if (CORBA::is_nil( aSubShape ) && HasShapeToMesh())
THROW_SALOME_CORBA_EXCEPTION("bad Sub-shape reference",SALOME::BAD_PARAM);
SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShape,
SMESH::SMESH_Hypothesis_ptr anHyp)
{
- if(MYDEBUG) MESSAGE("removeHypothesis()");
+ MESSAGE("removeHypothesis()");
if (CORBA::is_nil( aSubShape ) && HasShapeToMesh())
THROW_SALOME_CORBA_EXCEPTION("bad Sub-shape reference", SALOME::BAD_PARAM);
SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShape)
{
Unexpect aCatch(SALOME_SalomeException);
- if (MYDEBUG) MESSAGE("GetHypothesisList");
+ MESSAGE("GetHypothesisList");
if (_impl->HasShapeToMesh() && CORBA::is_nil(aSubShape))
THROW_SALOME_CORBA_EXCEPTION("bad Sub-shape reference", SALOME::BAD_PARAM);
SMESH::submesh_array* SMESH_Mesh_i::GetSubMeshes()
{
Unexpect aCatch(SALOME_SalomeException);
- if (MYDEBUG) MESSAGE("GetSubMeshes");
+ MESSAGE("GetSubMeshes");
SMESH::submesh_array_var aList = new SMESH::submesh_array();
SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups()
{
Unexpect aCatch(SALOME_SalomeException);
- if (MYDEBUG) MESSAGE("GetGroups");
+ MESSAGE("GetGroups");
SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
}
old2newShapeMap.Bind( group->GetShape(), groupsData.back()._shape );
}
-
+
}
}
// store assigned hypotheses
SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
{
- if(MYDEBUG) MESSAGE( "createSubMesh" );
+ MESSAGE( "createSubMesh" );
TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
int subMeshId = 0;
// register CORBA object for persistence
int nextId = _gen_i->RegisterObject( subMesh );
- if(MYDEBUG) { MESSAGE( "Add submesh to map with id = "<< nextId); }
- else { (void)nextId; } // avoid "unused variable" warning
+ MESSAGE( "Add submesh to map with id = "<< nextId);
// to track changes of GEOM groups
if ( subMeshId > 0 )
// register CORBA object for persistence
int nextId = _gen_i->RegisterObject( aGroup );
- if(MYDEBUG) { MESSAGE( "Add group to map with id = "<< nextId); }
- else { nextId = ( nextId > 0 ); } // avoid "unused variable" warning in release mode
+ MESSAGE( "Add group to map with id = "<< nextId);
// to track changes of GEOM groups
if ( !theShape.IsNull() ) {
void SMESH_Mesh_i::removeGroup( const int theId )
{
- if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
+ MESSAGE("SMESH_Mesh_i::removeGroup()");
if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
SMESH::SMESH_GroupBase_var group = _mapGroups[theId];
_mapGroups.erase( theId );
void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
{
- if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
+ MESSAGE("SMESH_Mesh_i::SetImpl");
_impl = impl;
if ( _impl )
_impl->SetCallUp( new TCallUp_i(this));
::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
{
- if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
+ MESSAGE("SMESH_Mesh_i::GetImpl()");
return *_impl;
}
checkGroupNames();
// Update Python script
TPythonDump() << SMESH::SMESH_Mesh_var(_this())
- << ".ExportUNV( r'" << file << "' " << renumber << "' )";
+ << ".ExportUNV( r'" << file << "', " << renumber << " )";
// Perform Export
PrepareForWriting( file );
SMESH_CATCH( SMESH::throwCorbaException );
}
+//================================================================================
+/*!
+ * \brief Export a part of mesh to a file with meshio library
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportPartToMESHIO(SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file,
+ const char* selectedFilter)
+{
+ // Get default MED version
+ SMESH::long_array_var medVersions = GetMEDVersionsCompatibleForAppend();
+ const CORBA::Long version = medVersions[0];
+ MESSAGE("Export part with meshio through MED version: " << version);
+
+ // Default values are the same as for MED export
+ const bool auto_groups = false;
+ const bool overwrite = true;
+ const bool autoDimension = true;
+ const GEOM::ListOfFields fields;
+ const char* geomAssocFields = "";
+ const double ZTolerance = -1.0;
+ const bool saveNumbers = true;
+
+ // Create an object that holds a temp file name and
+ // removes the file when goes out of scope.
+ SMESH_Meshio meshio(selectedFilter);
+ const QString tempFileName = meshio.CreateTempFileName(file);
+
+ // Export a given mesh into the temp file
+ MEDFileSpeCls spe(tempFileName.toUtf8().data(), overwrite, version);
+ this->ExportPartToMEDCommon(spe, meshPart, auto_groups, autoDimension, fields,
+ geomAssocFields, ZTolerance, saveNumbers);
+
+ // Convert temp file into a target one with meshio command
+ meshio.Convert(tempFileName, file);
+
+ // Prepare python dump
+ SMESH_TRY;
+
+ TPythonDump() << _this() << ".ExportPartToMESHIO("
+ << meshPart << ", r'"
+ << file << "', '"
+ << selectedFilter << "'"
+ << ")";
+
+ SMESH_CATCH(SMESH::throwCorbaException);
+}
+
//================================================================================
class MEDFileMemSpeCls
//================================================================================
/*!
- * \brief Export a part of mesh to an STL file
+ * \brief Export a part of mesh to an CGNS file
*/
//================================================================================
#endif
}
+//================================================================================
+/*!
+ * \brief Export a part of mesh to an StructuredCGNS file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportStructuredCGNS( SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file,
+ CORBA::Boolean overwrite )
+{
+#ifdef WITH_CGNS
+ SMESH_TRY;
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ PrepareForWriting(file,overwrite);
+
+ std::string meshName("");
+ SALOMEDS::SObject_wrap so = _gen_i->ObjectToSObject( meshPart );
+ if ( !so->_is_nil() )
+ {
+ CORBA::String_var name = so->GetName();
+ meshName = name.in();
+ }
+ SMESH_TRY;
+
+ SMESH::SMESH_Mesh_var mesh = meshPart->GetMesh();
+ SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
+ mesh_i->Load();
+ auto myMesh = mesh_i->GetImpl().GetMeshDS();
+ _impl->ExportStructuredCGNS(file, myMesh, meshName.c_str());
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+
+ TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportStructuredCGNS( "
+ "r'" << file << "', " << overwrite << ", " << meshPart << ")";
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+
+#else
+ THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR);
+#endif
+}
+
//================================================================================
/*!
* \brief Export a part of mesh to a GMF file
_preMeshInfo->FullLoadFromFile();
CORBA::LongLong pointeur = CORBA::LongLong(_impl);
- if ( MYDEBUG ) MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
+ MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
return pointeur;
}
// register CORBA object for persistence
int nextId = _gen_i->RegisterObject( groupVar );
- if(MYDEBUG) { MESSAGE( "Add group to map with id = "<< nextId); }
- else { (void)nextId; } // avoid "unused variable" warning in release mode
+ MESSAGE( "Add group to map with id = "<< nextId);
// publishing the groups in the study
GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
*/
//=============================================================================
-bool SMESH_Mesh_i::IsComputedOK()
+CORBA::Boolean SMESH_Mesh_i::IsComputedOK()
{
return _impl->IsComputedOK();
}
/*!
* \brief Return false if GetMeshInfo() return incorrect information that may
* happen if mesh data is not yet fully loaded from the file of study.
- *
- *
+ *
+ *
*/
//================================================================================
return res;
}
+
//=============================================================================
/*!
* \brief Convert submesh ids into submesh interfaces
{
if ( _meshDS ) return _meshDS->MinNodeID();
return NbNodes() == 0 ? 0 : (*_elements[ SMDSAbs_Node ].begin())->GetID();
-}
+}
// -------------------------------------------------------------------------------------
smIdType SMESH_MeshPartDS::MaxElementID() const
{