layout.signal_track_added.connect(sigc::mem_fun(this, &Layout3D::track_added));
layout.signal_track_removed.connect(sigc::mem_fun(this, &Layout3D::track_removed));
layout.signal_vehicle_added.connect(sigc::mem_fun(this, &Layout3D::vehicle_added));
+ layout.signal_vehicle_removed.connect(sigc::mem_fun(this, &Layout3D::vehicle_removed));
const set<Track *> <racks = layout.get_tracks();
for(set<Track *>::iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
new Vehicle3D(*this, v);
}
+void Layout3D::vehicle_removed(Vehicle &v)
+{
+ VehicleMap::iterator i = vehicles.find(&v);
+ if(i!=vehicles.end())
+ delete i->second;
+}
+
} // namespace Marklin
engineer(e),
train(t)
{
- set_size(250, 275);
+ set_size(250, 305);
GLtk::Label *label;
add(*(label = new GLtk::Label(res, "Train properties")));
drp_priority->append("Express passenger");
add(*(lst_vehicles = new GLtk::List(res)));
- lst_vehicles->set_geometry(GLtk::Geometry(10, geom.h-205, geom.w-20, 100));
+ lst_vehicles->set_geometry(GLtk::Geometry(10, 100, geom.w-20, geom.h-205));
+
+ GLtk::Button *btn;
+
+ add(*(btn = new GLtk::Button(res, "Rem")));
+ btn->set_geometry(GLtk::Geometry(10, 70, 40, 25));
+ btn->signal_clicked.connect(sigc::mem_fun(this, &TrainProperties::remove_vehicle_clicked));
add(*(drp_new_vehicle = new GLtk::Dropdown(res)));
- drp_new_vehicle->set_geometry(GLtk::Geometry(10, geom.h-230, geom.w-20, 20));
+ drp_new_vehicle->set_geometry(GLtk::Geometry(10, 45, geom.w-20, 20));
drp_new_vehicle->append("(new vehicle)");
drp_new_vehicle->set_selected_index(0);
for(Catalogue::VehicleMap::const_iterator i=vehs.begin(); i!=vehs.end(); ++i)
train->set_name(ent_name->get_text());
train->set_priority(drp_priority->get_selected_index()-2);
+ // The locomotive is vehicle 0 so we need to add 1
+ for(set<unsigned>::const_iterator i=rem_vehicles.end(); i!=rem_vehicles.begin();)
+ train->remove_vehicle(*--i+1);
for(vector<const VehicleType *>::const_iterator i=add_vehicles.begin(); i!=add_vehicles.end(); ++i)
train->add_vehicle(**i);
}
drp_new_vehicle->set_selected_index(0);
}
+void TrainProperties::remove_vehicle_clicked()
+{
+ int selected = lst_vehicles->get_selected_index();
+ if(selected<0)
+ return;
+
+ lst_vehicles->remove(selected);
+
+ unsigned n_vehicles = train->get_n_vehicles()-rem_vehicles.size();
+ if(static_cast<unsigned>(selected)>=n_vehicles)
+ add_vehicles.erase(add_vehicles.begin()+(selected-n_vehicles));
+ else
+ {
+ for(set<unsigned>::const_iterator i=rem_vehicles.begin(); i!=rem_vehicles.end(); ++i)
+ if(*i<=static_cast<unsigned>(selected))
+ ++selected;
+ rem_vehicles.insert(selected);
+ }
+}
+
const VehicleType &TrainProperties::get_vehicle_type(unsigned n, bool loco)
{
const Catalogue::VehicleMap &vehs = engineer.get_catalogue().get_vehicles();
Msp::GLtk::List *lst_vehicles;
Msp::GLtk::Dropdown *drp_new_vehicle;
std::vector<const Marklin::VehicleType *> add_vehicles;
+ std::set<unsigned> rem_vehicles;
public:
TrainProperties(Engineer &, const Msp::GLtk::Resources &, Marklin::Train *);
private:
virtual void on_ok_clicked();
void new_vehicle_selected(unsigned, const std::string &);
+ void remove_vehicle_clicked();
const Marklin::VehicleType &get_vehicle_type(unsigned, bool);
};