46
46
import com.sun.electric.tool.Job;
47
47
import com.sun.electric.tool.io.FileType;
48
48
import com.sun.electric.tool.io.input.EpicAnalysis;
49
import com.sun.electric.tool.io.input.NewEpicAnalysis;
49
50
import com.sun.electric.tool.io.input.Simulate;
50
51
import com.sun.electric.tool.io.output.PNG;
51
52
import com.sun.electric.tool.io.output.Spice;
52
53
import com.sun.electric.tool.ncc.NccCrossProbing;
53
54
import com.sun.electric.tool.ncc.result.NccResult;
54
import com.sun.electric.tool.simulation.*;
55
import com.sun.electric.tool.simulation.AnalogAnalysis;
56
import com.sun.electric.tool.simulation.AnalogSignal;
57
import com.sun.electric.tool.simulation.Analysis;
58
import com.sun.electric.tool.simulation.DigitalSignal;
59
import com.sun.electric.tool.simulation.Signal;
60
import com.sun.electric.tool.simulation.Simulation;
61
import com.sun.electric.tool.simulation.Stimuli;
62
import com.sun.electric.tool.simulation.Waveform;
55
63
import com.sun.electric.tool.user.ActivityLogger;
56
64
import com.sun.electric.tool.user.HighlightListener;
57
65
import com.sun.electric.tool.user.Highlighter;
99
107
import java.awt.print.PrinterJob;
100
108
import java.beans.PropertyChangeEvent;
101
109
import java.beans.PropertyChangeListener;
102
import java.io.BufferedWriter;
103
import java.io.FileWriter;
104
import java.io.IOException;
105
import java.io.InputStreamReader;
106
import java.io.LineNumberReader;
107
import java.io.PrintWriter;
108
111
import java.net.URL;
109
112
import java.net.URLConnection;
110
113
import java.util.ArrayList;
201
207
/** Font for all text in the window */ private static Font waveWindowFont;
202
208
/** For rendering text */ private static FontRenderContext waveWindowFRC;
203
209
/** The colors of signal lines */ private static Color offStrengthColor, nodeStrengthColor, gateStrengthColor, powerStrengthColor;
210
/** The background color */ private static Color backgroundColor;
205
211
/** drop target (for drag and drop) */ public static WaveFormDropTarget waveformDropTarget = new WaveFormDropTarget();
207
213
private static final ImageIcon iconAddPanel = Resources.getResource(WaveformWindow.class, "ButtonSimAddPanel.gif");
933
940
mainHorizRulerPanel.repaint();
943
public static void exportSimulationDataAsCSV(String file)
945
if (file == null) // cancel operation for example
947
WindowFrame current = WindowFrame.getCurrentWindowFrame();
948
WindowContent content = current.getContent();
949
if (!(content instanceof WaveformWindow)) {
950
System.out.println("Must select a Waveform window first");
953
WaveformWindow ww = (WaveformWindow)content;
955
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file)));
956
for(Panel wp : ww.wavePanels)
959
System.out.println("Exported Waveform in CSV format file '" + file + "'");
960
} catch (Exception e) {
961
throw new RuntimeException(e);
965
public static void plotSimulationData(String file, String format) {
966
WindowFrame current = WindowFrame.getCurrentWindowFrame();
967
WindowContent content = current.getContent();
968
if (!(content instanceof WaveformWindow)) {
969
System.out.println("Must select a Waveform window first");
972
WaveformWindow ww = (WaveformWindow)content;
974
String commands = "";
975
double min = Double.MAX_VALUE;
976
double max = Double.MIN_VALUE;
978
for(Panel wp : ww.wavePanels) {
979
min = Math.min(min, wp.convertXScreenToData(0));
980
max = Math.max(max, wp.convertXScreenToData(wp.getSz().width));
981
sr = Math.min(sr, ((double)wp.getSz().height)/((double)wp.getSz().width));
984
commands += "set terminal "+format+"; ";
985
commands += "set output \""+file+"\"; ";
987
commands += "set size ratio "+sr+"; ";
988
commands += "set xrange [\""+min+"\":\""+max+"\"]; ";
989
commands += "plot \"-\" with lines; ";
990
System.out.println("Running: gnuplot -e \""+commands+"\"");
991
ExecProcess ep = new ExecProcess(new String[] { "gnuplot", "-e", commands }, null);
992
ep.redirectStdout(System.out);
993
ep.redirectStderr(System.out);
995
PrintWriter pw = new PrintWriter(new OutputStreamWriter(ep.getStdin()));
996
for(Panel wp : ww.wavePanels)
997
wp.dumpDataForGnuplot(pw);
999
} catch (Exception e) {
1000
System.out.println("ERROR: Unable to run 'gnuplot': " + e);
937
1005
* Method to initialize for a new text search.
938
1006
* @param search the string to locate.
1904
1974
redrawAllPanels();
1907
private void vcrClickFaster()
1977
public void vcrClickFaster()
1909
1979
int j = vcrAdvanceSpeed / 4;
1910
1980
if (j <= 0) j = 1;
1911
1981
vcrAdvanceSpeed += j;
1914
private void vcrClickSlower()
1984
public void vcrClickSlower()
1916
1986
int j = vcrAdvanceSpeed / 4;
1917
1987
if (j <= 0) j = 1;
2124
2194
DefaultMutableTreeNode analysisNode = ((EpicAnalysis)an).getSignalsForExplorer(analysis);
2125
2195
treePathFromAnalysis.put(an, parentPath.pathByAddingChild(analysisNode));
2126
2196
return analysisNode;
2197
} else if (an instanceof NewEpicAnalysis)
2199
DefaultMutableTreeNode analysisNode = ((NewEpicAnalysis)an).getSignalsForExplorer(analysis);
2200
treePathFromAnalysis.put(an, parentPath.pathByAddingChild(analysisNode));
2201
return analysisNode;
2128
2203
DefaultMutableTreeNode signalsExplorerTree = new DefaultMutableTreeNode(analysis);
2129
2204
TreePath analysisPath = parentPath.pathByAddingChild(signalsExplorerTree);
2130
2205
treePathFromAnalysis.put(an, analysisPath);
3441
3516
System.out.println("Simulation data reloaded from disk");
3519
public static WaveformWindow getCurrentWaveformWindow() {
3520
WindowFrame current = WindowFrame.getCurrentWindowFrame();
3521
WindowContent content = current.getContent();
3522
if (!(content instanceof WaveformWindow))
3524
System.out.println("Must select a Waveform window first");
3527
return (WaveformWindow)content;
3445
3531
* Method to write the simulation data as a tab-separated file.
4032
4120
if (!wp.isSelected()) continue;
4122
boolean removedSingleStimuli = false;
4034
4123
for(WaveSignal ws : wp.getSignals())
4036
4125
if (ws.getSelectedControlPoints() != null)
4038
4127
if (sd.getEngine() != null)
4039
sd.getEngine().removeSelectedStimuli();
4129
if (sd.getEngine().removeSelectedStimuli())
4130
removedSingleStimuli = true;
4042
if (wp.getAnalysisType() != null) deleteSignalFromPanel(wp); else
4044
// do not delete the panel: make them use the "X" button
4045
// saveSignalOrder();
4134
if (wp.getAnalysisType() != null && !removedSingleStimuli) deleteSignalFromPanel(wp);
4100
4187
for(Panel wp : wavePanels)
4102
4189
if (wp.getXAxisSignal() != null) continue;
4103
Analysis an = sd.findAnalysis(wp.getAnalysisType());
4104
if (leftEdge == rightEdge)
4106
leftEdge = an.getLeftEdge();
4107
rightEdge = an.getRightEdge();
4110
if (leftEdge < rightEdge)
4190
for(WaveSignal ws : wp.getSignals())
4192
Rectangle2D bounds = ws.getSignal().getBounds();
4193
if (leftEdge == rightEdge)
4112
leftEdge = Math.min(leftEdge, an.getLeftEdge());
4113
rightEdge = Math.max(rightEdge, an.getRightEdge());
4195
leftEdge = bounds.getMinX();
4196
rightEdge = bounds.getMaxX();
4116
leftEdge = Math.max(leftEdge, an.getLeftEdge());
4117
rightEdge = Math.min(rightEdge, an.getRightEdge());
4199
leftEdge = Math.min(leftEdge, bounds.getMinX());
4200
rightEdge = Math.max(rightEdge, bounds.getMaxX());
4203
// Analysis an = sd.findAnalysis(wp.getAnalysisType());
4204
// if (leftEdge == rightEdge)
4206
// leftEdge = an.getLeftEdge();
4207
// rightEdge = an.getRightEdge();
4210
// if (leftEdge < rightEdge)
4212
// leftEdge = Math.min(leftEdge, an.getLeftEdge());
4213
// rightEdge = Math.max(rightEdge, an.getRightEdge());
4216
// leftEdge = Math.max(leftEdge, an.getLeftEdge());
4217
// rightEdge = Math.min(rightEdge, an.getRightEdge());
4122
4222
// if there is an overriding signal on the X axis, use its bounds
4274
4374
// ************************************* DRAG AND DROP CLASSES *************************************
4277
* This class extends JPanel so that components of the Waveform window can be identified by the Drag and Drop system.
4377
* This class extends JPanel so that components of the Waveform window can be identified by the Drag and Drop system
4378
* and by the key binding manager.
4279
4380
public static class OnePanel extends JPanel