Succesful build.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-03-18 23:11:14 +02:00
parent ca020c4c7f
commit 19265e1f93
27 changed files with 1289 additions and 27 deletions

View File

@ -73,6 +73,9 @@ void VToolOptionsPropertyBrowser::ClearPropertyBrowser()
//---------------------------------------------------------------------------------------------------------------------
void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item)
{
// This check helps to find missed tools in the switch
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in switch.");
switch (item->type())
{
case VToolBasePoint::Type:
@ -141,6 +144,9 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item)
case VToolSplinePath::Type:
ShowOptionsToolSplinePath(item);
break;
case VToolCubicBezierPath::Type:
ShowOptionsToolCubicBezierPath(item);
break;
case VToolTriangle::Type:
ShowOptionsToolTriangle(item);
break;
@ -184,6 +190,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions()
return;
}
// This check helps to find missed tools in the switch
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in switch.");
switch (currentItem->type())
{
case VToolBasePoint::Type:
@ -252,6 +261,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions()
case VToolSplinePath::Type:
UpdateOptionsToolSplinePath();
break;
case VToolCubicBezierPath::Type:
UpdateOptionsToolCubicBezierPath();
break;
case VToolTriangle::Type:
UpdateOptionsToolTriangle();
break;
@ -310,6 +322,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property)
return;
}
// This check helps to find missed tools in the switch
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in switch.");
switch (currentItem->type())
{
case VToolBasePoint::Type:
@ -378,6 +393,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property)
case VToolSplinePath::Type:
ChangeDataToolSplinePath(prop);
break;
case VToolCubicBezierPath::Type:
ChangeDataToolCubicBezierPath(prop);
break;
case VToolTriangle::Type:
ChangeDataToolTriangle(prop);
break;
@ -1404,6 +1422,30 @@ void VToolOptionsPropertyBrowser::ChangeDataToolSplinePath(VProperty *property)
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolOptionsPropertyBrowser::ChangeDataToolCubicBezierPath(VProperty *property)
{
SCASSERT(property != nullptr)
QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole);
const QString id = propertyToId[property];
VToolCubicBezierPath *i = qgraphicsitem_cast<VToolCubicBezierPath *>(currentItem);
SCASSERT(i != nullptr);
switch (PropertiesList().indexOf(id))
{
case 0: // AttrName
Q_UNREACHABLE();//The attribute is read only
break;
case 27: // AttrTypeColor
i->SetLineColor(value.toString());
break;
default:
qWarning()<<"Unknown property type. id = "<<id;
break;
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolOptionsPropertyBrowser::ChangeDataToolTriangle(VProperty *property)
{
@ -1818,6 +1860,17 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolSplinePath(QGraphicsItem *item)
AddPropertyLineColor(i, tr("Color"), VAbstractTool::ColorsList(), AttrColor);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolOptionsPropertyBrowser::ShowOptionsToolCubicBezierPath(QGraphicsItem *item)
{
VToolCubicBezierPath *i = qgraphicsitem_cast<VToolCubicBezierPath *>(item);
i->ShowVisualization(true);
formView->setTitle(tr("Tool cubic bezier curve"));
AddPropertyObjectName(i, tr("Name"), true);
AddPropertyLineColor(i, tr("Color"), VAbstractTool::ColorsList(), AttrColor);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolOptionsPropertyBrowser::ShowOptionsToolTriangle(QGraphicsItem *item)
{
@ -2253,6 +2306,15 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSplinePath()
idToProperty[AttrColor]->setValue(VLineColorProperty::IndexOfColor(VAbstractTool::ColorsList(), i->GetLineColor()));
}
//---------------------------------------------------------------------------------------------------------------------
void VToolOptionsPropertyBrowser::UpdateOptionsToolCubicBezierPath()
{
auto i = qgraphicsitem_cast<VToolCubicBezierPath *>(currentItem);
idToProperty[AttrName]->setValue(i->name());
idToProperty[AttrColor]->setValue(VLineColorProperty::IndexOfColor(VAbstractTool::ColorsList(), i->GetLineColor()));
}
//---------------------------------------------------------------------------------------------------------------------
void VToolOptionsPropertyBrowser::UpdateOptionsToolTriangle()
{

View File

@ -140,6 +140,7 @@ private:
void ChangeDataToolSpline(VPE::VProperty *property);
void ChangeDataToolCubicBezier(VPE::VProperty *property);
void ChangeDataToolSplinePath(VPE::VProperty *property);
void ChangeDataToolCubicBezierPath(VPE::VProperty *property);
void ChangeDataToolTriangle(VPE::VProperty *property);
void ChangeDataToolLineIntersectAxis(VPE::VProperty *property);
void ChangeDataToolCurveIntersectAxis(VPE::VProperty *property);
@ -169,6 +170,7 @@ private:
void ShowOptionsToolSpline(QGraphicsItem *item);
void ShowOptionsToolCubicBezier(QGraphicsItem *item);
void ShowOptionsToolSplinePath(QGraphicsItem *item);
void ShowOptionsToolCubicBezierPath(QGraphicsItem *item);
void ShowOptionsToolTriangle(QGraphicsItem *item);
void ShowOptionsToolLineIntersectAxis(QGraphicsItem *item);
void ShowOptionsToolCurveIntersectAxis(QGraphicsItem *item);
@ -198,6 +200,7 @@ private:
void UpdateOptionsToolSpline();
void UpdateOptionsToolCubicBezier();
void UpdateOptionsToolSplinePath();
void UpdateOptionsToolCubicBezierPath();
void UpdateOptionsToolTriangle();
void UpdateOptionsToolLineIntersectAxis();
void UpdateOptionsToolCurveIntersectAxis();

View File

@ -833,7 +833,11 @@ void MainWindow::ToolSplinePath(bool checked)
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::ToolCubicBezierPath(bool checked)
{
SetToolButtonWithApply<DialogCubicBezierPath>(checked, Tool::CubicBezierPath,
":/cursor/cubic_bezier_path_cursor.png",
tr("Select point of cubic bezier path"),
&MainWindow::ClosedDialogWithApply<VToolCubicBezierPath>,
&MainWindow::ApplyDialog<VToolCubicBezierPath>);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -44,6 +44,7 @@
#include "../vgeometry/varc.h"
#include "../vgeometry/vsplinepath.h"
#include "../vgeometry/vcubicbezier.h"
#include "../vgeometry/vcubicbezierpath.h"
#include "../core/vapplication.h"
#include "../vpatterndb/calculator.h"
@ -2129,6 +2130,58 @@ void VPattern::ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPattern::ParseToolCubicBezierPath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse)
{
SCASSERT(scene != nullptr);
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");
try
{
quint32 id = 0;
ToolsCommonAttributes(domElement, id);
const QString color = GetParametrString(domElement, AttrColor, ColorBlack);
const quint32 duplicate = GetParametrUInt(domElement, AttrDuplicate, "0");
QVector<VPointF> points;
const QDomNodeList nodeList = domElement.childNodes();
const qint32 num = nodeList.size();
for (qint32 i = 0; i < num; ++i)
{
const QDomElement element = nodeList.at(i).toElement();
if (element.isNull() == false)
{
if (element.tagName() == AttrPathPoint)
{
const quint32 pSpline = GetParametrUInt(element, AttrPSpline, NULL_ID_STR);
const VPointF p = *data->GeometricObject<VPointF>(pSpline);
points.append(p);
if (parse == Document::FullParse)
{
IncrementReferens(p.getIdTool());
}
}
}
}
auto path = new VCubicBezierPath(points);
if (duplicate > 0)
{
path->SetDuplicate(duplicate);
}
VToolCubicBezierPath::Create(id, path, color, scene, this, data, parse, Source::FromFile);
}
catch (const VExceptionBadId &e)
{
VExceptionObjectError excep(tr("Error creating or updating cubic bezier path curve"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPattern::ParseNodeSpline(const QDomElement &domElement, const Document &parse)
{
@ -2431,7 +2484,8 @@ void VPattern::ParseSplineElement(VMainGraphicsScene *scene, QDomElement &domEle
<< VToolSplinePath::ToolType /*3*/
<< VNodeSpline::ToolType /*4*/
<< VNodeSplinePath::ToolType /*5*/
<< VToolCubicBezier::ToolType; /*6*/
<< VToolCubicBezier::ToolType /*6*/
<< VToolCubicBezierPath::ToolType; /*7*/
switch (splines.indexOf(type))
{
case 0: //VToolSpline::OldToolType
@ -2462,6 +2516,10 @@ void VPattern::ParseSplineElement(VMainGraphicsScene *scene, QDomElement &domEle
qCDebug(vXML, "VToolCubicBezier.");
ParseToolCubicBezier(scene, domElement, parse);
break;
case 7: //VToolCubicBezierPath::ToolType
qCDebug(vXML, "VToolCubicBezierPath.");
ParseToolCubicBezierPath(scene, domElement, parse);
break;
default:
VException e(tr("Unknown spline type '%1'.").arg(type));
throw e;

View File

@ -176,6 +176,7 @@ private:
void ParseOldToolSplinePath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse);
void ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse);
void ParseToolCubicBezierPath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse);
void ParseNodeSpline(const QDomElement &domElement, const Document &parse);
void ParseNodeSplinePath(const QDomElement &domElement, const Document &parse);

View File

@ -31,6 +31,8 @@
#include "vgobject.h"
#include <QMetaType>
class QPointF;
class QString;
class VPointFData;
@ -69,6 +71,7 @@ private:
QSharedDataPointer<VPointFData> d;
};
Q_DECLARE_METATYPE(VPointF)
Q_DECLARE_TYPEINFO(VPointF, Q_MOVABLE_TYPE);
#if defined(Q_CC_INTEL)

View File

@ -35,7 +35,8 @@ HEADERS += \
$$PWD/support/dialogundo.h \
$$PWD/tools/dialogtruedarts.h \
$$PWD/tools/dialogpointofintersectioncurves.h \
$$PWD/tools/dialogcubicbezier.h
$$PWD/tools/dialogcubicbezier.h \
$$PWD/tools/dialogcubicbezierpath.h
SOURCES += \
$$PWD/tools/dialogalongline.cpp \
@ -70,7 +71,8 @@ SOURCES += \
$$PWD/support/dialogundo.cpp \
$$PWD/tools/dialogtruedarts.cpp \
$$PWD/tools/dialogpointofintersectioncurves.cpp \
$$PWD/tools/dialogcubicbezier.cpp
$$PWD/tools/dialogcubicbezier.cpp \
$$PWD/tools/dialogcubicbezierpath.cpp
FORMS += \
$$PWD/tools/dialogalongline.ui \
@ -104,4 +106,5 @@ FORMS += \
$$PWD/support/dialogundo.ui \
$$PWD/tools/dialogtruedarts.ui \
$$PWD/tools/dialogpointofintersectioncurves.ui \
$$PWD/tools/dialogcubicbezier.ui
$$PWD/tools/dialogcubicbezier.ui \
$$PWD/tools/dialogcubicbezierpath.ui

View File

@ -44,6 +44,7 @@
#include "dialogs/tools/dialogspline.h"
#include "dialogs/tools/dialogcubicbezier.h"
#include "dialogs/tools/dialogsplinepath.h"
#include "dialogs/tools/dialogcubicbezierpath.h"
#include "dialogs/tools/dialogheight.h"
#include "dialogs/tools/dialogcutarc.h"
#include "dialogs/tools/dialogcutspline.h"

View File

@ -0,0 +1,312 @@
/************************************************************************
**
** @file dialogcubicbezierpath.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 18 3, 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 "dialogcubicbezierpath.h"
#include "ui_dialogcubicbezierpath.h"
#include "../../visualization/vistoolcubicbezierpath.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
# include "../vmisc/vmath.h"
#else
# include <QtMath>
#endif
//---------------------------------------------------------------------------------------------------------------------
DialogCubicBezierPath::DialogCubicBezierPath(const VContainer *data, const quint32 &toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogCubicBezierPath),
path(),
newDuplicate(-1)
{
ui->setupUi(this);
InitOkCancelApply(ui);
bOk->setEnabled(false);
FillComboBoxPoints(ui->comboBoxPoint);
FillComboBoxLineColors(ui->comboBoxColor);
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogCubicBezierPath::PointChanged);
connect(ui->comboBoxPoint, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &DialogCubicBezierPath::currentPointChanged);
vis = new VisToolCubicBezierPath(data);
}
//---------------------------------------------------------------------------------------------------------------------
DialogCubicBezierPath::~DialogCubicBezierPath()
{
DeleteVisualization<VisToolCubicBezierPath>();
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
VCubicBezierPath DialogCubicBezierPath::GetPath() const
{
return path;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCubicBezierPath::SetPath(const VCubicBezierPath &value)
{
this->path = value;
ui->listWidget->blockSignals(true);
ui->listWidget->clear();
for (qint32 i = 0; i < path.CountPoints(); ++i)
{
NewItem(path.at(i));
}
ui->listWidget->setFocus(Qt::OtherFocusReason);
ui->lineEditSplPathName->setText(path.name());
auto visPath = qobject_cast<VisToolCubicBezierPath *>(vis);
SCASSERT(visPath != nullptr);
visPath->setPath(path);
ui->listWidget->blockSignals(false);
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogCubicBezierPath::GetColor() const
{
return GetComboBoxCurrentData(ui->comboBoxColor);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCubicBezierPath::SetColor(const QString &value)
{
ChangeCurrentData(ui->comboBoxColor, value);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCubicBezierPath::ChosenObject(quint32 id, const SceneObject &type)
{
if (type == SceneObject::Point)
{
if (AllIds().contains(id))
{
return;
}
const auto point = data->GeometricObject<VPointF>(id);
NewItem(*point);
SavePath();
auto visPath = qobject_cast<VisToolCubicBezierPath *>(vis);
SCASSERT(visPath != nullptr);
visPath->setPath(path);
if (path.CountPoints() == 1)
{
visPath->VisualMode(NULL_ID);
connect(visPath, &VisToolCubicBezierPath::ToolTip, this, &DialogTool::ShowVisToolTip);
}
else
{
visPath->RefreshGeometry();
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCubicBezierPath::ShowDialog(bool click)
{
if (click == false)
{
if (path.CountPoints() >= 7)
{
if (path.CountPoints() - ((path.CountSubSpl() - 1) * 3 + 4) == 0)
{// Accept only if all subpaths are completed
emit ToolTip("");
if (not data->IsUnique(path.name()))
{
path.SetDuplicate(DNumber(path.name()));
}
DialogAccepted();
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCubicBezierPath::ShowVisualization()
{
AddVisualization<VisToolCubicBezierPath>();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCubicBezierPath::SaveData()
{
const quint32 d = path.GetDuplicate();//Save previous value
SavePath();
newDuplicate <= -1 ? path.SetDuplicate(d) : path.SetDuplicate(static_cast<quint32>(newDuplicate));
auto visPath = qobject_cast<VisToolCubicBezierPath *>(vis);
SCASSERT(visPath != nullptr);
visPath->setPath(path);
visPath->SetMode(Mode::Show);
visPath->RefreshGeometry();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCubicBezierPath::PointChanged(int row)
{
if (ui->listWidget->count() == 0)
{
return;
}
const auto p = qvariant_cast<VPointF>(ui->listWidget->item(row)->data(Qt::UserRole));
DataPoint(p);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCubicBezierPath::currentPointChanged(int index)
{
const quint32 id = qvariant_cast<quint32>(ui->comboBoxPoint->itemData(index));
QListWidgetItem *item = ui->listWidget->item( ui->listWidget->currentRow() );
const auto point = data->GeometricObject<VPointF>(id);
DataPoint(*point);
item->setData(Qt::UserRole, QVariant::fromValue(*point));
QColor color = okColor;
if (not IsPathValid())
{
flagError = false;
color = errorColor;
ui->lineEditSplPathName->setText(tr("Invalid spline path"));
}
else
{
flagError = true;
color = okColor;
auto first = qvariant_cast<VPointF>(ui->listWidget->item(0)->data(Qt::UserRole));
auto last = qvariant_cast<VPointF>(ui->listWidget->item(ui->listWidget->count()-1)->data(Qt::UserRole));
if (first.id() == path.at(0).id() && last.id() == path.at(path.CountPoints()-1).id())
{
newDuplicate = -1;
ui->lineEditSplPathName->setText(path.name());
}
else
{
VCubicBezierPath newPath = ExtractPath();
if (not data->IsUnique(newPath.name()))
{
newDuplicate = DNumber(newPath.name());
newPath.SetDuplicate(newDuplicate);
}
ui->lineEditSplPathName->setText(newPath.name());
}
}
ChangeColor(ui->labelName, color);
ChangeColor(ui->labelPoint, color);
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCubicBezierPath::NewItem(const VPointF &point)
{
auto item = new QListWidgetItem(point.name());
item->setFont(QFont("Times", 12, QFont::Bold));
item->setData(Qt::UserRole, QVariant::fromValue(point));
ui->listWidget->addItem(item);
ui->listWidget->setCurrentItem(item);
if (ui->listWidget->count() >= 7)
{
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
bOk->setEnabled(true);
}
DataPoint(point);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCubicBezierPath::DataPoint(const VPointF &p)
{
ui->comboBoxPoint->blockSignals(true);
ChangeCurrentData(ui->comboBoxPoint, p.id());
ui->comboBoxPoint->blockSignals(false);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCubicBezierPath::SavePath()
{
path.Clear();
path = ExtractPath();
}
//---------------------------------------------------------------------------------------------------------------------
QSet<quint32> DialogCubicBezierPath::AllIds() const
{
QVector<quint32> points;
for (qint32 i = 0; i < ui->listWidget->count(); ++i)
{
points.append(qvariant_cast<VPointF>(ui->listWidget->item(i)->data(Qt::UserRole)).id());
}
QSet<quint32> ids;
const qint32 count = qFloor(qAbs((points.size() - 4) / 3 + 1));// Count subpaths
for (qint32 i = 0; i < count; ++i)
{
const qint32 base = (i - 1) * 3;
ids.insert(points.at(base));// The first subpath's point
ids.insert(points.at(base + 3));// The last subpath's point
}
return ids;
}
//---------------------------------------------------------------------------------------------------------------------
bool DialogCubicBezierPath::IsPathValid() const
{
if (path.CountPoints() < 7)
{
return false;
}
return (AllIds().size() == path.CountSubSpl() + 1);
}
//---------------------------------------------------------------------------------------------------------------------
VCubicBezierPath DialogCubicBezierPath::ExtractPath() const
{
QVector<VPointF> points;
for (qint32 i = 0; i < ui->listWidget->count(); ++i)
{
points.append(qvariant_cast<VPointF>(ui->listWidget->item(i)->data(Qt::UserRole)));
}
return VCubicBezierPath(points);
}

View File

@ -0,0 +1,80 @@
/************************************************************************
**
** @file dialogcubicbezierpath.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 18 3, 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 DIALOGCUBICBEZIERPATH_H
#define DIALOGCUBICBEZIERPATH_H
#include "dialogtool.h"
#include "../vgeometry/vcubicbezierpath.h"
namespace Ui
{
class DialogCubicBezierPath;
}
class DialogCubicBezierPath : public DialogTool
{
Q_OBJECT
public:
explicit DialogCubicBezierPath(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
virtual ~DialogCubicBezierPath();
VCubicBezierPath GetPath() const;
void SetPath(const VCubicBezierPath &value);
QString GetColor() const;
void SetColor(const QString &value);
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE;
virtual void ShowDialog(bool click) Q_DECL_OVERRIDE;
protected:
virtual void ShowVisualization() Q_DECL_OVERRIDE;
virtual void SaveData() Q_DECL_OVERRIDE;
private slots:
void PointChanged(int row);
void currentPointChanged(int index);
private:
Q_DISABLE_COPY(DialogCubicBezierPath)
Ui::DialogCubicBezierPath *ui;
/** @brief path cubic bezier path */
VCubicBezierPath path;
qint32 newDuplicate;
void NewItem(const VPointF &point);
void DataPoint(const VPointF &p);
void SavePath();
QSet<quint32> AllIds() const;
bool IsPathValid() const;
VCubicBezierPath ExtractPath() const;
};
#endif // DIALOGCUBICBEZIERPATH_H

View File

@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogCubicBezierPath</class>
<widget class="QDialog" name="DialogCubicBezierPath">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>324</width>
<height>327</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog cubic bezier path</string>
</property>
<property name="windowIcon">
<iconset resource="../../../vmisc/share/resources/icon.qrc">
<normaloff>:/icon/64x64/icon64x64.png</normaloff>:/icon/64x64/icon64x64.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="labelPoint">
<property name="text">
<string>Point:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxPoint"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="listWidget">
<property name="toolTip">
<string>List of points</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Color:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBoxColor"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelName">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditSplPathName">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../../vmisc/share/resources/icon.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DialogCubicBezierPath</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DialogCubicBezierPath</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -42,6 +42,7 @@
#include "toolcurve/vtoolspline.h"
#include "toolcurve/vtoolcubicbezier.h"
#include "toolcurve/vtoolsplinepath.h"
#include "toolcurve/vtoolcubicbezierpath.h"
#include "vtoolline.h"
#include "toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h"
#include "toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h"

View File

@ -73,7 +73,7 @@ protected:
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) Q_DECL_OVERRIDE;
virtual void SetVisualization() Q_DECL_OVERRIDE;
private:
void RefreshGeometry();
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
};
#endif // VTOOLARC_H

View File

@ -74,7 +74,7 @@ protected:
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) Q_DECL_OVERRIDE;
virtual void SetVisualization() Q_DECL_OVERRIDE;
private:
void RefreshGeometry();
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
};

View File

@ -63,7 +63,7 @@ protected:
private:
Q_DISABLE_COPY(VToolCubicBezier)
void RefreshGeometry ();
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
void SetSplineAttributes(QDomElement &domElement, const VCubicBezier &spl);
};

View File

@ -0,0 +1,254 @@
/************************************************************************
**
** @file vtoolcubicbezierpath.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 18 3, 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 "vtoolcubicbezierpath.h"
#include "../../../dialogs/tools/dialogcubicbezierpath.h"
#include "../../../visualization/vistoolcubicbezierpath.h"
const QString VToolCubicBezierPath::ToolType = QStringLiteral("cubicBezierPath");
//---------------------------------------------------------------------------------------------------------------------
VToolCubicBezierPath::VToolCubicBezierPath(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color,
const Source &typeCreation, QGraphicsItem *parent)
: VAbstractSpline(doc, data, id, parent)
{
sceneType = SceneObject::SplinePath;
lineColor = color;
this->setPath(ToolPath());
this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);
this->setAcceptHoverEvents(true);
ToolCreation(typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
VToolCubicBezierPath::~VToolCubicBezierPath()
{
}
//---------------------------------------------------------------------------------------------------------------------
void VToolCubicBezierPath::setDialog()
{
SCASSERT(dialog != nullptr);
auto dialogTool = qobject_cast<DialogCubicBezierPath*>(dialog);
SCASSERT(dialogTool != nullptr);
const QSharedPointer<VCubicBezierPath> splPath = VAbstractTool::data.GeometricObject<VCubicBezierPath>(id);
dialogTool->SetPath(*splPath);
dialogTool->SetColor(lineColor);
}
//---------------------------------------------------------------------------------------------------------------------
VToolCubicBezierPath *VToolCubicBezierPath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data)
{
SCASSERT(dialog != nullptr);
auto dialogTool = qobject_cast<DialogCubicBezierPath*>(dialog);
SCASSERT(dialogTool != nullptr);
auto path = new VCubicBezierPath(dialogTool->GetPath());
const QString color = dialogTool->GetColor();
for (qint32 i = 0; i < path->CountPoints(); ++i)
{
doc->IncrementReferens((*path)[i].getIdTool());
}
VToolCubicBezierPath* spl = Create(0, path, color, scene, doc, data, Document::FullParse, Source::FromGui);
if (spl != nullptr)
{
spl->dialog=dialogTool;
}
return spl;
}
//---------------------------------------------------------------------------------------------------------------------
VToolCubicBezierPath *VToolCubicBezierPath::Create(const quint32 _id, VCubicBezierPath *path, const QString &color,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
{
quint32 id = _id;
if (typeCreation == Source::FromGui)
{
id = data->AddGObject(path);
data->AddCurve<VCubicBezierPath>(id);
}
else
{
data->UpdateGObject(id, path);
data->AddCurve<VCubicBezierPath>(id);
if (parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
}
}
VDrawTool::AddRecord(id, Tool::CubicBezierPath, doc);
if (parse == Document::FullParse)
{
VToolCubicBezierPath *spl = new VToolCubicBezierPath(doc, data, id, color, typeCreation);
scene->addItem(spl);
connect(spl, &VToolCubicBezierPath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
connect(scene, &VMainGraphicsScene::NewFactor, spl, &VToolCubicBezierPath::SetFactor);
connect(scene, &VMainGraphicsScene::DisableItem, spl, &VToolCubicBezierPath::Disable);
doc->AddTool(id, spl);
return spl;
}
return nullptr;
}
//---------------------------------------------------------------------------------------------------------------------
void VToolCubicBezierPath::UpdatePathPoints(VAbstractPattern *doc, QDomElement &element, const VCubicBezierPath &path)
{
VDomDocument::RemoveAllChildren(element);
for (qint32 i = 0; i < path.CountPoints(); ++i)
{
AddPathPoint(doc, element, path.at(i));
}
}
//---------------------------------------------------------------------------------------------------------------------
VCubicBezierPath VToolCubicBezierPath::getSplinePath() const
{
QSharedPointer<VCubicBezierPath> splPath = VAbstractTool::data.GeometricObject<VCubicBezierPath>(id);
return *splPath.data();
}
//---------------------------------------------------------------------------------------------------------------------
void VToolCubicBezierPath::setSplinePath(const VCubicBezierPath &splPath)
{
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
QSharedPointer<VCubicBezierPath> splinePath = qSharedPointerDynamicCast<VCubicBezierPath>(obj);
*splinePath.data() = splPath;
SaveOption(obj);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolCubicBezierPath::ShowVisualization(bool show)
{
ShowToolVisualization<VisToolCubicBezierPath>(show);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolCubicBezierPath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
try
{
ContextMenu<DialogCubicBezierPath>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolCubicBezierPath::RemoveReferens()
{
const QSharedPointer<VCubicBezierPath> splPath = VAbstractTool::data.GeometricObject<VCubicBezierPath>(id);
for (qint32 i = 0; i < splPath->CountSubSpl(); ++i)
{
doc->DecrementReferens(splPath->at(i).getIdTool());
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolCubicBezierPath::SaveDialog(QDomElement &domElement)
{
SCASSERT(dialog != nullptr);
const auto dialogTool = qobject_cast<DialogCubicBezierPath*>(dialog);
SCASSERT(dialogTool != nullptr);
doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor());
SetSplinePathAttributes(domElement, dialogTool->GetPath());
}
//---------------------------------------------------------------------------------------------------------------------
void VToolCubicBezierPath::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
{
VAbstractSpline::SaveOptions(tag, obj);
QSharedPointer<VCubicBezierPath> splPath = qSharedPointerDynamicCast<VCubicBezierPath>(obj);
SCASSERT(splPath.isNull() == false);
SetSplinePathAttributes(tag, *splPath);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolCubicBezierPath::SetVisualization()
{
if (vis != nullptr)
{
auto visual = qobject_cast<VisToolCubicBezierPath *>(vis);
SCASSERT(visual != nullptr);
QSharedPointer<VCubicBezierPath> splPath = VAbstractTool::data.GeometricObject<VCubicBezierPath>(id);
visual->setPath(*splPath.data());
visual->SetMode(Mode::Show);
visual->RefreshGeometry();
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolCubicBezierPath::RefreshGeometry()
{
isHovered || detailsMode ? setPath(ToolPath(PathDirection::Show)) : setPath(ToolPath());
this->setPen(QPen(CorrectColor(lineColor),
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
SetVisualization();
}
//---------------------------------------------------------------------------------------------------------------------
void VToolCubicBezierPath::AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VPointF &splPoint)
{
SCASSERT(doc != nullptr);
QDomElement pathPoint = doc->createElement(AttrPathPoint);
doc->SetAttribute(pathPoint, AttrPSpline, splPoint.id());
domElement.appendChild(pathPoint);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolCubicBezierPath::SetSplinePathAttributes(QDomElement &domElement, const VCubicBezierPath &path)
{
doc->SetAttribute(domElement, AttrType, ToolType);
if (path.GetDuplicate() > 0)
{
doc->SetAttribute(domElement, AttrDuplicate, path.GetDuplicate());
}
else
{
if (domElement.hasAttribute(AttrDuplicate))
{
domElement.removeAttribute(AttrDuplicate);
}
}
UpdatePathPoints(doc, domElement, path);
}

View File

@ -0,0 +1,73 @@
/************************************************************************
**
** @file vtoolcubicbezierpath.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 18 3, 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 VTOOLCUBICBEZIERPATH_H
#define VTOOLCUBICBEZIERPATH_H
#include "vabstractspline.h"
class VCubicBezierPath;
class VToolCubicBezierPath:public VAbstractSpline
{
Q_OBJECT
public:
VToolCubicBezierPath(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color,
const Source &typeCreation, QGraphicsItem * parent = nullptr);
virtual ~VToolCubicBezierPath();
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolCubicBezierPath *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolCubicBezierPath *Create(const quint32 _id, VCubicBezierPath *path, const QString &color,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static const QString ToolType;
static void UpdatePathPoints(VAbstractPattern *doc, QDomElement &element, const VCubicBezierPath &path);
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::CubicBezierPath)};
VCubicBezierPath getSplinePath()const;
void setSplinePath(const VCubicBezierPath &splPath);
virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE;
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE;
virtual void RemoveReferens() Q_DECL_OVERRIDE;
virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE;
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) Q_DECL_OVERRIDE;
virtual void SetVisualization() Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(VToolCubicBezierPath)
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
static void AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VPointF &splPoint);
void SetSplinePathAttributes(QDomElement &domElement, const VCubicBezierPath &path);
};
#endif // VTOOLCUBICBEZIERPATH_H

View File

@ -81,7 +81,7 @@ private:
QPointF oldPosition;
bool IsMovable() const;
void RefreshGeometry ();
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
void SetSplineAttributes(QDomElement &domElement, const VSpline &spl);
};

View File

@ -389,10 +389,10 @@ void VToolSplinePath::AddPathPoint(VAbstractPattern *doc, QDomElement &domElemen
*/
void VToolSplinePath::RemoveReferens()
{
const VSplinePath splPath = *VAbstractTool::data.GeometricObject<VSplinePath>(id);
for (qint32 i = 0; i < splPath.CountSubSpl(); ++i)
const QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
for (qint32 i = 0; i < splPath->CountSubSpl(); ++i)
{
doc->DecrementReferens(splPath.at(i).P().getIdTool());
doc->DecrementReferens(splPath->at(i).P().getIdTool());
}
}

View File

@ -46,7 +46,7 @@ public:
const Source &typeCreation,
QGraphicsItem * parent = nullptr);
virtual ~VToolSplinePath() Q_DECL_OVERRIDE;
virtual void setDialog();
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolSplinePath *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolSplinePath *Create(const quint32 _id, VSplinePath *path, const QString &color,
@ -100,11 +100,12 @@ protected:
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual void SetVisualization() Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(VToolSplinePath)
QPointF oldPosition;
int splIndex;
bool IsMovable(int index) const;
void RefreshGeometry();
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
static void AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VSplinePoint &splPoint);
void UpdateControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline) const;
void SetSplinePathAttributes(QDomElement &domElement, const VSplinePath &path);

