-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
{ \
PyObject *w; \
int rc; \
- if ( ( w = PyInt_FromLong( i ) ) == NULL ) return; \
+ if ( ( w = PyLong_FromLong( i ) ) == NULL ) return NULL; \
rc = PyDict_SetItemString( aModuleDict, #i, w ); \
Py_DECREF( w ); \
- if ( rc < 0 ) return; \
+ if ( rc < 0 ) return NULL; \
}
//! View operation type
static PyObject* aVTKModule = 0;
PyObject* aPyClass = 0;
if( !aVTKModule ) {
-#if VTK_XVERSION < 30000
- aVTKModule = PyImport_ImportModule( "libVTKGraphicsPython" );
-#elif VTK_XVERSION < 50700
- aVTKModule = PyImport_ImportModule( "vtk.libvtkRenderingPython" );
-#elif VTK_XVERSION < 60000
- aVTKModule = PyImport_ImportModule( "vtkRenderingPython" );
-#else
- aVTKModule = PyImport_ImportModule( "vtkRenderingCorePython" );
-#endif
+ aVTKModule = PyImport_ImportModule( "vtk.vtkRenderingCore" );
if( PyErr_Occurred() ) {
PyErr_Print();
}
\param toCreate window find/create mode
\return VTK window pointer or 0 if it could not be found/created
*/
-static SVTK_ViewWindow* GetVTKViewWindow( int toCreate = __FindOrCreate ) {
+static SVTK_ViewWindow* GetVTKViewWindow( int toCreate = __FindOrCreate, int toKeepDetached = 0 ) {
SVTK_ViewWindow* aVW = 0;
if ( SUIT_Session::session() ) {
// get application
}
}
else {
+ anApp->setProperty("keep_detached", toKeepDetached != 0 );
SVTK_ViewManager* aVM = dynamic_cast<SVTK_ViewManager*>( anApp->getViewManager( "VTKViewer", toCreate == __FindOrCreate ) );
+ anApp->setProperty("keep_detached", QVariant());
if ( aVM ) {
aVW = dynamic_cast<SVTK_ViewWindow*>( aVM->getActiveView() );
// VSR : When new view window is created it can be not active yet at this moment,
typedef PyObject* TResult;
TResult myResult;
int myCreate;
- TGetRendererEvent( bool toCreate )
- : myResult( Py_None ), myCreate( toCreate ) {}
+ int myKeepDetached;
+ TGetRendererEvent( bool toCreate, bool toKeepDetached )
+ : myResult( Py_None ), myCreate( toCreate ), myKeepDetached( toKeepDetached ) {}
virtual void Execute()
{
PyTypeObject* aPyClass = ::GetPyClass( "vtkRenderer" );
SVTK_ViewWindow* aVTKViewWindow =
- ::GetVTKViewWindow( myCreate ? __Create : __FindOrCreate );
+ ::GetVTKViewWindow( myCreate ? __Create : __FindOrCreate, myKeepDetached );
if( aVTKViewWindow && aPyClass ) {
vtkRenderer* aVTKObject = aVTKViewWindow->getRenderer();
-#if VTK_XVERSION < 50700
- myResult = PyVTKObject_New( aPyClass, aVTKObject );
-#else
myResult = PyVTKObject_FromPointer( aPyClass, NULL, aVTKObject );
-#endif
}
}
};
-extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_getRenderer( PyObject* self, PyObject* args )
+extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_getRenderer( PyObject* /*self*/, PyObject* args )
{
PyObject* aResult = Py_None;
int toCreate = 0;
- if ( !PyArg_ParseTuple( args, "|i:getRenderer", &toCreate ) )
+ int toKeepDetached = 0;
+ if ( !PyArg_ParseTuple( args, "|ii:getRenderer", &toCreate, &toKeepDetached ) )
PyErr_Print();
else
- aResult = ProcessEvent( new TGetRendererEvent( toCreate ) );
+ aResult = ProcessEvent( new TGetRendererEvent( toCreate, toKeepDetached ) );
return aResult;
}
typedef PyObject* TResult;
TResult myResult;
int myCreate;
- TGetRenderWindowEvent( bool toCreate )
- : myResult( Py_None ), myCreate( toCreate ) {}
+ int myKeepDetached;
+ TGetRenderWindowEvent( bool toCreate, bool toKeepDetached )
+ : myResult( Py_None ), myCreate( toCreate ), myKeepDetached( toKeepDetached ) {}
virtual void Execute()
{
PyTypeObject* aPyClass = ::GetPyClass( "vtkRenderWindow" );
SVTK_ViewWindow* aVTKViewWindow =
- ::GetVTKViewWindow( myCreate ? __Create : __FindOrCreate );
+ ::GetVTKViewWindow( myCreate ? __Create : __FindOrCreate, myKeepDetached );
if( aVTKViewWindow && aPyClass ) {
vtkRenderWindow* aVTKObject = aVTKViewWindow->getRenderWindow();
-#if VTK_XVERSION < 50700
- myResult = PyVTKObject_New( aPyClass, aVTKObject );
-#else
myResult = PyVTKObject_FromPointer( aPyClass, NULL, aVTKObject );
-#endif
}
}
};
-extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_getRenderWindow( PyObject* self, PyObject* args )
+extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_getRenderWindow( PyObject* /*self*/, PyObject* args )
{
PyObject* aResult = Py_None;
int toCreate = 0;
- if ( !PyArg_ParseTuple( args, "|i:getRenderWindow", &toCreate ) )
+ int toKeepDetached = 0;
+ if ( !PyArg_ParseTuple( args, "|ii:getRenderWindow", &toCreate, &toKeepDetached ) )
PyErr_Print();
else
- aResult = ProcessEvent( new TGetRenderWindowEvent( toCreate ) );
+ aResult = ProcessEvent( new TGetRenderWindowEvent( toCreate, toKeepDetached ) );
return aResult;
}
typedef PyObject* TResult;
TResult myResult;
int myCreate;
- TGetRenderWindowInteractorEvent( bool toCreate )
- : myResult( Py_None ), myCreate( toCreate ) {}
+ int myKeepDetached;
+ TGetRenderWindowInteractorEvent( bool toCreate, bool toKeepDetached )
+ : myResult( Py_None ), myCreate( toCreate ), myKeepDetached( toKeepDetached ) {}
virtual void Execute()
{
PyTypeObject* aPyClass = ::GetPyClass( "vtkRenderWindowInteractor" );
SVTK_ViewWindow* aVTKViewWindow =
- ::GetVTKViewWindow( myCreate ? __Create : __FindOrCreate );
+ ::GetVTKViewWindow( myCreate ? __Create : __FindOrCreate, myKeepDetached );
if( aVTKViewWindow && aPyClass ) {
vtkRenderWindowInteractor* aVTKObject = aVTKViewWindow->getInteractor();
-#if VTK_XVERSION < 50700
- myResult = PyVTKObject_New( aPyClass, aVTKObject );
-#else
myResult = PyVTKObject_FromPointer( aPyClass, NULL, aVTKObject );
-#endif
}
}
};
-extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_getRenderWindowInteractor( PyObject* self, PyObject* args )
+extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_getRenderWindowInteractor( PyObject* /*self*/, PyObject* args )
{
PyObject* aResult = Py_None;
int toCreate = 0;
- if ( !PyArg_ParseTuple( args, "|i:getRenderWindowInteractor", &toCreate ) )
+ int toKeepDetached = 0;
+ if ( !PyArg_ParseTuple( args, "|ii:getRenderWindowInteractor", &toCreate, &toKeepDetached ) )
PyErr_Print();
else
- aResult = ProcessEvent( new TGetRenderWindowInteractorEvent( toCreate ) );
+ aResult = ProcessEvent( new TGetRenderWindowInteractorEvent( toCreate, toKeepDetached ) );
return aResult;
}
\return nothing (Py_None)
*/
-extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_showTrihedron( PyObject* self, PyObject* args )
+extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_showTrihedron( PyObject* /*self*/, PyObject* args )
{
class TEvent: public SALOME_Event
{
virtual void Execute()
{
if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow( __Find ) ) {
- if ( aVTKViewWindow->isTrihedronDisplayed() != myShow )
+ if ( aVTKViewWindow->isTrihedronDisplayed() != (bool)myShow )
aVTKViewWindow->onViewTrihedron(myShow);
}
}
\return nothing (Py_None)
*/
-extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_fitAll( PyObject* self, PyObject* args )
+extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_fitAll( PyObject* /*self*/, PyObject* /*args*/ )
{
class TEvent: public SALOME_Event
{
\return nothing (Py_None)
*/
-extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_setView( PyObject* self, PyObject* args )
+extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_setView( PyObject* /*self*/, PyObject* args )
{
class TEvent: public SALOME_Event
{
\return nothing (Py_None)
*/
-extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_resetView( PyObject* self, PyObject* args )
+extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_resetView( PyObject* /*self*/, PyObject* /*args*/ )
{
class TEvent: public SALOME_Event
{
static PyMethodDef libSalomePy_methods[] =
{
- { "getRenderer", libSalomePy_getRenderer, METH_VARARGS },
- { "getRenderWindow", libSalomePy_getRenderWindow, METH_VARARGS },
- { "getRenderWindowInteractor", libSalomePy_getRenderWindowInteractor, METH_VARARGS },
- { "showTrihedron", libSalomePy_showTrihedron, METH_VARARGS },
- { "fitAll", libSalomePy_fitAll, METH_NOARGS },
- { "setView", libSalomePy_setView, METH_VARARGS },
- { "resetView", libSalomePy_resetView, METH_NOARGS },
- { NULL, NULL }
+ { "getRenderer", libSalomePy_getRenderer, METH_VARARGS, PyDoc_STR("Get renderer from current vtk view") },
+ { "getRenderWindow", libSalomePy_getRenderWindow, METH_VARARGS, PyDoc_STR("Get render window from current vtk view") },
+ { "getRenderWindowInteractor", libSalomePy_getRenderWindowInteractor, METH_VARARGS, PyDoc_STR("Get interactor from current vtk view") },
+ { "showTrihedron", libSalomePy_showTrihedron, METH_VARARGS, PyDoc_STR("Show/hide trihedron in current vtk view") },
+ { "fitAll", libSalomePy_fitAll, METH_NOARGS, PyDoc_STR("Fit current vtk view to show all contents") },
+ { "setView", libSalomePy_setView, METH_VARARGS, PyDoc_STR("Set side view for the current VTK viewer") },
+ { "resetView", libSalomePy_resetView, METH_NOARGS, PyDoc_STR("Reset camera for current vtk view") },
+ { 0, 0, 0, 0 }
};
struct module_state {
\brief Python module initialization.
\internal
*/
-extern "C" SALOMEPY_EXPORT void initlibSalomePy()
+extern "C" SALOMEPY_EXPORT PyMODINIT_FUNC PyInit_libSalomePy(void)
{
// init module
PyObject *aModule = PyModule_Create(&moduledef);
if( PyErr_Occurred() ) {
PyErr_Print();
- return;
+ return NULL;
}
// get module's dictionary
PyObject *aModuleDict = PyModule_GetDict( aModule );
if ( aModuleDict == NULL )
- return;
+ return NULL;
// export View type enumeration
PUBLISH_ENUM( ViewFront );
PUBLISH_ENUM( ViewBottom );
PUBLISH_ENUM( ViewRight );
PUBLISH_ENUM( ViewLeft );
+
+ return aModule;
}