Skip to content
OE_subcurve.cpp 2.25 KiB
Newer Older
3dsman's avatar
3dsman committed
* This file is part of project OpenEmbroidery. It's copyrighted by
* the contributors recorded in the version control history of the file.
* Original project location https://code.electrolab.fr/openEmbroidery/openEmbroidery_software
*
* SPDX-License-Identifier: CECILL-2.1
* License-Filename: Licence_CeCILL_V2.1-en.txt
*/
#include "curves/OE_subcurve.h"
raoul's avatar
raoul committed
#include "Archive.h"
#include <iostream>

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>

raoul's avatar
raoul committed
OE_subcurve::OE_subcurve() : curve(nullptr), start(0), end(0), reverse(false)
{
}

raoul's avatar
raoul committed
OE_subcurve::OE_subcurve(OE_curve* curve, float curveStart, float curveEnd, bool reverse) : start(-1), end(-1)
{
	this->curve = curve;
	start = curveStart;
	end = curveEnd;
raoul's avatar
raoul committed
	this->reverse = reverse;
	//refresh();
}

OE_subcurve::~OE_subcurve()
{
raoul's avatar
raoul committed
	curve->removeDependency(this);
raoul's avatar
raoul committed
void OE_subcurve::persist(Pakal::Archive* archive)
{
	archive->refer("curve", curve);
	archive->value("start", start);
	archive->value("end", end);
	archive->value("reverse", reverse);
}
raoul's avatar
raoul committed
/** \brief check if the curve is valid. */
bool OE_subcurve::check()
{
raoul's avatar
raoul committed
	return curve != 0;
raoul's avatar
raoul committed

/** \brief refresh the discPts array. */
void OE_subcurve::refresh(float dpi, bool force)
raoul's avatar
raoul committed
{
	if (!check() || !(needRefresh||force))
	{
		return;
	}

	curve->refresh(dpi, force);

	float tmpStart = start;
	float tmpEnd = end;
raoul's avatar
raoul committed
	if (start == -1)
	{
		tmpStart = 0;
	}
	if (end == -1)
	{
		tmpEnd = (curve->getNpts()-1)/3;
	}

	pts.clear();
	pts = curve->subCurve(tmpStart, tmpEnd, reverse);
raoul's avatar
raoul committed
	OE_curve::refresh(dpi);
raoul's avatar
raoul committed
void OE_subcurve::delDependency(OE_base* object)
raoul's avatar
raoul committed
	if (curve == object)
	{
		curve = 0;
	}
void OE_subcurve::refreshDependency()
{
raoul's avatar
raoul committed
	if(curve)
	{
		curve->refreshDependency();
raoul's avatar
raoul committed
		curve->addDependency(this);
raoul's avatar
raoul committed
}
bool OE_subcurve::setStart(float curveStart)
{
raoul's avatar
raoul committed
	start = curveStart;
	setNeedRefresh();
	return true;
}

bool OE_subcurve::setEnd(float curveEnd)
{
raoul's avatar
raoul committed
	end = curveEnd;
	setNeedRefresh();
raoul's avatar
raoul committed
	reverse = curveReverse;
	setNeedRefresh();
	return true;
OE_curve* OE_subcurve::getCurve()
{
raoul's avatar
raoul committed
	return curve;
}

float OE_subcurve::getStart()
{
	return start;
}

float OE_subcurve::getEnd()
{
	return end;
}

bool OE_subcurve::getReverse()
{
	return reverse;