00001
00002
00003
00004 #ifndef FITYK__UI__H__
00005 #define FITYK__UI__H__
00006
00007 #include "common.h"
00008
00009 class Ftk;
00010 class Parser;
00011 class Runner;
00012
00013
00014
00015 class UserInterface
00016 {
00017 public:
00018 enum RepaintMode {
00019 kRepaint,
00020 kRepaintImmediately
00021 };
00022
00023
00024 enum Style
00025 {
00026 kNormal,
00027 kWarning,
00028 kQuoted,
00029 kInput
00030 };
00031
00032 static const int max_cmd = 4096;
00033 enum Status { kStatusOk, kStatusExecuteError, kStatusSyntaxError };
00034
00035 struct Cmd
00036 {
00037 std::string cmd;
00038 Status status;
00039
00040 Cmd(const std::string& c, Status s) : cmd(c), status(s) {}
00041 std::string str() const;
00042 };
00043
00044 UserInterface(Ftk* F);
00045 ~UserInterface();
00046
00047
00048 void draw_plot(RepaintMode mode);
00049
00050
00051
00052 void output_message (Style style, const std::string& s) const;
00053
00054
00055 void exec_script(const std::string& filename);
00056
00057 void exec_stream(FILE *fp);
00058 void exec_string_as_script(const char* s);
00059
00060 UserInterface::Status exec_and_log(const std::string& c);
00061
00062
00063 void raw_execute_line(const std::string& str);
00064
00065
00066 UserInterface::Status execute_line(const std::string& str);
00067
00068
00069 bool check_syntax(const std::string& str);
00070
00071
00072 void process_cmd_line_filename(const std::string& par);
00073
00074
00075 typedef void t_do_draw_plot(RepaintMode mode);
00076 void set_do_draw_plot(t_do_draw_plot *func) { do_draw_plot_ = func; }
00077
00078 typedef void t_show_message(Style style, const std::string& s);
00079 void set_show_message(t_show_message *func) { show_message_ = func; }
00080
00081 typedef UserInterface::Status t_exec_command(const std::string &s);
00082 void set_exec_command(t_exec_command *func) { exec_command_ = func; }
00083
00084 typedef void t_refresh();
00085 void set_refresh(t_refresh *func) { refresh_ = func; }
00086
00087 void refresh() { if (refresh_) (*refresh_)(); }
00088
00089 typedef void t_compute_ui(bool);
00090 void set_compute_ui(t_compute_ui *func) { compute_ui_ = func; }
00091 void enable_compute_ui(bool enable)
00092 { if (compute_ui_) (*compute_ui_)(enable); }
00093
00094 typedef void t_wait(float seconds);
00095 void set_wait(t_wait *func) { wait_ = func; }
00096
00097 void wait(float seconds) { if (wait_) (*wait_)(seconds); }
00098
00099
00100 Parser* parser() const { return parser_; }
00101
00102 const std::vector<Cmd>& cmds() const { return cmds_; }
00103 std::string get_history_summary() const;
00104
00105 private:
00106 Ftk* F_;
00107 t_show_message *show_message_;
00108 t_do_draw_plot *do_draw_plot_;
00109 t_exec_command *exec_command_;
00110 t_refresh *refresh_;
00111 t_compute_ui *compute_ui_;
00112 t_wait *wait_;
00113 int cmd_count_;
00114 std::vector<Cmd> cmds_;
00115 Parser *parser_;
00116 Runner *runner_;
00117
00118
00119 void show_message(Style style, const std::string& s) const
00120 { if (show_message_) (*show_message_)(style, s); }
00121
00122
00123
00124 UserInterface::Status exec_command(const std::string& s);
00125
00126 DISALLOW_COPY_AND_ASSIGN(UserInterface);
00127 };
00128
00129
00130 extern const char* startup_commands_filename;
00131 extern const char* config_dirname;
00132
00133 #endif