From 6bfc5065bd7743552b4a52363a03dc3163004364 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 8 May 2021 10:54:14 +0300 Subject: [PATCH] Alias support for tools Point of intersection curve and axis and Point of intersection curves. --- ChangeLog.txt | 1 + src/app/valentina/xml/vpattern.cpp | 6 + src/libs/ifc/ifcdef.cpp | 4 + src/libs/ifc/ifcdef.h | 4 + src/libs/ifc/schema.qrc | 1 + src/libs/ifc/schema/pattern/v0.8.11.xsd | 1126 +++++++++++++++++ src/libs/ifc/xml/vpatternconverter.cpp | 23 +- src/libs/ifc/xml/vpatternconverter.h | 3 +- src/libs/vtools/dialogs/dialogtoolbox.cpp | 49 + src/libs/vtools/dialogs/dialogtoolbox.h | 2 + .../tools/dialogcurveintersectaxis.cpp | 72 ++ .../dialogs/tools/dialogcurveintersectaxis.h | 15 +- .../dialogs/tools/dialogcurveintersectaxis.ui | 32 +- .../vtools/dialogs/tools/dialogcutarc.cpp | 2 +- .../vtools/dialogs/tools/dialogcutspline.cpp | 2 +- .../dialogs/tools/dialogcutsplinepath.cpp | 2 +- .../tools/dialogpointofintersectioncurves.cpp | 123 +- .../tools/dialogpointofintersectioncurves.h | 24 +- .../tools/dialogpointofintersectioncurves.ui | 247 ++-- .../toolsinglepoint/toolcut/vtoolcut.cpp | 4 +- .../toollinepoint/vtoolcurveintersectaxis.cpp | 42 +- .../toollinepoint/vtoolcurveintersectaxis.h | 8 +- .../vtoolpointofintersectioncurves.cpp | 76 +- .../vtoolpointofintersectioncurves.h | 12 + .../toolsinglepoint/vtoolsinglepoint.cpp | 21 +- .../toolsinglepoint/vtoolsinglepoint.h | 15 +- 26 files changed, 1789 insertions(+), 127 deletions(-) create mode 100644 src/libs/ifc/schema/pattern/v0.8.11.xsd diff --git a/ChangeLog.txt b/ChangeLog.txt index 9e9890525..760b1a585 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -11,6 +11,7 @@ - Fix correct handle a final measurement formula error when exporting a pattern recipe. - Fix regression. Incorrect data caching. - Improve tool tooltip. Show segment names and aliases. +- Alias support for tools Point of intersection curve and axis and 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/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index b59489571..89f590e97 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2282,6 +2282,8 @@ void VPattern::ParseToolCurveIntersectAxis(VMainGraphicsScene *scene, QDomElemen initData.curveId = GetParametrUInt(domElement, AttrCurve, NULL_ID_STR); initData.formulaAngle = GetParametrString(domElement, AttrAngle, QStringLiteral("0.0")); const QString angleFix = initData.formulaAngle; + initData.aliasSuffix1 = GetParametrEmptyString(domElement, AttrAlias1); + initData.aliasSuffix2 = GetParametrEmptyString(domElement, AttrAlias2); VToolCurveIntersectAxis::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. @@ -2403,6 +2405,10 @@ void VPattern::ParseToolPointOfIntersectionCurves(VMainGraphicsScene *scene, QDo initData.secondCurveId = GetParametrUInt(domElement, AttrCurve2, NULL_ID_STR); initData.vCrossPoint = static_cast(GetParametrUInt(domElement, AttrVCrossPoint, QChar('1'))); initData.hCrossPoint = static_cast(GetParametrUInt(domElement, AttrHCrossPoint, QChar('1'))); + initData.curve1AliasSuffix1 = GetParametrEmptyString(domElement, AttrCurve1Alias1); + initData.curve1AliasSuffix2 = GetParametrEmptyString(domElement, AttrCurve1Alias2); + initData.curve2AliasSuffix1 = GetParametrEmptyString(domElement, AttrCurve2Alias1); + initData.curve2AliasSuffix2 = GetParametrEmptyString(domElement, AttrCurve2Alias2); VToolPointOfIntersectionCurves::Create(initData); } diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index db035f16e..bf2c32bd6 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -137,6 +137,10 @@ const QString AttrNotes = QStringLiteral("notes"); const QString AttrAlias = QStringLiteral("alias"); const QString AttrAlias1 = QStringLiteral("alias1"); const QString AttrAlias2 = QStringLiteral("alias2"); +const QString AttrCurve1Alias1 = QStringLiteral("curve1Alias1"); +const QString AttrCurve1Alias2 = QStringLiteral("curve1Alias2"); +const QString AttrCurve2Alias1 = QStringLiteral("curve2Alias1"); +const QString AttrCurve2Alias2 = QStringLiteral("curve2Alias2"); const QString TypeLineDefault = QStringLiteral("default"); const QString TypeLineNone = QStringLiteral("none"); diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 3173145cd..d74fbdb69 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -155,6 +155,10 @@ extern const QString AttrNotes; extern const QString AttrAlias; extern const QString AttrAlias1; extern const QString AttrAlias2; +extern const QString AttrCurve1Alias1; +extern const QString AttrCurve1Alias2; +extern const QString AttrCurve2Alias1; +extern const QString AttrCurve2Alias2; extern const QString TypeLineDefault; extern const QString TypeLineNone; diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 7d322dbb9..f804d75c8 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -62,6 +62,7 @@ schema/pattern/v0.8.8.xsd schema/pattern/v0.8.9.xsd schema/pattern/v0.8.10.xsd + schema/pattern/v0.8.11.xsd schema/multisize_measurements/v0.3.0.xsd schema/multisize_measurements/v0.4.0.xsd schema/multisize_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/pattern/v0.8.11.xsd b/src/libs/ifc/schema/pattern/v0.8.11.xsd new file mode 100644 index 000000000..b82690505 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.8.11.xsd @@ -0,0 +1,1126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 7316ab6dc..6d2474940 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -59,8 +59,8 @@ class QDomElement; */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.4"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.8.10"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.8.10.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.8.11"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.8.11.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -240,7 +240,8 @@ QString VPatternConverter::XSDSchema(int ver) const std::make_pair(FORMAT_VERSION(0, 8, 7), QStringLiteral("://schema/pattern/v0.8.7.xsd")), std::make_pair(FORMAT_VERSION(0, 8, 8), QStringLiteral("://schema/pattern/v0.8.8.xsd")), std::make_pair(FORMAT_VERSION(0, 8, 9), QStringLiteral("://schema/pattern/v0.8.9.xsd")), - std::make_pair(FORMAT_VERSION(0, 8, 10), CurrentSchema) + std::make_pair(FORMAT_VERSION(0, 8, 10), QStringLiteral("://schema/pattern/v0.8.10.xsd")), + std::make_pair(FORMAT_VERSION(0, 8, 11), CurrentSchema) }; if (schemas.contains(ver)) @@ -501,6 +502,10 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(FORMAT_VERSION(0, 8, 10))); Q_FALLTHROUGH(); case (FORMAT_VERSION(0, 8, 10)): + ToV0_8_11(); + ValidateXML(XSDSchema(FORMAT_VERSION(0, 8, 11))); + Q_FALLTHROUGH(); + case (FORMAT_VERSION(0, 8, 11)): break; default: InvalidVersion(m_ver); @@ -518,7 +523,7 @@ void VPatternConverter::DowngradeToCurrentMaxVersion() bool VPatternConverter::IsReadOnly() const { // Check if attribute readOnly was not changed in file format - Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == FORMAT_VERSION(0, 8, 10), + Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == FORMAT_VERSION(0, 8, 11), "Check attribute readOnly."); // Possibly in future attribute readOnly will change position etc. @@ -1189,6 +1194,16 @@ void VPatternConverter::ToV0_8_10() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_8_11() +{ + // TODO. Delete if minimal supported version is 0.8.11 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 8, 11), + "Time to refactor the code."); + SetVersion(QStringLiteral("0.8.11")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index 6fea9583b..6bd1d9913 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -53,7 +53,7 @@ public: static const QString PatternMaxVerStr; static const QString CurrentSchema; static Q_DECL_CONSTEXPR const int PatternMinVer = FORMAT_VERSION(0, 1, 4); - static Q_DECL_CONSTEXPR const int PatternMaxVer = FORMAT_VERSION(0, 8, 10); + static Q_DECL_CONSTEXPR const int PatternMaxVer = FORMAT_VERSION(0, 8, 11); protected: virtual int MinVer() const override; @@ -133,6 +133,7 @@ private: void ToV0_8_8(); void ToV0_8_9(); void ToV0_8_10(); + void ToV0_8_11(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); diff --git a/src/libs/vtools/dialogs/dialogtoolbox.cpp b/src/libs/vtools/dialogs/dialogtoolbox.cpp index a2ce91c1d..8e74f2bb5 100644 --- a/src/libs/vtools/dialogs/dialogtoolbox.cpp +++ b/src/libs/vtools/dialogs/dialogtoolbox.cpp @@ -36,6 +36,12 @@ #include "../vpatterndb/variables/vcurvelength.h" #include "../ifc/exception/vexceptionbadid.h" #include "../vpatterndb/vcontainer.h" +#include "../vgeometry/vellipticalarc.h" +#include "../vgeometry/varc.h" +#include "../vgeometry/vcubicbezier.h" +#include "../vgeometry/vcubicbezierpath.h" +#include "../vgeometry/vspline.h" +#include "../vgeometry/vsplinepath.h" #include #include @@ -106,7 +112,20 @@ bool DoubleCurve(const VPieceNode &firstNode, const VPieceNode &secondNode) return false; } + +//--------------------------------------------------------------------------------------------------------------------- +template +auto CurveAliases(const QString &alias1, const QString &alias2) -> QPair +{ + T curve1; + curve1.SetAliasSuffix(alias1); + + T curve2; + curve2.SetAliasSuffix(alias2); + + return qMakePair(curve1.GetAlias(), curve2.GetAlias()); } +} // namespace //--------------------------------------------------------------------------------------------------------------------- VPieceNode RowNode(QListWidget *listWidget, int i) @@ -527,3 +546,33 @@ QIcon LineColor(int size, const QString &color) pix.fill(QColor(color)); return QIcon(pix); } + +//--------------------------------------------------------------------------------------------------------------------- +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") +auto SegmentAliases(GOType curveType, const QString &alias1, const QString &alias2) -> QPair +{ + switch(curveType) + { + case GOType::EllipticalArc: + return CurveAliases(alias1, alias2); + case GOType::Arc: + return CurveAliases(alias1, alias2); + case GOType::CubicBezier: + return CurveAliases(alias1, alias2); + case GOType::Spline: + return CurveAliases(alias1, alias2); + case GOType::CubicBezierPath: + return CurveAliases(alias1, alias2); + case GOType::SplinePath: + return CurveAliases(alias1, alias2); + case GOType::Point: + case GOType::PlaceLabel: + case GOType::Unknown: + Q_UNREACHABLE(); + break; + } + + return {}; +} +QT_WARNING_POP diff --git a/src/libs/vtools/dialogs/dialogtoolbox.h b/src/libs/vtools/dialogs/dialogtoolbox.h index ec7b1ee4b..bba25526b 100644 --- a/src/libs/vtools/dialogs/dialogtoolbox.h +++ b/src/libs/vtools/dialogs/dialogtoolbox.h @@ -34,6 +34,7 @@ #include "../vpatterndb/variables/vinternalvariable.h" #include "../vmisc/typedef.h" +#include "../vgeometry/vgeometrydef.h" class QPlainTextEdit; class QPushButton; @@ -88,5 +89,6 @@ QFont NodeFont(QFont font, bool nodeExcluded = false); void CurrentCurveLength(vidtype curveId, VContainer *data); void SetTabStopDistance(QPlainTextEdit *edit, int tabWidthChar=4); QIcon LineColor(int size, const QString &color); +auto SegmentAliases(GOType curveType, const QString &alias1, const QString &alias2) -> QPair; #endif // DIALOGTOOLBOX_H diff --git a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp index c7facc36a..d3dc6ecc0 100644 --- a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp @@ -51,6 +51,8 @@ #include "../support/dialogeditwrongformula.h" #include "../vmisc/vabstractapplication.h" #include "../vmisc/vcommonsettings.h" +#include "../qmuparser/qmudef.h" +#include "../dialogtoolbox.h" #include "ui_dialogcurveintersectaxis.h" //--------------------------------------------------------------------------------------------------------------------- @@ -95,6 +97,8 @@ DialogCurveIntersectAxis::DialogCurveIntersectAxis(const VContainer *data, quint }); connect(ui->pushButtonGrowLengthAngle, &QPushButton::clicked, this, &DialogCurveIntersectAxis::DeployAngleTextEdit); connect(timerFormula, &QTimer::timeout, this, &DialogCurveIntersectAxis::EvalAngle); + connect(ui->lineEditAlias1, &QLineEdit::textEdited, this, &DialogCurveIntersectAxis::ValidateAlias); + connect(ui->lineEditAlias2, &QLineEdit::textEdited, this, &DialogCurveIntersectAxis::ValidateAlias); vis = new VisToolCurveIntersectAxis(data); @@ -352,6 +356,46 @@ void DialogCurveIntersectAxis::closeEvent(QCloseEvent *event) DialogTool::closeEvent(event); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogCurveIntersectAxis::ValidateAlias() +{ + QRegularExpression rx(NameRegExp()); + + const QSharedPointer curve = data->GeometricObject(getCurveId()); + QPair alias = SegmentAliases(curve->getType(), GetAliasSuffix1(), GetAliasSuffix2()); + + + if (not GetAliasSuffix1().isEmpty() && + (not rx.match(alias.first).hasMatch() || + (originAliasSuffix1 != GetAliasSuffix1() && not data->IsUnique(alias.first)) || + alias.first == alias.second)) + { + flagAlias1 = false; + ChangeColor(ui->labelAlias1, errorColor); + } + else + { + flagAlias1 = true; + ChangeColor(ui->labelAlias1, OkColor(this)); + } + + if (not GetAliasSuffix2().isEmpty() && + (not rx.match(alias.second).hasMatch() || + (originAliasSuffix2 != GetAliasSuffix2() && not data->IsUnique(alias.second)) || + alias.first == alias.second)) + { + flagAlias2 = false; + ChangeColor(ui->labelAlias2, errorColor); + } + else + { + flagAlias2 = true; + ChangeColor(ui->labelAlias2, OkColor(this)); + } + + CheckState(); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogCurveIntersectAxis::SetNotes(const QString ¬es) { @@ -363,3 +407,31 @@ QString DialogCurveIntersectAxis::GetNotes() const { return ui->plainTextEditToolNotes->toPlainText(); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCurveIntersectAxis::SetAliasSuffix1(const QString &alias) +{ + originAliasSuffix1 = alias; + ui->lineEditAlias1->setText(originAliasSuffix1); + ValidateAlias(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogCurveIntersectAxis::GetAliasSuffix1() const +{ + return ui->lineEditAlias1->text(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCurveIntersectAxis::SetAliasSuffix2(const QString &alias) +{ + originAliasSuffix2 = alias; + ui->lineEditAlias2->setText(originAliasSuffix2); + ValidateAlias(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogCurveIntersectAxis::GetAliasSuffix2() const +{ + return ui->lineEditAlias2->text(); +} diff --git a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.h b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.h index 6bb117784..d79fb93e1 100644 --- a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.h +++ b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.h @@ -72,6 +72,12 @@ public: void SetNotes(const QString ¬es); QString GetNotes() const; + void SetAliasSuffix1(const QString &alias); + QString GetAliasSuffix1() const; + + void SetAliasSuffix2(const QString &alias); + QString GetAliasSuffix2() const; + virtual void ShowDialog(bool click) override; public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) override; @@ -86,6 +92,8 @@ protected: virtual void SaveData() override; virtual void closeEvent(QCloseEvent *event) override; virtual bool IsValid() const final; +private slots: + void ValidateAlias(); private: Q_DISABLE_COPY(DialogCurveIntersectAxis) Ui::DialogCurveIntersectAxis *ui; @@ -101,12 +109,17 @@ private: bool flagFormula; bool flagName; + bool flagAlias1{true}; + bool flagAlias2{true}; + + QString originAliasSuffix1{}; + QString originAliasSuffix2{}; }; //--------------------------------------------------------------------------------------------------------------------- inline bool DialogCurveIntersectAxis::IsValid() const { - return flagFormula && flagName; + return flagFormula && flagName && flagAlias1 && flagAlias2; } #endif // DIALOGCURVEINTERSECTAXIS_H diff --git a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.ui b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.ui index 42d222f6c..0d6038518 100644 --- a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.ui +++ b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.ui @@ -6,8 +6,8 @@ 0 0 - 335 - 331 + 324 + 394 @@ -320,6 +320,34 @@ + + + + Alias1: + + + + + + + true + + + + + + + Alias2: + + + + + + + true + + + diff --git a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp index ec0bbb4d9..2a484473b 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp @@ -219,7 +219,7 @@ void DialogCutArc::ValidateAlias() if (not GetAliasSuffix1().isEmpty() && (not rx.match(arc1.GetAlias()).hasMatch() || - (originAliasSuffix2 != GetAliasSuffix1() && not data->IsUnique(arc1.GetAlias())) || + (originAliasSuffix1 != GetAliasSuffix1() && not data->IsUnique(arc1.GetAlias())) || arc1.GetAlias() == arc2.GetAlias())) { flagAlias1 = false; diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp index 30dd1a12e..fc1795152 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp @@ -227,7 +227,7 @@ void DialogCutSpline::ValidateAlias() if (not GetAliasSuffix1().isEmpty() && (not rx.match(spl1.GetAlias()).hasMatch() || - (originAliasSuffix2 != GetAliasSuffix1() && not data->IsUnique(spl1.GetAlias())) || + (originAliasSuffix1 != GetAliasSuffix1() && not data->IsUnique(spl1.GetAlias())) || spl1.GetAlias() == spl2.GetAlias())) { flagAlias1 = false; diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp index 44e5c6175..90f5305cb 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp @@ -227,7 +227,7 @@ void DialogCutSplinePath::ValidateAlias() if (not GetAliasSuffix1().isEmpty() && (not rx.match(path1.GetAlias()).hasMatch() || - (originAliasSuffix2 != GetAliasSuffix1() && not data->IsUnique(path1.GetAlias())) || + (originAliasSuffix1 != GetAliasSuffix1() && not data->IsUnique(path1.GetAlias())) || path1.GetAlias() == path2.GetAlias())) { flagAlias1 = false; diff --git a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.cpp b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.cpp index 653aa4bd0..b16ce1858 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.cpp @@ -38,7 +38,9 @@ #include "../../visualization/path/vistoolpointofintersectioncurves.h" #include "../../visualization/visualization.h" #include "../vmisc/vabstractapplication.h" -#include "dialogtool.h" +#include "../qmuparser/qmudef.h" +#include "../dialogtoolbox.h" +#include "../vpatterndb/vcontainer.h" #include "ui_dialogpointofintersectioncurves.h" //--------------------------------------------------------------------------------------------------------------------- @@ -72,6 +74,10 @@ DialogPointOfIntersectionCurves::DialogPointOfIntersectionCurves(const VContaine this, &DialogPointOfIntersectionCurves::CurveChanged); connect(ui->comboBoxCurve2, &QComboBox::currentTextChanged, this, &DialogPointOfIntersectionCurves::CurveChanged); + connect(ui->lineEditCurve1Alias1, &QLineEdit::textEdited, this, &DialogPointOfIntersectionCurves::ValidateAlias); + connect(ui->lineEditCurve1Alias2, &QLineEdit::textEdited, this, &DialogPointOfIntersectionCurves::ValidateAlias); + connect(ui->lineEditCurve2Alias1, &QLineEdit::textEdited, this, &DialogPointOfIntersectionCurves::ValidateAlias); + connect(ui->lineEditCurve2Alias2, &QLineEdit::textEdited, this, &DialogPointOfIntersectionCurves::ValidateAlias); vis = new VisToolPointOfIntersectionCurves(data); @@ -252,6 +258,65 @@ void DialogPointOfIntersectionCurves::CurveChanged() CheckState(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionCurves::ValidateAlias() +{ + QRegularExpression rx(NameRegExp()); + + const QSharedPointer curve1 = data->GeometricObject(GetFirstCurveId()); + QPair curve1Alias = SegmentAliases(curve1->getType(), GetCurve1AliasSuffix1(), + GetCurve1AliasSuffix2()); + + const QSharedPointer curve2 = data->GeometricObject(GetSecondCurveId()); + QPair curve2Alias = SegmentAliases(curve2->getType(), GetCurve2AliasSuffix1(), + GetCurve2AliasSuffix2()); + + QSet uniqueAliases; + int countAliases = 0; + + auto CountUniqueAliases = [&countAliases, &uniqueAliases](const QString &alias) + { + if (not alias.isEmpty()) + { + uniqueAliases.insert(alias); + ++countAliases; + } + }; + + CountUniqueAliases(curve1Alias.first); + CountUniqueAliases(curve1Alias.second); + CountUniqueAliases(curve2Alias.first); + CountUniqueAliases(curve2Alias.second); + + auto Validate = [countAliases, uniqueAliases, rx, this](const QString &originalSuffix, const QString &suffix, + const QString &alias, bool &flagAlias, QLabel *label) + { + if (not suffix.isEmpty() && + (not rx.match(alias).hasMatch() || (originalSuffix != suffix && not data->IsUnique(alias)) || + countAliases != uniqueAliases.size())) + { + flagAlias = false; + ChangeColor(label, errorColor); + } + else + { + flagAlias = true; + ChangeColor(label, OkColor(this)); + } + }; + + Validate(originCurve1AliasSuffix1, GetCurve1AliasSuffix1(), curve1Alias.first, flagCurve1Alias1, + ui->labelCurve1Alias1); + Validate(originCurve1AliasSuffix2, GetCurve1AliasSuffix2(), curve1Alias.second, flagCurve1Alias2, + ui->labelCurve1Alias2); + Validate(originCurve2AliasSuffix1, GetCurve2AliasSuffix1(), curve2Alias.first, flagCurve2Alias1, + ui->labelCurve2Alias1); + Validate(originCurve2AliasSuffix2, GetCurve2AliasSuffix2(), curve2Alias.second, flagCurve2Alias2, + ui->labelCurve2Alias2); + + CheckState(); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPointOfIntersectionCurves::SetNotes(const QString ¬es) { @@ -263,3 +328,59 @@ QString DialogPointOfIntersectionCurves::GetNotes() const { return ui->plainTextEditToolNotes->toPlainText(); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionCurves::SetCurve1AliasSuffix1(const QString &alias) +{ + originCurve1AliasSuffix1 = alias; + ui->lineEditCurve1Alias1->setText(originCurve1AliasSuffix1); + ValidateAlias(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogPointOfIntersectionCurves::GetCurve1AliasSuffix1() const +{ + return ui->lineEditCurve1Alias1->text(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionCurves::SetCurve1AliasSuffix2(const QString &alias) +{ + originCurve1AliasSuffix2 = alias; + ui->lineEditCurve1Alias2->setText(originCurve1AliasSuffix2); + ValidateAlias(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogPointOfIntersectionCurves::GetCurve1AliasSuffix2() const +{ + return ui->lineEditCurve1Alias2->text(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionCurves::SetCurve2AliasSuffix1(const QString &alias) +{ + originCurve2AliasSuffix1 = alias; + ui->lineEditCurve2Alias1->setText(originCurve2AliasSuffix1); + ValidateAlias(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogPointOfIntersectionCurves::GetCurve2AliasSuffix1() const +{ + return ui->lineEditCurve2Alias1->text(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionCurves::SetCurve2AliasSuffix2(const QString &alias) +{ + originCurve2AliasSuffix2 = alias; + ui->lineEditCurve2Alias2->setText(originCurve2AliasSuffix2); + ValidateAlias(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogPointOfIntersectionCurves::GetCurve2AliasSuffix2() const +{ + return ui->lineEditCurve2Alias2->text(); +} diff --git a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.h b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.h index 734a4a35f..f8b07aa62 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.h +++ b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.h @@ -69,6 +69,18 @@ public: void SetNotes(const QString ¬es); QString GetNotes() const; + void SetCurve1AliasSuffix1(const QString &alias); + QString GetCurve1AliasSuffix1() const; + + void SetCurve1AliasSuffix2(const QString &alias); + QString GetCurve1AliasSuffix2() const; + + void SetCurve2AliasSuffix1(const QString &alias); + QString GetCurve2AliasSuffix1() const; + + void SetCurve2AliasSuffix2(const QString &alias); + QString GetCurve2AliasSuffix2() const; + public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) override; @@ -83,6 +95,7 @@ protected: private slots: void CurveChanged(); + void ValidateAlias(); private: Q_DISABLE_COPY(DialogPointOfIntersectionCurves) @@ -93,12 +106,21 @@ private: bool flagName; bool flagError; + bool flagCurve1Alias1{true}; + bool flagCurve1Alias2{true}; + bool flagCurve2Alias1{true}; + bool flagCurve2Alias2{true}; + + QString originCurve1AliasSuffix1{}; + QString originCurve1AliasSuffix2{}; + QString originCurve2AliasSuffix1{}; + QString originCurve2AliasSuffix2{}; }; //--------------------------------------------------------------------------------------------------------------------- inline bool DialogPointOfIntersectionCurves::IsValid() const { - return flagName && flagError; + return flagName && flagError && flagCurve1Alias1 && flagCurve1Alias2 && flagCurve2Alias1 && flagCurve2Alias2; } #endif // DIALOGPOINTOFINTERSECTIONCURVES_H diff --git a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.ui b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.ui index 202dce314..b49926786 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.ui +++ b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.ui @@ -6,8 +6,8 @@ 0 0 - 304 - 242 + 324 + 463 @@ -17,7 +17,7 @@ :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png - + @@ -27,95 +27,170 @@ Tool - - - QFormLayout::ExpandingFieldsGrow - - - - - - 0 - 0 - - - - First curve: + + + + + + + + 0 + 0 + + + + First curve: + + + + + + + + + + + + + + + 0 + 0 + + + + Second curve: + + + + + + + + + + + 0 + 0 + + + + Point label: + + + + + + + + 0 + 0 + + + + Unique label + + + Choose unique label. + + + + + + + Vertical correction: + + + + + + + + + + Horizontal correction: + + + + + + + + + + + + Curve 1 + + + + + Alias1: + + + + + + + true + + + + + + + Alias2: + + + + + + + true + + + + - - - - + + + + Curve 2 + + + + + Alias1: + + + + + + + true + + + + + + + Alias2: + + + + + + + true + + + + - - - - - 0 - 0 - - - - Second curve: - - - - - - - - - - - 0 - 0 - - - - Point label: - - - - - - - - 0 - 0 - - - - Unique label - - - Choose unique label. - - - - - - - Vertical correction: - - - - - - - - - - Horizontal correction: - - - - - - diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp index c64823d52..d95ce21a7 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp @@ -200,6 +200,6 @@ void VToolCut::ReadToolAttributes(const QDomElement &domElement) { VToolSinglePoint::ReadToolAttributes(domElement); - m_aliasSuffix1 = doc->GetParametrEmptyString(domElement, AttrAlias1); - m_aliasSuffix2 = doc->GetParametrEmptyString(domElement, AttrAlias2); + m_aliasSuffix1 = VAbstractPattern::GetParametrEmptyString(domElement, AttrAlias1); + m_aliasSuffix2 = VAbstractPattern::GetParametrEmptyString(domElement, AttrAlias2); } 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 bf9325a70..e988feda5 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp @@ -77,7 +77,9 @@ VToolCurveIntersectAxis::VToolCurveIntersectAxis(const VToolCurveIntersectAxisIn initData.basePointId, 0, initData.notes, parent), formulaAngle(initData.formulaAngle), curveId(initData.curveId), - m_segments(initData.segments) + m_segments(initData.segments), + m_aliasSuffix1(initData.aliasSuffix1), + m_aliasSuffix2(initData.aliasSuffix2) { ToolCreation(initData.typeCreation); } @@ -97,6 +99,8 @@ void VToolCurveIntersectAxis::setDialog() dialogTool->setCurveId(curveId); dialogTool->SetPointName(p->name()); dialogTool->SetNotes(m_notes); + dialogTool->SetAliasSuffix1(m_aliasSuffix1); + dialogTool->SetAliasSuffix2(m_aliasSuffix2); } //--------------------------------------------------------------------------------------------------------------------- @@ -121,6 +125,8 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(const QPointerGetNotes(); + initData.aliasSuffix1 = dialogTool->GetAliasSuffix1(); + initData.aliasSuffix2 = dialogTool->GetAliasSuffix2(); VToolCurveIntersectAxis *point = Create(initData); if (point != nullptr) @@ -162,7 +168,7 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis initData.data->getNextId(); initData.data->getNextId(); initData.segments = VToolSinglePoint::InitSegments(curve->getType(), segLength, p, initData.curveId, - initData.data); + initData.data, initData.aliasSuffix1, initData.aliasSuffix2); } else { @@ -170,7 +176,7 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis initData.data->AddLine(initData.basePointId, initData.id); initData.segments = VToolSinglePoint::InitSegments(curve->getType(), segLength, p, initData.curveId, - initData.data); + initData.data, initData.aliasSuffix1, initData.aliasSuffix2); if (initData.parse != Document::FullParse) { @@ -189,6 +195,10 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis initData.doc->IncrementReferens(curve->getIdTool()); return point; } + + auto *tool = qobject_cast(VAbstractPattern::getTool(initData.id)); + tool->SetSegments(initData.segments); + return nullptr; } @@ -267,6 +277,10 @@ void VToolCurveIntersectAxis::SaveDialog(QDomElement &domElement, QList doc->SetAttribute(domElement, AttrAngle, dialogTool->GetAngle()); doc->SetAttribute(domElement, AttrBasePoint, QString().setNum(dialogTool->GetBasePointId())); doc->SetAttribute(domElement, AttrCurve, QString().setNum(dialogTool->getCurveId())); + doc->SetAttributeOrRemoveIf(domElement, AttrAlias1, dialogTool->GetAliasSuffix1(), + dialogTool->GetAliasSuffix1().isEmpty()); + doc->SetAttributeOrRemoveIf(domElement, AttrAlias2, dialogTool->GetAliasSuffix2(), + dialogTool->GetAliasSuffix2().isEmpty()); const QString notes = dialogTool->GetNotes(); doc->SetAttributeOrRemoveIf(domElement, AttrNotes, notes, notes.isEmpty()); @@ -281,6 +295,8 @@ void VToolCurveIntersectAxis::SaveOptions(QDomElement &tag, QSharedPointerSetAttribute(tag, AttrAngle, formulaAngle); doc->SetAttribute(tag, AttrBasePoint, basePointId); doc->SetAttribute(tag, AttrCurve, curveId); + doc->SetAttributeOrRemoveIf(tag, AttrAlias1, m_aliasSuffix1, m_aliasSuffix1.isEmpty()); + doc->SetAttributeOrRemoveIf(tag, AttrAlias2, m_aliasSuffix2, m_aliasSuffix2.isEmpty()); } //--------------------------------------------------------------------------------------------------------------------- @@ -288,11 +304,13 @@ void VToolCurveIntersectAxis::ReadToolAttributes(const QDomElement &domElement) { VToolLinePoint::ReadToolAttributes(domElement); - m_lineType = doc->GetParametrString(domElement, AttrTypeLine, TypeLineLine); - lineColor = doc->GetParametrString(domElement, AttrLineColor, ColorBlack); - basePointId = doc->GetParametrUInt(domElement, AttrBasePoint, NULL_ID_STR); - curveId = doc->GetParametrUInt(domElement, AttrCurve, NULL_ID_STR); - formulaAngle = doc->GetParametrString(domElement, AttrAngle, QString()); + m_lineType = VAbstractPattern::GetParametrString(domElement, AttrTypeLine, TypeLineLine); + lineColor = VAbstractPattern::GetParametrString(domElement, AttrLineColor, ColorBlack); + basePointId = VAbstractPattern::GetParametrUInt(domElement, AttrBasePoint, NULL_ID_STR); + curveId = VAbstractPattern::GetParametrUInt(domElement, AttrCurve, NULL_ID_STR); + formulaAngle = VAbstractPattern::GetParametrString(domElement, AttrAngle, QString()); + m_aliasSuffix1 = VAbstractPattern::GetParametrEmptyString(domElement, AttrAlias1); + m_aliasSuffix2 = VAbstractPattern::GetParametrEmptyString(domElement, AttrAlias2); } //--------------------------------------------------------------------------------------------------------------------- @@ -300,7 +318,7 @@ void VToolCurveIntersectAxis::SetVisualization() { if (not vis.isNull()) { - VisToolCurveIntersectAxis *visual = qobject_cast(vis); + auto *visual = qobject_cast(vis); SCASSERT(visual != nullptr) visual->setObject1Id(curveId); @@ -336,3 +354,9 @@ QString VToolCurveIntersectAxis::MakeToolTip() const tr("Segment 2"), m_segments.second); /* 10, 11 */ return toolTip; } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCurveIntersectAxis::SetSegments(const QPair &segments) +{ + m_segments = segments; +} diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h index 8c24031db..8f0f5a02c 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h @@ -52,6 +52,8 @@ struct VToolCurveIntersectAxisInitData : VToolLinePointInitData quint32 basePointId{NULL_ID}; quint32 curveId{NULL_ID}; QPair segments{}; + QString aliasSuffix1{}; + QString aliasSuffix2{}; }; class VToolCurveIntersectAxis : public VToolLinePoint @@ -87,13 +89,17 @@ protected: virtual void ReadToolAttributes(const QDomElement &domElement) override; virtual void SetVisualization() override; virtual auto MakeToolTip() const -> QString override; + + void SetSegments(const QPair &segments); private: Q_DISABLE_COPY(VToolCurveIntersectAxis) QString formulaAngle; quint32 curveId; QPair m_segments{}; + QString m_aliasSuffix1{}; + QString m_aliasSuffix2{}; - VToolCurveIntersectAxis(const VToolCurveIntersectAxisInitData &initData, QGraphicsItem *parent = nullptr); + explicit VToolCurveIntersectAxis(const VToolCurveIntersectAxisInitData &initData, QGraphicsItem *parent = nullptr); template static void InitArc(VContainer *data, qreal segLength, const VPointF *p, quint32 curveId); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp index 3d030241f..e859fc58a 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp @@ -64,7 +64,11 @@ VToolPointOfIntersectionCurves::VToolPointOfIntersectionCurves(const VToolPointO vCrossPoint(initData.vCrossPoint), hCrossPoint(initData.hCrossPoint), m_curve1Segments(initData.curve1Segments), - m_curve2Segments(initData.curve2Segments) + m_curve2Segments(initData.curve2Segments), + m_curve1AliasSuffix1(initData.curve1AliasSuffix1), + m_curve1AliasSuffix2(initData.curve1AliasSuffix2), + m_curve2AliasSuffix1(initData.curve2AliasSuffix1), + m_curve2AliasSuffix2(initData.curve2AliasSuffix2) { ToolCreation(initData.typeCreation); } @@ -82,6 +86,10 @@ void VToolPointOfIntersectionCurves::setDialog() dialogTool->SetHCrossPoint(hCrossPoint); dialogTool->SetPointName(p->name()); dialogTool->SetNotes(m_notes); + dialogTool->SetCurve1AliasSuffix1(m_curve1AliasSuffix1); + dialogTool->SetCurve1AliasSuffix2(m_curve1AliasSuffix2); + dialogTool->SetCurve2AliasSuffix1(m_curve2AliasSuffix1); + dialogTool->SetCurve2AliasSuffix2(m_curve2AliasSuffix2); } //--------------------------------------------------------------------------------------------------------------------- @@ -106,6 +114,10 @@ VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(const QPo initData.parse = Document::FullParse; initData.typeCreation = Source::FromGui; initData.notes = dialogTool->GetNotes(); + initData.curve1AliasSuffix1 = dialogTool->GetCurve1AliasSuffix1(); + initData.curve1AliasSuffix2 = dialogTool->GetCurve1AliasSuffix2(); + initData.curve2AliasSuffix1 = dialogTool->GetCurve2AliasSuffix1(); + initData.curve2AliasSuffix2 = dialogTool->GetCurve2AliasSuffix2(); VToolPointOfIntersectionCurves *point = Create(initData); if (point != nullptr) @@ -144,22 +156,31 @@ VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(VToolPoin initData.id = initData.data->AddGObject(p); initData.curve1Segments = VToolSinglePoint::InitSegments(curve1->getType(), segLength1, p, - initData.firstCurveId, initData.data); + initData.firstCurveId, initData.data, + initData.curve1AliasSuffix1, + initData.curve1AliasSuffix2); initData.curve2Segments = VToolSinglePoint::InitSegments(curve2->getType(), segLength2, p, - initData.secondCurveId, initData.data); + initData.secondCurveId, initData.data, + initData.curve2AliasSuffix1, + initData.curve2AliasSuffix2); } else { initData.data->UpdateGObject(initData.id, p); initData.curve1Segments = VToolSinglePoint::InitSegments(curve1->getType(), segLength1, p, - initData.firstCurveId, initData.data); + initData.firstCurveId, initData.data, + initData.curve1AliasSuffix1, + initData.curve1AliasSuffix2); initData.curve2Segments = VToolSinglePoint::InitSegments(curve2->getType(), segLength2, p, - initData.secondCurveId, initData.data); + initData.secondCurveId, initData.data, + initData.curve2AliasSuffix1, + initData.curve2AliasSuffix2); if (initData.parse != Document::FullParse) { initData.doc->UpdateToolData(initData.id, initData.data); + } } @@ -174,6 +195,11 @@ VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(VToolPoin initData.doc->IncrementReferens(curve2->getIdTool()); return point; } + + auto *tool = qobject_cast(VAbstractPattern::getTool(initData.id)); + tool->SetCurve1Segments(initData.curve1Segments); + tool->SetCurve2Segments(initData.curve2Segments); + return nullptr; } @@ -373,7 +399,7 @@ void VToolPointOfIntersectionCurves::SaveDialog(QDomElement &domElement, QList &newDependencies) { SCASSERT(not m_dialog.isNull()) - auto dialogTool = qobject_cast(m_dialog); + auto *dialogTool = qobject_cast(m_dialog); SCASSERT(dialogTool != nullptr) AddDependence(oldDependencies, firstCurveId); @@ -386,6 +412,14 @@ void VToolPointOfIntersectionCurves::SaveDialog(QDomElement &domElement, QListSetAttribute(domElement, AttrCurve2, QString().setNum(dialogTool->GetSecondCurveId())); doc->SetAttribute(domElement, AttrVCrossPoint, QString().setNum(static_cast(dialogTool->GetVCrossPoint()))); doc->SetAttribute(domElement, AttrHCrossPoint, QString().setNum(static_cast(dialogTool->GetHCrossPoint()))); + doc->SetAttributeOrRemoveIf(domElement, AttrCurve1Alias1, dialogTool->GetCurve1AliasSuffix1(), + dialogTool->GetCurve1AliasSuffix1().isEmpty()); + doc->SetAttributeOrRemoveIf(domElement, AttrCurve1Alias2, dialogTool->GetCurve1AliasSuffix2(), + dialogTool->GetCurve1AliasSuffix2().isEmpty()); + doc->SetAttributeOrRemoveIf(domElement, AttrCurve2Alias1, dialogTool->GetCurve2AliasSuffix1(), + dialogTool->GetCurve2AliasSuffix1().isEmpty()); + doc->SetAttributeOrRemoveIf(domElement, AttrCurve2Alias2, dialogTool->GetCurve2AliasSuffix2(), + dialogTool->GetCurve2AliasSuffix2().isEmpty()); const QString notes = dialogTool->GetNotes(); doc->SetAttributeOrRemoveIf(domElement, AttrNotes, notes, notes.isEmpty()); @@ -401,6 +435,10 @@ void VToolPointOfIntersectionCurves::SaveOptions(QDomElement &tag, QSharedPointe doc->SetAttribute(tag, AttrCurve2, secondCurveId); doc->SetAttribute(tag, AttrVCrossPoint, static_cast(vCrossPoint)); doc->SetAttribute(tag, AttrHCrossPoint, static_cast(hCrossPoint)); + doc->SetAttributeOrRemoveIf(tag, AttrCurve1Alias1, m_curve1AliasSuffix1, m_curve1AliasSuffix1.isEmpty()); + doc->SetAttributeOrRemoveIf(tag, AttrCurve1Alias2, m_curve1AliasSuffix2, m_curve1AliasSuffix2.isEmpty()); + doc->SetAttributeOrRemoveIf(tag, AttrCurve2Alias1, m_curve2AliasSuffix1, m_curve2AliasSuffix1.isEmpty()); + doc->SetAttributeOrRemoveIf(tag, AttrCurve2Alias2, m_curve2AliasSuffix2, m_curve2AliasSuffix2.isEmpty()); } //--------------------------------------------------------------------------------------------------------------------- @@ -408,10 +446,16 @@ void VToolPointOfIntersectionCurves::ReadToolAttributes(const QDomElement &domEl { VToolSinglePoint::ReadToolAttributes(domElement); - firstCurveId = doc->GetParametrUInt(domElement, AttrCurve1, NULL_ID_STR); - secondCurveId = doc->GetParametrUInt(domElement, AttrCurve2, NULL_ID_STR); - vCrossPoint = static_cast(doc->GetParametrUInt(domElement, AttrVCrossPoint, QChar('1'))); - hCrossPoint = static_cast(doc->GetParametrUInt(domElement, AttrHCrossPoint, QChar('1'))); + firstCurveId = VAbstractPattern::GetParametrUInt(domElement, AttrCurve1, NULL_ID_STR); + secondCurveId = VAbstractPattern::GetParametrUInt(domElement, AttrCurve2, NULL_ID_STR); + vCrossPoint = static_cast(VAbstractPattern::GetParametrUInt(domElement, AttrVCrossPoint, + QChar('1'))); + hCrossPoint = static_cast(VAbstractPattern::GetParametrUInt(domElement, AttrHCrossPoint, + QChar('1'))); + m_curve1AliasSuffix1 = VAbstractPattern::GetParametrEmptyString(domElement, AttrCurve1Alias1); + m_curve1AliasSuffix2 = VAbstractPattern::GetParametrEmptyString(domElement, AttrCurve1Alias2); + m_curve2AliasSuffix1 = VAbstractPattern::GetParametrEmptyString(domElement, AttrCurve2Alias1); + m_curve2AliasSuffix2 = VAbstractPattern::GetParametrEmptyString(domElement, AttrCurve2Alias2); } //--------------------------------------------------------------------------------------------------------------------- @@ -450,3 +494,15 @@ auto VToolPointOfIntersectionCurves::MakeToolTip() const -> QString return toolTip; } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersectionCurves::SetCurve1Segments(const QPair &segments) +{ + m_curve1Segments = segments; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersectionCurves::SetCurve2Segments(const QPair &segments) +{ + m_curve2Segments = segments; +} diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h index ca76efeac..f316f5ca4 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h @@ -53,6 +53,10 @@ struct VToolPointOfIntersectionCurvesInitData : VToolSinglePointInitData HCrossCurvesPoint hCrossPoint{HCrossCurvesPoint::LeftmostPoint}; QPair curve1Segments{}; QPair curve2Segments{}; + QString curve1AliasSuffix1{}; + QString curve1AliasSuffix2{}; + QString curve2AliasSuffix1{}; + QString curve2AliasSuffix2{}; }; class VToolPointOfIntersectionCurves : public VToolSinglePoint @@ -89,6 +93,9 @@ protected: virtual void ReadToolAttributes(const QDomElement &domElement) override; virtual void SetVisualization() override; virtual auto MakeToolTip() const -> QString override; + + void SetCurve1Segments(const QPair &segments); + void SetCurve2Segments(const QPair &segments); private: Q_DISABLE_COPY(VToolPointOfIntersectionCurves) @@ -101,6 +108,11 @@ private: QPair m_curve1Segments{}; QPair m_curve2Segments{}; + QString m_curve1AliasSuffix1{}; + QString m_curve1AliasSuffix2{}; + QString m_curve2AliasSuffix1{}; + QString m_curve2AliasSuffix2{}; + explicit VToolPointOfIntersectionCurves(const VToolPointOfIntersectionCurvesInitData &initData, QGraphicsItem *parent = nullptr); }; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index a0cffaf69..a91245fbe 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -396,14 +396,15 @@ void VToolSinglePoint::ToolSelectionType(const SelectionType &type) QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") auto VToolSinglePoint::InitSegments(GOType curveType, qreal segLength, const VPointF *p, quint32 curveId, - VContainer *data) -> QPair + VContainer *data, const QString &alias1, + const QString &alias2) -> QPair { switch(curveType) { case GOType::EllipticalArc: - return InitArc(data, segLength, p, curveId); + return InitArc(data, segLength, p, curveId, alias1, alias2); case GOType::Arc: - return InitArc(data, segLength, p, curveId); + return InitArc(data, segLength, p, curveId, alias1, alias2); case GOType::CubicBezier: case GOType::Spline: { @@ -442,12 +443,19 @@ auto VToolSinglePoint::InitSegments(GOType curveType, qreal segLength, const VPo delete spl2; } + spline1->SetAliasSuffix(alias1); + spline2->SetAliasSuffix(alias2); + data->RegisterUniqueName(spline1); data->AddSpline(spline1, NULL_ID, p->id()); data->RegisterUniqueName(spline2); data->AddSpline(spline2, NULL_ID, p->id()); + // Because we don't store segments, but only data about them we must register the names manually + data->RegisterUniqueName(spline1); + data->RegisterUniqueName(spline2); + return qMakePair(spline1->ObjectName(), spline2->ObjectName()); } case GOType::CubicBezierPath: @@ -491,12 +499,19 @@ auto VToolSinglePoint::InitSegments(GOType curveType, qreal segLength, const VPo delete splPath2; } + splP1->SetAliasSuffix(alias1); + splP2->SetAliasSuffix(alias2); + data->RegisterUniqueName(splP1); data->AddSpline(splP1, NULL_ID, p->id()); data->RegisterUniqueName(splP2); data->AddSpline(splP2, NULL_ID, p->id()); + // Because we don't store segments, but only data about them we must register the names manually + data->RegisterUniqueName(splP1); + data->RegisterUniqueName(splP2); + return qMakePair(splP1->ObjectName(), splP2->ObjectName()); } case GOType::Point: diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h index aa8cf3f27..93a86a224 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h @@ -108,9 +108,10 @@ protected: virtual void ChangeLabelVisibility(quint32 id, bool visible) override; template - static QPair InitArc(VContainer *data, qreal segLength, const VPointF *p, quint32 curveId); + static QPair InitArc(VContainer *data, qreal segLength, const VPointF *p, quint32 curveId, + const QString &alias1, const QString &alias2); static QPair InitSegments(GOType curveType, qreal segLength, const VPointF *p, quint32 curveId, - VContainer *data); + VContainer *data, const QString &alias1, const QString &alias2); private: Q_DISABLE_COPY(VToolSinglePoint) }; @@ -118,7 +119,8 @@ private: //--------------------------------------------------------------------------------------------------------------------- template inline auto VToolSinglePoint::InitArc(VContainer *data, qreal segLength, const VPointF *p, - quint32 curveId) -> QPair + quint32 curveId, const QString &alias1, + const QString &alias2) -> QPair { QSharedPointer a1; QSharedPointer a2; @@ -140,6 +142,9 @@ inline auto VToolSinglePoint::InitArc(VContainer *data, qreal segLength, const V arc1.setId(p->id() + 1); arc2.setId(p->id() + 2); + arc1.SetAliasSuffix(alias1); + arc2.SetAliasSuffix(alias2); + if (not VFuzzyComparePossibleNulls(segLength, -1)) { a1 = QSharedPointer(new Item(arc1)); @@ -158,6 +163,10 @@ inline auto VToolSinglePoint::InitArc(VContainer *data, qreal segLength, const V data->AddArc(a1, arc1.id(), p->id()); data->AddArc(a2, arc2.id(), p->id()); + // Because we don't store segments, but only data about them we must register the names manually + data->RegisterUniqueName(a1); + data->RegisterUniqueName(a2); + return qMakePair(arc1.ObjectName(), arc2.ObjectName()); }