Get a server-defined trace configuration for a given tier and modify its traversability scope, add new condition barriers and control what is included in the subnetwork trace result.

Use case
While some traces are built from an ad-hoc group of parameters, many are based on a variation of the trace configuration taken from the subnetwork definition. For example, an electrical trace will be based on the trace configuration of the subnetwork, but may add additional clauses to constrain the trace along a single phase. Similarly, a trace in a gas or electric design application may include features with a status of “In Design” that are normally excluded from trace results.
How to use the sample
The sample loads with a server-defined trace configuration from a tier. Check or uncheck which options to include in the trace - such as containers or barriers. Use the selection boxes to define a new condition network attribute comparison, and then use ‘Add’ to add the it to the trace configuration. Click ‘Trace’ to run a subnetwork trace with this modified configuration from a default starting location.
Example barrier conditions for the default dataset:
- ‘Transformer Load’ Equal ‘15’
- ‘Phases Current’ DoesNotIncludeTheValues ‘A’
- ‘Generation KW’ LessThan ‘50’
How it works
- Create a
ServiceGeodatabasewith a feature service URL. - Create and load a
UtilityNetworkwith a feature service URL, then get an asset type and a tier by their names. - Populate the choice list for the comparison source with the non-system defined
Definition::networkAttributes. Populate the choice list for the comparison operator with the enum values fromUtilityAttributeComparisonOperator. - Create a
UtilityElementfrom this asset type to use as the starting location for the trace. - Update the selected barrier expression and the checked options in the UI using this tier’s
TraceConfiguration. - When ‘Network Attribute’ is selected, if its
Domainis aCodedValueDomain, populate the choice list for the comparison value with itsCodedValues. Otherwise, display a free-form textbox for entering an attribute value. - When ‘Add’ is clicked, create a new
UtilityNetworkAttributeComparisonusing the selected comparison source, operator, and selected or typed value. Use the selected source’sNetworkAttribute::dataTypeto convert the comparison value to the correct data type. - If the Traversability’s list of
Barriersis not empty, create aUtilityTraceOrConditionwith the existingBarriersand the new comparison from Step 6. - When ‘Trace’ is clicked, create
UtilityTraceParameterspassing inUtilityTraceType::subnetworkand the default starting location. Set itsTraceConfigurationwith the modified options, selections, and expression; then run aUtilityNetwork::traceAsync. - When
Resetis clicked, set the trace configurations expression back to its original value. - Display the count of returned
UtilityElementTraceResult::elements.
Relevant API
- CodedValueDomain
- UtilityAssetType
- UtilityAttributeComparisonOperator
- UtilityCategory
- UtilityCategoryComparison
- UtilityCategoryComparisonOperator
- UtilityDomainNetwork
- UtilityElement
- UtilityElementTraceResult
- UtilityNetwork
- UtilityNetworkAttribute
- UtilityNetworkAttributeComparison
- UtilityNetworkDefinition
- UtilityTerminal
- UtilityTier
- UtilityTraceAndCondition
- UtilityTraceConfiguration
- UtilityTraceOrCondition
- UtilityTraceParameters
- UtilityTraceResult
- UtilityTraceType
- UtilityTraversability
About the data
The Naperville electrical network feature service, hosted on ArcGIS Online, contains a utility network used to run the subnetwork-based trace shown in this sample.
Additional information
Using utility network on ArcGIS Enterprise 10.8 requires an ArcGIS Enterprise member account licensed with the Utility Network user type extension. Please refer to the utility network services documentation.
Credentials:
- Username: viewer01
- Password: I68VGU^nMurF
Tags
category comparison, condition barriers, network analysis, network attribute comparison, subnetwork trace, trace configuration, traversability, utility network, validate consistency
Sample Code
// [WriteFile Name=ConfigureSubnetworkTrace, Category=UtilityNetwork]// [Legal]// Copyright 2020 Esri.//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]
#ifdef PCH_BUILD#include "pch.hpp"#endif // PCH_BUILD
// sample headers#include "ConfigureSubnetworkTrace.h"
// ArcGIS Maps SDK headers#include "ArcGISRuntimeEnvironment.h"#include "Authentication/AuthenticationManager.h"#include "Authentication/ArcGISAuthenticationChallenge.h"#include "Authentication/TokenCredential.h"#include "CodedValueDomain.h"#include "Error.h"#include "ErrorException.h"#include "ServiceGeodatabase.h"#include "UtilityAssetGroup.h"#include "UtilityAssetType.h"#include "UtilityCategory.h"#include "UtilityCategoryComparison.h"#include "UtilityDomainNetwork.h"#include "UtilityElement.h"#include "UtilityElementTraceResult.h"#include "UtilityNetwork.h"#include "UtilityNetworkDefinition.h"#include "UtilityNetworkSource.h"#include "UtilityNetworkTypes.h"#include "UtilityTerminal.h"#include "UtilityTerminalConfiguration.h"#include "UtilityTier.h"#include "UtilityTraceAndCondition.h"#include "UtilityTraceConfiguration.h"#include "UtilityTraceOrCondition.h"#include "UtilityTraceParameters.h"#include "UtilityTraceResultListModel.h"#include "UtilityTraversability.h"
// Qt headers#include <QFuture>#include <QQmlEngine>
// STL headers#include <algorithm>
using namespace Esri::ArcGISRuntime;using namespace Esri::ArcGISRuntime::Authentication;
ConfigureSubnetworkTrace::ConfigureSubnetworkTrace(QObject* parent /* = nullptr */): ArcGISAuthenticationChallengeHandler(parent){ ArcGISRuntimeEnvironment::authenticationManager()->setArcGISAuthenticationChallengeHandler(this); m_utilityNetwork = new UtilityNetwork(new ServiceGeodatabase(m_featureLayerUrl, this), this);
connect(m_utilityNetwork, &UtilityNetwork::doneLoading, this, &ConfigureSubnetworkTrace::onUtilityNetworkLoaded);
m_utilityNetwork->load();}
QString ConfigureSubnetworkTrace::expressionToString(UtilityTraceConditionalExpression* expression){ switch (expression->traceConditionType()) { case UtilityTraceConditionType::UtilityNetworkAttributeComparison: { const UtilityNetworkAttributeComparison* attributeExpression = static_cast<UtilityNetworkAttributeComparison*>(expression); const UtilityNetworkAttribute* networkAttribute = attributeExpression->networkAttribute(); const UtilityNetworkAttribute* otherNetworkAttribute = attributeExpression->otherNetworkAttribute(); const Domain networkDomain = networkAttribute->domain(); const QString operatorAsString = comparisonOperatorToString(attributeExpression->comparisonOperator());
// check if attribute domain is a coded value domain. if (!networkDomain.isEmpty() && (networkDomain.domainType() == DomainType::CodedValueDomain)) { const CodedValueDomain codedValueDomain = static_cast<CodedValueDomain>(networkDomain); const QList<CodedValue> codedValues = codedValueDomain.codedValues();
// get the coded value using the value as the index for the list of coded values const QString codedValueName = codedValues[attributeExpression->value().toInt()].name();
return QString("`%1` %2 `%3`").arg(networkAttribute->name(), operatorAsString, codedValueName); } else { if (otherNetworkAttribute) { return QString("`%1` %2 `%3`").arg(networkAttribute->name(), operatorAsString, otherNetworkAttribute->name()); } return QString("`%1` %2 `%3`").arg(networkAttribute->name(), operatorAsString, attributeExpression->value().toString()); } } case UtilityTraceConditionType::UtilityCategoryComparison: { const UtilityCategoryComparison* comparisonExpression = static_cast<UtilityCategoryComparison*>(expression);
return QString("`%1` %2").arg(comparisonExpression->category()->name(), (comparisonExpression->comparisonOperator() == UtilityCategoryComparisonOperator::Exists) ? "Exists" : "DoesNotExist"); } case UtilityTraceConditionType::UtilityTraceAndCondition: { const UtilityTraceAndCondition* andExpression = static_cast<UtilityTraceAndCondition*>(expression);
return QString("(%1) AND\n (%2)").arg(expressionToString(andExpression->leftExpression()), expressionToString(andExpression->rightExpression())); } case UtilityTraceConditionType::UtilityTraceOrCondition: { const UtilityTraceOrCondition* orExpression = static_cast<UtilityTraceOrCondition*>(expression); return QString("(%1) OR\n (%2)").arg(expressionToString(orExpression->leftExpression()), expressionToString(orExpression->rightExpression())); } default: return QString("Unknown trace conditional expression"); }}
QString ConfigureSubnetworkTrace::comparisonOperatorToString(const UtilityAttributeComparisonOperator& comparisonOperator){ switch (comparisonOperator) { case UtilityAttributeComparisonOperator::Equal: return QString("Equal"); case UtilityAttributeComparisonOperator::NotEqual: return QString("NotEqual"); case UtilityAttributeComparisonOperator::GreaterThan: return QString("GreaterThan"); case UtilityAttributeComparisonOperator::GreaterThanEqual: return QString("GreaterThanEqual"); case UtilityAttributeComparisonOperator::LessThan: return QString("LessThan"); case UtilityAttributeComparisonOperator::LessThanEqual: return QString("LessThanEqual"); case UtilityAttributeComparisonOperator::IncludesTheValues: return QString("IncludesTheValues"); case UtilityAttributeComparisonOperator::DoesNotIncludeTheValues: return QString("DoesNotIncludeTheValues"); case UtilityAttributeComparisonOperator::IncludesAny: return QString("IncludesAny"); case UtilityAttributeComparisonOperator::DoesNotIncludeAny: return QString("DoesNotIncludeAny"); default: return QString("Unknown comparison operator"); }}
QVariant ConfigureSubnetworkTrace::convertToDataType(const QVariant& value, const Esri::ArcGISRuntime::UtilityNetworkAttributeDataType& dataType){ switch (dataType) { case UtilityNetworkAttributeDataType::Integer: { // inconsistent results when using QVariant.toInt() on a // QString that doesn't contain an Integer dataType. // e.g. QVariant(QString("123.321")).toInt(); return static_cast<int>(value.toDouble()); } case UtilityNetworkAttributeDataType::Float: { return value.toFloat(); } case UtilityNetworkAttributeDataType::Double: { return value.toDouble(); } case UtilityNetworkAttributeDataType::Boolean: { return value.toBool(); } default: return QVariant(); }}
void ConfigureSubnetworkTrace::codedValueOrInputText(const QString& currentText){ // Update the UI to show the correct value entry for the attribute. if (m_networkDefinition) { const Domain domain = m_networkDefinition->networkAttribute(currentText)->domain(); if (!domain.isEmpty() && (domain.domainType() == DomainType::CodedValueDomain)) { m_valueSelectionListModel.clear(); const CodedValueDomain codedValueDomain = static_cast<CodedValueDomain>(domain);
const auto values = codedValueDomain.codedValues(); for (const CodedValue& codedValue: values) m_valueSelectionListModel.append(codedValue.name());
m_textFieldVisible = false; } else { m_textFieldVisible = true; } emit valueSelectionListModelChanged(); emit textFieldVisibleChanged(); }}
void ConfigureSubnetworkTrace::addCondition(const QString& selectedAttribute, int selectedOperator, const QVariant& selectedValue){ // NOTE: You may also create a UtilityCategoryComparison with UtilityNetworkDefinition.Categories and UtilityCategoryComparisonOperator.
UtilityNetworkAttribute* selectedNetworkAttribute = m_networkDefinition->networkAttribute(selectedAttribute); const QVariant convertedSelectedValue = convertToDataType(selectedValue, selectedNetworkAttribute->dataType());
if (convertedSelectedValue.isNull()) { m_dialogText = "Unknow network attribute data type"; emit dialogTextChanged(); emit showDialog(); return; }
const UtilityAttributeComparisonOperator selectedOperatorEnum = static_cast<UtilityAttributeComparisonOperator>(selectedOperator);
// NOTE: You may also create a UtilityNetworkAttributeComparison with another NetworkAttribute. UtilityTraceConditionalExpression* expression = new UtilityNetworkAttributeComparison(selectedNetworkAttribute, selectedOperatorEnum, convertedSelectedValue, this);
UtilityTraceConditionalExpression* otherExpression = static_cast<UtilityTraceConditionalExpression*>(m_traceConfiguration->traversability()->barriers());
// NOTE: You may also combine expressions with UtilityTraceAndCondition UtilityTraceConditionalExpression* combineExpressions = new UtilityTraceOrCondition(otherExpression, expression, this);
m_expressionBuilder = expressionToString(combineExpressions); emit expressionBuilderChanged();
if (m_traceConfiguration) m_traceConfiguration->traversability()->setBarriers(combineExpressions);}
void ConfigureSubnetworkTrace::changeIncludeBarriersState(bool includeBarriers){ if (m_traceConfiguration) m_traceConfiguration->setIncludeBarriers(includeBarriers);}
void ConfigureSubnetworkTrace::changeIncludeContainersState(bool includeContainers){ if (m_traceConfiguration) m_traceConfiguration->setIncludeContainers(includeContainers);}
void ConfigureSubnetworkTrace::reset(){ // Reset the barrier condition to the initial value. m_traceConfiguration->traversability()->setBarriers(m_initialExpression); m_expressionBuilder.clear(); m_expressionBuilder = expressionToString(static_cast<UtilityTraceConditionalExpression*>(m_initialExpression)); emit expressionBuilderChanged();}
void ConfigureSubnetworkTrace::trace(){ if (!m_utilityNetwork || !m_utilityElementStartingLocation) { return; }
m_busy = true; emit busyChanged(); const QList<UtilityElement*> startingLocations {m_utilityElementStartingLocation}; // Create utility trace parameters for the starting location. m_traceParams = new UtilityTraceParameters(UtilityTraceType::Subnetwork, startingLocations, this); m_traceParams->setTraceConfiguration(m_traceConfiguration);
// trace the network m_utilityNetwork->traceAsync(m_traceParams).then(this, [this](QList<UtilityTraceResult*>) { onTraceCompleted_(); });}
void ConfigureSubnetworkTrace::onTraceCompleted_(){ if (m_utilityNetwork->traceResult()->isEmpty()) { m_dialogText = "No results returned"; emit dialogTextChanged(); emit showDialog(); return; } // Get the first result. UtilityTraceResult* result = m_utilityNetwork->traceResult()->at(0);
const QList<UtilityElement*> elements = static_cast<UtilityElementTraceResult*>(result)->elements(this);
// Display the number of elements found by the trace. m_dialogText = QString("%1 elements found.").arg(elements.length()); m_busy = false; emit dialogTextChanged(); emit showDialog(); emit busyChanged();}
void ConfigureSubnetworkTrace::onUtilityNetworkLoaded(const Error& e){ if (!e.isEmpty()) { m_dialogText = QString("%1 - %2").arg(e.message(), e.additionalMessage()); m_busy = false; emit dialogTextChanged(); emit showDialog(); emit busyChanged(); return; }
m_busy = false; emit busyChanged(); m_networkDefinition = m_utilityNetwork->definition();
// Build the choice lists for network attribute comparison. const auto attributes = m_networkDefinition->networkAttributes(); for (UtilityNetworkAttribute* networkAttribute : attributes) { if (!networkAttribute->isSystemDefined()) m_attributeListModel.append(networkAttribute->name()); } emit attributeListModelChanged();
// Create a default starting location. const UtilityNetworkSource* networkSource = m_networkDefinition->networkSource(m_deviceTableName); const UtilityAssetGroup* assetGroup = networkSource->assetGroup(m_assetGroupName); UtilityAssetType* assetType = assetGroup->assetType(m_assetTypeName); m_utilityElementStartingLocation = m_utilityNetwork->createElementWithAssetType(assetType, m_gloabId);
QList<UtilityTerminal*> terminals = m_utilityElementStartingLocation->assetType()->terminalConfiguration()->terminals();
// Set the terminal for this location. (For our case, we use the 'Load' terminal.) auto terminal = std::find_if(terminals.begin(), terminals.end(), [](UtilityTerminal* terminal) { return terminal->name() == "Load"; });
m_utilityElementStartingLocation->setTerminal(static_cast<UtilityTerminal*>(*terminal));
// Get a default trace configuration from a tier to update the UI. const UtilityDomainNetwork* domainNetwork = m_networkDefinition->domainNetwork(m_domainNetworkName); const UtilityTier* utilityTierSource = domainNetwork->tier(m_tierName);
// Set the trace configuration. m_traceConfiguration = utilityTierSource->defaultTraceConfiguration();
m_initialExpression = m_traceConfiguration->traversability()->barriers();
if (m_initialExpression) { m_expressionBuilder = expressionToString(static_cast<UtilityTraceConditionalExpression*>(m_initialExpression)); emit expressionBuilderChanged(); }
// Set the traversability scope. utilityTierSource->defaultTraceConfiguration()->traversability()->setScope(UtilityTraversabilityScope::Junctions);}
ConfigureSubnetworkTrace::~ConfigureSubnetworkTrace() = default;
void ConfigureSubnetworkTrace::init(){ qmlRegisterType<ConfigureSubnetworkTrace>("Esri.Samples", 1, 0, "ConfigureSubnetworkTraceSample");}
void ConfigureSubnetworkTrace::handleArcGISAuthenticationChallenge(ArcGISAuthenticationChallenge* challenge){ TokenCredential::createWithChallengeAsync(challenge, "viewer01", "I68VGU^nMurF", {}, this).then(this, [challenge](TokenCredential* tokenCredential) { challenge->continueWithCredential(tokenCredential); }).onFailed(this, [challenge](const ErrorException& e) { challenge->continueWithError(e.error()); });}// [WriteFile Name=ConfigureSubnetworkTrace, Category=UtilityNetwork]// [Legal]// Copyright 2020 Esri.//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]
#ifndef CONFIGURESUBNETWORKTRACE_H#define CONFIGURESUBNETWORKTRACE_H
// ArcGIS Maps SDK headers#include "Authentication/ArcGISAuthenticationChallengeHandler.h"#include "UtilityNetworkAttribute.h"#include "UtilityNetworkAttributeComparison.h"
// Qt headers#include <QUrl>#include <QUuid>
namespace Esri::ArcGISRuntime{class Credential;class Error;class UtilityElement;class UtilityNetwork;class UtilityNetworkDefinition;class UtilityTerminal;class UtilityTier;class UtilityTraceCondition;class UtilityTraceConditionalExpression;class UtilityTraceConfiguration;class UtilityTraceParameters;}
namespace Esri::ArcGISRuntime::Authentication{ class ArcGISAuthenticationChallenge;}
class ConfigureSubnetworkTrace : public Esri::ArcGISRuntime::Authentication::ArcGISAuthenticationChallengeHandler{ Q_OBJECT
Q_PROPERTY(bool busy MEMBER m_busy NOTIFY busyChanged) Q_PROPERTY(bool textFieldVisible MEMBER m_textFieldVisible NOTIFY textFieldVisibleChanged) Q_PROPERTY(QString dialogText MEMBER m_dialogText NOTIFY dialogTextChanged) Q_PROPERTY(QString expressionBuilder MEMBER m_expressionBuilder NOTIFY expressionBuilderChanged) Q_PROPERTY(QStringList attributeListModel MEMBER m_attributeListModel NOTIFY attributeListModelChanged) Q_PROPERTY(QStringList conditionBarrierExpressionListModel MEMBER m_conditionBarrierExpressionListModel NOTIFY conditionBarrierExpressionChanged) Q_PROPERTY(QStringList valueSelectionListModel MEMBER m_valueSelectionListModel NOTIFY valueSelectionListModelChanged)
public: explicit ConfigureSubnetworkTrace(QObject* parent = nullptr); ~ConfigureSubnetworkTrace();
static void init();
Q_INVOKABLE void addCondition(const QString& selectedAttribute, int selectedOperator, const QVariant& selectedValue); Q_INVOKABLE void changeIncludeBarriersState(bool includeBarriers); Q_INVOKABLE void changeIncludeContainersState(bool includeContainers); Q_INVOKABLE void codedValueOrInputText(const QString& currentText); Q_INVOKABLE void reset(); Q_INVOKABLE void trace();
signals: void attributeListModelChanged(); void busyChanged(); void conditionBarrierExpressionChanged(); void dialogTextChanged(); void showDialog(); void expressionBuilderChanged(); void textFieldVisibleChanged(); void valueSelectionListModelChanged();
private slots: void onUtilityNetworkLoaded(const Esri::ArcGISRuntime::Error& e);
private: void onTraceCompleted_();
static QString comparisonOperatorToString(const Esri::ArcGISRuntime::UtilityAttributeComparisonOperator& comparisonOperator); static QString expressionToString(Esri::ArcGISRuntime::UtilityTraceConditionalExpression* expression); static QVariant convertToDataType(const QVariant& value, const Esri::ArcGISRuntime::UtilityNetworkAttributeDataType& dataType);
void handleArcGISAuthenticationChallenge(Esri::ArcGISRuntime::Authentication::ArcGISAuthenticationChallenge* challenge) override;
Esri::ArcGISRuntime::UtilityElement* m_utilityElementStartingLocation = nullptr; Esri::ArcGISRuntime::UtilityNetwork* m_utilityNetwork = nullptr; Esri::ArcGISRuntime::UtilityNetworkDefinition* m_networkDefinition = nullptr; Esri::ArcGISRuntime::UtilityTraceCondition* m_initialExpression = nullptr; Esri::ArcGISRuntime::UtilityTraceConfiguration* m_traceConfiguration = nullptr; Esri::ArcGISRuntime::UtilityTraceParameters* m_traceParams = nullptr;
QStringList m_attributeListModel; QStringList m_conditionBarrierExpressionListModel; QStringList m_valueSelectionListModel;
bool m_busy = true; bool m_textFieldVisible = true; const QString m_assetGroupName = "Circuit Breaker"; const QString m_assetTypeName = "Three Phase"; const QString m_deviceTableName = "Electric Distribution Device"; const QString m_domainNetworkName = "ElectricDistribution"; const QString m_tierName = "Medium Voltage Radial"; const QUrl m_featureLayerUrl = QUrl("https://sampleserver7.arcgisonline.com/server/rest/services/UtilityNetwork/NapervilleElectric/FeatureServer"); const QUuid m_gloabId = QUuid("{1CAF7740-0BF4-4113-8DB2-654E18800028}"); QString m_dialogText; QString m_expressionBuilder;
};
#endif // CONFIGURESUBNETWORKTRACE_H// [WriteFile Name=ConfigureSubnetworkTrace, Category=UtilityNetwork]// [Legal]// Copyright 2020 Esri.//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]
import QtQuickimport QtQuick.Controlsimport QtQuick.Layoutsimport QtQuick.Shapesimport Esri.Samples
Item { readonly property var comparisonOperatorModel: ["Equal","NotEqual","GreaterThan","GreaterThanEqual","LessThan","LessThanEqual","IncludesTheValues","DoesNotIncludeTheValues","IncludesAny","DoesNotIncludeAny"]
Rectangle { id: rootRectangle anchors.fill: parent color: "lightgrey"
ScrollView { id: scrollView anchors.fill: parent
ColumnLayout { id: controlItemsLayout anchors.left: parent.left anchors.right: parent.right
CheckBox { text: qsTr("Include barriers") Layout.fillWidth: true enabled: !busyIndicator.visible checkState: Qt.Checked onCheckStateChanged: model.changeIncludeBarriersState(checked); }
CheckBox { text: qsTr("Include containers") Layout.fillWidth: true enabled: !busyIndicator.visible checkState: Qt.Checked onCheckStateChanged: model.changeIncludeContainersState(checked); }
Shape { height: 2 ShapePath { strokeWidth: 1 strokeColor: "black" strokeStyle: ShapePath.SolidLine startX: 2; startY: 0 PathLine { x: controlItemsLayout.width - 2 ; y: 0 } } }
Text { text: qsTr("Example barrier condition for this data. 'Transformer Load' Equal '15'") font.pixelSize: 11 Layout.minimumWidth: rootRectangle.width horizontalAlignment: Text.AlignHCenter enabled: !model.busy }
Shape { height: 2 ShapePath { strokeWidth: 1 strokeColor: "black" strokeStyle: ShapePath.SolidLine startX: 2; startY: 0 PathLine { x: controlItemsLayout.width - 2 ; y: 0 } } }
Text { text: qsTr("New Barrier Condition:") Layout.fillWidth: true }
ComboBox { id: networkAttributeComboBox model: model.attributeListModel ? model.attributeListModel : null Layout.fillWidth: true enabled: !busyIndicator.visible
onModelChanged: currentIndex = 0;
onCurrentTextChanged: model.codedValueOrInputText(currentText); }
ComboBox { id: comparisonOperatorComboBox model: comparisonOperatorModel Layout.fillWidth: true enabled: !busyIndicator.visible }
RowLayout { enabled: !model.busy ComboBox { id: valueSelectionComboBox Layout.fillWidth: true enabled: !busyIndicator.visible visible: !model.textFieldVisible model: model.valueSelectionListModel }
TextField { id: inputTextField Layout.minimumHeight: valueSelectionComboBox.height Layout.fillWidth: true visible: model.textFieldVisible validator: DoubleValidator {} color: "black" placeholderText: qsTr("Enter value here") placeholderTextColor: "black" selectByMouse: true background: Rectangle { anchors.centerIn: parent height: parent.height width: parent.width color: "white" } } }
Button { text: qsTr("Add") Layout.fillWidth: true enabled: !busyIndicator.visible onClicked: { if (model.textFieldVisible) { if (inputTextField.text) model.addCondition(networkAttributeComboBox.currentText, comparisonOperatorComboBox.currentIndex, inputTextField.text); return; } else { model.addCondition(networkAttributeComboBox.currentText, comparisonOperatorComboBox.currentIndex, valueSelectionComboBox.currentIndex); } } }
ScrollView { Layout.fillWidth: true Layout.maximumWidth: rootRectangle.width Layout.minimumHeight: 50 Layout.maximumHeight: .15 * rootRectangle.height clip: true Row { anchors.fill: parent Text { text: model.expressionBuilder } } }
RowLayout { enabled: !model.busy Button { text: qsTr("Trace") Layout.fillWidth: true enabled: !busyIndicator.visible onClicked: model.trace(); }
Button { text: qsTr("Reset") Layout.fillWidth: true enabled: !busyIndicator.visible onClicked: model.reset(); } } } } }
Dialog { id: dialog modal: true standardButtons: Dialog.Ok x: (parent.width - width) / 2 y: (parent.height - height) / 2
Text { text: model.dialogText anchors.centerIn: parent } }
BusyIndicator { id: busyIndicator anchors.centerIn: parent visible: model.busy }
ConfigureSubnetworkTraceSample { id: model
onShowDialog: dialog.open(); }}// [Legal]// Copyright 2020 Esri.//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]
// sample headers#include "ConfigureSubnetworkTrace.h"
// ArcGIS Maps SDK headers#include "ArcGISRuntimeEnvironment.h"
// Qt headers#include <QDir>#include <QGuiApplication>#include <QQmlApplicationEngine>
// Platform specific headers#ifdef Q_OS_WIN#include <Windows.h>#endif
int main(int argc, char *argv[]){ Esri::ArcGISRuntime::ArcGISRuntimeEnvironment::setUseLegacyAuthentication(false); QGuiApplication app(argc, argv); app.setApplicationName(QString("ConfigureSubnetworkTrace"));
// Use of ArcGIS location services, such as basemap styles, geocoding, and routing services, // requires an access token. For more information see // https://links.esri.com/arcgis-runtime-security-auth.
// The following methods grant an access token:
// 1. User authentication: Grants a temporary access token associated with a user's ArcGIS account. // To generate a token, a user logs in to the app with an ArcGIS account that is part of an // organization in ArcGIS Online or ArcGIS Enterprise.
// 2. API key authentication: Get a long-lived access token that gives your application access to // ArcGIS location services. Go to the tutorial at https://links.esri.com/create-an-api-key. // Copy the API Key access token.
const QString accessToken = QString("");
if (accessToken.isEmpty()) { qWarning() << "Use of ArcGIS location services, such as the basemap styles service, requires" << "you to authenticate with an ArcGIS account or set the API Key property."; } else { Esri::ArcGISRuntime::ArcGISRuntimeEnvironment::setApiKey(accessToken); }
// Initialize the sample ConfigureSubnetworkTrace::init();
// Initialize application view QQmlApplicationEngine engine; // Add the import Path engine.addImportPath(QDir(QCoreApplication::applicationDirPath()).filePath("qml"));
#ifdef ARCGIS_RUNTIME_IMPORT_PATH_2 engine.addImportPath(ARCGIS_RUNTIME_IMPORT_PATH_2);#endif
// Set the source engine.load(QUrl("qrc:/Samples/UtilityNetwork/ConfigureSubnetworkTrace/main.qml"));
return app.exec();}// Copyright 2020 Esri.
// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.
import QtQuick.Controlsimport Esri.Samples
ApplicationWindow { visible: true width: 800 height: 600
ConfigureSubnetworkTrace { anchors.fill: parent }}