Visualization for VToolCutSplinePath. Fixed issue #16.
--HG-- branch : feature
This commit is contained in:
parent
e75ed95561
commit
ede640618f
|
@ -32,6 +32,7 @@
|
|||
#include "../../geometry/vsplinepath.h"
|
||||
#include "../../container/vcontainer.h"
|
||||
#include "../../xml/vpattern.h"
|
||||
#include "../../visualization/vistoolcutsplinepath.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
|
@ -41,7 +42,7 @@
|
|||
*/
|
||||
DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent)
|
||||
:DialogTool(data, toolId, parent), ui(new Ui::DialogCutSplinePath), formula(QString()),
|
||||
splinePathId(NULL_ID), formulaBaseHeight(0)
|
||||
splinePathId(NULL_ID), formulaBaseHeight(0), path(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
InitVariables(ui);
|
||||
|
@ -50,7 +51,7 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 &
|
|||
labelEditNamePoint = ui->labelEditNamePoint;
|
||||
this->formulaBaseHeight = ui->plainTextEditFormula->height();
|
||||
|
||||
InitOkCancel(ui);
|
||||
InitOkCancelApply(ui);
|
||||
flagFormula = false;
|
||||
CheckState();
|
||||
|
||||
|
@ -62,11 +63,14 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 &
|
|||
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSplinePath::NamePointChanged);
|
||||
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutSplinePath::FormulaChanged);
|
||||
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSplinePath::DeployFormulaTextEdit);
|
||||
|
||||
path = new VisToolCutSplinePath(data);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DialogCutSplinePath::~DialogCutSplinePath()
|
||||
{
|
||||
delete path;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
@ -96,6 +100,7 @@ void DialogCutSplinePath::setFormula(const QString &value)
|
|||
this->DeployFormulaTextEdit();
|
||||
}
|
||||
ui->plainTextEditFormula->setPlainText(formula);
|
||||
path->setLength(formula);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -106,6 +111,7 @@ void DialogCutSplinePath::setFormula(const QString &value)
|
|||
void DialogCutSplinePath::setSplinePathId(const quint32 &value)
|
||||
{
|
||||
setCurrentSplinePathId(ui->comboBoxSplinePath, splinePathId, value, ComboBoxCutSpline::CutSpline);
|
||||
path->setPoint1Id(splinePathId);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -122,6 +128,8 @@ void DialogCutSplinePath::ChosenObject(quint32 id, const SceneObject &type)
|
|||
{
|
||||
if (SetObject(id, ui->comboBoxSplinePath, ""))
|
||||
{
|
||||
path->VisualMode(id);
|
||||
prepare = true;
|
||||
this->setModal(true);
|
||||
this->show();
|
||||
}
|
||||
|
@ -136,6 +144,10 @@ void DialogCutSplinePath::SaveData()
|
|||
formula = ui->plainTextEditFormula->toPlainText();
|
||||
formula.replace("\n", " ");
|
||||
splinePathId = getCurrentObjectId(ui->comboBoxSplinePath);
|
||||
|
||||
path->setPoint1Id(splinePathId);
|
||||
path->setLength(formula);
|
||||
path->RefreshGeometry();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -143,3 +155,15 @@ void DialogCutSplinePath::DeployFormulaTextEdit()
|
|||
{
|
||||
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogCutSplinePath::ShowVisualization()
|
||||
{
|
||||
if (prepare == false)
|
||||
{
|
||||
VMainGraphicsScene *scene = qApp->getCurrentScene();
|
||||
connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor);
|
||||
scene->addItem(path);
|
||||
path->RefreshGeometry();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ namespace Ui
|
|||
class DialogCutSplinePath;
|
||||
}
|
||||
|
||||
class VisToolCutSplinePath;
|
||||
|
||||
/**
|
||||
* @brief The DialogCutSplinePath class dialog for ToolCutSplinePath.
|
||||
*/
|
||||
|
@ -61,6 +63,7 @@ public slots:
|
|||
*/
|
||||
void DeployFormulaTextEdit();
|
||||
protected:
|
||||
virtual void ShowVisualization();
|
||||
/**
|
||||
* @brief SaveData Put dialog data in local variables
|
||||
*/
|
||||
|
@ -79,6 +82,8 @@ private:
|
|||
|
||||
/** @brief formulaBaseHeight base height defined by dialogui */
|
||||
int formulaBaseHeight;
|
||||
|
||||
VisToolCutSplinePath *path;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -392,7 +392,7 @@
|
|||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -535,9 +535,10 @@ void MainWindow::ToolSplinePath(bool checked)
|
|||
*/
|
||||
void MainWindow::ToolCutSplinePath(bool checked)
|
||||
{
|
||||
SetToolButton<DialogCutSplinePath>(checked, Tool::CutSplinePath,
|
||||
SetToolButtonWithApply<DialogCutSplinePath>(checked, Tool::CutSplinePath,
|
||||
":/cursor/splinepath_cut_point_cursor.png", tr("Select curve path"),
|
||||
&MainWindow::ClosedDialog<VToolCutSplinePath>);
|
||||
&MainWindow::ClosedDialogWithApply<VToolCutSplinePath>,
|
||||
&MainWindow::ApplyDialog<VToolCutSplinePath>);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include "../../container/calculator.h"
|
||||
#include "../../dialogs/tools/dialogcutsplinepath.h"
|
||||
#include "../../geometry/vpointf.h"
|
||||
#include "../../visualization/vistoolcutsplinepath.h"
|
||||
#include "vabstractspline.h"
|
||||
|
||||
#include "../../geometry/vsplinepath.h"
|
||||
|
||||
|
@ -169,16 +171,16 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString
|
|||
splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(),
|
||||
spl1.GetAngle1()));
|
||||
VSplinePoint cutPoint;
|
||||
if (typeCreation == Source::FromGui)
|
||||
{
|
||||
cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), spl1.GetAngle2()+180,
|
||||
spl1.GetAngle2());
|
||||
}
|
||||
else
|
||||
{
|
||||
// if (typeCreation == Source::FromGui)
|
||||
// {
|
||||
// cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), spl2.GetKasm1(),
|
||||
// spl1.GetAngle2());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), spl2.GetKasm1(),
|
||||
spl1.GetAngle2()+180);
|
||||
}
|
||||
// }
|
||||
splPath1->append(cutPoint);
|
||||
continue;
|
||||
}
|
||||
|
@ -245,33 +247,38 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolCutSplinePath::ShowVisualization(bool show)
|
||||
{
|
||||
// if (show)
|
||||
// {
|
||||
// if (vis == nullptr)
|
||||
// {
|
||||
// VisTool * visual = new VisTool(getData());
|
||||
// VMainGraphicsScene *scene = qApp->getCurrentScene();
|
||||
// connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
|
||||
// scene->addItem(visual);
|
||||
if (show)
|
||||
{
|
||||
if (vis == nullptr)
|
||||
{
|
||||
VisToolCutSplinePath *visual = new VisToolCutSplinePath(getData());
|
||||
VMainGraphicsScene *scene = qApp->getCurrentScene();
|
||||
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
|
||||
scene->addItem(visual);
|
||||
|
||||
// // add options
|
||||
// visual->RefreshGeometry();
|
||||
// vis = visual;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// VisTool * visual = qobject_cast<VisTool *>(vis);
|
||||
// if (visual != nullptr)
|
||||
// {
|
||||
// visual->show();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// delete vis;
|
||||
// vis = nullptr;
|
||||
// }
|
||||
visual->setPoint1Id(curveCutId);
|
||||
visual->setLength(formula);
|
||||
visual->RefreshGeometry();
|
||||
vis = visual;
|
||||
}
|
||||
else
|
||||
{
|
||||
VisToolCutSplinePath *visual = qobject_cast<VisToolCutSplinePath *>(vis);
|
||||
if (visual != nullptr)
|
||||
{
|
||||
visual->show();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete vis;
|
||||
vis = nullptr;
|
||||
}
|
||||
if (VAbstractSpline *parentCurve = qobject_cast<VAbstractSpline *>(doc->getTool(curveCutId)))
|
||||
{
|
||||
parentCurve->ShowFoot(show);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -281,6 +288,14 @@ void VToolCutSplinePath::ShowVisualization(bool show)
|
|||
void VToolCutSplinePath::FullUpdateFromFile()
|
||||
{
|
||||
FullUpdateCurveFromFile(AttrSplinePath);
|
||||
|
||||
if (vis != nullptr)
|
||||
{
|
||||
VisToolCutSplinePath *visual = qobject_cast<VisToolCutSplinePath *>(vis);
|
||||
visual->setPoint1Id(curveCutId);
|
||||
visual->setLength(formula);
|
||||
visual->RefreshGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
118
src/app/visualization/vistoolcutsplinepath.cpp
Normal file
118
src/app/visualization/vistoolcutsplinepath.cpp
Normal file
|
@ -0,0 +1,118 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vistoolcutsplinepath.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 7 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 "vistoolcutsplinepath.h"
|
||||
#include "../container/vcontainer.h"
|
||||
#include "../geometry/vsplinepath.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisToolCutSplinePath::VisToolCutSplinePath(const VContainer *data, QGraphicsItem *parent)
|
||||
:VisPath(data, parent), point(nullptr), splPath1(nullptr), splPath2(nullptr), length(0)
|
||||
{
|
||||
splPath1 = InitItem<QGraphicsPathItem>(Qt::darkGreen, this);
|
||||
splPath1->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
|
||||
splPath2 = InitItem<QGraphicsPathItem>(Qt::darkRed, this);
|
||||
splPath2->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
|
||||
|
||||
point = InitPoint(mainColor, this);
|
||||
point->setZValue(2);
|
||||
point->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisToolCutSplinePath::~VisToolCutSplinePath()
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolCutSplinePath::RefreshGeometry()
|
||||
{
|
||||
if (point1Id > 0)
|
||||
{
|
||||
const QSharedPointer<VSplinePath> splPath = Visualization::data->GeometricObject<VSplinePath>(point1Id);
|
||||
DrawPath(this, splPath->GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap);
|
||||
|
||||
if (qFuzzyCompare(1 + length, 1 + 0) == false)
|
||||
{
|
||||
QPointF spl1p2, spl1p3, spl2p2, spl2p3;
|
||||
qint32 p1 = 0, p2 = 0;
|
||||
|
||||
const QPointF cutPoint = splPath->CutSplinePath(length, p1, p2, spl1p2, spl1p3, spl2p2, spl2p3);
|
||||
VPointF p = VPointF(cutPoint);
|
||||
|
||||
VSplinePoint splP1 = splPath->at(p1);
|
||||
VSplinePoint splP2 = splPath->at(p2);
|
||||
const VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, p, splPath->getKCurve());
|
||||
const VSpline spl2 = VSpline(p, spl2p2, spl2p3, splP2.P(), splPath->getKCurve());
|
||||
|
||||
VSplinePath spPath1 = VSplinePath();
|
||||
VSplinePath spPath2 = VSplinePath();
|
||||
|
||||
for (qint32 i = 0; i < splPath->CountPoint(); i++)
|
||||
{
|
||||
if (i <= p1 && i < p2)
|
||||
{
|
||||
if (i == p1)
|
||||
{
|
||||
spPath1.append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(),
|
||||
spl1.GetAngle1()));
|
||||
VSplinePoint cutPoint;
|
||||
cutPoint = VSplinePoint(p, spl1.GetKasm2(), spl1.GetAngle2(), spl2.GetKasm1(),
|
||||
spl1.GetAngle2()+180);
|
||||
spPath1.append(cutPoint);
|
||||
continue;
|
||||
}
|
||||
spPath1.append(splPath->at(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i == p2)
|
||||
{
|
||||
const VSplinePoint cutPoint = VSplinePoint(p, spl1.GetKasm2(), spl2.GetAngle1()+180,
|
||||
spl2.GetKasm1(), spl2.GetAngle1());
|
||||
spPath2.append(cutPoint);
|
||||
spPath2.append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2(), splP2.KAsm2(),
|
||||
spl2.GetAngle2()+180));
|
||||
continue;
|
||||
}
|
||||
spPath2.append(splPath->at(i));
|
||||
}
|
||||
}
|
||||
|
||||
DrawPoint(point, cutPoint, mainColor);
|
||||
|
||||
DrawPath(splPath1, spPath1.GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap);
|
||||
DrawPath(splPath2, spPath2.GetPath(PathDirection::Show), Qt::darkRed, Qt::SolidLine, Qt::RoundCap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolCutSplinePath::setLength(const QString &expression)
|
||||
{
|
||||
length = FindLength(expression);
|
||||
}
|
53
src/app/visualization/vistoolcutsplinepath.h
Normal file
53
src/app/visualization/vistoolcutsplinepath.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vistoolcutsplinepath.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 7 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 VISTOOLCUTSPLINEPATH_H
|
||||
#define VISTOOLCUTSPLINEPATH_H
|
||||
|
||||
#include "vispath.h"
|
||||
|
||||
class VisToolCutSplinePath : public VisPath
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VisToolCutSplinePath(const VContainer *data, QGraphicsItem *parent = 0);
|
||||
virtual ~VisToolCutSplinePath();
|
||||
|
||||
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(VisToolCutSplinePath)
|
||||
QGraphicsEllipseItem *point;
|
||||
QGraphicsPathItem *splPath1;
|
||||
QGraphicsPathItem *splPath2;
|
||||
qreal length;
|
||||
};
|
||||
|
||||
#endif // VISTOOLCUTSPLINEPATH_H
|
|
@ -20,7 +20,8 @@ HEADERS += \
|
|||
visualization/vistoolcutarc.h \
|
||||
visualization/vistoolspline.h \
|
||||
visualization/vistoolcutspline.h \
|
||||
visualization/vistoolsplinepath.h
|
||||
visualization/vistoolsplinepath.h \
|
||||
visualization/vistoolcutsplinepath.h
|
||||
|
||||
SOURCES += \
|
||||
visualization/vgraphicssimpletextitem.cpp \
|
||||
|
@ -44,4 +45,5 @@ SOURCES += \
|
|||
visualization/vistoolcutarc.cpp \
|
||||
visualization/vistoolspline.cpp \
|
||||
visualization/vistoolcutspline.cpp \
|
||||
visualization/vistoolsplinepath.cpp
|
||||
visualization/vistoolsplinepath.cpp \
|
||||
visualization/vistoolcutsplinepath.cpp
|
||||
|
|
|
@ -2452,7 +2452,10 @@ void VPattern::PrepareForParse(const Document &parse)
|
|||
else if (parse == Document::LiteParse)
|
||||
{
|
||||
data->ClearUniqueNames();
|
||||
data->ClearVariables();
|
||||
data->ClearVariables(VarType::ArcLength);
|
||||
data->ClearVariables(VarType::LineAngle);
|
||||
data->ClearVariables(VarType::LineLength);
|
||||
data->ClearVariables(VarType::SplineLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user