Skip to content
Snippets Groups Projects
Commit 269be6c1 authored by Martin Christoph Hierholzer's avatar Martin Christoph Hierholzer
Browse files

implement HierarchyModifier::moveToRoot

parent 9b0ec308
No related branches found
No related tags found
No related merge requests found
......@@ -195,8 +195,8 @@ namespace ChimeraTK {
/** Add the part of the tree structure matching the given tag to a
* VirtualModule. Users normally will use findTag() instead. "tag" is
* interpreted as a regular expression (see std::regex_match). */
void findTagAndAppendToModule(VirtualModule& module, const std::string& tag, bool eliminateAllHierarchies = false,
bool eliminateFirstHierarchy = false, bool negate = false) const;
void findTagAndAppendToModule(VirtualModule& module, const std::string& tag, bool eliminateAllHierarchies,
bool eliminateFirstHierarchy, bool negate, VirtualModule& root) const;
/** The name of this instance */
std::string _name;
......
......@@ -14,6 +14,7 @@
#include "Module.h"
#include "ModuleGraphVisitor.h"
#include "VirtualModule.h"
#include "Application.h"
namespace ChimeraTK {
......@@ -98,7 +99,16 @@ namespace ChimeraTK {
VirtualModule module{_name, _description, getModuleType()};
// add everything matching the tag to the virtual module and return it
findTagAndAppendToModule(module, tag, false, true);
if(this == &Application::getInstance()) {
// if this module is the top-level application, we need special treatment for HierarchyModifier::moveThisToRoot
findTagAndAppendToModule(module, tag, false, true, false, module);
}
else {
// Not the top-level module: Things that are moved to the top-level are simply discarded
VirtualModule discard("discarded", "", ModuleType::Invalid);
findTagAndAppendToModule(module, tag, false, true, false, discard);
}
return module;
}
......@@ -109,14 +119,22 @@ namespace ChimeraTK {
VirtualModule module{_name, _description, getModuleType()};
// add everything matching the tag to the virtual module and return it
findTagAndAppendToModule(module, tag, false, true, true);
if(this == &Application::getInstance()) {
// if this module is the top-level application, we need special treatment for HierarchyModifier::moveToRoot
findTagAndAppendToModule(module, tag, false, true, true, module);
}
else {
// Not the top-level module: Things that are moved to the top-level are simply discarded
VirtualModule discard("discarded", "", ModuleType::Invalid);
findTagAndAppendToModule(module, tag, false, true, true, discard);
}
return module;
}
/*********************************************************************************************************************/
void EntityOwner::findTagAndAppendToModule(VirtualModule& module, const std::string& tag,
bool eliminateAllHierarchies, bool eliminateFirstHierarchy, bool negate) const {
bool eliminateAllHierarchies, bool eliminateFirstHierarchy, bool negate, VirtualModule& root) const {
VirtualModule nextmodule{_name, _description, getModuleType()};
VirtualModule* moduleToAddTo;
......@@ -153,17 +171,22 @@ namespace ChimeraTK {
// exists: add to the existing module
auto* existingSubModule = dynamic_cast<VirtualModule*>(moduleToAddTo->getSubmodule(submodule->getName()));
assert(existingSubModule != nullptr);
submodule->findTagAndAppendToModule(*existingSubModule, tag, eliminateAllHierarchies, true, negate);
submodule->findTagAndAppendToModule(*existingSubModule, tag, eliminateAllHierarchies, true, negate, root);
}
else {
// does not yet exist: add as new submodule to the current module
submodule->findTagAndAppendToModule(*moduleToAddTo, tag, eliminateAllHierarchies, false, negate);
submodule->findTagAndAppendToModule(*moduleToAddTo, tag, eliminateAllHierarchies, false, negate, root);
}
}
if(needToAddSubModule) {
if(nextmodule.getAccessorList().size() > 0 || nextmodule.getSubmoduleList().size() > 0) {
module.addSubModule(nextmodule);
if(_hierarchyModifier != HierarchyModifier::moveToRoot) {
module.addSubModule(nextmodule);
}
else {
root.addSubModule(nextmodule);
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment