KiCad PCB EDA Suite
dialog_signal_list.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) 2016 CERN
5  * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Maciej Suminski <maciej.suminski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 3
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * https://www.gnu.org/licenses/gpl-3.0.html
22  * or you may search the http://www.gnu.org website for the version 3 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #include "dialog_signal_list.h"
28 #include <kicad_string.h>
29 #include <sim/sim_plot_frame.h>
30 
32 
33 
35  NETLIST_EXPORTER_PSPICE_SIM* aExporter ) :
36  DIALOG_SIGNAL_LIST_BASE( aParent ),
37  m_plotFrame( aParent ),
38  m_exporter( aExporter )
39 {
40 
41 }
42 
43 
45 {
46  if( !DIALOG_SIGNAL_LIST_BASE::TransferDataFromWindow() )
47  return false;
48 
50 
51  return true;
52 }
53 
54 
56 {
57  // Create a list of possible signals
59  if( m_exporter )
60  {
61  // Voltage list
62  for( const auto& net : m_exporter->GetNetIndexMap() )
63  {
64  // netnames are escaped (can contain "{slash}" for '/') Unscape them:
65  wxString netname = UnescapeString( net.first );
66 
67  if( netname != "GND" && netname != "0" )
68  m_signals->Append( wxString::Format( "V(%s)", netname ) );
69  }
70 
71  auto simType = m_exporter->GetSimType();
72 
73  if( simType == ST_TRANSIENT || simType == ST_DC )
74  {
75  for( const auto& item : m_exporter->GetSpiceItems() )
76  {
77  // Add all possible currents for the primitive
78  for( const auto& current :
80  {
81  m_signals->Append( wxString::Format( "%s(%s)", current, item.m_refName ) );
82  }
83  }
84  }
85  }
86 
87  bool success = DIALOG_SIGNAL_LIST_BASE::TransferDataToWindow();
88 
89  // Now all widgets have the size fixed, call FinishDialogSettings
91 
92  return success;
93 }
94 
95 
96 bool DIALOG_SIGNAL_LIST::addSignalToPlotFrame( const wxString& aPlotName )
97 {
98 
99  // Get the part in the parentheses
100  wxString name = aPlotName.AfterFirst( '(' ).BeforeLast( ')' );
101 
102  if( !name.IsEmpty() )
103  {
104  wxUniChar firstChar = aPlotName[0];
105 
106  if( firstChar == 'V' || firstChar == 'v' )
107  {
109  }
110  else if( firstChar == 'I' || firstChar == 'i' )
111  {
112  m_plotFrame->AddCurrentPlot( name, aPlotName.BeforeFirst( '(' ) );
113  }
114  else
115  {
116  return false;
117  }
118  }
119  else
120  {
121  return false;
122  }
123 
124  return true;
125 }
126 
127 
129 {
130  for( unsigned int i = 0; i < m_signals->GetCount(); ++i )
131  {
132  if( m_signals->IsSelected( i ) )
133  {
134  const wxString& plotName = m_signals->GetString( i );
135 
136  if( !addSignalToPlotFrame( plotName ) )
137  wxASSERT_MSG( false, "Unhandled plot type" );
138  }
139  }
140 
141  // Add manually entered signal, if any
142  const wxString& plotName = m_signalEntry->GetValue();
143 
144  if( !plotName.IsEmpty() )
145  {
146  if( !addSignalToPlotFrame( plotName ) )
147  m_plotFrame->AddVoltagePlot( plotName ); // Assume it's a V plot by default
148 
149  m_signalEntry->SetSelection( -1, -1 );
150  }
151 }
NETLIST_EXPORTER_PSPICE_SIM * m_exporter
const SPICE_ITEM_LIST & GetSpiceItems() const
Return list of items representing schematic components in the Spice world.
bool addSignalToPlotFrame(const wxString &aPlotName)
Class DIALOG_SIGNAL_LIST_BASE.
void AddVoltagePlot(const wxString &aNetName)
Add a voltage plot for a given net name.
void AddCurrentPlot(const wxString &aDeviceName, const wxString &aParam)
Add a current plot for a particular device.
DIALOG_SIGNAL_LIST(SIM_PLOT_FRAME *aParent, NETLIST_EXPORTER_PSPICE_SIM *aExporter)
static const std::vector< wxString > & GetCurrents(SPICE_PRIMITIVE aPrimitive)
Return a list of currents that can be probed in a Spice primitive.
const NET_INDEX_MAP & GetNetIndexMap() const
Return a map of circuit nodes to net names.
Subclass of SIM_PLOT_FRAME_BASE, which is generated by wxFormBuilder.
bool TransferDataFromWindow() override
Implementing SIM_PLOT_FRAME_BASE.
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
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
const char * name
Definition: DXF_plotter.cpp:59
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:222
SIM_PLOT_FRAME * m_plotFrame
bool TransferDataToWindow() override
SIM_TYPE GetSimType()
Return simulation type basing on the simulation command directives.
Special netlist exporter flavor that allows one to override simulation commands.