Mercurial > octave-nkf
comparison src/dldfcn/__init_gnuplot__.cc @ 15076:000587f92082
rename src/DLD-FUNCTIONS directory to src/dldfcn
* src/dldfcn: Rename from src/DLD-FUNCTIONS.
* autogen.sh, src/Makefile.am, src/dldfcn/config-module.awk,
src/dldfcn/config-module.sh: Change all uses of DLD-FUNCTIONS to be
dldfcn. Change all uses of DLD_FUNCTIONS to be DLDFCN.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 31 Jul 2012 21:57:58 -0400 |
parents | src/DLD-FUNCTIONS/__init_gnuplot__.cc@72c96de7a403 |
children |
comparison
equal
deleted
inserted
replaced
15075:b62b0b85369c | 15076:000587f92082 |
---|---|
1 /* | |
2 | |
3 Copyright (C) 2007-2012 John W. Eaton | |
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 /* | |
24 | |
25 To initialize: | |
26 | |
27 graphics_toolkit ("gnuplot"); | |
28 plot (randn (1e3, 1)); | |
29 | |
30 */ | |
31 | |
32 #ifdef HAVE_CONFIG_H | |
33 #include <config.h> | |
34 #endif | |
35 | |
36 #include "defun-dld.h" | |
37 #include "error.h" | |
38 #include "graphics.h" | |
39 #include "parse.h" | |
40 #include "variables.h" | |
41 | |
42 // PKG_ADD: register_graphics_toolkit ("gnuplot"); | |
43 | |
44 static bool toolkit_loaded = false; | |
45 | |
46 class gnuplot_graphics_toolkit : public base_graphics_toolkit | |
47 { | |
48 public: | |
49 gnuplot_graphics_toolkit (void) | |
50 : base_graphics_toolkit ("gnuplot") { } | |
51 | |
52 ~gnuplot_graphics_toolkit (void) { } | |
53 | |
54 bool is_valid (void) const { return true; } | |
55 | |
56 bool initialize (const graphics_object& go) | |
57 { | |
58 return go.isa ("figure"); | |
59 } | |
60 | |
61 void finalize (const graphics_object& go) | |
62 { | |
63 if (go.isa ("figure")) | |
64 { | |
65 const figure::properties& props = | |
66 dynamic_cast<const figure::properties&> (go.get_properties ()); | |
67 | |
68 send_quit (props.get___plot_stream__ ()); | |
69 } | |
70 } | |
71 | |
72 void update (const graphics_object& go, int id) | |
73 { | |
74 if (go.isa ("figure")) | |
75 { | |
76 graphics_object obj (go); | |
77 | |
78 figure::properties& props = | |
79 dynamic_cast<figure::properties&> (obj.get_properties ()); | |
80 | |
81 switch (id) | |
82 { | |
83 case base_properties::ID_VISIBLE: | |
84 if (! props.is_visible ()) | |
85 { | |
86 send_quit (props.get___plot_stream__ ()); | |
87 props.set___plot_stream__ (Matrix ()); | |
88 props.set___enhanced__ (false); | |
89 } | |
90 break; | |
91 } | |
92 } | |
93 } | |
94 | |
95 void redraw_figure (const graphics_object& go) const | |
96 { | |
97 octave_value_list args; | |
98 args(0) = go.get_handle ().as_octave_value (); | |
99 feval ("__gnuplot_drawnow__", args); | |
100 } | |
101 | |
102 void print_figure (const graphics_object& go, const std::string& term, | |
103 const std::string& file, bool mono, | |
104 const std::string& debug_file) const | |
105 { | |
106 octave_value_list args; | |
107 if (! debug_file.empty ()) | |
108 args(4) = debug_file; | |
109 args(3) = mono; | |
110 args(2) = file; | |
111 args(1) = term; | |
112 args(0) = go.get_handle ().as_octave_value (); | |
113 feval ("__gnuplot_drawnow__", args); | |
114 } | |
115 | |
116 Matrix get_canvas_size (const graphics_handle&) const | |
117 { | |
118 Matrix sz (1, 2, 0.0); | |
119 return sz; | |
120 } | |
121 | |
122 double get_screen_resolution (void) const | |
123 { return 72.0; } | |
124 | |
125 Matrix get_screen_size (void) const | |
126 { return Matrix (1, 2, 0.0); } | |
127 | |
128 void close (void) | |
129 { | |
130 if (toolkit_loaded) | |
131 { | |
132 munlock ("__init_gnuplot__"); | |
133 | |
134 gtk_manager::unload_toolkit ("gnuplot"); | |
135 | |
136 toolkit_loaded = false; | |
137 } | |
138 } | |
139 | |
140 private: | |
141 | |
142 void send_quit (const octave_value& pstream) const | |
143 { | |
144 if (! pstream.is_empty ()) | |
145 { | |
146 octave_value_list args; | |
147 Matrix fids = pstream.matrix_value (); | |
148 | |
149 if (! error_state) | |
150 { | |
151 args(1) = "\nquit;\n"; | |
152 args(0) = fids(0); | |
153 feval ("fputs", args); | |
154 | |
155 args.resize (1); | |
156 feval ("fflush", args); | |
157 feval ("pclose", args); | |
158 | |
159 if (fids.numel () > 1) | |
160 { | |
161 args(0) = fids(1); | |
162 feval ("pclose", args); | |
163 | |
164 if (fids.numel () > 2) | |
165 { | |
166 args(0) = fids(2); | |
167 feval ("waitpid", args); | |
168 } | |
169 } | |
170 } | |
171 } | |
172 } | |
173 }; | |
174 | |
175 // Initialize the fltk graphics toolkit. | |
176 | |
177 DEFUN_DLD (__init_gnuplot__, , , "") | |
178 { | |
179 octave_value retval; | |
180 | |
181 if (! toolkit_loaded) | |
182 { | |
183 mlock (); | |
184 | |
185 graphics_toolkit tk (new gnuplot_graphics_toolkit ()); | |
186 gtk_manager::load_toolkit (tk); | |
187 | |
188 toolkit_loaded = true; | |
189 } | |
190 | |
191 return retval; | |
192 } | |
193 |