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
/**
* This file is part of VisiCut.
* Copyright (C) 2011 - 2013 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/>.
**/
package com.t_oster.liblasercut.drivers;
import com.t_oster.liblasercut.IllegalJobException;
import com.t_oster.liblasercut.JobPart;
import com.t_oster.liblasercut.LaserCutter;
import com.t_oster.liblasercut.LaserJob;
import com.t_oster.liblasercut.LaserProperty;
import com.t_oster.liblasercut.ProgressListener;
import com.t_oster.liblasercut.VectorCommand;
import com.t_oster.liblasercut.VectorPart;
import com.t_oster.liblasercut.platform.Util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Thomas Oster <thomas.oster@rwth-aachen.de>
*/
public class IModelaMill extends LaserCutter
{
private void writeInitializationCode(PrintStream out)
{
out.println("%");
out.println("G90");//absolute positioning
out.println("G21");//select mm as input unit
}
private void writeFinalizationCode(PrintStream out)
{
out.println("M02");//END_OF_PROGRAM
out.println("%");
}
private void writeVectorCode(VectorPart p, PrintStream out)
{
double dpi = p.getDPI();
boolean spindleOn = false;
for (VectorCommand c : p.getCommandList())
{
switch (c.getType())
{
case MOVETO:
{
double x = Util.px2mm(c.getX(), dpi);
double y = Util.px2mm(c.getY(), dpi);
if (spindleOn)
{
out.println("M05");//stop spindle
spindleOn = false;
}
break;
}
case LINETO:
{
double x = Util.px2mm(c.getX(), dpi);
double y = Util.px2mm(c.getY(), dpi);
if (!spindleOn)
{
out.println("M03");//start spindle
spindleOn = true;
}
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
break;
}
case SETPROPERTY:
{
break;
}
}
}
}
@Override
public LaserProperty getLaserPropertyForVectorPart()
{
return new IModelaProperty();
}
@Override
public void sendJob(LaserJob job, ProgressListener pl, List<String> warnings) throws IllegalJobException, Exception
{
pl.taskChanged(this, "checking...");
checkJob(job);
pl.progressChanged(this, 20);
ByteArrayOutputStream result = new ByteArrayOutputStream();
PrintStream out = new PrintStream(result, true, "US-ASCII");
pl.taskChanged(this, "generating...");
writeInitializationCode(out);
double all = job.getParts().size();
int i = 1;
for (JobPart p : job.getParts())
{
if (p instanceof VectorPart)
{
pl.progressChanged(this, (int) (20+30*i++/all));
writeVectorCode((VectorPart) p, out);
}
}
writeFinalizationCode(out);
pl.progressChanged(this, 50);
pl.taskChanged(this, "sending...");
sendGCode(result.toByteArray());
pl.progressChanged(this, 100);
pl.taskChanged(this, "done");
warnings.add("WARNING: THE iModela driver only outputs to command line");
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
}
@Override
public List<Double> getResolutions()
{
return Arrays.asList(new Double[]{1000d});
}
@Override
public double getBedWidth()
{
return 100;
}
@Override
public double getBedHeight()
{
return 100;
}
@Override
public String getModelName()
{
return "ROLAND iModela";
}
@Override
public LaserCutter clone()
{
IModelaMill result = new IModelaMill();
for (String k:this.getPropertyKeys())
{
result.setProperty(k, this.getProperty(k));
}
return result;
}
@Override
public String[] getPropertyKeys()
{
return new String[0];
}
@Override
public void setProperty(String key, Object value)
{
}
@Override
public Object getProperty(String key)
{
return null;
}
private void sendGCode(byte[] toByteArray)
{
try
{
System.out.write(toByteArray);
}
catch (IOException ex)
{
Logger.getLogger(IModelaMill.class.getName()).log(Level.SEVERE, null, ex);
}
}
}