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
gerbview_config.cpp
gerbview_frame.cpp
hotkeys.cpp
initpcb.cpp
init_gbr_drawlayers.cpp
locate.cpp
menubar.cpp
onleftclick.cpp
onrightclick.cpp
pcbplot.cpp
printout_control.cpp
readgerb.cpp
rs274_read_XY_and_IJ_coordinates.cpp
rs274d.cpp
......@@ -71,7 +72,6 @@ set( GERBVIEW_EXTRA_SRCS
../common/class_layer_box_selector.cpp
../common/class_page_info.cpp
../pcbnew/layer_widget.cpp
../pcbnew/printout_controler.cpp
)
if( MINGW )
......
......@@ -164,7 +164,7 @@ void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event )
break;
case ID_GERBVIEW_GLOBAL_DELETE:
Erase_Current_Layer( true );
Erase_Current_DrawLayer( true );
ClearMsgPanel();
break;
......
This diff is collapsed.
......@@ -47,7 +47,7 @@ void GERBVIEW_FRAME::OnGbrFileHistory( wxCommandEvent& event )
if( !fn.IsEmpty() )
{
Erase_Current_Layer( false );
Erase_Current_DrawLayer( false );
LoadGerberFiles( fn );
}
}
......@@ -61,7 +61,7 @@ void GERBVIEW_FRAME::OnDrlFileHistory( wxCommandEvent& event )
if( !fn.IsEmpty() )
{
Erase_Current_Layer( false );
Erase_Current_DrawLayer( false );
LoadExcellonFiles( fn );
}
}
......@@ -75,12 +75,12 @@ void GERBVIEW_FRAME::Files_io( wxCommandEvent& event )
switch( id )
{
case wxID_FILE:
Erase_Current_Layer( false );
Erase_Current_DrawLayer( false );
LoadGerberFiles( wxEmptyString );
break;
case ID_GERBVIEW_ERASE_ALL:
Clear_Pcb( true );
Clear_DrawLayers( true );
Zoom_Automatique( false );
m_canvas->Refresh();
ClearMsgPanel();
......
......@@ -138,6 +138,7 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ):
lyrs.MinSize( m_LayersManager->GetBestSize() );
lyrs.BestSize( m_LayersManager->GetBestSize() );
lyrs.Caption( _( "Visibles" ) );
lyrs.TopDockable( false ).BottomDockable( false );
if( m_mainToolBar )
......
......@@ -630,8 +630,8 @@ public:
void Liste_D_Codes();
// PCB handling
bool Clear_Pcb( bool query );
void Erase_Current_Layer( bool query );
bool Clear_DrawLayers( bool query );
void Erase_Current_DrawLayer( bool query );
// Conversion function
void ExportDataInPcbnewFormat( wxCommandEvent& event );
......
......@@ -23,7 +23,7 @@
*/
/**
* @file gerbview/initpcb.cpp
* @file init_gbr_drawlayers.cpp
*/
#include <fctsys.h>
......@@ -38,7 +38,7 @@
#include <class_gerbview_layer_widget.h>
#include <class_gbr_layout.h>
bool GERBVIEW_FRAME::Clear_Pcb( bool query )
bool GERBVIEW_FRAME::Clear_DrawLayers( bool query )
{
int layer;
......@@ -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();
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 @@
// depending on the gerber file format
// this scale list assumes gerber units are imperial.
// 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] =
{
1000.0 * IU_PER_MILS, // x.1 format (certainly useless)
......@@ -28,9 +28,9 @@ static double scale_list[SCALE_LIST_SIZE] =
1.0 * IU_PER_MILS, // x.4 format
0.1 * IU_PER_MILS, // x.5 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.000001 * IU_PER_MILS
};
/*
......
......@@ -359,17 +359,19 @@ void LAYERS_MAP_DIALOG::OnSelectLayer( wxCommandEvent& event )
}
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 = m_Parent->SelectPCBLayer( jj, m_exportBoardCopperLayersCount, true );
if( !IsValidLayer( jj ) )
if( jj != UNSELECTED_LAYER && !IsValidLayer( jj ) )
return;
if( jj != m_layersLookUpTable[m_buttonTable[ii]] )
{
m_layersLookUpTable[m_buttonTable[ii]] = jj;
if( jj == UNSELECTED_LAYER )
{
m_layersList[ii]->SetLabel( _( "Do not export" ) );
......
......@@ -37,16 +37,10 @@
#include <class_drawpanel.h>
#include <confirm.h>
#include <base_units.h>
#ifdef PCBNEW
#include <wxBasePcbFrame.h>
#include <class_board.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 <wxBasePcbFrame.h>
#include <class_board.h>
#include <pcbnew.h>
#include <printout_controler.h>
......@@ -89,7 +83,6 @@ BOARD_PRINTOUT_CONTROLLER::BOARD_PRINTOUT_CONTROLLER( const PRINT_PARAMETERS& aP
bool BOARD_PRINTOUT_CONTROLLER::OnPrintPage( int aPage )
{
#ifdef PCBNEW
LSET lset = m_PrintParams.m_PrintMaskLayer;
// compute layer mask from page number if we want one page per layer
......@@ -115,11 +108,6 @@ bool BOARD_PRINTOUT_CONTROLLER::OnPrintPage( int aPage )
DrawPage();
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;
}
......@@ -154,16 +142,9 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage()
wxBusyCursor dummy;
#if defined (PCBNEW)
BOARD * brd = ((PCB_BASE_FRAME*) m_Parent)->GetBoard();
boardBoundingBox = brd->ComputeBoundingBox();
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
// is less than 1.
......@@ -362,12 +343,6 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage()
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_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