diff --git a/HopsanGUI/LibraryHandler.cpp b/HopsanGUI/LibraryHandler.cpp index dd606db5b..536ed817c 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 900889974..71d9e27aa 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 b39104234..2c14bfbc0 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 42dcfdda5..84876f817 100644 --- a/HopsanGenerator/templates/library_template.xml +++ b/HopsanGenerator/templates/library_template.xml @@ -1,5 +1,5 @@ - + <<>> <<>> <<>>