Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PI2
PI2 View
Commits
781bc038
Commit
781bc038
authored
Jan 21, 2019
by
Martin Kröning
🦀
Browse files
Explicitly have API calls for bicycles and cars respectively
parent
be9cfbcf
Changes
8
Hide whitespace changes
Inline
Side-by-side
pi2-demo/include/MapAppABIWrapper.hpp
View file @
781bc038
...
...
@@ -13,10 +13,12 @@ public:
void
addRoad
(
const
std
::
string
&
laneThereName
,
const
std
::
string
&
laneBackName
,
const
std
::
vector
<
double
>
&
coordinates
);
void
addOrReplace
Vehi
cle
(
const
std
::
string
&
vehicleName
,
void
addOrReplace
Bicy
cle
(
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:
...
...
pi2-demo/src/Bicycle.cpp
View file @
781bc038
...
...
@@ -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
.
addOrReplace
Vehi
cle
(
getName
(),
laneName
,
positionOnLane
,
getSpeed
(
speedLimit
)
,
0
,
0
,
1
,
0
);
mapApp
.
addOrReplace
Bicy
cle
(
getName
(),
laneName
,
positionOnLane
,
getSpeed
(
speedLimit
));
}
double
Bicycle
::
getSpeed
(
const
double
speedLimit
)
const
{
...
...
pi2-demo/src/Car.cpp
View file @
781bc038
...
...
@@ -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
.
addOrReplace
Vehicle
(
getName
(),
laneName
,
positionOnLane
,
getSpeed
(
speedLimit
),
fuel
,
1
,
0
,
0
);
mapApp
.
addOrReplace
Car
(
getName
(),
laneName
,
positionOnLane
,
getSpeed
(
speedLimit
),
fuel
);
}
double
Car
::
getSpeed
(
const
double
speedLimit
)
const
{
...
...
pi2-demo/src/MapAppABIWrapper.cpp
View file @
781bc038
...
...
@@ -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
)
{
...
...
pi2-view/include/MapApp.hpp
View file @
781bc038
...
...
@@ -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
addOrReplace
Vehi
cle
(
const
std
::
string
&
vehicleName
,
void
addOrReplace
Bicy
cle
(
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
);
...
...
pi2-view/include/pi2-view.h
View file @
781bc038
...
...
@@ -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
mapAppAddOrReplace
Vehi
cle
(
MapApp
*
mapApp
,
const
char
*
vehicleName
,
void
mapAppAddOrReplace
Bicy
cle
(
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
...
...
pi2-view/src/MapApp.cpp
View file @
781bc038
...
...
@@ -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
r
ed
,
double
g
re
en
,
double
blue
)
{
const
double
positionOnLane
,
const
double
spe
ed
,
const
double
re
mainingFuel
,
double
red
,
double
green
,
double
blue
)
{
auto
&
road
=
*
std
::
find_if
(
roads
.
begin
(),
roads
.
end
(),
[
&
laneName
](
const
DrawableRoad
&
road
)
{
return
road
.
contains
(
laneName
);
...
...
pi2-view/src/pi2-view.cpp
View file @
781bc038
...
...
@@ -34,13 +34,19 @@ void mapAppAddRoad(MapApp *mapApp, gsl::czstring<> laneThereName,
mapApp
->
addRoad
(
laneThereName
,
laneBackName
,
coordinateVector
);
}
void
mapAppAddOrReplace
Vehi
cle
(
MapApp
*
mapApp
,
gsl
::
czstring
<>
vehicleName
,
void
mapAppAddOrReplace
Bicy
cle
(
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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment