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-2017 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 
28 #include <fctsys.h>
29 #include <macros.h> // DIM()
30 #include <common.h>
31 #include <project.h>
32 #include <confirm.h>
33 #include <gr_basic.h>
34 #include <base_struct.h>
35 #include <class_drawpanel.h>
36 #include <title_block.h>
37 #include <draw_frame.h>
39 #include <base_screen.h>
41 
42 #include <wx/valgen.h>
43 #include <wx/tokenzr.h>
44 
45 #ifdef EESCHEMA
46 #include <sch_screen.h>
47 #include <general.h>
48 #endif
49 
50 #include <worksheet.h>
51 #include <dialog_page_settings.h>
52 
53 
54 // List of page formats.
55 // they are prefixed by "_HKI" (already in use for hotkeys) instead of "_",
56 // because we need both the translated and the not translated version.
57 // when displayed in dialog we should explicitely call wxGetTranslation()
58 // to show the translated version.
59 // See hotkeys_basic.h for more info
60 #define _HKI( x ) wxT( x )
61 static const wxString pageFmts[] =
62 {
63  _HKI("A4 210x297mm"),
64  _HKI("A3 297x420mm"),
65  _HKI("A2 420x594mm"),
66  _HKI("A1 594x841mm"),
67  _HKI("A0 841x1189mm"),
68  _HKI("A 8.5x11in"),
69  _HKI("B 11x17in"),
70  _HKI("C 17x22in"),
71  _HKI("D 22x34in"),
72  _HKI("E 34x44in"),
73  _HKI("USLetter 8.5x11in"), // USLetter without space is correct
74  _HKI("USLegal 8.5x14in"), // USLegal without space is correct
75  _HKI("USLedger 11x17in"), // USLedger without space is correct
76  _HKI("User (Custom)"), // size defined by user. The string must contain "Custom"
77  // to be reconized in code
78 };
79 
80 void EDA_DRAW_FRAME::Process_PageSettings( wxCommandEvent& event )
81 {
82  DIALOG_PAGES_SETTINGS dlg( this );
84 
85  if( dlg.ShowModal() == wxID_OK )
86  {
87  if( m_canvas )
88  m_canvas->Refresh();
89  }
90 }
91 
92 
95  m_initialized( false )
96 {
97  m_parent = parent;
100  m_page_bitmap = NULL;
102  m_customFmt = false;
103  m_localPrjConfigChanged = false;
104  m_pagelayout = NULL;
105 
106  m_PickDate->SetValue( wxDateTime::Now() );
107 
108  initDialog();
109 
110  GetSizer()->SetSizeHints( this );
111  Centre();
112 }
113 
114 
116 {
117  delete m_page_bitmap;
118  delete m_pagelayout;
119 }
120 
121 
123 {
124  wxString msg;
125  double customSizeX;
126  double customSizeY;
127 
128  // initalize page format choice box and page format list.
129  // The first shows translated strings, the second contains not translated strings
130  m_paperSizeComboBox->Clear();
131 
132  for( unsigned ii = 0; ii < DIM(pageFmts); ii++ )
133  {
134  m_pageFmt.Add( pageFmts[ii] );
135  m_paperSizeComboBox->Append( wxGetTranslation( pageFmts[ii] ) );
136  }
137 
138  // initialize the page layout descr filename
140 
141 
142 #ifdef EESCHEMA
143  // Init display value for schematic sub-sheet number
144  wxString format = m_TextSheetCount->GetLabel();
145  msg.Printf( format, m_screen->m_NumberOfScreens );
146  m_TextSheetCount->SetLabel( msg );
147 
148  format = m_TextSheetNumber->GetLabel();
149  msg.Printf( format, m_screen->m_ScreenNumber );
150  m_TextSheetNumber->SetLabel( msg );
151 #else
152  m_TextSheetCount->Show( false );
153  m_TextSheetNumber->Show( false );
154 #endif
155 
158  m_orientationComboBox->SetSelection( m_pageInfo.IsPortrait() );
159 
160  // only a click fires the "selection changed" event, so have to fabricate this check
161  wxCommandEvent dummy;
162  OnPaperSizeChoice( dummy );
163 
164  if( m_customFmt) // The custom value is defined by the page size
165  {
166  customSizeX = m_pageInfo.GetWidthMils();
167  customSizeY = m_pageInfo.GetHeightMils();
168  }
169  else // The custom value is set to a default value, or the last defined value
170  {
171  customSizeX = m_pageInfo.GetCustomWidthMils();
172  customSizeY = m_pageInfo.GetCustomHeightMils();
173  }
174 
175  switch( g_UserUnit )
176  {
177  case MILLIMETRES:
178  customSizeX *= 25.4e-3;
179  customSizeY *= 25.4e-3;
180 
181  msg.Printf( wxT( "%.2f" ), customSizeX );
182  m_TextUserSizeX->SetValue( msg );
183 
184  msg.Printf( wxT( "%.2f" ), customSizeY );
185  m_TextUserSizeY->SetValue( msg );
186  break;
187 
188  default:
189  case INCHES:
190  customSizeX /= 1000.0;
191  customSizeY /= 1000.0;
192 
193  msg.Printf( wxT( "%.3f" ), customSizeX );
194  m_TextUserSizeX->SetValue( msg );
195 
196  msg.Printf( wxT( "%.3f" ), customSizeY );
197  m_TextUserSizeY->SetValue( msg );
198  break;
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.GetComment1() );
206  m_TextComment2->SetValue( m_tb.GetComment2() );
207  m_TextComment3->SetValue( m_tb.GetComment3() );
208  m_TextComment4->SetValue( m_tb.GetComment4() );
209 
210 #ifndef EESCHEMA
211  // these options have meaning only for Eeschema.
212  // disable them for other apps
213  m_RevisionExport->Show( false );
214  m_DateExport->Show( false );
215  m_TitleExport->Show( false );
216  m_CompanyExport->Show( false );
217  m_Comment1Export->Show( false );
218  m_Comment2Export->Show( false );
219  m_Comment3Export->Show( false );
220  m_Comment4Export->Show( false );
221 #endif
222 
225 
226  // Make the OK button the default.
227  m_sdbSizerOK->SetDefault();
228  m_initialized = true;
229 }
230 
231 
232 void DIALOG_PAGES_SETTINGS::OnOkClick( wxCommandEvent& event )
233 {
234  if( SavePageSettings() )
235  {
236  m_screen->SetModify();
237  m_parent->GetCanvas()->Refresh();
238 
239  if( LocalPrjConfigChanged() )
240  m_parent->SaveProjectSettings( true );
241  }
242 
243  event.Skip();
244 }
245 
246 
247 void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
248 {
249  int idx = m_paperSizeComboBox->GetSelection();
250 
251  if( idx < 0 )
252  idx = 0;
253 
254  const wxString paperType = m_pageFmt[idx];
255 
256  if( paperType.Contains( PAGE_INFO::Custom ) )
257  {
258  m_orientationComboBox->Enable( false );
259  m_TextUserSizeX->Enable( true );
260  m_TextUserSizeY->Enable( true );
261  m_customFmt = true;
262  }
263  else
264  {
265  m_orientationComboBox->Enable( true );
266 
267 #if 0
268  // ForcePortrait() does not exist, but could be useful.
269  // so I leave these lines, which could be seen as a todo feature
270  if( paperType.ForcePortrait() )
271  {
272  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
273  m_orientationComboBox->Enable( false );
274  }
275 #endif
276  m_TextUserSizeX->Enable( false );
277  m_TextUserSizeY->Enable( false );
278  m_customFmt = false;
279  }
280 
283 }
284 
285 
287 {
288  if( m_initialized && m_TextUserSizeX->IsModified() )
289  {
292  }
293 }
294 
295 
297 {
298  if( m_initialized && m_TextUserSizeY->IsModified() )
299  {
302  }
303 }
304 
305 
307 {
308  if( m_initialized )
309  {
312  }
313 }
314 
315 
316 void DIALOG_PAGES_SETTINGS::OnRevisionTextUpdated( wxCommandEvent& event )
317 {
318  if( m_initialized && m_TextRevision->IsModified() )
319  {
321  m_tb.SetRevision( m_TextRevision->GetValue() );
323  }
324 }
325 
326 
327 void DIALOG_PAGES_SETTINGS::OnDateTextUpdated( wxCommandEvent& event )
328 {
329  if( m_initialized && m_TextDate->IsModified() )
330  {
332  m_tb.SetDate( m_TextDate->GetValue() );
334  }
335 }
336 
337 
338 void DIALOG_PAGES_SETTINGS::OnTitleTextUpdated( wxCommandEvent& event )
339 {
340  if( m_initialized && m_TextTitle->IsModified() )
341  {
343  m_tb.SetTitle( m_TextTitle->GetValue() );
345  }
346 }
347 
348 
349 void DIALOG_PAGES_SETTINGS::OnCompanyTextUpdated( wxCommandEvent& event )
350 {
351  if( m_initialized && m_TextCompany->IsModified() )
352  {
354  m_tb.SetCompany( m_TextCompany->GetValue() );
356  }
357 }
358 
359 
360 void DIALOG_PAGES_SETTINGS::OnComment1TextUpdated( wxCommandEvent& event )
361 {
362  if( m_initialized && m_TextComment1->IsModified() )
363  {
365  m_tb.SetComment1( m_TextComment1->GetValue() );
367  }
368 }
369 
370 
371 void DIALOG_PAGES_SETTINGS::OnComment2TextUpdated( wxCommandEvent& event )
372 {
373  if( m_initialized && m_TextComment2->IsModified() )
374  {
376  m_tb.SetComment2( m_TextComment2->GetValue() );
378  }
379 }
380 
381 
382 void DIALOG_PAGES_SETTINGS::OnComment3TextUpdated( wxCommandEvent& event )
383 {
384  if( m_initialized && m_TextComment3->IsModified() )
385  {
387  m_tb.SetComment3( m_TextComment3->GetValue() );
389  }
390 }
391 
392 
393 void DIALOG_PAGES_SETTINGS::OnComment4TextUpdated( wxCommandEvent& event )
394 {
395  if( m_initialized && m_TextComment4->IsModified() )
396  {
398  m_tb.SetComment4( m_TextComment4->GetValue() );
400  }
401 }
402 
403 
404 void DIALOG_PAGES_SETTINGS::OnDateApplyClick( wxCommandEvent& event )
405 {
406  wxDateTime datetime = m_PickDate->GetValue();
407  wxString date =
408  // We can choose different formats. Only one must be uncommented
409  //
410  // datetime.Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
411  // datetime.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
412  // datetime.Format( wxT("%Y-%b-%d") );
413  datetime.FormatISODate();
414 
415  m_TextDate->SetValue( date );
416 }
417 
418 
420 {
421  bool retSuccess = false;
422 
423  wxString fileName = GetWksFileName();
424 
426  {
427  wxString fullFileName =
429 
430  if( !fullFileName.IsEmpty() )
431  {
432 
433  if( !wxFileExists( fullFileName ) )
434  {
435  wxString msg;
436  msg.Printf( _("Page layout description file \"%s\" not found. Abort"),
437  GetChars( fullFileName ) );
438  wxMessageBox( msg );
439  return false;
440  }
441  }
442 
445  pglayout.SetPageLayout( fullFileName );
447  }
448 
449  int idx = m_paperSizeComboBox->GetSelection();
450 
451  if( idx < 0 )
452  idx = 0;
453 
454  const wxString paperType = m_pageFmt[idx];
455 
456  if( paperType.Contains( PAGE_INFO::Custom ) )
457  {
459 
460  retSuccess = m_pageInfo.SetType( PAGE_INFO::Custom );
461 
462  if( retSuccess )
463  {
466  {
467  wxString msg = wxString::Format( _( "Selected custom paper size\nis out of the permissible \
468 limits\n%.1f - %.1f %s!\nSelect another custom paper size?" ),
469  g_UserUnit == INCHES ? MIN_PAGE_SIZE / 1000. : MIN_PAGE_SIZE * 25.4 / 1000,
470  g_UserUnit == INCHES ? MAX_PAGE_SIZE / 1000. : MAX_PAGE_SIZE * 25.4 / 1000,
471  g_UserUnit == INCHES ? _( "inches" ) : _( "mm" ) );
472 
473  if( wxMessageBox( msg, _( "Warning!" ), wxYES_NO | wxICON_EXCLAMATION, this ) == wxYES )
474  {
475  return false;
476  }
477 
480  }
481 
484 
487  }
488  }
489  else
490  {
491  // search for longest common string first, e.g. A4 before A
492  if( paperType.Contains( PAGE_INFO::USLetter ) )
493  retSuccess = m_pageInfo.SetType( PAGE_INFO::USLetter );
494  else if( paperType.Contains( PAGE_INFO::USLegal ) )
495  retSuccess = m_pageInfo.SetType( PAGE_INFO::USLegal );
496  else if( paperType.Contains( PAGE_INFO::USLedger ) )
497  retSuccess = m_pageInfo.SetType( PAGE_INFO::USLedger );
498  else if( paperType.Contains( PAGE_INFO::GERBER ) )
499  retSuccess = m_pageInfo.SetType( PAGE_INFO::GERBER );
500  else if( paperType.Contains( PAGE_INFO::A4 ) )
501  retSuccess = m_pageInfo.SetType( PAGE_INFO::A4 );
502  else if( paperType.Contains( PAGE_INFO::A3 ) )
503  retSuccess = m_pageInfo.SetType( PAGE_INFO::A3 );
504  else if( paperType.Contains( PAGE_INFO::A2 ) )
505  retSuccess = m_pageInfo.SetType( PAGE_INFO::A2 );
506  else if( paperType.Contains( PAGE_INFO::A1 ) )
507  retSuccess = m_pageInfo.SetType( PAGE_INFO::A1 );
508  else if( paperType.Contains( PAGE_INFO::A0 ) )
509  retSuccess = m_pageInfo.SetType( PAGE_INFO::A0 );
510  else if( paperType.Contains( PAGE_INFO::A ) )
511  retSuccess = m_pageInfo.SetType( PAGE_INFO::A );
512  else if( paperType.Contains( PAGE_INFO::B ) )
513  retSuccess = m_pageInfo.SetType( PAGE_INFO::B );
514  else if( paperType.Contains( PAGE_INFO::C ) )
515  retSuccess = m_pageInfo.SetType( PAGE_INFO::C );
516  else if( paperType.Contains( PAGE_INFO::D ) )
517  retSuccess = m_pageInfo.SetType( PAGE_INFO::D );
518  else if( paperType.Contains( PAGE_INFO::E ) )
519  retSuccess = m_pageInfo.SetType( PAGE_INFO::E );
520 
521  if( retSuccess )
522  {
523  int choice = m_orientationComboBox->GetSelection();
524  m_pageInfo.SetPortrait( choice != 0 );
525  }
526  }
527 
528  if( !retSuccess )
529  {
530  wxASSERT_MSG( false, wxT( "the translation for paper size must preserve original spellings" ) );
532  }
533 
535 
536  m_tb.SetRevision( m_TextRevision->GetValue() );
537  m_tb.SetDate( m_TextDate->GetValue() );
538  m_tb.SetCompany( m_TextCompany->GetValue() );
539  m_tb.SetTitle( m_TextTitle->GetValue() );
540  m_tb.SetComment1( m_TextComment1->GetValue() );
541  m_tb.SetComment2( m_TextComment2->GetValue() );
542  m_tb.SetComment3( m_TextComment3->GetValue() );
543  m_tb.SetComment4( m_TextComment4->GetValue() );
544 
546 
547 
548 #ifdef EESCHEMA
549  // Exports settings to other sheets if requested:
550  SCH_SCREEN* screen;
551 
552  // Build the screen list
553  SCH_SCREENS ScreenList;
554 
555  // Update title blocks for all screens
556  for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
557  {
558  if( screen == m_screen )
559  continue;
560 
561  TITLE_BLOCK tb2 = screen->GetTitleBlock();
562 
563  if( m_RevisionExport->IsChecked() )
564  tb2.SetRevision( m_tb.GetRevision() );
565 
566  if( m_DateExport->IsChecked() )
567  tb2.SetDate( m_tb.GetDate() );
568 
569  if( m_TitleExport->IsChecked() )
570  tb2.SetTitle( m_tb.GetTitle() );
571 
572  if( m_CompanyExport->IsChecked() )
573  tb2.SetCompany( m_tb.GetCompany() );
574 
575  if( m_Comment1Export->IsChecked() )
576  tb2.SetComment1( m_tb.GetComment1() );
577 
578  if( m_Comment2Export->IsChecked() )
579  tb2.SetComment2( m_tb.GetComment2() );
580 
581  if( m_Comment3Export->IsChecked() )
582  tb2.SetComment3( m_tb.GetComment3() );
583 
584  if( m_Comment4Export->IsChecked() )
585  tb2.SetComment4( m_tb.GetComment4() );
586 
587  screen->SetTitleBlock( tb2 );
588  }
589 
590 #endif
591 
592  return true;
593 }
594 
595 
596 void DIALOG_PAGES_SETTINGS::SetCurrentPageSizeSelection( const wxString& aPaperSize )
597 {
598  // search all the not translated label list containing our paper type
599  for( unsigned i = 0; i < m_pageFmt.GetCount(); ++i )
600  {
601  // parse each label looking for aPaperSize within it
602  wxStringTokenizer st( m_pageFmt[i] );
603 
604  while( st.HasMoreTokens() )
605  {
606  if( st.GetNextToken() == aPaperSize )
607  {
608  m_paperSizeComboBox->SetSelection( i );
609  return;
610  }
611  }
612  }
613 }
614 
615 
617 {
618  int lyWidth, lyHeight;
619 
620  wxSize clamped_layout_size( Clamp( MIN_PAGE_SIZE, m_layout_size.x, MAX_PAGE_SIZE ),
622 
623  double lyRatio = clamped_layout_size.x < clamped_layout_size.y ?
624  (double) clamped_layout_size.y / clamped_layout_size.x :
625  (double) clamped_layout_size.x / clamped_layout_size.y;
626 
627  if( clamped_layout_size.x < clamped_layout_size.y )
628  {
629  lyHeight = MAX_PAGE_EXAMPLE_SIZE;
630  lyWidth = KiROUND( (double) lyHeight / lyRatio );
631  }
632  else
633  {
634  lyWidth = MAX_PAGE_EXAMPLE_SIZE;
635  lyHeight = KiROUND( (double) lyWidth / lyRatio );
636  }
637 
638  if( m_page_bitmap )
639  {
640  m_PageLayoutExampleBitmap->SetBitmap( wxNullBitmap );
641  delete m_page_bitmap;
642  }
643 
644  m_page_bitmap = new wxBitmap( lyWidth + 1, lyHeight + 1 );
645 
646  if( m_page_bitmap->IsOk() )
647  {
648  // Calculate layout preview scale.
649  int appScale = m_screen->MilsToIuScalar();
650 
651  double scaleW = (double) lyWidth / clamped_layout_size.x / appScale;
652  double scaleH = (double) lyHeight / clamped_layout_size.y / appScale;
653 
654  // Prepare DC.
655  wxSize example_size( lyWidth + 1, lyHeight + 1 );
656  wxMemoryDC memDC;
657  memDC.SelectObject( *m_page_bitmap );
658  memDC.SetClippingRegion( wxPoint( 0, 0 ), example_size );
659  memDC.Clear();
660  memDC.SetUserScale( scaleW, scaleH );
661 
662  // Get logical page size and margins.
663  PAGE_INFO pageDUMMY;
664 
665  // Get page type
666  int idx = m_paperSizeComboBox->GetSelection();
667 
668  if( idx < 0 )
669  idx = 0;
670 
671  wxString pageFmtName = m_pageFmt[idx].BeforeFirst( ' ' );
672  bool portrait = clamped_layout_size.x < clamped_layout_size.y;
673  pageDUMMY.SetType( pageFmtName, portrait );
674  if( m_customFmt )
675  {
676  pageDUMMY.SetWidthMils( clamped_layout_size.x );
677  pageDUMMY.SetHeightMils( clamped_layout_size.y );
678  }
679 
680  // Draw layout preview.
681  wxString emptyString;
682  GRResetPenAndBrush( &memDC );
683 
685  DrawPageLayout( &memDC, NULL, pageDUMMY,
686  emptyString, emptyString,
688  m_screen->m_ScreenNumber, 1, appScale, DARKGRAY, RED );
689 
690  memDC.SelectObject( wxNullBitmap );
693 
694  // Refresh the dialog.
695  Layout();
696  Refresh();
697  }
698 }
699 
700 
702 {
703  int idx = m_paperSizeComboBox->GetSelection();
704 
705  if( idx < 0 )
706  idx = 0;
707 
708  const wxString paperType = m_pageFmt[idx];
709 
710  // here we assume translators will keep original paper size spellings
711  if( paperType.Contains( PAGE_INFO::Custom ) )
712  {
714 
715  if( m_layout_size.x && m_layout_size.y )
716  {
717  if( m_layout_size.x < m_layout_size.y )
718  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
719  else
720  m_orientationComboBox->SetStringSelection( _( "Landscape" ) );
721  }
722  }
723  else
724  {
725  PAGE_INFO pageInfo; // SetType() later to lookup size
726 
727  static const wxChar* papers[] = {
728  // longest common string first, since sequential search below
734  PAGE_INFO::A,
735  PAGE_INFO::B,
736  PAGE_INFO::C,
737  PAGE_INFO::D,
738  PAGE_INFO::E,
742  };
743 
744  unsigned i;
745 
746  for( i=0; i < DIM( papers ); ++i )
747  {
748  if( paperType.Contains( papers[i] ) )
749  {
750  pageInfo.SetType( papers[i] );
751  break;
752  }
753  }
754 
755  wxASSERT( i != DIM(papers) ); // dialog UI match the above list?
756 
757  m_layout_size = pageInfo.GetSizeMils();
758 
759  // swap sizes to match orientation
760  bool isPortrait = (bool) m_orientationComboBox->GetSelection();
761 
762  if( ( isPortrait && m_layout_size.x >= m_layout_size.y ) ||
763  ( !isPortrait && m_layout_size.x < m_layout_size.y ) )
764  {
766  }
767  }
768 }
769 
770 
772 {
773  double customSizeX;
774  double customSizeY;
775  wxString msg;
776 
777  msg = m_TextUserSizeX->GetValue();
778  msg.ToDouble( &customSizeX );
779 
780  msg = m_TextUserSizeY->GetValue();
781  msg.ToDouble( &customSizeY );
782 
783  switch( g_UserUnit )
784  {
785  case MILLIMETRES:
786  customSizeX *= 1000. / 25.4;
787  customSizeY *= 1000. / 25.4;
788  break;
789 
790  default:
791  case INCHES:
792  customSizeX *= 1000.;
793  customSizeY *= 1000.;
794  }
795 
796  // Prepare to painless double -> int conversion.
797  customSizeX = Clamp( double( INT_MIN ), customSizeX, double( INT_MAX ) );
798  customSizeY = Clamp( double( INT_MIN ), customSizeY, double( INT_MAX ) );
799  m_layout_size = wxSize( KiROUND( customSizeX ), KiROUND( customSizeY ) );
800 }
801 
802 // Called on .kicad_wks file description selection change
803 void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
804 {
805  // Display a file picker dialog
806  wxFileDialog fileDialog( this, _( "Select Page Layout Description File" ),
809  wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
810 
811  if( fileDialog.ShowModal() != wxID_OK )
812  return;
813 
814  wxString fileName = fileDialog.GetPath();
815 
816  // Try to remove the path, if the path is the current working dir,
817  // or the dir of kicad.pro (template), and use a relative path
818  wxString shortFileName = WORKSHEET_LAYOUT::MakeShortFileName( fileName, m_projectPath );
819 
820  // For Win/Linux/macOS compatibility, a relative path is a good idea
821  if( shortFileName != GetWksFileName() && shortFileName != fileName )
822  {
823  wxString msg = wxString::Format( _(
824  "The page layout descr filename has changed.\n"
825  "Do you want to use the relative path:\n"
826  "\"%s\"\n"
827  "instead of\n"
828  "\"%s\"" ), GetChars( shortFileName ), GetChars( fileName ) );
829 
830  if( !IsOK( this, msg ) )
831  shortFileName = fileName;
832  }
833 
834  SetWksFileName( shortFileName );
835 
836  if( m_pagelayout == NULL )
838 
839  m_pagelayout->SetPageLayout( fileName );
840 
843 }
void SetComment1(const wxString &aComment)
Definition: title_block.h:116
void OnDateApplyClick(wxCommandEvent &event) override
#define DIM(x)
of elements in an array
Definition: macros.h:98
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)=0
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:218
static const wxChar A[]
Definition: page_info.h:64
wxString PageLayoutDescrFileWildcard()
SCH_SCREEN * GetNext()
int m_ScreenNumber
Definition: base_screen.h:216
#define MAX_PAGE_EXAMPLE_SIZE
const T & Clamp(const T &lower, const T &value, const T &upper)
Function Clamp limits value within the range lower <= value <= upper.
Definition: macros.h:127
virtual const TITLE_BLOCK & GetTitleBlock() const =0
static int GetCustomHeightMils()
Function GetCustomHeightMils.
Definition: page_info.h:171
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
void OnPageOrientationChoice(wxCommandEvent &event) override
const wxString & GetCompany() const
Definition: title_block.h:98
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:339
This file is part of the common library.
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:342
virtual void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)=0
void SetRevision(const wxString &aRevision)
Definition: title_block.h:83
static const wxChar E[]
Definition: page_info.h:68
void OnComment3TextUpdated(wxCommandEvent &event) override
static const wxChar GERBER[]
Definition: page_info.h:69
TITLE_BLOCK m_tb
true if the page selection is custom
static const wxChar A3[]
Definition: page_info.h:60
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
const wxString & GetComment4() const
Definition: title_block.h:123
void SetDate(const wxString &aDate)
Function SetDate sets the date field, and defaults to the current time and date.
Definition: title_block.h:73
const wxString & GetDate() const
Definition: title_block.h:78
void OnUserPageSizeXTextUpdated(wxCommandEvent &event) override
static const wxChar Custom[]
"User" defined page type
Definition: page_info.h:73
static const wxChar D[]
Definition: page_info.h:67
const wxString GetWksFileName()
bool m_initialized
list of page sizes (not translated)
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:54
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:39
wxSize m_layout_size
Temporary bitmap for the page layout example.
void SetComment4(const wxString &aComment)
Definition: title_block.h:119
static WORKSHEET_LAYOUT & GetTheInstance()
static function: returns the instance of WORKSHEET_LAYOUT used in the application ...
This file contains miscellaneous commonly used macros and functions.
const wxSize & GetSizeMils() const
Definition: page_info.h:137
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:180
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
virtual const PAGE_INFO & GetPageSettings() const =0
const wxString & GetTitle() const
Definition: title_block.h:64
void OnComment1TextUpdated(wxCommandEvent &event) override
bool IsPortrait() const
Definition: page_info.h:116
virtual BASE_SCREEN * GetScreen() const
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:352
static const wxChar USLegal[]
Definition: page_info.h:71
static const wxChar B[]
Definition: page_info.h:65
static const wxChar C[]
Definition: page_info.h:66
void Refresh()
Update the board display after modifying it bu a python script (note: it is automatically called by a...
const wxString & GetRevision() const
Definition: title_block.h:88
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:49
#define MAX_PAGE_SIZE
Definition: page_info.h:223
Definition: common.h:145
void SetCompany(const wxString &aCompany)
Definition: title_block.h:93
The common library.
static const wxChar A4[]
Definition: page_info.h:59
Definition: colors.h:60
const wxString & GetComment3() const
Definition: title_block.h:122
virtual int MilsToIuScalar()
Function MilsToIuScalar returns the scalar required to convert mils to internal units.
Definition: base_screen.h:245
void OnDateTextUpdated(wxCommandEvent &event) override
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: sch_screen.h:127
void SetCurrentPageSizeSelection(const wxString &aPaperSize)
void SetTitle(const wxString &aTitle)
Definition: title_block.h:59
int GetWidthMils() const
Definition: page_info.h:132
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:253
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:125
static const wxChar USLedger[]
Definition: page_info.h:72
const wxString & GetComment2() const
Definition: title_block.h:121
WORKSHEET_LAYOUT handles the graphic items list to draw/plot the title block and other items (page re...
void OnWksFileSelection(wxCommandEvent &event) override
Class DIALOG_PAGES_SETTINGS_BASE.
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
virtual void SaveProjectSettings(bool aAskForSave)
Function SaveProjectSettings saves changes to the project settings to the project (...
static const wxChar A1[]
Definition: page_info.h:62
Definitions for the Eeschema program SCH_SCREEN class.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
static const wxChar USLetter[]
Definition: page_info.h:70
void OnOkClick(wxCommandEvent &event) override
void SetComment2(const wxString &aComment)
Definition: title_block.h:117
const wxString & GetComment1() const
Definition: title_block.h:120
void DrawPageLayout(wxDC *aDC, EDA_RECT *aClipBox, const PAGE_INFO &aPageInfo, const wxString &aFullSheetName, const wxString &aFileName, TITLE_BLOCK &aTitleBlock, int aSheetCount, int aSheetNumber, int aPenWidth, double aScalar, COLOR4D aColor, COLOR4D aAltColor, const wxString &aSheetLayer)
Function DrawPageLayout is a core function to draw the page layout with the frame and the basic inscr...
Definition: worksheet.cpp:48
PAGE_INFO m_pageInfo
Logical page layout size.
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:92
void OnUserPageSizeYTextUpdated(wxCommandEvent &event) override
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 when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
static const wxString MakeShortFileName(const wxString &aFullFileName, const wxString &aProjectPath)
WORKSHEET_LAYOUT * m_pagelayout
Temporary title block (basic inscriptions).
DIALOG_PAGES_SETTINGS(EDA_DRAW_FRAME *parent)
static const wxString pageFmts[]
static const wxString MakeFullFileName(const wxString &aShortFileName, const wxString &aProjectPath)
Static function.
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:239
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:100
The common library.
static int GetCustomWidthMils()
Function GetCustomWidthMils.
Definition: page_info.h:165
void Process_PageSettings(wxCommandEvent &event)
bool m_customFmt
Temporary page info.
int m_NumberOfScreens
Definition: base_screen.h:217
static const wxChar A2[]
Definition: page_info.h:61
classes and function to generate graphics to plt or draw titles blocks and frame references ...
SCH_SCREEN * GetFirst()
void OnComment2TextUpdated(wxCommandEvent &event) override
void OnPaperSizeChoice(wxCommandEvent &event) override
void SetComment3(const wxString &aComment)
Definition: title_block.h:118
const wxString & GetType() const
Definition: page_info.h:92
Basic classes for most KiCad items.
void OnTitleTextUpdated(wxCommandEvent &event) override
void OnCompanyTextUpdated(wxCommandEvent &event) override
void SetModify()
Definition: base_screen.h:324
void OnRevisionTextUpdated(wxCommandEvent &event) override
#define MIN_PAGE_SIZE
Min and max page sizes for clamping.
Definition: page_info.h:222
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)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:289
static void SetAltInstance(WORKSHEET_LAYOUT *aLayout=NULL)
static function: Set an alternate instance of WORKSHEET_LAYOUT mainly used in page setting dialog ...
int GetHeightMils() const
Definition: page_info.h:135
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:503
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...
static const wxChar A0[]
Definition: page_info.h:63