mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 23:36:27 -04:00
added some documentation
This commit is contained in:
parent
6e09ffaa1b
commit
4647426d39
@ -58,6 +58,14 @@ public class Circuit {
|
|||||||
return xStream;
|
return xStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new circuit instance from a stored file
|
||||||
|
*
|
||||||
|
* @param filename filename
|
||||||
|
* @param shapeFactory shapeFactory used to create the shapes
|
||||||
|
* @return the circuit
|
||||||
|
* @throws IOException IOException
|
||||||
|
*/
|
||||||
public static Circuit loadCircuit(File filename, ShapeFactory shapeFactory) throws IOException {
|
public static Circuit loadCircuit(File filename, ShapeFactory shapeFactory) throws IOException {
|
||||||
XStream xStream = getxStream();
|
XStream xStream = getxStream();
|
||||||
try (InputStream in = new FileInputStream(filename)) {
|
try (InputStream in = new FileInputStream(filename)) {
|
||||||
@ -80,6 +88,12 @@ public class Circuit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the circuit in the given file
|
||||||
|
*
|
||||||
|
* @param filename filename
|
||||||
|
* @throws IOException IOException
|
||||||
|
*/
|
||||||
public void save(File filename) throws IOException {
|
public void save(File filename) throws IOException {
|
||||||
wires = new WireConsistencyChecker(wires).check();
|
wires = new WireConsistencyChecker(wires).check();
|
||||||
dotsPresent = false;
|
dotsPresent = false;
|
||||||
@ -91,17 +105,30 @@ public class Circuit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a ne empty circuit instance
|
||||||
|
*/
|
||||||
public Circuit() {
|
public Circuit() {
|
||||||
visualElements = new ArrayList<>();
|
visualElements = new ArrayList<>();
|
||||||
wires = new ArrayList<>();
|
wires = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the elements attributes
|
||||||
|
*
|
||||||
|
* @return the attributes
|
||||||
|
*/
|
||||||
public ElementAttributes getAttributes() {
|
public ElementAttributes getAttributes() {
|
||||||
if (attributes == null)
|
if (attributes == null)
|
||||||
attributes = new ElementAttributes();
|
attributes = new ElementAttributes();
|
||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the attribute editor
|
||||||
|
*
|
||||||
|
* @param parent the parent component
|
||||||
|
*/
|
||||||
public void editAttributes(Component parent) {
|
public void editAttributes(Component parent) {
|
||||||
if (new AttributeDialog(parent, null, ATTR_LIST, getAttributes()).showDialog()) {
|
if (new AttributeDialog(parent, null, ATTR_LIST, getAttributes()).showDialog()) {
|
||||||
if (attributes.isEmpty())
|
if (attributes.isEmpty())
|
||||||
@ -110,10 +137,21 @@ public class Circuit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws tis circuit using the given graphic instance
|
||||||
|
*
|
||||||
|
* @param graphic the graphic instance used
|
||||||
|
*/
|
||||||
public void drawTo(Graphic graphic) {
|
public void drawTo(Graphic graphic) {
|
||||||
drawTo(graphic, EMPTY_SET);
|
drawTo(graphic, EMPTY_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws tis circuit using the given graphic instance
|
||||||
|
*
|
||||||
|
* @param graphic the graphic instance used
|
||||||
|
* @param highLighted a list of Drawables to highlight
|
||||||
|
*/
|
||||||
public void drawTo(Graphic graphic, Collection<Drawable> highLighted) {
|
public void drawTo(Graphic graphic, Collection<Drawable> highLighted) {
|
||||||
if (!dotsPresent) {
|
if (!dotsPresent) {
|
||||||
new DotCreator(wires).applyDots();
|
new DotCreator(wires).applyDots();
|
||||||
@ -131,11 +169,21 @@ public class Circuit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a ne VisualElement
|
||||||
|
*
|
||||||
|
* @param visualElement the visual element to add
|
||||||
|
*/
|
||||||
public void add(VisualElement visualElement) {
|
public void add(VisualElement visualElement) {
|
||||||
visualElements.add(visualElement);
|
visualElements.add(visualElement);
|
||||||
modified();
|
modified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new Wire
|
||||||
|
*
|
||||||
|
* @param newWire the wire to add
|
||||||
|
*/
|
||||||
public void add(Wire newWire) {
|
public void add(Wire newWire) {
|
||||||
if (newWire.p1.equals(newWire.p2))
|
if (newWire.p1.equals(newWire.p2))
|
||||||
return;
|
return;
|
||||||
@ -160,10 +208,22 @@ public class Circuit {
|
|||||||
modified();
|
modified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all visual elements
|
||||||
|
*
|
||||||
|
* @return the list
|
||||||
|
*/
|
||||||
public ArrayList<VisualElement> getElements() {
|
public ArrayList<VisualElement> getElements() {
|
||||||
return visualElements;
|
return visualElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all Moveables in the given rectangle.
|
||||||
|
*
|
||||||
|
* @param min upper left corner of the rectangle
|
||||||
|
* @param max lower right corner of the rectangle
|
||||||
|
* @return the list
|
||||||
|
*/
|
||||||
public ArrayList<Moveable> getElementsToMove(Vector min, Vector max) {
|
public ArrayList<Moveable> getElementsToMove(Vector min, Vector max) {
|
||||||
ArrayList<Moveable> m = new ArrayList<>();
|
ArrayList<Moveable> m = new ArrayList<>();
|
||||||
for (VisualElement vp : visualElements)
|
for (VisualElement vp : visualElements)
|
||||||
@ -182,6 +242,14 @@ public class Circuit {
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all Moveables in the given rectangle.
|
||||||
|
* It creates a deep copy of all elements.
|
||||||
|
*
|
||||||
|
* @param min upper left corner of the rectangle
|
||||||
|
* @param max lower right corner of the rectangle
|
||||||
|
* @return the list
|
||||||
|
*/
|
||||||
public ArrayList<Moveable> getElementsToCopy(Vector min, Vector max, ShapeFactory shapeFactory) {
|
public ArrayList<Moveable> getElementsToCopy(Vector min, Vector max, ShapeFactory shapeFactory) {
|
||||||
ArrayList<Moveable> m = new ArrayList<>();
|
ArrayList<Moveable> m = new ArrayList<>();
|
||||||
for (VisualElement vp : visualElements)
|
for (VisualElement vp : visualElements)
|
||||||
@ -199,31 +267,45 @@ public class Circuit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes all elements th the given rectangle
|
||||||
|
*
|
||||||
|
* @param min upper left corner of the rectangle
|
||||||
|
* @param max lower right corner of the rectangle
|
||||||
|
*/
|
||||||
public void delete(Vector min, Vector max) {
|
public void delete(Vector min, Vector max) {
|
||||||
{
|
Iterator<VisualElement> veIt = visualElements.iterator();
|
||||||
Iterator<VisualElement> it = visualElements.iterator();
|
while (veIt.hasNext())
|
||||||
while (it.hasNext())
|
if (veIt.next().matches(min, max))
|
||||||
if (it.next().matches(min, max))
|
veIt.remove();
|
||||||
it.remove();
|
|
||||||
}
|
Iterator<Wire> wIt = wires.iterator();
|
||||||
{
|
while (wIt.hasNext()) {
|
||||||
Iterator<Wire> it = wires.iterator();
|
Wire w = wIt.next();
|
||||||
while (it.hasNext()) {
|
|
||||||
Wire w = it.next();
|
|
||||||
if (w.p1.inside(min, max) || w.p2.inside(min, max))
|
if (w.p1.inside(min, max) || w.p2.inside(min, max))
|
||||||
it.remove();
|
wIt.remove();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
dotsPresent = false;
|
dotsPresent = false;
|
||||||
modified();
|
modified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a single visual element
|
||||||
|
*
|
||||||
|
* @param partToDelete the element to delete
|
||||||
|
*/
|
||||||
public void delete(VisualElement partToDelete) {
|
public void delete(VisualElement partToDelete) {
|
||||||
if (visualElements.remove(partToDelete))
|
if (visualElements.remove(partToDelete))
|
||||||
modified();
|
modified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the element at the given position
|
||||||
|
*
|
||||||
|
* @param pos the cursor position
|
||||||
|
* @return the element or null if there is no element at the given position
|
||||||
|
*/
|
||||||
public VisualElement getElementAt(Vector pos) {
|
public VisualElement getElementAt(Vector pos) {
|
||||||
for (VisualElement element : visualElements) {
|
for (VisualElement element : visualElements) {
|
||||||
if (element.matches(pos))
|
if (element.matches(pos))
|
||||||
@ -232,6 +314,12 @@ public class Circuit {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if there is a pin at the given position
|
||||||
|
*
|
||||||
|
* @param pos the position
|
||||||
|
* @return true if position is a pin position
|
||||||
|
*/
|
||||||
public boolean isPinPos(Vector pos) {
|
public boolean isPinPos(Vector pos) {
|
||||||
VisualElement el = getElementAt(pos);
|
VisualElement el = getElementAt(pos);
|
||||||
if (el == null) return false;
|
if (el == null) return false;
|
||||||
@ -239,6 +327,13 @@ public class Circuit {
|
|||||||
return isPinPos(pos, el);
|
return isPinPos(pos, el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given element has a pin at the given position
|
||||||
|
*
|
||||||
|
* @param pos the position
|
||||||
|
* @param el the element
|
||||||
|
* @return true if position is a pin position
|
||||||
|
*/
|
||||||
public boolean isPinPos(Vector pos, VisualElement el) {
|
public boolean isPinPos(Vector pos, VisualElement el) {
|
||||||
for (Pin p : el.getPins())
|
for (Pin p : el.getPins())
|
||||||
if (p.getPos().equals(pos))
|
if (p.getPos().equals(pos))
|
||||||
@ -248,14 +343,31 @@ public class Circuit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets this circuits state to modified
|
||||||
|
*/
|
||||||
public void modified() {
|
public void modified() {
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if modified
|
||||||
|
*/
|
||||||
|
public boolean isModified() {
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a list of all wires
|
||||||
|
*/
|
||||||
public ArrayList<Wire> getWires() {
|
public ArrayList<Wire> getWires() {
|
||||||
return wires;
|
return wires;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the references to the ObservableValues representing the elements or wire state.
|
||||||
|
*/
|
||||||
public void clearState() {
|
public void clearState() {
|
||||||
for (VisualElement vp : visualElements)
|
for (VisualElement vp : visualElements)
|
||||||
vp.setState(null, null);
|
vp.setState(null, null);
|
||||||
@ -263,10 +375,13 @@ public class Circuit {
|
|||||||
w.setValue(null);
|
w.setValue(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isModified() {
|
/**
|
||||||
return modified;
|
* returns a list of all input names of this circuit
|
||||||
}
|
*
|
||||||
|
* @param library the library
|
||||||
|
* @return the list of input names
|
||||||
|
* @throws PinException PinException
|
||||||
|
*/
|
||||||
public String[] getInputNames(ElementLibrary library) throws PinException {
|
public String[] getInputNames(ElementLibrary library) throws PinException {
|
||||||
ArrayList<String> pinList = new ArrayList<>();
|
ArrayList<String> pinList = new ArrayList<>();
|
||||||
for (VisualElement ve : visualElements) {
|
for (VisualElement ve : visualElements) {
|
||||||
@ -282,6 +397,14 @@ public class Circuit {
|
|||||||
return pinList.toArray(new String[pinList.size()]);
|
return pinList.toArray(new String[pinList.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a list of all output ObservableNames.
|
||||||
|
* The ObservableValue is not connected to a model! Its just a wrapper for the outputs name.
|
||||||
|
*
|
||||||
|
* @param library the library
|
||||||
|
* @return the list of output ObservableValues
|
||||||
|
* @throws PinException PinException
|
||||||
|
*/
|
||||||
public ObservableValue[] getOutputNames(ElementLibrary library) throws PinException {
|
public ObservableValue[] getOutputNames(ElementLibrary library) throws PinException {
|
||||||
ArrayList<ObservableValue> pinList = new ArrayList<>();
|
ArrayList<ObservableValue> pinList = new ArrayList<>();
|
||||||
for (VisualElement ve : visualElements) {
|
for (VisualElement ve : visualElements) {
|
||||||
@ -294,12 +417,12 @@ public class Circuit {
|
|||||||
pinList.add(new ObservableValue(name, 0) {
|
pinList.add(new ObservableValue(name, 0) {
|
||||||
@Override
|
@Override
|
||||||
public long getValue() {
|
public long getValue() {
|
||||||
throw new RuntimeException("invallid call!");
|
throw new RuntimeException("invalid call!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObservableValue addObserver(Observer observer) {
|
public ObservableValue addObserver(Observer observer) {
|
||||||
throw new RuntimeException("invallid call!");
|
throw new RuntimeException("invalid call!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ public class CircuitComponent extends JComponent {
|
|||||||
break;
|
break;
|
||||||
case select:
|
case select:
|
||||||
listener = new SelectMouseListener();
|
listener = new SelectMouseListener();
|
||||||
setCursor(new Cursor(Cursor.MOVE_CURSOR));
|
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
|
||||||
break;
|
break;
|
||||||
case running:
|
case running:
|
||||||
listener = new RunningMouseListener();
|
listener = new RunningMouseListener();
|
||||||
|
@ -67,7 +67,7 @@ err_noShapeFoundFor_N=Es wurde kein Diagramm für {0} gefunden.
|
|||||||
err_invalidFileFormat=Ung\u00FCltiges Dateiformat
|
err_invalidFileFormat=Ung\u00FCltiges Dateiformat
|
||||||
err_readOfHighZ=Lesen einer hochohmigen Leitung
|
err_readOfHighZ=Lesen einer hochohmigen Leitung
|
||||||
err_notAllOutputsSameBits=Es haben nicht alle Ausg\u00E4nge die gleiche Bitbreite
|
err_notAllOutputsSameBits=Es haben nicht alle Ausg\u00E4nge die gleiche Bitbreite
|
||||||
err_notAllOutputsSupportHighZ=Wenn mehrere Ausg\u00E4nge verbunden sind, m\u00FCssen alle Tri-State Ausg\u00E4nge sein
|
err_notAllOutputsSupportHighZ=Wenn mehrere Ausg\u00E4nge verbunden sind, m\u00FCssen alle Ausgänge Tri-State Ausg\u00E4nge sein
|
||||||
err_breakTimeOut=Nach {0} Zyklen ist kein Break aufgetreten
|
err_breakTimeOut=Nach {0} Zyklen ist kein Break aufgetreten
|
||||||
|
|
||||||
attr_dialogTitle=Eigenschaften
|
attr_dialogTitle=Eigenschaften
|
||||||
|
Loading…
x
Reference in New Issue
Block a user