-/* $Id$
-
-This file is part of the MSP Märklin suite
-Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
#include <msp/gltk/label.h>
-#include <msp/strings/formatter.h>
+#include <msp/strings/format.h>
#include <msp/strings/lexicalcast.h>
-#include "libmarklin/vehicle.h"
-#include "libmarklin/vehicletype.h"
+#include "libr2c2/driver.h"
+#include "libr2c2/vehicle.h"
+#include "libr2c2/vehicletype.h"
#include "engineer.h"
#include "trainproperties.h"
using namespace std;
using namespace Msp;
-using namespace Marklin;
+using namespace R2C2;
TrainProperties::TrainProperties(Engineer &e, Train *t):
engineer(e),
add(*(ent_addr = new GLtk::Entry));
ent_addr->set_geometry(GLtk::Geometry(10, geom.h-50, 40, 20));
+ add(*(drp_protocol = new GLtk::Dropdown));
+ drp_protocol->set_geometry(GLtk::Geometry(60, geom.h-50, 60, 20));
+ for(unsigned i=0;; ++i)
+ {
+ if(const char *proto = engineer.get_layout().get_driver().enumerate_protocols(i))
+ drp_protocol->append(proto);
+ else
+ break;
+ }
+ drp_protocol->set_selected_index(0);
+
add(*(drp_type = new GLtk::Dropdown));
- drp_type->set_geometry(GLtk::Geometry(60, geom.h-50, geom.w-70, 20));
+ drp_type->set_geometry(GLtk::Geometry(130, geom.h-50, geom.w-140, 20));
const Catalogue::VehicleMap &vehs = engineer.get_catalogue().get_vehicles();
unsigned n = 0;
if(train)
{
- ent_addr->set_text(lexical_cast(train->get_address()));
+ ent_addr->set_text(lexical_cast<string>(train->get_address()));
ent_name->set_text(train->get_name());
drp_priority->set_selected_index(train->get_priority()+2);
{
const VehicleType &type = get_vehicle_type(drp_type->get_selected_index(), true);
unsigned addr = lexical_cast<unsigned>(ent_addr->get_text());
- train = new Train(engineer.get_layout(), type, addr);
+ train = new Train(engineer.get_layout(), type, addr, drp_protocol->get_selected());
}
train->set_name(ent_name->get_text());
lst_vehicles->remove(selected);
- unsigned n_vehicles = train->get_n_vehicles()-rem_vehicles.size();
+ unsigned n_vehicles = (train ? train->get_n_vehicles()-rem_vehicles.size() : 0);
if(static_cast<unsigned>(selected)>=n_vehicles)
add_vehicles.erase(add_vehicles.begin()+(selected-n_vehicles));
else
++i;
}
- throw InvalidParameterValue("Vehicle type index out of range");
+ throw out_of_range("TrainProperties::get_vehicle_type");
}