]> git.tdb.fi Git - r2c2.git/commitdiff
Export routes over network
authorMikko Rasa <tdb@tdb.fi>
Sun, 13 Dec 2009 18:14:52 +0000 (18:14 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sun, 13 Dec 2009 18:14:52 +0000 (18:14 +0000)
Implement the reverse field in TrainSpeedPacket
Derive the TrainPanel in remote from Expander for a more compact train list
Set default size for the remote controller window
Catch exceptions caused by packets sent by a client

17 files changed:
source/engineer/trainpanel.cpp
source/engineer/trainpanel.h
source/libmarklin/layout.cpp
source/libmarklin/layout.h
source/libmarklin/trafficmanager.h
source/network/client.cpp
source/network/client.h
source/network/packets.h
source/network/protocol.cpp
source/network/server.cpp
source/network/server.h
source/network/train.cpp
source/network/train.h
source/remote/remote.cpp
source/remote/remote.h
source/remote/trainpanel.cpp
source/remote/trainpanel.h

index d462b5139c85f192d7bf747523c3b4e40fca1cdd..250b283c23990ead07f5e8114f3f057f7d39e567 100644 (file)
@@ -50,6 +50,7 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t):
        tgl_forward->set_geometry(GLtk::Geometry(geom.w-30, geom.h-59, 20, 27));
        tgl_forward->set_value(!train.get_locomotive().get_reverse());
        tgl_forward->signal_toggled.connect(sigc::mem_fun(this, &TrainPanel::forward_toggled));
+       train.get_locomotive().signal_reverse_changed.connect(sigc::mem_fun(this, &TrainPanel::train_reverse_changed));
 
        add(*(lbl_route=new GLtk::Label(res, "Free run")));
        lbl_route->set_style("digital");
@@ -107,6 +108,11 @@ void TrainPanel::train_speed_changed(unsigned speed)
        sld_speed->set_value(speed);
 }
 
+void TrainPanel::train_reverse_changed(bool reverse)
+{
+       tgl_forward->set_value(!reverse);
+}
+
 void TrainPanel::loco_function_changed(unsigned func, bool value)
 {
        map<unsigned, GLtk::Toggle *>::iterator i = tgl_funcs.find(func);
index aae71f98431f0f49d50d06e6f6e64d158c3d4233..a76d907a1af33bcb994e365dafbc8a6e8e411b14 100644 (file)
@@ -36,6 +36,7 @@ public:
 private:
        void speed_slider_changed(double);
        void train_speed_changed(unsigned);
+       void train_reverse_changed(bool);
        void loco_function_changed(unsigned, bool);
        void train_route_changed(const Marklin::Route *);
        void train_status_changed(const std::string &);
index 121e19e937a1366ec1c4afd259a36943f522edd1..67d646b1d5f542b1e5b156713c7ef79156660ba0 100644 (file)
@@ -45,6 +45,14 @@ void Layout::add_route(Route &r)
                signal_route_added.emit(r);
 }
 
+Route &Layout::get_route(const string &name) const
+{
+       for(set<Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i)
+               if((*i)->get_name()==name)
+                       return **i;
+       throw KeyError("Unknown route", name);
+}
+
 void Layout::remove_route(Route &r)
 {
        if(routes.erase(&r))
index 2a1817f5e021616ba5929f293629c2d78baded51..8573a542c82db2ccaec1b4f94c827b9501a505e8 100644 (file)
@@ -53,6 +53,7 @@ public:
        void remove_track(Track &);
        void add_route(Route &);
        const std::set<Route *> &get_routes() const { return routes; }
+       Route &get_route(const std::string &) const;
        void remove_route(Route &);
        void save(const std::string &);
 private:
index b01860af5d4fb774069d9211bd51f4caaa0327dc..d4ea2b3c54010ffacecde8939cb61b2bce610a47 100644 (file)
@@ -43,6 +43,7 @@ public:
        ~TrafficManager();
 
        Control &get_control() const { return control; }
+       Layout &get_layout() const { return layout; }
        const std::list<Block *> &get_blocks() const { return blocks; }
        Block &get_block_by_track(const Track &) const;
        const std::list<Train *> &get_trains() const { return trains; }
index 4eb4b25f5aefdd81498cd06a66b78925426b03f8..8e31cfe54c59b9cfe5e501722b31c112e36ea3c7 100644 (file)
@@ -73,4 +73,14 @@ void Client::receive(const TrainStatusPacket &pkt)
        get_train(pkt.address).process_packet(pkt);
 }
 
