mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-18 09:24:42 -04:00
Preparartion of Traces
This commit is contained in:
parent
4240b60737
commit
1056dc84c6
@ -103,6 +103,8 @@ public class Model {
|
||||
if (!isInitialized)
|
||||
throw new RuntimeException("notInitialized!");
|
||||
|
||||
fireEvent(ModelEvent.STEP);
|
||||
|
||||
version++;
|
||||
// swap lists
|
||||
ArrayList<Node> nl = nodesToUpdateNext;
|
||||
@ -149,7 +151,7 @@ public class Model {
|
||||
}
|
||||
|
||||
public void removeObserver(ModelStateObserver observer) {
|
||||
observers.add(observer);
|
||||
observers.remove(observer);
|
||||
}
|
||||
|
||||
private void fireEvent(ModelEvent event) {
|
||||
|
@ -10,7 +10,9 @@ import java.util.ArrayList;
|
||||
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.draw.elements.VisualElement;
|
||||
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 javax.swing.*;
|
||||
@ -13,9 +13,9 @@ import java.awt.event.ActionEvent;
|
||||
* @author hneemann
|
||||
*/
|
||||
public class LibrarySelector {
|
||||
private final PartLibrary library;
|
||||
private final ElementLibrary library;
|
||||
|
||||
public LibrarySelector(PartLibrary library) {
|
||||
public LibrarySelector(ElementLibrary library) {
|
||||
this.library = library;
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ public class LibrarySelector {
|
||||
|
||||
JMenu subMenu = null;
|
||||
String lastPath = null;
|
||||
for (PartLibrary.PartContainer pc : library) {
|
||||
for (ElementLibrary.PartContainer pc : library) {
|
||||
String path = pc.getTreePath();
|
||||
if (!path.equals(lastPath)) {
|
||||
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.Wire;
|
||||
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.shapes.ShapeFactory;
|
||||
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 final CircuitComponent circuitComponent;
|
||||
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 JCheckBoxMenuItem traceEnable;
|
||||
private File filename;
|
||||
private Model model;
|
||||
private ModelDescription modelDescription;
|
||||
@ -176,13 +177,15 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
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(runModelMicro.createJMenuItem());
|
||||
run.add(doStep.createJMenuItem());
|
||||
run.add(speedTest.createJMenuItem());
|
||||
run.add(traceEnable);
|
||||
doStep.setEnabled(false);
|
||||
|
||||
JToolBar toolBar = new JToolBar();
|
||||
@ -228,6 +231,11 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
modelDescription = new ModelDescription(circuitComponent.getCircuit(), library);
|
||||
model = modelDescription.createModel(true);
|
||||
modelDescription.connectToGui(circuitComponent);
|
||||
|
||||
if (traceEnable.isSelected()) {
|
||||
|
||||
}
|
||||
|
||||
model.init();
|
||||
} catch (NodeException e) {
|
||||
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.graphics.*;
|
||||
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.GenericShape;
|
||||
|
||||
@ -26,13 +26,13 @@ import java.util.ArrayList;
|
||||
public class CircuitComponent extends JComponent implements Observer {
|
||||
|
||||
private static final String delAction = "myDelAction";
|
||||
private final PartLibrary library;
|
||||
private final ElementLibrary library;
|
||||
private Circuit circuit;
|
||||
private Mouse listener;
|
||||
private AffineTransform transform = new AffineTransform();
|
||||
private Observer manualChangeObserver;
|
||||
|
||||
public CircuitComponent(Circuit aCircuit, PartLibrary library) {
|
||||
public CircuitComponent(Circuit aCircuit, ElementLibrary library) {
|
||||
this.library = library;
|
||||
setCircuit(aCircuit);
|
||||
|
||||
|
@ -54,4 +54,12 @@ public class Pins implements Iterable<Pin> {
|
||||
return true;
|
||||
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
|
||||
*/
|
||||
public class PartLibrary implements Iterable<PartLibrary.PartContainer> {
|
||||
public class ElementLibrary implements Iterable<ElementLibrary.PartContainer> {
|
||||
|
||||
private final HashMap<String, ElementTypeDescription> map = new HashMap<>();
|
||||
private ArrayList<PartContainer> list = new ArrayList<>();
|
||||
|
||||
public PartLibrary() {
|
||||
public ElementLibrary() {
|
||||
add(And.DESCRIPTION, "Logic");
|
||||
add(NAnd.DESCRIPTION, "Logic");
|
||||
add(Or.DESCRIPTION, "Logic");
|
||||
@ -67,10 +67,10 @@ public class PartLibrary implements Iterable<PartLibrary.PartContainer> {
|
||||
list.add(new PartContainer(name, treePath));
|
||||
}
|
||||
|
||||
public ElementTypeDescription getElementType(String partName) {
|
||||
ElementTypeDescription pd = map.get(partName);
|
||||
public ElementTypeDescription getElementType(String elementName) {
|
||||
ElementTypeDescription pd = map.get(elementName);
|
||||
if (pd == null)
|
||||
throw new RuntimeException("element " + partName + " not found");
|
||||
throw new RuntimeException("element " + elementName + " not found");
|
||||
return pd;
|
||||
}
|
||||
|
@ -1,20 +1,18 @@
|
||||
package de.neemann.digital.gui.draw.model;
|
||||
|
||||
import de.neemann.digital.core.*;
|
||||
import de.neemann.digital.core.Observer;
|
||||
import de.neemann.digital.core.element.Element;
|
||||
import de.neemann.digital.core.element.ElementTypeDescription;
|
||||
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.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author hneemann
|
||||
*/
|
||||
public class ModelDescription {
|
||||
public class ModelDescription implements Iterable<ModelEntry> {
|
||||
|
||||
private final NetList netList;
|
||||
private final ArrayList<ModelEntry> entries;
|
||||
@ -30,7 +28,7 @@ public class ModelDescription {
|
||||
* @param library the library
|
||||
* @throws PinException
|
||||
*/
|
||||
public ModelDescription(Circuit circuit, PartLibrary library) throws PinException {
|
||||
public ModelDescription(Circuit circuit, ElementLibrary library) throws PinException {
|
||||
entries = new ArrayList<>();
|
||||
netList = new NetList(circuit.getWires());
|
||||
for (VisualElement vp : circuit.getParts()) {
|
||||
@ -117,4 +115,9 @@ public class ModelDescription {
|
||||
for (Net net : netList)
|
||||
net.setHighLight(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ModelEntry> iterator() {
|
||||
return entries.iterator();
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,10 @@ public class ModelEntry {
|
||||
visualElement.setState(ioState, guiObserver);
|
||||
}
|
||||
|
||||
public Pins getPins() {
|
||||
return pins;
|
||||
}
|
||||
|
||||
public Element getElement() {
|
||||
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.Delay;
|
||||
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;
|
||||
|
||||
@ -32,7 +32,7 @@ public final class ShapeFactory {
|
||||
}
|
||||
|
||||
public HashMap<String, Creator> map = new HashMap<>();
|
||||
private PartLibrary library;
|
||||
private ElementLibrary library;
|
||||
|
||||
private ShapeFactory() {
|
||||
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;
|
||||
return library;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user