GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Backend.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://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 "__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 "__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));
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.
118  if (pId == figure::properties::ID___PLOT_STREAM__
119  || pId == uicontrol::properties::ID___OBJECT__
120  || pId == uipanel::properties::ID___OBJECT__
121  || pId == uibuttongroup::properties::ID___OBJECT__
122  || pId == uimenu::properties::ID___OBJECT__
123  || pId == uicontextmenu::properties::ID___OBJECT__
124  || pId == uitoolbar::properties::ID___OBJECT__
125  || pId == uipushtool::properties::ID___OBJECT__
126  || pId == uitoggletool::properties::ID___OBJECT__
127  || pId == base_properties::ID___MODIFIED__)
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")
138  && pId == uicontrol::properties::ID_STYLE)
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  ObjectProxy *proxy = toolkitObjectProxy (go);
189 
190  if (proxy)
191  proxy->print (QString::fromStdString (file_cmd),
192  QString::fromStdString (term));
193  }
194 
197  {
199 
200  if (go.isa ("figure"))
201  {
202  ObjectProxy *proxy = toolkitObjectProxy (go);
203 
204  if (proxy)
205  retval = proxy->get_pixels ();
206  }
207 
208  return retval;
209  }
210 
211  Object*
213  {
214  ObjectProxy *proxy = toolkitObjectProxy (go);
215 
216  if (proxy)
217  return proxy->object ();
218 
219  return nullptr;
220  }
221 
222  ObjectProxy*
224  {
225  if (go)
226  {
227  octave_value ov = go.get (toolkitObjectProperty (go));
228 
229  if (ov.is_defined () && ! ov.isempty ())
230  {
231  OCTAVE_INTPTR_TYPE ptr = ov.OCTAVE_PTR_SCALAR ().value ();
232 
233  return reinterpret_cast<ObjectProxy *> (ptr);
234  }
235  }
236 
237  return nullptr;
238  }
239 
240 };
#define OCTAVE_PTR_TYPE
Definition: Backend.cc:43
void update(const graphics_object &obj, int pId)
Definition: Backend.cc:115
bool isempty(void) const
Definition: ov.h:529
virtual void set(const caseless_str &, const octave_value &)
bool initialize(const graphics_object &obj)
Definition: Backend.cc:85
double value(void) const
Definition: oct-handle.h:74
graphics_handle get_handle(void) const
Definition: graphics.in.h:2774
void redraw_figure(const graphics_object &h) const
Definition: Backend.cc:171
QString fromStdString(const std::string &s)
bool is_defined(void) const
Definition: ov.h:523
bool isa(const std::string &go_name) const
Definition: graphics.in.h:2786
void print_figure(const graphics_object &go, const std::string &term, const std::string &file_cmd, const std::string &) const
Definition: Backend.cc:183
Object * object(void)
Definition: ObjectProxy.h:50
void createObject(double handle)
static ObjectFactory * instance(void)
static void debug(const char *fmt,...)
Definition: Logger.cc:75
#define OCTAVE_INTPTR_TYPE
Definition: Backend.cc:44
octave_value get(bool all=false) const
Definition: graphics.in.h:2711
double tmp
Definition: data.cc:6252
octave_value retval
Definition: data.cc:6246
static ObjectProxy * toolkitObjectProxy(const graphics_object &go)
Definition: Backend.cc:223
uint8NDArray get_pixels(const graphics_object &go) const
Definition: Backend.cc:196
base_properties & get_properties(void)
Definition: graphics.in.h:2788
static std::string toolkitObjectProperty(const graphics_object &go)
Definition: Backend.cc:52
Definition: dMatrix.h:36
static Object * toolkitObject(const graphics_object &go)
Definition: Backend.cc:212
uint8NDArray get_pixels(void)
Definition: ObjectProxy.cc:116
std::string type(void) const
Definition: graphics.in.h:2808
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:888
void finalize(const graphics_object &obj)
Definition: Backend.cc:152
void print(const QString &file_cmd, const QString &term)
Definition: ObjectProxy.cc:110