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  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * https://www.gnu.org/licenses/gpl-3.0.html
20  * or you may search the http://www.gnu.org website for the version 3 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include "dialog_signal_list.h"
26 #include <kicad_string.h>
27 #include <sim/sim_plot_frame.h>
28 
30 
32  : DIALOG_SIGNAL_LIST_BASE( aParent ), m_plotFrame( aParent ), m_exporter( aExporter )
33 {
34 
35 }
36 
37 
39 {
40  if( !DIALOG_SIGNAL_LIST_BASE::TransferDataFromWindow() )
41  return false;
42 
44 
45  return true;
46 }
47 
48 
50 {
51  // Create a list of possible signals
53  if( m_exporter )
54  {
55  // Voltage list
56  for( const auto& net : m_exporter->GetNetIndexMap() )
57  {
58  // netnames are escaped (can contain "{slash}" for '/') Unscape them:
59  wxString netname = UnescapeString( net.first );
60 
61  if( netname != "GND" && netname != "0" )
62  m_signals->Append( wxString::Format( "V(%s)", netname ) );
63  }
64 
65  auto simType = m_exporter->GetSimType();
66 
67  if( simType == ST_TRANSIENT || simType == ST_DC )
68  {
69  for( const auto& item : m_exporter->GetSpiceItems() )
70  {
71  // Add all possible currents for the primitive
72  for( const auto& current :
74  {
75  m_signals->Append( wxString::Format( "%s(%s)", current, item.m_refName ) );
76  }
77  }
78  }
79  }
80 
81  bool success = DIALOG_SIGNAL_LIST_BASE::TransferDataToWindow();
82 
83  // Now all widgets have the size fixed, call FinishDialogSettings
85 
86  return success;
87 }
88 
89 
90 bool DIALOG_SIGNAL_LIST::addSignalToPlotFrame( const wxString& aPlotName )
91 {
92 
93  // Get the part in the parentheses
94  wxString name = aPlotName.AfterFirst( '(' ).BeforeLast( ')' );
95 
96  if( !name.IsEmpty() )
97  {
98  wxUniChar firstChar = aPlotName[0];
99  if( firstChar == 'V' || firstChar == 'v' )
100  {
102  }
103  else if( firstChar == 'I' || firstChar == 'i' )
104  {
105  m_plotFrame->AddCurrentPlot( name, aPlotName.BeforeFirst( '(' ) );
106  }
107  else
108  {
109  return false;
110  }
111  }
112  else
113  {
114  return false;
115  }
116 
117  return true;
118 }
119 
120 
122 {
123  for( unsigned int i = 0; i < m_signals->GetCount(); ++i )
124  {
125  if( m_signals->IsSelected( i ) )
126  {
127  const wxString& plotName = m_signals->GetString( i );
128  if( !addSignalToPlotFrame( plotName ) )
129  wxASSERT_MSG( false, "Unhandled plot type" );
130  }
131  }
132 
133  // Add manually entered signal, if any
134  const wxString& plotName = m_signalEntry->GetValue();
135 
136  if( !plotName.IsEmpty() )
137  {
138  if( !addSignalToPlotFrame( plotName ) )
139  m_plotFrame->AddVoltagePlot( plotName ); // Assume it's a V plot by default
140 
141  m_signalEntry->SetSelection( -1, -1 );
142  }
143 }
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:150
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.