+void Client::receive(const RouteInfoPacket &pkt)
+{
+       routes.push_back(pkt.name);
+}
+
+void Client::receive(const TrainRoutePacket &pkt)
+{
+       get_train(pkt.address).process_packet(pkt);
+}
+
 } // namespace Marklin
index ce8dcb66fc15cdb681157b57d3b5e50b968741fc..3a9cbc0717a659cc042e8874b6333d5f099b0f89 100644 (file)
@@ -20,7 +20,9 @@ namespace Marklin {
 class Client: public Msp::Net::PacketReceiver<TrainInfoPacket>,
        Msp::Net::PacketReceiver<TrainSpeedPacket>,
        Msp::Net::PacketReceiver<TrainFunctionPacket>,
-       Msp::Net::PacketReceiver<TrainStatusPacket>
+       Msp::Net::PacketReceiver<TrainStatusPacket>,
+       Msp::Net::PacketReceiver<RouteInfoPacket>,
+       Msp::Net::PacketReceiver<TrainRoutePacket>
 {
 public:
        sigc::signal<void, NetTrain &> signal_train_added;
@@ -31,6 +33,7 @@ private:
        Msp::Net::StreamSocket *socket;
        Msp::Net::Communicator *comm;
        Msp::IO::EventDispatcher *event_disp;
+       std::list<std::string> routes;
        std::map<unsigned, NetTrain *> trains;
 
 public:
@@ -45,6 +48,7 @@ public:
        { if(comm) comm->send(pkt); }
 
        const Catalogue &get_catalogue() const { return catalogue; }
+       const std::list<std::string> &get_routes() const { return routes; }
        NetTrain &get_train(unsigned);
 
 private:
@@ -52,6 +56,8 @@ private:
        virtual void receive(const TrainSpeedPacket &);
        virtual void receive(const TrainFunctionPacket &);
        virtual void receive(const TrainStatusPacket &);
+       virtual void receive(const RouteInfoPacket &);
+       virtual void receive(const TrainRoutePacket &);
 };
 
 } // namespace Marklin
index d6efafc666d4cf49d746f27ec3a985654a61ee2b..31fd56d11350ff8390585cdfa7c97745956b1319 100644 (file)
@@ -38,6 +38,22 @@ struct TrainStatusPacket
        std::string status;
 };
 
+struct RouteInfoPacket
+{
+       std::string name;
+};
+
+struct TrainRoutePacket
+{
+       unsigned address;
+       std::string route;
+};
+
+struct ErrorPacket
+{
+       std::string message;
+};
+
 } // namespace Marklin
 
 #endif
index 5801d375eb2c99a769eacd8f2c8a4483a6ab86af..f8e13beb4ac5f4156780a415d9b24cecfd7be2fb 100644 (file)
@@ -20,6 +20,10 @@ Protocol::Protocol()
                (&TrainFunctionPacket::functions);
        add<TrainStatusPacket>() (&TrainStatusPacket::address)
                (&TrainStatusPacket::status);
+       add<RouteInfoPacket>() (&RouteInfoPacket::name);
+       add<TrainRoutePacket>() (&TrainRoutePacket::address)
+               (&TrainRoutePacket::route);
+       add<ErrorPacket>() (&ErrorPacket::message);
 }
 
 } // namespace Marklin
index 17142f8dcdaeacf5340e710ff8258c00773846ae..cd52b48502b1e5345a9a749e7a36c024f978940d 100644 (file)
@@ -7,8 +7,10 @@ Distributed under the GPL
 
 #include <msp/net/inet.h>
 #include "libmarklin/control.h"
+#include "libmarklin/layout.h"
 #include "libmarklin/locomotive.h"
 #include "libmarklin/locotype.h"
+#include "libmarklin/route.h"
 #include "server.h"
 
 using namespace std;
