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) 2021 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <base_screen.h>
21 #include <confirm.h>
22 #include <core/arraydim.h>
24 #include <eda_draw_frame.h>
25 #include <eda_item.h>
26 #include <gr_basic.h>
27 #include <kiface_i.h>
28 #include <macros.h>
29 #include <math/util.h> // for KiROUND, Clamp
30 #include <project.h>
31 #include <title_block.h>
32 #include <tool/actions.h>
33 #include <tool/tool_manager.h>
37 #include <wx/valgen.h>
38 #include <wx/tokenzr.h>
39 #include <wx/filedlg.h>
40 #include <wx/dcmemory.h>
41 
42 #define MAX_PAGE_EXAMPLE_SIZE 200
43 
44 
45 // List of page formats.
46 // they are prefixed by "_HKI" (already in use for hotkeys) instead of "_",
47 // because we need both the translated and the not translated version.
48 // when displayed in dialog we should explicitly call wxGetTranslation()
49 // to show the translated version.
50 // See hotkeys_basic.h for more info
51 #define _HKI( x ) wxT( x )
52 static const wxString pageFmts[] =
53 {
54  _HKI("A5 148x210mm"),
55  _HKI("A4 210x297mm"),
56  _HKI("A3 297x420mm"),
57  _HKI("A2 420x594mm"),
58  _HKI("A1 594x841mm"),
59  _HKI("A0 841x1189mm"),
60  _HKI("A 8.5x11in"),
61  _HKI("B 11x17in"),
62  _HKI("C 17x22in"),
63  _HKI("D 22x34in"),
64  _HKI("E 34x44in"),
65  _HKI("USLetter 8.5x11in"), // USLetter without space is correct
66  _HKI("USLegal 8.5x14in"), // USLegal without space is correct
67  _HKI("USLedger 11x17in"), // USLedger without space is correct
68  _HKI("User (Custom)"), // size defined by user. The string must contain "Custom"
69  // to be recognized in code
70 };
71 
73  wxSize aMaxUserSizeMils ) :
74  DIALOG_PAGES_SETTINGS_BASE( aParent ),
75  m_parent( aParent ),
76  m_screen( m_parent->GetScreen() ),
77  m_initialized( false ),
78  m_pageBitmap( nullptr ),
79  m_iuPerMils( aIuPerMils ),
80  m_customSizeX( aParent, m_userSizeXLabel, m_userSizeXCtrl, m_userSizeXUnits ),
81  m_customSizeY( aParent, m_userSizeYLabel, m_userSizeYCtrl, m_userSizeYUnits )
82 {
84  m_maxPageSizeMils = aMaxUserSizeMils;
86  m_customFmt = false;
88 
90  wxString serialization;
91  DS_DATA_MODEL::GetTheInstance().SaveInString( &serialization );
92  m_drawingSheet->SetPageLayout( TO_UTF8( serialization ) );
93 
94  m_PickDate->SetValue( wxDateTime::Now() );
95 
96  if( m_parent->GetName() == PL_EDITOR_FRAME_NAME )
97  {
98  SetTitle( _( "Preview Settings" ) );
99  m_staticTextPaper->SetLabel( _( "Preview Paper" ) );
100  m_staticTextTitleBlock->SetLabel( _( "Preview Title Block Data" ) );
101  }
102  else
103  {
104  SetTitle( _( "Page Settings" ) );
105  m_staticTextPaper->SetLabel( _( "Paper" ) );
106  m_staticTextTitleBlock->SetLabel( _( "Title Block" ) );
107  }
108 
109  Centre();
110 }
111 
112 
114 {
115  delete m_pageBitmap;
116  delete m_drawingSheet;
117 }
118 
119 
121 {
122  wxString msg;
123 
124  // initialize page format choice box and page format list.
125  // The first shows translated strings, the second contains not translated strings
126  m_paperSizeComboBox->Clear();
127 
128  for( const wxString& pageFmt : pageFmts )
129  {
130  m_pageFmt.Add( pageFmt );
131  m_paperSizeComboBox->Append( wxGetTranslation( pageFmt ) );
132  }
133 
134  // initialize the drawing sheet filename
136 
139  m_orientationComboBox->SetSelection( m_pageInfo.IsPortrait() );
140 
141  // only a click fires the "selection changed" event, so have to fabricate this check
142  wxCommandEvent dummy;
144 
145  if( m_customFmt )
146  {
149  }
150  else
151  {
154  }
155 
156  m_TextRevision->SetValue( m_tb.GetRevision() );
157  m_TextDate->SetValue( m_tb.GetDate() );
158  m_TextTitle->SetValue( m_tb.GetTitle() );
159  m_TextCompany->SetValue( m_tb.GetCompany() );
160  m_TextComment1->SetValue( m_tb.GetComment( 0 ) );
161  m_TextComment2->SetValue( m_tb.GetComment( 1 ) );
162  m_TextComment3->SetValue( m_tb.GetComment( 2 ) );
163  m_TextComment4->SetValue( m_tb.GetComment( 3 ) );
164  m_TextComment5->SetValue( m_tb.GetComment( 4 ) );
165  m_TextComment6->SetValue( m_tb.GetComment( 5 ) );
166  m_TextComment7->SetValue( m_tb.GetComment( 6 ) );
167  m_TextComment8->SetValue( m_tb.GetComment( 7 ) );
168  m_TextComment9->SetValue( m_tb.GetComment( 8 ) );
169 
170  // The default is to disable aall these fields for the "generic" dialog
171  m_TextSheetCount->Show( false );
172  m_TextSheetNumber->Show( false );
173  m_PaperExport->Show( false );
174  m_RevisionExport->Show( false );
175  m_DateExport->Show( false );
176  m_TitleExport->Show( false );
177  m_CompanyExport->Show( false );
178  m_Comment1Export->Show( false );
179  m_Comment2Export->Show( false );
180  m_Comment3Export->Show( false );
181  m_Comment4Export->Show( false );
182  m_Comment5Export->Show( false );
183  m_Comment6Export->Show( false );
184  m_Comment7Export->Show( false );
185  m_Comment8Export->Show( false );
186  m_Comment9Export->Show( false );
187 
189 
192 
193  GetSizer()->SetSizeHints( this );
194 
195  // Make the OK button the default.
196  m_sdbSizerOK->SetDefault();
197  m_initialized = true;
198 
199  return true;
200 }
201 
202 
204 {
206  return false;
207 
209  return false;
210 
211  if( SavePageSettings() )
212  {
214 
215  if( LocalPrjConfigChanged() )
217 
218  // Call the post processing (if any) after changes
220  }
221 
222  return true;
223 }
224 
225 
226 void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
227 {
228  int idx = m_paperSizeComboBox->GetSelection();
229 
230  if( idx < 0 )
231  idx = 0;
232 
233  const wxString paperType = m_pageFmt[idx];
234 
235  if( paperType.Contains( PAGE_INFO::Custom ) )
236  {
237  m_orientationComboBox->Enable( false );
238  m_customSizeX.Enable( true );
239  m_customSizeY.Enable( true );
240  m_customFmt = true;
241  }
242  else
243  {
244  m_orientationComboBox->Enable( true );
245 
246 #if 0
247  // ForcePortrait() does not exist, but could be useful.
248  // so I leave these lines, which could be seen as a todo feature
249  if( paperType.ForcePortrait() )
250  {
251  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
252  m_orientationComboBox->Enable( false );
253  }
254 #endif
255  m_customSizeX.Enable( false );
256  m_customSizeY.Enable( false );
257  m_customFmt = false;
258  }
259 
262 }
263 
264 
266 {
267  if( m_initialized )
268  {
271  }
272 }
273 
274 
276 {
277  if( m_initialized )
278  {
281  }
282 }
283 
284 
286 {
287  if( m_initialized )
288  {
291  }
292 }
293 
294 
295 void DIALOG_PAGES_SETTINGS::OnRevisionTextUpdated( wxCommandEvent& event )
296 {
297  if( m_initialized && m_TextRevision->IsModified() )
298  {
300  m_tb.SetRevision( m_TextRevision->GetValue() );
302  }
303 }
304 
305 
306 void DIALOG_PAGES_SETTINGS::OnDateTextUpdated( wxCommandEvent& event )
307 {
308  if( m_initialized && m_TextDate->IsModified() )
309  {
311  m_tb.SetDate( m_TextDate->GetValue() );
313  }
314 }
315 
316 
317 void DIALOG_PAGES_SETTINGS::OnTitleTextUpdated( wxCommandEvent& event )
318 {
319  if( m_initialized && m_TextTitle->IsModified() )
320  {
322  m_tb.SetTitle( m_TextTitle->GetValue() );
324  }
325 }
326 
327 
328 void DIALOG_PAGES_SETTINGS::OnCompanyTextUpdated( wxCommandEvent& event )
329 {
330  if( m_initialized && m_TextCompany->IsModified() )
331  {
333  m_tb.SetCompany( m_TextCompany->GetValue() );
335  }
336 }
337 
338 
339 void DIALOG_PAGES_SETTINGS::OnComment1TextUpdated( wxCommandEvent& event )
340 {
341  if( m_initialized && m_TextComment1->IsModified() )
342  {
344  m_tb.SetComment( 0, m_TextComment1->GetValue() );
346  }
347 }
348 
349 
350 void DIALOG_PAGES_SETTINGS::OnComment2TextUpdated( wxCommandEvent& event )
351 {
352  if( m_initialized && m_TextComment2->IsModified() )
353  {
355  m_tb.SetComment( 1, m_TextComment2->GetValue() );
357  }
358 }
359 
360 
361 void DIALOG_PAGES_SETTINGS::OnComment3TextUpdated( wxCommandEvent& event )
362 {
363  if( m_initialized && m_TextComment3->IsModified() )
364  {
366  m_tb.SetComment( 2, m_TextComment3->GetValue() );
368  }
369 }
370 
371 
372 void DIALOG_PAGES_SETTINGS::OnComment4TextUpdated( wxCommandEvent& event )
373 {
374  if( m_initialized && m_TextComment4->IsModified() )
375  {
377  m_tb.SetComment( 3, m_TextComment4->GetValue() );
379  }
380 }
381 
382 
383 void DIALOG_PAGES_SETTINGS::OnComment5TextUpdated( wxCommandEvent& event )
384 {
385  if( m_initialized && m_TextComment5->IsModified() )
386  {
388  m_tb.SetComment( 4, m_TextComment5->GetValue() );
390  }
391 }
392 
393 
394 void DIALOG_PAGES_SETTINGS::OnComment6TextUpdated( wxCommandEvent& event )
395 {
396  if( m_initialized && m_TextComment6->IsModified() )
397  {
399  m_tb.SetComment( 5, m_TextComment6->GetValue() );
401  }
402 }
403 
404 
405 void DIALOG_PAGES_SETTINGS::OnComment7TextUpdated( wxCommandEvent& event )
406 {
407  if( m_initialized && m_TextComment7->IsModified() )
408  {
410  m_tb.SetComment( 6, m_TextComment7->GetValue() );
412  }
413 }
414 
415 
416 void DIALOG_PAGES_SETTINGS::OnComment8TextUpdated( wxCommandEvent& event )
417 {
418  if( m_initialized && m_TextComment8->IsModified() )
419  {
421  m_tb.SetComment( 7, m_TextComment8->GetValue() );
423  }
424 }
425 
426 
427 void DIALOG_PAGES_SETTINGS::OnComment9TextUpdated( wxCommandEvent& event )
428 {
429  if( m_initialized && m_TextComment9->IsModified() )
430  {
432  m_tb.SetComment( 8, m_TextComment9->GetValue() );
434  }
435 }
436 
437 
438 void DIALOG_PAGES_SETTINGS::OnDateApplyClick( wxCommandEvent& event )
439 {
440  wxDateTime datetime = m_PickDate->GetValue();
441  wxString date =
442  // We can choose different formats. Only one must be uncommented
443  //
444  // datetime.Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
445  // datetime.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
446  // datetime.Format( wxT("%Y-%b-%d") );
447  datetime.FormatISODate();
448 
449  m_TextDate->SetValue( date );
450 }
451 
452 
454 {
455  bool success = false;
456 
457  wxString fileName = GetWksFileName();
458 
459  if( fileName != BASE_SCREEN::m_DrawingSheetFileName )
460  {
461  wxString fullFileName = DS_DATA_MODEL::MakeFullFileName( fileName, m_projectPath );
462 
463  if( !fullFileName.IsEmpty() && !wxFileExists( fullFileName ) )
464  {
465  wxString msg;
466  msg.Printf( _( "Drawing sheet file '%s' not found." ), fullFileName );
467  wxMessageBox( msg );
468  return false;
469  }
470 
474  }
475 
476  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
477  const wxString paperType = m_pageFmt[idx];
478 
479  if( paperType.Contains( PAGE_INFO::Custom ) )
480  {
482 
483  success = m_pageInfo.SetType( PAGE_INFO::Custom );
484 
485  if( success )
486  {
489 
492  }
493  }
494  else
495  {
496  // search for longest common string first, e.g. A4 before A
497  if( paperType.Contains( PAGE_INFO::USLetter ) )
499  else if( paperType.Contains( PAGE_INFO::USLegal ) )
501  else if( paperType.Contains( PAGE_INFO::USLedger ) )
503  else if( paperType.Contains( PAGE_INFO::GERBER ) )
504  success = m_pageInfo.SetType( PAGE_INFO::GERBER );
505  else if( paperType.Contains( PAGE_INFO::A5 ) )
506  success = m_pageInfo.SetType( PAGE_INFO::A5 );
507  else if( paperType.Contains( PAGE_INFO::A4 ) )
508  success = m_pageInfo.SetType( PAGE_INFO::A4 );
509  else if( paperType.Contains( PAGE_INFO::A3 ) )
510  success = m_pageInfo.SetType( PAGE_INFO::A3 );
511  else if( paperType.Contains( PAGE_INFO::A2 ) )
512  success = m_pageInfo.SetType( PAGE_INFO::A2 );
513  else if( paperType.Contains( PAGE_INFO::A1 ) )
514  success = m_pageInfo.SetType( PAGE_INFO::A1 );
515  else if( paperType.Contains( PAGE_INFO::A0 ) )
516  success = m_pageInfo.SetType( PAGE_INFO::A0 );
517  else if( paperType.Contains( PAGE_INFO::A ) )
518  success = m_pageInfo.SetType( PAGE_INFO::A );
519  else if( paperType.Contains( PAGE_INFO::B ) )
520  success = m_pageInfo.SetType( PAGE_INFO::B );
521  else if( paperType.Contains( PAGE_INFO::C ) )
522  success = m_pageInfo.SetType( PAGE_INFO::C );
523  else if( paperType.Contains( PAGE_INFO::D ) )
524  success = m_pageInfo.SetType( PAGE_INFO::D );
525  else if( paperType.Contains( PAGE_INFO::E ) )
526  success = m_pageInfo.SetType( PAGE_INFO::E );
527 
528  if( success )
529  {
530  int choice = m_orientationComboBox->GetSelection();
531  m_pageInfo.SetPortrait( choice != 0 );
532  }
533  }
534 
535  if( !success )
536  {
537  wxASSERT_MSG( false, _( "the translation for paper size must preserve original spellings" ) );
539  }
540 
542 
543  m_tb.SetRevision( m_TextRevision->GetValue() );
544  m_tb.SetDate( m_TextDate->GetValue() );
545  m_tb.SetCompany( m_TextCompany->GetValue() );
546  m_tb.SetTitle( m_TextTitle->GetValue() );
547  m_tb.SetComment( 0, m_TextComment1->GetValue() );
548  m_tb.SetComment( 1, m_TextComment2->GetValue() );
549  m_tb.SetComment( 2, m_TextComment3->GetValue() );
550  m_tb.SetComment( 3, m_TextComment4->GetValue() );
551  m_tb.SetComment( 4, m_TextComment5->GetValue() );
552  m_tb.SetComment( 5, m_TextComment6->GetValue() );
553  m_tb.SetComment( 6, m_TextComment7->GetValue() );
554  m_tb.SetComment( 7, m_TextComment8->GetValue() );
555  m_tb.SetComment( 8, m_TextComment9->GetValue() );
556 
558 
559  return onSavePageSettings();
560 }
561 
562 
563 void DIALOG_PAGES_SETTINGS::SetCurrentPageSizeSelection( const wxString& aPaperSize )
564 {
565  // search all the not translated label list containing our paper type
566  for( unsigned i = 0; i < m_pageFmt.GetCount(); ++i )
567  {
568  // parse each label looking for aPaperSize within it
569  wxStringTokenizer st( m_pageFmt[i] );
570 
571  while( st.HasMoreTokens() )
572  {
573  if( st.GetNextToken() == aPaperSize )
574  {
575  m_paperSizeComboBox->SetSelection( i );
576  return;
577  }
578  }
579  }
580 }
581 
582 
584 {
585  int lyWidth, lyHeight;
586 
587  wxSize clamped_layout_size( Clamp( MIN_PAGE_SIZE_MILS, m_layout_size.x, m_maxPageSizeMils.x ),
589 
590  double lyRatio = clamped_layout_size.x < clamped_layout_size.y ?
591  (double) clamped_layout_size.y / clamped_layout_size.x :
592  (double) clamped_layout_size.x / clamped_layout_size.y;
593 
594  if( clamped_layout_size.x < clamped_layout_size.y )
595  {
596  lyHeight = MAX_PAGE_EXAMPLE_SIZE;
597  lyWidth = KiROUND( (double) lyHeight / lyRatio );
598  }
599  else
600  {
601  lyWidth = MAX_PAGE_EXAMPLE_SIZE;
602  lyHeight = KiROUND( (double) lyWidth / lyRatio );
603  }
604 
605  if( m_pageBitmap )
606  {
607  m_PageLayoutExampleBitmap->SetBitmap( wxNullBitmap );
608  delete m_pageBitmap;
609  }
610 
611  m_pageBitmap = new wxBitmap( lyWidth + 1, lyHeight + 1 );
612 
613  if( m_pageBitmap->IsOk() )
614  {
615  double scaleW = (double) lyWidth / clamped_layout_size.x;
616  double scaleH = (double) lyHeight / clamped_layout_size.y;
617  double scale = std::min( scaleW, scaleH );
618 
619  // Prepare DC.
620  wxSize example_size( lyWidth + 1, lyHeight + 1 );
621  wxMemoryDC memDC;
622  memDC.SelectObject( *m_pageBitmap );
623  memDC.SetClippingRegion( wxPoint( 0, 0 ), example_size );
624  memDC.Clear();
625  memDC.SetUserScale( scale, scale );
626 
627  // Get logical page size and margins.
628  PAGE_INFO pageDUMMY;
629 
630  // Get page type
631  int idx = m_paperSizeComboBox->GetSelection();
632 
633  if( idx < 0 )
634  idx = 0;
635 
636  wxString pageFmtName = m_pageFmt[idx].BeforeFirst( ' ' );
637  bool portrait = clamped_layout_size.x < clamped_layout_size.y;
638  pageDUMMY.SetType( pageFmtName, portrait );
639  if( m_customFmt )
640  {
641  pageDUMMY.SetWidthMils( clamped_layout_size.x );
642  pageDUMMY.SetHeightMils( clamped_layout_size.y );
643  }
644 
645  // Draw layout preview.
646  KIGFX::DS_RENDER_SETTINGS renderSettings;
647  COLOR_SETTINGS* colorSettings = m_parent->GetColorSettings();
648  COLOR4D bgColor = m_parent->GetDrawBgColor();
649  wxString emptyString;
650 
652  {
653  GRResetPenAndBrush( &memDC );
654  renderSettings.SetDefaultPenWidth( 1 );
655  renderSettings.LoadColors( colorSettings );
656  renderSettings.SetPrintDC( &memDC );
657 
658  if( m_parent->IsType( FRAME_SCH )
662  {
664  renderSettings.SetLayerColor( LAYER_DRAWINGSHEET, color );
665  }
666 
667  GRFilledRect( NULL, &memDC, 0, 0, m_layout_size.x, m_layout_size.y, bgColor, bgColor );
668 
669  PrintDrawingSheet( &renderSettings, pageDUMMY, emptyString, emptyString, m_tb,
671  wxEmptyString, m_screen->GetVirtualPageNumber() == 1 );
672 
673  memDC.SelectObject( wxNullBitmap );
675  }
677 
678  // Refresh the dialog.
679  Layout();
680  Refresh();
681  }
682 }
683 
684 
686 {
687  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
688  const wxString paperType = m_pageFmt[idx];
689 
690  // here we assume translators will keep original paper size spellings
691  if( paperType.Contains( PAGE_INFO::Custom ) )
692  {
694 
695  if( m_layout_size.x && m_layout_size.y )
696  {
697  if( m_layout_size.x < m_layout_size.y )
698  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
699  else
700  m_orientationComboBox->SetStringSelection( _( "Landscape" ) );
701  }
702  }
703  else
704  {
705  PAGE_INFO pageInfo; // SetType() later to lookup size
706 
707  static const wxChar* papers[] = {
708  // longest common string first, since sequential search below
715  PAGE_INFO::A,
716  PAGE_INFO::B,
717  PAGE_INFO::C,
718  PAGE_INFO::D,
719  PAGE_INFO::E,
723  };
724 
725  unsigned i;
726 
727  for( i=0; i < arrayDim( papers ); ++i )
728  {
729  if( paperType.Contains( papers[i] ) )
730  {
731  pageInfo.SetType( papers[i] );
732  break;
733  }
734  }
735 
736  wxASSERT( i != arrayDim(papers) ); // dialog UI match the above list?
737 
738  m_layout_size = pageInfo.GetSizeMils();
739 
740  // swap sizes to match orientation
741  bool isPortrait = (bool) m_orientationComboBox->GetSelection();
742 
743  if( ( isPortrait && m_layout_size.x >= m_layout_size.y ) ||
744  ( !isPortrait && m_layout_size.x < m_layout_size.y ) )
745  {
747  }
748  }
749 }
750 
751 
753 {
754  double customSizeX = (double) m_customSizeX.GetValue() / m_iuPerMils;
755  double customSizeY = (double) m_customSizeY.GetValue() / m_iuPerMils;
756 
757  // Prepare to painless double -> int conversion.
758  customSizeX = Clamp( double( INT_MIN ), customSizeX, double( INT_MAX ) );
759  customSizeY = Clamp( double( INT_MIN ), customSizeY, double( INT_MAX ) );
760  m_layout_size = wxSize( KiROUND( customSizeX ), KiROUND( customSizeY ) );
761 }
762 
763 
764 void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
765 {
766  wxFileName fn = GetWksFileName();
767  wxString name = GetWksFileName();
768  wxString path;
769 
770  if( fn.IsAbsolute() )
771  {
772  path = fn.GetPath();
773  name = fn.GetFullName();
774  }
775  else
776  {
778  }
779 
780  // Display a file picker dialog
781  wxFileDialog fileDialog( this, _( "Select Drawing Sheet File" ),
783  wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
784 
785  if( fileDialog.ShowModal() != wxID_OK )
786  return;
787 
788  wxString fileName = fileDialog.GetPath();
789 
790  // Try to remove the path, if the path is the current working dir,
791  // or the dir of kicad.pro (template), and use a relative path
792  wxString shortFileName = DS_DATA_MODEL::MakeShortFileName( fileName, m_projectPath );
793 
794  // For Win/Linux/macOS compatibility, a relative path is a good idea
795  if( shortFileName != GetWksFileName() && shortFileName != fileName )
796  {
797  wxString msg = wxString::Format( _( "The drawing sheet file name has changed.\n"
798  "Do you want to use the relative path:\n"
799  "\"%s\"\n"
800  "instead of\n"
801  "\"%s\"?" ),
802  shortFileName,
803  fileName );
804 
805  if( !IsOK( this, msg ) )
806  shortFileName = fileName;
807  }
808 
809  std::unique_ptr<DS_DATA_MODEL> ws = std::make_unique<DS_DATA_MODEL>();
810 
811  if( ws->LoadDrawingSheet( fileName ) )
812  {
813  if( m_drawingSheet != nullptr )
814  {
815  delete m_drawingSheet;
816  }
817 
818  m_drawingSheet = ws.release();
819 
820  SetWksFileName( shortFileName );
821 
824  }
825 }
void OnDateApplyClick(wxCommandEvent &event) override
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)=0
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:118
virtual void onTransferDataToWindow()
static const wxChar A[]
Definition: page_info.h:68
Handle the graphic items list to draw/plot the frame and title block.
Definition: ds_data_model.h:38
void OnComment5TextUpdated(wxCommandEvent &event) override
wxSize m_maxPageSizeMils
Logical drawing sheet size.
virtual const TITLE_BLOCK & GetTitleBlock() const =0
static int GetCustomHeightMils()
Definition: page_info.h:165
static void SetAltInstance(DS_DATA_MODEL *aLayout=NULL)
Set an alternate instance of DS_DATA_MODEL.
void OnPageOrientationChoice(wxCommandEvent &event) override
This file is part of the common library.
virtual void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)=0
void SetRevision(const wxString &aRevision)
Definition: title_block.h:81
const wxString & GetComment(int aIdx) const
Definition: title_block.h:107
int GetHeightMils() const
Definition: page_info.h:133
static const wxChar E[]
Definition: page_info.h:72
void OnComment3TextUpdated(wxCommandEvent &event) override
static const wxChar GERBER[]
Definition: page_info.h:73
void GRFilledRect(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:882
TITLE_BLOCK m_tb
true if the page selection is custom
int color
Definition: DXF_plotter.cpp:60
static const wxChar A3[]
Definition: page_info.h:64
void OnComment7TextUpdated(wxCommandEvent &event) override
int GetVirtualPageNumber() const
Definition: base_screen.h:75
void SetWksFileName(const wxString &aFilename)
static void SetCustomWidthMils(int aWidthInMils)
Set the width of Custom page in mils for any custom page constructed or made via SetType() after maki...
Definition: page_info.cpp:231
virtual bool TransferDataFromWindow() override
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Set the name of the page type and also the sizes and margins commonly associated with that type name.
Definition: page_info.cpp:119
virtual void SaveProjectSettings()
Save changes to the project settings to the project (.pro) file.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
int GetPageCount() const
Definition: base_screen.h:72
void SetDate(const wxString &aDate)
Set the date field, and defaults to the current time and date.
Definition: title_block.h:71
virtual bool TransferDataToWindow() override
static const char * emptyString
#define PL_EDITOR_FRAME_NAME
void OnUserPageSizeXTextUpdated(wxCommandEvent &event) override
static const wxChar Custom[]
"User" defined page type
Definition: page_info.h:77
const wxString & GetType() const
Definition: page_info.h:94
#define MAX_PAGE_EXAMPLE_SIZE
static const wxChar D[]
Definition: page_info.h:71
const wxString GetWksFileName()
bool m_initialized
list of page sizes (not translated)
The base class for create windows for drawing purpose.
#define MIN_PAGE_SIZE_MILS
Min and max page sizes for clamping, in mils.
Definition: page_info.h:39
wxSize m_layout_size
Temporary bitmap for the drawing sheet example.
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:123
DIALOG_PAGES_SETTINGS(EDA_DRAW_FRAME *aParent, double aIuPerMils, wxSize aMaxUserSizeMils)
This file contains miscellaneous commonly used macros and functions.
const wxString & GetPageNumber() const
Definition: base_screen.cpp:71
Store page-layout-specific render settings.
Definition: ds_painter.h:46
DS_DATA_MODEL * m_drawingSheet
Temporary title block (basic inscriptions).
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:70
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
virtual const PAGE_INFO & GetPageSettings() const =0
void OnComment8TextUpdated(wxCommandEvent &event) override
void OnComment1TextUpdated(wxCommandEvent &event) override
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
static const wxChar USLegal[]
Definition: page_info.h:75
virtual bool onSavePageSettings()
void OnComment9TextUpdated(wxCommandEvent &event) override
static const wxChar B[]
Definition: page_info.h:69
void SetComment(int aIdx, const wxString &aComment)
Definition: title_block.h:101
#define NULL
static const wxChar C[]
Definition: page_info.h:70
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:86
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
const wxString & GetCompany() const
Definition: title_block.h:96
static const wxString MakeShortFileName(const wxString &aFullFileName, const wxString &aProjectPath)
void PrintDrawingSheet(const RENDER_SETTINGS *aSettings, const PAGE_INFO &aPageInfo, const wxString &aFullSheetName, const wxString &aFileName, const TITLE_BLOCK &aTitleBlock, int aSheetCount, const wxString &aPageNumber, double aMils2Iu, const PROJECT *aProject, const wxString &aSheetLayer, bool aIsFirstPage)
Print the border and title block.
void SetCompany(const wxString &aCompany)
Definition: title_block.h:91
Definition of file extensions used in Kicad.
#define _(s)
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Change the color used to draw a layer.
static const wxChar A4[]
Definition: page_info.h:63
const wxSize & GetSizeMils() const
Definition: page_info.h:135
void OnDateTextUpdated(wxCommandEvent &event) override
void SetCurrentPageSizeSelection(const wxString &aPaperSize)
void SetTitle(const wxString &aTitle)
Definition: title_block.h:58
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:257
wxBitmap * m_pageBitmap
the page layuout filename was changed
static const wxChar USLedger[]
Definition: page_info.h:76
void OnWksFileSelection(wxCommandEvent &event) override
Class DIALOG_PAGES_SETTINGS_BASE.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void SetContentModified(bool aModified=true)
Definition: base_screen.h:59
static const wxChar A1[]
Definition: page_info.h:66
const wxString & GetDate() const
Definition: title_block.h:76
void OnComment6TextUpdated(wxCommandEvent &event) override
void SetPageLayout(const char *aPageLayout, bool aAppend=false, const wxString &aSource=wxT("Sexpr_string"))
Populate the list from a S expr description stored in a string.
static const wxChar USLetter[]
Definition: page_info.h:74
virtual void OnPageSettingsChange()
Called when modifying the page settings.
PAGE_INFO m_pageInfo
The max page size allowed by the caller frame.
const int scale
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Validate the control against the given range, informing the user of any errors found.
void OnComment4TextUpdated(wxCommandEvent &event) override
void OnUserPageSizeYTextUpdated(wxCommandEvent &event) override
bool IsType(FRAME_T aType) const
const char * name
Definition: DXF_plotter.cpp:59
bool IsPortrait() const
Definition: page_info.h:117
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition: base_screen.h:85
static const wxString pageFmts[]
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
static const wxString MakeFullFileName(const wxString &aShortFileName, const wxString &aProjectPath)
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:243
static const wxChar A5[]
Definition: page_info.h:62
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:70
bool LoadDrawingSheet(const wxString &aFullFileName=wxEmptyString, bool Append=false)
Populates the list with a custom layout or the default layout if no custom layout is available.
const T & Clamp(const T &lower, const T &value, const T &upper)
Function Clamp limits value within the range lower <= value <= upper.
Definition: util.h:49
static int GetCustomWidthMils()
Definition: page_info.h:160
void SaveInString(wxString *aOutputString)
Save the description in a buffer.
virtual long long int GetValue()
Return the current value in Internal Units.
bool m_customFmt
Temporary page info.
Color settings are a bit different than most of the settings objects in that there can be more than o...
static const wxChar A2[]
Definition: page_info.h:65
const wxString & GetTitle() const
Definition: title_block.h:63
virtual COLOR4D GetDrawBgColor() const
wxString DrawingSheetFileWildcard()
void OnComment2TextUpdated(wxCommandEvent &event) override
void OnPaperSizeChoice(wxCommandEvent &event) override
drawingsheet frame and titleblock
virtual COLOR_SETTINGS * GetColorSettings() const
Returns a pointer to the active color theme settings.
void OnTitleTextUpdated(wxCommandEvent &event) override
void OnCompanyTextUpdated(wxCommandEvent &event) override
void OnRevisionTextUpdated(wxCommandEvent &event) override
void SetDefaultPenWidth(int aWidth)
BASE_SCREEN class implementation.
#define _HKI(x)
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
Definition: page_info.cpp:186
void LoadColors(const COLOR_SETTINGS *aSettings) override
Definition: ds_painter.cpp:57
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:296
void SetPrintDC(wxDC *aDC)
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
static void SetCustomHeightMils(int aHeightInMils)
Set the height of Custom page in mils for any custom page constructed or made via SetType() after mak...
Definition: page_info.cpp:237
int GetWidthMils() const
Definition: page_info.h:130
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
static const wxChar A0[]
Definition: page_info.h:67