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, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <kiface_base.h>
23#include <pgm_base.h>
24#include <bitmaps.h>
25#include <core/arraydim.h>
29#include <confirm.h>
30#include <kiplatform/app.h>
32#include <gal/painter.h>
34#include <tool/selection.h>
35#include <tool/action_toolbar.h>
38#include <tool/tool_manager.h>
39#include <tool/common_control.h>
40#include <tool/common_tools.h>
41#include <tool/picker_tool.h>
42#include <tool/zoom_tool.h>
44#include "pl_editor_frame.h"
45#include "pl_editor_id.h"
46#include "pl_editor_settings.h"
47#include "properties_frame.h"
48#include <toolbars_pl_editor.h>
49#include "tools/pl_actions.h"
52#include "tools/pl_edit_tool.h"
56#include <view/view_controls.h>
57
58#include <wx/filedlg.h>
59#include <wx/print.h>
60#include <wx/treebook.h>
61#include <wx/msgdlg.h>
62#include <wx/log.h>
63#include <kiplatform/ui.h>
64
65#if defined(__linux__) || defined(__FreeBSD__)
67#else
69#endif
70
71
72BEGIN_EVENT_TABLE( PL_EDITOR_FRAME, EDA_DRAW_FRAME )
75
77
80
83
84 // Drop files event
85 EVT_DROP_FILES( PL_EDITOR_FRAME::OnDropFiles )
86END_EVENT_TABLE()
87
88
89PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
90 EDA_DRAW_FRAME( aKiway, aParent, FRAME_PL_EDITOR, wxT( "PlEditorFrame" ), wxDefaultPosition,
94 m_originSelectBox( nullptr ), m_originSelectChoice( 0 ), m_pageSelectBox( nullptr ),
95 m_mruImagePath( wxEmptyString )
96{
99
100 m_showBorderAndTitleBlock = true; // true for reference drawings.
102 m_aboutTitle = _HKI( "KiCad Drawing Sheet Editor" );
103
104 // Give an icon
105 wxIcon icon;
106 wxIconBundle icon_bundle;
107
108 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor, 48 ) );
109 icon_bundle.AddIcon( icon );
110 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor, 128 ) );
111 icon_bundle.AddIcon( icon );
112 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor, 256 ) );
113 icon_bundle.AddIcon( icon );
114 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor_32 ) );
115 icon_bundle.AddIcon( icon );
116 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor_16 ) );
117 icon_bundle.AddIcon( icon );
118
119 SetIcons( icon_bundle );
120
121 // Create GAL canvas
122 auto* drawPanel = new PL_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
125 SetCanvas( drawPanel );
126
127 LoadSettings( config() );
128
130 DragAcceptFiles( true );
131
132 VECTOR2I pageSizeIU = GetPageLayout().GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS );
133 SetScreen( new BASE_SCREEN( pageSizeIU ) );
134
135 setupTools();
138
142
143 wxStatusBar* stsbar = GetStatusBar();
144 int spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x * 2;
145
146 int dims[] = {
147
148 // balance of status bar on far left is set to a default or whatever is left over.
149 -1,
150
151 // When using GetTextSize() remember the width of '1' is not the same
152 // as the width of '0' unless the font is fixed width, and it usually won't be.
153
154 // zoom:
155 KIUI::GetTextSize( wxT( "Z 762000" ), stsbar ).x + spacer,
156
157 // cursor coords
158 KIUI::GetTextSize( wxT( "X 0234.567 Y 0234.567" ), stsbar ).x + spacer,
159
160 // delta distances
161 KIUI::GetTextSize( wxT( "dx 0234.567 dx 0234.567" ), stsbar ).x + spacer,
162
163 // grid size
164 KIUI::GetTextSize( wxT( "grid 0234.567" ), stsbar ).x + spacer,
165
166 // Coord origin (use the bigger message)
167 KIUI::GetTextSize( _( "coord origin: Right Bottom page corner" ), stsbar ).x + spacer,
168
169 // units display, Inches is bigger than mm
170 KIUI::GetTextSize( _( "Inches" ), stsbar ).x + spacer,
171
172 // constraint mode
173 KIUI::GetTextSize( _( "Constrain to H, V, 45" ), stsbar ).x + spacer
174 };
175
176 if( stsbar )
177 stsbar->SetFieldsCount( arrayDim( dims ), dims );
178
179 m_auimgr.SetManagedWindow( this );
180
183
184 // Rows; layers 4 - 6
185 m_auimgr.AddPane( m_tbTopMain, EDA_PANE().HToolbar().Name( "TopMainToolbar" )
186 .Top().Layer( 6 ) );
187 m_auimgr.AddPane( m_tbLeft, EDA_PANE().VToolbar().Name( "LeftToolbar" )
188 .Left().Layer( 3 ) );
189 m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
190 .Bottom().Layer( 6 ) );
191
192 // Columns; layers 1 - 3
193 m_auimgr.AddPane( m_tbRight, EDA_PANE().VToolbar().Name( "RightToolbar" )
194 .Right().Layer( 2 ) );
195
196 m_auimgr.AddPane( m_propertiesPagelayout, EDA_PANE().Palette().Name( "Props" )
197 .Right().Layer( 3 )
198 .Caption( _( "Properties" ) )
199 .MinSize( m_propertiesPagelayout->GetMinSize() )
200 .BestSize( m_propertiesFrameWidth, -1 ) );
201
202 // Center
203 m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" )
204 .Center() );
205
207
210
211 // Add the exit key handler
212 setupUnits( config() );
213
214 VECTOR2I originCoord = ReturnCoordOriginCorner();
215 SetGridOrigin( originCoord );
216
217 // Initialize the current drawing sheet
218#if 0 //start with empty layout
221#else // start with the default KiCad layout
222 DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( wxEmptyString, nullptr );
223#endif
225
226 // Ensure the window is on top
227 Raise();
228
229 // Register a call to update the toolbar sizes. It can't be done immediately because
230 // it seems to require some sizes calculated that aren't yet (at least on GTK).
231 CallAfter( [this]()
232 {
233 // Ensure the controls on the toolbars all are correctly sized
235 } );
236
237 try
238 {
239 if( !m_spaceMouse )
240 {
241#if defined(__linux__) || defined(__FreeBSD__)
242 m_spaceMouse = std::make_unique<SPNAV_2D_PLUGIN>( GetCanvas() );
243 m_spaceMouse->SetScale( drawSheetIUScale.IU_PER_MILS / pcbIUScale.IU_PER_MILS );
244#else
245 m_spaceMouse = std::make_unique<NL_PL_EDITOR_PLUGIN>();
246#endif
247 }
248
249 m_spaceMouse->SetCanvas( GetCanvas() );
250 }
251 catch( const std::exception& e )
252 {
253 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), wxS( "%s" ), e.what() );
254 }
255 catch( ... )
256 {
257 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ),
258 wxT( "Unknown exception during SpaceMouse initialization" ) );
259 }
260}
261
262
264{
265 // Ensure m_canvasType is up to date, to save it in config
267
268 // Shutdown all running tools
269 if( m_toolManager )
270 m_toolManager->ShutdownAllTools();
271}
272
273
275{
276 // Create the manager and dispatcher & route draw panel events to the dispatcher
278 m_toolManager->SetEnvironment( nullptr, GetCanvas()->GetView(),
279 GetCanvas()->GetViewControls(), config(), this );
280 m_actions = new PL_ACTIONS();
282
284
285 // Register tools
286 m_toolManager->RegisterTool( new COMMON_CONTROL );
287 m_toolManager->RegisterTool( new COMMON_TOOLS );
288 m_toolManager->RegisterTool( new ZOOM_TOOL );
289 m_toolManager->RegisterTool( new PL_SELECTION_TOOL );
290 m_toolManager->RegisterTool( new PL_EDITOR_CONTROL );
291 m_toolManager->RegisterTool( new PL_DRAWING_TOOLS );
292 m_toolManager->RegisterTool( new PL_EDIT_TOOL );
293 m_toolManager->RegisterTool( new PL_POINT_EDITOR );
294 m_toolManager->RegisterTool( new PICKER_TOOL );
295 m_toolManager->InitTools();
296
297 // Run the selection tool, it is supposed to be always active
298 m_toolManager->InvokeTool( "common.InteractiveSelection" );
299}
300
301
303{
305
306 ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
307 EDITOR_CONDITIONS cond( this );
308
309 wxASSERT( mgr );
310
311#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
312#define CHECK( x ) ACTION_CONDITIONS().Check( x )
313
317
319
324
331
340
341 // Not a tool, just a way to activate the action
344
345 auto titleBlockNormalMode =
346 [] ( const SELECTION& )
347 {
349 };
350
351 auto titleBlockEditMode =
352 [] ( const SELECTION& )
353 {
355 };
356
357 mgr->SetConditions( PL_ACTIONS::layoutNormalMode, CHECK( titleBlockNormalMode ) );
358 mgr->SetConditions( PL_ACTIONS::layoutEditMode, CHECK( titleBlockEditMode ) );
359
360#undef CHECK
361#undef ENABLE
362}
363
364
365bool PL_EDITOR_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
366{
367 wxString fn = aFileSet[0];
368
369 if( !LoadDrawingSheetFile( fn ) )
370 {
371 wxMessageBox( wxString::Format( _( "Error loading drawing sheet '%s'." ), fn ) );
372 return false;
373 }
374 else
375 {
377 return true;
378 }
379}
380
381
383{
384 // Must be called after a change in order to set the "modify" flag and update
385 // the frame title.
387
389
390 if( m_isClosing )
391 return;
392
394}
395
396
398{
399 return GetScreen() && GetScreen()->IsContentModified();
400}
401
402
403void PL_EDITOR_FRAME::OnExit( wxCommandEvent& aEvent )
404{
405 if( aEvent.GetId() == wxID_EXIT )
406 Kiway().OnKiCadExit();
407
408 if( aEvent.GetId() == wxID_CLOSE || Kiface().IsSingle() )
409 Close( false );
410}
411
412
413bool PL_EDITOR_FRAME::canCloseWindow( wxCloseEvent& aEvent )
414{
415 // Shutdown blocks must be determined and vetoed as early as possible
417 && aEvent.GetId() == wxEVT_QUERY_END_SESSION
418 && IsContentModified() )
419 {
420 return false;
421 }
422
423 if( IsContentModified() )
424 {
425 wxFileName filename = GetCurrentFileName();
426 wxString msg = _( "Save changes to '%s' before closing?" );
427
428 if( !HandleUnsavedChanges( this, wxString::Format( msg, filename.GetFullName() ),
429 [&]() -> bool
430 {
431 return saveCurrentPageLayout();
432 } ) )
433 {
434 return false;
435 }
436 }
437
438 return true;
439}
440
441
443{
444 // do not show the window because we do not want any paint event
445 Show( false );
446
447 // clean up the data before the view is destroyed
449
450 // On Linux, m_propertiesPagelayout must be destroyed
451 // before deleting the main frame to avoid a crash when closing
452 m_propertiesPagelayout->Destroy();
453 Destroy();
454}
455
456
457void PL_EDITOR_FRAME::OnSelectPage( wxCommandEvent& event )
458{
459 KIGFX::VIEW* view = GetCanvas()->GetView();
460 view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGE1, m_pageSelectBox->GetSelection() == 0 );
461 view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGEn, m_pageSelectBox->GetSelection() == 1 );
462 GetCanvas()->Refresh();
463}
464
465
467{
468 m_originSelectChoice = m_originSelectBox->GetSelection();
469 UpdateStatusBar(); // Update grid origin
471 GetCanvas()->Refresh();
472}
473
474
475void PL_EDITOR_FRAME::ToPrinter( bool doPreview )
476{
477 // static print data and page setup data, to remember settings during the session
478 static wxPrintData* s_PrintData;
479 static wxPageSetupDialogData* s_pageSetupData = nullptr;
480
481 const PAGE_INFO& pageInfo = GetPageSettings();
482
483 if( s_PrintData == nullptr ) // First print
484 {
485 s_PrintData = new wxPrintData();
486 s_PrintData->SetQuality( wxPRINT_QUALITY_HIGH ); // Default resolution = HIGH;
487 }
488
489 if( !s_PrintData->Ok() )
490 {
491 wxMessageBox( _( "Error Init Printer info" ) );
492 return;
493 }
494
495 if( s_pageSetupData == nullptr )
496 s_pageSetupData = new wxPageSetupDialogData( *s_PrintData );
497
498 s_pageSetupData->SetPaperId( pageInfo.GetPaperId() );
499 s_pageSetupData->GetPrintData().SetOrientation( pageInfo.GetWxOrientation() );
500
501 if( pageInfo.IsCustom() )
502 {
503 if( pageInfo.IsPortrait() )
504 s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ),
505 EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ) ) );
506 else
507 s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ),
508 EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ) ) );
509 }
510
511 *s_PrintData = s_pageSetupData->GetPrintData();
512
513 if( doPreview )
514 InvokeDialogPrintPreview( this, s_PrintData );
515 else
516 InvokeDialogPrint( this, s_PrintData, s_pageSetupData );
517}
518
519
520const BOX2I PL_EDITOR_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
521{
522 BOX2I rv( VECTOR2I( 0, 0 ), GetPageLayout().GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS ) );
523 return rv;
524}
525
526
528{
530
531 PL_EDITOR_SETTINGS* cfg = dynamic_cast<PL_EDITOR_SETTINGS*>( aCfg );
532 wxCHECK( cfg, /*void*/ );
533
536
538
541
542 PAGE_INFO pageInfo = GetPageSettings();
543 pageInfo.SetType( cfg->m_LastPaperSize, cfg->m_LastWasPortrait );
544 SetPageSettings( pageInfo );
545}
546
547
549{
551
552 auto cfg = static_cast<PL_EDITOR_SETTINGS*>( aCfg );
553
555
556 cfg->m_PropertiesFrameWidth = m_propertiesFrameWidth;
557 cfg->m_CornerOrigin = m_originSelectChoice;
558 cfg->m_BlackBackground = GetDrawBgColor() == BLACK;
559 cfg->m_LastPaperSize = GetPageSettings().GetTypeAsString();
560 cfg->m_LastWasPortrait = GetPageSettings().IsPortrait();
561 cfg->m_LastCustomWidth = PAGE_INFO::GetCustomWidthMils();
562 cfg->m_LastCustomHeight = PAGE_INFO::GetCustomHeightMils();
563}
564
565
567{
568 wxString title;
569 wxFileName file( GetCurrentFileName() );
570
571 if( IsContentModified() )
572 title = wxT( "*" );
573
574 if( file.IsOk() )
575 title += file.GetName();
576 else
577 title += _( "[no drawing sheet loaded]" );
578
579 title += wxT( " \u2014 " ) + _( "Drawing Sheet Editor" ),
580
581 SetTitle( title );
582}
583
584
589
590
591void PL_EDITOR_FRAME::SetCurrentFileName( const wxString& aName )
592{
594}
595
596
597void PL_EDITOR_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
598{
599 m_pageLayout.SetPageSettings( aPageSettings );
600
601 if( GetScreen() )
602 GetScreen()->InitDataPoints( aPageSettings.GetSizeIU( drawSheetIUScale.IU_PER_MILS ) );
603}
604
605
607{
608 return m_pageLayout.GetPageSettings();
609}
610
611
613{
614 // this function is only needed because EDA_DRAW_FRAME is not compiled
615 // with either -DPCBNEW or -DEESCHEMA, so the virtual is used to route
616 // into an application specific source file.
617 return m_pageLayout.GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS );
618}
619
620
625
626
628{
629 m_pageLayout.SetTitleBlock( aTitleBlock );
630}
631
632
634{
636
639
640 // Update gal display options like cursor shape, grid options:
642
643 GetCanvas()->GetView()->GetPainter()->GetSettings()->LoadColors( colors );
644
647
649 Layout();
650 SendSizeEvent();
651}
652
653
655{
656 m_grid_origin = aPoint;
657
658 if( PL_DRAW_PANEL_GAL* canvas = GetCanvas() )
659 {
660 canvas->GetGAL()->SetGridOrigin( VECTOR2D( aPoint ) );
661 canvas->GetView()->MarkDirty();
662 }
663}
664
665
667{
668 // calculate the position (in page, in iu) of the corner used as coordinate origin
669 // coordinate origin can be the paper Top Left corner, or each of 4 page corners
670 VECTOR2I originCoord;
671
672 // To avoid duplicate code, we use a dummy segment starting at 0,0 in relative coord
674
675 switch( m_originSelectChoice )
676 {
677 default:
678 case 0: // Origin = paper Left Top corner
679 break;
680
681 case 1: // Origin = page Right Bottom corner
682 dummy.SetStart( 0, 0, RB_CORNER );
683 originCoord = dummy.GetStartPosIU();
684 break;
685
686 case 2: // Origin = page Left Bottom corner
687 dummy.SetStart( 0, 0, LB_CORNER );
688 originCoord = dummy.GetStartPosIU();
689 break;
690
691 case 3: // Origin = page Right Top corner
692 dummy.SetStart( 0, 0, RT_CORNER );
693 originCoord = dummy.GetStartPosIU();
694 break;
695
696 case 4: // Origin = page Left Top corner
697 dummy.SetStart( 0, 0, LT_CORNER );
698 originCoord = dummy.GetStartPosIU();
699 break;
700 }
701
702 return originCoord;
703}
704
705
707{
708 wxString line;
709 wxString gridformatter;
710
711 switch( GetUserUnits() )
712 {
713 case EDA_UNITS::INCH: gridformatter = wxS( "grid %.3f" ); break;
714 case EDA_UNITS::MM: gridformatter = wxS( "grid %.4f" ); break;
715 default: gridformatter = wxS( "grid %f" ); break;
716 }
717
719 GetCanvas()->GetGAL()->GetGridSize().x );
720 line.Printf( gridformatter, grid );
721
722 SetStatusText( line, 4 );
723}
724
725
727{
728 // Display Zoom level:
729 SetStatusText( GetZoomLevelIndicator(), 1 );
730
731 // coordinate origin can be the paper Top Left corner, or each of 4 page corners
732 VECTOR2I originCoord = ReturnCoordOriginCorner();
733
734 // We need the orientation of axis (sign of coordinates)
735 int Xsign = 1;
736 int Ysign = 1;
737
738 switch( m_originSelectChoice )
739 {
740 default:
741 case 0: // Origin = paper Left Top corner
742 break;
743
744 case 1: // Origin = page Right Bottom corner
745 Xsign = -1;
746 Ysign = -1;
747 break;
748
749 case 2: // Origin = page Left Bottom corner
750 Ysign = -1;
751 break;
752
753 case 3: // Origin = page Right Top corner
754 Xsign = -1;
755 break;
756
757 case 4: // Origin = page Left Top corner
758 break;
759 }
760
761 // Display absolute coordinates:
763 VECTOR2D coord = cursorPos - originCoord;
764 double dXpos = EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, GetUserUnits(), coord.x * Xsign );
765 double dYpos = EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, GetUserUnits(), coord.y * Ysign );
766
767 wxString absformatter = wxT( "X %.4g Y %.4g" );
768 wxString locformatter = wxT( "dx %.4g dy %.4g" );
769
770 switch( GetUserUnits() )
771 {
772 case EDA_UNITS::INCH: SetStatusText( _( "inches" ), 6 ); break;
773 case EDA_UNITS::MILS: SetStatusText( _( "mils" ), 6 ); break;
774 case EDA_UNITS::MM: SetStatusText( _( "mm" ), 6 ); break;
775 case EDA_UNITS::UNSCALED: SetStatusText( wxEmptyString, 6 ); break;
776 default: wxASSERT( false ); break;
777 }
778
779 wxString line;
780
781 // Display abs coordinates
782 line.Printf( absformatter, dXpos, dYpos );
783 SetStatusText( line, 2 );
784
785 // Display relative coordinates:
786 if( GetScreen() )
787 {
788 double dx = cursorPos.x - GetScreen()->m_LocalOrigin.x;
789 double dy = cursorPos.y - GetScreen()->m_LocalOrigin.y;
792 line.Printf( locformatter, dXpos, dYpos );
793 SetStatusText( line, 3 );
794 }
795
797
798 // Display corner reference for coord origin
799 line.Printf( _("coord origin: %s"),
800 m_originSelectBox->GetString( m_originSelectChoice ).GetData() );
801 SetStatusText( line, 5 );
802}
803
804
809
810
812{
813 return m_toolManager->GetTool<PL_SELECTION_TOOL>()->GetSelection();
814}
815
816
818{
820
822 PL_SELECTION& selection = selTool->GetSelection();
823 DS_DATA_ITEM* item = nullptr;
824
825 if( selection.GetSize() == 1 )
826 item = static_cast<DS_DRAW_ITEM_BASE*>( selection.Front() )->GetPeer();
827
828 m_propertiesPagelayout->CopyPrmsFromItemToPanel( item );
829 m_propertiesPagelayout->CopyPrmsFromGeneralToPanel();
831 GetCanvas()->Refresh();
832}
833
834
836{
837 DS_DATA_ITEM * item = nullptr;
838
839 switch( aType )
840 {
842 item = new DS_DATA_ITEM_TEXT( wxT( "Text") );
843 break;
844
847 break;
848
851 break;
852
854 item = new DS_DATA_ITEM_POLYGONS();
855 break;
856
858 {
859 wxFileDialog fileDlg( this, _( "Choose Image" ), m_mruImagePath, wxEmptyString,
860 FILEEXT::ImageFileWildcard(), wxFD_OPEN );
861
863
864 if( fileDlg.ShowModal() != wxID_OK )
865 return nullptr;
866
867 wxString fullFilename = fileDlg.GetPath();
868 m_mruImagePath = wxPathOnly( fullFilename );
869
870 if( !wxFileExists( fullFilename ) )
871 {
872 wxMessageBox( _( "Could not load image from '%s'." ), fullFilename );
873 break;
874 }
875
877
878 if( !image->ReadImageFile( fullFilename ) )
879 {
880 wxMessageBox( _( "Could not load image from '%s'." ), fullFilename );
881 delete image;
882 break;
883 }
884
885 // Set the scale factor for pl_editor (it is set for Eeschema by default)
886 image->SetPixelSizeIu( drawSheetIUScale.IU_PER_MILS * 1000.0 / image->GetPPI() );
887 item = new DS_DATA_ITEM_BITMAP( image );
888 break;
889 }
890 }
891
892 if( item == nullptr )
893 return nullptr;
894
896 item->SyncDrawItems( nullptr, GetCanvas()->GetView() );
897
898 return item;
899}
900
901
903{
905 GetScreen()->SetContentModified( false );
907
908 m_propertiesPagelayout->CopyPrmsFromItemToPanel( nullptr );
909 m_propertiesPagelayout->CopyPrmsFromGeneralToPanel();
910
912
914
915 if( GetCurrentFileName().IsEmpty() )
916 {
917 // Default shutdown reason until a file is loaded
918 KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New drawing sheet file is unsaved" ) );
919 }
920 else
921 {
922 KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Drawing sheet changes are unsaved" ) );
923 }
924}
925
926
928{
929 if( aItemCount == 0 )
930 return;
931
932 UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
933
934 if( aItemCount < 0 )
935 {
936 list.ClearCommandList();
937 }
938 else
939 {
940 for( int ii = 0; ii < aItemCount; ii++ )
941 {
942 if( list.m_CommandsList.size() == 0 )
943 break;
944
945 PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
946 list.m_CommandsList.erase( list.m_CommandsList.begin() );
947
948 curr_cmd->ClearListAndDeleteItems( []( EDA_ITEM* aItem )
949 {
950 delete aItem;
951 } );
952 delete curr_cmd; // Delete command
953 }
954 }
955}
956
957
959{
960 return m_pageSelectBox->GetSelection() == 0;
961}
962
963#if 1
965{
966 VECTOR2D size = GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS );
967
968 std::vector<MSG_PANEL_ITEM> msgItems;
969 msgItems.emplace_back( _( "Page Width" ), MessageTextFromValue( size.x ) );
970 msgItems.emplace_back( _( "Page Height" ), MessageTextFromValue( size.y ) );
971
972 SetMsgPanel( msgItems );
973}
974#endif
975
976void PL_EDITOR_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
977{
979
980 if( m_spaceMouse )
981 m_spaceMouse->SetFocus( aEvent.GetActive() );
982}
983
984
985void PL_EDITOR_FRAME::handleIconizeEvent( wxIconizeEvent& aEvent )
986{
988
989 if( m_spaceMouse )
990 m_spaceMouse->SetFocus( false );
991}
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition arraydim.h:27
constexpr EDA_IU_SCALE drawSheetIUScale
Definition base_units.h:122
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
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:100
@ icon_pagelayout_editor
@ icon_pagelayout_editor_16
@ icon_pagelayout_editor_32
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
static TOOL_ACTION toggleGrid
Definition actions.h:194
static TOOL_ACTION paste
Definition actions.h:76
static TOOL_ACTION copy
Definition actions.h:74
static TOOL_ACTION undo
Definition actions.h:71
static TOOL_ACTION doDelete
Definition actions.h:81
static TOOL_ACTION selectionTool
Definition actions.h:247
static TOOL_ACTION save
Definition actions.h:54
static TOOL_ACTION zoomFitScreen
Definition actions.h:138
static TOOL_ACTION redo
Definition actions.h:72
static TOOL_ACTION deleteTool
Definition actions.h:82
static TOOL_ACTION zoomTool
Definition actions.h:142
static TOOL_ACTION cut
Definition actions.h:73
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:37
bool IsContentModified() const
Definition base_screen.h:56
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition base_screen.h:81
VECTOR2D m_LocalOrigin
Relative Screen cursor coordinate (on grid) in user units.
Definition base_screen.h:86
void SetContentModified(bool aModified=true)
Definition base_screen.h:55
void InitDataPoints(const VECTOR2I &aPageSizeInternalUnits)
This class handle bitmap images in KiCad.
Definition bitmap_base.h:45
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 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 setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
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:96
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 GridVisible()
Create a functor testing if the grid is visible 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:63
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition view.h:405
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition view.cpp:1686
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition view.h:225
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:311
void OnKiCadExit()
Definition kiway.cpp:796
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:75
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:129
static double GetCustomHeightMils()
Definition page_info.h:198
const VECTOR2D GetSizeIU(double aIUScale) const
Gets the page size in internal units.
Definition page_info.h:173
double GetHeightMils() const
Definition page_info.h:143
wxPaperSize GetPaperId() const
Definition page_info.h:134
double GetWidthMils() const
Definition page_info.h:138
bool IsCustom() const
bool IsPortrait() const
Definition page_info.h:124
static double GetCustomWidthMils()
Definition page_info.h:193
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:32
static TOOL_ACTION placeImage
Definition pl_actions.h:37
static TOOL_ACTION drawRectangle
Definition pl_actions.h:38
static TOOL_ACTION layoutNormalMode
Definition pl_actions.h:45
static TOOL_ACTION placeText
Definition pl_actions.h:36
static TOOL_ACTION layoutEditMode
Definition pl_actions.h:46
static TOOL_ACTION appendImportedDrawingSheet
Definition pl_actions.h:40
static TOOL_ACTION drawLine
Definition pl_actions.h:39
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:37
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:44
@ BLACK
Definition color4d.h:40
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:146
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:55
static const std::string DrawingSheetFileExtension
static wxString ImageFileWildcard()
@ ID_FILE_LIST_CLEAR
Definition id.h:58
@ ID_FILEMAX
Definition id.h:56
@ ID_FILE1
Definition id.h:55
EVT_MENU(ID_COMPARE_PROJECT_BRANCHES, KICAD_MANAGER_FRAME::OnCompareProjectBranches) KICAD_MANAGER_FRAME
@ LAYER_DRAWINGSHEET_PAGEn
Sheet Editor previewing pages after first page.
Definition layer_ids.h:323
@ LAYER_DRAWINGSHEET_PAGE1
Sheet Editor previewing first page.
Definition layer_ids.h:322
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:78
@ COLOR
Color has changed.
Definition view_item.h:50
void SetShutdownBlockReason(wxWindow *aWindow, const wxString &aReason)
Sets the block reason why the window/application is preventing OS shutdown.
Definition unix/app.cpp:102
bool SupportsShutdownBlockReason()
Whether or not the window supports setting a shutdown block reason.
Definition unix/app.cpp:91
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:448
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:40
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:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682
Definition of file extensions used in Kicad.