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 #define MAX_PAGE_EXAMPLE_SIZE 200
54 
55 
56 // List of page formats.
57 // they are prefixed by "_HKI" (already in use for hotkeys) instead of "_",
58 // because we need both the translated and the not translated version.
59 // when displayed in dialog we should explicitly call wxGetTranslation()
60 // to show the translated version.
61 // See hotkeys_basic.h for more info
62 #define _HKI( x ) wxT( x )
63 static const wxString pageFmts[] =
64 {
65  _HKI("A4 210x297mm"),
66  _HKI("A3 297x420mm"),
67  _HKI("A2 420x594mm"),
68  _HKI("A1 594x841mm"),
69  _HKI("A0 841x1189mm"),
70  _HKI("A 8.5x11in"),
71  _HKI("B 11x17in"),
72  _HKI("C 17x22in"),
73  _HKI("D 22x34in"),
74  _HKI("E 34x44in"),
75  _HKI("USLetter 8.5x11in"), // USLetter without space is correct
76  _HKI("USLegal 8.5x14in"), // USLegal without space is correct
77  _HKI("USLedger 11x17in"), // USLedger without space is correct
78  _HKI("User (Custom)"), // size defined by user. The string must contain "Custom"
79  // to be recognized in code
80 };
81 
82 void EDA_DRAW_FRAME::Process_PageSettings( wxCommandEvent& event )
83 {
84  FRAME_T smallSizeFrames[] =
85  {
90  };
91 
92  // Fix the max page size: it is MAX_PAGE_SIZE_EDITORS
93  // or MAX_PAGE_SIZE_PCBNEW for Pcbnew draw frames, due to the small internal
94  // units that do not allow too large draw areas
96 
97  for( unsigned ii = 0; ii < DIM( smallSizeFrames ); ii++ )
98  {
99  if( IsType( smallSizeFrames[ii] ) )
100  {
101  maxPageSize.x = maxPageSize.y = MAX_PAGE_SIZE_PCBNEW_MILS;
102  break;
103  }
104  }
105 
106  DIALOG_PAGES_SETTINGS dlg( this, maxPageSize );
108 
109  if( dlg.ShowModal() == wxID_OK )
110  {
111 #ifdef EESCHEMA
112  RedrawScreen( wxPoint( 0, 0 ), false );
113 #else
114  GetCanvas()->Refresh();
115 #endif
116  }
117 }
118 
119 
121  DIALOG_PAGES_SETTINGS_BASE( parent ),
122  m_initialized( false ),
123  m_customSizeX( parent, m_userSizeXLabel, m_userSizeXCtrl, m_userSizeXUnits, false,
124  MIN_PAGE_SIZE * IU_PER_MILS, aMaxUserSizeMils.x * IU_PER_MILS ),
125  m_customSizeY( parent, m_userSizeYLabel, m_userSizeYCtrl, m_userSizeYUnits, false,
126  MIN_PAGE_SIZE * IU_PER_MILS, aMaxUserSizeMils.y * IU_PER_MILS )
127 {
128  m_parent = parent;
131  m_page_bitmap = NULL;
132  m_maxPageSizeMils = aMaxUserSizeMils;
134  m_customFmt = false;
135  m_localPrjConfigChanged = false;
136  m_pagelayout = NULL;
137 
138  m_PickDate->SetValue( wxDateTime::Now() );
139 
140  initDialog();
141 
142  GetSizer()->SetSizeHints( this );
143  Centre();
144 }
145 
146 
148 {
149  delete m_page_bitmap;
150  delete m_pagelayout;
151 }
152 
153 
155 {
156  wxString msg;
157 
158  // initialize page format choice box and page format list.
159  // The first shows translated strings, the second contains not translated strings
160  m_paperSizeComboBox->Clear();
161 
162  for( unsigned ii = 0; ii < DIM(pageFmts); ii++ )
163  {
164  m_pageFmt.Add( pageFmts[ii] );
165  m_paperSizeComboBox->Append( wxGetTranslation( pageFmts[ii] ) );
166  }
167 
168  // initialize the page layout descr filename
170 
171 #ifdef EESCHEMA
172  // Init display value for schematic sub-sheet number
173  wxString format = m_TextSheetCount->GetLabel();
174  msg.Printf( format, m_screen->m_NumberOfScreens );
175  m_TextSheetCount->SetLabel( msg );
176 
177  format = m_TextSheetNumber->GetLabel();
178  msg.Printf( format, m_screen->m_ScreenNumber );
179  m_TextSheetNumber->SetLabel( msg );
180 #else
181  m_TextSheetCount->Show( false );
182  m_TextSheetNumber->Show( false );
183 #endif
184 
187  m_orientationComboBox->SetSelection( m_pageInfo.IsPortrait() );
188 
189  // only a click fires the "selection changed" event, so have to fabricate this check
190  wxCommandEvent dummy;
191  OnPaperSizeChoice( dummy );
192 
193  if( m_customFmt )
194  {
197  }
198  else
199  {
202  }
203 
204  m_TextRevision->SetValue( m_tb.GetRevision() );
205  m_TextDate->SetValue( m_tb.GetDate() );
206  m_TextTitle->SetValue( m_tb.GetTitle() );
207  m_TextCompany->SetValue( m_tb.GetCompany() );
208  m_TextComment1->SetValue( m_tb.GetComment1() );
209  m_TextComment2->SetValue( m_tb.GetComment2() );
210  m_TextComment3->SetValue( m_tb.GetComment3() );
211  m_TextComment4->SetValue( m_tb.GetComment4() );
212 
213 #ifndef EESCHEMA
214  // these options have meaning only for Eeschema.
215  // disable them for other apps
216  m_RevisionExport->Show( false );
217  m_DateExport->Show( false );
218  m_TitleExport->Show( false );
219  m_CompanyExport->Show( false );
220  m_Comment1Export->Show( false );
221  m_Comment2Export->Show( false );
222  m_Comment3Export->Show( false );
223  m_Comment4Export->Show( false );
224 #endif
225 
228 
229  // Make the OK button the default.
230  m_sdbSizerOK->SetDefault();
231  m_initialized = true;
232 }
233 
234 
235 void DIALOG_PAGES_SETTINGS::OnOkClick( wxCommandEvent& event )
236 {
237  if( SavePageSettings() )
238  {
239  m_screen->SetModify();
240 
241  if( LocalPrjConfigChanged() )
242  m_parent->SaveProjectSettings( false );
243 
244  // Call the post processing (if any) after changes
246  }
247 
248  event.Skip();
249 }
250 
251 
252 void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
253 {
254  int idx = m_paperSizeComboBox->GetSelection();
255 
256  if( idx < 0 )
257  idx = 0;
258 
259  const wxString paperType = m_pageFmt[idx];
260 
261  if( paperType.Contains( PAGE_INFO::Custom ) )
262  {
263  m_orientationComboBox->Enable( false );
264  m_customSizeX.Enable( true );
265  m_customSizeY.Enable( true );
266  m_customFmt = true;
267  }
268  else
269  {
270  m_orientationComboBox->Enable( true );
271 
272 #if 0
273  // ForcePortrait() does not exist, but could be useful.
274  // so I leave these lines, which could be seen as a todo feature
275  if( paperType.ForcePortrait() )
276  {
277  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
278  m_orientationComboBox->Enable( false );
279  }
280 #endif
281  m_customSizeX.Enable( false );
282  m_customSizeY.Enable( false );
283  m_customFmt = false;
284  }
285 
288 }
289 
290 
292 {
293  if( m_initialized )
294  {
297  }
298 }
299 
300 
302 {
303  if( m_initialized )
304  {
307  }
308 }
309 
310 
312 {
313  if( m_initialized )
314  {
317  }
318 }
319 
320 
321 void DIALOG_PAGES_SETTINGS::OnRevisionTextUpdated( wxCommandEvent& event )
322 {
323  if( m_initialized && m_TextRevision->IsModified() )
324  {
326  m_tb.SetRevision( m_TextRevision->GetValue() );
328  }
329 }
330 
331 
332 void DIALOG_PAGES_SETTINGS::OnDateTextUpdated( wxCommandEvent& event )
333 {
334  if( m_initialized && m_TextDate->IsModified() )
335  {
337  m_tb.SetDate( m_TextDate->GetValue() );
339  }
340 }
341 
342 
343 void DIALOG_PAGES_SETTINGS::OnTitleTextUpdated( wxCommandEvent& event )
344 {
345  if( m_initialized && m_TextTitle->IsModified() )
346  {
348  m_tb.SetTitle( m_TextTitle->GetValue() );
350  }
351 }
352 
353 
354 void DIALOG_PAGES_SETTINGS::OnCompanyTextUpdated( wxCommandEvent& event )
355 {
356  if( m_initialized && m_TextCompany->IsModified() )
357  {
359  m_tb.SetCompany( m_TextCompany->GetValue() );
361  }
362 }
363 
364 
365 void DIALOG_PAGES_SETTINGS::OnComment1TextUpdated( wxCommandEvent& event )
366 {
367  if( m_initialized && m_TextComment1->IsModified() )
368  {
370  m_tb.SetComment1( m_TextComment1->GetValue() );
372  }
373 }
374 
375 
376 void DIALOG_PAGES_SETTINGS::OnComment2TextUpdated( wxCommandEvent& event )
377 {
378  if( m_initialized && m_TextComment2->IsModified() )
379  {
381  m_tb.SetComment2( m_TextComment2->GetValue() );
383  }
384 }
385 
386 
387 void DIALOG_PAGES_SETTINGS::OnComment3TextUpdated( wxCommandEvent& event )
388 {
389  if( m_initialized && m_TextComment3->IsModified() )
390  {
392  m_tb.SetComment3( m_TextComment3->GetValue() );
394  }
395 }
396 
397 
398 void DIALOG_PAGES_SETTINGS::OnComment4TextUpdated( wxCommandEvent& event )
399 {
400  if( m_initialized && m_TextComment4->IsModified() )
401  {
403  m_tb.SetComment4( m_TextComment4->GetValue() );
405  }
406 }
407 
408 
409 void DIALOG_PAGES_SETTINGS::OnDateApplyClick( wxCommandEvent& event )
410 {
411  wxDateTime datetime = m_PickDate->GetValue();
412  wxString date =
413  // We can choose different formats. Only one must be uncommented
414  //
415  // datetime.Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
416  // datetime.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
417  // datetime.Format( wxT("%Y-%b-%d") );
418  datetime.FormatISODate();
419 
420  m_TextDate->SetValue( date );
421 }
422 
423 
425 {
426  bool retSuccess = false;
427 
428  wxString fileName = GetWksFileName();
429 
431  {
432  wxString fullFileName = WORKSHEET_LAYOUT::MakeFullFileName( fileName, m_projectPath );
433 
434  if( !fullFileName.IsEmpty() && !wxFileExists( fullFileName ) )
435  {
436  wxString msg;
437  msg.Printf( _( "Page layout description file \"%s\" not found." ),
438  GetChars( fullFileName ) );
439  wxMessageBox( msg );
440  return false;
441  }
442 
445  pglayout.SetPageLayout( fullFileName );
447  }
448 
449  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
450  const wxString paperType = m_pageFmt[idx];
451 
452  if( paperType.Contains( PAGE_INFO::Custom ) )
453  {
455 
456  retSuccess = m_pageInfo.SetType( PAGE_INFO::Custom );
457 
458  if( retSuccess )
459  {
460  if( !m_customSizeX.Validate( true ) || !m_customSizeY.Validate( true ) )
461  return false;
462 
465 
468  }
469  }
470  else
471  {
472  // search for longest common string first, e.g. A4 before A
473  if( paperType.Contains( PAGE_INFO::USLetter ) )
474  retSuccess = m_pageInfo.SetType( PAGE_INFO::USLetter );
475  else if( paperType.Contains( PAGE_INFO::USLegal ) )
476  retSuccess = m_pageInfo.SetType( PAGE_INFO::USLegal );
477  else if( paperType.Contains( PAGE_INFO::USLedger ) )
478  retSuccess = m_pageInfo.SetType( PAGE_INFO::USLedger );
479  else if( paperType.Contains( PAGE_INFO::GERBER ) )
480  retSuccess = m_pageInfo.SetType( PAGE_INFO::GERBER );
481  else if( paperType.Contains( PAGE_INFO::A4 ) )
482  retSuccess = m_pageInfo.SetType( PAGE_INFO::A4 );
483  else if( paperType.Contains( PAGE_INFO::A3 ) )
484  retSuccess = m_pageInfo.SetType( PAGE_INFO::A3 );
485  else if( paperType.Contains( PAGE_INFO::A2 ) )
486  retSuccess = m_pageInfo.SetType( PAGE_INFO::A2 );
487  else if( paperType.Contains( PAGE_INFO::A1 ) )
488  retSuccess = m_pageInfo.SetType( PAGE_INFO::A1 );
489  else if( paperType.Contains( PAGE_INFO::A0 ) )
490  retSuccess = m_pageInfo.SetType( PAGE_INFO::A0 );
491  else if( paperType.Contains( PAGE_INFO::A ) )
492  retSuccess = m_pageInfo.SetType( PAGE_INFO::A );
493  else if( paperType.Contains( PAGE_INFO::B ) )
494  retSuccess = m_pageInfo.SetType( PAGE_INFO::B );
495  else if( paperType.Contains( PAGE_INFO::C ) )
496  retSuccess = m_pageInfo.SetType( PAGE_INFO::C );
497  else if( paperType.Contains( PAGE_INFO::D ) )
498  retSuccess = m_pageInfo.SetType( PAGE_INFO::D );
499  else if( paperType.Contains( PAGE_INFO::E ) )
500  retSuccess = m_pageInfo.SetType( PAGE_INFO::E );
501 
502  if( retSuccess )
503  {
504  int choice = m_orientationComboBox->GetSelection();
505  m_pageInfo.SetPortrait( choice != 0 );
506  }
507  }
508 
509  if( !retSuccess )
510  {
511  wxASSERT_MSG( false, _( "the translation for paper size must preserve original spellings" ) );
513  }
514 
516 
517  m_tb.SetRevision( m_TextRevision->GetValue() );
518  m_tb.SetDate( m_TextDate->GetValue() );
519  m_tb.SetCompany( m_TextCompany->GetValue() );
520  m_tb.SetTitle( m_TextTitle->GetValue() );
521  m_tb.SetComment1( m_TextComment1->GetValue() );
522  m_tb.SetComment2( m_TextComment2->GetValue() );
523  m_tb.SetComment3( m_TextComment3->GetValue() );
524  m_tb.SetComment4( m_TextComment4->GetValue() );
525 
527 
528 
529 #ifdef EESCHEMA
530  // Exports settings to other sheets if requested:
531  SCH_SCREEN* screen;
532 
533  // Build the screen list
534  SCH_SCREENS ScreenList;
535 
536  // Update title blocks for all screens
537  for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
538  {
539  if( screen == m_screen )
540  continue;
541 
542  TITLE_BLOCK tb2 = screen->GetTitleBlock();
543 
544  if( m_RevisionExport->IsChecked() )
545  tb2.SetRevision( m_tb.GetRevision() );
546 
547  if( m_DateExport->IsChecked() )
548  tb2.SetDate( m_tb.GetDate() );
549 
550  if( m_TitleExport->IsChecked() )
551  tb2.SetTitle( m_tb.GetTitle() );
552 
553  if( m_CompanyExport->IsChecked() )
554  tb2.SetCompany( m_tb.GetCompany() );
555 
556  if( m_Comment1Export->IsChecked() )
557  tb2.SetComment1( m_tb.GetComment1() );
558 
559  if( m_Comment2Export->IsChecked() )
560  tb2.SetComment2( m_tb.GetComment2() );
561 
562  if( m_Comment3Export->IsChecked() )
563  tb2.SetComment3( m_tb.GetComment3() );
564 
565  if( m_Comment4Export->IsChecked() )
566  tb2.SetComment4( m_tb.GetComment4() );
567 
568  screen->SetTitleBlock( tb2 );
569  }
570 
571 #endif
572 
573  return true;
574 }
575 
576 
577 void DIALOG_PAGES_SETTINGS::SetCurrentPageSizeSelection( const wxString& aPaperSize )
578 {
579  // search all the not translated label list containing our paper type
580  for( unsigned i = 0; i < m_pageFmt.GetCount(); ++i )
581  {
582  // parse each label looking for aPaperSize within it
583  wxStringTokenizer st( m_pageFmt[i] );
584 
585  while( st.HasMoreTokens() )
586  {
587  if( st.GetNextToken() == aPaperSize )
588  {
589  m_paperSizeComboBox->SetSelection( i );
590  return;
591  }
592  }
593  }
594 }
595 
596 
598 {
599  int lyWidth, lyHeight;
600 
601  wxSize clamped_layout_size( Clamp( MIN_PAGE_SIZE, m_layout_size.x, m_maxPageSizeMils.x ),
603 
604  double lyRatio = clamped_layout_size.x < clamped_layout_size.y ?
605  (double) clamped_layout_size.y / clamped_layout_size.x :
606  (double) clamped_layout_size.x / clamped_layout_size.y;
607 
608  if( clamped_layout_size.x < clamped_layout_size.y )
609  {
610  lyHeight = MAX_PAGE_EXAMPLE_SIZE;
611  lyWidth = KiROUND( (double) lyHeight / lyRatio );
612  }
613  else
614  {
615  lyWidth = MAX_PAGE_EXAMPLE_SIZE;
616  lyHeight = KiROUND( (double) lyWidth / lyRatio );
617  }
618 
619  if( m_page_bitmap )
620  {
621  m_PageLayoutExampleBitmap->SetBitmap( wxNullBitmap );
622  delete m_page_bitmap;
623  }
624 
625  m_page_bitmap = new wxBitmap( lyWidth + 1, lyHeight + 1 );
626 
627  if( m_page_bitmap->IsOk() )
628  {
629  // Calculate layout preview scale.
630  int appScale = m_screen->MilsToIuScalar();
631 
632  double scaleW = (double) lyWidth / clamped_layout_size.x / appScale;
633  double scaleH = (double) lyHeight / clamped_layout_size.y / appScale;
634 
635  // Prepare DC.
636  wxSize example_size( lyWidth + 1, lyHeight + 1 );
637  wxMemoryDC memDC;
638  memDC.SelectObject( *m_page_bitmap );
639  memDC.SetClippingRegion( wxPoint( 0, 0 ), example_size );
640  memDC.Clear();
641  memDC.SetUserScale( scaleW, scaleH );
642 
643  // Get logical page size and margins.
644  PAGE_INFO pageDUMMY;
645 
646  // Get page type
647  int idx = m_paperSizeComboBox->GetSelection();
648 
649  if( idx < 0 )
650  idx = 0;
651 
652  wxString pageFmtName = m_pageFmt[idx].BeforeFirst( ' ' );
653  bool portrait = clamped_layout_size.x < clamped_layout_size.y;
654  pageDUMMY.SetType( pageFmtName, portrait );
655  if( m_customFmt )
656  {
657  pageDUMMY.SetWidthMils( clamped_layout_size.x );
658  pageDUMMY.SetHeightMils( clamped_layout_size.y );
659  }
660 
661  // Draw layout preview.
662  wxString emptyString;
663  GRResetPenAndBrush( &memDC );
664 
666  DrawPageLayout( &memDC, NULL, pageDUMMY,
667  emptyString, emptyString,
669  m_screen->m_ScreenNumber, 1, appScale, DARKGRAY, RED );
670 
671  memDC.SelectObject( wxNullBitmap );
674 
675  // Refresh the dialog.
676  Layout();
677  Refresh();
678  }
679 }
680 
681 
683 {
684  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
685  const wxString paperType = m_pageFmt[idx];
686 
687  // here we assume translators will keep original paper size spellings
688  if( paperType.Contains( PAGE_INFO::Custom ) )
689  {
691 
692  if( m_layout_size.x && m_layout_size.y )
693  {
694  if( m_layout_size.x < m_layout_size.y )
695  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
696  else
697  m_orientationComboBox->SetStringSelection( _( "Landscape" ) );
698  }
699  }
700  else
701  {
702  PAGE_INFO pageInfo; // SetType() later to lookup size
703 
704  static const wxChar* papers[] = {
705  // longest common string first, since sequential search below
711  PAGE_INFO::A,
712  PAGE_INFO::B,
713  PAGE_INFO::C,
714  PAGE_INFO::D,
715  PAGE_INFO::E,
719  };
720 
721  unsigned i;
722 
723  for( i=0; i < DIM( papers ); ++i )
724  {
725  if( paperType.Contains( papers[i] ) )
726  {
727  pageInfo.SetType( papers[i] );
728  break;
729  }
730  }
731 
732  wxASSERT( i != DIM(papers) ); // dialog UI match the above list?
733 
734  m_layout_size = pageInfo.GetSizeMils();
735 
736  // swap sizes to match orientation
737  bool isPortrait = (bool) m_orientationComboBox->GetSelection();
738 
739  if( ( isPortrait && m_layout_size.x >= m_layout_size.y ) ||
740  ( !isPortrait && m_layout_size.x < m_layout_size.y ) )
741  {
743  }
744  }
745 }
746 
747 
749 {
750  double customSizeX = (double) m_customSizeX.GetValue() / IU_PER_MILS;
751  double customSizeY = (double) m_customSizeY.GetValue() / IU_PER_MILS;
752 
753  // Prepare to painless double -> int conversion.
754  customSizeX = Clamp( double( INT_MIN ), customSizeX, double( INT_MAX ) );
755  customSizeY = Clamp( double( INT_MIN ), customSizeY, double( INT_MAX ) );
756  m_layout_size = wxSize( KiROUND( customSizeX ), KiROUND( customSizeY ) );
757 }
758 
759 
760 void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
761 {
762  wxFileName fn = GetWksFileName();
763  wxString name = GetWksFileName();
764  wxString path;
765 
766  if( fn.IsAbsolute() )
767  {
768  path = fn.GetPath();
769  name = fn.GetFullName();
770  }
771  else
772  {
773  path = m_projectPath;
774  }
775 
776  // Display a file picker dialog
777  wxFileDialog fileDialog( this, _( "Select Page Layout Description File" ),
778  path, name, PageLayoutDescrFileWildcard(),
779  wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
780 
781  if( fileDialog.ShowModal() != wxID_OK )
782  return;
783 
784  wxString fileName = fileDialog.GetPath();
785 
786  // Try to remove the path, if the path is the current working dir,
787  // or the dir of kicad.pro (template), and use a relative path
788  wxString shortFileName = WORKSHEET_LAYOUT::MakeShortFileName( fileName, m_projectPath );
789 
790  // For Win/Linux/macOS compatibility, a relative path is a good idea
791  if( shortFileName != GetWksFileName() && shortFileName != fileName )
792  {
793  wxString msg = wxString::Format( _(
794  "The page layout description file name has changed.\n"
795  "Do you want to use the relative path:\n"
796  "\"%s\"\n"
797  "instead of\n"
798  "\"%s\"?" ), GetChars( shortFileName ), GetChars( fileName ) );
799 
800  if( !IsOK( this, msg ) )
801  shortFileName = fileName;
802  }
803 
804  SetWksFileName( shortFileName );
805 
806  if( m_pagelayout == NULL )
808 
809  m_pagelayout->SetPageLayout( fileName );
810 
813 }
void SetComment1(const wxString &aComment)
Definition: title_block.h:117
virtual bool Validate(bool setFocusOnError=false)
Function Validate Validates the control, informing the user of any errors found.
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:123
static const wxChar A[]
Definition: page_info.h:69
wxString PageLayoutDescrFileWildcard()
SCH_SCREEN * GetNext()
int m_ScreenNumber
Definition: base_screen.h:216
wxSize m_maxPageSizeMils
Logical page layout 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 EDA_DRAW_PANEL * GetCanvas() const
Definition: draw_frame.h:388
virtual const TITLE_BLOCK & GetTitleBlock() const =0
static int GetCustomHeightMils()
Function GetCustomHeightMils.
Definition: page_info.h:176
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
void OnPageOrientationChoice(wxCommandEvent &event) override
const wxString & GetCompany() const
Definition: title_block.h:99
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
static const wxChar E[]
Definition: page_info.h:73
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
void OnComment3TextUpdated(wxCommandEvent &event) override
static const wxChar GERBER[]
Definition: page_info.h:74
TITLE_BLOCK m_tb
true if the page selection is custom
static const wxChar A3[]
Definition: page_info.h:65
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:124
void SetDate(const wxString &aDate)
Function SetDate sets the date field, and defaults to the current time and date.
Definition: title_block.h:74
const wxString & GetDate() const
Definition: title_block.h:79
void OnUserPageSizeXTextUpdated(wxCommandEvent &event) override
static const wxChar Custom[]
"User" defined page type
Definition: page_info.h:78
#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.
Definition: draw_frame.h:78
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:40
wxSize m_layout_size
Temporary bitmap for the page layout example.
void SetComment4(const wxString &aComment)
Definition: title_block.h:120
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:142
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
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:65
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...
void OnComment1TextUpdated(wxCommandEvent &event) override
bool IsPortrait() const
Definition: page_info.h:121
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:397
static const wxChar USLegal[]
Definition: page_info.h:76
static const wxChar B[]
Definition: page_info.h:70
static const wxChar C[]
Definition: page_info.h:71
#define MAX_PAGE_SIZE_PCBNEW_MILS
Definition: page_info.h:40
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
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
void SetCompany(const wxString &aCompany)
Definition: title_block.h:94
The common library.
static const wxChar A4[]
Definition: page_info.h:64
Definition: colors.h:60
const wxString & GetComment3() const
Definition: title_block.h:123
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:138
void SetCurrentPageSizeSelection(const wxString &aPaperSize)
void SetTitle(const wxString &aTitle)
Definition: title_block.h:60
int GetWidthMils() const
Definition: page_info.h:137
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:253
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:136
static const wxChar USLedger[]
Definition: page_info.h:77
const wxString & GetComment2() const
Definition: title_block.h:122
DIALOG_PAGES_SETTINGS(EDA_DRAW_FRAME *parent, wxSize aMaxUserSizeMils)
#define MAX_PAGE_SIZE_EDITORS_MILS
Definition: page_info.h:41
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.
virtual void SaveProjectSettings(bool aAskForSave)
Function SaveProjectSettings saves changes to the project settings to the project (...
static const wxChar A1[]
Definition: page_info.h:67
Definitions for the Eeschema program SCH_SCREEN class.
virtual void RedrawScreen(const wxPoint &aCenterPoint, bool aWarpPointer)
Redraw the entire screen area by updating the scroll bars and mouse pointer in order to have aCenterP...
static const wxChar USLetter[]
Definition: page_info.h:75
void OnOkClick(wxCommandEvent &event) override
void SetComment2(const wxString &aComment)
Definition: title_block.h:118
virtual void OnPageSettingsChange()
Called when modifying the page settings.
Definition: draw_frame.h:757
const wxString & GetComment1() const
Definition: title_block.h:121
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: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...
#define max(a, b)
Definition: auxiliary.h:86
static const wxString MakeShortFileName(const wxString &aFullFileName, const wxString &aProjectPath)
WORKSHEET_LAYOUT * m_pagelayout
Temporary title block (basic inscriptions).
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...
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
#define IU_PER_MILS
Definition: plotter.cpp:134
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:102
The common library.
static int GetCustomWidthMils()
Function GetCustomWidthMils.
Definition: page_info.h:170
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:66
classes and function to generate graphics to plt or draw titles blocks and frame references ...
SCH_SCREEN * GetFirst()
void OnComment2TextUpdated(wxCommandEvent &event) override
bool IsType(FRAME_T aType) const
void OnPaperSizeChoice(wxCommandEvent &event) override
void SetComment3(const wxString &aComment)
Definition: title_block.h:119
const wxString & GetType() const
Definition: page_info.h:97
Basic classes for most KiCad items.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
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, in mils.
Definition: page_info.h:39
BASE_SCREEN class implementation.
#define _HKI(x)
void SetPortrait(bool aIsPortrait)
Function SetPortrait will rotate the paper page 90 degrees.
Definition: page_info.cpp:182
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:295
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:140
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:523
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:68