Visualization for VToolCutSpline.

--HG--
branch : feature
This commit is contained in:
dismine 2014-09-06 15:47:25 +03:00
parent d2e5be50b4
commit 2a4eef7695
12 changed files with 230 additions and 35 deletions

View File

@ -32,6 +32,7 @@
#include "../../geometry/vspline.h" #include "../../geometry/vspline.h"
#include "../../container/vcontainer.h" #include "../../container/vcontainer.h"
#include "../../xml/vpattern.h" #include "../../xml/vpattern.h"
#include "../../visualization/vistoolcutspline.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
@ -41,7 +42,7 @@
*/ */
DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogCutSpline), formula(QString()), :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSpline), formula(QString()),
splineId(NULL_ID), formulaBaseHeight(0) splineId(NULL_ID), formulaBaseHeight(0), path(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);
InitVariables(ui); InitVariables(ui);
@ -50,7 +51,7 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId,
labelEditNamePoint = ui->labelEditNamePoint; labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight = ui->plainTextEditFormula->height(); this->formulaBaseHeight = ui->plainTextEditFormula->height();
InitOkCancel(ui); InitOkCancelApply(ui);
flagFormula = false; flagFormula = false;
CheckState(); CheckState();
@ -62,11 +63,14 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId,
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSpline::NamePointChanged); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSpline::NamePointChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutSpline::FormulaChanged); connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutSpline::FormulaChanged);
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSpline::DeployFormulaTextEdit); connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSpline::DeployFormulaTextEdit);
path = new VisToolCutSpline(data);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogCutSpline::~DialogCutSpline() DialogCutSpline::~DialogCutSpline()
{ {
delete path;
delete ui; delete ui;
} }
@ -96,6 +100,7 @@ void DialogCutSpline::setFormula(const QString &value)
this->DeployFormulaTextEdit(); this->DeployFormulaTextEdit();
} }
ui->plainTextEditFormula->setPlainText(formula); ui->plainTextEditFormula->setPlainText(formula);
path->setLength(formula);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -106,6 +111,7 @@ void DialogCutSpline::setFormula(const QString &value)
void DialogCutSpline::setSplineId(const quint32 &value) void DialogCutSpline::setSplineId(const quint32 &value)
{ {
setCurrentSplineId(ui->comboBoxSpline, splineId, value, ComboBoxCutSpline::CutSpline); setCurrentSplineId(ui->comboBoxSpline, splineId, value, ComboBoxCutSpline::CutSpline);
path->setPoint1Id(splineId);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -122,6 +128,8 @@ void DialogCutSpline::ChosenObject(quint32 id, const SceneObject &type)
{ {
if (SetObject(id, ui->comboBoxSpline, "")) if (SetObject(id, ui->comboBoxSpline, ""))
{ {
path->VisualMode(id);
prepare = true;
this->setModal(true); this->setModal(true);
this->show(); this->show();
} }
@ -136,6 +144,10 @@ void DialogCutSpline::SaveData()
formula = ui->plainTextEditFormula->toPlainText(); formula = ui->plainTextEditFormula->toPlainText();
formula.replace("\n", " "); formula.replace("\n", " ");
splineId = getCurrentObjectId(ui->comboBoxSpline); splineId = getCurrentObjectId(ui->comboBoxSpline);
path->setPoint1Id(splineId);
path->setLength(formula);
path->RefreshGeometry();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -143,3 +155,15 @@ void DialogCutSpline::DeployFormulaTextEdit()
{ {
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight); DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSpline::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor);
scene->addItem(path);
path->RefreshGeometry();
}
}

View File

@ -36,6 +36,8 @@ namespace Ui
class DialogCutSpline; class DialogCutSpline;
} }
class VisToolCutSpline;
/** /**
* @brief The DialogCutSpline class dialog for ToolCutSpline. * @brief The DialogCutSpline class dialog for ToolCutSpline.
*/ */
@ -61,6 +63,7 @@ public slots:
*/ */
void DeployFormulaTextEdit(); void DeployFormulaTextEdit();
protected: protected:
virtual void ShowVisualization();
/** /**
* @brief SaveData Put dialog data in local variables * @brief SaveData Put dialog data in local variables
*/ */
@ -79,6 +82,8 @@ private:
/** @brief formulaBaseHeight base height defined by dialogui */ /** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight; int formulaBaseHeight;
VisToolCutSpline *path;
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -392,7 +392,7 @@
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -241,6 +241,20 @@ QPointF VSpline::CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPo
return p1234; return p1234;
} }
//---------------------------------------------------------------------------------------------------------------------
QPointF VSpline::CutSpline(qreal length, VSpline &spl1, VSpline &spl2) const
{
QPointF spl1p2;
QPointF spl1p3;
QPointF spl2p2;
QPointF spl2p3;
QPointF cutPoint = CutSpline (length, spl1p2, spl1p3, spl2p2, spl2p3 );
spl1 = VSpline(GetP1(), spl1p2, spl1p3, cutPoint, GetKcurve());
spl2 = VSpline(cutPoint, spl2p2, spl2p3, GetP4(), GetKcurve());
return cutPoint;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief GetPoints return list with spline points. * @brief GetPoints return list with spline points.

View File

@ -68,6 +68,7 @@ public:
QLineF::IntersectType CrossingSplLine(const QLineF &line, QPointF *intersectionPoint ) const; QLineF::IntersectType CrossingSplLine(const QLineF &line, QPointF *intersectionPoint ) const;
qreal LengthT(qreal t) const; qreal LengthT(qreal t) const;
QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const; QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const;
QPointF CutSpline ( qreal length, VSpline &spl1, VSpline &spl2) const;
QVector<QPointF> GetPoints () const; QVector<QPointF> GetPoints () const;
// cppcheck-suppress unusedFunction // cppcheck-suppress unusedFunction
static QVector<QPointF> SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, static QVector<QPointF> SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1,

View File

@ -497,8 +497,10 @@ void MainWindow::ToolSpline(bool checked)
*/ */
void MainWindow::ToolCutSpline(bool checked) void MainWindow::ToolCutSpline(bool checked)
{ {
SetToolButton<DialogCutSpline>(checked, Tool::CutSpline, ":/cursor/spline_cut_point_cursor.png", SetToolButtonWithApply<DialogCutSpline>(checked, Tool::CutSpline, ":/cursor/spline_cut_point_cursor.png",
tr("Select simple curve"), &MainWindow::ClosedDialog<VToolCutSpline>); tr("Select simple curve"),
&MainWindow::ClosedDialogWithApply<VToolCutSpline>,
&MainWindow::ApplyDialog<VToolCutSpline>);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -99,7 +99,10 @@ enum class Vis : unsigned char
ToolPointOfIntersection, ToolPointOfIntersection,
ToolShoulderPoint, ToolShoulderPoint,
ToolSpline, ToolSpline,
ToolTriangle ToolTriangle,
ToolCutSpline,
ToolSplinePath,
ToolCutSplinePath
}; };
enum class Source : char { FromGui, FromFile, FromTool }; enum class Source : char { FromGui, FromFile, FromTool };

