~ubuntu-branches/ubuntu/maverick/electric/maverick

« back to all changes in this revision

Viewing changes to com/sun/electric/tool/simulation/BTreeNewSignal.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:
 
1
/* -*- tab-width: 4 -*-
 
2
 *
 
3
 * Electric(tm) VLSI Design System
 
4
 *
 
5
 * Copyright (c) 2009 Sun Microsystems and Static Free Software
 
6
 *
 
7
 * Electric(tm) is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 3 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * Electric(tm) 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 Electric(tm); see the file COPYING.  If not, write to
 
19
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 
20
 * Boston, Mass 02111-1307, USA.
 
21
 */
 
22
package com.sun.electric.tool.simulation;
 
23
 
 
24
import java.io.*;
 
25
import java.util.*;
 
26
import com.sun.electric.database.geometry.btree.*;
 
27
import com.sun.electric.database.geometry.btree.unboxed.*;
 
28
import com.sun.electric.tool.simulation.*;
 
29
 
 
30
public class BTreeNewSignal extends NewSignalSimpleImpl implements Waveform {
 
31
 
 
32
    public final int numEvents;
 
33
    public final int eventWithMinValue;
 
34
    public final int eventWithMaxValue;
 
35
    private NewSignal.Approximation<ScalarSample> preferredApproximation = null;
 
36
    private final BTree<Double,Double,Serializable> tree;
 
37
    
 
38
    public BTreeNewSignal(int eventWithMinValue,
 
39
                          int eventWithMaxValue,
 
40
                          BTree<Double,Double,Serializable> tree
 
41
                          ) {
 
42
        this.numEvents = tree.size();
 
43
        this.eventWithMinValue = eventWithMinValue;
 
44
        this.eventWithMaxValue = eventWithMaxValue;
 
45
        if (tree==null) throw new RuntimeException();
 
46
        this.tree = tree;
 
47
        this.preferredApproximation = new BTreeNewSignalApproximation();
 
48
    }
 
49
 
 
50
    public synchronized NewSignal.Approximation<ScalarSample> getPreferredApproximation() {
 
51
        return preferredApproximation;
 
52
    }
 
53
 
 
54
    protected ScalarSample getSampleForTime(double t, boolean justLessThan) {
 
55
        Double d = tree.getValFromKeyFloor(t);
 
56
        if (d==null) throw new RuntimeException("index out of bounds");
 
57
        return new ScalarSample(d.doubleValue());
 
58
    }
 
59
 
 
60
    public int getNumEvents() { return numEvents; }
 
61
    protected int getEventForTime(double t, boolean justLessThan) {
 
62
        return tree.getOrdFromKeyFloor(t);
 
63
    }
 
64
    public void getEvent(int index, double[] result) {
 
65
        result[0] = getPreferredApproximation().getTime(index);
 
66
        result[1] = result[2] = getPreferredApproximation().getSample(index).getValue();
 
67
    }
 
68
 
 
69
    public NewSignal.Approximation<ScalarSample>
 
70
        getPixelatedApproximation(double t0, double t1, int numRegions) {
 
71
        return new BTreePixelatedApproximation(t0, t1, numRegions);
 
72
    }
 
73
 
 
74
    private class BTreeNewSignalApproximation implements NewSignal.Approximation<ScalarSample> {
 
75
        public int getNumEvents() { return numEvents; }
 
76
        public double             getTime(int index) {
 
77
            Double d = tree.getKeyFromOrd(index);
 
78
            if (d==null) throw new RuntimeException("index out of bounds");
 
79
            return d.doubleValue();
 
80
        }
 
81
        public ScalarSample       getSample(int index) {
 
82
            Double d = tree.getValFromOrd(index);
 
83
            if (d==null) throw new RuntimeException("index out of bounds");
 
84
            return new ScalarSample(d.doubleValue());
 
85
        }
 
86
        public int getTimeNumerator(int index) { throw new RuntimeException("not implemented"); }
 
87
        public int getTimeDenominator() { throw new RuntimeException("not implemented"); }
 
88
        public int getEventWithMaxValue() { return eventWithMaxValue; }
 
89
        public int getEventWithMinValue() { return eventWithMinValue; }
 
90
    }
 
91
 
 
92
    private class BTreePixelatedApproximation implements NewSignal.Approximation<ScalarSample> {
 
93
        int[] events;
 
94
        public BTreePixelatedApproximation(double t0, double t1, int numRegions) {
 
95
            int[] events = new int[numRegions];
 
96
            int j = 0;
 
97
            double stride = (t1-t0)/(numRegions*2);
 
98
            for(int i=0; i<numRegions; i++) {
 
99
                double t = t0 + (2*i+1)*stride;
 
100
                int idx = i==numRegions-1
 
101
                    ? tree.getOrdFromKeyCeiling(t)
 
102
                    : tree.getOrdFromKeyFloor(t);
 
103
                if (j>0 && events[j-1]==idx) idx = tree.getOrdFromKeyCeiling(t);
 
104
                if (j>0 && events[j-1]==idx) continue;
 
105
                if (idx==tree.size()) continue;
 
106
                if (idx==-1) continue;
 
107
                if (j < numRegions-1 && tree.getKeyFromOrd(idx) > t+2*stride) continue;
 
108
                events[j++] = idx;
 
109
            }
 
110
            this.events = new int[j];
 
111
            System.arraycopy(events, 0, this.events, 0, j);
 
112
        }
 
113
        public int getNumEvents() { return events.length; }
 
114
        public double getTime(int index) {
 
115
            Double d = tree.getKeyFromOrd(events[index]);
 
116
            if (d==null) throw new RuntimeException("index "+index+"/"+events[index]+" out of bounds, size="+tree.size());
 
117
            return d.doubleValue();
 
118
        }
 
119
        public ScalarSample getSample(int index) {
 
120
            Double d = tree.getValFromOrd(events[index]);
 
121
            if (d==null) throw new RuntimeException("index out of bounds");
 
122
            return new ScalarSample(d.doubleValue());
 
123
        }
 
124
        public int getTimeNumerator(int index) { throw new RuntimeException("not implemented"); }
 
125
        public int getTimeDenominator() { throw new RuntimeException("not implemented"); }
 
126
        public int getEventWithMaxValue() {
 
127
            //return eventWithMaxValue;
 
128
            throw new RuntimeException("not implemented");
 
129
        }
 
130
        public int getEventWithMinValue() { 
 
131
            //return eventWithMinValue;
 
132
            throw new RuntimeException("not implemented");
 
133
        }
 
134
    }
 
135
}