1
+ /*
2
+ By Chris Eugene Mills
3
+
4
+ Partly based off SimpleDirectDraw by Koblin, but the GCode import and drawing
5
+ is original.
6
+
7
+ Requires:
8
+ EBB firmware >=2.5.1
9
+ Processing >=3.3.5
10
+
11
+
12
+
13
+ GCODE FORMAT NOTES IN QUEUERUNNERCLASS.PDE
14
+
15
+ TODO:
16
+ Press '?' for help.
17
+ Acceleration
18
+ Smoothing lots of small movements
19
+ UI refinements
20
+ */
21
+
22
+ // LIBRARIES ///////////////////////////////////////////////////////////////////
23
+
24
+ import controlP5.* ;
25
+ import processing.serial.* ;
26
+
27
+ import java.io.* ;
28
+ import java.util.* ;
29
+ import java.lang.Character ;
30
+ import java.lang.reflect.* ;
31
+ import java.util.concurrent.TimeUnit ;
32
+
33
+
34
+
35
+ // CONFIG //////////////////////////////////////////////////////////////////////
36
+
37
+ // Letter/A4
38
+ static final boolean customMode = false ;
39
+ static final boolean letterSize = true ;
40
+
41
+ // UI Size
42
+ // windowMult*paperWidthMM = canvas width
43
+ static final int windowMult = 4 ;
44
+
45
+
46
+
47
+
48
+ // VARS ////////////////////////////////////////////////////////////////////////
49
+
50
+ // Machines, runners
51
+ AxiDrawMachine axidraw;
52
+ DummyMachine dummy;
53
+ QueueRunner qRunner;
54
+
55
+ // Drawing, sizes
56
+ PGraphics buffer, penLoc, grid;
57
+ int bufferwidth, bufferheight;
58
+ boolean gridOn = true ;
59
+
60
+
61
+ // User Interface
62
+ ControlFrame partner;
63
+ ControlP5 cp5;
64
+
65
+ // Fixes windowlocation sensing/setting discrepancies. OS-specific.
66
+ int yWindowOffset = 26 ;
67
+ color bg = color (37 );
68
+
69
+
70
+
71
+
72
+
73
+ // BEGIN ///////////////////////////////////////////////////////////////////////
74
+
75
+ void settings () {
76
+ // Setup Canvas ////
77
+ size (900 , 900 , P2D );
78
+ smooth ();
79
+ }
80
+
81
+ void setup () {
82
+
83
+ // Setup Canvas ///////////////
84
+ frameRate (120 );
85
+ c_init(255 , true , false );
86
+
87
+
88
+ // Paper Size in MM //////////////
89
+ if (letterSize) {
90
+ // Letter Paper
91
+ bufferwidth = 280 ;
92
+ bufferheight = 216 ;
93
+ } else {
94
+ // A4 Paper
95
+ bufferwidth = 297 ;
96
+ bufferheight = 210 ;
97
+ }
98
+
99
+ if (customMode) {
100
+ // Notebook = 200x120
101
+ // 16x9 = 280x157
102
+ bufferwidth = 200 ;
103
+ bufferheight = 120 ;
104
+ }
105
+
106
+
107
+
108
+ // Match canvas size
109
+ surface. setSize(bufferwidth* windowMult, bufferheight* windowMult);
110
+ surface. setResizable(false );
111
+ surface. setLocation(100 ,100 );
112
+
113
+
114
+
115
+ // Draw Buffers //////////////////////////////////////////
116
+ grid = createGraphics (bufferwidth* windowMult, bufferheight* windowMult);
117
+ grid. noSmooth();
118
+ grid. beginDraw();
119
+ grid. clear();
120
+ grid. stroke(0 , 25 );
121
+ for (int i = 0 ; i < grid. width ; i += (10 * windowMult)) {
122
+ grid. line(i, 0 , i, grid. height );
123
+ grid. line(0 , i, grid. width , i);
124
+ }
125
+ grid. endDraw();
126
+
127
+ buffer = createGraphics (bufferwidth* 15 , bufferheight* 15 );
128
+ buffer. beginDraw();
129
+ buffer. clear();
130
+ buffer. endDraw();
131
+
132
+ penLoc = createGraphics (bufferwidth* 4 , bufferheight* 4 );
133
+ penLoc. beginDraw();
134
+ penLoc. clear();
135
+ penLoc. endDraw();
136
+
137
+
138
+
139
+ // MACHINES ///////////////////////////////////////////////////
140
+ axidraw = new AxiDrawMachine (this , bufferwidth, bufferheight);
141
+ dummy = new DummyMachine (axidraw, buffer);
142
+
143
+
144
+
145
+ // QUEUERUNNER ////////////////////////////////////////////
146
+ qRunner = new QueueRunner (axidraw, dummy);
147
+ qRunner. drawOn(buffer, penLoc);
148
+
149
+
150
+
151
+ // Control Frame //////////////////
152
+ partner = new ControlFrame (this , 400 , bufferheight* windowMult, " Controls" );
153
+ partner. setResizable(true );
154
+ thread(" matchPartnerWindowLoop" ); // Match windows in background
155
+
156
+ // ControlP5 /////////////////
157
+ cp5 = new ControlP5 (this );
158
+ cp5. enableShortcuts();
159
+ primaryWindowSetup(cp5);
160
+ secondaryWindowSetup(partner. cp5);
161
+
162
+
163
+
164
+ //
165
+ //
166
+ // Connect to Machine
167
+ axidraw. connect();
168
+ }
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+ void c_draw () {
178
+
179
+
180
+ // Run queue, draw Plotter position, and preview
181
+ qRunner. run();
182
+
183
+
184
+ // Draw buffer to canvas
185
+ pushMatrix ();
186
+
187
+ // Mouse Zoom
188
+ translate (translateX, translateY);
189
+ scale (scaleFactor);
190
+
191
+ if (gridOn) image (grid, 0 , 0 , width , (grid. height * width / grid. width ));
192
+ image (buffer, 0 , 0 , width , (buffer. height * width / buffer. width ));
193
+ image (penLoc, 0 , 0 , width , (penLoc. height * width / penLoc. width ));
194
+
195
+ popMatrix ();
196
+
197
+
198
+ // Line to demarcate headerbar on Windows 10
199
+ stroke (bg);
200
+ noFill ();
201
+ strokeWeight (2 );
202
+ line (0 , 0 , width , 0 );
203
+
204
+
205
+ // Interface Draw
206
+ primaryWindowUpdate(cp5);
207
+ secondaryWindowUpdate(partner. cp5);
208
+ checkActions(); // All method interaction routed through here
209
+ }
210
+
211
+
212
+
213
+ // GCODE ENTRY /////////////////////////////////////////////////////////////////
214
+
215
+
216
+ void loadFile () {
217
+ if (! qRunner. isRunning())
218
+ selectInput (" Select a file to process:" , " fileSelected" );
219
+ }
220
+
221
+ void fileSelected (File selection ) {
222
+ if (selection == null ) {
223
+ println (" Window was closed or the user hit cancel." );
224
+ } else {
225
+ println (" INPUT: " + selection. getAbsolutePath());
226
+ GCodeParser parser = new GCodeParser (selection. getAbsolutePath());
227
+ parser. outputParsedGCodeFile();
228
+ qRunner. loadFile(parser. export());
229
+ }
230
+ }
231
+
232
+
233
+
234
+ // SYSTEM FUNCTIONS ///////////////////////////////////////////////////////////////////
235
+
236
+ // void reset() {
237
+ // setup();
238
+ // }
239
+
240
+
241
+ // TODO
242
+ void printHelp () {
243
+ println (" " );
244
+ }
0 commit comments