Commit a8212727 authored by jean-pierre charras's avatar jean-pierre charras

Gerbview: fix scaling error in x.6 file format. Minor cleaning code.

Better separation between Pcbnew code and Gerber code.
Update export to Pcb code (uses now the version 4  kicad_pcb file format).
parent c5e14ef1
...@@ -50,12 +50,13 @@ set( GERBVIEW_SRCS ...@@ -50,12 +50,13 @@ set( GERBVIEW_SRCS
gerbview_config.cpp gerbview_config.cpp
gerbview_frame.cpp gerbview_frame.cpp
hotkeys.cpp hotkeys.cpp
initpcb.cpp init_gbr_drawlayers.cpp
locate.cpp locate.cpp
menubar.cpp menubar.cpp
onleftclick.cpp onleftclick.cpp
onrightclick.cpp onrightclick.cpp
pcbplot.cpp pcbplot.cpp
printout_control.cpp
readgerb.cpp readgerb.cpp
rs274_read_XY_and_IJ_coordinates.cpp rs274_read_XY_and_IJ_coordinates.cpp
rs274d.cpp rs274d.cpp
...@@ -71,7 +72,6 @@ set( GERBVIEW_EXTRA_SRCS ...@@ -71,7 +72,6 @@ set( GERBVIEW_EXTRA_SRCS
../common/class_layer_box_selector.cpp ../common/class_layer_box_selector.cpp
../common/class_page_info.cpp ../common/class_page_info.cpp
../pcbnew/layer_widget.cpp ../pcbnew/layer_widget.cpp
../pcbnew/printout_controler.cpp
) )
if( MINGW ) if( MINGW )
......
...@@ -7,8 +7,12 @@ ...@@ -7,8 +7,12 @@
#include <gerbview_frame.h> #include <gerbview_frame.h>
#include <select_layers_to_pcb.h> #include <select_layers_to_pcb.h>
#define NB_PCB_LAYERS LAYER_ID_COUNT
#define FIRST_COPPER_LAYER 0
#define LAST_COPPER_LAYER 31
// Exported function // Exported function
const wxString GetPCBDefaultLayerName( int aLayerNumber ); const wxString GetPCBDefaultLayerName( int aLayerId );
enum layer_sel_id { enum layer_sel_id {
...@@ -21,9 +25,8 @@ enum layer_sel_id { ...@@ -21,9 +25,8 @@ enum layer_sel_id {
class SELECT_LAYER_DIALOG : public wxDialog class SELECT_LAYER_DIALOG : public wxDialog
{ {
private: private:
GERBVIEW_FRAME* m_Parent; wxRadioBox* m_layerList;
wxRadioBox* m_LayerList; std::vector <int> m_layerId;
int m_LayerId[int(GERBER_DRAWLAYERS_COUNT) + 1]; // One extra element for "(Deselect)" radiobutton
public: public:
// Constructor and destructor // Constructor and destructor
...@@ -64,12 +67,11 @@ END_EVENT_TABLE() ...@@ -64,12 +67,11 @@ END_EVENT_TABLE()
int GERBVIEW_FRAME::SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount, int GERBVIEW_FRAME::SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount,
bool aShowDeselectOption ) bool aShowDeselectOption )
{ {
int layer;
SELECT_LAYER_DIALOG* frame = new SELECT_LAYER_DIALOG( this, aDefaultLayer, SELECT_LAYER_DIALOG* frame = new SELECT_LAYER_DIALOG( this, aDefaultLayer,
aCopperLayerCount, aCopperLayerCount,
aShowDeselectOption ); aShowDeselectOption );
layer = frame->ShowModal(); int layer = frame->ShowModal();
frame->Destroy(); frame->Destroy();
return layer; return layer;
} }
...@@ -88,85 +90,73 @@ SELECT_LAYER_DIALOG::SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent, ...@@ -88,85 +90,73 @@ SELECT_LAYER_DIALOG::SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent,
wxSize( 470, 250 ), wxSize( 470, 250 ),
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ) wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
{ {
#define NB_PCB_LAYERS 64 wxButton* button;
#define FIRST_COPPER_LAYER 0
#define LAST_COPPER_LAYER 31
wxButton* Button;
int ii; int ii;
wxString LayerList[NB_PCB_LAYERS + 1]; // One extra element for "(Deselect)" wxArrayString layerList;
// radiobutton int layerSelect = -1;
int LayerCount, LayerSelect = -1;
m_Parent = parent;
// Build the layer list; first build copper layers list // Build the layer list; first build copper layers list
LayerCount = 0; int layerCount = 0;
for( ii = FIRST_COPPER_LAYER; ii <= LAST_COPPER_LAYER; ++ii ) for( ii = FIRST_COPPER_LAYER; ii <= LAST_COPPER_LAYER; ++ii )
{ {
m_LayerId[ii] = 0;
if( ii == FIRST_COPPER_LAYER || ii == LAST_COPPER_LAYER || ii < aCopperLayerCount-1 ) if( ii == FIRST_COPPER_LAYER || ii == LAST_COPPER_LAYER || ii < aCopperLayerCount-1 )
{ {
LayerList[LayerCount] = GetPCBDefaultLayerName( ii ); layerList.Add( GetPCBDefaultLayerName( ii ) );
if( ii == aDefaultLayer ) if( ii == aDefaultLayer )
LayerSelect = LayerCount; layerSelect = layerCount;
m_LayerId[LayerCount] = ii; m_layerId.push_back( ii );
LayerCount++; layerCount++;
} }
} }
// Build the layer list; build non copper layers list // Build the layer list; build non copper layers list
for( ; ii < NB_PCB_LAYERS; ++ii ) for( ; ii < NB_PCB_LAYERS; ++ii )
{ {
m_LayerId[ii] = 0; layerList.Add( GetPCBDefaultLayerName( ii ) );
LayerList[LayerCount] = GetPCBDefaultLayerName( ii );
if( ii == aDefaultLayer ) if( ii == aDefaultLayer )
LayerSelect = LayerCount; layerSelect = layerCount;
m_LayerId[LayerCount] = ii; m_layerId.push_back( ii );
LayerCount++; layerCount++;
} }
// When appropriate, also provide a "(Deselect)" radiobutton // When appropriate, also provide a "(Deselect)" radiobutton
if( aShowDeselectOption ) if( aShowDeselectOption )
{ {
LayerList[LayerCount] = _( "(Deselect)" ); layerList.Add( _( "Do not export" ) );
if( NB_PCB_LAYERS == aDefaultLayer ) if( UNSELECTED_LAYER == aDefaultLayer )
LayerSelect = LayerCount; layerSelect = layerCount;
m_LayerId[LayerCount] = NB_PCB_LAYERS; m_layerId.push_back( UNSELECTED_LAYER );
LayerCount++; layerCount++;
} }
m_LayerList = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ), m_layerList = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ),
wxPoint( -1, -1 ), wxSize( -1, -1 ), wxPoint( -1, -1 ), wxSize( -1, -1 ),
LayerCount, LayerList, layerList,
(LayerCount < 8) ? LayerCount : 8, (layerCount < 8) ? layerCount : 8,
wxRA_SPECIFY_ROWS ); wxRA_SPECIFY_ROWS );
if( LayerSelect >= 0 ) if( layerSelect >= 0 )
m_LayerList->SetSelection( LayerSelect ); m_layerList->SetSelection( layerSelect );
wxBoxSizer* FrameBoxSizer = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer* FrameBoxSizer = new wxBoxSizer( wxHORIZONTAL );
SetSizer( FrameBoxSizer ); SetSizer( FrameBoxSizer );
FrameBoxSizer->Add( m_LayerList, 0, wxALIGN_TOP | wxALL, 5 ); FrameBoxSizer->Add( m_layerList, 0, wxALIGN_TOP | wxALL, 5 );
wxBoxSizer* ButtonBoxSizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer* ButtonBoxSizer = new wxBoxSizer( wxVERTICAL );
FrameBoxSizer->Add( ButtonBoxSizer, 0, wxALIGN_BOTTOM | wxALL, 0 ); FrameBoxSizer->Add( ButtonBoxSizer, 0, wxALIGN_BOTTOM | wxALL, 0 );
Button = new wxButton( this, wxID_OK, _( "OK" ) ); button = new wxButton( this, wxID_OK, _( "OK" ) );
Button->SetDefault(); button->SetDefault();
ButtonBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 ); ButtonBoxSizer->Add( button, 0, wxGROW | wxALL, 5 );
Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
ButtonBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
SetFocus(); button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
ButtonBoxSizer->Add( button, 0, wxGROW | wxALL, 5 );
GetSizer()->SetSizeHints( this ); GetSizer()->SetSizeHints( this );
...@@ -176,7 +166,7 @@ SELECT_LAYER_DIALOG::SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent, ...@@ -176,7 +166,7 @@ SELECT_LAYER_DIALOG::SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent,
void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event ) void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event )
{ {
int ii = m_LayerId[m_LayerList->GetSelection()]; int ii = m_layerId[m_layerList->GetSelection()];
EndModal( ii ); EndModal( ii );
} }
...@@ -187,12 +177,15 @@ void SELECT_LAYER_DIALOG::OnCancelClick( wxCommandEvent& event ) ...@@ -187,12 +177,15 @@ void SELECT_LAYER_DIALOG::OnCancelClick( wxCommandEvent& event )
EndModal( -1 ); EndModal( -1 );
} }
const wxString GetPCBDefaultLayerName( int aLayerNumber ) // This function is a duplicate of
// const wxChar* LSET::Name( LAYER_ID aLayerId )
// However it avoids a dependency to Pcbnew code.
const wxString GetPCBDefaultLayerName( int aLayerId )
{ {
const wxChar* txt; const wxChar* txt;
// Use a switch to explicitly show the mapping more clearly // using a switch to explicitly show the mapping more clearly
switch( aLayerNumber ) switch( aLayerId )
{ {
case F_Cu: txt = wxT( "F.Cu" ); break; case F_Cu: txt = wxT( "F.Cu" ); break;
case In1_Cu: txt = wxT( "In1.Cu" ); break; case In1_Cu: txt = wxT( "In1.Cu" ); break;
...@@ -209,7 +202,25 @@ const wxString GetPCBDefaultLayerName( int aLayerNumber ) ...@@ -209,7 +202,25 @@ const wxString GetPCBDefaultLayerName( int aLayerNumber )
case In12_Cu: txt = wxT( "In12.Cu" ); break; case In12_Cu: txt = wxT( "In12.Cu" ); break;
case In13_Cu: txt = wxT( "In13.Cu" ); break; case In13_Cu: txt = wxT( "In13.Cu" ); break;
case In14_Cu: txt = wxT( "In14.Cu" ); break; case In14_Cu: txt = wxT( "In14.Cu" ); break;
case In15_Cu: txt = wxT( "In15.Cu" ); break;
case In16_Cu: txt = wxT( "In16.Cu" ); break;
case In17_Cu: txt = wxT( "In17.Cu" ); break;
case In18_Cu: txt = wxT( "In18.Cu" ); break;
case In19_Cu: txt = wxT( "In19.Cu" ); break;
case In20_Cu: txt = wxT( "In20.Cu" ); break;
case In21_Cu: txt = wxT( "In21.Cu" ); break;
case In22_Cu: txt = wxT( "In22.Cu" ); break;
case In23_Cu: txt = wxT( "In23.Cu" ); break;
case In24_Cu: txt = wxT( "In24.Cu" ); break;
case In25_Cu: txt = wxT( "In25.Cu" ); break;
case In26_Cu: txt = wxT( "In26.Cu" ); break;
case In27_Cu: txt = wxT( "In27.Cu" ); break;
case In28_Cu: txt = wxT( "In28.Cu" ); break;
case In29_Cu: txt = wxT( "In29.Cu" ); break;
case In30_Cu: txt = wxT( "In30.Cu" ); break;
case B_Cu: txt = wxT( "B.Cu" ); break; case B_Cu: txt = wxT( "B.Cu" ); break;
// Technicals
case B_Adhes: txt = wxT( "B.Adhes" ); break; case B_Adhes: txt = wxT( "B.Adhes" ); break;
case F_Adhes: txt = wxT( "F.Adhes" ); break; case F_Adhes: txt = wxT( "F.Adhes" ); break;
case B_Paste: txt = wxT( "B.Paste" ); break; case B_Paste: txt = wxT( "B.Paste" ); break;
...@@ -218,12 +229,24 @@ const wxString GetPCBDefaultLayerName( int aLayerNumber ) ...@@ -218,12 +229,24 @@ const wxString GetPCBDefaultLayerName( int aLayerNumber )
case F_SilkS: txt = wxT( "F.SilkS" ); break; case F_SilkS: txt = wxT( "F.SilkS" ); break;
case B_Mask: txt = wxT( "B.Mask" ); break; case B_Mask: txt = wxT( "B.Mask" ); break;
case F_Mask: txt = wxT( "F.Mask" ); break; case F_Mask: txt = wxT( "F.Mask" ); break;
// Users
case Dwgs_User: txt = wxT( "Dwgs.User" ); break; case Dwgs_User: txt = wxT( "Dwgs.User" ); break;
case Cmts_User: txt = wxT( "Cmts.User" ); break; case Cmts_User: txt = wxT( "Cmts.User" ); break;
case Eco1_User: txt = wxT( "Eco1.User" ); break; case Eco1_User: txt = wxT( "Eco1.User" ); break;
case Eco2_User: txt = wxT( "Eco2.User" ); break; case Eco2_User: txt = wxT( "Eco2.User" ); break;
case Edge_Cuts: txt = wxT( "Edge.Cuts" ); break; case Edge_Cuts: txt = wxT( "Edge.Cuts" ); break;
default: txt = wxT( "BAD_INDEX" ); break; case Margin: txt = wxT( "Margin" ); break;
// Footprint
case F_CrtYd: txt = wxT( "F.CrtYd" ); break;
case B_CrtYd: txt = wxT( "B.CrtYd" ); break;
case F_Fab: txt = wxT( "F.Fab" ); break;
case B_Fab: txt = wxT( "B.Fab" ); break;
default:
wxASSERT_MSG( 0, wxT( "aLayerId out of range" ) );
txt = wxT( "BAD INDEX!" ); break;
} }
return wxString( txt ); return wxString( txt );
......
...@@ -164,7 +164,7 @@ void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -164,7 +164,7 @@ void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
case ID_GERBVIEW_GLOBAL_DELETE: case ID_GERBVIEW_GLOBAL_DELETE:
Erase_Current_Layer( true ); Erase_Current_DrawLayer( true );
ClearMsgPanel(); ClearMsgPanel();
break; break;
......
This diff is collapsed.
...@@ -47,7 +47,7 @@ void GERBVIEW_FRAME::OnGbrFileHistory( wxCommandEvent& event ) ...@@ -47,7 +47,7 @@ void GERBVIEW_FRAME::OnGbrFileHistory( wxCommandEvent& event )
if( !fn.IsEmpty() ) if( !fn.IsEmpty() )
{ {
Erase_Current_Layer( false ); Erase_Current_DrawLayer( false );
LoadGerberFiles( fn ); LoadGerberFiles( fn );
} }
} }
...@@ -61,7 +61,7 @@ void GERBVIEW_FRAME::OnDrlFileHistory( wxCommandEvent& event ) ...@@ -61,7 +61,7 @@ void GERBVIEW_FRAME::OnDrlFileHistory( wxCommandEvent& event )
if( !fn.IsEmpty() ) if( !fn.IsEmpty() )
{ {
Erase_Current_Layer( false ); Erase_Current_DrawLayer( false );
LoadExcellonFiles( fn ); LoadExcellonFiles( fn );
} }
} }
...@@ -75,12 +75,12 @@ void GERBVIEW_FRAME::Files_io( wxCommandEvent& event ) ...@@ -75,12 +75,12 @@ void GERBVIEW_FRAME::Files_io( wxCommandEvent& event )
switch( id ) switch( id )
{ {
case wxID_FILE: case wxID_FILE:
Erase_Current_Layer( false ); Erase_Current_DrawLayer( false );
LoadGerberFiles( wxEmptyString ); LoadGerberFiles( wxEmptyString );
break; break;
case ID_GERBVIEW_ERASE_ALL: case ID_GERBVIEW_ERASE_ALL:
Clear_Pcb( true ); Clear_DrawLayers( true );
Zoom_Automatique( false ); Zoom_Automatique( false );
m_canvas->Refresh(); m_canvas->Refresh();
ClearMsgPanel(); ClearMsgPanel();
......
...@@ -138,6 +138,7 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ): ...@@ -138,6 +138,7 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ):
lyrs.MinSize( m_LayersManager->GetBestSize() ); lyrs.MinSize( m_LayersManager->GetBestSize() );
lyrs.BestSize( m_LayersManager->GetBestSize() ); lyrs.BestSize( m_LayersManager->GetBestSize() );
lyrs.Caption( _( "Visibles" ) ); lyrs.Caption( _( "Visibles" ) );
lyrs.TopDockable( false ).BottomDockable( false );
if( m_mainToolBar ) if( m_mainToolBar )
......
...@@ -630,8 +630,8 @@ public: ...@@ -630,8 +630,8 @@ public:
void Liste_D_Codes(); void Liste_D_Codes();
// PCB handling // PCB handling
bool Clear_Pcb( bool query ); bool Clear_DrawLayers( bool query );
void Erase_Current_Layer( bool query ); void Erase_Current_DrawLayer( bool query );
// Conversion function // Conversion function
void ExportDataInPcbnewFormat( wxCommandEvent& event ); void ExportDataInPcbnewFormat( wxCommandEvent& event );
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
*/ */
/** /**
* @file gerbview/initpcb.cpp * @file init_gbr_drawlayers.cpp
*/ */
#include <fctsys.h> #include <fctsys.h>
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include <class_gerbview_layer_widget.h> #include <class_gerbview_layer_widget.h>
#include <class_gbr_layout.h> #include <class_gbr_layout.h>
bool GERBVIEW_FRAME::Clear_Pcb( bool query ) bool GERBVIEW_FRAME::Clear_DrawLayers( bool query )
{ {
int layer; int layer;
...@@ -73,7 +73,7 @@ bool GERBVIEW_FRAME::Clear_Pcb( bool query ) ...@@ -73,7 +73,7 @@ bool GERBVIEW_FRAME::Clear_Pcb( bool query )
} }
void GERBVIEW_FRAME::Erase_Current_Layer( bool query ) void GERBVIEW_FRAME::Erase_Current_DrawLayer( bool query )
{ {
int layer = getActiveLayer(); int layer = getActiveLayer();
wxString msg; wxString msg;
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2014 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 2
* 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, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file printout_controller.cpp
* @brief Board print handler implementation file.
*/
// Set this to 1 if you want to test PostScript printing under MSW.
#define wxTEST_POSTSCRIPT_IN_MSW 1
#include <fctsys.h>
#include <pgm_base.h>
#include <gr_basic.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <base_units.h>
#include <wxstruct.h>
#include <class_base_screen.h>
#include <layers_id_colors_and_visibility.h>
#include <gerbview_frame.h>
#include <printout_controler.h>
PRINT_PARAMETERS::PRINT_PARAMETERS()
{
m_PenDefaultSize = Millimeter2iu( 0.2 ); // A reasonable default value to draw items
// which do not have a specified line width
m_PrintScale = 1.0;
m_XScaleAdjust = 1.0;
m_YScaleAdjust = 1.0;
m_Print_Sheet_Ref = false;
m_PrintMaskLayer.set();
m_PrintMirror = false;
m_Print_Black_and_White = true;
m_OptionPrintPage = 1;
m_PageCount = 1;
m_ForceCentered = false;
m_Flags = 0;
m_DrillShapeOpt = PRINT_PARAMETERS::SMALL_DRILL_SHAPE;
m_PageSetupData = NULL;
}
BOARD_PRINTOUT_CONTROLLER::BOARD_PRINTOUT_CONTROLLER( const PRINT_PARAMETERS& aParams,
EDA_DRAW_FRAME* aParent,
const wxString& aTitle ) :
wxPrintout( aTitle )
{
m_PrintParams = aParams; // Make a local copy of the print parameters.
m_Parent = aParent;
}
bool BOARD_PRINTOUT_CONTROLLER::OnPrintPage( int aPage )
{
// in gerbview, draw layers are always printed on separate pages
// because handling negative objects when using only one page is tricky
m_PrintParams.m_Flags = aPage-1; // = gerber draw layer id
DrawPage();
return true;
}
void BOARD_PRINTOUT_CONTROLLER::GetPageInfo( int* minPage, int* maxPage,
int* selPageFrom, int* selPageTo )
{
*minPage = 1;
*selPageFrom = 1;
int icnt = 1;
if( m_PrintParams.m_OptionPrintPage == 0 )
icnt = m_PrintParams.m_PageCount;
*maxPage = icnt;
*selPageTo = icnt;
}
void BOARD_PRINTOUT_CONTROLLER::DrawPage()
{
wxPoint offset;
double userscale;
EDA_RECT boardBoundingBox;
EDA_RECT drawRect;
wxDC* dc = GetDC();
BASE_SCREEN* screen = m_Parent->GetScreen();
bool printMirror = m_PrintParams.m_PrintMirror;
wxSize pageSizeIU = m_Parent->GetPageSizeIU();
wxBusyCursor dummy;
boardBoundingBox = ((GERBVIEW_FRAME*) m_Parent)->GetGerberLayoutBoundingBox();
wxString titleblockFilename; // TODO see if we uses the gerber file name
// Use the page size as the drawing area when the board is shown or the user scale
// is less than 1.
if( m_PrintParams.PrintBorderAndTitleBlock() )
boardBoundingBox = EDA_RECT( wxPoint( 0, 0 ), pageSizeIU );
// Compute the PCB size in internal units
userscale = m_PrintParams.m_PrintScale;
if( m_PrintParams.m_PrintScale == 0 ) // fit in page option
{
if(boardBoundingBox.GetWidth() && boardBoundingBox.GetHeight())
{
int margin = Millimeter2iu( 10.0 ); // add a margin around the drawings
double scaleX = (double)(pageSizeIU.x - (2 * margin)) /
boardBoundingBox.GetWidth();
double scaleY = (double)(pageSizeIU.y - (2 * margin)) /
boardBoundingBox.GetHeight();
userscale = (scaleX < scaleY) ? scaleX : scaleY;
}
else
userscale = 1.0;
}
wxSize scaledPageSize = pageSizeIU;
drawRect.SetSize( scaledPageSize );
scaledPageSize.x = wxRound( scaledPageSize.x / userscale );
scaledPageSize.y = wxRound( scaledPageSize.y / userscale );
if( m_PrintParams.m_PageSetupData )
{
// Always scale to the size of the paper.
FitThisSizeToPageMargins( scaledPageSize, *m_PrintParams.m_PageSetupData );
}
// Compute Accurate scale 1
if( m_PrintParams.m_PrintScale == 1.0 )
{
// We want a 1:1 scale, regardless the page setup
// like page size, margin ...
MapScreenSizeToPaper(); // set best scale and offset (scale is not used)
int w, h;
GetPPIPrinter( &w, &h );
double accurate_Xscale = (double) w / (IU_PER_MILS*1000);
double accurate_Yscale = (double) h / (IU_PER_MILS*1000);
if( IsPreview() ) // Scale must take in account the DC size in Preview
{
// Get the size of the DC in pixels
wxSize PlotAreaSize;
dc->GetSize( &PlotAreaSize.x, &PlotAreaSize.y );
GetPageSizePixels( &w, &h );
accurate_Xscale *= (double)PlotAreaSize.x / w;
accurate_Yscale *= (double)PlotAreaSize.y / h;
}
// Fine scale adjust
accurate_Xscale *= m_PrintParams.m_XScaleAdjust;
accurate_Yscale *= m_PrintParams.m_YScaleAdjust;
// Set print scale for 1:1 exact scale
dc->SetUserScale( accurate_Xscale, accurate_Yscale );
}
// Get the final size of the DC in pixels
wxSize PlotAreaSizeInPixels;
dc->GetSize( &PlotAreaSizeInPixels.x, &PlotAreaSizeInPixels.y );
double scalex, scaley;
dc->GetUserScale( &scalex, &scaley );
wxSize PlotAreaSizeInUserUnits;
PlotAreaSizeInUserUnits.x = KiROUND( PlotAreaSizeInPixels.x / scalex );
PlotAreaSizeInUserUnits.y = KiROUND( PlotAreaSizeInPixels.y / scaley );
// In some cases the plot origin is the centre of the board outline rather than the center
// of the selected paper size.
if( m_PrintParams.CenterOnBoardOutline() )
{
// Here we are only drawing the board and it's contents.
drawRect = boardBoundingBox;
offset.x += wxRound( (double) -scaledPageSize.x / 2.0 );
offset.y += wxRound( (double) -scaledPageSize.y / 2.0 );
wxPoint center = boardBoundingBox.Centre();
if( printMirror )
{
// Calculate the mirrored center of the board.
center.x = m_Parent->GetPageSizeIU().x - boardBoundingBox.Centre().x;
}
offset += center;
}
GRResetPenAndBrush( dc );
EDA_DRAW_PANEL* panel = m_Parent->GetCanvas();
EDA_RECT tmp = *panel->GetClipBox();
// Set clip box to the max size
#define MAX_VALUE (INT_MAX/2) // MAX_VALUE is the max we can use in an integer
// and that allows calculations without overflow
panel->SetClipBox( EDA_RECT( wxPoint( 0, 0 ), wxSize( MAX_VALUE, MAX_VALUE ) ) );
screen->m_IsPrinting = true;
EDA_COLOR_T bg_color = m_Parent->GetDrawBgColor();
// Print frame reference, if requested, before printing draw layers
if( m_PrintParams.m_Print_Black_and_White )
GRForceBlackPen( true );
if( m_PrintParams.PrintBorderAndTitleBlock() )
m_Parent->DrawWorkSheet( dc, screen, m_PrintParams.m_PenDefaultSize,
IU_PER_MILS, titleblockFilename );
if( printMirror )
{
// To plot mirror, we reverse the x axis, and modify the plot x origin
dc->SetAxisOrientation( false, false);
/* Plot offset x is moved by the x plot area size in order to have
* the old draw area in the new draw area, because the draw origin has not moved
* (this is the upper left corner) but the X axis is reversed, therefore the plotting area
* is the x coordinate values from - PlotAreaSize.x to 0 */
int x_dc_offset = PlotAreaSizeInPixels.x;
x_dc_offset = KiROUND( x_dc_offset * userscale );
dc->SetDeviceOrigin( x_dc_offset, 0 );
panel->SetClipBox( EDA_RECT( wxPoint( -MAX_VALUE/2, -MAX_VALUE/2 ),
panel->GetClipBox()->GetSize() ) );
}
// screen->m_DrawOrg = offset;
dc->SetLogicalOrigin( offset.x, offset.y );
m_Parent->SetDrawBgColor( WHITE );
// Never force black pen to print draw layers
// because negative objects need a white pen, not a black pen
// B&W mode is handled in print page function
GRForceBlackPen( false );
m_Parent->PrintPage( dc, m_PrintParams.m_PrintMaskLayer, printMirror,
&m_PrintParams );
m_Parent->SetDrawBgColor( bg_color );
screen->m_IsPrinting = false;
panel->SetClipBox( tmp );
}
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
// depending on the gerber file format // depending on the gerber file format
// this scale list assumes gerber units are imperial. // this scale list assumes gerber units are imperial.
// for metric gerber units, the imperial to metric conversion is made in read functions // for metric gerber units, the imperial to metric conversion is made in read functions
#define SCALE_LIST_SIZE 10 #define SCALE_LIST_SIZE 9
static double scale_list[SCALE_LIST_SIZE] = static double scale_list[SCALE_LIST_SIZE] =
{ {
1000.0 * IU_PER_MILS, // x.1 format (certainly useless) 1000.0 * IU_PER_MILS, // x.1 format (certainly useless)
...@@ -28,9 +28,9 @@ static double scale_list[SCALE_LIST_SIZE] = ...@@ -28,9 +28,9 @@ static double scale_list[SCALE_LIST_SIZE] =
1.0 * IU_PER_MILS, // x.4 format 1.0 * IU_PER_MILS, // x.4 format
0.1 * IU_PER_MILS, // x.5 format 0.1 * IU_PER_MILS, // x.5 format
0.01 * IU_PER_MILS, // x.6 format 0.01 * IU_PER_MILS, // x.6 format
0.0001 * IU_PER_MILS, // x.7 format 0.001 * IU_PER_MILS, // x.7 format (currently the max allowed precision)
0.0001 * IU_PER_MILS, // provided, but not used
0.00001 * IU_PER_MILS, // provided, but not used 0.00001 * IU_PER_MILS, // provided, but not used
0.000001 * IU_PER_MILS
}; };
/* /*
......
...@@ -359,17 +359,19 @@ void LAYERS_MAP_DIALOG::OnSelectLayer( wxCommandEvent& event ) ...@@ -359,17 +359,19 @@ void LAYERS_MAP_DIALOG::OnSelectLayer( wxCommandEvent& event )
} }
LAYER_NUM jj = m_layersLookUpTable[m_buttonTable[ii]]; LAYER_NUM jj = m_layersLookUpTable[m_buttonTable[ii]];
if( !IsValidLayer( jj ) )
if( jj != UNSELECTED_LAYER && !IsValidLayer( jj ) )
jj = B_Cu; // (Defaults to "Copper" layer.) jj = B_Cu; // (Defaults to "Copper" layer.)
jj = m_Parent->SelectPCBLayer( jj, m_exportBoardCopperLayersCount, true ); jj = m_Parent->SelectPCBLayer( jj, m_exportBoardCopperLayersCount, true );
if( !IsValidLayer( jj ) ) if( jj != UNSELECTED_LAYER && !IsValidLayer( jj ) )
return; return;
if( jj != m_layersLookUpTable[m_buttonTable[ii]] ) if( jj != m_layersLookUpTable[m_buttonTable[ii]] )
{ {
m_layersLookUpTable[m_buttonTable[ii]] = jj; m_layersLookUpTable[m_buttonTable[ii]] = jj;
if( jj == UNSELECTED_LAYER ) if( jj == UNSELECTED_LAYER )
{ {
m_layersList[ii]->SetLabel( _( "Do not export" ) ); m_layersList[ii]->SetLabel( _( "Do not export" ) );
......
...@@ -37,16 +37,10 @@ ...@@ -37,16 +37,10 @@
#include <class_drawpanel.h> #include <class_drawpanel.h>
#include <confirm.h> #include <confirm.h>
#include <base_units.h> #include <base_units.h>
#ifdef PCBNEW #include <wxBasePcbFrame.h>
#include <wxBasePcbFrame.h> #include <class_board.h>
#include <class_board.h> #include <pcbnew.h>
#include <pcbnew.h>
#else
#include <wxstruct.h>
#include <class_base_screen.h>
#include <layers_id_colors_and_visibility.h>
#include <gerbview_frame.h>
#endif
#include <printout_controler.h> #include <printout_controler.h>
...@@ -89,7 +83,6 @@ BOARD_PRINTOUT_CONTROLLER::BOARD_PRINTOUT_CONTROLLER( const PRINT_PARAMETERS& aP ...@@ -89,7 +83,6 @@ BOARD_PRINTOUT_CONTROLLER::BOARD_PRINTOUT_CONTROLLER( const PRINT_PARAMETERS& aP
bool BOARD_PRINTOUT_CONTROLLER::OnPrintPage( int aPage ) bool BOARD_PRINTOUT_CONTROLLER::OnPrintPage( int aPage )
{ {
#ifdef PCBNEW
LSET lset = m_PrintParams.m_PrintMaskLayer; LSET lset = m_PrintParams.m_PrintMaskLayer;
// compute layer mask from page number if we want one page per layer // compute layer mask from page number if we want one page per layer
...@@ -115,11 +108,6 @@ bool BOARD_PRINTOUT_CONTROLLER::OnPrintPage( int aPage ) ...@@ -115,11 +108,6 @@ bool BOARD_PRINTOUT_CONTROLLER::OnPrintPage( int aPage )
DrawPage(); DrawPage();
m_PrintParams.m_PrintMaskLayer = lset; m_PrintParams.m_PrintMaskLayer = lset;
#else // GERBVIEW
// in gerbview, draw layers are printed on separate pages
m_PrintParams.m_Flags = aPage-1; // = gerber draw layer id
DrawPage();
#endif
return true; return true;
} }
...@@ -154,16 +142,9 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage() ...@@ -154,16 +142,9 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage()
wxBusyCursor dummy; wxBusyCursor dummy;
#if defined (PCBNEW)
BOARD * brd = ((PCB_BASE_FRAME*) m_Parent)->GetBoard(); BOARD * brd = ((PCB_BASE_FRAME*) m_Parent)->GetBoard();
boardBoundingBox = brd->ComputeBoundingBox(); boardBoundingBox = brd->ComputeBoundingBox();
wxString titleblockFilename = brd->GetFileName(); wxString titleblockFilename = brd->GetFileName();
#elif defined (GERBVIEW)
boardBoundingBox = ((GERBVIEW_FRAME*) m_Parent)->GetGerberLayoutBoundingBox();
wxString titleblockFilename; // TODO see if we uses the gerber file name
#else
#error BOARD_PRINTOUT_CONTROLLER::DrawPage() works only for PCBNEW or GERBVIEW
#endif
// Use the page size as the drawing area when the board is shown or the user scale // Use the page size as the drawing area when the board is shown or the user scale
// is less than 1. // is less than 1.
...@@ -362,12 +343,6 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage() ...@@ -362,12 +343,6 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage()
GRForceBlackPen( true ); GRForceBlackPen( true );
#if defined (GERBVIEW)
// In B&W mode, do not force black pen for Gerbview
// because negative objects need a white pen, not a black pen
// B&W mode is handled in print page
GRForceBlackPen( false );
#endif
m_Parent->PrintPage( dc, m_PrintParams.m_PrintMaskLayer, printMirror, m_Parent->PrintPage( dc, m_PrintParams.m_PrintMaskLayer, printMirror,
&m_PrintParams ); &m_PrintParams );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment