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 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 <tool/tool_manager.h>
28 #include <tools/pcb_actions.h>
29 #include <graphics_cleaner.h>
30 #include <pcb_base_frame.h>
31 
32 
34  bool aIsFootprintEditor ) :
36  m_parentFrame( aParent ),
37  m_isFootprintEditor( aIsFootprintEditor )
38 {
40  m_changesDataView->AssociateModel( m_changesTreeModel );
41 
43 
44  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
45  // that requires us to correct the button labels here.
46  m_sdbSizerOK->SetLabel( aIsFootprintEditor ? _( "Update Footprint" ) : _( "Update PCB" ) );
47 
48  m_sdbSizerOK->SetDefault();
49  GetSizer()->SetSizeHints(this);
50  Centre();
51 }
52 
53 
55 {
56  m_changesTreeModel->DecRef();
57 }
58 
59 
60 void DIALOG_CLEANUP_GRAPHICS::OnCheckBox( wxCommandEvent& anEvent )
61 {
62  doCleanup( true );
63 }
64 
65 
67 {
68  doCleanup( true );
69 
70  return true;
71 }
72 
73 
75 {
76  doCleanup( false );
77 
78  return true;
79 }
80 
81 
83 {
84  wxBusyCursor busy;
85 
86  BOARD_COMMIT commit( m_parentFrame );
87  BOARD* board = m_parentFrame->GetBoard();
88  FOOTPRINT* fp = m_isFootprintEditor ? board->GetFirstFootprint() : nullptr;
89  GRAPHICS_CLEANER cleaner( fp ? fp->GraphicalItems() : board->Drawings(), fp, commit );
90 
91  if( !aDryRun )
92  {
93  // Clear current selection list to avoid selection of deleted items
95 
96  // ... and to keep the treeModel from trying to refresh a deleted item
97  m_changesTreeModel->SetProvider( nullptr );
98  }
99 
100  m_items.clear();
101 
102  // Old model has to be refreshed, GAL normally does not keep updating it
104 
105  cleaner.CleanupBoard( aDryRun, &m_items, m_createRectanglesOpt->GetValue(),
106  m_deleteRedundantOpt->GetValue() );
107 
108  if( aDryRun )
109  {
111  m_changesTreeModel->SetProvider( provider );
112  }
113  else if( !commit.Empty() )
114  {
115  // Clear undo and redo lists to avoid inconsistencies between lists
116  commit.Push( _( "Graphics cleanup" ) );
117  m_parentFrame->GetCanvas()->Refresh( true );
118  }
119 }
120 
121 
122 void DIALOG_CLEANUP_GRAPHICS::OnSelectItem( wxDataViewEvent& aEvent )
123 {
124  const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
125  BOARD_ITEM* item = m_parentFrame->GetBoard()->GetItem( itemID );
126  WINDOW_THAWER thawer( m_parentFrame );
127 
128  m_parentFrame->FocusOnItem( item );
130 
131  aEvent.Skip();
132 }
133 
134 
135 void DIALOG_CLEANUP_GRAPHICS::OnLeftDClickItem( wxMouseEvent& event )
136 {
137  event.Skip();
138 
139  if( m_changesDataView->GetCurrentItem().IsOk() )
140  {
141  if( !IsModal() )
142  Show( false );
143  }
144 }
145 
146 
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
BOARD_ITEM * GetItem(const KIID &aID) const
Definition: board.cpp:867
Class DIALOG_CLEANUP_GRAPHICS_BASE.
void SetProvider(RC_ITEMS_PROVIDER *aProvider)
Definition: rc_item.cpp:289
void Compile_Ratsnest(bool aDisplayStatus)
Create the entire board ratsnest.
Definition: ratsnest.cpp:40
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
DIALOG_CLEANUP_GRAPHICS(PCB_BASE_FRAME *aParent, bool aIsFootprintEditor)
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:144
void SetSeverities(int aSeverities)
Definition: rc_item.cpp:295
Provide an abstract interface of a RC_ITEM* list manager.
Definition: rc_item.h:45
void OnSelectItem(wxDataViewEvent &event) override
Classes used in Pcbnew, CvPcb and GerbView.
Definition: kiid.h:44
void OnCheckBox(wxCommandEvent &anEvent) override
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:317
void OnLeftDClickItem(wxMouseEvent &event) override
An implementation of the interface named RC_ITEMS_PROVIDER which uses a vector of pointers to CLEANUP...
Definition: cleanup_item.h:69
std::vector< std::shared_ptr< CLEANUP_ITEM > > m_items
#define _(s)
DRAWINGS & GraphicalItems()
Definition: footprint.h:162
bool Show(bool show) override
bool Empty() const
Returns status of an item.
Definition: commit.h:140
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
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...
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Revert the commit by restoring the modified items state.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
BOARD * GetBoard() const
DRAWINGS & Drawings()
Definition: board.h:236
void FocusOnItem(BOARD_ITEM *aItem)
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.