2015-01-21 21:58:35 +01:00
|
|
|
/*******************************************************************************
|
2021-01-09 14:26:49 +01:00
|
|
|
* Copyright (c) 2015-2021 MINRES Technologies GmbH and others.
|
2015-01-21 21:58:35 +01:00
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* MINRES Technologies GmbH - initial API and implementation
|
|
|
|
*******************************************************************************/
|
2015-01-06 17:14:16 +01:00
|
|
|
package com.minres.scviewer.database.vcd;
|
|
|
|
|
2018-10-15 09:13:41 +02:00
|
|
|
import java.util.Map.Entry;
|
2015-01-20 18:50:15 +01:00
|
|
|
import java.util.NavigableMap;
|
|
|
|
import java.util.TreeMap;
|
2015-01-06 17:14:16 +01:00
|
|
|
|
|
|
|
import com.minres.scviewer.database.HierNode;
|
2020-11-28 10:22:22 +01:00
|
|
|
import com.minres.scviewer.database.IEvent;
|
2015-01-06 17:14:16 +01:00
|
|
|
import com.minres.scviewer.database.IWaveform;
|
2020-11-28 14:08:34 +01:00
|
|
|
import com.minres.scviewer.database.WaveformType;
|
2015-01-06 17:14:16 +01:00
|
|
|
|
2020-11-28 10:22:22 +01:00
|
|
|
public class VCDSignal<T extends IEvent> extends HierNode implements IWaveform {
|
2015-01-06 17:14:16 +01:00
|
|
|
|
|
|
|
private long id;
|
|
|
|
|
|
|
|
private String fullName;
|
|
|
|
|
|
|
|
private final int width;
|
2018-11-05 18:21:54 +01:00
|
|
|
|
2020-11-28 10:22:22 +01:00
|
|
|
private NavigableMap<Long, IEvent[]> values;
|
2015-01-06 17:14:16 +01:00
|
|
|
|
2021-01-02 17:02:05 +01:00
|
|
|
public VCDSignal(String name) {
|
|
|
|
this(0, name, 1);
|
2015-01-06 17:14:16 +01:00
|
|
|
}
|
|
|
|
|
2021-01-02 17:02:05 +01:00
|
|
|
public VCDSignal(int id, String name) {
|
|
|
|
this(id,name,1);
|
2015-01-06 17:14:16 +01:00
|
|
|
}
|
|
|
|
|
2021-01-02 17:02:05 +01:00
|
|
|
public VCDSignal(int id, String name, int width) {
|
2015-01-06 17:14:16 +01:00
|
|
|
super(name);
|
|
|
|
fullName=name;
|
|
|
|
this.id=id;
|
|
|
|
this.width=width;
|
2020-11-29 10:25:48 +01:00
|
|
|
this.values=new TreeMap<>();
|
2015-01-06 17:14:16 +01:00
|
|
|
}
|
|
|
|
|
2020-11-29 10:25:48 +01:00
|
|
|
public VCDSignal(VCDSignal<T> o, int id, String name) {
|
2015-01-06 17:14:16 +01:00
|
|
|
super(name);
|
|
|
|
fullName=name;
|
|
|
|
this.id=id;
|
2020-11-28 10:22:22 +01:00
|
|
|
this.width=o.width;
|
|
|
|
this.values=o.values;
|
2015-01-06 17:14:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getFullName() {
|
|
|
|
return fullName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setId(int id) {
|
|
|
|
this.id=id;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Long getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2018-11-05 18:21:54 +01:00
|
|
|
public void addSignalChange(Long time, T value){
|
2020-11-28 10:22:22 +01:00
|
|
|
if(values.containsKey(time)) {
|
|
|
|
IEvent[] oldV = values.get(time);
|
|
|
|
IEvent[] newV = new IEvent[oldV.length+1];
|
|
|
|
System.arraycopy(oldV, 0, newV, 0, oldV.length);
|
|
|
|
newV[oldV.length]=value;
|
|
|
|
values.put(time, newV);
|
|
|
|
} else {
|
|
|
|
values.put(time, new IEvent[] {value});
|
|
|
|
}
|
2015-01-06 17:14:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-11-28 10:22:22 +01:00
|
|
|
public NavigableMap<Long, IEvent[]> getEvents() {
|
2015-01-06 17:14:16 +01:00
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-11-28 10:22:22 +01:00
|
|
|
public IEvent[] getEventsAtTime(Long time) {
|
2015-01-20 18:50:15 +01:00
|
|
|
return values.get(time);
|
2015-01-06 17:14:16 +01:00
|
|
|
}
|
|
|
|
|
2015-07-10 13:40:50 +02:00
|
|
|
@Override
|
2020-11-28 10:22:22 +01:00
|
|
|
public IEvent[] getEventsBeforeTime(Long time) {
|
|
|
|
Entry<Long, IEvent[]> e = values.floorEntry(time);
|
2018-10-15 09:13:41 +02:00
|
|
|
if(e==null)
|
2020-11-29 10:25:48 +01:00
|
|
|
return new IEvent[] {};
|
2018-10-15 09:13:41 +02:00
|
|
|
else
|
2020-11-29 10:25:48 +01:00
|
|
|
return values.floorEntry(time).getValue();
|
2015-07-10 13:40:50 +02:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:02:58 +02:00
|
|
|
@Override
|
2020-11-29 10:25:48 +01:00
|
|
|
public boolean isSame(IWaveform other) {
|
2020-03-13 16:01:16 +01:00
|
|
|
return( other instanceof VCDSignal<?> && this.getId().equals(other.getId()));
|
2015-10-22 00:02:58 +02:00
|
|
|
}
|
|
|
|
|
2018-11-05 18:21:54 +01:00
|
|
|
@Override
|
2020-11-28 14:08:34 +01:00
|
|
|
public WaveformType getType() {
|
|
|
|
return WaveformType.SIGNAL;
|
2018-11-05 18:21:54 +01:00
|
|
|
}
|
|
|
|
|
2020-11-28 10:22:22 +01:00
|
|
|
@Override
|
2021-01-14 23:13:11 +01:00
|
|
|
public int getRowCount() {
|
2020-11-28 14:08:34 +01:00
|
|
|
return width;
|
2020-11-28 10:22:22 +01:00
|
|
|
}
|
2015-01-06 17:14:16 +01:00
|
|
|
|
2021-01-09 10:34:22 +01:00
|
|
|
@Override
|
|
|
|
public String getKind() {
|
|
|
|
return "signal";
|
|
|
|
}
|
|
|
|
|
2015-01-06 17:14:16 +01:00
|
|
|
}
|