GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
graphics-utils.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2007-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include "caseless-str.h"
31
32#include "gh-manager.h"
33#include "graphics-utils.h"
34#include "graphics.h"
35#include "input.h"
36#include "interpreter-private.h"
37#include "ov.h"
38
40
41// Flag to stop redraws due to callbacks while deletion is in progress.
43
44void
45xset (const graphics_handle& h, const caseless_str& pname,
46 const octave_value& val)
47{
48 gh_manager& gh_mgr = octave::__get_gh_manager__ ();
49
50 graphics_object go = gh_mgr.get_object (h);
51
52 go.set (pname, val);
53}
54
55void
56xset (const graphics_handle& h, const octave_value_list& args)
57{
58 if (args.length () > 0)
59 {
60 gh_manager& gh_mgr = octave::__get_gh_manager__ ();
61
62 graphics_object go = gh_mgr.get_object (h);
63
64 go.set (args);
65 }
66}
67
69xget (const graphics_handle& h, const caseless_str& pname)
70{
71 gh_manager& gh_mgr = octave::__get_gh_manager__ ();
72
73 graphics_object go = gh_mgr.get_object (h);
74
75 return go.get (pname);
76}
77
78bool
79isfigure (double val)
80{
81 gh_manager& gh_mgr = octave::__get_gh_manager__ ();
82
83 graphics_object go = gh_mgr.get_object (val);
84
85 return go && go.isa ("figure");
86}
87
89reparent (const octave_value& ov, const std::string& who,
90 const std::string& pname, const graphics_handle& new_parent,
91 bool adopt)
92{
93 double hv = ov.xdouble_value ("%s: %s must be a graphics handle",
94 who.c_str (), pname.c_str ());
95
96 gh_manager& gh_mgr = octave::__get_gh_manager__ ();
97
98 graphics_handle h = gh_mgr.lookup (hv);
99
100 if (! h.ok ())
101 error ("%s: invalid graphics handle (= %g) for %s",
102 who.c_str (), hv, pname.c_str ());
103
104 graphics_object go = gh_mgr.get_object (h);
105
106 graphics_handle parent_h = go.get_parent ();
107
108 graphics_object parent_go = gh_mgr.get_object (parent_h);
109
110 parent_go.remove_child (h);
111
112 if (adopt)
113 go.set ("parent", new_parent.value ());
114 else
115 go.reparent (new_parent);
116
117 return h;
118}
119
120void
121delete_graphics_object (const graphics_handle& h, bool from_root)
122{
123 if (h.ok ())
124 {
125 gh_manager& gh_mgr = octave::__get_gh_manager__ ();
126
127 graphics_object go = gh_mgr.get_object (h);
128
129 // Don't do recursive deleting, due to callbacks
130 if (! go.get_properties ().is_beingdeleted ())
131 {
132 // NOTE: Freeing the handle also calls any deletefcn. It also calls
133 // the parent's delete_child function.
134
135 gh_mgr.free (h, from_root || go.isa ("figure"));
136
137 Vdrawnow_requested = true;
138 }
139 }
140}
141
142void
143delete_graphics_object (double val, bool from_root)
144{
145 gh_manager& gh_mgr = octave::__get_gh_manager__ ();
146
147 delete_graphics_object (gh_mgr.lookup (val), from_root || isfigure (val));
148}
149
150void
151delete_graphics_objects (const NDArray vals, bool from_root)
152{
153 // Prevent redraw of partially deleted objects.
154 octave::unwind_protect_var<bool> restore_var (delete_executing, true);
155
156 for (octave_idx_type i = 0; i < vals.numel (); i++)
157 delete_graphics_object (vals.elem (i), from_root);
158}
159
160void
162{
163 octave_value closerequestfcn = xget (h, "closerequestfcn");
164
165 gh_manager& gh_mgr = octave::__get_gh_manager__ ();
166
167 gh_mgr.execute_callback (h, closerequestfcn);
168}
169
170void
172{
173 // Remove the deletefcn and closerequestfcn callbacks
174 // and delete the object directly.
175
176 xset (h, "deletefcn", Matrix ());
177 xset (h, "closerequestfcn", Matrix ());
178
179 delete_graphics_object (h, true);
180}
181
182OCTAVE_END_NAMESPACE(octave)
T & elem(octave_idx_type n)
Size of the specified dimension.
Definition Array.h:563
octave_idx_type numel() const
Number of elements in the array.
Definition Array.h:418
graphics_object get_object(double val) const
Definition gh-manager.h:68
graphics_handle lookup(double val) const
Definition gh-manager.h:54
void free(const graphics_handle &h, bool from_root=false)
Definition gh-manager.cc:91
void execute_callback(const graphics_handle &h, const std::string &name, const octave_value &data=Matrix())
Definition gh-manager.h:150
double value() const
Definition oct-handle.h:78
bool ok() const
Definition oct-handle.h:113
octave_idx_type length() const
Definition ovl.h:111
double xdouble_value(const char *fmt,...) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition error.cc:1003
void xset(const graphics_handle &h, const caseless_str &pname, const octave_value &val)
bool delete_executing
bool isfigure(double val)
void force_close_figure(const graphics_handle &h)
graphics_handle reparent(const octave_value &ov, const std::string &who, const std::string &pname, const graphics_handle &new_parent, bool adopt)
void close_figure(const graphics_handle &h)
void delete_graphics_object(const graphics_handle &h, bool from_root)
octave_value xget(const graphics_handle &h, const caseless_str &pname)
void delete_graphics_objects(const NDArray vals, bool from_root)
bool Vdrawnow_requested
Definition input.cc:89