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  if( m_runDragCommand )
96  m_frame->GetToolManager()->InvokeTool( "pcbnew.InteractiveEdit" );
97 }
98 
99 
101 {
103 
104  REPORTER& reporter = m_messagePanel->Reporter();
105  TOOL_MANAGER* toolManager = m_frame->GetToolManager();
106  BOARD* board = m_frame->GetBoard();
107 
108  // keep trace of the initial baord area, if we want to place new footprints
109  // outside the existinag board
110  EDA_RECT bbox = board->GetBoundingBox();
111 
112  toolManager->RunAction( PCB_ACTIONS::selectionClear, true );
113  m_runDragCommand = false;
114 
116  m_netlist->SetFindByTimeStamp( m_matchByTimestamp->GetSelection() == 0 );
118 
120  updater.SetReporter ( &reporter );
121  updater.SetIsDryRun( aDryRun );
122  updater.SetLookupByTimestamp( m_matchByTimestamp->GetSelection() == 0 );
123  updater.SetDeleteUnusedComponents ( m_cbDeleteExtraFootprints->GetValue() );
124  updater.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
125  updater.SetDeleteSinglePadNets( m_cbDeleteSinglePadNets->GetValue() );
126  updater.UpdateNetlist( *m_netlist );
127 
128  m_messagePanel->Flush( true );
129 
130  if( aDryRun )
131  return;
132 
133  m_frame->SetCurItem( nullptr );
134  m_frame->SetMsgPanel( board );
135 
136  // Update rendered tracks and vias net labels
137  auto view = m_frame->GetGalCanvas()->GetView();
138 
139  // TODO is there a way to extract information about which nets were modified?
140  for( auto track : board->Tracks() )
141  view->Update( track );
142 
143  std::vector<MODULE*> newFootprints = updater.GetAddedComponents();
144 
145  // Spread new footprints.
146  wxPoint areaPosition = m_frame->GetCrossHairPosition();
147 
148  if( !m_frame->IsGalCanvasActive() )
149  {
150  // In legacy mode place area to the left side of the board.
151  // if the board is empty, the bbox position is (0,0)
152  areaPosition.x = bbox.GetEnd().x + Millimeter2iu( 10 );
153  areaPosition.y = bbox.GetOrigin().y;
154  }
155 
156  m_frame->SpreadFootprints( &newFootprints, false, false, areaPosition, false );
157 
158  if( m_frame->IsGalCanvasActive() )
159  {
160  // Start drag command for new modules
161  if( !newFootprints.empty() )
162  {
163  for( MODULE* footprint : newFootprints )
164  toolManager->RunAction( PCB_ACTIONS::selectItem, true, footprint );
165 
166  m_runDragCommand = true;
167  }
168  }
169 
170  m_frame->GetCanvas()->Refresh();
171 }
172 
173 
174 void DIALOG_UPDATE_PCB::OnMatchChanged( wxCommandEvent& event )
175 {
176  if( m_initialized )
177  PerformUpdate( true );
178 }
179 
180 
181 void DIALOG_UPDATE_PCB::OnOptionChanged( wxCommandEvent& event )
182 {
183  if( m_initialized )
184  PerformUpdate( true );
185 }
186 
187 
188 void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event )
189 {
190  m_messagePanel->SetLabel( _( "Changes Applied To PCB" ) );
191  PerformUpdate( false );
192  m_sdbSizer1Cancel->SetDefault();
193 }
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:798
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:385
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
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID...
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:918
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:1538
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:931
void Clear()
clears the report panel
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:171
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:925
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:254
#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)