#include "3d/vehicle.h"
#include "engineer.h"
#include "mainwindow.h"
+#include "newtraindialog.h"
#include "traindialog.h"
#include "trainview.h"
keyboard(window),
mouse(window),
ui_res("r2c2.res"),
+ import_active(false),
layout(catalogue, (options.driver.empty() ? 0 : Driver::create(options.driver))),
layout_3d(layout),
server(0),
DataFile::load(catalogue, "wagons.dat");
DataFile::load(layout, options.layout_fn);
+ if(layout.has_driver())
+ layout.get_driver().signal_locomotive_detected.connect(sigc::mem_fun(this, &Engineer::locomotive_detected));
layout.signal_train_added.connect(sigc::mem_fun(this, &Engineer::train_added));
layout.signal_emergency.connect(sigc::mem_fun(this, &Engineer::set_status));
const set<Block *> &blocks = layout.get_all<Block>();
return layout.pick<Track>(Ray(start, Vector(ray)));
}
+void Engineer::locomotive_detected(const Driver::DetectedLocomotive &loco)
+{
+ if(!import_active)
+ {
+ NewTrainDialog *dlg = new NewTrainDialog(*this);
+ dlg->prefill(loco);
+ dlg->signal_response.connect(sigc::mem_fun(this, &Engineer::import_finished));
+ root->add(*dlg);
+ import_active = true;
+ }
+}
+
+void Engineer::import_finished(int)
+{
+ import_active = false;
+}
+
void Engineer::process_new_train(Train &train)
{
Vehicle3D &loco3d = layout_3d.get_3d(train.get_vehicle(0));
#include <msp/gltk/resources.h>
#include <msp/gltk/root.h>
#include "libr2c2/catalogue.h"
+#include "libr2c2/driver.h"
#include "libr2c2/train.h"
#include "3d/layout.h"
#include "3d/overlay.h"
Msp::GLtk::Resources ui_res;
Msp::GLtk::Root *root;
Msp::GLtk::Arrangement *root_arrangement;
+ bool import_active;
R2C2::Catalogue catalogue;
R2C2::Layout layout;
void sensor_event(unsigned, bool);
void block_reserved(const R2C2::Block &, const R2C2::Train *);
R2C2::Object *pick_object(const R2C2::Vector &);
+ void locomotive_detected(const R2C2::Driver::DetectedLocomotive &);
+ void import_finished(int);
void train_added(R2C2::Train &);
void process_new_train(R2C2::Train &);
virtual void sighandler(int);
};
+class DetectedLocoItem: public GLtk::List::MultiColumnItem
+{
+public:
+ typedef const Driver::DetectedLocomotive *ValueType;
+
+ DetectedLocoItem(ValueType);
+};
+
+
TrainListDialog::TrainListDialog(Engineer &e):
engineer(e),
layout(engineer.get_layout())
lst_trains->set_data(trains);
lst_trains->set_item_type<TrainItem>();
+ lst_imported = dynamic_cast<GLtk::List *>(get_item(widgets, "lst_imported"));
+ lst_imported->set_data(detected_locos);
+ lst_imported->set_item_type<DetectedLocoItem>();
+
+ dynamic_cast<GLtk::Toggle *>(get_item(widgets, "tgl_trains"))->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &TrainListDialog::tab_toggled), lst_trains));
+ dynamic_cast<GLtk::Toggle *>(get_item(widgets, "tgl_import"))->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &TrainListDialog::tab_toggled), lst_imported));
+
dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_new"))->signal_clicked.connect(sigc::mem_fun(this, &TrainListDialog::new_clicked));
dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_show"))->signal_clicked.connect(sigc::mem_fun(this, &TrainListDialog::show_clicked));
i->second->signal_name_changed.connect(sigc::hide(sigc::bind(sigc::mem_fun(this, &TrainListDialog::train_name_changed), sigc::ref(*i->second))));
}
+ if(layout.has_driver())
+ {
+ Driver &driver = layout.get_driver();
+ driver.signal_locomotive_detected.connect(sigc::mem_fun(this, &TrainListDialog::locomotive_detected));
+ driver.signal_locomotive_gone.connect(sigc::mem_fun(this, &TrainListDialog::locomotive_gone));
+ }
layout.signal_train_added.connect(sigc::mem_fun(this, &TrainListDialog::train_added));
layout.signal_train_removed.connect(sigc::mem_fun(this, &TrainListDialog::train_removed));
}
void TrainListDialog::new_clicked()
{
NewTrainDialog *dlg = new NewTrainDialog(engineer);
+ if(lst_imported->is_visible())
+ {
+ int selected = lst_imported->get_selected_index();
+ if(selected>=0)
+ dlg->prefill(*detected_locos.get(selected));
+ }
find_ancestor<GLtk::Root>()->add(*dlg);
dlg->autosize();
}
}
}
+void TrainListDialog::tab_toggled(bool value, GLtk::Widget *wdg)
+{
+ wdg->set_visible(value);
+}
+
+void TrainListDialog::locomotive_detected(const Driver::DetectedLocomotive &loco)
+{
+ detected_locos.append(&loco);
+}
+
+void TrainListDialog::locomotive_gone(const Driver::DetectedLocomotive &loco)
+{
+ int index = detected_locos.find(&loco);
+ if(index>=0)
+ detected_locos.remove(index);
+}
+
void TrainListDialog::train_added(Train &train)
{
unsigned n_items = trains.size();
add(*new GLtk::Label(train->get_name()));
}
+
+DetectedLocoItem::DetectedLocoItem(ValueType loco)
+{
+ add(*new GLtk::Label(loco->protocol));
+ add(*new GLtk::Label(lexical_cast<string>(loco->address)));
+ add(*new GLtk::Label(loco->name));
+}
R2C2::Layout &layout;
Msp::GLtk::BasicListData<R2C2::Train *> trains;
Msp::GLtk::List *lst_trains;
+ Msp::GLtk::BasicListData<const R2C2::Driver::DetectedLocomotive *> detected_locos;
+ Msp::GLtk::List *lst_imported;
public:
TrainListDialog(Engineer &);
private:
void new_clicked();
void show_clicked();
+ void tab_toggled(bool, Msp::GLtk::Widget *);
+ void locomotive_detected(const R2C2::Driver::DetectedLocomotive &);
+ void locomotive_gone(const R2C2::Driver::DetectedLocomotive &);
void train_added(R2C2::Train &);
void train_removed(R2C2::Train &);
void train_name_changed(R2C2::Train &);