Added few chassis-related components under "Electromechanical" category

fixed thin line style when zoomed in
This commit is contained in:
Branislav Stojkovic
2018-12-18 18:38:39 +01:00
parent 680397b44f
commit 3fec176fc1
13 changed files with 406 additions and 8 deletions
@@ -63,6 +63,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
public static Color LABEL_COLOR_SELECTED = Color.red; public static Color LABEL_COLOR_SELECTED = Color.red;
public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 14); public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 14);
public static Color METAL_COLOR = Color.decode("#759DAF"); public static Color METAL_COLOR = Color.decode("#759DAF");
public static Color LIGHT_METAL_COLOR = Color.decode("#EEEEEE");
public static Color COPPER_COLOR = Color.decode("#DA8A67"); public static Color COPPER_COLOR = Color.decode("#DA8A67");
@EditableProperty(defaultable = false) @EditableProperty(defaultable = false)
@@ -403,11 +403,11 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
@Override @Override
public void setStroke(Stroke s) { public void setStroke(Stroke s) {
if (this.zoom > 1 && s.getClass() == BasicStroke.class) { if (this.zoom > 1 && s instanceof BasicStroke) {
BasicStroke bs = (BasicStroke) s; BasicStroke bs = (BasicStroke) s;
// make thin lines even thinner to compensate for zoom factor // make thin lines even thinner to compensate for zoom factor
if (bs.getLineWidth() <= 2) if (bs.getLineWidth() <= 2)
s = ObjectCache.getInstance().fetchBasicStroke((float) (bs.getLineWidth() / zoom)); s = ObjectCache.getInstance().fetchStroke((float) (bs.getLineWidth() / zoom), bs.getDashArray(), bs.getDashPhase());
} }
canvasGraphics.setStroke(s); canvasGraphics.setStroke(s);
} }
@@ -36,7 +36,7 @@ public class Constants {
public static Color CANVAS_COLOR = Color.white; public static Color CANVAS_COLOR = Color.white;
public static final Stroke DASHED_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, public static final Stroke DASHED_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f,
new float[] {2.0f}, 0.0f); new float[] {2.0f, 4.0f}, 0.0f);
public static final Theme DEFAULT_THEME = new Theme("Light", Constants.CANVAS_COLOR, new Color(240, 240, 240), public static final Theme DEFAULT_THEME = new Theme("Light", Constants.CANVAS_COLOR, new Color(240, 240, 240),
Color.black); Color.black);
Binary file not shown.
@@ -0,0 +1,97 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
package org.diylc.components.chassis;
import java.awt.AlphaComposite;
import java.awt.Composite;
import java.awt.Graphics2D;
import org.diylc.common.ObjectCache;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.shapes.AbstractShape;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Chassis Panel", author = "Branislav Stojkovic", category = "Electromechanical",
instanceNamePrefix = "CP", description = "One side of a chassis, with or withouth rounded edges",
zOrder = IDIYComponent.CHASSIS, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false,
transformer = SimpleComponentTransformer.class)
public class ChassisPanel extends AbstractShape {
private static final long serialVersionUID = 1L;
protected Size edgeRadius = new Size(0d, SizeUnit.mm);
public ChassisPanel() {
this.color = LIGHT_METAL_COLOR;
this.borderColor = LIGHT_METAL_COLOR.darker();
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels()));
int radius = (int) edgeRadius.convertToPixels();
if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
g2d.setColor(color);
g2d.fillRoundRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y, radius,
radius);
g2d.setComposite(oldComposite);
}
// Do not track any changes that follow because the whole rect has been
// tracked so far.
drawingObserver.stopTracking();
g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor);
g2d.drawRoundRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y, radius,
radius);
}
@EditableProperty(name = "Radius")
public Size getEdgeRadius() {
return edgeRadius;
}
public void setEdgeRadius(Size edgeRadius) {
this.edgeRadius = edgeRadius;
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(LIGHT_METAL_COLOR);
g2d.fillRect(2 / factor, 4 / factor, width - 4 / factor, height - 8 / factor);
g2d.setColor(LIGHT_METAL_COLOR.darker());
g2d.drawRect(2 / factor, 4 / factor, width - 4 / factor, height - 8 / factor);
}
}
@@ -0,0 +1,75 @@
/*
*
* 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
* <http://www.gnu.org/licenses/>.
*/
package org.diylc.components.chassis;
import java.awt.AlphaComposite;
import java.awt.Composite;
import java.awt.Graphics2D;
import org.diylc.common.ObjectCache;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.shapes.AbstractShape;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
@ComponentDescriptor(name = "Elliptical Cutout", author = "Branislav Stojkovic", category = "Electromechanical",
instanceNamePrefix = "ELC", description = "Elliptical chassis cutout", zOrder = IDIYComponent.CHASSIS + 0.1,
bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class)
public class EllipticalCutout extends AbstractShape {
private static final long serialVersionUID = 1L;
public EllipticalCutout() {
this.borderColor = LIGHT_METAL_COLOR.darker();
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels()));
if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
g2d.setColor(color);
g2d.fillOval(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y);
g2d.setComposite(oldComposite);
}
// Do not track any changes that follow because the whole oval has been
// tracked so far.
drawingObserver.stopTracking();
g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor);
g2d.drawOval(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(COLOR);
g2d.fillOval(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
g2d.setColor(LIGHT_METAL_COLOR.darker());
g2d.drawOval(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
}
}
@@ -0,0 +1,125 @@
/*
*
* 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
* <http://www.gnu.org/licenses/>.
*/
package org.diylc.components.chassis;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.Arrays;
import org.diylc.common.ObjectCache;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.shapes.AbstractShape;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
@ComponentDescriptor(name = "Polygonal Cutout", author = "Branislav Stojkovic", category = "Electromechanical",
instanceNamePrefix = "POLYC", description = "Polygonal chassis cutout", zOrder = IDIYComponent.CHASSIS + 0.1,
bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class)
public class PolygonalCutout extends AbstractShape {
private static final long serialVersionUID = 1L;
protected PointCount pointCount = PointCount._4;
public PolygonalCutout() {
super();
this.borderColor = LIGHT_METAL_COLOR.darker();
this.controlPoints =
new Point[] {new Point(0, 0), new Point(0, (int) DEFAULT_HEIGHT.convertToPixels()),
new Point((int) DEFAULT_WIDTH.convertToPixels(), (int) DEFAULT_HEIGHT.convertToPixels()),
new Point((int) DEFAULT_WIDTH.convertToPixels(), 0)};
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels()));
g2d.setColor(color);
int[] xPoints = new int[controlPoints.length];
int[] yPoints = new int[controlPoints.length];
for (int i = 0; i < controlPoints.length; i++) {
xPoints[i] = controlPoints[i].x;
yPoints[i] = controlPoints[i].y;
}
Composite oldComposite = g2d.getComposite();
if (this.alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(3, 1.0F * this.alpha / MAX_ALPHA));
}
g2d.fillPolygon(xPoints, yPoints, controlPoints.length);
g2d.setComposite(oldComposite);
// Do not track any changes that follow because the whole board has been
// tracked so far.
drawingObserver.stopTracking();
Color lineColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor;
g2d.setColor(lineColor);
g2d.drawPolygon(xPoints, yPoints, controlPoints.length);
}
@EditableProperty(name = "Edges")
public PointCount getPointCount() {
return pointCount;
}
public void setPointCount(PointCount pointCount) {
if (this.pointCount == pointCount)
return;
int oldPointCount = Integer.parseInt(this.pointCount.toString());
int newPointCount = Integer.parseInt(pointCount.toString());
this.controlPoints = Arrays.copyOf(this.controlPoints, newPointCount);
if (oldPointCount < newPointCount) {
this.controlPoints[newPointCount - 1] = this.controlPoints[oldPointCount - 1];
for (int i = oldPointCount - 1; i < newPointCount - 1; i++) {
this.controlPoints[i] =
new Point((this.controlPoints[i - 1].x + this.controlPoints[newPointCount - 1].x) / 2,
(this.controlPoints[i - 1].y + this.controlPoints[newPointCount - 1].y) / 2);
}
}
this.pointCount = pointCount;
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(COLOR);
int[] x = {2 / factor, width - 2 / factor, width - 4 / factor, 3 / factor};
int[] y = {4 / factor, 2 / factor, height - 5 / factor, height - 2 / factor};
g2d.fillPolygon(x, y, 4);
g2d.setColor(LIGHT_METAL_COLOR.darker());
g2d.drawPolygon(x, y, 4);
}
public enum PointCount {
_3, _4, _5, _6, _7, _8;
public String toString() {
return name().substring(1);
};
}
}
@@ -0,0 +1,92 @@
/*
*
* 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
* <http://www.gnu.org/licenses/>.
*/
package org.diylc.components.chassis;
import java.awt.AlphaComposite;
import java.awt.Composite;
import java.awt.Graphics2D;
import org.diylc.common.ObjectCache;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.shapes.AbstractShape;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Rectangular Cutout", author = "Branislav Stojkovic", category = "Electromechanical",
instanceNamePrefix = "RECTC", description = "Rectangular chassis cutout, with or without rounded edges",
zOrder = IDIYComponent.CHASSIS + 0.1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
transformer = SimpleComponentTransformer.class)
public class RectangularCutout extends AbstractShape {
private static final long serialVersionUID = 1L;
protected Size edgeRadius = new Size(0d, SizeUnit.mm);
public RectangularCutout() {
this.borderColor = LIGHT_METAL_COLOR.darker();
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels()));
int radius = (int) edgeRadius.convertToPixels();
if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
g2d.setColor(color);
g2d.fillRoundRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y, radius,
radius);
g2d.setComposite(oldComposite);
}
// Do not track any changes that follow because the whole rect has been
// tracked so far.
drawingObserver.stopTracking();
g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor);
g2d.drawRoundRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y, radius,
radius);
}
@EditableProperty(name = "Radius")
public Size getEdgeRadius() {
return edgeRadius;
}
public void setEdgeRadius(Size edgeRadius) {
this.edgeRadius = edgeRadius;
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(COLOR);
g2d.fillRect(2 / factor, 4 / factor, width - 4 / factor, height - 8 / factor);
g2d.setColor(LIGHT_METAL_COLOR.darker());
g2d.drawRect(2 / factor, 4 / factor, width - 4 / factor, height - 8 / factor);
}
}
@@ -71,10 +71,10 @@ public class Line extends AbstractLeadedComponent<Void> {
stroke = ObjectCache.getInstance().fetchBasicStroke(thickness); stroke = ObjectCache.getInstance().fetchBasicStroke(thickness);
break; break;
case DASHED: case DASHED:
stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness * 2}, thickness * 4); stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness * 2, thickness * 4}, thickness * 4);
break; break;
case DOTTED: case DOTTED:
stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness / 4, thickness * 3}, 0); stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness, thickness * 5}, 0);
break; break;
} }
g2d.setStroke(stroke); g2d.setStroke(stroke);
@@ -41,7 +41,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Turret Lug", category = "Connectivity", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Turret Lug", category = "Connectivity", author = "Branislav Stojkovic",
description = "Turret terminal lug", instanceNamePrefix = "Eyelet", stretchable = false, description = "Turret terminal lug", instanceNamePrefix = "Turret", stretchable = false,
zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false, zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false,
keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME, transformer = SimpleComponentTransformer.class) keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME, transformer = SimpleComponentTransformer.class)
public class Turret extends AbstractComponent<String> { public class Turret extends AbstractComponent<String> {
Binary file not shown.
Binary file not shown.
+9 -1
View File
@@ -1959,13 +1959,21 @@
<minor>44</minor> <minor>44</minor>
<build>0</build> <build>0</build>
</versionNumber> </versionNumber>
<releaseDate>2018-12-17 00:00:00.000 CET</releaseDate> <releaseDate>2018-12-18 00:00:00.000 CET</releaseDate>
<name></name> <name></name>
<changes> <changes>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added few chassis-related components under "Electromechanical" category</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>
<description>Change mouse cursor when in "Highlight Connected Areas" mode to avoid confusion</description> <description>Change mouse cursor when in "Highlight Connected Areas" mode to avoid confusion</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>Thin dashed and dotted lines turn to solid when zommed in</description>
</org.diylc.appframework.update.Change>
</changes> </changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url> <url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version> </org.diylc.appframework.update.Version>