diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml b/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml index d6460070..65688254 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml @@ -12,7 +12,7 @@ metric - true + false default.org.diylc.components.semiconductors.DIL_IC:Value diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/library/main.jar b/ diy-layout-creator --username bancika@gmail.com/DIYLC/library/main.jar index e259da9c..fd61c492 100644 Binary files a/ diy-layout-creator --username bancika@gmail.com/DIYLC/library/main.jar and b/ diy-layout-creator --username bancika@gmail.com/DIYLC/library/main.jar differ diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractCurvedComponent.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractCurvedComponent.java index 5c35cecb..e3f145d8 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractCurvedComponent.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractCurvedComponent.java @@ -11,17 +11,21 @@ import java.awt.geom.CubicCurve2D; import org.diylc.core.ComponentState; import org.diylc.core.Project; import org.diylc.core.annotations.EditableProperty; -import org.diylc.utils.Constants; +import org.diylc.core.measures.Size; +import org.diylc.core.measures.SizeUnit; public abstract class AbstractCurvedComponent extends AbstractTransparentComponent { private static final long serialVersionUID = 1L; public static Color GUIDELINE_COLOR = Color.blue; + public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in); protected Point[] controlPoints = new Point[] { - new Point(-5 * Constants.GRID, -5 * Constants.GRID), new Point(0, -5 * Constants.GRID), - new Point(0, 5 * Constants.GRID), new Point(5 * Constants.GRID, 5 * Constants.GRID) }; + new Point(-DEFAULT_SIZE.convertToPixels() / 2, -DEFAULT_SIZE.convertToPixels() / 2), + new Point(0, -DEFAULT_SIZE.convertToPixels() / 2), + new Point(0, DEFAULT_SIZE.convertToPixels() / 2), + new Point(DEFAULT_SIZE.convertToPixels() / 2, DEFAULT_SIZE.convertToPixels() / 2) }; protected Color color = getDefaultColor(); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractLeadedComponent.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractLeadedComponent.java index 8684a7f9..72aaa07a 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractLeadedComponent.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractLeadedComponent.java @@ -32,11 +32,13 @@ public abstract class AbstractLeadedComponent extends AbstractTransparentComp public static Color LABEL_COLOR = Color.black; public static Color LABEL_COLOR_SELECTED = Color.red; public static Size LEAD_THICKNESS = new Size(0.3d, SizeUnit.mm); + public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in); protected Size width; protected Size height; - protected Point[] points = new Point[] { new Point((int) (-Constants.GRID * 5), 0), - new Point((int) (Constants.GRID * 5), 0) }; + protected Point[] points = new Point[] { + new Point((int) (-DEFAULT_SIZE.convertToPixels() / 2), 0), + new Point(DEFAULT_SIZE.convertToPixels() / 2, 0) }; protected Color bodyColor = getDefaultBodyColor(); protected Color borderColor = getDefaultBorderColor(); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/Project.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/Project.java index c659734b..bbeef943 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/Project.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/Project.java @@ -24,12 +24,14 @@ public class Project implements Serializable { public static String DEFAULT_TITLE = "New Project"; public static Size DEFAULT_WIDTH = new Size(29d, SizeUnit.cm); public static Size DEFAULT_HEIGHT = new Size(21d, SizeUnit.cm); + public static Size DEFAULT_GRID_SPACING = new Size(0.2d, SizeUnit.in); private String title; private String author; private String description; private Size width; private Size height; + private Size gridSpacing; private List> components; private Set>> groups; @@ -40,9 +42,10 @@ public class Project implements Serializable { author = System.getProperty("user.name"); width = DEFAULT_WIDTH; height = DEFAULT_HEIGHT; + gridSpacing = DEFAULT_GRID_SPACING; } - public Project(String title, String author, String description, Size width, Size height, + public Project(String title, String author, String description, Size width, Size height, Size gridSpacing, List> components, Set>> groups) { super(); this.title = title; @@ -50,6 +53,7 @@ public class Project implements Serializable { this.description = description; this.width = width; this.height = height; + this.gridSpacing = gridSpacing; this.components = components; this.groups = groups; } @@ -98,6 +102,15 @@ public class Project implements Serializable { public void setHeight(Size height) { this.height = height; } + + @EditableProperty + public Size getGridSpacing() { + return gridSpacing; + } + + public void setGridSpacing(Size gridSpacing) { + this.gridSpacing = gridSpacing; + } /** * List of components sorted by z-order ascending. diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/measures/Size.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/measures/Size.java index 9cf1701d..3be1be08 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/measures/Size.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/measures/Size.java @@ -17,10 +17,12 @@ public class Size extends AbstractMeasure { } public int convertToPixels() { - double factor = getUnit().getFactor() / SizeUnit.in.getFactor(); - int grids = (int) (factor * getValue() * Constants.GRIDS_PER_INCH); - double remainder = (factor * getValue() * Constants.GRIDS_PER_INCH) - grids; - return (int) Math.round(Constants.GRID * (grids + remainder)); +// double factor = getUnit().getFactor() / SizeUnit.in.getFactor(); +// int grids = (int) (factor * getValue() * Constants.GRIDS_PER_INCH); +// double remainder = (factor * getValue() * Constants.GRIDS_PER_INCH) - grids; +// return (int) Math.round(Constants.PIXELS_PER_INCH / Constants.GRIDS_PER_INCH +// * (grids + remainder)); + return (int) (getValue() * getUnit().getFactor() / SizeUnit.in.getFactor() * Constants.PIXELS_PER_INCH); } @Override diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java index 8dca5056..e6f3ef2e 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java @@ -58,7 +58,7 @@ public class Presenter implements IPlugInPort { private static final Logger LOG = Logger.getLogger(Presenter.class); - public static final VersionNumber CURRENT_VERSION = new VersionNumber(0, 0, 0); + public static final VersionNumber CURRENT_VERSION = new VersionNumber(0, 1, 0); public static final String DEFAULTS_KEY = "default."; public static final String METRIC_KEY = "metric"; @@ -235,7 +235,7 @@ public class Presenter implements IPlugInPort { g2dWrapper.fillRect(0, 0, d.width, d.height); if (drawOptions.contains(DrawOption.GRID)) { - double zoomStep = Constants.GRID * zoomLevel; + double zoomStep = currentProject.getGridSpacing().convertToPixels() * zoomLevel; g2dWrapper.setColor(Constants.GRID_COLOR); for (double i = zoomStep; i < d.width; i += zoomStep) { @@ -331,7 +331,8 @@ public class Presenter implements IPlugInPort { @Override public void injectGUIComponent(JComponent component, int position) throws BadPositionException { - LOG.info(String.format("injectGUIComponent(%s, %s)", component.getClass().getName(), position)); + LOG.info(String.format("injectGUIComponent(%s, %s)", component.getClass().getName(), + position)); view.addComponent(component, position); } @@ -620,24 +621,25 @@ public class Presenter implements IPlugInPort { int dx = (scaledPoint.x - previousDragPoint.x); int dy = (scaledPoint.y - previousDragPoint.y); if (snapToGrid) { - dx = (int) (Math.round(dx / Constants.GRID) * Constants.GRID); - dy = (int) (Math.round(dy / Constants.GRID) * Constants.GRID); + dx = roundToGrid(dx); + dy = roundToGrid(dy); } // Only repaint if there's an actual change. repaint = dx != 0 || dy != 0; - previousDragPoint.translate(dx, dy); + if (repaint) { + previousDragPoint.translate(dx, dy); - // Update all points. - for (Map.Entry, Set> entry : controlPointMap.entrySet()) { - IDIYComponent c = entry.getKey(); - for (Integer index : entry.getValue()) { - Point p = new Point(c.getControlPoint(index)); - p.translate(dx, dy); - c.setControlPoint(p, index); + // Update all points. + for (Map.Entry, Set> entry : controlPointMap.entrySet()) { + IDIYComponent c = entry.getKey(); + for (Integer index : entry.getValue()) { + Point p = new Point(c.getControlPoint(index)); + p.translate(dx, dy); + c.setControlPoint(p, index); + } } } - // dragStartPoint = point; } else if (selectedComponents.isEmpty()) { // If there's no selection, the only thing to do is update the // selection rectangle and refresh. @@ -654,6 +656,17 @@ public class Presenter implements IPlugInPort { return true; } + /** + * Rounds the number to the closest grid line. + * + * @param x + * @return + */ + private int roundToGrid(int x) { + int grid = currentProject.getGridSpacing().convertToPixels(); + return (Math.round(x / grid) * grid); + } + @Override public void dragEnded(Point point) { LOG.debug(String.format("dragEnded(%s)", point)); @@ -867,8 +880,8 @@ public class Presenter implements IPlugInPort { } double width = area.getBounds2D().getWidth(); double height = area.getBounds2D().getHeight(); - width /= Constants.GRID * Constants.GRIDS_PER_INCH; - height /= Constants.GRID * Constants.GRIDS_PER_INCH; + width /= Constants.PIXELS_PER_INCH; + height /= Constants.PIXELS_PER_INCH; if (isMetric) { width *= SizeUnit.in.getFactor() / SizeUnit.cm.getFactor(); height *= SizeUnit.in.getFactor() / SizeUnit.cm.getFactor(); @@ -935,8 +948,8 @@ public class Presenter implements IPlugInPort { int x = controlPoint.x + point.x; int y = controlPoint.y + point.y; if (snapToGrid) { - x = (int) (Math.round(x / Constants.GRID) * Constants.GRID); - y = (int) (Math.round(y / Constants.GRID) * Constants.GRID); + x = roundToGrid(x); + y = roundToGrid(y); } controlPoint.setLocation(x, y); component.setControlPoint(controlPoint, j); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/utils/Constants.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/utils/Constants.java index ceb795f9..5ddd7743 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/utils/Constants.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/utils/Constants.java @@ -5,15 +5,12 @@ import java.awt.Color; import java.awt.Font; import java.awt.Stroke; -import org.diylc.core.measures.Size; -import org.diylc.core.measures.SizeUnit; - public class Constants { -// public static final int PIXELS_PER_INCH = Toolkit.getDefaultToolkit().getScreenResolution(); - public static int GRIDS_PER_INCH = 10; - public static Size GRID_SIZE = new Size(1d / GRIDS_PER_INCH, SizeUnit.in); - public static final int GRID = 10; + public static final int PIXELS_PER_INCH = 100;//Toolkit.getDefaultToolkit().getScreenResolution(); + public static int GRIDS_PER_INCH = 8; +// public static Size GRID_SIZE = new Size(1d / GRIDS_PER_INCH, SizeUnit.in); +// public static final int GRID = 20; public static Color CANVAS_COLOR = Color.white; public static Color GRID_COLOR = new Color(240, 240, 240); diff --git a/ diy-layout-creator --username bancika@gmail.com/Library/.classpath b/ diy-layout-creator --username bancika@gmail.com/Library/.classpath index 74a976b1..5602a8e8 100644 --- a/ diy-layout-creator --username bancika@gmail.com/Library/.classpath +++ b/ diy-layout-creator --username bancika@gmail.com/Library/.classpath @@ -2,6 +2,6 @@ - + diff --git a/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/boards/AbstractBoard.java b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/boards/AbstractBoard.java index 5ebd76f8..955bade3 100644 --- a/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/boards/AbstractBoard.java +++ b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/boards/AbstractBoard.java @@ -11,7 +11,8 @@ import org.diylc.components.AbstractTransparentComponent; import org.diylc.core.ComponentState; import org.diylc.core.Project; import org.diylc.core.annotations.EditableProperty; -import org.diylc.utils.Constants; +import org.diylc.core.measures.Size; +import org.diylc.core.measures.SizeUnit; public abstract class AbstractBoard extends AbstractTransparentComponent { @@ -19,12 +20,14 @@ public abstract class AbstractBoard extends AbstractTransparentComponent public static Color BOARD_COLOR = Color.decode("#BCED91"); public static Color BORDER_COLOR = BOARD_COLOR.darker(); + public static Size DEFAULT_WIDTH = new Size(1.5d, SizeUnit.in); + public static Size DEFAULT_HEIGHT = new Size(1d, SizeUnit.in); protected String name; protected String value; protected Point[] controlPoints = new Point[] { - new Point((int) (-5 * Constants.GRID), (int) (-5 * Constants.GRID)), - new Point((int) (5 * Constants.GRID), (int) (5 * Constants.GRID)) }; + new Point(-DEFAULT_WIDTH.convertToPixels() / 2, -DEFAULT_HEIGHT.convertToPixels() / 2), + new Point(DEFAULT_WIDTH.convertToPixels() / 2, DEFAULT_HEIGHT.convertToPixels() / 2) }; protected Color boardColor = BOARD_COLOR; protected Color borderColor = BORDER_COLOR; diff --git a/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/connectivity/HookupWire.java b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/connectivity/HookupWire.java index 9642f8ef..56f2a952 100644 --- a/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/connectivity/HookupWire.java +++ b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/connectivity/HookupWire.java @@ -30,7 +30,7 @@ public class HookupWire extends AbstractCurvedComponent { @Override protected void drawCurve(CubicCurve2D curve, Graphics2D g2d, ComponentState componentState) { int thickness = (int) (Math.pow(Math.E, -1.12436 - 0.11594 * value.getValue()) - * Constants.GRID * Constants.GRIDS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT)); + * Constants.PIXELS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT)); g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color.darker()); g2d.setStroke(new BasicStroke(thickness)); diff --git a/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/misc/BOM.java b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/misc/BOM.java index bf2786a4..33a37f0a 100644 --- a/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/misc/BOM.java +++ b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/misc/BOM.java @@ -25,7 +25,7 @@ import org.diylc.utils.Constants; public class BOM extends AbstractComponent { public static Size DEFAULT_SIZE = new Size(10d, SizeUnit.cm); - public static Size SPACING = Constants.GRID_SIZE; + public static Size SPACING = new Size(0.1d, SizeUnit.in); public static Color COLOR = Color.black; public static String DEFAULT_TEXT = "No components to show in the Bill of Materials"; diff --git a/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/misc/ProjectInformation.java b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/misc/ProjectInformation.java index a2dd961b..fcbe87f9 100644 --- a/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/misc/ProjectInformation.java +++ b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/misc/ProjectInformation.java @@ -20,7 +20,6 @@ import org.diylc.utils.Constants; public class ProjectInformation extends AbstractComponent { public static Size DEFAULT_SIZE = new Size(10d, SizeUnit.cm); - public static Size SPACING = Constants.GRID_SIZE; public static Color COLOR = Color.black; public static String DEFAULT_TEXT = "No components to show in the Bill of Materials"; diff --git a/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/semiconductors/DIL_IC.java b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/semiconductors/DIL_IC.java index aa3981d7..f0ddad31 100644 --- a/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/semiconductors/DIL_IC.java +++ b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/semiconductors/DIL_IC.java @@ -41,13 +41,16 @@ public class DIL_IC extends AbstractTransparentComponent { private String value = ""; private Orientation orientation = Orientation.DEFAULT; private PinCount pinCount = PinCount._8; + private Size pinSpacing = new Size(0.1d, SizeUnit.in); private Size rowSpacing = new Size(0.3d, SizeUnit.in); - private Point[] controlPoints = new Point[] { new Point(0, 0), - new Point(0, (int) Constants.GRID), new Point(0, (int) (2 * Constants.GRID)), - new Point(0, (int) (3 * Constants.GRID)), new Point((int) (3 * Constants.GRID), 0), - new Point((int) (3 * Constants.GRID), (int) Constants.GRID), - new Point((int) (3 * Constants.GRID), (int) (2 * Constants.GRID)), - new Point((int) (3 * Constants.GRID), (int) (3 * Constants.GRID)) }; + private Point[] controlPoints = new Point[] { new Point(0, 0) }; +// new Point(0, pinSpacing.convertToPixels()), +// new Point(0, 2 * pinSpacing.convertToPixels()), +// new Point(0, 3 * pinSpacing.convertToPixels()), +// new Point(3 * pinSpacing.convertToPixels(), 0), +// new Point(3 * pinSpacing.convertToPixels(), pinSpacing.convertToPixels()), +// new Point(3 * pinSpacing.convertToPixels(), 2 * pinSpacing.convertToPixels()), +// new Point(3 * pinSpacing.convertToPixels(), 3 * pinSpacing.convertToPixels()) }; private Shape body; public DIL_IC() { @@ -87,6 +90,15 @@ public class DIL_IC extends AbstractTransparentComponent { body = null; } + @EditableProperty(name = "Pin spacing") + public Size getPinSpacing() { + return pinSpacing; + } + + public void setPinSpacing(Size pinSpacing) { + this.pinSpacing = pinSpacing; + } + @EditableProperty(name = "Row spacing") public Size getRowSpacing() { return rowSpacing; @@ -128,26 +140,26 @@ public class DIL_IC extends AbstractTransparentComponent { switch (orientation) { case DEFAULT: dx1 = 0; - dy1 = (int) (i * Constants.GRID); + dy1 = i * pinSpacing.convertToPixels(); dx2 = rowSpacing.convertToPixels(); - dy2 = (int) (i * Constants.GRID); + dy2 = i * pinSpacing.convertToPixels(); break; case _90: - dx1 = (int) (-i * Constants.GRID); + dx1 = -i * pinSpacing.convertToPixels(); dy1 = 0; - dx2 = (int) (-i * Constants.GRID); + dx2 = -i * pinSpacing.convertToPixels(); dy2 = rowSpacing.convertToPixels(); break; case _180: dx1 = 0; - dy1 = (int) (-i * Constants.GRID); + dy1 = -i * pinSpacing.convertToPixels(); dx2 = -rowSpacing.convertToPixels(); - dy2 = (int) (-i * Constants.GRID); + dy2 = -i * pinSpacing.convertToPixels(); break; case _270: - dx1 = (int) (i * Constants.GRID); + dx1 = i * pinSpacing.convertToPixels(); dy1 = 0; - dx2 = (int) (i * Constants.GRID); + dx2 = i * pinSpacing.convertToPixels(); dy2 = rowSpacing.convertToPixels(); break; default: @@ -169,26 +181,26 @@ public class DIL_IC extends AbstractTransparentComponent { switch (orientation) { case DEFAULT: width = rowSpacing.convertToPixels() - pinSize; - height = (int) ((pinCount.getValue() / 2) * Constants.GRID); + height = (pinCount.getValue() / 2) * pinSpacing.convertToPixels(); x += pinSize / 2; - y -= (int) (Constants.GRID / 2); + y -= pinSpacing.convertToPixels() / 2; break; case _90: - width = (int) ((pinCount.getValue() / 2) * Constants.GRID); + width = (pinCount.getValue() / 2) * pinSpacing.convertToPixels(); height = rowSpacing.convertToPixels() - pinSize; - x -= (int) (Constants.GRID / 2) + width - Constants.GRID; + x -= (pinSpacing.convertToPixels() / 2) + width - pinSpacing.convertToPixels(); y += pinSize / 2; break; case _180: width = rowSpacing.convertToPixels() - pinSize; - height = (int) ((pinCount.getValue() / 2) * Constants.GRID); + height = (pinCount.getValue() / 2) * pinSpacing.convertToPixels(); x -= rowSpacing.convertToPixels() - pinSize / 2; - y -= (int) (Constants.GRID / 2) + height - Constants.GRID; + y -= (pinSpacing.convertToPixels() / 2) + height - pinSpacing.convertToPixels(); break; case _270: - width = (int) ((pinCount.getValue() / 2) * Constants.GRID); + width = (pinCount.getValue() / 2) * pinSpacing.convertToPixels(); height = rowSpacing.convertToPixels() - pinSize; - x -= (int) (Constants.GRID / 2); + x -= pinSpacing.convertToPixels() / 2; y += pinSize / 2; break; default: