KiCad PCB EDA Suite
dialog_update_from_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) 2019 Alexander Shuklin <Jasuramme@gmail.com>
9  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, you may find one here:
23  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24  * or you may search the http://www.gnu.org website for the version 2 license,
25  * or you may write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27  */
28 
29 #include <backannotate.h>
30 #include <class_draw_panel_gal.h>
31 #include <common.h>
32 #include <confirm.h>
33 #include <dialog_update_from_pcb.h>
34 #include <functional>
35 #include <sch_edit_frame.h>
36 #include <sch_editor_control.h>
37 #include <tool/tool_manager.h>
38 #include <view/view.h>
39 #include <wx_html_report_panel.h>
40 
41 // Saved dialog settings
43  DIALOG_UPDATE_FROM_PCB::s_savedDialogState{ true, false, false, false };
44 
46  : DIALOG_UPDATE_FROM_PCB_BASE( aParent ),
47  m_frame( aParent ),
48  m_editorControl( m_frame->GetToolManager()->GetTool<SCH_EDITOR_CONTROL>() )
49 
50 {
51  m_messagePanel->SetLabel( _( "Changes To Be Applied" ) );
53  m_messagePanel->GetSizer()->SetSizeHints( this );
54 
59 
60  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
61  // that requires us to correct the button labels here.
62  m_sdbSizerOK->SetLabel( _( "Update Schematic" ) );
63  m_sdbSizerCancel->SetLabel( _( "Close" ) );
64  m_sdbSizer->Layout();
65 
66  m_sdbSizerOK->SetDefault();
68 }
69 
71 {
73  m_cbUpdateValues->GetValue(), m_cbUpdateReferences->GetValue(),
74  m_cbIgnoreOtherProjects->GetValue(), aDryRun };
75 }
76 
78 {
79  bool successfulRun = false;
81  BACK_ANNOTATE backAnno( this->m_frame, getSettings( true ) );
82  std::string netlist;
83 
84  if( backAnno.FetchNetlistFromPCB( netlist ) )
85  successfulRun = backAnno.BackAnnotateSymbols( netlist );
86  m_sdbSizerOK->Enable( successfulRun );
87  m_messagePanel->Flush( false );
88 }
89 
91 {
92  updateData();
93  return true;
94 }
95 
97 {
98 }
99 
100 void DIALOG_UPDATE_FROM_PCB::OnOptionChanged( wxCommandEvent& event )
101 {
102  updateData();
107 }
108 
109 void DIALOG_UPDATE_FROM_PCB::OnUpdateClick( wxCommandEvent& event )
110 {
111  KIDIALOG dlg( this,
112  _( "\n\nThis operation will change the existing annotation and cannot be undone." ),
113  _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
114  dlg.SetOKLabel( _( "Back annotate" ) );
115  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
116 
117  if( dlg.ShowModal() == wxID_CANCEL )
118  return;
119 
120  std::string netlist;
122  BACK_ANNOTATE backAnno( this->m_frame, getSettings( false ) );
123 
124  if( backAnno.FetchNetlistFromPCB( netlist ) && backAnno.BackAnnotateSymbols( netlist ) )
125  {
128  m_frame->SyncView();
129  m_frame->OnModify();
130  m_frame->GetCanvas()->Refresh();
131  }
132  m_messagePanel->Flush( true );
133 }
BACK_ANNOTATE::SETTINGS getSettings(bool aDryRun)
Creates back annotate settings from dialog ui.
void SetLazyUpdate(bool aLazyUpdate)
Sets the lasy update.
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox
Definition: confirm.cpp:53
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: confirm.h:44
This file is part of the common library.
Struct containing the dialog last saved state.
void Flush(bool aSort=false)
Forces updating the HTML page, after the report is built in lazy mode If aSort = true,...
DIALOG_UPDATE_FROM_PCB(SCH_EDIT_FRAME *aParent)
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void OnOptionChanged(wxCommandEvent &event) override
Schematic editor (Eeschema) main window.
void UpdateAllScreenReferences()
Function UpdateAllScreenReferences updates the reference and the m_Multi parameter (part selection) f...
bool BackAnnotateSymbols(const std::string &aNetlist)
Run back annotation algorithm.
SCH_EDITOR_CONTROL.
bool FetchNetlistFromPCB(std::string &aNetlist)
Get netlist from the PCBnew.
void SyncView()
Mark all items for refresh.
REPORTER & Reporter()
returns the reporter object that reports to this panel
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void OnUpdateClick(wxCommandEvent &event) override
Class DIALOG_UPDATE_FROM_PCB_BASE.
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...
void Clear()
clears the report panel
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
#define _(s)
Definition: 3d_actions.cpp:33
Back annotation algorithm class.
Definition: backannotate.h:58
static DIALOG_UPDATE_FROM_PCB_SAVED_STATE s_savedDialogState
The common library.
int ShowModal() override
Definition: confirm.cpp:95
SCH_SHEET_PATH & GetCurrentSheet() const
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
void SetLabel(const wxString &aLabel) override
sets the frame label
settings struct to set up back annotation
Definition: backannotate.h:64