KiCad PCB EDA Suite
panel_setup_formatting.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020 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 
24 #include <sch_edit_frame.h>
25 #include <sch_painter.h>
26 #include <kiface_base.h>
27 #include <panel_setup_formatting.h>
28 #include <sch_junction.h>
29 #include <schematic.h>
30 #include <schematic_settings.h>
31 #include <project/project_file.h>
32 #include <project/net_settings.h>
33 
34 
36  PANEL_SETUP_FORMATTING_BASE( aWindow ),
37  m_frame( aFrame ),
38  m_textSize( aFrame, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits ),
39  m_lineWidth( aFrame, m_lineWidthLabel, m_lineWidthCtrl, m_lineWidthUnits ),
40  m_pinSymbolSize( aFrame, m_pinSymbolSizeLabel, m_pinSymbolSizeCtrl, m_pinSymbolSizeUnits )
41 {
42 }
43 
44 void PANEL_SETUP_FORMATTING::onCheckBoxIref( wxCommandEvent& event )
45 {
46  bool enabled = m_showIntersheetsReferences->GetValue();
47 
48  m_radioFormatStandard->Enable( enabled );
49  m_radioFormatAbbreviated->Enable( enabled );
50  m_prefixCtrl->Enable( enabled );
51  m_suffixCtrl->Enable( enabled );
52  m_listOwnPage->Enable( enabled );
53 }
54 
55 
57 {
59 
60  // Reference style one of: "A" ".A" "-A" "_A" ".1" "-1" "_1"
61  int refStyleSelection;
62 
64  {
65  default:
66  case 0: refStyleSelection = 0; break;
67  case '.': refStyleSelection = LIB_SYMBOL::GetSubpartFirstId() == '1' ? 4 : 1; break;
68  case '-': refStyleSelection = LIB_SYMBOL::GetSubpartFirstId() == '1' ? 5 : 2; break;
69  case '_': refStyleSelection = LIB_SYMBOL::GetSubpartFirstId() == '1' ? 6 : 3; break;
70  }
71 
72  m_choiceSeparatorRefId->SetSelection( refStyleSelection );
73 
77 
81  m_choiceJunctionDotSize->SetSelection( settings.m_JunctionSizeChoice );
82 
84 
85  m_radioFormatStandard->Enable( settings.m_IntersheetRefsShow );
87  m_prefixCtrl->Enable( settings.m_IntersheetRefsShow );
88  m_suffixCtrl->Enable( settings.m_IntersheetRefsShow );
89  m_listOwnPage->Enable( settings.m_IntersheetRefsShow );
90 
93  m_prefixCtrl->ChangeValue( settings.m_IntersheetRefsPrefix );
94  m_suffixCtrl->ChangeValue( settings.m_IntersheetRefsSuffix );
95  m_listOwnPage->SetValue( settings.m_IntersheetRefsListOwnPage );
96 
97  wxString offsetRatio = wxString::Format( wxT( "%f" ), settings.m_TextOffsetRatio * 100.0 );
98  m_textOffsetRatioCtrl->SetValue( offsetRatio );
99 
100  wxString labelSizeRatio = wxString::Format( wxT( "%f" ), settings.m_LabelSizeRatio * 100.0 );
101  m_labelSizeRatioCtrl->SetValue( labelSizeRatio );
102 
103  return true;
104 }
105 
106 
108 {
109  SCHEMATIC_SETTINGS& settings = m_frame->Schematic().Settings();
110 
111  // Reference style one of: "A" ".A" "-A" "_A" ".1" "-1" "_1"
112  int firstRefId, refSeparator;
113 
114  switch( m_choiceSeparatorRefId->GetSelection() )
115  {
116  default:
117  case 0: firstRefId = 'A'; refSeparator = 0; break;
118  case 1: firstRefId = 'A'; refSeparator = '.'; break;
119  case 2: firstRefId = 'A'; refSeparator = '-'; break;
120  case 3: firstRefId = 'A'; refSeparator = '_'; break;
121  case 4: firstRefId = '1'; refSeparator = '.'; break;
122  case 5: firstRefId = '1'; refSeparator = '-'; break;
123  case 6: firstRefId = '1'; refSeparator = '_'; break;
124  }
125 
126  if( refSeparator != LIB_SYMBOL::GetSubpartIdSeparator() ||
127  firstRefId != LIB_SYMBOL::GetSubpartFirstId() )
128  {
129  LIB_SYMBOL::SetSubpartIdNotation( refSeparator, firstRefId );
130  }
131 
132  settings.m_DefaultTextSize = (int) m_textSize.GetValue();
133  settings.m_DefaultLineWidth = (int) m_lineWidth.GetValue();
134  settings.m_PinSymbolSize = (int) m_pinSymbolSize.GetValue();
135 
136  if( m_choiceJunctionDotSize->GetSelection() != wxNOT_FOUND )
137  settings.m_JunctionSizeChoice = m_choiceJunctionDotSize->GetSelection();
138 
139  settings.m_IntersheetRefsShow = m_showIntersheetsReferences->GetValue();
140  settings.m_IntersheetRefsFormatShort = !m_radioFormatStandard->GetValue();
141  settings.m_IntersheetRefsPrefix = m_prefixCtrl->GetValue();
142  settings.m_IntersheetRefsSuffix = m_suffixCtrl->GetValue();
143  settings.m_IntersheetRefsListOwnPage = m_listOwnPage->GetValue();
144 
145  double dtmp = DEFAULT_TEXT_OFFSET_RATIO;
146  m_textOffsetRatioCtrl->GetValue().ToDouble( &dtmp );
147  settings.m_TextOffsetRatio = dtmp / 100.0;
148 
150  m_labelSizeRatioCtrl->GetValue().ToDouble( &dtmp );
151  settings.m_LabelSizeRatio = dtmp / 100.0;
152 
153  return true;
154 }
155 
156 
158 {
162 
163  m_showIntersheetsReferences->SetValue( aSettings.m_IntersheetRefsShow );
164  m_radioFormatStandard->SetValue( aSettings.m_IntersheetRefsFormatShort );
166  m_prefixCtrl->ChangeValue( aSettings.m_IntersheetRefsPrefix );
167  m_suffixCtrl->ChangeValue( aSettings.m_IntersheetRefsSuffix );
168  m_listOwnPage->SetValue( aSettings.m_IntersheetRefsListOwnPage );
169 
170  wxString offsetRatio = wxString::Format( wxT( "%f" ), aSettings.m_TextOffsetRatio * 100.0 );
171  m_textOffsetRatioCtrl->SetValue( offsetRatio );
172 
173  wxString labelSizeRatio = wxString::Format( wxT( "%f" ), aSettings.m_LabelSizeRatio * 100.0 );
174  m_labelSizeRatioCtrl->SetValue( labelSizeRatio );
175 }
#define DEFAULT_LABEL_SIZE_RATIO
The offset of the pin name string from the end of the pin in mils.
PANEL_SETUP_FORMATTING(wxWindow *aWindow, SCH_EDIT_FRAME *aFrame)
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:167
Schematic editor (Eeschema) main window.
Class PANEL_SETUP_FORMATTING_BASE.
static int GetSubpartFirstId()
Definition: lib_symbol.h:531
SCHEMATIC & Schematic() const
void onCheckBoxIref(wxCommandEvent &event) override
static int GetSubpartIdSeparator()
Definition: lib_symbol.h:525
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
virtual void SetUnits(EDA_UNITS aUnits)
Normally not needed (as the UNIT_BINDER inherits from the parent frame), but can be used to set to DE...
Definition: unit_binder.cpp:92
These settings were stored in SCH_BASE_FRAME previously.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
virtual long long int GetValue()
Return the current value in Internal Units.
void ImportSettingsFrom(SCHEMATIC_SETTINGS &aSettings)
static void SetSubpartIdNotation(int aSep, int aFirstId)
Set the separator char between the subpart id and the reference 0 (no separator) or '.
#define DEFAULT_TEXT_OFFSET_RATIO
Ratio of the font height to space around global labels.