Commit bf5802f1 authored by Wayne Stambaugh's avatar Wayne Stambaugh

Removal of internal units.

* Remove internal units from BASE_SCREEN and it's derivatives.
* Remove internal units from EDA_DRAW_FRAME and it's derivatives.
* Use build time code to replace internal units conversions.
* Fix scaling bug in page layout sample window that I created in my
  last commit.
parent 6468805c
......@@ -33,6 +33,7 @@
#include <base_struct.h>
#include <class_base_screen.h>
#include <id.h>
#include <base_units.h>
#define CURSOR_SIZE 12 /// size of the cross cursor.
......@@ -86,12 +87,6 @@ void BASE_SCREEN::InitDataPoints( const wxSize& aPageSizeIU )
}
int BASE_SCREEN::GetInternalUnits( void )
{
return EESCHEMA_INTERNAL_UNIT;
}
double BASE_SCREEN::GetScalingFactor() const
{
double scale = 1.0 / GetZoom();
......@@ -320,30 +315,14 @@ void BASE_SCREEN::AddGrid( const wxRealPoint& size, int id )
void BASE_SCREEN::AddGrid( const wxRealPoint& size, EDA_UNITS_T aUnit, int id )
{
double x, y;
wxRealPoint new_size;
GRID_TYPE new_grid;
switch( aUnit )
{
case MILLIMETRES:
x = size.x / 25.4;
y = size.y / 25.4;
break;
default:
case INCHES:
case UNSCALED_UNITS:
x = size.x;
y = size.y;
break;
}
new_size.x = x * GetInternalUnits();
new_size.y = y * GetInternalUnits();
new_size.x = From_User_Unit( aUnit, size.x );
new_size.y = From_User_Unit( aUnit, size.y );
new_grid.m_Id = id;
new_grid.m_Size = new_size;
AddGrid( new_grid );
}
......
......@@ -167,7 +167,7 @@ void PutValueInLocalUnits( wxTextCtrl& aTextCtr, int aValue )
}
int From_User_Unit( EDA_UNITS_T aUnit, double aValue )
double From_User_Unit( EDA_UNITS_T aUnit, double aValue )
{
double value;
......@@ -187,7 +187,7 @@ int From_User_Unit( EDA_UNITS_T aUnit, double aValue )
value = aValue;
}
return wxRound( value );
return value;
}
......
......@@ -30,9 +30,8 @@ void EDA_DRAW_FRAME::PlotWorkSheet( PLOTTER* plotter, BASE_SCREEN* screen )
wxPoint pos, ref;
EDA_COLOR_T color;
// paper is sized in mils. Here is a conversion factor to
// scale mils to internal units.
int conv_unit = screen->GetInternalUnits() / 1000;
// Paper is sized in mils. Here is a conversion factor to scale mils to internal units.
int conv_unit = screen->MilsToIuScalar();
wxString msg;
wxSize text_size;
......
......@@ -72,7 +72,7 @@ bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame )
BASE_SCREEN* screen = aFrame->GetCanvas()->GetScreen();
/* scale is the ratio resolution/internal units */
float scale = 82.0 / aFrame->GetInternalUnits();
float scale = 82.0 / 1000.0 / (double) screen->MilsToIuScalar();
if( screen->IsBlockActive() )
{
......
......@@ -26,7 +26,7 @@
*/
#include <fctsys.h>
#include <macros.h> // DIM()
#include <macros.h> // DIM()
#include <common.h>
#include <gr_basic.h>
#include <base_struct.h>
......@@ -34,6 +34,7 @@
#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>
......@@ -118,10 +119,12 @@ void DIALOG_PAGES_SETTINGS::initDialog()
// initalize page format choice box and page format list.
// The first shows translated strings, the second contains not tralated strings
m_paperSizeComboBox->Clear();
for( unsigned ii = 0; ; ii++ )
{
if( pageFmts[ii].IsEmpty() )
break;
m_pageFmt.Add( pageFmts[ii] );
m_paperSizeComboBox->Append( wxGetTranslation( pageFmts[ii] ) );
}
......@@ -137,8 +140,8 @@ void DIALOG_PAGES_SETTINGS::initDialog()
msg.Printf( format, m_Screen->m_ScreenNumber );
m_TextSheetNumber->SetLabel( msg );
#else
m_TextSheetCount->Show(false);
m_TextSheetNumber->Show(false);
m_TextSheetCount->Show( false );
m_TextSheetNumber->Show( false );
#endif
m_pageInfo = m_Parent->GetPageSettings();
......@@ -251,10 +254,11 @@ void DIALOG_PAGES_SETTINGS::OnOkClick( wxCommandEvent& event )
{
m_save_flag = false;
SavePageSettings( event );
if( m_save_flag )
{
m_modified = true;
Close( true );
m_modified = true;
Close( true );
}
}
......@@ -268,9 +272,12 @@ void DIALOG_PAGES_SETTINGS::OnCancelClick( wxCommandEvent& event )
void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
{
int idx = m_paperSizeComboBox->GetSelection();
if( idx < 0 )
idx = 0;
const wxString paperType = m_pageFmt[idx];
if( paperType.Contains( PAGE_INFO::Custom ) )
{
m_orientationComboBox->Enable( false );
......@@ -280,14 +287,17 @@ void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
else
{
m_orientationComboBox->Enable( true );
if( paperType.Contains( wxT( "A4" ) ) && IsGOST() )
{
m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
m_orientationComboBox->Enable( false );
}
}
m_TextUserSizeX->Enable( false );
m_TextUserSizeY->Enable( false );
}
GetPageLayoutInfoFromDialog();
UpdatePageLayoutExample();
}
......@@ -407,8 +417,10 @@ void DIALOG_PAGES_SETTINGS::SavePageSettings( wxCommandEvent& event )
m_save_flag = true;
int idx = m_paperSizeComboBox->GetSelection();
if( idx < 0 )
idx = 0;
const wxString paperType = m_pageFmt[idx];
if( paperType.Contains( PAGE_INFO::Custom ) )
......@@ -416,6 +428,7 @@ void DIALOG_PAGES_SETTINGS::SavePageSettings( wxCommandEvent& event )
GetCustomSizeMilsFromDialog();
retSuccess = m_pageInfo.SetType( PAGE_INFO::Custom );
if( retSuccess )
{
if( m_layout_size.x < MIN_PAGE_SIZE || m_layout_size.y < MIN_PAGE_SIZE ||
......@@ -432,6 +445,7 @@ limits\n%.1f - %.1f %s!\nSelect another custom paper size?" ),
m_save_flag = false;
return;
}
m_layout_size.x = Clamp( MIN_PAGE_SIZE, m_layout_size.x, MAX_PAGE_SIZE );
m_layout_size.y = Clamp( MIN_PAGE_SIZE, m_layout_size.y, MAX_PAGE_SIZE );
}
......@@ -595,6 +609,7 @@ void DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample()
}
m_page_bitmap = new wxBitmap( lyWidth + 1, lyHeight + 1 );
if( m_page_bitmap->IsOk() )
{
// Save current clip box and temporary expand it.
......@@ -602,7 +617,8 @@ 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 = m_Parent->GetInternalUnits() / 1000;
int appScale = MILS_TO_IU_SCALAR;
double scaleW = (double) lyWidth / clamped_layout_size.x / appScale;
double scaleH = (double) lyHeight / clamped_layout_size.y / appScale;
......@@ -630,7 +646,7 @@ void DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample()
m_Parent->TraceWorkSheet( (wxDC*) &memDC, dummySize, pointLeftTop, pointRightBottom,
emptyString, emptyString, m_tb, m_Screen->m_NumberOfScreen,
m_Screen->m_ScreenNumber, 1, LIGHTGRAY, RED );
m_Screen->m_ScreenNumber, 1, appScale, LIGHTGRAY, RED );
memDC.SelectObject( wxNullBitmap );
m_PageLayoutExampleBitmap->SetBitmap( *m_page_bitmap );
......@@ -648,14 +664,17 @@ void DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample()
void DIALOG_PAGES_SETTINGS::GetPageLayoutInfoFromDialog()
{
int idx = m_paperSizeComboBox->GetSelection();
if( idx < 0 )
idx = 0;
const wxString paperType = m_pageFmt[idx];
// here we assume translators will keep original paper size spellings
if( paperType.Contains( PAGE_INFO::Custom ) )
{
GetCustomSizeMilsFromDialog();
if( m_layout_size.x && m_layout_size.y )
{
if( m_layout_size.x < m_layout_size.y )
......@@ -687,6 +706,7 @@ void DIALOG_PAGES_SETTINGS::GetPageLayoutInfoFromDialog()
};
unsigned i;
for( i=0; i < DIM( papers ); ++i )
{
if( paperType.Contains( *papers[i] ) )
......
......@@ -110,7 +110,6 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( wxWindow* father, int idtype, const wxString& ti
m_snapToGrid = true;
// Internal units per inch: = 1000 for schema, = 10000 for PCB
m_internalUnits = EESCHEMA_INTERNAL_UNIT;
minsize.x = 470;
minsize.y = 350 + m_MsgFrameHeight;
......
......@@ -215,7 +215,7 @@ bool DIALOG_SVG_PRINT::DrawSVGPage( EDA_DRAW_FRAME* frame,
LOCALE_IO toggle;
float dpi = (float) frame->GetInternalUnits();
float dpi = 1000.0;
KicadSVGFileDC dc( FullFileName, sheetSize.x, sheetSize.y, dpi );
EDA_RECT tmp = *panel->GetClipBox();
......@@ -227,6 +227,7 @@ bool DIALOG_SVG_PRINT::DrawSVGPage( EDA_DRAW_FRAME* frame,
wxSize( 0x7FFFFF0, 0x7FFFFF0 ) ) );
screen->m_IsPrinting = true;
if( frame->IsType( SCHEMATIC_FRAME ) )
screen->Draw( panel, &dc, GR_COPY );
......
......@@ -96,7 +96,7 @@ void PutValueInLocalUnits( wxTextCtrl& aTextCtr, int aValue );
/**
* Return in internal units the value "val" given in inch or mm
*/
int From_User_Unit( EDA_UNITS_T aUnit, double aValue );
double From_User_Unit( EDA_UNITS_T aUnit, double aValue );
/**
* Function ReturnValueFromeString
......
......@@ -158,14 +158,14 @@ public:
wxString GetFileName() const { return m_fileName; }
/**
* Function GetInternalUnits
* @return the screen units scalar.
* Function MilsToIuScalar
* returns the scalar required to convert mils to internal units.
*
* Default implementation returns scalar used for schematic screen. The
* internal units used by the schematic screen is 1 mil (0.001"). Override
* this in derived classes that require internal units other than 1 mil.
* @note This is a temporary hack until the derived objects SCH_SCREEN and PCB_SCREEN
* no longer need to be derived from BASE_SCREEN. I does allow removal of the
* obsolete GetInternalUnits function.
*/
virtual int GetInternalUnits( void );
virtual int MilsToIuScalar() { return 1; }
/**
* Function GetCrossHairPosition
......
......@@ -37,7 +37,7 @@ public:
void SetPreviousZoom();
void SetLastZoom();
virtual int GetInternalUnits();
virtual int MilsToIuScalar();
/**
* Function GetCurItem
......@@ -57,7 +57,6 @@ public:
*/
void SetCurItem( BOARD_ITEM* aItem ) { BASE_SCREEN::SetCurItem( (EDA_ITEM*)aItem ); }
/* full undo redo management : */
// use BASE_SCREEN::ClearUndoRedoList()
......
......@@ -387,10 +387,6 @@ protected:
/// The area to draw on.
EDA_DRAW_PANEL* m_canvas;
/// Internal units count that is equivalent to 1 inch. Set to 1000 (0.001") for
/// schematic drawing and 10000 (0.0001") for PCB drawing.
int m_internalUnits;
/// Tool ID of previously active draw tool bar button.
int m_lastDrawToolId;
......@@ -477,8 +473,6 @@ public:
void SetShowBorderAndTitleBlock( bool aShow ) { m_showBorderAndTitleBlock = aShow; }
int GetInternalUnits() const { return m_internalUnits; }
EDA_DRAW_PANEL* GetCanvas() { return m_canvas; }
virtual wxString GetScreenDesc();
......
......@@ -82,7 +82,6 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( wxWindow* father,
long style) :
EDA_DRAW_FRAME( father, idtype, title, pos, size, style )
{
m_internalUnits = PCB_INTERNAL_UNIT; // Internal unit = 1/10000 inch
m_Pcb = NULL;
m_DisplayPadFill = true; // How to draw pads
......
......@@ -125,9 +125,13 @@ PCB_SCREEN::~PCB_SCREEN()
}
int PCB_SCREEN::GetInternalUnits()
int PCB_SCREEN::MilsToIuScalar()
{
return PCB_INTERNAL_UNIT;
#if defined( USE_PCBNEW_NANOMETRES )
return 25400;
#else
return 10;
#endif
}
......
......@@ -239,7 +239,14 @@ bool DIALOG_SVG_PRINT::DrawPage( const wxString& FullFileName,
screen->m_StartVisu.x = screen->m_StartVisu.y = 0;
screen->SetScalingFactor( 1.0 );
float dpi = (float)m_Parent->GetInternalUnits();
float dpi;
#if defined( USE_PCBNEW_NANOMETRES )
dpi = 25.4e6;
#else
dpi = 10000.0;
#endif
EDA_DRAW_PANEL* panel = m_Parent->GetCanvas();
......
......@@ -473,7 +473,7 @@ void DIALOG_DESIGN_RULES::InitializeRulesSelectionBoxes()
/* Initialize the rules list from board
*/
static void class2gridRow( wxGrid* grid, int row, NETCLASS* nc, int units )
static void class2gridRow( wxGrid* grid, int row, NETCLASS* nc )
{
wxString msg;
......@@ -515,7 +515,7 @@ void DIALOG_DESIGN_RULES::InitRulesList()
}
// enter the Default NETCLASS.
class2gridRow( m_grid, 0, netclasses.GetDefault(), m_Parent->GetInternalUnits() );
class2gridRow( m_grid, 0, netclasses.GetDefault() );
// enter others netclasses
int row = 1;
......@@ -523,12 +523,12 @@ void DIALOG_DESIGN_RULES::InitRulesList()
{
NETCLASS* netclass = i->second;
class2gridRow( m_grid, row, netclass, m_Parent->GetInternalUnits() );
class2gridRow( m_grid, row, netclass );
}
}
static void gridRow2class( wxGrid* grid, int row, NETCLASS* nc, int units )
static void gridRow2class( wxGrid* grid, int row, NETCLASS* nc )
{
#define MYCELL( col ) \
ReturnValueFromString( g_UserUnit, grid->GetCellValue( row, col ) )
......@@ -552,7 +552,7 @@ void DIALOG_DESIGN_RULES::CopyRulesListToBoard()
netclasses.Clear();
// Copy the default NetClass:
gridRow2class( m_grid, 0, netclasses.GetDefault(), m_Parent->GetInternalUnits() );
gridRow2class( m_grid, 0, netclasses.GetDefault() );
// Copy other NetClasses :
for( int row = 1; row < m_grid->GetNumberRows(); ++row )
......@@ -565,13 +565,13 @@ void DIALOG_DESIGN_RULES::CopyRulesListToBoard()
// Should not occur because OnAddNetclassClick() tests for existing NetClass names
wxString msg;
msg.Printf( wxT( "CopyRulesListToBoard(): The NetClass \"%s\" already exists. Skip" ),
GetChars( m_grid->GetRowLabelValue( row ) ) );
GetChars( m_grid->GetRowLabelValue( row ) ) );
wxMessageBox( msg );
delete nc;
continue;
}
gridRow2class( m_grid, row, nc, m_Parent->GetInternalUnits() );
gridRow2class( m_grid, row, nc );
}
// Now read all nets and push them in the corresponding netclass net buffer
......
......@@ -315,8 +315,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title,
icon.CopyFromBitmap( KiBitmap( icon_pcbnew_xpm ) );
SetIcon( icon );
m_internalUnits = PCB_INTERNAL_UNIT; // Unites internes = 1/10000 inch
SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU() ) );
// PCB drawings start in the upper left corner.
......
......@@ -16,9 +16,6 @@
class DIALOG_SET_GRID : public DIALOG_SET_GRID_BASE
{
public:
int m_internalUnits;
public:
DIALOG_SET_GRID( wxWindow* parent, const wxPoint& pos );
~DIALOG_SET_GRID() { }
......@@ -41,7 +38,6 @@ void PCB_BASE_FRAME::InstallGridFrame( const wxPoint& pos )
{
DIALOG_SET_GRID dlg( this, pos );
dlg.m_internalUnits = m_internalUnits;
dlg.SetGridUnits( m_UserGridUnit );
dlg.SetGridSize( m_UserGridSize );
dlg.SetGridOrigin( GetScreen()->m_GridOrigin );
......
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