From 6c77dd510263cdf5c3dbd5ed1e999bd53cdfa716 Mon Sep 17 00:00:00 2001 From: bancika Date: Sat, 18 Apr 2020 18:21:15 +0200 Subject: [PATCH] add support for guitar pickup leads --- .../org/diylc/editor/FlexibleLeadsEditor.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/diylc/diylc-library/src/org/diylc/editor/FlexibleLeadsEditor.java b/diylc/diylc-library/src/org/diylc/editor/FlexibleLeadsEditor.java index 7116d96b..03fd10bb 100644 --- a/diylc/diylc-library/src/org/diylc/editor/FlexibleLeadsEditor.java +++ b/diylc/diylc-library/src/org/diylc/editor/FlexibleLeadsEditor.java @@ -11,6 +11,8 @@ import org.diylc.components.AbstractCurvedComponent.PointCount; import org.diylc.components.AbstractLeadedComponent; import org.diylc.components.connectivity.AWG; import org.diylc.components.connectivity.HookupWire; +import org.diylc.components.guitar.AbstractGuitarPickup; +import org.diylc.components.guitar.SingleCoilPickup; import org.diylc.components.passive.PotentiometerPanel; import org.diylc.components.passive.PotentiometerPanel.Type; import org.diylc.components.semiconductors.AbstractTransistorPackage; @@ -40,6 +42,8 @@ public class FlexibleLeadsEditor implements IProjectEditor { addLeads((PotentiometerPanel) c, project, newSelection); else if (c instanceof TubeSocket) addLeads((TubeSocket) c, project, newSelection); + else if (c instanceof AbstractGuitarPickup) + addLeads((AbstractGuitarPickup) c, project, newSelection); } return newSelection; @@ -216,6 +220,44 @@ public class FlexibleLeadsEditor implements IProjectEditor { project.getComponents().add(index + 1, w); } } + + private void addLeads(AbstractGuitarPickup c, Project project, Set> newSelection) { + Size offset = new Size(1d, SizeUnit.in); + + // create leads + for (int i = 0; i < c.getControlPointCount(); i++) { + if (!c.isControlPointSticky(i)) + continue; + Point p0 = c.getControlPoint(i); + double dx = 0; + double dy = 0; + + if (c instanceof SingleCoilPickup) + dy = offset.convertToPixels(); + else + dx = offset.convertToPixels(); + + AffineTransform tx = null; + if (c.getOrientation() != Orientation.DEFAULT) + tx = AffineTransform.getRotateInstance(c.getOrientation().toRadians(), p0.x, p0.y); + + HookupWire w = new HookupWire(); + w.setGauge(AWG._24); + getInstantiationManager().fillWithDefaultProperties(w, null); + for (int j = 0; j < w.getControlPointCount(); j++) { + Point p = new Point((int)(p0.x + dx * j), (int)(p0.y + dy * j)); + if (tx != null) + tx.transform(p, p); + w.setControlPoint(p, j); + } + + newSelection.add(w); + + // inject leads right before the component + int index = project.getComponents().indexOf(c); + project.getComponents().add(index + 1, w); + } + } @Override public String getEditAction() {