better scaling

added marshall board and trimmer
This commit is contained in:
bancika
2011-02-03 21:47:16 +00:00
parent 02d38bed01
commit 6eee1525ee
34 changed files with 576 additions and 104 deletions
@@ -1,15 +1,15 @@
<map>
<entry>
<string>metric</string>
<boolean>true</boolean>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop\oldFiles</string>
</entry>
<entry>
<string>zoom</string>
<double>1.0</double>
</entry>
<entry>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop\oldFiles</string>
<string>metric</string>
<boolean>false</boolean>
</entry>
<entry>
<string>showTemplatesAtStartup</string>
@@ -53,7 +53,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
* @param x
* @return
*/
protected int getClosestOdd(int x) {
return (x / 2) * 2 + 1;
protected int getClosestOdd(double x) {
return ((int) x / 2) * 2 + 1;
}
}
@@ -24,10 +24,12 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
public static Color GUIDELINE_COLOR = Color.blue;
public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in);
protected Point[] controlPoints = new Point[] { new Point(0, 0),
new Point(DEFAULT_SIZE.convertToPixels() / 2, 0),
new Point(DEFAULT_SIZE.convertToPixels() / 2, DEFAULT_SIZE.convertToPixels()),
new Point(DEFAULT_SIZE.convertToPixels(), DEFAULT_SIZE.convertToPixels()) };
protected Point[] controlPoints = new Point[] {
new Point(0, 0),
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), 0),
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), (int) (DEFAULT_SIZE
.convertToPixels())),
new Point((int) DEFAULT_SIZE.convertToPixels(), (int) DEFAULT_SIZE.convertToPixels()) };
protected Color color = getDefaultColor();
@@ -107,7 +109,7 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.WHEN_SELECTED;
}
@Override
public boolean canControlPointOverlap(int index) {
// Only shape control points may overlap.
@@ -40,7 +40,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
protected Size width;
protected Point[] points = new Point[] {
new Point((int) (-DEFAULT_SIZE.convertToPixels() / 2), 0),
new Point(DEFAULT_SIZE.convertToPixels() / 2, 0) };
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), 0) };
protected Color bodyColor = Color.white;
protected Color borderColor = Color.black;
protected Color labelColor = LABEL_COLOR;
@@ -173,7 +173,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
* @return default lead thickness. Override this method to change it.
*/
protected int getLeadThickness() {
return LEAD_THICKNESS.convertToPixels();
return (int) LEAD_THICKNESS.convertToPixels();
}
/**
@@ -16,13 +16,13 @@ public class Size extends AbstractMeasure<SizeUnit> implements Comparable<Size>
// TODO Auto-generated constructor stub
}
public int convertToPixels() {
public double convertToPixels() {
// double factor = getUnit().getFactor() / SizeUnit.in.getFactor();
// int grids = (int) (factor * getValue() * Constants.GRIDS_PER_INCH);
// double remainder = (factor * getValue() * Constants.GRIDS_PER_INCH) - grids;
// return (int) Math.round(Constants.PIXELS_PER_INCH / Constants.GRIDS_PER_INCH
// * (grids + remainder));
return (int) (getValue() * getUnit().getFactor() / SizeUnit.in.getFactor() * Constants.PIXELS_PER_INCH);
return getValue() * getUnit().getFactor() / SizeUnit.in.getFactor() * Constants.PIXELS_PER_INCH;
}
@Override
@@ -13,8 +13,8 @@ public class CalcUtils {
* @return
*/
public static int roundToGrid(int x, Size gridSpacing) {
int grid = gridSpacing.convertToPixels();
return (Math.round(1f * x / grid) * grid);
double grid = gridSpacing.convertToPixels();
return (int) (Math.round(1f * x / grid) * grid);
}
public static void snapPointToGrid(Point point, Size gridSpacing) {
@@ -331,7 +331,7 @@ public class DrawingManager {
public Dimension getCanvasDimensions(Project project, Double zoomLevel, boolean useZoom) {
double width = project.getWidth().convertToPixels();
int height = project.getHeight().convertToPixels();
double height = project.getHeight().convertToPixels();
if (useZoom) {
width *= zoomLevel;
height *= zoomLevel;
@@ -815,8 +815,8 @@ public class Presenter implements IPlugInPort {
for (IDIYComponent<?> component : components) {
for (int i = 0; i < component.getControlPointCount(); i++) {
Point point = new Point(component.getControlPoint(i));
point.translate(currentProject.getGridSpacing().convertToPixels(), currentProject
.getGridSpacing().convertToPixels());
point.translate((int) currentProject.getGridSpacing().convertToPixels(),
(int) currentProject.getGridSpacing().convertToPixels());
component.setControlPoint(point, i);
}
addComponent(component, ComponentProcessor.getInstance().extractComponentTypeFrom(
@@ -161,8 +161,8 @@ public class ProjectFileManager {
int height = Integer.parseInt(root.getAttribute("Height")) + 1;
int boardWidth = (int) (width * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue());
int boardHeight = (int) (height * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue());
int projectWidth = project.getWidth().convertToPixels();
int projectHeight = project.getHeight().convertToPixels();
int projectWidth = (int) project.getWidth().convertToPixels();
int projectHeight = (int) project.getHeight().convertToPixels();
int x = (projectWidth - boardWidth) / 2;
int y = (projectHeight - boardHeight) / 2;
AbstractBoard board;
@@ -178,11 +178,11 @@ public class ProjectFileManager {
throw new IllegalArgumentException("Unrecognized board type: " + type);
}
board.setName("Main board");
Point referencePoint = new Point(roundToGrid(x, V1_GRID_SPACING), roundToGrid(y,
V1_GRID_SPACING));
Point referencePoint = new Point(CalcUtils.roundToGrid(x, V1_GRID_SPACING), CalcUtils
.roundToGrid(y, V1_GRID_SPACING));
board.setControlPoint(referencePoint, 0);
board.setControlPoint(new Point(roundToGrid(x + boardWidth, V1_GRID_SPACING), roundToGrid(y
+ boardHeight, V1_GRID_SPACING)), 1);
board.setControlPoint(new Point(CalcUtils.roundToGrid(x + boardWidth, V1_GRID_SPACING),
CalcUtils.roundToGrid(y + boardHeight, V1_GRID_SPACING)), 1);
project.getComponents().add(board);
NodeList childNodes = root.getChildNodes();
@@ -435,9 +435,4 @@ public class ProjectFileManager {
fis.close();
return project;
}
public int roundToGrid(int x, Size gridSpacing) {
int grid = gridSpacing.convertToPixels();
return (Math.round(1f * x / grid) * grid);
}
}
@@ -49,7 +49,7 @@ class CanvasPanel extends JComponent implements Autoscroll {
private Image bufferImage;
private GraphicsConfiguration screenGraphicsConfiguration;
private static boolean USE_HARDWARE_ACCELLERATION = true;
private static boolean USE_HARDWARE_ACCELLERATION = false;
static final EnumSet<DrawOption> DRAW_OPTIONS = EnumSet.of(DrawOption.GRID,
DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.ANTIALIASING,
@@ -112,7 +112,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
private RulerScrollPane getScrollPane() {
if (scrollPane == null) {
scrollPane = new RulerScrollPane(getCanvasPanel(), new ProjectDrawingProvider(
plugInPort, true), new Size(1d, SizeUnit.cm).convertToPixels(), new Size(1d,
plugInPort, true), (int) new Size(1d, SizeUnit.cm).convertToPixels(), (int) new Size(1d,
SizeUnit.in).convertToPixels());
boolean metric = ConfigurationManager.getInstance().readBoolean(Presenter.METRIC_KEY,
true);
@@ -167,6 +167,10 @@
<changeType>IMPROVEMENT</changeType>
<description>Fixed lead alignment issue</description>
</com.diyfever.gui.update.Change>
<com.diyfever.gui.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Better scaling, grid lines are more precise</description>
</com.diyfever.gui.update.Change>
<com.diyfever.gui.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added resistor schematic symbol</description>
@@ -179,6 +183,14 @@
<changeType>NEW_FEATURE</changeType>
<description>Added eyelet/turret component</description>
</com.diyfever.gui.update.Change>
<com.diyfever.gui.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added Marshall/Trainwreck style boards</description>
</com.diyfever.gui.update.Change>
<com.diyfever.gui.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added few types of trimmers</description>
</com.diyfever.gui.update.Change>
</changes>
<url>http://code.google.com/p/diy-layout-creator/downloads/list
</url>