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 
34  m_parentFrame( aParent ),
35  m_isModEdit( isModEdit )
36 {
38  m_changesDataView->AssociateModel( m_changesTreeModel );
39 
41 
42  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
43  // that requires us to correct the button labels here.
44  m_sdbSizerOK->SetLabel( isModEdit ? _( "Update Footprint" ) : _( "Update PCB" ) );
45 
46  m_sdbSizerOK->SetDefault();
47  GetSizer()->SetSizeHints(this);
48  Centre();
49 }
50 
51 
53 {
54  m_changesTreeModel->DecRef();
55 }
56 
57 
58 void DIALOG_CLEANUP_GRAPHICS::OnCheckBox( wxCommandEvent& anEvent )
59 {
60  doCleanup( true );
61 }
62 
63 
65 {
66  doCleanup( true );
67 
68  return true;
69 }
70 
71 
73 {
74  doCleanup( false );
75 
76  return true;
77 }
78 
79 
81 {
82  wxBusyCursor busy;
83 
84  BOARD_COMMIT commit( m_parentFrame );
85  BOARD* board = m_parentFrame->GetBoard();
86  MODULE* fp = m_isModEdit ? board->GetFirstModule() : nullptr;
87  GRAPHICS_CLEANER cleaner( fp ? fp->GraphicalItems() : board->Drawings(), fp, commit );
88 
89  if( !aDryRun )
90  {
91  // Clear current selection list to avoid selection of deleted items
93 
94  // ... and to keep the treeModel from trying to refresh a deleted item
95  m_changesTreeModel->SetProvider( nullptr );
96  }
97 
98  m_items.clear();
99 
100  // Old model has to be refreshed, GAL normally does not keep updating it
102 
103  cleaner.CleanupBoard( aDryRun, &m_items, m_createRectanglesOpt->GetValue(),
104  m_deleteRedundantOpt->GetValue() );
105 
106  if( aDryRun )
107  {
109  m_changesTreeModel->SetProvider( provider );
110  }
111  else if( !commit.Empty() )
112  {
113  // Clear undo and redo lists to avoid inconsistencies between lists
114  commit.Push( _( "Graphics cleanup" ) );
115  m_parentFrame->GetCanvas()->Refresh( true );
116  }
117 }
118 
119 
120 void DIALOG_CLEANUP_GRAPHICS::OnSelectItem( wxDataViewEvent& aEvent )
121 {
122  const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
123  BOARD_ITEM* item = m_parentFrame->GetBoard()->GetItem( itemID );
124  WINDOW_THAWER thawer( m_parentFrame );
125 
126  m_parentFrame->FocusOnItem( item );
128 
129  aEvent.Skip();
130 }
131 
132 
133 void DIALOG_CLEANUP_GRAPHICS::OnLeftDClickItem( wxMouseEvent& event )
134 {
135  event.Skip();
136 
137  if( m_changesDataView->GetCurrentItem().IsOk() )
138  {
139  if( !IsModal() )
140  Show( false );
141  }
142 }
143 
144 
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
BOARD_ITEM * GetItem(const KIID &aID) const
Class DIALOG_CLEANUP_GRAPHICS_BASE.
void SetProvider(RC_ITEMS_PROVIDER *aProvider)
Definition: rc_item.cpp:258
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:141
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:119
DIALOG_CLEANUP_GRAPHICS(PCB_BASE_FRAME *aParent, bool isModEdit)
DRAWINGS & GraphicalItems()
Definition: class_module.h:185
void SetSeverities(int aSeverities)
Definition: rc_item.cpp:264
Provide an abstract interface of a RC_ITEM* list manager.
Definition: rc_item.h:44
void OnSelectItem(wxDataViewEvent &event) override
Classes used in Pcbnew, CvPcb and GerbView.
Definition: common.h:70
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:346
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
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
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
#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:76
BOARD * GetBoard() const
DRAWINGS & Drawings()
Definition: class_board.h:287
void FocusOnItem(BOARD_ITEM *aItem)
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.