Merge with feature. Resolved issue #395. Create Curve tool which uses point as
control handle. --HG-- branch : develop
|
@ -89,6 +89,7 @@ cov-int/
|
||||||
/.qmake.stash
|
/.qmake.stash
|
||||||
*.pro.user
|
*.pro.user
|
||||||
*.pro.user.*
|
*.pro.user.*
|
||||||
|
*.qbs.user
|
||||||
*.moc
|
*.moc
|
||||||
moc_*.cpp
|
moc_*.cpp
|
||||||
qrc_*.cpp
|
qrc_*.cpp
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# Version 0.5.0
|
# Version 0.5.0
|
||||||
|
- [#395] Create Curve tool which uses point as control handle.
|
||||||
- pdftops updated to version 3.04.
|
- pdftops updated to version 3.04.
|
||||||
- [#306] Layout generator optimization. Divide into strips.
|
- [#306] Layout generator optimization. Divide into strips.
|
||||||
- Fixed case with duplicate names of curves if they connect same points.
|
- Fixed case with duplicate names of curves if they connect same points.
|
||||||
|
|
|
@ -73,6 +73,9 @@ void VToolOptionsPropertyBrowser::ClearPropertyBrowser()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item)
|
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())
|
switch (item->type())
|
||||||
{
|
{
|
||||||
case VToolBasePoint::Type:
|
case VToolBasePoint::Type:
|
||||||
|
@ -141,6 +144,9 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item)
|
||||||
case VToolSplinePath::Type:
|
case VToolSplinePath::Type:
|
||||||
ShowOptionsToolSplinePath(item);
|
ShowOptionsToolSplinePath(item);
|
||||||
break;
|
break;
|
||||||
|
case VToolCubicBezierPath::Type:
|
||||||
|
ShowOptionsToolCubicBezierPath(item);
|
||||||
|
break;
|
||||||
case VToolTriangle::Type:
|
case VToolTriangle::Type:
|
||||||
ShowOptionsToolTriangle(item);
|
ShowOptionsToolTriangle(item);
|
||||||
break;
|
break;
|
||||||
|
@ -184,6 +190,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions()
|
||||||
return;
|
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())
|
switch (currentItem->type())
|
||||||
{
|
{
|
||||||
case VToolBasePoint::Type:
|
case VToolBasePoint::Type:
|
||||||
|
@ -252,6 +261,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions()
|
||||||
case VToolSplinePath::Type:
|
case VToolSplinePath::Type:
|
||||||
UpdateOptionsToolSplinePath();
|
UpdateOptionsToolSplinePath();
|
||||||
break;
|
break;
|
||||||
|
case VToolCubicBezierPath::Type:
|
||||||
|
UpdateOptionsToolCubicBezierPath();
|
||||||
|
break;
|
||||||
case VToolTriangle::Type:
|
case VToolTriangle::Type:
|
||||||
UpdateOptionsToolTriangle();
|
UpdateOptionsToolTriangle();
|
||||||
break;
|
break;
|
||||||
|
@ -310,6 +322,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property)
|
||||||
return;
|
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())
|
switch (currentItem->type())
|
||||||
{
|
{
|
||||||
case VToolBasePoint::Type:
|
case VToolBasePoint::Type:
|
||||||
|
@ -378,6 +393,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property)
|
||||||
case VToolSplinePath::Type:
|
case VToolSplinePath::Type:
|
||||||
ChangeDataToolSplinePath(prop);
|
ChangeDataToolSplinePath(prop);
|
||||||
break;
|
break;
|
||||||
|
case VToolCubicBezierPath::Type:
|
||||||
|
ChangeDataToolCubicBezierPath(prop);
|
||||||
|
break;
|
||||||
case VToolTriangle::Type:
|
case VToolTriangle::Type:
|
||||||
ChangeDataToolTriangle(prop);
|
ChangeDataToolTriangle(prop);
|
||||||
break;
|
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)
|
void VToolOptionsPropertyBrowser::ChangeDataToolTriangle(VProperty *property)
|
||||||
{
|
{
|
||||||
|
@ -1818,6 +1860,17 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolSplinePath(QGraphicsItem *item)
|
||||||
AddPropertyLineColor(i, tr("Color"), VAbstractTool::ColorsList(), AttrColor);
|
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)
|
void VToolOptionsPropertyBrowser::ShowOptionsToolTriangle(QGraphicsItem *item)
|
||||||
{
|
{
|
||||||
|
@ -2253,6 +2306,15 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSplinePath()
|
||||||
idToProperty[AttrColor]->setValue(VLineColorProperty::IndexOfColor(VAbstractTool::ColorsList(), i->GetLineColor()));
|
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()
|
void VToolOptionsPropertyBrowser::UpdateOptionsToolTriangle()
|
||||||
{
|
{
|
||||||
|
|
|
@ -140,6 +140,7 @@ private:
|
||||||
void ChangeDataToolSpline(VPE::VProperty *property);
|
void ChangeDataToolSpline(VPE::VProperty *property);
|
||||||
void ChangeDataToolCubicBezier(VPE::VProperty *property);
|
void ChangeDataToolCubicBezier(VPE::VProperty *property);
|
||||||
void ChangeDataToolSplinePath(VPE::VProperty *property);
|
void ChangeDataToolSplinePath(VPE::VProperty *property);
|
||||||
|
void ChangeDataToolCubicBezierPath(VPE::VProperty *property);
|
||||||
void ChangeDataToolTriangle(VPE::VProperty *property);
|
void ChangeDataToolTriangle(VPE::VProperty *property);
|
||||||
void ChangeDataToolLineIntersectAxis(VPE::VProperty *property);
|
void ChangeDataToolLineIntersectAxis(VPE::VProperty *property);
|
||||||
void ChangeDataToolCurveIntersectAxis(VPE::VProperty *property);
|
void ChangeDataToolCurveIntersectAxis(VPE::VProperty *property);
|
||||||
|
@ -169,6 +170,7 @@ private:
|
||||||
void ShowOptionsToolSpline(QGraphicsItem *item);
|
void ShowOptionsToolSpline(QGraphicsItem *item);
|
||||||
void ShowOptionsToolCubicBezier(QGraphicsItem *item);
|
void ShowOptionsToolCubicBezier(QGraphicsItem *item);
|
||||||
void ShowOptionsToolSplinePath(QGraphicsItem *item);
|
void ShowOptionsToolSplinePath(QGraphicsItem *item);
|
||||||
|
void ShowOptionsToolCubicBezierPath(QGraphicsItem *item);
|
||||||
void ShowOptionsToolTriangle(QGraphicsItem *item);
|
void ShowOptionsToolTriangle(QGraphicsItem *item);
|
||||||
void ShowOptionsToolLineIntersectAxis(QGraphicsItem *item);
|
void ShowOptionsToolLineIntersectAxis(QGraphicsItem *item);
|
||||||
void ShowOptionsToolCurveIntersectAxis(QGraphicsItem *item);
|
void ShowOptionsToolCurveIntersectAxis(QGraphicsItem *item);
|
||||||
|
@ -198,6 +200,7 @@ private:
|
||||||
void UpdateOptionsToolSpline();
|
void UpdateOptionsToolSpline();
|
||||||
void UpdateOptionsToolCubicBezier();
|
void UpdateOptionsToolCubicBezier();
|
||||||
void UpdateOptionsToolSplinePath();
|
void UpdateOptionsToolSplinePath();
|
||||||
|
void UpdateOptionsToolCubicBezierPath();
|
||||||
void UpdateOptionsToolTriangle();
|
void UpdateOptionsToolTriangle();
|
||||||
void UpdateOptionsToolLineIntersectAxis();
|
void UpdateOptionsToolLineIntersectAxis();
|
||||||
void UpdateOptionsToolCurveIntersectAxis();
|
void UpdateOptionsToolCurveIntersectAxis();
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "../vgeometry/varc.h"
|
#include "../vgeometry/varc.h"
|
||||||
#include "../vgeometry/vcubicbezier.h"
|
#include "../vgeometry/vcubicbezier.h"
|
||||||
#include "../vgeometry/vsplinepath.h"
|
#include "../vgeometry/vsplinepath.h"
|
||||||
|
#include "../vgeometry/vcubicbezierpath.h"
|
||||||
#include "../vgeometry/vpointf.h"
|
#include "../vgeometry/vpointf.h"
|
||||||
#include "../vtools/tools/vabstracttool.h"
|
#include "../vtools/tools/vabstracttool.h"
|
||||||
#include "../vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h"
|
#include "../vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h"
|
||||||
|
@ -162,7 +163,7 @@ void DialogHistory::FillTable()
|
||||||
{
|
{
|
||||||
const VToolRecord tool = history.at(i);
|
const VToolRecord tool = history.at(i);
|
||||||
const QString historyRecord = Record(tool);
|
const QString historyRecord = Record(tool);
|
||||||
if (historyRecord.isEmpty() ==false)
|
if (not historyRecord.isEmpty())
|
||||||
{
|
{
|
||||||
currentRow++;
|
currentRow++;
|
||||||
|
|
||||||
|
@ -194,12 +195,11 @@ void DialogHistory::FillTable()
|
||||||
ui->tableWidget->verticalHeader()->setDefaultSectionSize(20);
|
ui->tableWidget->verticalHeader()->setDefaultSectionSize(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
#if defined(Q_CC_GNU)
|
#if defined(Q_CC_GNU)
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wswitch-default"
|
#pragma GCC diagnostic ignored "-Wswitch-default"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
/**
|
||||||
* @brief Record return description for record
|
* @brief Record return description for record
|
||||||
* @param tool record data
|
* @param tool record data
|
||||||
|
@ -208,7 +208,7 @@ void DialogHistory::FillTable()
|
||||||
QString DialogHistory::Record(const VToolRecord &tool)
|
QString DialogHistory::Record(const VToolRecord &tool)
|
||||||
{
|
{
|
||||||
// This check helps to find missed tools in the switch
|
// This check helps to find missed tools in the switch
|
||||||
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 40, "Not all tools was used in history.");
|
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in history.");
|
||||||
|
|
||||||
const QDomElement domElem = doc->elementById(tool.getId());
|
const QDomElement domElem = doc->elementById(tool.getId());
|
||||||
if (domElem.isElement() == false)
|
if (domElem.isElement() == false)
|
||||||
|
@ -268,49 +268,39 @@ QString DialogHistory::Record(const VToolRecord &tool)
|
||||||
{
|
{
|
||||||
const QSharedPointer<VSpline> spl = data->GeometricObject<VSpline>(tool.getId());
|
const QSharedPointer<VSpline> spl = data->GeometricObject<VSpline>(tool.getId());
|
||||||
SCASSERT(spl != nullptr);
|
SCASSERT(spl != nullptr);
|
||||||
return QString(tr("Curve %1_%2")).arg(PointName(spl->GetP1().id())).arg(PointName(spl->GetP4().id()));
|
return spl->NameForHistory(tr("Curve"));
|
||||||
}
|
}
|
||||||
case Tool::CubicBezier:
|
case Tool::CubicBezier:
|
||||||
{
|
{
|
||||||
const QSharedPointer<VCubicBezier> spl = data->GeometricObject<VCubicBezier>(tool.getId());
|
const QSharedPointer<VCubicBezier> spl = data->GeometricObject<VCubicBezier>(tool.getId());
|
||||||
SCASSERT(spl != nullptr);
|
SCASSERT(spl != nullptr);
|
||||||
return QString(tr("Cubic bezier curve %1_%2")).arg(PointName(spl->GetP1().id()))
|
return spl->NameForHistory(tr("Cubic bezier curve"));
|
||||||
.arg(PointName(spl->GetP4().id()));
|
|
||||||
}
|
}
|
||||||
case Tool::Arc:
|
case Tool::Arc:
|
||||||
{
|
{
|
||||||
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(tool.getId());
|
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(tool.getId());
|
||||||
SCASSERT(arc != nullptr);
|
SCASSERT(arc != nullptr);
|
||||||
return QString(tr("Arc with center in point %1")).arg(PointName(arc->GetCenter().id()));
|
return arc->NameForHistory(tr("Arc"));
|
||||||
}
|
}
|
||||||
case Tool::ArcWithLength:
|
case Tool::ArcWithLength:
|
||||||
{
|
{
|
||||||
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(tool.getId());
|
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(tool.getId());
|
||||||
SCASSERT(arc != nullptr);
|
SCASSERT(arc != nullptr);
|
||||||
return QString(tr("Arc with center in point %1 and length %2")).arg(PointName(arc->GetCenter().id()))
|
return QString(tr("%1 with length %2"))
|
||||||
|
.arg(arc->NameForHistory(tr("Arc")))
|
||||||
.arg(arc->GetLength());
|
.arg(arc->GetLength());
|
||||||
}
|
}
|
||||||
case Tool::SplinePath:
|
case Tool::SplinePath:
|
||||||
{
|
{
|
||||||
const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(tool.getId());
|
const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(tool.getId());
|
||||||
SCASSERT(splPath != nullptr);
|
SCASSERT(splPath != nullptr);
|
||||||
const QVector<VSplinePoint> points = splPath->GetSplinePath();
|
return splPath->NameForHistory(tr("Spline path"));
|
||||||
QString record;
|
}
|
||||||
if (points.size() != 0 )
|
case Tool::CubicBezierPath:
|
||||||
{
|
{
|
||||||
// We use only first and last point name in curve
|
const QSharedPointer<VCubicBezierPath> splPath = data->GeometricObject<VCubicBezierPath>(tool.getId());
|
||||||
record = QString(tr("Curve point %1")).arg(PointName(points.at(0).P().id()));
|
SCASSERT(splPath != nullptr);
|
||||||
if (points.size() > 1)
|
return splPath->NameForHistory(tr("Cubic bezier curve path"));
|
||||||
{
|
|
||||||
record.append(QString("_%1").arg(PointName(points.last().P().id())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug()<<"Not enough points in splinepath"<<Q_FUNC_INFO;
|
|
||||||
return tr("Can't create record.");
|
|
||||||
}
|
|
||||||
return record;
|
|
||||||
}
|
}
|
||||||
case Tool::PointOfContact:
|
case Tool::PointOfContact:
|
||||||
return QString(tr("%4 - point of contact of arc with the center in point %1 and line %2_%3"))
|
return QString(tr("%4 - point of contact of arc with the center in point %1 and line %2_%3"))
|
||||||
|
@ -338,43 +328,27 @@ QString DialogHistory::Record(const VToolRecord &tool)
|
||||||
{
|
{
|
||||||
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(AttrUInt(domElem, AttrArc));
|
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(AttrUInt(domElem, AttrArc));
|
||||||
SCASSERT(arc != nullptr);
|
SCASSERT(arc != nullptr);
|
||||||
return QString(tr("%1 - cut arc with center %2"))
|
return QString(tr("%1 - cut %2"))
|
||||||
.arg(PointName(tool.getId()))
|
.arg(PointName(tool.getId()))
|
||||||
.arg(PointName(arc->GetCenter().id()));
|
.arg(arc->NameForHistory(tr("arc")));
|
||||||
}
|
}
|
||||||
case Tool::CutSpline:
|
case Tool::CutSpline:
|
||||||
{
|
{
|
||||||
const quint32 splineId = AttrUInt(domElem, VToolCutSpline::AttrSpline);
|
const quint32 splineId = AttrUInt(domElem, VToolCutSpline::AttrSpline);
|
||||||
const QSharedPointer<VSpline> spl = data->GeometricObject<VSpline>(splineId);
|
const QSharedPointer<VSpline> spl = data->GeometricObject<VSpline>(splineId);
|
||||||
SCASSERT(spl != nullptr);
|
SCASSERT(spl != nullptr);
|
||||||
return QString(tr("%1 - cut curve %2_%3"))
|
return QString(tr("%1 - cut %2"))
|
||||||
.arg(PointName(tool.getId()))
|
.arg(PointName(tool.getId()))
|
||||||
.arg(PointName(spl->GetP1().id()))
|
.arg(spl->NameForHistory(tr("curve")));
|
||||||
.arg(PointName(spl->GetP4().id()));
|
|
||||||
}
|
}
|
||||||
case Tool::CutSplinePath:
|
case Tool::CutSplinePath:
|
||||||
{
|
{
|
||||||
const quint32 splinePathId = AttrUInt(domElem, VToolCutSplinePath::AttrSplinePath);
|
const quint32 splinePathId = AttrUInt(domElem, VToolCutSplinePath::AttrSplinePath);
|
||||||
const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(splinePathId);
|
const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(splinePathId);
|
||||||
SCASSERT(splPath != nullptr);
|
SCASSERT(splPath != nullptr);
|
||||||
const QVector<VSplinePoint> points = splPath->GetSplinePath();
|
return QString(tr("%1 - cut %2"))
|
||||||
QString record;
|
.arg(PointName(tool.getId()))
|
||||||
if (points.size() != 0 )
|
.arg(splPath->NameForHistory(tr("curve path")));
|
||||||
{
|
|
||||||
record = QString(tr("%1 - cut curve path %2"))
|
|
||||||
.arg(PointName(tool.getId()))
|
|
||||||
.arg(PointName(points.at(0).P().id()));
|
|
||||||
if (points.size() > 1)
|
|
||||||
{
|
|
||||||
record.append(QString("_%1").arg(PointName(points.last().P().id())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug()<<"Not enough points in splinepath"<<Q_FUNC_INFO;
|
|
||||||
return QString(tr("Can't create record."));
|
|
||||||
}
|
|
||||||
return record;
|
|
||||||
}
|
}
|
||||||
case Tool::LineIntersectAxis:
|
case Tool::LineIntersectAxis:
|
||||||
return QString(tr("%1 - point of intersection line %2_%3 and axis through point %4"))
|
return QString(tr("%1 - point of intersection line %2_%3 and axis through point %4"))
|
||||||
|
@ -409,7 +383,7 @@ QString DialogHistory::Record(const VToolRecord &tool)
|
||||||
case Tool::NodePoint:
|
case Tool::NodePoint:
|
||||||
case Tool::NodeSpline:
|
case Tool::NodeSpline:
|
||||||
case Tool::NodeSplinePath:
|
case Tool::NodeSplinePath:
|
||||||
break;
|
return QString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const VExceptionBadId &e)
|
catch (const VExceptionBadId &e)
|
||||||
|
|
|
@ -830,6 +830,16 @@ void MainWindow::ToolSplinePath(bool checked)
|
||||||
&MainWindow::ApplyDialog<VToolSplinePath>);
|
&MainWindow::ApplyDialog<VToolSplinePath>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
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>);
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief ToolCutSplinePath handler tool CutSplinePath.
|
* @brief ToolCutSplinePath handler tool CutSplinePath.
|
||||||
|
@ -1615,6 +1625,7 @@ void MainWindow::InitToolButtons()
|
||||||
connect(ui->toolButtonCubicBezier, &QToolButton::clicked, this, &MainWindow::ToolCubicBezier);
|
connect(ui->toolButtonCubicBezier, &QToolButton::clicked, this, &MainWindow::ToolCubicBezier);
|
||||||
connect(ui->toolButtonArc, &QToolButton::clicked, this, &MainWindow::ToolArc);
|
connect(ui->toolButtonArc, &QToolButton::clicked, this, &MainWindow::ToolArc);
|
||||||
connect(ui->toolButtonSplinePath, &QToolButton::clicked, this, &MainWindow::ToolSplinePath);
|
connect(ui->toolButtonSplinePath, &QToolButton::clicked, this, &MainWindow::ToolSplinePath);
|
||||||
|
connect(ui->toolButtonCubicBezierPath, &QToolButton::clicked, this, &MainWindow::ToolCubicBezierPath);
|
||||||
connect(ui->toolButtonPointOfContact, &QToolButton::clicked, this, &MainWindow::ToolPointOfContact);
|
connect(ui->toolButtonPointOfContact, &QToolButton::clicked, this, &MainWindow::ToolPointOfContact);
|
||||||
connect(ui->toolButtonNewDetail, &QToolButton::clicked, this, &MainWindow::ToolDetail);
|
connect(ui->toolButtonNewDetail, &QToolButton::clicked, this, &MainWindow::ToolDetail);
|
||||||
connect(ui->toolButtonHeight, &QToolButton::clicked, this, &MainWindow::ToolHeight);
|
connect(ui->toolButtonHeight, &QToolButton::clicked, this, &MainWindow::ToolHeight);
|
||||||
|
@ -1669,11 +1680,18 @@ void MainWindow::mouseMove(const QPointF &scenePos)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
#if defined(Q_CC_GNU)
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wswitch-default"
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* @brief CancelTool cancel tool.
|
* @brief CancelTool cancel tool.
|
||||||
*/
|
*/
|
||||||
void MainWindow::CancelTool()
|
void MainWindow::CancelTool()
|
||||||
{
|
{
|
||||||
|
// 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 handled.");
|
||||||
|
|
||||||
qCDebug(vMainWindow, "Canceling tool.");
|
qCDebug(vMainWindow, "Canceling tool.");
|
||||||
delete dialogTool;
|
delete dialogTool;
|
||||||
dialogTool = nullptr;
|
dialogTool = nullptr;
|
||||||
|
@ -1692,6 +1710,16 @@ void MainWindow::CancelTool()
|
||||||
redoAction->setEnabled(false);
|
redoAction->setEnabled(false);
|
||||||
return;
|
return;
|
||||||
case Tool::BasePoint:
|
case Tool::BasePoint:
|
||||||
|
case Tool::SinglePoint:
|
||||||
|
case Tool::DoublePoint:
|
||||||
|
case Tool::LinePoint:
|
||||||
|
case Tool::AbstractSpline:
|
||||||
|
case Tool::Cut:
|
||||||
|
case Tool::LAST_ONE_DO_NOT_USE:
|
||||||
|
case Tool::NodePoint:
|
||||||
|
case Tool::NodeArc:
|
||||||
|
case Tool::NodeSpline:
|
||||||
|
case Tool::NodeSplinePath:
|
||||||
Q_UNREACHABLE(); //-V501
|
Q_UNREACHABLE(); //-V501
|
||||||
//Nothing to do here because we can't create this tool from main window.
|
//Nothing to do here because we can't create this tool from main window.
|
||||||
break;
|
break;
|
||||||
|
@ -1731,6 +1759,9 @@ void MainWindow::CancelTool()
|
||||||
case Tool::SplinePath:
|
case Tool::SplinePath:
|
||||||
ui->toolButtonSplinePath->setChecked(false);
|
ui->toolButtonSplinePath->setChecked(false);
|
||||||
break;
|
break;
|
||||||
|
case Tool::CubicBezierPath:
|
||||||
|
ui->toolButtonCubicBezierPath->setChecked(false);
|
||||||
|
break;
|
||||||
case Tool::PointOfContact:
|
case Tool::PointOfContact:
|
||||||
ui->toolButtonPointOfContact->setChecked(false);
|
ui->toolButtonPointOfContact->setChecked(false);
|
||||||
break;
|
break;
|
||||||
|
@ -1783,13 +1814,6 @@ void MainWindow::CancelTool()
|
||||||
case Tool::TrueDarts:
|
case Tool::TrueDarts:
|
||||||
ui->toolButtonTrueDarts->setChecked(false);
|
ui->toolButtonTrueDarts->setChecked(false);
|
||||||
break;
|
break;
|
||||||
case Tool::NodePoint:
|
|
||||||
case Tool::NodeArc:
|
|
||||||
case Tool::NodeSpline:
|
|
||||||
case Tool::NodeSplinePath:
|
|
||||||
default:
|
|
||||||
qDebug()<<"Got wrong tool type. Ignored.";
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
currentScene->setFocus(Qt::OtherFocusReason);
|
currentScene->setFocus(Qt::OtherFocusReason);
|
||||||
currentScene->clearSelection();
|
currentScene->clearSelection();
|
||||||
|
@ -1801,6 +1825,10 @@ void MainWindow::CancelTool()
|
||||||
redoAction->setEnabled(qApp->getUndoStack()->canRedo());
|
redoAction->setEnabled(qApp->getUndoStack()->canRedo());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(Q_CC_GNU)
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief ArrowTool enable arrow tool.
|
* @brief ArrowTool enable arrow tool.
|
||||||
|
@ -2949,6 +2977,7 @@ void MainWindow::SetEnableTool(bool enable)
|
||||||
ui->toolButtonCubicBezier->setEnabled(drawTools);
|
ui->toolButtonCubicBezier->setEnabled(drawTools);
|
||||||
ui->toolButtonArc->setEnabled(drawTools);
|
ui->toolButtonArc->setEnabled(drawTools);
|
||||||
ui->toolButtonSplinePath->setEnabled(drawTools);
|
ui->toolButtonSplinePath->setEnabled(drawTools);
|
||||||
|
ui->toolButtonCubicBezierPath->setEnabled(drawTools);
|
||||||
ui->toolButtonPointOfContact->setEnabled(drawTools);
|
ui->toolButtonPointOfContact->setEnabled(drawTools);
|
||||||
ui->toolButtonNewDetail->setEnabled(drawTools);
|
ui->toolButtonNewDetail->setEnabled(drawTools);
|
||||||
ui->toolButtonHeight->setEnabled(drawTools);
|
ui->toolButtonHeight->setEnabled(drawTools);
|
||||||
|
@ -3233,8 +3262,16 @@ void MainWindow::CreateMenus()
|
||||||
AddDocks();
|
AddDocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
#if defined(Q_CC_GNU)
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wswitch-default"
|
||||||
|
#endif
|
||||||
void MainWindow::LastUsedTool()
|
void MainWindow::LastUsedTool()
|
||||||
{
|
{
|
||||||
|
// 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 handled.");
|
||||||
|
|
||||||
if (currentTool == lastUsedTool)
|
if (currentTool == lastUsedTool)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -3247,6 +3284,16 @@ void MainWindow::LastUsedTool()
|
||||||
ArrowTool();
|
ArrowTool();
|
||||||
break;
|
break;
|
||||||
case Tool::BasePoint:
|
case Tool::BasePoint:
|
||||||
|
case Tool::SinglePoint:
|
||||||
|
case Tool::DoublePoint:
|
||||||
|
case Tool::LinePoint:
|
||||||
|
case Tool::AbstractSpline:
|
||||||
|
case Tool::Cut:
|
||||||
|
case Tool::LAST_ONE_DO_NOT_USE:
|
||||||
|
case Tool::NodePoint:
|
||||||
|
case Tool::NodeArc:
|
||||||
|
case Tool::NodeSpline:
|
||||||
|
case Tool::NodeSplinePath:
|
||||||
Q_UNREACHABLE(); //-V501
|
Q_UNREACHABLE(); //-V501
|
||||||
//Nothing to do here because we can't create this tool from main window.
|
//Nothing to do here because we can't create this tool from main window.
|
||||||
break;
|
break;
|
||||||
|
@ -3282,6 +3329,10 @@ void MainWindow::LastUsedTool()
|
||||||
ui->toolButtonSpline->setChecked(true);
|
ui->toolButtonSpline->setChecked(true);
|
||||||
ToolSpline(true);
|
ToolSpline(true);
|
||||||
break;
|
break;
|
||||||
|
case Tool::CubicBezier:
|
||||||
|
ui->toolButtonCubicBezier->setChecked(true);
|
||||||
|
ToolCubicBezier(true);
|
||||||
|
break;
|
||||||
case Tool::Arc:
|
case Tool::Arc:
|
||||||
ui->toolButtonArc->setChecked(true);
|
ui->toolButtonArc->setChecked(true);
|
||||||
ToolArc(true);
|
ToolArc(true);
|
||||||
|
@ -3290,6 +3341,10 @@ void MainWindow::LastUsedTool()
|
||||||
ui->toolButtonSplinePath->setChecked(true);
|
ui->toolButtonSplinePath->setChecked(true);
|
||||||
ToolSplinePath(true);
|
ToolSplinePath(true);
|
||||||
break;
|
break;
|
||||||
|
case Tool::CubicBezierPath:
|
||||||
|
ui->toolButtonCubicBezierPath->setChecked(true);
|
||||||
|
ToolCubicBezierPath(true);
|
||||||
|
break;
|
||||||
case Tool::PointOfContact:
|
case Tool::PointOfContact:
|
||||||
ui->toolButtonPointOfContact->setChecked(true);
|
ui->toolButtonPointOfContact->setChecked(true);
|
||||||
ToolPointOfContact(true);
|
ToolPointOfContact(true);
|
||||||
|
@ -3362,16 +3417,13 @@ void MainWindow::LastUsedTool()
|
||||||
ui->toolButtonTrueDarts->setChecked(true);
|
ui->toolButtonTrueDarts->setChecked(true);
|
||||||
ToolTrueDarts(true);
|
ToolTrueDarts(true);
|
||||||
break;
|
break;
|
||||||
case Tool::NodePoint:
|
|
||||||
case Tool::NodeArc:
|
|
||||||
case Tool::NodeSpline:
|
|
||||||
case Tool::NodeSplinePath:
|
|
||||||
default:
|
|
||||||
qDebug()<<"Got wrong tool type. Ignored.";
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(Q_CC_GNU)
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void MainWindow::AddDocks()
|
void MainWindow::AddDocks()
|
||||||
{
|
{
|
||||||
|
|
|
@ -112,6 +112,7 @@ public slots:
|
||||||
void ToolCutSpline(bool checked);
|
void ToolCutSpline(bool checked);
|
||||||
void ToolArc(bool checked);
|
void ToolArc(bool checked);
|
||||||
void ToolSplinePath(bool checked);
|
void ToolSplinePath(bool checked);
|
||||||
|
void ToolCubicBezierPath(bool checked);
|
||||||
void ToolCutSplinePath(bool checked);
|
void ToolCutSplinePath(bool checked);
|
||||||
void ToolPointOfContact(bool checked);
|
void ToolPointOfContact(bool checked);
|
||||||
void ToolDetail(bool checked);
|
void ToolDetail(bool checked);
|
||||||
|
|
|
@ -618,7 +618,33 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="3" column="0">
|
||||||
|
<widget class="QToolButton" name="toolButtonIntersectionCurves">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Point intersection curves</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">...</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="share/resources/toolicon.qrc">
|
||||||
|
<normaloff>:/toolicon/32x32/intersection_curves.png</normaloff>:/toolicon/32x32/intersection_curves.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>32</width>
|
||||||
|
<height>32</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
<widget class="QToolButton" name="toolButtonCurveIntersectAxis">
|
<widget class="QToolButton" name="toolButtonCurveIntersectAxis">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
|
@ -644,20 +670,17 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="2" column="1">
|
||||||
<widget class="QToolButton" name="toolButtonIntersectionCurves">
|
<widget class="QToolButton" name="toolButtonCubicBezierPath">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
|
||||||
<string>Point intersection curves</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string notr="true">...</string>
|
<string notr="true">...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="share/resources/toolicon.qrc">
|
<iconset resource="share/resources/toolicon.qrc">
|
||||||
<normaloff>:/toolicon/32x32/intersection_curves.png</normaloff>:/toolicon/32x32/intersection_curves.png</iconset>
|
<normaloff>:/toolicon/32x32/cubic_bezier_path.png</normaloff>:/toolicon/32x32/cubic_bezier_path.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
<size>
|
<size>
|
||||||
|
|
|
@ -62,5 +62,7 @@
|
||||||
<file>cursor/intersection_curves_cursor@2x.png</file>
|
<file>cursor/intersection_curves_cursor@2x.png</file>
|
||||||
<file>cursor/cubic_bezier_cursor.png</file>
|
<file>cursor/cubic_bezier_cursor.png</file>
|
||||||
<file>cursor/cubic_bezier_cursor@2x.png</file>
|
<file>cursor/cubic_bezier_cursor@2x.png</file>
|
||||||
|
<file>cursor/cubic_bezier_path_cursor.png</file>
|
||||||
|
<file>cursor/cubic_bezier_path_cursor@2x.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
Before Width: | Height: | Size: 644 B After Width: | Height: | Size: 676 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 2.2 KiB |
|
@ -60,5 +60,7 @@
|
||||||
<file>toolicon/32x32/intersection_curves@2x.png</file>
|
<file>toolicon/32x32/intersection_curves@2x.png</file>
|
||||||
<file>toolicon/32x32/cubic_bezier.png</file>
|
<file>toolicon/32x32/cubic_bezier.png</file>
|
||||||
<file>toolicon/32x32/cubic_bezier@2x.png</file>
|
<file>toolicon/32x32/cubic_bezier@2x.png</file>
|
||||||
|
<file>toolicon/32x32/cubic_bezier_path.png</file>
|
||||||
|
<file>toolicon/32x32/cubic_bezier_path@2x.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
Before Width: | Height: | Size: 895 B After Width: | Height: | Size: 1007 B |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 4.1 KiB |
|
@ -32,7 +32,7 @@
|
||||||
id="namedview12"
|
id="namedview12"
|
||||||
showgrid="false"
|
showgrid="false"
|
||||||
inkscape:zoom="14.75"
|
inkscape:zoom="14.75"
|
||||||
inkscape:cx="-5.7288133"
|
inkscape:cx="-4.3389831"
|
||||||
inkscape:cy="12.164845"
|
inkscape:cy="12.164845"
|
||||||
inkscape:window-x="65"
|
inkscape:window-x="65"
|
||||||
inkscape:window-y="24"
|
inkscape:window-y="24"
|
||||||
|
@ -60,11 +60,25 @@
|
||||||
id="path4205"
|
id="path4205"
|
||||||
inkscape:connector-curvature="0"
|
inkscape:connector-curvature="0"
|
||||||
sodipodi:nodetypes="cc" />
|
sodipodi:nodetypes="cc" />
|
||||||
|
<path
|
||||||
|
style="fill:none;fill-rule:evenodd;stroke:#009b05;stroke-width:0.9413439px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||||
|
d="M 7.8321193,10.281061 2.8797451,24.024024"
|
||||||
|
id="path3401"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cc" />
|
||||||
<path
|
<path
|
||||||
d="m 4.6965534,23.856149 a 1.8239208,1.9086996 0 0 1 -3.6478415,0 1.8239208,1.9086996 0 1 1 3.6478415,0 z"
|
d="m 4.6965534,23.856149 a 1.8239208,1.9086996 0 0 1 -3.6478415,0 1.8239208,1.9086996 0 1 1 3.6478415,0 z"
|
||||||
id="path2985-2-9"
|
id="path2985-2-9"
|
||||||
style="fill:#000000;fill-opacity:1;stroke:#370000;stroke-width:1.57200003;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.93950177"
|
style="fill:#000000;fill-opacity:1;stroke:#370000;stroke-width:1.57200003;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.93950177"
|
||||||
inkscape:connector-curvature="0" />
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="fill:none;fill-rule:evenodd;stroke:#009b05;stroke-width:0.9413439px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||||
|
d="M 29.052458,7.8742813 23.150931,22.024024"
|
||||||
|
id="path3401-9"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cc"
|
||||||
|
inkscape:transform-center-x="0.88135593"
|
||||||
|
inkscape:transform-center-y="-6.779661" />
|
||||||
<path
|
<path
|
||||||
inkscape:connector-curvature="0"
|
inkscape:connector-curvature="0"
|
||||||
style="fill:#000000;fill-opacity:1;stroke:#370000;stroke-width:1.57200003;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.93950177"
|
style="fill:#000000;fill-opacity:1;stroke:#370000;stroke-width:1.57200003;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.93950177"
|
||||||
|
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 4.2 KiB |
|
@ -0,0 +1,134 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
version="1.1"
|
||||||
|
width="32"
|
||||||
|
height="32"
|
||||||
|
id="svg3837"
|
||||||
|
inkscape:version="0.91 r"
|
||||||
|
sodipodi:docname="cubic_bezier_path.svg"
|
||||||
|
inkscape:export-filename="splinePath_cut_point@2x.png"
|
||||||
|
inkscape:export-xdpi="180"
|
||||||
|
inkscape:export-ydpi="180">
|
||||||
|
<sodipodi:namedview
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1"
|
||||||
|
objecttolerance="10"
|
||||||
|
gridtolerance="10"
|
||||||
|
guidetolerance="10"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:window-width="1855"
|
||||||
|
inkscape:window-height="1056"
|
||||||
|
id="namedview12"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:zoom="14.75"
|
||||||
|
inkscape:cx="2.4143977"
|
||||||
|
inkscape:cy="20.543065"
|
||||||
|
inkscape:window-x="65"
|
||||||
|
inkscape:window-y="24"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="layer1" />
|
||||||
|
<defs
|
||||||
|
id="defs3839" />
|
||||||
|
<metadata
|
||||||
|
id="metadata3842">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title />
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
id="layer1">
|
||||||
|
<path
|
||||||
|
style="fill:none;fill-rule:evenodd;stroke:#f73208;stroke-width:1.88268781;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
d="M 3.112883,10.764601 C 6.3916001,14.586244 5.7887323,31.249436 15.358034,26.006531 24.457447,21.021076 6.3049089,9.5946777 16.283414,5.899158 28.412506,1.4071725 21.858311,19.768822 28.488188,24.091485"
|
||||||
|
id="path4205"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cssc" />
|
||||||
|
<path
|
||||||
|
style="fill:none;fill-rule:evenodd;stroke:#009b05;stroke-width:0.9413439px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||||
|
d="m 3.3869492,11.080403 0.064486,6.821344"
|
||||||
|
id="path3401"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
d="m 5.0812691,11.009551 a 1.7348604,1.77818 0 0 1 -3.4697207,0 1.7348604,1.77818 0 1 1 3.4697207,0 z"
|
||||||
|
id="path2985-2-9"
|
||||||
|
style="fill:#000000;fill-opacity:1;stroke:#370000;stroke-width:1.47979271;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.93950177"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="fill:none;fill-rule:evenodd;stroke:#009b05;stroke-width:0.9413439px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||||
|
d="M 28.601037,24.470447 22.02345,15.88061"
|
||||||
|
id="path3407"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#000000;fill-opacity:1;stroke:#370000;stroke-width:1.47979271;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.93950177"
|
||||||
|
id="path4199"
|
||||||
|
d="m 30.166385,24.210111 a 1.7348605,1.7781801 0 1 0 -3.46972,0 1.7348605,1.7781801 0 0 0 3.46972,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:none;fill-rule:evenodd;stroke:#009b05;stroke-width:0.9413439px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||||
|
d="M 7.06266,29.712775 22.087936,22.765112"
|
||||||
|
id="path3403"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
d="m 17.140181,25.978608 a 1.7348606,1.7781802 0 1 0 -3.469721,0 1.7348606,1.7781802 0 0 0 3.469721,0 z"
|
||||||
|
id="path4201"
|
||||||
|
style="fill:#000000;fill-opacity:1;stroke:#370000;stroke-width:1.47979271;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.93950177"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="fill:none;fill-rule:evenodd;stroke:#009b05;stroke-width:0.9413439px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||||
|
d="M 9.2551899,9.3750691 23.442144,2.7432084"
|
||||||
|
id="path3405"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#000000;fill-opacity:1;stroke:#370000;stroke-width:1.47979271;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.93950177"
|
||||||
|
id="path4203"
|
||||||
|
d="m 17.978501,6.019865 a 1.7348606,1.7781801 0 1 0 -3.469721,0 1.7348606,1.7781801 0 0 0 3.469721,0 z" />
|
||||||
|
<path
|
||||||
|
d="m 5.0573234,17.743977 a 1.7348604,1.7781801 0 0 1 -3.4697207,0 1.7348604,1.7781801 0 1 1 3.4697207,0 z"
|
||||||
|
id="path2985-2-9-6"
|
||||||
|
style="fill:#000000;fill-opacity:1;stroke:#370000;stroke-width:1.47979271;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.93950177"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
d="m 8.7975206,29.397105 a 1.7348605,1.7781805 0 1 0 -3.4697211,0 1.7348605,1.7781805 0 0 0 3.4697211,0 z"
|
||||||
|
id="path4201-2"
|
||||||
|
style="fill:#000000;fill-opacity:1;stroke:#370000;stroke-width:1.47979271;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.93950177"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
d="m 24.016255,22.638923 a 1.7348606,1.7781801 0 1 0 -3.46972,0 1.7348606,1.7781801 0 0 0 3.46972,0 z"
|
||||||
|
id="path4201-3"
|
||||||
|
style="fill:#000000;fill-opacity:1;stroke:#370000;stroke-width:1.47979271;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.93950177"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#000000;fill-opacity:1;stroke:#370000;stroke-width:1.47979271;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.93950177"
|
||||||
|
id="path4203-3"
|
||||||
|
d="m 10.99005,9.2488796 a 1.7348605,1.7781801 0 1 0 -3.4697206,0 1.7348605,1.7781801 0 0 0 3.4697206,0 z" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#000000;fill-opacity:1;stroke:#370000;stroke-width:1.47979271;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.93950177"
|
||||||
|
id="path4203-35"
|
||||||
|
d="m 25.112519,2.8065007 a 1.734861,1.7781806 0 1 0 -3.469722,0 1.734861,1.7781806 0 0 0 3.469722,0 z" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#000000;fill-opacity:1;stroke:#370000;stroke-width:1.47979271;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.93950177"
|
||||||
|
id="path4203-0"
|
||||||
|
d="m 23.822796,15.880741 a 1.7348606,1.7781801 0 1 0 -3.469721,0 1.7348606,1.7781801 0 0 0 3.469721,0 z" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 6.9 KiB |
|
@ -44,6 +44,7 @@
|
||||||
#include "../vgeometry/varc.h"
|
#include "../vgeometry/varc.h"
|
||||||
#include "../vgeometry/vsplinepath.h"
|
#include "../vgeometry/vsplinepath.h"
|
||||||
#include "../vgeometry/vcubicbezier.h"
|
#include "../vgeometry/vcubicbezier.h"
|
||||||
|
#include "../vgeometry/vcubicbezierpath.h"
|
||||||
#include "../core/vapplication.h"
|
#include "../core/vapplication.h"
|
||||||
#include "../vpatterndb/calculator.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)
|
void VPattern::ParseNodeSpline(const QDomElement &domElement, const Document &parse)
|
||||||
{
|
{
|
||||||
|
@ -2425,13 +2478,14 @@ void VPattern::ParseSplineElement(VMainGraphicsScene *scene, QDomElement &domEle
|
||||||
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
||||||
Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty");
|
Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty");
|
||||||
|
|
||||||
QStringList splines = QStringList() << VToolSpline::OldToolType /*0*/
|
QStringList splines = QStringList() << VToolSpline::OldToolType /*0*/
|
||||||
<< VToolSpline::ToolType /*1*/
|
<< VToolSpline::ToolType /*1*/
|
||||||
<< VToolSplinePath::OldToolType /*2*/
|
<< VToolSplinePath::OldToolType /*2*/
|
||||||
<< VToolSplinePath::ToolType /*3*/
|
<< VToolSplinePath::ToolType /*3*/
|
||||||
<< VNodeSpline::ToolType /*4*/
|
<< VNodeSpline::ToolType /*4*/
|
||||||
<< VNodeSplinePath::ToolType /*5*/
|
<< VNodeSplinePath::ToolType /*5*/
|
||||||
<< VToolCubicBezier::ToolType; /*6*/
|
<< VToolCubicBezier::ToolType /*6*/
|
||||||
|
<< VToolCubicBezierPath::ToolType; /*7*/
|
||||||
switch (splines.indexOf(type))
|
switch (splines.indexOf(type))
|
||||||
{
|
{
|
||||||
case 0: //VToolSpline::OldToolType
|
case 0: //VToolSpline::OldToolType
|
||||||
|
@ -2462,6 +2516,10 @@ void VPattern::ParseSplineElement(VMainGraphicsScene *scene, QDomElement &domEle
|
||||||
qCDebug(vXML, "VToolCubicBezier.");
|
qCDebug(vXML, "VToolCubicBezier.");
|
||||||
ParseToolCubicBezier(scene, domElement, parse);
|
ParseToolCubicBezier(scene, domElement, parse);
|
||||||
break;
|
break;
|
||||||
|
case 7: //VToolCubicBezierPath::ToolType
|
||||||
|
qCDebug(vXML, "VToolCubicBezierPath.");
|
||||||
|
ParseToolCubicBezierPath(scene, domElement, parse);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
VException e(tr("Unknown spline type '%1'.").arg(type));
|
VException e(tr("Unknown spline type '%1'.").arg(type));
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -3036,7 +3094,7 @@ void VPattern::ToolsCommonAttributes(const QDomElement &domElement, quint32 &id)
|
||||||
QRectF VPattern::ActiveDrawBoundingRect() const
|
QRectF VPattern::ActiveDrawBoundingRect() const
|
||||||
{
|
{
|
||||||
// This check helps to find missed tools in the switch
|
// This check helps to find missed tools in the switch
|
||||||
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 40, "Not all tools was used.");
|
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used.");
|
||||||
|
|
||||||
QRectF rec;
|
QRectF rec;
|
||||||
|
|
||||||
|
@ -3092,6 +3150,9 @@ QRectF VPattern::ActiveDrawBoundingRect() const
|
||||||
case Tool::SplinePath:
|
case Tool::SplinePath:
|
||||||
rec = ToolBoundingRect<VToolSplinePath>(rec, tool.getId());
|
rec = ToolBoundingRect<VToolSplinePath>(rec, tool.getId());
|
||||||
break;
|
break;
|
||||||
|
case Tool::CubicBezierPath:
|
||||||
|
rec = ToolBoundingRect<VToolCubicBezierPath>(rec, tool.getId());
|
||||||
|
break;
|
||||||
case Tool::PointOfContact:
|
case Tool::PointOfContact:
|
||||||
rec = ToolBoundingRect<VToolPointOfContact>(rec, tool.getId());
|
rec = ToolBoundingRect<VToolPointOfContact>(rec, tool.getId());
|
||||||
break;
|
break;
|
||||||
|
@ -3140,8 +3201,7 @@ QRectF VPattern::ActiveDrawBoundingRect() const
|
||||||
case Tool::TrueDarts:
|
case Tool::TrueDarts:
|
||||||
rec = ToolBoundingRect<VToolTrueDarts>(rec, tool.getId());
|
rec = ToolBoundingRect<VToolTrueDarts>(rec, tool.getId());
|
||||||
break;
|
break;
|
||||||
//Because "history" not only show history of pattern, but help restore current data for each pattern's
|
//These tools are not accesseble in Draw mode, but still 'history' contains them.
|
||||||
//piece, we need add record about details and nodes, but don't show them.
|
|
||||||
case Tool::Detail:
|
case Tool::Detail:
|
||||||
case Tool::UnionDetails:
|
case Tool::UnionDetails:
|
||||||
case Tool::NodeArc:
|
case Tool::NodeArc:
|
||||||
|
@ -3166,7 +3226,7 @@ QRectF VPattern::ToolBoundingRect(const QRectF &rec, const quint32 &id) const
|
||||||
QRectF recTool = rec;
|
QRectF recTool = rec;
|
||||||
if (tools.contains(id))
|
if (tools.contains(id))
|
||||||
{
|
{
|
||||||
T *vTool = qobject_cast<T *>(tools.value(id));
|
const T *vTool = qobject_cast<T *>(tools.value(id));
|
||||||
SCASSERT(vTool != nullptr);
|
SCASSERT(vTool != nullptr);
|
||||||
|
|
||||||
QRectF childrenRect = vTool->childrenBoundingRect();
|
QRectF childrenRect = vTool->childrenBoundingRect();
|
||||||
|
|
|
@ -136,7 +136,7 @@ private:
|
||||||
void SplinesCommonAttributes(const QDomElement &domElement, quint32 &id, quint32 &idObject,
|
void SplinesCommonAttributes(const QDomElement &domElement, quint32 &id, quint32 &idObject,
|
||||||
quint32 &idTool);
|
quint32 &idTool);
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const;
|
QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const;
|
||||||
void ParseCurrentPP();
|
void ParseCurrentPP();
|
||||||
QString GetLabelBase(quint32 index)const;
|
QString GetLabelBase(quint32 index)const;
|
||||||
|
|
||||||
|
@ -177,6 +177,7 @@ private:
|
||||||
void ParseOldToolSplinePath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse);
|
void ParseOldToolSplinePath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse);
|
||||||
|
|
||||||
void ParseToolSplinePath(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 ParseNodeSpline(const QDomElement &domElement, const Document &parse);
|
||||||
void ParseNodeSplinePath(const QDomElement &domElement, const Document &parse);
|
void ParseNodeSplinePath(const QDomElement &domElement, const Document &parse);
|
||||||
|
|
||||||
|
|
|
@ -126,6 +126,17 @@ QPointF VAbstractCubicBezier::CutSpline(qreal length, QPointF &spl1p2, QPointF &
|
||||||
return p1234;
|
return p1234;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QString VAbstractCubicBezier::NameForHistory(const QString &toolName) const
|
||||||
|
{
|
||||||
|
QString name = toolName + QString(" %1_%2").arg(GetP1().name()).arg(GetP4().name());
|
||||||
|
if (GetDuplicate() > 0)
|
||||||
|
{
|
||||||
|
name += QString("_%1").arg(GetDuplicate());
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VAbstractCubicBezier::CreateName()
|
void VAbstractCubicBezier::CreateName()
|
||||||
{
|
{
|
||||||
|
|
|
@ -46,6 +46,8 @@ public:
|
||||||
|
|
||||||
QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const;
|
QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const;
|
||||||
|
|
||||||
|
virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void CreateName() Q_DECL_OVERRIDE;
|
virtual void CreateName() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
|
228
src/libs/vgeometry/vabstractcubicbezierpath.cpp
Normal file
|
@ -0,0 +1,228 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vabstractcubicbezierpath.cpp
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 16 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 "vabstractcubicbezierpath.h"
|
||||||
|
#include "../ifc/exception/vexception.h"
|
||||||
|
#include "vspline.h"
|
||||||
|
|
||||||
|
#include <QPainterPath>
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VAbstractCubicBezierPath::VAbstractCubicBezierPath(const GOType &type, const quint32 &idObject, const Draw &mode)
|
||||||
|
: VAbstractCurve(type, idObject, mode)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VAbstractCubicBezierPath::VAbstractCubicBezierPath(const VAbstractCubicBezierPath &curve)
|
||||||
|
: VAbstractCurve(curve)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VAbstractCubicBezierPath &VAbstractCubicBezierPath::operator=(const VAbstractCubicBezierPath &curve)
|
||||||
|
{
|
||||||
|
if ( &curve == this )
|
||||||
|
{
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
VAbstractCurve::operator=(curve);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VAbstractCubicBezierPath::~VAbstractCubicBezierPath()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetPath return QPainterPath which reprezent spline path.
|
||||||
|
* @return path.
|
||||||
|
*/
|
||||||
|
QPainterPath VAbstractCubicBezierPath::GetPath(PathDirection direction) const
|
||||||
|
{
|
||||||
|
QPainterPath painterPath;
|
||||||
|
for (qint32 i = 1; i <= CountSubSpl(); ++i)
|
||||||
|
{
|
||||||
|
painterPath.addPath(GetSpline(i).GetPath(direction));
|
||||||
|
}
|
||||||
|
return painterPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetPathPoints return list of points what located on path.
|
||||||
|
* @return list.
|
||||||
|
*/
|
||||||
|
QVector<QPointF> VAbstractCubicBezierPath::GetPoints() const
|
||||||
|
{
|
||||||
|
QVector<QPointF> pathPoints;
|
||||||
|
for (qint32 i = 1; i <= CountSubSpl(); ++i)
|
||||||
|
{
|
||||||
|
pathPoints += GetSpline(i).GetPoints();
|
||||||
|
}
|
||||||
|
return pathPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetLength return length of spline path.
|
||||||
|
* @return length.
|
||||||
|
*/
|
||||||
|
qreal VAbstractCubicBezierPath::GetLength() const
|
||||||
|
{
|
||||||
|
qreal length = 0;
|
||||||
|
for (qint32 i = 1; i <= CountSubSpl(); ++i)
|
||||||
|
{
|
||||||
|
length += GetSpline(i).GetLength();
|
||||||
|
}
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
int VAbstractCubicBezierPath::Segment(const QPointF &p) const
|
||||||
|
{
|
||||||
|
int index = -1;
|
||||||
|
for (qint32 i = 1; i <= CountSubSpl(); ++i)
|
||||||
|
{
|
||||||
|
const qreal t = GetSpline(i).ParamT(p);
|
||||||
|
if (not qFuzzyIsNull(t) && qFuzzyCompare(t, -1))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief CutSplinePath cut spline path into two. This method don't return two spline path. You must create spline
|
||||||
|
* paths by yourself.
|
||||||
|
* Example:
|
||||||
|
* QPointF spl1p2, spl1p3, spl2p2, spl2p3;
|
||||||
|
* qint32 p1 = 0, p2 = 0;
|
||||||
|
* QPointF point = splPath->CutSplinePath(length, p1, p2, spl1p2, spl1p3, spl2p2, spl2p3);
|
||||||
|
*
|
||||||
|
* VSplinePoint splP1 = splPath->at(p1);
|
||||||
|
* VSplinePoint splP2 = splPath->at(p2);
|
||||||
|
* VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, *p, splPath->GetKCurve());
|
||||||
|
* VSpline spl2 = VSpline(*p, spl2p2, spl2p3, splP2.P(), splPath->GetKCurve());
|
||||||
|
* @param length length first spline path.
|
||||||
|
* @param p1 index first spline point in list.
|
||||||
|
* @param p2 index second spline point in list.
|
||||||
|
* @param spl1p2 first control point first spline.
|
||||||
|
* @param spl1p3 second control point first spline.
|
||||||
|
* @param spl2p2 first control point second spline.
|
||||||
|
* @param spl2p3 second control point second spline.
|
||||||
|
* @return cutting point.
|
||||||
|
*/
|
||||||
|
QPointF VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3,
|
||||||
|
QPointF &spl2p2, QPointF &spl2p3) const
|
||||||
|
{
|
||||||
|
if (CountSubSpl() < 1)
|
||||||
|
{
|
||||||
|
throw VException(tr("Can't cut this spline"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Always need return two spline paths, so we must correct wrong length.
|
||||||
|
qreal fullLength = GetLength();
|
||||||
|
if (length < fullLength * 0.02)
|
||||||
|
{
|
||||||
|
length = fullLength * 0.02;
|
||||||
|
}
|
||||||
|
else if ( length > fullLength * 0.98)
|
||||||
|
{
|
||||||
|
length = fullLength * 0.98;
|
||||||
|
}
|
||||||
|
|
||||||
|
fullLength = 0;
|
||||||
|
for (qint32 i = 1; i <= CountSubSpl(); ++i)
|
||||||
|
{
|
||||||
|
const VSpline spl = GetSpline(i);
|
||||||
|
fullLength += spl.GetLength();
|
||||||
|
if (fullLength > length)
|
||||||
|
{
|
||||||
|
p1 = i-1;
|
||||||
|
p2 = i;
|
||||||
|
return spl.CutSpline(length - (fullLength - spl.GetLength()), spl1p2, spl1p3, spl2p2, spl2p3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QPointF();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief NameForHistory helps to create name for dialog History.
|
||||||
|
* @param toolName first part of name. Like 'Spline path' or 'Cubic Bezier path'.
|
||||||
|
* @return name of curve for history records.
|
||||||
|
*/
|
||||||
|
QString VAbstractCubicBezierPath::NameForHistory(const QString &toolName) const
|
||||||
|
{
|
||||||
|
QString name = toolName;
|
||||||
|
if (CountPoints() > 0)
|
||||||
|
{
|
||||||
|
name += QString(" %1").arg(FirstPoint().name());
|
||||||
|
if (CountSubSpl() >= 1)
|
||||||
|
{
|
||||||
|
name += QString("_%1").arg(LastPoint().name());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetDuplicate() > 0)
|
||||||
|
{
|
||||||
|
name += QString("_%1").arg(GetDuplicate());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VAbstractCubicBezierPath::CreateName()
|
||||||
|
{
|
||||||
|
QString name;
|
||||||
|
if (CountPoints() > 0)
|
||||||
|
{
|
||||||
|
name = splPath;
|
||||||
|
name.append(QString("_%1").arg(FirstPoint().name()));
|
||||||
|
if (CountSubSpl() >= 2)
|
||||||
|
{
|
||||||
|
name.append(QString("_%1").arg(LastPoint().name()));
|
||||||
|
|
||||||
|
if (GetDuplicate() > 0)
|
||||||
|
{
|
||||||
|
name += QString("_%1").arg(GetDuplicate());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setName(name);
|
||||||
|
}
|
72
src/libs/vgeometry/vabstractcubicbezierpath.h
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vabstractcubicbezierpath.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 16 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 VABSTRACTCUBICBEZIERPATH_H
|
||||||
|
#define VABSTRACTCUBICBEZIERPATH_H
|
||||||
|
|
||||||
|
#include "vabstractcurve.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
class VPointF;
|
||||||
|
class VSpline;
|
||||||
|
|
||||||
|
class VAbstractCubicBezierPath : public VAbstractCurve
|
||||||
|
{
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(VAbstractCubicBezierPath)
|
||||||
|
public:
|
||||||
|
VAbstractCubicBezierPath(const GOType &type, const quint32 &idObject = NULL_ID,
|
||||||
|
const Draw &mode = Draw::Calculation);
|
||||||
|
VAbstractCubicBezierPath(const VAbstractCubicBezierPath &curve);
|
||||||
|
VAbstractCubicBezierPath& operator= (const VAbstractCubicBezierPath &curve);
|
||||||
|
virtual ~VAbstractCubicBezierPath();
|
||||||
|
|
||||||
|
virtual qint32 CountSubSpl() const =0;
|
||||||
|
virtual qint32 CountPoints() const =0;
|
||||||
|
virtual void Clear() =0;
|
||||||
|
virtual VSpline GetSpline(qint32 index) const =0;
|
||||||
|
|
||||||
|
virtual QPainterPath GetPath(PathDirection direction = PathDirection::Hide) const Q_DECL_OVERRIDE;
|
||||||
|
virtual QVector<QPointF> GetPoints() const Q_DECL_OVERRIDE;
|
||||||
|
virtual qreal GetLength() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
int Segment(const QPointF &p) const;
|
||||||
|
|
||||||
|
QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2,
|
||||||
|
QPointF &spl2p3) const;
|
||||||
|
|
||||||
|
virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void CreateName() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
virtual VPointF FirstPoint() const =0;
|
||||||
|
virtual VPointF LastPoint() const =0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VABSTRACTCUBICBEZIERPATH_H
|
|
@ -65,6 +65,8 @@ public:
|
||||||
void SetDuplicate(quint32 number);
|
void SetDuplicate(quint32 number);
|
||||||
|
|
||||||
static QVector<QPointF> CurveIntersectLine(const QVector<QPointF> &points, const QLineF &line);
|
static QVector<QPointF> CurveIntersectLine(const QVector<QPointF> &points, const QLineF &line);
|
||||||
|
|
||||||
|
virtual QString NameForHistory(const QString &toolName) const=0;
|
||||||
protected:
|
protected:
|
||||||
QPainterPath ShowDirection(const QVector<QPointF> &points) const;
|
QPainterPath ShowDirection(const QVector<QPointF> &points) const;
|
||||||
virtual void CreateName() =0;
|
virtual void CreateName() =0;
|
||||||
|
|
|
@ -315,6 +315,23 @@ void VArc::setId(const quint32 &id)
|
||||||
CreateName();
|
CreateName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QString VArc::NameForHistory(const QString &toolName) const
|
||||||
|
{
|
||||||
|
QString name = toolName + QString(" %1").arg(this->GetCenter().name());
|
||||||
|
|
||||||
|
if (VAbstractCurve::id() != NULL_ID)
|
||||||
|
{
|
||||||
|
name += QString("_%1").arg(VAbstractCurve::id());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetDuplicate() > 0)
|
||||||
|
{
|
||||||
|
name += QString("_%1").arg(GetDuplicate());
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VArc::CreateName()
|
void VArc::CreateName()
|
||||||
{
|
{
|
||||||
|
|
|
@ -80,6 +80,7 @@ public:
|
||||||
QPointF CutArc (const qreal &length, VArc &arc1, VArc &arc2) const;
|
QPointF CutArc (const qreal &length, VArc &arc1, VArc &arc2) const;
|
||||||
QPointF CutArc (const qreal &length) const;
|
QPointF CutArc (const qreal &length) const;
|
||||||
virtual void setId(const quint32 &id) Q_DECL_OVERRIDE;
|
virtual void setId(const quint32 &id) Q_DECL_OVERRIDE;
|
||||||
|
virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE;
|
||||||
protected:
|
protected:
|
||||||
virtual void CreateName() Q_DECL_OVERRIDE;
|
virtual void CreateName() Q_DECL_OVERRIDE;
|
||||||
private:
|
private:
|
||||||
|
|
249
src/libs/vgeometry/vcubicbezierpath.cpp
Normal file
|
@ -0,0 +1,249 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vcubicbezierpath.cpp
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 16 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 "vcubicbezierpath.h"
|
||||||
|
#include "vcubicbezierpath_p.h"
|
||||||
|
#include "vspline.h"
|
||||||
|
#include "../ifc/exception/vexception.h"
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
|
||||||
|
# include "../vmisc/vmath.h"
|
||||||
|
#else
|
||||||
|
# include <QtMath>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VCubicBezierPath::VCubicBezierPath(quint32 idObject, Draw mode)
|
||||||
|
: VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode),
|
||||||
|
d(new VCubicBezierPathData())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VCubicBezierPath::VCubicBezierPath(const VCubicBezierPath &curve)
|
||||||
|
: VAbstractCubicBezierPath(curve),
|
||||||
|
d(curve.d)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VCubicBezierPath::VCubicBezierPath(const QVector<VPointF> &points, quint32 idObject, Draw mode)
|
||||||
|
: VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode),
|
||||||
|
d(new VCubicBezierPathData())
|
||||||
|
{
|
||||||
|
if (points.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->path = points;
|
||||||
|
CreateName();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VCubicBezierPath &VCubicBezierPath::operator=(const VCubicBezierPath &curve)
|
||||||
|
{
|
||||||
|
if ( &curve == this )
|
||||||
|
{
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
VAbstractCurve::operator=(curve);
|
||||||
|
d = curve.d;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VCubicBezierPath::~VCubicBezierPath()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VPointF &VCubicBezierPath::operator[](int indx)
|
||||||
|
{
|
||||||
|
return d->path[indx];
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
const VPointF &VCubicBezierPath::at(int indx) const
|
||||||
|
{
|
||||||
|
return d->path[indx];
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VCubicBezierPath::append(const VPointF &point)
|
||||||
|
{
|
||||||
|
if (d->path.size() > 0 && d->path.last().toQPointF() != point.toQPointF())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->path.append(point);
|
||||||
|
CreateName();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
qint32 VCubicBezierPath::CountSubSpl() const
|
||||||
|
{
|
||||||
|
return CountSubSpl(d->path.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
qint32 VCubicBezierPath::CountPoints() const
|
||||||
|
{
|
||||||
|
return d->path.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VCubicBezierPath::Clear()
|
||||||
|
{
|
||||||
|
d->path.clear();
|
||||||
|
SetDuplicate(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VSpline VCubicBezierPath::GetSpline(qint32 index) const
|
||||||
|
{
|
||||||
|
if (CountPoints() < 4)
|
||||||
|
{
|
||||||
|
throw VException(tr("Not enough points to create the spline."));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index < 1 || index > CountSubSpl())
|
||||||
|
{
|
||||||
|
throw VException(tr("This spline does not exist."));
|
||||||
|
}
|
||||||
|
|
||||||
|
const qint32 base = SubSplOffset(index);
|
||||||
|
|
||||||
|
// Correction the first control point of each next spline curve except for the first.
|
||||||
|
QPointF p2 = d->path.at(base + 1).toQPointF();
|
||||||
|
if (base + 1 > 1)
|
||||||
|
{
|
||||||
|
const QPointF b = d->path.at(base).toQPointF();
|
||||||
|
QLineF foot1(b, d->path.at(base - 1).toQPointF());
|
||||||
|
QLineF foot2(b, p2);
|
||||||
|
|
||||||
|
foot2.setAngle(foot1.angle() + 180);
|
||||||
|
p2 = foot2.p2();
|
||||||
|
}
|
||||||
|
|
||||||
|
VSpline spl(d->path.at(base), p2, d->path.at(base + 2).toQPointF(), d->path.at(base + 3));
|
||||||
|
return spl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
qreal VCubicBezierPath::GetStartAngle() const
|
||||||
|
{
|
||||||
|
if (CountSubSpl() > 0)
|
||||||
|
{
|
||||||
|
return GetSpline(1).GetStartAngle();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
qreal VCubicBezierPath::GetEndAngle() const
|
||||||
|
{
|
||||||
|
const qint32 count = CountSubSpl();
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
return GetSpline(count).GetEndAngle();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QVector<VPointF> VCubicBezierPath::GetSplinePath() const
|
||||||
|
{
|
||||||
|
return d->path;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
qint32 VCubicBezierPath::CountSubSpl(qint32 size)
|
||||||
|
{
|
||||||
|
if (size <= 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return qFloor(qAbs((size - 4) / 3.0 + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
qint32 VCubicBezierPath::SubSplOffset(qint32 subSplIndex)
|
||||||
|
{
|
||||||
|
if (subSplIndex <= 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (subSplIndex - 1) * 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
qint32 VCubicBezierPath::SubSplPointsCount(qint32 countSubSpl)
|
||||||
|
{
|
||||||
|
if (countSubSpl <= 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((countSubSpl - 1) * 3 + 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VPointF VCubicBezierPath::FirstPoint() const
|
||||||
|
{
|
||||||
|
if (not d->path.isEmpty())
|
||||||
|
{
|
||||||
|
return d->path.first();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return VPointF();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VPointF VCubicBezierPath::LastPoint() const
|
||||||
|
{
|
||||||
|
const qint32 count = CountSubSpl();
|
||||||
|
if (count >= 1)
|
||||||
|
{
|
||||||
|
return d->path.at(SubSplOffset(count) + 3);// Take last point of the last real spline
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return VPointF();
|
||||||
|
}
|
||||||
|
}
|
77
src/libs/vgeometry/vcubicbezierpath.h
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vcubicbezierpath.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 16 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 VCUBICBEZIERPATH_H
|
||||||
|
#define VCUBICBEZIERPATH_H
|
||||||
|
|
||||||
|
#include "vabstractcubicbezierpath.h"
|
||||||
|
#include "vpointf.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
class VCubicBezierPathData;
|
||||||
|
class VSpline;
|
||||||
|
|
||||||
|
class VCubicBezierPath : public VAbstractCubicBezierPath
|
||||||
|
{
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(VCubicBezierPath)
|
||||||
|
public:
|
||||||
|
explicit VCubicBezierPath(quint32 idObject = 0, Draw mode = Draw::Calculation);
|
||||||
|
VCubicBezierPath(const VCubicBezierPath &curve);
|
||||||
|
VCubicBezierPath(const QVector<VPointF> &points, quint32 idObject = 0, Draw mode = Draw::Calculation);
|
||||||
|
VCubicBezierPath &operator=(const VCubicBezierPath &curve);
|
||||||
|
virtual ~VCubicBezierPath();
|
||||||
|
|
||||||
|
VPointF &operator[](int indx);
|
||||||
|
|
||||||
|
const VPointF &at(int indx) const;
|
||||||
|
|
||||||
|
void append(const VPointF &point);
|
||||||
|
|
||||||
|
virtual qint32 CountSubSpl() const Q_DECL_OVERRIDE;
|
||||||
|
virtual qint32 CountPoints() const Q_DECL_OVERRIDE;
|
||||||
|
virtual void Clear() Q_DECL_OVERRIDE;
|
||||||
|
virtual VSpline GetSpline(qint32 index) const Q_DECL_OVERRIDE;
|
||||||
|
virtual qreal GetStartAngle () const Q_DECL_OVERRIDE;
|
||||||
|
virtual qreal GetEndAngle () const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
QVector<VPointF> GetSplinePath() const;
|
||||||
|
|
||||||
|
static qint32 CountSubSpl(qint32 size);
|
||||||
|
static qint32 SubSplOffset(qint32 subSplIndex);
|
||||||
|
static qint32 SubSplPointsCount(qint32 countSubSpl);
|
||||||
|
protected:
|
||||||
|
virtual VPointF FirstPoint() const Q_DECL_OVERRIDE;
|
||||||
|
virtual VPointF LastPoint() const Q_DECL_OVERRIDE;
|
||||||
|
private:
|
||||||
|
QSharedDataPointer<VCubicBezierPathData> d;
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_TYPEINFO(VCubicBezierPath, Q_MOVABLE_TYPE);
|
||||||
|
|
||||||
|
#endif // VCUBICBEZIERPATH_H
|
70
src/libs/vgeometry/vcubicbezierpath_p.h
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vcubicbezierpath_p.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 16 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 VCUBICBEZIERPATH_P_H
|
||||||
|
#define VCUBICBEZIERPATH_P_H
|
||||||
|
|
||||||
|
#include <QSharedData>
|
||||||
|
|
||||||
|
#include "vpointf.h"
|
||||||
|
|
||||||
|
#ifdef Q_CC_GNU
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Weffc++"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class VCubicBezierPathData : public QSharedData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
VCubicBezierPathData()
|
||||||
|
: path()
|
||||||
|
{}
|
||||||
|
|
||||||
|
VCubicBezierPathData(const VCubicBezierPathData &splPath)
|
||||||
|
: QSharedData(splPath),
|
||||||
|
path(splPath.path)
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual ~VCubicBezierPathData();
|
||||||
|
|
||||||
|
/** @brief path list of points. */
|
||||||
|
QVector<VPointF> path;
|
||||||
|
|
||||||
|
private:
|
||||||
|
VCubicBezierPathData &operator=(const VCubicBezierPathData &) Q_DECL_EQ_DELETE;
|
||||||
|
};
|
||||||
|
|
||||||
|
VCubicBezierPathData::~VCubicBezierPathData()
|
||||||
|
{}
|
||||||
|
|
||||||
|
#ifdef Q_CC_GNU
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // VCUBICBEZIERPATH_P_H
|
|
@ -375,6 +375,23 @@ void VEllipticalArc::setId(const quint32 &id)
|
||||||
CreateName();
|
CreateName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QString VEllipticalArc::NameForHistory(const QString &toolName) const
|
||||||
|
{
|
||||||
|
QString name = toolName + QString(" %1").arg(this->GetCenter().name());
|
||||||
|
|
||||||
|
if (VAbstractCurve::id() != NULL_ID)
|
||||||
|
{
|
||||||
|
name += QString("_%1").arg(VAbstractCurve::id());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetDuplicate() > 0)
|
||||||
|
{
|
||||||
|
name += QString("_%1").arg(GetDuplicate());
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VEllipticalArc::CreateName()
|
void VEllipticalArc::CreateName()
|
||||||
{
|
{
|
||||||
|
|
|
@ -92,6 +92,7 @@ public:
|
||||||
QPointF CutArc (const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2) const;
|
QPointF CutArc (const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2) const;
|
||||||
QPointF CutArc (const qreal &length) const;
|
QPointF CutArc (const qreal &length) const;
|
||||||
virtual void setId(const quint32 &id) Q_DECL_OVERRIDE;
|
virtual void setId(const quint32 &id) Q_DECL_OVERRIDE;
|
||||||
|
virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE;
|
||||||
protected:
|
protected:
|
||||||
virtual void CreateName() Q_DECL_OVERRIDE;
|
virtual void CreateName() Q_DECL_OVERRIDE;
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -11,7 +11,9 @@ SOURCES += \
|
||||||
$$PWD/vsplinepoint.cpp \
|
$$PWD/vsplinepoint.cpp \
|
||||||
$$PWD/vellipticalarc.cpp \
|
$$PWD/vellipticalarc.cpp \
|
||||||
$$PWD/vcubicbezier.cpp \
|
$$PWD/vcubicbezier.cpp \
|
||||||
$$PWD/vabstractcubicbezier.cpp
|
$$PWD/vabstractcubicbezier.cpp \
|
||||||
|
$$PWD/vabstractcubicbezierpath.cpp \
|
||||||
|
$$PWD/vcubicbezierpath.cpp
|
||||||
|
|
||||||
win32-msvc*:SOURCES += $$PWD/stable.cpp
|
win32-msvc*:SOURCES += $$PWD/stable.cpp
|
||||||
|
|
||||||
|
@ -36,4 +38,7 @@ HEADERS += \
|
||||||
$$PWD/vabstractcurve_p.h \
|
$$PWD/vabstractcurve_p.h \
|
||||||
$$PWD/vcubicbezier.h \
|
$$PWD/vcubicbezier.h \
|
||||||
$$PWD/vcubicbezier_p.h \
|
$$PWD/vcubicbezier_p.h \
|
||||||
$$PWD/vabstractcubicbezier.h
|
$$PWD/vabstractcubicbezier.h \
|
||||||
|
$$PWD/vabstractcubicbezierpath.h \
|
||||||
|
$$PWD/vcubicbezierpath.h \
|
||||||
|
$$PWD/vcubicbezierpath_p.h
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
|
|
||||||
#include "vgobject.h"
|
#include "vgobject.h"
|
||||||
|
|
||||||
|
#include <QMetaType>
|
||||||
|
|
||||||
class QPointF;
|
class QPointF;
|
||||||
class QString;
|
class QString;
|
||||||
class VPointFData;
|
class VPointFData;
|
||||||
|
@ -69,6 +71,7 @@ private:
|
||||||
QSharedDataPointer<VPointFData> d;
|
QSharedDataPointer<VPointFData> d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(VPointF)
|
||||||
Q_DECLARE_TYPEINFO(VPointF, Q_MOVABLE_TYPE);
|
Q_DECLARE_TYPEINFO(VPointF, Q_MOVABLE_TYPE);
|
||||||
|
|
||||||
#if defined(Q_CC_INTEL)
|
#if defined(Q_CC_INTEL)
|
||||||
|
|
|
@ -43,13 +43,13 @@
|
||||||
* @param mode mode creation spline path.
|
* @param mode mode creation spline path.
|
||||||
*/
|
*/
|
||||||
VSplinePath::VSplinePath(quint32 idObject, Draw mode)
|
VSplinePath::VSplinePath(quint32 idObject, Draw mode)
|
||||||
: VAbstractCurve(GOType::SplinePath, idObject, mode),
|
: VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode),
|
||||||
d(new VSplinePathData())
|
d(new VSplinePathData())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VSplinePath::VSplinePath(const QVector<VFSplinePoint> &points, qreal kCurve, quint32 idObject, Draw mode)
|
VSplinePath::VSplinePath(const QVector<VFSplinePoint> &points, qreal kCurve, quint32 idObject, Draw mode)
|
||||||
: VAbstractCurve(GOType::SplinePath, idObject, mode),
|
: VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode),
|
||||||
d(new VSplinePathData())
|
d(new VSplinePathData())
|
||||||
{
|
{
|
||||||
if (points.size() < 3)
|
if (points.size() < 3)
|
||||||
|
@ -84,7 +84,7 @@ VSplinePath::VSplinePath(const QVector<VFSplinePoint> &points, qreal kCurve, qui
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VSplinePath::VSplinePath(const QVector<VSplinePoint> &points, quint32 idObject, Draw mode)
|
VSplinePath::VSplinePath(const QVector<VSplinePoint> &points, quint32 idObject, Draw mode)
|
||||||
: VAbstractCurve(GOType::SplinePath, idObject, mode),
|
: VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode),
|
||||||
d(new VSplinePathData())
|
d(new VSplinePathData())
|
||||||
{
|
{
|
||||||
if (points.isEmpty())
|
if (points.isEmpty())
|
||||||
|
@ -102,7 +102,7 @@ VSplinePath::VSplinePath(const QVector<VSplinePoint> &points, quint32 idObject,
|
||||||
* @param splPath spline path.
|
* @param splPath spline path.
|
||||||
*/
|
*/
|
||||||
VSplinePath::VSplinePath(const VSplinePath &splPath)
|
VSplinePath::VSplinePath(const VSplinePath &splPath)
|
||||||
: VAbstractCurve(splPath),
|
: VAbstractCubicBezierPath(splPath),
|
||||||
d(splPath.d)
|
d(splPath.d)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -128,12 +128,12 @@ void VSplinePath::append(const VSplinePoint &point)
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief Count return count point.
|
* @brief CountSubSpl return count of simple splines.
|
||||||
* @return count.
|
* @return count.
|
||||||
*/
|
*/
|
||||||
qint32 VSplinePath::Count() const
|
qint32 VSplinePath::CountSubSpl() const
|
||||||
{
|
{
|
||||||
if (d->path.size() == 0)
|
if (d->path.isEmpty())
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -151,14 +151,16 @@ qint32 VSplinePath::Count() const
|
||||||
*/
|
*/
|
||||||
VSpline VSplinePath::GetSpline(qint32 index) const
|
VSpline VSplinePath::GetSpline(qint32 index) const
|
||||||
{
|
{
|
||||||
if (Count()<1)
|
if (CountPoints()<1)
|
||||||
{
|
{
|
||||||
throw VException(tr("Not enough points to create the spline."));
|
throw VException(tr("Not enough points to create the spline."));
|
||||||
}
|
}
|
||||||
if (index < 1 || index > Count())
|
|
||||||
|
if (index < 1 || index > CountSubSpl())
|
||||||
{
|
{
|
||||||
throw VException(tr("This spline does not exist."));
|
throw VException(tr("This spline does not exist."));
|
||||||
}
|
}
|
||||||
|
|
||||||
const VSplinePoint &p1 = d->path.at(index-1);
|
const VSplinePoint &p1 = d->path.at(index-1);
|
||||||
const VSplinePoint &p2 = d->path.at(index);
|
const VSplinePoint &p2 = d->path.at(index);
|
||||||
VSpline spl(p1.P(), p2.P(), p1.Angle2(), p1.Angle2Formula(), p2.Angle1(), p2.Angle1Formula(), p1.Length2(),
|
VSpline spl(p1.P(), p2.P(), p1.Angle2(), p1.Angle2Formula(), p2.Angle1(), p2.Angle1Formula(), p1.Length2(),
|
||||||
|
@ -166,63 +168,6 @@ VSpline VSplinePath::GetSpline(qint32 index) const
|
||||||
return spl;
|
return spl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief GetPath return QPainterPath which reprezent spline path.
|
|
||||||
* @return path.
|
|
||||||
*/
|
|
||||||
QPainterPath VSplinePath::GetPath(PathDirection direction) const
|
|
||||||
{
|
|
||||||
QPainterPath painterPath;
|
|
||||||
for (qint32 i = 1; i <= Count(); ++i)
|
|
||||||
{
|
|
||||||
const VSplinePoint &p1 = d->path.at(i-1);
|
|
||||||
const VSplinePoint &p2 = d->path.at(i);
|
|
||||||
VSpline spl(p1.P(), p2.P(), p1.Angle2(), p1.Angle2Formula(), p2.Angle1(), p2.Angle1Formula(), p1.Length2(),
|
|
||||||
p1.Length2Formula(), p2.Length1(), p2.Length1Formula(), 1);
|
|
||||||
painterPath.addPath(spl.GetPath(direction));
|
|
||||||
}
|
|
||||||
return painterPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief GetPathPoints return list of points what located on path.
|
|
||||||
* @return list.
|
|
||||||
*/
|
|
||||||
QVector<QPointF> VSplinePath::GetPoints() const
|
|
||||||
{
|
|
||||||
QVector<QPointF> pathPoints;
|
|
||||||
for (qint32 i = 1; i <= Count(); ++i)
|
|
||||||
{
|
|
||||||
const VSplinePoint &p1 = d->path.at(i-1);
|
|
||||||
const VSplinePoint &p2 = d->path.at(i);
|
|
||||||
VSpline spl(p1.P(), p2.P(), p1.Angle2(), p1.Angle2Formula(), p2.Angle1(), p2.Angle1Formula(), p1.Length2(),
|
|
||||||
p1.Length2Formula(), p2.Length1(), p2.Length1Formula(), 1);
|
|
||||||
pathPoints += spl.GetPoints();
|
|
||||||
}
|
|
||||||
return pathPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief GetLength return length of spline path.
|
|
||||||
* @return length.
|
|
||||||
*/
|
|
||||||
qreal VSplinePath::GetLength() const
|
|
||||||
{
|
|
||||||
qreal length = 0;
|
|
||||||
for (qint32 i = 1; i <= Count(); ++i)
|
|
||||||
{
|
|
||||||
const VSplinePoint &p1 = d->path.at(i-1);
|
|
||||||
const VSplinePoint &p2 = d->path.at(i);
|
|
||||||
VSpline spl(p1.P(), p2.P(), p1.Angle2(), p1.Angle2Formula(), p2.Angle1(), p2.Angle1Formula(), p1.Length2(),
|
|
||||||
p1.Length2Formula(), p2.Length1(), p2.Length1Formula(), 1);
|
|
||||||
length += spl.GetLength();
|
|
||||||
}
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief UpdatePoint update spline point in list.
|
* @brief UpdatePoint update spline point in list.
|
||||||
|
@ -232,7 +177,7 @@ qreal VSplinePath::GetLength() const
|
||||||
*/
|
*/
|
||||||
void VSplinePath::UpdatePoint(qint32 indexSpline, const SplinePointPosition &pos, const VSplinePoint &point)
|
void VSplinePath::UpdatePoint(qint32 indexSpline, const SplinePointPosition &pos, const VSplinePoint &point)
|
||||||
{
|
{
|
||||||
if (indexSpline < 1 || indexSpline > Count())
|
if (indexSpline < 1 || indexSpline > CountSubSpl())
|
||||||
{
|
{
|
||||||
throw VException(tr("This spline does not exist."));
|
throw VException(tr("This spline does not exist."));
|
||||||
}
|
}
|
||||||
|
@ -255,7 +200,7 @@ void VSplinePath::UpdatePoint(qint32 indexSpline, const SplinePointPosition &pos
|
||||||
*/
|
*/
|
||||||
VSplinePoint VSplinePath::GetSplinePoint(qint32 indexSpline, SplinePointPosition pos) const
|
VSplinePoint VSplinePath::GetSplinePoint(qint32 indexSpline, SplinePointPosition pos) const
|
||||||
{
|
{
|
||||||
if (indexSpline < 1 || indexSpline > Count())
|
if (indexSpline < 1 || indexSpline > CountSubSpl())
|
||||||
{
|
{
|
||||||
throw VException(tr("This spline does not exist."));
|
throw VException(tr("This spline does not exist."));
|
||||||
}
|
}
|
||||||
|
@ -308,98 +253,12 @@ const VSplinePoint &VSplinePath::at(int indx) const
|
||||||
return d->path[indx];
|
return d->path[indx];
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief CutSplinePath cut spline path into two. This method don't return two spline path. You must create spline
|
|
||||||
* paths by yourself.
|
|
||||||
* Example:
|
|
||||||
* QPointF spl1p2, spl1p3, spl2p2, spl2p3;
|
|
||||||
* qint32 p1 = 0, p2 = 0;
|
|
||||||
* QPointF point = splPath->CutSplinePath(length, p1, p2, spl1p2, spl1p3, spl2p2, spl2p3);
|
|
||||||
*
|
|
||||||
* VSplinePoint splP1 = splPath->at(p1);
|
|
||||||
* VSplinePoint splP2 = splPath->at(p2);
|
|
||||||
* VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, *p, splPath->GetKCurve());
|
|
||||||
* VSpline spl2 = VSpline(*p, spl2p2, spl2p3, splP2.P(), splPath->GetKCurve());
|
|
||||||
* @param length length first spline path.
|
|
||||||
* @param p1 index first spline point in list.
|
|
||||||
* @param p2 index second spline point in list.
|
|
||||||
* @param spl1p2 first control point first spline.
|
|
||||||
* @param spl1p3 second control point first spline.
|
|
||||||
* @param spl2p2 first control point second spline.
|
|
||||||
* @param spl2p3 second control point second spline.
|
|
||||||
* @return cutting point.
|
|
||||||
*/
|
|
||||||
QPointF VSplinePath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3,
|
|
||||||
QPointF &spl2p2, QPointF &spl2p3) const
|
|
||||||
{
|
|
||||||
if (Count() < 2)
|
|
||||||
{
|
|
||||||
throw VException(tr("Can't cut spline path with one point"));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Always need return two spline paths, so we must correct wrong length.
|
|
||||||
qreal fullLength = GetLength();
|
|
||||||
if (length < fullLength * 0.02)
|
|
||||||
{
|
|
||||||
length = fullLength * 0.02;
|
|
||||||
}
|
|
||||||
else if ( length > fullLength * 0.98)
|
|
||||||
{
|
|
||||||
length = fullLength * 0.98;
|
|
||||||
}
|
|
||||||
|
|
||||||
fullLength = 0;
|
|
||||||
for (qint32 i = 1; i <= Count(); ++i)
|
|
||||||
{
|
|
||||||
const VSplinePoint &point1 = d->path.at(i-1);
|
|
||||||
const VSplinePoint &point2 = d->path.at(i);
|
|
||||||
VSpline spl = VSpline(point1.P(), point2.P(), point1.Angle2(), point1.Angle2Formula(), point2.Angle1(),
|
|
||||||
point2.Angle1Formula(), point1.Length2(), point1.Length2Formula(), point2.Length1(),
|
|
||||||
point2.Length1Formula(), 1);
|
|
||||||
fullLength += spl.GetLength();
|
|
||||||
if (fullLength > length)
|
|
||||||
{
|
|
||||||
p1 = i-1;
|
|
||||||
p2 = i;
|
|
||||||
return spl.CutSpline(length - (fullLength - spl.GetLength()), spl1p2, spl1p3, spl2p2, spl2p3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QPointF();
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
int VSplinePath::Segment(const QPointF &p) const
|
|
||||||
{
|
|
||||||
int index = -1;
|
|
||||||
for (qint32 i = 1; i <= Count(); ++i)
|
|
||||||
{
|
|
||||||
const VSplinePoint &p1 = d->path.at(i-1);
|
|
||||||
const VSplinePoint &p2 = d->path.at(i);
|
|
||||||
VSpline spl = VSpline(p1.P(), p2.P(), p1.Angle2(), p1.Angle2Formula(), p2.Angle1(), p2.Angle1Formula(),
|
|
||||||
p1.Length2(), p1.Length2Formula(), p2.Length1(), p2.Length1Formula(), 1.0);
|
|
||||||
|
|
||||||
const qreal t = spl.ParamT(p);
|
|
||||||
|
|
||||||
if (qFloor(t) == -1)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
index = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
qreal VSplinePath::GetStartAngle() const
|
qreal VSplinePath::GetStartAngle() const
|
||||||
{
|
{
|
||||||
if (CountPoint() > 0)
|
if (CountPoints() > 0)
|
||||||
{
|
{
|
||||||
return GetSplinePath().first().Angle1();
|
return GetSplinePath().first().Angle2();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -410,9 +269,9 @@ qreal VSplinePath::GetStartAngle() const
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
qreal VSplinePath::GetEndAngle() const
|
qreal VSplinePath::GetEndAngle() const
|
||||||
{
|
{
|
||||||
if (CountPoint() > 0)
|
if (CountPoints() > 0)
|
||||||
{
|
{
|
||||||
return GetSplinePath().last().Angle2();
|
return GetSplinePath().last().Angle1();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -421,32 +280,38 @@ qreal VSplinePath::GetEndAngle() const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VSplinePath::CreateName()
|
VPointF VSplinePath::FirstPoint() const
|
||||||
{
|
{
|
||||||
QString name;
|
|
||||||
if (not d->path.isEmpty())
|
if (not d->path.isEmpty())
|
||||||
{
|
{
|
||||||
name = splPath;
|
return d->path.first().P();
|
||||||
name.append(QString("_%1").arg(d->path.first().P().name()));
|
}
|
||||||
if (d->path.size() > 1)
|
else
|
||||||
{
|
{
|
||||||
name.append(QString("_%1").arg(d->path.last().P().name()));
|
return VPointF();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (GetDuplicate() > 0)
|
|
||||||
{
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
name += QString("_%1").arg(GetDuplicate());
|
VPointF VSplinePath::LastPoint() const
|
||||||
}
|
{
|
||||||
|
const qint32 count = CountSubSpl();
|
||||||
|
if (count >= 1)
|
||||||
|
{
|
||||||
|
return d->path.at(count).P();// Take last point of the last real spline
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return VPointF();
|
||||||
}
|
}
|
||||||
setName(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief CountPoint return count point.
|
* @brief CountPoints return count of points.
|
||||||
* @return count.
|
* @return count.
|
||||||
*/
|
*/
|
||||||
qint32 VSplinePath::CountPoint() const
|
qint32 VSplinePath::CountPoints() const
|
||||||
{
|
{
|
||||||
return d->path.size();
|
return d->path.size();
|
||||||
}
|
}
|
||||||
|
@ -467,7 +332,7 @@ QVector<VFSplinePoint> VSplinePath::GetFSplinePath() const
|
||||||
QVector<VFSplinePoint> points;
|
QVector<VFSplinePoint> points;
|
||||||
points.reserve(d->path.size());
|
points.reserve(d->path.size());
|
||||||
|
|
||||||
for (qint32 i = 1; i <= Count(); ++i)
|
for (qint32 i = 1; i <= CountSubSpl(); ++i)
|
||||||
{
|
{
|
||||||
const VSplinePoint &p1 = d->path.at(i-1);
|
const VSplinePoint &p1 = d->path.at(i-1);
|
||||||
const VSplinePoint &p2 = d->path.at(i);
|
const VSplinePoint &p2 = d->path.at(i);
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#ifndef VSPLINEPATH_H
|
#ifndef VSPLINEPATH_H
|
||||||
#define VSPLINEPATH_H
|
#define VSPLINEPATH_H
|
||||||
|
|
||||||
#include "vabstractcurve.h"
|
#include "vabstractcubicbezierpath.h"
|
||||||
#include "vspline.h"
|
#include "vspline.h"
|
||||||
#include "vsplinepoint.h"
|
#include "vsplinepoint.h"
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
@ -41,7 +41,7 @@ class VSplinePathData;
|
||||||
/**
|
/**
|
||||||
* @brief The VSplinePath class keep information about splinePath.
|
* @brief The VSplinePath class keep information about splinePath.
|
||||||
*/
|
*/
|
||||||
class VSplinePath :public VAbstractCurve
|
class VSplinePath :public VAbstractCubicBezierPath
|
||||||
{
|
{
|
||||||
Q_DECLARE_TR_FUNCTIONS(VSplinePath)
|
Q_DECLARE_TR_FUNCTIONS(VSplinePath)
|
||||||
public:
|
public:
|
||||||
|
@ -56,14 +56,11 @@ public:
|
||||||
VSplinePoint &operator[](int indx);
|
VSplinePoint &operator[](int indx);
|
||||||
|
|
||||||
void append(const VSplinePoint &point);
|
void append(const VSplinePoint &point);
|
||||||
qint32 Count() const;
|
|
||||||
qint32 CountPoint() const;
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
VSpline GetSpline(qint32 index) const;
|
virtual qint32 CountSubSpl() const Q_DECL_OVERRIDE;
|
||||||
QPainterPath GetPath(PathDirection direction = PathDirection::Hide) const;
|
virtual qint32 CountPoints() const Q_DECL_OVERRIDE;
|
||||||
QVector<QPointF> GetPoints() const;
|
virtual void Clear() Q_DECL_OVERRIDE;
|
||||||
qreal GetLength() const;
|
virtual VSpline GetSpline(qint32 index) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
QVector<VSplinePoint> GetSplinePath() const;
|
QVector<VSplinePoint> GetSplinePath() const;
|
||||||
QVector<VFSplinePoint> GetFSplinePath() const;
|
QVector<VFSplinePoint> GetFSplinePath() const;
|
||||||
|
@ -75,13 +72,9 @@ public:
|
||||||
VSplinePoint GetSplinePoint(qint32 indexSpline, SplinePointPosition pos) const;
|
VSplinePoint GetSplinePoint(qint32 indexSpline, SplinePointPosition pos) const;
|
||||||
|
|
||||||
const VSplinePoint &at(int indx) const;
|
const VSplinePoint &at(int indx) const;
|
||||||
|
|
||||||
QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2,
|
|
||||||
QPointF &spl2p3) const;
|
|
||||||
|
|
||||||
int Segment(const QPointF &p) const;
|
|
||||||
protected:
|
protected:
|
||||||
virtual void CreateName() Q_DECL_OVERRIDE;
|
virtual VPointF FirstPoint() const Q_DECL_OVERRIDE;
|
||||||
|
virtual VPointF LastPoint() const Q_DECL_OVERRIDE;
|
||||||
private:
|
private:
|
||||||
QSharedDataPointer<VSplinePathData> d;
|
QSharedDataPointer<VSplinePathData> d;
|
||||||
};
|
};
|
||||||
|
|
|
@ -80,6 +80,7 @@ enum class Tool : ToolVisHolderType
|
||||||
Arc,
|
Arc,
|
||||||
ArcWithLength,
|
ArcWithLength,
|
||||||
SplinePath,
|
SplinePath,
|
||||||
|
CubicBezierPath,
|
||||||
CutSplinePath,
|
CutSplinePath,
|
||||||
PointOfContact,
|
PointOfContact,
|
||||||
Detail,
|
Detail,
|
||||||
|
@ -129,6 +130,7 @@ enum class Vis : ToolVisHolderType
|
||||||
ToolShoulderPoint,
|
ToolShoulderPoint,
|
||||||
ToolSpline,
|
ToolSpline,
|
||||||
ToolCubicBezier,
|
ToolCubicBezier,
|
||||||
|
ToolCubicBezierPath,
|
||||||
ToolTriangle,
|
ToolTriangle,
|
||||||
ToolCutSpline,
|
ToolCutSpline,
|
||||||
ToolSplinePath,
|
ToolSplinePath,
|
||||||
|
|
|
@ -35,7 +35,8 @@ HEADERS += \
|
||||||
$$PWD/support/dialogundo.h \
|
$$PWD/support/dialogundo.h \
|
||||||
$$PWD/tools/dialogtruedarts.h \
|
$$PWD/tools/dialogtruedarts.h \
|
||||||
$$PWD/tools/dialogpointofintersectioncurves.h \
|
$$PWD/tools/dialogpointofintersectioncurves.h \
|
||||||
$$PWD/tools/dialogcubicbezier.h
|
$$PWD/tools/dialogcubicbezier.h \
|
||||||
|
$$PWD/tools/dialogcubicbezierpath.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/tools/dialogalongline.cpp \
|
$$PWD/tools/dialogalongline.cpp \
|
||||||
|
@ -70,7 +71,8 @@ SOURCES += \
|
||||||
$$PWD/support/dialogundo.cpp \
|
$$PWD/support/dialogundo.cpp \
|
||||||
$$PWD/tools/dialogtruedarts.cpp \
|
$$PWD/tools/dialogtruedarts.cpp \
|
||||||
$$PWD/tools/dialogpointofintersectioncurves.cpp \
|
$$PWD/tools/dialogpointofintersectioncurves.cpp \
|
||||||
$$PWD/tools/dialogcubicbezier.cpp
|
$$PWD/tools/dialogcubicbezier.cpp \
|
||||||
|
$$PWD/tools/dialogcubicbezierpath.cpp
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
$$PWD/tools/dialogalongline.ui \
|
$$PWD/tools/dialogalongline.ui \
|
||||||
|
@ -104,4 +106,5 @@ FORMS += \
|
||||||
$$PWD/support/dialogundo.ui \
|
$$PWD/support/dialogundo.ui \
|
||||||
$$PWD/tools/dialogtruedarts.ui \
|
$$PWD/tools/dialogtruedarts.ui \
|
||||||
$$PWD/tools/dialogpointofintersectioncurves.ui \
|
$$PWD/tools/dialogpointofintersectioncurves.ui \
|
||||||
$$PWD/tools/dialogcubicbezier.ui
|
$$PWD/tools/dialogcubicbezier.ui \
|
||||||
|
$$PWD/tools/dialogcubicbezierpath.ui
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include "dialogs/tools/dialogspline.h"
|
#include "dialogs/tools/dialogspline.h"
|
||||||
#include "dialogs/tools/dialogcubicbezier.h"
|
#include "dialogs/tools/dialogcubicbezier.h"
|
||||||
#include "dialogs/tools/dialogsplinepath.h"
|
#include "dialogs/tools/dialogsplinepath.h"
|
||||||
|
#include "dialogs/tools/dialogcubicbezierpath.h"
|
||||||
#include "dialogs/tools/dialogheight.h"
|
#include "dialogs/tools/dialogheight.h"
|
||||||
#include "dialogs/tools/dialogcutarc.h"
|
#include "dialogs/tools/dialogcutarc.h"
|
||||||
#include "dialogs/tools/dialogcutspline.h"
|
#include "dialogs/tools/dialogcutspline.h"
|
||||||
|
|
318
src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp
Normal file
|
@ -0,0 +1,318 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @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);
|
||||||
|
|
||||||
|
if (ui->listWidget->count() > 0)
|
||||||
|
{
|
||||||
|
ui->listWidget->setCurrentRow(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
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 (AllPathBackboneIds().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)
|
||||||
|
{
|
||||||
|
const int size = path.CountPoints();
|
||||||
|
if (size >= 7)
|
||||||
|
{
|
||||||
|
if (size - VCubicBezierPath::SubSplPointsCount(path.CountSubSpl()) == 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::AllPathBackboneIds() 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 = VCubicBezierPath::CountSubSpl(points.size());// Count subpaths
|
||||||
|
for (qint32 i = 1; i <= count; ++i)
|
||||||
|
{
|
||||||
|
const qint32 base = VCubicBezierPath::SubSplOffset(i);
|
||||||
|
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 (AllPathBackboneIds().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);
|
||||||
|
}
|
80
src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h
Normal 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> AllPathBackboneIds() const;
|
||||||
|
bool IsPathValid() const;
|
||||||
|
VCubicBezierPath ExtractPath() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DIALOGCUBICBEZIERPATH_H
|
130
src/libs/vtools/dialogs/tools/dialogcubicbezierpath.ui
Normal 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>
|
|
@ -127,7 +127,7 @@ void DialogSplinePath::SetPath(const VSplinePath &value)
|
||||||
this->path = value;
|
this->path = value;
|
||||||
ui->listWidget->blockSignals(true);
|
ui->listWidget->blockSignals(true);
|
||||||
ui->listWidget->clear();
|
ui->listWidget->clear();
|
||||||
for (qint32 i = 0; i < path.CountPoint(); ++i)
|
for (qint32 i = 0; i < path.CountPoints(); ++i)
|
||||||
{
|
{
|
||||||
NewItem(path.at(i));
|
NewItem(path.at(i));
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ void DialogSplinePath::ChosenObject(quint32 id, const SceneObject &type)
|
||||||
SCASSERT(visPath != nullptr);
|
SCASSERT(visPath != nullptr);
|
||||||
visPath->setPath(path);
|
visPath->setPath(path);
|
||||||
|
|
||||||
if (path.CountPoint() == 1)
|
if (path.CountPoints() == 1)
|
||||||
{
|
{
|
||||||
visPath->VisualMode(NULL_ID);
|
visPath->VisualMode(NULL_ID);
|
||||||
connect(visPath, &VisToolSplinePath::ToolTip, this, &DialogTool::ShowVisToolTip);
|
connect(visPath, &VisToolSplinePath::ToolTip, this, &DialogTool::ShowVisToolTip);
|
||||||
|
@ -666,7 +666,7 @@ void DialogSplinePath::currentPointChanged(int index)
|
||||||
auto first = qvariant_cast<VSplinePoint>(ui->listWidget->item(0)->data(Qt::UserRole));
|
auto first = qvariant_cast<VSplinePoint>(ui->listWidget->item(0)->data(Qt::UserRole));
|
||||||
auto last = qvariant_cast<VSplinePoint>(ui->listWidget->item(ui->listWidget->count()-1)->data(Qt::UserRole));
|
auto last = qvariant_cast<VSplinePoint>(ui->listWidget->item(ui->listWidget->count()-1)->data(Qt::UserRole));
|
||||||
|
|
||||||
if (first.P().id() == path.at(0).P().id() && last.P().id() == path.at(path.CountPoint()-1).P().id())
|
if (first.P().id() == path.at(0).P().id() && last.P().id() == path.at(path.CountPoints()-1).P().id())
|
||||||
{
|
{
|
||||||
newDuplicate = -1;
|
newDuplicate = -1;
|
||||||
ui->lineEditSplPathName->setText(path.name());
|
ui->lineEditSplPathName->setText(path.name());
|
||||||
|
@ -694,7 +694,7 @@ void DialogSplinePath::ShowDialog(bool click)
|
||||||
{
|
{
|
||||||
if (click == false)
|
if (click == false)
|
||||||
{
|
{
|
||||||
if (path.CountPoint() >= 3)
|
if (path.CountPoints() >= 3)
|
||||||
{
|
{
|
||||||
emit ToolTip("");
|
emit ToolTip("");
|
||||||
|
|
||||||
|
@ -888,12 +888,12 @@ QSet<quint32> DialogSplinePath::AllIds() const
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool DialogSplinePath::IsPathValid() const
|
bool DialogSplinePath::IsPathValid() const
|
||||||
{
|
{
|
||||||
if (path.CountPoint() < 3)
|
if (path.CountPoints() < 3)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (AllIds().size() == path.CountPoint());
|
return (AllIds().size() == path.CountPoints());
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include "toolcurve/vtoolspline.h"
|
#include "toolcurve/vtoolspline.h"
|
||||||
#include "toolcurve/vtoolcubicbezier.h"
|
#include "toolcurve/vtoolcubicbezier.h"
|
||||||
#include "toolcurve/vtoolsplinepath.h"
|
#include "toolcurve/vtoolsplinepath.h"
|
||||||
|
#include "toolcurve/vtoolcubicbezierpath.h"
|
||||||
#include "vtoolline.h"
|
#include "vtoolline.h"
|
||||||
#include "toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h"
|
#include "toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h"
|
||||||
#include "toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h"
|
#include "toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h"
|
||||||
|
|
|
@ -73,7 +73,7 @@ protected:
|
||||||
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) Q_DECL_OVERRIDE;
|
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) Q_DECL_OVERRIDE;
|
||||||
virtual void SetVisualization() Q_DECL_OVERRIDE;
|
virtual void SetVisualization() Q_DECL_OVERRIDE;
|
||||||
private:
|
private:
|
||||||
void RefreshGeometry();
|
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VTOOLARC_H
|
#endif // VTOOLARC_H
|
||||||
|
|
|
@ -74,7 +74,7 @@ protected:
|
||||||
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) Q_DECL_OVERRIDE;
|
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) Q_DECL_OVERRIDE;
|
||||||
virtual void SetVisualization() Q_DECL_OVERRIDE;
|
virtual void SetVisualization() Q_DECL_OVERRIDE;
|
||||||
private:
|
private:
|
||||||
void RefreshGeometry();
|
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VToolCubicBezier)
|
Q_DISABLE_COPY(VToolCubicBezier)
|
||||||
|
|
||||||
void RefreshGeometry ();
|
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
|
||||||
void SetSplineAttributes(QDomElement &domElement, const VCubicBezier &spl);
|
void SetSplineAttributes(QDomElement &domElement, const VCubicBezier &spl);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -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
|
|
@ -81,7 +81,7 @@ private:
|
||||||
QPointF oldPosition;
|
QPointF oldPosition;
|
||||||
|
|
||||||
bool IsMovable() const;
|
bool IsMovable() const;
|
||||||
void RefreshGeometry ();
|
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
|
||||||
void SetSplineAttributes(QDomElement &domElement, const VSpline &spl);
|
void SetSplineAttributes(QDomElement &domElement, const VSpline &spl);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3
|
||||||
this->setAcceptHoverEvents(true);
|
this->setAcceptHoverEvents(true);
|
||||||
|
|
||||||
const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(id);
|
const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(id);
|
||||||
for (qint32 i = 1; i<=splPath->Count(); ++i)
|
for (qint32 i = 1; i<=splPath->CountSubSpl(); ++i)
|
||||||
{
|
{
|
||||||
const VSpline spl = splPath->GetSpline(i);
|
const VSpline spl = splPath->GetSpline(i);
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ VToolSplinePath* VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene
|
||||||
SCASSERT(dialogTool != nullptr);
|
SCASSERT(dialogTool != nullptr);
|
||||||
VSplinePath *path = new VSplinePath(dialogTool->GetPath());
|
VSplinePath *path = new VSplinePath(dialogTool->GetPath());
|
||||||
const QString color = dialogTool->GetColor();
|
const QString color = dialogTool->GetColor();
|
||||||
for (qint32 i = 0; i < path->CountPoint(); ++i)
|
for (qint32 i = 0; i < path->CountPoints(); ++i)
|
||||||
{
|
{
|
||||||
doc->IncrementReferens((*path)[i].P().getIdTool());
|
doc->IncrementReferens((*path)[i].P().getIdTool());
|
||||||
}
|
}
|
||||||
|
@ -302,7 +302,7 @@ void VToolSplinePath::SetSplinePathAttributes(QDomElement &domElement, const VSp
|
||||||
void VToolSplinePath::UpdatePathPoints(VAbstractPattern *doc, QDomElement &element, const VSplinePath &path)
|
void VToolSplinePath::UpdatePathPoints(VAbstractPattern *doc, QDomElement &element, const VSplinePath &path)
|
||||||
{
|
{
|
||||||
VDomDocument::RemoveAllChildren(element);
|
VDomDocument::RemoveAllChildren(element);
|
||||||
for (qint32 i = 0; i < path.CountPoint(); ++i)
|
for (qint32 i = 0; i < path.CountPoints(); ++i)
|
||||||
{
|
{
|
||||||
AddPathPoint(doc, element, path.at(i));
|
AddPathPoint(doc, element, path.at(i));
|
||||||
}
|
}
|
||||||
|
@ -389,10 +389,10 @@ void VToolSplinePath::AddPathPoint(VAbstractPattern *doc, QDomElement &domElemen
|
||||||
*/
|
*/
|
||||||
void VToolSplinePath::RemoveReferens()
|
void VToolSplinePath::RemoveReferens()
|
||||||
{
|
{
|
||||||
const VSplinePath splPath = *VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
const QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
||||||
for (qint32 i = 0; i < splPath.Count(); ++i)
|
for (qint32 i = 0; i < splPath->CountSubSpl(); ++i)
|
||||||
{
|
{
|
||||||
doc->DecrementReferens(splPath.at(i).P().getIdTool());
|
doc->DecrementReferens(splPath->at(i).P().getIdTool());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,7 +407,7 @@ void VToolSplinePath::SaveDialog(QDomElement &domElement)
|
||||||
SCASSERT(dialogTool != nullptr);
|
SCASSERT(dialogTool != nullptr);
|
||||||
|
|
||||||
const VSplinePath splPath = dialogTool->GetPath();
|
const VSplinePath splPath = dialogTool->GetPath();
|
||||||
for (qint32 i = 1; i <= splPath.Count(); ++i)
|
for (qint32 i = 1; i <= splPath.CountSubSpl(); ++i)
|
||||||
{
|
{
|
||||||
VSpline spl = splPath.GetSpline(i);
|
VSpline spl = splPath.GetSpline(i);
|
||||||
qint32 j = i*2;
|
qint32 j = i*2;
|
||||||
|
@ -605,7 +605,7 @@ bool VToolSplinePath::IsMovable(int index) const
|
||||||
const auto splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
const auto splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
||||||
|
|
||||||
//index == -1 - can delete, but decided to left
|
//index == -1 - can delete, but decided to left
|
||||||
if (index == -1 || index < 1 || index > splPath->Count())
|
if (index == -1 || index < 1 || index > splPath->CountSubSpl())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -641,7 +641,7 @@ void VToolSplinePath::RefreshGeometry()
|
||||||
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
|
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
|
||||||
|
|
||||||
const auto splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
const auto splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
||||||
for (qint32 i = 1; i<=splPath->Count(); ++i)
|
for (qint32 i = 1; i<=splPath->CountSubSpl(); ++i)
|
||||||
{
|
{
|
||||||
const qint32 j = i*2;
|
const qint32 j = i*2;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
const Source &typeCreation,
|
const Source &typeCreation,
|
||||||
QGraphicsItem * parent = nullptr);
|
QGraphicsItem * parent = nullptr);
|
||||||
virtual ~VToolSplinePath() Q_DECL_OVERRIDE;
|
virtual ~VToolSplinePath() Q_DECL_OVERRIDE;
|
||||||
virtual void setDialog();
|
virtual void setDialog() Q_DECL_OVERRIDE;
|
||||||
static VToolSplinePath *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
|
static VToolSplinePath *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
|
||||||
VContainer *data);
|
VContainer *data);
|
||||||
static VToolSplinePath *Create(const quint32 _id, VSplinePath *path, const QString &color,
|
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 hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
|
||||||
virtual void SetVisualization() Q_DECL_OVERRIDE;
|
virtual void SetVisualization() Q_DECL_OVERRIDE;
|
||||||
private:
|
private:
|
||||||
|
Q_DISABLE_COPY(VToolSplinePath)
|
||||||
QPointF oldPosition;
|
QPointF oldPosition;
|
||||||
int splIndex;
|
int splIndex;
|
||||||
|
|
||||||
bool IsMovable(int index) const;
|
bool IsMovable(int index) const;
|
||||||
void RefreshGeometry();
|
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
|
||||||
static void AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VSplinePoint &splPoint);
|
static void AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VSplinePoint &splPoint);
|
||||||
void UpdateControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline) const;
|
void UpdateControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline) const;
|
||||||
void SetSplinePathAttributes(QDomElement &domElement, const VSplinePath &path);
|
void SetSplinePathAttributes(QDomElement &domElement, const VSplinePath &path);
|
||||||
|
|
|
@ -154,7 +154,7 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString
|
||||||
VSplinePath *splPath1 = new VSplinePath();
|
VSplinePath *splPath1 = new VSplinePath();
|
||||||
VSplinePath *splPath2 = new VSplinePath();
|
VSplinePath *splPath2 = new VSplinePath();
|
||||||
|
|
||||||
for (qint32 i = 0; i < splPath->CountPoint(); i++)
|
for (qint32 i = 0; i < splPath->CountPoints(); i++)
|
||||||
{
|
{
|
||||||
if (i <= p1 && i < p2)
|
if (i <= p1 && i < p2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,7 +48,8 @@ HEADERS += \
|
||||||
$$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h \
|
$$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h \
|
||||||
$$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h \
|
$$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h \
|
||||||
$$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h \
|
$$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h \
|
||||||
$$PWD/drawTools/toolcurve/vtoolcubicbezier.h
|
$$PWD/drawTools/toolcurve/vtoolcubicbezier.h \
|
||||||
|
$$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/vtooldetail.cpp \
|
$$PWD/vtooldetail.cpp \
|
||||||
|
@ -94,4 +95,5 @@ SOURCES += \
|
||||||
$$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp \
|
$$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp \
|
||||||
$$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp \
|
$$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp \
|
||||||
$$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp \
|
$$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp \
|
||||||
$$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp
|
$$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp \
|
||||||
|
$$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp
|
||||||
|
|
|
@ -216,7 +216,7 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte
|
||||||
VSplinePath *path = new VSplinePath();
|
VSplinePath *path = new VSplinePath();
|
||||||
path->setMode(Draw::Modeling);
|
path->setMode(Draw::Modeling);
|
||||||
const QSharedPointer<VSplinePath> splinePath = data->GeometricObject<VSplinePath>(det.at(i).getId());
|
const QSharedPointer<VSplinePath> splinePath = data->GeometricObject<VSplinePath>(det.at(i).getId());
|
||||||
for (qint32 i = 1; i <= splinePath->Count(); ++i)
|
for (qint32 i = 1; i <= splinePath->CountSubSpl(); ++i)
|
||||||
{
|
{
|
||||||
const VSplinePoint &point1 = splinePath->at(i-1);
|
const VSplinePoint &point1 = splinePath->at(i-1);
|
||||||
const VSplinePoint &point2 = splinePath->at(i);
|
const VSplinePoint &point2 = splinePath->at(i);
|
||||||
|
@ -366,7 +366,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const
|
||||||
path->setMode(Draw::Modeling);
|
path->setMode(Draw::Modeling);
|
||||||
const QSharedPointer<VSplinePath> splinePath = data->GeometricObject<VSplinePath>(det.at(i).getId());
|
const QSharedPointer<VSplinePath> splinePath = data->GeometricObject<VSplinePath>(det.at(i).getId());
|
||||||
SCASSERT(splinePath != nullptr);
|
SCASSERT(splinePath != nullptr);
|
||||||
for (qint32 i = 1; i <= splinePath->Count(); ++i)
|
for (qint32 i = 1; i <= splinePath->CountSubSpl(); ++i)
|
||||||
{
|
{
|
||||||
const VSplinePoint &point1 = splinePath->at(i-1);
|
const VSplinePoint &point1 = splinePath->at(i-1);
|
||||||
const VSplinePoint &point2 = splinePath->at(i);
|
const VSplinePoint &point2 = splinePath->at(i);
|
||||||
|
|
|
@ -39,14 +39,16 @@ VisToolCubicBezier::VisToolCubicBezier(const VContainer *data, QGraphicsItem *pa
|
||||||
point2(nullptr),
|
point2(nullptr),
|
||||||
point3(nullptr),
|
point3(nullptr),
|
||||||
point4(nullptr),
|
point4(nullptr),
|
||||||
helpLine(nullptr)
|
helpLine1(nullptr),
|
||||||
|
helpLine2(nullptr)
|
||||||
{
|
{
|
||||||
|
helpLine1 = InitItem<QGraphicsLineItem>(mainColor, this);
|
||||||
|
helpLine2 = InitItem<QGraphicsLineItem>(mainColor, this);
|
||||||
|
|
||||||
point1 = InitPoint(supportColor, this);
|
point1 = InitPoint(supportColor, this);
|
||||||
point2 = InitPoint(supportColor, this); //-V656
|
point2 = InitPoint(supportColor, this); //-V656
|
||||||
point3 = InitPoint(supportColor, this); //-V656
|
point3 = InitPoint(supportColor, this); //-V656
|
||||||
point4 = InitPoint(supportColor, this); //-V656
|
point4 = InitPoint(supportColor, this); //-V656
|
||||||
|
|
||||||
helpLine = InitItem<QGraphicsLineItem>(mainColor, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -60,19 +62,17 @@ void VisToolCubicBezier::RefreshGeometry()
|
||||||
if (object1Id > NULL_ID)
|
if (object1Id > NULL_ID)
|
||||||
{
|
{
|
||||||
const auto first = Visualization::data->GeometricObject<VPointF>(object1Id);
|
const auto first = Visualization::data->GeometricObject<VPointF>(object1Id);
|
||||||
DrawPoint(point1, first->toQPointF(), supportColor);
|
DrawPoint(point1, first->toQPointF(), Qt::DashLine);
|
||||||
|
|
||||||
if (object2Id <= NULL_ID)
|
if (object2Id <= NULL_ID)
|
||||||
{
|
{
|
||||||
const QLineF line = QLineF(first->toQPointF(), Visualization::scenePos);
|
DrawLine(helpLine1, QLineF(first->toQPointF(), Visualization::scenePos), mainColor, Qt::DashLine);
|
||||||
DrawLine(helpLine, line, mainColor, lineStyle);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
helpLine->setVisible(false);
|
|
||||||
|
|
||||||
const auto second = Visualization::data->GeometricObject<VPointF>(object2Id);
|
const auto second = Visualization::data->GeometricObject<VPointF>(object2Id);
|
||||||
DrawPoint(point2, second->toQPointF(), supportColor);
|
DrawPoint(point2, second->toQPointF(), supportColor);
|
||||||
|
DrawLine(helpLine1, QLineF(first->toQPointF(), second->toQPointF()), mainColor, Qt::DashLine);
|
||||||
|
|
||||||
if (object3Id <= NULL_ID)
|
if (object3Id <= NULL_ID)
|
||||||
{
|
{
|
||||||
|
@ -89,11 +89,13 @@ void VisToolCubicBezier::RefreshGeometry()
|
||||||
{
|
{
|
||||||
VCubicBezier spline(*first, *second, *third, VPointF(Visualization::scenePos));
|
VCubicBezier spline(*first, *second, *third, VPointF(Visualization::scenePos));
|
||||||
DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap);
|
DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap);
|
||||||
|
DrawLine(helpLine2, QLineF(third->toQPointF(), Visualization::scenePos), mainColor, Qt::DashLine);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const auto fourth = Visualization::data->GeometricObject<VPointF>(object4Id);
|
const auto fourth = Visualization::data->GeometricObject<VPointF>(object4Id);
|
||||||
DrawPoint(point4, fourth->toQPointF(), supportColor);
|
DrawPoint(point4, fourth->toQPointF(), supportColor);
|
||||||
|
DrawLine(helpLine2, QLineF(fourth->toQPointF(), third->toQPointF()), mainColor, Qt::DashLine);
|
||||||
|
|
||||||
VCubicBezier spline(*first, *second, *third, *fourth);
|
VCubicBezier spline(*first, *second, *third, *fourth);
|
||||||
DrawPath(this, spline.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap);
|
DrawPath(this, spline.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap);
|
||||||
|
|
|
@ -56,7 +56,8 @@ protected:
|
||||||
QGraphicsEllipseItem *point2;
|
QGraphicsEllipseItem *point2;
|
||||||
QGraphicsEllipseItem *point3;
|
QGraphicsEllipseItem *point3;
|
||||||
QGraphicsEllipseItem *point4;
|
QGraphicsEllipseItem *point4;
|
||||||
QGraphicsLineItem *helpLine;
|
QGraphicsLineItem *helpLine1;
|
||||||
|
QGraphicsLineItem *helpLine2;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VISTOOLCUBICBEZIER_H
|
#endif // VISTOOLCUBICBEZIER_H
|
||||||
|
|
280
src/libs/vtools/visualization/vistoolcubicbezierpath.cpp
Normal file
|
@ -0,0 +1,280 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @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()
|
||||||
|
{
|
||||||
|
const QVector<VPointF> pathPoints = path.GetSplinePath();
|
||||||
|
const int size = pathPoints.size();
|
||||||
|
if (size > 0)
|
||||||
|
{
|
||||||
|
const int countSubSpl = VCubicBezierPath::CountSubSpl(size);
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
if (countSubSpl < 1)
|
||||||
|
{
|
||||||
|
Creating(pathPoints, size-1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const qint32 last = VCubicBezierPath::SubSplOffset(countSubSpl) + 3;
|
||||||
|
Creating(pathPoints, size-1-last);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (countSubSpl >= 1)
|
||||||
|
{
|
||||||
|
DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RefreshToolTip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VisToolCubicBezierPath::setPath(const VCubicBezierPath &value)
|
||||||
|
{
|
||||||
|
path = value;
|
||||||
|
|
||||||
|
RefreshToolTip();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
const int size = pathPoints.size();
|
||||||
|
if (pathPoints.isEmpty() || size+1 < pointsLeft)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int subSplPoints = 0;
|
||||||
|
const int subSplCount = VCubicBezierPath::CountSubSpl(size);
|
||||||
|
if (subSplCount >= 1)
|
||||||
|
{
|
||||||
|
subSplPoints = VCubicBezierPath::SubSplPointsCount(subSplCount)-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(pointsLeft)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
{
|
||||||
|
const VPointF p1 = pathPoints.last();
|
||||||
|
if (pathPoints.size() >= 4)
|
||||||
|
{
|
||||||
|
QLineF p1p2(p1.toQPointF(), Visualization::scenePos);
|
||||||
|
QLineF prP3p1(pathPoints.at(size-2).toQPointF(), p1.toQPointF());
|
||||||
|
p1p2.setAngle(prP3p1.angle());
|
||||||
|
|
||||||
|
const QPointF p2 = p1p2.p2();
|
||||||
|
|
||||||
|
VSpline spline(p1, p2, Visualization::scenePos, VPointF(Visualization::scenePos));
|
||||||
|
DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap);
|
||||||
|
|
||||||
|
DrawLine(helpLine1, p1p2, mainColor, Qt::DashLine);
|
||||||
|
|
||||||
|
const int preLastPoint = subSplCount * 2;
|
||||||
|
QGraphicsEllipseItem *p2Ctrl = this->getPoint(ctrlPoints, static_cast<unsigned>(preLastPoint));
|
||||||
|
DrawPoint(p2Ctrl, p2, Qt::green);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DrawLine(helpLine1, QLineF(p1.toQPointF(), Visualization::scenePos), mainColor, Qt::DashLine);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
const VPointF p1 = pathPoints.at(subSplPoints + pointsLeft-1);
|
||||||
|
QPointF p2 = pathPoints.at(subSplPoints + pointsLeft).toQPointF();
|
||||||
|
|
||||||
|
if (subSplCount >= 1)
|
||||||
|
{
|
||||||
|
QLineF p1p2(p1.toQPointF(), p2);
|
||||||
|
QLineF prP3p1(pathPoints.at(subSplPoints + pointsLeft-2).toQPointF(), p1.toQPointF());
|
||||||
|
p1p2.setAngle(prP3p1.angle());
|
||||||
|
p2 = p1p2.p2();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
const int preLastPoint = subSplCount * 2;
|
||||||
|
QGraphicsEllipseItem *p2Ctrl = this->getPoint(ctrlPoints, static_cast<unsigned>(preLastPoint));
|
||||||
|
DrawPoint(p2Ctrl, p2, Qt::green);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
const VPointF p1 = pathPoints.at(subSplPoints + pointsLeft-2);
|
||||||
|
QPointF p2 = pathPoints.at(subSplPoints + pointsLeft-1).toQPointF();
|
||||||
|
const QPointF p3 = pathPoints.at(subSplPoints + pointsLeft).toQPointF();
|
||||||
|
|
||||||
|
if (subSplCount >= 1)
|
||||||
|
{
|
||||||
|
QLineF p1p2(p1.toQPointF(), p2);
|
||||||
|
QLineF prP3p1(pathPoints.at(subSplPoints + pointsLeft-3).toQPointF(), p1.toQPointF());
|
||||||
|
p1p2.setAngle(prP3p1.angle());
|
||||||
|
p2 = p1p2.p2();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
const int preLastPoint = subSplCount * 2;
|
||||||
|
QGraphicsEllipseItem *p2Ctrl = this->getPoint(ctrlPoints, static_cast<unsigned>(preLastPoint));
|
||||||
|
DrawPoint(p2Ctrl, p2, Qt::green);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VisToolCubicBezierPath::RefreshToolTip()
|
||||||
|
{
|
||||||
|
const int size = path.CountPoints();
|
||||||
|
if (size > 0)
|
||||||
|
{
|
||||||
|
const int countSubSpl = VCubicBezierPath::CountSubSpl(size);
|
||||||
|
|
||||||
|
if (size < 7)
|
||||||
|
{
|
||||||
|
Visualization::toolTip = tr("<b>Curved path</b>: select seven or more points");
|
||||||
|
}
|
||||||
|
else if (size >= 7 && size - VCubicBezierPath::SubSplPointsCount(countSubSpl) == 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");
|
||||||
|
}
|
||||||
|
emit ToolTip(Visualization::toolTip);
|
||||||
|
}
|
||||||
|
}
|
67
src/libs/vtools/visualization/vistoolcubicbezierpath.h
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @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;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QGraphicsEllipseItem *getPoint(QVector<QGraphicsEllipseItem *> &points, quint32 i, qreal z = 0);
|
||||||
|
QGraphicsLineItem *getLine(quint32 i);
|
||||||
|
void Creating(const QVector<VPointF> &pathPoints , int pointsLeft);
|
||||||
|
void RefreshToolTip();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VISTOOLCUBICBEZIERPATH_H
|
|
@ -73,7 +73,7 @@ void VisToolCutSplinePath::RefreshGeometry()
|
||||||
VSplinePath spPath1 = VSplinePath();
|
VSplinePath spPath1 = VSplinePath();
|
||||||
VSplinePath spPath2 = VSplinePath();
|
VSplinePath spPath2 = VSplinePath();
|
||||||
|
|
||||||
for (qint32 i = 0; i < splPath->CountPoint(); i++)
|
for (qint32 i = 0; i < splPath->CountPoints(); i++)
|
||||||
{
|
{
|
||||||
if (i <= p1 && i < p2)
|
if (i <= p1 && i < p2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,7 +53,7 @@ VisToolSplinePath::~VisToolSplinePath()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VisToolSplinePath::RefreshGeometry()
|
void VisToolSplinePath::RefreshGeometry()
|
||||||
{
|
{
|
||||||
if (path.CountPoint() > 0)
|
if (path.CountPoints() > 0)
|
||||||
{
|
{
|
||||||
const QVector<VSplinePoint> pathPoints = path.GetSplinePath();
|
const QVector<VSplinePoint> pathPoints = path.GetSplinePath();
|
||||||
const int size = pathPoints.size();
|
const int size = pathPoints.size();
|
||||||
|
@ -68,9 +68,9 @@ void VisToolSplinePath::RefreshGeometry()
|
||||||
{
|
{
|
||||||
if (size > 1)
|
if (size > 1)
|
||||||
{
|
{
|
||||||
for (qint32 i = 1; i<=path.Count(); ++i)
|
for (qint32 i = 1; i<=path.CountSubSpl(); ++i)
|
||||||
{
|
{
|
||||||
const int preLastPoint = (path.Count() - 1) * 2;
|
const int preLastPoint = (path.CountSubSpl() - 1) * 2;
|
||||||
const int lastPoint = preLastPoint + 1;
|
const int lastPoint = preLastPoint + 1;
|
||||||
|
|
||||||
VSpline spl = path.GetSpline(i);
|
VSpline spl = path.GetSpline(i);
|
||||||
|
@ -90,7 +90,7 @@ void VisToolSplinePath::RefreshGeometry()
|
||||||
DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap);
|
DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path.CountPoint() < 3)
|
if (path.CountPoints() < 3)
|
||||||
{
|
{
|
||||||
Visualization::toolTip = tr("<b>Curved path</b>: select three or more points");
|
Visualization::toolTip = tr("<b>Curved path</b>: select three or more points");
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ class VisToolSplinePath : public VisPath
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit VisToolSplinePath(const VContainer *data, QGraphicsItem *parent = 0);
|
explicit VisToolSplinePath(const VContainer *data, QGraphicsItem *parent = nullptr);
|
||||||
virtual ~VisToolSplinePath() Q_DECL_OVERRIDE;
|
virtual ~VisToolSplinePath() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
|
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
|
||||||
|
|
|
@ -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);
|
QGraphicsEllipseItem *point = new QGraphicsEllipseItem(parent);
|
||||||
point->setZValue(1);
|
point->setZValue(1);
|
||||||
|
@ -122,6 +122,7 @@ QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsIte
|
||||||
point->setRect(PointRect(ToPixel(DefPointRadius/*mm*/, Unit::Mm)));
|
point->setRect(PointRect(ToPixel(DefPointRadius/*mm*/, Unit::Mm)));
|
||||||
point->setPos(QPointF());
|
point->setPos(QPointF());
|
||||||
point->setFlags(QGraphicsItem::ItemStacksBehindParent);
|
point->setFlags(QGraphicsItem::ItemStacksBehindParent);
|
||||||
|
point->setZValue(z);
|
||||||
point->setVisible(false);
|
point->setVisible(false);
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ protected:
|
||||||
virtual void InitPen()=0;
|
virtual void InitPen()=0;
|
||||||
virtual void AddOnScene()=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;
|
QRectF PointRect(const qreal &radius) const;
|
||||||
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color,
|
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color,
|
||||||
Qt::PenStyle style = Qt::SolidLine);
|
Qt::PenStyle style = Qt::SolidLine);
|
||||||
|
|
|
@ -31,7 +31,8 @@ HEADERS += \
|
||||||
$$PWD/vistoolarcwithlength.h \
|
$$PWD/vistoolarcwithlength.h \
|
||||||
$$PWD/vistooltruedarts.h \
|
$$PWD/vistooltruedarts.h \
|
||||||
$$PWD/vistoolpointofintersectioncurves.h \
|
$$PWD/vistoolpointofintersectioncurves.h \
|
||||||
$$PWD/vistoolcubicbezier.h
|
$$PWD/vistoolcubicbezier.h \
|
||||||
|
$$PWD/vistoolcubicbezierpath.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/visline.cpp \
|
$$PWD/visline.cpp \
|
||||||
|
@ -63,4 +64,5 @@ SOURCES += \
|
||||||
$$PWD/vistoolarcwithlength.cpp \
|
$$PWD/vistoolarcwithlength.cpp \
|
||||||
$$PWD/vistooltruedarts.cpp \
|
$$PWD/vistooltruedarts.cpp \
|
||||||
$$PWD/vistoolpointofintersectioncurves.cpp \
|
$$PWD/vistoolpointofintersectioncurves.cpp \
|
||||||
$$PWD/vistoolcubicbezier.cpp
|
$$PWD/vistoolcubicbezier.cpp \
|
||||||
|
$$PWD/vistoolcubicbezierpath.cpp
|
||||||
|
|
|
@ -56,7 +56,8 @@ SOURCES += \
|
||||||
tst_vdetail.cpp \
|
tst_vdetail.cpp \
|
||||||
tst_vabstractcurve.cpp \
|
tst_vabstractcurve.cpp \
|
||||||
tst_findpoint.cpp \
|
tst_findpoint.cpp \
|
||||||
tst_vellipticalarc.cpp
|
tst_vellipticalarc.cpp \
|
||||||
|
tst_vcubicbezierpath.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
tst_vposter.h \
|
tst_vposter.h \
|
||||||
|
@ -80,7 +81,8 @@ HEADERS += \
|
||||||
tst_vdetail.h \
|
tst_vdetail.h \
|
||||||
tst_vabstractcurve.h \
|
tst_vabstractcurve.h \
|
||||||
tst_findpoint.h \
|
tst_findpoint.h \
|
||||||
tst_vellipticalarc.h
|
tst_vellipticalarc.h \
|
||||||
|
tst_vcubicbezierpath.h
|
||||||
|
|
||||||
# Set using ccache. Function enable_ccache() defined in common.pri.
|
# Set using ccache. Function enable_ccache() defined in common.pri.
|
||||||
$$enable_ccache()
|
$$enable_ccache()
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#include "tst_vdetail.h"
|
#include "tst_vdetail.h"
|
||||||
#include "tst_findpoint.h"
|
#include "tst_findpoint.h"
|
||||||
#include "tst_vabstractcurve.h"
|
#include "tst_vabstractcurve.h"
|
||||||
|
#include "tst_vcubicbezierpath.h"
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
@ -82,6 +83,7 @@ int main(int argc, char** argv)
|
||||||
ASSERT_TEST(new TST_VCommandLine());
|
ASSERT_TEST(new TST_VCommandLine());
|
||||||
ASSERT_TEST(new TST_TSTranslation());
|
ASSERT_TEST(new TST_TSTranslation());
|
||||||
ASSERT_TEST(new TST_VAbstractCurve());
|
ASSERT_TEST(new TST_VAbstractCurve());
|
||||||
|
ASSERT_TEST(new TST_VCubicBezierPath());
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
122
src/test/ValentinaTest/tst_vcubicbezierpath.cpp
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file tst_vcubicbezierpath.cpp
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 19 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 "tst_vcubicbezierpath.h"
|
||||||
|
#include "../vgeometry/vcubicbezierpath.h"
|
||||||
|
|
||||||
|
#include <QtTest>
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
TST_VCubicBezierPath::TST_VCubicBezierPath(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TST_VCubicBezierPath::TestCountSubSpl_data() const
|
||||||
|
{
|
||||||
|
QTest::addColumn<qint32>("points");
|
||||||
|
QTest::addColumn<qint32>("countSubSpl");
|
||||||
|
|
||||||
|
QTest::newRow("Empty") << 0 << 0;
|
||||||
|
QTest::newRow("1 point") << 1 << 0;
|
||||||
|
QTest::newRow("2 points") << 2 << 0;
|
||||||
|
QTest::newRow("3 points") << 3 << 0;
|
||||||
|
QTest::newRow("4 points") << 4 << 1;
|
||||||
|
QTest::newRow("5 points") << 5 << 1;
|
||||||
|
QTest::newRow("6 points") << 6 << 1;
|
||||||
|
QTest::newRow("7 points") << 7 << 2;
|
||||||
|
QTest::newRow("8 points") << 8 << 2;
|
||||||
|
QTest::newRow("9 points") << 9 << 2;
|
||||||
|
QTest::newRow("10 points") << 10 << 3;
|
||||||
|
QTest::newRow("11 points") << 11 << 3;
|
||||||
|
QTest::newRow("12 points") << 12 << 3;
|
||||||
|
QTest::newRow("13 points") << 13 << 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TST_VCubicBezierPath::TestCountSubSpl() const
|
||||||
|
{
|
||||||
|
QFETCH(qint32, points);
|
||||||
|
QFETCH(qint32, countSubSpl);
|
||||||
|
|
||||||
|
const qint32 res = VCubicBezierPath::CountSubSpl(points);
|
||||||
|
QCOMPARE(res, countSubSpl);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TST_VCubicBezierPath::TestSubSplOffset_data() const
|
||||||
|
{
|
||||||
|
QTest::addColumn<qint32>("subSplIndex");
|
||||||
|
QTest::addColumn<qint32>("offset");
|
||||||
|
|
||||||
|
QTest::newRow("Wrong index") << -1 << -1;
|
||||||
|
QTest::newRow("Wrong index") << 0 << -1;
|
||||||
|
QTest::newRow("1 subSpl") << 1 << 0;
|
||||||
|
QTest::newRow("2 subSpls") << 2 << 3;
|
||||||
|
QTest::newRow("3 subSpls") << 3 << 6;
|
||||||
|
QTest::newRow("4 subSpls") << 4 << 9;
|
||||||
|
QTest::newRow("5 subSpls") << 5 << 12;
|
||||||
|
QTest::newRow("6 subSpls") << 6 << 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TST_VCubicBezierPath::TestSubSplOffset() const
|
||||||
|
{
|
||||||
|
QFETCH(qint32, subSplIndex);
|
||||||
|
QFETCH(qint32, offset);
|
||||||
|
|
||||||
|
const qint32 res = VCubicBezierPath::SubSplOffset(subSplIndex);
|
||||||
|
QCOMPARE(res, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TST_VCubicBezierPath::TestSubSplPointsCount_data() const
|
||||||
|
{
|
||||||
|
QTest::addColumn<qint32>("countSubSpl");
|
||||||
|
QTest::addColumn<qint32>("points");
|
||||||
|
|
||||||
|
QTest::newRow("Wrong count") << -1 << 0;
|
||||||
|
QTest::newRow("Wrong count") << 0 << 0;
|
||||||
|
QTest::newRow("1 subSpl") << 1 << 4;
|
||||||
|
QTest::newRow("2 subSpls") << 2 << 7;
|
||||||
|
QTest::newRow("3 subSpls") << 3 << 10;
|
||||||
|
QTest::newRow("4 subSpls") << 4 << 13;
|
||||||
|
QTest::newRow("5 subSpls") << 5 << 16;
|
||||||
|
QTest::newRow("6 subSpls") << 6 << 19;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TST_VCubicBezierPath::TestSubSplPointsCount() const
|
||||||
|
{
|
||||||
|
QFETCH(qint32, countSubSpl);
|
||||||
|
QFETCH(qint32, points);
|
||||||
|
|
||||||
|
const qint32 res = VCubicBezierPath::SubSplPointsCount(countSubSpl);
|
||||||
|
QCOMPARE(res, points);
|
||||||
|
}
|
53
src/test/ValentinaTest/tst_vcubicbezierpath.h
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file tst_vcubicbezierpath.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 19 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 TST_VCUBICBEZIERPATH_H
|
||||||
|
#define TST_VCUBICBEZIERPATH_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class TST_VCubicBezierPath : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit TST_VCubicBezierPath(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void TestCountSubSpl_data() const;
|
||||||
|
void TestCountSubSpl() const;
|
||||||
|
void TestSubSplOffset_data() const;
|
||||||
|
void TestSubSplOffset() const;
|
||||||
|
void TestSubSplPointsCount_data() const;
|
||||||
|
void TestSubSplPointsCount() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(TST_VCubicBezierPath)
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TST_VCUBICBEZIERPATH_H
|