3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2010 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>
12 #include "libmarklin/locotype.h"
14 #include "trainproperties.h"
18 using namespace Marklin;
20 TrainProperties::TrainProperties(Engineer &e, const GLtk::Resources &r, Train *t):
29 add(*(label=new GLtk::Label(res, "Train properties")));
30 label->set_geometry(GLtk::Geometry(10, geom.h-25, geom.w-20, 20));
32 add(*(ent_addr=new GLtk::Entry(res)));
33 ent_addr->set_geometry(GLtk::Geometry(10, geom.h-50, 40, 20));
35 add(*(drp_type=new GLtk::Dropdown(res)));
36 drp_type->set_geometry(GLtk::Geometry(60, geom.h-50, geom.w-70, 20));
38 const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
40 for(map<unsigned, LocoType *>::const_iterator i=locos.begin(); i!=locos.end(); ++i, ++n)
42 drp_type->append(format("%d %s", i->second->get_article_number(), i->second->get_name()));
43 if(train && i->second==&train->get_locomotive_type())
44 drp_type->set_selected_index(n);
47 add(*(ent_name=new GLtk::Entry(res)));
48 ent_name->set_geometry(GLtk::Geometry(10, geom.h-75, geom.w-20, 20));
52 ent_addr->set_text(lexical_cast(train->get_address()));
53 ent_name->set_text(train->get_name());
56 ent_name->set_text(format("Train %d", engineer.get_layout().get_trains().size()+1));
59 void TrainProperties::on_ok_clicked()
63 const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
64 map<unsigned, LocoType *>::const_iterator i = locos.begin();
65 advance(i, drp_type->get_selected_index());
67 unsigned addr = lexical_cast<unsigned>(ent_addr->get_text());
68 train = new Train(engineer.get_layout(), *i->second, addr);
71 train->set_name(ent_name->get_text());