#ifndef CNavlibImpl_HPP_INCLUDED #define CNavlibImpl_HPP_INCLUDED /* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (c) 2018-2021 3Dconnexion. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ /** * @file CNavlibImpl.hpp * @brief INavlib implementation. */ #include #include #include // stdlib #include #include #include #include // navlib #include #include namespace TDx { namespace SpaceMouse { namespace Navigation3D { /// /// Implementation for creating a shared pointer. /// class CNavlibImpl : public INavlib, #if defined(_MSC_VER) && _MSC_VER < 1800 public IAccessors, #else private IAccessors, #endif public std::enable_shared_from_this { typedef CNavlibImpl this_type; friend std::shared_ptr std::static_pointer_cast(const std::shared_ptr &) NOEXCEPT; /// /// Make the constructors private to force creation of a shared pointer. /// CNavlibImpl(){}; CNavlibImpl(IAccessors *iclient) : m_iclient(iclient) { } public: /// /// Creates a new instance of the CNavlibImpl class. /// /// pointer to the instance implementing the IAccessors interface. /// true to use multi-threading, false for single-threaded. /// true for row-major ordered matrices, false for column-major. /// /// A to the new CNavlibImpl instance. /// static std::shared_ptr CreateInstance(IAccessors *iclient, bool multiThreaded = false, bool rowMajor = false) { return CreateInstance(iclient, multiThreaded, rowMajor ? navlib::row_major_order : navlib::none); } /// /// Creates a new instance of the CNavlibImpl class. /// /// pointer to the instance implementing the IAccessors interface. /// true to use multi-threading, false for single-threaded. /// A combination of the values. /// /// A to the new CNavlibImpl instance. /// static std::shared_ptr CreateInstance(IAccessors *iclient, bool multiThreaded, navlib::nlOptions_t options) { if (iclient == nullptr) { throw std::logic_error("The accessor interface is null"); } // So that std::make_shared<> can be used with the private constructor. struct make_shared_enabler : public this_type { make_shared_enabler(IAccessors *iclient) : this_type(iclient) { } }; std::shared_ptr result = std::make_shared(iclient); #if 1 result->m_pNavlib = std::unique_ptr( new CNavlibInterface(std::static_pointer_cast(result), multiThreaded, options)); #endif return result; } /// /// Clean up the resources /// virtual ~CNavlibImpl() { } // INavlib implementation /// /// Close the connection to the 3D navigation library. /// void Close() override { m_pNavlib->Close(); } /// /// Opens a connection to the 3D navigation library. /// void Open() override { m_pNavlib->Open(); } /// /// Opens a connection to the 3D navigation library /// /// The name of the 3Dconnexion profile to use. /// The connection to the library is already open. /// Cannot create a connection to the library. /// The name of the profile is empty. void Open(std::string profileName) override { m_pNavlib->Open(std::move(profileName)); } /// /// Writes the value of a property to the navlib. /// /// The name of the navlib property to /// write. /// The to write. /// 0 =no error, otherwise a value from . /// No connection to the navlib / 3D Mouse. long Write(const std::string &propertyName, const navlib::value &value) override { return m_pNavlib->Write(propertyName, value); } /// /// Reads the value of a navlib property. /// /// The name of the navlib property to /// read. /// The to read. /// 0 =no error, otherwise a value from . /// No connection to the navlib / 3D Mouse. long Read(const std::string &propertyName, navlib::value &value) const override { return m_pNavlib->Read(propertyName, value); } /// /// Reads the value of a navlib string property. /// /// The name of the navlib property to /// read. /// The value of the property. /// 0 =no error, otherwise a value from . /// No connection to the navlib. long Read(const std::string &propertyName, std::string &string) const override { return m_pNavlib->Read(propertyName, string); } private: // IEvents overrides long SetActiveCommand(std::string commandId) override { return m_iclient->SetActiveCommand(commandId); } long SetSettingsChanged(long change) override { return m_iclient->SetSettingsChanged(change); } long SetKeyPress(long vkey) override { return m_iclient->SetKeyPress(vkey); } long SetKeyRelease(long vkey) override { return m_iclient->SetKeyRelease(vkey); } // IHit overrides long GetHitLookAt(navlib::point_t &position) const override { return m_iclient->GetHitLookAt(position); } long SetHitAperture(double aperture) override { return m_iclient->SetHitAperture(aperture); } long SetHitDirection(const navlib::vector_t &direction) override { return m_iclient->SetHitDirection(direction); } long SetHitLookFrom(const navlib::point_t &eye) override { return m_iclient->SetHitLookFrom(eye); } long SetHitSelectionOnly(bool onlySelection) override { return m_iclient->SetHitSelectionOnly(onlySelection); } // IModel overrides long GetModelExtents(navlib::box_t &extents) const override { return m_iclient->GetModelExtents(extents); } long GetSelectionExtents(navlib::box_t &extents) const override { return m_iclient->GetSelectionExtents(extents); } long GetSelectionTransform(navlib::matrix_t &transform) const override { return m_iclient->GetSelectionTransform(transform); } long GetIsSelectionEmpty(navlib::bool_t &empty) const override { return m_iclient->GetIsSelectionEmpty(empty); } long SetSelectionTransform(const navlib::matrix_t &matrix) override { return m_iclient->SetSelectionTransform(matrix); } // IPivot overrides long GetPivotPosition(navlib::point_t &position) const override { return m_iclient->GetPivotPosition(position); } long IsUserPivot(navlib::bool_t &userPivot) const override { return m_iclient->IsUserPivot(userPivot); } long SetPivotPosition(const navlib::point_t &position) override { return m_iclient->SetPivotPosition(position); } long GetPivotVisible(navlib::bool_t &visible) const override { return m_iclient->GetPivotVisible(visible); } long SetPivotVisible(bool visible) override { return m_iclient->SetPivotVisible(visible); } // ISpace3D overrides long GetCoordinateSystem(navlib::matrix_t &matrix) const override { return m_iclient->GetCoordinateSystem(matrix); } long GetFrontView(navlib::matrix_t &matrix) const override { return m_iclient->GetFrontView(matrix); } // IState overrides long SetTransaction(long transaction) override { return m_iclient->SetTransaction(transaction); } long SetMotionFlag(bool motion) override { return m_iclient->SetMotionFlag(motion); } // IView overrides long GetCameraMatrix(navlib::matrix_t &matrix) const override { return m_iclient->GetCameraMatrix(matrix); } long GetCameraTarget(navlib::point_t &point) const override { return m_iclient->GetCameraTarget(point); } long GetPointerPosition(navlib::point_t &position) const override { return m_iclient->GetPointerPosition(position); } long GetViewConstructionPlane(navlib::plane_t &plane) const override { return m_iclient->GetViewConstructionPlane(plane); } long GetViewExtents(navlib::box_t &extents) const override { return m_iclient->GetViewExtents(extents); } long GetViewFOV(double &fov) const override { return m_iclient->GetViewFOV(fov); } long GetViewFrustum(navlib::frustum_t &frustum) const override { return m_iclient->GetViewFrustum(frustum); } long GetIsViewPerspective(navlib::bool_t &perspective) const override { return m_iclient->GetIsViewPerspective(perspective); } long GetIsViewRotatable(navlib::bool_t &isRotatable) const override { return m_iclient->GetIsViewRotatable(isRotatable); } long SetCameraMatrix(const navlib::matrix_t &matrix) override { return m_iclient->SetCameraMatrix(matrix); } long SetCameraTarget(const navlib::point_t &target) override { return m_iclient->SetCameraTarget(target); } long SetPointerPosition(const navlib::point_t &position) override { return m_iclient->SetPointerPosition(position); } long SetViewExtents(const navlib::box_t &extents) override { return m_iclient->SetViewExtents(extents); } long SetViewFOV(double fov) override { return m_iclient->SetViewFOV(fov); } long SetViewFrustum(const navlib::frustum_t &frustum) override { return m_iclient->SetViewFrustum(frustum); } private: IAccessors *m_iclient; std::unique_ptr m_pNavlib; }; } // namespace Navigation3D } // namespace SpaceMouse } // namespace TDx #endif // CNavlibImpl_HPP_INCLUDED