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, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <board_commit.h>
22#include <footprint.h>
23#include <pad.h>
24#include <tool/tool_manager.h>
25#include <tools/pcb_actions.h>
26#include <graphics_cleaner.h>
27#include <pcb_base_frame.h>
28
29
30static int s_defaultTolerance = pcbIUScale.mmToIU( 2 );
31
33 bool aIsFootprintEditor ) :
35 m_parentFrame( aParent ),
36 m_isFootprintEditor( aIsFootprintEditor ),
38{
40 m_changesDataView->AssociateModel( m_changesTreeModel );
41 m_changesDataView->SetLayoutDirection( wxLayout_LeftToRight );
42
43 if( aIsFootprintEditor )
44 {
45 SetupStandardButtons( { { wxID_OK, _( "Update Footprint" ) } } );
46 m_nettieHint->SetFont( KIUI::GetInfoFont( aParent ).Italic() );
47
48 m_fixBoardOutlines->Show( false );
49 m_toleranceSizer->Show( false );
50 }
51 else
52 {
53 SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) } } );
54 m_mergePadsOpt->Show( false );
55 m_nettieHint->Show( false );
56 }
57
58 GetSizer()->SetSizeHints(this);
59 Centre();
60}
61
62
67
68
69void DIALOG_CLEANUP_GRAPHICS::OnCheckBox( wxCommandEvent& anEvent )
70{
71 doCleanup( true );
72}
73
74
76{
78
79 doCleanup( true );
80
81 return true;
82}
83
84
86{
88
89 doCleanup( false );
90
91 return true;
92}
93
94
96{
97 wxBusyCursor busy;
98
100 BOARD* board = m_parentFrame->GetBoard();
101 FOOTPRINT* fp = m_isFootprintEditor ? board->GetFirstFootprint() : nullptr;
102 GRAPHICS_CLEANER cleaner( fp ? fp->GraphicalItems() : board->Drawings(), fp, commit,
103 m_parentFrame->GetToolManager() );
104
105 if( !aDryRun )
106 {
107 // Clear current selection list to avoid selection of deleted items
108 m_parentFrame->GetToolManager()->RunAction( ACTIONS::selectionClear );
109
110 // ... and to keep the treeModel from trying to refresh a deleted item
111 m_changesTreeModel->Update( nullptr, RPT_SEVERITY_ACTION );
112 }
113
114 m_items.clear();
115
116 // Old model has to be refreshed, GAL normally does not keep updating it
117 m_parentFrame->GetBoard()->CompileRatsnest();
118
119 cleaner.CleanupBoard( aDryRun, &m_items, m_createRectanglesOpt->GetValue(),
120 m_deleteRedundantOpt->GetValue(), m_mergePadsOpt->GetValue(),
121 m_fixBoardOutlines->GetValue(), m_tolerance.GetIntValue() );
122
123 if( aDryRun )
124 {
125 m_changesTreeModel->Update( std::make_shared<VECTOR_CLEANUP_ITEMS_PROVIDER>( &m_items ),
127 }
128 else if( !commit.Empty() )
129 {
130 // Clear undo and redo lists to avoid inconsistencies between lists
131 commit.Push( _( "Cleanup Graphics" ) );
132 m_parentFrame->GetCanvas()->Refresh( true );
133 }
134}
135
136
137void DIALOG_CLEANUP_GRAPHICS::OnSelectItem( wxDataViewEvent& aEvent )
138{
139 const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
140
141 if( BOARD_ITEM* item = m_parentFrame->GetBoard()->ResolveItem( itemID, true ) )
142 {
144
145 if( !item->GetLayerSet().test( m_parentFrame->GetActiveLayer() ) )
146 m_parentFrame->SetActiveLayer( item->GetLayerSet().UIOrder().front() );
147
148 m_parentFrame->FocusOnItem( item );
149 m_parentFrame->GetCanvas()->Refresh();
150 }
151
152 aEvent.Skip();
153}
154
155
157{
158 event.Skip();
159
160 if( m_changesDataView->GetCurrentItem().IsOk() )
161 {
162 if( !IsModal() )
163 Show( false );
164 }
165}
166
167
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:220
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:81
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:587
const DRAWINGS & Drawings() const
Definition board.h:422
bool Empty() const
Definition commit.h:134
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:378
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:44
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
static KIID ToUUID(wxDataViewItem aItem)
Definition rc_item.cpp:223
static int s_defaultTolerance
#define _(s)
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
@ RPT_SEVERITY_ACTION