Skip to content

Commit 03497f2

Browse files
committed
add formula to grainline arrows
1 parent ed13470 commit 03497f2

20 files changed

+1510
-234
lines changed

‎src/app/seamly2d/xml/vpattern.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@ void VPattern::ParsePieceGrainline(const QDomElement &domElement, VPiece &piece)
10761076
gGeometry.setLength(GetParametrString(domElement, AttrLength, "1"));
10771077
gGeometry.setRotation(GetParametrString(domElement, AttrRotation, "90"));
10781078
gGeometry.setArrowType(static_cast<ArrowType>(GetParametrUInt(domElement, AttrArrows, "0")));
1079+
gGeometry.setArrowLength(GetParametrString(domElement, AttrArrowLength, ".5"));
10791080
gGeometry.setCenterAnchorPoint(GetParametrUInt(domElement, PatternPieceTool::AttrCenterAnchor, NULL_ID_STR));
10801081
gGeometry.setTopAnchorPoint(GetParametrUInt(domElement, PatternPieceTool::AttrTopAnchorPoint, NULL_ID_STR));
10811082
gGeometry.setBottomAnchorPoint(GetParametrUInt(domElement, PatternPieceTool::AttrBottomAnchorPoint, NULL_ID_STR));

‎src/libs/ifc/schema.qrc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,6 @@
6161
<file>schema/pattern/v0.7.0.xsd</file>
6262
<file>schema/pattern/v0.7.1.xsd</file>
6363
<file>schema/pattern/v0.7.2.xsd</file>
64+
<file>schema/pattern/v0.7.3.xsd</file>
6465
</qresource>
6566
</RCC>

‎src/libs/ifc/schema/pattern/v0.7.3.xsd‎

Lines changed: 1047 additions & 0 deletions
Large diffs are not rendered by default.

‎src/libs/ifc/xml/vabstractpattern.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ const QString VAbstractPattern::AttrOnFold = QStringLiteral("onFold
162162
const QString VAbstractPattern::AttrDateFormat = QStringLiteral("dateFormat");
163163
const QString VAbstractPattern::AttrTimeFormat = QStringLiteral("timeFormat");
164164
const QString VAbstractPattern::AttrArrows = QStringLiteral("arrows");
165+
const QString VAbstractPattern::AttrArrowLength = QStringLiteral("arrowLength");
165166
const QString VAbstractPattern::AttrNodeReverse = QStringLiteral("reverse");
166167
const QString VAbstractPattern::AttrNodeExcluded = QStringLiteral("excluded");
167168
const QString VAbstractPattern::AttrNodeIsNotch = QStringLiteral("notch");

‎src/libs/ifc/xml/vabstractpattern.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ class VAbstractPattern : public QObject, public VDomDocument
358358
static const QString AttrDateFormat;
359359
static const QString AttrTimeFormat;
360360
static const QString AttrArrows;
361+
static const QString AttrArrowLength;
361362
static const QString AttrNodeReverse;
362363
static const QString AttrNodeExcluded;
363364
static const QString AttrNodeIsNotch;

‎src/libs/ifc/xml/vpatternconverter.cpp‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ Q_LOGGING_CATEGORY(PatternConverter, "patternConverter")
8181
*/
8282

8383
const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0");
84-
const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.7.2");
85-
const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.7.2.xsd");
84+
const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.7.3");
85+
const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.7.3.xsd");
8686

8787
//VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!!
8888
//VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!!
@@ -341,7 +341,9 @@ QString VPatternConverter::getSchema(int ver) const
341341
case (0x000701):
342342
return QStringLiteral("://schema/pattern/v0.7.1.xsd");;
343343
case (0x000702):
344-
qCDebug(PatternConverter, "Current schema - ://schema/pattern/v0.7.2.xsd");
344+
return QStringLiteral("://schema/pattern/v0.7.2.xsd");;
345+
case (0x000703):
346+
qCDebug(PatternConverter, "Current schema - ://schema/pattern/v0.7.3.xsd");
345347
return CurrentSchema;
346348
default:
347349
InvalidVersion(ver);
@@ -540,6 +542,10 @@ void VPatternConverter::applyPatches()
540542
ValidateXML(getSchema(0x000702), m_convertedFileName);
541543
V_FALLTHROUGH
542544
case (0x000702):
545+
toVersion0_7_3();
546+
ValidateXML(getSchema(0x000703), m_convertedFileName);
547+
V_FALLTHROUGH
548+
case (0x000703):
543549
break;
544550
default:
545551
InvalidVersion(m_ver);
@@ -558,7 +564,7 @@ void VPatternConverter::downgradeToCurrentMaxVersion()
558564
bool VPatternConverter::isReadOnly() const
559565
{
560566
// Check if attribute readOnly was not changed in file format
561-
Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 7, 2),
567+
Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 7, 3),
562568
"Check attribute readOnly.");
563569

