diff --git a/.github/workflows/ied-simulator-qt.yml b/.github/workflows/ied-simulator-qt.yml index bf09ec6ab..9596caccc 100644 --- a/.github/workflows/ied-simulator-qt.yml +++ b/.github/workflows/ied-simulator-qt.yml @@ -133,6 +133,13 @@ jobs: apps/ied_simulator/qml/FileWorkspace.qml apps/ied_simulator/qml/Main.qml + - name: IEDScout-style Browser convergence contract + run: >- + python3 apps/ied_simulator/test_browser_convergence.py + apps/ied_simulator/qml/IedBrowserWorkspace.qml + apps/ied_simulator/qml/IedBrowserNavigation.qml + apps/ied_simulator/qml/BrowserStatusConsole.qml + - name: IED Browser session ownership gates env: QT_QPA_PLATFORM: offscreen diff --git a/apps/ied_simulator/CMakeLists.txt b/apps/ied_simulator/CMakeLists.txt index 02df93694..13f104fb5 100644 --- a/apps/ied_simulator/CMakeLists.txt +++ b/apps/ied_simulator/CMakeLists.txt @@ -95,6 +95,7 @@ qt_add_qml_module(arstack_ied_simulator qml/FileWorkspace.qml qml/IedBrowserWorkspace.qml qml/IedBrowserNavigation.qml + qml/BrowserStatusConsole.qml qml/BrowserDataSetPane.qml qml/BrowserGoosePane.qml qml/SnifferWorkspace.qml diff --git a/apps/ied_simulator/qml/BrowserStatusConsole.qml b/apps/ied_simulator/qml/BrowserStatusConsole.qml new file mode 100644 index 000000000..b225cd469 --- /dev/null +++ b/apps/ied_simulator/qml/BrowserStatusConsole.qml @@ -0,0 +1,258 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +Rectangle { + id: root + + required property var theme + required property var session + required property var client + required property var context + required property var reports + required property var utilities + + property bool expanded: false + readonly property int maximumEntries: 80 + property string lastEventKey: "" + + Layout.fillWidth: true + Layout.preferredHeight: expanded ? 152 : 26 + color: theme.statusChrome + border.width: 1 + border.color: session.lastError.length ? theme.red : theme.lineSoft + + ListModel { id: historyModel } + + function eventSeverity(errorText, busy, connected) { + if (errorText && String(errorText).length > 0) return "error" + if (busy) return "busy" + if (connected) return "success" + return "info" + } + + function appendEvent(category, message, severity) { + const normalized = String(message || "").trim() + if (!normalized.length) + return + const key = category + "|" + normalized + "|" + severity + if (key === lastEventKey) + return + lastEventKey = key + historyModel.insert(0, { + time: Qt.formatTime(new Date(), "HH:mm:ss"), + category: category, + message: normalized, + severity: severity + }) + while (historyModel.count > maximumEntries) + historyModel.remove(historyModel.count - 1) + } + + function captureSession() { + appendEvent( + "SESSION", + session.lastError.length ? session.lastError : session.stateText + " · " + session.endpoint, + eventSeverity(session.lastError, session.busy, session.connected)) + } + + function captureContext() { + if (!context.loaded) { + appendEvent("MODEL", "No active engineering model", "info") + return + } + appendEvent( + "MODEL", + (context.iedName.length ? context.iedName : "IED") + + " · " + context.authority + + " · " + (context.online ? "ONLINE" : "OFFLINE"), + context.online ? "success" : "info") + } + + function captureReports() { + if (reports.lastError.length) { + appendEvent("REPORT", reports.lastError, "error") + return + } + if (reports.connected) + appendEvent("REPORT", reports.stateText, reports.active ? "success" : "info") + } + + function captureUtilities() { + if (utilities.lastError.length) { + appendEvent("UTILITY", utilities.lastError, "error") + return + } + if (utilities.connected) + appendEvent("UTILITY", utilities.stateText, "info") + } + + Component.onCompleted: { + appendEvent("BROWSER", "Engineering Browser ready", "info") + captureContext() + captureSession() + } + + Connections { + target: root.session + function onStateChanged() { root.captureSession() } + } + Connections { + target: root.context + function onContextChanged() { root.captureContext() } + function onRuntimeChanged() { root.captureContext() } + } + Connections { + target: root.reports + function onStateChanged() { root.captureReports() } + } + Connections { + target: root.utilities + function onStateChanged() { root.captureUtilities() } + } + Connections { + target: root.client + function onDiagnosticsChanged() { + if (root.client.lastError.length) + root.appendEvent("MMS", root.client.lastError, "error") + else if (root.client.lastDiagnostic.length) + root.appendEvent("MMS", root.client.lastDiagnostic, "info") + } + } + + ColumnLayout { + anchors.fill: parent + spacing: 0 + + Rectangle { + Layout.fillWidth: true + Layout.preferredHeight: 26 + color: session.lastError.length ? theme.redSoft : theme.statusChrome + + RowLayout { + anchors.fill: parent + anchors.leftMargin: 9 + anchors.rightMargin: 7 + spacing: 7 + + Rectangle { + width: 6 + height: 6 + radius: 3 + color: session.lastError.length ? theme.red + : session.connected ? theme.green + : session.busy ? theme.amber + : theme.muted + } + + Label { + text: "STATUS" + color: session.lastError.length ? theme.red : theme.navigationMuted + font.pixelSize: 7 + font.weight: Font.DemiBold + } + + Label { + Layout.fillWidth: true + text: session.lastError.length + ? session.lastError + : session.stateText + " · " + (context.loaded ? (context.iedName || "IED") : "no model") + color: session.lastError.length ? theme.red : theme.navigationText + font.pixelSize: 8 + elide: Text.ElideRight + } + + Label { + text: historyModel.count + "/" + maximumEntries + color: session.lastError.length ? theme.red : theme.navigationMuted + font.pixelSize: 7 + } + + ToolButton { + text: root.expanded ? "Hide history" : "History" + font.pixelSize: 8 + onClicked: root.expanded = !root.expanded + } + } + } + + ListView { + id: historyList + visible: root.expanded + Layout.fillWidth: true + Layout.fillHeight: true + clip: true + model: historyModel + boundsBehavior: Flickable.StopAtBounds + ScrollBar.vertical: ScrollBar { policy: ScrollBar.AsNeeded } + + delegate: Rectangle { + required property string time + required property string category + required property string message + required property string severity + + width: historyList.width + height: 25 + color: index % 2 ? root.theme.chrome : root.theme.surface + + RowLayout { + anchors.fill: parent + anchors.leftMargin: 9 + anchors.rightMargin: 9 + spacing: 8 + + Label { + Layout.preferredWidth: 46 + text: time + color: root.theme.muted + font.pixelSize: 7 + } + Label { + Layout.preferredWidth: 52 + text: category + color: severity === "error" ? root.theme.red + : severity === "success" ? root.theme.green + : severity === "busy" ? root.theme.amber + : root.theme.accent + font.pixelSize: 7 + font.weight: Font.DemiBold + } + Label { + Layout.fillWidth: true + text: message + color: root.theme.textSoft + font.pixelSize: 8 + elide: Text.ElideRight + } + } + } + } + + RowLayout { + visible: root.expanded + Layout.fillWidth: true + Layout.preferredHeight: root.expanded ? 24 : 0 + Layout.leftMargin: 9 + Layout.rightMargin: 7 + spacing: 6 + + Label { + Layout.fillWidth: true + text: "Bounded Browser history · no background polling" + color: root.theme.navigationMuted + font.pixelSize: 7 + } + ToolButton { + text: "Clear" + font.pixelSize: 8 + enabled: historyModel.count > 0 + onClicked: { + historyModel.clear() + root.lastEventKey = "" + } + } + } + } +} diff --git a/apps/ied_simulator/qml/IedBrowserNavigation.qml b/apps/ied_simulator/qml/IedBrowserNavigation.qml index d90d332d9..b4e8dcad6 100644 --- a/apps/ied_simulator/qml/IedBrowserNavigation.qml +++ b/apps/ied_simulator/qml/IedBrowserNavigation.qml @@ -64,7 +64,7 @@ Rectangle { RowLayout { anchors.fill: parent - anchors.leftMargin: 10 + anchors.leftMargin: 24 anchors.rightMargin: 8 spacing: 7 Label { @@ -102,7 +102,7 @@ Rectangle { Rectangle { Layout.fillWidth: true - Layout.preferredHeight: 56 + Layout.preferredHeight: 42 color: root.theme.statusChrome border.width: 1 border.color: root.theme.lineSoft @@ -111,31 +111,21 @@ Rectangle { anchors.fill: parent anchors.leftMargin: 10 anchors.rightMargin: 10 - anchors.topMargin: 7 - anchors.bottomMargin: 7 - spacing: 1 + anchors.topMargin: 6 + anchors.bottomMargin: 6 + spacing: 0 Label { Layout.fillWidth: true - text: client.iedName.length ? client.iedName : "IED" - color: root.theme.text - font.pixelSize: 10 + text: "ENGINEERING EXPLORER" + color: root.theme.navigationText + font.pixelSize: 9 font.weight: Font.DemiBold - elide: Text.ElideRight - } - Label { - Layout.fillWidth: true - text: session.endpoint - color: root.theme.muted - font.pixelSize: 8 - elide: Text.ElideMiddle } Label { Layout.fillWidth: true - text: session.connected - ? client.logicalDeviceCount + " LD · " + client.logicalNodeCount + " LN" - : "Offline" - color: session.connected ? root.theme.green : root.theme.muted - font.pixelSize: 8 + text: "One active IED context" + color: root.theme.navigationMuted + font.pixelSize: 7 } } } @@ -149,6 +139,56 @@ Rectangle { width: Math.max(0, parent.width) spacing: 0 + Rectangle { + id: iedRoot + Layout.fillWidth: true + implicitHeight: 39 + color: root.theme.surfaceSoft + border.width: 1 + border.color: root.theme.lineSoft + + RowLayout { + anchors.fill: parent + anchors.leftMargin: 10 + anchors.rightMargin: 8 + spacing: 6 + + Label { + text: "▾" + color: root.theme.accent + font.pixelSize: 10 + Layout.preferredWidth: 12 + } + ColumnLayout { + Layout.fillWidth: true + spacing: 0 + Label { + Layout.fillWidth: true + text: context.iedName.length ? context.iedName : "IED" + color: root.theme.text + font.pixelSize: 9 + font.weight: Font.DemiBold + elide: Text.ElideRight + } + Label { + Layout.fillWidth: true + text: context.loaded + ? context.authority + " · " + (context.endpoint.length ? context.endpoint : session.endpoint) + : "No engineering model loaded" + color: root.theme.muted + font.pixelSize: 7 + elide: Text.ElideMiddle + } + } + Label { + text: context.online ? "ONLINE" : "OFFLINE" + color: context.online ? root.theme.green : root.theme.muted + font.pixelSize: 7 + font.weight: Font.DemiBold + } + } + } + NavButton { targetSection: 5 title: "GOOSE" @@ -374,7 +414,7 @@ Rectangle { RowLayout { anchors.fill: parent - anchors.leftMargin: 18 + model.depth * 12 + anchors.leftMargin: 30 + model.depth * 12 anchors.rightMargin: 7 spacing: 4 Label { diff --git a/apps/ied_simulator/qml/IedBrowserWorkspace.qml b/apps/ied_simulator/qml/IedBrowserWorkspace.qml index 686aa38c3..d9d21f3a4 100644 --- a/apps/ied_simulator/qml/IedBrowserWorkspace.qml +++ b/apps/ied_simulator/qml/IedBrowserWorkspace.qml @@ -20,6 +20,10 @@ Item { property string activeSectionTitle: "Data Model" property var selectedModelNode: context.treeModel.selectedNode + function activeIedLabel() { + return context.iedName && context.iedName.length ? context.iedName : "IED" + } + function ensureActiveService() { if (!session.connected) return @@ -32,22 +36,22 @@ Item { function breadcrumb() { if (activeSection === 0) { var ref = selectedModelNode.reference || selectedModelNode.label || "" - return ref.length ? "IED / Data Model / " + ref : "IED / Data Model" + return ref.length ? root.activeIedLabel() + " / Data Model / " + ref : root.activeIedLabel() + " / Data Model" } if (activeSection === 1) { if (reports.selectedDataSetIndex >= 0 && reports.selectedDataSetIndex < reports.dataSets.length) - return "IED / DataSets / " + (reports.dataSets[reports.selectedDataSetIndex].reference || "") - return "IED / DataSets" + return root.activeIedLabel() + " / DataSets / " + (reports.dataSets[reports.selectedDataSetIndex].reference || "") + return root.activeIedLabel() + " / DataSets" } if (activeSection === 2) - return reports.selectedRcb.reference ? "IED / Reports / " + reports.selectedRcb.reference : "IED / Reports" + return reports.selectedRcb.reference ? root.activeIedLabel() + " / Reports / " + reports.selectedRcb.reference : root.activeIedLabel() + " / Reports" if (activeSection === 3) return utilities.selectedSettingGroup.reference - ? "IED / Setting Groups / " + utilities.selectedSettingGroup.reference - : "IED / Setting Groups" + ? root.activeIedLabel() + " / Setting Groups / " + utilities.selectedSettingGroup.reference + : root.activeIedLabel() + " / Setting Groups" if (activeSection === 4) - return "IED / Files" + (utilities.currentDirectory.length ? " / " + utilities.currentDirectory : "") - return "IED / GOOSE" + return root.activeIedLabel() + " / Files" + (utilities.currentDirectory.length ? " / " + utilities.currentDirectory : "") + return root.activeIedLabel() + " / GOOSE" } function selectSection(section, title) { @@ -102,7 +106,7 @@ Item { Rectangle { Layout.fillWidth: true - Layout.preferredHeight: 58 + Layout.preferredHeight: 62 color: root.theme.chrome border.width: 1 border.color: root.theme.lineSoft @@ -117,14 +121,14 @@ Item { Layout.preferredWidth: 155 spacing: 1 Label { - text: "IED BROWSER" + text: "MODEL" color: root.theme.text font.pixelSize: 11 font.weight: Font.DemiBold } Label { text: context.loaded - ? context.authority + " · persistent engineering navigation" + ? root.activeIedLabel() + " · " + context.authority : "Open SCL or discover one IED endpoint" color: root.theme.muted font.pixelSize: 8 @@ -173,7 +177,7 @@ Item { } Button { - text: context.loaded && context.authorityKey === "scl" ? "Connect SCL" : "Connect model" + text: "Online" visible: context.loaded enabled: !session.connected && !session.busy && !context.selectionRequired onClicked: { @@ -352,6 +356,14 @@ Item { anchors.rightMargin: 10 spacing: 7 + Label { + text: "COMMANDS" + color: root.theme.muted + font.pixelSize: 7 + font.weight: Font.DemiBold + Layout.rightMargin: 2 + } + ColumnLayout { Layout.fillWidth: true spacing: 0 @@ -462,49 +474,13 @@ Item { } } - Rectangle { - Layout.fillWidth: true - Layout.preferredHeight: 24 - color: session.lastError.length ? root.theme.redSoft : root.theme.statusChrome - border.width: 1 - border.color: session.lastError.length ? root.theme.red : root.theme.lineSoft - - RowLayout { - anchors.fill: parent - anchors.leftMargin: 10 - anchors.rightMargin: 10 - spacing: 8 - - Rectangle { - width: 6 - height: 6 - radius: 3 - color: session.lastError.length ? root.theme.red - : session.connected ? root.theme.green - : session.busy ? root.theme.amber - : root.theme.muted - } - Label { - Layout.fillWidth: true - text: session.lastError.length - ? session.lastError - : session.stateText + " · " + root.activeSectionTitle - color: session.lastError.length ? root.theme.red : root.theme.navigationText - font.pixelSize: 8 - elide: Text.ElideRight - } - Label { - text: session.endpoint - color: session.lastError.length ? root.theme.red : root.theme.navigationMuted - font.pixelSize: 8 - } - Label { - 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 - } - } + BrowserStatusConsole { + theme: root.theme + session: root.session + client: root.client + context: root.context + reports: root.reports + utilities: root.utilities } } } diff --git a/apps/ied_simulator/test_browser_convergence.py b/apps/ied_simulator/test_browser_convergence.py new file mode 100644 index 000000000..82e4824ce --- /dev/null +++ b/apps/ied_simulator/test_browser_convergence.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +from pathlib import Path +import sys + +if len(sys.argv) != 4: + raise SystemExit("usage: test_browser_convergence.py IedBrowserWorkspace.qml IedBrowserNavigation.qml BrowserStatusConsole.qml") + +workspace = Path(sys.argv[1]).read_text(encoding="utf-8") +navigation = Path(sys.argv[2]).read_text(encoding="utf-8") +status = Path(sys.argv[3]).read_text(encoding="utf-8") + +workspace_required = [ + 'text: "MODEL"', + 'text: "COMMANDS"', + 'text: "Online"', + '"Discover IED"', + 'client.readEngineeringSelected()', + 'BrowserStatusConsole {', + 'modelProvider: root.context', +] +navigation_required = [ + 'text: "ENGINEERING EXPLORER"', + 'id: iedRoot', + 'title: "GOOSE"', + 'title: "Reports"', + 'title: "Setting Groups"', + 'title: "Files"', + 'title: "DataSets"', + 'title: "Data Model"', + 'context.treeModel', +] +status_required = [ + 'readonly property int maximumEntries: 80', + 'while (historyModel.count > maximumEntries)', + 'function captureSession()', + 'function captureContext()', + 'Bounded Browser history · no background polling', +] + +for label, source, required in [ + ("workspace", workspace, workspace_required), + ("navigation", navigation, navigation_required), + ("status", status, status_required), +]: + missing = [token for token in required if token not in source] + if missing: + raise SystemExit("BROWSER_CONVERGENCE_FAIL " + label + " missing=" + ",".join(missing)) + +if "client.treeModel" in navigation: + raise SystemExit("BROWSER_CONVERGENCE_FAIL navigation regressed to session-owned model") +if "Timer {" in status: + raise SystemExit("BROWSER_CONVERGENCE_FAIL status console introduced polling timer") +if "maximumEntries: 80" not in status: + raise SystemExit("BROWSER_CONVERGENCE_FAIL status history is not bounded") + +print("BROWSER_CONVERGENCE_PASS ied_root=pass contextual_commands=pass canonical_tree=pass bounded_history=80 polling=false")