diff --git a/diylc/diylc-library/src/org/diylc/components/misc/CurrentSourceSymbol.java b/diylc/diylc-library/src/org/diylc/components/misc/CurrentSourceSymbol.java
new file mode 100644
index 00000000..dddc13ee
--- /dev/null
+++ b/diylc/diylc-library/src/org/diylc/components/misc/CurrentSourceSymbol.java
@@ -0,0 +1,211 @@
+/*
+
+ DIY Layout Creator (DIYLC).
+ Copyright (c) 2009-2018 held jointly by the individual authors.
+
+ This file is part of DIYLC.
+
+ DIYLC is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ DIYLC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DIYLC. If not, see .
+
+*/
+package org.diylc.components.misc;
+
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.Line2D;
+
+import org.diylc.components.AbstractSchematicLeadedSymbol;
+import org.diylc.core.CreationMethod;
+import org.diylc.core.IDIYComponent;
+import org.diylc.core.annotations.ComponentDescriptor;
+import org.diylc.core.annotations.EditableProperty;
+import org.diylc.core.measures.CurrentUnit;
+import org.diylc.core.measures.Size;
+import org.diylc.core.measures.SizeUnit;
+import org.diylc.core.measures.VoltageUnit;
+
+@ComponentDescriptor(name = "Current Source", author = "JD", category = "Schematic Symbols", creationMethod = CreationMethod.POINT_BY_POINT,
+ instanceNamePrefix = "I", description = "Current Source schematic symbol", zOrder = IDIYComponent.COMPONENT)
+
+/**
+ * Component type for Current Source Symbol, options for 2 drawing styles.
+ * Modified from the Voltage Source Symbol component. Author: JD
+ *
+ * @author JD
+ */
+public class CurrentSourceSymbol extends AbstractSchematicLeadedSymbol {
+
+ // FIELDS
+ private static final long serialVersionUID = 1L;
+ private String value = "Current Source";
+ private SourceStyle source_Style = SourceStyle.Standard;
+
+ // Overall size
+ public static Size DEFAULT_LENGTH = new Size(0.2, SizeUnit.in);
+ public static Size DEFAULT_WIDTH = new Size(0.2, SizeUnit.in);
+
+ // Sets current to 100mA by default
+ private org.diylc.core.measures.Current currentNew = new org.diylc.core.measures.Current(100d, CurrentUnit.mA);
+
+ // METHODS
+
+ @Override
+ public String getValueForDisplay() {
+ return getValue().toString() + (getCurrentNew() == null ? "" : " " + getCurrentNew().toString());
+ }
+
+ @EditableProperty
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ @EditableProperty(name = "Current")
+ public org.diylc.core.measures.Current getCurrentNew() {
+ return currentNew;
+ }
+
+ public void setVoltageNew(org.diylc.core.measures.Current currentNew) {
+ this.currentNew = currentNew;
+ }
+
+ /**
+ * Returns whether the source drawing style is Standard or Alternate. Uses Enum
+ * "SourceStyle" Author: JD (Modified Bancika's code, credit to Bancika)
+ * @return
+ */
+ @EditableProperty(name = "Source Style")
+ public SourceStyle getSourceStyle() {
+ if (source_Style == null)
+ source_Style = SourceStyle.Standard;
+ return source_Style;
+ }
+
+ /**
+ * Sets whether the source is standard or alternate. Uses Enum "SourceStyle"
+ * Author: JD (Modified Bancika's code, credit to Bancika)
+ * @param sourceStyle
+ */
+ public void setSourceStyle(SourceStyle source_Style) {
+ this.source_Style = source_Style;
+ }
+
+ @Override
+ protected Size getDefaultWidth() {
+ return DEFAULT_WIDTH;
+ }
+
+ @Override
+ protected Size getDefaultLength() {
+ return DEFAULT_LENGTH;
+ }
+
+ @Override
+ protected Shape getBodyShape() {
+ double width = getWidth().convertToPixels();
+ double length = getLength().convertToPixels();
+ GeneralPath body = new GeneralPath();
+
+ switch (getSourceStyle()) {
+ case Standard:
+ // Main body is a circle, drawn with an Ellipse
+ body.append(new Ellipse2D.Double(0d, 0d, width, length), true);
+ break;
+ case Alternate:
+ // Main body is two circles
+ body.append(new Ellipse2D.Double(0d, 0d, length, length), true);
+ body.moveTo(length * 1.5 , length / 2); // Prevents a closing line being drawn
+ body.append(new Ellipse2D.Double(length / 2, 0d, length, length), true);
+ break;
+ }
+ return (Shape) body;
+ }
+
+ @Override
+ protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
+ double width = getWidth().convertToPixels();
+ double height = getLength().convertToPixels();
+
+ g2d.setColor(getBorderColor());
+ switch (getSourceStyle()) {
+ case Standard: // Draw arrow inside main circle
+ g2d.draw(new Line2D.Double(0.25 * width, height / 2,
+ 0.75 * width, height / 2));
+
+ g2d.draw(new Line2D.Double(0.75 * width, height / 2,
+ (0.75 * width) - 0.45 * (0.25 * width), (height / 2) + height / 5));
+
+ g2d.draw(new Line2D.Double(0.75 * width, height / 2,
+ (0.75 * width) - 0.45 * (0.25 * width), (height / 2) - height / 5));
+
+ break;
+ case Alternate: // Draw arrow below the two circles
+ g2d.draw(new Line2D.Double(0.25 * width * 1.5, height * 1.5,
+ 0.75 * width * 1.5, height * 1.5));
+
+ g2d.draw(new Line2D.Double(0.75 * width * 1.5, height * 1.5,
+ (0.75 * width * 1.5) - 0.45 * (0.25 * width * 1.5), (height * 1.5) + height / 5));
+
+ g2d.draw(new Line2D.Double(0.75 * width * 1.5, height * 1.5,
+ (0.75 * width * 1.5) - 0.45 * (0.25 * width * 1.5), (height * 1.5) - height / 5));
+
+
+ break;
+ default:
+ }
+ }
+
+ public void drawIcon(Graphics2D g2d, int width, int height) {
+ g2d.rotate(-Math.PI / 4, width / 2, height / 2);
+ // g2d.rotate(-Math.PI, width / 2, height / 2);
+ g2d.setColor(LEAD_COLOR);
+
+ // Draw Leads
+ g2d.draw(new Line2D.Double(0, height / 2, width / 4, height / 2));
+ g2d.draw(new Line2D.Double(width, height / 2, width * 0.75, height / 2));
+
+ g2d.setColor(COLOR);
+
+ // Draw Ellipse
+ double startx = width / 4;
+ double starty = height / 4;
+ g2d.draw(new Ellipse2D.Double(startx, starty, 0.5 * width, 0.5 * height));
+
+ // Draw arrow
+
+ // g2d.setStroke();
+ g2d.draw(new Line2D.Double(startx + 0.25 * width / 2, starty + height / 4,
+ startx + 0.75 * width / 2, starty + height / 4));
+
+ g2d.draw(new Line2D.Double(startx + 0.25 * width / 2, starty + height / 4,
+ startx + (0.25 * width / 2) + 0.3 * (startx + (0.25 * width / 2)), (starty + height / 4) + height / 9));
+
+ g2d.draw(new Line2D.Double(startx + 0.25 * width / 2, starty + height / 4,
+ startx + (0.25 * width / 2) + 0.3 * (startx + (0.25 * width / 2)), (starty + height / 4) - height / 9));
+ }
+
+ @Override
+ public String getControlPointNodeName(int index) {
+ return getName() + "." + (index == 0 ? "+" : "-");
+ }
+
+ public enum SourceStyle {
+ Standard, Alternate
+ }
+}
\ No newline at end of file
diff --git a/diylc/diylc-library/src/org/diylc/components/misc/VoltageSourceSymbol.java b/diylc/diylc-library/src/org/diylc/components/misc/VoltageSourceSymbol.java
index 38ff2212..ae758cb9 100644
--- a/diylc/diylc-library/src/org/diylc/components/misc/VoltageSourceSymbol.java
+++ b/diylc/diylc-library/src/org/diylc/components/misc/VoltageSourceSymbol.java
@@ -1,67 +1,63 @@
-/*
-
- DIY Layout Creator (DIYLC).
- Copyright (c) 2009-2018 held jointly by the individual authors.
-
- This file is part of DIYLC.
-
- DIYLC is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- DIYLC is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with DIYLC. If not, see .
-
-*/
+/*
+
+ DIY Layout Creator (DIYLC).
+ Copyright (c) 2009-2018 held jointly by the individual authors.
+
+ This file is part of DIYLC.
+
+ DIYLC is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ DIYLC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DIYLC. If not, see .
+
+*/
package org.diylc.components.misc;
-import java.awt.Graphics2D;
-import java.awt.Shape;
-import java.awt.geom.CubicCurve2D;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Line2D;
-import org.diylc.components.AbstractSchematicLeadedSymbol;
-import org.diylc.core.CreationMethod;
-import org.diylc.core.IDIYComponent;
-import org.diylc.core.annotations.ComponentDescriptor;
-import org.diylc.core.annotations.EditableProperty;
-import org.diylc.core.measures.Size;
-import org.diylc.core.measures.SizeUnit;
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.CubicCurve2D;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Line2D;
+import org.diylc.components.AbstractSchematicLeadedSymbol;
+import org.diylc.core.CreationMethod;
+import org.diylc.core.IDIYComponent;
+import org.diylc.core.annotations.ComponentDescriptor;
+import org.diylc.core.annotations.EditableProperty;
+import org.diylc.core.measures.Size;
+import org.diylc.core.measures.SizeUnit;
import org.diylc.core.measures.VoltageUnit;
-@ComponentDescriptor(name = "Voltage Source", author = "JD", category = "Schematic Symbols",
- creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "V", description = "Voltage Source schematic symbol",
- zOrder = IDIYComponent.COMPONENT)
-
-/** Component type for Voltage Source Symbol, options for both AC and DC.
- * Modified from the Battery Symbol component.
- * Author: JD
- *
- * @author JD
+@ComponentDescriptor(name = "Voltage Source", author = "JD", category = "Schematic Symbols", creationMethod = CreationMethod.POINT_BY_POINT,
+ instanceNamePrefix = "V", description = "Voltage Source schematic symbol", zOrder = IDIYComponent.COMPONENT)
+
+/**
+ * Component type for Voltage Source Symbol, options for both AC and DC.
+ * Modified from the Battery Symbol component. Author: JD
+ *
+ * @author JD
*/
public class VoltageSourceSymbol extends AbstractSchematicLeadedSymbol {
-
- // FIELDS
+
private static final long serialVersionUID = 1L;
- private String value = "Voltage Source";
- private SourceType source_Type = SourceType.DC;
-
- // Overall size
- public static Size DEFAULT_LENGTH = new Size(0.2, SizeUnit.in);
- public static Size DEFAULT_WIDTH = new Size(0.2, SizeUnit.in);
-
+ private String value = "Voltage Source";
+ private SourceType source_Type = SourceType.DC;
+
+ // Overall size
+ public static Size DEFAULT_LENGTH = new Size(0.2, SizeUnit.in);
+ public static Size DEFAULT_WIDTH = new Size(0.2, SizeUnit.in);
+
// Sets voltage to 5V by default
private org.diylc.core.measures.Voltage voltageNew = new org.diylc.core.measures.Voltage(5d, VoltageUnit.V);
-
- // METHODS
-
+
@Override
public String getValueForDisplay() {
return getValue().toString() + (getVoltageNew() == null ? "" : " " + getVoltageNew().toString());
@@ -84,28 +80,30 @@ public class VoltageSourceSymbol extends AbstractSchematicLeadedSymbol {
public void setVoltageNew(org.diylc.core.measures.Voltage voltageNew) {
this.voltageNew = voltageNew;
}
-
- /** Returns whether the source is AC or DC.
- * Uses Enum "SourceType"
- * Author: JD (Modified Bancika's code, credit to Bancika)
- * @return
- */
- @EditableProperty
- public SourceType getSourceType() {
- if (source_Type == null)
- source_Type = SourceType.DC;
- return source_Type;
- }
-
- /** Sets whether the source is AC or DC.
- * Uses Enum "SourceType"
- * Author: JD (Modified Bancika's code, credit to Bancika)
- * @param source_Type
- */
- public void setSourceType(SourceType source_Type) {
- this.source_Type = source_Type;
- }
-
+
+ /**
+ * Returns whether the source is AC or DC. Uses Enum "SourceType" Author: JD
+ * (Modified Bancika's code, credit to Bancika)
+ *
+ * @return
+ */
+ @EditableProperty(name = "Source Type")
+ public SourceType getSourceType() {
+ if (source_Type == null)
+ source_Type = SourceType.DC;
+ return source_Type;
+ }
+
+ /**
+ * Sets whether the source is AC or DC. Uses Enum "SourceType" Author: JD
+ * (Modified Bancika's code, credit to Bancika)
+ *
+ * @param source_Type
+ */
+ public void setSourceType(SourceType source_Type) {
+ this.source_Type = source_Type;
+ }
+
@Override
protected Size getDefaultWidth() {
return DEFAULT_WIDTH;
@@ -117,80 +115,84 @@ public class VoltageSourceSymbol extends AbstractSchematicLeadedSymbol {
}
@Override
- protected Shape getBodyShape() {
- // Main body is a circle, drawn with an Ellipse
- double width = getWidth().convertToPixels();
- double length = getLength().convertToPixels();
- GeneralPath body = new GeneralPath();
- body.append(new Ellipse2D.Double(0d, 0d, width, length), true);
- return (Shape)body;
+ protected Shape getBodyShape() {
+ // Main body is a circle, drawn with an Ellipse
+ double width = getWidth().convertToPixels();
+ double length = getLength().convertToPixels();
+ GeneralPath body = new GeneralPath();
+ body.append(new Ellipse2D.Double(0d, 0d, width, length), true);
+ return (Shape) body;
}
@Override
- protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
- g2d.setColor(getBorderColor());
- double arbritaryLength = getWidth().convertToPixels();
- switch (getSourceType()){
- case AC: // AC Source, inside will be a sine wave
- // Cubic curve format is: (x1, y1, cx1, cy1, cx2, cy2, x2, y2)
- g2d.draw(new CubicCurve2D.Double(0.2 * arbritaryLength, arbritaryLength / 2, // x1, y1
- 0.5 * arbritaryLength, - arbritaryLength * 0.3, // cx1, cy1
- 0.5 * arbritaryLength, arbritaryLength + arbritaryLength * 0.3, // cx2, cy2
- 0.8 * arbritaryLength, arbritaryLength / 2)); // x2, y2
- break;
- case DC: // DC Source, inside will have "+" & "-" signs
- double plusSize = arbritaryLength / 6; // Plus sign is 1/6 of overall size
- // Draw "+" sign
- g2d.draw(new Line2D.Double(arbritaryLength*0.1, arbritaryLength/2,
- arbritaryLength*0.1 + plusSize, arbritaryLength/2));
-
- g2d.draw(new Line2D.Double(arbritaryLength*0.1 + plusSize/2, arbritaryLength/2 + plusSize/2,
- arbritaryLength*0.1 + plusSize/2, arbritaryLength/2 - plusSize/2));
- // Draw "-" Sign
- g2d.draw(new Line2D.Double(arbritaryLength*0.76 + plusSize/2, arbritaryLength/2 + plusSize/2,
- arbritaryLength*0.76 + plusSize/2, arbritaryLength/2 - plusSize/2));
- break;
- default:
- }
+ protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
+ g2d.setColor(getBorderColor());
+ double arbritaryLength = getWidth().convertToPixels();
+ switch (getSourceType()) {
+
+ case AC: // AC Source, inside will be a sine wave
+ // Cubic curve format is: (x1, y1, cx1, cy1, cx2, cy2, x2, y2)
+ g2d.draw(new CubicCurve2D.Double(0.2 * arbritaryLength, arbritaryLength / 2, // x1, y1
+ 0.5 * arbritaryLength, -arbritaryLength * 0.3, // cx1, cy1
+ 0.5 * arbritaryLength, arbritaryLength + arbritaryLength * 0.3, // cx2, cy2
+ 0.8 * arbritaryLength, arbritaryLength / 2)); // x2, y2
+ break;
+
+ case DC: // DC Source, inside will have "+" & "-" signs
+ double plusSize = arbritaryLength / 6; // Plus sign is 1/6 of overall size
+ // Draw "+" sign
+ g2d.draw(new Line2D.Double(arbritaryLength * 0.1, arbritaryLength / 2,
+ arbritaryLength * 0.1 + plusSize, arbritaryLength / 2));
+
+ g2d.draw(new Line2D.Double(arbritaryLength * 0.1 + plusSize / 2, arbritaryLength / 2 + plusSize / 2,
+ arbritaryLength * 0.1 + plusSize / 2, arbritaryLength / 2 - plusSize / 2));
+ // Draw "-" Sign
+ g2d.draw(new Line2D.Double(arbritaryLength * 0.76 + plusSize / 2, arbritaryLength / 2 + plusSize / 2,
+ arbritaryLength * 0.76 + plusSize / 2, arbritaryLength / 2 - plusSize / 2));
+ break;
+ default:
+ }
}
public void drawIcon(Graphics2D g2d, int width, int height) {
- g2d.rotate(-Math.PI / 4, width / 2, height / 2);
+ g2d.rotate(-Math.PI / 4, width / 2, height / 2);
// g2d.rotate(-Math.PI, width / 2, height / 2);
- g2d.setColor(LEAD_COLOR);
-
- // Draw Leads
- g2d.draw(new Line2D.Double(0, height / 2, width / 4, height / 2));
- g2d.draw(new Line2D.Double(width, height / 2, width * 0.75, height / 2));
-
- g2d.setColor(COLOR);
- // Draw Ellipse
- double startx = width/4;
- double starty = height/4;
-
- g2d.draw(new Ellipse2D.Double(startx, starty, 0.5 * width, 0.5 * height));
-
- // Draw signs
- double arbritaryLength = width * 0.5;
- double plusSize = arbritaryLength / 5; // Plus sign is 1/5 of overall size
-
- // Draw "+" sign
- g2d.draw(new Line2D.Double(startx + arbritaryLength*0.12, starty + arbritaryLength/2,
- startx + arbritaryLength*0.12 + plusSize, starty + arbritaryLength/2));
-
- g2d.draw(new Line2D.Double(startx + arbritaryLength*0.12 + plusSize/2, starty + arbritaryLength/2 + plusSize/2,
- startx + arbritaryLength*0.12 + plusSize/2, starty + arbritaryLength/2 -1*(plusSize/2)));
- // Draw "-" Sign
- g2d.draw(new Line2D.Double(startx + arbritaryLength*0.72 + plusSize/2, starty + arbritaryLength/2 + plusSize/2,
- startx + arbritaryLength*0.72 + plusSize/2, starty + arbritaryLength/2 -1*(plusSize/2)));
- }
-
- @Override
- public String getControlPointNodeName(int index) {
- return getName() + "." + (index == 0 ? "+" : "-");
- }
-
- public enum SourceType {
- AC, DC
+ g2d.setColor(LEAD_COLOR);
+
+ // Draw Leads
+ g2d.draw(new Line2D.Double(0, height / 2, width / 4, height / 2));
+ g2d.draw(new Line2D.Double(width, height / 2, width * 0.75, height / 2));
+
+ g2d.setColor(COLOR);
+ // Draw Ellipse
+ double startx = width / 4;
+ double starty = height / 4;
+
+ g2d.draw(new Ellipse2D.Double(startx, starty, 0.5 * width, 0.5 * height));
+
+ // Draw signs
+ double arbritaryLength = width * 0.5;
+ double plusSize = arbritaryLength / 5; // Plus sign is 1/5 of overall size
+
+ // Draw "+" sign
+ g2d.draw(new Line2D.Double(startx + arbritaryLength * 0.12, starty + arbritaryLength / 2,
+ startx + arbritaryLength * 0.12 + plusSize, starty + arbritaryLength / 2));
+
+ g2d.draw(
+ new Line2D.Double(startx + arbritaryLength * 0.12 + plusSize / 2, starty + arbritaryLength / 2 + plusSize / 2,
+ startx + arbritaryLength * 0.12 + plusSize / 2, starty + arbritaryLength / 2 - 1 * (plusSize / 2)));
+ // Draw "-" Sign
+ g2d.draw(
+ new Line2D.Double(startx + arbritaryLength * 0.72 + plusSize / 2, starty + arbritaryLength / 2 + plusSize / 2,
+ startx + arbritaryLength * 0.72 + plusSize / 2, starty + arbritaryLength / 2 - 1 * (plusSize / 2)));
}
-}
\ No newline at end of file
+
+ @Override
+ public String getControlPointNodeName(int index) {
+ return getName() + "." + (index == 0 ? "+" : "-");
+ }
+
+ public enum SourceType {
+ AC, DC
+ }
+}