renamed the ModelDescription to ModelCreator

This commit is contained in:
hneemann 2016-06-30 08:17:29 +02:00
parent 51eaa84232
commit fe8efe1bcc
10 changed files with 51 additions and 50 deletions

View File

@ -6,7 +6,7 @@ import de.neemann.digital.core.ObservableValues;
import de.neemann.digital.core.element.Element;
import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.elements.PinException;
import de.neemann.digital.draw.model.ModelDescription;
import de.neemann.digital.draw.model.ModelCreator;
import de.neemann.digital.draw.model.NetList;
/**
@ -37,19 +37,19 @@ public class CustomElement implements Element {
}
/**
* Gets a {@link ModelDescription} of this circuit.
* Every time this method is called a new {@link ModelDescription} is created.
* Gets a {@link ModelCreator} of this circuit.
* Every time this method is called a new {@link ModelCreator} is created.
*
* @param subName name of the circuit, used to name unique elements
* @return the {@link ModelDescription}
* @return the {@link ModelCreator}
* @throws PinException PinException
* @throws NodeException NodeException
*/
public ModelDescription getModelDescription(String subName) throws PinException, NodeException {
public ModelCreator getModelDescription(String subName) throws PinException, NodeException {
if (netList == null)
netList = new NetList(circuit);
return new ModelDescription(circuit, library, true, name, new NetList(netList), subName);
return new ModelCreator(circuit, library, true, name, new NetList(netList), subName);
}
@Override

View File

@ -24,7 +24,7 @@ import java.util.*;
*
* @author hneemann
*/
public class ModelDescription implements Iterable<ModelEntry> {
public class ModelCreator implements Iterable<ModelEntry> {
private final Circuit circuit;
private final NetList netList;
@ -42,7 +42,7 @@ public class ModelDescription implements Iterable<ModelEntry> {
* @throws PinException PinException
* @throws NodeException NodeException
*/
public ModelDescription(Circuit circuit, ElementLibrary library) throws PinException, NodeException {
public ModelCreator(Circuit circuit, ElementLibrary library) throws PinException, NodeException {
this(circuit, library, false);
}
@ -55,7 +55,7 @@ public class ModelDescription implements Iterable<ModelEntry> {
* @throws PinException PinException
* @throws NodeException NodeException
*/
public ModelDescription(Circuit circuit, ElementLibrary library, boolean readAsCustom) throws PinException, NodeException {
public ModelCreator(Circuit circuit, ElementLibrary library, boolean readAsCustom) throws PinException, NodeException {
this(circuit, library, readAsCustom, "unknown", new NetList(circuit), "");
}
@ -71,7 +71,7 @@ public class ModelDescription implements Iterable<ModelEntry> {
* @throws PinException PinException
* @throws NodeException NodeException
*/
public ModelDescription(Circuit circuit, ElementLibrary library, boolean isNestedCircuit, String fileName, NetList netList, String subName) throws PinException, NodeException {
public ModelCreator(Circuit circuit, ElementLibrary library, boolean isNestedCircuit, String fileName, NetList netList, String subName) throws PinException, NodeException {
this.circuit = circuit;
this.netList = netList;
entries = new ArrayList<>();
@ -119,13 +119,13 @@ public class ModelDescription implements Iterable<ModelEntry> {
}
// connect all custom elements to the parents net
ArrayList<ModelDescription> cmdl = new ArrayList<>();
ArrayList<ModelCreator> cmdl = new ArrayList<>();
Iterator<ModelEntry> it = entries.iterator();
while (it.hasNext()) {
ModelEntry me = it.next();
if (me.getElement() instanceof CustomElement) { // at first look for custom elements
CustomElement ce = (CustomElement) me.getElement();
ModelDescription child = ce.getModelDescription(combineNames(subName, me.getVisualElement().getElementAttributes().getCleanLabel()));
ModelCreator child = ce.getModelDescription(combineNames(subName, me.getVisualElement().getElementAttributes().getCleanLabel()));
cmdl.add(child);
for (Pin p : me.getPins()) { // connect the custom elements to the parents net
@ -143,7 +143,7 @@ public class ModelDescription implements Iterable<ModelEntry> {
it.remove();
}
}
for (ModelDescription md : cmdl) { // put the elements of the custom element to the parent
for (ModelCreator md : cmdl) { // put the elements of the custom element to the parent
entries.addAll(md.entries);
netList.add(md.netList);
}
@ -207,10 +207,11 @@ public class ModelDescription implements Iterable<ModelEntry> {
}
/**
* Needs to be called after create model is called!
* Needs to be called after createModel is called!
* Connects the gui to the model
*
* @param guiObserver
* @param guiObserver the observer which can be attached to {@link de.neemann.digital.core.ObservableValue}s
* which have a state dependant graphical representation.
*/
public void connectToGui(Observer guiObserver) {
for (ModelEntry e : entries)
@ -242,7 +243,7 @@ public class ModelDescription implements Iterable<ModelEntry> {
}
/**
* Returns a list of all ModelEntries which contain a element of the given name
* Returns a list of all ModelEntries which contain an element of the given name
*
* @param elementName the name of the element
* @return the list
@ -256,7 +257,7 @@ public class ModelDescription implements Iterable<ModelEntry> {
}
/**
* @return the circuit whih was used to create this model description
* @return the circuit which was used to create this model description
*/
public Circuit getCircuit() {
return circuit;

View File

@ -10,7 +10,7 @@ import de.neemann.digital.core.element.PinDescriptions;
import de.neemann.digital.draw.elements.IOState;
import de.neemann.digital.draw.elements.Pins;
import de.neemann.digital.draw.graphics.Graphic;
import de.neemann.digital.draw.model.ModelDescription;
import de.neemann.digital.draw.model.ModelCreator;
import de.neemann.digital.draw.model.ModelEntry;
import de.neemann.digital.gui.components.CircuitComponent;
import de.neemann.digital.gui.components.OrderMerger;
@ -68,9 +68,9 @@ public class DataShape implements Shape {
}
@Override
public void registerModel(ModelDescription modelDescription, Model model, ModelEntry element) {
public void registerModel(ModelCreator modelCreator, Model model, ModelEntry element) {
ArrayList<Signal> signals = model.getSignalsCopy();
new OrderMerger<String, Signal>(modelDescription.getCircuit().getMeasurementOrdering()) {
new OrderMerger<String, Signal>(modelCreator.getCircuit().getMeasurementOrdering()) {
@Override
public boolean equals(Signal a, String b) {
return a.getName().equals(b);

View File

@ -4,7 +4,7 @@ import de.neemann.digital.core.Model;
import de.neemann.digital.core.Observer;
import de.neemann.digital.draw.elements.IOState;
import de.neemann.digital.draw.elements.Pins;
import de.neemann.digital.draw.model.ModelDescription;
import de.neemann.digital.draw.model.ModelCreator;
import de.neemann.digital.draw.model.ModelEntry;
/**
@ -43,10 +43,10 @@ public interface Shape extends Drawable {
* Allows the shape to make its drawing dependent of the model by registering a Observer to the model.
* It is used by {@link DataShape} to create and show the data graph.
*
* @param modelDescription the models description
* @param modelCreator the models description
* @param model the model itself
* @param element the ModelElement this shape belongs to
*/
default void registerModel(ModelDescription modelDescription, Model model, ModelEntry element) {
default void registerModel(ModelCreator modelCreator, Model model, ModelEntry element) {
}
}

View File

@ -19,7 +19,7 @@ import de.neemann.digital.draw.elements.PinException;
import de.neemann.digital.draw.elements.VisualElement;
import de.neemann.digital.draw.graphics.*;
import de.neemann.digital.draw.library.ElementLibrary;
import de.neemann.digital.draw.model.ModelDescription;
import de.neemann.digital.draw.model.ModelCreator;
import de.neemann.digital.draw.model.RealTimeClock;
import de.neemann.digital.draw.shapes.ShapeFactory;
import de.neemann.digital.gui.components.*;
@ -102,7 +102,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
private FileHistory fileHistory;
private Model model;
private ModelDescription modelDescription;
private ModelCreator modelCreator;
private boolean realtimeClockRunning;
private State elementState;
@ -432,7 +432,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
try {
model.doMicroStep(false);
circuitComponent.removeHighLighted();
modelDescription.addNodeElementsTo(model.nodesToUpdate(), circuitComponent.getHighLighted());
modelCreator.addNodeElementsTo(model.nodesToUpdate(), circuitComponent.getHighLighted());
circuitComponent.repaint();
doStep.setEnabled(model.needsUpdate());
} catch (Exception e1) {
@ -465,7 +465,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
@Override
public void actionPerformed(ActionEvent e) {
try {
Model model = new ModelDescription(circuitComponent.getCircuit(), library).createModel(false);
Model model = new ModelCreator(circuitComponent.getCircuit(), library).createModel(false);
SpeedTest speedTest = new SpeedTest(model);
double frequency = speedTest.calculate();
@ -515,7 +515,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
@Override
public void actionPerformed(ActionEvent e) {
try {
Model model = new ModelDescription(circuitComponent.getCircuit(), library).createModel(false);
Model model = new ModelCreator(circuitComponent.getCircuit(), library).createModel(false);
new TableDialog(Main.this, new ModelAnalyser(model).analyse(), shapeFactory, filename)
.setPinMap(new PinMap().addModel(model))
.setVisible(true);
@ -542,7 +542,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
private void orderMeasurements() {
try {
Model m = new ModelDescription(circuitComponent.getCircuit(), library).createModel(false);
Model m = new ModelCreator(circuitComponent.getCircuit(), library).createModel(false);
elementState.enter();
ArrayList<String> names = new ArrayList<>();
for (Signal s : m.getSignals())
@ -605,7 +605,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
if (model != null)
model.close();
modelDescription = null;
modelCreator = null;
model = null;
}
@ -614,12 +614,12 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
circuitComponent.removeHighLighted();
circuitComponent.setModeAndReset(true);
modelDescription = new ModelDescription(circuitComponent.getCircuit(), library);
modelCreator = new ModelCreator(circuitComponent.getCircuit(), library);
if (model != null)
model.close();
model = modelDescription.createModel(true);
model = modelCreator.createModel(true);
statusLabel.setText(Lang.get("msg_N_nodes", model.size()));
@ -634,11 +634,11 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
if (realtimeClockRunning) {
// if clock is running, enable automatic update of gui
GuiModelObserver gmo = new GuiModelObserver(circuitComponent, updateEvent);
modelDescription.connectToGui(gmo);
modelCreator.connectToGui(gmo);
model.addObserver(gmo);
} else
// all repainting is initiated by user actions!
modelDescription.connectToGui(null);
modelCreator.connectToGui(null);
doStep.setEnabled(false);
runToBreakAction.setEnabled(!realtimeClockRunning && model.isFastRunModel());
@ -676,8 +676,8 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
if (cause instanceof NodeException) {
NodeException e = (NodeException) cause;
circuitComponent.addHighLightedWires(e.getValues());
if (modelDescription != null)
modelDescription.addNodeElementsTo(e.getNodes(), circuitComponent.getHighLighted());
if (modelCreator != null)
modelCreator.addNodeElementsTo(e.getNodes(), circuitComponent.getHighLighted());
} else if (cause instanceof PinException) {
PinException e = (PinException) cause;
circuitComponent.addHighLighted(e.getVisualElement());
@ -800,7 +800,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
@Override
public void hasChanged() {
modelDescription.addNodeElementsTo(model.nodesToUpdate(), circuitComponent.getHighLighted());
modelCreator.addNodeElementsTo(model.nodesToUpdate(), circuitComponent.getHighLighted());
model.fireManualChangeEvent();
circuitComponent.repaint();
doStep.setEnabled(model.needsUpdate());

View File

@ -16,7 +16,7 @@
* classes which you can find in the core package.
* This classes form the simulation model represented by the {@link de.neemann.digital.core.Model} class.
* Furthermore this representation is called the model.
* In the package draw.model you can find the class {@link de.neemann.digital.draw.model.ModelDescription}.
* In the package draw.model you can find the class {@link de.neemann.digital.draw.model.ModelCreator}.
* This class takes a circuit represented by a Circuit instance and creates
* a Model instance representation.
* Some of the elements out of the Circuit representation you can also find

View File

@ -8,7 +8,7 @@ import de.neemann.digital.core.element.Element;
import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.elements.PinException;
import de.neemann.digital.draw.library.ElementLibrary;
import de.neemann.digital.draw.model.ModelDescription;
import de.neemann.digital.draw.model.ModelCreator;
import de.neemann.digital.draw.model.ModelEntry;
import de.neemann.digital.draw.shapes.ShapeFactory;
import de.neemann.digital.integration.Resources;
@ -37,7 +37,7 @@ public class TestExecuter {
File filename = new File(Resources.getRoot(), name);
Circuit circuit = Circuit.loadCircuit(filename, new ShapeFactory(library));
ModelDescription mb = new ModelDescription(circuit, library);
ModelCreator mb = new ModelCreator(circuit, library);
return new TestExecuter(mb.createModel(false), true).setUp(mb);
}
@ -99,9 +99,9 @@ public class TestExecuter {
setOutputs(me.getIoState().getInputs());
}
public TestExecuter setUp(ModelDescription modelDescription) {
List<ModelEntry> inputs = modelDescription.getEntries("In");
List<ModelEntry> outputs = modelDescription.getEntries("Out");
public TestExecuter setUp(ModelCreator modelCreator) {
List<ModelEntry> inputs = modelCreator.getEntries("In");
List<ModelEntry> outputs = modelCreator.getEntries("Out");
for (ModelEntry input : inputs) {
assertEquals(0, input.getIoState().inputCount());

View File

@ -5,7 +5,7 @@ import de.neemann.digital.analyse.expression.Expression;
import de.neemann.digital.analyse.expression.Variable;
import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.library.ElementLibrary;
import de.neemann.digital.draw.model.ModelDescription;
import de.neemann.digital.draw.model.ModelCreator;
import de.neemann.digital.draw.shapes.ShapeFactory;
import junit.framework.TestCase;
@ -31,7 +31,7 @@ public class CircuitBuilderTest extends TestCase {
.addCombinatorial("y", y)
.createCircuit();
ModelDescription m = new ModelDescription(circuit, library);
ModelCreator m = new ModelCreator(circuit, library);
TestExecuter te = new TestExecuter(m.createModel(false)).setUp(m);
te.check(0, 0, 0);
@ -56,7 +56,7 @@ public class CircuitBuilderTest extends TestCase {
.addCombinatorial("Y_1", y1)
.createCircuit();
ModelDescription m = new ModelDescription(circuit, library);
ModelCreator m = new ModelCreator(circuit, library);
TestExecuter te = new TestExecuter(m.createModel(false)).setUp(m);
te.check(0, 0);
te.checkC(1, 0);

View File

@ -5,7 +5,7 @@ import de.neemann.digital.core.Model;
import de.neemann.digital.core.Node;
import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.library.ElementLibrary;
import de.neemann.digital.draw.model.ModelDescription;
import de.neemann.digital.draw.model.ModelCreator;
import de.neemann.digital.draw.model.ModelEntry;
import de.neemann.digital.draw.shapes.ShapeFactory;
import junit.framework.TestCase;
@ -30,7 +30,7 @@ public class TestAnd extends TestCase {
File filename = new File(Resources.getRoot(), "dig/and.dig");
Circuit circuit = Circuit.loadCircuit(filename, new ShapeFactory(new ElementLibrary()));
ModelDescription md = new ModelDescription(circuit, library);
ModelCreator md = new ModelCreator(circuit, library);
Model model = md.createModel(false);
List<Node> nodes = model.getNodes();

View File

@ -6,7 +6,7 @@ import de.neemann.digital.core.NodeException;
import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.elements.PinException;
import de.neemann.digital.draw.library.ElementLibrary;
import de.neemann.digital.draw.model.ModelDescription;
import de.neemann.digital.draw.model.ModelCreator;
import de.neemann.digital.draw.shapes.ShapeFactory;
import de.neemann.digital.gui.LibrarySelector;
@ -71,7 +71,7 @@ public class ToBreakRunner {
LibrarySelector librarySelector = new LibrarySelector(library, shapeFactory, null);
librarySelector.setFilePath(filename.getParentFile());
ModelDescription md = new ModelDescription(circuit, library);
ModelCreator md = new ModelCreator(circuit, library);
model = md.createModel(false);
if (doInit)
model.init(true);