Visualization for VToolSplinePath.

--HG--
branch : feature
This commit is contained in:
dismine 2014-09-07 19:51:22 +03:00
parent 2a4eef7695
commit e75ed95561
9 changed files with 325 additions and 45 deletions

View File

@ -30,6 +30,7 @@
#include "ui_dialogsplinepath.h" #include "ui_dialogsplinepath.h"
#include "../../geometry/vsplinepoint.h" #include "../../geometry/vsplinepoint.h"
#include "../../container/vcontainer.h" #include "../../container/vcontainer.h"
#include "../../visualization/vistoolsplinepath.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
@ -38,10 +39,10 @@
* @param parent parent widget * @param parent parent widget
*/ */
DialogSplinePath::DialogSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogSplinePath::DialogSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()) :DialogTool(data, toolId, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()), visPath(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);
InitOkCancel(ui); InitOkCancelApply(ui);
bOk->setEnabled(false); bOk->setEnabled(false);
FillComboBoxPoints(ui->comboBoxPoint); FillComboBoxPoints(ui->comboBoxPoint);
@ -57,11 +58,14 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, const quint32 &toolId
this, &DialogSplinePath::KAsm1Changed); this, &DialogSplinePath::KAsm1Changed);
connect(ui->doubleSpinBoxKasm2, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), connect(ui->doubleSpinBoxKasm2, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogSplinePath::KAsm2Changed); this, &DialogSplinePath::KAsm2Changed);
visPath = new VisToolSplinePath(data);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogSplinePath::~DialogSplinePath() DialogSplinePath::~DialogSplinePath()
{ {
delete visPath;
delete ui; delete ui;
} }
@ -73,6 +77,7 @@ DialogSplinePath::~DialogSplinePath()
void DialogSplinePath::SetPath(const VSplinePath &value) void DialogSplinePath::SetPath(const VSplinePath &value)
{ {
this->path = value; this->path = value;
ui->listWidget->blockSignals(true);
ui->listWidget->clear(); ui->listWidget->clear();
for (qint32 i = 0; i < path.CountPoint(); ++i) for (qint32 i = 0; i < path.CountPoint(); ++i)
{ {
@ -80,6 +85,9 @@ void DialogSplinePath::SetPath(const VSplinePath &value)
} }
ui->listWidget->setFocus(Qt::OtherFocusReason); ui->listWidget->setFocus(Qt::OtherFocusReason);
ui->doubleSpinBoxKcurve->setValue(path.getKCurve()); ui->doubleSpinBoxKcurve->setValue(path.getKCurve());
visPath->setPath(path);
ui->listWidget->blockSignals(false);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -94,20 +102,29 @@ void DialogSplinePath::ChosenObject(quint32 id, const SceneObject &type)
{ {
NewItem(id, 1, 0, 1, 180); NewItem(id, 1, 0, 1, 180);
emit ToolTip(tr("Select point of curve path")); emit ToolTip(tr("Select point of curve path"));
this->show();
SavePath();
visPath->setPath(path);
if (path.CountPoint() == 1)
{
visPath->VisualMode(NULL_ID);
connect(visPath, &VisToolSplinePath::ToolTip, this, &DialogTool::ShowVisToolTip);
connect(visPath, &VisToolSplinePath::PathChanged, this, &DialogSplinePath::PathUpdated);
}
else
{
visPath->RefreshGeometry();
}
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogSplinePath::SaveData() void DialogSplinePath::SaveData()
{ {
path.Clear(); SavePath();
for (qint32 i = 0; i < ui->listWidget->count(); ++i)
{ visPath->setPath(path);
QListWidgetItem *item = ui->listWidget->item(i); visPath->RefreshGeometry();
path.append( qvariant_cast<VSplinePoint>(item->data(Qt::UserRole)));
}
path.setKCurve(ui->doubleSpinBoxKcurve->value());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -214,6 +231,35 @@ void DialogSplinePath::UpdateList()
*/ */
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogSplinePath::ShowDialog(bool click)
{
if (click == false)
{
emit ToolTip("");
DialogAccepted();
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSplinePath::PathUpdated(const VSplinePath &path)
{
SetPath(path);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSplinePath::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
connect(scene, &VMainGraphicsScene::NewFactor, visPath, &Visualization::SetFactor);
scene->addItem(visPath);
visPath->setMode(Mode::Show);
visPath->RefreshGeometry();
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief NewItem add point to list * @brief NewItem add point to list
@ -228,7 +274,7 @@ void DialogSplinePath::NewItem(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(id); const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(id);
QListWidgetItem *item = new QListWidgetItem(point->name()); QListWidgetItem *item = new QListWidgetItem(point->name());
item->setFont(QFont("Times", 12, QFont::Bold)); item->setFont(QFont("Times", 12, QFont::Bold));
VSplinePoint p(*point, kAsm1, angle1, kAsm2, angle2); VSplinePoint p(*point.data(), kAsm1, angle1, kAsm2, angle2);
DataPoint(point->id(), kAsm1, angle1, kAsm2, angle2); DataPoint(point->id(), kAsm1, angle1, kAsm2, angle2);
item->setData(Qt::UserRole, QVariant::fromValue(p)); item->setData(Qt::UserRole, QVariant::fromValue(p));
ui->listWidget->addItem(item); ui->listWidget->addItem(item);
@ -295,3 +341,15 @@ void DialogSplinePath::EnableFields()
return; return;
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogSplinePath::SavePath()
{
path.Clear();
for (qint32 i = 0; i < ui->listWidget->count(); ++i)
{
QListWidgetItem *item = ui->listWidget->item(i);
path.append( qvariant_cast<VSplinePoint>(item->data(Qt::UserRole)));
}
path.setKCurve(ui->doubleSpinBoxKcurve->value());
}

View File

@ -37,6 +37,8 @@ namespace Ui
class DialogSplinePath; class DialogSplinePath;
} }
class VisToolSplinePath;
/** /**
* @brief The DialogSplinePath class dialog for ToolSplinePath. Help create spline path and edit option. * @brief The DialogSplinePath class dialog for ToolSplinePath. Help create spline path and edit option.
*/ */
@ -58,7 +60,10 @@ public slots:
void KAsm1Changed(qreal d); void KAsm1Changed(qreal d);
void KAsm2Changed(qreal d); void KAsm2Changed(qreal d);
virtual void UpdateList(); virtual void UpdateList();
virtual void ShowDialog(bool click);
void PathUpdated(const VSplinePath &path);
protected: protected:
virtual void ShowVisualization();
/** /**
* @brief SaveData Put dialog data in local variables * @brief SaveData Put dialog data in local variables
*/ */
@ -72,9 +77,12 @@ private:
/** @brief path spline path */ /** @brief path spline path */
VSplinePath path; VSplinePath path;
VisToolSplinePath *visPath;
void NewItem(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); void NewItem(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2);
void DataPoint(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); void DataPoint(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2);
void EnableFields(); void EnableFields();
void SavePath();
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -191,7 +191,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

@ -80,21 +80,21 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
case QtWarningMsg: case QtWarningMsg:
messageBox.setIcon(QMessageBox::Warning); messageBox.setIcon(QMessageBox::Warning);
messageBox.setInformativeText(msg); messageBox.setInformativeText(msg);
messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); messageBox.setStandardButtons(QMessageBox::Ok);
fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line,
context.function); context.function);
break; break;
case QtCriticalMsg: case QtCriticalMsg:
messageBox.setIcon(QMessageBox::Critical); messageBox.setIcon(QMessageBox::Critical);
messageBox.setInformativeText(msg); messageBox.setInformativeText(msg);
messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); messageBox.setStandardButtons(QMessageBox::Ok);
fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line,
context.function); context.function);
break; break;
case QtFatalMsg: case QtFatalMsg:
messageBox.setIcon(QMessageBox::Critical); messageBox.setIcon(QMessageBox::Critical);
messageBox.setInformativeText(msg); messageBox.setInformativeText(msg);
messageBox.setStandardButtons(QMessageBox::Cancel); messageBox.setStandardButtons(QMessageBox::Ok);
fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line,
context.function); context.function);
break; break;

