Added optional outer foil marking for all film capacitors

This commit is contained in:
bancika
2020-04-15 14:12:24 +02:00
parent 6a630aa498
commit a18a226020
4 changed files with 205 additions and 177 deletions
@@ -0,0 +1,147 @@
/*
*
* 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.passive;
import java.awt.Color;
import java.awt.Graphics2D;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.Theme;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.PositiveMeasureValidator;
import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
public abstract class AbstractFilmCapacitor extends AbstractLeadedComponent<Capacitance> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_WIDTH = new Size(1d / 2, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
public static Color OUTER_FOIL_COLOR = Color.white;
protected Capacitance value = null;
@Deprecated
protected Voltage voltage = Voltage._63V;
protected org.diylc.core.measures.Voltage voltageNew = null;
protected Boolean showOuterFoil = false;
protected Color outerFoilColor = OUTER_FOIL_COLOR;
@Override
protected boolean supportsStandingMode() {
return true;
}
@EditableProperty(validatorClass = PositiveMeasureValidator.class)
public Capacitance getValue() {
return value;
}
public void setValue(Capacitance value) {
this.value = value;
}
@Deprecated
public Voltage getVoltage() {
return voltage;
}
@Deprecated
public void setVoltage(Voltage voltage) {
this.voltage = voltage;
}
@Override
public String getValueForDisplay() {
return (getValue() == null ? "" : getValue().toString())
+ (getVoltageNew() == null ? "" : " " + getVoltageNew().toString());
}
@EditableProperty(name = "Voltage")
public org.diylc.core.measures.Voltage getVoltageNew() {
return voltageNew;
}
public void setVoltageNew(org.diylc.core.measures.Voltage voltageNew) {
this.voltageNew = voltageNew;
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultLength() {
return DEFAULT_WIDTH;
}
@EditableProperty(name = "Reverse (standing)")
public boolean getFlipStanding() {
return super.getFlipStanding();
}
@EditableProperty(name = "Outer Foil Mark")
public Boolean getShowOuterFoil() {
if (showOuterFoil == null)
showOuterFoil = false;
return showOuterFoil;
}
public void setShowOuterFoil(Boolean showOuterFoil) {
this.showOuterFoil = showOuterFoil;
}
@Override
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
if (!getShowOuterFoil())
return;
int width = (int) getWidth().convertToPixels();
int offset = (int) (getLength().convertToPixels() * 0.08);
Color finalTickColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
Constants.DEFAULT_THEME);
finalTickColor = theme.getOutlineColor();
} else {
finalTickColor = getOuterFoilColor();
}
g2d.setColor(finalTickColor);
g2d.setStroke(ObjectCache.getInstance().fetchZoomableStroke((float) (width * 0.1)));
g2d.drawLine((int) getLength().convertToPixels() - offset,
(int) (width / 2 - width * 0.35), (int) getLength().convertToPixels() - offset,
(int) (width / 2 + width * 0.35));
}
@EditableProperty(name = "Outer Foil")
public Color getOuterFoilColor() {
if (outerFoilColor == null)
outerFoilColor = OUTER_FOIL_COLOR;
return outerFoilColor;
}
public void setOuterFoilColor(Color outerFoilColor) {
this.outerFoilColor = outerFoilColor;
}
}
@@ -1,131 +1,64 @@
/*
*
* 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.passive;
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.passive;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.AbstractLeadedComponent;
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.annotations.PositiveMeasureValidator;
import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Film Capacitor (Axial)", author = "Branislav Stojkovic", category = "Passive",
creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C",
description = "Axial film capacitor, similar to Mallory 150s", zOrder = IDIYComponent.COMPONENT,
transformer = SimpleComponentTransformer.class)
public class AxialFilmCapacitor extends AbstractLeadedComponent<Capacitance> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_WIDTH = new Size(1d / 2, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
public static Color BODY_COLOR = Color.decode("#FFE303");
public static Color BORDER_COLOR = BODY_COLOR.darker();
private Capacitance value = null;
@Deprecated
private Voltage voltage = Voltage._63V;
private org.diylc.core.measures.Voltage voltageNew = null;
public AxialFilmCapacitor() {
super();
this.bodyColor = BODY_COLOR;
this.borderColor = BORDER_COLOR;
}
@Override
protected boolean supportsStandingMode() {
return true;
}
@EditableProperty(validatorClass = PositiveMeasureValidator.class)
public Capacitance getValue() {
return value;
}
public void setValue(Capacitance value) {
this.value = value;
}
@Deprecated
public Voltage getVoltage() {
return voltage;
}
@Deprecated
public void setVoltage(Voltage voltage) {
this.voltage = voltage;
}
@Override
public String getValueForDisplay() {
return (getValue() == null ? "" : getValue().toString()) + (getVoltageNew() == null ? "" : " " + getVoltageNew().toString());
}
@EditableProperty(name = "Voltage")
public org.diylc.core.measures.Voltage getVoltageNew() {
return voltageNew;
}
public void setVoltageNew(org.diylc.core.measures.Voltage voltageNew) {
this.voltageNew = voltageNew;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(LEAD_COLOR_ICON);
g2d.drawLine(0, height / 2, width, height / 2);
g2d.setColor(BODY_COLOR);
g2d.fillRect(4, height / 2 - 3, width - 8, 6);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(4, height / 2 - 3, width - 8, 6);
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultLength() {
return DEFAULT_WIDTH;
}
@Override
protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth().convertToPixels()));
}
@EditableProperty(name = "Reverse (standing)")
public boolean getFlipStanding() {
return super.getFlipStanding();
}
}
@ComponentDescriptor(name = "Film Capacitor (Axial)", author = "Branislav Stojkovic",
category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C",
description = "Axial film capacitor, similar to Mallory 150s", zOrder = IDIYComponent.COMPONENT,
transformer = SimpleComponentTransformer.class)
public class AxialFilmCapacitor extends AbstractFilmCapacitor {
private static final long serialVersionUID = 1L;
public static Color BODY_COLOR = Color.decode("#FFE303");
public static Color BORDER_COLOR = BODY_COLOR.darker();
public static Color OUTER_FOIL_COLOR = Color.white;
public AxialFilmCapacitor() {
super();
this.bodyColor = BODY_COLOR;
this.borderColor = BORDER_COLOR;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(LEAD_COLOR_ICON);
g2d.drawLine(0, height / 2, width, height / 2);
g2d.setColor(BODY_COLOR);
g2d.fillRect(4, height / 2 - 3, width - 8, 6);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(4, height / 2 - 3, width - 8, 6);
}
@Override
protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(),
getClosestOdd(getWidth().convertToPixels()));
}
}
@@ -27,73 +27,27 @@ import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.AbstractRadialComponent;
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.annotations.PositiveMeasureValidator;
import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Film Capacitor (Radial)", author = "Branislav Stojkovic", category = "Passive",
creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C",
description = "Radial film capacitor, similar to Sprague Orange Drop", zOrder = IDIYComponent.COMPONENT,
transformer = SimpleComponentTransformer.class)
public class RadialFilmCapacitor extends AbstractRadialComponent<Capacitance> {
public class RadialFilmCapacitor extends AbstractFilmCapacitor {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_WIDTH = new Size(1d / 4, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
public static Color BODY_COLOR = Color.decode("#FF8000");
public static Color BORDER_COLOR = BODY_COLOR.darker();
private Capacitance value = null;
@Deprecated
private Voltage voltage = Voltage._63V;
private org.diylc.core.measures.Voltage voltageNew = null;
public RadialFilmCapacitor() {
super();
this.bodyColor = BODY_COLOR;
this.borderColor = BORDER_COLOR;
}
@EditableProperty(validatorClass = PositiveMeasureValidator.class)
public Capacitance getValue() {
return value;
}
public void setValue(Capacitance value) {
this.value = value;
}
@Override
public String getValueForDisplay() {
return (getValue() == null ? "" : getValue().toString()) + (getVoltageNew() == null ? "" : " " + getVoltageNew().toString());
}
@Deprecated
public Voltage getVoltage() {
return voltage;
}
@Deprecated
public void setVoltage(Voltage voltage) {
this.voltage = voltage;
}
@EditableProperty(name = "Voltage")
public org.diylc.core.measures.Voltage getVoltageNew() {
return voltageNew;
}
public void setVoltageNew(org.diylc.core.measures.Voltage voltageNew) {
this.voltageNew = voltageNew;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(LEAD_COLOR_ICON);
@@ -104,16 +58,6 @@ public class RadialFilmCapacitor extends AbstractRadialComponent<Capacitance> {
g2d.drawRoundRect(4, height / 2 - 3, width - 8, 6, 5, 5);
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultLength() {
return DEFAULT_WIDTH;
}
@Override
protected Shape getBodyShape() {
double radius = getWidth().convertToPixels() * 0.7;