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_edit_frame.h>
47 #include <sch_screen.h>
48 #include <schematic.h>
49 #include <eeschema_settings.h>
50 #endif
51 
52 #define MAX_PAGE_EXAMPLE_SIZE 200
53 
54 
55 // List of page formats.
56 // they are prefixed by "_HKI" (already in use for hotkeys) instead of "_",
57 // because we need both the translated and the not translated version.
58 // when displayed in dialog we should explicitly call wxGetTranslation()
59 // to show the translated version.
60 // See hotkeys_basic.h for more info
61 #define _HKI( x ) wxT( x )
62 static const wxString pageFmts[] =
63 {
64  _HKI("A5 148x210mm"),
65  _HKI("A4 210x297mm"),
66  _HKI("A3 297x420mm"),
67  _HKI("A2 420x594mm"),
68  _HKI("A1 594x841mm"),
69  _HKI("A0 841x1189mm"),
70  _HKI("A 8.5x11in"),
71  _HKI("B 11x17in"),
72  _HKI("C 17x22in"),
73  _HKI("D 22x34in"),
74  _HKI("E 34x44in"),
75  _HKI("USLetter 8.5x11in"), // USLetter without space is correct
76  _HKI("USLegal 8.5x14in"), // USLegal without space is correct
77  _HKI("USLedger 11x17in"), // USLedger without space is correct
78  _HKI("User (Custom)"), // size defined by user. The string must contain "Custom"
79  // to be recognized in code
80 };
81 
82 DIALOG_PAGES_SETTINGS::DIALOG_PAGES_SETTINGS( EDA_DRAW_FRAME* parent, wxSize aMaxUserSizeMils ) :
84  m_initialized( false ),
85  m_customSizeX( parent, m_userSizeXLabel, m_userSizeXCtrl, m_userSizeXUnits, false ),
86  m_customSizeY( parent, m_userSizeYLabel, m_userSizeYCtrl, m_userSizeYUnits, false )
87 {
88  m_parent = parent;
92  m_maxPageSizeMils = aMaxUserSizeMils;
94  m_customFmt = false;
96 
98  wxString serialization;
100  m_pagelayout->SetPageLayout( TO_UTF8( serialization ) );
101 
102  m_PickDate->SetValue( wxDateTime::Now() );
103 
104  if( parent->GetName() == PL_EDITOR_FRAME_NAME )
105  {
106  SetTitle( _( "Preview Settings" ) );
107  m_staticTextPaper->SetLabel( _( "Preview Paper" ) );
108  m_staticTextTitleBlock->SetLabel( _( "Preview Title Block Data" ) );
109  }
110  else
111  {
112  SetTitle( _( "Page Settings" ) );
113  m_staticTextPaper->SetLabel( _( "Paper" ) );
114  m_staticTextTitleBlock->SetLabel( _( "Title Block" ) );
115  }
116 
117  initDialog();
118 
119  GetSizer()->SetSizeHints( this );
120  Centre();
121 }
122 
123 
125 {
126 #ifdef EESCHEMA
127  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
128  wxASSERT( cfg );
129 
130  cfg->m_PageSettings.export_paper = m_PaperExport->GetValue();
131  cfg->m_PageSettings.export_revision = m_RevisionExport->GetValue();
132  cfg->m_PageSettings.export_date = m_DateExport->GetValue();
133  cfg->m_PageSettings.export_title = m_TitleExport->GetValue();
134  cfg->m_PageSettings.export_company = m_CompanyExport->GetValue();
135  cfg->m_PageSettings.export_comment1 = m_Comment1Export->GetValue();
136  cfg->m_PageSettings.export_comment2 = m_Comment2Export->GetValue();
137  cfg->m_PageSettings.export_comment3 = m_Comment3Export->GetValue();
138  cfg->m_PageSettings.export_comment4 = m_Comment4Export->GetValue();
139  cfg->m_PageSettings.export_comment5 = m_Comment5Export->GetValue();
140  cfg->m_PageSettings.export_comment6 = m_Comment6Export->GetValue();
141  cfg->m_PageSettings.export_comment7 = m_Comment7Export->GetValue();
142  cfg->m_PageSettings.export_comment8 = m_Comment8Export->GetValue();
143  cfg->m_PageSettings.export_comment9 = m_Comment9Export->GetValue();
144 #endif
145 
146  delete m_page_bitmap;
147  delete m_pagelayout;
148 }
149 
150 
152 {
153  wxString msg;
154 
155  // initialize page format choice box and page format list.
156  // The first shows translated strings, the second contains not translated strings
157  m_paperSizeComboBox->Clear();
158 
159  for( const wxString& pageFmt : pageFmts )
160  {
161  m_pageFmt.Add( pageFmt );
162  m_paperSizeComboBox->Append( wxGetTranslation( pageFmt ) );
163  }
164 
165  // initialize the page layout descr filename
167 
168 #ifdef EESCHEMA
169  // Init display value for schematic sub-sheet number
170  wxString format = m_TextSheetCount->GetLabel();
171  msg.Printf( format, m_screen->m_NumberOfScreens );
172  m_TextSheetCount->SetLabel( msg );
173 
174  format = m_TextSheetNumber->GetLabel();
175  msg.Printf( format, m_screen->m_ScreenNumber );
176  m_TextSheetNumber->SetLabel( msg );
177 #else
178  m_TextSheetCount->Show( false );
179  m_TextSheetNumber->Show( false );
180 #endif
181 
184  m_orientationComboBox->SetSelection( m_pageInfo.IsPortrait() );
185 
186  // only a click fires the "selection changed" event, so have to fabricate this check
187  wxCommandEvent dummy;
189 
190  if( m_customFmt )
191  {
194  }
195  else
196  {
199  }
200 
201  m_TextRevision->SetValue( m_tb.GetRevision() );
202  m_TextDate->SetValue( m_tb.GetDate() );
203  m_TextTitle->SetValue( m_tb.GetTitle() );
204  m_TextCompany->SetValue( m_tb.GetCompany() );
205  m_TextComment1->SetValue( m_tb.GetComment( 0 ) );
206  m_TextComment2->SetValue( m_tb.GetComment( 1 ) );
207  m_TextComment3->SetValue( m_tb.GetComment( 2 ) );
208  m_TextComment4->SetValue( m_tb.GetComment( 3 ) );
209  m_TextComment5->SetValue( m_tb.GetComment( 4 ) );
210  m_TextComment6->SetValue( m_tb.GetComment( 5 ) );
211  m_TextComment7->SetValue( m_tb.GetComment( 6 ) );
212  m_TextComment8->SetValue( m_tb.GetComment( 7 ) );
213  m_TextComment9->SetValue( m_tb.GetComment( 8 ) );
214 
215 #ifdef EESCHEMA
216  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
217  wxASSERT( cfg );
218 
219  m_PaperExport->SetValue( cfg->m_PageSettings.export_paper );
220  m_RevisionExport->SetValue( cfg->m_PageSettings.export_revision );
221  m_DateExport->SetValue( cfg->m_PageSettings.export_date );
222  m_TitleExport->SetValue( cfg->m_PageSettings.export_title );
223  m_CompanyExport->SetValue( cfg->m_PageSettings.export_company );
224  m_Comment1Export->SetValue( cfg->m_PageSettings.export_comment1 );
225  m_Comment2Export->SetValue( cfg->m_PageSettings.export_comment2 );
226  m_Comment3Export->SetValue( cfg->m_PageSettings.export_comment3 );
227  m_Comment4Export->SetValue( cfg->m_PageSettings.export_comment4 );
228  m_Comment5Export->SetValue( cfg->m_PageSettings.export_comment5 );
229  m_Comment6Export->SetValue( cfg->m_PageSettings.export_comment6 );
230  m_Comment7Export->SetValue( cfg->m_PageSettings.export_comment7 );
231  m_Comment8Export->SetValue( cfg->m_PageSettings.export_comment8 );
232  m_Comment9Export->SetValue( cfg->m_PageSettings.export_comment9 );
233 #else
234  m_PaperExport->Show( false );
235  m_RevisionExport->Show( false );
236  m_DateExport->Show( false );
237  m_TitleExport->Show( false );
238  m_CompanyExport->Show( false );
239  m_Comment1Export->Show( false );
240  m_Comment2Export->Show( false );
241  m_Comment3Export->Show( false );
242  m_Comment4Export->Show( false );
243  m_Comment5Export->Show( false );
244  m_Comment6Export->Show( false );
245  m_Comment7Export->Show( false );
246  m_Comment8Export->Show( false );
247  m_Comment9Export->Show( false );
248 #endif
249 
252 
253  // Make the OK button the default.
254  m_sdbSizerOK->SetDefault();
255  m_initialized = true;
256 }
257 
258 
259 void DIALOG_PAGES_SETTINGS::OnOkClick( wxCommandEvent& event )
260 {
262  return;
263 
265  return;
266 
267  if( SavePageSettings() )
268  {
269  m_screen->SetModify();
270 
271  if( LocalPrjConfigChanged() )
273 
274  // Call the post processing (if any) after changes
276  }
277 
278  event.Skip();
279 }
280 
281 
282 void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
283 {
284  int idx = m_paperSizeComboBox->GetSelection();
285 
286  if( idx < 0 )
287  idx = 0;
288 
289  const wxString paperType = m_pageFmt[idx];
290 
291  if( paperType.Contains( PAGE_INFO::Custom ) )
292  {
293  m_orientationComboBox->Enable( false );
294  m_customSizeX.Enable( true );
295  m_customSizeY.Enable( true );
296  m_customFmt = true;
297  }
298  else
299  {
300  m_orientationComboBox->Enable( true );
301 
302 #if 0
303  // ForcePortrait() does not exist, but could be useful.
304  // so I leave these lines, which could be seen as a todo feature
305  if( paperType.ForcePortrait() )
306  {
307  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
308  m_orientationComboBox->Enable( false );
309  }
310 #endif
311  m_customSizeX.Enable( false );
312  m_customSizeY.Enable( false );
313  m_customFmt = false;
314  }
315 
318 }
319 
320 
322 {
323  if( m_initialized )
324  {
327  }
328 }
329 
330 
332 {
333  if( m_initialized )
334  {
337  }
338 }
339 
340 
342 {
343  if( m_initialized )
344  {
347  }
348 }
349 
350 
351 void DIALOG_PAGES_SETTINGS::OnRevisionTextUpdated( wxCommandEvent& event )
352 {
353  if( m_initialized && m_TextRevision->IsModified() )
354  {
356  m_tb.SetRevision( m_TextRevision->GetValue() );
358  }
359 }
360 
361 
362 void DIALOG_PAGES_SETTINGS::OnDateTextUpdated( wxCommandEvent& event )
363 {
364  if( m_initialized && m_TextDate->IsModified() )
365  {
367  m_tb.SetDate( m_TextDate->GetValue() );
369  }
370 }
371 
372 
373 void DIALOG_PAGES_SETTINGS::OnTitleTextUpdated( wxCommandEvent& event )
374 {
375  if( m_initialized && m_TextTitle->IsModified() )
376  {
378  m_tb.SetTitle( m_TextTitle->GetValue() );
380  }
381 }
382 
383 
384 void DIALOG_PAGES_SETTINGS::OnCompanyTextUpdated( wxCommandEvent& event )
385 {
386  if( m_initialized && m_TextCompany->IsModified() )
387  {
389  m_tb.SetCompany( m_TextCompany->GetValue() );
391  }
392 }
393 
394 
395 void DIALOG_PAGES_SETTINGS::OnComment1TextUpdated( wxCommandEvent& event )
396 {
397  if( m_initialized && m_TextComment1->IsModified() )
398  {
400  m_tb.SetComment( 0, m_TextComment1->GetValue() );
402  }
403 }
404 
405 
406 void DIALOG_PAGES_SETTINGS::OnComment2TextUpdated( wxCommandEvent& event )
407 {
408  if( m_initialized && m_TextComment2->IsModified() )
409  {
411  m_tb.SetComment( 1, m_TextComment2->GetValue() );
413  }
414 }
415 
416 
417 void DIALOG_PAGES_SETTINGS::OnComment3TextUpdated( wxCommandEvent& event )
418 {
419  if( m_initialized && m_TextComment3->IsModified() )
420  {
422  m_tb.SetComment( 2, m_TextComment3->GetValue() );
424  }
425 }
426 
427 
428 void DIALOG_PAGES_SETTINGS::OnComment4TextUpdated( wxCommandEvent& event )
429 {
430  if( m_initialized && m_TextComment4->IsModified() )
431  {
433  m_tb.SetComment( 3, m_TextComment4->GetValue() );
435  }
436 }
437 
438 
439 void DIALOG_PAGES_SETTINGS::OnComment5TextUpdated( wxCommandEvent& event )
440 {
441  if( m_initialized && m_TextComment5->IsModified() )
442  {
444  m_tb.SetComment( 4, m_TextComment5->GetValue() );
446  }
447 }
448 
449 
450 void DIALOG_PAGES_SETTINGS::OnComment6TextUpdated( wxCommandEvent& event )
451 {
452  if( m_initialized && m_TextComment6->IsModified() )
453  {
455  m_tb.SetComment( 5, m_TextComment6->GetValue() );
457  }
458 }
459 
460 
461 void DIALOG_PAGES_SETTINGS::OnComment7TextUpdated( wxCommandEvent& event )
462 {
463  if( m_initialized && m_TextComment7->IsModified() )
464  {
466  m_tb.SetComment( 6, m_TextComment7->GetValue() );
468  }
469 }
470 
471 
472 void DIALOG_PAGES_SETTINGS::OnComment8TextUpdated( wxCommandEvent& event )
473 {
474  if( m_initialized && m_TextComment8->IsModified() )
475  {
477  m_tb.SetComment( 7, m_TextComment8->GetValue() );
479  }
480 }
481 
482 
483 void DIALOG_PAGES_SETTINGS::OnComment9TextUpdated( wxCommandEvent& event )
484 {
485  if( m_initialized && m_TextComment9->IsModified() )
486  {
488  m_tb.SetComment( 8, m_TextComment9->GetValue() );
490  }
491 }
492 
493 
494 void DIALOG_PAGES_SETTINGS::OnDateApplyClick( wxCommandEvent& event )
495 {
496  wxDateTime datetime = m_PickDate->GetValue();
497  wxString date =
498  // We can choose different formats. Only one must be uncommented
499  //
500  // datetime.Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
501  // datetime.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
502  // datetime.Format( wxT("%Y-%b-%d") );
503  datetime.FormatISODate();
504 
505  m_TextDate->SetValue( date );
506 }
507 
508 
510 {
511  bool success = false;
512 
513  wxString fileName = GetWksFileName();
514 
516  {
517  wxString fullFileName = WS_DATA_MODEL::MakeFullFileName( fileName, m_projectPath );
518 
519  if( !fullFileName.IsEmpty() && !wxFileExists( fullFileName ) )
520  {
521  wxString msg;
522  msg.Printf( _( "Page layout description file \"%s\" not found." ),
523  GetChars( fullFileName ) );
524  wxMessageBox( msg );
525  return false;
526  }
527 
530  pglayout.SetPageLayout( fullFileName );
532  }
533 
534  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
535  const wxString paperType = m_pageFmt[idx];
536 
537  if( paperType.Contains( PAGE_INFO::Custom ) )
538  {
540 
541  success = m_pageInfo.SetType( PAGE_INFO::Custom );
542 
543  if( success )
544  {
547 
550  }
551  }
552  else
553  {
554  // search for longest common string first, e.g. A4 before A
555  if( paperType.Contains( PAGE_INFO::USLetter ) )
557  else if( paperType.Contains( PAGE_INFO::USLegal ) )
559  else if( paperType.Contains( PAGE_INFO::USLedger ) )
561  else if( paperType.Contains( PAGE_INFO::GERBER ) )
562  success = m_pageInfo.SetType( PAGE_INFO::GERBER );
563  else if( paperType.Contains( PAGE_INFO::A5 ) )
564  success = m_pageInfo.SetType( PAGE_INFO::A5 );
565  else if( paperType.Contains( PAGE_INFO::A4 ) )
566  success = m_pageInfo.SetType( PAGE_INFO::A4 );
567  else if( paperType.Contains( PAGE_INFO::A3 ) )
568  success = m_pageInfo.SetType( PAGE_INFO::A3 );
569  else if( paperType.Contains( PAGE_INFO::A2 ) )
570  success = m_pageInfo.SetType( PAGE_INFO::A2 );
571  else if( paperType.Contains( PAGE_INFO::A1 ) )
572  success = m_pageInfo.SetType( PAGE_INFO::A1 );
573  else if( paperType.Contains( PAGE_INFO::A0 ) )
574  success = m_pageInfo.SetType( PAGE_INFO::A0 );
575  else if( paperType.Contains( PAGE_INFO::A ) )
576  success = m_pageInfo.SetType( PAGE_INFO::A );
577  else if( paperType.Contains( PAGE_INFO::B ) )
578  success = m_pageInfo.SetType( PAGE_INFO::B );
579  else if( paperType.Contains( PAGE_INFO::C ) )
580  success = m_pageInfo.SetType( PAGE_INFO::C );
581  else if( paperType.Contains( PAGE_INFO::D ) )
582  success = m_pageInfo.SetType( PAGE_INFO::D );
583  else if( paperType.Contains( PAGE_INFO::E ) )
584  success = m_pageInfo.SetType( PAGE_INFO::E );
585 
586  if( success )
587  {
588  int choice = m_orientationComboBox->GetSelection();
589  m_pageInfo.SetPortrait( choice != 0 );
590  }
591  }
592 
593  if( !success )
594  {
595  wxASSERT_MSG( false, _( "the translation for paper size must preserve original spellings" ) );
597  }
598 
600 
601  m_tb.SetRevision( m_TextRevision->GetValue() );
602  m_tb.SetDate( m_TextDate->GetValue() );
603  m_tb.SetCompany( m_TextCompany->GetValue() );
604  m_tb.SetTitle( m_TextTitle->GetValue() );
605  m_tb.SetComment( 0, m_TextComment1->GetValue() );
606  m_tb.SetComment( 1, m_TextComment2->GetValue() );
607  m_tb.SetComment( 2, m_TextComment3->GetValue() );
608  m_tb.SetComment( 3, m_TextComment4->GetValue() );
609  m_tb.SetComment( 4, m_TextComment5->GetValue() );
610  m_tb.SetComment( 5, m_TextComment6->GetValue() );
611  m_tb.SetComment( 6, m_TextComment7->GetValue() );
612  m_tb.SetComment( 7, m_TextComment8->GetValue() );
613  m_tb.SetComment( 8, m_TextComment9->GetValue() );
614 
616 
617 
618 #ifdef EESCHEMA
619  wxCHECK_MSG( dynamic_cast<SCH_EDIT_FRAME*>( m_parent ), true,
620  "DIALOG_PAGES_SETTINGS::OnDateApplyClick frame is not a schematic frame!" );
621 
622  // Exports settings to other sheets if requested:
623  SCH_SCREENS ScreenList( dynamic_cast<SCH_EDIT_FRAME*>( m_parent )->Schematic().Root() );
624 
625  // Update page info and/or title blocks for all screens
626  for( SCH_SCREEN* screen = ScreenList.GetFirst(); screen; screen = ScreenList.GetNext() )
627  {
628  if( screen == m_screen )
629  continue;
630 
631  if( m_PaperExport->IsChecked() )
632  screen->SetPageSettings( m_pageInfo );
633 
634  TITLE_BLOCK tb2 = screen->GetTitleBlock();
635 
636  if( m_RevisionExport->IsChecked() )
637  tb2.SetRevision( m_tb.GetRevision() );
638 
639  if( m_DateExport->IsChecked() )
640  tb2.SetDate( m_tb.GetDate() );
641 
642  if( m_TitleExport->IsChecked() )
643  tb2.SetTitle( m_tb.GetTitle() );
644 
645  if( m_CompanyExport->IsChecked() )
646  tb2.SetCompany( m_tb.GetCompany() );
647 
648  if( m_Comment1Export->IsChecked() )
649  tb2.SetComment( 0, m_tb.GetComment( 0 ) );
650 
651  if( m_Comment2Export->IsChecked() )
652  tb2.SetComment( 1, m_tb.GetComment( 1 ) );
653 
654  if( m_Comment3Export->IsChecked() )
655  tb2.SetComment( 2, m_tb.GetComment( 2 ) );
656 
657  if( m_Comment4Export->IsChecked() )
658  tb2.SetComment( 3, m_tb.GetComment( 3 ) );
659 
660  if( m_Comment5Export->IsChecked() )
661  tb2.SetComment( 4, m_tb.GetComment( 4 ) );
662 
663  if( m_Comment6Export->IsChecked() )
664  tb2.SetComment( 5, m_tb.GetComment( 5 ) );
665 
666  if( m_Comment7Export->IsChecked() )
667  tb2.SetComment( 6, m_tb.GetComment( 6 ) );
668 
669  if( m_Comment8Export->IsChecked() )
670  tb2.SetComment( 7, m_tb.GetComment( 7 ) );
671 
672  if( m_Comment9Export->IsChecked() )
673  tb2.SetComment( 8, m_tb.GetComment( 8 ) );
674 
675  screen->SetTitleBlock( tb2 );
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_MILS, 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  KIGFX::WS_RENDER_SETTINGS renderSettings;
770  renderSettings.SetDefaultPenWidth( 1 );
771  renderSettings.SetLayerColor( LAYER_WORKSHEET, COLOR4D( RED ) );
772  renderSettings.SetPrintDC( &memDC );
773 
774  GRFilledRect( NULL, &memDC, 0, 0, m_layout_size.x, m_layout_size.y, WHITE, WHITE );
775 
776  PrintPageLayout( &renderSettings, pageDUMMY, emptyString, emptyString, m_tb,
778 
779  memDC.SelectObject( wxNullBitmap );
782 
783  // Refresh the dialog.
784  Layout();
785  Refresh();
786  }
787 }
788 
789 
791 {
792  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
793  const wxString paperType = m_pageFmt[idx];
794 
795  // here we assume translators will keep original paper size spellings
796  if( paperType.Contains( PAGE_INFO::Custom ) )
797  {
799 
800  if( m_layout_size.x && m_layout_size.y )
801  {
802  if( m_layout_size.x < m_layout_size.y )
803  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
804  else
805  m_orientationComboBox->SetStringSelection( _( "Landscape" ) );
806  }
807  }
808  else
809  {
810  PAGE_INFO pageInfo; // SetType() later to lookup size
811 
812  static const wxChar* papers[] = {
813  // longest common string first, since sequential search below
820  PAGE_INFO::A,
821  PAGE_INFO::B,
822  PAGE_INFO::C,
823  PAGE_INFO::D,
824  PAGE_INFO::E,
828  };
829 
830  unsigned i;
831 
832  for( i=0; i < arrayDim( papers ); ++i )
833  {
834  if( paperType.Contains( papers[i] ) )
835  {
836  pageInfo.SetType( papers[i] );
837  break;
838  }
839  }
840 
841  wxASSERT( i != arrayDim(papers) ); // dialog UI match the above list?
842 
843  m_layout_size = pageInfo.GetSizeMils();
844 
845  // swap sizes to match orientation
846  bool isPortrait = (bool) m_orientationComboBox->GetSelection();
847 
848  if( ( isPortrait && m_layout_size.x >= m_layout_size.y ) ||
849  ( !isPortrait && m_layout_size.x < m_layout_size.y ) )
850  {
852  }
853  }
854 }
855 
856 
858 {
859  double customSizeX = (double) m_customSizeX.GetValue() / IU_PER_MILS;
860  double customSizeY = (double) m_customSizeY.GetValue() / IU_PER_MILS;
861 
862  // Prepare to painless double -> int conversion.
863  customSizeX = Clamp( double( INT_MIN ), customSizeX, double( INT_MAX ) );
864  customSizeY = Clamp( double( INT_MIN ), customSizeY, double( INT_MAX ) );
865  m_layout_size = wxSize( KiROUND( customSizeX ), KiROUND( customSizeY ) );
866 }
867 
868 
869 void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
870 {
871  wxFileName fn = GetWksFileName();
872  wxString name = GetWksFileName();
873  wxString path;
874 
875  if( fn.IsAbsolute() )
876  {
877  path = fn.GetPath();
878  name = fn.GetFullName();
879  }
880  else
881  {
882  path = m_projectPath;
883  }
884 
885  // Display a file picker dialog
886  wxFileDialog fileDialog( this, _( "Select Page Layout Description File" ),
888  wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
889 
890  if( fileDialog.ShowModal() != wxID_OK )
891  return;
892 
893  wxString fileName = fileDialog.GetPath();
894 
895  // Try to remove the path, if the path is the current working dir,
896  // or the dir of kicad.pro (template), and use a relative path
897  wxString shortFileName = WS_DATA_MODEL::MakeShortFileName( fileName, m_projectPath );
898 
899  // For Win/Linux/macOS compatibility, a relative path is a good idea
900  if( shortFileName != GetWksFileName() && shortFileName != fileName )
901  {
902  wxString msg = wxString::Format( _(
903  "The page layout description file name has changed.\n"
904  "Do you want to use the relative path:\n"
905  "\"%s\"\n"
906  "instead of\n"
907  "\"%s\"?" ), GetChars( shortFileName ), GetChars( fileName ) );
908 
909  if( !IsOK( this, msg ) )
910  shortFileName = fileName;
911  }
912 
913  SetWksFileName( shortFileName );
914 
915  if( m_pagelayout == NULL )
917 
918  m_pagelayout->SetPageLayout( fileName );
919 
922 }
WS_RENDER_SETTINGS Stores page-layout-specific render settings.
Definition: ws_painter.h:47
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:122
static const wxChar A[]
Definition: page_info.h:70
wxString PageLayoutDescrFileWildcard()
SCH_SCREEN * GetNext()
int m_ScreenNumber
Definition: base_screen.h:79
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:177
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:141
static const wxChar E[]
Definition: page_info.h:74
void OnComment3TextUpdated(wxCommandEvent &event) override
static const wxChar GERBER[]
Definition: page_info.h:75
void GRFilledRect(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:886
TITLE_BLOCK m_tb
true if the page selection is custom
static const wxChar A3[]
Definition: page_info.h:66
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:231
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:119
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
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:79
const wxString & GetType() const
Definition: page_info.h:98
#define MAX_PAGE_EXAMPLE_SIZE
static const wxChar D[]
Definition: page_info.h:73
const wxString GetWksFileName()
bool m_initialized
list of page sizes (not translated)
The base class for create windows for drawing purpose.
#define MIN_PAGE_SIZE_MILS
Min and max page sizes for clamping, in mils.
Definition: page_info.h:39
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:124
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:57
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:100
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:77
void OnComment9TextUpdated(wxCommandEvent &event) override
static const wxChar B[]
Definition: page_info.h:71
void SetComment(int aIdx, const wxString &aComment)
Definition: title_block.h:104
#define NULL
static const wxChar C[]
Definition: page_info.h:72
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.
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Function SetLayerColor Changes the color used to draw a layer.
static const wxChar A4[]
Definition: page_info.h:65
const wxSize & GetSizeMils() const
Definition: page_info.h:143
void OnDateTextUpdated(wxCommandEvent &event) override
void SetCurrentPageSizeSelection(const wxString &aPaperSize)
void SetTitle(const wxString &aTitle)
Definition: title_block.h:60
Definition: color4d.h:59
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:257
static const wxChar USLedger[]
Definition: page_info.h:78
DIALOG_PAGES_SETTINGS(EDA_DRAW_FRAME *parent, wxSize aMaxUserSizeMils)
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:160
void OnWksFileSelection(wxCommandEvent &event) override
Class DIALOG_PAGES_SETTINGS_BASE.
Definition: color4d.h:48
static const wxChar A1[]
Definition: page_info.h:68
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED, bool aUseMils=false)
Function Validate Validates the control against the given range, informing the user of any errors fou...
const wxString & GetDate() const
Definition: title_block.h:79
void OnComment6TextUpdated(wxCommandEvent &event) override
static const wxChar USLetter[]
Definition: page_info.h:76
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:153
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:201
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
void PrintPageLayout(RENDER_SETTINGS *aSettings, const PAGE_INFO &aPageInfo, const wxString &aFullSheetName, const wxString &aFileName, const TITLE_BLOCK &aTitleBlock, int aSheetCount, int aSheetNumber, double aScalar, const PROJECT *aProject, const wxString &aSheetLayer)
Function PrintPageLayout is a core function to print the page layout with the frame and the basic ins...
bool IsPortrait() const
Definition: page_info.h:122
#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:243
static const wxChar A5[]
Definition: page_info.h:64
#define IU_PER_MILS
Definition: plotter.cpp:138
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:68
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:46
static int GetCustomWidthMils()
Function GetCustomWidthMils.
Definition: page_info.h:171
WS_DATA_MODEL * m_pagelayout
Temporary title block (basic inscriptions).
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:80
static const wxChar A2[]
Definition: page_info.h:67
const wxString & GetTitle() const
Definition: title_block.h:65
SCH_SCREEN * GetFirst()
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:100
void OnRevisionTextUpdated(wxCommandEvent &event) override
void SetDefaultPenWidth(int aWidth)
BASE_SCREEN class implementation.
#define _HKI(x)
void SetPortrait(bool aIsPortrait)
Function SetPortrait will rotate the paper page 90 degrees.
Definition: page_info.cpp:186
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:283
void SetPrintDC(wxDC *aDC)
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:237
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:515
int GetWidthMils() const
Definition: page_info.h:138
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99
static const wxChar A0[]
Definition: page_info.h:69