564570
// Possibly in future attribute readOnly will change position etc.
@@ -1414,6 +1420,16 @@ void VPatternConverter::toVersion0_7_2()
14141420
Save();
14151421
}
14161422

1423+
//---------------------------------------------------------------------------------------------------------------------
1424+
void VPatternConverter::toVersion0_7_3()
1425+
{
1426+
// TODO. Delete if minimal supported version is 0.7.3
1427+
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 3),
1428+
"Time to refactor the code.");
1429+
setVersion(QStringLiteral("0.7.3"));
1430+
Save();
1431+
}
1432+
14171433
//---------------------------------------------------------------------------------------------------------------------
14181434
void VPatternConverter::TagUnitToV0_2_0()
14191435
{

‎src/libs/ifc/xml/vpatternconverter.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class VPatternConverter : public VAbstractConverter
7575
static const QString PatternMaxVerStr;
7676
static const QString CurrentSchema;
7777
static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0);
78-
static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 7, 2);
78+
static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 7, 3);
7979

8080
protected:
8181
virtual int minVer() const override;
@@ -140,6 +140,7 @@ class VPatternConverter : public VAbstractConverter
140140
void toVersion0_7_0();
141141
void toVersion0_7_1();
142142
void toVersion0_7_2();
143+
void toVersion0_7_3();
143144

144145
void TagUnitToV0_2_0();
145146
void TagIncrementToV0_2_0();

