2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
// StrokeDeformation.cpp: implementation of the StrokeDeformation class.
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#ifdef _DEBUG
|
|
|
|
#define _STLP_DEBUG 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ext/StrokeDeformation.h"
|
|
|
|
#include "ext/SquarePotential.h"
|
|
|
|
#include "ext/StrokeParametricDeformer.h"
|
2016-09-06 01:20:21 +12:00
|
|
|
#include "ext/NotSymmetricBezierPotential.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
#include "ext/SmoothDeformation.h"
|
|
|
|
#include "ext/ContextStatus.h"
|
|
|
|
#include "ext/Designer.h"
|
|
|
|
//#include "ext/TriParam.h"
|
|
|
|
|
|
|
|
#include "ext/StraightCornerDeformation.h"
|
|
|
|
#include "ext/CornerDeformation.h"
|
|
|
|
|
|
|
|
#include "ext/StrokeDeformationImpl.h"
|
|
|
|
#include "DeformationSelector.h"
|
|
|
|
|
|
|
|
#include <tcurves.h>
|
|
|
|
#include <tstrokeutil.h>
|
|
|
|
#include <tmathutil.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iterator>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "tthreadmessage.h"
|
|
|
|
|
|
|
|
using namespace ToonzExt;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Manage a mutable context.
|
|
|
|
*/
|
|
|
|
static TThread::Mutex s_mutex;
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
StrokeDeformation::StrokeDeformation() {
|
|
|
|
state_ = CREATED;
|
|
|
|
deformationImpl_ = SmoothDeformation::instance();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
StrokeDeformation::~StrokeDeformation() {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void StrokeDeformation::activate(const ContextStatus *status) {
|
|
|
|
QMutexLocker sl(&s_mutex);
|
|
|
|
|
|
|
|
assert(status && "Status is null!!!");
|
|
|
|
if (!status) return;
|
|
|
|
|
|
|
|
if (state_ == RESETTED) delete this->deactivate();
|
|
|
|
|
|
|
|
if (state_ == CREATED || state_ == DEACTIVE) {
|
|
|
|
deformationImpl_ = this->retrieveDeformator(status);
|
|
|
|
} else {
|
|
|
|
// if it is a not valid entry state_ recover
|
|
|
|
assert(deformationImpl_ && "Can not find a valid deformator!!!");
|
|
|
|
if (!deformationImpl_) return;
|
|
|
|
deformationImpl_->reset();
|
|
|
|
deformationImpl_ = DeformationSelector::instance()->getDeformation(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(deformationImpl_ && "Deformation is null!!!");
|
|
|
|
if (!deformationImpl_) return;
|
|
|
|
|
|
|
|
if (!deformationImpl_->activate_impl(status)) {
|
|
|
|
deformationImpl_->reset();
|
|
|
|
state_ = DEACTIVE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
state_ = ACTIVE;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void StrokeDeformation::update(const TPointD &delta) {
|
|
|
|
QMutexLocker sl(&s_mutex);
|
|
|
|
|
|
|
|
assert(deformationImpl_ && "Deformation is null!!!");
|
|
|
|
if (!deformationImpl_) {
|
|
|
|
state_ = DEACTIVE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state_ != ACTIVE && state_ != UPDATING) {
|
|
|
|
deformationImpl_->reset();
|
|
|
|
state_ = ACTIVE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
deformationImpl_->update_impl(delta);
|
|
|
|
state_ = UPDATING;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TStroke *StrokeDeformation::deactivate() {
|
|
|
|
QMutexLocker sl(&s_mutex);
|
|
|
|
|
|
|
|
if (!deformationImpl_) {
|
|
|
|
state_ = DEACTIVE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state_ != ACTIVE && state_ != UPDATING) {
|
|
|
|
state_ = DEACTIVE;
|
|
|
|
deformationImpl_->reset();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
state_ = DEACTIVE;
|
|
|
|
TStroke *out = deformationImpl_->deactivate_impl();
|
|
|
|
deformationImpl_ = 0;
|
|
|
|
return out;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void StrokeDeformation::reset() {
|
|
|
|
QMutexLocker sl(&s_mutex);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
state_ = RESETTED;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void StrokeDeformation::draw(Designer *designer) {
|
|
|
|
QMutexLocker sl(&s_mutex);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
assert(designer && "Designer is null!!!");
|
|
|
|
if (!deformationImpl_ || !designer) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// this is to draw the icon
|
|
|
|
deformationImpl_->draw(designer);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// this is to draw stroke when change something
|
|
|
|
designer->draw(this);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void StrokeDeformation::check(const ContextStatus *status) {
|
|
|
|
QMutexLocker sl(&s_mutex);
|
|
|
|
if (state_ != UPDATING) deformationImpl_ = this->retrieveDeformator(status);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
const TStroke *StrokeDeformation::getCopiedStroke() const {
|
|
|
|
QMutexLocker sl(&s_mutex);
|
|
|
|
if (deformationImpl_) return deformationImpl_->getCopiedStroke();
|
|
|
|
return 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
const TStroke *StrokeDeformation::getStroke() const {
|
|
|
|
QMutexLocker sl(&s_mutex);
|
|
|
|
if (deformationImpl_) return deformationImpl_->getStrokeSelected();
|
|
|
|
return 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
const TStroke *StrokeDeformation::getTransformedStroke() const {
|
|
|
|
QMutexLocker sl(&s_mutex);
|
|
|
|
if (deformationImpl_) return deformationImpl_->getTransformedStroke();
|
|
|
|
return 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void StrokeDeformation::recover() {
|
|
|
|
QMutexLocker sl(&s_mutex);
|
|
|
|
assert(deformationImpl_ && "Deformation is null!!!");
|
|
|
|
if (!deformationImpl_) return;
|
|
|
|
|
|
|
|
deformationImpl_->reset();
|
|
|
|
// this->clearStatus();
|
|
|
|
|
|
|
|
// deformationImpl_ = DeformationSelector::instance()->getDeformation(status);
|
|
|
|
// assert(deformationImpl_ && "Deformation is null!!!" );
|
|
|
|
// if( !deformationImpl_ )
|
|
|
|
// return;
|
|
|
|
// deformationImpl_->activate_impl(status);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
const ContextStatus *StrokeDeformation::getStatus() const {
|
|
|
|
QMutexLocker sl(&s_mutex);
|
|
|
|
if (deformationImpl_) return deformationImpl_->getImplStatus();
|
|
|
|
return 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
ToonzExt::Interval StrokeDeformation::getExtremes() const {
|
|
|
|
QMutexLocker sl(&s_mutex);
|
|
|
|
if (!deformationImpl_) return Interval(-1, -1);
|
|
|
|
return deformationImpl_->getExtremes();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
StrokeDeformationImpl *StrokeDeformation::retrieveDeformator(
|
|
|
|
const ContextStatus *status) {
|
|
|
|
QMutexLocker sl(&s_mutex);
|
|
|
|
return DeformationSelector::instance()->getDeformation(status);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int StrokeDeformation::getCursorId() const {
|
|
|
|
QMutexLocker sl(&s_mutex);
|
|
|
|
if (!deformationImpl_) return -1;
|
|
|
|
return deformationImpl_->getCursorId();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
const Potential *StrokeDeformation::getPotential() const {
|
|
|
|
assert(deformationImpl_ && "Deformation is null!!!");
|
|
|
|
if (!deformationImpl_) return 0;
|
|
|
|
return deformationImpl_->getPotential();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
const StrokeDeformationImpl *StrokeDeformation::getDeformationImpl() const {
|
|
|
|
return deformationImpl_;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// End Of File
|
|
|
|
//-----------------------------------------------------------------------------
|