diff --git a/ChangeLog.txt b/ChangeLog.txt index 442eafb15..503a48765 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,5 @@ # Version 0.5.0 +- Fixed case with duplicate names of curves if they connect same points. - [#216] Better powerful way creation curved path. - Improved exporting to dxf. QPainterPath export as Polyline. - Show additional message dialog if measurements was changed. Related to issue [#440]. diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index e72b6d622..552ebbd17 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -445,11 +445,12 @@ void VToolOptionsPropertyBrowser::AddPropertyFormula(const QString &propertyName //--------------------------------------------------------------------------------------------------------------------- template -void VToolOptionsPropertyBrowser::AddPropertyPointName(Tool *i, const QString &propertyName) +void VToolOptionsPropertyBrowser::AddPropertyObjectName(Tool *i, const QString &propertyName, bool readOnly) { - VStringProperty *itemName = new VStringProperty(propertyName); + auto itemName = new VStringProperty(propertyName); itemName->setClearButtonEnable(true); itemName->setValue(i->name()); + itemName->setReadOnly(readOnly); AddProperty(itemName, AttrName); } @@ -1301,6 +1302,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolSpline(VProperty *property) SCASSERT(i != nullptr); switch (PropertiesList().indexOf(id)) { + case 0: // AttrName + Q_UNREACHABLE();//The attribute is read only + break; case 25: // AttrKCurve { VSpline spl = i->getSpline(); @@ -1329,6 +1333,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolSplinePath(VProperty *property) SCASSERT(i != nullptr); switch (PropertiesList().indexOf(id)) { + case 0: // AttrName + Q_UNREACHABLE();//The attribute is read only + break; case 25: // AttrKCurve { VSplinePath splPath = i->getSplinePath(); @@ -1431,7 +1438,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolSinglePoint(QGraphicsItem *item i->ShowVisualization(true); formView->setTitle(tr("Base point")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); VPointFProperty* itemPosition = new VPointFProperty(tr("Position")); itemPosition->setValue(i->pos()); @@ -1445,7 +1452,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolEndLine(QGraphicsItem *item) i->ShowVisualization(true); formView->setTitle(tr("Point at distance and angle")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics()); AddPropertyLineColor(i, tr("Line color"), VAbstractTool::ColorsList(), AttrLineColor); AddPropertyFormula(tr("Length"), i->GetFormulaLength(), AttrLength); @@ -1459,7 +1466,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolAlongLine(QGraphicsItem *item) i->ShowVisualization(true); formView->setTitle(tr("Point at distance along line")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics()); AddPropertyLineColor(i, tr("Line color"), VAbstractTool::ColorsList(), AttrLineColor); AddPropertyFormula(tr("Length"), i->GetFormulaLength(), AttrLength); @@ -1498,7 +1505,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolBisector(QGraphicsItem *item) i->ShowVisualization(true); formView->setTitle(tr("Point along bisector")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics()); AddPropertyLineColor(i, tr("Line color"), VAbstractTool::ColorsList(), AttrLineColor); AddPropertyFormula(tr("Length"), i->GetFormulaLength(), AttrLength); @@ -1522,7 +1529,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolCutArc(QGraphicsItem *item) i->ShowVisualization(true); formView->setTitle(tr("Cut arc tool")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyFormula(tr("Length"), i->GetFormula(), AttrLength); AddPropertyLineColor(i, tr("Color"), VAbstractTool::ColorsList(), AttrColor); } @@ -1534,7 +1541,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolCutSpline(QGraphicsItem *item) i->ShowVisualization(true); formView->setTitle(tr("Tool for segmenting a curve")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyFormula(tr("Length"), i->GetFormula(), AttrLength); AddPropertyLineColor(i, tr("Color"), VAbstractTool::ColorsList(), AttrColor); } @@ -1546,7 +1553,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolCutSplinePath(QGraphicsItem *it i->ShowVisualization(true); formView->setTitle(tr("Tool segment a pathed curve")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyFormula(tr("Length"), i->GetFormula(), AttrLength); AddPropertyLineColor(i, tr("Color"), VAbstractTool::ColorsList(), AttrColor); } @@ -1558,7 +1565,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolHeight(QGraphicsItem *item) i->ShowVisualization(true); formView->setTitle(tr("Perpendicular point along line")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics()); AddPropertyLineColor(i, tr("Line color"), VAbstractTool::ColorsList(), AttrLineColor); } @@ -1583,7 +1590,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolLineIntersect(QGraphicsItem *it i->ShowVisualization(true); formView->setTitle(tr("Point at line intersection")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); } //--------------------------------------------------------------------------------------------------------------------- @@ -1594,7 +1601,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolNormal(QGraphicsItem *item) formView->setTitle(tr("Point along perpendicular")); AddPropertyFormula(tr("Length"), i->GetFormulaLength(), AttrLength); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics()); AddPropertyLineColor(i, tr("Line color"), VAbstractTool::ColorsList(), AttrLineColor); @@ -1613,7 +1620,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolPointOfContact(QGraphicsItem *i i->ShowVisualization(true); formView->setTitle(tr("Point at intersection of arc and line")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyFormula(tr("Radius"), i->getArcRadius(), AttrRadius); } @@ -1624,7 +1631,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolPointOfIntersection(QGraphicsIt i->ShowVisualization(true); formView->setTitle(tr("Tool to make point from x & y of two other points")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); } //--------------------------------------------------------------------------------------------------------------------- @@ -1634,7 +1641,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolPointOfIntersectionArcs(QGraphi i->ShowVisualization(true); formView->setTitle(tr("Tool to make point from intersection two arcs")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyCrossPoint(i, tr("Take")); } @@ -1645,7 +1652,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolPointOfIntersectionCircles(QGra i->ShowVisualization(true); formView->setTitle(tr("Tool to make point from intersection two circles")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyFormula(tr("First circle radius"), i->GetFirstCircleRadius(), AttrC1Radius); AddPropertyFormula(tr("Second circle radius"), i->GetSecondCircleRadius(), AttrC2Radius); AddPropertyCrossPoint(i, tr("Take")); @@ -1658,7 +1665,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolPointOfIntersectionCurves(QGrap i->ShowVisualization(true); formView->setTitle(tr("Tool to make point from intersection two curves")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyVCrossPoint(i, tr("Vertical correction")); AddPropertyHCrossPoint(i, tr("Horizontal correction")); } @@ -1670,7 +1677,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolPointFromCircleAndTangent(QGrap i->ShowVisualization(true); formView->setTitle(tr("Tool to make point from circle and tangent")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyFormula(tr("Circle radius"), i->GetCircleRadius(), AttrCRadius); AddPropertyCrossPoint(i, tr("Take")); } @@ -1682,7 +1689,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolPointFromArcAndTangent(QGraphic i->ShowVisualization(true); formView->setTitle(tr("Tool to make point from arc and tangent")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyCrossPoint(i, tr("Take")); } @@ -1693,7 +1700,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolShoulderPoint(QGraphicsItem *it i->ShowVisualization(true); formView->setTitle(tr("Special point on shoulder")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics()); AddPropertyLineColor(i, tr("Line color"), VAbstractTool::ColorsList(), AttrLineColor); AddPropertyFormula(tr("Length"), i->GetFormulaLength(), AttrLength); @@ -1706,6 +1713,8 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolSpline(QGraphicsItem *item) i->ShowVisualization(true); formView->setTitle(tr("Curve tool")); + AddPropertyObjectName(i, tr("Name"), true); + VDoubleProperty* itemFactor = new VDoubleProperty(tr("Curve factor")); VSpline spl = i->getSpline(); itemFactor->setSetting("Min", 0.1); @@ -1724,6 +1733,8 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolSplinePath(QGraphicsItem *item) i->ShowVisualization(true); formView->setTitle(tr("Tool for path curve")); + AddPropertyObjectName(i, tr("Name"), true); + VDoubleProperty* itemFactor = new VDoubleProperty(tr("Curve factor")); VSplinePath splPath = i->getSplinePath(); itemFactor->setSetting("Min", 0.1); @@ -1742,7 +1753,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolTriangle(QGraphicsItem *item) i->ShowVisualization(true); formView->setTitle(tr("Tool triangle")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); } //--------------------------------------------------------------------------------------------------------------------- @@ -1752,7 +1763,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolLineIntersectAxis(QGraphicsItem i->ShowVisualization(true); formView->setTitle(tr("Point intersection line and axis")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics()); AddPropertyLineColor(i, tr("Line color"), VAbstractTool::ColorsList(), AttrLineColor); AddPropertyFormula(tr("Angle"), i->GetFormulaAngle(), AttrAngle); @@ -1765,7 +1776,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolCurveIntersectAxis(QGraphicsIte i->ShowVisualization(true); formView->setTitle(tr("Point intersection curve and axis")); - AddPropertyPointName(i, tr("Point label")); + AddPropertyObjectName(i, tr("Point label")); AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics()); AddPropertyLineColor(i, tr("Line color"), VAbstractTool::ColorsList(), AttrLineColor); AddPropertyFormula(tr("Angle"), i->GetFormulaAngle(), AttrAngle); @@ -2112,25 +2123,21 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolShoulderPoint() //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolSpline() { - VToolSpline *i = qgraphicsitem_cast(currentItem); + auto i = qgraphicsitem_cast(currentItem); - VSpline spl = i->getSpline(); - idToProperty[AttrKCurve]->setValue(spl.GetKcurve()); - - const qint32 index = VLineColorProperty::IndexOfColor(VAbstractTool::ColorsList(), i->GetLineColor()); - idToProperty[AttrColor]->setValue(index); + idToProperty[AttrName]->setValue(i->name()); + idToProperty[AttrKCurve]->setValue(i->getSpline().GetKcurve()); + idToProperty[AttrColor]->setValue(VLineColorProperty::IndexOfColor(VAbstractTool::ColorsList(), i->GetLineColor())); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolSplinePath() { - VToolSplinePath *i = qgraphicsitem_cast(currentItem); + auto i = qgraphicsitem_cast(currentItem); - VSplinePath splPath = i->getSplinePath(); - idToProperty[AttrKCurve]->setValue(splPath.GetKCurve()); - - const qint32 index = VLineColorProperty::IndexOfColor(VAbstractTool::ColorsList(), i->GetLineColor()); - idToProperty[AttrColor]->setValue(index); + idToProperty[AttrName]->setValue(i->name()); + idToProperty[AttrKCurve]->setValue(i->getSplinePath().GetKCurve()); + idToProperty[AttrColor]->setValue(VLineColorProperty::IndexOfColor(VAbstractTool::ColorsList(), i->GetLineColor())); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.h b/src/app/valentina/core/vtooloptionspropertybrowser.h index 6dabcd7e8..acb6b278d 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.h +++ b/src/app/valentina/core/vtooloptionspropertybrowser.h @@ -87,7 +87,7 @@ private: void SetHCrossCurvesPoint(const QVariant &value); template - void AddPropertyPointName(Tool *i, const QString &propertyName); + void AddPropertyObjectName(Tool *i, const QString &propertyName, bool readOnly = false); template void AddPropertyPointName1(Tool *i, const QString &propertyName); diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 4c8f714de..7e21a3adc 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -1860,9 +1860,18 @@ void VPattern::ParseToolSpline(VMainGraphicsScene *scene, const QDomElement &dom const qreal kAsm2 = GetParametrDouble(domElement, AttrKAsm2, "1.0"); const qreal kCurve = GetParametrDouble(domElement, AttrKCurve, "1.0"); const QString color = GetParametrString(domElement, AttrColor, ColorBlack); + const quint32 duplicate = GetParametrUInt(domElement, AttrDuplicate, "0"); - VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, color, scene, this, data, - parse, Source::FromFile); + const auto p1 = data->GeometricObject(point1); + const auto p4 = data->GeometricObject(point4); + + VSpline spline(*p1, *p4, angle1, angle2, kAsm1, kAsm2, kCurve); + if (duplicate > 0) + { + spline.SetDuplicate(duplicate); + } + + VToolSpline::Create(id, spline, color, scene, this, data, parse, Source::FromFile); } catch (const VExceptionBadId &e) { @@ -1885,7 +1894,13 @@ void VPattern::ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement ToolsCommonAttributes(domElement, id); const qreal kCurve = GetParametrDouble(domElement, AttrKCurve, "1.0"); const QString color = GetParametrString(domElement, AttrColor, ColorBlack); - VSplinePath *path = new VSplinePath(kCurve); + const quint32 duplicate = GetParametrUInt(domElement, AttrDuplicate, "0"); + + auto path = new VSplinePath(kCurve); + if (duplicate > 0) + { + path->SetDuplicate(duplicate); + } const QDomNodeList nodeList = domElement.childNodes(); const qint32 num = nodeList.size(); diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index 58566ee35..e086d1c20 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -102,6 +102,7 @@ const QString AttrPoint4 = QStringLiteral("point4"); const QString AttrKAsm1 = QStringLiteral("kAsm1"); const QString AttrKAsm2 = QStringLiteral("kAsm2"); const QString AttrKCurve = QStringLiteral("kCurve"); +const QString AttrDuplicate = QStringLiteral("duplicate"); const QString AttrPathPoint = QStringLiteral("pathPoint"); const QString AttrPSpline = QStringLiteral("pSpline"); const QString AttrAxisP1 = QStringLiteral("axisP1"); diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index f630b509d..8553e8d15 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -104,6 +104,7 @@ extern const QString AttrPoint4; extern const QString AttrKAsm1; extern const QString AttrKAsm2; extern const QString AttrKCurve; +extern const QString AttrDuplicate; extern const QString AttrPathPoint; extern const QString AttrPSpline; extern const QString AttrAxisP1; diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 73c86c494..24a646a18 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -11,6 +11,7 @@ schema/pattern/v0.2.3.xsd schema/pattern/v0.2.4.xsd schema/pattern/v0.2.5.xsd + schema/pattern/v0.2.6.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/pattern/v0.2.6.xsd b/src/libs/ifc/schema/pattern/v0.2.6.xsd new file mode 100644 index 000000000..5d01f9bb3 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.2.6.xsd @@ -0,0 +1,435 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 84e02bf87..4814337dd 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -43,8 +43,8 @@ */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.2.5"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.2.5.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.2.6"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.2.6.xsd"); //--------------------------------------------------------------------------------------------------------------------- VPatternConverter::VPatternConverter(const QString &fileName) @@ -107,6 +107,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000204): return QStringLiteral("://schema/pattern/v0.2.4.xsd"); case (0x000205): + return QStringLiteral("://schema/pattern/v0.2.5.xsd"); + case (0x000206): return CurrentSchema; default: InvalidVersion(ver); @@ -192,6 +194,13 @@ void VPatternConverter::ApplyPatches() V_FALLTHROUGH } case (0x000205): + { + ToV0_2_6(); + const QString schema = XSDSchema(0x000206); + ValidateXML(schema, fileName); + V_FALLTHROUGH + } + case (0x000206): break; default: break; @@ -299,6 +308,13 @@ void VPatternConverter::ToV0_2_5() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_2_6() +{ + SetVersion(QStringLiteral("0.2.6")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index e49f04c19..7b6f76bb2 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -66,6 +66,7 @@ private: void ToV0_2_3(); void ToV0_2_4(); void ToV0_2_5(); + void ToV0_2_6(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); diff --git a/src/libs/vgeometry/vabstractcurve.cpp b/src/libs/vgeometry/vabstractcurve.cpp index 704de469b..dfe580ce8 100644 --- a/src/libs/vgeometry/vabstractcurve.cpp +++ b/src/libs/vgeometry/vabstractcurve.cpp @@ -27,17 +27,18 @@ *************************************************************************/ #include "vabstractcurve.h" +#include "vabstractcurve_p.h" #include #include VAbstractCurve::VAbstractCurve(const GOType &type, const quint32 &idObject, const Draw &mode) - :VGObject(type, idObject, mode) + :VGObject(type, idObject, mode), d (new VAbstractCurveData()) {} //--------------------------------------------------------------------------------------------------------------------- VAbstractCurve::VAbstractCurve(const VAbstractCurve &curve) - :VGObject(curve) + :VGObject(curve), d (curve.d) {} //--------------------------------------------------------------------------------------------------------------------- @@ -48,9 +49,14 @@ VAbstractCurve &VAbstractCurve::operator=(const VAbstractCurve &curve) return *this; } VGObject::operator=(curve); + d = curve.d; return *this; } +//--------------------------------------------------------------------------------------------------------------------- +VAbstractCurve::~VAbstractCurve() +{} + //--------------------------------------------------------------------------------------------------------------------- QVector VAbstractCurve::GetSegmentPoints(const QPointF &begin, const QPointF &end, bool reverse) const { @@ -165,6 +171,19 @@ bool VAbstractCurve::IsIntersectLine(const QLineF &line) const return not points.isEmpty(); } +//--------------------------------------------------------------------------------------------------------------------- +quint32 VAbstractCurve::GetDuplicate() const +{ + return d->duplicate; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractCurve::SetDuplicate(quint32 number) +{ + d->duplicate = number; + CreateName(); +} + //--------------------------------------------------------------------------------------------------------------------- QVector VAbstractCurve::CurveIntersectLine(const QVector &points, const QLineF &line) { diff --git a/src/libs/vgeometry/vabstractcurve.h b/src/libs/vgeometry/vabstractcurve.h index adeee8942..536406a95 100644 --- a/src/libs/vgeometry/vabstractcurve.h +++ b/src/libs/vgeometry/vabstractcurve.h @@ -37,6 +37,7 @@ enum class PathDirection : char { Hide, Show }; class QPainterPath; class QLineF; +class VAbstractCurveData; class VAbstractCurve :public VGObject { @@ -45,6 +46,7 @@ public: const Draw &mode = Draw::Calculation); explicit VAbstractCurve(const VAbstractCurve &curve); VAbstractCurve& operator= (const VAbstractCurve &curve); + virtual ~VAbstractCurve() Q_DECL_OVERRIDE; virtual QVector GetPoints() const =0; QVector GetSegmentPoints(const QPointF &begin, const QPointF &end, bool reverse = false) const; @@ -57,12 +59,20 @@ public: virtual qreal GetStartAngle () const=0; virtual qreal GetEndAngle () const=0; + quint32 GetDuplicate() const; + void SetDuplicate(quint32 number); + static QVector CurveIntersectLine(const QVector &points, const QLineF &line); protected: QPainterPath ShowDirection(const QVector &points) const; + virtual void CreateName() =0; private: + QSharedDataPointer d; + static QVector FromBegin(const QVector &points, const QPointF &begin); static QVector ToEnd(const QVector &points, const QPointF &end); }; +Q_DECLARE_TYPEINFO(VAbstractCurve, Q_MOVABLE_TYPE); + #endif // VABSTRACTCURVE_H diff --git a/src/libs/vgeometry/vabstractcurve_p.h b/src/libs/vgeometry/vabstractcurve_p.h new file mode 100644 index 000000000..0bcdbc26c --- /dev/null +++ b/src/libs/vgeometry/vabstractcurve_p.h @@ -0,0 +1,67 @@ +/************************************************************************ + ** + ** @file vabstractcurve_p.h + ** @author Roman Telezhynskyi + ** @date 15 2, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VABSTRACTCURVE_P_H +#define VABSTRACTCURVE_P_H + +#include + +#ifdef Q_CC_GNU + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Weffc++" +#endif + +class VAbstractCurveData : public QSharedData +{ +public: + + VAbstractCurveData () + : duplicate(0) + {} + + VAbstractCurveData(const VAbstractCurveData &curve) + : QSharedData(curve), duplicate(curve.duplicate) + {} + + virtual ~VAbstractCurveData(); + + /** @brief duplicate helps create unique name for curves that connects the same start and finish points. */ + quint32 duplicate; + +private: + VAbstractCurveData &operator=(const VAbstractCurveData &) Q_DECL_EQ_DELETE; +}; + +VAbstractCurveData::~VAbstractCurveData() +{} + +#ifdef Q_CC_GNU +#pragma GCC diagnostic pop +#endif + +#endif // VABSTRACTCURVE_P_H diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index fc87a77d1..f15de23a2 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -58,14 +58,14 @@ VArc::VArc (VPointF center, qreal radius, QString formulaRadius, qreal f1, QStri : VAbstractCurve(GOType::Arc, idObject, mode), d (new VArcData(center, radius, formulaRadius, f1, formulaF1, f2, formulaF2)) { - ArcName(); + CreateName(); } //--------------------------------------------------------------------------------------------------------------------- VArc::VArc(VPointF center, qreal radius, qreal f1, qreal f2) : VAbstractCurve(GOType::Arc, NULL_ID, Draw::Calculation), d (new VArcData(center, radius, f1, f2)) { - ArcName(); + CreateName(); } //--------------------------------------------------------------------------------------------------------------------- @@ -74,7 +74,7 @@ VArc::VArc(qreal length, QString formulaLength, VPointF center, qreal radius, QS : VAbstractCurve(GOType::Arc, idObject, mode), d (new VArcData(formulaLength, center, radius, formulaRadius, f1, formulaF1)) { - ArcName(); + CreateName(); FindF2(length); } @@ -82,7 +82,7 @@ VArc::VArc(qreal length, QString formulaLength, VPointF center, qreal radius, QS VArc::VArc(qreal length, VPointF center, qreal radius, qreal f1) : VAbstractCurve(GOType::Arc, NULL_ID, Draw::Calculation), d (new VArcData(center, radius, f1)) { - ArcName(); + CreateName(); FindF2(length); } @@ -126,7 +126,7 @@ qreal VArc::GetLength() const qreal length = (M_PI * d->radius)/180 * AngleArc(); if (d->isFlipped) { - length = length * -1; + length *= -1; } return length; @@ -312,13 +312,25 @@ QPointF VArc::CutArc(const qreal &length) const void VArc::setId(const quint32 &id) { VAbstractCurve::setId(id); - setName(ARC_ + QString("%1_%2").arg(d->center.name()).arg(id)); + CreateName(); } //--------------------------------------------------------------------------------------------------------------------- -void VArc::ArcName() +void VArc::CreateName() { - setName(ARC_ + QString("%1").arg(this->GetCenter().name())); + QString name = ARC_ + QString("%1").arg(this->GetCenter().name()); + + if (VAbstractCurve::id() != NULL_ID) + { + name += QString("_%1").arg(VAbstractCurve::id()); + } + + if (GetDuplicate() > 0) + { + name += QString("_%1").arg(GetDuplicate()); + } + + setName(name); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vgeometry/varc.h b/src/libs/vgeometry/varc.h index 7802eaab7..89ac7b4a2 100644 --- a/src/libs/vgeometry/varc.h +++ b/src/libs/vgeometry/varc.h @@ -80,10 +80,11 @@ public: QPointF CutArc (const qreal &length, VArc &arc1, VArc &arc2) const; QPointF CutArc (const qreal &length) const; virtual void setId(const quint32 &id) Q_DECL_OVERRIDE; +protected: + virtual void CreateName() Q_DECL_OVERRIDE; private: QSharedDataPointer d; - void ArcName(); void FindF2(qreal length); qreal MaxLength() const; diff --git a/src/libs/vgeometry/vgeometry.pri b/src/libs/vgeometry/vgeometry.pri index c88e4f97d..d195e20c9 100644 --- a/src/libs/vgeometry/vgeometry.pri +++ b/src/libs/vgeometry/vgeometry.pri @@ -27,4 +27,5 @@ HEADERS += \ $$PWD/vsplinepath_p.h \ $$PWD/vsplinepoint.h \ $$PWD/vsplinepoint_p.h \ - $$PWD/vgeometrydef.h + $$PWD/vgeometrydef.h \ + $$PWD/vabstractcurve_p.h diff --git a/src/libs/vgeometry/vspline.cpp b/src/libs/vgeometry/vspline.cpp index 9a22810e7..6a3771b3a 100644 --- a/src/libs/vgeometry/vspline.cpp +++ b/src/libs/vgeometry/vspline.cpp @@ -600,7 +600,13 @@ qreal VSpline::CalcSqDistance (qreal x1, qreal y1, qreal x2, qreal y2) */ void VSpline::CreateName() { - setName(SPL_ + QString("%1_%2").arg(this->GetP1().name(), this->GetP4().name())); + QString name = SPL_ + QString("%1_%2").arg(this->GetP1().name()).arg(this->GetP4().name()); + if (GetDuplicate() > 0) + { + name += QString("_%1").arg(GetDuplicate()); + } + + setName(name); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vgeometry/vspline.h b/src/libs/vgeometry/vspline.h index 44b5f3dba..aca2919e4 100644 --- a/src/libs/vgeometry/vspline.h +++ b/src/libs/vgeometry/vspline.h @@ -76,13 +76,13 @@ public: qreal ParamT(const QPointF &pBt) const; protected: static QVector GetPoints (const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4 ); + virtual void CreateName() Q_DECL_OVERRIDE; private: QSharedDataPointer d; static qreal LengthBezier (const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4 ); static void PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4, qint16 level, QVector &px, QVector &py); static qreal CalcSqDistance ( qreal x1, qreal y1, qreal x2, qreal y2); - void CreateName(); QVector CalcT(qreal curveCoord1, qreal curveCoord2, qreal curveCoord3, qreal curveCoord4, qreal pointCoord) const; static qint32 Cubic(QVector &x, qreal a, qreal b, qreal c); diff --git a/src/libs/vgeometry/vsplinepath.cpp b/src/libs/vgeometry/vsplinepath.cpp index a4ea4a8ff..bde1dc103 100644 --- a/src/libs/vgeometry/vsplinepath.cpp +++ b/src/libs/vgeometry/vsplinepath.cpp @@ -59,13 +59,7 @@ void VSplinePath::append(const VSplinePoint &point) } d->path.append(point); - QString name = splPath; - name.append(QString("_%1").arg(d->path.first().P().name())); - if (d->path.size() > 1) - { - name.append(QString("_%1").arg(d->path.last().P().name())); - } - setName(name); + CreateName(); } //--------------------------------------------------------------------------------------------------------------------- @@ -92,8 +86,8 @@ VSpline VSplinePath::GetSpline(qint32 index) const { throw VException(tr("This spline does not exist.")); } - const VSplinePoint &p1 = d->path.at(index-1); - const VSplinePoint &p2 = d->path.at(index); + const VSplinePoint &p1 = d->path.at(index-1); + const VSplinePoint &p2 = d->path.at(index); VSpline spl(p1.P(), p2.P(), p1.Angle2(), p2.Angle1(), p1.KAsm2(), p2.KAsm1(), d->kCurve); return spl; } @@ -104,8 +98,8 @@ QPainterPath VSplinePath::GetPath(PathDirection direction) const QPainterPath painterPath; for (qint32 i = 1; i <= Count(); ++i) { - const VSplinePoint &p1 = d->path.at(i-1); - const VSplinePoint &p2 = d->path.at(i); + const VSplinePoint &p1 = d->path.at(i-1); + const VSplinePoint &p2 = d->path.at(i); VSpline spl(p1.P(), p2.P(), p1.Angle2(), p2.Angle1(), p1.KAsm2(), p2.KAsm1(), d->kCurve); painterPath.addPath(spl.GetPath(direction)); } @@ -118,8 +112,8 @@ QVector VSplinePath::GetPoints() const QVector pathPoints; for (qint32 i = 1; i <= Count(); ++i) { - const VSplinePoint &p1 = d->path.at(i-1); - const VSplinePoint &p2 = d->path.at(i); + const VSplinePoint &p1 = d->path.at(i-1); + const VSplinePoint &p2 = d->path.at(i); VSpline spl(p1.P(), p2.P(), p1.Angle2(), p2.Angle1(), p1.KAsm2(), p2.KAsm1(), d->kCurve); pathPoints += spl.GetPoints(); } @@ -132,8 +126,8 @@ qreal VSplinePath::GetLength() const qreal length = 0; for (qint32 i = 1; i <= Count(); ++i) { - const VSplinePoint &p1 = d->path.at(i-1); - const VSplinePoint &p2 = d->path.at(i); + const VSplinePoint &p1 = d->path.at(i-1); + const VSplinePoint &p2 = d->path.at(i); VSpline spl(p1.P(), p2.P(), p1.Angle2(), p2.Angle1(), p1.KAsm2(), p2.KAsm1(), d->kCurve); length += spl.GetLength(); @@ -222,10 +216,10 @@ QPointF VSplinePath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF fullLength = 0; for (qint32 i = 1; i <= Count(); ++i) { - const VSplinePoint &point1 = d->path.at(i-1); - const VSplinePoint &point2 = d->path.at(i); - VSpline spl = VSpline(point1.P(), point2.P(), point1.Angle2(), point2.Angle1(), point1.KAsm2(), - point2.KAsm1(), d->kCurve); + const VSplinePoint &point1 = d->path.at(i-1); + const VSplinePoint &point2 = d->path.at(i); + VSpline spl = VSpline(point1.P(), point2.P(), point1.Angle2(), point2.Angle1(), point1.KAsm2(), + point2.KAsm1(), d->kCurve); fullLength += spl.GetLength(); if (fullLength > length) { @@ -243,8 +237,8 @@ int VSplinePath::Segment(const QPointF &p) const int index = -1; for (qint32 i = 1; i <= Count(); ++i) { - const VSplinePoint &p1 = d->path.at(i-1); - const VSplinePoint &p2 = d->path.at(i); + const VSplinePoint &p1 = d->path.at(i-1); + const VSplinePoint &p2 = d->path.at(i); VSpline spl = VSpline(p1.P(), p2.P(), p1.Angle2(), p2.Angle1(), p1.KAsm2(), p2.KAsm1(), d->kCurve); const qreal t = spl.ParamT(p); @@ -288,6 +282,27 @@ qreal VSplinePath::GetEndAngle() const } } +//--------------------------------------------------------------------------------------------------------------------- +void VSplinePath::CreateName() +{ + QString name; + if (not d->path.isEmpty()) + { + name = splPath; + name.append(QString("_%1").arg(d->path.first().P().name())); + if (d->path.size() > 1) + { + name.append(QString("_%1").arg(d->path.last().P().name())); + } + + if (GetDuplicate() > 0) + { + name += QString("_%1").arg(GetDuplicate()); + } + } + setName(name); +} + //--------------------------------------------------------------------------------------------------------------------- qint32 VSplinePath::CountPoint() const { @@ -304,6 +319,7 @@ QVector VSplinePath::GetSplinePath() const void VSplinePath::Clear() { d->path.clear(); + SetDuplicate(0); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vgeometry/vsplinepath.h b/src/libs/vgeometry/vsplinepath.h index 04ea29fb0..739f89623 100644 --- a/src/libs/vgeometry/vsplinepath.h +++ b/src/libs/vgeometry/vsplinepath.h @@ -178,6 +178,8 @@ public: virtual qreal GetStartAngle () const Q_DECL_OVERRIDE; virtual qreal GetEndAngle () const Q_DECL_OVERRIDE; +protected: + virtual void CreateName() Q_DECL_OVERRIDE; private: QSharedDataPointer d; }; diff --git a/src/libs/vtools/dialogs/tools/dialogspline.cpp b/src/libs/vtools/dialogs/tools/dialogspline.cpp index cf91e8bf0..578bd12d5 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogspline.cpp @@ -43,7 +43,7 @@ * @param parent parent widget */ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogSpline), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1) + :DialogTool(data, toolId, parent), ui(new Ui::DialogSpline), spl(), newDuplicate(-1) { ui->setupUi(this); InitOkCancelApply(ui); @@ -52,6 +52,8 @@ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidge FillComboBoxPoints(ui->comboBoxP4); FillComboBoxLineColors(ui->comboBoxColor); + CheckState(); + connect(ui->comboBoxP1, static_cast(&QComboBox::currentIndexChanged), this, &DialogSpline::PointNameChanged); connect(ui->comboBoxP4, static_cast(&QComboBox::currentIndexChanged), @@ -74,16 +76,6 @@ DialogSpline::~DialogSpline() delete ui; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetP1 return id first point of spline - * @return id - */ -quint32 DialogSpline::GetP1() const -{ - return getCurrentObjectId(ui->comboBoxP1); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. @@ -133,17 +125,22 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type) //--------------------------------------------------------------------------------------------------------------------- void DialogSpline::SaveData() { - angle1 = ui->spinBoxAngle1->value(); - angle2 = ui->spinBoxAngle2->value(); - kAsm1 = ui->doubleSpinBoxKasm1->value(); - kAsm2 = ui->doubleSpinBoxKasm2->value(); - kCurve = ui->doubleSpinBoxKcurve->value(); + const qreal angle1 = ui->spinBoxAngle1->value(); + const qreal angle2 = ui->spinBoxAngle2->value(); + const qreal kAsm1 = ui->doubleSpinBoxKasm1->value(); + const qreal kAsm2 = ui->doubleSpinBoxKasm2->value(); + const qreal kCurve = ui->doubleSpinBoxKcurve->value(); + + const quint32 d = spl.GetDuplicate();//Save previous value + spl = VSpline(*GetP1(), *GetP4(), angle1, angle2, kAsm1, kAsm2, kCurve); + + newDuplicate <= -1 ? spl.SetDuplicate(d) : spl.SetDuplicate(static_cast(newDuplicate)); auto path = qobject_cast(vis); SCASSERT(path != nullptr); - path->setObject1Id(GetP1()); - path->setObject4Id(GetP4()); + path->setObject1Id(GetP1()->id()); + path->setObject4Id(GetP4()->id()); path->SetAngle1(angle1); path->SetAngle2(angle2); path->SetKAsm1(kAsm1); @@ -153,6 +150,18 @@ void DialogSpline::SaveData() path->RefreshGeometry(); } +//--------------------------------------------------------------------------------------------------------------------- +const QSharedPointer DialogSpline::GetP1() const +{ + return data->GeometricObject(getCurrentObjectId(ui->comboBoxP1)); +} + +//--------------------------------------------------------------------------------------------------------------------- +const QSharedPointer DialogSpline::GetP4() const +{ + return data->GeometricObject(getCurrentObjectId(ui->comboBoxP4)); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSpline::PointNameChanged() { @@ -165,12 +174,34 @@ void DialogSpline::PointNameChanged() { flagError = false; color = errorColor; + + ui->lineEditSplineName->setText(tr("Invalid spline")); } else { flagError = true; color = okColor; + + if (getCurrentObjectId(ui->comboBoxP1) == spl.GetP1().id() && + getCurrentObjectId(ui->comboBoxP4) == spl.GetP4().id()) + { + newDuplicate = -1; + ui->lineEditSplineName->setText(spl.name()); + } + else + { + VSpline spline(*GetP1(), *GetP4(), spl.GetStartAngle(), spl.GetEndAngle(), spl.GetKasm1(), spl.GetKasm2(), + spl.GetKcurve()); + + if (not data->IsUnique(spline.name())) + { + newDuplicate = DNumber(spline.name()); + spline.SetDuplicate(newDuplicate); + } + ui->lineEditSplineName->setText(spline.name()); + } } + ChangeColor(ui->labelName, color); ChangeColor(ui->labelFirstPoint, color); ChangeColor(ui->labelSecondPoint, color); CheckState(); @@ -181,22 +212,23 @@ void DialogSpline::ShowDialog(bool click) { if (prepare && click) { - const auto p1 = data->GeometricObject(getCurrentObjectId(ui->comboBoxP1)); - const auto p4 = data->GeometricObject(getCurrentObjectId(ui->comboBoxP4)); - auto *path = qobject_cast(vis); SCASSERT(path != nullptr); - const QPointF p2 = path->GetP2(); - const QPointF p3 = path->GetP3(); + spl = VSpline(*GetP1(), path->GetP2(), path->GetP3(), *GetP4(), ui->doubleSpinBoxKcurve->value()); - VSpline spline(*p1, p2, p3, *p4, kCurve); + ui->spinBoxAngle1->setValue(static_cast(spl.GetStartAngle())); + ui->spinBoxAngle2->setValue(static_cast(spl.GetEndAngle())); - ui->spinBoxAngle1->setValue(static_cast(spline.GetStartAngle())); - ui->spinBoxAngle2->setValue(static_cast(spline.GetEndAngle())); + ui->doubleSpinBoxKasm1->setValue(spl.GetKasm1()); + ui->doubleSpinBoxKasm2->setValue(spl.GetKasm2()); - ui->doubleSpinBoxKasm1->setValue(spline.GetKasm1()); - ui->doubleSpinBoxKasm2->setValue(spline.GetKasm2()); + if (not data->IsUnique(spl.name())) + { + spl.SetDuplicate(DNumber(spl.name())); + } + + ui->lineEditSplineName->setText(spl.name()); DialogAccepted(); } @@ -209,18 +241,36 @@ void DialogSpline::ShowVisualization() } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetKCurve set coefficient curve - * @param value value. Can be >= 0. - */ -void DialogSpline::SetKCurve(const qreal &value) +VSpline DialogSpline::GetSpline() const { - kCurve = value; - ui->doubleSpinBoxKcurve->setValue(value); + return spl; +} - VisToolSpline *path = qobject_cast(vis); +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::SetSpline(const VSpline &spline) +{ + spl = spline; + + setCurrentPointId(ui->comboBoxP1, spl.GetP1().id()); + setCurrentPointId(ui->comboBoxP4, spl.GetP4().id()); + ui->spinBoxAngle1->setValue(static_cast(spl.GetStartAngle())); + ui->spinBoxAngle2->setValue(static_cast(spl.GetEndAngle())); + ui->doubleSpinBoxKasm1->setValue(spl.GetKasm1()); + ui->doubleSpinBoxKasm2->setValue(spl.GetKasm2()); + ui->doubleSpinBoxKcurve->setValue(spl.GetKcurve()); + + ui->lineEditSplineName->setText(spl.name()); + + auto path = qobject_cast(vis); SCASSERT(path != nullptr); - path->SetKCurve(kCurve); + + path->setObject1Id(spl.GetP1().id()); + path->setObject4Id(spl.GetP4().id()); + path->SetAngle1(spl.GetStartAngle()); + path->SetAngle2(spl.GetEndAngle()); + path->SetKAsm1(spl.GetKasm1()); + path->SetKAsm2(spl.GetKasm2()); + path->SetKCurve(spl.GetKcurve()); } //--------------------------------------------------------------------------------------------------------------------- @@ -234,151 +284,3 @@ void DialogSpline::SetColor(const QString &value) { ChangeCurrentData(ui->comboBoxColor, value); } - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetKAsm2 set second coefficient asymmetry - * @param value value. Can be >= 0. - */ -void DialogSpline::SetKAsm2(const qreal &value) -{ - kAsm2 = value; - ui->doubleSpinBoxKasm2->setValue(value); - - VisToolSpline *path = qobject_cast(vis); - SCASSERT(path != nullptr); - path->SetKAsm2(kAsm2); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetKAsm1 set first coefficient asymmetry - * @param value value. Can be >= 0. - */ -void DialogSpline::SetKAsm1(const qreal &value) -{ - kAsm1 = value; - ui->doubleSpinBoxKasm1->setValue(value); - - VisToolSpline *path = qobject_cast(vis); - SCASSERT(path != nullptr); - path->SetKAsm1(kAsm1); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetAngle2 set second angle of spline - * @param value angle in degree - */ -void DialogSpline::SetAngle2(const qreal &value) -{ - angle2 = value; - ui->spinBoxAngle2->setValue(static_cast(value)); - - VisToolSpline *path = qobject_cast(vis); - SCASSERT(path != nullptr); - path->SetAngle2(angle2); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetAngle1 set first angle of spline - * @param value angle in degree - */ -void DialogSpline::SetAngle1(const qreal &value) -{ - angle1 = value; - ui->spinBoxAngle1->setValue(static_cast(value)); - - VisToolSpline *path = qobject_cast(vis); - SCASSERT(path != nullptr); - path->SetAngle1(angle1); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetP4 set id fourth point of spline - * @param value id - */ -void DialogSpline::SetP4(const quint32 &value) -{ - setCurrentPointId(ui->comboBoxP4, value); - - VisToolSpline *path = qobject_cast(vis); - SCASSERT(path != nullptr); - path->setObject4Id(value); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetP1 set id first point of spline - * @param value id - */ -void DialogSpline::SetP1(const quint32 &value) -{ - setCurrentPointId(ui->comboBoxP1, value); - - VisToolSpline *path = qobject_cast(vis); - SCASSERT(path != nullptr); - path->setObject1Id(value); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetP4 return id fourth point of spline - * @return id - */ -quint32 DialogSpline::GetP4() const -{ - return getCurrentObjectId(ui->comboBoxP4); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetAngle1 return first angle of spline - * @return angle in degree - */ -qreal DialogSpline::GetAngle1() const -{ - return angle1; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetAngle2 return second angle of spline - * @return angle in degree - */ -qreal DialogSpline::GetAngle2() const -{ - return angle2; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetKAsm1 return first coefficient asymmetry - * @return value. Can be >= 0. - */ -qreal DialogSpline::GetKAsm1() const -{ - return kAsm1; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetKAsm2 return second coefficient asymmetry - * @return value. Can be >= 0. - */ -qreal DialogSpline::GetKAsm2() const -{ - return kAsm2; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetKCurve return coefficient curve - * @return value. Can be >= 0. - */ -qreal DialogSpline::GetKCurve() const -{ - return kCurve; -} diff --git a/src/libs/vtools/dialogs/tools/dialogspline.h b/src/libs/vtools/dialogs/tools/dialogspline.h index 2d899aa64..ab7160b5b 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.h +++ b/src/libs/vtools/dialogs/tools/dialogspline.h @@ -30,6 +30,7 @@ #define DIALOGSPLINE_H #include "dialogtool.h" +#include "../vgeometry/vspline.h" namespace Ui { @@ -46,29 +47,11 @@ public: DialogSpline(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr); virtual ~DialogSpline() Q_DECL_OVERRIDE; - quint32 GetP1() const; - void SetP1(const quint32 &value); + VSpline GetSpline() const; + void SetSpline(const VSpline &spline); - quint32 GetP4() const; - void SetP4(const quint32 &value); - - qreal GetAngle1() const; - void SetAngle1(const qreal &value); - - qreal GetAngle2() const; - void SetAngle2(const qreal &value); - - qreal GetKAsm1() const; - void SetKAsm1(const qreal &value); - - qreal GetKAsm2() const; - void SetKAsm2(const qreal &value); - - qreal GetKCurve() const; - void SetKCurve(const qreal &value); - - QString GetColor() const; - void SetColor(const QString &value); + QString GetColor() const; + void SetColor(const QString &value); public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; virtual void PointNameChanged() Q_DECL_OVERRIDE; @@ -85,20 +68,13 @@ private: /** @brief ui keeps information about user interface */ Ui::DialogSpline *ui; - /** @brief angle1 first angle of spline in degree */ - qreal angle1; + /** @brief spl spline */ + VSpline spl; - /** @brief angle2 second angle of spline in degree */ - qreal angle2; + qint32 newDuplicate; - /** @brief kAsm1 first coefficient asymmetry */ - qreal kAsm1; - - /** @brief kAsm2 second coefficient asymmetry */ - qreal kAsm2; - - /** @brief kCurve coefficient curve */ - qreal kCurve; + const QSharedPointer GetP1() const; + const QSharedPointer GetP4() const; }; #endif // DIALOGSPLINE_H diff --git a/src/libs/vtools/dialogs/tools/dialogspline.ui b/src/libs/vtools/dialogs/tools/dialogspline.ui index 52c4af988..839a00e72 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.ui +++ b/src/libs/vtools/dialogs/tools/dialogspline.ui @@ -7,7 +7,7 @@ 0 0 540 - 233 + 273 @@ -207,6 +207,20 @@ + + + + Name: + + + + + + + true + + + diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index dde11226a..26f87d18a 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -39,7 +39,7 @@ * @param parent parent widget */ DialogSplinePath::DialogSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()) + :DialogTool(data, toolId, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()), newDuplicate(-1) { ui->setupUi(this); InitOkCancelApply(ui); @@ -94,6 +94,7 @@ void DialogSplinePath::SetPath(const VSplinePath &value) } ui->listWidget->setFocus(Qt::OtherFocusReason); ui->doubleSpinBoxKcurve->setValue(path.GetKCurve()); + ui->lineEditSplPathName->setText(path.name()); auto visPath = qobject_cast(vis); SCASSERT(visPath != nullptr); @@ -123,7 +124,7 @@ void DialogSplinePath::ChosenObject(quint32 id, const SceneObject &type) { if (type == SceneObject::Point) { - if (path.CountPoint() >= 2 && path.at(path.CountPoint()-1).P().id() == id) + if (AllIds().contains(id)) { return; } @@ -153,7 +154,9 @@ void DialogSplinePath::ChosenObject(quint32 id, const SceneObject &type) //--------------------------------------------------------------------------------------------------------------------- void DialogSplinePath::SaveData() { + const quint32 d = path.GetDuplicate();//Save previous value SavePath(); + newDuplicate <= -1 ? path.SetDuplicate(d) : path.SetDuplicate(static_cast(newDuplicate)); auto visPath = qobject_cast(vis); SCASSERT(visPath != nullptr); @@ -195,6 +198,45 @@ void DialogSplinePath::currentPointChanged(int index) DataPoint(p.P().id(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2()); EnableFields(); item->setData(Qt::UserRole, QVariant::fromValue(p)); + item->setText(p.P().name()); + + QColor color = okColor; + if (not IsPathValid()) + { + flagError = false; + color = errorColor; + + ui->lineEditSplPathName->setText(tr("Invalid spline path")); + } + else + { + flagError = true; + color = okColor; + + auto first = qvariant_cast(ui->listWidget->item(0)->data(Qt::UserRole)); + auto last = qvariant_cast(ui->listWidget->item(ui->listWidget->count()-1)->data(Qt::UserRole)); + + if (first.P().id() == path.at(0).P().id() && last.P().id() == path.at(path.CountPoint()-1).P().id()) + { + newDuplicate = -1; + ui->lineEditSplPathName->setText(path.name()); + } + else + { + VSplinePath newPath = ExtractPath(); + + if (not data->IsUnique(newPath.name())) + { + newDuplicate = DNumber(newPath.name()); + newPath.SetDuplicate(newDuplicate); + } + + ui->lineEditSplPathName->setText(newPath.name()); + } + } + ChangeColor(ui->labelName, color); + ChangeColor(ui->labelPoint, color); + CheckState(); } //--------------------------------------------------------------------------------------------------------------------- @@ -265,6 +307,12 @@ void DialogSplinePath::ShowDialog(bool click) if (path.CountPoint() >= 3) { emit ToolTip(""); + + if (not data->IsUnique(path.name())) + { + path.SetDuplicate(DNumber(path.name())); + } + DialogAccepted(); } } @@ -368,10 +416,39 @@ void DialogSplinePath::EnableFields() void DialogSplinePath::SavePath() { path.Clear(); + path = ExtractPath(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QSet DialogSplinePath::AllIds() const +{ + QSet ids; for (qint32 i = 0; i < ui->listWidget->count(); ++i) { - QListWidgetItem *item = ui->listWidget->item(i); - path.append( qvariant_cast(item->data(Qt::UserRole))); + ids.insert(qvariant_cast(ui->listWidget->item(i)->data(Qt::UserRole)).P().id()); } - path.SetKCurve(ui->doubleSpinBoxKcurve->value()); + + return ids; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogSplinePath::IsPathValid() const +{ + if (path.CountPoint() < 3) + { + return false; + } + + return (AllIds().size() == path.CountPoint()); +} + +//--------------------------------------------------------------------------------------------------------------------- +VSplinePath DialogSplinePath::ExtractPath() const +{ + VSplinePath path(ui->doubleSpinBoxKcurve->value()); + for (qint32 i = 0; i < ui->listWidget->count(); ++i) + { + path.append( qvariant_cast(ui->listWidget->item(i)->data(Qt::UserRole))); + } + return path; } diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.h b/src/libs/vtools/dialogs/tools/dialogsplinepath.h index c10146364..b992a697f 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.h +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.h @@ -77,10 +77,15 @@ private: /** @brief path spline path */ VSplinePath path; + qint32 newDuplicate; + void NewItem(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); void DataPoint(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); void EnableFields(); void SavePath(); + QSet AllIds() const; + bool IsPathValid() const; + VSplinePath ExtractPath() const; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.ui b/src/libs/vtools/dialogs/tools/dialogsplinepath.ui index 1942bc658..140fe7fac 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.ui +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.ui @@ -7,7 +7,7 @@ 0 0 528 - 322 + 353 @@ -28,7 +28,7 @@ - + Point of curve @@ -196,6 +196,20 @@ + + + + Name: + + + + + + + true + + + diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index 5cff1eb04..fe1040147 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -311,6 +311,20 @@ bool DialogTool::eventFilter(QObject *object, QEvent *event) return false; } +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogTool::DNumber(const QString &baseName) const +{ + quint32 num = 0; + QString name; + do + { + ++num; + name = baseName + QString("_%1").arg(num); + } while (not data->IsUnique(name)); + + return num; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ValFormulaChanged handle change formula diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index c95109718..a715bb1f0 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -255,6 +255,7 @@ protected: virtual void SaveData() {} void MoveCursorToEnd(QPlainTextEdit *plainTextEdit); bool eventFilter(QObject *object, QEvent *event); + quint32 DNumber(const QString &baseName) const; private: void FillList(QComboBox *box, const QMap &list)const; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index 6c32892c1..f6e31f2b9 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -266,3 +266,9 @@ void VAbstractSpline::setEnabled(bool enabled) qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); } } + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractSpline::name() const +{ + return ObjectName(id); +} diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h index e6ca060ba..40f874c0d 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h @@ -52,6 +52,8 @@ public: void setEnabled(bool enabled); + QString name() const; + public slots: virtual void FullUpdateFromFile () Q_DECL_OVERRIDE; virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp index 729b8b804..c58ec1290 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp @@ -104,14 +104,8 @@ void VToolSpline::setDialog() SCASSERT(dialog != nullptr); DialogSpline *dialogTool = qobject_cast(dialog); SCASSERT(dialogTool != nullptr); - const QSharedPointer spl = VAbstractTool::data.GeometricObject(id); - dialogTool->SetP1(spl->GetP1().id()); - dialogTool->SetP4(spl->GetP4().id()); - dialogTool->SetAngle1(spl->GetStartAngle()); - dialogTool->SetAngle2(spl->GetEndAngle()); - dialogTool->SetKAsm1(spl->GetKasm1()); - dialogTool->SetKAsm2(spl->GetKasm2()); - dialogTool->SetKCurve(spl->GetKcurve()); + const auto spl = VAbstractTool::data.GeometricObject(id); + dialogTool->SetSpline(*spl); dialogTool->SetColor(lineColor); } @@ -127,18 +121,12 @@ void VToolSpline::setDialog() VToolSpline* VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data) { SCASSERT(dialog != nullptr); - DialogSpline *dialogTool = qobject_cast(dialog); + auto dialogTool = qobject_cast(dialog); SCASSERT(dialogTool != nullptr); - const quint32 p1 = dialogTool->GetP1(); - const quint32 p4 = dialogTool->GetP4(); - const qreal kAsm1 = dialogTool->GetKAsm1(); - const qreal kAsm2 = dialogTool->GetKAsm2(); - const qreal angle1 = dialogTool->GetAngle1(); - const qreal angle2 = dialogTool->GetAngle2(); - const qreal kCurve = dialogTool->GetKCurve(); - const QString color = dialogTool->GetColor(); - VToolSpline *spl = Create(0, p1, p4, kAsm1, kAsm2, angle1, angle2, kCurve, color, scene, doc, data, - Document::FullParse, Source::FromGui); + + auto spl = Create(0, dialogTool->GetSpline(), dialogTool->GetColor(), scene, doc, data, Document::FullParse, + Source::FromGui); + if (spl != nullptr) { spl->dialog=dialogTool; @@ -150,13 +138,8 @@ VToolSpline* VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. - * @param p1 id first spline point. - * @param p4 id last spline point. - * @param kAsm1 coefficient of length first control line. - * @param kAsm2 coefficient of length second control line. - * @param angle1 angle from first point to first control point. - * @param angle2 angle from second point to second control point. - * @param kCurve coefficient of curvature spline. + * @param spl spline. + * @param color spline color. * @param scene pointer to scene. * @param doc dom document container. * @param data container with variables. @@ -164,15 +147,11 @@ VToolSpline* VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, * @param typeCreation way we create this tool. * @return the created tool */ -VToolSpline* VToolSpline::Create(const quint32 _id, const quint32 &p1, const quint32 &p4, const qreal &kAsm1, - const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, - const QString &color, VMainGraphicsScene *scene, VAbstractPattern *doc, - VContainer *data, - const Document &parse, const Source &typeCreation) +VToolSpline* VToolSpline::Create(const quint32 _id, const VSpline &spl, const QString &color, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation) { - VPointF point1 = *data->GeometricObject(p1); - VPointF point4 = *data->GeometricObject(p4); - VSpline *spline = new VSpline(point1, point4, angle1, angle2, kAsm1, kAsm2, kCurve); + auto spline = new VSpline(spl); quint32 id = _id; if (typeCreation == Source::FromGui) { @@ -191,17 +170,17 @@ VToolSpline* VToolSpline::Create(const quint32 _id, const quint32 &p1, const qui VDrawTool::AddRecord(id, Tool::Spline, doc); if (parse == Document::FullParse) { - VToolSpline *spl = new VToolSpline(doc, data, id, color, typeCreation); - scene->addItem(spl); - connect(spl, &VToolSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(scene, &VMainGraphicsScene::NewFactor, spl, &VToolSpline::SetFactor); - connect(scene, &VMainGraphicsScene::DisableItem, spl, &VToolSpline::Disable); - connect(scene, &VMainGraphicsScene::EnableToolMove, spl, &VToolSpline::EnableToolMove); - connect(scene, &VMainGraphicsScene::CurveDetailsMode, spl, &VToolSpline::DetailsMode); - doc->AddTool(id, spl); - doc->IncrementReferens(point1.getIdTool()); - doc->IncrementReferens(point4.getIdTool()); - return spl; + auto _spl = new VToolSpline(doc, data, id, color, typeCreation); + scene->addItem(_spl); + connect(_spl, &VToolSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(scene, &VMainGraphicsScene::NewFactor, _spl, &VToolSpline::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, _spl, &VToolSpline::Disable); + connect(scene, &VMainGraphicsScene::EnableToolMove, _spl, &VToolSpline::EnableToolMove); + connect(scene, &VMainGraphicsScene::CurveDetailsMode, _spl, &VToolSpline::DetailsMode); + doc->AddTool(id, _spl); + doc->IncrementReferens(spline->GetP1().id()); + doc->IncrementReferens(spline->GetP4().id()); + return _spl; } return nullptr; } @@ -297,13 +276,10 @@ void VToolSpline::RemoveReferens() void VToolSpline::SaveDialog(QDomElement &domElement) { SCASSERT(dialog != nullptr); - DialogSpline *dialogTool = qobject_cast(dialog); + auto dialogTool = qobject_cast(dialog); SCASSERT(dialogTool != nullptr); - VPointF point1 = *VAbstractTool::data.GeometricObject(dialogTool->GetP1()); - VPointF point4 = *VAbstractTool::data.GeometricObject(dialogTool->GetP4()); - VSpline spl = VSpline (point1, point4, dialogTool->GetAngle1(), dialogTool->GetAngle2(), - dialogTool->GetKAsm1(), dialogTool->GetKAsm2(), dialogTool->GetKCurve()); + const VSpline spl = dialogTool->GetSpline(); controlPoints[0]->blockSignals(true); controlPoints[1]->blockSignals(true); @@ -314,8 +290,6 @@ void VToolSpline::SaveDialog(QDomElement &domElement) controlPoints[0]->blockSignals(false); controlPoints[1]->blockSignals(false); - spl = VSpline (point1, controlPoints[0]->pos(), controlPoints[1]->pos(), point4, dialogTool->GetKCurve()); - doc->SetAttribute(domElement, AttrPoint1, spl.GetP1().id()); doc->SetAttribute(domElement, AttrPoint4, spl.GetP4().id()); doc->SetAttribute(domElement, AttrAngle1, spl.GetStartAngle()); @@ -342,6 +316,18 @@ void VToolSpline::SaveOptions(QDomElement &tag, QSharedPointer &obj) doc->SetAttribute(tag, AttrKAsm1, spl->GetKasm1()); doc->SetAttribute(tag, AttrKAsm2, spl->GetKasm2()); doc->SetAttribute(tag, AttrKCurve, spl->GetKcurve()); + + if (spl->GetDuplicate() > 0) + { + doc->SetAttribute(tag, AttrDuplicate, spl->GetDuplicate()); + } + else + { + if (tag.hasAttribute(AttrDuplicate)) + { + tag.removeAttribute(AttrDuplicate); + } + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h index 0204e4c69..6d563b57b 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h @@ -44,12 +44,10 @@ public: QGraphicsItem * parent = nullptr ); virtual ~VToolSpline() Q_DECL_OVERRIDE; virtual void setDialog() Q_DECL_OVERRIDE; - static VToolSpline *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolSpline *Create(const quint32 _id, const quint32 &p1, const quint32 &p4, const qreal &kAsm1, - const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, - const QString &color, VMainGraphicsScene *scene, VAbstractPattern *doc, - VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolSpline *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); + static VToolSpline *Create(const quint32 _id, const VSpline &spl, const QString &color, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::Spline)}; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index 04ec5fcb0..5027f90f5 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -404,6 +404,18 @@ void VToolSplinePath::SaveOptions(QDomElement &tag, QSharedPointer &ob doc->SetAttribute(tag, AttrType, ToolType); doc->SetAttribute(tag, AttrKCurve, splPath->GetKCurve()); + if (splPath->GetDuplicate() > 0) + { + doc->SetAttribute(tag, AttrDuplicate, splPath->GetDuplicate()); + } + else + { + if (tag.hasAttribute(AttrDuplicate)) + { + tag.removeAttribute(AttrDuplicate); + } + } + doc->RemoveAllChild(tag); for (qint32 i = 0; i < splPath->CountPoint(); ++i) { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp index 66b67a6c5..099e23a8d 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp @@ -76,7 +76,7 @@ void VToolDoublePoint::paint(QPainter *painter, const QStyleOptionGraphicsItem * //--------------------------------------------------------------------------------------------------------------------- QString VToolDoublePoint::nameP1() const { - return PointName(p1id); + return ObjectName(p1id); } //--------------------------------------------------------------------------------------------------------------------- @@ -88,7 +88,7 @@ void VToolDoublePoint::setNameP1(const QString &name) //--------------------------------------------------------------------------------------------------------------------- QString VToolDoublePoint::nameP2() const { - return PointName(p2id); + return ObjectName(p2id); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index d0cf96a75..38d484b70 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -95,7 +95,7 @@ void VToolSinglePoint::paint(QPainter *painter, const QStyleOptionGraphicsItem * //--------------------------------------------------------------------------------------------------------------------- QString VToolSinglePoint::name() const { - return PointName(id); + return ObjectName(id); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.cpp index a0423c207..e7027800e 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.cpp @@ -71,21 +71,6 @@ void VAbstractPoint::DeleteFromLabel() } } -//--------------------------------------------------------------------------------------------------------------------- -QString VAbstractPoint::PointName(quint32 id) const -{ - try - { - return VAbstractTool::data.GeometricObject(id)->name(); - } - catch (const VExceptionBadId &e) - { - qCDebug(vTool, "Error! Couldn't get point name. %s %s", qUtf8Printable(e.ErrorMessage()), - qUtf8Printable(e.DetailedInformation())); - return QString("");// Return empty string for property browser - } -} - //--------------------------------------------------------------------------------------------------------------------- void VAbstractPoint::SetPointName(quint32 id, const QString &name) { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h index ef8c02d76..c38bb4903 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h @@ -50,7 +50,6 @@ public slots: void DeleteFromLabel(); protected: - QString PointName(quint32 id) const; void SetPointName(quint32 id, const QString &name); template diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 5c6512247..e9fba51a9 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -112,6 +112,9 @@ protected: template void ShowItem(Item *item, quint32 id, bool enable); + + template + QString ObjectName(quint32 id) const; private: Q_DISABLE_COPY(VDrawTool) }; @@ -202,4 +205,25 @@ void VDrawTool::ShowItem(Item *item, quint32 id, bool enable) } } +//--------------------------------------------------------------------------------------------------------------------- +template +/** + * @brief ObjectName get object (point, curve, arc) name. + * @param id object id in container. + */ +QString VDrawTool::ObjectName(quint32 id) const +{ + try + { + return VAbstractTool::data.GeometricObject(id)->name(); + } + catch (const VExceptionBadId &e) + { + qCDebug(vTool, "Error! Couldn't get object name by id = %s. %s %s", qUtf8Printable(QString().setNum(id)), + qUtf8Printable(e.ErrorMessage()), + qUtf8Printable(e.DetailedInformation())); + return QString("");// Return empty string for property browser + } +} + #endif // VDRAWTOOL_H