@@ -23,12 +25,7 @@ Server::Server(TrafficManager &tm):
 {
        const list<Train *> &trains = trfc_mgr.get_trains();
        for(list<Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
-       {
-               Locomotive &loco = (*i)->get_locomotive();
-               (*i)->signal_target_speed_changed.connect(sigc::bind<0>(sigc::mem_fun(this, &Server::train_speed_changed), sigc::ref(**i)));
-               loco.signal_function_changed.connect(sigc::bind<0>(sigc::mem_fun(this, &Server::train_function_changed), sigc::ref(**i)));
-               (*i)->signal_status_changed.connect(sigc::bind<0>(sigc::mem_fun(this, &Server::train_status_changed), sigc::ref(**i)));
-       }
+               train_added(**i);
 
        listen_sock.listen(Net::InetAddr(0, 8315), 4);
        listen_sock.signal_data_available.connect(sigc::mem_fun(this, &Server::incoming_connection));
@@ -52,7 +49,9 @@ void Server::train_added(Train &train)
 {
        Locomotive &loco = train.get_locomotive();
        train.signal_target_speed_changed.connect(sigc::bind<0>(sigc::mem_fun(this, &Server::train_speed_changed), sigc::ref(train)));
+       loco.signal_reverse_changed.connect(sigc::bind<0>(sigc::mem_fun(this, &Server::train_reverse_changed), sigc::ref(train)));
        loco.signal_function_changed.connect(sigc::bind<0>(sigc::mem_fun(this, &Server::train_function_changed), sigc::ref(train)));
+       train.signal_route_changed.connect(sigc::bind<0>(sigc::mem_fun(this, &Server::train_route_changed), sigc::ref(train)));
        train.signal_status_changed.connect(sigc::bind<0>(sigc::mem_fun(this, &Server::train_status_changed), sigc::ref(train)));
 
        TrainInfoPacket pkt;
@@ -71,6 +70,15 @@ void Server::train_speed_changed(const Train &train, unsigned speed)
        send(pkt);
 }
 
+void Server::train_reverse_changed(const Train &train, bool reverse)
+{
+       TrainSpeedPacket pkt;
+       pkt.address = train.get_locomotive().get_address();
+       pkt.speed = train.get_target_speed();
+       pkt.reverse = reverse;
+       send(pkt);
+}
+
 void Server::train_function_changed(const Train &train, unsigned, bool)
 {
        TrainFunctionPacket pkt;
@@ -79,6 +87,15 @@ void Server::train_function_changed(const Train &train, unsigned, bool)
        send(pkt);
 }
 
+void Server::train_route_changed(const Train &train, const Route *route)
+{
+       TrainRoutePacket pkt;
+       pkt.address = train.get_locomotive().get_address();
+       if(route)
+               pkt.route = route->get_name();
+       send(pkt);
+}
+
 void Server::train_status_changed(const Train &train, const string &status)
 {
        TrainStatusPacket pkt;
@@ -113,6 +130,14 @@ Server::Connection::~Connection()
 
 void Server::Connection::handshake_done()
 {
+       const set<Route *> &routes = server.trfc_mgr.get_layout().get_routes();
+       for(set<Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i)
+       {
+               RouteInfoPacket pkt;
+               pkt.name = (*i)->get_name();
+               comm.send(pkt);
+       }
+
        const list<Train *> &trains = server.trfc_mgr.get_trains();
        for(list<Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
        {
@@ -144,6 +169,13 @@ void Server::Connection::handshake_done()
                        pkt.status = (*i)->get_status();
                        comm.send(pkt);
                }
+               if((*i)->get_route())
+               {
+                       TrainRoutePacket pkt;
+                       pkt.address = loco.get_address();
+                       pkt.route = (*i)->get_route()->get_name();
+                       comm.send(pkt);
+               }
        }
 }
 
@@ -155,20 +187,61 @@ void Server::Connection::end_of_file()
 
 void Server::Connection::receive(const TrainSpeedPacket &pkt)
 {
-       Locomotive &loco = server.trfc_mgr.get_control().get_locomotive(pkt.address);
-       Train &train = server.trfc_mgr.get_train_by_locomotive(loco);
-       if(pkt.reverse!=loco.get_reverse())
-               train.set_reverse(pkt.reverse);
-       else
-               train.set_speed(pkt.speed);
+       try
+       {
+               Locomotive &loco = server.trfc_mgr.get_control().get_locomotive(pkt.address);
+               Train &train = server.trfc_mgr.get_train_by_locomotive(loco);
+               if(pkt.reverse!=loco.get_reverse())
+                       train.set_reverse(pkt.reverse);
+               else
+                       train.set_speed(pkt.speed);
+       }
+       catch(const Exception &e)
+       {
+               error(e.what());
+       }
 }
 
 void Server::Connection::receive(const TrainFunctionPacket &pkt)
 {
-       Locomotive &loco = server.trfc_mgr.get_control().get_locomotive(pkt.address);
-       for(unsigned i=0; i<9; ++i)
-               if(((pkt.functions^loco.get_functions())>>i)&1)
-                       loco.set_function(i, (pkt.functions>>i)&1);
+       try
+       {
+               Locomotive &loco = server.trfc_mgr.get_control().get_locomotive(pkt.address);
+               for(unsigned i=0; i<9; ++i)
+                       if(((pkt.functions^loco.get_functions())>>i)&1)
+                               loco.set_function(i, (pkt.functions>>i)&1);
+       }
+       catch(const Exception &e)
+       {
+               error(e.what());
+       }
+}
+
+void Server::Connection::receive(const TrainRoutePacket &pkt)
+{
+       try
+       {
+               Locomotive &loco = server.trfc_mgr.get_control().get_locomotive(pkt.address);
+               Train &train = server.trfc_mgr.get_train_by_locomotive(loco);
+               if(pkt.route.empty())
+                       train.set_route(0);
+               else
+               {
+                       Route &route = server.trfc_mgr.get_layout().get_route(pkt.route);
+                       train.set_route(&route);
+               }
+       }
+       catch(const Exception &e)
+       {
+               error(e.what());
+       }
+}
+
+void Server::Connection::error(const string &msg)
+{
+       ErrorPacket pkt;
+       pkt.message = msg;
+       comm.send(pkt);
 }
 
 } // namespace Marklin
index 6ce965e555d05009c66fbd35c9b89e886c859d67..7c3dce959c300e9fbb1226e3797b0bd02b60cdd2 100644 (file)
@@ -22,7 +22,8 @@ class Server
 {
 private:
        struct Connection: private Msp::Net::PacketReceiver<TrainSpeedPacket>,
-               private Msp::Net::PacketReceiver<TrainFunctionPacket>
+               private Msp::Net::PacketReceiver<TrainFunctionPacket>,
+               private Msp::Net::PacketReceiver<TrainRoutePacket>
        {
                Server &server;
                Msp::Net::StreamSocket *socket;
@@ -36,6 +37,8 @@ private:
                void end_of_file();
                virtual void receive(const TrainSpeedPacket &);
                virtual void receive(const TrainFunctionPacket &);
+               virtual void receive(const TrainRoutePacket &);
+               void error(const std::string &);
        };
 
        Protocol proto;
@@ -52,7 +55,9 @@ private:
 
        void train_added(Train &);
        void train_speed_changed(const Train &, unsigned);
+       void train_reverse_changed(const Train &, bool);
        void train_function_changed(const Train &, unsigned, bool);
+       void train_route_changed(const Train &, const Route *);
        void train_status_changed(const Train &, const std::string &);
 
        template<typename P>
index 468b2200a0aa7d97dfd9e9724169a89e1b348da6..025dcf52a75268b1dcdaa6b40c3cdc41d2a84d9b 100644 (file)
@@ -58,6 +58,17 @@ void NetTrain::set_function(unsigned i, bool set)
        client.send(pkt);
 }
 
+void NetTrain::set_route(const string &r)
+{
+       if(r==route)
+               return;
+
+       TrainRoutePacket pkt;
+       pkt.address = address;
+       pkt.route = r;
+       client.send(pkt);
+}
+
 void NetTrain::process_packet(const TrainSpeedPacket &pkt)
 {
        if(pkt.speed!=speed)
@@ -87,4 +98,10 @@ void NetTrain::process_packet(const TrainStatusPacket &pkt)
        signal_status_changed.emit(status);
 }
 
+void NetTrain::process_packet(const TrainRoutePacket &pkt)
+{
+       route = pkt.route;
+       signal_route_changed.emit(route);
+}
+
 } // namespace Marklin
index 57154a04e7245dd997990ee1fa79c9da520c037b..0a6a8a8f9063700dadf6bdb1d26c8f6eda835fbf 100644 (file)
@@ -23,6 +23,7 @@ public:
        sigc::signal<void, unsigned> signal_speed_changed;
        sigc::signal<void, bool> signal_reverse_changed;
        sigc::signal<void, unsigned, bool> signal_function_changed;
+       sigc::signal<void, const std::string &> signal_route_changed;
        sigc::signal<void, const std::string &> signal_status_changed;
 
 private:
@@ -33,6 +34,7 @@ private:
        unsigned speed;
        bool reverse;
        unsigned functions;
+       std::string route;
        std::string status;
 
 public:
@@ -47,9 +49,12 @@ public:
        bool get_reverse() const { return reverse; }
        void set_function(unsigned, bool);
        bool get_function(unsigned i) const { return (functions>>i)&1; }
+       void set_route(const std::string &);
+       const std::string &get_route() const { return route; }
 
        void process_packet(const TrainSpeedPacket &);
        void process_packet(const TrainFunctionPacket &);
+       void process_packet(const TrainRoutePacket &);
        void process_packet(const TrainStatusPacket &);
 };
 
