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.

228 lines
10 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 <sch_edit_frame.h>
  24. #include <sch_painter.h>
  25. #include <kiface_base.h>
  26. #include <panel_setup_formatting.h>
  27. #include <sch_junction.h>
  28. #include <schematic.h>
  29. #include <schematic_settings.h>
  30. #include <project/project_file.h>
  31. #include <project/net_settings.h>
  32. PANEL_SETUP_FORMATTING::PANEL_SETUP_FORMATTING( wxWindow* aWindow, SCH_EDIT_FRAME* aFrame ) :
  33. PANEL_SETUP_FORMATTING_BASE( aWindow ),
  34. m_frame( aFrame ),
  35. m_textSize( aFrame, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits ),
  36. m_lineWidth( aFrame, m_lineWidthLabel, m_lineWidthCtrl, m_lineWidthUnits ),
  37. m_pinSymbolSize( aFrame, m_pinSymbolSizeLabel, m_pinSymbolSizeCtrl, m_pinSymbolSizeUnits ),
  38. m_connectionGridSize( aFrame, m_connectionGridLabel, m_connectionGridCtrl,
  39. m_connectionGridUnits )
  40. {
  41. wxSize minSize = m_dashLengthCtrl->GetMinSize();
  42. int minWidth = m_dashLengthCtrl->GetTextExtent( wxT( "XXX.XXX" ) ).GetWidth();
  43. m_dashLengthCtrl->SetMinSize( wxSize( minWidth, minSize.GetHeight() ) );
  44. m_gapLengthCtrl->SetMinSize( wxSize( minWidth, minSize.GetHeight() ) );
  45. m_dashedLineHelp->SetFont( KIUI::GetSmallInfoFont( this ).Italic() );
  46. }
  47. void PANEL_SETUP_FORMATTING::onCheckBoxIref( wxCommandEvent& event )
  48. {
  49. bool enabled = m_showIntersheetsReferences->GetValue();
  50. m_radioFormatStandard->Enable( enabled );
  51. m_radioFormatAbbreviated->Enable( enabled );
  52. m_prefixLabel->Enable( enabled );
  53. m_prefixCtrl->Enable( enabled );
  54. m_suffixLabel->Enable( enabled );
  55. m_suffixCtrl->Enable( enabled );
  56. m_listOwnPage->Enable( enabled );
  57. }
  58. int getRefStyleMenuIndex( int aSubpartIdSeparator, int aFirstSubpartId )
  59. {
  60. // Reference style one of: "A" ".A" "-A" "_A" ".1" "-1" "_1"
  61. switch( aSubpartIdSeparator )
  62. {
  63. default:
  64. case 0: return 0;
  65. case '.': return aFirstSubpartId == '1' ? 4 : 1;
  66. case '-': return aFirstSubpartId == '1' ? 5 : 2;
  67. case '_': return aFirstSubpartId == '1' ? 6 : 3;
  68. }
  69. }
  70. bool PANEL_SETUP_FORMATTING::TransferDataToWindow()
  71. {
  72. SCHEMATIC_SETTINGS& settings = m_frame->Schematic().Settings();
  73. m_choiceSeparatorRefId->SetSelection( getRefStyleMenuIndex( settings.m_SubpartIdSeparator,
  74. settings.m_SubpartFirstId ) );
  75. m_textSize.SetUnits( EDA_UNITS::MILS );
  76. m_lineWidth.SetUnits( EDA_UNITS::MILS );
  77. m_pinSymbolSize.SetUnits( EDA_UNITS::MILS );
  78. m_connectionGridSize.SetUnits( EDA_UNITS::MILS );
  79. m_textSize.SetValue( settings.m_DefaultTextSize );
  80. m_lineWidth.SetValue( settings.m_DefaultLineWidth );
  81. m_pinSymbolSize.SetValue( settings.m_PinSymbolSize );
  82. m_choiceJunctionDotSize->SetSelection( settings.m_JunctionSizeChoice );
  83. m_connectionGridSize.SetValue( settings.m_ConnectionGridSize );
  84. m_showIntersheetsReferences->SetValue( settings.m_IntersheetRefsShow );
  85. m_radioFormatStandard->Enable( settings.m_IntersheetRefsShow );
  86. m_radioFormatAbbreviated->Enable( settings.m_IntersheetRefsShow );
  87. m_prefixLabel->Enable( settings.m_IntersheetRefsShow );
  88. m_prefixCtrl->Enable( settings.m_IntersheetRefsShow );
  89. m_suffixLabel->Enable( settings.m_IntersheetRefsShow );
  90. m_suffixCtrl->Enable( settings.m_IntersheetRefsShow );
  91. m_listOwnPage->Enable( settings.m_IntersheetRefsShow );
  92. m_radioFormatStandard->SetValue( !settings.m_IntersheetRefsFormatShort );
  93. m_radioFormatAbbreviated->SetValue( settings.m_IntersheetRefsFormatShort );
  94. m_prefixCtrl->ChangeValue( settings.m_IntersheetRefsPrefix );
  95. m_suffixCtrl->ChangeValue( settings.m_IntersheetRefsSuffix );
  96. m_listOwnPage->SetValue( settings.m_IntersheetRefsListOwnPage );
  97. #define SET_VALUE( ctrl, units, value ) \
  98. ctrl->SetValue( EDA_UNIT_UTILS::UI::StringFromValue( unityScale, units, value ) )
  99. SET_VALUE( m_textOffsetRatioCtrl, EDA_UNITS::PERCENT, settings.m_TextOffsetRatio * 100.0 );
  100. SET_VALUE( m_overbarHeightCtrl, EDA_UNITS::PERCENT,
  101. settings.m_FontMetrics.m_OverbarHeight * 100.0 );
  102. SET_VALUE( m_dashLengthCtrl, EDA_UNITS::UNSCALED, settings.m_DashedLineDashRatio );
  103. SET_VALUE( m_gapLengthCtrl, EDA_UNITS::UNSCALED, settings.m_DashedLineGapRatio );
  104. SET_VALUE( m_labelSizeRatioCtrl, EDA_UNITS::PERCENT, settings.m_LabelSizeRatio * 100.0 );
  105. #undef SET_VALUE
  106. m_vPrecisionCtrl->SetValue( settings.m_OPO_VPrecision );
  107. m_vRangeCtrl->SetStringSelection( settings.m_OPO_VRange );
  108. m_iPrecisionCtrl->SetValue( settings.m_OPO_IPrecision );
  109. m_iRangeCtrl->SetStringSelection( settings.m_OPO_IRange );
  110. return true;
  111. }
  112. bool PANEL_SETUP_FORMATTING::TransferDataFromWindow()
  113. {
  114. if( !m_connectionGridSize.Validate( MIN_CONNECTION_GRID_MILS, 10000, EDA_UNITS::MILS ) )
  115. return false;
  116. SCHEMATIC_SETTINGS& settings = m_frame->Schematic().Settings();
  117. // Reference style one of: "A" ".A" "-A" "_A" ".1" "-1" "_1"
  118. switch( m_choiceSeparatorRefId->GetSelection() )
  119. {
  120. default:
  121. case 0: settings.m_SubpartFirstId = 'A'; settings.m_SubpartIdSeparator = 0; break;
  122. case 1: settings.m_SubpartFirstId = 'A'; settings.m_SubpartIdSeparator = '.'; break;
  123. case 2: settings.m_SubpartFirstId = 'A'; settings.m_SubpartIdSeparator = '-'; break;
  124. case 3: settings.m_SubpartFirstId = 'A'; settings.m_SubpartIdSeparator = '_'; break;
  125. case 4: settings.m_SubpartFirstId = '1'; settings.m_SubpartIdSeparator = '.'; break;
  126. case 5: settings.m_SubpartFirstId = '1'; settings.m_SubpartIdSeparator = '-'; break;
  127. case 6: settings.m_SubpartFirstId = '1'; settings.m_SubpartIdSeparator = '_'; break;
  128. }
  129. settings.m_DefaultTextSize = m_textSize.GetIntValue();
  130. settings.m_DefaultLineWidth = m_lineWidth.GetIntValue();
  131. settings.m_PinSymbolSize = m_pinSymbolSize.GetIntValue();
  132. settings.m_ConnectionGridSize = m_connectionGridSize.GetIntValue();
  133. if( m_choiceJunctionDotSize->GetSelection() != wxNOT_FOUND )
  134. settings.m_JunctionSizeChoice = m_choiceJunctionDotSize->GetSelection();
  135. settings.m_IntersheetRefsShow = m_showIntersheetsReferences->GetValue();
  136. settings.m_IntersheetRefsFormatShort = !m_radioFormatStandard->GetValue();
  137. settings.m_IntersheetRefsPrefix = m_prefixCtrl->GetValue();
  138. settings.m_IntersheetRefsSuffix = m_suffixCtrl->GetValue();
  139. settings.m_IntersheetRefsListOwnPage = m_listOwnPage->GetValue();
  140. #define GET_VALUE( units, str ) EDA_UNIT_UTILS::UI::DoubleValueFromString( unityScale, units, str )
  141. settings.m_TextOffsetRatio = GET_VALUE( EDA_UNITS::PERCENT,
  142. m_textOffsetRatioCtrl->GetValue() ) / 100.0;
  143. settings.m_FontMetrics.m_OverbarHeight = GET_VALUE( EDA_UNITS::PERCENT,
  144. m_overbarHeightCtrl->GetValue() ) / 100.0;
  145. settings.m_DashedLineDashRatio = GET_VALUE( EDA_UNITS::UNSCALED, m_dashLengthCtrl->GetValue() );
  146. settings.m_DashedLineGapRatio = GET_VALUE( EDA_UNITS::UNSCALED, m_gapLengthCtrl->GetValue() );
  147. settings.m_LabelSizeRatio = GET_VALUE( EDA_UNITS::PERCENT,
  148. m_labelSizeRatioCtrl->GetValue() ) / 100.0;
  149. #undef GET_VALUE
  150. settings.m_OPO_VPrecision = m_vPrecisionCtrl->GetValue();
  151. if( m_vRangeCtrl->GetSelection() == 0 )
  152. settings.m_OPO_VRange = wxS( "~V" );
  153. else
  154. settings.m_OPO_VRange = m_vRangeCtrl->GetStringSelection();
  155. settings.m_OPO_IPrecision = m_iPrecisionCtrl->GetValue();
  156. if( m_iRangeCtrl->GetSelection() == 0 )
  157. settings.m_OPO_IRange = wxS( "~A" );
  158. else
  159. settings.m_OPO_IRange = m_iRangeCtrl->GetStringSelection();
  160. return true;
  161. }
  162. void PANEL_SETUP_FORMATTING::ImportSettingsFrom( SCHEMATIC_SETTINGS& aSettings )
  163. {
  164. m_choiceSeparatorRefId->SetSelection( getRefStyleMenuIndex( aSettings.m_SubpartIdSeparator,
  165. aSettings.m_SubpartFirstId ) );
  166. m_textSize.SetValue( aSettings.m_DefaultTextSize );
  167. m_lineWidth.SetValue( aSettings.m_DefaultLineWidth );
  168. m_pinSymbolSize.SetValue( aSettings.m_PinSymbolSize );
  169. m_connectionGridSize.SetValue( aSettings.m_ConnectionGridSize );
  170. m_showIntersheetsReferences->SetValue( aSettings.m_IntersheetRefsShow );
  171. m_radioFormatStandard->SetValue( aSettings.m_IntersheetRefsFormatShort );
  172. m_radioFormatAbbreviated->SetValue( !aSettings.m_IntersheetRefsFormatShort );
  173. m_prefixCtrl->ChangeValue( aSettings.m_IntersheetRefsPrefix );
  174. m_suffixCtrl->ChangeValue( aSettings.m_IntersheetRefsSuffix );
  175. m_listOwnPage->SetValue( aSettings.m_IntersheetRefsListOwnPage );
  176. #define SET_VALUE( ctrl, units, value ) \
  177. ctrl->SetValue( EDA_UNIT_UTILS::UI::StringFromValue( unityScale, units, value ) )
  178. SET_VALUE( m_textOffsetRatioCtrl, EDA_UNITS::PERCENT, aSettings.m_TextOffsetRatio * 100.0 );
  179. SET_VALUE( m_dashLengthCtrl, EDA_UNITS::UNSCALED, aSettings.m_DashedLineDashRatio );
  180. SET_VALUE( m_gapLengthCtrl, EDA_UNITS::UNSCALED, aSettings.m_DashedLineGapRatio );
  181. SET_VALUE( m_labelSizeRatioCtrl, EDA_UNITS::PERCENT, aSettings.m_LabelSizeRatio * 100.0 );
  182. #undef SET_VALUE
  183. }