0027344: Configuration, CMake: bugs with detecting third-party products
[occt.git] / samples / qt / AndroidQt / AndroidQt.h
1 // Copyright (c) 2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef ANDROIDQT_H
15 #define ANDROIDQT_H
16
17 #include <OpenGl_Context.hxx>
18
19 // workaround broken definitions in Qt
20 #define GLdouble GLdouble
21
22 #include <QtQuick/qquickwindow.h>
23 #include <QtQuick/QQuickItem>
24
25 #undef GLdouble
26
27 #include <AIS_InteractiveContext.hxx>
28 #include <V3d_View.hxx>
29
30 #include <QMutex>
31
32 #include <AndroidQt_TouchParameters.h>
33
34 //! QML item with embedded OCCT viewer.
35 class AndroidQt : public QQuickItem
36 {
37   Q_OBJECT
38
39 public:
40   //! Default constructor.
41   AndroidQt();
42
43   //! Display shape from file.
44   Q_INVOKABLE bool ReadShapeFromFile (QString theFilePath);
45
46   //! Handle touch event.
47   Q_INVOKABLE void InitTouch   (const double theX,
48                                 const double theY);
49   
50   //! Handle touch event.
51   Q_INVOKABLE void UpdateTouch (const double theX,
52                                 const double theY);
53
54 public slots:
55
56   //! Handle OpenGL context creation and window resize events.
57   void sync();
58   
59   //! Redraw OCCT viewer and handle pending viewer events in rendering thread.
60   void paint();
61
62 private slots:
63
64   //! Handle window change event.
65   void handleWindowChanged (QQuickWindow* theWin);
66
67 private:
68
69   //! (Re-)initialize viewer on OpenGL context change.
70   bool initViewer();
71
72   //! Close viewer
73   void release();
74
75 private:
76
77   Handle(V3d_Viewer)             myViewer;       //!< 3D viewer
78   Handle(V3d_View)               myView;         //!< 3D view
79   Handle(AIS_InteractiveContext) myContext;      //!< interactive context
80
81   QMutex                         myMutex;        //!< mutex for interconnection with rendering thread
82   QSize                          myViewportSize; //!< QML item size
83   AndroidQt_TouchParameters      myTouchPoint;   //!< cached state of touch event
84   bool                           myFitAllAction; //!< queued viewer FitALL event
85
86 };
87
88 #endif // ANDROIDQT_H