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 <eeschema_settings.h>
27 #include <kiface_i.h>
28 #include <panel_setup_formatting.h>
29 #include <sch_junction.h>
30 #include <schematic.h>
31 #include <schematic_settings.h>
32 
33 
35  PANEL_SETUP_FORMATTING_BASE( aWindow ),
36  m_frame( aFrame ),
37  m_textSize( aFrame, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true ),
38  m_lineWidth( aFrame, m_lineWidthLabel, m_lineWidthCtrl, m_lineWidthUnits, true ),
39  m_pinSymbolSize( aFrame, m_pinSymbolSizeLabel, m_pinSymbolSizeCtrl, m_pinSymbolSizeUnits,
40  true )
41 {
42 }
43 
44 
46 {
48 
49  // Reference style one of: "A" ".A" "-A" "_A" ".1" "-1" "_1"
50  int refStyleSelection;
51 
53  {
54  default:
55  case 0: refStyleSelection = 0; break;
56  case '.': refStyleSelection = LIB_PART::GetSubpartFirstId() == '1' ? 4 : 1; break;
57  case '-': refStyleSelection = LIB_PART::GetSubpartFirstId() == '1' ? 5 : 2; break;
58  case '_': refStyleSelection = LIB_PART::GetSubpartFirstId() == '1' ? 6 : 3; break;
59  }
60 
61  m_choiceSeparatorRefId->SetSelection( refStyleSelection );
62 
66 
70  m_choiceJunctionDotSize->SetSelection( settings.m_JunctionSizeChoice );
71 
75  m_prefixCtrl->ChangeValue( settings.m_IntersheetRefsPrefix );
76  m_suffixCtrl->ChangeValue( settings.m_IntersheetRefsSuffix );
77 
78  wxString offsetRatio = wxString::Format( "%f", settings.m_TextOffsetRatio * 100.0 );
79  m_textOffsetRatioCtrl->SetValue( offsetRatio );
80 
81  return true;
82 }
83 
84 
86 {
88 
89  // Reference style one of: "A" ".A" "-A" "_A" ".1" "-1" "_1"
90  int firstRefId, refSeparator;
91 
92  switch( m_choiceSeparatorRefId->GetSelection() )
93  {
94  default:
95  case 0: firstRefId = 'A'; refSeparator = 0; break;
96  case 1: firstRefId = 'A'; refSeparator = '.'; break;
97  case 2: firstRefId = 'A'; refSeparator = '-'; break;
98  case 3: firstRefId = 'A'; refSeparator = '_'; break;
99  case 4: firstRefId = '1'; refSeparator = '.'; break;
100  case 5: firstRefId = '1'; refSeparator = '-'; break;
101  case 6: firstRefId = '1'; refSeparator = '_'; break;
102  }
103 
104  if( refSeparator != LIB_PART::GetSubpartIdSeparator() ||
105  firstRefId != LIB_PART::GetSubpartFirstId() )
106  {
107  LIB_PART::SetSubpartIdNotation( refSeparator, firstRefId );
108  }
109 
110  settings.m_DefaultTextSize = (int) m_textSize.GetValue();
111  settings.m_DefaultLineWidth = (int) m_lineWidth.GetValue();
112  settings.m_PinSymbolSize = (int) m_pinSymbolSize.GetValue();
113 
114  // Get the current working size in case of problem with wxChoice widget results
115  int currJunctionDotSize = settings.m_JunctionSize;
116  // See if user has made a junction dot size selection
117  int currDotSizeIndex = m_choiceJunctionDotSize->GetSelection();
118 
119  if( currDotSizeIndex != wxNOT_FOUND )
120  {
121  EESCHEMA_SETTINGS* projSettings =
122  dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
123 
124  wxCHECK( projSettings, false );
125 
126  if( currDotSizeIndex )
127  {
128  // Junction dots are scaled value of default line width
129  currJunctionDotSize =
130  settings.m_DefaultLineWidth
131  * projSettings->m_Drawing.junction_size_mult_list[currDotSizeIndex];
132  }
133  else
134  {
135  // Don't set to zero or else it's set to min of 10 mils in "sch_painter.cpp"
136  currJunctionDotSize = 1;
137  }
138 
139  settings.m_JunctionSizeChoice = currDotSizeIndex; // Store to set pulldown next time
140  }
141 
142  settings.m_JunctionSize = currJunctionDotSize;
143 
144  settings.m_IntersheetRefsShow = m_showIntersheetsReferences->GetValue();
145  settings.m_IntersheetRefsFormatShort = !m_radioFormatStandard->GetValue();
146  settings.m_IntersheetRefsPrefix = m_prefixCtrl->GetValue();
147  settings.m_IntersheetRefsSuffix = m_suffixCtrl->GetValue();
148 
149  double dtmp = 0.0;
150  wxString msg = m_textOffsetRatioCtrl->GetValue();
151  msg.ToDouble( &dtmp );
152  settings.m_TextOffsetRatio = dtmp / 100.0;
153 
158 
161  m_frame->GetCanvas()->Refresh();
162 
163  return true;
164 }
165 
166 
168 {
172 
173  m_showIntersheetsReferences->SetValue( aSettings.m_IntersheetRefsShow );
174  m_radioFormatStandard->SetValue( aSettings.m_IntersheetRefsFormatShort );
176  m_prefixCtrl->ChangeValue( aSettings.m_IntersheetRefsPrefix );
177  m_suffixCtrl->ChangeValue( aSettings.m_IntersheetRefsSuffix );
178 
179  wxString offsetRatio = wxString::Format( "%f", aSettings.m_TextOffsetRatio * 100.0 );
180  m_textOffsetRatioCtrl->SetValue( offsetRatio );
181 }
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
PANEL_SETUP_FORMATTING(wxWindow *aWindow, SCH_EDIT_FRAME *aFrame)
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:125
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition: view.cpp:1412
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
Schematic editor (Eeschema) main window.
bool TransferDataFromWindow() override
Class PANEL_SETUP_FORMATTING_BASE.
static int GetSubpartIdSeparator()
Definition: lib_symbol.h:508
Item needs to be redrawn.
Definition: view_item.h:57
static int GetSubpartFirstId()
Definition: lib_symbol.h:514
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
SCHEMATIC & Schematic() const
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
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:81
static void SetSubpartIdNotation(int aSep, int aFirstId)
Set the separator char between the subpart id and the reference 0 (no separator) or '.
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
These settings were stored in SCH_BASE_FRAME previously.
virtual long long int GetValue()
Return the current value in Internal Units.
std::vector< double > junction_size_mult_list
void ImportSettingsFrom(SCHEMATIC_SETTINGS &aSettings)
void SetDefaultPenWidth(int aWidth)
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:598