mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
rotate breadboard
This commit is contained in:
@@ -3,9 +3,11 @@ package org.diylc.components.boards;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
|
||||||
import org.diylc.common.HorizontalAlignment;
|
import org.diylc.common.HorizontalAlignment;
|
||||||
import org.diylc.common.ObjectCache;
|
import org.diylc.common.ObjectCache;
|
||||||
|
import org.diylc.common.Orientation;
|
||||||
import org.diylc.common.VerticalAlignment;
|
import org.diylc.common.VerticalAlignment;
|
||||||
import org.diylc.components.AbstractComponent;
|
import org.diylc.components.AbstractComponent;
|
||||||
import org.diylc.core.ComponentState;
|
import org.diylc.core.ComponentState;
|
||||||
@@ -48,7 +50,9 @@ public class Breadboard extends AbstractComponent<Void> {
|
|||||||
|
|
||||||
protected BreadboardSize breadboardSize;
|
protected BreadboardSize breadboardSize;
|
||||||
protected PowerStripPosition powerStripPosition;
|
protected PowerStripPosition powerStripPosition;
|
||||||
|
protected Orientation orientation;
|
||||||
|
|
||||||
|
@SuppressWarnings("incomplete-switch")
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
||||||
IDrawingObserver drawingObserver) {
|
IDrawingObserver drawingObserver) {
|
||||||
@@ -56,6 +60,23 @@ public class Breadboard extends AbstractComponent<Void> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// adjust the angle
|
||||||
|
double theta = 0;
|
||||||
|
switch (getOrientation()) {
|
||||||
|
case _90:
|
||||||
|
theta = Math.PI / 2;
|
||||||
|
break;
|
||||||
|
case _180:
|
||||||
|
theta = Math.PI;
|
||||||
|
break;
|
||||||
|
case _270:
|
||||||
|
theta = Math.PI * 3 / 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (theta != 0) {
|
||||||
|
g2d.rotate(theta, point.x, point.y);
|
||||||
|
}
|
||||||
|
|
||||||
int bodyArc = (int) BODY_ARC.convertToPixels();
|
int bodyArc = (int) BODY_ARC.convertToPixels();
|
||||||
double spacing = SPACING.convertToPixels();
|
double spacing = SPACING.convertToPixels();
|
||||||
int holeCount = getBreadboardSize() == BreadboardSize.Full ? 63 : 30;
|
int holeCount = getBreadboardSize() == BreadboardSize.Full ? 63 : 30;
|
||||||
@@ -189,10 +210,21 @@ public class Breadboard extends AbstractComponent<Void> {
|
|||||||
g2d.drawLine(width / 2, 2 / factor, width / 2, height - 4 / factor);
|
g2d.drawLine(width / 2, 2 / factor, width / 2, height - 4 / factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EditableProperty
|
||||||
|
public Orientation getOrientation() {
|
||||||
|
if (orientation == null)
|
||||||
|
orientation = Orientation.DEFAULT;
|
||||||
|
return orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrientation(Orientation orientation) {
|
||||||
|
this.orientation = orientation;
|
||||||
|
}
|
||||||
|
|
||||||
@EditableProperty(name = "Size")
|
@EditableProperty(name = "Size")
|
||||||
public BreadboardSize getBreadboardSize() {
|
public BreadboardSize getBreadboardSize() {
|
||||||
if (breadboardSize == null)
|
if (breadboardSize == null)
|
||||||
breadboardSize = BreadboardSize.Full;
|
breadboardSize = BreadboardSize.Half;
|
||||||
return breadboardSize;
|
return breadboardSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,13 +248,32 @@ public class Breadboard extends AbstractComponent<Void> {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("incomplete-switch")
|
||||||
@Override
|
@Override
|
||||||
public Point getControlPoint(int index) {
|
public Point getControlPoint(int index) {
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
return point;
|
return point;
|
||||||
double spacing = SPACING.convertToPixels();
|
double spacing = SPACING.convertToPixels();
|
||||||
int holeCount = getBreadboardSize() == BreadboardSize.Full ? 63 : 30;
|
int holeCount = getBreadboardSize() == BreadboardSize.Full ? 63 : 30;
|
||||||
return new Point((int)(point.x + 23 * spacing), (int)(point.y + holeCount * spacing));
|
// adjust the angle
|
||||||
|
double theta = 0;
|
||||||
|
switch (getOrientation()) {
|
||||||
|
case _90:
|
||||||
|
theta = Math.PI / 2;
|
||||||
|
break;
|
||||||
|
case _180:
|
||||||
|
theta = Math.PI;
|
||||||
|
break;
|
||||||
|
case _270:
|
||||||
|
theta = Math.PI * 3 / 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Point secondPoint = new Point((int) (point.x + 23 * spacing), (int) (point.y + (holeCount + 1) * spacing));
|
||||||
|
if (theta != 0) {
|
||||||
|
AffineTransform tx = AffineTransform.getRotateInstance(theta, point.x, point.y);
|
||||||
|
tx.transform(secondPoint, secondPoint);
|
||||||
|
}
|
||||||
|
return secondPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Binary file not shown.
@@ -1628,7 +1628,7 @@
|
|||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Added more control over Breadboard size and appearance</description>
|
<description>Added more control over Breadboard size, orientation and appearance</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</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>
|
||||||
|
|||||||
Reference in New Issue
Block a user