diff --git a/common/worksheet_viewitem.cpp b/common/worksheet_viewitem.cpp index def1a81c92..15924033ab 100644 --- a/common/worksheet_viewitem.cpp +++ b/common/worksheet_viewitem.cpp @@ -37,8 +37,10 @@ using namespace KIGFX; -WORKSHEET_VIEWITEM::WORKSHEET_VIEWITEM( const PAGE_INFO* aPageInfo, const TITLE_BLOCK* aTitleBlock ) : +WORKSHEET_VIEWITEM::WORKSHEET_VIEWITEM( int aMils2IUscalefactor, + const PAGE_INFO* aPageInfo, const TITLE_BLOCK* aTitleBlock ) : EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type + m_mils2IUscalefactor( aMils2IUscalefactor ), m_titleBlock( aTitleBlock ), m_pageInfo( aPageInfo ), m_sheetNumber( 1 ), m_sheetCount( 1 ) {} @@ -61,8 +63,8 @@ const BOX2I WORKSHEET_VIEWITEM::ViewBBox() const if( m_pageInfo != NULL ) { bbox.SetOrigin( VECTOR2I( 0, 0 ) ); - bbox.SetEnd( VECTOR2I( m_pageInfo->GetWidthMils() * 25400, - m_pageInfo->GetHeightMils() * 25400 ) ); + bbox.SetEnd( VECTOR2I( m_pageInfo->GetWidthMils() * m_mils2IUscalefactor, + m_pageInfo->GetHeightMils() * m_mils2IUscalefactor ) ); } else { @@ -82,10 +84,10 @@ void WORKSHEET_VIEWITEM::ViewDraw( int aLayer, VIEW* aView ) const WS_DRAW_ITEM_LIST drawList; drawList.SetPenSize( settings->GetWorksheetLineWidth() ); - // Sorry, but I don't get this multi #ifdef from include/convert_to_biu.h, so here goes a magic - // number. IU_PER_MILS should be 25400 (as in a different compilation unit), but somehow - // it equals 1 in this case.. - drawList.SetMilsToIUfactor( 25400 /* IU_PER_MILS */ ); + // Adjust the scaling factor for worksheet items: + // worksheet items coordinates and sizes are stored in mils, + // and must be scaled to the same units as the caller + drawList.SetMilsToIUfactor( m_mils2IUscalefactor ); drawList.SetSheetNumber( m_sheetNumber ); drawList.SetSheetCount( m_sheetCount ); drawList.SetFileName( fileName ); diff --git a/gerbview/gerbview_draw_panel_gal.cpp b/gerbview/gerbview_draw_panel_gal.cpp index 033d2dd4a7..547e8b9a9d 100644 --- a/gerbview/gerbview_draw_panel_gal.cpp +++ b/gerbview/gerbview_draw_panel_gal.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -134,12 +135,20 @@ void GERBVIEW_DRAW_PANEL_GAL::setDefaultLayerDeps() m_view->SetLayerDisplayOnly( LAYER_GERBVIEW_GRID ); m_view->SetLayerDisplayOnly( LAYER_GERBVIEW_AXES ); m_view->SetLayerDisplayOnly( LAYER_GERBVIEW_BACKGROUND ); + m_view->SetLayerDisplayOnly( LAYER_WORKSHEET ); m_view->SetLayerTarget( LAYER_GP_OVERLAY, KIGFX::TARGET_OVERLAY ); m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ); } +void GERBVIEW_DRAW_PANEL_GAL::SetWorksheet( KIGFX::WORKSHEET_VIEWITEM* aWorksheet ) +{ + m_worksheet.reset( aWorksheet ); + m_view->Add( m_worksheet.get() ); +} + + void GERBVIEW_DRAW_PANEL_GAL::SetTopLayer( int aLayer ) { m_view->ClearTopLayers(); diff --git a/gerbview/gerbview_draw_panel_gal.h b/gerbview/gerbview_draw_panel_gal.h index c83def2596..4e9ea44bd6 100644 --- a/gerbview/gerbview_draw_panel_gal.h +++ b/gerbview/gerbview_draw_panel_gal.h @@ -21,6 +21,12 @@ #define GERBVIEW_DRAW_PANEL_GAL_H_ #include +#include + +namespace KIGFX +{ + class WORKSHEET_VIEWITEM; +} class COLORS_DESIGN_SETTINGS; @@ -55,9 +61,19 @@ public: ///> @copydoc EDA_DRAW_PANEL_GAL::SetTopLayer virtual void SetTopLayer( int aLayer ) override; + /** + * Sets (or updates) worksheet used by the draw panel. + * @param aWorksheet is the worksheet to be used. + * The object is then owned by GERBVIEW_DRAW_PANEL_GAL. + */ + void SetWorksheet( KIGFX::WORKSHEET_VIEWITEM* aWorksheet ); + protected: ///> Sets rendering targets & dependencies for layers. void setDefaultLayerDeps(); + + ///> Currently used worksheet + std::unique_ptr m_worksheet; }; diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index 26a147b734..813d7fda65 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -75,9 +75,6 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ): // obviously depends on the monitor, // but this is an acceptable value - PAGE_INFO pageInfo( wxT( "GERBER" ) ); - SetPageSettings( pageInfo ); - m_show_layer_manager_tools = true; m_showAxis = true; // true to show X and Y axis on screen @@ -400,8 +397,6 @@ void GERBVIEW_FRAME::LoadSettings( wxConfigBase* aCfg ) SetPageSettings( pageInfo ); - GetScreen()->InitDataPoints( pageInfo.GetSizeIU() ); - bool tmp; aCfg->Read( cfgShowDCodes, &tmp, true ); SetElementVisibility( LAYER_DCODES, tmp ); @@ -990,9 +985,29 @@ void GERBVIEW_FRAME::SetActiveLayer( int aLayer, bool doLayerWidgetUpdate ) void GERBVIEW_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings ) { m_paper = aPageSettings; + GBR_SCREEN* screen = static_cast( GetScreen() ); - if( GetScreen() ) - GetScreen()->InitDataPoints( aPageSettings.GetSizeIU() ); + if( screen ) + screen->InitDataPoints( aPageSettings.GetSizeIU() ); + + if( IsGalCanvasActive() ) + { + GERBVIEW_DRAW_PANEL_GAL* drawPanel = + static_cast( GetGalCanvas() ); + + // Prepare worksheet template + KIGFX::WORKSHEET_VIEWITEM* worksheet; + worksheet = new KIGFX::WORKSHEET_VIEWITEM( IU_PER_MILS, &GetPageSettings(), &GetTitleBlock() ); + + if( screen != NULL ) + { + worksheet->SetSheetNumber( 1 ); + worksheet->SetSheetCount( 1 ); + } + + // PCB_DRAW_PANEL_GAL takes ownership of the worksheet + drawPanel->SetWorksheet( worksheet ); + } } @@ -1219,6 +1234,8 @@ void GERBVIEW_FRAME::UseGalCanvas( bool aEnable ) galCanvas->GetGAL()->SetGridColor( GetLayerColor( LAYER_GERBVIEW_GRID ) ); + SetPageSettings( GetPageSettings() ); + galCanvas->GetView()->RecacheAllItems(); galCanvas->SetEventDispatcher( m_toolDispatcher ); galCanvas->StartDrawing(); diff --git a/gerbview/gerbview_painter.cpp b/gerbview/gerbview_painter.cpp index b2f91857c1..a91d186697 100644 --- a/gerbview/gerbview_painter.cpp +++ b/gerbview/gerbview_painter.cpp @@ -102,6 +102,9 @@ const COLOR4D& GERBVIEW_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int a if( IsDCodeLayer( aLayer ) ) return m_layerColors[ LAYER_DCODES ]; + if( aLayer == LAYER_WORKSHEET ) + return m_layerColors[ LAYER_WORKSHEET ]; + if( item ) { if( item->IsSelected() ) diff --git a/include/worksheet_viewitem.h b/include/worksheet_viewitem.h index efbb6d0133..2a6115e705 100644 --- a/include/worksheet_viewitem.h +++ b/include/worksheet_viewitem.h @@ -48,7 +48,8 @@ class GAL; class WORKSHEET_VIEWITEM : public EDA_ITEM { public: - WORKSHEET_VIEWITEM( const PAGE_INFO* aPageInfo, const TITLE_BLOCK* aTitleBlock ); + WORKSHEET_VIEWITEM( int aMils2IUscalefactor, + const PAGE_INFO* aPageInfo, const TITLE_BLOCK* aTitleBlock ); /** * Function SetFileName() @@ -135,6 +136,10 @@ public: } protected: + /// the factor between mils (units used in worksheet and internal units) + /// it is the value IU_PER_MILS used in the caller + int m_mils2IUscalefactor; + /// File name displayed in the title block std::string m_fileName; diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 0a51319f7d..133c1c516f 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -567,7 +567,7 @@ void PCB_EDIT_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings ) // Prepare worksheet template KIGFX::WORKSHEET_VIEWITEM* worksheet; - worksheet = new KIGFX::WORKSHEET_VIEWITEM( &m_Pcb->GetPageSettings(), + worksheet = new KIGFX::WORKSHEET_VIEWITEM( IU_PER_MILS ,&m_Pcb->GetPageSettings(), &m_Pcb->GetTitleBlock() ); worksheet->SetSheetName( std::string( GetScreenDesc().mb_str() ) );