~ubuntu-branches/ubuntu/natty/electric/natty

« back to all changes in this revision

Viewing changes to com/sun/electric/tool/user/waveform/WaveformWindow.java

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2010-01-09 16:26:04 UTC
  • mfrom: (1.1.4 upstream) (3.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100109162604-1ypvmy8ijmlc6oq7
Tags: 8.10-1
* New upstream version.
* debian/control
  - Add libjava3d-java and quilt build dependencies.
  - Update standards version to 3.8.3.
  - Add libjava3d-java as recommends to binary package.
* debian/rules
  - Use quilt patch system instead of simple patchsys.
  - Add java3d related jar files to DEB_JARS.
* debian/patches/*
  - Update as per current upstream source. Convert to quilt.
* debian/ant.properties
  - Do not disable 3D plugin anymore.
  - Use new property to disable compilation of OS X related classes.
* debian/wrappers/electric
  - Add java3d related jar files to runtime classpath.
* debian/README.source
  - Change text to the appropriate one for quilt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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;
 
110
import java.io.*;
108
111
import java.net.URL;
109
112
import java.net.URLConnection;
110
113
import java.util.ArrayList;
117
120
import java.util.Map;
118
121
import java.util.Set;
119
122
import java.util.Stack;
120
 
 
121
123
import java.util.prefs.Preferences;
 
124
 
122
125
import javax.print.attribute.standard.ColorSupported;
123
126
import javax.swing.AbstractCellEditor;
124
127
import javax.swing.BoxLayout;
145
148
import javax.swing.tree.TreeNode;
146
149
import javax.swing.tree.TreePath;
147
150
 
 
151
import com.sun.electric.tool.io.*;
 
152
import java.io.*;
 
153
 
148
154
/**
149
155
 * This class defines the a screenful of Panels that make up a waveform display.
150
156
 */
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;
204
 
 
 
210
        /** The background color */                                                             private static Color backgroundColor;
205
211
        /** drop target (for drag and drop) */                                  public static WaveFormDropTarget waveformDropTarget = new WaveFormDropTarget();
206
212
 
207
213
        private static final ImageIcon iconAddPanel = Resources.getResource(WaveformWindow.class, "ButtonSimAddPanel.gif");
636
642
                        public void actionPerformed(ActionEvent evt) { vcrClickSlower(); }
637
643
                });
638
644
 
 
645
                backgroundColor = vcrButtonSlower.getBackground();
639
646
                // the single horizontal ruler panel (when the X axes are locked)
640
647
                if (xAxisLocked)
641
648
                {
933
940
                        mainHorizRulerPanel.repaint();
934
941
        }
935
942
 
 
943
    public static void exportSimulationDataAsCSV(String file) 
 
944
    {
 
945
        if (file == null) // cancel operation for example
 
946
                return;
 
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");
 
951
            return;
 
952
        }
 
953
        WaveformWindow ww = (WaveformWindow)content;
 
954
        try {
 
955
            PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file)));
 
956
            for(Panel wp : ww.wavePanels)
 
957
                wp.dumpDataCSV(pw);
 
958
            pw.close();
 
959
            System.out.println("Exported Waveform in CSV format file '" + file + "'");
 
960
        } catch (Exception e) {
 
961
            throw new RuntimeException(e);
 
962
        }
 
963
    }
 
964
 
 
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");
 
970
            return;
 
971
        }
 
972
        WaveformWindow ww = (WaveformWindow)content;
 
973
        try {
 
974
            String commands = "";
 
975
            double min = Double.MAX_VALUE;
 
976
            double max = Double.MIN_VALUE;
 
977
            double sr = 1;
 
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));
 
982
            }
 
983
            if (file!=null) {
 
984
                commands += "set terminal "+format+"; ";
 
985
                commands += "set output \""+file+"\"; ";
 
986
            }
 
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);
 
994
            ep.start();
 
995
            PrintWriter pw = new PrintWriter(new OutputStreamWriter(ep.getStdin()));
 
