From 8552ba089bff7c20d4f431002c27f298df9df408 Mon Sep 17 00:00:00 2001 From: Robert Braun Date: Wed, 17 Feb 2021 10:39:12 +0100 Subject: [PATCH] Prevent adding same DCP server twice in same model --- HopsanGUI/GraphicsView.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/HopsanGUI/GraphicsView.cpp b/HopsanGUI/GraphicsView.cpp index efceac188c..3d758dd78e 100644 --- a/HopsanGUI/GraphicsView.cpp +++ b/HopsanGUI/GraphicsView.cpp @@ -154,6 +154,14 @@ void GraphicsView::contextMenuEvent ( QContextMenuEvent * event ) QFileInfo dcpFileInfo(dcpPath); gpConfig->setStringSetting(CFG_DCPDIR, dcpFileInfo.absolutePath()); + //Check that DCP server is not already added to model + for(const auto &comp : mpParentModelWidget->getTopLevelSystemContainer()->getModelObjects()) { + if(comp->getParameterValue("dcpFile") == dcpFileInfo.absoluteFilePath()) { + gpMessageHandler->addErrorMessage("Specified DCP server already exists in model. Only one instance is allowed."); + return; + } + } + hopsan::HString name, variables, valueRefs; getDataFromProtocolFile(dcpFileInfo.filePath().toStdString().c_str(), name, variables, valueRefs);