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>
45#include <wx/valgen.h>
46#include <wx/tokenzr.h>
47#include <wx/filedlg.h>
48#include <wx/dcmemory.h>
49#include <wx/msgdlg.h>
50#include <confirm.h>
51#include <kiplatform/ui.h>
52#include <env_vars.h>
53
54#define MAX_PAGE_EXAMPLE_SIZE 200
55
56
58 double aIuPerMils, const VECTOR2D& aMaxUserSizeMils ) :
60 m_parent( aParent ),
61 m_screen( m_parent->GetScreen() ),
62 m_initialized( false ),
63 m_pageBitmap( nullptr ),
64 m_iuPerMils( aIuPerMils ),
65 m_embeddedFiles( aEmbeddedFiles ),
68{
71
72 m_maxPageSizeMils = aMaxUserSizeMils;
73 m_tb = m_parent->GetTitleBlock();
74 m_customFmt = false;
76
78 wxString serialization;
80 m_drawingSheet->SetPageLayout( TO_UTF8( serialization ) );
81
82 m_PickDate->SetValue( wxDateTime::Now() );
83
84 if( m_parent->GetName() == PL_EDITOR_FRAME_NAME )
85 {
86 SetTitle( _( "Preview Settings" ) );
87 m_staticTextPaper->SetLabel( _( "Preview Paper" ) );
88 m_staticTextTitleBlock->SetLabel( _( "Preview Title Block Data" ) );
89 }
90 else
91 {
92 SetTitle( _( "Page Settings" ) );
93 m_staticTextPaper->SetLabel( _( "Paper" ) );
94 m_staticTextTitleBlock->SetLabel( _( "Title Block" ) );
95 }
96
98 m_filenameResolver->SetProject( &Prj() );
99 m_filenameResolver->SetProgramBase( &Pgm() );
100
102
103 Centre();
104}
105
106
112
113
115{
116 // initialize page format choice box and page format list.
117 // The first shows translated strings, the second contains not translated strings
118 m_paperSizeComboBox->Clear();
119
120 int selectedIdx = -1;
121 m_pageInfo = m_parent->GetPageSettings();
122
123 for( const PAGE_INFO& pageFmt : PAGE_INFO::GetPageFormatsList() )
124 {
125 int idx = m_paperSizeComboBox->Append( wxGetTranslation( pageFmt.GetPageFormatDescription() ),
126 reinterpret_cast<void*>( static_cast<intptr_t>( pageFmt.GetType() ) ) );
127
128 if( pageFmt.GetType() == m_pageInfo.GetType() )
129 {
130 selectedIdx = idx;
131 }
132 }
133
134 m_paperSizeComboBox->SetSelection( selectedIdx );
135
136 // initialize the drawing sheet filename
138
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 {
147 m_customSizeX.SetDoubleValue( m_pageInfo.GetWidthMils() * m_iuPerMils );
148 m_customSizeY.SetDoubleValue( m_pageInfo.GetHeightMils() * m_iuPerMils );
149 }
150 else
151 {
152 m_customSizeX.SetDoubleValue( m_pageInfo.GetCustomWidthMils() * m_iuPerMils );
153 m_customSizeY.SetDoubleValue( m_pageInfo.GetCustomHeightMils() * m_iuPerMils );
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 m_initialized = true;
196
197 return true;
198}
199
200
202{
203 int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
204 void* clientData = m_paperSizeComboBox->GetClientData( idx );
205 PAGE_SIZE_TYPE pageType = static_cast<PAGE_SIZE_TYPE>( reinterpret_cast<intptr_t>( clientData ) );
206
207 if( pageType == PAGE_SIZE_TYPE::User )
208 {
210 return false;
211
213 return false;
214 }
215
216 if( SavePageSettings() )
217 {
218 m_screen->SetContentModified();
219
221 m_parent->OnModify();
222
223 // Call the post processing (if any) after changes
224 m_parent->OnPageSettingsChange();
225 }
226
227 return true;
228}
229
230
231void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
232{
233 int idx = m_paperSizeComboBox->GetSelection();
234
235 if( idx < 0 )
236 idx = 0;
237
238 void* clientData = m_paperSizeComboBox->GetClientData( idx );
239 PAGE_SIZE_TYPE pageType = static_cast<PAGE_SIZE_TYPE>( reinterpret_cast<intptr_t>( clientData ) );
240
241 if( pageType == PAGE_SIZE_TYPE::User )
242 {
243 m_staticTextOrient->Enable( false );
244 m_orientationComboBox->Enable( false );
245
246 m_staticTextCustSize->Enable( true );
247 m_customSizeX.Enable( true );
248 m_customSizeY.Enable( true );
249 m_customFmt = true;
250 }
251 else
252 {
253 m_staticTextOrient->Enable( true );
254 m_orientationComboBox->Enable( true );
255
256 m_staticTextCustSize->Enable( false );
257 m_customSizeX.Enable( false );
258 m_customSizeY.Enable( false );
259 m_customFmt = false;
260 }
261
264}
265
266
268{
269 if( m_initialized )
270 {
273 }
274}
275
276
278{
279 if( m_initialized )
280 {
283 }
284}
285
286
288{
289 if( m_initialized )
290 {
293 }
294}
295
296
298{
299 if( m_initialized && m_TextRevision->IsModified() )
300 {
302 m_tb.SetRevision( m_TextRevision->GetValue() );
304 }
305}
306
307
308void DIALOG_PAGES_SETTINGS::OnDateTextUpdated( wxCommandEvent& event )
309{
310 if( m_initialized && m_TextDate->IsModified() )
311 {
313 m_tb.SetDate( m_TextDate->GetValue() );
315 }
316}
317
318
319void DIALOG_PAGES_SETTINGS::OnTitleTextUpdated( wxCommandEvent& event )
320{
321 if( m_initialized && m_TextTitle->IsModified() )
322 {
324 m_tb.SetTitle( m_TextTitle->GetValue() );
326 }
327}
328
329
331{
332 if( m_initialized && m_TextCompany->IsModified() )
333 {
335 m_tb.SetCompany( m_TextCompany->GetValue() );
337 }
338}
339
340
342{
343 if( m_initialized && m_TextComment1->IsModified() )
344 {
346 m_tb.SetComment( 0, m_TextComment1->GetValue() );
348 }
349}
350
351
353{
354 if( m_initialized && m_TextComment2->IsModified() )
355 {
357 m_tb.SetComment( 1, m_TextComment2->GetValue() );
359 }
360}
361
362
364{
365 if( m_initialized && m_TextComment3->IsModified() )
366 {
368 m_tb.SetComment( 2, m_TextComment3->GetValue() );
370 }
371}
372
373
375{
376 if( m_initialized && m_TextComment4->IsModified() )
377 {
379 m_tb.SetComment( 3, m_TextComment4->GetValue() );
381 }
382}
383
384
386{
387 if( m_initialized && m_TextComment5->IsModified() )
388 {
390 m_tb.SetComment( 4, m_TextComment5->GetValue() );
392 }
393}
394
395
397{
398 if( m_initialized && m_TextComment6->IsModified() )
399 {
401 m_tb.SetComment( 5, m_TextComment6->GetValue() );
403 }
404}
405
406
408{
409 if( m_initialized && m_TextComment7->IsModified() )
410 {
412 m_tb.SetComment( 6, m_TextComment7->GetValue() );
414 }
415}
416
417
419{
420 if( m_initialized && m_TextComment8->IsModified() )
421 {
423 m_tb.SetComment( 7, m_TextComment8->GetValue() );
425 }
426}
427
428
430{
431 if( m_initialized && m_TextComment9->IsModified() )
432 {
434 m_tb.SetComment( 8, m_TextComment9->GetValue() );
436 }
437}
438
439
440void DIALOG_PAGES_SETTINGS::OnDateApplyClick( wxCommandEvent& event )
441{
442 wxDateTime datetime = m_PickDate->GetValue();
443
444 wxString date =
445 // We can choose different formats. Should probably be kept in sync with CURRENT_DATE
446 // formatting in TITLE_BLOCK.
447 //
448 // datetime.Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
449 // datetime.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
450 // datetime.Format( wxT("%Y-%b-%d") );
451 datetime.FormatISODate();
452
453 m_TextDate->SetValue( date );
454}
455
456
458{
459 bool success = false;
460 wxString msg;
461 wxString fileName = GetWksFileName();
462
463 wxString fullFileName = m_filenameResolver->ResolvePath( fileName, m_projectPath, { m_embeddedFiles } );
464
466
467 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( fullFileName, &msg ) )
468 DisplayErrorMessage( this, wxString::Format( _( "Error loading drawing sheet '%s'." ), fullFileName ), msg );
469
471
472 int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
473 void* clientData = m_paperSizeComboBox->GetClientData( idx );
474 PAGE_SIZE_TYPE pageType = static_cast<PAGE_SIZE_TYPE>( reinterpret_cast<intptr_t>( clientData ) );
475
476 if( pageType == PAGE_SIZE_TYPE::User )
477 {
479
480 success = m_pageInfo.SetType( PAGE_SIZE_TYPE::User );
481
482 if( success )
483 {
486
487 m_pageInfo.SetWidthMils( m_layout_size.x );
488 m_pageInfo.SetHeightMils( m_layout_size.y );
489 }
490 }
491 else
492 {
493 success = m_pageInfo.SetType( pageType );
494
495 if( success )
496 {
497 int choice = m_orientationComboBox->GetSelection();
498 m_pageInfo.SetPortrait( choice != 0 );
499 }
500 }
501
502 if( !success )
503 {
504 wxFAIL_MSG( "The translation for paper size must preserve original spellings" );
506 }
507
508 m_parent->SetPageSettings( m_pageInfo );
509
510 m_tb.SetRevision( m_TextRevision->GetValue() );
511 m_tb.SetDate( m_TextDate->GetValue() );
512 m_tb.SetCompany( m_TextCompany->GetValue() );
513 m_tb.SetTitle( m_TextTitle->GetValue() );
514 m_tb.SetComment( 0, m_TextComment1->GetValue() );
515 m_tb.SetComment( 1, m_TextComment2->GetValue() );
516 m_tb.SetComment( 2, m_TextComment3->GetValue() );
517 m_tb.SetComment( 3, m_TextComment4->GetValue() );
518 m_tb.SetComment( 4, m_TextComment5->GetValue() );
519 m_tb.SetComment( 5, m_TextComment6->GetValue() );
520 m_tb.SetComment( 6, m_TextComment7->GetValue() );
521 m_tb.SetComment( 7, m_TextComment8->GetValue() );
522 m_tb.SetComment( 8, m_TextComment9->GetValue() );
523
524 m_parent->SetTitleBlock( m_tb );
525
526 // The dialog is being accepted, so it is now safe to drop the embedded worksheets the user
527 // approved removing while switching sheets. Skip the one that ended up selected.
529 {
530 wxString embeddedPrefix = wxString::FromUTF8( FILEEXT::KiCadUriPrefix ) + wxT( "://" );
531 wxString finalEmbeddedName;
532
533 if( fileName.StartsWith( embeddedPrefix ) )
534 finalEmbeddedName = fileName.Mid( embeddedPrefix.length() );
535
536 for( const wxString& name : m_embeddedSheetsToRemove )
537 {
538 if( name != finalEmbeddedName )
539 m_embeddedFiles->RemoveFile( name );
540 }
541
543 }
544
545 return onSavePageSettings();
546}
547
548
550{
551 int lyWidth, lyHeight;
552
553 VECTOR2D clamped_layout_size( std::clamp( m_layout_size.x, (double) MIN_PAGE_SIZE_MILS,
555 std::clamp( m_layout_size.y, (double) MIN_PAGE_SIZE_MILS,
556 m_maxPageSizeMils.y ) );
557
558 double lyRatio = clamped_layout_size.x < clamped_layout_size.y ?
559 (double) clamped_layout_size.y / clamped_layout_size.x :
560 (double) clamped_layout_size.x / clamped_layout_size.y;
561
562 if( clamped_layout_size.x < clamped_layout_size.y )
563 {
564 lyHeight = MAX_PAGE_EXAMPLE_SIZE;
565 lyWidth = KiROUND( (double) lyHeight / lyRatio );
566 }
567 else
568 {
569 lyWidth = MAX_PAGE_EXAMPLE_SIZE;
570 lyHeight = KiROUND( (double) lyWidth / lyRatio );
571 }
572
573 if( m_pageBitmap )
574 {
575 m_PageLayoutExampleBitmap->SetBitmap( wxNullBitmap );
576 delete m_pageBitmap;
577 }
578
579 m_pageBitmap = new wxBitmap( lyWidth + 1, lyHeight + 1 );
580
581 if( m_pageBitmap->IsOk() )
582 {
583 double scaleW = (double) lyWidth / clamped_layout_size.x;
584 double scaleH = (double) lyHeight / clamped_layout_size.y;
585 double scale = std::min( scaleW, scaleH );
586
587 // Prepare DC.
588 wxSize example_size( lyWidth + 1, lyHeight + 1 );
589 wxMemoryDC memDC;
590 memDC.SelectObject( *m_pageBitmap );
591 memDC.SetClippingRegion( wxPoint( 0, 0 ), example_size );
592 memDC.Clear();
593 memDC.SetUserScale( scale, scale );
594
595 // Get logical page size and margins.
596 PAGE_INFO pageDUMMY;
597
598 // Get page type
599 int idx = m_paperSizeComboBox->GetSelection();
600
601 if( idx < 0 )
602 idx = 0;
603
604 void* clientData = m_paperSizeComboBox->GetClientData( idx );
605 PAGE_SIZE_TYPE pageType = static_cast<PAGE_SIZE_TYPE>( reinterpret_cast<intptr_t>( clientData ) );
606
607 bool portrait = clamped_layout_size.x < clamped_layout_size.y;
608 pageDUMMY.SetType( pageType, portrait );
609
610 if( m_customFmt )
611 {
612 pageDUMMY.SetWidthMils( clamped_layout_size.x );
613 pageDUMMY.SetHeightMils( clamped_layout_size.y );
614 }
615
616 // Draw layout preview.
617 KIGFX::DS_RENDER_SETTINGS renderSettings;
618 COLOR_SETTINGS* colorSettings = m_parent->GetColorSettings();
619 COLOR4D bgColor = m_parent->GetDrawBgColor();
620 wxString emptyString;
621
623 {
624 GRResetPenAndBrush( &memDC );
625 renderSettings.SetDefaultPenWidth( 1 );
626 renderSettings.LoadColors( colorSettings );
627 renderSettings.SetPrintDC( &memDC );
628
629 if( m_parent->IsType( FRAME_SCH )
631 || m_parent->IsType( FRAME_SCH_VIEWER ) )
632 {
633 COLOR4D color = renderSettings.GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET );
634 renderSettings.SetLayerColor( LAYER_DRAWINGSHEET, color );
635 }
636
637 GRFilledRect( &memDC, VECTOR2I( 0, 0 ), m_layout_size, 0, bgColor, bgColor );
638
639 PrintDrawingSheet( &renderSettings, pageDUMMY, emptyString, emptyString, emptyString,
640 m_tb, nullptr, m_screen->GetPageCount(), m_screen->GetPageNumber(),
641 1, &Prj(), wxEmptyString, m_screen->GetVirtualPageNumber() == 1 );
642
643 memDC.SelectObject( wxNullBitmap );
645 }
646
648
649 // Refresh the dialog.
650 Layout();
651 Refresh();
652 }
653}
654
655
657{
658 int idx = std::max( m_paperSizeComboBox->GetSelection(), 0 );
659 void* clientData = m_paperSizeComboBox->GetClientData( idx );
660 PAGE_SIZE_TYPE pageType = static_cast<PAGE_SIZE_TYPE>( reinterpret_cast<intptr_t>( clientData ) );
661
662 if( pageType == PAGE_SIZE_TYPE::User )
663 {
665
666 if( m_layout_size.x && m_layout_size.y )
667 {
668 if( m_layout_size.x < m_layout_size.y )
669 m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
670 else
671 m_orientationComboBox->SetStringSelection( _( "Landscape" ) );
672 }
673 }
674 else
675 {
676 PAGE_INFO pageInfo; // SetType() later to lookup size
677
678 pageInfo.SetType( pageType );
679
680 VECTOR2D sz = pageInfo.GetSizeMils();
681 m_layout_size = VECTOR2D( sz.x, sz.y );
682
683 // swap sizes to match orientation
684 bool isPortrait = (bool) m_orientationComboBox->GetSelection();
685
686 if( ( isPortrait && m_layout_size.x >= m_layout_size.y ) ||
687 ( !isPortrait && m_layout_size.x < m_layout_size.y ) )
688 {
689 std::swap( m_layout_size.x, m_layout_size.y );
690 }
691 }
692}
693
694
696{
697 double customSizeX = (double) m_customSizeX.GetDoubleValue() / m_iuPerMils;
698 double customSizeY = (double) m_customSizeY.GetDoubleValue() / m_iuPerMils;
699
700 // Ensure layout size can be converted to int coordinates later
701 customSizeX = std::clamp( customSizeX, double( INT_MIN ), double( INT_MAX ) );
702 customSizeY = std::clamp( customSizeY, double( INT_MIN ), double( INT_MAX ) );
703 m_layout_size = VECTOR2D( customSizeX, customSizeY );
704}
705
706
707void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
708{
709 wxFileName fn = GetWksFileName();
710 wxString name = fn.GetFullName();
711 wxString path = m_projectPath;
712 wxString msg;
713
714 // Check if the current worksheet is embedded so we can offer to remove it later
715 wxString currentWksFileName = GetWksFileName();
716 wxString embeddedPrefix = wxString::FromUTF8( FILEEXT::KiCadUriPrefix ) + wxT( "://" );
717 bool currentIsEmbedded = currentWksFileName.StartsWith( embeddedPrefix );
718 wxString currentEmbeddedName;
719
720 if( currentIsEmbedded )
721 currentEmbeddedName = currentWksFileName.Mid( embeddedPrefix.length() );
722
723 if( fn.IsAbsolute() )
724 {
725 path = fn.GetPath();
726 }
727 else
728 {
729 wxFileName expanded( ExpandEnvVarSubstitutions( GetWksFileName(), &m_parentFrame->Prj() ) );
730 wxFileName inProject( expanded );
731
732 if( expanded.IsAbsolute() )
733 {
734 path = expanded.GetPath();
735 }
736 else if( !m_projectPath.IsEmpty()
737 && inProject.HasName()
738 && inProject.MakeAbsolute( m_projectPath )
739 && inProject.FileExists() )
740 {
741 path = inProject.GetPath();
742 }
743 else
744 {
745 ENV_VAR_MAP_CITER itUser = Pgm().GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" );
746
747 if( itUser != Pgm().GetLocalEnvVariables().end() && itUser->second.GetValue() != wxEmptyString )
748 {
749 wxString resolved = ExpandEnvVarSubstitutions( itUser->second.GetValue(), &m_parentFrame->Prj() );
750
751 if( !resolved.Contains( wxT( "${" ) ) && !resolved.Contains( wxT( "$(" ) ) )
752 {
753 wxFileName resolvedFn;
754 resolvedFn.AssignDir( resolved );
755 resolvedFn.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
756 path = resolvedFn.GetFullPath();
757 }
758 }
759 }
760 }
761
762 // Display a file picker dialog
765 m_embeddedFiles ? &embedHook : nullptr );
766 wxFileDialog fileDialog( this, _( "Drawing Sheet File" ), path, name, FILEEXT::DrawingSheetFileWildcard(),
767 wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
768
769 if( !m_projectPath.IsEmpty() )
770 fileDialog.SetCustomizeHook( relativeHook );
771 else if( m_embeddedFiles )
772 fileDialog.SetCustomizeHook( embedHook );
773
775
776 if( fileDialog.ShowModal() != wxID_OK )
777 return;
778
779 wxString fileName = fileDialog.GetPath();
780 wxString shortFileName;
781 wxString newEmbeddedName;
782
783 if( m_embeddedFiles && embedHook.GetEmbed() )
784 {
785 fn.Assign( fileName );
787 shortFileName = result->GetLink();
788 newEmbeddedName = result->name;
789 fileName = m_embeddedFiles->GetTemporaryFileName( result->name ).GetFullPath();
790
791 // Re-embedding a file that was queued for removal cancels that removal
792 m_embeddedSheetsToRemove.erase( newEmbeddedName );
793 }
794 else
795 {
796 shortFileName = NormalizePathForProject( fileName, &Pgm().GetLocalEnvVariables(), m_projectPath,
797 !m_projectPath.IsEmpty() && relativeHook.GetUseRelativePath() );
798 }
799
800 std::unique_ptr<DS_DATA_MODEL> ws = std::make_unique<DS_DATA_MODEL>();
801
802 if( !ws->LoadDrawingSheet( fileName, &msg ) )
803 {
805 wxString::Format( _( "Error loading drawing sheet '%s'.\n%s" ),
806 fileName ),
807 msg );
808 return;
809 }
810
811 // Now that the new sheet has loaded, offer to remove the previously embedded worksheet
812 // if we are switching to a different file. The removal is deferred until the dialog is
813 // accepted so that cancelling does not orphan the still-referenced worksheet.
814 if( m_embeddedFiles && currentIsEmbedded && !currentEmbeddedName.IsEmpty()
815 && currentEmbeddedName != newEmbeddedName )
816 {
817 if( IsOK( this, wxString::Format(
818 _( "Remove the previously embedded drawing sheet file '%s'?" ),
819 currentEmbeddedName ) ) )
820 {
821 m_embeddedSheetsToRemove.insert( currentEmbeddedName );
822 }
823 }
824
825 delete m_drawingSheet;
826
827 m_drawingSheet = ws.release();
828
829 SetWksFileName( shortFileName );
830
833}
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:982
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.
Add a sticky "Use relative path" checkbox to a file dialog.
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:145
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:276
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject, bool aAllowEscapes)
Replace any environment variable & text variable references with their values.
Definition common.cpp:777
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 NormalizePathForProject(const wxString &aPath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath, bool aAllowParentDirs)
Choose how to store a path the user picked for a project.
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:392
static const std::string KiCadUriPrefix
static wxString DrawingSheetFileWildcard()
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition idf_helpers.h:37
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:524
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:640
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
std::string path
VECTOR2I end
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().
Definition wx_filename.h:35