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

Define MM_TO_IU_SCALING_FACTOR (scaling factor from mm to internal units) only in convert_to_biu.h

Other scaling factors (MILS_TO_IU_SCALING_FACTOR and DECIMILS_TO_IU_SCALING_FACTOR)
also defined only in convert_to_biu.h.
Allows different scaling value for Gerbview.
Needs more tests.
parent e3b6385c
......@@ -83,7 +83,6 @@ add_library(common STATIC ${COMMON_SRCS})
set(PCB_COMMON_SRCS
base_screen.cpp
base_units.cpp
eda_text.cpp
class_page_info.cpp
pcbcommon.cpp
......@@ -120,7 +119,6 @@ set(PCB_COMMON_SRCS
../pcbnew/legacy_plugin.cpp
../pcbnew/kicad_plugin.cpp
pcb_plot_params_keywords.cpp
dialogs/dialog_page_settings.cpp
)
......
......@@ -40,25 +40,13 @@
#include <base_units.h>
#if defined( PCBNEW )
#if defined( USE_PCBNEW_NANOMETRES )
#define IU_TO_MM( x ) ( x * 1e-6 )
#define IU_TO_IN( x ) ( ( x * 1e-6 ) / 25.4 )
#define MM_TO_IU( x ) ( x * 1e6 )
#define IN_TO_IU( x ) ( ( x * 25.4 ) * 1e6 )
#else
#define IU_TO_MM( x ) ( ( x * 0.0001 ) * 25.4 )
#define IU_TO_IN( x ) ( x * 0.0001 )
#define MM_TO_IU( x ) ( ( x / 25.4 ) * 10000.0 )
#define IN_TO_IU( x ) ( x * 10000.0 )
#endif
#elif defined( EESCHEMA )
#define IU_TO_MM( x ) ( ( x * 0.001 ) * 25.4 )
#define IU_TO_IN( x ) ( x * 0.001 )
#define MM_TO_IU( x ) ( ( x / 25.4 ) * 1000.0 )
#define IN_TO_IU( x ) ( x * 1000.0 )
#if defined( PCBNEW ) || defined( CVPCB ) || defined( EESCHEMA )
#define IU_TO_MM( x ) ( x / MM_TO_IU_SCALING_FACTOR )
#define IU_TO_IN( x ) ( x / MILS_TO_IU_SCALING_FACTOR / 1000 )
#define MM_TO_IU( x ) ( x * MM_TO_IU_SCALING_FACTOR )
#define IN_TO_IU( x ) ( x * MILS_TO_IU_SCALING_FACTOR * 1000 )
#else
#error "Cannot resolve internal units due to no definition of EESCHEMA or PCBNEW."
#error "Cannot resolve internal units due to no definition of EESCHEMA, CVPCB or PCBNEW."
#endif
......
......@@ -34,7 +34,6 @@
#include <class_title_block.h>
#include <wxstruct.h>
#include <class_base_screen.h>
#include <base_units.h> // MILS_TO_IU_SCALAR
#include <wx/valgen.h>
#include <wx/tokenzr.h>
......@@ -617,7 +616,7 @@ void DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample()
m_Parent->GetCanvas()->SetClipBox( EDA_RECT( wxPoint( 0, 0 ),
wxSize( INT_MAX / 2, INT_MAX / 2 ) ) );
// Calculate layout preview scale.
int appScale = MILS_TO_IU_SCALAR;
int appScale = m_Screen->MilsToIuScalar();
double scaleW = (double) lyWidth / clamped_layout_size.x / appScale;
double scaleH = (double) lyHeight / clamped_layout_size.y / appScale;
......
......@@ -37,11 +37,7 @@
// Conversion to application internal units defined at build time.
#if defined( PCBNEW )
#include <class_board_item.h>
#if defined( USE_PCBNEW_NANOMETRES )
#define MILS_TO_IU( x ) ( x * 25400 );
#else
#define MILS_TO_IU( x ) ( x * 10 )
#endif
#define MILS_TO_IU( x ) ( x * MILS_TO_IU_SCALING_FACTOR );
#elif defined( EESCHEMA )
#include <sch_item_struct.h>
#define MILS_TO_IU( x ) ( x )
......
......@@ -26,6 +26,7 @@ set(CVPCB_DIALOGS
)
set(CVPCB_SRCS
../common/base_units.cpp
../pcbnew/netlist_reader_common.cpp
../pcbnew/netlist_reader_kicad.cpp
../pcbnew/netlist_reader_firstformat.cpp
......
......@@ -237,7 +237,7 @@ bool DIALOG_SVG_PRINT::DrawSVGPage( EDA_DRAW_FRAME* frame,
sheetSize.y/2) );
if( aPrint_Sheet_Ref )
frame->TraceWorkSheet( &dc, screen, g_DrawDefaultLineThickness, MILS_TO_IU_SCALAR );
frame->TraceWorkSheet( &dc, screen, g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR );
screen->m_IsPrinting = false;
panel->SetClipBox( tmp );
......
......@@ -378,7 +378,7 @@ void SCH_PRINTOUT::DrawPage( SCH_SCREEN* aScreen )
aScreen->Draw( panel, dc, GR_DEFAULT_DRAWMODE );
if( printReference )
parent->TraceWorkSheet( dc, aScreen, g_DrawDefaultLineThickness, MILS_TO_IU_SCALAR );
parent->TraceWorkSheet( dc, aScreen, g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR );
g_DrawBgColor = bg_color;
aScreen->m_IsPrinting = false;
......
......@@ -71,7 +71,7 @@ void SCH_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
GetScreen()->Draw( m_canvas, DC, GR_DEFAULT_DRAWMODE );
TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALAR );
TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR );
#ifdef USE_WX_OVERLAY
if( IsShown() )
......
......@@ -863,7 +863,7 @@ void SCH_EDIT_FRAME::SVG_Print( wxCommandEvent& event )
void SCH_EDIT_FRAME::PrintPage( wxDC* aDC, int aPrintMask, bool aPrintMirrorMode, void* aData )
{
GetScreen()->Draw( m_canvas, aDC, GR_DEFAULT_DRAWMODE );
TraceWorkSheet( aDC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALAR );
TraceWorkSheet( aDC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR );
}
......
......@@ -33,6 +33,7 @@ set(GERBVIEW_SRCS
class_am_param.cpp
class_aperture_macro.cpp
class_DCodeSelectionbox.cpp
class_gbr_screen.cpp
class_GERBER.cpp
class_gerber_draw_item.cpp
class_gerbview_layer_widget.cpp
......@@ -63,9 +64,10 @@ set(GERBVIEW_SRCS
)
###
# We need some extra sources from pcbnew
# We need some extra sources from common and pcbnew
###
set(GERBVIEW_EXTRA_SRCS
../common/base_units.cpp
../pcbnew/layer_widget.cpp
../pcbnew/printout_controler.cpp
../pcbnew/class_drc_item.cpp
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
......@@ -175,7 +175,8 @@ int GERBVIEW_FRAME::ReadDCodeDefinitionFile( const wxString& D_Code_FullFileName
/* Updating gerber scale: */
double dcode_scale = MILS_TO_IU_SCALAR; // By uniting dCode = mil, internal unit = MILS_TO_IU_SCALAR
double dcode_scale = MILS_TO_IU_SCALING_FACTOR; // By uniting dCode = mil,
// internal unit = MILS_TO_IU_SCALING_FACTOR
current_Dcode = 0;
if( D_Code_FullFileName.IsEmpty() )
......
......@@ -107,7 +107,7 @@ void GERBVIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
if( IsElementVisible( DCODES_VISIBLE ) )
DrawItemsDCodeID( DC, GR_COPY );
TraceWorkSheet( DC, screen, 0, MILS_TO_IU_SCALAR );
TraceWorkSheet( DC, screen, 0, MILS_TO_IU_SCALING_FACTOR );
if( m_canvas->IsMouseCaptured() )
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
......
......@@ -432,7 +432,7 @@ bool EXCELLON_IMAGE::Execute_HEADER_Command( char*& text )
if( dcode == NULL )
break;
// conv_scale = scaling factor from inch to Internal Unit
double conv_scale = MILS_TO_IU_SCALAR*1000;
double conv_scale = MILS_TO_IU_SCALING_FACTOR * 1000;
if( m_GerbMetric )
conv_scale /= 25.4;
......
......@@ -44,6 +44,7 @@
#include <dialog_helpers.h>
#include <class_DCodeSelectionbox.h>
#include <class_gerbview_layer_widget.h>
#include <class_gbr_screen.h>
......@@ -93,7 +94,7 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( wxWindow* father,
PAGE_INFO pageInfo( wxT( "GERBER" ) );
GetBoard()->SetPageSettings( pageInfo );
SetScreen( new PCB_SCREEN( pageInfo.GetSizeIU() ) );
SetScreen( new GBR_SCREEN( pageInfo.GetSizeIU() ) );
// Create the PCB_LAYER_WIDGET *after* SetBoard():
wxFont font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
......@@ -179,7 +180,7 @@ double GERBVIEW_FRAME::BestZoom()
{
// gives a minimal value to zoom, if no item in list
if( GetBoard()->m_Drawings == NULL )
return 160.0;
return ZOOM_FACTOR( 160.0 );
EDA_RECT bbox;
BOARD_ITEM* item = GetBoard()->m_Drawings;
......@@ -210,7 +211,8 @@ void GERBVIEW_FRAME::LoadSettings()
if( config == NULL )
return;
PCB_BASE_FRAME::LoadSettings();
// PCB_BASE_FRAME::LoadSettings();
EDA_DRAW_FRAME::LoadSettings();
wxGetApp().ReadCurrentSetupValues( GetConfigurationSettings() );
......@@ -255,7 +257,8 @@ void GERBVIEW_FRAME::SaveSettings()
if( config == NULL )
return;
PCB_BASE_FRAME::SaveSettings();
// PCB_BASE_FRAME::SaveSettings();
EDA_DRAW_FRAME::SaveSettings();
wxGetApp().SaveCurrentSetupValues( GetConfigurationSettings() );
......@@ -408,7 +411,7 @@ void GERBVIEW_FRAME::Liste_D_Codes()
D_CODE* pt_D_code;
wxString Line;
wxArrayString list;
double scale = MILS_TO_IU_SCALAR * 1000;
double scale = MILS_TO_IU_SCALING_FACTOR * 1000;
int curr_layer = getActiveLayer();
for( int layer = 0; layer < 32; layer++ )
......
......@@ -35,6 +35,7 @@
#include <wxBasePcbFrame.h>
#include <../pcbnew/class_board.h>
#include <class_gbr_screen.h>
class DCODE_SELECTION_BOX;
......@@ -53,7 +54,6 @@ class GERBER_DRAW_ITEM;
class GERBVIEW_FRAME : public PCB_BASE_FRAME
{
friend class PCB_LAYER_WIDGET;
protected:
GERBER_LAYER_WIDGET* m_LayersManager;
......@@ -62,7 +62,7 @@ protected:
wxFileHistory m_drillFileHistory;
public:
LAYER_BOX_SELECTOR* m_SelLayerBox;
LAYER_BOX_SELECTOR* m_SelLayerBox;
DCODE_SELECTION_BOX* m_DCodeSelector; // a list box to select the dcode Id to highlight.
wxTextCtrl* m_TextInfo; // a wxTextCtrl used to display some info about
// gerber data (format..)
......@@ -84,7 +84,7 @@ private:
bool m_show_layer_manager_tools;
// An array sting to store warning messages when reaging a gerber file.
// An array string to store warning messages when reading a gerber file.
wxArrayString m_Messages;
public: GERBVIEW_FRAME( wxWindow* father, const wxString& title,
......@@ -226,7 +226,7 @@ public: GERBVIEW_FRAME( wxWindow* father, const wxString& title,
*/
void setActiveLayer( int aLayer, bool doLayerWidgetUpdate = true )
{
( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer;
( (GBR_SCREEN*) GetScreen() )->m_Active_Layer = aLayer;
if( doLayerWidgetUpdate )
syncLayerWidget();
......@@ -239,7 +239,7 @@ public: GERBVIEW_FRAME( wxWindow* father, const wxString& title,
*/
int getActiveLayer()
{
return ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer;
return ( (GBR_SCREEN*) GetScreen() )->m_Active_Layer;
}
......@@ -440,8 +440,6 @@ public: GERBVIEW_FRAME( wxWindow* father, const wxString& title,
*/
void Block_Duplicate( wxDC* DC );
void ToPostProcess( wxCommandEvent& event );
/**
* Function ToPlotter
* Open a dialog frame to create plot and drill files
......
......@@ -21,7 +21,7 @@
*/
void GERBVIEW_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
{
BOARD_ITEM* DrawStruct = GetScreen()->GetCurItem();
EDA_ITEM* DrawStruct = GetScreen()->GetCurItem();
wxString msg;
if( GetToolId() == ID_NO_TOOL_SELECTED )
......@@ -36,7 +36,7 @@ void GERBVIEW_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
else
{
DrawStruct = Locate( aPosition, CURSEUR_OFF_GRILLE );
GetScreen()->SetCurItem( DrawStruct );
GetScreen()->SetCurItem( (BOARD_ITEM*)DrawStruct );
if( DrawStruct == NULL )
{
GERBER_IMAGE* gerber = g_GERBER_List[getActiveLayer() ];
......
......@@ -16,7 +16,7 @@
*/
bool GERBVIEW_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
{
BOARD_ITEM* DrawStruct = GetScreen()->GetCurItem();
EDA_ITEM* DrawStruct = GetScreen()->GetCurItem();
wxString msg;
bool BlockActive = !GetScreen()->m_BlockLocate.IsIdle();
bool busy = DrawStruct && DrawStruct->GetFlags();
......@@ -71,7 +71,7 @@ bool GERBVIEW_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
return true;
if( DrawStruct )
GetScreen()->SetCurItem( DrawStruct );
GetScreen()->SetCurItem( (BOARD_ITEM*)DrawStruct );
return true;
}
......@@ -36,28 +36,20 @@ void GERBVIEW_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
{
case ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH:
if( state )
{
DisplayOpt.DisplayPadFill = m_DisplayPadFill = false;
}
DisplayOpt.DisplayPadFill = false;
else
{
DisplayOpt.DisplayPadFill = m_DisplayPadFill = true;
}
DisplayOpt.DisplayPadFill = true;
m_DisplayPadFill = DisplayOpt.DisplayPadFill;
m_canvas->Refresh( true );
break;
case ID_TB_OPTIONS_SHOW_LINES_SKETCH:
if(state )
{
m_DisplayPcbTrackFill = false;
DisplayOpt.DisplayPcbTrackFill = false;
}
else
{
m_DisplayPcbTrackFill = true;
DisplayOpt.DisplayPcbTrackFill = true;
}
m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill;
m_canvas->Refresh( true );
break;
......
......@@ -21,16 +21,16 @@
// for metric gerber units, the imperial to metric conversion is made in read functions
static double scale_list[10] =
{
1000.0 * MILS_TO_IU_SCALAR,
100.0 * MILS_TO_IU_SCALAR,
10.0 * MILS_TO_IU_SCALAR,
1.0 * MILS_TO_IU_SCALAR,
0.1 * MILS_TO_IU_SCALAR,
0.01 * MILS_TO_IU_SCALAR,
0.001 * MILS_TO_IU_SCALAR,
0.0001 * MILS_TO_IU_SCALAR,
0.00001 * MILS_TO_IU_SCALAR,
0.000001 * MILS_TO_IU_SCALAR
1000.0 * MILS_TO_IU_SCALING_FACTOR,
100.0 * MILS_TO_IU_SCALING_FACTOR,
10.0 * MILS_TO_IU_SCALING_FACTOR,
1.0 * MILS_TO_IU_SCALING_FACTOR,
0.1 * MILS_TO_IU_SCALING_FACTOR,
0.01 * MILS_TO_IU_SCALING_FACTOR,
0.001 * MILS_TO_IU_SCALING_FACTOR,
0.0001 * MILS_TO_IU_SCALING_FACTOR,
0.00001 * MILS_TO_IU_SCALING_FACTOR,
0.000001 * MILS_TO_IU_SCALING_FACTOR
};
......@@ -44,9 +44,9 @@ int scaletoIU( double aCoord, bool isMetric )
int ret;
if( isMetric )
ret = KiROUND( aCoord * MILS_TO_IU_SCALAR / 0.00254 );
ret = KiROUND( aCoord * MILS_TO_IU_SCALING_FACTOR / 0.00254 );
else
ret = KiROUND( aCoord * MILS_TO_IU_SCALAR );
ret = KiROUND( aCoord * MILS_TO_IU_SCALING_FACTOR );
return ret;
}
......@@ -94,9 +94,9 @@ wxPoint GERBER_IMAGE::ReadXYCoord( char*& Text )
{
// When X or Y values are float numbers, they are given in mm or inches
if( m_GerbMetric ) // units are mm
current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALAR / 0.0254 );
current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR / 0.0254 );
else // units are inches
current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALAR * 1000 );
current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR * 1000 );
}
else
{
......@@ -185,9 +185,9 @@ wxPoint GERBER_IMAGE::ReadIJCoord( char*& Text )
{
// When X or Y values are float numbers, they are given in mm or inches
if( m_GerbMetric ) // units are mm
current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALAR / 0.0254 );
current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR / 0.0254 );
else // units are inches
current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALAR * 1000 );
current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR * 1000 );
}
else
{
......
......@@ -160,7 +160,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command,
double fcoord;
// conv_scale = scaling factor from inch to Internal Unit
double conv_scale = MILS_TO_IU_SCALAR*1000;
double conv_scale = MILS_TO_IU_SCALING_FACTOR * 1000;
if( m_GerbMetric )
conv_scale /= 25.4;
......@@ -294,7 +294,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command,
m_GerbMetric = false;
else if( code == MILLIMETER )
m_GerbMetric = true;
conv_scale = m_GerbMetric ? PCB_INTERNAL_UNIT / 25.4 : PCB_INTERNAL_UNIT;
conv_scale = m_GerbMetric ? MILS_TO_IU_SCALING_FACTOR / 25.4 : MILS_TO_IU_SCALING_FACTOR;
break;
case OFFSET: // command: OFAnnBnn (nn = float number) = layer Offset
......@@ -579,8 +579,8 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command,
text += 2; // skip "C," for example
dcode->m_Size.x = dcode->m_Size.y =
KiROUND( ReadDouble( text ) * conv_scale );
dcode->m_Size.x = KiROUND( ReadDouble( text ) * conv_scale );
dcode->m_Size.y = dcode->m_Size.x;
switch( stdAperture ) // Aperture desceiption has optional parameters. Read them
{
......@@ -631,8 +631,8 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command,
if( *text == 'X' )
{
text++;
dcode->m_Drill.x = dcode->m_Drill.y =
KiROUND( ReadDouble( text ) * conv_scale );
dcode->m_Drill.x = KiROUND( ReadDouble( text ) * conv_scale );
dcode->m_Drill.y = dcode->m_Drill.x;
dcode->m_DrillShape = APT_DEF_ROUND_HOLE;
}
......@@ -679,8 +679,8 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command,
if( *text == 'X' )
{
text++;
dcode->m_Drill.x = dcode->m_Drill.y =
KiROUND( ReadDouble( text ) * conv_scale );
dcode->m_Drill.x = KiROUND( ReadDouble( text ) * conv_scale );
dcode->m_Drill.y = dcode->m_Drill.x =
dcode->m_DrillShape = APT_DEF_ROUND_HOLE;
}
......@@ -690,8 +690,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command,
if( *text == 'X' )
{
text++;
dcode->m_Drill.y =
KiROUND( ReadDouble( text ) * conv_scale );
dcode->m_Drill.y = KiROUND( ReadDouble( text ) * conv_scale );
dcode->m_DrillShape = APT_DEF_RECT_HOLE;
}
dcode->m_Defined = true;
......
......@@ -35,19 +35,7 @@
#include <common.h>
/// Scalar to convert mils to internal units.
#if defined( PCBNEW )
#if defined( USE_PCBNEW_NANOMETRES )
#define MILS_TO_IU_SCALAR 25.4e3 // Pcbnew in nanometers.
#else
#define MILS_TO_IU_SCALAR 10.0 // Pcbnew in deci-mils.
#endif
#else
#define MILS_TO_IU_SCALAR 1.0 // Eeschema and anything else.
#endif
#include <convert_to_biu.h>
/**
......
......@@ -39,6 +39,7 @@
#include <wx/fileconf.h>
#include <richio.h>
#include <convert_to_biu.h>
#if !wxUSE_PRINTING_ARCHITECTURE
# error "You must use '--enable-printarch' in your wx library configuration."
......@@ -296,18 +297,9 @@ public:
// Accessors returning "Internal Units (IU)". IUs are mils in EESCHEMA,
// and either deci-mils or nanometers in PCBNew.
#if defined(PCBNEW)
# if defined(KICAD_NANOMETRE)
int GetWidthIU() const { return 25400 * GetWidthMils(); }
int GetHeightIU() const { return 25400 * GetHeightMils(); }
# else
int GetWidthIU() const { return 10 * GetWidthMils(); }
int GetHeightIU() const { return 10 * GetHeightMils(); }
# endif
const wxSize GetSizeIU() const { return wxSize( GetWidthIU(), GetHeightIU() ); }
#elif defined(EESCHEMA)
int GetWidthIU() const { return GetWidthMils(); }
int GetHeightIU() const { return GetHeightMils(); }
#if defined(PCBNEW) || defined(EESCHEMA) || defined(GERBVIEW)
int GetWidthIU() const { return MILS_TO_IU_SCALING_FACTOR * GetWidthMils(); }
int GetHeightIU() const { return MILS_TO_IU_SCALING_FACTOR * GetHeightMils(); }
const wxSize GetSizeIU() const { return wxSize( GetWidthIU(), GetHeightIU() ); }
#endif
......
......@@ -9,20 +9,37 @@
/**
* @brief inline convert functions to convert a value in decimils (or mils)
* to the internal unit used in pcbnew or cvpcb(nanometer or decimil)
* @brief some define and functions to convert a value in mils, decimils or mm
* to the internal unit used in pcbnew, cvpcb or gerbview (nanometer or decimil)
* depending on compil option
*/
#if defined(PCBNEW) || defined(CVPCB)
/// Scaling factor to convert mils to internal units.
#if defined(PCBNEW) || defined(CVPCB) || defined(GERBVIEW)
#if defined( USE_PCBNEW_NANOMETRES )
#if defined(GERBVIEW)
#define MM_TO_IU_SCALING_FACTOR 1e5 // Gerbview uses 10 micrometer.
#else
#define MM_TO_IU_SCALING_FACTOR 1e6 // Pcbnew uses nanometers.
#endif
#define MILS_TO_IU_SCALING_FACTOR ( MM_TO_IU_SCALING_FACTOR * 0.0254 )
#define DECIMILS_TO_IU_SCALING_FACTOR (MM_TO_IU_SCALING_FACTOR * 0.00254 )
#else // Pcbnew in deci-mils.
#define DECIMILS_TO_IU_SCALING_FACTOR 1
#define MILS_TO_IU_SCALING_FACTOR 10.0
#define MM_TO_IU_SCALING_FACTOR (1e4 / 25.4)
#endif
/// Convert mils to PCBNEW internal units (iu).
inline int Mils2iu( int mils )
{
#if defined( USE_PCBNEW_NANOMETRES )
double x = mils * 25.4e3;
double x = mils * MILS_TO_IU_SCALING_FACTOR;
return int( x < 0 ? x - 0.5 : x + 0.5 );
#else
return mils * 10;
return mils * MILS_TO_IU_SCALING_FACTOR;
#endif
}
......@@ -30,14 +47,17 @@ inline int Mils2iu( int mils )
inline int DMils2iu( int dmils )
{
#if defined( USE_PCBNEW_NANOMETRES )
double x = dmils * 25.4e2;
double x = dmils * DECIMILS_TO_IU_SCALING_FACTOR;
return int( x < 0 ? x - 0.5 : x + 0.5 );
#else
return dmils;
#endif
}
#elif defined(EESCHEMA)
#else // Eeschema and anything else.
#define MILS_TO_IU_SCALING_FACTOR 1.0
#define MM_TO_IU_SCALING_FACTOR (MILS_TO_IU_SCALING_FACTOR / 0.0254)
inline int Mils2iu( int mils )
{
return mils;
......
......@@ -203,7 +203,10 @@ set(PCBNEW_SRCS
###
# We need some extra sources from common
###
#set(PCBNEW_COMMON_SRCS ../common/dialogs/dialog_page_settings.cpp )
set(PCBNEW_COMMON_SRCS
../common/dialogs/dialog_page_settings.cpp
../common/base_units.cpp
)
###
......
......@@ -19,15 +19,11 @@
#include <pcbnew_id.h>
#if defined( USE_PCBNEW_NANOMETRES )
#define ZOOM_FACTOR( x ) ( x * 25.4e2 )
#define DMIL_GRID( x ) wxRealPoint( x * 25.4e2, x * 25.4e2 )
#define MM_GRID( x ) wxRealPoint( x * 1e6, x * 1e6 )
#else
#define ZOOM_FACTOR( x ) x
#define DMIL_GRID( x ) wxRealPoint( x , x )
#define MM_GRID( x ) wxRealPoint( x * 1e4 / 25.4, x * 1e4 / 25.4 )
#endif
#define ZOOM_FACTOR( x ) ( x * DECIMILS_TO_IU_SCALING_FACTOR )
#define DMIL_GRID( x ) wxRealPoint( x * DECIMILS_TO_IU_SCALING_FACTOR,\
x * DECIMILS_TO_IU_SCALING_FACTOR )
#define MM_GRID( x ) wxRealPoint( x * MM_TO_IU_SCALING_FACTOR,\
x * MM_TO_IU_SCALING_FACTOR )
/**
......@@ -110,7 +106,6 @@ PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) :
{
wxSize displayz = wxGetDisplaySize();
for( unsigned i = 0; i < DIM( pcbZoomList ); ++i )
m_ZoomList.Add( pcbZoomList[i] );
......@@ -124,7 +119,7 @@ PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) :
m_Route_Layer_TOP = LAYER_N_FRONT; // default layers pair for vias (bottom to top)
m_Route_Layer_BOTTOM = LAYER_N_BACK;
SetZoom( ZOOM_FACTOR( 150 ) ); // a default value for zoom
SetZoom( ZOOM_FACTOR( 120 ) ); // a default value for zoom
InitDataPoints( aPageSizeIU );
}
......@@ -138,11 +133,7 @@ PCB_SCREEN::~PCB_SCREEN()
int PCB_SCREEN::MilsToIuScalar()
{
#if defined( USE_PCBNEW_NANOMETRES )
return 25400;
#else
return 10;
#endif
return (int)MILS_TO_IU_SCALING_FACTOR;
}
......
......@@ -271,7 +271,7 @@ bool DIALOG_SVG_PRINT::DrawPage( const wxString& FullFileName,
g_DrawBgColor = WHITE;
if( aPrint_Frame_Ref )
m_Parent->TraceWorkSheet( &dc, screen, s_Parameters.m_PenDefaultSize, MILS_TO_IU_SCALAR );
m_Parent->TraceWorkSheet( &dc, screen, s_Parameters.m_PenDefaultSize, MILS_TO_IU_SCALING_FACTOR );
m_Parent->PrintPage( &dc, m_PrintMaskLayer, false, &s_Parameters);
g_DrawBgColor = bg_color;
......
......@@ -2682,7 +2682,7 @@ void LEGACY_PLUGIN::init( PROPERTIES* aProperties )
// conversion factor for saving RAM BIUs to KICAD legacy file format.
#if defined( USE_PCBNEW_NANOMETRES )
biuToDisk = 1/1000000.0; // BIUs are nanometers & file is mm
biuToDisk = 1/MM_TO_IU_SCALING_FACTOR; // BIUs are nanometers & file is mm
#else
biuToDisk = 1.0; // BIUs are deci-mils
#endif
......@@ -2694,11 +2694,8 @@ void LEGACY_PLUGIN::init( PROPERTIES* aProperties )
// then, during the file loading process, to start a conversion from
// mm to nanometers.
#if defined( USE_PCBNEW_NANOMETRES )
diskToBiu = 2540.0; // BIUs are nanometers
#else
diskToBiu = 1.0; // BIUs are deci-mils
#endif
diskToBiu = DECIMILS_TO_IU_SCALING_FACTOR; // BIUs are nanometers if USE_PCBNEW_NANOMETRES
// or BIUs are deci-mils
}
......
......@@ -180,12 +180,8 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage()
if( userscale == 0 ) // fit in page
{
// Margin = 0.4 inch
#if defined(KICAD_NANOMETRE)
int extra_margin = int( 0.4 * 25400 ); // nanometers
#else
int extra_margin = int( 0.4 * 1000 ); // deci-mils
#endif
// Margin = 10mm
int extra_margin = int( 10 * MM_TO_IU_SCALING_FACTOR ); // deci-mils
pageSizeIU.x = bbbox.GetWidth() + extra_margin * 2;
pageSizeIU.y = bbbox.GetHeight() + extra_margin * 2;
......@@ -278,7 +274,8 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage()
int bg_color = g_DrawBgColor;
if( m_PrintParams.m_Print_Sheet_Ref )
m_Parent->TraceWorkSheet( dc, screen, m_PrintParams.m_PenDefaultSize, MILS_TO_IU_SCALAR );
m_Parent->TraceWorkSheet( dc, screen, m_PrintParams.m_PenDefaultSize,
MILS_TO_IU_SCALING_FACTOR );
if( printMirror )
{
......
......@@ -171,10 +171,10 @@ static inline double scale( int kicadDist )
#if defined(USE_PCBNEW_NANOMETRES)
// nanometers to um
return kicadDist / 1000.0;
return kicadDist / ( MM_TO_IU_SCALING_FACTOR / 1000.0 );
// nanometers to mils
// return kicadDist/25400.0;
// return kicadDist/MILS_TO_IU_SCALING_FACTOR;
#else
// deci-mils to mils.
......@@ -185,11 +185,7 @@ static inline double scale( int kicadDist )
/// Convert integer internal units to float um
static inline double IU2um( int kicadDist )
{
#if defined(USE_PCBNEW_NANOMETRES)
return kicadDist / 1000.0;
#else
return kicadDist * 25.4e-1;
#endif
return kicadDist * (1000.0 / MM_TO_IU_SCALING_FACTOR);
}
......
......@@ -67,7 +67,7 @@ void FOOTPRINT_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
GRSetDrawMode( DC, GR_COPY );
m_canvas->DrawBackGround( DC );
TraceWorkSheet( DC, screen, 0, MILS_TO_IU_SCALAR );
TraceWorkSheet( DC, screen, 0, MILS_TO_IU_SCALING_FACTOR );
// Redraw the footprints
for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
......@@ -105,7 +105,7 @@ void PCB_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
m_canvas->DrawBackGround( DC );
TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALAR );
TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR );
GetBoard()->Draw( m_canvas, DC, GR_OR | GR_ALLOW_HIGHCONTRAST);
......
......@@ -357,9 +357,7 @@ int CPolyLine::MakeKboolPoly( int aStart_contour, int aEnd_contour, std::vector<
else
{
// style is ARC_CW or ARC_CCW
int n; // number of steps for arcs
n = ( abs( x2 - x1 ) + abs( y2 - y1 ) ) / (CArc::MAX_STEP);
n = MAX( n, CArc::MIN_STEPS ); // or at most 5 degrees of arc
int n = CArc::ARC_STEPS;
n_vertices += n;
n_arcs++;
}
......@@ -392,8 +390,7 @@ int CPolyLine::MakeKboolPoly( int aStart_contour, int aEnd_contour, std::vector<
{
// style is arc_cw or arc_ccw
int n; // number of steps for arcs
n = ( abs( x2 - x1 ) + abs( y2 - y1 ) ) / (CArc::MAX_STEP);
n = MAX( n, CArc::MIN_STEPS ); // or at most 5 degrees of arc
n = CArc::ARC_STEPS;
double xo, yo, theta1, theta2, a, b;
a = fabs( (double) (x1 - x2) );
b = fabs( (double) (y1 - y2) );
......
......@@ -77,8 +77,7 @@ public:
class CArc
{
public:
enum { MAX_STEP = 50 * 25400 }; // max step is 20 mils
enum { MIN_STEPS = 18 }; // min step is 5 degrees
enum { ARC_STEPS = 16 }; // arc approximation step is 16 segm / 90 degres
int style;
int xi, yi, xf, yf;
int n_steps; // number of straight-line segments in gpc_poly
......
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