View File

@ -522,8 +522,10 @@ void MainWindow::ToolArc(bool checked)
*/ */
void MainWindow::ToolSplinePath(bool checked) void MainWindow::ToolSplinePath(bool checked)
{ {
SetToolButton<DialogSplinePath>(checked, Tool::SplinePath, ":/cursor/splinepath_cursor.png", SetToolButtonWithApply<DialogSplinePath>(checked, Tool::SplinePath, ":/cursor/splinepath_cursor.png",
tr("Select point of curve path"), &MainWindow::ClosedDialog<VToolSplinePath>); tr("Select point of curve path"),
&MainWindow::ClosedDialogWithApply<VToolSplinePath>,
&MainWindow::ApplyDialog<VToolSplinePath>);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -29,6 +29,7 @@
#include "vtoolsplinepath.h" #include "vtoolsplinepath.h"
#include "../../dialogs/tools/dialogsplinepath.h" #include "../../dialogs/tools/dialogsplinepath.h"
#include "../../undocommands/movesplinepath.h" #include "../../undocommands/movesplinepath.h"
#include "../../visualization/vistoolsplinepath.h"
const QString VToolSplinePath::ToolType = QStringLiteral("path"); const QString VToolSplinePath::ToolType = QStringLiteral("path");
@ -73,6 +74,9 @@ VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, co
connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint);
controlPoints.append(controlPoint); controlPoints.append(controlPoint);
} }
ShowFoot(false);
if (typeCreation == Source::FromGui) if (typeCreation == Source::FromGui)
{ {
AddToFile(); AddToFile();
@ -283,33 +287,36 @@ void VToolSplinePath::setSplinePath(const VSplinePath &splPath)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSplinePath::ShowVisualization(bool show) void VToolSplinePath::ShowVisualization(bool show)
{ {
// if (show) if (show)
// { {
// if (vis == nullptr) if (vis == nullptr)
// { {
// VisTool * visual = new VisTool(getData()); VisToolSplinePath *visual = new VisToolSplinePath(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 QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
// visual->RefreshGeometry(); visual->setPath(*splPath.data());
// vis = visual; visual->setMode(Mode::Show);
// } visual->RefreshGeometry();
// else vis = visual;
// { }
// VisTool * visual = qobject_cast<VisTool *>(vis); else
// if (visual != nullptr) {
// { VisToolSplinePath *visual = qobject_cast<VisToolSplinePath *>(vis);
// visual->show(); if (visual != nullptr)
// } {
// } visual->show();
// } }
// else }
// { }
// delete vis; else
// vis = nullptr; {
// } delete vis;
vis = nullptr;
}
ShowFoot(show);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -441,4 +448,13 @@ void VToolSplinePath::RefreshGeometry()
controlPoints[j-2]->blockSignals(false); controlPoints[j-2]->blockSignals(false);
controlPoints[j-1]->blockSignals(false); controlPoints[j-1]->blockSignals(false);
} }
if (vis != nullptr)
{
VisToolSplinePath *visual = qobject_cast<VisToolSplinePath *>(vis);
QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
visual->setPath(*splPath.data());
visual->setMode(Mode::Show);
visual->RefreshGeometry();
}
} }

