From 9f099616d3496f55cb69eb89bac240a5a8566c72 Mon Sep 17 00:00:00 2001 From: Adrian Del Grosso <10929341+ad3154@users.noreply.github.com> Date: Sat, 9 Dec 2023 17:32:59 -0700 Subject: [PATCH] Macro execution, logging options, bugfixes Fixed a bug where an input boolean's background may not be filled properly. Added a way to change and save the logging level in the UI. Fixed bugs with dynamic sizing related to softkey mask size. Added support for executing numerous macros. --- include/ServerMainComponent.hpp | 3 +- include/SoftKeyMaskComponent.hpp | 4 +- src/DataMaskRenderAreaComponent.cpp | 60 ++++++++- src/InputBooleanComponent.cpp | 2 +- src/JuceManagedWorkingSetCache.cpp | 2 +- src/ServerMainComponent.cpp | 182 ++++++++++++++++++++++++---- src/SoftKeyMaskComponent.cpp | 10 +- src/SoftkeyMaskRenderArea.cpp | 4 + src/WorkingSetSelectorComponent.cpp | 5 +- 9 files changed, 234 insertions(+), 38 deletions(-) diff --git a/include/ServerMainComponent.hpp b/include/ServerMainComponent.hpp index e1cf907..e0405af 100644 --- a/include/ServerMainComponent.hpp +++ b/include/ServerMainComponent.hpp @@ -97,7 +97,8 @@ class ServerMainComponent : public juce::Component About, ConfigureLanguageCommand, ConfigureReportedVersion, - ConfigureReportedHardware + ConfigureReportedHardware, + ConfigureLogging }; class LanguageCommandConfigClosed diff --git a/include/SoftKeyMaskComponent.hpp b/include/SoftKeyMaskComponent.hpp index a44191a..27ea7c5 100644 --- a/include/SoftKeyMaskComponent.hpp +++ b/include/SoftKeyMaskComponent.hpp @@ -18,7 +18,7 @@ class SoftKeyMaskComponent : public isobus::SoftKeyMask , public Component { public: - SoftKeyMaskComponent(std::shared_ptr workingSet, isobus::SoftKeyMask sourceObject); + SoftKeyMaskComponent(std::shared_ptr workingSet, isobus::SoftKeyMask sourceObject, int dataAndAlarmMaskSize, int keyHeight, int keyWidth); void on_content_changed(bool initial = false); @@ -27,6 +27,8 @@ class SoftKeyMaskComponent : public isobus::SoftKeyMask private: std::shared_ptr parentWorkingSet; std::vector> childComponents; + int softKeyHeight = 60; + int softKeyWidth = 60; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SoftKeyMaskComponent) }; diff --git a/src/DataMaskRenderAreaComponent.cpp b/src/DataMaskRenderAreaComponent.cpp index 24c4133..0668d65 100644 --- a/src/DataMaskRenderAreaComponent.cpp +++ b/src/DataMaskRenderAreaComponent.cpp @@ -78,10 +78,12 @@ void DataMaskRenderAreaComponent::mouseDown(const MouseEvent &event) if (isobus::VirtualTerminalObjectType::Button == clickedObject->get_object_type()) { keyCode = std::static_pointer_cast(clickedObject)->get_key_code(); + ownerServer.processMacro(clickedObject, isobus::EventID::OnKeyPress, isobus::VirtualTerminalObjectType::Button, parentWorkingSet); } else if (isobus::VirtualTerminalObjectType::Key == clickedObject->get_object_type()) { keyCode = std::static_pointer_cast(clickedObject)->get_key_code(); + ownerServer.processMacro(clickedObject, isobus::EventID::OnKeyPress, isobus::VirtualTerminalObjectType::Key, parentWorkingSet); } ownerServer.send_button_activation_message(isobus::VirtualTerminalBase::KeyActivationCode::ButtonPressedOrLatched, @@ -125,6 +127,7 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event) activeMask->get_id(), keyCode, ownerServer.get_active_working_set()->get_control_function()); + ownerServer.processMacro(clickedObject, isobus::EventID::OnKeyRelease, isobus::VirtualTerminalObjectType::Button, parentWorkingSet); } } break; @@ -137,6 +140,7 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event) activeMask->get_id(), keyCode, ownerServer.get_active_working_set()->get_control_function()); + ownerServer.processMacro(clickedObject, isobus::EventID::OnKeyRelease, isobus::VirtualTerminalObjectType::Key, parentWorkingSet); } break; @@ -199,25 +203,33 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event) { if (std::static_pointer_cast(child)->get_value() != static_cast(result)) { + std::static_pointer_cast(child)->set_value(result); ownerServer.send_change_numeric_value_message(child->get_id(), result, ownerServer.get_client_control_function_for_working_set(parentWorkingSet)); + ownerServer.processMacro(child, isobus::EventID::OnChangeValue, isobus::VirtualTerminalObjectType::NumberVariable, parentWorkingSet); } - std::static_pointer_cast(child)->set_value(result); } } } else { + ownerServer.processMacro(clickedList, isobus::EventID::OnEntryOfAValue, isobus::VirtualTerminalObjectType::InputList, parentWorkingSet); if (clickedList->get_value() != result) { + ownerServer.processMacro(clickedList, isobus::EventID::OnEntryOfANewValue, isobus::VirtualTerminalObjectType::InputList, parentWorkingSet); + clickedList->set_value(static_cast(result)); ownerServer.send_change_numeric_value_message(clickedList->get_id(), result, ownerServer.get_client_control_function_for_working_set(parentWorkingSet)); + ownerServer.processMacro(clickedList, isobus::EventID::OnChangeValue, isobus::VirtualTerminalObjectType::InputList, parentWorkingSet); } - clickedList->set_value(static_cast(result)); } this->inputListModal->exitModalState(); + parentWorkingSet->set_object_focus(isobus::NULL_OBJECT_ID); + ownerServer.processMacro(clickedList, isobus::EventID::OnInputFieldDeselection, isobus::VirtualTerminalObjectType::InputList, parentWorkingSet); inputListModal.reset(); repaint(); }; inputListModal->enterModalState(true, ModalCallbackFunction::create(std::move(resultCallback)), false); + parentWorkingSet->set_object_focus(clickedObject->get_id()); + ownerServer.processMacro(clickedObject, isobus::EventID::OnInputFieldSelection, isobus::VirtualTerminalObjectType::InputList, parentWorkingSet); } } break; @@ -264,7 +276,7 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event) std::uint16_t varNumID = 0xFFFF; if (0 == result) { - clickedNumber->set_value(inputNumberListener.get_last_value()); + ownerServer.processMacro(clickedNumber, isobus::EventID::OnEntryOfAValue, isobus::VirtualTerminalObjectType::InputNumber, parentWorkingSet); if (isobus::NULL_OBJECT_ID != clickedNumber->get_variable_reference()) { @@ -272,10 +284,28 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event) if ((nullptr != child) && (isobus::VirtualTerminalObjectType::NumberVariable == child->get_object_type())) { - std::static_pointer_cast(child)->set_value(inputNumberListener.get_last_value()); varNumID = child->get_id(); } } + + if (isobus::NULL_OBJECT_ID != varNumID) + { + if (std::static_pointer_cast(clickedNumber->get_object_by_id(clickedNumber->get_variable_reference(), parentWorkingSet->get_object_tree()))->get_value() != inputNumberListener.get_last_value()) + { + ownerServer.processMacro(clickedNumber, isobus::EventID::OnEntryOfANewValue, isobus::VirtualTerminalObjectType::InputNumber, parentWorkingSet); + } + std::static_pointer_cast(clickedNumber->get_object_by_id(clickedNumber->get_variable_reference(), parentWorkingSet->get_object_tree()))->set_value(inputNumberListener.get_last_value()); + } + else + { + if (clickedNumber->get_value() != inputNumberListener.get_last_value()) + { + ownerServer.processMacro(clickedNumber, isobus::EventID::OnEntryOfANewValue, isobus::VirtualTerminalObjectType::InputNumber, parentWorkingSet); + clickedNumber->set_value(inputNumberListener.get_last_value()); + ownerServer.processMacro(clickedNumber, isobus::EventID::OnChangeValue, isobus::VirtualTerminalObjectType::InputNumber, parentWorkingSet); + } + } + this->needToRepaintActiveArea = true; } inputNumberListener.set_target(nullptr); @@ -288,19 +318,26 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event) if (0xFFFF != varNumID) { ownerServer.send_change_numeric_value_message(varNumID, clickedNumber->get_value(), ownerServer.get_client_control_function_for_working_set(parentWorkingSet)); + ownerServer.processMacro(clickedNumber->get_object_by_id(clickedNumber->get_variable_reference(), parentWorkingSet->get_object_tree()), isobus::EventID::OnChangeValue, isobus::VirtualTerminalObjectType::NumberVariable, parentWorkingSet); } else { ownerServer.send_change_numeric_value_message(clickedNumber->get_id(), clickedNumber->get_value(), ownerServer.get_client_control_function_for_working_set(parentWorkingSet)); + ownerServer.processMacro(clickedNumber, isobus::EventID::OnChangeValue, isobus::VirtualTerminalObjectType::InputNumber, parentWorkingSet); } } else { // TODO ESC } + + parentWorkingSet->set_object_focus(isobus::NULL_OBJECT_ID); + ownerServer.processMacro(clickedNumber, isobus::EventID::OnInputFieldDeselection, isobus::VirtualTerminalObjectType::InputNumber, parentWorkingSet); }; inputNumberModal->enterModalState(true, ModalCallbackFunction::create(std::move(resultCallback)), false); ownerServer.send_select_input_object_message(clickedNumber->get_id(), true, true, ownerServer.get_client_control_function_for_working_set(parentWorkingSet)); + parentWorkingSet->set_object_focus(clickedObject->get_id()); + ownerServer.processMacro(clickedObject, isobus::EventID::OnInputFieldSelection, isobus::VirtualTerminalObjectType::InputNumber, parentWorkingSet); } } break; @@ -312,6 +349,8 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event) if (clickedBool->get_enabled()) { bool hasNumberVariable = false; + ownerServer.processMacro(clickedBool, isobus::EventID::OnEntryOfAValue, isobus::VirtualTerminalObjectType::InputBoolean, parentWorkingSet); + ownerServer.processMacro(clickedBool, isobus::EventID::OnEntryOfANewValue, isobus::VirtualTerminalObjectType::InputBoolean, parentWorkingSet); if (isobus::NULL_OBJECT_ID != clickedBool->get_variable_reference()) { @@ -324,6 +363,7 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event) hasNumberVariable = true; std::static_pointer_cast(child)->set_value(!(0 != std::static_pointer_cast(child)->get_value())); ownerServer.send_change_numeric_value_message(child->get_id(), std::static_pointer_cast(child)->get_value(), ownerServer.get_client_control_function_for_working_set(parentWorkingSet)); + ownerServer.processMacro(child, isobus::EventID::OnChangeValue, isobus::VirtualTerminalObjectType::NumberVariable, parentWorkingSet); } } } @@ -332,6 +372,7 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event) { clickedBool->set_value(~clickedBool->get_value()); ownerServer.send_change_numeric_value_message(clickedBool->get_id(), clickedBool->get_value(), ownerServer.get_client_control_function_for_working_set(parentWorkingSet)); + ownerServer.processMacro(clickedBool, isobus::EventID::OnChangeValue, isobus::VirtualTerminalObjectType::InputBoolean, parentWorkingSet); } repaint(); } @@ -372,6 +413,7 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event) if (0 == result) //OK { String newContent = this->inputStringModal->getTextEditor("Input String")->getText(); + ownerServer.processMacro(clickedString, isobus::EventID::OnEntryOfAValue, isobus::VirtualTerminalObjectType::InputString, parentWorkingSet); if (nullptr != stringVariable) { @@ -382,6 +424,7 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event) } stringVariable->set_value(newContent.toStdString()); ownerServer.send_change_string_value_message(stringVariable->get_id(), newContent.toStdString(), ownerServer.get_client_control_function_for_working_set(parentWorkingSet)); + ownerServer.processMacro(stringVariable, isobus::EventID::OnChangeValue, isobus::VirtualTerminalObjectType::StringVariable, parentWorkingSet); } else { @@ -390,16 +433,25 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event) { newContent.append(" ", 1); } + if (clickedString->get_value() != newContent) + { + ownerServer.processMacro(clickedString, isobus::EventID::OnEntryOfANewValue, isobus::VirtualTerminalObjectType::InputString, parentWorkingSet); + } clickedString->set_value(newContent.toStdString()); ownerServer.send_change_string_value_message(clickedString->get_id(), newContent.toStdString(), ownerServer.get_client_control_function_for_working_set(parentWorkingSet)); + ownerServer.processMacro(clickedString, isobus::EventID::OnChangeValue, isobus::VirtualTerminalObjectType::InputString, parentWorkingSet); } needToRepaintActiveArea = true; } inputStringModal->exitModalState(); inputStringModal.reset(); + parentWorkingSet->set_object_focus(isobus::NULL_OBJECT_ID); + ownerServer.processMacro(clickedString, isobus::EventID::OnInputFieldDeselection, isobus::VirtualTerminalObjectType::InputString, parentWorkingSet); }; inputStringModal->enterModalState(true, ModalCallbackFunction::create(std::move(resultCallback)), false); ownerServer.send_select_input_object_message(clickedString->get_id(), true, true, ownerServer.get_client_control_function_for_working_set(parentWorkingSet)); + parentWorkingSet->set_object_focus(clickedObject->get_id()); + ownerServer.processMacro(clickedObject, isobus::EventID::OnInputFieldSelection, isobus::VirtualTerminalObjectType::InputString, parentWorkingSet); } } break; diff --git a/src/InputBooleanComponent.cpp b/src/InputBooleanComponent.cpp index 4270c40..789ebd0 100644 --- a/src/InputBooleanComponent.cpp +++ b/src/InputBooleanComponent.cpp @@ -20,7 +20,7 @@ void InputBooleanComponent::paint(Graphics &g) // Draw background auto vtColour = parentWorkingSet->get_colour(get_background_color()); g.setColour(Colour::fromFloatRGBA(vtColour.r, vtColour.g, vtColour.b, 1.0f)); - g.drawRect(0, 0, static_cast(get_width()), static_cast(get_height()), 0); + g.fillRect(0, 0, static_cast(get_width()), static_cast(get_height())); g.setColour(Colour::fromFloatRGBA(0.0f, 0.0f, 0.0f, 1.0f)); // Change colour to foreground colour if present diff --git a/src/JuceManagedWorkingSetCache.cpp b/src/JuceManagedWorkingSetCache.cpp index e5eb5d1..13bd22e 100644 --- a/src/JuceManagedWorkingSetCache.cpp +++ b/src/JuceManagedWorkingSetCache.cpp @@ -90,7 +90,7 @@ std::shared_ptr JuceManagedWorkingSetCache::create_component(std::sha case isobus::VirtualTerminalObjectType::SoftKeyMask: { - retVal = std::make_shared(workingSet, *std::static_pointer_cast(sourceObject)); + retVal = std::make_shared(workingSet, *std::static_pointer_cast(sourceObject), dataAndAlarmMaskSize, keyHeight, keyWidth); } break; diff --git a/src/ServerMainComponent.cpp b/src/ServerMainComponent.cpp index 531201d..42d8001 100644 --- a/src/ServerMainComponent.cpp +++ b/src/ServerMainComponent.cpp @@ -20,6 +20,9 @@ ServerMainComponent::ServerMainComponent(std::shared_ptr &allComman allCommands.add(static_cast(CommandIDs::ConfigureLanguageCommand)); allCommands.add(static_cast(CommandIDs::ConfigureReportedVersion)); allCommands.add(static_cast(CommandIDs::ConfigureReportedHardware)); + allCommands.add(static_cast(CommandIDs::ConfigureLogging)); } void ServerMainComponent::getCommandInfo(juce::CommandID commandID, ApplicationCommandInfo &result) @@ -551,6 +553,12 @@ void ServerMainComponent::getCommandInfo(juce::CommandID commandID, ApplicationC } break; + case CommandIDs::ConfigureLogging: + { + result.setInfo("Logging", "Change the logging level", "Configure", 0); + } + break; + case CommandIDs::NoCommand: default: break; @@ -642,6 +650,18 @@ bool ServerMainComponent::perform(const InvocationInfo &info) } break; + case static_cast(CommandIDs::ConfigureLogging): + { + popupMenu = std::make_unique("Configure Logging", "You can use this to change the logging level, which affects what's shown in the logging area. Setting logging to \"debug\" may impact performance, but will provide very verbose output.", MessageBoxIconType::NoIcon); + popupMenu->addComboBox("Logging Level", { "Debug", "Info", "Warning", "Error", "Critical" }); + popupMenu->getComboBoxComponent("Logging Level")->setSelectedItemIndex(static_cast(isobus::CANStackLogger::get_log_level())); + popupMenu->addButton("OK", 4, KeyPress(KeyPress::returnKey, 0, 0)); + popupMenu->addButton("Cancel", 0, KeyPress(KeyPress::escapeKey, 0, 0)); + popupMenu->enterModalState(true, ModalCallbackFunction::create(LanguageCommandConfigClosed{ *this })); + retVal = true; + } + break; + default: break; } @@ -664,6 +684,7 @@ PopupMenu ServerMainComponent::getMenuForIndex(int index, const juce::String &) retVal.addCommandItem(&mCommandManager, static_cast(CommandIDs::ConfigureLanguageCommand)); retVal.addCommandItem(&mCommandManager, static_cast(CommandIDs::ConfigureReportedVersion)); retVal.addCommandItem(&mCommandManager, static_cast(CommandIDs::ConfigureReportedHardware)); + retVal.addCommandItem(&mCommandManager, static_cast(CommandIDs::ConfigureLogging)); } break; @@ -703,19 +724,35 @@ void ServerMainComponent::change_selected_working_set(std::uint8_t index) { if (index < managedWorkingSetList.size()) { + bool lProcessActivateDeactivateMacros = false; + for (auto &ws : managedWorkingSetList) { ws->clear_callback_handles(); } auto &ws = managedWorkingSetList.at(index); + + if (activeWorkingSetMasterAddress != ws->get_control_function()->get_address()) + { + lProcessActivateDeactivateMacros = true; + + if (nullptr != activeWorkingSet) + { + processMacro(activeWorkingSet->get_working_set_object(), isobus::EventID::OnDeactivate, isobus::VirtualTerminalObjectType::WorkingSet, activeWorkingSet); + processMacro(ws->get_object_by_id(std::static_pointer_cast(ws->get_working_set_object())->get_active_mask()), isobus::EventID::OnHide, isobus::VirtualTerminalObjectType::DataMask, activeWorkingSet); + } + } + activeWorkingSetMasterAddress = ws->get_control_function()->get_address(); auto workingSetObject = std::static_pointer_cast(ws->get_working_set_object()); + std::uint16_t previousActiveMask = activeWorkingSetDataMaskObjectID; activeWorkingSetDataMaskObjectID = std::static_pointer_cast(ws->get_working_set_object())->get_active_mask(); dataMaskRenderer.on_change_active_mask(ws); softKeyMaskRenderer.on_change_active_mask(ws); activeWorkingSet = ws; + processMacro(activeWorkingSet->get_working_set_object(), isobus::EventID::OnActivate, isobus::VirtualTerminalObjectType::WorkingSet, activeWorkingSet); ws->save_callback_handle(get_on_repaint_event_dispatcher().add_listener([this](std::shared_ptr) { this->repaint_on_next_update(); })); ws->save_callback_handle(get_on_change_active_mask_event_dispatcher().add_listener([this](std::shared_ptr affectedWorkingSet, std::uint16_t workingSet, std::uint16_t newMask) { this->on_change_active_mask_callback(affectedWorkingSet, workingSet, newMask); })); @@ -727,6 +764,14 @@ void ServerMainComponent::change_selected_working_set(std::uint8_t index) { statusMessageTimestamp_ms = 0; } + + if (previousActiveMask != activeWorkingSetDataMaskObjectID) + { + processMacro(ws->get_object_by_id(previousActiveMask), isobus::EventID::OnHide, isobus::VirtualTerminalObjectType::DataMask, activeWorkingSet); + processMacro(ws->get_object_by_id(previousActiveMask), isobus::EventID::OnHide, isobus::VirtualTerminalObjectType::AlarmMask, activeWorkingSet); + processMacro(ws->get_object_by_id(activeWorkingSetDataMaskObjectID), isobus::EventID::OnShow, isobus::VirtualTerminalObjectType::DataMask, activeWorkingSet); + processMacro(ws->get_object_by_id(activeWorkingSetDataMaskObjectID), isobus::EventID::OnShow, isobus::VirtualTerminalObjectType::AlarmMask, activeWorkingSet); + } } } @@ -776,8 +821,8 @@ void ServerMainComponent::LanguageCommandConfigClosed::operator()(int result) co case 2: // Save Version { - auto version = static_cast(mParent.popupMenu->getComboBoxComponent("Version")->getSelectedItemIndex() + 2); - mParent.versionToReport = version; + auto version = mParent.popupMenu->getComboBoxComponent("Version")->getSelectedItemIndex() + 2; + mParent.versionToReport = get_version_from_setting(version); mParent.save_settings(); } @@ -805,6 +850,13 @@ void ServerMainComponent::LanguageCommandConfigClosed::operator()(int result) co } break; + case 4: // Log level + { + isobus::CANStackLogger::set_log_level(static_cast(mParent.popupMenu->getComboBoxComponent("Logging Level")->getSelectedItemIndex())); + mParent.save_settings(); + } + break; + default: { // Cancel. Do nothing @@ -973,27 +1025,106 @@ void ServerMainComponent::check_load_settings() { settings.copyPropertiesAndChildrenFrom(ValueTree::fromXml(*xml), nullptr); - auto firstChild = settings.getChild(0); - auto secondChild = settings.getChild(1); - auto thirdChild = settings.getChild(2); - languageCommandInterface.set_commanded_area_units(static_cast(int(firstChild.getProperty("AreaUnits")))); - languageCommandInterface.set_commanded_date_format(static_cast(int(firstChild.getProperty("DateFormat")))); - languageCommandInterface.set_commanded_decimal_symbol(static_cast(int(firstChild.getProperty("DecimalSymbol")))); - languageCommandInterface.set_commanded_distance_units(static_cast(int(firstChild.getProperty("DistanceUnits")))); - languageCommandInterface.set_commanded_force_units(static_cast(int(firstChild.getProperty("ForceUnits")))); - languageCommandInterface.set_commanded_generic_units(static_cast(int(firstChild.getProperty("UnitSystem")))); - languageCommandInterface.set_commanded_mass_units(static_cast(int(firstChild.getProperty("MassUnits")))); - languageCommandInterface.set_commanded_pressure_units(static_cast(int(firstChild.getProperty("PressureUnits")))); - languageCommandInterface.set_commanded_temperature_units(static_cast(int(firstChild.getProperty("TemperatureUnits")))); - languageCommandInterface.set_commanded_time_format(static_cast(int(firstChild.getProperty("TimeFormat")))); - languageCommandInterface.set_commanded_volume_units(static_cast(int(firstChild.getProperty("VolumeUnits")))); - languageCommandInterface.set_country_code(String(firstChild.getProperty("CountryCode").toString()).toStdString()); - languageCommandInterface.set_language_code(String(firstChild.getProperty("LanguageCode").toString()).toStdString()); - versionToReport = get_version_from_setting(static_cast(static_cast(secondChild.getProperty("Version")))); - - if (thirdChild.isValid()) - { + int index = 0; + auto child = settings.getChild(index); + while (child.isValid()) + { + if (Identifier("LanguageCommand") == child.getType()) + { + if (!child.getProperty("AreaUnits").isVoid()) + { + languageCommandInterface.set_commanded_area_units(static_cast(int(child.getProperty("AreaUnits")))); + } + if (!child.getProperty("DateFormat").isVoid()) + { + languageCommandInterface.set_commanded_date_format(static_cast(int(child.getProperty("DateFormat")))); + } + if (!child.getProperty("DecimalSymbol").isVoid()) + { + languageCommandInterface.set_commanded_decimal_symbol(static_cast(int(child.getProperty("DecimalSymbol")))); + } + if (!child.getProperty("DistanceUnits").isVoid()) + { + languageCommandInterface.set_commanded_distance_units(static_cast(int(child.getProperty("DistanceUnits")))); + } + if (!child.getProperty("ForceUnits").isVoid()) + { + languageCommandInterface.set_commanded_force_units(static_cast(int(child.getProperty("ForceUnits")))); + } + if (!child.getProperty("UnitSystem").isVoid()) + { + languageCommandInterface.set_commanded_generic_units(static_cast(int(child.getProperty("UnitSystem")))); + } + if (!child.getProperty("MassUnits").isVoid()) + { + languageCommandInterface.set_commanded_mass_units(static_cast(int(child.getProperty("MassUnits")))); + } + if (!child.getProperty("PressureUnits").isVoid()) + { + languageCommandInterface.set_commanded_pressure_units(static_cast(int(child.getProperty("PressureUnits")))); + } + if (!child.getProperty("TemperatureUnits").isVoid()) + { + languageCommandInterface.set_commanded_temperature_units(static_cast(int(child.getProperty("TemperatureUnits")))); + } + if (!child.getProperty("TimeFormat").isVoid()) + { + languageCommandInterface.set_commanded_time_format(static_cast(int(child.getProperty("TimeFormat")))); + } + if (!child.getProperty("VolumeUnits").isVoid()) + { + languageCommandInterface.set_commanded_volume_units(static_cast(int(child.getProperty("VolumeUnits")))); + } + if (!child.getProperty("CountryCode").isVoid()) + { + languageCommandInterface.set_country_code(String(child.getProperty("CountryCode").toString()).toStdString()); + } + if (!child.getProperty("LanguageCode").isVoid()) + { + languageCommandInterface.set_language_code(String(child.getProperty("LanguageCode").toString()).toStdString()); + } + } + else if (Identifier("Compatibility") == child.getType()) + { + if (!child.getProperty("Version").isVoid()) + { + versionToReport = get_version_from_setting(static_cast(static_cast(child.getProperty("Version")))); + } + } + else if (Identifier("Hardware") == child.getType()) + { + if (!child.getProperty("SoftKeyDesignatorWidth").isVoid()) + { + softKeyDesignatorWidth = static_cast(static_cast(child.getProperty("SoftKeyDesignatorWidth"))); + } + if (!child.getProperty("SoftKeyDesignatorHeight").isVoid()) + { + softKeyDesignatorHeight = static_cast(static_cast(child.getProperty("SoftKeyDesignatorHeight"))); + } + if (!child.getProperty("PhysicalSoftkeys").isVoid()) + { + numberPhysicalSoftKeys = static_cast(static_cast(child.getProperty("PhysicalSoftkeys"))); + } + if (!child.getProperty("DataMaskRenderAreaSize").isVoid()) + { + dataMaskRenderer.setSize(static_cast(static_cast(child.getProperty("DataMaskRenderAreaSize"))), static_cast(static_cast(child.getProperty("DataMaskRenderAreaSize")))); + softKeyMaskRenderer.setSize(100, static_cast(child.getProperty("DataMaskRenderAreaSize"))); + } + softKeyMaskRenderer.setTopLeftPosition(100 + dataMaskRenderer.getWidth(), 4 + juce::LookAndFeel::getDefaultLookAndFeel().getDefaultMenuBarHeight()); + JuceManagedWorkingSetCache::set_data_alarm_mask_size(dataMaskRenderer.getWidth()); + JuceManagedWorkingSetCache::set_soft_key_height(softKeyDesignatorHeight); + JuceManagedWorkingSetCache::set_soft_key_width(softKeyDesignatorWidth); + } + else if (Identifier("Logging") == child.getType()) + { + if ((!child.getProperty("Level").isVoid()) && (static_cast(child.getProperty("Level")) <= static_cast(isobus::CANStackLogger::LoggingLevel::Critical))) + { + isobus::CANStackLogger::set_log_level(static_cast(static_cast(child.getProperty("Level")))); + } + } + index++; + child = settings.getChild(index); } } } @@ -1025,6 +1156,7 @@ void ServerMainComponent::save_settings() ValueTree languageCommandSettings("LanguageCommand"); ValueTree compatibilitySettings("Compatibility"); ValueTree hardwareSettings("Hardware"); + ValueTree loggingSettings("Logging"); languageCommandSettings.setProperty("AreaUnits", static_cast(languageCommandInterface.get_commanded_area_units()), nullptr); languageCommandSettings.setProperty("DateFormat", static_cast(languageCommandInterface.get_commanded_date_format()), nullptr); @@ -1044,9 +1176,11 @@ void ServerMainComponent::save_settings() hardwareSettings.setProperty("SoftKeyDesignatorWidth", get_soft_key_descriptor_x_pixel_width(), nullptr); hardwareSettings.setProperty("SoftKeyDesignatorHeight", get_soft_key_descriptor_y_pixel_width(), nullptr); hardwareSettings.setProperty("PhysicalSoftkeys", get_number_of_physical_soft_keys(), nullptr); + loggingSettings.setProperty("Level", static_cast(isobus::CANStackLogger::get_log_level()), nullptr); settings.appendChild(languageCommandSettings, nullptr); settings.appendChild(compatibilitySettings, nullptr); settings.appendChild(hardwareSettings, nullptr); + settings.appendChild(loggingSettings, nullptr); std::unique_ptr xml(settings.createXml()); if (nullptr != xml) diff --git a/src/SoftKeyMaskComponent.cpp b/src/SoftKeyMaskComponent.cpp index 0b174c5..ce44855 100644 --- a/src/SoftKeyMaskComponent.cpp +++ b/src/SoftKeyMaskComponent.cpp @@ -6,12 +6,14 @@ #include "SoftKeyMaskComponent.hpp" #include "JuceManagedWorkingSetCache.hpp" -SoftKeyMaskComponent::SoftKeyMaskComponent(std::shared_ptr workingSet, isobus::SoftKeyMask sourceObject) : +SoftKeyMaskComponent::SoftKeyMaskComponent(std::shared_ptr workingSet, isobus::SoftKeyMask sourceObject, int dataAndAlarmMaskSize, int keyHeight, int keyWidth) : isobus::SoftKeyMask(sourceObject), - parentWorkingSet(workingSet) + parentWorkingSet(workingSet), + softKeyHeight(keyHeight), + softKeyWidth(keyWidth) { setOpaque(true); - setBounds(0, 0, 100, 480); + setBounds(0, 0, softKeyWidth > 80 ? softKeyWidth + 20 : 100, dataAndAlarmMaskSize); on_content_changed(true); } @@ -28,7 +30,7 @@ void SoftKeyMaskComponent::on_content_changed(bool initial) if (nullptr != childComponents.back()) { addAndMakeVisible(*childComponents.back()); - childComponents.back()->setTopLeftPosition(10, 10 + (60 * i) + (10 * i)); + childComponents.back()->setTopLeftPosition(10, 10 + (softKeyHeight * i) + (10 * i)); } } } diff --git a/src/SoftkeyMaskRenderArea.cpp b/src/SoftkeyMaskRenderArea.cpp index 803d656..d28830a 100644 --- a/src/SoftkeyMaskRenderArea.cpp +++ b/src/SoftkeyMaskRenderArea.cpp @@ -104,6 +104,8 @@ void SoftKeyMaskRenderAreaComponent::mouseDown(const MouseEvent &event) auto relativeEvent = event.getEventRelativeTo(this); auto clickedObject = getClickedChildRecursive(activeMask, relativeEvent.getMouseDownX(), relativeEvent.getMouseDownY()); + ownerServer.processMacro(clickedObject, isobus::EventID::OnKeyPress, isobus::VirtualTerminalObjectType::Key, parentWorkingSet); + std::uint8_t keyCode = 1; if (nullptr != clickedObject) @@ -156,6 +158,8 @@ void SoftKeyMaskRenderAreaComponent::mouseUp(const MouseEvent &event) auto relativeEvent = event.getEventRelativeTo(this); auto clickedObject = getClickedChildRecursive(activeMask, relativeEvent.getPosition().x, relativeEvent.getPosition().y); + ownerServer.processMacro(clickedObject, isobus::EventID::OnKeyRelease, isobus::VirtualTerminalObjectType::Key, parentWorkingSet); + std::uint8_t keyCode = 1; if (nullptr != clickedObject) diff --git a/src/WorkingSetSelectorComponent.cpp b/src/WorkingSetSelectorComponent.cpp index feac4f8..31cc568 100644 --- a/src/WorkingSetSelectorComponent.cpp +++ b/src/WorkingSetSelectorComponent.cpp @@ -48,14 +48,15 @@ void WorkingSetSelectorComponent::paint(Graphics &g) g.setColour(getLookAndFeel().findColour(ResizableWindow::backgroundColourId)); g.fillAll(); - int numberOfSquares = 0; + // Not sure if this is helpful... + /*int numberOfSquares = 0; for (auto ws = children.begin(); ws != children.end(); ws++) { g.setColour(getLookAndFeel().findColour(ResizableWindow::backgroundColourId).brighter()); g.drawRoundedRectangle(8.0f, 8.0f + (numberOfSquares * 80), 80, 80, 6, 1); numberOfSquares++; - } + }*/ } void WorkingSetSelectorComponent::resized()