Added visualization creating a path.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-11-23 13:57:12 +02:00
parent 5d5e677e2c
commit bb39410296
5 changed files with 242 additions and 63 deletions

View file

@ -29,6 +29,7 @@
#include "dialogpiecepath.h"
#include "ui_dialogpiecepath.h"
#include "../vpatterndb/vpiecenode.h"
#include "visualization/path/vistoolpiecepath.h"
#include <QMenu>
@ -36,7 +37,7 @@
DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogPiecePath),
m_showMode(true)
m_showMode(false)
{
ui->setupUi(this);
InitOkCancel(ui);
@ -49,15 +50,13 @@ DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget
if (not m_showMode)
{
//vis = new VisToolPiecePath(data);
vis = new VisToolPiecePath(data);
}
else
{
ui->comboBoxType->setDisabled(true);
ui->comboBoxPiece->setDisabled(true);
}
show();//temporary
}
//---------------------------------------------------------------------------------------------------------------------
@ -108,22 +107,22 @@ void DialogPiecePath::ChosenObject(quint32 id, const SceneObject &type)
if (not m_showMode)
{
// auto visPath = qobject_cast<VisToolPiecePath *>(vis);
// SCASSERT(visPath != nullptr);
// const VPiecePath p = CreatePath();
// visPath->SetPath(p);
auto visPath = qobject_cast<VisToolPiecePath *>(vis);
SCASSERT(visPath != nullptr);
const VPiecePath p = CreatePath();
visPath->SetPath(p);
// if (p.CountNodes() == 1)
// {
// emit ToolTip(tr("Select main path objects, <b>Shift</b> - reverse direction curve, "
// "<b>Enter</b> - finish creation"));
if (p.CountNodes() == 1)
{
emit ToolTip(tr("Select main path objects, <b>Shift</b> - reverse direction curve, "
"<b>Enter</b> - finish creation"));
// visPath->VisualMode(NULL_ID);
// }
// else
// {
// visPath->RefreshGeometry();
// }
visPath->VisualMode(NULL_ID);
}
else
{
visPath->RefreshGeometry();
}
}
}
}
@ -138,10 +137,10 @@ void DialogPiecePath::ShowDialog(bool click)
if (not m_showMode)
{
// auto visPath = qobject_cast<VisToolPiecePath *>(vis);
// SCASSERT(visPath != nullptr);
// visPath->SetMode(Mode::Show);
// visPath->RefreshGeometry();
auto visPath = qobject_cast<VisToolPiecePath *>(vis);
SCASSERT(visPath != nullptr);
visPath->SetMode(Mode::Show);
visPath->RefreshGeometry();
}
setModal(true);
show();
@ -206,10 +205,10 @@ void DialogPiecePath::ListChanged()
{
if (not m_showMode)
{
// auto visPath = qobject_cast<VisToolPiecePath *>(vis);
// SCASSERT(visPath != nullptr);
// visPath->SetPiece(CreatePath());
// visPath->RefreshGeometry();
auto visPath = qobject_cast<VisToolPiecePath *>(vis);
SCASSERT(visPath != nullptr);
visPath->SetPath(CreatePath());
visPath->RefreshGeometry();
}
}
@ -230,49 +229,64 @@ void DialogPiecePath::NameChanged()
}
//---------------------------------------------------------------------------------------------------------------------
//VPiecePath DialogPiecePath::GetPiecePath() const
//{
//}
VPiecePath DialogPiecePath::GetPiecePath() const
{
return CreatePath();
}
//---------------------------------------------------------------------------------------------------------------------
//void DialogPiecePath::SetPiecePath(const VPiecePath &path)
//{
void DialogPiecePath::SetPiecePath(const VPiecePath &path)
{
ui->listWidget->clear();
for (int i = 0; i < path.CountNodes(); ++i)
{
NewItem(path.at(i));
}
//}
ValidObjects(PathIsValid());
ListChanged();
}
//---------------------------------------------------------------------------------------------------------------------
//VPiecePath DialogPiecePath::CreatePath() const
//{
VPiecePath DialogPiecePath::CreatePath() const
{
VPiecePath path;
for (qint32 i = 0; i < ui->listWidget->count(); ++i)
{
QListWidgetItem *item = ui->listWidget->item(i);
path.Append(qvariant_cast<VPieceNode>(item->data(Qt::UserRole)));
}
//}
return path;
}
//---------------------------------------------------------------------------------------------------------------------
bool DialogPiecePath::PathIsValid() const
{
// QString url = DialogWarningIcon();
QString url = DialogWarningIcon();
// if(CreatePath().Points(data).count() < 2)
// {
// url += tr("You need more points!");
// ui->helpLabel->setText(url);
// return false;
// }
// else
// {
// if (FirstPointEqualLast(ui->listWidget))
// {
// url += tr("First point cannot be equal to the last point!");
// ui->helpLabel->setText(url);
// return false;
// }
// else if (DoublePoints(ui->listWidget))
// {
// url += tr("You have double points!");
// ui->helpLabel->setText(url);
// return false;
// }
// }
if(CreatePath().PathPoints(data).count() < 2)
{
url += tr("You need more points!");
ui->helpLabel->setText(url);
return false;
}
else
{
if (FirstPointEqualLast(ui->listWidget))
{
url += tr("First point cannot be equal to the last point!");
ui->helpLabel->setText(url);
return false;
}
else if (DoublePoints(ui->listWidget))
{
url += tr("You have double points!");
ui->helpLabel->setText(url);
return false;
}
}
ui->helpLabel->setText(tr("Ready!"));
return true;
}

