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 
30 
33  m_parentFrame( aParent ),
34  m_isModEdit( isModEdit )
35 {
37  m_changesDataView->AssociateModel( m_changesTreeModel );
38 
40 
41  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
42  // that requires us to correct the button labels here.
43  m_sdbSizerOK->SetLabel( isModEdit ? _( "Update Footprint" ) : _( "Update PCB" ) );
44 
45  m_sdbSizerOK->SetDefault();
46  GetSizer()->SetSizeHints(this);
47  Centre();
48 }
49 
50 
52 {
53  for( CLEANUP_ITEM* item : m_items )
54  delete item;
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  MODULE* fp = m_isModEdit ? board->GetFirstModule() : 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  for( CLEANUP_ITEM* item : m_items )
101  delete item;
102 
103  m_items.clear();
104 
105  // Old model has to be refreshed, GAL normally does not keep updating it
107 
108  cleaner.CleanupBoard( aDryRun, &m_items, m_createRectanglesOpt->GetValue(),
109  m_deleteRedundantOpt->GetValue() );
110 
111  if( aDryRun )
112  {
114  m_changesTreeModel->SetProvider( provider );
115  }
116  else if( !commit.Empty() )
117  {
118  // Clear undo and redo lists to avoid inconsistencies between lists
119  commit.Push( _( "Graphics cleanup" ) );
120  m_parentFrame->GetCanvas()->Refresh( true );
121  }
122 }
123 
124 
125 void DIALOG_CLEANUP_GRAPHICS::OnSelectItem( wxDataViewEvent& aEvent )
126 {
127  const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
128  BOARD_ITEM* item = m_parentFrame->GetBoard()->GetItem( itemID );
129  WINDOW_THAWER thawer( m_parentFrame );
130 
131  m_parentFrame->FocusOnItem( item );
133 
134  aEvent.Skip();
135 }
136 
137 
138 void DIALOG_CLEANUP_GRAPHICS::OnLeftDClickItem( wxMouseEvent& event )
139 {
140  event.Skip();
141 
142  if( m_changesDataView->GetCurrentItem().IsOk() )
143  {
144  if( !IsModal() )
145  Show( false );
146  }
147 }
148 
149 
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
Class DIALOG_CLEANUP_GRAPHICS_BASE.
void SetProvider(RC_ITEMS_PROVIDER *aProvider)
Definition: rc_item.cpp:227
void Compile_Ratsnest(bool aDisplayStatus)
Function Compile_Ratsnest Create the entire board ratsnest.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:91
DIALOG_CLEANUP_GRAPHICS(PCB_BASE_FRAME *aParent, bool isModEdit)
DRAWINGS & GraphicalItems()
Definition: class_module.h:183
BOARD_ITEM * GetItem(const KIID &aID)
void SetSeverities(int aSeverities)
Definition: rc_item.cpp:233
Provide an abstract interface of a RC_ITEM* list manager.
Definition: rc_item.h:42
void OnSelectItem(wxDataViewEvent &event) override
Definition: common.h:68
void OnCheckBox(wxCommandEvent &anEvent) override
void OnLeftDClickItem(wxMouseEvent &event) override
MODULE * GetFirstModule() const
Gets the first module in the list (used in footprint viewer/editor) or NULL if none.
Definition: class_board.h:330
VECTOR_CLEANUP_ITEMS_PROVIDER is an implementation of the interface named RC_ITEMS_PROVIDER which use...
Definition: cleanup_item.h:74
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
Definition: commit.h:139
std::vector< CLEANUP_ITEM * > m_items
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
#define _(s)
Definition: 3d_actions.cpp:33
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:74
BOARD * GetBoard() const
DRAWINGS & Drawings()
Definition: class_board.h:275
void FocusOnItem(BOARD_ITEM *aItem)
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.