diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index 8c8129803a..f5dda1f200 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -419,7 +419,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) SetCurItem( NULL ); Clear_Pcb( true ); GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) ); - Load_Module_From_Library( full_libraryfilename, NULL ); + Load_Module_From_Library( full_libraryfilename, true ); redraw = true; } diff --git a/pcbnew/modview.cpp b/pcbnew/modview.cpp index b7e517a344..839a5ad2f3 100644 --- a/pcbnew/modview.cpp +++ b/pcbnew/modview.cpp @@ -161,6 +161,7 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode ) GetBoard()->m_Modules.DeleteAll(); GetModuleLibrary( m_libraryName + wxT(".") + ModuleFileExtension, m_footprintName, true ); + Update3D_Frame(); } DisplayLibInfos(); diff --git a/pcbnew/modview_frame.cpp b/pcbnew/modview_frame.cpp index 08273a5ad6..ffa8ebc71b 100644 --- a/pcbnew/modview_frame.cpp +++ b/pcbnew/modview_frame.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include <3d_viewer.h> @@ -77,6 +78,7 @@ BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, EDA_DRAW_FRAME ) FOOTPRINT_VIEWER_FRAME::Process_Special_Functions ) EVT_TOOL( ID_MODVIEW_FOOTPRINT_EXPORT_TO_BOARD, FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint ) + EVT_TOOL( ID_MODVIEW_SHOW_3D_VIEW, FOOTPRINT_VIEWER_FRAME::Show3D_Frame ) /* listbox events */ EVT_LISTBOX( ID_MODVIEW_LIB_LIST, FOOTPRINT_VIEWER_FRAME::ClickOnLibList ) @@ -263,6 +265,8 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( wxWindow* parent, wxSemaphore* s FOOTPRINT_VIEWER_FRAME::~FOOTPRINT_VIEWER_FRAME() { + if( m_Draw3DFrame ) + m_Draw3DFrame->Destroy(); PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) GetParent(); frame->m_ModuleViewerFrame = NULL; } @@ -441,6 +445,7 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event ) DisplayLibInfos(); Zoom_Automatique( false ); m_canvas->Refresh(); + Update3D_Frame(); } } @@ -605,3 +610,46 @@ void FOOTPRINT_VIEWER_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition UpdateStatusBar(); /* Display new cursor coordinates */ } + + +void FOOTPRINT_VIEWER_FRAME::Show3D_Frame( wxCommandEvent& event ) +{ + if( m_Draw3DFrame ) + { + // Raising the window does not show the window on Windows if iconized. + // This should work on any platform. + if( m_Draw3DFrame->IsIconized() ) + m_Draw3DFrame->Iconize( false ); + + m_Draw3DFrame->Raise(); + + // Raising the window does not set the focus on Linux. This should work on any platform. + if( wxWindow::FindFocus() != m_Draw3DFrame ) + m_Draw3DFrame->SetFocus(); + + return; + } + + m_Draw3DFrame = new EDA_3D_FRAME( this, wxEmptyString ); + Update3D_Frame(); + m_Draw3DFrame->Show( true ); +} + +/** + * Function Update3D_Frame + * must be called after a footprint selection + * Updates the 3D view and 3D frame title. + */ +void FOOTPRINT_VIEWER_FRAME::Update3D_Frame() +{ + if( m_Draw3DFrame == NULL ) + return; + + wxString frm3Dtitle; + frm3Dtitle.Printf( _( "ModView: 3D Viewer [%s]" ), GetChars( m_footprintName ) ); + m_Draw3DFrame->SetTitle( frm3Dtitle ); + m_Draw3DFrame->ReloadRequest(); + // Force 3D screen refresh immediately + if( GetBoard()->m_Modules ) + m_Draw3DFrame->NewDisplay(); +} diff --git a/pcbnew/modview_frame.h b/pcbnew/modview_frame.h index f23a6c968c..98d4c72dc9 100644 --- a/pcbnew/modview_frame.h +++ b/pcbnew/modview_frame.h @@ -69,6 +69,10 @@ public: ~FOOTPRINT_VIEWER_FRAME(); + wxString& GetSelectedFootprint( void ) const { return m_selectedFootprintName; } + +private: + void OnSize( wxSizeEvent& event ); /** @@ -119,9 +123,7 @@ public: void SaveSettings(); wxString& GetFootprintName( void ) const { return m_footprintName; } - wxString& GetSelectedFootprint( void ) const { return m_selectedFootprintName; } -private: /** * Function OnActivate * is called when the frame frame is activate to reload the libraries and component lists @@ -149,6 +151,19 @@ private: bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ); + /** + * Function Show3D_Frame (virtual) + * displays 3D view of the footprint (module) being edited. + */ + void Show3D_Frame( wxCommandEvent& event ); + + /** + * Function Update3D_Frame + * must be called after a footprint selection + * Updates the 3D view and 3D frame title. + */ + void Update3D_Frame(); + /* * Virtual functions, not used here, but needed by PCB_BASE_FRAME * (virtual pure functions ) diff --git a/pcbnew/onleftclick.cpp b/pcbnew/onleftclick.cpp index 24ff3f233f..a6bb4035bc 100644 --- a/pcbnew/onleftclick.cpp +++ b/pcbnew/onleftclick.cpp @@ -362,7 +362,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) { m_canvas->MoveCursorToCrossHair(); - DrawStruct = (BOARD_ITEM*) Load_Module_From_Library( wxEmptyString, aDC ); + DrawStruct = (BOARD_ITEM*) Load_Module_From_Library( wxEmptyString, true, aDC ); SetCurItem( DrawStruct ); if( DrawStruct ) diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index ac3ce17e2f..e6b509c5a5 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -321,6 +321,7 @@ enum pcbnew_ids ID_MODVIEW_SELECT_PART, ID_MODVIEW_PREVIOUS, ID_MODVIEW_NEXT, + ID_MODVIEW_SHOW_3D_VIEW, ID_MODVIEW_FOOTPRINT_EXPORT_TO_BOARD }; diff --git a/pcbnew/tool_modview.cpp b/pcbnew/tool_modview.cpp index 5110a1c306..8318a10f05 100644 --- a/pcbnew/tool_modview.cpp +++ b/pcbnew/tool_modview.cpp @@ -66,6 +66,11 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar() KiBitmap( lib_next_xpm ), _( "Display next footprint" ) ); + m_mainToolBar->AddSeparator(); + m_mainToolBar->AddTool( ID_MODVIEW_SHOW_3D_VIEW, wxEmptyString, + KiBitmap( three_d_xpm ), + _( "Show footprint in 3D viewer" ) ); + m_mainToolBar->AddSeparator(); msg = AddHotkeyName( _( "Zoom in" ), g_Module_Editor_Hokeys_Descr, HK_ZOOM_IN, IS_COMMENT );