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 return false;
424
425 if( IsContentModified() )
426 {
427 wxFileName filename = GetCurrentFileName();
428 wxString msg = _( "Save changes to '%s' before closing?" );
429
430 if( !HandleUnsavedChanges( this, wxString::Format( msg, filename.GetFullName() ),
431 [&]() -> bool
432 {
433 return saveCurrentPageLayout();
434 } ) )
435 {
436 return false;
437 }
438 }
439
440 return true;
441}
442
443
445{
446 // do not show the window because we do not want any paint event
447 Show( false );
448
449 // clean up the data before the view is destroyed
451
452 // On Linux, m_propertiesPagelayout must be destroyed
453 // before deleting the main frame to avoid a crash when closing
454 m_propertiesPagelayout->Destroy();
455 Destroy();
456}
457
458
459void PL_EDITOR_FRAME::OnSelectPage( wxCommandEvent& event )
460{
461 KIGFX::VIEW* view = GetCanvas()->GetView();
462 view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGE1, m_pageSelectBox->GetSelection() == 0 );
463 view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGEn, m_pageSelectBox->GetSelection() == 1 );
464 GetCanvas()->Refresh();
465}
466
467
469{
470 m_originSelectChoice = m_originSelectBox->GetSelection();
471 UpdateStatusBar(); // Update grid origin
473 GetCanvas()->Refresh();
474}
475
476
477void PL_EDITOR_FRAME::ToPrinter( bool doPreview )
478{
479 // static print data and page setup data, to remember settings during the session
480 static wxPrintData* s_PrintData;
481 static wxPageSetupDialogData* s_pageSetupData = nullptr;
482
483 const PAGE_INFO& pageInfo = GetPageSettings();
484
485 if( s_PrintData == nullptr ) // First print
486 {
487 s_PrintData = new wxPrintData();
488 s_PrintData->SetQuality( wxPRINT_QUALITY_HIGH ); // Default resolution = HIGH;
489 }
490
491 if( !s_PrintData->Ok() )
492 {
493 wxMessageBox( _( "Error Init Printer info" ) );
494 return;
495 }
496
497 if( s_pageSetupData == nullptr )
498 s_pageSetupData = new wxPageSetupDialogData( *s_PrintData );
499
500 s_pageSetupData->SetPaperId( pageInfo.GetPaperId() );
501 s_pageSetupData->GetPrintData().SetOrientation( pageInfo.GetWxOrientation() );
502
503 if( pageInfo.IsCustom() )
504 {
505 if( pageInfo.IsPortrait() )
506 s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ),
507 EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ) ) );
508 else
509 s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ),
510 EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ) ) );
511 }
512
513 *s_PrintData = s_pageSetupData->GetPrintData();
514
515 if( doPreview )
516 InvokeDialogPrintPreview( this, s_PrintData );
517 else
518 InvokeDialogPrint( this, s_PrintData, s_pageSetupData );
519}
520
521
522const BOX2I PL_EDITOR_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
523{
524 BOX2I rv( VECTOR2I( 0, 0 ), GetPageLayout().GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS ) );
525 return rv;
526}
527
528
530{
532
533 PL_EDITOR_SETTINGS* cfg = dynamic_cast<PL_EDITOR_SETTINGS*>( aCfg );
534 wxCHECK( cfg, /*void*/ );
535
538
540
543
544 PAGE_INFO pageInfo = GetPageSettings();
545 pageInfo.SetType( cfg->m_LastPaperSize, cfg->m_LastWasPortrait );
546 SetPageSettings( pageInfo );
547}
548
549
551{
553
554 auto cfg = static_cast<PL_EDITOR_SETTINGS*>( aCfg );
555
557
558 cfg->m_PropertiesFrameWidth = m_propertiesFrameWidth;
559 cfg->m_PropertiesSplitter = m_propertiesPagelayout->SplitterProportion();
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 m_grid_origin = aPoint;
660
661 if( PL_DRAW_PANEL_GAL* canvas = GetCanvas() )
662 {
663 canvas->GetGAL()->SetGridOrigin( VECTOR2D( aPoint ) );
664 canvas->GetView()->MarkDirty();
665 }
666}
667
668
670{
671 // calculate the position (in page, in iu) of the corner used as coordinate origin
672 // coordinate origin can be the paper Top Left corner, or each of 4 page corners
673 VECTOR2I originCoord;
674
675 // To avoid duplicate code, we use a dummy segment starting at 0,0 in relative coord
677
678 switch( m_originSelectChoice )
679 {
680 default:
681 case 0: // Origin = paper Left Top corner
682 break;
683
684 case 1: // Origin = page Right Bottom corner
685 dummy.SetStart( 0, 0, RB_CORNER );
686 originCoord = dummy.GetStartPosIU();
687 break;
688
689 case 2: // Origin = page Left Bottom corner
690 dummy.SetStart( 0, 0, LB_CORNER );
691 originCoord = dummy.GetStartPosIU();
692 break;
693
694 case 3: // Origin = page Right Top corner
695 dummy.SetStart( 0, 0, RT_CORNER );
696 originCoord = dummy.GetStartPosIU();
697 break;
698
699 case 4: // Origin = page Left Top corner
700 dummy.SetStart( 0, 0, LT_CORNER );
701 originCoord = dummy.GetStartPosIU();
702 break;
703 }
704
705 return originCoord;
706}
707
708
710{
711 wxString line;
712 wxString gridformatter;
713
714 switch( GetUserUnits() )
715 {
716 case EDA_UNITS::INCH: gridformatter = wxS( "grid %.3f" ); break;
717 case EDA_UNITS::MM: gridformatter = wxS( "grid %.4f" ); break;
718 default: gridformatter = wxS( "grid %f" ); break;
719 }
720
722 GetCanvas()->GetGAL()->GetGridSize().x );
723 line.Printf( gridformatter, grid );
724
725 SetStatusText( line, 4 );
726}
727
728
730{
731 // Display Zoom level:
732 SetStatusText( GetZoomLevelIndicator(), 1 );
733
734 // coordinate origin can be the paper Top Left corner, or each of 4 page corners
735 VECTOR2I originCoord = ReturnCoordOriginCorner();
736
737 // We need the orientation of axis (sign of coordinates)
738 int Xsign = 1;
739 int Ysign = 1;
740
741 switch( m_originSelectChoice )
742 {
743 default:
744 case 0: // Origin = paper Left Top corner
745 break;
746
747 case 1: // Origin = page Right Bottom corner
748 Xsign = -1;
749 Ysign = -1;
750 break;
751
752 case 2: // Origin = page Left Bottom corner
753 Ysign = -1;
754 break;
755
756 case 3: // Origin = page Right Top corner
757 Xsign = -1;
758 break;
759
760 case 4: // Origin = page Left Top corner
761 break;
762 }
763
764 // Display absolute coordinates:
766 VECTOR2D coord = cursorPos - originCoord;
767 double dXpos = EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, GetUserUnits(), coord.x * Xsign );
768 double dYpos = EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, GetUserUnits(), coord.y * Ysign );
769
770 wxString absformatter = wxT( "X %.4g Y %.4g" );
771 wxString locformatter = wxT( "dx %.4g dy %.4g" );
772
773 switch( GetUserUnits() )
774 {
775 case EDA_UNITS::INCH: SetStatusText( _( "inches" ), 6 ); break;
776 case EDA_UNITS::MILS: SetStatusText( _( "mils" ), 6 ); break;
777 case EDA_UNITS::MM: SetStatusText( _( "mm" ), 6 ); break;
778 case EDA_UNITS::UNSCALED: SetStatusText( wxEmptyString, 6 ); break;
779 default: wxASSERT( false ); break;
780 }
781
782 wxString line;
783
784 // Display abs coordinates
785 line.Printf( absformatter, dXpos, dYpos );
786 SetStatusText( line, 2 );
787
788 // Display relative coordinates:
789 if( GetScreen() )
790 {
791 double dx = cursorPos.x - GetScreen()->m_LocalOrigin.x;
792 double dy = cursorPos.y - GetScreen()->m_LocalOrigin.y;
795 line.Printf( locformatter, dXpos, dYpos );
796 SetStatusText( line, 3 );
797 }
798
800
801 // Display corner reference for coord origin
802 line.Printf( _("coord origin: %s"),
803 m_originSelectBox->GetString( m_originSelectChoice ).GetData() );
804 SetStatusText( line, 5 );
805}
806
807
812
813
815{
816 return m_toolManager->GetTool<PL_SELECTION_TOOL>()->GetSelection();
817}
818
819
828
829
831{
832 DS_DATA_ITEM * item = nullptr;
833
834 switch( aType )
835 {
837 item = new DS_DATA_ITEM_TEXT( wxT( "Text") );
838 break;
839
842 break;
843
846 break;
847
849 item = new DS_DATA_ITEM_POLYGONS();
850 break;
851
853 {
854 wxFileDialog fileDlg( this, _( "Choose Image" ), m_mruImagePath, wxEmptyString,
855 FILEEXT::ImageFileWildcard(), wxFD_OPEN );
856
858
859 if( fileDlg.ShowModal() != wxID_OK )
860 return nullptr;
861
862 wxString fullFilename = fileDlg.GetPath();
863 m_mruImagePath = wxPathOnly( fullFilename );
864
865 if( !wxFileExists( fullFilename ) )
866 {
867 wxMessageBox( _( "Could not load image from '%s'." ), fullFilename );
868 break;
869 }
870
872
873 if( !image->ReadImageFile( fullFilename ) )
874 {
875 wxMessageBox( _( "Could not load image from '%s'." ), fullFilename );
876 delete image;
877 break;
878 }
879
880 // Set the scale factor for pl_editor (it is set for Eeschema by default)
881 image->SetPixelSizeIu( drawSheetIUScale.IU_PER_MILS * 1000.0 / image->GetPPI() );
882 item = new DS_DATA_ITEM_BITMAP( image );
883 break;
884 }
885 }
886
887 if( item == nullptr )
888 return nullptr;
889
890 SyncDataItem( item );
891
892 return item;
893}
894
895
897{
899 dummy.SetPaperFormat( GetPageSettings().GetTypeAsString() );
900 dummy.SetTitleBlock( &GetTitleBlock() );
901 dummy.SetProject( &Prj() );
902
903 aItem->SyncDrawItems( &dummy, GetCanvas()->GetView() );
904}
905
906
908{
910 GetScreen()->SetContentModified( false );
912
913 m_propertiesPagelayout->UpdateData();
914
916
918
919 if( GetCurrentFileName().IsEmpty() )
920 {
921 // Default shutdown reason until a file is loaded
922 KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New drawing sheet file is unsaved" ) );
923 }
924 else
925 {
926 KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Drawing sheet changes are unsaved" ) );
927 }
928}
929
930
932{
933 if( aItemCount == 0 )
934 return;
935
936 UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
937
938 if( aItemCount < 0 )
939 {
940 list.ClearCommandList();
941 }
942 else
943 {
944 for( int ii = 0; ii < aItemCount; ii++ )
945 {
946 if( list.m_CommandsList.size() == 0 )
947 break;
948
949 PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
950 list.m_CommandsList.erase( list.m_CommandsList.begin() );
951
952 curr_cmd->ClearListAndDeleteItems( []( EDA_ITEM* aItem )
953 {
954 delete aItem;
955 } );
956 delete curr_cmd; // Delete command
957 }
958 }
959}
960
961
963{
964 return m_pageSelectBox->GetSelection() == 0;
965}
966
967#if 1
969{
970 VECTOR2D size = GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS );
971
972 std::vector<MSG_PANEL_ITEM> msgItems;
973 msgItems.emplace_back( _( "Page Width" ), MessageTextFromValue( size.x ) );
974 msgItems.emplace_back( _( "Page Height" ), MessageTextFromValue( size.y ) );
975
976 SetMsgPanel( msgItems );
977}
978#endif
979
980void PL_EDITOR_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
981{
983
984 if( m_spaceMouse )
985 m_spaceMouse->SetFocus( aEvent.GetActive() );
986}
987
988
989void PL_EDITOR_FRAME::handleIconizeEvent( wxIconizeEvent& aEvent )
990{
992
993 if( m_spaceMouse )
994 m_spaceMouse->SetFocus( false );
995}
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:917
static TOOL_ACTION toggleGrid
Definition actions.h:195
static TOOL_ACTION paste
Definition actions.h:77
static TOOL_ACTION copy
Definition actions.h:75
static TOOL_ACTION undo
Definition actions.h:72
static TOOL_ACTION doDelete
Definition actions.h:82
static TOOL_ACTION selectionTool
Definition actions.h:248
static TOOL_ACTION save
Definition actions.h:54
static TOOL_ACTION zoomFitScreen
Definition actions.h:139
static TOOL_ACTION redo
Definition actions.h:73
static TOOL_ACTION deleteTool
Definition actions.h:83
static TOOL_ACTION zoomTool
Definition actions.h:143
static TOOL_ACTION cut
Definition actions.h:74
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...
bool isBlockableSessionEnd() const
Return true when the session is ending on a platform that shows a shutdown block reason.
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:2474
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:826
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
@ FOR_CANVAS
Definition common.h:92
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:178
#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
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:741
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.