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

improved generation of dot graph

parent b2766ecd
No related branches found
No related tags found
No related merge requests found
...@@ -139,6 +139,8 @@ namespace ChimeraTK { ...@@ -139,6 +139,8 @@ namespace ChimeraTK {
Profiler::registerThread(name); Profiler::registerThread(name);
} }
ModuleType getModuleType() const override { return ModuleType::ModuleGroup; }
protected: protected:
friend class Module; friend class Module;
......
...@@ -63,7 +63,9 @@ namespace ChimeraTK { ...@@ -63,7 +63,9 @@ namespace ChimeraTK {
moduleList = std::move(rhs.moduleList); moduleList = std::move(rhs.moduleList);
return *this; return *this;
} }
ModuleType getModuleType() const override { return ModuleType::ApplicationModule; }
protected: protected:
/** Wrapper around mainLoop(), to execute additional tasks in the thread before entering the main loop */ /** Wrapper around mainLoop(), to execute additional tasks in the thread before entering the main loop */
......
...@@ -35,6 +35,8 @@ namespace ChimeraTK { ...@@ -35,6 +35,8 @@ namespace ChimeraTK {
Module& operator[](const std::string& moduleName) const override; Module& operator[](const std::string& moduleName) const override;
ModuleType getModuleType() const override { return ModuleType::ControlSystem; }
protected: protected:
mtca4u::RegisterPath variableNamePrefix; mtca4u::RegisterPath variableNamePrefix;
......
...@@ -42,6 +42,8 @@ namespace ChimeraTK { ...@@ -42,6 +42,8 @@ namespace ChimeraTK {
Module& operator[](const std::string& moduleName) const override; Module& operator[](const std::string& moduleName) const override;
ModuleType getModuleType() const override { return ModuleType::Device; }
protected: protected:
std::string deviceAliasOrURI; std::string deviceAliasOrURI;
......
...@@ -113,10 +113,21 @@ namespace ChimeraTK { ...@@ -113,10 +113,21 @@ namespace ChimeraTK {
/** Create Graphviz dot graph write to file */ /** Create Graphviz dot graph write to file */
void dumpGraph(const std::string &fileName="graph.dot") const; void dumpGraph(const std::string &fileName="graph.dot") const;
/** Create Graphviz dot graph write to stream, excluding the surrounding digraph command */ enum class ModuleType {
void dumpGraphInternal(std::ostream &stream) const; ApplicationModule, ModuleGroup, VariableGroup, ControlSystem, Device
};
/** Return the module type of this module, or in case of a VirtualModule the module type this VirtualModule was
* derived from. */
virtual ModuleType getModuleType() const = 0;
protected: protected:
/** Create Graphviz dot graph write to stream, excluding the surrounding digraph command */
void dumpGraphInternal(std::ostream &stream) const;
/** Clean a fully qualified entity name so it can be used as a dot node name (i.e. strip slashes etc.) */
std::string cleanDotNode(std::string fullName) const;
/** The name of this instance */ /** The name of this instance */
std::string _name; std::string _name;
......
...@@ -40,17 +40,35 @@ namespace ChimeraTK { ...@@ -40,17 +40,35 @@ namespace ChimeraTK {
/** Destructor */ /** Destructor */
virtual ~ModuleGroup() {}; virtual ~ModuleGroup() {};
/** Move operation with the move constructor
@todo should be in the base class!? */
ModuleGroup(ModuleGroup &&rhs) {
_name = std::move(rhs._name);
_owner = std::move(rhs._owner);
_description = std::move(rhs._description);
accessorList = std::move(rhs.accessorList);
moduleList = std::move(rhs.moduleList);
_eliminateHierarchy = rhs._eliminateHierarchy;
_tags = std::move(rhs._tags);
}
/** Move operation with the assignment operator /** Move operation with the assignment operator
@todo should be in the base class!? */ @todo should be in the base class!? */
ModuleGroup& operator=(ModuleGroup &&rhs) { ModuleGroup& operator=(ModuleGroup &&rhs) {
_name = std::move(rhs._name); _name = std::move(rhs._name);
_owner = std::move(rhs._owner); _owner = std::move(rhs._owner);
_description = std::move(rhs._description);
accessorList = std::move(rhs.accessorList); accessorList = std::move(rhs.accessorList);
moduleList = std::move(rhs.moduleList); moduleList = std::move(rhs.moduleList);
_eliminateHierarchy = rhs._eliminateHierarchy;
_tags = std::move(rhs._tags);
return *this; return *this;
} }
ModuleGroup& operator=(ModuleGroup &rhs) = delete; ModuleGroup& operator=(ModuleGroup &rhs) = delete;
ModuleGroup& operator=(const ModuleGroup &rhs) = delete;
ModuleType getModuleType() const override { return ModuleType::ModuleGroup; }
}; };
......
...@@ -54,6 +54,8 @@ namespace ChimeraTK { ...@@ -54,6 +54,8 @@ namespace ChimeraTK {
VariableGroup& operator=(VariableGroup &rhs) = delete; VariableGroup& operator=(VariableGroup &rhs) = delete;
ModuleType getModuleType() const override { return ModuleType::VariableGroup; }
}; };
} /* namespace ChimeraTK */ } /* namespace ChimeraTK */
......
...@@ -22,7 +22,9 @@ namespace ChimeraTK { ...@@ -22,7 +22,9 @@ namespace ChimeraTK {
public: public:
/** Constructor */ /** Constructor */
VirtualModule(const std::string &name, const std::string &description) : Module(nullptr, name, description) {} VirtualModule(const std::string &name, const std::string &description, ModuleType moduleType)
: Module(nullptr, name, description), _moduleType(moduleType)
{}
/** Copy constructor */ /** Copy constructor */
VirtualModule(const VirtualModule &other); VirtualModule(const VirtualModule &other);
...@@ -36,10 +38,13 @@ namespace ChimeraTK { ...@@ -36,10 +38,13 @@ namespace ChimeraTK {
/** Add a virtual sub-module. The module instance will be added to an internal list. */ /** Add a virtual sub-module. The module instance will be added to an internal list. */
void addSubModule(VirtualModule module); void addSubModule(VirtualModule module);
ModuleType getModuleType() const override { return _moduleType; }
protected: protected:
std::list<VirtualModule> submodules; std::list<VirtualModule> submodules;
ModuleType _moduleType;
}; };
......
...@@ -80,7 +80,7 @@ namespace ChimeraTK { ...@@ -80,7 +80,7 @@ namespace ChimeraTK {
VirtualModule EntityOwner::findTag(const std::string &tag, bool eliminateAllHierarchies) const { VirtualModule EntityOwner::findTag(const std::string &tag, bool eliminateAllHierarchies) const {
// create new module to return // create new module to return
VirtualModule module{_name, _description}; VirtualModule module{_name, _description, getModuleType()};
// add everything matching the tag to the virtual module and return it // add everything matching the tag to the virtual module and return it
findTagAndAppendToModule(module, tag, eliminateAllHierarchies, true); findTagAndAppendToModule(module, tag, eliminateAllHierarchies, true);
...@@ -92,7 +92,7 @@ namespace ChimeraTK { ...@@ -92,7 +92,7 @@ namespace ChimeraTK {
void EntityOwner::findTagAndAppendToModule(VirtualModule &module, const std::string &tag, bool eliminateAllHierarchies, void EntityOwner::findTagAndAppendToModule(VirtualModule &module, const std::string &tag, bool eliminateAllHierarchies,
bool eliminateFirstHierarchy) const { bool eliminateFirstHierarchy) const {
VirtualModule nextmodule{_name, _description}; VirtualModule nextmodule{_name, _description, getModuleType()};
VirtualModule *moduleToAddTo; VirtualModule *moduleToAddTo;
bool needToAddSubModule = false; bool needToAddSubModule = false;
...@@ -152,20 +152,36 @@ namespace ChimeraTK { ...@@ -152,20 +152,36 @@ namespace ChimeraTK {
dumpGraphInternal(file); dumpGraphInternal(file);
file << "}" << std::endl; file << "}" << std::endl;
file.close(); file.close();
std::cout << "HIER " << fileName << std::endl; }
/*********************************************************************************************************************/
std::string EntityOwner::cleanDotNode(std::string fullName) const {
std::replace(fullName.begin(), fullName.end(), '/', '_');
std::replace(fullName.begin(), fullName.end(), ':', '_');
return fullName;
} }
/*********************************************************************************************************************/ /*********************************************************************************************************************/
void EntityOwner::dumpGraphInternal(std::ostream &stream) const { void EntityOwner::dumpGraphInternal(std::ostream &stream) const {
std::string myDotNode = getQualifiedName(); std::string myDotNode = cleanDotNode(getQualifiedName());
std::replace(myDotNode.begin(), myDotNode.end(), '/', '_');
stream << myDotNode << "[label=\"" << getName() << "\"]" << std::endl; stream << myDotNode << "[label=\"" << getName() << "\"";
if(_eliminateHierarchy) {
stream << ",style=dotted";
}
if(getModuleType() == ModuleType::ModuleGroup) {
stream << ",peripheries=2";
}
if(getModuleType() == ModuleType::ApplicationModule) {
stream << ",style=bold";
}
stream << "]" << std::endl;
for(auto &node : getAccessorList()) { for(auto &node : getAccessorList()) {
std::string dotNode = node.getQualifiedName(); std::string dotNode = cleanDotNode(node.getQualifiedName());
std::replace(dotNode.begin(), dotNode.end(), '/', '_');
stream << dotNode << "[label=\"{" << node.getName() << "| {"; stream << dotNode << "[label=\"{" << node.getName() << "| {";
bool first = true; bool first = true;
for(auto tag : node.getTags()) { for(auto tag : node.getTags()) {
...@@ -182,8 +198,7 @@ namespace ChimeraTK { ...@@ -182,8 +198,7 @@ namespace ChimeraTK {
} }
for(auto &submodule : getSubmoduleList()) { for(auto &submodule : getSubmoduleList()) {
std::string dotNode = submodule->getQualifiedName(); std::string dotNode = cleanDotNode(submodule->getQualifiedName());
std::replace(dotNode.begin(), dotNode.end(), '/', '_');
stream << " " << myDotNode << " -> " << dotNode << std::endl; stream << " " << myDotNode << " -> " << dotNode << std::endl;
submodule->dumpGraphInternal(stream); submodule->dumpGraphInternal(stream);
} }
...@@ -201,7 +216,7 @@ namespace ChimeraTK { ...@@ -201,7 +216,7 @@ namespace ChimeraTK {
/*********************************************************************************************************************/ /*********************************************************************************************************************/
VirtualModule EntityOwner::flatten() { VirtualModule EntityOwner::flatten() {
VirtualModule nextmodule{_name, _description}; VirtualModule nextmodule{_name, _description, getModuleType()};
for(auto &node : getAccessorListRecursive()) { for(auto &node : getAccessorListRecursive()) {
nextmodule.registerAccessor(node); nextmodule.registerAccessor(node);
} }
......
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