Commit 781bc038 authored by Martin Kröning's avatar Martin Kröning

Explicitly have API calls for bicycles and cars respectively

parent be9cfbcf
...@@ -13,10 +13,12 @@ public: ...@@ -13,10 +13,12 @@ public:
void addRoad(const std::string &laneThereName, void addRoad(const std::string &laneThereName,
const std::string &laneBackName, const std::string &laneBackName,
const std::vector<double> &coordinates); const std::vector<double> &coordinates);
void addOrReplaceVehicle(const std::string &vehicleName, void addOrReplaceBicycle(const std::string &vehicleName,
const std::string &laneName, double positionOnLane, const std::string &laneName, double positionOnLane,
double speed, double remainingFuel, double red, double speed);
double green, double blue); void addOrReplaceCar(const std::string &vehicleName,
const std::string &laneName, double positionOnLane,
double speed, double remainingFuel);
void setDurationLabel(std::chrono::minutes minutes); void setDurationLabel(std::chrono::minutes minutes);
private: private:
......
...@@ -11,8 +11,8 @@ Bicycle::Bicycle(std::string name, const double topSpeed, ...@@ -11,8 +11,8 @@ Bicycle::Bicycle(std::string name, const double topSpeed,
void Bicycle::draw(MapAppABIWrapper &mapApp, const std::string &laneName, void Bicycle::draw(MapAppABIWrapper &mapApp, const std::string &laneName,
const double laneLength, const double speedLimit) const { const double laneLength, const double speedLimit) const {
const auto positionOnLane = getDistanceOnLane() / laneLength; const auto positionOnLane = getDistanceOnLane() / laneLength;
mapApp.addOrReplaceVehicle(getName(), laneName, positionOnLane, mapApp.addOrReplaceBicycle(getName(), laneName, positionOnLane,
getSpeed(speedLimit), 0, 0, 1, 0); getSpeed(speedLimit));
} }
double Bicycle::getSpeed(const double speedLimit) const { double Bicycle::getSpeed(const double speedLimit) const {
......
...@@ -13,8 +13,8 @@ Car::Car(std::string name, const double topSpeed, const double timeOfStart, ...@@ -13,8 +13,8 @@ Car::Car(std::string name, const double topSpeed, const double timeOfStart,
void Car::draw(MapAppABIWrapper &mapApp, const std::string &laneName, void Car::draw(MapAppABIWrapper &mapApp, const std::string &laneName,
const double laneLength, const double speedLimit) const { const double laneLength, const double speedLimit) const {
const auto positionOnLane = getDistanceOnLane() / laneLength; const auto positionOnLane = getDistanceOnLane() / laneLength;
mapApp.addOrReplaceVehicle(getName(), laneName, positionOnLane, mapApp.addOrReplaceCar(getName(), laneName, positionOnLane,
getSpeed(speedLimit), fuel, 1, 0, 0); getSpeed(speedLimit), fuel);
} }
double Car::getSpeed(const double speedLimit) const { double Car::getSpeed(const double speedLimit) const {
......
...@@ -22,13 +22,21 @@ void MapAppABIWrapper::addRoad(const std::string &laneThereName, ...@@ -22,13 +22,21 @@ void MapAppABIWrapper::addRoad(const std::string &laneThereName,
coordinates.data(), coordinates.size()); coordinates.data(), coordinates.size());
} }
void MapAppABIWrapper::addOrReplaceVehicle( void MapAppABIWrapper::addOrReplaceBicycle(const std::string &vehicleName,
const std::string &vehicleName, const std::string &laneName, const std::string &laneName,
const double positionOnLane, const double speed, const double remainingFuel, const double positionOnLane,
const double red, const double green, const double blue) { const double speed) {
mapAppAddOrReplaceVehicle(mapApp, vehicleName.c_str(), laneName.c_str(), mapAppAddOrReplaceBicycle(mapApp, vehicleName.c_str(), laneName.c_str(),
positionOnLane, speed, remainingFuel, red, green, positionOnLane, speed);
blue); }
void MapAppABIWrapper::addOrReplaceCar(const std::string &vehicleName,
const std::string &laneName,
const double positionOnLane,
const double speed,
const double remainingFuel) {
mapAppAddOrReplaceCar(mapApp, vehicleName.c_str(), laneName.c_str(),
positionOnLane, speed, remainingFuel);
} }
void MapAppABIWrapper::setDurationLabel(const std::chrono::minutes minutes) { void MapAppABIWrapper::setDurationLabel(const std::chrono::minutes minutes) {
......
...@@ -27,14 +27,20 @@ public: ...@@ -27,14 +27,20 @@ public:
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,
std::vector<std::valarray<double>> coordinates); std::vector<std::valarray<double>> coordinates);
void addOrReplaceVehicle(const std::string &vehicleName, void addOrReplaceBicycle(const std::string &vehicleName,
const std::string &laneName, double positionOnLane, const std::string &laneName, double positionOnLane,
double speed, double remainingFuel, double red, double speed);
double green, double blue); void addOrReplaceCar(const std::string &vehicleName,
const std::string &laneName, double positionOnLane,
double speed, double remainingFuel);
void setDurationLabel(std::chrono::minutes minutes); void setDurationLabel(std::chrono::minutes minutes);
private: private:
static const std::vector<std::string> zoomLevels; static const std::vector<std::string> zoomLevels;
void addOrReplaceVehicle(const std::string &vehicleName,
const std::string &laneName, double positionOnLane,
double speed, double remainingFuel, double red,
double green, double blue);
void onZoomEntryActivate(); void onZoomEntryActivate();
void onZoomSelectionChanged(); void onZoomSelectionChanged();
void onVehicleRowSelected(Gtk::ListBoxRow *row); void onVehicleRowSelected(Gtk::ListBoxRow *row);
......
...@@ -46,18 +46,24 @@ void mapAppAddRoad(MapApp *mapApp, const char *laneThereName, ...@@ -46,18 +46,24 @@ void mapAppAddRoad(MapApp *mapApp, const char *laneThereName,
size_t coordinateCount); size_t coordinateCount);
/** /**
* Adds or replaces a vehicle to/in \p mapApp * Adds or replaces a bicycle to/in \p mapApp
*
* The parameters \p red \p green and \p blue are the RGB components of the
* color representing the vehicle. They have to be between 0 and 1.
* *
* \param positionOnLane The relative position of the vehicle on its lane * \param positionOnLane The relative position of the vehicle on its lane
* has to be between 0 and 1. * has to be between 0 and 1.
*/ */
void mapAppAddOrReplaceVehicle(MapApp *mapApp, const char *vehicleName, void mapAppAddOrReplaceBicycle(MapApp *mapApp, const char *vehicleName,
const char *roadName, double positionOnLane, const char *roadName, double positionOnLane,
double speed, double remainingFuel, double red, double speed);
double green, double blue);
/**
* Adds or replaces a car to/in \p mapApp
*
* \param positionOnLane The relative position of the vehicle on its lane
* has to be between 0 and 1.
*/
void mapAppAddOrReplaceCar(MapApp *mapApp, const char *vehicleName,
const char *roadName, double positionOnLane,
double speed, double remainingFuel);
/** /**
* Sets the duration label of \p mapApp to \p minutes * Sets the duration label of \p mapApp to \p minutes
......
...@@ -178,11 +178,26 @@ void MapApp::addRoad(std::string laneThereName, std::string laneBackName, ...@@ -178,11 +178,26 @@ void MapApp::addRoad(std::string laneThereName, std::string laneBackName,
Glib::PRIORITY_HIGH_IDLE + 20); Glib::PRIORITY_HIGH_IDLE + 20);
} }
void MapApp::addOrReplaceBicycle(const std::string &vehicleName,
const std::string &laneName,
const double positionOnLane,
const double speed) {
addOrReplaceVehicle(vehicleName, laneName, positionOnLane, speed, 0, 0, 1, 0);
}
void MapApp::addOrReplaceCar(const std::string &vehicleName,
const std::string &laneName,
const double positionOnLane, const double speed,
const double remainingFuel) {
addOrReplaceVehicle(vehicleName, laneName, positionOnLane, speed,
remainingFuel, 1, 0, 0);
}
void MapApp::addOrReplaceVehicle(const std::string &vehicleName, void MapApp::addOrReplaceVehicle(const std::string &vehicleName,
const std::string &laneName, const std::string &laneName,
double positionOnLane, double speed, const double positionOnLane,
double remainingFuel, double red, double green, const double speed, const double remainingFuel,
double blue) { double red, double green, double blue) {
auto &road = *std::find_if(roads.begin(), roads.end(), auto &road = *std::find_if(roads.begin(), roads.end(),
[&laneName](const DrawableRoad &road) { [&laneName](const DrawableRoad &road) {
return road.contains(laneName); return road.contains(laneName);
......
...@@ -34,13 +34,19 @@ void mapAppAddRoad(MapApp *mapApp, gsl::czstring<> laneThereName, ...@@ -34,13 +34,19 @@ void mapAppAddRoad(MapApp *mapApp, gsl::czstring<> laneThereName,
mapApp->addRoad(laneThereName, laneBackName, coordinateVector); mapApp->addRoad(laneThereName, laneBackName, coordinateVector);
} }
void mapAppAddOrReplaceVehicle(MapApp *mapApp, gsl::czstring<> vehicleName, void mapAppAddOrReplaceBicycle(MapApp *mapApp, gsl::czstring<> vehicleName,
gsl::czstring<> roadName, gsl::czstring<> roadName,
const double positionOnLane, const double speed, const double positionOnLane,
const double remainingFuel, const double red, const double speed) {
const double green, const double blue) { mapApp->addOrReplaceBicycle(vehicleName, roadName, positionOnLane, speed);
mapApp->addOrReplaceVehicle(vehicleName, roadName, positionOnLane, speed, }
remainingFuel, red, green, blue);
void mapAppAddOrReplaceCar(MapApp *mapApp, gsl::czstring<> vehicleName,
gsl::czstring<> roadName,
const double positionOnLane, const double speed,
const double remainingFuel) {
mapApp->addOrReplaceCar(vehicleName, roadName, positionOnLane, speed,
remainingFuel);
} }
void mapAppSetDurationLabel(MapApp *mapApp, int64_t minutes) { void mapAppSetDurationLabel(MapApp *mapApp, int64_t minutes) {
......
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