SMIL  1.1
DGuiInstance.h
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef _D_GUI_INSTANCE_H
31 #define _D_GUI_INSTANCE_H
32 
33 #include "Core/include/private/DInstance.hpp"
34 #include "Core/include/private/DImage.hpp"
35 #include "private/DImageViewer.hpp"
36 
37 #ifdef USE_QT
38 #include "Gui/Qt/DQtImageViewer.hpp"
39 #include "Gui/Qt/DQtImageViewer.hxx"
40 #endif // USE_QT
41 
42 #ifdef USE_AALIB
43 #include "Gui/AALib/DAAImageViewer.hpp"
44 #endif // USE_AALIB
45 
46 namespace smil
47 {
53  template <class T>
54  class ImageViewer;
55 
57  // Need this when Qt is enabled and import smilPython under Jupyter
58  inline bool isGuiDisabled()
59  {
60  // JOE XXX - solve this for windows
61 #if 1
62  char *env = getenv("SMIL_DISABLE_GUI");
63  if (env != nullptr) {
64  return (strcasecmp(env, "yes") == 0 || strcasecmp(env, "true") == 0);
65  }
66  env = getenv("DisableQt");
67  if (env != nullptr) {
68  return (strcasecmp(env, "yes") == 0 || strcasecmp(env, "true") == 0);
69  }
70 #endif
71  return false;
72  }
75  class Gui;
76 
80  class Gui : public UniqueInstance<Gui>
81  {
82  friend class UniqueInstance<Gui>;
83 
84  protected:
85  // disable Qt when running from notebooks or without GUI
86 
87  Gui()
88  {
89  }
90 
91  virtual ~Gui()
92  {
93  }
94 
95  public:
96  // Public interface
97  // static void kill();
98 
99  static RES_T initialize();
103  static void execLoop();
104  static void processEvents();
105  static void showHelp();
106 
110  template <class T>
112 
113  protected:
114  virtual void _execLoop()
115  {
116  }
117  virtual void _processEvents()
118  {
119  }
120  virtual void _showHelp()
121  {
122  }
123 
124  private:
125  };
126 
127  template <class T>
129  {
130 #ifdef USE_QT
131  if (!isGuiDisabled()) {
132  return new QtImageViewer<T>(im);
133  } else {
134  return new ImageViewer<T>(im);
135  }
136 #elif defined USE_AALIB
137  return new AaImageViewer<T>(im);
138 #else
139  return new ImageViewer<T>(im);
140 #endif
141  }
142 
145 } // namespace smil
146 
147 #endif // _D_GUI_INSTANCE_H
AA (Ascii Art) image viewer.
Definition: DAAImageViewer.hpp:56
Gui module instance.
Definition: DGuiInstance.h:81
ImageViewer< T > * createDefaultViewer(Image< T > &im=NULL)
Create a default viewer for type T.
Definition: DGuiInstance.h:128
static void execLoop()
Run the event loop.
Definition: DGuiInstance.cpp:59
Main Image class.
Definition: DImage.hpp:57
Base image viewer.
Definition: DImageViewer.hpp:52
Qt image viewer.
Definition: DQtImageViewer.hpp:75
Definition: DInstance.hpp:40