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 <base_screen.h>
25 #include <base_struct.h>
26 #include <common.h>
27 #include <confirm.h>
28 #include <dialog_page_settings.h>
29 #include <eda_draw_frame.h>
30 #include <fctsys.h>
31 #include <gr_basic.h>
32 #include <kiface_i.h>
33 #include <math/util.h> // for KiROUND, Clamp
34 #include <project.h>
35 #include <title_block.h>
36 #include <tool/actions.h>
37 #include <tool/tool_manager.h>
39 #include <ws_data_model.h>
40 #include <ws_painter.h>
41 #include <wx/valgen.h>
42 #include <wx/tokenzr.h>
43 
44 #ifdef EESCHEMA
45 #include <general.h>
46 #include <sch_screen.h>
47 #include <eeschema_settings.h>
48 #endif
49 
50 #define MAX_PAGE_EXAMPLE_SIZE 200
51 
52 
53 // List of page formats.
54 // they are prefixed by "_HKI" (already in use for hotkeys) instead of "_",
55 // because we need both the translated and the not translated version.
56 // when displayed in dialog we should explicitly call wxGetTranslation()
57 // to show the translated version.
58 // See hotkeys_basic.h for more info
59 #define _HKI( x ) wxT( x )
60 static const wxString pageFmts[] =
61 {
62  _HKI("A4 210x297mm"),
63  _HKI("A3 297x420mm"),
64  _HKI("A2 420x594mm"),
65  _HKI("A1 594x841mm"),
66  _HKI("A0 841x1189mm"),
67  _HKI("A 8.5x11in"),
68  _HKI("B 11x17in"),
69  _HKI("C 17x22in"),
70  _HKI("D 22x34in"),
71  _HKI("E 34x44in"),
72  _HKI("USLetter 8.5x11in"), // USLetter without space is correct
73  _HKI("USLegal 8.5x14in"), // USLegal without space is correct
74  _HKI("USLedger 11x17in"), // USLedger without space is correct
75  _HKI("User (Custom)"), // size defined by user. The string must contain "Custom"
76  // to be recognized in code
77 };
78 
79 DIALOG_PAGES_SETTINGS::DIALOG_PAGES_SETTINGS( EDA_DRAW_FRAME* parent, wxSize aMaxUserSizeMils ) :
81  m_initialized( false ),
82  m_customSizeX( parent, m_userSizeXLabel, m_userSizeXCtrl, m_userSizeXUnits, false ),
83  m_customSizeY( parent, m_userSizeYLabel, m_userSizeYCtrl, m_userSizeYUnits, false )
84 {
85  m_parent = parent;
89  m_maxPageSizeMils = aMaxUserSizeMils;
91  m_customFmt = false;
93 
95  wxString serialization;
97  m_pagelayout->SetPageLayout( TO_UTF8( serialization ) );
98 
99  m_PickDate->SetValue( wxDateTime::Now() );
100 
101  if( parent->GetName() == PL_EDITOR_FRAME_NAME )
102  {
103  SetTitle( _( "Preview Settings" ) );
104  m_staticTextPaper->SetLabel( _( "Preview Paper" ) );
105  m_staticTextTitleBlock->SetLabel( _( "Preview Title Block Data" ) );
106  }
107  else
108  {
109  SetTitle( _( "Page Settings" ) );
110  m_staticTextPaper->SetLabel( _( "Paper" ) );
111  m_staticTextTitleBlock->SetLabel( _( "Title Block" ) );
112  }
113 
114  initDialog();
115 
116  GetSizer()->SetSizeHints( this );
117  Centre();
118 }
119 
120 
122 {
123 #ifdef EESCHEMA
124  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
125  wxASSERT( cfg );
126 
127  cfg->m_PageSettings.export_revision = m_RevisionExport->GetValue();
128  cfg->m_PageSettings.export_date = m_DateExport->GetValue();
129  cfg->m_PageSettings.export_title = m_TitleExport->GetValue();
130  cfg->m_PageSettings.export_company = m_CompanyExport->GetValue();
131  cfg->m_PageSettings.export_comment1 = m_Comment1Export->GetValue();
132  cfg->m_PageSettings.export_comment2 = m_Comment2Export->GetValue();
133  cfg->m_PageSettings.export_comment3 = m_Comment3Export->GetValue();
134  cfg->m_PageSettings.export_comment4 = m_Comment4Export->GetValue();
135  cfg->m_PageSettings.export_comment5 = m_Comment5Export->GetValue();
136  cfg->m_PageSettings.export_comment6 = m_Comment6Export->GetValue();
137  cfg->m_PageSettings.export_comment7 = m_Comment7Export->GetValue();
138  cfg->m_PageSettings.export_comment8 = m_Comment8Export->GetValue();
139  cfg->m_PageSettings.export_comment9 = m_Comment9Export->GetValue();
140 #endif
141 
142  delete m_page_bitmap;
143  delete m_pagelayout;
144 }
145 
146 
148 {
149  wxString msg;
150 
151  // initialize page format choice box and page format list.
152  // The first shows translated strings, the second contains not translated strings
153  m_paperSizeComboBox->Clear();
154 
155  for( const wxString& pageFmt : pageFmts )
156  {
157  m_pageFmt.Add( pageFmt );
158  m_paperSizeComboBox->Append( wxGetTranslation( pageFmt ) );
159  }
160 
161  // initialize the page layout descr filename
163 
164 #ifdef EESCHEMA
165  // Init display value for schematic sub-sheet number
166  wxString format = m_TextSheetCount->GetLabel();
167  msg.Printf( format, m_screen->m_NumberOfScreens );
168  m_TextSheetCount->SetLabel( msg );
169 
170  format = m_TextSheetNumber->GetLabel();
171  msg.Printf( format, m_screen->m_ScreenNumber );
172  m_TextSheetNumber->SetLabel( msg );
173 #else
174  m_TextSheetCount->Show( false );
175  m_TextSheetNumber->Show( false );
176 #endif
177 
180  m_orientationComboBox->SetSelection( m_pageInfo.IsPortrait() );
181 
182  // only a click fires the "selection changed" event, so have to fabricate this check
183  wxCommandEvent dummy;
185 
186  if( m_customFmt )
187  {
190  }
191  else
192  {
195  }
196 
197  m_TextRevision->SetValue( m_tb.GetRevision() );
198  m_TextDate->SetValue( m_tb.GetDate() );
199  m_TextTitle->SetValue( m_tb.GetTitle() );
200  m_TextCompany->SetValue( m_tb.GetCompany() );
201  m_TextComment1->SetValue( m_tb.GetComment( 0 ) );
202  m_TextComment2->SetValue( m_tb.GetComment( 1 ) );
203  m_TextComment3->SetValue( m_tb.GetComment( 2 ) );
204  m_TextComment4->SetValue( m_tb.GetComment( 3 ) );
205  m_TextComment5->SetValue( m_tb.GetComment( 4 ) );
206  m_TextComment6->SetValue( m_tb.GetComment( 5 ) );
207  m_TextComment7->SetValue( m_tb.GetComment( 6 ) );
208  m_TextComment8->SetValue( m_tb.GetComment( 7 ) );
209  m_TextComment9->SetValue( m_tb.GetComment( 8 ) );
210 
211 #ifdef EESCHEMA
212  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
213  wxASSERT( cfg );
214 
215  m_RevisionExport->SetValue( cfg->m_PageSettings.export_revision );
216  m_DateExport->SetValue( cfg->m_PageSettings.export_date );
217  m_TitleExport->SetValue( cfg->m_PageSettings.export_title );
218  m_CompanyExport->SetValue( cfg->m_PageSettings.export_company );
219  m_Comment1Export->SetValue( cfg->m_PageSettings.export_comment1 );
220  m_Comment2Export->SetValue( cfg->m_PageSettings.export_comment2 );
221  m_Comment3Export->SetValue( cfg->m_PageSettings.export_comment3 );
222  m_Comment4Export->SetValue( cfg->m_PageSettings.export_comment4 );
223  m_Comment5Export->SetValue( cfg->m_PageSettings.export_comment5 );
224  m_Comment6Export->SetValue( cfg->m_PageSettings.export_comment6 );
225  m_Comment7Export->SetValue( cfg->m_PageSettings.export_comment7 );
226  m_Comment8Export->SetValue( cfg->m_PageSettings.export_comment8 );
227  m_Comment9Export->SetValue( cfg->m_PageSettings.export_comment9 );
228 #else
229  m_RevisionExport->Show( false );
230  m_DateExport->Show( false );
231  m_TitleExport->Show( false );
232  m_CompanyExport->Show( false );
233  m_Comment1Export->Show( false );
234  m_Comment2Export->Show( false );
235  m_Comment3Export->Show( false );
236  m_Comment4Export->Show( false );
237  m_Comment5Export->Show( false );
238  m_Comment6Export->Show( false );
239  m_Comment7Export->Show( false );
240  m_Comment8Export->Show( false );
241  m_Comment9Export->Show( false );
242 #endif
243 
246 
247  // Make the OK button the default.
248  m_sdbSizerOK->SetDefault();
249  m_initialized = true;
250 }
251 
252 
253 void DIALOG_PAGES_SETTINGS::OnOkClick( wxCommandEvent& event )
254 {
255  if( !m_customSizeX.Validate( Mils2iu( MIN_PAGE_SIZE ), Mils2iu( m_maxPageSizeMils.x ) ) )
256  return;
257 
258  if( !m_customSizeY.Validate( Mils2iu( MIN_PAGE_SIZE ), Mils2iu( m_maxPageSizeMils.y ) ) )
259  return;
260 
261  if( SavePageSettings() )
262  {
263  m_screen->SetModify();
264 
265  if( LocalPrjConfigChanged() )
267 
268  // Call the post processing (if any) after changes
270  }
271 
272  event.Skip();
273 }
274 
275 
276 void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
277 {
278  int idx = m_paperSizeComboBox->GetSelection();
279 
280  if( idx < 0 )
281  idx = 0;
282 
283  const wxString paperType = m_pageFmt[idx];
284 
285  if( paperType.Contains( PAGE_INFO::Custom ) )
286  {
287  m_orientationComboBox->Enable( false );
288  m_customSizeX.Enable( true );
289  m_customSizeY.Enable( true );
290  m_customFmt = true;
291  }
292  else
293  {
294  m_orientationComboBox->Enable( true );
295 
296 #if 0
297  // ForcePortrait() does not exist, but could be useful.
298  // so I leave these lines, which could be seen as a todo feature
299  if( paperType.ForcePortrait() )
300  {
301  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
302  m_orientationComboBox->Enable( false );
303  }
304 #endif
305  m_customSizeX.Enable( false );
306  m_customSizeY.Enable( false );
307  m_customFmt = false;
308  }
309 
312 }
313 
314 
316 {
317  if( m_initialized )
318  {
321  }
322 }
323 
324 
326 {
327  if( m_initialized )
328  {
331  }
332 }
333 
334 
336 {
337  if( m_initialized )
338  {
341  }
342 }
343 
344 
345 void DIALOG_PAGES_SETTINGS::OnRevisionTextUpdated( wxCommandEvent& event )
346 {
347  if( m_initialized && m_TextRevision->IsModified() )
348  {
350  m_tb.SetRevision( m_TextRevision->GetValue() );
352  }
353 }
354 
355 
356 void DIALOG_PAGES_SETTINGS::OnDateTextUpdated( wxCommandEvent& event )
357 {
358  if( m_initialized && m_TextDate->IsModified() )
359  {
361  m_tb.SetDate( m_TextDate->GetValue() );
363  }
364 }
365 
366 
367 void DIALOG_PAGES_SETTINGS::OnTitleTextUpdated( wxCommandEvent& event )
368 {
369  if( m_initialized && m_TextTitle->IsModified() )
370  {
372  m_tb.SetTitle( m_TextTitle->GetValue() );
374  }
375 }
376 
377 
378 void DIALOG_PAGES_SETTINGS::OnCompanyTextUpdated( wxCommandEvent& event )
379 {
380  if( m_initialized && m_TextCompany->IsModified() )
381  {
383  m_tb.SetCompany( m_TextCompany->GetValue() );
385  }
386 }
387 
388 
389 void DIALOG_PAGES_SETTINGS::OnComment1TextUpdated( wxCommandEvent& event )
390 {
391  if( m_initialized && m_TextComment1->IsModified() )
392  {
394  m_tb.SetComment( 0, m_TextComment1->GetValue() );
396  }
397 }
398 
399 
400 void DIALOG_PAGES_SETTINGS::OnComment2TextUpdated( wxCommandEvent& event )
401 {
402  if( m_initialized && m_TextComment2->IsModified() )
403  {
405  m_tb.SetComment( 1, m_TextComment2->GetValue() );
407  }
408 }
409 
410 
411 void DIALOG_PAGES_SETTINGS::OnComment3TextUpdated( wxCommandEvent& event )
412 {
413  if( m_initialized && m_TextComment3->IsModified() )
414  {
416  m_tb.SetComment( 2, m_TextComment3->GetValue() );
418  }
419 }
420 
421 
422 void DIALOG_PAGES_SETTINGS::OnComment4TextUpdated( wxCommandEvent& event )
423 {
424  if( m_initialized && m_TextComment4->IsModified() )
425  {
427  m_tb.SetComment( 3, m_TextComment4->GetValue() );
429  }
430 }
431 
432 
433 void DIALOG_PAGES_SETTINGS::OnComment5TextUpdated( wxCommandEvent& event )
434 {
435  if( m_initialized && m_TextComment5->IsModified() )
436  {
438  m_tb.SetComment( 4, m_TextComment5->GetValue() );
440  }
441 }
442 
443 
444 void DIALOG_PAGES_SETTINGS::OnComment6TextUpdated( wxCommandEvent& event )
445 {
446  if( m_initialized && m_TextComment6->IsModified() )
447  {
449  m_tb.SetComment( 5, m_TextComment6->GetValue() );
451  }
452 }
453 
454 
455 void DIALOG_PAGES_SETTINGS::OnComment7TextUpdated( wxCommandEvent& event )
456 {
457  if( m_initialized && m_TextComment7->IsModified() )
458  {
460  m_tb.SetComment( 6, m_TextComment7->GetValue() );
462  }
463 }
464 
465 
466 void DIALOG_PAGES_SETTINGS::OnComment8TextUpdated( wxCommandEvent& event )
467 {
468  if( m_initialized && m_TextComment8->IsModified() )
469  {
471  m_tb.SetComment( 7, m_TextComment8->GetValue() );
473  }
474 }
475 
476 
477 void DIALOG_PAGES_SETTINGS::OnComment9TextUpdated( wxCommandEvent& event )
478 {
479  if( m_initialized && m_TextComment9->IsModified() )
480  {
482  m_tb.SetComment( 8, m_TextComment9->GetValue() );
484  }
485 }
486 
487 
488 void DIALOG_PAGES_SETTINGS::OnDateApplyClick( wxCommandEvent& event )
489 {
490  wxDateTime datetime = m_PickDate->GetValue();
491  wxString date =
492  // We can choose different formats. Only one must be uncommented
493  //
494  // datetime.Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
495  // datetime.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
496  // datetime.Format( wxT("%Y-%b-%d") );
497  datetime.FormatISODate();
498 
499  m_TextDate->SetValue( date );
500 }
501 
502 
504 {
505  bool success = false;
506 
507  wxString fileName = GetWksFileName();
508 
510  {
511  wxString fullFileName = WS_DATA_MODEL::MakeFullFileName( fileName, m_projectPath );
512 
513  if( !fullFileName.IsEmpty() && !wxFileExists( fullFileName ) )
514  {
515  wxString msg;
516  msg.Printf( _( "Page layout description file \"%s\" not found." ),
517  GetChars( fullFileName ) );
518  wxMessageBox( msg );
519  return false;
520  }
521 
524  pglayout.SetPageLayout( fullFileName );
526  }
527 
528  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
529  const wxString paperType = m_pageFmt[idx];
530 
531  if( paperType.Contains( PAGE_INFO::Custom ) )
532  {
534 
535  success = m_pageInfo.SetType( PAGE_INFO::Custom );
536 
537  if( success )
538  {
541 
544  }
545  }
546  else
547  {
548  // search for longest common string first, e.g. A4 before A
549  if( paperType.Contains( PAGE_INFO::USLetter ) )
551  else if( paperType.Contains( PAGE_INFO::USLegal ) )
553  else if( paperType.Contains( PAGE_INFO::USLedger ) )
555  else if( paperType.Contains( PAGE_INFO::GERBER ) )
556  success = m_pageInfo.SetType( PAGE_INFO::GERBER );
557  else if( paperType.Contains( PAGE_INFO::A4 ) )
558  success = m_pageInfo.SetType( PAGE_INFO::A4 );
559  else if( paperType.Contains( PAGE_INFO::A3 ) )
560  success = m_pageInfo.SetType( PAGE_INFO::A3 );
561  else if( paperType.Contains( PAGE_INFO::A2 ) )
562  success = m_pageInfo.SetType( PAGE_INFO::A2 );
563  else if( paperType.Contains( PAGE_INFO::A1 ) )
564  success = m_pageInfo.SetType( PAGE_INFO::A1 );
565  else if( paperType.Contains( PAGE_INFO::A0 ) )
566  success = m_pageInfo.SetType( PAGE_INFO::A0 );
567  else if( paperType.Contains( PAGE_INFO::A ) )
568  success = m_pageInfo.SetType( PAGE_INFO::A );
569  else if( paperType.Contains( PAGE_INFO::B ) )
570  success = m_pageInfo.SetType( PAGE_INFO::B );
571  else if( paperType.Contains( PAGE_INFO::C ) )
572  success = m_pageInfo.SetType( PAGE_INFO::C );
573  else if( paperType.Contains( PAGE_INFO::D ) )
574  success = m_pageInfo.SetType( PAGE_INFO::D );
575  else if( paperType.Contains( PAGE_INFO::E ) )
576  success = m_pageInfo.SetType( PAGE_INFO::E );
577 
578  if( success )
579  {
580  int choice = m_orientationComboBox->GetSelection();
581  m_pageInfo.SetPortrait( choice != 0 );
582  }
583  }
584 
585  if( !success )
586  {
587  wxASSERT_MSG( false, _( "the translation for paper size must preserve original spellings" ) );
589  }
590 
592 
593  m_tb.SetRevision( m_TextRevision->GetValue() );
594  m_tb.SetDate( m_TextDate->GetValue() );
595  m_tb.SetCompany( m_TextCompany->GetValue() );
596  m_tb.SetTitle( m_TextTitle->GetValue() );
597  m_tb.SetComment( 0, m_TextComment1->GetValue() );
598  m_tb.SetComment( 1, m_TextComment2->GetValue() );
599  m_tb.SetComment( 2, m_TextComment3->GetValue() );
600  m_tb.SetComment( 3, m_TextComment4->GetValue() );
601  m_tb.SetComment( 4, m_TextComment5->GetValue() );
602  m_tb.SetComment( 5, m_TextComment6->GetValue() );
603  m_tb.SetComment( 6, m_TextComment7->GetValue() );
604  m_tb.SetComment( 7, m_TextComment8->GetValue() );
605  m_tb.SetComment( 8, m_TextComment9->GetValue() );
606 
608 
609 
610 #ifdef EESCHEMA
611  // Exports settings to other sheets if requested:
612  SCH_SCREEN* screen;
613 
614  // Build the screen list
615  SCH_SCREENS ScreenList;
616 
617  // Update title blocks for all screens
618  for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
619  {
620  if( screen == m_screen )
621  continue;
622 
623  TITLE_BLOCK tb2 = screen->GetTitleBlock();
624 
625  if( m_RevisionExport->IsChecked() )
626  tb2.SetRevision( m_tb.GetRevision() );
627 
628  if( m_DateExport->IsChecked() )
629  tb2.SetDate( m_tb.GetDate() );
630 
631  if( m_TitleExport->IsChecked() )
632  tb2.SetTitle( m_tb.GetTitle() );
633 
634  if( m_CompanyExport->IsChecked() )
635  tb2.SetCompany( m_tb.GetCompany() );
636 
637  if( m_Comment1Export->IsChecked() )
638  tb2.SetComment( 0, m_tb.GetComment( 0 ) );
639 
640  if( m_Comment2Export->IsChecked() )
641  tb2.SetComment( 1, m_tb.GetComment( 1 ) );
642 
643  if( m_Comment3Export->IsChecked() )
644  tb2.SetComment( 2, m_tb.GetComment( 2 ) );
645 
646  if( m_Comment4Export->IsChecked() )
647  tb2.SetComment( 3, m_tb.GetComment( 3 ) );
648 
649  if( m_Comment5Export->IsChecked() )
650  tb2.SetComment( 4, m_tb.GetComment( 4 ) );
651 
652  if( m_Comment6Export->IsChecked() )
653  tb2.SetComment( 5, m_tb.GetComment( 5 ) );
654 
655  if( m_Comment7Export->IsChecked() )
656  tb2.SetComment( 6, m_tb.GetComment( 6 ) );
657 
658  if( m_Comment8Export->IsChecked() )
659  tb2.SetComment( 7, m_tb.GetComment( 7 ) );
660 
661  if( m_Comment9Export->IsChecked() )
662  tb2.SetComment( 8, m_tb.GetComment( 8 ) );
663 
664  screen->SetTitleBlock( tb2 );
665  }
666 
667 #endif
668 
669  return true;
670 }
671 
672 
673 void DIALOG_PAGES_SETTINGS::SetCurrentPageSizeSelection( const wxString& aPaperSize )
674 {
675  // search all the not translated label list containing our paper type
676  for( unsigned i = 0; i < m_pageFmt.GetCount(); ++i )
677  {
678  // parse each label looking for aPaperSize within it
679  wxStringTokenizer st( m_pageFmt[i] );
680 
681  while( st.HasMoreTokens() )
682  {
683  if( st.GetNextToken() == aPaperSize )
684  {
685  m_paperSizeComboBox->SetSelection( i );
686  return;
687  }
688  }
689  }
690 }
691 
692 
694 {
695  int lyWidth, lyHeight;
696 
697  wxSize clamped_layout_size( Clamp( MIN_PAGE_SIZE, m_layout_size.x, m_maxPageSizeMils.x ),
699 
700  double lyRatio = clamped_layout_size.x < clamped_layout_size.y ?
701  (double) clamped_layout_size.y / clamped_layout_size.x :
702  (double) clamped_layout_size.x / clamped_layout_size.y;
703 
704  if( clamped_layout_size.x < clamped_layout_size.y )
705  {
706  lyHeight = MAX_PAGE_EXAMPLE_SIZE;
707  lyWidth = KiROUND( (double) lyHeight / lyRatio );
708  }
709  else
710  {
711  lyWidth = MAX_PAGE_EXAMPLE_SIZE;
712  lyHeight = KiROUND( (double) lyWidth / lyRatio );
713  }
714 
715  if( m_page_bitmap )
716  {
717  m_PageLayoutExampleBitmap->SetBitmap( wxNullBitmap );
718  delete m_page_bitmap;
719  }
720 
721  m_page_bitmap = new wxBitmap( lyWidth + 1, lyHeight + 1 );
722 
723  if( m_page_bitmap->IsOk() )
724  {
725  double scaleW = (double) lyWidth / clamped_layout_size.x;
726  double scaleH = (double) lyHeight / clamped_layout_size.y;
727 
728  // Prepare DC.
729  wxSize example_size( lyWidth + 1, lyHeight + 1 );
730  wxMemoryDC memDC;
731  memDC.SelectObject( *m_page_bitmap );
732  memDC.SetClippingRegion( wxPoint( 0, 0 ), example_size );
733  memDC.Clear();
734  memDC.SetUserScale( scaleW, scaleH );
735 
736  // Get logical page size and margins.
737  PAGE_INFO pageDUMMY;
738 
739  // Get page type
740  int idx = m_paperSizeComboBox->GetSelection();
741 
742  if( idx < 0 )
743  idx = 0;
744 
745  wxString pageFmtName = m_pageFmt[idx].BeforeFirst( ' ' );
746  bool portrait = clamped_layout_size.x < clamped_layout_size.y;
747  pageDUMMY.SetType( pageFmtName, portrait );
748  if( m_customFmt )
749  {
750  pageDUMMY.SetWidthMils( clamped_layout_size.x );
751  pageDUMMY.SetHeightMils( clamped_layout_size.y );
752  }
753 
754  // Draw layout preview.
755  wxString emptyString;
756  GRResetPenAndBrush( &memDC );
757 
759  GRFilledRect( NULL, &memDC, 0, 0, m_layout_size.x, m_layout_size.y, WHITE, WHITE );
760  PrintPageLayout( &memDC, pageDUMMY, emptyString, emptyString, m_tb,
762 
763  memDC.SelectObject( wxNullBitmap );
766 
767  // Refresh the dialog.
768  Layout();
769  Refresh();
770  }
771 }
772 
773 
775 {
776  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
777  const wxString paperType = m_pageFmt[idx];
778 
779  // here we assume translators will keep original paper size spellings
780  if( paperType.Contains( PAGE_INFO::Custom ) )
781  {
783 
784  if( m_layout_size.x && m_layout_size.y )
785  {
786  if( m_layout_size.x < m_layout_size.y )
787  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
788  else
789  m_orientationComboBox->SetStringSelection( _( "Landscape" ) );
790  }
791  }
792  else
793  {
794  PAGE_INFO pageInfo; // SetType() later to lookup size
795 
796  static const wxChar* papers[] = {
797  // longest common string first, since sequential search below
803  PAGE_INFO::A,
804  PAGE_INFO::B,
805  PAGE_INFO::C,
806  PAGE_INFO::D,
807  PAGE_INFO::E,
811  };
812 
813  unsigned i;
814 
815  for( i=0; i < arrayDim( papers ); ++i )
816  {
817  if( paperType.Contains( papers[i] ) )
818  {
819  pageInfo.SetType( papers[i] );
820  break;
821  }
822  }
823 
824  wxASSERT( i != arrayDim(papers) ); // dialog UI match the above list?
825 
826  m_layout_size = pageInfo.GetSizeMils();
827 
828  // swap sizes to match orientation
829  bool isPortrait = (bool) m_orientationComboBox->GetSelection();
830 
831  if( ( isPortrait && m_layout_size.x >= m_layout_size.y ) ||
832  ( !isPortrait && m_layout_size.x < m_layout_size.y ) )
833  {
835  }
836  }
837 }
838 
839 
841 {
842  double customSizeX = (double) m_customSizeX.GetValue() / IU_PER_MILS;
843  double customSizeY = (double) m_customSizeY.GetValue() / IU_PER_MILS;
844 
845  // Prepare to painless double -> int conversion.
846  customSizeX = Clamp( double( INT_MIN ), customSizeX, double( INT_MAX ) );
847  customSizeY = Clamp( double( INT_MIN ), customSizeY, double( INT_MAX ) );
848  m_layout_size = wxSize( KiROUND( customSizeX ), KiROUND( customSizeY ) );
849 }
850 
851 
852 void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
853 {
854  wxFileName fn = GetWksFileName();
855  wxString name = GetWksFileName();
856  wxString path;
857 
858  if( fn.IsAbsolute() )
859  {
860  path = fn.GetPath();
861  name = fn.GetFullName();
862  }
863  else
864  {
865  path = m_projectPath;
866  }
867 
868  // Display a file picker dialog
869  wxFileDialog fileDialog( this, _( "Select Page Layout Description File" ),
871  wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
872 
873  if( fileDialog.ShowModal() != wxID_OK )
874  return;
875 
876  wxString fileName = fileDialog.GetPath();
877 
878  // Try to remove the path, if the path is the current working dir,
879  // or the dir of kicad.pro (template), and use a relative path
880  wxString shortFileName = WS_DATA_MODEL::MakeShortFileName( fileName, m_projectPath );
881 
882  // For Win/Linux/macOS compatibility, a relative path is a good idea
883  if( shortFileName != GetWksFileName() && shortFileName != fileName )
884  {
885  wxString msg = wxString::Format( _(
886  "The page layout description file name has changed.\n"
887  "Do you want to use the relative path:\n"
888  "\"%s\"\n"
889  "instead of\n"
890  "\"%s\"?" ), GetChars( shortFileName ), GetChars( fileName ) );
891 
892  if( !IsOK( this, msg ) )
893  shortFileName = fileName;
894  }
895 
896  SetWksFileName( shortFileName );
897 
898  if( m_pagelayout == NULL )
900 
901  m_pagelayout->SetPageLayout( fileName );
902 
905 }
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:970
int m_ScreenNumber
Definition: base_screen.h:135
void OnComment5TextUpdated(wxCommandEvent &event) override
wxSize m_maxPageSizeMils
Logical page layout size.
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
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:884
TITLE_BLOCK m_tb
true if the page selection is custom
static const wxChar A3[]
Definition: page_info.h:65
void OnComment7TextUpdated(wxCommandEvent &event) override
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
virtual void SaveProjectSettings()
Save changes to the project settings to the project (.pro) file.
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:162
static const char * emptyString
#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 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.
TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout,...
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
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 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
#define NULL
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)
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
const wxString & GetCompany() const
Definition: title_block.h:99
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
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:164
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
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:253
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.
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
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
void OnUserPageSizeYTextUpdated(wxCommandEvent &event) override
static const wxString MakeFullFileName(const wxString &aShortFileName, const wxString &aProjectPath)
Static function.
const char * name
Definition: DXF_plotter.cpp:60
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.
bool IsPortrait() const
Definition: page_info.h:121
#define _(s)
Definition: 3d_actions.cpp:33
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...
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:239
#define IU_PER_MILS
Definition: plotter.cpp:137
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:61
The common library.
const T & Clamp(const T &lower, const T &value, const T &upper)
Function Clamp limits value within the range lower <= value <= upper.
Definition: util.h:45
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:959
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 _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:283
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.
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
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...