Adds 3DConnexion Device Button Map loading from XML file
This commit is contained in:
43
src/Gui/3DConnexion.xml
Normal file
43
src/Gui/3DConnexion.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ButtonMap DeviceName="SpacePilot">
|
||||
<Mapping>
|
||||
<Map Description="Ortho" KeyCode="0" DownTime="short" Command="Std_OrthographicCamera"/>
|
||||
<Map Description="Front" KeyCode="1" DownTime="short" Command="Std_ViewFront"/>
|
||||
<Map Description="Rear" KeyCode="2" DownTime="short" Command="Std_ViewFitAll"/>
|
||||
</Mapping>
|
||||
</ButtonMap>
|
||||
|
||||
<ButtonMap DeviceName="SpacePilot Pro">
|
||||
<Mapping>
|
||||
<Map Description="Menu" KeyCode="0" DownTime="short" Command=""/>
|
||||
<Map Description="Fit" KeyCode="1" DownTime="short" Command=""/>
|
||||
<Map Description="Top" KeyCode="2" DownTime="short" Command="Std_ViewTop"/>
|
||||
<Map Description="Bottom" KeyCode="2" DownTime="long" Command="Std_ViewBottom"/>
|
||||
<Map Description="Right" KeyCode="4" DownTime="short" Command="Std_ViewRight"/>
|
||||
<Map Description="Left" KeyCode="4" DownTime="long" Command="Std_ViewLeft"/>
|
||||
<Map Description="Front" KeyCode="5" DownTime="short" Command="Std_ViewFront"/>
|
||||
<Map Description="Rear" KeyCode="5" DownTime="long" Command="Std_ViewRear"/>
|
||||
<Map Description="Clockwise" KeyCode="8" DownTime="short" Command=""/>
|
||||
<Map Description="AntiClockwise" KeyCode="8" DownTime="long" Command=""/>
|
||||
<Map Description="ISO1" KeyCode="10" DownTime="short" Command="Std_OrthographicCamera"/>
|
||||
<Map Description="ISO2" KeyCode="10" DownTime="long" Command=""/>
|
||||
<Map Description="1" KeyCode="12" DownTime="short" Command=""/>
|
||||
<Map Description="6" KeyCode="12" DownTime="long" Command=""/>
|
||||
<Map Description="2" KeyCode="13" DownTime="short" Command=""/>
|
||||
<Map Description="7" KeyCode="13" DownTime="long" Command=""/>
|
||||
<Map Description="3" KeyCode="14" DownTime="short" Command=""/>
|
||||
<Map Description="8" KeyCode="14" DownTime="long" Command=""/>
|
||||
<Map Description="4" KeyCode="15" DownTime="short" Command=""/>
|
||||
<Map Description="9" KeyCode="15" DownTime="long" Command=""/>
|
||||
<Map Description="5" KeyCode="16" DownTime="short" Command=""/>
|
||||
<Map Description="10" KeyCode="16" DownTime="long" Command=""/>
|
||||
<Map Description="ESC" KeyCode="22" DownTime="short" Command=""/>
|
||||
<Map Description="ALT" KeyCode="23" DownTime="short" Command=""/>
|
||||
<Map Description="SHIFT" KeyCode="24" DownTime="short" Command=""/>
|
||||
<Map Description="CTRL" KeyCode="25" DownTime="short" Command=""/>
|
||||
<Map Description="ROTZ" KeyCode="26" DownTime="short" Command=""/>
|
||||
<Map Description="AXIS" KeyCode="27" DownTime="short" Command=""/>
|
||||
<Map Description="FIT" KeyCode="28" DownTime="short" Command=""/>
|
||||
<Map Description="PlusMinus" KeyCode="30" DownTime="short" Command=""/>
|
||||
</Mapping>
|
||||
</ButtonMap>
|
||||
@@ -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("<xmlattr>"))
|
||||
{
|
||||
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<ParameterGrp> 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("<xmlattr>"))
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -28,6 +28,10 @@
|
||||
#include <QAbstractListModel>
|
||||
#include "PropertyPage.h"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/xml_parser.hpp>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user