KiCad PCB EDA Suite
dialog_footprint_checker.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 <pcb_marker.h>
30 #include <footprint_edit_frame.h>
33 
34 
37  m_frame( aParent )
38 {
40  m_markersDataView->AssociateModel( m_markersTreeModel );
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( _( "Run Checks" ) );
47  m_sdbSizerCancel->SetLabel( _( "Close" ) );
48 
49  m_sdbSizerOK->SetDefault();
50  m_sdbSizer->SetSizeHints( this );
51  GetSizer()->SetSizeHints(this);
52  Centre();
53 }
54 
55 
57 {
58  m_markersTreeModel->DecRef();
59 }
60 
61 
63 {
64  runChecks();
65 
66  return true;
67 }
68 
69 
71 {
72  return true;
73 }
74 
75 
77 {
78  BOARD* board = m_frame->GetBoard();
79  FOOTPRINT* footprint = board->GetFirstFootprint();
80  wxString msg;
81 
83 
84  if( !footprint )
85  {
86  msg = _( "No footprint loaded." );
87  return;
88  }
89 
90  OUTLINE_ERROR_HANDLER errorHandler =
91  [&]( const wxString& aMsg, BOARD_ITEM* aItemA, BOARD_ITEM* aItemB, const wxPoint& aPt )
92  {
93  std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MALFORMED_COURTYARD );
94 
95  drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + aMsg );
96  drcItem->SetItems( aItemA, aItemB );
97 
98  PCB_MARKER* marker = new PCB_MARKER( drcItem, aPt );
99  board->Add( marker );
100  m_frame->GetCanvas()->GetView()->Add( marker );
101  };
102 
103  footprint->BuildPolyCourtyards( &errorHandler );
104 
106 
107  WINDOW_THAWER thawer( m_frame );
108 
109  m_frame->GetCanvas()->Refresh();
110 }
111 
112 
114 {
115  m_markersTreeModel->SetProvider( aProvider );
116 }
117 
118 
119 void DIALOG_FOOTPRINT_CHECKER::OnRunChecksClick( wxCommandEvent& aEvent )
120 {
121  runChecks();
122 }
123 
124 
125 void DIALOG_FOOTPRINT_CHECKER::OnCancelClick( wxCommandEvent& aEvent )
126 {
127  m_frame->FocusOnItem( nullptr );
128 
129  SetReturnCode( wxID_CANCEL );
130 
131  // Leave the tool to destroy (or not) the dialog
133  tool->DestroyCheckerDialog();
134 }
135 
136 
137 void DIALOG_FOOTPRINT_CHECKER::OnClose( wxCloseEvent& aEvent )
138 {
139  wxCommandEvent dummy;
140  OnCancelClick( dummy );
141 }
142 
143 
144 void DIALOG_FOOTPRINT_CHECKER::OnSelectItem( wxDataViewEvent& aEvent )
145 {
146  const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
147  BOARD_ITEM* item = m_frame->GetBoard()->GetItem( itemID );
148  WINDOW_THAWER thawer( m_frame );
149 
150  m_frame->FocusOnItem( item );
151  m_frame->GetCanvas()->Refresh();
152 
153  aEvent.Skip();
154 }
155 
156 
158 {
159  event.Skip();
160 
161  if( m_markersDataView->GetCurrentItem().IsOk() )
162  {
163  if( !IsModal() )
164  Show( false );
165  }
166 }
167 
168 
169 void DIALOG_FOOTPRINT_CHECKER::OnDeleteAllClick( wxCommandEvent& event )
170 {
172 
173  WINDOW_THAWER thawer( m_frame );
174 
175  m_frame->GetCanvas()->Refresh();
176 }
177 
178 
180 {
181  // Clear current selection list to avoid selection of deleted items
183 
184  m_markersTreeModel->DeleteItems( false, true, true );
185 }
186 
187 
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:63
void BuildPolyCourtyards(OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr)
Build complex polygons of the courtyard areas from graphic items on the courtyard layers.
Definition: footprint.cpp:1881
BOARD_ITEM * GetItem(const KIID &aID) const
Definition: board.cpp:792
void DeleteItems(bool aCurrentOnly, bool aIncludeExclusions, bool aDeep)
Deletes the current item or all items.
Definition: rc_item.cpp:438
Module editor specific tools.
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:245
void OnDeleteAllClick(wxCommandEvent &event) override
void SetProvider(RC_ITEMS_PROVIDER *aProvider)
Definition: rc_item.cpp:264
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.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
Definition: sch_symbol.cpp:69
functions to convert a shape built with DRAWSEGMENTS to a polygon.
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:119
FOOTPRINT_EDIT_FRAME * m_frame
void OnClose(wxCloseEvent &event) override
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 Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:563
Definition: kiid.h:44
FOOTPRINT * GetFirstFootprint() const
Gets the first footprint on the board or nullptr.
Definition: board.h:380
BOARD_DRC_ITEMS_PROVIDER is an implementation of the RC_ITEMS_PROVIDER interface which uses a BOARD i...
void OnRunChecksClick(wxCommandEvent &aEvent) override
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
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...
Class DIALOG_FOOTPRINT_CHECKER_BASE.
void OnSelectItem(wxDataViewEvent &event) override
void SetMarkersProvider(RC_ITEMS_PROVIDER *aProvider)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
#define _(s)
Definition: 3d_actions.cpp:33
void OnCancelClick(wxCommandEvent &aEvent) override
DIALOG_FOOTPRINT_CHECKER(FOOTPRINT_EDIT_FRAME *aParent)
const std::function< void(const wxString &msg, BOARD_ITEM *itemA, BOARD_ITEM *itemB, const wxPoint &pt)> OUTLINE_ERROR_HANDLER
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
BOARD * GetBoard() const
void OnLeftDClickItem(wxMouseEvent &event) override
void FocusOnItem(BOARD_ITEM *aItem)