From 6936effaa7e26813f2938a759068b4d9f45a2e5e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 26 May 2019 16:36:40 +0100 Subject: [PATCH] Implement undo for Page Settings in PlEditor, Eeschema and PCBNew. Fixes: lp:1820059 * https://bugs.launchpad.net/kicad/+bug/1820059 --- common/CMakeLists.txt | 3 +- common/dialogs/dialog_page_settings.cpp | 48 +- common/legacy_gal/eda_draw_frame.cpp | 33 -- common/legacy_wx/eda_draw_frame.cpp | 57 +- common/page_layout/page_layout_reader.cpp | 2 +- common/page_layout/ws_data_item.cpp | 2 +- common/page_layout/ws_data_model.cpp | 32 +- common/page_layout/ws_proxy_undo_item.cpp | 92 +++ ...s_view_item.cpp => ws_proxy_view_item.cpp} | 32 +- common/tool/action_menu.cpp | 2 +- common/tool/actions.cpp | 7 +- common/widgets/widget_hotkey_list.cpp | 6 +- eeschema/menubar.cpp | 4 +- eeschema/sch_draw_panel.cpp | 2 +- eeschema/sch_preview_panel.cpp | 2 +- eeschema/sch_view.cpp | 8 +- eeschema/sch_view.h | 6 +- eeschema/schematic_undo_redo.cpp | 66 ++- eeschema/toolbars_sch_editor.cpp | 2 +- eeschema/tools/sch_editor_control.cpp | 21 +- gerbview/gerbview_draw_panel_gal.cpp | 4 +- gerbview/gerbview_draw_panel_gal.h | 8 +- gerbview/gerbview_frame.cpp | 2 +- include/core/typeinfo.h | 3 +- include/draw_frame.h | 28 - include/id.h | 8 +- include/page_info.h | 6 +- include/pcb_screen.h | 4 - include/tool/actions.h | 3 +- include/undo_redo_container.h | 3 +- include/ws_data_model.h | 2 +- include/ws_proxy_undo_item.h | 62 ++ .../{ws_view_item.h => ws_proxy_view_item.h} | 16 +- pagelayout_editor/CMakeLists.txt | 1 - pagelayout_editor/menubar.cpp | 2 +- pagelayout_editor/pl_draw_panel_gal.cpp | 2 +- pagelayout_editor/pl_draw_panel_gal.h | 4 +- pagelayout_editor/pl_editor_frame.cpp | 26 +- pagelayout_editor/pl_editor_frame.h | 50 +- pagelayout_editor/pl_editor_layout.h | 20 +- pagelayout_editor/pl_editor_undo_redo.cpp | 184 +++--- pagelayout_editor/toolbars_pl_editor.cpp | 2 +- pagelayout_editor/tools/pl_editor_control.cpp | 21 +- pcbnew/class_board.cpp | 2 +- pcbnew/dialogs/dialog_print_pcbnew.cpp | 34 +- pcbnew/footprint_edit_frame.cpp | 6 + pcbnew/footprint_editor_utils.cpp | 7 - pcbnew/menubar_pcb_editor.cpp | 557 +++++++----------- pcbnew/pcb_base_edit_frame.h | 11 +- pcbnew/pcb_draw_panel_gal.cpp | 4 +- pcbnew/pcb_draw_panel_gal.h | 6 +- pcbnew/pcb_edit_frame.cpp | 23 +- pcbnew/pcb_edit_frame.h | 2 - pcbnew/ratsnest_viewitem.h | 4 +- pcbnew/toolbars_pcb_editor.cpp | 21 +- pcbnew/tools/pcb_editor_control.cpp | 76 ++- pcbnew/tools/pcb_editor_control.h | 8 + pcbnew/tools/pcbnew_control.cpp | 11 + pcbnew/tools/pcbnew_control.h | 3 + pcbnew/undo_redo.cpp | 51 +- 60 files changed, 822 insertions(+), 892 deletions(-) create mode 100644 common/page_layout/ws_proxy_undo_item.cpp rename common/page_layout/{ws_view_item.cpp => ws_proxy_view_item.cpp} (82%) create mode 100644 include/ws_proxy_undo_item.h rename include/{ws_view_item.h => ws_proxy_view_item.h} (92%) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index ed1f3fffda..1589fc3e3f 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -36,7 +36,6 @@ set( GAL_SRCS newstroke_font.cpp painter.cpp text_utils.cpp - page_layout/ws_view_item.cpp gal/color4d.cpp gal/gal_display_options.cpp gal/graphics_abstraction_layer.cpp @@ -241,6 +240,8 @@ set( COMMON_PAGE_LAYOUT_SRCS page_layout/ws_data_model_io.cpp page_layout/page_layout_default_description.cpp page_layout/ws_draw_item.cpp + page_layout/ws_proxy_undo_item.cpp + page_layout/ws_proxy_view_item.cpp page_layout/page_layout_reader_keywords.cpp page_layout/page_layout_reader.cpp ) diff --git a/common/dialogs/dialog_page_settings.cpp b/common/dialogs/dialog_page_settings.cpp index 97b96a87f6..be364c5b5f 100644 --- a/common/dialogs/dialog_page_settings.cpp +++ b/common/dialogs/dialog_page_settings.cpp @@ -22,7 +22,6 @@ */ #include -#include // arrayDim() #include #include #include @@ -34,7 +33,7 @@ #include #include #include - +#include #include #include @@ -45,6 +44,7 @@ #include #include +#include #define MAX_PAGE_EXAMPLE_SIZE 200 @@ -75,44 +75,6 @@ static const wxString pageFmts[] = // to be recognized in code }; -void EDA_DRAW_FRAME::Process_PageSettings( wxCommandEvent& event ) -{ - FRAME_T smallSizeFrames[] = - { - FRAME_PCB, FRAME_PCB_MODULE_EDITOR, FRAME_PCB_MODULE_VIEWER, - FRAME_PCB_MODULE_VIEWER_MODAL, FRAME_PCB_FOOTPRINT_WIZARD, - FRAME_PCB_FOOTPRINT_PREVIEW, - FRAME_CVPCB_DISPLAY - }; - - // Fix the max page size: it is MAX_PAGE_SIZE_EDITORS - // or MAX_PAGE_SIZE_PCBNEW for Pcbnew draw frames, due to the small internal - // units that do not allow too large draw areas - wxSize maxPageSize( MAX_PAGE_SIZE_EDITORS_MILS, MAX_PAGE_SIZE_EDITORS_MILS ); - - for( unsigned ii = 0; ii < arrayDim( smallSizeFrames ); ii++ ) - { - if( IsType( smallSizeFrames[ii] ) ) - { - maxPageSize.x = maxPageSize.y = MAX_PAGE_SIZE_PCBNEW_MILS; - break; - } - } - - DIALOG_PAGES_SETTINGS dlg( this, maxPageSize ); - dlg.SetWksFileName( BASE_SCREEN::m_PageLayoutDescrFileName ); - - if( dlg.ShowModal() == wxID_OK ) - { -#ifdef EESCHEMA - RedrawScreen( wxPoint( 0, 0 ), false ); -#else - GetCanvas()->Refresh(); -#endif - } -} - - DIALOG_PAGES_SETTINGS::DIALOG_PAGES_SETTINGS( EDA_DRAW_FRAME* parent, wxSize aMaxUserSizeMils ) : DIALOG_PAGES_SETTINGS_BASE( parent ), m_initialized( false ), @@ -157,10 +119,10 @@ void DIALOG_PAGES_SETTINGS::initDialog() // The first shows translated strings, the second contains not translated strings m_paperSizeComboBox->Clear(); - for( unsigned ii = 0; ii < arrayDim(pageFmts); ii++ ) + for( const wxString& pageFmt : pageFmts ) { - m_pageFmt.Add( pageFmts[ii] ); - m_paperSizeComboBox->Append( wxGetTranslation( pageFmts[ii] ) ); + m_pageFmt.Add( pageFmt ); + m_paperSizeComboBox->Append( wxGetTranslation( pageFmt ) ); } // initialize the page layout descr filename diff --git a/common/legacy_gal/eda_draw_frame.cpp b/common/legacy_gal/eda_draw_frame.cpp index 2d196d788c..53d31ec601 100644 --- a/common/legacy_gal/eda_draw_frame.cpp +++ b/common/legacy_gal/eda_draw_frame.cpp @@ -321,12 +321,6 @@ void EDA_DRAW_FRAME::SkipNextLeftButtonReleaseEvent() } -void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent ) -{ - wxFAIL_MSG( "Obsolete! Should go through EDITOR_CONTROL." ); -} - - bool EDA_DRAW_FRAME::GetToolToggled( int aToolId ) { // Checks all the toolbars and returns true if the given tool id is toggled. @@ -338,26 +332,6 @@ bool EDA_DRAW_FRAME::GetToolToggled( int aToolId ) } -void EDA_DRAW_FRAME::OnToggleCrossHairStyle( wxCommandEvent& aEvent ) -{ - wxFAIL_MSG( "Obsolete! Should go through EDITOR_CONTROL." ); -} - - -void EDA_DRAW_FRAME::OnUpdateUndo( wxUpdateUIEvent& aEvent ) -{ - if( GetScreen() ) - aEvent.Enable( GetScreen()->GetUndoCommandCount() > 0 ); -} - - -void EDA_DRAW_FRAME::OnUpdateRedo( wxUpdateUIEvent& aEvent ) -{ - if( GetScreen() ) - aEvent.Enable( GetScreen()->GetRedoCommandCount() > 0 ); -} - - void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent ) { // No need to update the grid select box if it doesn't exist or the grid setting change @@ -508,13 +482,6 @@ void EDA_DRAW_FRAME::SetNoToolSelected() } -wxPoint EDA_DRAW_FRAME::GetGridPosition( const wxPoint& aPosition ) const -{ - wxFAIL_MSG( "Obsolete! Should go through COMMON_TOOLS." ); - return aPosition; -} - - void EDA_DRAW_FRAME::SetNextGrid() { wxFAIL_MSG( "Obsolete! Should go through COMMON_TOOLS." ); diff --git a/common/legacy_wx/eda_draw_frame.cpp b/common/legacy_wx/eda_draw_frame.cpp index 5746b27a89..10566bd3e3 100644 --- a/common/legacy_wx/eda_draw_frame.cpp +++ b/common/legacy_wx/eda_draw_frame.cpp @@ -347,20 +347,6 @@ void EDA_DRAW_FRAME::SkipNextLeftButtonReleaseEvent() } -void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent ) -{ - SetGridVisibility( !IsGridVisible() ); - - if( IsGalCanvasActive() ) - { - GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() ); - GetGalCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); - } - - m_canvas->Refresh(); -} - - bool EDA_DRAW_FRAME::GetToolToggled( int aToolId ) { // Checks all the toolbars and returns true if the given tool id is toggled. @@ -372,19 +358,6 @@ bool EDA_DRAW_FRAME::GetToolToggled( int aToolId ) } -void EDA_DRAW_FRAME::OnToggleCrossHairStyle( wxCommandEvent& aEvent ) -{ - INSTALL_UNBUFFERED_DC( dc, m_canvas ); - m_canvas->CrossHairOff( &dc ); - - auto& galOpts = GetGalDisplayOptions(); - galOpts.m_fullscreenCursor = !galOpts.m_fullscreenCursor; - galOpts.NotifyChanged(); - - m_canvas->CrossHairOn( &dc ); -} - - void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent ) { // No need to update the grid select box if it doesn't exist or the grid setting change @@ -408,12 +381,6 @@ void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent ) } -void EDA_DRAW_FRAME::OnUpdateCrossHairStyle( wxUpdateUIEvent& aEvent ) -{ - aEvent.Check( GetGalDisplayOptions().m_fullscreenCursor ); -} - - void EDA_DRAW_FRAME::ReCreateAuxiliaryToolbar() { } @@ -620,17 +587,6 @@ void EDA_DRAW_FRAME::SetNoToolSelected() } -wxPoint EDA_DRAW_FRAME::GetGridPosition( const wxPoint& aPosition ) const -{ - wxPoint pos = aPosition; - - if( m_currentScreen != NULL && m_snapToGrid ) - pos = GetNearestGridPosition( aPosition ); - - return pos; -} - - void EDA_DRAW_FRAME::SetNextGrid() { BASE_SCREEN * screen = GetScreen(); @@ -1559,6 +1515,7 @@ bool EDA_DRAW_FRAME::GeneralControlKeyMovement( int aHotKey, wxPoint *aPos, bool void EDA_DRAW_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer ) { + // JEY TODO: OBSOLETE if( IsGalCanvasActive() ) return; @@ -1739,18 +1696,6 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event ) } -void EDA_DRAW_FRAME::SetNextZoom() -{ - GetScreen()->SetNextZoom(); -} - - -void EDA_DRAW_FRAME::SetPrevZoom() -{ - GetScreen()->SetPreviousZoom(); -} - - void EDA_DRAW_FRAME::SetPresetZoom( int aIndex ) { BASE_SCREEN* screen = GetScreen(); diff --git a/common/page_layout/page_layout_reader.cpp b/common/page_layout/page_layout_reader.cpp index d9301fcb44..255e81130d 100644 --- a/common/page_layout/page_layout_reader.cpp +++ b/common/page_layout/page_layout_reader.cpp @@ -748,7 +748,7 @@ void WS_DATA_MODEL::SetPageLayout( const wxString& aFullFileName, bool Append ) { #if 0 if( !fullFileName.IsEmpty() ) - wxLogMessage( wxT("Page layout file <%s> not found"), fullFileName.GetData() ); + wxLogMessage( wxT( "Page layout file <%s> not found" ), fullFileName.GetData() ); #endif SetDefaultLayout(); return; diff --git a/common/page_layout/ws_data_item.cpp b/common/page_layout/ws_data_item.cpp index 6e2b8c2dc2..e70853a400 100644 --- a/common/page_layout/ws_data_item.cpp +++ b/common/page_layout/ws_data_item.cpp @@ -549,7 +549,7 @@ void WS_DATA_ITEM_TEXT::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIE int pensize = GetPenSizeUi(); bool multilines = false; - if( WS_DATA_MODEL::GetTheInstance().m_SpecialMode ) + if( WS_DATA_MODEL::GetTheInstance().m_EditMode ) m_FullText = m_TextBase; else { diff --git a/common/page_layout/ws_data_model.cpp b/common/page_layout/ws_data_model.cpp index 9c17df00d0..7864a5d67a 100644 --- a/common/page_layout/ws_data_model.cpp +++ b/common/page_layout/ws_data_model.cpp @@ -25,23 +25,23 @@ /* - * the class WS_DATA_ITEM (and derived ) defines - * a basic shape of a page layout ( frame references and title block ) - * The list of these items is stored in a WS_DATA_MODEL instance. + * The WS_DATA_ITEM_* classes define the basic shapes of a page layout (frame references + * and title block). The list of these items is stored in a WS_DATA_MODEL instance. * + * These items cannot be drawn or plotetd "as is". They must be converted to WS_DRAW_* + * types. When building the draw list: + * - the WS_DATA_MODEL is used to create a WS_DRAW_ITEM_LIST + * - coordinates are converted to draw/plot coordinates. + * - texts are expanded if they contain format symbols. + * - items with m_RepeatCount > 1 are created m_RepeatCount times. * - * These items cannot be drawn or plot "as this". they should be converted - * to a "draw list". When building the draw list: - * the WS_DATA_MODEL is used to create a WS_DRAW_ITEM_LIST - * coordinates are converted to draw/plot coordinates. - * texts are expanded if they contain format symbols. - * Items with m_RepeatCount > 1 are created m_RepeatCount times + * The WS_DATA_MODEL is created only once. + * The WS_DRAW_ITEM_*s are created and maintained by the PlEditor, but are created each time + * they're needed for drawing by the clients (Eeschema, Pcbnew, etc.) * - * the WS_DATA_MODEL is created only once. - * the WS_DRAW_ITEM_LIST is created each time the page layout is plot/drawn - * - * the WS_DATA_MODEL instance is created from a S expression which - * describes the page layout (can be the default page layout or a custom file). + * The WS_DATA_MODEL instance is created from a S expression which describes the page + * layout (can be the default page layout or a custom file). This format is also used + * for undo/redo storage (wrapped in a WS_PROXY_UNDO_ITEM). */ #include @@ -63,7 +63,7 @@ WS_DATA_MODEL::WS_DATA_MODEL() : m_DefaultLineWidth( 0.0 ), m_DefaultTextSize( TB_DEFAULT_TEXTSIZE, TB_DEFAULT_TEXTSIZE ), m_DefaultTextThickness( 0.0 ), - m_SpecialMode( false ) + m_EditMode( false ) { m_allowVoidList = false; m_leftMargin = 10.0; // the left page margin in mm @@ -158,7 +158,7 @@ WS_DATA_ITEM* WS_DATA_MODEL::GetItem( unsigned aIdx ) const if( aIdx < m_list.size() ) return m_list[aIdx]; else - return NULL; + return nullptr; } diff --git a/common/page_layout/ws_proxy_undo_item.cpp b/common/page_layout/ws_proxy_undo_item.cpp new file mode 100644 index 0000000000..6f2e869818 --- /dev/null +++ b/common/page_layout/ws_proxy_undo_item.cpp @@ -0,0 +1,92 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2019 Kicad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include +#include +#include + +using namespace KIGFX; + +WS_PROXY_UNDO_ITEM::WS_PROXY_UNDO_ITEM( const EDA_DRAW_FRAME* aFrame ) : + EDA_ITEM( aFrame ? WS_PROXY_UNDO_ITEM_PLUS_T : WS_PROXY_UNDO_ITEM_T ), + m_selectedDataItem( INT_MAX ), + m_selectedDrawItem( INT_MAX ) +{ + if( aFrame ) + { + m_pageInfo = aFrame->GetPageSettings(); + m_titleBlock = aFrame->GetTitleBlock(); + } + + WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance(); + model.SaveInString( m_layoutSerialization ); + + for( int ii = 0; ii < model.GetItems().size(); ++ii ) + { + WS_DATA_ITEM* dataItem = model.GetItem( ii ); + + for( int jj = 0; jj < dataItem->GetDrawItems().size(); ++jj ) + { + WS_DRAW_ITEM_BASE* drawItem = dataItem->GetDrawItems()[ jj ]; + + if( drawItem->IsSelected() ) + { + m_selectedDataItem = ii; + m_selectedDrawItem = jj; + break; + } + } + } +} + + +void WS_PROXY_UNDO_ITEM::Restore( EDA_DRAW_FRAME* aFrame, KIGFX::VIEW* aView ) +{ + if( Type() == WS_PROXY_UNDO_ITEM_PLUS_T ) + { + aFrame->SetPageSettings( m_pageInfo ); + aFrame->SetTitleBlock( m_titleBlock ); + } + + WS_DATA_MODEL::GetTheInstance().SetPageLayout( TO_UTF8( m_layoutSerialization ) ); + + if( aView ) + { + aView->Clear(); + + for( int ii = 0; ii < WS_DATA_MODEL::GetTheInstance().GetItems().size(); ++ii ) + { + WS_DATA_ITEM* dataItem = WS_DATA_MODEL::GetTheInstance().GetItem( ii ); + + dataItem->SyncDrawItems( nullptr, aView ); + + if( ii == m_selectedDataItem && m_selectedDrawItem < dataItem->GetDrawItems().size() ) + { + WS_DRAW_ITEM_BASE* drawItem = dataItem->GetDrawItems()[ m_selectedDrawItem ]; + drawItem->SetSelected(); + } + } + } +} + diff --git a/common/page_layout/ws_view_item.cpp b/common/page_layout/ws_proxy_view_item.cpp similarity index 82% rename from common/page_layout/ws_view_item.cpp rename to common/page_layout/ws_proxy_view_item.cpp index de38aa31a4..5112f24d8f 100644 --- a/common/page_layout/ws_view_item.cpp +++ b/common/page_layout/ws_proxy_view_item.cpp @@ -22,12 +22,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file worksheet_viewitem.cpp - * @brief Class that handles properties and drawing of worksheet layout. - */ - -#include +#include #include #include #include @@ -39,26 +34,31 @@ using namespace KIGFX; -WS_VIEW_ITEM::WS_VIEW_ITEM( int aMils2IUscalefactor, - const PAGE_INFO* aPageInfo, const TITLE_BLOCK* aTitleBlock ) : - EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type - m_mils2IUscalefactor( aMils2IUscalefactor ), - m_titleBlock( aTitleBlock ), m_pageInfo( aPageInfo ), m_sheetNumber( 1 ), m_sheetCount( 1 ) {} +WS_PROXY_VIEW_ITEM::WS_PROXY_VIEW_ITEM( int aMils2IUscalefactor, const PAGE_INFO* aPageInfo, + const TITLE_BLOCK* aTitleBlock ) : + EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type + m_mils2IUscalefactor( aMils2IUscalefactor ), + m_titleBlock( aTitleBlock ), + m_pageInfo( aPageInfo ), + m_sheetNumber( 1 ), + m_sheetCount( 1 ) +{ +} -void WS_VIEW_ITEM::SetPageInfo( const PAGE_INFO* aPageInfo ) +void WS_PROXY_VIEW_ITEM::SetPageInfo( const PAGE_INFO* aPageInfo ) { m_pageInfo = aPageInfo; } -void WS_VIEW_ITEM::SetTitleBlock( const TITLE_BLOCK* aTitleBlock ) +void WS_PROXY_VIEW_ITEM::SetTitleBlock( const TITLE_BLOCK* aTitleBlock ) { m_titleBlock = aTitleBlock; } -const BOX2I WS_VIEW_ITEM::ViewBBox() const +const BOX2I WS_PROXY_VIEW_ITEM::ViewBBox() const { BOX2I bbox; @@ -77,7 +77,7 @@ const BOX2I WS_VIEW_ITEM::ViewBBox() const } -void WS_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const +void WS_PROXY_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const { auto gal = aView->GetGAL(); auto settings = aView->GetPainter()->GetSettings(); @@ -127,7 +127,7 @@ void WS_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const } -void WS_VIEW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const +void WS_PROXY_VIEW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const { aCount = 1; aLayers[0] = LAYER_WORKSHEET; diff --git a/common/tool/action_menu.cpp b/common/tool/action_menu.cpp index 7af205c4e4..d266707e4f 100644 --- a/common/tool/action_menu.cpp +++ b/common/tool/action_menu.cpp @@ -503,7 +503,7 @@ wxMenuItem* ACTION_MENU::appendCopy( const wxMenuItem* aSource ) // our predefined checked alternate bitmap const wxBitmap& src_bitmap = aSource->GetBitmap(); - if( src_bitmap.GetHeight() > 1 ) // a null bitmap has a 0 size + if( src_bitmap.IsOk() && src_bitmap.GetHeight() > 1 ) // a null bitmap has a 0 size AddBitmapToMenuItem( newItem, src_bitmap ); if( aSource->IsSubMenu() ) diff --git a/common/tool/actions.cpp b/common/tool/actions.cpp index 4445a4edb1..0aae5a613b 100644 --- a/common/tool/actions.cpp +++ b/common/tool/actions.cpp @@ -24,12 +24,17 @@ TOOL_ACTION ACTIONS::saveAs( "common.Control.saveAs", _( "Save As..." ), _( "Save current document to another location" ), save_as_xpm ); +TOOL_ACTION ACTIONS::saveCopyAs( "common.Control.saveCopyAs", + AS_GLOBAL, 0, + _( "Save Copy As..." ), _( "Save a copy of the current document to another location" ), + save_as_xpm ); + TOOL_ACTION ACTIONS::saveAll( "common.Control.saveAll", AS_GLOBAL, 0, _( "Save All" ), _( "Save all changes" ), save_xpm ); -TOOL_ACTION ACTIONS::pageSetup( "common.Control.pageSetup", +TOOL_ACTION ACTIONS::pageSettings( "common.Control.pageSettings", AS_GLOBAL, 0, _( "Page Settings..." ), _( "Settings for paper size and frame references" ), sheetset_xpm ); diff --git a/common/widgets/widget_hotkey_list.cpp b/common/widgets/widget_hotkey_list.cpp index d89b005b4b..67ccf0e2b7 100644 --- a/common/widgets/widget_hotkey_list.cpp +++ b/common/widgets/widget_hotkey_list.cpp @@ -43,7 +43,7 @@ static const int HOTKEY_MIN_WIDTH = 100; */ enum ID_WHKL_MENU_IDS { - ID_EDIT = 2001, + ID_EDIT_HOTKEY = 2001, ID_RESET, ID_DEFAULT, ID_RESET_ALL, @@ -426,7 +426,7 @@ void WIDGET_HOTKEY_LIST::OnContextMenu( wxTreeListEvent& aEvent ) // Some actions only apply if the row is hotkey data if( hkdata ) { - menu.Append( ID_EDIT, _( "Edit..." ) ); + menu.Append( ID_EDIT_HOTKEY, _( "Edit..." ) ); menu.Append( ID_RESET, _( "Undo Changes" ) ); menu.Append( ID_DEFAULT, _( "Restore Default" ) ); menu.Append( wxID_SEPARATOR ); @@ -443,7 +443,7 @@ void WIDGET_HOTKEY_LIST::OnMenu( wxCommandEvent& aEvent ) { switch( aEvent.GetId() ) { - case ID_EDIT: + case ID_EDIT_HOTKEY: EditItem( m_context_menu_item ); break; diff --git a/eeschema/menubar.cpp b/eeschema/menubar.cpp index 180a07e9f4..f4dcc40556 100644 --- a/eeschema/menubar.cpp +++ b/eeschema/menubar.cpp @@ -94,7 +94,7 @@ void SCH_EDIT_FRAME::ReCreateMenuBar() fileMenu->AddItem( ACTIONS::saveAs, EE_CONDITIONS::ShowAlways ); fileMenu->AddItem( ACTIONS::saveAll, modifiedDocumentCondition ); - fileMenu->AppendSeparator(); + fileMenu->AddSeparator(); fileMenu->AddItem( ID_APPEND_PROJECT, _( "Append Schematic Sheet Content..." ), _( "Append schematic sheet content from another project to the current sheet" ), @@ -133,7 +133,7 @@ void SCH_EDIT_FRAME::ReCreateMenuBar() fileMenu->AddMenu( submenuExport, EE_CONDITIONS::ShowAlways ); fileMenu->AddSeparator(); - fileMenu->AddItem( ACTIONS::pageSetup, EE_CONDITIONS::ShowAlways ); + fileMenu->AddItem( ACTIONS::pageSettings, EE_CONDITIONS::ShowAlways ); fileMenu->AddItem( ACTIONS::print, EE_CONDITIONS::ShowAlways ); fileMenu->AddItem( ACTIONS::plot, EE_CONDITIONS::ShowAlways ); diff --git a/eeschema/sch_draw_panel.cpp b/eeschema/sch_draw_panel.cpp index ece89a826c..cb9b7cb3ad 100644 --- a/eeschema/sch_draw_panel.cpp +++ b/eeschema/sch_draw_panel.cpp @@ -25,7 +25,7 @@ #include -#include +#include #include #include diff --git a/eeschema/sch_preview_panel.cpp b/eeschema/sch_preview_panel.cpp index c08d70db89..0b880bedb3 100644 --- a/eeschema/sch_preview_panel.cpp +++ b/eeschema/sch_preview_panel.cpp @@ -23,7 +23,7 @@ #include -#include +#include #include diff --git a/eeschema/sch_view.cpp b/eeschema/sch_view.cpp index ad440fb527..24797f2276 100644 --- a/eeschema/sch_view.cpp +++ b/eeschema/sch_view.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -52,9 +52,9 @@ SCH_VIEW::SCH_VIEW( bool aIsDynamic, SCH_BASE_FRAME* aFrame ) : // is acceptable for Pcbnew and Gerbview, but too large for Eeschema due to // very different internal units. // So we have to use a smaller value. - // A full size = 3 * MAX_PAGE_SIZE_EDITORS_MILS size allows a wide margin + // A full size = 3 * MAX_PAGE_SIZE_MILS size allows a wide margin // around the worksheet. - double max_size = MAX_PAGE_SIZE_EDITORS_MILS * IU_PER_MILS * 3.0; + double max_size = MAX_PAGE_SIZE_MILS * IU_PER_MILS * 3.0; m_boundary.SetOrigin( -max_size/4, -max_size/4 ); m_boundary.SetSize( max_size, max_size ); @@ -85,7 +85,7 @@ void SCH_VIEW::DisplaySheet( SCH_SCREEN *aScreen ) for( auto item = aScreen->GetDrawItems(); item; item = item->Next() ) Add( item ); - m_worksheet.reset( new KIGFX::WS_VIEW_ITEM( 1, &aScreen->GetPageSettings(), + m_worksheet.reset( new KIGFX::WS_PROXY_VIEW_ITEM( 1, &aScreen->GetPageSettings(), &aScreen->GetTitleBlock() ) ); m_worksheet->SetSheetNumber( aScreen->m_ScreenNumber ); m_worksheet->SetSheetCount( aScreen->m_NumberOfScreens ); diff --git a/eeschema/sch_view.h b/eeschema/sch_view.h index e27df490d9..f78ad593a1 100644 --- a/eeschema/sch_view.h +++ b/eeschema/sch_view.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include class SCH_SHEET; @@ -61,7 +61,7 @@ static const LAYER_NUM SCH_LAYER_ORDER[] = namespace KIGFX { class VIEW_GROUP; - class WS_VIEW_ITEM; + class WS_PROXY_VIEW_ITEM; namespace PREVIEW { @@ -105,7 +105,7 @@ public: private: SCH_BASE_FRAME* m_frame; // The frame using this view. Can be null. Used mainly // to know the sheet path name when drawing the page layout - std::unique_ptr m_worksheet; + std::unique_ptr m_worksheet; std::unique_ptr m_selectionArea; std::unique_ptr m_preview; std::vector m_ownedItems; diff --git a/eeschema/schematic_undo_redo.cpp b/eeschema/schematic_undo_redo.cpp index f2a8bdedac..efef170628 100644 --- a/eeschema/schematic_undo_redo.cpp +++ b/eeschema/schematic_undo_redo.cpp @@ -37,6 +37,8 @@ #include #include #include +#include +#include /* Functions to undo and redo edit commands. * commands to undo are stored in CurrentScreen->m_UndoList @@ -106,9 +108,9 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( SCH_ITEM* aItem, bool aAppend, const wxPoint& aTransformPoint ) { - PICKED_ITEMS_LIST* commandToUndo = NULL; + PICKED_ITEMS_LIST* commandToUndo = nullptr; - if( aItem == NULL ) + if( !aItem ) return; // Connectivity may change @@ -162,11 +164,11 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( SCH_ITEM* aItem, void SCH_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, - UNDO_REDO_T aTypeCommand, - bool aAppend, - const wxPoint& aTransformPoint ) + UNDO_REDO_T aTypeCommand, + bool aAppend, + const wxPoint& aTransformPoint ) { - PICKED_ITEMS_LIST* commandToUndo = NULL; + PICKED_ITEMS_LIST* commandToUndo = nullptr; if( !aItemsList.GetCount() ) return; @@ -195,11 +197,14 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, // Verify list, and creates data if needed for( unsigned ii = 0; ii < commandToUndo->GetCount(); ii++ ) { - SCH_ITEM* item = (SCH_ITEM*) commandToUndo->GetPickedItem( ii ); - wxASSERT( item ); + SCH_ITEM* sch_item = dynamic_cast( commandToUndo->GetPickedItem( ii ) ); + + // Common items implemented in EDA_DRAW_FRAME will not be SCH_ITEMs. + if( !sch_item ) + continue; // Connectivity may change - item->SetConnectivityDirty(); + sch_item->SetConnectivityDirty(); UNDO_REDO_T command = commandToUndo->GetPickedItemStatus( ii ); @@ -211,14 +216,14 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, switch( command ) { - case UR_CHANGED: /* Create a copy of item */ + case UR_CHANGED: /* If needed, create a copy of item, and put in undo list * in the picker, as link * If this link is not null, the copy is already done */ - if( commandToUndo->GetPickedItemLink( ii ) == NULL ) - commandToUndo->SetPickedItemLink( item->Duplicate( true ), ii ); + if( commandToUndo->GetPickedItemLink( ii ) == nullptr ) + commandToUndo->SetPickedItemLink( sch_item->Duplicate( true ), ii ); wxASSERT( commandToUndo->GetPickedItemLink( ii ) ); break; @@ -230,6 +235,7 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, case UR_NEW: case UR_DELETED: case UR_EXCHANGE_T: + case UR_PAGESETTINGS: break; default: @@ -255,36 +261,44 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRedoCommand ) { - SCH_ITEM* item; - SCH_ITEM* alt_item; - // Undo in the reverse order of list creation: (this can allow stacked changes like the // same item can be changed and deleted in the same complex command). for( int ii = aList->GetCount() - 1; ii >= 0; ii-- ) { UNDO_REDO_T status = aList->GetPickedItemStatus((unsigned) ii ); - item = (SCH_ITEM*) aList->GetPickedItem( (unsigned) ii ); - alt_item = (SCH_ITEM*) aList->GetPickedItemLink( (unsigned) ii ); + EDA_ITEM* eda_item = aList->GetPickedItem( (unsigned) ii ); - item->SetFlags( aList->GetPickerFlags( (unsigned) ii ) ); - item->ClearEditFlags(); - item->ClearTempFlags(); + eda_item->SetFlags( aList->GetPickerFlags( (unsigned) ii ) ); + eda_item->ClearEditFlags(); + eda_item->ClearTempFlags(); if( status == UR_NEW ) { // new items are deleted on undo - RemoveFromScreen( item ); + RemoveFromScreen( eda_item ); aList->SetPickedItemStatus( UR_DELETED, (unsigned) ii ); } - else if (status == UR_DELETED ) + else if( status == UR_DELETED ) { // deleted items are re-inserted on undo - AddToScreen( item ); + AddToScreen( eda_item ); aList->SetPickedItemStatus( UR_NEW, (unsigned) ii ); } - else + else if( status == UR_PAGESETTINGS ) + { + // swap current settings with stored settings + WS_PROXY_UNDO_ITEM alt_item( this ); + WS_PROXY_UNDO_ITEM* item = (WS_PROXY_UNDO_ITEM*) eda_item; + item->Restore( this ); + *item = alt_item; + GetToolManager()->RunAction( ACTIONS::zoomFitScreen ); + } + else if( dynamic_cast( eda_item ) ) { // everthing else is modified in place + + SCH_ITEM* item = (SCH_ITEM*) eda_item; + SCH_ITEM* alt_item = (SCH_ITEM*) aList->GetPickedItemLink( (unsigned) ii ); RemoveFromScreen( item ); switch( status ) @@ -318,8 +332,8 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed break; case UR_EXCHANGE_T: - alt_item->SetNext( NULL ); - alt_item->SetBack( NULL ); + alt_item->SetNext( nullptr ); + alt_item->SetBack( nullptr ); aList->SetPickedItem( alt_item, (unsigned) ii ); aList->SetPickedItemLink( item, (unsigned) ii ); item = alt_item; diff --git a/eeschema/toolbars_sch_editor.cpp b/eeschema/toolbars_sch_editor.cpp index f52576066f..d5a324c3a5 100644 --- a/eeschema/toolbars_sch_editor.cpp +++ b/eeschema/toolbars_sch_editor.cpp @@ -57,7 +57,7 @@ void SCH_EDIT_FRAME::ReCreateHToolbar() m_mainToolBar->Add( ACTIONS::saveAll ); KiScaledSeparator( m_mainToolBar, this ); - m_mainToolBar->Add( ACTIONS::pageSetup ); + m_mainToolBar->Add( ACTIONS::pageSettings ); m_mainToolBar->Add( ACTIONS::print ); m_mainToolBar->Add( ACTIONS::plot ); diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index e5baccb2c2..696a998fd6 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -46,6 +46,8 @@ #include #include #include +#include +#include TOOL_ACTION EE_ACTIONS::refreshPreview( "eeschema.EditorControl.refreshPreview", AS_GLOBAL, 0, "", "" ); @@ -155,8 +157,21 @@ int SCH_EDITOR_CONTROL::SaveAll( const TOOL_EVENT& aEvent ) int SCH_EDITOR_CONTROL::PageSetup( const TOOL_EVENT& aEvent ) { - wxCommandEvent dummy; - m_frame->Process_PageSettings( dummy ); + PICKED_ITEMS_LIST undoCmd; + WS_PROXY_UNDO_ITEM* undoItem = new WS_PROXY_UNDO_ITEM( m_frame ); + ITEM_PICKER wrapper( undoItem, UR_PAGESETTINGS ); + + undoCmd.PushItem( wrapper ); + m_frame->SaveCopyInUndoList( undoCmd, UR_PAGESETTINGS ); + + DIALOG_PAGES_SETTINGS dlg( m_frame, wxSize( MAX_PAGE_SIZE_MILS, MAX_PAGE_SIZE_MILS ) ); + dlg.SetWksFileName( BASE_SCREEN::m_PageLayoutDescrFileName ); + + if( dlg.ShowModal() == wxID_OK ) + m_toolMgr->RunAction( ACTIONS::zoomFitScreen ); + else + m_frame->RollbackSchematicFromUndo(); + return 0; } @@ -1094,7 +1109,7 @@ void SCH_EDITOR_CONTROL::setTransitions() Go( &SCH_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::SaveAs, ACTIONS::saveAs.MakeEvent() ); - Go( &SCH_EDITOR_CONTROL::PageSetup, ACTIONS::pageSetup.MakeEvent() ); + Go( &SCH_EDITOR_CONTROL::PageSetup, ACTIONS::pageSettings.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Quit, ACTIONS::quit.MakeEvent() ); diff --git a/gerbview/gerbview_draw_panel_gal.cpp b/gerbview/gerbview_draw_panel_gal.cpp index 10f7052e21..a0797a3593 100644 --- a/gerbview/gerbview_draw_panel_gal.cpp +++ b/gerbview/gerbview_draw_panel_gal.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include @@ -179,7 +179,7 @@ void GERBVIEW_DRAW_PANEL_GAL::setDefaultLayerDeps() } -void GERBVIEW_DRAW_PANEL_GAL::SetWorksheet( KIGFX::WS_VIEW_ITEM* aWorksheet ) +void GERBVIEW_DRAW_PANEL_GAL::SetWorksheet( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ) { m_worksheet.reset( aWorksheet ); m_view->Add( m_worksheet.get() ); diff --git a/gerbview/gerbview_draw_panel_gal.h b/gerbview/gerbview_draw_panel_gal.h index 0f8d7f0c91..e37933d1d3 100644 --- a/gerbview/gerbview_draw_panel_gal.h +++ b/gerbview/gerbview_draw_panel_gal.h @@ -21,11 +21,11 @@ #define GERBVIEW_DRAW_PANEL_GAL_H_ #include -#include +#include namespace KIGFX { - class WS_VIEW_ITEM; + class WS_PROXY_VIEW_ITEM; } class COLORS_DESIGN_SETTINGS; @@ -69,14 +69,14 @@ public: * @param aWorksheet is the worksheet to be used. * The object is then owned by GERBVIEW_DRAW_PANEL_GAL. */ - void SetWorksheet( KIGFX::WS_VIEW_ITEM* aWorksheet ); + void SetWorksheet( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ); protected: ///> Sets rendering targets & dependencies for layers. void setDefaultLayerDeps(); ///> Currently used worksheet - std::unique_ptr m_worksheet; + std::unique_ptr m_worksheet; }; diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index 1720248a3a..d7d7d2d7df 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -960,7 +960,7 @@ void GERBVIEW_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings ) // Prepare worksheet template auto worksheet = - new KIGFX::WS_VIEW_ITEM( IU_PER_MILS, &GetPageSettings(), &GetTitleBlock() ); + new KIGFX::WS_PROXY_VIEW_ITEM( IU_PER_MILS, &GetPageSettings(), &GetTitleBlock() ); if( screen != NULL ) { diff --git a/include/core/typeinfo.h b/include/core/typeinfo.h index 6a46fe79ab..98ce4a91aa 100644 --- a/include/core/typeinfo.h +++ b/include/core/typeinfo.h @@ -182,7 +182,8 @@ enum KICAD_T WSG_BITMAP_T, // serialized layout used in undo/redo commands - TYPE_PL_EDITOR_LAYOUT, + WS_PROXY_UNDO_ITEM_T, // serialized layout used in undo/redo commands + WS_PROXY_UNDO_ITEM_PLUS_T, // serialized layout plus page and title block settings /* * FOR PROJECT::_ELEMs diff --git a/include/draw_frame.h b/include/draw_frame.h index d7cdda7e4d..0c866c0d6c 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -482,7 +482,6 @@ public: inline double GetZoomLevelCoeff() const { return m_zoomLevelCoeff; } void EraseMsgBox(); - void Process_PageSettings( wxCommandEvent& event ); virtual void ReCreateHToolbar() = 0; virtual void ReCreateVToolbar() = 0; @@ -567,16 +566,6 @@ public: m_gridColor = aColor; } - /** - * Return the nearest grid position to \a aPosition if a screen is defined and snap to - * grid is enabled. Otherwise, the original positions is returned. - * - * @see m_snapToGrid and m_BaseScreen members. - * @param aPosition The position to test. - * @return The wxPoint of the appropriate cursor position. - */ - wxPoint GetGridPosition( const wxPoint& aPosition ) const; - /** * Change the grid size settings to the next one available. */ @@ -617,16 +606,9 @@ public: */ virtual void OnSelectZoom( wxCommandEvent& event ); - // Command event handlers shared by all applications derived from EDA_DRAW_FRAME. - void OnToggleGridState( wxCommandEvent& aEvent ); - void OnToggleCrossHairStyle( wxCommandEvent& aEvent ); - // Update user interface event handlers shared by all applications derived from // EDA_DRAW_FRAME. - void OnUpdateUndo( wxUpdateUIEvent& aEvent ); - void OnUpdateRedo( wxUpdateUIEvent& aEvent ); void OnUpdateSelectGrid( wxUpdateUIEvent& aEvent ); - void OnUpdateCrossHairStyle( wxUpdateUIEvent& aEvent ); /** * Perform application specific control using \a aDC at \a aPosition in logical units. @@ -653,11 +635,6 @@ public: virtual void OnZoom( wxCommandEvent& event ); - /** - * Change the zoom to the next one available. - */ - void SetNextZoom(); - /** * Change the zoom to the next one available redraws the screen * and warp the mouse pointer on request. @@ -667,11 +644,6 @@ public: */ void SetNextZoomAndRedraw( const wxPoint& aCenterPoint, bool aWarpPointer ); - /** - * Change the zoom to the previous one available. - */ - void SetPrevZoom(); - /** * Change the zoom to the previous one available redraws the screen * and warp the mouse pointer on request. diff --git a/include/id.h b/include/id.h index 8536ffac1c..3324504c84 100644 --- a/include/id.h +++ b/include/id.h @@ -121,7 +121,6 @@ enum main_id ID_GEN_EXPORT_FILE, ID_GEN_IMPORT_FILE, - ID_EXIT, ID_OPTIONS_SETUP, // id for toolbars @@ -130,7 +129,7 @@ enum main_id ID_OPT_TOOLBAR, ID_AUX_TOOLBAR, - ID_EDIT, + ID_EDIT_HOTKEY, ID_NO_TOOL_SELECTED, ID_ZOOM_SELECTION, ID_SEL_BG_COLOR, @@ -165,8 +164,6 @@ enum main_id ID_KICAD_SELECT_ICONS_IN_MENUS, ID_KICAD_SELECT_ICON_OPTIONS_END, - ID_SET_REPEAT_OPTION, - // Popup Menu (mouse Right button) (id consecutifs) ID_POPUP_GENERAL_START_RANGE, // first number @@ -174,8 +171,6 @@ enum main_id ID_POPUP_CLOSE_CURRENT_TOOL, ID_POPUP_GENERAL_END_RANGE, // last number - ID_POPUP_ENTER_MENU, - ID_ON_ZOOM_SELECT, ID_POPUP_ZOOM_START_RANGE, // first zoom id ID_POPUP_CANCEL, @@ -231,7 +226,6 @@ enum main_id ID_GRID_SETTINGS, - ID_SHEET_SET, ID_COMPONENT_BUTT, ID_ZOOM_BEGIN, diff --git a/include/page_info.h b/include/page_info.h index 38730d00e2..b1b41a1d3e 100644 --- a/include/page_info.h +++ b/include/page_info.h @@ -36,9 +36,9 @@ #include // for IU_PER_MILS /// Min and max page sizes for clamping, in mils. -#define MIN_PAGE_SIZE 4000 -#define MAX_PAGE_SIZE_PCBNEW_MILS 48000 -#define MAX_PAGE_SIZE_EDITORS_MILS 120000 +#define MIN_PAGE_SIZE 4000 +#define MAX_PAGE_SIZE_PCBNEW_MILS 48000 +#define MAX_PAGE_SIZE_MILS 120000 /** diff --git a/include/pcb_screen.h b/include/pcb_screen.h index 130c1989d0..1782c8623a 100644 --- a/include/pcb_screen.h +++ b/include/pcb_screen.h @@ -57,10 +57,6 @@ public: PCB_SCREEN* Next() const { return static_cast( Pnext ); } - void SetNextZoom(); - void SetPreviousZoom(); - void SetLastZoom(); - virtual int MilsToIuScalar() override; /** diff --git a/include/tool/actions.h b/include/tool/actions.h index 7983f39648..d6e81b6c06 100644 --- a/include/tool/actions.h +++ b/include/tool/actions.h @@ -49,8 +49,9 @@ public: static TOOL_ACTION open; static TOOL_ACTION save; static TOOL_ACTION saveAs; + static TOOL_ACTION saveCopyAs; static TOOL_ACTION saveAll; - static TOOL_ACTION pageSetup; + static TOOL_ACTION pageSettings; static TOOL_ACTION print; static TOOL_ACTION plot; static TOOL_ACTION quit; diff --git a/include/undo_redo_container.h b/include/undo_redo_container.h index f9bbaa6ed7..3bb34051d3 100644 --- a/include/undo_redo_container.h +++ b/include/undo_redo_container.h @@ -74,7 +74,8 @@ enum UNDO_REDO_T { UR_EXCHANGE_T, ///< Use for changing the schematic text type where swapping ///< data structure is insufficient to restore the change. UR_DRILLORIGIN, // origin changed (like UR_CHANGED, contains the origin and a copy) - UR_GRIDORIGIN // origin changed (like UR_CHANGED, contains the origin and a copy) + UR_GRIDORIGIN, // origin changed (like UR_CHANGED, contains the origin and a copy) + UR_PAGESETTINGS // page settings or title block changes }; diff --git a/include/ws_data_model.h b/include/ws_data_model.h index 0cc515e6b1..0b1840ae63 100644 --- a/include/ws_data_model.h +++ b/include/ws_data_model.h @@ -55,7 +55,7 @@ public: double m_DefaultLineWidth; // Used when object line width is 0 DSIZE m_DefaultTextSize; // Used when object text size is 0 double m_DefaultTextThickness; // Used when object text stroke width is 0 - bool m_SpecialMode; // Used in page layout editor to toggle variable substition + bool m_EditMode; // Used in page layout editor to toggle variable substition public: WS_DATA_MODEL(); diff --git a/include/ws_proxy_undo_item.h b/include/ws_proxy_undo_item.h new file mode 100644 index 0000000000..8173d0ce97 --- /dev/null +++ b/include/ws_proxy_undo_item.h @@ -0,0 +1,62 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2019 Kicad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef WS_PROXY_UNDO_ITEM_H +#define WS_PROXY_UNDO_ITEM_H + +#include +#include +#include + + +class WS_PROXY_UNDO_ITEM : public EDA_ITEM +{ +public: + explicit WS_PROXY_UNDO_ITEM( const EDA_DRAW_FRAME* aFrame ); + + /* + * Restores the saved worksheet layout to the global worksheet record, and the saved + * page info and title blocks to the given frame. The WS_DRAW_ITEMs are rehydrated + * and installed in aView if it is not null (ie: if we're in the PageLayout Editor). + */ + void Restore( EDA_DRAW_FRAME* aFrame, KIGFX::VIEW* aView = nullptr ); + +#if defined(DEBUG) + /// @copydoc EDA_ITEM::Show() + void Show( int x, std::ostream& st ) const override { } +#endif + + wxString GetClass() const override + { + return wxT( "WS_PROXY_UNDO_ITEM" ); + } + +protected: + TITLE_BLOCK m_titleBlock; + PAGE_INFO m_pageInfo; + wxString m_layoutSerialization; + int m_selectedDataItem; + int m_selectedDrawItem; +}; + +#endif /* WS_PROXY_UNDO_ITEM_H */ diff --git a/include/ws_view_item.h b/include/ws_proxy_view_item.h similarity index 92% rename from include/ws_view_item.h rename to include/ws_proxy_view_item.h index 602345cf21..69a30ebb78 100644 --- a/include/ws_view_item.h +++ b/include/ws_proxy_view_item.h @@ -22,8 +22,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef WS_VIEW_ITEM_H -#define WS_VIEW_ITEM_H +#ifndef WS_PROXY_VIEW_ITEM_H +#define WS_PROXY_VIEW_ITEM_H #include @@ -41,10 +41,10 @@ namespace KIGFX class VIEW; class GAL; -class WS_VIEW_ITEM : public EDA_ITEM +class WS_PROXY_VIEW_ITEM : public EDA_ITEM { public: - WS_VIEW_ITEM( int aScaleFactor, const PAGE_INFO* aPageInfo, const TITLE_BLOCK* aTitleBlock ); + WS_PROXY_VIEW_ITEM( int aScaleFactor, const PAGE_INFO* aPageInfo, const TITLE_BLOCK* aTitleBlock ); /** * Function SetFileName() @@ -117,9 +117,7 @@ public: #if defined(DEBUG) /// @copydoc EDA_ITEM::Show() - void Show( int x, std::ostream& st ) const override - { - } + void Show( int x, std::ostream& st ) const override { } #endif /** Get class name @@ -127,7 +125,7 @@ public: */ virtual wxString GetClass() const override { - return wxT( "WS_VIEW_ITEM" ); + return wxT( "WS_PROXY_VIEW_ITEM" ); } protected: @@ -155,4 +153,4 @@ protected: }; } -#endif /* WS_VIEW_ITEM_H */ +#endif /* WS_PROXY_VIEW_ITEM_H */ diff --git a/pagelayout_editor/CMakeLists.txt b/pagelayout_editor/CMakeLists.txt index 3299b5fea2..461b95dfe4 100644 --- a/pagelayout_editor/CMakeLists.txt +++ b/pagelayout_editor/CMakeLists.txt @@ -21,7 +21,6 @@ set( PL_EDITOR_SRCS pl_editor_screen.cpp pl_editor_layout.cpp files.cpp - ../common/page_layout/ws_data_model_io.cpp pl_editor_frame.cpp pl_editor_undo_redo.cpp properties_frame.cpp diff --git a/pagelayout_editor/menubar.cpp b/pagelayout_editor/menubar.cpp index 45552cda61..c27b7055fa 100644 --- a/pagelayout_editor/menubar.cpp +++ b/pagelayout_editor/menubar.cpp @@ -81,7 +81,7 @@ void PL_EDITOR_FRAME::ReCreateMenuBar() fileMenu->AddItem( ACTIONS::saveAs, SELECTION_CONDITIONS::ShowAlways ); fileMenu->AddSeparator(); - fileMenu->AddItem( ACTIONS::pageSetup, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->AddItem( ACTIONS::pageSettings, SELECTION_CONDITIONS::ShowAlways ); fileMenu->AddItem( ACTIONS::print, SELECTION_CONDITIONS::ShowAlways ); fileMenu->AppendSeparator(); diff --git a/pagelayout_editor/pl_draw_panel_gal.cpp b/pagelayout_editor/pl_draw_panel_gal.cpp index fad69249bb..8739ab9436 100644 --- a/pagelayout_editor/pl_draw_panel_gal.cpp +++ b/pagelayout_editor/pl_draw_panel_gal.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/pagelayout_editor/pl_draw_panel_gal.h b/pagelayout_editor/pl_draw_panel_gal.h index e1abf362c6..80deea8c3d 100644 --- a/pagelayout_editor/pl_draw_panel_gal.h +++ b/pagelayout_editor/pl_draw_panel_gal.h @@ -21,7 +21,7 @@ #define PL_DRAW_PANEL_GAL_H #include -#include +#include #include @@ -49,7 +49,7 @@ protected: void setDefaultLayerDeps(); ///> Currently used worksheet - std::unique_ptr m_worksheet; + std::unique_ptr m_worksheet; }; diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index 4d5dceeace..86c1882b69 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -50,7 +50,6 @@ #include #include #include -#include #include #include @@ -64,14 +63,13 @@ BEGIN_EVENT_TABLE( PL_EDITOR_FRAME, EDA_DRAW_FRAME ) EVT_MENU( ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST, PL_EDITOR_FRAME::Process_Special_Functions ) EVT_MENU( wxID_PREFERENCES, PL_EDITOR_FRAME::Process_Special_Functions ) - EVT_TOOL( ID_SHEET_SET, PL_EDITOR_FRAME::Process_Special_Functions ) EVT_TOOL( ID_SHOW_REAL_MODE, PL_EDITOR_FRAME::OnSelectTitleBlockDisplayMode ) EVT_TOOL( ID_SHOW_PL_EDITOR_MODE, PL_EDITOR_FRAME::OnSelectTitleBlockDisplayMode ) EVT_CHOICE( ID_SELECT_COORDINATE_ORIGIN, PL_EDITOR_FRAME::OnSelectCoordOriginCorner) EVT_CHOICE( ID_SELECT_PAGE_NUMBER, PL_EDITOR_FRAME::Process_Special_Functions) EVT_UPDATE_UI( ID_SHOW_REAL_MODE, PL_EDITOR_FRAME::OnUpdateTitleBlockDisplayNormalMode ) - EVT_UPDATE_UI( ID_SHOW_PL_EDITOR_MODE, PL_EDITOR_FRAME::OnUpdateTitleBlockDisplaySpecialMode ) + EVT_UPDATE_UI( ID_SHOW_PL_EDITOR_MODE, PL_EDITOR_FRAME::OnUpdateTitleBlockDisplayEditMode ) END_EVENT_TABLE() @@ -92,7 +90,7 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_hotkeysDescrList = PlEditorHotkeysDescr; m_originSelectChoice = 0; SetDrawBgColor( WHITE ); // default value, user option (WHITE/BLACK) - WS_DATA_MODEL::GetTheInstance().m_SpecialMode = true; + WS_DATA_MODEL::GetTheInstance().m_EditMode = true; SetShowPageLimits( true ); m_AboutTitle = "PlEditor"; @@ -289,18 +287,6 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) } break; - case ID_SHEET_SET: - { - DIALOG_PAGES_SETTINGS dlg( this, wxSize( MAX_PAGE_SIZE_EDITORS_MILS, - MAX_PAGE_SIZE_EDITORS_MILS ) ); - dlg.SetWksFileName( GetCurrFileName() ); - dlg.EnableWksFileNamePicker( false ); - - if( dlg.ShowModal() == wxID_OK ) - m_toolManager->RunAction( ACTIONS::zoomFitScreen ); - } - break; - default: wxMessageBox( wxT( "PL_EDITOR_FRAME::Process_Special_Functions error" ) ); break; @@ -321,7 +307,7 @@ void PL_EDITOR_FRAME::OnSelectCoordOriginCorner( wxCommandEvent& event ) void PL_EDITOR_FRAME::OnSelectTitleBlockDisplayMode( wxCommandEvent& event ) { - WS_DATA_MODEL::GetTheInstance().m_SpecialMode = (event.GetId() == ID_SHOW_PL_EDITOR_MODE); + WS_DATA_MODEL::GetTheInstance().m_EditMode = (event.GetId() == ID_SHOW_PL_EDITOR_MODE); HardRedraw(); } @@ -373,13 +359,13 @@ void PL_EDITOR_FRAME::ToPrinter( bool doPreview ) void PL_EDITOR_FRAME::OnUpdateTitleBlockDisplayNormalMode( wxUpdateUIEvent& event ) { - event.Check( WS_DATA_MODEL::GetTheInstance().m_SpecialMode == false ); + event.Check( WS_DATA_MODEL::GetTheInstance().m_EditMode == false ); } -void PL_EDITOR_FRAME::OnUpdateTitleBlockDisplaySpecialMode( wxUpdateUIEvent& event ) +void PL_EDITOR_FRAME::OnUpdateTitleBlockDisplayEditMode( wxUpdateUIEvent& event ) { - event.Check( WS_DATA_MODEL::GetTheInstance().m_SpecialMode == true ); + event.Check( WS_DATA_MODEL::GetTheInstance().m_EditMode == true ); } diff --git a/pagelayout_editor/pl_editor_frame.h b/pagelayout_editor/pl_editor_frame.h index 47a468f283..3053922e87 100644 --- a/pagelayout_editor/pl_editor_frame.h +++ b/pagelayout_editor/pl_editor_frame.h @@ -88,8 +88,7 @@ public: /** * Function InsertPageLayoutDescrFile - * Loads a .kicad_wks page layout descr file, and add items - * to the current layout list + * Loads a .kicad_wks page layout descr file, and add items to the current layout list * @param aFullFileName = the filename. */ bool InsertPageLayoutDescrFile( const wxString& aFullFileName ); @@ -109,9 +108,7 @@ public: /** * Function GetZoomLevelIndicator - * returns a human readable value which can be displayed as zoom - * level indicator in dialogs. - * Virtual from the base class + * returns a human readable value which can be displayed in dialogs. */ const wxString GetZoomLevelIndicator() const override; @@ -142,14 +139,12 @@ public: void UpdateStatusBar() override; /** - * Must be called to initialize parameters when a new page layout - * description is loaded + * Must be called to initialize parameters when a new page layout description is loaded */ void OnNewPageLayout(); /** * creates or updates the right vertical toolbar. - * @note This is currently not used. */ void ReCreateVToolbar() override; @@ -170,11 +165,9 @@ public: const BOX2I GetDocumentExtents() const override; /** - * Page layout editor can show the title block using a page number - * 1 or another number. - * This is because some items can be shown (or not) only on page 1 - * (a feature which look like word processing option - * "page 1 differs from other pages". + * Page layout editor can show the title block using a page number 1 or another number. + * This is because some items can be shown (or not) only on page 1 (a feature which + * looks like word processing option "page 1 differs from other pages"). * @return true if the page 1 is selected, and false if not */ bool GetPageNumberOption() const @@ -183,8 +176,7 @@ public: } /** - * Displays the short filename (if exists) loaded file - * on the caption of the main window + * Displays the short filename (if exists) loaded file on the caption of the main window */ void UpdateTitleAndInfo(); @@ -205,23 +197,22 @@ public: void Process_Special_Functions( wxCommandEvent& event ); /** - * called when the user select one of the 4 page corner as corner - * reference (or the left top paper corner) + * called when the user select one of the 4 page corner as corner reference (or the + * left top paper corner) */ void OnSelectCoordOriginCorner( wxCommandEvent& event ); /** * Toggle the display mode between the normal mode and the editor mode: - * In normal mode, title block texts are shown like they will be - * shown in other kicad applications: the format symbols in texts - * are replaced by the actual text. - * In editor mode, the format symbols in texts are not replaced - * by the actual text, and therefore format symbols are displayed. + * In normal mode, title block texts are shown like they will be shown in other kicad + * applications: the format symbols in texts are replaced by the actual text. + * In editor mode, the format symbols in texts are not replaced by the actual text, + * and therefore format symbols are displayed. */ void OnSelectTitleBlockDisplayMode( wxCommandEvent& event ); void OnUpdateTitleBlockDisplayNormalMode( wxUpdateUIEvent& event ); - void OnUpdateTitleBlockDisplaySpecialMode( wxUpdateUIEvent& event ); + void OnUpdateTitleBlockDisplayEditMode( wxUpdateUIEvent& event ); ///> @copydoc EDA_DRAW_FRAME::GetHotKeyDescription() EDA_HOTKEY* GetHotKeyDescription( int aCommand ) const override; @@ -286,8 +277,7 @@ public: WS_DATA_ITEM* AddPageLayoutItem( int aType ); /** - * Must be called after a change - * in order to set the "modify" flag of the current screen + * Must be called after a change in order to set the "modify" flag */ void OnModify() { @@ -295,10 +285,10 @@ public: } /** - * Save a copy of the description (in a S expr string) - * for Undo/redo commands + * Save a copy of the description (in a S expr string) for Undo/redo commands. + * Optionally save the pageInfo and titleBlock as well. */ - void SaveCopyInUndoList(); + void SaveCopyInUndoList( bool aSavePageSettingsAndTitleBlock = false ); /** Redo the last edit: * - Place the current edited layout in undo list @@ -313,8 +303,8 @@ public: void GetLayoutFromUndoList(); /** - * Remove the last command in Undo List. - * Used to clean the Undo stack after a cancel command + * Apply the last command in Undo List without stacking a Redo. Used to clean the + * Undo stack after cancelling a command. */ void RollbackFromUndo(); diff --git a/pagelayout_editor/pl_editor_layout.h b/pagelayout_editor/pl_editor_layout.h index 5eb4f6b883..a3fcc4f421 100644 --- a/pagelayout_editor/pl_editor_layout.h +++ b/pagelayout_editor/pl_editor_layout.h @@ -52,11 +52,9 @@ public: PL_EDITOR_LAYOUT(); ~PL_EDITOR_LAYOUT(); - const PAGE_INFO& GetPageSettings() const { return m_paper; } - void SetPageSettings( const PAGE_INFO& aPageSettings ) - { - m_paper = aPageSettings; - } + PAGE_INFO& GetPageSettings() { return m_paper; } + const PAGE_INFO& GetPageSettings() const { return m_paper; } + void SetPageSettings( const PAGE_INFO& aPageSettings ) { m_paper = aPageSettings; } const wxPoint& GetAuxOrigin() const { @@ -64,21 +62,15 @@ public: return zero; } - const TITLE_BLOCK& GetTitleBlock() const - { - return m_titles; - } + TITLE_BLOCK& GetTitleBlock() { return m_titles; } + const TITLE_BLOCK& GetTitleBlock() const { return m_titles; } + void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) { m_titles = aTitleBlock; } WS_DRAW_ITEM_LIST& GetDrawItems() { return m_drawItemList; } - void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) - { - m_titles = aTitleBlock; - } - /** * Function ComputeBoundingBox * calculates the bounding box containing all Gerber items. diff --git a/pagelayout_editor/pl_editor_undo_redo.cpp b/pagelayout_editor/pl_editor_undo_redo.cpp index 6281b83c05..4efa6393da 100644 --- a/pagelayout_editor/pl_editor_undo_redo.cpp +++ b/pagelayout_editor/pl_editor_undo_redo.cpp @@ -32,99 +32,16 @@ #include #include #include +#include +#include -/* Note: the Undo/redo commands use a "brute" method: - * the full page layout is converted to a S expression, and saved as string. - * When a previous version is needed, the old string is parsed, - * and the description replaces the current desc, just like reading a new file - * - * This is not optimal from the memory point of view, but: - * - the descriptions are never very long (max few thousand of bytes) - * - this is very easy to code - */ - -// A helper class used in undo/redo commad: -class PL_ITEM_LAYOUT: public EDA_ITEM +void PL_EDITOR_FRAME::SaveCopyInUndoList( bool aSavePageSettingsAndTitleBlock ) { - wxString m_serialization; - int m_selectedDataItem; - int m_selectedDrawItem; + PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST(); + WS_PROXY_UNDO_ITEM* copyItem = new WS_PROXY_UNDO_ITEM( this ); + ITEM_PICKER wrapper( copyItem, UR_LIBEDIT ); -public: - PL_ITEM_LAYOUT() : - EDA_ITEM( TYPE_PL_EDITOR_LAYOUT ), - m_selectedDataItem( INT_MAX ), - m_selectedDrawItem( INT_MAX ) - { - WS_DATA_MODEL& pglayout = WS_DATA_MODEL::GetTheInstance(); - pglayout.SaveInString( m_serialization ); - - for( size_t ii = 0; ii < pglayout.GetItems().size(); ++ii ) - { - WS_DATA_ITEM* dataItem = pglayout.GetItem( ii ); - - for( size_t jj = 0; jj < dataItem->GetDrawItems().size(); ++jj ) - { - WS_DRAW_ITEM_BASE* drawItem = dataItem->GetDrawItems()[ jj ]; - - if( drawItem->IsSelected() ) - { - m_selectedDataItem = ii; - m_selectedDrawItem = jj; - break; - } - } - } - } - - void RestoreLayout( PL_EDITOR_FRAME* aFrame ) - { - WS_DATA_MODEL& pglayout = WS_DATA_MODEL::GetTheInstance(); - PL_SELECTION_TOOL* selTool = aFrame->GetToolManager()->GetTool(); - KIGFX::VIEW* view = aFrame->GetGalCanvas()->GetView(); - - pglayout.SetPageLayout( TO_UTF8( m_serialization ) ); - - selTool->ClearSelection(); - view->Clear(); - - for( size_t ii = 0; ii < pglayout.GetItems().size(); ++ii ) - { - WS_DATA_ITEM* dataItem = pglayout.GetItem( ii ); - - dataItem->SyncDrawItems( nullptr, view ); - - if( ii == m_selectedDataItem && m_selectedDrawItem < dataItem->GetDrawItems().size() ) - { - WS_DRAW_ITEM_BASE* drawItem = dataItem->GetDrawItems()[ m_selectedDrawItem ]; - drawItem->SetSelected(); - } - } - - selTool->RebuildSelection(); - } - - // Required to keep compiler happy on debug builds. -#if defined(DEBUG) - virtual void Show( int nestLevel, std::ostream& os ) const override {} -#endif - - /** Get class name - * @return string "PL_ITEM_LAYOUT" - */ - virtual wxString GetClass() const override - { - return wxT( "PL_ITEM_LAYOUT" ); - } -}; - -void PL_EDITOR_FRAME::SaveCopyInUndoList() -{ - PL_ITEM_LAYOUT* copyItem = new PL_ITEM_LAYOUT; // constructor stores current layout - - PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST(); - ITEM_PICKER wrapper( copyItem, UR_LIBEDIT ); - lastcmd->PushItem(wrapper); + lastcmd->PushItem( wrapper ); GetScreen()->PushCommandToUndoList( lastcmd ); // Clear redo list, because after new save there is no redo to do. @@ -138,25 +55,34 @@ void PL_EDITOR_FRAME::SaveCopyInUndoList() */ void PL_EDITOR_FRAME::GetLayoutFromRedoList() { + PL_SELECTION_TOOL* selTool = GetToolManager()->GetTool(); + if ( GetScreen()->GetRedoCommandCount() <= 0 ) return; - PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST(); - PL_ITEM_LAYOUT* copyItem = new PL_ITEM_LAYOUT; // constructor stores current layout + ITEM_PICKER redoWrapper = GetScreen()->PopCommandFromRedoList()->PopItem(); + WS_PROXY_UNDO_ITEM* redoItem = static_cast( redoWrapper.GetItem() ); + bool pageSettingsAndTitleBlock = redoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T; - ITEM_PICKER wrapper( copyItem, UR_LIBEDIT ); + PICKED_ITEMS_LIST* undoCmd = new PICKED_ITEMS_LIST(); - lastcmd->PushItem( wrapper ); - GetScreen()->PushCommandToUndoList( lastcmd ); + undoCmd->PushItem( new WS_PROXY_UNDO_ITEM( pageSettingsAndTitleBlock ? this : nullptr ) ); + GetScreen()->PushCommandToUndoList( undoCmd ); - lastcmd = GetScreen()->PopCommandFromRedoList(); + selTool->ClearSelection(); + redoItem->Restore( this, GetGalCanvas()->GetView() ); + selTool->RebuildSelection(); - wrapper = lastcmd->PopItem(); - copyItem = static_cast( wrapper.GetItem() ); - copyItem->RestoreLayout( this ); - delete copyItem; + delete redoItem; + + if( pageSettingsAndTitleBlock ) + { + GetToolManager()->RunAction( ACTIONS::zoomFitScreen ); + HardRedraw(); // items based off of corners will need re-calculating + } + else + GetCanvas()->Refresh(); - GetCanvas()->Refresh(); OnModify(); } @@ -167,41 +93,63 @@ void PL_EDITOR_FRAME::GetLayoutFromRedoList() */ void PL_EDITOR_FRAME::GetLayoutFromUndoList() { + PL_SELECTION_TOOL* selTool = GetToolManager()->GetTool(); + if ( GetScreen()->GetUndoCommandCount() <= 0 ) return; - PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST(); - PL_ITEM_LAYOUT* copyItem = new PL_ITEM_LAYOUT; // constructor stores current layout + ITEM_PICKER undoWrapper = GetScreen()->PopCommandFromUndoList()->PopItem(); + WS_PROXY_UNDO_ITEM* undoItem = static_cast( undoWrapper.GetItem() ); + bool pageSettingsAndTitleBlock = undoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T; - ITEM_PICKER wrapper( copyItem, UR_LIBEDIT ); - lastcmd->PushItem( wrapper ); - GetScreen()->PushCommandToRedoList( lastcmd ); + PICKED_ITEMS_LIST* redoCmd = new PICKED_ITEMS_LIST(); - lastcmd = GetScreen()->PopCommandFromUndoList(); + redoCmd->PushItem( new WS_PROXY_UNDO_ITEM( pageSettingsAndTitleBlock ? this : nullptr ) ); + GetScreen()->PushCommandToRedoList( redoCmd ); - wrapper = lastcmd->PopItem(); - copyItem = static_cast( wrapper.GetItem() ); - copyItem->RestoreLayout( this ); - delete copyItem; + selTool->ClearSelection(); + undoItem->Restore( this, GetGalCanvas()->GetView() ); + selTool->RebuildSelection(); + + delete undoItem; + + if( pageSettingsAndTitleBlock ) + { + GetToolManager()->RunAction( ACTIONS::zoomFitScreen ); + HardRedraw(); // items based off of corners will need re-calculating + } + else + GetCanvas()->Refresh(); - GetCanvas()->Refresh(); OnModify(); } + /* Remove the last command in Undo List. * Used to clean the uUndo stack after a cancel command */ void PL_EDITOR_FRAME::RollbackFromUndo() { + PL_SELECTION_TOOL* selTool = GetToolManager()->GetTool(); + if ( GetScreen()->GetUndoCommandCount() <= 0 ) return; - PICKED_ITEMS_LIST* lastcmd = GetScreen()->PopCommandFromUndoList(); + ITEM_PICKER undoWrapper = GetScreen()->PopCommandFromUndoList()->PopItem(); + WS_PROXY_UNDO_ITEM* undoItem = static_cast( undoWrapper.GetItem() ); + bool pageSettingsAndTitleBlock = undoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T; - ITEM_PICKER wrapper = lastcmd->PopItem(); - PL_ITEM_LAYOUT* copyItem = static_cast( wrapper.GetItem() ); - copyItem->RestoreLayout( this ); - delete copyItem; + selTool->ClearSelection(); + undoItem->Restore( this, GetGalCanvas()->GetView() ); + selTool->RebuildSelection(); - GetCanvas()->Refresh(); + delete undoItem; + + if( pageSettingsAndTitleBlock ) + { + GetToolManager()->RunAction( ACTIONS::zoomFitScreen ); + HardRedraw(); // items based off of corners will need re-calculating + } + else + GetCanvas()->Refresh(); } diff --git a/pagelayout_editor/toolbars_pl_editor.cpp b/pagelayout_editor/toolbars_pl_editor.cpp index 7bfc9f73a2..7c18be8298 100644 --- a/pagelayout_editor/toolbars_pl_editor.cpp +++ b/pagelayout_editor/toolbars_pl_editor.cpp @@ -44,7 +44,7 @@ void PL_EDITOR_FRAME::ReCreateHToolbar() m_mainToolBar->Add( ACTIONS::save ); KiScaledSeparator( m_mainToolBar, this ); - m_mainToolBar->Add( ACTIONS::pageSetup ); + m_mainToolBar->Add( ACTIONS::pageSettings ); m_mainToolBar->Add( ACTIONS::print ); KiScaledSeparator( m_mainToolBar, this ); diff --git a/pagelayout_editor/tools/pl_editor_control.cpp b/pagelayout_editor/tools/pl_editor_control.cpp index bbc8c4ed60..5345116420 100644 --- a/pagelayout_editor/tools/pl_editor_control.cpp +++ b/pagelayout_editor/tools/pl_editor_control.cpp @@ -35,6 +35,7 @@ #include #include + TOOL_ACTION PL_ACTIONS::refreshPreview( "plEditor.EditorControl.refreshPreview", AS_GLOBAL, 0, "", "" ); @@ -92,8 +93,22 @@ int PL_EDITOR_CONTROL::SaveAs( const TOOL_EVENT& aEvent ) int PL_EDITOR_CONTROL::PageSetup( const TOOL_EVENT& aEvent ) { - wxCommandEvent evt( wxEVT_NULL, ID_SHEET_SET ); - m_frame->Process_Special_Functions( evt ); + m_frame->SaveCopyInUndoList( true ); + + DIALOG_PAGES_SETTINGS dlg( m_frame, wxSize( MAX_PAGE_SIZE_MILS, MAX_PAGE_SIZE_MILS ) ); + dlg.SetWksFileName( m_frame->GetCurrFileName() ); + dlg.EnableWksFileNamePicker( false ); + + if( dlg.ShowModal() != wxID_OK ) + { + // Nothing to roll back but we have to at least pop the stack + m_frame->RollbackFromUndo(); + } + else + { + m_toolMgr->RunAction( ACTIONS::zoomFitScreen ); + m_frame->HardRedraw(); + } return 0; } @@ -165,7 +180,7 @@ void PL_EDITOR_CONTROL::setTransitions() Go( &PL_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() ); Go( &PL_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() ); Go( &PL_EDITOR_CONTROL::SaveAs, ACTIONS::saveAs.MakeEvent() ); - Go( &PL_EDITOR_CONTROL::PageSetup, ACTIONS::pageSetup.MakeEvent() ); + Go( &PL_EDITOR_CONTROL::PageSetup, ACTIONS::pageSettings.MakeEvent() ); Go( &PL_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() ); Go( &PL_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() ); Go( &PL_EDITOR_CONTROL::Quit, ACTIONS::quit.MakeEvent() ); diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 634501f5f4..c42eeeba8c 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include #include diff --git a/pcbnew/dialogs/dialog_print_pcbnew.cpp b/pcbnew/dialogs/dialog_print_pcbnew.cpp index 00c1d54d6f..54edf26152 100644 --- a/pcbnew/dialogs/dialog_print_pcbnew.cpp +++ b/pcbnew/dialogs/dialog_print_pcbnew.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010-2016 Jean-Pierre Charras, jean-pierre.charras at wanadoo.fr - * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2018 CERN * Author: Maciej Suminski * @@ -28,20 +28,16 @@ #include #include #include -#include -#include #include #include #include #include - #include #include - +#include #include #include - class DIALOG_PRINT_PCBNEW : public DIALOG_PRINT_GENERIC { public: @@ -329,24 +325,20 @@ void DIALOG_PRINT_PCBNEW::saveSettings() } -void PCB_EDIT_FRAME::ToPrinter( wxCommandEvent& event ) +int PCBNEW_CONTROL::Print( const TOOL_EVENT& aEvent ) { - // Selection affects the original item visibility - GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true ); + // Selection affects the origin item visibility + m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); + + PCBNEW_PRINTOUT_SETTINGS settings( m_frame->GetPageSettings() ); + DIALOG_PRINT_PCBNEW dlg( (PCB_BASE_EDIT_FRAME*) m_frame, &settings ); + + if( m_editModules ) + dlg.ForcePrintBorder( false ); - PCBNEW_PRINTOUT_SETTINGS settings( GetPageSettings() ); - DIALOG_PRINT_PCBNEW dlg( this, &settings ); dlg.ShowModal(); + + return 0; } -void FOOTPRINT_EDIT_FRAME::ToPrinter( wxCommandEvent& event ) -{ - // Selection affects the original item visibility - GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true ); - - PCBNEW_PRINTOUT_SETTINGS settings( GetPageSettings() ); - DIALOG_PRINT_PCBNEW dlg( this, &settings ); - dlg.ForcePrintBorder( false ); - dlg.ShowModal(); -} diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index ca2ff48adf..2cda8a7b54 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -1061,3 +1061,9 @@ void FOOTPRINT_EDIT_FRAME::OnSaveFootprintAsPng( wxCommandEvent& event ) wxYield(); saveCanvasImageToFile( dlg.GetPath() ); } + + +void FOOTPRINT_EDIT_FRAME::ToPrinter( wxCommandEvent& event ) +{ + GetToolManager()->RunAction( ACTIONS::print ); +} diff --git a/pcbnew/footprint_editor_utils.cpp b/pcbnew/footprint_editor_utils.cpp index 97bb80f3ea..8d864ac105 100644 --- a/pcbnew/footprint_editor_utils.cpp +++ b/pcbnew/footprint_editor_utils.cpp @@ -280,10 +280,6 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) switch( id ) { - case ID_EXIT: - Close( true ); - break; - case ID_OPEN_MODULE_VIEWER: { FOOTPRINT_VIEWER_FRAME* viewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_PCB_MODULE_VIEWER, false ); @@ -578,9 +574,6 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) AddLibrary(); break; - case ID_MODEDIT_SHEET_SET: - break; - case ID_MODEDIT_EDIT_MODULE: LoadModuleFromLibrary( m_treePane->GetLibTree()->GetSelectedLibId() ); break; diff --git a/pcbnew/menubar_pcb_editor.cpp b/pcbnew/menubar_pcb_editor.cpp index 3f1259f41a..aa788ae31d 100644 --- a/pcbnew/menubar_pcb_editor.cpp +++ b/pcbnew/menubar_pcb_editor.cpp @@ -42,20 +42,9 @@ #include "pcbnew_id.h" -// Build the files menu. Because some commands are available only if -// Pcbnew is run outside a project (run alone), aIsOutsideProject is false -// when Pcbnew is run from Kicad manager, and true is run as stand alone app. -static void prepareFilesMenu( wxMenu* aParentMenu, bool aIsOutsideProject ); - -// Build the export submenu (inside files menu) -static void prepareExportMenu( wxMenu* aParentMenu ); - // Build the place submenu static void preparePlaceMenu( CONDITIONAL_MENU* aPlaceMenu, SELECTION_TOOL* aSelectionTool ); -// Build the edit submenu -static void prepareEditMenu( PCB_EDIT_FRAME * aFrame, CONDITIONAL_MENU* aEditMenu, SELECTION_TOOL* aSelectionTool ); - // Build the route menu static void prepareRouteMenu( wxMenu* aParentMenu ); @@ -81,16 +70,229 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() wxMenuBar* menuBar = new wxMenuBar(); wxString text; + auto modifiedDocumentCondition = [ this ] ( const SELECTION& sel ) { + return GetScreen()->IsModify(); + }; + // Recreate all menus: - // Create File Menu - wxMenu* filesMenu = new wxMenu; - prepareFilesMenu( filesMenu, Kiface().IsSingle() ); + //----- Edit menu ----------------------------------------------------------- + CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool ); + static ACTION_MENU* openRecentMenu; + + if( Kiface().IsSingle() ) // not when under a project mgr + { + // Add this menu to list menu managed by m_fileHistory + // (the file history will be updated when adding/removing files in history) + if( openRecentMenu ) + Kiface().GetFileHistory().RemoveMenu( openRecentMenu ); + + openRecentMenu = new ACTION_MENU(); + openRecentMenu->SetTool( selTool ); + openRecentMenu->SetTitle( _( "Open Recent" ) ); + openRecentMenu->SetIcon( recent_xpm ); + + Kiface().GetFileHistory().UseMenu( openRecentMenu ); + Kiface().GetFileHistory().AddFilesToMenu( openRecentMenu ); + + fileMenu->AddItem( ACTIONS::doNew, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->AddItem( ACTIONS::open, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->AddMenu( openRecentMenu, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->AddSeparator(); + } + + fileMenu->AddItem( ACTIONS::save, modifiedDocumentCondition ); + + // Save as menu: + // under a project mgr we do not want to modify the board filename + // to keep consistency with the project mgr which expects files names same as prj name + // for main files + if( Kiface().IsSingle() ) + fileMenu->AddItem( ACTIONS::saveAs, SELECTION_CONDITIONS::ShowAlways ); + else + fileMenu->AddItem( ACTIONS::saveCopyAs, SELECTION_CONDITIONS::ShowAlways ); + + fileMenu->AddSeparator(); + fileMenu->AddItem( ID_MENU_RECOVER_BOARD_AUTOSAVE, + _( "Resc&ue" ), + _( "Clear board and get last rescue file automatically saved by Pcbnew" ), + rescue_xpm, SELECTION_CONDITIONS::ShowAlways ); + + if( Kiface().IsSingle() ) // not when under a project mgr + { + fileMenu->AddItem( ID_APPEND_FILE, + _( "&Append Board..." ), + _( "Append another board to currently loaded board" ), + add_board_xpm, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->AddItem( ID_IMPORT_NON_KICAD_BOARD, + _( "Import Non-KiCad Board File..." ), + _( "Import board file from other applications" ), + import_brd_file_xpm, SELECTION_CONDITIONS::ShowAlways ); + } + + fileMenu->AddItem( ID_MENU_READ_BOARD_BACKUP_FILE, + _( "Revert to Last Backup" ), + _( "Clear board and get previous backup version of board" ), + undo_xpm, SELECTION_CONDITIONS::ShowAlways ); + + fileMenu->AddSeparator(); + + //----- Import submenu ------------------------------------------------------ + ACTION_MENU* submenuImport = new ACTION_MENU(); + submenuImport->SetTool( selTool ); + submenuImport->SetTitle( _( "Import" ) ); + submenuImport->SetIcon( import_xpm ); + + submenuImport->Add( _( "Netlist..." ), _( "Read netlist and update board connectivity" ), + ID_GET_NETLIST, netlist_xpm ); + submenuImport->Add( _( "Specctra Session..." ), _( "Import routed Specctra session (*.ses) file" ), + ID_GEN_IMPORT_SPECCTRA_SESSION, import_xpm ); + submenuImport->Add( _( "Graphics..." ), _( "Import 2D drawing file" ), + ID_GEN_IMPORT_GRAPHICS_FILE, import_vector_xpm ); + + fileMenu->AddMenu( submenuImport, SELECTION_CONDITIONS::ShowAlways ); + + //----- Export submenu ------------------------------------------------------ + ACTION_MENU* submenuExport = new ACTION_MENU(); + submenuExport->SetTool( selTool ); + submenuExport->SetTitle( _( "Export" ) ); + submenuExport->SetIcon( export_xpm ); + + submenuExport->Add( _( "Specctra DSN..." ), _( "Export Specctra DSN routing info" ), + ID_GEN_EXPORT_SPECCTRA, export_dsn_xpm ); + submenuExport->Add( _( "GenCAD..." ), _( "Export GenCAD 3D board representation" ), + ID_GEN_EXPORT_FILE_GENCADFORMAT, export_xpm ); + submenuExport->Add( _( "VRML..." ), _( "Export VRML 3D board representation" ), + ID_GEN_EXPORT_FILE_VRML, export3d_xpm ); + submenuExport->Add( _( "IDFv3..." ), _( "Export IDF 3D board representation" ), + ID_GEN_EXPORT_FILE_IDF3, export_idf_xpm ); + submenuExport->Add( _( "STEP..." ), _( "Export STEP 3D board representation" ), + ID_GEN_EXPORT_FILE_STEP, export_step_xpm ); + submenuExport->Add( _( "SVG..." ), _( "Export SVG board representation" ), + ID_GEN_PLOT_SVG, plot_svg_xpm ); + submenuExport->Add( _( "Footprint Association (.cmp) File..." ), + _( "Export footprint association file (*.cmp) for schematic back annotation" ), + ID_PCB_GEN_CMP_FILE, create_cmp_file_xpm ); + submenuExport->Add( _( "Hyperlynx..." ), "", + ID_GEN_EXPORT_FILE_HYPERLYNX, export_step_xpm ); + + fileMenu->AddMenu( submenuExport, SELECTION_CONDITIONS::ShowAlways ); + + //----- Fabrication Outputs submenu ----------------------------------------- + ACTION_MENU* submenuFabOutputs = new ACTION_MENU(); + submenuFabOutputs->SetTool( selTool ); + submenuFabOutputs->SetTitle( _( "Fabrication Outputs" ) ); + submenuFabOutputs->SetIcon( fabrication_xpm ); + + submenuFabOutputs->Add( _( "&Gerbers (.gbr)..." ), + _( "Generate Gerbers for fabrication" ), + ID_GEN_PLOT_GERBER, post_compo_xpm ); + submenuFabOutputs->Add( _( "&Drill Files (.drl)..." ), + _( "Generate Excellon drill file(s)" ), + ID_PCB_GEN_DRILL_FILE, post_drill_xpm ); + submenuFabOutputs->Add( _( "Footprint &Positions (.pos)..." ), + _( "Generate footprint position file for pick and place" ), + ID_PCB_GEN_POS_MODULES_FILE, post_compo_xpm ); + submenuFabOutputs->Add( _( "&Footprint Report (.rpt)..." ), + _( "Create report of all footprints from current board" ), + ID_GEN_EXPORT_FILE_MODULE_REPORT, tools_xpm ); + submenuFabOutputs->Add( _( "IPC-D-356 Netlist File..." ), + _( "Generate IPC-D-356 netlist file" ), + ID_PCB_GEN_D356_FILE, netlist_xpm ); + submenuFabOutputs->Add( _( "&BOM..." ), + _( "Create bill of materials from current schematic" ), + ID_PCB_GEN_BOM_FILE_FROM_BOARD, bom_xpm ); + + fileMenu->AddMenu( submenuFabOutputs, SELECTION_CONDITIONS::ShowAlways ); + + fileMenu->AddSeparator(); + fileMenu->AddItem( ID_BOARD_SETUP_DIALOG, + _( "&Board Setup..." ), + _( "Edit board setup including layers, design rules and various defaults" ), + options_board_xpm, SELECTION_CONDITIONS::ShowAlways ); + + fileMenu->AddSeparator(); + fileMenu->AddItem( ACTIONS::pageSettings, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->AddItem( ACTIONS::print, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->AddItem( ACTIONS::plot, SELECTION_CONDITIONS::ShowAlways ); + + + //----- archive submenu ----------------------------------------------------- + ACTION_MENU* submenuArchive = new ACTION_MENU(); + submenuArchive->SetTool( selTool ); + submenuArchive->SetTitle( _( "Archive Footprints" ) ); + submenuArchive->SetIcon( library_archive_xpm ); + + submenuArchive->Add( _( "&Archive Footprints in Existing Library..." ), + _( "Archive all footprints to existing library in footprint Lib table" + "(does not remove other footprints in this library)" ), + ID_MENU_ARCHIVE_MODULES_IN_LIBRARY, library_archive_xpm ); + + submenuArchive->Add( _( "&Create New Library and Archive Footprints..." ), + _( "Archive all footprints to a new library\n" + "(if the library already exists it will be replaced)" ), + ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES, library_archive_as_xpm ); + + fileMenu->AddSeparator(); + fileMenu->AddMenu( submenuArchive, SELECTION_CONDITIONS::ShowAlways ); + + // Quit + fileMenu->AddSeparator(); + fileMenu->AddItem( ACTIONS::quit, SELECTION_CONDITIONS::ShowAlways ); //----- Edit menu ----------------------------------------------------------- CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, selTool ); - prepareEditMenu( this, editMenu, selTool ); + auto enableUndoCondition = [ this ] ( const SELECTION& sel ) { + return GetScreen() && GetScreen()->GetUndoCommandCount() > 0; + }; + auto enableRedoCondition = [ this ] ( const SELECTION& sel ) { + return GetScreen() && GetScreen()->GetRedoCommandCount() > 0; + }; + auto noActiveToolCondition = [ this ] ( const SELECTION& aSelection ) { + return GetToolId() == ID_NO_TOOL_SELECTED; + }; + + editMenu->AddItem( ACTIONS::undo, enableUndoCondition ); + editMenu->AddItem( ACTIONS::redo, enableRedoCondition ); + + editMenu->AddSeparator(); + editMenu->AddItem( ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty ); + editMenu->AddItem( ACTIONS::copy, SELECTION_CONDITIONS::NotEmpty ); + editMenu->AddItem( ACTIONS::paste, noActiveToolCondition ); + + editMenu->AddSeparator(); + editMenu->AddItem( PCB_ACTIONS::deleteTool, SELECTION_CONDITIONS::ShowAlways ); + + editMenu->AddSeparator(); + editMenu->AddItem( ACTIONS::find, SELECTION_CONDITIONS::ShowAlways ); + + editMenu->AddSeparator(); + editMenu->AddItem( ID_PCB_EDIT_TRACKS_AND_VIAS, + _( "Edit Track && Via Properties..." ), "", + width_track_via_xpm, SELECTION_CONDITIONS::ShowAlways ); + editMenu->AddItem( ID_MENU_PCB_EDIT_TEXT_AND_GRAPHICS, + _( "Edit Text && Graphic Properties..." ), "", + reset_text_xpm, SELECTION_CONDITIONS::ShowAlways ); + editMenu->AddItem( PCB_ACTIONS::exchangeFootprints, SELECTION_CONDITIONS::ShowAlways ); + editMenu->AddItem( ID_MENU_PCB_SWAP_LAYERS, + _( "Swap Layers..." ), + _( "Move tracks or drawings from a layer to another layer" ), + swap_layer_xpm, SELECTION_CONDITIONS::ShowAlways ); + + editMenu->AddSeparator(); + editMenu->AddItem( PCB_ACTIONS::zoneFillAll, SELECTION_CONDITIONS::ShowAlways ); + editMenu->AddItem( PCB_ACTIONS::zoneUnfillAll, SELECTION_CONDITIONS::ShowAlways ); + + editMenu->AddSeparator(); + editMenu->AddItem( ID_PCB_GLOBAL_DELETE, + _( "Global Deletions..." ), + _( "Delete tracks, footprints and graphic items from board" ), + general_deletions_xpm, SELECTION_CONDITIONS::ShowAlways ); + editMenu->AddItem( ID_MENU_PCB_CLEAN, + _( "Cleanup Tracks and Vias..." ), + _( "Clean stubs, vias, delete break points or unconnected tracks" ), + delete_xpm, SELECTION_CONDITIONS::ShowAlways ); //----- View menu ----------------------------------------------------------- CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool ); @@ -149,17 +351,17 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() viewMenu->AddCheckItem( ID_TB_OPTIONS_SHOW_MANAGE_LAYERS_VERTICAL_TOOLBAR, _( "Show La&yers Manager" ), HELP_SHOW_HIDE_LAYERMANAGER, - layers_manager_xpm, layersPaletteShownCondition ); + layers_manager_xpm, layersPaletteShownCondition ); viewMenu->AddCheckItem( ID_TB_OPTIONS_SHOW_EXTRA_VERTICAL_TOOLBAR_MICROWAVE, _( "Show Microwa&ve Toolbar" ), HELP_SHOW_HIDE_MICROWAVE_TOOLS, - mw_toolbar_xpm, microwaveToolbarShownCondition ); + mw_toolbar_xpm, microwaveToolbarShownCondition ); viewMenu->AddItem( ID_OPEN_MODULE_VIEWER, _( "Footprint &Library Browser" ), _( "Browse footprint libraries" ), - modview_icon_xpm, SELECTION_CONDITIONS::ShowAlways ); + modview_icon_xpm, SELECTION_CONDITIONS::ShowAlways ); text = AddHotkeyName( _( "&3D Viewer" ), g_Board_Editor_Hotkeys_Descr, HK_3D_VIEWER ); viewMenu->AddItem( ID_MENU_PCB_SHOW_3D_FRAME, text, _( "Show board in 3D viewer" ), - three_d_xpm, SELECTION_CONDITIONS::ShowAlways ); + three_d_xpm, SELECTION_CONDITIONS::ShowAlways ); viewMenu->AddSeparator(); viewMenu->AddItem( ACTIONS::zoomInCenter, SELECTION_CONDITIONS::ShowAlways ); @@ -245,7 +447,7 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() preparePreferencesMenu( this, configmenu ); //------ Append all menus to the menuBar ------------------------------------ - menuBar->Append( filesMenu, _( "&File" ) ); + menuBar->Append( fileMenu, _( "&File" ) ); menuBar->Append( editMenu, _( "&Edit" ) ); menuBar->Append( viewMenu, _( "&View" ) ); menuBar->Append( placeMenu, _( "&Place" ) ); @@ -266,61 +468,6 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() } -void prepareEditMenu( PCB_EDIT_FRAME * aFrame, CONDITIONAL_MENU* aEditMenu, SELECTION_TOOL* aSelectionTool ) -{ - auto enableUndoCondition = [ aFrame ] ( const SELECTION& sel ) { - return aFrame->GetScreen() && aFrame->GetScreen()->GetUndoCommandCount() > 0; - }; - auto enableRedoCondition = [ aFrame ] ( const SELECTION& sel ) { - return aFrame->GetScreen() && aFrame->GetScreen()->GetRedoCommandCount() > 0; - }; - auto noActiveToolCondition = [ aFrame ] ( const SELECTION& aSelection ) { - return aFrame->GetToolId() == ID_NO_TOOL_SELECTED; - }; - - aEditMenu->AddItem( ACTIONS::undo, enableUndoCondition ); - aEditMenu->AddItem( ACTIONS::redo, enableRedoCondition ); - - aEditMenu->AddSeparator(); - aEditMenu->AddItem( ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty ); - aEditMenu->AddItem( ACTIONS::copy, SELECTION_CONDITIONS::NotEmpty ); - aEditMenu->AddItem( ACTIONS::paste, noActiveToolCondition ); - - aEditMenu->AddSeparator(); - aEditMenu->AddItem( PCB_ACTIONS::deleteTool, SELECTION_CONDITIONS::ShowAlways ); - - aEditMenu->AddSeparator(); - aEditMenu->AddItem( ACTIONS::find, SELECTION_CONDITIONS::ShowAlways ); - - aEditMenu->AddSeparator(); - aEditMenu->AddItem( ID_PCB_EDIT_TRACKS_AND_VIAS, - _( "Edit &Track && Via Properties..." ), "", - width_track_via_xpm, SELECTION_CONDITIONS::ShowAlways ); - aEditMenu->AddItem( ID_MENU_PCB_EDIT_TEXT_AND_GRAPHICS, - _( "Edit Text && &Graphic Properties..." ), "", - reset_text_xpm, SELECTION_CONDITIONS::ShowAlways ); - aEditMenu->AddItem( PCB_ACTIONS::exchangeFootprints, SELECTION_CONDITIONS::ShowAlways ); - aEditMenu->AddItem( ID_MENU_PCB_SWAP_LAYERS, - _( "&Swap Layers..." ), - _( "Move tracks or drawings from a layer to another layer" ), - swap_layer_xpm, SELECTION_CONDITIONS::ShowAlways ); - - aEditMenu->AddSeparator(); - aEditMenu->AddItem( PCB_ACTIONS::zoneFillAll, SELECTION_CONDITIONS::ShowAlways ); - aEditMenu->AddItem( PCB_ACTIONS::zoneUnfillAll, SELECTION_CONDITIONS::ShowAlways ); - - aEditMenu->AddSeparator(); - aEditMenu->AddItem( ID_PCB_GLOBAL_DELETE, - _( "Glo&bal Deletions..." ), - _( "Delete tracks, footprints and graphic items from board" ), - general_deletions_xpm, SELECTION_CONDITIONS::ShowAlways ); - aEditMenu->AddItem( ID_MENU_PCB_CLEAN, - _( "C&leanup Tracks and Vias..." ), - _( "Clean stubs, vias, delete break points or unconnected tracks" ), - delete_xpm, SELECTION_CONDITIONS::ShowAlways ); -} - - // Build the preferences menu void preparePreferencesMenu( PCB_EDIT_FRAME* aFrame, wxMenu* aParentMenu ) { @@ -547,263 +694,3 @@ void prepareToolsMenu( wxMenu* aParentMenu ) submenuActionPluginsMenu->AppendSeparator(); #endif } - - -// Build the files menu. -void prepareFilesMenu( wxMenu* aParentMenu, bool aIsOutsideProject ) -{ - wxString text; - - // Some commands are available only if Pcbnew is run outside a project (run alone). - // aIsOutsideProject is false when Pcbnew is run from Kicad manager. - - FILE_HISTORY& fhist = Kiface().GetFileHistory(); - - // Load Recent submenu - static wxMenu* openRecentMenu; - - // Add this menu to list menu managed by m_fileHistory - // (the file history will be updated when adding/removing files in history - if( openRecentMenu ) - fhist.RemoveMenu( openRecentMenu ); - - openRecentMenu = new wxMenu(); - - fhist.UseMenu( openRecentMenu ); - fhist.AddFilesToMenu(); - - if( aIsOutsideProject ) - { - text = AddHotkeyName( _( "&New" ), g_Board_Editor_Hotkeys_Descr, HK_NEW ); - AddMenuItem( aParentMenu, ID_NEW_BOARD, - text, _( "Create new board" ), - KiBitmap( new_board_xpm ) ); - - text = AddHotkeyName( _( "&Open..." ), g_Board_Editor_Hotkeys_Descr, HK_OPEN ); - AddMenuItem( aParentMenu, ID_LOAD_FILE, text, - _( "Open existing board" ), - KiBitmap( open_brd_file_xpm ) ); - - AddMenuItem( aParentMenu, openRecentMenu, - -1, _( "Open &Recent" ), - _( "Open recently opened board" ), - KiBitmap( recent_xpm ) ); - - aParentMenu->AppendSeparator(); - } - - text = AddHotkeyName( _( "&Save" ), g_Board_Editor_Hotkeys_Descr, HK_SAVE ); - AddMenuItem( aParentMenu, ID_SAVE_BOARD, text, - _( "Save current board" ), - KiBitmap( save_xpm ) ); - - // Save as menu: - // under a project mgr we do not want to modify the board filename - // to keep consistency with the project mgr which expects files names same as prj name - // for main files - // when not under a project mgr, we are free to change filenames, cwd ... - if( Kiface().IsSingle() ) // not when under a project mgr (pcbnew is run as stand alone) - { - text = AddHotkeyName( _( "Sa&ve As..." ), g_Board_Editor_Hotkeys_Descr, HK_SAVEAS ); - AddMenuItem( aParentMenu, ID_SAVE_BOARD_AS, text, - _( "Save current board with new name" ), - KiBitmap( save_as_xpm ) ); - } - // under a project mgr, we can save a copy of the board, - // but do not change the current board file name - else - { - text = AddHotkeyName( _( "Sa&ve Copy As..." ), g_Board_Editor_Hotkeys_Descr, HK_SAVEAS ); - AddMenuItem( aParentMenu, ID_COPY_BOARD_AS, text, - _( "Save copy of the current board" ), - KiBitmap( save_as_xpm ) ); - } - - aParentMenu->AppendSeparator(); - - AddMenuItem( aParentMenu, ID_MENU_RECOVER_BOARD_AUTOSAVE, - _( "Resc&ue" ), - _( "Clear board and get last rescue file automatically saved by Pcbnew" ), - KiBitmap( rescue_xpm ) ); - - if( aIsOutsideProject ) - { - AddMenuItem( aParentMenu, ID_APPEND_FILE, - _( "&Append Board..." ), - _( "Append another board to currently loaded board" ), - KiBitmap( add_board_xpm ) ); - - AddMenuItem( aParentMenu, ID_IMPORT_NON_KICAD_BOARD, - _( "Import Non-KiCad Board File..." ), - _( "Import board file from other applications" ), - KiBitmap( import_brd_file_xpm ) ); - } - - AddMenuItem( aParentMenu, ID_MENU_READ_BOARD_BACKUP_FILE, - _( "Revert to Las&t Backup" ), - _( "Clear board and get previous backup version of board" ), - KiBitmap( undo_xpm ) ); - - aParentMenu->AppendSeparator(); - - //----- Import submenu ------------------------------------------------------ - wxMenu* submenuImport = new wxMenu(); - - AddMenuItem( submenuImport, ID_GET_NETLIST, - _( "&Netlist..." ), - _( "Read netlist and update board connectivity" ), - KiBitmap( netlist_xpm ) ); - - AddMenuItem( submenuImport, ID_GEN_IMPORT_SPECCTRA_SESSION, - _( "&Specctra Session..." ), - _( "Import routed \"Specctra Session\" (*.ses) file" ), - KiBitmap( import_xpm ) ); - - AddMenuItem( submenuImport, ID_GEN_IMPORT_GRAPHICS_FILE, - _( "&Graphics..." ), - _( "Import 2D Drawing file to Pcbnew on Drawings layer" ), - KiBitmap( import_vector_xpm ) ); - - AddMenuItem( aParentMenu, submenuImport, - ID_GEN_IMPORT_FILE, _( "&Import" ), - _( "Import files" ), KiBitmap( import_xpm ) ); - - - //----- Export submenu ------------------------------------------------------ - wxMenu* submenuexport = new wxMenu(); - prepareExportMenu( submenuexport ); - - AddMenuItem( aParentMenu, submenuexport, - ID_GEN_EXPORT_FILE, _( "E&xport" ), - _( "Export board" ), KiBitmap( export_xpm ) ); - - - //----- Fabrication Outputs submenu ----------------------------------------- - wxMenu* fabricationOutputsMenu = new wxMenu; - AddMenuItem( fabricationOutputsMenu, ID_GEN_PLOT_GERBER, - _( "&Gerbers (.gbr)..." ), - _( "Generate Gerbers for fabrication" ), - KiBitmap( post_compo_xpm ) ); - - AddMenuItem( fabricationOutputsMenu, ID_PCB_GEN_DRILL_FILE, - _( "&Drill Files (.drl)..." ), - _( "Generate Excellon drill file(s)" ), - KiBitmap( post_drill_xpm ) ); - - AddMenuItem( fabricationOutputsMenu, ID_PCB_GEN_POS_MODULES_FILE, - _( "Footprint &Positions (.pos)..." ), - _( "Generate footprint position file for pick and place" ), - KiBitmap( post_compo_xpm ) ); - - AddMenuItem( fabricationOutputsMenu, ID_GEN_EXPORT_FILE_MODULE_REPORT, - _( "&Footprint Report (.rpt)..." ), - _( "Create report of all footprints from current board" ), - KiBitmap( tools_xpm ) ); - - AddMenuItem( fabricationOutputsMenu, ID_PCB_GEN_D356_FILE, - _( "IPC-D-356 Netlist File..." ), - _( "Generate IPC-D-356 netlist file" ), - KiBitmap( netlist_xpm ) ); - - AddMenuItem( fabricationOutputsMenu, ID_PCB_GEN_BOM_FILE_FROM_BOARD, - _( "&BOM..." ), - _( "Create bill of materials from current schematic" ), - KiBitmap( bom_xpm ) ); - - AddMenuItem( aParentMenu, fabricationOutputsMenu, - -1, _( "&Fabrication Outputs" ), - _( "Generate files for fabrication" ), - KiBitmap( fabrication_xpm ) ); - - aParentMenu->AppendSeparator(); - - AddMenuItem( aParentMenu, ID_BOARD_SETUP_DIALOG, - _( "&Board Setup..." ), - _( "Edit board setup including layers, design rules and various defaults" ), - KiBitmap( options_board_xpm ) ); - - aParentMenu->AppendSeparator(); - - AddMenuItem( aParentMenu, ID_SHEET_SET, - _( "Page S&ettings..." ), - _( "Settings for sheet size and frame references" ), - KiBitmap( sheetset_xpm ) ); - - text = AddHotkeyName( _( "&Print..." ), g_Board_Editor_Hotkeys_Descr, HK_PRINT ); - AddMenuItem( aParentMenu, wxID_PRINT, text, - _( "Print board" ), - KiBitmap( print_button_xpm ) ); - - AddMenuItem( aParentMenu, ID_GEN_PLOT, - _( "P&lot..." ), - _( "Plot board in HPGL, PostScript or Gerber RS-274X format)" ), - KiBitmap( plot_xpm ) ); - - aParentMenu->AppendSeparator(); - - //----- archive submenu ----------------------------------------------------- - wxMenu* submenuarchive = new wxMenu(); - - AddMenuItem( submenuarchive, ID_MENU_ARCHIVE_MODULES_IN_LIBRARY, - _( "&Archive Footprints in Existing Library..." ), - _( "Archive all footprints to existing library in footprint Lib table" - "(does not remove other footprints in this library)" ), - KiBitmap( library_archive_xpm ) ); - - AddMenuItem( submenuarchive, ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES, - _( "&Create New Library and Archive Footprints..." ), - _( "Archive all footprints to a new library\n" - "(if the library already exists it will be replaced)" ), - KiBitmap( library_archive_as_xpm ) ); - - AddMenuItem( aParentMenu, submenuarchive, - ID_MENU_ARCHIVE_MODULES, - _( "Arc&hive Footprints" ), - _( "Archive or add all footprints in library file" ), - KiBitmap( library_archive_xpm ) ); - - aParentMenu->AppendSeparator(); - AddMenuItem( aParentMenu, wxID_EXIT, _( "&Exit" ), _( "Close Pcbnew" ), KiBitmap( exit_xpm ) ); -} - - -// Build the import/export submenu (inside files menu) -void prepareExportMenu( wxMenu* aParentMenu ) -{ - AddMenuItem( aParentMenu, ID_GEN_EXPORT_SPECCTRA, - _( "S&pecctra DSN..." ), - _( "Export current board to \"Specctra DSN\" file" ), - KiBitmap( export_dsn_xpm ) ); - - AddMenuItem( aParentMenu, ID_GEN_EXPORT_FILE_GENCADFORMAT, - _( "&GenCAD..." ), _( "Export GenCAD format" ), - KiBitmap( export_xpm ) ); - - AddMenuItem( aParentMenu, ID_GEN_EXPORT_FILE_VRML, - _( "&VRML..." ), - _( "Export VRML board representation" ), - KiBitmap( export3d_xpm ) ); - - AddMenuItem( aParentMenu, ID_GEN_EXPORT_FILE_IDF3, - _( "I&DFv3..." ), _( "IDFv3 board and symbol export" ), - KiBitmap( export_idf_xpm ) ); - - AddMenuItem( aParentMenu, ID_GEN_EXPORT_FILE_STEP, - _( "S&TEP..." ), _( "STEP export" ), - KiBitmap( export_step_xpm ) ); - - AddMenuItem( aParentMenu, ID_GEN_PLOT_SVG, - _( "&SVG..." ), - _( "Export board file in Scalable Vector Graphics format" ), - KiBitmap( plot_svg_xpm ) ); - - AddMenuItem( aParentMenu, ID_PCB_GEN_CMP_FILE, - _( "&Footprint Association (.cmp) File..." ), - _( "Export footprint association file (*.cmp) for schematic back annotation" ), - KiBitmap( create_cmp_file_xpm ) ); - - AddMenuItem( aParentMenu, ID_GEN_EXPORT_FILE_HYPERLYNX, - _( "&Hyperlynx..." ), _( "Hyperlynx export" ), - KiBitmap( export_step_xpm ) ); - -} diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index 77dd8120fd..552985f178 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -120,15 +120,20 @@ public: */ void RestoreCopyFromUndoList( wxCommandEvent& aEvent ); + /** + * Performs an undo of the last edit WITHOUT logging a corresponding redo. Used to cancel + * an in-progress operation. + */ + void RollbackFromUndo(); + /** * Function PutDataInPreviousState * Used in undo or redo command. * Put data pointed by List in the previous state, i.e. the state memorized by List * @param aList = a PICKED_ITEMS_LIST pointer to the list of items to undo/redo * @param aRedoCommand = a bool: true for redo, false for undo - * @param aRebuildRatsnet = a bool: true to rebuild ratsnest (normal use), false - * to just retrieve last state (used in abort commands that do not need to - * rebuild ratsnest) + * @param aRebuildRatsnet = a bool: true to rebuild ratsnest (normal use), false to just + * retrieve last state (used in abort commands that do not need to rebuild ratsnest) */ void PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRedoCommand, diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp index 0f386f2e69..6f23bdeddb 100644 --- a/pcbnew/pcb_draw_panel_gal.cpp +++ b/pcbnew/pcb_draw_panel_gal.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -197,7 +197,7 @@ void PCB_DRAW_PANEL_GAL::DisplayBoard( BOARD* aBoard ) } -void PCB_DRAW_PANEL_GAL::SetWorksheet( KIGFX::WS_VIEW_ITEM* aWorksheet ) +void PCB_DRAW_PANEL_GAL::SetWorksheet( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ) { m_worksheet.reset( aWorksheet ); m_view->Add( m_worksheet.get() ); diff --git a/pcbnew/pcb_draw_panel_gal.h b/pcbnew/pcb_draw_panel_gal.h index caa33717ee..d46b396503 100644 --- a/pcbnew/pcb_draw_panel_gal.h +++ b/pcbnew/pcb_draw_panel_gal.h @@ -31,7 +31,7 @@ namespace KIGFX { - class WS_VIEW_ITEM; + class WS_PROXY_VIEW_ITEM; class RATSNEST_VIEWITEM; class PCB_VIEW; } @@ -59,7 +59,7 @@ public: * @param aWorksheet is the worksheet to be used. * The object is then owned by PCB_DRAW_PANEL_GAL. */ - void SetWorksheet( KIGFX::WS_VIEW_ITEM* aWorksheet ); + void SetWorksheet( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ); /** * Function UseColorScheme @@ -118,7 +118,7 @@ protected: void setDefaultLayerDeps(); ///> Currently used worksheet - std::unique_ptr m_worksheet; + std::unique_ptr m_worksheet; ///> Ratsnest view item std::unique_ptr m_ratsnest; diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index db5145d535..e57f39813e 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -55,7 +55,7 @@ #include #include #include -#include +#include #include #include #include @@ -121,11 +121,8 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) EVT_CLOSE( PCB_EDIT_FRAME::OnCloseWindow ) EVT_SIZE( PCB_EDIT_FRAME::OnSize ) - EVT_TOOL( ID_LOAD_FILE, PCB_EDIT_FRAME::Files_io ) EVT_TOOL( ID_MENU_READ_BOARD_BACKUP_FILE, PCB_EDIT_FRAME::Files_io ) EVT_TOOL( ID_MENU_RECOVER_BOARD_AUTOSAVE, PCB_EDIT_FRAME::Files_io ) - EVT_TOOL( ID_NEW_BOARD, PCB_EDIT_FRAME::Files_io ) - EVT_TOOL( ID_SAVE_BOARD, PCB_EDIT_FRAME::Files_io ) EVT_TOOL( ID_OPEN_MODULE_EDITOR, PCB_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_OPEN_MODULE_VIEWER, PCB_EDIT_FRAME::Process_Special_Functions ) @@ -134,8 +131,6 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) EVT_MENU( ID_MENU_PCB_FLIP_VIEW, PCB_EDIT_FRAME::OnFlipPcbView ) EVT_MENU( ID_APPEND_FILE, PCB_EDIT_FRAME::Files_io ) - EVT_MENU( ID_SAVE_BOARD_AS, PCB_EDIT_FRAME::Files_io ) - EVT_MENU( ID_COPY_BOARD_AS, PCB_EDIT_FRAME::Files_io ) EVT_MENU( ID_IMPORT_NON_KICAD_BOARD, PCB_EDIT_FRAME::Files_io ) EVT_MENU_RANGE( ID_FILE1, ID_FILEMAX, PCB_EDIT_FRAME::OnFileHistory ) @@ -157,8 +152,6 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) EVT_MENU( ID_MENU_ARCHIVE_MODULES_IN_LIBRARY, PCB_EDIT_FRAME::Process_Special_Functions ) EVT_MENU( ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES, PCB_EDIT_FRAME::Process_Special_Functions ) - EVT_MENU( wxID_EXIT, PCB_EDIT_FRAME::OnQuit ) - // menu Config EVT_MENU( ID_PCB_LIB_TABLE_EDIT, PCB_EDIT_FRAME::Process_Config ) EVT_MENU( ID_PCB_3DSHAPELIB_WIZARD, PCB_EDIT_FRAME::Process_Config ) @@ -197,10 +190,7 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) // Horizontal toolbar EVT_TOOL( ID_RUN_LIBRARY, PCB_EDIT_FRAME::Process_Special_Functions ) - EVT_TOOL( ID_SHEET_SET, EDA_DRAW_FRAME::Process_PageSettings ) - EVT_TOOL( wxID_PRINT, PCB_EDIT_FRAME::ToPrinter ) EVT_TOOL( ID_GEN_PLOT_SVG, PCB_EDIT_FRAME::ExportSVG ) - EVT_TOOL( ID_GEN_PLOT, PCB_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_GET_NETLIST, PCB_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_DRC_CONTROL, PCB_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_AUX_TOOLBAR_PCB_SELECT_LAYER_PAIR, PCB_EDIT_FRAME::Process_Special_Functions ) @@ -253,7 +243,6 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) PCB_EDIT_FRAME::Process_Special_Functions ) // User interface update event handlers. - EVT_UPDATE_UI( ID_SAVE_BOARD, PCB_EDIT_FRAME::OnUpdateSave ) EVT_UPDATE_UI( ID_AUX_TOOLBAR_PCB_SELECT_LAYER_PAIR, PCB_EDIT_FRAME::OnUpdateLayerPair ) EVT_UPDATE_UI( ID_TOOLBARH_PCB_SELECT_LAYER, PCB_EDIT_FRAME::OnUpdateLayerSelectBox ) EVT_UPDATE_UI( ID_TB_OPTIONS_DRC_OFF, PCB_EDIT_FRAME::OnUpdateDrcEnable ) @@ -487,8 +476,8 @@ void PCB_EDIT_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings ) PCB_DRAW_PANEL_GAL* drawPanel = static_cast( GetGalCanvas() ); // Prepare worksheet template - KIGFX::WS_VIEW_ITEM* worksheet; - worksheet = new KIGFX::WS_VIEW_ITEM( IU_PER_MILS ,&m_Pcb->GetPageSettings(), + KIGFX::WS_PROXY_VIEW_ITEM* worksheet; + worksheet = new KIGFX::WS_PROXY_VIEW_ITEM( IU_PER_MILS ,&m_Pcb->GetPageSettings(), &m_Pcb->GetTitleBlock() ); worksheet->SetSheetName( std::string( GetScreenDesc().mb_str() ) ); @@ -571,12 +560,6 @@ void PCB_EDIT_FRAME::ReFillLayerWidget() } -void PCB_EDIT_FRAME::OnQuit( wxCommandEvent& event ) -{ - Close( false ); -} - - void PCB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) { m_canvas->SetAbortRequest( true ); diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index e208c8dd9e..12b900ab13 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -300,8 +300,6 @@ public: */ void LoadFootprints( NETLIST& aNetlist, REPORTER& aReporter ); - void OnQuit( wxCommandEvent& event ); - /** * Reload the Python plugins if they are newer than * the already loaded, and load new plugins if any diff --git a/pcbnew/ratsnest_viewitem.h b/pcbnew/ratsnest_viewitem.h index 432c89133e..ac920ff52c 100644 --- a/pcbnew/ratsnest_viewitem.h +++ b/pcbnew/ratsnest_viewitem.h @@ -60,9 +60,7 @@ public: #if defined(DEBUG) /// @copydoc EDA_ITEM::Show() - void Show( int x, std::ostream& st ) const override - { - } + void Show( int x, std::ostream& st ) const override { } #endif /** Get class name diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index 2136a4ebee..c8feb0975f 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2012 Wayne Stambaugh - * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -250,19 +250,19 @@ void PCB_EDIT_FRAME::ReCreateHToolbar() // Set up toolbar if( Kiface().IsSingle() ) { - ADD_TOOL( ID_NEW_BOARD, new_board_xpm, _( "New board" ) ); - ADD_TOOL( ID_LOAD_FILE, open_brd_file_xpm, _( "Open existing board" ) ); + m_mainToolBar->Add( ACTIONS::doNew ); + m_mainToolBar->Add( ACTIONS::open ); } - ADD_TOOL( ID_SAVE_BOARD, save_xpm, _( "Save board" ) ); + m_mainToolBar->Add( ACTIONS::save ); KiScaledSeparator( m_mainToolBar, this ); ADD_TOOL( ID_BOARD_SETUP_DIALOG, options_board_xpm, _( "Board setup" ) ); KiScaledSeparator( m_mainToolBar, this ); - ADD_TOOL( ID_SHEET_SET, sheetset_xpm, _( "Page settings for paper size and texts" ) ); - ADD_TOOL( wxID_PRINT, print_button_xpm, _( "Print board" ) ); - ADD_TOOL( ID_GEN_PLOT, plot_xpm, _( "Plot (HPGL, PostScript, or GERBER format)" ) ); + m_mainToolBar->Add( ACTIONS::pageSettings ); + m_mainToolBar->Add( ACTIONS::print ); + m_mainToolBar->Add( ACTIONS::plot ); KiScaledSeparator( m_mainToolBar, this ); m_mainToolBar->Add( ACTIONS::undo ); @@ -782,12 +782,6 @@ bool PCB_EDIT_FRAME::MicrowaveToolbarShown() } -void PCB_EDIT_FRAME::OnUpdateSave( wxUpdateUIEvent& aEvent ) -{ - aEvent.Enable( GetScreen()->IsModify() ); -} - - void PCB_EDIT_FRAME::OnUpdateVerticalToolbar( wxUpdateUIEvent& aEvent ) { if( aEvent.GetEventObject() == m_drawToolBar || aEvent.GetEventObject() == m_mainToolBar ) @@ -807,6 +801,7 @@ void PCB_EDIT_FRAME::SyncMenusAndToolbars() KIGFX::GAL_DISPLAY_OPTIONS& galOpts = GetGalDisplayOptions(); int zoneMode = opts->m_DisplayZonesMode; + m_mainToolBar->Toggle( ACTIONS::save, GetScreen() && GetScreen()->IsModify() ); m_mainToolBar->Toggle( ACTIONS::undo, GetScreen() && GetScreen()->GetUndoCommandCount() > 0 ); m_mainToolBar->Toggle( ACTIONS::redo, GetScreen() && GetScreen()->GetRedoCommandCount() > 0 ); m_mainToolBar->Toggle( ACTIONS::zoomTool, GetToolId() == ID_ZOOM_SELECTION ); diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index a8c290b4f8..f03808fb5d 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -31,7 +31,7 @@ #include #include #include - +#include #include "edit_tool.h" #include "selection_tool.h" #include "drawing_tool.h" @@ -60,6 +60,7 @@ #include #include #include +#include using namespace std::placeholders; @@ -357,6 +358,71 @@ bool PCB_EDITOR_CONTROL::Init() } +int PCB_EDITOR_CONTROL::New( const TOOL_EVENT& aEvent ) +{ + m_frame->Files_io_from_id( ID_NEW_BOARD ); + return 0; +} + + +int PCB_EDITOR_CONTROL::Open( const TOOL_EVENT& aEvent ) +{ + m_frame->Files_io_from_id( ID_LOAD_FILE ); + return 0; +} + + +int PCB_EDITOR_CONTROL::Save( const TOOL_EVENT& aEvent ) +{ + m_frame->Files_io_from_id( ID_SAVE_BOARD ); + return 0; +} + + +int PCB_EDITOR_CONTROL::SaveAs( const TOOL_EVENT& aEvent ) +{ + m_frame->Files_io_from_id( ID_SAVE_BOARD_AS ); + return 0; +} + + +int PCB_EDITOR_CONTROL::SaveCopyAs( const TOOL_EVENT& aEvent ) +{ + m_frame->Files_io_from_id( ID_COPY_BOARD_AS ); + return 0; +} + + +int PCB_EDITOR_CONTROL::PageSettings( const TOOL_EVENT& aEvent ) +{ + PICKED_ITEMS_LIST undoCmd; + WS_PROXY_UNDO_ITEM* undoItem = new WS_PROXY_UNDO_ITEM( m_frame ); + ITEM_PICKER wrapper( undoItem, UR_PAGESETTINGS ); + + undoCmd.PushItem( wrapper ); + m_frame->SaveCopyInUndoList( undoCmd, UR_PAGESETTINGS ); + + DIALOG_PAGES_SETTINGS dlg( m_frame, wxSize( MAX_PAGE_SIZE_PCBNEW_MILS, + MAX_PAGE_SIZE_PCBNEW_MILS ) ); + dlg.SetWksFileName( BASE_SCREEN::m_PageLayoutDescrFileName ); + + if( dlg.ShowModal() == wxID_OK ) + m_toolMgr->RunAction( ACTIONS::zoomFitScreen ); + else + m_frame->RollbackFromUndo(); + + return 0; +} + + +int PCB_EDITOR_CONTROL::Plot( const TOOL_EVENT& aEvent ) +{ + wxCommandEvent evt( wxEVT_NULL, ID_GEN_PLOT ); + m_frame->ToPlotter( evt ); + return 0; +} + + int PCB_EDITOR_CONTROL::Find( const TOOL_EVENT& aEvent ) { DIALOG_FIND dlg( m_frame ); @@ -1279,6 +1345,14 @@ void PCB_EDITOR_CONTROL::calculateSelectionRatsnest() void PCB_EDITOR_CONTROL::setTransitions() { + Go( &PCB_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::SaveAs, ACTIONS::saveAs.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::SaveCopyAs, ACTIONS::saveCopyAs.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::PageSettings, ACTIONS::pageSettings.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::Find, ACTIONS::find.MakeEvent() ); // Track & via size control diff --git a/pcbnew/tools/pcb_editor_control.h b/pcbnew/tools/pcb_editor_control.h index 624745f6b1..22c295bbfd 100644 --- a/pcbnew/tools/pcb_editor_control.h +++ b/pcbnew/tools/pcb_editor_control.h @@ -51,6 +51,14 @@ public: /// @copydoc TOOL_INTERACTIVE::Init() bool Init() override; + int New( const TOOL_EVENT& aEvent ); + int Open( const TOOL_EVENT& aEvent ); + int Save( const TOOL_EVENT& aEvent ); + int SaveAs( const TOOL_EVENT& aEvent ); + int SaveCopyAs( const TOOL_EVENT& aEvent ); + int PageSettings( const TOOL_EVENT& aEvent ); + int Plot( const TOOL_EVENT& aEvent ); + int Find( const TOOL_EVENT& aEvent ); // Track & via size control diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index d698da80dd..50c475aca3 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -240,6 +240,14 @@ void PCBNEW_CONTROL::Reset( RESET_REASON aReason ) } } + +int PCBNEW_CONTROL::Quit( const TOOL_EVENT& aEvent ) +{ + m_frame->Close( false ); + return 0; +} + + template void Flip( T& aValue ) { aValue = !aValue; @@ -1006,6 +1014,9 @@ void PCBNEW_CONTROL::updateGrid() void PCBNEW_CONTROL::setTransitions() { + Go( &PCBNEW_CONTROL::Print, ACTIONS::print.MakeEvent() ); + Go( &PCBNEW_CONTROL::Quit, ACTIONS::quit.MakeEvent() ); + // Display modes Go( &PCBNEW_CONTROL::TrackDisplayMode, PCB_ACTIONS::trackDisplayMode.MakeEvent() ); Go( &PCBNEW_CONTROL::ToggleRatsnest, PCB_ACTIONS::showRatsnest.MakeEvent() ); diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index ba86378485..20d2a7dd82 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -50,6 +50,9 @@ public: /// @copydoc TOOL_INTERACTIVE::Reset() void Reset( RESET_REASON aReason ) override; + int Print( const TOOL_EVENT& aEvent ); + int Quit( const TOOL_EVENT& aEvent ); + // Display modes int ToggleRatsnest( const TOOL_EVENT& aEvent ); int ZoneDisplayMode( const TOOL_EVENT& aEvent ); diff --git a/pcbnew/undo_redo.cpp b/pcbnew/undo_redo.cpp index 75256c3e54..e8a8a25073 100644 --- a/pcbnew/undo_redo.cpp +++ b/pcbnew/undo_redo.cpp @@ -34,7 +34,6 @@ using namespace std::placeholders; #include #include - #include #include #include @@ -45,15 +44,14 @@ using namespace std::placeholders; #include #include #include - #include - +#include +#include #include #include #include -#include - #include +#include /* Functions to undo and redo edit commands. * commands to undo are stored in CurrentScreen->m_UndoList @@ -208,6 +206,8 @@ void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsLis UNDO_REDO_T aTypeCommand, const wxPoint& aTransformPoint ) { + static KICAD_T moduleChildren[] = { PCB_MODULE_TEXT_T, PCB_MODULE_EDGE_T, PCB_PAD_T, EOT }; + PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST(); commandToUndo->m_TransformPoint = aTransformPoint; @@ -218,11 +218,10 @@ void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsLis for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) { ITEM_PICKER curr_picker = aItemsList.GetItemWrapper(ii); - BOARD_ITEM* item = (BOARD_ITEM*) aItemsList.GetPickedItem( ii ); + BOARD_ITEM* item = dynamic_cast( aItemsList.GetPickedItem( ii ) ); // For items belonging to modules, we need to save state of the parent module - if( item->Type() == PCB_MODULE_TEXT_T || item->Type() == PCB_MODULE_EDGE_T - || item->Type() == PCB_PAD_T ) + if( item && item->IsType( moduleChildren ) ) { // Item to be stored in the undo buffer is the parent module item = item->GetParent(); @@ -281,7 +280,7 @@ void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsLis for( unsigned ii = 0; ii < commandToUndo->GetCount(); ii++ ) { - BOARD_ITEM* item = (BOARD_ITEM*) commandToUndo->GetPickedItem( ii ); + EDA_ITEM* item = aItemsList.GetPickedItem( ii ); UNDO_REDO_T command = commandToUndo->GetPickedItemStatus( ii ); if( command == UR_UNSPECIFIED ) @@ -315,6 +314,7 @@ void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsLis case UR_FLIPPED: case UR_NEW: case UR_DELETED: + case UR_PAGESETTINGS: break; default: @@ -420,8 +420,7 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool // Restore changes in reverse order for( int ii = aList->GetCount() - 1; ii >= 0 ; ii-- ) { - item = (BOARD_ITEM*) aList->GetPickedItem( ii ); - wxASSERT( item ); + EDA_ITEM* eda_item = aList->GetPickedItem( (unsigned) ii ); /* Test for existence of item on board. * It could be deleted, and no more on board: @@ -434,7 +433,8 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool if( status != UR_DELETED && status != UR_DRILLORIGIN // origin markers never on board - && status != UR_GRIDORIGIN ) // origin markers never on board + && status != UR_GRIDORIGIN // origin markers never on board + && status != UR_PAGESETTINGS ) // nor are page settings proxy items { if( build_item_list ) // Build list of existing items, for integrity test @@ -551,12 +551,21 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool } break; - default: + case UR_PAGESETTINGS: { - wxLogDebug( wxT( "PutDataInPreviousState() error (unknown code %X)" ), - aList->GetPickedItemStatus( ii ) ); + // swap current settings with stored settings + WS_PROXY_UNDO_ITEM alt_item( this ); + WS_PROXY_UNDO_ITEM* item = (WS_PROXY_UNDO_ITEM*) eda_item; + item->Restore( this ); + *item = alt_item; + GetToolManager()->RunAction( ACTIONS::zoomFitScreen ); } break; + + default: + wxLogDebug( wxT( "PutDataInPreviousState() error (unknown code %X)" ), + aList->GetPickedItemStatus( ii ) ); + break; } } @@ -601,3 +610,15 @@ void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount delete curr_cmd; // Delete command } } + + +void PCB_BASE_EDIT_FRAME::RollbackFromUndo() +{ + PICKED_ITEMS_LIST* undo = GetScreen()->PopCommandFromUndoList(); + PutDataInPreviousState( undo, false ); + + undo->ClearListAndDeleteItems(); + delete undo; + + GetCanvas()->Refresh(); +} \ No newline at end of file