From cc733a49664b016909f7717138bd72d17844eceb Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 9 Jul 2014 11:22:42 +0200 Subject: [PATCH] Initial version of GAL-based module viewer in pcbnew. --- pcbnew/class_module.cpp | 8 +++++-- pcbnew/modview_frame.cpp | 43 +++++++++++++++++++++++++++++++++++ pcbnew/modview_frame.h | 3 +++ pcbnew/pcb_draw_panel_gal.cpp | 12 ++++++++-- pcbnew/pcb_draw_panel_gal.h | 8 +++++++ 5 files changed, 70 insertions(+), 4 deletions(-) diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 0e3f015d39..bc01aa1bcb 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -448,8 +448,12 @@ const EDA_RECT MODULE::GetBoundingBox() const // Add the Clearance shape size: (shape around the pads when the // clearance is shown. Not optimized, but the draw cost is small // (perhaps smaller than optimization). - int biggest_clearance = GetBoard()->GetDesignSettings().GetBiggestClearanceValue(); - area.Inflate( biggest_clearance ); + BOARD* board = GetBoard(); + if( board ) + { + int biggest_clearance = board->GetDesignSettings().GetBiggestClearanceValue(); + area.Inflate( biggest_clearance ); + } return area; } diff --git a/pcbnew/modview_frame.cpp b/pcbnew/modview_frame.cpp index 1f80fe663e..9a762e5377 100644 --- a/pcbnew/modview_frame.cpp +++ b/pcbnew/modview_frame.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include <3d_viewer.h> #include @@ -54,6 +55,8 @@ #include #include +#include + #define NEXT_PART 1 #define NEW_PART 0 @@ -141,7 +144,14 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent m_footprintList = new wxListBox( this, ID_MODVIEW_FOOTPRINT_LIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL ); + // Create GAL canvas + EDA_DRAW_FRAME* drawFrame = static_cast( aParent ); + PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize, + drawFrame->GetGalCanvas()->GetBackend() ); + SetGalCanvas( drawPanel ); + SetBoard( new BOARD() ); + drawPanel->DisplayBoard( m_Pcb ); // Ensure all layers and items are visible: GetBoard()->SetVisibleAlls(); @@ -207,6 +217,8 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent // Manage the draw panel, right pane. m_auimgr.AddPane( m_canvas, wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() ); + m_auimgr.AddPane( (wxWindow*) GetGalCanvas(), + wxAuiPaneInfo().Name( wxT( "DrawFrameGal" ) ).CentrePane().Hide() ); // Manage the message panel, bottom pane. m_auimgr.AddPane( m_messagePanel, @@ -244,6 +256,8 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent #endif Show( true ); + + UseGalCanvas( drawFrame->IsGalCanvasActive() ); } @@ -421,6 +435,22 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event ) } UpdateTitle(); + + if( IsGalCanvasActive() ) + { + KIGFX::VIEW* view = GetGalCanvas()->GetView(); + view->Clear(); + + // Load modules and its additional elements + for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() ) + { + module->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) ); + view->Add( module ); + } + +// view->Add( loadFootprint( id ) ); + } + Zoom_Automatique( false ); m_canvas->Refresh(); Update3D_Frame(); @@ -827,3 +857,16 @@ void FOOTPRINT_VIEWER_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) if( module ) SetMsgPanel( module ); } + + +void FOOTPRINT_VIEWER_FRAME::UseGalCanvas( bool aEnable ) +{ + EDA_DRAW_FRAME::UseGalCanvas( aEnable ); + + if( aEnable ) + { + SetBoard( m_Pcb ); + + GetGalCanvas()->StartDrawing(); + } +} diff --git a/pcbnew/modview_frame.h b/pcbnew/modview_frame.h index aaa04afaf7..0301cfd52f 100644 --- a/pcbnew/modview_frame.h +++ b/pcbnew/modview_frame.h @@ -170,6 +170,9 @@ private: void SaveCopyInUndoList( BOARD_ITEM*, UNDO_REDO_T, const wxPoint& ) {} void SaveCopyInUndoList( const PICKED_ITEMS_LIST&, UNDO_REDO_T, const wxPoint &) {} + ///> @copydoc EDA_DRAW_FRAME::UseGalCanvas() + virtual void UseGalCanvas( bool aEnable ); + DECLARE_EVENT_TABLE() }; diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp index 778570b1e5..2c60634453 100644 --- a/pcbnew/pcb_draw_panel_gal.cpp +++ b/pcbnew/pcb_draw_panel_gal.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -210,8 +211,7 @@ void PCB_DRAW_PANEL_GAL::DisplayBoard( const BOARD* aBoard ) m_ratsnest = new KIGFX::RATSNEST_VIEWITEM( aBoard->GetRatsnest() ); m_view->Add( m_ratsnest ); - // Load layer color setup from PCB data - static_cast( m_view->GetPainter()->GetSettings() )->ImportLegacyColors( aBoard->GetColorsSettings() ); + UseColorScheme( aBoard->GetColorsSettings() ); m_view->RecacheAllItems( true ); } @@ -233,6 +233,14 @@ void PCB_DRAW_PANEL_GAL::SetWorksheet( KIGFX::WORKSHEET_VIEWITEM* aWorksheet ) } +void PCB_DRAW_PANEL_GAL::UseColorScheme( const COLORS_DESIGN_SETTINGS* aSettings ) +{ + KIGFX::PCB_RENDER_SETTINGS* rs; + rs = static_cast( m_view->GetPainter()->GetSettings() ); + rs->ImportLegacyColors( aSettings ); +} + + void PCB_DRAW_PANEL_GAL::SetHighContrastLayer( LAYER_ID aLayer ) { // Set display settings for high contrast mode diff --git a/pcbnew/pcb_draw_panel_gal.h b/pcbnew/pcb_draw_panel_gal.h index 9682b21f13..fa32cde04a 100644 --- a/pcbnew/pcb_draw_panel_gal.h +++ b/pcbnew/pcb_draw_panel_gal.h @@ -32,6 +32,7 @@ namespace KIGFX class WORKSHEET_VIEWITEM; class RATSNEST_VIEWITEM; } +class COLORS_DESIGN_SETTINGS; class PCB_DRAW_PANEL_GAL : public EDA_DRAW_PANEL_GAL { @@ -56,6 +57,13 @@ public: */ void SetWorksheet( KIGFX::WORKSHEET_VIEWITEM* aWorksheet ); + /** + * Function UseColorScheme + * Applies layer color settings. + * @param aSettings are the new settings. + */ + void UseColorScheme( const COLORS_DESIGN_SETTINGS* aSettings ); + ///> @copydoc EDA_DRAW_PANEL_GAL::SetHighContrastLayer() virtual void SetHighContrastLayer( LAYER_ID aLayer );