KiCad PCB EDA Suite
dialog_page_settings.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KICAD, a free EDA CAD application.
3  *
4  * Copyright (C) 1992-2018 Kicad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <fctsys.h>
25 #include <common.h>
26 #include <project.h>
27 #include <confirm.h>
28 #include <gr_basic.h>
29 #include <base_struct.h>
30 #include <title_block.h>
31 #include <eda_draw_frame.h>
32 #include <ws_data_model.h>
33 #include <base_screen.h>
35 #include <tool/tool_manager.h>
36 #include <wx/valgen.h>
37 #include <wx/tokenzr.h>
38 
39 #ifdef EESCHEMA
40 #include <sch_screen.h>
41 #include <general.h>
42 #endif
43 
44 #include <ws_painter.h>
45 #include <dialog_page_settings.h>
46 #include <tool/actions.h>
47 #include <kiface_i.h>
48 
49 #define MAX_PAGE_EXAMPLE_SIZE 200
50 
51 
52 #define KEY_EXPORT_REVISION wxT( "PageSettingsExportRevision" )
53 #define KEY_EXPORT_DATE wxT( "PageSettingsExportDate" )
54 #define KEY_EXPORT_TITLE wxT( "PageSettingsExportTitle" )
55 #define KEY_EXPORT_COMPANY wxT( "PageSettingsExportCompany" )
56 #define KEY_EXPORT_COMMENT1 wxT( "PageSettingsExportComment1" )
57 #define KEY_EXPORT_COMMENT2 wxT( "PageSettingsExportComment2" )
58 #define KEY_EXPORT_COMMENT3 wxT( "PageSettingsExportComment3" )
59 #define KEY_EXPORT_COMMENT4 wxT( "PageSettingsExportComment4" )
60 #define KEY_EXPORT_COMMENT5 wxT( "PageSettingsExportComment5" )
61 #define KEY_EXPORT_COMMENT6 wxT( "PageSettingsExportComment6" )
62 #define KEY_EXPORT_COMMENT7 wxT( "PageSettingsExportComment7" )
63 #define KEY_EXPORT_COMMENT8 wxT( "PageSettingsExportComment8" )
64 #define KEY_EXPORT_COMMENT9 wxT( "PageSettingsExportComment9" )
65 
66 
67 // List of page formats.
68 // they are prefixed by "_HKI" (already in use for hotkeys) instead of "_",
69 // because we need both the translated and the not translated version.
70 // when displayed in dialog we should explicitly call wxGetTranslation()
71 // to show the translated version.
72 // See hotkeys_basic.h for more info
73 #define _HKI( x ) wxT( x )
74 static const wxString pageFmts[] =
75 {
76  _HKI("A4 210x297mm"),
77  _HKI("A3 297x420mm"),
78  _HKI("A2 420x594mm"),
79  _HKI("A1 594x841mm"),
80  _HKI("A0 841x1189mm"),
81  _HKI("A 8.5x11in"),
82  _HKI("B 11x17in"),
83  _HKI("C 17x22in"),
84  _HKI("D 22x34in"),
85  _HKI("E 34x44in"),
86  _HKI("USLetter 8.5x11in"), // USLetter without space is correct
87  _HKI("USLegal 8.5x14in"), // USLegal without space is correct
88  _HKI("USLedger 11x17in"), // USLedger without space is correct
89  _HKI("User (Custom)"), // size defined by user. The string must contain "Custom"
90  // to be recognized in code
91 };
92 
93 DIALOG_PAGES_SETTINGS::DIALOG_PAGES_SETTINGS( EDA_DRAW_FRAME* parent, wxSize aMaxUserSizeMils ) :
95  m_initialized( false ),
96  m_customSizeX( parent, m_userSizeXLabel, m_userSizeXCtrl, m_userSizeXUnits, false ),
97  m_customSizeY( parent, m_userSizeYLabel, m_userSizeYCtrl, m_userSizeYUnits, false )
98 {
99  m_parent = parent;
102  m_page_bitmap = NULL;
103  m_maxPageSizeMils = aMaxUserSizeMils;
105  m_customFmt = false;
106  m_localPrjConfigChanged = false;
107 
109  wxString serialization;
110  WS_DATA_MODEL::GetTheInstance().SaveInString( serialization );
111  m_pagelayout->SetPageLayout( TO_UTF8( serialization ) );
112 
113  m_PickDate->SetValue( wxDateTime::Now() );
114 
115  if( parent->GetName() == PL_EDITOR_FRAME_NAME )
116  {
117  SetTitle( _( "Preview Settings" ) );
118  m_staticTextPaper->SetLabel( _( "Preview Paper" ) );
119  m_staticTextTitleBlock->SetLabel( _( "Preview Title Block Data" ) );
120  }
121  else
122  {
123  SetTitle( _( "Page Settings" ) );
124  m_staticTextPaper->SetLabel( _( "Paper" ) );
125  m_staticTextTitleBlock->SetLabel( _( "Title Block" ) );
126  }
127 
128  initDialog();
129 
130  GetSizer()->SetSizeHints( this );
131  Centre();
132 }
133 
134 
136 {
137 #ifdef EESCHEMA
138  wxConfigBase* config = Kiface().KifaceSettings();
139  config->Write( KEY_EXPORT_REVISION, m_RevisionExport->GetValue() );
140  config->Write( KEY_EXPORT_DATE, m_DateExport->GetValue() );
141  config->Write( KEY_EXPORT_TITLE, m_TitleExport->GetValue() );
142  config->Write( KEY_EXPORT_COMPANY, m_CompanyExport->GetValue() );
143  config->Write( KEY_EXPORT_COMMENT1, m_Comment1Export->GetValue() );
144  config->Write( KEY_EXPORT_COMMENT2, m_Comment2Export->GetValue() );
145  config->Write( KEY_EXPORT_COMMENT3, m_Comment3Export->GetValue() );
146  config->Write( KEY_EXPORT_COMMENT4, m_Comment4Export->GetValue() );
147  config->Write( KEY_EXPORT_COMMENT5, m_Comment5Export->GetValue() );
148  config->Write( KEY_EXPORT_COMMENT6, m_Comment6Export->GetValue() );
149  config->Write( KEY_EXPORT_COMMENT7, m_Comment7Export->GetValue() );
150  config->Write( KEY_EXPORT_COMMENT8, m_Comment8Export->GetValue() );
151  config->Write( KEY_EXPORT_COMMENT9, m_Comment9Export->GetValue() );
152 #endif
153 
154  delete m_page_bitmap;
155  delete m_pagelayout;
156 }
157 
158 
160 {
161  wxString msg;
162 
163  // initialize page format choice box and page format list.
164  // The first shows translated strings, the second contains not translated strings
165  m_paperSizeComboBox->Clear();
166 
167  for( const wxString& pageFmt : pageFmts )
168  {
169  m_pageFmt.Add( pageFmt );
170  m_paperSizeComboBox->Append( wxGetTranslation( pageFmt ) );
171  }
172 
173  // initialize the page layout descr filename
175 
176 #ifdef EESCHEMA
177  // Init display value for schematic sub-sheet number
178  wxString format = m_TextSheetCount->GetLabel();
179  msg.Printf( format, m_screen->m_NumberOfScreens );
180  m_TextSheetCount->SetLabel( msg );
181 
182  format = m_TextSheetNumber->GetLabel();
183  msg.Printf( format, m_screen->m_ScreenNumber );
184  m_TextSheetNumber->SetLabel( msg );
185 #else
186  m_TextSheetCount->Show( false );
187  m_TextSheetNumber->Show( false );
188 #endif
189 
192  m_orientationComboBox->SetSelection( m_pageInfo.IsPortrait() );
193 
194  // only a click fires the "selection changed" event, so have to fabricate this check
195  wxCommandEvent dummy;
197 
198  if( m_customFmt )
199  {
202  }
203  else
204  {
207  }
208 
209  m_TextRevision->SetValue( m_tb.GetRevision() );
210  m_TextDate->SetValue( m_tb.GetDate() );
211  m_TextTitle->SetValue( m_tb.GetTitle() );
212  m_TextCompany->SetValue( m_tb.GetCompany() );
213  m_TextComment1->SetValue( m_tb.GetComment( 0 ) );
214  m_TextComment2->SetValue( m_tb.GetComment( 1 ) );
215  m_TextComment3->SetValue( m_tb.GetComment( 2 ) );
216  m_TextComment4->SetValue( m_tb.GetComment( 3 ) );
217  m_TextComment5->SetValue( m_tb.GetComment( 4 ) );
218  m_TextComment6->SetValue( m_tb.GetComment( 5 ) );
219  m_TextComment7->SetValue( m_tb.GetComment( 6 ) );
220  m_TextComment8->SetValue( m_tb.GetComment( 7 ) );
221  m_TextComment9->SetValue( m_tb.GetComment( 8 ) );
222 
223 #ifdef EESCHEMA
224  wxConfigBase* config = Kiface().KifaceSettings();
225  m_RevisionExport->SetValue( config->ReadBool( KEY_EXPORT_REVISION, false ) );
226  m_DateExport->SetValue( config->ReadBool( KEY_EXPORT_DATE, false ) );
227  m_TitleExport->SetValue( config->ReadBool( KEY_EXPORT_TITLE, false ) );
228  m_CompanyExport->SetValue( config->ReadBool( KEY_EXPORT_COMPANY, false ) );
229  m_Comment1Export->SetValue( config->ReadBool( KEY_EXPORT_COMMENT1, false ) );
230  m_Comment2Export->SetValue( config->ReadBool( KEY_EXPORT_COMMENT2, false ) );
231  m_Comment3Export->SetValue( config->ReadBool( KEY_EXPORT_COMMENT3, false ) );
232  m_Comment4Export->SetValue( config->ReadBool( KEY_EXPORT_COMMENT4, false ) );
233  m_Comment5Export->SetValue( config->ReadBool( KEY_EXPORT_COMMENT5, false ) );
234  m_Comment6Export->SetValue( config->ReadBool( KEY_EXPORT_COMMENT6, false ) );
235  m_Comment7Export->SetValue( config->ReadBool( KEY_EXPORT_COMMENT7, false ) );
236  m_Comment8Export->SetValue( config->ReadBool( KEY_EXPORT_COMMENT8, false ) );
237  m_Comment9Export->SetValue( config->ReadBool( KEY_EXPORT_COMMENT9, false ) );
238 #else
239  m_RevisionExport->Show( false );
240  m_DateExport->Show( false );
241  m_TitleExport->Show( false );
242  m_CompanyExport->Show( false );
243  m_Comment1Export->Show( false );
244  m_Comment2Export->Show( false );
245  m_Comment3Export->Show( false );
246  m_Comment4Export->Show( false );
247  m_Comment5Export->Show( false );
248  m_Comment6Export->Show( false );
249  m_Comment7Export->Show( false );
250  m_Comment8Export->Show( false );
251  m_Comment9Export->Show( false );
252 #endif
253 
256 
257  // Make the OK button the default.
258  m_sdbSizerOK->SetDefault();
259  m_initialized = true;
260 }
261 
262 
263 void DIALOG_PAGES_SETTINGS::OnOkClick( wxCommandEvent& event )
264 {
265  if( !m_customSizeX.Validate( Mils2iu( MIN_PAGE_SIZE ), Mils2iu( m_maxPageSizeMils.x ) ) )
266  return;
267 
268  if( !m_customSizeY.Validate( Mils2iu( MIN_PAGE_SIZE ), Mils2iu( m_maxPageSizeMils.y ) ) )
269  return;
270 
271  if( SavePageSettings() )
272  {
273  m_screen->SetModify();
274 
275  if( LocalPrjConfigChanged() )
276  m_parent->SaveProjectSettings( false );
277 
278  // Call the post processing (if any) after changes
280  }
281 
282  event.Skip();
283 }
284 
285 
286 void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
287 {
288  int idx = m_paperSizeComboBox->GetSelection();
289 
290  if( idx < 0 )
291  idx = 0;
292 
293  const wxString paperType = m_pageFmt[idx];
294 
295  if( paperType.Contains( PAGE_INFO::Custom ) )
296  {
297  m_orientationComboBox->Enable( false );
298  m_customSizeX.Enable( true );
299  m_customSizeY.Enable( true );
300  m_customFmt = true;
301  }
302  else
303  {
304  m_orientationComboBox->Enable( true );
305 
306 #if 0
307  // ForcePortrait() does not exist, but could be useful.
308  // so I leave these lines, which could be seen as a todo feature
309  if( paperType.ForcePortrait() )
310  {
311  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
312  m_orientationComboBox->Enable( false );
313  }
314 #endif
315  m_customSizeX.Enable( false );
316  m_customSizeY.Enable( false );
317  m_customFmt = false;
318  }
319 
322 }
323 
324 
326 {
327  if( m_initialized )
328  {
331  }
332 }
333 
334 
336 {
337  if( m_initialized )
338  {
341  }
342 }
343 
344 
346 {
347  if( m_initialized )
348  {
351  }
352 }
353 
354 
355 void DIALOG_PAGES_SETTINGS::OnRevisionTextUpdated( wxCommandEvent& event )
356 {
357  if( m_initialized && m_TextRevision->IsModified() )
358  {
360  m_tb.SetRevision( m_TextRevision->GetValue() );
362  }
363 }
364 
365 
366 void DIALOG_PAGES_SETTINGS::OnDateTextUpdated( wxCommandEvent& event )
367 {
368  if( m_initialized && m_TextDate->IsModified() )
369  {
371  m_tb.SetDate( m_TextDate->GetValue() );
373  }
374 }
375 
376 
377 void DIALOG_PAGES_SETTINGS::OnTitleTextUpdated( wxCommandEvent& event )
378 {
379  if( m_initialized && m_TextTitle->IsModified() )
380  {
382  m_tb.SetTitle( m_TextTitle->GetValue() );
384  }
385 }
386 
387 
388 void DIALOG_PAGES_SETTINGS::OnCompanyTextUpdated( wxCommandEvent& event )
389 {
390  if( m_initialized && m_TextCompany->IsModified() )
391  {
393  m_tb.SetCompany( m_TextCompany->GetValue() );
395  }
396 }
397 
398 
399 void DIALOG_PAGES_SETTINGS::OnComment1TextUpdated( wxCommandEvent& event )
400 {
401  if( m_initialized && m_TextComment1->IsModified() )
402  {
404  m_tb.SetComment( 0, m_TextComment1->GetValue() );
406  }
407 }
408 
409 
410 void DIALOG_PAGES_SETTINGS::OnComment2TextUpdated( wxCommandEvent& event )
411 {
412  if( m_initialized && m_TextComment2->IsModified() )
413  {
415  m_tb.SetComment( 1, m_TextComment2->GetValue() );
417  }
418 }
419 
420 
421 void DIALOG_PAGES_SETTINGS::OnComment3TextUpdated( wxCommandEvent& event )
422 {
423  if( m_initialized && m_TextComment3->IsModified() )
424  {
426  m_tb.SetComment( 2, m_TextComment3->GetValue() );
428  }
429 }
430 
431 
432 void DIALOG_PAGES_SETTINGS::OnComment4TextUpdated( wxCommandEvent& event )
433 {
434  if( m_initialized && m_TextComment4->IsModified() )
435  {
437  m_tb.SetComment( 3, m_TextComment4->GetValue() );
439  }
440 }
441 
442 
443 void DIALOG_PAGES_SETTINGS::OnComment5TextUpdated( wxCommandEvent& event )
444 {
445  if( m_initialized && m_TextComment5->IsModified() )
446  {
448  m_tb.SetComment( 4, m_TextComment5->GetValue() );
450  }
451 }
452 
453 
454 void DIALOG_PAGES_SETTINGS::OnComment6TextUpdated( wxCommandEvent& event )
455 {
456  if( m_initialized && m_TextComment6->IsModified() )
457  {
459  m_tb.SetComment( 5, m_TextComment6->GetValue() );
461  }
462 }
463 
464 
465 void DIALOG_PAGES_SETTINGS::OnComment7TextUpdated( wxCommandEvent& event )
466 {
467  if( m_initialized && m_TextComment7->IsModified() )
468  {
470  m_tb.SetComment( 6, m_TextComment7->GetValue() );
472  }
473 }
474 
475 
476 void DIALOG_PAGES_SETTINGS::OnComment8TextUpdated( wxCommandEvent& event )
477 {
478  if( m_initialized && m_TextComment8->IsModified() )
479  {
481  m_tb.SetComment( 7, m_TextComment8->GetValue() );
483  }
484 }
485 
486 
487 void DIALOG_PAGES_SETTINGS::OnComment9TextUpdated( wxCommandEvent& event )
488 {
489  if( m_initialized && m_TextComment9->IsModified() )
490  {
492  m_tb.SetComment( 8, m_TextComment9->GetValue() );
494  }
495 }
496 
497 
498 void DIALOG_PAGES_SETTINGS::OnDateApplyClick( wxCommandEvent& event )
499 {
500  wxDateTime datetime = m_PickDate->GetValue();
501  wxString date =
502  // We can choose different formats. Only one must be uncommented
503  //
504  // datetime.Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
505  // datetime.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
506  // datetime.Format( wxT("%Y-%b-%d") );
507  datetime.FormatISODate();
508 
509  m_TextDate->SetValue( date );
510 }
511 
512 
514 {
515  bool success = false;
516 
517  wxString fileName = GetWksFileName();
518 
520  {
521  wxString fullFileName = WS_DATA_MODEL::MakeFullFileName( fileName, m_projectPath );
522 
523  if( !fullFileName.IsEmpty() && !wxFileExists( fullFileName ) )
524  {
525  wxString msg;
526  msg.Printf( _( "Page layout description file \"%s\" not found." ),
527  GetChars( fullFileName ) );
528  wxMessageBox( msg );
529  return false;
530  }
531 
534  pglayout.SetPageLayout( fullFileName );
536  }
537 
538  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
539  const wxString paperType = m_pageFmt[idx];
540 
541  if( paperType.Contains( PAGE_INFO::Custom ) )
542  {
544 
545  success = m_pageInfo.SetType( PAGE_INFO::Custom );
546 
547  if( success )
548  {
551 
554  }
555  }
556  else
557  {
558  // search for longest common string first, e.g. A4 before A
559  if( paperType.Contains( PAGE_INFO::USLetter ) )
561  else if( paperType.Contains( PAGE_INFO::USLegal ) )
563  else if( paperType.Contains( PAGE_INFO::USLedger ) )
565  else if( paperType.Contains( PAGE_INFO::GERBER ) )
566  success = m_pageInfo.SetType( PAGE_INFO::GERBER );
567  else if( paperType.Contains( PAGE_INFO::A4 ) )
568  success = m_pageInfo.SetType( PAGE_INFO::A4 );
569  else if( paperType.Contains( PAGE_INFO::A3 ) )
570  success = m_pageInfo.SetType( PAGE_INFO::A3 );
571  else if( paperType.Contains( PAGE_INFO::A2 ) )
572  success = m_pageInfo.SetType( PAGE_INFO::A2 );
573  else if( paperType.Contains( PAGE_INFO::A1 ) )
574  success = m_pageInfo.SetType( PAGE_INFO::A1 );
575  else if( paperType.Contains( PAGE_INFO::A0 ) )
576  success = m_pageInfo.SetType( PAGE_INFO::A0 );
577  else if( paperType.Contains( PAGE_INFO::A ) )
578  success = m_pageInfo.SetType( PAGE_INFO::A );
579  else if( paperType.Contains( PAGE_INFO::B ) )
580  success = m_pageInfo.SetType( PAGE_INFO::B );
581  else if( paperType.Contains( PAGE_INFO::C ) )
582  success = m_pageInfo.SetType( PAGE_INFO::C );
583  else if( paperType.Contains( PAGE_INFO::D ) )
584  success = m_pageInfo.SetType( PAGE_INFO::D );
585  else if( paperType.Contains( PAGE_INFO::E ) )
586  success = m_pageInfo.SetType( PAGE_INFO::E );
587 
588  if( success )
589  {
590  int choice = m_orientationComboBox->GetSelection();
591  m_pageInfo.SetPortrait( choice != 0 );
592  }
593  }
594 
595  if( !success )
596  {
597  wxASSERT_MSG( false, _( "the translation for paper size must preserve original spellings" ) );
599  }
600 
602 
603  m_tb.SetRevision( m_TextRevision->GetValue() );
604  m_tb.SetDate( m_TextDate->GetValue() );
605  m_tb.SetCompany( m_TextCompany->GetValue() );
606  m_tb.SetTitle( m_TextTitle->GetValue() );
607  m_tb.SetComment( 0, m_TextComment1->GetValue() );
608  m_tb.SetComment( 1, m_TextComment2->GetValue() );
609  m_tb.SetComment( 2, m_TextComment3->GetValue() );
610  m_tb.SetComment( 3, m_TextComment4->GetValue() );
611  m_tb.SetComment( 4, m_TextComment5->GetValue() );
612  m_tb.SetComment( 5, m_TextComment6->GetValue() );
613  m_tb.SetComment( 6, m_TextComment7->GetValue() );
614  m_tb.SetComment( 7, m_TextComment8->GetValue() );
615  m_tb.SetComment( 8, m_TextComment9->GetValue() );
616 
618 
619 
620 #ifdef EESCHEMA
621  // Exports settings to other sheets if requested:
622  SCH_SCREEN* screen;
623 
624  // Build the screen list
625  SCH_SCREENS ScreenList;
626 
627  // Update title blocks for all screens
628  for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
629  {
630  if( screen == m_screen )
631  continue;
632 
633  TITLE_BLOCK tb2 = screen->GetTitleBlock();
634 
635  if( m_RevisionExport->IsChecked() )
636  tb2.SetRevision( m_tb.GetRevision() );
637 
638  if( m_DateExport->IsChecked() )
639  tb2.SetDate( m_tb.GetDate() );
640 
641  if( m_TitleExport->IsChecked() )
642  tb2.SetTitle( m_tb.GetTitle() );
643 
644  if( m_CompanyExport->IsChecked() )
645  tb2.SetCompany( m_tb.GetCompany() );
646 
647  if( m_Comment1Export->IsChecked() )
648  tb2.SetComment( 0, m_tb.GetComment( 0 ) );
649 
650  if( m_Comment2Export->IsChecked() )
651  tb2.SetComment( 1, m_tb.GetComment( 1 ) );
652 
653  if( m_Comment3Export->IsChecked() )
654  tb2.SetComment( 2, m_tb.GetComment( 2 ) );
655 
656  if( m_Comment4Export->IsChecked() )
657  tb2.SetComment( 3, m_tb.GetComment( 3 ) );
658 
659  if( m_Comment5Export->IsChecked() )
660  tb2.SetComment( 4, m_tb.GetComment( 4 ) );
661 
662  if( m_Comment6Export->IsChecked() )
663  tb2.SetComment( 5, m_tb.GetComment( 5 ) );
664 
665  if( m_Comment7Export->IsChecked() )
666  tb2.SetComment( 6, m_tb.GetComment( 6 ) );
667 
668  if( m_Comment8Export->IsChecked() )
669  tb2.SetComment( 7, m_tb.GetComment( 7 ) );
670 
671  if( m_Comment9Export->IsChecked() )
672  tb2.SetComment( 8, m_tb.GetComment( 8 ) );
673 
674  screen->SetTitleBlock( tb2 );
675  }
676 
677 #endif
678 
679  return true;
680 }
681 
682 
683 void DIALOG_PAGES_SETTINGS::SetCurrentPageSizeSelection( const wxString& aPaperSize )
684 {
685  // search all the not translated label list containing our paper type
686  for( unsigned i = 0; i < m_pageFmt.GetCount(); ++i )
687  {
688  // parse each label looking for aPaperSize within it
689  wxStringTokenizer st( m_pageFmt[i] );
690 
691  while( st.HasMoreTokens() )
692  {
693  if( st.GetNextToken() == aPaperSize )
694  {
695  m_paperSizeComboBox->SetSelection( i );
696  return;
697  }
698  }
699  }
700 }
701 
702 
704 {
705  int lyWidth, lyHeight;
706 
707  wxSize clamped_layout_size( Clamp( MIN_PAGE_SIZE, m_layout_size.x, m_maxPageSizeMils.x ),
709 
710  double lyRatio = clamped_layout_size.x < clamped_layout_size.y ?
711  (double) clamped_layout_size.y / clamped_layout_size.x :
712  (double) clamped_layout_size.x / clamped_layout_size.y;
713 
714  if( clamped_layout_size.x < clamped_layout_size.y )
715  {
716  lyHeight = MAX_PAGE_EXAMPLE_SIZE;
717  lyWidth = KiROUND( (double) lyHeight / lyRatio );
718  }
719  else
720  {
721  lyWidth = MAX_PAGE_EXAMPLE_SIZE;
722  lyHeight = KiROUND( (double) lyWidth / lyRatio );
723  }
724 
725  if( m_page_bitmap )
726  {
727  m_PageLayoutExampleBitmap->SetBitmap( wxNullBitmap );
728  delete m_page_bitmap;
729  }
730 
731  m_page_bitmap = new wxBitmap( lyWidth + 1, lyHeight + 1 );
732 
733  if( m_page_bitmap->IsOk() )
734  {
735  double scaleW = (double) lyWidth / clamped_layout_size.x;
736  double scaleH = (double) lyHeight / clamped_layout_size.y;
737 
738  // Prepare DC.
739  wxSize example_size( lyWidth + 1, lyHeight + 1 );
740  wxMemoryDC memDC;
741  memDC.SelectObject( *m_page_bitmap );
742  memDC.SetClippingRegion( wxPoint( 0, 0 ), example_size );
743  memDC.Clear();
744  memDC.SetUserScale( scaleW, scaleH );
745 
746  // Get logical page size and margins.
747  PAGE_INFO pageDUMMY;
748 
749  // Get page type
750  int idx = m_paperSizeComboBox->GetSelection();
751 
752  if( idx < 0 )
753  idx = 0;
754 
755  wxString pageFmtName = m_pageFmt[idx].BeforeFirst( ' ' );
756  bool portrait = clamped_layout_size.x < clamped_layout_size.y;
757  pageDUMMY.SetType( pageFmtName, portrait );
758  if( m_customFmt )
759  {
760  pageDUMMY.SetWidthMils( clamped_layout_size.x );
761  pageDUMMY.SetHeightMils( clamped_layout_size.y );
762  }
763 
764  // Draw layout preview.
765  wxString emptyString;
766  GRResetPenAndBrush( &memDC );
767 
769  GRFilledRect( NULL, &memDC, 0, 0, m_layout_size.x, m_layout_size.y, WHITE, WHITE );
770  PrintPageLayout( &memDC, pageDUMMY, emptyString, emptyString, m_tb,
772 
773  memDC.SelectObject( wxNullBitmap );
776 
777  // Refresh the dialog.
778  Layout();
779  Refresh();
780  }
781 }
782 
783 
785 {
786  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
787  const wxString paperType = m_pageFmt[idx];
788 
789  // here we assume translators will keep original paper size spellings
790  if( paperType.Contains( PAGE_INFO::Custom ) )
791  {
793 
794  if( m_layout_size.x && m_layout_size.y )
795  {
796  if( m_layout_size.x < m_layout_size.y )
797  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
798  else
799  m_orientationComboBox->SetStringSelection( _( "Landscape" ) );
800  }
801  }
802  else
803  {
804  PAGE_INFO pageInfo; // SetType() later to lookup size
805 
806  static const wxChar* papers[] = {
807  // longest common string first, since sequential search below
813  PAGE_INFO::A,
814  PAGE_INFO::B,
815  PAGE_INFO::C,
816  PAGE_INFO::D,
817  PAGE_INFO::E,
821  };
822 
823  unsigned i;
824 
825  for( i=0; i < arrayDim( papers ); ++i )
826  {
827  if( paperType.Contains( papers[i] ) )
828  {
829  pageInfo.SetType( papers[i] );
830  break;
831  }
832  }
833 
834  wxASSERT( i != arrayDim(papers) ); // dialog UI match the above list?
835 
836  m_layout_size = pageInfo.GetSizeMils();
837 
838  // swap sizes to match orientation
839  bool isPortrait = (bool) m_orientationComboBox->GetSelection();
840 
841  if( ( isPortrait && m_layout_size.x >= m_layout_size.y ) ||
842  ( !isPortrait && m_layout_size.x < m_layout_size.y ) )
843  {
845  }
846  }
847 }
848 
849 
851 {
852  double customSizeX = (double) m_customSizeX.GetValue() / IU_PER_MILS;
853  double customSizeY = (double) m_customSizeY.GetValue() / IU_PER_MILS;
854 
855  // Prepare to painless double -> int conversion.
856  customSizeX = Clamp( double( INT_MIN ), customSizeX, double( INT_MAX ) );
857  customSizeY = Clamp( double( INT_MIN ), customSizeY, double( INT_MAX ) );
858  m_layout_size = wxSize( KiROUND( customSizeX ), KiROUND( customSizeY ) );
859 }
860 
861 
862 void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
863 {
864  wxFileName fn = GetWksFileName();
865  wxString name = GetWksFileName();
866  wxString path;
867 
868  if( fn.IsAbsolute() )
869  {
870  path = fn.GetPath();
871  name = fn.GetFullName();
872  }
873  else
874  {
875  path = m_projectPath;
876  }
877 
878  // Display a file picker dialog
879  wxFileDialog fileDialog( this, _( "Select Page Layout Description File" ),
881  wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
882 
883  if( fileDialog.ShowModal() != wxID_OK )
884  return;
885 
886  wxString fileName = fileDialog.GetPath();
887 
888  // Try to remove the path, if the path is the current working dir,
889  // or the dir of kicad.pro (template), and use a relative path
890  wxString shortFileName = WS_DATA_MODEL::MakeShortFileName( fileName, m_projectPath );
891 
892  // For Win/Linux/macOS compatibility, a relative path is a good idea
893  if( shortFileName != GetWksFileName() && shortFileName != fileName )
894  {
895  wxString msg = wxString::Format( _(
896  "The page layout description file name has changed.\n"
897  "Do you want to use the relative path:\n"
898  "\"%s\"\n"
899  "instead of\n"
900  "\"%s\"?" ), GetChars( shortFileName ), GetChars( fileName ) );
901 
902  if( !IsOK( this, msg ) )
903  shortFileName = fileName;
904  }
905 
906  SetWksFileName( shortFileName );
907 
908  if( m_pagelayout == NULL )
910 
911  m_pagelayout->SetPageLayout( fileName );
912 
915 }
void OnDateApplyClick(wxCommandEvent &event) override
WS_DATA_MODEL handles the graphic items list to draw/plot the frame and title block.
Definition: ws_data_model.h:39
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)=0
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:120
static const wxChar A[]
Definition: page_info.h:69
wxString PageLayoutDescrFileWildcard()
SCH_SCREEN * GetNext()
Definition: sch_screen.cpp:994
int m_ScreenNumber
Definition: base_screen.h:135
void OnComment5TextUpdated(wxCommandEvent &event) override
wxSize m_maxPageSizeMils
Logical page layout size.
const T & Clamp(const T &lower, const T &value, const T &upper)
Function Clamp limits value within the range lower <= value <= upper.
Definition: macros.h:139
virtual const TITLE_BLOCK & GetTitleBlock() const =0
static int GetCustomHeightMils()
Function GetCustomHeightMils.
Definition: page_info.h:176
void OnPageOrientationChoice(wxCommandEvent &event) override
This file is part of the common library.
virtual void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)=0
void SetRevision(const wxString &aRevision)
Definition: title_block.h:84
const wxString & GetComment(int aIdx) const
Definition: title_block.h:110
int GetHeightMils() const
Definition: page_info.h:140
static const wxChar E[]
Definition: page_info.h:73
#define KEY_EXPORT_TITLE
void OnComment3TextUpdated(wxCommandEvent &event) override
static const wxChar GERBER[]
Definition: page_info.h:74
void GRFilledRect(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:888
TITLE_BLOCK m_tb
true if the page selection is custom
#define KEY_EXPORT_COMMENT3
static const wxChar A3[]
Definition: page_info.h:65
void OnComment7TextUpdated(wxCommandEvent &event) override
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
void SetWksFileName(const wxString &aFilename)
static void SetCustomWidthMils(int aWidthInMils)
Function SetCustomWidthMils sets the width of Custom page in mils, for any custom page constructed or...
Definition: page_info.cpp:227
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Function SetType sets the name of the page type and also the sizes and margins commonly associated wi...
Definition: page_info.cpp:117
void SetDate(const wxString &aDate)
Function SetDate sets the date field, and defaults to the current time and date.
Definition: title_block.h:74
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:128
#define PL_EDITOR_FRAME_NAME
void SetPageLayout(const wxString &aFullFileName=wxEmptyString, bool Append=false)
Populates the list with a custom layout, or the default layout, if no custom layout available.
void OnUserPageSizeXTextUpdated(wxCommandEvent &event) override
static const wxChar Custom[]
"User" defined page type
Definition: page_info.h:78
const wxString & GetType() const
Definition: page_info.h:97
#define KEY_EXPORT_COMMENT5
#define MAX_PAGE_EXAMPLE_SIZE
static const wxChar D[]
Definition: page_info.h:72
const wxString GetWksFileName()
bool m_initialized
list of page sizes (not translated)
The base class for create windows for drawing purpose.
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot,...
Definition: title_block.h:40
wxSize m_layout_size
Temporary bitmap for the page layout example.
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:102
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:51
static WS_DATA_MODEL & GetTheInstance()
static function: returns the instance of WS_DATA_MODEL used in the application
static void SetAltInstance(WS_DATA_MODEL *aLayout=NULL)
static function: Set an alternate instance of WS_DATA_MODEL mainly used in page setting dialog
wxBitmap * m_page_bitmap
the page layuout filename was changed
static wxString m_PageLayoutDescrFileName
the name of the page layout descr file, or emty to used the default pagelayout
Definition: base_screen.h:109
#define KEY_EXPORT_COMMENT6
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
virtual const PAGE_INFO & GetPageSettings() const =0
void OnComment8TextUpdated(wxCommandEvent &event) override
void OnComment1TextUpdated(wxCommandEvent &event) override
static const wxChar USLegal[]
Definition: page_info.h:76
void OnComment9TextUpdated(wxCommandEvent &event) override
static const wxChar B[]
Definition: page_info.h:70
void SetComment(int aIdx, const wxString &aComment)
Definition: title_block.h:104
static const wxChar C[]
Definition: page_info.h:71
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
const wxString & GetRevision() const
Definition: title_block.h:89
static const wxString MakeShortFileName(const wxString &aFullFileName, const wxString &aProjectPath)
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
#define KEY_EXPORT_COMMENT1
const wxString & GetCompany() const
Definition: title_block.h:99
#define KEY_EXPORT_REVISION
#define KEY_EXPORT_COMMENT7
void SetCompany(const wxString &aCompany)
Definition: title_block.h:94
Definition of file extensions used in Kicad.
static const wxChar A4[]
Definition: page_info.h:64
Definition: colors.h:60
const wxSize & GetSizeMils() const
Definition: page_info.h:142
void OnDateTextUpdated(wxCommandEvent &event) override
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: sch_screen.h:130
virtual bool Validate(long long int aMin, long long int aMax, bool setFocusOnError=true)
Function Validate Validates the control against the given range, informing the user of any errors fou...
void SetCurrentPageSizeSelection(const wxString &aPaperSize)
void SetTitle(const wxString &aTitle)
Definition: title_block.h:60
#define _(s)
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:253
#define KEY_EXPORT_COMMENT9
static const wxChar USLedger[]
Definition: page_info.h:77
DIALOG_PAGES_SETTINGS(EDA_DRAW_FRAME *parent, wxSize aMaxUserSizeMils)
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
void OnWksFileSelection(wxCommandEvent &event) override
Class DIALOG_PAGES_SETTINGS_BASE.
virtual void SaveProjectSettings(bool aAskForSave)
Save changes to the project settings to the project (.pro) file.
static const wxChar A1[]
Definition: page_info.h:67
const wxString & GetDate() const
Definition: title_block.h:79
void OnComment6TextUpdated(wxCommandEvent &event) override
static const wxChar USLetter[]
Definition: page_info.h:75
void OnOkClick(wxCommandEvent &event) override
#define KEY_EXPORT_COMMENT4
virtual void OnPageSettingsChange()
Called when modifying the page settings.
PAGE_INFO m_pageInfo
The max page size allowed by the caller frame.
void OnComment4TextUpdated(wxCommandEvent &event) override
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
#define KEY_EXPORT_COMMENT2
void OnUserPageSizeYTextUpdated(wxCommandEvent &event) override
static const wxString MakeFullFileName(const wxString &aShortFileName, const wxString &aProjectPath)
Static function.
const char * name
Definition: DXF_plotter.cpp:61
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
#define max(a, b)
Definition: auxiliary.h:86
bool IsPortrait() const
Definition: page_info.h:121
static const wxString pageFmts[]
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
size_t i
Definition: json11.cpp:649
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:239
#define IU_PER_MILS
Definition: plotter.cpp:136
The common library.
static int GetCustomWidthMils()
Function GetCustomWidthMils.
Definition: page_info.h:170
WS_DATA_MODEL * m_pagelayout
Temporary title block (basic inscriptions).
Definition: colors.h:49
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
bool m_customFmt
Temporary page info.
int m_NumberOfScreens
Definition: base_screen.h:136
static const wxChar A2[]
Definition: page_info.h:66
const wxString & GetTitle() const
Definition: title_block.h:65
SCH_SCREEN * GetFirst()
Definition: sch_screen.cpp:983
void OnComment2TextUpdated(wxCommandEvent &event) override
void OnPaperSizeChoice(wxCommandEvent &event) override
void OnTitleTextUpdated(wxCommandEvent &event) override
void OnCompanyTextUpdated(wxCommandEvent &event) override
void SetModify()
Definition: base_screen.h:224
void OnRevisionTextUpdated(wxCommandEvent &event) override
#define MIN_PAGE_SIZE
Min and max page sizes for clamping, in mils.
Definition: page_info.h:39
BASE_SCREEN class implementation.
#define KEY_EXPORT_COMPANY
#define _HKI(x)
void SetPortrait(bool aIsPortrait)
Function SetPortrait will rotate the paper page 90 degrees.
Definition: page_info.cpp:182
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:281
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SaveInString(wxString &aOutputString)
Save the description in a buffer.
void Enable(bool aEnable)
Function Enable Enables/diasables the label, widget and units label.
#define KEY_EXPORT_DATE
static void SetCustomHeightMils(int aHeightInMils)
Function SetCustomHeightMils sets the height of Custom page in mils, for any custom page constructed ...
Definition: page_info.cpp:233
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:491
int GetWidthMils() const
Definition: page_info.h:137
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:114
#define KEY_EXPORT_COMMENT8
static const wxChar A0[]
Definition: page_info.h:68
void PrintPageLayout(wxDC *aDC, const PAGE_INFO &aPageInfo, const wxString &aFullSheetName, const wxString &aFileName, const TITLE_BLOCK &aTitleBlock, int aSheetCount, int aSheetNumber, int aPenWidth, double aScalar, COLOR4D aColor, const wxString &aSheetLayer)
Function PrintPageLayout is a core function to print the page layout with the frame and the basic ins...