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>
30#include <confirm.h>
31#include <kiplatform/app.h>
33#include <gal/painter.h>
35#include <tool/selection.h>
36#include <tool/action_toolbar.h>
39#include <tool/tool_manager.h>
40#include <tool/common_control.h>
41#include <tool/common_tools.h>
42#include <tool/picker_tool.h>
43#include <tool/zoom_tool.h>
45#include "pl_editor_frame.h"
46#include "pl_editor_id.h"
47#include "pl_editor_settings.h"
49#include <wx/choice.h>
50#include <toolbars_pl_editor.h>
51#include "tools/pl_actions.h"
54#include "tools/pl_edit_tool.h"
58#include <view/view_controls.h>
59
60#include <wx/filedlg.h>
61#include <wx/print.h>
62#include <wx/treebook.h>
63#include <wx/msgdlg.h>
64#include <wx/log.h>
65#include <kiplatform/ui.h>
66
67#include "widgets/kistatusbar.h"
68
69#if defined(__linux__) || defined(__FreeBSD__)
71#else
73#endif
74
75
76BEGIN_EVENT_TABLE( PL_EDITOR_FRAME, EDA_DRAW_FRAME )
79
81
84
87
88 // Drop files event
89 EVT_DROP_FILES( PL_EDITOR_FRAME::OnDropFiles )
90END_EVENT_TABLE()
91
92
93PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
94 EDA_DRAW_FRAME( aKiway, aParent, FRAME_PL_EDITOR, wxT( "PlEditorFrame" ), wxDefaultPosition,
98 m_originSelectBox( nullptr ), m_originSelectChoice( 0 ), m_pageSelectBox( nullptr ),
99 m_mruImagePath( wxEmptyString )
100{
101 m_maximizeByDefault = true;
103
104 m_showBorderAndTitleBlock = true; // true for reference drawings.
106 m_aboutTitle = _HKI( "KiCad Drawing Sheet Editor" );
107
108 // Give an icon
109 wxIcon icon;
110 wxIconBundle icon_bundle;
111
112 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor, 48 ) );
113 icon_bundle.AddIcon( icon );
114 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor, 128 ) );
115 icon_bundle.AddIcon( icon );
116 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor, 256 ) );
117 icon_bundle.AddIcon( icon );
118 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor_32 ) );
119 icon_bundle.AddIcon( icon );
120 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor_16 ) );
121 icon_bundle.AddIcon( icon );
122
123 SetIcons( icon_bundle );
124
125 // Create GAL canvas
126 auto* drawPanel = new PL_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
129 SetCanvas( drawPanel );
130
131 LoadSettings( config() );
132
134 DragAcceptFiles( true );
135
136 VECTOR2I pageSizeIU = GetPageLayout().GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS );
137 SetScreen( new BASE_SCREEN( pageSizeIU ) );
138
139 setupTools();
142
146
147 if( KISTATUSBAR* statusBar = dynamic_cast<KISTATUSBAR*>( GetStatusBar() ) )
148 {
149 int spacer = KIUI::GetTextSize( wxT( "M" ), statusBar ).x * 2;
150
151 int dims[] = {
152
153 // balance of status bar on far left is set to a default or whatever is left over.
154 -1,
155
156 // When using GetTextSize() remember the width of '1' is not the same
157 // as the width of '0' unless the font is fixed width, and it usually won't be.
158
159 // zoom:
160 KIUI::GetTextSize( wxT( "Z 762000" ), statusBar ).x + spacer,
161
162 // cursor coords
163 KIUI::GetTextSize( wxT( "X 0234.567 Y 0234.567" ), statusBar ).x + spacer,
164
165 // delta distances
166 KIUI::GetTextSize( wxT( "dx 0234.567 dx 0234.567" ), statusBar ).x + spacer,
167
168 // grid size
169 KIUI::GetTextSize( wxT( "grid 0234.567" ), statusBar ).x + spacer,
170
171 // Coord origin (use the bigger message)
172 KIUI::GetTextSize( _( "coord origin: Right Bottom page corner" ), statusBar ).x + spacer,
173
174 // units display, Inches is bigger than mm
175 KIUI::GetTextSize( _( "Inches" ), statusBar ).x + spacer,
176
177 // constraint mode
178 KIUI::GetTextSize( _( "Constrain to H, V, 45" ), statusBar ).x + spacer
179 };
180
181 statusBar->SetFieldsCount( arrayDim( dims ), dims );
182 }
183
184 m_auimgr.SetManagedWindow( this );
185
188 m_propertiesPagelayout->SetSplitterProportion(
189 static_cast<PL_EDITOR_SETTINGS*>( config() )->m_PropertiesSplitter );
190
191 // Rows; layers 4 - 6
192 m_auimgr.AddPane( m_tbTopMain, EDA_PANE().HToolbar().Name( "TopMainToolbar" )
193 .Top().Layer( 6 ) );
194 m_auimgr.AddPane( m_tbLeft, EDA_PANE().VToolbar().Name( "LeftToolbar" )
195 .Left().Layer( 3 ) );
196 m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
197 .Bottom().Layer( 6 ) );
198
199 // Columns; layers 1 - 3
200 m_auimgr.AddPane( m_tbRight, EDA_PANE().VToolbar().Name( "RightToolbar" )
201 .Right().Layer( 2 ) );
202
203 m_auimgr.AddPane( m_propertiesPagelayout, EDA_PANE().Palette().Name( "Props" )
204 .Right().Layer( 3 )
205 .Caption( _( "Properties" ) )
206 .MinSize( m_propertiesPagelayout->GetMinSize() )
207 .BestSize( m_propertiesFrameWidth, -1 ) );
208
209 // Center
210 m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" )
211 .Center() );
212
214
216
217 // Add the exit key handler
218 setupUnits( config() );
219
220 VECTOR2I originCoord = ReturnCoordOriginCorner();
221 SetGridOrigin( originCoord );
222
223 // Initialize the current drawing sheet
224#if 0 //start with empty layout
227#else // start with the default KiCad layout
228 DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( wxEmptyString, nullptr );
229#endif
231
232 // Ensure the window is on top
233 Raise();
234
235 // Register a call to update the toolbar sizes. It can't be done immediately because
236 // it seems to require some sizes calculated that aren't yet (at least on GTK).
237 CallAfter( [this]()
238 {
239 // Ensure the controls on the toolbars all are correctly sized
241 } );
242
243 try
244 {
245 if( !m_spaceMouse )
246 {
247#if defined(__linux__) || defined(__FreeBSD__)
248 m_spaceMouse = std::make_unique<SPNAV_2D_PLUGIN>( GetCanvas() );
249 m_spaceMouse->SetScale( drawSheetIUScale.IU_PER_MILS / pcbIUScale.IU_PER_MILS );
250#else
251 m_spaceMouse = std::make_unique<NL_PL_EDITOR_PLUGIN>();
252#endif
253 }
254
255 m_spaceMouse->SetCanvas( GetCanvas() );
256 }
257 catch( const std::exception& e )
258 {
259 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), wxS( "%s" ), e.what() );
260 }
261 catch( ... )
262 {
263 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ),
264 wxT( "Unknown exception during SpaceMouse initialization" ) );
265 }
266}
267
268
270{
271 // Ensure m_canvasType is up to date, to save it in config
273
274 // Shutdown all running tools
275 if( m_toolManager )
276 m_toolManager->ShutdownAllTools();
277}
278
279
281{
282 // Create the manager and dispatcher & route draw panel events to the dispatcher
284 m_toolManager->SetEnvironment( nullptr, GetCanvas()->GetView(),
285 GetCanvas()->GetViewControls(), config(), this );
286 m_actions = new PL_ACTIONS();
288
290
291 // Register tools
292 m_toolManager->RegisterTool( new COMMON_CONTROL );
293 m_toolManager->RegisterTool( new COMMON_TOOLS );
294 m_toolManager->RegisterTool( new ZOOM_TOOL );
295 m_toolManager->RegisterTool( new PL_SELECTION_TOOL );
296 m_toolManager->RegisterTool( new PL_EDITOR_CONTROL );
297 m_toolManager->RegisterTool( new PL_DRAWING_TOOLS );
298 m_toolManager->RegisterTool( new PL_EDIT_TOOL );
299 m_toolManager->RegisterTool( new PL_POINT_EDITOR );
300 m_toolManager->RegisterTool( new PICKER_TOOL );
301 m_toolManager->InitTools();
302
303 // Run the selection tool, it is supposed to be always active
304 m_toolManager->InvokeTool( "common.InteractiveSelection" );
305}
306
307
309{
311
312 ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
313 EDITOR_CONDITIONS cond( this );
314
315 wxASSERT( mgr );
316
317#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
318#define CHECK( x ) ACTION_CONDITIONS().Check( x )
319
323
325
330
337
346
347 // Not a tool, just a way to activate the action
350
351 auto titleBlockNormalMode =
352 [] ( const SELECTION& )
353 {
355 };
356
357 auto titleBlockEditMode =
358 [] ( const SELECTION& )
359 {
361 };
362
363 mgr->SetConditions( PL_ACTIONS::layoutNormalMode, CHECK( titleBlockNormalMode ) );
364 mgr->SetConditions( PL_ACTIONS::layoutEditMode, CHECK( titleBlockEditMode ) );
365
366#undef CHECK
367#undef ENABLE
368}
369
370
371bool PL_EDITOR_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
372{
373 wxString fn = aFileSet[0];
374
375 if( !LoadDrawingSheetFile( fn ) )
376 {
377 wxMessageBox( wxString::Format( _( "Error loading drawing sheet '%s'." ), fn ) );
378 return false;
379 }
380 else
381 {
383 return true;
384 }
385}
386
387
389{
390 // Must be called after a change in order to set the "modify" flag and update
391 // the frame title.
393
395
396 if( m_isClosing )
397 return;
398
400}
401
402
404{
405 return GetScreen() && GetScreen()->IsContentModified();
406}
407
408
409void PL_EDITOR_FRAME::OnExit( wxCommandEvent& aEvent )
410{
411 if( aEvent.GetId() == wxID_EXIT )
412 Kiway().OnKiCadExit();
413
414 if( aEvent.GetId() == wxID_CLOSE || Kiface().IsSingle() )
415 Close( false );
416}
417
418
419bool PL_EDITOR_FRAME::canCloseWindow( wxCloseEvent& aEvent )
420{
421 // Shutdown blocks must be determined and vetoed as early as possible
423 && aEvent.GetId() == wxEVT_QUERY_END_SESSION
424 && IsContentModified() )
425 {
426 return false;
427 }
428
429 if( IsContentModified() )
430 {
431 wxFileName filename = GetCurrentFileName();
432 wxString msg = _( "Save changes to '%s' before closing?" );
433
434 if( !HandleUnsavedChanges( this, wxString::Format( msg, filename.GetFullName() ),
435 [&]() -> bool
436 {
437 return saveCurrentPageLayout();
438 } ) )
439 {
440 return false;
441 }
442 }
443
444 return true;
445}
446
447
449{
450 // do not show the window because we do not want any paint event
451 Show( false );
452
453 // clean up the data before the view is destroyed
455
456 // On Linux, m_propertiesPagelayout must be destroyed
457 // before deleting the main frame to avoid a crash when closing
458 m_propertiesPagelayout->Destroy();
459 Destroy();
460}
461
462
463void PL_EDITOR_FRAME::OnSelectPage( wxCommandEvent& event )
464{
465 KIGFX::VIEW* view = GetCanvas()->GetView();
466 view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGE1, m_pageSelectBox->GetSelection() == 0 );
467 view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGEn, m_pageSelectBox->GetSelection() == 1 );
468 GetCanvas()->Refresh();
469}
470
471
473{
474 m_originSelectChoice = m_originSelectBox->GetSelection();
475 UpdateStatusBar(); // Update grid origin
477 GetCanvas()->Refresh();
478}
479
480
481void PL_EDITOR_FRAME::ToPrinter( bool doPreview )
482{
483 // static print data and page setup data, to remember settings during the session
484 static wxPrintData* s_PrintData;
485 static wxPageSetupDialogData* s_pageSetupData = nullptr;
486
487 const PAGE_INFO& pageInfo = GetPageSettings();
488
489 if( s_PrintData == nullptr ) // First print
490 {
491 s_PrintData = new wxPrintData();
492 s_PrintData->SetQuality( wxPRINT_QUALITY_HIGH ); // Default resolution = HIGH;
493 }
494
495 if( !s_PrintData->Ok() )
496 {
497 wxMessageBox( _( "Error Init Printer info" ) );
498 return;
499 }
500
501 if( s_pageSetupData == nullptr )
502 s_pageSetupData = new wxPageSetupDialogData( *s_PrintData );
503
504 s_pageSetupData->SetPaperId( pageInfo.GetPaperId() );
505 s_pageSetupData->GetPrintData().SetOrientation( pageInfo.GetWxOrientation() );
506
507 if( pageInfo.IsCustom() )
508 {
509 if( pageInfo.IsPortrait() )
510 s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ),
511 EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ) ) );
512 else
513 s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ),
514 EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ) ) );
515 }
516
517 *s_PrintData = s_pageSetupData->GetPrintData();
518
519 if( doPreview )
520 InvokeDialogPrintPreview( this, s_PrintData );
521 else
522 InvokeDialogPrint( this, s_PrintData, s_pageSetupData );
523}
524
525
526const BOX2I PL_EDITOR_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
527{
528 BOX2I rv( VECTOR2I( 0, 0 ), GetPageLayout().GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS ) );
529 return rv;
530}
531
532
534{
536
537 PL_EDITOR_SETTINGS* cfg = dynamic_cast<PL_EDITOR_SETTINGS*>( aCfg );
538 wxCHECK( cfg, /*void*/ );
539
542
544
547
548 PAGE_INFO pageInfo = GetPageSettings();
549 pageInfo.SetType( cfg->m_LastPaperSize, cfg->m_LastWasPortrait );
550 SetPageSettings( pageInfo );
551}
552
553
555{
557
558 auto cfg = static_cast<PL_EDITOR_SETTINGS*>( aCfg );
559
561
562 cfg->m_PropertiesFrameWidth = m_propertiesFrameWidth;
563 cfg->m_PropertiesSplitter = m_propertiesPagelayout->SplitterProportion();
564 cfg->m_CornerOrigin = m_originSelectChoice;
565 cfg->m_BlackBackground = GetDrawBgColor() == BLACK;
566 cfg->m_LastPaperSize = GetPageSettings().GetTypeAsString();
567 cfg->m_LastWasPortrait = GetPageSettings().IsPortrait();
568 cfg->m_LastCustomWidth = PAGE_INFO::GetCustomWidthMils();
569 cfg->m_LastCustomHeight = PAGE_INFO::GetCustomHeightMils();
570}
571
572
574{
575 wxString title;
576 wxFileName file( GetCurrentFileName() );
577
578 if( IsContentModified() )
579 title = wxT( "*" );
580
581 if( file.IsOk() )
582 title += file.GetName();
583 else
584 title += _( "[no drawing sheet loaded]" );
585
586 title += wxT( " \u2014 " ) + _( "Drawing Sheet Editor" ),
587
588 SetTitle( title );
589}
590
591
596
597
598void PL_EDITOR_FRAME::SetCurrentFileName( const wxString& aName )
599{
601}
602
603
604void PL_EDITOR_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
605{
606 m_pageLayout.SetPageSettings( aPageSettings );
607
608 if( GetScreen() )
609 GetScreen()->InitDataPoints( aPageSettings.GetSizeIU( drawSheetIUScale.IU_PER_MILS ) );
610}
611
612
614{
615 return m_pageLayout.GetPageSettings();
616}
617
618
620{
621 // this function is only needed because EDA_DRAW_FRAME is not compiled
622 // with either -DPCBNEW or -DEESCHEMA, so the virtual is used to route
623 // into an application specific source file.
624 return m_pageLayout.GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS );
625}
626
627
632
633
635{
636 m_pageLayout.SetTitleBlock( aTitleBlock );
637}
638
639
641{
643
646
647 // Update gal display options like cursor shape, grid options:
649
650 GetCanvas()->GetView()->GetPainter()->GetSettings()->LoadColors( colors );
651
654
656 Layout();
657 SendSizeEvent();
658}
659
660
662{
663 m_grid_origin = aPoint;
664
665 if( PL_DRAW_PANEL_GAL* canvas = GetCanvas() )
666 {
667 canvas->GetGAL()->SetGridOrigin( VECTOR2D( aPoint ) );
668 canvas->GetView()->MarkDirty();
669 }
670}
671
672
674{
675 // calculate the position (in page, in iu) of the corner used as coordinate origin
676 // coordinate origin can be the paper Top Left corner, or each of 4 page corners
677 VECTOR2I originCoord;
678
679 // To avoid duplicate code, we use a dummy segment starting at 0,0 in relative coord
681
682 switch( m_originSelectChoice )
683 {
684 default:
685 case 0: // Origin = paper Left Top corner
686 break;
687
688 case 1: // Origin = page Right Bottom corner
689 dummy.SetStart( 0, 0, RB_CORNER );
690 originCoord = dummy.GetStartPosIU();
691 break;
692
693 case 2: // Origin = page Left Bottom corner
694 dummy.SetStart( 0, 0, LB_CORNER );
695 originCoord = dummy.GetStartPosIU();
696 break;
697
698 case 3: // Origin = page Right Top corner
699 dummy.SetStart( 0, 0, RT_CORNER );
700 originCoord = dummy.GetStartPosIU();
701 break;
702
703 case 4: // Origin = page Left Top corner
704 dummy.SetStart( 0, 0, LT_CORNER );
705 originCoord = dummy.GetStartPosIU();
706 break;
707 }
708
709 return originCoord;
710}
711
712
714{
715 wxString line;
716 wxString gridformatter;
717
718 switch( GetUserUnits() )
719 {
720 case EDA_UNITS::INCH: gridformatter = wxS( "grid %.3f" ); break;
721 case EDA_UNITS::MM: gridformatter = wxS( "grid %.4f" ); break;
722 default: gridformatter = wxS( "grid %f" ); break;
723 }
724
726 GetCanvas()->GetGAL()->GetGridSize().x );
727 line.Printf( gridformatter, grid );
728
729 SetStatusText( line, 4 );
730}
731
732
734{
735 // Display Zoom level:
736 SetStatusText( GetZoomLevelIndicator(), 1 );
737
738 // coordinate origin can be the paper Top Left corner, or each of 4 page corners
739 VECTOR2I originCoord = ReturnCoordOriginCorner();
740
741 // We need the orientation of axis (sign of coordinates)
742 int Xsign = 1;
743 int Ysign = 1;
744
745 switch( m_originSelectChoice )
746 {
747 default:
748 case 0: // Origin = paper Left Top corner
749 break;
750
751 case 1: // Origin = page Right Bottom corner
752 Xsign = -1;
753 Ysign = -1;
754 break;
755
756 case 2: // Origin = page Left Bottom corner
757 Ysign = -1;
758 break;
759
760 case 3: // Origin = page Right Top corner
761 Xsign = -1;
762 break;
763
764 case 4: // Origin = page Left Top corner
765 break;
766 }
767
768 // Display absolute coordinates:
770 VECTOR2D coord = cursorPos - originCoord;
771 double dXpos = EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, GetUserUnits(), coord.x * Xsign );
772 double dYpos = EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, GetUserUnits(), coord.y * Ysign );
773
774 wxString absformatter = wxT( "X %.4g Y %.4g" );
775 wxString locformatter = wxT( "dx %.4g dy %.4g" );
776
777 switch( GetUserUnits() )
778 {
779 case EDA_UNITS::INCH: SetStatusText( _( "inches" ), 6 ); break;
780 case EDA_UNITS::MILS: SetStatusText( _( "mils" ), 6 ); break;
781 case EDA_UNITS::MM: SetStatusText( _( "mm" ), 6 ); break;
782 case EDA_UNITS::UNSCALED: SetStatusText( wxEmptyString, 6 ); break;
783 default: wxASSERT( false ); break;
784 }
785
786 wxString line;
787
788 // Display abs coordinates
789 line.Printf( absformatter, dXpos, dYpos );
790 SetStatusText( line, 2 );
791
792 // Display relative coordinates:
793 if( GetScreen() )
794 {
795 double dx = cursorPos.x - GetScreen()->m_LocalOrigin.x;
796 double dy = cursorPos.y - GetScreen()->m_LocalOrigin.y;
799 line.Printf( locformatter, dXpos, dYpos );
800 SetStatusText( line, 3 );
801 }
802
804
805 // Display corner reference for coord origin
806 line.Printf( _("coord origin: %s"),
807 m_originSelectBox->GetString( m_originSelectChoice ).GetData() );
808 SetStatusText( line, 5 );
809}
810
811
816
817
819{
820 return m_toolManager->GetTool<PL_SELECTION_TOOL>()->GetSelection();
821}
822
823
832
833
835{
836 DS_DATA_ITEM * item = nullptr;
837
838 switch( aType )
839 {
841 item = new DS_DATA_ITEM_TEXT( wxT( "Text") );
842 break;
843
846 break;
847
850 break;
851
853 item = new DS_DATA_ITEM_POLYGONS();
854 break;
855
857 {
858 wxFileDialog fileDlg( this, _( "Choose Image" ), m_mruImagePath, wxEmptyString,
859 FILEEXT::ImageFileWildcard(), wxFD_OPEN );
860
862
863 if( fileDlg.ShowModal() != wxID_OK )
864 return nullptr;
865
866 wxString fullFilename = fileDlg.GetPath();
867 m_mruImagePath = wxPathOnly( fullFilename );
868
869 if( !wxFileExists( fullFilename ) )
870 {
871 wxMessageBox( _( "Could not load image from '%s'." ), fullFilename );
872 break;
873 }
874
876
877 if( !image->ReadImageFile( fullFilename ) )
878 {
879 wxMessageBox( _( "Could not load image from '%s'." ), fullFilename );
880 delete image;
881 break;
882 }
883
884 // Set the scale factor for pl_editor (it is set for Eeschema by default)
885 image->SetPixelSizeIu( drawSheetIUScale.IU_PER_MILS * 1000.0 / image->GetPPI() );
886 item = new DS_DATA_ITEM_BITMAP( image );
887 break;
888 }
889 }
890
891 if( item == nullptr )
892 return nullptr;
893
894 SyncDataItem( item );
895
896 return item;
897}
898
899
901{
903 dummy.SetPaperFormat( GetPageSettings().GetTypeAsString() );
904 dummy.SetTitleBlock( &GetTitleBlock() );
905 dummy.SetProject( &Prj() );
906
907 aItem->SyncDrawItems( &dummy, GetCanvas()->GetView() );
908}
909
910
912{
914 GetScreen()->SetContentModified( false );
916
917 m_propertiesPagelayout->UpdateData();
918
920
922
923 if( GetCurrentFileName().IsEmpty() )
924 {
925 // Default shutdown reason until a file is loaded
926 KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New drawing sheet file is unsaved" ) );
927 }
928 else
929 {
930 KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Drawing sheet changes are unsaved" ) );
931 }
932}
933
934
936{
937 if( aItemCount == 0 )
938 return;
939
940 UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
941
942 if( aItemCount < 0 )
943 {
944 list.ClearCommandList();
945 }
946 else
947 {
948 for( int ii = 0; ii < aItemCount; ii++ )
949 {
950 if( list.m_CommandsList.size() == 0 )
951 break;
952
953 PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
954 list.m_CommandsList.erase( list.m_CommandsList.begin() );
955
956 curr_cmd->ClearListAndDeleteItems( []( EDA_ITEM* aItem )
957 {
958 delete aItem;
959 } );
960 delete curr_cmd; // Delete command
961 }
962 }
963}
964
965
967{
968 return m_pageSelectBox->GetSelection() == 0;
969}
970
971#if 1
973{
974 VECTOR2D size = GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS );
975
976 std::vector<MSG_PANEL_ITEM> msgItems;
977 msgItems.emplace_back( _( "Page Width" ), MessageTextFromValue( size.x ) );
978 msgItems.emplace_back( _( "Page Height" ), MessageTextFromValue( size.y ) );
979
980 SetMsgPanel( msgItems );
981}
982#endif
983
984void PL_EDITOR_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
985{
987
988 if( m_spaceMouse )
989 m_spaceMouse->SetFocus( aEvent.GetActive() );
990}
991
992
993void PL_EDITOR_FRAME::handleIconizeEvent( wxIconizeEvent& aEvent )
994{
996
997 if( m_spaceMouse )
998 m_spaceMouse->SetFocus( false );
999}
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:129
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
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:914
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:47
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 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.
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
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.
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 KIGFX::VIEW_CONTROLS instance used in the panel.
virtual KIGFX::VIEW * GetView() const
Return a pointer to the KIGFX::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 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:68
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition view.h:431
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition view.cpp:2475
PAINTER * GetPainter() const
Return the painter object used by the view for drawing VIEW_ITEM objects.
Definition view.h:242
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
Definition kistatusbar.h:50
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
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:348
void OnKiCadExit()
Definition kiway.cpp:803
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:128
static double GetCustomHeightMils()
Definition page_info.h:197
const VECTOR2D GetSizeIU(double aIUScale) const
Gets the page size in internal units.
Definition page_info.h:172
double GetHeightMils() const
Definition page_info.h:142
wxPaperSize GetPaperId() const
Definition page_info.h:133
double GetWidthMils() const
Definition page_info.h:137
bool IsCustom() const
bool IsPortrait() const
Definition page_info.h:123
static double GetCustomWidthMils()
Definition page_info.h:192
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 ITEM_PICKER::m_pickedItem or ITEM_PICKER::m_link.
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:39
static TOOL_ACTION layoutNormalMode
Definition pl_actions.h:46
static TOOL_ACTION placeText
Definition pl_actions.h:36
static TOOL_ACTION layoutEditMode
Definition pl_actions.h:47
static TOOL_ACTION appendImportedDrawingSheet
Definition pl_actions.h:41
static TOOL_ACTION drawLine
Definition pl_actions.h:40
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_PROPERTIES_PANEL * m_propertiesPagelayout
The last filename chosen to be proposed to the user.
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
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 SyncDataItem(DS_DATA_ITEM *aItem)
Rebuild a data item's draw items in the live view, with the same text expansion context a full rebuil...
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.
DS_DATA_ITEM * CreateDrawingSheetItem(int aType)
Create a new item and build its draw items in the view.
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.
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.
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:38
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.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition cvpcb.cpp:165
#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:332
@ LAYER_DRAWINGSHEET_PAGE1
Sheet Editor previewing first page.
Definition layer_ids.h:331
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:108
bool SupportsShutdownBlockReason()
Whether or not the window supports setting a shutdown block reason.
Definition unix/app.cpp:97
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:640
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:80
#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:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
Definition of file extensions used in Kicad.