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

View file

@ -45,8 +45,8 @@ public:
void DisableShowMode(bool disable); void DisableShowMode(bool disable);
// VPiecePath GetPiecePath() const; VPiecePath GetPiecePath() const;
// void SetPiecePath(const VPiecePath &path); void SetPiecePath(const VPiecePath &path);
public slots: public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE;
@ -67,7 +67,7 @@ private:
Ui::DialogPiecePath *ui; Ui::DialogPiecePath *ui;
bool m_showMode; bool m_showMode;
// VPiecePath CreatePath() const; VPiecePath CreatePath() const;
bool PathIsValid() const; bool PathIsValid() const;
void ValidObjects(bool value); 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/visoperation.h \
$$PWD/line/operation/vistoolflippingbyaxis.h \ $$PWD/line/operation/vistoolflippingbyaxis.h \
$$PWD/line/operation/vistoolmove.h \ $$PWD/line/operation/vistoolmove.h \
$$PWD/path/vistoolpiece.h $$PWD/path/vistoolpiece.h \
$$PWD/path/vistoolpiecepath.h
SOURCES += \ SOURCES += \
$$PWD/visualization.cpp \ $$PWD/visualization.cpp \
@ -77,4 +78,5 @@ SOURCES += \
$$PWD/line/operation/visoperation.cpp \ $$PWD/line/operation/visoperation.cpp \
$$PWD/line/operation/vistoolflippingbyaxis.cpp \ $$PWD/line/operation/vistoolflippingbyaxis.cpp \
$$PWD/line/operation/vistoolmove.cpp \ $$PWD/line/operation/vistoolmove.cpp \
$$PWD/path/vistoolpiece.cpp $$PWD/path/vistoolpiece.cpp \
$$PWD/path/vistoolpiecepath.cpp