diff --git a/3d-viewer/3d_navlib/CMakeLists.txt b/3d-viewer/3d_navlib/CMakeLists.txt index a6c4926264..060cf5c5b9 100644 --- a/3d-viewer/3d_navlib/CMakeLists.txt +++ b/3d-viewer/3d_navlib/CMakeLists.txt @@ -1,6 +1,8 @@ add_library(3d-viewer_navlib STATIC "nl_3d_viewer_plugin.cpp" "nl_3d_viewer_plugin_impl.cpp" + "nl_footprint_properties_plugin.cpp" + "nl_footprint_properties_plugin_impl.cpp" ) # 3d-viewer_navlib depends on make_lexer outputs in common diff --git a/3d-viewer/3d_navlib/nl_3d_viewer_plugin.cpp b/3d-viewer/3d_navlib/nl_3d_viewer_plugin.cpp index 1fa3e309eb..153d234ed9 100644 --- a/3d-viewer/3d_navlib/nl_3d_viewer_plugin.cpp +++ b/3d-viewer/3d_navlib/nl_3d_viewer_plugin.cpp @@ -25,20 +25,17 @@ NL_3D_VIEWER_PLUGIN::NL_3D_VIEWER_PLUGIN( EDA_3D_CANVAS* aViewport ) - : m_impl( nullptr ) { if( ADVANCED_CFG::GetCfg().m_Use3DConnexionDriver && KIPLATFORM::DRIVERS::Valid3DConnexionDriverVersion() ) { - m_impl = new NL_3D_VIEWER_PLUGIN_IMPL( aViewport ); + m_impl = std::make_unique( aViewport, "KiCAD 3D" ); + m_impl->Connect(); } } -NL_3D_VIEWER_PLUGIN::~NL_3D_VIEWER_PLUGIN() -{ - delete m_impl; -} +NL_3D_VIEWER_PLUGIN::~NL_3D_VIEWER_PLUGIN() = default; void NL_3D_VIEWER_PLUGIN::SetFocus( bool focus ) diff --git a/3d-viewer/3d_navlib/nl_3d_viewer_plugin.h b/3d-viewer/3d_navlib/nl_3d_viewer_plugin.h index 880c34a508..4a6153b16b 100644 --- a/3d-viewer/3d_navlib/nl_3d_viewer_plugin.h +++ b/3d-viewer/3d_navlib/nl_3d_viewer_plugin.h @@ -26,6 +26,8 @@ #ifndef NL_3D_VIEWER_PLUGIN_H_ #define NL_3D_VIEWER_PLUGIN_H_ +#include + // Forward declarations. class EDA_3D_CANVAS; class NL_3D_VIEWER_PLUGIN_IMPL; @@ -54,7 +56,7 @@ public: void SetFocus( bool aFocus = true ); private: - NL_3D_VIEWER_PLUGIN_IMPL* m_impl; + std::unique_ptr m_impl; }; #endif // NL_3D_VIEWER_PLUGIN_H_ diff --git a/3d-viewer/3d_navlib/nl_3d_viewer_plugin_impl.cpp b/3d-viewer/3d_navlib/nl_3d_viewer_plugin_impl.cpp index 3f17a76e56..722c7a246c 100644 --- a/3d-viewer/3d_navlib/nl_3d_viewer_plugin_impl.cpp +++ b/3d-viewer/3d_navlib/nl_3d_viewer_plugin_impl.cpp @@ -1,8 +1,8 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2021 3Dconnexion - * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * 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 @@ -27,6 +27,7 @@ // KiCAD includes #include #include +#include // stdlib #include @@ -72,7 +73,7 @@ bool equals( glm::mat const& aFirst, glm::mat const& aSe } -NL_3D_VIEWER_PLUGIN_IMPL::NL_3D_VIEWER_PLUGIN_IMPL( EDA_3D_CANVAS* aCanvas ) : +NL_3D_VIEWER_PLUGIN_IMPL::NL_3D_VIEWER_PLUGIN_IMPL( EDA_3D_CANVAS* aCanvas, const std::string& aProfileHint ) : NAV_3D( false, false ), m_canvas( aCanvas ), m_capIsMoving( false ), @@ -80,12 +81,7 @@ NL_3D_VIEWER_PLUGIN_IMPL::NL_3D_VIEWER_PLUGIN_IMPL( EDA_3D_CANVAS* aCanvas ) : { m_camera = dynamic_cast( m_canvas->GetCamera() ); - PutProfileHint( "KiCAD 3D" ); - - EnableNavigation( true ); - PutFrameTimingSource( TimingSource::SpaceMouse ); - - exportCommandsAndImages(); + PutProfileHint( aProfileHint ); } @@ -101,8 +97,19 @@ void NL_3D_VIEWER_PLUGIN_IMPL::SetFocus( bool aFocus ) NAV_3D::Write( navlib::focus_k, aFocus ); } -// temporary store for the categories -typedef std::map CATEGORY_STORE; + +EDA_3D_CANVAS* NL_3D_VIEWER_PLUGIN_IMPL::GetCanvas() const +{ + return m_canvas; +} + + +void NL_3D_VIEWER_PLUGIN_IMPL::Connect() +{ + EnableNavigation(true); + PutFrameTimingSource(TimingSource::SpaceMouse); + exportCommandsAndImages(); +} /** * Add a category to the store. @@ -571,7 +578,7 @@ long NL_3D_VIEWER_PLUGIN_IMPL::SetActiveCommand( std::string commandId ) if( parent->IsEnabled() ) { - TOOL_MANAGER* tool_manager = static_cast( parent )->GetToolManager(); + TOOL_MANAGER* tool_manager = dynamic_cast( parent )->GetToolManager(); if( tool_manager == nullptr ) { diff --git a/3d-viewer/3d_navlib/nl_3d_viewer_plugin_impl.h b/3d-viewer/3d_navlib/nl_3d_viewer_plugin_impl.h index 6ae6d23447..dc149f262b 100644 --- a/3d-viewer/3d_navlib/nl_3d_viewer_plugin_impl.h +++ b/3d-viewer/3d_navlib/nl_3d_viewer_plugin_impl.h @@ -1,8 +1,8 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2021 3Dconnexion - * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * 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 @@ -42,6 +42,11 @@ class EDA_3D_CANVAS; class TRACK_BALL; +// temporary store for the categories +typedef std::map CATEGORY_STORE; + +CATEGORY_STORE::iterator add_category( std::string aCategoryPath, CATEGORY_STORE& aCategoryStore ); + // Convenience typedef. typedef TDx::SpaceMouse::Navigation3D::CNavigation3D NAV_3D; @@ -56,8 +61,9 @@ public: * Initializes a new instance of the NL_3DVIEWER_PLUGIN. * * @param aCanvas is the viewport to be navigated. + * @param aProfileHint tells the 3DConnexion UI which profile to use. */ - NL_3D_VIEWER_PLUGIN_IMPL( EDA_3D_CANVAS* aCanvas ); + NL_3D_VIEWER_PLUGIN_IMPL( EDA_3D_CANVAS* aCanvas, const std::string& aProfileHint ); virtual ~NL_3D_VIEWER_PLUGIN_IMPL(); @@ -69,11 +75,21 @@ public: */ void SetFocus( bool aFocus = true ); + /** + * Get the m_canvas pointer. + */ + EDA_3D_CANVAS* GetCanvas() const; + + /** + * Connect plugin implementation to the driver. + */ + void Connect(); + private: /** * Export the invocable actions and images to the 3Dconnexion UI. */ - void exportCommandsAndImages(); + virtual void exportCommandsAndImages(); long GetCameraMatrix( navlib::matrix_t& aMatrix ) const override; long GetPointerPosition( navlib::point_t& aPosition ) const override; @@ -111,6 +127,7 @@ private: long GetCoordinateSystem( navlib::matrix_t& aMatrix ) const override; long GetIsViewRotatable( navlib::bool_t& isRotatable ) const override; + private: EDA_3D_CANVAS* m_canvas; TRACK_BALL* m_camera; diff --git a/3d-viewer/3d_navlib/nl_footprint_properties_plugin.cpp b/3d-viewer/3d_navlib/nl_footprint_properties_plugin.cpp new file mode 100644 index 0000000000..20f8e282a0 --- /dev/null +++ b/3d-viewer/3d_navlib/nl_footprint_properties_plugin.cpp @@ -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 . + */ + +#include "nl_footprint_properties_plugin.h" +#include "nl_footprint_properties_plugin_impl.h" +#include +#include + + +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( 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 ); +} diff --git a/3d-viewer/3d_navlib/nl_footprint_properties_plugin.h b/3d-viewer/3d_navlib/nl_footprint_properties_plugin.h new file mode 100644 index 0000000000..2995db189e --- /dev/null +++ b/3d-viewer/3d_navlib/nl_footprint_properties_plugin.h @@ -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 . + */ + +/** + * @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 + +// 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 m_impl; +}; + +#endif // NL_FOOTPRINT_PROPERTIES_PLUGIN_H_ diff --git a/3d-viewer/3d_navlib/nl_footprint_properties_plugin_impl.cpp b/3d-viewer/3d_navlib/nl_footprint_properties_plugin_impl.cpp new file mode 100644 index 0000000000..9516b0184e --- /dev/null +++ b/3d-viewer/3d_navlib/nl_footprint_properties_plugin_impl.cpp @@ -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 . + */ + +#include "nl_footprint_properties_plugin_impl.h" +#include <3d-viewer/3d_canvas/eda_3d_canvas.h> + +// KiCAD includes +#include +#include +#include + +#include + +#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 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 vImages; + + // add the action set to the category_store + categoryStore.insert( categoryStore.end(), CATEGORY_STORE::value_type( ".", &commandSet ) ); + + std::list::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( + 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 ); +} diff --git a/3d-viewer/3d_navlib/nl_footprint_properties_plugin_impl.h b/3d-viewer/3d_navlib/nl_footprint_properties_plugin_impl.h new file mode 100644 index 0000000000..2dba1c4a8d --- /dev/null +++ b/3d-viewer/3d_navlib/nl_footprint_properties_plugin_impl.h @@ -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 . + */ + +/** + * @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 + +/** + * 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_ diff --git a/3d-viewer/dialogs/panel_preview_3d_model.cpp b/3d-viewer/dialogs/panel_preview_3d_model.cpp index 0c3389e0b6..a980920c96 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.cpp +++ b/3d-viewer/dialogs/panel_preview_3d_model.cpp @@ -45,6 +45,8 @@ #include #include +#include <3d_navlib/nl_footprint_properties_plugin.h> + PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAME* aFrame, FOOTPRINT* aFootprint, std::vector* aParentModelList ) : @@ -127,6 +129,9 @@ PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAM m_boardAdapter, m_currentCamera, PROJECT_PCB::Get3DCacheManager( &aFrame->Prj() ) ); + m_spaceMouse = new NL_FOOTPRINT_PROPERTIES_PLUGIN( m_previewPane ); + m_spaceMouse->SetFocus( true ); + m_boardAdapter.SetBoard( m_dummyBoard ); m_boardAdapter.m_IsBoardView = false; m_boardAdapter.m_IsPreviewer = true; // Force display 3D models, regardless the 3D viewer options @@ -163,6 +168,8 @@ PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAM aFrame->Connect( EDA_EVT_UNITS_CHANGED, wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL::onUnitsChanged ), nullptr, this ); + + Bind( wxCUSTOM_PANEL_SHOWN_EVENT, &PANEL_PREVIEW_3D_MODEL::onPanelShownEvent, this ); } @@ -172,6 +179,7 @@ PANEL_PREVIEW_3D_MODEL::~PANEL_PREVIEW_3D_MODEL() if( m_boardAdapter.m_Cfg ) m_boardAdapter.m_Cfg->m_Render = m_initialRender; + delete m_spaceMouse; delete m_dummyBoard; delete m_previewPane; } @@ -610,6 +618,17 @@ void PANEL_PREVIEW_3D_MODEL::onUnitsChanged( wxCommandEvent& aEvent ) } +void PANEL_PREVIEW_3D_MODEL::onPanelShownEvent( wxCommandEvent& aEvent ) +{ + if( m_spaceMouse != nullptr ) + { + m_spaceMouse->SetFocus( static_cast( aEvent.GetInt() ) ); + } + + aEvent.Skip(); +} + + void PANEL_PREVIEW_3D_MODEL::UpdateDummyFootprint( bool aReloadRequired ) { m_dummyFootprint->Models().clear(); diff --git a/3d-viewer/dialogs/panel_preview_3d_model.h b/3d-viewer/dialogs/panel_preview_3d_model.h index b60a56143c..e100de1f9d 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.h +++ b/3d-viewer/dialogs/panel_preview_3d_model.h @@ -34,6 +34,7 @@ #include <3d_canvas/eda_3d_canvas.h> #include <3d_viewer_id.h> #include <3d_rendering/track_ball.h> +#include // Define min and max parameter values #define MAX_SCALE 10000.0 @@ -52,6 +53,7 @@ #define OFFSET_INCREMENT_MIL 25.0 #define OFFSET_INCREMENT_MIL_FINE 5.0 +wxDECLARE_EVENT( wxCUSTOM_PANEL_SHOWN_EVENT, wxCommandEvent ); // Declared classes to create pointers class WX_INFOBAR; @@ -60,6 +62,7 @@ class FILENAME_RESOLVER; class BOARD; class BOARD_ADAPTER; class FOOTPRINT; +class NL_FOOTPRINT_PROPERTIES_PLUGIN; class PANEL_PREVIEW_3D_MODEL: public EDA_3D_BOARD_HOLDER, public TOOLS_HOLDER, public PANEL_PREVIEW_3D_MODEL_BASE { @@ -139,6 +142,7 @@ private: void doIncrementOffset( wxSpinEvent& aEvent, double aSign ); void onUnitsChanged( wxCommandEvent& aEvent ); + void onPanelShownEvent( wxCommandEvent& aEvent ); wxString formatScaleValue( double aValue ); wxString formatRotationValue( double aValue ); @@ -211,6 +215,8 @@ private: bool m_bodyStyleShowAll; /// true if the board body is show /// The 3d viewer Render initial settings (must be saved and restored) EDA_3D_VIEWER_SETTINGS::RENDER_SETTINGS m_initialRender; + + NL_FOOTPRINT_PROPERTIES_PLUGIN* m_spaceMouse; }; #endif // PANEL_PREVIEW_3D_MODEL_H diff --git a/pcbnew/dialogs/panel_fp_properties_3d_model.cpp b/pcbnew/dialogs/panel_fp_properties_3d_model.cpp index 336e3b2e69..838682cbae 100644 --- a/pcbnew/dialogs/panel_fp_properties_3d_model.cpp +++ b/pcbnew/dialogs/panel_fp_properties_3d_model.cpp @@ -54,6 +54,8 @@ enum MODELS_TABLE_COLUMNS COL_SHOWN = 2 }; +wxDEFINE_EVENT( wxCUSTOM_PANEL_SHOWN_EVENT, wxCommandEvent ); + PANEL_FP_PROPERTIES_3D_MODEL::PANEL_FP_PROPERTIES_3D_MODEL( PCB_BASE_EDIT_FRAME* aFrame, FOOTPRINT* aFootprint, DIALOG_SHIM* aDialogParent, @@ -117,6 +119,10 @@ PANEL_FP_PROPERTIES_3D_MODEL::PANEL_FP_PROPERTIES_3D_MODEL( PCB_BASE_EDIT_FRAME* m_button3DShapeAdd->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) ); m_button3DShapeBrowse->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) ); m_button3DShapeRemove->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) ); + + Bind( wxEVT_SHOW, &PANEL_FP_PROPERTIES_3D_MODEL::onShowEvent, this ); + m_parentDialog->Bind( wxEVT_ACTIVATE, &PANEL_FP_PROPERTIES_3D_MODEL::onDialogActivateEvent, + this ); } @@ -125,6 +131,9 @@ PANEL_FP_PROPERTIES_3D_MODEL::~PANEL_FP_PROPERTIES_3D_MODEL() // Delete the GRID_TRICKS. m_modelsGrid->PopEventHandler( true ); + // Unbind OnShowEvent to prevent unnecessary event handling. + Unbind( wxEVT_SHOW, &PANEL_FP_PROPERTIES_3D_MODEL::onShowEvent, this ); + // free the memory used by all models, otherwise models which were // browsed but not used would consume memory PROJECT_PCB::Get3DCacheManager( &m_frame->Prj() )->FlushCache( false ); @@ -139,6 +148,7 @@ bool PANEL_FP_PROPERTIES_3D_MODEL::TransferDataToWindow() return true; } + bool PANEL_FP_PROPERTIES_3D_MODEL::TransferDataFromWindow() { // Only commit changes in the editor, not the models @@ -510,3 +520,27 @@ void PANEL_FP_PROPERTIES_3D_MODEL::OnUpdateUI( wxUpdateUIEvent& event ) { m_button3DShapeRemove->Enable( m_modelsGrid->GetNumberRows() > 0 ); } + + +void PANEL_FP_PROPERTIES_3D_MODEL::onShowEvent( wxShowEvent& aEvent ) +{ + postCustomPanelShownEventWithPredicate( static_cast( aEvent.IsShown() ) ); + aEvent.Skip(); +} + + +void PANEL_FP_PROPERTIES_3D_MODEL::onDialogActivateEvent( wxActivateEvent& aEvent ) +{ + postCustomPanelShownEventWithPredicate( aEvent.GetActive() + && m_previewPane->IsShownOnScreen() ); + aEvent.Skip(); +} + + +void PANEL_FP_PROPERTIES_3D_MODEL::postCustomPanelShownEventWithPredicate( bool predicate ) +{ + wxCommandEvent event( wxCUSTOM_PANEL_SHOWN_EVENT ); + event.SetEventObject( m_previewPane ); + event.SetInt( static_cast( predicate ) ); + m_previewPane->ProcessWindowEvent( event ); +} diff --git a/pcbnew/dialogs/panel_fp_properties_3d_model.h b/pcbnew/dialogs/panel_fp_properties_3d_model.h index be163c85fc..0afe10449a 100644 --- a/pcbnew/dialogs/panel_fp_properties_3d_model.h +++ b/pcbnew/dialogs/panel_fp_properties_3d_model.h @@ -86,6 +86,13 @@ private: void select3DModel( int aModelIdx ); + virtual void onDialogActivateEvent( wxActivateEvent& aEvent ); + virtual void onShowEvent( wxShowEvent& aEvent ); + + // Wrapper on creating and posting custom event + void postCustomPanelShownEventWithPredicate( bool predicate ); + + private: DIALOG_SHIM* m_parentDialog; PCB_BASE_EDIT_FRAME* m_frame;