View File

@ -48,7 +48,8 @@ HEADERS += \
$$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h \
$$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h \
$$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h \
$$PWD/drawTools/toolcurve/vtoolcubicbezier.h
$$PWD/drawTools/toolcurve/vtoolcubicbezier.h \
$$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h
SOURCES += \
$$PWD/vtooldetail.cpp \
@ -94,4 +95,5 @@ SOURCES += \
$$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp \
$$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp \
$$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp \
$$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp
$$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp \
$$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp

View File

@ -0,0 +1,206 @@
/************************************************************************
**
** @file vistoolcubicbezierpath.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 18 3, 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 "vistoolcubicbezierpath.h"
#include "../vgeometry/vspline.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolCubicBezierPath::VisToolCubicBezierPath(const VContainer *data, QGraphicsItem *parent)
: VisPath(data, parent),
mainPoints(),
ctrlPoints(),
lines(),
newCurveSegment(nullptr),
path(),
helpLine1(nullptr),
helpLine2(nullptr)
{
helpLine1 = InitItem<QGraphicsLineItem>(mainColor, this);
helpLine2 = InitItem<QGraphicsLineItem>(mainColor, this);
newCurveSegment = InitItem<QGraphicsPathItem>(mainColor, this);
}
//---------------------------------------------------------------------------------------------------------------------
VisToolCubicBezierPath::~VisToolCubicBezierPath()
{
qDeleteAll(mainPoints);
qDeleteAll(lines);
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolCubicBezierPath::RefreshGeometry()
{
if (path.CountPoints() > 0)
{
const QVector<VPointF> pathPoints = path.GetSplinePath();
const int size = pathPoints.size();
const int countSubSpl = path.CountSubSpl();
for (int i = 0; i < size; ++i)
{
QGraphicsEllipseItem *point = this->getPoint(mainPoints, static_cast<unsigned>(i), 1/*zValue*/);
DrawPoint(point, pathPoints.at(i).toQPointF(), supportColor);
}
if (mode == Mode::Creation)
{
for (qint32 i = 1; i<=countSubSpl; ++i)
{
const int preLastPoint = (countSubSpl - 1) * 2;
const int lastPoint = preLastPoint + 1;
const VSpline spl = path.GetSpline(i);
QGraphicsLineItem *ctrlLine1 = this->getLine(static_cast<unsigned>(preLastPoint));
DrawLine(ctrlLine1, QLineF(spl.GetP1().toQPointF(), spl.GetP2()), mainColor, Qt::DashLine);
QGraphicsEllipseItem *p2 = this->getPoint(ctrlPoints, static_cast<unsigned>(preLastPoint));
DrawPoint(p2, spl.GetP2(), Qt::green);
QGraphicsLineItem *ctrlLine2 = this->getLine(static_cast<unsigned>(lastPoint));
DrawLine(ctrlLine2, QLineF(spl.GetP4().toQPointF(), spl.GetP3()), mainColor, Qt::DashLine);
QGraphicsEllipseItem *p3 = this->getPoint(ctrlPoints, static_cast<unsigned>(lastPoint));
DrawPoint(p3, spl.GetP3(), Qt::green);
}
const qint32 last = (countSubSpl - 1) * 3 + 3;
Creating(pathPoints, size-1-last);
}
if (countSubSpl >= 1)
{
DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap);
}
if (countSubSpl < 7)
{
Visualization::toolTip = tr("<b>Curved path</b>: select seven or more points");
}
else if (countSubSpl >= 7 && size - ((countSubSpl - 1) * 3 + 4) == 0)
{
Visualization::toolTip = tr("<b>Curved path</b>: select seven or more points, "
"<b>Enter</b> - finish creation");
}
else
{
Visualization::toolTip = tr("<b>Curved path</b>: select more points for complete segment");
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolCubicBezierPath::setPath(const VCubicBezierPath &value)
{
path = value;
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
VCubicBezierPath VisToolCubicBezierPath::getPath()
{
return path;
}
//---------------------------------------------------------------------------------------------------------------------
QGraphicsEllipseItem *VisToolCubicBezierPath::getPoint(QVector<QGraphicsEllipseItem *> &points, quint32 i, qreal z)
{
if (not points.isEmpty() && static_cast<quint32>(points.size() - 1) >= i)
{
return points.at(static_cast<int>(i));
}
else
{
auto point = InitPoint(supportColor, this, z);
points.append(point);
return point;
}
return nullptr;
}
//---------------------------------------------------------------------------------------------------------------------
QGraphicsLineItem *VisToolCubicBezierPath::getLine(quint32 i)
{
if (static_cast<quint32>(lines.size() - 1) >= i && lines.isEmpty() == false)
{
return lines.at(static_cast<int>(i));
}
else
{
auto line = InitItem<QGraphicsLineItem>(mainColor, this);
lines.append(line);
return line;
}
return nullptr;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolCubicBezierPath::Creating(const QVector<VPointF> &pathPoints, int pointsLeft)
{
if (pathPoints.isEmpty() || pathPoints.size()+1 < pointsLeft)
{
return;
}
switch(pointsLeft)
{
case 0:
{
const QPointF p1 = pathPoints.last().toQPointF();
DrawLine(helpLine1, QLineF(p1, Visualization::scenePos), mainColor, Qt::DashLine);
break;
}
case 1:
{
const VPointF p1 = pathPoints.at(pointsLeft-1);
const QPointF p2 = pathPoints.at(pointsLeft).toQPointF();
DrawLine(helpLine1, QLineF(p1.toQPointF(), p2), mainColor, Qt::DashLine);
VSpline spline(p1, p2, Visualization::scenePos, VPointF(Visualization::scenePos));
DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap);
break;
}
case 2:
{
const VPointF p1 = pathPoints.at(pointsLeft-2);
const QPointF p2 = pathPoints.at(pointsLeft-1).toQPointF();
const QPointF p3 = pathPoints.at(pointsLeft).toQPointF();
DrawLine(helpLine1, QLineF(p1.toQPointF(), p2), mainColor, Qt::DashLine);
DrawLine(helpLine2, QLineF(p3, Visualization::scenePos), mainColor, Qt::DashLine);
VSpline spline(p1, p2, p3, VPointF(Visualization::scenePos));
DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap);
break;
}
default:
break;
}
}

View File

@ -0,0 +1,65 @@
/************************************************************************
**
** @file vistoolcubicbezierpath.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 18 3, 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 VISTOOLCUBICBEZIERPATH_H
#define VISTOOLCUBICBEZIERPATH_H
#include "vispath.h"
#include "../vgeometry/vcubicbezierpath.h"
class VisToolCubicBezierPath : public VisPath
{
Q_OBJECT
public:
explicit VisToolCubicBezierPath(const VContainer *data, QGraphicsItem *parent = nullptr);
virtual ~VisToolCubicBezierPath();
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
void setPath(const VCubicBezierPath &value);
VCubicBezierPath getPath();
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Vis::ToolCubicBezierPath)};
protected:
Q_DISABLE_COPY(VisToolCubicBezierPath)
QVector<QGraphicsEllipseItem *> mainPoints;
QVector<QGraphicsEllipseItem *> ctrlPoints;
QVector<QGraphicsLineItem *> lines;
QGraphicsPathItem *newCurveSegment;
VCubicBezierPath path;
QGraphicsLineItem *helpLine1;
QGraphicsLineItem *helpLine2;
QGraphicsEllipseItem *getPoint(QVector<QGraphicsEllipseItem *> &points, quint32 i, qreal z = 0);
QGraphicsLineItem *getLine(quint32 i);
void Creating(const QVector<VPointF> &pathPoints , int pointsLeft);
};
#endif // VISTOOLCUBICBEZIERPATH_H

View File

@ -38,7 +38,7 @@ class VisToolSplinePath : public VisPath
{
Q_OBJECT
public:
explicit VisToolSplinePath(const VContainer *data, QGraphicsItem *parent = 0);
explicit VisToolSplinePath(const VContainer *data, QGraphicsItem *parent = nullptr);
virtual ~VisToolSplinePath() Q_DECL_OVERRIDE;
virtual void RefreshGeometry() Q_DECL_OVERRIDE;

View File

@ -113,7 +113,7 @@ void Visualization::MousePos(const QPointF &scenePos)
}
//---------------------------------------------------------------------------------------------------------------------
QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsItem *parent) const
QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsItem *parent, qreal z) const
{
QGraphicsEllipseItem *point = new QGraphicsEllipseItem(parent);
point->setZValue(1);
@ -122,6 +122,7 @@ QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsIte
point->setRect(PointRect(ToPixel(DefPointRadius/*mm*/, Unit::Mm)));
point->setPos(QPointF());
point->setFlags(QGraphicsItem::ItemStacksBehindParent);
point->setZValue(z);
point->setVisible(false);
return point;
}

