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.

188 lines
7.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <design_block.h>
  24. #include <widgets/sch_design_block_pane.h>
  25. #include <widgets/sch_design_block_preview_widget.h>
  26. #include <widgets/panel_design_block_chooser.h>
  27. #include <kiface_base.h>
  28. #include <sch_edit_frame.h>
  29. #include <core/kicad_algo.h>
  30. #include <template_fieldnames.h>
  31. #include <wx/button.h>
  32. #include <wx/checkbox.h>
  33. #include <wx/sizer.h>
  34. #include <sch_actions.h>
  35. #include <tool/tool_manager.h>
  36. #include <tools/sch_design_block_control.h>
  37. // Do not make these static wxStrings; they need to respond to language changes
  38. #define REPEATED_PLACEMENT _( "Place repeated copies" )
  39. #define PLACE_AS_SHEET _( "Place as sheet" )
  40. #define PLACE_AS_GROUP _( "Place as group" )
  41. #define KEEP_ANNOTATIONS _( "Keep annotations" )
  42. SCH_DESIGN_BLOCK_PANE::SCH_DESIGN_BLOCK_PANE( SCH_EDIT_FRAME* aParent, const LIB_ID* aPreselect,
  43. std::vector<LIB_ID>& aHistoryList ) :
  44. DESIGN_BLOCK_PANE( aParent, aPreselect, aHistoryList )
  45. {
  46. wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
  47. m_chooserPanel = new PANEL_DESIGN_BLOCK_CHOOSER( aParent, this, aHistoryList,
  48. [aParent]()
  49. {
  50. aParent->GetToolManager()->RunAction(
  51. SCH_ACTIONS::placeDesignBlock );
  52. },
  53. aParent->GetToolManager()->GetTool<SCH_DESIGN_BLOCK_CONTROL>()
  54. );
  55. // Use the same draw engine type as the one used in parent frame m_frame
  56. EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = m_frame->GetCanvas()->GetBackend();
  57. m_chooserPanel->SetPreviewWidget(
  58. new SCH_DESIGN_BLOCK_PREVIEW_WIDGET( m_chooserPanel->GetDetailsPanel(), canvasType, true ) );
  59. sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
  60. if( aPreselect && aPreselect->IsValid() )
  61. m_chooserPanel->SetPreselect( *aPreselect );
  62. SetName( wxT( "Design Blocks" ) );
  63. wxBoxSizer* cbSizer = new wxBoxSizer( wxVERTICAL );
  64. m_repeatedPlacement = new wxCheckBox( this, wxID_ANY, REPEATED_PLACEMENT );
  65. m_placeAsGroup = new wxCheckBox( this, wxID_ANY, PLACE_AS_GROUP );
  66. m_placeAsSheet = new wxCheckBox( this, wxID_ANY, PLACE_AS_SHEET );
  67. m_keepAnnotations = new wxCheckBox( this, wxID_ANY, KEEP_ANNOTATIONS );
  68. setLabelsAndTooltips();
  69. UpdateCheckboxes();
  70. // Set all checkbox handlers to the same function
  71. m_repeatedPlacement->Bind( wxEVT_CHECKBOX, &SCH_DESIGN_BLOCK_PANE::OnCheckBox, this );
  72. m_placeAsGroup->Bind( wxEVT_CHECKBOX, &SCH_DESIGN_BLOCK_PANE::OnCheckBox, this );
  73. m_placeAsSheet->Bind( wxEVT_CHECKBOX, &SCH_DESIGN_BLOCK_PANE::OnCheckBox, this );
  74. m_keepAnnotations->Bind( wxEVT_CHECKBOX, &SCH_DESIGN_BLOCK_PANE::OnCheckBox, this );
  75. cbSizer->Add( m_repeatedPlacement, 0, wxTOP | wxLEFT, 2 );
  76. cbSizer->Add( m_placeAsGroup, 0, wxTOP | wxLEFT, 2 );
  77. cbSizer->Add( m_placeAsSheet, 0, wxTOP | wxLEFT, 2 );
  78. cbSizer->Add( m_keepAnnotations, 0, wxTOP | wxLEFT | wxBOTTOM, 2 );
  79. sizer->Add( cbSizer, 0, wxEXPAND, 5 );
  80. SetSizer( sizer );
  81. m_chooserPanel->FinishSetup();
  82. Layout();
  83. Bind( wxEVT_CHAR_HOOK, &PANEL_DESIGN_BLOCK_CHOOSER::OnChar, m_chooserPanel );
  84. }
  85. void SCH_DESIGN_BLOCK_PANE::setLabelsAndTooltips()
  86. {
  87. if( m_repeatedPlacement )
  88. {
  89. m_repeatedPlacement->SetLabel( REPEATED_PLACEMENT );
  90. m_repeatedPlacement->SetToolTip( _( "Place copies of the design block on subsequent "
  91. "clicks." ) );
  92. }
  93. if( m_placeAsGroup )
  94. {
  95. m_placeAsGroup->SetLabel( PLACE_AS_GROUP );
  96. m_placeAsGroup->SetToolTip( _( "Place the design block as a group." ) );
  97. }
  98. if( m_placeAsSheet )
  99. {
  100. m_placeAsSheet->SetLabel( PLACE_AS_SHEET );
  101. m_placeAsSheet->SetToolTip( _( "Place the design block as a new sheet." ) );
  102. }
  103. if( m_keepAnnotations )
  104. {
  105. m_keepAnnotations->SetLabel( KEEP_ANNOTATIONS );
  106. m_keepAnnotations->SetToolTip( _( "Preserve reference designators in the source "
  107. "schematic. Otherwise, clear then reannotate according "
  108. "to settings." ) );
  109. }
  110. }
  111. void SCH_DESIGN_BLOCK_PANE::OnCheckBox( wxCommandEvent& aEvent )
  112. {
  113. if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
  114. {
  115. cfg->m_DesignBlockChooserPanel.repeated_placement = m_repeatedPlacement->GetValue();
  116. cfg->m_DesignBlockChooserPanel.place_as_group = m_placeAsGroup->GetValue();
  117. cfg->m_DesignBlockChooserPanel.place_as_sheet = m_placeAsSheet->GetValue();
  118. cfg->m_DesignBlockChooserPanel.keep_annotations = m_keepAnnotations->GetValue();
  119. }
  120. }
  121. void SCH_DESIGN_BLOCK_PANE::UpdateCheckboxes()
  122. {
  123. if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
  124. {
  125. m_repeatedPlacement->SetValue( cfg->m_DesignBlockChooserPanel.repeated_placement );
  126. m_placeAsGroup->SetValue( cfg->m_DesignBlockChooserPanel.place_as_group );
  127. m_placeAsSheet->SetValue( cfg->m_DesignBlockChooserPanel.place_as_sheet );
  128. m_keepAnnotations->SetValue( cfg->m_DesignBlockChooserPanel.keep_annotations );
  129. }
  130. }
  131. FILEDLG_IMPORT_SHEET_CONTENTS::FILEDLG_IMPORT_SHEET_CONTENTS( EESCHEMA_SETTINGS* aSettings ) :
  132. m_cbRepeatedPlacement( nullptr ), m_cbPlaceAsGroup( nullptr ), m_cbPlaceAsSheet( nullptr ),
  133. m_cbKeepAnnotations( nullptr )
  134. {
  135. wxASSERT( aSettings );
  136. m_settings = aSettings;
  137. };
  138. void FILEDLG_IMPORT_SHEET_CONTENTS::TransferDataFromCustomControls()
  139. {
  140. m_settings->m_DesignBlockChooserPanel.repeated_placement = m_cbRepeatedPlacement->GetValue();
  141. m_settings->m_DesignBlockChooserPanel.place_as_group = m_cbPlaceAsGroup->GetValue();
  142. m_settings->m_DesignBlockChooserPanel.place_as_sheet = m_cbPlaceAsSheet->GetValue();
  143. m_settings->m_DesignBlockChooserPanel.keep_annotations = m_cbKeepAnnotations->GetValue();
  144. }
  145. void FILEDLG_IMPORT_SHEET_CONTENTS::AddCustomControls( wxFileDialogCustomize& customizer )
  146. {
  147. #ifdef __WXMAC__
  148. customizer.AddStaticText( wxT( "\n\n" ) ); // Increase height of static box
  149. #endif
  150. m_cbRepeatedPlacement = customizer.AddCheckBox( REPEATED_PLACEMENT );
  151. m_cbRepeatedPlacement->SetValue( m_settings->m_DesignBlockChooserPanel.repeated_placement );
  152. m_cbPlaceAsGroup = customizer.AddCheckBox( PLACE_AS_GROUP );
  153. m_cbPlaceAsGroup->SetValue( m_settings->m_DesignBlockChooserPanel.place_as_group );
  154. m_cbPlaceAsSheet = customizer.AddCheckBox( PLACE_AS_SHEET );
  155. m_cbPlaceAsSheet->SetValue( m_settings->m_DesignBlockChooserPanel.place_as_sheet );
  156. m_cbKeepAnnotations = customizer.AddCheckBox( KEEP_ANNOTATIONS );
  157. m_cbKeepAnnotations->SetValue( m_settings->m_DesignBlockChooserPanel.keep_annotations );
  158. }