From 83e9a4c8f0061368bf880f2484187e8d8fbc6225 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 27 Aug 2022 17:57:08 +0300 Subject: [PATCH] Enable Approximation scale option for Elliptical arc. --- ChangeLog.txt | 1 + .../core/vtooloptionspropertybrowser.cpp | 8 +++++ src/libs/vgeometry/vellipticalarc.cpp | 2 +- .../dialogs/tools/dialogellipticalarc.cpp | 17 +++++++++++ .../dialogs/tools/dialogellipticalarc.h | 3 ++ .../dialogs/tools/dialogellipticalarc.ui | 29 +++++++++++++++++-- .../toolcurve/vtoolellipticalarc.cpp | 21 ++++++++++++++ .../drawTools/toolcurve/vtoolellipticalarc.h | 3 ++ .../path/vistoolellipticalarc.cpp | 1 + 9 files changed, 81 insertions(+), 4 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 2679aa0dd..36bebc0e0 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -21,6 +21,7 @@ - Fix export tiled pdf on Mac OS. - Improve visualization for tools. - Fix calculating an elliptical arc. +- Enable Approximation scale option for Elliptical arc. # Valentina 0.7.51 April 18, 2022 - Z value change for a layout piece. diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index ed6838a37..fc01c75b7 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -2668,6 +2668,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolEllipticalArc(VPE::VProperty *pr case 59: // AttrPenStyle SetPenStyle(property); break; + case 60: // AttrAScale + SetApproximationScale(property); + break; case 61: // AttrNotes SetNotes(property); break; @@ -3301,6 +3304,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolEllipticalArc(QGraphicsItem *it AddPropertyFormula(tr("Rotation angle:"), i->GetFormulaRotationAngle(), AttrRotationAngle); AddPropertyAlias(i, tr("Alias:")); AddPropertyLineColor(i, tr("Color:"), VAbstractTool::ColorsList(), AttrColor); + AddPropertyApproximationScale(tr("Approximation scale:"), i->GetApproximationScale()); AddPropertyText(tr("Notes:"), i->GetNotes(), AttrNotes); } @@ -4267,6 +4271,10 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolEllipticalArc() valueCenterPoint.setValue(i->CenterPointName()); m_idToProperty[AttrCenter]->setValue(valueCenterPoint); + QVariant valueApproximationScale; + valueApproximationScale.setValue(i->GetApproximationScale()); + m_idToProperty[AttrAScale]->setValue(valueApproximationScale); + m_idToProperty[AttrNotes]->setValue(i->GetNotes()); m_idToProperty[AttrAlias]->setValue(i->GetAliasSuffix()); diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 7554aae4f..8190f5792 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -46,7 +46,7 @@ namespace { -constexpr qreal tolerance = accuracyPointOnLine/32; +constexpr qreal tolerance = accuracyPointOnLine/8; //--------------------------------------------------------------------------------------------------------------------- auto VLen(fpm::fixed_16_16 x, fpm::fixed_16_16 y) -> fpm::fixed_16_16 { diff --git a/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp b/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp index 54f8bf9b9..418935720 100644 --- a/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp @@ -374,6 +374,22 @@ void DialogEllipticalArc::SetColor(const QString &value) ChangeCurrentData(ui->comboBoxColor, value); } +//--------------------------------------------------------------------------------------------------------------------- +qreal DialogEllipticalArc::GetApproximationScale() const +{ + return ui->doubleSpinBoxApproximationScale->value(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEllipticalArc::SetApproximationScale(qreal value) +{ + ui->doubleSpinBoxApproximationScale->setValue(value); + + auto *path = qobject_cast(vis); + SCASSERT(path != nullptr) + path->SetApproximationScale(value); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief EvalRadiuses calculate value of radiuses @@ -682,6 +698,7 @@ void DialogEllipticalArc::SaveData() path->SetF1(m_f1); path->SetF2(m_f2); path->SetRotationAngle(m_rotationAngle); + path->SetApproximationScale(ui->doubleSpinBoxApproximationScale->value()); path->RefreshGeometry(); } diff --git a/src/libs/vtools/dialogs/tools/dialogellipticalarc.h b/src/libs/vtools/dialogs/tools/dialogellipticalarc.h index dc3f46c82..7f2a34537 100644 --- a/src/libs/vtools/dialogs/tools/dialogellipticalarc.h +++ b/src/libs/vtools/dialogs/tools/dialogellipticalarc.h @@ -74,6 +74,9 @@ public: auto GetColor() const -> QString; void SetColor(const QString &value); + auto GetApproximationScale() const -> qreal; + void SetApproximationScale(qreal value); + void SetNotes(const QString ¬es); auto GetNotes() const -> QString; diff --git a/src/libs/vtools/dialogs/tools/dialogellipticalarc.ui b/src/libs/vtools/dialogs/tools/dialogellipticalarc.ui index b1636b156..3829efae6 100644 --- a/src/libs/vtools/dialogs/tools/dialogellipticalarc.ui +++ b/src/libs/vtools/dialogs/tools/dialogellipticalarc.ui @@ -7,7 +7,7 @@ 0 0 396 - 595 + 633 @@ -1026,16 +1026,39 @@ - + Alias: - + + + + + Approximation scale: + + + + + + + Set approximation scale for this curve, 0 - use global value + + + 1 + + + 10.000000000000000 + + + 0.100000000000000 + + + diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp index a83cded12..265aaac28 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp @@ -125,6 +125,7 @@ VToolEllipticalArc* VToolEllipticalArc::Create(const QPointer &dialo initData.data = data; initData.parse = Document::FullParse; initData.typeCreation = Source::FromGui; + initData.approximationScale = dialogTool->GetApproximationScale(); initData.notes = dialogTool->GetNotes(); initData.aliasSuffix = dialogTool->GetAliasSuffix(); //initData.approximationScale = dialogTool->GetApproximationScale(); // For future use @@ -333,6 +334,24 @@ void VToolEllipticalArc::SetFormulaRotationAngle(const VFormula &value) } } +//--------------------------------------------------------------------------------------------------------------------- +qreal VToolEllipticalArc::GetApproximationScale() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(m_id); + SCASSERT(arc.isNull() == false) + + return arc->GetApproximationScale(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolEllipticalArc::SetApproximationScale(qreal value) +{ + QSharedPointer obj = VAbstractTool::data.GetGObject(m_id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + arc->SetApproximationScale(value); + SaveOption(obj); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolEllipticalArc::ShowVisualization(bool show) { @@ -388,6 +407,7 @@ void VToolEllipticalArc::SaveDialog(QDomElement &domElement, QList &old doc->SetAttribute(domElement, AttrRotationAngle, dialogTool->GetRotationAngle()); doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor()); doc->SetAttribute(domElement, AttrPenStyle, dialogTool->GetPenStyle()); + doc->SetAttribute(domElement, AttrAScale, dialogTool->GetApproximationScale()); doc->SetAttributeOrRemoveIf(domElement, AttrAlias, dialogTool->GetAliasSuffix(), [](const QString &suffix) noexcept {return suffix.isEmpty();}); doc->SetAttributeOrRemoveIf(domElement, AttrNotes, dialogTool->GetNotes(), @@ -430,6 +450,7 @@ void VToolEllipticalArc::SetVisualization() visual->SetF2(trVars->FormulaToUser(elArc->GetFormulaF2(), osSeparator)); visual->SetRotationAngle(trVars->FormulaToUser(elArc->GetFormulaRotationAngle(), osSeparator)); visual->SetLineStyle(LineStyleToPenStyle(elArc->GetPenStyle())); + visual->SetApproximationScale(elArc->GetApproximationScale()); visual->SetMode(Mode::Show); visual->RefreshGeometry(); } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.h index 5d1269901..46ff7ebdc 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.h @@ -94,6 +94,9 @@ public: VFormula GetFormulaRotationAngle() const; void SetFormulaRotationAngle(const VFormula &value); + qreal GetApproximationScale() const; + void SetApproximationScale(qreal value); + virtual void ShowVisualization(bool show) override; protected slots: virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 id=NULL_ID) override; diff --git a/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp b/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp index 39b61c0e9..f27968e99 100644 --- a/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp +++ b/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp @@ -236,6 +236,7 @@ auto VisToolEllipticalArc::DrawElArc(const VPointF ¢er, qreal radius1, qreal qreal rotationAngle) -> VEllipticalArc { VEllipticalArc elArc(center, radius1, radius2, f1, f2, rotationAngle); + elArc.SetApproximationScale(ApproximationScale()); DrawPath(this, elArc.GetPath(), elArc.DirectionArrows(), Color(VColor::MainColor), LineStyle(), Qt::RoundCap); return elArc;