KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pl_editor_frame.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) 2013 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <kiface_base.h>
27#include <pgm_base.h>
28#include <bitmaps.h>
29#include <core/arraydim.h>
33#include <confirm.h>
34#include <kiplatform/app.h>
36#include <gal/painter.h>
38#include <tool/selection.h>
39#include <tool/action_toolbar.h>
42#include <tool/tool_manager.h>
43#include <tool/common_control.h>
44#include <tool/common_tools.h>
45#include <tool/picker_tool.h>
46#include <tool/zoom_tool.h>
48#include "pl_editor_frame.h"
49#include "pl_editor_id.h"
50#include "pl_editor_settings.h"
51#include "properties_frame.h"
52#include <toolbars_pl_editor.h>
53#include "tools/pl_actions.h"
56#include "tools/pl_edit_tool.h"
60#include <view/view_controls.h>
61
62#include <wx/filedlg.h>
63#include <wx/print.h>
64#include <wx/treebook.h>
65#include <wx/msgdlg.h>
66#include <wx/log.h>
67
69
70
71BEGIN_EVENT_TABLE( PL_EDITOR_FRAME, EDA_DRAW_FRAME )
72 EVT_MENU( wxID_CLOSE, PL_EDITOR_FRAME::OnExit )
73 EVT_MENU( wxID_EXIT, PL_EDITOR_FRAME::OnExit )
74
75 EVT_MENU( wxID_FILE, PL_EDITOR_FRAME::Files_io )
76
79
82
83 // Drop files event
84 EVT_DROP_FILES( PL_EDITOR_FRAME::OnDropFiles )
85END_EVENT_TABLE()
86
87
88PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
89 EDA_DRAW_FRAME( aKiway, aParent, FRAME_PL_EDITOR, wxT( "PlEditorFrame" ), wxDefaultPosition,
92 m_propertiesPagelayout( nullptr ), m_propertiesFrameWidth( 200 ),
93 m_originSelectBox( nullptr ), m_originSelectChoice( 0 ), m_pageSelectBox( nullptr ),
94 m_mruImagePath( wxEmptyString )
95{
96 m_maximizeByDefault = true;
97 SetUserUnits( EDA_UNITS::MM );
98
99 m_showBorderAndTitleBlock = true; // true for reference drawings.
101 m_aboutTitle = _HKI( "KiCad Drawing Sheet Editor" );
102
103 // Give an icon
104 wxIcon icon;
105 wxIconBundle icon_bundle;
106
107 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor, 48 ) );
108 icon_bundle.AddIcon( icon );
109 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor, 128 ) );
110 icon_bundle.AddIcon( icon );
111 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor, 256 ) );
112 icon_bundle.AddIcon( icon );
113 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor_32 ) );
114 icon_bundle.AddIcon( icon );
115 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor_16 ) );
116 icon_bundle.AddIcon( icon );
117
118 SetIcons( icon_bundle );
119
120 // Create GAL canvas
121 auto* drawPanel = new PL_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
122 GetGalDisplayOptions(),
124 SetCanvas( drawPanel );
125
126 LoadSettings( config() );
127
128 m_acceptedExts.emplace( FILEEXT::DrawingSheetFileExtension, nullptr );
129 DragAcceptFiles( true );
130
131 VECTOR2I pageSizeIU = GetPageLayout().GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS );
132 SetScreen( new BASE_SCREEN( pageSizeIU ) );
133
134 setupTools();
135 setupUIConditions();
136 ReCreateMenuBar();
137
138 m_toolbarSettings = GetToolbarSettings<PL_EDITOR_TOOLBAR_SETTINGS>( "pl_editor-toolbars" );
139 configureToolbars();
140 RecreateToolbars();
141
142 wxWindow* stsbar = GetStatusBar();
143 int spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x * 2;
144
145 int dims[] = {
146
147 // balance of status bar on far left is set to a default or whatever is left over.
148 -1,
149
150 // When using GetTextSize() remember the width of '1' is not the same
151 // as the width of '0' unless the font is fixed width, and it usually won't be.
152
153 // zoom:
154 KIUI::GetTextSize( wxT( "Z 762000" ), stsbar ).x + spacer,
155
156 // cursor coords
157 KIUI::GetTextSize( wxT( "X 0234.567 Y 0234.567" ), stsbar ).x + spacer,
158
159 // delta distances
160 KIUI::GetTextSize( wxT( "dx 0234.567 dx 0234.567" ), stsbar ).x + spacer,
161
162 // grid size
163 KIUI::GetTextSize( wxT( "grid 0234.567" ), stsbar ).x + spacer,
164
165 // Coord origin (use the bigger message)
166 KIUI::GetTextSize( _( "coord origin: Right Bottom page corner" ), stsbar ).x + spacer,
167
168 // units display, Inches is bigger than mm
169 KIUI::GetTextSize( _( "Inches" ), stsbar ).x + spacer,
170
171 // constraint mode
172 KIUI::GetTextSize( _( "Constrain to H, V, 45" ), stsbar ).x + spacer
173 };
174
175 SetStatusWidths( arrayDim( dims ), dims );
176
177 m_auimgr.SetManagedWindow( this );
178
179 CreateInfoBar();
180 m_propertiesPagelayout = new PROPERTIES_FRAME( this );
181
182 // Rows; layers 4 - 6
183 m_auimgr.AddPane( m_tbTopMain, EDA_PANE().HToolbar().Name( "TopMainToolbar" )
184 .Top().Layer( 6 ) );
185 m_auimgr.AddPane( m_tbLeft, EDA_PANE().VToolbar().Name( "LeftToolbar" )
186 .Left().Layer( 3 ) );
187 m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
188 .Bottom().Layer( 6 ) );
189
190 // Columns; layers 1 - 3
191 m_auimgr.AddPane( m_tbRight, EDA_PANE().VToolbar().Name( "RightToolbar" )
192 .Right().Layer( 2 ) );
193
194 m_auimgr.AddPane( m_propertiesPagelayout, EDA_PANE().Palette().Name( "Props" )
195 .Right().Layer( 3 )
196 .Caption( _( "Properties" ) )
197 .MinSize( m_propertiesPagelayout->GetMinSize() )
198 .BestSize( m_propertiesFrameWidth, -1 ) );
199
200 // Center
201 m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" )
202 .Center() );
203
204 FinishAUIInitialization();
205
206 resolveCanvasType();
207 SwitchCanvas( m_canvasType );
208
209 // Add the exit key handler
210 setupUnits( config() );
211
212 VECTOR2I originCoord = ReturnCoordOriginCorner();
213 SetGridOrigin( originCoord );
214
215 // Initialize the current drawing sheet
216#if 0 //start with empty layout
219#else // start with the default KiCad layout
220 DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( wxEmptyString, nullptr );
221#endif
222 OnNewDrawingSheet();
223
224 // Ensure the window is on top
225 Raise();
226
227 // Register a call to update the toolbar sizes. It can't be done immediately because
228 // it seems to require some sizes calculated that aren't yet (at least on GTK).
229 CallAfter( [this]()
230 {
231 // Ensure the controls on the toolbars all are correctly sized
232 UpdateToolbarControlSizes();
233 } );
234
235 try
236 {
237 if( !m_spaceMouse )
238 m_spaceMouse = std::make_unique<NL_PL_EDITOR_PLUGIN>();
239 m_spaceMouse->SetCanvas( GetCanvas() );
240 }
241 catch( const std::system_error& e )
242 {
243 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), e.what() );
244 }
245}
246
247
249{
250 // Ensure m_canvasType is up to date, to save it in config
252
253 // Shutdown all running tools
254 if( m_toolManager )
256}
257
258
260{
261 // Create the manager and dispatcher & route draw panel events to the dispatcher
263 m_toolManager->SetEnvironment( nullptr, GetCanvas()->GetView(),
264 GetCanvas()->GetViewControls(), config(), this );
265 m_actions = new PL_ACTIONS();
267
269
270 // Register tools
281
282 // Run the selection tool, it is supposed to be always active
283 m_toolManager->InvokeTool( "common.InteractiveSelection" );
284}
285
286
288{
290
292 EDITOR_CONDITIONS cond( this );
293
294 wxASSERT( mgr );
295
296#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
297#define CHECK( x ) ACTION_CONDITIONS().Check( x )
298
302
305 mgr->SetConditions( ACTIONS::millimetersUnits, CHECK( cond.Units( EDA_UNITS::MM ) ) );
306 mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCH ) ) );
307 mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) );
308
313
320
329
330 // Not a tool, just a way to activate the action
333
334 auto titleBlockNormalMode =
335 [] ( const SELECTION& )
336 {
338 };
339
340 auto titleBlockEditMode =
341 [] ( const SELECTION& )
342 {
344 };
345
346 mgr->SetConditions( PL_ACTIONS::layoutNormalMode, CHECK( titleBlockNormalMode ) );
347 mgr->SetConditions( PL_ACTIONS::layoutEditMode, CHECK( titleBlockEditMode ) );
348
349#undef CHECK
350#undef ENABLE
351}
352
353
354bool PL_EDITOR_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
355{
356 wxString fn = aFileSet[0];
357
358 if( !LoadDrawingSheetFile( fn ) )
359 {
360 wxMessageBox( wxString::Format( _( "Error loading drawing sheet '%s'." ), fn ) );
361 return false;
362 }
363 else
364 {
366 return true;
367 }
368}
369
370
372{
373 // Must be called after a change in order to set the "modify" flag and update
374 // the frame title.
376
378
379 if( m_isClosing )
380 return;
381
383}
384
385
387{
388 return GetScreen() && GetScreen()->IsContentModified();
389}
390
391
392void PL_EDITOR_FRAME::OnExit( wxCommandEvent& aEvent )
393{
394 if( aEvent.GetId() == wxID_EXIT )
395 Kiway().OnKiCadExit();
396
397 if( aEvent.GetId() == wxID_CLOSE || Kiface().IsSingle() )
398 Close( false );
399}
400
401
402bool PL_EDITOR_FRAME::canCloseWindow( wxCloseEvent& aEvent )
403{
404 // Shutdown blocks must be determined and vetoed as early as possible
406 && aEvent.GetId() == wxEVT_QUERY_END_SESSION
407 && IsContentModified() )
408 {
409 return false;
410 }
411
412 if( IsContentModified() )
413 {
414 wxFileName filename = GetCurrentFileName();
415 wxString msg = _( "Save changes to '%s' before closing?" );
416
417 if( !HandleUnsavedChanges( this, wxString::Format( msg, filename.GetFullName() ),
418 [&]() -> bool
419 {
420 return saveCurrentPageLayout();
421 } ) )
422 {
423 return false;
424 }
425 }
426
427 return true;
428}
429
430
432{
433 // do not show the window because we do not want any paint event
434 Show( false );
435
436 // clean up the data before the view is destroyed
438
439 // On Linux, m_propertiesPagelayout must be destroyed
440 // before deleting the main frame to avoid a crash when closing
441 m_propertiesPagelayout->Destroy();
442 Destroy();
443}
444
445
446void PL_EDITOR_FRAME::OnSelectPage( wxCommandEvent& event )
447{
448 KIGFX::VIEW* view = GetCanvas()->GetView();
449 view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGE1, m_pageSelectBox->GetSelection() == 0 );
450 view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGEn, m_pageSelectBox->GetSelection() == 1 );
451 GetCanvas()->Refresh();
452}
453
454
456{
457 m_originSelectChoice = m_originSelectBox->GetSelection();
458 UpdateStatusBar(); // Update grid origin
460 GetCanvas()->Refresh();
461}
462
463
464void PL_EDITOR_FRAME::ToPrinter( bool doPreview )
465{
466 // static print data and page setup data, to remember settings during the session
467 static wxPrintData* s_PrintData;
468 static wxPageSetupDialogData* s_pageSetupData = nullptr;
469
470 const PAGE_INFO& pageInfo = GetPageSettings();
471
472 if( s_PrintData == nullptr ) // First print
473 {
474 s_PrintData = new wxPrintData();
475 s_PrintData->SetQuality( wxPRINT_QUALITY_HIGH ); // Default resolution = HIGH;
476 }
477
478 if( !s_PrintData->Ok() )
479 {
480 wxMessageBox( _( "Error Init Printer info" ) );
481 return;
482 }
483
484 if( s_pageSetupData == nullptr )
485 s_pageSetupData = new wxPageSetupDialogData( *s_PrintData );
486
487 s_pageSetupData->SetPaperId( pageInfo.GetPaperId() );
488 s_pageSetupData->GetPrintData().SetOrientation( pageInfo.GetWxOrientation() );
489
490 if( pageInfo.IsCustom() )
491 {
492 if( pageInfo.IsPortrait() )
493 s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ),
494 EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ) ) );
495 else
496 s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ),
497 EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ) ) );
498 }
499
500 *s_PrintData = s_pageSetupData->GetPrintData();
501
502 if( doPreview )
503 InvokeDialogPrintPreview( this, s_PrintData );
504 else
505 InvokeDialogPrint( this, s_PrintData, s_pageSetupData );
506}
507
508
509const BOX2I PL_EDITOR_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
510{
512 return rv;
513}
514
515
517{
519
520 PL_EDITOR_SETTINGS* cfg = dynamic_cast<PL_EDITOR_SETTINGS*>( aCfg );
521 wxCHECK( cfg, /*void*/ );
522
525
527
530
531 PAGE_INFO pageInfo = GetPageSettings();
532 pageInfo.SetType( cfg->m_LastPaperSize, cfg->m_LastWasPortrait );
533 SetPageSettings( pageInfo );
534}
535
536
538{
540
541 auto cfg = static_cast<PL_EDITOR_SETTINGS*>( aCfg );
542
544
545 cfg->m_PropertiesFrameWidth = m_propertiesFrameWidth;
546 cfg->m_CornerOrigin = m_originSelectChoice;
547 cfg->m_BlackBackground = GetDrawBgColor() == BLACK;
548 cfg->m_LastPaperSize = GetPageSettings().GetType();
549 cfg->m_LastWasPortrait = GetPageSettings().IsPortrait();
550 cfg->m_LastCustomWidth = PAGE_INFO::GetCustomWidthMils();
551 cfg->m_LastCustomHeight = PAGE_INFO::GetCustomHeightMils();
552}
553
554
556{
557 wxString title;
558 wxFileName file( GetCurrentFileName() );
559
560 if( IsContentModified() )
561 title = wxT( "*" );
562
563 if( file.IsOk() )
564 title += file.GetName();
565 else
566 title += _( "[no drawing sheet loaded]" );
567
568 title += wxT( " \u2014 " ) + _( "Drawing Sheet Editor" ),
569
570 SetTitle( title );
571}
572
573
575{
577}
578
579
580void PL_EDITOR_FRAME::SetCurrentFileName( const wxString& aName )
581{
583}
584
585
586void PL_EDITOR_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
587{
588 m_pageLayout.SetPageSettings( aPageSettings );
589
590 if( GetScreen() )
592}
593
594
596{
598}
599
600
602{
603 // this function is only needed because EDA_DRAW_FRAME is not compiled
604 // with either -DPCBNEW or -DEESCHEMA, so the virtual is used to route
605 // into an application specific source file.
607}
608
609
611{
612 return GetPageLayout().GetTitleBlock();
613}
614
615
617{
618 m_pageLayout.SetTitleBlock( aTitleBlock );
619}
620
621
623{
625
626 PL_EDITOR_SETTINGS* cfg = GetAppSettings<PL_EDITOR_SETTINGS>( "pl_editor" );
628
629 // Update gal display options like cursor shape, grid options:
631
632 GetCanvas()->GetView()->GetPainter()->GetSettings()->LoadColors( colors );
633
636
638 Layout();
639 SendSizeEvent();
640}
641
642
644{
645 // calculate the position (in page, in iu) of the corner used as coordinate origin
646 // coordinate origin can be the paper Top Left corner, or each of 4 page corners
647 VECTOR2I originCoord;
648
649 // To avoid duplicate code, we use a dummy segment starting at 0,0 in relative coord
651
652 switch( m_originSelectChoice )
653 {
654 default:
655 case 0: // Origin = paper Left Top corner
656 break;
657
658 case 1: // Origin = page Right Bottom corner
659 dummy.SetStart( 0, 0, RB_CORNER );
660 originCoord = dummy.GetStartPosIU();
661 break;
662
663 case 2: // Origin = page Left Bottom corner
664 dummy.SetStart( 0, 0, LB_CORNER );
665 originCoord = dummy.GetStartPosIU();
666 break;
667
668 case 3: // Origin = page Right Top corner
669 dummy.SetStart( 0, 0, RT_CORNER );
670 originCoord = dummy.GetStartPosIU();
671 break;
672
673 case 4: // Origin = page Left Top corner
674 dummy.SetStart( 0, 0, LT_CORNER );
675 originCoord = dummy.GetStartPosIU();
676 break;
677 }
678
679 return originCoord;
680}
681
682
684{
685 wxString line;
686 wxString gridformatter;
687
688 switch( GetUserUnits() )
689 {
690 case EDA_UNITS::INCH: gridformatter = wxS( "grid %.3f" ); break;
691 case EDA_UNITS::MM: gridformatter = wxS( "grid %.4f" ); break;
692 default: gridformatter = wxS( "grid %f" ); break;
693 }
694
696 GetCanvas()->GetGAL()->GetGridSize().x );
697 line.Printf( gridformatter, grid );
698
699 SetStatusText( line, 4 );
700}
701
702
704{
705 // Display Zoom level:
706 SetStatusText( GetZoomLevelIndicator(), 1 );
707
708 // coordinate origin can be the paper Top Left corner, or each of 4 page corners
709 VECTOR2I originCoord = ReturnCoordOriginCorner();
710 SetGridOrigin( originCoord );
711
712 // We need the orientation of axis (sign of coordinates)
713 int Xsign = 1;
714 int Ysign = 1;
715
716 switch( m_originSelectChoice )
717 {
718 default:
719 case 0: // Origin = paper Left Top corner
720 break;
721
722 case 1: // Origin = page Right Bottom corner
723 Xsign = -1;
724 Ysign = -1;
725 break;
726
727 case 2: // Origin = page Left Bottom corner
728 Ysign = -1;
729 break;
730
731 case 3: // Origin = page Right Top corner
732 Xsign = -1;
733 break;
734
735 case 4: // Origin = page Left Top corner
736 break;
737 }
738
739 // Display absolute coordinates:
741 VECTOR2D coord = cursorPos - originCoord;
742 double dXpos =
744 double dYpos =
746
747 wxString absformatter = wxT( "X %.4g Y %.4g" );
748 wxString locformatter = wxT( "dx %.4g dy %.4g" );
749
750 switch( GetUserUnits() )
751 {
752 case EDA_UNITS::INCH: SetStatusText( _( "inches" ), 6 ); break;
753 case EDA_UNITS::MILS: SetStatusText( _( "mils" ), 6 ); break;
754 case EDA_UNITS::MM: SetStatusText( _( "mm" ), 6 ); break;
755 case EDA_UNITS::UNSCALED: SetStatusText( wxEmptyString, 6 ); break;
756 default: wxASSERT( false ); break;
757 }
758
759 wxString line;
760
761 // Display abs coordinates
762 line.Printf( absformatter, dXpos, dYpos );
763 SetStatusText( line, 2 );
764
765 // Display relative coordinates:
766 if( GetScreen() )
767 {
768 double dx = cursorPos.x - GetScreen()->m_LocalOrigin.x;
769 double dy = cursorPos.y - GetScreen()->m_LocalOrigin.y;
772 line.Printf( locformatter, dXpos, dYpos );
773 SetStatusText( line, 3 );
774 }
775
777
778 // Display corner reference for coord origin
779 line.Printf( _("coord origin: %s"),
780 m_originSelectBox->GetString( m_originSelectChoice ).GetData() );
781 SetStatusText( line, 5 );
782}
783
784
786{
787 return static_cast<PL_DRAW_PANEL_GAL*>( EDA_DRAW_FRAME::GetCanvas() );
788}
789
790
792{
793 return m_toolManager->GetTool<PL_SELECTION_TOOL>()->GetSelection();
794}
795
796
798{
800
802 PL_SELECTION& selection = selTool->GetSelection();
803 DS_DATA_ITEM* item = nullptr;
804
805 if( selection.GetSize() == 1 )
806 item = static_cast<DS_DRAW_ITEM_BASE*>( selection.Front() )->GetPeer();
807
811 GetCanvas()->Refresh();
812}
813
814
816{
817 DS_DATA_ITEM * item = nullptr;
818
819 switch( aType )
820 {
822 item = new DS_DATA_ITEM_TEXT( wxT( "Text") );
823 break;
824
827 break;
828
831 break;
832
834 item = new DS_DATA_ITEM_POLYGONS();
835 break;
836
838 {
839 wxFileDialog fileDlg( this, _( "Choose Image" ), m_mruImagePath, wxEmptyString,
840 _( "Image Files" ) + wxS( " " ) + wxImage::GetImageExtWildcard(),
841 wxFD_OPEN );
842
843 if( fileDlg.ShowModal() != wxID_OK )
844 return nullptr;
845
846 wxString fullFilename = fileDlg.GetPath();
847 m_mruImagePath = wxPathOnly( fullFilename );
848
849 if( !wxFileExists( fullFilename ) )
850 {
851 wxMessageBox( _( "Could not load image from '%s'." ), fullFilename );
852 break;
853 }
854
856
857 if( !image->ReadImageFile( fullFilename ) )
858 {
859 wxMessageBox( _( "Could not load image from '%s'." ), fullFilename );
860 delete image;
861 break;
862 }
863
864 // Set the scale factor for pl_editor (it is set for Eeschema by default)
865 image->SetPixelSizeIu( drawSheetIUScale.IU_PER_MILS * 1000.0 / image->GetPPI() );
866 item = new DS_DATA_ITEM_BITMAP( image );
867 }
868 break;
869 }
870
871 if( item == nullptr )
872 return nullptr;
873
875 item->SyncDrawItems( nullptr, GetCanvas()->GetView() );
876
877 return item;
878}
879
880
882{
884 GetScreen()->SetContentModified( false );
886
889
891
893
894 if( GetCurrentFileName().IsEmpty() )
895 {
896 // Default shutdown reason until a file is loaded
897 KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New drawing sheet file is unsaved" ) );
898 }
899 else
900 {
901 KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Drawing sheet changes are unsaved" ) );
902 }
903}
904
905
907{
908 if( aItemCount == 0 )
909 return;
910
911 UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
912
913 if( aItemCount < 0 )
914 {
915 list.ClearCommandList();
916 }
917 else
918 {
919 for( int ii = 0; ii < aItemCount; ii++ )
920 {
921 if( list.m_CommandsList.size() == 0 )
922 break;
923
924 PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
925 list.m_CommandsList.erase( list.m_CommandsList.begin() );
926
927 curr_cmd->ClearListAndDeleteItems( []( EDA_ITEM* aItem )
928 {
929 delete aItem;
930 } );
931 delete curr_cmd; // Delete command
932 }
933 }
934}
935
936
938{
939 return m_pageSelectBox->GetSelection() == 0;
940}
941
942#if 1
944{
946
947 std::vector<MSG_PANEL_ITEM> msgItems;
948 msgItems.emplace_back( _( "Page Width" ), MessageTextFromValue( size.x ) );
949 msgItems.emplace_back( _( "Page Height" ), MessageTextFromValue( size.y ) );
950
951 SetMsgPanel( msgItems );
952}
953#endif
954
955void PL_EDITOR_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
956{
958
959 if( m_spaceMouse )
960 m_spaceMouse->SetFocus( aEvent.GetActive() );
961}
962
963
964void PL_EDITOR_FRAME::handleIconizeEvent( wxIconizeEvent& aEvent )
965{
967
968 if( m_spaceMouse )
969 m_spaceMouse->SetFocus( false );
970}
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
constexpr EDA_IU_SCALE drawSheetIUScale
Definition: base_units.h:113
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
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:104
@ icon_pagelayout_editor
@ icon_pagelayout_editor_16
@ icon_pagelayout_editor_32
static TOOL_ACTION toggleGrid
Definition: actions.h:195
static TOOL_ACTION paste
Definition: actions.h:80
static TOOL_ACTION millimetersUnits
Definition: actions.h:203
static TOOL_ACTION copy
Definition: actions.h:78
static TOOL_ACTION milsUnits
Definition: actions.h:202
static TOOL_ACTION undo
Definition: actions.h:75
static TOOL_ACTION inchesUnits
Definition: actions.h:201
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:151
static TOOL_ACTION doDelete
Definition: actions.h:85
static TOOL_ACTION selectionTool
Definition: actions.h:244
static TOOL_ACTION save
Definition: actions.h:58
static TOOL_ACTION zoomFitScreen
Definition: actions.h:141
static TOOL_ACTION redo
Definition: actions.h:76
static TOOL_ACTION deleteTool
Definition: actions.h:86
static TOOL_ACTION zoomTool
Definition: actions.h:145
static TOOL_ACTION cut
Definition: actions.h:77
Manage TOOL_ACTION objects.
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:108
WINDOW_SETTINGS m_Window
Definition: app_settings.h:234
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:237
Handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:41
bool IsContentModified() const
Definition: base_screen.h:60
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition: base_screen.h:85
VECTOR2D m_LocalOrigin
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:90
void SetContentModified(bool aModified=true)
Definition: base_screen.h:59
void InitDataPoints(const VECTOR2I &aPageSizeInternalUnits)
Definition: base_screen.cpp:46
This class handle bitmap images in KiCad.
Definition: bitmap_base.h:49
Color settings are a bit different than most of the settings objects in that there can be more than o...
Handle actions that are shared between different applications.
Handles action that are shared between different applications.
Definition: common_tools.h:38
Drawing sheet structure type definitions.
Definition: ds_data_item.h:96
virtual void SyncDrawItems(DS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView)
bool LoadDrawingSheet(const wxString &aFullFileName, wxString *aMsg, bool aAppend=false)
Populate the list with a custom layout or the default layout if no custom layout is available.
static DS_DATA_MODEL & GetTheInstance()
Return the instance of DS_DATA_MODEL used in the application.
void Append(DS_DATA_ITEM *aItem)
void AllowVoidList(bool Allow)
In KiCad applications, a drawing sheet is needed So if the list is empty, a default drawing sheet is ...
Definition: ds_data_model.h:83
void ClearList()
Erase the list of items.
Base class to handle basic graphic items.
Definition: ds_draw_item.h:59
virtual APP_SETTINGS_BASE * config() const
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual void handleIconizeEvent(wxIconizeEvent &aEvent)
Handle a window iconize event.
UNDO_REDO_CONTAINER m_undoList
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
UNDO_REDO_LIST
Specify whether we are interacting with the undo or redo stacks.
virtual void OnModify()
Must be called after a model change in order to set the "modify" flag and do other frame-specific pro...
virtual void RecreateToolbars()
UNDO_REDO_CONTAINER m_redoList
virtual void OnDropFiles(wxDropFilesEvent &aEvent)
Handle event fired when a file is dropped to the window.
bool m_isClosing
Set by the close window event handler after frames are asked if they can close.
The base class for create windows for drawing purpose.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
The current canvas type.
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
const wxString GetZoomLevelIndicator() const
Return a human readable value for display in dialogs.
GAL_DISPLAY_OPTIONS_IMPL & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
virtual void handleActivateEvent(wxActivateEvent &aEvent)
Handle a window activation event.
virtual void SetDrawBgColor(const COLOR4D &aColor)
virtual COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const
Returns a pointer to the active color theme settings.
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual COLOR4D GetDrawBgColor() const
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Return a pointer to the #VIEW_CONTROLS instance used in the panel.
virtual KIGFX::VIEW * GetView() const
Return a pointer to the #VIEW instance used in the panel.
void ForceRefresh()
Force a redraw.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
@ GAL_TYPE_NONE
GAL not used (the legacy wxDC engine is used)
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:97
Specialization of the wxAuiPaneInfo class for KiCad panels.
Class that groups generic conditions for editor states.
SELECTION_CONDITION NoActiveTool()
Create a functor testing if there are no tools active in the frame.
SELECTION_CONDITION RedoAvailable()
Create a functor that tests if there are any items in the redo queue.
SELECTION_CONDITION CurrentTool(const TOOL_ACTION &aTool)
Create a functor testing if the specified tool is the current active tool in the frame.
virtual SELECTION_CONDITION UndoAvailable()
Create a functor that tests if there are any items in the undo queue.
SELECTION_CONDITION Units(EDA_UNITS aUnit)
Create a functor that tests if the frame has the specified units.
SELECTION_CONDITION GridVisible()
Create a functor testing if the grid is visible in a frame.
SELECTION_CONDITION FullscreenCursor()
Create a functor testing if the cursor is full screen in a frame.
void ReadWindowSettings(WINDOW_SETTINGS &aCfg)
Read GAL config options from application-level config.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:396
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition: view.cpp:1551
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:216
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:286
void OnKiCadExit()
Definition: kiway.cpp:694
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:59
static void SetCustomWidthMils(double aWidthInMils)
Set the width of Custom page in mils for any custom page constructed or made via SetType() after maki...
Definition: page_info.cpp:236
wxPrintOrientation GetWxOrientation() const
Definition: page_info.h:127
static double GetCustomHeightMils()
Definition: page_info.h:196
const VECTOR2D GetSizeIU(double aIUScale) const
Gets the page size in internal units.
Definition: page_info.h:171
double GetHeightMils() const
Definition: page_info.h:141
wxPaperSize GetPaperId() const
Definition: page_info.h:132
const wxString & GetType() const
Definition: page_info.h:99
double GetWidthMils() const
Definition: page_info.h:136
bool IsCustom() const
Definition: page_info.cpp:183
bool IsPortrait() const
Definition: page_info.h:122
static double GetCustomWidthMils()
Definition: page_info.h:191
static void SetCustomHeightMils(double aHeightInMils)
Set the height of Custom page in mils for any custom page constructed or made via SetType() after mak...
Definition: page_info.cpp:242
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:122
A holder to handle information on schematic or board items.
void ClearListAndDeleteItems(std::function< void(EDA_ITEM *)> aItemDeleter)
Delete the list of pickers AND the data pointed by #m_PickedItem or #m_PickedItemLink according to th...
Gather all the actions that are shared by tools.
Definition: pl_actions.h:36
static TOOL_ACTION placeImage
Definition: pl_actions.h:41
static TOOL_ACTION drawRectangle
Definition: pl_actions.h:42
static TOOL_ACTION layoutNormalMode
Definition: pl_actions.h:49
static TOOL_ACTION placeText
Definition: pl_actions.h:40
static TOOL_ACTION layoutEditMode
Definition: pl_actions.h:50
static TOOL_ACTION appendImportedDrawingSheet
Definition: pl_actions.h:44
static TOOL_ACTION drawLine
Definition: pl_actions.h:43
Tool responsible for drawing/placing items (lines, rectangles, text, etc.)
void DisplayDrawingSheet()
Build and update the list of WS_DRAW_ITEM_xxx showing the frame layout.
Handle actions specific to the drawing sheet editor.
The main window used in the drawing sheet editor.
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl) override
Open a project or set of files given by aFileList.
void OnNewDrawingSheet()
Must be called to initialize parameters when a new drawing sheet is loaded.
std::unique_ptr< NL_PL_EDITOR_PLUGIN > m_spaceMouse
void OnModify() override
Must be called after a change in order to set the "modify" flag.
void SetCurrentFileName(const wxString &aName)
Store the current layout description file filename.
bool IsContentModified() const override
Get if the drawing sheet has been modified but not saved.
void Files_io(wxCommandEvent &event)
void ToPrinter(bool doPreview)
Open a dialog frame to print layers.
void UpdateMsgPanelInfo()
Display the size of the sheet to the message panel.
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Return bounding box of document with option to not include some items.
wxString m_mruImagePath
void doCloseWindow() override
VECTOR2I ReturnCoordOriginCorner() const
Calculate the position (in page, in iu) of the corner used as coordinate origin of items.
void OnClearFileHistory(wxCommandEvent &aEvent)
void SetPageSettings(const PAGE_INFO &) override
DS_DATA_ITEM * AddDrawingSheetItem(int aType)
Add a new item to the drawing sheet item list.
wxString GetCurrentFileName() const override
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
void OnFileHistory(wxCommandEvent &event)
void UpdateStatusBar() override
Update the status bar information.
void SetGridOrigin(const VECTOR2I &aPoint) override
void OnSelectPage(wxCommandEvent &event)
const TITLE_BLOCK & GetTitleBlock() const override
void UpdateTitleAndInfo()
Display the short filename (if exists) loaded file on the caption of the main window.
const VECTOR2I GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
void OnSelectCoordOriginCorner(wxCommandEvent &event)
Called when the user select one of the 4 page corner as corner reference (or the left top paper corne...
void handleActivateEvent(wxActivateEvent &aEvent) override
Handle a window activation event.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
PL_EDITOR_LAYOUT m_pageLayout
bool GetPageNumberOption() const
Drawing sheet editor can show the title block using a page number 1 or another number.
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
void handleIconizeEvent(wxIconizeEvent &aEvent) override
Handle a window iconize event.
void HardRedraw() override
Refresh the library tree and redraw the window.
void DisplayGridMsg() override
Display current grid size in the status bar.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
wxChoice * m_originSelectBox
const PAGE_INFO & GetPageSettings() const override
const PL_EDITOR_LAYOUT & GetPageLayout() const
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
PROPERTIES_FRAME * m_propertiesPagelayout
The last filename chosen to be proposed to the user.
wxChoice * m_pageSelectBox
PL_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void ClearUndoORRedoList(UNDO_REDO_LIST whichList, int aItemCount=-1) override
Remove the aItemCount of old commands from aList and delete commands, pickers and picked items if nee...
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock) override
void OnExit(wxCommandEvent &aEvent)
Event handler for the wxID_EXIT and wxID_CLOSE events.
bool LoadDrawingSheetFile(const wxString &aFullFileName)
Load a .kicad_wks drawing sheet file.
void SetPageSettings(const PAGE_INFO &aPageSettings)
TITLE_BLOCK & GetTitleBlock()
PAGE_INFO & GetPageSettings()
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Tool that displays edit points allowing to modify items by dragging the points.
PL_SELECTION & GetSelection()
Return the set of currently selected items.
PROPERTIES_FRAME display properties of the current item.
void CopyPrmsFromItemToPanel(DS_DATA_ITEM *aItem)
static bool NotEmpty(const SELECTION &aSelection)
Test if there are any items selected.
static bool Idle(const SELECTION &aSelection)
Test if there no items selected or being edited.
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
static bool ShowNever(const SELECTION &aSelection)
Always returns false.
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:41
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:171
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:173
ACTIONS * m_actions
Definition: tools_holder.h:172
Master controller class:
Definition: tool_manager.h:62
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
bool InvokeTool(TOOL_ID aToolId)
Call a tool by sending a tool activation event to tool of given ID.
ACTION_MANAGER * GetActionManager() const
Definition: tool_manager.h:306
void RegisterTool(TOOL_BASE *aTool)
Add a tool to the manager set and sets it up.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
void InitTools()
Initialize all registered tools.
void ShutdownAllTools()
Shutdown all tools with a currently registered event loop in this tool manager by waking them up with...
A holder to handle a list of undo (or redo) commands.
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
EDA_UNITS GetUserUnits() const
@ WHITE
Definition: color4d.h:48
@ BLACK
Definition: color4d.h:44
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
Definition: confirm.cpp:129
This file is part of the common library.
#define CHECK(x)
#define ENABLE(x)
#define _HKI(x)
int InvokeDialogPrintPreview(PL_EDITOR_FRAME *aCaller, wxPrintData *aPrintData)
Create and show a print preview dialog returns 1 if OK, 0 , there is a problem.
int InvokeDialogPrint(PL_EDITOR_FRAME *aCaller, wxPrintData *aPrintData, wxPageSetupDialogData *aPageSetupData)
Create and show a print dialog returns 1 if OK, 0 , there is a problem.
@ RB_CORNER
Definition: ds_data_item.h:49
@ RT_CORNER
Definition: ds_data_item.h:50
@ LT_CORNER
Definition: ds_data_item.h:52
@ LB_CORNER
Definition: ds_data_item.h:51
#define _(s)
#define KICAD_DEFAULT_DRAWFRAME_STYLE
#define PL_EDITOR_FRAME_NAME
EVT_MENU_RANGE(ID_GERBVIEW_DRILL_FILE1, ID_GERBVIEW_DRILL_FILEMAX, GERBVIEW_FRAME::OnDrlFileHistory) EVT_MENU_RANGE(ID_GERBVIEW_ZIP_FILE1
@ FRAME_PL_EDITOR
Definition: frame_type.h:59
static const std::string DrawingSheetFileExtension
@ ID_FILE_LIST_CLEAR
Definition: id.h:62
@ ID_FILEMAX
Definition: id.h:60
@ ID_FILE1
Definition: id.h:59
@ LAYER_DRAWINGSHEET_PAGEn
Sheet Editor previewing pages after first page.
Definition: layer_ids.h:322
@ LAYER_DRAWINGSHEET_PAGE1
Sheet Editor previewing first page.
Definition: layer_ids.h:321
KICOMMON_API double ToUserUnit(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnit, double aValue)
Convert aValue in internal units to the appropriate user units defined by aUnit.
Definition: eda_units.cpp:289
KICOMMON_API int Mils2mm(double aVal)
Convert mils to mm.
Definition: eda_units.cpp:82
@ COLOR
Color has changed.
Definition: view_item.h:54
void SetShutdownBlockReason(wxWindow *aWindow, const wxString &aReason)
Sets the block reason why the window/application is preventing OS shutdown.
Definition: unix/app.cpp:90
bool SupportsShutdownBlockReason()
Whether or not the window supports setting a shutdown block reason.
Definition: unix/app.cpp:79
KICOMMON_API wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition: ui_common.cpp:78
see class PGM_BASE
@ ID_SELECT_PAGE_NUMBER
Definition: pl_editor_id.h:38
@ ID_SELECT_COORDINATE_ORIGIN
Definition: pl_editor_id.h:37
#define DEFAULT_THEME
KIWAY Kiway(KFCTL_STANDALONE)
std::vector< FAB_LAYER_COLOR > dummy
const double IU_PER_MILS
Definition: base_units.h:77
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695
Definition of file extensions used in Kicad.