Newer
Older
/*
* Copyright (c) 2015 Tricoire Sebastien 3dsman@free.fr
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
*/
#include "OE_controller.h"
#include <iostream>
#include <typeinfo>
//OE_controller::OE_controller(OE_display * display, OE_document* document ) : comm("/dev/ttyUSB0", 80, 10)
OE_controller::OE_controller(OE_display * display, OE_document* document ) : comm("20:15:05:11:28:40", 80, 30)
{
this->display = display;
this->document = document;
OE_linestitch::initMotifs();
}
OE_controller::~OE_controller()
{
}
bool OE_controller::testLogo2()
{
// test motifs
if (document)
{
document->setZeroPoint(vector_2d(0,1050));
3dsman
committed
unsigned curStitch = 0;
/*
// bordure rectange haut
addCurve(new OE_subcurve(getCurve(2),0.1, 0.8, false));
//selectCurve(getCurve(document->curves.size()-1), true);
addLineStitch(getCurve(document->curves.size()-1),1,2,4,-0.2);
curStitch = document->stitchs.size()-1;
setStitchThread(curStitch, getThread(1));*/
// interrieur premier rectangle
/*addCurve(new OE_subcurve(getCurve(2),0.1, 0.8, true));
addCurve(new OE_subcurve(getCurve(2),2, 3, false));
addBirailStitch(getCurve(document->curves.size()-1), getCurve(document->curves.size()-2), false, false, -0.2, -0.2, 1.0);
curStitch = document->stitchs.size()-1;*/
// interrieur 1er rectangle
addCurve(new OE_subcurve(getCurve(2),2, 3, false));
addCurve(new OE_subcurve(getCurve(2),0, 1, true));
addBirailStitch(getCurve(document->curves.size()-1), getCurve(document->curves.size()-2), false, false, -0.2, -0.2, 0.5);
curStitch = document->stitchs.size()-1;
setStitchThread(curStitch, getThread(1));
// interrieur 2eme rectangle
addCurve(new OE_subcurve(getCurve(7),2, 4, true));
addCurve(new OE_subcurve(getCurve(7),6, 1, false));
addBirailStitch(getCurve(document->curves.size()-1), getCurve(document->curves.size()-2), false, false, 0.2, 0.2, 0.5);
curStitch = document->stitchs.size()-1;
setStitchThread(curStitch, getThread(1));
// interrieur 3eme rectangle
addCurve(new OE_subcurve(getCurve(5),0, 1, false));
addCurve(new OE_subcurve(getCurve(5),2, 3, true));
addBirailStitch(getCurve(document->curves.size()-1),getCurve(document->curves.size()-2), false, false, -0.2, -0.2, 0.5);
3dsman
committed
curStitch = document->stitchs.size()-1;
setStitchThread(curStitch, getThread(1));
3dsman
committed
addThread(120,220,20,2);
// rectangle bas
3dsman
committed
curStitch = document->stitchs.size()-1;
//setLineStitchCurve(curStitch, getCurve(5));
3dsman
committed
setLineStitchMotif(curStitch, 1);
setLineStitchSize(curStitch,1,0.5);
setStitchThread(curStitch, getThread(2));
3dsman
committed
// circle logo
addCurve(new OE_subcurve(getCurve(1),0, 2, true));
addCurve(new OE_subcurve(getCurve(1),2, 4, true));
addCurve(new OE_joincurve(getCurve(document->curves.size()-2),getCurve(document->curves.size()-1)));
addBirailStitch(getCurve(0), getCurve(document->curves.size()-1),false,false, 0.2, 0.2, 0.5);
curStitch = document->stitchs.size()-1;
setStitchMaxLen(curStitch, 5);
setStitchThread(curStitch, getThread(1));
//selectCurve(getCurve(document->curves.size()-1), true);
//E
addCurve(new OE_subcurve(getCurve(9),9, 10, false));
addCurve(new OE_subcurve(getCurve(9),11, 12, true));
addBirailStitch(getCurve(document->curves.size()-1), getCurve(document->curves.size()-2),false,false, 0.2, 0.2, 0.5);
addCurve(new OE_subcurve(getCurve(9),0, 2, false));
addCurve(new OE_subcurve(getCurve(9),7, 9, false));
addCurve(new OE_joincurve(getCurve(document->curves.size()-1),getCurve(document->curves.size()-2)));
addCurve(new OE_subcurve(getCurve(9),3, 6, true));
addBirailStitch(getCurve(document->curves.size()-1), getCurve(document->curves.size()-2),false,false, 0.2, 0.2, 0.5);
3dsman
committed
curStitch = document->stitchs.size()-1;
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
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
201
202
203
204
205
//l
addCurve(new OE_subcurve(getCurve(11),3, 0, true));
addCurve(new OE_subcurve(getCurve(11),1, 2, false));
addBirailStitch(getCurve(document->curves.size()-1), getCurve(document->curves.size()-2),false,false, -0.2, -0.2, 0.5);
curStitch = document->stitchs.size()-1;
//e
addCurve(new OE_subcurve(getCurve(13),0, 2, false));
addCurve(new OE_joincurve(getCurve(12),getCurve(document->curves.size()-1)));
addCurve(new OE_subcurve(getCurve(13),3, 9, true));
addBirailStitch(getCurve(document->curves.size()-1), getCurve(document->curves.size()-2),false,false, 0.2, 0.2, 0.5);
curStitch = document->stitchs.size()-1;
//c
addCurve(new OE_subcurve(getCurve(16),10, 4, false));
addCurve(new OE_subcurve(getCurve(16),5, 9, true));
addBirailStitch(getCurve(document->curves.size()-1), getCurve(document->curves.size()-2),false,false, 0.2, 0.2, 0.5);
curStitch = document->stitchs.size()-1;
//t
addCurve(new OE_subcurve(getCurve(17),1, 2, true));
addCurve(new OE_subcurve(getCurve(17),5, 6, true));
addCurve(new OE_joincurve(getCurve(document->curves.size()-1),getCurve(document->curves.size()-2)));
addCurve(new OE_subcurve(getCurve(17),7,8, true));
addCurve(new OE_subcurve(getCurve(17),15,16, true));
addCurve(new OE_joincurve(getCurve(document->curves.size()-1),getCurve(document->curves.size()-2)));
addBirailStitch(getCurve(document->curves.size()-1), getCurve(document->curves.size()-4),false,true, 0.2, 0.2, 0.5);
addCurve(new OE_subcurve(getCurve(17),2, 3, false));
addCurve(new OE_subcurve(getCurve(17),12,15, false));
addCurve(new OE_joincurve(getCurve(document->curves.size()-1),getCurve(document->curves.size()-2)));
addCurve(new OE_subcurve(getCurve(17),4, 5, true));
addCurve(new OE_subcurve(getCurve(17),8,11, true));
addCurve(new OE_joincurve(getCurve(document->curves.size()-1),getCurve(document->curves.size()-2)));
addBirailStitch(getCurve(document->curves.size()-1), getCurve(document->curves.size()-4),true,true, -0.2, -0.2, 0.5);
curStitch = document->stitchs.size()-1;
//r
addCurve(new OE_subcurve(getCurve(19),6, 7, true));
addCurve(new OE_subcurve(getCurve(19),2, 3, true));
addCurve(new OE_joincurve(getCurve(document->curves.size()-1),getCurve(document->curves.size()-2)));
addCurve(new OE_subcurve(getCurve(19),4, 5, false));
addBirailStitch(getCurve(document->curves.size()-2),getCurve(document->curves.size()-1),false,false, 0.2, 0.2, 0.5);
addCurve(new OE_subcurve(getCurve(19),0, 2, true));
addCurve(new OE_subcurve(getCurve(19),7, 9, false));
addBirailStitch(getCurve(document->curves.size()-1), getCurve(document->curves.size()-2),false,false, -0.2, -0.2, 0.5);
curStitch = document->stitchs.size()-1;
//o
addCurve(new OE_subcurve(getCurve(22),0, 4, false));
addCurve(new OE_subcurve(getCurve(21),0, 4, true));
addBirailStitch(getCurve(document->curves.size()-1), getCurve(document->curves.size()-2),false,false, 0.2, 0.2, 0.5);
//l
addCurve(new OE_subcurve(getCurve(23),3, 0, true));
addCurve(new OE_subcurve(getCurve(23),1, 2, false));
addBirailStitch(getCurve(document->curves.size()-1), getCurve(document->curves.size()-2),false,false, -0.2, -0.2, 0.5);
curStitch = document->stitchs.size()-1;
//a
addCurve(new OE_subcurve(getCurve(27),11, 12, true));
addCurve(new OE_subcurve(getCurve(27),0, 2, true));
addCurve(new OE_joincurve(getCurve(document->curves.size()-1),getCurve(document->curves.size()-2)));
addCurve(new OE_subcurve(getCurve(27),8, 10, false));
addCurve(new OE_subcurve(getCurve(25),4, 0, false));
addCurve(new OE_joincurve(getCurve(document->curves.size()-1),getCurve(document->curves.size()-2)));
addCurve(new OE_subcurve(getCurve(27),3, 4, false));
addCurve(new OE_joincurve(getCurve(document->curves.size()-1),getCurve(document->curves.size()-2)));
addBirailStitch(getCurve(document->curves.size()-6), getCurve(document->curves.size()-1),true,true, -0.2, -0.2, 0.5);
addCurve(new OE_subcurve(getCurve(25),0, 4, true));
addCurve(new OE_subcurve(getCurve(27),4, 8, false));
addBirailStitch(getCurve(document->curves.size()-1), getCurve(document->curves.size()-2),false,false, -0.2, -0.2, 0.5);
curStitch = document->stitchs.size()-1;
//b
addCurve(new OE_subcurve(getCurve(29),6, 7, true));
addCurve(new OE_subcurve(getCurve(28),2, 3, true));
addCurve(new OE_joincurve(getCurve(document->curves.size()-1),getCurve(document->curves.size()-2)));
addCurve(new OE_subcurve(getCurve(29),2, 3, true));
addCurve(new OE_joincurve(getCurve(document->curves.size()-1),getCurve(document->curves.size()-2)));
addCurve(new OE_subcurve(getCurve(29),4, 5, false));
addBirailStitch(getCurve(document->curves.size()-2),getCurve(document->curves.size()-1),true,true, -0.2, -0.2, 0.5);
3dsman
committed
addCurve(new OE_subcurve(getCurve(28),3, 5, true));
addCurve(new OE_subcurve(getCurve(28),0, 2, true));
addCurve(new OE_joincurve(getCurve(document->curves.size()-1),getCurve(document->curves.size()-2)));
addCurve(new OE_subcurve(getCurve(29),0, 2, false));
addCurve(new OE_subcurve(getCurve(29),7, 9, false));
addCurve(new OE_joincurve(getCurve(document->curves.size()-1),getCurve(document->curves.size()-2)));
addBirailStitch(getCurve(document->curves.size()-1), getCurve(document->curves.size()-4),true,true, 0.2, 0.2, 0.5);
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
addLineStitch(getCurve(30),1.2,0.5,1,0);
addLineStitch(getCurve(31),1.2,0.5,1,0);
addLineStitch(getCurve(32),1.2,0.5,1,0);
addLineStitch(getCurve(33),1.2,0.5,1,0);
//e
addLineStitch(getCurve(52),1.2,0.5,1,0);
addLineStitch(getCurve(51),1.2,0.5,1,0);
//c
addLineStitch(getCurve(49),1.2,0.5,1,0);
//a
addLineStitch(getCurve(48),1.2,0.5,1,0);
addLineStitch(getCurve(47),1.2,0.5,1,0);
//p
addLineStitch(getCurve(46),1.2,0.5,1,0);
//s
addLineStitch(getCurve(45),1.2,0.5,1,0);
//r
addLineStitch(getCurve(44),1.2,0.5,1,0);
addLineStitch(getCurve(43),1.2,0.5,1,0);
//e
addLineStitch(getCurve(42),1.2,0.5,1,0);
addLineStitch(getCurve(41),1.2,0.5,1,0);
//k
addLineStitch(getCurve(40),1.2,0.5,1,0);
addLineStitch(getCurve(39),1.2,0.5,1,0);
//c
addLineStitch(getCurve(38),1.2,0.5,1,0);
//a
addLineStitch(getCurve(37),1.2,0.5,1,0);
addLineStitch(getCurve(36),1.2,0.5,1,0);
//h
addLineStitch(getCurve(50),1.2,0.5,1,0);
addLineStitch(getCurve(35),1.2,0.5,1,0);
addLineStitch(getCurve(34),1.2,0.5,1,0);
/*
addLineStitch(getCurve(62),1.4,0.5,1,0);
addLineStitch(getCurve(60),1.4,0.5,1,0);
addLineStitch(getCurve(58),1.4,0.5,1,0);
addLineStitch(getCurve(56),1.4,0.5,1,0);
addLineStitch(getCurve(54),1.4,0.5,1,0);
addCurve(new OE_subcurve(getCurve(52),4, 4, true));
addLineStitch(getCurve(document->curves.size()-1),1.4,0.5,1,0);
addLineStitch(getCurve(50),1.4,0.5,1,0);
addCurve(new OE_subcurve(getCurve(48),9, 9, true));
addLineStitch(getCurve(document->curves.size()-1),1.4,0.5,1,0);
addCurve(new OE_subcurve(getCurve(46),4, 4, true));
addLineStitch(getCurve(document->curves.size()-1),1.4,0.5,1,0);
addCurve(new OE_subcurve(getCurve(42),4, 4, true));
addLineStitch(getCurve(document->curves.size()-1),1.4,0.5,1,0);
addLineStitch(getCurve(40),1.4,0.5,1,0);
addLineStitch(getCurve(38),1.4,0.5,1,0);
addLineStitch(getCurve(36),1.4,0.5,1,0);
addCurve(new OE_subcurve(getCurve(34),7, 7, true));
addLineStitch(getCurve(document->curves.size()-1),1.4,0.5,1,0);*/
3dsman
committed
//refreshStitch(curStitch);
//addLineStitch(document->curves.at(15),1.5,3.5,1,0,0,0.1);
/*
setLineStitchCurve(0, getCurve(0));
setLineStitchMotif(0, 1);
setLineStitchSize(0,2,2);
setStitchThread(0, getCurve(0));*/
// texte
addLineStitch(getCurve(13),1,0.5,1,0.1);
3dsman
committed
curStitch = document->stitchs.size()-1;
setStitchThread(curStitch, getThread(0));
}
// fin motifs
return false;
}
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
bool OE_controller::testOpenEmbroider()
{
if (document)
{
addThread(220,120,20,2);
document->setZeroPoint(vector_2d(255,267));
unsigned curStitch = 0;
//fil
addLineStitch(getCurve(4),3,0.4,1,0);
addLineStitch(getCurve(5),3,0.4,1,0);
/*
//dents
addBirailStitch(getCurve(18),getCurve(19),true,false, 0, 0, 0.5);
addBirailStitch(getCurve(16),getCurve(17),true,false, 0, 0, 0.5);
addBirailStitch(getCurve(20),getCurve(21),true,false, 0, 0, 0.5);
addBirailStitch(getCurve(8),getCurve(9),false,true, 0, 0, 0.5);
addBirailStitch(getCurve(10),getCurve(11),false,true, 0, 0, 0.5);
addBirailStitch(getCurve(12),getCurve(13),false,true, 0, 0, 0.5);
addBirailStitch(getCurve(14),getCurve(15),false,true, 0, 0, 0.5);
//cercle
//addBirailStitch(getCurve(6),getCurve(7),true,true, 0, 0, 0.5);
addBirailStitch(getCurve(6),getCurve(22),true,true, -0.4, -0.6, 0.5);
addBirailStitch(getCurve(22),getCurve(7),true,true, -0.6, -0.4, 0.5);
//setStitchMaxLen(document->stitchs.size()-1,4);
addLineStitch(getCurve(23),1.4,0.6,1,0);*/
addLineStitch(getCurve(23),0.5,0.8,2,0.3);
//pointe
addCurve(new OE_subcurve(getCurve(3),0, 1, true));
addCurve(new OE_subcurve(getCurve(3),1, 2, false));
addBirailStitch(getCurve(document->curves.size()-2),getCurve(document->curves.size()-1),false,false, 0, 0, 0.5);
setStitchThread(document->stitchs.size()-1, getThread(1));
//aiguille
addCurve(new OE_subcurve(getCurve(1),3, 3, false));
addCurve(new OE_subcurve(getCurve(0),3.5, 5, true));
addCurve(new OE_joincurve(getCurve(document->curves.size()-1),getCurve(document->curves.size()-2)));
addCurve(new OE_subcurve(getCurve(document->curves.size()-1),0, 5.2, false));
addCurve(new OE_subcurve(getCurve(0),0, 2.4, false));
addBirailStitch(getCurve(document->curves.size()-2),getCurve(document->curves.size()-1),false,false, 0, 0, 0.5);
setStitchThread(document->stitchs.size()-1, getThread(1));
addCurve(new OE_subcurve(getCurve(document->curves.size()-3),5.2, 7, false));
addCurve(new OE_subcurve(getCurve(0),2.4, 3.5, false));
addBirailStitch(getCurve(document->curves.size()-2),getCurve(document->curves.size()-1),false,false, 0, 0, 0.5);
setStitchThread(document->stitchs.size()-1, getThread(1));
return true;
}
return false;
}
bool OE_controller::testStarTrek()
{
if (document)
{
addThread(220,120,20,2);
document->setZeroPoint(vector_2d(45,60));
unsigned curStitch = 0;
addLineStitch(getCurve(0),4,1,0,0.5);
//addLineStitch(getCurve(14),4,1,0,0.5);
addLineStitch(getCurve(0),4,1,0,0.5);
addLineStitch(getCurve(0),3,2,4,-0.4);
addCurve(new OE_subcurve(getCurve(2),1, 3, false));
addCurve(new OE_subcurve(getCurve(3),0, 4, false));
//addBirailStitch(getCurve(4),getCurve(2),false,false, 0, 0, 0.5);
addBirailStitch(getCurve(document->curves.size()-2),getCurve(document->curves.size()-1),false,false, 0.2, 0.2, 0.5);
addCurve(new OE_subcurve(getCurve(2),3, 4, true));
addCurve(new OE_subcurve(getCurve(2),4, 5, false));
addBirailStitch(getCurve(document->curves.size()-2),getCurve(document->curves.size()-1),false,false, 0.2, 0.2, 0.5);
addCurve(new OE_subcurve(getCurve(2),5, 7, false));
addCurve(new OE_subcurve(getCurve(4),0, 3, false));
addBirailStitch(getCurve(document->curves.size()-2),getCurve(document->curves.size()-1),false,false, 0.2, 0.2, 0.5);
addCurve(new OE_subcurve(getCurve(2),7, 8, true));
addCurve(new OE_subcurve(getCurve(2),0, 1, false));
addBirailStitch(getCurve(document->curves.size()-2),getCurve(document->curves.size()-1),false,false, 0.2, 0.2, 0.5);
//addLineStitch(getCurve(5),0.5,0.8,2,0.3);
//addLineStitch(getCurve(6),0.5,0.8,2,0.3);
addBirailStitch(getCurve(5),getCurve(6),true,false, 0.2, 0.2, 0.5);
addBirailStitch(getCurve(7),getCurve(8),true,false, 0.2, 0.2, 0.5);
addBirailStitch(getCurve(9),getCurve(10),true,false, 0.2, 0.2, 0.5);
addBirailStitch(getCurve(11),getCurve(12),false,true, 0.2, 0.2, 0.5);
//addLineStitch(getCurve(13),0.5,0.8,2,0.3);
addLineStitch(getCurve(13),2,0.6,1,0);
//addLineStitch(getCurve(document->curves.size()-1),0.5,0.8,2,0.3);
return true;
}
return false;
}
bool OE_controller::testRadio()
{
if (document)
{
addThread(220,120,20,2);
document->setZeroPoint(vector_2d(95,60));
unsigned curStitch = 0;
unsigned motif = 2;
float longeur=2;
float large=0.6;
addLineStitch(getCurve(56),longeur,large,motif,0);
addLineStitch(getCurve(59),longeur,large,motif,0);
//for(unsigned i=55; i<57;i++)
// addLineStitch(getCurve(i),longeur,large,motif,0);
//addLineStitch(getCurve(1),longeur,large,motif,0);
return true;
}
return false;
}
bool OE_controller::setDefault()
{
OE_birailstitch::defaultLen = 1;
OE_birailstitch::defaultMaxlen = 0;
return true;
}
OE_curve* OE_controller::getCurve (unsigned index)
{
if ((document)&&(index<document->curves.size()))
{
std::list<OE_curve*>::iterator curve = document->curves.begin();
for(unsigned i=0; i<index;i++)
curve++;
return (*curve);
}
return nullptr;
}
OE_pointcurve* OE_controller::getPointcurve (unsigned index)
{
//if ((document)&&(index<document->curves.size()))
return (dynamic_cast<OE_pointcurve*> (getCurve (index)));
//return nullptr;
}
OE_subcurve* OE_controller::getSubcurve (unsigned index)
{
//if ((document)&&(index<document->curves.size()))
return (dynamic_cast<OE_subcurve*> (getCurve (index)));
//return nullptr;
}
OE_joincurve* OE_controller::getJoincurve (unsigned index)
{
//if ((document)&&(index<document->curves.size()))
return (dynamic_cast<OE_joincurve*> (getCurve (index)));
//return nullptr;
}
OE_stitchs* OE_controller::getStitch (unsigned index)
{
if ((document)&&(index<document->stitchs.size()))
{
std::list<OE_stitchs*>::iterator stitch = document->stitchs.begin();
for(unsigned i=0; i<index;i++)
stitch++;
return (*stitch);
}
//return document->stitchs.at(index);
return nullptr;
}
OE_linestitch* OE_controller::getLineStitch (unsigned index)
//if ((document)&&(index<document->stitchs.size()))
return (dynamic_cast<OE_linestitch*> (getStitch(index)));
//return nullptr;
}
OE_birailstitch* OE_controller::getBirailStitch (unsigned index)
{
//if ((document)&&(index<document->stitchs.size()))
return (dynamic_cast<OE_birailstitch*> (getStitch(index)));
//return nullptr;
3dsman
committed
OE_linkstitch* OE_controller::getLinkStitch (unsigned index)
{
//if ((document)&&(index<document->stitchs.size()))
return (dynamic_cast<OE_linkstitch*> (getStitch(index)));
3dsman
committed
//return nullptr;
3dsman
committed
}
OE_thread* OE_controller::getThread (unsigned index)
{
if ((document)&&(index<document->threads.size()))
{
std::list<OE_thread*>::iterator thread = document->threads.begin();
for(unsigned i=0; i<index;i++)
thread++;
return (*thread);
}
//return document->threads.at(index);
return nullptr;
}
3dsman
committed
bool OE_controller::addStitch(OE_stitchs * stitch)
{
if (document)
{
if (document->stitchs.size() > 0)
{
OE_stitchs* tmpstitch = document->stitchs.back();
document->addStitch( new OE_linkstitch(tmpstitch, stitch));
}
3dsman
committed
document->addStitch(stitch);
return true;
}
return false;
}
bool OE_controller::addCurve( std::vector<vector_2d> points, bool closed)
{
if (document)
{
return document->addCurve( new OE_pointcurve(points, closed));
}
return false;
}
bool OE_controller::addCurve( OE_curve* curve)
{
if (document)
{
return document->addCurve( curve);
bool OE_controller::addLineStitch(OE_curve* curve)
return addLineStitch( curve, 1, 0, 0, 0);
bool OE_controller::addLineStitch( OE_curve* curve, float len, float width, unsigned motif, float offset)
return addStitch(new OE_linestitch(document->threads.front(), curve, len, width, motif, offset));
3dsman
committed
bool OE_controller::addBirailStitch(OE_curve* curve1, OE_curve* curve2, bool reverse1, bool reverse2, float offset1, float offset2, float len)
return addStitch(new OE_birailstitch(document->threads.front(), curve1, curve2, reverse1, reverse2, offset1, offset2, len));
3dsman
committed
bool OE_controller::addThread()
{
if (document)
return document->addThread(new OE_thread());
return false;
}
bool OE_controller::addThread(unsigned char r, unsigned char g, unsigned char b, float width )
{
if (document)
return document->addThread(new OE_thread(r, g, b, width));
return false;
}
bool OE_controller::selectCurve( OE_curve* curve, bool add)
{
if (document)
{
if (!add) document->selectedCurves.clear();
document->selectedCurves.push_back(curve);
return true;
}
return false;
}
bool OE_controller::selectStitch( OE_stitchs* stitch, bool add)
{
if (document)
{
if (!add) document->selectedStitchs.clear();
document->selectedStitchs.push_back(stitch);
return true;
}
return false;
}
3dsman
committed
bool OE_controller::refreshStitchs()
{
if (document)
{
std::list<OE_stitchs*>::iterator stitch = document->stitchs.begin();
while (stitch != document->stitchs.end())
{
//for(unsigned i = 0; i < document->stitchs.size();i++)
(*stitch)->refresh();
stitch++;
}
3dsman
committed
}
return true;
}
bool OE_controller::setStitchMaxLen( unsigned index, float maxLen)
{
if ((document)&&(index<document->stitchs.size()))
{
getStitch(index)->setMaxLen(maxLen);
return true;
}
return false;
}
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
bool OE_controller::setLineStitchMotif( unsigned index, unsigned motif)
{
OE_linestitch * tmpstitch = getLineStitch(index);
if (!tmpstitch)return false;
tmpstitch->setMotif(motif);
return true;
}
bool OE_controller::setLineStitchCurve( unsigned index, OE_curve* curve)
{
OE_linestitch * tmpstitch = getLineStitch(index);
if (!tmpstitch)return false;
tmpstitch->setCurve(curve);
return true;
}
bool OE_controller::setLineStitchSize( unsigned index, float len, float width)
{
OE_linestitch * tmpstitch = getLineStitch(index);
if (!tmpstitch)return false;
tmpstitch->setLen(len);
tmpstitch->setWidth(width);
return true;
}
3dsman
committed
bool OE_controller::setLineStitchSizeReverse(unsigned index, bool reverse)
{
OE_linestitch * tmpstitch = getLineStitch(index);
if (!tmpstitch)return false;
tmpstitch->setReverse(reverse);
return true;
}
bool OE_controller::setBirailStitchCurves( unsigned index, OE_curve* curve1, OE_curve* curve2)
{
OE_birailstitch * tmpstitch = getBirailStitch(index);
if (!tmpstitch)return false;
tmpstitch->setCurve1(curve1);
tmpstitch->setCurve2(curve2);
return true;
}
bool OE_controller::setBirailStitchSize( unsigned index, float len, float offset1, float offset2)
{
OE_birailstitch * tmpstitch = getBirailStitch(index);
if (!tmpstitch)return false;
tmpstitch->setLen(len);
tmpstitch->setOffset1(offset1);
tmpstitch->setOffset2(offset2);
return true;
}
3dsman
committed
bool OE_controller::setLinkStitchStitch( unsigned index, OE_stitchs* stitchStart, OE_stitchs* stitchEnd)
{
OE_linkstitch * tmpstitch = getLinkStitch(index);
if (!tmpstitch)return false;
tmpstitch->setStitchStart(stitchStart);
tmpstitch->setStitchStart(stitchEnd);
return true;
}
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
bool OE_controller::setStitchThread(unsigned index, OE_thread * thread)
{
OE_stitchs * tmpstitch = getStitch(index);
if (!tmpstitch)return false;
tmpstitch->setThread(thread);
return true;
}
bool OE_controller::setThreadColor(unsigned index, unsigned char r, unsigned char g, unsigned char b )
{
OE_thread * tmpthread = getThread(index);
if (!tmpthread)return false;
tmpthread->setColor(r, g, b);
return true;
}
bool OE_controller::setThreadWidth(unsigned index, float width)
{
OE_thread * tmpthread = getThread(index);
if (!tmpthread)return false;
tmpthread->setWidth(width);
return true;
}
bool OE_controller::setsubcurvePos( unsigned index, float start, float end)
{
OE_subcurve * tmpcurve = getSubcurve(index);
if (!tmpcurve)return false;
tmpcurve->setStart(start);
tmpcurve->setEnd(end);
return true;
}
bool OE_controller::generateInstructions()
{
if (document)
{
document->instPoints.clear();
for (unsigned i = 0; i < document->instCommand.size(); i++) {
delete (document->instCommand.at(i));
}
document->instCommand.clear();
std::list<OE_stitchs*>::iterator stitch = document->stitchs.begin();
OE_thread * instThread = (*stitch)->getThread();
if(!instThread)
instThread = document->threads.front();
document->instCommand.push_back(new OE_start(document->instPoints.size(), instThread->getColor()));
while (stitch != document->stitchs.end())
{
(*stitch)->refresh();
if((*stitch)->check()&&(*stitch)->getNpts()>0)
{
OE_thread * curThread = (*stitch)->getThread();
if (!curThread)
curThread = document->threads.front();
instThread = curThread;
document->instCommand.push_back(new OE_waitcolor(document->instPoints.size(), instThread->getColor()));
}
std::vector<vector_2d> points = (*stitch)->getPoints();
document->instPoints.insert( document->instPoints.end(), points.begin(), points.end() );
}
stitch++;
}
vector_2d zero = document->getZeroPoint();
float size = document->getPulseByMm();
for ( unsigned i = 0; i < document->instPoints.size(); i++)
{
document->instPoints.at(i) = (document->instPoints.at(i) - zero)*size;
}
}
return true;
}
uint8_t int7(int i) // transform int32 to int7
{
if (i>=0)
return i;
int8_t i8 = 2*i;
return (*(uint8_t*)&i8)>>1;
}
void OE_controller::sendInstPoint()
{
static bool running = false;
static int oldX, oldY;
static unsigned sndPoint;
static uint8_t dxys[32];
static bool started = false;
if (!running)
{
std::cout << "sendInstPoint x " << document->instPoints.size() <<std::endl;
comm.stopMove();
if (!comm.ack()) std::cerr << "Can't set pos" << std::endl;
comm.setPos(0, 0);
if (!comm.ack()) std::cerr << "Can't set pos" << std::endl;
comm.setNPoint(0);
if (!comm.ack()) std::cerr << "Can't set point" << std::endl;
comm.deletePoints();
if (!comm.ack()) std::cerr << "Can't delete points" << std::endl;
oldX = oldY = 0;
sndPoint = 0;
running = true;
} else {
document->curPoint = comm.info.nPoint;
int x, y, dx, dy, bigdx, bigdy;
unsigned cmdPoints = 0;
if (!started && comm.info.spaceSize && (comm.info.freeSpace<512) ) {
comm.startMove();
if (!comm.ack()) std::cerr << "Can't start" << std::endl;
started = true;
}
if ((sndPoint<document->instPoints.size()) && comm.info.spaceSize && (comm.info.freeSpace>64))
while (sndPoint<document->instPoints.size())
x = roundf(document->instPoints.at(sndPoint).x);
y = roundf(-document->instPoints.at(sndPoint).y);
dx = x-oldX;
dy = y-oldY;
if ((dx<-64)||(63<dx)||(dy<-64)||(63<dy))
bigdx = (dx+(dx>=0?0:1))/64;
bigdy = (dy+(dy>=0?0:1))/64;
dx -= 64*bigdx;
dy -= 64*bigdy;
if (cmdPoints==15)
{
comm.addPoints(dxys, 15);
if (!comm.ack()) std::cerr << "Can't add points" << std::endl;
return;
}
dxys[2*cmdPoints] = 0x80|int7(bigdx);
dxys[2*cmdPoints+1] = int7(bigdy);
cmdPoints++;
dxys[2*cmdPoints] = int7(dx);
dxys[2*cmdPoints+1] = int7(dy);
sndPoint++;
oldX = x;
oldY = y;
if (cmdPoints==16)
{
comm.addPoints(dxys, 16);
if (!comm.ack()) std::cerr << "Can't add points" << std::endl;
return;
}
comm.addPoints(dxys, cmdPoints);
if (!comm.ack()) std::cerr << "Can't add points" << std::endl;