You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.7 KiB

  1. /**
  2. * @file eeschema/dialogs/dialog_update_from_pcb.cpp
  3. */
  4. /*
  5. * This program source code file is part of KiCad, a free EDA CAD application.
  6. *
  7. * Copyright (C) 2019 Alexander Shuklin <Jasuramme@gmail.com>
  8. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.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. #include <backannotate.h>
  28. #include <class_draw_panel_gal.h>
  29. #include <common.h>
  30. #include <confirm.h>
  31. #include <dialog_update_from_pcb.h>
  32. #include <functional>
  33. #include <sch_edit_frame.h>
  34. #include <sch_editor_control.h>
  35. #include <tool/tool_manager.h>
  36. #include <view/view.h>
  37. #include <wx_html_report_panel.h>
  38. // Saved dialog settings
  39. DIALOG_UPDATE_FROM_PCB::DIALOG_UPDATE_FROM_PCB_SAVED_STATE
  40. DIALOG_UPDATE_FROM_PCB::s_savedDialogState{ true, false, false, false };
  41. DIALOG_UPDATE_FROM_PCB::DIALOG_UPDATE_FROM_PCB( SCH_EDIT_FRAME* aParent )
  42. : DIALOG_UPDATE_FROM_PCB_BASE( aParent ),
  43. m_frame( aParent ),
  44. m_editorControl( m_frame->GetToolManager()->GetTool<SCH_EDITOR_CONTROL>() )
  45. {
  46. m_messagePanel->SetLabel( _( "Changes To Be Applied" ) );
  47. m_messagePanel->SetLazyUpdate( true );
  48. m_messagePanel->GetSizer()->SetSizeHints( this );
  49. m_cbUpdateReferences->SetValue( s_savedDialogState.UpdateReferences );
  50. m_cbUpdateFootprints->SetValue( s_savedDialogState.UpdateFootprints );
  51. m_cbUpdateValues->SetValue( s_savedDialogState.UpdateValues );
  52. m_cbIgnoreOtherProjects->SetValue( s_savedDialogState.IgnoreOtherProjectsErrors );
  53. // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
  54. // that requires us to correct the button labels here.
  55. m_sdbSizerOK->SetLabel( _( "Update Schematic" ) );
  56. m_sdbSizerCancel->SetLabel( _( "Close" ) );
  57. m_sdbSizer->Layout();
  58. m_sdbSizerOK->SetDefault();
  59. FinishDialogSettings();
  60. }
  61. BACK_ANNOTATE::SETTINGS DIALOG_UPDATE_FROM_PCB::getSettings( bool aDryRun )
  62. {
  63. return BACK_ANNOTATE::SETTINGS{ m_messagePanel->Reporter(), m_cbUpdateFootprints->GetValue(),
  64. m_cbUpdateValues->GetValue(), m_cbUpdateReferences->GetValue(),
  65. m_cbIgnoreOtherProjects->GetValue(), aDryRun };
  66. }
  67. void DIALOG_UPDATE_FROM_PCB::updateData()
  68. {
  69. bool successfulRun = false;
  70. m_messagePanel->Clear();
  71. BACK_ANNOTATE backAnno( this->m_frame, getSettings( true ) );
  72. std::string netlist;
  73. if( backAnno.FetchNetlistFromPCB( netlist ) )
  74. successfulRun = backAnno.BackAnnotateSymbols( netlist );
  75. m_sdbSizerOK->Enable( successfulRun );
  76. m_messagePanel->Flush( false );
  77. }
  78. bool DIALOG_UPDATE_FROM_PCB::TransferDataToWindow()
  79. {
  80. updateData();
  81. return true;
  82. }
  83. DIALOG_UPDATE_FROM_PCB::~DIALOG_UPDATE_FROM_PCB()
  84. {
  85. }
  86. void DIALOG_UPDATE_FROM_PCB::OnOptionChanged( wxCommandEvent& event )
  87. {
  88. updateData();
  89. s_savedDialogState.UpdateReferences = m_cbUpdateReferences->GetValue();
  90. s_savedDialogState.UpdateFootprints = m_cbUpdateFootprints->GetValue();
  91. s_savedDialogState.UpdateValues = m_cbUpdateValues->GetValue();
  92. s_savedDialogState.IgnoreOtherProjectsErrors = m_cbIgnoreOtherProjects->GetValue();
  93. }
  94. void DIALOG_UPDATE_FROM_PCB::OnUpdateClick( wxCommandEvent& event )
  95. {
  96. KIDIALOG dlg( this,
  97. _( "\n\nThis operation will change the existing annotation and cannot be undone." ),
  98. _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
  99. dlg.SetOKLabel( _( "Back annotate" ) );
  100. dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
  101. if( dlg.ShowModal() == wxID_CANCEL )
  102. return;
  103. std::string netlist;
  104. m_messagePanel->Clear();
  105. BACK_ANNOTATE backAnno( this->m_frame, getSettings( false ) );
  106. if( backAnno.FetchNetlistFromPCB( netlist ) && backAnno.BackAnnotateSymbols( netlist ) )
  107. {
  108. g_CurrentSheet->UpdateAllScreenReferences();
  109. m_frame->SetSheetNumberAndCount();
  110. m_frame->SyncView();
  111. m_frame->OnModify();
  112. m_frame->GetCanvas()->Refresh();
  113. }
  114. m_messagePanel->Flush( true );
  115. }