996
            for(Panel wp : ww.wavePanels)
 
997
                wp.dumpDataForGnuplot(pw);
 
998
            pw.close();
 
999
        } catch (Exception e) {
 
1000
                System.out.println("ERROR: Unable to run 'gnuplot': " + e);
 
1001
        }
 
1002
    }
 
1003
 
936
1004
        /**
937
1005
         * Method to initialize for a new text search.
938
1006
         * @param search the string to locate.
1266
1334
 
1267
1335
        public JTable getWaveformTable() { return table; }
1268
1336
 
 
1337
        public static Color getBackgroundColor() { return backgroundColor; }
 
1338
 
1269
1339
        // ************************************* CONTROL OF PANELS IN THE WINDOW *************************************
1270
1340
 
1271
1341
        /**
1846
1916
                redrawAllPanels();
1847
1917
        }
1848
1918
 
1849
 
        private void vcrClickRewind()
 
1919
        public void vcrClickRewind()
1850
1920
        {
1851
1921
                vcrClickStop();
1852
1922
                Rectangle2D bounds = sd.getBounds();
1855
1925
                redrawAllPanels();
1856
1926
        }
1857
1927
 
1858
 
        private void vcrClickPlayBackwards()
 
1928
        public void vcrClickPlayBackwards()
1859
1929
        {
1860
1930
                if (vcrTimer == null)
1861
1931
                {
1880
1950
                vcrTimer = null;
1881
1951
        }
1882
1952
 
1883
 
        private void vcrClickPlay()
 
1953
        public void vcrClickPlay()
1884
1954
        {
1885
1955
                if (vcrTimer == null)
1886
1956
                {
1895
1965
                vcrPlayingBackwards = false;
1896
1966
        }
1897
1967
 
1898
 
        private void vcrClickToEnd()
 
1968
        public void vcrClickToEnd()
1899
1969
        {
1900
1970
                vcrClickStop();
1901
1971
                Rectangle2D bounds = sd.getBounds();
1904
1974
                redrawAllPanels();
1905
1975
        }
1906
1976
 
1907
 
        private void vcrClickFaster()
 
1977
        public void vcrClickFaster()
1908
1978
        {
1909
1979
                int j = vcrAdvanceSpeed / 4;
1910
1980
                if (j <= 0) j = 1;
1911
1981
                vcrAdvanceSpeed += j;
1912
1982
        }
1913
1983
 
1914
 
        private void vcrClickSlower()
 
1984
        public void vcrClickSlower()
1915
1985
        {
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;
2127
 
                }
 
2197
                } else if (an instanceof NewEpicAnalysis)
 
2198
        {
 
2199
                        DefaultMutableTreeNode analysisNode = ((NewEpicAnalysis)an).getSignalsForExplorer(analysis);
 
2200
                        treePathFromAnalysis.put(an, parentPath.pathByAddingChild(analysisNode));
 
2201
                        return analysisNode;
 
2202
        }
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");
3442
3517
        }
3443
3518
 
 
3519
    public static WaveformWindow getCurrentWaveformWindow() {
 
3520
                WindowFrame current = WindowFrame.getCurrentWindowFrame();
 
3521
                WindowContent content = current.getContent();
 
3522
                if (!(content instanceof WaveformWindow))
 
3523
                {
 
3524
                        System.out.println("Must select a Waveform window first");
 
3525
                        return null;
 
3526
                }
 
3527
        return (WaveformWindow)content;
 
3528
    }
 
3529
 
3444
3530
        /**
3445
3531
         * Method to write the simulation data as a tab-separated file.
3446
3532
         */
3852
3938
                                }
3853
3939
                                sb.append("\t");
3854
3940
                                sb.append(sigName);
 
3941
                                Color color = ws.getColor();
 
3942
                                sb.append(" {" + color.getRed() + "," + color.getGreen() + "," + color.getBlue() + "}");
3855
3943
                        }
3856
3944
                        sb.append("\n");
3857
3945
                }
