First implementation of iterator

This commit is contained in:
Mathis Chevallier 2024-12-11 15:01:07 +01:00
parent 3d4fc4e1e2
commit e88352f46f
12 changed files with 133 additions and 4 deletions

View File

@ -170,6 +170,10 @@ module SMESH
*/
boolean IsEnablePublish();
/*!
* void SetAlgoIterator(in long long ptAlgoPy);
*/
/*!
* Create a hypothesis that can be shared by different parts of the mesh.
* An hypothesis is either:

View File

@ -776,6 +776,9 @@ module SMESH
*/
double GetComputeProgress();
void SetAlgoIterator(in long long ptAlgoPy)
raises (SALOME::SALOME_Exception);
/*!
* Get information about mesh contents
*/

View File

@ -61,6 +61,7 @@ SET(_link_LIBRARIES
${GEOM_NMTTools}
${GEOM_GEOMUtils}
${Boost_LIBRARIES}
${PYTHON_LIBRARIES}
SMESHDS
SMESHControls
MeshDriverDAT
@ -124,6 +125,11 @@ SET(SMESHimpl_SOURCES
SMESH_MeshLocker.cxx
)
SET(SMESH_ENGINE_PY
smesh_algoIterator.py
)
# --- rules ---
ADD_LIBRARY(SMESHimpl ${SMESHimpl_SOURCES})
@ -136,3 +142,5 @@ TARGET_LINK_LIBRARIES(SMESHimpl ${_link_LIBRARIES} )
INSTALL(TARGETS SMESHimpl EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
INSTALL(FILES ${SMESHimpl_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})
SALOME_INSTALL_SCRIPTS("${SMESH_ENGINE_PY}" ${SALOME_INSTALL_PYTHON}/salome/smesh DEF_PERMS)

View File

@ -39,6 +39,7 @@
#include "SMESH_Hypothesis.hxx"
#include "SMESH_subMesh.hxx"
#include "PythonCppUtils.hxx"
#include "utilities.h"
#include "DriverDAT_W_SMDS_Mesh.h"
@ -97,6 +98,12 @@ class SMESH_Mesh::SubMeshHolder : public SMESHDS_TSubMeshHolder< SMESH_subMesh >
{
};
struct SMESH_Mesh::PyImpl
{
AutoPyRef pyref;
operator PyObject *() { return pyref; }
};
//=============================================================================
/*!
*
@ -107,7 +114,7 @@ SMESH_Mesh::SMESH_Mesh(int theLocalId,
SMESH_Gen* theGen,
bool theIsEmbeddedMode,
SMESHDS_Document* theDocument):
_groupId( 0 ), _nbSubShapes( 0 )
_groupId( 0 ), _nbSubShapes( 0 ), _pAlgoIt(new SMESH_Mesh::PyImpl)
{
MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
_id = theLocalId;
@ -158,7 +165,8 @@ SMESH_Mesh::SMESH_Mesh():
_isAutoColor( false ),
_isModified( false ),
_shapeDiagonal( 0.0 ),
_callUp( 0 )
_callUp( 0 ),
_pAlgoIt(new SMESH_Mesh::PyImpl)
{
_subMeshHolder = new SubMeshHolder;
}
@ -233,6 +241,7 @@ SMESH_Mesh::~SMESH_Mesh()
int result=pthread_create(&thread, NULL, deleteMeshDS, (void*)_meshDS);
#endif
}
delete _pAlgoIt;
}
//================================================================================
@ -2588,6 +2597,38 @@ bool SMESH_Mesh::IsOrderOK( const SMESH_subMesh* smBefore,
return true; // no order imposed to given sub-meshes
}
void *SMESH_Mesh::getAlgoIt()
{
return (PyObject *)this->_pAlgoIt->pyref;
}
void SMESH_Mesh::SetAlgoIterator(void *pAlgoItVoid)
{
PyObject *pAlgoIt = reinterpret_cast<PyObject *>(pAlgoItVoid);
AutoGIL gstate;
if(pAlgoIt){
_pAlgoIt->pyref = pAlgoIt;
std::cout << "pAlgoIt OK " << std::endl;
//seg fault
//PyObject *pGetPath = PyObject_GetAttrString(_pAlgoIt, "getItPath");
AutoPyRef name_attr = PyObject_GetAttrString(*_pAlgoIt, "path");
if (!!name_attr && PyUnicode_Check(name_attr)) {
const char* name = PyUnicode_AsUTF8(name_attr);
std::cout << "name: " << name << std::endl;
} else {
std::cerr << "Error: Attribute 'name' not found" << std::endl;
}
}else{
std::cerr << "pAlgoIt KO" << std::endl;
}
}
//=============================================================================
/*!
* \brief sort submeshes according to stored mesh order

View File

@ -392,6 +392,10 @@ class SMESH_EXPORT SMESH_Mesh
std::ostream& Dump(std::ostream & save);
void* getAlgoIt();
void SetAlgoIterator(void* pAlgoIt);
// Parallel computation functions
virtual void Lock(){};
@ -459,9 +463,11 @@ protected:
// when group removal is invoked by hyp modification (issue 0020918)
// 2) to forget not loaded mesh data at hyp modification
TCallUp* _callUp;
struct PyImpl;
PyImpl *_pAlgoIt = nullptr; // python iterator object of each mesh to generate a json
protected:
SMESH_Mesh();
SMESH_Mesh(const SMESH_Mesh&) {};
SMESH_Mesh(const SMESH_Mesh&) { _pAlgoIt = nullptr; }
};
#endif

View File

@ -76,8 +76,12 @@ void SMESH_ParallelMesh::cleanup()
//=============================================================================
bool SMESH_ParallelMesh::keepingTmpFolfer()
{
const char* envSALOME_SMESH_DEBUG = std::getenv("SALOME_SMESH_DEBUG");
if(!!envSALOME_SMESH_DEBUG){
setenv("SMESH_KEEP_TMP", "1", 1); //1 to overwrite
}
const char* envVar = std::getenv("SMESH_KEEP_TMP");
if (envVar && (envVar[0] != '\0'))
{
try

View File

@ -0,0 +1,19 @@
#testing import
import salome
import SMESH
import json
import os
class AlgoIterator:
def __init__(self, path):
self.path = path
self.jsonData = []
def getNumberOfAlgoCalls(self):
return len(self.jsonData)
def getItPath(self):
return self.path

View File

@ -724,6 +724,11 @@ void SMESH_Gen_i::SetEnablePublish( CORBA::Boolean theIsEnablePublish )
myIsEnablePublish = theIsEnablePublish;
}
// void SMESH_Gen_i::SetAlgoIterator( CORBA::LongLong ptAlgoPy )
// {
// std::cout << "Mathoissssssssssssssssssssssss " << ptAlgoPy << std::endl;
// }
//=============================================================================
/*!
* SMESH_Gen_i::IsEnablePublish

View File

@ -165,6 +165,8 @@ public:
// Set enable publishing in the study
void SetEnablePublish( CORBA::Boolean theIsEnablePublish );
//void SetAlgoIterator( CORBA::LongLong ptAlgoPy);
// Check enable publishing
CORBA::Boolean IsEnablePublish();

View File

@ -23,6 +23,8 @@
// Author : Paul RASCLE, EDF
// Module : SMESH
#include <Python.h>
#include "SMESH_Mesh_i.hxx"
#include "DriverMED_R_SMESHDS_Mesh.h"
@ -4638,6 +4640,22 @@ CORBA::Double SMESH_Mesh_i::GetComputeProgress()
return 0.;
}
void SMESH_Mesh_i::SetAlgoIterator( CORBA::LongLong ptAlgoPy )
{
SMESH_TRY;
std::cout << "SMESH_Mesh_i.cxx::SetAlgoIterator -> " << ptAlgoPy << std::endl;
PyObject* pAlgoIt = reinterpret_cast<PyObject*>(ptAlgoPy);
std::cout << "SMESH_Mesh_i.cxx::SetAlgoIterator 2 -> " << pAlgoIt << std::endl;
_impl->SetAlgoIterator(pAlgoIt);
SMESH_CATCH( SMESH::throwCorbaException );
}
//================================================================================
/*!
* \brief Return nb of nodes

View File

@ -277,6 +277,8 @@ public:
CORBA::Double GetComputeProgress();
void SetAlgoIterator( CORBA::LongLong ptAlgoPy);
SMESH::smIdType NbNodes();
SMESH::smIdType NbElements();

View File

@ -20,6 +20,8 @@
# Author : Francis KLOSS, OCC
# Module : SMESH
import ctypes
import salome
from salome.geom import geomBuilder
@ -8082,6 +8084,21 @@ class ParallelMesh(Mesh):
param2d = algo2d.Parameters()
copy_param(2, param2d, hyp)
def setAlgoIterator(self, it):
"""
doc : to do
"""
print(id(it))
print(hex(id(it)))
ctypes.pythonapi.Py_IncRef(ctypes.py_object(it))
self.mesh.SetAlgoIterator(id(it))
#to be continued
parallelMeshIt = it.jsonData
print(parallelMeshIt)
pass # End of ParallelMesh
class meshProxy(SMESH._objref_SMESH_Mesh):