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 ),
38  m_lineWidth( aFrame, m_lineWidthLabel, m_lineWidthCtrl, m_lineWidthUnits ),
39  m_pinSymbolSize( aFrame, m_pinSymbolSizeLabel, m_pinSymbolSizeCtrl, m_pinSymbolSizeUnits )
40 {
41 }
42 
43 void PANEL_SETUP_FORMATTING::onCheckBoxIref( wxCommandEvent& event )
44 {
45  bool enabled = m_showIntersheetsReferences->GetValue();
46 
47  m_radioFormatStandard->Enable( enabled );
48  m_radioFormatAbbreviated->Enable( enabled );
49  m_prefixCtrl->Enable( enabled );
50  m_suffixCtrl->Enable( enabled );
51  m_listOwnPage->Enable( enabled );
52 }
53 
54 
56 {
58 
59  // Reference style one of: "A" ".A" "-A" "_A" ".1" "-1" "_1"
60  int refStyleSelection;
61 
63  {
64  default:
65  case 0: refStyleSelection = 0; break;
66  case '.': refStyleSelection = LIB_SYMBOL::GetSubpartFirstId() == '1' ? 4 : 1; break;
67  case '-': refStyleSelection = LIB_SYMBOL::GetSubpartFirstId() == '1' ? 5 : 2; break;
68  case '_': refStyleSelection = LIB_SYMBOL::GetSubpartFirstId() == '1' ? 6 : 3; break;
69  }
70 
71  m_choiceSeparatorRefId->SetSelection( refStyleSelection );
72 
76 
80  m_choiceJunctionDotSize->SetSelection( settings.m_JunctionSizeChoice );
81 
83 
84  m_radioFormatStandard->Enable( settings.m_IntersheetRefsShow );
86  m_prefixCtrl->Enable( settings.m_IntersheetRefsShow );
87  m_suffixCtrl->Enable( settings.m_IntersheetRefsShow );
88  m_listOwnPage->Enable( settings.m_IntersheetRefsShow );
89 
92  m_prefixCtrl->ChangeValue( settings.m_IntersheetRefsPrefix );
93  m_suffixCtrl->ChangeValue( settings.m_IntersheetRefsSuffix );
94  m_listOwnPage->SetValue( settings.m_IntersheetRefsListOwnPage );
95 
96  wxString offsetRatio = wxString::Format( "%f", settings.m_TextOffsetRatio * 100.0 );
97  m_textOffsetRatioCtrl->SetValue( offsetRatio );
98 
99  return true;
100 }
101 
102 
104 {
105  SCHEMATIC_SETTINGS& settings = m_frame->Schematic().Settings();
106 
107  // Reference style one of: "A" ".A" "-A" "_A" ".1" "-1" "_1"
108  int firstRefId, refSeparator;
109 
110  switch( m_choiceSeparatorRefId->GetSelection() )
111  {
112  default:
113  case 0: firstRefId = 'A'; refSeparator = 0; break;
114  case 1: firstRefId = 'A'; refSeparator = '.'; break;
115  case 2: firstRefId = 'A'; refSeparator = '-'; break;
116  case 3: firstRefId = 'A'; refSeparator = '_'; break;
117  case 4: firstRefId = '1'; refSeparator = '.'; break;
118  case 5: firstRefId = '1'; refSeparator = '-'; break;
119  case 6: firstRefId = '1'; refSeparator = '_'; break;
120  }
121 
122  if( refSeparator != LIB_SYMBOL::GetSubpartIdSeparator() ||
123  firstRefId != LIB_SYMBOL::GetSubpartFirstId() )
124  {
125  LIB_SYMBOL::SetSubpartIdNotation( refSeparator, firstRefId );
126  }
127 
128  settings.m_DefaultTextSize = (int) m_textSize.GetValue();
129  settings.m_DefaultLineWidth = (int) m_lineWidth.GetValue();
130  settings.m_PinSymbolSize = (int) m_pinSymbolSize.GetValue();
131 
132  // Get the current working size in case of problem with wxChoice widget results
133  int currJunctionDotSize = settings.m_JunctionSize;
134  // See if user has made a junction dot size selection
135  int currDotSizeIndex = m_choiceJunctionDotSize->GetSelection();
136 
137  if( currDotSizeIndex != wxNOT_FOUND )
138  {
139  EESCHEMA_SETTINGS* projSettings =
140  dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
141 
142  wxCHECK( projSettings, false );
143 
144  if( currDotSizeIndex )
145  {
146  // Junction dots are scaled value of default line width
147  currJunctionDotSize =
148  settings.m_DefaultLineWidth
149  * projSettings->m_Drawing.junction_size_mult_list[currDotSizeIndex];
150  }
151  else
152  {
153  // Don't set to zero or else it's set to min of 10 mils in "sch_painter.cpp"
154  currJunctionDotSize = 1;
155  }
156 
157  settings.m_JunctionSizeChoice = currDotSizeIndex; // Store to set pulldown next time
158  }
159 
160  settings.m_JunctionSize = currJunctionDotSize;
161 
162  settings.m_IntersheetRefsShow = m_showIntersheetsReferences->GetValue();
163  settings.m_IntersheetRefsFormatShort = !m_radioFormatStandard->GetValue();
164  settings.m_IntersheetRefsPrefix = m_prefixCtrl->GetValue();
165  settings.m_IntersheetRefsSuffix = m_suffixCtrl->GetValue();
166  settings.m_IntersheetRefsListOwnPage = m_listOwnPage->GetValue();
167 
168  double dtmp = 0.0;
169  wxString msg = m_textOffsetRatioCtrl->GetValue();
170  msg.ToDouble( &dtmp );
171  settings.m_TextOffsetRatio = dtmp / 100.0;
172 
177 
180  m_frame->GetCanvas()->Refresh();
181 
182  return true;
183 }
184 
185 
187 {
191 
192  m_showIntersheetsReferences->SetValue( aSettings.m_IntersheetRefsShow );
193  m_radioFormatStandard->SetValue( aSettings.m_IntersheetRefsFormatShort );
195  m_prefixCtrl->ChangeValue( aSettings.m_IntersheetRefsPrefix );
196  m_suffixCtrl->ChangeValue( aSettings.m_IntersheetRefsSuffix );
197  m_listOwnPage->SetValue( aSettings.m_IntersheetRefsListOwnPage );
198 
199  wxString offsetRatio = wxString::Format( "%f", aSettings.m_TextOffsetRatio * 100.0 );
200  m_textOffsetRatioCtrl->SetValue( offsetRatio );
201 }
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:129
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition: view.cpp:1416
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.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
SCHEMATIC & Schematic() const
void onCheckBoxIref(wxCommandEvent &event) override
static int GetSubpartIdSeparator()
Definition: lib_symbol.h:514
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
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)
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:599