diff --git a/apps/ied_simulator/qml/BrowserGoosePane.qml b/apps/ied_simulator/qml/BrowserGoosePane.qml index 8b42ee6e9..5b7e4e3b8 100644 --- a/apps/ied_simulator/qml/BrowserGoosePane.qml +++ b/apps/ied_simulator/qml/BrowserGoosePane.qml @@ -6,16 +6,16 @@ import QtQuick.Layouts Rectangle { id: root required property var theme - required property var client + required property var context required property var engineering property var visibleStreams: { var all = engineering.gooseStreams - if (!client.iedName.length) + if (!context.iedName.length) return all var filtered = [] for (var index = 0; index < all.length; ++index) { - if (String(all[index].iedName) === client.iedName) + if (String(all[index].iedName) === context.iedName) filtered.push(all[index]) } return filtered diff --git a/apps/ied_simulator/qml/FileWorkspace.qml b/apps/ied_simulator/qml/FileWorkspace.qml index 9fd39982f..06f08d5df 100644 --- a/apps/ied_simulator/qml/FileWorkspace.qml +++ b/apps/ied_simulator/qml/FileWorkspace.qml @@ -10,6 +10,7 @@ Item { required property var theme required property var workspace required property var hardening + required property var browserSession property int viewIndex: 0 @@ -43,8 +44,10 @@ Item { fileMode: FileDialog.OpenFile nameFilters: ["IEC 61850 engineering files (*.scl *.cid *.scd *.iid *.icd)", "All files (*)"] onAccepted: { - if (workspace.openFile(selectedFile)) + if (workspace.openFile(selectedFile)) { root.viewIndex = 1 + root.browserRequested() + } } } @@ -104,7 +107,7 @@ Item { theme: root.theme text: "Open SCL" primary: !workspace.loaded - enabled: !workspace.busy + enabled: !workspace.busy && !browserSession.configurationLocked onClicked: openDialog.open() } @@ -173,13 +176,19 @@ Item { Label { text: "Engineering file"; color: root.theme.text; font.pixelSize: 10; font.weight: Font.DemiBold } Label { Layout.fillWidth: true - text: "Open SCL / CID / SCD / IID / ICD without changing protocol runtime." + text: "Open SCL / CID / SCD / IID / ICD and continue in the unified IED Browser." color: root.theme.muted font.pixelSize: 8 wrapMode: Text.WordWrap } Item { Layout.fillHeight: true } - ActionButton { theme: root.theme; text: "Open SCL"; primary: true; onClicked: openDialog.open() } + ActionButton { + theme: root.theme + text: "Open SCL" + primary: true + enabled: !workspace.busy && !browserSession.configurationLocked + onClicked: openDialog.open() + } } } @@ -346,10 +355,14 @@ Item { id: resourceMouse anchors.fill: parent hoverEnabled: true - enabled: hardening.recentResourceExists(index) && !workspace.busy + enabled: hardening.recentResourceExists(index) + && !workspace.busy + && !browserSession.configurationLocked onClicked: { - if (workspace.openFile(hardening.recentResourceUrl(index))) + if (workspace.openFile(hardening.recentResourceUrl(index))) { root.viewIndex = 1 + root.browserRequested() + } } } } diff --git a/apps/ied_simulator/qml/IedBrowserNavigation.qml b/apps/ied_simulator/qml/IedBrowserNavigation.qml index 994c32594..d90d332d9 100644 --- a/apps/ied_simulator/qml/IedBrowserNavigation.qml +++ b/apps/ied_simulator/qml/IedBrowserNavigation.qml @@ -9,6 +9,7 @@ Rectangle { required property var theme required property var session required property var client + required property var context required property var reports required property var utilities required property var engineering @@ -28,11 +29,11 @@ Rectangle { function configuredGooseCount() { var streams = engineering.gooseStreams - if (!client.iedName.length) + if (!context.iedName.length) return streams.length var count = 0 for (var index = 0; index < streams.length; ++index) { - if (String(streams[index].iedName) === client.iedName) + if (String(streams[index].iedName) === context.iedName) ++count } return count @@ -213,7 +214,8 @@ Rectangle { NavButton { targetSection: 3 title: "Setting Groups" - countText: utilities.connected ? String(utilities.settingGroupCount) : "" + countText: utilities.connected ? String(utilities.settingGroupCount) + : context.loaded ? String(context.settingGroupCount) : "" } Loader { @@ -267,7 +269,8 @@ Rectangle { NavButton { targetSection: 1 title: "DataSets" - countText: reports.connected ? String(reports.dataSets.length) : "" + countText: reports.connected ? String(reports.dataSets.length) + : context.loaded ? String(context.dataSetCount) : "" } Loader { @@ -322,7 +325,7 @@ Rectangle { NavButton { targetSection: 0 title: "Data Model" - countText: client.connected ? String(client.treeModel.totalNodeCount) : "" + countText: context.loaded ? String(context.treeModel.totalNodeCount) : "" } ColumnLayout { @@ -338,7 +341,7 @@ Rectangle { Layout.topMargin: 5 Layout.bottomMargin: 5 placeholderText: "Filter model" - enabled: client.connected + enabled: context.loaded onTextChanged: searchDebounce.restart() } @@ -346,7 +349,7 @@ Rectangle { id: searchDebounce interval: 100 repeat: false - onTriggered: client.treeModel.filterText = modelSearch.text + onTriggered: context.treeModel.filterText = modelSearch.text } ListView { @@ -356,7 +359,7 @@ Rectangle { clip: true reuseItems: true cacheBuffer: 0 - model: client.treeModel + model: context.treeModel ScrollBar.vertical: ScrollBar {} delegate: Rectangle { @@ -408,16 +411,16 @@ Rectangle { anchors.fill: parent hoverEnabled: true onClicked: function(event) { - client.treeModel.selectRow(index) + context.treeModel.selectRow(index) if (model.hasChildren && event.x < 44 + model.depth * 12) - client.treeModel.toggle(index) + context.treeModel.toggle(index) root.choose(0, "Data Model") } onDoubleClicked: { if (model.hasChildren) - client.treeModel.toggle(index) - else - client.readSelected() + context.treeModel.toggle(index) + else if (client.connected) + client.readEngineeringSelected() } } } diff --git a/apps/ied_simulator/qml/IedBrowserWorkspace.qml b/apps/ied_simulator/qml/IedBrowserWorkspace.qml index aa83c34f5..7ec7cc4c0 100644 --- a/apps/ied_simulator/qml/IedBrowserWorkspace.qml +++ b/apps/ied_simulator/qml/IedBrowserWorkspace.qml @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later import QtQuick import QtQuick.Controls +import QtQuick.Dialogs import QtQuick.Layouts Item { @@ -9,6 +10,7 @@ Item { required property var theme required property var session required property var client + required property var context required property var reports required property var utilities required property var engineering @@ -16,7 +18,7 @@ Item { property int activeSection: 0 property string activeSectionTitle: "Data Model" - property var selectedModelNode: client.treeModel.selectedNode + property var selectedModelNode: context.treeModel.selectedNode function ensureActiveService() { if (!session.connected) @@ -70,6 +72,14 @@ Item { } } + FileDialog { + id: browserSclDialog + title: "Open IEC 61850 engineering model" + fileMode: FileDialog.OpenFile + nameFilters: ["IEC 61850 engineering files (*.scl *.cid *.scd *.iid *.icd)", "All files (*)"] + onAccepted: engineering.openFile(selectedFile) + } + Rectangle { anchors.fill: parent; color: root.theme.background } ColumnLayout { @@ -99,12 +109,22 @@ Item { font.weight: Font.DemiBold } Label { - text: "One endpoint · persistent engineering navigation" + text: context.loaded + ? context.authority + " · persistent engineering navigation" + : "Open SCL or discover one IED endpoint" color: root.theme.muted font.pixelSize: 8 } } + Button { + text: "Open SCL" + enabled: !session.configurationLocked && !engineering.busy + onClicked: browserSclDialog.open() + ToolTip.visible: hovered + ToolTip.text: "Open SCL/CID/SCD/IID/ICD into the persistent Browser model." + } + TextField { id: hostField Layout.preferredWidth: 205 @@ -127,13 +147,30 @@ Item { } Button { - text: session.connected ? "Connected" : session.busy ? "Connecting..." : "Connect" + text: context.loaded && context.authorityKey === "scl" ? "Connect SCL" : "Connect model" + visible: context.loaded + enabled: !session.connected && !session.busy && !context.selectionRequired + onClicked: { + session.host = hostField.text + session.port = portField.value + session.connectUsingEngineeringContext() + } + ToolTip.visible: hovered + ToolTip.text: context.authorityKey === "scl" + ? "Connect using the active trusted SCL model." + : "Reconnect/discover the active IED endpoint." + } + + Button { + text: session.busy && !session.connected ? "Discovering…" : "Discover IED" enabled: !session.connected && !session.busy onClicked: { session.host = hostField.text session.port = portField.value - session.connectToIed() + session.discoverAndConnect() } + ToolTip.visible: hovered + ToolTip.text: "Ignore trusted SCL for this connect, discover the live MMS model, and publish it into this Browser context." } Button { @@ -170,19 +207,21 @@ Item { Item { Layout.fillWidth: true } ColumnLayout { - visible: session.connected + visible: context.loaded spacing: 0 Label { Layout.alignment: Qt.AlignRight - text: client.iedName.length ? client.iedName : "Online IED" + text: context.iedName.length ? context.iedName + : context.selectionRequired ? "Select active IED" : "IED model" color: root.theme.text font.pixelSize: 10 font.weight: Font.DemiBold } Label { Layout.alignment: Qt.AlignRight - text: client.logicalDeviceCount + " LD · " + client.logicalNodeCount + " LN · " - + client.dataAttributeCount + " DA" + text: context.logicalDeviceCount + " LD · " + context.logicalNodeCount + " LN · " + + context.dataAttributeCount + " DA · " + + (context.online ? "ONLINE" : "OFFLINE") color: root.theme.muted font.pixelSize: 8 } @@ -190,6 +229,47 @@ Item { } } + Rectangle { + visible: context.selectionRequired + Layout.fillWidth: true + Layout.preferredHeight: context.selectionRequired ? 42 : 0 + color: root.theme.amberSoft + border.width: 1 + border.color: root.theme.amber + + RowLayout { + anchors.fill: parent + anchors.leftMargin: 14 + anchors.rightMargin: 14 + spacing: 8 + Label { + text: "Multi-IED SCL · select the active IED" + color: root.theme.text + font.pixelSize: 9 + font.weight: Font.DemiBold + } + ComboBox { + id: activeIedPicker + Layout.preferredWidth: 220 + model: context.candidateIeds + enabled: !session.configurationLocked + } + Button { + text: "Use IED" + enabled: !session.configurationLocked + && activeIedPicker.currentIndex >= 0 + onClicked: context.selectIed(activeIedPicker.currentText) + } + Item { Layout.fillWidth: true } + Label { + text: context.lastError + color: root.theme.muted + font.pixelSize: 8 + elide: Text.ElideRight + } + } + } + SplitView { id: browserSplit Layout.fillWidth: true @@ -205,6 +285,7 @@ Item { theme: root.theme session: root.session client: root.client + context: root.context reports: root.reports utilities: root.utilities engineering: root.engineering @@ -269,7 +350,7 @@ Item { text: client.operationBusy ? "Reading…" : "Read" enabled: client.connected && !client.operationBusy && root.selectedModelNode.readable === true - onClicked: client.readSelected() + onClicked: client.readEngineeringSelected() } Button { @@ -318,6 +399,7 @@ Item { MmsClientWorkspace { theme: root.theme client: root.client + modelProvider: root.context showConnectionHeader: false showNavigationPanel: false } @@ -349,7 +431,7 @@ Item { BrowserGoosePane { theme: root.theme - client: root.client + context: root.context engineering: root.engineering } } @@ -391,8 +473,8 @@ Item { font.pixelSize: 8 } Label { - visible: root.activeSection === 0 && client.connected - text: client.treeModel.visibleNodeCount + "/" + client.treeModel.totalNodeCount + " nodes" + visible: root.activeSection === 0 && context.loaded + text: context.treeModel.visibleNodeCount + "/" + context.treeModel.totalNodeCount + " nodes" color: session.lastError.length ? root.theme.red : root.theme.navigationMuted font.pixelSize: 8 } diff --git a/apps/ied_simulator/qml/Main.qml b/apps/ied_simulator/qml/Main.qml index e691f81da..fa23f709e 100644 --- a/apps/ied_simulator/qml/Main.qml +++ b/apps/ied_simulator/qml/Main.qml @@ -57,6 +57,7 @@ ApplicationWindow { client: mmsClient reports: reports utilities: utilities + engineeringContext: iedContext } SclWorkspaceController { id: sclWorkspace @@ -279,6 +280,7 @@ ApplicationWindow { theme: appTheme workspace: sclWorkspace hardening: hardening + browserSession: browserSession onBrowserRequested: root.workspaceIndex = 1 onEndpointRequested: function(host, port) { if (!browserSession.configurationLocked) { @@ -296,6 +298,7 @@ ApplicationWindow { productState: hardening session: browserSession client: mmsClient + context: iedContext reports: reports utilities: utilities engineering: sclWorkspace diff --git a/apps/ied_simulator/qml/MmsClientWorkspace.qml b/apps/ied_simulator/qml/MmsClientWorkspace.qml index 215b25072..555a1db79 100644 --- a/apps/ied_simulator/qml/MmsClientWorkspace.qml +++ b/apps/ied_simulator/qml/MmsClientWorkspace.qml @@ -9,10 +9,13 @@ Item { required property var theme required property var client + property var modelProvider: client property bool showConnectionHeader: true property bool showNavigationPanel: true - property var selected: client.treeModel.selectedNode + property var selected: modelProvider.treeModel.selectedNode + property bool modelAvailable: modelProvider && modelProvider.treeModel + && modelProvider.treeModel.totalNodeCount > 0 property string pendingWrite: "" function text(value) { @@ -33,6 +36,28 @@ Item { return theme.muted } + function usingEngineeringModel() { + return modelProvider !== client + } + + function readCurrentSelection() { + if (usingEngineeringModel()) + return client.readEngineeringSelected() + return client.readSelected() + } + + function refreshCurrentVisible(firstRow, lastRow) { + if (usingEngineeringModel()) + return client.refreshEngineeringVisible(firstRow, lastRow) + return client.refreshVisible(firstRow, lastRow) + } + + function writeCurrentSelection(value) { + if (usingEngineeringModel()) + return client.writeEngineeringSelected(value) + return client.writeSelected(value) + } + function firstVisibleRow() { var index = tree.indexAt(4, tree.contentY + 4) return index >= 0 ? index : 0 @@ -183,19 +208,19 @@ Item { id: searchField Layout.fillWidth: true placeholderText: "Search reference, FC, type or value" - enabled: client.connected + enabled: root.modelAvailable onTextChanged: searchDebounce.restart() } Button { text: "Refresh visible" enabled: client.connected && !client.operationBusy && tree.count > 0 - onClicked: client.refreshVisible(root.firstVisibleRow(), root.lastVisibleRow()) + onClicked: root.refreshCurrentVisible(root.firstVisibleRow(), root.lastVisibleRow()) } Timer { id: searchDebounce interval: 100 repeat: false - onTriggered: client.treeModel.filterText = searchField.text + onTriggered: root.modelProvider.treeModel.filterText = searchField.text } } @@ -208,7 +233,7 @@ Item { clip: true reuseItems: true cacheBuffer: 0 - model: client.treeModel + model: root.modelProvider.treeModel ScrollBar.vertical: ScrollBar { } delegate: Rectangle { @@ -267,12 +292,13 @@ Item { anchors.fill: parent hoverEnabled: true onClicked: function(event) { - client.treeModel.selectRow(index) - if (model.hasChildren && event.x < 38 + model.depth * 14) client.treeModel.toggle(index) + root.modelProvider.treeModel.selectRow(index) + if (model.hasChildren && event.x < 38 + model.depth * 14) + root.modelProvider.treeModel.toggle(index) } onDoubleClicked: { - if (model.hasChildren) client.treeModel.toggle(index) - else client.readSelected() + if (model.hasChildren) root.modelProvider.treeModel.toggle(index) + else root.readCurrentSelection() } } } @@ -346,7 +372,7 @@ Item { Button { text: client.operationBusy ? "Reading…" : "Read" enabled: client.connected && !client.operationBusy && root.selected.readable === true - onClicked: client.readSelected() + onClicked: root.readCurrentSelection() } TextField { id: writeValue @@ -411,7 +437,7 @@ Item { width: Math.min(480, Math.max(320, root.width - 32)) implicitWidth: 480 standardButtons: Dialog.Ok | Dialog.Cancel - onAccepted: client.writeSelected(root.pendingWrite) + onAccepted: root.writeCurrentSelection(root.pendingWrite) contentItem: ColumnLayout { spacing: 8 Label { Layout.fillWidth: true; text: root.text(root.selected.reference); color: theme.text; font.pixelSize: 10; wrapMode: Text.WrapAnywhere } diff --git a/apps/ied_simulator/src/IedBrowserSessionController.cpp b/apps/ied_simulator/src/IedBrowserSessionController.cpp index 3d6a48c79..7223c1414 100644 --- a/apps/ied_simulator/src/IedBrowserSessionController.cpp +++ b/apps/ied_simulator/src/IedBrowserSessionController.cpp @@ -53,6 +53,26 @@ void IedBrowserSessionController::setReports(MmsReportController* value) { emit stateChanged(); } +void IedBrowserSessionController::setEngineeringContext(IedEngineeringContextController* value) { + if (engineeringContext_ == value) return; + if (engineeringContext_) disconnect(engineeringContext_, nullptr, this, nullptr); + engineeringContext_ = value; + if (engineeringContext_) { + connect( + engineeringContext_, + &IedEngineeringContextController::contextChanged, + this, + [this] { + if (!configurationLocked()) applyEngineeringEndpoint(); + emit stateChanged(); + }); + } + syncConfiguration(); + if (!configurationLocked()) applyEngineeringEndpoint(); + emit servicesChanged(); + emit stateChanged(); +} + void IedBrowserSessionController::setUtilities(MmsFileSettingsController* value) { if (utilities_ == value) return; if (utilities_) disconnect(utilities_, nullptr, this, nullptr); @@ -158,6 +178,7 @@ void IedBrowserSessionController::syncConfiguration() { client_->setHost(host_); client_->setPort(port_); client_->setTrustedSclPath(trustedSclPath_); + client_->setEngineeringContext(engineeringContext_); } if (reports_) { reports_->setHost(host_); @@ -169,6 +190,53 @@ void IedBrowserSessionController::syncConfiguration() { } } +bool IedBrowserSessionController::applyEngineeringEndpoint() { + if (!engineeringContext_ || !engineeringContext_->loaded() || + engineeringContext_->selectionRequired() || configurationLocked()) { + return false; + } + const auto host = engineeringContext_->endpointHost().trimmed(); + const auto port = engineeringContext_->endpointPort(); + if (host.isEmpty() || port < 1 || port > 65'535) return false; + setHost(host); + setPort(port); + return host_ == host && port_ == port; +} + +bool IedBrowserSessionController::connectUsingEngineeringContext() { + if (!engineeringContext_ || !engineeringContext_->loaded()) { + coordinatorError_ = QStringLiteral("Open or discover an IED model before connecting this Browser context."); + emit stateChanged(); + return false; + } + if (engineeringContext_->selectionRequired()) { + coordinatorError_ = QStringLiteral("Select the active IED from the engineering model before connecting."); + emit stateChanged(); + return false; + } + if (configurationLocked()) return connected(); + + if (engineeringContext_->authorityKey() == QStringLiteral("scl")) { + const auto source = engineeringContext_->sourcePath().trimmed(); + if (source.isEmpty()) { + coordinatorError_ = QStringLiteral("The active SCL context has no trusted local source path."); + emit stateChanged(); + return false; + } + setTrustedSclPath(source); + } else { + setTrustedSclPath({}); + } + static_cast(applyEngineeringEndpoint()); + return connectToIed(); +} + +bool IedBrowserSessionController::discoverAndConnect() { + if (configurationLocked()) return connected(); + setTrustedSclPath({}); + return connectToIed(); +} + bool IedBrowserSessionController::connectToIed() { if (!client_) { coordinatorError_ = QStringLiteral("IED Browser model service is unavailable."); diff --git a/apps/ied_simulator/src/IedBrowserSessionController.hpp b/apps/ied_simulator/src/IedBrowserSessionController.hpp index 979bc5703..9567ffdf8 100644 --- a/apps/ied_simulator/src/IedBrowserSessionController.hpp +++ b/apps/ied_simulator/src/IedBrowserSessionController.hpp @@ -20,6 +20,7 @@ class IedBrowserSessionController : public QObject { Q_PROPERTY(MmsClientController* client READ client WRITE setClient NOTIFY servicesChanged) Q_PROPERTY(MmsReportController* reports READ reports WRITE setReports NOTIFY servicesChanged) Q_PROPERTY(MmsFileSettingsController* utilities READ utilities WRITE setUtilities NOTIFY servicesChanged) + Q_PROPERTY(IedEngineeringContextController* engineeringContext READ engineeringContext WRITE setEngineeringContext NOTIFY servicesChanged) Q_PROPERTY(bool connected READ connected NOTIFY stateChanged) Q_PROPERTY(bool busy READ busy NOTIFY stateChanged) Q_PROPERTY(bool configurationLocked READ configurationLocked NOTIFY stateChanged) @@ -36,6 +37,9 @@ class IedBrowserSessionController : public QObject { [[nodiscard]] MmsClientController* client() const noexcept { return client_; } [[nodiscard]] MmsReportController* reports() const noexcept { return reports_; } [[nodiscard]] MmsFileSettingsController* utilities() const noexcept { return utilities_; } + [[nodiscard]] IedEngineeringContextController* engineeringContext() const noexcept { + return engineeringContext_; + } void setHost(const QString& value); void setPort(int value); @@ -43,6 +47,7 @@ class IedBrowserSessionController : public QObject { void setClient(MmsClientController* value); void setReports(MmsReportController* value); void setUtilities(MmsFileSettingsController* value); + void setEngineeringContext(IedEngineeringContextController* value); [[nodiscard]] bool connected() const noexcept; [[nodiscard]] bool busy() const noexcept; @@ -51,6 +56,9 @@ class IedBrowserSessionController : public QObject { [[nodiscard]] QString stateText() const; [[nodiscard]] QString lastError() const; + Q_INVOKABLE bool applyEngineeringEndpoint(); + Q_INVOKABLE bool connectUsingEngineeringContext(); + Q_INVOKABLE bool discoverAndConnect(); Q_INVOKABLE bool connectToIed(); Q_INVOKABLE void disconnectFromIed(); Q_INVOKABLE bool ensureReportsConnected(); @@ -73,4 +81,5 @@ class IedBrowserSessionController : public QObject { QPointer client_; QPointer reports_; QPointer utilities_; + QPointer engineeringContext_; }; diff --git a/apps/ied_simulator/src/IedEngineeringContextController.hpp b/apps/ied_simulator/src/IedEngineeringContextController.hpp index 2b5a0b1ff..7051a6e68 100644 --- a/apps/ied_simulator/src/IedEngineeringContextController.hpp +++ b/apps/ied_simulator/src/IedEngineeringContextController.hpp @@ -28,6 +28,8 @@ class IedEngineeringContextController : public QObject { Q_PROPERTY(QStringList candidateIeds READ candidateIeds NOTIFY contextChanged) Q_PROPERTY(QString accessPointName READ accessPointName NOTIFY contextChanged) Q_PROPERTY(QString endpoint READ endpoint NOTIFY contextChanged) + Q_PROPERTY(QString endpointHost READ endpointHost NOTIFY contextChanged) + Q_PROPERTY(int endpointPort READ endpointPort NOTIFY contextChanged) Q_PROPERTY(QString structuralFingerprint READ structuralFingerprint NOTIFY contextChanged) Q_PROPERTY(QString lastError READ lastError NOTIFY contextChanged) Q_PROPERTY(bool online READ online NOTIFY runtimeChanged) @@ -59,6 +61,12 @@ class IedEngineeringContextController : public QObject { [[nodiscard]] QStringList candidateIeds() const { return candidateIeds_; } [[nodiscard]] QString accessPointName() const { return accessPointName_; } [[nodiscard]] QString endpoint() const { return endpoint_; } + [[nodiscard]] QString endpointHost() const { + return model_ ? QString::fromStdString(model_->endpoint.host) : QString{}; + } + [[nodiscard]] int endpointPort() const noexcept { + return model_ ? static_cast(model_->endpoint.port) : 102; + } [[nodiscard]] QString structuralFingerprint() const { return structuralFingerprint_; } [[nodiscard]] QString lastError() const { return lastError_; } [[nodiscard]] bool online() const noexcept { return online_; } diff --git a/apps/ied_simulator/src/MmsClientController.cpp b/apps/ied_simulator/src/MmsClientController.cpp index c4bdd720d..5429966f7 100644 --- a/apps/ied_simulator/src/MmsClientController.cpp +++ b/apps/ied_simulator/src/MmsClientController.cpp @@ -386,6 +386,10 @@ bool MmsClientController::connectToIed() { if (self->engineeringContext_) { self->engineeringContext_->publishTrustedSclOnline( *model, requestedTrustedSclPath); + for (const auto& value : *initialValues) { + self->engineeringContext_->treeModel()->applyReadValue( + snapshotKey(value), QString::fromStdString(value.display)); + } } self->appendDiagnostic(healthSummary); self->appendDiagnostic( @@ -512,7 +516,13 @@ void MmsClientController::startRead( if (self) { QMetaObject::invokeMethod(self, [self, generation, values, operationName] { if (!self || self->generation_ != generation) return; - for (const auto& value : values) self->treeModel_.applyReadValue(value.key, value.display); + for (const auto& value : values) { + self->treeModel_.applyReadValue(value.key, value.display); + if (self->engineeringContext_) { + self->engineeringContext_->treeModel()->applyReadValue( + value.key, value.display); + } + } self->setOperationBusy(false); self->lastError_.clear(); self->appendDiagnostic( @@ -550,6 +560,46 @@ bool MmsClientController::refreshVisible(const int firstRow, const int lastRow) return true; } +bool MmsClientController::readEngineeringSelected() { + if (!connected() || operationBusy_ || !engineeringContext_ || !engineeringContext_->loaded()) { + return false; + } + const auto targets = engineeringContext_->treeModel()->selectedReadTargets(); + if (targets.isEmpty()) return false; + startRead(targets, QStringLiteral("Read engineering selection")); + return true; +} + +bool MmsClientController::refreshEngineeringVisible(const int firstRow, const int lastRow) { + if (!connected() || operationBusy_ || !engineeringContext_ || !engineeringContext_->loaded()) { + return false; + } + const auto targets = + engineeringContext_->treeModel()->readTargetsForVisibleRange(firstRow, lastRow, 64); + if (targets.isEmpty()) return false; + startRead(targets, QStringLiteral("Refresh engineering model")); + return true; +} + +bool MmsClientController::writeEngineeringSelected(const QString& textValue) { + if (!connected() || operationBusy_ || !engineeringContext_ || !engineeringContext_->loaded()) { + return false; + } + const auto selection = engineeringContext_->treeModel()->selectionSnapshot(); + if (!selection || selection->domain.isEmpty() || selection->item.isEmpty()) { + lastError_ = QStringLiteral("Select a writable engineering-model DataAttribute first."); + emit stateChanged(); + return false; + } + if (!treeModel_.selectMmsItem(selection->domain, selection->item)) { + lastError_ = QStringLiteral( + "The selected engineering-model attribute is not present in the active MMS session."); + emit stateChanged(); + return false; + } + return writeSelected(textValue); +} + bool MmsClientController::writeSelected(const QString& textValue) { if (!connected() || operationBusy_) return false; const auto selection = treeModel_.selectionSnapshot(); @@ -604,7 +654,13 @@ bool MmsClientController::writeSelected(const QString& textValue) { if (self) { QMetaObject::invokeMethod(self, [self, generation, reference, values] { if (!self || self->generation_ != generation) return; - for (const auto& read : values) self->treeModel_.applyReadValue(read.key, read.display); + for (const auto& read : values) { + self->treeModel_.applyReadValue(read.key, read.display); + if (self->engineeringContext_) { + self->engineeringContext_->treeModel()->applyReadValue( + read.key, read.display); + } + } self->setOperationBusy(false); self->lastError_.clear(); self->appendDiagnostic(QStringLiteral("Guarded Write verified · %1").arg(reference)); diff --git a/apps/ied_simulator/src/MmsClientController.hpp b/apps/ied_simulator/src/MmsClientController.hpp index 3c943b1a5..6468f5652 100644 --- a/apps/ied_simulator/src/MmsClientController.hpp +++ b/apps/ied_simulator/src/MmsClientController.hpp @@ -99,6 +99,9 @@ class MmsClientController : public QObject { Q_INVOKABLE bool readSelected(); Q_INVOKABLE bool refreshVisible(int firstRow, int lastRow); Q_INVOKABLE bool writeSelected(const QString& textValue); + Q_INVOKABLE bool readEngineeringSelected(); + Q_INVOKABLE bool refreshEngineeringVisible(int firstRow, int lastRow); + Q_INVOKABLE bool writeEngineeringSelected(const QString& textValue); Q_INVOKABLE QString diagnosticsText() const; signals: diff --git a/apps/ied_simulator/src/ied_browser_session_qa.cpp b/apps/ied_simulator/src/ied_browser_session_qa.cpp index 686a1085e..c1e2ed6e1 100644 --- a/apps/ied_simulator/src/ied_browser_session_qa.cpp +++ b/apps/ied_simulator/src/ied_browser_session_qa.cpp @@ -12,10 +12,38 @@ int main(int argc, char** argv) { MmsReportController reports; MmsFileSettingsController utilities; IedBrowserSessionController browser; + IedEngineeringContextController engineeringContext; browser.setClient(&client); browser.setReports(&reports); browser.setUtilities(&utilities); + browser.setEngineeringContext(&engineeringContext); + + ar::iec61850::scl::SclDocument document; + document.source_name = "browser-context.cid"; + document.edition = ar::iec61850::scl::SclEdition::edition2; + document.ieds.push_back({"BROWSERIED", "ARStack", "QA", "1"}); + ar::iec61850::scl::SclMmsAccessPoint accessPoint; + accessPoint.ied_name = "BROWSERIED"; + accessPoint.access_point_name = "AP1"; + accessPoint.ip_address = "192.0.2.77"; + accessPoint.tcp_port = 8102; + document.mms_access_points.push_back(accessPoint); + ar::iec61850::scl::SclLogicalNode lln0; + lln0.ied_name = "BROWSERIED"; + lln0.ld_inst = "LD0"; + lln0.ln_class = "LLN0"; + lln0.name = "LLN0"; + document.logical_nodes.push_back(lln0); + + if (!engineeringContext.publishSclDocument( + document, QStringLiteral("/tmp/browser-context.cid")) || + browser.host() != QStringLiteral("192.0.2.77") || + browser.port() != 8102 || + client.engineeringContext() != &engineeringContext) { + std::cerr << "Canonical Browser engineering-context adoption failed.\n"; + return 2; + } browser.setHost(QStringLiteral("192.0.2.40")); browser.setPort(8102); @@ -28,7 +56,7 @@ int main(int argc, char** argv) { reports.port() != browser.port() || utilities.port() != browser.port() || client.trustedSclPath() != browser.trustedSclPath()) { std::cerr << "Browser endpoint/trusted-SCL propagation failed.\n"; - return 2; + return 3; } browser.setHost(QStringLiteral("[2001:db8::40]")); @@ -38,19 +66,19 @@ int main(int argc, char** argv) { client.host() != browser.host() || reports.host() != browser.host() || utilities.host() != browser.host()) { std::cerr << "Browser IPv6 endpoint normalization/propagation failed.\n"; - return 3; + return 4; } browser.setPort(0); if (browser.port() != 102 || browser.lastError().isEmpty()) { std::cerr << "Invalid Browser port did not fail closed.\n"; - return 4; + return 5; } browser.setHost(QStringLiteral("invalid host")); if (browser.host() != QStringLiteral("2001:db8::40") || browser.lastError().isEmpty()) { std::cerr << "Invalid Browser host did not fail closed.\n"; - return 5; + return 6; } browser.setHost(QStringLiteral("relay.local")); @@ -59,18 +87,20 @@ int main(int argc, char** argv) { reports.host() != QStringLiteral("relay.local") || utilities.host() != QStringLiteral("relay.local")) { std::cerr << "Browser recovery after invalid configuration failed.\n"; - return 6; + return 7; } browser.disconnectFromIed(); if (browser.connected() || client.connected() || reports.connected() || utilities.connected()) { std::cerr << "Coordinated Browser disconnect contract failed.\n"; - return 7; + return 8; } std::cout << "IED_BROWSER_SESSION_PASS" << " endpoint=relay.local:102" << " propagation=pass" + << " canonical_context=pass" + << " engineering_endpoint=pass" << " trusted_scl=pass" << " invalid_endpoint=fail_closed" << " disconnect=coordinated\n";