diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.h b/src/libs/vgeometry/vabstractcubicbezierpath.h index 78e2cd0d6..bc2f6554f 100644 --- a/src/libs/vgeometry/vabstractcubicbezierpath.h +++ b/src/libs/vgeometry/vabstractcubicbezierpath.h @@ -35,6 +35,7 @@ class VPointF; class VSpline; +class VSplinePoint; class VAbstractCubicBezierPath : public VAbstractCurve { @@ -50,6 +51,7 @@ public: virtual qint32 CountPoints() const =0; virtual void Clear() =0; virtual VSpline GetSpline(qint32 index) const =0; + virtual QVector GetSplinePath() const =0; virtual QPainterPath GetPath(PathDirection direction = PathDirection::Hide) const Q_DECL_OVERRIDE; virtual QVector GetPoints() const Q_DECL_OVERRIDE; diff --git a/src/libs/vgeometry/vcubicbezierpath.cpp b/src/libs/vgeometry/vcubicbezierpath.cpp index c4c257446..cf463b794 100644 --- a/src/libs/vgeometry/vcubicbezierpath.cpp +++ b/src/libs/vgeometry/vcubicbezierpath.cpp @@ -30,6 +30,8 @@ #include "vcubicbezierpath_p.h" #include "vspline.h" #include "../ifc/exception/vexception.h" +#include "vsplinepoint.h" +#include "../vmisc/vabstractapplication.h" #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) # include "../vmisc/vmath.h" @@ -39,7 +41,7 @@ //--------------------------------------------------------------------------------------------------------------------- VCubicBezierPath::VCubicBezierPath(quint32 idObject, Draw mode) - : VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode), + : VAbstractCubicBezierPath(GOType::CubicBezierPath, idObject, mode), d(new VCubicBezierPathData()) { } @@ -53,7 +55,7 @@ VCubicBezierPath::VCubicBezierPath(const VCubicBezierPath &curve) //--------------------------------------------------------------------------------------------------------------------- VCubicBezierPath::VCubicBezierPath(const QVector &points, quint32 idObject, Draw mode) - : VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode), + : VAbstractCubicBezierPath(GOType::CubicBezierPath, idObject, mode), d(new VCubicBezierPathData()) { if (points.isEmpty()) @@ -184,7 +186,36 @@ qreal VCubicBezierPath::GetEndAngle() const } //--------------------------------------------------------------------------------------------------------------------- -QVector VCubicBezierPath::GetSplinePath() const +QVector VCubicBezierPath::GetSplinePath() const +{ + const int size = CountSubSpl(); + QVector splPoints(size+1); + + for (qint32 i = 1; i <= size; ++i) + { + const VSpline spl = GetSpline(i); + + { + VSplinePoint p = splPoints.at(i-1); + p.SetP(spl.GetP1()); + p.SetAngle2(spl.GetStartAngle(), spl.GetStartAngleFormula()); + p.SetLength2(spl.GetC1Length(), spl.GetC1LengthFormula()); + splPoints[i-1] = p; + } + + { + VSplinePoint p = splPoints.at(i); + p.SetP(spl.GetP4()); + p.SetAngle1(spl.GetEndAngle(), spl.GetEndAngleFormula()); + p.SetLength1(spl.GetC2Length(), spl.GetC2LengthFormula()); + splPoints[i] = p; + } + } + return splPoints; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector VCubicBezierPath::GetCubicPath() const { return d->path; } diff --git a/src/libs/vgeometry/vcubicbezierpath.h b/src/libs/vgeometry/vcubicbezierpath.h index b83fbd6f6..aa84f87e5 100644 --- a/src/libs/vgeometry/vcubicbezierpath.h +++ b/src/libs/vgeometry/vcubicbezierpath.h @@ -60,7 +60,8 @@ public: virtual qreal GetStartAngle () const Q_DECL_OVERRIDE; virtual qreal GetEndAngle () const Q_DECL_OVERRIDE; - QVector GetSplinePath() const; + virtual QVector GetSplinePath() const Q_DECL_OVERRIDE; + QVector GetCubicPath() const; static qint32 CountSubSpl(qint32 size); static qint32 SubSplOffset(qint32 subSplIndex); diff --git a/src/libs/vgeometry/vgeometrydef.h b/src/libs/vgeometry/vgeometrydef.h index 67e60764f..f083d1353 100644 --- a/src/libs/vgeometry/vgeometrydef.h +++ b/src/libs/vgeometry/vgeometrydef.h @@ -32,7 +32,7 @@ #include enum class Draw : char { Calculation, Modeling, Layout }; -enum class GOType : char { Point, Arc, EllipticalArc, Spline, SplinePath, CubicBezier, Unknown }; +enum class GOType : char { Point, Arc, EllipticalArc, Spline, SplinePath, CubicBezier, CubicBezierPath, Unknown }; enum class SplinePointPosition : char { FirstPoint, LastPoint }; #endif // VGEOMETRYDEF_H diff --git a/src/libs/vgeometry/vsplinepath.h b/src/libs/vgeometry/vsplinepath.h index 5ec9c183f..a683065c1 100644 --- a/src/libs/vgeometry/vsplinepath.h +++ b/src/libs/vgeometry/vsplinepath.h @@ -62,7 +62,7 @@ public: virtual void Clear() Q_DECL_OVERRIDE; virtual VSpline GetSpline(qint32 index) const Q_DECL_OVERRIDE; - QVector GetSplinePath() const; + virtual QVector GetSplinePath() const Q_DECL_OVERRIDE; QVector GetFSplinePath() const; virtual qreal GetStartAngle () const Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp index 80d2d1167..f73db268a 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp @@ -61,7 +61,7 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, flagFormula = false; CheckState(); - FillComboBoxSimpleSplines(ui->comboBoxSpline, FillComboBox::NoChildren, ch1, ch2); + FillComboBoxSplines(ui->comboBoxSpline, FillComboBox::NoChildren, ch1, ch2); FillComboBoxLineColors(ui->comboBoxColor); connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogCutSpline::FXLength); diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index 51877ee89..051def095 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -134,19 +134,43 @@ void DialogTool::FillComboBoxArcs(QComboBox *box, FillComboBox rule, const quint //--------------------------------------------------------------------------------------------------------------------- void DialogTool::FillComboBoxSplines(QComboBox *box, FillComboBox rule, const quint32 &ch1, const quint32 &ch2) const { - FillCombo(box, GOType::Spline, rule, ch1, ch2); + SCASSERT(box != nullptr); + box->blockSignals(true); + + const auto objs = data->DataGObjects(); + QHash >::const_iterator i; + QMap list; + for (i = objs->constBegin(); i != objs->constEnd(); ++i) + { + if (rule == FillComboBox::NoChildren) + { + if (i.key() != toolId && i.key() != ch1 && i.key() != ch2) + { + if (IsSpline(i.value())) + { + PrepareList(list, i.key()); + } + } + } + else + { + if (i.key() != toolId) + { + if (IsSpline(i.value())) + { + PrepareList(list, i.key()); + } + } + } + } + FillList(box, list); + + box->blockSignals(false); } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::FillComboBoxSplinesPath(QComboBox *box, FillComboBox rule, const quint32 &ch1, const quint32 &ch2) const -{ - FillCombo(box, GOType::SplinePath, rule, ch1, ch2); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogTool::FillComboBoxSimpleSplines(QComboBox *box, FillComboBox rule, const quint32 &ch1, - const quint32 &ch2) const { SCASSERT(box != nullptr); box->blockSignals(true); @@ -160,22 +184,9 @@ void DialogTool::FillComboBoxSimpleSplines(QComboBox *box, FillComboBox rule, co { if (i.key() != toolId && i.key() != ch1 && i.key() != ch2) { - QSharedPointer obj = i.value(); - if ((obj->getType() == GOType::Spline || obj->getType() == GOType::CubicBezier) && - obj->getMode() == Draw::Calculation) + if (IsSplinePath(i.value())) { - const auto curve = data->GeometricObject(i.key()); - - QString newName = curve->name(); - int bias = 0; - if (qApp->TrVars()->VariablesToUser(newName, 0, curve->name(), bias)) - { - list[newName] = i.key(); - } - else - { - list[curve->name()] = i.key(); - } + PrepareList(list, i.key()); } } } @@ -183,22 +194,9 @@ void DialogTool::FillComboBoxSimpleSplines(QComboBox *box, FillComboBox rule, co { if (i.key() != toolId) { - QSharedPointer obj = i.value(); - if ((obj->getType() == GOType::Spline || obj->getType() == GOType::CubicBezier) && - obj->getMode() == Draw::Calculation) + if (IsSplinePath(i.value())) { - const auto curve = data->GeometricObject(i.key()); - - QString newName = curve->name(); - int bias = 0; - if (qApp->TrVars()->VariablesToUser(newName, 0, curve->name(), bias)) - { - list[newName] = i.key(); - } - else - { - list[curve->name()] = i.key(); - } + PrepareList(list, i.key()); } } } @@ -221,21 +219,10 @@ void DialogTool::FillComboBoxCurves(QComboBox *box) const { QSharedPointer obj = i.value(); if ((obj->getType() == GOType::Arc || obj->getType() == GOType::Spline || - obj->getType() == GOType::SplinePath || obj->getType() == GOType::CubicBezier) && - obj->getMode() == Draw::Calculation) + obj->getType() == GOType::SplinePath || obj->getType() == GOType::CubicBezier || + obj->getType() == GOType::CubicBezierPath) && obj->getMode() == Draw::Calculation) { - const auto curve = data->GeometricObject(i.key()); - - QString newName = curve->name(); - int bias = 0; - if (qApp->TrVars()->VariablesToUser(newName, 0, curve->name(), bias)) - { - list[newName] = i.key(); - } - else - { - list[curve->name()] = i.key(); - } + PrepareList(list, i.key()); } } } @@ -390,6 +377,13 @@ quint32 DialogTool::DNumber(const QString &baseName) const return num; } +//--------------------------------------------------------------------------------------------------------------------- +bool DialogTool::IsSplinePath(const QSharedPointer &obj) const +{ + return (obj->getType() == GOType::SplinePath || obj->getType() == GOType::CubicBezierPath) && + obj->getMode() == Draw::Calculation; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ValFormulaChanged handle change formula @@ -676,6 +670,32 @@ void DialogTool::FillList(QComboBox *box, const QMap &list) co } } +//--------------------------------------------------------------------------------------------------------------------- +template +void DialogTool::PrepareList(QMap &list, quint32 id) const +{ + const auto obj = data->GeometricObject(id); + SCASSERT(obj != nullptr); + + QString newName = obj->name(); + int bias = 0; + if (qApp->TrVars()->VariablesToUser(newName, 0, obj->name(), bias)) + { + list[newName] = id; + } + else + { + list[obj->name()] = id; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogTool::IsSpline(const QSharedPointer &obj) const +{ + return (obj->getType() == GOType::Spline || obj->getType() == GOType::CubicBezier) && + obj->getMode() == Draw::Calculation; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief CheckState enable, when all is correct, or disable, when something wrong, button ok @@ -937,18 +957,7 @@ void DialogTool::FillCombo(QComboBox *box, GOType gType, FillComboBox rule, cons QSharedPointer obj = i.value(); if (obj->getType() == gType && obj->getMode() == Draw::Calculation) { - const QSharedPointer arc = data->GeometricObject(i.key()); - - QString newName = arc->name(); - int bias = 0; - if (qApp->TrVars()->VariablesToUser(newName, 0, arc->name(), bias)) - { - list[newName] = i.key(); - } - else - { - list[arc->name()] = i.key(); - } + PrepareList(list, i.key()); } } } @@ -959,18 +968,7 @@ void DialogTool::FillCombo(QComboBox *box, GOType gType, FillComboBox rule, cons QSharedPointer obj = i.value(); if (obj->getType() == gType && obj->getMode() == Draw::Calculation) { - const QSharedPointer arc = data->GeometricObject(i.key()); - - QString newName = arc->name(); - int bias = 0; - if (qApp->TrVars()->VariablesToUser(newName, 0, arc->name(), bias)) - { - list[newName] = i.key(); - } - else - { - list[arc->name()] = i.key(); - } + PrepareList(list, i.key()); } } } diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index 7722c1ec3..72322ade0 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -192,8 +192,6 @@ protected: const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID)const; void FillComboBoxSplinesPath(QComboBox *box, FillComboBox rule = FillComboBox::Whole, const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID)const; - void FillComboBoxSimpleSplines(QComboBox *box, FillComboBox rule = FillComboBox::Whole, - const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID)const; void FillComboBoxCurves(QComboBox *box)const; void FillComboBoxTypeLine(QComboBox *box, const QMap &stylesPics) const; void FillComboBoxLineColors(QComboBox *box)const; @@ -262,9 +260,17 @@ protected: private: void FillList(QComboBox *box, const QMap &list)const; + template + void PrepareList(QMap &list, quint32 id) const; + + bool IsSpline(const QSharedPointer &obj) const; + bool IsSplinePath(const QSharedPointer &obj) const; + template void FillCombo(QComboBox *box, GOType gType, FillComboBox rule = FillComboBox::Whole, const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID) const; + + }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp index 0f8a20a82..eac1dd822 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp @@ -123,17 +123,24 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString const QString &color, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation) { - const QSharedPointer splPath = data->GeometricObject(splinePathId); + const auto splPath = data->GeometricObject(splinePathId); SCASSERT(splPath != nullptr); const qreal result = CheckFormula(_id, formula, data); quint32 id = _id; - QPointF spl1p2, spl1p3, spl2p2, spl2p3; - qint32 p1 = 0, p2 = 0; + VSplinePath *splPath1 = nullptr; + VSplinePath *splPath2 = nullptr; + VPointF *p = VToolCutSplinePath::CutSplinePath(qApp->toPixel(result), splPath, &splPath1, &splPath2); + + SCASSERT(splPath1 != nullptr); + SCASSERT(splPath2 != nullptr); + SCASSERT(p != nullptr); + + p->setName(pointName); + p->setMx(mx); + p->setMy(my); - const QPointF point = splPath->CutSplinePath(qApp->toPixel(result), p1, p2, spl1p2, spl1p3, spl2p2, spl2p3); - VPointF *p = new VPointF(point, pointName, mx, my); if (typeCreation == Source::FromGui) { id = data->AddGObject(p); @@ -146,64 +153,6 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString quint32 splPath1id = id + 1; quint32 splPath2id = id + 2; - VSplinePoint splP1 = splPath->at(p1); - VSplinePoint splP2 = splPath->at(p2); - const VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, *p); - const VSpline spl2 = VSpline(*p, spl2p2, spl2p3, splP2.P()); - - VSplinePath *splPath1 = new VSplinePath(); - VSplinePath *splPath2 = new VSplinePath(); - - for (qint32 i = 0; i < splPath->CountPoints(); i++) - { - if (i <= p1 && i < p2) - { - if (i == p1) - { - const qreal angle1 = spl1.GetStartAngle()+180; - const QString angle1F = QString().number(angle1); - - splPath1->append(VSplinePoint(splP1.P(), angle1, angle1F, spl1.GetStartAngle(), - spl1.GetStartAngleFormula(), splP1.Length1(), splP1.Length1Formula(), - spl1.GetC1Length(), spl1.GetC1LengthFormula())); - - const qreal angle2 = spl1.GetEndAngle()+180; - const QString angle2F = QString().number(angle2); - - const auto cutPoint = VSplinePoint(*p, spl1.GetEndAngle(), spl1.GetEndAngleFormula(), angle2, angle2F, - spl1.GetC2Length(), spl1.GetC2LengthFormula(), spl2.GetC1Length(), - spl2.GetC1LengthFormula()); - splPath1->append(cutPoint); - continue; - } - splPath1->append(splPath->at(i)); - } - else - { - if (i == p2) - { - const qreal angle1 = spl2.GetStartAngle()+180; - const QString angle1F = QString().number(angle1); - - const auto cutPoint = VSplinePoint(*p, angle1, angle1F, spl2.GetStartAngle(), - spl2.GetStartAngleFormula(), spl1.GetC2Length(), - spl1.GetC2LengthFormula(), spl2.GetC1Length(), - spl2.GetC1LengthFormula()); - - splPath2->append(cutPoint); - - const qreal angle2 = spl2.GetEndAngle()+180; - const QString angle2F = QString().number(angle2); - - splPath2->append(VSplinePoint(splP2.P(), spl2.GetEndAngle(), spl2.GetEndAngleFormula(), angle2, angle2F, - spl2.GetC2Length(), spl2.GetC2LengthFormula(), splP2.Length2(), - splP2.Length2Formula())); - continue; - } - splPath2->append(splPath->at(i)); - } - } - if (typeCreation == Source::FromGui) { splPath1id = data->AddGObject(splPath1); @@ -252,6 +201,81 @@ void VToolCutSplinePath::ShowVisualization(bool show) ShowToolVisualization(show); } +//--------------------------------------------------------------------------------------------------------------------- +VPointF *VToolCutSplinePath::CutSplinePath(qreal length, const QSharedPointer &splPath, + VSplinePath **splPath1, VSplinePath **splPath2) +{ + SCASSERT(splPath != nullptr); + + QPointF spl1p2, spl1p3, spl2p2, spl2p3; + qint32 p1 = 0, p2 = 0; + + const QPointF point = splPath->CutSplinePath(length, p1, p2, spl1p2, spl1p3, spl2p2, spl2p3); + VPointF *p = new VPointF(point); + + const QVector points = splPath->GetSplinePath(); + + const VSplinePoint splP1 = points.at(p1); + const VSplinePoint splP2 = points.at(p2); + const VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, *p); + const VSpline spl2 = VSpline(*p, spl2p2, spl2p3, splP2.P()); + + *splPath1 = new VSplinePath(); + *splPath2 = new VSplinePath(); + + for (qint32 i = 0; i < points.size(); i++) + { + if (i <= p1 && i < p2) + { + if (i == p1) + { + const qreal angle1 = spl1.GetStartAngle()+180; + const QString angle1F = QString().number(angle1); + + (*splPath1)->append(VSplinePoint(splP1.P(), angle1, angle1F, spl1.GetStartAngle(), + spl1.GetStartAngleFormula(), splP1.Length1(), splP1.Length1Formula(), + spl1.GetC1Length(), spl1.GetC1LengthFormula())); + + const qreal angle2 = spl1.GetEndAngle()+180; + const QString angle2F = QString().number(angle2); + + const auto cutPoint = VSplinePoint(*p, spl1.GetEndAngle(), spl1.GetEndAngleFormula(), angle2, angle2F, + spl1.GetC2Length(), spl1.GetC2LengthFormula(), spl2.GetC1Length(), + spl2.GetC1LengthFormula()); + (*splPath1)->append(cutPoint); + continue; + } + (*splPath1)->append(points.at(i)); + } + else + { + if (i == p2) + { + const qreal angle1 = spl2.GetStartAngle()+180; + const QString angle1F = QString().number(angle1); + + const auto cutPoint = VSplinePoint(*p, angle1, angle1F, spl2.GetStartAngle(), + spl2.GetStartAngleFormula(), spl1.GetC2Length(), + spl1.GetC2LengthFormula(), spl2.GetC1Length(), + spl2.GetC1LengthFormula()); + + (*splPath2)->append(cutPoint); + + const qreal angle2 = spl2.GetEndAngle()+180; + const QString angle2F = QString().number(angle2); + + (*splPath2)->append(VSplinePoint(splP2.P(), spl2.GetEndAngle(), spl2.GetEndAngleFormula(), angle2, + angle2F, spl2.GetC2Length(), spl2.GetC2LengthFormula(), + splP2.Length2(), splP2.Length2Formula())); + continue; + } + (*splPath2)->append(points.at(i)); + } + } + + return p; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h index 040c271a4..65ab52353 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h @@ -31,6 +31,9 @@ #include "vtoolcut.h" +class VAbstractCubicBezierPath; +class VSplinePath; + /** * @brief The VToolCutSplinePath class for tool CutSplinePath. This tool find point on splinePath and cut splinePath on * two. @@ -56,6 +59,9 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::CutSplinePath)}; virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; + + static VPointF *CutSplinePath(qreal length, const QSharedPointer &splPath, + VSplinePath **splPath1, VSplinePath **splPath2); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp b/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp index 5e0445836..198f64938 100644 --- a/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp +++ b/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp @@ -56,7 +56,7 @@ VisToolCubicBezierPath::~VisToolCubicBezierPath() //--------------------------------------------------------------------------------------------------------------------- void VisToolCubicBezierPath::RefreshGeometry() { - const QVector pathPoints = path.GetSplinePath(); + const QVector pathPoints = path.GetCubicPath(); const int size = pathPoints.size(); if (size > 0) { diff --git a/src/libs/vtools/visualization/vistoolcutsplinepath.cpp b/src/libs/vtools/visualization/vistoolcutsplinepath.cpp index 35737a802..dc29ce613 100644 --- a/src/libs/vtools/visualization/vistoolcutsplinepath.cpp +++ b/src/libs/vtools/visualization/vistoolcutsplinepath.cpp @@ -27,8 +27,9 @@ *************************************************************************/ #include "vistoolcutsplinepath.h" -#include "../../vpatterndb/vcontainer.h" -#include "../../vgeometry/vsplinepath.h" +#include "../vpatterndb/vcontainer.h" +#include "../vgeometry/vsplinepath.h" +#include "../tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h" //--------------------------------------------------------------------------------------------------------------------- VisToolCutSplinePath::VisToolCutSplinePath(const VContainer *data, QGraphicsItem *parent) @@ -53,83 +54,26 @@ void VisToolCutSplinePath::RefreshGeometry() { if (object1Id > NULL_ID) { - const QSharedPointer splPath = Visualization::data->GeometricObject(object1Id); + const auto splPath = Visualization::data->GeometricObject(object1Id); DrawPath(this, splPath->GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); - if (qFuzzyCompare(1 + length, 1 + 0) == false) + if (not qFuzzyIsNull(length)) { - QPointF spl1p2, spl1p3, spl2p2, spl2p3; - qint32 p1 = 0, p2 = 0; + VSplinePath *spPath1 = nullptr; + VSplinePath *spPath2 = nullptr; + VPointF *p = VToolCutSplinePath::CutSplinePath(length, splPath, &spPath1, &spPath2); + SCASSERT(p != nullptr); + SCASSERT(spPath1 != nullptr); + SCASSERT(spPath2 != nullptr); - // TODO make refactoring. CutSplPath repeat twice. Here and in VToolCutSpline. - const QPointF cutPoint = splPath->CutSplinePath(length, p1, p2, spl1p2, spl1p3, spl2p2, spl2p3); - VPointF p = VPointF(cutPoint); + DrawPoint(point, p->toQPointF(), mainColor); + delete p; - VSplinePoint splP1 = splPath->at(p1); - VSplinePoint splP2 = splPath->at(p2); - const VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, p); - const VSpline spl2 = VSpline(p, spl2p2, spl2p3, splP2.P()); + DrawPath(splPath1, spPath1->GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap); + DrawPath(splPath2, spPath2->GetPath(PathDirection::Show), Qt::darkRed, Qt::SolidLine, Qt::RoundCap); - VSplinePath spPath1 = VSplinePath(); - VSplinePath spPath2 = VSplinePath(); - - for (qint32 i = 0; i < splPath->CountPoints(); i++) - { - if (i <= p1 && i < p2) - { - if (i == p1) - { - const qreal angle1 = spl1.GetStartAngle()+180; - const QString angle1F = QString().number(angle1); - - spPath1.append(VSplinePoint(splP1.P(), angle1, angle1F, spl1.GetStartAngle(), - spl1.GetStartAngleFormula(), splP1.Length1(), - splP1.Length1Formula(), spl1.GetC1Length(), - spl1.GetC1LengthFormula())); - - const qreal angle2 = spl1.GetEndAngle()+180; - const QString angle2F = QString().number(angle2); - - const auto cutPoint = VSplinePoint(p, spl1.GetEndAngle(), spl1.GetEndAngleFormula(), angle2, - angle2F, spl1.GetC2Length(), spl1.GetC2LengthFormula(), - spl2.GetC1Length(), spl2.GetC1LengthFormula()); - - spPath1.append(cutPoint); - continue; - } - spPath1.append(splPath->at(i)); - } - else - { - if (i == p2) - { - const qreal angle1 = spl2.GetStartAngle()+180; - const QString angle1F = QString().number(angle1); - - const auto cutPoint = VSplinePoint(p, angle1, angle1F, spl2.GetStartAngle(), - spl2.GetStartAngleFormula(), spl1.GetC2Length(), - spl1.GetC2LengthFormula(), spl2.GetC1Length(), - spl2.GetC1LengthFormula()); - - spPath2.append(cutPoint); - - const qreal angle2 = spl2.GetEndAngle()+180; - const QString angle2F = QString().number(angle2); - - spPath2.append(VSplinePoint(splP2.P(), spl2.GetEndAngle(), spl2.GetEndAngleFormula(), angle2, - angle2F, spl2.GetC2Length(), spl2.GetC2LengthFormula(), - splP2.Length2(), splP2.Length2Formula())); - - continue; - } - spPath2.append(splPath->at(i)); - } - } - - DrawPoint(point, cutPoint, mainColor); - - DrawPath(splPath1, spPath1.GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap); - DrawPath(splPath2, spPath2.GetPath(PathDirection::Show), Qt::darkRed, Qt::SolidLine, Qt::RoundCap); + delete spPath1; + delete spPath2; } } }