41#include <wx/mstream.h>
61template <glm::length_t L, glm::length_t C,
class T, glm::qualifier Q>
62bool equals( glm::mat<L, C, T, Q>
const& aFirst, glm::mat<L, C, T, Q>
const& aSecond,
63 T aEpsilon =
static_cast<T>( FLT_EPSILON * 10 ) )
65 T const* first = glm::value_ptr( aFirst );
66 T const* second = glm::value_ptr( aSecond );
68 for( glm::length_t j = 0; j <
L *
C; ++j )
70 if( !
equals( first[j], second[j], aEpsilon ) )
81 const std::string& aProfileHint ) :
89 PutProfileHint( aProfileHint );
96 EnableNavigation(
false );
102 wxLogTrace(
m_logTrace, wxT(
"NL_3D_VIEWER_PLUGIN_IMPL::SetFocus %d" ), aFocus );
103 NAV_3D::Write( navlib::focus_k, aFocus );
117 EnableNavigation(
true );
118 PutFrameTimingSource( TimingSource::SpaceMouse );
126 using TDx::SpaceMouse::CCategory;
128 CATEGORY_STORE::iterator parent_iter = aCategoryStore.begin();
129 std::string::size_type pos = aCategoryPath.find_last_of(
'.' );
131 if( pos != std::string::npos )
133 std::string parentPath = aCategoryPath.substr( 0, pos );
134 parent_iter = aCategoryStore.find( parentPath );
136 if( parent_iter == aCategoryStore.end() )
138 parent_iter =
add_category( parentPath, aCategoryStore );
142 std::string
name = aCategoryPath.substr( pos + 1 );
143 std::unique_ptr<CCategory> categoryNode =
144 std::make_unique<CCategory>( aCategoryPath.c_str(),
name.c_str() );
146 CATEGORY_STORE::iterator iter = aCategoryStore.insert(
147 aCategoryStore.end(), CATEGORY_STORE::value_type( aCategoryPath, categoryNode.get() ) );
149 parent_iter->second->push_back( std::move( categoryNode ) );
156 wxLogTrace(
m_logTrace, wxT(
"NL_3D_VIEWER_PLUGIN_IMPL::exportCommandsAndImages" ) );
160 if( actions.size() == 0 )
165 using TDx::SpaceMouse::CCommand;
166 using TDx::SpaceMouse::CCommandSet;
169 CCommandSet commandSet(
"EDA_3D_CANVAS",
"3D Viewer" );
172 NAV_3D::PutActiveCommands( commandSet.GetId() );
177 std::vector<TDx::CImage> vImages;
180 categoryStore.insert( categoryStore.end(), CATEGORY_STORE::value_type(
".", &commandSet ) );
182 std::list<TOOL_ACTION*>::const_iterator it;
184 for( it = actions.begin(); it != actions.end(); ++it )
187 std::string label = action->
GetMenuLabel().ToStdString();
197 if(
name.rfind(
"pcbnew.", 0 ) == 0 )
203 CATEGORY_STORE::iterator iter = categoryStore.find( strCategory );
205 if( iter == categoryStore.end() )
207 iter =
add_category( std::move( strCategory ), categoryStore );
213 wxMemoryOutputStream imageStream;
218 image.SaveFile( imageStream, wxBitmapType::wxBITMAP_TYPE_PNG );
221 if( imageStream.GetSize() )
223 wxStreamBuffer* streamBuffer = imageStream.GetOutputStreamBuffer();
224 TDx::CImage tdxImage = TDx::CImage::FromData(
"", 0,
name.c_str() );
225 tdxImage.AssignImage( std::string(
reinterpret_cast<const char*
>(
226 streamBuffer->GetBufferStart() ),
227 streamBuffer->GetBufferSize() ),
231 vImages.push_back( std::move( tdxImage ) );
235 wxLogTrace(
m_logTrace, wxT(
"Inserting command: %s, description: %s, in category: %s" ),
236 name, description, iter->first );
238 iter->second->push_back(
239 CCommand( std::move(
name ), std::move( label ), std::move( description ) ) );
242 NAV_3D::AddCommandSet( commandSet );
243 NAV_3D::AddImages( vImages );
253 std::copy_n( glm::value_ptr( glm::inverse(
m_cameraMatrix ) ), 16, matrix.m );
262 m_camera->MakeRayAtCurrentMousePosition( origin, direction );
264 position = { origin.x, origin.y, origin.z };
274 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
279 double half_width = f.
fw / 2.;
280 double half_height = f.
fh / 2.;
281 extents = { -half_width, -half_height, f.
nearD, half_width, half_height, f.
farD };
291 aFov = glm::radians( f.
angle );
300 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
304 double half_width = f.
nw / 2.;
305 double half_height = f.
nh / 2.;
306 aFrustum = { -half_width, half_width, -half_height, half_height, f.
nearD, f.
farD };
324 glm::mat4 cam, viewMatrix;
325 std::copy_n( aCameraMatrix.m, 16, glm::value_ptr( cam ) );
326 viewMatrix = glm::inverse( cam );
328 glm::mat4 camera =
m_camera->GetViewMatrix();
338 glm::vec4 lookat(
m_camera->GetLookAtPos(), 1.0f );
339 glm::vec4 lookat_new = viewMatrix * lookat;
340 glm::vec4 lookat_old = camera * lookat;
342 viewMatrix[3].z += lookat_old.z - lookat_new.z;
357 return navlib::make_result_code( navlib::navlib_errc::error );
360 m_camera->SetViewMatrix( viewMatrix );
371 return navlib::make_result_code( navlib::navlib_errc::error );
382 float factor = f.
nw / ( extents.max_x - extents.min_x );
395 return navlib::make_result_code( navlib::navlib_errc::error );
404 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
410 return navlib::make_result_code( navlib::navlib_errc::permission_denied );
419 extents = { min.x, min.y, min.z, max.x, max.y, max.z };
427 return navlib::make_result_code( navlib::navlib_errc::no_data_available );
433 return navlib::make_result_code( navlib::navlib_errc::no_data_available );
447 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
455 position = { lap.x, lap.y, lap.z };
474 m_canvas->Set3dmousePivotPos( pivotPos );
477 m_camera->SetLookAtPos_T1( pivotPos );
487 visible =
m_canvas->GetRender3dmousePivot();
495 m_canvas->SetRender3dmousePivot( visible );
513 if(
m_canvas->GetBoardAdapter().GetBBox().Intersect( mouseRay, &hit ) )
515 vec = mouseRay.
at( hit );
516 position = { vec.x, vec.y, vec.z };
520 return navlib::make_result_code( navlib::navlib_errc::no_data_available );
526 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
548 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
554 if( commandId.empty() )
560 for( std::list<TOOL_ACTION*>::const_iterator it = actions.begin(); it != actions.end(); it++ )
563 std::string nm = action->
GetName();
565 if( commandId == nm )
569 if( context !=
nullptr )
571 wxWindow* parent =
m_canvas->GetParent();
575 if( parent && parent->IsEnabled() )
581 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
586 bool runAction =
true;
589 runAction = aCond->GetHotkeyCondition()( sel );
599 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
629 wxLogTrace(
m_logTrace, wxT(
"End of transaction" ) );
638 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
644 matrix = { 1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1 };
652 matrix = { 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1 };
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
const ACTION_CONDITIONS * GetCondition(const TOOL_ACTION &aAction) const
Get the conditions to use for a specific tool action.
static std::list< TOOL_ACTION * > & GetActionList()
Return list of TOOL_ACTIONs.
Implement a canvas based on a wxGLCanvas.
long GetViewExtents(navlib::box_t &aExtents) const override
long GetCameraMatrix(navlib::matrix_t &aMatrix) const override
void Connect()
Connect plugin implementation to the driver.
long SetHitLookFrom(const navlib::point_t &aPosition) override
long SetActiveCommand(std::string aCommandId) override
EDA_3D_CANVAS * GetCanvas() const
Get the m_canvas pointer.
long GetPivotPosition(navlib::point_t &aPosition) const override
long GetModelExtents(navlib::box_t &aExtents) const override
long GetPointerPosition(navlib::point_t &aPosition) const override
long SetPivotVisible(bool aVisible) override
long SetTransaction(long aValue) override
long SetViewFOV(double aFov) override
long SetMotionFlag(bool aValue) override
long SetCameraMatrix(const navlib::matrix_t &aMatrix) override
long GetHitLookAt(navlib::point_t &aPosition) const override
long SetHitAperture(double aAperture) override
long SetPivotPosition(const navlib::point_t &aPosition) override
long SetHitDirection(const navlib::vector_t &aDirection) override
long GetSelectionTransform(navlib::matrix_t &aTransform) const override
long SetSelectionTransform(const navlib::matrix_t &aMatrix) override
long SetSettingsChanged(long aChangeNumber) override
virtual ~NL_3D_VIEWER_PLUGIN_IMPL()
long SetHitSelectionOnly(bool aSelectionOnly) override
long GetIsSelectionEmpty(navlib::bool_t &aEmpty) const override
long GetSelectionExtents(navlib::box_t &aExtents) const override
long GetCoordinateSystem(navlib::matrix_t &aMatrix) const override
long IsUserPivot(navlib::bool_t &aUserPivot) const override
long GetViewFOV(double &aFov) const override
long GetPivotVisible(navlib::bool_t &aVisible) const override
long GetFrontView(navlib::matrix_t &aMatrix) const override
NL_3D_VIEWER_PLUGIN_IMPL(EDA_3D_CANVAS *aCanvas, const std::string &aProfileHint)
Initializes a new instance of the NL_3DVIEWER_PLUGIN.
long GetViewFrustum(navlib::frustum_t &aFrustum) const override
long GetIsViewPerspective(navlib::bool_t &aPerspective) const override
long SetViewFrustum(const navlib::frustum_t &aFrustum) override
long SetViewExtents(const navlib::box_t &aExtents) override
virtual void exportCommandsAndImages()
Export the invocable actions and images to the 3Dconnexion UI.
void SetFocus(bool aFocus=true)
Set the connection to the 3Dconnexion driver to the focus state so that 3DMouse data is routed here.
long GetIsViewRotatable(navlib::bool_t &isRotatable) const override
long SetCameraTarget(const navlib::point_t &aPosition) override
static bool empty(const wxTextEntryBase *aCtrl)
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
bool SafeNavlibInit(const std::function< void()> &aInitFunc)
Attempt to run the given function, recovering from both C++ exceptions and abort() calls triggered by...
Safe initialization wrapper for the 3Dconnexion navlib SDK.
bool equals(glm::mat< L, C, T, Q > const &aFirst, glm::mat< L, C, T, Q > const &aSecond, T aEpsilon=static_cast< T >(FLT_EPSILON *10))
Template to compare two glm::mat<T> values for equality within a required epsilon.
CATEGORY_STORE::iterator add_category(std::string aCategoryPath, CATEGORY_STORE &aCategoryStore)
Add a category to the store.
Declaration of the NL_3D_VIEWER_PLUGIN_IMPL class.
std::map< std::string, TDx::CCommandTreeNode * > CATEGORY_STORE
CATEGORY_STORE::iterator add_category(std::string aCategoryPath, CATEGORY_STORE &aCategoryStore)
Add a category to the store.
TDx::SpaceMouse::Navigation3D::CNavigation3D NAV_3D
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
Frustum is a implementation based on a tutorial by http://www.lighthouse3d.com/tutorials/view-frustum...
void Init(const SFVEC3F &o, const SFVEC3F &d)
SFVEC3F at(float t) const
wxString result
Test unit parsing edge cases and error handling.
Declaration for a track ball camera.