KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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
34static int s_defaultTolerance = pcbIUScale.mmToIU( 2 );
35
37 bool aIsFootprintEditor ) :
39 m_parentFrame( aParent ),
40 m_isFootprintEditor( aIsFootprintEditor ),
42{
44 m_changesDataView->AssociateModel( m_changesTreeModel );
45 m_changesDataView->SetLayoutDirection( wxLayout_LeftToRight );
46
47 if( aIsFootprintEditor )
48 {
49 SetupStandardButtons( { { wxID_OK, _( "Update Footprint" ) } } );
50 m_nettieHint->SetFont( KIUI::GetInfoFont( aParent ).Italic() );
51
52 m_fixBoardOutlines->Show( false );
53 m_toleranceSizer->Show( false );
54 }
55 else
56 {
57 SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) } } );
58 m_mergePadsOpt->Show( false );
59 m_nettieHint->Show( false );
60 }
61
62 GetSizer()->SetSizeHints(this);
63 Centre();
64}
65
66
71
72
73void DIALOG_CLEANUP_GRAPHICS::OnCheckBox( wxCommandEvent& anEvent )
74{
75 doCleanup( true );
76}
77
78
80{
82
83 doCleanup( true );
84
85 return true;
86}
87
88
90{
92
93 doCleanup( false );
94
95 return true;
96}
97
98
100{
101 wxBusyCursor busy;
102
103 BOARD_COMMIT commit( m_parentFrame );
104 BOARD* board = m_parentFrame->GetBoard();
105 FOOTPRINT* fp = m_isFootprintEditor ? board->GetFirstFootprint() : nullptr;
106 GRAPHICS_CLEANER cleaner( fp ? fp->GraphicalItems() : board->Drawings(), fp, commit,
107 m_parentFrame->GetToolManager() );
108
109 if( !aDryRun )
110 {
111 // Clear current selection list to avoid selection of deleted items
112 m_parentFrame->GetToolManager()->RunAction( ACTIONS::selectionClear );
113
114 // ... and to keep the treeModel from trying to refresh a deleted item
115 m_changesTreeModel->Update( nullptr, RPT_SEVERITY_ACTION );
116 }
117
118 m_items.clear();
119
120 // Old model has to be refreshed, GAL normally does not keep updating it
121 m_parentFrame->Compile_Ratsnest( false );
122
123 cleaner.CleanupBoard( aDryRun, &m_items, m_createRectanglesOpt->GetValue(),
124 m_deleteRedundantOpt->GetValue(), m_mergePadsOpt->GetValue(),
125 m_fixBoardOutlines->GetValue(), m_tolerance.GetIntValue() );
126
127 if( aDryRun )
128 {
129 m_changesTreeModel->Update( std::make_shared<VECTOR_CLEANUP_ITEMS_PROVIDER>( &m_items ),
131 }
132 else if( !commit.Empty() )
133 {
134 // Clear undo and redo lists to avoid inconsistencies between lists
135 commit.Push( _( "Cleanup Graphics" ) );
136 m_parentFrame->GetCanvas()->Refresh( true );
137 }
138}
139
140
141void DIALOG_CLEANUP_GRAPHICS::OnSelectItem( wxDataViewEvent& aEvent )
142{
143 const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
144
145 if( BOARD_ITEM* item = m_parentFrame->GetBoard()->ResolveItem( itemID, true ) )
146 {
148
149 if( !item->GetLayerSet().test( m_parentFrame->GetActiveLayer() ) )
150 m_parentFrame->SetActiveLayer( item->GetLayerSet().UIOrder().front() );
151
152 m_parentFrame->FocusOnItem( item );
153 m_parentFrame->GetCanvas()->Refresh();
154 }
155
156 aEvent.Skip();
157}
158
159
161{
162 event.Skip();
163
164 if( m_changesDataView->GetCurrentItem().IsOk() )
165 {
166 if( !IsModal() )
167 Show( false );
168 }
169}
170
171
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:224
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:83
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:530
const DRAWINGS & Drawings() const
Definition board.h:365
bool Empty() const
Definition commit.h:137
DIALOG_CLEANUP_GRAPHICS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Cleanup Graphics"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
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={})
DRAWINGS & GraphicalItems()
Definition footprint.h:309
void CleanupBoard(bool aDryRun, std::vector< std::shared_ptr< CLEANUP_ITEM > > *aItemsList, bool aMergeRects, bool aDeleteRedundant, bool aMergePads, bool aFixBoardOutlines, int aTolerance)
the cleanup function.
Definition kiid.h:49
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
static KIID ToUUID(wxDataViewItem aItem)
Definition rc_item.cpp:226
static int s_defaultTolerance
#define _(s)
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
@ RPT_SEVERITY_ACTION