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("A4 210x297mm"),
65  _HKI("A3 297x420mm"),
66  _HKI("A2 420x594mm"),
67  _HKI("A1 594x841mm"),
68  _HKI("A0 841x1189mm"),
69  _HKI("A 8.5x11in"),
70  _HKI("B 11x17in"),
71  _HKI("C 17x22in"),
72  _HKI("D 22x34in"),
73  _HKI("E 34x44in"),
74  _HKI("USLetter 8.5x11in"), // USLetter without space is correct
75  _HKI("USLegal 8.5x14in"), // USLegal without space is correct
76  _HKI("USLedger 11x17in"), // USLedger without space is correct
77  _HKI("User (Custom)"), // size defined by user. The string must contain "Custom"
78  // to be recognized in code
79 };
80 
81 DIALOG_PAGES_SETTINGS::DIALOG_PAGES_SETTINGS( EDA_DRAW_FRAME* parent, wxSize aMaxUserSizeMils ) :
83  m_initialized( false ),
84  m_customSizeX( parent, m_userSizeXLabel, m_userSizeXCtrl, m_userSizeXUnits, false ),
85  m_customSizeY( parent, m_userSizeYLabel, m_userSizeYCtrl, m_userSizeYUnits, false )
86 {
87  m_parent = parent;
91  m_maxPageSizeMils = aMaxUserSizeMils;
93  m_customFmt = false;
95 
97  wxString serialization;
99  m_pagelayout->SetPageLayout( TO_UTF8( serialization ) );
100 
101  m_PickDate->SetValue( wxDateTime::Now() );
102 
103  if( parent->GetName() == PL_EDITOR_FRAME_NAME )
104  {
105  SetTitle( _( "Preview Settings" ) );
106  m_staticTextPaper->SetLabel( _( "Preview Paper" ) );
107  m_staticTextTitleBlock->SetLabel( _( "Preview Title Block Data" ) );
108  }
109  else
110  {
111  SetTitle( _( "Page Settings" ) );
112  m_staticTextPaper->SetLabel( _( "Paper" ) );
113  m_staticTextTitleBlock->SetLabel( _( "Title Block" ) );
114  }
115 
116  initDialog();
117 
118  GetSizer()->SetSizeHints( this );
119  Centre();
120 }
121 
122 
124 {
125 #ifdef EESCHEMA
126  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
127  wxASSERT( cfg );
128 
129  cfg->m_PageSettings.export_paper = m_PaperExport->GetValue();
130  cfg->m_PageSettings.export_revision = m_RevisionExport->GetValue();
131  cfg->m_PageSettings.export_date = m_DateExport->GetValue();
132  cfg->m_PageSettings.export_title = m_TitleExport->GetValue();
133  cfg->m_PageSettings.export_company = m_CompanyExport->GetValue();
134  cfg->m_PageSettings.export_comment1 = m_Comment1Export->GetValue();
135  cfg->m_PageSettings.export_comment2 = m_Comment2Export->GetValue();
136  cfg->m_PageSettings.export_comment3 = m_Comment3Export->GetValue();
137  cfg->m_PageSettings.export_comment4 = m_Comment4Export->GetValue();
138  cfg->m_PageSettings.export_comment5 = m_Comment5Export->GetValue();
139  cfg->m_PageSettings.export_comment6 = m_Comment6Export->GetValue();
140  cfg->m_PageSettings.export_comment7 = m_Comment7Export->GetValue();
141  cfg->m_PageSettings.export_comment8 = m_Comment8Export->GetValue();
142  cfg->m_PageSettings.export_comment9 = m_Comment9Export->GetValue();
143 #endif
144 
145  delete m_page_bitmap;
146  delete m_pagelayout;
147 }
148 
149 
151 {
152  wxString msg;
153 
154  // initialize page format choice box and page format list.
155  // The first shows translated strings, the second contains not translated strings
156  m_paperSizeComboBox->Clear();
157 
158  for( const wxString& pageFmt : pageFmts )
159  {
160  m_pageFmt.Add( pageFmt );
161  m_paperSizeComboBox->Append( wxGetTranslation( pageFmt ) );
162  }
163 
164  // initialize the page layout descr filename
166 
167 #ifdef EESCHEMA
168  // Init display value for schematic sub-sheet number
169  wxString format = m_TextSheetCount->GetLabel();
170  msg.Printf( format, m_screen->m_NumberOfScreens );
171  m_TextSheetCount->SetLabel( msg );
172 
173  format = m_TextSheetNumber->GetLabel();
174  msg.Printf( format, m_screen->m_ScreenNumber );
175  m_TextSheetNumber->SetLabel( msg );
176 #else
177  m_TextSheetCount->Show( false );
178  m_TextSheetNumber->Show( false );
179 #endif
180 
183  m_orientationComboBox->SetSelection( m_pageInfo.IsPortrait() );
184 
185  // only a click fires the "selection changed" event, so have to fabricate this check
186  wxCommandEvent dummy;
188 
189  if( m_customFmt )
190  {
193  }
194  else
195  {
198  }
199 
200  m_TextRevision->SetValue( m_tb.GetRevision() );
201  m_TextDate->SetValue( m_tb.GetDate() );
202  m_TextTitle->SetValue( m_tb.GetTitle() );
203  m_TextCompany->SetValue( m_tb.GetCompany() );
204  m_TextComment1->SetValue( m_tb.GetComment( 0 ) );
205  m_TextComment2->SetValue( m_tb.GetComment( 1 ) );
206  m_TextComment3->SetValue( m_tb.GetComment( 2 ) );
207  m_TextComment4->SetValue( m_tb.GetComment( 3 ) );
208  m_TextComment5->SetValue( m_tb.GetComment( 4 ) );
209  m_TextComment6->SetValue( m_tb.GetComment( 5 ) );
210  m_TextComment7->SetValue( m_tb.GetComment( 6 ) );
211  m_TextComment8->SetValue( m_tb.GetComment( 7 ) );
212  m_TextComment9->SetValue( m_tb.GetComment( 8 ) );
213 
214 #ifdef EESCHEMA
215  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
216  wxASSERT( cfg );
217 
218  m_PaperExport->SetValue( cfg->m_PageSettings.export_paper );
219  m_RevisionExport->SetValue( cfg->m_PageSettings.export_revision );
220  m_DateExport->SetValue( cfg->m_PageSettings.export_date );
221  m_TitleExport->SetValue( cfg->m_PageSettings.export_title );
222  m_CompanyExport->SetValue( cfg->m_PageSettings.export_company );
223  m_Comment1Export->SetValue( cfg->m_PageSettings.export_comment1 );
224  m_Comment2Export->SetValue( cfg->m_PageSettings.export_comment2 );
225  m_Comment3Export->SetValue( cfg->m_PageSettings.export_comment3 );
226  m_Comment4Export->SetValue( cfg->m_PageSettings.export_comment4 );
227  m_Comment5Export->SetValue( cfg->m_PageSettings.export_comment5 );
228  m_Comment6Export->SetValue( cfg->m_PageSettings.export_comment6 );
229  m_Comment7Export->SetValue( cfg->m_PageSettings.export_comment7 );
230  m_Comment8Export->SetValue( cfg->m_PageSettings.export_comment8 );
231  m_Comment9Export->SetValue( cfg->m_PageSettings.export_comment9 );
232 #else
233  m_PaperExport->Show( false );
234  m_RevisionExport->Show( false );
235  m_DateExport->Show( false );
236  m_TitleExport->Show( false );
237  m_CompanyExport->Show( false );
238  m_Comment1Export->Show( false );
239  m_Comment2Export->Show( false );
240  m_Comment3Export->Show( false );
241  m_Comment4Export->Show( false );
242  m_Comment5Export->Show( false );
243  m_Comment6Export->Show( false );
244  m_Comment7Export->Show( false );
245  m_Comment8Export->Show( false );
246  m_Comment9Export->Show( false );
247 #endif
248 
251 
252  // Make the OK button the default.
253  m_sdbSizerOK->SetDefault();
254  m_initialized = true;
255 }
256 
257 
258 void DIALOG_PAGES_SETTINGS::OnOkClick( wxCommandEvent& event )
259 {
261  return;
262 
264  return;
265 
266  if( SavePageSettings() )
267  {
268  m_screen->SetModify();
269 
270  if( LocalPrjConfigChanged() )
272 
273  // Call the post processing (if any) after changes
275  }
276 
277  event.Skip();
278 }
279 
280 
281 void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
282 {
283  int idx = m_paperSizeComboBox->GetSelection();
284 
285  if( idx < 0 )
286  idx = 0;
287 
288  const wxString paperType = m_pageFmt[idx];
289 
290  if( paperType.Contains( PAGE_INFO::Custom ) )
291  {
292  m_orientationComboBox->Enable( false );
293  m_customSizeX.Enable( true );
294  m_customSizeY.Enable( true );
295  m_customFmt = true;
296  }
297  else
298  {
299  m_orientationComboBox->Enable( true );
300 
301 #if 0
302  // ForcePortrait() does not exist, but could be useful.
303  // so I leave these lines, which could be seen as a todo feature
304  if( paperType.ForcePortrait() )
305  {
306  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
307  m_orientationComboBox->Enable( false );
308  }
309 #endif
310  m_customSizeX.Enable( false );
311  m_customSizeY.Enable( false );
312  m_customFmt = false;
313  }
314 
317 }
318 
319 
321 {
322  if( m_initialized )
323  {
326  }
327 }
328 
329 
331 {
332  if( m_initialized )
333  {
336  }
337 }
338 
339 
341 {
342  if( m_initialized )
343  {
346  }
347 }
348 
349 
350 void DIALOG_PAGES_SETTINGS::OnRevisionTextUpdated( wxCommandEvent& event )
351 {
352  if( m_initialized && m_TextRevision->IsModified() )
353  {
355  m_tb.SetRevision( m_TextRevision->GetValue() );
357  }
358 }
359 
360 
361 void DIALOG_PAGES_SETTINGS::OnDateTextUpdated( wxCommandEvent& event )
362 {
363  if( m_initialized && m_TextDate->IsModified() )
364  {
366  m_tb.SetDate( m_TextDate->GetValue() );
368  }
369 }
370 
371 
372 void DIALOG_PAGES_SETTINGS::OnTitleTextUpdated( wxCommandEvent& event )
373 {
374  if( m_initialized && m_TextTitle->IsModified() )
375  {
377  m_tb.SetTitle( m_TextTitle->GetValue() );
379  }
380 }
381 
382 
383 void DIALOG_PAGES_SETTINGS::OnCompanyTextUpdated( wxCommandEvent& event )
384 {
385  if( m_initialized && m_TextCompany->IsModified() )
386  {
388  m_tb.SetCompany( m_TextCompany->GetValue() );
390  }
391 }
392 
393 
394 void DIALOG_PAGES_SETTINGS::OnComment1TextUpdated( wxCommandEvent& event )
395 {
396  if( m_initialized && m_TextComment1->IsModified() )
397  {
399  m_tb.SetComment( 0, m_TextComment1->GetValue() );
401  }
402 }
403 
404 
405 void DIALOG_PAGES_SETTINGS::OnComment2TextUpdated( wxCommandEvent& event )
406 {
407  if( m_initialized && m_TextComment2->IsModified() )
408  {
410  m_tb.SetComment( 1, m_TextComment2->GetValue() );
412  }
413 }
414 
415 
416 void DIALOG_PAGES_SETTINGS::OnComment3TextUpdated( wxCommandEvent& event )
417 {
418  if( m_initialized && m_TextComment3->IsModified() )
419  {
421  m_tb.SetComment( 2, m_TextComment3->GetValue() );
423  }
424 }
425 
426 
427 void DIALOG_PAGES_SETTINGS::OnComment4TextUpdated( wxCommandEvent& event )
428 {
429  if( m_initialized && m_TextComment4->IsModified() )
430  {
432  m_tb.SetComment( 3, m_TextComment4->GetValue() );
434  }
435 }
436 
437 
438 void DIALOG_PAGES_SETTINGS::OnComment5TextUpdated( wxCommandEvent& event )
439 {
440  if( m_initialized && m_TextComment5->IsModified() )
441  {
443  m_tb.SetComment( 4, m_TextComment5->GetValue() );
445  }
446 }
447 
448 
449 void DIALOG_PAGES_SETTINGS::OnComment6TextUpdated( wxCommandEvent& event )
450 {
451  if( m_initialized && m_TextComment6->IsModified() )
452  {
454  m_tb.SetComment( 5, m_TextComment6->GetValue() );
456  }
457 }
458 
459 
460 void DIALOG_PAGES_SETTINGS::OnComment7TextUpdated( wxCommandEvent& event )
461 {
462  if( m_initialized && m_TextComment7->IsModified() )
463  {
465  m_tb.SetComment( 6, m_TextComment7->GetValue() );
467  }
468 }
469 
470 
471 void DIALOG_PAGES_SETTINGS::OnComment8TextUpdated( wxCommandEvent& event )
472 {
473  if( m_initialized && m_TextComment8->IsModified() )
474  {
476  m_tb.SetComment( 7, m_TextComment8->GetValue() );
478  }
479 }
480 
481 
482 void DIALOG_PAGES_SETTINGS::OnComment9TextUpdated( wxCommandEvent& event )
483 {
484  if( m_initialized && m_TextComment9->IsModified() )
485  {
487  m_tb.SetComment( 8, m_TextComment9->GetValue() );
489  }
490 }
491 
492 
493 void DIALOG_PAGES_SETTINGS::OnDateApplyClick( wxCommandEvent& event )
494 {
495  wxDateTime datetime = m_PickDate->GetValue();
496  wxString date =
497  // We can choose different formats. Only one must be uncommented
498  //
499  // datetime.Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
500  // datetime.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
501  // datetime.Format( wxT("%Y-%b-%d") );
502  datetime.FormatISODate();
503 
504  m_TextDate->SetValue( date );
505 }
506 
507 
509 {
510  bool success = false;
511 
512  wxString fileName = GetWksFileName();
513 
515  {
516  wxString fullFileName = WS_DATA_MODEL::MakeFullFileName( fileName, m_projectPath );
517 
518  if( !fullFileName.IsEmpty() && !wxFileExists( fullFileName ) )
519  {
520  wxString msg;
521  msg.Printf( _( "Page layout description file \"%s\" not found." ),
522  GetChars( fullFileName ) );
523  wxMessageBox( msg );
524  return false;
525  }
526 
529  pglayout.SetPageLayout( fullFileName );
531  }
532 
533  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
534  const wxString paperType = m_pageFmt[idx];
535 
536  if( paperType.Contains( PAGE_INFO::Custom ) )
537  {
539 
540  success = m_pageInfo.SetType( PAGE_INFO::Custom );
541 
542  if( success )
543  {
546 
549  }
550  }
551  else
552  {
553  // search for longest common string first, e.g. A4 before A
554  if( paperType.Contains( PAGE_INFO::USLetter ) )
556  else if( paperType.Contains( PAGE_INFO::USLegal ) )
558  else if( paperType.Contains( PAGE_INFO::USLedger ) )
560  else if( paperType.Contains( PAGE_INFO::GERBER ) )
561  success = m_pageInfo.SetType( PAGE_INFO::GERBER );
562  else if( paperType.Contains( PAGE_INFO::A4 ) )
563  success = m_pageInfo.SetType( PAGE_INFO::A4 );
564  else if( paperType.Contains( PAGE_INFO::A3 ) )
565  success = m_pageInfo.SetType( PAGE_INFO::A3 );
566  else if( paperType.Contains( PAGE_INFO::A2 ) )
567  success = m_pageInfo.SetType( PAGE_INFO::A2 );
568  else if( paperType.Contains( PAGE_INFO::A1 ) )
569  success = m_pageInfo.SetType( PAGE_INFO::A1 );
570  else if( paperType.Contains( PAGE_INFO::A0 ) )
571  success = m_pageInfo.SetType( PAGE_INFO::A0 );
572  else if( paperType.Contains( PAGE_INFO::A ) )
573  success = m_pageInfo.SetType( PAGE_INFO::A );
574  else if( paperType.Contains( PAGE_INFO::B ) )
575  success = m_pageInfo.SetType( PAGE_INFO::B );
576  else if( paperType.Contains( PAGE_INFO::C ) )
577  success = m_pageInfo.SetType( PAGE_INFO::C );
578  else if( paperType.Contains( PAGE_INFO::D ) )
579  success = m_pageInfo.SetType( PAGE_INFO::D );
580  else if( paperType.Contains( PAGE_INFO::E ) )
581  success = m_pageInfo.SetType( PAGE_INFO::E );
582 
583  if( success )
584  {
585  int choice = m_orientationComboBox->GetSelection();
586  m_pageInfo.SetPortrait( choice != 0 );
587  }
588  }
589 
590  if( !success )
591  {
592  wxASSERT_MSG( false, _( "the translation for paper size must preserve original spellings" ) );
594  }
595 
597 
598  m_tb.SetRevision( m_TextRevision->GetValue() );
599  m_tb.SetDate( m_TextDate->GetValue() );
600  m_tb.SetCompany( m_TextCompany->GetValue() );
601  m_tb.SetTitle( m_TextTitle->GetValue() );
602  m_tb.SetComment( 0, m_TextComment1->GetValue() );
603  m_tb.SetComment( 1, m_TextComment2->GetValue() );
604  m_tb.SetComment( 2, m_TextComment3->GetValue() );
605  m_tb.SetComment( 3, m_TextComment4->GetValue() );
606  m_tb.SetComment( 4, m_TextComment5->GetValue() );
607  m_tb.SetComment( 5, m_TextComment6->GetValue() );
608  m_tb.SetComment( 6, m_TextComment7->GetValue() );
609  m_tb.SetComment( 7, m_TextComment8->GetValue() );
610  m_tb.SetComment( 8, m_TextComment9->GetValue() );
611 
613 
614 
615 #ifdef EESCHEMA
616  wxCHECK_MSG( dynamic_cast<SCH_EDIT_FRAME*>( m_parent ), true,
617  "DIALOG_PAGES_SETTINGS::OnDateApplyClick frame is not a schematic frame!" );
618 
619  // Exports settings to other sheets if requested:
620  SCH_SCREENS ScreenList( dynamic_cast<SCH_EDIT_FRAME*>( m_parent )->Schematic().Root() );
621 
622  // Update page info and/or title blocks for all screens
623  for( SCH_SCREEN* screen = ScreenList.GetFirst(); screen; screen = ScreenList.GetNext() )
624  {
625  if( screen == m_screen )
626  continue;
627 
628  if( m_PaperExport->IsChecked() )
629  screen->SetPageSettings( m_pageInfo );
630 
631  TITLE_BLOCK tb2 = screen->GetTitleBlock();
632 
633  if( m_RevisionExport->IsChecked() )
634  tb2.SetRevision( m_tb.GetRevision() );
635 
636  if( m_DateExport->IsChecked() )
637  tb2.SetDate( m_tb.GetDate() );
638 
639  if( m_TitleExport->IsChecked() )
640  tb2.SetTitle( m_tb.GetTitle() );
641 
642  if( m_CompanyExport->IsChecked() )
643  tb2.SetCompany( m_tb.GetCompany() );
644 
645  if( m_Comment1Export->IsChecked() )
646  tb2.SetComment( 0, m_tb.GetComment( 0 ) );
647 
648  if( m_Comment2Export->IsChecked() )
649  tb2.SetComment( 1, m_tb.GetComment( 1 ) );
650 
651  if( m_Comment3Export->IsChecked() )
652  tb2.SetComment( 2, m_tb.GetComment( 2 ) );
653 
654  if( m_Comment4Export->IsChecked() )
655  tb2.SetComment( 3, m_tb.GetComment( 3 ) );
656 
657  if( m_Comment5Export->IsChecked() )
658  tb2.SetComment( 4, m_tb.GetComment( 4 ) );
659 
660  if( m_Comment6Export->IsChecked() )
661  tb2.SetComment( 5, m_tb.GetComment( 5 ) );
662 
663  if( m_Comment7Export->IsChecked() )
664  tb2.SetComment( 6, m_tb.GetComment( 6 ) );
665 
666  if( m_Comment8Export->IsChecked() )
667  tb2.SetComment( 7, m_tb.GetComment( 7 ) );
668 
669  if( m_Comment9Export->IsChecked() )
670  tb2.SetComment( 8, m_tb.GetComment( 8 ) );
671 
672  screen->SetTitleBlock( tb2 );
673  }
674 #endif
675 
676  return true;
677 }
678 
679 
680 void DIALOG_PAGES_SETTINGS::SetCurrentPageSizeSelection( const wxString& aPaperSize )
681 {
682  // search all the not translated label list containing our paper type
683  for( unsigned i = 0; i < m_pageFmt.GetCount(); ++i )
684  {
685  // parse each label looking for aPaperSize within it
686  wxStringTokenizer st( m_pageFmt[i] );
687 
688  while( st.HasMoreTokens() )
689  {
690  if( st.GetNextToken() == aPaperSize )
691  {
692  m_paperSizeComboBox->SetSelection( i );
693  return;
694  }
695  }
696  }
697 }
698 
699 
701 {
702  int lyWidth, lyHeight;
703 
704  wxSize clamped_layout_size( Clamp( MIN_PAGE_SIZE_MILS, m_layout_size.x, m_maxPageSizeMils.x ),
706 
707  double lyRatio = clamped_layout_size.x < clamped_layout_size.y ?
708  (double) clamped_layout_size.y / clamped_layout_size.x :
709  (double) clamped_layout_size.x / clamped_layout_size.y;
710 
711  if( clamped_layout_size.x < clamped_layout_size.y )
712  {
713  lyHeight = MAX_PAGE_EXAMPLE_SIZE;
714  lyWidth = KiROUND( (double) lyHeight / lyRatio );
715  }
716  else
717  {
718  lyWidth = MAX_PAGE_EXAMPLE_SIZE;
719  lyHeight = KiROUND( (double) lyWidth / lyRatio );
720  }
721 
722  if( m_page_bitmap )
723  {
724  m_PageLayoutExampleBitmap->SetBitmap( wxNullBitmap );
725  delete m_page_bitmap;
726  }
727 
728  m_page_bitmap = new wxBitmap( lyWidth + 1, lyHeight + 1 );
729 
730  if( m_page_bitmap->IsOk() )
731  {
732  double scaleW = (double) lyWidth / clamped_layout_size.x;
733  double scaleH = (double) lyHeight / clamped_layout_size.y;
734 
735  // Prepare DC.
736  wxSize example_size( lyWidth + 1, lyHeight + 1 );
737  wxMemoryDC memDC;
738  memDC.SelectObject( *m_page_bitmap );
739  memDC.SetClippingRegion( wxPoint( 0, 0 ), example_size );
740  memDC.Clear();
741  memDC.SetUserScale( scaleW, scaleH );
742 
743  // Get logical page size and margins.
744  PAGE_INFO pageDUMMY;
745 
746  // Get page type
747  int idx = m_paperSizeComboBox->GetSelection();
748 
749  if( idx < 0 )
750  idx = 0;
751 
752  wxString pageFmtName = m_pageFmt[idx].BeforeFirst( ' ' );
753  bool portrait = clamped_layout_size.x < clamped_layout_size.y;
754  pageDUMMY.SetType( pageFmtName, portrait );
755  if( m_customFmt )
756  {
757  pageDUMMY.SetWidthMils( clamped_layout_size.x );
758  pageDUMMY.SetHeightMils( clamped_layout_size.y );
759  }
760 
761  // Draw layout preview.
762  wxString emptyString;
763  GRResetPenAndBrush( &memDC );
764 
766  KIGFX::WS_RENDER_SETTINGS renderSettings;
767  renderSettings.SetDefaultPenWidth( 1 );
768  renderSettings.SetLayerColor( LAYER_WORKSHEET, COLOR4D( RED ) );
769  renderSettings.SetPrintDC( &memDC );
770 
771  GRFilledRect( NULL, &memDC, 0, 0, m_layout_size.x, m_layout_size.y, WHITE, WHITE );
772 
773  PrintPageLayout( &renderSettings, pageDUMMY, emptyString, emptyString, m_tb,
775 
776  memDC.SelectObject( wxNullBitmap );
779 
780  // Refresh the dialog.
781  Layout();
782  Refresh();
783  }
784 }
785 
786 
788 {
789  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
790  const wxString paperType = m_pageFmt[idx];
791 
792  // here we assume translators will keep original paper size spellings
793  if( paperType.Contains( PAGE_INFO::Custom ) )
794  {
796 
797  if( m_layout_size.x && m_layout_size.y )
798  {
799  if( m_layout_size.x < m_layout_size.y )
800  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
801  else
802  m_orientationComboBox->SetStringSelection( _( "Landscape" ) );
803  }
804  }
805  else
806  {
807  PAGE_INFO pageInfo; // SetType() later to lookup size
808 
809  static const wxChar* papers[] = {
810  // longest common string first, since sequential search below
816  PAGE_INFO::A,
817  PAGE_INFO::B,
818  PAGE_INFO::C,
819  PAGE_INFO::D,
820  PAGE_INFO::E,
824  };
825 
826  unsigned i;
827 
828  for( i=0; i < arrayDim( papers ); ++i )
829  {
830  if( paperType.Contains( papers[i] ) )
831  {
832  pageInfo.SetType( papers[i] );
833  break;
834  }
835  }
836 
837  wxASSERT( i != arrayDim(papers) ); // dialog UI match the above list?
838 
839  m_layout_size = pageInfo.GetSizeMils();
840 
841  // swap sizes to match orientation
842  bool isPortrait = (bool) m_orientationComboBox->GetSelection();
843 
844  if( ( isPortrait && m_layout_size.x >= m_layout_size.y ) ||
845  ( !isPortrait && m_layout_size.x < m_layout_size.y ) )
846  {
848  }
849  }
850 }
851 
852 
854 {
855  double customSizeX = (double) m_customSizeX.GetValue() / IU_PER_MILS;
856  double customSizeY = (double) m_customSizeY.GetValue() / IU_PER_MILS;
857 
858  // Prepare to painless double -> int conversion.
859  customSizeX = Clamp( double( INT_MIN ), customSizeX, double( INT_MAX ) );
860  customSizeY = Clamp( double( INT_MIN ), customSizeY, double( INT_MAX ) );
861  m_layout_size = wxSize( KiROUND( customSizeX ), KiROUND( customSizeY ) );
862 }
863 
864 
865 void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
866 {
867  wxFileName fn = GetWksFileName();
868  wxString name = GetWksFileName();
869  wxString path;
870 
871  if( fn.IsAbsolute() )
872  {
873  path = fn.GetPath();
874  name = fn.GetFullName();
875  }
876  else
877  {
878  path = m_projectPath;
879  }
880 
881  // Display a file picker dialog
882  wxFileDialog fileDialog( this, _( "Select Page Layout Description File" ),
884  wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
885 
886  if( fileDialog.ShowModal() != wxID_OK )
887  return;
888 
889  wxString fileName = fileDialog.GetPath();
890 
891  // Try to remove the path, if the path is the current working dir,
892  // or the dir of kicad.pro (template), and use a relative path
893  wxString shortFileName = WS_DATA_MODEL::MakeShortFileName( fileName, m_projectPath );
894 
895  // For Win/Linux/macOS compatibility, a relative path is a good idea
896  if( shortFileName != GetWksFileName() && shortFileName != fileName )
897  {
898  wxString msg = wxString::Format( _(
899  "The page layout description file name has changed.\n"
900  "Do you want to use the relative path:\n"
901  "\"%s\"\n"
902  "instead of\n"
903  "\"%s\"?" ), GetChars( shortFileName ), GetChars( fileName ) );
904 
905  if( !IsOK( this, msg ) )
906  shortFileName = fileName;
907  }
908 
909  SetWksFileName( shortFileName );
910 
911  if( m_pagelayout == NULL )
913 
914  m_pagelayout->SetPageLayout( fileName );
915 
918 }
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:69
wxString PageLayoutDescrFileWildcard()
SCH_SCREEN * GetNext()
int m_ScreenNumber
Definition: base_screen.h:85
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:886
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
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.
#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:122
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:59
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.
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:64
const wxSize & GetSizeMils() const
Definition: page_info.h:142
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: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:160
void OnWksFileSelection(wxCommandEvent &event) override
Class DIALOG_PAGES_SETTINGS_BASE.
Definition: color4d.h:48
static const wxChar A1[]
Definition: page_info.h:67
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: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: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:205
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: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: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
#define TO_UTF8(wxstring)
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:170
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:86
static const wxChar A2[]
Definition: page_info.h:66
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:183
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:182
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:233
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:546
int GetWidthMils() const
Definition: page_info.h:137
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99
static const wxChar A0[]
Definition: page_info.h:68