diff --git a/HopsanGUI/GUIObjects/GUIComponent.cpp b/HopsanGUI/GUIObjects/GUIComponent.cpp index 06aa4ef21..5a8d61e9a 100644 --- a/HopsanGUI/GUIObjects/GUIComponent.cpp +++ b/HopsanGUI/GUIObjects/GUIComponent.cpp @@ -197,7 +197,13 @@ bool Component::setParameterValue(QString name, QString value, bool force) app->x = double(1+i)/double(1+portSpecs.size()); app->rot = 270; app->mEnabled = true; - QString portName = "P"+QString::number(i+1); + QString portName; + if(portSpecs[i].contains(':')) { + portName = portSpecs[i].split(',').at(0).split(':').at(1); + } + else { + portName = "P"+QString::number(i+1); + } this->getAppearanceData()->addPortAppearance(portName, app); this->createRefreshExternalPort(portName); } diff --git a/componentLibraries/defaultLibrary/Connectivity/FMIWrapperQ.hpp b/componentLibraries/defaultLibrary/Connectivity/FMIWrapperQ.hpp index f928e5c86..3f9105570 100644 --- a/componentLibraries/defaultLibrary/Connectivity/FMIWrapperQ.hpp +++ b/componentLibraries/defaultLibrary/Connectivity/FMIWrapperQ.hpp @@ -13,6 +13,8 @@ #include "HopsanEssentials.h" #include "ComponentEssentials.h" #include "ComponentUtilities.h" +#include "CoreUtilities/StringUtilities.h" +#include #ifdef USEFMI4C #include "fmi4c.h" @@ -325,8 +327,17 @@ class FMIWrapperQ : public ComponentQ HVector ports = mPortSpecs.split(';'); int portNumber = 1; for(size_t i=0; i specs = ports[i].split(','); - HString nodeType = specs[0]; + HString nodeType, portName; + if(specs[0].containes(':')) { + nodeType = specs[0].split(':')[0]; + portName = specs[0].split(':')[1]; + } + else { + nodeType = specs[0]; + portName = "P"+to_hstring(portNumber); + } //Check that node is not empty (parameter not given) if(nodeType.empty()) { @@ -338,10 +349,12 @@ class FMIWrapperQ : public ComponentQ std::vector v = hopsanCore.getRegisteredNodeTypes(); if(std::find(v.begin(), v.end(), nodeType) == v.end()) { addErrorMessage("Unsupported node type: "+nodeType); - for(size_t i=0; igetName()); - } - mPorts.clear(); + return; + } + + //Check port name + if(!hopsan::isNameValid(portName)) { + addErrorMessage("Illegal port name: "+portName); return; } @@ -354,17 +367,35 @@ class FMIWrapperQ : public ComponentQ if(numberOfVariables != expectedNumberOfVariables) { addErrorMessage("Error in port type specification: \""+nodeType+"\" requires "+to_hstring(expectedNumberOfVariables)+" variables."); - for(size_t i=0; igetName()); - } - mPorts.clear(); return; } - Port *pPort = addPowerPort("P"+to_hstring(portNumber), nodeType, ""); - mPorts.push_back(pPort); + + //Check that all variables exist and are unique for(size_t i=0; i portNames = getPortNames(); + if(mFmiVersion == fmiVersion1 && fmi1_getVariableByName(fmu, specs[i+1].c_str()) == nullptr) { + addErrorMessage("Variable \""+specs[i+1]+"\" does not exist in FMU."); + return; + } + else if(mFmiVersion == fmiVersion2 && fmi2_getVariableByName(fmu, specs[i+1].c_str()) == nullptr) { + addErrorMessage("Variable \""+specs[i+1]+"\" does not exist in FMU."); + return; + } + else if(mFmiVersion == fmiVersion3 && fmi3_getVariableByName(fmu, specs[i+1].c_str()) == nullptr) { + addErrorMessage("Variable \""+specs[i+1]+"\" does not exist in FMU."); + return; + } + usedVariables.append(specs[i+1]); } + + Port *pPort = addPowerPort(portName, nodeType, ""); + mPorts.push_back(pPort); + ++portNumber; }