KiCad PCB EDA Suite
dialog_update_pcb.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #include <common.h>
29 #include <pcb_edit_frame.h>
30 #include <pcb_netlist.h>
31 #include <dialog_update_pcb.h>
32 #include <wx_html_report_panel.h>
33 #include <board_netlist_updater.h>
34 #include <tool/tool_manager.h>
35 #include <tools/pcb_actions.h>
36 #include <class_draw_panel_gal.h>
37 #include <class_drawpanel.h>
38 #include <class_board.h>
39 #include <ratsnest_data.h>
40 #include <view/view.h>
41 
42 #include <functional>
43 #include <kiface_i.h>
44 
45 using namespace std::placeholders;
46 
47 #define NETLIST_FILTER_MESSAGES_KEY wxT("NetlistReportFilterMsg")
48 #define NETLIST_UPDATEFOOTPRINTS_KEY wxT("NetlistUpdateFootprints")
49 #define NETLIST_DELETESHORTINGTRACKS_KEY wxT("NetlistDeleteShortingTracks")
50 #define NETLIST_DELETEEXTRAFOOTPRINTS_KEY wxT("NetlistDeleteExtraFootprints")
51 #define NETLIST_DELETESINGLEPADNETS_KEY wxT("NetlistDeleteSinglePadNets")
52 
53 
55  DIALOG_UPDATE_PCB_BASE( aParent ),
56  m_frame( aParent ),
57  m_netlist( aNetlist ),
58  m_initialized( false )
59 {
61 
65 
66  m_messagePanel->SetLabel( _("Changes To Be Applied") );
69 
71 
72  m_messagePanel->GetSizer()->SetSizeHints( this );
73 
74  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
75  // that requires us to correct the button labels here.
76  m_sdbSizer1OK->SetLabel( _( "Update PCB" ) );
77  m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
78  m_sdbSizer1->Layout();
79 
80  m_sdbSizer1OK->SetDefault();
82 
83  m_initialized = true;
84  PerformUpdate( true );
85 }
86 
87 
89 {
94 }
95 
96 
98 {
100 
101  REPORTER& reporter = m_messagePanel->Reporter();
102  TOOL_MANAGER* toolManager = m_frame->GetToolManager();
103  BOARD* board = m_frame->GetBoard();
104 
105  // keep trace of the initial baord area, if we want to place new footprints
106  // outside the existinag board
107  EDA_RECT bbox = board->GetBoundingBox();
108 
109  toolManager->RunAction( PCB_ACTIONS::selectionClear, true );
110 
112  m_netlist->SetFindByTimeStamp( m_matchByTimestamp->GetSelection() == 0 );
114 
116  updater.SetReporter ( &reporter );
117  updater.SetIsDryRun( aDryRun );
118  updater.SetLookupByTimestamp( m_matchByTimestamp->GetSelection() == 0 );
119  updater.SetDeleteUnusedComponents ( m_cbDeleteExtraFootprints->GetValue() );
120  updater.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
121  updater.SetDeleteSinglePadNets( m_cbDeleteSinglePadNets->GetValue() );
122  updater.UpdateNetlist( *m_netlist );
123 
124  m_messagePanel->Flush( true );
125 
126  if( aDryRun )
127  return;
128 
129  m_frame->SetCurItem( nullptr );
130  m_frame->SetMsgPanel( board );
131 
132  // Update rendered tracks and vias net labels
133  auto view = m_frame->GetGalCanvas()->GetView();
134 
135  // TODO is there a way to extract information about which nets were modified?
136  for( auto track : board->Tracks() )
137  view->Update( track );
138 
139  std::vector<MODULE*> newFootprints = updater.GetAddedComponents();
140 
141  // Spread new footprints.
142  wxPoint areaPosition = m_frame->GetCrossHairPosition();
143 
144  if( !m_frame->IsGalCanvasActive() )
145  {
146  // In legacy mode place area to the left side of the board.
147  // if the board is empty, the bbox position is (0,0)
148  areaPosition.x = bbox.GetEnd().x + Millimeter2iu( 10 );
149  areaPosition.y = bbox.GetOrigin().y;
150  }
151 
152  m_frame->SpreadFootprints( &newFootprints, false, false, areaPosition, false );
153 
154  if( m_frame->IsGalCanvasActive() )
155  {
156  // Start move and place the new modules command
157  if( !newFootprints.empty() )
158  {
159  for( MODULE* footprint : newFootprints )
160  toolManager->RunAction( PCB_ACTIONS::selectItem, true, footprint );
161  }
162  }
163 
164  m_frame->GetCanvas()->Refresh();
165 }
166 
167 
168 void DIALOG_UPDATE_PCB::OnMatchChanged( wxCommandEvent& event )
169 {
170  if( m_initialized )
171  PerformUpdate( true );
172 }
173 
174 
175 void DIALOG_UPDATE_PCB::OnOptionChanged( wxCommandEvent& event )
176 {
177  if( m_initialized )
178  PerformUpdate( true );
179 }
180 
181 
182 void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event )
183 {
184  m_messagePanel->SetLabel( _( "Changes Applied To PCB" ) );
185  PerformUpdate( false );
186  m_sdbSizer1Cancel->SetDefault();
187 }
void SetVisibleSeverities(int aSeverities)
Set the visible severity filter.
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: class_board.h:792
void SetLazyUpdate(bool aLazyUpdate)
Sets the lasy update.
const wxPoint GetOrigin() const
Definition: eda_rect.h:112
void SpreadFootprints(std::vector< MODULE * > *aFootprints, bool aMoveFootprintsOutsideBoardOnly, bool aCheckForBoardEdges, wxPoint aSpreadAreaPosition, bool aPrepareUndoCommand=true)
Function SpreadFootprints Footprints (after loaded by reading a netlist for instance) are moved to be...
virtual EDA_DRAW_PANEL * GetCanvas() const
Definition: draw_frame.h:388
void OnOptionChanged(wxCommandEvent &event) override
void OnMatchChanged(wxCommandEvent &event) override
Class BOARD_NETLIST_UPDATER updates the BOARD with a new netlist.
Class BOARD to handle a board.
Class DIALOG_UPDATE_PCB_BASE.
Class that computes missing connections on a PCB.
#define NETLIST_FILTER_MESSAGES_KEY
void Flush(bool aSort=false)
Forces updating the HTML page, after the report is built in lazy mode If aSort = true, the body messages will be ordered by severity
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
BOARD * GetBoard() const
BOARD_NETLIST_UPDATER class definition.
void SetFindByTimeStamp(bool aFindByTimeStamp)
Definition: pcb_netlist.h:311
void SetReporter(REPORTER *aReporter)
Sets the reporter object
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
PCB_EDIT_FRAME * m_frame
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
void SortByReference()
wxConfigBase * m_config
Class TOOL_MANAGER.
Definition: tool_manager.h:49
void OnUpdateClick(wxCommandEvent &event) override
void SetReplaceFootprints(bool aReplaceFootprints)
Definition: pcb_netlist.h:315
Class NETLIST stores all of information read from a netlist along with the flags used to update the N...
Definition: pcb_netlist.h:214
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
REPORTER & Reporter()
returns the reporter object that reports to this panel
#define NETLIST_DELETESINGLEPADNETS_KEY
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:921
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1530
const wxPoint GetEnd() const
Definition: eda_rect.h:114
WX_HTML_REPORT_PANEL * m_messagePanel
TOOL_MANAGER * GetToolManager() const
Return the tool manager instance, if any.
Definition: draw_frame.h:934
void Clear()
clears the report panel
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:56
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
The common library.
#define NETLIST_DELETEEXTRAFOOTPRINTS_KEY
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:928
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:253
#define NETLIST_UPDATEFOOTPRINTS_KEY
void SetDeleteExtraFootprints(bool aDeleteExtraFootprints)
Definition: pcb_netlist.h:300
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
DIALOG_UPDATE_PCB(PCB_EDIT_FRAME *aParent, NETLIST *aNetlist)
void SetLabel(const wxString &aLabel) override
sets the frame label
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
wxStdDialogButtonSizer * m_sdbSizer1
void PerformUpdate(bool aDryRun)