From 74c60d6008bd1206994702ae4a35f16b1da39cfd Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 13 Mar 2016 16:51:25 +0200 Subject: [PATCH 01/13] Icons for tool Cubic Bezier Path. --HG-- branch : feature --- src/app/valentina/share/resources/cursor.qrc | 2 + .../cursor/cubic_bezier_path_cursor.png | Bin 0 -> 878 bytes .../cursor/cubic_bezier_path_cursor@2x.png | Bin 0 -> 2234 bytes .../valentina/share/resources/toolicon.qrc | 2 + .../toolicon/32x32/cubic_bezier_path.png | Bin 0 -> 1737 bytes .../toolicon/32x32/cubic_bezier_path@2x.png | Bin 0 -> 4232 bytes .../toolicon/svg/cubic_bezier_path.svg | 134 ++++++++++++++++++ 7 files changed, 138 insertions(+) create mode 100644 src/app/valentina/share/resources/cursor/cubic_bezier_path_cursor.png create mode 100644 src/app/valentina/share/resources/cursor/cubic_bezier_path_cursor@2x.png create mode 100644 src/app/valentina/share/resources/toolicon/32x32/cubic_bezier_path.png create mode 100644 src/app/valentina/share/resources/toolicon/32x32/cubic_bezier_path@2x.png create mode 100644 src/app/valentina/share/resources/toolicon/svg/cubic_bezier_path.svg diff --git a/src/app/valentina/share/resources/cursor.qrc b/src/app/valentina/share/resources/cursor.qrc index bde68b73c..a52e2b468 100644 --- a/src/app/valentina/share/resources/cursor.qrc +++ b/src/app/valentina/share/resources/cursor.qrc @@ -62,5 +62,7 @@ cursor/intersection_curves_cursor@2x.png cursor/cubic_bezier_cursor.png cursor/cubic_bezier_cursor@2x.png + cursor/cubic_bezier_path_cursor.png + cursor/cubic_bezier_path_cursor@2x.png diff --git a/src/app/valentina/share/resources/cursor/cubic_bezier_path_cursor.png b/src/app/valentina/share/resources/cursor/cubic_bezier_path_cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..7f6337bf3c70dbac308eea4e2a049d2f9f5b32f7 GIT binary patch literal 878 zcmV-!1CjiRP)o|pgU`Oh#6{Lh~Z0^1S^(1D+cLrGG{ zZ@`R*&ETwn+Jb9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vzf9sPq2h+slmXcfAop!|% z@Hvr6zYN$F$N0K~+y{jTu%->xJ~>VP!4RAff@OhoiDNrzB*2z}-GH*B%v}r{-)%mNPgONiZI4>TWvz_=oUN{L;-WQQs9 zJ8NTTlmQ_LlPtK)f*+K_xH`yECJ(LHAwQkeB2qYXEC9LL|TArnm5Cp;?6uACgY@haQHn$!*WG$$Y z{5%M681VLx769P>Pq0!UJ`u3Mu&s61)B@p$Z#m$7319xM(kgf-T^jeSvR75D6fTEO z$#e*(!({9ZHNbtePB; z9uPu&PoP$rreo&B>H2r~*2$ICVLa7cW(XC5Ih3b>X2Zi_xW5h(M#0SAIIZl{-{(ArSogpQ?ZC1Yqpd&% zm%3pN@UKARD7{k(BirFV9o!5E`C#~Adsbwwswp6|-JDE$n(H<+ePPJ10)-$oIPL*! z9FPRI9%TQ5*Qt!>eTH%oR8!!924!AoaKI)nZ1^nlCTraIKdz7hUW1FSM*si-07*qo IM6N<$f*$Y*;s5{u literal 0 HcmV?d00001 diff --git a/src/app/valentina/share/resources/toolicon.qrc b/src/app/valentina/share/resources/toolicon.qrc index 48576c6d8..772aa06a7 100644 --- a/src/app/valentina/share/resources/toolicon.qrc +++ b/src/app/valentina/share/resources/toolicon.qrc @@ -60,5 +60,7 @@ toolicon/32x32/intersection_curves@2x.png toolicon/32x32/cubic_bezier.png toolicon/32x32/cubic_bezier@2x.png + toolicon/32x32/cubic_bezier_path.png + toolicon/32x32/cubic_bezier_path@2x.png diff --git a/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier_path.png b/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier_path.png new file mode 100644 index 0000000000000000000000000000000000000000..7376c983da55a575ed290795b4a075431ed9c4e2 GIT binary patch literal 1737 zcmV;)1~&PLP)QtRrMLiKfm9(_ndS41}$$Tl(k~PvI5Gzz4x|b z5GQI3Y9q$Fm*@-zqt1o>F>o1X8(Ffrw-}5=iEe9zxiM()CE0XKhPV;?-r`sWT`OHD zpcLh{WtVeb&Nnd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 zOHgkOrmw`y*F{U9y{CH3SO9NWI9Z}C<3VS+APczHz*+NRTCD17@fKG@FxrE(4{v3b z1b5^o`XJm$<+fvMiji{;Q|69W_Pk0+Zc$R9OAW1$29MH23WR;K&oyH)ymTfUw;GPH zZi@yMURm4|QSZfow?Oo^*7?Q-PqWd@R^hG?u6V8~wU5Qj0ghgmg`Z8d+&xz5OgRsx zMs}+8r2hVMMbFP<}a5VM#y)O5#HFuNUC>j$2d1M{VQh z>l*a9lHes2{nB#j`nL{Qe#km`;eyw@$F0cgSR3hM+}l|-?+_|z9kzathg&9G-Mo60BY~Y`93ZM)48}O4> zXSeKj4Co9HS3qSHQtRn01Re~G0Z$WT8HgX;MQ-#qUravd(Wo}hp)f8_P03yKQJIQsIFj4p;BT7Clx7CkP=---@W59 z*N-CxDuC9=gw#>Ey`KU0#T_EX6dDz1iLlDb{+vIloA esLc0&qVRu}HOvy-=l#b30000 + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + From 2c4312046ca59362cf003cd0c03b6d3da0be859e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 16 Mar 2016 20:07:50 +0200 Subject: [PATCH 02/13] New classes VAbstractCubicBezierPath and VCubicBezierPath. --HG-- branch : feature --- .../vgeometry/vabstractcubicbezierpath.cpp | 203 ++++++++++++++++ src/libs/vgeometry/vabstractcubicbezierpath.h | 70 ++++++ src/libs/vgeometry/vcubicbezierpath.cpp | 218 ++++++++++++++++++ src/libs/vgeometry/vcubicbezierpath.h | 73 ++++++ src/libs/vgeometry/vcubicbezierpath_p.h | 70 ++++++ src/libs/vgeometry/vgeometry.pri | 9 +- src/libs/vgeometry/vsplinepath.cpp | 213 ++++------------- src/libs/vgeometry/vsplinepath.h | 23 +- .../vtools/dialogs/tools/dialogsplinepath.cpp | 12 +- .../drawTools/toolcurve/vtoolsplinepath.cpp | 14 +- .../toolcut/vtoolcutsplinepath.cpp | 2 +- src/libs/vtools/tools/vtooluniondetails.cpp | 4 +- .../visualization/vistoolcutsplinepath.cpp | 2 +- .../visualization/vistoolsplinepath.cpp | 8 +- 14 files changed, 709 insertions(+), 212 deletions(-) create mode 100644 src/libs/vgeometry/vabstractcubicbezierpath.cpp create mode 100644 src/libs/vgeometry/vabstractcubicbezierpath.h create mode 100644 src/libs/vgeometry/vcubicbezierpath.cpp create mode 100644 src/libs/vgeometry/vcubicbezierpath.h create mode 100644 src/libs/vgeometry/vcubicbezierpath_p.h diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.cpp b/src/libs/vgeometry/vabstractcubicbezierpath.cpp new file mode 100644 index 000000000..8a5f9709d --- /dev/null +++ b/src/libs/vgeometry/vabstractcubicbezierpath.cpp @@ -0,0 +1,203 @@ +/************************************************************************ + ** + ** @file vabstractcubicbezierpath.cpp + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#include "vabstractcubicbezierpath.h" +#include "../ifc/exception/vexception.h" +#include "vspline.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +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 VAbstractCubicBezierPath::GetPoints() const +{ + QVector 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(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractCubicBezierPath::CreateName() +{ + QString name; + if (CountPoints() > 0) + { + name = splPath; + name.append(QString("_%1").arg(FirstPoint().name())); + if (CountSubSpl() >= 1) + { + name.append(QString("_%1").arg(LastPoint().name())); + } + + if (GetDuplicate() > 0) + { + name += QString("_%1").arg(GetDuplicate()); + } + } + setName(name); +} diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.h b/src/libs/vgeometry/vabstractcubicbezierpath.h new file mode 100644 index 000000000..d43b5a586 --- /dev/null +++ b/src/libs/vgeometry/vabstractcubicbezierpath.h @@ -0,0 +1,70 @@ +/************************************************************************ + ** + ** @file vabstractcubicbezierpath.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#ifndef VABSTRACTCUBICBEZIERPATH_H +#define VABSTRACTCUBICBEZIERPATH_H + +#include "vabstractcurve.h" + +#include + +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 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; + +protected: + virtual void CreateName() Q_DECL_OVERRIDE; + + virtual VPointF FirstPoint() const =0; + virtual VPointF LastPoint() const =0; +}; + +#endif // VABSTRACTCUBICBEZIERPATH_H diff --git a/src/libs/vgeometry/vcubicbezierpath.cpp b/src/libs/vgeometry/vcubicbezierpath.cpp new file mode 100644 index 000000000..dbb7a31a6 --- /dev/null +++ b/src/libs/vgeometry/vcubicbezierpath.cpp @@ -0,0 +1,218 @@ +/************************************************************************ + ** + ** @file vcubicbezierpath.cpp + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#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 +#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 &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 qFloor(qAbs((d->path.size() - 4) / 3 + 1)); +} + +//--------------------------------------------------------------------------------------------------------------------- +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 = (index - 1) * 3; + + // 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 VCubicBezierPath::GetSplinePath() const +{ + return d->path; +} + +//--------------------------------------------------------------------------------------------------------------------- +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) + { + const qint32 base = (count - 1) * 3; + return d->path.at(base + 3);// Take last point of the last real spline + } + else + { + return VPointF(); + } +} diff --git a/src/libs/vgeometry/vcubicbezierpath.h b/src/libs/vgeometry/vcubicbezierpath.h new file mode 100644 index 000000000..ac67abd31 --- /dev/null +++ b/src/libs/vgeometry/vcubicbezierpath.h @@ -0,0 +1,73 @@ +/************************************************************************ + ** + ** @file vcubicbezierpath.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#ifndef VCUBICBEZIERPATH_H +#define VCUBICBEZIERPATH_H + +#include "vabstractcubicbezierpath.h" +#include "vpointf.h" + +#include + +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 &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 GetSplinePath() const; +protected: + virtual VPointF FirstPoint() const Q_DECL_OVERRIDE; + virtual VPointF LastPoint() const Q_DECL_OVERRIDE; +private: + QSharedDataPointer d; +}; + +Q_DECLARE_TYPEINFO(VCubicBezierPath, Q_MOVABLE_TYPE); + +#endif // VCUBICBEZIERPATH_H diff --git a/src/libs/vgeometry/vcubicbezierpath_p.h b/src/libs/vgeometry/vcubicbezierpath_p.h new file mode 100644 index 000000000..34fd9b6f0 --- /dev/null +++ b/src/libs/vgeometry/vcubicbezierpath_p.h @@ -0,0 +1,70 @@ +/************************************************************************ + ** + ** @file vcubicbezierpath_p.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#ifndef VCUBICBEZIERPATH_P_H +#define VCUBICBEZIERPATH_P_H + +#include + +#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 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 diff --git a/src/libs/vgeometry/vgeometry.pri b/src/libs/vgeometry/vgeometry.pri index 94c1f4a34..60586d110 100644 --- a/src/libs/vgeometry/vgeometry.pri +++ b/src/libs/vgeometry/vgeometry.pri @@ -11,7 +11,9 @@ SOURCES += \ $$PWD/vsplinepoint.cpp \ $$PWD/vellipticalarc.cpp \ $$PWD/vcubicbezier.cpp \ - $$PWD/vabstractcubicbezier.cpp + $$PWD/vabstractcubicbezier.cpp \ + $$PWD/vabstractcubicbezierpath.cpp \ + $$PWD/vcubicbezierpath.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -36,4 +38,7 @@ HEADERS += \ $$PWD/vabstractcurve_p.h \ $$PWD/vcubicbezier.h \ $$PWD/vcubicbezier_p.h \ - $$PWD/vabstractcubicbezier.h + $$PWD/vabstractcubicbezier.h \ + $$PWD/vabstractcubicbezierpath.h \ + $$PWD/vcubicbezierpath.h \ + $$PWD/vcubicbezierpath_p.h diff --git a/src/libs/vgeometry/vsplinepath.cpp b/src/libs/vgeometry/vsplinepath.cpp index 8928ef402..775e8c206 100644 --- a/src/libs/vgeometry/vsplinepath.cpp +++ b/src/libs/vgeometry/vsplinepath.cpp @@ -43,13 +43,13 @@ * @param mode mode creation spline path. */ VSplinePath::VSplinePath(quint32 idObject, Draw mode) - : VAbstractCurve(GOType::SplinePath, idObject, mode), + : VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode), d(new VSplinePathData()) {} //--------------------------------------------------------------------------------------------------------------------- VSplinePath::VSplinePath(const QVector &points, qreal kCurve, quint32 idObject, Draw mode) - : VAbstractCurve(GOType::SplinePath, idObject, mode), + : VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode), d(new VSplinePathData()) { if (points.size() < 3) @@ -84,7 +84,7 @@ VSplinePath::VSplinePath(const QVector &points, qreal kCurve, qui //--------------------------------------------------------------------------------------------------------------------- VSplinePath::VSplinePath(const QVector &points, quint32 idObject, Draw mode) - : VAbstractCurve(GOType::SplinePath, idObject, mode), + : VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode), d(new VSplinePathData()) { if (points.isEmpty()) @@ -102,7 +102,7 @@ VSplinePath::VSplinePath(const QVector &points, quint32 idObject, * @param splPath spline path. */ VSplinePath::VSplinePath(const VSplinePath &splPath) - : VAbstractCurve(splPath), + : VAbstractCubicBezierPath(splPath), d(splPath.d) {} @@ -128,10 +128,10 @@ void VSplinePath::append(const VSplinePoint &point) //--------------------------------------------------------------------------------------------------------------------- /** - * @brief Count return count point. + * @brief CountSubSpl return count of simple splines. * @return count. */ -qint32 VSplinePath::Count() const +qint32 VSplinePath::CountSubSpl() const { if (d->path.size() == 0) { @@ -151,14 +151,16 @@ qint32 VSplinePath::Count() const */ VSpline VSplinePath::GetSpline(qint32 index) const { - if (Count()<1) + if (CountPoints()<1) { 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.")); } + const VSplinePoint &p1 = d->path.at(index-1); const VSplinePoint &p2 = d->path.at(index); 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; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @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 VSplinePath::GetPoints() const -{ - QVector 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. @@ -232,7 +177,7 @@ qreal VSplinePath::GetLength() const */ 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.")); } @@ -255,7 +200,7 @@ void VSplinePath::UpdatePoint(qint32 indexSpline, const SplinePointPosition &pos */ 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.")); } @@ -308,98 +253,12 @@ const VSplinePoint &VSplinePath::at(int indx) const 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 { - if (CountPoint() > 0) + if (CountPoints() > 0) { - return GetSplinePath().first().Angle1(); + return GetSplinePath().first().Angle2(); } else { @@ -410,9 +269,9 @@ qreal VSplinePath::GetStartAngle() const //--------------------------------------------------------------------------------------------------------------------- qreal VSplinePath::GetEndAngle() const { - if (CountPoint() > 0) + if (CountPoints() > 0) { - return GetSplinePath().last().Angle2(); + return GetSplinePath().last().Angle1(); } else { @@ -421,32 +280,38 @@ qreal VSplinePath::GetEndAngle() const } //--------------------------------------------------------------------------------------------------------------------- -void VSplinePath::CreateName() +VPointF VSplinePath::FirstPoint() const { - QString name; if (not d->path.isEmpty()) { - name = splPath; - name.append(QString("_%1").arg(d->path.first().P().name())); - if (d->path.size() > 1) - { - name.append(QString("_%1").arg(d->path.last().P().name())); - } - - if (GetDuplicate() > 0) - { - name += QString("_%1").arg(GetDuplicate()); - } + return d->path.first().P(); + } + else + { + return VPointF(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +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. */ -qint32 VSplinePath::CountPoint() const +qint32 VSplinePath::CountPoints() const { return d->path.size(); } @@ -467,7 +332,7 @@ QVector VSplinePath::GetFSplinePath() const QVector points; 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 &p2 = d->path.at(i); diff --git a/src/libs/vgeometry/vsplinepath.h b/src/libs/vgeometry/vsplinepath.h index d8d788367..5ec9c183f 100644 --- a/src/libs/vgeometry/vsplinepath.h +++ b/src/libs/vgeometry/vsplinepath.h @@ -29,7 +29,7 @@ #ifndef VSPLINEPATH_H #define VSPLINEPATH_H -#include "vabstractcurve.h" +#include "vabstractcubicbezierpath.h" #include "vspline.h" #include "vsplinepoint.h" #include @@ -41,7 +41,7 @@ class VSplinePathData; /** * @brief The VSplinePath class keep information about splinePath. */ -class VSplinePath :public VAbstractCurve +class VSplinePath :public VAbstractCubicBezierPath { Q_DECLARE_TR_FUNCTIONS(VSplinePath) public: @@ -56,14 +56,11 @@ public: VSplinePoint &operator[](int indx); void append(const VSplinePoint &point); - qint32 Count() const; - qint32 CountPoint() const; - void Clear(); - VSpline GetSpline(qint32 index) const; - QPainterPath GetPath(PathDirection direction = PathDirection::Hide) const; - QVector GetPoints() const; - qreal GetLength() const; + 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; QVector GetSplinePath() const; QVector GetFSplinePath() const; @@ -75,13 +72,9 @@ public: VSplinePoint GetSplinePoint(qint32 indexSpline, SplinePointPosition pos) 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: - virtual void CreateName() Q_DECL_OVERRIDE; + virtual VPointF FirstPoint() const Q_DECL_OVERRIDE; + virtual VPointF LastPoint() const Q_DECL_OVERRIDE; private: QSharedDataPointer d; }; diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index 7f0c47b0a..d9dd6e457 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -127,7 +127,7 @@ void DialogSplinePath::SetPath(const VSplinePath &value) this->path = value; ui->listWidget->blockSignals(true); ui->listWidget->clear(); - for (qint32 i = 0; i < path.CountPoint(); ++i) + for (qint32 i = 0; i < path.CountPoints(); ++i) { NewItem(path.at(i)); } @@ -179,7 +179,7 @@ void DialogSplinePath::ChosenObject(quint32 id, const SceneObject &type) SCASSERT(visPath != nullptr); visPath->setPath(path); - if (path.CountPoint() == 1) + if (path.CountPoints() == 1) { visPath->VisualMode(NULL_ID); connect(visPath, &VisToolSplinePath::ToolTip, this, &DialogTool::ShowVisToolTip); @@ -666,7 +666,7 @@ void DialogSplinePath::currentPointChanged(int index) auto first = qvariant_cast(ui->listWidget->item(0)->data(Qt::UserRole)); auto last = qvariant_cast(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; ui->lineEditSplPathName->setText(path.name()); @@ -694,7 +694,7 @@ void DialogSplinePath::ShowDialog(bool click) { if (click == false) { - if (path.CountPoint() >= 3) + if (path.CountPoints() >= 3) { emit ToolTip(""); @@ -888,12 +888,12 @@ QSet DialogSplinePath::AllIds() const //--------------------------------------------------------------------------------------------------------------------- bool DialogSplinePath::IsPathValid() const { - if (path.CountPoint() < 3) + if (path.CountPoints() < 3) { return false; } - return (AllIds().size() == path.CountPoint()); + return (AllIds().size() == path.CountPoints()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index 78a51a3f7..e402ba19c 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -68,7 +68,7 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3 this->setAcceptHoverEvents(true); const QSharedPointer splPath = data->GeometricObject(id); - for (qint32 i = 1; i<=splPath->Count(); ++i) + for (qint32 i = 1; i<=splPath->CountSubSpl(); ++i) { const VSpline spl = splPath->GetSpline(i); @@ -138,7 +138,7 @@ VToolSplinePath* VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene SCASSERT(dialogTool != nullptr); VSplinePath *path = new VSplinePath(dialogTool->GetPath()); 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()); } @@ -302,7 +302,7 @@ void VToolSplinePath::SetSplinePathAttributes(QDomElement &domElement, const VSp void VToolSplinePath::UpdatePathPoints(VAbstractPattern *doc, QDomElement &element, const VSplinePath &path) { 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)); } @@ -390,7 +390,7 @@ void VToolSplinePath::AddPathPoint(VAbstractPattern *doc, QDomElement &domElemen void VToolSplinePath::RemoveReferens() { const VSplinePath splPath = *VAbstractTool::data.GeometricObject(id); - for (qint32 i = 0; i < splPath.Count(); ++i) + for (qint32 i = 0; i < splPath.CountSubSpl(); ++i) { doc->DecrementReferens(splPath.at(i).P().getIdTool()); } @@ -407,7 +407,7 @@ void VToolSplinePath::SaveDialog(QDomElement &domElement) SCASSERT(dialogTool != nullptr); 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); qint32 j = i*2; @@ -605,7 +605,7 @@ bool VToolSplinePath::IsMovable(int index) const const auto splPath = VAbstractTool::data.GeometricObject(id); //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; } @@ -641,7 +641,7 @@ void VToolSplinePath::RefreshGeometry() qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); const auto splPath = VAbstractTool::data.GeometricObject(id); - for (qint32 i = 1; i<=splPath->Count(); ++i) + for (qint32 i = 1; i<=splPath->CountSubSpl(); ++i) { const qint32 j = i*2; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp index 2cba23674..0f8a20a82 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp @@ -154,7 +154,7 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString VSplinePath *splPath1 = 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) { diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 39d1a1b45..0cce48dde 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -216,7 +216,7 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte VSplinePath *path = new VSplinePath(); path->setMode(Draw::Modeling); const QSharedPointer splinePath = data->GeometricObject(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 &point2 = splinePath->at(i); @@ -366,7 +366,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const path->setMode(Draw::Modeling); const QSharedPointer splinePath = data->GeometricObject(det.at(i).getId()); 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 &point2 = splinePath->at(i); diff --git a/src/libs/vtools/visualization/vistoolcutsplinepath.cpp b/src/libs/vtools/visualization/vistoolcutsplinepath.cpp index 2b43faf89..35737a802 100644 --- a/src/libs/vtools/visualization/vistoolcutsplinepath.cpp +++ b/src/libs/vtools/visualization/vistoolcutsplinepath.cpp @@ -73,7 +73,7 @@ void VisToolCutSplinePath::RefreshGeometry() VSplinePath spPath1 = 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) { diff --git a/src/libs/vtools/visualization/vistoolsplinepath.cpp b/src/libs/vtools/visualization/vistoolsplinepath.cpp index a9dfb6617..47e0d16fa 100644 --- a/src/libs/vtools/visualization/vistoolsplinepath.cpp +++ b/src/libs/vtools/visualization/vistoolsplinepath.cpp @@ -53,7 +53,7 @@ VisToolSplinePath::~VisToolSplinePath() //--------------------------------------------------------------------------------------------------------------------- void VisToolSplinePath::RefreshGeometry() { - if (path.CountPoint() > 0) + if (path.CountPoints() > 0) { const QVector pathPoints = path.GetSplinePath(); const int size = pathPoints.size(); @@ -68,9 +68,9 @@ void VisToolSplinePath::RefreshGeometry() { 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; VSpline spl = path.GetSpline(i); @@ -90,7 +90,7 @@ void VisToolSplinePath::RefreshGeometry() DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); } - if (path.CountPoint() < 3) + if (path.CountPoints() < 3) { Visualization::toolTip = tr("Curved path: select three or more points"); } From 037e91484ae576d747b93ebce47a1fa9458a6ceb Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 17 Mar 2016 16:26:25 +0200 Subject: [PATCH 03/13] For tool Cubic Bezier curve show connection to control points. --HG-- branch : feature --- .../vtools/visualization/vistoolcubicbezier.cpp | 14 ++++++++------ src/libs/vtools/visualization/vistoolcubicbezier.h | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/libs/vtools/visualization/vistoolcubicbezier.cpp b/src/libs/vtools/visualization/vistoolcubicbezier.cpp index 6234c6913..c6d3af4ca 100644 --- a/src/libs/vtools/visualization/vistoolcubicbezier.cpp +++ b/src/libs/vtools/visualization/vistoolcubicbezier.cpp @@ -39,14 +39,16 @@ VisToolCubicBezier::VisToolCubicBezier(const VContainer *data, QGraphicsItem *pa point2(nullptr), point3(nullptr), point4(nullptr), - helpLine(nullptr) + helpLine1(nullptr), + helpLine2(nullptr) { + helpLine1 = InitItem(mainColor, this); + helpLine2 = InitItem(mainColor, this); + point1 = InitPoint(supportColor, this); point2 = InitPoint(supportColor, this); //-V656 point3 = InitPoint(supportColor, this); //-V656 point4 = InitPoint(supportColor, this); //-V656 - - helpLine = InitItem(mainColor, this); } //--------------------------------------------------------------------------------------------------------------------- @@ -65,14 +67,13 @@ void VisToolCubicBezier::RefreshGeometry() if (object2Id <= NULL_ID) { const QLineF line = QLineF(first->toQPointF(), Visualization::scenePos); - DrawLine(helpLine, line, mainColor, lineStyle); + DrawLine(helpLine1, line, mainColor, Qt::DashLine); } else { - helpLine->setVisible(false); - const auto second = Visualization::data->GeometricObject(object2Id); DrawPoint(point2, second->toQPointF(), supportColor); + DrawLine(helpLine1, QLineF(first->toQPointF(), second->toQPointF()), mainColor, Qt::DashLine); if (object3Id <= NULL_ID) { @@ -94,6 +95,7 @@ void VisToolCubicBezier::RefreshGeometry() { const auto fourth = Visualization::data->GeometricObject(object4Id); DrawPoint(point4, fourth->toQPointF(), supportColor); + DrawLine(helpLine2, QLineF(fourth->toQPointF(), third->toQPointF()), mainColor, Qt::DashLine); VCubicBezier spline(*first, *second, *third, *fourth); DrawPath(this, spline.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); diff --git a/src/libs/vtools/visualization/vistoolcubicbezier.h b/src/libs/vtools/visualization/vistoolcubicbezier.h index d67fcfdf7..2fc6d5fd9 100644 --- a/src/libs/vtools/visualization/vistoolcubicbezier.h +++ b/src/libs/vtools/visualization/vistoolcubicbezier.h @@ -56,7 +56,8 @@ protected: QGraphicsEllipseItem *point2; QGraphicsEllipseItem *point3; QGraphicsEllipseItem *point4; - QGraphicsLineItem *helpLine; + QGraphicsLineItem *helpLine1; + QGraphicsLineItem *helpLine2; }; #endif // VISTOOLCUBICBEZIER_H From dc8e75ed7d490d3de333dfa531fd355359985d05 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 17 Mar 2016 16:26:58 +0200 Subject: [PATCH 04/13] Updated .hgignore file. Ignore *.qbs.user files. --HG-- branch : feature --- .hgignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgignore b/.hgignore index 166ab3143..acd48da3d 100644 --- a/.hgignore +++ b/.hgignore @@ -89,6 +89,7 @@ cov-int/ /.qmake.stash *.pro.user *.pro.user.* +*.qbs.user *.moc moc_*.cpp qrc_*.cpp From 54294f1a71fcf0694dc31dee2f1eab1ab3d9623d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 17 Mar 2016 16:35:14 +0200 Subject: [PATCH 05/13] Updated icon for tool Cubic Bezier curve. --HG-- branch : feature --- .../resources/cursor/cubic_bezier_cursor.png | Bin 644 -> 676 bytes .../cursor/cubic_bezier_cursor@2x.png | Bin 1395 -> 1518 bytes .../resources/toolicon/32x32/cubic_bezier.png | Bin 895 -> 1007 bytes .../toolicon/32x32/cubic_bezier@2x.png | Bin 1983 -> 2282 bytes .../resources/toolicon/svg/cubic_bezier.svg | 16 +++++++++++++++- 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/app/valentina/share/resources/cursor/cubic_bezier_cursor.png b/src/app/valentina/share/resources/cursor/cubic_bezier_cursor.png index 6c50010d27fd51fe79074ef3a354ad2f6c90298c..c78b1fec4950c8b5a54f7690c294af422fa149b5 100644 GIT binary patch delta 577 zcmV-H0>1r(1*8R#Zhs+3L_t(oh3(eQYtvvH$MN?Qo2+FWZgZQ6sE1lm%GOC+Q4lOh z(SsK)6FhmDF#HRK=s|WE?BM(p#x4#o;?0YCa+ZOJf|n^OC{o-UMEmmkWQ;D3JSGjPUBfCO@0B8&#&CveV7fM*CZz<(1&y$R5BL@Pi~5mtbn zA!=;^Jwf~p&~=0zK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valentina/share/resources/cursor/cubic_bezier_cursor@2x.png b/src/app/valentina/share/resources/cursor/cubic_bezier_cursor@2x.png index 1e1522991d69d2f6d804cb960adde50df11dbec7..317a23efc73dbcae69ca49e5d7f80f43d840e513 100644 GIT binary patch delta 1427 zcmV;E1#J5B3hoP#ZGQ!8NklE$qUFS2~Gv%jD#CF7myPY!i-Ho)=Nl*fUK4mK)=B6m^#Za=!gbsckTnwA6p$4X`fyi3#!Cp{zJQFDFkS*ORzff1 zCmb~*JSHaAiq5Buby$k z-1$PQME$UHPD{A!pYQE5U?duVr?6IyT&4MaqTW7F@4W}q^D~YZr{Zw_FKhqOs8ArR zA`ltO+t3{}x0OU#P}whEz)QfFDemIPc>MEG>VY{SeSb&ml3=B2$kRipRZ6i4p#-Hg0TCr8)@T$3 zB7%ekb;1<>^e8zQGtB0PHc=P#;h`gT+ODaQGGGvR2Ke5UPL70WuBq;mj^kekUr~zZ z1T|Y(x5QVKqDh3`5ze8wXo%_-!xPdldj|CA)#75JG++vt>>+^9w-S@B?6A*XJAVO( zfm+~MpxMQ4+Oq>~dQ8^tI_g>EH7NoaK-4}IKZsWy4~B=%^B@NMF=d1is|I|(ng01P zr7ke2pGj2CPQd1rbi^Sq_XMh%HFMe0F8shz!F)F`b?8TFApUQmmc+kb4tWNw2iDB{ zK(Fjtt?ljooJgYb$qs|Au^jSd=6|tRzhu6*@w%u2UET@?BD zsPaJ>nJgd(D|Og(MUl?{933!bH$pYZ-)$1xsl?DfO33K%SdkidsgxR|JXMr44%X&;2#DDw*oB-w(yCTJk-hG{B zmLll5*9G9A;#OzoW0;6A>v}?(i2$>%C%6I3Duhwo0cH)t2$KWM3WVtZDjp%l^Z*r& zkR&sJibco<*&^H_ ze*k5PkZ*vpLw~qU{sGDgVUWTAlnp{50m=g57KH^Ud4vH94^YwwGX+qx2sfEIfRaS` zmzf19IfP;WloY}ZiUUwG2-hhdKuI7J8=&Y2{TWoSq7klnsBA?cloCL}5ya)YtHAt1 z?a*U7fHk=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HjpC14K002ovPDHLkV1j>NcmMzZ diff --git a/src/app/valentina/share/resources/toolicon/svg/cubic_bezier.svg b/src/app/valentina/share/resources/toolicon/svg/cubic_bezier.svg index b2a3d3dd7..c60a95c6d 100644 --- a/src/app/valentina/share/resources/toolicon/svg/cubic_bezier.svg +++ b/src/app/valentina/share/resources/toolicon/svg/cubic_bezier.svg @@ -32,7 +32,7 @@ id="namedview12" showgrid="false" inkscape:zoom="14.75" - inkscape:cx="-5.7288133" + inkscape:cx="-4.3389831" inkscape:cy="12.164845" inkscape:window-x="65" inkscape:window-y="24" @@ -60,11 +60,25 @@ id="path4205" inkscape:connector-curvature="0" sodipodi:nodetypes="cc" /> + + Date: Thu, 17 Mar 2016 20:12:48 +0200 Subject: [PATCH 06/13] Refactoring. More switch tests. Added tool button for tool Cubic bezier path. --HG-- branch : feature --- src/app/valentina/dialogs/dialoghistory.cpp | 70 ++++++----------- src/app/valentina/mainwindow.cpp | 76 +++++++++++++++---- src/app/valentina/mainwindow.h | 1 + src/app/valentina/mainwindow.ui | 37 +++++++-- src/app/valentina/xml/vpattern.cpp | 65 ++-------------- src/app/valentina/xml/vpattern.h | 3 +- src/libs/vgeometry/vabstractcubicbezier.cpp | 11 +++ src/libs/vgeometry/vabstractcubicbezier.h | 2 + .../vgeometry/vabstractcubicbezierpath.cpp | 25 ++++++ src/libs/vgeometry/vabstractcubicbezierpath.h | 2 + src/libs/vgeometry/vabstractcurve.h | 2 + src/libs/vgeometry/varc.cpp | 17 +++++ src/libs/vgeometry/varc.h | 1 + src/libs/vgeometry/vellipticalarc.cpp | 17 +++++ src/libs/vgeometry/vellipticalarc.h | 1 + src/libs/vmisc/def.h | 2 + 16 files changed, 201 insertions(+), 131 deletions(-) diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index 878be176c..006b82bc4 100644 --- a/src/app/valentina/dialogs/dialoghistory.cpp +++ b/src/app/valentina/dialogs/dialoghistory.cpp @@ -31,6 +31,7 @@ #include "../vgeometry/varc.h" #include "../vgeometry/vcubicbezier.h" #include "../vgeometry/vsplinepath.h" +#include "../vgeometry/vcubicbezierpath.h" #include "../vgeometry/vpointf.h" #include "../vtools/tools/vabstracttool.h" #include "../vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h" @@ -194,12 +195,11 @@ void DialogHistory::FillTable() ui->tableWidget->verticalHeader()->setDefaultSectionSize(20); } +//--------------------------------------------------------------------------------------------------------------------- #if defined(Q_CC_GNU) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wswitch-default" #endif - -//--------------------------------------------------------------------------------------------------------------------- /** * @brief Record return description for record * @param tool record data @@ -208,7 +208,7 @@ void DialogHistory::FillTable() QString DialogHistory::Record(const VToolRecord &tool) { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 40, "Not all tools was used in history."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in history."); const QDomElement domElem = doc->elementById(tool.getId()); if (domElem.isElement() == false) @@ -268,49 +268,39 @@ QString DialogHistory::Record(const VToolRecord &tool) { const QSharedPointer spl = data->GeometricObject(tool.getId()); 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: { const QSharedPointer spl = data->GeometricObject(tool.getId()); SCASSERT(spl != nullptr); - return QString(tr("Cubic bezier curve %1_%2")).arg(PointName(spl->GetP1().id())) - .arg(PointName(spl->GetP4().id())); + return spl->NameForHistory(tr("Cubic bezier curve")); } case Tool::Arc: { const QSharedPointer arc = data->GeometricObject(tool.getId()); 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: { const QSharedPointer arc = data->GeometricObject(tool.getId()); 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()); } case Tool::SplinePath: { const QSharedPointer splPath = data->GeometricObject(tool.getId()); SCASSERT(splPath != nullptr); - const QVector points = splPath->GetSplinePath(); - QString record; - if (points.size() != 0 ) - { - // We use only first and last point name in curve - record = QString(tr("Curve point %1")).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"<NameForHistory(tr("Spline path")); + } + case Tool::CubicBezierPath: + { + const QSharedPointer splPath = data->GeometricObject(tool.getId()); + SCASSERT(splPath != nullptr); + return splPath->NameForHistory(tr("Cubic bezier curve path")); } case Tool::PointOfContact: 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 arc = data->GeometricObject(AttrUInt(domElem, AttrArc)); SCASSERT(arc != nullptr); - return QString(tr("%1 - cut arc with center %2")) + return QString(tr("%1 - cut %2")) .arg(PointName(tool.getId())) - .arg(PointName(arc->GetCenter().id())); + .arg(arc->NameForHistory(tr("arc"))); } case Tool::CutSpline: { const quint32 splineId = AttrUInt(domElem, VToolCutSpline::AttrSpline); const QSharedPointer spl = data->GeometricObject(splineId); SCASSERT(spl != nullptr); - return QString(tr("%1 - cut curve %2_%3")) + return QString(tr("%1 - cut %2")) .arg(PointName(tool.getId())) - .arg(PointName(spl->GetP1().id())) - .arg(PointName(spl->GetP4().id())); + .arg(spl->NameForHistory(tr("curve"))); } case Tool::CutSplinePath: { const quint32 splinePathId = AttrUInt(domElem, VToolCutSplinePath::AttrSplinePath); const QSharedPointer splPath = data->GeometricObject(splinePathId); SCASSERT(splPath != nullptr); - const QVector points = splPath->GetSplinePath(); - QString record; - if (points.size() != 0 ) - { - 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"<NameForHistory(tr("curve path"))); } case Tool::LineIntersectAxis: return QString(tr("%1 - point of intersection line %2_%3 and axis through point %4")) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 91a41adcc..a52ca3972 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -830,6 +830,12 @@ void MainWindow::ToolSplinePath(bool checked) &MainWindow::ApplyDialog); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolCubicBezierPath(bool checked) +{ + +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ToolCutSplinePath handler tool CutSplinePath. @@ -1615,6 +1621,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonCubicBezier, &QToolButton::clicked, this, &MainWindow::ToolCubicBezier); connect(ui->toolButtonArc, &QToolButton::clicked, this, &MainWindow::ToolArc); 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->toolButtonNewDetail, &QToolButton::clicked, this, &MainWindow::ToolDetail); connect(ui->toolButtonHeight, &QToolButton::clicked, this, &MainWindow::ToolHeight); @@ -1669,11 +1676,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. */ void MainWindow::CancelTool() { + // This check helps to find missed tools in the switch + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was handled."); + qCDebug(vMainWindow, "Canceling tool."); delete dialogTool; dialogTool = nullptr; @@ -1692,6 +1706,16 @@ void MainWindow::CancelTool() redoAction->setEnabled(false); return; 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 //Nothing to do here because we can't create this tool from main window. break; @@ -1731,6 +1755,9 @@ void MainWindow::CancelTool() case Tool::SplinePath: ui->toolButtonSplinePath->setChecked(false); break; + case Tool::CubicBezierPath: + ui->toolButtonCubicBezierPath->setChecked(false); + break; case Tool::PointOfContact: ui->toolButtonPointOfContact->setChecked(false); break; @@ -1783,13 +1810,6 @@ void MainWindow::CancelTool() case Tool::TrueDarts: ui->toolButtonTrueDarts->setChecked(false); 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->clearSelection(); @@ -1801,6 +1821,10 @@ void MainWindow::CancelTool() redoAction->setEnabled(qApp->getUndoStack()->canRedo()); } +#if defined(Q_CC_GNU) + #pragma GCC diagnostic pop +#endif + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ArrowTool enable arrow tool. @@ -2949,6 +2973,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonCubicBezier->setEnabled(drawTools); ui->toolButtonArc->setEnabled(drawTools); ui->toolButtonSplinePath->setEnabled(drawTools); + ui->toolButtonCubicBezierPath->setEnabled(drawTools); ui->toolButtonPointOfContact->setEnabled(drawTools); ui->toolButtonNewDetail->setEnabled(drawTools); ui->toolButtonHeight->setEnabled(drawTools); @@ -3233,8 +3258,16 @@ void MainWindow::CreateMenus() AddDocks(); } +//--------------------------------------------------------------------------------------------------------------------- +#if defined(Q_CC_GNU) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wswitch-default" +#endif void MainWindow::LastUsedTool() { + // This check helps to find missed tools in the switch + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was handled."); + if (currentTool == lastUsedTool) { return; @@ -3247,6 +3280,16 @@ void MainWindow::LastUsedTool() ArrowTool(); break; 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 //Nothing to do here because we can't create this tool from main window. break; @@ -3282,6 +3325,10 @@ void MainWindow::LastUsedTool() ui->toolButtonSpline->setChecked(true); ToolSpline(true); break; + case Tool::CubicBezier: + ui->toolButtonCubicBezier->setChecked(true); + ToolCubicBezier(true); + break; case Tool::Arc: ui->toolButtonArc->setChecked(true); ToolArc(true); @@ -3290,6 +3337,10 @@ void MainWindow::LastUsedTool() ui->toolButtonSplinePath->setChecked(true); ToolSplinePath(true); break; + case Tool::CubicBezierPath: + ui->toolButtonCubicBezierPath->setChecked(true); + ToolCubicBezierPath(true); + break; case Tool::PointOfContact: ui->toolButtonPointOfContact->setChecked(true); ToolPointOfContact(true); @@ -3362,16 +3413,13 @@ void MainWindow::LastUsedTool() ui->toolButtonTrueDarts->setChecked(true); ToolTrueDarts(true); 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() { diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 4e54292d4..92829ac41 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -112,6 +112,7 @@ public slots: void ToolCutSpline(bool checked); void ToolArc(bool checked); void ToolSplinePath(bool checked); + void ToolCubicBezierPath(bool checked); void ToolCutSplinePath(bool checked); void ToolPointOfContact(bool checked); void ToolDetail(bool checked); diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index 6cc18b312..77b9f7ff2 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -618,7 +618,33 @@ - + + + + false + + + Point intersection curves + + + ... + + + + :/toolicon/32x32/intersection_curves.png:/toolicon/32x32/intersection_curves.png + + + + 32 + 32 + + + + true + + + + false @@ -644,20 +670,17 @@ - - + + false - - Point intersection curves - ... - :/toolicon/32x32/intersection_curves.png:/toolicon/32x32/intersection_curves.png + :/toolicon/32x32/cubic_bezier_path.png:/toolicon/32x32/cubic_bezier_path.png diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 1e8d2373a..01bde6c92 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -3036,7 +3036,7 @@ void VPattern::ToolsCommonAttributes(const QDomElement &domElement, quint32 &id) QRectF VPattern::ActiveDrawBoundingRect() const { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 40, "Not all tools was used."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used."); QRectF rec; @@ -3057,91 +3057,37 @@ QRectF VPattern::ActiveDrawBoundingRect() const Q_UNREACHABLE(); break; case Tool::BasePoint: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::EndLine: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::Line: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::AlongLine: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::ShoulderPoint: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::Normal: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::Bisector: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::LineIntersect: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::Spline: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::CubicBezier: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::Arc: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::SplinePath: - rec = ToolBoundingRect(rec, tool.getId()); - break; + case Tool::CubicBezierPath: case Tool::PointOfContact: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::Height: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::Triangle: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::PointOfIntersection: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::CutArc: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::CutSpline: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::CutSplinePath: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::ArcWithLength: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::LineIntersectAxis: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::PointOfIntersectionArcs: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::PointOfIntersectionCircles: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::PointOfIntersectionCurves: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::CurveIntersectAxis: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::PointFromCircleAndTangent: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::PointFromArcAndTangent: - rec = ToolBoundingRect(rec, tool.getId()); - break; case Tool::TrueDarts: - rec = ToolBoundingRect(rec, tool.getId()); + rec = ToolBoundingRect(rec, tool.getId()); break; - //Because "history" not only show history of pattern, but help restore current data for each pattern's - //piece, we need add record about details and nodes, but don't show them. + //These tools are not accesseble in Draw mode, but still 'history' contains them. case Tool::Detail: case Tool::UnionDetails: case Tool::NodeArc: @@ -3160,13 +3106,12 @@ QRectF VPattern::ActiveDrawBoundingRect() const #endif //--------------------------------------------------------------------------------------------------------------------- -template QRectF VPattern::ToolBoundingRect(const QRectF &rec, const quint32 &id) const { QRectF recTool = rec; if (tools.contains(id)) { - T *vTool = qobject_cast(tools.value(id)); + const QGraphicsItem *vTool = qobject_cast(tools.value(id)); SCASSERT(vTool != nullptr); QRectF childrenRect = vTool->childrenBoundingRect(); diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 08724c88c..481b0f353 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -135,8 +135,7 @@ private: void PointsCommonAttributes(const QDomElement &domElement, quint32 &id, qreal &mx, qreal &my); void SplinesCommonAttributes(const QDomElement &domElement, quint32 &id, quint32 &idObject, quint32 &idTool); - template - QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const; + QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const; void ParseCurrentPP(); QString GetLabelBase(quint32 index)const; diff --git a/src/libs/vgeometry/vabstractcubicbezier.cpp b/src/libs/vgeometry/vabstractcubicbezier.cpp index 9117d2418..2f0686719 100644 --- a/src/libs/vgeometry/vabstractcubicbezier.cpp +++ b/src/libs/vgeometry/vabstractcubicbezier.cpp @@ -126,6 +126,17 @@ QPointF VAbstractCubicBezier::CutSpline(qreal length, QPointF &spl1p2, QPointF & 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() { diff --git a/src/libs/vgeometry/vabstractcubicbezier.h b/src/libs/vgeometry/vabstractcubicbezier.h index ec8d8b8b9..21d8029ea 100644 --- a/src/libs/vgeometry/vabstractcubicbezier.h +++ b/src/libs/vgeometry/vabstractcubicbezier.h @@ -46,6 +46,8 @@ public: QPointF CutSpline ( qreal length, 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; diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.cpp b/src/libs/vgeometry/vabstractcubicbezierpath.cpp index 8a5f9709d..f113e9757 100644 --- a/src/libs/vgeometry/vabstractcubicbezierpath.cpp +++ b/src/libs/vgeometry/vabstractcubicbezierpath.cpp @@ -181,6 +181,31 @@ QPointF VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32 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() { diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.h b/src/libs/vgeometry/vabstractcubicbezierpath.h index d43b5a586..78e2cd0d6 100644 --- a/src/libs/vgeometry/vabstractcubicbezierpath.h +++ b/src/libs/vgeometry/vabstractcubicbezierpath.h @@ -60,6 +60,8 @@ public: 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; diff --git a/src/libs/vgeometry/vabstractcurve.h b/src/libs/vgeometry/vabstractcurve.h index fbc32ac7a..6390c9c16 100644 --- a/src/libs/vgeometry/vabstractcurve.h +++ b/src/libs/vgeometry/vabstractcurve.h @@ -65,6 +65,8 @@ public: void SetDuplicate(quint32 number); static QVector CurveIntersectLine(const QVector &points, const QLineF &line); + + virtual QString NameForHistory(const QString &toolName) const=0; protected: QPainterPath ShowDirection(const QVector &points) const; virtual void CreateName() =0; diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index 10ef8393a..408b692a4 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -315,6 +315,23 @@ void VArc::setId(const quint32 &id) 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() { diff --git a/src/libs/vgeometry/varc.h b/src/libs/vgeometry/varc.h index 89ac7b4a2..a1f0077c9 100644 --- a/src/libs/vgeometry/varc.h +++ b/src/libs/vgeometry/varc.h @@ -80,6 +80,7 @@ public: QPointF CutArc (const qreal &length, VArc &arc1, VArc &arc2) const; QPointF CutArc (const qreal &length) const; virtual void setId(const quint32 &id) Q_DECL_OVERRIDE; + virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE; protected: virtual void CreateName() Q_DECL_OVERRIDE; private: diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 0f1485b79..5b56a474c 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -375,6 +375,23 @@ void VEllipticalArc::setId(const quint32 &id) 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() { diff --git a/src/libs/vgeometry/vellipticalarc.h b/src/libs/vgeometry/vellipticalarc.h index 44a3f2cd1..b2d608c20 100644 --- a/src/libs/vgeometry/vellipticalarc.h +++ b/src/libs/vgeometry/vellipticalarc.h @@ -92,6 +92,7 @@ public: QPointF CutArc (const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2) const; QPointF CutArc (const qreal &length) const; virtual void setId(const quint32 &id) Q_DECL_OVERRIDE; + virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE; protected: virtual void CreateName() Q_DECL_OVERRIDE; private: diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 516f2ab3c..28afb2291 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -80,6 +80,7 @@ enum class Tool : ToolVisHolderType Arc, ArcWithLength, SplinePath, + CubicBezierPath, CutSplinePath, PointOfContact, Detail, @@ -129,6 +130,7 @@ enum class Vis : ToolVisHolderType ToolShoulderPoint, ToolSpline, ToolCubicBezier, + ToolCubicBezierPath, ToolTriangle, ToolCutSpline, ToolSplinePath, From f61bd5f42aaba4dbb79aeee58d2024f7b4d2c39e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 18 Mar 2016 12:27:20 +0200 Subject: [PATCH 07/13] Skip history for Detail's mode tools. --HG-- branch : feature --- src/app/valentina/dialogs/dialoghistory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index 006b82bc4..5c5c462de 100644 --- a/src/app/valentina/dialogs/dialoghistory.cpp +++ b/src/app/valentina/dialogs/dialoghistory.cpp @@ -163,7 +163,7 @@ void DialogHistory::FillTable() { const VToolRecord tool = history.at(i); const QString historyRecord = Record(tool); - if (historyRecord.isEmpty() ==false) + if (not historyRecord.isEmpty()) { currentRow++; @@ -383,7 +383,7 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::NodePoint: case Tool::NodeSpline: case Tool::NodeSplinePath: - break; + return QString(); } } catch (const VExceptionBadId &e) From ca020c4c7f432fdb9d90b029bf17fcdb2e140617 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 18 Mar 2016 12:28:28 +0200 Subject: [PATCH 08/13] Improved visualization for tool Cubic Bezier. --HG-- branch : feature --- src/libs/vtools/visualization/vistoolcubicbezier.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/vtools/visualization/vistoolcubicbezier.cpp b/src/libs/vtools/visualization/vistoolcubicbezier.cpp index c6d3af4ca..7d534657a 100644 --- a/src/libs/vtools/visualization/vistoolcubicbezier.cpp +++ b/src/libs/vtools/visualization/vistoolcubicbezier.cpp @@ -62,12 +62,11 @@ void VisToolCubicBezier::RefreshGeometry() if (object1Id > NULL_ID) { const auto first = Visualization::data->GeometricObject(object1Id); - DrawPoint(point1, first->toQPointF(), supportColor); + DrawPoint(point1, first->toQPointF(), Qt::DashLine); if (object2Id <= NULL_ID) { - const QLineF line = QLineF(first->toQPointF(), Visualization::scenePos); - DrawLine(helpLine1, line, mainColor, Qt::DashLine); + DrawLine(helpLine1, QLineF(first->toQPointF(), Visualization::scenePos), mainColor, Qt::DashLine); } else { @@ -90,6 +89,7 @@ void VisToolCubicBezier::RefreshGeometry() { VCubicBezier spline(*first, *second, *third, VPointF(Visualization::scenePos)); DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); + DrawLine(helpLine2, QLineF(third->toQPointF(), Visualization::scenePos), mainColor, Qt::DashLine); } else { From 19265e1f93ebc2cf7f3f99bc9cab34fef8ce0863 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 18 Mar 2016 23:11:14 +0200 Subject: [PATCH 09/13] Succesful build. --HG-- branch : feature --- .../core/vtooloptionspropertybrowser.cpp | 62 ++++ .../core/vtooloptionspropertybrowser.h | 3 + src/app/valentina/mainwindow.cpp | 6 +- src/app/valentina/xml/vpattern.cpp | 72 +++- src/app/valentina/xml/vpattern.h | 1 + src/libs/vgeometry/vpointf.h | 3 + src/libs/vtools/dialogs/dialogs.pri | 9 +- src/libs/vtools/dialogs/tooldialogs.h | 1 + .../dialogs/tools/dialogcubicbezierpath.cpp | 312 ++++++++++++++++++ .../dialogs/tools/dialogcubicbezierpath.h | 80 +++++ .../dialogs/tools/dialogcubicbezierpath.ui | 130 ++++++++ src/libs/vtools/tools/drawTools/drawtools.h | 1 + .../tools/drawTools/toolcurve/vtoolarc.h | 2 +- .../drawTools/toolcurve/vtoolarcwithlength.h | 2 +- .../drawTools/toolcurve/vtoolcubicbezier.h | 2 +- .../toolcurve/vtoolcubicbezierpath.cpp | 254 ++++++++++++++ .../toolcurve/vtoolcubicbezierpath.h | 73 ++++ .../tools/drawTools/toolcurve/vtoolspline.h | 2 +- .../drawTools/toolcurve/vtoolsplinepath.cpp | 6 +- .../drawTools/toolcurve/vtoolsplinepath.h | 5 +- src/libs/vtools/tools/tools.pri | 6 +- .../visualization/vistoolcubicbezierpath.cpp | 206 ++++++++++++ .../visualization/vistoolcubicbezierpath.h | 65 ++++ .../vtools/visualization/vistoolsplinepath.h | 2 +- .../vtools/visualization/visualization.cpp | 3 +- src/libs/vtools/visualization/visualization.h | 2 +- .../vtools/visualization/visualization.pri | 6 +- 27 files changed, 1289 insertions(+), 27 deletions(-) create mode 100644 src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp create mode 100644 src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h create mode 100644 src/libs/vtools/dialogs/tools/dialogcubicbezierpath.ui create mode 100644 src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp create mode 100644 src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h create mode 100644 src/libs/vtools/visualization/vistoolcubicbezierpath.cpp create mode 100644 src/libs/vtools/visualization/vistoolcubicbezierpath.h diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 303c70c25..b508af5f5 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -73,6 +73,9 @@ void VToolOptionsPropertyBrowser::ClearPropertyBrowser() //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) { + // This check helps to find missed tools in the switch + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in switch."); + switch (item->type()) { case VToolBasePoint::Type: @@ -141,6 +144,9 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) case VToolSplinePath::Type: ShowOptionsToolSplinePath(item); break; + case VToolCubicBezierPath::Type: + ShowOptionsToolCubicBezierPath(item); + break; case VToolTriangle::Type: ShowOptionsToolTriangle(item); break; @@ -184,6 +190,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions() return; } + // This check helps to find missed tools in the switch + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in switch."); + switch (currentItem->type()) { case VToolBasePoint::Type: @@ -252,6 +261,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions() case VToolSplinePath::Type: UpdateOptionsToolSplinePath(); break; + case VToolCubicBezierPath::Type: + UpdateOptionsToolCubicBezierPath(); + break; case VToolTriangle::Type: UpdateOptionsToolTriangle(); break; @@ -310,6 +322,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) return; } + // This check helps to find missed tools in the switch + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in switch."); + switch (currentItem->type()) { case VToolBasePoint::Type: @@ -378,6 +393,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) case VToolSplinePath::Type: ChangeDataToolSplinePath(prop); break; + case VToolCubicBezierPath::Type: + ChangeDataToolCubicBezierPath(prop); + break; case VToolTriangle::Type: ChangeDataToolTriangle(prop); break; @@ -1404,6 +1422,30 @@ void VToolOptionsPropertyBrowser::ChangeDataToolSplinePath(VProperty *property) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolCubicBezierPath(VProperty *property) +{ + SCASSERT(property != nullptr) + + QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolCubicBezierPath *i = qgraphicsitem_cast(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 = "<(item); + i->ShowVisualization(true); + formView->setTitle(tr("Tool cubic bezier curve")); + + AddPropertyObjectName(i, tr("Name"), true); + AddPropertyLineColor(i, tr("Color"), VAbstractTool::ColorsList(), AttrColor); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolTriangle(QGraphicsItem *item) { @@ -2253,6 +2306,15 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSplinePath() idToProperty[AttrColor]->setValue(VLineColorProperty::IndexOfColor(VAbstractTool::ColorsList(), i->GetLineColor())); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolCubicBezierPath() +{ + auto i = qgraphicsitem_cast(currentItem); + + idToProperty[AttrName]->setValue(i->name()); + idToProperty[AttrColor]->setValue(VLineColorProperty::IndexOfColor(VAbstractTool::ColorsList(), i->GetLineColor())); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolTriangle() { diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.h b/src/app/valentina/core/vtooloptionspropertybrowser.h index a4847e5dd..6ffd7a12b 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.h +++ b/src/app/valentina/core/vtooloptionspropertybrowser.h @@ -140,6 +140,7 @@ private: void ChangeDataToolSpline(VPE::VProperty *property); void ChangeDataToolCubicBezier(VPE::VProperty *property); void ChangeDataToolSplinePath(VPE::VProperty *property); + void ChangeDataToolCubicBezierPath(VPE::VProperty *property); void ChangeDataToolTriangle(VPE::VProperty *property); void ChangeDataToolLineIntersectAxis(VPE::VProperty *property); void ChangeDataToolCurveIntersectAxis(VPE::VProperty *property); @@ -169,6 +170,7 @@ private: void ShowOptionsToolSpline(QGraphicsItem *item); void ShowOptionsToolCubicBezier(QGraphicsItem *item); void ShowOptionsToolSplinePath(QGraphicsItem *item); + void ShowOptionsToolCubicBezierPath(QGraphicsItem *item); void ShowOptionsToolTriangle(QGraphicsItem *item); void ShowOptionsToolLineIntersectAxis(QGraphicsItem *item); void ShowOptionsToolCurveIntersectAxis(QGraphicsItem *item); @@ -198,6 +200,7 @@ private: void UpdateOptionsToolSpline(); void UpdateOptionsToolCubicBezier(); void UpdateOptionsToolSplinePath(); + void UpdateOptionsToolCubicBezierPath(); void UpdateOptionsToolTriangle(); void UpdateOptionsToolLineIntersectAxis(); void UpdateOptionsToolCurveIntersectAxis(); diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index a52ca3972..2c6febaaa 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -833,7 +833,11 @@ void MainWindow::ToolSplinePath(bool checked) //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolCubicBezierPath(bool checked) { - + SetToolButtonWithApply(checked, Tool::CubicBezierPath, + ":/cursor/cubic_bezier_path_cursor.png", + tr("Select point of cubic bezier path"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 01bde6c92..a7bad80df 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -44,6 +44,7 @@ #include "../vgeometry/varc.h" #include "../vgeometry/vsplinepath.h" #include "../vgeometry/vcubicbezier.h" +#include "../vgeometry/vcubicbezierpath.h" #include "../core/vapplication.h" #include "../vpatterndb/calculator.h" @@ -2129,6 +2130,58 @@ void VPattern::ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement } } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParseToolCubicBezierPath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse) +{ + SCASSERT(scene != nullptr); + Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); + + try + { + quint32 id = 0; + + ToolsCommonAttributes(domElement, id); + const QString color = GetParametrString(domElement, AttrColor, ColorBlack); + const quint32 duplicate = GetParametrUInt(domElement, AttrDuplicate, "0"); + + QVector 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(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) { @@ -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(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); - QStringList splines = QStringList() << VToolSpline::OldToolType /*0*/ - << VToolSpline::ToolType /*1*/ - << VToolSplinePath::OldToolType /*2*/ - << VToolSplinePath::ToolType /*3*/ - << VNodeSpline::ToolType /*4*/ - << VNodeSplinePath::ToolType /*5*/ - << VToolCubicBezier::ToolType; /*6*/ + QStringList splines = QStringList() << VToolSpline::OldToolType /*0*/ + << VToolSpline::ToolType /*1*/ + << VToolSplinePath::OldToolType /*2*/ + << VToolSplinePath::ToolType /*3*/ + << VNodeSpline::ToolType /*4*/ + << VNodeSplinePath::ToolType /*5*/ + << VToolCubicBezier::ToolType /*6*/ + << VToolCubicBezierPath::ToolType; /*7*/ switch (splines.indexOf(type)) { case 0: //VToolSpline::OldToolType @@ -2462,6 +2516,10 @@ void VPattern::ParseSplineElement(VMainGraphicsScene *scene, QDomElement &domEle qCDebug(vXML, "VToolCubicBezier."); ParseToolCubicBezier(scene, domElement, parse); break; + case 7: //VToolCubicBezierPath::ToolType + qCDebug(vXML, "VToolCubicBezierPath."); + ParseToolCubicBezierPath(scene, domElement, parse); + break; default: VException e(tr("Unknown spline type '%1'.").arg(type)); throw e; diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 481b0f353..8471662ca 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -176,6 +176,7 @@ private: void ParseOldToolSplinePath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); + void ParseToolCubicBezierPath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseNodeSpline(const QDomElement &domElement, const Document &parse); void ParseNodeSplinePath(const QDomElement &domElement, const Document &parse); diff --git a/src/libs/vgeometry/vpointf.h b/src/libs/vgeometry/vpointf.h index 04fa0d8ae..7494a1405 100644 --- a/src/libs/vgeometry/vpointf.h +++ b/src/libs/vgeometry/vpointf.h @@ -31,6 +31,8 @@ #include "vgobject.h" +#include + class QPointF; class QString; class VPointFData; @@ -69,6 +71,7 @@ private: QSharedDataPointer d; }; +Q_DECLARE_METATYPE(VPointF) Q_DECLARE_TYPEINFO(VPointF, Q_MOVABLE_TYPE); #if defined(Q_CC_INTEL) diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index a432d4e95..fd77d2ce3 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -35,7 +35,8 @@ HEADERS += \ $$PWD/support/dialogundo.h \ $$PWD/tools/dialogtruedarts.h \ $$PWD/tools/dialogpointofintersectioncurves.h \ - $$PWD/tools/dialogcubicbezier.h + $$PWD/tools/dialogcubicbezier.h \ + $$PWD/tools/dialogcubicbezierpath.h SOURCES += \ $$PWD/tools/dialogalongline.cpp \ @@ -70,7 +71,8 @@ SOURCES += \ $$PWD/support/dialogundo.cpp \ $$PWD/tools/dialogtruedarts.cpp \ $$PWD/tools/dialogpointofintersectioncurves.cpp \ - $$PWD/tools/dialogcubicbezier.cpp + $$PWD/tools/dialogcubicbezier.cpp \ + $$PWD/tools/dialogcubicbezierpath.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ @@ -104,4 +106,5 @@ FORMS += \ $$PWD/support/dialogundo.ui \ $$PWD/tools/dialogtruedarts.ui \ $$PWD/tools/dialogpointofintersectioncurves.ui \ - $$PWD/tools/dialogcubicbezier.ui + $$PWD/tools/dialogcubicbezier.ui \ + $$PWD/tools/dialogcubicbezierpath.ui diff --git a/src/libs/vtools/dialogs/tooldialogs.h b/src/libs/vtools/dialogs/tooldialogs.h index c37b25f3b..08326cce0 100644 --- a/src/libs/vtools/dialogs/tooldialogs.h +++ b/src/libs/vtools/dialogs/tooldialogs.h @@ -44,6 +44,7 @@ #include "dialogs/tools/dialogspline.h" #include "dialogs/tools/dialogcubicbezier.h" #include "dialogs/tools/dialogsplinepath.h" +#include "dialogs/tools/dialogcubicbezierpath.h" #include "dialogs/tools/dialogheight.h" #include "dialogs/tools/dialogcutarc.h" #include "dialogs/tools/dialogcutspline.h" diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp new file mode 100644 index 000000000..ddb7400b7 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp @@ -0,0 +1,312 @@ +/************************************************************************ + ** + ** @file dialogcubicbezierpath.cpp + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#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 +#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(&QComboBox::currentIndexChanged), + this, &DialogCubicBezierPath::currentPointChanged); + + vis = new VisToolCubicBezierPath(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogCubicBezierPath::~DialogCubicBezierPath() +{ + DeleteVisualization(); + 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(vis); + SCASSERT(visPath != nullptr); + visPath->setPath(path); + ui->listWidget->blockSignals(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogCubicBezierPath::GetColor() const +{ + return GetComboBoxCurrentData(ui->comboBoxColor); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::SetColor(const QString &value) +{ + ChangeCurrentData(ui->comboBoxColor, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::ChosenObject(quint32 id, const SceneObject &type) +{ + if (type == SceneObject::Point) + { + if (AllIds().contains(id)) + { + return; + } + + const auto point = data->GeometricObject(id); + NewItem(*point); + + SavePath(); + + auto visPath = qobject_cast(vis); + SCASSERT(visPath != nullptr); + visPath->setPath(path); + + if (path.CountPoints() == 1) + { + visPath->VisualMode(NULL_ID); + connect(visPath, &VisToolCubicBezierPath::ToolTip, this, &DialogTool::ShowVisToolTip); + } + else + { + visPath->RefreshGeometry(); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::ShowDialog(bool click) +{ + if (click == false) + { + if (path.CountPoints() >= 7) + { + if (path.CountPoints() - ((path.CountSubSpl() - 1) * 3 + 4) == 0) + {// Accept only if all subpaths are completed + emit ToolTip(""); + + if (not data->IsUnique(path.name())) + { + path.SetDuplicate(DNumber(path.name())); + } + + DialogAccepted(); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::ShowVisualization() +{ + AddVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::SaveData() +{ + const quint32 d = path.GetDuplicate();//Save previous value + SavePath(); + newDuplicate <= -1 ? path.SetDuplicate(d) : path.SetDuplicate(static_cast(newDuplicate)); + + auto visPath = qobject_cast(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(ui->listWidget->item(row)->data(Qt::UserRole)); + DataPoint(p); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::currentPointChanged(int index) +{ + const quint32 id = qvariant_cast(ui->comboBoxPoint->itemData(index)); + QListWidgetItem *item = ui->listWidget->item( ui->listWidget->currentRow() ); + const auto point = data->GeometricObject(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(ui->listWidget->item(0)->data(Qt::UserRole)); + auto last = qvariant_cast(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 DialogCubicBezierPath::AllIds() const +{ + QVector points; + for (qint32 i = 0; i < ui->listWidget->count(); ++i) + { + points.append(qvariant_cast(ui->listWidget->item(i)->data(Qt::UserRole)).id()); + } + + QSet ids; + const qint32 count = qFloor(qAbs((points.size() - 4) / 3 + 1));// Count subpaths + for (qint32 i = 0; i < count; ++i) + { + const qint32 base = (i - 1) * 3; + ids.insert(points.at(base));// The first subpath's point + ids.insert(points.at(base + 3));// The last subpath's point + } + + return ids; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogCubicBezierPath::IsPathValid() const +{ + if (path.CountPoints() < 7) + { + return false; + } + + return (AllIds().size() == path.CountSubSpl() + 1); +} + +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezierPath DialogCubicBezierPath::ExtractPath() const +{ + QVector points; + for (qint32 i = 0; i < ui->listWidget->count(); ++i) + { + points.append(qvariant_cast(ui->listWidget->item(i)->data(Qt::UserRole))); + } + return VCubicBezierPath(points); +} diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h new file mode 100644 index 000000000..a9b56975a --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h @@ -0,0 +1,80 @@ +/************************************************************************ + ** + ** @file dialogcubicbezierpath.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#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 AllIds() const; + bool IsPathValid() const; + VCubicBezierPath ExtractPath() const; +}; + +#endif // DIALOGCUBICBEZIERPATH_H diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.ui b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.ui new file mode 100644 index 000000000..85f4b80a7 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.ui @@ -0,0 +1,130 @@ + + + DialogCubicBezierPath + + + + 0 + 0 + 324 + 327 + + + + Dialog cubic bezier path + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + + + + + + + + + + + + Point: + + + + + + + + + + + + + + List of points + + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Color: + + + + + + + + + + Name: + + + + + + + true + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogCubicBezierPath + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogCubicBezierPath + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libs/vtools/tools/drawTools/drawtools.h b/src/libs/vtools/tools/drawTools/drawtools.h index fa96e5bfc..5b0bee7ff 100644 --- a/src/libs/vtools/tools/drawTools/drawtools.h +++ b/src/libs/vtools/tools/drawTools/drawtools.h @@ -42,6 +42,7 @@ #include "toolcurve/vtoolspline.h" #include "toolcurve/vtoolcubicbezier.h" #include "toolcurve/vtoolsplinepath.h" +#include "toolcurve/vtoolcubicbezierpath.h" #include "vtoolline.h" #include "toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h" #include "toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h" diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h index 3fe9ddef8..cbcd0f33c 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h @@ -73,7 +73,7 @@ protected: virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: - void RefreshGeometry(); + virtual void RefreshGeometry() Q_DECL_OVERRIDE; }; #endif // VTOOLARC_H diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h index a1c8572e8..e0446548a 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h @@ -74,7 +74,7 @@ protected: virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: - void RefreshGeometry(); + virtual void RefreshGeometry() Q_DECL_OVERRIDE; }; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h index 0bde70ef8..ca8d53ed8 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h @@ -63,7 +63,7 @@ protected: private: Q_DISABLE_COPY(VToolCubicBezier) - void RefreshGeometry (); + virtual void RefreshGeometry() Q_DECL_OVERRIDE; void SetSplineAttributes(QDomElement &domElement, const VCubicBezier &spl); }; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp new file mode 100644 index 000000000..fd07b2304 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp @@ -0,0 +1,254 @@ +/************************************************************************ + ** + ** @file vtoolcubicbezierpath.cpp + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#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(dialog); + SCASSERT(dialogTool != nullptr); + const QSharedPointer splPath = VAbstractTool::data.GeometricObject(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(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(id); + } + else + { + data->UpdateGObject(id, path); + data->AddCurve(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 splPath = VAbstractTool::data.GeometricObject(id); + return *splPath.data(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::setSplinePath(const VCubicBezierPath &splPath) +{ + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer splinePath = qSharedPointerDynamicCast(obj); + *splinePath.data() = splPath; + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::ShowVisualization(bool show) +{ + ShowToolVisualization(show); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::RemoveReferens() +{ + const QSharedPointer splPath = VAbstractTool::data.GeometricObject(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(dialog); + SCASSERT(dialogTool != nullptr); + + doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor()); + SetSplinePathAttributes(domElement, dialogTool->GetPath()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + VAbstractSpline::SaveOptions(tag, obj); + + QSharedPointer splPath = qSharedPointerDynamicCast(obj); + SCASSERT(splPath.isNull() == false); + + SetSplinePathAttributes(tag, *splPath); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::SetVisualization() +{ + if (vis != nullptr) + { + auto visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + QSharedPointer splPath = VAbstractTool::data.GeometricObject(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); +} diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h new file mode 100644 index 000000000..29089fe2b --- /dev/null +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h @@ -0,0 +1,73 @@ +/************************************************************************ + ** + ** @file vtoolcubicbezierpath.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#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(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 &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 diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h index d3a411123..e404087a6 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h @@ -81,7 +81,7 @@ private: QPointF oldPosition; bool IsMovable() const; - void RefreshGeometry (); + virtual void RefreshGeometry() Q_DECL_OVERRIDE; void SetSplineAttributes(QDomElement &domElement, const VSpline &spl); }; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index e402ba19c..b88c12e7a 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -389,10 +389,10 @@ void VToolSplinePath::AddPathPoint(VAbstractPattern *doc, QDomElement &domElemen */ void VToolSplinePath::RemoveReferens() { - const VSplinePath splPath = *VAbstractTool::data.GeometricObject(id); - for (qint32 i = 0; i < splPath.CountSubSpl(); ++i) + const QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); + for (qint32 i = 0; i < splPath->CountSubSpl(); ++i) { - doc->DecrementReferens(splPath.at(i).P().getIdTool()); + doc->DecrementReferens(splPath->at(i).P().getIdTool()); } } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h index dc12005dc..a7035225e 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h @@ -46,7 +46,7 @@ public: const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual ~VToolSplinePath() Q_DECL_OVERRIDE; - virtual void setDialog(); + virtual void setDialog() Q_DECL_OVERRIDE; static VToolSplinePath *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolSplinePath *Create(const quint32 _id, VSplinePath *path, const QString &color, @@ -100,11 +100,12 @@ protected: virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: + Q_DISABLE_COPY(VToolSplinePath) QPointF oldPosition; int splIndex; bool IsMovable(int index) const; - void RefreshGeometry(); + virtual void RefreshGeometry() Q_DECL_OVERRIDE; static void AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VSplinePoint &splPoint); void UpdateControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline) const; void SetSplinePathAttributes(QDomElement &domElement, const VSplinePath &path); diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index dcf73d160..a8ed05c2e 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -48,7 +48,8 @@ HEADERS += \ $$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h \ $$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h \ - $$PWD/drawTools/toolcurve/vtoolcubicbezier.h + $$PWD/drawTools/toolcurve/vtoolcubicbezier.h \ + $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -94,4 +95,5 @@ SOURCES += \ $$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp \ $$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp \ - $$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp + $$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp \ + $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp diff --git a/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp b/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp new file mode 100644 index 000000000..a519a14c4 --- /dev/null +++ b/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp @@ -0,0 +1,206 @@ +/************************************************************************ + ** + ** @file vistoolcubicbezierpath.cpp + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#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(mainColor, this); + helpLine2 = InitItem(mainColor, this); + + newCurveSegment = InitItem(mainColor, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolCubicBezierPath::~VisToolCubicBezierPath() +{ + qDeleteAll(mainPoints); + qDeleteAll(lines); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCubicBezierPath::RefreshGeometry() +{ + if (path.CountPoints() > 0) + { + const QVector pathPoints = path.GetSplinePath(); + const int size = pathPoints.size(); + const int countSubSpl = path.CountSubSpl(); + + for (int i = 0; i < size; ++i) + { + QGraphicsEllipseItem *point = this->getPoint(mainPoints, static_cast(i), 1/*zValue*/); + DrawPoint(point, pathPoints.at(i).toQPointF(), supportColor); + } + + if (mode == Mode::Creation) + { + for (qint32 i = 1; i<=countSubSpl; ++i) + { + const int preLastPoint = (countSubSpl - 1) * 2; + const int lastPoint = preLastPoint + 1; + + const VSpline spl = path.GetSpline(i); + + QGraphicsLineItem *ctrlLine1 = this->getLine(static_cast(preLastPoint)); + DrawLine(ctrlLine1, QLineF(spl.GetP1().toQPointF(), spl.GetP2()), mainColor, Qt::DashLine); + + QGraphicsEllipseItem *p2 = this->getPoint(ctrlPoints, static_cast(preLastPoint)); + DrawPoint(p2, spl.GetP2(), Qt::green); + + QGraphicsLineItem *ctrlLine2 = this->getLine(static_cast(lastPoint)); + DrawLine(ctrlLine2, QLineF(spl.GetP4().toQPointF(), spl.GetP3()), mainColor, Qt::DashLine); + + QGraphicsEllipseItem *p3 = this->getPoint(ctrlPoints, static_cast(lastPoint)); + DrawPoint(p3, spl.GetP3(), Qt::green); + } + + const qint32 last = (countSubSpl - 1) * 3 + 3; + Creating(pathPoints, size-1-last); + } + + if (countSubSpl >= 1) + { + DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); + } + + if (countSubSpl < 7) + { + Visualization::toolTip = tr("Curved path: select seven or more points"); + } + else if (countSubSpl >= 7 && size - ((countSubSpl - 1) * 3 + 4) == 0) + { + Visualization::toolTip = tr("Curved path: select seven or more points, " + "Enter - finish creation"); + } + else + { + Visualization::toolTip = tr("Curved path: select more points for complete segment"); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCubicBezierPath::setPath(const VCubicBezierPath &value) +{ + path = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +VCubicBezierPath VisToolCubicBezierPath::getPath() +{ + return path; +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsEllipseItem *VisToolCubicBezierPath::getPoint(QVector &points, quint32 i, qreal z) +{ + if (not points.isEmpty() && static_cast(points.size() - 1) >= i) + { + return points.at(static_cast(i)); + } + else + { + auto point = InitPoint(supportColor, this, z); + points.append(point); + return point; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsLineItem *VisToolCubicBezierPath::getLine(quint32 i) +{ + if (static_cast(lines.size() - 1) >= i && lines.isEmpty() == false) + { + return lines.at(static_cast(i)); + } + else + { + auto line = InitItem(mainColor, this); + lines.append(line); + return line; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCubicBezierPath::Creating(const QVector &pathPoints, int pointsLeft) +{ + if (pathPoints.isEmpty() || pathPoints.size()+1 < pointsLeft) + { + return; + } + + switch(pointsLeft) + { + case 0: + { + const QPointF p1 = pathPoints.last().toQPointF(); + DrawLine(helpLine1, QLineF(p1, Visualization::scenePos), mainColor, Qt::DashLine); + break; + } + case 1: + { + const VPointF p1 = pathPoints.at(pointsLeft-1); + const QPointF p2 = pathPoints.at(pointsLeft).toQPointF(); + + DrawLine(helpLine1, QLineF(p1.toQPointF(), p2), mainColor, Qt::DashLine); + + VSpline spline(p1, p2, Visualization::scenePos, VPointF(Visualization::scenePos)); + DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); + break; + } + case 2: + { + const VPointF p1 = pathPoints.at(pointsLeft-2); + const QPointF p2 = pathPoints.at(pointsLeft-1).toQPointF(); + const QPointF p3 = pathPoints.at(pointsLeft).toQPointF(); + + DrawLine(helpLine1, QLineF(p1.toQPointF(), p2), mainColor, Qt::DashLine); + DrawLine(helpLine2, QLineF(p3, Visualization::scenePos), mainColor, Qt::DashLine); + + VSpline spline(p1, p2, p3, VPointF(Visualization::scenePos)); + DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); + break; + } + default: + break; + } +} diff --git a/src/libs/vtools/visualization/vistoolcubicbezierpath.h b/src/libs/vtools/visualization/vistoolcubicbezierpath.h new file mode 100644 index 000000000..d33ddea1c --- /dev/null +++ b/src/libs/vtools/visualization/vistoolcubicbezierpath.h @@ -0,0 +1,65 @@ +/************************************************************************ + ** + ** @file vistoolcubicbezierpath.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#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(Vis::ToolCubicBezierPath)}; + +protected: + Q_DISABLE_COPY(VisToolCubicBezierPath) + QVector mainPoints; + QVector ctrlPoints; + QVector lines; + QGraphicsPathItem *newCurveSegment; + VCubicBezierPath path; + QGraphicsLineItem *helpLine1; + QGraphicsLineItem *helpLine2; + + QGraphicsEllipseItem *getPoint(QVector &points, quint32 i, qreal z = 0); + QGraphicsLineItem *getLine(quint32 i); + void Creating(const QVector &pathPoints , int pointsLeft); +}; + +#endif // VISTOOLCUBICBEZIERPATH_H diff --git a/src/libs/vtools/visualization/vistoolsplinepath.h b/src/libs/vtools/visualization/vistoolsplinepath.h index cbddfef70..8707463ac 100644 --- a/src/libs/vtools/visualization/vistoolsplinepath.h +++ b/src/libs/vtools/visualization/vistoolsplinepath.h @@ -38,7 +38,7 @@ class VisToolSplinePath : public VisPath { Q_OBJECT public: - explicit VisToolSplinePath(const VContainer *data, QGraphicsItem *parent = 0); + explicit VisToolSplinePath(const VContainer *data, QGraphicsItem *parent = nullptr); virtual ~VisToolSplinePath() Q_DECL_OVERRIDE; virtual void RefreshGeometry() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/visualization/visualization.cpp b/src/libs/vtools/visualization/visualization.cpp index 23c151801..cc7c7c3aa 100644 --- a/src/libs/vtools/visualization/visualization.cpp +++ b/src/libs/vtools/visualization/visualization.cpp @@ -113,7 +113,7 @@ void Visualization::MousePos(const QPointF &scenePos) } //--------------------------------------------------------------------------------------------------------------------- -QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsItem *parent) const +QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsItem *parent, qreal z) const { QGraphicsEllipseItem *point = new QGraphicsEllipseItem(parent); point->setZValue(1); @@ -122,6 +122,7 @@ QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsIte point->setRect(PointRect(ToPixel(DefPointRadius/*mm*/, Unit::Mm))); point->setPos(QPointF()); point->setFlags(QGraphicsItem::ItemStacksBehindParent); + point->setZValue(z); point->setVisible(false); return point; } diff --git a/src/libs/vtools/visualization/visualization.h b/src/libs/vtools/visualization/visualization.h index 03339f02e..f4be1c451 100644 --- a/src/libs/vtools/visualization/visualization.h +++ b/src/libs/vtools/visualization/visualization.h @@ -80,7 +80,7 @@ protected: virtual void InitPen()=0; virtual void AddOnScene()=0; - QGraphicsEllipseItem *InitPoint(const QColor &color, QGraphicsItem *parent) const; + QGraphicsEllipseItem *InitPoint(const QColor &color, QGraphicsItem *parent, qreal z = 0) const; QRectF PointRect(const qreal &radius) const; void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, Qt::PenStyle style = Qt::SolidLine); diff --git a/src/libs/vtools/visualization/visualization.pri b/src/libs/vtools/visualization/visualization.pri index f1139b5ff..ffd124876 100644 --- a/src/libs/vtools/visualization/visualization.pri +++ b/src/libs/vtools/visualization/visualization.pri @@ -31,7 +31,8 @@ HEADERS += \ $$PWD/vistoolarcwithlength.h \ $$PWD/vistooltruedarts.h \ $$PWD/vistoolpointofintersectioncurves.h \ - $$PWD/vistoolcubicbezier.h + $$PWD/vistoolcubicbezier.h \ + $$PWD/vistoolcubicbezierpath.h SOURCES += \ $$PWD/visline.cpp \ @@ -63,4 +64,5 @@ SOURCES += \ $$PWD/vistoolarcwithlength.cpp \ $$PWD/vistooltruedarts.cpp \ $$PWD/vistoolpointofintersectioncurves.cpp \ - $$PWD/vistoolcubicbezier.cpp + $$PWD/vistoolcubicbezier.cpp \ + $$PWD/vistoolcubicbezierpath.cpp From 30ece7e8560a097968a006a94fbf0c8c0e3bf0ae Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 19 Mar 2016 10:38:29 +0200 Subject: [PATCH 10/13] Unfortunately we can't throw template. QGrapthisItem class is not reachable in this case. --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 61 +++++++++++++++++++++++++++++- src/app/valentina/xml/vpattern.h | 1 + 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index a7bad80df..e7d0bd65e 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -3115,35 +3115,91 @@ QRectF VPattern::ActiveDrawBoundingRect() const Q_UNREACHABLE(); break; case Tool::BasePoint: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::EndLine: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::Line: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::AlongLine: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::ShoulderPoint: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::Normal: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::Bisector: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::LineIntersect: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::Spline: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::CubicBezier: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::Arc: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::SplinePath: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::CubicBezierPath: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::PointOfContact: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::Height: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::Triangle: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::PointOfIntersection: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::CutArc: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::CutSpline: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::CutSplinePath: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::ArcWithLength: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::LineIntersectAxis: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::PointOfIntersectionArcs: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::PointOfIntersectionCircles: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::PointOfIntersectionCurves: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::CurveIntersectAxis: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::PointFromCircleAndTangent: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::PointFromArcAndTangent: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::TrueDarts: - rec = ToolBoundingRect(rec, tool.getId()); + rec = ToolBoundingRect(rec, tool.getId()); break; //These tools are not accesseble in Draw mode, but still 'history' contains them. case Tool::Detail: @@ -3164,12 +3220,13 @@ QRectF VPattern::ActiveDrawBoundingRect() const #endif //--------------------------------------------------------------------------------------------------------------------- +template QRectF VPattern::ToolBoundingRect(const QRectF &rec, const quint32 &id) const { QRectF recTool = rec; if (tools.contains(id)) { - const QGraphicsItem *vTool = qobject_cast(tools.value(id)); + const T *vTool = qobject_cast(tools.value(id)); SCASSERT(vTool != nullptr); QRectF childrenRect = vTool->childrenBoundingRect(); diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 8471662ca..c65ccb6d1 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -135,6 +135,7 @@ private: void PointsCommonAttributes(const QDomElement &domElement, quint32 &id, qreal &mx, qreal &my); void SplinesCommonAttributes(const QDomElement &domElement, quint32 &id, quint32 &idObject, quint32 &idTool); + template QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const; void ParseCurrentPP(); QString GetLabelBase(quint32 index)const; From 505cec891d2e49ab27b34c5589915203fb916585 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 19 Mar 2016 16:20:09 +0200 Subject: [PATCH 11/13] Several bug fixes. --HG-- branch : feature --- .../vgeometry/vabstractcubicbezierpath.cpp | 10 +- src/libs/vgeometry/vcubicbezierpath.cpp | 39 ++++- src/libs/vgeometry/vcubicbezierpath.h | 4 + src/libs/vgeometry/vsplinepath.cpp | 2 +- .../dialogs/tools/dialogcubicbezierpath.cpp | 17 ++- .../dialogs/tools/dialogcubicbezierpath.h | 2 +- .../visualization/vistoolcubicbezierpath.cpp | 140 +++++++++++++----- .../visualization/vistoolcubicbezierpath.h | 2 + src/test/ValentinaTest/ValentinaTest.pro | 6 +- src/test/ValentinaTest/qttestmainlambda.cpp | 2 + .../ValentinaTest/tst_vcubicbezierpath.cpp | 122 +++++++++++++++ src/test/ValentinaTest/tst_vcubicbezierpath.h | 53 +++++++ 12 files changed, 345 insertions(+), 54 deletions(-) create mode 100644 src/test/ValentinaTest/tst_vcubicbezierpath.cpp create mode 100644 src/test/ValentinaTest/tst_vcubicbezierpath.h diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.cpp b/src/libs/vgeometry/vabstractcubicbezierpath.cpp index f113e9757..d5d7d736d 100644 --- a/src/libs/vgeometry/vabstractcubicbezierpath.cpp +++ b/src/libs/vgeometry/vabstractcubicbezierpath.cpp @@ -214,14 +214,14 @@ void VAbstractCubicBezierPath::CreateName() { name = splPath; name.append(QString("_%1").arg(FirstPoint().name())); - if (CountSubSpl() >= 1) + if (CountSubSpl() >= 2) { name.append(QString("_%1").arg(LastPoint().name())); - } - if (GetDuplicate() > 0) - { - name += QString("_%1").arg(GetDuplicate()); + if (GetDuplicate() > 0) + { + name += QString("_%1").arg(GetDuplicate()); + } } } setName(name); diff --git a/src/libs/vgeometry/vcubicbezierpath.cpp b/src/libs/vgeometry/vcubicbezierpath.cpp index dbb7a31a6..c4c257446 100644 --- a/src/libs/vgeometry/vcubicbezierpath.cpp +++ b/src/libs/vgeometry/vcubicbezierpath.cpp @@ -109,7 +109,7 @@ void VCubicBezierPath::append(const VPointF &point) //--------------------------------------------------------------------------------------------------------------------- qint32 VCubicBezierPath::CountSubSpl() const { - return qFloor(qAbs((d->path.size() - 4) / 3 + 1)); + return CountSubSpl(d->path.size()); } //--------------------------------------------------------------------------------------------------------------------- @@ -138,7 +138,7 @@ VSpline VCubicBezierPath::GetSpline(qint32 index) const throw VException(tr("This spline does not exist.")); } - const qint32 base = (index - 1) * 3; + 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(); @@ -189,6 +189,38 @@ QVector 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 { @@ -208,8 +240,7 @@ VPointF VCubicBezierPath::LastPoint() const const qint32 count = CountSubSpl(); if (count >= 1) { - const qint32 base = (count - 1) * 3; - return d->path.at(base + 3);// Take last point of the last real spline + return d->path.at(SubSplOffset(count) + 3);// Take last point of the last real spline } else { diff --git a/src/libs/vgeometry/vcubicbezierpath.h b/src/libs/vgeometry/vcubicbezierpath.h index ac67abd31..b83fbd6f6 100644 --- a/src/libs/vgeometry/vcubicbezierpath.h +++ b/src/libs/vgeometry/vcubicbezierpath.h @@ -61,6 +61,10 @@ public: virtual qreal GetEndAngle () const Q_DECL_OVERRIDE; QVector 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; diff --git a/src/libs/vgeometry/vsplinepath.cpp b/src/libs/vgeometry/vsplinepath.cpp index 775e8c206..64a2a5590 100644 --- a/src/libs/vgeometry/vsplinepath.cpp +++ b/src/libs/vgeometry/vsplinepath.cpp @@ -133,7 +133,7 @@ void VSplinePath::append(const VSplinePoint &point) */ qint32 VSplinePath::CountSubSpl() const { - if (d->path.size() == 0) + if (d->path.isEmpty()) { return 0; } diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp index ddb7400b7..03cb04b65 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp @@ -107,7 +107,7 @@ void DialogCubicBezierPath::ChosenObject(quint32 id, const SceneObject &type) { if (type == SceneObject::Point) { - if (AllIds().contains(id)) + if (AllPathBackboneIds().contains(id)) { return; } @@ -138,9 +138,10 @@ void DialogCubicBezierPath::ShowDialog(bool click) { if (click == false) { - if (path.CountPoints() >= 7) + const int size = path.CountPoints(); + if (size >= 7) { - if (path.CountPoints() - ((path.CountSubSpl() - 1) * 3 + 4) == 0) + if (size - VCubicBezierPath::SubSplPointsCount(path.CountSubSpl()) == 0) {// Accept only if all subpaths are completed emit ToolTip(""); @@ -269,7 +270,7 @@ void DialogCubicBezierPath::SavePath() } //--------------------------------------------------------------------------------------------------------------------- -QSet DialogCubicBezierPath::AllIds() const +QSet DialogCubicBezierPath::AllPathBackboneIds() const { QVector points; for (qint32 i = 0; i < ui->listWidget->count(); ++i) @@ -278,10 +279,10 @@ QSet DialogCubicBezierPath::AllIds() const } QSet ids; - const qint32 count = qFloor(qAbs((points.size() - 4) / 3 + 1));// Count subpaths - for (qint32 i = 0; i < count; ++i) + const qint32 count = VCubicBezierPath::CountSubSpl(points.size());// Count subpaths + for (qint32 i = 1; i <= count; ++i) { - const qint32 base = (i - 1) * 3; + 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 } @@ -297,7 +298,7 @@ bool DialogCubicBezierPath::IsPathValid() const return false; } - return (AllIds().size() == path.CountSubSpl() + 1); + return (AllPathBackboneIds().size() == path.CountSubSpl() + 1); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h index a9b56975a..ead6931de 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h @@ -72,7 +72,7 @@ private: void NewItem(const VPointF &point); void DataPoint(const VPointF &p); void SavePath(); - QSet AllIds() const; + QSet AllPathBackboneIds() const; bool IsPathValid() const; VCubicBezierPath ExtractPath() const; }; diff --git a/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp b/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp index a519a14c4..5e0445836 100644 --- a/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp +++ b/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp @@ -56,11 +56,11 @@ VisToolCubicBezierPath::~VisToolCubicBezierPath() //--------------------------------------------------------------------------------------------------------------------- void VisToolCubicBezierPath::RefreshGeometry() { - if (path.CountPoints() > 0) + const QVector pathPoints = path.GetSplinePath(); + const int size = pathPoints.size(); + if (size > 0) { - const QVector pathPoints = path.GetSplinePath(); - const int size = pathPoints.size(); - const int countSubSpl = path.CountSubSpl(); + const int countSubSpl = VCubicBezierPath::CountSubSpl(size); for (int i = 0; i < size; ++i) { @@ -70,6 +70,21 @@ void VisToolCubicBezierPath::RefreshGeometry() 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; @@ -89,29 +104,9 @@ void VisToolCubicBezierPath::RefreshGeometry() QGraphicsEllipseItem *p3 = this->getPoint(ctrlPoints, static_cast(lastPoint)); DrawPoint(p3, spl.GetP3(), Qt::green); } - - const qint32 last = (countSubSpl - 1) * 3 + 3; - Creating(pathPoints, size-1-last); } - if (countSubSpl >= 1) - { - DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); - } - - if (countSubSpl < 7) - { - Visualization::toolTip = tr("Curved path: select seven or more points"); - } - else if (countSubSpl >= 7 && size - ((countSubSpl - 1) * 3 + 4) == 0) - { - Visualization::toolTip = tr("Curved path: select seven or more points, " - "Enter - finish creation"); - } - else - { - Visualization::toolTip = tr("Curved path: select more points for complete segment"); - } + RefreshToolTip(); } } @@ -119,6 +114,8 @@ void VisToolCubicBezierPath::RefreshGeometry() void VisToolCubicBezierPath::setPath(const VCubicBezierPath &value) { path = value; + + RefreshToolTip(); } //--------------------------------------------------------------------------------------------------------------------- @@ -163,44 +160,121 @@ QGraphicsLineItem *VisToolCubicBezierPath::getLine(quint32 i) //--------------------------------------------------------------------------------------------------------------------- void VisToolCubicBezierPath::Creating(const QVector &pathPoints, int pointsLeft) { - if (pathPoints.isEmpty() || pathPoints.size()+1 < 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 QPointF p1 = pathPoints.last().toQPointF(); - DrawLine(helpLine1, QLineF(p1, Visualization::scenePos), mainColor, Qt::DashLine); + 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(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(pointsLeft-1); - const QPointF p2 = pathPoints.at(pointsLeft).toQPointF(); + 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(preLastPoint)); + DrawPoint(p2Ctrl, p2, Qt::green); break; } case 2: { - const VPointF p1 = pathPoints.at(pointsLeft-2); - const QPointF p2 = pathPoints.at(pointsLeft-1).toQPointF(); - const QPointF p3 = pathPoints.at(pointsLeft).toQPointF(); + 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(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("Curved path: select seven or more points"); + } + else if (size >= 7 && size - VCubicBezierPath::SubSplPointsCount(countSubSpl) == 0) + { + Visualization::toolTip = tr("Curved path: select seven or more points, " + "Enter - finish creation"); + } + else + { + Visualization::toolTip = tr("Curved path: select more points for complete segment"); + } + emit ToolTip(Visualization::toolTip); + } +} diff --git a/src/libs/vtools/visualization/vistoolcubicbezierpath.h b/src/libs/vtools/visualization/vistoolcubicbezierpath.h index d33ddea1c..32943d714 100644 --- a/src/libs/vtools/visualization/vistoolcubicbezierpath.h +++ b/src/libs/vtools/visualization/vistoolcubicbezierpath.h @@ -57,9 +57,11 @@ protected: QGraphicsLineItem *helpLine1; QGraphicsLineItem *helpLine2; +private: QGraphicsEllipseItem *getPoint(QVector &points, quint32 i, qreal z = 0); QGraphicsLineItem *getLine(quint32 i); void Creating(const QVector &pathPoints , int pointsLeft); + void RefreshToolTip(); }; #endif // VISTOOLCUBICBEZIERPATH_H diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index a57763b63..5e6434567 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -56,7 +56,8 @@ SOURCES += \ tst_vdetail.cpp \ tst_vabstractcurve.cpp \ tst_findpoint.cpp \ - tst_vellipticalarc.cpp + tst_vellipticalarc.cpp \ + tst_vcubicbezierpath.cpp HEADERS += \ tst_vposter.h \ @@ -80,7 +81,8 @@ HEADERS += \ tst_vdetail.h \ tst_vabstractcurve.h \ tst_findpoint.h \ - tst_vellipticalarc.h + tst_vellipticalarc.h \ + tst_vcubicbezierpath.h # Set using ccache. Function enable_ccache() defined in common.pri. $$enable_ccache() diff --git a/src/test/ValentinaTest/qttestmainlambda.cpp b/src/test/ValentinaTest/qttestmainlambda.cpp index ec78c032f..a7d7c15e9 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -48,6 +48,7 @@ #include "tst_vdetail.h" #include "tst_findpoint.h" #include "tst_vabstractcurve.h" +#include "tst_vcubicbezierpath.h" 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_TSTranslation()); ASSERT_TEST(new TST_VAbstractCurve()); + ASSERT_TEST(new TST_VCubicBezierPath()); return status; } diff --git a/src/test/ValentinaTest/tst_vcubicbezierpath.cpp b/src/test/ValentinaTest/tst_vcubicbezierpath.cpp new file mode 100644 index 000000000..d4e5a6862 --- /dev/null +++ b/src/test/ValentinaTest/tst_vcubicbezierpath.cpp @@ -0,0 +1,122 @@ +/************************************************************************ + ** + ** @file tst_vcubicbezierpath.cpp + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#include "tst_vcubicbezierpath.h" +#include "../vgeometry/vcubicbezierpath.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +TST_VCubicBezierPath::TST_VCubicBezierPath(QObject *parent) : + QObject(parent) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VCubicBezierPath::TestCountSubSpl_data() const +{ + QTest::addColumn("points"); + QTest::addColumn("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("subSplIndex"); + QTest::addColumn("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("countSubSpl"); + QTest::addColumn("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); +} diff --git a/src/test/ValentinaTest/tst_vcubicbezierpath.h b/src/test/ValentinaTest/tst_vcubicbezierpath.h new file mode 100644 index 000000000..166afe157 --- /dev/null +++ b/src/test/ValentinaTest/tst_vcubicbezierpath.h @@ -0,0 +1,53 @@ +/************************************************************************ + ** + ** @file tst_vcubicbezierpath.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#ifndef TST_VCUBICBEZIERPATH_H +#define TST_VCUBICBEZIERPATH_H + +#include + +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 From 02cb84c4a173f1780088c832bae0efa067517df5 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 19 Mar 2016 16:29:26 +0200 Subject: [PATCH 12/13] Show list of points from the begin of the list. --HG-- branch : feature --- src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp index 03cb04b65..bfa063f76 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp @@ -88,6 +88,11 @@ void DialogCubicBezierPath::SetPath(const VCubicBezierPath &value) SCASSERT(visPath != nullptr); visPath->setPath(path); ui->listWidget->blockSignals(false); + + if (ui->listWidget->count() > 0) + { + ui->listWidget->setCurrentRow(0); + } } //--------------------------------------------------------------------------------------------------------------------- From eb5d05d690955607f7c20db3f9e9c2755d08e727 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 19 Mar 2016 16:35:14 +0200 Subject: [PATCH 13/13] Changelog updated. --HG-- branch : feature --- ChangeLog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 6b7e824f0..a0dd3dde6 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,5 @@ # Version 0.5.0 +- [#395] Create Curve tool which uses point as control handle. - pdftops updated to version 3.04. - [#306] Layout generator optimization. Divide into strips. - Fixed case with duplicate names of curves if they connect same points.