1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0029571: Samples: build qt samples together with OCCT

Extending CMake procedure by 'BUILD_MODULE_QtSamples' variable to switch on qt samples build.
Implementation required:
- union of occt_toolkit_tool.cmake and occt_toolkit.cmake files;
- correction of qt samples sources by adding path to Qt 'plugins' folder. It helps to avoid definition of additional variable (QT_QPA_PLATFORM_PLUGIN_PATH) when staring sample.bat for qt samples;
- executable processing is extended in cmake procedure by providing 'EXECUTABLE_PROJECT' variable. Now we need not specify custom processing for DRAWEXE in occt_toolkit.cmake
This commit is contained in:
nds
2018-03-18 15:34:17 +03:00
committed by bugmaster
parent 7f3408c8c8
commit 1fa1615244
82 changed files with 672 additions and 485 deletions

View File

@@ -0,0 +1,291 @@
// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <AndroidQt_Window.h>
#include <AndroidQt.h>
#include <AndroidQt_UserInteractionParameters.h>
#include <AIS_Shape.hxx>
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <Quantity_Color.hxx>
#include <Standard_ErrorHandler.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <UnitsAPI.hxx>
#include <EGL/egl.h>
#include <QFileInfo>
// =======================================================================
// function : AndroidQt
// purpose :
// =======================================================================
AndroidQt::AndroidQt()
: myFitAllAction (false)
{
connect (this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
// set shaders location variable
QByteArray aDataRoot = "/data/data/org.qtproject.example.AndroidQt/files/opencascade/shared";
qputenv ("CSF_ShadersDirectory", aDataRoot + "/Shaders");
}
// =======================================================================
// function : ReadShapeFromFile
// purpose :
// =======================================================================
bool AndroidQt::ReadShapeFromFile (QString theFilePath)
{
QUrl aFileUrl (theFilePath);
QString aFilePath = theFilePath;
if (aFileUrl.isLocalFile())
{
aFilePath = QUrl (theFilePath).toLocalFile();
}
if (!QFile (aFilePath).exists())
{
return false;
}
TopoDS_Shape aShape;
BRep_Builder aBuildTool;
try
{
OCC_CATCH_SIGNALS
if (!BRepTools::Read (aShape, aFilePath.toStdString().c_str(), aBuildTool))
{
return false;
}
if (!myContext.IsNull())
{
myContext->EraseAll (Standard_False);
Handle(AIS_Shape) aShapePrs = new AIS_Shape (aShape);
aShapePrs->SetColor (Quantity_Color(1.0, 0.73, 0.2, Quantity_TOC_RGB));
myContext->Display (aShapePrs, Standard_False);
myContext->SetDisplayMode (aShapePrs, AIS_Shaded, Standard_False);
}
myMutex.lock();
myFitAllAction = true;
myMutex.unlock();
if (window())
{
window()->update();
}
}
catch (Standard_Failure)
{
return false;
}
return true;
}
// =======================================================================
// function : InitTouch
// purpose :
// =======================================================================
void AndroidQt::InitTouch (const double theX,
const double theY)
{
myMutex.lock();
myTouchPoint.SetStarts (theX, theY);
myMutex.unlock();
}
// =======================================================================
// function : UpdateTouch
// purpose :
// =======================================================================
void AndroidQt::UpdateTouch (const double theX,
const double theY)
{
myMutex.lock();
myTouchPoint.SetEnds (theX, theY);
myMutex.unlock();
if (window())
window()->update();
}
// =======================================================================
// function : handleWindowChanged
// purpose :
// =======================================================================
void AndroidQt::handleWindowChanged (QQuickWindow* theWin)
{
if (theWin == NULL)
{
return;
}
connect(theWin, SIGNAL(beforeSynchronizing()), this, SLOT(sync()), Qt::DirectConnection);
theWin->setClearBeforeRendering (false);
}
// =======================================================================
// function : sync
// purpose :
// =======================================================================
void AndroidQt::sync()
{
myViewportSize = window()->size() * window()->devicePixelRatio();
if (myViewer.IsNull())
{
initViewer();
connect (window(), SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection);
}
else
{
Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (myViewer->Driver());
if (aDriver->getRawGlContext() != eglGetCurrentContext())
{
initViewer();
}
else
{
Handle(AndroidQt_Window) aWindow = Handle(AndroidQt_Window)::DownCast (myView->Window());
aWindow->SetSize (myViewportSize.width(), myViewportSize.height());
//myView->MustBeResized(); // can be used instead of SetWindow() when EGLsurface has not been changed
EGLContext anEglContext = eglGetCurrentContext();
myView->SetWindow (aWindow, (Aspect_RenderingContext )anEglContext);
}
}
}
// =======================================================================
// function : paint
// purpose :
// =======================================================================
void AndroidQt::paint()
{
myMutex.lock();
if (Abs(myTouchPoint.DevX()) + Abs(myTouchPoint.DevY()) > 1)
{
myView->StartRotation (myTouchPoint.X().first, myTouchPoint.Y().first);
myView->Rotation (myTouchPoint.X().second, myTouchPoint.Y().second);
myTouchPoint.ClearDev();
}
if (myFitAllAction)
{
myView->FitAll();
myFitAllAction = false;
}
myMutex.unlock();
myView->Redraw();
}
// =======================================================================
// function : initViewer
// purpose :
// =======================================================================
bool AndroidQt::initViewer()
{
EGLint aCfgId = 0;
int aWidth = 0, aHeight = 0;
EGLDisplay anEglDisplay = eglGetCurrentDisplay();
EGLContext anEglContext = eglGetCurrentContext();
EGLSurface anEglSurf = eglGetCurrentSurface (EGL_DRAW);
if (anEglDisplay == EGL_NO_DISPLAY
|| anEglContext == EGL_NO_CONTEXT
|| anEglSurf == EGL_NO_SURFACE)
{
release();
return false;
}
eglQuerySurface (anEglDisplay, anEglSurf, EGL_WIDTH, &aWidth);
eglQuerySurface (anEglDisplay, anEglSurf, EGL_HEIGHT, &aHeight);
eglQuerySurface (anEglDisplay, anEglSurf, EGL_CONFIG_ID, &aCfgId);
const EGLint aConfigAttribs[] = { EGL_CONFIG_ID, aCfgId, EGL_NONE };
EGLint aNbConfigs = 0;
void* anEglConfig = NULL;
if (eglChooseConfig (anEglDisplay, aConfigAttribs, &anEglConfig, 1, &aNbConfigs) != EGL_TRUE)
{
release();
return false;
}
if (!myViewer.IsNull())
{
Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (myViewer->Driver());
Handle(AndroidQt_Window) aWindow = Handle(AndroidQt_Window)::DownCast (myView->Window());
if (!aDriver->InitEglContext (anEglDisplay, anEglContext, anEglConfig))
{
release();
return false;
}
aWindow->SetSize (aWidth, aHeight);
myView->SetWindow (aWindow, (Aspect_RenderingContext )anEglContext);
}
Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver (NULL, Standard_False);
aDriver->ChangeOptions().buffersNoSwap = Standard_True;
//aDriver->ChangeOptions().glslWarnings = Standard_True; // for GLSL shaders debug
if (!aDriver->InitEglContext (anEglDisplay, anEglContext, anEglConfig))
{
release();
return false;
}
// create viewer
myViewer = new V3d_Viewer (aDriver);
myViewer->SetDefaultBackgroundColor (AndroidQt_UserInteractionParameters::BgColor.Name());
myViewer->SetDefaultLights();
myViewer->SetLightOn();
// create AIS context
myContext = new AIS_InteractiveContext (myViewer);
myContext->SetDisplayMode (AIS_Shaded, false);
Handle(AndroidQt_Window) aWindow = new AndroidQt_Window (aWidth, aHeight);
myView = myViewer->CreateView();
myView->SetWindow (aWindow, (Aspect_RenderingContext )anEglContext);
myView->TriedronDisplay (Aspect_TOTP_RIGHT_LOWER, Quantity_NOC_WHITE, 0.08, V3d_ZBUFFER);
return true;
}
// =======================================================================
// function : release
// purpose :
// =======================================================================
void AndroidQt::release()
{
myContext.Nullify();
myView.Nullify();
myViewer.Nullify();
}

View File

@@ -0,0 +1,88 @@
// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef ANDROIDQT_H
#define ANDROIDQT_H
#include <OpenGl_Context.hxx>
// workaround broken definitions in Qt
#define GLdouble GLdouble
#include <QtQuick/qquickwindow.h>
#include <QtQuick/QQuickItem>
#undef GLdouble
#include <AIS_InteractiveContext.hxx>
#include <V3d_View.hxx>
#include <QMutex>
#include <AndroidQt_TouchParameters.h>
//! QML item with embedded OCCT viewer.
class AndroidQt : public QQuickItem
{
Q_OBJECT
public:
//! Default constructor.
AndroidQt();
//! Display shape from file.
Q_INVOKABLE bool ReadShapeFromFile (QString theFilePath);
//! Handle touch event.
Q_INVOKABLE void InitTouch (const double theX,
const double theY);
//! Handle touch event.
Q_INVOKABLE void UpdateTouch (const double theX,
const double theY);
public slots:
//! Handle OpenGL context creation and window resize events.
void sync();
//! Redraw OCCT viewer and handle pending viewer events in rendering thread.
void paint();
private slots:
//! Handle window change event.
void handleWindowChanged (QQuickWindow* theWin);
private:
//! (Re-)initialize viewer on OpenGL context change.
bool initViewer();
//! Close viewer
void release();
private:
Handle(V3d_Viewer) myViewer; //!< 3D viewer
Handle(V3d_View) myView; //!< 3D view
Handle(AIS_InteractiveContext) myContext; //!< interactive context
QMutex myMutex; //!< mutex for interconnection with rendering thread
QSize myViewportSize; //!< QML item size
AndroidQt_TouchParameters myTouchPoint; //!< cached state of touch event
bool myFitAllAction; //!< queued viewer FitALL event
};
#endif // ANDROIDQT_H

View File

@@ -0,0 +1,8 @@
<RCC>
<qresource prefix="/">
<file alias="main.qml">../res/qml/main.qml</file>
</qresource>
<qresource prefix="/">
<file alias="ic_action_collection.png">../res/icons/ic_action_collection.png</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,107 @@
// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <AndroidQt_TouchParameters.h>
// =======================================================================
// function : AndroidQt_TouchParameters
// purpose :
// =======================================================================
AndroidQt_TouchParameters::AndroidQt_TouchParameters()
: myXStart (0.0),
myXEnd (0.0),
myYStart (0.0),
myYEnd (0.0)
{
}
// =======================================================================
// function : AndroidQt_TouchParameters
// purpose :
// =======================================================================
AndroidQt_TouchParameters::AndroidQt_TouchParameters (const double theX,
const double theY)
: myXStart (theX),
myXEnd (theX),
myYStart (theY),
myYEnd (theY)
{
}
// =======================================================================
// function : X
// purpose :
// =======================================================================
QPair<double, double> AndroidQt_TouchParameters::X() const
{
return qMakePair(myXStart, myXEnd);
}
// =======================================================================
// function : DevX
// purpose :
// =======================================================================
double AndroidQt_TouchParameters::DevX() const
{
return myXEnd - myXStart;
}
// =======================================================================
// function : Y
// purpose :
// =======================================================================
QPair<double, double> AndroidQt_TouchParameters::Y() const
{
return qMakePair(myYStart, myYEnd);
}
// =======================================================================
// function : DevY
// purpose :
// =======================================================================
double AndroidQt_TouchParameters::DevY() const
{
return myYEnd - myYStart;
}
// =======================================================================
// function : SetStarts
// purpose :
// =======================================================================
void AndroidQt_TouchParameters::SetStarts (const double theXStart,
const double theYStart)
{
myXStart = theXStart;
myYStart = theYStart;
}
// =======================================================================
// function : SetEnds
// purpose :
// =======================================================================
void AndroidQt_TouchParameters::SetEnds (const double theXEnd,
const double theYEnd)
{
myXEnd = theXEnd;
myYEnd = theYEnd;
}
// =======================================================================
// function : ClearDev
// purpose :
// =======================================================================
void AndroidQt_TouchParameters::ClearDev()
{
myXStart = myXEnd;
myYStart = myYEnd;
}

View File

@@ -0,0 +1,60 @@
// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef ANDROIDQT_TOUCHPARAMETERS_H
#define ANDROIDQT_TOUCHPARAMETERS_H
#include <QPair>
//! Class holding touch event state.
class AndroidQt_TouchParameters
{
public:
//! Empty constructor.
AndroidQt_TouchParameters();
//! Default constructor.
AndroidQt_TouchParameters (const double theX,
const double theY);
//! x coord
QPair<double, double> X() const;
double DevX() const;
//! y coord
QPair<double, double> Y() const;
double DevY() const;
//! Start coords
void SetStarts (const double theXStart,
const double theYStart);
//! End coords
void SetEnds (const double theXEnd,
const double theYEnd);
void ClearDev();
private:
double myXStart;
double myXEnd;
double myYStart;
double myYEnd;
};
#endif // ANDROIDQT_TOUCHPARAMETERS_H

View File

@@ -0,0 +1,28 @@
// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef ANDROIDQT_USERINTERACTIONPARAMETERS_H
#define ANDROIDQT_USERINTERACTIONPARAMETERS_H
#include <Quantity_Color.hxx>
namespace AndroidQt_UserInteractionParameters
{
const double RotationThreshold = 2; // [pixel]
const double PanThreshold = 4; // [pixel]
const double ZoomThreshold = 6; // [pixel]
const double ZoomRatio = 0.13; // distance ratio
const Quantity_Color BgColor = Quantity_Color(0.145, 0.145, 0.145, Quantity_TOC_RGB); // color of viewer's background
}
#endif // USERINTERACTIONPARAMETERS_H

View File

@@ -0,0 +1,86 @@
// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <AndroidQt_Window.h>
IMPLEMENT_STANDARD_RTTIEXT(AndroidQt_Window, Aspect_Window)
// =======================================================================
// function : AndroidQt_Window
// purpose :
// =======================================================================
AndroidQt_Window::AndroidQt_Window (const int theWidth, const int theHeight,
const int theX1, const int theX2,
const int theY1, const int theY2)
: myWidth (theWidth), myHeight(theHeight),
myX1 (theX1), myX2 (theX2),
myY1 (theY1), myY2 (theY2)
{
if (myX1 == -1) myX1 = 0;
if (myX2 == -1) myX2 = myWidth;
if (myY1 == -1) myY1 = 0;
if (myY2 == -1) myY2 = myHeight;
}
// =======================================================================
// function : Position
// purpose :
// =======================================================================
void AndroidQt_Window::Position (Standard_Integer& theX1,
Standard_Integer& theY1,
Standard_Integer& theX2,
Standard_Integer& theY2) const
{
theX1 = myX1;
theX2 = myX2;
theY1 = myY1;
theY2 = myY2;
}
// =======================================================================
// function : SetPosition
// purpose :
// =======================================================================
void AndroidQt_Window::SetPosition (const Standard_Integer theX1,
const Standard_Integer theY1,
const Standard_Integer theX2,
const Standard_Integer theY2)
{
myX1 = theX1;
myX2 = theX2;
myY1 = theY1;
myY2 = theY2;
}
// =======================================================================
// function : Size
// purpose :
// =======================================================================
void AndroidQt_Window::Size (Standard_Integer& theWidth,
Standard_Integer& theHeight) const
{
theWidth = myWidth;
theHeight = myHeight;
}
// =======================================================================
// function : SetSize
// purpose :
// =======================================================================
void AndroidQt_Window::SetSize (const Standard_Integer theWidth,
const Standard_Integer theHeight)
{
myWidth = theWidth;
myHeight = theHeight;
}

View File

@@ -0,0 +1,90 @@
// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef ANDROIDQT_WINDOW_H
#define ANDROIDQT_WINDOW_H
#include <Aspect_Window.hxx>
//! This class defines dummy window.
//! The main functionality is viewport dimensions.
class AndroidQt_Window : public Aspect_Window
{
DEFINE_STANDARD_RTTIEXT(AndroidQt_Window, Aspect_Window)
public:
//! Creates a wrapper over existing Window handle
AndroidQt_Window(const int theWidth, const int theHeight,
const int theX1 = -1, const int theX2 = -1,
const int theY1 = -1, const int theY2 = -1);
//! Returns native Window handle
virtual Aspect_Drawable NativeHandle() const { return 0; }
//! Returns parent of native Window handle.
virtual Aspect_Drawable NativeParentHandle() const { return 0; }
//! Returns native Window FB config (GLXFBConfig on Xlib)
virtual Aspect_FBConfig NativeFBConfig() const { return 0; }
//! Opens the window <me>
virtual void Map() const {}
//! Closes the window <me>
virtual void Unmap() const {}
//! Applies the resizing to the window <me>
virtual Aspect_TypeOfResize DoResize() const { return Aspect_TOR_UNKNOWN; }
//! Apply the mapping change to the window <me>
virtual Standard_Boolean DoMapping() const { return Standard_True; }
//! Returns True if the window <me> is opened
virtual Standard_Boolean IsMapped() const { return Standard_True; }
//! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions
virtual Standard_Real Ratio() const { return 1.0; }
//! Returns The Window POSITION in PIXEL
virtual void Position (Standard_Integer& theX1,
Standard_Integer& theY1,
Standard_Integer& theX2,
Standard_Integer& theY2) const;
//! Set The Window POSITION in PIXEL
virtual void SetPosition (const Standard_Integer theX1,
const Standard_Integer theY1,
const Standard_Integer theX2,
const Standard_Integer theY2);
//! Returns The Window SIZE in PIXEL
virtual void Size (Standard_Integer& theWidth,
Standard_Integer& theHeight) const;
//! Set The Window SIZE in PIXEL
virtual void SetSize (const Standard_Integer theWidth,
const Standard_Integer theHeight);
private:
int myWidth;
int myHeight;
int myX1;
int myX2;
int myY1;
int myY2;
};
#endif // ANDROIDQT_WINDOW_H

View File

@@ -0,0 +1,9 @@
AndroidQt.cxx
AndroidQt.h
AndroidQt.qrc
AndroidQt_TouchParameters.cxx
AndroidQt_TouchParameters.h
AndroidQt_UserInteractionParameters.h
AndroidQt_Window.cxx
AndroidQt_Window.h
Main.cxx

View File

@@ -0,0 +1,29 @@
// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <QApplication>
#include <QQmlApplicationEngine>
#include <AndroidQt.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
qmlRegisterType<AndroidQt>("AndroidQt", 1, 0, "AndroidQt");
QQmlApplicationEngine engine;
engine.load (QUrl (QStringLiteral ("qrc:/main.qml")));
return app.exec();
}