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( "%f", settings.m_TextOffsetRatio * 100.0 );
98  m_textOffsetRatioCtrl->SetValue( offsetRatio );
99 
100  wxString labelSizeRatio = wxString::Format( "%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 
140 
141  settings.m_IntersheetRefsShow = m_showIntersheetsReferences->GetValue();
142  settings.m_IntersheetRefsFormatShort = !m_radioFormatStandard->GetValue();
143  settings.m_IntersheetRefsPrefix = m_prefixCtrl->GetValue();
144  settings.m_IntersheetRefsSuffix = m_suffixCtrl->GetValue();
145  settings.m_IntersheetRefsListOwnPage = m_listOwnPage->GetValue();
146 
147  double dtmp = DEFAULT_TEXT_OFFSET_RATIO;
148  m_textOffsetRatioCtrl->GetValue().ToDouble( &dtmp );
149  settings.m_TextOffsetRatio = dtmp / 100.0;
150 
152  m_labelSizeRatioCtrl->GetValue().ToDouble( &dtmp );
153  settings.m_LabelSizeRatio = dtmp / 100.0;
154 
160 
163  m_frame->GetCanvas()->Refresh();
164 
165  return true;
166 }
167 
168 
170 {
174 
175  m_showIntersheetsReferences->SetValue( aSettings.m_IntersheetRefsShow );
176  m_radioFormatStandard->SetValue( aSettings.m_IntersheetRefsFormatShort );
178  m_prefixCtrl->ChangeValue( aSettings.m_IntersheetRefsPrefix );
179  m_suffixCtrl->ChangeValue( aSettings.m_IntersheetRefsSuffix );
180  m_listOwnPage->SetValue( aSettings.m_IntersheetRefsListOwnPage );
181 
182  wxString offsetRatio = wxString::Format( "%f", aSettings.m_TextOffsetRatio * 100.0 );
183  m_textOffsetRatioCtrl->SetValue( offsetRatio );
184 
185  wxString labelSizeRatio = wxString::Format( "%f", aSettings.m_LabelSizeRatio * 100.0 );
186  m_labelSizeRatioCtrl->SetValue( labelSizeRatio );
187 }
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
#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
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition: view.cpp:1430
int GetSchematicJunctionSize()
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
Schematic editor (Eeschema) main window.
Class PANEL_SETUP_FORMATTING_BASE.
static int GetSubpartFirstId()
Definition: lib_symbol.h:520
Item needs to be redrawn.
Definition: view_item.h:57
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
SCHEMATIC & Schematic() const
void onCheckBoxIref(wxCommandEvent &event) override
static int GetSubpartIdSeparator()
Definition: lib_symbol.h:514
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
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
These settings were stored in SCH_BASE_FRAME previously.
virtual long long int GetValue()
Return the current value in Internal Units.
void ImportSettingsFrom(SCHEMATIC_SETTINGS &aSettings)
void SetDefaultPenWidth(int aWidth)
static void SetSubpartIdNotation(int aSep, int aFirstId)
Set the separator char between the subpart id and the reference 0 (no separator) or '.
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:633
#define DEFAULT_TEXT_OFFSET_RATIO
Ratio of the font height to space around global labels.