From: Mikko Rasa Date: Tue, 14 Apr 2015 23:36:07 +0000 (+0300) Subject: Remove the GTK-based remote control program X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a9bbf8d37a2f94a720897fe4f0ab06a016779c69;p=r2c2.git Remove the GTK-based remote control program It's woefully outdated, and GTK is annoying to deploy to other operating systems. --- diff --git a/Build b/Build index 4aaaf76..8f0fb18 100644 --- a/Build +++ b/Build @@ -56,15 +56,6 @@ package "r2c2" use "r2c2_net"; }; - program "remote" - { - source "source/remote"; - require "gtkmm-2.4"; - require "mspnet"; - use "r2c2"; - use "r2c2_net"; - }; - program "serial" { source "source/serial"; diff --git a/source/remote/mainpanel.cpp b/source/remote/mainpanel.cpp deleted file mode 100644 index 705c402..0000000 --- a/source/remote/mainpanel.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "mainpanel.h" - -using namespace std; -using namespace R2C2; - -MainPanel::MainPanel(Remote &r, R2C2::Client &c): - remote(r), - client(c) -{ - client.signal_power_changed.connect(sigc::mem_fun(this, &MainPanel::power_changed)); - client.signal_halt_changed.connect(sigc::mem_fun(this, &MainPanel::halt_changed)); - client.signal_emergency.connect(sigc::mem_fun(this, &MainPanel::emergency)); - - Gtk::HBox *hbox = new Gtk::HBox(false, 5); - pack_start(*manage(hbox), false, true); - - hbox->pack_start(*manage(chk_power = new Gtk::CheckButton("Power")), false, true); - chk_power->signal_toggled().connect(sigc::mem_fun(this, &MainPanel::ui_power_changed)); - - hbox->pack_start(*manage(chk_halt = new Gtk::CheckButton("Halt")), false, true); - chk_halt->signal_toggled().connect(sigc::mem_fun(this, &MainPanel::ui_halt_changed)); - - pack_start(*manage(lbl_status = new Gtk::Label), false, true); - - show_all(); -} - -void MainPanel::power_changed(bool p) -{ - chk_power->set_active(p); -} - -void MainPanel::halt_changed(bool h) -{ - chk_halt->set_active(h); - if(!h) - lbl_status->set_text(string()); -} - -void MainPanel::emergency(const string &msg) -{ - lbl_status->set_text(msg); -} - -void MainPanel::ui_power_changed() -{ - client.set_power(chk_power->get_active()); -} - -void MainPanel::ui_halt_changed() -{ - client.set_halt(chk_halt->get_active()); -} diff --git a/source/remote/mainpanel.h b/source/remote/mainpanel.h deleted file mode 100644 index 6c156cf..0000000 --- a/source/remote/mainpanel.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef MAINPANEL_H_ -#define MAINPANEL_H_ - -#include -#include -#include -#include "network/client.h" - -class Remote; - -class MainPanel: public Gtk::VBox -{ -private: - Remote &remote; - R2C2::Client &client; - Gtk::CheckButton *chk_power; - Gtk::CheckButton *chk_halt; - Gtk::Label *lbl_status; - -public: - MainPanel(Remote &, R2C2::Client &); - -private: - void power_changed(bool); - void halt_changed(bool); - void emergency(const std::string &); - void ui_power_changed(); - void ui_halt_changed(); -}; - -#endif diff --git a/source/remote/remote.cpp b/source/remote/remote.cpp deleted file mode 100644 index dbcb7e4..0000000 --- a/source/remote/remote.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include -#include -#include -#include "mainpanel.h" -#include "remote.h" -#include "trainpanel.h" - -using namespace std; -using namespace Msp; - -Remote::Remote(int argc, char **argv): - client(catalogue), - gtk(argc, argv) -{ - if(argc<2) - throw usage_error("No address given"); - - DataFile::load(catalogue, "locos.dat"); - - client.use_event_dispatcher(event_disp); - client.signal_train_added.connect(sigc::mem_fun(this, &Remote::train_added)); - string addr_str = argv[1]; - if(addr_str.find(':')==string::npos) - addr_str += ":8315"; - Net::SockAddr *addr = Net::resolve(addr_str); - client.connect(*addr); - delete addr; - - window.signal_hide().connect(sigc::bind(sigc::mem_fun(this, &Remote::exit), 0)); - window.set_default_size(300, 200); - window.set_border_width(5); - - Gtk::ScrolledWindow *scroll = new Gtk::ScrolledWindow; - window.add(*manage(scroll)); - scroll->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); - - panel_box = new Gtk::VBox(false, 5); - scroll->add(*manage(panel_box)); - - main_panel = new MainPanel(*this, client); - panel_box->pack_start(*manage(main_panel), false, true); - - window.show_all(); -} - -void Remote::tick() -{ - event_disp.tick(Time::zero); - gtk.iteration(false); -} - -void Remote::train_added(R2C2::NetTrain &t) -{ - Gtk::HSeparator *sep = new Gtk::HSeparator; - panel_box->pack_start(*manage(sep), false, true); - sep->show(); - - TrainPanel *panel = new TrainPanel(*this, client, t); - panel_box->pack_start(*manage(panel), false, true); - train_panels.push_back(panel); -} diff --git a/source/remote/remote.h b/source/remote/remote.h deleted file mode 100644 index 875f25b..0000000 --- a/source/remote/remote.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef REMOTE_H_ -#define REMOTE_H_ - -#include -#include -#include -#include -#include "network/client.h" - -class MainPanel; -class TrainPanel; - -class Remote: public Msp::RegisteredApplication -{ -private: - Msp::IO::EventDispatcher event_disp; - R2C2::Catalogue catalogue; - R2C2::Client client; - Gtk::Main gtk; - Gtk::Window window; - Gtk::Box *panel_box; - MainPanel *main_panel; - std::vector train_panels; - -public: - Remote(int argc, char **argv); - - const R2C2::Catalogue &get_catalogue() const { return catalogue; } -private: - void tick(); - - void train_added(R2C2::NetTrain &); -}; - -#endif diff --git a/source/remote/trainpanel.cpp b/source/remote/trainpanel.cpp deleted file mode 100644 index 26963a0..0000000 --- a/source/remote/trainpanel.cpp +++ /dev/null @@ -1,139 +0,0 @@ -#include -#include -#include "remote.h" -#include "trainpanel.h" - -using namespace std; - -TrainPanel::TrainPanel(Remote &r, R2C2::Client &c, R2C2::NetTrain &t): - remote(r), - client(c), - train(t) -{ - train.signal_name_changed.connect(sigc::mem_fun(this, &TrainPanel::name_changed)); - train.signal_control_changed.connect(sigc::mem_fun(this, &TrainPanel::control_changed)); - train.signal_function_changed.connect(sigc::mem_fun(this, &TrainPanel::function_changed)); - train.signal_route_changed.connect(sigc::mem_fun(this, &TrainPanel::route_changed)); - train.signal_status_changed.connect(sigc::mem_fun(this, &TrainPanel::status_changed)); - - set_label(train.get_name()); - - Gtk::VBox *vbox = new Gtk::VBox(false, 5); - add(*manage(vbox)); - vbox->set_border_width(5); - - Gtk::HBox *hbox = new Gtk::HBox(false, 5); - vbox->add(*manage(hbox)); - - hbox->pack_start(*manage(scl_speed = new Gtk::HScale), true, true); - scl_speed->set_digits(0); - scl_speed->set_range(0, 200); - scl_speed->set_increments(5, 5); - scl_speed->set_size_request(210, -1); - scl_speed->signal_value_changed().connect(sigc::mem_fun(this, &TrainPanel::ui_speed_changed)); - - hbox->pack_start(*manage(chk_reverse = new Gtk::CheckButton("Rev")), false, true); - chk_reverse->signal_toggled().connect(sigc::mem_fun(this, &TrainPanel::ui_reverse_changed)); - - Gtk::HBox *func_box = new Gtk::HBox(false, 5); - vbox->add(*manage(func_box)); - const R2C2::VehicleType::FunctionMap &funcs = train.get_loco_type().get_functions(); - for(R2C2::VehicleType::FunctionMap::const_iterator i=funcs.begin(); i!=funcs.end(); ++i) - { - Gtk::CheckButton *&chk = chk_funcs[i->first]; - chk = new Gtk::CheckButton(i->second); - func_box->pack_start(*manage(chk), false, true); - chk->signal_toggled().connect(sigc::bind(sigc::mem_fun(this, &TrainPanel::ui_function_changed), i->first)); - } - - Glib::RefPtr route_store = Gtk::ListStore::create(route_columns); - vbox->add(*manage(cmb_route = new Gtk::ComboBox(static_cast &>(route_store)))); - cmb_route->pack_start(route_columns.name); - route_store->append(); - const list &routes = client.get_routes(); - for(list::const_iterator i=routes.begin(); i!=routes.end(); ++i) - { - Gtk::TreeIter iter = route_store->append(); - (*iter)[route_columns.name] = *i; - } - cmb_route->signal_changed().connect(sigc::mem_fun(this, &TrainPanel::ui_route_changed)); - - vbox->add(*manage(lbl_status = new Gtk::Label)); - - show_all(); -} - -void TrainPanel::name_changed(const string &name) -{ - set_label(name); -} - -void TrainPanel::status_changed(const string &status) -{ - lbl_status->set_text(status); -} - -void TrainPanel::control_changed(const string &control, float value) -{ - if(control=="speed") - { - // XXX It would be better to make the VehicleType give us the catalogue - scl_speed->set_value(value*3.6/remote.get_catalogue().get_scale()); - } - else if(control=="reverse") - chk_reverse->set_active(value); -} - -void TrainPanel::function_changed(unsigned func, bool set) -{ - std::map::iterator i = chk_funcs.find(func); - if(i!=chk_funcs.end()) - i->second->set_active(set); -} - -void TrainPanel::route_changed(const string &route) -{ - Gtk::TreeNodeChildren children = cmb_route->get_model()->children(); - for(Gtk::TreeIter i=children.begin(); i!=children.end(); ++i) - if((*i)[route_columns.name]==route) - { - cmb_route->set_active(i); - break; - } -} - -void TrainPanel::ui_speed_changed() -{ - float speed = scl_speed->get_value()/3.6*remote.get_catalogue().get_scale(); - train.set_control("speed", speed); -} - -void TrainPanel::ui_reverse_changed() -{ - if(train.get_control("speed")) - { - train.set_control("speed", 0); - chk_reverse->set_active(train.get_control("reverse")); - } - else - train.set_control("reverse", chk_reverse->get_active()); -} - -void TrainPanel::ui_function_changed(unsigned func) -{ - std::map::iterator i = chk_funcs.find(func); - if(i!=chk_funcs.end()) - train.set_function(func, i->second->get_active()); -} - -void TrainPanel::ui_route_changed() -{ - Gtk::TreeIter iter = cmb_route->get_active(); - train.set_route(Glib::ustring((*iter)[route_columns.name])); -} - - -TrainPanel::RouteRecord::RouteRecord() -{ - add(name); -} diff --git a/source/remote/trainpanel.h b/source/remote/trainpanel.h deleted file mode 100644 index 1cf7151..0000000 --- a/source/remote/trainpanel.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef TRAINPANEL_H_ -#define TRAINPANEL_H_ - -#include -#include -#include -#include -#include -#include "network/client.h" -#include "network/train.h" - -class Remote; - -class TrainPanel: public Gtk::Expander -{ -private: - struct RouteRecord: public Gtk::TreeModelColumnRecord - { - Gtk::TreeModelColumn name; - - RouteRecord(); - }; - - Remote &remote; - R2C2::Client &client; - R2C2::NetTrain &train; - Gtk::Scale *scl_speed; - Gtk::Label *lbl_status; - Gtk::CheckButton *chk_reverse; - RouteRecord route_columns; - Gtk::ComboBox *cmb_route; - std::map chk_funcs; - -public: - TrainPanel(Remote &, R2C2::Client &, R2C2::NetTrain &); -private: - void name_changed(const std::string &); - void status_changed(const std::string &); - void control_changed(const std::string &, float); - void function_changed(unsigned, bool); - void route_changed(const std::string &); - void ui_speed_changed(); - void ui_reverse_changed(); - void ui_function_changed(unsigned); - void ui_route_changed(); -}; - -#endif