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
68#ifndef __linux__
70#else
72#endif
73
74
75BEGIN_EVENT_TABLE( PL_EDITOR_FRAME, EDA_DRAW_FRAME )
76 EVT_MENU( wxID_CLOSE, PL_EDITOR_FRAME::OnExit )
77 EVT_MENU( wxID_EXIT, PL_EDITOR_FRAME::OnExit )
78
79 EVT_MENU( wxID_FILE, PL_EDITOR_FRAME::Files_io )
80
83
86
87 // Drop files event
88 EVT_DROP_FILES( PL_EDITOR_FRAME::OnDropFiles )
89END_EVENT_TABLE()
90
91
92PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
93 EDA_DRAW_FRAME( aKiway, aParent, FRAME_PL_EDITOR, wxT( "PlEditorFrame" ), wxDefaultPosition,
97 m_originSelectBox( nullptr ), m_originSelectChoice( 0 ), m_pageSelectBox( nullptr ),
98 m_mruImagePath( wxEmptyString )
99{
100 m_maximizeByDefault = true;
102
103 m_showBorderAndTitleBlock = true; // true for reference drawings.
105 m_aboutTitle = _HKI( "KiCad Drawing Sheet Editor" );
106
107 // Give an icon
108 wxIcon icon;
109 wxIconBundle icon_bundle;
110
111 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor, 48 ) );
112 icon_bundle.AddIcon( icon );
113 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor, 128 ) );
114 icon_bundle.AddIcon( icon );
115 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor, 256 ) );
116 icon_bundle.AddIcon( icon );
117 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor_32 ) );
118 icon_bundle.AddIcon( icon );
119 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor_16 ) );
120 icon_bundle.AddIcon( icon );
121
122 SetIcons( icon_bundle );
123
124 // Create GAL canvas
125 auto* drawPanel = new PL_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
128 SetCanvas( drawPanel );
129
130 LoadSettings( config() );
131
133 DragAcceptFiles( true );
134
135 VECTOR2I pageSizeIU = GetPageLayout().GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS );
136 SetScreen( new BASE_SCREEN( pageSizeIU ) );
137
138 setupTools();
141
145
146 wxWindow* stsbar = GetStatusBar();
147 int spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x * 2;
148
149 int dims[] = {
150
151 // balance of status bar on far left is set to a default or whatever is left over.
152 -1,
153
154 // When using GetTextSize() remember the width of '1' is not the same
155 // as the width of '0' unless the font is fixed width, and it usually won't be.
156
157 // zoom:
158 KIUI::GetTextSize( wxT( "Z 762000" ), stsbar ).x + spacer,
159
160 // cursor coords
161 KIUI::GetTextSize( wxT( "X 0234.567 Y 0234.567" ), stsbar ).x + spacer,
162
163 // delta distances
164 KIUI::GetTextSize( wxT( "dx 0234.567 dx 0234.567" ), stsbar ).x + spacer,
165
166 // grid size
167 KIUI::GetTextSize( wxT( "grid 0234.567" ), stsbar ).x + spacer,
168
169 // Coord origin (use the bigger message)
170 KIUI::GetTextSize( _( "coord origin: Right Bottom page corner" ), stsbar ).x + spacer,
171
172 // units display, Inches is bigger than mm
173 KIUI::GetTextSize( _( "Inches" ), stsbar ).x + spacer,
174
175 // constraint mode
176 KIUI::GetTextSize( _( "Constrain to H, V, 45" ), stsbar ).x + spacer
177 };
178
179 SetStatusWidths( arrayDim( dims ), dims );
180
181 m_auimgr.SetManagedWindow( this );
182
185
186 // Rows; layers 4 - 6
187 m_auimgr.AddPane( m_tbTopMain, EDA_PANE().HToolbar().Name( "TopMainToolbar" )
188 .Top().Layer( 6 ) );
189 m_auimgr.AddPane( m_tbLeft, EDA_PANE().VToolbar().Name( "LeftToolbar" )
190 .Left().Layer( 3 ) );
191 m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
192 .Bottom().Layer( 6 ) );
193
194 // Columns; layers 1 - 3
195 m_auimgr.AddPane( m_tbRight, EDA_PANE().VToolbar().Name( "RightToolbar" )
196 .Right().Layer( 2 ) );
197
198 m_auimgr.AddPane( m_propertiesPagelayout, EDA_PANE().Palette().Name( "Props" )
199 .Right().Layer( 3 )
200 .Caption( _( "Properties" ) )
201 .MinSize( m_propertiesPagelayout->GetMinSize() )
202 .BestSize( m_propertiesFrameWidth, -1 ) );
203
204 // Center
205 m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" )
206 .Center() );
207
209
212
213 // Add the exit key handler
214 setupUnits( config() );
215
216 VECTOR2I originCoord = ReturnCoordOriginCorner();
217 SetGridOrigin( originCoord );
218
219 // Initialize the current drawing sheet
220#if 0 //start with empty layout
223#else // start with the default KiCad layout
224 DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( wxEmptyString, nullptr );
225#endif
227
228 // Ensure the window is on top
229 Raise();
230
231 // Register a call to update the toolbar sizes. It can't be done immediately because
232 // it seems to require some sizes calculated that aren't yet (at least on GTK).
233 CallAfter( [this]()
234 {
235 // Ensure the controls on the toolbars all are correctly sized
237 } );
238
239 try
240 {
241 if( !m_spaceMouse )
242 {
243#ifndef __linux__
244 m_spaceMouse = std::make_unique<NL_PL_EDITOR_PLUGIN>();
245#else
246 m_spaceMouse = std::make_unique<SPNAV_2D_PLUGIN>( GetCanvas() );
247 m_spaceMouse->SetScale( drawSheetIUScale.IU_PER_MILS / pcbIUScale.IU_PER_MILS );
248#endif
249 }
250
251 m_spaceMouse->SetCanvas( GetCanvas() );
252 }
253 catch( const std::system_error& e )
254 {
255 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), e.what() );
256 }
257}
258
259
261{
262 // Ensure m_canvasType is up to date, to save it in config
264
265 // Shutdown all running tools
266 if( m_toolManager )
267 m_toolManager->ShutdownAllTools();
268}
269
270
272{
273 // Create the manager and dispatcher & route draw panel events to the dispatcher
275 m_toolManager->SetEnvironment( nullptr, GetCanvas()->GetView(),
276 GetCanvas()->GetViewControls(), config(), this );
277 m_actions = new PL_ACTIONS();
279
281
282 // Register tools
283 m_toolManager->RegisterTool( new COMMON_CONTROL );
284 m_toolManager->RegisterTool( new COMMON_TOOLS );
285 m_toolManager->RegisterTool( new ZOOM_TOOL );
286 m_toolManager->RegisterTool( new PL_SELECTION_TOOL );
287 m_toolManager->RegisterTool( new PL_EDITOR_CONTROL );
288 m_toolManager->RegisterTool( new PL_DRAWING_TOOLS );
289 m_toolManager->RegisterTool( new PL_EDIT_TOOL );
290 m_toolManager->RegisterTool( new PL_POINT_EDITOR );
291 m_toolManager->RegisterTool( new PICKER_TOOL );
292 m_toolManager->InitTools();
293
294 // Run the selection tool, it is supposed to be always active
295 m_toolManager->InvokeTool( "common.InteractiveSelection" );
296}
297
298
300{
302
303 ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
304 EDITOR_CONDITIONS cond( this );
305
306 wxASSERT( mgr );
307
308#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
309#define CHECK( x ) ACTION_CONDITIONS().Check( x )
310
314
322
327
334
343
344 // Not a tool, just a way to activate the action
347
348 auto titleBlockNormalMode =
349 [] ( const SELECTION& )
350 {
352 };
353
354 auto titleBlockEditMode =
355 [] ( const SELECTION& )
356 {
358 };
359
360 mgr->SetConditions( PL_ACTIONS::layoutNormalMode, CHECK( titleBlockNormalMode ) );
361 mgr->SetConditions( PL_ACTIONS::layoutEditMode, CHECK( titleBlockEditMode ) );
362
363#undef CHECK
364#undef ENABLE
365}
366
367
368bool PL_EDITOR_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
369{
370 wxString fn = aFileSet[0];
371
372 if( !LoadDrawingSheetFile( fn ) )
373 {
374 wxMessageBox( wxString::Format( _( "Error loading drawing sheet '%s'." ), fn ) );
375 return false;
376 }
377 else
378 {
380 return true;
381 }
382}
383
384
386{
387 // Must be called after a change in order to set the "modify" flag and update
388 // the frame title.
390
392
393 if( m_isClosing )
394 return;
395
397}
398
399
401{
402 return GetScreen() && GetScreen()->IsContentModified();
403}
404
405
406void PL_EDITOR_FRAME::OnExit( wxCommandEvent& aEvent )
407{
408 if( aEvent.GetId() == wxID_EXIT )
409 Kiway().OnKiCadExit();
410
411 if( aEvent.GetId() == wxID_CLOSE || Kiface().IsSingle() )
412 Close( false );
413}
414
415
416bool PL_EDITOR_FRAME::canCloseWindow( wxCloseEvent& aEvent )
417{
418 // Shutdown blocks must be determined and vetoed as early as possible
420 && aEvent.GetId() == wxEVT_QUERY_END_SESSION
421 && IsContentModified() )
422 {
423 return false;
424 }
425
426 if( IsContentModified() )
427 {
428 wxFileName filename = GetCurrentFileName();
429 wxString msg = _( "Save changes to '%s' before closing?" );
430
431 if( !HandleUnsavedChanges( this, wxString::Format( msg, filename.GetFullName() ),
432 [&]() -> bool
433 {
434 return saveCurrentPageLayout();
435 } ) )
436 {
437 return false;
438 }
439 }
440
441 return true;
442}
443
444
446{
447 // do not show the window because we do not want any paint event
448 Show( false );
449
450 // clean up the data before the view is destroyed
452
453 // On Linux, m_propertiesPagelayout must be destroyed
454 // before deleting the main frame to avoid a crash when closing
455 m_propertiesPagelayout->Destroy();
456 Destroy();
457}
458
459
460void PL_EDITOR_FRAME::OnSelectPage( wxCommandEvent& event )
461{
462 KIGFX::VIEW* view = GetCanvas()->GetView();
463 view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGE1, m_pageSelectBox->GetSelection() == 0 );
464 view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGEn, m_pageSelectBox->GetSelection() == 1 );
465 GetCanvas()->Refresh();
466}
467
468
470{
471 m_originSelectChoice = m_originSelectBox->GetSelection();
472 UpdateStatusBar(); // Update grid origin
474 GetCanvas()->Refresh();
475}
476
477
478void PL_EDITOR_FRAME::ToPrinter( bool doPreview )
479{
480 // static print data and page setup data, to remember settings during the session
481 static wxPrintData* s_PrintData;
482 static wxPageSetupDialogData* s_pageSetupData = nullptr;
483
484 const PAGE_INFO& pageInfo = GetPageSettings();
485
486 if( s_PrintData == nullptr ) // First print
487 {
488 s_PrintData = new wxPrintData();
489 s_PrintData->SetQuality( wxPRINT_QUALITY_HIGH ); // Default resolution = HIGH;
490 }
491
492 if( !s_PrintData->Ok() )
493 {
494 wxMessageBox( _( "Error Init Printer info" ) );
495 return;
496 }
497
498 if( s_pageSetupData == nullptr )
499 s_pageSetupData = new wxPageSetupDialogData( *s_PrintData );
500
501 s_pageSetupData->SetPaperId( pageInfo.GetPaperId() );
502 s_pageSetupData->GetPrintData().SetOrientation( pageInfo.GetWxOrientation() );
503
504 if( pageInfo.IsCustom() )
505 {
506 if( pageInfo.IsPortrait() )
507 s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ),
508 EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ) ) );
509 else
510 s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ),
511 EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ) ) );
512 }
513
514 *s_PrintData = s_pageSetupData->GetPrintData();
515
516 if( doPreview )
517 InvokeDialogPrintPreview( this, s_PrintData );
518 else
519 InvokeDialogPrint( this, s_PrintData, s_pageSetupData );
520}
521
522
523const BOX2I PL_EDITOR_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
524{
525 BOX2I rv( VECTOR2I( 0, 0 ), GetPageLayout().GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS ) );
526 return rv;
527}
528
529
531{
533
534 PL_EDITOR_SETTINGS* cfg = dynamic_cast<PL_EDITOR_SETTINGS*>( aCfg );
535 wxCHECK( cfg, /*void*/ );
536
539
541
544
545 PAGE_INFO pageInfo = GetPageSettings();
546 pageInfo.SetType( cfg->m_LastPaperSize, cfg->m_LastWasPortrait );
547 SetPageSettings( pageInfo );
548}
549
550
552{
554
555 auto cfg = static_cast<PL_EDITOR_SETTINGS*>( aCfg );
556
558
559 cfg->m_PropertiesFrameWidth = m_propertiesFrameWidth;
560 cfg->m_CornerOrigin = m_originSelectChoice;
561 cfg->m_BlackBackground = GetDrawBgColor() == BLACK;
562 cfg->m_LastPaperSize = GetPageSettings().GetTypeAsString();
563 cfg->m_LastWasPortrait = GetPageSettings().IsPortrait();
564 cfg->m_LastCustomWidth = PAGE_INFO::GetCustomWidthMils();
565 cfg->m_LastCustomHeight = PAGE_INFO::GetCustomHeightMils();
566}
567
568
570{
571 wxString title;
572 wxFileName file( GetCurrentFileName() );
573
574 if( IsContentModified() )
575 title = wxT( "*" );
576
577 if( file.IsOk() )
578 title += file.GetName();
579 else
580 title += _( "[no drawing sheet loaded]" );
581
582 title += wxT( " \u2014 " ) + _( "Drawing Sheet Editor" ),
583
584 SetTitle( title );
585}
586
587
592
593
594void PL_EDITOR_FRAME::SetCurrentFileName( const wxString& aName )
595{
597}
598
599
600void PL_EDITOR_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
601{
602 m_pageLayout.SetPageSettings( aPageSettings );
603
604 if( GetScreen() )
605 GetScreen()->InitDataPoints( aPageSettings.GetSizeIU( drawSheetIUScale.IU_PER_MILS ) );
606}
607
608
610{
611 return m_pageLayout.GetPageSettings();
612}
613
614
616{
617 // this function is only needed because EDA_DRAW_FRAME is not compiled
618 // with either -DPCBNEW or -DEESCHEMA, so the virtual is used to route
619 // into an application specific source file.
620 return m_pageLayout.GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS );
621}
622
623
628
629
631{
632 m_pageLayout.SetTitleBlock( aTitleBlock );
633}
634
635
637{
639
642
643 // Update gal display options like cursor shape, grid options:
645
646 GetCanvas()->GetView()->GetPainter()->GetSettings()->LoadColors( colors );
647
650
652 Layout();
653 SendSizeEvent();
654}
655
656
658{
659 // calculate the position (in page, in iu) of the corner used as coordinate origin
660 // coordinate origin can be the paper Top Left corner, or each of 4 page corners
661 VECTOR2I originCoord;
662
663 // To avoid duplicate code, we use a dummy segment starting at 0,0 in relative coord
665
666 switch( m_originSelectChoice )
667 {
668 default:
669 case 0: // Origin = paper Left Top corner
670 break;
671
672 case 1: // Origin = page Right Bottom corner
673 dummy.SetStart( 0, 0, RB_CORNER );
674 originCoord = dummy.GetStartPosIU();
675 break;
676
677 case 2: // Origin = page Left Bottom corner
678 dummy.SetStart( 0, 0, LB_CORNER );
679 originCoord = dummy.GetStartPosIU();
680 break;
681
682 case 3: // Origin = page Right Top corner
683 dummy.SetStart( 0, 0, RT_CORNER );
684 originCoord = dummy.GetStartPosIU();
685 break;
686
687 case 4: // Origin = page Left Top corner
688 dummy.SetStart( 0, 0, LT_CORNER );
689 originCoord = dummy.GetStartPosIU();
690 break;
691 }
692
693 return originCoord;
694}
695
696
698{
699 wxString line;
700 wxString gridformatter;
701
702 switch( GetUserUnits() )
703 {
704 case EDA_UNITS::INCH: gridformatter = wxS( "grid %.3f" ); break;
705 case EDA_UNITS::MM: gridformatter = wxS( "grid %.4f" ); break;
706 default: gridformatter = wxS( "grid %f" ); break;
707 }
708
710 GetCanvas()->GetGAL()->GetGridSize().x );
711 line.Printf( gridformatter, grid );
712
713 SetStatusText( line, 4 );
714}
715
716
718{
719 // Display Zoom level:
720 SetStatusText( GetZoomLevelIndicator(), 1 );
721
722 // coordinate origin can be the paper Top Left corner, or each of 4 page corners
723 VECTOR2I originCoord = ReturnCoordOriginCorner();
724 SetGridOrigin( originCoord );
725
726 // We need the orientation of axis (sign of coordinates)
727 int Xsign = 1;
728 int Ysign = 1;
729
730 switch( m_originSelectChoice )
731 {
732 default:
733 case 0: // Origin = paper Left Top corner
734 break;
735
736 case 1: // Origin = page Right Bottom corner
737 Xsign = -1;
738 Ysign = -1;
739 break;
740
741 case 2: // Origin = page Left Bottom corner
742 Ysign = -1;
743 break;
744
745 case 3: // Origin = page Right Top corner
746 Xsign = -1;
747 break;
748
749 case 4: // Origin = page Left Top corner
750 break;
751 }
752
753 // Display absolute coordinates:
755 VECTOR2D coord = cursorPos - originCoord;
756 double dXpos =
758 double dYpos =
760
761 wxString absformatter = wxT( "X %.4g Y %.4g" );
762 wxString locformatter = wxT( "dx %.4g dy %.4g" );
763
764 switch( GetUserUnits() )
765 {
766 case EDA_UNITS::INCH: SetStatusText( _( "inches" ), 6 ); break;
767 case EDA_UNITS::MILS: SetStatusText( _( "mils" ), 6 ); break;
768 case EDA_UNITS::MM: SetStatusText( _( "mm" ), 6 ); break;
769 case EDA_UNITS::UNSCALED: SetStatusText( wxEmptyString, 6 ); break;
770 default: wxASSERT( false ); break;
771 }
772
773 wxString line;
774
775 // Display abs coordinates
776 line.Printf( absformatter, dXpos, dYpos );
777 SetStatusText( line, 2 );
778
779 // Display relative coordinates:
780 if( GetScreen() )
781 {
782 double dx = cursorPos.x - GetScreen()->m_LocalOrigin.x;
783 double dy = cursorPos.y - GetScreen()->m_LocalOrigin.y;
786 line.Printf( locformatter, dXpos, dYpos );
787 SetStatusText( line, 3 );
788 }
789
791
792 // Display corner reference for coord origin
793 line.Printf( _("coord origin: %s"),
794 m_originSelectBox->GetString( m_originSelectChoice ).GetData() );
795 SetStatusText( line, 5 );
796}
797
798
803
804
806{
807 return m_toolManager->GetTool<PL_SELECTION_TOOL>()->GetSelection();
808}
809
810
812{
814
816 PL_SELECTION& selection = selTool->GetSelection();
817 DS_DATA_ITEM* item = nullptr;
818
819 if( selection.GetSize() == 1 )
820 item = static_cast<DS_DRAW_ITEM_BASE*>( selection.Front() )->GetPeer();
821
822 m_propertiesPagelayout->CopyPrmsFromItemToPanel( item );
823 m_propertiesPagelayout->CopyPrmsFromGeneralToPanel();
825 GetCanvas()->Refresh();
826}
827
828
830{
831 DS_DATA_ITEM * item = nullptr;
832
833 switch( aType )
834 {
836 item = new DS_DATA_ITEM_TEXT( wxT( "Text") );
837 break;
838
841 break;
842
845 break;
846
848 item = new DS_DATA_ITEM_POLYGONS();
849 break;
850
852 {
853 wxFileDialog fileDlg( this, _( "Choose Image" ), m_mruImagePath, wxEmptyString,
854 _( "Image Files" ) + wxS( " " ) + wxImage::GetImageExtWildcard(),
855 wxFD_OPEN );
856
857 if( fileDlg.ShowModal() != wxID_OK )
858 return nullptr;
859
860 wxString fullFilename = fileDlg.GetPath();
861 m_mruImagePath = wxPathOnly( fullFilename );
862
863 if( !wxFileExists( fullFilename ) )
864 {
865 wxMessageBox( _( "Could not load image from '%s'." ), fullFilename );
866 break;
867 }
868
870
871 if( !image->ReadImageFile( fullFilename ) )
872 {
873 wxMessageBox( _( "Could not load image from '%s'." ), fullFilename );
874 delete image;
875 break;
876 }
877
878 // Set the scale factor for pl_editor (it is set for Eeschema by default)
879 image->SetPixelSizeIu( drawSheetIUScale.IU_PER_MILS * 1000.0 / image->GetPPI() );
880 item = new DS_DATA_ITEM_BITMAP( image );
881 }
882 break;
883 }
884
885 if( item == nullptr )
886 return nullptr;
887
889 item->SyncDrawItems( nullptr, GetCanvas()->GetView() );
890
891 return item;
892}
893
894
896{
898 GetScreen()->SetContentModified( false );
900
901 m_propertiesPagelayout->CopyPrmsFromItemToPanel( nullptr );
902 m_propertiesPagelayout->CopyPrmsFromGeneralToPanel();
903
905
907
908 if( GetCurrentFileName().IsEmpty() )
909 {
910 // Default shutdown reason until a file is loaded
911 KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New drawing sheet file is unsaved" ) );
912 }
913 else
914 {
915 KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Drawing sheet changes are unsaved" ) );
916 }
917}
918
919
921{
922 if( aItemCount == 0 )
923 return;
924
925 UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
926
927 if( aItemCount < 0 )
928 {
929 list.ClearCommandList();
930 }
931 else
932 {
933 for( int ii = 0; ii < aItemCount; ii++ )
934 {
935 if( list.m_CommandsList.size() == 0 )
936 break;
937
938 PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
939 list.m_CommandsList.erase( list.m_CommandsList.begin() );
940
941 curr_cmd->ClearListAndDeleteItems( []( EDA_ITEM* aItem )
942 {
943 delete aItem;
944 } );
945 delete curr_cmd; // Delete command
946 }
947 }
948}
949
950
952{
953 return m_pageSelectBox->GetSelection() == 0;
954}
955
956#if 1
958{
959 VECTOR2D size = GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS );
960
961 std::vector<MSG_PANEL_ITEM> msgItems;
962 msgItems.emplace_back( _( "Page Width" ), MessageTextFromValue( size.x ) );
963 msgItems.emplace_back( _( "Page Height" ), MessageTextFromValue( size.y ) );
964
965 SetMsgPanel( msgItems );
966}
967#endif
968
969void PL_EDITOR_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
970{
972
973 if( m_spaceMouse )
974 m_spaceMouse->SetFocus( aEvent.GetActive() );
975}
976
977
978void PL_EDITOR_FRAME::handleIconizeEvent( wxIconizeEvent& aEvent )
979{
981
982 if( m_spaceMouse )
983 m_spaceMouse->SetFocus( false );
984}
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
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
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
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
static TOOL_ACTION toggleGrid
Definition actions.h:197
static TOOL_ACTION paste
Definition actions.h:80
static TOOL_ACTION millimetersUnits
Definition actions.h:205
static TOOL_ACTION cursorSmallCrosshairs
Definition actions.h:151
static TOOL_ACTION copy
Definition actions.h:78
static TOOL_ACTION milsUnits
Definition actions.h:204
static TOOL_ACTION undo
Definition actions.h:75
static TOOL_ACTION inchesUnits
Definition actions.h:203
static TOOL_ACTION doDelete
Definition actions.h:85
static TOOL_ACTION selectionTool
Definition actions.h:250
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 cursor45Crosshairs
Definition actions.h:153
static TOOL_ACTION cut
Definition actions.h:77
static TOOL_ACTION cursorFullCrosshairs
Definition actions.h:152
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.
WINDOW_SETTINGS m_Window
wxString m_ColorTheme
Active color theme name.
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)
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.
Drawing sheet structure type definitions.
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 ...
void ClearList()
Erase the list of items.
Base class to handle basic graphic items.
DS_DATA_ITEM * GetPeer() const
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...
ACTION_TOOLBAR * m_tbRight
TOOLBAR_SETTINGS * m_toolbarSettings
wxAuiManager m_auimgr
virtual void RecreateToolbars()
UNDO_REDO_CONTAINER m_redoList
ACTION_TOOLBAR * m_tbLeft
virtual void OnDropFiles(wxDropFilesEvent &aEvent)
Handle event fired when a file is dropped to the window.
std::map< const wxString, TOOL_ACTION * > m_acceptedExts
Associate file extensions with action to execute.
ACTION_TOOLBAR * m_tbTopMain
wxString m_aboutTitle
bool m_isClosing
Set by the close window event handler after frames are asked if they can close.
void ReCreateMenuBar()
Recreate the menu bar.
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 setupUnits(APP_SETTINGS_BASE *aCfg)
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.
virtual void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Change the current rendering backend.
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 resolveCanvasType()
Determine the canvas type to load (with prompt if required) and initializes m_canvasType.
EDA_MSG_PANEL * m_messagePanel
void SetCanvas(EDA_DRAW_PANEL_GAL *aPanel)
virtual void SetScreen(BASE_SCREEN *aScreen)
EDA_DRAW_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, const EDA_IU_SCALE &aIuScale)
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.
bool m_showBorderAndTitleBlock
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:98
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 CursorSmallCrosshairs()
Create a functor testing if the cursor is full screen in a frame.
SELECTION_CONDITION GridVisible()
Create a functor testing if the grid is visible in a frame.
SELECTION_CONDITION Cursor45Crosshairs()
SELECTION_CONDITION CursorFullCrosshairs()
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:66
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition view.h:400
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition view.cpp:1561
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition view.h:220
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:717
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:79
wxString GetTypeAsString() const
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...
wxPrintOrientation GetWxOrientation() const
Definition page_info.h:133
static double GetCustomHeightMils()
Definition page_info.h:202
const VECTOR2D GetSizeIU(double aIUScale) const
Gets the page size in internal units.
Definition page_info.h:177
double GetHeightMils() const
Definition page_info.h:147
wxPaperSize GetPaperId() const
Definition page_info.h:138
double GetWidthMils() const
Definition page_info.h:142
bool IsCustom() const
bool IsPortrait() const
Definition page_info.h:128
static double GetCustomWidthMils()
Definition page_info.h:197
static void SetCustomHeightMils(double aHeightInMils)
Set the height of Custom page in mils for any custom page constructed or made via SetType() after mak...
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 configureToolbars() override
void ToPrinter(bool doPreview)
Open a dialog frame to print layers.
PL_EDITOR_FRAME(KIWAY *aKiway, wxWindow *aParent)
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.
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 UpdateToolbarControlSizes() override
Update the sizes of any controls in the toolbars of the frame.
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.
TITLE_BLOCK & GetTitleBlock()
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.
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
TOOL_DISPATCHER * m_toolDispatcher
ACTIONS * m_actions
Master controller class:
A holder to handle a list of undo (or redo) commands.
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
void SetUserUnits(EDA_UNITS aUnits)
@ 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)
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
@ RT_CORNER
@ LT_CORNER
@ LB_CORNER
#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:326
@ LAYER_DRAWINGSHEET_PAGE1
Sheet Editor previewing first page.
Definition layer_ids.h:325
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.
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
#define _HKI(x)
Definition page_info.cpp:44
see class PGM_BASE
@ ID_SELECT_PAGE_NUMBER
@ ID_SELECT_COORDINATE_ORIGIN
#define DEFAULT_THEME
T * GetToolbarSettings(const wxString &aFilename)
T * GetAppSettings(const char *aFilename)
KIWAY Kiway(KFCTL_STANDALONE)
std::vector< FAB_LAYER_COLOR > dummy
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694
Definition of file extensions used in Kicad.