/* $Id$
This file is part of the MSP Märklin suite
-Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
#include <msp/gltk/button.h>
#include <msp/strings/formatter.h>
-#include "libmarklin/locomotive.h"
+#include "libmarklin/locotype.h"
#include "engineer.h"
#include "routeselect.h"
#include "trainpanel.h"
{
set_size(200, 170);
- add(*(lbl_addr=new GLtk::Label(res, format("%2d", train.get_locomotive().get_address()))));
+ add(*(lbl_addr=new GLtk::Label(res, format("%2d", train.get_address()))));
lbl_addr->set_style("digital");
lbl_addr->set_geometry(GLtk::Geometry(10, geom.h-34, 35, 24));
lbl_name->set_geometry(GLtk::Geometry(45, geom.h-34, geom.w-55, 24));
train.signal_name_changed.connect(sigc::mem_fun(lbl_name, &GLtk::Label::set_text));
- add(*(lbl_speed=new GLtk::Label(res, format("%2d", train.get_locomotive().get_speed()))));
+ add(*(lbl_speed=new GLtk::Label(res, format("%2d", train.get_speed()))));
lbl_speed->set_style("digital");
lbl_speed->set_geometry(GLtk::Geometry(10, geom.h-58, 35, 24));
train.signal_target_speed_changed.connect(sigc::mem_fun(this, &TrainPanel::train_speed_changed));
add(*(tgl_forward=new GLtk::Toggle(res)));
tgl_forward->set_text("Fwd");
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->set_value(!train.get_reverse());
tgl_forward->signal_toggled.connect(sigc::mem_fun(this, &TrainPanel::forward_toggled));
+ train.signal_reverse_changed.connect(sigc::mem_fun(this, &TrainPanel::train_reverse_changed));
- add(*(lbl_route=new GLtk::Label(res, "Free run")));
+ const Route *route = train.get_route();
+ add(*(lbl_route=new GLtk::Label(res, (route ? route->get_name() : "Free run"))));
lbl_route->set_style("digital");
lbl_route->set_geometry(GLtk::Geometry(10, 58, geom.w-20, 24));
train.signal_route_changed.connect(sigc::mem_fun(this, &TrainPanel::train_route_changed));
lbl_status->set_geometry(GLtk::Geometry(10, 34, geom.w-20, 24));
train.signal_status_changed.connect(sigc::mem_fun(this, &TrainPanel::train_status_changed));
- const map<unsigned, string> &funcs = train.get_locomotive().get_type().get_functions();
+ const map<unsigned, string> &funcs = train.get_locomotive_type().get_functions();
unsigned x = 10;
- for(map<unsigned, string>::const_iterator i=funcs.begin(); i!=funcs.end(); ++i, x+=35)
+ for(map<unsigned, string>::const_iterator i=funcs.begin(); i!=funcs.end(); ++i, x+=36)
{
string fname = i->second;
fname[0] = toupper(fname[0]);
GLtk::Toggle *tgl;
add(*(tgl=new GLtk::Toggle(res)));
tgl->set_text(fname);
- tgl->set_geometry(GLtk::Geometry(x, geom.h-85, 35, 27));
- tgl->set_value(train.get_locomotive().get_function(i->first));
+ tgl->set_geometry(GLtk::Geometry(x, geom.h-85, 36, 27));
+ tgl->set_value(train.get_function(i->first));
tgl->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &TrainPanel::func_toggled), i->first));
tgl_funcs[i->first] = tgl;
}
- train.get_locomotive().signal_function_changed.connect(sigc::mem_fun(this, &TrainPanel::loco_function_changed));
+ train.signal_function_changed.connect(sigc::mem_fun(this, &TrainPanel::train_function_changed));
GLtk::Button *btn;
sld_speed->set_value(speed);
}
-void TrainPanel::loco_function_changed(unsigned func, bool value)
+void TrainPanel::train_reverse_changed(bool reverse)
+{
+ tgl_forward->set_value(!reverse);
+}
+
+void TrainPanel::train_function_changed(unsigned func, bool value)
{
map<unsigned, GLtk::Toggle *>::iterator i = tgl_funcs.find(func);
if(i!=tgl_funcs.end())
void TrainPanel::func_toggled(bool value, unsigned func)
{
- train.get_locomotive().set_function(func, value);
+ train.set_function(func, value);
}