Unified databases so that signals and transactions can be loaded into
same database
This commit is contained in:
parent
9553fbff8c
commit
dc861722c4
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="SQLiteDbFactory">
|
||||
<implementation class="com.minres.scviewer.database.sqlite.SQLiteDbFactory"/>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="SQLiteDbLoader">
|
||||
<implementation class="com.minres.scviewer.database.sqlite.SQLiteDbLoader"/>
|
||||
<service>
|
||||
<provide interface="com.minres.scviewer.database.IWaveformDbFactory"/>
|
||||
<provide interface="com.minres.scviewer.database.IWaveformDbLoader"/>
|
||||
</service>
|
||||
</scr:component>
|
||||
|
@ -1,36 +0,0 @@
|
||||
package com.minres.scviewer.database.sqlite;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbFactory;
|
||||
|
||||
public class SQLiteDbFactory implements IWaveformDbFactory {
|
||||
|
||||
private byte[] x = "SQLite format 3".getBytes();
|
||||
|
||||
public SQLiteDbFactory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveformDb createDatabase(File file) {
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
byte[] buffer = new byte[x.length];
|
||||
int read = fis.read(buffer, 0, x.length);
|
||||
fis.close();
|
||||
if (read == x.length)
|
||||
for (int i = 0; i < x.length; i++)
|
||||
if (buffer[i] != x[i])
|
||||
return null;
|
||||
SQLiteDb db = new SQLiteDb();
|
||||
db.load(file);
|
||||
return db;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ package com.minres.scviewer.database.sqlite;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
@ -9,12 +10,9 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.EventTime;
|
||||
import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IHierNode;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.sqlite.db.IDatabase;
|
||||
import com.minres.scviewer.database.sqlite.db.SQLiteDatabase;
|
||||
@ -23,7 +21,7 @@ import com.minres.scviewer.database.sqlite.tables.ScvSimProps;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvStream;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvTxEvent;
|
||||
|
||||
public class SQLiteDb extends HierNode implements IWaveformDb {
|
||||
public class SQLiteDbLoader implements IWaveformDbLoader {
|
||||
|
||||
protected IDatabase database;
|
||||
|
||||
@ -32,13 +30,10 @@ public class SQLiteDb extends HierNode implements IWaveformDb {
|
||||
long timeResolution=1;
|
||||
|
||||
private HashMap<String, RelationType> relationMap = new HashMap<String, RelationType>();
|
||||
|
||||
private IWaveformDb db;
|
||||
|
||||
IDatabase getDb(){
|
||||
return database;
|
||||
}
|
||||
|
||||
public SQLiteDb() {
|
||||
super("SQLiteDb");
|
||||
public SQLiteDbLoader() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,7 +58,7 @@ public class SQLiteDb extends HierNode implements IWaveformDb {
|
||||
streams=new ArrayList<IWaveform>();
|
||||
try {
|
||||
for(ScvStream scvStream:handler.selectObjects()){
|
||||
streams.add(new TxStream(this, scvStream));
|
||||
streams.add(new TxStream(database, db, scvStream));
|
||||
}
|
||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||
@ -73,77 +68,34 @@ public class SQLiteDb extends HierNode implements IWaveformDb {
|
||||
return streams;
|
||||
}
|
||||
|
||||
private byte[] x = "SQLite format 3".getBytes();
|
||||
|
||||
@Override
|
||||
public void load(File file) throws InputFormatException {
|
||||
public boolean load(IWaveformDb db, File file) throws Exception {
|
||||
this.db=db;
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
byte[] buffer = new byte[x.length];
|
||||
int read = fis.read(buffer, 0, x.length);
|
||||
fis.close();
|
||||
if (read == x.length)
|
||||
for (int i = 0; i < x.length; i++)
|
||||
if (buffer[i] != x[i]) return false;
|
||||
|
||||
database=new SQLiteDatabase(file.getAbsolutePath());
|
||||
database.setData("TIMERESOLUTION", 1L);
|
||||
SQLiteDatabaseSelectHandler<ScvSimProps> handler = new SQLiteDatabaseSelectHandler<ScvSimProps>(ScvSimProps.class, database);
|
||||
try {
|
||||
for(ScvSimProps scvSimProps:handler.selectObjects()){
|
||||
timeResolution=scvSimProps.getTime_resolution();
|
||||
database.setData("TIMERESOLUTION", scvSimProps.getTime_resolution());
|
||||
}
|
||||
return true;
|
||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
buildHierarchyNodes();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
database=null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveform getStreamByName(String name) {
|
||||
for (IWaveform n : getAllWaves())
|
||||
if (n.getFullName().equals(name))
|
||||
return n;
|
||||
return null;
|
||||
}
|
||||
|
||||
public ITxStream getStreamById(long id) {
|
||||
for (IWaveform n : getAllWaves())
|
||||
if (n.getId().equals(id))
|
||||
return (ITxStream) n;
|
||||
return null;
|
||||
}
|
||||
|
||||
private void buildHierarchyNodes() throws InputFormatException{
|
||||
for(IWaveform stream:getAllWaves()){
|
||||
String[] hier = stream.getFullName().split("\\.");
|
||||
IHierNode node = this;
|
||||
for(String name:hier){
|
||||
IHierNode n1 = null;
|
||||
for (IHierNode n : node.getChildNodes()) {
|
||||
if (n.getName().equals(name)) {
|
||||
n1=n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(name == hier[hier.length-1]){ //leaf
|
||||
if(n1!=null) {
|
||||
if(n1 instanceof HierNode){
|
||||
node.getChildNodes().remove(n1);
|
||||
stream.getChildNodes().addAll(n1.getChildNodes());
|
||||
} else {
|
||||
throw new InputFormatException();
|
||||
}
|
||||
}
|
||||
stream.setName(name);
|
||||
node.getChildNodes().add(stream);
|
||||
node=stream;
|
||||
} else { // intermediate
|
||||
if(n1 != null) {
|
||||
node=n1;
|
||||
} else {
|
||||
HierNode newNode = new HierNode(name);
|
||||
node.getChildNodes().add(newNode);
|
||||
node=newNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RelationType getRelationType(String relationName) {
|
||||
if(relationMap.containsKey(relationName)) return relationMap.get(relationName);
|
@ -14,6 +14,7 @@ import com.minres.scviewer.database.ITxGenerator;
|
||||
import com.minres.scviewer.database.ITxRelation;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.sqlite.db.IDatabase;
|
||||
import com.minres.scviewer.database.sqlite.db.SQLiteDatabaseSelectHandler;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvTx;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvTxAttribute;
|
||||
@ -22,6 +23,7 @@ import com.minres.scviewer.database.sqlite.tables.ScvTxRelation;
|
||||
|
||||
public class Tx implements ITx {
|
||||
|
||||
private IDatabase database;
|
||||
private TxStream trStream;
|
||||
private TxGenerator trGenerator;
|
||||
private ScvTx scvTx;
|
||||
@ -29,7 +31,8 @@ public class Tx implements ITx {
|
||||
private EventTime begin, end;
|
||||
private List<ITxRelation> incoming, outgoing;
|
||||
|
||||
public Tx(TxStream trStream, TxGenerator trGenerator, ScvTx scvTx) {
|
||||
public Tx(IDatabase database, TxStream trStream, TxGenerator trGenerator, ScvTx scvTx) {
|
||||
this.database=database;
|
||||
this.trStream=trStream;
|
||||
this.trGenerator=trGenerator;
|
||||
this.scvTx=scvTx;
|
||||
@ -54,10 +57,10 @@ public class Tx implements ITx {
|
||||
public EventTime getBeginTime() {
|
||||
if(begin==null){
|
||||
SQLiteDatabaseSelectHandler<ScvTxEvent> handler = new SQLiteDatabaseSelectHandler<ScvTxEvent>(ScvTxEvent.class,
|
||||
trStream.getDb().getDb(), "tx="+scvTx.getId()+" AND type="+ AssociationType.BEGIN.ordinal());
|
||||
database, "tx="+scvTx.getId()+" AND type="+ AssociationType.BEGIN.ordinal());
|
||||
try {
|
||||
for(ScvTxEvent scvEvent:handler.selectObjects()){
|
||||
begin= new EventTime(scvEvent.getTime()*trStream.getDb().timeResolution);
|
||||
begin= new EventTime(scvEvent.getTime()*(Long)database.getData("TIMERESOLUTION"));
|
||||
}
|
||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||
@ -70,10 +73,10 @@ public class Tx implements ITx {
|
||||
public EventTime getEndTime() {
|
||||
if(end==null){
|
||||
SQLiteDatabaseSelectHandler<ScvTxEvent> handler = new SQLiteDatabaseSelectHandler<ScvTxEvent>(ScvTxEvent.class,
|
||||
trStream.getDb().getDb(), "tx="+scvTx.getId()+" AND type="+ AssociationType.END.ordinal());
|
||||
database, "tx="+scvTx.getId()+" AND type="+ AssociationType.END.ordinal());
|
||||
try {
|
||||
for(ScvTxEvent scvEvent:handler.selectObjects()){
|
||||
end = new EventTime(scvEvent.getTime()*trStream.getDb().timeResolution);
|
||||
end = new EventTime(scvEvent.getTime()*(Long)database.getData("TIMERESOLUTION"));
|
||||
}
|
||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||
@ -86,7 +89,7 @@ public class Tx implements ITx {
|
||||
public List<ITxAttribute> getAttributes() {
|
||||
if(attributes==null){
|
||||
SQLiteDatabaseSelectHandler<ScvTxAttribute> handler = new SQLiteDatabaseSelectHandler<ScvTxAttribute>(
|
||||
ScvTxAttribute.class, trStream.getDb().getDb(), "tx="+scvTx.getId());
|
||||
ScvTxAttribute.class, database, "tx="+scvTx.getId());
|
||||
try {
|
||||
attributes = new ArrayList<ITxAttribute>();
|
||||
for(ScvTxAttribute scvAttribute:handler.selectObjects()){
|
||||
@ -104,7 +107,7 @@ public class Tx implements ITx {
|
||||
public Collection<ITxRelation> getIncomingRelations() {
|
||||
if(incoming==null){
|
||||
SQLiteDatabaseSelectHandler<ScvTxRelation> handler = new SQLiteDatabaseSelectHandler<ScvTxRelation>(
|
||||
ScvTxRelation.class, trStream.getDb().getDb(), "sink="+scvTx.getId());
|
||||
ScvTxRelation.class, database, "sink="+scvTx.getId());
|
||||
try {
|
||||
incoming = new ArrayList<ITxRelation>();
|
||||
for(ScvTxRelation scvRelation:handler.selectObjects()){
|
||||
@ -121,7 +124,7 @@ public class Tx implements ITx {
|
||||
public Collection<ITxRelation> getOutgoingRelations() {
|
||||
if(outgoing==null){
|
||||
SQLiteDatabaseSelectHandler<ScvTxRelation> handler = new SQLiteDatabaseSelectHandler<ScvTxRelation>(
|
||||
ScvTxRelation.class, trStream.getDb().getDb(), "src="+scvTx.getId());
|
||||
ScvTxRelation.class, database, "src="+scvTx.getId());
|
||||
try {
|
||||
outgoing = new ArrayList<ITxRelation>();
|
||||
for(ScvTxRelation scvRelation:handler.selectObjects()){
|
||||
@ -136,8 +139,9 @@ public class Tx implements ITx {
|
||||
|
||||
private ITxRelation createRelation(ScvTxRelation rel, boolean outgoing) {
|
||||
long otherId = outgoing?rel.getSink():rel.getSrc();
|
||||
/*FIXME:
|
||||
try {
|
||||
List<ScvTx> scvTx=new SQLiteDatabaseSelectHandler<ScvTx>(ScvTx.class, trStream.getDb().getDb(), "id="+otherId).selectObjects();
|
||||
List<ScvTx> scvTx=new SQLiteDatabaseSelectHandler<ScvTx>(ScvTx.class, database, "id="+otherId).selectObjects();
|
||||
assert(scvTx.size()==1);
|
||||
ITxStream stream = trStream.getDb().getStreamById(scvTx.get(0).getStream());
|
||||
Tx that=(Tx) stream.getTransactionById(otherId);
|
||||
@ -147,7 +151,7 @@ public class Tx implements ITx {
|
||||
return new TxRelation(trStream.getDb().getRelationType(rel.getName()), that, this);
|
||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||
}
|
||||
}*/
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,8 @@ import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.ITxGenerator;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.sqlite.db.IDatabase;
|
||||
import com.minres.scviewer.database.sqlite.db.SQLiteDatabaseSelectHandler;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvGenerator;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvStream;
|
||||
@ -20,9 +22,11 @@ import com.minres.scviewer.database.sqlite.tables.ScvTx;
|
||||
|
||||
public class TxStream extends HierNode implements ITxStream {
|
||||
|
||||
private IDatabase database;
|
||||
|
||||
private String fullName;
|
||||
|
||||
private SQLiteDb db;
|
||||
private IWaveformDb db;
|
||||
|
||||
private ScvStream scvStream;
|
||||
|
||||
@ -30,11 +34,17 @@ public class TxStream extends HierNode implements ITxStream {
|
||||
|
||||
private NavigableSet<ITx> transactions;
|
||||
|
||||
public TxStream(SQLiteDb trSQLiteDb, ScvStream scvStream) {
|
||||
public TxStream(IDatabase database, IWaveformDb waveformDb, ScvStream scvStream) {
|
||||
super(scvStream.getName());
|
||||
this.database=database;
|
||||
fullName=scvStream.getName();
|
||||
this.scvStream=scvStream;
|
||||
db=trSQLiteDb;
|
||||
db=waveformDb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveformDb getDb() {
|
||||
return db;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,16 +62,11 @@ public class TxStream extends HierNode implements ITxStream {
|
||||
return scvStream.getKind();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLiteDb getDb() {
|
||||
return db;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITxGenerator> getGenerators() {
|
||||
if(generators==null){
|
||||
SQLiteDatabaseSelectHandler<ScvGenerator> handler = new SQLiteDatabaseSelectHandler<ScvGenerator>(
|
||||
ScvGenerator.class, db.getDb(), "stream="+scvStream.getId());
|
||||
ScvGenerator.class, database, "stream="+scvStream.getId());
|
||||
generators=new HashMap<Integer, TxGenerator>();
|
||||
try {
|
||||
for(ScvGenerator scvGenerator:handler.selectObjects()){
|
||||
@ -94,12 +99,12 @@ public class TxStream extends HierNode implements ITxStream {
|
||||
protected void checkTransactions() {
|
||||
if(transactions==null){
|
||||
if(generators==null) getGenerators();
|
||||
SQLiteDatabaseSelectHandler<ScvTx> handler = new SQLiteDatabaseSelectHandler<ScvTx>(ScvTx.class, db.getDb(),
|
||||
SQLiteDatabaseSelectHandler<ScvTx> handler = new SQLiteDatabaseSelectHandler<ScvTx>(ScvTx.class, database,
|
||||
"stream="+scvStream.getId());
|
||||
transactions=new TreeSet<ITx>();
|
||||
try {
|
||||
for(ScvTx scvTx:handler.selectObjects()){
|
||||
transactions.add(new Tx(this, generators.get(scvTx.getGenerator()), scvTx));
|
||||
transactions.add(new Tx(database, this, generators.get(scvTx.getGenerator()), scvTx));
|
||||
}
|
||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||
|
@ -45,4 +45,7 @@ public interface IDatabase {
|
||||
*/
|
||||
public void close(PreparedStatement preparedStatement, Connection connection);
|
||||
|
||||
public void setData(String name, Object value);
|
||||
|
||||
public Object getData(String name);
|
||||
}
|
@ -6,14 +6,18 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SQLiteDatabase implements IDatabase {
|
||||
|
||||
protected String dbFileName;
|
||||
|
||||
protected HashMap<String, Object> props;
|
||||
|
||||
public SQLiteDatabase(String dbFileName) {
|
||||
super();
|
||||
this.dbFileName = dbFileName;
|
||||
props = new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,4 +54,14 @@ public class SQLiteDatabase implements IDatabase {
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(String name, Object value){
|
||||
props.put(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getData(String name){
|
||||
return props.get(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,33 +17,20 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbFactory;
|
||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
import com.minres.scviewer.database.WaveformDb;
|
||||
|
||||
public class DatabaseServicesTest {
|
||||
|
||||
private static CountDownLatch dependencyLatch = new CountDownLatch(3);// 1 = number of dependencies required
|
||||
|
||||
private static List<IWaveformDbFactory> services=new LinkedList<IWaveformDbFactory>();
|
||||
|
||||
public void bind(IWaveformDbFactory factory){
|
||||
services.add(factory);
|
||||
dependencyLatch.countDown();
|
||||
// System.out.println("service added");
|
||||
}
|
||||
|
||||
public void unbind(IWaveformDbFactory factory){
|
||||
services.remove(factory);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Wait for OSGi dependencies
|
||||
try {
|
||||
dependencyLatch.await(10, TimeUnit.SECONDS);
|
||||
// Dependencies fulfilled
|
||||
} catch (InterruptedException ex) {
|
||||
fail("OSGi dependencies unfulfilled");
|
||||
}
|
||||
// Wait for OSGi dependencies
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (WaveformDb.getLoaders().size() == 3) // Dependencies fulfilled
|
||||
return;
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
fail("OSGi dependencies unfulfilled");
|
||||
}
|
||||
|
||||
@After
|
||||
@ -51,48 +38,36 @@ public class DatabaseServicesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVCD() throws URISyntaxException {
|
||||
public void testVCD() throws Exception {
|
||||
File f = new File("inputs/my_db.vcd").getAbsoluteFile();
|
||||
assertTrue(f.exists());
|
||||
IWaveformDb database=null;
|
||||
for(IWaveformDbFactory factory:services){
|
||||
database = factory.createDatabase(f);
|
||||
if(database!=null) break;
|
||||
}
|
||||
IWaveformDb database=new WaveformDb();
|
||||
database.load(f);
|
||||
assertNotNull(database);
|
||||
assertEquals(3, services.size());
|
||||
assertEquals(14, database.getAllWaves().size());
|
||||
assertEquals(2, database.getChildNodes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTxSQLite() throws URISyntaxException {
|
||||
public void testTxSQLite() throws Exception {
|
||||
File f = new File("inputs/my_db.txdb").getAbsoluteFile();
|
||||
assertTrue(f.exists());
|
||||
IWaveformDb database=null;
|
||||
for(IWaveformDbFactory factory:services){
|
||||
database = factory.createDatabase(f);
|
||||
if(database!=null) break;
|
||||
}
|
||||
IWaveformDb database=new WaveformDb();
|
||||
database.load(f);
|
||||
assertNotNull(database);
|
||||
assertEquals(3, services.size());
|
||||
assertEquals(3, database.getAllWaves().size());
|
||||
assertEquals(3, database.getChildNodes().size());
|
||||
assertEquals(1, database.getChildNodes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTxText() throws URISyntaxException {
|
||||
public void testTxText() throws Exception {
|
||||
File f = new File("inputs/my_db.txlog").getAbsoluteFile();
|
||||
assertTrue(f.exists());
|
||||
IWaveformDb database=null;
|
||||
for(IWaveformDbFactory factory:services){
|
||||
database = factory.createDatabase(f);
|
||||
if(database!=null) break;
|
||||
}
|
||||
IWaveformDb database=new WaveformDb();
|
||||
database.load(f);
|
||||
assertNotNull(database);
|
||||
assertEquals(3, services.size());
|
||||
assertEquals(3, database.getAllWaves().size());
|
||||
assertEquals(3, database.getChildNodes().size());
|
||||
assertEquals(1, database.getChildNodes().size());
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="TextDbFactory">
|
||||
<implementation class="com.minres.scviewer.database.text.TextDbFactory"/>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="TextDbLoader">
|
||||
<implementation class="com.minres.scviewer.database.text.TextDbLoader"/>
|
||||
<service>
|
||||
<provide interface="com.minres.scviewer.database.IWaveformDbFactory"/>
|
||||
<provide interface="com.minres.scviewer.database.IWaveformDbLoader"/>
|
||||
</service>
|
||||
</scr:component>
|
||||
|
@ -1,31 +0,0 @@
|
||||
package com.minres.scviewer.database.text
|
||||
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import com.minres.scviewer.database.IWaveformDb
|
||||
import com.minres.scviewer.database.IWaveformDbFactory;
|
||||
|
||||
class TextDbFactory implements IWaveformDbFactory {
|
||||
|
||||
byte[] x = "scv_tr_stream".bytes
|
||||
|
||||
@Override
|
||||
public IWaveformDb createDatabase(File file) {
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
byte[] buffer = new byte[x.size()];
|
||||
def read = fis.read(buffer, 0, x.size());
|
||||
fis.close();
|
||||
if(read==x.size())
|
||||
for(int i=0; i<x.size(); i++)
|
||||
if(buffer[i]!=x[i]) return null;
|
||||
def db = new TextDb();
|
||||
db.load(file)
|
||||
return db
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -22,28 +22,27 @@ import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.ITxAttributeType;
|
||||
import com.minres.scviewer.database.ITxAttribute;
|
||||
import com.minres.scviewer.database.IWaveform
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.ITxGenerator;
|
||||
import com.minres.scviewer.database.IHierNode;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.EventTime
|
||||
import com.minres.scviewer.database.RelationType
|
||||
|
||||
public class TextDb extends HierNode implements IWaveformDb{
|
||||
public class TextDbLoader implements IWaveformDbLoader{
|
||||
|
||||
private EventTime maxTime;
|
||||
|
||||
|
||||
IWaveformDb db;
|
||||
|
||||
def streams = []
|
||||
|
||||
def relationTypes=[:]
|
||||
|
||||
public TextDb() {
|
||||
super("TextDb");
|
||||
}
|
||||
|
||||
public String getFullName() {
|
||||
return getName();
|
||||
public TextDbLoader() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,16 +50,9 @@ public class TextDb extends HierNode implements IWaveformDb{
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
public ITxStream getStreamByName(String name){
|
||||
streams.find{ITxStream stream-> stream.fullName == name }
|
||||
}
|
||||
|
||||
public List<ITxStream> getAllWaves() {
|
||||
return new LinkedList<ITxStream>(streams);
|
||||
}
|
||||
|
||||
public List<IHierNode> getChildNodes() {
|
||||
return childs.sort{it.name};
|
||||
@Override
|
||||
public List<IWaveform> getAllWaves() {
|
||||
return new LinkedList<IWaveform>(streams);
|
||||
}
|
||||
|
||||
public Map<Long, ITxGenerator> getGeneratorsById() {
|
||||
@ -69,14 +61,20 @@ public class TextDb extends HierNode implements IWaveformDb{
|
||||
return res;
|
||||
}
|
||||
|
||||
void clear(){
|
||||
streams = []
|
||||
maxTime=new EventTime(0, "ns")
|
||||
}
|
||||
|
||||
void load(File file) throws InputFormatException {
|
||||
this.name = file.name;
|
||||
static final byte[] x = "scv_tr_stream".bytes
|
||||
|
||||
@Override
|
||||
boolean load(IWaveformDb db, File file) throws Exception {
|
||||
this.db=db
|
||||
FileInputStream fis = new FileInputStream(file)
|
||||
byte[] buffer = new byte[x.size()]
|
||||
def readCnt = fis.read(buffer, 0, x.size())
|
||||
fis.close()
|
||||
if(readCnt==x.size())
|
||||
for(int i=0; i<x.size(); i++)
|
||||
if(buffer[i]!=x[i]) return false
|
||||
parseInput(file)
|
||||
return true
|
||||
}
|
||||
|
||||
private def parseInput(File input){
|
||||
@ -96,7 +94,7 @@ public class TextDb extends HierNode implements IWaveformDb{
|
||||
case "end_attribute":
|
||||
if ((matcher = line =~ /^scv_tr_stream\s+\(ID (\d+),\s+name\s+"([^"]+)",\s+kind\s+"([^"]+)"\)$/)) {
|
||||
def id = Integer.parseInt(matcher[0][1])
|
||||
def stream = new TxStream(id, this, matcher[0][2], matcher[0][3])
|
||||
def stream = new TxStream(db, id, matcher[0][2], matcher[0][3])
|
||||
streams<<stream
|
||||
streamsById[id]=stream
|
||||
} else if ((matcher = line =~ /^scv_tr_generator\s+\(ID\s+(\d+),\s+name\s+"([^"]+)",\s+scv_tr_stream\s+(\d+),$/)) {
|
||||
@ -117,7 +115,7 @@ public class TextDb extends HierNode implements IWaveformDb{
|
||||
case "tx_begin"://matcher = line =~ /^tx_begin\s+(\d+)\s+(\d+)\s+(\d+)\s+([munpf]?s)/
|
||||
def id = Integer.parseInt(tokens[1])
|
||||
TxGenerator gen=generatorsById[Integer.parseInt(tokens[2])]
|
||||
transaction = new Tx(id, gen.stream, gen, new EventTime(Integer.parseInt(tokens[3]), tokens[4]))
|
||||
transaction = new Tx(id, gen.stream, gen, new EventTime(Integer.parseInt(tokens[3]), EventTime.Unit.fromString(tokens[4])))
|
||||
gen.transactions << transaction
|
||||
transactionsById[id]= transaction
|
||||
gen.begin_attrs_idx=0;
|
||||
@ -128,7 +126,7 @@ public class TextDb extends HierNode implements IWaveformDb{
|
||||
def id = Integer.parseInt(tokens[1])
|
||||
transaction = transactionsById[id]
|
||||
assert Integer.parseInt(tokens[2])==transaction.generator.id
|
||||
transaction.endTime = new EventTime(Integer.parseInt(tokens[3]), tokens[4])
|
||||
transaction.endTime = new EventTime(Integer.parseInt(tokens[3]), EventTime.Unit.fromString(tokens[4]))
|
||||
transaction.generator.end_attrs_idx=0;
|
||||
maxTime = maxTime>transaction.endTime?maxTime:transaction.endTime
|
||||
endTransaction=true
|
||||
@ -158,38 +156,6 @@ public class TextDb extends HierNode implements IWaveformDb{
|
||||
|
||||
}
|
||||
}
|
||||
addHierarchyNodes()
|
||||
}
|
||||
|
||||
def addHierarchyNodes(){
|
||||
streams.each{ TxStream stream->
|
||||
def hier = stream.fullName.split(/\./)
|
||||
IHierNode node = this
|
||||
hier.each { name ->
|
||||
def n1 = node.childNodes.find{it.name == name}
|
||||
if(name == hier[-1]){ //leaf
|
||||
if(n1!=null) {
|
||||
if(n1 instanceof HierNode){
|
||||
node.childNodes.remove(n1)
|
||||
stream.childNodes.addAll(n1.childNodes)
|
||||
} else {
|
||||
throw new InputFormatException()
|
||||
}
|
||||
}
|
||||
stream.name=name
|
||||
node.childNodes<<stream
|
||||
node=stream
|
||||
} else { // intermediate
|
||||
if(n1 != null) {
|
||||
node=n1
|
||||
} else {
|
||||
HierNode newNode = new HierNode(name)
|
||||
node.childNodes<<newNode
|
||||
node=newNode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -15,6 +15,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb
|
||||
import com.minres.scviewer.database.ITxGenerator
|
||||
import com.minres.scviewer.database.IHierNode
|
||||
@ -25,7 +26,7 @@ class TxStream extends HierNode implements ITxStream {
|
||||
|
||||
Long id;
|
||||
|
||||
TextDb database
|
||||
IWaveformDb database
|
||||
|
||||
String fullName;
|
||||
|
||||
@ -35,7 +36,7 @@ class TxStream extends HierNode implements ITxStream {
|
||||
|
||||
private TreeSet<Tx> allTransactions;
|
||||
|
||||
TxStream(int id, TextDb db, String name, String kind){
|
||||
TxStream(IWaveformDb db, int id, String name, String kind){
|
||||
super(name)
|
||||
this.id=id
|
||||
this.database=db
|
||||
|
7
com.minres.scviewer.database.vcd/.classpath
Normal file
7
com.minres.scviewer.database.vcd/.classpath
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
1
com.minres.scviewer.database.vcd/.gitignore
vendored
Normal file
1
com.minres.scviewer.database.vcd/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/bin/
|
33
com.minres.scviewer.database.vcd/.project
Normal file
33
com.minres.scviewer.database.vcd/.project
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.minres.scviewer.database.vcd</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ds.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
@ -0,0 +1,3 @@
|
||||
eclipse.preferences.version=1
|
||||
pluginProject.extensions=false
|
||||
resolve.requirebundle=false
|
13
com.minres.scviewer.database.vcd/META-INF/MANIFEST.MF
Normal file
13
com.minres.scviewer.database.vcd/META-INF/MANIFEST.MF
Normal file
@ -0,0 +1,13 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Vcd
|
||||
Bundle-SymbolicName: com.minres.scviewer.database.vcd
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Vendor: MINRES Technologies GmbH
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Require-Bundle: com.minres.scviewer.database;bundle-version="1.0.0",
|
||||
org.eclipse.equinox.util;bundle-version="1.0.500",
|
||||
org.eclipse.equinox.ds;bundle-version="1.4.200",
|
||||
org.eclipse.osgi.services;bundle-version="3.4.0"
|
||||
Service-Component: OSGI-INF/component.xml
|
||||
Bundle-ActivationPolicy: lazy
|
7
com.minres.scviewer.database.vcd/OSGI-INF/component.xml
Normal file
7
com.minres.scviewer.database.vcd/OSGI-INF/component.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="VCDDbLoader">
|
||||
<implementation class="com.minres.scviewer.database.vcd.VCDDbLoader"/>
|
||||
<service>
|
||||
<provide interface="com.minres.scviewer.database.IWaveformDbLoader"/>
|
||||
</service>
|
||||
</scr:component>
|
4
com.minres.scviewer.database.vcd/build.properties
Normal file
4
com.minres.scviewer.database.vcd/build.properties
Normal file
@ -0,0 +1,4 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
@ -18,6 +18,7 @@ import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IHierNode;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.SignalChange;
|
||||
|
||||
@ -25,19 +26,19 @@ import com.minres.scviewer.database.SignalChange;
|
||||
/**
|
||||
* The Class VCDDb.
|
||||
*/
|
||||
public class VCDDb extends HierNode implements IWaveformDb, IVCDDatabaseBuilder {
|
||||
public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
||||
|
||||
|
||||
private static final EventTime.Unit TIME_RES = EventTime.Unit.PS;
|
||||
|
||||
private IWaveformDb db;
|
||||
|
||||
/** The module stack. */
|
||||
private Stack<String> moduleStack;
|
||||
|
||||
/** The signals. */
|
||||
private List<IWaveform> signals;
|
||||
|
||||
private HashMap<String, IWaveform> waveformLookup;
|
||||
|
||||
private long maxTime;
|
||||
|
||||
/**
|
||||
@ -45,28 +46,29 @@ public class VCDDb extends HierNode implements IWaveformDb, IVCDDatabaseBuilder
|
||||
*
|
||||
* @param netName the net name
|
||||
*/
|
||||
public VCDDb() {
|
||||
super("VCDDb");
|
||||
signals = new Vector<IWaveform>();
|
||||
waveformLookup = new HashMap<String, IWaveform>();
|
||||
public VCDDbLoader() {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.minres.scviewer.database.ITrDb#getStreamByName(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public IWaveform getStreamByName(String name) {
|
||||
return waveformLookup.get(name);
|
||||
}
|
||||
private byte[] x = "$date".getBytes();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.minres.scviewer.database.ITrDb#load(java.io.File)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void load(File inp) throws Exception {
|
||||
public boolean load(IWaveformDb db, File file) throws Exception {
|
||||
this.db=db;
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
byte[] buffer = new byte[x.length];
|
||||
int read = fis.read(buffer, 0, x.length);
|
||||
fis.close();
|
||||
if (read == x.length)
|
||||
for (int i = 0; i < x.length; i++)
|
||||
if (buffer[i] != x[i])
|
||||
return false;
|
||||
|
||||
signals = new Vector<IWaveform>();
|
||||
moduleStack= new Stack<String>();
|
||||
boolean res = new VCDFileParser(false).load(new FileInputStream(inp), this);
|
||||
boolean res = new VCDFileParser(false).load(new FileInputStream(file), this);
|
||||
moduleStack=null;
|
||||
if(!res) throw new InputFormatException();
|
||||
EventTime lastTime=new EventTime(maxTime, TIME_RES);
|
||||
@ -78,15 +80,7 @@ public class VCDDb extends HierNode implements IWaveformDb, IVCDDatabaseBuilder
|
||||
((ISignal<ISignalChange>)signal).getSignalChanges().add(lastChange);
|
||||
}
|
||||
}
|
||||
buildHierarchyNodes();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.minres.scviewer.database.ITrDb#clear()
|
||||
*/
|
||||
@Override
|
||||
public void clear() {
|
||||
signals.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@ -133,10 +127,10 @@ public class VCDDb extends HierNode implements IWaveformDb, IVCDDatabaseBuilder
|
||||
int id = signals.size();
|
||||
VCDSignal<? extends ISignalChange> signal;
|
||||
if(width==1){
|
||||
signal = i<0 ? new VCDSignal<ISignalChangeSingle>(id, netName) :
|
||||
signal = i<0 ? new VCDSignal<ISignalChangeSingle>(db, id, netName) :
|
||||
new VCDSignal<ISignalChangeSingle>(signals.get(i), id, netName);
|
||||
} else {
|
||||
signal = i<0 ? new VCDSignal<ISignalChangeMulti>(id, netName, width) :
|
||||
signal = i<0 ? new VCDSignal<ISignalChangeMulti>(db, id, netName, width) :
|
||||
new VCDSignal<ISignalChangeMulti>(signals.get(i), id, netName);
|
||||
};
|
||||
signals.add(signal);
|
||||
@ -146,6 +140,7 @@ public class VCDDb extends HierNode implements IWaveformDb, IVCDDatabaseBuilder
|
||||
/* (non-Javadoc)
|
||||
* @see com.minres.scviewer.database.vcd.ITraceBuilder#getNetWidth(int)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public int getNetWidth(int intValue) {
|
||||
VCDSignal<? extends ISignalChange> signal = (VCDSignal<? extends ISignalChange>) signals.get(intValue);
|
||||
@ -170,43 +165,4 @@ public class VCDDb extends HierNode implements IWaveformDb, IVCDDatabaseBuilder
|
||||
maxTime= Math.max(maxTime, fCurrentTime);
|
||||
}
|
||||
|
||||
private void buildHierarchyNodes() throws InputFormatException{
|
||||
for(IWaveform stream:getAllWaves()){
|
||||
waveformLookup.put(stream.getFullName(), stream);
|
||||
String[] hier = stream.getFullName().split("\\.");
|
||||
IHierNode node = this;
|
||||
for(String name:hier){
|
||||
IHierNode n1 = null;
|
||||
for (IHierNode n : node.getChildNodes()) {
|
||||
if (n.getName().equals(name)) {
|
||||
n1=n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(name == hier[hier.length-1]){ //leaf
|
||||
if(n1!=null) {
|
||||
if(n1 instanceof HierNode){
|
||||
node.getChildNodes().remove(n1);
|
||||
stream.getChildNodes().addAll(n1.getChildNodes());
|
||||
} else {
|
||||
throw new InputFormatException();
|
||||
}
|
||||
}
|
||||
stream.setName(name);
|
||||
node.getChildNodes().add(stream);
|
||||
node=stream;
|
||||
} else { // intermediate
|
||||
if(n1 != null) {
|
||||
node=n1;
|
||||
} else {
|
||||
HierNode newNode = new HierNode(name);
|
||||
node.getChildNodes().add(newNode);
|
||||
node=newNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package com.minres.scviewer.database.vcd;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.NavigableSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
@ -8,8 +7,8 @@ import com.minres.scviewer.database.EventTime;
|
||||
import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.ISignal;
|
||||
import com.minres.scviewer.database.ISignalChange;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.SignalChange;
|
||||
|
||||
public class VCDSignal<T extends ISignalChange> extends HierNode implements ISignal<T> {
|
||||
@ -22,20 +21,21 @@ public class VCDSignal<T extends ISignalChange> extends HierNode implements ISig
|
||||
|
||||
private final int width;
|
||||
|
||||
private VCDDb db;
|
||||
private IWaveformDb db;
|
||||
|
||||
TreeSet<ISignalChange> values;
|
||||
|
||||
public VCDSignal(String name) {
|
||||
this(0, name, 1);
|
||||
public VCDSignal(IWaveformDb db, String name) {
|
||||
this(db, 0, name, 1);
|
||||
}
|
||||
|
||||
public VCDSignal(int id, String name) {
|
||||
this(id,name,1);
|
||||
public VCDSignal(IWaveformDb db, int id, String name) {
|
||||
this(db, id,name,1);
|
||||
}
|
||||
|
||||
public VCDSignal(int id, String name, int width) {
|
||||
public VCDSignal(IWaveformDb db, int id, String name, int width) {
|
||||
super(name);
|
||||
this.db=db;
|
||||
fullName=name;
|
||||
this.id=id;
|
||||
this.width=width;
|
||||
@ -50,6 +50,7 @@ public class VCDSignal<T extends ISignalChange> extends HierNode implements ISig
|
||||
assert(other instanceof VCDSignal<?>);
|
||||
this.width=((VCDSignal<? extends ISignalChange>)other).width;
|
||||
this.values=((VCDSignal<T>)other).values;
|
||||
this.db=other.getDb();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -89,6 +90,7 @@ public class VCDSignal<T extends ISignalChange> extends HierNode implements ISig
|
||||
return values;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T getSignalChangeByTime(EventTime time) {
|
||||
return (T) values.floor(new SignalChange(time));
|
@ -5,7 +5,6 @@ Bundle-SymbolicName: com.minres.scviewer.database
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Vendor: MINRES Technologies GmbH
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Export-Package: com.minres.scviewer.database,
|
||||
com.minres.scviewer.database.vcd
|
||||
Service-Component: OSGI-INF/component.xml
|
||||
Export-Package: com.minres.scviewer.database
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Service-Component: OSGI-INF/component.xml
|
||||
|
@ -1,7 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="VCDDbFactory">
|
||||
<implementation class="com.minres.scviewer.database.vcd.VCDDbFactory"/>
|
||||
<service>
|
||||
<provide interface="com.minres.scviewer.database.IWaveformDbFactory"/>
|
||||
</service>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.minres.scviewer.database">
|
||||
<implementation class="com.minres.scviewer.database.WaveformDb"/>
|
||||
<reference bind="bind" cardinality="0..n" interface="com.minres.scviewer.database.IWaveformDbLoader" name="IWaveformDbLoader" policy="dynamic" unbind="unbind"/>
|
||||
</scr:component>
|
||||
|
@ -1,5 +1,6 @@
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
OSGI-INF/component.xml,\
|
||||
OSGI-INF/component.xml
|
||||
source.. = src/
|
||||
|
@ -28,7 +28,13 @@ public class EventTime implements Comparable<EventTime>{
|
||||
}
|
||||
}
|
||||
|
||||
static final double[] scales = {1,1000.0,1000000.0,1000000000.0,1000000000000.0};
|
||||
static final double[] scales = {
|
||||
1,
|
||||
1000.0,
|
||||
1000000.0,
|
||||
1000000000.0,
|
||||
1000000000000.0,
|
||||
1000000000000000.0};
|
||||
|
||||
public static final EventTime ZERO = new EventTime(0L);
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.minres.scviewer.database;
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class HierNode implements IHierNode {
|
||||
@ -10,19 +12,29 @@ public class HierNode implements IHierNode {
|
||||
|
||||
protected ArrayList<IHierNode> childs;
|
||||
|
||||
public HierNode(String name) {
|
||||
this.name=name;
|
||||
protected PropertyChangeSupport pcs;
|
||||
|
||||
public HierNode() {
|
||||
childs = new ArrayList<IHierNode>();
|
||||
pcs=new PropertyChangeSupport(this);
|
||||
}
|
||||
|
||||
public HierNode(String name) {
|
||||
this();
|
||||
this.name=name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
pcs.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
pcs.removePropertyChangeListener(l);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getFullName() {
|
||||
return name;
|
||||
@ -43,4 +55,9 @@ public class HierNode implements IHierNode {
|
||||
return childs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IHierNode o) {
|
||||
return name.compareTo(o.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ package com.minres.scviewer.database;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.List;
|
||||
|
||||
public interface IHierNode {
|
||||
public interface IHierNode extends Comparable<IHierNode>{
|
||||
|
||||
/**
|
||||
* Attach a non-null PropertyChangeListener to this object.
|
||||
|
@ -22,7 +22,7 @@ public interface IWaveformDb extends IHierNode {
|
||||
|
||||
public List<IWaveform> getAllWaves();
|
||||
|
||||
public void load(File inp) throws Exception;
|
||||
public boolean load(File inp) throws Exception;
|
||||
|
||||
public void clear();
|
||||
|
||||
|
@ -1,9 +0,0 @@
|
||||
package com.minres.scviewer.database;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public interface IWaveformDbFactory {
|
||||
|
||||
IWaveformDb createDatabase(File file);
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.minres.scviewer.database;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public interface IWaveformDbLoader {
|
||||
|
||||
public boolean load(IWaveformDb db, File inp) throws Exception;
|
||||
|
||||
public EventTime getMaxTime();
|
||||
|
||||
public List<IWaveform> getAllWaves() ;
|
||||
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
package com.minres.scviewer.database;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class WaveformDb extends HierNode implements IWaveformDb {
|
||||
|
||||
private static List<IWaveformDbLoader> loaders=new LinkedList<IWaveformDbLoader>();
|
||||
|
||||
private List<IHierNode> childNodes;
|
||||
|
||||
private Map<String, IWaveform> waveforms;
|
||||
|
||||
private EventTime maxTime;
|
||||
|
||||
|
||||
public void bind(IWaveformDbLoader loader){
|
||||
loaders.add(loader);
|
||||
}
|
||||
|
||||
public void unbind(IWaveformDbLoader loader){
|
||||
loaders.remove(loader);
|
||||
}
|
||||
|
||||
|
||||
public static List<IWaveformDbLoader> getLoaders() {
|
||||
return Collections.unmodifiableList(loaders);
|
||||
}
|
||||
|
||||
public WaveformDb() {
|
||||
super();
|
||||
waveforms = new HashMap<String, IWaveform>();
|
||||
maxTime=EventTime.ZERO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventTime getMaxTime() {
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveform getStreamByName(String name) {
|
||||
return waveforms.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IWaveform> getAllWaves() {
|
||||
return new ArrayList<IWaveform>(waveforms.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean load(File inp) throws Exception {
|
||||
for(IWaveformDbLoader loader:loaders){
|
||||
if(loader.load(this, inp)){
|
||||
for(IWaveform w:loader.getAllWaves())
|
||||
waveforms.put(w.getFullName(),w);
|
||||
buildHierarchyNodes() ;
|
||||
if(name==null) name=getFileBasename(inp.getName());
|
||||
pcs.firePropertyChange("WAVEFORMS", null, waveforms);
|
||||
pcs.firePropertyChange("CHILDS", null, childNodes);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static String getFileBasename(String f) {
|
||||
String ext = "";
|
||||
int i = f.lastIndexOf('.');
|
||||
if (i > 0 && i < f.length() - 1) {
|
||||
ext = f.substring(0, i);
|
||||
}
|
||||
return ext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
waveforms.clear();
|
||||
childNodes.clear();
|
||||
}
|
||||
|
||||
private void buildHierarchyNodes() throws InputFormatException{
|
||||
childNodes= new ArrayList<IHierNode>();
|
||||
for(IWaveform stream:getAllWaves()){
|
||||
updateMaxTime(stream);
|
||||
String[] hier = stream.getFullName().split("\\.");
|
||||
IHierNode node = this;
|
||||
for(String name:hier){
|
||||
IHierNode n1 = null;
|
||||
for (IHierNode n : node.getChildNodes()) {
|
||||
if (n.getName().equals(name)) {
|
||||
n1=n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(name == hier[hier.length-1]){ //leaf
|
||||
if(n1!=null) {
|
||||
if(n1 instanceof HierNode){
|
||||
node.getChildNodes().remove(n1);
|
||||
stream.getChildNodes().addAll(n1.getChildNodes());
|
||||
Collections.sort(stream.getChildNodes());
|
||||
} else {
|
||||
throw new InputFormatException();
|
||||
}
|
||||
}
|
||||
stream.setName(name);
|
||||
node.getChildNodes().add(stream);
|
||||
Collections.sort(node.getChildNodes());
|
||||
node=stream;
|
||||
} else { // intermediate
|
||||
if(n1 != null) {
|
||||
node=n1;
|
||||
} else {
|
||||
HierNode newNode = new HierNode(name);
|
||||
node.getChildNodes().add(newNode);
|
||||
Collections.sort(node.getChildNodes());
|
||||
node=newNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMaxTime(IWaveform stream) {
|
||||
EventTime last=null;
|
||||
if(stream instanceof ITxStream){
|
||||
last=((ITxStream)stream).getTransactions().last().getEndTime();
|
||||
} else if(stream instanceof ISignal<?>){
|
||||
last=((ISignal<ISignalChange>)stream).getSignalChanges().last().getTime();
|
||||
}
|
||||
if(last.getValue()>maxTime.getValue())
|
||||
maxTime=last;
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.minres.scviewer.database.vcd;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbFactory;
|
||||
|
||||
public class VCDDbFactory implements IWaveformDbFactory {
|
||||
|
||||
private byte[] x = "$date".getBytes();
|
||||
|
||||
public VCDDbFactory(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveformDb createDatabase(File file) {
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
byte[] buffer = new byte[x.length];
|
||||
int read = fis.read(buffer, 0, x.length);
|
||||
fis.close();
|
||||
if (read == x.length)
|
||||
for (int i = 0; i < x.length; i++)
|
||||
if (buffer[i] != x[i])
|
||||
return null;
|
||||
VCDDb db = new VCDDb();
|
||||
db.load(file);
|
||||
return db;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,8 @@ Bundle-SymbolicName: com.minres.scviewer.ui;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Activator: com.minres.scviewer.ui.TxEditorPlugin
|
||||
Bundle-Vendor: MINRES Technologies GmbH
|
||||
Require-Bundle: org.eclipse.core.runtime,
|
||||
Require-Bundle: com.minres.scviewer.database;bundle-version="1.0.0",
|
||||
org.eclipse.core.runtime,
|
||||
org.eclipse.core.resources,
|
||||
org.eclipse.jface.text,
|
||||
org.eclipse.ui,
|
||||
@ -14,9 +15,8 @@ Require-Bundle: org.eclipse.core.runtime,
|
||||
org.eclipse.ui.views.properties.tabbed,
|
||||
org.eclipse.swt,
|
||||
org.eclipse.osgi,
|
||||
com.minres.scviewer.database;bundle-version="1.0.0"
|
||||
org.eclipse.core.expressions;bundle-version="3.4.600"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Import-Package: org.eclipse.ui.views.contentoutline
|
||||
Bundle-ClassPath: .,
|
||||
swing2swt.jar
|
||||
|
56
com.minres.scviewer.ui/SilkCompanion1.txt
Normal file
56
com.minres.scviewer.ui/SilkCompanion1.txt
Normal file
@ -0,0 +1,56 @@
|
||||
Silk companion icon set #1 - "More Silk!"
|
||||
Last updated: 19 November 2007
|
||||
|
||||
_________________________________________
|
||||
Damien Guard
|
||||
http://www.damieng.com/icons/silkcompanion
|
||||
_________________________________________
|
||||
|
||||
This work is licensed under a
|
||||
Creative Commons Attribution 2.5 License.
|
||||
[ http://creativecommons.org/licenses/by/2.5/ ]
|
||||
|
||||
The FamFamFam Silk icon set is a very large,
|
||||
consistent set of well-drawn icons that has
|
||||
proven to be popular with both applications
|
||||
and web sites.
|
||||
|
||||
On a number of occasions I have found myself
|
||||
wanting more icons in the same style. This
|
||||
companion set represents what I needed but also
|
||||
what I felt like adding.
|
||||
|
||||
Some are new icons in the same style, some are
|
||||
alternative sizes/colours of the existing icons
|
||||
and some are new compositions of the elements.
|
||||
|
||||
Any questions about this companion set please
|
||||
contact damieng@gmail.com.
|
||||
|
||||
|
||||
|
||||
The Original Silk readme this work is based upon:
|
||||
|
||||
|
||||
Silk icon set 1.3
|
||||
|
||||
_________________________________________
|
||||
Mark James
|
||||
http://www.famfamfam.com/lab/icons/silk/
|
||||
_________________________________________
|
||||
|
||||
This work is licensed under a
|
||||
Creative Commons Attribution 2.5 License.
|
||||
[ http://creativecommons.org/licenses/by/2.5/ ]
|
||||
|
||||
This means you may use it for any purpose,
|
||||
and make any changes you like.
|
||||
All I ask is that you include a link back
|
||||
to this page in your credits.
|
||||
|
||||
Are you using this icon set? Send me an email
|
||||
(including a link or picture if available) to
|
||||
mjames@gmail.com
|
||||
|
||||
Any other questions about this icon set please
|
||||
contact mjames@gmail.com
|
@ -107,5 +107,104 @@
|
||||
id="com.minres.scviewer.ui.TxEditorInputFactory">
|
||||
</factory>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.menus">
|
||||
<menuContribution
|
||||
allPopups="false"
|
||||
locationURI="toolbar:org.eclipse.ui.main.toolbar">
|
||||
<toolbar
|
||||
id="com.minres.scviewer.ui.toolbar1">
|
||||
<command
|
||||
commandId="com.minres.scviewer.ui.gotoPrev"
|
||||
disabledIcon="res/images/previous-green-d.png"
|
||||
icon="res/images/previous-green.png"
|
||||
label="Prev"
|
||||
style="push"
|
||||
tooltip="Go to previous event">
|
||||
<visibleWhen
|
||||
checkEnabled="false">
|
||||
<reference
|
||||
definitionId="com.minres.scviewer.ui.waveEditorActive">
|
||||
</reference>
|
||||
</visibleWhen>
|
||||
</command>
|
||||
<command
|
||||
commandId="com.minres.scviewer.ui.gotoNext"
|
||||
disabledIcon="res/images/next-green-d.png"
|
||||
icon="res/images/next-green.png"
|
||||
label="Next"
|
||||
style="push"
|
||||
tooltip="Go to next event">
|
||||
<visibleWhen
|
||||
checkEnabled="false">
|
||||
<reference
|
||||
definitionId="com.minres.scviewer.ui.waveEditorActive">
|
||||
</reference>
|
||||
</visibleWhen>
|
||||
</command>
|
||||
</toolbar>
|
||||
</menuContribution>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.commands">
|
||||
<command
|
||||
description="Go to next event"
|
||||
id="com.minres.scviewer.ui.gotoNext"
|
||||
name="Next">
|
||||
</command>
|
||||
<command
|
||||
description="Go to previous event"
|
||||
id="com.minres.scviewer.ui.gotoPrev"
|
||||
name="Prev">
|
||||
</command>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.handlers">
|
||||
<handler
|
||||
class="com.minres.scviewer.ui.handler.GotoNext"
|
||||
commandId="com.minres.scviewer.ui.gotoNext">
|
||||
<enabledWhen>
|
||||
<reference
|
||||
definitionId="com.minres.scviewer.ui.oneElementSeleted">
|
||||
</reference>
|
||||
</enabledWhen>
|
||||
</handler>
|
||||
<handler
|
||||
class="com.minres.scviewer.ui.handler.GotoPrev"
|
||||
commandId="com.minres.scviewer.ui.gotoPrev">
|
||||
<enabledWhen>
|
||||
<reference
|
||||
definitionId="com.minres.scviewer.ui.oneElementSeleted">
|
||||
</reference>
|
||||
</enabledWhen>
|
||||
</handler>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.core.expressions.definitions">
|
||||
<definition
|
||||
id="com.minres.scviewer.ui.oneElementSeleted">
|
||||
<with
|
||||
variable="selection">
|
||||
<and>
|
||||
<count
|
||||
value="1">
|
||||
</count>
|
||||
<iterate
|
||||
operator="or">
|
||||
<instanceof value="com.minres.scviewer.database.ITx"/>
|
||||
</iterate>
|
||||
</and>
|
||||
</with>
|
||||
</definition>
|
||||
<definition
|
||||
id="com.minres.scviewer.ui.waveEditorActive">
|
||||
<with
|
||||
variable="activeEditorId">
|
||||
<equals
|
||||
value="com.minres.scviewer.ui.TxEditorPart">
|
||||
</equals>
|
||||
</with>
|
||||
</definition>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
BIN
com.minres.scviewer.ui/res/images/next-green-d.png
Normal file
BIN
com.minres.scviewer.ui/res/images/next-green-d.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 337 B |
BIN
com.minres.scviewer.ui/res/images/next-green.png
Normal file
BIN
com.minres.scviewer.ui/res/images/next-green.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 519 B |
BIN
com.minres.scviewer.ui/res/images/previous-green-d.png
Normal file
BIN
com.minres.scviewer.ui/res/images/previous-green-d.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 345 B |
BIN
com.minres.scviewer.ui/res/images/previous-green.png
Normal file
BIN
com.minres.scviewer.ui/res/images/previous-green.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 524 B |
@ -12,6 +12,8 @@ package com.minres.scviewer.ui;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
@ -35,8 +37,9 @@ import org.osgi.framework.ServiceReference;
|
||||
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.IWaveformDbFactory;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.WaveformDb;
|
||||
import com.minres.scviewer.ui.handler.GotoDirection;
|
||||
import com.minres.scviewer.ui.swt.TxDisplay;
|
||||
import com.minres.scviewer.ui.views.TxOutlinePage;
|
||||
|
||||
@ -62,21 +65,7 @@ public class TxEditorPart extends EditorPart implements ITabbedPropertySheetPage
|
||||
*/
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
myParent=parent;
|
||||
/** Add handlers for global actions (delete, etc) */
|
||||
// IActionBars actionBars = getEditorSite().getActionBars();
|
||||
// actionBars.setGlobalActionHandler(WAVE_ACTION_ID, new Action() {
|
||||
// @Override
|
||||
// public void runWithEvent(Event event) {
|
||||
// System.out.println("AddToWave with event");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
// System.out.println("AddToWave");
|
||||
// }
|
||||
// });
|
||||
|
||||
myParent=parent;
|
||||
txDisplay = new TxDisplay(parent);
|
||||
if(database!=null) database.addPropertyChangeListener(txDisplay);
|
||||
getSite().setSelectionProvider(txDisplay);
|
||||
@ -98,57 +87,63 @@ public class TxEditorPart extends EditorPart implements ITabbedPropertySheetPage
|
||||
*/
|
||||
protected void setInput(IEditorInput input) {
|
||||
super.setInput(input);
|
||||
if(input instanceof IFileEditorInput){
|
||||
if(!(input instanceof TxEditorInput))
|
||||
super.setInput(new TxEditorInput(((IFileEditorInput)input).getFile()));
|
||||
try {
|
||||
IPath location = ((IFileEditorInput) input).getFile().getLocation();
|
||||
if (location != null)
|
||||
getTrDatabase(location.toFile());
|
||||
setPartName(((IFileEditorInput) input).getFile().getName());
|
||||
} catch (Exception e) {
|
||||
handleLoadException(e);
|
||||
}
|
||||
} else if(input instanceof FileStoreEditorInput){
|
||||
try {
|
||||
//database.load(((FileStoreEditorInput) input).getURI().toURL().openStream());
|
||||
File file=new File(((FileStoreEditorInput) input).getURI().getPath());
|
||||
getTrDatabase(file);
|
||||
setPartName(((FileStoreEditorInput) input).getName());
|
||||
} catch (Exception e) {
|
||||
handleLoadException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void getTrDatabase(File file) {
|
||||
try {
|
||||
BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
|
||||
ServiceReference<?>[] serviceReferences = context.getServiceReferences(IWaveformDbFactory.class.getName(), null);
|
||||
if(serviceReferences!=null){
|
||||
for(ServiceReference<?> serviceReference:serviceReferences){
|
||||
database = ((IWaveformDbFactory) context.getService(serviceReference)).createDatabase(file);
|
||||
if(database!=null){
|
||||
if(txDisplay !=null) database.addPropertyChangeListener(txDisplay);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(input instanceof IFileEditorInput){
|
||||
if(!(input instanceof TxEditorInput))
|
||||
super.setInput(new TxEditorInput(((IFileEditorInput)input).getFile()));
|
||||
IPath location = ((IFileEditorInput) input).getFile().getLocation();
|
||||
if (location != null) loadDatabases(location.toFile());
|
||||
} else if(input instanceof FileStoreEditorInput){
|
||||
File file=new File(((FileStoreEditorInput) input).getURI().getPath());
|
||||
loadDatabases(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
handleLoadException(e);
|
||||
}
|
||||
MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
|
||||
"Error loading database", "Could not find an usable and applicable database loader implementation");
|
||||
database=null;
|
||||
// if(TxEditorPlugin.getDefault().getTransactionDbFactory()!=null){
|
||||
// database = TxEditorPlugin.getDefault().getTransactionDbFactory().createDatabase();
|
||||
// if(txDisplay !=null) database.addPropertyChangeListener(txDisplay);
|
||||
// } else {
|
||||
// MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
|
||||
// "Error loading database", "Could not find database loader implementation");
|
||||
// database=null;
|
||||
// }
|
||||
if(database!=null) setPartName(database.getName());
|
||||
}
|
||||
|
||||
protected void loadDatabases(File file) throws Exception {
|
||||
database=new WaveformDb();
|
||||
if(txDisplay !=null) database.addPropertyChangeListener(txDisplay);
|
||||
if(database.load(file)){
|
||||
String ext = getFileExtension(file.getName());
|
||||
if("vcd".equals(ext.toLowerCase())){
|
||||
File txFile = new File(renameFileExtension(file.getCanonicalPath(), "txdb"));
|
||||
if(txFile.exists() && database.load(txFile)) return;
|
||||
txFile = new File(renameFileExtension(file.getCanonicalPath(), "txlog"));
|
||||
if(txFile.exists()) database.load(txFile);
|
||||
} else if("txdb".equals(ext.toLowerCase()) || "txlog".equals(ext.toLowerCase())){
|
||||
File txFile = new File(renameFileExtension(file.getCanonicalPath(), "vcd"));
|
||||
if(txFile.exists()) database.load(txFile);
|
||||
}
|
||||
} else {
|
||||
MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
|
||||
"Error loading database", "Could not find an usable and applicable database loader implementation");
|
||||
database=null;
|
||||
}
|
||||
}
|
||||
|
||||
protected static String renameFileExtension(String source, String newExt) {
|
||||
String target;
|
||||
String currentExt = getFileExtension(source);
|
||||
if (currentExt.equals("")){
|
||||
target=source+"."+newExt;
|
||||
} else {
|
||||
target=source.replaceFirst(Pattern.quote("."+currentExt)+"$", Matcher.quoteReplacement("."+newExt));
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
protected static String getFileExtension(String f) {
|
||||
String ext = "";
|
||||
int i = f.lastIndexOf('.');
|
||||
if (i > 0 && i < f.length() - 1) {
|
||||
ext = f.substring(i + 1);
|
||||
}
|
||||
return ext;
|
||||
}
|
||||
|
||||
private void handleLoadException(Exception e) {
|
||||
MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
|
||||
"Error loading database", e.getMessage());
|
||||
@ -249,4 +244,8 @@ public class TxEditorPart extends EditorPart implements ITabbedPropertySheetPage
|
||||
return getSite().getId();
|
||||
}
|
||||
|
||||
public void moveSelection(GotoDirection next) {
|
||||
txDisplay.moveSelection( next);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,8 +24,6 @@ import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.eclipse.wb.swt.SWTResourceManager;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
import com.minres.scviewer.database.IWaveformDbFactory;
|
||||
|
||||
/**
|
||||
* The activator class controls the plug-in life cycle
|
||||
*/
|
||||
|
@ -0,0 +1,3 @@
|
||||
package com.minres.scviewer.ui.handler;
|
||||
|
||||
public enum GotoDirection {PREV, NEXT}
|
@ -0,0 +1,23 @@
|
||||
package com.minres.scviewer.ui.handler;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import com.minres.scviewer.ui.TxEditorPart;
|
||||
|
||||
public class GotoNext extends AbstractHandler {
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IEditorPart editor = HandlerUtil.getActiveEditor(event);
|
||||
if(editor instanceof TxEditorPart){
|
||||
((TxEditorPart)editor).moveSelection(GotoDirection.NEXT);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.minres.scviewer.ui.handler;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import com.minres.scviewer.ui.TxEditorPart;
|
||||
|
||||
public class GotoPrev extends AbstractHandler {
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IEditorPart editor = HandlerUtil.getActiveEditor(event);
|
||||
if(editor instanceof TxEditorPart){
|
||||
((TxEditorPart)editor).moveSelection(GotoDirection.PREV);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.minres.scviewer.ui.swt;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.NavigableSet;
|
||||
import java.util.Vector;
|
||||
|
||||
|
@ -56,6 +56,7 @@ import com.minres.scviewer.database.ISignalChange;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.ui.handler.GotoDirection;
|
||||
|
||||
public class TxDisplay implements PropertyChangeListener, ISelectionProvider, MouseListener{
|
||||
|
||||
@ -63,7 +64,7 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
|
||||
private static final String NAMEWIDGET = "NAMEWIDGET";
|
||||
private static final String WAVEFORM = "WAVEFORM";
|
||||
private ListenerList listeners = new ListenerList();
|
||||
private ITxStream currentStreamSelection;
|
||||
private IWaveform currentStreamSelection;
|
||||
private ITx currentSelection;
|
||||
private ScrolledComposite valueListScrolled;
|
||||
private ScrolledComposite nameListScrolled;
|
||||
@ -416,4 +417,16 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
|
||||
return res;
|
||||
}
|
||||
|
||||
public void moveSelection(GotoDirection direction) {
|
||||
if(currentStreamSelection instanceof ITxStream){
|
||||
ITx transaction=null;
|
||||
if(direction==GotoDirection.NEXT)
|
||||
transaction = ((ITxStream)currentStreamSelection).getTransactions().higher(currentSelection);
|
||||
else if(direction==GotoDirection.PREV)
|
||||
transaction = ((ITxStream)currentStreamSelection).getTransactions().lower(currentSelection);
|
||||
if(transaction!=null)
|
||||
setSelection(new StructuredSelection(transaction));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ package com.minres.scviewer.ui.views.sections;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
@ -49,9 +48,8 @@ import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
|
||||
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
|
||||
|
||||
import com.minres.scviewer.database.ITxRelation;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.ITxRelation;
|
||||
|
||||
public class RelatedProperty extends AbstractPropertySection implements ISelectionProvider, ISelectionChangedListener {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user