All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.electric.tool.simulation.BusSample Maven / Gradle / Ivy

/* -*- tab-width: 4 -*-
 *
 * Electric(tm) VLSI Design System
 *
 * File: BusSample.java
 *
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
 *
 * Electric(tm) is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Electric(tm) is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Electric(tm); see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, Mass 02111-1307, USA.
 */
package com.sun.electric.tool.simulation;

import com.sun.electric.database.geometry.Poly;
import com.sun.electric.database.geometry.PolyBase;
import com.sun.electric.database.variable.TextDescriptor;
import com.sun.electric.tool.user.waveform.Panel;
import com.sun.electric.tool.user.waveform.WaveSignal;
import com.sun.electric.tool.user.waveform.Panel.WaveSelection;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.font.GlyphVector;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.HashSet;
import java.util.List;
import java.util.TreeMap;

/**
 * A bus of many Signal is represented as a single
 * Signal>.
 */
public class BusSample implements Sample
{
    private final Sample[] vals;

    public BusSample(Sample[] vals)
    {
        int numValids = 0;
        for(int i=0; i)) return false;
        BusSample bo = (BusSample)o;
        if (bo.vals.length != vals.length) return false;
        for(int i=0; i)) throw new RuntimeException("tried to call BusSample.lub("+s.getClass().getName()+")");
        BusSample ds = (BusSample)s;
        if (ds.vals.length != vals.length) throw new RuntimeException("tried to call lub() on BusSamples of different width");
        Sample[] ret = new Sample[vals.length];
        for(int i=0; i(ret);
    }

    public Sample glb(Sample s)
    {
        if (!(s instanceof BusSample)) throw new RuntimeException("tried to call BusSample.glb("+s.getClass().getName()+")");
        BusSample ds = (BusSample)s;
        if (ds.vals.length != vals.length) throw new RuntimeException("tried to call glb() on BusSamples of different width");
        Sample[] ret = new Sample[vals.length];
        for(int i=0; i(ret);
    }

    public double getMinValue()
    {
    	double min = Double.MAX_VALUE;
    	for(int i=0; i> */
    public static  Signal> createSignal(SignalCollection sc, Stimuli sd, String signalName,
    	String signalContext, int width)
    {
        /*
        final Unboxed> unboxer = new Unboxed>() {
            public int getSize() { return 1; }
            public DigitalSample deserialize(byte[] buf, int ofs) { return fromByteRepresentation(buf[ofs]); }
            public void serialize(DigitalSample v, byte[] buf, int ofs) { buf[ofs] = v.getByteRepresentation(); }
            public int compare(byte[] buf1, int ofs1, byte[] buf2, int ofs2) { return (buf1[ofs1]&0xff)-(buf2[ofs2]&0xff); }
        };
        Signal ret =
            new BTreeSignal(an, signalName, signalContext, BTreeSignal.getTree(unboxer, latticeOp)) {
            public boolean isAnalog() { return true; }
        };
        an.addSignal(ret);
        return ret;
        */
        throw new RuntimeException("not implemented");
    }

    /** create a Signal> from preexisting Signal's */
    public static  Signal> createSignal(SignalCollection sc, Stimuli sd, String signalName,
    	String signalContext, boolean digital, final Signal[] subsignals)
    {
        return new Signal>(sc, sd, signalName, signalContext, digital)
        {
            public boolean isEmpty() { for(Signal sig : subsignals) if (!sig.isEmpty()) return false; return true; }

            public Signal[] getBusMembers() { return subsignals; }

            public Signal.View>> getRasterView(final double t0, final double t1, final int numPixels)
            {
                final Signal.View>[] subviews = new Signal.View[subsignals.length];

                for(int i=0; i (exists j such that subviews[i].getTime(j)==t)
                TreeMap> tm = new TreeMap>();
                for (int i=0; i> view = subviews[i];
                    for(int j=0; j hs = tm.get(t);
                        if (hs == null) tm.put(t, hs = new HashSet());
                        hs.add(new Integer(i));
                    }
                }

                // now we know, for each point in time, which signals changed at that point
                final double[] times = new double[tm.size()];
                final RangeSample>[] vals = new RangeSample[tm.size()];
                int i = 0;
                int[] event = new int[subviews.length];
                SS[] minvals = (SS[])new Sample[subviews.length];
                SS[] maxvals = (SS[])new Sample[subviews.length];
                for(Double t : tm.keySet())
                {
                	times[i] = t.doubleValue();
                    HashSet hs = tm.get(t);
                    for(int v : hs)
                    {
                    	// this used to be an assertion, but since it is possible for two successive events
                    	// to have the same time, the assertion may fail
                    	if (subviews[v].getTime(event[v]) != t.doubleValue()) continue;
                        RangeSample rs = subviews[v].getSample(event[v]);
						if (rs != null)
						{
	                        minvals[v] = rs.getMin();
	                        maxvals[v] = rs.getMax();
						}
                        event[v]++;
                    }
                    vals[i] = new RangeSample>( new BusSample(minvals), new BusSample(maxvals) );
                    i++;
                }

                return new Signal.View>>()
                {
                    public int                        getNumEvents() { return times.length; }
                    public double                     getTime(int event) { return times[event]; }
                    public RangeSample> getSample(int event) { return vals[event]; }
                };
            }

            public Signal.View> getExactView()
            {
                final Signal.View[] subviews = new Signal.View[subsignals.length];
                for(int i=0; i (exists j such that subviews[i].getTime(j)==t)
                TreeMap> tm = new TreeMap>();
                for (int i=0; i view = subviews[i];
                    for(int j=0; j hs = tm.get(t);
                        if (hs == null) tm.put(t, hs = new HashSet());
                        hs.add(new Integer(i));
                    }
                }

                // now we know, for each point in time, which signals changed at that point
                final double[] times = new double[tm.size()];
                final BusSample[] vals = new BusSample[tm.size()];
                int i = 0;
                int[] event = new int[subviews.length];
                SS[] sampleVals = (SS[])new Sample[subviews.length];
                for(Double t : tm.keySet())
                {
                	times[i] = t.doubleValue();
                    HashSet hs = tm.get(t);
                    for(int v : hs)
                    {
                        assert subviews[v].getTime(event[v]) == t.doubleValue();  // sanity check
                        SS rs = subviews[v].getSample(event[v]);
						if (rs != null) sampleVals[v] = rs;
                        event[v]++;
                    }
                    vals[i] = new BusSample(sampleVals);
                    i++;
                }

                return new Signal.View>()
                {
                    public int           getNumEvents() { return times.length; }
                    public double        getTime(int event) { return times[event]; }
                    public BusSample getSample(int event) { return vals[event]; }
                };
            }

            public double getMinTime()
            {
                double min = Double.MAX_VALUE;
                for(Signal sig : subsignals) min = Math.min(min, sig.getMinTime());
                return min;
            }

            public double getMaxTime()
            {
                double max = -Double.MAX_VALUE;
                for(Signal sig : subsignals) max = Math.max(max, sig.getMaxTime());
                return max;
            }

            public double getMinValue()
            {
                double min = Double.MAX_VALUE;
                for(Signal sig : subsignals) min = Math.min(min, sig.getMinValue());
                return min;
            }

            public double getMaxValue()
            {
                double max = -Double.MAX_VALUE;
                for(Signal sig : subsignals) max = Math.max(max, sig.getMaxValue());
                return max;
            }

            public void plot(Panel panel, Graphics g, WaveSignal ws, Color light, List forPs,
            	Rectangle2D bounds, List selectedObjects, Signal xAxisSignal)
            {
                Dimension sz = panel.getSize();
                int hei = sz.height;

                // draw digital traces
				Signal> ds = (Signal>)ws.getSignal();
                Signal.View > > view = ds.getRasterView(panel.convertXScreenToData(0),
                    panel.convertXScreenToData(sz.width), sz.width);
                int lastX = 0;
                int trueLen = (subsignals.length + 3) / 4 * 4;
                int [] values = new int[trueLen];
                for(int i=0; i > rs = view.getSample(i);
                    // XXX: shouldn't ignore the max!
                    BusSample bs = rs.getMin();
                    int invert = trueLen - 1;
                    for(int j=0; j= panel.getVertAxisPos())
                    {
                        if (x < panel.getVertAxisPos()+5)
                        {
                            // on the left edge: just draw the "<"
                            if (panel.processALine(g, x, hei/2, x+5, hei-5, bounds, forPs, selectedObjects, ws, -1)) return;
                            if (panel.processALine(g, x, hei/2, x+5, 5, bounds, forPs, selectedObjects, ws, -1)) return;
                        } else
                        {
                            // bus change point: draw the "X"
                            if (panel.processALine(g, x-5, 5, x+5, hei-5, bounds, forPs, selectedObjects, ws, -1)) return;
                            if (panel.processALine(g, x+5, 5, x-5, hei-5, bounds, forPs, selectedObjects, ws, -1)) return;
                        }
                        if (lastX+5 < x-5)
                        {
                            // previous bus change point: draw horizontal bars to connect
                            if (panel.processALine(g, lastX+5, 5, x-5, 5, bounds, forPs, selectedObjects, ws, -1)) return;
                            if (panel.processALine(g, lastX+5, hei-5, x-5, hei-5, bounds, forPs, selectedObjects, ws, -1)) return;
                        }

                        String valString = "0x";
                        for(int j=0; j 1)
                        {
                        	for(int j=0; j