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 
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 explicitly 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 recognized 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  // initialize 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 #ifdef EESCHEMA
142  // Init display value for schematic sub-sheet number
143  wxString format = m_TextSheetCount->GetLabel();
144  msg.Printf( format, m_screen->m_NumberOfScreens );
145  m_TextSheetCount->SetLabel( msg );
146 
147  format = m_TextSheetNumber->GetLabel();
148  msg.Printf( format, m_screen->m_ScreenNumber );
149  m_TextSheetNumber->SetLabel( msg );
150 #else
151  m_TextSheetCount->Show( false );
152  m_TextSheetNumber->Show( false );
153 #endif
154 
157  m_orientationComboBox->SetSelection( m_pageInfo.IsPortrait() );
158 
159  // only a click fires the "selection changed" event, so have to fabricate this check
160  wxCommandEvent dummy;
161  OnPaperSizeChoice( dummy );
162 
163  if( m_customFmt) // The custom value is defined by the page size
164  {
165  customSizeX = m_pageInfo.GetWidthMils();
166  customSizeY = m_pageInfo.GetHeightMils();
167  }
168  else // The custom value is set to a default value, or the last defined value
169  {
170  customSizeX = m_pageInfo.GetCustomWidthMils();
171  customSizeY = m_pageInfo.GetCustomHeightMils();
172  }
173 
174  switch( g_UserUnit )
175  {
176  case MILLIMETRES:
177  customSizeX *= 25.4e-3;
178  customSizeY *= 25.4e-3;
179 
180  msg.Printf( wxT( "%.2f" ), customSizeX );
181  m_TextUserSizeX->SetValue( msg );
182 
183  msg.Printf( wxT( "%.2f" ), customSizeY );
184  m_TextUserSizeY->SetValue( msg );
185  break;
186 
187  default:
188  case INCHES:
189  customSizeX /= 1000.0;
190  customSizeY /= 1000.0;
191 
192  msg.Printf( wxT( "%.3f" ), customSizeX );
193  m_TextUserSizeX->SetValue( msg );
194 
195  msg.Printf( wxT( "%.3f" ), customSizeY );
196  m_TextUserSizeY->SetValue( msg );
197  break;
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.GetComment1() );
205  m_TextComment2->SetValue( m_tb.GetComment2() );
206  m_TextComment3->SetValue( m_tb.GetComment3() );
207  m_TextComment4->SetValue( m_tb.GetComment4() );
208 
209 #ifndef EESCHEMA
210  // these options have meaning only for Eeschema.
211  // disable them for other apps
212  m_RevisionExport->Show( false );
213  m_DateExport->Show( false );
214  m_TitleExport->Show( false );
215  m_CompanyExport->Show( false );
216  m_Comment1Export->Show( false );
217  m_Comment2Export->Show( false );
218  m_Comment3Export->Show( false );
219  m_Comment4Export->Show( false );
220 #endif
221 
224 
225  // Make the OK button the default.
226  m_sdbSizerOK->SetDefault();
227  m_initialized = true;
228 }
229 
230 
231 void DIALOG_PAGES_SETTINGS::OnOkClick( wxCommandEvent& event )
232 {
233  if( SavePageSettings() )
234  {
235  m_screen->SetModify();
236  m_parent->GetCanvas()->Refresh();
237 
238  if( LocalPrjConfigChanged() )
239  m_parent->SaveProjectSettings( true );
240  }
241 
242  event.Skip();
243 }
244 
245 
246 void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
247 {
248  int idx = m_paperSizeComboBox->GetSelection();
249 
250  if( idx < 0 )
251  idx = 0;
252 
253  const wxString paperType = m_pageFmt[idx];
254 
255  if( paperType.Contains( PAGE_INFO::Custom ) )
256  {
257  m_orientationComboBox->Enable( false );
258  m_TextUserSizeX->Enable( true );
259  m_TextUserSizeY->Enable( true );
260  m_customFmt = true;
261  }
262  else
263  {
264  m_orientationComboBox->Enable( true );
265 
266 #if 0
267  // ForcePortrait() does not exist, but could be useful.
268  // so I leave these lines, which could be seen as a todo feature
269  if( paperType.ForcePortrait() )
270  {
271  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
272  m_orientationComboBox->Enable( false );
273  }
274 #endif
275  m_TextUserSizeX->Enable( false );
276  m_TextUserSizeY->Enable( false );
277  m_customFmt = false;
278  }
279 
282 }
283 
284 
286 {
287  if( m_initialized && m_TextUserSizeX->IsModified() )
288  {
291  }
292 }
293 
294 
296 {
297  if( m_initialized && m_TextUserSizeY->IsModified() )
298  {
301  }
302 }
303 
304 
306 {
307  if( m_initialized )
308  {
311  }
312 }
313 
314 
315 void DIALOG_PAGES_SETTINGS::OnRevisionTextUpdated( wxCommandEvent& event )
316 {
317  if( m_initialized && m_TextRevision->IsModified() )
318  {
320  m_tb.SetRevision( m_TextRevision->GetValue() );
322  }
323 }
324 
325 
326 void DIALOG_PAGES_SETTINGS::OnDateTextUpdated( wxCommandEvent& event )
327 {
328  if( m_initialized && m_TextDate->IsModified() )
329  {
331  m_tb.SetDate( m_TextDate->GetValue() );
333  }
334 }
335 
336 
337 void DIALOG_PAGES_SETTINGS::OnTitleTextUpdated( wxCommandEvent& event )
338 {
339  if( m_initialized && m_TextTitle->IsModified() )
340  {
342  m_tb.SetTitle( m_TextTitle->GetValue() );
344  }
345 }
346 
347 
348 void DIALOG_PAGES_SETTINGS::OnCompanyTextUpdated( wxCommandEvent& event )
349 {
350  if( m_initialized && m_TextCompany->IsModified() )
351  {
353  m_tb.SetCompany( m_TextCompany->GetValue() );
355  }
356 }
357 
358 
359 void DIALOG_PAGES_SETTINGS::OnComment1TextUpdated( wxCommandEvent& event )
360 {
361  if( m_initialized && m_TextComment1->IsModified() )
362  {
364  m_tb.SetComment1( m_TextComment1->GetValue() );
366  }
367 }
368 
369 
370 void DIALOG_PAGES_SETTINGS::OnComment2TextUpdated( wxCommandEvent& event )
371 {
372  if( m_initialized && m_TextComment2->IsModified() )
373  {
375  m_tb.SetComment2( m_TextComment2->GetValue() );
377  }
378 }
379 
380 
381 void DIALOG_PAGES_SETTINGS::OnComment3TextUpdated( wxCommandEvent& event )
382 {
383  if( m_initialized && m_TextComment3->IsModified() )
384  {
386  m_tb.SetComment3( m_TextComment3->GetValue() );
388  }
389 }
390 
391 
392 void DIALOG_PAGES_SETTINGS::OnComment4TextUpdated( wxCommandEvent& event )
393 {
394  if( m_initialized && m_TextComment4->IsModified() )
395  {
397  m_tb.SetComment4( m_TextComment4->GetValue() );
399  }
400 }
401 
402 
403 void DIALOG_PAGES_SETTINGS::OnDateApplyClick( wxCommandEvent& event )
404 {
405  wxDateTime datetime = m_PickDate->GetValue();
406  wxString date =
407  // We can choose different formats. Only one must be uncommented
408  //
409  // datetime.Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
410  // datetime.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
411  // datetime.Format( wxT("%Y-%b-%d") );
412  datetime.FormatISODate();
413 
414  m_TextDate->SetValue( date );
415 }
416 
417 
419 {
420  bool retSuccess = false;
421 
422  wxString fileName = GetWksFileName();
423 
425  {
426  wxString fullFileName =
428 
429  if( !fullFileName.IsEmpty() )
430  {
431 
432  if( !wxFileExists( fullFileName ) )
433  {
434  wxString msg;
435  msg.Printf( _("Page layout description file \"%s\" not found. Abort"),
436  GetChars( fullFileName ) );
437  wxMessageBox( msg );
438  return false;
439  }
440  }
441 
444  pglayout.SetPageLayout( fullFileName );
446  }
447 
448  int idx = m_paperSizeComboBox->GetSelection();
449 
450  if( idx < 0 )
451  idx = 0;
452 
453  const wxString paperType = m_pageFmt[idx];
454 
455  if( paperType.Contains( PAGE_INFO::Custom ) )
456  {
458 
459  retSuccess = m_pageInfo.SetType( PAGE_INFO::Custom );
460 
461  if( retSuccess )
462  {
465  {
466  wxString msg = wxString::Format( _( "Selected custom paper size\n"
467  "is out of the permissible limits\n"
468  "%.1f - %.1f %s!\nSelect another custom "
469  "paper size?" ),
470  g_UserUnit == INCHES ? MIN_PAGE_SIZE / 1000. : MIN_PAGE_SIZE * 25.4 / 1000,
471  g_UserUnit == INCHES ? MAX_PAGE_SIZE / 1000. : MAX_PAGE_SIZE * 25.4 / 1000,
472  g_UserUnit == INCHES ? _( "inches" ) : _( "mm" ) );
473 
474  if( wxMessageBox( msg, _( "Warning!" ),
475  wxYES_NO | wxICON_EXCLAMATION, this ) == wxYES )
476  {
477  return false;
478  }
479 
482  }
483 
486 
489  }
490  }
491  else
492  {
493  // search for longest common string first, e.g. A4 before A
494  if( paperType.Contains( PAGE_INFO::USLetter ) )
495  retSuccess = m_pageInfo.SetType( PAGE_INFO::USLetter );
496  else if( paperType.Contains( PAGE_INFO::USLegal ) )
497  retSuccess = m_pageInfo.SetType( PAGE_INFO::USLegal );
498  else if( paperType.Contains( PAGE_INFO::USLedger ) )
499  retSuccess = m_pageInfo.SetType( PAGE_INFO::USLedger );
500  else if( paperType.Contains( PAGE_INFO::GERBER ) )
501  retSuccess = m_pageInfo.SetType( PAGE_INFO::GERBER );
502  else if( paperType.Contains( PAGE_INFO::A4 ) )
503  retSuccess = m_pageInfo.SetType( PAGE_INFO::A4 );
504  else if( paperType.Contains( PAGE_INFO::A3 ) )
505  retSuccess = m_pageInfo.SetType( PAGE_INFO::A3 );
506  else if( paperType.Contains( PAGE_INFO::A2 ) )
507  retSuccess = m_pageInfo.SetType( PAGE_INFO::A2 );
508  else if( paperType.Contains( PAGE_INFO::A1 ) )
509  retSuccess = m_pageInfo.SetType( PAGE_INFO::A1 );
510  else if( paperType.Contains( PAGE_INFO::A0 ) )
511  retSuccess = m_pageInfo.SetType( PAGE_INFO::A0 );
512  else if( paperType.Contains( PAGE_INFO::A ) )
513  retSuccess = m_pageInfo.SetType( PAGE_INFO::A );
514  else if( paperType.Contains( PAGE_INFO::B ) )
515  retSuccess = m_pageInfo.SetType( PAGE_INFO::B );
516  else if( paperType.Contains( PAGE_INFO::C ) )
517  retSuccess = m_pageInfo.SetType( PAGE_INFO::C );
518  else if( paperType.Contains( PAGE_INFO::D ) )
519  retSuccess = m_pageInfo.SetType( PAGE_INFO::D );
520  else if( paperType.Contains( PAGE_INFO::E ) )
521  retSuccess = m_pageInfo.SetType( PAGE_INFO::E );
522 
523  if( retSuccess )
524  {
525  int choice = m_orientationComboBox->GetSelection();
526  m_pageInfo.SetPortrait( choice != 0 );
527  }
528  }
529 
530  if( !retSuccess )
531  {
532  wxASSERT_MSG( false, wxT( "the translation for paper size must preserve original spellings" ) );
534  }
535 
537 
538  m_tb.SetRevision( m_TextRevision->GetValue() );
539  m_tb.SetDate( m_TextDate->GetValue() );
540  m_tb.SetCompany( m_TextCompany->GetValue() );
541  m_tb.SetTitle( m_TextTitle->GetValue() );
542  m_tb.SetComment1( m_TextComment1->GetValue() );
543  m_tb.SetComment2( m_TextComment2->GetValue() );
544  m_tb.SetComment3( m_TextComment3->GetValue() );
545  m_tb.SetComment4( m_TextComment4->GetValue() );
546 
548 
549 
550 #ifdef EESCHEMA
551  // Exports settings to other sheets if requested:
552  SCH_SCREEN* screen;
553 
554  // Build the screen list
555  SCH_SCREENS ScreenList;
556 
557  // Update title blocks for all screens
558  for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
559  {
560  if( screen == m_screen )
561  continue;
562 
563  TITLE_BLOCK tb2 = screen->GetTitleBlock();
564 
565  if( m_RevisionExport->IsChecked() )
566  tb2.SetRevision( m_tb.GetRevision() );
567 
568  if( m_DateExport->IsChecked() )
569  tb2.SetDate( m_tb.GetDate() );
570 
571  if( m_TitleExport->IsChecked() )
572  tb2.SetTitle( m_tb.GetTitle() );
573 
574  if( m_CompanyExport->IsChecked() )
575  tb2.SetCompany( m_tb.GetCompany() );
576 
577  if( m_Comment1Export->IsChecked() )
578  tb2.SetComment1( m_tb.GetComment1() );
579 
580  if( m_Comment2Export->IsChecked() )
581  tb2.SetComment2( m_tb.GetComment2() );
582 
583  if( m_Comment3Export->IsChecked() )
584  tb2.SetComment3( m_tb.GetComment3() );
585 
586  if( m_Comment4Export->IsChecked() )
587  tb2.SetComment4( m_tb.GetComment4() );
588 
589  screen->SetTitleBlock( tb2 );
590  }
591 
592 #endif
593 
594  return true;
595 }
596 
597 
598 void DIALOG_PAGES_SETTINGS::SetCurrentPageSizeSelection( const wxString& aPaperSize )
599 {
600  // search all the not translated label list containing our paper type
601  for( unsigned i = 0; i < m_pageFmt.GetCount(); ++i )
602  {
603  // parse each label looking for aPaperSize within it
604  wxStringTokenizer st( m_pageFmt[i] );
605 
606  while( st.HasMoreTokens() )
607  {
608  if( st.GetNextToken() == aPaperSize )
609  {
610  m_paperSizeComboBox->SetSelection( i );
611  return;
612  }
613  }
614  }
615 }
616 
617 
619 {
620  int lyWidth, lyHeight;
621 
622  wxSize clamped_layout_size( Clamp( MIN_PAGE_SIZE, m_layout_size.x, MAX_PAGE_SIZE ),
624 
625  double lyRatio = clamped_layout_size.x < clamped_layout_size.y ?
626  (double) clamped_layout_size.y / clamped_layout_size.x :
627  (double) clamped_layout_size.x / clamped_layout_size.y;
628 
629  if( clamped_layout_size.x < clamped_layout_size.y )
630  {
631  lyHeight = MAX_PAGE_EXAMPLE_SIZE;
632  lyWidth = KiROUND( (double) lyHeight / lyRatio );
633  }
634  else
635  {
636  lyWidth = MAX_PAGE_EXAMPLE_SIZE;
637  lyHeight = KiROUND( (double) lyWidth / lyRatio );
638  }
639 
640  if( m_page_bitmap )
641  {
642  m_PageLayoutExampleBitmap->SetBitmap( wxNullBitmap );
643  delete m_page_bitmap;
644  }
645 
646  m_page_bitmap = new wxBitmap( lyWidth + 1, lyHeight + 1 );
647 
648  if( m_page_bitmap->IsOk() )
649  {
650  // Calculate layout preview scale.
651  int appScale = m_screen->MilsToIuScalar();
652 
653  double scaleW = (double) lyWidth / clamped_layout_size.x / appScale;
654  double scaleH = (double) lyHeight / clamped_layout_size.y / appScale;
655 
656  // Prepare DC.
657  wxSize example_size( lyWidth + 1, lyHeight + 1 );
658  wxMemoryDC memDC;
659  memDC.SelectObject( *m_page_bitmap );
660  memDC.SetClippingRegion( wxPoint( 0, 0 ), example_size );
661  memDC.Clear();
662  memDC.SetUserScale( scaleW, scaleH );
663 
664  // Get logical page size and margins.
665  PAGE_INFO pageDUMMY;
666 
667  // Get page type
668  int idx = m_paperSizeComboBox->GetSelection();
669 
670  if( idx < 0 )
671  idx = 0;
672 
673  wxString pageFmtName = m_pageFmt[idx].BeforeFirst( ' ' );
674  bool portrait = clamped_layout_size.x < clamped_layout_size.y;
675  pageDUMMY.SetType( pageFmtName, portrait );
676  if( m_customFmt )
677  {
678  pageDUMMY.SetWidthMils( clamped_layout_size.x );
679  pageDUMMY.SetHeightMils( clamped_layout_size.y );
680  }
681 
682  // Draw layout preview.
683  wxString emptyString;
684  GRResetPenAndBrush( &memDC );
685 
687  DrawPageLayout( &memDC, NULL, pageDUMMY,
688  emptyString, emptyString,
690  m_screen->m_ScreenNumber, 1, appScale, DARKGRAY, RED );
691 
692  memDC.SelectObject( wxNullBitmap );
695 
696  // Refresh the dialog.
697  Layout();
698  Refresh();
699  }
700 }
701 
702 
704 {
705  int idx = m_paperSizeComboBox->GetSelection();
706 
707  if( idx < 0 )
708  idx = 0;
709 
710  const wxString paperType = m_pageFmt[idx];
711 
712  // here we assume translators will keep original paper size spellings
713  if( paperType.Contains( PAGE_INFO::Custom ) )
714  {
716 
717  if( m_layout_size.x && m_layout_size.y )
718  {
719  if( m_layout_size.x < m_layout_size.y )
720  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
721  else
722  m_orientationComboBox->SetStringSelection( _( "Landscape" ) );
723  }
724  }
725  else
726  {
727  PAGE_INFO pageInfo; // SetType() later to lookup size
728 
729  static const wxChar* papers[] = {
730  // longest common string first, since sequential search below
736  PAGE_INFO::A,
737  PAGE_INFO::B,
738  PAGE_INFO::C,
739  PAGE_INFO::D,
740  PAGE_INFO::E,
744  };
745 
746  unsigned i;
747 
748  for( i=0; i < DIM( papers ); ++i )
749  {
750  if( paperType.Contains( papers[i] ) )
751  {
752  pageInfo.SetType( papers[i] );
753  break;
754  }
755  }
756 
757  wxASSERT( i != DIM(papers) ); // dialog UI match the above list?
758 
759  m_layout_size = pageInfo.GetSizeMils();
760 
761  // swap sizes to match orientation
762  bool isPortrait = (bool) m_orientationComboBox->GetSelection();
763 
764  if( ( isPortrait && m_layout_size.x >= m_layout_size.y ) ||
765  ( !isPortrait && m_layout_size.x < m_layout_size.y ) )
766  {
768  }
769  }
770 }
771 
772 
774 {
775  double customSizeX;
776  double customSizeY;
777  wxString msg;
778 
779  msg = m_TextUserSizeX->GetValue();
780  msg.ToDouble( &customSizeX );
781 
782  msg = m_TextUserSizeY->GetValue();
783  msg.ToDouble( &customSizeY );
784 
785  switch( g_UserUnit )
786  {
787  case MILLIMETRES:
788  customSizeX *= 1000. / 25.4;
789  customSizeY *= 1000. / 25.4;
790  break;
791 
792  default:
793  case INCHES:
794  customSizeX *= 1000.;
795  customSizeY *= 1000.;
796  }
797 
798  // Prepare to painless double -> int conversion.
799  customSizeX = Clamp( double( INT_MIN ), customSizeX, double( INT_MAX ) );
800  customSizeY = Clamp( double( INT_MIN ), customSizeY, double( INT_MAX ) );
801  m_layout_size = wxSize( KiROUND( customSizeX ), KiROUND( customSizeY ) );
802 }
803 
804 
805 void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
806 {
807  wxFileName fn = GetWksFileName();
808  wxString name = GetWksFileName();
809  wxString path;
810 
811  if( fn.IsAbsolute() )
812  {
813  path = fn.GetPath();
814  name = fn.GetFullName();
815  }
816  else
817  {
818  path = m_projectPath;
819  }
820 
821  // Display a file picker dialog
822  wxFileDialog fileDialog( this, _( "Select Page Layout Description File" ),
823  path, name, PageLayoutDescrFileWildcard(),
824  wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
825 
826  if( fileDialog.ShowModal() != wxID_OK )
827  return;
828 
829  wxString fileName = fileDialog.GetPath();
830 
831  // Try to remove the path, if the path is the current working dir,
832  // or the dir of kicad.pro (template), and use a relative path
833  wxString shortFileName = WORKSHEET_LAYOUT::MakeShortFileName( fileName, m_projectPath );
834 
835  // For Win/Linux/macOS compatibility, a relative path is a good idea
836  if( shortFileName != GetWksFileName() && shortFileName != fileName )
837  {
838  wxString msg = wxString::Format( _(
839  "The page layout description file name has changed.\n"
840  "Do you want to use the relative path:\n"
841  "\"%s\"\n"
842  "instead of\n"
843  "\"%s\"?" ), GetChars( shortFileName ), GetChars( fileName ) );
844 
845  if( !IsOK( this, msg ) )
846  shortFileName = fileName;
847  }
848 
849  SetWksFileName( shortFileName );
850 
851  if( m_pagelayout == NULL )
853 
854  m_pagelayout->SetPageLayout( fileName );
855 
858 }
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:338
This file is part of the common library.
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:351
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:55
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:361
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:57
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:98
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
const char * name
Definition: DXF_plotter.cpp:61
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
static LIB_PART * dummy()
Used 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.
size_t i
Definition: json11.cpp:597
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:233
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