Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
* This file is part of VisiCut.
* Copyright (C) 2011 Thomas Oster <thomas.oster@rwth-aachen.de>
* RWTH Aachen University - 52062 Aachen, Germany
*
* 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.
*
* 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.
*
* 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;
import java.util.LinkedList;
import java.util.List;
/**
*
* @author Thomas Oster <thomas.oster@rwth-aachen.de>
*/
public class VectorPart
{
private LaserProperty currentCuttingProperty;
private int maxX;
private int maxY;
private int minX;
private int minY;
private List<VectorCommand> commands;
public VectorPart(LaserProperty initialProperty)
{
this.currentCuttingProperty = initialProperty.clone();
commands = new LinkedList<VectorCommand>();
commands.add(new VectorCommand(VectorCommand.CmdType.SETPOWER, currentCuttingProperty.getPower()));
commands.add(new VectorCommand(VectorCommand.CmdType.SETSPEED, currentCuttingProperty.getSpeed()));
commands.add(new VectorCommand(VectorCommand.CmdType.SETFREQUENCY, currentCuttingProperty.getFrequency()));
}
public LaserProperty getCurrentCuttingProperty()
{
return currentCuttingProperty;
}
public void setCurrentCuttingProperty(LaserProperty cp)
{
this.setFrequency(cp.getFrequency());
this.setPower(cp.getPower());
this.setSpeed(cp.getSpeed());
this.setFocus(cp.getFocus());
}
public VectorCommand[] getCommandList()
{
return commands.toArray(new VectorCommand[0]);
}
public void setSpeed(int speed)
{
if (speed != this.currentCuttingProperty.getSpeed())
{
commands.add(new VectorCommand(VectorCommand.CmdType.SETSPEED, speed));
this.currentCuttingProperty.setSpeed(speed);
}
}
public void setPower(int power)
{
if (power != this.currentCuttingProperty.getPower())
{
commands.add(new VectorCommand(VectorCommand.CmdType.SETPOWER, power));
this.currentCuttingProperty.setPower(power);
}
}
public void setFrequency(int frequency)
{
if (frequency != this.currentCuttingProperty.getFrequency())
{
commands.add(new VectorCommand(VectorCommand.CmdType.SETFREQUENCY, frequency));
this.currentCuttingProperty.setFrequency(frequency);
}
}
public void setFocus(float focus)
{
if (focus != this.currentCuttingProperty.getFocus())
{
commands.add(new VectorCommand(VectorCommand.CmdType.SETFOCUS, focus));
this.currentCuttingProperty.setFocus(focus);
}
}
private void checkMin(int x, int y)
{
if (x < minX)
{
minX = x;
}
if (y < minY)
{
minY = y;
}
}
private void checkMax(int x, int y)
{
if (x > maxX)
{
maxX = x;
}
if (y > maxY)
{
maxY = y;
}
}
public void moveto(int x, int y)
{
commands.add(new VectorCommand(VectorCommand.CmdType.MOVETO, x, y));
checkMin(x, y);
checkMax(x, y);
}
public void lineto(int x, int y)
{
commands.add(new VectorCommand(VectorCommand.CmdType.LINETO, x, y));
checkMin(x, y);
checkMax(x, y);
}
/**
* Returns the Width of the CuttingPart in Pixels
* @return
*/
public int getWidth()
{
return maxX - minX;
}
/**
* Returns the height of the CuttingPart in Pixels
* @return
*/
public int getHeight()
{
return maxY - minY;
}
}