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 )
{
this->display = display;
this->document = document;
OE_linestitch::initMotifs();
addThread(220,120,20,2);
}
OE_controller::~OE_controller()
{
}
bool OE_controller::test()
{
// test motifs
if (document)
{
3dsman
committed
unsigned curStitch = 0;
//addLineStitch(document->curves.at(0),0,0,1,0,1,0.1);
3dsman
committed
addLineStitch(document->curves.at(2),0.1,0.8,0.5,1,1,-0.5);
curStitch = document->stitchs.size()-1;
setStitchThread(curStitch, document->threads.at(0));
addBirailStitch(document->curves.at(2), document->curves.at(2), 0.1, 2, 0.8, 3, false, true, -1.2, -1.2, 1.5);
curStitch = document->stitchs.size()-1;
addThread(120,220,20,2);
addLineStitch();
curStitch = document->stitchs.size()-1;
setLineStitchCurve(curStitch, document->curves.at(5));
setLineStitchMotif(curStitch, 1);
setLineStitchSize(curStitch,2,1.5);
setStitchThread(curStitch, document->threads.at(1));
addBirailStitch(document->curves.at(0), document->curves.at(1), 0, 0, 2, 2,false,true, 0, 0, 1.5);
curStitch = document->stitchs.size()-1;
addBirailStitch(document->curves.at(0), document->curves.at(1), 2, 2, 4, 4,false,true, 0, 0, 1.5);
curStitch = document->stitchs.size()-1;
//refreshStitch(curStitch);
//addLineStitch(document->curves.at(15),1.5,3.5,1,0,0,0.1);
/*setLineStitchCurve(0, document->curves.at(0));
setLineStitchMotif(0, 1);
setLineStitchSize(0,2,2);
setStitchThread(0, document->threads.at(0));*/
3dsman
committed
addLineStitch(document->curves.at(13),0,0,1,0.5,1,0.1);
curStitch = document->stitchs.size()-1;
setStitchThread(curStitch, document->threads.at(0));
3dsman
committed
}
// fin motifs
return false;
}
bool OE_controller::setDefault()
{
OE_birailstitch::defaultLen = 1;
OE_birailstitch::defaultMaxlen = 0;
return true;
}
OE_stitchs* OE_controller::getStitch (unsigned index)
{
if ((document)&&(index<document->stitchs.size()))
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*> (document->stitchs.at(index)));
return nullptr;
}
OE_birailstitch* OE_controller::getBirailStitch (unsigned index)
{
if ((document)&&(index<document->stitchs.size()))
return (dynamic_cast<OE_birailstitch*> (document->stitchs.at(index)));
3dsman
committed
OE_linkstitch* OE_controller::getLinkStitch (unsigned index)
{
if ((document)&&(index<document->stitchs.size()))
return (dynamic_cast<OE_linkstitch*> (document->stitchs.at(index)));
return nullptr;
}
OE_thread* OE_controller::getThread (unsigned index)
{
if ((document)&&(index<document->threads.size()))
return document->threads.at(index);
return nullptr;
}
3dsman
committed
bool OE_controller::addStitch(OE_stitchs * stitch)
{
if (document)
{
if (document->stitchs.size() > 0)
document->addStitch( new OE_linkstitch(document->stitchs.at(document->stitchs.size()-1), stitch));
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_curve(points, closed));
}
return false;
}
bool OE_controller::addLineStitch()
{
if (document)
3dsman
committed
return addStitch(new OE_linestitch());
return false;
}
bool OE_controller::addLineStitch( OE_curve* curve,float curveStart, float curveEnd, float len, float width, unsigned motif, float offset)
{
if (document)
3dsman
committed
return addStitch(new OE_linestitch(curve,curveStart, curveEnd, len, width, motif, offset));
3dsman
committed
bool OE_controller::addBirailStitch(OE_curve* curve1, OE_curve* curve2, float curve1Start, float curve2Start, float curve1End, float curve2End, bool reverse1, bool reverse2, float offset1, float offset2, float len)
3dsman
committed
return addStitch(new OE_birailstitch(curve1, curve2, curve1Start, curve2Start, curve1End, curve2End, reverse1, reverse2, offset1, offset2, len));
3dsman
committed
/*
bool OE_controller::setLinkStitchStitch( unsigned index, OE_stitchs* stitchStart, OE_stitchs* stitchEnd)
3dsman
committed
return addStitch(new OE_linkstitch(stitchStart, stitchEnd));
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;
}
3dsman
committed
bool OE_controller::refreshStitchs()
{
if (document)
{
for(unsigned i = 0; i < document->stitchs.size();i++)
document->stitchs.at(i)->refresh();
}
return true;
}
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
261
262
263
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::setLineStitchSub( unsigned index, float start, float end)
{
OE_linestitch * tmpstitch = getLineStitch(index);
if (!tmpstitch)return false;
tmpstitch->setStart(start);
tmpstitch->setEnd(end);
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;
}
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
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::setBirailStitchSub( unsigned index, float start1, float end1, bool reverse1, float start2, float end2, bool reverse2)
{
OE_birailstitch * tmpstitch = getBirailStitch(index);
if (!tmpstitch)return false;
tmpstitch->setStart1(start1);
tmpstitch->setEnd1(end1);
tmpstitch->setReverse1(reverse1);
tmpstitch->setStart1(start2);
tmpstitch->setEnd1(end2);
tmpstitch->setReverse1(reverse2);
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;
}
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
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;
}