2012-03-26 21:45:05 +00:00
|
|
|
/*
|
2020-12-19 15:08:31 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2012-03-26 21:45:05 +00:00
|
|
|
*
|
2022-12-13 20:47:28 +00:00
|
|
|
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-03-26 21:45:05 +00:00
|
|
|
*
|
2020-12-19 15:08:31 +00:00
|
|
|
* 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 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
2012-03-26 21:45:05 +00:00
|
|
|
*
|
2020-12-19 15:08:31 +00:00
|
|
|
* 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.
|
2012-03-26 21:45:05 +00:00
|
|
|
*
|
2020-12-19 15:08:31 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-09-30 18:15:37 +00:00
|
|
|
*/
|
2010-03-14 10:34:40 +00:00
|
|
|
|
2021-09-23 15:44:39 +00:00
|
|
|
#include <env_paths.h>
|
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <bitmaps.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <base_screen.h>
|
2022-10-26 02:08:28 +00:00
|
|
|
#include <common.h> // ExpandEnvVarSubstitutions
|
2013-07-19 18:27:22 +00:00
|
|
|
#include <confirm.h>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/arraydim.h>
|
2020-12-17 13:12:18 +00:00
|
|
|
#include <dialogs/dialog_page_settings.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <eda_draw_frame.h>
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.h>
|
2020-10-14 02:46:39 +00:00
|
|
|
#include <gr_basic.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND, Clamp
|
|
|
|
#include <project.h>
|
|
|
|
#include <tool/actions.h>
|
2019-05-26 15:36:40 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_data_model.h>
|
|
|
|
#include <drawing_sheet/ds_painter.h>
|
2022-12-13 20:47:28 +00:00
|
|
|
#include <widgets/std_bitmap_button.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <wx/valgen.h>
|
2011-12-31 05:44:00 +00:00
|
|
|
#include <wx/tokenzr.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/filedlg.h>
|
|
|
|
#include <wx/dcmemory.h>
|
2010-03-14 10:34:40 +00:00
|
|
|
|
2018-08-04 11:18:15 +00:00
|
|
|
#define MAX_PAGE_EXAMPLE_SIZE 200
|
|
|
|
|
2013-01-18 06:04:25 +00:00
|
|
|
|
2012-03-27 16:41:13 +00:00
|
|
|
// List of page formats.
|
2016-01-21 10:15:13 +00:00
|
|
|
// they are prefixed by "_HKI" (already in use for hotkeys) instead of "_",
|
|
|
|
// because we need both the translated and the not translated version.
|
2018-04-14 14:51:15 +00:00
|
|
|
// when displayed in dialog we should explicitly call wxGetTranslation()
|
2012-03-27 16:41:13 +00:00
|
|
|
// to show the translated version.
|
2016-01-21 10:15:13 +00:00
|
|
|
// See hotkeys_basic.h for more info
|
|
|
|
#define _HKI( x ) wxT( x )
|
2013-04-18 18:54:03 +00:00
|
|
|
static const wxString pageFmts[] =
|
2012-03-27 16:41:13 +00:00
|
|
|
{
|
2020-07-21 00:00:36 +00:00
|
|
|
_HKI("A5 148x210mm"),
|
2016-01-21 10:15:13 +00:00
|
|
|
_HKI("A4 210x297mm"),
|
|
|
|
_HKI("A3 297x420mm"),
|
|
|
|
_HKI("A2 420x594mm"),
|
|
|
|
_HKI("A1 594x841mm"),
|
|
|
|
_HKI("A0 841x1189mm"),
|
|
|
|
_HKI("A 8.5x11in"),
|
|
|
|
_HKI("B 11x17in"),
|
|
|
|
_HKI("C 17x22in"),
|
|
|
|
_HKI("D 22x34in"),
|
|
|
|
_HKI("E 34x44in"),
|
|
|
|
_HKI("USLetter 8.5x11in"), // USLetter without space is correct
|
|
|
|
_HKI("USLegal 8.5x14in"), // USLegal without space is correct
|
|
|
|
_HKI("USLedger 11x17in"), // USLedger without space is correct
|
|
|
|
_HKI("User (Custom)"), // size defined by user. The string must contain "Custom"
|
2018-04-14 14:51:15 +00:00
|
|
|
// to be recognized in code
|
2012-03-27 16:41:13 +00:00
|
|
|
};
|
2010-03-14 10:34:40 +00:00
|
|
|
|
2020-12-19 15:08:31 +00:00
|
|
|
DIALOG_PAGES_SETTINGS::DIALOG_PAGES_SETTINGS( EDA_DRAW_FRAME* aParent, double aIuPerMils,
|
2023-02-19 03:40:07 +00:00
|
|
|
const VECTOR2I& aMaxUserSizeMils ) :
|
2020-12-19 15:08:31 +00:00
|
|
|
DIALOG_PAGES_SETTINGS_BASE( aParent ),
|
|
|
|
m_parent( aParent ),
|
|
|
|
m_screen( m_parent->GetScreen() ),
|
|
|
|
m_initialized( false ),
|
2020-12-19 23:29:10 +00:00
|
|
|
m_pageBitmap( nullptr ),
|
|
|
|
m_iuPerMils( aIuPerMils ),
|
2021-03-12 15:12:49 +00:00
|
|
|
m_customSizeX( aParent, m_userSizeXLabel, m_userSizeXCtrl, m_userSizeXUnits ),
|
|
|
|
m_customSizeY( aParent, m_userSizeYLabel, m_userSizeYCtrl, m_userSizeYUnits )
|
2010-03-14 10:34:40 +00:00
|
|
|
{
|
2014-12-31 12:31:19 +00:00
|
|
|
m_projectPath = Prj().GetProjectPath();
|
2021-09-23 15:44:39 +00:00
|
|
|
m_browseButton->SetBitmap( KiBitmap( BITMAPS::small_folder ) );
|
|
|
|
|
2018-08-04 11:18:15 +00:00
|
|
|
m_maxPageSizeMils = aMaxUserSizeMils;
|
2013-07-19 18:27:22 +00:00
|
|
|
m_tb = m_parent->GetTitleBlock();
|
2013-01-19 09:58:25 +00:00
|
|
|
m_customFmt = false;
|
2013-07-19 18:27:22 +00:00
|
|
|
m_localPrjConfigChanged = false;
|
2019-05-25 13:56:52 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
m_drawingSheet = new DS_DATA_MODEL;
|
2019-05-25 13:56:52 +00:00
|
|
|
wxString serialization;
|
2021-06-09 09:47:14 +00:00
|
|
|
DS_DATA_MODEL::GetTheInstance().SaveInString( &serialization );
|
|
|
|
m_drawingSheet->SetPageLayout( TO_UTF8( serialization ) );
|
2010-03-14 10:34:40 +00:00
|
|
|
|
2016-01-01 08:39:12 +00:00
|
|
|
m_PickDate->SetValue( wxDateTime::Now() );
|
|
|
|
|
2020-12-19 15:08:31 +00:00
|
|
|
if( m_parent->GetName() == PL_EDITOR_FRAME_NAME )
|
2019-07-10 22:15:57 +00:00
|
|
|
{
|
|
|
|
SetTitle( _( "Preview Settings" ) );
|
|
|
|
m_staticTextPaper->SetLabel( _( "Preview Paper" ) );
|
|
|
|
m_staticTextTitleBlock->SetLabel( _( "Preview Title Block Data" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetTitle( _( "Page Settings" ) );
|
|
|
|
m_staticTextPaper->SetLabel( _( "Paper" ) );
|
|
|
|
m_staticTextTitleBlock->SetLabel( _( "Title Block" ) );
|
|
|
|
}
|
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
|
|
|
|
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()
|
|
|
|
{
|
2020-12-19 15:08:31 +00:00
|
|
|
delete m_pageBitmap;
|
2021-02-22 23:47:17 +00:00
|
|
|
delete m_drawingSheet;
|
2010-03-14 10:34:40 +00:00
|
|
|
}
|
|
|
|
|
2011-03-14 15:17:18 +00:00
|
|
|
|
2020-12-19 15:08:31 +00:00
|
|
|
bool DIALOG_PAGES_SETTINGS::TransferDataToWindow()
|
2010-03-14 10:34:40 +00:00
|
|
|
{
|
2018-04-14 14:51:15 +00:00
|
|
|
// initialize 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
|
|
|
|
2019-05-26 15:36:40 +00:00
|
|
|
for( const wxString& pageFmt : pageFmts )
|
2012-03-27 16:41:13 +00:00
|
|
|
{
|
2019-05-26 15:36:40 +00:00
|
|
|
m_pageFmt.Add( pageFmt );
|
|
|
|
m_paperSizeComboBox->Append( wxGetTranslation( pageFmt ) );
|
2012-03-27 16:41:13 +00:00
|
|
|
}
|
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
// initialize the drawing sheet filename
|
|
|
|
SetWksFileName( BASE_SCREEN::m_DrawingSheetFileName );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
m_pageInfo = m_parent->GetPageSettings();
|
2012-03-26 21:45:05 +00:00
|
|
|
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
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
if( m_customFmt )
|
2013-01-19 09:58:25 +00:00
|
|
|
{
|
2020-12-19 15:08:31 +00:00
|
|
|
m_customSizeX.SetValue( m_pageInfo.GetWidthMils() * m_iuPerMils );
|
|
|
|
m_customSizeY.SetValue( m_pageInfo.GetHeightMils() * m_iuPerMils );
|
2013-01-19 09:58:25 +00:00
|
|
|
}
|
2018-06-14 08:26:11 +00:00
|
|
|
else
|
2010-03-14 10:34:40 +00:00
|
|
|
{
|
2020-12-19 15:08:31 +00:00
|
|
|
m_customSizeX.SetValue( m_pageInfo.GetCustomWidthMils() * m_iuPerMils );
|
|
|
|
m_customSizeY.SetValue( m_pageInfo.GetCustomHeightMils() * m_iuPerMils );
|
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() );
|
2013-05-23 18:45:23 +00:00
|
|
|
m_TextDate->SetValue( m_tb.GetDate() );
|
2012-03-26 21:45:05 +00:00
|
|
|
m_TextTitle->SetValue( m_tb.GetTitle() );
|
|
|
|
m_TextCompany->SetValue( m_tb.GetCompany() );
|
2019-08-21 16:58:29 +00:00
|
|
|
m_TextComment1->SetValue( m_tb.GetComment( 0 ) );
|
|
|
|
m_TextComment2->SetValue( m_tb.GetComment( 1 ) );
|
|
|
|
m_TextComment3->SetValue( m_tb.GetComment( 2 ) );
|
|
|
|
m_TextComment4->SetValue( m_tb.GetComment( 3 ) );
|
|
|
|
m_TextComment5->SetValue( m_tb.GetComment( 4 ) );
|
|
|
|
m_TextComment6->SetValue( m_tb.GetComment( 5 ) );
|
|
|
|
m_TextComment7->SetValue( m_tb.GetComment( 6 ) );
|
|
|
|
m_TextComment8->SetValue( m_tb.GetComment( 7 ) );
|
|
|
|
m_TextComment9->SetValue( m_tb.GetComment( 8 ) );
|
2010-03-14 10:34:40 +00:00
|
|
|
|
2020-12-19 15:08:31 +00:00
|
|
|
// The default is to disable aall these fields for the "generic" dialog
|
|
|
|
m_TextSheetCount->Show( false );
|
|
|
|
m_TextSheetNumber->Show( false );
|
2020-04-19 11:34:01 +00:00
|
|
|
m_PaperExport->Show( false );
|
2011-03-14 15:17:18 +00:00
|
|
|
m_RevisionExport->Show( false );
|
2013-05-23 18:45:23 +00:00
|
|
|
m_DateExport->Show( false );
|
2011-03-14 15:17:18 +00:00
|
|
|
m_TitleExport->Show( false );
|
|
|
|
m_CompanyExport->Show( false );
|
|
|
|
m_Comment1Export->Show( false );
|
|
|
|
m_Comment2Export->Show( false );
|
|
|
|
m_Comment3Export->Show( false );
|
|
|
|
m_Comment4Export->Show( false );
|
2019-08-21 16:58:29 +00:00
|
|
|
m_Comment5Export->Show( false );
|
|
|
|
m_Comment6Export->Show( false );
|
|
|
|
m_Comment7Export->Show( false );
|
|
|
|
m_Comment8Export->Show( false );
|
|
|
|
m_Comment9Export->Show( false );
|
2020-12-19 15:08:31 +00:00
|
|
|
|
|
|
|
onTransferDataToWindow();
|
2011-03-14 15:17:18 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
GetPageLayoutInfoFromDialog();
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2012-03-26 21:45:05 +00:00
|
|
|
|
2020-12-19 15:08:31 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
m_initialized = true;
|
2020-12-19 15:08:31 +00:00
|
|
|
|
|
|
|
return true;
|
2010-03-14 10:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-19 15:08:31 +00:00
|
|
|
bool DIALOG_PAGES_SETTINGS::TransferDataFromWindow()
|
2010-03-14 10:34:40 +00:00
|
|
|
{
|
2021-07-29 15:46:52 +00:00
|
|
|
int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
|
|
|
|
const wxString paperType = m_pageFmt[idx];
|
2018-11-29 18:59:38 +00:00
|
|
|
|
2021-07-29 15:46:52 +00:00
|
|
|
if( paperType.Contains( PAGE_INFO::Custom ) )
|
|
|
|
{
|
|
|
|
if( !m_customSizeX.Validate( MIN_PAGE_SIZE_MILS, m_maxPageSizeMils.x, EDA_UNITS::MILS ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( !m_customSizeY.Validate( MIN_PAGE_SIZE_MILS, m_maxPageSizeMils.y, EDA_UNITS::MILS ) )
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-29 18:59:38 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
if( SavePageSettings() )
|
2012-03-26 21:45:05 +00:00
|
|
|
{
|
2021-05-28 19:07:04 +00:00
|
|
|
m_screen->SetContentModified();
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2014-12-31 12:31:19 +00:00
|
|
|
if( LocalPrjConfigChanged() )
|
2023-03-04 19:25:07 +00:00
|
|
|
m_parent->OnModify();
|
2018-11-20 14:11:22 +00:00
|
|
|
|
|
|
|
// Call the post processing (if any) after changes
|
|
|
|
m_parent->OnPageSettingsChange();
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
2010-03-14 10:34:40 +00:00
|
|
|
|
2020-12-19 15:08:31 +00:00
|
|
|
return 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
|
|
|
{
|
2021-09-23 15:44:39 +00:00
|
|
|
m_staticTextOrient->Enable( false );
|
2012-01-16 20:48:32 +00:00
|
|
|
m_orientationComboBox->Enable( false );
|
2021-09-23 15:44:39 +00:00
|
|
|
|
|
|
|
m_staticTextCustSize->Enable( true );
|
2018-06-14 08:26:11 +00:00
|
|
|
m_customSizeX.Enable( true );
|
|
|
|
m_customSizeY.Enable( true );
|
2013-01-19 09:58:25 +00:00
|
|
|
m_customFmt = true;
|
2012-01-16 04:11:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-09-23 15:44:39 +00:00
|
|
|
m_staticTextOrient->Enable( true );
|
2012-01-16 20:48:32 +00:00
|
|
|
m_orientationComboBox->Enable( true );
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2021-09-23 15:44:39 +00:00
|
|
|
m_staticTextCustSize->Enable( false );
|
2018-06-14 08:26:11 +00:00
|
|
|
m_customSizeX.Enable( false );
|
|
|
|
m_customSizeY.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();
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
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
|
|
|
{
|
2018-06-14 08:26:11 +00:00
|
|
|
if( m_initialized )
|
2012-03-26 21:45:05 +00:00
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-14 10:34:40 +00:00
|
|
|
|
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
void DIALOG_PAGES_SETTINGS::OnUserPageSizeYTextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
2018-06-14 08:26:11 +00:00
|
|
|
if( m_initialized )
|
2012-03-26 21:45:05 +00:00
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
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();
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
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() );
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-12 14:07:09 +00:00
|
|
|
|
|
|
|
|
2013-05-23 18:45:23 +00:00
|
|
|
void DIALOG_PAGES_SETTINGS::OnDateTextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextDate->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
m_tb.SetDate( m_TextDate->GetValue() );
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2013-05-23 18:45:23 +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() );
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
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() );
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnComment1TextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextComment1->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
2019-08-21 16:58:29 +00:00
|
|
|
m_tb.SetComment( 0, m_TextComment1->GetValue() );
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnComment2TextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextComment2->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
2019-08-21 16:58:29 +00:00
|
|
|
m_tb.SetComment( 1, m_TextComment2->GetValue() );
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnComment3TextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextComment3->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
2019-08-21 16:58:29 +00:00
|
|
|
m_tb.SetComment( 2, m_TextComment3->GetValue() );
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnComment4TextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextComment4->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
2019-08-21 16:58:29 +00:00
|
|
|
m_tb.SetComment( 3, m_TextComment4->GetValue() );
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2019-08-21 16:58:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnComment5TextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextComment5->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
m_tb.SetComment( 4, m_TextComment5->GetValue() );
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2019-08-21 16:58:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnComment6TextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextComment6->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
m_tb.SetComment( 5, m_TextComment6->GetValue() );
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2019-08-21 16:58:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnComment7TextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextComment7->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
m_tb.SetComment( 6, m_TextComment7->GetValue() );
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2019-08-21 16:58:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnComment8TextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextComment8->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
m_tb.SetComment( 7, m_TextComment8->GetValue() );
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2019-08-21 16:58:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::OnComment9TextUpdated( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized && m_TextComment9->IsModified() )
|
|
|
|
{
|
|
|
|
GetPageLayoutInfoFromDialog();
|
|
|
|
m_tb.SetComment( 8, m_TextComment9->GetValue() );
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-14 17:58:57 +00:00
|
|
|
|
2013-05-23 18:45:23 +00:00
|
|
|
void DIALOG_PAGES_SETTINGS::OnDateApplyClick( wxCommandEvent& event )
|
|
|
|
{
|
2015-06-14 17:58:57 +00:00
|
|
|
wxDateTime datetime = m_PickDate->GetValue();
|
|
|
|
wxString date =
|
2021-07-07 23:19:31 +00:00
|
|
|
// We can choose different formats. Should probably be kept in sync with CURRENT_DATE
|
|
|
|
// formatting in TITLE_BLOCK.
|
2015-06-14 17:58:57 +00:00
|
|
|
//
|
|
|
|
// datetime.Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
|
|
|
|
// datetime.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
|
|
|
|
// datetime.Format( wxT("%Y-%b-%d") );
|
|
|
|
datetime.FormatISODate();
|
|
|
|
|
|
|
|
m_TextDate->SetValue( date );
|
2013-05-23 18:45:23 +00:00
|
|
|
}
|
2012-01-16 20:48:32 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
bool DIALOG_PAGES_SETTINGS::SavePageSettings()
|
2012-03-26 21:45:05 +00:00
|
|
|
{
|
2018-11-29 18:59:38 +00:00
|
|
|
bool success = false;
|
2012-03-26 21:45:05 +00:00
|
|
|
|
2013-08-09 16:19:52 +00:00
|
|
|
wxString fileName = GetWksFileName();
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
if( fileName != BASE_SCREEN::m_DrawingSheetFileName )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-09-23 15:44:39 +00:00
|
|
|
wxString fullFileName = DS_DATA_MODEL::ResolvePath( fileName, m_projectPath );
|
2014-12-31 12:31:19 +00:00
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
if( !fullFileName.IsEmpty() && !wxFileExists( fullFileName ) )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2018-06-14 08:26:11 +00:00
|
|
|
wxString msg;
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Drawing sheet file '%s' not found." ), fullFileName );
|
2018-06-14 08:26:11 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
return false;
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
BASE_SCREEN::m_DrawingSheetFileName = fileName;
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( fullFileName );
|
2013-07-19 18:27:22 +00:00
|
|
|
m_localPrjConfigChanged = true;
|
|
|
|
}
|
2012-03-26 21:45:05 +00:00
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
|
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();
|
|
|
|
|
2018-11-29 18:59:38 +00:00
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::Custom );
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2018-11-29 18:59:38 +00:00
|
|
|
if( success )
|
2012-03-26 21:45:05 +00:00
|
|
|
{
|
|
|
|
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 ) )
|
2018-11-29 18:59:38 +00:00
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::USLetter );
|
2012-03-26 21:45:05 +00:00
|
|
|
else if( paperType.Contains( PAGE_INFO::USLegal ) )
|
2018-11-29 18:59:38 +00:00
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::USLegal );
|
2012-03-26 21:45:05 +00:00
|
|
|
else if( paperType.Contains( PAGE_INFO::USLedger ) )
|
2018-11-29 18:59:38 +00:00
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::USLedger );
|
2012-03-26 21:45:05 +00:00
|
|
|
else if( paperType.Contains( PAGE_INFO::GERBER ) )
|
2018-11-29 18:59:38 +00:00
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::GERBER );
|
2020-07-21 00:00:36 +00:00
|
|
|
else if( paperType.Contains( PAGE_INFO::A5 ) )
|
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::A5 );
|
2012-03-26 21:45:05 +00:00
|
|
|
else if( paperType.Contains( PAGE_INFO::A4 ) )
|
2018-11-29 18:59:38 +00:00
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::A4 );
|
2012-03-26 21:45:05 +00:00
|
|
|
else if( paperType.Contains( PAGE_INFO::A3 ) )
|
2018-11-29 18:59:38 +00:00
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::A3 );
|
2012-03-26 21:45:05 +00:00
|
|
|
else if( paperType.Contains( PAGE_INFO::A2 ) )
|
2018-11-29 18:59:38 +00:00
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::A2 );
|
2012-03-26 21:45:05 +00:00
|
|
|
else if( paperType.Contains( PAGE_INFO::A1 ) )
|
2018-11-29 18:59:38 +00:00
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::A1 );
|
2012-03-26 21:45:05 +00:00
|
|
|
else if( paperType.Contains( PAGE_INFO::A0 ) )
|
2018-11-29 18:59:38 +00:00
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::A0 );
|
2012-03-26 21:45:05 +00:00
|
|
|
else if( paperType.Contains( PAGE_INFO::A ) )
|
2018-11-29 18:59:38 +00:00
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::A );
|
2012-03-26 21:45:05 +00:00
|
|
|
else if( paperType.Contains( PAGE_INFO::B ) )
|
2018-11-29 18:59:38 +00:00
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::B );
|
2012-03-26 21:45:05 +00:00
|
|
|
else if( paperType.Contains( PAGE_INFO::C ) )
|
2018-11-29 18:59:38 +00:00
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::C );
|
2012-03-26 21:45:05 +00:00
|
|
|
else if( paperType.Contains( PAGE_INFO::D ) )
|
2018-11-29 18:59:38 +00:00
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::D );
|
2012-03-26 21:45:05 +00:00
|
|
|
else if( paperType.Contains( PAGE_INFO::E ) )
|
2018-11-29 18:59:38 +00:00
|
|
|
success = m_pageInfo.SetType( PAGE_INFO::E );
|
2012-03-26 21:45:05 +00:00
|
|
|
|
2018-11-29 18:59:38 +00:00
|
|
|
if( success )
|
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
|
|
|
|
2018-11-29 18:59:38 +00:00
|
|
|
if( !success )
|
2012-03-26 21:45:05 +00:00
|
|
|
{
|
2021-12-21 21:06:25 +00:00
|
|
|
wxFAIL_MSG( "The translation for paper size must preserve original spellings" );
|
2012-03-26 21:45:05 +00:00
|
|
|
m_pageInfo.SetType( PAGE_INFO::A4 );
|
2012-01-16 20:48:32 +00:00
|
|
|
}
|
2012-01-16 04:11:43 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
m_parent->SetPageSettings( m_pageInfo );
|
2012-03-26 21:45:05 +00:00
|
|
|
|
|
|
|
m_tb.SetRevision( m_TextRevision->GetValue() );
|
2013-05-23 18:45:23 +00:00
|
|
|
m_tb.SetDate( m_TextDate->GetValue() );
|
2012-03-26 21:45:05 +00:00
|
|
|
m_tb.SetCompany( m_TextCompany->GetValue() );
|
|
|
|
m_tb.SetTitle( m_TextTitle->GetValue() );
|
2019-08-21 16:58:29 +00:00
|
|
|
m_tb.SetComment( 0, m_TextComment1->GetValue() );
|
|
|
|
m_tb.SetComment( 1, m_TextComment2->GetValue() );
|
|
|
|
m_tb.SetComment( 2, m_TextComment3->GetValue() );
|
|
|
|
m_tb.SetComment( 3, m_TextComment4->GetValue() );
|
|
|
|
m_tb.SetComment( 4, m_TextComment5->GetValue() );
|
|
|
|
m_tb.SetComment( 5, m_TextComment6->GetValue() );
|
|
|
|
m_tb.SetComment( 6, m_TextComment7->GetValue() );
|
|
|
|
m_tb.SetComment( 7, m_TextComment8->GetValue() );
|
|
|
|
m_tb.SetComment( 8, m_TextComment9->GetValue() );
|
2012-03-26 21:45:05 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
m_parent->SetTitleBlock( m_tb );
|
|
|
|
|
2020-12-19 15:08:31 +00:00
|
|
|
return onSavePageSettings();
|
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
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
void DIALOG_PAGES_SETTINGS::UpdateDrawingSheetExample()
|
2012-03-26 21:45:05 +00:00
|
|
|
{
|
|
|
|
int lyWidth, lyHeight;
|
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
wxSize clamped_layout_size( Clamp( MIN_PAGE_SIZE_MILS, m_layout_size.x, m_maxPageSizeMils.x ),
|
|
|
|
Clamp( MIN_PAGE_SIZE_MILS, m_layout_size.y, m_maxPageSizeMils.y ) );
|
2012-03-26 21:45:05 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-12-19 15:08:31 +00:00
|
|
|
if( m_pageBitmap )
|
2012-03-26 21:45:05 +00:00
|
|
|
{
|
|
|
|
m_PageLayoutExampleBitmap->SetBitmap( wxNullBitmap );
|
2020-12-19 15:08:31 +00:00
|
|
|
delete m_pageBitmap;
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
|
|
|
|
2020-12-19 15:08:31 +00:00
|
|
|
m_pageBitmap = new wxBitmap( lyWidth + 1, lyHeight + 1 );
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2020-12-19 15:08:31 +00:00
|
|
|
if( m_pageBitmap->IsOk() )
|
2012-03-26 21:45:05 +00:00
|
|
|
{
|
2019-02-23 14:22:27 +00:00
|
|
|
double scaleW = (double) lyWidth / clamped_layout_size.x;
|
|
|
|
double scaleH = (double) lyHeight / clamped_layout_size.y;
|
2020-11-27 14:42:27 +00:00
|
|
|
double scale = std::min( scaleW, scaleH );
|
2012-03-26 21:45:05 +00:00
|
|
|
|
|
|
|
// Prepare DC.
|
2013-05-28 09:49:53 +00:00
|
|
|
wxSize example_size( lyWidth + 1, lyHeight + 1 );
|
2012-03-26 21:45:05 +00:00
|
|
|
wxMemoryDC memDC;
|
2020-12-19 15:08:31 +00:00
|
|
|
memDC.SelectObject( *m_pageBitmap );
|
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();
|
2020-11-27 14:42:27 +00:00
|
|
|
memDC.SetUserScale( scale, scale );
|
2012-03-26 21:45:05 +00:00
|
|
|
|
|
|
|
// Get logical page size and margins.
|
|
|
|
PAGE_INFO pageDUMMY;
|
|
|
|
|
2013-03-27 20:38:20 +00:00
|
|
|
// Get page type
|
|
|
|
int idx = m_paperSizeComboBox->GetSelection();
|
|
|
|
|
|
|
|
if( idx < 0 )
|
|
|
|
idx = 0;
|
|
|
|
|
2013-05-25 09:01:44 +00:00
|
|
|
wxString pageFmtName = m_pageFmt[idx].BeforeFirst( ' ' );
|
|
|
|
bool portrait = clamped_layout_size.x < clamped_layout_size.y;
|
|
|
|
pageDUMMY.SetType( pageFmtName, portrait );
|
2021-07-15 19:26:35 +00:00
|
|
|
|
2013-05-25 09:01:44 +00:00
|
|
|
if( m_customFmt )
|
|
|
|
{
|
|
|
|
pageDUMMY.SetWidthMils( clamped_layout_size.x );
|
|
|
|
pageDUMMY.SetHeightMils( clamped_layout_size.y );
|
|
|
|
}
|
2013-03-27 20:38:20 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
// Draw layout preview.
|
2021-02-22 23:47:17 +00:00
|
|
|
KIGFX::DS_RENDER_SETTINGS renderSettings;
|
2020-12-23 23:18:02 +00:00
|
|
|
COLOR_SETTINGS* colorSettings = m_parent->GetColorSettings();
|
|
|
|
COLOR4D bgColor = m_parent->GetDrawBgColor();
|
|
|
|
wxString emptyString;
|
2012-03-26 21:45:05 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL::SetAltInstance( m_drawingSheet );
|
2020-12-23 23:18:02 +00:00
|
|
|
{
|
|
|
|
GRResetPenAndBrush( &memDC );
|
|
|
|
renderSettings.SetDefaultPenWidth( 1 );
|
|
|
|
renderSettings.LoadColors( colorSettings );
|
|
|
|
renderSettings.SetPrintDC( &memDC );
|
2020-04-14 12:25:00 +00:00
|
|
|
|
2020-12-25 16:58:57 +00:00
|
|
|
if( m_parent->IsType( FRAME_SCH )
|
|
|
|
|| m_parent->IsType( FRAME_SCH_SYMBOL_EDITOR )
|
|
|
|
|| m_parent->IsType( FRAME_SCH_VIEWER )
|
|
|
|
|| m_parent->IsType( FRAME_SCH_VIEWER_MODAL ) )
|
|
|
|
{
|
2021-05-30 22:56:24 +00:00
|
|
|
COLOR4D color = renderSettings.GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET );
|
|
|
|
renderSettings.SetLayerColor( LAYER_DRAWINGSHEET, color );
|
2020-12-25 16:58:57 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
GRFilledRect( &memDC, VECTOR2I( 0, 0 ), m_layout_size, 0, bgColor, bgColor );
|
2020-04-14 12:25:00 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
PrintDrawingSheet( &renderSettings, pageDUMMY, emptyString, emptyString, m_tb,
|
2022-09-20 14:25:03 +00:00
|
|
|
nullptr, m_screen->GetPageCount(), m_screen->GetPageNumber(), 1,
|
|
|
|
&Prj(), wxEmptyString, m_screen->GetVirtualPageNumber() == 1 );
|
2012-03-26 21:45:05 +00:00
|
|
|
|
2020-12-23 23:18:02 +00:00
|
|
|
memDC.SelectObject( wxNullBitmap );
|
|
|
|
m_PageLayoutExampleBitmap->SetBitmap( *m_pageBitmap );
|
|
|
|
}
|
2021-07-15 19:26:35 +00:00
|
|
|
|
|
|
|
DS_DATA_MODEL::SetAltInstance( nullptr );
|
2012-03-26 21:45:05 +00:00
|
|
|
|
|
|
|
// Refresh the dialog.
|
|
|
|
Layout();
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::GetPageLayoutInfoFromDialog()
|
|
|
|
{
|
2018-06-14 08:26:11 +00:00
|
|
|
int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
|
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
|
|
|
|
|
2014-06-11 05:00:30 +00:00
|
|
|
static const wxChar* papers[] = {
|
2012-03-26 21:45:05 +00:00
|
|
|
// longest common string first, since sequential search below
|
2020-07-21 00:00:36 +00:00
|
|
|
PAGE_INFO::A5,
|
2014-06-11 05:00:30 +00:00
|
|
|
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::USLetter,
|
|
|
|
PAGE_INFO::USLegal,
|
|
|
|
PAGE_INFO::USLedger,
|
2012-03-26 21:45:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
unsigned i;
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2019-01-06 16:43:12 +00:00
|
|
|
for( i=0; i < arrayDim( papers ); ++i )
|
2012-03-26 21:45:05 +00:00
|
|
|
{
|
2014-10-17 08:14:30 +00:00
|
|
|
if( paperType.Contains( papers[i] ) )
|
2012-03-26 21:45:05 +00:00
|
|
|
{
|
2014-10-17 08:14:30 +00:00
|
|
|
pageInfo.SetType( papers[i] );
|
2012-03-26 21:45:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-06 16:43:12 +00:00
|
|
|
wxASSERT( i != arrayDim(papers) ); // dialog UI match the above list?
|
2012-03-26 21:45:05 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I sz = pageInfo.GetSizeMils();
|
2023-02-19 03:40:07 +00:00
|
|
|
m_layout_size = VECTOR2I( sz.x, sz.y );
|
2012-03-26 21:45:05 +00:00
|
|
|
|
|
|
|
// 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 ) )
|
|
|
|
{
|
2023-02-19 03:40:07 +00:00
|
|
|
std::swap( m_layout_size.x, m_layout_size.y );
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PAGES_SETTINGS::GetCustomSizeMilsFromDialog()
|
|
|
|
{
|
2020-12-19 15:08:31 +00:00
|
|
|
double customSizeX = (double) m_customSizeX.GetValue() / m_iuPerMils;
|
|
|
|
double customSizeY = (double) m_customSizeY.GetValue() / m_iuPerMils;
|
2012-03-26 21:45:05 +00:00
|
|
|
|
|
|
|
// Prepare to painless double -> int conversion.
|
|
|
|
customSizeX = Clamp( double( INT_MIN ), customSizeX, double( INT_MAX ) );
|
|
|
|
customSizeY = Clamp( double( INT_MIN ), customSizeY, double( INT_MAX ) );
|
2023-02-19 03:40:07 +00:00
|
|
|
m_layout_size = VECTOR2I( KiROUND( customSizeX ), KiROUND( customSizeY ) );
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2018-04-14 14:51:15 +00:00
|
|
|
|
2013-08-09 16:19:52 +00:00
|
|
|
void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2018-04-14 14:51:15 +00:00
|
|
|
wxFileName fn = GetWksFileName();
|
2022-10-26 02:08:28 +00:00
|
|
|
wxString name = fn.GetFullName();
|
2018-04-14 14:51:15 +00:00
|
|
|
wxString path;
|
|
|
|
|
|
|
|
if( fn.IsAbsolute() )
|
|
|
|
{
|
|
|
|
path = fn.GetPath();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-26 02:08:28 +00:00
|
|
|
wxFileName expanded( ExpandEnvVarSubstitutions( GetWksFileName(), &m_parentFrame->Prj() ) );
|
|
|
|
|
|
|
|
if( expanded.IsAbsolute() )
|
|
|
|
path = expanded.GetPath();
|
|
|
|
else
|
|
|
|
path = m_projectPath;
|
2018-04-14 14:51:15 +00:00
|
|
|
}
|
|
|
|
|
2013-08-09 16:19:52 +00:00
|
|
|
// Display a file picker dialog
|
2021-09-23 15:44:39 +00:00
|
|
|
wxFileDialog fileDialog( this, _( "Select Drawing Sheet File" ), path, name,
|
|
|
|
DrawingSheetFileWildcard(), wxFD_DEFAULT_STYLE|wxFD_FILE_MUST_EXIST );
|
2013-08-09 16:19:52 +00:00
|
|
|
|
|
|
|
if( fileDialog.ShowModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString fileName = fileDialog.GetPath();
|
2021-09-23 15:44:39 +00:00
|
|
|
wxString shortFileName;
|
2013-08-09 16:19:52 +00:00
|
|
|
|
2021-09-23 15:44:39 +00:00
|
|
|
// Try to use a project-relative path first:
|
|
|
|
if( !m_projectPath.IsEmpty() && fileName.StartsWith( m_projectPath ) )
|
2013-08-09 16:19:52 +00:00
|
|
|
{
|
2021-09-23 15:44:39 +00:00
|
|
|
fn = wxFileName( fileName );
|
|
|
|
fn.MakeRelativeTo( m_projectPath );
|
|
|
|
shortFileName = fn.GetFullPath();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Failing that see if we can shorten it with env vars:
|
|
|
|
shortFileName = NormalizePath( fileName, &Pgm().GetLocalEnvVariables(), nullptr );
|
2013-08-09 16:19:52 +00:00
|
|
|
}
|
|
|
|
|
2021-05-01 18:14:57 +00:00
|
|
|
std::unique_ptr<DS_DATA_MODEL> ws = std::make_unique<DS_DATA_MODEL>();
|
2014-12-31 12:31:19 +00:00
|
|
|
|
2021-05-01 18:11:16 +00:00
|
|
|
if( ws->LoadDrawingSheet( fileName ) )
|
|
|
|
{
|
2021-09-23 15:44:39 +00:00
|
|
|
delete m_drawingSheet;
|
2014-12-31 12:31:19 +00:00
|
|
|
|
2021-05-01 18:14:57 +00:00
|
|
|
m_drawingSheet = ws.release();
|
2014-12-31 12:31:19 +00:00
|
|
|
|
2021-05-01 18:11:16 +00:00
|
|
|
SetWksFileName( shortFileName );
|
|
|
|
|
|
|
|
GetPageLayoutInfoFromDialog();
|
2021-05-30 22:56:24 +00:00
|
|
|
UpdateDrawingSheetExample();
|
2021-05-01 18:11:16 +00:00
|
|
|
}
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|