GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Backend.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2017 Michael Goffioul
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <cstdint>
28 
29 #include <QApplication>
30 #include <QThread>
31 
32 #include "Backend.h"
33 #include "Logger.h"
34 #include "Object.h"
35 #include "ObjectFactory.h"
36 #include "ObjectProxy.h"
37 
38 //#if INTPTR_MAX == INT32_MAX
39 //# define OCTAVE_PTR_TYPE octave_uint32
40 //# define OCTAVE_INTPTR_TYPE uint32_t
41 //# define OCTAVE_PTR_SCALAR uint32_scalar_value
42 //#else
43 # define OCTAVE_PTR_TYPE octave_uint64
44 # define OCTAVE_INTPTR_TYPE uint64_t
45 # define OCTAVE_PTR_SCALAR uint64_scalar_value
46 //#endif
47 
48 namespace QtHandles
49 {
50 
51  static std::string
53  {
54  if (go.isa ("figure"))
55  return std::string ("__plot_stream__");
56  else if (go.isa ("uicontrol")
57  || go.isa ("uipanel")
58  || go.isa ("uibuttongroup")
59  || go.isa ("uimenu")
60  || go.isa ("uicontextmenu")
61  || go.isa ("uitoolbar")
62  || go.isa ("uipushtool")
63  || go.isa ("uitoggletool"))
64  return std::string ("__object__");
65  else
66  qCritical ("QtHandles::Backend: no __object__ property known for object "
67  "of type %s", go.type ().c_str ());
68 
69  return "";
70  }
71 
73  : QObject (), base_graphics_toolkit ("qt")
74  {
76 
77  connect (this, SIGNAL (createObject (double)),
78  factory, SLOT (createObject (double)));
79  }
80 
82  { }
83 
84  bool
86  {
87  if (go.isa ("figure")
88  || go.isa ("uicontrol")
89  || go.isa ("uipanel")
90  || go.isa ("uibuttongroup")
91  || go.isa ("uimenu")
92  || go.isa ("uicontextmenu")
93  || go.isa ("uitoolbar")
94  || go.isa ("uipushtool")
95  || go.isa ("uitoggletool"))
96  {
97  Logger::debug ("Backend::initialize %s from thread %08x",
98  go.type ().c_str (), QThread::currentThreadId ());
99 
100  ObjectProxy* proxy = new ObjectProxy ();
101  graphics_object gObj (go);
102 
103  OCTAVE_PTR_TYPE tmp (reinterpret_cast<OCTAVE_INTPTR_TYPE> (proxy));
104  gObj.get_properties ().set(toolkitObjectProperty (go), tmp);
105 
106  emit createObject (go.get_handle ().value ());
107 
108  return true;
109  }
110 
111  return false;
112  }
113 
114  void
115  Backend::update (const graphics_object& go, int pId)
116  {
117  // Rule out obvious properties we want to ignore.
128  return;
129 
130  Logger::debug ("Backend::update %s(%d) from thread %08x",
131  go.type ().c_str (), pId, QThread::currentThreadId ());
132 
133  ObjectProxy* proxy = toolkitObjectProxy (go);
134 
135  if (proxy)
136  {
137  if (go.isa ("uicontrol")
139  {
140  // Special case: we need to recreate the control widget
141  // associated with the octave graphics_object
142 
143  finalize (go);
144  initialize (go);
145  }
146  else
147  proxy->update (pId);
148  }
149  }
150 
151  void
153  {
154  Logger::debug ("Backend::finalize %s from thread %08x",
155  go.type ().c_str (), QThread::currentThreadId ());
156 
157  ObjectProxy* proxy = toolkitObjectProxy (go);
158 
159  if (proxy)
160  {
161  proxy->finalize ();
162  delete proxy;
163 
164  graphics_object gObj (go);
165 
166  gObj.get_properties ().set (toolkitObjectProperty (go), Matrix ());
167  }
168  }
169 
170  void
172  {
173  if (go.get_properties ().is_visible ())
174  {
175  ObjectProxy* proxy = toolkitObjectProxy (go);
176 
177  if (proxy)
178  proxy->redraw ();
179  }
180  }
181 
182  void
184  const std::string& term,
185  const std::string& file_cmd,
186  const std::string& /*debug_file*/) const
187  {
188  if (go.get_properties ().is_visible ())
189  {
190  ObjectProxy* proxy = toolkitObjectProxy (go);
191 
192  if (proxy)
193  proxy->print (QString::fromStdString (file_cmd),
194  QString::fromStdString (term));
195  }
196  }
197 
198  Object*
200  {
201  ObjectProxy* proxy = toolkitObjectProxy (go);
202 
203  if (proxy)
204  return proxy->object ();
205 
206  return 0;
207  }
208 
209  ObjectProxy*
211  {
212  if (go)
213  {
214  octave_value ov = go.get (toolkitObjectProperty (go));
215 
216  if (ov.is_defined () && ! ov.is_empty ())
217  {
218  OCTAVE_INTPTR_TYPE ptr = ov.OCTAVE_PTR_SCALAR ().value ();
219 
220  return reinterpret_cast<ObjectProxy*> (ptr);
221  }
222  }
223 
224  return 0;
225  }
226 
227 };
#define OCTAVE_PTR_TYPE
Definition: Backend.cc:43
void update(const graphics_object &obj, int pId)
Definition: Backend.cc:115
bool is_visible(void) const
Definition: graphics.h:2704
bool initialize(const graphics_object &obj)
Definition: Backend.cc:85
bool isa(const std::string &go_name) const
Definition: graphics.h:3286
void print_figure(const graphics_object &go, const std::string &term, const std::string &file_cmd, const std::string &) const
Definition: Backend.cc:183
bool is_defined(void) const
Definition: ov.h:536
QString fromStdString(const std::string &s)
octave_value get(bool all=false) const
Definition: graphics.h:3211
Object * object(void)
Definition: ObjectProxy.h:47
void redraw_figure(const graphics_object &h) const
Definition: Backend.cc:171
void createObject(double handle)
Definition: moc-Backend.cc:100
static ObjectFactory * instance(void)
double value(void) const
Definition: oct-handle.h:74
static void debug(const char *fmt,...)
Definition: Logger.cc:75
#define OCTAVE_INTPTR_TYPE
Definition: Backend.cc:44
double tmp
Definition: data.cc:6300
static ObjectProxy * toolkitObjectProxy(const graphics_object &go)
Definition: Backend.cc:210
base_properties & get_properties(void)
Definition: graphics.h:3288
static std::string toolkitObjectProperty(const graphics_object &go)
Definition: Backend.cc:52
Definition: dMatrix.h:37
std::string type(void) const
Definition: graphics.h:3308
bool is_empty(void) const
Definition: ov.h:542
static Object * toolkitObject(const graphics_object &go)
Definition: Backend.cc:199
graphics_handle get_handle(void) const
Definition: graphics.h:3274
virtual void set(const caseless_str &, const octave_value &)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
void finalize(const graphics_object &obj)
Definition: Backend.cc:152
void print(const QString &file_cmd, const QString &term)
Definition: ObjectProxy.cc:107