Improve tool Point of intersection curves. Closes #119

This commit is contained in:
Roman Telezhynskyi 2021-04-09 18:06:34 +03:00
parent 2a9adb5d88
commit dbf7343c87
5 changed files with 189 additions and 167 deletions

View File

@ -1,5 +1,6 @@
# Version 0.7.47 (unreleased) # Version 0.7.47 (unreleased)
- [smart-pattern/valentina#118] Incorrect seam allowance. - [smart-pattern/valentina#118] Incorrect seam allowance.
- [smart-pattern/valentina#119] Improve tool Point of intersection curves.
# Version 0.7.46 Mar 31, 2021 # Version 0.7.46 Mar 31, 2021
- Fix incorrect calculation of value for multisize measurements in Valentina. - Fix incorrect calculation of value for multisize measurements in Valentina.

View File

@ -150,7 +150,7 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis
const qreal segLength = curve->GetLengthByPoint(fPoint); 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); p->SetShowLabel(initData.showLabel);
if (initData.typeCreation == Source::FromGui) if (initData.typeCreation == Source::FromGui)
@ -160,14 +160,14 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis
initData.data->getNextId(); initData.data->getNextId();
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 else
{ {
initData.data->UpdateGObject(initData.id, p); initData.data->UpdateGObject(initData.id, p);
initData.data->AddLine(initData.basePointId, initData.id); 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) if (initData.parse != Document::FullParse)
{ {
@ -178,7 +178,7 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis
if (initData.parse == Document::FullParse) if (initData.parse == Document::FullParse)
{ {
VAbstractTool::AddRecord(initData.id, Tool::CurveIntersectAxis, initData.doc); VAbstractTool::AddRecord(initData.id, Tool::CurveIntersectAxis, initData.doc);
VToolCurveIntersectAxis *point = new VToolCurveIntersectAxis(initData); auto *point = new VToolCurveIntersectAxis(initData);
initData.scene->addItem(point); initData.scene->addItem(point);
InitToolConnections(initData.scene, point); InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point); VAbstractPattern::AddTool(initData.id, point);
@ -308,163 +308,3 @@ void VToolCurveIntersectAxis::SetVisualization()
visual->RefreshGeometry(); visual->RefreshGeometry();
} }
} }
//---------------------------------------------------------------------------------------------------------------------
template <class Item>
void VToolCurveIntersectAxis::InitArc(VContainer *data, qreal segLength, const VPointF *p, quint32 curveId)
{
QSharedPointer<Item> a1;
QSharedPointer<Item> a2;
const QSharedPointer<Item> arc = data->GeometricObject<Item>(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<Item>(new Item(arc1));
a2 = QSharedPointer<Item>(new Item(arc2));
}
else
{
a1 = QSharedPointer<Item>(new Item());
a2 = QSharedPointer<Item>(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<VEllipticalArc>(data, segLength, p, curveId);
break;
case GOType::Arc:
InitArc<VArc>(data, segLength, p, curveId);
break;
case GOType::CubicBezier:
case GOType::Spline:
{
QSharedPointer<VAbstractBezier> spline1;
QSharedPointer<VAbstractBezier> spline2;
const auto spl = data->GeometricObject<VAbstractCubicBezier>(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<VAbstractBezier>(spl1);
spline2 = QSharedPointer<VAbstractBezier>(spl2);
}
else
{
spline1 = QSharedPointer<VAbstractBezier>(new VSpline());
spline2 = QSharedPointer<VAbstractBezier>(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<VAbstractBezier> splP1;
QSharedPointer<VAbstractBezier> splP2;
const auto splPath = data->GeometricObject<VAbstractCubicBezierPath>(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<VAbstractBezier>(splPath1);
splP2 = QSharedPointer<VAbstractBezier>(splPath2);
}
else
{
splP1 = QSharedPointer<VAbstractBezier>(new VSplinePath());
splP2 = QSharedPointer<VAbstractBezier>(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

View File

@ -119,9 +119,9 @@ VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(VToolPoin
auto curve1 = initData.data->GeometricObject<VAbstractCurve>(initData.firstCurveId); auto curve1 = initData.data->GeometricObject<VAbstractCurve>(initData.firstCurveId);
auto curve2 = initData.data->GeometricObject<VAbstractCurve>(initData.secondCurveId); auto curve2 = initData.data->GeometricObject<VAbstractCurve>(initData.secondCurveId);
QPointF point; QPointF fPoint;
const bool success = VToolPointOfIntersectionCurves::FindPoint(curve1->GetPoints(), curve2->GetPoints(), const bool success = VToolPointOfIntersectionCurves::FindPoint(curve1->GetPoints(), curve2->GetPoints(),
initData.vCrossPoint, initData.hCrossPoint, &point); initData.vCrossPoint, initData.hCrossPoint, &fPoint);
if (not success) if (not success)
{ {
@ -131,16 +131,26 @@ VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(VToolPoin
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; 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); p->SetShowLabel(initData.showLabel);
if (initData.typeCreation == Source::FromGui) if (initData.typeCreation == Source::FromGui)
{ {
initData.id = initData.data->AddGObject(p); 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 else
{ {
initData.data->UpdateGObject(initData.id, p); 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) if (initData.parse != Document::FullParse)
{ {
initData.doc->UpdateToolData(initData.id, initData.data); initData.doc->UpdateToolData(initData.id, initData.data);

View File

@ -52,6 +52,12 @@
#include "../vmisc/diagnostic.h" #include "../vmisc/diagnostic.h"
#include "../vgeometry/vgobject.h" #include "../vgeometry/vgobject.h"
#include "../vgeometry/vpointf.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 "../vmisc/vabstractapplication.h"
#include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vcontainer.h"
#include "../vwidgets/vgraphicssimpletextitem.h" #include "../vwidgets/vgraphicssimpletextitem.h"
@ -59,6 +65,7 @@
#include "../../../vabstracttool.h" #include "../../../vabstracttool.h"
#include "../../vdrawtool.h" #include "../../vdrawtool.h"
#include "../vabstractpoint.h" #include "../vabstractpoint.h"
#include "toolcut/vtoolcutsplinepath.h"
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes") QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
@ -384,3 +391,120 @@ void VToolSinglePoint::ToolSelectionType(const SelectionType &type)
VAbstractTool::ToolSelectionType(type); VAbstractTool::ToolSelectionType(type);
m_namePoint->LabelSelectionType(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<VEllipticalArc>(data, segLength, p, curveId);
break;
case GOType::Arc:
InitArc<VArc>(data, segLength, p, curveId);
break;
case GOType::CubicBezier:
case GOType::Spline:
{
QSharedPointer<VAbstractBezier> spline1;
QSharedPointer<VAbstractBezier> spline2;
const auto spl = data->GeometricObject<VAbstractCubicBezier>(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<VAbstractBezier>(spl1);
spline2 = QSharedPointer<VAbstractBezier>(spl2);
}
else
{
spline1 = QSharedPointer<VAbstractBezier>(new VSpline());
spline2 = QSharedPointer<VAbstractBezier>(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<VAbstractBezier> splP1;
QSharedPointer<VAbstractBezier> splP2;
const auto splPath = data->GeometricObject<VAbstractCubicBezierPath>(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<VAbstractBezier>(splPath1);
splP2 = QSharedPointer<VAbstractBezier>(splPath2);
}
else
{
splP1 = QSharedPointer<VAbstractBezier>(new VSplinePath());
splP2 = QSharedPointer<VAbstractBezier>(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

View File

@ -106,8 +106,55 @@ protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) override; virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) override;
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) override; virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) override;
virtual void ChangeLabelVisibility(quint32 id, bool visible) override; virtual void ChangeLabelVisibility(quint32 id, bool visible) override;
template <class Item>
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: private:
Q_DISABLE_COPY(VToolSinglePoint) Q_DISABLE_COPY(VToolSinglePoint)
}; };
//---------------------------------------------------------------------------------------------------------------------
template <class Item>
inline void VToolSinglePoint::InitArc(VContainer *data, qreal segLength, const VPointF *p, quint32 curveId)
{
QSharedPointer<Item> a1;
QSharedPointer<Item> a2;
const QSharedPointer<Item> arc = data->GeometricObject<Item>(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<Item>(new Item(arc1));
a2 = QSharedPointer<Item>(new Item(arc2));
}
else
{
a1 = QSharedPointer<Item>(new Item());
a2 = QSharedPointer<Item>(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 #endif // VTOOLSINGLEPOINT_H