GNU Octave  4.0.0
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-2015 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 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include <QApplication>
28 #include <QThread>
29 
30 #include <stdint.h>
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 ("uimenu")
59  || go.isa ("uicontextmenu")
60  || go.isa ("uitoolbar")
61  || go.isa ("uipushtool")
62  || go.isa ("uitoggletool"))
63  return std::string ("__object__");
64  else
65  qCritical ("QtHandles::Backend: no __object__ property known for object "
66  "of type %s", go.type ().c_str ());
67 
68  return std::string ();
69 }
70 
72  : QObject (), base_graphics_toolkit ("qt")
73 {
75 
76  connect (this, SIGNAL (createObject (double)),
77  factory, SLOT (createObject (double)));
78 }
79 
81 {
82 }
83 
84 bool
86 {
87  if (go.isa ("figure")
88  || go.isa ("uicontrol")
89  || go.isa ("uipanel")
90  || go.isa ("uimenu")
91  || go.isa ("uicontextmenu")
92  || go.isa ("uitoolbar")
93  || go.isa ("uipushtool")
94  || go.isa ("uitoggletool"))
95  {
96  Logger::debug ("Backend::initialize %s from thread %08x",
97  go.type ().c_str (), QThread::currentThreadId ());
98 
99  ObjectProxy* proxy = new ObjectProxy ();
100  graphics_object gObj (go);
101 
102  OCTAVE_PTR_TYPE tmp (reinterpret_cast <OCTAVE_INTPTR_TYPE> (proxy));
103  gObj.get_properties ().set(toolkitObjectProperty (go), tmp);
104 
105  emit createObject (go.get_handle ().value ());
106 
107  return true;
108  }
109 
110  return false;
111 }
112 
113 void
114 Backend::update (const graphics_object& go, int pId)
115 {
116  // Rule out obvious properties we want to ignore.
126  return;
127 
128  Logger::debug ("Backend::update %s(%d) from thread %08x",
129  go.type ().c_str (), pId, QThread::currentThreadId ());
130 
131  ObjectProxy* proxy = toolkitObjectProxy (go);
132 
133  if (proxy)
134  {
135  if (go.isa ("uicontrol")
137  {
138  // Special case: we need to recreate the control widget
139  // associated with the octave graphics_object
140 
141  finalize (go);
142  initialize (go);
143  }
144  else
145  proxy->update (pId);
146  }
147 }
148 
149 void
151 {
152  Logger::debug ("Backend::finalize %s from thread %08x",
153  go.type ().c_str (), QThread::currentThreadId ());
154 
155  ObjectProxy* proxy = toolkitObjectProxy (go);
156 
157  if (proxy)
158  {
159  proxy->finalize ();
160  delete proxy;
161 
162  graphics_object gObj (go);
163 
164  gObj.get_properties ().set (toolkitObjectProperty (go), Matrix ());
165  }
166 }
167 
168 void
170 {
171  if (go.get_properties ().is_visible ())
172  {
173  ObjectProxy* proxy = toolkitObjectProxy (go);
174 
175  if (proxy)
176  proxy->redraw ();
177  }
178 }
179 
180 void
182  const std::string& term,
183  const std::string& file_cmd, bool /*mono*/,
184  const std::string& /*debug_file*/) const
185 {
186  if (go.get_properties ().is_visible ())
187  {
188  ObjectProxy* proxy = toolkitObjectProxy (go);
189 
190  if (proxy)
191  proxy->print (QString::fromStdString (file_cmd),
192  QString::fromStdString (term));
193  }
194 }
195 
196 Object*
198 {
199  ObjectProxy* proxy = toolkitObjectProxy (go);
200 
201  if (proxy)
202  return proxy->object ();
203 
204  return 0;
205 }
206 
209 {
210  if (go)
211  {
212  octave_value ov = go.get (toolkitObjectProperty (go));
213 
214  if (ov.is_defined () && ! ov.is_empty ())
215  {
216  OCTAVE_INTPTR_TYPE ptr = ov.OCTAVE_PTR_SCALAR ().value ();
217 
218  if (! error_state)
219  return reinterpret_cast<ObjectProxy*> (ptr);
220  }
221  }
222 
223  return 0;
224 }
225 
226 };
#define OCTAVE_PTR_TYPE
Definition: Backend.cc:43
void update(const graphics_object &obj, int pId)
Definition: Backend.cc:114
bool is_visible(void) const
Definition: graphics.h:2758
bool initialize(const graphics_object &obj)
Definition: Backend.cc:85
bool isa(const std::string &go_name) const
Definition: graphics.h:3375
bool is_defined(void) const
Definition: ov.h:520
QString fromStdString(const std::string &s)
octave_value get(bool all=false) const
Definition: graphics.h:3300
Object * object(void)
Definition: ObjectProxy.h:47
void redraw_figure(const graphics_object &h) const
Definition: Backend.cc:169
void createObject(double handle)
Definition: moc-Backend.cc:100
static ObjectFactory * instance(void)
double value(void) const
Definition: oct-handle.h:70
static void debug(const char *fmt,...)
Definition: Logger.cc:76
#define OCTAVE_INTPTR_TYPE
Definition: Backend.cc:44
void print_figure(const graphics_object &go, const std::string &term, const std::string &file_cmd, bool, const std::string &) const
Definition: Backend.cc:181
int error_state
Definition: error.cc:101
static ObjectProxy * toolkitObjectProxy(const graphics_object &go)
Definition: Backend.cc:208
base_properties & get_properties(void)
Definition: graphics.h:3377
static std::string toolkitObjectProperty(const graphics_object &go)
Definition: Backend.cc:52
Definition: dMatrix.h:35
std::string type(void) const
Definition: graphics.h:3397
bool is_empty(void) const
Definition: ov.h:526
static Object * toolkitObject(const graphics_object &go)
Definition: Backend.cc:197
graphics_handle get_handle(void) const
Definition: graphics.h:3363
virtual void set(const caseless_str &, const octave_value &)
void finalize(const graphics_object &obj)
Definition: Backend.cc:150
void print(const QString &file_cmd, const QString &term)
Definition: ObjectProxy.cc:106