38#include <wx/mstream.h>
58template <glm::length_t L, glm::length_t C,
class T, glm::qualifier Q>
59bool equals( glm::mat<L, C, T, Q>
const& aFirst, glm::mat<L, C, T, Q>
const& aSecond,
60 T aEpsilon =
static_cast<T>( FLT_EPSILON * 10 ) )
62 T const* first = glm::value_ptr( aFirst );
63 T const* second = glm::value_ptr( aSecond );
65 for( glm::length_t j = 0; j <
L *
C; ++j )
67 if( !
equals( first[j], second[j], aEpsilon ) )
78 const std::string& aProfileHint ) :
86 PutProfileHint( aProfileHint );
93 EnableNavigation(
false );
99 wxLogTrace(
m_logTrace, wxT(
"NL_3D_VIEWER_PLUGIN_IMPL::SetFocus %d" ), aFocus );
100 NAV_3D::Write( navlib::focus_k, aFocus );
114 EnableNavigation(
true );
115 PutFrameTimingSource( TimingSource::SpaceMouse );
123 using TDx::SpaceMouse::CCategory;
125 CATEGORY_STORE::iterator parent_iter = aCategoryStore.begin();
126 std::string::size_type pos = aCategoryPath.find_last_of(
'.' );
128 if( pos != std::string::npos )
130 std::string parentPath = aCategoryPath.substr( 0, pos );
131 parent_iter = aCategoryStore.find( parentPath );
133 if( parent_iter == aCategoryStore.end() )
135 parent_iter =
add_category( parentPath, aCategoryStore );
139 std::string
name = aCategoryPath.substr( pos + 1 );
140 std::unique_ptr<CCategory> categoryNode =
141 std::make_unique<CCategory>( aCategoryPath.c_str(),
name.c_str() );
143 CATEGORY_STORE::iterator iter = aCategoryStore.insert(
144 aCategoryStore.end(), CATEGORY_STORE::value_type( aCategoryPath, categoryNode.get() ) );
146 parent_iter->second->push_back( std::move( categoryNode ) );
153 wxLogTrace(
m_logTrace, wxT(
"NL_3D_VIEWER_PLUGIN_IMPL::exportCommandsAndImages" ) );
157 if( actions.size() == 0 )
162 using TDx::SpaceMouse::CCommand;
163 using TDx::SpaceMouse::CCommandSet;
166 CCommandSet commandSet(
"EDA_3D_CANVAS",
"3D Viewer" );
169 NAV_3D::PutActiveCommands( commandSet.GetId() );
174 std::vector<TDx::CImage> vImages;
177 categoryStore.insert( categoryStore.end(), CATEGORY_STORE::value_type(
".", &commandSet ) );
179 std::list<TOOL_ACTION*>::const_iterator it;
181 for( it = actions.begin(); it != actions.end(); ++it )
184 std::string label = action->
GetMenuLabel().ToStdString();
194 if(
name.rfind(
"pcbnew.", 0 ) == 0 )
200 CATEGORY_STORE::iterator iter = categoryStore.find( strCategory );
202 if( iter == categoryStore.end() )
204 iter =
add_category( std::move( strCategory ), categoryStore );
210 wxMemoryOutputStream imageStream;
215 image.SaveFile( imageStream, wxBitmapType::wxBITMAP_TYPE_PNG );
218 if( imageStream.GetSize() )
220 wxStreamBuffer* streamBuffer = imageStream.GetOutputStreamBuffer();
221 TDx::CImage tdxImage = TDx::CImage::FromData(
"", 0,
name.c_str() );
222 tdxImage.AssignImage( std::string(
reinterpret_cast<const char*
>(
223 streamBuffer->GetBufferStart() ),
224 streamBuffer->GetBufferSize() ),
228 vImages.push_back( std::move( tdxImage ) );
232 wxLogTrace(
m_logTrace, wxT(
"Inserting command: %s, description: %s, in category: %s" ),
233 name, description, iter->first );
235 iter->second->push_back(
236 CCommand( std::move(
name ), std::move( label ), std::move( description ) ) );
239 NAV_3D::AddCommandSet( commandSet );
240 NAV_3D::AddImages( vImages );
250 std::copy_n( glm::value_ptr( glm::inverse(
m_cameraMatrix ) ), 16, matrix.m );
259 m_camera->MakeRayAtCurrentMousePosition( origin, direction );
261 position = { origin.x, origin.y, origin.z };
271 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
276 double half_width = f.
fw / 2.;
277 double half_height = f.
fh / 2.;
278 extents = { -half_width, -half_height, f.
nearD, half_width, half_height, f.
farD };
288 aFov = glm::radians( f.
angle );
297 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
301 double half_width = f.
nw / 2.;
302 double half_height = f.
nh / 2.;
303 aFrustum = { -half_width, half_width, -half_height, half_height, f.
nearD, f.
farD };
321 glm::mat4 cam, viewMatrix;
322 std::copy_n( aCameraMatrix.m, 16, glm::value_ptr( cam ) );
323 viewMatrix = glm::inverse( cam );
325 glm::mat4 camera =
m_camera->GetViewMatrix();
335 glm::vec4 lookat(
m_camera->GetLookAtPos(), 1.0f );
336 glm::vec4 lookat_new = viewMatrix * lookat;
337 glm::vec4 lookat_old = camera * lookat;
339 viewMatrix[3].z += lookat_old.z - lookat_new.z;
354 return navlib::make_result_code( navlib::navlib_errc::error );
357 m_camera->SetViewMatrix( viewMatrix );
368 return navlib::make_result_code( navlib::navlib_errc::error );
379 float factor = f.
nw / ( extents.max_x - extents.min_x );
392 return navlib::make_result_code( navlib::navlib_errc::error );
401 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
407 return navlib::make_result_code( navlib::navlib_errc::permission_denied );
416 extents = { min.x, min.y, min.z, max.x, max.y, max.z };
424 return navlib::make_result_code( navlib::navlib_errc::no_data_available );
430 return navlib::make_result_code( navlib::navlib_errc::no_data_available );
444 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
452 position = { lap.x, lap.y, lap.z };
471 m_canvas->Set3dmousePivotPos( pivotPos );
474 m_camera->SetLookAtPos_T1( pivotPos );
484 visible =
m_canvas->GetRender3dmousePivot();
492 m_canvas->SetRender3dmousePivot( visible );
510 if(
m_canvas->GetBoardAdapter().GetBBox().Intersect( mouseRay, &hit ) )
512 vec = mouseRay.
at( hit );
513 position = { vec.x, vec.y, vec.z };
517 return navlib::make_result_code( navlib::navlib_errc::no_data_available );
523 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
545 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
551 if( commandId.empty() )
557 for( std::list<TOOL_ACTION*>::const_iterator it = actions.begin(); it != actions.end(); it++ )
560 std::string nm = action->
GetName();
562 if( commandId == nm )
566 if( context !=
nullptr )
568 wxWindow* parent =
m_canvas->GetParent();
572 if( parent && parent->IsEnabled() )
578 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
583 bool runAction =
true;
586 runAction = aCond->enableCondition( sel );
596 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
626 wxLogTrace(
m_logTrace, wxT(
"End of transaction" ) );
635 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
641 matrix = { 1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1 };
649 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.