35#if defined (HAVE_CONFIG_H)
46#include "builtin-defun-decls.h"
61class gnuplot_graphics_toolkit :
public octave::base_graphics_toolkit
65 gnuplot_graphics_toolkit (octave::interpreter& interp)
68 static bool warned =
false;
73 (
"Octave:gnuplot-graphics",
74 "using the gnuplot graphics toolkit is discouraged\n\
76The gnuplot graphics toolkit is not actively maintained and has a number\n\
77of limitations that are unlikely to be fixed. Communication with gnuplot\n\
78uses a one-directional pipe and limited information is passed back to the\n\
79Octave interpreter so most changes made interactively in the plot window\n\
80will not be reflected in the graphics properties managed by Octave. For\n\
81example, if the plot window is closed with a mouse click, Octave will not\n\
82be notified and will not update its internal list of open figure windows.\n\
83The qt toolkit is recommended instead.\n");
89 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (gnuplot_graphics_toolkit)
91 ~gnuplot_graphics_toolkit () =
default;
93 bool is_valid ()
const {
return true; }
95 bool initialize (
const graphics_object& go)
97 return go.isa (
"figure");
100 void finalize (
const graphics_object& go)
102 if (go.isa (
"figure"))
104 const figure::properties& props
105 =
dynamic_cast<const figure::properties&
> (go.get_properties ());
107 send_quit (props.get___plot_stream__ ());
111 void update (
const graphics_object& go,
int id)
113 if (go.isa (
"figure"))
115 graphics_object obj (go);
117 figure::properties& props
118 =
dynamic_cast<figure::properties&
> (obj.get_properties ());
122 case base_properties::ID_VISIBLE:
123 if (! props.is_visible ())
125 send_quit (props.get___plot_stream__ ());
126 props.set___plot_stream__ (
Matrix ());
127 props.set_graphicssmoothing (
false);
134 void redraw_figure (
const graphics_object& go)
const
136 static bool drawnow_executing =
false;
139 if (! drawnow_executing)
141 octave::unwind_protect_var<bool> restore_var (drawnow_executing,
true);
144 args(0) = go.get_handle ().as_octave_value ();
145 m_interpreter.feval (
"__gnuplot_drawnow__", args);
149 void print_figure (
const graphics_object& go,
const std::string& term,
150 const std::string& file,
151 const std::string& debug_file)
const
154 if (! debug_file.empty ())
155 args(3) = debug_file;
158 args(0) = go.get_handle ().as_octave_value ();
159 m_interpreter.feval (
"__gnuplot_drawnow__", args);
168 double get_screen_resolution ()
const
171 Matrix get_screen_size ()
const
172 {
return Matrix (1, 2, 0.0); }
176 if (m_interpreter.mislocked (
"__init_gnuplot__"))
177 m_interpreter.munlock (
"__init_gnuplot__");
189 octave::Ffputs (m_interpreter,
ovl (fids(0),
"\nquit;\n"));
191 octave::Ffflush (m_interpreter,
ovl (fids(0)));
192 octave::Fpclose (m_interpreter,
ovl (fids(0)));
194 if (fids.
numel () > 1)
196 octave::Fpclose (m_interpreter,
ovl (fids(1)));
198 if (fids.
numel () > 2)
199 octave::Fwaitpid (
ovl (fids(2)));
204 octave::interpreter& m_interpreter;
210 const std::string exeext = octave::build_env::EXEEXT;
211 const std::string path = octave::sys::env::getenv (
"PATH");
219 if (tmp(0).is_string () && ! tmp(0).isempty ())
221 std::string gnuplot_binary = tmp(0).string_value ();
224 std::string gnuplot_path = octave::search_path_for_file (path, args);
226 octave::sys::file_stat fs (gnuplot_path);
228 if (! fs.exists () && ! exeext.empty ())
232 gnuplot_path = octave::search_path_for_file (path, args);
234 fs = octave::sys::file_stat (gnuplot_path);
237 retval = fs.exists ();
240 catch (
const octave::execution_exception&)
256 if (! have_gnuplot_binary (interp))
257 error (
"__init_gnuplot__: the gnuplot program is not available, see 'gnuplot_binary'");
258 else if (! interp.
mislocked (
"__init_gnuplot__"))
277 return ovl (have_gnuplot_binary (interp));
285OCTAVE_END_NAMESPACE(octave)
octave_idx_type numel() const
Number of elements in the array.
void load_toolkit(const graphics_toolkit &tk)
void mlock(bool skip_first=false) const
gtk_manager & get_gtk_manager()
bool mislocked(bool skip_first=false) const
octave_value_list feval(const char *name, const octave_value_list &args=octave_value_list(), int nargout=0)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
void recover_from_exception()
Matrix matrix_value(bool frc_str_conv=false) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFMETHOD_DLD(name, interp_name, args_name, nargout_name, doc)
Macro to define an at run time dynamically loadable builtin method.
void warning_with_id(const char *id, const char *fmt,...)
void error(const char *fmt,...)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.