From 8573ff4c9e9dc80550c119d7be7d910d0e21357a Mon Sep 17 00:00:00 2001 From: SolidDude Date: Sun, 16 Feb 2020 15:30:37 +0000 Subject: [PATCH] Adds 3DConnexion Device Button Map loading from XML file --- src/Gui/3DConnexion.xml | 43 +++++++++++++ src/Gui/DlgCustomizeSpaceball.cpp | 103 +++++++++++++++++++++++++++++- src/Gui/DlgCustomizeSpaceball.h | 6 ++ 3 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 src/Gui/3DConnexion.xml diff --git a/src/Gui/3DConnexion.xml b/src/Gui/3DConnexion.xml new file mode 100644 index 0000000000..9b495dd7f1 --- /dev/null +++ b/src/Gui/3DConnexion.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Gui/DlgCustomizeSpaceball.cpp b/src/Gui/DlgCustomizeSpaceball.cpp index 43d84473da..c284a97c50 100644 --- a/src/Gui/DlgCustomizeSpaceball.cpp +++ b/src/Gui/DlgCustomizeSpaceball.cpp @@ -78,9 +78,110 @@ void ButtonView::goChangedCommand(const QString& commandName) ButtonModel::ButtonModel(QObject *parent) : QAbstractListModel(parent) { - + Load3DConnexionButtons("SpacePilot Pro"); } +// Process the given Mapping tree to load in the Button mappings. +void ButtonModel::Load3DConnexionButtonMapping(boost::property_tree::ptree ButtonMapTree) +{ + spaceballButtonGroup()->Clear(); + + BOOST_FOREACH(const boost::property_tree::ptree::value_type &Map, ButtonMapTree.get_child("Mapping")) + { + if ("Map" == Map.first) + { + std::string ButtonDescription; + std::string ButtonCode; + std::string ButtonCommand; + std::string ButtonDownTime; + + // Inspect Map attributes + BOOST_FOREACH(const boost::property_tree::ptree::value_type &kv, Map.second.get_child("")) + { + std::string Attribute; + std::string Value; + + Attribute = kv.first.data(); + Value = kv.second.data(); + + if (0 == Attribute.compare("Description")) + { + ButtonDescription = Value; + } + if (0 == Attribute.compare("KeyCode")) + { + ButtonCode = Value; + } + if (0 == Attribute.compare("DownTime")) + { + ButtonDownTime = Value; + } + if (0 == Attribute.compare("Command")) + { + ButtonCommand = Value; + } + } + + // ButtonCode is mandatory, the remaining attributes optional. + if (!ButtonCode.empty()) + { + Base::Reference newGroup; + + newGroup = spaceballButtonGroup()->GetGroup(ButtonCode.c_str()); + newGroup->SetASCII("Command", ButtonCommand.c_str()); + } + } + } +} + +// Optionally preload Button model with 3DConnexion configuration to match Solidworks +// For now the Button mapping file (3DConnexion.xml) is held the same folder as the FreeCAD executable. +void ButtonModel::Load3DConnexionButtons(const char *RequiredDeviceName) +{ + try + { + boost::property_tree::ptree tree; + boost::property_tree::ptree DeviceTree; + + // exception thrown if no file found + read_xml("3DConnexion.xml", tree); + + BOOST_FOREACH(const boost::property_tree::ptree::value_type &ButtonMap, tree.get_child("")) + { + if ("ButtonMap" == ButtonMap.first) + { + // Inspect ButtonMap attributes for DeviceName + BOOST_FOREACH(const boost::property_tree::ptree::value_type &kv, ButtonMap.second.get_child("")) + { + std::string Attribute; + std::string Value; + + Attribute = kv.first.data(); + Value = kv.second.data(); + + if (0 == Attribute.compare("DeviceName")) + { + if (0 == Value.compare(RequiredDeviceName)) + { + // We found the ButtonMap we want to load up + DeviceTree = ButtonMap.second; + } + } + } + } + } + // If we found the required devices ButtonMap + if (!DeviceTree.empty()) + { + Load3DConnexionButtonMapping(DeviceTree); + } + } + catch (const std::exception& e) + { + // We don't mind not finding the file to be opened + } +} + int ButtonModel::rowCount (const QModelIndex &parent) const { Q_UNUSED(parent); diff --git a/src/Gui/DlgCustomizeSpaceball.h b/src/Gui/DlgCustomizeSpaceball.h index 315c8af1d9..b46780071f 100644 --- a/src/Gui/DlgCustomizeSpaceball.h +++ b/src/Gui/DlgCustomizeSpaceball.h @@ -28,6 +28,10 @@ #include #include "PropertyPage.h" +#include +#include +#include + class Command; class QPushButton; @@ -63,6 +67,8 @@ namespace Gui void goMacroRemoved(const QByteArray& macroName); void goClear(); private: + void Load3DConnexionButtonMapping(boost::property_tree::ptree ButtonMapTree); + void Load3DConnexionButtons(const char *RequiredDeviceName); ParameterGrp::handle spaceballButtonGroup() const; QString getLabel(const int &number) const; };