0023701: Add Cocoa support to Qt samples
authordbv <dbv@opencascade.com>
Fri, 25 Jan 2013 10:41:33 +0000 (14:41 +0400)
committerdbv <dbv@opencascade.com>
Fri, 25 Jan 2013 10:41:33 +0000 (14:41 +0400)
Adapted Qt samples for using Cocoa on Mac OS X

samples/qt/Common/src/View.cxx
samples/qt/IESample/IESample.pro
samples/qt/IESample/make.sh [changed mode: 0644->0755]
samples/qt/IESample/run.sh
samples/qt/Tutorial/Tutorial.pro
samples/qt/Tutorial/make.sh
samples/qt/Tutorial/run.sh

index ce7b137..342c17d 100755 (executable)
 #include <Graphic3d_ExportFormat.hxx>
 #include <QWindowsStyle>
   
-#ifdef WNT
+#if defined(_WIN32) || defined(__WIN32__)
 #include <WNT_Window.hxx>
 #include <Graphic3d_WNTGraphicDevice.hxx>
+#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+#include <Cocoa_Window.hxx>
 #else
 #include <QX11Info>
 #include <GL/glx.h>
@@ -53,7 +55,7 @@ View::View( Handle(AIS_InteractiveContext) theContext, QWidget* parent )
 : QWidget( parent ),
 myViewActions( 0 )
 {
-#ifndef WNT
+#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
   //XSynchronize( x11Display(),true ); // it is possible to use QApplication::syncX();
   XSynchronize( x11Info().display(),true ); // it is possible to use QApplication::syncX();
 #endif
@@ -70,7 +72,7 @@ myViewActions( 0 )
        setAttribute(Qt::WA_PaintOnScreen);
     setAttribute(Qt::WA_NoSystemBackground);
 
-#if !defined WNT
+#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
     XVisualInfo* pVisualInfo;
     if ( x11Info().display() )
     {
@@ -161,22 +163,28 @@ View::~View()
 
 void View::init()
 {
-    if(myView.IsNull())
-    myView = myContext->CurrentViewer()->CreateView();
-    int windowHandle = (int) winId();
-    short hi, lo;
-    lo = (short) windowHandle;
-    hi = (short) (windowHandle >> 16);
-#ifdef WNT
-    Handle(WNT_Window) hWnd = new WNT_Window(Handle(Graphic3d_WNTGraphicDevice)::DownCast(myContext->CurrentViewer()->Device()),(int) hi,(int) lo);
+  if (myView.IsNull())
+  myView = myContext->CurrentViewer()->CreateView();
+#if defined(_WIN32) || defined(__WIN32__)
+  Aspect_Handle aWindowHandle = (Aspect_Handle )winId();
+  Handle(WNT_Window) hWnd = new WNT_Window (Handle(Graphic3d_WNTGraphicDevice)::DownCast (myContext->CurrentViewer()->Device()),
+                                            aWindowHandle);
+#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+  NSView* aViewHandle = (NSView* )winId();
+  Handle(Cocoa_Window) hWnd = new Cocoa_Window (aViewHandle);
 #else
-    Handle(Xw_Window) hWnd = new Xw_Window(Handle(Graphic3d_GraphicDevice)::DownCast(myContext->CurrentViewer()->Device()),(int) hi,(int) lo,Xw_WQ_SAMEQUALITY);
+  Aspect_Handle aWindowHandle = (Aspect_Handle )winId();
+  Handle(Xw_Window) hWnd = new Xw_Window (Handle(Graphic3d_GraphicDevice)::DownCast (myContext->CurrentViewer()->Device()),
+                                          aWindowHandle,
+                                          Xw_WQ_SAMEQUALITY);
 #endif // WNT
-    myView->SetWindow( hWnd );
-    if ( !hWnd->IsMapped() )
-        hWnd->Map();
-    myView->SetBackgroundColor(Quantity_NOC_BLACK);
-    myView->MustBeResized();
+  myView->SetWindow (hWnd);
+  if (!hWnd->IsMapped())
+  {
+    hWnd->Map();
+  }
+  myView->SetBackgroundColor (Quantity_NOC_BLACK);
+  myView->MustBeResized();
 }
 
 void View::paintEvent( QPaintEvent * e )
index f7fb980..3dc34ab 100755 (executable)
@@ -30,9 +30,13 @@ unix {
        OBJECTS_DIR = ./$$UNAME/obj
        MOC_DIR = ./$$UNAME/src
     }
-    INCLUDEPATH += $$QMAKE_INCDIR_X11 $$QMAKE_INCDIR_OPENGL $$QMAKE_INCDIR_THREAD
-    DEFINES += LIN LININTEL OCC_CONVERT_SIGNALS HAVE_CONFIG_H HAVE_WOK_CONFIG_H QT_NO_STL
-    LIBS += -L$$QMAKE_LIBDIR_X11 $$QMAKE_LIBS_X11 -L$$QMAKE_LIBDIR_OPENGL $$QMAKE_LIBS_OPENGL $$QMAKE_LIBS_THREAD
+
+    MACOSX_USE_GLX = $$(MACOSX_USE_GLX)
+
+    !macx | equals(MACOSX_USE_GLX, true): INCLUDEPATH += $$QMAKE_INCDIR_X11 $$QMAKE_INCDIR_OPENGL $$QMAKE_INCDIR_THREAD
+    !macx | equals(MACOSX_USE_GLX, true): DEFINES += LIN LININTEL
+    DEFINES += OCC_CONVERT_SIGNALS HAVE_CONFIG_H HAVE_WOK_CONFIG_H QT_NO_STL
+    !macx | equals(MACOSX_USE_GLX, true): LIBS += -L$$QMAKE_LIBDIR_X11 $$QMAKE_LIBS_X11 -L$$QMAKE_LIBDIR_OPENGL $$QMAKE_LIBS_OPENGL $$QMAKE_LIBS_THREAD
     LIBS += -lfreeimageplus
     LIBS += -ltbb -ltbbmalloc
 }
old mode 100644 (file)
new mode 100755 (executable)
index 7654298..f2af5ab
@@ -4,4 +4,6 @@ export aSamplePath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 if [ -e "${aSamplePath}/env.sh" ]; then source "${aSamplePath}/env.sh"; fi
 cd $aSamplePath
 qmake IESample.pro
-make
+if test `uname -s` != "Darwin"; then
+  make
+fi
index 200b06b..7fec2ea 100755 (executable)
@@ -8,7 +8,17 @@ host=`uname -s`
 STATION=$host
 
 RES_DIR="${aSamplePath}/res"
-BIN_DIR="${aSamplePath}/${STATION}/bin"
+
+aSystem=`uname -s`
+if [ "$aSystem" == "Darwin" ]; then
+  if [ "${CASDEB}" == "d" ]; then
+    BIN_DIR="${aSamplePath}/build/Debug/IESample.app/Contents/MacOS"
+  else
+    BIN_DIR="${aSamplePath}/build/Release/IESample.app/Contents/MacOS"
+  fi
+else
+  BIN_DIR="${aSamplePath}/${STATION}/bin${CASDEB}"
+fi
 
 CSF_ResourcesDefaults="${RES_DIR}"
 CSF_IEResourcesDefaults="${RES_DIR}"
@@ -19,9 +29,13 @@ export CSF_IEResourcesDefaults CSF_ResourcesDefaults
 export PATH
 
 if test ! -r "${BIN_DIR}/IESample"; then
-   echo "Executable \"${BIN_DIR}/IESample\" not found."
-   echo "Probably you don't compile the application. Execute \"make\"."
-   exit 1
+  echo "Executable \"${BIN_DIR}/IESample\" not found."
+  if [ "$aSystem" == "Darwin" ]; then
+    echo "Probably you don't compile the application. Build it with Xcode."
+  else
+    echo "Probably you don't compile the application. Execute \"make\"."
+  fi
+  exit 1
 fi
 
 ${BIN_DIR}/IESample
index 586e2dd..273a330 100755 (executable)
@@ -32,11 +32,15 @@ unix {
        OBJECTS_DIR = ./$$UNAME/obj
        MOC_DIR = ./$$UNAME/src
     }
-    INCLUDEPATH += $$QMAKE_INCDIR_X11 $$QMAKE_INCDIR_OPENGL $$QMAKE_INCDIR_THREAD
-    DEFINES += LIN LININTEL OCC_CONVERT_SIGNALS HAVE_CONFIG_H HAVE_WOK_CONFIG_H
-    LIBS += -L$$QMAKE_LIBDIR_X11 $$QMAKE_LIBS_X11 -L$$QMAKE_LIBDIR_OPENGL $$QMAKE_LIBS_OPENGL $$QMAKE_LIBS_THREAD
-       LIBS += -lfreeimageplus
-       LIBS += -ltbb -ltbbmalloc
+
+    MACOSX_USE_GLX = $$(MACOSX_USE_GLX)
+
+    !macx | equals(MACOSX_USE_GLX, true): INCLUDEPATH += $$QMAKE_INCDIR_X11 $$QMAKE_INCDIR_OPENGL $$QMAKE_INCDIR_THREAD
+    !macx | equals(MACOSX_USE_GLX, true): DEFINES += LIN LININTEL
+    DEFINES += OCC_CONVERT_SIGNALS HAVE_CONFIG_H HAVE_WOK_CONFIG_H QT_NO_STL
+    !macx | equals(MACOSX_USE_GLX, true): LIBS += -L$$QMAKE_LIBDIR_X11 $$QMAKE_LIBS_X11 -L$$QMAKE_LIBDIR_OPENGL $$QMAKE_LIBS_OPENGL $$QMAKE_LIBS_THREAD
+    LIBS += -lfreeimageplus
+    LIBS += -ltbb -ltbbmalloc
 }
 
 win32 {
index 1f7b3ac..2420cf2 100644 (file)
@@ -4,4 +4,6 @@ export aSamplePath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 if [ -e "${aSamplePath}/env.sh" ]; then source "${aSamplePath}/env.sh"; fi
 cd $aSamplePath
 qmake Tutorial.pro
-make
+if test `uname -s` != "Darwin"; then
+  make
+fi
index bd67909..8e440fe 100755 (executable)
@@ -8,7 +8,17 @@ host=`uname -s`
 STATION=$host
 
 RES_DIR="${aSamplePath}/res"
-BIN_DIR="${aSamplePath}/${STATION}/bin"
+
+aSystem=`uname -s`
+if [ "$aSystem" == "Darwin" ]; then
+  if [ "${CASDEB}" == "d" ]; then
+    BIN_DIR="${aSamplePath}/build/Debug/Tutorial.app/Contents/MacOS"
+  else
+    BIN_DIR="${aSamplePath}/build/Release/Tutorial.app/Contents/MacOS"
+  fi
+else
+  BIN_DIR="${aSamplePath}/${STATION}/bin${CASDEB}"
+fi
 
 CSF_ResourcesDefaults="${RES_DIR}"
 CSF_TutorialResourcesDefaults="${RES_DIR}"
@@ -19,9 +29,13 @@ export CSF_TutorialResourcesDefaults CSF_ResourcesDefaults
 export PATH
 
 if test ! -r "${BIN_DIR}/Tutorial"; then
-   echo "Executable \"${BIN_DIR}/Tutorial\" not found."
-   echo "Probably you don't compile the application. Execute \"make\"."
-   exit 1
+  echo "Executable \"${BIN_DIR}/Tutorial\" not found."
+  if [ "$aSystem" == "Darwin" ]; then
+    echo "Probably you don't compile the application. Build it with Xcode."
+  else
+    echo "Probably you don't compile the application. Execute \"make\"."
+  fi
+  exit 1
 fi
 
 ${BIN_DIR}/Tutorial