KiCad PCB EDA Suite
dialog_cleanup_graphics.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25#include <board_commit.h>
26#include <footprint.h>
27#include <pad.h>
28#include <tool/tool_manager.h>
29#include <tools/pcb_actions.h>
30#include <graphics_cleaner.h>
31#include <pcb_base_frame.h>
32
33
35 bool aIsFootprintEditor ) :
37 m_parentFrame( aParent ),
38 m_isFootprintEditor( aIsFootprintEditor )
39{
41 m_changesDataView->AssociateModel( m_changesTreeModel );
42
43 if( aIsFootprintEditor )
44 {
45 SetupStandardButtons( { { wxID_OK, _( "Update Footprint" ) } } );
46 m_nettieHint->SetFont( KIUI::GetInfoFont( aParent ).Italic() );
47 }
48 else
49 {
50 SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) } } );
51 m_mergePadsOpt->Show( false );
52 m_nettieHint->Show( false );
53 }
54
55 GetSizer()->SetSizeHints(this);
56 Centre();
57}
58
59
61{
62 m_changesTreeModel->DecRef();
63}
64
65
66void DIALOG_CLEANUP_GRAPHICS::OnCheckBox( wxCommandEvent& anEvent )
67{
68 doCleanup( true );
69}
70
71
73{
74 doCleanup( true );
75
76 return true;
77}
78
79
81{
82 doCleanup( false );
83
84 return true;
85}
86
87
89{
90 wxBusyCursor busy;
91
93 BOARD* board = m_parentFrame->GetBoard();
94 FOOTPRINT* fp = m_isFootprintEditor ? board->GetFirstFootprint() : nullptr;
95 GRAPHICS_CLEANER cleaner( fp ? fp->GraphicalItems() : board->Drawings(), fp, commit,
97
98 if( !aDryRun )
99 {
100 // Clear current selection list to avoid selection of deleted items
102
103 // ... and to keep the treeModel from trying to refresh a deleted item
105 }
106
107 m_items.clear();
108
109 // Old model has to be refreshed, GAL normally does not keep updating it
111
112 cleaner.CleanupBoard( aDryRun, &m_items, m_createRectanglesOpt->GetValue(),
113 m_deleteRedundantOpt->GetValue(),
114 m_mergePadsOpt->GetValue() );
115
116 if( aDryRun )
117 {
118 m_changesTreeModel->Update( std::make_shared<VECTOR_CLEANUP_ITEMS_PROVIDER>( &m_items ),
120 }
121 else if( !commit.Empty() )
122 {
123 // Clear undo and redo lists to avoid inconsistencies between lists
124 commit.Push( _( "Graphics cleanup" ) );
125 m_parentFrame->GetCanvas()->Refresh( true );
126 }
127}
128
129
130void DIALOG_CLEANUP_GRAPHICS::OnSelectItem( wxDataViewEvent& aEvent )
131{
132 const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
133 BOARD_ITEM* item = m_parentFrame->GetBoard()->GetItem( itemID );
135
136 if( item && !item->GetLayerSet().test( m_parentFrame->GetActiveLayer() ) )
137 m_parentFrame->SetActiveLayer( item->GetLayerSet().UIOrder().front() );
138
139 m_parentFrame->FocusOnItem( item );
141
142 aEvent.Skip();
143}
144
145
147{
148 event.Skip();
149
150 if( m_changesDataView->GetCurrentItem().IsOk() )
151 {
152 if( !IsModal() )
153 Show( false );
154 }
155}
156
157
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:58
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:185
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
BOARD_ITEM * GetItem(const KIID &aID) const
Definition: board.cpp:943
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:397
DRAWINGS & Drawings()
Definition: board.h:310
bool Empty() const
Returns status of an item.
Definition: commit.h:139
Class DIALOG_CLEANUP_GRAPHICS_BASE.
DIALOG_CLEANUP_GRAPHICS(PCB_BASE_FRAME *aParent, bool aIsFootprintEditor)
void OnCheckBox(wxCommandEvent &anEvent) override
void OnSelectItem(wxDataViewEvent &event) override
void OnLeftDClickItem(wxMouseEvent &event) override
std::vector< std::shared_ptr< CLEANUP_ITEM > > m_items
bool Show(bool show) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
DRAWINGS & GraphicalItems()
Definition: footprint.h:173
void CleanupBoard(bool aDryRun, std::vector< std::shared_ptr< CLEANUP_ITEM > > *aItemsList, bool aMergeRects, bool aDeleteRedundant, bool aMergePads)
the cleanup function.
Definition: kiid.h:48
LSEQ UIOrder() const
Definition: lset.cpp:922
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual PCB_LAYER_ID GetActiveLayer() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
void Compile_Ratsnest(bool aDisplayStatus)
Create the entire board ratsnest.
Definition: ratsnest.cpp:35
void FocusOnItem(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
void Update(std::shared_ptr< RC_ITEMS_PROVIDER > aProvider, int aSeverities)
Definition: rc_item.cpp:289
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:149
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
#define _(s)
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:144
@ RPT_SEVERITY_ACTION