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 ) )
77 const std::string& aProfileHint ) :
80 m_capIsMoving( false ),
85 PutProfileHint( aProfileHint );
91 EnableNavigation(
false );
97 wxLogTrace(
m_logTrace, wxT(
"NL_3D_VIEWER_PLUGIN_IMPL::SetFocus %d" ), aFocus );
98 NAV_3D::Write( navlib::focus_k, aFocus );
110 EnableNavigation(
true);
111 PutFrameTimingSource(TimingSource::SpaceMouse);
118 using TDx::SpaceMouse::CCategory;
120 CATEGORY_STORE::iterator parent_iter = aCategoryStore.begin();
121 std::string::size_type pos = aCategoryPath.find_last_of(
'.' );
123 if( pos != std::string::npos )
125 std::string parentPath = aCategoryPath.substr( 0, pos );
126 parent_iter = aCategoryStore.find( parentPath );
128 if( parent_iter == aCategoryStore.end() )
130 parent_iter =
add_category( parentPath, aCategoryStore );
134 std::string
name = aCategoryPath.substr( pos + 1 );
135 std::unique_ptr<CCategory> categoryNode =
136 std::make_unique<CCategory>( aCategoryPath.c_str(),
name.c_str() );
138 CATEGORY_STORE::iterator iter = aCategoryStore.insert(
139 aCategoryStore.end(), CATEGORY_STORE::value_type( aCategoryPath, categoryNode.get() ) );
141 parent_iter->second->push_back( std::move( categoryNode ) );
148 wxLogTrace(
m_logTrace, wxT(
"NL_3D_VIEWER_PLUGIN_IMPL::exportCommandsAndImages" ) );
152 if( actions.size() == 0 )
157 using TDx::SpaceMouse::CCommand;
158 using TDx::SpaceMouse::CCommandSet;
161 CCommandSet commandSet(
"EDA_3D_CANVAS",
"3D Viewer" );
164 NAV_3D::PutActiveCommands( commandSet.GetId() );
169 std::vector<TDx::CImage> vImages;
172 categoryStore.insert( categoryStore.end(), CATEGORY_STORE::value_type(
".", &commandSet ) );
174 std::list<TOOL_ACTION*>::const_iterator it;
176 for( it = actions.begin(); it != actions.end(); ++it )
179 std::string label = action->
GetMenuLabel().ToStdString();
189 if(
name.rfind(
"pcbnew.", 0 ) == 0 )
195 CATEGORY_STORE::iterator iter = categoryStore.find( strCategory );
197 if( iter == categoryStore.end() )
199 iter =
add_category( std::move( strCategory ), categoryStore );
205 wxMemoryOutputStream imageStream;
207 if( action->
GetIcon() != BITMAPS::INVALID_BITMAP )
210 image.SaveFile( imageStream, wxBitmapType::wxBITMAP_TYPE_PNG );
213 if( imageStream.GetSize() )
215 wxStreamBuffer* streamBuffer = imageStream.GetOutputStreamBuffer();
216 TDx::CImage tdxImage = TDx::CImage::FromData(
"", 0,
name.c_str() );
217 tdxImage.AssignImage( std::string(
reinterpret_cast<const char*
>(
218 streamBuffer->GetBufferStart() ),
219 streamBuffer->GetBufferSize() ),
223 vImages.push_back( std::move( tdxImage ) );
227 wxLogTrace(
m_logTrace, wxT(
"Inserting command: %s, description: %s, in category: %s" ),
228 name, description, iter->first );
230 iter->second->push_back(
231 CCommand( std::move(
name ), std::move( label ), std::move( description ) ) );
234 NAV_3D::AddCommandSet( commandSet );
235 NAV_3D::AddImages( vImages );
245 std::copy_n( glm::value_ptr( glm::inverse(
m_cameraMatrix ) ), 16, matrix.m );
256 position = { origin.x, origin.y, origin.z };
266 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
271 double half_width = f.
fw / 2.;
272 double half_height = f.
fh / 2.;
273 extents = { -half_width, -half_height, f.
nearD, half_width, half_height, f.
farD };
283 aFov = glm::radians( f.
angle );
292 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
296 double half_width = f.
nw / 2.;
297 double half_height = f.
nh / 2.;
298 aFrustum = { -half_width, half_width, -half_height, half_height, f.
nearD, f.
farD };
316 glm::mat4 cam, viewMatrix;
317 std::copy_n( aCameraMatrix.m, 16, glm::value_ptr( cam ) );
318 viewMatrix = glm::inverse( cam );
331 glm::vec4 lookat_new = viewMatrix * lookat;
332 glm::vec4 lookat_old = camera * lookat;
334 viewMatrix[3].z += lookat_old.z - lookat_new.z;
349 return navlib::make_result_code( navlib::navlib_errc::error );
363 return navlib::make_result_code( navlib::navlib_errc::error );
374 float factor = f.
nw / ( extents.max_x - extents.min_x );
387 return navlib::make_result_code( navlib::navlib_errc::error );
396 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
402 return navlib::make_result_code( navlib::navlib_errc::permission_denied );
411 extents = { min.x, min.y, min.z, max.x, max.y, max.z };
419 return navlib::make_result_code( navlib::navlib_errc::no_data_available );
425 return navlib::make_result_code( navlib::navlib_errc::no_data_available );
439 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
447 position = { lap.x, lap.y, lap.z };
507 vec = mouseRay.
at( hit );
508 position = { vec.x, vec.y, vec.z };
512 return navlib::make_result_code( navlib::navlib_errc::no_data_available );
518 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
540 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
546 if( commandId.empty() )
554 for( std::list<TOOL_ACTION*>::const_iterator it = actions.begin(); it != actions.end(); it++ )
557 std::string nm = action->
GetName();
559 if( commandId == nm )
565 if( context !=
nullptr )
567 wxWindow* parent =
m_canvas->GetParent();
573 if( parent->IsEnabled() && ( tools_holder =
dynamic_cast<TOOLS_HOLDER*
>( parent ) ) )
577 if( tool_manager ==
nullptr )
579 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
585 bool runAction =
true;
590 runAction = aCond->enableCondition( sel );
601 return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
631 wxLogTrace(
m_logTrace, wxT(
"End of transaction" ) );
640 return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
646 matrix = { 1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1 };
654 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 outline 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.