37#include <wx/mstream.h>
57template <glm::length_t L, glm::length_t C,
class T, glm::qualifier Q>
58bool equals( glm::mat<L, C, T, Q>
const& aFirst, glm::mat<L, C, T, Q>
const& aSecond,
59 T aEpsilon =
static_cast<T
>( FLT_EPSILON * 10 ) )
61 T
const* first = glm::value_ptr( aFirst );
62 T
const* second = glm::value_ptr( aSecond );
64 for( glm::length_t j = 0; j < L *
C; ++j )
66 if( !
equals( first[j], second[j], aEpsilon ) )
79 m_capIsMoving( false ),
84 PutProfileHint( aProfileHint );
90 EnableNavigation(
false );
96 wxLogTrace(
m_logTrace, wxT(
"NL_3D_VIEWER_PLUGIN_IMPL::SetFocus %d" ), aFocus );
97 NAV_3D::Write( navlib::focus_k, aFocus );
109 EnableNavigation(
true);
110 PutFrameTimingSource(TimingSource::SpaceMouse);
125 using TDx::SpaceMouse::CCategory;
127 CATEGORY_STORE::iterator parent_iter = aCategoryStore.begin();
128 std::string::size_type pos = aCategoryPath.find_last_of(
'.' );
130 if( pos != std::string::npos )
132 std::string parentPath = aCategoryPath.substr( 0, pos );
133 parent_iter = aCategoryStore.find( parentPath );
135 if( parent_iter == aCategoryStore.end() )
137 parent_iter =
add_category( parentPath, aCategoryStore );
141 std::string
name = aCategoryPath.substr( pos + 1 );
142 std::unique_ptr<CCategory> categoryNode =
143 std::make_unique<CCategory>( aCategoryPath.c_str(),
name.c_str() );
145 CATEGORY_STORE::iterator iter = aCategoryStore.insert(
146 aCategoryStore.end(), CATEGORY_STORE::value_type( aCategoryPath, categoryNode.get() ) );
148 parent_iter->second->push_back( std::move( categoryNode ) );
155 wxLogTrace(
m_logTrace, wxT(
"NL_3D_VIEWER_PLUGIN_IMPL::exportCommandsAndImages" ) );
159 if( actions.size() == 0 )
164 using TDx::SpaceMouse::CCommand;
165 using TDx::SpaceMouse::CCommandSet;
168 CCommandSet commandSet(
"EDA_3D_CANVAS",
"3D Viewer" );
171 NAV_3D::PutActiveCommands( commandSet.GetId() );
176 std::vector<TDx::CImage> vImages;
179 categoryStore.insert( categoryStore.end(), CATEGORY_STORE::value_type(
".", &commandSet ) );
181 std::list<TOOL_ACTION*>::const_iterator it;
183 for( it = actions.begin(); it != actions.end(); ++it )
186 std::string label = action->
GetMenuLabel().ToStdString();
196 if(
name.rfind(
"pcbnew.", 0 ) == 0 )
202 CATEGORY_STORE::iterator iter = categoryStore.find( strCategory );
204 if( iter == categoryStore.end() )
206 iter =
add_category( std::move( strCategory ), categoryStore );
212 wxMemoryOutputStream imageStream;
214 if( action->
GetIcon() != BITMAPS::INVALID_BITMAP )
217 image.SaveFile( imageStream, wxBitmapType::wxBITMAP_TYPE_PNG );
220 if( imageStream.GetSize() )
222 wxStreamBuffer* streamBuffer = imageStream.GetOutputStreamBuffer();
223 TDx::CImage tdxImage = TDx::CImage::FromData(
"", 0,
name.c_str() );
224 tdxImage.AssignImage( std::string(
reinterpret_cast<const char*
>(
225 streamBuffer->GetBufferStart() ),
226 streamBuffer->GetBufferSize() ),
230 vImages.push_back( std::move( tdxImage ) );
234 wxLogTrace(
m_logTrace, wxT(
"Inserting command: %s, description: %s, in category: %s" ),
235 name, description, iter->first );
237 iter->second->push_back(
238 CCommand( std::move(
name ), std::move( label ), std::move( description ) ) );
241 NAV_3D::AddCommandSet( commandSet );
242 NAV_3D::AddImages( vImages );
252 std::copy_n( glm::value_ptr( glm::inverse(
m_cameraMatrix ) ), 16, matrix.m );
263 position = { origin.x, origin.y, origin.z };
273 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
278 double half_width = f.
fw / 2.;
279 double half_height = f.
fh / 2.;
280 extents = { -half_width, -half_height, f.
nearD, half_width, half_height, f.
farD };
290 aFov = glm::radians( f.
angle );
299 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
303 double half_width = f.
nw / 2.;
304 double half_height = f.
nh / 2.;
305 aFrustum = { -half_width, half_width, -half_height, half_height, f.
nearD, f.
farD };
323 glm::mat4 cam, viewMatrix;
324 std::copy_n( aCameraMatrix.m, 16, glm::value_ptr( cam ) );
325 viewMatrix = glm::inverse( cam );
338 glm::vec4 lookat_new = viewMatrix * lookat;
339 glm::vec4 lookat_old = camera * lookat;
341 viewMatrix[3].z += lookat_old.z - lookat_new.z;
356 return navlib::make_result_code( navlib::navlib_errc::error );
370 return navlib::make_result_code( navlib::navlib_errc::error );
381 float factor = f.
nw / ( extents.max_x - extents.min_x );
394 return navlib::make_result_code( navlib::navlib_errc::error );
403 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
409 return navlib::make_result_code( navlib::navlib_errc::permission_denied );
418 extents = { min.x, min.y, min.z, max.x, max.y, max.z };
426 return navlib::make_result_code( navlib::navlib_errc::no_data_available );
432 return navlib::make_result_code( navlib::navlib_errc::no_data_available );
446 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
454 position = { lap.x, lap.y, lap.z };
514 vec = mouseRay.
at( hit );
515 position = { vec.x, vec.y, vec.z };
519 return navlib::make_result_code( navlib::navlib_errc::no_data_available );
525 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
547 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
553 if( commandId.empty() )
561 for( std::list<TOOL_ACTION*>::const_iterator it = actions.begin(); it != actions.end(); it++ )
564 std::string nm = action->
GetName();
566 if( commandId == nm )
572 if( context !=
nullptr )
574 wxWindow* parent =
m_canvas->GetParent();
580 if( parent->IsEnabled() && ( tools_holder =
dynamic_cast<TOOLS_HOLDER*
>( parent ) ) )
584 if( tool_manager ==
nullptr )
586 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
592 bool runAction =
true;
597 runAction = aCond->enableCondition( sel );
608 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
638 wxLogTrace(
m_logTrace, wxT(
"End of transaction" ) );
647 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
653 matrix = { 1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1 };
661 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.
const BBOX_3D & GetBBox() const noexcept
Get the board outling bounding box.
const CAMERA_FRUSTUM & GetFrustum() const
PROJECTION_TYPE GetProjection()
const SFVEC3F & GetLookAtPos() const
void MakeRayAtCurrentMousePosition(SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
Make a ray based on the latest mouse position.
const glm::mat4 & GetViewMatrix() const
void SetLookAtPos_T1(const SFVEC3F &aLookAtPos)
void SetViewMatrix(glm::mat4 aViewMatrix)
Set the affine matrix to be applied to a transformation camera.
void Update()
Update the camera.
Implement a canvas based on a wxGLCanvas.
void Set3dmousePivotPos(const SFVEC3F &aPos)
Set the position of the the 3dmouse pivot.
bool GetRender3dmousePivot()
Get a value indicating whether to render the 3dmouse pivot.
void SetRender3dmousePivot(bool aValue)
Set aValue indicating whether to render the 3dmouse pivot.
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
const BOARD_ADAPTER & GetBoardAdapter() const
Get information used to display 3D board.
CAMERA * GetCamera()
Get the canvas camera.
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 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 ...
bool Intersect(const RAY &aRay, float *t) const
const SFVEC3F & Min() const
Return the minimum vertex pointer.
const SFVEC3F & Max() const
Return the maximum vertex pointer.
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
Declaration for a track ball camera.