From 4282fda6817744d9c05283043685f4696c0f31c5 Mon Sep 17 00:00:00 2001 From: Miklos Marton Date: Mon, 11 Nov 2024 21:29:02 +0100 Subject: [PATCH] Add displayed_value method to the OutputString Add a helper function to the OutputString which will return the value of the referenced variable (if set) otherwise the value of the OutputString directly. --- .../isobus/isobus_virtual_terminal_objects.hpp | 6 ++++++ isobus/src/isobus_virtual_terminal_objects.cpp | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/isobus/include/isobus/isobus/isobus_virtual_terminal_objects.hpp b/isobus/include/isobus/isobus/isobus_virtual_terminal_objects.hpp index 7171919f..46220a5d 100644 --- a/isobus/include/isobus/isobus/isobus_virtual_terminal_objects.hpp +++ b/isobus/include/isobus/isobus/isobus_virtual_terminal_objects.hpp @@ -19,6 +19,8 @@ namespace isobus { + class VirtualTerminalServerManagedWorkingSet; + /// @brief The types of objects in an object pool by object type byte value enum class VirtualTerminalObjectType : std::uint8_t { @@ -1784,6 +1786,10 @@ namespace isobus /// @returns The value of the string std::string get_value() const; + /// @brief Returns the value of the variable (if referenced) otherwise the set value + /// @returns The displayed value of the string + std::string displayed_value(std::shared_ptr parentWorkingSet) const; + /// @brief Sets the value of the string (only matters if it has no child string variable) /// @param[in] value The new value for the string void set_value(const std::string &value); diff --git a/isobus/src/isobus_virtual_terminal_objects.cpp b/isobus/src/isobus_virtual_terminal_objects.cpp index 4c14296b..752a097b 100644 --- a/isobus/src/isobus_virtual_terminal_objects.cpp +++ b/isobus/src/isobus_virtual_terminal_objects.cpp @@ -7,6 +7,7 @@ /// @copyright 2023 The Open-Agriculture Developers //================================================================================================ #include "isobus/isobus/isobus_virtual_terminal_objects.hpp" +#include "isobus/isobus/isobus_virtual_terminal_server_managed_working_set.hpp" namespace isobus { @@ -3331,6 +3332,20 @@ namespace isobus return stringValue; } + std::string OutputString::displayed_value(std::shared_ptr parentWorkingSet) const + { + if (isobus::NULL_OBJECT_ID != get_variable_reference()) + { + auto child = get_object_by_id(get_variable_reference(), parentWorkingSet->get_object_tree()); + + if ((nullptr != child) && (isobus::VirtualTerminalObjectType::StringVariable == child->get_object_type())) + { + return std::static_pointer_cast(child)->get_value(); + } + } + return get_value(); + } + void OutputString::set_value(const std::string &value) { stringValue = value;