View File

@ -80,7 +80,7 @@ protected:
virtual void InitPen()=0;
virtual void AddOnScene()=0;
QGraphicsEllipseItem *InitPoint(const QColor &color, QGraphicsItem *parent) const;
QGraphicsEllipseItem *InitPoint(const QColor &color, QGraphicsItem *parent, qreal z = 0) const;
QRectF PointRect(const qreal &radius) const;
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color,
Qt::PenStyle style = Qt::SolidLine);

View File

@ -31,7 +31,8 @@ HEADERS += \
$$PWD/vistoolarcwithlength.h \
$$PWD/vistooltruedarts.h \
$$PWD/vistoolpointofintersectioncurves.h \
$$PWD/vistoolcubicbezier.h
$$PWD/vistoolcubicbezier.h \
$$PWD/vistoolcubicbezierpath.h
SOURCES += \
$$PWD/visline.cpp \
@ -63,4 +64,5 @@ SOURCES += \
$$PWD/vistoolarcwithlength.cpp \
$$PWD/vistooltruedarts.cpp \
$$PWD/vistoolpointofintersectioncurves.cpp \
$$PWD/vistoolcubicbezier.cpp
$$PWD/vistoolcubicbezier.cpp \
$$PWD/vistoolcubicbezierpath.cpp