mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-19 01:44:44 -04:00
Preparartion of Traces
This commit is contained in:
parent
4240b60737
commit
1056dc84c6
@ -103,6 +103,8 @@ public class Model {
|
|||||||
if (!isInitialized)
|
if (!isInitialized)
|
||||||
throw new RuntimeException("notInitialized!");
|
throw new RuntimeException("notInitialized!");
|
||||||
|
|
||||||
|
fireEvent(ModelEvent.STEP);
|
||||||
|
|
||||||
version++;
|
version++;
|
||||||
// swap lists
|
// swap lists
|
||||||
ArrayList<Node> nl = nodesToUpdateNext;
|
ArrayList<Node> nl = nodesToUpdateNext;
|
||||||
@ -149,7 +151,7 @@ public class Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeObserver(ModelStateObserver observer) {
|
public void removeObserver(ModelStateObserver observer) {
|
||||||
observers.add(observer);
|
observers.remove(observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireEvent(ModelEvent event) {
|
private void fireEvent(ModelEvent event) {
|
||||||
|
@ -10,7 +10,9 @@ import java.util.ArrayList;
|
|||||||
public class ModelEvent {
|
public class ModelEvent {
|
||||||
|
|
||||||
|
|
||||||
public enum Event {STARTED, STOPPED, FETCHCLOCK}
|
public static final ModelEvent STEP = new ModelEvent(Event.STEP);
|
||||||
|
|
||||||
|
public enum Event {STARTED, STOPPED, FETCHCLOCK, STEP}
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package de.neemann.digital.gui;
|
|||||||
import de.neemann.digital.gui.components.CircuitComponent;
|
import de.neemann.digital.gui.components.CircuitComponent;
|
||||||
import de.neemann.digital.gui.draw.elements.VisualElement;
|
import de.neemann.digital.gui.draw.elements.VisualElement;
|
||||||
import de.neemann.digital.gui.draw.graphics.Vector;
|
import de.neemann.digital.gui.draw.graphics.Vector;
|
||||||
import de.neemann.digital.gui.draw.library.PartLibrary;
|
import de.neemann.digital.gui.draw.library.ElementLibrary;
|
||||||
import de.process.utils.gui.ToolTipAction;
|
import de.process.utils.gui.ToolTipAction;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@ -13,9 +13,9 @@ import java.awt.event.ActionEvent;
|
|||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class LibrarySelector {
|
public class LibrarySelector {
|
||||||
private final PartLibrary library;
|
private final ElementLibrary library;
|
||||||
|
|
||||||
public LibrarySelector(PartLibrary library) {
|
public LibrarySelector(ElementLibrary library) {
|
||||||
this.library = library;
|
this.library = library;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ public class LibrarySelector {
|
|||||||
|
|
||||||
JMenu subMenu = null;
|
JMenu subMenu = null;
|
||||||
String lastPath = null;
|
String lastPath = null;
|
||||||
for (PartLibrary.PartContainer pc : library) {
|
for (ElementLibrary.PartContainer pc : library) {
|
||||||
String path = pc.getTreePath();
|
String path = pc.getTreePath();
|
||||||
if (!path.equals(lastPath)) {
|
if (!path.equals(lastPath)) {
|
||||||
subMenu = new JMenu(path);
|
subMenu = new JMenu(path);
|
||||||
|
@ -15,7 +15,7 @@ import de.neemann.digital.gui.draw.elements.PinException;
|
|||||||
import de.neemann.digital.gui.draw.elements.VisualElement;
|
import de.neemann.digital.gui.draw.elements.VisualElement;
|
||||||
import de.neemann.digital.gui.draw.elements.Wire;
|
import de.neemann.digital.gui.draw.elements.Wire;
|
||||||
import de.neemann.digital.gui.draw.graphics.Vector;
|
import de.neemann.digital.gui.draw.graphics.Vector;
|
||||||
import de.neemann.digital.gui.draw.library.PartLibrary;
|
import de.neemann.digital.gui.draw.library.ElementLibrary;
|
||||||
import de.neemann.digital.gui.draw.model.ModelDescription;
|
import de.neemann.digital.gui.draw.model.ModelDescription;
|
||||||
import de.neemann.digital.gui.draw.shapes.ShapeFactory;
|
import de.neemann.digital.gui.draw.shapes.ShapeFactory;
|
||||||
import de.process.utils.gui.ClosingWindowListener;
|
import de.process.utils.gui.ClosingWindowListener;
|
||||||
@ -38,8 +38,9 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
private static final String MESSAGE = "Digital\n\nA simple simulator for digital circuits.\nWritten bei H.Neemann in 2016";
|
private static final String MESSAGE = "Digital\n\nA simple simulator for digital circuits.\nWritten bei H.Neemann in 2016";
|
||||||
private final CircuitComponent circuitComponent;
|
private final CircuitComponent circuitComponent;
|
||||||
private final ToolTipAction save;
|
private final ToolTipAction save;
|
||||||
private final PartLibrary library = ShapeFactory.getInstance().setLibrary(new PartLibrary());
|
private final ElementLibrary library = ShapeFactory.getInstance().setLibrary(new ElementLibrary());
|
||||||
private final ToolTipAction doStep;
|
private final ToolTipAction doStep;
|
||||||
|
private final JCheckBoxMenuItem traceEnable;
|
||||||
private File filename;
|
private File filename;
|
||||||
private Model model;
|
private Model model;
|
||||||
private ModelDescription modelDescription;
|
private ModelDescription modelDescription;
|
||||||
@ -176,13 +177,15 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
new ErrorMessage("SpeedTestError").addCause(e1).show();
|
new ErrorMessage("SpeedTestError").addCause(e1).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.setToolTip("Runs the Model");
|
}.setToolTip("Performs a speed test by calculating the max. clock frequency.");
|
||||||
|
|
||||||
|
traceEnable = new JCheckBoxMenuItem("Trace");
|
||||||
|
|
||||||
run.add(runModel.createJMenuItem());
|
run.add(runModel.createJMenuItem());
|
||||||
run.add(runModelMicro.createJMenuItem());
|
run.add(runModelMicro.createJMenuItem());
|
||||||
run.add(doStep.createJMenuItem());
|
run.add(doStep.createJMenuItem());
|
||||||
run.add(speedTest.createJMenuItem());
|
run.add(speedTest.createJMenuItem());
|
||||||
|
run.add(traceEnable);
|
||||||
doStep.setEnabled(false);
|
doStep.setEnabled(false);
|
||||||
|
|
||||||
JToolBar toolBar = new JToolBar();
|
JToolBar toolBar = new JToolBar();
|
||||||
@ -228,6 +231,11 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
modelDescription = new ModelDescription(circuitComponent.getCircuit(), library);
|
modelDescription = new ModelDescription(circuitComponent.getCircuit(), library);
|
||||||
model = modelDescription.createModel(true);
|
model = modelDescription.createModel(true);
|
||||||
modelDescription.connectToGui(circuitComponent);
|
modelDescription.connectToGui(circuitComponent);
|
||||||
|
|
||||||
|
if (traceEnable.isSelected()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
model.init();
|
model.init();
|
||||||
} catch (NodeException e) {
|
} catch (NodeException e) {
|
||||||
if (modelDescription != null) {
|
if (modelDescription != null) {
|
||||||
|
58
src/main/java/de/neemann/digital/gui/TraceGenerator.java
Normal file
58
src/main/java/de/neemann/digital/gui/TraceGenerator.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package de.neemann.digital.gui;
|
||||||
|
|
||||||
|
import de.neemann.digital.core.Model;
|
||||||
|
import de.neemann.digital.core.ModelEvent;
|
||||||
|
import de.neemann.digital.core.ModelStateObserver;
|
||||||
|
import de.neemann.digital.core.ObservableValue;
|
||||||
|
import de.neemann.digital.core.element.AttributeKey;
|
||||||
|
import de.neemann.digital.core.io.In;
|
||||||
|
import de.neemann.digital.core.io.Out;
|
||||||
|
import de.neemann.digital.gui.draw.library.ElementLibrary;
|
||||||
|
import de.neemann.digital.gui.draw.model.ModelDescription;
|
||||||
|
import de.neemann.digital.gui.draw.model.ModelEntry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hneemann
|
||||||
|
*/
|
||||||
|
public class TraceGenerator implements ModelStateObserver {
|
||||||
|
|
||||||
|
private final Model model;
|
||||||
|
|
||||||
|
public TraceGenerator(ModelDescription modelDescription, Model model, ElementLibrary library) {
|
||||||
|
this.model = model;
|
||||||
|
for (ModelEntry me : modelDescription) {
|
||||||
|
String name = me.getVisualElement().getElementName();
|
||||||
|
if (library.getElementType(name) == In.DESCRIPTION)
|
||||||
|
register(me);
|
||||||
|
if (library.getElementType(name) == Out.DESCRIPTION)
|
||||||
|
register(me);
|
||||||
|
if (library.getElementType(name) == Out.LEDDESCRIPTION)
|
||||||
|
register(me);
|
||||||
|
if (library.getElementType(name) == Out.PROBEDESCRIPTION)
|
||||||
|
register(me);
|
||||||
|
}
|
||||||
|
model.addObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void register(ModelEntry me) {
|
||||||
|
ObservableValue value = me.getPins().get(0).getValue();
|
||||||
|
String labelName = me.getVisualElement().getElementAttributes().get(AttributeKey.Label);
|
||||||
|
if (value != null && labelName != null && labelName.length() > 0) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleEvent(ModelEvent event) {
|
||||||
|
switch (event.getType()) {
|
||||||
|
case STEP:
|
||||||
|
break;
|
||||||
|
case STOPPED:
|
||||||
|
model.removeObserver(this);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,7 +8,7 @@ import de.neemann.digital.gui.draw.elements.VisualElement;
|
|||||||
import de.neemann.digital.gui.draw.elements.Wire;
|
import de.neemann.digital.gui.draw.elements.Wire;
|
||||||
import de.neemann.digital.gui.draw.graphics.*;
|
import de.neemann.digital.gui.draw.graphics.*;
|
||||||
import de.neemann.digital.gui.draw.graphics.Polygon;
|
import de.neemann.digital.gui.draw.graphics.Polygon;
|
||||||
import de.neemann.digital.gui.draw.library.PartLibrary;
|
import de.neemann.digital.gui.draw.library.ElementLibrary;
|
||||||
import de.neemann.digital.gui.draw.shapes.Drawable;
|
import de.neemann.digital.gui.draw.shapes.Drawable;
|
||||||
import de.neemann.digital.gui.draw.shapes.GenericShape;
|
import de.neemann.digital.gui.draw.shapes.GenericShape;
|
||||||
|
|
||||||
@ -26,13 +26,13 @@ import java.util.ArrayList;
|
|||||||
public class CircuitComponent extends JComponent implements Observer {
|
public class CircuitComponent extends JComponent implements Observer {
|
||||||
|
|
||||||
private static final String delAction = "myDelAction";
|
private static final String delAction = "myDelAction";
|
||||||
private final PartLibrary library;
|
private final ElementLibrary library;
|
||||||
private Circuit circuit;
|
private Circuit circuit;
|
||||||
private Mouse listener;
|
private Mouse listener;
|
||||||
private AffineTransform transform = new AffineTransform();
|
private AffineTransform transform = new AffineTransform();
|
||||||
private Observer manualChangeObserver;
|
private Observer manualChangeObserver;
|
||||||
|
|
||||||
public CircuitComponent(Circuit aCircuit, PartLibrary library) {
|
public CircuitComponent(Circuit aCircuit, ElementLibrary library) {
|
||||||
this.library = library;
|
this.library = library;
|
||||||
setCircuit(aCircuit);
|
setCircuit(aCircuit);
|
||||||
|
|
||||||
|
@ -54,4 +54,12 @@ public class Pins implements Iterable<Pin> {
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return allPins.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pin get(int index) {
|
||||||
|
return allPins.get(index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,12 @@ import java.util.Iterator;
|
|||||||
/**
|
/**
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class PartLibrary implements Iterable<PartLibrary.PartContainer> {
|
public class ElementLibrary implements Iterable<ElementLibrary.PartContainer> {
|
||||||
|
|
||||||
private final HashMap<String, ElementTypeDescription> map = new HashMap<>();
|
private final HashMap<String, ElementTypeDescription> map = new HashMap<>();
|
||||||
private ArrayList<PartContainer> list = new ArrayList<>();
|
private ArrayList<PartContainer> list = new ArrayList<>();
|
||||||
|
|
||||||
public PartLibrary() {
|
public ElementLibrary() {
|
||||||
add(And.DESCRIPTION, "Logic");
|
add(And.DESCRIPTION, "Logic");
|
||||||
add(NAnd.DESCRIPTION, "Logic");
|
add(NAnd.DESCRIPTION, "Logic");
|
||||||
add(Or.DESCRIPTION, "Logic");
|
add(Or.DESCRIPTION, "Logic");
|
||||||
@ -67,10 +67,10 @@ public class PartLibrary implements Iterable<PartLibrary.PartContainer> {
|
|||||||
list.add(new PartContainer(name, treePath));
|
list.add(new PartContainer(name, treePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ElementTypeDescription getElementType(String partName) {
|
public ElementTypeDescription getElementType(String elementName) {
|
||||||
ElementTypeDescription pd = map.get(partName);
|
ElementTypeDescription pd = map.get(elementName);
|
||||||
if (pd == null)
|
if (pd == null)
|
||||||
throw new RuntimeException("element " + partName + " not found");
|
throw new RuntimeException("element " + elementName + " not found");
|
||||||
return pd;
|
return pd;
|
||||||
}
|
}
|
||||||
|
|
@ -1,20 +1,18 @@
|
|||||||
package de.neemann.digital.gui.draw.model;
|
package de.neemann.digital.gui.draw.model;
|
||||||
|
|
||||||
import de.neemann.digital.core.*;
|
import de.neemann.digital.core.*;
|
||||||
|
import de.neemann.digital.core.Observer;
|
||||||
import de.neemann.digital.core.element.Element;
|
import de.neemann.digital.core.element.Element;
|
||||||
import de.neemann.digital.core.element.ElementTypeDescription;
|
import de.neemann.digital.core.element.ElementTypeDescription;
|
||||||
import de.neemann.digital.gui.draw.elements.*;
|
import de.neemann.digital.gui.draw.elements.*;
|
||||||
import de.neemann.digital.gui.draw.library.PartLibrary;
|
import de.neemann.digital.gui.draw.library.ElementLibrary;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class ModelDescription {
|
public class ModelDescription implements Iterable<ModelEntry> {
|
||||||
|
|
||||||
private final NetList netList;
|
private final NetList netList;
|
||||||
private final ArrayList<ModelEntry> entries;
|
private final ArrayList<ModelEntry> entries;
|
||||||
@ -30,7 +28,7 @@ public class ModelDescription {
|
|||||||
* @param library the library
|
* @param library the library
|
||||||
* @throws PinException
|
* @throws PinException
|
||||||
*/
|
*/
|
||||||
public ModelDescription(Circuit circuit, PartLibrary library) throws PinException {
|
public ModelDescription(Circuit circuit, ElementLibrary library) throws PinException {
|
||||||
entries = new ArrayList<>();
|
entries = new ArrayList<>();
|
||||||
netList = new NetList(circuit.getWires());
|
netList = new NetList(circuit.getWires());
|
||||||
for (VisualElement vp : circuit.getParts()) {
|
for (VisualElement vp : circuit.getParts()) {
|
||||||
@ -117,4 +115,9 @@ public class ModelDescription {
|
|||||||
for (Net net : netList)
|
for (Net net : netList)
|
||||||
net.setHighLight(false);
|
net.setHighLight(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<ModelEntry> iterator() {
|
||||||
|
return entries.iterator();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,10 @@ public class ModelEntry {
|
|||||||
visualElement.setState(ioState, guiObserver);
|
visualElement.setState(ioState, guiObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Pins getPins() {
|
||||||
|
return pins;
|
||||||
|
}
|
||||||
|
|
||||||
public Element getElement() {
|
public Element getElement() {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import de.neemann.digital.core.io.Out;
|
|||||||
import de.neemann.digital.core.wiring.Clock;
|
import de.neemann.digital.core.wiring.Clock;
|
||||||
import de.neemann.digital.core.wiring.Delay;
|
import de.neemann.digital.core.wiring.Delay;
|
||||||
import de.neemann.digital.core.wiring.Splitter;
|
import de.neemann.digital.core.wiring.Splitter;
|
||||||
import de.neemann.digital.gui.draw.library.PartLibrary;
|
import de.neemann.digital.gui.draw.library.ElementLibrary;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ public final class ShapeFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, Creator> map = new HashMap<>();
|
public HashMap<String, Creator> map = new HashMap<>();
|
||||||
private PartLibrary library;
|
private ElementLibrary library;
|
||||||
|
|
||||||
private ShapeFactory() {
|
private ShapeFactory() {
|
||||||
map.put(And.DESCRIPTION.getName(), new CreatorSimple("&", And.DESCRIPTION, false));
|
map.put(And.DESCRIPTION.getName(), new CreatorSimple("&", And.DESCRIPTION, false));
|
||||||
@ -61,7 +61,7 @@ public final class ShapeFactory {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PartLibrary setLibrary(PartLibrary library) {
|
public ElementLibrary setLibrary(ElementLibrary library) {
|
||||||
this.library = library;
|
this.library = library;
|
||||||
return library;
|
return library;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user