Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions cmake/cpp.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is for:
# - Encapsulating some platform differences
# - Encapsulating some platform and compiler differences
# - Source declaration
# - Qt6 dependency declaration
#
Expand All @@ -16,12 +16,23 @@ set(APP_SOURCES
set(OTHER_APP_SOURCES
"${CMAKE_SOURCE_DIR}/src/App/Recreation.cpp")

set(WIDGET_SOURCES
set(WINDOWING_SOURCES
"${WINDOWING_SRC_DIR}/DevWindow.cpp"
"${WINDOWING_SRC_DIR}/NumericTestWidget.cpp"
"${WINDOWING_SRC_DIR}/NumericTestWidget.cpp")

set(DIAL_SOURCES
"${WIDGETS_SRC_DIR}/Dial/Attitude.cpp"
"${WIDGETS_SRC_DIR}/Dial/Composite.cpp")

set(DISPLAYER_SOURCES
"${WIDGETS_SRC_DIR}/Displays/QuantitiesRatesDisplay.cpp"
"${WIDGETS_SRC_DIR}/Displays/QuantitiesRatesRow.cpp"
"${WIDGETS_SRC_DIR}/Dial/AttitudeDial.cpp")
"${WIDGETS_SRC_DIR}/Displays/RateLabel.cpp")

set(WIDGET_SOURCES
${WINDOWING_SOURCES}
${DIAL_SOURCES}
${DISPLAYER_SOURCES})

set(PLOTTING_SOURCES
"${PLOTTING_SRC_DIR}/Plot2D.cpp"
Expand Down
4 changes: 2 additions & 2 deletions src/Plotting/Backend/CoreQChart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ void PlotQChart::Plot() {

QList<QPointF> pts;
const SeriesInfo& sinfo = sinfos[idx];
unsigned int n = sinfo.Times.size();
std::size_t n = sinfo.Times.size();
if (n == 0) { continue; }

for (unsigned int i = 0; i < n; i++) {
for (unsigned int i = 0; static_cast<std::size_t>(i) < n; i++) {
pts.append({ sinfo.Times[i], sinfo.Quantities[i] });
}

Expand Down
8 changes: 4 additions & 4 deletions src/Plotting/Plot2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace VSCL::Plot {

void EmbeddablePlot2D::AddPoint(double time, double quantity, bool update) { AddPoint(0, time, quantity); }
void EmbeddablePlot2D::AddPoint(double time, double quantity, bool update) { AddPoint(0, time, quantity, update); }
void EmbeddablePlot2D::AddPoint(uint8_t idx, double time, double quantity, bool update) {
std::vector<double>& oldTime = Series[idx].Times;
std::vector<double>& oldQty = Series[idx].Quantities;
Expand All @@ -19,8 +19,8 @@ void EmbeddablePlot2D::AddPoints(uint8_t idx,
std::vector<double>& oldTime = Series[idx].Times;
std::vector<double>& oldQty = Series[idx].Quantities;

oldTime.resize(oldTime.size() + times.size());
oldQty.resize(oldQty.size() + quantities.size());
oldTime.reserve(oldTime.size() + times.size());
oldQty.reserve(oldQty.size() + quantities.size());

for (double time : times) {
oldTime.push_back(time);
Expand All @@ -34,7 +34,7 @@ void EmbeddablePlot2D::AddPoints(uint8_t idx,
}
void EmbeddablePlot2D::AddPoints(
const std::vector<double>& times, const std::vector<double>& quantities, bool update) {
AddPoints(0, times, quantities); }
AddPoints(0, times, quantities, update); }

void EmbeddablePlot2D::SetAxis(const Axis axis, const AxisInfo& info) {
switch (axis) {
Expand Down
14 changes: 14 additions & 0 deletions src/Util/FiniteDiff.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <array>

namespace VSCL::Util {

static constexpr double CenterFiniteDifference(const std::array<double, 3>& ts, const std::array<double, 3>& qtys) {
double h = (ts[2] - ts[0]) / 2.0;
double fwd = (qtys[2] - qtys[1]) / 2.0;
double bkd = (qtys[1] - qtys[0]) / 2.0;

return (fwd - bkd) / h;
}
} // namespace VSCL::Util
15 changes: 12 additions & 3 deletions src/Util/Sizing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@

namespace VSCL::Util {

constexpr int MinimumWidth = 720;
constexpr int MinimumHeight = 480;
static constexpr int MinimumWidth = 720;
static constexpr int MinimumHeight = 480;

struct FontAdjustment {
int PointSizeAtMinimum;
/*
* The point size at the window's minimum resolution.
*/
unsigned int PointSizeAtMinimum = 12;

/*
* When true, adjust to the width of the window.
* When false, adjust to the height of the window.
*/
bool AdjustToWidth = false;

const int AdjustPointSize(QWidget* win) const {
return PointSizeAtMinimum
+ ((AdjustToWidth) ?
Expand Down
95 changes: 41 additions & 54 deletions src/Widgets/Dial/AttitudeDial.cpp → src/Widgets/Dial/Attitude.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
#include <QBoxLayout>
#include <QPainter>

#include <algorithm>
#include <cmath>

#include "AttitudeDial.hpp"
#include "Attitude.hpp"

namespace VSCL {

AttitudeDial::AttitudeDial(QWidget* parent) : QWidget(parent) {
NumericDisplayFont = QFont();
NumericDisplay = new QLabel(this);
NumericDisplay->setBuddy(this);
NumericDisplay->setAlignment(Qt::AlignCenter);
NumericDisplay->setFrameStyle(QFrame::Panel | QFrame::Raised);
NumericDisplay->setFont(NumericDisplayFont);
NumericDisplay->setStyleSheet(" QLabel { color: white; background-color: black; border-radius: 3% } ");

SetRangeType(RangeTypeMode);
update();
} // AttitudeDial ctor

AttitudeDial::AttitudeDial(QWidget* parent, bool showNumericDisplay) : AttitudeDial(parent) {
SetNumericDisplayState(showNumericDisplay);
}

void AttitudeDial::SetDialAngle(double value) {
CurrentAngle = value;
update();
Expand All @@ -43,29 +28,38 @@
Origin = { curSize.width() / 2, curSize.height() / 2 };
}

void AttitudeDial::UpdateNumericDisplay() {
NumericDisplay->setText(QString::number(CurrentAngle) + "°");
QPoint AttitudeDial::HandEndingLowestNominal() const {
double ang = (CurrentAngle - Range[0]) * 3.14 / 180.0;
int linex = Radius*std::sin(ang);
int liney = -Radius*std::cos(ang);

int w = int(0.2*Radius);
int h = int(0.1*Radius);
return Origin + QPoint{ linex, liney };
}

NumericDisplay->setFixedSize(w, h);
NumericDisplay->move(Origin - QPoint{ w / 2 , h / 2 });
} // void AttitudeDial::UpdateNumericDisplay()
QPoint AttitudeDial::HandEndingCenteredNominal() const {
double rangeCtr = (Range[1] - Range[0]) / 2.0;
double ang = (CurrentAngle - rangeCtr) * 3.14 / 180.0;
int linex = -Radius*std::sin(ang);
int liney = Radius*std::cos(ang);

void AttitudeDial::UpdateNumericFont() {
int pts = Radius / 20;
pts = (pts < 1) ? 1 : pts;
return Origin + QPoint{ linex, liney };
}

NumericDisplayFont.setPointSize(pts);
NumericDisplay->setFont(NumericDisplayFont);
} // void AttitudeDial::UpdateNumericDisplay()
void AttitudeDial::SetRangeType(RangeType newRangeType) {
RangeTypeMode = newRangeType;

switch (RangeTypeMode) {
case RangeType::LowestNominal:
RangeHandlerFunction = std::bind(&AttitudeDial::HandEndingLowestNominal, this);
break;
case RangeType::CenteredNominal:
default:
RangeHandlerFunction = std::bind(&AttitudeDial::HandEndingCenteredNominal, this);
break;
}

void AttitudeDial::SetNumericDisplayState(bool enabled) {
NumericDisplayEnabled = enabled;
NumericDisplay->setVisible(enabled);
update();
} // void AttitudeDial::UpdateNumericDisplay()
}

void AttitudeDial::PaintCircularBacking(QPainter* painter) {
QBrush fillBrush = painter->brush();
Expand All @@ -78,43 +72,41 @@
} // void AttitudeDial::PaintCircularBacking()

void AttitudeDial::PaintTicks(QPainter* painter) {
for (int i = 0; i < 12; i++) {
QPoint st, ed;
for (int i = 0; i < 8; i++) {
QColor tickcolor;
const double ci = Radius*Cos30Degs[i];
const double si = Radius*Sin30Degs[i];
double ticker[2] = { 0.0, 1.0 };
std::array<double, 2> ticker = { 0.0, 1.0 };
std::array<double, 2> cossin;

switch (i) {
case 0:
case 3:
case 6:
case 9: // major
case 1:
case 2:
case 3: // major
ticker[0] = 0.85;
tickcolor = Palette.MajorTick;
cossin = MajorTicks[i];
break;
default: // minor
ticker[0] = 0.95;
tickcolor = Palette.MinorTick;
cossin = MinorTicks[i - 4];
break;
}

st = Origin + ticker[0] * QPoint{ int(ci), int(si) };
ed = Origin + ticker[1] * QPoint{ int(ci), int(si) };

double ci = Radius * cossin[0];
double si = Radius * cossin[1];
QPen pen = painter->pen();
pen.setColor(tickcolor);

QPoint st = Origin + ticker[0] * QPoint{ int(ci), int(si) };
QPoint ed = Origin + ticker[1] * QPoint{ int(ci), int(si) };
painter->setPen(pen);
painter->drawLine(st, ed);
}
} // void AttitudeDial::PaintTicks()

void AttitudeDial::PaintHand(QPainter* painter) {
double ang = CurrentAngle * 3.14 / 180.0;
int linex = Radius*std::sin(ang);
int liney = -Radius*std::cos(ang);
QPoint end = Origin + QPoint{ linex, liney };
QPoint end = (RangeHandlerFunction) ? RangeHandlerFunction(this) : Origin + QPoint{ 0, (int)Radius };

QPen pen = painter->pen();
pen.setColor(Palette.Hand);
Expand All @@ -138,7 +130,7 @@
AttitudeDialPalette AttitudeDial::GetPalette() const { return Palette; }
const AttitudeDialPalette& AttitudeDial::GetPaletteView() const { return Palette; }

void AttitudeDial::paintEvent(QPaintEvent* event) {

Check warning on line 133 in src/Widgets/Dial/Attitude.cpp

View workflow job for this annotation

GitHub Actions / Windows

'event': unreferenced parameter

Check warning on line 133 in src/Widgets/Dial/Attitude.cpp

View workflow job for this annotation

GitHub Actions / Windows

'event': unreferenced parameter
UpdateRadius();
UpdateOrigin();

Expand All @@ -147,10 +139,5 @@
PaintTicks(&painter);
PaintHand(&painter);
PaintCap(&painter);

if (NumericDisplayEnabled) {
UpdateNumericDisplay();
UpdateNumericFont();
}
}
} // namespace VSCL
42 changes: 21 additions & 21 deletions src/Widgets/Dial/AttitudeDial.hpp → src/Widgets/Dial/Attitude.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#pragma once

#include <cstdint>
#include <array>
#include <QtWidgets>

namespace VSCL {
struct AttitudeDialPalette {
QColor Primary = QColorConstants::White;
QColor Hand = QColorConstants::Black;
QColor Hand = QColorConstants::Red;
QColor Cap = QColorConstants::Black;
QColor MajorTick = QColorConstants::DarkGray;
QColor MinorTick = QColorConstants::DarkGray;
QColor MinorTick = QColorConstants::LightGray;
};

class AttitudeDial : public QWidget {
Expand All @@ -18,15 +19,18 @@ class AttitudeDial : public QWidget {

public:
AttitudeDial(QWidget* parent);
AttitudeDial(QWidget* parent, bool enabled);

void SetDialAngle(double value);
void SetNumericDisplayState(bool enabled);

void SetPalette(AttitudeDialPalette& newPalette);
AttitudeDialPalette GetPalette() const;
const AttitudeDialPalette& GetPaletteView() const;

enum class RangeType : uint8_t {
CenteredNominal,
LowestNominal
};
void SetRangeType(RangeType newRangeType);

virtual void paintEvent(QPaintEvent* event) override;

private:
Expand All @@ -37,28 +41,24 @@ class AttitudeDial : public QWidget {
void UpdateRadius();

AttitudeDialPalette Palette;

QFont NumericDisplayFont;
QLabel* NumericDisplay;
bool NumericDisplayEnabled = true;
void UpdateNumericFont();
void UpdateNumericDisplay();
std::array<double, 2> Range = { -180, 180 };
RangeType RangeTypeMode = RangeType::CenteredNominal;
QPoint HandEndingLowestNominal() const;
QPoint HandEndingCenteredNominal() const;
std::function<QPoint(const AttitudeDial&)> RangeHandlerFunction = nullptr;

void PaintCircularBacking(QPainter* painter);
void PaintTicks(QPainter* painter);
void PaintHand(QPainter* painter);
void PaintCap(QPainter* painter);

static constexpr std::array<double, 12> Cos30Degs = {
1.0, 0.8660254037844387, 0.5, 0.0,
-0.5, -0.8660254037844387, -1.0, -0.8660254037844387,
-0.5, 0.0, 0.5, 0.8660254037844387
};
static constexpr std::array<double, 12> Sin30Degs = {
0.0, 0.5, 0.8660254037844387, 1.0,
0.8660254037844387, 0.5, 0.0, -0.5,
-0.8660254037844387, -1.0, -0.8660254037844387, -0.5
};
static constexpr std::array<std::array<double, 2>, 4> MajorTicks = {{
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do with ticks that aren't spaced 45 degrees apart, as well. Check up with Dr. Valasek on this aspect.

{ 1.0, 0.0 }, { 0.0, 1.0 }, { -1.0, 0.0 }, { 0.0, -1.0 }
}};

static constexpr std::array<std::array<double, 2>, 4> MinorTicks = {{
{ 0.7071067811865475, 0.7071067811865475 }, { 0.7071067811865475, -0.7071067811865475 },
{ -0.7071067811865475, -0.7071067811865475 }, { -0.7071067811865475, 0.7071067811865475 }
}};
}; // class AttitudeDial
} // namespace VSCL
Loading
Loading