View file

@ -45,8 +45,8 @@ public:
void DisableShowMode(bool disable);
// VPiecePath GetPiecePath() const;
// void SetPiecePath(const VPiecePath &path);
VPiecePath GetPiecePath() const;
void SetPiecePath(const VPiecePath &path);
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE;
@ -67,7 +67,7 @@ private:
Ui::DialogPiecePath *ui;
bool m_showMode;
// VPiecePath CreatePath() const;
VPiecePath CreatePath() const;
bool PathIsValid() const;
void ValidObjects(bool value);

View file

@ -0,0 +1,100 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 22 11, 2016
**
** @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) 2016 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 "vistoolpiecepath.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolPiecePath::VisToolPiecePath(const VContainer *data, QGraphicsItem *parent)
: VisPath(data, parent),
m_points(),
m_line(nullptr),
m_path()
{
m_line = InitItem<QGraphicsLineItem>(supportColor, this);
}
//---------------------------------------------------------------------------------------------------------------------
VisToolPiecePath::~VisToolPiecePath()
{}
//---------------------------------------------------------------------------------------------------------------------
void VisToolPiecePath::RefreshGeometry()
{
HideAllItems();
if (m_path.CountNodes() > 0)
{
DrawPath(this, m_path.PainterPath(Visualization::data), mainColor, Qt::SolidLine, Qt::RoundCap);
const QVector<QPointF> nodes = m_path.PathNodePoints(Visualization::data);
for (int i = 0; i < nodes.size(); ++i)
{
QGraphicsEllipseItem *point = GetPoint(static_cast<quint32>(i), supportColor);
DrawPoint(point, nodes.at(i), supportColor);
}
if (mode == Mode::Creation)
{
const QVector<QPointF> points = m_path.PathPoints(Visualization::data);
if (points.size() > 0)
{
DrawLine(m_line, QLineF(points.last(), Visualization::scenePos), supportColor, Qt::DashLine);
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolPiecePath::SetPath(const VPiecePath &path)
{
m_path = path;
}
//---------------------------------------------------------------------------------------------------------------------
QGraphicsEllipseItem *VisToolPiecePath::GetPoint(quint32 i, const QColor &color)
{
return GetPointItem(Visualization::data, factor, m_points, i, color, this);
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolPiecePath::HideAllItems()
{
if (m_line)
{
m_line->setVisible(false);
}
for (int i=0; i < m_points.size(); ++i)
{
if (QGraphicsEllipseItem *item = m_points.at(i))
{
item->setVisible(false);
}
}
}

View file

@ -0,0 +1,63 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 22 11, 2016
**
** @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) 2016 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 VISTOOLPIECEPATH_H
#define VISTOOLPIECEPATH_H
#include <QtCore/QObject>
#include <QtGlobal>
#include "vispath.h"
#include "../vpatterndb/vpiecepath.h"
class VisToolPiecePath : public VisPath
{
Q_OBJECT
public:
VisToolPiecePath(const VContainer *data, QGraphicsItem *parent = nullptr);
virtual ~VisToolPiecePath();
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
void SetPath(const VPiecePath &piece);
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Vis::ToolPiecePath)};
private:
Q_DISABLE_COPY(VisToolPiecePath)
QVector<QGraphicsEllipseItem *> m_points;
QGraphicsLineItem *m_line;
VPiecePath m_path;
QGraphicsEllipseItem* GetPoint(quint32 i, const QColor &color);
void HideAllItems();
};
#endif // VISTOOLPIECEPATH_H

View file

@ -38,7 +38,8 @@ HEADERS += \
$$PWD/line/operation/visoperation.h \
$$PWD/line/operation/vistoolflippingbyaxis.h \
$$PWD/line/operation/vistoolmove.h \
$$PWD/path/vistoolpiece.h
$$PWD/path/vistoolpiece.h \
$$PWD/path/vistoolpiecepath.h
SOURCES += \
$$PWD/visualization.cpp \
@ -77,4 +78,5 @@ SOURCES += \
$$PWD/line/operation/visoperation.cpp \
$$PWD/line/operation/vistoolflippingbyaxis.cpp \
$$PWD/line/operation/vistoolmove.cpp \
$$PWD/path/vistoolpiece.cpp
$$PWD/path/vistoolpiece.cpp \
$$PWD/path/vistoolpiecepath.cpp