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