3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/gltk/button.h>
9 #include <msp/gltk/label.h>
10 #include <msp/strings/formatter.h>
11 #include <msp/strings/lexicalcast.h>
13 #include "trainproperties.h"
17 using namespace Marklin;
19 TrainProperties::TrainProperties(Engineer &e, const GLtk::Resources &r, Train *t):
28 add(*(label=new GLtk::Label(res, "Train properties")));
29 label->set_geometry(GLtk::Geometry(10, geom.h-25, geom.w-20, 20));
31 add(*(ent_addr=new GLtk::Entry(res)));
32 ent_addr->set_geometry(GLtk::Geometry(10, geom.h-50, 40, 20));
34 add(*(drp_type=new GLtk::Dropdown(res)));
35 drp_type->set_geometry(GLtk::Geometry(60, geom.h-50, geom.w-70, 20));
37 const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
39 for(map<unsigned, LocoType *>::const_iterator i=locos.begin(); i!=locos.end(); ++i, ++n)
41 drp_type->append(format("%d %s", i->second->get_article_number(), i->second->get_name()));
42 if(train && i->second==&train->get_locomotive().get_type())
43 drp_type->set_selected_index(n);
46 add(*(ent_name=new GLtk::Entry(res)));
47 ent_name->set_geometry(GLtk::Geometry(10, geom.h-75, geom.w-20, 20));
51 ent_addr->set_text(lexical_cast(train->get_locomotive().get_address()));
52 ent_name->set_text(train->get_name());
55 ent_name->set_text(format("Train %d", engineer.get_traffic_manager().get_trains().size()+1));
58 void TrainProperties::on_ok_clicked()
62 const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
63 map<unsigned, LocoType *>::const_iterator i = locos.begin();
64 advance(i, drp_type->get_selected_index());
66 unsigned addr = lexical_cast<unsigned>(ent_addr->get_text());
67 Locomotive *loco = new Locomotive(*i->second, engineer.get_control(), addr);
68 train = new Train(engineer.get_traffic_manager(), *loco);
71 train->set_name(ent_name->get_text());