]> git.tdb.fi Git - r2c2.git/blob - source/engineer/mainpanel.cpp
Add framework for generating simple meshes for vehicles
[r2c2.git] / source / engineer / mainpanel.cpp
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include <msp/gltk/button.h>
9 #include "libmarklin/driver.h"
10 #include "engineer.h"
11 #include "mainpanel.h"
12 #include "trainproperties.h"
13
14 using namespace std;
15 using namespace Msp;
16
17 MainPanel::MainPanel(Engineer &e, GLtk::Resources &r):
18         Widget(r),
19         Panel(r),
20         engineer(e)
21 {
22         set_size(200, 117);
23
24         GLtk::Button *btn;
25
26         add(*(btn=new GLtk::Button(res, "Off")));
27         btn->set_geometry(GLtk::Geometry(10, 70, 40, 25));
28         btn->set_style("red");
29         btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::power_off));
30
31         add(*(ind_off=new GLtk::Indicator(res)));
32         ind_off->set_geometry(GLtk::Geometry(10, 95, 40, 12));
33         ind_off->set_style("red");
34
35         add(*(btn=new GLtk::Button(res, "On")));
36         btn->set_geometry(GLtk::Geometry(50, 70, 40, 25));
37         btn->set_style("green");
38         btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::power_on));
39
40         add(*(ind_on=new GLtk::Indicator(res)));
41         ind_on->set_geometry(GLtk::Geometry(50, 95, 40, 12));
42         ind_on->set_style("green");
43
44         add(*(btn=new GLtk::Button(res, "Halt")));
45         btn->set_geometry(GLtk::Geometry(90, 70, 40, 25));
46         btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::toggle_halt));
47
48         add(*(ind_halt=new GLtk::Indicator(res)));
49         ind_halt->set_geometry(GLtk::Geometry(90, 95, 40, 12));
50
51         add(*(btn=new GLtk::Button(res, "Quit")));
52         btn->set_geometry(GLtk::Geometry(150, 70, 40, 25));
53         btn->set_style("red");
54         btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::quit));
55
56         add(*(btn=new GLtk::Button(res, "+Loc")));
57         btn->set_geometry(GLtk::Geometry(10, 40, 40, 25));
58         btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::new_loc));
59
60         add(*(lbl_status=new GLtk::Label(res)));
61         lbl_status->set_geometry(GLtk::Geometry(10, 10, 180, 20));
62         lbl_status->set_style("digital");
63
64         Marklin::Driver &driver = engineer.get_layout().get_driver();
65         if(driver.get_power())
66                 ind_on->set_active(true);
67         else
68                 ind_off->set_active(true);
69
70         driver.signal_power.connect(sigc::mem_fun(this, &MainPanel::power_event));
71         driver.signal_halt.connect(sigc::mem_fun(this, &MainPanel::halt_event));
72 }
73
74 void MainPanel::set_status_text(const string &txt)
75 {
76         lbl_status->set_text(txt);
77 }
78
79 void MainPanel::power_on()
80 {
81         engineer.get_layout().get_driver().set_power(true);
82 }
83
84 void MainPanel::power_off()
85 {
86         engineer.get_layout().get_driver().set_power(false);
87 }
88
89 void MainPanel::toggle_halt()
90 {
91         Marklin::Driver &driver = engineer.get_layout().get_driver();
92         driver.halt(!driver.is_halted());
93 }
94
95 void MainPanel::new_loc()
96 {
97         TrainProperties *dialog = new TrainProperties(engineer, res, 0);
98         engineer.get_root().add(*dialog);
99         dialog->set_position(geom.x+geom.w, geom.y+geom.h-dialog->get_geometry().h);
100         dialog->set_visible(true);
101 }
102
103 void MainPanel::quit()
104 {
105         engineer.quit();
106 }
107
108 void MainPanel::power_event(bool p)
109 {
110         ind_on->set_active(p);
111         ind_off->set_active(!p);
112 }
113
114 void MainPanel::halt_event(bool h)
115 {
116         ind_halt->set_active(h);
117 }