Skip to content

Commit

Permalink
Prevent recompilation of library with XML flag
Browse files Browse the repository at this point in the history
  • Loading branch information
robbr48 committed Jan 23, 2024
1 parent debf953 commit 449500b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion HopsanGUI/LibraryHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions HopsanGUI/LibraryHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class GUIComponentLibrary
public:
QString id;
QString version;
bool recompilable;
QString name;
QString loadPath;
QString xmlFilePath;
Expand Down
4 changes: 4 additions & 0 deletions HopsanGUI/Widgets/LibraryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion HopsanGenerator/templates/library_template.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<hopsancomponentlibrary version="0.3">
<hopsancomponentlibrary version="0.3" recompilable="true">
<id><<<libid>>></id>
<name><<<libname>>></name>
<lib debug_ext="<<<libdebugext>>>"><<<libname>>></lib>
Expand Down

0 comments on commit 449500b

Please sign in to comment.