index 57080c1fd0897ea86ea0527cf974a42f8b836d5d..c6afc6de537e0ab4fe7d3d4ffb75970fc69af24f 100644 (file)
@@ -5,6 +5,7 @@ Copyright © 2009  Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
+#include <gtkmm/separator.h>
 #include <msp/net/resolve.h>
 #include <msp/time/units.h>
 #include "remote.h"
@@ -34,9 +35,12 @@ Remote::Remote(int argc, char **argv):
        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);
+
        train_box = new Gtk::VBox(false, 5);
        window.add(*manage(train_box));
+
        window.show_all();
 }
 
@@ -48,6 +52,13 @@ void Remote::tick()
 
 void Remote::train_added(Marklin::NetTrain &t)
 {
-       TrainPanel *panel = new TrainPanel(t);
-       train_box->add(*manage(panel));
+       TrainPanel *panel = new TrainPanel(client, t);
+       if(!train_panels.empty())
+       {
+               Gtk::HSeparator *sep = new Gtk::HSeparator;
+               train_box->pack_start(*manage(sep), false, true);
+               sep->show();
+       }
+       train_box->pack_start(*manage(panel), false, true);
+       train_panels.push_back(panel);
 }
index 4599a139af32989b2c0c4212168c8d15694cac29..a4bfc428e7ed467797e90b59414ded97baf2a367 100644 (file)
@@ -14,6 +14,8 @@ Distributed under the GPL
 #include <msp/core/application.h>
 #include "network/client.h"
 
