316 lines
10 KiB
C++
Executable File
316 lines
10 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* HMI Plugin for Observer Controller - DemandSituation Dialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Patric Karwat, SLSE, 2018-03-27
|
|
*/
|
|
|
|
#include "osc_demand_situation.h"
|
|
#include "ui_osc_demand_situation.h"
|
|
#include <AdvancedSymbology/asb_data_plugin_interface.h>
|
|
#include <Plugins/SituationMapPlugin/situation_map_gui_plugin_interface.h>
|
|
#include <PluginInterfaces/gui_plugin_interface.h>
|
|
#include <LtsUtilsSettings/settings.h>
|
|
#include <Map/map.h> // Interface
|
|
#include <QTreeView>
|
|
|
|
namespace OcSituationClient
|
|
{
|
|
|
|
DemandSituation::DemandSituation(LtsSession::LtsSession *session, QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
|
|
, m_session(session)
|
|
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
|
, m_selectedEqNr(0)
|
|
, m_ocDemandGroupString(QStringLiteral("ObserverControllerDemand"))
|
|
, m_ocDemandFilterGroupString(QStringLiteral("ObserverControllerDemandFilter"))
|
|
, m_opSettings(LtsUtils::OperatorSettings::getInstance())
|
|
, m_model(nullptr)
|
|
, m_proxyModel(nullptr)
|
|
, m_ui(new Ui::DemandSituation)
|
|
, m_logger(getLogger("DemandSituationDialog"))
|
|
{
|
|
m_ui->setupUi(this);
|
|
setOnlineHelpFilename(QStringLiteral("OC-Demand_Situation"));
|
|
}
|
|
|
|
DemandSituation::~DemandSituation()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
bool DemandSituation::init(const std::shared_ptr<Interface::Ftc> &ftc)
|
|
{
|
|
if (!ftc)
|
|
return false;
|
|
|
|
m_ftc = ftc;
|
|
|
|
std::shared_ptr<ParticipantManagement::Interface::Dtc> dtcPpm;
|
|
if (!m_session->getDtc<ParticipantManagement::DataInterface>(dtcPpm))
|
|
return false;
|
|
|
|
if (!m_session->getForeignGuiInterface<ParticipantManagement::ForeignGuiComboboxInterface>(m_ppmCbxGui))
|
|
return false;
|
|
|
|
if (!m_session->getForeignGuiInterface<SituationMap::ForeignGuiInterface>(m_sitMapGuiIfc))
|
|
return false;
|
|
//optional
|
|
m_session->getForeignGuiInterface<SituationMap::ForeignGuiInterface>(m_sitMapGuiIfc);
|
|
|
|
|
|
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> asb;
|
|
m_session->getForeignDataInterface<AdvancedSymbology::DataInterface>(asb);
|
|
m_model = new ParticipantManagement::ParticipantEditModel(this, dtcPpm, asb);
|
|
// only needed to set recursiveFilteringEnabled
|
|
m_proxyModel = new ParticipantManagement::ParticipantTreeFilterProxyModel(this);
|
|
m_proxyModel->setSourceModel(m_model);
|
|
m_proxyModel->setRecursiveFilteringEnabled(true);
|
|
m_ui->dvParticipants->setModel(m_proxyModel);
|
|
|
|
m_ppmCbxGui->fillPartyComboBox(m_ui->cbParty, ParticipantManagement::ForeignGuiComboboxInterface::CbxPartyFilter::NormalOc);
|
|
connect(m_ui->dvParticipants, &LtsDataView::LtsDataView::signalSelectionChanged,
|
|
this, &DemandSituation::onSlotSelectionChanged);
|
|
|
|
if (m_sitMapGuiIfc)
|
|
{
|
|
connect(m_ui->pbClear, &QPushButton::clicked, this, &DemandSituation::onClearCoordinate);
|
|
connect(m_ui->pbPos, &QPushButton::clicked, this, &DemandSituation::onGetPosition);
|
|
}
|
|
else
|
|
{
|
|
m_ui->pbPos->setEnabled(false);
|
|
}
|
|
|
|
connect(m_ui->cbParty, &LtsWidgets::LtsComboBox::currentTextChanged, this, [this]
|
|
{
|
|
m_model->onReinitModel(m_ui->cbParty->currentData().toInt());
|
|
m_ui->dvParticipants->expandAll();
|
|
});
|
|
|
|
connect(m_ui->slRange, &QSlider::valueChanged, this, [this](int range)
|
|
{
|
|
m_ui->lblRange->setText(QString::number(range));
|
|
repaintSitmapCircle();
|
|
});
|
|
|
|
m_model->onReinitModel(m_ui->cbParty->currentData().toInt());
|
|
m_ui->slRange->setValue(10);
|
|
m_ui->dvParticipants->expandAll();
|
|
m_ui->dvParticipants->setSortIndicator(0, Qt::AscendingOrder);
|
|
|
|
//load old settings
|
|
m_ui->slRange->setValue(m_opSettings->value(m_ocDemandGroupString, QStringLiteral("Range"), 100).toInt());
|
|
m_ui->cbParty->setCurrentIndex(m_ui->cbParty->findData(m_opSettings->value(m_ocDemandGroupString, QStringLiteral("Party"), 1).toInt()));
|
|
if (m_opSettings->value(m_ocDemandGroupString, QStringLiteral("ParticipantId"), 0).toInt() > 0)
|
|
{
|
|
const auto idx = m_model->indexFromParticipantId(m_opSettings->value(m_ocDemandGroupString, QStringLiteral("ParticipantId"), -1).toInt());
|
|
m_ui->dvParticipants->treeView()->setCurrentIndex(m_proxyModel->mapFromSource(idx));
|
|
m_ui->dtePos->clear();
|
|
}
|
|
else if (m_opSettings->value(m_ocDemandGroupString, QStringLiteral("PosLon"), -1).toDouble() > 0)
|
|
{
|
|
m_ui->dtePos->setCoordinate(m_opSettings->value(m_ocDemandGroupString, QStringLiteral("PosLon"), -1).toDouble(),
|
|
m_opSettings->value(m_ocDemandGroupString, QStringLiteral("PosLat"), -1).toDouble());
|
|
}
|
|
|
|
m_ui->cbFilter->setChecked(m_opSettings->value(m_ocDemandGroupString, QStringLiteral("FilterActive"), false).toBool());
|
|
|
|
connect(m_ui->pbClear, &QPushButton::clicked,
|
|
m_ui->dvParticipants->selectionModel(), &QItemSelectionModel::clearSelection);
|
|
|
|
__unchange__();
|
|
|
|
return true;
|
|
}
|
|
|
|
void DemandSituation::onSendDemandSituationReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (replyObject.str().empty())
|
|
{
|
|
// save new settings
|
|
m_opSettings->setValue(m_ocDemandGroupString, QStringLiteral("Range"), m_ui->slRange->value());
|
|
m_opSettings->setValue(m_ocDemandGroupString, QStringLiteral("Party"), m_ui->cbParty->currentData().toInt());
|
|
const auto selIndexes = m_ui->dvParticipants->selectedRows();
|
|
if (!selIndexes.isEmpty())
|
|
m_opSettings->setValue(m_ocDemandGroupString, QStringLiteral("ParticipantId"), m_model->getParticipantData(selIndexes.first()).id());
|
|
else
|
|
m_opSettings->setValue(m_ocDemandGroupString, QStringLiteral("ParticipantId"), 0);
|
|
|
|
m_opSettings->setValue(m_ocDemandGroupString, QStringLiteral("PosLon"), m_ui->dtePos->coordinate().x());
|
|
m_opSettings->setValue(m_ocDemandGroupString, QStringLiteral("PosLat"), m_ui->dtePos->coordinate().y());
|
|
|
|
m_opSettings->setValue(m_ocDemandGroupString, QStringLiteral("FilterActive"),m_ui->cbFilter->isChecked());
|
|
}
|
|
else
|
|
{
|
|
// reset to old settings
|
|
discardSitmapCircle();
|
|
}
|
|
m_requestHelper->requestReply(replyObject);
|
|
}
|
|
|
|
void DemandSituation::onSlotSelectionChanged()
|
|
{
|
|
m_selectedEqNr = 0;
|
|
|
|
const auto selIndexes = m_ui->dvParticipants->selectedRows();
|
|
if (!selIndexes.isEmpty())
|
|
{
|
|
ParticipantManagement::ParticipantData part = m_model->getParticipantData(selIndexes.first());
|
|
if (part.equipmentNumber().is_set())
|
|
{
|
|
//clear pos
|
|
onClearCoordinate();
|
|
|
|
m_selectedEqNr = part.equipmentNumber().get();
|
|
}
|
|
else
|
|
m_selectedEqNr = 0;
|
|
}
|
|
repaintSitmapCircle();
|
|
slotChangesMade();
|
|
}
|
|
|
|
void DemandSituation::onGetPosition()
|
|
{
|
|
//clear selection
|
|
m_ui->dvParticipants->selectionModel()->clearSelection();
|
|
m_sitMapGuiIfc->getCircle(this,
|
|
SLOT(onCoordinate(QPointF, double)),
|
|
nullptr,
|
|
m_ui->slRange->minimum(),
|
|
m_ui->slRange->maximum());
|
|
}
|
|
|
|
void DemandSituation::onCoordinate(const QPointF &coord, double radius)
|
|
{
|
|
m_ui->dtePos->setCoordinate(coord);
|
|
m_ui->slRange->setValue(static_cast<int>(radius));
|
|
repaintSitmapCircle();
|
|
slotChangesMade();
|
|
}
|
|
|
|
void DemandSituation::onClearCoordinate()
|
|
{
|
|
m_ui->dtePos->clear();
|
|
slotChangesMade();
|
|
}
|
|
|
|
void DemandSituation::retranslate()
|
|
{
|
|
translate(m_ui, tr("Demand Situation") );
|
|
m_uiRequirements->clear();
|
|
m_uiRequirements->addRequirement({m_ui->lbRange, [this]() { return !!(m_selectedEqNr >= 0 || m_ui->dtePos->coordinate().x() > 0 ); },
|
|
tr("Select none or one participant with equipment number or a position.")});
|
|
|
|
}
|
|
|
|
bool DemandSituation::apply()
|
|
{
|
|
// set filter
|
|
m_partys.clear();
|
|
m_typesClass.clear();
|
|
if(m_ui->cbFilter->isChecked())
|
|
{
|
|
m_filterActive = true;
|
|
QStringList partyList = m_opSettings->value(m_ocDemandFilterGroupString, QStringLiteral("Partys"),-1).toStringList();
|
|
for(const auto &s : partyList)
|
|
m_partys.push_back(s.toInt());
|
|
|
|
QStringList typeClassList = m_opSettings->value(m_ocDemandFilterGroupString, QStringLiteral("TypeClass"),-1).toStringList();
|
|
for(const auto &s : typeClassList)
|
|
m_typesClass.push_back(s.toInt());
|
|
}
|
|
else
|
|
{
|
|
m_filterActive = false;
|
|
}
|
|
|
|
SendDemandSituationRequest req(m_selectedEqNr,
|
|
m_ui->slRange->value(),
|
|
dds::core::optional<Core::GeoPosition2D>(),
|
|
m_filterActive,
|
|
m_partys,
|
|
m_typesClass);
|
|
|
|
bool bret;
|
|
bool stopDemand = false;
|
|
if (m_ui->dtePos->coordinate().isNull() && m_selectedEqNr == 0)
|
|
{
|
|
req.radius() = 0;
|
|
const Core::GeoPosition2D pos(std::nan(""),std::nan(""));
|
|
req.position() = pos;
|
|
stopDemand = true;
|
|
}
|
|
else if (m_ui->dtePos->coordinate().x() > 0)
|
|
{
|
|
const Core::GeoPosition2D pos(m_ui->dtePos->coordinate().x(), m_ui->dtePos->coordinate().y() );
|
|
req.position().set(pos);
|
|
}
|
|
|
|
|
|
|
|
bret = m_requestHelper->startSingleRequest([req, this]()
|
|
{
|
|
return m_ftc->sendDemandSituationRequest(req, this);
|
|
});
|
|
|
|
if (bret && stopDemand)
|
|
emit demandSituationStopped();
|
|
|
|
return bret;
|
|
}
|
|
|
|
void DemandSituation::dialogCanceled()
|
|
{
|
|
discardSitmapCircle();
|
|
}
|
|
|
|
void DemandSituation::repaintSitmapCircle()
|
|
{
|
|
double range = static_cast<double>(m_ui->slRange->value());
|
|
const auto selIndexes = m_ui->dvParticipants->selectedRows();
|
|
if (!selIndexes.isEmpty())
|
|
{
|
|
m_sitMapGuiIfc->ocSituationRange_create(m_model->getParticipantData(selIndexes.first()).id(), range);
|
|
}
|
|
else if (!m_ui->dtePos->coordinate().isNull())
|
|
{
|
|
QPointF pos(m_ui->dtePos->coordinate().x(),
|
|
m_ui->dtePos->coordinate().y());
|
|
|
|
m_sitMapGuiIfc->ocSituationRange_create(pos, range);
|
|
}
|
|
else
|
|
{
|
|
m_sitMapGuiIfc->ocSituationRange_remove();
|
|
}
|
|
}
|
|
|
|
void DemandSituation::discardSitmapCircle()
|
|
{
|
|
//load old settings
|
|
double range = static_cast<double>(m_opSettings->value(m_ocDemandGroupString, QStringLiteral("Range"), 100).toInt());
|
|
int participantId = m_opSettings->value(m_ocDemandGroupString, QStringLiteral("ParticipantId"), 0).toInt();
|
|
if (participantId > 0)
|
|
{
|
|
m_sitMapGuiIfc->ocSituationRange_create(participantId, range);
|
|
}
|
|
else if (m_opSettings->value(m_ocDemandGroupString, QStringLiteral("PosLon"), -1).toDouble() > 0)
|
|
{
|
|
QPointF pos(m_opSettings->value(m_ocDemandGroupString, QStringLiteral("PosLon"), -1).toDouble(),
|
|
m_opSettings->value(m_ocDemandGroupString, QStringLiteral("PosLat"), -1).toDouble());
|
|
|
|
m_sitMapGuiIfc->ocSituationRange_create(pos, range);
|
|
}
|
|
else // no oc sitmap selected
|
|
{
|
|
m_sitMapGuiIfc->ocSituationRange_remove();
|
|
}
|
|
}
|
|
|
|
} // namespace OcSituationClient
|