Skip to content
Snippets Groups Projects
Commit 1a344e29 authored by Martin Killenberg's avatar Martin Killenberg
Browse files

implemented oneLevelUp without hiding

parent 6468ce67
No related branches found
No related tags found
No related merge requests found
......@@ -211,7 +211,7 @@ namespace ChimeraTK {
* 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,
bool eliminateFirstHierarchy, bool negate, VirtualModule& root) const;
bool eliminateFirstHierarchy, bool negate, VirtualModule& root, VirtualModule * ownerOfModule) const;
/** The name of this instance */
std::string _name;
......
......@@ -41,7 +41,10 @@ namespace ChimeraTK {
moveToRoot, ///< The module at which this flag is specified is moved to the root level, together with the entire
///< structure below the module. Note: Unless you run findTag() or so on the entire application, the
///< moved hierarchy structures might not be visible in the control system etc.
oneLevelUp ///< Move the structure in the module up to the level where the owner lives. Instead of adding a hierrarchy
oneLevelUp, ///< Move the module up to the level where the owner lives. Instead of creating a "daughter"
///< of the owning module, it creates a "sister" (module that lives on the same level).
///< This modifyer can only be used in sub-modules, not on the first level
oneUpAndHide///< Move the structure inside the module up to the level where the owner lives. Instead of adding a hierrarchy
///< level, one level is removed. This modifyer can only be used in sub-modules, not on the first level
///< inside an application.
};
......
......@@ -101,12 +101,12 @@ namespace ChimeraTK {
// add everything matching the tag to the virtual module and return it
if(this == &Application::getInstance()) {
// if this module is the top-level application, we need special treatment for HierarchyModifier::moveToRoot
findTagAndAppendToModule(module, tag, false, true, false, module);
findTagAndAppendToModule(module, tag, false, true, false, module, nullptr);
}
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);
findTagAndAppendToModule(module, tag, false, true, false, discard, nullptr);
}
return module;
......@@ -121,12 +121,12 @@ namespace ChimeraTK {
// add everything matching the tag to the virtual module and return it
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);
findTagAndAppendToModule(module, tag, false, true, true, module, nullptr);
}
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);
findTagAndAppendToModule(module, tag, false, true, true, discard, nullptr);
}
return module;
}
......@@ -134,17 +134,20 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
void EntityOwner::findTagAndAppendToModule(VirtualModule& module, const std::string& tag,
bool eliminateAllHierarchies, bool eliminateFirstHierarchy, bool negate, VirtualModule& root) const {
bool eliminateAllHierarchies, bool eliminateFirstHierarchy, bool negate, VirtualModule& root, VirtualModule * ownerOfModule) const {
VirtualModule nextmodule{_name, _description, getModuleType()};
VirtualModule* moduleToAddTo;
VirtualModule* ownerOfModuleToAddTo;
bool needToAddSubModule = false;
if(!getEliminateHierarchy() && !eliminateAllHierarchies && !eliminateFirstHierarchy) {
moduleToAddTo = &nextmodule;
ownerOfModuleToAddTo = &module;
needToAddSubModule = true;
}
else {
moduleToAddTo = &module;
ownerOfModuleToAddTo = ownerOfModule;
}
// add nodes to the module if matching the tag
......@@ -171,11 +174,11 @@ 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, root);
submodule->findTagAndAppendToModule(*existingSubModule, tag, eliminateAllHierarchies, true, negate, root, ownerOfModuleToAddTo);
}
else {
// does not yet exist: add as new submodule to the current module
submodule->findTagAndAppendToModule(*moduleToAddTo, tag, eliminateAllHierarchies, false, negate, root);
submodule->findTagAndAppendToModule(*moduleToAddTo, tag, eliminateAllHierarchies, false, negate, root, ownerOfModuleToAddTo);
}
}
......@@ -184,10 +187,9 @@ namespace ChimeraTK {
if(_hierarchyModifier == HierarchyModifier::moveToRoot) {
root.addSubModule(nextmodule);
}
else if(_hierarchyModifier == HierarchyModifier::moveToRoot) {
auto owner = dynamic_cast<VirtualModule*>(module.getOwner());
if(owner) { // the root does not have an owner.
owner->addSubModule(nextmodule);
else if(_hierarchyModifier == HierarchyModifier::oneLevelUp) {
if(ownerOfModule) { // the root does not have an owner.
ownerOfModule->addSubModule(nextmodule);
}
else {
throw logic_error(std::string("Module ") + module.getName() +
......
......@@ -36,8 +36,12 @@ struct FirstHierarchy : ctk::ModuleGroup {
ctk::ScalarOutput<int> varC{this, "varC", "MV/m", "Desc"};
struct : ctk::VariableGroup {
using ctk::VariableGroup::VariableGroup;
ctk::ScalarPushInput<double> sisterOfVarGroup{this, "sisterOfVarGroup", "MV/m", "Desc"};
} movedUp{getOwner(), "youLNeverSee", "minus one test", ctk::HierarchyModifier::hideThis, {"Partial"}};
ctk::ScalarPushInput<double> nieceOfVarGroup{this, "nieceOfVarGroup", "MV/m", "Desc"};
} movedUp{this, "sisterGroupOfVarGroup", "minus one test 1", ctk::HierarchyModifier::oneLevelUp, {"Partial"}};
struct : ctk::VariableGroup {
using ctk::VariableGroup::VariableGroup;
ctk::ScalarPushInput<double> sisterVarOfVarGroup{this, "sisterVarOfVarGroup", "MV/m", "Desc"};
} movedUpAndHidden{this, "youLNeverSee", "minus one test 2", ctk::HierarchyModifier::oneUpAndHide, {"Partial"}};
} varGroup{this, "VarGroup", "A group", ctk::HierarchyModifier::none, {"Exclude", "Partial"}};
struct MoveToRoot : ctk::VariableGroup {
......@@ -90,13 +94,14 @@ BOOST_AUTO_TEST_CASE(testEverythingTag) {
app.findTag("Everything").connectTo(app.cs);
ctk::TestFacility test;
test.runApplication();
app.cs.dump();
// check if all variables are found on the ControlSystem - read/write dummy values as a consistency check. We have
// different types and input/output mixed, so mixing up variables will be noticed.
test.writeScalar<int>("/first/TestModule/VarGroup/varA", 42);
test.writeScalar<double>("/first/TestModule/VarGroup/varB", 3.14);
test.readScalar<int>("/first/TestModule/VarGroup/varC");
test.writeScalar<double>("/first/TestModule/sisterOfVarGroup", 9.9);
test.writeScalar<double>("/first/TestModule/sisterGroupOfVarGroup/nieceOfVarGroup", 9.9);
test.writeScalar<std::string>("/first/TestModule/varA", "Hallo123");
test.readScalar<float>("/first/TestModule/varX");
for(size_t i = 0; i < 22; ++i) {
......
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