‎src/libs/vlayout/vlayoutpiece.cpp‎

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ bool findLabelGeometry(const VPatternLabelData &labelData, const VContainer *pat
193193

194194
//---------------------------------------------------------------------------------------------------------------------
195195
bool findGrainlineGeometry(const VGrainlineData& data, const VContainer *pattern, qreal &length, qreal &rotationAngle,
196-
QPointF &pos)
196+
qreal &arrowLength, QPointF &pos)
197197
{
198198
SCASSERT(pattern != nullptr)
199199

@@ -211,6 +211,10 @@ bool findGrainlineGeometry(const VGrainlineData& data, const VContainer *pattern
211211
length = grainline.length();
212212
rotationAngle = grainline.angle();
213213

214+
Calculator cal3;
215+
arrowLength = cal3.EvalFormula(pattern->DataVariables(), data.getArrowLength());
216+
arrowLength = ToPixel(arrowLength, *pattern->GetPatternUnit());
217+
214218
if (!VFuzzyComparePossibleNulls(rotationAngle, 0))
215219
{
216220
grainline.setAngle(0);
@@ -236,6 +240,10 @@ bool findGrainlineGeometry(const VGrainlineData& data, const VContainer *pattern
236240
Calculator cal2;
237241
length = cal2.EvalFormula(pattern->DataVariables(), data.getLength());
238242
length = ToPixel(length, *pattern->GetPatternUnit());
243+
244+
Calculator cal3;
245+
arrowLength = cal3.EvalFormula(pattern->DataVariables(), data.getArrowLength());
246+
arrowLength = ToPixel(arrowLength, *pattern->GetPatternUnit());
239247
}
240248
catch(qmu::QmuParserError &error)
241249
{
@@ -438,20 +446,20 @@ VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern
438446
}
439447

440448
const VPieceLabelData& pieceLabelData = piece.GetPatternPieceData();
441-
if (pieceLabelData.IsVisible() == true)
449+
if (pieceLabelData.IsVisible() & qApp->Settings()->showLabels())
442450
{
443451
layoutPiece.SetPieceText(piece.GetName(), pieceLabelData, qApp->Settings()->getLabelFont(), pattern);
444452
}
445453

446454
const VPatternLabelData& patternLabelData = piece.GetPatternInfo();
447-
if (patternLabelData.IsVisible() == true)
455+
if (patternLabelData.IsVisible() & qApp->Settings()->showLabels())
448456
{
449457
VAbstractPattern* pDoc = qApp->getCurrentDocument();
450458
layoutPiece.SetPatternInfo(pDoc, patternLabelData, qApp->Settings()->getLabelFont(), pattern);
451459
}
452460

453461
const VGrainlineData& grainlineGeom = piece.GetGrainlineGeometry();
454-
if (grainlineGeom.IsVisible() == true)
462+
if (grainlineGeom.IsVisible() & qApp->Settings()->showGrainlines())
455463
{
456464
layoutPiece.setGrainline(grainlineGeom, pattern);
457465
}
@@ -633,47 +641,39 @@ void VLayoutPiece::setGrainline(const VGrainlineData& data, const VContainer* pa
633641
QPointF pt1;
634642
qreal rotationAngle = 0;
635643
qreal length = 0;
636-
if (!findGrainlineGeometry(data, pattern, length, rotationAngle, pt1))
644+
qreal arrowLength = 0;
645+
if (!findGrainlineGeometry(data, pattern, length, rotationAngle, arrowLength, pt1))
637646
{
638647
return;
639648
}
640649

641-
const qreal arrowLength = 45;
642-
const qreal arrowAngle = M_PI/9;
643-
644-
QPointF pt2(pt1.x() + arrowLength * qCos(rotationAngle),
645-
pt1.y() - arrowLength * qSin(rotationAngle));
646-
QPointF pt3(pt1.x() + length * qCos(rotationAngle),
650+
QPointF pt2(pt1.x() + length * qCos(rotationAngle),
647651
pt1.y() - length * qSin(rotationAngle));
648-
QPointF pt4(pt1.x() + (length - arrowLength) * qCos(rotationAngle),
649-
pt1.y() - (length - arrowLength) * qSin(rotationAngle));
650652

651-
QVector<QPointF> v;
652-
v << pt2;
653+
QVector<QPointF> path;
654+
path << pt1;
653655
if (data.getArrowType() != ArrowType::Top)
654656
{
655-
v << QPointF(pt1.x() + arrowLength * qCos(rotationAngle + arrowAngle),
656-
pt1.y() - arrowLength * qSin(rotationAngle + arrowAngle));
657-
v << pt1;
658-
v << QPointF(pt1.x() + arrowLength * qCos(rotationAngle - arrowAngle),
659-
pt1.y() - arrowLength * qSin(rotationAngle - arrowAngle));
660-
v << pt2;
657+
path << QPointF(pt1.x() + arrowLength * cos(rotationAngle + M_PI / 9),
658+
pt1.y() - arrowLength * sin(rotationAngle + M_PI / 9));
659+
660+
path << QPointF(pt1.x() + arrowLength * cos(rotationAngle - M_PI / 9),
661+
pt1.y() - arrowLength * sin(rotationAngle - M_PI / 9));
661662
}
663+
path << pt1 << pt2;
662664

663-
v << pt4;
664665
if (data.getArrowType() != ArrowType::Bottom)
665666
{
666-
rotationAngle += M_PI;
667-
v << QPointF(pt3.x() + arrowLength * qCos(rotationAngle + arrowAngle),
668-
pt3.y() - arrowLength * qSin(rotationAngle + arrowAngle));
669-
v << pt3;
670-
v << QPointF(pt3.x() + arrowLength * qCos(rotationAngle - arrowAngle),
671-
pt3.y() - arrowLength * qSin(rotationAngle - arrowAngle));
672-
v << pt4;
667+
path << QPointF(pt2.x() + arrowLength * cos(M_PI + rotationAngle + M_PI / 9),
668+
pt2.y() - arrowLength * sin(M_PI + rotationAngle + M_PI / 9));
669+
670+
path << QPointF(pt2.x() + arrowLength * cos(M_PI + rotationAngle - M_PI / 9),
671+
pt2.y() - arrowLength * sin(M_PI + rotationAngle - M_PI / 9));
673672
}
673+
path << pt2;
674674

675675
QScopedPointer<QGraphicsItem> item(getMainPathItem());
676-
d->grainlinePoints = CorrectPosition(item->boundingRect(), v);
676+
d->grainlinePoints = CorrectPosition(item->boundingRect(), path);
677677
}
678678

679679
//---------------------------------------------------------------------------------------------------------------------

‎src/libs/vlayout/vlayoutpiece.h‎

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,52 @@
1-
/***************************************************************************
2-
* *
3-
* Copyright (C) 2017 Seamly, LLC *
4-
* *
5-
* https://github.com/fashionfreedom/seamly2d *
6-
* *
7-
***************************************************************************
8-
**
9-
** Seamly2D is free software: you can redistribute it and/or modify
10-
** it under the terms of the GNU General Public License as published by
11-
** the Free Software Foundation, either version 3 of the License, or
12-
** (at your option) any later version.
13-
**
14-
** Seamly2D is distributed in the hope that it will be useful,
15-
** but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17-
** GNU General Public License for more details.
18-
**
19-
** You should have received a copy of the GNU General Public License
20-
** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21-
**
22-
**************************************************************************
23-
24-
************************************************************************
25-
**
26-
** @file vlayoutdetail.h
27-
** @author Roman Telezhynskyi <dismine(at)gmail.com>
28-
** @date 2 1, 2015
29-
**
30-
** @brief
31-
** @copyright
32-
** This source code is part of the Valentine project, a pattern making
33-
** program, whose allow create and modeling patterns of clothing.
34-
** Copyright (C) 2013-2015 Seamly2D project
35-
** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36-
**
37-
** Seamly2D is free software: you can redistribute it and/or modify
38-
** it under the terms of the GNU General Public License as published by
39-
** the Free Software Foundation, either version 3 of the License, or
40-
** (at your option) any later version.
41-
**
42-
** Seamly2D is distributed in the hope that it will be useful,
43-
** but WITHOUT ANY WARRANTY; without even the implied warranty of
44-
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45-
** GNU General Public License for more details.
46-
**
47-
** You should have received a copy of the GNU General Public License
48-
** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49-
**
50-
*************************************************************************/
1+
//---------------------------------------------------------------------------------------------------------------------
2+
// @file vlayoutpiece.h
3+
// @author Douglas S Caskey
4+
// @date Dec 27, 2022
5+
//
6+
// @copyright
7+
// Copyright (C) 2017 - 2025 Seamly, LLC
8+
// https://github.com/fashionfreedom/seamly2d
9+
//
10+
// @brief
11+
// Seamly2D is free software: you can redistribute it and/or modify
12+
// it under the terms of the GNU General Public License as published by
13+
// the Free Software Foundation, either version 3 of the License, or
14+
// (at your option) any later version.
15+
//
16+
// Seamly2D is distributed in the hope that it will be useful,
17+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
// GNU General Public License for more details.
20+
//
21+
// You should have received a copy of the GNU General Public License
22+
// along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
23+
//---------------------------------------------------------------------------------------------------------------------
24+
25+
//---------------------------------------------------------------------------------------------------------------------
26+
// @file vlayoutdetail.cpp
27+
// @author Roman Telezhynskyi <dismine(at)gmail.com>
28+
// @date 2 1, 2015
29+
//
30+
// @brief
31+
// @copyright
32+
// This source code is part of the Valentina project, a pattern making
33+
// program, whose allow create and modeling patterns of clothing.
34+
// Copyright (C) 2016 Valentina project
35+
// <https://bitbucket.org/dismine/valentina> All Rights Reserved.
36+
//
37+
// Valentina is free software: you can redistribute it and/or modify
38+
// it under the terms of the GNU General Public License as published by
39+
// the Free Software Foundation, either version 3 of the License, or
40+
// (at your option) any later version.
41+
//
42+
// Valentina is distributed in the hope that it will be useful,
43+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
44+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45+
// GNU General Public License for more details.
46+
//
47+
// You should have received a copy of the GNU General Public License
48+
// along with Valentina. If not, see <http://www.gnu.org/licenses/>.
49+
//---------------------------------------------------------------------------------------------------------------------
5150

5251
#ifndef VLAYOUTDETAIL_H
5352
#define VLAYOUTDETAIL_H

0 commit comments

Comments
 (0)