From 6dbefd646d04d287132e8361438a532879ef605f Mon Sep 17 00:00:00 2001 From: Robert Braun Date: Thu, 8 Feb 2024 09:35:36 +0100 Subject: [PATCH 1/3] Internal attribute for system parameters --- HopsanCore/include/ComponentSystem.h | 4 +- HopsanCore/include/Parameters.h | 10 ++-- HopsanCore/src/Component.cpp | 2 +- HopsanCore/src/ComponentSystem.cpp | 10 ++-- HopsanCore/src/CoreUtilities/HmfLoader.cpp | 3 +- HopsanCore/src/Parameters.cpp | 22 ++++++-- HopsanGUI/CoreAccess.cpp | 3 + HopsanGUI/CoreAccess.h | 5 +- HopsanGUI/GUIObjects/GUIComponent.cpp | 3 +- HopsanGUI/GUIObjects/GUIContainerObject.cpp | 59 ++++++++++---------- HopsanGUI/GUIObjects/GUIModelObject.cpp | 2 +- HopsanGUI/UndoStack.cpp | 8 +-- HopsanGUI/Utilities/XMLUtilities.cpp | 6 +- HopsanGUI/Utilities/XMLUtilities.h | 5 +- HopsanGUI/Widgets/SystemParametersWidget.cpp | 21 ++++++- HopsanGUI/loadFunctions.cpp | 3 +- HopsanGenerator/src/GeneratorTypes.cpp | 3 + 17 files changed, 107 insertions(+), 62 deletions(-) diff --git a/HopsanCore/include/ComponentSystem.h b/HopsanCore/include/ComponentSystem.h index 9f6cfa55e8..d2f67f0c0f 100644 --- a/HopsanCore/include/ComponentSystem.h +++ b/HopsanCore/include/ComponentSystem.h @@ -166,8 +166,8 @@ namespace hopsan { bool wasSimulationAborted() const; // System parameters - bool setOrAddSystemParameter(const HString &rName, const HString &rValue, const HString &rType, const HString &rDescription="", const HString &rUnitOrQuantity="", const bool force=false); - bool setSystemParameter(const HString &rName, const HString &rValue, const HString &rType, const HString &rDescription="", const HString &rUnitOrQuantity="", const bool force=false); + bool setOrAddSystemParameter(const HString &rName, const HString &rValue, const HString &rType, const HString &rDescription="", const HString &rUnitOrQuantity="", const bool internal=false, const bool force=false); + bool setSystemParameter(const HString &rName, const HString &rValue, const HString &rType, const HString &rDescription="", const HString &rUnitOrQuantity="", const bool internal=false, const bool force=false); void unRegisterParameter(const HString &name); void addSearchPath(HString searchPath); diff --git a/HopsanCore/include/Parameters.h b/HopsanCore/include/Parameters.h index 8f0b239a0f..2f4000f841 100644 --- a/HopsanCore/include/Parameters.h +++ b/HopsanCore/include/Parameters.h @@ -48,11 +48,11 @@ class HOPSANCORE_DLLAPI ParameterEvaluator friend class ParameterEvaluatorHandler; public: ParameterEvaluator(const HString &rName, const HString &rValue, const HString &rDescription, const HString &rQuantity, const HString &rUnit, - const HString &rType, void* pDataPtr=0, ParameterEvaluatorHandler* pParameterEvalHandler=0); + const HString &rType, const bool internal=false, void* pDataPtr=0, ParameterEvaluatorHandler* pParameterEvalHandler=0); bool setParameterValue(const HString &rValue, ParameterEvaluator **ppNeedEvaluation=0, bool force=false); bool setParameter(const HString &rValue, const HString &rDescription, const HString &rQuantity, const HString &rUnit, - const HString &rType, ParameterEvaluator **pNeedEvaluation=0, bool force=false); + const HString &rType, ParameterEvaluator **pNeedEvaluation=0, bool internal=false, bool force=false); bool evaluate(HString &rResult); bool evaluate(); @@ -67,6 +67,7 @@ class HOPSANCORE_DLLAPI ParameterEvaluator const HString &getDescription() const; const HString &getQuantity() const; const std::vector &getConditions() const; + bool isInternal() const; void setTriggersReconfiguration(); bool triggersReconfiguration(); @@ -85,6 +86,7 @@ class HOPSANCORE_DLLAPI ParameterEvaluator size_t mDepthCounter; ParameterEvaluatorHandler* mpParameterEvaluatorHandler; std::vector mConditions; + bool mInternal; bool mTriggersReconfiguration; }; @@ -97,7 +99,7 @@ class HOPSANCORE_DLLAPI ParameterEvaluatorHandler bool addParameter(const HString &rName, const HString &rValue, const HString &rDescription, const HString &rQuantity, const HString &rUnit, const HString &rType, - void* pData=0, bool force=false, std::vector conditions = std::vector()); + void* pData=0, bool internal=false, bool force=false, std::vector conditions = std::vector()); void deleteParameter(const HString &rName); bool renameParameter(const HString &rOldName, const HString &rNewName); @@ -105,7 +107,7 @@ class HOPSANCORE_DLLAPI ParameterEvaluatorHandler const ParameterEvaluator* getParameter(const HString &rName) const; void getParameterNames(std::vector &rParameterNames); bool setParameter(const HString &rName, const HString &rValue, const HString &rDescription="", const HString &rQuantity="", - const HString &rUnit="", const HString &rType="", const bool force=false); + const HString &rUnit="", const HString &rType="", const bool internal=false, const bool force=false); void getParameterValue(const HString &rName, HString &rValue); bool setParameterValue(const HString &rName, const HString &rValue, bool force=false); diff --git a/HopsanCore/src/Component.cpp b/HopsanCore/src/Component.cpp index d1a0926636..edac2ce839 100644 --- a/HopsanCore/src/Component.cpp +++ b/HopsanCore/src/Component.cpp @@ -728,7 +728,7 @@ void Component::registerConditionalParameter(const HString &rName, const HString if(mpParameters->hasParameter(rName)) mpParameters->deleteParameter(rName); //Remove parameter if it is already registered - mpParameters->addParameter(rName, to_hstring(rValue), rDescription, "", "", "conditional", &rValue, false, rConditions); + mpParameters->addParameter(rName, to_hstring(rValue), rDescription, "", "", "conditional", &rValue, false, false, rConditions); } diff --git a/HopsanCore/src/ComponentSystem.cpp b/HopsanCore/src/ComponentSystem.cpp index 509c380648..9536499d41 100644 --- a/HopsanCore/src/ComponentSystem.cpp +++ b/HopsanCore/src/ComponentSystem.cpp @@ -290,14 +290,14 @@ void ComponentSystem::addSearchPath(HString searchPath) //! @brief Set, add or change a system parameter including all meta data -bool ComponentSystem::setOrAddSystemParameter(const HString &rName, const HString &rValue, const HString &rType, const HString &rDescription, const HString &rUnitOrQuantity, const bool force) +bool ComponentSystem::setOrAddSystemParameter(const HString &rName, const HString &rValue, const HString &rType, const HString &rDescription, const HString &rUnitOrQuantity, const bool internal, const bool force) { bool success; HString quantity, bu; if(mpParameters->hasParameter(rName)) { checkIfQuantityOrUnit(rUnitOrQuantity, quantity, bu); - success = mpParameters->setParameter(rName, rValue, rDescription, quantity, bu, rType, force); + success = mpParameters->setParameter(rName, rValue, rDescription, quantity, bu, rType, internal, force); } else { @@ -309,7 +309,7 @@ bool ComponentSystem::setOrAddSystemParameter(const HString &rName, const HStrin else { checkIfQuantityOrUnit(rUnitOrQuantity, quantity, bu); - success = mpParameters->addParameter(rName, rValue, rDescription, quantity, bu, rType, 0, force); + success = mpParameters->addParameter(rName, rValue, rDescription, quantity, bu, rType, 0, internal, force); if (success) { reserveUniqueName(rName,UniqueSysparamNameType); @@ -322,11 +322,11 @@ bool ComponentSystem::setOrAddSystemParameter(const HString &rName, const HStrin //! @brief Set or change a system parameter including all meta data -bool ComponentSystem::setSystemParameter(const HString &rName, const HString &rValue, const HString &rType, const HString &rDescription, const HString &rUnitOrQuantity, const bool force) +bool ComponentSystem::setSystemParameter(const HString &rName, const HString &rValue, const HString &rType, const HString &rDescription, const HString &rUnitOrQuantity, const bool internal, const bool force) { if(mpParameters->hasParameter(rName)) { - return setOrAddSystemParameter(rName, rValue, rType, rDescription, rUnitOrQuantity, force); + return setOrAddSystemParameter(rName, rValue, rType, rDescription, rUnitOrQuantity, internal, force); } addErrorMessage("No such system parameter: "+rName); return false; diff --git a/HopsanCore/src/CoreUtilities/HmfLoader.cpp b/HopsanCore/src/CoreUtilities/HmfLoader.cpp index c82b579576..89265fdc7f 100644 --- a/HopsanCore/src/CoreUtilities/HmfLoader.cpp +++ b/HopsanCore/src/CoreUtilities/HmfLoader.cpp @@ -674,13 +674,14 @@ void loadSystemParameters(rapidxml::xml_node<> *pSysNode, ComponentSystem* pSyst string paramName = readStringAttribute(pParameter, "name", "ERROR_NO_PARAM_NAME_GIVEN"); string val = readStringAttribute(pParameter, "value", "ERROR_NO_PARAM_VALUE_GIVEN"); string type = readStringAttribute(pParameter, "type", "ERROR_NO_PARAM_TYPE_GIVEN"); + bool internal = readBoolAttribute(pParameter, "internal", false); //! @todo maybe type should be data type or value type or something string quantityORunit = readStringAttribute(pParameter, "quantity", readStringAttribute(pParameter, "unit", "")); string description = readStringAttribute(pParameter, "description", ""); // Here we use force=true to make sure system parameters load even if they do not evaluate //! @todo if system parameters are loaded in the correct order (top to bottom) they should evaluate, why don't they? - bool ok = pSystem->setOrAddSystemParameter(paramName.c_str(), val.c_str(), type.c_str(), description.c_str(), quantityORunit.c_str(), true); + bool ok = pSystem->setOrAddSystemParameter(paramName.c_str(), val.c_str(), type.c_str(), description.c_str(), quantityORunit.c_str(), internal, true); if(!ok) { pSystem->addErrorMessage(HString("Failed to load parameter: ")+(paramName+"="+val).c_str()); diff --git a/HopsanCore/src/Parameters.cpp b/HopsanCore/src/Parameters.cpp index 208fc106f7..8fd456dabf 100644 --- a/HopsanCore/src/Parameters.cpp +++ b/HopsanCore/src/Parameters.cpp @@ -63,7 +63,7 @@ using namespace std; //! @param [in] pDataPtr Only used by Components, system parameters don't use this, default: 0 //! @param [in] pParentParameters A pointer to the Parameters object that contains the Parameter ParameterEvaluator::ParameterEvaluator(const HString &rName, const HString &rValue, const HString &rDescription, const HString &rQuantity, const HString &rUnit, - const HString &rType, void* pDataPtr, ParameterEvaluatorHandler* pParameterEvalHandler) + const HString &rType, const bool internal, void* pDataPtr, ParameterEvaluatorHandler* pParameterEvalHandler) { mDepthCounter=0; mParameterName = rName; @@ -73,6 +73,7 @@ ParameterEvaluator::ParameterEvaluator(const HString &rName, const HString &rVal mQuantity = rQuantity; mUnit = rUnit; mTriggersReconfiguration = false; + mInternal = internal; mpData = pDataPtr; mpParameterEvaluatorHandler = pParameterEvalHandler; @@ -87,7 +88,7 @@ void* ParameterEvaluator::getDataPtr() return mpData; } -bool ParameterEvaluator::setParameter(const HString &rValue, const HString &rDescription, const HString &rQuantity, const HString &rUnit, const HString &rType, ParameterEvaluator **pNeedEvaluation, bool force) +bool ParameterEvaluator::setParameter(const HString &rValue, const HString &rDescription, const HString &rQuantity, const HString &rUnit, const HString &rType, ParameterEvaluator **pNeedEvaluation, bool internal, bool force) { bool success; HString oldValue = mParameterValue; @@ -95,6 +96,7 @@ bool ParameterEvaluator::setParameter(const HString &rValue, const HString &rDes HString oldUnit = mUnit; HString oldType = mType; HString oldQuantity = mQuantity; + bool oldInternal = mInternal; if(!rDescription.empty()) { mDescription = rDescription; @@ -111,6 +113,7 @@ bool ParameterEvaluator::setParameter(const HString &rValue, const HString &rDes { mType = rType; } + mInternal = internal; success = setParameterValue(rValue, pNeedEvaluation); if((force) && !(success)) { @@ -124,6 +127,7 @@ bool ParameterEvaluator::setParameter(const HString &rValue, const HString &rDes mQuantity = oldQuantity; mUnit = oldUnit; mType = oldType; + mInternal = oldInternal; } return success; } @@ -461,6 +465,11 @@ const std::vector &ParameterEvaluator::getConditions() const return mConditions; } +bool ParameterEvaluator::isInternal() const +{ + return mInternal; +} + void ParameterEvaluator::setTriggersReconfiguration() { mTriggersReconfiguration = true; @@ -548,7 +557,7 @@ ParameterEvaluatorHandler::~ParameterEvaluatorHandler() //! @param [in] force Should we force to add parameter even if it fails to evaluate //! @param [in] conditions Conditions for a conditional constant parameter //! @return true if success, otherwise false -bool ParameterEvaluatorHandler::addParameter(const HString &rName, const HString &rValue, const HString &rDescription, const HString &rQuantity, const HString &rUnit, const HString &rType, void* pData, bool force, std::vector conditions) +bool ParameterEvaluatorHandler::addParameter(const HString &rName, const HString &rValue, const HString &rDescription, const HString &rQuantity, const HString &rUnit, const HString &rType, void* pData, bool internal, bool force, std::vector conditions) { bool success = false; if (!rName.empty()) @@ -556,7 +565,7 @@ bool ParameterEvaluatorHandler::addParameter(const HString &rName, const HString if(!hasParameter(rName)) { //! @todo should make sure that parameter names do not have + - * / . or similar as first character - ParameterEvaluator* newParameter = new ParameterEvaluator(rName, rValue, rDescription, rQuantity, rUnit, rType, pData, this); + ParameterEvaluator* newParameter = new ParameterEvaluator(rName, rValue, rDescription, rQuantity, rUnit, rType, internal, pData, this); if(rType == "conditional") { newParameter->mConditions = conditions; @@ -688,9 +697,10 @@ const std::vector *ParameterEvaluatorHandler::getParameters bool ParameterEvaluatorHandler::setParameter(const HString &rName, const HString &rValue, const HString &rDescription, - const HString &rQuantity, const HString &rUnit, const HString &rType, const bool force) + const HString &rQuantity, const HString &rUnit, const HString &rType, const bool internal, const bool force) { bool success = false; + std::cout << "Setting hidden to " << internal << "\n"; // Try to find the parameter among the existing parameters for(size_t i=0; igetName()) )//&& (value != mParameters[i]->getName()) ) //By commenting this a parameter can be set to a systems parameter with same name as component parameter e.g. mass m = m (system parameter) related to issue #783 { ParameterEvaluator *needEvaluation=0; - success = mParameters[i]->setParameter(rValue, rDescription, rQuantity, rUnit, rType, &needEvaluation, force); //Sets the new value, if the parameter is of the type to need evaluation e.g. if it is a system parameter needEvaluation points to the parameter + success = mParameters[i]->setParameter(rValue, rDescription, rQuantity, rUnit, rType, &needEvaluation, internal, force); //Sets the new value, if the parameter is of the type to need evaluation e.g. if it is a system parameter needEvaluation points to the parameter if(needEvaluation) { if(mParametersNeedEvaluation.end() == find(mParametersNeedEvaluation.begin(), mParametersNeedEvaluation.end(), needEvaluation)) diff --git a/HopsanGUI/CoreAccess.cpp b/HopsanGUI/CoreAccess.cpp index dcedbc329b..1d8eb78da5 100644 --- a/HopsanGUI/CoreAccess.cpp +++ b/HopsanGUI/CoreAccess.cpp @@ -81,6 +81,7 @@ void copyParameterData(const hopsan::ParameterEvaluator *pCoreParam, CoreParamet { rGUIParam.mConditions.append(QString(pCoreParam->getConditions()[c].c_str())); } + rGUIParam.mInternal = pCoreParam->isInternal(); } @@ -1114,6 +1115,7 @@ bool CoreSystemAccess::setSystemParameter(const CoreParameterData &rParameter, b rParameter.mType.toStdString().c_str(), rParameter.mDescription.toStdString().c_str(), rParameter.mQuantity.toStdString().c_str(), + rParameter.mInternal, force); } else @@ -1124,6 +1126,7 @@ bool CoreSystemAccess::setSystemParameter(const CoreParameterData &rParameter, b rParameter.mType.toStdString().c_str(), rParameter.mDescription.toStdString().c_str(), rParameter.mQuantity.toStdString().c_str(), + rParameter.mInternal, force); } } diff --git a/HopsanGUI/CoreAccess.h b/HopsanGUI/CoreAccess.h index 75c6944268..079788db08 100644 --- a/HopsanGUI/CoreAccess.h +++ b/HopsanGUI/CoreAccess.h @@ -108,8 +108,8 @@ class CoreParameterData { public: CoreParameterData() {} - CoreParameterData(const QString name, const QString value, const QString type, const QString quantity="", const QString unit="", const QString desc="") - : mName(name), mValue(value), mType(type), mQuantity(quantity), mUnit(unit), mDescription(desc) {} + CoreParameterData(const QString name, const QString value, const QString type, const QString quantity="", const QString unit="", const QString desc="", const bool internal=false) + : mName(name), mValue(value), mType(type), mQuantity(quantity), mUnit(unit), mDescription(desc), mInternal(internal) {} bool hasBooleanValue() const; bool hasIntegerValue() const; @@ -119,6 +119,7 @@ class CoreParameterData QString mAlias; QString mValue; QString mType; + bool mInternal = false; QString mQuantity; QString mUnit; QString mDescription; diff --git a/HopsanGUI/GUIObjects/GUIComponent.cpp b/HopsanGUI/GUIObjects/GUIComponent.cpp index e5fae736d5..d40b3f6505 100644 --- a/HopsanGUI/GUIObjects/GUIComponent.cpp +++ b/HopsanGUI/GUIObjects/GUIComponent.cpp @@ -275,7 +275,7 @@ int Component::type() const QString Component::getHmfTagName() const { - return HMF_COMPONENTTAG; + return HMF_COMPONENT; } @@ -346,6 +346,7 @@ void Component::saveCoreDataToDomElement(QDomElement &rDomElement, SaveContentsE xmlParam.setAttribute(HMF_VALUETAG, paramDataVec[i].mValue); xmlParam.setAttribute(HMF_TYPE, paramDataVec[i].mType); xmlParam.setAttribute(HMF_UNIT, paramDataVec[i].mUnit); + xmlParam.setAttribute(HMF_INTERNAL, bool2str(paramDataVec[i].mInternal)); /*if(this->isParameterMappedToSystemParameter(*pit)) { diff --git a/HopsanGUI/GUIObjects/GUIContainerObject.cpp b/HopsanGUI/GUIObjects/GUIContainerObject.cpp index 55d16f6638..503cc58044 100644 --- a/HopsanGUI/GUIObjects/GUIContainerObject.cpp +++ b/HopsanGUI/GUIObjects/GUIContainerObject.cpp @@ -616,12 +616,12 @@ ModelObject* SystemObject::addModelObject(QString fullTypeName, QPointF position QFile file(pAppearanceData->getBasePath()+hmfFile); QDomDocument domDocument; - QDomElement hmfRoot = loadXMLDomDocument(file, domDocument, HMF_ROOTTAG); + QDomElement hmfRoot = loadXMLDomDocument(file, domDocument, hmf::root); if (!hmfRoot.isNull()) { //! @todo Check version numbers //! @todo check if we could load else give error message and don't attempt to load - QDomElement systemElement = hmfRoot.firstChildElement(HMF_SYSTEMTAG); + QDomElement systemElement = hmfRoot.firstChildElement(hmf::system); pObj->setModelFileInfo(file); //Remember info about the file from which the data was loaded QFileInfo fileInfo(file); pObj->setAppearanceDataBasePath(fileInfo.absolutePath()); @@ -1552,6 +1552,7 @@ void SystemObject::copySelected(CopyStack *xmlStack) xmlParameter.setAttribute(HMF_NAMETAG, systemParameterData.mName); xmlParameter.setAttribute(HMF_VALUETAG, systemParameterData.mValue); xmlParameter.setAttribute(HMF_TYPE, systemParameterData.mType); + xmlParameter.setAttribute(HMF_INTERNAL, systemParameterData.mInternal); if (!systemParameterData.mQuantity.isEmpty()) { xmlParameter.setAttribute(HMF_QUANTITY, systemParameterData.mQuantity); @@ -1665,11 +1666,11 @@ void SystemObject::paste(CopyStack *xmlStack) }; // Paste Components and Systems - pasteComponentOrSystem(HMF_COMPONENTTAG); - pasteComponentOrSystem(HMF_SYSTEMTAG); + pasteComponentOrSystem(hmf::component); + pasteComponentOrSystem(hmf::system); // Paste system ports - QDomElement systemPortElement = copyRoot->firstChildElement(HMF_SYSTEMPORTTAG); + QDomElement systemPortElement = copyRoot->firstChildElement(hmf::systemport); while (!systemPortElement.isNull()) { ModelObject* pObj = loadSystemPortObject(systemPortElement, this, Undo); if (pObj) { @@ -1683,7 +1684,7 @@ void SystemObject::paste(CopyStack *xmlStack) didPaste = true; mpUndoStack->registerMovedObject(prevPos, pObj->pos(), actualNameAfterLoad); } - systemPortElement = systemPortElement.nextSiblingElement(HMF_SYSTEMPORTTAG); + systemPortElement = systemPortElement.nextSiblingElement(hmf::systemport); } // Paste connectors @@ -1758,8 +1759,9 @@ void SystemObject::paste(CopyStack *xmlStack) QString type = parElement.attribute(HMF_TYPE); QString quantityORunit = parElement.attribute(HMF_QUANTITY, parElement.attribute(HMF_UNIT)); QString description = parElement.attribute(HMF_DESCRIPTIONTAG); + bool internal = parseAttributeBool(parElement, HMF_INTERNAL, false); - CoreParameterData parData = CoreParameterData(name, value, type, quantityORunit, "", description); + CoreParameterData parData = CoreParameterData(name, value, type, quantityORunit, "", description, internal); setOrAddParameter(parData); didPaste = true; } @@ -3631,7 +3633,7 @@ int SystemObject::type() const QString SystemObject::getHmfTagName() const { - return HMF_SYSTEMTAG; + return hmf::system; } void SystemObject::deleteInHopsanCore() @@ -3778,6 +3780,7 @@ void SystemObject::saveCoreDataToDomElement(QDomElement &rDomElement, SaveConten xmlParameter.setAttribute(HMF_NAMETAG, paramDataVector[i].mName); xmlParameter.setAttribute(HMF_VALUETAG, paramDataVector[i].mValue); xmlParameter.setAttribute(HMF_TYPE, paramDataVector[i].mType); + xmlParameter.setAttribute(HMF_INTERNAL, bool2str(paramDataVector[i].mInternal)); if (!paramDataVector[i].mQuantity.isEmpty()) { xmlParameter.setAttribute(HMF_QUANTITY, paramDataVector[i].mQuantity); @@ -3865,12 +3868,12 @@ void SystemObject::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) this->clearContents(); QDomDocument domDocument; - QDomElement hmfRoot = loadXMLDomDocument(file, domDocument, HMF_ROOTTAG); + QDomElement hmfRoot = loadXMLDomDocument(file, domDocument, hmf::root); if (!hmfRoot.isNull()) { //! @todo Check version numbers //! @todo check if we could load else give error message and don't attempt to load - QDomElement systemElement = hmfRoot.firstChildElement(HMF_SYSTEMTAG); + QDomElement systemElement = hmfRoot.firstChildElement(hmf::system); this->setModelFileInfo(file); //Remember info about the file from which the data was loaded QFileInfo fileInfo(file); this->setAppearanceDataBasePath(fileInfo.absolutePath()); @@ -4080,7 +4083,7 @@ void SystemObject::saveSensitivityAnalysisSettingsToDomElement(QDomElement &rDom for(int i = 0; i < mSensSettings.parameters.size(); ++i) { QDomElement XMLparameter = appendDomElement(XMLparameters, HMF_PARAMETERTAG); - appendDomTextNode(XMLparameter, HMF_COMPONENTTAG, mSensSettings.parameters.at(i).compName); + appendDomTextNode(XMLparameter, hmf::component, mSensSettings.parameters.at(i).compName); appendDomTextNode(XMLparameter, HMF_PARAMETERTAG, mSensSettings.parameters.at(i).parName); appendDomValueNode2(XMLparameter, HMF_MINMAX, mSensSettings.parameters.at(i).min, mSensSettings.parameters.at(i).max); appendDomValueNode(XMLparameter, HMF_AVERAGE, mSensSettings.parameters.at(i).aver); @@ -4092,7 +4095,7 @@ void SystemObject::saveSensitivityAnalysisSettingsToDomElement(QDomElement &rDom for(int i = 0; i < mSensSettings.variables.size(); ++i) { QDomElement XMLobjective = appendDomElement(XMLobjectives, HMF_PLOTVARIABLE); - appendDomTextNode(XMLobjective, HMF_COMPONENTTAG, mSensSettings.variables.at(i).compName); + appendDomTextNode(XMLobjective, hmf::component, mSensSettings.variables.at(i).compName); appendDomTextNode(XMLobjective, HMF_PORTTAG, mSensSettings.variables.at(i).portName); appendDomTextNode(XMLobjective, HMF_PLOTVARIABLE, mSensSettings.variables.at(i).varName); } @@ -4125,7 +4128,7 @@ void SystemObject::loadSensitivityAnalysisSettingsFromDomElement(QDomElement &rD while (!parameterElement.isNull()) { SensitivityAnalysisParameter par; - par.compName = parameterElement.firstChildElement(HMF_COMPONENTTAG).text(); + par.compName = parameterElement.firstChildElement(hmf::component).text(); par.parName = parameterElement.firstChildElement(HMF_PARAMETERTAG).text(); parseDomValueNode2(parameterElement.firstChildElement(HMF_MINMAX), par.min, par.max); par.aver = parseDomValueNode(parameterElement.firstChildElement(HMF_AVERAGE), 0); @@ -4144,7 +4147,7 @@ void SystemObject::loadSensitivityAnalysisSettingsFromDomElement(QDomElement &rD { SensitivityAnalysisVariable var; - var.compName = variableElement.firstChildElement(HMF_COMPONENTTAG).text(); + var.compName = variableElement.firstChildElement(hmf::component).text(); var.portName = variableElement.firstChildElement(HMF_PORTTAG).text(); var.varName = variableElement.firstChildElement(HMF_PLOTVARIABLE).text(); mSensSettings.variables.append(var); @@ -4176,7 +4179,7 @@ void SystemObject::saveOptimizationSettingsToDomElement(QDomElement &rDomElement for(int i = 0; i < mOptSettings.mParamters.size(); ++i) { QDomElement XMLparameter = appendDomElement(XMLparameters, HMF_PARAMETERTAG); - appendDomTextNode(XMLparameter, HMF_COMPONENTTAG, mOptSettings.mParamters.at(i).mComponentName); + appendDomTextNode(XMLparameter, hmf::component, mOptSettings.mParamters.at(i).mComponentName); appendDomTextNode(XMLparameter, HMF_PARAMETERTAG, mOptSettings.mParamters.at(i).mParameterName); appendDomValueNode2(XMLparameter, HMF_MINMAX, mOptSettings.mParamters.at(i).mMin, mOptSettings.mParamters.at(i).mMax); } @@ -4197,7 +4200,7 @@ void SystemObject::saveOptimizationSettingsToDomElement(QDomElement &rDomElement for(int j = 0; j < mOptSettings.mObjectives.at(i).mVariableInfo.size(); ++j) { QDomElement XMLObjectiveVariable = appendDomElement(XMLObjectiveVariables, HMF_PLOTVARIABLE); - appendDomTextNode(XMLObjectiveVariable, HMF_COMPONENTTAG, mOptSettings.mObjectives.at(i).mVariableInfo.at(j).at(0)); + appendDomTextNode(XMLObjectiveVariable, hmf::component, mOptSettings.mObjectives.at(i).mVariableInfo.at(j).at(0)); appendDomTextNode(XMLObjectiveVariable, HMF_PORTTAG, mOptSettings.mObjectives.at(i).mVariableInfo.at(j).at(1)); appendDomTextNode(XMLObjectiveVariable, HMF_PLOTVARIABLE, mOptSettings.mObjectives.at(i).mVariableInfo.at(j).at(2)); } @@ -4243,7 +4246,7 @@ void SystemObject::loadOptimizationSettingsFromDomElement(QDomElement &rDomEleme while (!parameterElement.isNull()) { OptParameter parameter; - parameter.mComponentName = parameterElement.firstChildElement(HMF_COMPONENTTAG).text(); + parameter.mComponentName = parameterElement.firstChildElement(hmf::component).text(); parameter.mParameterName = parameterElement.firstChildElement(HMF_PARAMETERTAG).text(); parseDomValueNode2(parameterElement.firstChildElement(HMF_MINMAX), parameter.mMin, parameter.mMax); mOptSettings.mParamters.append(parameter); @@ -4273,7 +4276,7 @@ void SystemObject::loadOptimizationSettingsFromDomElement(QDomElement &rDomEleme { QStringList variableInfo; - variableInfo.append(varElement.firstChildElement(HMF_COMPONENTTAG).text()); + variableInfo.append(varElement.firstChildElement(hmf::component).text()); variableInfo.append(varElement.firstChildElement(HMF_PORTTAG).text()); variableInfo.append(varElement.firstChildElement(HMF_PLOTVARIABLE).text()); @@ -4469,7 +4472,7 @@ void SystemObject::saveToDomElement(QDomElement &rDomElement, SaveContentsEnumT if (mLoadType=="EMBEDED" || mLoadType=="ROOT") { //Save subcomponents and subsystems - QDomElement xmlObjects = appendDomElement(xmlSubsystem, HMF_OBJECTS); + QDomElement xmlObjects = appendDomElement(xmlSubsystem, hmf::objects); ModelObjectMapT::iterator it; for(it = mModelObjectMap.begin(); it!=mModelObjectMap.end(); ++it) { @@ -4533,8 +4536,8 @@ void SystemObject::saveToDomElement(QDomElement &rDomElement, SaveContentsEnumT void SystemObject::loadFromDomElement(QDomElement domElement) { // Loop back up to root level to get version numbers - QString hmfFormatVersion = domElement.ownerDocument().firstChildElement(HMF_ROOTTAG).attribute(HMF_VERSIONTAG, "0"); - QString coreHmfVersion = domElement.ownerDocument().firstChildElement(HMF_ROOTTAG).attribute(HMF_HOPSANCOREVERSIONTAG, "0"); + QString hmfFormatVersion = domElement.ownerDocument().firstChildElement(hmf::root).attribute(HMF_VERSIONTAG, "0"); + QString coreHmfVersion = domElement.ownerDocument().firstChildElement(hmf::root).attribute(HMF_HOPSANCOREVERSIONTAG, "0"); // Check if the subsystem is external or internal, and load appropriately QString external_path = domElement.attribute(HMF_EXTERNALPATHTAG); @@ -4680,8 +4683,8 @@ void SystemObject::loadFromDomElement(QDomElement domElement) //2. Load all sub-components QList volunectorObjectPtrs; - QDomElement xmlSubObjects = domElement.firstChildElement(HMF_OBJECTS); - xmlSubObject = xmlSubObjects.firstChildElement(HMF_COMPONENTTAG); + QDomElement xmlSubObjects = domElement.firstChildElement(hmf::objects); + xmlSubObject = xmlSubObjects.firstChildElement(hmf::component); while (!xmlSubObject.isNull()) { updateHmfComponentProperties(xmlSubObject, hmfFormatVersion, coreHmfVersion); @@ -4719,7 +4722,7 @@ void SystemObject::loadFromDomElement(QDomElement domElement) volunectorObjectPtrs.append(pObj); } - xmlSubObject = xmlSubObject.nextSiblingElement(HMF_COMPONENTTAG); + xmlSubObject = xmlSubObject.nextSiblingElement(hmf::component); } //3. Load all text box widgets @@ -4739,19 +4742,19 @@ void SystemObject::loadFromDomElement(QDomElement domElement) } //5. Load all sub-systems - xmlSubObject = xmlSubObjects.firstChildElement(HMF_SYSTEMTAG); + xmlSubObject = xmlSubObjects.firstChildElement(hmf::system); while (!xmlSubObject.isNull()) { loadModelObject(xmlSubObject, this, NoUndo); - xmlSubObject = xmlSubObject.nextSiblingElement(HMF_SYSTEMTAG); + xmlSubObject = xmlSubObject.nextSiblingElement(hmf::system); } //6. Load all system ports - xmlSubObject = xmlSubObjects.firstChildElement(HMF_SYSTEMPORTTAG); + xmlSubObject = xmlSubObjects.firstChildElement(hmf::systemport); while (!xmlSubObject.isNull()) { loadSystemPortObject(xmlSubObject, this, NoUndo); - xmlSubObject = xmlSubObject.nextSiblingElement(HMF_SYSTEMPORTTAG); + xmlSubObject = xmlSubObject.nextSiblingElement(hmf::systemport); } //7. Load all connectors diff --git a/HopsanGUI/GUIObjects/GUIModelObject.cpp b/HopsanGUI/GUIObjects/GUIModelObject.cpp index 47cd88489f..250967b979 100644 --- a/HopsanGUI/GUIObjects/GUIModelObject.cpp +++ b/HopsanGUI/GUIObjects/GUIModelObject.cpp @@ -177,7 +177,7 @@ QStringList ModelObject::getSystemNameHieararchy() const QString ModelObject::getHmfTagName() const { - return HMF_OBJECTTAG; //!< @todo change this + return HMF_OBJECT; //!< @todo change this } diff --git a/HopsanGUI/UndoStack.cpp b/HopsanGUI/UndoStack.cpp index 7dd3c4285e..6845638bfe 100644 --- a/HopsanGUI/UndoStack.cpp +++ b/HopsanGUI/UndoStack.cpp @@ -144,7 +144,7 @@ void UndoStack::undoOneStep() didSomething = true; if(stuffElement.attribute("what") == UNDO_DELETEDOBJECT) { - QDomElement componentElement = stuffElement.firstChildElement(HMF_COMPONENTTAG); + QDomElement componentElement = stuffElement.firstChildElement(HMF_COMPONENT); ModelObject* pObj = loadModelObject(componentElement, mpParentSystemObject, NoUndo); //Load parameter values @@ -168,7 +168,7 @@ void UndoStack::undoOneStep() } else if(stuffElement.attribute("what") == UNDO_ADDEDOBJECT) { - QDomElement componentElement = stuffElement.firstChildElement(HMF_COMPONENTTAG); + QDomElement componentElement = stuffElement.firstChildElement(HMF_COMPONENT); addedObjectList.append(componentElement); } else if(stuffElement.attribute("what") == UNDO_ADDEDSYSTEMPORT) @@ -514,7 +514,7 @@ void UndoStack::redoOneStep() didSomething = true; if(stuffElement.attribute("what") == UNDO_DELETEDOBJECT) { - QDomElement componentElement = stuffElement.firstChildElement(HMF_COMPONENTTAG); + QDomElement componentElement = stuffElement.firstChildElement(HMF_COMPONENT); QString name = componentElement.attribute(HMF_NAMETAG); if(mpParentSystemObject->hasModelObject(name)) { mpParentSystemObject->deleteModelObject(name, NoUndo); @@ -548,7 +548,7 @@ void UndoStack::redoOneStep() } else if(stuffElement.attribute("what") == UNDO_ADDEDOBJECT) { - QDomElement componentElement = stuffElement.firstChildElement(HMF_COMPONENTTAG); + QDomElement componentElement = stuffElement.firstChildElement(HMF_COMPONENT); loadModelObject(componentElement, mpParentSystemObject, NoUndo); } else if(stuffElement.attribute("what") == UNDO_ADDEDSYSTEMPORT) diff --git a/HopsanGUI/Utilities/XMLUtilities.cpp b/HopsanGUI/Utilities/XMLUtilities.cpp index 3656dd37a3..d5ca72b1cb 100644 --- a/HopsanGUI/Utilities/XMLUtilities.cpp +++ b/HopsanGUI/Utilities/XMLUtilities.cpp @@ -631,7 +631,7 @@ void updateRenamedComponentType(QDomElement &rDomElement, const QString oldType, void updateRenamedComponentName(QDomElement &rDomElement, const QString oldName, const QString newName) { - if((rDomElement.tagName() == HMF_COMPONENTTAG) && rDomElement.attribute(HMF_NAMETAG) == oldName) + if((rDomElement.tagName() == HMF_COMPONENT) && rDomElement.attribute(HMF_NAMETAG) == oldName) { rDomElement.setAttribute(HMF_NAMETAG, newName); gpMessageHandler->addWarningMessage("Renamed component: "+oldName+" to "+newName); @@ -775,10 +775,10 @@ void updateHmfSystemProperties(QDomElement &systemElement, const QString hmfVers for (const auto& oldName : invalidNames) { QString newName = oldName+"_INVALID_NAME"; - QDomElement xmlComponent = systemElement.firstChildElement(HMF_OBJECTS).firstChildElement(HMF_COMPONENTTAG); + QDomElement xmlComponent = systemElement.firstChildElement(HMF_OBJECTS).firstChildElement(HMF_COMPONENT); while (!xmlComponent.isNull()) { updateRenamedComponentName(xmlComponent, oldName, newName); - xmlComponent = xmlComponent.nextSiblingElement(HMF_COMPONENTTAG); + xmlComponent = xmlComponent.nextSiblingElement(HMF_COMPONENT); } QDomElement xmlConnection = systemElement.firstChildElement(HMF_CONNECTIONS).firstChildElement(HMF_CONNECTORTAG); diff --git a/HopsanGUI/Utilities/XMLUtilities.h b/HopsanGUI/Utilities/XMLUtilities.h index 386f3b72e9..7cd448732c 100644 --- a/HopsanGUI/Utilities/XMLUtilities.h +++ b/HopsanGUI/Utilities/XMLUtilities.h @@ -114,9 +114,9 @@ void readFromSsv(const QString filePath, QList &rParameters); #define HMF_OBJECTS "objects" #define HMF_OBJECTTAG "object" //Non core Gui Object #define HMF_MODELOBJECT "modelobject" -#define HMF_COMPONENTTAG "component" +#define HMF_COMPONENT "component" #define HMF_SYSTEMTAG "system" -#define HMF_SYSTEMPORTTAG "systemport" +#define HMF_SYSTEMPORTTAGTAG "systemport" #define HMF_CONNECTIONS "connections" #define HMF_CONNECTORTAG "connect" #define HMF_PARAMETERTAG "parameter" @@ -142,6 +142,7 @@ void readFromSsv(const QString filePath, QList &rParameters); #define HMF_SUBTYPENAME "subtypename" #define HMF_CQSTYPE "cqstype" #define HMF_TYPE "type" +#define HMF_INTERNAL "internal" #define HMF_UNIT "unit" #define HMF_QUANTITY "quantity" #define HMF_CPPCODETAG "cppcode" diff --git a/HopsanGUI/Widgets/SystemParametersWidget.cpp b/HopsanGUI/Widgets/SystemParametersWidget.cpp index 2c8ee821a7..66dd28fa67 100644 --- a/HopsanGUI/Widgets/SystemParametersWidget.cpp +++ b/HopsanGUI/Widgets/SystemParametersWidget.cpp @@ -98,7 +98,7 @@ int SysParamTableModel::rowCount(const QModelIndex &parent) const int SysParamTableModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); - return 3; + return 4; } QVariant SysParamTableModel::data(const QModelIndex &index, int role) const @@ -122,6 +122,9 @@ QVariant SysParamTableModel::data(const QModelIndex &index, int role) const case 2: return mParameterData.at(index.row()).mType; break; + case 3: + return mParameterData.at(index.row()).mInternal; + break; } } @@ -191,6 +194,17 @@ bool SysParamTableModel::setData(const QModelIndex &index, const QVariant &value emit dataChanged(index, index); } break; + case 3: + data = mParameterData[index.row()]; + data.mInternal = value.toBool(); + qDebug() << "hidden = " << data.mInternal; + isOk = addOrSetParameter(data); + if (isOk) + { + mParameterData[index.row()] = data; + emit dataChanged(index, index); + } + break; } } return isOk; @@ -211,6 +225,8 @@ QVariant SysParamTableModel::headerData(int section, Qt::Orientation orientation return QString("Value"); case 2: return QString("Type"); + case 3: + return QString("Hidden"); } } else @@ -340,6 +356,9 @@ void SysParamTableModel::setContainer(SystemObject *pContainerObject) mParameterData.clear(); emit layoutChanged(); } + if(mParameterData.size() >= 2) { + qDebug() << "setContainer(): " << mParameterData[0].mInternal << ", " << mParameterData[1].mInternal; + } } diff --git a/HopsanGUI/loadFunctions.cpp b/HopsanGUI/loadFunctions.cpp index b420f3cde2..ec1120a716 100644 --- a/HopsanGUI/loadFunctions.cpp +++ b/HopsanGUI/loadFunctions.cpp @@ -533,6 +533,7 @@ void loadSystemParameter(QDomElement &rDomElement, bool doAdd, const QString hmf type = rDomElement.attribute(HMF_TYPENAME, type); //!< @deprecated load old typename QString quantityORunit = rDomElement.attribute(HMF_QUANTITY, rDomElement.attribute(HMF_UNIT)); QString description = rDomElement.attribute(HMF_DESCRIPTIONTAG); + bool internal = parseAttributeBool(rDomElement, HMF_INTERNAL, false); if( (hmfVersion <= "0.3") && type.isEmpty()) //Version check, types did not exist in 0.3 and bellow (everything was double) { @@ -540,7 +541,7 @@ void loadSystemParameter(QDomElement &rDomElement, bool doAdd, const QString hmf } // Core will take care of deciding about quantity or unit, leave unit empty - CoreParameterData paramData(name, value, type, quantityORunit, "", description); + CoreParameterData paramData(name, value, type, quantityORunit, "", description, internal); if (doAdd) { pContainer->setOrAddParameter(paramData, true); diff --git a/HopsanGenerator/src/GeneratorTypes.cpp b/HopsanGenerator/src/GeneratorTypes.cpp index 3874e912e6..30bba69a11 100644 --- a/HopsanGenerator/src/GeneratorTypes.cpp +++ b/HopsanGenerator/src/GeneratorTypes.cpp @@ -853,6 +853,9 @@ QString BuildFlags::platformString() const void getParameters(QList ¶meters, hopsan::ComponentSystem *pSystem) { for(hopsan::ParameterEvaluator *par : (*pSystem->getParametersVectorPtr())) { + if(par->isInternal()) { + continue; + } ParameterSpecification spec; if(par->getType() == "double") { spec.type = "Real"; From d3a20d8f7328543401406746a6ad0d44feb2acf6 Mon Sep 17 00:00:00 2001 From: Robert Braun Date: Tue, 13 Feb 2024 11:50:30 +0100 Subject: [PATCH 2/3] Replace XML tag defines with constexpr --- HopsanGUI/Configuration.cpp | 332 +++++----- HopsanGUI/Configuration.h | 221 ++++--- .../Dialogs/AnimatedIconPropertiesDialog.cpp | 2 +- .../Dialogs/ComponentPropertiesDialog3.cpp | 2 +- HopsanGUI/Dialogs/LicenseDialog.cpp | 4 +- HopsanGUI/Dialogs/OptimizationDialog.cpp | 8 +- .../Dialogs/OptimizationScriptWizard.cpp | 4 +- HopsanGUI/Dialogs/OptionsDialog.cpp | 152 ++--- .../Dialogs/SensitivityAnalysisDialog.cpp | 14 +- HopsanGUI/GUIConnector.cpp | 28 +- HopsanGUI/GUIObjects/GUIComponent.cpp | 28 +- HopsanGUI/GUIObjects/GUIContainerObject.cpp | 452 ++++++------- HopsanGUI/GUIObjects/GUIContainerPort.cpp | 2 +- HopsanGUI/GUIObjects/GUIModelObject.cpp | 70 +- .../GUIObjects/GUIModelObjectAppearance.cpp | 612 +++++++++--------- .../GUIObjects/GUIModelObjectAppearance.h | 8 +- HopsanGUI/GUIObjects/GUIWidgets.cpp | 110 ++-- HopsanGUI/GUIPort.cpp | 2 +- HopsanGUI/GraphicsView.cpp | 16 +- HopsanGUI/HcomHandler.cpp | 34 +- HopsanGUI/LibraryHandler.cpp | 107 +-- HopsanGUI/LogDataHandler2.cpp | 28 +- HopsanGUI/MainWindow.cpp | 6 +- HopsanGUI/ModelHandler.cpp | 9 +- HopsanGUI/OptimizationHandler.cpp | 26 +- HopsanGUI/PlotHandler.cpp | 4 +- HopsanGUI/PlotTab.cpp | 50 +- HopsanGUI/RemoteSimulationUtils.cpp | 8 +- HopsanGUI/SimulationThreadHandler.cpp | 20 +- HopsanGUI/UndoStack.cpp | 84 +-- HopsanGUI/Utilities/XMLUtilities.cpp | 110 ++-- HopsanGUI/Utilities/XMLUtilities.h | 342 +++++----- HopsanGUI/Widgets/AnimationWidget.cpp | 4 +- HopsanGUI/Widgets/DataExplorer.cpp | 8 +- HopsanGUI/Widgets/HcomWidget.cpp | 8 +- HopsanGUI/Widgets/MessageWidget.cpp | 8 +- HopsanGUI/Widgets/ModelWidget.cpp | 54 +- HopsanGUI/Widgets/TextEditorWidget.cpp | 2 +- HopsanGUI/Widgets/WelcomeWidget.cpp | 2 +- HopsanGUI/loadFunctions.cpp | 170 ++--- HopsanGUI/main.cpp | 2 +- 41 files changed, 1594 insertions(+), 1559 deletions(-) diff --git a/HopsanGUI/Configuration.cpp b/HopsanGUI/Configuration.cpp index 573690b953..3d5f453f37 100644 --- a/HopsanGUI/Configuration.cpp +++ b/HopsanGUI/Configuration.cpp @@ -142,11 +142,11 @@ void Configuration::saveToXml() { // Write to hopsanconfig.xml QDomDocument domDocument; - QDomElement configRoot = domDocument.createElement(CFG_HOPSANCONFIG); - configRoot.setAttribute(HMF_HOPSANGUIVERSIONTAG, HOPSANGUIVERSION); + QDomElement configRoot = domDocument.createElement(cfg::hopsanconfig); + configRoot.setAttribute(hmf::version::hopsangui, HOPSANGUIVERSION); domDocument.appendChild(configRoot); - QDomElement settings = appendDomElement(configRoot,CFG_SETTINGS); + QDomElement settings = appendDomElement(configRoot,cfg::settings); // Write string settings for(auto it=mStringSettings.begin(); it!=mStringSettings.end(); ++it) @@ -173,11 +173,11 @@ void Configuration::saveToXml() } // Write other settings - appendDomValueNode2(settings, CFG_PLOTGFXSIZE, mPlotGfxSize.width(), mPlotGfxSize.height()); - appendDomTextNode(settings, CFG_BACKGROUNDCOLOR, mBackgroundColor.name()); + appendDomValueNode2(settings, cfg::plotgfxsize, mPlotGfxSize.width(), mPlotGfxSize.height()); + appendDomTextNode(settings, cfg::backgroundcolor, mBackgroundColor.name()); // Write style - QDomElement style = appendDomElement(configRoot, HMF_STYLETAG); + QDomElement style = appendDomElement(configRoot, cfg::style); for(auto it1 = mPenStyles.begin(); it1 != mPenStyles.end(); ++it1) { for(auto it2 = it1.value().begin(); it2 != it1.value().end(); ++it2) @@ -190,64 +190,64 @@ void Configuration::saveToXml() if(it1.key() == BrokenConnectorStyle) type = "Broken"; if(it1.key() == UndefinedConnectorStyle) type = "Undefined"; - QDomElement tempElement = appendDomElement(style, CFG_PENSTYLE); - tempElement.setAttribute(CFG_TYPE, type); - tempElement.setAttribute(CFG_GFXTYPE, it2.key()); - tempElement.setAttribute(CFG_SITUATION, it3.key()); - tempElement.setAttribute(CFG_COLOR, it3.value().color().name()); - setQrealAttribute(tempElement, CFG_WIDTH, it3.value().widthF()); - tempElement.setAttribute(HMF_STYLETAG, it3.value().style()); - tempElement.setAttribute(CFG_CAPSTYLE, it3.value().capStyle()); + QDomElement tempElement = appendDomElement(style, cfg::penstyle); + tempElement.setAttribute(cfg::type, type); + tempElement.setAttribute(cfg::gfxtype, it2.key()); + tempElement.setAttribute(cfg::situation, it3.key()); + tempElement.setAttribute(cfg::color, it3.value().color().name()); + setQrealAttribute(tempElement, cfg::width, it3.value().widthF()); + tempElement.setAttribute(cfg::style, it3.value().style()); + tempElement.setAttribute(cfg::capstyle, it3.value().capStyle()); } } } - QDomElement libs = appendDomElement(configRoot, XML_LIBS); + QDomElement libs = appendDomElement(configRoot, cfg::libs); for(int i=0; i-1; --i) { if(mRecentModels.at(i) != "") - appendDomTextNode(models, XML_RECENTMODEL, mRecentModels.at(i)); + appendDomTextNode(models, cfg::models::recent, mRecentModels.at(i)); } for(int i = mRecentGeneratorModels.size()-1; i>-1; --i) { if(mRecentGeneratorModels.at(i) != "") - appendDomTextNode(models, XML_RECENTGENERATORMODEL, mRecentGeneratorModels.at(i)); + appendDomTextNode(models, cfg::models::recentgenerator, mRecentGeneratorModels.at(i)); } - QDomElement xmlUnitScales = appendDomElement(configRoot, CFG_UNITSETTINGS); + QDomElement xmlUnitScales = appendDomElement(configRoot, cfg::unitsettings); QMap::iterator qit; for(qit = mUnitScales.begin(); qit != mUnitScales.end(); ++qit) { - QDomElement xmlQuantity = appendDomElement(xmlUnitScales, CFG_QUANTITY); - xmlQuantity.setAttribute(HMF_NAMETAG, qit.key()); + QDomElement xmlQuantity = appendDomElement(xmlUnitScales, cfg::quantity); + xmlQuantity.setAttribute(hmf::name, qit.key()); QString baseunit = qit.value().baseunit; if (!baseunit.isEmpty()) { - xmlQuantity.setAttribute(CFG_BASEUNIT, baseunit); + xmlQuantity.setAttribute(cfg::baseunit, baseunit); } xmlQuantity.setAttribute(cfg::siunits::kg, qit.value().kg); xmlQuantity.setAttribute(cfg::siunits::m, qit.value().m); @@ -262,7 +262,7 @@ void Configuration::saveToXml() QMap::iterator itdu = mSelectedDefaultUnits.find(qit.key()); if (itdu!=mSelectedDefaultUnits.end()) { - xmlQuantity.setAttribute(CFG_DEFAULTDISPALYUNIT, itdu.value()); + xmlQuantity.setAttribute(cfg::defaultdisplayunits, itdu.value()); } // Save all custom (non built in) unit conversions @@ -273,19 +273,19 @@ void Configuration::saveToXml() if ( (cuit.key() != baseunit) && !qit.value().builtInUnitconversions.contains(cuit.key()) ) { - QDomElement xmlUS = appendDomElement(xmlQuantity, CFG_UNIT); - xmlUS.setAttribute(CFG_NAME, cuit.key()); - xmlUS.setAttribute(CFG_SCALE, cuit.value().mScale); - xmlUS.setAttribute(CFG_OFFSET, cuit.value().mOffset); + QDomElement xmlUS = appendDomElement(xmlQuantity, cfg::unit); + xmlUS.setAttribute(cfg::name, cuit.key()); + xmlUS.setAttribute(cfg::scale, cuit.value().mScale); + xmlUS.setAttribute(cfg::offset, cuit.value().mOffset); } } } - QDomElement hcom = appendDomElement(configRoot, CFG_HCOM); - appendDomTextNode(hcom, CFG_PWD, mHcomWorkingDirectory); + QDomElement hcom = appendDomElement(configRoot, cfg::hcom); + appendDomTextNode(hcom, cfg::pwd, mHcomWorkingDirectory); for(int i=0; itr("Hopsan"), "The file is not an Hopsan Configuration File. Incorrect hmf root tag name: " @@ -367,38 +367,38 @@ void Configuration::loadFromXml() verifyConfigurationCompatibility(configRoot); //Check version compatibility //Load user settings - QDomElement settingsElement = configRoot.firstChildElement(HMF_SETTINGS); + QDomElement settingsElement = configRoot.firstChildElement(hmf::sensitivityanalysis::settings); loadUserSettings(settingsElement); //Load style settings - QDomElement styleElement = configRoot.firstChildElement(HMF_STYLETAG); + QDomElement styleElement = configRoot.firstChildElement(cfg::style); loadStyleSettings(styleElement); //Load library settings - QDomElement libsElement = configRoot.firstChildElement(XML_LIBS); + QDomElement libsElement = configRoot.firstChildElement(cfg::libs); loadLibrarySettings(libsElement); //Load model settings - QDomElement modelsElement = configRoot.firstChildElement(XML_MODELS); + QDomElement modelsElement = configRoot.firstChildElement(cfg::models::root); loadModelSettings(modelsElement); //Load unit settings - QDomElement unitscalesElement = configRoot.firstChildElement(CFG_UNITSETTINGS); + QDomElement unitscalesElement = configRoot.firstChildElement(cfg::unitsettings); loadUnitSettings(unitscalesElement, false); // ---------------------------------------------- used for backwards compatibility can be removed after 0.7.x is complete //! @todo deprecated - QDomElement unitsElement = configRoot.firstChildElement(CFG_UNITS); + QDomElement unitsElement = configRoot.firstChildElement(cfg::units); QDomElement xmlDefaultUnit = unitsElement.firstChildElement("defaultunit"); while (!xmlDefaultUnit.isNull()) { - mSelectedDefaultUnits.insert(xmlDefaultUnit.attribute(HMF_NAMETAG), xmlDefaultUnit.attribute(CFG_UNIT)); + mSelectedDefaultUnits.insert(xmlDefaultUnit.attribute(hmf::name), xmlDefaultUnit.attribute(cfg::unit)); xmlDefaultUnit = xmlDefaultUnit.nextSiblingElement("defaultunit"); } // ---------------------------------------------- //Load settings to HcomDockWidget in MainWindow - QDomElement hcomElement = configRoot.firstChildElement(CFG_HCOM); + QDomElement hcomElement = configRoot.firstChildElement(cfg::hcom); loadScriptSettings(hcomElement); } } @@ -446,15 +446,15 @@ void Configuration::loadDefaultsFromXml() verifyConfigurationCompatibility(configRoot); // Load default user settings - QDomElement settingsElement = configRoot.firstChildElement(CFG_SETTINGS); + QDomElement settingsElement = configRoot.firstChildElement(cfg::settings); loadUserSettings(settingsElement); // Load default GUI style - QDomElement styleElement = configRoot.firstChildElement(HMF_STYLETAG); + QDomElement styleElement = configRoot.firstChildElement(cfg::style); loadStyleSettings(styleElement); // Load default units - QDomElement unitscalesElement = configRoot.firstChildElement(CFG_UNITSETTINGS); + QDomElement unitscalesElement = configRoot.firstChildElement(cfg::unitsettings); loadUnitSettings(unitscalesElement, true); } } @@ -576,16 +576,16 @@ void Configuration::loadUserSettings(QDomElement &rDomElement) } // Load other settings - if(!rDomElement.firstChildElement(CFG_PLOTGFXSIZE).isNull()) + if(!rDomElement.firstChildElement(cfg::plotgfxsize).isNull()) { double width = mPlotGfxSize.width(); double height = mPlotGfxSize.height(); - parseDomValueNode2(rDomElement.firstChildElement(CFG_PLOTGFXSIZE), width, height); + parseDomValueNode2(rDomElement.firstChildElement(cfg::plotgfxsize), width, height); mPlotGfxSize.setWidth(width); mPlotGfxSize.setHeight(height); } - mBackgroundColor.setNamedColor(parseDomStringNode(rDomElement.firstChildElement(CFG_BACKGROUNDCOLOR), mBackgroundColor.name())); + mBackgroundColor.setNamedColor(parseDomStringNode(rDomElement.firstChildElement(cfg::backgroundcolor), mBackgroundColor.name())); refreshQuickAccessVariables(); } @@ -595,16 +595,16 @@ void Configuration::loadUserSettings(QDomElement &rDomElement) //! @brief Utility function that loads style settings from dom element void Configuration::loadStyleSettings(QDomElement &rDomElement) { - QDomElement penElement = rDomElement.firstChildElement(CFG_PENSTYLE); + QDomElement penElement = rDomElement.firstChildElement(cfg::penstyle); while(!penElement.isNull()) { - QString type = penElement.attribute(CFG_TYPE); - QString gfxType = penElement.attribute(CFG_GFXTYPE); - QString situation = penElement.attribute(CFG_SITUATION); - QString color = penElement.attribute(CFG_COLOR); - double width = penElement.attribute(CFG_WIDTH).toDouble(); - Qt::PenStyle penstyle = Qt::PenStyle(penElement.attribute(HMF_STYLETAG).toInt()); - Qt::PenCapStyle capStyle = Qt::PenCapStyle(penElement.attribute(CFG_CAPSTYLE).toInt()); + QString type = penElement.attribute(cfg::type); + QString gfxType = penElement.attribute(cfg::gfxtype); + QString situation = penElement.attribute(cfg::situation); + QString color = penElement.attribute(cfg::color); + double width = penElement.attribute(cfg::width).toDouble(); + Qt::PenStyle penstyle = Qt::PenStyle(penElement.attribute(cfg::style).toInt()); + Qt::PenCapStyle capStyle = Qt::PenCapStyle(penElement.attribute(cfg::capstyle).toInt()); QPen pen = QPen(QColor(color), width, penstyle, capStyle); ConnectorStyleEnumT style; @@ -625,7 +625,7 @@ void Configuration::loadStyleSettings(QDomElement &rDomElement) } mPenStyles.find(style).value().find(gfxType).value().insert(situation, pen); - penElement = penElement.nextSiblingElement(CFG_PENSTYLE); + penElement = penElement.nextSiblingElement(cfg::penstyle); } QDomElement paletteElement = rDomElement.firstChildElement("palette"); if(!paletteElement.isNull()) @@ -670,11 +670,11 @@ void Configuration::loadStyleSettings(QDomElement &rDomElement) //! @brief Utility function that loads unit scales from xml void Configuration::loadUnitSettings(QDomElement &rDomElement, bool tagAsBuiltIn) { - QDomElement xmlQuantity = rDomElement.firstChildElement(CFG_QUANTITY); + QDomElement xmlQuantity = rDomElement.firstChildElement(cfg::quantity); while (!xmlQuantity.isNull()) { - QString quantity = xmlQuantity.attribute(HMF_NAMETAG); - QString baseunit = xmlQuantity.attribute(CFG_BASEUNIT); + QString quantity = xmlQuantity.attribute(hmf::name); + QString baseunit = xmlQuantity.attribute(cfg::baseunit); int kg = parseAttributeInt(xmlQuantity, cfg::siunits::kg, 0); int m = parseAttributeInt(xmlQuantity, cfg::siunits::m, 0); int s = parseAttributeInt(xmlQuantity, cfg::siunits::s, 0); @@ -683,7 +683,7 @@ void Configuration::loadUnitSettings(QDomElement &rDomElement, bool tagAsBuiltIn int mol = parseAttributeInt(xmlQuantity, cfg::siunits::mol, 0); int cd = parseAttributeInt(xmlQuantity, cfg::siunits::cd, 0); int rad = parseAttributeInt(xmlQuantity, cfg::siunits::rad, 0); - QString deafdisplayunit = xmlQuantity.attribute(CFG_DEFAULTDISPALYUNIT, baseunit); + QString deafdisplayunit = xmlQuantity.attribute(cfg::defaultdisplayunits, baseunit); if (!deafdisplayunit.isEmpty()) { mSelectedDefaultUnits.insert(quantity, deafdisplayunit); @@ -714,17 +714,17 @@ void Configuration::loadUnitSettings(QDomElement &rDomElement, bool tagAsBuiltIn } } - QDomElement xmlUnitscale = xmlQuantity.firstChildElement(CFG_UNIT); + QDomElement xmlUnitscale = xmlQuantity.firstChildElement(cfg::unit); while (!xmlUnitscale.isNull()) { - QString unitname = xmlUnitscale.attribute(CFG_NAME); - QString fromBaseToUnitExpr = xmlUnitscale.attribute(CFG_FROMBASEEXPR); - QString toBaseUnitFromUnitExpr = xmlUnitscale.attribute(CFG_TOBBASEEXPR); + QString unitname = xmlUnitscale.attribute(cfg::name); + QString fromBaseToUnitExpr = xmlUnitscale.attribute(cfg::frombaseexpr); + QString toBaseUnitFromUnitExpr = xmlUnitscale.attribute(cfg::tobaseexpr); // prevent overwriting existing built in unit conversions if (!qit.value().builtInUnitconversions.contains(unitname)) { - QString scale = xmlUnitscale.attribute(CFG_SCALE); - QString offset = xmlUnitscale.attribute(CFG_OFFSET); + QString scale = xmlUnitscale.attribute(cfg::scale); + QString offset = xmlUnitscale.attribute(cfg::offset); // If scale or offset would be empty here, then result of evaluation would be "pi" if (!scale.isEmpty()) { @@ -745,10 +745,10 @@ void Configuration::loadUnitSettings(QDomElement &rDomElement, bool tagAsBuiltIn qit.value().builtInUnitconversions.append(unitname); } } - xmlUnitscale = xmlUnitscale.nextSiblingElement(CFG_UNIT); + xmlUnitscale = xmlUnitscale.nextSiblingElement(cfg::unit); } - xmlQuantity = xmlQuantity.nextSiblingElement(CFG_QUANTITY); + xmlQuantity = xmlQuantity.nextSiblingElement(cfg::quantity); } } @@ -756,16 +756,16 @@ void Configuration::loadUnitSettings(QDomElement &rDomElement, bool tagAsBuiltIn //! @brief Utility function that loads library settings void Configuration::loadLibrarySettings(QDomElement &rDomElement) { - QDomElement userLibElement = rDomElement.firstChildElement(XML_USERLIB); + QDomElement userLibElement = rDomElement.firstChildElement(cfg::userlib); while (!userLibElement.isNull()) { mUserLibs.append(QFileInfo(userLibElement.text())); - QString typeStr = userLibElement.attribute(XML_LIBTYPE); - if(typeStr == XML_LIBTYPE_EXTERNAL) + QString typeStr = userLibElement.attribute(cfg::libtype::root); + if(typeStr == cfg::libtype::external) { mUserLibTypes.append(ExternalLib); } - else if(typeStr == XML_LIBTYPE_FMU) + else if(typeStr == cfg::libtype::fmu) { mUserLibTypes.append(FmuLib); } @@ -773,7 +773,7 @@ void Configuration::loadLibrarySettings(QDomElement &rDomElement) { mUserLibTypes.append(InternalLib); } - userLibElement = userLibElement.nextSiblingElement((XML_USERLIB)); + userLibElement = userLibElement.nextSiblingElement((cfg::userlib)); } } @@ -781,23 +781,23 @@ void Configuration::loadLibrarySettings(QDomElement &rDomElement) //! @brief Utility function that loads model settings void Configuration::loadModelSettings(QDomElement &rDomElement) { - QDomElement lastSessionElement = rDomElement.firstChildElement(XML_LASTSESSIONMODEL); + QDomElement lastSessionElement = rDomElement.firstChildElement(cfg::models::lastsession); while (!lastSessionElement.isNull()) { mLastSessionModels.prepend(lastSessionElement.text()); - lastSessionElement = lastSessionElement.nextSiblingElement(XML_LASTSESSIONMODEL); + lastSessionElement = lastSessionElement.nextSiblingElement(cfg::models::lastsession); } - QDomElement recentModelElement = rDomElement.firstChildElement(XML_RECENTMODEL); + QDomElement recentModelElement = rDomElement.firstChildElement(cfg::models::recent); while (!recentModelElement.isNull()) { mRecentModels.prepend(recentModelElement.text()); - recentModelElement = recentModelElement.nextSiblingElement(XML_RECENTMODEL); + recentModelElement = recentModelElement.nextSiblingElement(cfg::models::recent); } - QDomElement recentGeneratorModelElement = rDomElement.firstChildElement(XML_RECENTGENERATORMODEL); + QDomElement recentGeneratorModelElement = rDomElement.firstChildElement(cfg::models::recentgenerator); while (!recentGeneratorModelElement.isNull()) { mRecentGeneratorModels.prepend(recentGeneratorModelElement.text()); - recentGeneratorModelElement = recentGeneratorModelElement.nextSiblingElement(XML_RECENTGENERATORMODEL); + recentGeneratorModelElement = recentGeneratorModelElement.nextSiblingElement(cfg::models::recentgenerator); } } @@ -807,30 +807,30 @@ void Configuration::loadScriptSettings(QDomElement &rHcomElement) { if(!rHcomElement.isNull()) { - QDomElement pwdElement = rHcomElement.firstChildElement(CFG_PWD); + QDomElement pwdElement = rHcomElement.firstChildElement(cfg::pwd); if(!pwdElement.isNull()) { mHcomWorkingDirectory = pwdElement.text(); } - QDomElement commandElement = rHcomElement.firstChildElement(CFG_COMMAND); + QDomElement commandElement = rHcomElement.firstChildElement(cfg::command); while(!commandElement.isNull()) { mTerminalHistory.append(commandElement.text()); - commandElement = commandElement.nextSiblingElement(CFG_COMMAND); + commandElement = commandElement.nextSiblingElement(cfg::command); } } } void Configuration::refreshQuickAccessVariables() { - mInvertWheel = getBoolSetting(CFG_INVERTWHEEL); - mShowPopupHelp = getBoolSetting(CFG_SHOWPOPUPHELP); - mCacheLogData = getBoolSetting(CFG_CACHELOGDATA); - mUseMulticore = getBoolSetting(CFG_MULTICORE); - mProgressBarStep = getIntegerSetting(CFG_PROGRESSBARSTEP); - mSnapping = getBoolSetting(CFG_SNAPPING); - mGenerationLimit = getIntegerSetting(CFG_GENERATIONLIMIT); - mZoomStep = getDoubleSetting(CFG_ZOOMSTEP); + mInvertWheel = getBoolSetting(cfg::invertwheel); + mShowPopupHelp = getBoolSetting(cfg::showpopuphelp); + mCacheLogData = getBoolSetting(cfg::cachelogdata); + mUseMulticore = getBoolSetting(cfg::multicore); + mProgressBarStep = getIntegerSetting(cfg::progressbarstep); + mSnapping = getBoolSetting(cfg::snapping); + mGenerationLimit = getIntegerSetting(cfg::generationlimit); + mZoomStep = getDoubleSetting(cfg::zoomstep); } @@ -1080,7 +1080,7 @@ QPen Configuration::getPen(ConnectorStyleEnumT style, GraphicsTypeEnumT gfxType, QPalette Configuration::getPalette() const { - if(getBoolSetting(CFG_NATIVESTYLESHEET)) + if(getBoolSetting(cfg::nativestylesheet)) { QMainWindow *dummy = new QMainWindow(); QPalette dummyPalette = dummy->palette(); @@ -1106,7 +1106,7 @@ QFont Configuration::getFont() const //! @brief Returns the current style sheet QString Configuration::getStyleSheet() const { - if(getBoolSetting(CFG_NATIVESTYLESHEET)) + if(getBoolSetting(cfg::nativestylesheet)) return QString(); else return mStyleSheet; @@ -1290,87 +1290,87 @@ void Configuration::setHcomWorkingDirectory(QString value) void Configuration::registerSettings() { // String settings - mStringSettings.insert(CFG_REMOTEHOPSANADDRESS, ""); - mStringSettings.insert(CFG_REMOTEHOPSANADDRESSSERVERADDRESS, ""); - mStringSettings.insert(CFG_REMOTEHOPSANUSERIDENTIFICATION, ""); - mStringSettings.insert(CFG_PARAMETEREXPORTDIR, ""); - mStringSettings.insert(CFG_PARAMETERIMPORTDIR, ""); - mStringSettings.insert(CFG_LOADMODELDIR, gpDesktopHandler->getModelsPath()); - mStringSettings.insert(CFG_MODELGFXDIR, gpDesktopHandler->getDocumentsPath()); - mStringSettings.insert(CFG_PLOTDATADIR, gpDesktopHandler->getDocumentsPath()); - mStringSettings.insert(CFG_PLOTGFXDIR, gpDesktopHandler->getDocumentsPath()); - mStringSettings.insert(CFG_SIMULINKEXPORTDIR, gpDesktopHandler->getDocumentsPath()); - mStringSettings.insert(CFG_SUBSYSTEMDIR, gpDesktopHandler->getModelsPath()); - mStringSettings.insert(CFG_EXTERNALLIBDIR, gpDesktopHandler->getDocumentsPath()); - mStringSettings.insert(CFG_SCRIPTDIR, gpDesktopHandler->getScriptsPath()); - mStringSettings.insert(CFG_PLOTWINDOWDIR, gpDesktopHandler->getDocumentsPath()); - mStringSettings.insert(CFG_FMUIMPORTDIR, gpDesktopHandler->getDocumentsPath()); - mStringSettings.insert(CFG_FMUEXPORTDIR, gpDesktopHandler->getDocumentsPath()); - mStringSettings.insert(CFG_EXEEXPORTDIR, gpDesktopHandler->getDocumentsPath()); - mStringSettings.insert(CFG_LABVIEWEXPORTDIR, gpDesktopHandler->getDocumentsPath()); - mStringSettings.insert(CFG_CUSTOMTEMPPATH, ""); - mStringSettings.insert(CFG_GCC64DIR, ""); - mStringSettings.insert(CFG_GCC32DIR, ""); + mStringSettings.insert(cfg::remotehopsanaddress, ""); + mStringSettings.insert(cfg::remotehopsanaddresserveraddress, ""); + mStringSettings.insert(cfg::remotehopsanuseridentification, ""); + mStringSettings.insert(cfg::dir::parameterexport, ""); + mStringSettings.insert(cfg::dir::parameterimport, ""); + mStringSettings.insert(cfg::dir::loadmodel, gpDesktopHandler->getModelsPath()); + mStringSettings.insert(cfg::dir::modelgfx, gpDesktopHandler->getDocumentsPath()); + mStringSettings.insert(cfg::dir::plotdata, gpDesktopHandler->getDocumentsPath()); + mStringSettings.insert(cfg::dir::plotgfx, gpDesktopHandler->getDocumentsPath()); + mStringSettings.insert(cfg::dir::simulinkexport, gpDesktopHandler->getDocumentsPath()); + mStringSettings.insert(cfg::dir::subsystem, gpDesktopHandler->getModelsPath()); + mStringSettings.insert(cfg::dir::externallib, gpDesktopHandler->getDocumentsPath()); + mStringSettings.insert(cfg::dir::script, gpDesktopHandler->getScriptsPath()); + mStringSettings.insert(cfg::dir::plotwindow, gpDesktopHandler->getDocumentsPath()); + mStringSettings.insert(cfg::dir::fmuimport, gpDesktopHandler->getDocumentsPath()); + mStringSettings.insert(cfg::dir::fmuexport, gpDesktopHandler->getDocumentsPath()); + mStringSettings.insert(cfg::dir::exeexport, gpDesktopHandler->getDocumentsPath()); + mStringSettings.insert(cfg::dir::labviewexport, gpDesktopHandler->getDocumentsPath()); + mStringSettings.insert(cfg::dir::customtemppath, ""); + mStringSettings.insert(cfg::dir::gcc64, ""); + mStringSettings.insert(cfg::dir::gcc32, ""); #ifndef _WIN32 #ifdef HOPSANCOMPILED64BIT - mStringSettings.insert(CFG_GCC64DIR, "/usr/bin"); + mStringSettings.insert(cfg::GCC64DIR, "/usr/bin"); #else - mStringSettings.insert(CFG_GCC32DIR, "/usr/bin"); + mStringSettings.insert(cfg::GCC32DIR, "/usr/bin"); #endif //! @todo OSX ? #endif - mStringSettings.insert(CFG_PLOTGFXIMAGEFORMAT, "png"); - mStringSettings.insert(CFG_PLOTGFXDIMENSIONSUNIT, "px"); + mStringSettings.insert(cfg::plotgfximageformat, "png"); + mStringSettings.insert(cfg::plotgfxdimensionunit, "px"); mStringSettings.insert(cfg::paths::corelogfile, ""); // Bool settings - mBoolSettings.insert(CFG_USEREMOTEADDRESSSERVER, false); - mBoolSettings.insert(CFG_USEREMOTEOPTIMIZATION, false); - mBoolSettings.insert(CFG_PLOTWINDOWSONTOP, true); - mBoolSettings.insert(CFG_PLOTGFXUSESCREENSIZE, false); - mBoolSettings.insert(CFG_PLOTGFXKEEPASPECT, true); - mBoolSettings.insert(CFG_AUTOLIMITGENERATIONS, false); - mBoolSettings.insert(CFG_CACHELOGDATA, true); - mBoolSettings.insert(CFG_SHOWHIDDENNODEDATAVARIABLES, false); - mBoolSettings.insert(CFG_AUTOBACKUP, true); - mBoolSettings.insert(CFG_GROUPMESSAGESBYTAG, true); - mBoolSettings.insert(CFG_GROUPMESSAGESBYTAG, true); - mBoolSettings.insert(CFG_TOGGLENAMESBUTTONCHECKED, true); - mBoolSettings.insert(CFG_TOGGLEPORTSBUTTONCHECKED, true); - mBoolSettings.insert(CFG_SNAPPING, true); - mBoolSettings.insert(CFG_INVERTWHEEL, false); - mBoolSettings.insert(CFG_ANTIALIASING, true); + mBoolSettings.insert(cfg::useremoteaddresserver, false); + mBoolSettings.insert(cfg::useremoteoptimization, false); + mBoolSettings.insert(cfg::plotwindowsontop, true); + mBoolSettings.insert(cfg::plotgfxusescreensize, false); + mBoolSettings.insert(cfg::plotgfxkeepaspect, true); + mBoolSettings.insert(cfg::autolimitgenerations, false); + mBoolSettings.insert(cfg::cachelogdata, true); + mBoolSettings.insert(cfg::showhiddennodedatavariables, false); + mBoolSettings.insert(cfg::autobackup, true); + mBoolSettings.insert(cfg::groupmessagesbytag, true); + mBoolSettings.insert(cfg::groupmessagesbytag, true); + mBoolSettings.insert(cfg::togglenamesbuttonchecked, true); + mBoolSettings.insert(cfg::toggleportsbuttonchecked, true); + mBoolSettings.insert(cfg::snapping, true); + mBoolSettings.insert(cfg::invertwheel, false); + mBoolSettings.insert(cfg::antialiasing, true); #if defined(_WIN32) - mBoolSettings.insert(CFG_NATIVESTYLESHEET, false); + mBoolSettings.insert(cfg::nativestylesheet, false); #else - mBoolSettings.insert(CFG_NATIVESTYLESHEET, true); + mBoolSettings.insert(cfg::NATIVESTYLESHEET, true); #endif - mBoolSettings.insert(CFG_SHOWPOPUPHELP, true); - mBoolSettings.insert(CFG_MULTICORE, false); - mBoolSettings.insert(CFG_PROGRESSBAR, true); - mBoolSettings.insert(CFG_SETPWDTOMWD, false); - mBoolSettings.insert(CFG_SHOWLICENSEONSTARTUP, true); - mBoolSettings.insert(CFG_CHECKFORDEVELOPMENTUPDATES, false); - mBoolSettings.insert(CFG_LOGDURINGSIMULATION, false); + mBoolSettings.insert(cfg::showpopuphelp, true); + mBoolSettings.insert(cfg::multicore, false); + mBoolSettings.insert(cfg::progressbar, true); + mBoolSettings.insert(cfg::setpwdtomwd, false); + mBoolSettings.insert(cfg::showlicenseonstartup, true); + mBoolSettings.insert(cfg::checkfordevelopmentupdates, false); + mBoolSettings.insert(cfg::logduringsimulation, false); #ifdef _WIN32 - mBoolSettings.insert(CFG_PREFERINCLUDEDCOMPILER, true); + mBoolSettings.insert(cfg::preferincludedcompiler, true); #else - mBoolSettings.insert(CFG_PREFERINCLUDEDCOMPILER, false); + mBoolSettings.insert(cfg::PREFERINCLUDEDCOMPILER, false); #endif // Integer settings - mIntegerSettings.insert(CFG_LIBRARYSTYLE, 0); - mIntegerSettings.insert(CFG_PROGRESSBARSTEP, 100); - mIntegerSettings.insert(CFG_NUMBEROFTHREADS, 0); - mIntegerSettings.insert(CFG_GENERATIONLIMIT, 100); - mIntegerSettings.insert(CFG_PLOEXPORTVERSION, 1); - mIntegerSettings.insert(CFG_REMOTESHORTTIMEOUT, 5); - mIntegerSettings.insert(CFG_REMOTELONGTIMEOUT, 30); - mIntegerSettings.insert(CFG_LOGSTEPS, 100); + mIntegerSettings.insert(cfg::librarystyle, 0); + mIntegerSettings.insert(cfg::progressbarstep, 100); + mIntegerSettings.insert(cfg::numberofthreads, 0); + mIntegerSettings.insert(cfg::generationlimit, 100); + mIntegerSettings.insert(cfg::ploexportversion, 1); + mIntegerSettings.insert(cfg::remoteshorttimeout, 5); + mIntegerSettings.insert(cfg::remotelongtimeout, 30); + mIntegerSettings.insert(cfg::logsteps, 100); // Double settings - mDoubleSettings.insert(CFG_PLOTGFXDPI, 96.0); - mDoubleSettings.insert(CFG_ZOOMSTEP, 15.0); + mDoubleSettings.insert(cfg::plotgfxdpi, 96.0); + mDoubleSettings.insert(cfg::zoomstep, 15.0); } void Configuration::setParallelAlgorithm(int value) @@ -1380,7 +1380,7 @@ void Configuration::setParallelAlgorithm(int value) QString Configuration::getGCCPath() const { - if (getBoolSetting(CFG_PREFERINCLUDEDCOMPILER)) + if (getBoolSetting(cfg::preferincludedcompiler)) { QString compilerpath = gpDesktopHandler->getIncludedCompilerPath(); if (!compilerpath.isEmpty()) @@ -1390,17 +1390,17 @@ QString Configuration::getGCCPath() const } #ifdef HOPSANCOMPILED64BIT - return getStringSetting(CFG_GCC64DIR); + return getStringSetting(cfg::dir::gcc64); #else - return getStringSetting(CFG_GCC32DIR); + return getStringSetting(cfg::GCC32DIR); #endif } void Configuration::refreshIfDesktopPath(const QString &cfgKey) { - if (cfgKey == CFG_CUSTOMTEMPPATH) + if (cfgKey == cfg::dir::customtemppath) { - gpDesktopHandler->setCustomTempPath(mStringSettings[CFG_CUSTOMTEMPPATH]); + gpDesktopHandler->setCustomTempPath(mStringSettings[cfg::dir::customtemppath]); } } @@ -1412,16 +1412,16 @@ QString Configuration::getCompilerPath(const ArchitectureEnumT arch) if(arch == ArchitectureEnumT::x86) { a = 32; - cfgkey = CFG_GCC32DIR; + cfgkey = cfg::dir::gcc32; } else //x64 { a = 64; - cfgkey = CFG_GCC64DIR; + cfgkey = cfg::dir::gcc64; } QString compilerPath; - if (getBoolSetting(CFG_PREFERINCLUDEDCOMPILER)) + if (getBoolSetting(cfg::preferincludedcompiler)) { compilerPath = gpDesktopHandler->getIncludedCompilerPath(a); } diff --git a/HopsanGUI/Configuration.h b/HopsanGUI/Configuration.h index 51bd087e89..6b3d8c805c 100644 --- a/HopsanGUI/Configuration.h +++ b/HopsanGUI/Configuration.h @@ -34,114 +34,7 @@ #ifndef CONFIGURATION_H #define CONFIGURATION_H -#define CFG_HOPSANCONFIG "hopsanconfig" -#define CFG_SETTINGS "settings" - -#define CFG_LIBRARYSTYLE "librarystyle" -#define CFG_PLOEXPORTVERSION "ploexportversion" - -#define CFG_CHECKFORDEVELOPMENTUPDATES "checkfordevelopmentupdates" -#define CFG_SHOWLICENSEONSTARTUP "showlicenseonstartup2" -#define CFG_SHOWHIDDENNODEDATAVARIABLES "showhiddennodedatavariables" -#define CFG_SHOWPOPUPHELP "showpopuphelp" -#define CFG_NATIVESTYLESHEET "nativestylesheet" -#define CFG_ANTIALIASING "antialiasing" -#define CFG_INVERTWHEEL "invertwheel" -#define CFG_ZOOMSTEP "zoomstep" -#define CFG_SNAPPING "snapping" -#define CFG_PROGRESSBAR "progressbar" -#define CFG_PROGRESSBARSTEP "progressbar_step" -#define CFG_MULTICORE "multicore" -#define CFG_NUMBEROFTHREADS "numberofthreads" -#define CFG_TOGGLENAMESBUTTONCHECKED "togglenamesbuttonchecked" -#define CFG_TOGGLEPORTSBUTTONCHECKED "toggleportsbuttonchecked" -#define CFG_GROUPMESSAGESBYTAG "groupmessagesbytag" -#define CFG_GENERATIONLIMIT "generationlimit" -#define CFG_CACHELOGDATA "cachelogdata" -#define CFG_AUTOBACKUP "autobackup" -#define CFG_AUTOLIMITGENERATIONS "autolimitgenerations" -#define CFG_SETPWDTOMWD "setpwdtomwd" -#define CFG_PLOTWINDOWSONTOP "plotwindowsontop" -#define CFG_LOGDURINGSIMULATION "logduringsimulation" -#define CFG_LOGSTEPS "logsteps" - -#define CFG_PLOTGFXIMAGEFORMAT "plotgfximageformat" -#define CFG_PLOTGFXDIMENSIONSUNIT "plotgfxdimensionsunit" -#define CFG_PLOTGFXDPI "plotgfxdpi" -#define CFG_PLOTGFXSIZE "plotgfxsize" -#define CFG_PLOTGFXKEEPASPECT "plotgfxkeepaspect" -#define CFG_PLOTGFXUSESCREENSIZE "plotgfxusescreensize" -#define CFG_BACKGROUNDCOLOR "backgroundcolor" - -#define CFG_PARAMETEREXPORTDIR "parameterexportdir" -#define CFG_PARAMETERIMPORTDIR "parameterimportdir" -#define CFG_LOADMODELDIR "loadmodeldir" -#define CFG_LOADSCRIPTDIR "loadmodeldir" -#define CFG_MODELGFXDIR "modelgfxdir" -#define CFG_PLOTDATADIR "plotdatadir" -#define CFG_PLOTGFXDIR "plotgfxdir" -#define CFG_SIMULINKEXPORTDIR "simulinkexportdir" -#define CFG_SUBSYSTEMDIR "subsystemdir" -#define CFG_EXTERNALLIBDIR "externallibdir" -#define CFG_SCRIPTDIR "scriptdir" -#define CFG_PLOTWINDOWDIR "plotwindowdir" -#define CFG_FMUDIR "fmudir" -#define CFG_FMUIMPORTDIR "fmuimportdir" -#define CFG_FMUEXPORTDIR "fmuexportdir" -#define CFG_EXEEXPORTDIR "exeexportdir" -#define CFG_LABVIEWEXPORTDIR "labviewexportdir" -#define CFG_PREFERINCLUDEDCOMPILER "preferincludedcompiler" -#define CFG_GCC32DIR "gcc32dir" -#define CFG_GCC64DIR "gcc64dir" -#define CFG_CUSTOMTEMPPATH "customtemppath" - -#define CFG_REMOTEHOPSANADDRESS "remotehopsanaddress" -#define CFG_REMOTEHOPSANADDRESSSERVERADDRESS "remotehopsanaddressserveraddress" -#define CFG_USEREMOTEADDRESSSERVER "useremotehopsanaddressserver" -#define CFG_USEREMOTEOPTIMIZATION "useremoteoptimization" -#define CFG_REMOTEHOPSANUSERIDENTIFICATION "remotehopsanuserid" -#define CFG_REMOTESHORTTIMEOUT "remoteshorttimeout" -#define CFG_REMOTELONGTIMEOUT "remotelongtimeout" - -#define CFG_PENSTYLE "penstyle" -#define CFG_TYPE "type" -#define CFG_GFXTYPE "gfxtype" -#define CFG_SITUATION "situation" -#define CFG_COLOR "color" -#define CFG_WIDTH "width" -#define CFG_CAPSTYLE "capstyle" - -#define CFG_UNITSETTINGS "unitsettings" -#define CFG_QUANTITY "quantity" -namespace cfg { - namespace siunits { - constexpr auto kg = "kg"; - constexpr auto m = "m"; - constexpr auto s = "s"; - constexpr auto A = "A"; - constexpr auto K = "K"; - constexpr auto mol = "mol"; - constexpr auto cd = "cd"; - constexpr auto rad = "rad"; - } -} - -#define CFG_BASEUNIT "baseunit" -#define CFG_UNIT "unit" -#define CFG_UNITS "units" -#define CFG_DEFAULTDISPALYUNIT "defaultdisplayunit" -#define CFG_NAME "name" -#define CFG_UNIT "unit" -#define CFG_CUSTOMUNIT "customunit" -#define CFG_SCALE "scale" -#define CFG_OFFSET "offset" -#define CFG_FROMBASEEXPR "frombaseexpr" -#define CFG_TOBBASEEXPR "tobaseexpr" - -#define CFG_HCOM "hcom" -#define CFG_PWD "pwd" -#define CFG_COMMAND "command" namespace cfg { namespace paths { @@ -161,6 +54,120 @@ namespace cfg { #include "common.h" #include "UnitScale.h" +namespace cfg { + constexpr auto hopsanconfig = "hopsanconfig"; + constexpr auto settings = "settings"; + constexpr auto librarystyle = "librarystyle"; + constexpr auto ploexportversion = "ploexportversion"; + constexpr auto checkfordevelopmentupdates = "checkfordevelopmentupdates"; + constexpr auto showlicenseonstartup = "showlicenseonstartup2"; + constexpr auto showhiddennodedatavariables = "showhiddennodedatavariables"; + constexpr auto showpopuphelp = "showpopuphelp"; + constexpr auto nativestylesheet = "nativestylesheet"; + constexpr auto antialiasing = "antialiasing"; + constexpr auto invertwheel = "invertwheel"; + constexpr auto zoomstep = "zoomstep"; + constexpr auto snapping = "snapping"; + constexpr auto progressbar = "progressbar"; + constexpr auto progressbarstep = "progressbar_step"; + constexpr auto multicore = "multicore"; + constexpr auto numberofthreads = "numberofthreads"; + constexpr auto togglenamesbuttonchecked = "togglenamesbuttonchecked"; + constexpr auto toggleportsbuttonchecked = "toggleportsbuttonchecked"; + constexpr auto groupmessagesbytag = "groupmessagesbytag"; + constexpr auto generationlimit = "generationlimit"; + constexpr auto cachelogdata = "cachelogdata"; + constexpr auto autobackup = "autobackup"; + constexpr auto autolimitgenerations = "autolimitgenerations"; + constexpr auto setpwdtomwd = "setpwdtomwd"; + constexpr auto plotwindowsontop = "plotwindowsontop"; + constexpr auto logduringsimulation = "logduringsimulation"; + constexpr auto logsteps = "logsteps"; + constexpr auto plotgfximageformat = "plotgfximageformat"; + constexpr auto plotgfxdimensionunit = "plotgfxdimensionsunit"; + constexpr auto plotgfxdpi = "plotgfxdpi"; + constexpr auto plotgfxsize = "plotgfxsize"; + constexpr auto plotgfxkeepaspect = "plotgfxkeepaspect"; + constexpr auto plotgfxusescreensize = "plotgfxusescreensize"; + constexpr auto backgroundcolor = "backgroundcolor"; + namespace dir { + constexpr auto parameterexport = "parameterexportdir"; + constexpr auto parameterimport = "parameterimportdir"; + constexpr auto loadmodel = "loadmodeldir"; + constexpr auto loadscript = "loadmodeldir"; + constexpr auto modelgfx = "modelgfxdir"; + constexpr auto plotdata = "plotdatadir"; + constexpr auto plotgfx = "plotgfxdir"; + constexpr auto simulinkexport = "simulinkexportdir"; + constexpr auto subsystem = "subsystemdir"; + constexpr auto externallib = "externallibdir"; + constexpr auto script = "scriptdir"; + constexpr auto plotwindow = "plotwindowdir"; + constexpr auto fmuimport = "fmuimportdir"; + constexpr auto fmuexport = "fmuexportdir"; + constexpr auto exeexport = "exeexportdir"; + constexpr auto labviewexport = "labviewexportdir"; + constexpr auto gcc32 = "gcc32dir"; + constexpr auto gcc64 = "gcc64dir"; + constexpr auto customtemppath = "customtemppath"; + } + constexpr auto preferincludedcompiler = "preferincludedcompiler"; + constexpr auto remotehopsanaddress = "remotehopsanaddress"; + constexpr auto remotehopsanaddresserveraddress = "remotehopsanaddresserveraddress"; + constexpr auto useremoteaddresserver = "useremotehopsanaddressserver"; + constexpr auto useremoteoptimization = "useremoteoptimization"; + constexpr auto remotehopsanuseridentification = "remotehopsanuserid"; + constexpr auto remoteshorttimeout = "remoteshorttimeout"; + constexpr auto remotelongtimeout = "remotelongtimeout"; + constexpr auto penstyle = "penstyle"; + constexpr auto type = "type"; + constexpr auto gfxtype = "gfxtype"; + constexpr auto situation = "situation"; + constexpr auto color = "color"; + constexpr auto width = "width"; + constexpr auto capstyle = "capstyle"; + constexpr auto style = "style"; + constexpr auto unitsettings = "unitsettings"; + constexpr auto quantity = "quantity"; + constexpr auto baseunit = "baseunit"; + constexpr auto unit = "unit"; + constexpr auto units = "units"; + constexpr auto defaultdisplayunits = "defaultdisplayunit"; + constexpr auto name = "name"; + constexpr auto customunit = "customunit"; + constexpr auto scale = "scale"; + constexpr auto offset = "offset"; + constexpr auto frombaseexpr = "frombaseexpr"; + constexpr auto tobaseexpr = "tobaseexpr"; + constexpr auto hcom = "hcom"; + constexpr auto pwd = "pwd"; + constexpr auto command = "command"; + constexpr auto libs = "libs"; + constexpr auto userlib = "userlib"; + namespace libtype { + constexpr auto root = "libtype"; + constexpr auto internal = "internal"; + constexpr auto external = "external"; + constexpr auto fmu = "fmu"; + } + namespace models { + constexpr auto root = "models"; + constexpr auto lastsession = "lastsessionmodel"; + constexpr auto recent = "recentmodel"; + constexpr auto recentgenerator = "recentgeneratormodel"; + } + namespace siunits { + constexpr auto kg = "kg"; + constexpr auto m = "m"; + constexpr auto s = "s"; + constexpr auto A = "A"; + constexpr auto K = "K"; + constexpr auto mol = "mol"; + constexpr auto cd = "cd"; + constexpr auto rad = "rad"; + } +} + class Configuration : public QObject { Q_OBJECT diff --git a/HopsanGUI/Dialogs/AnimatedIconPropertiesDialog.cpp b/HopsanGUI/Dialogs/AnimatedIconPropertiesDialog.cpp index 3c782ba8ee..53760cb911 100644 --- a/HopsanGUI/Dialogs/AnimatedIconPropertiesDialog.cpp +++ b/HopsanGUI/Dialogs/AnimatedIconPropertiesDialog.cpp @@ -607,7 +607,7 @@ void AnimatedIconPropertiesDialog::setValues() void AnimatedIconPropertiesDialog::resetValues() { QDomDocument domDocument; - QDomElement animationRoot = domDocument.createElement(HMF_ANIMATION); + QDomElement animationRoot = domDocument.createElement(hmf::animation); domDocument.appendChild(animationRoot); QString subTypeName = mpAnimatedComponent->mpModelObject->getSubTypeName(); diff --git a/HopsanGUI/Dialogs/ComponentPropertiesDialog3.cpp b/HopsanGUI/Dialogs/ComponentPropertiesDialog3.cpp index 239f9050cf..9e3d601b76 100644 --- a/HopsanGUI/Dialogs/ComponentPropertiesDialog3.cpp +++ b/HopsanGUI/Dialogs/ComponentPropertiesDialog3.cpp @@ -1055,7 +1055,7 @@ VariableTableWidget::VariableTableWidget(ModelObject *pModelObject, QWidget *pPa for (int i=0; igetBoolSetting(CFG_SHOWHIDDENNODEDATAVARIABLES) || (variameters[i].mVariabelType != "Hidden") ) ) + ( gpConfig->getBoolSetting(cfg::showhiddennodedatavariables) || (variameters[i].mVariabelType != "Hidden") ) ) { // Extract current port name to see if we should make a separator QString portName = variameters[i].mPortName; diff --git a/HopsanGUI/Dialogs/LicenseDialog.cpp b/HopsanGUI/Dialogs/LicenseDialog.cpp index dd19146c09..f5d2504c78 100644 --- a/HopsanGUI/Dialogs/LicenseDialog.cpp +++ b/HopsanGUI/Dialogs/LicenseDialog.cpp @@ -120,7 +120,7 @@ LicenseDialog::LicenseDialog(QWidget *pParent) : pLayout->addWidget(pDocsButton, 1); QCheckBox *pAlwaysShow = new QCheckBox("Always show on startup", this); - pAlwaysShow->setChecked(gpConfig->getBoolSetting(CFG_SHOWLICENSEONSTARTUP)); + pAlwaysShow->setChecked(gpConfig->getBoolSetting(cfg::showlicenseonstartup)); connect(pAlwaysShow, SIGNAL(clicked(bool)), this, SLOT(toggleAlwaysShow(bool))); QPushButton *pCloseButton = new QPushButton("Close", this); @@ -137,7 +137,7 @@ LicenseDialog::LicenseDialog(QWidget *pParent) : void LicenseDialog::toggleAlwaysShow(bool tf) { - gpConfig->setBoolSetting(CFG_SHOWLICENSEONSTARTUP, tf); + gpConfig->setBoolSetting(cfg::showlicenseonstartup, tf); } void LicenseDialog::showLicenseDocs() diff --git a/HopsanGUI/Dialogs/OptimizationDialog.cpp b/HopsanGUI/Dialogs/OptimizationDialog.cpp index 6c2510974e..b3474d85fd 100644 --- a/HopsanGUI/Dialogs/OptimizationDialog.cpp +++ b/HopsanGUI/Dialogs/OptimizationDialog.cpp @@ -335,7 +335,7 @@ void OptimizationDialog::saveAs(QString filePath) else if(filePath.isEmpty()) { filePath = QFileDialog::getSaveFileName(this, tr("Save Script File"), - gpConfig->getStringSetting(CFG_SCRIPTDIR), + gpConfig->getStringSetting(cfg::dir::script), this->tr("HCOM Script (*.hcom)")); if(filePath.isEmpty()) //Don't save anything if user presses cancel @@ -345,7 +345,7 @@ void OptimizationDialog::saveAs(QString filePath) mScriptFileInfo.setFile(filePath); //Save file info for "save as" mpTabWidget->setTabText(0, QString("Script (%1)").arg(mScriptFileInfo.fileName())); mpScriptFileLabel->setText(QString("Script file: %1").arg(mScriptFileInfo.fileName())); - gpConfig->setStringSetting(CFG_SCRIPTDIR, mScriptFileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::script, mScriptFileInfo.absolutePath()); } QFile file(filePath); //Create a QFile object @@ -373,13 +373,13 @@ void OptimizationDialog::loadScriptFile(QString filePath) if(filePath.isEmpty()) { filePath = QFileDialog::getOpenFileName(gpMainWindowWidget, tr("Load Script File)"), - gpConfig->getStringSetting(CFG_SCRIPTDIR), + gpConfig->getStringSetting(cfg::dir::script), tr("HCOM Script (*.hcom)")); if(filePath.isEmpty()) //Canceled by user return; } - gpConfig->setStringSetting(CFG_SCRIPTDIR, QFileInfo(filePath).absolutePath()); + gpConfig->setStringSetting(cfg::dir::script, QFileInfo(filePath).absolutePath()); QFile file(filePath); file.open(QFile::Text | QFile::ReadOnly); diff --git a/HopsanGUI/Dialogs/OptimizationScriptWizard.cpp b/HopsanGUI/Dialogs/OptimizationScriptWizard.cpp index 6edd501612..8bcedbede2 100644 --- a/HopsanGUI/Dialogs/OptimizationScriptWizard.cpp +++ b/HopsanGUI/Dialogs/OptimizationScriptWizard.cpp @@ -174,7 +174,7 @@ OptimizationScriptWizard::OptimizationScriptWizard(SystemObject* pSystem, QWidge mpElitesLineEdit->setValidator(new QIntValidator()); mpNumModelsLabel = new QLabel("Number of models: "); - mpNumModelsLineEdit = new QLineEdit(QString::number(qMax(1,gpConfig->getIntegerSetting(CFG_NUMBEROFTHREADS))), this); + mpNumModelsLineEdit = new QLineEdit(QString::number(qMax(1,gpConfig->getIntegerSetting(cfg::numberofthreads))), this); mpNumModelsLineEdit->setValidator(new QIntValidator()); mpMethodLabel = new QLabel("Parallel method: "); @@ -1202,7 +1202,7 @@ void OptimizationScriptWizard::generateParameterSweepScript() generateParameterCode(templateCode); generateCommonOptions(templateCode); - int nThreads = gpConfig->getIntegerSetting(CFG_NUMBEROFTHREADS); + int nThreads = gpConfig->getIntegerSetting(cfg::numberofthreads); templateCode.replace("<<>>", QString::number(mpLengthSpinBox->value()/double(nThreads))); templateCode.replace("<<>>", QString::number(nThreads)); diff --git a/HopsanGUI/Dialogs/OptionsDialog.cpp b/HopsanGUI/Dialogs/OptionsDialog.cpp index e7f9544684..7b8c646c7c 100644 --- a/HopsanGUI/Dialogs/OptionsDialog.cpp +++ b/HopsanGUI/Dialogs/OptionsDialog.cpp @@ -330,7 +330,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) mpEnableProgressBarCheckBox->setCheckable(true); QLabel *pProgressBarLabel = new QLabel(tr("Progress Bar Time Step [ms]")); - pProgressBarLabel->setEnabled(gpConfig->getBoolSetting(CFG_PROGRESSBAR)); + pProgressBarLabel->setEnabled(gpConfig->getBoolSetting(cfg::progressbar)); mpProgressBarSpinBox = new QSpinBox(); mpProgressBarSpinBox->setMinimum(1); mpProgressBarSpinBox->setMaximum(5000); @@ -482,8 +482,8 @@ OptionsDialog::OptionsDialog(QWidget *parent) pCompilersLayout->addWidget(new QWidget(this), ++row,0,1,3); pCompilersLayout->setRowStretch(row,1); - setCompiler32Path(gpConfig->getStringSetting(CFG_GCC32DIR)); - setCompiler64Path(gpConfig->getStringSetting(CFG_GCC64DIR)); + setCompiler32Path(gpConfig->getStringSetting(cfg::dir::gcc32)); + setCompiler64Path(gpConfig->getStringSetting(cfg::dir::gcc64)); connect(pCompiler32Button, SIGNAL(clicked()), this, SLOT(setCompiler32Path())); connect(mpCompiler32LineEdit, SIGNAL(textChanged(QString)), this, SLOT(setCompiler32Path(QString))); @@ -601,11 +601,11 @@ void OptionsDialog::setValues() // Toggle writing to disk off, since we would write many times fore each set below gpConfig->beginMultiSet(); - gpConfig->setBoolSetting(CFG_SHOWPOPUPHELP, mpShowPopupHelpCheckBox->isChecked()); - gpConfig->setBoolSetting(CFG_NATIVESTYLESHEET, mpNativeStyleSheetCheckBox->isChecked()); - gpConfig->setBoolSetting(CFG_CHECKFORDEVELOPMENTUPDATES, mpCheckDevelopmentUpdatesCheckBox->isChecked()); + gpConfig->setBoolSetting(cfg::showpopuphelp, mpShowPopupHelpCheckBox->isChecked()); + gpConfig->setBoolSetting(cfg::nativestylesheet, mpNativeStyleSheetCheckBox->isChecked()); + gpConfig->setBoolSetting(cfg::checkfordevelopmentupdates, mpCheckDevelopmentUpdatesCheckBox->isChecked()); - if(gpConfig->getBoolSetting(CFG_NATIVESTYLESHEET)) + if(gpConfig->getBoolSetting(cfg::nativestylesheet)) { gpMainWindowWidget->setStyleSheet((" ")); QMainWindow dummy; @@ -619,33 +619,33 @@ void OptionsDialog::setValues() this->setPalette(gpConfig->getPalette()); } emit paletteChanged(); - gpConfig->setBoolSetting(CFG_INVERTWHEEL, mpInvertWheelCheckBox->isChecked()); - gpConfig->setBoolSetting(CFG_ANTIALIASING, mpAntiAliasingCheckBox->isChecked()); - gpConfig->setBoolSetting(CFG_SNAPPING, mpSnappingCheckBox->isChecked()); - gpConfig->setBoolSetting(CFG_SETPWDTOMWD, mpAutoSetPwdToMwdCheckBox->isChecked()); - gpConfig->setDoubleSetting(CFG_ZOOMSTEP, mpZoomStepSpinBox->value()); + gpConfig->setBoolSetting(cfg::invertwheel, mpInvertWheelCheckBox->isChecked()); + gpConfig->setBoolSetting(cfg::antialiasing, mpAntiAliasingCheckBox->isChecked()); + gpConfig->setBoolSetting(cfg::snapping, mpSnappingCheckBox->isChecked()); + gpConfig->setBoolSetting(cfg::setpwdtomwd, mpAutoSetPwdToMwdCheckBox->isChecked()); + gpConfig->setDoubleSetting(cfg::zoomstep, mpZoomStepSpinBox->value()); for(int i=0; icount(); ++i) { - gpModelHandler->getModel(i)->getGraphicsView()->setRenderHint(QPainter::Antialiasing, gpConfig->getBoolSetting(CFG_ANTIALIASING)); + gpModelHandler->getModel(i)->getGraphicsView()->setRenderHint(QPainter::Antialiasing, gpConfig->getBoolSetting(cfg::antialiasing)); } gpConfig->setBackgroundColor(mPickedBackgroundColor); for(int i=0; icount(); ++i) { gpModelHandler->getModel(i)->getGraphicsView()->updateViewPort(); } - gpConfig->setBoolSetting(CFG_PROGRESSBAR, mpEnableProgressBarCheckBox->isChecked()); - gpConfig->setIntegerSetting(CFG_PROGRESSBARSTEP, mpProgressBarSpinBox->value()); - gpConfig->setBoolSetting(CFG_MULTICORE, mpUseMulticoreCheckBox->isChecked()); - gpConfig->setIntegerSetting(CFG_NUMBEROFTHREADS, mpThreadsSpinBox->value()); - gpConfig->setBoolSetting(CFG_LOGDURINGSIMULATION, mpLogDuringSimulationCheckBox->isChecked()); - gpConfig->setIntegerSetting(CFG_LOGSTEPS, mpLogStepsSpinBox->value()); - gpConfig->setBoolSetting(CFG_AUTOLIMITGENERATIONS, mpAutoLimitGenerationsCheckBox->isChecked()); - gpConfig->setBoolSetting(CFG_SHOWHIDDENNODEDATAVARIABLES, mpShowHiddenNodeDataVarCheckBox->isChecked()); - gpConfig->setBoolSetting(CFG_PLOTWINDOWSONTOP, mpPlotWindowsOnTop->isChecked()); - gpConfig->setIntegerSetting(CFG_GENERATIONLIMIT, mpGenerationLimitSpinBox->value()); - gpConfig->setIntegerSetting(CFG_PLOEXPORTVERSION, mpDefaultPloExportVersion->value()); - gpConfig->setBoolSetting(CFG_CACHELOGDATA, mpCacheLogDataCeckBox->isChecked()); - gpConfig->setStringSetting(CFG_CUSTOMTEMPPATH, mpCustomTempPathLineEdit->text()); + gpConfig->setBoolSetting(cfg::progressbar, mpEnableProgressBarCheckBox->isChecked()); + gpConfig->setIntegerSetting(cfg::progressbarstep, mpProgressBarSpinBox->value()); + gpConfig->setBoolSetting(cfg::multicore, mpUseMulticoreCheckBox->isChecked()); + gpConfig->setIntegerSetting(cfg::numberofthreads, mpThreadsSpinBox->value()); + gpConfig->setBoolSetting(cfg::logduringsimulation, mpLogDuringSimulationCheckBox->isChecked()); + gpConfig->setIntegerSetting(cfg::logsteps, mpLogStepsSpinBox->value()); + gpConfig->setBoolSetting(cfg::autolimitgenerations, mpAutoLimitGenerationsCheckBox->isChecked()); + gpConfig->setBoolSetting(cfg::showhiddennodedatavariables, mpShowHiddenNodeDataVarCheckBox->isChecked()); + gpConfig->setBoolSetting(cfg::plotwindowsontop, mpPlotWindowsOnTop->isChecked()); + gpConfig->setIntegerSetting(cfg::generationlimit, mpGenerationLimitSpinBox->value()); + gpConfig->setIntegerSetting(cfg::ploexportversion, mpDefaultPloExportVersion->value()); + gpConfig->setBoolSetting(cfg::cachelogdata, mpCacheLogDataCeckBox->isChecked()); + gpConfig->setStringSetting(cfg::dir::customtemppath, mpCustomTempPathLineEdit->text()); for(int i=0; icount(); ++i) //Loop through all containers and reduce their plot data { gpModelHandler->getModel(i)->getLogDataHandler()->limitPlotGenerations(); @@ -662,17 +662,17 @@ void OptionsDialog::setValues() } } - gpConfig->setStringSetting(CFG_GCC32DIR, mpCompiler32LineEdit->text()); - gpConfig->setStringSetting(CFG_GCC64DIR, mpCompiler64LineEdit->text()); - gpConfig->setBoolSetting(CFG_PREFERINCLUDEDCOMPILER, mpPrefereIncludedCompiler->isChecked()); + gpConfig->setStringSetting(cfg::dir::gcc32, mpCompiler32LineEdit->text()); + gpConfig->setStringSetting(cfg::dir::gcc64, mpCompiler64LineEdit->text()); + gpConfig->setBoolSetting(cfg::preferincludedcompiler, mpPrefereIncludedCompiler->isChecked()); - gpConfig->setStringSetting(CFG_REMOTEHOPSANADDRESS, mpRemoteHopsanAddress->text()); - gpConfig->setStringSetting(CFG_REMOTEHOPSANADDRESSSERVERADDRESS, mpRemoteHopsanAddressServerAddress->text()); - gpConfig->setStringSetting(CFG_REMOTEHOPSANUSERIDENTIFICATION, mpRemoteHopsanUserId->text()); - gpConfig->setBoolSetting(CFG_USEREMOTEADDRESSSERVER, mpUseRemoteHopsanAddressServer->isChecked()); - gpConfig->setBoolSetting(CFG_USEREMOTEOPTIMIZATION, mpUseRemoteOptimization->isChecked()); - gpConfig->setIntegerSetting(CFG_REMOTESHORTTIMEOUT, mpRemoteShortTOSpinbox->value()); - gpConfig->setIntegerSetting(CFG_REMOTELONGTIMEOUT, mpRemoteLongTOSpinbox->value()); + gpConfig->setStringSetting(cfg::remotehopsanaddress, mpRemoteHopsanAddress->text()); + gpConfig->setStringSetting(cfg::remotehopsanaddresserveraddress, mpRemoteHopsanAddressServerAddress->text()); + gpConfig->setStringSetting(cfg::remotehopsanuseridentification, mpRemoteHopsanUserId->text()); + gpConfig->setBoolSetting(cfg::useremoteaddresserver, mpUseRemoteHopsanAddressServer->isChecked()); + gpConfig->setBoolSetting(cfg::useremoteoptimization, mpUseRemoteOptimization->isChecked()); + gpConfig->setIntegerSetting(cfg::remoteshorttimeout, mpRemoteShortTOSpinbox->value()); + gpConfig->setIntegerSetting(cfg::remotelongtimeout, mpRemoteLongTOSpinbox->value()); // Toggle writing to disk back on before saving gpConfig->endMultiSet(); @@ -734,46 +734,46 @@ void OptionsDialog::show() mpBackgroundColorButton->setStyleSheet(buttonStyle); mPickedBackgroundColor = gpConfig->getBackgroundColor(); - mpCheckDevelopmentUpdatesCheckBox->setChecked(gpConfig->getBoolSetting(CFG_CHECKFORDEVELOPMENTUPDATES)); - mpNativeStyleSheetCheckBox->setChecked(gpConfig->getBoolSetting(CFG_NATIVESTYLESHEET)); - mpShowPopupHelpCheckBox->setChecked(gpConfig->getBoolSetting(CFG_SHOWPOPUPHELP)); - mpAntiAliasingCheckBox->setChecked(gpConfig->getBoolSetting(CFG_ANTIALIASING)); - mpInvertWheelCheckBox->setChecked(gpConfig->getBoolSetting(CFG_INVERTWHEEL)); - mpSnappingCheckBox->setChecked(gpConfig->getBoolSetting(CFG_SNAPPING)); - mpZoomStepSpinBox->setValue(gpConfig->getDoubleSetting(CFG_ZOOMSTEP)); - mpAutoSetPwdToMwdCheckBox->setChecked(gpConfig->getBoolSetting(CFG_SETPWDTOMWD)); - mpEnableProgressBarCheckBox->setChecked(gpConfig->getBoolSetting(CFG_PROGRESSBAR)); - mpProgressBarSpinBox->setValue(gpConfig->getIntegerSetting(CFG_PROGRESSBARSTEP)); - mpProgressBarSpinBox->setEnabled(gpConfig->getBoolSetting(CFG_PROGRESSBAR)); - mpThreadsSpinBox->setEnabled(gpConfig->getBoolSetting(CFG_MULTICORE)); - mpUseMulticoreCheckBox->setChecked(gpConfig->getBoolSetting(CFG_MULTICORE)); - mpThreadsSpinBox->setValue(gpConfig->getIntegerSetting(CFG_NUMBEROFTHREADS)); - mpThreadsLabel->setEnabled(gpConfig->getBoolSetting(CFG_MULTICORE)); - mpLogDuringSimulationCheckBox->setChecked(gpConfig->getBoolSetting(CFG_LOGDURINGSIMULATION)); - mpLogStepsLabel->setEnabled(gpConfig->getBoolSetting(CFG_LOGDURINGSIMULATION)); - mpLogStepsSpinBox->setEnabled(gpConfig->getBoolSetting(CFG_LOGDURINGSIMULATION)); - mpLogStepsSpinBox->setValue(gpConfig->getIntegerSetting(CFG_LOGSTEPS)); - mpGenerationLimitSpinBox->setValue(gpConfig->getIntegerSetting(CFG_GENERATIONLIMIT)); - mpDefaultPloExportVersion->setValue(gpConfig->getIntegerSetting(CFG_PLOEXPORTVERSION)); - mpAutoLimitGenerationsCheckBox->setChecked(gpConfig->getBoolSetting(CFG_AUTOLIMITGENERATIONS)); - mpShowHiddenNodeDataVarCheckBox->setChecked(gpConfig->getBoolSetting(CFG_SHOWHIDDENNODEDATAVARIABLES)); - mpPlotWindowsOnTop->setChecked(gpConfig->getBoolSetting(CFG_PLOTWINDOWSONTOP)); - mpCacheLogDataCeckBox->setChecked(gpConfig->getBoolSetting(CFG_CACHELOGDATA)); - mpCustomTempPathLineEdit->setText(gpConfig->getStringSetting(CFG_CUSTOMTEMPPATH)); - - mpRemoteHopsanAddress->setText(gpConfig->getStringSetting(CFG_REMOTEHOPSANADDRESS)); - mpRemoteHopsanAddressServerAddress->setText(gpConfig->getStringSetting(CFG_REMOTEHOPSANADDRESSSERVERADDRESS)); - mpRemoteHopsanUserId->setText(gpConfig->getStringSetting(CFG_REMOTEHOPSANUSERIDENTIFICATION)); - mpUseRemoteHopsanAddressServer->setChecked(gpConfig->getBoolSetting(CFG_USEREMOTEADDRESSSERVER)); - mpUseRemoteOptimization->setChecked(gpConfig->getBoolSetting(CFG_USEREMOTEOPTIMIZATION)); - mpRemoteShortTOSpinbox->setValue(gpConfig->getIntegerSetting(CFG_REMOTESHORTTIMEOUT)); - mpRemoteLongTOSpinbox->setValue(gpConfig->getIntegerSetting(CFG_REMOTELONGTIMEOUT)); - - setCompiler32Path(gpConfig->getStringSetting(CFG_GCC32DIR)); - setCompiler64Path(gpConfig->getStringSetting(CFG_GCC64DIR)); + mpCheckDevelopmentUpdatesCheckBox->setChecked(gpConfig->getBoolSetting(cfg::checkfordevelopmentupdates)); + mpNativeStyleSheetCheckBox->setChecked(gpConfig->getBoolSetting(cfg::nativestylesheet)); + mpShowPopupHelpCheckBox->setChecked(gpConfig->getBoolSetting(cfg::showpopuphelp)); + mpAntiAliasingCheckBox->setChecked(gpConfig->getBoolSetting(cfg::antialiasing)); + mpInvertWheelCheckBox->setChecked(gpConfig->getBoolSetting(cfg::invertwheel)); + mpSnappingCheckBox->setChecked(gpConfig->getBoolSetting(cfg::snapping)); + mpZoomStepSpinBox->setValue(gpConfig->getDoubleSetting(cfg::zoomstep)); + mpAutoSetPwdToMwdCheckBox->setChecked(gpConfig->getBoolSetting(cfg::setpwdtomwd)); + mpEnableProgressBarCheckBox->setChecked(gpConfig->getBoolSetting(cfg::progressbar)); + mpProgressBarSpinBox->setValue(gpConfig->getIntegerSetting(cfg::progressbarstep)); + mpProgressBarSpinBox->setEnabled(gpConfig->getBoolSetting(cfg::progressbar)); + mpThreadsSpinBox->setEnabled(gpConfig->getBoolSetting(cfg::multicore)); + mpUseMulticoreCheckBox->setChecked(gpConfig->getBoolSetting(cfg::multicore)); + mpThreadsSpinBox->setValue(gpConfig->getIntegerSetting(cfg::numberofthreads)); + mpThreadsLabel->setEnabled(gpConfig->getBoolSetting(cfg::multicore)); + mpLogDuringSimulationCheckBox->setChecked(gpConfig->getBoolSetting(cfg::logduringsimulation)); + mpLogStepsLabel->setEnabled(gpConfig->getBoolSetting(cfg::logduringsimulation)); + mpLogStepsSpinBox->setEnabled(gpConfig->getBoolSetting(cfg::logduringsimulation)); + mpLogStepsSpinBox->setValue(gpConfig->getIntegerSetting(cfg::logsteps)); + mpGenerationLimitSpinBox->setValue(gpConfig->getIntegerSetting(cfg::generationlimit)); + mpDefaultPloExportVersion->setValue(gpConfig->getIntegerSetting(cfg::ploexportversion)); + mpAutoLimitGenerationsCheckBox->setChecked(gpConfig->getBoolSetting(cfg::autolimitgenerations)); + mpShowHiddenNodeDataVarCheckBox->setChecked(gpConfig->getBoolSetting(cfg::showhiddennodedatavariables)); + mpPlotWindowsOnTop->setChecked(gpConfig->getBoolSetting(cfg::plotwindowsontop)); + mpCacheLogDataCeckBox->setChecked(gpConfig->getBoolSetting(cfg::cachelogdata)); + mpCustomTempPathLineEdit->setText(gpConfig->getStringSetting(cfg::dir::customtemppath)); + + mpRemoteHopsanAddress->setText(gpConfig->getStringSetting(cfg::remotehopsanaddress)); + mpRemoteHopsanAddressServerAddress->setText(gpConfig->getStringSetting(cfg::remotehopsanaddresserveraddress)); + mpRemoteHopsanUserId->setText(gpConfig->getStringSetting(cfg::remotehopsanuseridentification)); + mpUseRemoteHopsanAddressServer->setChecked(gpConfig->getBoolSetting(cfg::useremoteaddresserver)); + mpUseRemoteOptimization->setChecked(gpConfig->getBoolSetting(cfg::useremoteoptimization)); + mpRemoteShortTOSpinbox->setValue(gpConfig->getIntegerSetting(cfg::remoteshorttimeout)); + mpRemoteLongTOSpinbox->setValue(gpConfig->getIntegerSetting(cfg::remotelongtimeout)); + + setCompiler32Path(gpConfig->getStringSetting(cfg::dir::gcc32)); + setCompiler64Path(gpConfig->getStringSetting(cfg::dir::gcc64)); QString compilerpath = gpDesktopHandler->getIncludedCompilerPath(); - mpPrefereIncludedCompiler->setChecked(gpConfig->getBoolSetting(CFG_PREFERINCLUDEDCOMPILER)); + mpPrefereIncludedCompiler->setChecked(gpConfig->getBoolSetting(cfg::preferincludedcompiler)); if (compilerpath.isEmpty()) { mpIncludedCompilerLabel->setText("Not present!"); @@ -803,7 +803,7 @@ void OptionsDialog::show() void OptionsDialog::setCompiler32Path() { - QString path = QFileDialog::getExistingDirectory(this, "Set Compiler Path:", gpConfig->getStringSetting(CFG_GCC32DIR)); + QString path = QFileDialog::getExistingDirectory(this, "Set Compiler Path:", gpConfig->getStringSetting(cfg::dir::gcc32)); if(path.isEmpty()) return; @@ -819,7 +819,7 @@ void OptionsDialog::setCompiler32Path(QString path) void OptionsDialog::setCompiler64Path() { - QString path = QFileDialog::getExistingDirectory(this, "Set Compiler Path:", gpConfig->getStringSetting(CFG_GCC64DIR)); + QString path = QFileDialog::getExistingDirectory(this, "Set Compiler Path:", gpConfig->getStringSetting(cfg::dir::gcc64)); if(path.isEmpty()) return; diff --git a/HopsanGUI/Dialogs/SensitivityAnalysisDialog.cpp b/HopsanGUI/Dialogs/SensitivityAnalysisDialog.cpp index 8f5c5d2a58..c56cc351ab 100644 --- a/HopsanGUI/Dialogs/SensitivityAnalysisDialog.cpp +++ b/HopsanGUI/Dialogs/SensitivityAnalysisDialog.cpp @@ -556,7 +556,7 @@ void SensitivityAnalysisDialog::run() // } -// int nThreads = gpConfig->getIntegerSetting(CFG_NUMBEROFTHREADS); +// int nThreads = gpConfig->getIntegerSetting(cfg::numberofthreads); // if(nThreads == 0) // { //#ifdef _WIN32 @@ -606,8 +606,8 @@ void SensitivityAnalysisDialog::run() // mModelPtrs.at(m)->getTopLevelSystemContainer()->getCoreSystemAccessPtr()->addSearchPath(appearanceDataBasePath); // } -// bool progressBarOrgSetting = gpConfig->getBoolSetting(CFG_PROGRESSBAR); -// gpConfig->setBoolSetting(CFG_PROGRESSBAR, false); +// bool progressBarOrgSetting = gpConfig->getBoolSetting(cfg::progressbar); +// gpConfig->setBoolSetting(cfg::progressbar, false); // for(int i=0; isimulateMultipleModels_blocking(mModelPtrs)) // { // gpMessageHandler->addErrorMessage("Unable to perform sensitivity analysis: Failed to simulate model."); -// gpConfig->setBoolSetting(CFG_PROGRESSBAR, progressBarOrgSetting); +// gpConfig->setBoolSetting(cfg::progressbar, progressBarOrgSetting); // return; // } // } @@ -657,7 +657,7 @@ void SensitivityAnalysisDialog::run() // } // mpProgressBar->setValue(100); //Just to make it look better -// gpConfig->setBoolSetting(CFG_PROGRESSBAR, progressBarOrgSetting); +// gpConfig->setBoolSetting(cfg::progressbar, progressBarOrgSetting); // for(int v=0; vvalue(); int nParameters = mSelectedParameters.size(); - int nThreads = gpConfig->getIntegerSetting(CFG_NUMBEROFTHREADS); + int nThreads = gpConfig->getIntegerSetting(cfg::numberofthreads); if(nThreads == 0) { #ifdef _WIN32 @@ -817,7 +817,7 @@ void SensitivityAnalysisDialog::updateProgressBar(int i) void SensitivityAnalysisEvaluator::plot() { mpDialog->updateProgressBar(mpWorker->getMaxNumberOfIterations()); //Just to make it look better - // gpConfig->setBoolSetting(CFG_PROGRESSBAR, progressBarOrgSetting); + // gpConfig->setBoolSetting(cfg::progressbar, progressBarOrgSetting); if (!mModelPtrs.empty()) { diff --git a/HopsanGUI/GUIConnector.cpp b/HopsanGUI/GUIConnector.cpp index 54b0d3aaab..183c5eadfb 100644 --- a/HopsanGUI/GUIConnector.cpp +++ b/HopsanGUI/GUIConnector.cpp @@ -628,39 +628,39 @@ void Connector::saveToDomElement(QDomElement &rDomElement) } //Core necessary stuff - QDomElement xmlConnect = appendDomElement(rDomElement, HMF_CONNECTORTAG); + QDomElement xmlConnect = appendDomElement(rDomElement, hmf::connector::root); - xmlConnect.setAttribute(HMF_CONNECTORSTARTCOMPONENTTAG, getStartComponentName()); - xmlConnect.setAttribute(HMF_CONNECTORSTARTPORTTAG, getStartPortName()); - xmlConnect.setAttribute(HMF_CONNECTORENDCOMPONENTTAG, getEndComponentName()); - xmlConnect.setAttribute(HMF_CONNECTORENDPORTTAG, getEndPortName()); + xmlConnect.setAttribute(hmf::connector::startcomponent, getStartComponentName()); + xmlConnect.setAttribute(hmf::connector::startport, getStartPortName()); + xmlConnect.setAttribute(hmf::connector::endcomponent, getEndComponentName()); + xmlConnect.setAttribute(hmf::connector::endport, getEndPortName()); //Save gui data to dom - QDomElement xmlConnectGUI = appendDomElement(xmlConnect, HMF_HOPSANGUITAG); - QDomElement xmlCoordinates = appendDomElement(xmlConnectGUI, HMF_COORDINATES); + QDomElement xmlConnectGUI = appendDomElement(xmlConnect, hmf::hopsangui); + QDomElement xmlCoordinates = appendDomElement(xmlConnectGUI, hmf::connector::coordinates); for(int j=0; jgetCustomColor(); if(customColor != QColor()) { - appendDomTextNode(xmlConnectGUI, HMF_COLORTAG, makeRgbString(customColor)); + appendDomTextNode(xmlConnectGUI, hmf::connector::color, makeRgbString(customColor)); } } diff --git a/HopsanGUI/GUIObjects/GUIComponent.cpp b/HopsanGUI/GUIObjects/GUIComponent.cpp index d40b3f6505..46fed79eb5 100644 --- a/HopsanGUI/GUIObjects/GUIComponent.cpp +++ b/HopsanGUI/GUIObjects/GUIComponent.cpp @@ -232,7 +232,7 @@ void Component::loadParameterValuesFromFile(QString parameterFile) { if(parameterFile.isEmpty()) { parameterFile = QFileDialog::getOpenFileName(gpMainWindowWidget, tr("Load Parameter File"), - gpConfig->getStringSetting(CFG_LOADMODELDIR), + gpConfig->getStringSetting(cfg::dir::loadmodel), tr("Hopsan Parameter Files (*.hpf *.xml)")); } @@ -245,7 +245,7 @@ void Component::loadParameterValuesFromFile(QString parameterFile) if (numChanged > 0) { mpParentSystemObject->mpModelWidget->hasChanged(); } - gpConfig->setStringSetting(CFG_LOADMODELDIR, QFileInfo(parameterFile).absolutePath()); + gpConfig->setStringSetting(cfg::dir::loadmodel, QFileInfo(parameterFile).absolutePath()); } #if QT_VERSION_MAJOR < 5 QMetaObject::invokeMethod(mpParentSystemObject,"checkMessages"); @@ -275,7 +275,7 @@ int Component::type() const QString Component::getHmfTagName() const { - return HMF_COMPONENT; + return hmf::component; } @@ -336,28 +336,28 @@ void Component::saveCoreDataToDomElement(QDomElement &rDomElement, SaveContentsE ModelObject::saveCoreDataToDomElement(rDomElement, contents); //Save parameters (also core related) - QDomElement xmlParameters = appendDomElement(rDomElement, HMF_PARAMETERS); + QDomElement xmlParameters = appendDomElement(rDomElement, hmf::parameters); QVector paramDataVec; getParameters(paramDataVec); for(int i=0; iisParameterMappedToSystemParameter(*pit)) { - xmlParam.setAttribute(HMF_SYSTEMPARAMETERTAG, this->getSystemParameterKey(*pit)); + xmlParam.setAttribute(hmf::systemparameter, this->getSystemParameterKey(*pit)); }*/ } if(contents==FullModel) { //Implementation of Feature #698 - Save nodetype in HMF - QDomElement xmlPorts = appendDomElement(rDomElement, HMF_PORTSTAG); + QDomElement xmlPorts = appendDomElement(rDomElement, hmf::ports); // Note! we cant loop local ports since non-enabled ports will not exist at all in the GUI // Instead we ask Core for all "variameters" and extract port info from there @@ -371,7 +371,7 @@ void Component::saveCoreDataToDomElement(QDomElement &rDomElement, SaveContentsE { currentPort = desc.mPortName; QDomElement xmlPort = appendDomElement(xmlPorts, "port"); - xmlPort.setAttribute(HMF_NAMETAG, desc.mPortName); + xmlPort.setAttribute(hmf::name, desc.mPortName); xmlPort.setAttribute("nodetype", desc.mNodeType); Port *pPort = this->getPort(desc.mPortName); if (pPort) @@ -394,7 +394,7 @@ void Component::saveCoreDataToDomElement(QDomElement &rDomElement, SaveContentsE QDomElement Component::saveGuiDataToDomElement(QDomElement &rDomElement) { ModelObject::saveGuiDataToDomElement(rDomElement); - QDomElement guiStuff = rDomElement.firstChildElement(HMF_HOPSANGUITAG); + QDomElement guiStuff = rDomElement.firstChildElement(hmf::hopsangui); QDomElement xmlApp = appendOrGetCAFRootTag(guiStuff); SharedModelObjectAppearanceT pLibraryAppearance = gpLibraryHandler->getModelObjectAppearancePtr(getTypeName(), getSubTypeName()); diff --git a/HopsanGUI/GUIObjects/GUIContainerObject.cpp b/HopsanGUI/GUIObjects/GUIContainerObject.cpp index 503cc58044..2c2761e20f 100644 --- a/HopsanGUI/GUIObjects/GUIContainerObject.cpp +++ b/HopsanGUI/GUIObjects/GUIContainerObject.cpp @@ -1548,22 +1548,22 @@ void SystemObject::copySelected(CopyStack *xmlStack) if(thisSystemsParameterNames.contains(var)) { CoreParameterData systemParameterData; getParameter(var, systemParameterData); - QDomElement xmlParameter = appendDomElement(*copyRoot, HMF_PARAMETERTAG); - xmlParameter.setAttribute(HMF_NAMETAG, systemParameterData.mName); - xmlParameter.setAttribute(HMF_VALUETAG, systemParameterData.mValue); - xmlParameter.setAttribute(HMF_TYPE, systemParameterData.mType); - xmlParameter.setAttribute(HMF_INTERNAL, systemParameterData.mInternal); + QDomElement xmlParameter = appendDomElement(*copyRoot, hmf::parameter::root); + xmlParameter.setAttribute(hmf::name, systemParameterData.mName); + xmlParameter.setAttribute(hmf::value, systemParameterData.mValue); + xmlParameter.setAttribute(hmf::type, systemParameterData.mType); + xmlParameter.setAttribute(hmf::internal, systemParameterData.mInternal); if (!systemParameterData.mQuantity.isEmpty()) { - xmlParameter.setAttribute(HMF_QUANTITY, systemParameterData.mQuantity); + xmlParameter.setAttribute(hmf::quantity, systemParameterData.mQuantity); } if (!systemParameterData.mUnit.isEmpty()) { - xmlParameter.setAttribute(HMF_UNIT, systemParameterData.mUnit); + xmlParameter.setAttribute(hmf::unit, systemParameterData.mUnit); } if (!systemParameterData.mDescription.isEmpty()) { - xmlParameter.setAttribute(HMF_DESCRIPTIONTAG, systemParameterData.mDescription); + xmlParameter.setAttribute(hmf::modelinfo::description, systemParameterData.mDescription); } } } @@ -1627,7 +1627,7 @@ void SystemObject::paste(CopyStack *xmlStack) QHash renamedMap; // Determine paste offset (will paste components at mouse position - QDomElement coordTag = copyRoot->firstChildElement(HMF_COORDINATETAG); + QDomElement coordTag = copyRoot->firstChildElement(hmf::connector::coordinate); double x, y; parseCoordinateTag(coordTag, x, y); QPointF oldCenter(x, y); @@ -1655,7 +1655,7 @@ void SystemObject::paste(CopyStack *xmlStack) const auto prevPos = pObj->pos(); pObj->moveBy(offset.x(), offset.y()); // Map renamed components - const QString desiredName = objectElement.attribute(HMF_NAMETAG); + const QString desiredName = objectElement.attribute(hmf::name); const QString actualNameAfterLoad = pObj->getName(); renamedMap.insert(desiredName, {actualNameAfterLoad, false}); didPaste = true; @@ -1678,7 +1678,7 @@ void SystemObject::paste(CopyStack *xmlStack) const auto prevPos = pObj->pos(); pObj->moveBy(offset.x(), offset.y()); // Map renamed components - const QString desiredName = systemPortElement.attribute(HMF_NAMETAG); + const QString desiredName = systemPortElement.attribute(hmf::name); const QString actualNameAfterLoad = pObj->getName(); renamedMap.insert(desiredName, {actualNameAfterLoad, true}); didPaste = true; @@ -1688,38 +1688,38 @@ void SystemObject::paste(CopyStack *xmlStack) } // Paste connectors - QDomElement connectorElement = copyRoot->firstChildElement(HMF_CONNECTORTAG); + QDomElement connectorElement = copyRoot->firstChildElement(hmf::connector::root); while(!connectorElement.isNull()) { QDomElement tempConnectorElement = connectorElement.cloneNode(true).toElement(); - const RenamedCompOrSysport actualStartComp = renamedMap.value(connectorElement.attribute(HMF_CONNECTORSTARTCOMPONENTTAG)); - const RenamedCompOrSysport actualEndComp = renamedMap.value(connectorElement.attribute(HMF_CONNECTORENDCOMPONENTTAG)); + const RenamedCompOrSysport actualStartComp = renamedMap.value(connectorElement.attribute(hmf::connector::startcomponent)); + const RenamedCompOrSysport actualEndComp = renamedMap.value(connectorElement.attribute(hmf::connector::endcomponent)); // Replace component names with actual names - tempConnectorElement.setAttribute(HMF_CONNECTORSTARTCOMPONENTTAG, actualStartComp.actualName); - tempConnectorElement.setAttribute(HMF_CONNECTORENDCOMPONENTTAG, actualEndComp.actualName); + tempConnectorElement.setAttribute(hmf::connector::startcomponent, actualStartComp.actualName); + tempConnectorElement.setAttribute(hmf::connector::endcomponent, actualEndComp.actualName); // Replace system port port names with actual names if (actualStartComp.isSystemPort) { - tempConnectorElement.setAttribute(HMF_CONNECTORSTARTPORTTAG, actualStartComp.actualName); + tempConnectorElement.setAttribute(hmf::connector::startport, actualStartComp.actualName); } if (actualEndComp.isSystemPort) { - tempConnectorElement.setAttribute(HMF_CONNECTORENDPORTTAG, actualStartComp.actualName); + tempConnectorElement.setAttribute(hmf::connector::endport, actualStartComp.actualName); } bool sucess = loadConnector(tempConnectorElement, this, Undo); if (sucess) { - Connector *tempConnector = this->findConnector(tempConnectorElement.attribute(HMF_CONNECTORSTARTCOMPONENTTAG), tempConnectorElement.attribute(HMF_CONNECTORSTARTPORTTAG), - tempConnectorElement.attribute(HMF_CONNECTORENDCOMPONENTTAG), tempConnectorElement.attribute(HMF_CONNECTORENDPORTTAG)); + Connector *tempConnector = this->findConnector(tempConnectorElement.attribute(hmf::connector::startcomponent), tempConnectorElement.attribute(hmf::connector::startport), + tempConnectorElement.attribute(hmf::connector::endcomponent), tempConnectorElement.attribute(hmf::connector::endport)); // Apply offset to connector tempConnector->moveAllPoints(offset.x(), offset.y()); tempConnector->drawConnector(true); didPaste = true; } - connectorElement = connectorElement.nextSiblingElement(HMF_CONNECTORTAG); + connectorElement = connectorElement.nextSiblingElement(hmf::connector::root); } - // Paste text box widgets - QDomElement textBoxElement = copyRoot->firstChildElement(HMF_TEXTBOXWIDGETTAG); + // Paste widgets + QDomElement textBoxElement = copyRoot->firstChildElement(hmf::widget::textboxwidget); while(!textBoxElement.isNull()) { TextBoxWidget *pWidget = loadTextBoxWidget(textBoxElement, this, Undo); @@ -1730,11 +1730,11 @@ void SystemObject::paste(CopyStack *xmlStack) didPaste = true; mpUndoStack->registerMovedWidget(pWidget, prevPos, pWidget->pos()); } - textBoxElement = textBoxElement.nextSiblingElement(HMF_TEXTBOXWIDGETTAG); + textBoxElement = textBoxElement.nextSiblingElement(hmf::widget::textboxwidget); } // Paste image widgets - QDomElement imageElement = copyRoot->firstChildElement(hmf::imagewidget); + QDomElement imageElement = copyRoot->firstChildElement(hmf::widget::imagewidget); while(!imageElement.isNull()) { ImageWidget *pWidget = loadImageWidget(imageElement, this, Undo); @@ -1745,27 +1745,27 @@ void SystemObject::paste(CopyStack *xmlStack) didPaste = true; mpUndoStack->registerMovedWidget(pWidget, prevPos, pWidget->pos()); } - imageElement = imageElement.nextSiblingElement(hmf::imagewidget); + imageElement = imageElement.nextSiblingElement(hmf::widget::imagewidget); } // Paste system parameters - QDomElement parElement = copyRoot->firstChildElement(HMF_PARAMETERTAG); + QDomElement parElement = copyRoot->firstChildElement(hmf::parameter::root); while(!parElement.isNull()) { - QString name = parElement.attribute(HMF_NAMETAG); + QString name = parElement.attribute(hmf::name); if(!getParameterNames().contains(name)) { - QString value = parElement.attribute(HMF_VALUETAG); - QString type = parElement.attribute(HMF_TYPE); - QString quantityORunit = parElement.attribute(HMF_QUANTITY, parElement.attribute(HMF_UNIT)); - QString description = parElement.attribute(HMF_DESCRIPTIONTAG); - bool internal = parseAttributeBool(parElement, HMF_INTERNAL, false); + QString value = parElement.attribute(hmf::value); + QString type = parElement.attribute(hmf::type); + QString quantityORunit = parElement.attribute(hmf::quantity, parElement.attribute(hmf::unit)); + QString description = parElement.attribute(hmf::modelinfo::description); + bool internal = parseAttributeBool(parElement, hmf::internal, false); CoreParameterData parData = CoreParameterData(name, value, type, quantityORunit, "", description, internal); setOrAddParameter(parData); didPaste = true; } - parElement = parElement.nextSiblingElement(HMF_PARAMETERTAG); + parElement = parElement.nextSiblingElement(hmf::parameter::root); } if (didPaste) { @@ -2024,7 +2024,7 @@ void SystemObject::replaceComponent(QString name, QString newType) renameModelObject(newObj->getName(), name); //Paste connectors - QDomElement connectorElement = copyRoot->firstChildElement(HMF_CONNECTORTAG); + QDomElement connectorElement = copyRoot->firstChildElement(hmf::connector::root); while(!connectorElement.isNull()) { bool sucess = loadConnector(connectorElement, this, Undo); @@ -3157,12 +3157,12 @@ void SystemObject::plotMeasuredSimulationTime() void SystemObject::exportMesasuredSimulationTime() { //! @todo Ask for filename - QString pathStr = QFileDialog::getSaveFileName(gpMainWindowWidget, "Save measured simulation times", gpConfig->getStringSetting(CFG_PLOTDATADIR), "*.csv"); + QString pathStr = QFileDialog::getSaveFileName(gpMainWindowWidget, "Save measured simulation times", gpConfig->getStringSetting(cfg::dir::plotdata), "*.csv"); if(pathStr.isEmpty()) return; //User aborted - gpConfig->setStringSetting(CFG_PLOTDATADIR, QFileInfo(pathStr).absolutePath()); + gpConfig->setStringSetting(cfg::dir::plotdata, QFileInfo(pathStr).absolutePath()); QFile csvFile(pathStr); @@ -3294,12 +3294,12 @@ void SystemObject::exportToLabView() //Open file dialogue and initialize the file stream QString filePath; filePath = QFileDialog::getSaveFileName(gpMainWindowWidget, tr("Export Project to HopsanRT Wrapper Code"), - gpConfig->getStringSetting(CFG_LABVIEWEXPORTDIR), + gpConfig->getStringSetting(cfg::dir::labviewexport), tr("C++ Source File (*.cpp)")); if(filePath.isEmpty()) return; //Don't save anything if user presses cancel QFileInfo file(filePath); - gpConfig->setStringSetting(CFG_LABVIEWEXPORTDIR, file.absolutePath()); + gpConfig->setStringSetting(cfg::dir::labviewexport, file.absolutePath()); auto spGenerator = createDefaultExportGenerator(); if (!spGenerator->generateToLabViewSIT(filePath, mpCoreSystemAccess->getCoreSystemPtr())) @@ -3347,14 +3347,14 @@ void SystemObject::exportToFMU(QString savePath, int version, ArchitectureEnumT //Open file dialogue and initialize the file stream QDir fileDialogSaveDir; savePath = QFileDialog::getExistingDirectory(gpMainWindowWidget, tr("Create Functional Mockup Unit"), - gpConfig->getStringSetting(CFG_FMUEXPORTDIR), + gpConfig->getStringSetting(cfg::dir::fmuexport), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if(savePath.isEmpty()) return; //Don't save anything if user presses cancel QDir saveDir; saveDir.setPath(savePath); - gpConfig->setStringSetting(CFG_FMUEXPORTDIR, saveDir.absolutePath()); + gpConfig->setStringSetting(cfg::dir::fmuexport, saveDir.absolutePath()); saveDir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot); if(!saveDir.entryList().isEmpty()) { @@ -3495,12 +3495,12 @@ void SystemObject::exportToSimulink() //Open file dialogue and initialize the file stream QString savePath; savePath = QFileDialog::getExistingDirectory(gpMainWindowWidget, tr("Create Simulink Source Files"), - gpConfig->getStringSetting(CFG_SIMULINKEXPORTDIR), + gpConfig->getStringSetting(cfg::dir::simulinkexport), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if(savePath.isEmpty()) return; //Don't save anything if user presses cancel QFileInfo file(savePath); - gpConfig->setStringSetting(CFG_SIMULINKEXPORTDIR, file.absolutePath()); + gpConfig->setStringSetting(cfg::dir::simulinkexport, file.absolutePath()); // Save xml document mpModelWidget->saveTo(savePath+"/"+fileName); @@ -3554,14 +3554,14 @@ void SystemObject::exportToExecutableModel(QString savePath, ArchitectureEnumT a //Open file dialog and initialize the file stream QDir fileDialogSaveDir; savePath = QFileDialog::getExistingDirectory(gpMainWindowWidget, tr("Compile Executable Model"), - gpConfig->getStringSetting(CFG_EXEEXPORTDIR), + gpConfig->getStringSetting(cfg::dir::exeexport), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if(savePath.isEmpty()) return; //Don't save anything if user presses cancel QDir saveDir; saveDir.setPath(savePath); - gpConfig->setStringSetting(CFG_EXEEXPORTDIR, saveDir.absolutePath()); + gpConfig->setStringSetting(cfg::dir::exeexport, saveDir.absolutePath()); saveDir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot); if(!saveDir.entryList().isEmpty()) { @@ -3755,7 +3755,7 @@ void SystemObject::saveCoreDataToDomElement(QDomElement &rDomElement, SaveConten // This information should ONLY be used to indicate that a subsystem is external, it SHOULD NOT be included in the actual external system // If it would be, the load function will fail - rDomElement.setAttribute( HMF_EXTERNALPATHTAG, relPath ); + rDomElement.setAttribute( hmf::externalpath, relPath ); } if (mLoadType != "EXTERNAL" && contents == FullModel) @@ -3767,43 +3767,43 @@ void SystemObject::saveCoreDataToDomElement(QDomElement &rDomElement, SaveConten // Save the NumHop script if (!mNumHopScript.isEmpty()) { - appendDomTextNode(rDomElement, HMF_NUMHOPSCRIPT, mNumHopScript); + appendDomTextNode(rDomElement, hmf::numhopscript, mNumHopScript); } // Save the parameter values for the system QVector paramDataVector; this->getParameters(paramDataVector); - QDomElement xmlParameters = appendDomElement(rDomElement, HMF_PARAMETERS); + QDomElement xmlParameters = appendDomElement(rDomElement, hmf::parameters); for(int i=0; igetStringSetting(CFG_SUBSYSTEMDIR), + gpConfig->getStringSetting(cfg::dir::subsystem), tr("Hopsan Model Files (*.hmf)")); if (!modelFilePath.isNull()) { QFile file; file.setFileName(modelFilePath); QFileInfo fileInfo(file); - gpConfig->setStringSetting(CFG_SUBSYSTEMDIR, fileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::subsystem, fileInfo.absolutePath()); bool doIt = true; if (mModelObjectMap.size() > 0) @@ -3887,7 +3887,7 @@ void SystemObject::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) //Get file name QString modelFilePath; modelFilePath = QFileDialog::getSaveFileName(gpMainWindowWidget, tr("Save Subsystem As"), - gpConfig->getStringSetting(CFG_LOADMODELDIR), + gpConfig->getStringSetting(cfg::dir::loadmodel), tr("Hopsan Model Files (*.hmf)")); if(modelFilePath.isEmpty()) //Don't save anything if user presses cancel @@ -3940,7 +3940,7 @@ void SystemObject::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) //Get file name QString cafFilePath; cafFilePath = QFileDialog::getSaveFileName(gpMainWindowWidget, tr("Save Subsystem As"), - gpConfig->getStringSetting(CFG_LOADMODELDIR), + gpConfig->getStringSetting(cfg::dir::loadmodel), tr("Hopsan Component Appearance Files (*.xml)")); if(cafFilePath.isEmpty()) //Don't save anything if user presses cancel @@ -4066,38 +4066,38 @@ void SystemObject::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) void SystemObject::saveSensitivityAnalysisSettingsToDomElement(QDomElement &rDomElement) { - QDomElement XMLsens = appendDomElement(rDomElement, HMF_SENSITIVITYANALYSIS); - QDomElement XMLsetting = appendDomElement(XMLsens, HMF_SETTINGS); - appendDomIntegerNode(XMLsetting, HMF_ITERATIONS, mSensSettings.nIter); + QDomElement XMLsens = appendDomElement(rDomElement, hmf::sensitivityanalysis::root); + QDomElement XMLsetting = appendDomElement(XMLsens, hmf::sensitivityanalysis::settings); + appendDomIntegerNode(XMLsetting, hmf::sensitivityanalysis::iterations, mSensSettings.nIter); if(mSensSettings.distribution == SensitivityAnalysisSettings::UniformDistribution) { - appendDomTextNode(XMLsetting, HMF_DISTRIBUTIONTYPE, HMF_UNIFORMDIST); + appendDomTextNode(XMLsetting, hmf::sensitivityanalysis::distribution, hmf::sensitivityanalysis::uniformdistribution); } else if(mSensSettings.distribution == SensitivityAnalysisSettings::NormalDistribution) { - appendDomTextNode(XMLsetting, HMF_DISTRIBUTIONTYPE, HMF_NORMALDIST); + appendDomTextNode(XMLsetting, hmf::sensitivityanalysis::distribution, hmf::sensitivityanalysis::normaldistribution); } //Parameters - QDomElement XMLparameters = appendDomElement(XMLsens, HMF_PARAMETERS); + QDomElement XMLparameters = appendDomElement(XMLsens, hmf::parameters); for(int i = 0; i < mSensSettings.parameters.size(); ++i) { - QDomElement XMLparameter = appendDomElement(XMLparameters, HMF_PARAMETERTAG); + QDomElement XMLparameter = appendDomElement(XMLparameters, hmf::parameter::root); appendDomTextNode(XMLparameter, hmf::component, mSensSettings.parameters.at(i).compName); - appendDomTextNode(XMLparameter, HMF_PARAMETERTAG, mSensSettings.parameters.at(i).parName); - appendDomValueNode2(XMLparameter, HMF_MINMAX, mSensSettings.parameters.at(i).min, mSensSettings.parameters.at(i).max); - appendDomValueNode(XMLparameter, HMF_AVERAGE, mSensSettings.parameters.at(i).aver); - appendDomValueNode(XMLparameter, HMF_SIGMA, mSensSettings.parameters.at(i).sigma); + appendDomTextNode(XMLparameter, hmf::parameter::root, mSensSettings.parameters.at(i).parName); + appendDomValueNode2(XMLparameter, hmf::sensitivityanalysis::minmax, mSensSettings.parameters.at(i).min, mSensSettings.parameters.at(i).max); + appendDomValueNode(XMLparameter, hmf::sensitivityanalysis::average, mSensSettings.parameters.at(i).aver); + appendDomValueNode(XMLparameter, hmf::sensitivityanalysis::sigma, mSensSettings.parameters.at(i).sigma); } //Variables - QDomElement XMLobjectives = appendDomElement(XMLsens, HMF_PLOTVARIABLES); + QDomElement XMLobjectives = appendDomElement(XMLsens, hmf::sensitivityanalysis::plotvariables); for(int i = 0; i < mSensSettings.variables.size(); ++i) { - QDomElement XMLobjective = appendDomElement(XMLobjectives, HMF_PLOTVARIABLE); + QDomElement XMLobjective = appendDomElement(XMLobjectives, hmf::sensitivityanalysis::plotvariable); appendDomTextNode(XMLobjective, hmf::component, mSensSettings.variables.at(i).compName); - appendDomTextNode(XMLobjective, HMF_PORTTAG, mSensSettings.variables.at(i).portName); - appendDomTextNode(XMLobjective, HMF_PLOTVARIABLE, mSensSettings.variables.at(i).varName); + appendDomTextNode(XMLobjective, hmf::port, mSensSettings.variables.at(i).portName); + appendDomTextNode(XMLobjective, hmf::sensitivityanalysis::plotvariable, mSensSettings.variables.at(i).varName); } } @@ -4106,53 +4106,53 @@ void SystemObject::loadSensitivityAnalysisSettingsFromDomElement(QDomElement &rD { qDebug() << rDomElement.toDocument().toString(); - QDomElement settingsElement = rDomElement.firstChildElement(HMF_SETTINGS); + QDomElement settingsElement = rDomElement.firstChildElement(hmf::sensitivityanalysis::settings); if(!settingsElement.isNull()) { - mSensSettings.nIter = parseDomIntegerNode(settingsElement.firstChildElement(HMF_ITERATIONS), mSensSettings.nIter); - QDomElement distElement = settingsElement.firstChildElement(HMF_DISTRIBUTIONTYPE); - if(!distElement.isNull() && distElement.text() == HMF_UNIFORMDIST) + mSensSettings.nIter = parseDomIntegerNode(settingsElement.firstChildElement(hmf::sensitivityanalysis::iterations), mSensSettings.nIter); + QDomElement distElement = settingsElement.firstChildElement(hmf::sensitivityanalysis::distribution); + if(!distElement.isNull() && distElement.text() == hmf::sensitivityanalysis::uniformdistribution) { mSensSettings.distribution = SensitivityAnalysisSettings::UniformDistribution; } - else if(!distElement.isNull() && distElement.text() == HMF_NORMALDIST) + else if(!distElement.isNull() && distElement.text() == hmf::sensitivityanalysis::normaldistribution) { mSensSettings.distribution = SensitivityAnalysisSettings::NormalDistribution; } } - QDomElement parametersElement = rDomElement.firstChildElement(HMF_PARAMETERS); + QDomElement parametersElement = rDomElement.firstChildElement(hmf::parameters); if(!parametersElement.isNull()) { - QDomElement parameterElement =parametersElement.firstChildElement(HMF_PARAMETERTAG); + QDomElement parameterElement =parametersElement.firstChildElement(hmf::parameter::root); while (!parameterElement.isNull()) { SensitivityAnalysisParameter par; par.compName = parameterElement.firstChildElement(hmf::component).text(); - par.parName = parameterElement.firstChildElement(HMF_PARAMETERTAG).text(); - parseDomValueNode2(parameterElement.firstChildElement(HMF_MINMAX), par.min, par.max); - par.aver = parseDomValueNode(parameterElement.firstChildElement(HMF_AVERAGE), 0); - par.sigma = parseDomValueNode(parameterElement.firstChildElement(HMF_SIGMA), 0); + par.parName = parameterElement.firstChildElement(hmf::parameter::root).text(); + parseDomValueNode2(parameterElement.firstChildElement(hmf::sensitivityanalysis::minmax), par.min, par.max); + par.aver = parseDomValueNode(parameterElement.firstChildElement(hmf::sensitivityanalysis::average), 0); + par.sigma = parseDomValueNode(parameterElement.firstChildElement(hmf::sensitivityanalysis::sigma), 0); mSensSettings.parameters.append(par); - parameterElement = parameterElement.nextSiblingElement(HMF_PARAMETERTAG); + parameterElement = parameterElement.nextSiblingElement(hmf::parameter::root); } } - QDomElement variablesElement = rDomElement.firstChildElement(HMF_PLOTVARIABLES); + QDomElement variablesElement = rDomElement.firstChildElement(hmf::sensitivityanalysis::plotvariables); if(!variablesElement.isNull()) { - QDomElement variableElement = variablesElement.firstChildElement(HMF_PLOTVARIABLE); + QDomElement variableElement = variablesElement.firstChildElement(hmf::sensitivityanalysis::plotvariable); while (!variableElement.isNull()) { SensitivityAnalysisVariable var; var.compName = variableElement.firstChildElement(hmf::component).text(); - var.portName = variableElement.firstChildElement(HMF_PORTTAG).text(); - var.varName = variableElement.firstChildElement(HMF_PLOTVARIABLE).text(); + var.portName = variableElement.firstChildElement(hmf::port).text(); + var.varName = variableElement.firstChildElement(hmf::sensitivityanalysis::plotvariable).text(); mSensSettings.variables.append(var); - variableElement = variableElement.nextSiblingElement((HMF_PLOTVARIABLE)); + variableElement = variableElement.nextSiblingElement((hmf::sensitivityanalysis::plotvariable)); } } } @@ -4160,59 +4160,59 @@ void SystemObject::loadSensitivityAnalysisSettingsFromDomElement(QDomElement &rD void SystemObject::saveOptimizationSettingsToDomElement(QDomElement &rDomElement) { - QDomElement XMLopt = appendDomElement(rDomElement, HMF_OPTIMIZATION); - QDomElement XMLsetting = appendDomElement(XMLopt, HMF_SETTINGS); - appendDomTextNode(XMLsetting, HMF_SCRIPTFILETAG, mOptSettings.mScriptFile); - appendDomIntegerNode(XMLsetting, HMF_ITERATIONS, mOptSettings.mNiter); - appendDomIntegerNode(XMLsetting, HMF_SEARCHPOINTS, mOptSettings.mNsearchp); - appendDomValueNode(XMLsetting, HMF_REFLCOEFF, mOptSettings.mRefcoeff); - appendDomValueNode(XMLsetting, HMF_RANDOMFACTOR, mOptSettings.mRandfac); - appendDomValueNode(XMLsetting, HMF_FORGETTINGFACTOR, mOptSettings.mForgfac); - appendDomValueNode(XMLsetting, HMF_PARTOL, mOptSettings.mPartol); - appendDomBooleanNode(XMLsetting, HMF_PLOT, mOptSettings.mPlot); - appendDomBooleanNode(XMLsetting, HMF_SAVECSV, mOptSettings.mSavecsv); - appendDomBooleanNode(XMLsetting, HMF_FINALEVAL, mOptSettings.mFinalEval); + QDomElement XMLopt = appendDomElement(rDomElement, hmf::optimization::root); + QDomElement XMLsetting = appendDomElement(XMLopt, hmf::sensitivityanalysis::settings); + appendDomTextNode(XMLsetting, hmf::scriptfile, mOptSettings.mScriptFile); + appendDomIntegerNode(XMLsetting, hmf::sensitivityanalysis::iterations, mOptSettings.mNiter); + appendDomIntegerNode(XMLsetting, hmf::optimization::numberofsearchpoints, mOptSettings.mNsearchp); + appendDomValueNode(XMLsetting, hmf::optimization::reflectioncoefficient, mOptSettings.mRefcoeff); + appendDomValueNode(XMLsetting, hmf::optimization::randomfactor, mOptSettings.mRandfac); + appendDomValueNode(XMLsetting, hmf::optimization::forgettingfactor, mOptSettings.mForgfac); + appendDomValueNode(XMLsetting, hmf::optimization::partol, mOptSettings.mPartol); + appendDomBooleanNode(XMLsetting, hmf::optimization::plot, mOptSettings.mPlot); + appendDomBooleanNode(XMLsetting, hmf::optimization::savecsv, mOptSettings.mSavecsv); + appendDomBooleanNode(XMLsetting, hmf::optimization::finaleval, mOptSettings.mFinalEval); //Parameters - appendDomBooleanNode(XMLsetting, HMF_LOGPAR, mOptSettings.mlogPar); - QDomElement XMLparameters = appendDomElement(XMLopt, HMF_PARAMETERS); + appendDomBooleanNode(XMLsetting, hmf::optimization::logpar, mOptSettings.mlogPar); + QDomElement XMLparameters = appendDomElement(XMLopt, hmf::parameters); for(int i = 0; i < mOptSettings.mParamters.size(); ++i) { - QDomElement XMLparameter = appendDomElement(XMLparameters, HMF_PARAMETERTAG); + QDomElement XMLparameter = appendDomElement(XMLparameters, hmf::parameter::root); appendDomTextNode(XMLparameter, hmf::component, mOptSettings.mParamters.at(i).mComponentName); - appendDomTextNode(XMLparameter, HMF_PARAMETERTAG, mOptSettings.mParamters.at(i).mParameterName); - appendDomValueNode2(XMLparameter, HMF_MINMAX, mOptSettings.mParamters.at(i).mMin, mOptSettings.mParamters.at(i).mMax); + appendDomTextNode(XMLparameter, hmf::parameter::root, mOptSettings.mParamters.at(i).mParameterName); + appendDomValueNode2(XMLparameter, hmf::sensitivityanalysis::minmax, mOptSettings.mParamters.at(i).mMin, mOptSettings.mParamters.at(i).mMax); } //Objective Functions - QDomElement XMLobjectives = appendDomElement(XMLopt, HMF_OBJECTIVES); + QDomElement XMLobjectives = appendDomElement(XMLopt, hmf::optimization::objectives); for(int i = 0; i < mOptSettings.mObjectives.size(); ++i) { - QDomElement XMLobjective = appendDomElement(XMLobjectives, HMF_OBJECTIVE); - appendDomTextNode(XMLobjective, HMF_FUNCNAME, mOptSettings.mObjectives.at(i).mFunctionName); - appendDomValueNode(XMLobjective, HMF_WEIGHT, mOptSettings.mObjectives.at(i).mWeight); - appendDomValueNode(XMLobjective, HMF_NORM, mOptSettings.mObjectives.at(i).mNorm); - appendDomValueNode(XMLobjective, HMF_EXP, mOptSettings.mObjectives.at(i).mExp); + QDomElement XMLobjective = appendDomElement(XMLobjectives, hmf::optimization::objective); + appendDomTextNode(XMLobjective, hmf::optimization::functionname, mOptSettings.mObjectives.at(i).mFunctionName); + appendDomValueNode(XMLobjective, hmf::optimization::weight, mOptSettings.mObjectives.at(i).mWeight); + appendDomValueNode(XMLobjective, hmf::optimization::norm, mOptSettings.mObjectives.at(i).mNorm); + appendDomValueNode(XMLobjective, hmf::optimization::exp, mOptSettings.mObjectives.at(i).mExp); - QDomElement XMLObjectiveVariables = appendDomElement(XMLobjective, HMF_PLOTVARIABLES); + QDomElement XMLObjectiveVariables = appendDomElement(XMLobjective, hmf::sensitivityanalysis::plotvariables); if(!(mOptSettings.mObjectives.at(i).mVariableInfo.isEmpty())) { for(int j = 0; j < mOptSettings.mObjectives.at(i).mVariableInfo.size(); ++j) { - QDomElement XMLObjectiveVariable = appendDomElement(XMLObjectiveVariables, HMF_PLOTVARIABLE); + QDomElement XMLObjectiveVariable = appendDomElement(XMLObjectiveVariables, hmf::sensitivityanalysis::plotvariable); appendDomTextNode(XMLObjectiveVariable, hmf::component, mOptSettings.mObjectives.at(i).mVariableInfo.at(j).at(0)); - appendDomTextNode(XMLObjectiveVariable, HMF_PORTTAG, mOptSettings.mObjectives.at(i).mVariableInfo.at(j).at(1)); - appendDomTextNode(XMLObjectiveVariable, HMF_PLOTVARIABLE, mOptSettings.mObjectives.at(i).mVariableInfo.at(j).at(2)); + appendDomTextNode(XMLObjectiveVariable, hmf::port, mOptSettings.mObjectives.at(i).mVariableInfo.at(j).at(1)); + appendDomTextNode(XMLObjectiveVariable, hmf::sensitivityanalysis::plotvariable, mOptSettings.mObjectives.at(i).mVariableInfo.at(j).at(2)); } } if(!(mOptSettings.mObjectives.at(i).mData.isEmpty())) { - QDomElement XMLdata = appendDomElement(XMLobjective, HMF_DATA); + QDomElement XMLdata = appendDomElement(XMLobjective, hmf::optimization::data); for(int j = 0; j < mOptSettings.mObjectives.at(i).mData.size(); ++j) { - appendDomTextNode(XMLdata, HMF_PARAMETERTAG, mOptSettings.mObjectives.at(i).mData.at(j)); + appendDomTextNode(XMLdata, hmf::parameter::root, mOptSettings.mObjectives.at(i).mData.at(j)); } } } @@ -4223,82 +4223,82 @@ void SystemObject::loadOptimizationSettingsFromDomElement(QDomElement &rDomEleme { qDebug() << rDomElement.toDocument().toString(); - QDomElement settingsElement = rDomElement.firstChildElement(HMF_SETTINGS); + QDomElement settingsElement = rDomElement.firstChildElement(hmf::sensitivityanalysis::settings); if(!settingsElement.isNull()) { - mOptSettings.mScriptFile = parseDomStringNode(settingsElement.firstChildElement(HMF_SCRIPTFILETAG), mOptSettings.mScriptFile); - mOptSettings.mNiter = parseDomIntegerNode(settingsElement.firstChildElement(HMF_ITERATIONS), mOptSettings.mNiter); - mOptSettings.mNsearchp = parseDomIntegerNode(settingsElement.firstChildElement(HMF_SEARCHPOINTS), mOptSettings.mNsearchp); - mOptSettings.mRefcoeff = parseDomValueNode(settingsElement.firstChildElement(HMF_REFLCOEFF), mOptSettings.mRefcoeff); - mOptSettings.mRandfac = parseDomValueNode(settingsElement.firstChildElement(HMF_RANDOMFACTOR), mOptSettings.mRandfac); - mOptSettings.mForgfac = parseDomValueNode(settingsElement.firstChildElement(HMF_FORGETTINGFACTOR), mOptSettings.mForgfac); - mOptSettings.mPartol = parseDomValueNode(settingsElement.firstChildElement(HMF_PARTOL), mOptSettings.mPartol); - mOptSettings.mPlot = parseDomBooleanNode(settingsElement.firstChildElement(HMF_PLOT), mOptSettings.mPlot); - mOptSettings.mSavecsv = parseDomBooleanNode(settingsElement.firstChildElement(HMF_SAVECSV), mOptSettings.mSavecsv); - mOptSettings.mFinalEval = parseDomBooleanNode(settingsElement.firstChildElement(HMF_FINALEVAL), mOptSettings.mFinalEval); - mOptSettings.mlogPar = parseDomBooleanNode(settingsElement.firstChildElement(HMF_LOGPAR), mOptSettings.mlogPar); + mOptSettings.mScriptFile = parseDomStringNode(settingsElement.firstChildElement(hmf::scriptfile), mOptSettings.mScriptFile); + mOptSettings.mNiter = parseDomIntegerNode(settingsElement.firstChildElement(hmf::sensitivityanalysis::iterations), mOptSettings.mNiter); + mOptSettings.mNsearchp = parseDomIntegerNode(settingsElement.firstChildElement(hmf::optimization::numberofsearchpoints), mOptSettings.mNsearchp); + mOptSettings.mRefcoeff = parseDomValueNode(settingsElement.firstChildElement(hmf::optimization::reflectioncoefficient), mOptSettings.mRefcoeff); + mOptSettings.mRandfac = parseDomValueNode(settingsElement.firstChildElement(hmf::optimization::randomfactor), mOptSettings.mRandfac); + mOptSettings.mForgfac = parseDomValueNode(settingsElement.firstChildElement(hmf::optimization::forgettingfactor), mOptSettings.mForgfac); + mOptSettings.mPartol = parseDomValueNode(settingsElement.firstChildElement(hmf::optimization::partol), mOptSettings.mPartol); + mOptSettings.mPlot = parseDomBooleanNode(settingsElement.firstChildElement(hmf::optimization::plot), mOptSettings.mPlot); + mOptSettings.mSavecsv = parseDomBooleanNode(settingsElement.firstChildElement(hmf::optimization::savecsv), mOptSettings.mSavecsv); + mOptSettings.mFinalEval = parseDomBooleanNode(settingsElement.firstChildElement(hmf::optimization::finaleval), mOptSettings.mFinalEval); + mOptSettings.mlogPar = parseDomBooleanNode(settingsElement.firstChildElement(hmf::optimization::logpar), mOptSettings.mlogPar); } - QDomElement parametersElement = rDomElement.firstChildElement(HMF_PARAMETERS); + QDomElement parametersElement = rDomElement.firstChildElement(hmf::parameters); if(!parametersElement.isNull()) { - QDomElement parameterElement = parametersElement.firstChildElement(HMF_PARAMETERTAG); + QDomElement parameterElement = parametersElement.firstChildElement(hmf::parameter::root); while (!parameterElement.isNull()) { OptParameter parameter; parameter.mComponentName = parameterElement.firstChildElement(hmf::component).text(); - parameter.mParameterName = parameterElement.firstChildElement(HMF_PARAMETERTAG).text(); - parseDomValueNode2(parameterElement.firstChildElement(HMF_MINMAX), parameter.mMin, parameter.mMax); + parameter.mParameterName = parameterElement.firstChildElement(hmf::parameter::root).text(); + parseDomValueNode2(parameterElement.firstChildElement(hmf::sensitivityanalysis::minmax), parameter.mMin, parameter.mMax); mOptSettings.mParamters.append(parameter); - parameterElement = parameterElement.nextSiblingElement(HMF_PARAMETERTAG); + parameterElement = parameterElement.nextSiblingElement(hmf::parameter::root); } } - QDomElement objectivesElement = rDomElement.firstChildElement(HMF_OBJECTIVES); + QDomElement objectivesElement = rDomElement.firstChildElement(hmf::optimization::objectives); if(!objectivesElement.isNull()) { - QDomElement objElement = objectivesElement.firstChildElement(HMF_OBJECTIVE); + QDomElement objElement = objectivesElement.firstChildElement(hmf::optimization::objective); while (!objElement.isNull()) { Objectives objectives; - objectives.mFunctionName = objElement.firstChildElement(HMF_FUNCNAME).text(); - objectives.mWeight = objElement.firstChildElement(HMF_WEIGHT).text().toDouble(); - objectives.mNorm = objElement.firstChildElement(HMF_NORM).text().toDouble(); - objectives.mExp = objElement.firstChildElement(HMF_EXP).text().toDouble(); + objectives.mFunctionName = objElement.firstChildElement(hmf::optimization::functionname).text(); + objectives.mWeight = objElement.firstChildElement(hmf::optimization::weight).text().toDouble(); + objectives.mNorm = objElement.firstChildElement(hmf::optimization::norm).text().toDouble(); + objectives.mExp = objElement.firstChildElement(hmf::optimization::exp).text().toDouble(); - QDomElement variablesElement = objElement.firstChildElement(HMF_PLOTVARIABLES); + QDomElement variablesElement = objElement.firstChildElement(hmf::sensitivityanalysis::plotvariables); if(!variablesElement.isNull()) { - QDomElement varElement = variablesElement.firstChildElement(HMF_PLOTVARIABLE); + QDomElement varElement = variablesElement.firstChildElement(hmf::sensitivityanalysis::plotvariable); while (!varElement.isNull()) { QStringList variableInfo; variableInfo.append(varElement.firstChildElement(hmf::component).text()); - variableInfo.append(varElement.firstChildElement(HMF_PORTTAG).text()); - variableInfo.append(varElement.firstChildElement(HMF_PLOTVARIABLE).text()); + variableInfo.append(varElement.firstChildElement(hmf::port).text()); + variableInfo.append(varElement.firstChildElement(hmf::sensitivityanalysis::plotvariable).text()); objectives.mVariableInfo.append(variableInfo); - varElement = varElement.nextSiblingElement(HMF_PLOTVARIABLE); + varElement = varElement.nextSiblingElement(hmf::sensitivityanalysis::plotvariable); } } - QDomElement dataElement = objElement.firstChildElement(HMF_DATA); + QDomElement dataElement = objElement.firstChildElement(hmf::optimization::data); if(!dataElement.isNull()) { - QDomElement parElement = dataElement.firstChildElement(HMF_PARAMETERTAG); + QDomElement parElement = dataElement.firstChildElement(hmf::parameter::root); while (!parElement.isNull()) { objectives.mData.append(parElement.text()); - parElement = parElement.nextSiblingElement(HMF_PARAMETERTAG); + parElement = parElement.nextSiblingElement(hmf::parameter::root); } } - objElement = objElement.nextSiblingElement(HMF_OBJECTIVE); + objElement = objElement.nextSiblingElement(hmf::optimization::objective); mOptSettings.mObjectives.append(objectives); } @@ -4337,8 +4337,8 @@ QDomElement SystemObject::saveGuiDataToDomElement(QDomElement &rDomElement) QDomElement guiStuff = ModelObject::saveGuiDataToDomElement(rDomElement); //Save animation disabled setting - QDomElement animationElement = guiStuff.firstChildElement(HMF_ANIMATION); - animationElement.setAttribute(HMF_DISABLEDTAG, bool2str(mAnimationDisabled)); + QDomElement animationElement = guiStuff.firstChildElement(hmf::animation); + animationElement.setAttribute(hmf::appearance::disabled, bool2str(mAnimationDisabled)); //Should we try to append appearancedata stuff, we don't want this in external systems as they contain their own appearance if (mLoadType!="EXTERNAL") @@ -4348,25 +4348,25 @@ QDomElement SystemObject::saveGuiDataToDomElement(QDomElement &rDomElement) getModelInfo(author, email, affiliation, description); if (!(author.isEmpty() && email.isEmpty() && affiliation.isEmpty() && description.isEmpty())) { - QDomElement infoElement = appendDomElement(guiStuff, HMF_INFOTAG); - appendDomTextNode(infoElement, HMF_AUTHORTAG, author); - appendDomTextNode(infoElement, HMF_EMAILTAG, email); - appendDomTextNode(infoElement, HMF_AFFILIATIONTAG, affiliation); - appendDomTextNode(infoElement, HMF_DESCRIPTIONTAG, description); + QDomElement infoElement = appendDomElement(guiStuff, hmf::modelinfo::root); + appendDomTextNode(infoElement, hmf::modelinfo::author, author); + appendDomTextNode(infoElement, hmf::modelinfo::email, email); + appendDomTextNode(infoElement, hmf::modelinfo::affiliation, affiliation); + appendDomTextNode(infoElement, hmf::modelinfo::description, description); } GraphicsViewPort vp = this->getGraphicsViewport(); appendViewPortTag(guiStuff, vp.mCenter.x(), vp.mCenter.y(), vp.mZoom); - QDomElement portsHiddenElement = appendDomElement(guiStuff, HMF_PORTSTAG); + QDomElement portsHiddenElement = appendDomElement(guiStuff, hmf::ports); portsHiddenElement.setAttribute("hidden", !mShowSubComponentPorts); - QDomElement namesHiddenElement = appendDomElement(guiStuff, HMF_NAMESTAG); + QDomElement namesHiddenElement = appendDomElement(guiStuff, hmf::names); namesHiddenElement.setAttribute("hidden", !mShowSubComponentNames); QString gfxType = "iso"; if(mGfxType == UserGraphics) gfxType = "user"; - QDomElement gfxTypeElement = appendDomElement(guiStuff, HMF_GFXTAG); + QDomElement gfxTypeElement = appendDomElement(guiStuff, hmf::appearance::graphics); gfxTypeElement.setAttribute("type", gfxType); this->refreshExternalPortsAppearanceAndPosition(); @@ -4494,7 +4494,7 @@ void SystemObject::saveToDomElement(QDomElement &rDomElement, SaveContentsEnumT } //Save the connectors - QDomElement xmlConnections = appendDomElement(xmlSubsystem, HMF_CONNECTIONS); + QDomElement xmlConnections = appendDomElement(xmlSubsystem, hmf::connections); for(int i=0; isaveToDomElement(xmlConnections); @@ -4536,60 +4536,60 @@ void SystemObject::saveToDomElement(QDomElement &rDomElement, SaveContentsEnumT void SystemObject::loadFromDomElement(QDomElement domElement) { // Loop back up to root level to get version numbers - QString hmfFormatVersion = domElement.ownerDocument().firstChildElement(hmf::root).attribute(HMF_VERSIONTAG, "0"); - QString coreHmfVersion = domElement.ownerDocument().firstChildElement(hmf::root).attribute(HMF_HOPSANCOREVERSIONTAG, "0"); + QString hmfFormatVersion = domElement.ownerDocument().firstChildElement(hmf::root).attribute(hmf::version::hmf, "0"); + QString coreHmfVersion = domElement.ownerDocument().firstChildElement(hmf::root).attribute(hmf::version::hopsancore, "0"); // Check if the subsystem is external or internal, and load appropriately - QString external_path = domElement.attribute(HMF_EXTERNALPATHTAG); + QString external_path = domElement.attribute(hmf::externalpath); if (external_path.isEmpty()) { // Load embedded subsystem // 0. Load core and gui stuff //! @todo might need some error checking here in case some fields are missing // Now load the core specific data, might need inherited function for this - this->setName(domElement.attribute(HMF_NAMETAG)); + this->setName(domElement.attribute(hmf::name)); // Load the NumHop script - setNumHopScript(parseDomStringNode(domElement.firstChildElement(HMF_NUMHOPSCRIPT), "")); + setNumHopScript(parseDomStringNode(domElement.firstChildElement(hmf::numhopscript), "")); // Begin loading GUI stuff like appearance data and viewport - QDomElement guiStuff = domElement.firstChildElement(HMF_HOPSANGUITAG); - mModelObjectAppearance.readFromDomElement(guiStuff.firstChildElement(CAF_ROOT).firstChildElement(CAF_MODELOBJECT)); + QDomElement guiStuff = domElement.firstChildElement(hmf::hopsangui); + mModelObjectAppearance.readFromDomElement(guiStuff.firstChildElement(caf::root).firstChildElement(caf::modelobject)); refreshDisplayName(); // This must be done because in some occasions the loadAppearanceData line above will overwrite the correct name - QDomElement animationElement = guiStuff.firstChildElement(HMF_ANIMATION); + QDomElement animationElement = guiStuff.firstChildElement(hmf::animation); bool animationDisabled = false; if(!animationElement.isNull()) { - animationDisabled = parseAttributeBool(animationElement, HMF_DISABLEDTAG, false); + animationDisabled = parseAttributeBool(animationElement, hmf::appearance::disabled, false); } setAnimationDisabled(animationDisabled); // Load system/model info - QDomElement infoElement = domElement.parentNode().firstChildElement(HMF_INFOTAG); //!< @deprecated info tag is in the system from 0.7.5 an onwards, this line loads from old models + QDomElement infoElement = domElement.parentNode().firstChildElement(hmf::modelinfo::root); //!< @deprecated info tag is in the system from 0.7.5 an onwards, this line loads from old models if (infoElement.isNull()) { - infoElement = guiStuff.firstChildElement(HMF_INFOTAG); + infoElement = guiStuff.firstChildElement(hmf::modelinfo::root); } if(!infoElement.isNull()) { QString author, email, affiliation, description; - QDomElement authorElement = infoElement.firstChildElement(HMF_AUTHORTAG); + QDomElement authorElement = infoElement.firstChildElement(hmf::modelinfo::author); if(!authorElement.isNull()) { author = authorElement.text(); } - QDomElement emailElement = infoElement.firstChildElement(HMF_EMAILTAG); + QDomElement emailElement = infoElement.firstChildElement(hmf::modelinfo::email); if(!emailElement.isNull()) { email = emailElement.text(); } - QDomElement affiliationElement = infoElement.firstChildElement(HMF_AFFILIATIONTAG); + QDomElement affiliationElement = infoElement.firstChildElement(hmf::modelinfo::affiliation); if(!affiliationElement.isNull()) { affiliation = affiliationElement.text(); } - QDomElement descriptionElement = infoElement.firstChildElement(HMF_DESCRIPTIONTAG); + QDomElement descriptionElement = infoElement.firstChildElement(hmf::modelinfo::description); if(!descriptionElement.isNull()) { description = descriptionElement.text(); @@ -4619,22 +4619,22 @@ void SystemObject::loadFromDomElement(QDomElement domElement) } // Continue loading GUI stuff like appearance data and viewport - this->mShowSubComponentNames = !parseAttributeBool(guiStuff.firstChildElement(HMF_NAMESTAG),"hidden",true); - this->mShowSubComponentPorts = !parseAttributeBool(guiStuff.firstChildElement(HMF_PORTSTAG),"hidden",true); - QString gfxType = guiStuff.firstChildElement(HMF_GFXTAG).attribute("type"); + this->mShowSubComponentNames = !parseAttributeBool(guiStuff.firstChildElement(hmf::names),"hidden",true); + this->mShowSubComponentPorts = !parseAttributeBool(guiStuff.firstChildElement(hmf::ports),"hidden",true); + QString gfxType = guiStuff.firstChildElement(hmf::appearance::graphics).attribute("type"); if(gfxType == "user") { mGfxType = UserGraphics; } else if(gfxType == "iso") { mGfxType = ISOGraphics; } //! @todo these two should not be set here gpToggleNamesAction->setChecked(mShowSubComponentNames); gpTogglePortsAction->setChecked(mShowSubComponentPorts); - double x = guiStuff.firstChildElement(HMF_VIEWPORTTAG).attribute("x").toDouble(); - double y = guiStuff.firstChildElement(HMF_VIEWPORTTAG).attribute("y").toDouble(); - double zoom = guiStuff.firstChildElement(HMF_VIEWPORTTAG).attribute("zoom").toDouble(); + double x = guiStuff.firstChildElement(hmf::appearance::viewport).attribute("x").toDouble(); + double y = guiStuff.firstChildElement(hmf::appearance::viewport).attribute("y").toDouble(); + double zoom = guiStuff.firstChildElement(hmf::appearance::viewport).attribute("zoom").toDouble(); bool dontClearUndo = false; - if(!guiStuff.firstChildElement(HMF_UNDO).isNull()) + if(!guiStuff.firstChildElement(hmf::undo).isNull()) { - QDomElement undoElement = guiStuff.firstChildElement(HMF_UNDO); + QDomElement undoElement = guiStuff.firstChildElement(hmf::undo); mpUndoStack->fromXml(undoElement); dontClearUndo = true; mSaveUndoStack = true; //Set save undo stack setting to true if loading a hmf file with undo stack saved @@ -4651,16 +4651,16 @@ void SystemObject::loadFromDomElement(QDomElement domElement) //Load simulation time QString startT,stepT,stopT; bool inheritTs; - parseSimulationTimeTag(domElement.firstChildElement(HMF_SIMULATIONTIMETAG), startT, stepT, stopT, inheritTs); + parseSimulationTimeTag(domElement.firstChildElement(hmf::simulationtime), startT, stepT, stopT, inheritTs); this->setTimeStep(stepT.toDouble()); mpCoreSystemAccess->setInheritTimeStep(inheritTs); // Load number of log samples - parseLogSettingsTag(domElement.firstChildElement(HMF_SIMULATIONLOGSETTINGS), mLogStartTime, mNumberOfLogSamples); + parseLogSettingsTag(domElement.firstChildElement(hmf::simulationlogsettings), mLogStartTime, mNumberOfLogSamples); //! @deprecated 20131002 we keep this below for backwards compatibility for a while - if(domElement.hasAttribute(HMF_LOGSAMPLES)) + if(domElement.hasAttribute(hmf::logsamples)) { - mNumberOfLogSamples = domElement.attribute(HMF_LOGSAMPLES).toInt(); + mNumberOfLogSamples = domElement.attribute(hmf::logsamples).toInt(); } // Only set start stop time for the top level system @@ -4673,12 +4673,12 @@ void SystemObject::loadFromDomElement(QDomElement domElement) updateHmfSystemProperties(domElement, hmfFormatVersion, coreHmfVersion); //1. Load global parameters - QDomElement xmlParameters = domElement.firstChildElement(HMF_PARAMETERS); - QDomElement xmlSubObject = xmlParameters.firstChildElement(HMF_PARAMETERTAG); + QDomElement xmlParameters = domElement.firstChildElement(hmf::parameters); + QDomElement xmlSubObject = xmlParameters.firstChildElement(hmf::parameter::root); while (!xmlSubObject.isNull()) { loadSystemParameter(xmlSubObject, true, hmfFormatVersion, this); - xmlSubObject = xmlSubObject.nextSiblingElement(HMF_PARAMETERTAG); + xmlSubObject = xmlSubObject.nextSiblingElement(hmf::parameter::root); } //2. Load all sub-components @@ -4692,14 +4692,14 @@ void SystemObject::loadFromDomElement(QDomElement domElement) if(pObj == nullptr) { gpMessageHandler->addErrorMessage(QString("Model contains component from a library that has not been loaded. TypeName: ") + - xmlSubObject.attribute(HMF_TYPENAME) + QString(", Name: ") + xmlSubObject.attribute(HMF_NAMETAG)); + xmlSubObject.attribute(hmf::typenametag) + QString(", Name: ") + xmlSubObject.attribute(hmf::name)); // Insert missing component dummy instead - QString typeName = xmlSubObject.attribute(HMF_TYPENAME); - xmlSubObject.setAttribute(HMF_TYPENAME, "MissingComponent"); - xmlSubObject.setAttribute(HMF_SUBTYPENAME, ""); + QString typeName = xmlSubObject.attribute(hmf::typenametag); + xmlSubObject.setAttribute(hmf::typenametag, "MissingComponent"); + xmlSubObject.setAttribute(hmf::subtypename, ""); pObj = loadModelObject(xmlSubObject, this, NoUndo); - xmlSubObject.setAttribute(HMF_TYPENAME, typeName); + xmlSubObject.setAttribute(hmf::typenametag, typeName); pObj->setFallbackDomElement(xmlSubObject); } else @@ -4709,12 +4709,12 @@ void SystemObject::loadFromDomElement(QDomElement domElement) //! @deprecated This StartValue load code is only kept for up converting old files, we should keep it here until we have some other way of up converting old formats //Load start values //Is not needed, start values are saved as ordinary parameters! This code snippet can probably be removed. - QDomElement xmlStartValues = xmlSubObject.firstChildElement(HMF_STARTVALUES); - QDomElement xmlStartValue = xmlStartValues.firstChildElement(HMF_STARTVALUE); + QDomElement xmlStartValues = xmlSubObject.firstChildElement(hmf::startvalues); + QDomElement xmlStartValue = xmlStartValues.firstChildElement(hmf::startvalue); while (!xmlStartValue.isNull()) { loadStartValue(xmlStartValue, pObj, NoUndo); - xmlStartValue = xmlStartValue.nextSiblingElement(HMF_STARTVALUE); + xmlStartValue = xmlStartValue.nextSiblingElement(hmf::startvalue); } } if(xmlSubObject.attribute("volunector") == "true") @@ -4726,19 +4726,19 @@ void SystemObject::loadFromDomElement(QDomElement domElement) } //3. Load all text box widgets - xmlSubObject = xmlSubObjects.firstChildElement(HMF_TEXTBOXWIDGETTAG); + xmlSubObject = xmlSubObjects.firstChildElement(hmf::widget::textboxwidget); while (!xmlSubObject.isNull()) { loadTextBoxWidget(xmlSubObject, this, NoUndo); - xmlSubObject = xmlSubObject.nextSiblingElement(HMF_TEXTBOXWIDGETTAG); + xmlSubObject = xmlSubObject.nextSiblingElement(hmf::widget::textboxwidget); } //4. Load all image widgets - xmlSubObject = xmlSubObjects.firstChildElement(hmf::imagewidget); + xmlSubObject = xmlSubObjects.firstChildElement(hmf::widget::imagewidget); while (!xmlSubObject.isNull()) { loadImageWidget(xmlSubObject, this, NoUndo); - xmlSubObject = xmlSubObject.nextSiblingElement(hmf::imagewidget); + xmlSubObject = xmlSubObject.nextSiblingElement(hmf::widget::imagewidget); } //5. Load all sub-systems @@ -4758,8 +4758,8 @@ void SystemObject::loadFromDomElement(QDomElement domElement) } //7. Load all connectors - QDomElement xmlConnections = domElement.firstChildElement(HMF_CONNECTIONS); - xmlSubObject = xmlConnections.firstChildElement(HMF_CONNECTORTAG); + QDomElement xmlConnections = domElement.firstChildElement(hmf::connections); + xmlSubObject = xmlConnections.firstChildElement(hmf::connector::root); QList failedConnections; while (!xmlSubObject.isNull()) { @@ -4767,7 +4767,7 @@ void SystemObject::loadFromDomElement(QDomElement domElement) { // failedConnections.append(xmlSubObject); } - xmlSubObject = xmlSubObject.nextSiblingElement(HMF_CONNECTORTAG); + xmlSubObject = xmlSubObject.nextSiblingElement(hmf::connector::root); } // //If some connectors failed to load, it could mean that they were loaded in wrong order. // //Try again until they work, or abort if number of attempts are greater than maximum possible for success. @@ -4786,38 +4786,38 @@ void SystemObject::loadFromDomElement(QDomElement domElement) //8. Load system parameters again in case we need to reregister system port start values - xmlParameters = domElement.firstChildElement(HMF_PARAMETERS); - xmlSubObject = xmlParameters.firstChildElement(HMF_PARAMETERTAG); + xmlParameters = domElement.firstChildElement(hmf::parameters); + xmlSubObject = xmlParameters.firstChildElement(hmf::parameter::root); while (!xmlSubObject.isNull()) { loadSystemParameter(xmlSubObject, false, hmfFormatVersion, this); - xmlSubObject = xmlSubObject.nextSiblingElement(HMF_PARAMETERTAG); + xmlSubObject = xmlSubObject.nextSiblingElement(hmf::parameter::root); } //9. Load plot variable aliases - QDomElement xmlAliases = domElement.firstChildElement(HMF_ALIASES); - QDomElement xmlAlias = xmlAliases.firstChildElement(HMF_ALIAS); + QDomElement xmlAliases = domElement.firstChildElement(hmf::aliases); + QDomElement xmlAlias = xmlAliases.firstChildElement(hmf::alias); while (!xmlAlias.isNull()) { loadPlotAlias(xmlAlias, this); - xmlAlias = xmlAlias.nextSiblingElement(HMF_ALIAS); + xmlAlias = xmlAlias.nextSiblingElement(hmf::alias); } //9.1 Load plot variable aliases //! @deprecated Remove in the future when hmf format stabilized and everyone has upgraded - xmlSubObject = xmlParameters.firstChildElement(HMF_ALIAS); + xmlSubObject = xmlParameters.firstChildElement(hmf::alias); while (!xmlSubObject.isNull()) { loadPlotAlias(xmlSubObject, this); - xmlSubObject = xmlSubObject.nextSiblingElement(HMF_ALIAS); + xmlSubObject = xmlSubObject.nextSiblingElement(hmf::alias); } //10. Load optimization settings - xmlSubObject = guiStuff.firstChildElement(HMF_OPTIMIZATION); + xmlSubObject = guiStuff.firstChildElement(hmf::optimization::root); loadOptimizationSettingsFromDomElement(xmlSubObject); //11. Load sensitivity analysis settings - xmlSubObject = guiStuff.firstChildElement(HMF_SENSITIVITYANALYSIS); + xmlSubObject = guiStuff.firstChildElement(hmf::sensitivityanalysis::root); loadSensitivityAnalysisSettingsFromDomElement(xmlSubObject); @@ -4917,9 +4917,9 @@ void SystemObject::setModelFileInfo(QFile &rFile, const QString relModelPath) void SystemObject::loadParameterValuesFromFile(QString parameterFile) { if(parameterFile.isEmpty()) { - QString openLocation = gpConfig->getStringSetting(CFG_PARAMETERIMPORTDIR); + QString openLocation = gpConfig->getStringSetting(cfg::dir::parameterimport); if (openLocation.isEmpty()) { - openLocation = gpConfig->getStringSetting(CFG_LOADMODELDIR); + openLocation = gpConfig->getStringSetting(cfg::dir::loadmodel); } parameterFile = QFileDialog::getOpenFileName(gpMainWindowWidget, tr("Load Parameter File"), openLocation, @@ -4933,7 +4933,7 @@ void SystemObject::loadParameterValuesFromFile(QString parameterFile) // Trigger system parameter widget refresh, regardless if any system parameters actually changed emit systemParametersChanged(); } - gpConfig->setStringSetting(CFG_PARAMETERIMPORTDIR, QFileInfo(parameterFile).absolutePath()); + gpConfig->setStringSetting(cfg::dir::parameterimport, QFileInfo(parameterFile).absolutePath()); } emit checkMessages(); } diff --git a/HopsanGUI/GUIObjects/GUIContainerPort.cpp b/HopsanGUI/GUIObjects/GUIContainerPort.cpp index 1e453f3518..9cba29c72d 100644 --- a/HopsanGUI/GUIObjects/GUIContainerPort.cpp +++ b/HopsanGUI/GUIObjects/GUIContainerPort.cpp @@ -130,7 +130,7 @@ int SystemPortObject::type() const QString SystemPortObject::getHmfTagName() const { - return HMF_SYSTEMPORTTAG; + return hmf::systemport; } //! @brief Check if this is a system port (a container port belonging to a system) diff --git a/HopsanGUI/GUIObjects/GUIModelObject.cpp b/HopsanGUI/GUIObjects/GUIModelObject.cpp index 250967b979..96f5cc4074 100644 --- a/HopsanGUI/GUIObjects/GUIModelObject.cpp +++ b/HopsanGUI/GUIObjects/GUIModelObject.cpp @@ -177,7 +177,7 @@ QStringList ModelObject::getSystemNameHieararchy() const QString ModelObject::getHmfTagName() const { - return HMF_OBJECT; //!< @todo change this + return hmf::object; //!< @todo change this } @@ -656,9 +656,9 @@ void ModelObject::openPropertiesDialog() void ModelObject::saveParameterValuesToFile(QString parameterFile) { if (parameterFile.isEmpty()) { - QString saveDirectory = gpConfig->getStringSetting(CFG_PARAMETEREXPORTDIR); + QString saveDirectory = gpConfig->getStringSetting(cfg::dir::parameterexport); if(saveDirectory.isEmpty()) { - saveDirectory = gpConfig->getStringSetting(CFG_LOADMODELDIR); + saveDirectory = gpConfig->getStringSetting(cfg::dir::loadmodel); } parameterFile = QFileDialog::getSaveFileName(gpMainWindowWidget, tr("Save Parameter Value File"), saveDirectory, @@ -670,7 +670,7 @@ void ModelObject::saveParameterValuesToFile(QString parameterFile) auto saveFunction = [this]() -> QDomDocument { QDomDocument domDocument; - QDomElement rootElement = domDocument.createElement(HPF_ROOTTAG); + QDomElement rootElement = domDocument.createElement(hpf::root); domDocument.appendChild(rootElement); this->saveToDomElement(rootElement, SaveContentsEnumT::ParametersOnly); appendRootXMLProcessingInstruction(domDocument); @@ -836,11 +836,11 @@ QMap ModelObject::getVariableAliases(const QString &rPortName) getVariameterDescriptions(vds); for (int i=0; igetBoolSetting(CFG_SHOWHIDDENNODEDATAVARIABLES) || (vds[i].mVariabelType != "Hidden")) ) + if ( !vds[i].mAlias.isEmpty() && rPortName.isEmpty() && (gpConfig->getBoolSetting(cfg::showhiddennodedatavariables) || (vds[i].mVariabelType != "Hidden")) ) { results.insert(vds[i].mPortName+"#"+vds[i].mName, vds[i].mAlias); } - else if ( !vds[i].mAlias.isEmpty() && (rPortName == vds[i].mPortName) && (gpConfig->getBoolSetting(CFG_SHOWHIDDENNODEDATAVARIABLES) || (vds[i].mVariabelType != "Hidden")) ) + else if ( !vds[i].mAlias.isEmpty() && (rPortName == vds[i].mPortName) && (gpConfig->getBoolSetting(cfg::showhiddennodedatavariables) || (vds[i].mVariabelType != "Hidden")) ) { results.insert(vds[i].mName, vds[i].mAlias); } @@ -1052,12 +1052,12 @@ void ModelObject::setModelFileInfo(QFile &rFile, const QString relModelPath) void ModelObject::saveCoreDataToDomElement(QDomElement &rDomElement, SaveContentsEnumT contents) { - rDomElement.setAttribute(HMF_TYPENAME, getTypeName()); - rDomElement.setAttribute(HMF_SUBTYPENAME, getSubTypeName()); - rDomElement.setAttribute(HMF_NAMETAG, getName()); + rDomElement.setAttribute(hmf::typenametag, getTypeName()); + rDomElement.setAttribute(hmf::subtypename, getSubTypeName()); + rDomElement.setAttribute(hmf::name, getName()); if(contents==FullModel) { - rDomElement.setAttribute(HMF_CQSTYPE, getTypeCQS()); - rDomElement.setAttribute(HMF_DISABLEDTAG, bool2str(isDisabled())); + rDomElement.setAttribute(hmf::cqstype, getTypeCQS()); + rDomElement.setAttribute(hmf::appearance::disabled, bool2str(isDisabled())); } } @@ -1065,74 +1065,74 @@ QDomElement ModelObject::saveGuiDataToDomElement(QDomElement &rDomElement) { if (!getSubTypeName().isEmpty()) { - rDomElement.setAttribute(HMF_SUBTYPENAME, getSubTypeName()); + rDomElement.setAttribute(hmf::subtypename, getSubTypeName()); } - rDomElement.setAttribute(HMF_LOCKEDTAG, bool2str(mIsLocked)); + rDomElement.setAttribute(hmf::appearance::locked, bool2str(mIsLocked)); // Save GUI related stuff - QDomElement xmlGuiStuff = appendDomElement(rDomElement,HMF_HOPSANGUITAG); + QDomElement xmlGuiStuff = appendDomElement(rDomElement,hmf::hopsangui); // Save center pos in parent coordinates (same as scene coordinates for model objects) QPointF cpos = this->getCenterPos(); appendPoseTag(xmlGuiStuff, cpos.x(), cpos.y(), rotation(), this->mIsFlipped, 10); // Save the alwasys visible setting - xmlGuiStuff.setAttribute("alwaysvisible", mAlwaysVisible); + xmlGuiStuff.setAttribute(hmf::appearance::alwaysvisible, mAlwaysVisible); // Save the text displaying the component name - QDomElement nametext = appendDomElement(xmlGuiStuff, HMF_NAMETEXTTAG); - nametext.setAttribute("position", getNameTextPos()); - nametext.setAttribute("visible", mNameTextAlwaysVisible); + QDomElement nametext = appendDomElement(xmlGuiStuff, hmf::appearance::nametext); + nametext.setAttribute(hmf::appearance::position, getNameTextPos()); + nametext.setAttribute(hmf::appearance::visible, mNameTextAlwaysVisible); // Save any custom selected parameter scales if (!mRegisteredCustomParameterUnitScales.isEmpty()) { - QDomElement plotscales = appendDomElement(xmlGuiStuff, HMF_PARAMETERSCALES); + QDomElement plotscales = appendDomElement(xmlGuiStuff, hmf::parameter::scales); QMap::iterator psit; for (psit=mRegisteredCustomParameterUnitScales.begin(); psit!=mRegisteredCustomParameterUnitScales.end(); ++psit) { UnitConverter &us = psit.value(); - QDomElement plotscale = appendDomElement(plotscales, HMF_PARAMETERSCALE); - plotscale.setAttribute(HMF_PARAMETERSCALEPARAMNAME, psit.key()); - plotscale.setAttribute(HMF_PARAMETERSCALEUNIT, us.mUnit); - plotscale.setAttribute(HMF_PARAMETERSCALESCALE, us.mScale); + QDomElement plotscale = appendDomElement(plotscales, hmf::parameter::scale); + plotscale.setAttribute(hmf::parameter::scaleparametername, psit.key()); + plotscale.setAttribute(hmf::parameter::scaleunit, us.mUnit); + plotscale.setAttribute(hmf::parameter::scalescale, us.mScale); if (!us.mOffset.isEmpty()) { - plotscale.setAttribute(HMF_PARAMETERSCALEOFFSET, us.mOffset); + plotscale.setAttribute(hmf::parameter::scaleoffset, us.mOffset); } if (!us.mQuantity.isEmpty()) { - plotscale.setAttribute(HMF_PARAMETERSCALEQUANTITY, us.mQuantity); + plotscale.setAttribute(hmf::parameter::scalequantity, us.mQuantity); } CoreParameterData data; getParameter(psit.key(), data); - plotscale.setAttribute(HMF_PARAMETERSCALEVALUE, us.convertFromBase(data.mValue)); + plotscale.setAttribute(hmf::parameter::scalevalue, us.convertFromBase(data.mValue)); } } // Save custom selected plot settings if (!mRegisteredInvertPlotVariables.isEmpty()) { - QDomElement plotsettings = appendDomElement(xmlGuiStuff, HMF_VARIABLEPLOTSETTINGS); + QDomElement plotsettings = appendDomElement(xmlGuiStuff, hmf::variable::plotsettings); QList invkeys = mRegisteredInvertPlotVariables.keys(); QList labelkeys = mRegisteredPlotLabels.keys(); for (QString &invkey : invkeys) { - QDomElement plotsetting = appendDomElement(plotsettings, HMF_VARIABLEPLOTSETTING); - plotsetting.setAttribute("name", invkey); - plotsetting.setAttribute("invert", mRegisteredInvertPlotVariables.value(invkey)); + QDomElement plotsetting = appendDomElement(plotsettings, hmf::variable::plotsetting); + plotsetting.setAttribute(hmf::name, invkey); + plotsetting.setAttribute(hmf::plot::invert, mRegisteredInvertPlotVariables.value(invkey)); if (labelkeys.contains(invkey)) { - plotsetting.setAttribute("label", mRegisteredPlotLabels.value(invkey)); + plotsetting.setAttribute(hmf::plot::label, mRegisteredPlotLabels.value(invkey)); labelkeys.removeAll(invkey); } } for (QString &labelkey : labelkeys) { - QDomElement plotsetting = appendDomElement(plotsettings, HMF_VARIABLEPLOTSETTING); - plotsetting.setAttribute("name", labelkey); - plotsetting.setAttribute("label", mRegisteredPlotLabels.value(labelkey)); + QDomElement plotsetting = appendDomElement(plotsettings, hmf::variable::plotsetting); + plotsetting.setAttribute(hmf::name, labelkey); + plotsetting.setAttribute(hmf::variable::plotlabel, mRegisteredPlotLabels.value(labelkey)); } } // if (!mRegisteredCustomPlotUnitsOrScales.isEmpty()) @@ -1150,7 +1150,7 @@ QDomElement ModelObject::saveGuiDataToDomElement(QDomElement &rDomElement) // } // Save animation settings - QDomElement animationElement = appendDomElement(xmlGuiStuff, HMF_ANIMATION); + QDomElement animationElement = appendDomElement(xmlGuiStuff, hmf::animation); mModelObjectAppearance.getAnimationDataPtr()->saveToDomElement(animationElement); // Return dom node with appended gui contents diff --git a/HopsanGUI/GUIObjects/GUIModelObjectAppearance.cpp b/HopsanGUI/GUIObjects/GUIModelObjectAppearance.cpp index 9af30df17d..ad91fb118d 100644 --- a/HopsanGUI/GUIObjects/GUIModelObjectAppearance.cpp +++ b/HopsanGUI/GUIObjects/GUIModelObjectAppearance.cpp @@ -43,103 +43,89 @@ #include -// ========== Defines for load/save common strings ========== -#define CAF_TYPENAME "typename" -#define CAF_SUBTYPENAME "subtypename" -#define CAF_TYPE "type" -#define CAF_DISPLAYNAME "displayname" -#define CAF_SOURCECODE "sourcecode" -#define CAF_LIBPATH "libpath" -#define CAF_RECOMPILABLE "recompilable" -#define CAF_NAME "name" -#define CAF_IDX "idx" - -#define CAF_HMFFILE "hmffile" - -#define CAF_ICON "icon" -#define CAF_ICONS "icons" -#define CAF_PATH "path" -#define CAF_SCALE "scale" -#define CAF_ICONROTATION "iconrotation" -#define CAF_USERPATH "userpath" -#define CAF_ISOPATH "isopath" -#define CAF_USERSCALE "userscale" -#define CAF_ISOSCALE "isoscale" - -#define CAF_HELP "help" -#define CAF_HELPTEXT "text" -#define CAF_HELPPICTURE "picture" -#define CAF_HELPLINK "link" -#define CAF_HELPHTML "html" -#define CAF_HELPMARKDOWN "md" - namespace caf { constexpr auto name = "name"; constexpr auto path = "path"; constexpr auto parametersets = "parametersets"; constexpr auto parameterset = "parameterset"; + constexpr auto typenametag = "typename"; + constexpr auto subtypename = "subtypename"; + constexpr auto type = "type"; + constexpr auto displayname = "displayname"; + constexpr auto sourcecode = "sourcecode"; + constexpr auto libpath = "libpath"; + constexpr auto recompilable = "recompilable"; + constexpr auto idx = "idx"; + constexpr auto hmffile = "hmffile"; + constexpr auto icon = "icon"; + constexpr auto icons = "icons"; + constexpr auto scale = "scale"; + constexpr auto iconrotation = "iconrotation"; + constexpr auto userpath = "userpath"; + constexpr auto isopath = "isopath"; + constexpr auto userscasle = "userscale"; + constexpr auto isoscale = "isoscale"; + constexpr auto parameters = "defaultparameters"; + constexpr auto parameter = "parameter"; + constexpr auto hidden = "hidden"; + constexpr auto ports = "ports"; + constexpr auto port = "port"; + constexpr auto portpositions = "portpositions"; + constexpr auto portpose = "portpose"; + constexpr auto replacables = "replacables"; + constexpr auto replacable = "replacable"; + constexpr auto autoplaced = "autoplaced"; + constexpr auto enabled = "enabled"; + namespace help { + constexpr auto root = "help"; + constexpr auto text = "text"; + constexpr auto picture = "picture"; + constexpr auto link = "link"; + constexpr auto html = "html"; + constexpr auto markdown = "md"; + } + namespace animation { + constexpr auto root = "animation"; + constexpr auto adjustable = "adjustable"; + constexpr auto xgain = "xgain"; + constexpr auto ygain = "ygain"; + constexpr auto switchable = "switchable"; + constexpr auto momentary = "momentary"; + constexpr auto indicator = "indicator"; + constexpr auto portname = "portname"; + constexpr auto startx = "startx"; + constexpr auto starty = "starty"; + constexpr auto movingport = "movingport"; + constexpr auto relative = "relative"; + constexpr auto movable = "movable"; + constexpr auto hideicon = "hideicon"; + constexpr auto dataname = "dataname"; + constexpr auto onvalue = "onvalue"; + constexpr auto offvalue = "offvalue"; + constexpr auto xmin = "xmin"; + constexpr auto xmax = "xmax"; + constexpr auto ymin = "ymin"; + constexpr auto ymax = "ymax" ; + constexpr auto multiplier = "multiplier"; + constexpr auto divisor = "divisor"; + constexpr auto start = "start"; + constexpr auto movement = "movement"; + constexpr auto initscale = "initscale"; + constexpr auto resize = "resize"; + constexpr auto initcolor = "initcolor"; + constexpr auto color = "color"; + constexpr auto transformorigin = "transformorigin"; + constexpr auto flowspeed = "flowspeed"; + constexpr auto hydraulicminpressure = "hydraulicminpressure"; + constexpr auto hydraulicmaxpressure = "hydraulicmaxpressure"; + } } -#define CAF_PARAMETERS "defaultparameters" -#define CAF_PARAMETER "parameter" -#define CAF_NAME "name" -#define CAF_HIDDEN "hidden" - -#define CAF_PORTS "ports" -#define CAF_PORT "port" -#define CAF_DESCRIPTION "description" -#define CAF_PORTPOSITIONS "portpositions" -#define CAF_PORTPOSE "portpose" - -#define CAF_REPLACABLES "replacables" -#define CAF_REPLACABLE "replacable" - -#define CAF_AUTOPLACED "autoplaced" -#define CAF_ENABLED "enabled" - -#define CAF_ANIMATION "animation" - -#define CAF_DATANAME "dataname" -#define CAF_ONVALUE "onvalue" -#define CAF_OFFVALUE "offvalue" -#define CAF_XMIN "xmin" -#define CAF_XMAX "xmax" -#define CAF_YMIN "ymin" -#define CAF_YMAX "ymax" - -#define CAF_MULTIPLIER "multiplier" -#define CAF_DIVISOR "divisor" -#define CAF_START "start" -#define CAF_MOVEMENT "movement" -#define CAF_INITSCALE "initscale" -#define CAF_RESIZE "resize" -#define CAF_INITCOLOR "initcolor" -#define CAF_COLOR "color" -#define CAF_TRANSFORMORIGIN "transformorigin" -#define CAF_FLOWSPEED "flowspeed" -#define CAF_HYDRAULICMINPRESSURE "hydraulicminpressure" -#define CAF_HYDRAULICMAXPRESSURE "hydraulicmaxpressure" - -#define CAF_ADJUSTABLE "adjustable" -#define CAF_XGAIN "xgain" -#define CAF_YGAIN "ygain" -#define CAF_SWITCHABLE "switchable" -#define CAF_MOMENTARY "momentary" -#define CAF_INDICATOR "indicator" -#define CAF_PORTNAME "portname" -#define CAF_STARTX "startx" -#define CAF_STARTY "starty" -#define CAF_MOVINGPORT "movingport" -#define CAF_RELATIVE "relative" -#define CAF_MOVABLE "movable" -#define CAF_HIDEICON "hideicon" - - // =============== Help Functions =============== QDomElement appendOrGetCAFRootTag(QDomElement parentElement) { - QDomElement cafroot = getOrAppendNewDomElement(parentElement, CAF_ROOT); - cafroot.setAttribute(CAF_VERSION, CAF_VERSIONNUM); + QDomElement cafroot = getOrAppendNewDomElement(parentElement, caf::root); + cafroot.setAttribute(caf::version, CAF_VERSIONNUM); return cafroot; } @@ -152,7 +138,7 @@ QDomElement appendOrGetCAFRootTag(QDomElement parentElement) //! @deprecated Only use for loading old version files void parsePortPoseTag(QDomElement domElement, QString &rName, double &rX, double &rY, double &rTheta) { - rName = domElement.attribute(CAF_NAME); + rName = domElement.attribute(caf::name); bool dummy; parsePoseTag(domElement, rX, rY, rTheta, dummy); } @@ -163,26 +149,26 @@ void parsePortPoseTag(QDomElement domElement, QString &rName, double &rX, double //! @param [in] rPortAppearance Reference to PortAppearance object to be written void appendPortDomElement(QDomElement &rDomElement, const QString portName, const PortAppearance &rPortAppearance) { - QDomElement xmlPort = appendDomElement(rDomElement, CAF_PORT); - xmlPort.setAttribute(CAF_NAME, portName); + QDomElement xmlPort = appendDomElement(rDomElement, caf::port); + xmlPort.setAttribute(caf::name, portName); setQrealAttribute(xmlPort, "x", rPortAppearance.x, 10, 'g'); setQrealAttribute(xmlPort, "y", rPortAppearance.y, 10, 'g'); setQrealAttribute(xmlPort, "a", rPortAppearance.rot, 6, 'g'); if(rPortAppearance.mAutoPlaced) { - xmlPort.setAttribute(CAF_AUTOPLACED, HMF_TRUETAG); + xmlPort.setAttribute(caf::autoplaced, hmf::truetag); } else { - xmlPort.setAttribute(CAF_AUTOPLACED, HMF_FALSETAG); + xmlPort.setAttribute(caf::autoplaced, hmf::falsetag); } if(rPortAppearance.mEnabled) { - xmlPort.setAttribute(CAF_ENABLED, HMF_TRUETAG); + xmlPort.setAttribute(caf::enabled, hmf::truetag); } else { - xmlPort.setAttribute(CAF_ENABLED, HMF_FALSETAG); + xmlPort.setAttribute(caf::enabled, hmf::falsetag); } } @@ -192,13 +178,13 @@ void appendPortDomElement(QDomElement &rDomElement, const QString portName, cons //! @param [out] rPortAppearance Reference to PortAppearance object that will contain parsed data void parsePortDomElement(QDomElement domElement, QString &rPortName, PortAppearance &rPortAppearance) { - rPortName = domElement.attribute(CAF_NAME); + rPortName = domElement.attribute(caf::name); rPortAppearance.x = parseAttributeQreal(domElement, "x", 0); rPortAppearance.y = parseAttributeQreal(domElement, "y", 0); rPortAppearance.rot = parseAttributeQreal(domElement, "a", 0); - rPortAppearance.mAutoPlaced = parseAttributeBool(domElement, CAF_AUTOPLACED, true); - rPortAppearance.mEnabled = parseAttributeBool(domElement, CAF_ENABLED, true); + rPortAppearance.mAutoPlaced = parseAttributeBool(domElement, caf::autoplaced, true); + rPortAppearance.mEnabled = parseAttributeBool(domElement, caf::enabled, true); } @@ -219,10 +205,10 @@ void ModelObjectAnimationData::readFromDomElement(QDomElement &rDomElement, QStr { if(!rDomElement.isNull()) { - QDomElement iconElement = rDomElement.firstChildElement(CAF_ICON); + QDomElement iconElement = rDomElement.firstChildElement(caf::icon); if(!iconElement.isNull()) { - baseIconPath = iconElement.attribute(CAF_USERPATH); + baseIconPath = iconElement.attribute(caf::userpath); } QFileInfo baseIconFileInfo(baseIconPath); @@ -232,34 +218,34 @@ void ModelObjectAnimationData::readFromDomElement(QDomElement &rDomElement, QStr baseIconPath = baseIconFileInfo.absoluteFilePath(); } - if(rDomElement.hasAttribute(CAF_FLOWSPEED)) + if(rDomElement.hasAttribute(caf::animation::flowspeed)) { - flowSpeed = rDomElement.attribute(CAF_FLOWSPEED).toDouble(); + flowSpeed = rDomElement.attribute(caf::animation::flowspeed).toDouble(); } else { flowSpeed = 100; } - if(rDomElement.hasAttribute(CAF_HYDRAULICMINPRESSURE)) + if(rDomElement.hasAttribute(caf::animation::hydraulicminpressure)) { - hydraulicMinPressure = rDomElement.attribute(CAF_HYDRAULICMINPRESSURE).toDouble(); + hydraulicMinPressure = rDomElement.attribute(caf::animation::hydraulicminpressure).toDouble(); } else { hydraulicMinPressure = 0; } - if(rDomElement.hasAttribute(CAF_HYDRAULICMAXPRESSURE)) + if(rDomElement.hasAttribute(caf::animation::hydraulicmaxpressure)) { - hydraulicMaxPressure = rDomElement.attribute(CAF_HYDRAULICMAXPRESSURE).toDouble(); + hydraulicMaxPressure = rDomElement.attribute(caf::animation::hydraulicmaxpressure).toDouble(); } else { hydraulicMaxPressure = 2e7; } - QDomElement xmlMovable = rDomElement.firstChildElement(CAF_MOVABLE); + QDomElement xmlMovable = rDomElement.firstChildElement(caf::animation::movable); int idx=0; while(!xmlMovable.isNull()) { @@ -273,7 +259,7 @@ void ModelObjectAnimationData::readFromDomElement(QDomElement &rDomElement, QStr } ++idx; - xmlMovable = xmlMovable.nextSiblingElement(CAF_MOVABLE); + xmlMovable = xmlMovable.nextSiblingElement(caf::animation::movable); } //Sort movables by indexes (no index = leave at bottom) @@ -297,11 +283,11 @@ void ModelObjectAnimationData::readFromDomElement(QDomElement &rDomElement, QStr void ModelObjectAnimationData::saveToDomElement(QDomElement &rDomElement) { - rDomElement.setAttribute(CAF_FLOWSPEED, flowSpeed); - rDomElement.setAttribute(CAF_HYDRAULICMINPRESSURE, hydraulicMinPressure); - rDomElement.setAttribute(CAF_HYDRAULICMAXPRESSURE, hydraulicMaxPressure); + rDomElement.setAttribute(caf::animation::flowspeed, flowSpeed); + rDomElement.setAttribute(caf::animation::hydraulicminpressure, hydraulicMinPressure); + rDomElement.setAttribute(caf::animation::hydraulicmaxpressure, hydraulicMaxPressure); for(const ModelObjectAnimationMovableData &m : movables) { - QDomElement movableElement = appendDomElement(rDomElement, CAF_MOVABLE); + QDomElement movableElement = appendDomElement(rDomElement, caf::animation::movable); //! @note Saving icons is disabled, because it probably makes no sense (paths will not work if moving hmf to other location) //QDomElement iconElement = appendDomElement(movableElement, CAF_ICON); @@ -309,7 +295,7 @@ void ModelObjectAnimationData::saveToDomElement(QDomElement &rDomElement) if(m.idx >= 0) { - movableElement.setAttribute(CAF_IDX, m.idx); + movableElement.setAttribute(caf::idx, m.idx); } for(int i=0; i, but lets check for more just in case - xmlPorts = xmlPorts.nextSiblingElement(CAF_PORTS); + xmlPorts = xmlPorts.nextSiblingElement(caf::ports); } - QDomElement xmlReplacables = domElement.firstChildElement(CAF_REPLACABLES); + QDomElement xmlReplacables = domElement.firstChildElement(caf::replacables); while (!xmlReplacables.isNull()) { - QDomElement xmlReplacable = xmlReplacables.firstChildElement(CAF_REPLACABLE); + QDomElement xmlReplacable = xmlReplacables.firstChildElement(caf::replacable); while (!xmlReplacable.isNull()) { - QString typeName = xmlReplacable.attribute(CAF_TYPENAME); + QString typeName = xmlReplacable.attribute(caf::typenametag); gpLibraryHandler->addReplacement(mTypeName, typeName); //!< @todo mainwindow and library should not be called in this file it is supposed to be a leaf class - xmlReplacable = xmlReplacable.nextSiblingElement(CAF_REPLACABLE); + xmlReplacable = xmlReplacable.nextSiblingElement(caf::replacable); } - xmlReplacables = xmlReplacables.nextSiblingElement(CAF_REPLACABLES); + xmlReplacables = xmlReplacables.nextSiblingElement(caf::replacables); } // vvvvvvvvvvvvvvvvvvvvv=== Bellow Reads old Format 0.2 Tags ===vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv - QDomElement xmlHelp_02 = domElement.firstChildElement(CAF_HELP); + QDomElement xmlHelp_02 = domElement.firstChildElement(caf::help::root); if(!xmlHelp_02.isNull()) { - if (xmlHelp_02.hasAttribute(CAF_HELPPICTURE)) + if (xmlHelp_02.hasAttribute(caf::help::picture)) { - mHelpPicture = xmlHelp_02.attribute(CAF_HELPPICTURE); + mHelpPicture = xmlHelp_02.attribute(caf::help::picture); } - if (xmlHelp_02.hasAttribute(CAF_HELPTEXT)) + if (xmlHelp_02.hasAttribute(caf::help::text)) { - mHelpText = xmlHelp_02.attribute(CAF_HELPTEXT); + mHelpText = xmlHelp_02.attribute(caf::help::text); } } QString portname; - QDomElement xmlPorts_02 = domElement.firstChildElement(CAF_PORTPOSITIONS); + QDomElement xmlPorts_02 = domElement.firstChildElement(caf::portpositions); while (!xmlPorts_02.isNull()) { - QDomElement xmlPortPose = xmlPorts_02.firstChildElement(CAF_PORTPOSE); + QDomElement xmlPortPose = xmlPorts_02.firstChildElement(caf::portpose); while (!xmlPortPose.isNull()) { PortAppearance portApp; parsePortPoseTag(xmlPortPose, portname, portApp.x, portApp.y, portApp.rot); mPortAppearanceMap.insert(portname, SharedPortAppearanceT(new PortAppearance(portApp))); - xmlPortPose = xmlPortPose.nextSiblingElement(CAF_PORTPOSE); + xmlPortPose = xmlPortPose.nextSiblingElement(caf::portpose); } // There should only be one , but lets check for more just in case - xmlPorts_02 = xmlPorts_02.nextSiblingElement(CAF_PORTPOSITIONS); + xmlPorts_02 = xmlPorts_02.nextSiblingElement(caf::portpositions); } - QDomElement xmlAnimation = domElement.firstChildElement(CAF_ANIMATION); + QDomElement xmlAnimation = domElement.firstChildElement(caf::animation::root); mAnimationData.readFromDomElement(xmlAnimation, mBasePath); // vvvvvvvvvvvvvvvvvvvvv=== Bellow Reads old Format 0.1 Tags ===vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv // Read old style icons - QDomElement xmlIcon2 = domElement.firstChildElement(CAF_ICON); + QDomElement xmlIcon2 = domElement.firstChildElement(caf::icon); if (!xmlIcon2.isNull()) { - mIsoIconAppearance.mRelativePath = xmlIcon2.attribute(CAF_ISOPATH); - mUserIconAppearance.mRelativePath = xmlIcon2.attribute(CAF_USERPATH); - mIsoIconAppearance.mRotationBehaviour = xmlIcon2.attribute(CAF_RELATIVE); - mUserIconAppearance.mRotationBehaviour = xmlIcon2.attribute(CAF_RELATIVE); - mUserIconAppearance.mScale = parseAttributeQreal(xmlIcon2, CAF_USERSCALE, 1.0); - mIsoIconAppearance.mScale = parseAttributeQreal(xmlIcon2, CAF_ISOSCALE, 1.0); + mIsoIconAppearance.mRelativePath = xmlIcon2.attribute(caf::isopath); + mUserIconAppearance.mRelativePath = xmlIcon2.attribute(caf::userpath); + mIsoIconAppearance.mRotationBehaviour = xmlIcon2.attribute(caf::animation::relative); + mUserIconAppearance.mRotationBehaviour = xmlIcon2.attribute(caf::animation::relative); + mUserIconAppearance.mScale = parseAttributeQreal(xmlIcon2, caf::userscasle, 1.0); + mIsoIconAppearance.mScale = parseAttributeQreal(xmlIcon2, caf::isoscale, 1.0); } // Read old style portposes, where portposes were not contained inside a common "ports" element - QDomElement xmlPortPose = domElement.firstChildElement(CAF_PORTPOSE); + QDomElement xmlPortPose = domElement.firstChildElement(caf::portpose); while (!xmlPortPose.isNull()) { PortAppearance portApp; parsePortPoseTag(xmlPortPose, portname, portApp.x, portApp.y, portApp.rot); mPortAppearanceMap.insert(portname, SharedPortAppearanceT(new PortAppearance(portApp))); - xmlPortPose = xmlPortPose.nextSiblingElement(CAF_PORTPOSE); + xmlPortPose = xmlPortPose.nextSiblingElement(caf::portpose); } // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -1081,12 +1067,12 @@ void ModelObjectAppearance::readFromDomElement(QDomElement domElement) //! @brief Adds the model object root dom element, or returns one that already exist QDomElement ModelObjectAppearance::addModelObjectRootElement(QDomElement parentDomElement) { - QDomElement more = getOrAppendNewDomElement(parentDomElement, CAF_MODELOBJECT); - more.setAttribute(CAF_TYPENAME, mTypeName); - more.setAttribute(CAF_DISPLAYNAME, mDisplayName); + QDomElement more = getOrAppendNewDomElement(parentDomElement, caf::modelobject); + more.setAttribute(caf::typenametag, mTypeName); + more.setAttribute(caf::displayname, mDisplayName); if (!mSubTypeName.isEmpty()) { - more.setAttribute(CAF_SUBTYPENAME, mSubTypeName); + more.setAttribute(caf::subtypename, mSubTypeName); } return more; } @@ -1099,61 +1085,61 @@ void ModelObjectAppearance::saveToDomElement(QDomElement &rDomElement) QDomElement xmlObject = addModelObjectRootElement(rDomElement); // Save icon data - QDomElement xmlIcons = appendDomElement(xmlObject, CAF_ICONS); + QDomElement xmlIcons = appendDomElement(xmlObject, caf::icons); if (hasIcon(UserGraphics)) { - QDomElement xmlIcon = appendDomElement(xmlIcons, CAF_ICON); - xmlIcon.setAttribute(CAF_TYPE, "user"); - xmlIcon.setAttribute(CAF_PATH, mUserIconAppearance.mRelativePath); - setQrealAttribute(xmlIcon, CAF_SCALE, mUserIconAppearance.mScale, 6, 'g'); - xmlIcon.setAttribute(CAF_ICONROTATION, mUserIconAppearance.mRotationBehaviour); + QDomElement xmlIcon = appendDomElement(xmlIcons, caf::icon); + xmlIcon.setAttribute(caf::type, "user"); + xmlIcon.setAttribute(caf::path, mUserIconAppearance.mRelativePath); + setQrealAttribute(xmlIcon, caf::scale, mUserIconAppearance.mScale, 6, 'g'); + xmlIcon.setAttribute(caf::iconrotation, mUserIconAppearance.mRotationBehaviour); } if (hasIcon(ISOGraphics)) { - QDomElement xmlIcon = appendDomElement(xmlIcons, CAF_ICON); - xmlIcon.setAttribute(CAF_TYPE, "iso"); - xmlIcon.setAttribute(CAF_PATH, mIsoIconAppearance.mRelativePath); - setQrealAttribute(xmlIcon, CAF_SCALE, mIsoIconAppearance.mScale, 6, 'g'); - xmlIcon.setAttribute(CAF_ICONROTATION, mIsoIconAppearance.mRotationBehaviour); + QDomElement xmlIcon = appendDomElement(xmlIcons, caf::icon); + xmlIcon.setAttribute(caf::type, "iso"); + xmlIcon.setAttribute(caf::path, mIsoIconAppearance.mRelativePath); + setQrealAttribute(xmlIcon, caf::scale, mIsoIconAppearance.mScale, 6, 'g'); + xmlIcon.setAttribute(caf::iconrotation, mIsoIconAppearance.mRotationBehaviour); } // If default missing have changed, then save that data as well //! @todo not hardcoded should be defined if (mDefaultMissingIconPath != "missingcomponenticon.svg") { - QDomElement xmlIcon = appendDomElement(xmlIcons, CAF_ICON); - xmlIcon.setAttribute(CAF_TYPE, "defaultmissing"); - xmlIcon.setAttribute(CAF_PATH, mDefaultMissingIconPath); + QDomElement xmlIcon = appendDomElement(xmlIcons, caf::icon); + xmlIcon.setAttribute(caf::type, "defaultmissing"); + xmlIcon.setAttribute(caf::path, mDefaultMissingIconPath); } // Save help text and picture data if(!mHelpText.isEmpty() || !mHelpPicture.isEmpty() || !mHelpLinks.isEmpty() || !mHelpHtmlPath.isEmpty() ) { - QDomElement xmlHelp = appendDomElement(xmlObject, CAF_HELP); + QDomElement xmlHelp = appendDomElement(xmlObject, caf::help::root); if( !mHelpText.isEmpty() ) { - appendDomTextNode(xmlHelp, CAF_HELPTEXT, mHelpText); + appendDomTextNode(xmlHelp, caf::help::text, mHelpText); } if( !mHelpPicture.isEmpty() ) { - appendDomTextNode(xmlHelp, CAF_HELPPICTURE, mHelpPicture); + appendDomTextNode(xmlHelp, caf::help::picture, mHelpPicture); } for( QString &link : mHelpLinks ) { - appendDomTextNode(xmlHelp, CAF_HELPLINK, link); + appendDomTextNode(xmlHelp, caf::help::link, link); } if( !mHelpHtmlPath.isEmpty() ) { - appendDomTextNode(xmlHelp, CAF_HELPHTML, mHelpHtmlPath); + appendDomTextNode(xmlHelp, caf::help::html, mHelpHtmlPath); } } // Save port data //! @todo maybe make the port appearance class capable of saving itself to DOM - QDomElement xmlPorts = appendDomElement(xmlObject, CAF_PORTS); + QDomElement xmlPorts = appendDomElement(xmlObject, caf::ports); PortAppearanceMapT::iterator pit; for (pit=mPortAppearanceMap.begin(); pit!=mPortAppearanceMap.end(); ++pit) { @@ -1161,13 +1147,13 @@ void ModelObjectAppearance::saveToDomElement(QDomElement &rDomElement) } QDomElement xmlAnimation; - if(xmlObject.firstChildElement(CAF_ANIMATION).isNull()) + if(xmlObject.firstChildElement(caf::animation::root).isNull()) { - xmlAnimation = appendDomElement(xmlObject, CAF_ANIMATION); + xmlAnimation = appendDomElement(xmlObject, caf::animation::root); } else { - xmlAnimation = xmlObject.firstChildElement(CAF_ANIMATION); + xmlAnimation = xmlObject.firstChildElement(caf::animation::root); } mAnimationData.saveToDomElement(xmlAnimation); } @@ -1179,7 +1165,7 @@ void ModelObjectAppearance::saveSpecificPortsToDomElement(QDomElement &rDomEleme QDomElement xmlModelObject = addModelObjectRootElement(rDomElement); // First check if the ports element already exist, else add the element - QDomElement xmlPorts = getOrAppendNewDomElement(xmlModelObject, CAF_PORTS); + QDomElement xmlPorts = getOrAppendNewDomElement(xmlModelObject, caf::ports); for (const QString &portName : rPortNames) { const SharedPortAppearanceT pData = mPortAppearanceMap.value(portName); @@ -1195,9 +1181,9 @@ void ModelObjectAppearance::saveToXMLFile(QString filename) { //Save to file QDomDocument doc; - QDomElement cafroot = doc.createElement(CAF_ROOT); + QDomElement cafroot = doc.createElement(caf::root); doc.appendChild(cafroot); - cafroot.setAttribute(CAF_VERSION, CAF_VERSIONNUM); + cafroot.setAttribute(caf::version, CAF_VERSIONNUM); this->saveToDomElement(cafroot); appendRootXMLProcessingInstruction(doc); //The xml "comment" on the first line saveXmlFile(filename, gpMessageHandler, [&](){return doc;}); @@ -1366,14 +1352,14 @@ GraphicsTypeEnumT ModelObjectAppearance::selectAvailableGraphicsType(const Graph void ModelObjectAnimationMovableData::readFromDomElement(QDomElement &rDomElement, QString basePath) { - if(rDomElement.hasAttribute(CAF_IDX)) + if(rDomElement.hasAttribute(caf::idx)) { - idx = rDomElement.attribute(CAF_IDX).toInt(); + idx = rDomElement.attribute(caf::idx).toInt(); } - if(iconPath.isEmpty() && !rDomElement.firstChildElement(CAF_ICON).isNull() && !rDomElement.firstChildElement(CAF_ICON).attribute(CAF_USERPATH).isEmpty()) + if(iconPath.isEmpty() && !rDomElement.firstChildElement(caf::icon).isNull() && !rDomElement.firstChildElement(caf::icon).attribute(caf::userpath).isEmpty()) { - iconPath = rDomElement.firstChildElement(CAF_ICON).attribute(CAF_USERPATH); + iconPath = rDomElement.firstChildElement(caf::icon).attribute(caf::userpath); } QDomElement dataElement = rDomElement.firstChildElement("data"); @@ -1384,40 +1370,40 @@ void ModelObjectAnimationMovableData::readFromDomElement(QDomElement &rDomElemen } while(!dataElement.isNull()) { - int idx = dataElement.attribute(CAF_IDX).toInt(); + int idx = dataElement.attribute(caf::idx).toInt(); while(dataPorts.size() < idx+1) { dataPorts.append(""); dataNames.append(""); //Assume names and ports always have same size } - dataPorts[idx] = dataElement.attribute(CAF_PORT); - dataNames[idx] = dataElement.attribute(CAF_DATANAME); + dataPorts[idx] = dataElement.attribute(caf::port); + dataNames[idx] = dataElement.attribute(caf::animation::dataname); dataElement = dataElement.nextSiblingElement("data"); } - QDomElement multiplierElement = rDomElement.firstChildElement(CAF_MULTIPLIER); + QDomElement multiplierElement = rDomElement.firstChildElement(caf::animation::multiplier); if(!multiplierElement.isNull()) { multipliers.clear(); } while(!multiplierElement.isNull()) { - multipliers.append(multiplierElement.attribute(CAF_NAME)); - multiplierElement = multiplierElement.nextSiblingElement(CAF_MULTIPLIER); + multipliers.append(multiplierElement.attribute(caf::name)); + multiplierElement = multiplierElement.nextSiblingElement(caf::animation::multiplier); } - QDomElement divisorElement = rDomElement.firstChildElement(CAF_DIVISOR); + QDomElement divisorElement = rDomElement.firstChildElement(caf::animation::divisor); if(!divisorElement.isNull()) { divisors.clear(); } while(!divisorElement.isNull()) { - divisors.append(divisorElement.attribute(CAF_NAME)); - divisorElement = divisorElement.nextSiblingElement(CAF_DIVISOR); + divisors.append(divisorElement.attribute(caf::name)); + divisorElement = divisorElement.nextSiblingElement(caf::animation::divisor); } - QDomElement xmlMovement = rDomElement.firstChildElement(CAF_MOVEMENT); + QDomElement xmlMovement = rDomElement.firstChildElement(caf::animation::movement); if(!xmlMovement.isNull()) { movementData.clear(); @@ -1427,19 +1413,19 @@ void ModelObjectAnimationMovableData::readFromDomElement(QDomElement &rDomElemen ModelObjectAnimationMovementData movement; movement.readFromDomElement(xmlMovement); movementData.append(movement); - xmlMovement = xmlMovement.nextSiblingElement(CAF_MOVEMENT); + xmlMovement = xmlMovement.nextSiblingElement(caf::animation::movement); } - if(!rDomElement.firstChildElement(CAF_START).isNull()) + if(!rDomElement.firstChildElement(caf::animation::start).isNull()) { - startX = rDomElement.firstChildElement(CAF_START).attribute("x").toDouble(); - startY = rDomElement.firstChildElement(CAF_START).attribute("y").toDouble(); - startTheta = rDomElement.firstChildElement(CAF_START).attribute("a").toDouble(); + startX = rDomElement.firstChildElement(caf::animation::start).attribute("x").toDouble(); + startY = rDomElement.firstChildElement(caf::animation::start).attribute("y").toDouble(); + startTheta = rDomElement.firstChildElement(caf::animation::start).attribute("a").toDouble(); } - if(!rDomElement.firstChildElement(CAF_INITSCALE).isNull()) + if(!rDomElement.firstChildElement(caf::animation::initscale).isNull()) { - initScaleX = rDomElement.firstChildElement(CAF_INITSCALE).attribute("x").toDouble(); - initScaleY = rDomElement.firstChildElement(CAF_INITSCALE).attribute("y").toDouble(); + initScaleX = rDomElement.firstChildElement(caf::animation::initscale).attribute("x").toDouble(); + initScaleY = rDomElement.firstChildElement(caf::animation::initscale).attribute("y").toDouble(); } else { @@ -1447,7 +1433,7 @@ void ModelObjectAnimationMovableData::readFromDomElement(QDomElement &rDomElemen initScaleY = 1; } - QDomElement xmlResize = rDomElement.firstChildElement(CAF_RESIZE); + QDomElement xmlResize = rDomElement.firstChildElement(caf::animation::resize); resizeData.clear(); @@ -1456,21 +1442,21 @@ void ModelObjectAnimationMovableData::readFromDomElement(QDomElement &rDomElemen ModelObjectAnimationResizeData resize; resize.readFromDomElement(xmlResize); resizeData.append(resize); - xmlResize = xmlResize.nextSiblingElement(CAF_RESIZE); + xmlResize = xmlResize.nextSiblingElement(caf::animation::resize); } - QDomElement xmlInitColor = rDomElement.firstChildElement(CAF_INITCOLOR); - QDomElement xmlColor = rDomElement.firstChildElement(CAF_COLOR); + QDomElement xmlInitColor = rDomElement.firstChildElement(caf::animation::initcolor); + QDomElement xmlColor = rDomElement.firstChildElement(caf::animation::color); if(!xmlInitColor.isNull() && !xmlColor.isNull()) { colorData.readFromDomElements(xmlInitColor, xmlColor); } - if(!rDomElement.firstChildElement(CAF_TRANSFORMORIGIN).isNull()) + if(!rDomElement.firstChildElement(caf::animation::transformorigin).isNull()) { - transformOriginX = rDomElement.firstChildElement(CAF_TRANSFORMORIGIN).attribute("x").toDouble(); - transformOriginY = rDomElement.firstChildElement(CAF_TRANSFORMORIGIN).attribute("y").toDouble(); + transformOriginX = rDomElement.firstChildElement(caf::animation::transformorigin).attribute("x").toDouble(); + transformOriginY = rDomElement.firstChildElement(caf::animation::transformorigin).attribute("y").toDouble(); } QFileInfo movableIconFileInfo(iconPath); @@ -1479,34 +1465,34 @@ void ModelObjectAnimationMovableData::readFromDomElement(QDomElement &rDomElemen movableIconFileInfo.setFile(QDir(basePath), iconPath); iconPath = movableIconFileInfo.absoluteFilePath(); } - QDomElement xmlAdjustable = rDomElement.firstChildElement(CAF_ADJUSTABLE); + QDomElement xmlAdjustable = rDomElement.firstChildElement(caf::animation::adjustable); if(!xmlAdjustable.isNull()) { isAdjustable = true; - adjustableMinX = xmlAdjustable.attribute(CAF_XMIN).toDouble(); - adjustableMaxX = xmlAdjustable.attribute(CAF_XMAX).toDouble(); - adjustableMinY = xmlAdjustable.attribute(CAF_YMIN).toDouble(); - adjustableMaxY = xmlAdjustable.attribute(CAF_YMAX).toDouble(); - adjustablePort = xmlAdjustable.attribute(CAF_PORT); - adjustableDataName = xmlAdjustable.attribute(CAF_DATANAME); - adjustableGainX = xmlAdjustable.attribute(CAF_XGAIN).toDouble(); - adjustableGainY = xmlAdjustable.attribute(CAF_YGAIN).toDouble(); + adjustableMinX = xmlAdjustable.attribute(caf::animation::xmin).toDouble(); + adjustableMaxX = xmlAdjustable.attribute(caf::animation::xmax).toDouble(); + adjustableMinY = xmlAdjustable.attribute(caf::animation::ymin).toDouble(); + adjustableMaxY = xmlAdjustable.attribute(caf::animation::ymax).toDouble(); + adjustablePort = xmlAdjustable.attribute(caf::port); + adjustableDataName = xmlAdjustable.attribute(caf::animation::dataname); + adjustableGainX = xmlAdjustable.attribute(caf::animation::xgain).toDouble(); + adjustableGainY = xmlAdjustable.attribute(caf::animation::ygain).toDouble(); } else { isAdjustable = false; } - QDomElement xmlSwitchable = rDomElement.firstChildElement(CAF_SWITCHABLE); + QDomElement xmlSwitchable = rDomElement.firstChildElement(caf::animation::switchable); if(!xmlSwitchable.isNull()) { isSwitchable = true; - isMomentary = parseAttributeBool(xmlSwitchable, CAF_MOMENTARY, false); - switchableOffValue = xmlSwitchable.attribute(CAF_OFFVALUE).toDouble(); - switchableOnValue = xmlSwitchable.attribute(CAF_ONVALUE).toDouble(); - switchablePort = xmlSwitchable.attribute(CAF_PORT); - switchableDataName = xmlSwitchable.attribute(CAF_DATANAME); - hideIconOnSwitch = parseAttributeBool(xmlSwitchable, CAF_HIDEICON, false); + isMomentary = parseAttributeBool(xmlSwitchable, caf::animation::momentary, false); + switchableOffValue = xmlSwitchable.attribute(caf::animation::offvalue).toDouble(); + switchableOnValue = xmlSwitchable.attribute(caf::animation::onvalue).toDouble(); + switchablePort = xmlSwitchable.attribute(caf::port); + switchableDataName = xmlSwitchable.attribute(caf::animation::dataname); + hideIconOnSwitch = parseAttributeBool(xmlSwitchable, caf::animation::hideicon, false); } else { @@ -1519,12 +1505,12 @@ void ModelObjectAnimationMovableData::readFromDomElement(QDomElement &rDomElemen hideIconOnSwitch = false; } - QDomElement xmlIndicaor = rDomElement.firstChildElement(CAF_INDICATOR); + QDomElement xmlIndicaor = rDomElement.firstChildElement(caf::animation::indicator); if(!xmlIndicaor.isNull()) { isIndicator = true; - indicatorPort = xmlIndicaor.attribute(CAF_PORT); - indicatorDataName = xmlIndicaor.attribute(CAF_DATANAME); + indicatorPort = xmlIndicaor.attribute(caf::port); + indicatorDataName = xmlIndicaor.attribute(caf::animation::dataname); } else { @@ -1534,7 +1520,7 @@ void ModelObjectAnimationMovableData::readFromDomElement(QDomElement &rDomElemen } - QDomElement xmlMovingPorts = rDomElement.firstChildElement(CAF_MOVINGPORT); + QDomElement xmlMovingPorts = rDomElement.firstChildElement(caf::animation::movingport); if(!xmlMovingPorts.isNull()) { movablePortNames.clear(); @@ -1543,20 +1529,20 @@ void ModelObjectAnimationMovableData::readFromDomElement(QDomElement &rDomElemen } while(!xmlMovingPorts.isNull()) { - QString portName = xmlMovingPorts.attribute(CAF_PORTNAME); + QString portName = xmlMovingPorts.attribute(caf::animation::portname); if(!portName.isEmpty() && !movablePortNames.contains(portName)) //Don't load tags without a port name, and tags that has already been loaded { - movablePortNames.append(xmlMovingPorts.attribute(CAF_PORTNAME)); - movablePortStartX.append(xmlMovingPorts.attribute(CAF_STARTX).toDouble()); - movablePortStartY.append(xmlMovingPorts.attribute(CAF_STARTY).toDouble()); + movablePortNames.append(xmlMovingPorts.attribute(caf::animation::portname)); + movablePortStartX.append(xmlMovingPorts.attribute(caf::animation::startx).toDouble()); + movablePortStartY.append(xmlMovingPorts.attribute(caf::animation::starty).toDouble()); } - xmlMovingPorts = xmlMovingPorts.nextSiblingElement(CAF_MOVINGPORT); + xmlMovingPorts = xmlMovingPorts.nextSiblingElement(caf::animation::movingport); } - QDomElement xmlRelative = rDomElement.firstChildElement(CAF_RELATIVE); + QDomElement xmlRelative = rDomElement.firstChildElement(caf::animation::relative); if(!xmlRelative.isNull()) { - movableRelative = xmlRelative.attribute(CAF_IDX).toInt(); + movableRelative = xmlRelative.attribute(caf::idx).toInt(); } else { @@ -1568,12 +1554,12 @@ void ModelObjectAnimationMovableData::readFromDomElement(QDomElement &rDomElemen //! @brief Loads animation movement data from dom element void ModelObjectAnimationMovementData::readFromDomElement(QDomElement &rDomElement) { - dataIdx = rDomElement.attribute(CAF_IDX).toDouble(); + dataIdx = rDomElement.attribute(caf::idx).toDouble(); x = rDomElement.attribute("x").toDouble(); y = rDomElement.attribute("y").toDouble(); theta = rDomElement.attribute("a").toDouble(); - divisor = rDomElement.attribute(CAF_DIVISOR); - multiplier = rDomElement.attribute(CAF_MULTIPLIER); + divisor = rDomElement.attribute(caf::animation::divisor); + multiplier = rDomElement.attribute(caf::animation::multiplier); } @@ -1583,9 +1569,9 @@ void ModelObjectAnimationMovementData::saveToDomElement(QDomElement &rDomElement setQrealAttribute(rDomElement, "x", x); setQrealAttribute(rDomElement, "y", y); setQrealAttribute(rDomElement, "a", theta); - rDomElement.setAttribute(CAF_IDX, dataIdx); - rDomElement.setAttribute(CAF_DIVISOR, divisor); - rDomElement.setAttribute(CAF_MULTIPLIER, multiplier); + rDomElement.setAttribute(caf::idx, dataIdx); + rDomElement.setAttribute(caf::animation::divisor, divisor); + rDomElement.setAttribute(caf::animation::multiplier, multiplier); } @@ -1599,8 +1585,8 @@ void ModelObjectAnimationResizeData::readFromDomElement(QDomElement &rDomElement else dataIdx1 = parseAttributeInt(rDomElement, "idx", 0); //For backwards compatibility dataIdx2 = parseAttributeInt(rDomElement, "idx2", -1); - divisor = rDomElement.attribute(CAF_DIVISOR); - multiplier = rDomElement.attribute(CAF_MULTIPLIER); + divisor = rDomElement.attribute(caf::animation::divisor); + multiplier = rDomElement.attribute(caf::animation::multiplier); } void ModelObjectAnimationResizeData::saveToDomElement(QDomElement &rDomElement) const @@ -1609,8 +1595,8 @@ void ModelObjectAnimationResizeData::saveToDomElement(QDomElement &rDomElement) setQrealAttribute(rDomElement, "y", y); rDomElement.setAttribute("idx1", dataIdx1); rDomElement.setAttribute("idx2", dataIdx2); - rDomElement.setAttribute(CAF_DIVISOR, divisor); - rDomElement.setAttribute(CAF_MULTIPLIER, multiplier); + rDomElement.setAttribute(caf::animation::divisor, divisor); + rDomElement.setAttribute(caf::animation::multiplier, multiplier); } @@ -1621,13 +1607,13 @@ void ModelObjectAnimationColorData::readFromDomElements(QDomElement &rInitDomEle initB = rInitDomElement.attribute("b").toDouble(); initA = rInitDomElement.attribute("a").toDouble(); - dataIdx = rDomElement.attribute(CAF_IDX).toInt(); + dataIdx = rDomElement.attribute(caf::idx).toInt(); r = rDomElement.attribute("r").toDouble(); g = rDomElement.attribute("g").toDouble(); b = rDomElement.attribute("b").toDouble(); a = rDomElement.attribute("a").toDouble(); - divisor = rDomElement.attribute(CAF_DIVISOR); - multiplier = rDomElement.attribute(CAF_MULTIPLIER); + divisor = rDomElement.attribute(caf::animation::divisor); + multiplier = rDomElement.attribute(caf::animation::multiplier); } void ModelObjectAnimationColorData::saveToDomElements(QDomElement &rInitDomElement, QDomElement &rDomElement) const @@ -1641,7 +1627,7 @@ void ModelObjectAnimationColorData::saveToDomElements(QDomElement &rInitDomEleme setQrealAttribute(rDomElement, "g", g); setQrealAttribute(rDomElement, "b", b); setQrealAttribute(rDomElement, "a", a); - rDomElement.setAttribute(CAF_IDX, dataIdx); - rDomElement.setAttribute(CAF_DIVISOR, divisor); - rDomElement.setAttribute(CAF_MULTIPLIER, multiplier); + rDomElement.setAttribute(caf::idx, dataIdx); + rDomElement.setAttribute(caf::animation::divisor, divisor); + rDomElement.setAttribute(caf::animation::multiplier, multiplier); } diff --git a/HopsanGUI/GUIObjects/GUIModelObjectAppearance.h b/HopsanGUI/GUIObjects/GUIModelObjectAppearance.h index 3940fa742f..88fa0ab4a4 100644 --- a/HopsanGUI/GUIObjects/GUIModelObjectAppearance.h +++ b/HopsanGUI/GUIObjects/GUIModelObjectAppearance.h @@ -44,9 +44,11 @@ #include "GUIPortAppearance.h" //Define for the root xml element name, and the element name for each component (modelobject) -#define CAF_VERSION "version" -#define CAF_ROOT "hopsanobjectappearance" -#define CAF_MODELOBJECT "modelobject" +namespace caf { + constexpr auto version = "version"; + constexpr auto root = "hopsanobjectappearance"; + constexpr auto modelobject = "modelobject"; +} enum AbsoluteRelativeEnumT {Absolute, Relative}; diff --git a/HopsanGUI/GUIObjects/GUIWidgets.cpp b/HopsanGUI/GUIObjects/GUIWidgets.cpp index 1d81cd7153..4e5f4b3225 100644 --- a/HopsanGUI/GUIObjects/GUIWidgets.cpp +++ b/HopsanGUI/GUIObjects/GUIWidgets.cpp @@ -206,7 +206,7 @@ WidgetTypesEnumT TextBoxWidget::getWidgetType() const QString TextBoxWidget::getHmfTagName() const { - return HMF_TEXTBOXWIDGETTAG; + return hmf::widget::textboxwidget; } @@ -217,39 +217,39 @@ void TextBoxWidget::saveToDomElement(QDomElement &rDomElement, SaveContentsEnumT QDomElement xmlObject = appendDomElement(rDomElement, getHmfTagName()); //Save GUI related stuff - QDomElement xmlGuiStuff = appendDomElement(xmlObject,HMF_HOPSANGUITAG); + QDomElement xmlGuiStuff = appendDomElement(xmlObject,hmf::hopsangui); QPointF pos = mapToScene(boundingRect().topLeft()); - QDomElement xmlPose = appendDomElement(xmlGuiStuff, HMF_POSETAG); - setQrealAttribute(xmlPose, "x", pos.x()); - setQrealAttribute(xmlPose, "y", pos.y()); + QDomElement xmlPose = appendDomElement(xmlGuiStuff, hmf::appearance::pose); + setQrealAttribute(xmlPose, hmf::widget::x, pos.x()); + setQrealAttribute(xmlPose, hmf::widget::y, pos.y()); - QDomElement xmlText = appendDomElement(xmlGuiStuff, "textobject"); - xmlText.setAttribute("text", mpTextItem->toPlainText()); - xmlText.setAttribute("font", mpTextItem->font().toString()); - xmlText.setAttribute("fontcolor", mpTextItem->defaultTextColor().name()); - xmlText.setAttribute("reflow", mReflowText); + QDomElement xmlText = appendDomElement(xmlGuiStuff, hmf::widget::textobject); + xmlText.setAttribute(hmf::widget::text, mpTextItem->toPlainText()); + xmlText.setAttribute(hmf::widget::font, mpTextItem->font().toString()); + xmlText.setAttribute(hmf::widget::fontcolor, mpTextItem->defaultTextColor().name()); + xmlText.setAttribute(hmf::widget::reflow, mReflowText); - QDomElement xmlSize = appendDomElement(xmlGuiStuff, "size"); - setQrealAttribute(xmlSize, "width", mpBorderItem->rect().width()); - setQrealAttribute(xmlSize, "height", mpBorderItem->rect().height()); + QDomElement xmlSize = appendDomElement(xmlGuiStuff, hmf::widget::size); + setQrealAttribute(xmlSize, hmf::widget::width, mpBorderItem->rect().width()); + setQrealAttribute(xmlSize, hmf::widget::height, mpBorderItem->rect().height()); - QDomElement xmlLine = appendDomElement(xmlGuiStuff, "line"); - xmlLine.setAttribute("visible", mpBorderItem->isVisible()); - xmlLine.setAttribute("width", mpBorderItem->pen().width()); - xmlLine.setAttribute("color", mpBorderItem->pen().color().name()); + QDomElement xmlLine = appendDomElement(xmlGuiStuff, hmf::widget::line); + xmlLine.setAttribute(hmf::widget::visible, mpBorderItem->isVisible()); + xmlLine.setAttribute(hmf::widget::width, mpBorderItem->pen().width()); + xmlLine.setAttribute(hmf::widget::color, mpBorderItem->pen().color().name()); QString style; if(mpBorderItem->pen().style() == Qt::SolidLine) - style = "solidline"; + style = hmf::widget::solidline; else if(mpBorderItem->pen().style() == Qt::DashLine) - style = "dashline"; + style = hmf::widget::dashline; else if(mpBorderItem->pen().style() == Qt::DotLine) - style = "dotline"; + style = hmf::widget::dotline; else if(mpBorderItem->pen().style() == Qt::DashDotLine) - style = "dashdotline"; - xmlLine.setAttribute(HMF_STYLETAG, style); + style = hmf::widget::dashdotline; + xmlLine.setAttribute(hmf::connector::style, style); } void TextBoxWidget::loadFromDomElement(QDomElement domElement) @@ -258,32 +258,32 @@ void TextBoxWidget::loadFromDomElement(QDomElement domElement) QColor textColor, lineColor; // Read gui specific stuff - QDomElement guiData = domElement.firstChildElement(HMF_HOPSANGUITAG); + QDomElement guiData = domElement.firstChildElement(hmf::hopsangui); // Text - QDomElement textObject = guiData.firstChildElement("textobject"); - QString text = textObject.attribute("text"); - font.fromString(textObject.attribute("font")); - textColor.setNamedColor(textObject.attribute("fontcolor")); - bool reflowText = parseAttributeBool(textObject, "reflow", false); + QDomElement textObject = guiData.firstChildElement(hmf::widget::textobject); + QString text = textObject.attribute(hmf::widget::text); + font.fromString(textObject.attribute(hmf::widget::font)); + textColor.setNamedColor(textObject.attribute(hmf::widget::fontcolor)); + bool reflowText = parseAttributeBool(textObject, hmf::widget::reflow, false); // Box - QDomElement poseTag = guiData.firstChildElement(HMF_POSETAG); - QPointF point( parseAttributeQreal(poseTag,"x",0), parseAttributeQreal(poseTag,"y",0)); - QDomElement sizeTag = guiData.firstChildElement("size"); - double width = parseAttributeQreal(sizeTag, "width", 10); - double height = parseAttributeQreal(sizeTag, "height", 10); - QDomElement lineTag = guiData.firstChildElement("line"); - bool lineVisible = parseAttributeBool(lineTag, "visible", true); - int linewidth = parseAttributeInt(lineTag, "width", 1); + QDomElement poseTag = guiData.firstChildElement(hmf::appearance::pose); + QPointF point( parseAttributeQreal(poseTag,hmf::widget::x,0), parseAttributeQreal(poseTag,hmf::widget::y,0)); + QDomElement sizeTag = guiData.firstChildElement(hmf::widget::size); + double width = parseAttributeQreal(sizeTag, hmf::widget::width, 10); + double height = parseAttributeQreal(sizeTag, hmf::widget::height, 10); + QDomElement lineTag = guiData.firstChildElement(hmf::widget::line); + bool lineVisible = parseAttributeBool(lineTag, hmf::widget::visible, true); + int linewidth = parseAttributeInt(lineTag, hmf::widget::width, 1); //! @todo this check is for backwards compatibility, remove in the future (added 20140224) if (linewidth == 1) { // Try double parsing - linewidth = parseAttributeQreal(lineTag, "width", linewidth); + linewidth = parseAttributeQreal(lineTag, hmf::widget::width, linewidth); } - QString linestyle = lineTag.attribute(HMF_STYLETAG); - lineColor.setNamedColor(lineTag.attribute("color",textColor.name())); + QString linestyle = lineTag.attribute(hmf::widget::style); + lineColor.setNamedColor(lineTag.attribute(hmf::widget::color,textColor.name())); setText(text); setFont(font); @@ -845,17 +845,17 @@ void ImageWidget::saveToDomElement(QDomElement &rDomElement, SaveContentsEnumT c QDomElement xmlObject = appendDomElement(rDomElement, getHmfTagName()); //Save GUI related stuff - QDomElement xmlGuiStuff = appendDomElement(xmlObject,HMF_HOPSANGUITAG); + QDomElement xmlGuiStuff = appendDomElement(xmlObject,hmf::hopsangui); QPointF pos = mapToScene(boundingRect().topLeft()); - QDomElement xmlPose = appendDomElement(xmlGuiStuff, HMF_POSETAG); - setQrealAttribute(xmlPose, hmf::x, pos.x()); - setQrealAttribute(xmlPose, hmf::y, pos.y()); + QDomElement xmlPose = appendDomElement(xmlGuiStuff, hmf::appearance::pose); + setQrealAttribute(xmlPose, hmf::widget::x, pos.x()); + setQrealAttribute(xmlPose, hmf::widget::y, pos.y()); - QDomElement xmlImage = appendDomElement(xmlGuiStuff, hmf::image); - xmlImage.setAttribute(hmf::path, mImagePath); - xmlImage.setAttribute(hmf::scale, mpImage->scale()); + QDomElement xmlImage = appendDomElement(xmlGuiStuff, hmf::widget::image); + xmlImage.setAttribute(hmf::widget::path, mImagePath); + xmlImage.setAttribute(hmf::widget::scale, mpImage->scale()); } WidgetTypesEnumT ImageWidget::getWidgetType() const @@ -865,7 +865,7 @@ WidgetTypesEnumT ImageWidget::getWidgetType() const QString ImageWidget::getHmfTagName() const { - return hmf::imagewidget; + return hmf::widget::imagewidget; } void ImageWidget::setImage(const QString &path, double iconScale) @@ -1006,7 +1006,7 @@ void ImageWidget::flipHorizontal(UndoStatusEnumT undoSettings) void ImageWidget::browseForImageFile() { QString filePath = QFileDialog::getOpenFileName(gpMainWindowWidget, tr("Select Image File"), - gpConfig->getStringSetting(CFG_MODELGFXDIR), + gpConfig->getStringSetting(cfg::dir::modelgfx), tr("Scalar Vector Graphics (*.svg)")); if(!filePath.isEmpty()) { mpEditDialogPathLineEdit->setText(filePath); @@ -1033,18 +1033,18 @@ void ImageWidget::updateWidgetFromDialog() void ImageWidget::loadFromDomElement(QDomElement domElement) { // Read gui specific stuff - QDomElement guiData = domElement.firstChildElement(HMF_HOPSANGUITAG); + QDomElement guiData = domElement.firstChildElement(hmf::hopsangui); //Pose - QDomElement poseObject = guiData.firstChildElement(HMF_POSETAG); - double x = parseAttributeQreal(poseObject, hmf::x, 0); - double y = parseAttributeQreal(poseObject, hmf::y, 0); + QDomElement poseObject = guiData.firstChildElement(hmf::appearance::pose); + double x = parseAttributeQreal(poseObject, hmf::widget::x, 0); + double y = parseAttributeQreal(poseObject, hmf::widget::y, 0); this->setPos(x, y); // Image - QDomElement imageObject = guiData.firstChildElement(hmf::image); - QString path = imageObject.attribute(hmf::path); - double scale = parseAttributeQreal(imageObject, hmf::scale, 1.0); + QDomElement imageObject = guiData.firstChildElement(hmf::widget::image); + QString path = imageObject.attribute(hmf::widget::path); + double scale = parseAttributeQreal(imageObject, hmf::widget::scale, 1.0); setImage(path, scale); refreshWidgetSize(); diff --git a/HopsanGUI/GUIPort.cpp b/HopsanGUI/GUIPort.cpp index eb1ebceb14..794300345c 100644 --- a/HopsanGUI/GUIPort.cpp +++ b/HopsanGUI/GUIPort.cpp @@ -325,7 +325,7 @@ void Port::openRightClickMenu(QPoint screenPos) { if (variameterDescriptions[i].mPortName == this->getName()) { - if (gpConfig->getBoolSetting(CFG_SHOWHIDDENNODEDATAVARIABLES) || (variameterDescriptions[i].mVariabelType != "Hidden")) + if (gpConfig->getBoolSetting(cfg::showhiddennodedatavariables) || (variameterDescriptions[i].mVariabelType != "Hidden")) { QAction *pAliasAction; if (variameterDescriptions[i].mAlias.isEmpty()) diff --git a/HopsanGUI/GraphicsView.cpp b/HopsanGUI/GraphicsView.cpp index 6a00e643e9..d46c12e0aa 100644 --- a/HopsanGUI/GraphicsView.cpp +++ b/HopsanGUI/GraphicsView.cpp @@ -87,7 +87,9 @@ GraphicsView::GraphicsView(ModelWidget *parent) this->setViewportUpdateMode(QGraphicsView::FullViewportUpdate); this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - this->setSceneRect(0,0,5000,5000); + //This scene rect is needed because the old scene was (0,0) - (5000,5000) with center in (2500,2500). + //We need to ensure the center is still at the same position even though the scene is now larger. + this->setSceneRect(-25000+2500,-25000+2500,25000+2500,25000+2500); this->centerOn(this->sceneRect().center()); mIsoColor = QColor("white"); @@ -104,7 +106,7 @@ GraphicsView::GraphicsView(ModelWidget *parent) hideAddComponentLineEdit(); this->updateViewPort(); - this->setRenderHint(QPainter::Antialiasing, gpConfig->getBoolSetting(CFG_ANTIALIASING)); + this->setRenderHint(QPainter::Antialiasing, gpConfig->getBoolSetting(cfg::antialiasing)); } @@ -836,12 +838,12 @@ void GraphicsView::print() void GraphicsView::exportToPDF() { QString fileName = QFileDialog::getSaveFileName( - this, "Export File Name", gpConfig->getStringSetting(CFG_MODELGFXDIR), + this, "Export File Name", gpConfig->getStringSetting(cfg::dir::modelgfx), "Adobe PDF Documents (*.pdf)"); if ( !fileName.isEmpty() ) { QFileInfo file(fileName); - gpConfig->setStringSetting(CFG_MODELGFXDIR, file.absolutePath()); + gpConfig->setStringSetting(cfg::dir::modelgfx, file.absolutePath()); //Here we set A0, Landscape and Fullpage among other things to make sure that components get large enough to be treated as vector graphics //Some bug or "feature" makes small objects be converted to bitmaps (ugly) @@ -912,13 +914,13 @@ void GraphicsView::exportToPNG() double res = pScaleEdit->text().toDouble(); // Open save dialog to get the file name - QString fileName = QFileDialog::getSaveFileName(this, "Export File Name", gpConfig->getStringSetting(CFG_MODELGFXDIR), "Portable Network Graphics (*.png)"); + QString fileName = QFileDialog::getSaveFileName(this, "Export File Name", gpConfig->getStringSetting(cfg::dir::modelgfx), "Portable Network Graphics (*.png)"); // Attempt to save if user did select a filename if(!fileName.isEmpty()) { QFileInfo file(fileName); - gpConfig->setStringSetting(CFG_MODELGFXDIR, file.absolutePath()); + gpConfig->setStringSetting(cfg::dir::modelgfx, file.absolutePath()); pScene->setSceneRect(pScene->itemsBoundingRect()); qDebug() << "itemsBoundingRect(): " << pScene->itemsBoundingRect().width() << "*" << pScene->itemsBoundingRect().height(); @@ -990,7 +992,7 @@ AnimatedGraphicsView::AnimatedGraphicsView(QGraphicsScene *pScene, QWidget *pPar mZoomFactor = 1.0; this->updateViewPort(); - this->setRenderHint(QPainter::Antialiasing, gpConfig->getBoolSetting(CFG_ANTIALIASING)); + this->setRenderHint(QPainter::Antialiasing, gpConfig->getBoolSetting(cfg::antialiasing)); connect(this, SIGNAL(hovered()), gpLibraryWidget, SLOT(clearHoverEffects())); //connect(this, SIGNAL(hovered()), gpPlotWidget, SLOT(clearHoverEffects())); diff --git a/HopsanGUI/HcomHandler.cpp b/HopsanGUI/HcomHandler.cpp index 6cd6b30666..0ab250ff29 100644 --- a/HopsanGUI/HcomHandler.cpp +++ b/HopsanGUI/HcomHandler.cpp @@ -4020,7 +4020,7 @@ void HcomHandler::executeSetCommand(const QString cmd) HCOMERR("Unknown value."); return; } - getConfigPtr()->setBoolSetting(CFG_MULTICORE, value=="on"); + getConfigPtr()->setBoolSetting(cfg::multicore, value=="on"); } else if(pref == "threads") { @@ -4035,7 +4035,7 @@ void HcomHandler::executeSetCommand(const QString cmd) HCOMERR("Number of simulation threads must be a positive integer."); return; } - getConfigPtr()->setIntegerSetting(CFG_NUMBEROFTHREADS, mAnsScalar); + getConfigPtr()->setIntegerSetting(cfg::numberofthreads, mAnsScalar); } else if(pref == "algorithm") { @@ -4053,7 +4053,7 @@ void HcomHandler::executeSetCommand(const QString cmd) { HCOMERR("Unknown value."); } - getConfigPtr()->setBoolSetting(CFG_CACHELOGDATA, value=="on"); + getConfigPtr()->setBoolSetting(cfg::cachelogdata, value=="on"); } else if(pref == "generationlimit") { @@ -4068,7 +4068,7 @@ void HcomHandler::executeSetCommand(const QString cmd) HCOMERR("Generation limit must be a positive integer."); return; } - getConfigPtr()->setIntegerSetting(CFG_GENERATIONLIMIT, mAnsScalar); + getConfigPtr()->setIntegerSetting(cfg::generationlimit, mAnsScalar); } else if(pref == "samples") { @@ -4099,7 +4099,7 @@ void HcomHandler::executeSetCommand(const QString cmd) { HCOMERR("Unknown value."); } - getConfigPtr()->setBoolSetting(CFG_AUTOBACKUP, value=="on"); + getConfigPtr()->setBoolSetting(cfg::autobackup, value=="on"); } else if(pref == "progressbar") { @@ -4107,7 +4107,7 @@ void HcomHandler::executeSetCommand(const QString cmd) { HCOMERR("Unknown value."); } - getConfigPtr()->setBoolSetting(CFG_PROGRESSBAR, value=="on"); + getConfigPtr()->setBoolSetting(cfg::progressbar, value=="on"); } else if(pref == "progressbarstep") { @@ -4122,7 +4122,7 @@ void HcomHandler::executeSetCommand(const QString cmd) HCOMERR("Progress bar step size must be a positive integer."); return; } - getConfigPtr()->setIntegerSetting(CFG_PROGRESSBARSTEP, mAnsScalar); + getConfigPtr()->setIntegerSetting(cfg::progressbarstep, mAnsScalar); } else { @@ -4152,7 +4152,7 @@ void HcomHandler::executeGetCommand(const QString cmd) if(all || pref == "multicore") { QString output = "Multi-threaded simulation: "; - if(getConfigPtr()->getBoolSetting(CFG_MULTICORE)) + if(getConfigPtr()->getBoolSetting(cfg::multicore)) output.append("ON"); else output.append("OFF"); @@ -4161,7 +4161,7 @@ void HcomHandler::executeGetCommand(const QString cmd) if(all || pref == "threads") { QString output = "Simulation threads: "; - output.append(QString::number(getConfigPtr()->getIntegerSetting(CFG_NUMBEROFTHREADS))+""); + output.append(QString::number(getConfigPtr()->getIntegerSetting(cfg::numberofthreads))+""); HCOMPRINT(output); } if(all || pref == "algorithm") @@ -4191,7 +4191,7 @@ void HcomHandler::executeGetCommand(const QString cmd) if(all || pref == "cachetodisk") { QString output = "Cache log data to disk: "; - if(getConfigPtr()->getBoolSetting(CFG_CACHELOGDATA)) + if(getConfigPtr()->getBoolSetting(cfg::cachelogdata)) output.append("ON"); else output.append("OFF"); @@ -4200,7 +4200,7 @@ void HcomHandler::executeGetCommand(const QString cmd) if(all || pref == "generationlimit") { QString output = "Generation limit: "; - output.append(QString::number(getConfigPtr()->getIntegerSetting(CFG_GENERATIONLIMIT))+""); + output.append(QString::number(getConfigPtr()->getIntegerSetting(cfg::generationlimit))+""); HCOMPRINT(output); } if(all || pref == "samples") @@ -4237,7 +4237,7 @@ void HcomHandler::executeGetCommand(const QString cmd) if(all || pref == "backup") { QString output = "Auto-backup: "; - if(getConfigPtr()->getBoolSetting(CFG_AUTOBACKUP)) + if(getConfigPtr()->getBoolSetting(cfg::autobackup)) output.append("ON"); else output.append("OFF"); @@ -4246,7 +4246,7 @@ void HcomHandler::executeGetCommand(const QString cmd) if(all || pref == "progressbar") { QString output = "Progres bar: "; - if(getConfigPtr()->getBoolSetting(CFG_PROGRESSBAR)) + if(getConfigPtr()->getBoolSetting(cfg::progressbar)) output.append("ON"); else output.append("OFF"); @@ -4255,7 +4255,7 @@ void HcomHandler::executeGetCommand(const QString cmd) if(all || pref == "progressbarstep") { QString output = "Progress bar step size: "; - output.append(QString::number(getConfigPtr()->getIntegerSetting(CFG_PROGRESSBARSTEP))+""); + output.append(QString::number(getConfigPtr()->getIntegerSetting(cfg::progressbarstep))+""); HCOMPRINT(output); } } @@ -5683,8 +5683,8 @@ void HcomHandler::executeSetMultiThreadingCommand(const QString cmd) } } - getConfigPtr()->setBoolSetting(CFG_MULTICORE, useMultiThreading); - if(nArgs > 1) getConfigPtr()->setIntegerSetting(CFG_NUMBEROFTHREADS, nThreads); + getConfigPtr()->setBoolSetting(cfg::multicore, useMultiThreading); + if(nArgs > 1) getConfigPtr()->setIntegerSetting(cfg::numberofthreads, nThreads); if(nArgs > 2) getConfigPtr()->setParallelAlgorithm(algorithm); } @@ -7809,7 +7809,7 @@ void HcomHandler::splitAtFirst(QString str, QString c, QString &left, QString &r void HcomHandler::updatePwd() { - if(mpModel && mpModel->isSaved() && gpConfig->getBoolSetting(CFG_SETPWDTOMWD)) + if(mpModel && mpModel->isSaved() && gpConfig->getBoolSetting(cfg::setpwdtomwd)) { mPwd = mpModel->getTopLevelSystemContainer()->getModelFileInfo().absoluteDir().path(); } diff --git a/HopsanGUI/LibraryHandler.cpp b/HopsanGUI/LibraryHandler.cpp index 536ed817c5..dff563357f 100644 --- a/HopsanGUI/LibraryHandler.cpp +++ b/HopsanGUI/LibraryHandler.cpp @@ -32,20 +32,25 @@ //$Id$ //Defines -#define XML_LIBRARY "hopsancomponentlibrary" -#define XML_VERSION "version" -#define XML_RECOMPILABLE "recompilable" -#define XML_LIBRARY_NAME "name" -#define XML_LIBRARY_ID "id" -#define XML_LIBRARY_LIB "lib" -#define XML_LIBRARY_LIB_DBGEXT "debug_ext" -#define XML_LIBRARY_CAF "caf" -#define XML_LIBRARY_SOURCE "source" -#define XML_LIBRARY_EXTRA_SOURCE "extrasource" -#define XML_LIBRARY_INCLUDEPATH "includepath" -#define XML_LIBRARY_LINKPATH "linkpath" -#define XML_LIBRARY_LINKLIBRARY "linklibrary" -#define XML_COMPONENT_XML "componentxml" +namespace libxml { + constexpr auto root = "hopsancomponentlibrary"; + constexpr auto version = "version"; + constexpr auto recompilable = "recompilable"; + constexpr auto name = "name"; + constexpr auto id = "id"; + constexpr auto lib = "lib"; + constexpr auto source = "source"; + constexpr auto extrasource = "extrasource"; + constexpr auto includepath = "includepath"; + constexpr auto linkpath = "linkpath"; + constexpr auto linklibrary = "linklibrary"; + constexpr auto componentxml = "componentxml"; + constexpr auto debugextension = "debug_ext"; + constexpr auto componentappearancefile = "caf"; + constexpr auto buildflags = "buildflags"; + constexpr auto cflags = "cflags"; + constexpr auto lflags = "lflags"; +} #include #include @@ -131,7 +136,7 @@ LibraryHandler::LibraryHandler(QObject *parent) void LibraryHandler::loadLibrary() { QString libDir = QFileDialog::getExistingDirectory(gpMainWindowWidget, tr("Choose Library Directory"), - gpConfig->getStringSetting(CFG_EXTERNALLIBDIR), + gpConfig->getStringSetting(cfg::dir::externallib), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if(libDir.isEmpty()) @@ -140,7 +145,7 @@ void LibraryHandler::loadLibrary() } else { - gpConfig->setStringSetting(CFG_EXTERNALLIBDIR,libDir); + gpConfig->setStringSetting(cfg::dir::externallib,libDir); loadLibrary(libDir); @@ -199,7 +204,7 @@ void LibraryHandler::loadLibrary(QString loadPath, LibraryTypeEnumT type, Hidden { // Here only library xml files are interesting, other xml files are ignored QDomElement xmlRoot = domDocument.documentElement(); - if(xmlRoot.tagName() == QString(XML_LIBRARY)) + if(xmlRoot.tagName() == QString(libxml::root)) { foundLibraryXmlFiles.append(fileInfo.canonicalFilePath()); } @@ -237,14 +242,14 @@ void LibraryHandler::loadLibrary(QString loadPath, LibraryTypeEnumT type, Hidden { // The document must have library root tag to be valid QDomElement xmlRoot = domDocument.documentElement(); - if(xmlRoot.tagName() == QString(XML_LIBRARY)) + if(xmlRoot.tagName() == QString(libxml::root)) { foundLibraryXmlFiles.append(fileInfo.canonicalFilePath()); } else { gpMessageHandler->addErrorMessage(QString("The specified XML file does not have Hopsan library root element. Expected: %1, Found: %2, In: %3") - .arg(XML_LIBRARY).arg(xmlRoot.tagName()).arg(fileInfo.canonicalFilePath())); + .arg(libxml::root).arg(xmlRoot.tagName()).arg(fileInfo.canonicalFilePath())); } } else @@ -913,7 +918,7 @@ void LibraryHandler::createNewLibrary() { return; } if(!libName.isEmpty()) { - QString libDirPath = QFileDialog::getExistingDirectory(gpMainWindowWidget, "Choose Library Directory", gpConfig->getStringSetting(CFG_EXTERNALLIBDIR)); + QString libDirPath = QFileDialog::getExistingDirectory(gpMainWindowWidget, "Choose Library Directory", gpConfig->getStringSetting(cfg::dir::externallib)); QDir libDir(libDirPath); if(libDir.entryList(QDir::AllDirs).contains(libName)) { QMessageBox existWarningBox(QMessageBox::Warning, "Warning", "Directory already contains a sub-folder with specified type name. Do you want to create new library here anyway?", nullptr, nullptr); @@ -1124,16 +1129,16 @@ bool LibraryHandler::loadLibrary(SharedComponentLibraryPtrT pLibrary, LibraryTyp if(domDocument.setContent(&file, false, &errorStr, &errorLine, &errorColumn)) { QDomElement xmlRoot = domDocument.documentElement(); - if(xmlRoot.tagName() == QString(XML_LIBRARY)) + if(xmlRoot.tagName() == QString(libxml::root)) { - pLibrary->version = xmlRoot.attribute(XML_VERSION); - pLibrary->recompilable = parseAttributeBool(xmlRoot, XML_RECOMPILABLE, true); + pLibrary->version = xmlRoot.attribute(libxml::version); + pLibrary->recompilable = parseAttributeBool(xmlRoot, libxml::recompilable, true); // Read name of library - pLibrary->name = xmlRoot.firstChildElement(XML_LIBRARY_NAME).text(); + pLibrary->name = xmlRoot.firstChildElement(libxml::name).text(); if (pLibrary->name.isEmpty()) { // Try fall-back loading deprecated name attribute - if(xmlRoot.hasAttribute(XML_LIBRARY_NAME)) { - pLibrary->name = xmlRoot.attribute(XML_LIBRARY_NAME); + if(xmlRoot.hasAttribute(libxml::name)) { + pLibrary->name = xmlRoot.attribute(libxml::name); } } @@ -1145,7 +1150,7 @@ bool LibraryHandler::loadLibrary(SharedComponentLibraryPtrT pLibrary, LibraryTyp } // Read id of library - pLibrary->id = xmlRoot.firstChildElement(XML_LIBRARY_ID).text(); + pLibrary->id = xmlRoot.firstChildElement(libxml::id).text(); if (pLibrary->id.isEmpty()) { gpMessageHandler->addWarningMessage(QString("Library: %1 is missing the element, or id is empty. Using name '%2' as fall-back.") .arg(libraryMainFileInfo.canonicalFilePath()).arg(pLibrary->name)); @@ -1162,10 +1167,10 @@ bool LibraryHandler::loadLibrary(SharedComponentLibraryPtrT pLibrary, LibraryTyp } // Read library share lib file - QDomElement libElement = xmlRoot.firstChildElement(XML_LIBRARY_LIB); + QDomElement libElement = xmlRoot.firstChildElement(libxml::lib); if(!libElement.isNull()) { - pLibrary->debugExtension = libElement.attribute(XML_LIBRARY_LIB_DBGEXT,""); + pLibrary->debugExtension = libElement.attribute(libxml::debugextension,""); pLibrary->libFilePath = libraryMainFileInfo.canonicalPath()+"/"+QString(LIBPREFIX)+libElement.text(); #ifdef HOPSAN_BUILD_TYPE_DEBUG pLibrary->libFilePath += pLibrary->debugExtension; @@ -1174,14 +1179,14 @@ bool LibraryHandler::loadLibrary(SharedComponentLibraryPtrT pLibrary, LibraryTyp } // Read build flags - QDomElement bfElement = xmlRoot.firstChildElement("buildflags").firstChildElement(); + QDomElement bfElement = xmlRoot.firstChildElement(libxml::buildflags).firstChildElement(); while (!bfElement.isNull()) { - if (bfElement.tagName() == "cflags") + if (bfElement.tagName() == libxml::cflags) { pLibrary->cflags.append(" "+bfElement.text()); } - else if (bfElement.tagName() == "lflags") + else if (bfElement.tagName() == libxml::lflags) { pLibrary->lflags.append(" "+bfElement.text()); } @@ -1189,46 +1194,46 @@ bool LibraryHandler::loadLibrary(SharedComponentLibraryPtrT pLibrary, LibraryTyp bfElement = bfElement.nextSiblingElement(); } - QDomElement includePathElement = xmlRoot.firstChildElement(QString(XML_LIBRARY_INCLUDEPATH)); + QDomElement includePathElement = xmlRoot.firstChildElement(QString(libxml::includepath)); while(!includePathElement.isNull()) { pLibrary->includePaths.append(includePathElement.text()); - includePathElement = includePathElement.nextSiblingElement(QString(XML_LIBRARY_INCLUDEPATH)); + includePathElement = includePathElement.nextSiblingElement(QString(libxml::includepath)); } - QDomElement linkPathElement = xmlRoot.firstChildElement(QString(XML_LIBRARY_LINKPATH)); + QDomElement linkPathElement = xmlRoot.firstChildElement(QString(libxml::linkpath)); while(!linkPathElement.isNull()) { pLibrary->linkPaths.append(linkPathElement.text()); - linkPathElement = linkPathElement.nextSiblingElement(QString(XML_LIBRARY_LINKPATH)); + linkPathElement = linkPathElement.nextSiblingElement(QString(libxml::linkpath)); } - QDomElement linkLibraryElement = xmlRoot.firstChildElement(QString(XML_LIBRARY_LINKLIBRARY)); + QDomElement linkLibraryElement = xmlRoot.firstChildElement(QString(libxml::linklibrary)); while(!linkLibraryElement.isNull()) { pLibrary->linkLibraries.append(linkLibraryElement.text()); - linkLibraryElement = linkLibraryElement.nextSiblingElement(QString(XML_LIBRARY_LINKLIBRARY)); + linkLibraryElement = linkLibraryElement.nextSiblingElement(QString(libxml::linklibrary)); } // Read source files - QDomElement sourceElement = xmlRoot.firstChildElement(QString(XML_LIBRARY_SOURCE)); + QDomElement sourceElement = xmlRoot.firstChildElement(QString(libxml::source)); while(!sourceElement.isNull()) { pLibrary->sourceFiles.append(QFileInfo(file).canonicalPath()+"/"+sourceElement.text()); - sourceElement = sourceElement.nextSiblingElement(QString(XML_LIBRARY_SOURCE)); + sourceElement = sourceElement.nextSiblingElement(QString(libxml::source)); } // Read extra source files - QDomElement extraSourceElement = xmlRoot.firstChildElement(QString(XML_LIBRARY_EXTRA_SOURCE)); + QDomElement extraSourceElement = xmlRoot.firstChildElement(QString(libxml::extrasource)); while(!extraSourceElement.isNull()) { pLibrary->sourceFiles.append(QFileInfo(file).canonicalPath()+"/"+extraSourceElement.text()); - extraSourceElement = extraSourceElement.nextSiblingElement(QString(XML_LIBRARY_EXTRA_SOURCE)); + extraSourceElement = extraSourceElement.nextSiblingElement(QString(libxml::extrasource)); } // Read components if(!libraryFormatVersionLessThen(pLibrary->version.toDouble(), 0.3)) { - QDomElement cafElement = xmlRoot.firstChildElement(QString(XML_COMPONENT_XML)); + QDomElement cafElement = xmlRoot.firstChildElement(QString(libxml::componentxml)); while(!cafElement.isNull()) { pLibrary->cafFiles.append(libraryRootDir.absoluteFilePath(cafElement.text())); - cafElement = cafElement.nextSiblingElement(QString(XML_COMPONENT_XML)); + cafElement = cafElement.nextSiblingElement(QString(libxml::componentxml)); } qDebug() << "CAF files: " << pLibrary->cafFiles; } @@ -1273,7 +1278,7 @@ bool LibraryHandler::loadLibrary(SharedComponentLibraryPtrT pLibrary, LibraryTyp else { gpMessageHandler->addErrorMessage(QString("The specified XML file does not have Hopsan library root element. Expected: %1, Found: %2, In: %3") - .arg(XML_LIBRARY).arg(xmlRoot.tagName()).arg(libraryMainFileInfo.canonicalFilePath())); + .arg(libxml::root).arg(xmlRoot.tagName()).arg(libraryMainFileInfo.canonicalFilePath())); return false; } } @@ -1316,7 +1321,7 @@ bool LibraryHandler::loadLibrary(SharedComponentLibraryPtrT pLibrary, LibraryTyp if(domDocument.setContent(&cafFile, false, &errorStr, &errorLine, &errorColumn)) { QDomElement cafRoot = domDocument.documentElement(); - if(cafRoot.tagName() == QString(CAF_ROOT)) + if(cafRoot.tagName() == QString(caf::root)) { pLibrary->cafFiles.append(cafFileInfo.absoluteFilePath()); } @@ -1349,9 +1354,9 @@ bool LibraryHandler::loadLibrary(SharedComponentLibraryPtrT pLibrary, LibraryTyp int errorLine, errorColumn; if(domDocument.setContent(&cafFile, false, &errorStr, &errorLine, &errorColumn)) { QDomElement cafRoot = domDocument.documentElement(); - if(cafRoot.tagName() == QString(CAF_ROOT)) { + if(cafRoot.tagName() == QString(caf::root)) { //Read appearance data from the caf xml file, begin with the first - QDomElement xmlModelObjectAppearance = cafRoot.firstChildElement(CAF_MODELOBJECT); //! @todo extend this code to be able to read many appearance objects from same file + QDomElement xmlModelObjectAppearance = cafRoot.firstChildElement(caf::modelobject); //! @todo extend this code to be able to read many appearance objects from same file SharedModelObjectAppearanceT pAppearanceData = SharedModelObjectAppearanceT(new ModelObjectAppearance); pAppearanceData->setBasePath(QFileInfo(cafFile).absolutePath()+"/"); pAppearanceData->setXMLFile(QFileInfo(cafFile)); @@ -1359,7 +1364,7 @@ bool LibraryHandler::loadLibrary(SharedComponentLibraryPtrT pLibrary, LibraryTyp pAppearanceData->cacheIcons(); // Check CAF version, and ask user if they want to update to latest version - QString caf_version = cafRoot.attribute(CAF_VERSION); + QString caf_version = cafRoot.attribute(caf::version); if (caf_version < CAF_VERSIONNUM) { bool doSave=false; @@ -1659,7 +1664,7 @@ void LibraryHandler::importFmu() { //Load .fmu file and create paths QString filePath = QFileDialog::getOpenFileName(gpMainWindowWidget, tr("Import Functional Mockup Unit (FMU)"), - gpConfig->getStringSetting(CFG_FMUIMPORTDIR), + gpConfig->getStringSetting(cfg::dir::fmuimport), tr("Functional Mockup Unit (*.fmu)")); if(filePath.isEmpty()) //Cancelled by user return; @@ -1670,7 +1675,7 @@ void LibraryHandler::importFmu() gpMessageHandler->addErrorMessage("File not found: "+filePath); return; } - gpConfig->setStringSetting(CFG_FMUIMPORTDIR, fmuFileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::fmuimport, fmuFileInfo.absolutePath()); SystemObject *pSystem = gpModelHandler->getCurrentTopLevelSystem(); if(pSystem) { diff --git a/HopsanGUI/LogDataHandler2.cpp b/HopsanGUI/LogDataHandler2.cpp index 9af2a91238..10d08b6cef 100644 --- a/HopsanGUI/LogDataHandler2.cpp +++ b/HopsanGUI/LogDataHandler2.cpp @@ -116,7 +116,7 @@ void LogDataHandler2::exportToPlo(const QString &rFilePath, QList 3) ) { - version = gpConfig->getIntegerSetting(CFG_PLOEXPORTVERSION); + version = gpConfig->getIntegerSetting(cfg::ploexportversion); } if (variables.isEmpty()) @@ -408,7 +408,7 @@ void LogDataHandler2::importFromPlo(QString importFilePath) { importFilePath = QFileDialog::getOpenFileName(0,tr("Choose Hopsan .plo File"), - gpConfig->getStringSetting(CFG_PLOTDATADIR), + gpConfig->getStringSetting(cfg::dir::plotdata), tr("Hopsan File (*.plo)")); } if(importFilePath.isEmpty()) @@ -418,7 +418,7 @@ void LogDataHandler2::importFromPlo(QString importFilePath) QFile file(importFilePath); QFileInfo fileInfo(file); - gpConfig->setStringSetting(CFG_PLOTDATADIR, fileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::plotdata, fileInfo.absolutePath()); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -618,7 +618,7 @@ void LogDataHandler2::importFromCSV_AutoFormat(QString importFilePath) { importFilePath = QFileDialog::getOpenFileName(0,tr("Choose .csv File"), - gpConfig->getStringSetting(CFG_PLOTDATADIR), + gpConfig->getStringSetting(cfg::dir::plotdata), tr("Comma-separated values files (*.csv)")); } if(importFilePath.isEmpty()) @@ -698,7 +698,7 @@ void LogDataHandler2::importHopsanRowCSV(QString importFilePath) { importFilePath = QFileDialog::getOpenFileName(0,tr("Choose .csv File"), - gpConfig->getStringSetting(CFG_PLOTDATADIR), + gpConfig->getStringSetting(cfg::dir::plotdata), tr("Hopsan row based csv files (*.csv)")); } if(importFilePath.isEmpty()) @@ -708,7 +708,7 @@ void LogDataHandler2::importHopsanRowCSV(QString importFilePath) QFile file(importFilePath); QFileInfo fileInfo(file); - gpConfig->setStringSetting(CFG_PLOTDATADIR, fileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::plotdata, fileInfo.absolutePath()); bool parseOk = true; @@ -797,7 +797,7 @@ void LogDataHandler2::importFromPlainColumnCsv(QString importFilePath, const QCh if(importFilePath.isEmpty()) { importFilePath = QFileDialog::getOpenFileName(0,tr("Choose .csv File"), - gpConfig->getStringSetting(CFG_PLOTDATADIR), + gpConfig->getStringSetting(cfg::dir::plotdata), tr("Comma-separated values files (*.csv)")); } if(importFilePath.isEmpty()) @@ -807,7 +807,7 @@ void LogDataHandler2::importFromPlainColumnCsv(QString importFilePath, const QCh QFile file(importFilePath); QFileInfo fileInfo(file); - gpConfig->setStringSetting(CFG_PLOTDATADIR, fileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::plotdata, fileInfo.absolutePath()); QTextStream ts(&file); QStringList names; @@ -874,7 +874,7 @@ void LogDataHandler2::importFromPlainRowCsv(QString importFilePath, const QChar if(importFilePath.isEmpty()) { importFilePath = QFileDialog::getOpenFileName(0,tr("Choose .csv File"), - gpConfig->getStringSetting(CFG_PLOTDATADIR), + gpConfig->getStringSetting(cfg::dir::plotdata), tr("Comma-separated values files (*.csv)")); } if(importFilePath.isEmpty()) @@ -884,7 +884,7 @@ void LogDataHandler2::importFromPlainRowCsv(QString importFilePath, const QChar QFile file(importFilePath); QFileInfo fileInfo(file); - gpConfig->setStringSetting(CFG_PLOTDATADIR, fileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::plotdata, fileInfo.absolutePath()); bool parseOk = true; @@ -1226,7 +1226,7 @@ bool LogDataHandler2::collectLogDataFromSystem(SystemObject *pCurrentSystem, con for(auto &varDesc : varDescs) { // Skip hidden variables - if ( gpConfig->getBoolSetting(CFG_SHOWHIDDENNODEDATAVARIABLES) || (varDesc.mNodeDataVariableType != "Hidden") ) + if ( gpConfig->getBoolSetting(cfg::showhiddennodedatavariables) || (varDesc.mNodeDataVariableType != "Hidden") ) { // Fetch variable data QVector dataVec; @@ -1564,7 +1564,7 @@ void LogDataHandler2::limitPlotGenerations() const int generationLimit = gpConfig->getGenerationLimit(); if (numGens > generationLimit) { - if(!gpConfig->getBoolSetting(CFG_AUTOLIMITGENERATIONS)) + if(!gpConfig->getBoolSetting(cfg::autolimitgenerations)) { QDialog dialog(gpMainWindowWidget); dialog.setWindowTitle("Hopsan"); @@ -1573,7 +1573,7 @@ void LogDataHandler2::limitPlotGenerations() "
Number of data generations: "+QString::number(numGens)+ "

Discard "+QString::number(numGens-generationLimit)+" generations(s)?"); QCheckBox *pAutoLimitCheckBox = new QCheckBox("Automatically discard old generations", &dialog); - pAutoLimitCheckBox->setChecked(gpConfig->getBoolSetting(CFG_AUTOLIMITGENERATIONS)); + pAutoLimitCheckBox->setChecked(gpConfig->getBoolSetting(cfg::autolimitgenerations)); QDialogButtonBox *pButtonBox = new QDialogButtonBox(&dialog); QPushButton *pDiscardButton = pButtonBox->addButton("Discard", QDialogButtonBox::AcceptRole); QPushButton *pKeepButton = pButtonBox->addButton("Keep", QDialogButtonBox::RejectRole); @@ -1585,7 +1585,7 @@ void LogDataHandler2::limitPlotGenerations() pLayout->addWidget(pButtonBox); int retval = dialog.exec(); - gpConfig->setBoolSetting(CFG_AUTOLIMITGENERATIONS, pAutoLimitCheckBox->isChecked()); + gpConfig->setBoolSetting(cfg::autolimitgenerations, pAutoLimitCheckBox->isChecked()); if(retval == QDialog::Rejected) { diff --git a/HopsanGUI/MainWindow.cpp b/HopsanGUI/MainWindow.cpp index 8a6db9097d..ae791fa740 100644 --- a/HopsanGUI/MainWindow.cpp +++ b/HopsanGUI/MainWindow.cpp @@ -342,7 +342,7 @@ void MainWindow::createContents() this->updateRecentList(); // Update style sheet setting after all children has been created and added so that they too will be affected - if(!gpConfig->getBoolSetting(CFG_NATIVESTYLESHEET)) + if(!gpConfig->getBoolSetting(cfg::nativestylesheet)) { setStyleSheet(gpConfig->getStyleSheet()); setPalette(gpConfig->getPalette()); @@ -755,7 +755,7 @@ void MainWindow::createActions() gpToggleNamesAction = mpToggleNamesAction; mpToggleNamesAction->setText("Show Component Names (Ctrl+N)"); mpToggleNamesAction->setCheckable(true); - mpToggleNamesAction->setChecked(gpConfig->getBoolSetting(CFG_TOGGLENAMESBUTTONCHECKED)); + mpToggleNamesAction->setChecked(gpConfig->getBoolSetting(cfg::togglenamesbuttonchecked)); mpToggleNamesAction->setShortcut(QKeySequence("Ctrl+n")); connect(mpToggleNamesAction, SIGNAL(hovered()), this, SLOT(showToolBarHelpPopup())); mHelpPopupTextMap.insert(mpToggleNamesAction, "Toggle visibility of component names for all components."); @@ -907,7 +907,7 @@ void MainWindow::createActions() gpTogglePortsAction = mpTogglePortsAction; mpTogglePortsAction->setText("Show Unconnected Ports (Ctrl+T)"); mpTogglePortsAction->setCheckable(true); - mpTogglePortsAction->setChecked(gpConfig->getBoolSetting(CFG_TOGGLEPORTSBUTTONCHECKED)); + mpTogglePortsAction->setChecked(gpConfig->getBoolSetting(cfg::toggleportsbuttonchecked)); mpTogglePortsAction->setShortcut(QKeySequence("Ctrl+t")); connect(mpTogglePortsAction, SIGNAL(hovered()), this, SLOT(showToolBarHelpPopup())); mHelpPopupTextMap.insert(mpTogglePortsAction, "Toggle visibility of unconnected ports."); diff --git a/HopsanGUI/ModelHandler.cpp b/HopsanGUI/ModelHandler.cpp index e78ed06240..83f2ffeb55 100644 --- a/HopsanGUI/ModelHandler.cpp +++ b/HopsanGUI/ModelHandler.cpp @@ -237,12 +237,12 @@ void ModelHandler::loadModel() { QDir fileDialogOpenDir; QStringList modelFileNames = QFileDialog::getOpenFileNames(gpMainWindowWidget, tr("Choose Model File"), - gpConfig->getStringSetting(CFG_LOADMODELDIR), + gpConfig->getStringSetting(cfg::dir::loadmodel), tr("Hopsan Model Files (*.hmf *.xml)")); for(const QString &modelFileName : modelFileNames) { loadModel(modelFileName); QFileInfo fileInfo = QFileInfo(modelFileName); - gpConfig->setStringSetting(CFG_LOADMODELDIR, fileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::loadmodel, fileInfo.absolutePath()); } } @@ -252,7 +252,7 @@ void ModelHandler::loadModel() void ModelHandler::loadTextFile() { QStringList fileNames = QFileDialog::getOpenFileNames(gpMainWindowWidget, tr("Choose Text File"), - gpConfig->getStringSetting(CFG_LOADSCRIPTDIR), + gpConfig->getStringSetting(cfg::dir::loadscript), tr("All Supported Files (*.hcom *.hpp *.h *.cpp *.cc *.c *.xml *.mo *.py);;HCOM Script Files (*.hcom);;C++ Header Files (*.hpp *.h);;C++ Source Files (*.cpp *.cc *.c);;XML files (*.xml);;Modelica files (*.mo);;Python Script Files (*.py)")); for(const auto &fileName : fileNames) { @@ -269,7 +269,7 @@ void ModelHandler::loadTextFile() } loadTextFile(fileName); - gpConfig->setStringSetting(CFG_LOADSCRIPTDIR, fileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::loadscript, fileInfo.absolutePath()); } } @@ -853,6 +853,7 @@ void ModelHandler::restoreState() // mStateInfoLogDataHandlersList[i]->setParentContainerObject(getCurrentTopLevelSystem()); } gpCentralTabWidget->setCurrentIndex(mStateInfoIndex); + gpPlotWidget->updateList(); mStateInfoList.clear(); } diff --git a/HopsanGUI/OptimizationHandler.cpp b/HopsanGUI/OptimizationHandler.cpp index 48eadc2653..1dc3fedf15 100644 --- a/HopsanGUI/OptimizationHandler.cpp +++ b/HopsanGUI/OptimizationHandler.cpp @@ -128,12 +128,12 @@ void OptimizationHandler::startOptimization(ModelWidget *pModel, QString &modelP // connect(mpWorker, SIGNAL(pointChanged(int)), this, SLOT(logPoint(int))); // connect(mpWorker, SIGNAL(stepCompleted(int)), this, SLOT(checkIfRescheduleIsNeeded())); - mOrgSetPwdToMwdSetting = gpConfig->getBoolSetting(CFG_SETPWDTOMWD); - mOrgProgressBarSetting = gpConfig->getBoolSetting(CFG_PROGRESSBAR); - mOrgLimitDataGenerationsSetting = gpConfig->getBoolSetting(CFG_AUTOLIMITGENERATIONS); - gpConfig->setBoolSetting(CFG_SETPWDTOMWD, false); - gpConfig->setBoolSetting(CFG_PROGRESSBAR, false); - gpConfig->setBoolSetting(CFG_AUTOLIMITGENERATIONS, true); + mOrgSetPwdToMwdSetting = gpConfig->getBoolSetting(cfg::setpwdtomwd); + mOrgProgressBarSetting = gpConfig->getBoolSetting(cfg::progressbar); + mOrgLimitDataGenerationsSetting = gpConfig->getBoolSetting(cfg::autolimitgenerations); + gpConfig->setBoolSetting(cfg::setpwdtomwd, false); + gpConfig->setBoolSetting(cfg::progressbar, false); + gpConfig->setBoolSetting(cfg::autolimitgenerations, true); int nModels = mpWorker->getNumberOfCandidates(); this->initModels(pModel, nModels, modelPath); @@ -141,7 +141,7 @@ void OptimizationHandler::startOptimization(ModelWidget *pModel, QString &modelP #ifdef USEZMQ // Setup parallel server queues - if (gpConfig->getBoolSetting(CFG_USEREMOTEOPTIMIZATION)) + if (gpConfig->getBoolSetting(cfg::useremoteoptimization)) { int pm, pa; double su; rescheduleForBestSpeedup(pm,pa,su,true); @@ -167,9 +167,9 @@ void OptimizationHandler::startOptimization(ModelWidget *pModel, QString &modelP printLogFile(); printDebugFile(); - gpConfig->setBoolSetting(CFG_SETPWDTOMWD, mOrgSetPwdToMwdSetting); - gpConfig->setBoolSetting(CFG_PROGRESSBAR, mOrgProgressBarSetting); - gpConfig->setBoolSetting(CFG_AUTOLIMITGENERATIONS, mOrgLimitDataGenerationsSetting); + gpConfig->setBoolSetting(cfg::setpwdtomwd, mOrgSetPwdToMwdSetting); + gpConfig->setBoolSetting(cfg::progressbar, mOrgProgressBarSetting); + gpConfig->setBoolSetting(cfg::autolimitgenerations, mOrgLimitDataGenerationsSetting); } else { @@ -179,7 +179,7 @@ void OptimizationHandler::startOptimization(ModelWidget *pModel, QString &modelP #ifdef USEZMQ // Clear and disconnect from parallel server queues - if (gpConfig->getBoolSetting(CFG_USEREMOTEOPTIMIZATION)) + if (gpConfig->getBoolSetting(cfg::useremoteoptimization)) { mpRemoteSimulationQueueHandler->clear(); } @@ -736,7 +736,7 @@ bool OptimizationHandler::evaluateAllCandidates() bool simOK=false; #ifdef USEZMQ - if (gpConfig->getBoolSetting(CFG_USEREMOTEOPTIMIZATION)) + if (gpConfig->getBoolSetting(cfg::useremoteoptimization)) { if (mpRemoteSimulationQueueHandler && mpRemoteSimulationQueueHandler->hasServers()) { @@ -1327,7 +1327,7 @@ void OptimizationHandler::checkIfRescheduleIsNeeded() int pm, pa; double su; rescheduleForBestSpeedup(pm,pa,su); // Setup parallel server queues - if (gpConfig->getBoolSetting(CFG_USEREMOTEOPTIMIZATION)) + if (gpConfig->getBoolSetting(cfg::useremoteoptimization)) { mpRemoteSimulationQueueHandler->setupModelQueues(mModelPtrs.mid(0, mpWorker->getNumberOfCandidates()), pm); } diff --git a/HopsanGUI/PlotHandler.cpp b/HopsanGUI/PlotHandler.cpp index b679d7493e..9d26d914d3 100644 --- a/HopsanGUI/PlotHandler.cpp +++ b/HopsanGUI/PlotHandler.cpp @@ -70,7 +70,7 @@ PlotWindow *PlotHandler::createNewPlotWindowOrGetCurrentOne(QString name) PlotWindow* pPlotWindow = getPlotWindow(name); if (pPlotWindow==0) { - if(gpConfig->getBoolSetting(CFG_PLOTWINDOWSONTOP)) + if(gpConfig->getBoolSetting(cfg::plotwindowsontop)) pPlotWindow = new PlotWindow(name, gpMainWindowWidget); else pPlotWindow = new PlotWindow(name, 0); @@ -98,7 +98,7 @@ PlotWindow *PlotHandler::createNewUniquePlotWindow(const QString &rName) } PlotWindow *pPlotWindow; - if(gpConfig->getBoolSetting(CFG_PLOTWINDOWSONTOP)) + if(gpConfig->getBoolSetting(cfg::plotwindowsontop)) pPlotWindow = new PlotWindow(rName, gpMainWindowWidget); else pPlotWindow = new PlotWindow(rName, 0); diff --git a/HopsanGUI/PlotTab.cpp b/HopsanGUI/PlotTab.cpp index 97a6b8f6a5..d76c946612 100644 --- a/HopsanGUI/PlotTab.cpp +++ b/HopsanGUI/PlotTab.cpp @@ -338,11 +338,11 @@ void PlotTab::exportToCsv() QString filePath; QFileInfo fileInfo; filePath = QFileDialog::getSaveFileName(this, tr("Export Plot Tab To CSV File"), - gpConfig->getStringSetting(CFG_PLOTDATADIR), + gpConfig->getStringSetting(cfg::dir::plotdata), tr("Comma-separated values files (*.csv)")); if(filePath.isEmpty()) return; //Don't save anything if user presses cancel fileInfo.setFile(filePath); - gpConfig->setStringSetting(CFG_PLOTDATADIR, fileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::plotdata, fileInfo.absolutePath()); exportToCsv(filePath); } @@ -453,7 +453,7 @@ void PlotTab::exportToHvc(QString fileName) { // Open file dialog and initialize the file stream QString filePath = QFileDialog::getSaveFileName(this, tr("Export Plot Tab To HVC and HVD"), - gpConfig->getStringSetting(CFG_PLOTDATADIR), + gpConfig->getStringSetting(cfg::dir::plotdata), tr("HopsanValidationCfg (*.hvc)")); if(filePath.isEmpty()) return; //Don't save anything if user presses cancel hvcFileInfo.setFile(filePath); @@ -516,11 +516,11 @@ void PlotTab::exportToMatlab() QFileInfo fileInfo; QFile file; filePath = QFileDialog::getSaveFileName(this, tr("Export Plot Tab To MATLAB File"), - gpConfig->getStringSetting(CFG_PLOTDATADIR), + gpConfig->getStringSetting(cfg::dir::plotdata), tr("MATLAB script file (*.m)")); if(filePath.isEmpty()) return; //Don't save anything if user presses cancel fileInfo.setFile(filePath); - gpConfig->setStringSetting(CFG_PLOTDATADIR, fileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::plotdata, fileInfo.absolutePath()); file.setFileName(fileInfo.filePath()); //Create a QFile object if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { @@ -637,11 +637,11 @@ void PlotTab::exportToGnuplot() QFileInfo fileInfo; QFile file; filePath = QFileDialog::getSaveFileName(this, tr("Export Plot Tab To gnuplot File"), - gpConfig->getStringSetting(CFG_PLOTDATADIR), + gpConfig->getStringSetting(cfg::dir::plotdata), tr("gnuplot file (*.dat)")); if(filePath.isEmpty()) return; //Don't save anything if user presses cancel fileInfo.setFile(filePath); - gpConfig->setStringSetting(CFG_PLOTDATADIR, fileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::plotdata, fileInfo.absolutePath()); file.setFileName(fileInfo.filePath()); //Create a QFile object if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { @@ -711,11 +711,11 @@ void PlotTab::exportToPLO() QString filePath; QFileInfo fileInfo; filePath = QFileDialog::getSaveFileName(this, tr("Export Plot Tab To OldHopsan Format File"), - gpConfig->getStringSetting(CFG_PLOTDATADIR), + gpConfig->getStringSetting(cfg::dir::plotdata), tr("Hopsan Classic file (*.PLO)")); if(filePath.isEmpty()) return; //Don't save anything if user presses cancel fileInfo.setFile(filePath); - gpConfig->setStringSetting(CFG_PLOTDATADIR, fileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::plotdata, fileInfo.absolutePath()); if (getPlotTabType() != XYPlotType) { @@ -739,11 +739,11 @@ void PlotTab::exportToHDF5() QString filePath; QFileInfo fileInfo; filePath = QFileDialog::getSaveFileName(this, tr("Export HDF5 Format File"), - gpConfig->getStringSetting(CFG_PLOTDATADIR), + gpConfig->getStringSetting(cfg::dir::plotdata), tr("Hopsan Classic file (*.h5)")); if(filePath.isEmpty()) return; //Don't save anything if user presses cancel fileInfo.setFile(filePath); - gpConfig->setStringSetting(CFG_PLOTDATADIR, fileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::plotdata, fileInfo.absolutePath()); if (getPlotTabType() != XYPlotType) { @@ -1121,11 +1121,11 @@ void PlotTab::saveToXml() QString filePath; QFileInfo fileInfo; filePath = QFileDialog::getSaveFileName(this, tr("Export Plot Tab To XML File"), - gpConfig->getStringSetting(CFG_PLOTDATADIR), + gpConfig->getStringSetting(cfg::dir::plotdata), tr("Extensible Markup Language (*.xml)")); if(filePath.isEmpty()) return; //Don't save anything if user presses cancel fileInfo.setFile(filePath); - gpConfig->setStringSetting(CFG_PLOTDATADIR, fileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::plotdata, fileInfo.absolutePath()); QDomDocument domDocument; QDomElement element = domDocument.createElement("hopsanplotdata"); @@ -1742,12 +1742,12 @@ PlotGraphicsExporter::PlotGraphicsExporter() { mSupportedFormats << "png" << "pdf" << "svg" << "ps" << "jpeg"; - mImageFormat = gpConfig->getStringSetting(CFG_PLOTGFXIMAGEFORMAT); - mDimensionsUnit = gpConfig->getStringSetting(CFG_PLOTGFXDIMENSIONSUNIT); - mDPI = gpConfig->getDoubleSetting(CFG_PLOTGFXDPI); + mImageFormat = gpConfig->getStringSetting(cfg::plotgfximageformat); + mDimensionsUnit = gpConfig->getStringSetting(cfg::plotgfxdimensionunit); + mDPI = gpConfig->getDoubleSetting(cfg::plotgfxdpi); mSetSize = gpConfig->getPlotGfxSize(); - mKeepAspect = gpConfig->getBoolSetting(CFG_PLOTGFXKEEPASPECT); - mUseScreenSize = gpConfig->getBoolSetting(CFG_PLOTGFXUSESCREENSIZE); + mKeepAspect = gpConfig->getBoolSetting(cfg::plotgfxkeepaspect); + mUseScreenSize = gpConfig->getBoolSetting(cfg::plotgfxusescreensize); } void PlotGraphicsExporter::openExportDialog() @@ -1885,7 +1885,7 @@ QString PlotGraphicsExporter::selectExportFilename() fileFilter.append(";;all (*.*)"); - QString path = gpConfig->getStringSetting(CFG_PLOTGFXDIR); + QString path = gpConfig->getStringSetting(cfg::dir::plotgfx); if (!mImageFilename.isEmpty()) { QFileInfo file(mImageFilename); @@ -1896,7 +1896,7 @@ QString PlotGraphicsExporter::selectExportFilename() if(!mImageFilename.isEmpty()) { QFileInfo file(mImageFilename); - gpConfig->setStringSetting(CFG_PLOTGFXDIR, file.canonicalPath()); + gpConfig->setStringSetting(cfg::dir::plotgfx, file.canonicalPath()); } return mImageFilename; } @@ -2062,10 +2062,10 @@ void PlotGraphicsExporter::rememberDialogValues() mUseScreenSize = mpUseScreenSizeCheckBox->isChecked(); mKeepAspect = mpKeepAspectRatioCheckBox->isChecked(); - gpConfig->setStringSetting(CFG_PLOTGFXIMAGEFORMAT, mImageFormat); - gpConfig->setStringSetting(CFG_PLOTGFXDIMENSIONSUNIT, mDimensionsUnit); + gpConfig->setStringSetting(cfg::plotgfximageformat, mImageFormat); + gpConfig->setStringSetting(cfg::plotgfxdimensionunit, mDimensionsUnit); gpConfig->setPlotGfxSize(mSetSize); - gpConfig->setDoubleSetting(CFG_PLOTGFXDPI, mDPI); - gpConfig->setBoolSetting(CFG_PLOTGFXUSESCREENSIZE, mUseScreenSize); - gpConfig->setBoolSetting(CFG_PLOTGFXKEEPASPECT, mKeepAspect); + gpConfig->setDoubleSetting(cfg::plotgfxdpi, mDPI); + gpConfig->setBoolSetting(cfg::plotgfxusescreensize, mUseScreenSize); + gpConfig->setBoolSetting(cfg::plotgfxkeepaspect, mKeepAspect); } diff --git a/HopsanGUI/RemoteSimulationUtils.cpp b/HopsanGUI/RemoteSimulationUtils.cpp index 0aaf3fdc12..ed39c2f2a3 100644 --- a/HopsanGUI/RemoteSimulationUtils.cpp +++ b/HopsanGUI/RemoteSimulationUtils.cpp @@ -239,7 +239,7 @@ void RemoteSimulationQueueHandler::setupModelQueues(QVector model servers.pop_front(); SharedRemoteCoreSimulationHandlerT pSH(new RemoteCoreSimulationHandler()); - pSH->setUserIdentification(gpConfig->getStringSetting(CFG_REMOTEHOPSANUSERIDENTIFICATION)); + pSH->setUserIdentification(gpConfig->getStringSetting(cfg::remotehopsanuseridentification)); pSH->setAddressServer(mpRemoteCoreAddressHandler->getAddressAndPort()); pSH->setHopsanServer(server_addr); pSH->setNumThreads(mNumThreadsPerModel); @@ -441,7 +441,7 @@ bool RemoteSimulationQueueHandler::connectToAddressServer() } // Disconnect if address has changed - if (mpRemoteCoreAddressHandler->getAddressAndPort() != gpConfig->getStringSetting(CFG_REMOTEHOPSANADDRESSSERVERADDRESS)) + if (mpRemoteCoreAddressHandler->getAddressAndPort() != gpConfig->getStringSetting(cfg::remotehopsanaddresserveraddress)) { mpRemoteCoreAddressHandler->disconnect(); } @@ -450,7 +450,7 @@ bool RemoteSimulationQueueHandler::connectToAddressServer() bool addrserver_connected = mpRemoteCoreAddressHandler->isConnected(); if (!addrserver_connected) { - mpRemoteCoreAddressHandler->setHopsanAddressServer(gpConfig->getStringSetting(CFG_REMOTEHOPSANADDRESSSERVERADDRESS)); + mpRemoteCoreAddressHandler->setHopsanAddressServer(gpConfig->getStringSetting(cfg::remotehopsanaddresserveraddress)); addrserver_connected = mpRemoteCoreAddressHandler->connect(); } @@ -520,7 +520,7 @@ void RemoteSimulationQueueHandler::benchmarkModel(ModelWidget *pModel) // Benchmark evalTime vs numThreads QString server_addr = mpRemoteCoreAddressHandler->getBestAvailableServer(maxNumSlots, mServerBlacklist); SharedRemoteCoreSimulationHandlerT pRCSH(new RemoteCoreSimulationHandler()); - pRCSH->setUserIdentification(gpConfig->getStringSetting(CFG_REMOTEHOPSANUSERIDENTIFICATION)); + pRCSH->setUserIdentification(gpConfig->getStringSetting(cfg::remotehopsanuseridentification)); pRCSH->setAddressServer(mpRemoteCoreAddressHandler->getAddressAndPort()); pRCSH->setHopsanServer(server_addr); bool rc = pRCSH->connectServer(); diff --git a/HopsanGUI/SimulationThreadHandler.cpp b/HopsanGUI/SimulationThreadHandler.cpp index 50cf7ee02b..2092ddc93b 100644 --- a/HopsanGUI/SimulationThreadHandler.cpp +++ b/HopsanGUI/SimulationThreadHandler.cpp @@ -96,18 +96,18 @@ void LocalSimulationWorkerObject::initSimulateFinalize() // Check if we should simulate multiple systems at the same time using multicore if ((coreSystemAccessVector.size() > 1) && (gpConfig->getUseMulticore())) { - simulateSuccess = simuHandler.simulate(mStartTime, mStopTime, gpConfig->getIntegerSetting(CFG_NUMBEROFTHREADS), coreSystemAccessVector, mNoChanges); + simulateSuccess = simuHandler.simulate(mStartTime, mStopTime, gpConfig->getIntegerSetting(cfg::numberofthreads), coreSystemAccessVector, mNoChanges); } - else if (gpConfig->getUseMulticore() && !gpConfig->getBoolSetting(CFG_LOGDURINGSIMULATION)) + else if (gpConfig->getUseMulticore() && !gpConfig->getBoolSetting(cfg::logduringsimulation)) { // Choose if we should simulate each system (or just the one system) using multiple cores (but each system in sequence) timer.start(); - simulateSuccess = simuHandler.simulate(mStartTime, mStopTime, gpConfig->getIntegerSetting(CFG_NUMBEROFTHREADS), coreSystemAccessVector, mNoChanges); + simulateSuccess = simuHandler.simulate(mStartTime, mStopTime, gpConfig->getIntegerSetting(cfg::numberofthreads), coreSystemAccessVector, mNoChanges); } - else if (gpConfig->getUseMulticore() && gpConfig->getBoolSetting(CFG_LOGDURINGSIMULATION)) + else if (gpConfig->getUseMulticore() && gpConfig->getBoolSetting(cfg::logduringsimulation)) { // Choose if we should simulate each system (or just the one system) using multiple cores (but each system in sequence) - int logSteps = gpConfig->getBoolSetting(CFG_LOGSTEPS); + int logSteps = gpConfig->getBoolSetting(cfg::logsteps); timer.start(); double time = mStartTime; simulateSuccess = true; @@ -118,11 +118,11 @@ void LocalSimulationWorkerObject::initSimulateFinalize() time += mStopTime/logSteps; emit stepFinished(); } - simulateSuccess = simuHandler.simulate(mStartTime, mStopTime, gpConfig->getIntegerSetting(CFG_NUMBEROFTHREADS), coreSystemAccessVector, mNoChanges); + simulateSuccess = simuHandler.simulate(mStartTime, mStopTime, gpConfig->getIntegerSetting(cfg::numberofthreads), coreSystemAccessVector, mNoChanges); } - else if(!gpConfig->getUseMulticore() && gpConfig->getBoolSetting(CFG_LOGDURINGSIMULATION)) + else if(!gpConfig->getUseMulticore() && gpConfig->getBoolSetting(cfg::logduringsimulation)) { - int logSteps = gpConfig->getIntegerSetting(CFG_LOGSTEPS); + int logSteps = gpConfig->getIntegerSetting(cfg::logsteps); timer.start(); double time = mStartTime; simulateSuccess = true; @@ -350,7 +350,7 @@ void SimulationThreadHandler::initSimulateFinalizePrivate() mInitSuccess=false; mSimuSucess=false; mFiniSucess=false; mAborted=false; mpSimulationWorkerObject->moveToThread(&mSimulationWorkerThread); - if (gpConfig->getBoolSetting(CFG_PROGRESSBAR) && mProgressBarEnabled) + if (gpConfig->getBoolSetting(cfg::progressbar) && mProgressBarEnabled) { // Create it if it does not exist (first time) if (!mpProgressDialog) { @@ -398,7 +398,7 @@ void SimulationThreadHandler::initSimulateFinalizePrivate() mpCheckMessagesTimer = new QTimer(this); } connect(mpSimulationWorkerObject, &SimulationWorkerObjectBase::simulateDone, mpCheckMessagesTimer, &QTimer::stop, Qt::BlockingQueuedConnection); - if(gpConfig->getBoolSetting(CFG_LOGDURINGSIMULATION)) { + if(gpConfig->getBoolSetting(cfg::logduringsimulation)) { connect(mpSimulationWorkerObject, SIGNAL(stepFinished()), this, SIGNAL(stepFinished())); } connect(mpCheckMessagesTimer, &QTimer::timeout, mpMessageHandler, &GUIMessageHandler::collectHopsanCoreMessages); diff --git a/HopsanGUI/UndoStack.cpp b/HopsanGUI/UndoStack.cpp index 6845638bfe..ac5256fb37 100644 --- a/HopsanGUI/UndoStack.cpp +++ b/HopsanGUI/UndoStack.cpp @@ -85,7 +85,7 @@ void UndoStack::clear(QString errorMsg) { mCurrentStackPosition = -1; mUndoRoot.clear(); - mUndoRoot = mDomDocument.createElement(HMF_UNDO); + mUndoRoot = mDomDocument.createElement(hmf::undo); mDomDocument.appendChild(mUndoRoot); QDomElement firstPost = appendDomElement(mUndoRoot, "post"); firstPost.setAttribute("number", mCurrentStackPosition); @@ -144,51 +144,51 @@ void UndoStack::undoOneStep() didSomething = true; if(stuffElement.attribute("what") == UNDO_DELETEDOBJECT) { - QDomElement componentElement = stuffElement.firstChildElement(HMF_COMPONENT); + QDomElement componentElement = stuffElement.firstChildElement(hmf::component); ModelObject* pObj = loadModelObject(componentElement, mpParentSystemObject, NoUndo); //Load parameter values - QDomElement xmlParameters = componentElement.firstChildElement(HMF_PARAMETERS); - QDomElement xmlParameter = xmlParameters.firstChildElement(HMF_PARAMETERTAG); + QDomElement xmlParameters = componentElement.firstChildElement(hmf::parameters); + QDomElement xmlParameter = xmlParameters.firstChildElement(hmf::parameter::root); while (!xmlParameter.isNull()) { loadParameterValue(xmlParameter, pObj, NoUndo); - xmlParameter = xmlParameter.nextSiblingElement(HMF_PARAMETERTAG); + xmlParameter = xmlParameter.nextSiblingElement(hmf::parameter::root); } } else if(stuffElement.attribute("what") == UNDO_DELETEDSYSTEMPORT) { - QDomElement systemPortElement = stuffElement.firstChildElement(HMF_SYSTEMPORTTAG); + QDomElement systemPortElement = stuffElement.firstChildElement(hmf::systemport); loadSystemPortObject(systemPortElement, mpParentSystemObject, NoUndo); } else if(stuffElement.attribute("what") == UNDO_DELETEDSUBSYSTEM) { - QDomElement systemElement = stuffElement.firstChildElement(HMF_SYSTEMTAG); + QDomElement systemElement = stuffElement.firstChildElement(hmf::system); loadModelObject(systemElement, mpParentSystemObject, NoUndo); } else if(stuffElement.attribute("what") == UNDO_ADDEDOBJECT) { - QDomElement componentElement = stuffElement.firstChildElement(HMF_COMPONENT); + QDomElement componentElement = stuffElement.firstChildElement(hmf::component); addedObjectList.append(componentElement); } else if(stuffElement.attribute("what") == UNDO_ADDEDSYSTEMPORT) { - QDomElement systemPortElement = stuffElement.firstChildElement(HMF_SYSTEMPORTTAG); + QDomElement systemPortElement = stuffElement.firstChildElement(hmf::systemport); addedsystemportsList.append(systemPortElement); } else if(stuffElement.attribute("what") == UNDO_ADDEDSUBSYSTEM) { - QDomElement systemElement = stuffElement.firstChildElement(HMF_SYSTEMTAG); + QDomElement systemElement = stuffElement.firstChildElement(hmf::system); addedsubsystemsList.append(systemElement); } else if(stuffElement.attribute("what") == UNDO_DELETEDCONNECTOR) { - QDomElement connectorElement = stuffElement.firstChildElement(HMF_CONNECTORTAG); + QDomElement connectorElement = stuffElement.firstChildElement(hmf::connector::root); deletedConnectorList.append(connectorElement); } else if(stuffElement.attribute("what") == UNDO_ADDEDCONNECTOR) { - QDomElement connectorElement = stuffElement.firstChildElement(HMF_CONNECTORTAG); + QDomElement connectorElement = stuffElement.firstChildElement(hmf::connector::root); addedConnectorList.append(connectorElement); } else if(stuffElement.attribute("what") == UNDO_RENAME) @@ -212,7 +212,7 @@ void UndoStack::undoOneStep() parseDomValueNode2(newPosElement, tempX, tempY); QPointF newPos = QPointF(tempX, tempY); int lineNumber = stuffElement.attribute("linenumber").toDouble(); - QDomElement connectorElement = stuffElement.firstChildElement(HMF_CONNECTORTAG); + QDomElement connectorElement = stuffElement.firstChildElement(hmf::connector::root); QString startComponent = connectorElement.attribute("startcomponent"); QString startPort = connectorElement.attribute("startport"); QString endComponent = connectorElement.attribute("endcomponent"); @@ -234,7 +234,7 @@ void UndoStack::undoOneStep() QDomElement oldPosElement = stuffElement.firstChildElement("oldpos"); parseDomValueNode2(newPosElement, x_new, y_new); parseDomValueNode2(oldPosElement, x, y); - QString name = stuffElement.attribute(HMF_NAMETAG); + QString name = stuffElement.attribute(hmf::name); if(!mpParentSystemObject->hasModelObject(name)) { this->clear("Undo stack attempted to access non-existing component. Stack was cleared to ensure stability."); @@ -251,7 +251,7 @@ void UndoStack::undoOneStep() double dx = stuffElement.attribute("dx").toDouble(); double dy = stuffElement.attribute("dy").toDouble(); - QDomElement connectorElement = stuffElement.firstChildElement(HMF_CONNECTORTAG); + QDomElement connectorElement = stuffElement.firstChildElement(hmf::connector::root); QString startComponent = connectorElement.attribute("startcomponent"); QString startPort = connectorElement.attribute("startport"); QString endComponent = connectorElement.attribute("endcomponent"); @@ -389,11 +389,11 @@ void UndoStack::undoOneStep() } else if(stuffElement.attribute("what") == UNDO_REMOVEDALIASES) { - QDomElement xmlAlias = stuffElement.firstChildElement(HMF_ALIAS); + QDomElement xmlAlias = stuffElement.firstChildElement(hmf::alias); while (!xmlAlias.isNull()) { loadPlotAlias(xmlAlias, mpParentSystemObject); - xmlAlias = xmlAlias.nextSiblingElement(HMF_ALIAS); + xmlAlias = xmlAlias.nextSiblingElement(hmf::alias); } } stuffElement = stuffElement.previousSiblingElement("stuff"); @@ -432,7 +432,7 @@ void UndoStack::undoOneStep() // Remove objects after removing connectors, to make sure connectors don't lose their start and end components for(it = addedObjectList.begin(); it!=addedObjectList.end(); ++it) { - QString name = (*it).attribute(HMF_NAMETAG); + QString name = (*it).attribute(hmf::name); if(!mpParentSystemObject->hasModelObject(name)) { this->clear("Undo stack attempted to access non-existing component. Stack was cleared to ensure stability."); @@ -444,7 +444,7 @@ void UndoStack::undoOneStep() // Remove system ports for(it = addedsystemportsList.begin(); it!=addedsystemportsList.end(); ++it) { - QString name = (*it).attribute(HMF_NAMETAG); + QString name = (*it).attribute(hmf::name); if(!mpParentSystemObject->hasModelObject(name)) { this->clear("Undo stack attempted to access non-existing component. Stack was cleared to ensure stability."); @@ -456,7 +456,7 @@ void UndoStack::undoOneStep() // Remove subsystems for(it = addedsubsystemsList.begin(); it!=addedsubsystemsList.end(); ++it) { - QString name = (*it).attribute(HMF_NAMETAG); + QString name = (*it).attribute(hmf::name); SystemObject *pSystemToRemove = qobject_cast(mpParentSystemObject->getModelObject(name)); // Update information about Subsystem in DOM tree, in case it has changed inside since registered in the undo stack @@ -514,8 +514,8 @@ void UndoStack::redoOneStep() didSomething = true; if(stuffElement.attribute("what") == UNDO_DELETEDOBJECT) { - QDomElement componentElement = stuffElement.firstChildElement(HMF_COMPONENT); - QString name = componentElement.attribute(HMF_NAMETAG); + QDomElement componentElement = stuffElement.firstChildElement(hmf::component); + QString name = componentElement.attribute(hmf::name); if(mpParentSystemObject->hasModelObject(name)) { mpParentSystemObject->deleteModelObject(name, NoUndo); } @@ -525,8 +525,8 @@ void UndoStack::redoOneStep() } else if(stuffElement.attribute("what") == UNDO_DELETEDSYSTEMPORT) { - QDomElement systemPortElement = stuffElement.firstChildElement(HMF_SYSTEMPORTTAG); - QString name = systemPortElement.attribute(HMF_NAMETAG); + QDomElement systemPortElement = stuffElement.firstChildElement(hmf::systemport); + QString name = systemPortElement.attribute(hmf::name); if(mpParentSystemObject->hasModelObject(name)) { mpParentSystemObject->deleteModelObject(name, NoUndo); } @@ -537,8 +537,8 @@ void UndoStack::redoOneStep() } else if(stuffElement.attribute("what") == UNDO_DELETEDSUBSYSTEM) { - QDomElement systemElement = stuffElement.firstChildElement(HMF_SYSTEMTAG); - QString name = systemElement.attribute(HMF_NAMETAG); + QDomElement systemElement = stuffElement.firstChildElement(hmf::system); + QString name = systemElement.attribute(hmf::name); if(mpParentSystemObject->hasModelObject(name)) { mpParentSystemObject->deleteModelObject(name, NoUndo); } @@ -548,22 +548,22 @@ void UndoStack::redoOneStep() } else if(stuffElement.attribute("what") == UNDO_ADDEDOBJECT) { - QDomElement componentElement = stuffElement.firstChildElement(HMF_COMPONENT); + QDomElement componentElement = stuffElement.firstChildElement(hmf::component); loadModelObject(componentElement, mpParentSystemObject, NoUndo); } else if(stuffElement.attribute("what") == UNDO_ADDEDSYSTEMPORT) { - QDomElement systemPortElement = stuffElement.firstChildElement(HMF_SYSTEMPORTTAG); + QDomElement systemPortElement = stuffElement.firstChildElement(hmf::systemport); loadSystemPortObject(systemPortElement, mpParentSystemObject, NoUndo); } else if(stuffElement.attribute("what") == UNDO_ADDEDSUBSYSTEM) { - QDomElement systemElement = stuffElement.firstChildElement(HMF_SYSTEMTAG); + QDomElement systemElement = stuffElement.firstChildElement(hmf::system); loadModelObject(systemElement, mpParentSystemObject, NoUndo); } else if(stuffElement.attribute("what") == UNDO_DELETEDCONNECTOR) { - QDomElement connectorElement = stuffElement.firstChildElement(HMF_CONNECTORTAG); + QDomElement connectorElement = stuffElement.firstChildElement(hmf::connector::root); QString startComponent = connectorElement.attribute("startcomponent"); QString startPort = connectorElement.attribute("startport"); QString endComponent = connectorElement.attribute("endcomponent"); @@ -577,7 +577,7 @@ void UndoStack::redoOneStep() } else if(stuffElement.attribute("what") == UNDO_ADDEDCONNECTOR) { - QDomElement connectorElement = stuffElement.firstChildElement(HMF_CONNECTORTAG); + QDomElement connectorElement = stuffElement.firstChildElement(hmf::connector::root); addedConnectorList.append(connectorElement); } else if(stuffElement.attribute("what") == UNDO_RENAME) @@ -604,7 +604,7 @@ void UndoStack::redoOneStep() QDomElement oldPosElement = stuffElement.firstChildElement("oldpos"); parseDomValueNode2(newPosElement, x, y); parseDomValueNode2(oldPosElement, x_old, y_old); - QString name = stuffElement.attribute(HMF_NAMETAG); + QString name = stuffElement.attribute(hmf::name); if(mpParentSystemObject->hasModelObject(name)) { mpParentSystemObject->getModelObject(name)->setPos(x, y); mpParentSystemObject->getModelObject(name)->rememberPos(); @@ -753,7 +753,7 @@ void UndoStack::redoOneStep() int lineNumber = (*it).attribute("linenumber").toDouble(); - QDomElement connectorElement = (*it).firstChildElement(HMF_CONNECTORTAG); + QDomElement connectorElement = (*it).firstChildElement(hmf::connector::root); QString startComponent = connectorElement.attribute("startcomponent"); QString startPort = connectorElement.attribute("startport"); QString endComponent = connectorElement.attribute("endcomponent"); @@ -925,7 +925,7 @@ void UndoStack::registerMovedObject(QPointF oldPos, QPointF newPos, QString obje QDomElement currentPostElement = getCurrentPost(); QDomElement stuffElement = appendDomElement(currentPostElement, "stuff"); stuffElement.setAttribute("what", UNDO_MOVEDOBJECT); - stuffElement.setAttribute(HMF_NAMETAG, objectName); + stuffElement.setAttribute(hmf::name, objectName); appendDomValueNode2(stuffElement, "oldpos", oldPos.x(), oldPos.y()); appendDomValueNode2(stuffElement, "newpos", newPos.x(), newPos.y()); gpUndoWidget->refreshList(); @@ -1021,9 +1021,9 @@ void UndoStack::registerRemovedAliases(QStringList &aliases) //! @todo need one function that gets both alias and full maybe for (int i=0; igetFullNameFromAlias(aliases[i]); appendDomTextNode(alias, "fullname",fullName ); } @@ -1149,7 +1149,7 @@ void UndoStack::setEnabled(bool enabled) void UndoStack::addTextboxwidget(const QDomElement &rStuffElement) { - QDomElement textBoxElement = rStuffElement.firstChildElement(HMF_TEXTBOXWIDGETTAG); + QDomElement textBoxElement = rStuffElement.firstChildElement(hmf::widget::textboxwidget); int id = parseAttributeInt(textBoxElement, "index", 0); TextBoxWidget *pWidget = mpParentSystemObject->addTextBoxWidget(QPointF(1,1), id, NoUndo); pWidget->loadFromDomElement(textBoxElement); @@ -1169,7 +1169,7 @@ void UndoStack::modifyTextboxWidget(QDomElement &rStuffElement) { pWidget->saveToDomElement(rStuffElement); - QString tagname(HMF_TEXTBOXWIDGETTAG); + QString tagname(hmf::widget::textboxwidget); pWidget->loadFromDomElement(rStuffElement.firstChildElement(tagname)); // Now remember the prevData in case we want to redo/undo again @@ -1180,8 +1180,8 @@ void UndoStack::modifyTextboxWidget(QDomElement &rStuffElement) void UndoStack::addImageWidget(const QDomElement &rStuffElement) { - QDomElement imageElement = rStuffElement.firstChildElement(hmf::imagewidget); - int id = parseAttributeInt(imageElement, hmf::index, 0); + QDomElement imageElement = rStuffElement.firstChildElement(hmf::widget::imagewidget); + int id = parseAttributeInt(imageElement, hmf::widget::index, 0); ImageWidget *pWidget = mpParentSystemObject->addImageWidget(QPointF(1,1), id, NoUndo); pWidget->loadFromDomElement(imageElement); } @@ -1201,7 +1201,7 @@ void UndoStack::modifyImageWidget(QDomElement &rStuffElement) if (pWidget) { pWidget->saveToDomElement(rStuffElement); - QString tagname(hmf::imagewidget); + QString tagname(hmf::widget::imagewidget); pWidget->loadFromDomElement(rStuffElement.firstChildElement(tagname)); // Now remember the prevData in case we want to redo/undo again diff --git a/HopsanGUI/Utilities/XMLUtilities.cpp b/HopsanGUI/Utilities/XMLUtilities.cpp index d5ca72b1cb..6386da5bad 100644 --- a/HopsanGUI/Utilities/XMLUtilities.cpp +++ b/HopsanGUI/Utilities/XMLUtilities.cpp @@ -46,11 +46,11 @@ QString bool2str(const bool in) { if (in) { - return HMF_TRUETAG; + return hmf::truetag; } else { - return HMF_FALSETAG; + return hmf::falsetag; } } @@ -104,11 +104,11 @@ void appendRootXMLProcessingInstruction(QDomDocument &rDomDocument) //! @returns The created root DOM element QDomElement appendHMFRootElement(QDomDocument &rDomDocument, QString hmfVersion, QString hopsanGuiVersion, QString hopsanCoreVersion) { - QDomElement hmfRoot = rDomDocument.createElement(HMF_ROOTTAG); + QDomElement hmfRoot = rDomDocument.createElement(hmf::root); rDomDocument.appendChild(hmfRoot); - hmfRoot.setAttribute(HMF_VERSIONTAG, hmfVersion); - hmfRoot.setAttribute(HMF_HOPSANGUIVERSIONTAG, hopsanGuiVersion); - hmfRoot.setAttribute(HMF_HOPSANCOREVERSIONTAG, hopsanCoreVersion); + hmfRoot.setAttribute(hmf::version::hmf, hmfVersion); + hmfRoot.setAttribute(hmf::version::hopsangui, hopsanGuiVersion); + hmfRoot.setAttribute(hmf::version::hopsancore, hopsanCoreVersion); return hmfRoot; } @@ -163,11 +163,11 @@ QDomElement appendDomBooleanNode(QDomElement &rDomElement, const QString element { if(value) { - return appendDomTextNode(rDomElement, element_name, HMF_TRUETAG); + return appendDomTextNode(rDomElement, element_name, hmf::truetag); } else { - return appendDomTextNode(rDomElement, element_name, HMF_FALSETAG); + return appendDomTextNode(rDomElement, element_name, hmf::falsetag); } } @@ -323,7 +323,7 @@ bool parseDomBooleanNode(QDomElement domElement, const bool defaultValue) return defaultValue; } // else check if it is true or not (something else = false) - return (domElement.text() == HMF_TRUETAG); + return (domElement.text() == hmf::truetag); } //! @brief Special purpose function for adding a Hopsan specific XML tag containing Object Pose information @@ -334,7 +334,7 @@ bool parseDomBooleanNode(QDomElement domElement, const bool defaultValue) //! @param[in] flipped isFlipped status of the object void appendPoseTag(QDomElement &rDomElement, const double x, const double y, const double th, const bool flipped, const int precision) { - QDomElement pose = appendDomElement(rDomElement, HMF_POSETAG); + QDomElement pose = appendDomElement(rDomElement, hmf::appearance::pose); setQrealAttribute(pose, "x", x, precision, 'g'); setQrealAttribute(pose, "y", y, precision, 'g'); @@ -348,7 +348,7 @@ void appendPoseTag(QDomElement &rDomElement, const double x, const double y, con //! @param[in] y The y coordinate void appendCoordinateTag(QDomElement &rDomElement, const double x, const double y, const int precision) { - QDomElement pose = appendDomElement(rDomElement, HMF_COORDINATETAG); + QDomElement pose = appendDomElement(rDomElement, hmf::connector::coordinate); setQrealAttribute(pose, "x", x, precision); setQrealAttribute(pose, "y", y, precision); } @@ -361,7 +361,7 @@ void appendCoordinateTag(QDomElement &rDomElement, const double x, const double void appendViewPortTag(QDomElement &rDomElement, const double x, const double y, const double zoom) { //qDebug() << QLocale().languageToString(QLocale().language()) << " " << QLocale().countryToString(QLocale().country()) << "DecimalPoint: " << QLocale().decimalPoint(); - QDomElement pose = appendDomElement(rDomElement, HMF_VIEWPORTTAG); + QDomElement pose = appendDomElement(rDomElement, hmf::appearance::viewport); setQrealAttribute(pose, "x", x, 6, 'g'); setQrealAttribute(pose, "y", y, 6, 'g'); @@ -377,7 +377,7 @@ void appendViewPortTag(QDomElement &rDomElement, const double x, const double y, //! @param[in] stop The stoptime void appendSimulationTimeTag(QDomElement &rDomElement, const double start, const double step, const double stop, const bool inheritTs) { - QDomElement simu = appendDomElement(rDomElement, HMF_SIMULATIONTIMETAG); + QDomElement simu = appendDomElement(rDomElement, hmf::simulationtime); setQrealAttribute(simu, "start", start, 10, 'g'); setQrealAttribute(simu, "timestep", step, 10, 'g'); setQrealAttribute(simu, "stop", stop, 10, 'g'); @@ -392,7 +392,7 @@ void appendSimulationTimeTag(QDomElement &rDomElement, const double start, const //! @param[in] stop The stoptime void appendLogSettingsTag(QDomElement &rDomElement, const double logStartTime, const unsigned int numLogSamples) { - QDomElement log = appendDomElement(rDomElement, HMF_SIMULATIONLOGSETTINGS); + QDomElement log = appendDomElement(rDomElement, hmf::simulationlogsettings); setQrealAttribute(log, "starttime", logStartTime, 10, 'g'); log.setAttribute("numsamples", numLogSamples); } @@ -463,7 +463,7 @@ double parseAttributeQreal(const QDomElement domElement, const QString attribute bool parseAttributeBool(const QDomElement domElement, const QString attributeName, const bool defaultValue) { QString attr = domElement.attribute(attributeName, bool2str(defaultValue)); - if ( (attr==HMF_TRUETAG) || (attr=="True") || (attr=="1")) + if ( (attr==hmf::truetag) || (attr=="True") || (attr=="1")) { return true; } @@ -539,7 +539,7 @@ void updateHmfComponentProperties(QDomElement &element, const QString /*hmfVersi updateRenamedPort(element, "HydraulicFlowSourceQ", "in", "q"); // Fix incorrect parameter names - QDomElement xmlParameter = element.firstChildElement(HMF_PARAMETERS).firstChildElement(HMF_PARAMETERTAG); + QDomElement xmlParameter = element.firstChildElement(hmf::parameters).firstChildElement(hmf::parameter::root); while (!xmlParameter.isNull()) { // Fix renamed node data variables @@ -585,7 +585,7 @@ void updateHmfComponentProperties(QDomElement &element, const QString /*hmfVersi xmlParameter.setAttribute("name", name); } - xmlParameter = xmlParameter.nextSiblingElement(HMF_PARAMETERTAG); + xmlParameter = xmlParameter.nextSiblingElement(hmf::parameter::root); } } } @@ -594,7 +594,7 @@ void updateHmfComponentProperties(QDomElement &element, const QString /*hmfVersi //! @brief Handles compatibility issues for xml data loaded from configuration file void verifyConfigurationCompatibility(QDomElement &rConfigElement) { - qDebug() << "Current version = " << HOPSANGUIVERSION << ", config version = " << rConfigElement.attribute(HMF_HOPSANGUIVERSIONTAG); + qDebug() << "Current version = " << HOPSANGUIVERSION << ", config version = " << rConfigElement.attribute(hmf::version::hopsangui); QDomElement unitsElement = rConfigElement.firstChildElement("units"); if(!unitsElement.isNull()) @@ -613,17 +613,17 @@ void verifyConfigurationCompatibility(QDomElement &rConfigElement) void updateRenamedComponentType(QDomElement &rDomElement, const QString oldType, const QString newType) { - if(rDomElement.attribute(HMF_TYPENAME) == oldType) + if(rDomElement.attribute(hmf::typenametag) == oldType) { - rDomElement.setAttribute(HMF_TYPENAME, newType); - QDomElement guiElement = rDomElement.firstChildElement(HMF_HOPSANGUITAG); + rDomElement.setAttribute(hmf::typenametag, newType); + QDomElement guiElement = rDomElement.firstChildElement(hmf::hopsangui); if(!guiElement.isNull()) { - QDomElement cafElement = guiElement.firstChildElement(CAF_ROOT); + QDomElement cafElement = guiElement.firstChildElement(caf::root); if(!cafElement.isNull()) { - QDomElement objectElement = cafElement.firstChildElement(CAF_MODELOBJECT); - objectElement.setAttribute(HMF_TYPENAME, newType); + QDomElement objectElement = cafElement.firstChildElement(caf::modelobject); + objectElement.setAttribute(hmf::typenametag, newType); } } } @@ -631,26 +631,26 @@ void updateRenamedComponentType(QDomElement &rDomElement, const QString oldType, void updateRenamedComponentName(QDomElement &rDomElement, const QString oldName, const QString newName) { - if((rDomElement.tagName() == HMF_COMPONENT) && rDomElement.attribute(HMF_NAMETAG) == oldName) + if((rDomElement.tagName() == hmf::component) && rDomElement.attribute(hmf::name) == oldName) { - rDomElement.setAttribute(HMF_NAMETAG, newName); + rDomElement.setAttribute(hmf::name, newName); gpMessageHandler->addWarningMessage("Renamed component: "+oldName+" to "+newName); - QDomElement guiElement = rDomElement.firstChildElement(HMF_HOPSANGUITAG); + QDomElement guiElement = rDomElement.firstChildElement(hmf::hopsangui); if(!guiElement.isNull()) { - QDomElement cafElement = guiElement.firstChildElement(CAF_ROOT); + QDomElement cafElement = guiElement.firstChildElement(caf::root); if(!cafElement.isNull()) { - QDomElement objectElement = cafElement.firstChildElement(CAF_MODELOBJECT); + QDomElement objectElement = cafElement.firstChildElement(caf::modelobject); objectElement.setAttribute("displayname", newName); } } } - else if ((rDomElement.tagName() == HMF_CONNECTORTAG) && (rDomElement.attribute(HMF_CONNECTORSTARTCOMPONENTTAG) == oldName)) { - rDomElement.setAttribute(HMF_CONNECTORSTARTCOMPONENTTAG, newName); + else if ((rDomElement.tagName() == hmf::connector::root) && (rDomElement.attribute(hmf::connector::startcomponent) == oldName)) { + rDomElement.setAttribute(hmf::connector::startcomponent, newName); } - else if ((rDomElement.tagName() == HMF_CONNECTORTAG) && (rDomElement.attribute(HMF_CONNECTORENDCOMPONENTTAG) == oldName)) { - rDomElement.setAttribute(HMF_CONNECTORENDCOMPONENTTAG, newName); + else if ((rDomElement.tagName() == hmf::connector::root) && (rDomElement.attribute(hmf::connector::endcomponent) == oldName)) { + rDomElement.setAttribute(hmf::connector::endcomponent, newName); } } @@ -660,42 +660,42 @@ void updateRenamedPort(QDomElement &rDomElement, const QString componentType, co if(rDomElement.attribute("typename") == componentType) { // Rename startvalue parameters - QDomElement parameter = rDomElement.firstChildElement(HMF_PARAMETERS).firstChildElement(HMF_PARAMETERTAG); + QDomElement parameter = rDomElement.firstChildElement(hmf::parameters).firstChildElement(hmf::parameter::root); while (!parameter.isNull()) { - QString paramName = parameter.attribute(HMF_NAMETAG); + QString paramName = parameter.attribute(hmf::name); if (paramName.contains(oldName+"#")) { paramName.replace(oldName+"#",newName+"#"); - parameter.setAttribute(HMF_NAMETAG, paramName); + parameter.setAttribute(hmf::name, paramName); } - parameter = parameter.nextSiblingElement(HMF_PARAMETERTAG); + parameter = parameter.nextSiblingElement(hmf::parameter::root); } // Now try to find all connections, and replace portname - QString compName = rDomElement.attribute(HMF_NAMETAG); - QDomElement connection = rDomElement.parentNode().parentNode().firstChildElement(HMF_CONNECTIONS).firstChildElement(HMF_CONNECTORTAG); + QString compName = rDomElement.attribute(hmf::name); + QDomElement connection = rDomElement.parentNode().parentNode().firstChildElement(hmf::connections).firstChildElement(hmf::connector::root); while (!connection.isNull()) { - QString startComp = connection.attribute(HMF_CONNECTORSTARTCOMPONENTTAG); - QString endComp = connection.attribute(HMF_CONNECTORENDCOMPONENTTAG); + QString startComp = connection.attribute(hmf::connector::startcomponent); + QString endComp = connection.attribute(hmf::connector::endcomponent); if (startComp == compName) { - if (connection.attribute(HMF_CONNECTORSTARTPORTTAG) == oldName) + if (connection.attribute(hmf::connector::startport) == oldName) { - connection.setAttribute(HMF_CONNECTORSTARTPORTTAG, newName); + connection.setAttribute(hmf::connector::startport, newName); } } if (endComp == compName) { - if (connection.attribute(HMF_CONNECTORENDPORTTAG) == oldName) + if (connection.attribute(hmf::connector::endport) == oldName) { - connection.setAttribute(HMF_CONNECTORENDPORTTAG, newName); + connection.setAttribute(hmf::connector::endport, newName); } } - connection = connection.nextSiblingElement(HMF_CONNECTORTAG); + connection = connection.nextSiblingElement(hmf::connector::root); } } } @@ -704,15 +704,15 @@ void updateRenamedParameter(QDomElement &rDomElement, const QString componentTyp { if(rDomElement.attribute("typename") == componentType) { - QDomElement parameter = rDomElement.firstChildElement(HMF_PARAMETERS).firstChildElement(HMF_PARAMETERTAG); + QDomElement parameter = rDomElement.firstChildElement(hmf::parameters).firstChildElement(hmf::parameter::root); while (!parameter.isNull()) { - if (parameter.attribute(HMF_NAMETAG) == oldName) + if (parameter.attribute(hmf::name) == oldName) { - parameter.setAttribute(HMF_NAMETAG, newName); - gpMessageHandler->addWarningMessage("Renamed parameter: "+oldName+" to "+newName+" in: "+rDomElement.attribute(HMF_NAMETAG)); + parameter.setAttribute(hmf::name, newName); + gpMessageHandler->addWarningMessage("Renamed parameter: "+oldName+" to "+newName+" in: "+rDomElement.attribute(hmf::name)); } - parameter = parameter.nextSiblingElement(HMF_PARAMETERTAG); + parameter = parameter.nextSiblingElement(hmf::parameter::root); } } } @@ -775,16 +775,16 @@ void updateHmfSystemProperties(QDomElement &systemElement, const QString hmfVers for (const auto& oldName : invalidNames) { QString newName = oldName+"_INVALID_NAME"; - QDomElement xmlComponent = systemElement.firstChildElement(HMF_OBJECTS).firstChildElement(HMF_COMPONENT); + QDomElement xmlComponent = systemElement.firstChildElement(hmf::objects).firstChildElement(hmf::component); while (!xmlComponent.isNull()) { updateRenamedComponentName(xmlComponent, oldName, newName); - xmlComponent = xmlComponent.nextSiblingElement(HMF_COMPONENT); + xmlComponent = xmlComponent.nextSiblingElement(hmf::component); } - QDomElement xmlConnection = systemElement.firstChildElement(HMF_CONNECTIONS).firstChildElement(HMF_CONNECTORTAG); + QDomElement xmlConnection = systemElement.firstChildElement(hmf::connections).firstChildElement(hmf::connector::root); while(!xmlConnection.isNull()) { updateRenamedComponentName(xmlConnection, oldName, newName); - xmlConnection = xmlConnection.nextSiblingElement(HMF_CONNECTORTAG); + xmlConnection = xmlConnection.nextSiblingElement(hmf::connector::root); } // This will rename the system parameter and preserve the value, but any user of the parameter must be updated manually diff --git a/HopsanGUI/Utilities/XMLUtilities.h b/HopsanGUI/Utilities/XMLUtilities.h index 7cd448732c..ddb1211f01 100644 --- a/HopsanGUI/Utilities/XMLUtilities.h +++ b/HopsanGUI/Utilities/XMLUtilities.h @@ -107,164 +107,196 @@ class SsvParameter { void readFromSsv(const QString filePath, QList &rParameters); //Save Load Definitions -//! @todo clean up this list and give some smarter names, remove TAG from end, also make sure we use theses defines where appropriate instead of hardcoded strings -#define HPF_ROOTTAG "hopsanparameterfile" - -#define HMF_ROOTTAG "hopsanmodelfile" -#define HMF_OBJECTS "objects" -#define HMF_OBJECTTAG "object" //Non core Gui Object -#define HMF_MODELOBJECT "modelobject" -#define HMF_COMPONENT "component" -#define HMF_SYSTEMTAG "system" -#define HMF_SYSTEMPORTTAGTAG "systemport" -#define HMF_CONNECTIONS "connections" -#define HMF_CONNECTORTAG "connect" -#define HMF_PARAMETERTAG "parameter" -#define HMF_PARAMETERS "parameters" -#define HMF_NUMHOPSCRIPT "numhopscript" -#define HMF_ALIASES "aliases" -#define HMF_ALIAS "alias" -#define HMF_STARTVALUES "startvalues" -#define HMF_STARTVALUE "startvalue" -#define HMF_GROUPTAG "group" -#define HMF_TEXTBOXWIDGETTAG "textboxwidget" -#define HMF_TEXTWIDGETTAG "textwidget" -#define HMF_BOXWIDGETTAG "boxwidget" -#define HMF_PORTSTAG "ports" -#define HMF_PORTTAG "port" -#define HMF_NAMESTAG "names" -#define HMF_GFXTAG "graphics" -#define HMF_LOGSAMPLES "logsamples" -#define HMF_ANIMATION "animation" - -#define HMF_NAMETAG "name" -#define HMF_TYPENAME "typename" -#define HMF_SUBTYPENAME "subtypename" -#define HMF_CQSTYPE "cqstype" -#define HMF_TYPE "type" -#define HMF_INTERNAL "internal" -#define HMF_UNIT "unit" -#define HMF_QUANTITY "quantity" -#define HMF_CPPCODETAG "cppcode" -#define HMF_CPPINPUTS "inputs" -#define HMF_CPPOUTPUTS "outputs" - -#define HMF_HOPSANGUITAG "hopsangui" -#define HMF_COORDINATES "coordinates" -#define HMF_COORDINATETAG "coordinate" -#define HMF_GEOMETRIES "geometries" -#define HMF_GEOMETRYTAG "geometry" -#define HMF_STYLETAG "style" -#define HMF_COLORTAG "color" -#define HMF_XYTAG "xy" //Contains an xy coordinate pair -#define HMF_EXTERNALPATHTAG "external_path" //Contains the path to an external subsystem -#define HMF_VALUETAG "value" -#define HMF_SYSTEMPARAMETERTAG "globalkey" -#define HMF_TRUETAG "true" -#define HMF_FALSETAG "false" - -#define HMF_PARAMETERSCALES "customparamscales" -#define HMF_PARAMETERSCALE "customparamscale" -#define HMF_PARAMETERSCALEPARAMNAME "parameter" -#define HMF_PARAMETERSCALEUNIT "unit" -#define HMF_PARAMETERSCALESCALE "scale" -#define HMF_PARAMETERSCALEOFFSET "offset" -#define HMF_PARAMETERSCALEVALUE "value" -#define HMF_PARAMETERSCALEQUANTITY "quantity" - -#define HMF_PLOTSCALES "plotscales" -#define HMF_PLOTSCALE "plotscale" -#define HMF_PLOTSCALEPORTDATANAME "portdataname" -#define HMF_PLOTSCALEDESCRIPTION "description" -#define HMF_PLOTSCALEVALUE "scale" - -#define HMF_VARIABLEPLOTSETTINGS "variableplotsettings" -#define HMF_VARIABLEPLOTSETTING "variableplotsetting" -#define HMF_VARIABLEINVERTPLOT "variableinvertplot" -#define HMF_VARIABLEPLOTLABEL "variableplotlabel" - -#define HMF_POSETAG "pose" -#define HMF_VIEWPORTTAG "viewport" -#define HMF_NAMETEXTTAG "nametext" -#define HMF_NAMETEXTPOSTAG "nametextpos" -#define HMF_VISIBLETAG "nametextvisible" -#define HMF_LOCKEDTAG "locked" -#define HMF_DISABLEDTAG "disabled" - -#define HMF_CONNECTORSTARTCOMPONENTTAG "startcomponent" -#define HMF_CONNECTORSTARTPORTTAG "startport" -#define HMF_CONNECTORENDCOMPONENTTAG "endcomponent" -#define HMF_CONNECTORENDPORTTAG "endport" -#define HMF_CONNECTORDASHEDTAG "dashed" - -#define HMF_SYSTEMAPPEARANCETAG "systemappearance" - -#define HMF_VERSIONTAG "hmfversion" -#define HMF_HOPSANGUIVERSIONTAG "hopsanguiversion" -#define HMF_HOPSANCOREVERSIONTAG "hopsancoreversion" -#define HMF_SIMULATIONTIMETAG "simulationtime" -#define HMF_SIMULATIONLOGSETTINGS "simulationlogsettings" -#define HMF_SCRIPTFILETAG "scriptfile" - -#define HMF_UNDO "hopsanundo" - -#define HMF_INFOTAG "info" -#define HMF_AUTHORTAG "author" -#define HMF_EMAILTAG "email" -#define HMF_AFFILIATIONTAG "affiliation" -#define HMF_DESCRIPTIONTAG "description" - -#define HMF_OPTIMIZATION "optimization" -#define HMF_SEARCHPOINTS "nsearchp" -#define HMF_REFLCOEFF "refcoeff" -#define HMF_RANDOMFACTOR "randfac" -#define HMF_FORGETTINGFACTOR "forgfac" -#define HMF_PARTOL "partol" -#define HMF_PLOT "plot" -#define HMF_SAVECSV "savecsv" -#define HMF_FINALEVAL "finaleval" -#define HMF_LOGPAR "logpar" -#define HMF_OBJECTIVES "objectives" -#define HMF_OBJECTIVE "objective" -#define HMF_FUNCNAME "functionname" -#define HMF_WEIGHT "weight" -#define HMF_NORM "norm" -#define HMF_EXP "exp" -#define HMF_DATA "data" - -#define HMF_SENSITIVITYANALYSIS "senstivitityanalysis" -#define HMF_SETTINGS "settings" -#define HMF_ITERATIONS "iterations" -#define HMF_DISTRIBUTIONTYPE "distribution" -#define HMF_PLOTVARIABLES "plotvariables" -#define HMF_PLOTVARIABLE "variable" -#define HMF_UNIFORMDIST "uniform" -#define HMF_NORMALDIST "normal" -#define HMF_MINMAX "minmax" -#define HMF_AVERAGE "average" -#define HMF_SIGMA "sigma" +namespace hpf { + constexpr auto root = "hopsanparameterfile"; +} namespace hmf { - constexpr auto imagewidget="imagewidget"; - constexpr auto x="x"; - constexpr auto y="y"; - constexpr auto image="image"; - constexpr auto path="path"; - constexpr auto scale="scale"; - constexpr auto index="index"; -} + constexpr auto root = "hopsanmodelfile"; + constexpr auto truetag = "true"; + constexpr auto falsetag = "false"; + constexpr auto name = "name"; + constexpr auto signalquantity = "signalquantity"; + constexpr auto fullname = "fullname"; + constexpr auto objects = "objects"; + constexpr auto object = "object"; //non core gui object + constexpr auto modelobject = "modelobject"; + constexpr auto component = "component"; + constexpr auto system = "system"; + constexpr auto systemport = "systemport"; + constexpr auto parameters = "parameters"; + constexpr auto numhopscript = "numhopscript"; + constexpr auto aliases = "aliases"; + constexpr auto alias = "alias"; + constexpr auto startvalues = "startvalues"; + constexpr auto startvalue = "startvalue"; + constexpr auto group = "group"; + constexpr auto ports = "ports"; + constexpr auto port = "port"; + constexpr auto names = "names"; + constexpr auto data = "data"; + + constexpr auto logsamples = "logsamples"; + constexpr auto animation = "animation"; + + constexpr auto typenametag = "typename"; + constexpr auto subtypename = "subtypename"; + constexpr auto cqstype = "cqstype"; + constexpr auto type = "type"; + constexpr auto internal = "internal"; + constexpr auto unit = "unit"; + constexpr auto quantity = "quantity"; + constexpr auto cppcode = "cppcode"; + constexpr auto cppinputs = "inputs"; + constexpr auto cppoutputs = "outputs"; + constexpr auto hopsangui = "hopsangui"; + constexpr auto externalpath = "external_path"; //contains the path to an external subsystem + constexpr auto value = "value"; + constexpr auto systemparameter = "globalkey"; + constexpr auto connections = "connections"; + constexpr auto simulationtime = "simulationtime"; + constexpr auto simulationlogsettings = "simulationlogsettings"; + constexpr auto scriptfile = "scriptfile"; + constexpr auto undo = "hopsanundo"; + + namespace widget { + constexpr auto textboxwidget = "textboxwidget"; + constexpr auto imagewidget = "imagewidget"; + constexpr auto x = "x"; + constexpr auto y = "y"; + constexpr auto image = "image"; + constexpr auto path = "path"; + constexpr auto scale = "scale"; + constexpr auto index = "index"; + constexpr auto color = "color"; + constexpr auto style = "style"; + constexpr auto line = "line"; + constexpr auto solidline = "solidline"; + constexpr auto dashline = "dashline"; + constexpr auto dotline = "dotline"; + constexpr auto dashdotline = "dashdotline"; + constexpr auto width = "width"; + constexpr auto height = "height"; + constexpr auto visible = "visible"; + constexpr auto size = "size"; + constexpr auto textobject = "textobject"; + constexpr auto text = "text"; + constexpr auto font = "font"; + constexpr auto fontcolor = "fontcolor"; + constexpr auto reflow = "reflow"; + } + + + + + + namespace parameter { + constexpr auto root = "parameter"; + constexpr auto scales = "customparamscales"; + constexpr auto scale = "customparamscale"; + constexpr auto scaleparametername = "parameter"; + constexpr auto scaleunit = "unit"; + constexpr auto scalescale = "scale"; + constexpr auto scaleoffset = "offset"; + constexpr auto scalevalue = "value"; + constexpr auto scalequantity = "quantity"; + } + + namespace plot { + constexpr auto invert = "invert"; + constexpr auto label = "label"; + } + + namespace variable { + constexpr auto plotsettings = "variableplotsettings"; + constexpr auto plotsetting = "variableplotsetting"; + constexpr auto invertplot = "variableinvertplot"; + constexpr auto plotlabel = "variableplotlabel"; + } + + namespace appearance { + + constexpr auto graphics = "graphics"; + constexpr auto pose = "pose"; + constexpr auto viewport = "viewport"; + constexpr auto nametext = "nametext"; + constexpr auto nametextpos = "nametextpos"; + constexpr auto visible = "nametextvisible"; + constexpr auto locked = "locked"; + constexpr auto disabled = "disabled"; + constexpr auto position = "position"; + constexpr auto alwaysvisible = "alwaysvisible"; + } + + namespace connector { + constexpr auto root = "connect"; + constexpr auto startcomponent = "startcomponent"; + constexpr auto startport = "startport"; + constexpr auto endcomponent = "endcomponent"; + constexpr auto endport = "endport"; + constexpr auto dashed = "dashed"; + constexpr auto coordinates = "coordinates"; + constexpr auto coordinate = "coordinate"; + constexpr auto geometries = "geometries"; + constexpr auto geometry = "geometry"; + constexpr auto style = "style"; + constexpr auto color = "color"; + constexpr auto diagonal = "diagonal"; + } + + namespace version { + constexpr auto hmf = "hmfversion"; + constexpr auto hopsangui = "hopsanguiversion"; + constexpr auto hopsancore = "hopsancoreversion"; + } -#define XML_LIBS "libs" -#define XML_USERLIB "userlib" -#define XML_LIBTYPE "libtype" -#define XML_LIBTYPE_INTERNAL "internal" -#define XML_LIBTYPE_EXTERNAL "external" -#define XML_LIBTYPE_FMU "fmu" - -#define XML_MODELS "models" -#define XML_LASTSESSIONMODEL "lastsessionmodel" -#define XML_RECENTMODEL "recentmodel" -#define XML_RECENTGENERATORMODEL "recentgeneratormodel" + namespace modelinfo { + constexpr auto root = "info"; + constexpr auto author = "author"; + constexpr auto email = "email"; + constexpr auto affiliation = "affiliation"; + constexpr auto description = "description"; + } + + namespace optimization { + constexpr auto root = "optimization"; + constexpr auto numberofsearchpoints = "nsearchp"; + constexpr auto reflectioncoefficient = "refcoeff"; + constexpr auto randomfactor = "randfac"; + constexpr auto forgettingfactor = "forgfac"; + constexpr auto partol = "partol"; + constexpr auto plot = "plot"; + constexpr auto savecsv = "savecsv"; + constexpr auto finaleval = "finaleval"; + constexpr auto logpar = "logpar"; + constexpr auto objectives = "objectives"; + constexpr auto objective = "objective"; + constexpr auto functionname = "functionname"; + constexpr auto weight = "weight"; + constexpr auto norm = "norm"; + constexpr auto exp = "exp"; + constexpr auto data = "data"; + } + + namespace sensitivityanalysis { + constexpr auto root = "senstivitityanalysis"; + constexpr auto settings = "settings"; + constexpr auto iterations = "iterations"; + constexpr auto distribution = "distribution"; + constexpr auto plotvariables = "plotvariables"; + constexpr auto plotvariable = "variable"; + constexpr auto uniformdistribution = "uniform"; + constexpr auto normaldistribution = "normal"; + constexpr auto minmax = "minmax"; + constexpr auto average = "average"; + constexpr auto sigma = "sigma"; + } + namespace deprecated { + constexpr auto variable = "variable"; + constexpr auto portname = "portname"; + constexpr auto value = "value"; + } +} namespace ssv { constexpr auto parameterSet = "ssv:ParameterSet"; diff --git a/HopsanGUI/Widgets/AnimationWidget.cpp b/HopsanGUI/Widgets/AnimationWidget.cpp index 7f641225b5..16c9d1071e 100644 --- a/HopsanGUI/Widgets/AnimationWidget.cpp +++ b/HopsanGUI/Widgets/AnimationWidget.cpp @@ -89,7 +89,7 @@ AnimationWidget::AnimationWidget(QWidget *parent) : mpGraphicsView->setOptimizationFlags(QGraphicsView::DontSavePainterState | QGraphicsView::DontAdjustForAntialiasing); //mpGraphicsView->centerOn(mpGraphicsView->sceneRect().topLeft()); mpGraphicsView->setZoomFactor(pOrgView->getZoomFactor()); - mpGraphicsView->setRenderHint(QPainter::Antialiasing, gpConfig->getBoolSetting(CFG_ANTIALIASING)); + mpGraphicsView->setRenderHint(QPainter::Antialiasing, gpConfig->getBoolSetting(cfg::antialiasing)); double X,Y,Z; pOrgView->getViewPort(X,Y,Z); mpGraphicsView->centerOn(X,Y+3/Z); @@ -621,7 +621,7 @@ void AnimationWidget::resetAllAnimationDataToDefault() AnimatedComponent *pComp = mAnimatedComponentList.at(c); QDomDocument domDocument; - QDomElement animationRoot = domDocument.createElement(HMF_ANIMATION); + QDomElement animationRoot = domDocument.createElement(hmf::animation); domDocument.appendChild(animationRoot); QString subTypeName = pComp->mpModelObject->getSubTypeName(); diff --git a/HopsanGUI/Widgets/DataExplorer.cpp b/HopsanGUI/Widgets/DataExplorer.cpp index 3c4c72559d..db02ddde5e 100644 --- a/HopsanGUI/Widgets/DataExplorer.cpp +++ b/HopsanGUI/Widgets/DataExplorer.cpp @@ -205,7 +205,7 @@ public slots: void openImportDataDialog() { - QFileDialog fd(mpParentWidget, tr("Choose Hopsan Data File"), gpConfig->getStringSetting(CFG_PLOTDATADIR), + QFileDialog fd(mpParentWidget, tr("Choose Hopsan Data File"), gpConfig->getStringSetting(cfg::dir::plotdata), tr("Data Files (*.plo *.PLO *.csv *.CSV);; Space-separated Column Data (*.*);; All (Treat as csv) (*.*)")); fd.setFileMode(QFileDialog::ExistingFiles); const auto rc = fd.exec(); @@ -301,7 +301,7 @@ public slots: // Get save file name if ((pFilenameButtons->checkedButton() == pAppendGenButton) && (gens.size() > 1)) { - QString fileName = QFileDialog::getSaveFileName(mpParentWidget,tr("Choose Hopsan Data File Name"), gpConfig->getStringSetting(CFG_PLOTDATADIR), tr("Data Files")+QString(" (%1)").arg(suffixFilter)); + QString fileName = QFileDialog::getSaveFileName(mpParentWidget,tr("Choose Hopsan Data File Name"), gpConfig->getStringSetting(cfg::dir::plotdata), tr("Data Files")+QString(" (%1)").arg(suffixFilter)); QFileInfo file(fileName); for (int i=0; igetStringSetting(CFG_PLOTDATADIR), tr("Data Files")+QString(" (%1)").arg(suffixFilter))); + fNames.append(QFileDialog::getSaveFileName(mpParentWidget,QString("Choose File Name for Gen: %1").arg(gens[i]), gpConfig->getStringSetting(cfg::dir::plotdata), tr("Data Files")+QString(" (%1)").arg(suffixFilter))); } } // Remember this output dir for later use if (!fNames.isEmpty()) { QFileInfo exportPath(fNames.last()); - gpConfig->setStringSetting(CFG_PLOTDATADIR, exportPath.absolutePath()); + gpConfig->setStringSetting(cfg::dir::plotdata, exportPath.absolutePath()); } QProgressDialog progress("Exporting Data", "Cancel", 0, fNames.size(), mpParentWidget); diff --git a/HopsanGUI/Widgets/HcomWidget.cpp b/HopsanGUI/Widgets/HcomWidget.cpp index 0a8a0a18d5..5c0e0724de 100644 --- a/HopsanGUI/Widgets/HcomWidget.cpp +++ b/HopsanGUI/Widgets/HcomWidget.cpp @@ -95,7 +95,7 @@ TerminalWidget::TerminalWidget(QWidget *pParent) pShowDebugMessagesButton->setToolTip("Show Debug Messages"); mpGroupByTagCheckBox = new QCheckBox("Group Similar Messages"); - mpGroupByTagCheckBox->setChecked(gpConfig->getBoolSetting(CFG_GROUPMESSAGESBYTAG)); + mpGroupByTagCheckBox->setChecked(gpConfig->getBoolSetting(cfg::groupmessagesbytag)); mpConsole = new TerminalConsole(this); mpHandler = new HcomHandler(mpConsole); @@ -144,7 +144,7 @@ QSize TerminalWidget::sizeHint() const //! load the config directly in the constructor. void TerminalWidget::loadConfig() { - mpGroupByTagCheckBox->setChecked(gpConfig->getBoolSetting(CFG_GROUPMESSAGESBYTAG)); + mpGroupByTagCheckBox->setChecked(gpConfig->getBoolSetting(cfg::groupmessagesbytag)); mpConsole->mHistory = gpConfig->getTerminalHistory(); if(!gpConfig->getHcomWorkingDirectory().isEmpty()) @@ -221,7 +221,7 @@ TerminalConsole::TerminalConsole(TerminalWidget *pParent) //this->setTextColor(QColor("Black")); //this->setStyleSheet(QString::fromUtf8("QTextEdit {background-color: white; border: 1px solid gray;}")); - mGroupByTag = gpConfig->getBoolSetting(CFG_GROUPMESSAGESBYTAG); + mGroupByTag = gpConfig->getBoolSetting(cfg::groupmessagesbytag); mDontPrint = false; mDontPrintErrors = false; @@ -397,7 +397,7 @@ void TerminalConsole::abortHCOM() void TerminalConsole::setGroupByTag(bool value) { mGroupByTag = value; - gpConfig->setBoolSetting(CFG_GROUPMESSAGESBYTAG, value); + gpConfig->setBoolSetting(cfg::groupmessagesbytag, value); } diff --git a/HopsanGUI/Widgets/MessageWidget.cpp b/HopsanGUI/Widgets/MessageWidget.cpp index a0daff102d..b783f6c7cd 100644 --- a/HopsanGUI/Widgets/MessageWidget.cpp +++ b/HopsanGUI/Widgets/MessageWidget.cpp @@ -63,7 +63,7 @@ MessageWidget::MessageWidget(QWidget *pParent) mpTextEdit->setMouseTracking(true); mpTextEdit->installEventFilter(this); - mGroupByTag = gpConfig->getBoolSetting(CFG_GROUPMESSAGESBYTAG); + mGroupByTag = gpConfig->getBoolSetting(cfg::groupmessagesbytag); mShowErrorMessages = true; mShowWarningMessages = true; @@ -101,7 +101,7 @@ MessageWidget::MessageWidget(QWidget *pParent) pShowDebugMessagesButton->setToolTip("Show Debug Messages"); mpGroupByTagCheckBox = new QCheckBox("Group Similar Messages"); - mpGroupByTagCheckBox->setChecked(gpConfig->getBoolSetting(CFG_GROUPMESSAGESBYTAG)); + mpGroupByTagCheckBox->setChecked(gpConfig->getBoolSetting(cfg::groupmessagesbytag)); QGridLayout *pLayout = new QGridLayout(this); pLayout->addWidget(mpTextEdit,0,0,1,7); @@ -145,7 +145,7 @@ QSize MessageWidget::sizeHint() const //! load the config directly in the constructor. void MessageWidget::loadConfig() { - mpGroupByTagCheckBox->setChecked(gpConfig->getBoolSetting(CFG_GROUPMESSAGESBYTAG)); + mpGroupByTagCheckBox->setChecked(gpConfig->getBoolSetting(cfg::groupmessagesbytag)); } @@ -278,7 +278,7 @@ void MessageWidget::clear() void MessageWidget::setGroupByTag(bool value) { mGroupByTag = value; - gpConfig->setBoolSetting(CFG_GROUPMESSAGESBYTAG, value); + gpConfig->setBoolSetting(cfg::groupmessagesbytag, value); reprintEverything(); } diff --git a/HopsanGUI/Widgets/ModelWidget.cpp b/HopsanGUI/Widgets/ModelWidget.cpp index 0f742b2511..d49ebda38f 100644 --- a/HopsanGUI/Widgets/ModelWidget.cpp +++ b/HopsanGUI/Widgets/ModelWidget.cpp @@ -456,7 +456,7 @@ void ModelWidget::setUseRemoteSimulation(bool useRemoteCore, bool useAddressServ if (useRemoteCore) { - int nThreads = gpConfig->getIntegerSetting(CFG_NUMBEROFTHREADS); + int nThreads = gpConfig->getIntegerSetting(cfg::numberofthreads); nThreads = qMax(nThreads, 1); QString serveraddress; @@ -465,10 +465,10 @@ void ModelWidget::setUseRemoteSimulation(bool useRemoteCore, bool useAddressServ SharedRemoteCoreAddressHandlerT pAddressHandler = getSharedRemoteCoreAddressHandler(); // Check if we should change server address and reconnect - if (!pAddressHandler.isNull() && (pAddressHandler->getAddressAndPort() != gpConfig->getStringSetting(CFG_REMOTEHOPSANADDRESSSERVERADDRESS)) ) + if (!pAddressHandler.isNull() && (pAddressHandler->getAddressAndPort() != gpConfig->getStringSetting(cfg::remotehopsanaddresserveraddress)) ) { pAddressHandler->disconnect(); - pAddressHandler->setHopsanAddressServer(gpConfig->getStringSetting(CFG_REMOTEHOPSANADDRESSSERVERADDRESS)); + pAddressHandler->setHopsanAddressServer(gpConfig->getStringSetting(cfg::remotehopsanaddresserveraddress)); pAddressHandler->connect(); //! @todo what happens if it disconnects, then we would need to reconnect, we also need to keep the connection alive by polling } @@ -479,14 +479,14 @@ void ModelWidget::setUseRemoteSimulation(bool useRemoteCore, bool useAddressServ } else { - serveraddress = gpConfig->getStringSetting(CFG_REMOTEHOPSANADDRESS); + serveraddress = gpConfig->getStringSetting(cfg::remotehopsanaddress); } if (!serveraddress.isEmpty()) { // If we have found the best available server, then create a local remote simulation handler and connect it to the server mpLocalRemoteCoreSimulationHandler = SharedRemoteCoreSimulationHandlerT(new RemoteCoreSimulationHandler()); - mpLocalRemoteCoreSimulationHandler->setUserIdentification(gpConfig->getStringSetting(CFG_REMOTEHOPSANUSERIDENTIFICATION)); + mpLocalRemoteCoreSimulationHandler->setUserIdentification(gpConfig->getStringSetting(cfg::remotehopsanuseridentification)); mpLocalRemoteCoreSimulationHandler->setNumThreads(nThreads); if (useAddressServer) { @@ -586,7 +586,7 @@ void ModelWidget::setSaved(bool value) bool ModelWidget::simulate_nonblocking() { // Save backup copy (if needed) - if (!isSaved() && gpConfig->getBoolSetting(CFG_AUTOBACKUP)) + if (!isSaved() && gpConfig->getBoolSetting(cfg::autobackup)) { QString fileNameWithoutHmf = mpToplevelSystem->getModelFileInfo().fileName(); fileNameWithoutHmf.chop(4); @@ -622,12 +622,12 @@ bool ModelWidget::simulate_nonblocking() if(!mSimulateMutex.tryLock()) return false; qDebug() << "Calling simulate_nonblocking()"; - if(gpConfig->getBoolSetting(CFG_LOGDURINGSIMULATION)) { + if(gpConfig->getBoolSetting(cfg::logduringsimulation)) { prepareForLogDuringSimulation(); } mpSimulationThreadHandler->setSimulationTimeVariables(mStartTime.toDouble(), mStopTime.toDouble(), mpToplevelSystem->getLogStartTime(), mpToplevelSystem->getNumberOfLogSamples()); mpSimulationThreadHandler->initSimulateFinalize(mpToplevelSystem); - if(gpConfig->getBoolSetting(CFG_LOGDURINGSIMULATION)) { + if(gpConfig->getBoolSetting(cfg::logduringsimulation)) { cleanupAfterLogDuringSimulation(); } } @@ -639,7 +639,7 @@ bool ModelWidget::simulate_nonblocking() bool ModelWidget::simulate_blocking() { // Save backup copy - if (!isSaved() && gpConfig->getBoolSetting(CFG_AUTOBACKUP)) + if (!isSaved() && gpConfig->getBoolSetting(cfg::autobackup)) { //! @todo this should be a help function, also we may not want to call it every time when we run optimization (not sure if that is done now but probably) QString fileNameWithoutHmf = mpToplevelSystem->getModelFileInfo().fileName(); @@ -733,14 +733,14 @@ void ModelWidget::exportModelParametersToSsv() QStringList names, values, dataTypes, quantities, units; getTopLevelSystemContainer()->getAllParametersAndValuesRecursively("", names, values, dataTypes, quantities, units); - QString saveDirectory = gpConfig->getStringSetting(CFG_PARAMETEREXPORTDIR); + QString saveDirectory = gpConfig->getStringSetting(cfg::dir::parameterexport); QString ssvFile = QFileDialog::getSaveFileName(gpMainWindowWidget, tr("Save Parameters to SSV"), saveDirectory, tr("System Structure Parameter Values (*.ssv)")); if(ssvFile.isEmpty()) { return; } - gpConfig->setStringSetting(CFG_PARAMETEREXPORTDIR, QFileInfo(ssvFile).absolutePath()); + gpConfig->setStringSetting(cfg::dir::parameterexport, QFileInfo(ssvFile).absolutePath()); //! @todo Don't assume all parameters to be of real type @@ -809,15 +809,15 @@ void ModelWidget::importModelParametersFromHpf(QString parameterFile) void ModelWidget::importModelParametersFromSsv() { //Let user choose SSV file - QString openLocation = gpConfig->getStringSetting(CFG_PARAMETERIMPORTDIR); + QString openLocation = gpConfig->getStringSetting(cfg::dir::parameterimport); if (openLocation.isEmpty()) { - openLocation = gpConfig->getStringSetting(CFG_LOADMODELDIR); + openLocation = gpConfig->getStringSetting(cfg::dir::loadmodel); } QString parameterFile = QFileDialog::getOpenFileName(gpMainWindowWidget, tr("Load Parameters from SSV File"), openLocation, tr("System Structure Parameter Values (*.ssv)")); if(!parameterFile.isEmpty()) { - gpConfig->setStringSetting(CFG_PARAMETERIMPORTDIR, QFileInfo(parameterFile).absolutePath()); + gpConfig->setStringSetting(cfg::dir::parameterimport, QFileInfo(parameterFile).absolutePath()); } QList ssvParameters; @@ -1091,7 +1091,7 @@ void ModelWidget::collectPlotData(bool overWriteGeneration) void ModelWidget::setUseRemoteSimulation(bool tf) { - setUseRemoteSimulation(tf, gpConfig->getBoolSetting(CFG_USEREMOTEADDRESSSERVER)); + setUseRemoteSimulation(tf, gpConfig->getBoolSetting(cfg::useremoteaddresserver)); } void ModelWidget::revertModel() @@ -1197,7 +1197,7 @@ void ModelWidget::openCurrentContainerInNewTab() void ModelWidget::saveModel(SaveTargetEnumT saveAsFlag, SaveContentsEnumT contents) { // Backup old save file before saving (if old file exists) - if(saveAsFlag == ExistingFile && gpConfig->getBoolSetting(CFG_AUTOBACKUP)) + if(saveAsFlag == ExistingFile && gpConfig->getBoolSetting(cfg::autobackup)) { QFile backupFile(mpToplevelSystem->getModelFileInfo().filePath()); QString fileNameWithoutHmf = mpToplevelSystem->getModelFileInfo().fileName(); @@ -1227,14 +1227,14 @@ void ModelWidget::saveModel(SaveTargetEnumT saveAsFlag, SaveContentsEnumT conten dialogTitle = tr("Save Model File"); saveDirectory = modelDirPath; if(saveDirectory.isEmpty()) { - saveDirectory = gpConfig->getStringSetting(CFG_LOADMODELDIR); + saveDirectory = gpConfig->getStringSetting(cfg::dir::loadmodel); } } else if(contents==ParametersOnly) { filter = tr("Hopsan Parameter Files (*.hpf)"); dialogTitle = tr("Save Parameter File"); - saveDirectory = gpConfig->getStringSetting(CFG_PARAMETEREXPORTDIR); + saveDirectory = gpConfig->getStringSetting(cfg::dir::parameterexport); if(saveDirectory.isEmpty()) { saveDirectory = modelDirPath; } @@ -1261,7 +1261,7 @@ void ModelWidget::saveModel(SaveTargetEnumT saveAsFlag, SaveContentsEnumT conten mpToplevelSystem->getCoreSystemAccessPtr()->addSearchPath(mpToplevelSystem->getModelFileInfo().absolutePath()); - gpConfig->setStringSetting(CFG_LOADMODELDIR, QFileInfo(filePathToDestinationFile).absolutePath()); + gpConfig->setStringSetting(cfg::dir::loadmodel, QFileInfo(filePathToDestinationFile).absolutePath()); mpMessageHandler->addInfoMessage("Saved model: " + filePathToDestinationFile); emit modelSaved(this); @@ -1276,7 +1276,7 @@ void ModelWidget::saveModel(SaveTargetEnumT saveAsFlag, SaveContentsEnumT conten } else if ((contents==ParametersOnly) && success) { - gpConfig->setStringSetting(CFG_PARAMETEREXPORTDIR, QFileInfo(filePathToDestinationFile).absolutePath()); + gpConfig->setStringSetting(cfg::dir::parameterexport, QFileInfo(filePathToDestinationFile).absolutePath()); mpMessageHandler->addInfoMessage("Exported model parameters to: " + filePathToDestinationFile); } } @@ -1398,14 +1398,14 @@ bool ModelWidget::loadModel(QFile &rModelFile) // Check if this is an expected hmf xml file QDomDocument domDocument; - QDomElement hmfRoot = loadXMLDomDocument(rModelFile, domDocument, HMF_ROOTTAG); + QDomElement hmfRoot = loadXMLDomDocument(rModelFile, domDocument, hmf::root); if (!hmfRoot.isNull()) { //! @todo check if we could load else give error message and don't attempt to load - QDomElement systemElement = hmfRoot.firstChildElement(HMF_SYSTEMTAG); + QDomElement systemElement = hmfRoot.firstChildElement(hmf::system); // Check if Format version OK - QString hmfFormatVersion = hmfRoot.attribute(HMF_VERSIONTAG, "0"); + QString hmfFormatVersion = hmfRoot.attribute(hmf::version::hmf, "0"); if (!verifyHmfFormatVersion(hmfFormatVersion)) { gpMessageHandler->addErrorMessage("Model file format: "+hmfFormatVersion+", is to old. Try to update (resave) the model in an previous version of Hopsan"); @@ -1431,7 +1431,7 @@ bool ModelWidget::loadModel(QFile &rModelFile) auto pRequiredLib = gpLibraryHandler->getLibrary(requiredLibID); // Print debug for "old" required data as that data was incorrect - if (hmfRoot.attribute(HMF_HOPSANGUIVERSIONTAG, "0") < "2.9.0.20180816.1300") + if (hmfRoot.attribute(hmf::version::hopsangui, "0") < "2.9.0.20180816.1300") { // Override name due to old xml format requiredLibName = compLib.text(); @@ -1461,7 +1461,7 @@ bool ModelWidget::loadModel(QFile &rModelFile) } // Upconvert adding self. to parameter names - if (hmfRoot.attribute(HMF_HOPSANGUIVERSIONTAG, "0") < "2.14.0") { + if (hmfRoot.attribute(hmf::version::hopsangui, "0") < "2.14.0") { prependSelfToParameterExpressions(mpToplevelSystem); QString neededChanges = checkPrependSelfToEmbeddedScripts(mpToplevelSystem); if (!neededChanges.isEmpty()) { @@ -1480,7 +1480,7 @@ bool ModelWidget::loadModel(QFile &rModelFile) } else { - gpMessageHandler->addErrorMessage(QString("Model does not contain a HMF root tag: ")+HMF_ROOTTAG); + gpMessageHandler->addErrorMessage(QString("Model does not contain a HMF root tag: ")+hmf::root); return false; } } @@ -1505,7 +1505,7 @@ QDomDocument ModelWidget::saveToDom(SaveContentsEnumT contents) } else { - rootElement = domDocument.createElement(HPF_ROOTTAG); + rootElement = domDocument.createElement(hpf::root); domDocument.appendChild(rootElement); } diff --git a/HopsanGUI/Widgets/TextEditorWidget.cpp b/HopsanGUI/Widgets/TextEditorWidget.cpp index c77aff2701..8bcb4be8da 100644 --- a/HopsanGUI/Widgets/TextEditorWidget.cpp +++ b/HopsanGUI/Widgets/TextEditorWidget.cpp @@ -218,7 +218,7 @@ void TextEditorWidget::save(SaveTargetEnumT saveAsFlag) } QFile file(mFileInfo.absoluteFilePath()); - gpConfig->setStringSetting(CFG_LOADSCRIPTDIR, mFileInfo.absolutePath()); + gpConfig->setStringSetting(cfg::dir::loadscript, mFileInfo.absolutePath()); if(!file.open(QFile::WriteOnly | QFile::Text)) { diff --git a/HopsanGUI/Widgets/WelcomeWidget.cpp b/HopsanGUI/Widgets/WelcomeWidget.cpp index 57972e610b..1fe1649295 100644 --- a/HopsanGUI/Widgets/WelcomeWidget.cpp +++ b/HopsanGUI/Widgets/WelcomeWidget.cpp @@ -686,7 +686,7 @@ void WelcomeWidget::checkVersion(QNetworkReply *pReply) official_releases = parseHopsanReleases(reader, HOPSANRELEASEVERSION); } - if (reader.readNextStartElement() && gpConfig->getBoolSetting(CFG_CHECKFORDEVELOPMENTUPDATES) && reader.name() == "development") + if (reader.readNextStartElement() && gpConfig->getBoolSetting(cfg::checkfordevelopmentupdates) && reader.name() == "development") { development_release = parseHopsanReleases(reader, HOPSANRELEASEVERSION); } diff --git a/HopsanGUI/loadFunctions.cpp b/HopsanGUI/loadFunctions.cpp index ec1120a716..6adca133fe 100644 --- a/HopsanGUI/loadFunctions.cpp +++ b/HopsanGUI/loadFunctions.cpp @@ -61,10 +61,10 @@ bool loadConnector(QDomElement &rDomElement, SystemObject* pContainer, UndoStatu QStringList geometryList; // Read core specific stuff - startComponentName = rDomElement.attribute(HMF_CONNECTORSTARTCOMPONENTTAG); - startPortName = rDomElement.attribute(HMF_CONNECTORSTARTPORTTAG); - endComponentName = rDomElement.attribute(HMF_CONNECTORENDCOMPONENTTAG); - endPortName = rDomElement.attribute(HMF_CONNECTORENDPORTTAG); + startComponentName = rDomElement.attribute(hmf::connector::startcomponent); + startPortName = rDomElement.attribute(hmf::connector::startport); + endComponentName = rDomElement.attribute(hmf::connector::endcomponent); + endPortName = rDomElement.attribute(hmf::connector::endport); //qDebug() << "loadConnector: " << startComponentName << " " << startPortName << " " << endComponentName << " " << endPortName; //! @todo To upconvert old models these are needed, may not be necessary later @@ -75,32 +75,32 @@ bool loadConnector(QDomElement &rDomElement, SystemObject* pContainer, UndoStatu // Read gui specific stuff double x,y; - QDomElement guiData = rDomElement.firstChildElement(HMF_HOPSANGUITAG); - QDomElement guiCoordinates = guiData.firstChildElement(HMF_COORDINATES); - QDomElement coordTag = guiCoordinates.firstChildElement(HMF_COORDINATETAG); + QDomElement guiData = rDomElement.firstChildElement(hmf::hopsangui); + QDomElement guiCoordinates = guiData.firstChildElement(hmf::connector::coordinates); + QDomElement coordTag = guiCoordinates.firstChildElement(hmf::connector::coordinate); while (!coordTag.isNull()) { parseCoordinateTag(coordTag, x, y); pointVector.push_back(QPointF(x,y)); - coordTag = coordTag.nextSiblingElement(HMF_COORDINATETAG); + coordTag = coordTag.nextSiblingElement(hmf::connector::coordinate); } - QDomElement guiGeometries = guiData.firstChildElement(HMF_GEOMETRIES); - QDomElement geometryTag = guiGeometries.firstChildElement(HMF_GEOMETRYTAG); + QDomElement guiGeometries = guiData.firstChildElement(hmf::connector::geometries); + QDomElement geometryTag = guiGeometries.firstChildElement(hmf::connector::geometry); while (!geometryTag.isNull()) { geometryList.append(geometryTag.text()); - geometryTag = geometryTag.nextSiblingElement(HMF_GEOMETRYTAG); + geometryTag = geometryTag.nextSiblingElement(hmf::connector::geometry); } - QDomElement styleTag = guiData.firstChildElement(HMF_STYLETAG); + QDomElement styleTag = guiData.firstChildElement(hmf::connector::style); if(!styleTag.isNull()) { - isDashed = (styleTag.text() == "dashed"); + isDashed = (styleTag.text() == hmf::connector::dashed); } else { isDashed = false; } - QDomElement colorTag = guiData.firstChildElement(HMF_COLORTAG); + QDomElement colorTag = guiData.firstChildElement(hmf::connector::color); QColor color = QColor(); if(!colorTag.isNull()) { @@ -123,7 +123,7 @@ bool loadConnector(QDomElement &rDomElement, SystemObject* pContainer, UndoStatu pointVector.push_back(pConn->getStartPort()->boundingRect().center()); pointVector.push_back(pConn->getEndPort()->boundingRect().center()); geometryList.clear(); - geometryList.append("diagonal"); + geometryList.append(hmf::connector::diagonal); } pConn->setPointsAndGeometries(pointVector, geometryList); pConn->setDashed(isDashed); @@ -168,11 +168,11 @@ void loadParameterValue(QDomElement &rDomElement, ModelObject* pObject, UndoStat QString parameterValue; QString parameterType; - parameterName = rDomElement.attribute(HMF_NAMETAG); + parameterName = rDomElement.attribute(hmf::name); parameterName.replace("::","#"); //!< @todo this can be removed in the future (after 0.7), used to upconvert old hmf file formats - parameterValue = rDomElement.attribute(HMF_VALUETAG); - parameterType = rDomElement.attribute(HMF_TYPE); - parameterType = rDomElement.attribute(HMF_TYPENAME, parameterType); //!< @deprecated load old typename + parameterValue = rDomElement.attribute(hmf::value); + parameterType = rDomElement.attribute(hmf::type); + parameterType = rDomElement.attribute(hmf::typenametag, parameterType); //!< @deprecated load old typename //! @todo Remove this check in the future when models should have been updated QStringList existingNames = pObject->getParameterNames(); @@ -205,11 +205,11 @@ void loadParameterValue(QDomElement &rDomElement, ModelObject* pObject, UndoStat if (!tryingToAddColonColonValue && parameterName.contains("::Value")) { QStringList theotherparameternames; - QDomElement parameterDOM = rDomElement.parentNode().firstChildElement(HMF_PARAMETERTAG); + QDomElement parameterDOM = rDomElement.parentNode().firstChildElement(hmf::parameter::root); while (!parameterDOM.isNull()) { - theotherparameternames.append(parameterDOM.attribute(HMF_NAMETAG)); - parameterDOM = parameterDOM.nextSiblingElement(HMF_PARAMETERTAG); + theotherparameternames.append(parameterDOM.attribute(hmf::name)); + parameterDOM = parameterDOM.nextSiblingElement(hmf::parameter::root); } QString portparname = parameterName.split("::")[0]; @@ -231,9 +231,9 @@ void loadParameterValue(QDomElement &rDomElement, ModelObject* pObject, UndoStat //! @deprecated This StartValue load code is only kept for upconverting old files, we should keep it here until we have some other way of upconverting old formats void loadStartValue(QDomElement &rDomElement, ModelObject* pObject, UndoStatusEnumT /*undoSettings*/) { - QString portName = rDomElement.attribute("portname"); - QString variable = rDomElement.attribute("variable"); - QString startValue = rDomElement.attribute("value"); + QString portName = rDomElement.attribute(hmf::deprecated::portname); + QString variable = rDomElement.attribute(hmf::deprecated::variable); + QString startValue = rDomElement.attribute(hmf::deprecated::value); // bool isDbl; // //Assumes that if it is convertible to a double it is a plain value otherwise it is assumed to be mapped to a System parameter @@ -260,32 +260,32 @@ ModelObject* loadModelObject(const QDomElement &domElement, SystemObject* pSyste QDomElement loadDomElement = domElement.cloneNode().toElement(); //Read core specific data - QString type = loadDomElement.attribute(HMF_TYPENAME); - QString subtype = loadDomElement.attribute(HMF_SUBTYPENAME); - QString name = loadDomElement.attribute(HMF_NAMETAG); - bool locked = parseAttributeBool(loadDomElement, HMF_LOCKEDTAG, false); - bool disabled = parseAttributeBool(loadDomElement, HMF_DISABLEDTAG, false); + QString type = loadDomElement.attribute(hmf::typenametag); + QString subtype = loadDomElement.attribute(hmf::subtypename); + QString name = loadDomElement.attribute(hmf::name); + bool locked = parseAttributeBool(loadDomElement, hmf::appearance::locked, false); + bool disabled = parseAttributeBool(loadDomElement, hmf::appearance::disabled, false); //Read gui specific data double posX, posY, target_rotation; bool isFlipped; - QDomElement guiData = loadDomElement.firstChildElement(HMF_HOPSANGUITAG); - parsePoseTag(guiData.firstChildElement(HMF_POSETAG), posX, posY, target_rotation, isFlipped); + QDomElement guiData = loadDomElement.firstChildElement(hmf::hopsangui); + parsePoseTag(guiData.firstChildElement(hmf::appearance::pose), posX, posY, target_rotation, isFlipped); target_rotation = normDeg360(target_rotation); //Make sure target rotation between 0 and 359.999 - bool alwaysVisible = parseAttributeBool(guiData, "alwaysvisible", false); + bool alwaysVisible = parseAttributeBool(guiData, hmf::appearance::alwaysvisible, false); - int nameTextPos = guiData.firstChildElement(HMF_NAMETEXTTAG).attribute("position").toInt(); - bool nameTextVisible = parseAttributeBool(guiData.firstChildElement(HMF_NAMETEXTTAG), "visible", false); + int nameTextPos = guiData.firstChildElement(hmf::appearance::nametext).attribute(hmf::appearance::position).toInt(); + bool nameTextVisible = parseAttributeBool(guiData.firstChildElement(hmf::appearance::nametext), hmf::appearance::visible, false); const SharedModelObjectAppearanceT pAppearanceData = gpLibraryHandler->getModelObjectAppearancePtr(type, subtype); if (pAppearanceData && gpLibraryHandler->getEntry(type).state != Disabled) { ModelObjectAppearance appearanceData = *pAppearanceData; //Make a copy - QDomElement animationElement = guiData.firstChildElement(HMF_ANIMATION); + QDomElement animationElement = guiData.firstChildElement(hmf::animation); if(!animationElement.isNull() && appearanceData.getTypeName() == type) { appearanceData.getAnimationDataPtr()->readFromDomElement(animationElement, appearanceData.getBasePath()); @@ -310,7 +310,7 @@ ModelObject* loadModelObject(const QDomElement &domElement, SystemObject* pSyste pObj->setNameTextPos(nameTextPos); pObj->setNameTextAlwaysVisible(nameTextVisible); pObj->setSubTypeName(subtype); //!< @todo is this really needed - loadDomElement.setAttribute(HMF_NAMETAG, pObj->getName()); // Update name in load data to avoid additional rename + loadDomElement.setAttribute(hmf::name, pObj->getName()); // Update name in load data to avoid additional rename //First set flip (before rotate, Important!) //! @todo For now If flipped than we need to rotate in wrong direction also, saving saves flipped rotation angle i think but changing save and load would cause old models to load incorrectly @@ -325,13 +325,13 @@ ModelObject* loadModelObject(const QDomElement &domElement, SystemObject* pSyste } //Read system specific core and gui data - if (loadDomElement.tagName() == HMF_SYSTEMTAG) + if (loadDomElement.tagName() == hmf::system) { //Check if we should load an embedded or external system QString externalFilePath = appearanceData.getBasePath()+"/"+appearanceData.getHmfFile(); if(!QFile::exists(externalFilePath) || appearanceData.getSubTypeName().isEmpty()) { - externalFilePath = loadDomElement.attribute(HMF_EXTERNALPATHTAG); + externalFilePath = loadDomElement.attribute(hmf::externalpath); } if (externalFilePath.isEmpty()) { @@ -362,10 +362,10 @@ ModelObject* loadModelObject(const QDomElement &domElement, SystemObject* pSyste if (externalModelFile.exists()) { QDomDocument domDocument; - QDomElement externalRoot = loadXMLDomDocument(externalModelFile, domDocument, HMF_ROOTTAG); - QDomElement externalSystemRoot = externalRoot.firstChildElement(HMF_SYSTEMTAG); + QDomElement externalRoot = loadXMLDomDocument(externalModelFile, domDocument, hmf::root); + QDomElement externalSystemRoot = externalRoot.firstChildElement(hmf::system); //! @todo set the modefile info, maybe we should have built in helpfunction for loading directly from file in System - pObj->setModelFileInfo(externalModelFile, loadDomElement.attribute(HMF_EXTERNALPATHTAG)); + pObj->setModelFileInfo(externalModelFile, loadDomElement.attribute(hmf::externalpath)); pObj->getAppearanceData()->setBasePath(extFileInfo.absolutePath()); // Set the basepath for relative icon paths pObj->loadFromDomElement(externalSystemRoot); //! @todo this code is duplicated with the one in system->loadfromdomelement (external code) that code will never run, as this will take care of it. When we have embedded subsystems will will need to fix this @@ -377,13 +377,13 @@ ModelObject* loadModelObject(const QDomElement &domElement, SystemObject* pSyste } // Now load all overwritten parameters - QDomElement xmlParameters = loadDomElement.firstChildElement(HMF_PARAMETERS); - QDomElement xmlParameter = xmlParameters.firstChildElement(HMF_PARAMETERTAG); + QDomElement xmlParameters = loadDomElement.firstChildElement(hmf::parameters); + QDomElement xmlParameter = xmlParameters.firstChildElement(hmf::parameter::root); while (!xmlParameter.isNull()) { SystemObject* pCont = dynamic_cast(pObj); loadSystemParameter(xmlParameter, false, "1000", pCont); - xmlParameter = xmlParameter.nextSiblingElement(HMF_PARAMETERTAG); + xmlParameter = xmlParameter.nextSiblingElement(hmf::parameter::root); } } else @@ -397,29 +397,29 @@ ModelObject* loadModelObject(const QDomElement &domElement, SystemObject* pSyste { //! @todo maybe this parameter load code and the one for external systems above could be the same //Load parameter values - QDomElement xmlParameters = loadDomElement.firstChildElement(HMF_PARAMETERS); - QDomElement xmlParameter = xmlParameters.firstChildElement(HMF_PARAMETERTAG); + QDomElement xmlParameters = loadDomElement.firstChildElement(hmf::parameters); + QDomElement xmlParameter = xmlParameters.firstChildElement(hmf::parameter::root); while (!xmlParameter.isNull()) { loadParameterValue(xmlParameter, pObj, NoUndo); - xmlParameter = xmlParameter.nextSiblingElement(HMF_PARAMETERTAG); + xmlParameter = xmlParameter.nextSiblingElement(hmf::parameter::root); } // Load any custom signal quantities - QDomElement portTag = loadDomElement.firstChildElement(HMF_PORTSTAG).firstChildElement(HMF_PORTTAG); + QDomElement portTag = loadDomElement.firstChildElement(hmf::ports).firstChildElement(hmf::port); while (!portTag.isNull()) { - QString q = portTag.attribute("signalquantity"); + QString q = portTag.attribute(hmf::signalquantity); if (!q.isEmpty()) { - pObj->setModifyableSignalQuantity(portTag.attribute("name")+"#Value", q); + pObj->setModifyableSignalQuantity(portTag.attribute(hmf::name)+"#Value", q); } - portTag = portTag.nextSiblingElement(HMF_PORTTAG); + portTag = portTag.nextSiblingElement(hmf::port); } // Load component specific override port data, and dynamic parameter port positions - QDomElement cafMoStuff = loadDomElement.firstChildElement(HMF_HOPSANGUITAG).firstChildElement(CAF_ROOT).firstChildElement(CAF_MODELOBJECT); + QDomElement cafMoStuff = loadDomElement.firstChildElement(hmf::hopsangui).firstChildElement(caf::root).firstChildElement(caf::modelobject); if (!cafMoStuff.isNull()) { //We read all model object appearance data in the hmf to get the ports @@ -428,11 +428,11 @@ ModelObject* loadModelObject(const QDomElement &domElement, SystemObject* pSyste pObj->refreshDisplayName(); //Need to refresh display name if read appearance data contained an incorrect name // Now refresh only those ports that were new - QDomElement dom_port = cafMoStuff.firstChildElement("ports").firstChildElement("port"); + QDomElement dom_port = cafMoStuff.firstChildElement(hmf::ports).firstChildElement(hmf::port); while (!dom_port.isNull()) { // Create or refresh modified ports - QString portName = dom_port.attribute("name"); + QString portName = dom_port.attribute(hmf::name); pObj->createRefreshExternalPort(portName); Port *pPort = pObj->getPort(portName); @@ -441,17 +441,17 @@ ModelObject* loadModelObject(const QDomElement &domElement, SystemObject* pSyste pPort->setModified(true); //Tag as modified since we loaded override data } - dom_port = dom_port.nextSiblingElement("port"); + dom_port = dom_port.nextSiblingElement(hmf::port); } } // Load any custom set parameter scales - QDomElement paramscale = loadDomElement.firstChildElement(HMF_HOPSANGUITAG).firstChildElement(HMF_PARAMETERSCALES).firstChildElement(HMF_PARAMETERSCALE); + QDomElement paramscale = loadDomElement.firstChildElement(hmf::hopsangui).firstChildElement(hmf::parameter::scales).firstChildElement(hmf::parameter::scale); while (!paramscale.isNull()) { - QString quantity = paramscale.attribute(HMF_PARAMETERSCALEQUANTITY); - QString unit = paramscale.attribute(HMF_PARAMETERSCALEUNIT); - QString scale = paramscale.attribute(HMF_PARAMETERSCALESCALE); + QString quantity = paramscale.attribute(hmf::parameter::scalequantity); + QString unit = paramscale.attribute(hmf::parameter::scaleunit); + QString scale = paramscale.attribute(hmf::parameter::scalescale); UnitConverter confus, us; gpConfig->getUnitScale(quantity, unit, confus); @@ -466,31 +466,31 @@ ModelObject* loadModelObject(const QDomElement &domElement, SystemObject* pSyste us = UnitConverter(quantity, unit, scale, - paramscale.attribute(HMF_PARAMETERSCALEOFFSET)); + paramscale.attribute(hmf::parameter::scaleoffset)); } - pObj->registerCustomParameterUnitScale(paramscale.attribute(HMF_PARAMETERSCALEPARAMNAME), us); + pObj->registerCustomParameterUnitScale(paramscale.attribute(hmf::parameter::scaleparametername), us); //! @todo The actual custom value is ignored here, since only scale can be registered, custom values are not a part of parameters yet so it is difficult to support loading custom values, (rescaling will happen automatically from SI unit value loaded by core) - paramscale = paramscale.nextSiblingElement(HMF_PARAMETERSCALE); + paramscale = paramscale.nextSiblingElement(hmf::parameter::scale); } // Load any custom variable plot settings - QDomElement plotsetting = loadDomElement.firstChildElement(HMF_HOPSANGUITAG).firstChildElement(HMF_VARIABLEPLOTSETTINGS).firstChildElement(HMF_VARIABLEPLOTSETTING); + QDomElement plotsetting = loadDomElement.firstChildElement(hmf::hopsangui).firstChildElement(hmf::variable::plotsettings).firstChildElement(hmf::variable::plotsetting); while (!plotsetting.isNull()) { - QString name = plotsetting.attribute("name"); + QString name = plotsetting.attribute(hmf::name); if (!name.isEmpty()) { - if(plotsetting.hasAttribute("invert")) + if(plotsetting.hasAttribute(hmf::plot::invert)) { - pObj->setInvertPlotVariable(name, parseAttributeBool(plotsetting, "invert", false)); + pObj->setInvertPlotVariable(name, parseAttributeBool(plotsetting, hmf::plot::invert, false)); } - if(plotsetting.hasAttribute("label")) + if(plotsetting.hasAttribute(hmf::plot::label)) { - pObj->setVariablePlotLabel(name, plotsetting.attribute("label")); + pObj->setVariablePlotLabel(name, plotsetting.attribute(hmf::plot::label)); } } - plotsetting = plotsetting.nextSiblingElement(HMF_VARIABLEPLOTSETTING); + plotsetting = plotsetting.nextSiblingElement(hmf::variable::plotsetting); } } @@ -516,7 +516,7 @@ ModelObject* loadModelObject(const QDomElement &domElement, SystemObject* pSyste ModelObject* loadSystemPortObject(QDomElement &rDomElement, SystemObject* pSystem, UndoStatusEnumT undoSettings) { //! @todo this does not feel right should try to avoid it maybe - rDomElement.setAttribute(HMF_TYPENAME, HOPSANGUISYSTEMPORTTYPENAME); //Set the typename for the gui, or overwrite if anything was actually given in the HMF file + rDomElement.setAttribute(hmf::typenametag, HOPSANGUISYSTEMPORTTYPENAME); //Set the typename for the gui, or overwrite if anything was actually given in the HMF file return loadModelObject(rDomElement, pSystem, undoSettings); //We use the loadGUIModelObject function as it does what is needed } @@ -527,13 +527,13 @@ ModelObject* loadSystemPortObject(QDomElement &rDomElement, SystemObject* pSyste //! @param[in] pContainer The Container Object to load into void loadSystemParameter(QDomElement &rDomElement, bool doAdd, const QString hmfVersion, SystemObject* pContainer) { - QString name = rDomElement.attribute(HMF_NAMETAG); - QString value = rDomElement.attribute(HMF_VALUETAG); - QString type = rDomElement.attribute(HMF_TYPE); - type = rDomElement.attribute(HMF_TYPENAME, type); //!< @deprecated load old typename - QString quantityORunit = rDomElement.attribute(HMF_QUANTITY, rDomElement.attribute(HMF_UNIT)); - QString description = rDomElement.attribute(HMF_DESCRIPTIONTAG); - bool internal = parseAttributeBool(rDomElement, HMF_INTERNAL, false); + QString name = rDomElement.attribute(hmf::name); + QString value = rDomElement.attribute(hmf::value); + QString type = rDomElement.attribute(hmf::type); + type = rDomElement.attribute(hmf::typenametag, type); //!< @deprecated load old typename + QString quantityORunit = rDomElement.attribute(hmf::quantity, rDomElement.attribute(hmf::unit)); + QString description = rDomElement.attribute(hmf::modelinfo::description); + bool internal = parseAttributeBool(rDomElement, hmf::internal, false); if( (hmfVersion <= "0.3") && type.isEmpty()) //Version check, types did not exist in 0.3 and bellow (everything was double) { @@ -561,18 +561,18 @@ void loadPlotAlias(QDomElement &rDomElement, SystemObject* pContainer) //! @todo not hardcoded attrnames //! @todo what about type //! @todo actually Core should load this data - QString type = rDomElement.attribute("type", "UnknownAliasType"); - aliasname = rDomElement.attribute("name", "UnknownAliasName"); - fullName = rDomElement.firstChildElement("fullname").text(); + QString type = rDomElement.attribute(hmf::type, "UnknownAliasType"); + aliasname = rDomElement.attribute(hmf::name, "UnknownAliasName"); + fullName = rDomElement.firstChildElement(hmf::fullname).text(); // try the old format //! @todo don't know if this works, but likely only atlas cares if (type=="UnknownAliasType") { - aliasname = rDomElement.attribute("alias"); - QString componentName = rDomElement.attribute("component"); - QString portName = rDomElement.attribute("port"); - QString dataName = rDomElement.attribute("data"); + aliasname = rDomElement.attribute(hmf::alias); + QString componentName = rDomElement.attribute(hmf::component); + QString portName = rDomElement.attribute(hmf::port); + QString dataName = rDomElement.attribute(hmf::data); //! @todo we need a help function to build and to split a full variable name fullName = componentName+"#"+portName+"#"+dataName; diff --git a/HopsanGUI/main.cpp b/HopsanGUI/main.cpp index 43384d6efb..da2f62bc2d 100644 --- a/HopsanGUI/main.cpp +++ b/HopsanGUI/main.cpp @@ -201,7 +201,7 @@ R"(HopsanGUI gpMessageHandler->startPublish(); // Show license dialog - if (gpConfig->getBoolSetting(CFG_SHOWLICENSEONSTARTUP)) + if (gpConfig->getBoolSetting(cfg::showlicenseonstartup)) { (new LicenseDialog(gpMainWindowWidget))->show(); // Note! it will delete on close automatically From de37013df04d6d0fc702963ce862a7679c790d2f Mon Sep 17 00:00:00 2001 From: Robert Braun Date: Thu, 15 Feb 2024 09:26:56 +0100 Subject: [PATCH 3/3] Fix Linux and 32-bit compilation --- HopsanGUI/Configuration.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/HopsanGUI/Configuration.cpp b/HopsanGUI/Configuration.cpp index 3d5f453f37..c7ac2b17d4 100644 --- a/HopsanGUI/Configuration.cpp +++ b/HopsanGUI/Configuration.cpp @@ -1313,9 +1313,9 @@ void Configuration::registerSettings() mStringSettings.insert(cfg::dir::gcc32, ""); #ifndef _WIN32 #ifdef HOPSANCOMPILED64BIT - mStringSettings.insert(cfg::GCC64DIR, "/usr/bin"); + mStringSettings.insert(cfg::dir::gcc64, "/usr/bin"); #else - mStringSettings.insert(cfg::GCC32DIR, "/usr/bin"); + mStringSettings.insert(cfg::dir::gcc32, "/usr/bin"); #endif //! @todo OSX ? #endif @@ -1343,7 +1343,7 @@ void Configuration::registerSettings() #if defined(_WIN32) mBoolSettings.insert(cfg::nativestylesheet, false); #else - mBoolSettings.insert(cfg::NATIVESTYLESHEET, true); + mBoolSettings.insert(cfg::nativestylesheet, true); #endif mBoolSettings.insert(cfg::showpopuphelp, true); mBoolSettings.insert(cfg::multicore, false); @@ -1355,7 +1355,7 @@ void Configuration::registerSettings() #ifdef _WIN32 mBoolSettings.insert(cfg::preferincludedcompiler, true); #else - mBoolSettings.insert(cfg::PREFERINCLUDEDCOMPILER, false); + mBoolSettings.insert(cfg::preferincludedcompiler, false); #endif // Integer settings @@ -1392,7 +1392,7 @@ QString Configuration::getGCCPath() const #ifdef HOPSANCOMPILED64BIT return getStringSetting(cfg::dir::gcc64); #else - return getStringSetting(cfg::GCC32DIR); + return getStringSetting(cfg::dir::gcc32); #endif }