2012-03-26 21:45:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2010 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
|
2011-09-30 18:15:37 +00:00
|
|
|
*/
|
2010-03-14 10:34:40 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
/**
|
|
|
|
* @file dialog_page_settings.cpp
|
2010-03-14 10:34:40 +00:00
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
2012-04-16 23:31:29 +00:00
|
|
|
#include <macros.h> // DIM()
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <common.h>
|
2012-03-26 21:45:05 +00:00
|
|
|
#include <gr_basic.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <base_struct.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <class_title_block.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <class_base_screen.h>
|
|
|
|
|
|
|
|
#include <wx/valgen.h>
|
2011-12-31 05:44:00 +00:00
|
|
|
#include <wx/tokenzr.h>
|
2010-03-14 10:34:40 +00:00
|
|
|
|
|
|
|
#ifdef EESCHEMA
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_sch_screen.h>
|
|
|
|
#include <general.h>
|
2010-03-14 10:34:40 +00:00
|
|
|
#endif
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialog_page_settings.h>
|
2010-03-14 10:34:40 +00:00
|
|
|
|
2013-01-18 06:04:25 +00:00
|
|
|
|
2012-03-27 16:41:13 +00:00
|
|
|
// List of page formats.
|
|
|
|
// should be statically initialized, because we need both
|
|
|
|
// the translated and the not translated version.
|
|
|
|
// when displayed in dialog we should explicitely call wxGetTranslation()
|
|
|
|
// to show the translated version.
|
|
|
|
const wxString pageFmts[] =
|
|
|
|
{
|
|
|
|
_("A4 210x297mm"),
|
|
|
|
_("A3 297x420mm"),
|
|
|
|
_("A2 420x594mm"),
|
|
|
|
_("A1 594x841mm"),
|
|
|
|
_("A0 841x1189mm"),
|
|
|
|
_("A 8.5x11in"),
|
|
|
|
_("B 11x17in"),
|
|
|
|
_("C 17x22in"),
|
|
|
|
_("D 22x34in"),
|
|
|
|
_("E 34x44in"),
|
|
|
|
_("USLetter 8.5x11in"),
|
|
|
|
_("USLegal 8.5x14in"),
|
|
|
|
_("USLedger 11x17in"),
|
|
|
|
_("User (Custom)"),
|
|
|
|
wxT("") // end of list
|
|
|
|
};
|
2010-03-14 10:34:40 +00:00
|
|
|
|
2011-03-14 15:17:18 +00:00
|
|
|
void EDA_DRAW_FRAME::Process_PageSettings( wxCommandEvent& event )
|
2010-03-14 10:34:40 +00:00
|
|
|
{
|
2011-03-14 15:17:18 +00:00
|
|
|
DIALOG_PAGES_SETTINGS frame( this );
|
2010-03-14 10:34:40 +00:00
|
|
|
int diag = frame.ShowModal();
|
2011-03-14 15:17:18 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas && diag )
|
|
|
|
m_canvas->Refresh();
|
2010-03-14 10:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-14 15:17:18 +00:00
|
|
|
DIALOG_PAGES_SETTINGS::DIALOG_PAGES_SETTINGS( EDA_DRAW_FRAME* parent ) :
|
2011-12-22 21:57:50 +00:00
|
|
|
DIALOG_PAGES_SETTINGS_BASE( parent ),
|
2012-03-26 21:45:05 +00:00
|
|
|
m_initialized( false )
|
2010-03-14 10:34:40 +00:00
|
|
|
{
|
2011-03-14 15:17:18 +00:00
|
|
|
m_Parent = parent;
|
|
|
|
m_Screen = m_Parent->GetScreen();
|
2011-12-22 21:57:50 +00:00
|
|
|
m_modified = false;
|
2012-03-26 21:45:05 +00:00
|
|
|
m_page_bitmap = NULL;
|
|
|
|
m_tb = m_Parent->GetTitleBlock();
|
2013-01-19 09:58:25 +00:00
|
|
|
m_customFmt = false;
|
2010-03-14 10:34:40 +00:00
|
|
|
|
2011-03-14 15:17:18 +00:00
|
|
|
initDialog();
|
2010-03-14 10:34:40 +00:00
|
|
|
|
2011-03-14 15:17:18 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
2010-03-14 10:34:40 +00:00
|
|
|
Centre();
|
|
|
|
}
|
|
|
|
|
2011-03-14 15:17:18 +00:00
|
|
|
|
2010-03-14 10:34:40 +00:00
|
|
|
DIALOG_PAGES_SETTINGS::~DIALOG_PAGES_SETTINGS()
|
|
|
|
{
|
2012-03-26 21:45:05 +00:00
|
|
|
if( m_page_bitmap )
|
|
|
|
delete m_page_bitmap;
|
2010-03-14 10:34:40 +00:00
|
|
|
}
|
|
|
|
|
2011-03-14 15:17:18 +00:00
|
|
|
|
2010-03-14 10:34:40 +00:00
|
|
|
void DIALOG_PAGES_SETTINGS::initDialog()
|
|
|
|
{
|
2011-12-22 21:57:50 +00:00
|
|
|
wxString msg;
|
2012-03-26 21:45:05 +00:00
|
|
|
double customSizeX;
|
|
|
|
double customSizeY;
|
2010-03-14 10:34:40 +00:00
|
|
|
|
2012-03-27 16:41:13 +00:00
|
|
|
// initalize page format choice box and page format list.
|
2013-01-19 09:58:25 +00:00
|
|
|
// The first shows translated strings, the second contains not translated strings
|
2012-03-27 16:41:13 +00:00
|
|
|
m_paperSizeComboBox->Clear();
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-27 16:41:13 +00:00
|
|
|
for( unsigned ii = 0; ; ii++ )
|
|
|
|
{
|
|
|
|
if( pageFmts[ii].IsEmpty() )
|
|
|
|
break;
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-27 16:41:13 +00:00
|
|
|
m_pageFmt.Add( pageFmts[ii] );
|
|
|
|
m_paperSizeComboBox->Append( wxGetTranslation( pageFmts[ii] ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#ifdef EESCHEMA
|
2012-10-04 06:57:15 +00:00
|
|
|
// Init display value for schematic sub-sheet number
|
2010-03-14 10:34:40 +00:00
|
|
|
wxString format = m_TextSheetCount->GetLabel();
|
2012-05-27 00:19:12 +00:00
|
|
|
msg.Printf( format, m_Screen->m_NumberOfScreens );
|
2011-03-14 15:17:18 +00:00
|
|
|
m_TextSheetCount->SetLabel( msg );
|
2011-12-31 05:44:00 +00:00
|
|
|
|
2010-03-14 10:34:40 +00:00
|
|
|
format = m_TextSheetNumber->GetLabel();
|
2011-03-14 15:17:18 +00:00
|
|
|
msg.Printf( format, m_Screen->m_ScreenNumber );
|
|
|
|
m_TextSheetNumber->SetLabel( msg );
|
2012-01-23 04:33:36 +00:00
|
|
|
#else
|
2012-04-16 23:31:29 +00:00
|
|
|
m_TextSheetCount->Show( false );
|
|
|
|
m_TextSheetNumber->Show( false );
|
2012-01-23 04:33:36 +00:00
|
|
|
#endif
|
2010-03-14 10:34:40 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
m_pageInfo = m_Parent->GetPageSettings();
|
|
|
|
SetCurrentPageSizeSelection( m_pageInfo.GetType() );
|
|
|
|
m_orientationComboBox->SetSelection( m_pageInfo.IsPortrait() );
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2012-01-17 14:58:58 +00:00
|
|
|
// only a click fires the "selection changed" event, so have to fabricate this check
|
|
|
|
wxCommandEvent dummy;
|
2012-03-26 21:45:05 +00:00
|
|
|
OnPaperSizeChoice( dummy );
|
2012-01-16 04:11:43 +00:00
|
|
|
|
2013-01-19 09:58:25 +00:00
|
|
|
if( m_customFmt) // The custom value is defined by the page size
|
|
|
|
{
|
|
|
|
customSizeX = m_pageInfo.GetWidthMils();
|
|
|
|
customSizeY = m_pageInfo.GetHeightMils();
|
|
|
|
}
|
|
|
|
else // The custom value is set to a default value, or the last defined value
|
|
|
|
{
|
|
|
|
customSizeX = m_pageInfo.GetCustomWidthMils();
|
|
|
|
customSizeY = m_pageInfo.GetCustomHeightMils();
|
|
|
|
}
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
switch( g_UserUnit )
|
2010-03-14 10:34:40 +00:00
|
|
|
{
|
2010-07-12 14:07:09 +00:00
|
|
|
case MILLIMETRES:
|
2013-01-19 09:58:25 +00:00
|
|
|
customSizeX *= 25.4e-3;
|
|
|
|
customSizeY *= 25.4e-3;
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
msg.Printf( wxT( "%.2f" ), customSizeX );
|
2010-07-12 14:07:09 +00:00
|
|
|
m_TextUserSizeX->SetValue( msg );
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
msg.Printf( wxT( "%.2f" ), customSizeY );
|
2010-07-12 14:07:09 +00:00
|
|
|
m_TextUserSizeY->SetValue( msg );
|
|
|
|
break;
|
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
default:
|
2010-07-12 14:07:09 +00:00
|
|
|
case INCHES:
|
2013-01-19 09:58:25 +00:00
|
|
|
customSizeX /= 1000.0;
|
|
|
|
customSizeY /= 1000.0;
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
msg.Printf( wxT( "%.3f" ), customSizeX );
|
2010-07-12 14:07:09 +00:00
|
|
|
m_TextUserSizeX->SetValue( msg );
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
msg.Printf( wxT( "%.3f" ), customSizeY );
|
2010-07-12 14:07:09 +00:00
|
|
|
m_TextUserSizeY->SetValue( msg );
|
|
|
|
break;
|
2010-03-14 10:34:40 +00:00
|
|
|
}
|
2010-07-12 14:07:09 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
m_TextRevision->SetValue( m_tb.GetRevision() );
|
|
|
|
m_TextTitle->SetValue( m_tb.GetTitle() );
|
|
|
|
m_TextCompany->SetValue( m_tb.GetCompany() );
|
|
|
|
m_TextComment1->SetValue( m_tb.GetComment1() );
|
|
|
|
m_TextComment2->SetValue( m_tb.GetComment2() );
|
|
|
|
m_TextComment3->SetValue( m_tb.GetComment3() );
|
|
|
|
m_TextComment4->SetValue( m_tb.GetComment4() );
|
2010-03-14 10:34:40 +00:00
|
|
|
|
|
|
|
#ifndef EESCHEMA
|
2011-03-14 15:17:18 +00:00
|
|
|
m_RevisionExport->Show( false );
|
|
|
|
m_TitleExport->Show( false );
|
|
|
|
m_CompanyExport->Show( false );
|
|
|
|
m_Comment1Export->Show( false );
|
|
|
|
m_Comment2Export->Show( false );
|
|
|
|
m_Comment3Export->Show( false );
|
|
|
|
m_Comment4Export->Show( false );
|
2010-03-14 10:34:40 +00:00
|
|
|
#endif
|
2011-03-14 15:17:18 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
UpdatePageLayoutExample();
|
|
|
|
|
2011-03-14 15:17:18 +00:00
|
|
|
// Make the OK button the default.
|
|
|
|
m_sdbSizer1OK->SetDefault();
|
2012-03-26 21:45:05 +00:00
|
|
|
m_initialized = true;
|
2010-03-14 10:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnCloseWindow( wxCloseEvent& event )
|
|
|
|
{
|
2011-12-22 21:57:50 +00:00
|
|
|
EndModal( m_modified );
|
2010-03-14 10:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnOkClick( wxCommandEvent& event )
|
|
|
|
{
|
2012-03-26 21:45:05 +00:00
|
|
|
m_save_flag = false;
|
2010-03-14 10:34:40 +00:00
|
|
|
SavePageSettings( event );
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
if( m_save_flag )
|
|
|
|
{
|
2012-04-16 23:31:29 +00:00
|
|
|
m_modified = true;
|
|
|
|
Close( true );
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
2010-03-14 10:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnCancelClick( wxCommandEvent& event )
|
|
|
|
{
|
2011-03-14 15:17:18 +00:00
|
|
|
Close( true );
|
2010-03-14 10:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
|
2012-01-16 04:11:43 +00:00
|
|
|
{
|
2012-03-27 16:41:13 +00:00
|
|
|
int idx = m_paperSizeComboBox->GetSelection();
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-27 16:41:13 +00:00
|
|
|
if( idx < 0 )
|
|
|
|
idx = 0;
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-27 16:41:13 +00:00
|
|
|
const wxString paperType = m_pageFmt[idx];
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
if( paperType.Contains( PAGE_INFO::Custom ) )
|
2012-01-16 04:11:43 +00:00
|
|
|
{
|
2012-01-16 20:48:32 +00:00
|
|
|
m_orientationComboBox->Enable( false );
|
2012-03-26 21:45:05 +00:00
|
|
|
m_TextUserSizeX->Enable( true );
|
|
|
|
m_TextUserSizeY->Enable( true );
|
2013-01-19 09:58:25 +00:00
|
|
|
m_customFmt = true;
|
2012-01-16 04:11:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-16 20:48:32 +00:00
|
|
|
m_orientationComboBox->Enable( true );
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
if( paperType.Contains( wxT( "A4" ) ) && IsGOST() )
|
|
|
|
{
|
|
|
|
m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
|
|
|
|
m_orientationComboBox->Enable( false );
|
2012-04-16 23:31:29 +00:00
|
|
|
}
|
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
m_TextUserSizeX->Enable( false );
|
|
|
|
m_TextUserSizeY->Enable( false );
|
2013-01-19 09:58:25 +00:00
|
|
|
m_customFmt = false;
|
2012-01-16 04:11:43 +00:00
|
|
|
}
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
UpdatePageLayoutExample();
|
2012-01-16 04:11:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
void DIALOG_PAGES_SETTINGS::OnUserPageSizeXTextUpdated( wxCommandEvent& event )
|
2010-03-14 10:34:40 +00:00
|
|
|
{
|
2012-03-26 21:45:05 +00:00
|
|
|
if( m_initialized && m_TextUserSizeX->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
UpdatePageLayoutExample();
|
|
|
|
}
|
|
|
|
}
|
2010-03-14 10:34:40 +00:00
|
|
|
|
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
void DIALOG_PAGES_SETTINGS::OnUserPageSizeYTextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextUserSizeY->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
UpdatePageLayoutExample();
|
|
|
|
}
|
|
|
|
}
|
2012-01-15 21:07:01 +00:00
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
void DIALOG_PAGES_SETTINGS::OnPageOrientationChoice( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
UpdatePageLayoutExample();
|
|
|
|
}
|
|
|
|
}
|
2010-03-14 10:34:40 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnRevisionTextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextRevision->IsModified() )
|
2010-03-14 10:34:40 +00:00
|
|
|
{
|
2012-03-26 21:45:05 +00:00
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
m_tb.SetRevision( m_TextRevision->GetValue() );
|
|
|
|
UpdatePageLayoutExample();
|
|
|
|
}
|
|
|
|
}
|
2010-07-12 14:07:09 +00:00
|
|
|
|
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
void DIALOG_PAGES_SETTINGS::OnTitleTextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextTitle->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
m_tb.SetTitle( m_TextTitle->GetValue() );
|
|
|
|
UpdatePageLayoutExample();
|
2010-03-14 10:34:40 +00:00
|
|
|
}
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
2010-03-14 10:34:40 +00:00
|
|
|
|
2012-01-15 21:07:01 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
void DIALOG_PAGES_SETTINGS::OnCompanyTextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextCompany->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
m_tb.SetCompany( m_TextCompany->GetValue() );
|
|
|
|
UpdatePageLayoutExample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnComment1TextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextComment1->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
m_tb.SetComment1( m_TextComment1->GetValue() );
|
|
|
|
UpdatePageLayoutExample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnComment2TextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextComment2->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
m_tb.SetComment2( m_TextComment2->GetValue() );
|
|
|
|
UpdatePageLayoutExample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnComment3TextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextComment3->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
m_tb.SetComment3( m_TextComment3->GetValue() );
|
|
|
|
UpdatePageLayoutExample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnComment4TextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextComment4->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
m_tb.SetComment4( m_TextComment4->GetValue() );
|
|
|
|
UpdatePageLayoutExample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-16 20:48:32 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
void DIALOG_PAGES_SETTINGS::SavePageSettings( wxCommandEvent& event )
|
|
|
|
{
|
2012-03-27 16:41:13 +00:00
|
|
|
bool retSuccess = false;
|
2012-03-26 21:45:05 +00:00
|
|
|
|
|
|
|
m_save_flag = true;
|
|
|
|
|
2012-03-27 16:41:13 +00:00
|
|
|
int idx = m_paperSizeComboBox->GetSelection();
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-27 16:41:13 +00:00
|
|
|
if( idx < 0 )
|
|
|
|
idx = 0;
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-27 16:41:13 +00:00
|
|
|
const wxString paperType = m_pageFmt[idx];
|
2012-03-26 21:45:05 +00:00
|
|
|
|
2012-01-16 20:48:32 +00:00
|
|
|
if( paperType.Contains( PAGE_INFO::Custom ) )
|
|
|
|
{
|
2012-03-26 21:45:05 +00:00
|
|
|
GetCustomSizeMilsFromDialog();
|
|
|
|
|
|
|
|
retSuccess = m_pageInfo.SetType( PAGE_INFO::Custom );
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
if( retSuccess )
|
|
|
|
{
|
|
|
|
if( m_layout_size.x < MIN_PAGE_SIZE || m_layout_size.y < MIN_PAGE_SIZE ||
|
|
|
|
m_layout_size.x > MAX_PAGE_SIZE || m_layout_size.y > MAX_PAGE_SIZE )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format( _( "Selected custom paper size\nis out of the permissible \
|
|
|
|
limits\n%.1f - %.1f %s!\nSelect another custom paper size?" ),
|
|
|
|
g_UserUnit == INCHES ? MIN_PAGE_SIZE / 1000. : MIN_PAGE_SIZE * 25.4 / 1000,
|
|
|
|
g_UserUnit == INCHES ? MAX_PAGE_SIZE / 1000. : MAX_PAGE_SIZE * 25.4 / 1000,
|
|
|
|
g_UserUnit == INCHES ? _( "inches" ) : _( "mm" ) );
|
|
|
|
|
|
|
|
if( wxMessageBox( msg, _( "Warning!" ), wxYES_NO | wxICON_EXCLAMATION, this ) == wxYES )
|
|
|
|
{
|
|
|
|
m_save_flag = false;
|
|
|
|
return;
|
|
|
|
}
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
PAGE_INFO::SetCustomWidthMils( m_layout_size.x );
|
|
|
|
PAGE_INFO::SetCustomHeightMils( m_layout_size.y );
|
2012-04-05 18:27:56 +00:00
|
|
|
|
2012-04-02 18:11:00 +00:00
|
|
|
m_pageInfo.SetWidthMils( m_layout_size.x );
|
|
|
|
m_pageInfo.SetHeightMils( m_layout_size.y );
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
2012-01-16 20:48:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-26 21:45:05 +00:00
|
|
|
// search for longest common string first, e.g. A4 before A
|
|
|
|
if( paperType.Contains( PAGE_INFO::USLetter ) )
|
|
|
|
retSuccess = m_pageInfo.SetType( PAGE_INFO::USLetter );
|
|
|
|
else if( paperType.Contains( PAGE_INFO::USLegal ) )
|
|
|
|
retSuccess = m_pageInfo.SetType( PAGE_INFO::USLegal );
|
|
|
|
else if( paperType.Contains( PAGE_INFO::USLedger ) )
|
|
|
|
retSuccess = m_pageInfo.SetType( PAGE_INFO::USLedger );
|
|
|
|
else if( paperType.Contains( PAGE_INFO::GERBER ) )
|
|
|
|
retSuccess = m_pageInfo.SetType( PAGE_INFO::GERBER );
|
|
|
|
else if( paperType.Contains( PAGE_INFO::A4 ) )
|
|
|
|
retSuccess = m_pageInfo.SetType( PAGE_INFO::A4 );
|
|
|
|
else if( paperType.Contains( PAGE_INFO::A3 ) )
|
|
|
|
retSuccess = m_pageInfo.SetType( PAGE_INFO::A3 );
|
|
|
|
else if( paperType.Contains( PAGE_INFO::A2 ) )
|
|
|
|
retSuccess = m_pageInfo.SetType( PAGE_INFO::A2 );
|
|
|
|
else if( paperType.Contains( PAGE_INFO::A1 ) )
|
|
|
|
retSuccess = m_pageInfo.SetType( PAGE_INFO::A1 );
|
|
|
|
else if( paperType.Contains( PAGE_INFO::A0 ) )
|
|
|
|
retSuccess = m_pageInfo.SetType( PAGE_INFO::A0 );
|
|
|
|
else if( paperType.Contains( PAGE_INFO::A ) )
|
|
|
|
retSuccess = m_pageInfo.SetType( PAGE_INFO::A );
|
|
|
|
else if( paperType.Contains( PAGE_INFO::B ) )
|
|
|
|
retSuccess = m_pageInfo.SetType( PAGE_INFO::B );
|
|
|
|
else if( paperType.Contains( PAGE_INFO::C ) )
|
|
|
|
retSuccess = m_pageInfo.SetType( PAGE_INFO::C );
|
|
|
|
else if( paperType.Contains( PAGE_INFO::D ) )
|
|
|
|
retSuccess = m_pageInfo.SetType( PAGE_INFO::D );
|
|
|
|
else if( paperType.Contains( PAGE_INFO::E ) )
|
|
|
|
retSuccess = m_pageInfo.SetType( PAGE_INFO::E );
|
|
|
|
|
|
|
|
if( retSuccess )
|
2012-01-16 20:48:32 +00:00
|
|
|
{
|
2012-03-26 21:45:05 +00:00
|
|
|
int choice = m_orientationComboBox->GetSelection();
|
|
|
|
m_pageInfo.SetPortrait( choice != 0 );
|
2012-01-16 20:48:32 +00:00
|
|
|
}
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
2012-01-17 14:58:58 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
if( !retSuccess )
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( false, wxT( "the translation for paper size must preserve original spellings" ) );
|
|
|
|
m_pageInfo.SetType( PAGE_INFO::A4 );
|
2012-01-16 20:48:32 +00:00
|
|
|
}
|
2012-01-16 04:11:43 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
m_Parent->SetPageSettings( m_pageInfo );
|
|
|
|
|
|
|
|
m_tb.SetRevision( m_TextRevision->GetValue() );
|
|
|
|
m_tb.SetCompany( m_TextCompany->GetValue() );
|
|
|
|
m_tb.SetTitle( m_TextTitle->GetValue() );
|
|
|
|
m_tb.SetComment1( m_TextComment1->GetValue() );
|
|
|
|
m_tb.SetComment2( m_TextComment2->GetValue() );
|
|
|
|
m_tb.SetComment3( m_TextComment3->GetValue() );
|
|
|
|
m_tb.SetComment4( m_TextComment4->GetValue() );
|
|
|
|
|
|
|
|
m_Parent->SetTitleBlock( m_tb );
|
2012-01-15 21:07:01 +00:00
|
|
|
|
2010-03-14 10:34:40 +00:00
|
|
|
#ifdef EESCHEMA
|
2011-12-31 05:44:00 +00:00
|
|
|
// Exports settings to other sheets if requested:
|
2011-03-14 15:17:18 +00:00
|
|
|
SCH_SCREEN* screen;
|
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
// Build the screen list
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_SCREENS ScreenList;
|
2011-03-14 15:17:18 +00:00
|
|
|
|
2012-01-09 08:35:06 +00:00
|
|
|
// Update title blocks for all screens
|
2010-03-14 10:34:40 +00:00
|
|
|
for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
|
|
|
|
{
|
|
|
|
if( screen == m_Screen )
|
|
|
|
continue;
|
|
|
|
|
2012-01-09 08:35:06 +00:00
|
|
|
TITLE_BLOCK tb2 = screen->GetTitleBlock();
|
|
|
|
|
2010-03-14 10:34:40 +00:00
|
|
|
if( m_RevisionExport->IsChecked() )
|
2012-03-26 21:45:05 +00:00
|
|
|
tb2.SetRevision( m_tb.GetRevision() );
|
2010-03-14 10:34:40 +00:00
|
|
|
|
|
|
|
if( m_TitleExport->IsChecked() )
|
2012-03-26 21:45:05 +00:00
|
|
|
tb2.SetTitle( m_tb.GetTitle() );
|
2010-03-14 10:34:40 +00:00
|
|
|
|
|
|
|
if( m_CompanyExport->IsChecked() )
|
2012-03-26 21:45:05 +00:00
|
|
|
tb2.SetCompany( m_tb.GetCompany() );
|
2010-03-14 10:34:40 +00:00
|
|
|
|
|
|
|
if( m_Comment1Export->IsChecked() )
|
2012-03-26 21:45:05 +00:00
|
|
|
tb2.SetComment1( m_tb.GetComment1() );
|
2010-03-14 10:34:40 +00:00
|
|
|
|
|
|
|
if( m_Comment2Export->IsChecked() )
|
2012-03-26 21:45:05 +00:00
|
|
|
tb2.SetComment2( m_tb.GetComment2() );
|
2010-03-14 10:34:40 +00:00
|
|
|
|
|
|
|
if( m_Comment3Export->IsChecked() )
|
2012-03-26 21:45:05 +00:00
|
|
|
tb2.SetComment3( m_tb.GetComment3() );
|
2010-03-14 10:34:40 +00:00
|
|
|
|
|
|
|
if( m_Comment4Export->IsChecked() )
|
2012-03-26 21:45:05 +00:00
|
|
|
tb2.SetComment4( m_tb.GetComment4() );
|
2012-01-09 08:35:06 +00:00
|
|
|
|
|
|
|
screen->SetTitleBlock( tb2 );
|
2010-03-14 10:34:40 +00:00
|
|
|
}
|
2011-03-14 15:17:18 +00:00
|
|
|
|
2010-03-14 10:34:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
m_Screen->SetModify();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_Parent->GetCanvas()->Refresh();
|
2010-03-14 10:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
void DIALOG_PAGES_SETTINGS::SetCurrentPageSizeSelection( const wxString& aPaperSize )
|
2010-03-14 10:34:40 +00:00
|
|
|
{
|
2012-03-27 16:41:13 +00:00
|
|
|
// search all the not translated label list containing our paper type
|
|
|
|
for( unsigned i = 0; i < m_pageFmt.GetCount(); ++i )
|
2010-03-14 10:34:40 +00:00
|
|
|
{
|
2012-01-09 08:35:06 +00:00
|
|
|
// parse each label looking for aPaperSize within it
|
2012-03-27 16:41:13 +00:00
|
|
|
wxStringTokenizer st( m_pageFmt[i] );
|
2011-12-31 05:44:00 +00:00
|
|
|
|
|
|
|
while( st.HasMoreTokens() )
|
2011-12-22 21:57:50 +00:00
|
|
|
{
|
2012-01-09 08:35:06 +00:00
|
|
|
if( st.GetNextToken() == aPaperSize )
|
2011-12-31 05:44:00 +00:00
|
|
|
{
|
2012-01-16 20:48:32 +00:00
|
|
|
m_paperSizeComboBox->SetSelection( i );
|
2011-12-31 05:44:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-12-22 21:57:50 +00:00
|
|
|
}
|
2010-03-14 10:34:40 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample()
|
|
|
|
{
|
|
|
|
int lyWidth, lyHeight;
|
|
|
|
|
|
|
|
wxSize clamped_layout_size( Clamp( MIN_PAGE_SIZE, m_layout_size.x, MAX_PAGE_SIZE ),
|
|
|
|
Clamp( MIN_PAGE_SIZE, m_layout_size.y, MAX_PAGE_SIZE ) );
|
|
|
|
|
|
|
|
double lyRatio = clamped_layout_size.x < clamped_layout_size.y ?
|
|
|
|
(double) clamped_layout_size.y / clamped_layout_size.x :
|
|
|
|
(double) clamped_layout_size.x / clamped_layout_size.y;
|
|
|
|
|
|
|
|
if( clamped_layout_size.x < clamped_layout_size.y )
|
|
|
|
{
|
|
|
|
lyHeight = MAX_PAGE_EXAMPLE_SIZE;
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
lyWidth = KiROUND( (double) lyHeight / lyRatio );
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lyWidth = MAX_PAGE_EXAMPLE_SIZE;
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
lyHeight = KiROUND( (double) lyWidth / lyRatio );
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_page_bitmap )
|
|
|
|
{
|
|
|
|
m_PageLayoutExampleBitmap->SetBitmap( wxNullBitmap );
|
|
|
|
delete m_page_bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_page_bitmap = new wxBitmap( lyWidth + 1, lyHeight + 1 );
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
if( m_page_bitmap->IsOk() )
|
|
|
|
{
|
|
|
|
// Save current clip box and temporary expand it.
|
|
|
|
EDA_RECT save_clip_box = *m_Parent->GetCanvas()->GetClipBox();
|
|
|
|
m_Parent->GetCanvas()->SetClipBox( EDA_RECT( wxPoint( 0, 0 ),
|
|
|
|
wxSize( INT_MAX / 2, INT_MAX / 2 ) ) );
|
|
|
|
// Calculate layout preview scale.
|
2012-04-25 19:33:24 +00:00
|
|
|
int appScale = m_Screen->MilsToIuScalar();
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
double scaleW = (double) lyWidth / clamped_layout_size.x / appScale;
|
|
|
|
double scaleH = (double) lyHeight / clamped_layout_size.y / appScale;
|
|
|
|
|
|
|
|
// Prepare DC.
|
|
|
|
wxSize example_size( lyWidth, lyHeight );
|
|
|
|
wxMemoryDC memDC;
|
|
|
|
memDC.SelectObject( *m_page_bitmap );
|
2012-07-11 08:02:47 +00:00
|
|
|
memDC.SetClippingRegion( wxPoint( 0, 0 ), example_size );
|
2012-03-26 21:45:05 +00:00
|
|
|
memDC.Clear();
|
|
|
|
memDC.SetUserScale( scaleW, scaleH );
|
|
|
|
|
|
|
|
// Get logical page size and margins.
|
|
|
|
PAGE_INFO pageDUMMY;
|
|
|
|
|
|
|
|
pageDUMMY.SetWidthMils( clamped_layout_size.x );
|
|
|
|
pageDUMMY.SetHeightMils( clamped_layout_size.y );
|
|
|
|
|
|
|
|
wxSize dummySize = pageDUMMY.GetSizeMils();
|
|
|
|
wxPoint pointLeftTop( pageDUMMY.GetLeftMarginMils(), pageDUMMY.GetTopMarginMils() );
|
|
|
|
wxPoint pointRightBottom( pageDUMMY.GetRightMarginMils(), pageDUMMY.GetBottomMarginMils() );
|
|
|
|
|
|
|
|
// Draw layout preview.
|
|
|
|
wxString emptyString;
|
|
|
|
GRResetPenAndBrush( ( wxDC* ) &memDC );
|
|
|
|
|
|
|
|
m_Parent->TraceWorkSheet( (wxDC*) &memDC, dummySize, pointLeftTop, pointRightBottom,
|
2012-05-27 00:19:12 +00:00
|
|
|
emptyString, emptyString, m_tb, m_Screen->m_NumberOfScreens,
|
2012-04-16 23:31:29 +00:00
|
|
|
m_Screen->m_ScreenNumber, 1, appScale, LIGHTGRAY, RED );
|
2012-03-26 21:45:05 +00:00
|
|
|
|
|
|
|
memDC.SelectObject( wxNullBitmap );
|
|
|
|
m_PageLayoutExampleBitmap->SetBitmap( *m_page_bitmap );
|
|
|
|
|
|
|
|
// Restore current clip box.
|
|
|
|
m_Parent->GetCanvas()->SetClipBox( save_clip_box );
|
|
|
|
|
|
|
|
// Refresh the dialog.
|
|
|
|
Layout();
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::GetPageLayoutInfoFromDialog()
|
|
|
|
{
|
2012-03-27 16:41:13 +00:00
|
|
|
int idx = m_paperSizeComboBox->GetSelection();
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-27 16:41:13 +00:00
|
|
|
if( idx < 0 )
|
|
|
|
idx = 0;
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-27 16:41:13 +00:00
|
|
|
const wxString paperType = m_pageFmt[idx];
|
2012-03-26 21:45:05 +00:00
|
|
|
|
|
|
|
// here we assume translators will keep original paper size spellings
|
|
|
|
if( paperType.Contains( PAGE_INFO::Custom ) )
|
|
|
|
{
|
|
|
|
GetCustomSizeMilsFromDialog();
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
if( m_layout_size.x && m_layout_size.y )
|
|
|
|
{
|
|
|
|
if( m_layout_size.x < m_layout_size.y )
|
|
|
|
m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
|
|
|
|
else
|
|
|
|
m_orientationComboBox->SetStringSelection( _( "Landscape" ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PAGE_INFO pageInfo; // SetType() later to lookup size
|
|
|
|
|
|
|
|
static const wxString* papers[] = {
|
|
|
|
// longest common string first, since sequential search below
|
|
|
|
&PAGE_INFO::A4,
|
|
|
|
&PAGE_INFO::A3,
|
|
|
|
&PAGE_INFO::A2,
|
|
|
|
&PAGE_INFO::A1,
|
|
|
|
&PAGE_INFO::A0,
|
|
|
|
&PAGE_INFO::A,
|
|
|
|
&PAGE_INFO::B,
|
|
|
|
&PAGE_INFO::C,
|
|
|
|
&PAGE_INFO::D,
|
|
|
|
&PAGE_INFO::E,
|
|
|
|
//&PAGE_INFO::GERBER,
|
|
|
|
&PAGE_INFO::USLetter,
|
|
|
|
&PAGE_INFO::USLegal,
|
|
|
|
&PAGE_INFO::USLedger,
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned i;
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
for( i=0; i < DIM( papers ); ++i )
|
|
|
|
{
|
|
|
|
if( paperType.Contains( *papers[i] ) )
|
|
|
|
{
|
|
|
|
pageInfo.SetType( *papers[i] );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxASSERT( i != DIM(papers) ); // dialog UI match the above list?
|
|
|
|
|
|
|
|
m_layout_size = pageInfo.GetSizeMils();
|
|
|
|
|
|
|
|
// swap sizes to match orientation
|
|
|
|
bool isPortrait = (bool) m_orientationComboBox->GetSelection();
|
|
|
|
|
|
|
|
if( ( isPortrait && m_layout_size.x >= m_layout_size.y ) ||
|
|
|
|
( !isPortrait && m_layout_size.x < m_layout_size.y ) )
|
|
|
|
{
|
|
|
|
m_layout_size.Set( m_layout_size.y, m_layout_size.x );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::GetCustomSizeMilsFromDialog()
|
|
|
|
{
|
|
|
|
double customSizeX;
|
|
|
|
double customSizeY;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
msg = m_TextUserSizeX->GetValue();
|
|
|
|
msg.ToDouble( &customSizeX );
|
|
|
|
|
|
|
|
msg = m_TextUserSizeY->GetValue();
|
|
|
|
msg.ToDouble( &customSizeY );
|
|
|
|
|
|
|
|
switch( g_UserUnit )
|
|
|
|
{
|
|
|
|
case MILLIMETRES:
|
|
|
|
customSizeX *= 1000. / 25.4;
|
|
|
|
customSizeY *= 1000. / 25.4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case INCHES:
|
|
|
|
customSizeX *= 1000.;
|
|
|
|
customSizeY *= 1000.;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare to painless double -> int conversion.
|
|
|
|
customSizeX = Clamp( double( INT_MIN ), customSizeX, double( INT_MAX ) );
|
|
|
|
customSizeY = Clamp( double( INT_MIN ), customSizeY, double( INT_MAX ) );
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
m_layout_size = wxSize( KiROUND( customSizeX ), KiROUND( customSizeY ) );
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|