Skip to content

Commit

Permalink
Merge pull request #396 from pskowronskiTDx/tdx-integration-pr
Browse files Browse the repository at this point in the history
Integration with 3Dconnexion input devices
  • Loading branch information
ghutchis authored Sep 1, 2023
2 parents 87fc3e2 + fe01deb commit 17b8ff9
Show file tree
Hide file tree
Showing 41 changed files with 9,421 additions and 2 deletions.
21 changes: 21 additions & 0 deletions avogadro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ elseif(WIN32)
list(APPEND avogadro_srcs icons/avogadro.rc)
endif()

if(USE_3DCONNEXION AND (WIN32 OR APPLE))
list(APPEND avogadro_srcs icons/3dx_pivot.png)
list(APPEND avogadro_srcs tdxcontroller.cpp)
list(APPEND avogadro_srcs "${AvogadroApp_SOURCE_DIR}/thirdparty/3DConnexion/src/navlib_load.cpp")
list(APPEND avogadro_srcs "${AvogadroApp_SOURCE_DIR}/thirdparty/3DConnexion/src/navlib_stub.c")
set_source_files_properties(icons/3dx_pivot.png PROPERTIES
MACOSX_PACKAGE_LOCATION Resources)
endif()

add_executable(avogadro WIN32 MACOSX_BUNDLE
${avogadro_srcs} ${ui_srcs} ${rcc_srcs})
target_link_libraries(avogadro Qt::Widgets Qt::Network Qt::Concurrent)
Expand All @@ -188,6 +197,18 @@ endif()
if(QT_VERSION EQUAL 6)
target_link_libraries(avogadro Qt6::Core5Compat)
endif()

if(USE_3DCONNEXION AND (WIN32 OR APPLE))
target_compile_definitions(avogadro PUBLIC _3DCONNEXION)
target_include_directories(avogadro PUBLIC "${AvogadroApp_SOURCE_DIR}/thirdparty/3DConnexion/inc")
if(APPLE)
target_compile_definitions(avogadro PUBLIC __APPLE__)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdeclspec")
elseif(WIN32)
install(FILES "icons/3dx_pivot.png" DESTINATION "${CMAKE_INSTALL_BINDIR}/img")
endif()
endif()

install(TARGETS avogadro
RUNTIME DESTINATION ${INSTALL_RUNTIME_DIR}
BUNDLE DESTINATION .
Expand Down
Binary file added avogadro/icons/3dx_pivot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 30 additions & 1 deletion avogadro/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "renderingdialog.h"
#include "tooltipfilter.h"
#include "viewfactory.h"
#include "tdxcontroller.h"

#include <avogadro/core/elements.h>
#include <avogadro/io/cjsonformat.h>
Expand Down Expand Up @@ -245,6 +246,9 @@ MainWindow::MainWindow(const QStringList& fileNames, bool disableSettings)
, m_redo(nullptr)
, m_copyImage(nullptr)
, m_viewFactory(new ViewFactory)
#ifdef _3DCONNEXION
, m_TDxController(nullptr)
#endif
{
// If disable settings, ensure we create a cleared QSettings object.
if (disableSettings) {
Expand Down Expand Up @@ -312,10 +316,35 @@ MainWindow::MainWindow(const QStringList& fileNames, bool disableSettings)
statusBar()->showMessage(tr("Ready…"), 2000);

updateWindowTitle();

#ifdef _3DCONNEXION
GLWidget* glWidget =
qobject_cast<GLWidget*>(m_multiViewWidget->activeWidget());

m_TDxController = new TDxController(this, glWidget);

connect(this, &MainWindow::moleculeChanged, m_TDxController,
&TDxController::updateMolecule);

m_TDxController->enableController();

QMap<QString, QList<QAction*>> actionsMap = m_menuBuilder->getMenuActions();
QList<QAction*> toolActions;

for (auto tool : m_tools)
toolActions.push_back(tool->activateAction());

actionsMap.insert("Toolbox", toolActions);

m_TDxController->exportCommands(actionsMap);
#endif
}

MainWindow::~MainWindow()
{
#ifdef _3DCONNEXION
m_TDxController->disableController();
#endif
writeSettings();
delete m_molecule;
delete m_menuBuilder;
Expand Down Expand Up @@ -1810,7 +1839,7 @@ void MainWindow::buildMenu()
m_menuBuilder->addAction(path, action, 960);
m_fileToolBar->addAction(action);
connect(action, SIGNAL(triggered()), SLOT(saveFileAs()));

// Export
QStringList exportPath = path;
exportPath << tr("&Export");
Expand Down
8 changes: 7 additions & 1 deletion avogadro/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace QtOpenGL {
class GLWidget;
}

namespace Io {
namespace Io {
class FileFormat;
}

Expand All @@ -48,6 +48,9 @@ class RWMolecule;
class LayerModel;
}

#ifdef _3DCONNEXION
class TDxController;
#endif
/**
* @class MainWindow
* @author Marcus D. Hanwell
Expand Down Expand Up @@ -404,6 +407,9 @@ private slots:
ViewFactory* m_viewFactory;

QNetworkAccessManager* m_network = nullptr;
#ifdef _3DCONNEXION
TDxController* m_TDxController;
#endif

#ifdef QTTESTING
pqTestUtility* m_testUtility;
Expand Down
8 changes: 8 additions & 0 deletions avogadro/menubuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ class MenuBuilder : public QObject
*/
void print();

/**
* @brief Get the map of string to action lists.
*/
const QMap<QString, QList<QAction*>>& getMenuActions() const
{
return m_menuActions;
};

private:
/** A map of string to action lists. */
QMap<QString, QList<QAction*>> m_menuActions;
Expand Down
Loading

0 comments on commit 17b8ff9

Please sign in to comment.