0031620: Samples - update Android JNI sample to use AIS_ViewController
[occt.git] / samples / java / jniviewer / app / src / main / jni / OcctJni_Viewer.hxx
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 #include <AIS_InteractiveContext.hxx>
15 #include <AIS_ViewController.hxx>
16 #include <TopoDS_Shape.hxx>
17 #include <V3d_Viewer.hxx>
18 #include <V3d_View.hxx>
19
20 class AIS_ViewCube;
21
22 //! Main C++ back-end for activity.
23 class OcctJni_Viewer : public AIS_ViewController
24 {
25
26 public:
27
28   //! Empty constructor
29   OcctJni_Viewer (float theDispDensity);
30
31   //! Initialize the viewer
32   bool init();
33
34   //! Release the viewer
35   void release();
36
37   //! Resize the viewer
38   void resize (int theWidth,
39                int theHeight);
40
41   //! Open CAD file
42   bool open (const TCollection_AsciiString& thePath);
43
44   //! Take snapshot
45   bool saveSnapshot (const TCollection_AsciiString& thePath,
46                      int theWidth  = 0,
47                      int theHeight = 0);
48
49   //! Viewer update.
50   //! Returns TRUE if more frames should be requested.
51   bool redraw();
52
53   //! Move camera
54   void setProj (V3d_TypeOfOrientation theProj)
55   {
56     if (myView.IsNull())
57     {
58       return;
59     }
60
61     myView->SetProj (theProj);
62     myView->Invalidate();
63   }
64
65   //! Fit All.
66   void fitAll();
67
68 protected:
69
70   //! Reset viewer content.
71   void initContent();
72
73   //! Print information about OpenGL ES context.
74   void dumpGlInfo (bool theIsBasic);
75
76   //! Handle redraw.
77   virtual void handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx,
78                                  const Handle(V3d_View)& theView) override;
79
80 protected:
81
82   Handle(V3d_Viewer)             myViewer;
83   Handle(V3d_View)               myView;
84   Handle(AIS_InteractiveContext) myContext;
85   Handle(Prs3d_TextAspect)       myTextStyle; //!< text style for OSD elements
86   Handle(AIS_ViewCube)           myViewCube;  //!< view cube object
87   TopoDS_Shape                   myShape;
88   float                          myDevicePixelRatio; //!< device pixel ratio for handling high DPI displays
89   bool                           myIsJniMoreFrames; //!< need more frame flag
90
91 };