26 #if defined (HAVE_CONFIG_H)
42 make_handle_fraction ()
44 static double maxrand = RAND_MAX + 2.0;
46 return (
rand () + 1.0) / maxrand;
54 if (integer_figure_handle)
63 while (m_handle_map.find (retval) != m_handle_map.end ())
72 auto p = m_handle_free_list.begin ();
74 if (p != m_handle_free_list.end ())
77 m_handle_free_list.erase (p);
83 m_next_handle =
std::ceil (m_next_handle) - 1.0 - make_handle_fraction ();
96 error (
"graphics_handle::free: can't delete root object");
98 auto p = m_handle_map.find (h);
100 if (p == m_handle_map.end ())
101 error (
"graphics_handle::free: invalid object %g", h.
value ());
116 p->second.remove_all_listeners ();
126 p->second.finalize ();
145 m_handle_map.erase (p);
148 m_handle_free_list.insert
157 auto p = m_handle_map.find (old_gh);
159 if (p == m_handle_map.end ())
160 error (
"graphics_handle::free: invalid object %g", old_gh.
value ());
164 m_handle_map.erase (p);
166 m_handle_map[new_gh] = go;
168 if (old_gh.
value () < 0)
170 - make_handle_fraction ());
172 for (
auto& hfig : m_figure_list)
187 m_event_queue.clear ();
218 if (hlist.
numel () != 0)
219 warning (
"gh_manager::close_all_figures: some graphics elements failed to close");
223 m_callback_objects.clear ();
229 : m_interpreter (interp), m_handle_map (), m_handle_free_list (),
230 m_next_handle (-1.0 - (
rand () + 1.0) / (RAND_MAX + 2.0)),
231 m_figure_list (), m_graphics_lock (), m_event_queue (),
232 m_callback_objects (), m_event_processing (0)
239 gtk_mgr.default_toolkit ();
245 bool integer_figure_handle,
246 bool call_createfcn,
bool notify_toolkit)
253 error (
"gh_manager::make_graphics_handle: invalid object type '%s'",
258 m_handle_map[h] = go;
260 if (go_name ==
"axes")
306 m_handle_map[h] = go;
322 m_figure_list.push_front (h);
328 for (
auto it = m_figure_list.begin (); it != m_figure_list.end (); it++)
332 m_figure_list.erase (it);
354 octave::autolock guard (m_graphics_lock);
356 m_callback_objects.pop_front ();
358 xset_gcbo (m_callback_objects.empty ()
365 if (octave::thread::is_thread ())
369 octave::autolock guard (m_graphics_lock);
392 octave::unwind_action_safe restore_gcbo_action
400 octave::autolock guard (m_graphics_lock);
401 m_callback_objects.push_front (go);
419 m_interpreter.eval_string (s,
false, status, 0);
421 catch (
const octave::execution_exception& ee)
423 m_interpreter.handle_exception (ee);
429 || cb.
cell_value ()(0).is_function_handle ()))
435 for (
int i = 1; i < c.
numel () ; i++)
441 error (
"trying to execute non-executable object (class = %s)",
449 m_interpreter.feval (ov_fcn, args);
451 m_interpreter.feval (fcn, args);
453 catch (
const octave::execution_exception& ee)
455 m_interpreter.handle_exception (ee);
466 if (go_name.length () > 1
467 && go_name[0] ==
'u' && go_name[1] ==
'i')
478 process_graphics_events ()
488 m_event_queue.push_back (e);
490 octave::command_editor::add_event_hook (process_graphics_events);
497 octave::autolock guard (m_graphics_lock);
506 if (cname ==
"deletefcn" || cname ==
"createfcn"
507 || cname ==
"closerequestfcn"
508 || ((go.
isa (
"figure") || go.
isa (
"uipanel")
509 || go.
isa (
"uibuttongroup"))
510 && (cname ==
"resizefcn" || cname ==
"sizechangedfcn")))
517 if (cname ==
"closerequestfcn")
519 std::string cmd (
"close (gcbf ());");
531 octave::autolock guard (m_graphics_lock);
541 octave::autolock guard (m_graphics_lock);
552 bool events_executed =
false;
559 octave::autolock guard (m_graphics_lock);
561 if (! m_event_queue.empty ())
563 if (m_callback_objects.empty () || force)
565 e = m_event_queue.front ();
567 m_event_queue.pop_front ();
575 e = m_event_queue.front ();
577 m_event_queue.pop_front ();
581 std::list<graphics_event>::iterator p = m_event_queue.begin ();
583 while (p != m_event_queue.end ())
586 p = m_event_queue.erase (p);
588 else if (p->get_busyaction ()
592 m_event_queue.erase (p);
605 events_executed =
true;
611 octave::autolock guard (m_graphics_lock);
613 if (m_event_queue.empty () && m_event_processing == 0)
614 octave::command_editor::remove_event_hook (process_graphics_events);
688 octave::autolock guard (m_graphics_lock);
692 m_event_processing++;
694 octave::command_editor::add_event_hook (process_graphics_events);
698 m_event_processing--;
700 if (m_event_queue.empty () && m_event_processing == 0)
701 octave::command_editor::remove_event_hook (process_graphics_events);
705 OCTAVE_END_NAMESPACE(
octave)
octave_value_list Fdrawnow(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_idx_type numel() const
Number of elements in the array.
graphics_handle get_title() const
graphics_handle get_xlabel() const
graphics_handle get_ylabel() const
graphics_handle get_zlabel() const
virtual base_properties & get_properties()
bool is_beingdeleted() const
octave_value get_deletefcn() const
bool is_interruptible() const
void execute_deletefcn(const octave_value &new_data=octave_value()) const
std::string get_busyaction() const
void set_beingdeleted(const octave_value &val)
void execute_createfcn(const octave_value &new_data=octave_value()) const
virtual void delete_children(bool clear=false, bool from_root=false)
virtual std::string graphics_object_name() const
void post_set(const graphics_handle &h, const std::string &name, const octave_value &value, bool notify_toolkit=true, bool redraw_figure=false)
graphics_object get_object(double val) const
void renumber_figure(const graphics_handle &old_gh, const graphics_handle &new_gh)
void execute_listener(const graphics_handle &h, const octave_value &l)
gh_manager(octave::interpreter &interp)
void push_figure(const graphics_handle &h)
void post_event(const graphics_event &e)
Matrix figure_handle_list(bool show_hidden=false)
graphics_handle lookup(double val) const
void enable_event_processing(bool enable=true)
void post_function(graphics_event::event_fcn fcn, void *fcn_data=nullptr)
void free(const graphics_handle &h, bool from_root=false)
void pop_figure(const graphics_handle &h)
void post_callback(const graphics_handle &h, const std::string &name, const octave_value &data=Matrix())
graphics_handle make_graphics_handle(const std::string &go_name, const graphics_handle &p, bool integer_figure_handle=false, bool call_createfcn=true, bool notify_toolkit=true)
void execute_callback(const graphics_handle &h, const std::string &name, const octave_value &data=Matrix())
int process_events(bool force=false)
graphics_handle make_figure_handle(double val, bool notify_toolkit=true)
graphics_handle get_handle(bool integer_figure_handle)
static graphics_event create_mcode_event(const graphics_handle &h, const std::string &cmd, int busyaction)
void(* event_fcn)(void *)
static graphics_event create_function_event(event_fcn fcn, void *data=nullptr)
static graphics_event create_set_event(const graphics_handle &h, const std::string &name, const octave_value &value, bool notify_toolkit=true, bool redraw_figure=false)
static graphics_event create_callback_event(const graphics_handle &h, const std::string &name, const octave_value &data=Matrix(), int busyaction=base_graphics_event::QUEUE)
void override_defaults(base_graphics_object &obj)
base_properties & get_properties()
bool isa(const std::string &go_name) const
bool valid_object() const
void remove_child(const graphics_handle &h)
octave_value as_octave_value() const
bool is_function_handle() const
std::string class_name() const
octave_idx_type rows() const
octave_function * function_value(bool silent=false) const
std::string string_value(bool force=false) const
octave_idx_type length() const
octave_idx_type columns() const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void warning(const char *fmt,...)
void() error(const char *fmt,...)
octave_handle graphics_handle
bool isfigure(double val)
void force_close_figure(const graphics_handle &h)
void close_figure(const graphics_handle &h)
base_graphics_object * make_graphics_object_from_type(const caseless_str &type, const graphics_handle &h, const graphics_handle &p)
gh_manager & __get_gh_manager__()
gtk_manager & __get_gtk_manager__()
std::complex< T > ceil(const std::complex< T > &x)