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 
58 
60 {
61 }
62 
63 
65 {
67 
68  REPORTER& reporter = m_messagePanel->Reporter();
69  TOOL_MANAGER* toolManager = m_frame->GetToolManager();
70  BOARD* board = m_frame->GetBoard();
71 
72  // keep trace of the initial baord area, if we want to place new footprints
73  // outside the existinag board
74  EDA_RECT bbox = board->GetBoundingBox();
75 
76  if( !aDryRun )
77  {
78 
79  // Clear selection, just in case a selected item has to be removed
80  toolManager->RunAction( PCB_ACTIONS::selectionClear, true );
81  }
82 
86 
87  try
88  {
89  m_frame->LoadFootprints( *m_netlist, &reporter );
90  }
91  catch( IO_ERROR &error )
92  {
93  wxString msg;
94 
95  reporter.Report( _( "Failed to load one or more footprints. Please add the missing libraries in PCBNew configuration. "
96  "The PCB will not update completely." ), REPORTER::RPT_ERROR );
97  reporter.Report( error.What(), REPORTER::RPT_INFO );
98  }
99 
101  updater.SetReporter ( &reporter );
102  updater.SetIsDryRun( aDryRun );
103  updater.SetLookupByTimestamp( m_matchByTimestamp->GetValue() );
104  updater.SetDeleteUnusedComponents ( true );
105  updater.SetReplaceFootprints( true );
106  updater.SetDeleteSinglePadNets( false );
107  updater.UpdateNetlist( *m_netlist );
108 
110 
111  if( aDryRun )
112  return;
113 
114  m_frame->SetCurItem( NULL );
115  m_frame->SetMsgPanel( board );
116 
117  // Update rendered tracks and vias net labels
118  auto view = m_frame->GetGalCanvas()->GetView();
119 
120  // TODO is there a way to extract information about which nets were modified?
121  for( auto track : board->Tracks() )
122  view->Update( track );
123 
124  std::vector<MODULE*> newFootprints = updater.GetAddedComponents();
125 
126  // Spread new footprints.
127  wxPoint areaPosition = m_frame->GetCrossHairPosition();
128 
129  if( !m_frame->IsGalCanvasActive() )
130  {
131  // In legacy mode place area to the left side of the board.
132  // if the board is empty, the bbox position is (0,0)
133  areaPosition.x = bbox.GetEnd().x + Millimeter2iu( 10 );
134  areaPosition.y = bbox.GetOrigin().y;
135  }
136 
137  m_frame->SpreadFootprints( &newFootprints, false, false, areaPosition, false );
138 
139  if( m_frame->IsGalCanvasActive() )
140  {
141  // Start move and place the new modules command
142  if( !newFootprints.empty() )
143  {
144  for( MODULE* footprint : newFootprints )
145  {
146  toolManager->RunAction( PCB_ACTIONS::selectItem, true, footprint );
147  }
148 
149  toolManager->InvokeTool( "pcbnew.InteractiveEdit" );
150  }
151  }
152  else // Legacy canvas
153  m_frame->GetCanvas()->Refresh();
154 
155  m_btnPerformUpdate->Enable( false );
156  m_btnPerformUpdate->SetLabel( _( "Update complete" ) );
157  m_btnCancel->SetLabel( _( "Close" ) );
158  m_btnCancel->SetFocus();
159 }
160 
161 
162 void DIALOG_UPDATE_PCB::OnMatchChange( wxCommandEvent& event )
163 {
164  PerformUpdate( true );
165 }
166 
167 
168 void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event )
169 {
170  m_messagePanel->SetLabel( _( "Changes applied to the PCB:" ) );
171  PerformUpdate( false );
172  m_btnCancel->SetFocus();
173 }
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:785
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 bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:339
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:342
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 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:302
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:306
Class NETLIST stores all of information read from a netlist along with the flags used to update the N...
Definition: pcb_netlist.h:205
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:790
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:874
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:1382
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:889
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 Flush()
Forces updating the HTML page, after the report is built in lazy mode
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
The common library.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:882
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:249
void SetDeleteExtraFootprints(bool aDeleteExtraFootprints)
Definition: pcb_netlist.h:291
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:47
void PerformUpdate(bool aDryRun)
virtual void OnMatchChange(wxCommandEvent &event) override