3 This file is part of the MSP Märklin suite
4 Copyright © 2009-2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/gltk/button.h>
9 #include <msp/strings/formatter.h>
10 #include "libmarklin/route.h"
16 using namespace Marklin;
18 Toolbar::Toolbar(Designer &d):
19 GLtk::Widget(d.get_ui_resources()),
20 GLtk::Panel(d.get_ui_resources()),
28 add(*(btn=new GLtk::Button(res, "Load")));
29 btn->set_geometry(GLtk::Geometry(5, 10, 40, 24));
30 btn->set_tooltip("Load layout (not implemented)");
32 add(*(btn=new GLtk::Button(res, "Save")));
33 btn->set_geometry(GLtk::Geometry(45, 10, 40, 24));
34 btn->set_tooltip("Save current layout");
35 btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::save));
37 add(*(btn=new GLtk::Button(res, "Quit")));
38 btn->set_geometry(GLtk::Geometry(85, 10, 40, 24));
39 btn->set_style("red");
40 btn->set_tooltip("Exit Designer");
41 btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::quit));
43 add(*(btn=new GLtk::Button(res, "NewT")));
44 btn->set_geometry(GLtk::Geometry(135, 10, 40, 24));
45 btn->set_tooltip("Add a track piece");
46 btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::new_track));
48 add(*(btn=new GLtk::Button(res, "Trnt")));
49 btn->set_geometry(GLtk::Geometry(175, 10, 40, 24));
50 btn->set_tooltip("Set turnout ID of selected track");
51 btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::set_turnout_id));
53 add(*(btn=new GLtk::Button(res, "Sens")));
54 btn->set_geometry(GLtk::Geometry(215, 10, 40, 24));
55 btn->set_tooltip("Set sensor ID of selected tracks");
56 btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::set_sensor_id));
58 add(*(lbl=new GLtk::Label(res, "Routes:")));
59 lbl->set_geometry(GLtk::Geometry(265, 22, 40, 13));
61 add(*(drp_routes=new GLtk::Dropdown(res)));
62 drp_routes->set_geometry(GLtk::Geometry(265, 5, 100, 17));
63 drp_routes->set_tooltip("Select route to edit");
64 drp_routes->append("(new route)");
65 drp_routes->signal_item_selected.connect(sigc::mem_fun(this, &Toolbar::route_selected));
67 add(*(btn=new GLtk::Button(res, "AddT")));
68 btn->set_geometry(GLtk::Geometry(365, 10, 40, 24));
69 btn->set_tooltip("Add selected tracks to current route");
70 btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::add_selection_to_route));
72 designer.get_layout()->signal_route_added.connect(sigc::hide(sigc::mem_fun(this, &Toolbar::update_routes)));
73 designer.get_layout()->signal_route_removed.connect(sigc::hide(sigc::mem_fun(this, &Toolbar::update_routes)));
77 void Toolbar::route_selected(unsigned index, const string &)
79 if(index==drp_routes->get_n_items()-1)
81 Layout &layout = *designer.get_layout();
82 Route *route = new Route(layout, format("Route %d", layout.get_routes().size()+1));
83 designer.get_layout()->add_route(*route);
84 designer.edit_route(*route);
86 const map<string, Route *> &routes = designer.get_layout()->get_routes();
89 for(map<string, Route *>::const_iterator i=routes.begin(); (selected<0 && i!=routes.end()); ++i, ++n)
92 drp_routes->set_selected_index(selected);
96 const map<string, Route *> &routes = designer.get_layout()->get_routes();
97 map<string, Route *>::const_iterator i = routes.begin();
99 designer.edit_route(*i->second);
103 void Toolbar::update_routes()
106 const map<string, Route *> &routes = designer.get_layout()->get_routes();
109 for(map<string, Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i, ++n)
111 drp_routes->append(i->second->get_name());
112 if(i->second==designer.get_current_route())
115 drp_routes->append("(new route)");
116 drp_routes->set_selected_index(selected);