diff --git a/source/RobotAPI/libraries/core/visualization/DebugDrawerTopic.cpp b/source/RobotAPI/libraries/core/visualization/DebugDrawerTopic.cpp index 24db3fe0fabbb12aaa14723a9148e7f423852830..c5e3326f90a61ff197ed88f678f89b6f811b5ea5 100644 --- a/source/RobotAPI/libraries/core/visualization/DebugDrawerTopic.cpp +++ b/source/RobotAPI/libraries/core/visualization/DebugDrawerTopic.cpp @@ -58,6 +58,16 @@ namespace armarx return topic; } + void DebugDrawerTopic::setEnabled(bool enabled) + { + this->_enabled = enabled; + } + + bool DebugDrawerTopic::enabled() const + { + return _enabled && topic; + } + void DebugDrawerTopic::offeringTopic(ManagedIceObject& component, const std::string& topicNameOverride) const { component.offeringTopic(topicNameOverride.empty() ? TOPIC_NAME : topicNameOverride); @@ -841,15 +851,10 @@ namespace armarx } } - bool DebugDrawerTopic::enabled() const - { - return topic; - } - DebugDrawerTopic::operator bool() const { - return topic; + return enabled(); } armarx::DebugDrawerTopic::operator DebugDrawerInterfacePrx& () diff --git a/source/RobotAPI/libraries/core/visualization/DebugDrawerTopic.h b/source/RobotAPI/libraries/core/visualization/DebugDrawerTopic.h index 2dd3b8f3751c47cce2c099753844befb5dd2d9ad..cba61cfe610439abbfec12dbe642bcb1a0d64667 100644 --- a/source/RobotAPI/libraries/core/visualization/DebugDrawerTopic.h +++ b/source/RobotAPI/libraries/core/visualization/DebugDrawerTopic.h @@ -30,16 +30,17 @@ namespace armarx * types, and take care of conversion to Ice variants or data structures. * In addition, this class provides useful overloads for different use cases. * - * All methods check whether the internal topic proxy is set, and do - * nothing if it is not set. To disable visualization by this classs - * completely, just do not set the topic. To check whether visualization - * is enabled (i.e. a topic proxy is set), use `enabled()` or just convert - * `*this` to bool: + * Drawing is enabled if the internal topic proxy is set and an optional + * enabled flag is set (true by default). All methods check whether drawing + * is enabled and do nothing if drawing is disabled. To disable + * visualization by this class completely, use `setEnabled(true/false)` or + * just do not set the topic. To check whether visualization is enabled, + * use `enabled()` or just convert `*this` to bool: * @code * DebugDrawerTopic debugDrawer; - * if (debugDrawer) // equivalent: if (debugDrawer.enabled()) + * if (debugDrawer) // Equivalent: if (debugDrawer.enabled()) * { - * // do stuff if visualization is enabled + * // Do stuff if visualization is enabled. * } * @endcode * @@ -230,6 +231,14 @@ namespace armarx /// Get the topic. DebugDrawerInterfacePrx getTopic() const; + /** + * @brief Set whether drawing is enabled. + * Visualization is only truly enabled if the topic is set. + */ + void setEnabled(bool enabled); + /// Indicate whether visualization is enabled, i.e. a topic is set and enabled flag is set. + bool enabled() const; + /** * @brief Call offeringTopic([topicName]) on the given component. * @param component The component (`*this` when called from a component). @@ -644,16 +653,12 @@ namespace armarx bool ignoreLengthScale = false); - // STATUS + // OPERATORS - /// Indicate whether a topic is set, i.e. visualization is enabled. - bool enabled() const; - /// Indicate whether a topic is set, i.e. visualization is enabled. + /// Indicate whether visualization is enabled. + /// @see `enabled()` operator bool() const; - - // OPERATORS - /// Conversion operator to DebugDrawerInterfacePrx. operator DebugDrawerInterfacePrx& (); operator const DebugDrawerInterfacePrx& () const; @@ -741,6 +746,9 @@ namespace armarx /// The debug drawer topic. DebugDrawerInterfacePrx topic = nullptr; + /// Whether drawing is enabled. (In comination with `topic`. + bool _enabled = true; + /// The default layer (used if none is passed to the method). std::string _layer = DEFAULT_LAYER;