Newer
Older
* Copyright (C) 2012 Thomas Oster <thomas.oster@rwth-aachen.de>
Thomas Oster
committed
*
* VisiCut is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
Thomas Oster
committed
*
* VisiCut 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 Lesser General Public License for more details.
Thomas Oster
committed
*
* You should have received a copy of the GNU Lesser General Public License
* along with VisiCut. If not, see <http://www.gnu.org/licenses/>.
**/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.t_oster.liblasercut;
Thomas Oster
committed
import com.sun.java_cup.internal.runtime.virtual_parse_stack;
import com.t_oster.liblasercut.platform.Util;
Thomas Oster
committed
import java.util.LinkedList;
import java.util.List;
/**
*
* @author Thomas Oster <thomas.oster@rwth-aachen.de>
*/
public class LaserJob
{
private String title;
private String name;
private String user;
Thomas Oster
committed
private double startX = 0;
private double startY = 0;
Thomas Oster
committed
private List<JobPart> parts = new LinkedList<JobPart>();
public LaserJob(String title, String name, String user)
{
this.title = title;
this.name = name;
this.user = user;
}
Thomas Oster
committed
/**
* Sets a custom offset on the job. The values are considered to be in
* mm and measured from the top-left corner of the laserbed.
* As a result, all coordinates cx,cy in the job will be corrected
* to cx-x,cy-y
* @param x
* @param y
*/
public void setStartPoint(double x, double y)
Thomas Oster
committed
public double getStartX()
Thomas Oster
committed
public double getStartY()
{
return startY;
}
public String getTitle()
{
return title;
}
public String getName()
{
return name;
}
public String getUser()
{
return user;
}
Thomas Oster
committed
public void addPart(JobPart p)
Thomas Oster
committed
this.parts.add(p);
Thomas Oster
committed
Thomas Oster
committed
public void removePart(JobPart p)
Thomas Oster
committed
this.parts.remove(p);
Thomas Oster
committed
Thomas Oster
committed
public List<JobPart> getParts()
Thomas Oster
committed
return parts;
Thomas Oster
committed
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
* This mehtod will substract the start-point coordinates
* from all parts of the job (in the corresponding resolution)
* and then set the start-point to 0,0. This way multiple calls
* to this method won't result in corrupted jobs.
*/
public void applyStartPoint()
{
if (startX != 0 || startY != 0)
{
for (JobPart p : this.getParts())
{
if (p instanceof VectorPart)
{
for (VectorCommand c : ((VectorPart) p).getCommandList())
{
if (c.getType().equals(VectorCommand.CmdType.LINETO) || c.getType().equals(VectorCommand.CmdType.MOVETO))
{
c.setX((int) (c.getX() - Util.mm2inch(startX)*p.getDPI()));
c.setY((int) (c.getY() - Util.mm2inch(startY)*p.getDPI()));
}
}
}
else if (p instanceof RasterPart)
{
RasterPart rp = (RasterPart) p;
rp.start.x -= (int) (Util.mm2inch(startX)*p.getDPI());
rp.start.y -= (int) (Util.mm2inch(startY)*p.getDPI());
}
else if (p instanceof Raster3dPart)
{
Raster3dPart rp = (Raster3dPart) p;
rp.start.x -= (int) (Util.mm2inch(startX)*p.getDPI());
rp.start.y -= (int) (Util.mm2inch(startY)*p.getDPI());
}
}
startX = 0;
startY = 0;
}
}