Apply clang-format to Lts/Common and DTC/enum headers
- Formatted all CodeGen module files (9 files) - Formatted LtsAppDescriptor module files - Formatted LtsAppManager/AppChooser files - Applied clang-format to all DTC and enum headers across modules - Removed coordTransTests from CommonUnitTestsPlaceholder (moved to tests/) Cosmetic changes only, no functional modifications. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
848 files changed
+89305
-100020
No files matched your search
Executable → Regular
+184
-218
@@ -1,338 +1,304 @@
|
||||
|
||||
|
||||
|
||||
#include "bdv_building_edit.h"
|
||||
|
||||
#include "bdv_edit_item.h"
|
||||
#include "ui_bdv_building_edit.h"
|
||||
|
||||
#include <LtsSession/lts_session_data.h>
|
||||
#include <LtsUtilsSettings/settings.h>
|
||||
|
||||
#include <Buildings/bld_operator_rights.h>
|
||||
#include <Buildings/bld.hpp>
|
||||
#include <Buildings/bld_ftc.h>
|
||||
|
||||
#include <Buildings/bld_operator_rights.h>
|
||||
#include <LtsSession/lts_session_data.h>
|
||||
#include <LtsUtilsSettings/settings.h>
|
||||
#include <nglwidgets/ngltreeitem.h>
|
||||
|
||||
namespace BuildingViewer
|
||||
{
|
||||
BuildingEdit::BuildingEdit(QWidget *parent)
|
||||
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
|
||||
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
||||
, m_ui(new Ui::BuildingEdit)
|
||||
BuildingEdit::BuildingEdit(QWidget* parent)
|
||||
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel),
|
||||
m_requestHelper(new LtsUtils::RequestHelper(this)), m_ui(new Ui::BuildingEdit)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_ui->setupUi(this);
|
||||
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Ok)->hide();
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &BuildingEdit::slotEditItem);
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Ok)->hide();
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &BuildingEdit::slotEditItem);
|
||||
|
||||
bool userHasRightsToEdit = LtsSessionData::LtsSessionData::getInstance()->hasOperatorRight(OperatorRights::BuildingViewerSettingsEdit);
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Edit)->setVisible(userHasRightsToEdit);
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Apply)->setVisible(userHasRightsToEdit);
|
||||
bool userHasRightsToEdit =
|
||||
LtsSessionData::LtsSessionData::getInstance()->hasOperatorRight(OperatorRights::BuildingViewerSettingsEdit);
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Edit)->setVisible(userHasRightsToEdit);
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Apply)->setVisible(userHasRightsToEdit);
|
||||
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Edit)->setEnabled(false);
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Edit)->setEnabled(false);
|
||||
|
||||
LtsUtils::ProjectSettings *ps = LtsUtils::ProjectSettings::getInstance();
|
||||
const bool enableGuiDestroyRooms = ps->value(QStringLiteral("bld"),
|
||||
QStringLiteral("enableGuiDestroyRooms")).toBool();
|
||||
|
||||
auto btnDestroy = m_buttonBox->getButton(LtsWidgets::DialogButton::Add);
|
||||
btnDestroy->setText(tr("Destroy"));
|
||||
btnDestroy->setVisible(enableGuiDestroyRooms);
|
||||
LtsUtils::ProjectSettings* ps = LtsUtils::ProjectSettings::getInstance();
|
||||
const bool enableGuiDestroyRooms =
|
||||
ps->value(QStringLiteral("bld"), QStringLiteral("enableGuiDestroyRooms")).toBool();
|
||||
|
||||
connect(btnDestroy, &QPushButton::pressed, this, &BuildingEdit::onDestroyElement);
|
||||
auto btnDestroy = m_buttonBox->getButton(LtsWidgets::DialogButton::Add);
|
||||
btnDestroy->setText(tr("Destroy"));
|
||||
btnDestroy->setVisible(enableGuiDestroyRooms);
|
||||
|
||||
connect(btnDestroy, &QPushButton::pressed, this, &BuildingEdit::onDestroyElement);
|
||||
|
||||
setOnlineHelpFilename(QStringLiteral("Building_Viewer-Building_List"));
|
||||
setOnlineHelpFilename(QStringLiteral("Building_Viewer-Building_List"));
|
||||
}
|
||||
|
||||
|
||||
BuildingEdit::~BuildingEdit()
|
||||
{
|
||||
delete m_ui;
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
|
||||
void BuildingEdit::retranslate()
|
||||
{
|
||||
translate(m_ui, tr("Building Edit: %1").arg(m_buildingName));
|
||||
translate(m_ui, tr("Building Edit: %1").arg(m_buildingName));
|
||||
}
|
||||
|
||||
|
||||
bool BuildingEdit::init(int32_t buildingDatabaseId,
|
||||
const std::shared_ptr<InfrastructureManagement::Interface::Dtc> &ismDtc,
|
||||
const std::shared_ptr<InfrastructureManagement::Interface::Ftc> &ismFtc,
|
||||
const std::shared_ptr<Buildings::Interface::Dtc> &bldDtc,
|
||||
const std::shared_ptr<Buildings::Interface::Ftc> &bldFtc)
|
||||
const std::shared_ptr<InfrastructureManagement::Interface::Dtc>& ismDtc,
|
||||
const std::shared_ptr<InfrastructureManagement::Interface::Ftc>& ismFtc,
|
||||
const std::shared_ptr<Buildings::Interface::Dtc>& bldDtc,
|
||||
const std::shared_ptr<Buildings::Interface::Ftc>& bldFtc)
|
||||
{
|
||||
if (m_ismDtc)
|
||||
return false;
|
||||
m_buildingDatabaseId = buildingDatabaseId;
|
||||
if (m_ismDtc)
|
||||
return false;
|
||||
m_buildingDatabaseId = buildingDatabaseId;
|
||||
|
||||
m_ismDtc = ismDtc;
|
||||
m_ismFtc = ismFtc;
|
||||
m_bldDtc = bldDtc;
|
||||
m_bldFtc = bldFtc;
|
||||
m_ismDtc = ismDtc;
|
||||
m_ismFtc = ismFtc;
|
||||
m_bldDtc = bldDtc;
|
||||
m_bldFtc = bldFtc;
|
||||
|
||||
|
||||
InfrastructureManagement::MainStructureElement building = m_ismDtc->mainStructureElement(m_buildingDatabaseId);
|
||||
m_buildingId = building.id();
|
||||
InfrastructureManagement::MainStructureElement building = m_ismDtc->mainStructureElement(m_buildingDatabaseId);
|
||||
m_buildingId = building.id();
|
||||
|
||||
buildModel();
|
||||
m_buildingName = m_model->getBuildingName();
|
||||
buildModel();
|
||||
m_buildingName = m_model->getBuildingName();
|
||||
|
||||
if (LtsSessionData::LtsSessionData::getInstance()->hasOperatorRight(OperatorRights::BuildingViewerSettingsEdit))
|
||||
{
|
||||
connect(m_ui->treeViewEdit, &QTreeView::clicked, this, &BuildingEdit::slotTreeViewClicked);
|
||||
connect(m_ui->treeViewEdit, &QTreeView::doubleClicked, this, &BuildingEdit::slotDoubleClicked);
|
||||
connect(m_model, &BuildingEditModel::signalModelDataChanged, this, &BuildingEdit::slotChangesMade);
|
||||
}
|
||||
if (LtsSessionData::LtsSessionData::getInstance()->hasOperatorRight(OperatorRights::BuildingViewerSettingsEdit))
|
||||
{
|
||||
connect(m_ui->treeViewEdit, &QTreeView::clicked, this, &BuildingEdit::slotTreeViewClicked);
|
||||
connect(m_ui->treeViewEdit, &QTreeView::doubleClicked, this, &BuildingEdit::slotDoubleClicked);
|
||||
connect(m_model, &BuildingEditModel::signalModelDataChanged, this, &BuildingEdit::slotChangesMade);
|
||||
}
|
||||
|
||||
connect(m_ismDtc.get(), &InfrastructureManagement::Interface::Dtc::mainStructureElementChanged,
|
||||
this, &BuildingEdit::slotMainStructureElementChanged);
|
||||
connect(m_ismDtc.get(), &InfrastructureManagement::Interface::Dtc::mainStructureElementChanged, this,
|
||||
&BuildingEdit::slotMainStructureElementChanged);
|
||||
|
||||
connect(m_bldDtc.get(), &Buildings::Interface::Dtc::buildingStateChanged,
|
||||
this, &BuildingEdit::slotBuildingStateChanged);
|
||||
connect(m_bldDtc.get(), &Buildings::Interface::Dtc::buildingStateChanged, this,
|
||||
&BuildingEdit::slotBuildingStateChanged);
|
||||
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void BuildingEdit::slotTreeViewClicked()
|
||||
{
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Edit)->setEnabled(selectedIndexView().isValid());
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Edit)->setEnabled(selectedIndexView().isValid());
|
||||
}
|
||||
|
||||
|
||||
void BuildingEdit::buildModel()
|
||||
{
|
||||
m_model = new BuildingEditModel(this, m_ismDtc, m_bldDtc);
|
||||
m_model = new BuildingEditModel(this, m_ismDtc, m_bldDtc);
|
||||
|
||||
|
||||
m_proxyModel = new BuildingEditProxyModel(this);
|
||||
m_proxyModel->setSourceModel(m_model);
|
||||
m_proxyModel = new BuildingEditProxyModel(this);
|
||||
m_proxyModel->setSourceModel(m_model);
|
||||
|
||||
|
||||
m_ui->treeViewEdit->setModel(m_proxyModel);
|
||||
m_ui->treeViewEdit->expandAll();
|
||||
m_ui->treeViewEdit->sortByColumn(BuildingEditModel::Building, Qt::AscendingOrder);
|
||||
m_ui->treeViewEdit->setModel(m_proxyModel);
|
||||
m_ui->treeViewEdit->expandAll();
|
||||
m_ui->treeViewEdit->sortByColumn(BuildingEditModel::Building, Qt::AscendingOrder);
|
||||
|
||||
|
||||
m_ui->treeViewEdit->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
m_ui->treeViewEdit->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
m_model->init(m_buildingDatabaseId);
|
||||
m_ui->treeViewEdit->expandAll();
|
||||
m_ui->treeViewEdit->setColumnWidth(BuildingEditModel::Building, 230);
|
||||
m_model->init(m_buildingDatabaseId);
|
||||
m_ui->treeViewEdit->expandAll();
|
||||
m_ui->treeViewEdit->setColumnWidth(BuildingEditModel::Building, 230);
|
||||
#ifdef LTS_DEBUG
|
||||
m_ui->treeViewEdit->setColumnWidth(BuildingEditModel::Name, 150);
|
||||
m_ui->treeViewEdit->setColumnWidth(BuildingEditModel::MountingPointId, 120);
|
||||
m_ui->treeViewEdit->setColumnWidth(BuildingEditModel::StructureElementId, 80);
|
||||
m_ui->treeViewEdit->setColumnWidth(BuildingEditModel::Name, 150);
|
||||
m_ui->treeViewEdit->setColumnWidth(BuildingEditModel::MountingPointId, 120);
|
||||
m_ui->treeViewEdit->setColumnWidth(BuildingEditModel::StructureElementId, 80);
|
||||
#else
|
||||
m_ui->treeViewEdit->hideColumn(BuildingEditModel::Name);
|
||||
m_ui->treeViewEdit->hideColumn(BuildingEditModel::MountingPointId);
|
||||
m_ui->treeViewEdit->hideColumn(BuildingEditModel::StructureElementId);
|
||||
m_ui->treeViewEdit->hideColumn(BuildingEditModel::Name);
|
||||
m_ui->treeViewEdit->hideColumn(BuildingEditModel::MountingPointId);
|
||||
m_ui->treeViewEdit->hideColumn(BuildingEditModel::StructureElementId);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
QModelIndex BuildingEdit::selectedIndexView() const
|
||||
{
|
||||
QItemSelectionModel *selectionModel = m_ui->treeViewEdit->selectionModel();
|
||||
QModelIndexList indexL = selectionModel->selectedRows(0);
|
||||
if (indexL.size() == 0)
|
||||
return QModelIndex();
|
||||
QItemSelectionModel* selectionModel = m_ui->treeViewEdit->selectionModel();
|
||||
QModelIndexList indexL = selectionModel->selectedRows(0);
|
||||
if (indexL.size() == 0)
|
||||
return QModelIndex();
|
||||
|
||||
return m_proxyModel->mapToSource(indexL.at(0));
|
||||
return m_proxyModel->mapToSource(indexL.at(0));
|
||||
}
|
||||
|
||||
|
||||
void BuildingEdit::slotEditItem()
|
||||
{
|
||||
QModelIndex selIndex = selectedIndexView();
|
||||
if (!selIndex.isValid())
|
||||
return;
|
||||
QModelIndex selIndex = selectedIndexView();
|
||||
if (!selIndex.isValid())
|
||||
return;
|
||||
|
||||
BuildingViewer::TreeItem data = m_model->privateData(selIndex)->data().value<TreeItem>();
|
||||
BuildingViewer::TreeItem data = m_model->privateData(selIndex)->data().value<TreeItem>();
|
||||
|
||||
ParticipantEditItemWidget *newItemDlg = new ParticipantEditItemWidget(m_buildingName, data, this);
|
||||
newItemDlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
ParticipantEditItemWidget* newItemDlg = new ParticipantEditItemWidget(m_buildingName, data, this);
|
||||
newItemDlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
connect(newItemDlg, &ParticipantEditItemWidget::signalItemUpdated,
|
||||
m_model, &BuildingEditModel::slotUpdateRow);
|
||||
connect(newItemDlg, &ParticipantEditItemWidget::signalItemUpdated, m_model, &BuildingEditModel::slotUpdateRow);
|
||||
|
||||
newItemDlg->show();
|
||||
newItemDlg->show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool BuildingEdit::apply()
|
||||
{
|
||||
|
||||
|
||||
const auto fortifyFactors = m_model->getRoomsWithChangedFortifyFactors();
|
||||
|
||||
const auto fortifyFactors = m_model->getRoomsWithChangedFortifyFactors();
|
||||
|
||||
|
||||
DEBUG_LOG(m_logger) << "fortifyFactors.size()=" << fortifyFactors.size();
|
||||
if (fortifyFactors.size())
|
||||
{
|
||||
m_requestHelper->addRequest([this, fortifyFactors]()
|
||||
DEBUG_LOG(m_logger) << "fortifyFactors.size()=" << fortifyFactors.size();
|
||||
if (fortifyFactors.size())
|
||||
{
|
||||
Buildings::SetFortifyFactorRequest fortifyRequest;
|
||||
fortifyRequest.buildingId(m_buildingDatabaseId);
|
||||
m_requestHelper->addRequest([this, fortifyFactors]() {
|
||||
Buildings::SetFortifyFactorRequest fortifyRequest;
|
||||
fortifyRequest.buildingId(m_buildingDatabaseId);
|
||||
|
||||
|
||||
fortifyRequest.fortifyFactors().reserve(fortifyFactors.size());
|
||||
for (const auto &e : fortifyFactors)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "push_back= databaseId=" << e.structureElementId()
|
||||
<< " fortifyFactor=" << e.fortifyFactor();
|
||||
fortifyRequest.fortifyFactors().push_back(Buildings::FortifyFactor(e.structureElementId(), e.fortifyFactor()));
|
||||
}
|
||||
fortifyRequest.fortifyFactors().reserve(fortifyFactors.size());
|
||||
for (const auto& e : fortifyFactors)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "push_back= databaseId=" << e.structureElementId()
|
||||
<< " fortifyFactor=" << e.fortifyFactor();
|
||||
fortifyRequest.fortifyFactors().push_back(
|
||||
Buildings::FortifyFactor(e.structureElementId(), e.fortifyFactor()));
|
||||
}
|
||||
|
||||
return m_bldFtc->setFortifyFactorRequest(fortifyRequest, this);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const auto displayNames = m_model->getRoomsWithChangedDisplayNames();
|
||||
|
||||
|
||||
|
||||
if (displayNames.size())
|
||||
{
|
||||
std::vector<InfrastructureManagement::StructureElement> vecModifiedRooms;
|
||||
vecModifiedRooms.reserve(displayNames.size());
|
||||
InfrastructureManagement::MainStructureElement building = m_ismDtc->mainStructureElement(m_buildingDatabaseId);
|
||||
|
||||
for (const auto &treeItem : displayNames)
|
||||
{
|
||||
|
||||
for (const auto &room : building.elements())
|
||||
{
|
||||
if (room.id() == treeItem.structureElementId())
|
||||
{
|
||||
auto copy = room;
|
||||
copy.displayName(treeItem.displayName().toStdString());
|
||||
vecModifiedRooms.push_back(copy);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return m_bldFtc->setFortifyFactorRequest(fortifyRequest, this);
|
||||
});
|
||||
}
|
||||
|
||||
m_requestHelper->addRequest([this, vecModifiedRooms]()
|
||||
{
|
||||
InfrastructureManagement::StructureElementModifyRequest request(m_buildingDatabaseId, vecModifiedRooms);
|
||||
return m_ismFtc->structureElementModifyRequest(request, this);
|
||||
});
|
||||
}
|
||||
return m_requestHelper->startRequests();
|
||||
}
|
||||
const auto displayNames = m_model->getRoomsWithChangedDisplayNames();
|
||||
|
||||
if (displayNames.size())
|
||||
{
|
||||
std::vector<InfrastructureManagement::StructureElement> vecModifiedRooms;
|
||||
vecModifiedRooms.reserve(displayNames.size());
|
||||
InfrastructureManagement::MainStructureElement building = m_ismDtc->mainStructureElement(m_buildingDatabaseId);
|
||||
|
||||
for (const auto& treeItem : displayNames)
|
||||
{
|
||||
|
||||
for (const auto& room : building.elements())
|
||||
{
|
||||
if (room.id() == treeItem.structureElementId())
|
||||
{
|
||||
auto copy = room;
|
||||
copy.displayName(treeItem.displayName().toStdString());
|
||||
vecModifiedRooms.push_back(copy);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_requestHelper->addRequest([this, vecModifiedRooms]() {
|
||||
InfrastructureManagement::StructureElementModifyRequest request(m_buildingDatabaseId, vecModifiedRooms);
|
||||
return m_ismFtc->structureElementModifyRequest(request, this);
|
||||
});
|
||||
}
|
||||
return m_requestHelper->startRequests();
|
||||
}
|
||||
|
||||
void BuildingEdit::selectRoomRow(int mountingPointId)
|
||||
{
|
||||
QModelIndex mIndex = m_model->modelIndexByStructureElementId(mountingPointId);
|
||||
m_ui->treeViewEdit->setCurrentIndex(mIndex);
|
||||
m_ui->treeViewEdit->selectionModel()->setCurrentIndex(mIndex, QItemSelectionModel::ClearAndSelect);
|
||||
QModelIndex mIndex = m_model->modelIndexByStructureElementId(mountingPointId);
|
||||
m_ui->treeViewEdit->setCurrentIndex(mIndex);
|
||||
m_ui->treeViewEdit->selectionModel()->setCurrentIndex(mIndex, QItemSelectionModel::ClearAndSelect);
|
||||
}
|
||||
|
||||
|
||||
void BuildingEdit::reinitModel()
|
||||
{
|
||||
m_model->init(m_buildingDatabaseId);
|
||||
m_ui->treeViewEdit->expandAll();
|
||||
m_model->init(m_buildingDatabaseId);
|
||||
m_ui->treeViewEdit->expandAll();
|
||||
}
|
||||
|
||||
|
||||
void BuildingEdit::slotDoubleClicked(const QModelIndex &selIndex)
|
||||
void BuildingEdit::slotDoubleClicked(const QModelIndex& selIndex)
|
||||
{
|
||||
if (!selIndex.isValid())
|
||||
return;
|
||||
if (!selIndex.isValid())
|
||||
return;
|
||||
|
||||
slotEditItem();
|
||||
slotEditItem();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void BuildingEdit::slotMainStructureElementChanged(const InfrastructureManagement::MainStructureElement &mse, DataModification modType)
|
||||
void BuildingEdit::slotMainStructureElementChanged(const InfrastructureManagement::MainStructureElement& mse,
|
||||
DataModification modType)
|
||||
{
|
||||
if(modType == DataModification::eRemoved)
|
||||
return;
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
if(mse.id() == m_buildingDatabaseId)
|
||||
{
|
||||
|
||||
slotHandleExternalDdsChange();
|
||||
}
|
||||
if (mse.id() == m_buildingDatabaseId)
|
||||
{
|
||||
|
||||
slotHandleExternalDdsChange();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BuildingEdit::slotBuildingStateChanged(const Buildings::BuildingState &state, DataModification modType)
|
||||
void BuildingEdit::slotBuildingStateChanged(const Buildings::BuildingState& state, DataModification modType)
|
||||
{
|
||||
if(modType == DataModification::eRemoved)
|
||||
return;
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
if(state.id() == m_buildingDatabaseId)
|
||||
{
|
||||
|
||||
slotHandleExternalDdsChange();
|
||||
}
|
||||
if (state.id() == m_buildingDatabaseId)
|
||||
{
|
||||
|
||||
slotHandleExternalDdsChange();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BuildingEdit::slotHandleExternalDdsChange()
|
||||
{
|
||||
reinitModel();
|
||||
reinitModel();
|
||||
}
|
||||
|
||||
bool BuildingEdit::sendBuildingStateRequest(ProjectDataManagement::VulnerabilityState state, std::vector<int32_t> structureElementIds)
|
||||
bool BuildingEdit::sendBuildingStateRequest(ProjectDataManagement::VulnerabilityState state,
|
||||
std::vector<int32_t> structureElementIds)
|
||||
{
|
||||
|
||||
m_requestHelper->addRequest([this, state, structureElementIds]()
|
||||
{
|
||||
Buildings::Building building;
|
||||
std::vector< Buildings::Building > buildings;
|
||||
buildings.resize(1);
|
||||
Buildings::SetBuildingStatesRequest requestData;
|
||||
|
||||
building.buildingId(m_buildingId);
|
||||
building.roomIds().set(structureElementIds);
|
||||
buildings[0] = building;
|
||||
requestData.buildings(buildings);
|
||||
requestData.vulnerabilityState(state);
|
||||
|
||||
DEBUG_LOG(m_logger) << Q_FUNC_INFO << "currentData: " << state;
|
||||
m_requestHelper->addRequest([this, state, structureElementIds]() {
|
||||
Buildings::Building building;
|
||||
std::vector<Buildings::Building> buildings;
|
||||
buildings.resize(1);
|
||||
Buildings::SetBuildingStatesRequest requestData;
|
||||
|
||||
return m_bldFtc->setBuildingStatesRequest(requestData, this);
|
||||
});
|
||||
building.buildingId(m_buildingId);
|
||||
building.roomIds().set(structureElementIds);
|
||||
buildings[0] = building;
|
||||
requestData.buildings(buildings);
|
||||
requestData.vulnerabilityState(state);
|
||||
|
||||
return m_requestHelper->startRequests();
|
||||
DEBUG_LOG(m_logger) << Q_FUNC_INFO << "currentData: " << state;
|
||||
|
||||
return m_bldFtc->setBuildingStatesRequest(requestData, this);
|
||||
});
|
||||
|
||||
return m_requestHelper->startRequests();
|
||||
}
|
||||
|
||||
void BuildingEdit::onDestroyElement()
|
||||
{
|
||||
QModelIndex selIndex = selectedIndexView();
|
||||
if (!selIndex.isValid())
|
||||
return;
|
||||
QModelIndex selIndex = selectedIndexView();
|
||||
if (!selIndex.isValid())
|
||||
return;
|
||||
|
||||
std::vector<int32_t> structureElementIds;
|
||||
getStructureElementIds(m_model->privateData(selIndex), structureElementIds);
|
||||
std::vector<int32_t> structureElementIds;
|
||||
getStructureElementIds(m_model->privateData(selIndex), structureElementIds);
|
||||
|
||||
sendBuildingStateRequest(ProjectDataManagement::VulnerabilityState_def::CatastrophicKill, structureElementIds);
|
||||
sendBuildingStateRequest(ProjectDataManagement::VulnerabilityState_def::CatastrophicKill, structureElementIds);
|
||||
}
|
||||
|
||||
void BuildingEdit::getStructureElementIds(NGLTreeItem *item, std::vector<int32_t> &structureElementIds)
|
||||
void BuildingEdit::getStructureElementIds(NGLTreeItem* item, std::vector<int32_t>& structureElementIds)
|
||||
{
|
||||
for (NGLTreeItem *child : item->children())
|
||||
getStructureElementIds(child, structureElementIds);
|
||||
for (NGLTreeItem* child : item->children())
|
||||
getStructureElementIds(child, structureElementIds);
|
||||
|
||||
BuildingViewer::TreeItem data = item->data().value<TreeItem>();
|
||||
if (data.isRoom())
|
||||
structureElementIds.push_back(data.structureElementId());
|
||||
BuildingViewer::TreeItem data = item->data().value<TreeItem>();
|
||||
if (data.isRoom())
|
||||
structureElementIds.push_back(data.structureElementId());
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace BuildingViewer
|
||||
Executable → Regular
+64
-56
@@ -1,19 +1,15 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "bdv_edit_model.h"
|
||||
|
||||
|
||||
#include <Common/logger.h>
|
||||
#include <LtsUtils/LtsUtilsGui/LtsUtilsGuiDds/request_helper.h>
|
||||
#include <LtsWidgets/lts_dialog.h>
|
||||
#include <Plugins/Buildings/bld_data_plugin_interface.h>
|
||||
#include <Plugins/InfrastructureManagement/ism_data_plugin_interface.h>
|
||||
|
||||
#include <LtsWidgets/lts_dialog.h>
|
||||
#include <LtsUtils/LtsUtilsGui/LtsUtilsGuiDds/request_helper.h>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class BuildingEdit;
|
||||
@@ -21,68 +17,80 @@ class BuildingEdit;
|
||||
|
||||
namespace BuildingViewer
|
||||
{
|
||||
class BuildingEdit : public LtsWidgets::LtsDialog
|
||||
, protected Buildings::Interface::Ftc::SetFortifyFactorReplyHandler
|
||||
, protected Buildings::Interface::Ftc::SetBuildingStatesReplyHandler
|
||||
, protected InfrastructureManagement::Interface::Ftc::StructureElementModifyReplyHandler
|
||||
class BuildingEdit : public LtsWidgets::LtsDialog,
|
||||
protected Buildings::Interface::Ftc::SetFortifyFactorReplyHandler,
|
||||
protected Buildings::Interface::Ftc::SetBuildingStatesReplyHandler,
|
||||
protected InfrastructureManagement::Interface::Ftc::StructureElementModifyReplyHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BuildingEdit(QWidget *parent = nullptr);
|
||||
~BuildingEdit();
|
||||
public:
|
||||
explicit BuildingEdit(QWidget* parent = nullptr);
|
||||
~BuildingEdit();
|
||||
|
||||
bool init(int32_t buildingDatabaseId,
|
||||
const std::shared_ptr<InfrastructureManagement::Interface::Dtc> &ismDtc,
|
||||
const std::shared_ptr<InfrastructureManagement::Interface::Ftc> &ismFtc,
|
||||
const std::shared_ptr<Buildings::Interface::Dtc> &bldDtc,
|
||||
const std::shared_ptr<Buildings::Interface::Ftc> &bldFtc);
|
||||
bool init(int32_t buildingDatabaseId, const std::shared_ptr<InfrastructureManagement::Interface::Dtc>& ismDtc,
|
||||
const std::shared_ptr<InfrastructureManagement::Interface::Ftc>& ismFtc,
|
||||
const std::shared_ptr<Buildings::Interface::Dtc>& bldDtc,
|
||||
const std::shared_ptr<Buildings::Interface::Ftc>& bldFtc);
|
||||
|
||||
void onSetFortifyFactorReply(const Core::FunctionReplyObject &replyObject) override final { m_requestHelper->requestReply(replyObject); }
|
||||
void onSetBuildingStatesReply(const Core::FunctionReplyObject &replyObject) override final { m_requestHelper->requestReply(replyObject); }
|
||||
void onStructureElementModifyReply(const Core::FunctionReplyObject &replyObject) override final { m_requestHelper->requestReply(replyObject); }
|
||||
void selectRoomRow(int mountingPointId);
|
||||
void onSetFortifyFactorReply(const Core::FunctionReplyObject& replyObject) override final
|
||||
{
|
||||
m_requestHelper->requestReply(replyObject);
|
||||
}
|
||||
|
||||
signals:
|
||||
void signalAccept();
|
||||
void onSetBuildingStatesReply(const Core::FunctionReplyObject& replyObject) override final
|
||||
{
|
||||
m_requestHelper->requestReply(replyObject);
|
||||
}
|
||||
|
||||
private slots:
|
||||
void slotEditItem();
|
||||
void slotDoubleClicked(const QModelIndex &selIndex);
|
||||
void slotMainStructureElementChanged(const InfrastructureManagement::MainStructureElement &mse, DataModification modType);
|
||||
void slotBuildingStateChanged(const Buildings::BuildingState &state, DataModification modType);
|
||||
void slotHandleExternalDdsChange();
|
||||
void slotTreeViewClicked();
|
||||
void onStructureElementModifyReply(const Core::FunctionReplyObject& replyObject) override final
|
||||
{
|
||||
m_requestHelper->requestReply(replyObject);
|
||||
}
|
||||
|
||||
bool sendBuildingStateRequest(ProjectDataManagement::VulnerabilityState state, std::vector<int32_t> structureElementId);
|
||||
void onDestroyElement();
|
||||
void selectRoomRow(int mountingPointId);
|
||||
|
||||
protected:
|
||||
signals:
|
||||
void signalAccept();
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
void retranslate() override;
|
||||
bool apply() override;
|
||||
private slots:
|
||||
void slotEditItem();
|
||||
void slotDoubleClicked(const QModelIndex& selIndex);
|
||||
void slotMainStructureElementChanged(const InfrastructureManagement::MainStructureElement& mse,
|
||||
DataModification modType);
|
||||
void slotBuildingStateChanged(const Buildings::BuildingState& state, DataModification modType);
|
||||
void slotHandleExternalDdsChange();
|
||||
void slotTreeViewClicked();
|
||||
|
||||
private:
|
||||
void getStructureElementIds(NGLTreeItem *item, std::vector<int32_t> &structureElementIds);
|
||||
void buildModel();
|
||||
QModelIndex selectedIndexView() const;
|
||||
void reinitModel();
|
||||
bool sendBuildingStateRequest(ProjectDataManagement::VulnerabilityState state,
|
||||
std::vector<int32_t> structureElementId);
|
||||
void onDestroyElement();
|
||||
|
||||
private:
|
||||
std::shared_ptr<InfrastructureManagement::Interface::Dtc> m_ismDtc;
|
||||
std::shared_ptr<InfrastructureManagement::Interface::Ftc> m_ismFtc;
|
||||
std::shared_ptr<Buildings::Interface::Dtc> m_bldDtc;
|
||||
std::shared_ptr<Buildings::Interface::Ftc> m_bldFtc;
|
||||
protected:
|
||||
NGL::INGLLogger& m_logger;
|
||||
void retranslate() override;
|
||||
bool apply() override;
|
||||
|
||||
BuildingEditModel *m_model = nullptr;
|
||||
BuildingEditProxyModel *m_proxyModel = nullptr;
|
||||
LtsUtils::RequestHelper *m_requestHelper = nullptr;
|
||||
Ui::BuildingEdit *m_ui = nullptr;
|
||||
private:
|
||||
void getStructureElementIds(NGLTreeItem* item, std::vector<int32_t>& structureElementIds);
|
||||
void buildModel();
|
||||
QModelIndex selectedIndexView() const;
|
||||
void reinitModel();
|
||||
|
||||
QString m_buildingName;
|
||||
int32_t m_buildingDatabaseId = 0;
|
||||
int32_t m_buildingId = 0;
|
||||
private:
|
||||
std::shared_ptr<InfrastructureManagement::Interface::Dtc> m_ismDtc;
|
||||
std::shared_ptr<InfrastructureManagement::Interface::Ftc> m_ismFtc;
|
||||
std::shared_ptr<Buildings::Interface::Dtc> m_bldDtc;
|
||||
std::shared_ptr<Buildings::Interface::Ftc> m_bldFtc;
|
||||
|
||||
BuildingEditModel* m_model = nullptr;
|
||||
BuildingEditProxyModel* m_proxyModel = nullptr;
|
||||
LtsUtils::RequestHelper* m_requestHelper = nullptr;
|
||||
Ui::BuildingEdit* m_ui = nullptr;
|
||||
|
||||
QString m_buildingName;
|
||||
int32_t m_buildingDatabaseId = 0;
|
||||
int32_t m_buildingId = 0;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace BuildingViewer
|
||||
Executable → Regular
+213
-242
@@ -1,297 +1,268 @@
|
||||
|
||||
|
||||
|
||||
#include "bdv_edit_model.h"
|
||||
#include <utility>
|
||||
#include <Common/logger.h>
|
||||
#include <Services/InfrastructureManagement/ism.hpp>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QTableWidget>
|
||||
#include <QPalette>
|
||||
#include <QApplication>
|
||||
|
||||
#include <Common/logger.h>
|
||||
#include <QApplication>
|
||||
#include <QPalette>
|
||||
#include <QTableWidget>
|
||||
#include <QtCore/QDebug>
|
||||
#include <Services/InfrastructureManagement/ism.hpp>
|
||||
#include <nglwidgets/ngltreeitem.h>
|
||||
#include <utility>
|
||||
|
||||
namespace BuildingViewer
|
||||
{
|
||||
BuildingEditModel::BuildingEditModel(QObject *parent,
|
||||
const std::shared_ptr<InfrastructureManagement::Interface::Dtc> &ismDtc,
|
||||
const std::shared_ptr<Buildings::Interface::Dtc> &bldDtc) : NGLTreeModel(parent, new NGLTreeItem(QVariant()),,
|
||||
m_logger(NGL::NGLLoggerBootstrap::getLogger()) {
|
||||
tr("Selected Building"),
|
||||
QStringLiteral("Name (DEBUG)"),
|
||||
QStringLiteral("MountingPointId (DEBUG)"),
|
||||
QStringLiteral("StructureElementId (DEBUG)"),
|
||||
tr("Fortify Factor"),
|
||||
tr("Damage Percent")})
|
||||
, m_ismDtc(ismDtc)
|
||||
, m_bldDtc(bldDtc)
|
||||
, m_buildingName(QString())
|
||||
{}
|
||||
|
||||
QVariant BuildingEditModel::data(const QModelIndex &index, int role) const
|
||||
BuildingEditModel::BuildingEditModel(QObject* parent,
|
||||
const std::shared_ptr<InfrastructureManagement::Interface::Dtc>& ismDtc,
|
||||
const std::shared_ptr<Buildings::Interface::Dtc>& bldDtc)
|
||||
: NGLTreeModel(parent, new NGLTreeItem(QVariant()), ,
|
||||
m_logger(NGL::NGLLoggerBootstrap::getLogger()){
|
||||
tr("Selected Building"), QStringLiteral("Name (DEBUG)"),
|
||||
QStringLiteral("MountingPointId (DEBUG)"), QStringLiteral("StructureElementId (DEBUG)"),
|
||||
tr("Fortify Factor"), tr("Damage Percent")}),
|
||||
m_ismDtc(ismDtc), m_bldDtc(bldDtc), m_buildingName(QString())
|
||||
{
|
||||
if (!index.isValid() || (role != Qt::BackgroundRole && role != Qt::DisplayRole))
|
||||
}
|
||||
|
||||
QVariant BuildingEditModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if (!index.isValid() || (role != Qt::BackgroundRole && role != Qt::DisplayRole))
|
||||
return {};
|
||||
|
||||
NGLTreeItem* pNGLTreeItem = privateData(index);
|
||||
|
||||
if (pNGLTreeItem->data().canConvert<BuildingViewer::TreeItem>())
|
||||
{
|
||||
BuildingViewer::TreeItem item = pNGLTreeItem->data().value<BuildingViewer::TreeItem>();
|
||||
|
||||
if (role == Qt::BackgroundRole)
|
||||
{
|
||||
if (item.hasDisplayNameChanged() || item.hasFortifyFactorChanged())
|
||||
return QGuiApplication::palette().color(QPalette::Highlight);
|
||||
}
|
||||
else if (role == Qt::DisplayRole)
|
||||
{
|
||||
switch (index.column())
|
||||
{
|
||||
case BuildingEditModel::Building:
|
||||
return item.displayName();
|
||||
case BuildingEditModel::Name:
|
||||
return item.name();
|
||||
case BuildingEditModel::MountingPointId:
|
||||
if (item.hasMountingPointId())
|
||||
return item.mountingPointId();
|
||||
break;
|
||||
case BuildingEditModel::StructureElementId:
|
||||
return item.structureElementId();
|
||||
case BuildingEditModel::FortifyFactor:
|
||||
if (item.isRoom())
|
||||
return QString::number(item.fortifyFactor(), 'f', 1);
|
||||
break;
|
||||
case BuildingEditModel::DamagePercent:
|
||||
if (item.isRoom())
|
||||
return QString::number(item.damagePercent());
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
|
||||
|
||||
NGLTreeItem *pNGLTreeItem = privateData(index);
|
||||
|
||||
if (pNGLTreeItem->data().canConvert<BuildingViewer::TreeItem>())
|
||||
{
|
||||
BuildingViewer::TreeItem item = pNGLTreeItem->data().value<BuildingViewer::TreeItem>();
|
||||
|
||||
if (role == Qt::BackgroundRole)
|
||||
{
|
||||
if (item.hasDisplayNameChanged() || item.hasFortifyFactorChanged())
|
||||
return QGuiApplication::palette().color(QPalette::Highlight);
|
||||
}
|
||||
else if (role == Qt::DisplayRole)
|
||||
{
|
||||
switch (index.column())
|
||||
{
|
||||
case BuildingEditModel::Building:
|
||||
return item.displayName();
|
||||
case BuildingEditModel::Name:
|
||||
return item.name();
|
||||
case BuildingEditModel::MountingPointId:
|
||||
if (item.hasMountingPointId())
|
||||
return item.mountingPointId();
|
||||
break;
|
||||
case BuildingEditModel::StructureElementId:
|
||||
return item.structureElementId();
|
||||
case BuildingEditModel::FortifyFactor:
|
||||
if (item.isRoom())
|
||||
return QString::number(item.fortifyFactor(),'f',1);
|
||||
break;
|
||||
case BuildingEditModel::DamagePercent:
|
||||
if (item.isRoom())
|
||||
return QString::number(item.damagePercent());
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
bool BuildingEditModel::slotUpdateRow(const BuildingViewer::TreeItem &room, const bool fortifyChanged)
|
||||
bool BuildingEditModel::slotUpdateRow(const BuildingViewer::TreeItem& room, const bool fortifyChanged)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "slotUpdateRow isBuilding=" << room.isBuilding()
|
||||
<< " isFloor" << room.isFloor()
|
||||
<< " isRoom" << room.isRoom();
|
||||
DEBUG_LOG(m_logger) << "slotUpdateRow isBuilding=" << room.isBuilding() << " isFloor" << room.isFloor() << " isRoom"
|
||||
<< room.isRoom();
|
||||
|
||||
QModelIndex idx = modelIndexByStructureElementId(room.structureElementId());
|
||||
|
||||
QModelIndex idx = modelIndexByStructureElementId(room.structureElementId());
|
||||
|
||||
if (fortifyChanged && ( !room.isRoom() || !qFuzzyIsNull(room.fortifyFactor())))
|
||||
{
|
||||
for (auto *item : privateData(idx)->children())
|
||||
if (fortifyChanged && (!room.isRoom() || !qFuzzyIsNull(room.fortifyFactor())))
|
||||
{
|
||||
TreeItem childItem = item->data().value<TreeItem>();
|
||||
childItem.setFortifyFactor(room.fortifyFactor());
|
||||
slotUpdateRow(childItem, fortifyChanged);
|
||||
for (auto* item : privateData(idx)->children())
|
||||
{
|
||||
TreeItem childItem = item->data().value<TreeItem>();
|
||||
childItem.setFortifyFactor(room.fortifyFactor());
|
||||
slotUpdateRow(childItem, fortifyChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (room.hasDisplayNameChanged())
|
||||
m_mapRoomsWithChangedDisplayName[room.structureElementId()] = room;
|
||||
if (fortifyChanged && (room.isRoom() && room.hasFortifyFactorChanged()))
|
||||
m_mapRoomsWithChangedFortifyFactor[room.structureElementId()] = room;
|
||||
if (room.hasDisplayNameChanged())
|
||||
m_mapRoomsWithChangedDisplayName[room.structureElementId()] = room;
|
||||
if (fortifyChanged && (room.isRoom() && room.hasFortifyFactorChanged()))
|
||||
m_mapRoomsWithChangedFortifyFactor[room.structureElementId()] = room;
|
||||
|
||||
QVariant data;
|
||||
data.setValue(room);
|
||||
QVariant data;
|
||||
data.setValue(room);
|
||||
|
||||
emit signalModelDataChanged();
|
||||
return setItemData(idx, data, QIcon());
|
||||
emit signalModelDataChanged();
|
||||
return setItemData(idx, data, QIcon());
|
||||
}
|
||||
|
||||
|
||||
bool BuildingEditModel::onInsertRow(int &row, const QModelIndex &parent, const BuildingViewer::TreeItem &folderData)
|
||||
bool BuildingEditModel::onInsertRow(int& row, const QModelIndex& parent, const BuildingViewer::TreeItem& folderData)
|
||||
{
|
||||
row = rowCount(parent);
|
||||
QVariant data;
|
||||
data.setValue(folderData);
|
||||
NGLTreeItem *item = new NGLTreeItem(data, QIcon());
|
||||
item->setModified(true);
|
||||
row = rowCount(parent);
|
||||
QVariant data;
|
||||
data.setValue(folderData);
|
||||
NGLTreeItem* item = new NGLTreeItem(data, QIcon());
|
||||
item->setModified(true);
|
||||
|
||||
emit signalModelDataChanged();
|
||||
emit signalModelDataChanged();
|
||||
|
||||
return NGLTreeModel::insertRow(row, parent, item);
|
||||
return NGLTreeModel::insertRow(row, parent, item);
|
||||
}
|
||||
|
||||
|
||||
bool BuildingEditModel::init(int32_t mseId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "init mseId=" << mseId;
|
||||
NGLTreeModel::resetModel();
|
||||
m_mapRoomsWithChangedFortifyFactor.clear();
|
||||
INFO_LOG(m_logger) << "init mseId=" << mseId;
|
||||
NGLTreeModel::resetModel();
|
||||
m_mapRoomsWithChangedFortifyFactor.clear();
|
||||
|
||||
QMap<qint32, BuildingViewer::TreeItem> treemap;
|
||||
QMap<qint32, qint32> lookupFloorId2TreeId;
|
||||
QString rootName;
|
||||
QMap<qint32, BuildingViewer::TreeItem> treemap;
|
||||
QMap<qint32, qint32> lookupFloorId2TreeId;
|
||||
QString rootName;
|
||||
|
||||
|
||||
InfrastructureManagement::MainStructureElement building = m_ismDtc->mainStructureElement(mseId);
|
||||
int rootId = 0;
|
||||
qint32 mapId = 0;
|
||||
|
||||
|
||||
|
||||
InfrastructureManagement::MainStructureElement building = m_ismDtc->mainStructureElement(mseId);
|
||||
int rootId = 0;
|
||||
qint32 mapId = 0;
|
||||
|
||||
const std::vector<InfrastructureManagement::StructureElement> &vecElements = building.elements();
|
||||
for (const auto &se : vecElements)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "se: " << se;
|
||||
if (se.structureElementTypeId() == InfrastructureManagement::StructureElementType::Building)
|
||||
const std::vector<InfrastructureManagement::StructureElement>& vecElements = building.elements();
|
||||
for (const auto& se : vecElements)
|
||||
{
|
||||
BuildingViewer::TreeItem rootItemBuilding(se);
|
||||
rootName =rootItemBuilding.name();
|
||||
m_buildingName = rootItemBuilding.displayName();
|
||||
mapId = rootId;
|
||||
treemap[mapId++] = rootItemBuilding;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for (const auto &se : vecElements)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "se: =" << se;
|
||||
if (se.structureElementTypeId() == InfrastructureManagement::StructureElementType_def::Floor)
|
||||
{
|
||||
BuildingViewer::TreeItem itemRoom(se);
|
||||
itemRoom.setSuperior(rootId);
|
||||
|
||||
lookupFloorId2TreeId[se.id()] = mapId;
|
||||
treemap[mapId++] = itemRoom;
|
||||
}
|
||||
}
|
||||
|
||||
m_bldDtc->enableBuildingState();
|
||||
m_bldDtc->waitForHistoricalDataBuildingState(1000);
|
||||
|
||||
auto bs = m_bldDtc->buildingState(mseId);
|
||||
|
||||
QMap<int32_t, Buildings::RoomState> roomStates;
|
||||
for (const auto &e : bs.roomStates())
|
||||
roomStates[e.id()] = e;
|
||||
|
||||
|
||||
for (const auto &se : vecElements)
|
||||
{
|
||||
if (se.structureElementTypeId() == InfrastructureManagement::StructureElementType_def::Room)
|
||||
{
|
||||
|
||||
double fortifyFactor = 1.0;
|
||||
qint32 damagePercent = bs.damagePercent();
|
||||
if (roomStates.contains(se.id()))
|
||||
{
|
||||
fortifyFactor = roomStates[se.id()].fortifyFactor();
|
||||
damagePercent = roomStates[se.id()].damagePercent();
|
||||
}
|
||||
|
||||
BuildingViewer::TreeItem itemRoom(se, fortifyFactor, damagePercent);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
int32_t floorID = se.path()[1];
|
||||
itemRoom.setSuperior(lookupFloorId2TreeId[floorID]);
|
||||
}
|
||||
catch (const std::out_of_range &e)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Caught exception while trying to get superior id for building " << rootName << " with room with mounting point id: " << se.mountingPointId() << ": " << e.what();
|
||||
return false;
|
||||
}
|
||||
|
||||
treemap[mapId++] = itemRoom;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QHash<int, QPersistentModelIndex> parentItemIndexCache;
|
||||
parentItemIndexCache.insert(rootId, QModelIndex());
|
||||
|
||||
for (auto iter = treemap.constBegin(); iter != treemap.constEnd(); ++iter)
|
||||
{
|
||||
int itemDatabaseId = iter.key();
|
||||
const BuildingViewer::TreeItem &item = iter.value();
|
||||
|
||||
QVariant data;
|
||||
data.setValue(item);
|
||||
|
||||
int parentId = item.hasSuperior() ? item.getSuperior() : rootId;
|
||||
if (!parentItemIndexCache.contains(parentId))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Invalid building structure! Tree can not be built!";
|
||||
return false;
|
||||
DEBUG_LOG(m_logger) << "se: " << se;
|
||||
if (se.structureElementTypeId() == InfrastructureManagement::StructureElementType::Building)
|
||||
{
|
||||
BuildingViewer::TreeItem rootItemBuilding(se);
|
||||
rootName = rootItemBuilding.name();
|
||||
m_buildingName = rootItemBuilding.displayName();
|
||||
mapId = rootId;
|
||||
treemap[mapId++] = rootItemBuilding;
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex pIndex = parentItemIndexCache.value(parentId);
|
||||
int rowPos = -1;
|
||||
for (const auto& se : vecElements)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "se: =" << se;
|
||||
if (se.structureElementTypeId() == InfrastructureManagement::StructureElementType_def::Floor)
|
||||
{
|
||||
BuildingViewer::TreeItem itemRoom(se);
|
||||
itemRoom.setSuperior(rootId);
|
||||
|
||||
onInsertRow(rowPos, pIndex, item);
|
||||
lookupFloorId2TreeId[se.id()] = mapId;
|
||||
treemap[mapId++] = itemRoom;
|
||||
}
|
||||
}
|
||||
|
||||
QPersistentModelIndex mIndex = index(rowPos, 0, pIndex);
|
||||
m_mapModelIndices[item.structureElementId()] = mIndex;
|
||||
parentItemIndexCache.insert(itemDatabaseId, mIndex);
|
||||
}
|
||||
m_bldDtc->enableBuildingState();
|
||||
m_bldDtc->waitForHistoricalDataBuildingState(1000);
|
||||
|
||||
return true;
|
||||
auto bs = m_bldDtc->buildingState(mseId);
|
||||
|
||||
QMap<int32_t, Buildings::RoomState> roomStates;
|
||||
for (const auto& e : bs.roomStates())
|
||||
roomStates[e.id()] = e;
|
||||
|
||||
for (const auto& se : vecElements)
|
||||
{
|
||||
if (se.structureElementTypeId() == InfrastructureManagement::StructureElementType_def::Room)
|
||||
{
|
||||
|
||||
double fortifyFactor = 1.0;
|
||||
qint32 damagePercent = bs.damagePercent();
|
||||
if (roomStates.contains(se.id()))
|
||||
{
|
||||
fortifyFactor = roomStates[se.id()].fortifyFactor();
|
||||
damagePercent = roomStates[se.id()].damagePercent();
|
||||
}
|
||||
|
||||
BuildingViewer::TreeItem itemRoom(se, fortifyFactor, damagePercent);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
int32_t floorID = se.path()[1];
|
||||
itemRoom.setSuperior(lookupFloorId2TreeId[floorID]);
|
||||
}
|
||||
catch (const std::out_of_range& e)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Caught exception while trying to get superior id for building " << rootName
|
||||
<< " with room with mounting point id: " << se.mountingPointId() << ": "
|
||||
<< e.what();
|
||||
return false;
|
||||
}
|
||||
|
||||
treemap[mapId++] = itemRoom;
|
||||
}
|
||||
}
|
||||
|
||||
QHash<int, QPersistentModelIndex> parentItemIndexCache;
|
||||
parentItemIndexCache.insert(rootId, QModelIndex());
|
||||
|
||||
for (auto iter = treemap.constBegin(); iter != treemap.constEnd(); ++iter)
|
||||
{
|
||||
int itemDatabaseId = iter.key();
|
||||
const BuildingViewer::TreeItem& item = iter.value();
|
||||
|
||||
QVariant data;
|
||||
data.setValue(item);
|
||||
|
||||
int parentId = item.hasSuperior() ? item.getSuperior() : rootId;
|
||||
if (!parentItemIndexCache.contains(parentId))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Invalid building structure! Tree can not be built!";
|
||||
return false;
|
||||
}
|
||||
|
||||
QModelIndex pIndex = parentItemIndexCache.value(parentId);
|
||||
int rowPos = -1;
|
||||
|
||||
onInsertRow(rowPos, pIndex, item);
|
||||
|
||||
QPersistentModelIndex mIndex = index(rowPos, 0, pIndex);
|
||||
m_mapModelIndices[item.structureElementId()] = mIndex;
|
||||
parentItemIndexCache.insert(itemDatabaseId, mIndex);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QModelIndex BuildingEditModel::modelIndexByMountingPointId(int mountingPointId) const
|
||||
{
|
||||
for(const QPersistentModelIndex &mi : std::as_const(m_mapModelIndices))
|
||||
{
|
||||
if (privateData(mi)->data().value<TreeItem>().mountingPointId() == mountingPointId)
|
||||
return mi;
|
||||
}
|
||||
WARNING_LOG(m_logger)<<"Could not find modelindex for given room mountig point id: " << mountingPointId;
|
||||
return {};
|
||||
for (const QPersistentModelIndex& mi : std::as_const(m_mapModelIndices))
|
||||
{
|
||||
if (privateData(mi)->data().value<TreeItem>().mountingPointId() == mountingPointId)
|
||||
return mi;
|
||||
}
|
||||
WARNING_LOG(m_logger) << "Could not find modelindex for given room mountig point id: " << mountingPointId;
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
QModelIndex BuildingEditModel::modelIndexByStructureElementId(int structureElementId) const
|
||||
{
|
||||
auto it = m_mapModelIndices.find(structureElementId);
|
||||
if (it == m_mapModelIndices.end())
|
||||
{
|
||||
WARNING_LOG(m_logger)<<"Could not find modelindex for given room structreElementId: " << structureElementId;
|
||||
return {};
|
||||
}
|
||||
return it.value();
|
||||
auto it = m_mapModelIndices.find(structureElementId);
|
||||
if (it == m_mapModelIndices.end())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Could not find modelindex for given room structreElementId: " << structureElementId;
|
||||
return {};
|
||||
}
|
||||
return it.value();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BuildingEditProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
|
||||
void BuildingEditProxyModel::setSourceModel(QAbstractItemModel* sourceModel)
|
||||
{
|
||||
m_sourceModel = qobject_cast<BuildingEditModel*>(sourceModel);
|
||||
QSortFilterProxyModel::setSourceModel(m_sourceModel);
|
||||
m_sourceModel = qobject_cast<BuildingEditModel*>(sourceModel);
|
||||
QSortFilterProxyModel::setSourceModel(m_sourceModel);
|
||||
}
|
||||
|
||||
bool BuildingEditProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
bool BuildingEditProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
|
||||
{
|
||||
if (!m_sourceModel ||
|
||||
left.column() != 0 || right.column() != 0)
|
||||
if (!m_sourceModel || left.column() != 0 || right.column() != 0)
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
|
||||
NGLTreeItem* itemLeft = m_sourceModel->privateData(left);
|
||||
NGLTreeItem* itemRight = m_sourceModel->privateData(right);
|
||||
if (itemLeft && itemRight)
|
||||
return (itemLeft->row() < itemRight->row());
|
||||
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
|
||||
NGLTreeItem *itemLeft = m_sourceModel->privateData(left);
|
||||
NGLTreeItem *itemRight = m_sourceModel->privateData(right);
|
||||
if (itemLeft && itemRight)
|
||||
return (itemLeft->row() < itemRight->row());
|
||||
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace BuildingViewer
|
||||
Executable → Regular
+55
-52
@@ -2,13 +2,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Common/logger.h>
|
||||
|
||||
#include <Plugins/Buildings/bld_data_plugin_interface.h>
|
||||
#include <Plugins/InfrastructureManagement/ism_data_plugin_interface.h>
|
||||
|
||||
#include "bdv_treemodel_item.h"
|
||||
|
||||
#include <Common/logger.h>
|
||||
#include <Plugins/Buildings/bld_data_plugin_interface.h>
|
||||
#include <Plugins/InfrastructureManagement/ism_data_plugin_interface.h>
|
||||
#include <QMap>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <functional>
|
||||
@@ -18,70 +16,75 @@ namespace BuildingViewer
|
||||
{
|
||||
class BuildingEditModel : public NGLTreeModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Columns
|
||||
{
|
||||
Building,
|
||||
Name,
|
||||
MountingPointId,
|
||||
StructureElementId,
|
||||
FortifyFactor,
|
||||
DamagePercent,
|
||||
ColumnCount,
|
||||
};
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Columns {
|
||||
Building,
|
||||
Name,
|
||||
MountingPointId,
|
||||
StructureElementId,
|
||||
FortifyFactor,
|
||||
DamagePercent,
|
||||
ColumnCount,
|
||||
};
|
||||
|
||||
BuildingEditModel(QObject *parent,
|
||||
const std::shared_ptr<InfrastructureManagement::Interface::Dtc> &ismDtc,
|
||||
const std::shared_ptr<Buildings::Interface::Dtc> &bldDtc);
|
||||
BuildingEditModel(QObject* parent, const std::shared_ptr<InfrastructureManagement::Interface::Dtc>& ismDtc,
|
||||
const std::shared_ptr<Buildings::Interface::Dtc>& bldDtc);
|
||||
|
||||
QList<BuildingViewer::TreeItem> getRoomsWithChangedFortifyFactors() const { return m_mapRoomsWithChangedFortifyFactor.values(); }
|
||||
QList<BuildingViewer::TreeItem> getRoomsWithChangedDisplayNames() const { return m_mapRoomsWithChangedDisplayName.values(); }
|
||||
QList<BuildingViewer::TreeItem> getRoomsWithChangedFortifyFactors() const
|
||||
{
|
||||
return m_mapRoomsWithChangedFortifyFactor.values();
|
||||
}
|
||||
|
||||
bool init(int32_t buildingDatabaseId);
|
||||
QModelIndex modelIndexByMountingPointId(int mountingPointId) const;
|
||||
QModelIndex modelIndexByStructureElementId(int structureElementId) const;
|
||||
QString getBuildingName() const {return m_buildingName;}
|
||||
QList<BuildingViewer::TreeItem> getRoomsWithChangedDisplayNames() const
|
||||
{
|
||||
return m_mapRoomsWithChangedDisplayName.values();
|
||||
}
|
||||
|
||||
public slots:
|
||||
bool slotUpdateRow(const BuildingViewer::TreeItem &room, const bool fortifyChanged);
|
||||
bool init(int32_t buildingDatabaseId);
|
||||
QModelIndex modelIndexByMountingPointId(int mountingPointId) const;
|
||||
QModelIndex modelIndexByStructureElementId(int structureElementId) const;
|
||||
|
||||
signals:
|
||||
void signalModelDataChanged();
|
||||
QString getBuildingName() const
|
||||
{
|
||||
return m_buildingName;
|
||||
}
|
||||
|
||||
private:
|
||||
public slots:
|
||||
bool slotUpdateRow(const BuildingViewer::TreeItem& room, const bool fortifyChanged);
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
QVariant data(const QModelIndex &index, int role) const override final;
|
||||
bool onInsertRow(int &row, const QModelIndex &parent, const BuildingViewer::TreeItem &folderData);
|
||||
signals:
|
||||
void signalModelDataChanged();
|
||||
|
||||
QMap<int, QPersistentModelIndex> m_mapModelIndices;
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
QVariant data(const QModelIndex& index, int role) const override final;
|
||||
bool onInsertRow(int& row, const QModelIndex& parent, const BuildingViewer::TreeItem& folderData);
|
||||
|
||||
|
||||
QMap<int32_t, BuildingViewer::TreeItem> m_mapRoomsWithChangedFortifyFactor;
|
||||
QMap<int32_t, BuildingViewer::TreeItem> m_mapRoomsWithChangedDisplayName;
|
||||
QMap<int, QPersistentModelIndex> m_mapModelIndices;
|
||||
|
||||
std::shared_ptr<InfrastructureManagement::Interface::Dtc> m_ismDtc;
|
||||
std::shared_ptr<Buildings::Interface::Dtc> m_bldDtc;
|
||||
QMap<int32_t, BuildingViewer::TreeItem> m_mapRoomsWithChangedFortifyFactor;
|
||||
QMap<int32_t, BuildingViewer::TreeItem> m_mapRoomsWithChangedDisplayName;
|
||||
|
||||
QString m_buildingName;
|
||||
std::shared_ptr<InfrastructureManagement::Interface::Dtc> m_ismDtc;
|
||||
std::shared_ptr<Buildings::Interface::Dtc> m_bldDtc;
|
||||
|
||||
QString m_buildingName;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class BuildingEditProxyModel final : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QSortFilterProxyModel::QSortFilterProxyModel;
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QSortFilterProxyModel::QSortFilterProxyModel;
|
||||
|
||||
void setSourceModel(QAbstractItemModel *sourceModel) override;
|
||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
||||
private:
|
||||
BuildingEditModel *m_sourceModel = nullptr;
|
||||
void setSourceModel(QAbstractItemModel* sourceModel) override;
|
||||
bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
|
||||
|
||||
private:
|
||||
BuildingEditModel* m_sourceModel = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace BuildingViewer
|
||||
|
||||
Q_DECLARE_METATYPE(BuildingViewer::TreeItem)
|
||||
|
||||
Reference in new issue
Block a user