home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fs.zip / octave / octave-2.1.23 / src / pt-plot.h < prev    next >
C/C++ Source or Header  |  2000-01-15  |  9KB  |  443 lines

  1. /*
  2.  
  3. Copyright (C) 1996, 1997 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 2, or (at your option) any
  10. 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, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_tree_plot_h)
  24. #define octave_tree_plot_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. class ostream;
  31. class ostrstream;
  32.  
  33. class tree_expression;
  34. class tree_plot_command;
  35. class plot_limits;
  36. class plot_range;
  37. class subplot_using;
  38. class subplot_style;
  39. class subplot_axes;
  40. class subplot;
  41. class subplot_list;
  42.  
  43. class tree_walker;
  44.  
  45. #include <csignal>
  46.  
  47. #include <string>
  48.  
  49. #include <SLList.h>
  50.  
  51. #include "dColVector.h"
  52.  
  53. #include "pt-cmd.h"
  54.  
  55. class
  56. tree_plot_command : public tree_command
  57. {
  58. public:
  59.  
  60.   tree_plot_command (subplot_list *plt = 0, plot_limits *rng = 0, int nd = 0)
  61.     : tree_command (), ndim (nd), range (rng), plot_list (plt) { }
  62.  
  63.   ~tree_plot_command (void);
  64.  
  65.   void eval (void);
  66.  
  67.   int num_dimensions (void) { return ndim; }
  68.  
  69.   plot_limits *limits (void) { return range; }
  70.  
  71.   subplot_list *subplots (void) { return plot_list; }
  72.  
  73.   void accept (tree_walker& tw);
  74.  
  75. private:
  76.  
  77.   // The number of dimensions.  1 indicates a replot command.
  78.   int ndim;
  79.  
  80.   // The data ranges for the plot.
  81.   plot_limits *range;
  82.  
  83.   // The list of plots for this plot command.  For example, the
  84.   // command "plot sin(x), cos(x)" has two subplot commands.
  85.   subplot_list *plot_list;
  86.  
  87.   // No copying!
  88.  
  89.   tree_plot_command (const tree_plot_command&);
  90.  
  91.   tree_plot_command& operator = (const tree_plot_command&);
  92. };
  93.  
  94. class
  95. plot_limits
  96. {
  97. public:
  98.  
  99.   plot_limits (plot_range *xlim = 0, plot_range *ylim = 0,
  100.            plot_range *zlim = 0)
  101.     : x_range (xlim), y_range (ylim), z_range (zlim) { }
  102.  
  103.   ~plot_limits (void);
  104.  
  105.   void print (int ndim, ostrstream& plot_buf);
  106.  
  107.   plot_range *x_limits (void) { return x_range; }
  108.   plot_range *y_limits (void) { return y_range; }
  109.   plot_range *z_limits (void) { return z_range; }
  110.  
  111.   void accept (tree_walker& tw);
  112.  
  113. private:
  114.  
  115.   // Specified limits of the x, y, and z axes we should display for
  116.   // this plot.
  117.   plot_range *x_range;
  118.   plot_range *y_range;
  119.   plot_range *z_range;
  120.  
  121.   // No copying!
  122.  
  123.   plot_limits (const plot_limits&);
  124.  
  125.   plot_limits& operator = (const plot_limits&);
  126. };
  127.  
  128. class
  129. plot_range
  130. {
  131. public:
  132.  
  133.   plot_range (tree_expression *l = 0, tree_expression *u = 0)
  134.     : lower (l), upper (u) { }
  135.  
  136.   ~plot_range (void);
  137.  
  138.   void print (ostrstream& plot_buf);
  139.  
  140.   tree_expression *lower_bound (void) { return lower; }
  141.  
  142.   tree_expression *upper_bound (void) { return upper; }
  143.  
  144.   void accept (tree_walker& tw);
  145.  
  146. private:
  147.  
  148.   // A range can specify a lower or upper bound or both.  If neither
  149.   // is specified, the range to display is determined from the data.
  150.   tree_expression *lower;
  151.   tree_expression *upper;
  152.  
  153.   // No copying!
  154.  
  155.   plot_range (const plot_range&);
  156.  
  157.   plot_range& operator = (const plot_range&);
  158. };
  159.  
  160. class
  161. subplot_using
  162. {
  163. public:
  164.  
  165.   subplot_using (tree_expression *fmt = 0)
  166.     : qual_count (0), scanf_fmt (fmt), val (4, -1)
  167.       {
  168.     x[0] = x[1] = x[2] = x[3] = 0;
  169.       }
  170.  
  171.   ~subplot_using (void);
  172.  
  173.   subplot_using *set_format (tree_expression *fmt)
  174.     {
  175.       scanf_fmt = fmt;
  176.       return this;
  177.     }
  178.  
  179.   subplot_using *add_qualifier (tree_expression *t)
  180.     {
  181.       if (qual_count < 4)
  182.     x[qual_count] = t;
  183.  
  184.       qual_count++;
  185.  
  186.       return this;
  187.     }
  188.  
  189.   int eval (int ndim, int n_max);
  190.  
  191.   ColumnVector values (int ndim, int n_max = 0);
  192.  
  193.   int print (int ndim, int n_max, ostrstream& plot_buf);
  194.  
  195.   int qualifier_count (void) { return qual_count; }
  196.  
  197.   tree_expression **qualifiers (void) { return x; }
  198.  
  199.   tree_expression *scanf_format (void) { return scanf_fmt; }
  200.  
  201.   void accept (tree_walker& tw);
  202.  
  203. private:
  204.  
  205.   // The number of using qualifiers (in "using 1:2", 1 and 2 are the
  206.   // qualifiers).
  207.   int qual_count;
  208.  
  209.   // An optional scanf-style format.  This is parsed and stored but
  210.   // not currently used.
  211.   tree_expression *scanf_fmt;
  212.  
  213.   // This is a cache for evaluated versions of the qualifiers stored
  214.   // in x.
  215.   ColumnVector val;
  216.  
  217.   // A vector to hold using qualifiers.
  218.   tree_expression *x[4];
  219.  
  220.   // No copying!
  221.  
  222.   subplot_using (const subplot_using&);
  223.  
  224.   subplot_using& operator = (const subplot_using&);
  225. };
  226.  
  227. class
  228. subplot_style
  229. {
  230. public:
  231.  
  232.   subplot_style (const string& s = string (),
  233.          tree_expression *lt = 0, tree_expression *pt = 0)
  234.     : sp_style (s), sp_linetype (lt), sp_pointtype (pt) { }
  235.  
  236.   ~subplot_style (void);
  237.  
  238.   int print (ostrstream& plot_buf);
  239.  
  240.   bool columns_ok (int nc);
  241.  
  242.   string style (void) { return sp_style; }
  243.  
  244.   tree_expression *linetype (void) { return sp_linetype; }
  245.  
  246.   tree_expression *pointtype (void) { return sp_pointtype; }
  247.  
  248.   void accept (tree_walker& tw);
  249.  
  250. private:
  251.  
  252.   // The style we are using: `lines', `points', etc.
  253.   string sp_style;
  254.  
  255.   // The number of the line type to use.
  256.   tree_expression *sp_linetype;
  257.  
  258.   // The number of the point type to use.
  259.   tree_expression *sp_pointtype;
  260.  
  261.   // No copying!
  262.  
  263.   subplot_style (const subplot_style&);
  264.  
  265.   subplot_style& operator = (const subplot_style&);
  266. };
  267.  
  268. class
  269. subplot_axes
  270. {
  271. public:
  272.  
  273.   subplot_axes (const string& s = string ())
  274.     : sp_axes (s) { }
  275.  
  276.   ~subplot_axes (void) { }
  277.  
  278.   int print (ostrstream& plot_buf);
  279.  
  280.   string axes (void) { return sp_axes; }
  281.  
  282.   void accept (tree_walker& tw);
  283.  
  284. private:
  285.  
  286.   // The axes we are using: `x1y1', `x1y2', etc.
  287.   string sp_axes;
  288.  
  289.   // No copying!
  290.  
  291.   subplot_axes (const subplot_axes&);
  292.  
  293.   subplot_axes& operator = (const subplot_axes&);
  294. };
  295.  
  296. class
  297. subplot
  298. {
  299. public:
  300.  
  301.   subplot (tree_expression *data = 0)
  302.     : sp_plot_data (data), sp_using_clause (0), sp_title_clause (0),
  303.       sp_style_clause (0), sp_axes_clause (0) { }
  304.  
  305.   ~subplot (void);
  306.  
  307.   subplot *add_data (tree_expression *data)
  308.     {
  309.       sp_plot_data = data;
  310.       return this;
  311.     }
  312.  
  313.   subplot *add_clause (subplot_using *u)
  314.     {
  315.       if (! sp_using_clause)
  316.     {
  317.       sp_using_clause = u;
  318.       return this;
  319.     }
  320.       else
  321.     return 0;
  322.     }
  323.  
  324.   subplot *add_clause (tree_expression *t)
  325.     {
  326.       if (! sp_title_clause)
  327.     {
  328.       sp_title_clause = t;
  329.       return this;
  330.     }
  331.       else
  332.     return 0;
  333.     }
  334.  
  335.   subplot *add_clause (subplot_style *s)
  336.     {
  337.       if (! sp_style_clause)
  338.     {
  339.       sp_style_clause = s;
  340.       return this;
  341.     }
  342.       else
  343.     return 0;
  344.     }
  345.  
  346.   subplot *add_clause (subplot_axes *a)
  347.     {
  348.       if (! sp_axes_clause)
  349.     {
  350.       sp_axes_clause = a;
  351.       return this;
  352.     }
  353.       else
  354.     return 0;
  355.     }
  356.  
  357.   octave_value extract_plot_data (int ndim, octave_value& data);
  358.  
  359.   int handle_plot_data (int ndim, ostrstream& plot_buf);
  360.  
  361.   int print (int ndim, ostrstream& plot_buf);
  362.  
  363.   tree_expression *plot_data (void) { return sp_plot_data; }
  364.  
  365.   subplot_using *using_clause (void) { return sp_using_clause; }
  366.  
  367.   tree_expression *title_clause (void) { return sp_title_clause; }
  368.  
  369.   subplot_style *style_clause (void) { return sp_style_clause; }
  370.  
  371.   subplot_axes *axes_clause (void) { return sp_axes_clause; }
  372.  
  373.   void accept (tree_walker& tw);
  374.  
  375. private:
  376.  
  377.   // The data to plot.
  378.   tree_expression *sp_plot_data;
  379.  
  380.   // The `using' option
  381.   subplot_using *sp_using_clause;
  382.  
  383.   // The `title' option
  384.   tree_expression *sp_title_clause;
  385.  
  386.   // The `style' option
  387.   subplot_style *sp_style_clause;
  388.  
  389.   // The `axes' option
  390.   subplot_axes *sp_axes_clause;
  391.  
  392.   // No copying!
  393.  
  394.   subplot (const subplot&);
  395.  
  396.   subplot& operator = (const subplot&);
  397. };
  398.  
  399. class
  400. subplot_list : public SLList<subplot *>
  401. {
  402. public:
  403.  
  404.   subplot_list (void)
  405.     : SLList<subplot *> () { }
  406.  
  407.   subplot_list (subplot *t)
  408.     : SLList<subplot *> () { append (t); }
  409.  
  410.   ~subplot_list (void);
  411.  
  412.   int print (int ndim, ostrstream& plot_buf);
  413.  
  414.   void accept (tree_walker& tw);
  415.  
  416. private:
  417.  
  418.   // No copying!
  419.  
  420.   subplot_list (const subplot_list&);
  421.  
  422.   subplot_list& operator = (const subplot_list&);
  423. };
  424.  
  425. extern string save_in_tmp_file (octave_value& t, int ndim = 2,
  426.                 bool parametric = false);
  427.  
  428. extern void mark_for_deletion (const string&);
  429.  
  430. extern void cleanup_tmp_files (void);
  431.  
  432. extern void close_plot_stream (void);
  433.  
  434. extern void do_external_plotter_cd (const string& newdir);
  435.  
  436. #endif
  437.  
  438. /*
  439. ;;; Local Variables: ***
  440. ;;; mode: C++ ***
  441. ;;; End: ***
  442. */
  443.