Skyscraper 2.0
escalatorcontrol.cpp
Go to the documentation of this file.
1/*
2 Skyscraper 2.0 - Escalator Control
3 Copyright (C)2004-2024 Ryan Thoryk
4 https://www.skyscrapersim.net
5 https://sourceforge.net/projects/skyscraper/
6 Contact - ryan@skyscrapersim.net
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21*/
22
23//(*InternalHeaders(EscalatorControl)
24#include <wx/intl.h>
25#include <wx/string.h>
26//*)
27#include "globals.h"
28#include "sbs.h"
29#include "debugpanel.h"
30#include "escalator.h"
31#include "escalatorcontrol.h"
32
33namespace Skyscraper {
34
35//(*IdInit(EscalatorControl)
36const long EscalatorControl::ID_LISTBOX1 = wxNewId();
37const long EscalatorControl::ID_STATICTEXT1 = wxNewId();
38const long EscalatorControl::ID_txtName = wxNewId();
39const long EscalatorControl::ID_STATICTEXT2 = wxNewId();
40const long EscalatorControl::ID_txtParent = wxNewId();
41const long EscalatorControl::ID_txtRun = wxNewId();
42const long EscalatorControl::ID_SLIDER1 = wxNewId();
43const long EscalatorControl::ID_bOK = wxNewId();
44//*)
45
46BEGIN_EVENT_TABLE(EscalatorControl,wxDialog)
47 //(*EventTable(EscalatorControl)
48 //*)
49END_EVENT_TABLE()
50
52{
53 //(*Initialize(EscalatorControl)
54 wxBoxSizer* BoxSizer1;
55 wxFlexGridSizer* FlexGridSizer1;
56 wxFlexGridSizer* FlexGridSizer2;
57 wxFlexGridSizer* FlexGridSizer3;
58 wxFlexGridSizer* FlexGridSizer4;
59 wxFlexGridSizer* FlexGridSizer5;
60
61 Create(parent, id, _("Escalator Control"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("id"));
62 FlexGridSizer1 = new wxFlexGridSizer(0, 3, 0, 0);
63 FlexGridSizer2 = new wxFlexGridSizer(0, 3, 0, 0);
64 ListBox1 = new wxListBox(this, ID_LISTBOX1, wxDefaultPosition, wxSize(200,300), 0, 0, 0, wxDefaultValidator, _T("ID_LISTBOX1"));
65 FlexGridSizer2->Add(ListBox1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
66 FlexGridSizer4 = new wxFlexGridSizer(0, 1, 0, 0);
67 FlexGridSizer3 = new wxFlexGridSizer(0, 2, 0, 0);
68 StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Name:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
69 FlexGridSizer3->Add(StaticText1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
70 txtName = new wxTextCtrl(this, ID_txtName, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY, wxDefaultValidator, _T("ID_txtName"));
71 FlexGridSizer3->Add(txtName, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
72 StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("Parent:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
73 FlexGridSizer3->Add(StaticText2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
74 txtParent = new wxTextCtrl(this, ID_txtParent, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY, wxDefaultValidator, _T("ID_txtParent"));
75 FlexGridSizer3->Add(txtParent, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
76 FlexGridSizer4->Add(FlexGridSizer3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
77 FlexGridSizer5 = new wxFlexGridSizer(0, 1, 0, 0);
78 txtRun = new wxStaticText(this, ID_txtRun, _("Run"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE, _T("ID_txtRun"));
79 FlexGridSizer5->Add(txtRun, 1, wxALL|wxEXPAND, 5);
80 Slider1 = new wxSlider(this, ID_SLIDER1, 0, -1, 1, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_SLIDER1"));
81 FlexGridSizer5->Add(Slider1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
82 FlexGridSizer4->Add(FlexGridSizer5, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
83 BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
84 FlexGridSizer4->Add(BoxSizer1, 1, wxALL|wxEXPAND, 5);
85 bOK = new wxButton(this, ID_bOK, _("OK"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_bOK"));
86 FlexGridSizer4->Add(bOK, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
87 FlexGridSizer2->Add(FlexGridSizer4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
88 FlexGridSizer1->Add(FlexGridSizer2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
89 SetSizer(FlexGridSizer1);
90 FlexGridSizer1->SetSizeHints(this);
91
92 Connect(ID_SLIDER1,wxEVT_SLIDER,(wxObjectEventFunction)&EscalatorControl::On_Slider1_Scroll);
93 Connect(ID_bOK,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&EscalatorControl::On_bOK_Click);
94 //*)
95
96 lastcount = 0;
97 Simcore = 0;
98 panel = parent;
99 escalator = 0;
100}
101
103{
104 //(*Destroy(EscalatorControl)
105 //*)
106}
107
108void EscalatorControl::On_bOK_Click(wxCommandEvent& event)
109{
110 this->Close();
111}
112
114{
115 if (Simcore != panel->GetSystem())
116 {
117 //if active engine has changed, refresh values
119 }
120
121 if (!Simcore)
122 return;
123
124 BuildList();
125
126 int selection = ListBox1->GetSelection();
127
128 if (selection >= 0)
129 {
130 SBS::Escalator *newescalator = Simcore->GetEscalator(selection);
131
132 //if a new escalator has been selected, update values
133 if (newescalator && escalator != newescalator)
134 {
135 escalator = Simcore->GetEscalator(selection);
136 txtName->SetValue(escalator->GetName());
137 txtParent->SetValue(escalator->GetParent()->GetName());
138 Slider1->SetValue(escalator->GetRun());
140 }
141 }
142 else
143 escalator = 0;
144
145 if (!escalator)
146 return;
147}
148
149void EscalatorControl::BuildList(bool restore_selection)
150{
151 int count = Simcore->GetEscalatorCount();
152
153 if (count != lastcount)
154 {
155 lastcount = count;
156 int old_selection = ListBox1->GetSelection();
157 ListBox1->Clear();
158
159 for (int i = 0; i < count; i++)
160 {
162 if (esc)
163 ListBox1->Append(SBS::ToString(i + 1) + wxT(": ") + esc->GetName());
164 }
165
166 if (count > 0)
167 {
168 if (restore_selection == false)
169 ListBox1->SetSelection(0);
170 else
171 ListBox1->SetSelection(old_selection);
172 }
173 else
174 {
175 //clear values
176 txtName->SetValue(wxT(""));
177 txtParent->SetValue(wxT(""));
178 Slider1->SetValue(0);
179 }
180 }
181}
182
183void EscalatorControl::On_Slider1_Scroll(wxCommandEvent& event)
184{
185 if (escalator)
186 escalator->SetRun(Slider1->GetValue());
187
189}
191{
192 if (!escalator)
193 return;
194
195 int run = escalator->GetRun();
196
197 if (run == -1)
198 txtRun->SetLabel("Run: reverse");
199 else if (run == 0)
200 txtRun->SetLabel("Run: stopped");
201 else if (run == 1)
202 txtRun->SetLabel("Run: forward");
203}
204
205}
void SetRun(int value)
const std::string & GetName()
Definition object.cpp:53
Object * GetParent()
Definition object.cpp:42
Escalator * GetEscalator(int index)
Definition sbs.cpp:4660
int GetEscalatorCount()
Definition sbs.cpp:4019
SBS::SBS * GetSystem()
Definition debugpanel.h:131
void On_Slider1_Scroll(wxCommandEvent &event)
void On_bOK_Click(wxCommandEvent &event)
void BuildList(bool restore_selection=false)
std::string ToString(int number)
Definition globals.cpp:279