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
@@ -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);
}
}