Refactoring DialogSpline.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-02-15 11:02:55 +02:00
parent 1925f6476c
commit f264206aab
5 changed files with 97 additions and 281 deletions

View File

@ -1861,8 +1861,12 @@ void VPattern::ParseToolSpline(VMainGraphicsScene *scene, const QDomElement &dom
const qreal kCurve = GetParametrDouble(domElement, AttrKCurve, "1.0");
const QString color = GetParametrString(domElement, AttrColor, ColorBlack);
VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, color, scene, this, data,
parse, Source::FromFile);
const auto p1 = data->GeometricObject<VPointF>(point1);
const auto p4 = data->GeometricObject<VPointF>(point4);
VSpline spline(*p1, *p4, angle1, angle2, kAsm1, kAsm2, kCurve);
VToolSpline::Create(id, spline, color, scene, this, data, parse, Source::FromFile);
}
catch (const VExceptionBadId &e)
{

View File

@ -43,7 +43,7 @@
* @param parent parent widget
*/
DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogSpline), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1)
:DialogTool(data, toolId, parent), ui(new Ui::DialogSpline), spl()
{
ui->setupUi(this);
InitOkCancelApply(ui);
@ -74,16 +74,6 @@ DialogSpline::~DialogSpline()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetP1 return id first point of spline
* @return id
*/
quint32 DialogSpline::GetP1() const
{
return getCurrentObjectId(ui->comboBoxP1);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
@ -133,17 +123,19 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type)
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::SaveData()
{
angle1 = ui->spinBoxAngle1->value();
angle2 = ui->spinBoxAngle2->value();
kAsm1 = ui->doubleSpinBoxKasm1->value();
kAsm2 = ui->doubleSpinBoxKasm2->value();
kCurve = ui->doubleSpinBoxKcurve->value();
const qreal angle1 = ui->spinBoxAngle1->value();
const qreal angle2 = ui->spinBoxAngle2->value();
const qreal kAsm1 = ui->doubleSpinBoxKasm1->value();
const qreal kAsm2 = ui->doubleSpinBoxKasm2->value();
const qreal kCurve = ui->doubleSpinBoxKcurve->value();
spl = VSpline(*GetP1(), *GetP4(), angle1, angle2, kAsm1, kAsm2, kCurve);
auto path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
path->setObject1Id(GetP1());
path->setObject4Id(GetP4());
path->setObject1Id(GetP1()->id());
path->setObject4Id(GetP4()->id());
path->SetAngle1(angle1);
path->SetAngle2(angle2);
path->SetKAsm1(kAsm1);
@ -153,6 +145,18 @@ void DialogSpline::SaveData()
path->RefreshGeometry();
}
//---------------------------------------------------------------------------------------------------------------------
const QSharedPointer<VPointF> DialogSpline::GetP1() const
{
return data->GeometricObject<VPointF>(getCurrentObjectId(ui->comboBoxP1));
}
//---------------------------------------------------------------------------------------------------------------------
const QSharedPointer<VPointF> DialogSpline::GetP4() const
{
return data->GeometricObject<VPointF>(getCurrentObjectId(ui->comboBoxP4));
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::PointNameChanged()
{
@ -181,22 +185,16 @@ void DialogSpline::ShowDialog(bool click)
{
if (prepare && click)
{
const auto p1 = data->GeometricObject<VPointF>(getCurrentObjectId(ui->comboBoxP1));
const auto p4 = data->GeometricObject<VPointF>(getCurrentObjectId(ui->comboBoxP4));
auto *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
const QPointF p2 = path->GetP2();
const QPointF p3 = path->GetP3();
VSpline spl(*GetP1(), path->GetP2(), path->GetP3(), *GetP4(), 1);
VSpline spline(*p1, p2, p3, *p4, kCurve);
ui->spinBoxAngle1->setValue(static_cast<qint32>(spl.GetStartAngle()));
ui->spinBoxAngle2->setValue(static_cast<qint32>(spl.GetEndAngle()));
ui->spinBoxAngle1->setValue(static_cast<qint32>(spline.GetStartAngle()));
ui->spinBoxAngle2->setValue(static_cast<qint32>(spline.GetEndAngle()));
ui->doubleSpinBoxKasm1->setValue(spline.GetKasm1());
ui->doubleSpinBoxKasm2->setValue(spline.GetKasm2());
ui->doubleSpinBoxKasm1->setValue(spl.GetKasm1());
ui->doubleSpinBoxKasm2->setValue(spl.GetKasm2());
DialogAccepted();
}
@ -209,18 +207,34 @@ void DialogSpline::ShowVisualization()
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetKCurve set coefficient curve
* @param value value. Can be >= 0.
*/
void DialogSpline::SetKCurve(const qreal &value)
VSpline DialogSpline::GetSpline() const
{
kCurve = value;
ui->doubleSpinBoxKcurve->setValue(value);
return spl;
}
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::SetSpline(const VSpline &spline)
{
spl = spline;
setCurrentPointId(ui->comboBoxP1, spl.GetP1().id());
setCurrentPointId(ui->comboBoxP4, spl.GetP4().id());
ui->spinBoxAngle1->setValue(static_cast<qint32>(spl.GetStartAngle()));
ui->spinBoxAngle2->setValue(static_cast<qint32>(spl.GetEndAngle()));
ui->doubleSpinBoxKasm1->setValue(spl.GetKasm1());
ui->doubleSpinBoxKasm2->setValue(spl.GetKasm2());
ui->doubleSpinBoxKcurve->setValue(spl.GetKcurve());
auto path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
path->SetKCurve(kCurve);
path->setObject1Id(spl.GetP1().id());
path->setObject4Id(spl.GetP4().id());
path->SetAngle1(spl.GetStartAngle());
path->SetAngle2(spl.GetEndAngle());
path->SetKAsm1(spl.GetKasm1());
path->SetKAsm2(spl.GetKasm2());
path->SetKCurve(spl.GetKcurve());
}
//---------------------------------------------------------------------------------------------------------------------
@ -234,151 +248,3 @@ void DialogSpline::SetColor(const QString &value)
{
ChangeCurrentData(ui->comboBoxColor, value);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetKAsm2 set second coefficient asymmetry
* @param value value. Can be >= 0.
*/
void DialogSpline::SetKAsm2(const qreal &value)
{
kAsm2 = value;
ui->doubleSpinBoxKasm2->setValue(value);
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
path->SetKAsm2(kAsm2);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetKAsm1 set first coefficient asymmetry
* @param value value. Can be >= 0.
*/
void DialogSpline::SetKAsm1(const qreal &value)
{
kAsm1 = value;
ui->doubleSpinBoxKasm1->setValue(value);
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
path->SetKAsm1(kAsm1);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetAngle2 set second angle of spline
* @param value angle in degree
*/
void DialogSpline::SetAngle2(const qreal &value)
{
angle2 = value;
ui->spinBoxAngle2->setValue(static_cast<qint32>(value));
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
path->SetAngle2(angle2);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetAngle1 set first angle of spline
* @param value angle in degree
*/
void DialogSpline::SetAngle1(const qreal &value)
{
angle1 = value;
ui->spinBoxAngle1->setValue(static_cast<qint32>(value));
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
path->SetAngle1(angle1);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetP4 set id fourth point of spline
* @param value id
*/
void DialogSpline::SetP4(const quint32 &value)
{
setCurrentPointId(ui->comboBoxP4, value);
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
path->setObject4Id(value);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetP1 set id first point of spline
* @param value id
*/
void DialogSpline::SetP1(const quint32 &value)
{
setCurrentPointId(ui->comboBoxP1, value);
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
path->setObject1Id(value);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetP4 return id fourth point of spline
* @return id
*/
quint32 DialogSpline::GetP4() const
{
return getCurrentObjectId(ui->comboBoxP4);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetAngle1 return first angle of spline
* @return angle in degree
*/
qreal DialogSpline::GetAngle1() const
{
return angle1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetAngle2 return second angle of spline
* @return angle in degree
*/
qreal DialogSpline::GetAngle2() const
{
return angle2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetKAsm1 return first coefficient asymmetry
* @return value. Can be >= 0.
*/
qreal DialogSpline::GetKAsm1() const
{
return kAsm1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetKAsm2 return second coefficient asymmetry
* @return value. Can be >= 0.
*/
qreal DialogSpline::GetKAsm2() const
{
return kAsm2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetKCurve return coefficient curve
* @return value. Can be >= 0.
*/
qreal DialogSpline::GetKCurve() const
{
return kCurve;
}

View File

@ -30,6 +30,7 @@
#define DIALOGSPLINE_H
#include "dialogtool.h"
#include "../vgeometry/vspline.h"
namespace Ui
{
@ -46,26 +47,8 @@ public:
DialogSpline(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
virtual ~DialogSpline() Q_DECL_OVERRIDE;
quint32 GetP1() const;
void SetP1(const quint32 &value);
quint32 GetP4() const;
void SetP4(const quint32 &value);
qreal GetAngle1() const;
void SetAngle1(const qreal &value);
qreal GetAngle2() const;
void SetAngle2(const qreal &value);
qreal GetKAsm1() const;
void SetKAsm1(const qreal &value);
qreal GetKAsm2() const;
void SetKAsm2(const qreal &value);
qreal GetKCurve() const;
void SetKCurve(const qreal &value);
VSpline GetSpline() const;
void SetSpline(const VSpline &spline);
QString GetColor() const;
void SetColor(const QString &value);
@ -85,20 +68,11 @@ private:
/** @brief ui keeps information about user interface */
Ui::DialogSpline *ui;
/** @brief angle1 first angle of spline in degree */
qreal angle1;
/** @brief spl spline */
VSpline spl;
/** @brief angle2 second angle of spline in degree */
qreal angle2;
/** @brief kAsm1 first coefficient asymmetry */
qreal kAsm1;
/** @brief kAsm2 second coefficient asymmetry */
qreal kAsm2;
/** @brief kCurve coefficient curve */
qreal kCurve;
const QSharedPointer<VPointF> GetP1() const;
const QSharedPointer<VPointF> GetP4() const;
};
#endif // DIALOGSPLINE_H

View File

@ -104,14 +104,8 @@ void VToolSpline::setDialog()
SCASSERT(dialog != nullptr);
DialogSpline *dialogTool = qobject_cast<DialogSpline*>(dialog);
SCASSERT(dialogTool != nullptr);
const QSharedPointer<VSpline> spl = VAbstractTool::data.GeometricObject<VSpline>(id);
dialogTool->SetP1(spl->GetP1().id());
dialogTool->SetP4(spl->GetP4().id());
dialogTool->SetAngle1(spl->GetStartAngle());
dialogTool->SetAngle2(spl->GetEndAngle());
dialogTool->SetKAsm1(spl->GetKasm1());
dialogTool->SetKAsm2(spl->GetKasm2());
dialogTool->SetKCurve(spl->GetKcurve());
const auto spl = VAbstractTool::data.GeometricObject<VSpline>(id);
dialogTool->SetSpline(*spl);
dialogTool->SetColor(lineColor);
}
@ -127,18 +121,12 @@ void VToolSpline::setDialog()
VToolSpline* VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data)
{
SCASSERT(dialog != nullptr);
DialogSpline *dialogTool = qobject_cast<DialogSpline*>(dialog);
auto dialogTool = qobject_cast<DialogSpline*>(dialog);
SCASSERT(dialogTool != nullptr);
const quint32 p1 = dialogTool->GetP1();
const quint32 p4 = dialogTool->GetP4();
const qreal kAsm1 = dialogTool->GetKAsm1();
const qreal kAsm2 = dialogTool->GetKAsm2();
const qreal angle1 = dialogTool->GetAngle1();
const qreal angle2 = dialogTool->GetAngle2();
const qreal kCurve = dialogTool->GetKCurve();
const QString color = dialogTool->GetColor();
VToolSpline *spl = Create(0, p1, p4, kAsm1, kAsm2, angle1, angle2, kCurve, color, scene, doc, data,
Document::FullParse, Source::FromGui);
auto spl = Create(0, dialogTool->GetSpline(), dialogTool->GetColor(), scene, doc, data, Document::FullParse,
Source::FromGui);
if (spl != nullptr)
{
spl->dialog=dialogTool;
@ -150,13 +138,8 @@ VToolSpline* VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene,
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param p1 id first spline point.
* @param p4 id last spline point.
* @param kAsm1 coefficient of length first control line.
* @param kAsm2 coefficient of length second control line.
* @param angle1 angle from first point to first control point.
* @param angle2 angle from second point to second control point.
* @param kCurve coefficient of curvature spline.
* @param spl spline.
* @param color spline color.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
@ -164,15 +147,11 @@ VToolSpline* VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene,
* @param typeCreation way we create this tool.
* @return the created tool
*/
VToolSpline* VToolSpline::Create(const quint32 _id, const quint32 &p1, const quint32 &p4, const qreal &kAsm1,
const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve,
const QString &color, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data,
const Document &parse, const Source &typeCreation)
VToolSpline* VToolSpline::Create(const quint32 _id, const VSpline &spl, const QString &color, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation)
{
VPointF point1 = *data->GeometricObject<VPointF>(p1);
VPointF point4 = *data->GeometricObject<VPointF>(p4);
VSpline *spline = new VSpline(point1, point4, angle1, angle2, kAsm1, kAsm2, kCurve);
auto spline = new VSpline(spl);
quint32 id = _id;
if (typeCreation == Source::FromGui)
{
@ -191,17 +170,17 @@ VToolSpline* VToolSpline::Create(const quint32 _id, const quint32 &p1, const qui
VDrawTool::AddRecord(id, Tool::Spline, doc);
if (parse == Document::FullParse)
{
VToolSpline *spl = new VToolSpline(doc, data, id, color, typeCreation);
scene->addItem(spl);
connect(spl, &VToolSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
connect(scene, &VMainGraphicsScene::NewFactor, spl, &VToolSpline::SetFactor);
connect(scene, &VMainGraphicsScene::DisableItem, spl, &VToolSpline::Disable);
connect(scene, &VMainGraphicsScene::EnableToolMove, spl, &VToolSpline::EnableToolMove);
connect(scene, &VMainGraphicsScene::CurveDetailsMode, spl, &VToolSpline::DetailsMode);
doc->AddTool(id, spl);
doc->IncrementReferens(point1.getIdTool());
doc->IncrementReferens(point4.getIdTool());
return spl;
auto _spl = new VToolSpline(doc, data, id, color, typeCreation);
scene->addItem(_spl);
connect(_spl, &VToolSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
connect(scene, &VMainGraphicsScene::NewFactor, _spl, &VToolSpline::SetFactor);
connect(scene, &VMainGraphicsScene::DisableItem, _spl, &VToolSpline::Disable);
connect(scene, &VMainGraphicsScene::EnableToolMove, _spl, &VToolSpline::EnableToolMove);
connect(scene, &VMainGraphicsScene::CurveDetailsMode, _spl, &VToolSpline::DetailsMode);
doc->AddTool(id, _spl);
doc->IncrementReferens(spline->GetP1().id());
doc->IncrementReferens(spline->GetP4().id());
return _spl;
}
return nullptr;
}
@ -297,13 +276,10 @@ void VToolSpline::RemoveReferens()
void VToolSpline::SaveDialog(QDomElement &domElement)
{
SCASSERT(dialog != nullptr);
DialogSpline *dialogTool = qobject_cast<DialogSpline*>(dialog);
auto dialogTool = qobject_cast<DialogSpline*>(dialog);
SCASSERT(dialogTool != nullptr);
VPointF point1 = *VAbstractTool::data.GeometricObject<VPointF>(dialogTool->GetP1());
VPointF point4 = *VAbstractTool::data.GeometricObject<VPointF>(dialogTool->GetP4());
VSpline spl = VSpline (point1, point4, dialogTool->GetAngle1(), dialogTool->GetAngle2(),
dialogTool->GetKAsm1(), dialogTool->GetKAsm2(), dialogTool->GetKCurve());
const VSpline spl = dialogTool->GetSpline();
controlPoints[0]->blockSignals(true);
controlPoints[1]->blockSignals(true);
@ -314,8 +290,6 @@ void VToolSpline::SaveDialog(QDomElement &domElement)
controlPoints[0]->blockSignals(false);
controlPoints[1]->blockSignals(false);
spl = VSpline (point1, controlPoints[0]->pos(), controlPoints[1]->pos(), point4, dialogTool->GetKCurve());
doc->SetAttribute(domElement, AttrPoint1, spl.GetP1().id());
doc->SetAttribute(domElement, AttrPoint4, spl.GetP4().id());
doc->SetAttribute(domElement, AttrAngle1, spl.GetStartAngle());

View File

@ -45,11 +45,9 @@ public:
virtual ~VToolSpline() Q_DECL_OVERRIDE;
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolSpline *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data);
static VToolSpline *Create(const quint32 _id, const quint32 &p1, const quint32 &p4, const qreal &kAsm1,
const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve,
const QString &color, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolSpline *Create(const quint32 _id, const VSpline &spl, const QString &color, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::Spline)};