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 <sim/sim_plot_frame.h>
27 
29 
31  : DIALOG_SIGNAL_LIST_BASE( aParent ), m_plotFrame( aParent ), m_exporter( aExporter )
32 {
33 
34 }
35 
36 
38 {
39  if( !DIALOG_SIGNAL_LIST_BASE::TransferDataFromWindow() )
40  return false;
41 
43 
44  return true;
45 }
46 
47 
49 {
50  // Create a list of possible signals
52  if( m_exporter )
53  {
54  // Voltage list
55  for( const auto& net : m_exporter->GetNetIndexMap() )
56  {
57  // netnames are escaped (can contain "{slash}" for '/') Unscape them:
58  wxString netname = UnescapeString( net.first );
59 
60  if( netname != "GND" && netname != "0" )
61  m_signals->Append( wxString::Format( "V(%s)", netname ) );
62  }
63 
64  auto simType = m_exporter->GetSimType();
65 
66  if( simType == ST_TRANSIENT || simType == ST_DC )
67  {
68  for( const auto& item : m_exporter->GetSpiceItems() )
69  {
70  // Add all possible currents for the primitive
71  for( const auto& current :
73  {
74  m_signals->Append( wxString::Format( "%s(%s)", current, item.m_refName ) );
75  }
76  }
77  }
78  }
79 
80  bool success = DIALOG_SIGNAL_LIST_BASE::TransferDataToWindow();
81 
82  // Now all widgets have the size fixed, call FinishDialogSettings
84 
85  return success;
86 }
87 
88 
89 bool DIALOG_SIGNAL_LIST::addSignalToPlotFrame( const wxString& aPlotName )
90 {
91 
92  // Get the part in the parentheses
93  wxString name = aPlotName.AfterFirst( '(' ).BeforeLast( ')' );
94 
95  if( !name.IsEmpty() )
96  {
97  wxUniChar firstChar = aPlotName[0];
98  if( firstChar == 'V' || firstChar == 'v' )
99  {
101  }
102  else if( firstChar == 'I' || firstChar == 'i' )
103  {
104  m_plotFrame->AddCurrentPlot( name, aPlotName.BeforeFirst( '(' ) );
105  }
106  else
107  {
108  return false;
109  }
110  }
111  else
112  {
113  return false;
114  }
115 
116  return true;
117 }
118 
119 
121 {
122  for( unsigned int i = 0; i < m_signals->GetCount(); ++i )
123  {
124  if( m_signals->IsSelected( i ) )
125  {
126  const wxString& plotName = m_signals->GetString( i );
127  if( !addSignalToPlotFrame( plotName ) )
128  wxASSERT_MSG( false, "Unhandled plot type" );
129  }
130  }
131 
132  // Add manually entered signal, if any
133  const wxString& plotName = m_signalEntry->GetValue();
134 
135  if( !plotName.IsEmpty() )
136  {
137  if( !addSignalToPlotFrame( plotName ) )
138  m_plotFrame->AddVoltagePlot( plotName ); // Assume it's a V plot by default
139 
140  m_signalEntry->SetSelection( -1, -1 );
141  }
142 }
NETLIST_EXPORTER_PSPICE_SIM * m_exporter
const SPICE_ITEM_LIST & GetSpiceItems() const
Returns list of items representing schematic components in the Spice world.
bool addSignalToPlotFrame(const wxString &aPlotName)
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Class DIALOG_SIGNAL_LIST_BASE.
void AddVoltagePlot(const wxString &aNetName)
Adds a voltage plot for a given net name.
void AddCurrentPlot(const wxString &aDeviceName, const wxString &aParam)
Adds 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)
Returns a list of currents that can be probed in a Spice primitive.
const NET_INDEX_MAP & GetNetIndexMap() const
Returns 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.
const char * name
Definition: DXF_plotter.cpp:60
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
SPICE_PRIMITIVE
Basic Spice component primitives
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:152
SIM_PLOT_FRAME * m_plotFrame
bool TransferDataToWindow() override
SIM_TYPE GetSimType()
Returns simulation type basing on the simulation command directives.
Special netlist exporter flavor that allows one to override simulation commands.