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 
24 #include <wx/wx.h>
26 #include <tool/tool_manager.h>
27 #include <tools/pcb_actions.h>
28 #include <graphics_cleaner.h>
29 #include <pcb_base_frame.h>
30 
31 
33  bool aIsFootprintEditor ) :
35  m_parentFrame( aParent ),
36  m_isFootprintEditor( aIsFootprintEditor )
37 {
39  m_changesDataView->AssociateModel( m_changesTreeModel );
40 
42 
43  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
44  // that requires us to correct the button labels here.
45  m_sdbSizerOK->SetLabel( aIsFootprintEditor ? _( "Update Footprint" ) : _( "Update PCB" ) );
46 
47  m_sdbSizerOK->SetDefault();
48  GetSizer()->SetSizeHints(this);
49  Centre();
50 }
51 
52 
54 {
55  m_changesTreeModel->DecRef();
56 }
57 
58 
59 void DIALOG_CLEANUP_GRAPHICS::OnCheckBox( wxCommandEvent& anEvent )
60 {
61  doCleanup( true );
62 }
63 
64 
66 {
67  doCleanup( true );
68 
69  return true;
70 }
71 
72 
74 {
75  doCleanup( false );
76 
77  return true;
78 }
79 
80 
82 {
83  wxBusyCursor busy;
84 
85  BOARD_COMMIT commit( m_parentFrame );
86  BOARD* board = m_parentFrame->GetBoard();
87  FOOTPRINT* fp = m_isFootprintEditor ? board->GetFirstFootprint() : nullptr;
88  GRAPHICS_CLEANER cleaner( fp ? fp->GraphicalItems() : board->Drawings(), fp, commit );
89 
90  if( !aDryRun )
91  {
92  // Clear current selection list to avoid selection of deleted items
94 
95  // ... and to keep the treeModel from trying to refresh a deleted item
96  m_changesTreeModel->SetProvider( nullptr );
97  }
98 
99  m_items.clear();
100 
101  // Old model has to be refreshed, GAL normally does not keep updating it
103 
104  cleaner.CleanupBoard( aDryRun, &m_items, m_createRectanglesOpt->GetValue(),
105  m_deleteRedundantOpt->GetValue() );
106 
107  if( aDryRun )
108  {
110  m_changesTreeModel->SetProvider( provider );
111  }
112  else if( !commit.Empty() )
113  {
114  // Clear undo and redo lists to avoid inconsistencies between lists
115  commit.Push( _( "Graphics cleanup" ) );
116  m_parentFrame->GetCanvas()->Refresh( true );
117  }
118 }
119 
120 
121 void DIALOG_CLEANUP_GRAPHICS::OnSelectItem( wxDataViewEvent& aEvent )
122 {
123  const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
124  BOARD_ITEM* item = m_parentFrame->GetBoard()->GetItem( itemID );
125  WINDOW_THAWER thawer( m_parentFrame );
126 
127  m_parentFrame->FocusOnItem( item );
129 
130  aEvent.Skip();
131 }
132 
133 
134 void DIALOG_CLEANUP_GRAPHICS::OnLeftDClickItem( wxMouseEvent& event )
135 {
136  event.Skip();
137 
138  if( m_changesDataView->GetCurrentItem().IsOk() )
139  {
140  if( !IsModal() )
141  Show( false );
142  }
143 }
144 
145 
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:63
BOARD_ITEM * GetItem(const KIID &aID) const
Definition: board.cpp:792
Class DIALOG_CLEANUP_GRAPHICS_BASE.
void SetProvider(RC_ITEMS_PROVIDER *aProvider)
Definition: rc_item.cpp:264
void Compile_Ratsnest(bool aDisplayStatus)
Create the entire board ratsnest.
Definition: ratsnest.cpp:41
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
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:141
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:119
void SetSeverities(int aSeverities)
Definition: rc_item.cpp:270
Provide an abstract interface of a RC_ITEM* list manager.
Definition: rc_item.h:43
void OnSelectItem(wxDataViewEvent &event) override
Classes used in Pcbnew, CvPcb and GerbView.
Definition: kiid.h:44
void OnCheckBox(wxCommandEvent &anEvent) override
FOOTPRINT * GetFirstFootprint() const
Gets the first footprint on the board or nullptr.
Definition: board.h:380
void OnLeftDClickItem(wxMouseEvent &event) override
VECTOR_CLEANUP_ITEMS_PROVIDER is an implementation of the interface named RC_ITEMS_PROVIDER which use...
Definition: cleanup_item.h:71
std::vector< std::shared_ptr< CLEANUP_ITEM > > m_items
DRAWINGS & GraphicalItems()
Definition: footprint.h:167
bool Show(bool show) override
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
bool Empty() const
Returns status of an item.
Definition: commit.h:140
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
#define _(s)
Definition: 3d_actions.cpp:33
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:55
BOARD * GetBoard() const
DRAWINGS & Drawings()
Definition: board.h:306
void FocusOnItem(BOARD_ITEM *aItem)
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.