1- /*
2- * Copyright (C) 2020 Giulio Girardi.
1+ /* **************************************************************************
2+ * Copyright (c) 2022, Giulio Girardi
33 *
4- * This file is part of xeus-octave .
4+ * Distributed under the terms of the GNU General Public License v3 .
55 *
6- * xeus-octave is free software: you can redistribute it and/or modify
7- * it under the terms of the GNU General Public License as published by
8- * the Free Software Foundation, either version 3 of the License, or
9- * (at your option) any later version.
10- *
11- * xeus-octave is distributed in the hope that it will be useful,
12- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- * GNU General Public License for more details.
15- *
16- * You should have received a copy of the GNU General Public License
17- * along with xeus-octave. If not, see <http://www.gnu.org/licenses/>.
18- */
6+ * The full license is in the file LICENSE, distributed with this software.
7+ ****************************************************************************/
198
20- #ifndef XEUS_OCTAVE_PLOTSTREAM_H
21- #define XEUS_OCTAVE_PLOTSTREAM_H
9+ #ifndef XEUS_OCTAVE_PLOTSTREAM_HPP
10+ #define XEUS_OCTAVE_PLOTSTREAM_HPP
2211
2312#include < octave/graphics.h>
2413
14+ #include < xwidgets/ximage.hpp>
15+
16+ namespace oc = octave;
17+
2518namespace xeus_octave
2619{
2720
28- inline std::string getPlotStream (octave::graphics_object const & o)
21+ template <class T > inline T getPlotStream (oc::graphics_object const & o);
22+
23+ /* *
24+ * Retrieve from the graphics object the plot_stream property
25+ */
26+ template <> inline xw::image* getPlotStream<xw::image*>(oc::graphics_object const & o)
27+ {
28+ octave_value ps =
29+ dynamic_cast <oc::figure::properties const &>(o.get_ancestor (" figure" ).get_properties ()).get___plot_stream__ ();
30+
31+ if (ps.isnumeric () && ps.is_scalar_type ())
32+ return reinterpret_cast <xw::image*>(ps.long_value ());
33+ else
34+ return nullptr ;
35+ }
36+
37+ /* *
38+ * Retrieve from the graphics object the plot_stream property
39+ */
40+ template <> inline std::string getPlotStream<std::string>(oc::graphics_object const & o)
2941{
30- return dynamic_cast <octave::figure::properties const &>(o.get_ancestor (" figure" ).get_properties ())
31- .get___plot_stream__ ()
32- .string_value ();
42+ octave_value ps =
43+ dynamic_cast <oc::figure::properties const &>(o.get_ancestor (" figure" ).get_properties ()).get___plot_stream__ ();
44+
45+ if (ps.is_string ())
46+ return ps.string_value ();
47+ else
48+ return " " ;
3349}
3450
35- inline void setPlotStream (octave::graphics_object& o, std::string p)
51+ /* *
52+ * Set in the graphics object the plot_stream propert
53+ */
54+ inline void setPlotStream (oc::graphics_object& o, xw::image* p)
3655{
3756 if (o.isa (" figure" ))
38- dynamic_cast <octave::figure::properties&>(o.get_properties ()).set___plot_stream__ (p);
57+ {
58+ auto & fp = dynamic_cast <oc::figure::properties&>(o.get_properties ());
59+ fp.set___plot_stream__ (reinterpret_cast <intptr_t >(p));
60+ }
3961}
4062
41- inline void setPlotStream (octave::graphics_object const & o, std::string p)
63+ /* *
64+ * Set in the graphics object the plot_stream propert
65+ */
66+ inline void setPlotStream (oc::graphics_object& o, std::string p)
67+ {
68+ if (o.isa (" figure" ))
69+ {
70+ auto & fp = dynamic_cast <oc::figure::properties&>(o.get_properties ());
71+ fp.set___plot_stream__ (p);
72+ }
73+ }
74+
75+ /* *
76+ * Set in the graphics object the plot_stream propert (const version)
77+ */
78+ inline void setPlotStream (oc::graphics_object const & o, xw::image* p)
79+ {
80+ // deCONSTify the graphics_object
81+ auto _go = o;
82+ setPlotStream (_go, p);
83+ }
84+
85+ /* *
86+ * Set in the graphics object the plot_stream propert (const version)
87+ */
88+ inline void setPlotStream (oc::graphics_object const & o, std::string p)
4289{
4390 // deCONSTify the graphics_object
4491 auto _go = o;
@@ -47,4 +94,4 @@ inline void setPlotStream(octave::graphics_object const& o, std::string p)
4794
4895} // namespace xeus_octave
4996
50- #endif // XEUS_OCTAVE_PLOTSTREAM_H
97+ #endif
0 commit comments