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_base.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  const 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 {
205  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
206  const wxString paperType = m_pageFmt[idx];
207 
208  if( paperType.Contains( PAGE_INFO::Custom ) )
209  {
211  return false;
212 
214  return false;
215  }
216 
217  if( SavePageSettings() )
218  {
220 
221  if( LocalPrjConfigChanged() )
223 
224  // Call the post processing (if any) after changes
226  }
227 
228  return true;
229 }
230 
231 
232 void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
233 {
234  int idx = m_paperSizeComboBox->GetSelection();
235 
236  if( idx < 0 )
237  idx = 0;
238 
239  const wxString paperType = m_pageFmt[idx];
240 
241  if( paperType.Contains( PAGE_INFO::Custom ) )
242  {
243  m_orientationComboBox->Enable( false );
244  m_customSizeX.Enable( true );
245  m_customSizeY.Enable( true );
246  m_customFmt = true;
247  }
248  else
249  {
250  m_orientationComboBox->Enable( true );
251 
252 #if 0
253  // ForcePortrait() does not exist, but could be useful.
254  // so I leave these lines, which could be seen as a todo feature
255  if( paperType.ForcePortrait() )
256  {
257  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
258  m_orientationComboBox->Enable( false );
259  }
260 #endif
261  m_customSizeX.Enable( false );
262  m_customSizeY.Enable( false );
263  m_customFmt = false;
264  }
265 
268 }
269 
270 
272 {
273  if( m_initialized )
274  {
277  }
278 }
279 
280 
282 {
283  if( m_initialized )
284  {
287  }
288 }
289 
290 
292 {
293  if( m_initialized )
294  {
297  }
298 }
299 
300 
301 void DIALOG_PAGES_SETTINGS::OnRevisionTextUpdated( wxCommandEvent& event )
302 {
303  if( m_initialized && m_TextRevision->IsModified() )
304  {
306  m_tb.SetRevision( m_TextRevision->GetValue() );
308  }
309 }
310 
311 
312 void DIALOG_PAGES_SETTINGS::OnDateTextUpdated( wxCommandEvent& event )
313 {
314  if( m_initialized && m_TextDate->IsModified() )
315  {
317  m_tb.SetDate( m_TextDate->GetValue() );
319  }
320 }
321 
322 
323 void DIALOG_PAGES_SETTINGS::OnTitleTextUpdated( wxCommandEvent& event )
324 {
325  if( m_initialized && m_TextTitle->IsModified() )
326  {
328  m_tb.SetTitle( m_TextTitle->GetValue() );
330  }
331 }
332 
333 
334 void DIALOG_PAGES_SETTINGS::OnCompanyTextUpdated( wxCommandEvent& event )
335 {
336  if( m_initialized && m_TextCompany->IsModified() )
337  {
339  m_tb.SetCompany( m_TextCompany->GetValue() );
341  }
342 }
343 
344 
345 void DIALOG_PAGES_SETTINGS::OnComment1TextUpdated( wxCommandEvent& event )
346 {
347  if( m_initialized && m_TextComment1->IsModified() )
348  {
350  m_tb.SetComment( 0, m_TextComment1->GetValue() );
352  }
353 }
354 
355 
356 void DIALOG_PAGES_SETTINGS::OnComment2TextUpdated( wxCommandEvent& event )
357 {
358  if( m_initialized && m_TextComment2->IsModified() )
359  {
361  m_tb.SetComment( 1, m_TextComment2->GetValue() );
363  }
364 }
365 
366 
367 void DIALOG_PAGES_SETTINGS::OnComment3TextUpdated( wxCommandEvent& event )
368 {
369  if( m_initialized && m_TextComment3->IsModified() )
370  {
372  m_tb.SetComment( 2, m_TextComment3->GetValue() );
374  }
375 }
376 
377 
378 void DIALOG_PAGES_SETTINGS::OnComment4TextUpdated( wxCommandEvent& event )
379 {
380  if( m_initialized && m_TextComment4->IsModified() )
381  {
383  m_tb.SetComment( 3, m_TextComment4->GetValue() );
385  }
386 }
387 
388 
389 void DIALOG_PAGES_SETTINGS::OnComment5TextUpdated( wxCommandEvent& event )
390 {
391  if( m_initialized && m_TextComment5->IsModified() )
392  {
394  m_tb.SetComment( 4, m_TextComment5->GetValue() );
396  }
397 }
398 
399 
400 void DIALOG_PAGES_SETTINGS::OnComment6TextUpdated( wxCommandEvent& event )
401 {
402  if( m_initialized && m_TextComment6->IsModified() )
403  {
405  m_tb.SetComment( 5, m_TextComment6->GetValue() );
407  }
408 }
409 
410 
411 void DIALOG_PAGES_SETTINGS::OnComment7TextUpdated( wxCommandEvent& event )
412 {
413  if( m_initialized && m_TextComment7->IsModified() )
414  {
416  m_tb.SetComment( 6, m_TextComment7->GetValue() );
418  }
419 }
420 
421 
422 void DIALOG_PAGES_SETTINGS::OnComment8TextUpdated( wxCommandEvent& event )
423 {
424  if( m_initialized && m_TextComment8->IsModified() )
425  {
427  m_tb.SetComment( 7, m_TextComment8->GetValue() );
429  }
430 }
431 
432 
433 void DIALOG_PAGES_SETTINGS::OnComment9TextUpdated( wxCommandEvent& event )
434 {
435  if( m_initialized && m_TextComment9->IsModified() )
436  {
438  m_tb.SetComment( 8, m_TextComment9->GetValue() );
440  }
441 }
442 
443 
444 void DIALOG_PAGES_SETTINGS::OnDateApplyClick( wxCommandEvent& event )
445 {
446  wxDateTime datetime = m_PickDate->GetValue();
447  wxString date =
448  // We can choose different formats. Should probably be kept in sync with CURRENT_DATE
449  // formatting in TITLE_BLOCK.
450  //
451  // datetime.Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
452  // datetime.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
453  // datetime.Format( wxT("%Y-%b-%d") );
454  datetime.FormatISODate();
455 
456  m_TextDate->SetValue( date );
457 }
458 
459 
461 {
462  bool success = false;
463 
464  wxString fileName = GetWksFileName();
465 
466  if( fileName != BASE_SCREEN::m_DrawingSheetFileName )
467  {
468  wxString fullFileName = DS_DATA_MODEL::MakeFullFileName( fileName, m_projectPath );
469 
470  if( !fullFileName.IsEmpty() && !wxFileExists( fullFileName ) )
471  {
472  wxString msg;
473  msg.Printf( _( "Drawing sheet file '%s' not found." ), fullFileName );
474  wxMessageBox( msg );
475  return false;
476  }
477 
481  }
482 
483  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
484  const wxString paperType = m_pageFmt[idx];
485 
486  if( paperType.Contains( PAGE_INFO::Custom ) )
487  {
489 
490  success = m_pageInfo.SetType( PAGE_INFO::Custom );
491 
492  if( success )
493  {
496 
499  }
500  }
501  else
502  {
503  // search for longest common string first, e.g. A4 before A
504  if( paperType.Contains( PAGE_INFO::USLetter ) )
506  else if( paperType.Contains( PAGE_INFO::USLegal ) )
508  else if( paperType.Contains( PAGE_INFO::USLedger ) )
510  else if( paperType.Contains( PAGE_INFO::GERBER ) )
511  success = m_pageInfo.SetType( PAGE_INFO::GERBER );
512  else if( paperType.Contains( PAGE_INFO::A5 ) )
513  success = m_pageInfo.SetType( PAGE_INFO::A5 );
514  else if( paperType.Contains( PAGE_INFO::A4 ) )
515  success = m_pageInfo.SetType( PAGE_INFO::A4 );
516  else if( paperType.Contains( PAGE_INFO::A3 ) )
517  success = m_pageInfo.SetType( PAGE_INFO::A3 );
518  else if( paperType.Contains( PAGE_INFO::A2 ) )
519  success = m_pageInfo.SetType( PAGE_INFO::A2 );
520  else if( paperType.Contains( PAGE_INFO::A1 ) )
521  success = m_pageInfo.SetType( PAGE_INFO::A1 );
522  else if( paperType.Contains( PAGE_INFO::A0 ) )
523  success = m_pageInfo.SetType( PAGE_INFO::A0 );
524  else if( paperType.Contains( PAGE_INFO::A ) )
525  success = m_pageInfo.SetType( PAGE_INFO::A );
526  else if( paperType.Contains( PAGE_INFO::B ) )
527  success = m_pageInfo.SetType( PAGE_INFO::B );
528  else if( paperType.Contains( PAGE_INFO::C ) )
529  success = m_pageInfo.SetType( PAGE_INFO::C );
530  else if( paperType.Contains( PAGE_INFO::D ) )
531  success = m_pageInfo.SetType( PAGE_INFO::D );
532  else if( paperType.Contains( PAGE_INFO::E ) )
533  success = m_pageInfo.SetType( PAGE_INFO::E );
534 
535  if( success )
536  {
537  int choice = m_orientationComboBox->GetSelection();
538  m_pageInfo.SetPortrait( choice != 0 );
539  }
540  }
541 
542  if( !success )
543  {
544  wxASSERT_MSG( false,
545  _( "the translation for paper size must preserve original spellings" ) );
547  }
548 
550 
551  m_tb.SetRevision( m_TextRevision->GetValue() );
552  m_tb.SetDate( m_TextDate->GetValue() );
553  m_tb.SetCompany( m_TextCompany->GetValue() );
554  m_tb.SetTitle( m_TextTitle->GetValue() );
555  m_tb.SetComment( 0, m_TextComment1->GetValue() );
556  m_tb.SetComment( 1, m_TextComment2->GetValue() );
557  m_tb.SetComment( 2, m_TextComment3->GetValue() );
558  m_tb.SetComment( 3, m_TextComment4->GetValue() );
559  m_tb.SetComment( 4, m_TextComment5->GetValue() );
560  m_tb.SetComment( 5, m_TextComment6->GetValue() );
561  m_tb.SetComment( 6, m_TextComment7->GetValue() );
562  m_tb.SetComment( 7, m_TextComment8->GetValue() );
563  m_tb.SetComment( 8, m_TextComment9->GetValue() );
564 
566 
567  return onSavePageSettings();
568 }
569 
570 
571 void DIALOG_PAGES_SETTINGS::SetCurrentPageSizeSelection( const wxString& aPaperSize )
572 {
573  // search all the not translated label list containing our paper type
574  for( unsigned i = 0; i < m_pageFmt.GetCount(); ++i )
575  {
576  // parse each label looking for aPaperSize within it
577  wxStringTokenizer st( m_pageFmt[i] );
578 
579  while( st.HasMoreTokens() )
580  {
581  if( st.GetNextToken() == aPaperSize )
582  {
583  m_paperSizeComboBox->SetSelection( i );
584  return;
585  }
586  }
587  }
588 }
589 
590 
592 {
593  int lyWidth, lyHeight;
594 
595  wxSize clamped_layout_size( Clamp( MIN_PAGE_SIZE_MILS, m_layout_size.x, m_maxPageSizeMils.x ),
597 
598  double lyRatio = clamped_layout_size.x < clamped_layout_size.y ?
599  (double) clamped_layout_size.y / clamped_layout_size.x :
600  (double) clamped_layout_size.x / clamped_layout_size.y;
601 
602  if( clamped_layout_size.x < clamped_layout_size.y )
603  {
604  lyHeight = MAX_PAGE_EXAMPLE_SIZE;
605  lyWidth = KiROUND( (double) lyHeight / lyRatio );
606  }
607  else
608  {
609  lyWidth = MAX_PAGE_EXAMPLE_SIZE;
610  lyHeight = KiROUND( (double) lyWidth / lyRatio );
611  }
612 
613  if( m_pageBitmap )
614  {
615  m_PageLayoutExampleBitmap->SetBitmap( wxNullBitmap );
616  delete m_pageBitmap;
617  }
618 
619  m_pageBitmap = new wxBitmap( lyWidth + 1, lyHeight + 1 );
620 
621  if( m_pageBitmap->IsOk() )
622  {
623  double scaleW = (double) lyWidth / clamped_layout_size.x;
624  double scaleH = (double) lyHeight / clamped_layout_size.y;
625  double scale = std::min( scaleW, scaleH );
626 
627  // Prepare DC.
628  wxSize example_size( lyWidth + 1, lyHeight + 1 );
629  wxMemoryDC memDC;
630  memDC.SelectObject( *m_pageBitmap );
631  memDC.SetClippingRegion( wxPoint( 0, 0 ), example_size );
632  memDC.Clear();
633  memDC.SetUserScale( scale, scale );
634 
635  // Get logical page size and margins.
636  PAGE_INFO pageDUMMY;
637 
638  // Get page type
639  int idx = m_paperSizeComboBox->GetSelection();
640 
641  if( idx < 0 )
642  idx = 0;
643 
644  wxString pageFmtName = m_pageFmt[idx].BeforeFirst( ' ' );
645  bool portrait = clamped_layout_size.x < clamped_layout_size.y;
646  pageDUMMY.SetType( pageFmtName, portrait );
647 
648  if( m_customFmt )
649  {
650  pageDUMMY.SetWidthMils( clamped_layout_size.x );
651  pageDUMMY.SetHeightMils( clamped_layout_size.y );
652  }
653 
654  // Draw layout preview.
655  KIGFX::DS_RENDER_SETTINGS renderSettings;
656  COLOR_SETTINGS* colorSettings = m_parent->GetColorSettings();
657  COLOR4D bgColor = m_parent->GetDrawBgColor();
658  wxString emptyString;
659 
661  {
662  GRResetPenAndBrush( &memDC );
663  renderSettings.SetDefaultPenWidth( 1 );
664  renderSettings.LoadColors( colorSettings );
665  renderSettings.SetPrintDC( &memDC );
666 
667  if( m_parent->IsType( FRAME_SCH )
671  {
673  renderSettings.SetLayerColor( LAYER_DRAWINGSHEET, color );
674  }
675 
676  GRFilledRect( nullptr, &memDC, 0, 0, m_layout_size.x, m_layout_size.y, bgColor,
677  bgColor );
678 
679  PrintDrawingSheet( &renderSettings, pageDUMMY, emptyString, emptyString, m_tb,
681  wxEmptyString, m_screen->GetVirtualPageNumber() == 1 );
682 
683  memDC.SelectObject( wxNullBitmap );
685  }
686 
688 
689  // Refresh the dialog.
690  Layout();
691  Refresh();
692  }
693 }
694 
695 
697 {
698  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
699  const wxString paperType = m_pageFmt[idx];
700 
701  // here we assume translators will keep original paper size spellings
702  if( paperType.Contains( PAGE_INFO::Custom ) )
703  {
705 
706  if( m_layout_size.x && m_layout_size.y )
707  {
708  if( m_layout_size.x < m_layout_size.y )
709  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
710  else
711  m_orientationComboBox->SetStringSelection( _( "Landscape" ) );
712  }
713  }
714  else
715  {
716  PAGE_INFO pageInfo; // SetType() later to lookup size
717 
718  static const wxChar* papers[] = {
719  // longest common string first, since sequential search below
726  PAGE_INFO::A,
727  PAGE_INFO::B,
728  PAGE_INFO::C,
729  PAGE_INFO::D,
730  PAGE_INFO::E,
734  };
735 
736  unsigned i;
737 
738  for( i=0; i < arrayDim( papers ); ++i )
739  {
740  if( paperType.Contains( papers[i] ) )
741  {
742  pageInfo.SetType( papers[i] );
743  break;
744  }
745  }
746 
747  wxASSERT( i != arrayDim(papers) ); // dialog UI match the above list?
748 
749  m_layout_size = pageInfo.GetSizeMils();
750 
751  // swap sizes to match orientation
752  bool isPortrait = (bool) m_orientationComboBox->GetSelection();
753 
754  if( ( isPortrait && m_layout_size.x >= m_layout_size.y ) ||
755  ( !isPortrait && m_layout_size.x < m_layout_size.y ) )
756  {
758  }
759  }
760 }
761 
762 
764 {
765  double customSizeX = (double) m_customSizeX.GetValue() / m_iuPerMils;
766  double customSizeY = (double) m_customSizeY.GetValue() / m_iuPerMils;
767 
768  // Prepare to painless double -> int conversion.
769  customSizeX = Clamp( double( INT_MIN ), customSizeX, double( INT_MAX ) );
770  customSizeY = Clamp( double( INT_MIN ), customSizeY, double( INT_MAX ) );
771  m_layout_size = wxSize( KiROUND( customSizeX ), KiROUND( customSizeY ) );
772 }
773 
774 
775 void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
776 {
777  wxFileName fn = GetWksFileName();
778  wxString name = GetWksFileName();
779  wxString path;
780 
781  if( fn.IsAbsolute() )
782  {
783  path = fn.GetPath();
784  name = fn.GetFullName();
785  }
786  else
787  {
789  }
790 
791  // Display a file picker dialog
792  wxFileDialog fileDialog( this, _( "Select Drawing Sheet File" ),
794  wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
795 
796  if( fileDialog.ShowModal() != wxID_OK )
797  return;
798 
799  wxString fileName = fileDialog.GetPath();
800 
801  // Try to remove the path, if the path is the current working dir,
802  // or the dir of kicad.pro (template), and use a relative path
803  wxString shortFileName = DS_DATA_MODEL::MakeShortFileName( fileName, m_projectPath );
804 
805  // For Win/Linux/macOS compatibility, a relative path is a good idea
806  if( shortFileName != GetWksFileName() && shortFileName != fileName )
807  {
808  wxString msg = wxString::Format( _( "The drawing sheet file name has changed.\n"
809  "Do you want to use the relative path:\n"
810  "\"%s\"\n"
811  "instead of\n"
812  "\"%s\"?" ),
813  shortFileName,
814  fileName );
815 
816  if( !IsOK( this, msg ) )
817  shortFileName = fileName;
818  }
819 
820  std::unique_ptr<DS_DATA_MODEL> ws = std::make_unique<DS_DATA_MODEL>();
821 
822  if( ws->LoadDrawingSheet( fileName ) )
823  {
824  if( m_drawingSheet != nullptr )
825  {
826  delete m_drawingSheet;
827  }
828 
829  m_drawingSheet = ws.release();
830 
831  SetWksFileName( shortFileName );
832 
835  }
836 }
void OnDateApplyClick(wxCommandEvent &event) override
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)=0
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:111
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
void OnPageOrientationChoice(wxCommandEvent &event) override
This file is part of the common library.
void GRFilledRect(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, const COLOR4D &Color, const COLOR4D &BgColor)
Definition: gr_basic.cpp:811
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
TITLE_BLOCK m_tb
true if the page selection is custom
int color
Definition: DXF_plotter.cpp:57
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:122
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:72
#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
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.
static void SetAltInstance(DS_DATA_MODEL *aLayout=nullptr)
Set an alternate instance of DS_DATA_MODEL.
#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
drawingsheet frame and titleblock
Definition: layer_ids.h:212
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:56
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:73
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)
Limit value within the range lower <= value <= upper.
Definition: util.h:52
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
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.
DIALOG_PAGES_SETTINGS(EDA_DRAW_FRAME *aParent, double aIuPerMils, const wxSize &aMaxUserSizeMils)
#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:315
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