+class TrainPanel;
+
 class Remote: public Msp::Application
 {
 private:
@@ -23,6 +25,7 @@ private:
        Gtk::Main gtk;
        Gtk::Window window;
        Gtk::Box *train_box;
+       std::vector<TrainPanel *> train_panels;
 
        static Msp::Application::RegApp<Remote> reg;
 
index e3db1badb3cfcd0c5451216c5497daf09ef7110c..ce46fa19dffaa86634df6553609c8a28f086878e 100644 (file)
@@ -6,17 +6,21 @@ Distributed under the GPL
 */
 
 #include <gtkmm/box.h>
+#include <gtkmm/liststore.h>
 #include "libmarklin/locotype.h"
 #include "trainpanel.h"
 
 using namespace std;
 
-TrainPanel::TrainPanel(Marklin::NetTrain &t):
+TrainPanel::TrainPanel(Marklin::Client &c, Marklin::NetTrain &t):
+       client(c),
        train(t)
 {
        train.signal_name_changed.connect(sigc::mem_fun(this, &TrainPanel::name_changed));
        train.signal_speed_changed.connect(sigc::mem_fun(this, &TrainPanel::speed_changed));
+       train.signal_reverse_changed.connect(sigc::mem_fun(this, &TrainPanel::reverse_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());
@@ -25,13 +29,19 @@ TrainPanel::TrainPanel(Marklin::NetTrain &t):
        add(*manage(vbox));
        vbox->set_border_width(5);
 
-       vbox->add(*manage(scl_speed = new Gtk::HScale));
+       Gtk::HBox *hbox = new Gtk::HBox(false, 5);
+       vbox->add(*manage(hbox));
+
+       hbox->add(*manage(scl_speed = new Gtk::HScale));
        scl_speed->set_digits(0);
        scl_speed->set_range(0, 14);
        scl_speed->set_increments(1, 1);
-       scl_speed->set_size_request(280, -1);
+       scl_speed->set_size_request(210, -1);
        scl_speed->signal_value_changed().connect(sigc::mem_fun(this, &TrainPanel::ui_speed_changed));
 
+       hbox->add(*manage(chk_reverse = new Gtk::CheckButton("Rev")));
+       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 std::map<unsigned, string> &funcs = train.get_loco_type().get_functions();
@@ -43,6 +53,18 @@ TrainPanel::TrainPanel(Marklin::NetTrain &t):
                chk->signal_toggled().connect(sigc::bind(sigc::mem_fun(this, &TrainPanel::ui_function_changed), i->first));
        }
 
+       Glib::RefPtr<Gtk::ListStore> route_store = Gtk::ListStore::create(route_columns);
+       vbox->add(*manage(cmb_route = new Gtk::ComboBox(route_store)));
+       cmb_route->pack_start(route_columns.name);
+       route_store->append();
+       const list<string> &routes = client.get_routes();
+       for(list<string>::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();
@@ -63,6 +85,11 @@ void TrainPanel::speed_changed(unsigned speed)
        scl_speed->set_value(speed);
 }
 
+void TrainPanel::reverse_changed(bool rev)
+{
+       chk_reverse->set_active(rev);
+}
+
 void TrainPanel::function_changed(unsigned func, bool set)
 {
        std::map<unsigned, Gtk::CheckButton *>::iterator i = chk_funcs.find(func);
@@ -70,14 +97,42 @@ void TrainPanel::function_changed(unsigned func, bool set)
                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()
 {
        train.set_speed(static_cast<unsigned>(scl_speed->get_value()));
 }
 
+void TrainPanel::ui_reverse_changed()
+{
+       train.set_reverse(chk_reverse->get_active());
+}
+
 void TrainPanel::ui_function_changed(unsigned func)
 {
        std::map<unsigned, Gtk::CheckButton *>::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);
+}
index 2dcd095b593b403ae37576743be4c136e9a90be2..b969af406d2becef314f48b114823882801d4f3d 100644 (file)
@@ -9,28 +9,45 @@ Distributed under the GPL
 #define TRAINPANEL_H_
 
 #include <gtkmm/checkbutton.h>
-#include <gtkmm/frame.h>
+#include <gtkmm/combobox.h>
+#include <gtkmm/expander.h>
 #include <gtkmm/label.h>
 #include <gtkmm/scale.h>
+#include "network/client.h"
 #include "network/train.h"
 
-class TrainPanel: public Gtk::Frame
+class TrainPanel: public Gtk::Expander
 {
 private:
+       struct RouteRecord: public Gtk::TreeModelColumnRecord
+       {
+               Gtk::TreeModelColumn<Glib::ustring> name;
+
+               RouteRecord();
+       };
+
+       Marklin::Client &client;
        Marklin::NetTrain &train;
        Gtk::Scale *scl_speed;
        Gtk::Label *lbl_status;
+       Gtk::CheckButton *chk_reverse;
+       RouteRecord route_columns;
+       Gtk::ComboBox *cmb_route;
        std::map<unsigned, Gtk::CheckButton *> chk_funcs;
 
 public:
-       TrainPanel(Marklin::NetTrain &);
+       TrainPanel(Marklin::Client &, Marklin::NetTrain &);
 private:
        void name_changed(const std::string &);
        void status_changed(const std::string &);
        void speed_changed(unsigned);
+       void reverse_changed(bool);
        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