View File

@ -43,6 +43,7 @@ public:
virtual int type() const {return Type;} virtual int type() const {return Type;}
enum { Type = UserType + static_cast<int>(Tool::AbstractSpline)}; enum { Type = UserType + static_cast<int>(Tool::AbstractSpline)};
virtual QString getTagName() const; virtual QString getTagName() const;
void ShowFoot(bool show);
public slots: public slots:
virtual void FullUpdateFromFile (); virtual void FullUpdateFromFile ();
void Disable(bool disable); void Disable(bool disable);
@ -81,7 +82,6 @@ protected:
virtual void keyReleaseEvent(QKeyEvent * event); virtual void keyReleaseEvent(QKeyEvent * event);
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
QPainterPath ToolPath(PathDirection direction = PathDirection::Hide) const; QPainterPath ToolPath(PathDirection direction = PathDirection::Hide) const;
void ShowFoot(bool show);
}; };
#endif // VABSTRACTSPLINE_H #endif // VABSTRACTSPLINE_H

View File

@ -30,6 +30,8 @@
#include "../../container/calculator.h" #include "../../container/calculator.h"
#include "../../dialogs/tools/dialogcutspline.h" #include "../../dialogs/tools/dialogcutspline.h"
#include "../../geometry/vpointf.h" #include "../../geometry/vpointf.h"
#include "../../visualization/vistoolcutspline.h"
#include "vabstractspline.h"
#include <geometry/vspline.h> #include <geometry/vspline.h>
@ -190,33 +192,38 @@ VToolCutSpline* VToolCutSpline::Create(const quint32 _id, const QString &pointNa
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolCutSpline::ShowVisualization(bool show) void VToolCutSpline::ShowVisualization(bool show)
{ {
// if (show) if (show)
// { {
// if (vis == nullptr) if (vis == nullptr)
// { {
// VisTool * visual = new VisTool(getData()); VisToolCutSpline * visual = new VisToolCutSpline(getData());
// VMainGraphicsScene *scene = qApp->getCurrentScene(); VMainGraphicsScene *scene = qApp->getCurrentScene();
// connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
// scene->addItem(visual); scene->addItem(visual);
// // add options visual->setPoint1Id(curveCutId);
// visual->RefreshGeometry(); visual->setLength(formula);
// vis = visual; visual->RefreshGeometry();
// } vis = visual;
// else }
// { else
// VisTool * visual = qobject_cast<VisTool *>(vis); {
// if (visual != nullptr) VisToolCutSpline * visual = qobject_cast<VisToolCutSpline *>(vis);
// { if (visual != nullptr)
// visual->show(); {
// } visual->show();
// } }
// } }
// else }
// { else
// delete vis; {
// vis = nullptr; delete vis;
// } vis = nullptr;
}
if (VAbstractSpline *parentCurve = qobject_cast<VAbstractSpline *>(doc->getTool(curveCutId)))
{
parentCurve->ShowFoot(show);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -226,6 +233,14 @@ void VToolCutSpline::ShowVisualization(bool show)
void VToolCutSpline::FullUpdateFromFile() void VToolCutSpline::FullUpdateFromFile()
{ {
FullUpdateCurveFromFile(AttrSpline); FullUpdateCurveFromFile(AttrSpline);
if (vis != nullptr)
{
VisToolCutSpline *visual = qobject_cast<VisToolCutSpline *>(vis);
visual->setPoint1Id(curveCutId);
visual->setLength(formula);
visual->RefreshGeometry();
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -0,0 +1,76 @@
/************************************************************************
**
** @file vistoolcutspline.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 6 9, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vistoolcutspline.h"
#include "../geometry/vspline.h"
#include "../container/vcontainer.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolCutSpline::VisToolCutSpline(const VContainer *data, QGraphicsItem *parent)
:VisPath(data, parent), point(nullptr), spl1(nullptr), spl2(nullptr), length(0)
{
spl1 = InitItem<QGraphicsPathItem>(Qt::darkGreen, this);
spl1->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
spl2 = InitItem<QGraphicsPathItem>(Qt::darkRed, this);
spl2->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
point = InitPoint(mainColor, this);
point->setZValue(2);
point->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
}
//---------------------------------------------------------------------------------------------------------------------
VisToolCutSpline::~VisToolCutSpline()
{}
//---------------------------------------------------------------------------------------------------------------------
void VisToolCutSpline::RefreshGeometry()
{
if (point1Id > 0)
{
const QSharedPointer<VSpline> spl = Visualization::data->GeometricObject<VSpline>(point1Id);
DrawPath(this, spl->GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap);
if (qFuzzyCompare(1 + length, 1 + 0) == false)
{
VSpline sp1;
VSpline sp2;
QPointF p = spl->CutSpline(length, sp1, sp2);
DrawPoint(point, p, mainColor);
DrawPath(spl1, sp1.GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap);
DrawPath(spl2, sp2.GetPath(PathDirection::Show), Qt::darkRed, Qt::SolidLine, Qt::RoundCap);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolCutSpline::setLength(const QString &expression)
{
length = FindLength(expression);
}

View File

@ -0,0 +1,53 @@
/************************************************************************
**
** @file vistoolcutspline.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 6 9, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VISTOOLCUTSPLINE_H
#define VISTOOLCUTSPLINE_H
#include "vispath.h"
class VisToolCutSpline : public VisPath
{
Q_OBJECT
public:
VisToolCutSpline(const VContainer *data, QGraphicsItem *parent = 0);
virtual ~VisToolCutSpline();
virtual void RefreshGeometry();
void setLength(const QString &expression);
virtual int type() const {return Type;}
enum { Type = UserType + static_cast<int>(Vis::ToolCutSpline)};
protected:
Q_DISABLE_COPY(VisToolCutSpline)
QGraphicsEllipseItem *point;
QGraphicsPathItem *spl1;
QGraphicsPathItem *spl2;
qreal length;
};
#endif // VISTOOLCUTSPLINE_H

View File

@ -18,7 +18,8 @@ HEADERS += \
visualization/vistoolarc.h \ visualization/vistoolarc.h \
visualization/vispath.h \ visualization/vispath.h \
visualization/vistoolcutarc.h \ visualization/vistoolcutarc.h \
visualization/vistoolspline.h visualization/vistoolspline.h \
visualization/vistoolcutspline.h
SOURCES += \ SOURCES += \
visualization/vgraphicssimpletextitem.cpp \ visualization/vgraphicssimpletextitem.cpp \
@ -40,4 +41,5 @@ SOURCES += \
visualization/vistoolarc.cpp \ visualization/vistoolarc.cpp \
visualization/vispath.cpp \ visualization/vispath.cpp \
visualization/vistoolcutarc.cpp \ visualization/vistoolcutarc.cpp \
visualization/vistoolspline.cpp visualization/vistoolspline.cpp \
visualization/vistoolcutspline.cpp