mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-16 08:25:09 -04:00
better error messages, fixed som library bugs
This commit is contained in:
parent
784bafb67e
commit
59bc557fc1
@ -54,4 +54,9 @@ public class Pin {
|
||||
}
|
||||
|
||||
public enum Direction {input, output, both}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
@ -17,15 +17,17 @@ public class CustomElement implements Element {
|
||||
private final NetList netList;
|
||||
private final Circuit circuit;
|
||||
private final ElementLibrary library;
|
||||
private final String name;
|
||||
|
||||
public CustomElement(Circuit circuit, ElementLibrary library) {
|
||||
public CustomElement(Circuit circuit, ElementLibrary library, String name) {
|
||||
this.circuit = circuit;
|
||||
this.library = library;
|
||||
this.name = name;
|
||||
netList = new NetList(circuit.getWires());
|
||||
}
|
||||
|
||||
public ModelDescription getModelDescription() throws PinException, NodeException {
|
||||
return new ModelDescription(circuit, library, true, new NetList(netList));
|
||||
return new ModelDescription(circuit, library, true, name, new NetList(netList));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,10 +38,10 @@ public class ModelDescription implements Iterable<ModelEntry> {
|
||||
this(circuit, library, false);
|
||||
}
|
||||
public ModelDescription(Circuit circuit, ElementLibrary library, boolean readAsCustom) throws PinException, NodeException {
|
||||
this(circuit, library, readAsCustom, new NetList(circuit.getWires()));
|
||||
this(circuit, library, readAsCustom, "unknown", new NetList(circuit.getWires()));
|
||||
}
|
||||
|
||||
public ModelDescription(Circuit circuit, ElementLibrary library, boolean readAsCustom, NetList netList) throws PinException, NodeException {
|
||||
public ModelDescription(Circuit circuit, ElementLibrary library, boolean readAsCustom, String fileName, NetList netList) throws PinException, NodeException {
|
||||
this.netList = netList;
|
||||
entries = new ArrayList<>();
|
||||
if (readAsCustom)
|
||||
@ -63,9 +63,11 @@ public class ModelDescription implements Iterable<ModelEntry> {
|
||||
if (elementType == In.DESCRIPTION || elementType == Out.DESCRIPTION) {
|
||||
String label = ve.getElementAttributes().get(AttributeKey.Label);
|
||||
if (label == null || label.length() == 0)
|
||||
throw new PinException(Lang.get("err_pinWithoutName"));
|
||||
throw new PinException(Lang.get("err_pinWithoutName", fileName));
|
||||
if (pins.size() != 1)
|
||||
throw new PinException(Lang.get("err_N_isNotInputOrOutput", label));
|
||||
throw new PinException(Lang.get("err_N_isNotInputOrOutput", label, fileName));
|
||||
if (ioMap.containsKey(label))
|
||||
throw new PinException(Lang.get("err_duplicatePinLabel", label, fileName));
|
||||
|
||||
ioMap.put(label, pins.get(0));
|
||||
isNotAIO = false;
|
||||
|
@ -36,6 +36,7 @@ public class MissingShape implements Shape {
|
||||
@Override
|
||||
public void drawTo(Graphic graphic) {
|
||||
Style style = Style.SHAPE_PIN;
|
||||
graphic.drawLine(new Vector(0, 0), new Vector(0, style.getFontSize()), style);
|
||||
graphic.drawText(new Vector(0, 0), new Vector(1, 0), message, Orientation.LEFTBOTTOM, style);
|
||||
if (cause != null && cause.length() > 0)
|
||||
graphic.drawText(new Vector(0, style.getFontSize()), new Vector(1, style.getFontSize()), cause, Orientation.LEFTBOTTOM, style);
|
||||
|
@ -27,7 +27,7 @@ public class LibrarySelector implements ElementNotFoundNotification {
|
||||
private JMenu customMenu;
|
||||
private InsertHistory insertHistory;
|
||||
private CircuitComponent circuitComponent;
|
||||
private ArrayList<String> importedElements;
|
||||
private ArrayList<ImportedItem> importedElements;
|
||||
|
||||
public LibrarySelector(ElementLibrary library) {
|
||||
this.library = library;
|
||||
@ -56,8 +56,10 @@ public class LibrarySelector implements ElementNotFoundNotification {
|
||||
customMenu.add(new ToolTipAction(Lang.get("menu_refresh")) {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
for (String name : importedElements)
|
||||
library.removeElement(name);
|
||||
for (ImportedItem item : importedElements) {
|
||||
library.removeElement(item.name);
|
||||
customMenu.remove(item.menuEntry);
|
||||
}
|
||||
}
|
||||
}.setToolTip(Lang.get("menu_refresh_tt")));
|
||||
|
||||
@ -71,7 +73,7 @@ public class LibrarySelector implements ElementNotFoundNotification {
|
||||
parts.add(subMenu);
|
||||
lastPath = path;
|
||||
}
|
||||
subMenu.add(new InsertAction(pc.getName(), insertHistory, circuitComponent));
|
||||
subMenu.add(new InsertAction(pc.getName(), insertHistory, circuitComponent).createJMenuItem());
|
||||
}
|
||||
|
||||
return parts;
|
||||
@ -117,13 +119,15 @@ public class LibrarySelector implements ElementNotFoundNotification {
|
||||
Circuit circuit = Circuit.loadCircuit(file);
|
||||
ElementTypeDescription description =
|
||||
new ElementTypeDescription(file.getName(),
|
||||
attributes -> new CustomElement(circuit, library),
|
||||
attributes -> new CustomElement(circuit, library, file.getName()),
|
||||
circuit.getInputNames(library))
|
||||
.setShortName(createShortName(file));
|
||||
library.addDescription(description);
|
||||
JMenuItem menuEntry = new InsertAction(description.getName(), insertHistory, circuitComponent).createJMenuItem();
|
||||
if (customMenu != null)
|
||||
customMenu.add(new InsertAction(description.getName(), insertHistory, circuitComponent));
|
||||
importedElements.add(description.getName());
|
||||
customMenu.add(menuEntry);
|
||||
|
||||
importedElements.add(new ImportedItem(description.getName(), menuEntry));
|
||||
return description;
|
||||
} catch (Exception e) {
|
||||
SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorImportingModel")).addCause(e));
|
||||
@ -137,4 +141,13 @@ public class LibrarySelector implements ElementNotFoundNotification {
|
||||
return name;
|
||||
}
|
||||
|
||||
private static class ImportedItem {
|
||||
private final String name;
|
||||
private final JMenuItem menuEntry;
|
||||
|
||||
public ImportedItem(String name, JMenuItem menuEntry) {
|
||||
this.name = name;
|
||||
this.menuEntry = menuEntry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,15 +53,15 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
private Model model;
|
||||
private ModelDescription modelDescription;
|
||||
|
||||
public Main(File filename) {
|
||||
public Main(File fileToOpen) {
|
||||
super(Lang.get("digital"));
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
|
||||
Circuit cr = new Circuit();
|
||||
circuitComponent = new CircuitComponent(cr, library);
|
||||
|
||||
if (filename != null) {
|
||||
SwingUtilities.invokeLater(() -> loadFile(filename));
|
||||
if (fileToOpen != null) {
|
||||
SwingUtilities.invokeLater(() -> loadFile(fileToOpen));
|
||||
} else {
|
||||
String name = prefs.get("name", null);
|
||||
if (name != null) {
|
||||
|
@ -41,11 +41,12 @@ err_burnError=Es sind mehrere Ausg\u00E4nge zusammengeschaltet
|
||||
err_needs_N0_bits_found_N2_bits=Es werden {0} Bits ben\u00F6tigt, aber es wurden {1} Bits gefunden
|
||||
err_selectorInputCountMismatch=Die Zahl der Eing\u00E4nge passt nicht zur Bitbreite der Auswahlleitung
|
||||
err_splitterBitsMismatch=Die Bitzahl am Spiltter passt nicht
|
||||
err_pinWithoutName=Es gibt einen Pin ohne einen Namen
|
||||
err_pinWithoutName=Es gibt einen Pin ohne einen Namen in {0}
|
||||
err_pin_N_unknown=Pin {0} ist unbekannt
|
||||
err_pin_N_notFound=Pin {0} wurde nicht gefunden.
|
||||
err_netOfPin_N_notFound=Das Netz von Pin {0} wurde nicht gefunden
|
||||
err_N_isNotInputOrOutput=Pin {0} ist werder Eingang noch Ausgang
|
||||
err_N_isNotInputOrOutput=Pin {0} in Element {1} ist werder Eingang noch Ausgang
|
||||
err_duplicatePinLabel=Pin {0} in Element {1} exitiert mehrfach
|
||||
err_pin_N0_atElement_N1_notFound=Pin {0} von Element {1} wurde nicht gefunden
|
||||
err_noValueSetFor_N0_atElement_N1=Kein Wert gesetzt f\u00FCr {0} an Element {1}
|
||||
err_onOutConnectedToWire=Kein Ausgang mit der Leitung verbunden
|
||||
@ -67,7 +68,7 @@ msg_errorCreatingModel=Fehler beim Erzeugen des Modells
|
||||
msg_errorWritingFile=Fehler beim Schreiben einer Datei
|
||||
msg_errorReadingFile=Fehler beim Lesen einer Datei
|
||||
msg_errorCalculatingStep=Fehler beim Berechnen eines Schrittes
|
||||
msg_missingShape_N=Es fehlt ein Diagramm für {0}
|
||||
msg_missingShape_N=Es fehlt ein Diagramm f\u00FCr {0}
|
||||
btn_edit=Bearbeiten
|
||||
btn_load=Laden
|
||||
tt_moveItemUp=Eintrag nach oben schieben
|
||||
|
@ -41,11 +41,12 @@ err_burnError=More then one output is active on a wire
|
||||
err_needs_N0_bits_found_N2_bits=There are {0} bits needed, but {1} bits found
|
||||
err_selectorInputCountMismatch=Number of inputs does not match selector bit count
|
||||
err_splitterBitsMismatch=Bit count of splitter is not matching
|
||||
err_pinWithoutName=Found a pin without a name
|
||||
err_pinWithoutName=Found a pin without a name in {0}
|
||||
err_pin_N_unknown=Pin {0} unknown
|
||||
err_pin_N_notFound=Pin {0} not found
|
||||
err_netOfPin_N_notFound=Net of pin {0} not found
|
||||
err_N_isNotInputOrOutput=Pin {0} is not a input or output
|
||||
err_N_isNotInputOrOutput=Pin {0} in element {1} is not a input or output
|
||||
err_duplicatePinLabel=Pin {0} in element {1} exists twice
|
||||
err_pin_N0_atElement_N1_notFound=Pin {0} not found at Element {1}
|
||||
err_noValueSetFor_N0_atElement_N1=No value set for {0} at Element {1}
|
||||
err_onOutConnectedToWire=No output connected to a wire
|
||||
|
Loading…
x
Reference in New Issue
Block a user