From a1072973d2c98cb5de5f00817de02899f1ed3527 Mon Sep 17 00:00:00 2001 From: bancika Date: Fri, 11 Dec 2020 13:53:07 +0100 Subject: [PATCH] smd transformation --- .../diylc/components/smd/SMDCapacitor.java | 7 +- .../org/diylc/components/smd/SMDResistor.java | 7 +- .../transform/PassiveSMDTransformer.java | 83 +++++++++++++++++++ .../transform/TrimmerTransformer.java | 1 - 4 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 diylc/diylc-library/src/org/diylc/components/transform/PassiveSMDTransformer.java diff --git a/diylc/diylc-library/src/org/diylc/components/smd/SMDCapacitor.java b/diylc/diylc-library/src/org/diylc/components/smd/SMDCapacitor.java index 3989af1c..9a86b677 100644 --- a/diylc/diylc-library/src/org/diylc/components/smd/SMDCapacitor.java +++ b/diylc/diylc-library/src/org/diylc/components/smd/SMDCapacitor.java @@ -21,8 +21,9 @@ */ package org.diylc.components.smd; -import java.awt.Color; - +import java.awt.Color; + +import org.diylc.components.transform.PassiveSMDTransformer; import org.diylc.core.IDIYComponent; import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.EditableProperty; @@ -32,7 +33,7 @@ import org.diylc.core.measures.Capacitance; @ComponentDescriptor(name = "SMD Capacitor", author = "Branislav Stojkovic", category = "SMD", instanceNamePrefix = "C", description = "Surface mount capacitor", - zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE) + zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = PassiveSMDTransformer.class) public class SMDCapacitor extends PassiveSMDComponent { public static Color BODY_COLOR = Color.decode("#BD9347"); diff --git a/diylc/diylc-library/src/org/diylc/components/smd/SMDResistor.java b/diylc/diylc-library/src/org/diylc/components/smd/SMDResistor.java index ee085771..d7f8ebbe 100644 --- a/diylc/diylc-library/src/org/diylc/components/smd/SMDResistor.java +++ b/diylc/diylc-library/src/org/diylc/components/smd/SMDResistor.java @@ -21,8 +21,9 @@ */ package org.diylc.components.smd; -import java.awt.Color; - +import java.awt.Color; + +import org.diylc.components.transform.PassiveSMDTransformer; import org.diylc.core.IDIYComponent; import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.EditableProperty; @@ -32,7 +33,7 @@ import org.diylc.core.measures.Resistance; @ComponentDescriptor(name = "SMD Resistor", author = "Branislav Stojkovic", category = "SMD", instanceNamePrefix = "C", description = "Surface mount resistor", zOrder = IDIYComponent.COMPONENT, - keywordPolicy = KeywordPolicy.SHOW_VALUE) + keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = PassiveSMDTransformer.class) public class SMDResistor extends PassiveSMDComponent { public static Color BODY_COLOR = Color.gray; diff --git a/diylc/diylc-library/src/org/diylc/components/transform/PassiveSMDTransformer.java b/diylc/diylc-library/src/org/diylc/components/transform/PassiveSMDTransformer.java new file mode 100644 index 00000000..d8b5eba0 --- /dev/null +++ b/diylc/diylc-library/src/org/diylc/components/transform/PassiveSMDTransformer.java @@ -0,0 +1,83 @@ +/* + * + * 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.transform; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; + +import org.diylc.common.IComponentTransformer; +import org.diylc.common.Orientation; +import org.diylc.components.smd.PassiveSMDComponent; +import org.diylc.core.IDIYComponent; + +public class PassiveSMDTransformer implements IComponentTransformer { + + @Override + public boolean canRotate(IDIYComponent component) { + return PassiveSMDComponent.class.isAssignableFrom(component.getClass()); + } + + @Override + public boolean canMirror(IDIYComponent component) { + return true; + } + + @Override + public boolean mirroringChangesCircuit() { + return false; + } + + @Override + public void rotate(IDIYComponent component, Point2D center, int direction) { + AffineTransform rotate = + AffineTransform.getRotateInstance(Math.PI / 2 * direction, center.getX(), center.getY()); + for (int index = 0; index < component.getControlPointCount(); index++) { + Point2D p = new Point2D.Double(); + rotate.transform(component.getControlPoint(index), p); + component.setControlPoint(p, index); + } + + PassiveSMDComponent smd = (PassiveSMDComponent) component; + Orientation o = smd.getOrientation(); + int oValue = o.ordinal(); + oValue += direction; + if (oValue < 0) + oValue = Orientation.values().length - 1; + if (oValue >= Orientation.values().length) + oValue = 0; + o = Orientation.values()[oValue]; + smd.setOrientation(o); + } + + @Override + public void mirror(IDIYComponent component, Point2D center, int direction) { + PassiveSMDComponent smd = (PassiveSMDComponent) component; + for (int i = 0; i < smd.getControlPointCount(); i++) { + Point2D point = smd.getControlPoint(i); + double dx = 0; + double dy = 0; + if (direction == IComponentTransformer.HORIZONTAL) + dx = (center.getX() - point.getX()) * 2; + else + dy = (center.getY() - point.getY()) * 2; + Point2D newPoint = new Point2D.Double(point.getX() + dx, point.getY() + dy); + smd.setControlPoint(newPoint, i); + } + } +} diff --git a/diylc/diylc-library/src/org/diylc/components/transform/TrimmerTransformer.java b/diylc/diylc-library/src/org/diylc/components/transform/TrimmerTransformer.java index 1d301162..85ae7508 100644 --- a/diylc/diylc-library/src/org/diylc/components/transform/TrimmerTransformer.java +++ b/diylc/diylc-library/src/org/diylc/components/transform/TrimmerTransformer.java @@ -27,7 +27,6 @@ import java.awt.geom.Point2D; import org.diylc.common.IComponentTransformer; import org.diylc.common.Orientation; import org.diylc.components.passive.TrimmerPotentiometer; -import org.diylc.components.semiconductors.DIL_IC; import org.diylc.core.IDIYComponent; public class TrimmerTransformer implements IComponentTransformer {