GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
octave-link.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2013-2017 John W. Eaton
4 Copyright (C) 2011-2016 Jacob Dawid
5 Copyright (C) 2011-2016 John P. Swensen
6 
7 This file is part of Octave.
8 
9 Octave is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the
11 Free Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
13 
14 Octave is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Octave; see the file COPYING. If not, see
21 <http://www.gnu.org/licenses/>.
22 
23 */
24 
25 #if defined (HAVE_CONFIG_H)
26 # include "config.h"
27 #endif
28 
29 #include "cmd-edit.h"
30 #include "defun.h"
31 #include "oct-env.h"
32 #include "oct-mutex.h"
33 #include "pager.h"
34 #include "singleton-cleanup.h"
35 #include "interpreter.h"
36 
37 #include "octave-link.h"
38 
39 static int
41 {
46 
47  return 0;
48 }
49 
51 
53  : event_queue_mutex (new octave_mutex ()), gui_event_queue (),
54  debugging (false), link_enabled (true)
55 {
57 }
58 
60 {
61  delete event_queue_mutex;
62 }
63 
64 void
66 {
67  if (enabled ())
72 }
73 
74 // OBJ should be an object of a class that is derived from the base
75 // class octave_link, or 0 to disconnect the link. It is the
76 // responsibility of the caller to delete obj.
77 
78 void
80 {
81  if (obj && instance)
82  error ("octave_link is already linked!");
83 
84  instance = obj;
85 }
86 
87 void
89 { }
90 
91 void
93 {
95 
97 
99 }
100 
101 void
103 {
105 
107 
109 }
110 
111 DEFUN (__octave_link_enabled__, , ,
112  doc: /* -*- texinfo -*-
113 @deftypefn {} {} __octave_link_enabled__ ()
114 Undocumented internal function.
115 @end deftypefn */)
116 {
117  return ovl (octave_link::enabled ());
118 }
119 
120 DEFUN (__octave_link_edit_file__, args, ,
121  doc: /* -*- texinfo -*-
122 @deftypefn {} {} __octave_link_edit_file__ (@var{file})
123 Undocumented internal function.
124 @end deftypefn */)
125 {
127 
128  if (args.length () == 1)
129  {
130  std::string file = args(0).xstring_value ("first argument must be filename");
131 
133 
134  retval = octave_link::edit_file (file);
135  }
136  else if (args.length () == 2)
137  {
138  std::string file = args(0).xstring_value ("first argument must be filename");
139 
141 
142  retval = octave_link::prompt_new_edit_file (file);
143  }
144 
145  return retval;
146 }
147 
148 DEFUN (__octave_link_message_dialog__, args, ,
149  doc: /* -*- texinfo -*-
150 @deftypefn {} {} __octave_link_message_dialog__ (@var{dlg}, @var{msg}, @var{title})
151 Undocumented internal function.
152 @end deftypefn */)
153 {
155 
156  if (args.length () == 3)
157  {
158  std::string dlg = args(0).xstring_value ("invalid arguments");
159  std::string msg = args(1).xstring_value ("invalid arguments");
160  std::string title = args(2).xstring_value ("invalid arguments");
161 
163 
164  retval = octave_link::message_dialog (dlg, msg, title);
165  }
166 
167  return retval;
168 }
169 
170 DEFUN (__octave_link_question_dialog__, args, ,
171  doc: /* -*- texinfo -*-
172 @deftypefn {} {} __octave_link_question_dialog__ (@var{msg}, @var{title}, @var{btn1}, @var{btn2}, @var{btn3}, @var{default})
173 Undocumented internal function.
174 @end deftypefn */)
175 {
177 
178  if (args.length () == 6)
179  {
180  std::string msg = args(0).xstring_value ("invalid arguments");
181  std::string title = args(1).xstring_value ("invalid arguments");
182  std::string btn1 = args(2).xstring_value ("invalid arguments");
183  std::string btn2 = args(3).xstring_value ("invalid arguments");
184  std::string btn3 = args(4).xstring_value ("invalid arguments");
185  std::string btndef = args(5).xstring_value ("invalid arguments");
186 
188 
189  retval = octave_link::question_dialog (msg, title, btn1, btn2, btn3,
190  btndef);
191  }
192 
193  return retval;
194 }
195 
196 DEFUN (__octave_link_file_dialog__, args, ,
197  doc: /* -*- texinfo -*-
198 @deftypefn {} {} __octave_link_file_dialog__ (@var{filterlist}, @var{title}, @var{filename}, @var{size} @var{multiselect}, @var{pathname})
199 Undocumented internal function.
200 @end deftypefn */)
201 {
202  if (args.length () != 6)
203  return ovl ();
204 
206 
207  const Array<std::string> flist = args(0).cellstr_value ();
208  std::string title = args(1).string_value ();
209  std::string filename = args(2).string_value ();
210  Matrix pos = args(3).matrix_value ();
211  std::string multi_on = args(4).string_value (); // on, off, create
212  std::string pathname = args(5).string_value ();
213 
214  octave_idx_type nel;
215  octave_link::filter_list filter_lst;
216 
217  for (octave_idx_type i = 0; i < flist.rows (); i++)
218  filter_lst.push_back (std::make_pair (flist(i,0),
219  (flist.columns () > 1
220  ? flist(i,1) : "")));
221 
223 
224  std::list<std::string> items_lst
225  = octave_link::file_dialog (filter_lst, title, filename, pathname,
226  multi_on);
227 
228  nel = items_lst.size ();
229 
230  // If 3, then retval is filename, directory, and selected index.
231  if (nel <= 3)
232  {
233  if (items_lst.front ().empty ())
234  retval = ovl (octave_value (0.), octave_value (0.), octave_value (0.));
235  else
236  {
237  int idx = 0;
238  for (std::list<std::string>::iterator it = items_lst.begin ();
239  it != items_lst.end (); it++)
240  {
241  if (idx != 2)
242  retval(idx++) = *it;
243  else
244  retval(idx++) = atoi (it->c_str ());
245  }
246  }
247  }
248  else
249  {
250  // Multiple files.
251  nel -= 2;
252  Cell items (dim_vector (1, nel));
253 
254  std::list<std::string>::iterator it = items_lst.begin ();
255 
256  for (int idx = 0; idx < nel; idx++, it++)
257  items.xelem (idx) = *it;
258 
259  retval = ovl (items, *it++, atoi (it->c_str ()));
260  }
261 
262  return retval;
263 }
264 
265 DEFUN (__octave_link_list_dialog__, args, ,
266  doc: /* -*- texinfo -*-
267 @deftypefn {} {} __octave_link_list_dialog__ (@var{list}, @var{mode}, @var{size}, @var{intial}, @var{name}, @var{prompt}, @var{ok_string}, @var{cancel_string})
268 Undocumented internal function.
269 @end deftypefn */)
270 {
271  if (args.length () != 8)
272  return ovl ();
273 
274  Cell list = args(0).cell_value ();
275  const Array<std::string> tlist = list.cellstr_value ();
276  octave_idx_type nel = tlist.numel ();
277  std::list<std::string> list_lst;
278  for (octave_idx_type i = 0; i < nel; i++)
279  list_lst.push_back (tlist(i));
280 
281  std::string mode = args(1).string_value ();
282 
283  Matrix size_matrix = args(2).matrix_value ();
284  int width = size_matrix(0);
285  int height = size_matrix(1);
286 
287  Matrix initial_matrix = args(3).matrix_value ();
288  nel = initial_matrix.numel ();
289  std::list<int> initial_lst;
290  for (octave_idx_type i = 0; i < nel; i++)
291  initial_lst.push_back (initial_matrix(i));
292 
293  std::string name = args(4).string_value ();
294  list = args(5).cell_value ();
295  const Array<std::string> plist = list.cellstr_value ();
296  nel = plist.numel ();
297  std::list<std::string> prompt_lst;
298  for (octave_idx_type i = 0; i < nel; i++)
299  prompt_lst.push_back (plist(i));
300  std::string ok_string = args(6).string_value ();
301  std::string cancel_string = args(7).string_value ();
302 
304 
305  std::pair<std::list<int>, int> result
306  = octave_link::list_dialog (list_lst, mode, width, height,
307  initial_lst, name, prompt_lst,
308  ok_string, cancel_string);
309 
310  std::list<int> items_lst = result.first;
311  nel = items_lst.size ();
312  Matrix items (dim_vector (1, nel));
313  octave_idx_type i = 0;
314  for (std::list<int>::iterator it = items_lst.begin ();
315  it != items_lst.end (); it++)
316  {
317  items.xelem(i++) = *it;
318  }
319 
320  return ovl (items, result.second);
321 }
322 
323 DEFUN (__octave_link_input_dialog__, args, ,
324  doc: /* -*- texinfo -*-
325 @deftypefn {} {} __octave_link_input_dialog__ (@var{prompt}, @var{title}, @var{rowscols}, @var{defaults})
326 Undocumented internal function.
327 @end deftypefn */)
328 {
329  if (args.length () != 4)
330  return ovl ();
331 
332  Cell prompt = args(0).cell_value ();
334  octave_idx_type nel = tmp.numel ();
335  std::list<std::string> prompt_lst;
336  for (octave_idx_type i = 0; i < nel; i++)
337  prompt_lst.push_back (tmp(i));
338 
339  std::string title = args(1).string_value ();
340 
341  Matrix rc = args(2).matrix_value ();
342  nel = rc.rows ();
343  std::list<float> nr;
344  std::list<float> nc;
345  for (octave_idx_type i = 0; i < nel; i++)
346  {
347  nr.push_back (rc(i,0));
348  nc.push_back (rc(i,1));
349  }
350 
351  Cell defaults = args(3).cell_value ();
352  tmp = defaults.cellstr_value ();
353  nel = tmp.numel ();
354  std::list<std::string> defaults_lst;
355  for (octave_idx_type i = 0; i < nel; i++)
356  defaults_lst.push_back (tmp(i));
357 
359 
360  std::list<std::string> items_lst
361  = octave_link::input_dialog (prompt_lst, title, nr, nc,
362  defaults_lst);
363 
364  nel = items_lst.size ();
365  Cell items (dim_vector (nel, 1));
366  octave_idx_type i = 0;
367  for (std::list<std::string>::iterator it = items_lst.begin ();
368  it != items_lst.end (); it++)
369  {
370  items.xelem(i++) = *it;
371  }
372 
373  return ovl (items);
374 }
375 
376 DEFUN (__octave_link_show_preferences__, , ,
377  doc: /* -*- texinfo -*-
378 @deftypefn {} {} __octave_link_show_preferences__ ()
379 Undocumented internal function.
380 @end deftypefn */)
381 {
383 }
384 
385 DEFUN (__octave_link_show_doc__, args, ,
386  doc: /* -*- texinfo -*-
387 @deftypefn {} {} __octave_link_show_doc__ (@var{filename})
388 Undocumented internal function.
389 @end deftypefn */)
390 {
392 
393  if (args.length () >= 1)
394  file = args(0).string_value();
395 
396  return ovl (octave_link::show_doc (file));
397 }
void flush_octave_stdout(void)
Definition: pager.cc:454
void discard(size_t num)
Definition: Cell.h:37
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:120
The value of lines which begin with a space character are not saved in the history list A value of all commands are saved on the history list
Definition: oct-hist.cc:728
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).is_integer_type())
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
Definition: data.cc:6386
void run(size_t num)
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
void error(const char *fmt,...)
Definition: error.cc:570
std::string filename
Definition: urlwrite.cc:340
octave_idx_type rows(void) const
Definition: Array.h:401
static scope_id top_scope(void)
Definition: symtab.h:1161
JNIEnv void * args
Definition: ov-java.cc:67
Array< std::string > cellstr_value(void) const
Definition: Cell.cc:142
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
double tmp
Definition: data.cc:6300
is false
Definition: cellfun.cc:398
octave_value retval
Definition: data.cc:6294
Definition: dMatrix.h:37
With real return the complex result
Definition: data.cc:3375
T & xelem(octave_idx_type n)
Definition: Array.h:455
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
static void add_event_hook(event_hook_fcn f)
Definition: cmd-edit.cc:1545
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
static std::list< workspace_element > workspace_info(scope_id scope=xcurrent_scope)
Definition: symtab.h:2217
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
void lock(void)
Definition: oct-mutex.h:85
octave_idx_type columns(void) const
Definition: Array.h:410
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
static scope_id current_scope(void)
Definition: symtab.h:1163
void unlock(void)
Definition: oct-mutex.h:90