From 449500b041ad4b96195c4c2e362720ecb18938bf Mon Sep 17 00:00:00 2001 From: Robert Braun Date: Tue, 28 Nov 2023 11:48:51 +0100 Subject: [PATCH] Prevent recompilation of library with XML flag --- HopsanGUI/LibraryHandler.cpp | 10 +++++++++- HopsanGUI/LibraryHandler.h | 1 + HopsanGUI/Widgets/LibraryWidget.cpp | 4 ++++ HopsanGenerator/templates/library_template.xml | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/HopsanGUI/LibraryHandler.cpp b/HopsanGUI/LibraryHandler.cpp index dd606db5b0..536ed817c5 100644 --- a/HopsanGUI/LibraryHandler.cpp +++ b/HopsanGUI/LibraryHandler.cpp @@ -33,6 +33,8 @@ //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" @@ -1124,7 +1126,8 @@ bool LibraryHandler::loadLibrary(SharedComponentLibraryPtrT pLibrary, LibraryTyp QDomElement xmlRoot = domDocument.documentElement(); if(xmlRoot.tagName() == QString(XML_LIBRARY)) { - pLibrary->version = xmlRoot.attribute("version"); + pLibrary->version = xmlRoot.attribute(XML_VERSION); + pLibrary->recompilable = parseAttributeBool(xmlRoot, XML_RECOMPILABLE, true); // Read name of library pLibrary->name = xmlRoot.firstChildElement(XML_LIBRARY_NAME).text(); if (pLibrary->name.isEmpty()) { @@ -1685,6 +1688,11 @@ void LibraryHandler::importFmu() //! @param solver Solver to use (for Modelica code only) void LibraryHandler::recompileLibrary(SharedComponentLibraryPtrT pLib, bool dontUnloadAndLoad) { + if(!pLib->recompilable) { + gpMessageHandler->addErrorMessage("Library is not recompilable."); + return; + } + CoreLibraryAccess coreLibrary; auto spGenerator = createDefaultImportGenerator(); diff --git a/HopsanGUI/LibraryHandler.h b/HopsanGUI/LibraryHandler.h index 9008899748..71d9e27aa0 100644 --- a/HopsanGUI/LibraryHandler.h +++ b/HopsanGUI/LibraryHandler.h @@ -55,6 +55,7 @@ class GUIComponentLibrary public: QString id; QString version; + bool recompilable; QString name; QString loadPath; QString xmlFilePath; diff --git a/HopsanGUI/Widgets/LibraryWidget.cpp b/HopsanGUI/Widgets/LibraryWidget.cpp index b391042343..2c14bfbc09 100644 --- a/HopsanGUI/Widgets/LibraryWidget.cpp +++ b/HopsanGUI/Widgets/LibraryWidget.cpp @@ -531,6 +531,10 @@ void LibraryWidget::handleItemClick(QTreeWidgetItem *item, int column) else if (pReply == pRecompileAction) { gpModelHandler->saveState(); SharedComponentLibraryPtrT pLib = mItemToLibraryMap[item]; + if(!pLib->recompilable) { + gpMessageHandler->addErrorMessage("Library is not recompilable."); + return; + } bool expanded = getLibraryItem(pLib)->isExpanded(); // First unload the library QString libPath = pLib->xmlFilePath; diff --git a/HopsanGenerator/templates/library_template.xml b/HopsanGenerator/templates/library_template.xml index 42dcfdda5b..84876f8170 100644 --- a/HopsanGenerator/templates/library_template.xml +++ b/HopsanGenerator/templates/library_template.xml @@ -1,5 +1,5 @@ - + <<>> <<>> <<>>