Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
45c48fa0
Commit
45c48fa0
authored
May 24, 2013
by
dongfang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge
parent
d25d3be9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
138 additions
and
42 deletions
+138
-42
PrimaryFlightDisplay.cpp
src/ui/PrimaryFlightDisplay.cpp
+135
-41
PrimaryFlightDisplay.h
src/ui/PrimaryFlightDisplay.h
+3
-1
No files found.
src/ui/PrimaryFlightDisplay.cpp
View file @
45c48fa0
...
...
@@ -71,7 +71,7 @@ PrimaryFlightDisplay::PrimaryFlightDisplay(int width, int height, QWidget *paren
fineLineWidth
(
1
),
instrumentEdgePen
(
QColor
::
fromHsvF
(
0
,
0
,
0.65
,
0.5
)),
// AIEdgePen(QColor::fromHsvF(0, 0, 0.65, 0.5)),
// AIEdgePen(QColor::fromHsvF(0, 0, 0.65, 0.5)),
instrumentBackground
(
QColor
::
fromHsvF
(
0
,
0
,
0.3
,
0.3
)),
instrumentOpagueBackground
(
QColor
::
fromHsvF
(
0
,
0
,
0.3
,
1.0
))
...
...
@@ -130,7 +130,7 @@ void PrimaryFlightDisplay::resizeEvent(QResizeEvent *e) {
qreal
size
=
e
->
size
().
width
();
if
(
e
->
size
().
height
()
<
size
)
size
=
e
->
size
().
height
();
lineWidth
=
constrain
(
size
*
LINEWIDTH
,
2
,
4
);
lineWidth
=
constrain
(
size
*
LINEWIDTH
,
1
,
6
);
fineLineWidth
=
constrain
(
size
*
LINEWIDTH
*
2
/
3
,
1
,
2
);
instrumentEdgePen
.
setWidthF
(
fineLineWidth
);
...
...
@@ -212,7 +212,9 @@ void PrimaryFlightDisplay::updateAttitude(UASInterface* uas, double roll, double
// TODO: Units conversion? // Called from UAS.cc l. 646
this
->
roll
=
roll
*
(
180.0
/
M_PI
);
this
->
pitch
=
pitch
*
(
180.0
/
M_PI
);
this
->
heading
=
yaw
*
(
180.0
/
M_PI
);
yaw
=
yaw
*
(
180.0
/
M_PI
);
if
(
yaw
<
0
)
yaw
+=
360
;
this
->
heading
=
yaw
;
}
// TODO: Else-part. We really should have an "attitude bad or unknown" indication instead of just freezing.
...
...
@@ -227,17 +229,16 @@ void PrimaryFlightDisplay::updateAttitude(UASInterface* uas, int component, doub
{
Q_UNUSED
(
uas
);
Q_UNUSED
(
component
);
Q_UNUSED
(
roll
);
Q_UNUSED
(
pitch
);
Q_UNUSED
(
yaw
);
Q_UNUSED
(
timestamp
);
// Called from UAS.cc l. 616
// Called from UAS.cc l. 616
if
(
!
isnan
(
roll
)
&&
!
isinf
(
roll
)
&&
!
isnan
(
pitch
)
&&
!
isinf
(
pitch
)
&&
!
isnan
(
yaw
)
&&
!
isinf
(
yaw
))
{
this
->
roll
=
roll
*
(
180.0
/
M_PI
);
this
->
pitch
=
pitch
*
(
180.0
/
M_PI
);
this
->
heading
=
yaw
*
(
180.0
/
M_PI
);
}
qDebug
(
"(2) r,p,y: %f,%f,%f"
,
roll
,
pitch
,
yaw
);
yaw
=
yaw
*
(
180.0
/
M_PI
);
if
(
yaw
<
0
)
yaw
+=
360
;
this
->
heading
=
yaw
;
}
qDebug
(
"(2) r,p,y: %f,%f,%f"
,
roll
,
pitch
,
yaw
);
}
...
...
@@ -650,15 +651,8 @@ void PrimaryFlightDisplay::drawAICompassDisk(QPainter& painter, QRectF area) {
float
radius
=
area
.
width
()
/
2
;
float
innerRadius
=
radius
*
0.96
;
painter
.
resetTransform
();
if
(
layout
==
COMPASS_SEPARATED
)
{
painter
.
setBrush
(
instrumentOpagueBackground
);
painter
.
setPen
(
instrumentEdgePen
);
}
else
{
painter
.
setBrush
(
instrumentBackground
);
painter
.
setPen
(
instrumentEdgePen
);
}
painter
.
drawEllipse
(
area
);
painter
.
setBrush
(
Qt
::
NoBrush
);
...
...
@@ -709,7 +703,7 @@ void PrimaryFlightDisplay::drawAICompassDisk(QPainter& painter, QRectF area) {
drawTextCenter
(
painter
,
name
,
mediumTextSize
,
0
,
-
innerRadius
*
0.75
);
}
}
}
}
// draw the scale lines. If an arrow was drawn, stay off from it.
QPointF
p_start
=
drewArrow
?
QPoint
(
0
,
-
innerRadius
*
0.94
)
:
QPoint
(
0
,
-
innerRadius
);
...
...
@@ -733,8 +727,6 @@ void PrimaryFlightDisplay::drawAICompassDisk(QPainter& painter, QRectF area) {
painter
.
setPen
(
instrumentEdgePen
);
painter
.
drawRoundedRect
(
compassRect
,
instrumentEdgePen
.
widthF
()
*
2
/
3
,
instrumentEdgePen
.
widthF
()
*
2
/
3
);
if
(
heading
<
0
)
heading
+=
360
;
else
if
(
heading
>=
360
)
heading
-=
360
;
/* final safeguard for really stupid systems */
int
yawCompass
=
static_cast
<
int
>
(
heading
)
%
360
;
...
...
@@ -749,6 +741,101 @@ void PrimaryFlightDisplay::drawAICompassDisk(QPainter& painter, QRectF area) {
drawTextCenter
(
painter
,
yawAngle
,
largeTextSize
,
0
,
-
radius
*
0.38
);
}
// TODO: Merge common code above and below this line.....
void
PrimaryFlightDisplay
::
drawSeparateCompassDisk
(
QPainter
&
painter
,
QRectF
area
)
{
float
radius
=
area
.
width
()
/
2
;
float
innerRadius
=
radius
*
0.96
;
painter
.
resetTransform
();
painter
.
setBrush
(
instrumentOpagueBackground
);
painter
.
setPen
(
instrumentEdgePen
);
painter
.
drawEllipse
(
area
);
painter
.
setBrush
(
Qt
::
NoBrush
);
QPen
scalePen
(
Qt
::
white
);
scalePen
.
setWidthF
(
fineLineWidth
);
for
(
int
displayTick
=
0
;
displayTick
<
360
;
displayTick
+=
COMPASS_DISK_RESOLUTION
)
{
// yaw is in center.
float
off
=
displayTick
-
heading
;
// wrap that to ]-180..180]
if
(
off
<=-
180
)
off
+=
360
;
else
if
(
off
>
180
)
off
-=
360
;
painter
.
translate
(
area
.
center
());
painter
.
rotate
(
off
);
bool
drewArrow
=
false
;
bool
isMajor
=
displayTick
%
COMPASS_DISK_MAJORTICK
==
0
;
if
(
displayTick
==
30
||
displayTick
==
60
||
displayTick
==
120
||
displayTick
==
150
||
displayTick
==
210
||
displayTick
==
240
||
displayTick
==
300
||
displayTick
==
330
)
{
// draw a number
QString
s_number
;
s_number
.
sprintf
(
"%d"
,
displayTick
/
10
);
painter
.
setPen
(
scalePen
);
drawTextCenter
(
painter
,
s_number
,
mediumTextSize
,
0
,
-
innerRadius
*
0.75
);
}
else
{
if
(
displayTick
%
COMPASS_DISK_ARROWTICK
==
0
)
{
if
(
displayTick
!=
0
)
{
QPainterPath
markerPath
(
QPointF
(
0
,
-
innerRadius
*
(
1
-
COMPASS_DISK_MARKERHEIGHT
/
2
)));
markerPath
.
lineTo
(
innerRadius
*
COMPASS_DISK_MARKERWIDTH
/
4
,
-
innerRadius
);
markerPath
.
lineTo
(
-
innerRadius
*
COMPASS_DISK_MARKERWIDTH
/
4
,
-
innerRadius
);
markerPath
.
closeSubpath
();
painter
.
setPen
(
scalePen
);
painter
.
setBrush
(
Qt
::
SolidPattern
);
painter
.
drawPath
(
markerPath
);
painter
.
setBrush
(
Qt
::
NoBrush
);
drewArrow
=
true
;
}
if
(
displayTick
%
90
==
0
)
{
// Also draw a label
QString
name
=
compassWindNames
[
displayTick
/
45
];
painter
.
setPen
(
scalePen
);
drawTextCenter
(
painter
,
name
,
mediumTextSize
,
0
,
-
innerRadius
*
0.75
);
}
}
}
// draw the scale lines. If an arrow was drawn, stay off from it.
QPointF
p_start
=
drewArrow
?
QPoint
(
0
,
-
innerRadius
*
0.94
)
:
QPoint
(
0
,
-
innerRadius
);
QPoint
p_end
=
isMajor
?
QPoint
(
0
,
-
innerRadius
*
0.86
)
:
QPoint
(
0
,
-
innerRadius
*
0.90
);
painter
.
setPen
(
scalePen
);
painter
.
drawLine
(
p_start
,
p_end
);
painter
.
resetTransform
();
}
painter
.
setPen
(
scalePen
);
//painter.setBrush(Qt::SolidPattern);
painter
.
translate
(
area
.
center
());
QPainterPath
markerPath
(
QPointF
(
0
,
-
radius
-
2
));
markerPath
.
lineTo
(
radius
*
COMPASS_DISK_MARKERWIDTH
/
2
,
-
radius
-
radius
*
COMPASS_DISK_MARKERHEIGHT
-
2
);
markerPath
.
lineTo
(
-
radius
*
COMPASS_DISK_MARKERWIDTH
/
2
,
-
radius
-
radius
*
COMPASS_DISK_MARKERHEIGHT
-
2
);
markerPath
.
closeSubpath
();
painter
.
drawPath
(
markerPath
);
QRectF
headingNumberRect
(
-
radius
/
3
,
radius
*
0.13
,
radius
*
2
/
3
,
radius
*
0.28
);
painter
.
setPen
(
instrumentEdgePen
);
painter
.
drawRoundedRect
(
headingNumberRect
,
instrumentEdgePen
.
widthF
()
*
2
/
3
,
instrumentEdgePen
.
widthF
()
*
2
/
3
);
// if (heading < 0) heading += 360;
// else if (heading >= 360) heading -= 360;
/* final safeguard for really stupid systems */
int
yawCompass
=
static_cast
<
int
>
(
heading
)
%
360
;
QString
yawAngle
;
yawAngle
.
sprintf
(
"%03d"
,
yawCompass
);
QPen
pen
;
pen
.
setWidthF
(
lineWidth
);
pen
.
setColor
(
Qt
::
white
);
painter
.
setPen
(
pen
);
drawTextCenter
(
painter
,
yawAngle
,
largeTextSize
,
0
,
radius
/
4
);
}
void
PrimaryFlightDisplay
::
drawAltimeter
(
QPainter
&
painter
,
QRectF
area
,
// the area where to draw the tape.
...
...
@@ -776,7 +863,7 @@ void PrimaryFlightDisplay::drawAltimeter(
float
numbersLeft
=
0.42
*
w
;
float
markerHalfHeight
=
0.06
*
h
;
float
rightEdge
=
w
-
instrumentEdgePen
.
widthF
()
*
2
;
float
markerTip
=
tickmarkLeft
;
float
markerTip
=
(
tickmarkLeft
*
2
+
tickmarkRight
)
/
3
;
// altitude scale
#ifdef ALTIMETER_PROJECTED
...
...
@@ -821,7 +908,7 @@ void PrimaryFlightDisplay::drawAltimeter(
painter
.
resetTransform
();
painter
.
translate
(
area
.
left
(),
area
.
center
().
y
());
pen
.
setWidthF
(
fineL
ineWidth
);
pen
.
setWidthF
(
l
ineWidth
);
pen
.
setColor
(
Qt
::
white
);
painter
.
setPen
(
pen
);
...
...
@@ -1122,7 +1209,7 @@ void PrimaryFlightDisplay::doPaint() {
qreal
panelsWidth
=
width
()
/
4.0
f
;
qreal
remainingHeight
=
height
()
-
aiheight
;
qreal
panelsHeight
=
remainingHeight
/
5
.0
f
;
qreal
panelsHeight
=
remainingHeight
/
3
.0
f
;
QPoint
compassCenter
;
qreal
maxCompassDiam
;
if
(
remainingHeight
>
width
())
{
...
...
@@ -1149,7 +1236,14 @@ void PrimaryFlightDisplay::doPaint() {
// diagonal between 2 panel corners
qreal
xd
=
width
()
-
panelsWidth
*
2
;
qreal
yd
=
height
()
-
panelsHeight
-
AIArea
.
bottom
();
maxCompassDiam
=
sqrt
(
xd
*
xd
+
yd
*
yd
);
maxCompassDiam
=
qSqrt
(
xd
*
xd
+
yd
*
yd
);
if
(
maxCompassDiam
>
remainingHeight
)
{
maxCompassDiam
=
width
()
-
panelsWidth
*
2
;
if
(
maxCompassDiam
>
remainingHeight
)
{
// If still too large, lower.
// compassCenter.setY();
}
}
}
qreal
compassDiam
=
maxCompassDiam
*
0.8
;
...
...
@@ -1168,7 +1262,7 @@ void PrimaryFlightDisplay::doPaint() {
if
(
layout
==
COMPASS_SEPARATED
)
{
painter
.
setClipping
(
false
);
draw
AI
CompassDisk
(
painter
,
compassArea
);
draw
Separate
CompassDisk
(
painter
,
compassArea
);
}
else
{
drawAICompassDisk
(
painter
,
compassArea
);
...
...
src/ui/PrimaryFlightDisplay.h
View file @
45c48fa0
...
...
@@ -14,7 +14,7 @@
//#define PANELS_TEXT_SIZE 0.030
//#define COMPASS_SCALE_TEXT_SIZE 0.16
#define SMALL_TEXT_SIZE 0.0
28
f
#define SMALL_TEXT_SIZE 0.0
3
f
#define MEDIUM_TEXT_SIZE (SMALL_TEXT_SIZE*1.2f)
#define LARGE_TEXT_SIZE (MEDIUM_TEXT_SIZE*1.2f)
...
...
@@ -152,6 +152,8 @@ private:
void
drawRollScale
(
QPainter
&
painter
,
QRectF
area
,
bool
drawTicks
,
bool
drawNumbers
);
void
drawAIAttitudeScales
(
QPainter
&
painter
,
QRectF
area
);
void
drawAICompassDisk
(
QPainter
&
painter
,
QRectF
area
);
void
drawSeparateCompassDisk
(
QPainter
&
painter
,
QRectF
area
);
void
drawAltimeter
(
QPainter
&
painter
,
QRectF
area
,
float
altitude
,
float
maxAltitude
,
float
vv
);
void
fillInstrumentBackground
(
QPainter
&
painter
,
QRectF
edge
);
...
...
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