3931
4019
        /**
3932
4020
         * Method called to toggle the display of vertex points.
3933
4021
         */
3934
 
        private void toggleShowPoints()
 
4022
        public void toggleShowPoints()
3935
4023
        {
3936
4024
                linePointMode = (linePointMode+1) % 3;
3937
4025
                switch (linePointMode)
4031
4119
                {
4032
4120
                        if (!wp.isSelected()) continue;
4033
4121
 
 
4122
                        boolean removedSingleStimuli = false;
4034
4123
                        for(WaveSignal ws : wp.getSignals())
4035
4124
                        {
4036
4125
                                if (ws.getSelectedControlPoints() != null)
4037
4126
                                {
4038
4127
                                        if (sd.getEngine() != null)
4039
 
                                                sd.getEngine().removeSelectedStimuli();
 
4128
                                        {
 
4129
                                                if (sd.getEngine().removeSelectedStimuli())
 
4130
                                                        removedSingleStimuli = true;
 
4131
                                        }
4040
4132
                                }
4041
4133
                        }
4042
 
                        if (wp.getAnalysisType() != null) deleteSignalFromPanel(wp); else
4043
 
                        {
4044
 
                                // do not delete the panel: make them use the "X" button
4045
 
//                              saveSignalOrder();
4046
 
//                              wp.closePanel();
4047
 
                        }
 
4134
                        if (wp.getAnalysisType() != null && !removedSingleStimuli) deleteSignalFromPanel(wp);
4048
4135
                        break;
4049
4136
                }
4050
4137
        }
4100
4187
                for(Panel wp : wavePanels)
4101
4188
                {
4102
4189
                        if (wp.getXAxisSignal() != null) continue;
4103
 
                        Analysis an = sd.findAnalysis(wp.getAnalysisType());
4104
 
                        if (leftEdge == rightEdge)
4105
 
                        {
4106
 
                                leftEdge = an.getLeftEdge();
4107
 
                                rightEdge = an.getRightEdge();
4108
 
                        } else
4109
 
                        {
4110
 
                                if (leftEdge < rightEdge)
 
4190
                        for(WaveSignal ws : wp.getSignals())
 
4191
                        {
 
4192
                                Rectangle2D bounds = ws.getSignal().getBounds();
 
4193
                                if (leftEdge == rightEdge)
4111
4194
                                {
4112
 
                                        leftEdge = Math.min(leftEdge, an.getLeftEdge());
4113
 
                                        rightEdge = Math.max(rightEdge, an.getRightEdge());
 
4195
                                        leftEdge = bounds.getMinX();
 
4196
                                        rightEdge = bounds.getMaxX();
4114
4197
                                } else
4115
4198
                                {
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());
4118
4201
                                }
4119
4202
                        }
 
4203
//                      Analysis an = sd.findAnalysis(wp.getAnalysisType());
 
4204
//                      if (leftEdge == rightEdge)
 
4205
//                      {
 
4206
//                              leftEdge = an.getLeftEdge();
 
4207
//                              rightEdge = an.getRightEdge();
 
4208
//                      } else
 
4209
//                      {
 
4210
//                              if (leftEdge < rightEdge)
 
4211
//                              {
 
4212
//                                      leftEdge = Math.min(leftEdge, an.getLeftEdge());
 
4213
//                                      rightEdge = Math.max(rightEdge, an.getRightEdge());
 
4214
//                              } else
 
4215
//                              {
 
4216
//                                      leftEdge = Math.max(leftEdge, an.getLeftEdge());
 
4217
//                                      rightEdge = Math.min(rightEdge, an.getRightEdge());
 
4218
//                              }
 
4219
//                      }
4120
4220
                }
4121
4221
 
4122
4222
                // if there is an overriding signal on the X axis, use its bounds
4274
4374
        // ************************************* DRAG AND DROP CLASSES *************************************
4275
4375
 
4276
4376
        /**
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.
4278
4379
         */
4279
4380
        public static class OnePanel extends JPanel
4280
4381
        {