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 using namespace std::placeholders;
44 
46  DIALOG_UPDATE_PCB_BASE( aParent ),
47  m_frame( aParent ),
48  m_netlist( aNetlist )
49 {
50  m_messagePanel->SetLabel( _("Changes to be applied:") );
53  m_btnPerformUpdate->SetFocus();
54 
56 
57  m_messagePanel->GetSizer()->SetSizeHints( this );
58  GetSizer()->SetSizeHints( this );
59 }
60 
61 
63 {
64 }
65 
66 
68 {
70 
71  REPORTER& reporter = m_messagePanel->Reporter();
72  TOOL_MANAGER* toolManager = m_frame->GetToolManager();
73  BOARD* board = m_frame->GetBoard();
74 
75  // keep trace of the initial baord area, if we want to place new footprints
76  // outside the existinag board
77  EDA_RECT bbox = board->GetBoundingBox();
78 
79  if( !aDryRun )
80  {
81 
82  // Clear selection, just in case a selected item has to be removed
83  toolManager->RunAction( PCB_ACTIONS::selectionClear, true );
84  }
85 
89 
90  try
91  {
92  m_frame->LoadFootprints( *m_netlist, &reporter );
93  }
94  catch( IO_ERROR &error )
95  {
96  wxString msg;
97 
98  reporter.ReportTail( _( "Failed to load one or more footprints. Please add the missing libraries in PCBNew configuration. "
99  "The PCB will not update completely." ), REPORTER::RPT_ERROR );
100  reporter.ReportTail( error.What(), REPORTER::RPT_INFO );
101  }
102 
104  updater.SetReporter ( &reporter );
105  updater.SetIsDryRun( aDryRun );
106  updater.SetLookupByTimestamp( m_matchByTimestamp->GetValue() );
107  updater.SetDeleteUnusedComponents ( true );
108  updater.SetReplaceFootprints( true );
109  updater.SetDeleteSinglePadNets( false );
110  updater.UpdateNetlist( *m_netlist );
111 
112  m_messagePanel->Flush( true );
113 
114  if( aDryRun )
115  return;
116 
117  m_frame->SetCurItem( NULL );
118  m_frame->SetMsgPanel( board );
119 
120  // Update rendered tracks and vias net labels
121  auto view = m_frame->GetGalCanvas()->GetView();
122 
123  // TODO is there a way to extract information about which nets were modified?
124  for( auto track : board->Tracks() )
125  view->Update( track );
126 
127  std::vector<MODULE*> newFootprints = updater.GetAddedComponents();
128 
129  // Spread new footprints.
130  wxPoint areaPosition = m_frame->GetCrossHairPosition();
131 
132  if( !m_frame->IsGalCanvasActive() )
133  {
134  // In legacy mode place area to the left side of the board.
135  // if the board is empty, the bbox position is (0,0)
136  areaPosition.x = bbox.GetEnd().x + Millimeter2iu( 10 );
137  areaPosition.y = bbox.GetOrigin().y;
138  }
139 
140  m_frame->SpreadFootprints( &newFootprints, false, false, areaPosition, false );
141 
142  if( m_frame->IsGalCanvasActive() )
143  {
144  // Start move and place the new modules command
145  if( !newFootprints.empty() )
146  {
147  for( MODULE* footprint : newFootprints )
148  {
149  toolManager->RunAction( PCB_ACTIONS::selectItem, true, footprint );
150  }
151 
152  toolManager->InvokeTool( "pcbnew.InteractiveEdit" );
153  }
154  }
155  else // Legacy canvas
156  m_frame->GetCanvas()->Refresh();
157 
158  m_btnPerformUpdate->Enable( false );
159  m_btnPerformUpdate->SetLabel( _( "Update complete" ) );
160  m_btnCancel->SetLabel( _( "Close" ) );
161  m_btnCancel->SetFocus();
162 }
163 
164 
165 void DIALOG_UPDATE_PCB::OnMatchChange( wxCommandEvent& event )
166 {
167  PerformUpdate( true );
168 }
169 
170 
171 void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event )
172 {
173  m_messagePanel->SetLabel( _( "Changes applied to the PCB:" ) );
174  PerformUpdate( false );
175  m_btnCancel->SetFocus();
176 }
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:789
void SetLazyUpdate(bool aLazyUpdate)
Sets the lasy update.
wxRadioButton * m_matchByTimestamp
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 void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:338
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:359
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.
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 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
void SortByReference()
Class TOOL_MANAGER.
Definition: tool_manager.h:49
virtual 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)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:831
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)
Function ReportTail Places the report at the end of the list, for objects that support report orderin...
Definition: reporter.h:109
REPORTER & Reporter()
returns the reporter object that reports to this panel
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:895
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:1499
const wxPoint GetEnd() const
Definition: eda_rect.h:114
WX_HTML_REPORT_PANEL * m_messagePanel
TOOL_MANAGER * GetToolManager() const
Function GetToolManager returns the tool manager instance, if any.
Definition: draw_frame.h:910
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void LoadFootprints(NETLIST &aNetlist, REPORTER *aReporter)
Function loadFootprints loads the footprints for each COMPONENT in aNetlist from the list of librarie...
Definition: netlist.cpp:227
void Clear()
clears the report panel
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
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.
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:903
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:252
void SetDeleteExtraFootprints(bool aDeleteExtraFootprints)
Definition: pcb_netlist.h:300
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
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
void PerformUpdate(bool aDryRun)
virtual void OnMatchChange(wxCommandEvent &event) override