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 (C) 2020-2023 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
37 bool aIsFootprintEditor ) :
39 m_parentFrame( aParent ),
40 m_isFootprintEditor( aIsFootprintEditor ),
41 m_tolerance( aParent, m_toleranceLabel, m_toleranceCtrl, m_toleranceUnits )
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
67{
68 m_changesTreeModel->DecRef();
69}
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,
107
108 if( !aDryRun )
109 {
110 // Clear current selection list to avoid selection of deleted items
112
113 // ... and to keep the treeModel from trying to refresh a deleted item
115 }
116
117 m_items.clear();
118
119 // Old model has to be refreshed, GAL normally does not keep updating it
121
122 cleaner.CleanupBoard( aDryRun, &m_items, m_createRectanglesOpt->GetValue(),
123 m_deleteRedundantOpt->GetValue(), m_mergePadsOpt->GetValue(),
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 BOARD_ITEM* item = m_parentFrame->GetBoard()->GetItem( itemID );
145
146 if( item && !item->GetLayerSet().test( m_parentFrame->GetActiveLayer() ) )
147 m_parentFrame->SetActiveLayer( item->GetLayerSet().UIOrder().front() );
148
149 m_parentFrame->FocusOnItem( item );
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:108
virtual void Push(const wxString &aMessage=wxEmptyString, 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:79
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:257
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
BOARD_ITEM * GetItem(const KIID &aID) const
Definition: board.cpp:1412
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:448
const DRAWINGS & Drawings() const
Definition: board.h:333
bool Empty() const
Returns status of an item.
Definition: commit.h:144
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
DRAWINGS & GraphicalItems()
Definition: footprint.h:209
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
LSEQ UIOrder() const
Returns the copper, technical and user layers in the order shown in layer widget.
Definition: lset.cpp:809
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:68
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:364
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:220
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
int GetIntValue()
Definition: unit_binder.h:129
virtual long long int GetValue()
Return the current value in Internal Units.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
static int s_defaultTolerance
#define _(s)
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:154
@ RPT_SEVERITY_ACTION
constexpr int mmToIU(double mm) const
Definition: base_units.h:88