Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct typenames when regenerating component libraries #2196

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions HopsanGenerator/src/generators/HopsanGeneratorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,8 +1097,29 @@ bool HopsanGeneratorBase::generateLibrarySourceFile(const ComponentLibrary &lib)
output.append("extern \"C\" DLLEXPORT void register_contents(ComponentFactory* pComponentFactory, NodeFactory* pNodeFactory)\n");
output.append("{\n");
output.append(" //Register Components\n");
for(const QString& srcFile : lib.mComponentCodeFiles) {
QString typeName = QFileInfo(srcFile).baseName();
for(const QString& cafPath : lib.mComponentXMLFiles) {
QFile cafFile(QFileInfo(lib.mLoadFilePath).path()+"/"+cafPath);
QDomDocument cafDomDocument;
QDomElement cafRootElement;
cafRootElement = loadXMLDomDocument(cafFile,cafDomDocument,"hopsanobjectappearance");
if(QDomElement() == cafRootElement) {
printErrorMessage("Unable to parse XML file: "+QString(lib.mLoadFilePath+"/"+cafPath));
return false;
}
QDomElement modelObjectElement = cafRootElement.firstChildElement("modelobject");
if(modelObjectElement.isNull()) {
printErrorMessage("Unable to parse XML file: "+QString(lib.mLoadFilePath+"/"+cafPath)+" (cannot find \"modelobject\" element)");
return false;
}
QString typeName = modelObjectElement.attribute("typename");
if(typeName.isEmpty()) {
printErrorMessage("Type name not specified in component XML file.");
return false;
}
cafFile.close();
if(modelObjectElement.hasAttribute("subtypename") || modelObjectElement.hasAttribute("hmffile")) {
continue;
}
output.append(" pComponentFactory->registerCreatorFunction(\""+typeName+"\", "+typeName+"::Creator);\n");
}
output.append("\n");
Expand Down