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
46 if( aIsFootprintEditor )
47 {
48 SetupStandardButtons( { { wxID_OK, _( "Update Footprint" ) } } );
49 m_nettieHint->SetFont( KIUI::GetInfoFont( aParent ).Italic() );
50
51 m_fixBoardOutlines->Show( false );
52 m_toleranceSizer->Show( false );
53 }
54 else
55 {
56 SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) } } );
57 m_mergePadsOpt->Show( false );
58 m_nettieHint->Show( false );
59 }
60
61 GetSizer()->SetSizeHints(this);
62 Centre();
63}
64
65
70
71
72void DIALOG_CLEANUP_GRAPHICS::OnCheckBox( wxCommandEvent& anEvent )
73{
74 doCleanup( true );
75}
76
77
79{
81
82 doCleanup( true );
83
84 return true;
85}
86
87
89{
91
92 doCleanup( false );
93
94 return true;
95}
96
97
99{
100 wxBusyCursor busy;
101
102 BOARD_COMMIT commit( m_parentFrame );
103 BOARD* board = m_parentFrame->GetBoard();
104 FOOTPRINT* fp = m_isFootprintEditor ? board->GetFirstFootprint() : nullptr;
105 GRAPHICS_CLEANER cleaner( fp ? fp->GraphicalItems() : board->Drawings(), fp, commit,
106 m_parentFrame->GetToolManager() );
107
108 if( !aDryRun )
109 {
110 // Clear current selection list to avoid selection of deleted items
111 m_parentFrame->GetToolManager()->RunAction( ACTIONS::selectionClear );
112
113 // ... and to keep the treeModel from trying to refresh a deleted item
114 m_changesTreeModel->Update( nullptr, RPT_SEVERITY_ACTION );
115 }
116
117 m_items.clear();
118
119 // Old model has to be refreshed, GAL normally does not keep updating it
120 m_parentFrame->Compile_Ratsnest( false );
121
122 cleaner.CleanupBoard( aDryRun, &m_items, m_createRectanglesOpt->GetValue(),
123 m_deleteRedundantOpt->GetValue(), m_mergePadsOpt->GetValue(),
124 m_fixBoardOutlines->GetValue(), m_tolerance.GetIntValue() );
125
126 if( aDryRun )
127 {
128 m_changesTreeModel->Update( std::make_shared<VECTOR_CLEANUP_ITEMS_PROVIDER>( &m_items ),
130 }
131 else if( !commit.Empty() )
132 {
133 // Clear undo and redo lists to avoid inconsistencies between lists
134 commit.Push( _( "Cleanup Graphics" ) );
135 m_parentFrame->GetCanvas()->Refresh( true );
136 }
137}
138
139
140void DIALOG_CLEANUP_GRAPHICS::OnSelectItem( wxDataViewEvent& aEvent )
141{
142 const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
143
144 if( BOARD_ITEM* item = m_parentFrame->GetBoard()->ResolveItem( itemID, true ) )
145 {
147
148 if( !item->GetLayerSet().test( m_parentFrame->GetActiveLayer() ) )
149 m_parentFrame->SetActiveLayer( item->GetLayerSet().UIOrder().front() );
150
151 m_parentFrame->FocusOnItem( item );
152 m_parentFrame->GetCanvas()->Refresh();
153 }
154
155 aEvent.Skip();
156}
157
158
160{
161 event.Skip();
162
163 if( m_changesDataView->GetCurrentItem().IsOk() )
164 {
165 if( !IsModal() )
166 Show( false );
167 }
168}
169
170
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:223
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:79
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:317
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:488
const DRAWINGS & Drawings() const
Definition board.h:360
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:227
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:217
static int s_defaultTolerance
#define _(s)
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
@ RPT_SEVERITY_ACTION