Salome HOME
Merge branch 'rnv/23406'
[modules/gui.git] / src / SALOME_PY / SalomePy.cxx
index c7ec622c751a96e7ec25b54b8b3ca1955182e9d9..d099217b9fbd9616c526886a76074e9febff9210 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -24,7 +24,7 @@
 //  File   : SalomePy.cxx
 //  Author : Paul RASCLE, EDF
 //
-#ifdef WNT
+#ifdef WIN32
 // E.A. : On windows with python 2.6, there is a conflict
 // E.A. : between pymath.h and Standard_math.h which define
 // E.A. : some same symbols : acosh, asinh, ...
   In case of any error these methods return None object to the Python.
 */
 
+#ifdef WIN32
+ #if defined SALOMEPY_EXPORTS || defined SalomePy_EXPORTS
+  #define SALOMEPY_EXPORT __declspec( dllexport )
+ #else
+  #define SALOMEPY_EXPORT __declspec( dllimport )
+ #endif
+#else
+ #define SALOMEPY_EXPORT
+#endif
+
+
 #define PUBLISH_ENUM(i)                              \
 {                                                    \
   PyObject *w;                                       \
@@ -102,7 +113,7 @@ enum {
   \param theClassName Python class name
   \return Python class object or None object if class is not found
 */
-static PyObject* GetPyClass( const char* theClassName ) 
+static PyTypeObject* GetPyClass( const char* theClassName )
 {
   static PyObject* aVTKModule = 0;
   PyObject* aPyClass = 0;
@@ -123,8 +134,10 @@ static PyObject* GetPyClass( const char* theClassName )
   if ( aVTKModule ) {
     PyObject* aVTKDict = PyModule_GetDict( aVTKModule );
     aPyClass = PyDict_GetItemString(aVTKDict, const_cast<char*>( theClassName ) );
+    if (!PyType_Check(aPyClass))
+      return 0;
   }
-  return aPyClass;
+  return (PyTypeObject *)aPyClass;
 }
 
 /*!
@@ -198,7 +211,7 @@ static SVTK_ViewWindow* GetVTKViewWindow( int toCreate = __FindOrCreate ) {
   \return VTK window renderer object
 */
 
-class TGetRendererEvent: public SALOME_Event
+class SALOMEPY_EXPORT TGetRendererEvent: public SALOME_Event
 {
 public:
   typedef PyObject* TResult;
@@ -208,7 +221,7 @@ public:
     : myResult( Py_None ), myCreate( toCreate ) {}
   virtual void Execute()
   {
-    PyObject* aPyClass = ::GetPyClass( "vtkRenderer" );
+    PyTypeObject* aPyClass = ::GetPyClass( "vtkRenderer" );
     SVTK_ViewWindow* aVTKViewWindow = 
       ::GetVTKViewWindow( myCreate ? __Create : __FindOrCreate );
     if( aVTKViewWindow && aPyClass ) {
@@ -216,13 +229,13 @@ public:
 #if VTK_XVERSION < 50700
       myResult = PyVTKObject_New( aPyClass, aVTKObject );
 #else
-      myResult = PyVTKObject_New( aPyClass, NULL, aVTKObject );
+      myResult = PyVTKObject_FromPointer( aPyClass, NULL, aVTKObject );
 #endif
     }
   }
 };
 
-extern "C" 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;
@@ -251,7 +264,7 @@ extern "C" PyObject* libSalomePy_getRenderer( PyObject* self, PyObject* args )
   \return VTK window render window object
 */
 
-class TGetRenderWindowEvent: public SALOME_Event
+class SALOMEPY_EXPORT TGetRenderWindowEvent: public SALOME_Event
 {
 public:
   typedef PyObject* TResult;
@@ -261,7 +274,7 @@ public:
     : myResult( Py_None ), myCreate( toCreate ) {}
   virtual void Execute()
   {
-    PyObject* aPyClass = ::GetPyClass( "vtkRenderWindow" );
+    PyTypeObject* aPyClass = ::GetPyClass( "vtkRenderWindow" );
     SVTK_ViewWindow* aVTKViewWindow = 
       ::GetVTKViewWindow( myCreate ? __Create : __FindOrCreate );
     if( aVTKViewWindow && aPyClass ) {
@@ -269,13 +282,13 @@ public:
 #if VTK_XVERSION < 50700
       myResult = PyVTKObject_New( aPyClass, aVTKObject );
 #else
-      myResult = PyVTKObject_New( aPyClass, NULL, aVTKObject );
+      myResult = PyVTKObject_FromPointer( aPyClass, NULL, aVTKObject );
 #endif
     }
   }
 };
 
-extern "C" 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;
@@ -304,7 +317,7 @@ extern "C" PyObject* libSalomePy_getRenderWindow( PyObject* self, PyObject* args
   \return VTK window render window interactor object
 */
 
-class TGetRenderWindowInteractorEvent: public SALOME_Event
+class SALOMEPY_EXPORT TGetRenderWindowInteractorEvent: public SALOME_Event
 {
 public:
   typedef PyObject* TResult;
@@ -314,7 +327,7 @@ public:
     : myResult( Py_None ), myCreate( toCreate ) {}
   virtual void Execute()
   {
-    PyObject* aPyClass = ::GetPyClass( "vtkRenderWindowInteractor" );
+    PyTypeObject* aPyClass = ::GetPyClass( "vtkRenderWindowInteractor" );
     SVTK_ViewWindow* aVTKViewWindow = 
       ::GetVTKViewWindow( myCreate ? __Create : __FindOrCreate );
     if( aVTKViewWindow && aPyClass ) {
@@ -322,13 +335,13 @@ public:
 #if VTK_XVERSION < 50700
       myResult = PyVTKObject_New( aPyClass, aVTKObject );
 #else
-      myResult = PyVTKObject_New( aPyClass, NULL, aVTKObject );
+      myResult = PyVTKObject_FromPointer( aPyClass, NULL, aVTKObject );
 #endif
     }
   }
 };
 
-extern "C" 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;
@@ -349,7 +362,7 @@ extern "C" PyObject* libSalomePy_getRenderWindowInteractor( PyObject* self, PyOb
   \return nothing (Py_None)
 */
 
-extern "C" PyObject* libSalomePy_showTrihedron( PyObject* self, PyObject* args )
+extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_showTrihedron( PyObject* self, PyObject* args )
 {
   class TEvent: public SALOME_Event
   {
@@ -361,7 +374,7 @@ extern "C" PyObject* libSalomePy_showTrihedron( PyObject* self, PyObject* args )
     {
       if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow( __Find ) ) {
         if ( aVTKViewWindow->isTrihedronDisplayed() != myShow )
-          aVTKViewWindow->onViewTrihedron();
+          aVTKViewWindow->onViewTrihedron(myShow);
       }
     }
   };
@@ -384,7 +397,7 @@ extern "C" PyObject* libSalomePy_showTrihedron( PyObject* self, PyObject* args )
   \return nothing (Py_None)
 */
 
-extern "C" PyObject* libSalomePy_fitAll( PyObject* self, PyObject* args )
+extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_fitAll( PyObject* self, PyObject* args )
 {
   class TEvent: public SALOME_Event
   {
@@ -412,7 +425,7 @@ extern "C" PyObject* libSalomePy_fitAll( PyObject* self, PyObject* args )
   \return nothing (Py_None)
 */
 
-extern "C" PyObject* libSalomePy_setView( PyObject* self, PyObject* args )
+extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_setView( PyObject* self, PyObject* args )
 {
   class TEvent: public SALOME_Event
   {
@@ -436,7 +449,7 @@ extern "C" PyObject* libSalomePy_setView( PyObject* self, PyObject* args )
         case ViewLeft:
           aVTKViewWindow->onLeftView();   break;
         default:
-          PyErr_Format(PyExc_ValueError,"setView%: wrong parameter value; must be between %d and %d", ViewFront, ViewLeft );
+          PyErr_Format(PyExc_ValueError,"setView: wrong parameter value; must be between %d and %d", ViewFront, ViewLeft );
           break;
         }
       }
@@ -463,7 +476,7 @@ extern "C" PyObject* libSalomePy_setView( PyObject* self, PyObject* args )
   \return nothing (Py_None)
 */
 
-extern "C" PyObject* libSalomePy_resetView( PyObject* self, PyObject* args )
+extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_resetView( PyObject* self, PyObject* args )
 {
   class TEvent: public SALOME_Event
   {
@@ -497,7 +510,7 @@ static PyMethodDef Module_Methods[] =
   \brief Python module initialization.
   \internal
 */
-extern "C" void initlibSalomePy()
+extern "C" SALOMEPY_EXPORT void initlibSalomePy()
 {
   static char* modulename = (char*)"libSalomePy";