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
/*
* 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();
}
OE_controller::~OE_controller()
{
}
bool OE_controller::test()
{
// test motifs
if (document)
{
addLineStitch(document->curves.at(0),0.4,0.6,1,0,1,0.1);
addLineStitch(document->curves.at(8),0,0,1,0.5,1,0.1);
/*addLineStitch();
setLineStitchCurve(0, document->curves.at(0));
setLineStitchMotif(0, 1);
setLineStitchSize(0,2,2);
setLineStitchCurve(1, document->curves.at(1));
setLineStitchMotif(1, 1);
setLineStitchSize(1,3,2);
addLineStitch(document->curves.at(2),0.1,0.8,0.5,1,1,-0.5);
addBirailStitch(document->curves.at(0), document->curves.at(1), 0, 0, 2, 2,false,true, 0, 0, 1.5);
addBirailStitch(document->curves.at(0), document->curves.at(1), 2, 2, 4, 4,false,true, 0, 0, 1.5);
addBirailStitch(document->curves.at(2), document->curves.at(2), 0.1, 2, 0.8, 3, false, true, -1.2, -1.2, 1.5);*/
}
// fin motifs
return false;
}
bool OE_controller::setDefault()
{
OE_birailstitch::defaultLen = 1;
OE_birailstitch::defaultMaxlen = 0;
return true;
}
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)));
return nullptr;
}
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)
return document->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)
return document->addStitch(new OE_linestitch(curve,curveStart, curveEnd, len, width, motif, offset));
return false;
}
bool OE_controller::addBirailStitch()
{
if (document)
return document->addStitch(new OE_birailstitch());
return false;
}
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)
return document->addStitch(new OE_birailstitch(curve1, curve2, curve1Start, curve2Start, curve1End, curve2End, reverse1, reverse2, offset1, offset2, len));
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
bool OE_controller::setLineStitchMotif( unsigned index, unsigned motif)
{
OE_linestitch * tmpstitch = getLineStitch(index);
if (!tmpstitch)return false;
tmpstitch->setMotif(motif);
tmpstitch->needRefresh=true;
return true;
}
bool OE_controller::setLineStitchCurve( unsigned index, OE_curve* curve)
{
OE_linestitch * tmpstitch = getLineStitch(index);
if (!tmpstitch)return false;
tmpstitch->setCurve(curve);
tmpstitch->needRefresh=true;
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);
tmpstitch->needRefresh=true;
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);
tmpstitch->needRefresh=true;
return true;
}
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
206
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);
tmpstitch->needRefresh=true;
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);
tmpstitch->needRefresh=true;
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);
tmpstitch->needRefresh=true;
return true;
}