diff --git a/ChangeLog.txt b/ChangeLog.txt index b4e361cfb..49b1e178b 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,6 @@ # Version 0.7.47 (unreleased) - [smart-pattern/valentina#118] Incorrect seam allowance. +- [smart-pattern/valentina#119] Improve tool Point of intersection curves. # Version 0.7.46 Mar 31, 2021 - Fix incorrect calculation of value for multisize measurements in Valentina. diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp index c69611b09..b1260c3dc 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp @@ -150,7 +150,7 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis const qreal segLength = curve->GetLengthByPoint(fPoint); - VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); + auto *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); p->SetShowLabel(initData.showLabel); if (initData.typeCreation == Source::FromGui) @@ -160,14 +160,14 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis initData.data->getNextId(); initData.data->getNextId(); - InitSegments(curve->getType(), segLength, p, initData.curveId, initData.data); + VToolSinglePoint::InitSegments(curve->getType(), segLength, p, initData.curveId, initData.data); } else { initData.data->UpdateGObject(initData.id, p); initData.data->AddLine(initData.basePointId, initData.id); - InitSegments(curve->getType(), segLength, p, initData.curveId, initData.data); + VToolSinglePoint::InitSegments(curve->getType(), segLength, p, initData.curveId, initData.data); if (initData.parse != Document::FullParse) { @@ -178,7 +178,7 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis if (initData.parse == Document::FullParse) { VAbstractTool::AddRecord(initData.id, Tool::CurveIntersectAxis, initData.doc); - VToolCurveIntersectAxis *point = new VToolCurveIntersectAxis(initData); + auto *point = new VToolCurveIntersectAxis(initData); initData.scene->addItem(point); InitToolConnections(initData.scene, point); VAbstractPattern::AddTool(initData.id, point); @@ -308,163 +308,3 @@ void VToolCurveIntersectAxis::SetVisualization() visual->RefreshGeometry(); } } - -//--------------------------------------------------------------------------------------------------------------------- -template -void VToolCurveIntersectAxis::InitArc(VContainer *data, qreal segLength, const VPointF *p, quint32 curveId) -{ - QSharedPointer a1; - QSharedPointer a2; - - const QSharedPointer arc = data->GeometricObject(curveId); - Item arc1; - Item arc2; - - if (not VFuzzyComparePossibleNulls(segLength, -1)) - { - arc->CutArc(segLength, arc1, arc2); - } - else - { - arc->CutArc(0, arc1, arc2); - } - - // Arc highly depend on id. Need for creating the name. - arc1.setId(p->id() + 1); - arc2.setId(p->id() + 2); - - if (not VFuzzyComparePossibleNulls(segLength, -1)) - { - a1 = QSharedPointer(new Item(arc1)); - a2 = QSharedPointer(new Item(arc2)); - } - else - { - a1 = QSharedPointer(new Item()); - a2 = QSharedPointer(new Item()); - - // Take names for empty arcs from donors. - a1->setName(arc1.name()); - a2->setName(arc2.name()); - } - - data->AddArc(a1, arc1.id(), p->id()); - data->AddArc(a2, arc2.id(), p->id()); -} - -//--------------------------------------------------------------------------------------------------------------------- -QT_WARNING_PUSH -QT_WARNING_DISABLE_GCC("-Wswitch-default") -void VToolCurveIntersectAxis::InitSegments(GOType curveType, qreal segLength, const VPointF *p, quint32 curveId, - VContainer *data) -{ - switch(curveType) - { - case GOType::EllipticalArc: - InitArc(data, segLength, p, curveId); - break; - case GOType::Arc: - InitArc(data, segLength, p, curveId); - break; - case GOType::CubicBezier: - case GOType::Spline: - { - QSharedPointer spline1; - QSharedPointer spline2; - - const auto spl = data->GeometricObject(curveId); - QPointF spl1p2, spl1p3, spl2p2, spl2p3; - if (not VFuzzyComparePossibleNulls(segLength, -1)) - { - spl->CutSpline(segLength, spl1p2, spl1p3, spl2p2, spl2p3); - } - else - { - spl->CutSpline(0, spl1p2, spl1p3, spl2p2, spl2p3); - } - - VSpline *spl1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p); - VSpline *spl2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4()); - - if (not VFuzzyComparePossibleNulls(segLength, -1)) - { - spline1 = QSharedPointer(spl1); - spline2 = QSharedPointer(spl2); - } - else - { - spline1 = QSharedPointer(new VSpline()); - spline2 = QSharedPointer(new VSpline()); - - // Take names for empty splines from donors. - spline1->setName(spl1->name()); - spline2->setName(spl2->name()); - - delete spl1; - delete spl2; - } - - data->RegisterUniqueName(spline1); - data->AddSpline(spline1, NULL_ID, p->id()); - - data->RegisterUniqueName(spline2); - data->AddSpline(spline2, NULL_ID, p->id()); - break; - } - case GOType::CubicBezierPath: - case GOType::SplinePath: - { - QSharedPointer splP1; - QSharedPointer splP2; - - const auto splPath = data->GeometricObject(curveId); - VSplinePath *splPath1 = nullptr; - VSplinePath *splPath2 = nullptr; - if (not VFuzzyComparePossibleNulls(segLength, -1)) - { - VPointF *pC = VToolCutSplinePath::CutSplinePath(segLength, splPath, p->name(), &splPath1, &splPath2); - delete pC; - } - else - { - VPointF *pC = VToolCutSplinePath::CutSplinePath(0, splPath, p->name(), &splPath1, &splPath2); - delete pC; - } - - SCASSERT(splPath1 != nullptr) - SCASSERT(splPath2 != nullptr) - - if (not VFuzzyComparePossibleNulls(segLength, -1)) - { - splP1 = QSharedPointer(splPath1); - splP2 = QSharedPointer(splPath2); - } - else - { - splP1 = QSharedPointer(new VSplinePath()); - splP2 = QSharedPointer(new VSplinePath()); - - // Take names for empty spline paths from donors. - splP1->setName(splPath1->name()); - splP2->setName(splPath2->name()); - - delete splPath1; - delete splPath2; - } - - data->RegisterUniqueName(splP1); - data->AddSpline(splP1, NULL_ID, p->id()); - - data->RegisterUniqueName(splP2); - data->AddSpline(splP2, NULL_ID, p->id()); - break; - } - case GOType::Point: - case GOType::PlaceLabel: - case GOType::Unknown: - Q_UNREACHABLE(); - break; - } -} - -QT_WARNING_POP diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp index 6378c4223..113c467b3 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp @@ -119,9 +119,9 @@ VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(VToolPoin auto curve1 = initData.data->GeometricObject(initData.firstCurveId); auto curve2 = initData.data->GeometricObject(initData.secondCurveId); - QPointF point; + QPointF fPoint; const bool success = VToolPointOfIntersectionCurves::FindPoint(curve1->GetPoints(), curve2->GetPoints(), - initData.vCrossPoint, initData.hCrossPoint, &point); + initData.vCrossPoint, initData.hCrossPoint, &fPoint); if (not success) { @@ -131,16 +131,26 @@ VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(VToolPoin qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; } - VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); + const qreal segLength1 = curve1->GetLengthByPoint(fPoint); + const qreal segLength2 = curve2->GetLengthByPoint(fPoint); + + auto *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); p->SetShowLabel(initData.showLabel); if (initData.typeCreation == Source::FromGui) { initData.id = initData.data->AddGObject(p); + + VToolSinglePoint::InitSegments(curve1->getType(), segLength1, p, initData.firstCurveId, initData.data); + VToolSinglePoint::InitSegments(curve2->getType(), segLength2, p, initData.secondCurveId, initData.data); } else { initData.data->UpdateGObject(initData.id, p); + + VToolSinglePoint::InitSegments(curve1->getType(), segLength1, p, initData.firstCurveId, initData.data); + VToolSinglePoint::InitSegments(curve2->getType(), segLength2, p, initData.secondCurveId, initData.data); + if (initData.parse != Document::FullParse) { initData.doc->UpdateToolData(initData.id, initData.data); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index 547c392eb..96d2fbab9 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -52,6 +52,12 @@ #include "../vmisc/diagnostic.h" #include "../vgeometry/vgobject.h" #include "../vgeometry/vpointf.h" +#include "../vgeometry/vabstractcubicbezierpath.h" +#include "../vgeometry/vabstractcubicbezier.h" +#include "../vgeometry/vspline.h" +#include "../vgeometry/vsplinepath.h" +#include "../vgeometry/vellipticalarc.h" +#include "../vgeometry/varc.h" #include "../vmisc/vabstractapplication.h" #include "../vpatterndb/vcontainer.h" #include "../vwidgets/vgraphicssimpletextitem.h" @@ -59,6 +65,7 @@ #include "../../../vabstracttool.h" #include "../../vdrawtool.h" #include "../vabstractpoint.h" +#include "toolcut/vtoolcutsplinepath.h" QT_WARNING_PUSH QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes") @@ -384,3 +391,120 @@ void VToolSinglePoint::ToolSelectionType(const SelectionType &type) VAbstractTool::ToolSelectionType(type); m_namePoint->LabelSelectionType(type); } + +//--------------------------------------------------------------------------------------------------------------------- +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") +void VToolSinglePoint::InitSegments(GOType curveType, qreal segLength, const VPointF *p, quint32 curveId, + VContainer *data) +{ + switch(curveType) + { + case GOType::EllipticalArc: + InitArc(data, segLength, p, curveId); + break; + case GOType::Arc: + InitArc(data, segLength, p, curveId); + break; + case GOType::CubicBezier: + case GOType::Spline: + { + QSharedPointer spline1; + QSharedPointer spline2; + + const auto spl = data->GeometricObject(curveId); + QPointF spl1p2, spl1p3, spl2p2, spl2p3; + if (not VFuzzyComparePossibleNulls(segLength, -1)) + { + spl->CutSpline(segLength, spl1p2, spl1p3, spl2p2, spl2p3); + } + else + { + spl->CutSpline(0, spl1p2, spl1p3, spl2p2, spl2p3); + } + + VSpline *spl1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p); + VSpline *spl2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4()); + + if (not VFuzzyComparePossibleNulls(segLength, -1)) + { + spline1 = QSharedPointer(spl1); + spline2 = QSharedPointer(spl2); + } + else + { + spline1 = QSharedPointer(new VSpline()); + spline2 = QSharedPointer(new VSpline()); + + // Take names for empty splines from donors. + spline1->setName(spl1->name()); + spline2->setName(spl2->name()); + + delete spl1; + delete spl2; + } + + data->RegisterUniqueName(spline1); + data->AddSpline(spline1, NULL_ID, p->id()); + + data->RegisterUniqueName(spline2); + data->AddSpline(spline2, NULL_ID, p->id()); + break; + } + case GOType::CubicBezierPath: + case GOType::SplinePath: + { + QSharedPointer splP1; + QSharedPointer splP2; + + const auto splPath = data->GeometricObject(curveId); + VSplinePath *splPath1 = nullptr; + VSplinePath *splPath2 = nullptr; + if (not VFuzzyComparePossibleNulls(segLength, -1)) + { + VPointF *pC = VToolCutSplinePath::CutSplinePath(segLength, splPath, p->name(), &splPath1, &splPath2); + delete pC; + } + else + { + VPointF *pC = VToolCutSplinePath::CutSplinePath(0, splPath, p->name(), &splPath1, &splPath2); + delete pC; + } + + SCASSERT(splPath1 != nullptr) + SCASSERT(splPath2 != nullptr) + + if (not VFuzzyComparePossibleNulls(segLength, -1)) + { + splP1 = QSharedPointer(splPath1); + splP2 = QSharedPointer(splPath2); + } + else + { + splP1 = QSharedPointer(new VSplinePath()); + splP2 = QSharedPointer(new VSplinePath()); + + // Take names for empty spline paths from donors. + splP1->setName(splPath1->name()); + splP2->setName(splPath2->name()); + + delete splPath1; + delete splPath2; + } + + data->RegisterUniqueName(splP1); + data->AddSpline(splP1, NULL_ID, p->id()); + + data->RegisterUniqueName(splP2); + data->AddSpline(splP2, NULL_ID, p->id()); + break; + } + case GOType::Point: + case GOType::PlaceLabel: + case GOType::Unknown: + Q_UNREACHABLE(); + break; + } +} + +QT_WARNING_POP diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h index 926a0b20e..6fae77723 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h @@ -106,8 +106,55 @@ protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) override; virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) override; virtual void ChangeLabelVisibility(quint32 id, bool visible) override; + + template + static void InitArc(VContainer *data, qreal segLength, const VPointF *p, quint32 curveId); + static void InitSegments(GOType curveType, qreal segLength, const VPointF *p, quint32 curveId, VContainer *data); private: Q_DISABLE_COPY(VToolSinglePoint) }; +//--------------------------------------------------------------------------------------------------------------------- +template +inline void VToolSinglePoint::InitArc(VContainer *data, qreal segLength, const VPointF *p, quint32 curveId) +{ + QSharedPointer a1; + QSharedPointer a2; + + const QSharedPointer arc = data->GeometricObject(curveId); + Item arc1; + Item arc2; + + if (not VFuzzyComparePossibleNulls(segLength, -1)) + { + arc->CutArc(segLength, arc1, arc2); + } + else + { + arc->CutArc(0, arc1, arc2); + } + + // Arc highly depend on id. Need for creating the name. + arc1.setId(p->id() + 1); + arc2.setId(p->id() + 2); + + if (not VFuzzyComparePossibleNulls(segLength, -1)) + { + a1 = QSharedPointer(new Item(arc1)); + a2 = QSharedPointer(new Item(arc2)); + } + else + { + a1 = QSharedPointer(new Item()); + a2 = QSharedPointer(new Item()); + + // Take names for empty arcs from donors. + a1->setName(arc1.name()); + a2->setName(arc2.name()); + } + + data->AddArc(a1, arc1.id(), p->id()); + data->AddArc(a2, arc2.id(), p->id()); +} + #endif // VTOOLSINGLEPOINT_H