From 4c47c33c5ecfa87c24e29201daee3e59e64658f9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 10 Sep 2016 16:40:38 +0300 Subject: [PATCH 1/8] Flipping VPointF. --HG-- branch : feature --- src/libs/vgeometry/vgobject.cpp | 37 +++++++++ src/libs/vgeometry/vgobject.h | 3 + src/libs/vgeometry/vpointf.cpp | 9 +++ src/libs/vgeometry/vpointf.h | 1 + src/test/ValentinaTest/ValentinaTest.pro | 6 +- src/test/ValentinaTest/qttestmainlambda.cpp | 2 + src/test/ValentinaTest/tst_vpointf.cpp | 86 +++++++++++++++++++++ src/test/ValentinaTest/tst_vpointf.h | 47 +++++++++++ 8 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 src/test/ValentinaTest/tst_vpointf.cpp create mode 100644 src/test/ValentinaTest/tst_vpointf.h diff --git a/src/libs/vgeometry/vgobject.cpp b/src/libs/vgeometry/vgobject.cpp index e9e91f1cd..713239bf7 100644 --- a/src/libs/vgeometry/vgobject.cpp +++ b/src/libs/vgeometry/vgobject.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include "../vmisc/def.h" #include "../vmisc/vmath.h" @@ -575,3 +576,39 @@ int VGObject::GetLengthContour(const QVector &contour, const QVector &contour, const QVector &newPoints); static double accuracyPointOnLine; +protected: + static QTransform FlippingMatrix(const QLineF &axis); private: QSharedDataPointer d; diff --git a/src/libs/vgeometry/vpointf.cpp b/src/libs/vgeometry/vpointf.cpp index 67de60447..d6c3ab42c 100644 --- a/src/libs/vgeometry/vpointf.cpp +++ b/src/libs/vgeometry/vpointf.cpp @@ -31,6 +31,7 @@ #include #include #include +#include //--------------------------------------------------------------------------------------------------------------------- /** @@ -113,6 +114,14 @@ VPointF VPointF::Rotate(const QPointF &originPoint, qreal degrees, const QString return VPointF(p, name() + prefix, mx(), my()); } +//--------------------------------------------------------------------------------------------------------------------- +VPointF VPointF::Flip(const QLineF &axis, const QString &prefix) const +{ + const QTransform matrix = FlippingMatrix(axis); + const QPointF p = matrix.map(toQPointF()); + return VPointF(p, name() + prefix, mx(), my()); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief mx return offset name respect to x diff --git a/src/libs/vgeometry/vpointf.h b/src/libs/vgeometry/vpointf.h index 1b4777a7f..8bd7e1eca 100644 --- a/src/libs/vgeometry/vpointf.h +++ b/src/libs/vgeometry/vpointf.h @@ -65,6 +65,7 @@ public: VPointF &operator=(const VPointF &point); operator QPointF() const; VPointF Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; + VPointF Flip(const QLineF &axis, const QString &prefix = QString()) const; qreal mx() const; qreal my() const; void setMx(qreal mx); diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 39e50881e..3f5c649de 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -52,7 +52,8 @@ SOURCES += \ tst_vellipticalarc.cpp \ tst_vcubicbezierpath.cpp \ tst_vgobject.cpp \ - tst_vsplinepath.cpp + tst_vsplinepath.cpp \ + tst_vpointf.cpp win32-msvc*:SOURCES += stable.cpp @@ -75,7 +76,8 @@ HEADERS += \ tst_vellipticalarc.h \ tst_vcubicbezierpath.h \ tst_vgobject.h \ - tst_vsplinepath.h + tst_vsplinepath.h \ + tst_vpointf.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 36d818382..02cf31d74 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -46,6 +46,7 @@ #include "tst_vcubicbezierpath.h" #include "tst_vgobject.h" #include "tst_vsplinepath.h" +#include "tst_vpointf.h" #include "../vmisc/def.h" @@ -80,6 +81,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_VAbstractCurve()); ASSERT_TEST(new TST_VCubicBezierPath()); ASSERT_TEST(new TST_VGObject()); + ASSERT_TEST(new TST_VPointF()); return status; } diff --git a/src/test/ValentinaTest/tst_vpointf.cpp b/src/test/ValentinaTest/tst_vpointf.cpp new file mode 100644 index 000000000..6d3b983ba --- /dev/null +++ b/src/test/ValentinaTest/tst_vpointf.cpp @@ -0,0 +1,86 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 10 9, 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_vpointf.h" +#include "../vgeometry/vpointf.h" +#include "../vmisc/logging.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +TST_VPointF::TST_VPointF(QObject *parent) + : QObject(parent) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VPointF::TestFlip_data() +{ + QTest::addColumn("originPoint"); + QTest::addColumn("axis"); + QTest::addColumn("flipped"); + QTest::addColumn("prefix"); + + VPointF originPoint; + QLineF axis = QLineF(QPointF(5, 0), QPointF(5, 10)); + QPointF flipped = QPointF(10, 0); + + QTest::newRow("Vertical axis") << originPoint << axis << flipped << "a2"; + + axis = QLineF(QPointF(0, 5), QPointF(10, 5)); + flipped = QPointF(0, 10); + + QTest::newRow("Horizontal axis") << originPoint << axis << flipped << "a2"; + + QLineF l = QLineF(QPointF(), QPointF(10, 0)); + l.setAngle(315); + flipped = l.p2(); + l.setLength(l.length()/2.0); + + axis = QLineF(l.p2(), l.p1()); + axis.setAngle(axis.angle()+90); + + QTest::newRow("Diagonal axis") << originPoint << axis << flipped << "a2"; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VPointF::TestFlip() +{ + QFETCH(VPointF, originPoint); + QFETCH(QLineF, axis); + QFETCH(QPointF, flipped); + QFETCH(QString, prefix); + + const VPointF res = originPoint.Flip(axis, prefix); + + const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); + QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg)); + + QCOMPARE(flipped.toPoint(), res.toQPointF().toPoint()); +} + diff --git a/src/test/ValentinaTest/tst_vpointf.h b/src/test/ValentinaTest/tst_vpointf.h new file mode 100644 index 000000000..903acfa38 --- /dev/null +++ b/src/test/ValentinaTest/tst_vpointf.h @@ -0,0 +1,47 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 10 9, 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_VPOINTF_H +#define TST_VPOINTF_H + +#include +#include + +class TST_VPointF : public QObject +{ + Q_OBJECT +public: + explicit TST_VPointF(QObject *parent = nullptr); +private slots: + void TestFlip_data(); + void TestFlip(); +private: + Q_DISABLE_COPY(TST_VPointF) +}; + +#endif // TST_VPOINTF_H From 800181e8674a968b5d2c7f0cdaaac5758ef5e586 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 10 Sep 2016 18:18:11 +0300 Subject: [PATCH 2/8] Flipping VArc. --HG-- branch : feature --- src/libs/vgeometry/varc.cpp | 14 ++++++ src/libs/vgeometry/varc.h | 1 + src/libs/vgeometry/vpointf.cpp | 10 +++- src/libs/vgeometry/vpointf.h | 1 + src/test/ValentinaTest/tst_varc.cpp | 71 +++++++++++++++++++++++++++++ src/test/ValentinaTest/tst_varc.h | 2 + 6 files changed, 97 insertions(+), 2 deletions(-) diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index dd424fe66..8616f7079 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -131,6 +131,20 @@ VArc VArc::Rotate(const QPointF &originPoint, qreal degrees, const QString &pref return arc; } +//--------------------------------------------------------------------------------------------------------------------- +VArc VArc::Flip(const QLineF &axis, const QString &prefix) const +{ + const VPointF center = GetCenter().Flip(axis); + + const QPointF p1 = VPointF::FlipPF(axis, GetP1()); + const QPointF p2 = VPointF::FlipPF(axis, GetP2()); + + VArc arc(center, GetRadius(), QLineF(center, p1).angle(), QLineF(center, p2).angle()); + arc.setName(name() + prefix); + arc.SetFlipped(true); + return arc; +} + //--------------------------------------------------------------------------------------------------------------------- VArc::~VArc() {} diff --git a/src/libs/vgeometry/varc.h b/src/libs/vgeometry/varc.h index 67caef6e4..3a3c4d0c7 100644 --- a/src/libs/vgeometry/varc.h +++ b/src/libs/vgeometry/varc.h @@ -63,6 +63,7 @@ public: VArc(const VArc &arc); VArc& operator= (const VArc &arc); VArc Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; + VArc Flip(const QLineF &axis, const QString &prefix = QString()) const; virtual ~VArc() Q_DECL_OVERRIDE; QString GetFormulaRadius () const; diff --git a/src/libs/vgeometry/vpointf.cpp b/src/libs/vgeometry/vpointf.cpp index d6c3ab42c..fcb3f529d 100644 --- a/src/libs/vgeometry/vpointf.cpp +++ b/src/libs/vgeometry/vpointf.cpp @@ -117,8 +117,7 @@ VPointF VPointF::Rotate(const QPointF &originPoint, qreal degrees, const QString //--------------------------------------------------------------------------------------------------------------------- VPointF VPointF::Flip(const QLineF &axis, const QString &prefix) const { - const QTransform matrix = FlippingMatrix(axis); - const QPointF p = matrix.map(toQPointF()); + const QPointF p = FlipPF(axis, toQPointF()); return VPointF(p, name() + prefix, mx(), my()); } @@ -215,3 +214,10 @@ QPointF VPointF::RotatePF(const QPointF &originPoint, const QPointF &point, qrea axis.setAngle(axis.angle() + degrees); return axis.p2(); } + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VPointF::FlipPF(const QLineF &axis, const QPointF &point) +{ + const QTransform matrix = FlippingMatrix(axis); + return matrix.map(point); +} diff --git a/src/libs/vgeometry/vpointf.h b/src/libs/vgeometry/vpointf.h index 8bd7e1eca..3eb4a25ee 100644 --- a/src/libs/vgeometry/vpointf.h +++ b/src/libs/vgeometry/vpointf.h @@ -77,6 +77,7 @@ public: void setY(const qreal &value); static QPointF RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees); + static QPointF FlipPF(const QLineF &axis, const QPointF &point); private: QSharedDataPointer d; }; diff --git a/src/test/ValentinaTest/tst_varc.cpp b/src/test/ValentinaTest/tst_varc.cpp index ba2fbfb4c..207050c34 100644 --- a/src/test/ValentinaTest/tst_varc.cpp +++ b/src/test/ValentinaTest/tst_varc.cpp @@ -246,3 +246,74 @@ void TST_VArc::TestRotation() const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); QVERIFY2(rotatedArc.name().endsWith(prefix), qUtf8Printable(errorMsg)); } + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VArc::TestFlip_data() +{ + QTest::addColumn("center"); + QTest::addColumn("radius"); + QTest::addColumn("startAngle"); + QTest::addColumn("endAngle"); + QTest::addColumn("axis"); + QTest::addColumn("prefix"); + + const qreal radius = 5; + QPointF center(10, 5); + + QPointF p1(10, 0); + QPointF p2(5, 5); + + QLineF axis(QPointF(4, 6), QPointF(12, 6)); + + QTest::newRow("Vertical axis") << center << radius << QLineF(center, p1).angle() << QLineF(center, p2).angle() + << axis << "a2"; + + p1 = QPointF(15, 5); + p2 = QPointF(10, 0); + + axis = QLineF(QPointF(9, -1), QPointF(9, 6)); + + QTest::newRow("Horizontal axis") << center << radius << QLineF(center, p1).angle() << QLineF(center, p2).angle() + << axis << "a2"; + + QLineF l(center.x(), center.y(), center.x() + radius, center.y()); + + l.setAngle(45); + p2 = l.p2(); + + l.setAngle(225); + p1 = l.p2(); + + l.setAngle(45+90); + l.setLength(5); + + const QPointF p1Axis = l.p2(); + axis = QLineF(p1Axis.x(), p1Axis.y(), p1Axis.x() + radius, p1Axis.y()); + axis.setAngle(45); + + QTest::newRow("Diagonal axis") << center << radius << QLineF(center, p1).angle() << QLineF(center, p2).angle() + << axis << "a2"; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VArc::TestFlip() +{ + QFETCH(QPointF, center); + QFETCH(qreal, radius); + QFETCH(qreal, startAngle); + QFETCH(qreal, endAngle); + QFETCH(QLineF, axis); + QFETCH(QString, prefix); + + VArc originArc(center, radius, startAngle, endAngle); + const VArc res = originArc.Flip(axis, prefix); + + const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); + QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg)); + + QVERIFY2(res.IsFlipped(), qUtf8Printable("The arc is not flipped")); + + QCOMPARE(originArc.GetLength()*-1, res.GetLength()); + QCOMPARE(originArc.GetRadius(), res.GetRadius()); + QCOMPARE(originArc.AngleArc(), res.AngleArc()); +} diff --git a/src/test/ValentinaTest/tst_varc.h b/src/test/ValentinaTest/tst_varc.h index 770c2a7a7..74f62f2ed 100644 --- a/src/test/ValentinaTest/tst_varc.h +++ b/src/test/ValentinaTest/tst_varc.h @@ -44,6 +44,8 @@ private slots: void TestGetPoints(); void TestRotation_data(); void TestRotation(); + void TestFlip_data(); + void TestFlip(); }; #endif // TST_VARC_H From fe56607d7d1c03e950d89d208cc6c3bd07c28eec Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 10 Sep 2016 21:40:30 +0300 Subject: [PATCH 3/8] Flipping VSpline, VSplinePath, VEllipticalArc, VCubicBezierPath and VCubicBezier. --HG-- branch : feature --- src/libs/vgeometry/vcubicbezier.cpp | 12 ++++ src/libs/vgeometry/vcubicbezier.h | 1 + src/libs/vgeometry/vcubicbezierpath.cpp | 13 ++++ src/libs/vgeometry/vcubicbezierpath.h | 1 + src/libs/vgeometry/vellipticalarc.cpp | 14 +++++ src/libs/vgeometry/vellipticalarc.h | 2 + src/libs/vgeometry/vspline.cpp | 14 +++++ src/libs/vgeometry/vspline.h | 1 + src/libs/vgeometry/vsplinepath.cpp | 22 +++++++ src/libs/vgeometry/vsplinepath.h | 1 + src/test/ValentinaTest/tst_vellipticalarc.cpp | 41 +++++++++++++ src/test/ValentinaTest/tst_vellipticalarc.h | 2 + src/test/ValentinaTest/tst_vspline.cpp | 44 +++++++++++++ src/test/ValentinaTest/tst_vspline.h | 2 + src/test/ValentinaTest/tst_vsplinepath.cpp | 61 +++++++++++++++++++ src/test/ValentinaTest/tst_vsplinepath.h | 2 + 16 files changed, 233 insertions(+) diff --git a/src/libs/vgeometry/vcubicbezier.cpp b/src/libs/vgeometry/vcubicbezier.cpp index cfa3b071d..3b3d88786 100644 --- a/src/libs/vgeometry/vcubicbezier.cpp +++ b/src/libs/vgeometry/vcubicbezier.cpp @@ -78,6 +78,18 @@ VCubicBezier VCubicBezier::Rotate(const QPointF &originPoint, qreal degrees, con return curve; } +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezier VCubicBezier::Flip(const QLineF &axis, const QString &prefix) const +{ + const VPointF p1 = GetP1().Flip(axis); + const VPointF p2 = GetP2().Flip(axis); + const VPointF p3 = GetP3().Flip(axis); + const VPointF p4 = GetP4().Flip(axis); + VCubicBezier curve(p1, p2, p3, p4); + curve.setName(name() + prefix); + return curve; +} + //--------------------------------------------------------------------------------------------------------------------- VCubicBezier::~VCubicBezier() { diff --git a/src/libs/vgeometry/vcubicbezier.h b/src/libs/vgeometry/vcubicbezier.h index 8b6c1f338..283141884 100644 --- a/src/libs/vgeometry/vcubicbezier.h +++ b/src/libs/vgeometry/vcubicbezier.h @@ -53,6 +53,7 @@ public: Draw mode = Draw::Calculation); VCubicBezier &operator=(const VCubicBezier &curve); VCubicBezier Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; + VCubicBezier Flip(const QLineF &axis, const QString &prefix = QString()) const; virtual ~VCubicBezier(); virtual VPointF GetP1() const Q_DECL_OVERRIDE; diff --git a/src/libs/vgeometry/vcubicbezierpath.cpp b/src/libs/vgeometry/vcubicbezierpath.cpp index 496354a8a..1cc4c9c1b 100644 --- a/src/libs/vgeometry/vcubicbezierpath.cpp +++ b/src/libs/vgeometry/vcubicbezierpath.cpp @@ -91,6 +91,19 @@ VCubicBezierPath VCubicBezierPath::Rotate(const QPointF &originPoint, qreal degr return curve; } +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezierPath VCubicBezierPath::Flip(const QLineF &axis, const QString &prefix) const +{ + const QVector points = GetCubicPath(); + VCubicBezierPath curve; + for(int i=0; i < points.size(); ++i) + { + curve.append(points.at(i).Flip(axis)); + } + curve.setName(name() + prefix); + return curve; +} + //--------------------------------------------------------------------------------------------------------------------- VCubicBezierPath::~VCubicBezierPath() { diff --git a/src/libs/vgeometry/vcubicbezierpath.h b/src/libs/vgeometry/vcubicbezierpath.h index b232a7567..c0c38cd8e 100644 --- a/src/libs/vgeometry/vcubicbezierpath.h +++ b/src/libs/vgeometry/vcubicbezierpath.h @@ -56,6 +56,7 @@ public: VCubicBezierPath(const QVector &points, quint32 idObject = 0, Draw mode = Draw::Calculation); VCubicBezierPath &operator=(const VCubicBezierPath &curve); VCubicBezierPath Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; + VCubicBezierPath Flip(const QLineF &axis, const QString &prefix = QString()) const; virtual ~VCubicBezierPath(); VPointF &operator[](int indx); diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index f501a3392..81798cc81 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -134,6 +134,20 @@ VEllipticalArc VEllipticalArc::Rotate(const QPointF &originPoint, qreal degrees, return elArc; } +//--------------------------------------------------------------------------------------------------------------------- +VEllipticalArc VEllipticalArc::Flip(const QLineF &axis, const QString &prefix) const +{ + const VPointF center = GetCenter().Flip(axis); + const QPointF p1 = VPointF::FlipPF(axis, GetP1()); + const QPointF p2 = VPointF::FlipPF(axis, GetP2()); + const qreal f1 = QLineF(center, p1).angle() - GetRotationAngle(); + const qreal f2 = QLineF(center, p2).angle() - GetRotationAngle(); + VEllipticalArc elArc(center, GetRadius1(), GetRadius2(), f1, f2, GetRotationAngle()); + elArc.setName(name() + prefix); + elArc.SetFlipped(true); + return elArc; +} + //--------------------------------------------------------------------------------------------------------------------- VEllipticalArc::~VEllipticalArc() {} diff --git a/src/libs/vgeometry/vellipticalarc.h b/src/libs/vgeometry/vellipticalarc.h index 79393a70f..b77372efd 100644 --- a/src/libs/vgeometry/vellipticalarc.h +++ b/src/libs/vgeometry/vellipticalarc.h @@ -63,6 +63,7 @@ public: VEllipticalArc& operator= (const VEllipticalArc &arc); VEllipticalArc Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; + VEllipticalArc Flip(const QLineF &axis, const QString &prefix = QString()) const; virtual ~VEllipticalArc() Q_DECL_OVERRIDE; @@ -99,6 +100,7 @@ private: static int GetQuadransRad(qreal &rad); }; +Q_DECLARE_METATYPE(VEllipticalArc) Q_DECLARE_TYPEINFO(VEllipticalArc, Q_MOVABLE_TYPE); #endif // VELLIPTICALARC_H diff --git a/src/libs/vgeometry/vspline.cpp b/src/libs/vgeometry/vspline.cpp index 2234caea0..b9fceff03 100644 --- a/src/libs/vgeometry/vspline.cpp +++ b/src/libs/vgeometry/vspline.cpp @@ -126,6 +126,20 @@ VSpline VSpline::Rotate(const QPointF &originPoint, qreal degrees, const QString return spl; } +//--------------------------------------------------------------------------------------------------------------------- +VSpline VSpline::Flip(const QLineF &axis, const QString &prefix) const +{ + const VPointF p1 = GetP1().Flip(axis); + const VPointF p4 = GetP4().Flip(axis); + + const QPointF p2 = VPointF::FlipPF(axis, GetP2()); + const QPointF p3 = VPointF::FlipPF(axis, GetP3()); + + VSpline spl(p1, p2, p3, p4); + spl.setName(name() + prefix); + return spl; +} + //--------------------------------------------------------------------------------------------------------------------- VSpline::~VSpline() {} diff --git a/src/libs/vgeometry/vspline.h b/src/libs/vgeometry/vspline.h index e648a3c80..78705e496 100644 --- a/src/libs/vgeometry/vspline.h +++ b/src/libs/vgeometry/vspline.h @@ -63,6 +63,7 @@ public: const QString &angle2Formula, qreal c1Length, const QString &c1LengthFormula, qreal c2Length, const QString &c2LengthFormula, quint32 idObject = 0, Draw mode = Draw::Calculation); VSpline Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; + VSpline Flip(const QLineF &axis, const QString &prefix = QString()) const; virtual ~VSpline(); VSpline &operator=(const VSpline &spl); diff --git a/src/libs/vgeometry/vsplinepath.cpp b/src/libs/vgeometry/vsplinepath.cpp index 8410c8364..bbf0be400 100644 --- a/src/libs/vgeometry/vsplinepath.cpp +++ b/src/libs/vgeometry/vsplinepath.cpp @@ -122,6 +122,28 @@ VSplinePath VSplinePath::Rotate(const QPointF &originPoint, qreal degrees, const return splPath; } +//--------------------------------------------------------------------------------------------------------------------- +VSplinePath VSplinePath::Flip(const QLineF &axis, const QString &prefix) const +{ + QVector newPoints(CountPoints()); + for (qint32 i = 1; i <= CountSubSpl(); ++i) + { + const VSpline spl = GetSpline(i).Flip(axis); + + newPoints[i-1].SetP(spl.GetP1()); + newPoints[i-1].SetAngle2(spl.GetStartAngle(), spl.GetStartAngleFormula()); + newPoints[i-1].SetLength2(spl.GetC1Length(), spl.GetC1LengthFormula()); + + newPoints[i].SetP(spl.GetP4()); + newPoints[i].SetAngle1(spl.GetEndAngle(), spl.GetEndAngleFormula()); + newPoints[i].SetLength1(spl.GetC2Length(), spl.GetC2LengthFormula()); + } + + VSplinePath splPath(newPoints); + splPath.setName(name() + prefix); + return splPath; +} + //--------------------------------------------------------------------------------------------------------------------- VSplinePath::~VSplinePath() {} diff --git a/src/libs/vgeometry/vsplinepath.h b/src/libs/vgeometry/vsplinepath.h index e0dea14d9..424e1de44 100644 --- a/src/libs/vgeometry/vsplinepath.h +++ b/src/libs/vgeometry/vsplinepath.h @@ -61,6 +61,7 @@ public: VSplinePath(const QVector &points, quint32 idObject = 0, Draw mode = Draw::Calculation); VSplinePath(const VSplinePath& splPath); VSplinePath Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; + VSplinePath Flip(const QLineF &axis, const QString &prefix = QString()) const; virtual ~VSplinePath() Q_DECL_OVERRIDE; VSplinePath &operator=(const VSplinePath &path); diff --git a/src/test/ValentinaTest/tst_vellipticalarc.cpp b/src/test/ValentinaTest/tst_vellipticalarc.cpp index 023884d47..5abd8b583 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.cpp +++ b/src/test/ValentinaTest/tst_vellipticalarc.cpp @@ -31,6 +31,7 @@ #include "../vlayout/vabstractdetail.h" #include "../vmisc/logging.h" +#include #include //--------------------------------------------------------------------------------------------------------------------- @@ -455,3 +456,43 @@ void TST_VEllipticalArc::TestRotation() const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); QVERIFY2(rotatedArc.name().endsWith(prefix), qUtf8Printable(errorMsg)); } + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VEllipticalArc::TestFlip_data() +{ + QTest::addColumn("elArc"); + QTest::addColumn("axis"); + QTest::addColumn("prefix"); + + const VEllipticalArc elArc(QPointF(), 10., 20.0, 1., 91., 0.); + + QLineF axis(QPointF(600, 30), QPointF(600, 1800)); + + QTest::newRow("Vertical axis") << elArc << axis << "a2"; + + axis = QLineF(QPointF(600, 30), QPointF(1200, 30)); + + QTest::newRow("Horizontal axis") << elArc << axis << "a2"; + + axis = QLineF(QPointF(600, 30), QPointF(600, 1800)); + axis.setAngle(45); + + QTest::newRow("Diagonal axis") << elArc << axis << "a2"; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VEllipticalArc::TestFlip() +{ + QFETCH(VEllipticalArc, elArc); + QFETCH(QLineF, axis); + QFETCH(QString, prefix); + + const VEllipticalArc res = elArc.Flip(axis, prefix); + + const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); + QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg)); + + QCOMPARE(qRound(elArc.GetLength()*-1), qRound(res.GetLength())); + QCOMPARE(elArc.GetRadius1(), res.GetRadius1()); + QCOMPARE(elArc.GetRadius2(), res.GetRadius2()); +} diff --git a/src/test/ValentinaTest/tst_vellipticalarc.h b/src/test/ValentinaTest/tst_vellipticalarc.h index 17e8fc2b1..61f1f678c 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.h +++ b/src/test/ValentinaTest/tst_vellipticalarc.h @@ -51,6 +51,8 @@ private slots: void TestGetPoints4(); void TestRotation_data(); void TestRotation(); + void TestFlip_data(); + void TestFlip(); private: Q_DISABLE_COPY(TST_VEllipticalArc) diff --git a/src/test/ValentinaTest/tst_vspline.cpp b/src/test/ValentinaTest/tst_vspline.cpp index b5c0e206e..364274b87 100644 --- a/src/test/ValentinaTest/tst_vspline.cpp +++ b/src/test/ValentinaTest/tst_vspline.cpp @@ -28,6 +28,7 @@ #include "tst_vspline.h" #include "../vgeometry/vspline.h" +#include "../vmisc/logging.h" #include @@ -388,6 +389,49 @@ void TST_VSpline::TestLengthByPoint() QVERIFY(qAbs(resLength - length) < ToPixel(0.5, Unit::Mm)); } +//--------------------------------------------------------------------------------------------------------------------- +void TST_VSpline::TestFlip_data() +{ + QTest::addColumn("spl"); + QTest::addColumn("axis"); + QTest::addColumn("prefix"); + + VPointF p1(1168.8582803149607, 39.999874015748034, "p1", 5.0000125984251973, 9.9999874015748045); + VPointF p4(681.33729132409951, 1815.7969526662778, "p4", 5.0000125984251973, 9.9999874015748045); + + VSpline spl(p1, p4, 229.381, 41.6325, 0.96294100000000005, 1.00054, 1); + + QLineF axis(QPointF(600, 30), QPointF(600, 1800)); + + QTest::newRow("Vertical axis") << spl << axis << "a2"; + + axis = QLineF(QPointF(600, 30), QPointF(1200, 30)); + + QTest::newRow("Horizontal axis") << spl << axis << "a2"; + + axis = QLineF(QPointF(600, 30), QPointF(600, 1800)); + axis.setAngle(45); + + QTest::newRow("Diagonal axis") << spl << axis << "a2"; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VSpline::TestFlip() +{ + QFETCH(VSpline, spl); + QFETCH(QLineF, axis); + QFETCH(QString, prefix); + + const VSpline res = spl.Flip(axis, prefix); + + const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); + QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg)); + + QCOMPARE(spl.GetLength(), res.GetLength()); + QCOMPARE(spl.GetC1Length(), res.GetC1Length()); + QCOMPARE(spl.GetC2Length(), res.GetC2Length()); +} + //--------------------------------------------------------------------------------------------------------------------- void TST_VSpline::CompareSplines(const VSpline &spl1, const VSpline &spl2) const { diff --git a/src/test/ValentinaTest/tst_vspline.h b/src/test/ValentinaTest/tst_vspline.h index 7e910baf9..776274222 100644 --- a/src/test/ValentinaTest/tst_vspline.h +++ b/src/test/ValentinaTest/tst_vspline.h @@ -51,6 +51,8 @@ private slots: void TestParametrT(); void TestLengthByPoint_data(); void TestLengthByPoint(); + void TestFlip_data(); + void TestFlip(); private: Q_DISABLE_COPY(TST_VSpline) diff --git a/src/test/ValentinaTest/tst_vsplinepath.cpp b/src/test/ValentinaTest/tst_vsplinepath.cpp index 14af3e847..586bd36e9 100644 --- a/src/test/ValentinaTest/tst_vsplinepath.cpp +++ b/src/test/ValentinaTest/tst_vsplinepath.cpp @@ -135,3 +135,64 @@ void TST_VSplinePath::TestRotation() } } +//--------------------------------------------------------------------------------------------------------------------- +void TST_VSplinePath::TestFlip_data() +{ + QTest::addColumn>("originPoints"); + QTest::addColumn("axis"); + QTest::addColumn("prefix"); + + QVector originPoints; + + { + VPointF pSpline(30, 39.999874015748034, "X", 5.0000125984251973, 9.9999874015748045); + VSplinePoint p(pSpline, 89.208600000000004, "89.2086", 269.20859999999999, "269.209", 0, "0", + 153.33618897637794, "4.05702"); + originPoints.append(p); + } + + { + VPointF pSpline(198.77104389529981, 249.18158602595835, "X", 5.0000125984251973, 9.9999874015748045); + VSplinePoint p(pSpline, 146.43199999999999, "146.432", 326.43200000000002, "326.432", + 36.387590551181106, "0.962755", 60.978897637795278, "1.6134"); + originPoints.append(p); + } + + { + VPointF pSpline(820.42771653543309, 417.95262992125987, "X", 5.0000125984251973, 9.9999874015748045); + VSplinePoint p(pSpline, 173.39500000000001, "173.395", 353.39499999999998, "353.395", + 381.23716535433073, "10.0869", 0, "0"); + originPoints.append(p); + } + + QLineF axis(QPointF(0, 0), QPointF(0, 10)); + + QTest::newRow("Vertical axis") << originPoints << axis << "a2"; + + axis = QLineF(QPointF(0, 0), QPointF(10, 0)); + + QTest::newRow("Horizontal axis") << originPoints << axis << "a2"; + + axis = QLineF(QPointF(0, 0), QPointF(0, 10)); + axis.setAngle(45); + + QTest::newRow("Diagonal axis") << originPoints << axis << "a2"; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VSplinePath::TestFlip() +{ + QFETCH(QVector, originPoints); + QFETCH(QLineF, axis); + QFETCH(QString, prefix); + + const VSplinePath splPath(originPoints); + const VSplinePath res = splPath.Flip(axis, prefix); + + const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); + QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg)); + + QCOMPARE(splPath.GetLength(), res.GetLength()); + QCOMPARE(splPath.CountPoints(), res.CountPoints()); +} + diff --git a/src/test/ValentinaTest/tst_vsplinepath.h b/src/test/ValentinaTest/tst_vsplinepath.h index 0baec27a2..60362ba95 100644 --- a/src/test/ValentinaTest/tst_vsplinepath.h +++ b/src/test/ValentinaTest/tst_vsplinepath.h @@ -39,6 +39,8 @@ public: private slots: void TestRotation_data(); void TestRotation(); + void TestFlip_data(); + void TestFlip(); private: Q_DISABLE_COPY(TST_VSplinePath) }; From 9bb88afaa591e663267f1e70d001dfae1ead6804 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 13 Sep 2016 11:27:44 +0300 Subject: [PATCH 4/8] New tool Flipping by line. --HG-- branch : feature --- .../core/vtooloptionspropertybrowser.cpp | 53 +- .../core/vtooloptionspropertybrowser.h | 3 + src/app/valentina/dialogs/dialoghistory.cpp | 3 +- src/app/valentina/mainwindow.cpp | 24 +- src/app/valentina/mainwindow.h | 1 + src/app/valentina/mainwindow.ui | 44 +- src/app/valentina/share/resources/cursor.qrc | 2 + .../resources/cursor/flipping_line_cursor.png | Bin 0 -> 618 bytes .../cursor/flipping_line_cursor@2x.png | Bin 0 -> 1279 bytes .../valentina/share/resources/toolicon.qrc | 2 + .../toolicon/32x32/flipping_line.png | Bin 0 -> 1156 bytes .../toolicon/32x32/flipping_line@2x.png | Bin 0 -> 2553 bytes .../resources/toolicon/svg/flipping_line.svg | 82 +++ src/app/valentina/xml/vpattern.cpp | 43 +- src/app/valentina/xml/vpattern.h | 1 + src/libs/ifc/schema.qrc | 1 + src/libs/ifc/schema/pattern/v0.3.5.xsd | 574 ++++++++++++++++ src/libs/ifc/xml/vabstractpattern.cpp | 8 +- src/libs/ifc/xml/vpatternconverter.cpp | 17 +- src/libs/ifc/xml/vpatternconverter.h | 5 +- src/libs/vmisc/def.h | 5 +- src/libs/vtools/dialogs/dialogs.pri | 9 +- src/libs/vtools/dialogs/tooldialogs.h | 1 + .../dialogs/tools/dialogflippingbyline.cpp | 349 ++++++++++ .../dialogs/tools/dialogflippingbyline.h | 102 +++ .../dialogs/tools/dialogflippingbyline.ui | 98 +++ .../vtools/dialogs/tools/dialogrotation.cpp | 2 +- src/libs/vtools/tools/drawTools/drawtools.h | 1 + .../flipping/vtoolflippingbyline.cpp | 438 ++++++++++++ .../operation/flipping/vtoolflippingbyline.h | 104 +++ .../operation/vabstractoperation.cpp | 610 +++++++++++++++++ .../drawTools/operation/vabstractoperation.h | 203 ++++++ .../drawTools/operation/vtoolrotation.cpp | 622 +----------------- .../tools/drawTools/operation/vtoolrotation.h | 101 +-- src/libs/vtools/tools/tools.pri | 8 +- .../line/operation/visoperation.cpp | 99 +++ .../line/operation/visoperation.h | 62 ++ .../line/operation/vistoolflippingbyline.cpp | 185 ++++++ .../line/operation/vistoolflippingbyline.h | 60 ++ .../line/{ => operation}/vistoolrotation.cpp | 64 +- .../line/{ => operation}/vistoolrotation.h | 15 +- .../vtools/visualization/visualization.pri | 8 +- 42 files changed, 3190 insertions(+), 819 deletions(-) create mode 100644 src/app/valentina/share/resources/cursor/flipping_line_cursor.png create mode 100644 src/app/valentina/share/resources/cursor/flipping_line_cursor@2x.png create mode 100644 src/app/valentina/share/resources/toolicon/32x32/flipping_line.png create mode 100644 src/app/valentina/share/resources/toolicon/32x32/flipping_line@2x.png create mode 100644 src/app/valentina/share/resources/toolicon/svg/flipping_line.svg create mode 100644 src/libs/ifc/schema/pattern/v0.3.5.xsd create mode 100644 src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp create mode 100644 src/libs/vtools/dialogs/tools/dialogflippingbyline.h create mode 100644 src/libs/vtools/dialogs/tools/dialogflippingbyline.ui create mode 100644 src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp create mode 100644 src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h create mode 100644 src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp create mode 100644 src/libs/vtools/tools/drawTools/operation/vabstractoperation.h create mode 100644 src/libs/vtools/visualization/line/operation/visoperation.cpp create mode 100644 src/libs/vtools/visualization/line/operation/visoperation.h create mode 100644 src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp create mode 100644 src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h rename src/libs/vtools/visualization/line/{ => operation}/vistoolrotation.cpp (80%) rename src/libs/vtools/visualization/line/{ => operation}/vistoolrotation.h (82%) diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index ff55d7efb..8c2bca58f 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -75,7 +75,7 @@ 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) == 45, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was used in switch."); switch (item->type()) { @@ -185,6 +185,9 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) case VToolRotation::Type: ShowOptionsToolRotation(item); break; + case VToolFlippingByLine::Type: + ShowOptionsToolFlippingByLine(item); + break; default: break; } @@ -199,7 +202,7 @@ void VToolOptionsPropertyBrowser::UpdateOptions() } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -299,6 +302,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions() case VToolRotation::Type: UpdateOptionsToolRotation(); break; + case VToolFlippingByLine::Type: + UpdateOptionsToolFlippingByLine(); + break; default: break; } @@ -334,7 +340,7 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -428,6 +434,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) case VToolRotation::Type: ChangeDataToolRotation(prop); break; + case VToolFlippingByLine::Type: + ChangeDataToolFlippingByLine(prop); + break; default: break; } @@ -1601,6 +1610,27 @@ void VToolOptionsPropertyBrowser::ChangeDataToolRotation(VProperty *property) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolFlippingByLine(VProperty *property) +{ + SCASSERT(property != nullptr) + + QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolFlippingByLine *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 38: // AttrSuffix + SetOperationSuffix(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<GetFormulaAngle(), AttrAngle); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolFlippingByLine(QGraphicsItem *item) +{ + VToolFlippingByLine *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Tool flipping by line")); + + AddPropertyOperationSuffix(i, tr("Suffix")); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolSinglePoint() { @@ -2451,6 +2491,13 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolRotation() idToProperty[AttrAngle]->setValue(valueAngle); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolFlippingByLine() +{ + VToolFlippingByLine *i = qgraphicsitem_cast(currentItem); + idToProperty[AttrSuffix]->setValue(i->Suffix()); +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VToolOptionsPropertyBrowser::PropertiesList() const { diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.h b/src/app/valentina/core/vtooloptionspropertybrowser.h index 2c69b5513..5c521ab47 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.h +++ b/src/app/valentina/core/vtooloptionspropertybrowser.h @@ -152,6 +152,7 @@ private: void ChangeDataToolLineIntersectAxis(VPE::VProperty *property); void ChangeDataToolCurveIntersectAxis(VPE::VProperty *property); void ChangeDataToolRotation(VPE::VProperty *property); + void ChangeDataToolFlippingByLine(VPE::VProperty *property); void ShowOptionsToolSinglePoint(QGraphicsItem *item); void ShowOptionsToolEndLine(QGraphicsItem *item); @@ -183,6 +184,7 @@ private: void ShowOptionsToolLineIntersectAxis(QGraphicsItem *item); void ShowOptionsToolCurveIntersectAxis(QGraphicsItem *item); void ShowOptionsToolRotation(QGraphicsItem *item); + void ShowOptionsToolFlippingByLine(QGraphicsItem *item); void UpdateOptionsToolSinglePoint(); void UpdateOptionsToolEndLine(); @@ -214,6 +216,7 @@ private: void UpdateOptionsToolLineIntersectAxis(); void UpdateOptionsToolCurveIntersectAxis(); void UpdateOptionsToolRotation(); + void UpdateOptionsToolFlippingByLine(); }; #endif // VTOOLOPTIONSPROPERTYBROWSER_H diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index beab2bedb..2d5ac5ab9 100644 --- a/src/app/valentina/dialogs/dialoghistory.cpp +++ b/src/app/valentina/dialogs/dialoghistory.cpp @@ -207,7 +207,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") 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) == 45, "Not all tools was used in history."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was used in history."); const QDomElement domElem = doc->elementById(tool.getId()); if (domElem.isElement() == false) @@ -387,6 +387,7 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::NodeSplinePath: case Tool::Group: case Tool::Rotation: + case Tool::FlippingByLine: return QString(); } } diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index b6d2c79ed..1618916c8 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1033,6 +1033,17 @@ void MainWindow::ToolRotation(bool checked) &MainWindow::ApplyDialog); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolFlippingByLine(bool checked) +{ + ToolSelectOperationObjects(); + SetToolButtonWithApply(checked, Tool::FlippingByLine, + ":/cursor/flipping_line_cursor.png", + tr("Select one or more objects, Enter - confirm selection"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ClosedDialogGroup(int result) { @@ -1702,6 +1713,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonTrueDarts, &QToolButton::clicked, this, &MainWindow::ToolTrueDarts); connect(ui->toolButtonGroup, &QToolButton::clicked, this, &MainWindow::ToolGroup); connect(ui->toolButtonRotation, &QToolButton::clicked, this, &MainWindow::ToolRotation); + connect(ui->toolButtonFlippingByLine, &QToolButton::clicked, this, &MainWindow::ToolFlippingByLine); connect(ui->toolButtonMidpoint, &QToolButton::clicked, this, &MainWindow::ToolMidpoint); connect(ui->toolButtonLayoutExportAs, &QToolButton::clicked, this, &MainWindow::ExportLayoutAs); } @@ -1731,7 +1743,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") 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) == 45, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was handled."); qCDebug(vMainWindow, "Canceling tool."); delete dialogTool; @@ -1871,6 +1883,9 @@ void MainWindow::CancelTool() case Tool::Rotation: ui->toolButtonRotation->setChecked(false); break; + case Tool::FlippingByLine: + ui->toolButtonFlippingByLine->setChecked(false); + break; } // Crash: using CRTL+Z while using line tool. @@ -2952,6 +2967,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonTrueDarts->setEnabled(drawTools); ui->toolButtonGroup->setEnabled(drawTools); ui->toolButtonRotation->setEnabled(drawTools); + ui->toolButtonFlippingByLine->setEnabled(drawTools); ui->toolButtonMidpoint->setEnabled(drawTools); ui->actionLast_tool->setEnabled(drawTools); @@ -3234,7 +3250,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") 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) == 45, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was handled."); if (currentTool == lastUsedTool) { @@ -3400,6 +3416,10 @@ void MainWindow::LastUsedTool() ui->toolButtonRotation->setChecked(true); ToolRotation(true); break; + case Tool::FlippingByLine: + ui->toolButtonFlippingByLine->setChecked(true); + ToolFlippingByLine(true); + break; } } diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 375ffcda4..1bb634d1e 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -139,6 +139,7 @@ private slots: void ToolUnionDetails(bool checked); void ToolGroup(bool checked); void ToolRotation(bool checked); + void ToolFlippingByLine(bool checked); void ToolCutArc(bool checked); void ToolLineIntersectAxis(bool checked); void ToolCurveIntersectAxis(bool checked); diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index ae7bebe5e..295cb3186 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -48,14 +48,14 @@ Tools - 6 + 4 0 0 - 100 + 117 358 @@ -427,7 +427,7 @@ 0 0 - 100 + 130 110 @@ -536,7 +536,7 @@ 0 0 - 100 + 130 248 @@ -798,7 +798,7 @@ 0 0 - 100 + 130 248 @@ -1063,8 +1063,8 @@ 0 0 - 100 - 104 + 130 + 356 @@ -1156,6 +1156,32 @@ + + + + false + + + Flipping objects by line + + + ... + + + + :/toolicon/32x32/flipping_line.png:/toolicon/32x32/flipping_line.png + + + + 32 + 32 + + + + true + + + @@ -1163,7 +1189,7 @@ 0 0 - 100 + 130 104 @@ -2402,8 +2428,8 @@ - + diff --git a/src/app/valentina/share/resources/cursor.qrc b/src/app/valentina/share/resources/cursor.qrc index 95f4ef5ae..cb10b4aef 100644 --- a/src/app/valentina/share/resources/cursor.qrc +++ b/src/app/valentina/share/resources/cursor.qrc @@ -70,5 +70,7 @@ cursor/rotation_cursor@2x.png cursor/midpoint_cursor.png cursor/midpoint_cursor@2x.png + cursor/flipping_line_cursor@2x.png + cursor/flipping_line_cursor.png diff --git a/src/app/valentina/share/resources/cursor/flipping_line_cursor.png b/src/app/valentina/share/resources/cursor/flipping_line_cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..c1e80d2f004eee02e864bd73b85d4f2e33f63038 GIT binary patch literal 618 zcmV-w0+s!VP)?fj9MJ(W0KLLG1)C2m0_}KvHIieY$r-=0cJwufL0_X|i zUx2P7S^;zwQECy;HAFjrt{~b4B#v0^0FWr6Q$S*fjQ|ostZWd_5h7>+Y--Xb5--z( zE%x~t`;bOhtr0f4{)S?Gr%{v6$|#86>SK!lcz`$JKdb&I;{fu=;931cMQew18J{rR zM&VlSSUbA4Gg(n3GZ-9yiZIbW4MY(*i)8&F(5n~)-|Yof+al0WP-&r zxPcjrugcF42s0>z4GoL9g|p&`mqd2sCLSWUEH{@Djxlhy}*+SYk#dwLPcvC!QE={qlC3>=qz}YhUfXzEkQrg>#HVk^L!( z0V@GRA*G<%Vv$5HZ#TH(hwLuG0+mvHJE%?W>N$Az3uihFuz*v%BLDyZ07*qoM6N<$ Eg2HM4bpQYW literal 0 HcmV?d00001 diff --git a/src/app/valentina/share/resources/cursor/flipping_line_cursor@2x.png b/src/app/valentina/share/resources/cursor/flipping_line_cursor@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..7468a233ccdded6d856bfc407abc043395747a05 GIT binary patch literal 1279 zcmVSKnNl; zBfANilwnkosStsfLG|K;hL&JumNl3v@BNX?YuG&dlmzok5+> zIM*}hGXCJtUVFn@`~Uy$|9`E0*4doZS)J8covsh@8O|-XBgIn4*-rfwLO8|tU}SOK z>3g*}9YVj$gl4A$=y#cr4?w?ykd+@mzk$%CeE|IeLPr299zvsz0aP@E6FLW=Vj*+| zKt)1m&@})R2jRG`1E?qn-33rF5RU0SfQo={RL=mEJ%ru>P}UHR=p6uM3*oTd15lO_ zdK*C5LHJki11Kv9|0oQAvVl-Y0A&H;kir5ec?bs;9zaP$=qmsv3*m2l2cRS&{H1RJ zlpKU&04OO4e<}`ul7aAt;sGcL2*n0abO^t9!oiA$aG)E`RuqI%0#FnPzZD>ep4z8{ z3O1eRS}4@bx~Z(VQ#}$lqAF+UQ`)WP={)Tes&nmt6{r=r{`Ter&|Pi9-MN7ap-1r? zz7wG|*AjGJ=T$K|`xuezS1%S6J3)NIs?Pc+G6?dg1cf?c=-JDl|U zmY$YC3m(VPF7)Y%PKDkX4HX~GMYs(E#8PSzxBvI1df?1)Ox1V6cU4328YW<}_^OOU#GN#Pl-W4jA!wVH~}_bPEa?RWCiM}c`~spZ~5lS zfa!(tw^xwOaqmhs_>W?`~orfwc=~;)L_h& zB#x}BZ6ZH)p4Ong&a5-KP17Cn8 z;%n}tVBC46Hj#Wz&0UEv4|Qh1asm)A94}%Kmg6!^4(dkH@-{xA@!rJ8hdVoHIhDY- zSS8l}T=A8BN{~5+unM~gvpcH!wkjt8`!GuUMK~0bf=rrZGxl&|TH>oNzowTHfSH(> zYronkGmvBhcF}krLmGn2Aes`I6NV>bbJmtoolicon/32x32/rotation@2x.png toolicon/32x32/midpoint.png toolicon/32x32/midpoint@2x.png + toolicon/32x32/flipping_line@2x.png + toolicon/32x32/flipping_line.png diff --git a/src/app/valentina/share/resources/toolicon/32x32/flipping_line.png b/src/app/valentina/share/resources/toolicon/32x32/flipping_line.png new file mode 100644 index 0000000000000000000000000000000000000000..6f1224ab9522ab7d1ab53d5825bf704108d69719 GIT binary patch literal 1156 zcmV-~1bh35P)_ub|RA^98NWCb8D6)$rLfI7&jk1i0lAUhLU+@3Z|%KEGpCRsRI;s6}m3_%wb_znjrgrM?x%tNJH!w5nf1W0x7XU<+e+Y4=O+77bl^wvH3$lILAEL=E*&fZ=U{J&v#$)o z17f=OVQhpi7#b8l39=Am2Wq>E*3Whxw&PMU{q;D4<#;LC7UD=SdlXGu$<0q=^8;Ok z6R;z}cjJZxe>lN+mjwlLM^f5Km{0hv9AF>BMTEEo$Ag(uDQ!=_AJecT=U{8s zfc?q9RB^_W@I@7TO@e=3wguUA^1G7n7MgGC4&EOD)5O|-L7a`76a0BRT4ievW?eyU zJI0gS#N^v^_P6yEythI$9e*aD55;ps4(qzu1cli_@o*|K8^b9k7)%?He17Roz~%TW zJ>QZ*d91Ip)y1IM+#qX6f!Bs8vfI{I0hxG;3D}I91mBQsZzr3eczuvH#h`_!P6h6d zfLUTi3wSGmYQ*g`U{eL2Ee^7l1Ygk`ye|T-5-VE3n+a5lca!anD)_BI)*57`AbYSc z@ZJQ>5i452>tf35@LsaLCcWDryF18E1X)K=ysxkDo&-FLW9j#+2~>yolkJr%__73V z4+?ko2i}u_Qu^MQWrF@$YhoSVs2U06d)v~{*Na!pnJc1p)8-F%05bn6U2X~(|{ WR@}oDX!N510000h($8FWQhbW?9;ba!ELWdL_~cP?peYja~^ zaAhuUa%Y?FJQ@H133f?DK~#90-J5%GRmC00KYK|C(S#Q33#u&^wN@uOauXh-Qfdr{ z1uImvGQg-++tON#&e+E|?TmfN45NLZl~&r6)?%?BuTl$9P%9O4gYpQiEeuwyC;=Ks zfFw7$zy9$%*X-GIZq7||NiKe8GL!Q=-?L}Gzq|X}-QVspC=74`P)a8XffDO_05BLo zhB((B0%F#6iC0b@bV?A0v|0e%O3gDhZxVqhI`Wi}6-L>L2X z1}cDAzzEa3D>bihAvX_7?{h039Ls4g%BC4!A83Dx2%S9|7Nu;Isjk6%fQ8 zU^m)aS}l7skhHE311ax+0UE7)?Ld=t-RhN>hFf-%_e>g%UYU6BIBeZZdUY8AJP&-# zssDq(kAa4OGCvA|Z$q#J{2=1Nd_WoS9>HJrUhn=DA@{=m_Jy^8e8;6g4RD5K6JQST zxOeT29GNgA7R|{kQ~(?Ci%$Vxrc*q?-Ym;|>tu4kXmq%?=K(3;OTaH3?x}Rfr>?L9 zPL3EbhR(p4{_6m458;jt;fDR~0#1Yccffcw>f3cp0$<3IyPu%=r-5PVhw|A0R}(J& zrYyKAbW|AV-MbsrTIN2OuMW5dI7)Exa$^?UbYKiXm_9%lIZ+sWaoU!T4w!&Wmh5`9 z0Fy(wQ@ne2Y`8P5P@!yyP`*hh7oj{Q#HZ)uJm7k?j}EkKEx_l2wGrGDa2K%1EmXMl zOekCjT;`b!m>K!zfE$265)?lbcs7FD4$KCYxP=Or4}$?Uz^9yB1M|rN(}1V&=MRpf zLf1ub+ku&=LwpcMUjQ971lJ6JKY7ugmoZZ#S``ZDx0>8#D{s=G$cqxLLjt$G)LWPlI zpyOp=sAWz9b6swKI$#c&#lIZEO^g4tTc|MdYKYYUAGXXbkeUYODVN`04)_|Ht}>SG z5ISSq6u~_Xe2(C#fDoSmvDN5eh)%wlYS^+StRns4fO~+S;TL}poz2xna5Du)gi%w$ ztj3>ZZUS?yp*G;GH2T^BbAdXu z-wm<|e;|DaQsWGDTe7KGU(5s_0>0_k{)>wLR|NMUx-bfe5#slPnUB9k?S3fBCl}xcfZbKkbJF48#|J%yG)y25nV_ zZTovt*<3py20VslYHjR7MeTLCzd+aTX`}<=8}`EjF^E47#!Yl=hSo`j?f>g(g>&hE z7_bny!?Eu~qxicK+_ycRFMtW-3!r&1y6Ca73FJD%_QUi7xpF`Z_!Yr4^$v8B^IimZ z5Bkf$X+JESUj)rhqiHW2HPCj0VcXH(Ry-FDC_oP+xM}L`sQCR6+_2byFt!+ye?n(} zHdaF8&4yjAOKmqV1!8G+YRD44OH!L;jRQ*2Eh+aL;d*q_;#dUt?`Svh&Dgx0 z{d(Xm%bWt{7-|=0Rr?$uDh3QjlaH?W)o8On7Qx+!uIe1|<)a|>0)FxBU}hTTCI z6G2wt7vHQay1IT558*A~4uXzZfgYsjuxvxoQNZ4EUPaJJ2o=*nmf%lYAA!_l!`FtOFWK4Oh@r^~+X+tqU&JqJ z1lsIBZrQ2{b`LLY9oVqg1v1|7>Ym(HJvS&ocU@+oUk@_* zWDpPPfLpWR4aYibr#buP62#CiMzg^u;r$JZBM zt|62S0SSCdRDjOlinAyqDO^$l$yMkUw~f8P5@?ztl$V0B7Fj9l6Bkne#`-)rH3*FL zZaEcV)|x@APjQX&8LbS&AFzwTSTRdV$s*%b03^^fbysM+kkTDc{1?JMu{{^elh(_v zTkc5P)ji|f&-7d-bU%3ab8R#q`Vi$I?y9;9y&rksU2Vi(bN%W^VS*z#PE8~CsqFkBK&c0C#gh! P00000NkvXXu0mjfD1ft? literal 0 HcmV?d00001 diff --git a/src/app/valentina/share/resources/toolicon/svg/flipping_line.svg b/src/app/valentina/share/resources/toolicon/svg/flipping_line.svg new file mode 100644 index 000000000..aa4a3affc --- /dev/null +++ b/src/app/valentina/share/resources/toolicon/svg/flipping_line.svg @@ -0,0 +1,82 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index faf18ed06..46c7c42fc 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2519,7 +2519,7 @@ void VPattern::ParseToolRotation(VMainGraphicsScene *scene, QDomElement &domElem QVector source; QVector destination; - VToolRotation::ExtractData(this, domElement, source, destination); + VAbstractOperation::ExtractData(this, domElement, source, destination); VToolRotation::Create(id, center, a, suffix, source, destination, scene, this, data, parse, Source::FromFile); //Rewrite attribute formula. Need for situation when we have wrong formula. @@ -2544,6 +2544,36 @@ void VPattern::ParseToolRotation(VMainGraphicsScene *scene, QDomElement &domElem } } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParseToolFlippingByLine(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse) +{ + SCASSERT(scene != nullptr); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + + try + { + quint32 id = NULL_ID; + + ToolsCommonAttributes(domElement, id); + const quint32 p1 = GetParametrUInt(domElement, AttrP1Line, NULL_ID_STR); + const quint32 p2 = GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); + const QString suffix = GetParametrString(domElement, AttrSuffix, ""); + + QVector source; + QVector destination; + VAbstractOperation::ExtractData(this, domElement, source, destination); + + VToolFlippingByLine::Create(id, p1, p2, suffix, source, destination, scene, this, data, parse, + Source::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating operation of flipping by line"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } +} + //--------------------------------------------------------------------------------------------------------------------- qreal VPattern::EvalFormula(VContainer *data, const QString &formula, bool *ok) const { @@ -2794,13 +2824,17 @@ void VPattern::ParseOperationElement(VMainGraphicsScene *scene, QDomElement &dom Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(not type.isEmpty(), Q_FUNC_INFO, "type of operation is empty"); - const QStringList opers = QStringList() << VToolRotation::ToolType; /*0*/ + const QStringList opers = QStringList() << VToolRotation::ToolType /*0*/ + << VToolFlippingByLine::ToolType; /*1*/ switch (opers.indexOf(type)) { case 0: //VToolRotation::ToolType ParseToolRotation(scene, domElement, parse); break; + case 1: //VToolFlippingByLine::ToolType + ParseToolFlippingByLine(scene, domElement, parse); + break; default: VException e(tr("Unknown operation type '%1'.").arg(type)); throw e; @@ -3306,7 +3340,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") 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) == 45, "Not all tools was used."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was used."); QRectF rec; @@ -3418,6 +3452,9 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::Rotation: rec = ToolBoundingRect(rec, tool.getId()); break; + case Tool::FlippingByLine: + rec = ToolBoundingRect(rec, tool.getId()); + break; //These tools are not accesseble in Draw mode, but still 'history' contains them. case Tool::Detail: case Tool::UnionDetails: diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 9ccf41aa6..5ab917405 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -194,6 +194,7 @@ private: void ParseToolArcWithLength(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParseToolRotation(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); + void ParseToolFlippingByLine(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); qreal EvalFormula(VContainer *data, const QString &formula, bool *ok) const; diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index c55cd654e..3f4d890f7 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -18,6 +18,7 @@ schema/pattern/v0.3.2.xsd schema/pattern/v0.3.3.xsd schema/pattern/v0.3.4.xsd + schema/pattern/v0.3.5.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/pattern/v0.3.5.xsd b/src/libs/ifc/schema/pattern/v0.3.5.xsd new file mode 100644 index 000000000..b54271a63 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.3.5.xsd @@ -0,0 +1,574 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 2d1cf5568..4c0c34ed5 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -1372,7 +1372,7 @@ QStringList VAbstractPattern::ListPointExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46); QStringList expressions; const QDomNodeList list = elementsByTagName(TagPoint); @@ -1443,7 +1443,7 @@ QStringList VAbstractPattern::ListArcExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46); QStringList expressions; const QDomNodeList list = elementsByTagName(TagArc); @@ -1504,7 +1504,7 @@ QStringList VAbstractPattern::ListPathPointExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46); QStringList expressions; const QDomNodeList list = elementsByTagName(AttrPathPoint); @@ -1570,7 +1570,7 @@ QStringList VAbstractPattern::ListOperationExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46); QStringList expressions; const QDomNodeList list = elementsByTagName(TagOperation); diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 33b652163..dcd2a6eeb 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -58,8 +58,8 @@ class QDomElement; */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.3.4"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.3.4.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.3.5"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.3.5.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -167,6 +167,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000303): return QStringLiteral("://schema/pattern/v0.3.3.xsd"); case (0x000304): + return QStringLiteral("://schema/pattern/v0.3.4.xsd"); + case (0x000305): return CurrentSchema; default: InvalidVersion(ver); @@ -250,6 +252,10 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(0x000304), fileName); V_FALLTHROUGH case (0x000304): + ToV0_3_5(); + ValidateXML(XSDSchema(0x000305), fileName); + V_FALLTHROUGH + case (0x000305): break; default: break; @@ -410,6 +416,13 @@ void VPatternConverter::ToV0_3_4() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_3_5() +{ + SetVersion(QStringLiteral("0.3.5")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index b4af935ac..cca5e3c2f 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -55,10 +55,10 @@ public: // GCC 4.6 doesn't allow constexpr and const together #if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) <= 406 static Q_DECL_CONSTEXPR int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 3, 4); + static Q_DECL_CONSTEXPR int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 3, 5); #else static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 3, 4); + static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 3, 5); #endif protected: @@ -93,6 +93,7 @@ private: void ToV0_3_2(); void ToV0_3_3(); void ToV0_3_4(); + void ToV0_3_5(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index ad437abd6..0a51f4199 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -109,6 +109,7 @@ enum class Tool : ToolVisHolderType UnionDetails, Group, Rotation, + FlippingByLine, Midpoint, LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used }; @@ -121,6 +122,7 @@ enum class Vis : ToolVisHolderType SimpleCurve, Line, Path, + Operation, ToolAlongLine, ToolArc, ToolArcWithLength, @@ -149,7 +151,8 @@ enum class Vis : ToolVisHolderType ToolLineIntersectAxis, ToolCurveIntersectAxis, ToolTrueDarts, - ToolRotation + ToolRotation, + ToolFlippingByLine }; enum class VarType : char { Measurement, Increment, LineLength, CurveLength, LineAngle, CurveAngle, ArcRadius, diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index 5c1cc848e..8b51c331b 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -38,7 +38,8 @@ HEADERS += \ $$PWD/tools/dialogcubicbezier.h \ $$PWD/tools/dialogcubicbezierpath.h \ $$PWD/tools/dialoggroup.h \ - $$PWD/tools/dialogrotation.h + $$PWD/tools/dialogrotation.h \ + $$PWD/tools/dialogflippingbyline.h SOURCES += \ @@ -77,7 +78,8 @@ SOURCES += \ $$PWD/tools/dialogcubicbezier.cpp \ $$PWD/tools/dialogcubicbezierpath.cpp \ $$PWD/tools/dialoggroup.cpp \ - $$PWD/tools/dialogrotation.cpp + $$PWD/tools/dialogrotation.cpp \ + $$PWD/tools/dialogflippingbyline.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ @@ -114,4 +116,5 @@ FORMS += \ $$PWD/tools/dialogcubicbezier.ui \ $$PWD/tools/dialogcubicbezierpath.ui \ $$PWD/tools/dialoggroup.ui \ - $$PWD/tools/dialogrotation.ui + $$PWD/tools/dialogrotation.ui \ + $$PWD/tools/dialogflippingbyline.ui diff --git a/src/libs/vtools/dialogs/tooldialogs.h b/src/libs/vtools/dialogs/tooldialogs.h index d82ef4fb2..9a2e0d09d 100644 --- a/src/libs/vtools/dialogs/tooldialogs.h +++ b/src/libs/vtools/dialogs/tooldialogs.h @@ -62,6 +62,7 @@ #include "tools/dialogtruedarts.h" #include "tools/dialoggroup.h" #include "tools/dialogrotation.h" +#include "tools/dialogflippingbyline.h" #include "support/dialogeditwrongformula.h" #include "support/dialogundo.h" diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp b/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp new file mode 100644 index 000000000..39d92d6d6 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp @@ -0,0 +1,349 @@ +/************************************************************************ + ** + ** @file dialogflippingbyline.cpp + ** @author Roman Telezhynskyi + ** @date 12 9, 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 "dialogflippingbyline.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../visualization/visualization.h" +#include "../../visualization/line/operation/vistoolflippingbyline.h" +#include "../ifc/xml/vabstractpattern.h" +#include "../ifc/xml/vdomdocument.h" +#include "../qmuparser/qmudef.h" +#include "../vgeometry/vpointf.h" +#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vcommonsettings.h" +#include "../vpatterndb/vcontainer.h" +#include "../vwidgets/vabstractmainwindow.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "ui_dialogflippingbyline.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogFlippingByLine::DialogFlippingByLine(const VContainer *data, const quint32 &toolId, QWidget *parent) + : DialogTool(data, toolId, parent), + ui(new Ui::DialogFlippingByLine), + objects(), + stage1(true), + m_suffix() +{ + ui->setupUi(this); + + ui->lineEditSuffix->setText(qApp->getCurrentDocument()->GenerateSuffix()); + + InitOkCancelApply(ui); + + FillComboBoxPoints(ui->comboBoxFirstLinePoint); + FillComboBoxPoints(ui->comboBoxSecondLinePoint); + + flagName = true; + CheckState(); + + connect(ui->lineEditSuffix, &QLineEdit::textChanged, this, &DialogFlippingByLine::SuffixChanged); + connect(ui->comboBoxFirstLinePoint, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogFlippingByLine::PointChanged); + + vis = new VisToolFlippingByLine(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogFlippingByLine::~DialogFlippingByLine() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogFlippingByLine::GetFirstLinePointId() const +{ + return getCurrentObjectId(ui->comboBoxFirstLinePoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SetFirstLinePointId(quint32 value) +{ + ChangeCurrentData(ui->comboBoxFirstLinePoint, value); + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetFirstLinePointId(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogFlippingByLine::GetSecondLinePointId() const +{ + return getCurrentObjectId(ui->comboBoxSecondLinePoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SetSecondLinePointId(quint32 value) +{ + ChangeCurrentData(ui->comboBoxSecondLinePoint, value); + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetSecondLinePointId(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogFlippingByLine::GetSuffix() const +{ + return m_suffix; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SetSuffix(const QString &value) +{ + m_suffix = value; + ui->lineEditSuffix->setText(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector DialogFlippingByLine::GetObjects() const +{ + return objects.toVector(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::ShowDialog(bool click) +{ + if (stage1 && not click) + { + if (objects.isEmpty()) + { + return; + } + + stage1 = false; + + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + scene->clearSelection(); + + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetObjects(objects.toVector()); + operation->VisualMode(); + + scene->ToggleArcSelection(false); + scene->ToggleSplineSelection(false); + scene->ToggleSplinePathSelection(false); + + scene->ToggleArcHover(false); + scene->ToggleSplineHover(false); + scene->ToggleSplinePathHover(false); + + emit ToolTip("Select first line point"); + } + else if (not stage1 && prepare && click) + { + setModal(true); + emit ToolTip(""); + show(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::ChosenObject(quint32 id, const SceneObject &type) +{ + if (not stage1 && not prepare)// After first choose we ignore all objects + { + if (type == SceneObject::Point) + { + if (objects.contains(id)) + { + return; + } + + switch (number) + { + case 0: + if (SetObject(id, ui->comboBoxFirstLinePoint, tr("Select second line point"))) + { + number++; + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetFirstLinePointId(id); + operation->RefreshGeometry(); + } + break; + case 1: + if (getCurrentObjectId(ui->comboBoxFirstLinePoint) != id) + { + if (SetObject(id, ui->comboBoxSecondLinePoint, "")) + { + if (flagError) + { + number = 0; + prepare = true; + + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetSecondLinePointId(id); + operation->RefreshGeometry(); + } + } + } + break; + default: + break; + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SelectedObject(bool selected, quint32 object, quint32 tool) +{ + Q_UNUSED(tool) + if (stage1) + { + if (selected) + { + if (not objects.contains(object)) + { + objects.append(object); + } + } + else + { + objects.removeOne(object); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SuffixChanged() +{ + QLineEdit* edit = qobject_cast(sender()); + if (edit) + { + const QString suffix = edit->text(); + if (suffix.isEmpty()) + { + flagName = false; + ChangeColor(ui->labelSuffix, Qt::red); + CheckState(); + return; + } + else + { + if (m_suffix != suffix) + { + QRegularExpression rx(NameRegExp()); + const QStringList uniqueNames = data->AllUniqueNames(); + for (int i=0; i < uniqueNames.size(); ++i) + { + const QString name = uniqueNames.at(i) + suffix; + if (not rx.match(name).hasMatch() || not data->IsUnique(name)) + { + flagName = false; + ChangeColor(ui->labelSuffix, Qt::red); + CheckState(); + return; + } + } + } + } + + flagName = true; + ChangeColor(ui->labelSuffix, okColor); + } + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::CheckState() +{ + SCASSERT(bOk != nullptr); + bOk->setEnabled(flagError && flagName); + SCASSERT(bApply != nullptr); + bApply->setEnabled(bOk->isEnabled()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::ShowVisualization() +{ + AddVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SaveData() +{ + m_suffix = ui->lineEditSuffix->text(); + + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + + operation->SetObjects(objects.toVector()); + operation->SetFirstLinePointId(GetFirstLinePointId()); + operation->SetSecondLinePointId(GetSecondLinePointId()); + operation->RefreshGeometry(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::PointChanged() +{ + QColor color = okColor; + flagError = true; + ChangeColor(ui->labelFirstLinePoint, color); + ChangeColor(ui->labelSecondLinePoint, color); + + if (getCurrentObjectId(ui->comboBoxFirstLinePoint) == getCurrentObjectId(ui->comboBoxSecondLinePoint)) + { + flagError = false; + color = errorColor; + ChangeColor(ui->labelFirstLinePoint, color); + ChangeColor(ui->labelSecondLinePoint, color); + } + else if (objects.contains(getCurrentObjectId(ui->comboBoxFirstLinePoint))) + { + flagError = false; + color = errorColor; + ChangeColor(ui->labelFirstLinePoint, color); + } + else if (objects.contains(getCurrentObjectId(ui->comboBoxSecondLinePoint))) + { + flagError = false; + color = errorColor; + ChangeColor(ui->labelSecondLinePoint, color); + } + + CheckState(); +} diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyline.h b/src/libs/vtools/dialogs/tools/dialogflippingbyline.h new file mode 100644 index 000000000..300cbb0a3 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyline.h @@ -0,0 +1,102 @@ +/************************************************************************ + ** + ** @file dialogflippingbyline.h + ** @author Roman Telezhynskyi + ** @date 12 9, 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 DIALOGFLIPPINGBYLINE_H +#define DIALOGFLIPPINGBYLINE_H + +#include "dialogtool.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "../vmisc/def.h" + +class QWidget; +class VContainer; + +namespace Ui +{ + class DialogFlippingByLine; +} + +class DialogFlippingByLine : public DialogTool +{ + Q_OBJECT + +public: + explicit DialogFlippingByLine(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr); + virtual ~DialogFlippingByLine(); + + quint32 GetFirstLinePointId() const; + void SetFirstLinePointId(quint32 value); + + quint32 GetSecondLinePointId() const; + void SetSecondLinePointId(quint32 value); + + QString GetSuffix() const; + void SetSuffix(const QString &value); + + QVector GetObjects() const; + + virtual void ShowDialog(bool click) Q_DECL_OVERRIDE; + +public slots: + virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; + virtual void SelectedObject(bool selected, quint32 object, quint32 tool) Q_DECL_OVERRIDE; + +private slots: + void SuffixChanged(); + +protected: + virtual void CheckState() Q_DECL_OVERRIDE; + virtual void ShowVisualization() Q_DECL_OVERRIDE; + + /** @brief SaveData Put dialog data in local variables */ + virtual void SaveData() Q_DECL_OVERRIDE; + +private slots: + void PointChanged(); + +private: + Q_DISABLE_COPY(DialogFlippingByLine) + + Ui::DialogFlippingByLine *ui; + + QList objects; + + bool stage1; + + QString m_suffix; +}; + +#endif // DIALOGFLIPPINGBYLINE_H diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui b/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui new file mode 100644 index 000000000..cee345f19 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui @@ -0,0 +1,98 @@ + + + DialogFlippingByLine + + + + 0 + 0 + 285 + 146 + + + + Dialog + + + + + + + + First line point: + + + + + + + + + + Suffix: + + + + + + + + + + Second line point: + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DialogFlippingByLine + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogFlippingByLine + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.cpp b/src/libs/vtools/dialogs/tools/dialogrotation.cpp index 679e0f266..3a9babe2e 100644 --- a/src/libs/vtools/dialogs/tools/dialogrotation.cpp +++ b/src/libs/vtools/dialogs/tools/dialogrotation.cpp @@ -48,7 +48,7 @@ #include #include "../../visualization/visualization.h" -#include "../../visualization/line/vistoolrotation.h" +#include "../../visualization/line/operation/vistoolrotation.h" #include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vdomdocument.h" #include "../qmuparser/qmudef.h" diff --git a/src/libs/vtools/tools/drawTools/drawtools.h b/src/libs/vtools/tools/drawTools/drawtools.h index f52094158..93142cf64 100644 --- a/src/libs/vtools/tools/drawTools/drawtools.h +++ b/src/libs/vtools/tools/drawTools/drawtools.h @@ -59,5 +59,6 @@ #include "toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h" #include "toolpoint/tooldoublepoint/vtooltruedarts.h" #include "operation/vtoolrotation.h" +#include "operation/flipping/vtoolflippingbyline.h" #endif // DRAWTOOLS_H diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp new file mode 100644 index 000000000..7f097942e --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp @@ -0,0 +1,438 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 "vtoolflippingbyline.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../../../dialogs/tools/dialogtool.h" +#include "../../../../dialogs/tools/dialogflippingbyline.h" +#include "../../../../undocommands/label/rotationmovelabel.h" +#include "../../../../visualization/line/operation/vistoolflippingbyline.h" +#include "../../../../visualization/visualization.h" +#include "../vgeometry/vabstractcurve.h" +#include "../vgeometry/varc.h" +#include "../vgeometry/vcubicbezier.h" +#include "../vgeometry/vcubicbezierpath.h" +#include "../vgeometry/vgobject.h" +#include "../vgeometry/vpointf.h" +#include "../vgeometry/vspline.h" +#include "../vgeometry/vsplinepath.h" +#include "../vpatterndb/vtranslatevars.h" +#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vcommonsettings.h" +#include "../vmisc/diagnostic.h" +#include "../vmisc/logging.h" +#include "../vpatterndb/vcontainer.h" +#include "../vpatterndb/vformula.h" +#include "../ifc/ifcdef.h" +#include "../ifc/exception/vexception.h" +#include "../vwidgets/vabstractsimple.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "../../../vabstracttool.h" +#include "../../../vdatatool.h" +#include "../../vdrawtool.h" + +class QDomElement; +class QGraphicsSceneContextMenuEvent; +class QPainter; +class QStyleOptionGraphicsItem; +class QWidget; +template class QSharedPointer; + +const QString VToolFlippingByLine::ToolType = QStringLiteral("flippingByLine"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByLine::~VToolFlippingByLine() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::setDialog() +{ + SCASSERT(dialog != nullptr); + DialogFlippingByLine *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + dialogTool->SetFirstLinePointId(m_firstLinePointId); + dialogTool->SetSecondLinePointId(m_secondLinePointId); + dialogTool->SetSuffix(suffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByLine *VToolFlippingByLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data) +{ + SCASSERT(dialog != nullptr); + DialogFlippingByLine *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const quint32 firstLinePointId = dialogTool->GetFirstLinePointId(); + const quint32 secondLinePointId = dialogTool->GetSecondLinePointId(); + const QString suffix = dialogTool->GetSuffix(); + const QVector source = dialogTool->GetObjects(); + VToolFlippingByLine* operation = Create(0, firstLinePointId, secondLinePointId, suffix, source, + QVector(), scene, doc, data, Document::FullParse, + Source::FromGui); + if (operation != nullptr) + { + operation->dialog = dialogTool; + } + return operation; +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByLine *VToolFlippingByLine::Create(const quint32 _id, quint32 firstLinePointId, quint32 secondLinePointId, + const QString &suffix, const QVector &source, + const QVector &destination, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation) +{ + const auto firstPoint = *data->GeometricObject(firstLinePointId); + const QPointF fPoint = firstPoint; + + const auto secondPoint = *data->GeometricObject(secondLinePointId); + const QPointF sPoint = secondPoint; + + QVector dest = destination; + + quint32 id = _id; + if (typeCreation == Source::FromGui) + { + dest.clear();// Try to avoid mistake, value must be empty + + id = data->getNextId();//Just reserve id for tool + + for (int i = 0; i < source.size(); ++i) + { + const quint32 idObject = source.at(i); + const QSharedPointer obj = data->GetGObject(idObject); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch(static_cast(obj->getType())) + { + case GOType::Point: + dest.append(CreatePoint(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::Arc: + dest.append(CreateArc(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::EllipticalArc: + //dest.append(CreateItem(id, idObject, fPoint, sPoint, suffix)); + break; + case GOType::Spline: + dest.append(CreateCurve(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::SplinePath: + dest.append(CreateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::CubicBezier: + dest.append(CreateCurve(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::CubicBezierPath: + dest.append(CreateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::Unknown: + break; + } +QT_WARNING_POP + } + } + else + { + for (int i = 0; i < source.size(); ++i) + { + const quint32 idObject = source.at(i); + const QSharedPointer obj = data->GetGObject(idObject); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch(static_cast(obj->getType())) + { + case GOType::Point: + UpdatePoint(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id, dest.at(i).mx, + dest.at(i).my); + break; + case GOType::Arc: + UpdateArc(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::EllipticalArc: + //dest.append(UpdateItem(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::Spline: + UpdateCurve(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::SplinePath: + UpdateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::CubicBezier: + UpdateCurve(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::CubicBezierPath: + UpdateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data, + dest.at(i).id); + break; + case GOType::Unknown: + break; + } +QT_WARNING_POP + } + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + + VDrawTool::AddRecord(id, Tool::FlippingByLine, doc); + if (parse == Document::FullParse) + { + VToolFlippingByLine *tool = new VToolFlippingByLine(doc, data, id, firstLinePointId, secondLinePointId, suffix, + source, dest, typeCreation); + scene->addItem(tool); + InitOperationToolConnections(scene, tool); + doc->AddTool(id, tool); + doc->IncrementReferens(firstPoint.getIdTool()); + doc->IncrementReferens(secondPoint.getIdTool()); + for (int i = 0; i < source.size(); ++i) + { + doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool()); + } + return tool; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::ShowVisualization(bool show) +{ + ShowToolVisualization(show); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::SetVisualization() +{ + if (vis != nullptr) + { + VisToolFlippingByLine *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->SetObjects(source); + visual->SetFirstLinePointId(m_firstLinePointId); + visual->SetSecondLinePointId(m_secondLinePointId); + visual->RefreshGeometry(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::SaveDialog(QDomElement &domElement) +{ + SCASSERT(dialog != nullptr); + DialogFlippingByLine *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + + doc->SetAttribute(domElement, AttrP1Line, QString().setNum(dialogTool->GetFirstLinePointId())); + doc->SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->GetSecondLinePointId())); + doc->SetAttribute(domElement, AttrSuffix, dialogTool->GetSuffix()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::ReadToolAttributes(const QDomElement &domElement) +{ + m_firstLinePointId = doc->GetParametrUInt(domElement, AttrP1Line, NULL_ID_STR); + m_secondLinePointId = doc->GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); + suffix = doc->GetParametrString(domElement, AttrSuffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + VDrawTool::SaveOptions(tag, obj); + + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrP1Line, QString().setNum(m_firstLinePointId)); + doc->SetAttribute(tag, AttrP2Line, QString().setNum(m_secondLinePointId)); + doc->SetAttribute(tag, AttrSuffix, suffix); + + SaveSourceDestination(tag); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByLine::VToolFlippingByLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstLinePointId, + quint32 secondLinePointId, const QString &suffix, + const QVector &source, const QVector &destination, + const Source &typeCreation, QGraphicsItem *parent) + : VAbstractOperation(doc, data, id, suffix, source, destination, parent), + m_firstLinePointId(firstLinePointId), + m_secondLinePointId(secondLinePointId) +{ + InitOperatedObjects(); + ToolCreation(typeCreation); +} + +//--------------------------------------------------------------------------------------------------------------------- +DestinationItem VToolFlippingByLine::CreatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const QSharedPointer point = data->GeometricObject(idItem); + VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + + DestinationItem item; + item.mx = rotated.mx(); + item.my = rotated.my(); + item.id = data->AddGObject(new VPointF(rotated)); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +DestinationItem VToolFlippingByLine::CreateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); + data->AddArc(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id, + qreal mx, qreal my) +{ + const QSharedPointer point = data->GeometricObject(idItem); + VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + rotated.setMx(mx); + rotated.setMy(my); + data->UpdateGObject(id, new VPointF(rotated)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::UpdateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); + data->AddArc(data->GeometricObject(id), id); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VToolFlippingByLine::CreateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const QSharedPointer i = data->GeometricObject(idItem); + Item rotated = i->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + + DestinationItem item; + item.mx = INT_MAX; + item.my = INT_MAX; + item.id = data->AddGObject(new Item(rotated)); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VToolFlippingByLine::CreateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); + data->AddCurve(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VToolFlippingByLine::CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, + VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); + data->AddCurveWithSegments(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolFlippingByLine::UpdateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) +{ + const QSharedPointer i = data->GeometricObject(idItem); + Item rotated = i->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + data->UpdateGObject(id, new Item(rotated)); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolFlippingByLine::UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); + data->AddCurve(data->GeometricObject(id), id); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolFlippingByLine::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, + quint32 id) +{ + UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); + data->AddCurveWithSegments(data->GeometricObject(id), id); +} diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h new file mode 100644 index 000000000..485998b8f --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h @@ -0,0 +1,104 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 VTOOLFLIPPINGBYLINE_H +#define VTOOLFLIPPINGBYLINE_H + +#include + +#include "../vabstractoperation.h" + +class VToolFlippingByLine : public VAbstractOperation +{ + Q_OBJECT +public: + virtual ~VToolFlippingByLine(); + virtual void setDialog() Q_DECL_OVERRIDE; + static VToolFlippingByLine* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data); + static VToolFlippingByLine* Create(const quint32 _id, quint32 firstLinePointId, quint32 secondLinePointId, + const QString &suffix, const QVector &source, + const QVector &destination, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation); + + static const QString ToolType; + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Tool::FlippingByLine)}; + + virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; +protected: + virtual void SetVisualization() Q_DECL_OVERRIDE; + virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(VToolFlippingByLine) + + quint32 m_firstLinePointId; + quint32 m_secondLinePointId; + + VToolFlippingByLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstLinePointId, + quint32 secondLinePointId, const QString &suffix, const QVector &source, + const QVector &destination, const Source &typeCreation, + QGraphicsItem *parent = nullptr); + + static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + + template + static DestinationItem CreateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + static DestinationItem CreateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + template + static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + template + static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + + static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my); + template + static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id); + static void UpdateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id); + template + static void UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id); + template + static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, + quint32 id); +}; + +#endif // VTOOLFLIPPINGBYLINE_H diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp new file mode 100644 index 000000000..0a032c3a8 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -0,0 +1,610 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 "vabstractoperation.h" +#include "../../../undocommands/label/rotationmovelabel.h" +#include "../vgeometry/vpointf.h" + +const QString VAbstractOperation::TagItem = QStringLiteral("item"); +const QString VAbstractOperation::TagSource = QStringLiteral("source"); +const QString VAbstractOperation::TagDestination = QStringLiteral("destination"); + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractOperation::~VAbstractOperation() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractOperation::getTagName() const +{ + return VAbstractPattern::TagOperation; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::SetEnabled(bool enabled) +{ + this->setEnabled(enabled); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractOperation::Suffix() const +{ + return suffix; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::SetSuffix(const QString &suffix) +{ + // Don't know if need check name here. + this->suffix = suffix; + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::GroupVisibility(quint32 object, bool visible) +{ + if (operatedObjects.contains(object)) + { + VAbstractSimple *obj = operatedObjects.value(object); + if (obj->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(obj); + SCASSERT(item != nullptr); + item->setVisible(visible); + } + else + { + VSimpleCurve *item = qobject_cast(obj); + SCASSERT(item != nullptr); + item->setVisible(visible); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(painter); + Q_UNUSED(option); + Q_UNUSED(widget); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector &source, + QVector &destination) +{ + SCASSERT(doc != nullptr) + const QDomNodeList nodeList = domElement.childNodes(); + for (qint32 i = 0; i < nodeList.size(); ++i) + { + const QDomElement dataElement = nodeList.at(i).toElement(); + if (not dataElement.isNull() && dataElement.tagName() == TagSource) + { + source.clear(); + const QDomNodeList srcList = dataElement.childNodes(); + for (qint32 j = 0; j < srcList.size(); ++j) + { + const QDomElement element = srcList.at(j).toElement(); + if (not element.isNull()) + { + source.append(doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR)); + } + } + } + + if (not dataElement.isNull() && dataElement.tagName() == TagDestination) + { + destination.clear(); + const QDomNodeList srcList = dataElement.childNodes(); + for (qint32 j = 0; j < srcList.size(); ++j) + { + const QDomElement element = srcList.at(j).toElement(); + if (not element.isNull()) + { + DestinationItem d; + d.id = doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR); + d.mx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, QString::number(INT_MAX))); + d.my = qApp->toPixel(doc->GetParametrDouble(element, AttrMy, QString::number(INT_MAX))); + destination.append(d); + } + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::FullUpdateFromFile() +{ + ReadAttributes(); + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(VAbstractTool::data.GeometricObject(i.key())); + } + } + SetVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(VAbstractTool::data.GeometricObject(i.key())); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowHover(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setAcceptHoverEvents(enabled); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setAcceptHoverEvents(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowSelecting(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowPointHover(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setAcceptHoverEvents(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowPointSelecting(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowPointLabelHover(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->AllowLabelHover(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowPointLabelSelecting(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->AllowLabelSelecting(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowSplineHover(bool enabled) +{ + AllowCurveHover(enabled, GOType::Spline); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowSplineSelecting(bool enabled) +{ + AllowCurveSelecting(enabled, GOType::Spline); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowSplinePathHover(bool enabled) +{ + AllowCurveHover(enabled, GOType::SplinePath); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowSplinePathSelecting(bool enabled) +{ + AllowCurveSelecting(enabled, GOType::SplinePath); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowArcHover(bool enabled) +{ + AllowCurveHover(enabled, GOType::Arc); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowArcSelecting(bool enabled) +{ + AllowCurveSelecting(enabled, GOType::Arc); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::Disable(bool disable, const QString &namePP) +{ + enabled = !CorrectDisable(disable, namePP); + SetEnabled(enabled); + + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + i.value()->SetEnabled(enabled); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::ObjectSelected(bool selected, quint32 objId) +{ + emit ChangedToolSelection(selected, objId, id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::DeleteFromLabel() +{ + try + { + DeleteTool(); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::LabelChangePosition(const QPointF &pos, quint32 labelId) +{ + if (operatedObjects.contains(labelId)) + { + VAbstractSimple *obj = operatedObjects.value(labelId); + if (obj->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(obj); + SCASSERT(item != nullptr); + ChangePosition(item, labelId, pos); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractOperation::VAbstractOperation(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix, + const QVector &source, const QVector &destination, + QGraphicsItem *parent) + : VDrawTool(doc, data, id), + QGraphicsLineItem(parent), + suffix(suffix), + source(source), + destination(destination), + operatedObjects() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AddToFile() +{ + QDomElement domElement = doc->createElement(getTagName()); + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOptions(domElement, obj); + AddToCalculation(domElement); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(id); + if (domElement.isElement()) + { + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOptions(domElement, obj); + } + else + { + qCDebug(vTool, "Can't find tool with id = %u", id); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::UpdateNamePosition(quint32 id) +{ + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + auto moveLabel = new RotationMoveLabel(this->id, doc, point->mx(), point->my(), id); + connect(moveLabel, &RotationMoveLabel::ChangePosition, this, &VAbstractOperation::DoChangePosition); + qApp->getUndoStack()->push(moveLabel); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::SaveSourceDestination(QDomElement &tag) +{ + doc->RemoveAllChildren(tag); + + QDomElement tagObjects = doc->createElement(TagSource); + for (int i = 0; i < source.size(); ++i) + { + QDomElement item = doc->createElement(TagItem); + doc->SetAttribute(item, AttrIdObject, source.at(i)); + tagObjects.appendChild(item); + } + tag.appendChild(tagObjects); + + tagObjects = doc->createElement(TagDestination); + for (int i = 0; i < destination.size(); ++i) + { + QDomElement item = doc->createElement(TagItem); + doc->SetAttribute(item, AttrIdObject, destination.at(i).id); + + if (not VFuzzyComparePossibleNulls(destination.at(i).mx, INT_MAX) && + not VFuzzyComparePossibleNulls(destination.at(i).my, INT_MAX)) + { + doc->SetAttribute(item, AttrMx, qApp->fromPixel(destination.at(i).mx)); + doc->SetAttribute(item, AttrMy, qApp->fromPixel(destination.at(i).my)); + } + + tagObjects.appendChild(item); + } + tag.appendChild(tagObjects); +} + +//--------------------------------------------------------------------------------------------------------------------- +VSimpleCurve *VAbstractOperation::InitCurve(quint32 id, VContainer *data, GOType curveType) +{ + VSimpleCurve *curve = new VSimpleCurve(id, QColor(baseColor), *data->GetPatternUnit(), &factor); + curve->setParentItem(this); + curve->SetType(curveType); + connect(curve, &VSimpleCurve::Selected, this, &VAbstractOperation::ObjectSelected); + connect(curve, &VSimpleCurve::ShowContextMenu, [this](QGraphicsSceneContextMenuEvent * event) + { + contextMenuEvent(event); + }); + connect(curve, &VSimpleCurve::Delete, this, &VAbstractOperation::DeleteFromLabel); + curve->RefreshGeometry(VAbstractTool::data.GeometricObject(id)); + operatedObjects.insert(id, curve); + return curve; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::DoChangePosition(quint32 id, qreal mx, qreal my) +{ + if (operatedObjects.contains(id)) + { + VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(id)); + point->setMx(mx); + point->setMy(my); + VAbstractTool::data.UpdateGObject(id, point); + + VSimplePoint *item = qobject_cast(operatedObjects.value(id)); + SCASSERT(item != nullptr); + + item->RefreshGeometry(*point); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowCurveHover(bool enabled, GOType type) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() != GOType::Point) + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + if (item->GetType() == type) + { + item->setAcceptHoverEvents(enabled); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowCurveSelecting(bool enabled, GOType type) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() != GOType::Point) + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + if (item->GetType() == type) + { + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos) +{ + const QPointF p = pos - item->pos(); + DoChangePosition(id, p.x(), p.y()); + UpdateNamePosition(id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::InitOperatedObjects() +{ + for (int i = 0; i < destination.size(); ++i) + { + const DestinationItem object = destination.at(i); + const QSharedPointer obj = VAbstractTool::data.GetGObject(object.id); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch(static_cast(obj->getType())) + { + case GOType::Point: + { + VSimplePoint *point = new VSimplePoint(object.id, QColor(baseColor), + *VAbstractTool::data.GetPatternUnit(), &factor); + point->setParentItem(this); + point->SetType(GOType::Point); + connect(point, &VSimplePoint::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::Point); + }); + connect(point, &VSimplePoint::Selected, this, &VAbstractOperation::ObjectSelected); + connect(point, &VSimplePoint::ShowContextMenu, [this](QGraphicsSceneContextMenuEvent * event) + { + contextMenuEvent(event); + }); + connect(point, &VSimplePoint::Delete, this, &VAbstractOperation::DeleteFromLabel); + connect(point, &VSimplePoint::NameChangedPosition, this, &VAbstractOperation::LabelChangePosition); + point->RefreshGeometry(*VAbstractTool::data.GeometricObject(object.id)); + operatedObjects.insert(object.id, point); + break; + } + case GOType::Arc: + case GOType::EllipticalArc: + { + VSimpleCurve *curve = InitCurve(object.id, &(VAbstractTool::data), GOType::Arc); + connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::Arc); + }); + break; + } + case GOType::Spline: + case GOType::CubicBezier: + { + VSimpleCurve *curve = InitCurve(object.id, &(VAbstractTool::data), GOType::Spline); + connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::Spline); + }); + break; + } + case GOType::SplinePath: + case GOType::CubicBezierPath: + { + VSimpleCurve *curve = InitCurve(object.id, &(VAbstractTool::data), GOType::SplinePath); + connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::SplinePath); + }); + break; + } + case GOType::Unknown: + break; + } +QT_WARNING_POP + } +} diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h new file mode 100644 index 000000000..e10123df3 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h @@ -0,0 +1,203 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 VABSTRACTOPERATION_H +#define VABSTRACTOPERATION_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../vdrawtool.h" +#include "../vwidgets/vsimplecurve.h" +#include "../vwidgets/vsimplepoint.h" + +struct DestinationItem +{ + quint32 id; + qreal mx; + qreal my; +}; + +class VAbstractSimple; +class VAbstractPattern; +class QDomElement; +class QPainter; +class QPointF; +class QStyleOptionGraphicsItem; +class QWidget; +class VContainer; + +// FIXME. I don't know how to use QGraphicsItem properly, so just took first available finished class. +// QGraphicsItem itself produce case where clicking on empty space produce call to QGraphicsItem. +// And i don't know how to fix it. +class VAbstractOperation : public VDrawTool, public QGraphicsLineItem +{ + Q_OBJECT + // Fix warning "Class implements the interface QGraphicsItem but does not list it + // in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!" + Q_INTERFACES(QGraphicsItem) +public: + virtual ~VAbstractOperation(); + + static const QString TagItem; + static const QString TagSource; + static const QString TagDestination; + + virtual QString getTagName() const Q_DECL_OVERRIDE; + + void SetEnabled(bool enabled); + + QString Suffix() const; + void SetSuffix(const QString &suffix); + + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE; + + static void ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector &source, + QVector &destination); +public slots: + virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; + virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; + + virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; + virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; + + void AllowPointHover(bool enabled); + void AllowPointSelecting(bool enabled); + + void AllowPointLabelHover(bool enabled); + void AllowPointLabelSelecting(bool enabled); + + void AllowSplineHover(bool enabled); + void AllowSplineSelecting(bool enabled); + + void AllowSplinePathHover(bool enabled); + void AllowSplinePathSelecting(bool enabled); + + void AllowArcHover(bool enabled); + void AllowArcSelecting(bool enabled); + + virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; + void ObjectSelected(bool selected, quint32 objId); + void DeleteFromLabel(); + void LabelChangePosition(const QPointF &pos, quint32 labelId); +protected: + QString suffix; + + QVector source; + QVector destination; + + QMap operatedObjects; + + VAbstractOperation(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix, + const QVector &source, const QVector &destination, + QGraphicsItem *parent = nullptr); + + virtual void AddToFile() Q_DECL_OVERRIDE; + virtual void RefreshDataInFile() Q_DECL_OVERRIDE; + + void UpdateNamePosition(quint32 id); + void SaveSourceDestination(QDomElement &tag); + + template + void ShowToolVisualization(bool show); + + VSimpleCurve *InitCurve(quint32 id, VContainer *data, GOType curveType); + + template + static void InitOperationToolConnections(VMainGraphicsScene *scene, T *tool); + + void InitOperatedObjects(); +protected slots: + void DoChangePosition(quint32 id, qreal mx, qreal my); +private: + Q_DISABLE_COPY(VAbstractOperation) + + void AllowCurveHover(bool enabled, GOType type); + void AllowCurveSelecting(bool enabled, GOType type); + + void ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos); +}; + +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractOperation::ShowToolVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + AddVisualization(); + SetVisualization(); + } + else + { + if (T *visual = qobject_cast(vis)) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractOperation::InitOperationToolConnections(VMainGraphicsScene *scene, T *tool) +{ + SCASSERT(scene != nullptr); + SCASSERT(tool != nullptr); + + InitDrawToolConnections(scene, tool); + + QObject::connect(scene, &VMainGraphicsScene::EnablePointItemHover, tool, &T::AllowPointHover); + QObject::connect(scene, &VMainGraphicsScene::EnablePointItemSelection, tool, &T::AllowPointSelecting); + QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemHover, tool, &T::AllowPointLabelHover); + QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemSelection, tool, &T::AllowPointLabelSelecting); + + QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemHover, tool, &T::AllowSplineHover); + QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemSelection, tool, &T::AllowSplineSelecting); + + QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemHover, tool, &T::AllowSplinePathHover); + QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemSelection, tool, &T::AllowSplinePathSelecting); + + QObject::connect(scene, &VMainGraphicsScene::EnableArcItemHover, tool, &T::AllowArcHover); + QObject::connect(scene, &VMainGraphicsScene::EnableArcItemSelection, tool, &T::AllowArcSelecting); +} + +#endif // VABSTRACTOPERATION_H diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp index 07d80ff05..a02019573 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp @@ -44,8 +44,7 @@ #include "../../../dialogs/tools/dialogtool.h" #include "../../../dialogs/tools/dialogrotation.h" -#include "../../../undocommands/label/rotationmovelabel.h" -#include "../../../visualization/line/vistoolrotation.h" +#include "../../../visualization/line/operation/vistoolrotation.h" #include "../../../visualization/visualization.h" #include "../vgeometry/vabstractcurve.h" #include "../vgeometry/varc.h" @@ -66,8 +65,6 @@ #include "../ifc/exception/vexception.h" #include "../vwidgets/vabstractsimple.h" #include "../vwidgets/vmaingraphicsscene.h" -#include "../vwidgets/vsimplecurve.h" -#include "../vwidgets/vsimplepoint.h" #include "../../vabstracttool.h" #include "../../vdatatool.h" #include "../vdrawtool.h" @@ -79,90 +76,18 @@ class QStyleOptionGraphicsItem; class QWidget; template class QSharedPointer; -const QString VToolRotation::ToolType = QStringLiteral("rotation"); -const QString VToolRotation::TagItem = QStringLiteral("item"); -const QString VToolRotation::TagSource = QStringLiteral("source"); -const QString VToolRotation::TagDestination = QStringLiteral("destination"); +const QString VToolRotation::ToolType = QStringLiteral("rotation"); //--------------------------------------------------------------------------------------------------------------------- VToolRotation::VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId, const QString &angle, const QString &suffix, const QVector &source, const QVector &destination, const Source &typeCreation, QGraphicsItem *parent) - : VDrawTool(doc, data, id), - QGraphicsLineItem(parent), + : VAbstractOperation(doc, data, id, suffix, source, destination, parent), origPointId(origPointId), - formulaAngle(angle), - suffix(suffix), - source(source), - destination(destination), - rObjects() + formulaAngle(angle) { - for (int i = 0; i < destination.size(); ++i) - { - const DestinationItem object = destination.at(i); - const QSharedPointer obj = data->GetGObject(object.id); - - // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); - -QT_WARNING_PUSH -QT_WARNING_DISABLE_GCC("-Wswitch-default") - switch(static_cast(obj->getType())) - { - case GOType::Point: - { - VSimplePoint *point = new VSimplePoint(object.id, QColor(baseColor), *data->GetPatternUnit(), &factor); - point->setParentItem(this); - point->SetType(GOType::Point); - connect(point, &VSimplePoint::Choosed, [this](quint32 id) - { - emit ChoosedTool(id, SceneObject::Point); - }); - connect(point, &VSimplePoint::Selected, this, &VToolRotation::ObjectSelected); - connect(point, &VSimplePoint::ShowContextMenu, this, &VToolRotation::contextMenuEvent); - connect(point, &VSimplePoint::Delete, this, &VToolRotation::DeleteFromLabel); - connect(point, &VSimplePoint::NameChangedPosition, this, &VToolRotation::LabelChangePosition); - point->RefreshGeometry(*VAbstractTool::data.GeometricObject(object.id)); - rObjects.insert(object.id, point); - break; - } - case GOType::Arc: - case GOType::EllipticalArc: - { - VSimpleCurve *curve = InitCurve(object.id, data, GOType::Arc); - connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) - { - emit ChoosedTool(id, SceneObject::Arc); - }); - break; - } - case GOType::Spline: - case GOType::CubicBezier: - { - VSimpleCurve *curve = InitCurve(object.id, data, GOType::Spline); - connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) - { - emit ChoosedTool(id, SceneObject::Spline); - }); - break; - } - case GOType::SplinePath: - case GOType::CubicBezierPath: - { - VSimpleCurve *curve = InitCurve(object.id, data, GOType::SplinePath); - connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) - { - emit ChoosedTool(id, SceneObject::SplinePath); - }); - break; - } - case GOType::Unknown: - break; - } -QT_WARNING_POP - } - + InitOperatedObjects(); ToolCreation(typeCreation); } @@ -317,7 +242,7 @@ QT_WARNING_POP { VToolRotation *tool = new VToolRotation(doc, data, id, origin, angle, suffix, source, dest, typeCreation); scene->addItem(tool); - InitRotationToolConnections(scene, tool); + InitOperationToolConnections(scene, tool); doc->AddTool(id, tool); doc->IncrementReferens(originPoint.getIdTool()); for (int i = 0; i < source.size(); ++i) @@ -329,61 +254,6 @@ QT_WARNING_POP return nullptr; } -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector &source, - QVector &destination) -{ - SCASSERT(doc != nullptr) - const QDomNodeList nodeList = domElement.childNodes(); - for (qint32 i = 0; i < nodeList.size(); ++i) - { - const QDomElement dataElement = nodeList.at(i).toElement(); - if (not dataElement.isNull() && dataElement.tagName() == TagSource) - { - source.clear(); - const QDomNodeList srcList = dataElement.childNodes(); - for (qint32 j = 0; j < srcList.size(); ++j) - { - const QDomElement element = srcList.at(j).toElement(); - if (not element.isNull()) - { - source.append(doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR)); - } - } - } - - if (not dataElement.isNull() && dataElement.tagName() == TagDestination) - { - destination.clear(); - const QDomNodeList srcList = dataElement.childNodes(); - for (qint32 j = 0; j < srcList.size(); ++j) - { - const QDomElement element = srcList.at(j).toElement(); - if (not element.isNull()) - { - DestinationItem d; - d.id = doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR); - d.mx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, QString::number(INT_MAX))); - d.my = qApp->toPixel(doc->GetParametrDouble(element, AttrMy, QString::number(INT_MAX))); - destination.append(d); - } - } - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VToolRotation::getTagName() const -{ - return VAbstractPattern::TagOperation; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::SetEnabled(bool enabled) -{ - this->setEnabled(enabled); -} - //--------------------------------------------------------------------------------------------------------------------- VFormula VToolRotation::GetFormulaAngle() const { @@ -406,263 +276,12 @@ void VToolRotation::SetFormulaAngle(const VFormula &value) } } -//--------------------------------------------------------------------------------------------------------------------- -QString VToolRotation::Suffix() const -{ - return suffix; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::SetSuffix(const QString &suffix) -{ - // Don't know if need check name here. - this->suffix = suffix; - QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); - SaveOption(obj); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::GroupVisibility(quint32 object, bool visible) -{ - if (rObjects.contains(object)) - { - VAbstractSimple *obj = rObjects.value(object); - if (obj->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(obj); - SCASSERT(item != nullptr); - item->setVisible(visible); - } - else - { - VSimpleCurve *item = qobject_cast(obj); - SCASSERT(item != nullptr); - item->setVisible(visible); - } - } -} - //--------------------------------------------------------------------------------------------------------------------- void VToolRotation::ShowVisualization(bool show) { ShowToolVisualization(show); } -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::FullUpdateFromFile() -{ - ReadAttributes(); - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); - } - else - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->RefreshGeometry(VAbstractTool::data.GeometricObject(i.key())); - } - } - SetVisualization(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); - } - else - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->RefreshGeometry(VAbstractTool::data.GeometricObject(i.key())); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowHover(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setAcceptHoverEvents(enabled); - } - else - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setAcceptHoverEvents(enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowSelecting(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); - } - else - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowPointHover(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setAcceptHoverEvents(enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowPointSelecting(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowPointLabelHover(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->AllowLabelHover(enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowPointLabelSelecting(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->AllowLabelSelecting(enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowSplineHover(bool enabled) -{ - AllowCurveHover(enabled, GOType::Spline); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowSplineSelecting(bool enabled) -{ - AllowCurveSelecting(enabled, GOType::Spline); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowSplinePathHover(bool enabled) -{ - AllowCurveHover(enabled, GOType::SplinePath); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowSplinePathSelecting(bool enabled) -{ - AllowCurveSelecting(enabled, GOType::SplinePath); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowArcHover(bool enabled) -{ - AllowCurveHover(enabled, GOType::Arc); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowArcSelecting(bool enabled) -{ - AllowCurveSelecting(enabled, GOType::Arc); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AddToFile() -{ - QDomElement domElement = doc->createElement(getTagName()); - QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); - SaveOptions(domElement, obj); - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::RefreshDataInFile() -{ - QDomElement domElement = doc->elementById(id); - if (domElement.isElement()) - { - QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); - SaveOptions(domElement, obj); - } - else - { - qCDebug(vTool, "Can't find tool with id = %u", id); - } -} - //--------------------------------------------------------------------------------------------------------------------- void VToolRotation::SetVisualization() { @@ -678,63 +297,6 @@ void VToolRotation::SetVisualization() } } -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(painter); - Q_UNUSED(option); - Q_UNUSED(widget); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::Disable(bool disable, const QString &namePP) -{ - enabled = !CorrectDisable(disable, namePP); - SetEnabled(enabled); - - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - i.value()->SetEnabled(enabled); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::ObjectSelected(bool selected, quint32 objId) -{ - emit ChangedToolSelection(selected, objId, id); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::DeleteFromLabel() -{ - try - { - DeleteTool(); - } - catch(const VExceptionToolWasDeleted &e) - { - Q_UNUSED(e); - return;//Leave this method immediately!!! - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::LabelChangePosition(const QPointF &pos, quint32 labelId) -{ - if (rObjects.contains(labelId)) - { - VAbstractSimple *obj = rObjects.value(labelId); - if (obj->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(obj); - SCASSERT(item != nullptr); - ChangePosition(item, labelId, pos); - } - } -} - //--------------------------------------------------------------------------------------------------------------------- void VToolRotation::SaveDialog(QDomElement &domElement) { @@ -765,33 +327,7 @@ void VToolRotation::SaveOptions(QDomElement &tag, QSharedPointer &obj) doc->SetAttribute(tag, AttrAngle, formulaAngle); doc->SetAttribute(tag, AttrSuffix, suffix); - doc->RemoveAllChildren(tag); - - QDomElement tagObjects = doc->createElement(TagSource); - for (int i = 0; i < source.size(); ++i) - { - QDomElement item = doc->createElement(TagItem); - doc->SetAttribute(item, AttrIdObject, source.at(i)); - tagObjects.appendChild(item); - } - tag.appendChild(tagObjects); - - tagObjects = doc->createElement(TagDestination); - for (int i = 0; i < destination.size(); ++i) - { - QDomElement item = doc->createElement(TagItem); - doc->SetAttribute(item, AttrIdObject, destination.at(i).id); - - if (not VFuzzyComparePossibleNulls(destination.at(i).mx, INT_MAX) && - not VFuzzyComparePossibleNulls(destination.at(i).my, INT_MAX)) - { - doc->SetAttribute(item, AttrMx, qApp->fromPixel(destination.at(i).mx)); - doc->SetAttribute(item, AttrMy, qApp->fromPixel(destination.at(i).my)); - } - - tagObjects.appendChild(item); - } - tag.appendChild(tagObjects); + SaveSourceDestination(tag); } //--------------------------------------------------------------------------------------------------------------------- @@ -808,32 +344,6 @@ void VToolRotation::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) } } -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::DoChangePosition(quint32 id, qreal mx, qreal my) -{ - if (rObjects.contains(id)) - { - VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(id)); - point->setMx(mx); - point->setMy(my); - VAbstractTool::data.UpdateGObject(id, point); - - VSimplePoint *item = qobject_cast(rObjects.value(id)); - SCASSERT(item != nullptr); - - item->RefreshGeometry(*point); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::UpdateNamePosition(quint32 id) -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - auto moveLabel = new RotationMoveLabel(this->id, doc, point->mx(), point->my(), id); - connect(moveLabel, &RotationMoveLabel::ChangePosition, this, &VToolRotation::DoChangePosition); - qApp->getUndoStack()->push(moveLabel); -} - //--------------------------------------------------------------------------------------------------------------------- DestinationItem VToolRotation::CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data) @@ -942,121 +452,3 @@ void VToolRotation::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, cons UpdateItem(idTool, idItem, origin, angle, suffix, data, id); data->AddCurveWithSegments(data->GeometricObject(id), id); } - -//--------------------------------------------------------------------------------------------------------------------- -template -void VToolRotation::ShowToolVisualization(bool show) -{ - if (show) - { - if (vis == nullptr) - { - AddVisualization(); - SetVisualization(); - } - else - { - if (T *visual = qobject_cast(vis)) - { - visual->show(); - } - } - } - else - { - delete vis; - vis = nullptr; - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos) -{ - const QPointF p = pos - item->pos(); - DoChangePosition(id, p.x(), p.y()); - UpdateNamePosition(id); -} - -//--------------------------------------------------------------------------------------------------------------------- -VSimpleCurve *VToolRotation::InitCurve(quint32 id, VContainer *data, GOType curveType) -{ - VSimpleCurve *curve = new VSimpleCurve(id, QColor(baseColor), *data->GetPatternUnit(), &factor); - curve->setParentItem(this); - curve->SetType(curveType); - connect(curve, &VSimpleCurve::Selected, this, &VToolRotation::ObjectSelected); - connect(curve, &VSimpleCurve::ShowContextMenu, this, &VToolRotation::contextMenuEvent); - connect(curve, &VSimpleCurve::Delete, this, &VToolRotation::DeleteFromLabel); - curve->RefreshGeometry(VAbstractTool::data.GeometricObject(id)); - rObjects.insert(id, curve); - return curve; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowCurveHover(bool enabled, GOType type) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() != GOType::Point) - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - if (item->GetType() == type) - { - item->setAcceptHoverEvents(enabled); - } - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowCurveSelecting(bool enabled, GOType type) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() != GOType::Point) - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - if (item->GetType() == type) - { - item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); - } - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AddSourceObject(VAbstractPattern *doc, QDomElement &domElement, quint32 objId) -{ - QDomElement obj = doc->createElement(TagItem); - doc->SetAttribute(obj, AttrIdObject, objId); - domElement.appendChild(obj); -} - -//--------------------------------------------------------------------------------------------------------------------- -template -void VToolRotation::InitRotationToolConnections(VMainGraphicsScene *scene, T *tool) -{ - SCASSERT(scene != nullptr); - SCASSERT(tool != nullptr); - - InitDrawToolConnections(scene, tool); - - QObject::connect(scene, &VMainGraphicsScene::EnablePointItemHover, tool, &T::AllowPointHover); - QObject::connect(scene, &VMainGraphicsScene::EnablePointItemSelection, tool, &T::AllowPointSelecting); - QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemHover, tool, &T::AllowPointLabelHover); - QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemSelection, tool, &T::AllowPointLabelSelecting); - - QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemHover, tool, &T::AllowSplineHover); - QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemSelection, tool, &T::AllowSplineSelecting); - - QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemHover, tool, &T::AllowSplinePathHover); - QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemSelection, tool, &T::AllowSplinePathSelecting); - - QObject::connect(scene, &VMainGraphicsScene::EnableArcItemHover, tool, &T::AllowArcHover); - QObject::connect(scene, &VMainGraphicsScene::EnableArcItemSelection, tool, &T::AllowArcSelecting); -} diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h index 41e54cda2..0920158db 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h @@ -30,18 +30,14 @@ #define VTOOLROTATION_H #include -#include -#include -#include #include #include #include -#include #include #include #include -#include "../vdrawtool.h" +#include "vabstractoperation.h" #include "../vgeometry/vgeometrydef.h" #include "../vmisc/def.h" #include "../ifc/xml/vabstractpattern.h" @@ -49,35 +45,16 @@ class DialogTool; class QDomElement; class QGraphicsSceneContextMenuEvent; -class QPainter; class QPointF; -class QStyleOptionGraphicsItem; -class QWidget; class VContainer; class VGObject; class VMainGraphicsScene; template class QSharedPointer; - -struct DestinationItem -{ - quint32 id; - qreal mx; - qreal my; -}; - -class VAbstractSimple; class VFormula; -class VSimpleCurve; -// FIXME. I don't know how to use QGraphicsItem properly, so just took first available finished class. -// QGraphicsItem itself produce case where clicking on empty space produce call to QGraphicsItem. -// And i don't know how to fix it. -class VToolRotation : public VDrawTool, public QGraphicsLineItem +class VToolRotation : public VAbstractOperation { Q_OBJECT - // Fix warning "Class implements the interface QGraphicsItem but does not list it - // in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!" - Q_INTERFACES(QGraphicsItem) public: virtual ~VToolRotation(); virtual void setDialog() Q_DECL_OVERRIDE; @@ -87,85 +64,34 @@ public: const QVector &source, const QVector &destination, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); - static void ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector &source, - QVector &destination); + static const QString ToolType; - static const QString TagItem; - static const QString TagSource; - static const QString TagDestination; + virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::Rotation)}; - virtual QString getTagName() const Q_DECL_OVERRIDE; - - void SetEnabled(bool enabled); VFormula GetFormulaAngle() const; void SetFormulaAngle(const VFormula &value); - QString Suffix() const; - void SetSuffix(const QString &suffix); - - virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE; - -public slots: - virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; - - virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; - virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; - - void AllowPointHover(bool enabled); - void AllowPointSelecting(bool enabled); - - void AllowPointLabelHover(bool enabled); - void AllowPointLabelSelecting(bool enabled); - - void AllowSplineHover(bool enabled); - void AllowSplineSelecting(bool enabled); - - void AllowSplinePathHover(bool enabled); - void AllowSplinePathSelecting(bool enabled); - - void AllowArcHover(bool enabled); - void AllowArcSelecting(bool enabled); - - virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; - void ObjectSelected(bool selected, quint32 objId); - void DeleteFromLabel(); - void LabelChangePosition(const QPointF &pos, quint32 labelId); protected: - virtual void AddToFile() Q_DECL_OVERRIDE; - virtual void RefreshDataInFile() Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; -private slots: - void DoChangePosition(quint32 id, qreal mx, qreal my); - private: Q_DISABLE_COPY(VToolRotation) quint32 origPointId; QString formulaAngle; - QString suffix; - - QVector source; - QVector destination; - - QMap rObjects; VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId, const QString &formulaAngle, const QString &suffix, const QVector &source, const QVector &destination, const Source &typeCreation, QGraphicsItem *parent = nullptr); - void UpdateNamePosition(quint32 id); - static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data); @@ -178,8 +104,8 @@ private: static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data); template - static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, - const QString &suffix, VContainer *data); + static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, + qreal formulaAngle, const QString &suffix, VContainer *data); static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my); @@ -194,21 +120,6 @@ private: template static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data, quint32 id); - - template - void ShowToolVisualization(bool show); - - void ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos); - - VSimpleCurve *InitCurve(quint32 id, VContainer *data, GOType curveType); - - template - static void InitRotationToolConnections(VMainGraphicsScene *scene, T *tool); - - void AllowCurveHover(bool enabled, GOType type); - void AllowCurveSelecting(bool enabled, GOType type); - - static void AddSourceObject(VAbstractPattern *doc, QDomElement &domElement, quint32 objId); }; #endif // VTOOLROTATION_H diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index 0391ca475..f50749a81 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -51,7 +51,9 @@ HEADERS += \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.h \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h \ $$PWD/drawTools/operation/vtoolrotation.h \ - $$PWD/vtextgraphicsitem.h + $$PWD/vtextgraphicsitem.h \ + $$PWD/drawTools/operation/flipping/vtoolflippingbyline.h \ + $$PWD/drawTools/operation/vabstractoperation.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -100,4 +102,6 @@ SOURCES += \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp \ $$PWD/drawTools/operation/vtoolrotation.cpp \ - $$PWD/vtextgraphicsitem.cpp + $$PWD/vtextgraphicsitem.cpp \ + $$PWD/drawTools/operation/flipping/vtoolflippingbyline.cpp \ + $$PWD/drawTools/operation/vabstractoperation.cpp diff --git a/src/libs/vtools/visualization/line/operation/visoperation.cpp b/src/libs/vtools/visualization/line/operation/visoperation.cpp new file mode 100644 index 000000000..56628e3cb --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/visoperation.cpp @@ -0,0 +1,99 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 "visoperation.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisOperation::VisOperation(const VContainer *data, QGraphicsItem *parent) + : VisLine(data, parent), + objects(), + supportColor2(Qt::darkGreen), + points(), + curves() +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +VisOperation::~VisOperation() +{ + qDeleteAll(points); + qDeleteAll(curves); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisOperation::SetObjects(QVector objects) +{ + this->objects = objects; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisOperation::VisualMode(const quint32 &pointId) +{ + Q_UNUSED(pointId); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + + Visualization::scenePos = scene->getScenePos(); + RefreshGeometry(); + + AddOnScene(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsEllipseItem *VisOperation::GetPoint(quint32 i, const QColor &color) +{ + if (not points.isEmpty() && static_cast(points.size() - 1) >= i) + { + return points.at(static_cast(i)); + } + else + { + auto point = InitPoint(color, this); + points.append(point); + return point; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsPathItem *VisOperation::GetCurve(quint32 i, const QColor &color) +{ + if (not curves.isEmpty() && static_cast(curves.size() - 1) >= i) + { + return curves.at(static_cast(i)); + } + else + { + auto curve = InitItem(color, this); + curves.append(curve); + return curve; + } + return nullptr; +} + diff --git a/src/libs/vtools/visualization/line/operation/visoperation.h b/src/libs/vtools/visualization/line/operation/visoperation.h new file mode 100644 index 000000000..fe4628f04 --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/visoperation.h @@ -0,0 +1,62 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 VISOPERATION_H +#define VISOPERATION_H + +#include + +#include "../visline.h" + +class VisOperation : public VisLine +{ + Q_OBJECT +public: + explicit VisOperation(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisOperation(); + + void SetObjects(QVector objects); + + virtual void VisualMode(const quint32 &pointId = NULL_ID) Q_DECL_OVERRIDE; + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ToolRotation)}; +protected: + QVector objects; + QColor supportColor2; + + QVector points; + QVector curves; + + QGraphicsEllipseItem * GetPoint(quint32 i, const QColor &color); + QGraphicsPathItem * GetCurve(quint32 i, const QColor &color); +private: + Q_DISABLE_COPY(VisOperation) +}; + +#endif // VISOPERATION_H diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp new file mode 100644 index 000000000..0e66bf5b9 --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp @@ -0,0 +1,185 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 "vistoolflippingbyline.h" +#include "../vgeometry/vabstractcurve.h" +#include "../vgeometry/varc.h" +#include "../vgeometry/vcubicbezier.h" +#include "../vgeometry/vcubicbezierpath.h" +#include "../vgeometry/vellipticalarc.h" +#include "../vgeometry/vgeometrydef.h" +#include "../vgeometry/vgobject.h" +#include "../vgeometry/vpointf.h" +#include "../vgeometry/vspline.h" +#include "../vgeometry/vsplinepath.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolFlippingByLine::VisToolFlippingByLine(const VContainer *data, QGraphicsItem *parent) + : VisOperation(data, parent), + object2Id(NULL_ID), + point1(nullptr), + point2(nullptr) +{ + point1 = InitPoint(supportColor2, this); + point2 = InitPoint(supportColor2, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolFlippingByLine::~VisToolFlippingByLine() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") +void VisToolFlippingByLine::RefreshGeometry() +{ + if (objects.isEmpty()) + { + return; + } + + QPointF firstPoint; + QPointF secondPoint; + + if (object1Id != NULL_ID) + { + firstPoint = *Visualization::data->GeometricObject(object1Id); + DrawPoint(point1, firstPoint, supportColor2); + + if (object2Id == NULL_ID) + { + secondPoint = Visualization::scenePos; + } + else + { + secondPoint = *Visualization::data->GeometricObject(object2Id); + DrawPoint(point2, secondPoint, supportColor2); + } + + DrawLine(this, QLineF(firstPoint, secondPoint), supportColor2, Qt::DashLine); + } + + int iPoint = -1; + int iCurve = -1; + for (int i = 0; i < objects.size(); ++i) + { + const quint32 id = objects.at(i); + const QSharedPointer obj = Visualization::data->GetGObject(id); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + + switch(static_cast(obj->getType())) + { + case GOType::Point: + { + const QSharedPointer p = Visualization::data->GeometricObject(id); + + ++iPoint; + QGraphicsEllipseItem *point = GetPoint(iPoint, supportColor2); + DrawPoint(point, *p, supportColor2); + + ++iPoint; + point = GetPoint(iPoint, supportColor); + + if (object1Id != NULL_ID) + { + DrawPoint(point, p->Flip(QLineF(firstPoint, secondPoint)), supportColor); + } + break; + } + case GOType::Arc: + { + iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::EllipticalArc: + { + iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::Spline: + { + iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::SplinePath: + { + iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::CubicBezier: + { + iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::CubicBezierPath: + { + iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::Unknown: + break; + } + } +} +QT_WARNING_POP + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolFlippingByLine::SetFirstLinePointId(quint32 value) +{ + object1Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolFlippingByLine::SetSecondLinePointId(quint32 value) +{ + object2Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +int VisToolFlippingByLine::AddCurve(const QPointF &firstPoint, const QPointF &secondPoint, quint32 id, int i) +{ + const QSharedPointer curve = Visualization::data->template GeometricObject(id); + + ++i; + QGraphicsPathItem *path = GetCurve(i, supportColor2); + DrawPath(path, curve->GetPath(PathDirection::Show), supportColor2, Qt::SolidLine, Qt::RoundCap); + + ++i; + path = GetCurve(i, supportColor); + if (object1Id != NULL_ID) + { + const Item flipped = curve->Flip(QLineF(firstPoint, secondPoint)); + DrawPath(path, flipped.GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + } + + return i; +} diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h new file mode 100644 index 000000000..4e9160654 --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h @@ -0,0 +1,60 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 VISTOOLFLIPPINGBYLINE_H +#define VISTOOLFLIPPINGBYLINE_H + +#include + +#include "visoperation.h" + +class VisToolFlippingByLine : public VisOperation +{ + Q_OBJECT +public: + explicit VisToolFlippingByLine(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolFlippingByLine(); + + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + + void SetFirstLinePointId(quint32 value); + void SetSecondLinePointId(quint32 value); + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ToolFlippingByLine)}; +private: + Q_DISABLE_COPY(VisToolFlippingByLine) + quint32 object2Id; + QGraphicsEllipseItem *point1; + QGraphicsEllipseItem *point2; + + template + int AddCurve(const QPointF &firstPoint, const QPointF &secondPoint, quint32 id, int i); +}; + +#endif // VISTOOLFLIPPINGBYLINE_H diff --git a/src/libs/vtools/visualization/line/vistoolrotation.cpp b/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp similarity index 80% rename from src/libs/vtools/visualization/line/vistoolrotation.cpp rename to src/libs/vtools/visualization/line/operation/vistoolrotation.cpp index 2101cfb46..b2179db23 100644 --- a/src/libs/vtools/visualization/line/vistoolrotation.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp @@ -53,22 +53,17 @@ #include "../vmisc/vabstractapplication.h" #include "../vpatterndb/vcontainer.h" #include "../vwidgets/vmaingraphicsscene.h" -#include "../visualization.h" -#include "visline.h" +#include "visoperation.h" class QPointF; //--------------------------------------------------------------------------------------------------------------------- VisToolRotation::VisToolRotation(const VContainer *data, QGraphicsItem *parent) - : VisLine(data, parent), + : VisOperation(data, parent), angle(INT_MIN), - objects(), point(nullptr), angleArc(nullptr), - xAxis(nullptr), - supportColor2(Qt::darkGreen), - points(), - curves() + xAxis(nullptr) { point = InitPoint(supportColor2, this); angleArc = InitItem(supportColor2, this); @@ -78,8 +73,6 @@ VisToolRotation::VisToolRotation(const VContainer *data, QGraphicsItem *parent) //--------------------------------------------------------------------------------------------------------------------- VisToolRotation::~VisToolRotation() { - qDeleteAll(points); - qDeleteAll(curves); } //--------------------------------------------------------------------------------------------------------------------- @@ -198,12 +191,6 @@ void VisToolRotation::RefreshGeometry() QT_WARNING_POP -//--------------------------------------------------------------------------------------------------------------------- -void VisToolRotation::SetObjects(QVector objects) -{ - this->objects = objects; -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolRotation::SetOriginPointId(quint32 value) { @@ -222,51 +209,6 @@ void VisToolRotation::SetAngle(const QString &expression) angle = FindVal(expression, Visualization::data->PlainVariables()); } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolRotation::VisualMode(const quint32 &pointId) -{ - Q_UNUSED(pointId); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr); - - Visualization::scenePos = scene->getScenePos(); - RefreshGeometry(); - - AddOnScene(); -} - -//--------------------------------------------------------------------------------------------------------------------- -QGraphicsEllipseItem *VisToolRotation::GetPoint(quint32 i, const QColor &color) -{ - if (not points.isEmpty() && static_cast(points.size() - 1) >= i) - { - return points.at(static_cast(i)); - } - else - { - auto point = InitPoint(color, this); - points.append(point); - return point; - } - return nullptr; -} - -//--------------------------------------------------------------------------------------------------------------------- -QGraphicsPathItem *VisToolRotation::GetCurve(quint32 i, const QColor &color) -{ - if (not curves.isEmpty() && static_cast(curves.size() - 1) >= i) - { - return curves.at(static_cast(i)); - } - else - { - auto curve = InitItem(color, this); - curves.append(curve); - return curve; - } - return nullptr; -} - //--------------------------------------------------------------------------------------------------------------------- template int VisToolRotation::AddCurve(qreal angle, const QPointF &origin, quint32 id, int i) diff --git a/src/libs/vtools/visualization/line/vistoolrotation.h b/src/libs/vtools/visualization/line/operation/vistoolrotation.h similarity index 82% rename from src/libs/vtools/visualization/line/vistoolrotation.h rename to src/libs/vtools/visualization/line/operation/vistoolrotation.h index 988fff1a7..2f262dcc2 100644 --- a/src/libs/vtools/visualization/line/vistoolrotation.h +++ b/src/libs/vtools/visualization/line/operation/vistoolrotation.h @@ -41,12 +41,12 @@ #include "../ifc/ifcdef.h" #include "../vmisc/def.h" -#include "visline.h" +#include "visoperation.h" class QPointF; class VContainer; -class VisToolRotation : public VisLine +class VisToolRotation : public VisOperation { Q_OBJECT public: @@ -55,30 +55,19 @@ public: virtual void RefreshGeometry() Q_DECL_OVERRIDE; - void SetObjects(QVector objects); void SetOriginPointId(quint32 value); QString Angle() const; void SetAngle(const QString &expression); - virtual void VisualMode(const quint32 &pointId = NULL_ID) Q_DECL_OVERRIDE; - virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolRotation)}; private: Q_DISABLE_COPY(VisToolRotation) qreal angle; - QVector objects; QGraphicsEllipseItem *point; QGraphicsPathItem *angleArc; QGraphicsLineItem *xAxis; - QColor supportColor2; - - QVector points; - QVector curves; - - QGraphicsEllipseItem * GetPoint(quint32 i, const QColor &color); - QGraphicsPathItem * GetCurve(quint32 i, const QColor &color); template int AddCurve(qreal angle, const QPointF &origin, quint32 id, int i); diff --git a/src/libs/vtools/visualization/visualization.pri b/src/libs/vtools/visualization/visualization.pri index fce6c442e..6de291625 100644 --- a/src/libs/vtools/visualization/visualization.pri +++ b/src/libs/vtools/visualization/visualization.pri @@ -22,6 +22,8 @@ HEADERS += \ $$PWD/line/vistoolpointofintersectioncircles.h \ $$PWD/line/vistoolpointfromcircleandtangent.h \ $$PWD/line/vistoolpointfromarcandtangent.h \ + $$PWD/line/operation/vistoolrotation.h \ + $$PWD/line/operation/vistoolflippingbyline.h \ $$PWD/path/vispath.h \ $$PWD/path/vistoolarc.h \ $$PWD/path/vistoolcutarc.h \ @@ -33,7 +35,7 @@ HEADERS += \ $$PWD/path/vistoolpointofintersectioncurves.h \ $$PWD/path/vistoolcubicbezier.h \ $$PWD/path/vistoolcubicbezierpath.h \ - visualization/line/vistoolrotation.h + $$PWD/line/operation/visoperation.h SOURCES += \ $$PWD/visualization.cpp \ @@ -56,6 +58,8 @@ SOURCES += \ $$PWD/line/vistoolpointofintersectioncircles.cpp \ $$PWD/line/vistoolpointfromcircleandtangent.cpp \ $$PWD/line/vistoolpointfromarcandtangent.cpp \ + $$PWD/line/operation/vistoolrotation.cpp \ + $$PWD/line/operation/vistoolflippingbyline.cpp \ $$PWD/path/vispath.cpp \ $$PWD/path/vistoolarc.cpp \ $$PWD/path/vistoolcutarc.cpp \ @@ -67,4 +71,4 @@ SOURCES += \ $$PWD/path/vistoolpointofintersectioncurves.cpp \ $$PWD/path/vistoolcubicbezier.cpp \ $$PWD/path/vistoolcubicbezierpath.cpp \ - visualization/line/vistoolrotation.cpp + $$PWD/line/operation/visoperation.cpp From bfde34c8823961b8a42367c910933d3528dc3848 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 13 Sep 2016 11:47:33 +0300 Subject: [PATCH 5/8] Rename RotationMoveLabel class. --HG-- branch : feature --- .../drawTools/operation/vabstractoperation.cpp | 6 +++--- ...ionmovelabel.cpp => operationmovelabel.cpp} | 18 +++++++++--------- ...otationmovelabel.h => operationmovelabel.h} | 18 +++++++++--------- src/libs/vtools/undocommands/undocommands.pri | 8 ++++---- 4 files changed, 25 insertions(+), 25 deletions(-) rename src/libs/vtools/undocommands/label/{rotationmovelabel.cpp => operationmovelabel.cpp} (89%) rename src/libs/vtools/undocommands/label/{rotationmovelabel.h => operationmovelabel.h} (83%) diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp index 0a032c3a8..6396bfe0b 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -27,7 +27,7 @@ *************************************************************************/ #include "vabstractoperation.h" -#include "../../../undocommands/label/rotationmovelabel.h" +#include "../../../undocommands/label/operationmovelabel.h" #include "../vgeometry/vpointf.h" const QString VAbstractOperation::TagItem = QStringLiteral("item"); @@ -419,8 +419,8 @@ void VAbstractOperation::RefreshDataInFile() void VAbstractOperation::UpdateNamePosition(quint32 id) { const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - auto moveLabel = new RotationMoveLabel(this->id, doc, point->mx(), point->my(), id); - connect(moveLabel, &RotationMoveLabel::ChangePosition, this, &VAbstractOperation::DoChangePosition); + auto moveLabel = new OperationMoveLabel(this->id, doc, point->mx(), point->my(), id); + connect(moveLabel, &OperationMoveLabel::ChangePosition, this, &VAbstractOperation::DoChangePosition); qApp->getUndoStack()->push(moveLabel); } diff --git a/src/libs/vtools/undocommands/label/rotationmovelabel.cpp b/src/libs/vtools/undocommands/label/operationmovelabel.cpp similarity index 89% rename from src/libs/vtools/undocommands/label/rotationmovelabel.cpp rename to src/libs/vtools/undocommands/label/operationmovelabel.cpp index 89b2994e8..d83066110 100644 --- a/src/libs/vtools/undocommands/label/rotationmovelabel.cpp +++ b/src/libs/vtools/undocommands/label/operationmovelabel.cpp @@ -26,7 +26,7 @@ ** *************************************************************************/ -#include "rotationmovelabel.h" +#include "operationmovelabel.h" #include #include @@ -43,8 +43,8 @@ class QUndoCommand; //--------------------------------------------------------------------------------------------------------------------- -RotationMoveLabel::RotationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint, - QUndoCommand *parent) +OperationMoveLabel::OperationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint, + QUndoCommand *parent) : MoveAbstractLabel(doc, idPoint, x, y, parent), m_idTool(idTool) { @@ -69,14 +69,14 @@ RotationMoveLabel::RotationMoveLabel(quint32 idTool, VAbstractPattern *doc, doub } //--------------------------------------------------------------------------------------------------------------------- -RotationMoveLabel::~RotationMoveLabel() +OperationMoveLabel::~OperationMoveLabel() { } //--------------------------------------------------------------------------------------------------------------------- -bool RotationMoveLabel::mergeWith(const QUndoCommand *command) +bool OperationMoveLabel::mergeWith(const QUndoCommand *command) { - const RotationMoveLabel *moveCommand = static_cast(command); + const OperationMoveLabel *moveCommand = static_cast(command); SCASSERT(moveCommand != nullptr); if (moveCommand->GetToolId() != m_idTool && moveCommand->GetPointId() != nodeId) @@ -93,13 +93,13 @@ bool RotationMoveLabel::mergeWith(const QUndoCommand *command) } //--------------------------------------------------------------------------------------------------------------------- -int RotationMoveLabel::id() const +int OperationMoveLabel::id() const { return static_cast(UndoCommand::RotationMoveLabel); } //--------------------------------------------------------------------------------------------------------------------- -void RotationMoveLabel::Do(double mx, double my) +void OperationMoveLabel::Do(double mx, double my) { qCDebug(vUndo, "New mx %f", mx); qCDebug(vUndo, "New my %f", my); @@ -118,7 +118,7 @@ void RotationMoveLabel::Do(double mx, double my) } //--------------------------------------------------------------------------------------------------------------------- -QDomElement RotationMoveLabel::GetDestinationObject(quint32 idTool, quint32 idPoint) const +QDomElement OperationMoveLabel::GetDestinationObject(quint32 idTool, quint32 idPoint) const { const QDomElement tool = doc->elementById(idTool); if (tool.isElement()) diff --git a/src/libs/vtools/undocommands/label/rotationmovelabel.h b/src/libs/vtools/undocommands/label/operationmovelabel.h similarity index 83% rename from src/libs/vtools/undocommands/label/rotationmovelabel.h rename to src/libs/vtools/undocommands/label/operationmovelabel.h index 5308ddd02..b88f57f5b 100644 --- a/src/libs/vtools/undocommands/label/rotationmovelabel.h +++ b/src/libs/vtools/undocommands/label/operationmovelabel.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file moverotationlabel.h + ** @file operationmovelabel.h ** @author Roman Telezhynskyi ** @date 13 5, 2016 ** @@ -26,8 +26,8 @@ ** *************************************************************************/ -#ifndef ROTATIONMOVELABEL_H -#define ROTATIONMOVELABEL_H +#ifndef OPERATIONMOVELABEL_H +#define OPERATIONMOVELABEL_H #include #include @@ -42,13 +42,13 @@ class QDomElement; class QUndoCommand; class VAbstractPattern; -class RotationMoveLabel : public MoveAbstractLabel +class OperationMoveLabel : public MoveAbstractLabel { Q_OBJECT public: - RotationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint, + OperationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint, QUndoCommand *parent = nullptr); - virtual ~RotationMoveLabel(); + virtual ~OperationMoveLabel(); virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE; virtual int id() const Q_DECL_OVERRIDE; @@ -57,16 +57,16 @@ public: protected: virtual void Do(double mx, double my) Q_DECL_OVERRIDE; private: - Q_DISABLE_COPY(RotationMoveLabel) + Q_DISABLE_COPY(OperationMoveLabel) quint32 m_idTool; QDomElement GetDestinationObject(quint32 idTool, quint32 idPoint) const; }; //--------------------------------------------------------------------------------------------------------------------- -inline quint32 RotationMoveLabel::GetToolId() const +inline quint32 OperationMoveLabel::GetToolId() const { return m_idTool; } -#endif // ROTATIONMOVELABEL_H +#endif // OPERATIONMOVELABEL_H diff --git a/src/libs/vtools/undocommands/undocommands.pri b/src/libs/vtools/undocommands/undocommands.pri index 39a455dc1..216944bb2 100644 --- a/src/libs/vtools/undocommands/undocommands.pri +++ b/src/libs/vtools/undocommands/undocommands.pri @@ -21,9 +21,9 @@ HEADERS += \ $$PWD/label/movedoublelabel.h \ $$PWD/addgroup.h \ $$PWD/delgroup.h \ - $$PWD/label/rotationmovelabel.h \ $$PWD/label/moveabstractlabel.h \ - $$PWD/toggledetailinlayout.h + $$PWD/toggledetailinlayout.h \ + $$PWD/label/operationmovelabel.h SOURCES += \ $$PWD/addtocalc.cpp \ @@ -45,6 +45,6 @@ SOURCES += \ $$PWD/label/movedoublelabel.cpp \ $$PWD/addgroup.cpp \ $$PWD/delgroup.cpp \ - $$PWD/label/rotationmovelabel.cpp \ $$PWD/label/moveabstractlabel.cpp \ - $$PWD/toggledetailinlayout.cpp + $$PWD/toggledetailinlayout.cpp \ + $$PWD/label/operationmovelabel.cpp From 91c614a2b8c210b1e16354e1f1ac81adf08456de Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 16 Sep 2016 11:03:51 +0300 Subject: [PATCH 6/8] Fix broken build. --HG-- branch : feature --- .../tools/drawTools/operation/flipping/vtoolflippingbyline.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp index 7f097942e..1f22e274d 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp @@ -44,7 +44,7 @@ #include "../../../../dialogs/tools/dialogtool.h" #include "../../../../dialogs/tools/dialogflippingbyline.h" -#include "../../../../undocommands/label/rotationmovelabel.h" +#include "../../../../undocommands/label/operationmovelabel.h" #include "../../../../visualization/line/operation/vistoolflippingbyline.h" #include "../../../../visualization/visualization.h" #include "../vgeometry/vabstractcurve.h" From 74bc4179efa7a5d7570fd2a0e3a15feaed324769 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 17 Sep 2016 12:10:03 +0300 Subject: [PATCH 7/8] New tool Flipping by axis. --HG-- branch : feature --- .../core/vtooloptionspropertybrowser.cpp | 88 ++++- .../core/vtooloptionspropertybrowser.h | 9 + src/app/valentina/dialogs/dialoghistory.cpp | 3 +- src/app/valentina/mainwindow.cpp | 27 +- src/app/valentina/mainwindow.h | 1 + src/app/valentina/mainwindow.ui | 155 +++++---- src/app/valentina/share/resources/cursor.qrc | 2 + .../resources/cursor/flipping_axis_cursor.png | Bin 0 -> 700 bytes .../cursor/flipping_axis_cursor@2x.png | Bin 0 -> 1610 bytes .../valentina/share/resources/toolicon.qrc | 2 + .../toolicon/32x32/flipping_axis.png | Bin 0 -> 1050 bytes .../toolicon/32x32/flipping_axis@2x.png | Bin 0 -> 2310 bytes .../resources/toolicon/svg/flipping_axis.svg | 85 +++++ src/app/valentina/xml/vpattern.cpp | 41 ++- src/app/valentina/xml/vpattern.h | 1 + src/libs/ifc/ifcdef.cpp | 1 + src/libs/ifc/ifcdef.h | 1 + src/libs/ifc/schema/pattern/v0.3.5.xsd | 9 +- src/libs/ifc/xml/vabstractpattern.cpp | 8 +- src/libs/ifc/xml/vabstractpattern.h | 1 + src/libs/vmisc/def.h | 4 +- src/libs/vtools/dialogs/dialogs.pri | 9 +- src/libs/vtools/dialogs/tooldialogs.h | 1 + .../dialogs/tools/dialogflippingbyaxis.cpp | 325 ++++++++++++++++++ .../dialogs/tools/dialogflippingbyaxis.h | 104 ++++++ .../dialogs/tools/dialogflippingbyaxis.ui | 98 ++++++ .../dialogs/tools/dialogflippingbyline.cpp | 3 + .../dialogs/tools/dialogflippingbyline.ui | 8 +- src/libs/vtools/tools/drawTools/drawtools.h | 1 + .../operation/flipping/vabstractflipping.cpp | 195 +++++++++++ .../operation/flipping/vabstractflipping.h | 151 ++++++++ .../flipping/vtoolflippingbyaxis.cpp | 248 +++++++++++++ .../operation/flipping/vtoolflippingbyaxis.h | 77 +++++ .../flipping/vtoolflippingbyline.cpp | 215 +----------- .../operation/flipping/vtoolflippingbyline.h | 34 +- src/libs/vtools/tools/tools.pri | 8 +- .../line/operation/visoperation.cpp | 80 +++++ .../line/operation/visoperation.h | 26 ++ .../line/operation/vistoolflippingbyaxis.cpp | 87 +++++ .../line/operation/vistoolflippingbyaxis.h | 59 ++++ .../line/operation/vistoolflippingbyline.cpp | 97 +----- .../line/operation/vistoolflippingbyline.h | 3 - .../vtools/visualization/visualization.pri | 6 +- 43 files changed, 1840 insertions(+), 433 deletions(-) create mode 100644 src/app/valentina/share/resources/cursor/flipping_axis_cursor.png create mode 100644 src/app/valentina/share/resources/cursor/flipping_axis_cursor@2x.png create mode 100644 src/app/valentina/share/resources/toolicon/32x32/flipping_axis.png create mode 100644 src/app/valentina/share/resources/toolicon/32x32/flipping_axis@2x.png create mode 100644 src/app/valentina/share/resources/toolicon/svg/flipping_axis.svg create mode 100644 src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp create mode 100644 src/libs/vtools/dialogs/tools/dialogflippingbyaxis.h create mode 100644 src/libs/vtools/dialogs/tools/dialogflippingbyaxis.ui create mode 100644 src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp create mode 100644 src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h create mode 100644 src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp create mode 100644 src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.h create mode 100644 src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.cpp create mode 100644 src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.h diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 8c2bca58f..3d38dda94 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -75,7 +75,7 @@ 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) == 46, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools was used in switch."); switch (item->type()) { @@ -188,6 +188,9 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) case VToolFlippingByLine::Type: ShowOptionsToolFlippingByLine(item); break; + case VToolFlippingByAxis::Type: + ShowOptionsToolFlippingByAxis(item); + break; default: break; } @@ -202,7 +205,7 @@ void VToolOptionsPropertyBrowser::UpdateOptions() } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -305,6 +308,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions() case VToolFlippingByLine::Type: UpdateOptionsToolFlippingByLine(); break; + case VToolFlippingByAxis::Type: + UpdateOptionsToolFlippingByAxis(); + break; default: break; } @@ -340,7 +346,7 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -437,6 +443,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) case VToolFlippingByLine::Type: ChangeDataToolFlippingByLine(prop); break; + case VToolFlippingByAxis::Type: + ChangeDataToolFlippingByAxis(prop); + break; default: break; } @@ -565,6 +574,16 @@ void VToolOptionsPropertyBrowser::AddPropertyHCrossPoint(Tool *i, const QString AddProperty(itemProperty, AttrHCrossPoint); } +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyAxisType(Tool *i, const QString &propertyName) +{ + auto itemProperty = new VEnumProperty(propertyName); + itemProperty->setLiterals(QStringList()<< tr("Vertical axis") << tr("Horizontal axis")); + itemProperty->setValue(static_cast(i->GetAxisType())-1); + AddProperty(itemProperty, AttrAxisType); +} + //--------------------------------------------------------------------------------------------------------------------- template void VToolOptionsPropertyBrowser::AddPropertyLineType(Tool *i, const QString &propertyName, @@ -781,6 +800,20 @@ void VToolOptionsPropertyBrowser::SetHCrossCurvesPoint(const QVariant &value) } } +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::SetAxisType(const QVariant &value) +{ + if (auto i = qgraphicsitem_cast(currentItem)) + { + i->SetAxisType(GetCrossPoint(value)); + } + else + { + qWarning()<<"Can't cast item"; + } +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::AddProperty(VProperty *property, const QString &id) { @@ -1631,6 +1664,33 @@ void VToolOptionsPropertyBrowser::ChangeDataToolFlippingByLine(VProperty *proper } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolFlippingByAxis(VProperty *property) +{ + SCASSERT(property != nullptr) + + QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolFlippingByAxis *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 39: // AttrAxisType + { + const QVariant value = property->data(VProperty::DPC_Data, Qt::EditRole); + SetAxisType(value); + break; + } + case 38: // AttrSuffix + SetOperationSuffix(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<(item); + i->ShowVisualization(true); + formView->setTitle(tr("Tool flipping by axis")); + + AddPropertyAxisType(i, tr("Axis type")); + AddPropertyOperationSuffix(i, tr("Suffix")); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolSinglePoint() { @@ -2498,6 +2569,14 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolFlippingByLine() idToProperty[AttrSuffix]->setValue(i->Suffix()); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolFlippingByAxis() +{ + VToolFlippingByAxis *i = qgraphicsitem_cast(currentItem); + idToProperty[AttrAxisType]->setValue(static_cast(i->GetAxisType())-1); + idToProperty[AttrSuffix]->setValue(i->Suffix()); +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VToolOptionsPropertyBrowser::PropertiesList() const { @@ -2539,6 +2618,7 @@ QStringList VToolOptionsPropertyBrowser::PropertiesList() const << AttrHCrossPoint /* 35 */ << AttrLength1 /* 36 */ << AttrLength2 /* 37 */ - << AttrSuffix; /* 38 */ + << AttrSuffix /* 38 */ + << AttrAxisType; /* 39 */ return attr; } diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.h b/src/app/valentina/core/vtooloptionspropertybrowser.h index 5c521ab47..f23185bd2 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.h +++ b/src/app/valentina/core/vtooloptionspropertybrowser.h @@ -90,6 +90,9 @@ private: template void SetHCrossCurvesPoint(const QVariant &value); + template + void SetAxisType(const QVariant &value); + template void AddPropertyObjectName(Tool *i, const QString &propertyName, bool readOnly = false); @@ -111,6 +114,9 @@ private: template void AddPropertyHCrossPoint(Tool *i, const QString &propertyName); + template + void AddPropertyAxisType(Tool *i, const QString &propertyName); + template void AddPropertyLineType(Tool *i, const QString &propertyName, const QMap &styles); @@ -153,6 +159,7 @@ private: void ChangeDataToolCurveIntersectAxis(VPE::VProperty *property); void ChangeDataToolRotation(VPE::VProperty *property); void ChangeDataToolFlippingByLine(VPE::VProperty *property); + void ChangeDataToolFlippingByAxis(VPE::VProperty *property); void ShowOptionsToolSinglePoint(QGraphicsItem *item); void ShowOptionsToolEndLine(QGraphicsItem *item); @@ -185,6 +192,7 @@ private: void ShowOptionsToolCurveIntersectAxis(QGraphicsItem *item); void ShowOptionsToolRotation(QGraphicsItem *item); void ShowOptionsToolFlippingByLine(QGraphicsItem *item); + void ShowOptionsToolFlippingByAxis(QGraphicsItem *item); void UpdateOptionsToolSinglePoint(); void UpdateOptionsToolEndLine(); @@ -217,6 +225,7 @@ private: void UpdateOptionsToolCurveIntersectAxis(); void UpdateOptionsToolRotation(); void UpdateOptionsToolFlippingByLine(); + void UpdateOptionsToolFlippingByAxis(); }; #endif // VTOOLOPTIONSPROPERTYBROWSER_H diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index 2d5ac5ab9..c73d7fb19 100644 --- a/src/app/valentina/dialogs/dialoghistory.cpp +++ b/src/app/valentina/dialogs/dialoghistory.cpp @@ -207,7 +207,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") 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) == 46, "Not all tools was used in history."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools was used in history."); const QDomElement domElem = doc->elementById(tool.getId()); if (domElem.isElement() == false) @@ -388,6 +388,7 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::Group: case Tool::Rotation: case Tool::FlippingByLine: + case Tool::FlippingByAxis: return QString(); } } diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 1618916c8..3f0b08067 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1044,6 +1044,17 @@ void MainWindow::ToolFlippingByLine(bool checked) &MainWindow::ApplyDialog); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolFlippingByAxis(bool checked) +{ + ToolSelectOperationObjects(); + SetToolButtonWithApply(checked, Tool::FlippingByAxis, + ":/cursor/flipping_axis_cursor.png", + tr("Select one or more objects, Enter - confirm selection"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ClosedDialogGroup(int result) { @@ -1714,6 +1725,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonGroup, &QToolButton::clicked, this, &MainWindow::ToolGroup); connect(ui->toolButtonRotation, &QToolButton::clicked, this, &MainWindow::ToolRotation); connect(ui->toolButtonFlippingByLine, &QToolButton::clicked, this, &MainWindow::ToolFlippingByLine); + connect(ui->toolButtonFlippingByAxis, &QToolButton::clicked, this, &MainWindow::ToolFlippingByAxis); connect(ui->toolButtonMidpoint, &QToolButton::clicked, this, &MainWindow::ToolMidpoint); connect(ui->toolButtonLayoutExportAs, &QToolButton::clicked, this, &MainWindow::ExportLayoutAs); } @@ -1743,7 +1755,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") 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) == 46, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools was handled."); qCDebug(vMainWindow, "Canceling tool."); delete dialogTool; @@ -1886,6 +1898,9 @@ void MainWindow::CancelTool() case Tool::FlippingByLine: ui->toolButtonFlippingByLine->setChecked(false); break; + case Tool::FlippingByAxis: + ui->toolButtonFlippingByAxis->setChecked(false); + break; } // Crash: using CRTL+Z while using line tool. @@ -2934,6 +2949,9 @@ void MainWindow::SetEnableTool(bool enable) break; } + // This check helps to find missed tools + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools were handled."); + //Drawing Tools ui->toolButtonEndLine->setEnabled(drawTools); ui->toolButtonLine->setEnabled(drawTools); @@ -2968,6 +2986,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonGroup->setEnabled(drawTools); ui->toolButtonRotation->setEnabled(drawTools); ui->toolButtonFlippingByLine->setEnabled(drawTools); + ui->toolButtonFlippingByAxis->setEnabled(drawTools); ui->toolButtonMidpoint->setEnabled(drawTools); ui->actionLast_tool->setEnabled(drawTools); @@ -3250,7 +3269,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") 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) == 46, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools was handled."); if (currentTool == lastUsedTool) { @@ -3420,6 +3439,10 @@ void MainWindow::LastUsedTool() ui->toolButtonFlippingByLine->setChecked(true); ToolFlippingByLine(true); break; + case Tool::FlippingByAxis: + ui->toolButtonFlippingByAxis->setChecked(true); + ToolFlippingByAxis(true); + break; } } diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 1bb634d1e..3361c8ecd 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -140,6 +140,7 @@ private slots: void ToolGroup(bool checked); void ToolRotation(bool checked); void ToolFlippingByLine(bool checked); + void ToolFlippingByAxis(bool checked); void ToolCutArc(bool checked); void ToolLineIntersectAxis(bool checked); void ToolCurveIntersectAxis(bool checked); diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index 295cb3186..aa0b01eed 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -14,7 +14,7 @@ Valentina - + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png @@ -69,7 +69,7 @@ Tools for creating points. - + :/icon/16x16/toolsectionpoint.png:/icon/16x16/toolsectionpoint.png @@ -94,7 +94,7 @@ ... - + :/toolicon/32x32/along_line.png:/toolicon/32x32/along_line.png @@ -120,7 +120,7 @@ ... - + :/toolicon/32x32/normal.png:/toolicon/32x32/normal.png @@ -146,7 +146,7 @@ ... - + :/toolicon/32x32/bisector.png:/toolicon/32x32/bisector.png @@ -172,7 +172,7 @@ ... - + :/toolicon/32x32/shoulder.png:/toolicon/32x32/shoulder.png @@ -198,7 +198,7 @@ ... - + :/toolicon/32x32/point_of_contact.png:/toolicon/32x32/point_of_contact.png @@ -224,7 +224,7 @@ ... - + :/toolicon/32x32/triangle.png:/toolicon/32x32/triangle.png @@ -250,7 +250,7 @@ ... - + :/toolicon/32x32/point_of_intersection.png:/toolicon/32x32/point_of_intersection.png @@ -276,7 +276,7 @@ ... - + :/toolicon/32x32/height.png:/toolicon/32x32/height.png @@ -302,7 +302,7 @@ ... - + :/toolicon/32x32/line_intersect_axis.png:/toolicon/32x32/line_intersect_axis.png @@ -328,7 +328,7 @@ ... - + :/toolicon/32x32/true_darts.png:/toolicon/32x32/true_darts.png @@ -354,7 +354,7 @@ ... - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -380,7 +380,7 @@ ... - + :/toolicon/32x32/midpoint.png:/toolicon/32x32/midpoint.png @@ -406,7 +406,7 @@ ... - + :/toolicon/32x32/segment.png:/toolicon/32x32/segment.png @@ -441,7 +441,7 @@ Tools for creating lines. - + :/icon/16x16/toolsectionline.png:/icon/16x16/toolsectionline.png @@ -463,7 +463,7 @@ ... - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -489,7 +489,7 @@ ... - + :/toolicon/32x32/line.png:/toolicon/32x32/line.png @@ -515,7 +515,7 @@ ... - + :/toolicon/32x32/intersect.png:/toolicon/32x32/intersect.png @@ -550,7 +550,7 @@ Tools for creating curves. - + :/icon/16x16/toolsectioncurve.png:/icon/16x16/toolsectioncurve.png @@ -572,7 +572,7 @@ ... - + :/toolicon/32x32/spline_cut_point.png:/toolicon/32x32/spline_cut_point.png @@ -598,7 +598,7 @@ ... - + :/toolicon/32x32/cubic_bezier.png:/toolicon/32x32/cubic_bezier.png @@ -624,7 +624,7 @@ ... - + :/toolicon/32x32/splinePath.png:/toolicon/32x32/splinePath.png @@ -650,7 +650,7 @@ ... - + :/toolicon/32x32/splinePath_cut_point.png:/toolicon/32x32/splinePath_cut_point.png @@ -673,7 +673,7 @@ ... - + :/toolicon/32x32/cubic_bezier_path.png:/toolicon/32x32/cubic_bezier_path.png @@ -699,7 +699,7 @@ ... - + :/toolicon/32x32/intersection_curves.png:/toolicon/32x32/intersection_curves.png @@ -725,7 +725,7 @@ ... - + :/toolicon/32x32/curve_intersect_axis.png:/toolicon/32x32/curve_intersect_axis.png @@ -751,7 +751,7 @@ ... - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -777,7 +777,7 @@ ... - + :/toolicon/32x32/spline.png:/toolicon/32x32/spline.png @@ -812,7 +812,7 @@ Tools for creating arcs. - + :/icon/16x16/toolsectionarc.png:/icon/16x16/toolsectionarc.png @@ -834,7 +834,7 @@ ... - + :/toolicon/32x32/arc.png:/toolicon/32x32/arc.png @@ -860,7 +860,7 @@ ... - + :/toolicon/32x32/arc_cut.png:/toolicon/32x32/arc_cut.png @@ -886,7 +886,7 @@ ... - + :/toolicon/32x32/arc_intersect_axis.png:/toolicon/32x32/arc_intersect_axis.png @@ -912,7 +912,7 @@ ... - + :/toolicon/32x32/point_of_intersection_arcs.png:/toolicon/32x32/point_of_intersection_arcs.png @@ -938,7 +938,7 @@ ... - + :/toolicon/32x32/point_of_intersection_circles.png:/toolicon/32x32/point_of_intersection_circles.png @@ -964,7 +964,7 @@ ... - + :/toolicon/32x32/point_from_circle_and_tangent.png:/toolicon/32x32/point_from_circle_and_tangent.png @@ -990,7 +990,7 @@ ... - + :/toolicon/32x32/point_from_arc_and_tangent.png:/toolicon/32x32/point_from_arc_and_tangent.png @@ -1016,7 +1016,7 @@ ... - + :/toolicon/32x32/arc_with_length.png:/toolicon/32x32/arc_with_length.png @@ -1042,7 +1042,7 @@ ... - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -1068,7 +1068,7 @@ - + :/icon/16x16/operations.png:/icon/16x16/operations.png @@ -1090,7 +1090,7 @@ ... - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -1116,7 +1116,7 @@ ... - + :/toolicon/32x32/group_plus.png:/toolicon/32x32/group_plus.png @@ -1142,7 +1142,7 @@ ... - + :/toolicon/32x32/rotation.png:/toolicon/32x32/rotation.png @@ -1165,10 +1165,10 @@ Flipping objects by line - ... + ... - + :/toolicon/32x32/flipping_line.png:/toolicon/32x32/flipping_line.png @@ -1182,6 +1182,32 @@ + + + + false + + + Flipping objects by axis + + + ... + + + + :/toolicon/32x32/flipping_axis.png:/toolicon/32x32/flipping_axis.png + + + + 32 + 32 + + + + true + + + @@ -1203,7 +1229,7 @@ Tools for creating details. - + :/icon/16x16/toolsectiondetail.png:/icon/16x16/toolsectiondetail.png @@ -1225,7 +1251,7 @@ ... - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -1251,7 +1277,7 @@ ... - + :/toolicon/32x32/new_detail.png:/toolicon/32x32/new_detail.png @@ -1277,7 +1303,7 @@ ... - + :/toolicon/32x32/union.png:/toolicon/32x32/union.png @@ -1303,7 +1329,7 @@ - + :/icon/16x16/toolsectionlayout.png:/icon/16x16/toolsectionlayout.png @@ -1354,7 +1380,7 @@ ... - + :/icon/32x32/export_to_picture_document.png:/icon/32x32/export_to_picture_document.png @@ -1800,7 +1826,7 @@ false - + :/icon/32x32/draw.png:/icon/32x32/draw.png @@ -1824,7 +1850,7 @@ false - + :/icon/32x32/kontur.png:/icon/32x32/kontur.png @@ -1848,7 +1874,7 @@ true - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -1866,7 +1892,7 @@ false - + :/icon/32x32/new_draw.png:/icon/32x32/new_draw.png @@ -1887,7 +1913,7 @@ false - + :/icon/32x32/option_draw.png:/icon/32x32/option_draw.png @@ -1911,7 +1937,7 @@ false - + :/icon/32x32/table.png:/icon/32x32/table.png @@ -1935,7 +1961,7 @@ false - + :/icon/32x32/history.png:/icon/32x32/history.png @@ -1956,7 +1982,7 @@ false - + :/icon/32x32/layout.png:/icon/32x32/layout.png @@ -2221,7 +2247,7 @@ false - + :/icon/32x32/pdf.png:/icon/32x32/pdf.png @@ -2311,7 +2337,7 @@ false - + :/icon/32x32/export_to_picture_document.png:/icon/32x32/export_to_picture_document.png @@ -2388,7 +2414,7 @@ false - + :/icon/32x32/syncM.png:/icon/32x32/syncM.png @@ -2427,9 +2453,6 @@
vmaingraphicsview.h
- - - - + diff --git a/src/app/valentina/share/resources/cursor.qrc b/src/app/valentina/share/resources/cursor.qrc index cb10b4aef..0e75306b5 100644 --- a/src/app/valentina/share/resources/cursor.qrc +++ b/src/app/valentina/share/resources/cursor.qrc @@ -72,5 +72,7 @@ cursor/midpoint_cursor@2x.png cursor/flipping_line_cursor@2x.png cursor/flipping_line_cursor.png + cursor/flipping_axis_cursor.png + cursor/flipping_axis_cursor@2x.png diff --git a/src/app/valentina/share/resources/cursor/flipping_axis_cursor.png b/src/app/valentina/share/resources/cursor/flipping_axis_cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..fb31228bff515a7575181182e564929527470163 GIT binary patch literal 700 zcmV;t0z>_YP)B-EU?=NClA)xMg@HjqM5K!})6(y>INzWQ+RWIDv+0F_?*iw2 z&hMNvGyJdV`h?C}0s=;BiAXcV2#(YeP&33#Kur)+1%L%d%m!Fc#9V*{Lrne!upo$H zfT|-(0aO+7yF@_M5aj@>f+!bIam25A04j=@FJLZ23l^g#P#3hXt|p)mQHM9!hl@jY zv<2V12`Efcz4S;jS3tXc^66GdAFf zxE!Z&e8A81@%7?ilD8~7G#h{z`&FD1{~wfFr_m>FxE!wGdZ(t#2#h4SMXqNyzz1Bw zCG$Iy4d}+5>^{LqY`miN{q&g44@q|goy!XWTX1t8jq}wmPGTUt&xxm?x6z_BJ{nIF zkH$$JGtpHD_}A*e?W`#=fq;%|BLyas%yye_rjmdqIEelk&+-X;Ymy7`6trc4H7~I$ z*uSz;fZcd1ZsPoy`2@bFeq`%Ek_!&k^R5nkq{r$j1XwF3@HzwJumV4^?u%cOt(vC@ iuNa+TX-cRk-1`H9j;H(?UT(ZA@r`Qg5vlYtZ6_ zOCuLeYA_*E`{aWrCdLO}d@-WNTTIl%Cv2h*YHEcV4KV_Of{0BC!DtgxluD#npxE1V zE@%1hUwh8(>6y;;%Q<*7~mh|G)lg?R_|}^E$8dI#Z9}&$w)%E3!~Z zd3)Ltg^()S0laQut26&XX6@-}rSTqn$nmK?)0pWz%0qA)Ma{-{I zAsjb10D2a}F>?o?Cn3x=fS!Z!KXVVDry#tlI{E0PU^$;Nw< zjW;HWUIj22gl~%nxI6OxAMqdtlXqT|Y&w~2dNA2AIF-gWIvh(=xvz5^K1ly{lij=*0E~*2>g(}F zJTK~4y1--j6GpNHBpk*mnztrf`_8^)OLOT0zruxD0cx(cei8USC1C8%<&_oYzw)uNo?pe+1$@~GhHyXWa?&|-g4qIS z;&b?nc(tY*Dn##JfS-uR_hs4eW&x-#8lUpBy+MCWen{kTdr{u!-0H$`If zGwi{dd_0i~E^d-`VE{WPa)X%w_&ct{6VqwM47Cim3ZK4D1i`Y-7vL-Sp2!3C{J@bb zwDJIWh~nSa%;r^{3Ye}7Jd7=PcAD4CRO@jY{(|4-V`ZJM7HM$5NRHO;cJwA;0S$%< z_C1TAVhv*-=v2UTEa1nuNi3Pomu|!rxL-W8q}978^H!?4LXn?oG>Uv;le9OkZQPM; zUC~~^Q~`WbOgo1={MIck6TRQW1C@F;^7n)Ip$Nvq*tgy4hbfv715Rg9qkknmN!rS> zwe5vW<^scF2>OE7urps;i+2h0KTtVd*7+p9gb(8u+_1x?M@T8oxhh-1Q%7msD=g^~ z?S-7n0*>RO_|a@zGDB?@f$rBL_?4;-gH3!MU&P9s2_}lRh(G!$j#F%FPmMbP_`Qhq z*XP0)LaW8h?~n*$RaK|G#87w%3QlJzsnK!)*nddO8Q#W;YdhVns=LL!`>9zqVRm{e z-XT_co@@K9ng_rO_)lv;<=NrzIDi}s@5`6noGR_E<9fh=h&uzg*V%!$-2!%q$lh}@bfW|%k)v~Oy0Aydb7Hy58Fi2vv-1X+FfAO z_)N6w0%INA;FZ6T{)vr@Y^dI>F1ivM#3=Om1m_f5%jd*e#MiV|g>x!=Ne2M`7{+hK zLh3f^1)#vkg%#`)?=z9i5I~ma z{l5I$%OU|HCQ7StisdOLKgH{DIYuc)DaJ5D%AcN#@5KxM2Yt=3Lg+^MV*mgE07*qo IM6N<$f`>}@Z~y=R literal 0 HcmV?d00001 diff --git a/src/app/valentina/share/resources/toolicon.qrc b/src/app/valentina/share/resources/toolicon.qrc index 6cc54ff41..a81206cb6 100644 --- a/src/app/valentina/share/resources/toolicon.qrc +++ b/src/app/valentina/share/resources/toolicon.qrc @@ -70,5 +70,7 @@ toolicon/32x32/midpoint@2x.png toolicon/32x32/flipping_line@2x.png toolicon/32x32/flipping_line.png + toolicon/32x32/flipping_axis.png + toolicon/32x32/flipping_axis@2x.png diff --git a/src/app/valentina/share/resources/toolicon/32x32/flipping_axis.png b/src/app/valentina/share/resources/toolicon/32x32/flipping_axis.png new file mode 100644 index 0000000000000000000000000000000000000000..e712f780eec0c6cdb7593bf2521fb10b0cd82871 GIT binary patch literal 1050 zcmV+#1m*jQP)L(6uJQ{689fo&un`DxX_?6p7c)zcMV<*z((AJukdX)QMu1e zY{hO2%+_6B6pnw7g@Pt_ZKg5|dmT$pG%`+oyfF+Iiz|p_N`f&}# z)_wr0;m>Vn#6mNb0bLT0<&*={d1976YD;q+z&%(kzT@w8062jScnkZn4&S&Efyct)O*pF97AM_qKNZuL8gqVtDt7Nto#dulOxYOcC~{Ug^6dKm*%Tdrw7IeGTCi zypZ*iZmQz97*Fc$!IptsQw3Nn*7xsltOINhg=q1tJ7M9(Nqmi4`DsHpfHG04tM3GG z3ct+-s73&a+5;*#9L5$*_W`g*tcFQK7l6iIOi?@CN8mZ_w z!0C8W5~&^5=DJ^Wh<;1__@;fMQ#L-*Izi;<-yedC~kqJhUE+ z6SgMBt9q|;rYRmKo3g<{@peK`al zT1xM|J3h?r-I=qqyR-Y--#6LhH*@BkIeYfZ%$Yg!gTdiy;4i=d;Nu?pUBFk9=L3?c z>8;fC4rzKXYPu^1sOLa11RMf%@*MQEdC8)GK@v5+!o`agzLxWH>8iY{bTHsu( ze6FXBwtg!Q{VePELU`etHWZT>lmYG(<+y z`TZ!c*CuLu6F|qRIti0!DfYhBrm~&tCbe-J?#qMg?kRp)AxHAegyGe|kD4mx!ytyh zI!|2-LjXYgWcP)(hrmU^bDsJWz#LI`6`7~}6|*W#L(@9}%o02r^diNc=UdPfXx{@q zQ&8{ofct_g&MTn#zGhV%P&99x z2TPXKQLGGY8lcQI+cW@ePKIq6U^Z}T3Ek(;6$Vgc!{$~^cXp6w6==%w)W%=a(M342AC%^j1RSHsXMHVs?9}F*R^0 z@T}G52=3;l5}Mu-;LNNhdJn|=F*{9w7}WWSUH@pLbt<(V<^rKGk2jF(pbZ1awSR+0u5So@p6ozmiH9zDPK!Wq5N-Ni4f-`e7r59ep8y{6$n_cE zZs6O=<6GAS&s!0kdKfsC)v1d$OM5kScF?Z@`INnd6`~yY+EV z^cjSH3^0Nj|29$=4e@{~2%f3LNK*J@A)?;}fSXy7f}$q-b^`94_GV8zXe{YkehzZ8-b0$86LT3 zCbXr3CoMYjgyPwwz$0!O_1Pk&i%{19LsYxJPj31$->B$wIB8?^q$CetEJ9<! zNZt7!;EfW#SAeezo&-f60HCEV!NVZb0Pn)w_((BD{@kxjZu&L%0V^<(qr_9d$H-2T zN|!+wo%?}Ft75rk$pt0)6)IYUaon%^IPlLJa_yJdfm!RX!lcN*2wV;<$8}|CfI?jr zJO2gz-l>A1m>?uQuJ9jwm7yvWj)CpTQv|^?RPnLYy`XQ*%6grKZ>oy($Pf>>99U$P zj{%zt+D>aD%04AF1J5VVmp$~#WzfZ(Er5M_;zHA`&%)o43Y*e|wPj1zLhz~V~0FYam)Edo)+~$jRWBQIAW~@n#qRC67c@p;vNVNOB~-f519`=Q zwJfsgrNCuY`AzcM&N2)jF%s3-x14wgchB*DP46;a%Oauj>pz0oqK2Xc1IPmr9c%!_ zzBfQ`5!K!el22%dd>mcJ{f!PTd_!Ox*@5V{JR)i@gMwe46O3!R!?Kl6=yf<36F7po z%UcJ7SOscc=Ggs5z`8u4-wx6BvX##O(p5I%ZZ$*DLTaq}5J&{Zpf(B_xnUrMjsc$% zbw91sae>?h257bnx|ot-`%2AHCx;=0uExFTy%+Phm%6B%8}vcY>ka`>JbeHYZ=@K3 zsoU%}(g6Le{bh0+%mMuk0Sj`2R%FMkn(l8vecGyB3w#Z-FXcP- zYU=*B+!QSYLVew76z`(frzx~l(PhB-Rtrz!u@*uMun2R@tc$s9DIkYHGY?4cYv4bY z>~rA7t07a=m-0H_yMpxdA^b-w>1ZVV$TG*y^M(oBFs(i)qx*Qz^477b2e@^>lTB=0Q)2!vFmLBZm&tZrl` zME05AC`={kan*syx^)uI!JHbW{Bz*c%^mWS-+aQ({fh7!#(*|jxFn@FL2pxKGspIo zvDUf{CL_}(#yoWm_X30XU#EjBB8oG-ZQ`(}u4)MQ{&3wkwkyn?zc1k~MPrsy^T_;a zE?Mw&8kwul#^eyd{MRqtPsG3znAG~Kbu`l~o)0sA0xSn*8Au + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 46c7c42fc..c779f1896 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2574,6 +2574,36 @@ void VPattern::ParseToolFlippingByLine(VMainGraphicsScene *scene, QDomElement &d } } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParseToolFlippingByAxis(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse) +{ + SCASSERT(scene != nullptr); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + + try + { + quint32 id = NULL_ID; + + ToolsCommonAttributes(domElement, id); + const quint32 origin = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); + const auto axisType = static_cast(GetParametrUInt(domElement, AttrAxisType, "1")); + const QString suffix = GetParametrString(domElement, AttrSuffix, ""); + + QVector source; + QVector destination; + VAbstractOperation::ExtractData(this, domElement, source, destination); + + VToolFlippingByAxis::Create(id, origin, axisType, suffix, source, destination, scene, this, data, parse, + Source::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating operation of flipping by axis"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } +} + //--------------------------------------------------------------------------------------------------------------------- qreal VPattern::EvalFormula(VContainer *data, const QString &formula, bool *ok) const { @@ -2825,7 +2855,8 @@ void VPattern::ParseOperationElement(VMainGraphicsScene *scene, QDomElement &dom Q_ASSERT_X(not type.isEmpty(), Q_FUNC_INFO, "type of operation is empty"); const QStringList opers = QStringList() << VToolRotation::ToolType /*0*/ - << VToolFlippingByLine::ToolType; /*1*/ + << VToolFlippingByLine::ToolType /*1*/ + << VToolFlippingByAxis::ToolType; /*2*/ switch (opers.indexOf(type)) { @@ -2835,6 +2866,9 @@ void VPattern::ParseOperationElement(VMainGraphicsScene *scene, QDomElement &dom case 1: //VToolFlippingByLine::ToolType ParseToolFlippingByLine(scene, domElement, parse); break; + case 2: //VToolFlippingByAxis::ToolType + ParseToolFlippingByAxis(scene, domElement, parse); + break; default: VException e(tr("Unknown operation type '%1'.").arg(type)); throw e; @@ -3340,7 +3374,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") 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) == 46, "Not all tools was used."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools was used."); QRectF rec; @@ -3455,6 +3489,9 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::FlippingByLine: rec = ToolBoundingRect(rec, tool.getId()); break; + case Tool::FlippingByAxis: + rec = ToolBoundingRect(rec, tool.getId()); + break; //These tools are not accesseble in Draw mode, but still 'history' contains them. case Tool::Detail: case Tool::UnionDetails: diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 5ab917405..a67d9c76e 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -195,6 +195,7 @@ private: void ParseToolRotation(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParseToolFlippingByLine(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); + void ParseToolFlippingByAxis(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); qreal EvalFormula(VContainer *data, const QString &formula, bool *ok) const; diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index 59ef40b5d..5a47465c1 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -124,6 +124,7 @@ const QString AttrSecondArc = QStringLiteral("secondArc"); const QString AttrCrossPoint = QStringLiteral("crossPoint"); const QString AttrVCrossPoint = QStringLiteral("vCrossPoint"); const QString AttrHCrossPoint = QStringLiteral("hCrossPoint"); +const QString AttrAxisType = QStringLiteral("axisType"); const QString AttrC1Center = QStringLiteral("c1Center"); const QString AttrC2Center = QStringLiteral("c2Center"); const QString AttrC1Radius = QStringLiteral("c1Radius"); diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 750372b2e..900c31aa6 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -125,6 +125,7 @@ extern const QString AttrSecondArc; extern const QString AttrCrossPoint; extern const QString AttrVCrossPoint; extern const QString AttrHCrossPoint; +extern const QString AttrAxisType; extern const QString AttrC1Center; extern const QString AttrC2Center; extern const QString AttrC1Radius; diff --git a/src/libs/ifc/schema/pattern/v0.3.5.xsd b/src/libs/ifc/schema/pattern/v0.3.5.xsd index b54271a63..8499e9604 100644 --- a/src/libs/ifc/schema/pattern/v0.3.5.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.5.xsd @@ -211,6 +211,7 @@ + @@ -364,7 +365,7 @@ - + @@ -556,6 +557,12 @@ + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 4c0c34ed5..83b85ff4a 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -1372,7 +1372,7 @@ QStringList VAbstractPattern::ListPointExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47); QStringList expressions; const QDomNodeList list = elementsByTagName(TagPoint); @@ -1443,7 +1443,7 @@ QStringList VAbstractPattern::ListArcExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47); QStringList expressions; const QDomNodeList list = elementsByTagName(TagArc); @@ -1504,7 +1504,7 @@ QStringList VAbstractPattern::ListPathPointExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47); QStringList expressions; const QDomNodeList list = elementsByTagName(AttrPathPoint); @@ -1570,7 +1570,7 @@ QStringList VAbstractPattern::ListOperationExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47); QStringList expressions; const QDomNodeList list = elementsByTagName(TagOperation); diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 467eb6da5..d13d8f718 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -53,6 +53,7 @@ enum class LabelType : char {NewPatternPiece, NewLabel}; enum class CrossCirclesPoint : char {FirstPoint = 1, SecondPoint = 2}; enum class VCrossCurvesPoint : char {HighestPoint = 1, LowestPoint = 2}; enum class HCrossCurvesPoint : char {LeftmostPoint = 1, RightmostPoint = 2}; +enum class AxisType : char {VerticalAxis = 1, HorizontalAxis = 2}; class VContainer; class VDataTool; diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 0a51f4199..31b04099f 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -110,6 +110,7 @@ enum class Tool : ToolVisHolderType Group, Rotation, FlippingByLine, + FlippingByAxis, Midpoint, LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used }; @@ -152,7 +153,8 @@ enum class Vis : ToolVisHolderType ToolCurveIntersectAxis, ToolTrueDarts, ToolRotation, - ToolFlippingByLine + ToolFlippingByLine, + ToolFlippingByAxis }; enum class VarType : char { Measurement, Increment, LineLength, CurveLength, LineAngle, CurveAngle, ArcRadius, diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index 8b51c331b..167b8580d 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -39,7 +39,8 @@ HEADERS += \ $$PWD/tools/dialogcubicbezierpath.h \ $$PWD/tools/dialoggroup.h \ $$PWD/tools/dialogrotation.h \ - $$PWD/tools/dialogflippingbyline.h + $$PWD/tools/dialogflippingbyline.h \ + $$PWD/tools/dialogflippingbyaxis.h SOURCES += \ @@ -79,7 +80,8 @@ SOURCES += \ $$PWD/tools/dialogcubicbezierpath.cpp \ $$PWD/tools/dialoggroup.cpp \ $$PWD/tools/dialogrotation.cpp \ - $$PWD/tools/dialogflippingbyline.cpp + $$PWD/tools/dialogflippingbyline.cpp \ + $$PWD/tools/dialogflippingbyaxis.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ @@ -117,4 +119,5 @@ FORMS += \ $$PWD/tools/dialogcubicbezierpath.ui \ $$PWD/tools/dialoggroup.ui \ $$PWD/tools/dialogrotation.ui \ - $$PWD/tools/dialogflippingbyline.ui + $$PWD/tools/dialogflippingbyline.ui \ + $$PWD/tools/dialogflippingbyaxis.ui diff --git a/src/libs/vtools/dialogs/tooldialogs.h b/src/libs/vtools/dialogs/tooldialogs.h index 9a2e0d09d..7a884ce90 100644 --- a/src/libs/vtools/dialogs/tooldialogs.h +++ b/src/libs/vtools/dialogs/tooldialogs.h @@ -63,6 +63,7 @@ #include "tools/dialoggroup.h" #include "tools/dialogrotation.h" #include "tools/dialogflippingbyline.h" +#include "tools/dialogflippingbyaxis.h" #include "support/dialogeditwrongformula.h" #include "support/dialogundo.h" diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp new file mode 100644 index 000000000..a49fd2e82 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp @@ -0,0 +1,325 @@ +/************************************************************************ + ** + ** @file dialogflippingbyaxis.cpp + ** @author Roman Telezhynskyi + ** @date 16 9, 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 "dialogflippingbyaxis.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../visualization/visualization.h" +#include "../../visualization/line/operation/vistoolflippingbyaxis.h" +#include "../ifc/xml/vabstractpattern.h" +#include "../ifc/xml/vdomdocument.h" +#include "../qmuparser/qmudef.h" +#include "../vgeometry/vpointf.h" +#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vcommonsettings.h" +#include "../vpatterndb/vcontainer.h" +#include "../vwidgets/vabstractmainwindow.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "ui_dialogflippingbyaxis.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogFlippingByAxis::DialogFlippingByAxis(const VContainer *data, const quint32 &toolId, QWidget *parent) + : DialogTool(data, toolId, parent), + ui(new Ui::DialogFlippingByAxis), + objects(), + stage1(true), + m_suffix() +{ + ui->setupUi(this); + + ui->lineEditSuffix->setText(qApp->getCurrentDocument()->GenerateSuffix()); + + InitOkCancelApply(ui); + + FillComboBoxPoints(ui->comboBoxOriginPoint); + FillComboBoxAxisType(ui->comboBoxAxisType); + + flagName = true; + CheckState(); + + connect(ui->lineEditSuffix, &QLineEdit::textChanged, this, &DialogFlippingByAxis::SuffixChanged); + connect(ui->comboBoxOriginPoint, static_cast(&QComboBox::currentIndexChanged), + this, &DialogFlippingByAxis::PointChanged); + + vis = new VisToolFlippingByAxis(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogFlippingByAxis::~DialogFlippingByAxis() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogFlippingByAxis::GetOriginPointId() const +{ + return getCurrentObjectId(ui->comboBoxOriginPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::SetOriginPointId(quint32 value) +{ + ChangeCurrentData(ui->comboBoxOriginPoint, value); + VisToolFlippingByAxis *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetOriginPointId(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +AxisType DialogFlippingByAxis::GetAxisType() const +{ + return getCurrentCrossPoint(ui->comboBoxAxisType); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::SetAxisType(AxisType type) +{ + auto index = ui->comboBoxAxisType->findData(static_cast(type)); + if (index != -1) + { + ui->comboBoxAxisType->setCurrentIndex(index); + + auto operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetAxisType(type); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogFlippingByAxis::GetSuffix() const +{ + return m_suffix; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::SetSuffix(const QString &value) +{ + m_suffix = value; + ui->lineEditSuffix->setText(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector DialogFlippingByAxis::GetObjects() const +{ + return objects.toVector(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::ShowDialog(bool click) +{ + if (stage1 && not click) + { + if (objects.isEmpty()) + { + return; + } + + stage1 = false; + + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + scene->clearSelection(); + + VisToolFlippingByAxis *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetObjects(objects.toVector()); + operation->VisualMode(); + + scene->ToggleArcSelection(false); + scene->ToggleSplineSelection(false); + scene->ToggleSplinePathSelection(false); + + scene->ToggleArcHover(false); + scene->ToggleSplineHover(false); + scene->ToggleSplinePathHover(false); + + emit ToolTip("Select origin point"); + } + else if (not stage1 && prepare && click) + { + setModal(true); + emit ToolTip(""); + show(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::ChosenObject(quint32 id, const SceneObject &type) +{ + if (not stage1 && not prepare)// After first choose we ignore all objects + { + if (type == SceneObject::Point) + { + if (objects.contains(id)) + { + return; + } + + if (SetObject(id, ui->comboBoxOriginPoint, "")) + { + VisToolFlippingByAxis *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetOriginPointId(id); + operation->RefreshGeometry(); + + prepare = true; + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::SelectedObject(bool selected, quint32 object, quint32 tool) +{ + Q_UNUSED(tool) + if (stage1) + { + if (selected) + { + if (not objects.contains(object)) + { + objects.append(object); + } + } + else + { + objects.removeOne(object); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::SuffixChanged() +{ + QLineEdit* edit = qobject_cast(sender()); + if (edit) + { + const QString suffix = edit->text(); + if (suffix.isEmpty()) + { + flagName = false; + ChangeColor(ui->labelSuffix, Qt::red); + CheckState(); + return; + } + else + { + if (m_suffix != suffix) + { + QRegularExpression rx(NameRegExp()); + const QStringList uniqueNames = data->AllUniqueNames(); + for (int i=0; i < uniqueNames.size(); ++i) + { + const QString name = uniqueNames.at(i) + suffix; + if (not rx.match(name).hasMatch() || not data->IsUnique(name)) + { + flagName = false; + ChangeColor(ui->labelSuffix, Qt::red); + CheckState(); + return; + } + } + } + } + + flagName = true; + ChangeColor(ui->labelSuffix, okColor); + } + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::CheckState() +{ + SCASSERT(bOk != nullptr); + bOk->setEnabled(flagError && flagName); + SCASSERT(bApply != nullptr); + bApply->setEnabled(bOk->isEnabled()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::ShowVisualization() +{ + AddVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::SaveData() +{ + m_suffix = ui->lineEditSuffix->text(); + + VisToolFlippingByAxis *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + + operation->SetObjects(objects.toVector()); + operation->SetOriginPointId(GetOriginPointId()); + operation->SetAxisType(GetAxisType()); + operation->RefreshGeometry(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::PointChanged() +{ + QColor color = okColor; + if (objects.contains(getCurrentObjectId(ui->comboBoxOriginPoint))) + { + flagError = false; + color = errorColor; + } + else + { + flagError = true; + color = okColor; + } + ChangeColor(ui->labelOriginPoint, color); + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::FillComboBoxAxisType(QComboBox *box) +{ + SCASSERT(box != nullptr); + + box->addItem(tr("Vertical axis"), QVariant(static_cast(AxisType::VerticalAxis))); + box->addItem(tr("Horizontal axis"), QVariant(static_cast(AxisType::HorizontalAxis))); +} diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.h b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.h new file mode 100644 index 000000000..ac456dcc9 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.h @@ -0,0 +1,104 @@ +/************************************************************************ + ** + ** @file dialogflippingbyaxis.h + ** @author Roman Telezhynskyi + ** @date 16 9, 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 DIALOGFLIPPINGBYAXIS_H +#define DIALOGFLIPPINGBYAXIS_H + +#include "dialogtool.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "../vmisc/def.h" + +class QWidget; +class VContainer; + +namespace Ui +{ + class DialogFlippingByAxis; +} + +class DialogFlippingByAxis : public DialogTool +{ + Q_OBJECT + +public: + explicit DialogFlippingByAxis(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr); + virtual ~DialogFlippingByAxis(); + + quint32 GetOriginPointId() const; + void SetOriginPointId(quint32 value); + + AxisType GetAxisType() const; + void SetAxisType(AxisType type); + + QString GetSuffix() const; + void SetSuffix(const QString &value); + + QVector GetObjects() const; + + virtual void ShowDialog(bool click) Q_DECL_OVERRIDE; + +public slots: + virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; + virtual void SelectedObject(bool selected, quint32 object, quint32 tool) Q_DECL_OVERRIDE; + +private slots: + void SuffixChanged(); + +protected: + virtual void CheckState() Q_DECL_OVERRIDE; + virtual void ShowVisualization() Q_DECL_OVERRIDE; + + /** @brief SaveData Put dialog data in local variables */ + virtual void SaveData() Q_DECL_OVERRIDE; + +private slots: + void PointChanged(); + +private: + Q_DISABLE_COPY(DialogFlippingByAxis) + + Ui::DialogFlippingByAxis *ui; + + QList objects; + + bool stage1; + + QString m_suffix; + + static void FillComboBoxAxisType(QComboBox *box); +}; + +#endif // DIALOGFLIPPINGBYAXIS_H diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.ui b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.ui new file mode 100644 index 000000000..d80fc67e4 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.ui @@ -0,0 +1,98 @@ + + + DialogFlippingByAxis + + + + 0 + 0 + 285 + 146 + + + + Dialog + + + + + + + + Origin point: + + + + + + + + + + Suffix: + + + + + + + + + + Axis type: + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DialogFlippingByAxis + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogFlippingByAxis + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp b/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp index 39d92d6d6..78ca2ae88 100644 --- a/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp @@ -81,6 +81,9 @@ DialogFlippingByLine::DialogFlippingByLine(const VContainer *data, const quint32 connect(ui->comboBoxFirstLinePoint, static_cast(&QComboBox::currentIndexChanged), this, &DialogFlippingByLine::PointChanged); + connect(ui->comboBoxSecondLinePoint, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogFlippingByLine::PointChanged); vis = new VisToolFlippingByLine(data); } diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui b/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui index cee345f19..81d43f46f 100644 --- a/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui @@ -13,6 +13,10 @@ Dialog + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + @@ -60,7 +64,9 @@
- + + + buttonBox diff --git a/src/libs/vtools/tools/drawTools/drawtools.h b/src/libs/vtools/tools/drawTools/drawtools.h index 93142cf64..6adaecdd3 100644 --- a/src/libs/vtools/tools/drawTools/drawtools.h +++ b/src/libs/vtools/tools/drawTools/drawtools.h @@ -60,5 +60,6 @@ #include "toolpoint/tooldoublepoint/vtooltruedarts.h" #include "operation/vtoolrotation.h" #include "operation/flipping/vtoolflippingbyline.h" +#include "operation/flipping/vtoolflippingbyaxis.h" #endif // DRAWTOOLS_H diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp new file mode 100644 index 000000000..8cbd99b95 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp @@ -0,0 +1,195 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 9, 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 "vabstractflipping.h" +#include "../vgeometry/vabstractcurve.h" +#include "../vgeometry/varc.h" +#include "../vgeometry/vcubicbezier.h" +#include "../vgeometry/vcubicbezierpath.h" +#include "../vgeometry/vgobject.h" +#include "../vgeometry/vpointf.h" +#include "../vgeometry/vspline.h" +#include "../vgeometry/vsplinepath.h" + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractFlipping::~VAbstractFlipping() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractFlipping::VAbstractFlipping(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix, + const QVector &source, const QVector &destination, + QGraphicsItem *parent) + : VAbstractOperation(doc, data, id, suffix, source, destination, parent) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractFlipping::CreateDestination(Source typeCreation, quint32 &id, QVector &dest, + const QVector &source, const QPointF &fPoint, const QPointF &sPoint, + const QString &suffix, VAbstractPattern *doc, VContainer *data, + const Document &parse) +{ + if (typeCreation == Source::FromGui) + { + dest.clear();// Try to avoid mistake, value must be empty + + id = data->getNextId();//Just reserve id for tool + + for (int i = 0; i < source.size(); ++i) + { + const quint32 idObject = source.at(i); + const QSharedPointer obj = data->GetGObject(idObject); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch(static_cast(obj->getType())) + { + case GOType::Point: + dest.append(CreatePoint(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::Arc: + dest.append(CreateArc(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::EllipticalArc: + //dest.append(CreateItem(id, idObject, fPoint, sPoint, suffix)); + break; + case GOType::Spline: + dest.append(CreateCurve(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::SplinePath: + dest.append(CreateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::CubicBezier: + dest.append(CreateCurve(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::CubicBezierPath: + dest.append(CreateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::Unknown: + break; + } +QT_WARNING_POP + } + } + else + { + for (int i = 0; i < source.size(); ++i) + { + const quint32 idObject = source.at(i); + const QSharedPointer obj = data->GetGObject(idObject); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch(static_cast(obj->getType())) + { + case GOType::Point: + UpdatePoint(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id, dest.at(i).mx, + dest.at(i).my); + break; + case GOType::Arc: + UpdateArc(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::EllipticalArc: + //dest.append(UpdateItem(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::Spline: + UpdateCurve(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::SplinePath: + UpdateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::CubicBezier: + UpdateCurve(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::CubicBezierPath: + UpdateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data, + dest.at(i).id); + break; + case GOType::Unknown: + break; + } +QT_WARNING_POP + } + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +DestinationItem VAbstractFlipping::CreatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const QSharedPointer point = data->GeometricObject(idItem); + VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + + DestinationItem item; + item.mx = rotated.mx(); + item.my = rotated.my(); + item.id = data->AddGObject(new VPointF(rotated)); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +DestinationItem VAbstractFlipping::CreateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); + data->AddArc(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractFlipping::UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id, + qreal mx, qreal my) +{ + const QSharedPointer point = data->GeometricObject(idItem); + VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + rotated.setMx(mx); + rotated.setMy(my); + data->UpdateGObject(id, new VPointF(rotated)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractFlipping::UpdateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); + data->AddArc(data->GeometricObject(id), id); +} diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h new file mode 100644 index 000000000..0bc98b1be --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h @@ -0,0 +1,151 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 9, 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 VABSTRACTFLIPPING_H +#define VABSTRACTFLIPPING_H + +#include + +#include "../vabstractoperation.h" + +class VAbstractFlipping : public VAbstractOperation +{ + Q_OBJECT +public: + virtual ~VAbstractFlipping(); +protected: + VAbstractFlipping(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix, + const QVector &source, const QVector &destination, + QGraphicsItem *parent = nullptr); + + static void CreateDestination(Source typeCreation, quint32 &id, QVector &dest, + const QVector &source, const QPointF &fPoint, const QPointF &sPoint, + const QString &suffix, VAbstractPattern *doc, VContainer *data, + const Document &parse); + + static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + + template + static DestinationItem CreateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + static DestinationItem CreateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + template + static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + template + static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + + static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my); + template + static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id); + static void UpdateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id); + template + static void UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id); + template + static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, + quint32 id); +private: + Q_DISABLE_COPY(VAbstractFlipping) +}; + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VAbstractFlipping::CreateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const QSharedPointer i = data->GeometricObject(idItem); + Item rotated = i->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + + DestinationItem item; + item.mx = INT_MAX; + item.my = INT_MAX; + item.id = data->AddGObject(new Item(rotated)); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VAbstractFlipping::CreateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); + data->AddCurve(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VAbstractFlipping::CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, + VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); + data->AddCurveWithSegments(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractFlipping::UpdateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) +{ + const QSharedPointer i = data->GeometricObject(idItem); + Item rotated = i->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + data->UpdateGObject(id, new Item(rotated)); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractFlipping::UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); + data->AddCurve(data->GeometricObject(id), id); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractFlipping::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, + quint32 id) +{ + UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); + data->AddCurveWithSegments(data->GeometricObject(id), id); +} + +#endif // VABSTRACTFLIPPING_H diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp new file mode 100644 index 000000000..42d22be86 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp @@ -0,0 +1,248 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 9, 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 "vtoolflippingbyaxis.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../../../dialogs/tools/dialogtool.h" +#include "../../../../dialogs/tools/dialogflippingbyaxis.h" +#include "../../../../visualization/line/operation/vistoolflippingbyaxis.h" +#include "../../../../visualization/visualization.h" +#include "../vgeometry/vpointf.h" +#include "../vpatterndb/vtranslatevars.h" +#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vcommonsettings.h" +#include "../vmisc/diagnostic.h" +#include "../vmisc/logging.h" +#include "../vpatterndb/vcontainer.h" +#include "../vpatterndb/vformula.h" +#include "../ifc/ifcdef.h" +#include "../ifc/exception/vexception.h" +#include "../vwidgets/vabstractsimple.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "../../../vabstracttool.h" +#include "../../../vdatatool.h" +#include "../../vdrawtool.h" + +class QDomElement; +class QGraphicsSceneContextMenuEvent; +class QPainter; +class QStyleOptionGraphicsItem; +class QWidget; +template class QSharedPointer; + +const QString VToolFlippingByAxis::ToolType = QStringLiteral("flippingByAxis"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByAxis::~VToolFlippingByAxis() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::setDialog() +{ + SCASSERT(dialog != nullptr); + DialogFlippingByAxis *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + dialogTool->SetOriginPointId(m_originPointId); + dialogTool->SetAxisType(m_axisType); + dialogTool->SetSuffix(suffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByAxis *VToolFlippingByAxis::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data) +{ + SCASSERT(dialog != nullptr); + DialogFlippingByAxis *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const quint32 originPointId = dialogTool->GetOriginPointId(); + const AxisType axisType = dialogTool->GetAxisType(); + const QString suffix = dialogTool->GetSuffix(); + const QVector source = dialogTool->GetObjects(); + VToolFlippingByAxis* operation = Create(0, originPointId, axisType, suffix, source, QVector(), + scene, doc, data, Document::FullParse, Source::FromGui); + if (operation != nullptr) + { + operation->dialog = dialogTool; + } + return operation; +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByAxis *VToolFlippingByAxis::Create(const quint32 _id, quint32 originPointId, AxisType axisType, + const QString &suffix, const QVector &source, + const QVector &destination, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation) +{ + const auto originPoint = *data->GeometricObject(originPointId); + const QPointF fPoint = originPoint; + + QPointF sPoint; + if (axisType == AxisType::VerticalAxis) + { + sPoint = QPointF(fPoint.x(), fPoint.y() + 100); + } + else + { + sPoint = QPointF(fPoint.x() + 100, fPoint.y()); + } + + QVector dest = destination; + + quint32 id = _id; + CreateDestination(typeCreation, id, dest, source, fPoint, sPoint, suffix, doc, data, parse); + + VDrawTool::AddRecord(id, Tool::FlippingByAxis, doc); + if (parse == Document::FullParse) + { + VToolFlippingByAxis *tool = new VToolFlippingByAxis(doc, data, id, originPointId, axisType, suffix, source, + dest, typeCreation); + scene->addItem(tool); + InitOperationToolConnections(scene, tool); + doc->AddTool(id, tool); + doc->IncrementReferens(originPoint.getIdTool()); + for (int i = 0; i < source.size(); ++i) + { + doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool()); + } + return tool; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +AxisType VToolFlippingByAxis::GetAxisType() const +{ + return m_axisType; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::SetAxisType(AxisType value) +{ + m_axisType = value; + + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::ShowVisualization(bool show) +{ + ShowToolVisualization(show); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::SetVisualization() +{ + if (vis != nullptr) + { + VisToolFlippingByAxis *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->SetObjects(source); + visual->SetOriginPointId(m_originPointId); + visual->SetAxisType(m_axisType); + visual->RefreshGeometry(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::SaveDialog(QDomElement &domElement) +{ + SCASSERT(dialog != nullptr); + DialogFlippingByAxis *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + + doc->SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->GetOriginPointId())); + doc->SetAttribute(domElement, AttrAxisType, QString().setNum(static_cast(dialogTool->GetAxisType()))); + doc->SetAttribute(domElement, AttrSuffix, dialogTool->GetSuffix()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::ReadToolAttributes(const QDomElement &domElement) +{ + m_originPointId = doc->GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); + m_axisType = static_cast(doc->GetParametrUInt(domElement, AttrAxisType, "1")); + suffix = doc->GetParametrString(domElement, AttrSuffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + VDrawTool::SaveOptions(tag, obj); + + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrCenter, QString().setNum(m_originPointId)); + doc->SetAttribute(tag, AttrAxisType, QString().setNum(static_cast(m_axisType))); + doc->SetAttribute(tag, AttrSuffix, suffix); + + SaveSourceDestination(tag); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByAxis::VToolFlippingByAxis(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 originPointId, + AxisType axisType, const QString &suffix, + const QVector &source, const QVector &destination, + const Source &typeCreation, QGraphicsItem *parent) + : VAbstractFlipping(doc, data, id, suffix, source, destination, parent), + m_originPointId(originPointId), + m_axisType(axisType) +{ + InitOperatedObjects(); + ToolCreation(typeCreation); +} + diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.h b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.h new file mode 100644 index 000000000..5159446e1 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.h @@ -0,0 +1,77 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 9, 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 VTOOLFLIPPINGBYAXIS_H +#define VTOOLFLIPPINGBYAXIS_H + +#include + +#include "vabstractflipping.h" + +class VToolFlippingByAxis : public VAbstractFlipping +{ + Q_OBJECT +public: + virtual ~VToolFlippingByAxis(); + virtual void setDialog() Q_DECL_OVERRIDE; + static VToolFlippingByAxis* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data); + static VToolFlippingByAxis* Create(const quint32 _id, quint32 originPointId, AxisType axisType, + const QString &suffix, const QVector &source, + const QVector &destination, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation); + + static const QString ToolType; + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Tool::FlippingByAxis)}; + + AxisType GetAxisType() const; + void SetAxisType(AxisType value); + + virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; +protected: + virtual void SetVisualization() Q_DECL_OVERRIDE; + virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(VToolFlippingByAxis) + + quint32 m_originPointId; + AxisType m_axisType; + + VToolFlippingByAxis(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 originPointId, + AxisType axisType, const QString &suffix, const QVector &source, + const QVector &destination, const Source &typeCreation, + QGraphicsItem *parent = nullptr); +}; + +#endif // VTOOLFLIPPINGBYAXIS_H diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp index 1f22e274d..3b2165e14 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp @@ -44,17 +44,9 @@ #include "../../../../dialogs/tools/dialogtool.h" #include "../../../../dialogs/tools/dialogflippingbyline.h" -#include "../../../../undocommands/label/operationmovelabel.h" #include "../../../../visualization/line/operation/vistoolflippingbyline.h" #include "../../../../visualization/visualization.h" -#include "../vgeometry/vabstractcurve.h" -#include "../vgeometry/varc.h" -#include "../vgeometry/vcubicbezier.h" -#include "../vgeometry/vcubicbezierpath.h" -#include "../vgeometry/vgobject.h" #include "../vgeometry/vpointf.h" -#include "../vgeometry/vspline.h" -#include "../vgeometry/vsplinepath.h" #include "../vpatterndb/vtranslatevars.h" #include "../vmisc/vabstractapplication.h" #include "../vmisc/vcommonsettings.h" @@ -132,98 +124,7 @@ VToolFlippingByLine *VToolFlippingByLine::Create(const quint32 _id, quint32 firs QVector dest = destination; quint32 id = _id; - if (typeCreation == Source::FromGui) - { - dest.clear();// Try to avoid mistake, value must be empty - - id = data->getNextId();//Just reserve id for tool - - for (int i = 0; i < source.size(); ++i) - { - const quint32 idObject = source.at(i); - const QSharedPointer obj = data->GetGObject(idObject); - - // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); - -QT_WARNING_PUSH -QT_WARNING_DISABLE_GCC("-Wswitch-default") - switch(static_cast(obj->getType())) - { - case GOType::Point: - dest.append(CreatePoint(id, idObject, fPoint, sPoint, suffix, data)); - break; - case GOType::Arc: - dest.append(CreateArc(id, idObject, fPoint, sPoint, suffix, data)); - break; - case GOType::EllipticalArc: - //dest.append(CreateItem(id, idObject, fPoint, sPoint, suffix)); - break; - case GOType::Spline: - dest.append(CreateCurve(id, idObject, fPoint, sPoint, suffix, data)); - break; - case GOType::SplinePath: - dest.append(CreateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data)); - break; - case GOType::CubicBezier: - dest.append(CreateCurve(id, idObject, fPoint, sPoint, suffix, data)); - break; - case GOType::CubicBezierPath: - dest.append(CreateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data)); - break; - case GOType::Unknown: - break; - } -QT_WARNING_POP - } - } - else - { - for (int i = 0; i < source.size(); ++i) - { - const quint32 idObject = source.at(i); - const QSharedPointer obj = data->GetGObject(idObject); - - // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); - -QT_WARNING_PUSH -QT_WARNING_DISABLE_GCC("-Wswitch-default") - switch(static_cast(obj->getType())) - { - case GOType::Point: - UpdatePoint(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id, dest.at(i).mx, - dest.at(i).my); - break; - case GOType::Arc: - UpdateArc(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); - break; - case GOType::EllipticalArc: - //dest.append(UpdateItem(id, idObject, fPoint, sPoint, suffix, data)); - break; - case GOType::Spline: - UpdateCurve(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); - break; - case GOType::SplinePath: - UpdateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); - break; - case GOType::CubicBezier: - UpdateCurve(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); - break; - case GOType::CubicBezierPath: - UpdateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data, - dest.at(i).id); - break; - case GOType::Unknown: - break; - } -QT_WARNING_POP - } - if (parse != Document::FullParse) - { - doc->UpdateToolData(id, data); - } - } + CreateDestination(typeCreation, id, dest, source, fPoint, sPoint, suffix, doc, data, parse); VDrawTool::AddRecord(id, Tool::FlippingByLine, doc); if (parse == Document::FullParse) @@ -317,122 +218,10 @@ VToolFlippingByLine::VToolFlippingByLine(VAbstractPattern *doc, VContainer *data quint32 secondLinePointId, const QString &suffix, const QVector &source, const QVector &destination, const Source &typeCreation, QGraphicsItem *parent) - : VAbstractOperation(doc, data, id, suffix, source, destination, parent), + : VAbstractFlipping(doc, data, id, suffix, source, destination, parent), m_firstLinePointId(firstLinePointId), m_secondLinePointId(secondLinePointId) { InitOperatedObjects(); ToolCreation(typeCreation); } - -//--------------------------------------------------------------------------------------------------------------------- -DestinationItem VToolFlippingByLine::CreatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data) -{ - const QSharedPointer point = data->GeometricObject(idItem); - VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix); - rotated.setIdObject(idTool); - - DestinationItem item; - item.mx = rotated.mx(); - item.my = rotated.my(); - item.id = data->AddGObject(new VPointF(rotated)); - return item; -} - -//--------------------------------------------------------------------------------------------------------------------- -DestinationItem VToolFlippingByLine::CreateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data) -{ - const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); - data->AddArc(data->GeometricObject(item.id), item.id); - return item; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolFlippingByLine::UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id, - qreal mx, qreal my) -{ - const QSharedPointer point = data->GeometricObject(idItem); - VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix); - rotated.setIdObject(idTool); - rotated.setMx(mx); - rotated.setMy(my); - data->UpdateGObject(id, new VPointF(rotated)); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolFlippingByLine::UpdateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) -{ - UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); - data->AddArc(data->GeometricObject(id), id); -} - -//--------------------------------------------------------------------------------------------------------------------- -template -DestinationItem VToolFlippingByLine::CreateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data) -{ - const QSharedPointer i = data->GeometricObject(idItem); - Item rotated = i->Flip(QLineF(firstPoint, secondPoint), suffix); - rotated.setIdObject(idTool); - - DestinationItem item; - item.mx = INT_MAX; - item.my = INT_MAX; - item.id = data->AddGObject(new Item(rotated)); - return item; -} - -//--------------------------------------------------------------------------------------------------------------------- -template -DestinationItem VToolFlippingByLine::CreateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data) -{ - const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); - data->AddCurve(data->GeometricObject(item.id), item.id); - return item; -} - -//--------------------------------------------------------------------------------------------------------------------- -template -DestinationItem VToolFlippingByLine::CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, - VContainer *data) -{ - const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); - data->AddCurveWithSegments(data->GeometricObject(item.id), item.id); - return item; -} - -//--------------------------------------------------------------------------------------------------------------------- -template -void VToolFlippingByLine::UpdateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) -{ - const QSharedPointer i = data->GeometricObject(idItem); - Item rotated = i->Flip(QLineF(firstPoint, secondPoint), suffix); - rotated.setIdObject(idTool); - data->UpdateGObject(id, new Item(rotated)); -} - -//--------------------------------------------------------------------------------------------------------------------- -template -void VToolFlippingByLine::UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) -{ - UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); - data->AddCurve(data->GeometricObject(id), id); -} - -//--------------------------------------------------------------------------------------------------------------------- -template -void VToolFlippingByLine::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data, - quint32 id) -{ - UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); - data->AddCurveWithSegments(data->GeometricObject(id), id); -} diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h index 485998b8f..6d11c77c5 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h @@ -31,9 +31,9 @@ #include -#include "../vabstractoperation.h" +#include "vabstractflipping.h" -class VToolFlippingByLine : public VAbstractOperation +class VToolFlippingByLine : public VAbstractFlipping { Q_OBJECT public: @@ -69,36 +69,6 @@ private: quint32 secondLinePointId, const QString &suffix, const QVector &source, const QVector &destination, const Source &typeCreation, QGraphicsItem *parent = nullptr); - - static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data); - - template - static DestinationItem CreateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data); - static DestinationItem CreateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data); - template - static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data); - template - static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data); - - static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, - const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my); - template - static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, - const QString &suffix, VContainer *data, quint32 id); - static void UpdateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, - const QString &suffix, VContainer *data, quint32 id); - template - static void UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, - const QString &suffix, VContainer *data, quint32 id); - template - static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data, - quint32 id); }; #endif // VTOOLFLIPPINGBYLINE_H diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index f50749a81..d84f0ff2a 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -53,7 +53,9 @@ HEADERS += \ $$PWD/drawTools/operation/vtoolrotation.h \ $$PWD/vtextgraphicsitem.h \ $$PWD/drawTools/operation/flipping/vtoolflippingbyline.h \ - $$PWD/drawTools/operation/vabstractoperation.h + $$PWD/drawTools/operation/vabstractoperation.h \ + $$PWD/drawTools/operation/flipping/vtoolflippingbyaxis.h \ + $$PWD/drawTools/operation/flipping/vabstractflipping.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -104,4 +106,6 @@ SOURCES += \ $$PWD/drawTools/operation/vtoolrotation.cpp \ $$PWD/vtextgraphicsitem.cpp \ $$PWD/drawTools/operation/flipping/vtoolflippingbyline.cpp \ - $$PWD/drawTools/operation/vabstractoperation.cpp + $$PWD/drawTools/operation/vabstractoperation.cpp \ + $$PWD/drawTools/operation/flipping/vtoolflippingbyaxis.cpp \ + $$PWD/drawTools/operation/flipping/vabstractflipping.cpp diff --git a/src/libs/vtools/visualization/line/operation/visoperation.cpp b/src/libs/vtools/visualization/line/operation/visoperation.cpp index 56628e3cb..03d3aa7a9 100644 --- a/src/libs/vtools/visualization/line/operation/visoperation.cpp +++ b/src/libs/vtools/visualization/line/operation/visoperation.cpp @@ -27,6 +27,16 @@ *************************************************************************/ #include "visoperation.h" +#include "../vgeometry/vabstractcurve.h" +#include "../vgeometry/varc.h" +#include "../vgeometry/vcubicbezier.h" +#include "../vgeometry/vcubicbezierpath.h" +#include "../vgeometry/vellipticalarc.h" +#include "../vgeometry/vgeometrydef.h" +#include "../vgeometry/vgobject.h" +#include "../vgeometry/vpointf.h" +#include "../vgeometry/vspline.h" +#include "../vgeometry/vsplinepath.h" //--------------------------------------------------------------------------------------------------------------------- VisOperation::VisOperation(const VContainer *data, QGraphicsItem *parent) @@ -97,3 +107,73 @@ QGraphicsPathItem *VisOperation::GetCurve(quint32 i, const QColor &color) return nullptr; } +//--------------------------------------------------------------------------------------------------------------------- +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") +void VisOperation::RefreshFlippedObjects(const QPointF &firstPoint, const QPointF &secondPoint) +{ + int iPoint = -1; + int iCurve = -1; + for (int i = 0; i < objects.size(); ++i) + { + const quint32 id = objects.at(i); + const QSharedPointer obj = Visualization::data->GetGObject(id); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + + switch(static_cast(obj->getType())) + { + case GOType::Point: + { + const QSharedPointer p = Visualization::data->GeometricObject(id); + + ++iPoint; + QGraphicsEllipseItem *point = GetPoint(iPoint, supportColor2); + DrawPoint(point, *p, supportColor2); + + ++iPoint; + point = GetPoint(iPoint, supportColor); + + if (object1Id != NULL_ID) + { + DrawPoint(point, p->Flip(QLineF(firstPoint, secondPoint)), supportColor); + } + break; + } + case GOType::Arc: + { + iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::EllipticalArc: + { + iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::Spline: + { + iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::SplinePath: + { + iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::CubicBezier: + { + iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::CubicBezierPath: + { + iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::Unknown: + break; + } + } +} +QT_WARNING_POP diff --git a/src/libs/vtools/visualization/line/operation/visoperation.h b/src/libs/vtools/visualization/line/operation/visoperation.h index fe4628f04..6e698e81d 100644 --- a/src/libs/vtools/visualization/line/operation/visoperation.h +++ b/src/libs/vtools/visualization/line/operation/visoperation.h @@ -55,8 +55,34 @@ protected: QGraphicsEllipseItem * GetPoint(quint32 i, const QColor &color); QGraphicsPathItem * GetCurve(quint32 i, const QColor &color); + + template + int AddFlippedCurve(const QPointF &firstPoint, const QPointF &secondPoint, quint32 id, int i); + + void RefreshFlippedObjects(const QPointF &firstPoint, const QPointF &secondPoint); private: Q_DISABLE_COPY(VisOperation) }; +//--------------------------------------------------------------------------------------------------------------------- +template +int VisOperation::AddFlippedCurve(const QPointF &firstPoint, const QPointF &secondPoint, quint32 id, int i) +{ + const QSharedPointer curve = Visualization::data->template GeometricObject(id); + + ++i; + QGraphicsPathItem *path = GetCurve(i, supportColor2); + DrawPath(path, curve->GetPath(PathDirection::Show), supportColor2, Qt::SolidLine, Qt::RoundCap); + + ++i; + path = GetCurve(i, supportColor); + if (object1Id != NULL_ID) + { + const Item flipped = curve->Flip(QLineF(firstPoint, secondPoint)); + DrawPath(path, flipped.GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + } + + return i; +} + #endif // VISOPERATION_H diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.cpp b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.cpp new file mode 100644 index 000000000..2b20e984f --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.cpp @@ -0,0 +1,87 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 9, 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 "vistoolflippingbyaxis.h" +#include "../vgeometry/vpointf.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolFlippingByAxis::VisToolFlippingByAxis(const VContainer *data, QGraphicsItem *parent) + : VisOperation(data, parent), + m_axisType(AxisType::VerticalAxis), + point1(nullptr) +{ + point1 = InitPoint(supportColor2, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolFlippingByAxis::~VisToolFlippingByAxis() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolFlippingByAxis::RefreshGeometry() +{ + if (objects.isEmpty()) + { + return; + } + + QPointF firstPoint; + QPointF secondPoint; + + if (object1Id != NULL_ID) + { + firstPoint = *Visualization::data->GeometricObject(object1Id); + DrawPoint(point1, firstPoint, supportColor2); + + if (m_axisType == AxisType::VerticalAxis) + { + secondPoint = QPointF(firstPoint.x(), firstPoint.y() + 100); + } + else + { + secondPoint = QPointF(firstPoint.x() + 100, firstPoint.y()); + } + + DrawLine(this, Axis(firstPoint, secondPoint), supportColor2, Qt::DashLine); + } + + RefreshFlippedObjects(firstPoint, secondPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolFlippingByAxis::SetOriginPointId(quint32 value) +{ + object1Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolFlippingByAxis::SetAxisType(AxisType value) +{ + m_axisType = value; +} diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.h b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.h new file mode 100644 index 000000000..301f33dcd --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.h @@ -0,0 +1,59 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 9, 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 VISTOOLFLIPPINGBYAXIS_H +#define VISTOOLFLIPPINGBYAXIS_H + +#include + +#include "visoperation.h" +#include "../ifc/xml/vabstractpattern.h" + +class VisToolFlippingByAxis : public VisOperation +{ + Q_OBJECT +public: + explicit VisToolFlippingByAxis(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolFlippingByAxis(); + + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + + void SetOriginPointId(quint32 value); + void SetAxisType(AxisType value); + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ToolFlippingByAxis)}; +private: + Q_DISABLE_COPY(VisToolFlippingByAxis) + + AxisType m_axisType; + + QGraphicsEllipseItem *point1; +}; + +#endif // VISTOOLFLIPPINGBYAXIS_H diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp index 0e66bf5b9..ce808d1b0 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp @@ -27,16 +27,7 @@ *************************************************************************/ #include "vistoolflippingbyline.h" -#include "../vgeometry/vabstractcurve.h" -#include "../vgeometry/varc.h" -#include "../vgeometry/vcubicbezier.h" -#include "../vgeometry/vcubicbezierpath.h" -#include "../vgeometry/vellipticalarc.h" -#include "../vgeometry/vgeometrydef.h" -#include "../vgeometry/vgobject.h" #include "../vgeometry/vpointf.h" -#include "../vgeometry/vspline.h" -#include "../vgeometry/vsplinepath.h" //--------------------------------------------------------------------------------------------------------------------- VisToolFlippingByLine::VisToolFlippingByLine(const VContainer *data, QGraphicsItem *parent) @@ -55,8 +46,6 @@ VisToolFlippingByLine::~VisToolFlippingByLine() } //--------------------------------------------------------------------------------------------------------------------- -QT_WARNING_PUSH -QT_WARNING_DISABLE_GCC("-Wswitch-default") void VisToolFlippingByLine::RefreshGeometry() { if (objects.isEmpty()) @@ -85,71 +74,8 @@ void VisToolFlippingByLine::RefreshGeometry() DrawLine(this, QLineF(firstPoint, secondPoint), supportColor2, Qt::DashLine); } - int iPoint = -1; - int iCurve = -1; - for (int i = 0; i < objects.size(); ++i) - { - const quint32 id = objects.at(i); - const QSharedPointer obj = Visualization::data->GetGObject(id); - - // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); - - switch(static_cast(obj->getType())) - { - case GOType::Point: - { - const QSharedPointer p = Visualization::data->GeometricObject(id); - - ++iPoint; - QGraphicsEllipseItem *point = GetPoint(iPoint, supportColor2); - DrawPoint(point, *p, supportColor2); - - ++iPoint; - point = GetPoint(iPoint, supportColor); - - if (object1Id != NULL_ID) - { - DrawPoint(point, p->Flip(QLineF(firstPoint, secondPoint)), supportColor); - } - break; - } - case GOType::Arc: - { - iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); - break; - } - case GOType::EllipticalArc: - { - iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); - break; - } - case GOType::Spline: - { - iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); - break; - } - case GOType::SplinePath: - { - iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); - break; - } - case GOType::CubicBezier: - { - iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); - break; - } - case GOType::CubicBezierPath: - { - iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); - break; - } - case GOType::Unknown: - break; - } - } + RefreshFlippedObjects(firstPoint, secondPoint); } -QT_WARNING_POP //--------------------------------------------------------------------------------------------------------------------- void VisToolFlippingByLine::SetFirstLinePointId(quint32 value) @@ -162,24 +88,3 @@ void VisToolFlippingByLine::SetSecondLinePointId(quint32 value) { object2Id = value; } - -//--------------------------------------------------------------------------------------------------------------------- -template -int VisToolFlippingByLine::AddCurve(const QPointF &firstPoint, const QPointF &secondPoint, quint32 id, int i) -{ - const QSharedPointer curve = Visualization::data->template GeometricObject(id); - - ++i; - QGraphicsPathItem *path = GetCurve(i, supportColor2); - DrawPath(path, curve->GetPath(PathDirection::Show), supportColor2, Qt::SolidLine, Qt::RoundCap); - - ++i; - path = GetCurve(i, supportColor); - if (object1Id != NULL_ID) - { - const Item flipped = curve->Flip(QLineF(firstPoint, secondPoint)); - DrawPath(path, flipped.GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); - } - - return i; -} diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h index 4e9160654..21768a03a 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h @@ -52,9 +52,6 @@ private: quint32 object2Id; QGraphicsEllipseItem *point1; QGraphicsEllipseItem *point2; - - template - int AddCurve(const QPointF &firstPoint, const QPointF &secondPoint, quint32 id, int i); }; #endif // VISTOOLFLIPPINGBYLINE_H diff --git a/src/libs/vtools/visualization/visualization.pri b/src/libs/vtools/visualization/visualization.pri index 6de291625..4e2775d3f 100644 --- a/src/libs/vtools/visualization/visualization.pri +++ b/src/libs/vtools/visualization/visualization.pri @@ -35,7 +35,8 @@ HEADERS += \ $$PWD/path/vistoolpointofintersectioncurves.h \ $$PWD/path/vistoolcubicbezier.h \ $$PWD/path/vistoolcubicbezierpath.h \ - $$PWD/line/operation/visoperation.h + $$PWD/line/operation/visoperation.h \ + $$PWD/line/operation/vistoolflippingbyaxis.h SOURCES += \ $$PWD/visualization.cpp \ @@ -71,4 +72,5 @@ SOURCES += \ $$PWD/path/vistoolpointofintersectioncurves.cpp \ $$PWD/path/vistoolcubicbezier.cpp \ $$PWD/path/vistoolcubicbezierpath.cpp \ - $$PWD/line/operation/visoperation.cpp + $$PWD/line/operation/visoperation.cpp \ + $$PWD/line/operation/vistoolflippingbyaxis.cpp From 9ba844426055b2655672fb371aede48bf7ef1e2a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 17 Sep 2016 12:11:10 +0300 Subject: [PATCH 8/8] Updated changelog. --HG-- branch : feature --- ChangeLog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 592abbc6e..a8034a2bd 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -39,6 +39,7 @@ - [#424] Improve Formula Wizard dialog. - Added "All/None" menu in detail list area for easier handling of many parts. - [#560] Flipped pattern pieces in Layout. +- [#138] New tool: 'Mirror Point' or 'Symmetric Point'. # Version 0.4.5 - [#435] Valentina doesn't change the cursor.