View File

@ -0,0 +1,127 @@
/************************************************************************
**
** @file vistoolsplinepath.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 "vistoolsplinepath.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolSplinePath::VisToolSplinePath(const VContainer *data, QGraphicsItem *parent)
: VisPath(data, parent), points(QVector<QGraphicsEllipseItem *>()), line(nullptr), path(VSplinePath()),
mode(Mode::Creation)
{
line = InitItem<QGraphicsLineItem>(mainColor, this);
}
//---------------------------------------------------------------------------------------------------------------------
VisToolSplinePath::~VisToolSplinePath()
{
qDeleteAll(points.begin(), points.end());
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolSplinePath::RefreshGeometry()
{
if (path.CountPoint() > 0)
{
QVector<VSplinePoint> pathPoints = path.GetSplinePath();
if (path.CountPoint() == 1)
{
QGraphicsEllipseItem *point = this->getPoint(0);
DrawPoint(point, pathPoints.at(0).P().toQPointF(), supportColor);
if (mode == Mode::Creation)
{
QLineF sceneLine = QLineF(pathPoints.at(0).P().toQPointF(), Visualization::scenePos);
DrawLine(line, sceneLine, mainColor, lineStyle);
path[0].SetAngle2(sceneLine.angle());
emit PathChanged(path);
}
}
else
{
for (int i = 0; i < pathPoints.size(); ++i)
{
QGraphicsEllipseItem *point = this->getPoint(i);
DrawPoint(point, pathPoints.at(i).P().toQPointF(), supportColor);
}
if (mode == Mode::Creation)
{
QLineF sceneLine = QLineF(pathPoints.at(pathPoints.size() - 1).P().toQPointF(),
Visualization::scenePos);
DrawLine(line, sceneLine, mainColor, lineStyle);
path[pathPoints.size() - 1].SetAngle2(sceneLine.angle());
emit PathChanged(path);
}
DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap);
}
Visualization::toolTip = QString(tr("<b>Curve path</b>: <b>Enter</b> - finish creation"));
}
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolSplinePath::setPath(const VSplinePath &value)
{
path = value;
}
//---------------------------------------------------------------------------------------------------------------------
VSplinePath VisToolSplinePath::getPath()
{
return path;
}
//---------------------------------------------------------------------------------------------------------------------
Mode VisToolSplinePath::getMode() const
{
return mode;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolSplinePath::setMode(const Mode &value)
{
mode = value;
}
//---------------------------------------------------------------------------------------------------------------------
QGraphicsEllipseItem *VisToolSplinePath::getPoint(unsigned int i)
{
if (points.size() - 1 >= i && points.isEmpty() == false)
{
return points.at(i);
}
else
{
QGraphicsEllipseItem * point = InitPoint(supportColor, this);
points.append(point);
return point;
}
return nullptr;
}

View File

@ -0,0 +1,67 @@
/************************************************************************
**
** @file vistoolsplinepath.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 VISTOOLSPLINEPATH_H
#define VISTOOLSPLINEPATH_H
#include "vispath.h"
#include "../geometry/vsplinepath.h"
enum class Mode : char {Creation, Show};
class VisToolSplinePath : public VisPath
{
Q_OBJECT
public:
VisToolSplinePath(const VContainer *data, QGraphicsItem *parent = 0);
virtual ~VisToolSplinePath();
virtual void RefreshGeometry();
void setPath(const VSplinePath &value);
VSplinePath getPath();
virtual int type() const {return Type;}
enum { Type = UserType + static_cast<int>(Vis::ToolSplinePath)};
Mode getMode() const;
void setMode(const Mode &value);
signals:
void PathChanged(const VSplinePath &path);
protected:
Q_DISABLE_COPY(VisToolSplinePath)
QVector<QGraphicsEllipseItem *> points;
QGraphicsLineItem *line;
VSplinePath path;
Mode mode;
QGraphicsEllipseItem * getPoint(unsigned int i);
};
#endif // VISTOOLSPLINEPATH_H

View File

@ -19,7 +19,8 @@ HEADERS += \
visualization/vispath.h \ visualization/vispath.h \
visualization/vistoolcutarc.h \ visualization/vistoolcutarc.h \
visualization/vistoolspline.h \ visualization/vistoolspline.h \
visualization/vistoolcutspline.h visualization/vistoolcutspline.h \
visualization/vistoolsplinepath.h
SOURCES += \ SOURCES += \
visualization/vgraphicssimpletextitem.cpp \ visualization/vgraphicssimpletextitem.cpp \
@ -42,4 +43,5 @@ SOURCES += \
visualization/vispath.cpp \ visualization/vispath.cpp \
visualization/vistoolcutarc.cpp \ visualization/vistoolcutarc.cpp \
visualization/vistoolspline.cpp \ visualization/vistoolspline.cpp \
visualization/vistoolcutspline.cpp visualization/vistoolcutspline.cpp \
visualization/vistoolsplinepath.cpp