swift
interpolationsetupform.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include "ui_interpolationsetupform.h"
7 
8 #include "gui/guiutility.h"
9 
10 using namespace swift::misc;
11 using namespace swift::misc::physical_quantities;
12 using namespace swift::misc::simulation;
13 
14 namespace swift::gui::editors
15 {
16  CInterpolationSetupForm::CInterpolationSetupForm(QWidget *parent)
17  : CForm(parent), ui(new Ui::CInterpolationSetupForm)
18  {
19  ui->setupUi(this);
20  m_allCheckBoxes = this->findChildren<QCheckBox *>(QString(), Qt::FindDirectChildrenOnly);
21  for (QCheckBox *cb : std::as_const(m_allCheckBoxes))
22  {
23  connect(cb, &QCheckBox::stateChanged, this, &CInterpolationSetupForm::onCheckboxChanged);
24  }
25 
26  // one connect is enough, otherwise 2 change signals
27  connect(ui->rb_Linear, &QRadioButton::toggled, this, &CInterpolationSetupForm::onInterpolatorModeChanged);
28 
29  // pitch
30  connect(ui->le_PitchOnGround, &QLineEdit::editingFinished, this, &CInterpolationSetupForm::onPitchChanged);
31  }
32 
34 
36  {
37  ui->cb_DebugDriver->setChecked(setup.showSimulatorDebugMessages());
38  ui->cb_LogInterpolation->setChecked(setup.logInterpolation());
39  ui->cb_EnableParts->setChecked(setup.isAircraftPartsEnabled());
40  ui->cb_ForceFullInterpolation->setChecked(setup.isForcingFullInterpolation());
41  ui->cb_SendGndFlagToSim->setChecked(setup.isSendingGndFlagToSimulator());
42  ui->cb_FixSceneryOffset->setChecked(setup.isFixingSceneryOffset());
43  this->setInterpolatorMode(setup.getInterpolatorMode());
44  this->displayPitchOnGround(setup.getPitchOnGround());
45  }
46 
48  {
50  setup.setEnabledAircraftParts(ui->cb_EnableParts->isChecked());
51  setup.setForceFullInterpolation(ui->cb_ForceFullInterpolation->isChecked());
52  setup.setLogInterpolation(ui->cb_LogInterpolation->isChecked());
53  setup.setSendingGndFlagToSimulator(ui->cb_SendGndFlagToSim->isChecked());
54  setup.setSimulatorDebuggingMessages(ui->cb_DebugDriver->isChecked());
55  setup.setFixingSceneryOffset(ui->cb_FixSceneryOffset->isChecked());
56  setup.setInterpolatorMode(this->getInterpolatorMode());
57  setup.setPitchOnGround(this->getPitchOnGround());
58  return setup;
59  }
60 
62  {
63  CGuiUtility::checkBoxReadOnly(ui->cb_DebugDriver, readonly);
64  CGuiUtility::checkBoxReadOnly(ui->cb_LogInterpolation, readonly);
65  CGuiUtility::checkBoxReadOnly(ui->cb_EnableParts, readonly);
66  CGuiUtility::checkBoxReadOnly(ui->cb_ForceFullInterpolation, readonly);
67  CGuiUtility::checkBoxReadOnly(ui->cb_SendGndFlagToSim, readonly);
68  CGuiUtility::checkBoxReadOnly(ui->cb_FixSceneryOffset, readonly);
69  ui->le_PitchOnGround->setReadOnly(readonly);
70 
71  const bool enabled = !readonly;
72  ui->rb_Linear->setEnabled(enabled);
73  ui->rb_Spline->setEnabled(enabled);
74  }
75 
77  {
78  Q_UNUSED(nested)
79  return CStatusMessageList();
80  }
81 
82  void CInterpolationSetupForm::onCheckboxChanged(int state)
83  {
84  Q_UNUSED(state)
85  emit this->valueChanged();
86  }
87 
88  CInterpolationAndRenderingSetupBase::InterpolatorMode CInterpolationSetupForm::getInterpolatorMode() const
89  {
90  if (ui->rb_Linear->isChecked()) { return CInterpolationAndRenderingSetupBase::Linear; }
91  return CInterpolationAndRenderingSetupBase::Spline;
92  }
93 
94  void CInterpolationSetupForm::setInterpolatorMode(CInterpolationAndRenderingSetupBase::InterpolatorMode mode)
95  {
96  switch (mode)
97  {
98  case CInterpolationAndRenderingSetupBase::Linear: ui->rb_Linear->setChecked(true); break;
99  case CInterpolationAndRenderingSetupBase::Spline:
100  default: ui->rb_Spline->setChecked(true); break;
101  }
102  }
103 
104  void CInterpolationSetupForm::onInterpolatorModeChanged(bool checked)
105  {
106  Q_UNUSED(checked)
107  emit this->valueChanged();
108  }
109 
110  void CInterpolationSetupForm::onPitchChanged()
111  {
112  const CAngle pitchOnGround = this->getPitchOnGround();
113  this->displayPitchOnGround(pitchOnGround);
114  }
115 
116  CAngle CInterpolationSetupForm::getPitchOnGround() const
117  {
118  CAngle pitch;
119  const QString p = ui->le_PitchOnGround->text().trimmed();
120  pitch.parseFromString(p, CPqString::SeparatorBestGuess, CAngleUnit::deg());
121  return pitch;
122  }
123 
124  void CInterpolationSetupForm::displayPitchOnGround(const CAngle &pitchOnGround)
125  {
126  const QString p = pitchOnGround.valueRoundedWithUnit(CAngleUnit::deg(), 1, true);
127  ui->le_PitchOnGround->setText(p);
128  }
129 } // namespace swift::gui::editors
static void checkBoxReadOnly(QCheckBox *checkBox, bool readOnly)
Pseudo readonly state for checkbox.
Definition: guiutility.cpp:450
Form base class.
Definition: form.h:27
Setup of interpolation and rendering.
swift::misc::simulation::CInterpolationAndRenderingSetupPerCallsign getValue() const
Get value.
void setValue(const swift::misc::simulation::CInterpolationAndRenderingSetupBase &setup)
Set value.
virtual void setReadOnly(bool readonly)
Set editable.
virtual swift::misc::CStatusMessageList validate(bool nested=false) const
Validate, empty list means OK.
Status messages, e.g. from Core -> GUI.
Physical unit angle (radians, degrees)
Definition: angle.h:23
void parseFromString(const QString &value)
Parse value from string.
QString valueRoundedWithUnit(const MU &unit, int digits=-1, bool withGroupSeparator=false, bool i18n=false) const
Value to QString with the given unit, e.g. "5.00m".
Value object for interpolator and rendering base class.
void setFixingSceneryOffset(bool fix)
Enable fix scenery offset if it has been detected.
bool setPitchOnGround(const physical_quantities::CAngle &pitchOnGround)
Force a given pitch on ground.
bool setSendingGndFlagToSimulator(bool sendFLag)
Set sending GND flag to simulator.
bool setEnabledAircraftParts(bool enabled)
Set enabled aircraft parts.
bool setInterpolatorMode(InterpolatorMode mode)
Set interpolator mode.
bool isFixingSceneryOffset() const
Fix scenery offset if it has been detected.
bool isAircraftPartsEnabled() const
Aircraft parts enabled (still requires the other aircraft to send parts)
void setSimulatorDebuggingMessages(bool debug)
Debugging messages for simulation.
const physical_quantities::CAngle & getPitchOnGround() const
Force a given pitch on ground.
bool showSimulatorDebugMessages() const
Debugging messages for simulation.
bool isForcingFullInterpolation() const
Full interpolation (skip optimizations like checking if aircraft moves etc.)
Value object for interpolator and rendering per callsign.
Free functions in swift::misc.