mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 08:55:05 -04:00
Added a simple compatibility check to the custom shape import.
This commit is contained in:
parent
547d3ada69
commit
8a2fbe89a9
@ -5,6 +5,10 @@
|
||||
*/
|
||||
package de.neemann.digital.draw.shapes.custom;
|
||||
|
||||
import de.neemann.digital.core.ObservableValue;
|
||||
import de.neemann.digital.core.ObservableValues;
|
||||
import de.neemann.digital.core.element.PinDescription;
|
||||
import de.neemann.digital.draw.elements.Circuit;
|
||||
import de.neemann.digital.draw.elements.PinException;
|
||||
import de.neemann.digital.draw.graphics.*;
|
||||
import de.neemann.digital.draw.graphics.Polygon;
|
||||
@ -197,6 +201,25 @@ public class CustomShapeDescription implements Iterable<CustomShapeDescription.H
|
||||
return pins.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the compatibility of this shape to the given circuit
|
||||
*
|
||||
* @param circuit the circuit
|
||||
* @throws PinException PinException
|
||||
*/
|
||||
public void checkCompatibility(Circuit circuit) throws PinException {
|
||||
final ObservableValues outputNames = circuit.getOutputNames();
|
||||
for (ObservableValue out : outputNames)
|
||||
getPin(out.getName());
|
||||
final PinDescription[] inputNames = circuit.getInputNames();
|
||||
for (PinDescription in : inputNames)
|
||||
getPin(in.getName());
|
||||
|
||||
int pinsNum = outputNames.size() + inputNames.length;
|
||||
if (pinsNum != pins.size())
|
||||
throw new PinException(Lang.get("err_morePinsDefinedInSVGAsNeeded"));
|
||||
}
|
||||
|
||||
private interface Transformable {
|
||||
void transform(Transform tr);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ package de.neemann.digital.gui.components;
|
||||
|
||||
import de.neemann.digital.core.element.ElementAttributes;
|
||||
import de.neemann.digital.core.element.Key;
|
||||
import de.neemann.digital.draw.elements.PinException;
|
||||
import de.neemann.digital.draw.shapes.custom.CustomShapeDescription;
|
||||
import de.neemann.digital.draw.shapes.custom.svg.SvgException;
|
||||
import de.neemann.digital.draw.shapes.custom.svg.SvgImporter;
|
||||
@ -62,8 +63,13 @@ public class CustomShapeEditor extends EditorFactory.LabelEditor<CustomShapeDesc
|
||||
if (fc.showOpenDialog(getAttributeDialog()) == JFileChooser.APPROVE_OPTION) {
|
||||
lastSVGFile = fc.getSelectedFile();
|
||||
try {
|
||||
customShapeDescription = new SvgImporter(fc.getSelectedFile()).create();
|
||||
} catch (IOException | SvgException e1) {
|
||||
CustomShapeDescription csd = new SvgImporter(fc.getSelectedFile()).create();
|
||||
final Main main = getAttributeDialog().getMain();
|
||||
if (main != null) {
|
||||
csd.checkCompatibility(main.getCircuitComponent().getCircuit());
|
||||
customShapeDescription = csd;
|
||||
}
|
||||
} catch (IOException | SvgException | PinException e1) {
|
||||
new ErrorMessage(Lang.get("msg_errorImportingSvg")).addCause(e1).show(getAttributeDialog());
|
||||
}
|
||||
}
|
||||
|
@ -963,6 +963,7 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
|
||||
<string name="err_moreThenOneRomFound">Mehr als einen Programmspeicher gefunden. Es darf nur einen Programmspeicher geben.</string>
|
||||
<string name="err_errorLoadingRomData">Fehler beim Laden des Programmspeichers.</string>
|
||||
<string name="err_parsingSVG">Fehler beim Laden der SVG-Datei.</string>
|
||||
<string name="err_morePinsDefinedInSVGAsNeeded">Die SVG-Datei enthält Pins, die es in der Schaltung nicht gibt.</string>
|
||||
|
||||
<string name="key_AddrBits">Adress-Bits</string><!-- ROM, RAMDualPort, RAMSinglePort, RAMSinglePortSel, EEPROM -->
|
||||
<string name="key_AddrBits_tt">Anzahl der Adress-Bits, die verwendet werden.</string>
|
||||
|
@ -960,6 +960,7 @@
|
||||
<string name="err_moreThenOneRomFound">More then one program memories found! Only one program memory must be flages as such.</string>
|
||||
<string name="err_errorLoadingRomData">Error loading the program memory.</string>
|
||||
<string name="err_parsingSVG">Error while reading the SVG file.</string>
|
||||
<string name="err_morePinsDefinedInSVGAsNeeded">The SVG file contains pins that do not exist in the circuit.</string>
|
||||
|
||||
<string name="key_AddrBits">Address Bits</string><!-- ROM, RAMDualPort, RAMSinglePort, RAMSinglePortSel, EEPROM -->
|
||||
<string name="key_AddrBits_tt">Number of address bits used.</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user