KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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
17 * along with this program. If not, see <https://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 <common.h> // ExpandEnvVarSubstitutions
25#include <core/arraydim.h>
27#include <eda_draw_frame.h>
28#include <eda_item.h>
29#include <embedded_files.h>
30#include <filename_resolver.h>
31#include <gr_basic.h>
32#include <kiface_base.h>
33#include <macros.h>
34#include <math/util.h> // for KiROUND
35#include <project.h>
36#include <tool/actions.h>
37#include <tool/tool_manager.h>
41#include <string_utils.h>
44#include <wx/valgen.h>
45#include <wx/tokenzr.h>
46#include <wx/filedlg.h>
47#include <wx/dcmemory.h>
48#include <wx/msgdlg.h>
49#include <confirm.h>
50#include <kiplatform/ui.h>
51#include <env_vars.h>
52
53#define MAX_PAGE_EXAMPLE_SIZE 200
54
55
57 double aIuPerMils, const VECTOR2D& aMaxUserSizeMils ) :
59 m_parent( aParent ),
60 m_screen( m_parent->GetScreen() ),
61 m_initialized( false ),
62 m_pageBitmap( nullptr ),
63 m_iuPerMils( aIuPerMils ),
64 m_embeddedFiles( aEmbeddedFiles ),
67{
70
71 m_maxPageSizeMils = aMaxUserSizeMils;
72 m_tb = m_parent->GetTitleBlock();
73 m_customFmt = false;
75
77 wxString serialization;
79 m_drawingSheet->SetPageLayout( TO_UTF8( serialization ) );
80
81 m_PickDate->SetValue( wxDateTime::Now() );
82
83 if( m_parent->GetName() == PL_EDITOR_FRAME_NAME )
84 {
85 SetTitle( _( "Preview Settings" ) );
86 m_staticTextPaper->SetLabel( _( "Preview Paper" ) );
87 m_staticTextTitleBlock->SetLabel( _( "Preview Title Block Data" ) );
88 }
89 else
90 {
91 SetTitle( _( "Page Settings" ) );
92 m_staticTextPaper->SetLabel( _( "Paper" ) );
93 m_staticTextTitleBlock->SetLabel( _( "Title Block" ) );
94 }
95
97 m_filenameResolver->SetProject( &Prj() );
98 m_filenameResolver->SetProgramBase( &Pgm() );
99
101
102 Centre();
103}
104
105
111
112
114{
115 // initialize page format choice box and page format list.
116 // The first shows translated strings, the second contains not translated strings
117 m_paperSizeComboBox->Clear();
118
119 int selectedIdx = -1;
120 m_pageInfo = m_parent->GetPageSettings();
121
122 for( const PAGE_INFO& pageFmt : PAGE_INFO::GetPageFormatsList() )
123 {
124 int idx = m_paperSizeComboBox->Append( wxGetTranslation( pageFmt.GetPageFormatDescription() ),
125 reinterpret_cast<void*>( static_cast<intptr_t>( pageFmt.GetType() ) ) );
126
127 if( pageFmt.GetType() == m_pageInfo.GetType() )
128 {
129 selectedIdx = idx;
130 }
131 }
132
133 m_paperSizeComboBox->SetSelection( selectedIdx );
134
135 // initialize the drawing sheet filename
137
138 m_orientationComboBox->SetSelection( m_pageInfo.IsPortrait() );
139
140 // only a click fires the "selection changed" event, so have to fabricate this check
141 wxCommandEvent dummy;
143
144 if( m_customFmt )
145 {
146 m_customSizeX.SetDoubleValue( m_pageInfo.GetWidthMils() * m_iuPerMils );
147 m_customSizeY.SetDoubleValue( m_pageInfo.GetHeightMils() * m_iuPerMils );
148 }
149 else
150 {
151 m_customSizeX.SetDoubleValue( m_pageInfo.GetCustomWidthMils() * m_iuPerMils );
152 m_customSizeY.SetDoubleValue( m_pageInfo.GetCustomHeightMils() * m_iuPerMils );
153 }
154
155 m_TextRevision->SetValue( m_tb.GetRevision() );
156 m_TextDate->SetValue( m_tb.GetDate() );
157 m_TextTitle->SetValue( m_tb.GetTitle() );
158 m_TextCompany->SetValue( m_tb.GetCompany() );
159 m_TextComment1->SetValue( m_tb.GetComment( 0 ) );
160 m_TextComment2->SetValue( m_tb.GetComment( 1 ) );
161 m_TextComment3->SetValue( m_tb.GetComment( 2 ) );
162 m_TextComment4->SetValue( m_tb.GetComment( 3 ) );
163 m_TextComment5->SetValue( m_tb.GetComment( 4 ) );
164 m_TextComment6->SetValue( m_tb.GetComment( 5 ) );
165 m_TextComment7->SetValue( m_tb.GetComment( 6 ) );
166 m_TextComment8->SetValue( m_tb.GetComment( 7 ) );
167 m_TextComment9->SetValue( m_tb.GetComment( 8 ) );
168
169 // The default is to disable aall these fields for the "generic" dialog
170 m_TextSheetCount->Show( false );
171 m_TextSheetNumber->Show( false );
172 m_PaperExport->Show( false );
173 m_RevisionExport->Show( false );
174 m_DateExport->Show( false );
175 m_TitleExport->Show( false );
176 m_CompanyExport->Show( false );
177 m_Comment1Export->Show( false );
178 m_Comment2Export->Show( false );
179 m_Comment3Export->Show( false );
180 m_Comment4Export->Show( false );
181 m_Comment5Export->Show( false );
182 m_Comment6Export->Show( false );
183 m_Comment7Export->Show( false );
184 m_Comment8Export->Show( false );
185 m_Comment9Export->Show( false );
186
188
191
192 GetSizer()->SetSizeHints( this );
193
194 m_initialized = true;
195
196 return true;
197}
198
199
201{
202 int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
203 void* clientData = m_paperSizeComboBox->GetClientData( idx );
204 PAGE_SIZE_TYPE pageType = static_cast<PAGE_SIZE_TYPE>( reinterpret_cast<intptr_t>( clientData ) );
205
206 if( pageType == PAGE_SIZE_TYPE::User )
207 {
209 return false;
210
212 return false;
213 }
214
215 if( SavePageSettings() )
216 {
217 m_screen->SetContentModified();
218
220 m_parent->OnModify();
221
222 // Call the post processing (if any) after changes
223 m_parent->OnPageSettingsChange();
224 }
225
226 return true;
227}
228
229
230void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
231{
232 int idx = m_paperSizeComboBox->GetSelection();
233
234 if( idx < 0 )
235 idx = 0;
236
237 void* clientData = m_paperSizeComboBox->GetClientData( idx );
238 PAGE_SIZE_TYPE pageType = static_cast<PAGE_SIZE_TYPE>( reinterpret_cast<intptr_t>( clientData ) );
239
240 if( pageType == PAGE_SIZE_TYPE::User )
241 {
242 m_staticTextOrient->Enable( false );
243 m_orientationComboBox->Enable( false );
244
245 m_staticTextCustSize->Enable( true );
246 m_customSizeX.Enable( true );
247 m_customSizeY.Enable( true );
248 m_customFmt = true;
249 }
250 else
251 {
252 m_staticTextOrient->Enable( true );
253 m_orientationComboBox->Enable( true );
254
255 m_staticTextCustSize->Enable( false );
256 m_customSizeX.Enable( false );
257 m_customSizeY.Enable( false );
258 m_customFmt = false;
259 }
260
263}
264
265
267{
268 if( m_initialized )
269 {
272 }
273}
274
275
277{
278 if( m_initialized )
279 {
282 }
283}
284
285
287{
288 if( m_initialized )
289 {
292 }
293}
294
295
297{
298 if( m_initialized && m_TextRevision->IsModified() )
299 {
301 m_tb.SetRevision( m_TextRevision->GetValue() );
303 }
304}
305
306
307void DIALOG_PAGES_SETTINGS::OnDateTextUpdated( wxCommandEvent& event )
308{
309 if( m_initialized && m_TextDate->IsModified() )
310 {
312 m_tb.SetDate( m_TextDate->GetValue() );
314 }
315}
316
317
318void DIALOG_PAGES_SETTINGS::OnTitleTextUpdated( wxCommandEvent& event )
319{
320 if( m_initialized && m_TextTitle->IsModified() )
321 {
323 m_tb.SetTitle( m_TextTitle->GetValue() );
325 }
326}
327
328
330{
331 if( m_initialized && m_TextCompany->IsModified() )
332 {
334 m_tb.SetCompany( m_TextCompany->GetValue() );
336 }
337}
338
339
341{
342 if( m_initialized && m_TextComment1->IsModified() )
343 {
345 m_tb.SetComment( 0, m_TextComment1->GetValue() );
347 }
348}
349
350
352{
353 if( m_initialized && m_TextComment2->IsModified() )
354 {
356 m_tb.SetComment( 1, m_TextComment2->GetValue() );
358 }
359}
360
361
363{
364 if( m_initialized && m_TextComment3->IsModified() )
365 {
367 m_tb.SetComment( 2, m_TextComment3->GetValue() );
369 }
370}
371
372
374{
375 if( m_initialized && m_TextComment4->IsModified() )
376 {
378 m_tb.SetComment( 3, m_TextComment4->GetValue() );
380 }
381}
382
383
385{
386 if( m_initialized && m_TextComment5->IsModified() )
387 {
389 m_tb.SetComment( 4, m_TextComment5->GetValue() );
391 }
392}
393
394
396{
397 if( m_initialized && m_TextComment6->IsModified() )
398 {
400 m_tb.SetComment( 5, m_TextComment6->GetValue() );
402 }
403}
404
405
407{
408 if( m_initialized && m_TextComment7->IsModified() )
409 {
411 m_tb.SetComment( 6, m_TextComment7->GetValue() );
413 }
414}
415
416
418{
419 if( m_initialized && m_TextComment8->IsModified() )
420 {
422 m_tb.SetComment( 7, m_TextComment8->GetValue() );
424 }
425}
426
427
429{
430 if( m_initialized && m_TextComment9->IsModified() )
431 {
433 m_tb.SetComment( 8, m_TextComment9->GetValue() );
435 }
436}
437
438
439void DIALOG_PAGES_SETTINGS::OnDateApplyClick( wxCommandEvent& event )
440{
441 wxDateTime datetime = m_PickDate->GetValue();
442 wxString date =
443 // We can choose different formats. Should probably be kept in sync with CURRENT_DATE
444 // formatting in TITLE_BLOCK.
445 //
446 // datetime.Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
447 // datetime.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
448 // datetime.Format( wxT("%Y-%b-%d") );
449 datetime.FormatISODate();
450
451 m_TextDate->SetValue( date );
452}
453
454
456{
457 bool success = false;
458 wxString msg;
459 wxString fileName = GetWksFileName();
460
461 wxString fullFileName = m_filenameResolver->ResolvePath( fileName, m_projectPath, { m_embeddedFiles } );
462
464
465 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( fullFileName, &msg ) )
466 DisplayErrorMessage( this, wxString::Format( _( "Error loading drawing sheet '%s'." ), fullFileName ), msg );
467
469
470 int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
471 void* clientData = m_paperSizeComboBox->GetClientData( idx );
472 PAGE_SIZE_TYPE pageType = static_cast<PAGE_SIZE_TYPE>( reinterpret_cast<intptr_t>( clientData ) );
473
474 if( pageType == PAGE_SIZE_TYPE::User )
475 {
477
478 success = m_pageInfo.SetType( PAGE_SIZE_TYPE::User );
479
480 if( success )
481 {
484
485 m_pageInfo.SetWidthMils( m_layout_size.x );
486 m_pageInfo.SetHeightMils( m_layout_size.y );
487 }
488 }
489 else
490 {
491 success = m_pageInfo.SetType( pageType );
492
493 if( success )
494 {
495 int choice = m_orientationComboBox->GetSelection();
496 m_pageInfo.SetPortrait( choice != 0 );
497 }
498 }
499
500 if( !success )
501 {
502 wxFAIL_MSG( "The translation for paper size must preserve original spellings" );
504 }
505
506 m_parent->SetPageSettings( m_pageInfo );
507
508 m_tb.SetRevision( m_TextRevision->GetValue() );
509 m_tb.SetDate( m_TextDate->GetValue() );
510 m_tb.SetCompany( m_TextCompany->GetValue() );
511 m_tb.SetTitle( m_TextTitle->GetValue() );
512 m_tb.SetComment( 0, m_TextComment1->GetValue() );
513 m_tb.SetComment( 1, m_TextComment2->GetValue() );
514 m_tb.SetComment( 2, m_TextComment3->GetValue() );
515 m_tb.SetComment( 3, m_TextComment4->GetValue() );
516 m_tb.SetComment( 4, m_TextComment5->GetValue() );
517 m_tb.SetComment( 5, m_TextComment6->GetValue() );
518 m_tb.SetComment( 6, m_TextComment7->GetValue() );
519 m_tb.SetComment( 7, m_TextComment8->GetValue() );
520 m_tb.SetComment( 8, m_TextComment9->GetValue() );
521
522 m_parent->SetTitleBlock( m_tb );
523
524 // The dialog is being accepted, so it is now safe to drop the embedded worksheets the user
525 // approved removing while switching sheets. Skip the one that ended up selected.
527 {
528 wxString embeddedPrefix = wxString::FromUTF8( FILEEXT::KiCadUriPrefix ) + wxT( "://" );
529 wxString finalEmbeddedName;
530
531 if( fileName.StartsWith( embeddedPrefix ) )
532 finalEmbeddedName = fileName.Mid( embeddedPrefix.length() );
533
534 for( const wxString& name : m_embeddedSheetsToRemove )
535 {
536 if( name != finalEmbeddedName )
537 m_embeddedFiles->RemoveFile( name );
538 }
539
541 }
542
543 return onSavePageSettings();
544}
545
546
548{
549 int lyWidth, lyHeight;
550
551 VECTOR2D clamped_layout_size( std::clamp( m_layout_size.x, (double) MIN_PAGE_SIZE_MILS,
553 std::clamp( m_layout_size.y, (double) MIN_PAGE_SIZE_MILS,
554 m_maxPageSizeMils.y ) );
555
556 double lyRatio = clamped_layout_size.x < clamped_layout_size.y ?
557 (double) clamped_layout_size.y / clamped_layout_size.x :
558 (double) clamped_layout_size.x / clamped_layout_size.y;
559
560 if( clamped_layout_size.x < clamped_layout_size.y )
561 {
562 lyHeight = MAX_PAGE_EXAMPLE_SIZE;
563 lyWidth = KiROUND( (double) lyHeight / lyRatio );
564 }
565 else
566 {
567 lyWidth = MAX_PAGE_EXAMPLE_SIZE;
568 lyHeight = KiROUND( (double) lyWidth / lyRatio );
569 }
570
571 if( m_pageBitmap )
572 {
573 m_PageLayoutExampleBitmap->SetBitmap( wxNullBitmap );
574 delete m_pageBitmap;
575 }
576
577 m_pageBitmap = new wxBitmap( lyWidth + 1, lyHeight + 1 );
578
579 if( m_pageBitmap->IsOk() )
580 {
581 double scaleW = (double) lyWidth / clamped_layout_size.x;
582 double scaleH = (double) lyHeight / clamped_layout_size.y;
583 double scale = std::min( scaleW, scaleH );
584
585 // Prepare DC.
586 wxSize example_size( lyWidth + 1, lyHeight + 1 );
587 wxMemoryDC memDC;
588 memDC.SelectObject( *m_pageBitmap );
589 memDC.SetClippingRegion( wxPoint( 0, 0 ), example_size );
590 memDC.Clear();
591 memDC.SetUserScale( scale, scale );
592
593 // Get logical page size and margins.
594 PAGE_INFO pageDUMMY;
595
596 // Get page type
597 int idx = m_paperSizeComboBox->GetSelection();
598
599 if( idx < 0 )
600 idx = 0;
601
602 void* clientData = m_paperSizeComboBox->GetClientData( idx );
603 PAGE_SIZE_TYPE pageType = static_cast<PAGE_SIZE_TYPE>( reinterpret_cast<intptr_t>( clientData ) );
604
605 bool portrait = clamped_layout_size.x < clamped_layout_size.y;
606 pageDUMMY.SetType( pageType, portrait );
607
608 if( m_customFmt )
609 {
610 pageDUMMY.SetWidthMils( clamped_layout_size.x );
611 pageDUMMY.SetHeightMils( clamped_layout_size.y );
612 }
613
614 // Draw layout preview.
615 KIGFX::DS_RENDER_SETTINGS renderSettings;
616 COLOR_SETTINGS* colorSettings = m_parent->GetColorSettings();
617 COLOR4D bgColor = m_parent->GetDrawBgColor();
618 wxString emptyString;
619
621 {
622 GRResetPenAndBrush( &memDC );
623 renderSettings.SetDefaultPenWidth( 1 );
624 renderSettings.LoadColors( colorSettings );
625 renderSettings.SetPrintDC( &memDC );
626
627 if( m_parent->IsType( FRAME_SCH )
629 || m_parent->IsType( FRAME_SCH_VIEWER ) )
630 {
631 COLOR4D color = renderSettings.GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET );
632 renderSettings.SetLayerColor( LAYER_DRAWINGSHEET, color );
633 }
634
635 GRFilledRect( &memDC, VECTOR2I( 0, 0 ), m_layout_size, 0, bgColor, bgColor );
636
637 PrintDrawingSheet( &renderSettings, pageDUMMY, emptyString, emptyString, emptyString,
638 m_tb, nullptr, m_screen->GetPageCount(), m_screen->GetPageNumber(),
639 1, &Prj(), wxEmptyString, m_screen->GetVirtualPageNumber() == 1 );
640
641 memDC.SelectObject( wxNullBitmap );
643 }
644
646
647 // Refresh the dialog.
648 Layout();
649 Refresh();
650 }
651}
652
653
655{
656 int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
657 void* clientData = m_paperSizeComboBox->GetClientData( idx );
658 PAGE_SIZE_TYPE pageType = static_cast<PAGE_SIZE_TYPE>( reinterpret_cast<intptr_t>( clientData ) );
659
660 if( pageType == PAGE_SIZE_TYPE::User )
661 {
663
664 if( m_layout_size.x && m_layout_size.y )
665 {
666 if( m_layout_size.x < m_layout_size.y )
667 m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
668 else
669 m_orientationComboBox->SetStringSelection( _( "Landscape" ) );
670 }
671 }
672 else
673 {
674 PAGE_INFO pageInfo; // SetType() later to lookup size
675
676 pageInfo.SetType( pageType );
677
678 VECTOR2D sz = pageInfo.GetSizeMils();
679 m_layout_size = VECTOR2D( sz.x, sz.y );
680
681 // swap sizes to match orientation
682 bool isPortrait = (bool) m_orientationComboBox->GetSelection();
683
684 if( ( isPortrait && m_layout_size.x >= m_layout_size.y ) ||
685 ( !isPortrait && m_layout_size.x < m_layout_size.y ) )
686 {
687 std::swap( m_layout_size.x, m_layout_size.y );
688 }
689 }
690}
691
692
694{
695 double customSizeX = (double) m_customSizeX.GetDoubleValue() / m_iuPerMils;
696 double customSizeY = (double) m_customSizeY.GetDoubleValue() / m_iuPerMils;
697
698 // Ensure layout size can be converted to int coordinates later
699 customSizeX = std::clamp( customSizeX, double( INT_MIN ), double( INT_MAX ) );
700 customSizeY = std::clamp( customSizeY, double( INT_MIN ), double( INT_MAX ) );
701 m_layout_size = VECTOR2D( customSizeX, customSizeY );
702}
703
704
705void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
706{
707 wxFileName fn = GetWksFileName();
708 wxString name = fn.GetFullName();
709 wxString path = m_projectPath;
710 wxString msg;
711
712 // Check if the current worksheet is embedded so we can offer to remove it later
713 wxString currentWksFileName = GetWksFileName();
714 wxString embeddedPrefix = wxString::FromUTF8( FILEEXT::KiCadUriPrefix ) + wxT( "://" );
715 bool currentIsEmbedded = currentWksFileName.StartsWith( embeddedPrefix );
716 wxString currentEmbeddedName;
717
718 if( currentIsEmbedded )
719 currentEmbeddedName = currentWksFileName.Mid( embeddedPrefix.length() );
720
721 if( fn.IsAbsolute() )
722 {
723 path = fn.GetPath();
724 }
725 else
726 {
727 wxFileName expanded( ExpandEnvVarSubstitutions( GetWksFileName(), &m_parentFrame->Prj() ) );
728
729 if( expanded.IsAbsolute() )
730 {
731 path = expanded.GetPath();
732 }
733 else
734 {
735 ENV_VAR_MAP_CITER itUser = Pgm().GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" );
736 if( itUser != Pgm().GetLocalEnvVariables().end() && itUser->second.GetValue() != wxEmptyString )
737 {
738 wxString resolved = ExpandEnvVarSubstitutions( itUser->second.GetValue(), &m_parentFrame->Prj() );
739 if( !resolved.Contains( wxT( "${" ) ) && !resolved.Contains( wxT( "$(" ) ) )
740 {
741 wxFileName resolvedFn;
742 resolvedFn.AssignDir( resolved );
743 resolvedFn.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
744 path = resolvedFn.GetFullPath();
745 }
746 }
747 }
748 }
749
750 // Display a file picker dialog
752 wxFileDialog fileDialog( this, _( "Drawing Sheet File" ), path, name, FILEEXT::DrawingSheetFileWildcard(),
753 wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
754
755 if( m_embeddedFiles )
756 fileDialog.SetCustomizeHook( customize );
757
759
760 if( fileDialog.ShowModal() != wxID_OK )
761 return;
762
763 wxString fileName = fileDialog.GetPath();
764 wxString shortFileName;
765 wxString newEmbeddedName;
766
767 if( m_embeddedFiles && customize.GetEmbed() )
768 {
769 fn.Assign( fileName );
771 shortFileName = result->GetLink();
772 newEmbeddedName = result->name;
773 fileName = m_embeddedFiles->GetTemporaryFileName( result->name ).GetFullPath();
774
775 // Re-embedding a file that was queued for removal cancels that removal
776 m_embeddedSheetsToRemove.erase( newEmbeddedName );
777 }
778 else if( !m_projectPath.IsEmpty() && fileName.StartsWith( m_projectPath ) )
779 {
780 // Try to use a project-relative path
781 fn = wxFileName( fileName );
782 fn.MakeRelativeTo( m_projectPath );
783 shortFileName = fn.GetFullPath();
784 }
785 else
786 {
787 // Failing that see if we can shorten it with env vars:
788 shortFileName = NormalizePath( fileName, &Pgm().GetLocalEnvVariables(), nullptr );
789 }
790
791 std::unique_ptr<DS_DATA_MODEL> ws = std::make_unique<DS_DATA_MODEL>();
792
793 if( !ws->LoadDrawingSheet( fileName, &msg ) )
794 {
796 wxString::Format( _( "Error loading drawing sheet '%s'.\n%s" ),
797 fileName ),
798 msg );
799 return;
800 }
801
802 // Now that the new sheet has loaded, offer to remove the previously embedded worksheet
803 // if we are switching to a different file. The removal is deferred until the dialog is
804 // accepted so that cancelling does not orphan the still-referenced worksheet.
805 if( m_embeddedFiles && currentIsEmbedded && !currentEmbeddedName.IsEmpty()
806 && currentEmbeddedName != newEmbeddedName )
807 {
808 if( IsOK( this, wxString::Format(
809 _( "Remove the previously embedded drawing sheet file '%s'?" ),
810 currentEmbeddedName ) ) )
811 {
812 m_embeddedSheetsToRemove.insert( currentEmbeddedName );
813 }
814 }
815
816 delete m_drawingSheet;
817
818 m_drawingSheet = ws.release();
819
820 SetWksFileName( shortFileName );
821
824}
const char * name
BASE_SCREEN class implementation.
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:986
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition base_screen.h:81
Color settings are a bit different than most of the settings objects in that there can be more than o...
DIALOG_PAGES_SETTINGS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Page Settings"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
std::set< wxString > m_embeddedSheetsToRemove
void OnComment4TextUpdated(wxCommandEvent &event) override
void OnPageOrientationChoice(wxCommandEvent &event) override
void OnUserPageSizeYTextUpdated(wxCommandEvent &event) override
PAGE_INFO m_pageInfo
The max page size allowed by the caller frame.
FILENAME_RESOLVER * m_filenameResolver
DS_DATA_MODEL * m_drawingSheet
Temporary title block (basic inscriptions).
DIALOG_PAGES_SETTINGS(EDA_DRAW_FRAME *aParent, EMBEDDED_FILES *aEmbeddedFiles, double aIuPerMils, const VECTOR2D &aMaxUserSizeMils)
void OnRevisionTextUpdated(wxCommandEvent &event) override
const wxString GetWksFileName()
void OnComment6TextUpdated(wxCommandEvent &event) override
void OnDateApplyClick(wxCommandEvent &event) override
TITLE_BLOCK m_tb
true if the page selection is custom
void OnDateTextUpdated(wxCommandEvent &event) override
VECTOR2D m_layout_size
Temporary bitmap for the drawing sheet example.
void OnComment3TextUpdated(wxCommandEvent &event) override
void OnCompanyTextUpdated(wxCommandEvent &event) override
void OnUserPageSizeXTextUpdated(wxCommandEvent &event) override
void OnComment7TextUpdated(wxCommandEvent &event) override
EMBEDDED_FILES * m_embeddedFiles
void OnPaperSizeChoice(wxCommandEvent &event) override
virtual bool onSavePageSettings()
virtual void onTransferDataToWindow()
void OnComment5TextUpdated(wxCommandEvent &event) override
void OnComment9TextUpdated(wxCommandEvent &event) override
void OnComment1TextUpdated(wxCommandEvent &event) override
void OnComment8TextUpdated(wxCommandEvent &event) override
void OnWksFileSelection(wxCommandEvent &event) override
VECTOR2D m_maxPageSizeMils
Logical drawing sheet size.
virtual bool TransferDataToWindow() override
virtual bool TransferDataFromWindow() override
void SetWksFileName(const wxString &aFilename)
bool m_customFmt
Temporary page info.
void OnComment2TextUpdated(wxCommandEvent &event) override
wxBitmap * m_pageBitmap
the page layuout filename was changed
void OnTitleTextUpdated(wxCommandEvent &event) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
EDA_BASE_FRAME * m_parentFrame
Handle the graphic items list to draw/plot the frame and title block.
static DS_DATA_MODEL & GetTheInstance()
Return the instance of DS_DATA_MODEL used in the application.
void SaveInString(wxString *aOutputString)
Save the description in a buffer.
static void SetAltInstance(DS_DATA_MODEL *aLayout=nullptr)
Set an alternate instance of DS_DATA_MODEL.
The base class for create windows for drawing purpose.
Provide an extensible class to resolve 3D model paths.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Store page-layout-specific render settings.
Definition ds_painter.h:42
void LoadColors(const COLOR_SETTINGS *aSettings) override
void SetDefaultPenWidth(int aWidth)
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Change the color used to draw a layer.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
void SetPrintDC(wxDC *aDC)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:75
bool SetType(PAGE_SIZE_TYPE aPageSize, bool aIsPortrait=false)
Set the name of the page type and also the sizes and margins commonly associated with that type name.
static void SetCustomWidthMils(double aWidthInMils)
Set the width of Custom page in mils for any custom page constructed or made via SetType() after maki...
void SetHeightMils(double aHeightInMils)
static const std::vector< PAGE_INFO > & GetPageFormatsList()
const VECTOR2D & GetSizeMils() const
Definition page_info.h:146
void SetWidthMils(double aWidthInMils)
static void SetCustomHeightMils(double aHeightInMils)
Set the height of Custom page in mils for any custom page constructed or made via SetType() after mak...
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition pgm_base.cpp:808
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:183
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition common.cpp:721
The common library.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition confirm.cpp:274
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
This file is part of the common library.
#define MAX_PAGE_EXAMPLE_SIZE
#define _(s)
void PrintDrawingSheet(const RENDER_SETTINGS *aSettings, const PAGE_INFO &aPageInfo, const wxString &aSheetName, const wxString &aSheetPath, const wxString &aFileName, const TITLE_BLOCK &aTitleBlock, const std::map< wxString, wxString > *aProperties, int aSheetCount, const wxString &aPageNumber, double aMils2Iu, const PROJECT *aProject, const wxString &aSheetLayer, bool aIsFirstPage)
Print the border and title block.
#define PL_EDITOR_FRAME_NAME
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:73
Helper functions to substitute paths with environmental variables.
Functions related to environment variables, including help functions.
@ FRAME_SCH_SYMBOL_EDITOR
Definition frame_type.h:31
@ FRAME_SCH_VIEWER
Definition frame_type.h:32
@ FRAME_SCH
Definition frame_type.h:30
void GRResetPenAndBrush(wxDC *DC)
Definition gr_basic.cpp:73
void GRFilledRect(wxDC *DC, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, const COLOR4D &aColor, const COLOR4D &aBgColor)
Definition gr_basic.cpp:404
static const std::string KiCadUriPrefix
static wxString DrawingSheetFileWildcard()
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition layer_ids.h:274
@ LAYER_SCHEMATIC_DRAWINGSHEET
Definition layer_ids.h:502
This file contains miscellaneous commonly used macros and functions.
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:521
PAGE_SIZE_TYPE
Definition page_info.h:46
#define MIN_PAGE_SIZE_MILS
Min and max page sizes for clamping, in mils.
Definition page_info.h:30
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
static const char * emptyString
const int scale
std::vector< FAB_LAYER_COLOR > dummy
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
std::string path
VECTOR2I end
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().
Definition wx_filename.h:35