Commit 4ab4167b authored by Martin Kröning's avatar Martin Kröning

Pass window title on MapApp construction

parent d7e8027f
...@@ -10,7 +10,7 @@ class Junction; ...@@ -10,7 +10,7 @@ class Junction;
class Map { class Map {
public: public:
explicit Map(std::istream &is); Map(std::istream &is, const std::string &windowTitle);
void simulate(std::chrono::seconds duration, double speedFactor, void simulate(std::chrono::seconds duration, double speedFactor,
double frequency); double frequency);
......
...@@ -7,7 +7,7 @@ struct MapApp; ...@@ -7,7 +7,7 @@ struct MapApp;
class MapAppABIWrapper { class MapAppABIWrapper {
public: public:
MapAppABIWrapper(); MapAppABIWrapper(const std::string &windowTitle);
virtual ~MapAppABIWrapper(); virtual ~MapAppABIWrapper();
void addJunction(double x, double y); void addJunction(double x, double y);
void addRoad(const std::string &laneThereName, void addRoad(const std::string &laneThereName,
......
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
Map::Map(std::istream &is) : time(0) { Map::Map(std::istream &is, const std::string &windowTitle)
: time(0), mapApp(windowTitle) {
std::string type; std::string type;
while (is >> type) { while (is >> type) {
if (type == "KREUZUNG") { if (type == "KREUZUNG") {
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
MapAppABIWrapper::MapAppABIWrapper() : mapApp(mapAppCreate()) {} MapAppABIWrapper::MapAppABIWrapper(const std::string &windowTitle)
: mapApp(mapAppCreate(windowTitle.c_str())) {}
MapAppABIWrapper::~MapAppABIWrapper() { MapAppABIWrapper::~MapAppABIWrapper() {
mapAppDestroy(mapApp); mapAppDestroy(mapApp);
......
...@@ -13,7 +13,7 @@ int main(int argc, char *argv[]) { ...@@ -13,7 +13,7 @@ int main(int argc, char *argv[]) {
std::string durationString; std::string durationString;
double timescale; double timescale;
double refreshRate; double refreshRate;
std::string filename; std::string nativePathname;
po::options_description visibleOptions("Allowed options"); po::options_description visibleOptions("Allowed options");
visibleOptions.add_options()( visibleOptions.add_options()(
...@@ -27,8 +27,8 @@ int main(int argc, char *argv[]) { ...@@ -27,8 +27,8 @@ int main(int argc, char *argv[]) {
"help", "display this help and exit"); "help", "display this help and exit");
po::options_description hiddenOptions("Hidden options"); po::options_description hiddenOptions("Hidden options");
hiddenOptions.add_options()("input-file", po::value<std::string>(&filename), hiddenOptions.add_options()(
"input file"); "input-file", po::value<std::string>(&nativePathname), "input file");
po::options_description allOptions; po::options_description allOptions;
allOptions.add(visibleOptions).add(hiddenOptions); allOptions.add(visibleOptions).add(hiddenOptions);
...@@ -53,9 +53,9 @@ int main(int argc, char *argv[]) { ...@@ -53,9 +53,9 @@ int main(int argc, char *argv[]) {
} }
if (variablesMap.count("input-file") > 0) { if (variablesMap.count("input-file") > 0) {
std::ifstream istrm(filename); std::ifstream istrm(nativePathname);
if (istrm.is_open()) { if (istrm.is_open()) {
Map map(istrm); Map map(istrm, "pi2-demo - " + nativePathname);
std::istringstream buffer(durationString); std::istringstream buffer(durationString);
int hours; int hours;
...@@ -74,7 +74,7 @@ int main(int argc, char *argv[]) { ...@@ -74,7 +74,7 @@ int main(int argc, char *argv[]) {
map.simulate(duration, timescale, refreshRate); map.simulate(duration, timescale, refreshRate);
std::cout << "Simulation done!" << std::endl; std::cout << "Simulation done!" << std::endl;
} else { } else {
std::cout << "Failed to open " << filename << std::endl; std::cout << "Failed to open " << nativePathname << std::endl;
return 1; return 1;
} }
} else { } else {
......
...@@ -22,7 +22,7 @@ class ListBoxRow; ...@@ -22,7 +22,7 @@ class ListBoxRow;
class MapApp { class MapApp {
public: public:
MapApp(); MapApp(std::string windowTitle);
virtual ~MapApp(); virtual ~MapApp();
void addJunction(double x, double y); void addJunction(double x, double y);
void addRoad(std::string laneThereName, std::string laneBackName, void addRoad(std::string laneThereName, std::string laneBackName,
......
...@@ -15,7 +15,7 @@ struct MapApp; ...@@ -15,7 +15,7 @@ struct MapApp;
/// You *have* to call mapAppDestroy(MapApp *) to avoid memory leaks. /// You *have* to call mapAppDestroy(MapApp *) to avoid memory leaks.
/// ///
/// \returns A pointer to the created MapApp /// \returns A pointer to the created MapApp
MapApp *mapAppCreate(); MapApp *mapAppCreate(const char *windowTitle);
/// Destroys \p mapApp and frees its memory. /// Destroys \p mapApp and frees its memory.
void mapAppDestroy(MapApp *mapApp); void mapAppDestroy(MapApp *mapApp);
......
...@@ -28,13 +28,13 @@ ...@@ -28,13 +28,13 @@
const std::vector<std::string> MapApp::zoomLevels = {"60%", "80%", "100%"}; const std::vector<std::string> MapApp::zoomLevels = {"60%", "80%", "100%"};
MapApp::MapApp() MapApp::MapApp(std::string windowTitle)
: app(Gtk::Application::create()), : app(Gtk::Application::create()),
mapArea(junctions, roads, nameVehicleMap), listBox(nullptr), mapArea(junctions, roads, nameVehicleMap), listBox(nullptr),
durationLabel(nullptr), laneLabel(nullptr), durationLabel(nullptr), laneLabel(nullptr),
lanePositionPercentageLabel(nullptr), speedLabel(nullptr), lanePositionPercentageLabel(nullptr), speedLabel(nullptr),
remainingFuelLabel(nullptr), zoomComboBoxText(nullptr) { remainingFuelLabel(nullptr), zoomComboBoxText(nullptr) {
win.set_title("pi2-demo"); win.set_title(std::move(windowTitle));
auto builder = auto builder =
Gtk::Builder::create_from_resource("/pi2-view/pi2-view.glade", "box"); Gtk::Builder::create_from_resource("/pi2-view/pi2-view.glade", "box");
......
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
#include <valarray> #include <valarray>
#include <vector> #include <vector>
gsl::owner<MapApp *> mapAppCreate() { return new MapApp(); } gsl::owner<MapApp *> mapAppCreate(gsl::czstring<> windowTitle) {
return new MapApp(windowTitle);
}
void mapAppDestroy(gsl::owner<MapApp *> mapApp) { delete mapApp; } void mapAppDestroy(gsl::owner<MapApp *> mapApp) { delete mapApp; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment