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 <env_paths.h>
21 #include <pgm_base.h>
22 #include <bitmaps.h>
23 #include <base_screen.h>
24 #include <confirm.h>
25 #include <core/arraydim.h>
27 #include <eda_draw_frame.h>
28 #include <eda_item.h>
29 #include <gr_basic.h>
30 #include <kiface_base.h>
31 #include <macros.h>
32 #include <math/util.h> // for KiROUND, Clamp
33 #include <project.h>
34 #include <title_block.h>
35 #include <tool/actions.h>
36 #include <tool/tool_manager.h>
40 #include <wx/valgen.h>
41 #include <wx/tokenzr.h>
42 #include <wx/filedlg.h>
43 #include <wx/dcmemory.h>
44 
45 #define MAX_PAGE_EXAMPLE_SIZE 200
46 
47 
48 // List of page formats.
49 // they are prefixed by "_HKI" (already in use for hotkeys) instead of "_",
50 // because we need both the translated and the not translated version.
51 // when displayed in dialog we should explicitly call wxGetTranslation()
52 // to show the translated version.
53 // See hotkeys_basic.h for more info
54 #define _HKI( x ) wxT( x )
55 static const wxString pageFmts[] =
56 {
57  _HKI("A5 148x210mm"),
58  _HKI("A4 210x297mm"),
59  _HKI("A3 297x420mm"),
60  _HKI("A2 420x594mm"),
61  _HKI("A1 594x841mm"),
62  _HKI("A0 841x1189mm"),
63  _HKI("A 8.5x11in"),
64  _HKI("B 11x17in"),
65  _HKI("C 17x22in"),
66  _HKI("D 22x34in"),
67  _HKI("E 34x44in"),
68  _HKI("USLetter 8.5x11in"), // USLetter without space is correct
69  _HKI("USLegal 8.5x14in"), // USLegal without space is correct
70  _HKI("USLedger 11x17in"), // USLedger without space is correct
71  _HKI("User (Custom)"), // size defined by user. The string must contain "Custom"
72  // to be recognized in code
73 };
74 
76  const wxSize& aMaxUserSizeMils ) :
77  DIALOG_PAGES_SETTINGS_BASE( aParent ),
78  m_parent( aParent ),
79  m_screen( m_parent->GetScreen() ),
80  m_initialized( false ),
81  m_pageBitmap( nullptr ),
82  m_iuPerMils( aIuPerMils ),
83  m_customSizeX( aParent, m_userSizeXLabel, m_userSizeXCtrl, m_userSizeXUnits ),
84  m_customSizeY( aParent, m_userSizeYLabel, m_userSizeYCtrl, m_userSizeYUnits )
85 {
88 
89  m_maxPageSizeMils = aMaxUserSizeMils;
91  m_customFmt = false;
93 
95  wxString serialization;
96  DS_DATA_MODEL::GetTheInstance().SaveInString( &serialization );
97  m_drawingSheet->SetPageLayout( TO_UTF8( serialization ) );
98 
99  m_PickDate->SetValue( wxDateTime::Now() );
100 
101  if( m_parent->GetName() == PL_EDITOR_FRAME_NAME )
102  {
103  SetTitle( _( "Preview Settings" ) );
104  m_staticTextPaper->SetLabel( _( "Preview Paper" ) );
105  m_staticTextTitleBlock->SetLabel( _( "Preview Title Block Data" ) );
106  }
107  else
108  {
109  SetTitle( _( "Page Settings" ) );
110  m_staticTextPaper->SetLabel( _( "Paper" ) );
111  m_staticTextTitleBlock->SetLabel( _( "Title Block" ) );
112  }
113 
114  Centre();
115 }
116 
117 
119 {
120  delete m_pageBitmap;
121  delete m_drawingSheet;
122 }
123 
124 
126 {
127  wxString msg;
128 
129  // initialize page format choice box and page format list.
130  // The first shows translated strings, the second contains not translated strings
131  m_paperSizeComboBox->Clear();
132 
133  for( const wxString& pageFmt : pageFmts )
134  {
135  m_pageFmt.Add( pageFmt );
136  m_paperSizeComboBox->Append( wxGetTranslation( pageFmt ) );
137  }
138 
139  // initialize the drawing sheet filename
141 
144  m_orientationComboBox->SetSelection( m_pageInfo.IsPortrait() );
145 
146  // only a click fires the "selection changed" event, so have to fabricate this check
147  wxCommandEvent dummy;
149 
150  if( m_customFmt )
151  {
154  }
155  else
156  {
159  }
160 
161  m_TextRevision->SetValue( m_tb.GetRevision() );
162  m_TextDate->SetValue( m_tb.GetDate() );
163  m_TextTitle->SetValue( m_tb.GetTitle() );
164  m_TextCompany->SetValue( m_tb.GetCompany() );
165  m_TextComment1->SetValue( m_tb.GetComment( 0 ) );
166  m_TextComment2->SetValue( m_tb.GetComment( 1 ) );
167  m_TextComment3->SetValue( m_tb.GetComment( 2 ) );
168  m_TextComment4->SetValue( m_tb.GetComment( 3 ) );
169  m_TextComment5->SetValue( m_tb.GetComment( 4 ) );
170  m_TextComment6->SetValue( m_tb.GetComment( 5 ) );
171  m_TextComment7->SetValue( m_tb.GetComment( 6 ) );
172  m_TextComment8->SetValue( m_tb.GetComment( 7 ) );
173  m_TextComment9->SetValue( m_tb.GetComment( 8 ) );
174 
175  // The default is to disable aall these fields for the "generic" dialog
176  m_TextSheetCount->Show( false );
177  m_TextSheetNumber->Show( false );
178  m_PaperExport->Show( false );
179  m_RevisionExport->Show( false );
180  m_DateExport->Show( false );
181  m_TitleExport->Show( false );
182  m_CompanyExport->Show( false );
183  m_Comment1Export->Show( false );
184  m_Comment2Export->Show( false );
185  m_Comment3Export->Show( false );
186  m_Comment4Export->Show( false );
187  m_Comment5Export->Show( false );
188  m_Comment6Export->Show( false );
189  m_Comment7Export->Show( false );
190  m_Comment8Export->Show( false );
191  m_Comment9Export->Show( false );
192 
194 
197 
198  GetSizer()->SetSizeHints( this );
199 
200  // Make the OK button the default.
201  m_sdbSizerOK->SetDefault();
202  m_initialized = true;
203 
204  return true;
205 }
206 
207 
209 {
210  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
211  const wxString paperType = m_pageFmt[idx];
212 
213  if( paperType.Contains( PAGE_INFO::Custom ) )
214  {
216  return false;
217 
219  return false;
220  }
221 
222  if( SavePageSettings() )
223  {
225 
226  if( LocalPrjConfigChanged() )
228 
229  // Call the post processing (if any) after changes
231  }
232 
233  return true;
234 }
235 
236 
237 void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
238 {
239  int idx = m_paperSizeComboBox->GetSelection();
240 
241  if( idx < 0 )
242  idx = 0;
243 
244  const wxString paperType = m_pageFmt[idx];
245 
246  if( paperType.Contains( PAGE_INFO::Custom ) )
247  {
248  m_staticTextOrient->Enable( false );
249  m_orientationComboBox->Enable( false );
250 
251  m_staticTextCustSize->Enable( true );
252  m_customSizeX.Enable( true );
253  m_customSizeY.Enable( true );
254  m_customFmt = true;
255  }
256  else
257  {
258  m_staticTextOrient->Enable( true );
259  m_orientationComboBox->Enable( true );
260 
261  m_staticTextCustSize->Enable( false );
262  m_customSizeX.Enable( false );
263  m_customSizeY.Enable( false );
264  m_customFmt = false;
265  }
266 
269 }
270 
271 
273 {
274  if( m_initialized )
275  {
278  }
279 }
280 
281 
283 {
284  if( m_initialized )
285  {
288  }
289 }
290 
291 
293 {
294  if( m_initialized )
295  {
298  }
299 }
300 
301 
302 void DIALOG_PAGES_SETTINGS::OnRevisionTextUpdated( wxCommandEvent& event )
303 {
304  if( m_initialized && m_TextRevision->IsModified() )
305  {
307  m_tb.SetRevision( m_TextRevision->GetValue() );
309  }
310 }
311 
312 
313 void DIALOG_PAGES_SETTINGS::OnDateTextUpdated( wxCommandEvent& event )
314 {
315  if( m_initialized && m_TextDate->IsModified() )
316  {
318  m_tb.SetDate( m_TextDate->GetValue() );
320  }
321 }
322 
323 
324 void DIALOG_PAGES_SETTINGS::OnTitleTextUpdated( wxCommandEvent& event )
325 {
326  if( m_initialized && m_TextTitle->IsModified() )
327  {
329  m_tb.SetTitle( m_TextTitle->GetValue() );
331  }
332 }
333 
334 
335 void DIALOG_PAGES_SETTINGS::OnCompanyTextUpdated( wxCommandEvent& event )
336 {
337  if( m_initialized && m_TextCompany->IsModified() )
338  {
340  m_tb.SetCompany( m_TextCompany->GetValue() );
342  }
343 }
344 
345 
346 void DIALOG_PAGES_SETTINGS::OnComment1TextUpdated( wxCommandEvent& event )
347 {
348  if( m_initialized && m_TextComment1->IsModified() )
349  {
351  m_tb.SetComment( 0, m_TextComment1->GetValue() );
353  }
354 }
355 
356 
357 void DIALOG_PAGES_SETTINGS::OnComment2TextUpdated( wxCommandEvent& event )
358 {
359  if( m_initialized && m_TextComment2->IsModified() )
360  {
362  m_tb.SetComment( 1, m_TextComment2->GetValue() );
364  }
365 }
366 
367 
368 void DIALOG_PAGES_SETTINGS::OnComment3TextUpdated( wxCommandEvent& event )
369 {
370  if( m_initialized && m_TextComment3->IsModified() )
371  {
373  m_tb.SetComment( 2, m_TextComment3->GetValue() );
375  }
376 }
377 
378 
379 void DIALOG_PAGES_SETTINGS::OnComment4TextUpdated( wxCommandEvent& event )
380 {
381  if( m_initialized && m_TextComment4->IsModified() )
382  {
384  m_tb.SetComment( 3, m_TextComment4->GetValue() );
386  }
387 }
388 
389 
390 void DIALOG_PAGES_SETTINGS::OnComment5TextUpdated( wxCommandEvent& event )
391 {
392  if( m_initialized && m_TextComment5->IsModified() )
393  {
395  m_tb.SetComment( 4, m_TextComment5->GetValue() );
397  }
398 }
399 
400 
401 void DIALOG_PAGES_SETTINGS::OnComment6TextUpdated( wxCommandEvent& event )
402 {
403  if( m_initialized && m_TextComment6->IsModified() )
404  {
406  m_tb.SetComment( 5, m_TextComment6->GetValue() );
408  }
409 }
410 
411 
412 void DIALOG_PAGES_SETTINGS::OnComment7TextUpdated( wxCommandEvent& event )
413 {
414  if( m_initialized && m_TextComment7->IsModified() )
415  {
417  m_tb.SetComment( 6, m_TextComment7->GetValue() );
419  }
420 }
421 
422 
423 void DIALOG_PAGES_SETTINGS::OnComment8TextUpdated( wxCommandEvent& event )
424 {
425  if( m_initialized && m_TextComment8->IsModified() )
426  {
428  m_tb.SetComment( 7, m_TextComment8->GetValue() );
430  }
431 }
432 
433 
434 void DIALOG_PAGES_SETTINGS::OnComment9TextUpdated( wxCommandEvent& event )
435 {
436  if( m_initialized && m_TextComment9->IsModified() )
437  {
439  m_tb.SetComment( 8, m_TextComment9->GetValue() );
441  }
442 }
443 
444 
445 void DIALOG_PAGES_SETTINGS::OnDateApplyClick( wxCommandEvent& event )
446 {
447  wxDateTime datetime = m_PickDate->GetValue();
448  wxString date =
449  // We can choose different formats. Should probably be kept in sync with CURRENT_DATE
450  // formatting in TITLE_BLOCK.
451  //
452  // datetime.Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
453  // datetime.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
454  // datetime.Format( wxT("%Y-%b-%d") );
455  datetime.FormatISODate();
456 
457  m_TextDate->SetValue( date );
458 }
459 
460 
462 {
463  bool success = false;
464 
465  wxString fileName = GetWksFileName();
466 
467  if( fileName != BASE_SCREEN::m_DrawingSheetFileName )
468  {
469  wxString fullFileName = DS_DATA_MODEL::ResolvePath( fileName, m_projectPath );
470 
471  if( !fullFileName.IsEmpty() && !wxFileExists( fullFileName ) )
472  {
473  wxString msg;
474  msg.Printf( _( "Drawing sheet file '%s' not found." ), fullFileName );
475  wxMessageBox( msg );
476  return false;
477  }
478 
482  }
483 
484  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
485  const wxString paperType = m_pageFmt[idx];
486 
487  if( paperType.Contains( PAGE_INFO::Custom ) )
488  {
490 
491  success = m_pageInfo.SetType( PAGE_INFO::Custom );
492 
493  if( success )
494  {
497 
500  }
501  }
502  else
503  {
504  // search for longest common string first, e.g. A4 before A
505  if( paperType.Contains( PAGE_INFO::USLetter ) )
507  else if( paperType.Contains( PAGE_INFO::USLegal ) )
509  else if( paperType.Contains( PAGE_INFO::USLedger ) )
511  else if( paperType.Contains( PAGE_INFO::GERBER ) )
512  success = m_pageInfo.SetType( PAGE_INFO::GERBER );
513  else if( paperType.Contains( PAGE_INFO::A5 ) )
514  success = m_pageInfo.SetType( PAGE_INFO::A5 );
515  else if( paperType.Contains( PAGE_INFO::A4 ) )
516  success = m_pageInfo.SetType( PAGE_INFO::A4 );
517  else if( paperType.Contains( PAGE_INFO::A3 ) )
518  success = m_pageInfo.SetType( PAGE_INFO::A3 );
519  else if( paperType.Contains( PAGE_INFO::A2 ) )
520  success = m_pageInfo.SetType( PAGE_INFO::A2 );
521  else if( paperType.Contains( PAGE_INFO::A1 ) )
522  success = m_pageInfo.SetType( PAGE_INFO::A1 );
523  else if( paperType.Contains( PAGE_INFO::A0 ) )
524  success = m_pageInfo.SetType( PAGE_INFO::A0 );
525  else if( paperType.Contains( PAGE_INFO::A ) )
526  success = m_pageInfo.SetType( PAGE_INFO::A );
527  else if( paperType.Contains( PAGE_INFO::B ) )
528  success = m_pageInfo.SetType( PAGE_INFO::B );
529  else if( paperType.Contains( PAGE_INFO::C ) )
530  success = m_pageInfo.SetType( PAGE_INFO::C );
531  else if( paperType.Contains( PAGE_INFO::D ) )
532  success = m_pageInfo.SetType( PAGE_INFO::D );
533  else if( paperType.Contains( PAGE_INFO::E ) )
534  success = m_pageInfo.SetType( PAGE_INFO::E );
535 
536  if( success )
537  {
538  int choice = m_orientationComboBox->GetSelection();
539  m_pageInfo.SetPortrait( choice != 0 );
540  }
541  }
542 
543  if( !success )
544  {
545  wxASSERT_MSG( false,
546  _( "the translation for paper size must preserve original spellings" ) );
548  }
549 
551 
552  m_tb.SetRevision( m_TextRevision->GetValue() );
553  m_tb.SetDate( m_TextDate->GetValue() );
554  m_tb.SetCompany( m_TextCompany->GetValue() );
555  m_tb.SetTitle( m_TextTitle->GetValue() );
556  m_tb.SetComment( 0, m_TextComment1->GetValue() );
557  m_tb.SetComment( 1, m_TextComment2->GetValue() );
558  m_tb.SetComment( 2, m_TextComment3->GetValue() );
559  m_tb.SetComment( 3, m_TextComment4->GetValue() );
560  m_tb.SetComment( 4, m_TextComment5->GetValue() );
561  m_tb.SetComment( 5, m_TextComment6->GetValue() );
562  m_tb.SetComment( 6, m_TextComment7->GetValue() );
563  m_tb.SetComment( 7, m_TextComment8->GetValue() );
564  m_tb.SetComment( 8, m_TextComment9->GetValue() );
565 
567 
568  return onSavePageSettings();
569 }
570 
571 
572 void DIALOG_PAGES_SETTINGS::SetCurrentPageSizeSelection( const wxString& aPaperSize )
573 {
574  // search all the not translated label list containing our paper type
575  for( unsigned i = 0; i < m_pageFmt.GetCount(); ++i )
576  {
577  // parse each label looking for aPaperSize within it
578  wxStringTokenizer st( m_pageFmt[i] );
579 
580  while( st.HasMoreTokens() )
581  {
582  if( st.GetNextToken() == aPaperSize )
583  {
584  m_paperSizeComboBox->SetSelection( i );
585  return;
586  }
587  }
588  }
589 }
590 
591 
593 {
594  int lyWidth, lyHeight;
595 
596  wxSize clamped_layout_size( Clamp( MIN_PAGE_SIZE_MILS, m_layout_size.x, m_maxPageSizeMils.x ),
598 
599  double lyRatio = clamped_layout_size.x < clamped_layout_size.y ?
600  (double) clamped_layout_size.y / clamped_layout_size.x :
601  (double) clamped_layout_size.x / clamped_layout_size.y;
602 
603  if( clamped_layout_size.x < clamped_layout_size.y )
604  {
605  lyHeight = MAX_PAGE_EXAMPLE_SIZE;
606  lyWidth = KiROUND( (double) lyHeight / lyRatio );
607  }
608  else
609  {
610  lyWidth = MAX_PAGE_EXAMPLE_SIZE;
611  lyHeight = KiROUND( (double) lyWidth / lyRatio );
612  }
613 
614  if( m_pageBitmap )
615  {
616  m_PageLayoutExampleBitmap->SetBitmap( wxNullBitmap );
617  delete m_pageBitmap;
618  }
619 
620  m_pageBitmap = new wxBitmap( lyWidth + 1, lyHeight + 1 );
621 
622  if( m_pageBitmap->IsOk() )
623  {
624  double scaleW = (double) lyWidth / clamped_layout_size.x;
625  double scaleH = (double) lyHeight / clamped_layout_size.y;
626  double scale = std::min( scaleW, scaleH );
627 
628  // Prepare DC.
629  wxSize example_size( lyWidth + 1, lyHeight + 1 );
630  wxMemoryDC memDC;
631  memDC.SelectObject( *m_pageBitmap );
632  memDC.SetClippingRegion( wxPoint( 0, 0 ), example_size );
633  memDC.Clear();
634  memDC.SetUserScale( scale, scale );
635 
636  // Get logical page size and margins.
637  PAGE_INFO pageDUMMY;
638 
639  // Get page type
640  int idx = m_paperSizeComboBox->GetSelection();
641 
642  if( idx < 0 )
643  idx = 0;
644 
645  wxString pageFmtName = m_pageFmt[idx].BeforeFirst( ' ' );
646  bool portrait = clamped_layout_size.x < clamped_layout_size.y;
647  pageDUMMY.SetType( pageFmtName, portrait );
648 
649  if( m_customFmt )
650  {
651  pageDUMMY.SetWidthMils( clamped_layout_size.x );
652  pageDUMMY.SetHeightMils( clamped_layout_size.y );
653  }
654 
655  // Draw layout preview.
656  KIGFX::DS_RENDER_SETTINGS renderSettings;
657  COLOR_SETTINGS* colorSettings = m_parent->GetColorSettings();
658  COLOR4D bgColor = m_parent->GetDrawBgColor();
659  wxString emptyString;
660 
662  {
663  GRResetPenAndBrush( &memDC );
664  renderSettings.SetDefaultPenWidth( 1 );
665  renderSettings.LoadColors( colorSettings );
666  renderSettings.SetPrintDC( &memDC );
667 
668  if( m_parent->IsType( FRAME_SCH )
672  {
674  renderSettings.SetLayerColor( LAYER_DRAWINGSHEET, color );
675  }
676 
677  GRFilledRect( nullptr, &memDC, 0, 0, m_layout_size.x, m_layout_size.y, bgColor,
678  bgColor );
679 
680  PrintDrawingSheet( &renderSettings, pageDUMMY, emptyString, emptyString, m_tb,
682  wxEmptyString, m_screen->GetVirtualPageNumber() == 1 );
683 
684  memDC.SelectObject( wxNullBitmap );
686  }
687 
689 
690  // Refresh the dialog.
691  Layout();
692  Refresh();
693  }
694 }
695 
696 
698 {
699  int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
700  const wxString paperType = m_pageFmt[idx];
701 
702  // here we assume translators will keep original paper size spellings
703  if( paperType.Contains( PAGE_INFO::Custom ) )
704  {
706 
707  if( m_layout_size.x && m_layout_size.y )
708  {
709  if( m_layout_size.x < m_layout_size.y )
710  m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
711  else
712  m_orientationComboBox->SetStringSelection( _( "Landscape" ) );
713  }
714  }
715  else
716  {
717  PAGE_INFO pageInfo; // SetType() later to lookup size
718 
719  static const wxChar* papers[] = {
720  // longest common string first, since sequential search below
727  PAGE_INFO::A,
728  PAGE_INFO::B,
729  PAGE_INFO::C,
730  PAGE_INFO::D,
731  PAGE_INFO::E,
735  };
736 
737  unsigned i;
738 
739  for( i=0; i < arrayDim( papers ); ++i )
740  {
741  if( paperType.Contains( papers[i] ) )
742  {
743  pageInfo.SetType( papers[i] );
744  break;
745  }
746  }
747 
748  wxASSERT( i != arrayDim(papers) ); // dialog UI match the above list?
749 
750  m_layout_size = pageInfo.GetSizeMils();
751 
752  // swap sizes to match orientation
753  bool isPortrait = (bool) m_orientationComboBox->GetSelection();
754 
755  if( ( isPortrait && m_layout_size.x >= m_layout_size.y ) ||
756  ( !isPortrait && m_layout_size.x < m_layout_size.y ) )
757  {
759  }
760  }
761 }
762 
763 
765 {
766  double customSizeX = (double) m_customSizeX.GetValue() / m_iuPerMils;
767  double customSizeY = (double) m_customSizeY.GetValue() / m_iuPerMils;
768 
769  // Prepare to painless double -> int conversion.
770  customSizeX = Clamp( double( INT_MIN ), customSizeX, double( INT_MAX ) );
771  customSizeY = Clamp( double( INT_MIN ), customSizeY, double( INT_MAX ) );
772  m_layout_size = wxSize( KiROUND( customSizeX ), KiROUND( customSizeY ) );
773 }
774 
775 
776 void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
777 {
778  wxFileName fn = GetWksFileName();
779  wxString name = GetWksFileName();
780  wxString path;
781 
782  if( fn.IsAbsolute() )
783  {
784  path = fn.GetPath();
785  name = fn.GetFullName();
786  }
787  else
788  {
790  }
791 
792  // Display a file picker dialog
793  wxFileDialog fileDialog( this, _( "Select Drawing Sheet File" ), path, name,
794  DrawingSheetFileWildcard(), wxFD_DEFAULT_STYLE|wxFD_FILE_MUST_EXIST );
795 
796  if( fileDialog.ShowModal() != wxID_OK )
797  return;
798 
799  wxString fileName = fileDialog.GetPath();
800  wxString shortFileName;
801 
802  // Try to use a project-relative path first:
803  if( !m_projectPath.IsEmpty() && fileName.StartsWith( m_projectPath ) )
804  {
805  fn = wxFileName( fileName );
806  fn.MakeRelativeTo( m_projectPath );
807  shortFileName = fn.GetFullPath();
808  }
809  else
810  {
811  // Failing that see if we can shorten it with env vars:
812  shortFileName = NormalizePath( fileName, &Pgm().GetLocalEnvVariables(), nullptr );
813  }
814 
815  std::unique_ptr<DS_DATA_MODEL> ws = std::make_unique<DS_DATA_MODEL>();
816 
817  if( ws->LoadDrawingSheet( fileName ) )
818  {
819  delete m_drawingSheet;
820 
821  m_drawingSheet = ws.release();
822 
823  SetWksFileName( shortFileName );
824 
827  }
828 }
void OnDateApplyClick(wxCommandEvent &event) override
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)=0
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:107
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:712
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
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
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
static const wxString ResolvePath(const wxString &aPath, const wxString &aProjectPath)
Resolve a path which might be project-relative or contain env variable references.
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
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:224
void OnDateTextUpdated(wxCommandEvent &event) override
void SetCurrentPageSizeSelection(const wxString &aPaperSize)
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
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 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
see class PGM_BASE
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[]
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 void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
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
void SetPrintDC(wxDC *aDC)
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalize a file path to an environmental variable, if possible.
Definition: env_paths.cpp:71
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