diff --git a/diylc/diylc-core/src/org/diylc/presenter/update.xml b/diylc/diylc-core/src/org/diylc/presenter/update.xml index 892fcd1c..7e084a10 100644 --- a/diylc/diylc-core/src/org/diylc/presenter/update.xml +++ b/diylc/diylc-core/src/org/diylc/presenter/update.xml @@ -4441,7 +4441,11 @@ NEW_FEATURE Added two types of 4PDT On/On/On Switches, e.g. DiMarzio EP1111 (thank you Lukasz Tekieli) - + + + NEW_FEATURE + Ability to set explicit dimensions of basic shapes - rectangles and ellipses + IMPROVEMENT Better rendering of the effective circuit graph in the guitar wiring analyzer, showing series and parallel connections in a more intuitive way diff --git a/diylc/diylc-library/lib/diylc-core.jar b/diylc/diylc-library/lib/diylc-core.jar index ca132f01..2a633017 100644 Binary files a/diylc/diylc-library/lib/diylc-core.jar and b/diylc/diylc-library/lib/diylc-core.jar differ diff --git a/diylc/diylc-library/src/org/diylc/components/boards/ShapeModeValidator.java b/diylc/diylc-library/src/org/diylc/components/boards/ShapeModeValidator.java new file mode 100644 index 00000000..0c7adbf8 --- /dev/null +++ b/diylc/diylc-library/src/org/diylc/components/boards/ShapeModeValidator.java @@ -0,0 +1,21 @@ +package org.diylc.components.boards; + +import org.diylc.components.boards.AbstractBoard.BoardSizingMode; +import org.diylc.components.shapes.AbstractShapeWithDimensions; +import org.diylc.components.shapes.AbstractShapeWithDimensions.ShapeSizingMode; +import org.diylc.core.IPropertyValidator; +import org.diylc.core.ValidationException; +import org.diylc.core.measures.Size; + +public class ShapeModeValidator implements IPropertyValidator { + + public ShapeModeValidator() {} + + @Override + public void validate(Object owner, Object value) throws ValidationException { + AbstractShapeWithDimensions board = (AbstractShapeWithDimensions)owner; + Size size = (Size)value; + if (board.getMode() == ShapeSizingMode.Explicit && (value == null || size.getValue() == null || size.getUnit() == null)) + throw new ValidationException("Dimensions are required when mode is set to " + BoardSizingMode.Explicit); + } +} \ No newline at end of file diff --git a/diylc/diylc-library/src/org/diylc/components/shapes/AbstractShape.java b/diylc/diylc-library/src/org/diylc/components/shapes/AbstractShape.java index 597183c7..f1aa5461 100644 --- a/diylc/diylc-library/src/org/diylc/components/shapes/AbstractShape.java +++ b/diylc/diylc-library/src/org/diylc/components/shapes/AbstractShape.java @@ -1,33 +1,33 @@ -/* - - 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.shapes; -import java.awt.Color; -import java.awt.geom.Point2D; -import org.diylc.components.AbstractTransparentComponent; -import org.diylc.core.VisibilityPolicy; -import org.diylc.core.annotations.EditableProperty; -import org.diylc.core.annotations.PositiveMeasureValidator; -import org.diylc.core.measures.Size; +import java.awt.Color; +import java.awt.geom.Point2D; +import org.diylc.components.AbstractTransparentComponent; +import org.diylc.core.VisibilityPolicy; +import org.diylc.core.annotations.EditableProperty; +import org.diylc.core.annotations.PositiveMeasureValidator; +import org.diylc.core.measures.Size; import org.diylc.core.measures.SizeUnit; public abstract class AbstractShape extends AbstractTransparentComponent { @@ -103,11 +103,11 @@ public abstract class AbstractShape extends AbstractTransparentComponent { Math.min(controlPoints[0].getY(), controlPoints[1].getY())); secondPoint.setLocation(Math.max(controlPoints[0].getX(), controlPoints[1].getX()), Math.max(controlPoints[0].getY(), controlPoints[1].getY())); - } - - @Override - public String getControlPointNodeName(int index) { - return null; + } + + @Override + public String getControlPointNodeName(int index) { + return null; } @Deprecated diff --git a/diylc/diylc-library/src/org/diylc/components/shapes/AbstractShapeWithDimensions.java b/diylc/diylc-library/src/org/diylc/components/shapes/AbstractShapeWithDimensions.java new file mode 100644 index 00000000..2dffc3d1 --- /dev/null +++ b/diylc/diylc-library/src/org/diylc/components/shapes/AbstractShapeWithDimensions.java @@ -0,0 +1,134 @@ +/* + + 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.shapes; + +import java.awt.geom.Point2D; +import org.diylc.appframework.miscutils.ConfigurationManager; +import org.diylc.common.IPlugInPort; +import org.diylc.components.boards.ShapeModeValidator; +import org.diylc.core.VisibilityPolicy; +import org.diylc.core.annotations.EditableProperty; +import org.diylc.core.measures.Size; +import org.diylc.core.measures.SizeUnit; + +public abstract class AbstractShapeWithDimensions extends AbstractShape { + + private static final long serialVersionUID = 1L; + + protected Size length; + protected Size width; + protected ShapeSizingMode mode = ShapeSizingMode.TwoPoints; + + @Override + public VisibilityPolicy getControlPointVisibilityPolicy(int index) { + return getMode() == ShapeSizingMode.TwoPoints ? VisibilityPolicy.WHEN_SELECTED : VisibilityPolicy.NEVER; + } + + protected Point2D getFinalSecondPoint() { + Point2D finalSecondPoint; + if (getMode() == ShapeSizingMode.TwoPoints) + finalSecondPoint = secondPoint; + else + finalSecondPoint = new Point2D.Double(firstPoint.getX() + getLength().convertToPixels(), + firstPoint.getY() + getWidth().convertToPixels()); + return finalSecondPoint; + } + + @Override + public void setControlPoint(Point2D point, int index) { + controlPoints[index].setLocation(point); + firstPoint.setLocation(Math.min(controlPoints[0].getX(), controlPoints[1].getX()), + Math.min(controlPoints[0].getY(), controlPoints[1].getY())); + secondPoint.setLocation(Math.max(controlPoints[0].getX(), controlPoints[1].getX()), + Math.max(controlPoints[0].getY(), controlPoints[1].getY())); + } + + + @EditableProperty(name = "Dimension Mode") + public ShapeSizingMode getMode() { + if (mode == null) + mode = ShapeSizingMode.TwoPoints; + return mode; + } + + public void setMode(ShapeSizingMode mode) { + this.mode = mode; + } + + @EditableProperty(name = "Explicit Length", validatorClass = ShapeModeValidator.class) + public Size getLength() { + if (getMode() == ShapeSizingMode.TwoPoints) { + double lengthPx = Math.abs(this.firstPoint.getX() - this.secondPoint.getX()); + this.length = Size.fromPixels(lengthPx, length == null ? getDefaultUnit() : length.getUnit()); + } + return this.length; + } + + public void setLength(Size length) { + if (getMode() == ShapeSizingMode.Explicit && length != null && width != null) { + setControlPoint(firstPoint, 0); + Point2D second = new Point2D.Double(firstPoint.getX() + length.convertToPixels(), + firstPoint.getY() + width.convertToPixels()); + setControlPoint(second, 1); + } + this.length = length; + } + + @EditableProperty(name = "Explicit Width", validatorClass = ShapeModeValidator.class) + public Size getWidth() { + if (getMode() == ShapeSizingMode.TwoPoints) { + double widthPx = Math.abs(this.firstPoint.getY() - this.secondPoint.getY()); + this.width = Size.fromPixels(widthPx, width == null ? getDefaultUnit() : width.getUnit()); + } + return this.width; + } + + public void setWidth(Size width) { + if (getMode() == ShapeSizingMode.Explicit && length != null && width != null) { + setControlPoint(firstPoint, 0); + Point2D second = new Point2D.Double(firstPoint.getX() + length.convertToPixels(), firstPoint.getY() + width.convertToPixels()); + setControlPoint(second, 1); + } + this.width = width; + } + + private SizeUnit getDefaultUnit() { + if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.METRIC_KEY, true)) + return SizeUnit.mm; + return SizeUnit.in; + } + + public static enum ShapeSizingMode { + TwoPoints("Opposing Points"), Explicit("Explicit Dimensions"); + + private String label; + + private ShapeSizingMode(String label) { + this.label = label; + } + + @Override + public String toString() { + return label; + } + } +} diff --git a/diylc/diylc-library/src/org/diylc/components/shapes/Ellipse.java b/diylc/diylc-library/src/org/diylc/components/shapes/Ellipse.java index 6141d5b6..71ee4a81 100644 --- a/diylc/diylc-library/src/org/diylc/components/shapes/Ellipse.java +++ b/diylc/diylc-library/src/org/diylc/components/shapes/Ellipse.java @@ -36,7 +36,7 @@ import org.diylc.core.annotations.ComponentDescriptor; @ComponentDescriptor(name = "Ellipse", author = "Branislav Stojkovic", category = "Shapes", instanceNamePrefix = "ELL", description = "Elliptical area", zOrder = IDIYComponent.COMPONENT, flexibleZOrder = true, bomPolicy = BomPolicy.SHOW_ALL_NAMES, autoEdit = false, transformer = SimpleComponentTransformer.class) -public class Ellipse extends AbstractShape { +public class Ellipse extends AbstractShapeWithDimensions { private static final long serialVersionUID = 1L; diff --git a/diylc/diylc-library/src/org/diylc/components/shapes/Rectangle.java b/diylc/diylc-library/src/org/diylc/components/shapes/Rectangle.java index 733c7a93..99f72002 100644 --- a/diylc/diylc-library/src/org/diylc/components/shapes/Rectangle.java +++ b/diylc/diylc-library/src/org/diylc/components/shapes/Rectangle.java @@ -40,7 +40,7 @@ import org.diylc.core.measures.SizeUnit; instanceNamePrefix = "RECT", description = "Ractangular area, with or withouth rounded edges", zOrder = IDIYComponent.COMPONENT, flexibleZOrder = true, bomPolicy = BomPolicy.SHOW_ALL_NAMES, autoEdit = false, transformer = SimpleComponentTransformer.class) -public class Rectangle extends AbstractShape { +public class Rectangle extends AbstractShapeWithDimensions { private static final long serialVersionUID = 1L; diff --git a/diylc/diylc-swing/lib/diylc-core.jar b/diylc/diylc-swing/lib/diylc-core.jar index ca132f01..2a633017 100644 Binary files a/diylc/diylc-swing/lib/diylc-core.jar and b/diylc/diylc-swing/lib/diylc-core.jar differ diff --git a/diylc/diylc-swing/library/main.jar b/diylc/diylc-swing/library/main.jar index 6ceefa4b..f95652c8 100644 Binary files a/diylc/diylc-swing/library/main.jar and b/diylc/diylc-swing/library/main.jar differ