Browse Source
ADDED: Support for 3D Mouse in Footprint Properties 3D Model tab
ADDED: Support for 3D Mouse in Footprint Properties 3D Model tab
Fixed https://gitlab.com/kicad/code/kicad/issues/14002jobs
committed by
Seth Hillbrand
13 changed files with 451 additions and 24 deletions
-
23d-viewer/3d_navlib/CMakeLists.txt
-
93d-viewer/3d_navlib/nl_3d_viewer_plugin.cpp
-
43d-viewer/3d_navlib/nl_3d_viewer_plugin.h
-
313d-viewer/3d_navlib/nl_3d_viewer_plugin_impl.cpp
-
253d-viewer/3d_navlib/nl_3d_viewer_plugin_impl.h
-
453d-viewer/3d_navlib/nl_footprint_properties_plugin.cpp
-
623d-viewer/3d_navlib/nl_footprint_properties_plugin.h
-
1623d-viewer/3d_navlib/nl_footprint_properties_plugin_impl.cpp
-
683d-viewer/3d_navlib/nl_footprint_properties_plugin_impl.h
-
193d-viewer/dialogs/panel_preview_3d_model.cpp
-
63d-viewer/dialogs/panel_preview_3d_model.h
-
36pcbnew/dialogs/panel_fp_properties_3d_model.cpp
-
6pcbnew/dialogs/panel_fp_properties_3d_model.h
@ -0,0 +1,45 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 3Dconnexion |
|||
* Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* 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 <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
#include "nl_footprint_properties_plugin.h"
|
|||
#include "nl_footprint_properties_plugin_impl.h"
|
|||
#include <advanced_config.h>
|
|||
#include <kiplatform/drivers.h>
|
|||
|
|||
|
|||
NL_FOOTPRINT_PROPERTIES_PLUGIN::NL_FOOTPRINT_PROPERTIES_PLUGIN( EDA_3D_CANVAS* aViewport ) |
|||
{ |
|||
if( ADVANCED_CFG::GetCfg().m_Use3DConnexionDriver |
|||
&& KIPLATFORM::DRIVERS::Valid3DConnexionDriverVersion() ) |
|||
{ |
|||
m_impl = std::make_unique<NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL>( aViewport ); |
|||
m_impl->Connect(); |
|||
} |
|||
} |
|||
|
|||
|
|||
NL_FOOTPRINT_PROPERTIES_PLUGIN::~NL_FOOTPRINT_PROPERTIES_PLUGIN() = default; |
|||
|
|||
|
|||
void NL_FOOTPRINT_PROPERTIES_PLUGIN::SetFocus( bool focus ) |
|||
{ |
|||
if( m_impl ) |
|||
m_impl->SetFocus( focus ); |
|||
} |
|||
@ -0,0 +1,62 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 3Dconnexion |
|||
* Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* 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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
/** |
|||
* @file nl_footprint_properties_plugin.h |
|||
* @brief declaration of the nl_footprint_properties_plugin class |
|||
*/ |
|||
|
|||
#ifndef NL_FOOTPRINT_PROPERTIES_PLUGIN_H_ |
|||
#define NL_FOOTPRINT_PROPERTIES_PLUGIN_H_ |
|||
|
|||
#include <memory> |
|||
|
|||
// Forward declarations. |
|||
class EDA_3D_CANVAS; |
|||
class NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL; |
|||
|
|||
/** |
|||
* The class that implements the public interface to the SpaceMouse plug-in. |
|||
*/ |
|||
class NL_FOOTPRINT_PROPERTIES_PLUGIN |
|||
{ |
|||
public: |
|||
/** |
|||
* Initializes a new instance of the NL_FOOTPRINT_PROPERTIES_PLUGIN. |
|||
* |
|||
* @param aViewport is the viewport to be navigated. |
|||
*/ |
|||
NL_FOOTPRINT_PROPERTIES_PLUGIN( EDA_3D_CANVAS* aViewport ); |
|||
|
|||
virtual ~NL_FOOTPRINT_PROPERTIES_PLUGIN(); |
|||
|
|||
/** |
|||
* Set the connection to the 3Dconnexion driver to the focus state so that |
|||
* 3DMouse data is routed here. |
|||
* |
|||
* @param aFocus is true to set the connection active. |
|||
*/ |
|||
void SetFocus( bool aFocus = true ); |
|||
|
|||
private: |
|||
std::unique_ptr<NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL> m_impl; |
|||
}; |
|||
|
|||
#endif // NL_FOOTPRINT_PROPERTIES_PLUGIN_H_ |
|||
@ -0,0 +1,162 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 3Dconnexion |
|||
* Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* 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 <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
#include "nl_footprint_properties_plugin_impl.h"
|
|||
#include <3d-viewer/3d_canvas/eda_3d_canvas.h>
|
|||
|
|||
// KiCAD includes
|
|||
#include <tool/action_manager.h>
|
|||
#include <tool/tool_manager.h>
|
|||
#include <tool/tools_holder.h>
|
|||
|
|||
#include <wx/mstream.h>
|
|||
|
|||
#define BOUNDING_BOX_SCALE_FACTOR 1.3f
|
|||
|
|||
/**
|
|||
* Flag to enable the NL_FOOTPRINT_PROPERTIES_PLUGIN debug tracing. |
|||
* |
|||
* Use "KI_TRACE_NL_FOOTPRINT_PROPERTIES_PLUGIN" to enable. |
|||
* |
|||
* @ingroup trace_env_vars |
|||
*/ |
|||
const wxChar* NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL::m_logTrace = |
|||
wxT( "KI_TRACE_NL_FOOTPRINT_PROPERTIES_PLUGIN" ); |
|||
|
|||
|
|||
NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL::NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL(EDA_3D_CANVAS* aCanvas) : |
|||
NL_3D_VIEWER_PLUGIN_IMPL(aCanvas, "KiCAD Footprint Properties") |
|||
{} |
|||
|
|||
|
|||
long NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL::GetModelExtents( navlib::box_t& extents ) const |
|||
{ |
|||
SFVEC3F min = NL_3D_VIEWER_PLUGIN_IMPL::GetCanvas()->GetBoardAdapter().GetBBox().Min(); |
|||
SFVEC3F max = NL_3D_VIEWER_PLUGIN_IMPL::GetCanvas()->GetBoardAdapter().GetBBox().Max(); |
|||
|
|||
SFVEC3F diff = ( BOUNDING_BOX_SCALE_FACTOR - 1.f ) / 2.f * ( max - min ); |
|||
|
|||
min -= diff; |
|||
max += diff; |
|||
|
|||
extents = { min.x, min.y, min.z, max.x, max.y, max.z }; |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
void NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL::exportCommandsAndImages() |
|||
{ |
|||
std::list<TOOL_ACTION*> actions = ACTION_MANAGER::GetActionList(); |
|||
|
|||
if( actions.size() == 0 ) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
using TDx::SpaceMouse::CCommand; |
|||
using TDx::SpaceMouse::CCommandSet; |
|||
|
|||
// The root action set node
|
|||
CCommandSet commandSet( "EDA_3D_CANVAS", "3D Viewer" ); |
|||
|
|||
// Activate the command set
|
|||
NAV_3D::PutActiveCommands( commandSet.GetId() ); |
|||
|
|||
// temporary store for the categories
|
|||
CATEGORY_STORE categoryStore; |
|||
|
|||
std::vector<TDx::CImage> vImages; |
|||
|
|||
// add the action set to the category_store
|
|||
categoryStore.insert( categoryStore.end(), CATEGORY_STORE::value_type( ".", &commandSet ) ); |
|||
|
|||
std::list<TOOL_ACTION*>::const_iterator it; |
|||
|
|||
for( it = actions.begin(); it != actions.end(); ++it ) |
|||
{ |
|||
const TOOL_ACTION* action = *it; |
|||
std::string label = action->GetMenuLabel().ToStdString(); |
|||
|
|||
if( label.empty() ) |
|||
{ |
|||
continue; |
|||
} |
|||
|
|||
std::string name = action->GetName(); |
|||
|
|||
// Do no export commands for the pcbnew app.
|
|||
if( name.rfind( "pcbnew.", 0 ) == 0 ) |
|||
{ |
|||
continue; |
|||
} |
|||
|
|||
// Exclude commands which can't be used in the footprint properties.
|
|||
if( name.rfind( "3DViewer.Control.pivotCenter", 0 ) == 0 |
|||
|| name.rfind( "3DViewer.Control.material", 0 ) == 0 |
|||
|| name.rfind( "3DViewer.Control.attribute", 0 ) == 0 |
|||
|| name.rfind( "3DViewer.Control.show", 0 ) == 0 ) |
|||
{ |
|||
continue; |
|||
} |
|||
|
|||
std::string strCategory = action->GetToolName(); |
|||
CATEGORY_STORE::iterator iter = categoryStore.find( strCategory ); |
|||
|
|||
if( iter == categoryStore.end() ) |
|||
{ |
|||
iter = add_category( std::move( strCategory ), categoryStore ); |
|||
} |
|||
|
|||
std::string description = action->GetDescription().ToStdString(); |
|||
|
|||
// Arbitrary 8-bit data stream
|
|||
wxMemoryOutputStream imageStream; |
|||
|
|||
if( action->GetIcon() != BITMAPS::INVALID_BITMAP ) |
|||
{ |
|||
wxImage image = KiBitmap( action->GetIcon() ).ConvertToImage(); |
|||
image.SaveFile( imageStream, wxBitmapType::wxBITMAP_TYPE_PNG ); |
|||
image.Destroy(); |
|||
|
|||
if( imageStream.GetSize() ) |
|||
{ |
|||
wxStreamBuffer* streamBuffer = imageStream.GetOutputStreamBuffer(); |
|||
TDx::CImage tdxImage = TDx::CImage::FromData( "", 0, name.c_str() ); |
|||
tdxImage.AssignImage( std::string( reinterpret_cast<const char*>( |
|||
streamBuffer->GetBufferStart() ), |
|||
streamBuffer->GetBufferSize() ), |
|||
0 ); |
|||
|
|||
wxLogTrace( m_logTrace, wxT( "Adding image for : %s" ), name ); |
|||
vImages.push_back( std::move( tdxImage ) ); |
|||
} |
|||
} |
|||
|
|||
wxLogTrace( m_logTrace, wxT( "Inserting command: %s, description: %s, in category: %s" ), |
|||
name, description, iter->first ); |
|||
|
|||
iter->second->push_back( |
|||
CCommand( std::move( name ), std::move( label ), std::move( description ) ) ); |
|||
} |
|||
|
|||
NAV_3D::AddCommandSet( commandSet ); |
|||
NAV_3D::AddImages( vImages ); |
|||
} |
|||
@ -0,0 +1,68 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 3Dconnexion |
|||
* Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* 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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
/** |
|||
* @file nl_footprint_properties_plugin_impl.h |
|||
* @brief declaration of the nl_footprint_properties_plugin_impl class |
|||
*/ |
|||
|
|||
#ifndef NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL_H_ |
|||
#define NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL_H_ |
|||
|
|||
#include "nl_3d_viewer_plugin_impl.h" |
|||
// TDxWare SDK. |
|||
#include <SpaceMouse/CNavigation3D.hpp> |
|||
|
|||
/** |
|||
* The class that adjusts NL_3D_VIEWER_PLUGIN_IMPL implementation for 3D Model preview in footprint properties dialog. |
|||
*/ |
|||
class NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL : public NL_3D_VIEWER_PLUGIN_IMPL |
|||
{ |
|||
public: |
|||
/** |
|||
* Initializes a new instance of the NL_FOOTPRINT_PROPERTIES_PLUGIN. |
|||
* |
|||
* @param aCanvas is the viewport to be navigated. |
|||
*/ |
|||
NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL( EDA_3D_CANVAS* aCanvas ); |
|||
|
|||
private: |
|||
/** |
|||
* Get Footprint 3D Model extents. |
|||
* |
|||
* @param extents is the box around the 3D model. |
|||
*/ |
|||
long GetModelExtents( navlib::box_t& extents ) const override; |
|||
|
|||
/** |
|||
* Export the invocable actions and images to the 3Dconnexion UI. |
|||
*/ |
|||
void exportCommandsAndImages() override; |
|||
|
|||
private: |
|||
/** |
|||
* Trace mask used to enable or disable the trace output of this class. |
|||
* The debug output can be turned on by setting the WXTRACE environment variable to |
|||
* "KI_TRACE_NL_FOOTPRINT_PROPERTIES_PLUGIN". See the wxWidgets documentation on wxLogTrace for |
|||
* more information. |
|||
*/ |
|||
static const wxChar* m_logTrace; |
|||
}; |
|||
#endif // NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL_H_ |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue