Seamly2D
Code documentation
vpatternconverter.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file vpatternconverter.cpp
3  ** @author Douglas S Caskey
4  ** @date Mar 2, 2023
5  **
6  ** @copyright
7  ** Copyright (C) 2017 - 2023 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  **
27  ** @file vpatternconverter.cpp
28  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
29  ** @date 11 12, 2014
30  **
31  ** @brief
32  ** @copyright
33  ** This source code is part of the Valentina project, a pattern making
34  ** program, whose allow create and modeling patterns of clothing.
35  ** Copyright (C) 2014 Valentina project
36  ** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
37  **
38  ** Valentina is free software: you can redistribute it and/or modify
39  ** it under the terms of the GNU General Public License as published by
40  ** the Free Software Foundation, either version 3 of the License, or
41  ** (at your option) any later version.
42  **
43  ** Valentina is distributed in the hope that it will be useful,
44  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
45  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46  ** GNU General Public License for more details.
47  **
48  ** You should have received a copy of the GNU General Public License
49  ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
50  **
51  *************************************************************************/
52 
53 #include "vpatternconverter.h"
54 
55 #include "vabstractconverter.h"
56 #include "../exception/vexception.h"
57 #include "../exception/vexceptionemptyparameter.h"
58 #include "../qmuparser/qmutokenparser.h"
59 #include "../vmisc/def.h"
60 #include "../vmisc/logging.h"
61 
62 #include <QDir>
63 #include <QDomNode>
64 #include <QDomNodeList>
65 #include <QDomText>
66 #include <QFile>
67 #include <QFileInfo>
68 #include <QLatin1String>
69 #include <QList>
70 #include <QStaticStringData>
71 #include <QStringData>
72 #include <QStringDataPtr>
73 #include <algorithm>
74 
75 class QDomElement;
76 
77 Q_LOGGING_CATEGORY(PatternConverter, "patternConverter")
78 
79 /*
80  * Version rules:
81  * 1. Version have three parts "major.minor.patch";
82  * 2. major part only for stable releases;
83  * 3. minor - 10 or more patch changes, or one big change;
84  * 4. patch - little change.
85  */
86 
87 const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0");
88 const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.6.8");
89 const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.6.8.xsd");
90 
91 //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!!
92 //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!!
93 
94 // The list of all string we use for conversion
95 // Better to use global variables because repeating QStringLiteral blows up code size
96 static const QString strUnit = QStringLiteral("unit");
97 static const QString strVersion = QStringLiteral("version");
98 static const QString strName = QStringLiteral("name");
99 static const QString strBase = QStringLiteral("base");
100 static const QString strFormula = QStringLiteral("formula");
101 static const QString strId = QStringLiteral("id");
102 static const QString strKGrowth = QStringLiteral("kgrowth");
103 static const QString strKSize = QStringLiteral("ksize");
104 static const QString strPoint = QStringLiteral("point");
105 static const QString strLength = QStringLiteral("length");
106 static const QString strAngle = QStringLiteral("angle");
107 static const QString strC1Radius = QStringLiteral("c1Radius");
108 static const QString strC2Radius = QStringLiteral("c2Radius");
109 static const QString strCRadius = QStringLiteral("cRadius");
110 static const QString strArc = QStringLiteral("arc");
111 static const QString strAngle1 = QStringLiteral("angle1");
112 static const QString strAngle2 = QStringLiteral("angle2");
113 static const QString strRadius = QStringLiteral("radius");
114 static const QString strPathPoint = QStringLiteral("pathPoint");
115 static const QString strKAsm1 = QStringLiteral("kAsm1");
116 static const QString strKAsm2 = QStringLiteral("kAsm2");
117 static const QString strPath = QStringLiteral("path");
118 static const QString strType = QStringLiteral("type");
119 static const QString strCutArc = QStringLiteral("cutArc");
120 static const QString strSpline = QStringLiteral("spline");
121 static const QString strSplinePath = QStringLiteral("splinePath");
122 static const QString strCutSpline = QStringLiteral("cutSpline");
123 static const QString strCutSplinePath = QStringLiteral("cutSplinePath");
124 static const QString strColor = QStringLiteral("color");
125 static const QString strMeasurements = QStringLiteral("measurements");
126 static const QString strIncrement = QStringLiteral("increment");
127 static const QString strIncrements = QStringLiteral("increments");
128 static const QString strModeling = QStringLiteral("modeling");
129 static const QString strTools = QStringLiteral("tools");
130 static const QString strIdTool = QStringLiteral("idTool");
131 static const QString strIdObject = QStringLiteral("idObject");
132 static const QString strChildren = QStringLiteral("children");
133 static const QString strChild = QStringLiteral("child");
134 static const QString strPointOfIntersectionCurves = QStringLiteral("pointOfIntersectionCurves");
135 static const QString strCurveIntersectAxis = QStringLiteral("curveIntersectAxis");
136 static const QString strCurve = QStringLiteral("curve");
137 static const QString strCurve1 = QStringLiteral("curve1");
138 static const QString strCurve2 = QStringLiteral("curve2");
139 static const QString strModelingPath = QStringLiteral("modelingPath");
140 static const QString strModelingSpline = QStringLiteral("modelingSpline");
141 static const QString strPointFromArcAndTangent = QStringLiteral("pointFromArcAndTangent");
142 static const QString strPointOfIntersectionArcs = QStringLiteral("pointOfIntersectionArcs");
143 static const QString strFirstArc = QStringLiteral("firstArc");
144 static const QString strSecondArc = QStringLiteral("secondArc");
145 static const QString strDraw = QStringLiteral("draw");
146 static const QString strDraftBlock = QStringLiteral("draftBlock");
147 static const QString strDetails = QStringLiteral("details");
148 static const QString strPieces = QStringLiteral("pieces");
149 static const QString strDetail = QStringLiteral("detail");
150 static const QString strPiece = QStringLiteral("piece");
151 static const QString strUnionDetail = QStringLiteral("unionDetail");
152 static const QString strUnion = QStringLiteral("union");
153 static const QString strSupplement = QStringLiteral("supplement");
154 static const QString strClosed = QStringLiteral("closed");
155 static const QString strWidth = QStringLiteral("width");
156 static const QString strHeight = QStringLiteral("height");
157 static const QString strNode = QStringLiteral("node");
158 static const QString strNodes = QStringLiteral("nodes");
159 static const QString strData = QStringLiteral("data");
160 static const QString strPatternInfo = QStringLiteral("patternInfo");
161 static const QString strGrainline = QStringLiteral("grainline");
162 static const QString strReverse = QStringLiteral("reverse");
163 static const QString strMx = QStringLiteral("mx");
164 static const QString strMy = QStringLiteral("my");
165 static const QString strForbidFlipping = QStringLiteral("forbidFlipping");
166 static const QString strInLayout = QStringLiteral("inLayout");
167 static const QString strSeamAllowance = QStringLiteral("seamAllowance");
168 static const QString strNodeType = QStringLiteral("nodeType");
169 static const QString strDet = QStringLiteral("det");
170 static const QString strTypeObject = QStringLiteral("typeObject");
171 static const QString strReadOnly = QStringLiteral("readOnly");
172 static const QString strPatternLabel = QStringLiteral("patternLabel");
173 static const QString strImage = QStringLiteral("image");
174 static const QString strAuthor = QStringLiteral("author");
175 static const QString strDescription = QStringLiteral("description");
176 static const QString strNotes = QStringLiteral("notes");
177 static const QString strGradation = QStringLiteral("gradation");
178 static const QString strPatternName = QStringLiteral("patternName");
179 static const QString strPatternNum = QStringLiteral("patternNumber");
180 static const QString strCompanyName = QStringLiteral("company");
181 static const QString strCustomerName = QStringLiteral("customer");
182 static const QString strLine = QStringLiteral("line");
183 static const QString strText = QStringLiteral("text");
184 static const QString strBold = QStringLiteral("bold");
185 static const QString strItalic = QStringLiteral("italic");
186 static const QString strAlignment = QStringLiteral("alignment");
187 static const QString strFSIncrement = QStringLiteral("sfIncrement");
188 static const QString strShowDate = QStringLiteral("showDate");
189 static const QString strShowMeasurements = QStringLiteral("showMeasurements");
190 static const QString strSize = QStringLiteral("size");
191 static const QString strMCP = QStringLiteral("mcp");
192 static const QString strLetter = QStringLiteral("letter");
193 static const QString strMaterial = QStringLiteral("material");
194 static const QString strUserDefined = QStringLiteral("userDef");
195 static const QString strPlacement = QStringLiteral("placement");
196 static const QString strPassmark = QStringLiteral("passmark");
197 static const QString strPassmarkLine = QStringLiteral("passmarkLine");
198 static const QString strPassmarkAngle = QStringLiteral("passmarkAngle");
199 static const QString strShowSecondPassmark = QStringLiteral("showSecondPassmark");
200 static const QString strNotch = QStringLiteral("notch");
201 static const QString strNotchCount = QStringLiteral("notchCount");
202 static const QString strNotchAngle = QStringLiteral("notchAngle");
203 static const QString strNotchType = QStringLiteral("notchType");
204 static const QString strNotchSubType = QStringLiteral("notchSubtype");
205 static const QString strShowNotch = QStringLiteral("showNotch");
206 static const QString strShowSecond = QStringLiteral("showSecondNotch");
207 static const QString strSlitNotch = QStringLiteral("slit");
208 static const QString strVMark = QStringLiteral("vMark");
209 static const QString strV_External = QStringLiteral("vExternal");
210 static const QString strTMark = QStringLiteral("tMark");
211 static const QString strT_Notch = QStringLiteral("tNotch");
212 static const QString strHair = QStringLiteral("hair");
213 static const QString strSolidLine = QStringLiteral("solidLine");
214 static const QString strOne = QStringLiteral("one");
215 static const QString strTwo = QStringLiteral("two");
216 static const QString strThree = QStringLiteral("three");
217 static const QString strTypeLine = QStringLiteral("typeLine");
218 static const QString strLineType = QStringLiteral("lineType");
219 static const QString strLineWeight = QStringLiteral("lineWeight");
220 static const QString strLineColor = QStringLiteral("lineColor");
221 static const QString strPenStyle = QStringLiteral("penStyle");
222 static const QString strElArc = QStringLiteral("elArc");
223 static const QString strTrue = QStringLiteral("true");
224 
225 static const QString strPin = QStringLiteral("pin");
226 static const QString strPins = QStringLiteral("pins");
227 static const QString strTopLeftPin = QStringLiteral("topLeftPin");
228 static const QString strBottomRightPin = QStringLiteral("bottomRightPin");
229 static const QString strCenterPin = QStringLiteral("centerPin");
230 static const QString strTopPin = QStringLiteral("topPin");
231 static const QString strBottomPin = QStringLiteral("bottomPin");
232 
233 static const QString strAnchor = QStringLiteral("anchor");
234 static const QString strAnchors = QStringLiteral("anchors");
235 static const QString strTopLeftAnchor = QStringLiteral("topLeftAnchor");
236 static const QString strBottomRightAnchor = QStringLiteral("bottomRightAnchor");
237 static const QString strCenterAnchor = QStringLiteral("centerAnchor");
238 static const QString strTopAnchor = QStringLiteral("topAnchor");
239 static const QString strBottomAnchor = QStringLiteral("bottomAnchor");
240 
241 //---------------------------------------------------------------------------------------------------------------------
242 VPatternConverter::VPatternConverter(const QString &fileName)
243  : VAbstractConverter(fileName)
244 {
245  ValidateInputFile(CurrentSchema);
246 }
247 
248 //---------------------------------------------------------------------------------------------------------------------
249 QString VPatternConverter::XSDSchema(int ver) const
250 {
251  switch (ver)
252  {
253  case (0x000100):
254  return QStringLiteral("://schema/pattern/v0.1.0.xsd");
255  case (0x000101):
256  return QStringLiteral("://schema/pattern/v0.1.1.xsd");
257  case (0x000102):
258  return QStringLiteral("://schema/pattern/v0.1.2.xsd");
259  case (0x000103):
260  return QStringLiteral("://schema/pattern/v0.1.3.xsd");
261  case (0x000104):
262  return QStringLiteral("://schema/pattern/v0.1.4.xsd");
263  case (0x000200):
264  return QStringLiteral("://schema/pattern/v0.2.0.xsd");
265  case (0x000201):
266  return QStringLiteral("://schema/pattern/v0.2.1.xsd");
267  case (0x000202):
268  return QStringLiteral("://schema/pattern/v0.2.2.xsd");
269  case (0x000203):
270  return QStringLiteral("://schema/pattern/v0.2.3.xsd");
271  case (0x000204):
272  return QStringLiteral("://schema/pattern/v0.2.4.xsd");
273  case (0x000205):
274  return QStringLiteral("://schema/pattern/v0.2.5.xsd");
275  case (0x000206):
276  return QStringLiteral("://schema/pattern/v0.2.6.xsd");
277  case (0x000207):
278  return QStringLiteral("://schema/pattern/v0.2.7.xsd");
279  case (0x000300):
280  return QStringLiteral("://schema/pattern/v0.3.0.xsd");
281  case (0x000301):
282  return QStringLiteral("://schema/pattern/v0.3.1.xsd");
283  case (0x000302):
284  return QStringLiteral("://schema/pattern/v0.3.2.xsd");
285  case (0x000303):
286  return QStringLiteral("://schema/pattern/v0.3.3.xsd");
287  case (0x000304):
288  return QStringLiteral("://schema/pattern/v0.3.4.xsd");
289  case (0x000305):
290  return QStringLiteral("://schema/pattern/v0.3.5.xsd");
291  case (0x000306):
292  return QStringLiteral("://schema/pattern/v0.3.6.xsd");
293  case (0x000307):
294  return QStringLiteral("://schema/pattern/v0.3.7.xsd");
295  case (0x000308):
296  return QStringLiteral("://schema/pattern/v0.3.8.xsd");
297  case (0x000309):
298  return QStringLiteral("://schema/pattern/v0.3.9.xsd");
299  case (0x000400):
300  return QStringLiteral("://schema/pattern/v0.4.0.xsd");
301  case (0x000401):
302  return QStringLiteral("://schema/pattern/v0.4.1.xsd");
303  case (0x000402):
304  return QStringLiteral("://schema/pattern/v0.4.2.xsd");
305  case (0x000403):
306  return QStringLiteral("://schema/pattern/v0.4.3.xsd");
307  case (0x000404):
308  return QStringLiteral("://schema/pattern/v0.4.4.xsd");
309  case (0x000405):
310  return QStringLiteral("://schema/pattern/v0.4.5.xsd");
311  case (0x000406):
312  return QStringLiteral("://schema/pattern/v0.4.6.xsd");
313  case (0x000407):
314  return QStringLiteral("://schema/pattern/v0.4.7.xsd");
315  case (0x000408):
316  return QStringLiteral("://schema/pattern/v0.4.8.xsd");
317  case (0x000500):
318  return QStringLiteral("://schema/pattern/v0.5.0.xsd");
319  case (0x000501):
320  return QStringLiteral("://schema/pattern/v0.5.1.xsd");
321  case (0x000600):
322  return QStringLiteral("://schema/pattern/v0.6.0.xsd");
323  case (0x000601):
324  return QStringLiteral("://schema/pattern/v0.6.1.xsd");
325  case (0x000602):
326  return QStringLiteral("://schema/pattern/v0.6.2.xsd");
327  case (0x000603):
328  return QStringLiteral("://schema/pattern/v0.6.3.xsd");
329  case (0x000604):
330  return QStringLiteral("://schema/pattern/v0.6.4.xsd");
331  case (0x000605):
332  return QStringLiteral("://schema/pattern/v0.6.5.xsd");
333  case (0x000606):
334  return QStringLiteral("://schema/pattern/v0.6.6.xsd");;
335  case (0x000607):
336  return QStringLiteral("://schema/pattern/v0.6.7.xsd");;
337  case (0x000608):
338  qCDebug(PatternConverter, "Current schema - ://schema/pattern/v0.6.8.xsd");
339  return CurrentSchema;
340  default:
341  InvalidVersion(ver);
342  break;
343  }
344  return QString();//unreachable code
345 }
346 
347 //---------------------------------------------------------------------------------------------------------------------
349 {
350  switch (m_ver)
351  {
352  case (0x000100):
353  toVersion0_1_1();
356  case (0x000101):
357  toVersion0_1_2();
360  case (0x000102):
361  toVersion0_1_3();
364  case (0x000103):
365  toVersion0_1_4();
368  case (0x000104):
369  toVersion0_2_0();
372  case (0x000200):
373  toVersion0_2_1();
376  case (0x000201):
377  toVersion0_2_2();
380  case (0x000202):
381  toVersion0_2_3();
384  case (0x000203):
385  toVersion0_2_4();
388  case (0x000204):
389  toVersion0_2_5();
392  case (0x000205):
393  toVersion0_2_6();
396  case (0x000206):
397  toVersion0_2_7();
400  case (0x000207):
401  toVersion0_3_0();
404  case (0x000300):
405  toVersion0_3_1();
408  case (0x000301):
409  toVersion0_3_2();
412  case (0x000302):
413  toVersion0_3_3();
416  case (0x000303):
417  toVersion0_3_4();
420  case (0x000304):
421  toVersion0_3_5();
424  case (0x000305):
425  toVersion0_3_6();
428  case (0x000306):
429  toVersion0_3_7();
432  case (0x000307):
433  toVersion0_3_8();
436  case (0x000308):
437  toVersion0_3_9();
440  case (0x000309):
441  toVersion0_4_0();
444  case (0x000400):
445  toVersion0_4_1();
448  case (0x000401):
449  toVersion0_4_2();
452  case (0x000402):
453  toVersion0_4_3();
456  case (0x000403):
457  toVersion0_4_4();
460  case (0x000404):
461  toVersion0_4_5();
464  case (0x000405):
465  toVersion0_4_6();
468  case (0x000406):
469  toVersion0_4_7();
472  case (0x000407):
473  toVersion0_4_8();
476  case (0x000408):
477  toVersion0_5_0();
480  case (0x000500):
481  toVersion0_5_1();
484  case (0x000501):
485  toVersion0_6_0();
488  case (0x000600):
489  toVersion0_6_1();
492  case (0x000601):
493  toVersion0_6_2();
496  case (0x000602):
497  toVersion0_6_3();
500  case (0x000603):
501  toVersion0_6_4();
504  case (0x000604):
505  toVersion0_6_5();
508  case (0x000605):
509  toVersion0_6_6();
512  case (0x000606):
513  toVersion0_6_7();
516  case (0x000607):
517  toVersion0_6_8();
520  case (0x000608):
521  break;
522  default:
524  break;
525  }
526 }
527 
528 //---------------------------------------------------------------------------------------------------------------------
530 {
532  Save();
533 }
534 
535 //---------------------------------------------------------------------------------------------------------------------
537 {
538  // Check if attribute readOnly was not changed in file format
539  Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 6, 8),
540  "Check attribute readOnly.");
541 
542  // Possibly in future attribute readOnly will change position etc.
543  // For now position is the same for all supported format versions.
544  // But don't forget to keep all versions of attribute until we support that format versions
545 
546  const QDomElement pattern = documentElement();
547 
548  if (pattern.isNull())
549  {
550  return false;
551  }
552 
553  return getParameterBool(pattern, strReadOnly, falseStr);
554 }
555 
556 //---------------------------------------------------------------------------------------------------------------------
558 {
559  // TODO. Delete if minimal supported version is 0.1.1
560  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 1, 1),
561  "Time to refactor the code.");
562 
563  SetVersion(QStringLiteral("0.1.1"));
564  Save();
565 }
566 
567 //---------------------------------------------------------------------------------------------------------------------
569 {
570  // TODO. Delete if minimal supported version is 0.1.2
571  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 1, 2),
572  "Time to refactor the code.");
573 
574  SetVersion(QStringLiteral("0.1.2"));
575  Save();
576 }
577 
578 //---------------------------------------------------------------------------------------------------------------------
580 {
581  // TODO. Delete if minimal supported version is 0.1.3
582  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 1, 3),
583  "Time to refactor the code.");
584 
585  SetVersion(QStringLiteral("0.1.3"));
586  Save();
587 }
588 
589 //---------------------------------------------------------------------------------------------------------------------
591 {
592  // TODO. Delete if minimal supported version is 0.1.4
593  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 1, 4),
594  "Time to refactor the code.");
595 
596  SetVersion(QStringLiteral("0.1.4"));
597  Save();
598 }
599 
600 //---------------------------------------------------------------------------------------------------------------------
602 {
603  // TODO. Delete if minimal supported version is 0.2.0
604  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 0),
605  "Time to refactor the code.");
606 
607  SetVersion(QStringLiteral("0.2.0"));
608  TagUnitToV0_2_0();
611  TagMeasurementsToV0_2_0();//Alwayse last!!!
612  Save();
613 }
614 
615 //---------------------------------------------------------------------------------------------------------------------
617 {
618  // TODO. Delete if minimal supported version is 0.2.1
619  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 1),
620  "Time to refactor the code.");
621 
622  SetVersion(QStringLiteral("0.2.1"));
624  Save();
625 }
626 
627 //---------------------------------------------------------------------------------------------------------------------
629 {
630  // TODO. Delete if minimal supported version is 0.2.2
631  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 2),
632  "Time to refactor the code.");
633 
634  SetVersion(QStringLiteral("0.2.2"));
635  Save();
636 }
637 
638 //---------------------------------------------------------------------------------------------------------------------
640 {
641  // TODO. Delete if minimal supported version is 0.2.3
642  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 3),
643  "Time to refactor the code.");
644 
645  SetVersion(QStringLiteral("0.2.3"));
646  Save();
647 }
648 
649 //---------------------------------------------------------------------------------------------------------------------
651 {
652  // TODO. Delete if minimal supported version is 0.2.4
653  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 4),
654  "Time to refactor the code.");
655 
657  SetVersion(QStringLiteral("0.2.4"));
658  Save();
659 }
660 
661 //---------------------------------------------------------------------------------------------------------------------
663 {
664  // TODO. Delete if minimal supported version is 0.2.5
665  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 5),
666  "Time to refactor the code.");
667 
668  SetVersion(QStringLiteral("0.2.5"));
669  Save();
670 }
671 
672 //---------------------------------------------------------------------------------------------------------------------
674 {
675  // TODO. Delete if minimal supported version is 0.2.6
676  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 6),
677  "Time to refactor the code.");
678 
679  SetVersion(QStringLiteral("0.2.6"));
680  Save();
681 }
682 
683 //---------------------------------------------------------------------------------------------------------------------
685 {
686  // TODO. Delete if minimal supported version is 0.2.7
687  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 7),
688  "Time to refactor the code.");
689 
690  SetVersion(QStringLiteral("0.2.7"));
691  Save();
692 }
693 
694 //---------------------------------------------------------------------------------------------------------------------
696 {
697  // TODO. Delete if minimal supported version is 0.3.0
698  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 3, 0),
699  "Time to refactor the code.");
700 
701  //Cutting path do not create anymore subpaths
702  FixCutPoint();
703  FixCutPoint();
704  SetVersion(QStringLiteral("0.3.0"));
705  Save();
706 }
707 
708 //---------------------------------------------------------------------------------------------------------------------
710 {
711  // TODO. Delete if minimal supported version is 0.3.1
712  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 3, 1),
713  "Time to refactor the code.");
714 
715  SetVersion(QStringLiteral("0.3.1"));
717  Save();
718 }
719 
720 //---------------------------------------------------------------------------------------------------------------------
722 {
723  // TODO. Delete if minimal supported version is 0.3.2
724  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 3, 2),
725  "Time to refactor the code.");
726 
727  SetVersion(QStringLiteral("0.3.2"));
728  Save();
729 }
730 
731 //---------------------------------------------------------------------------------------------------------------------
733 {
734  // TODO. Delete if minimal supported version is 0.3.3
735  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 3, 3),
736  "Time to refactor the code.");
737 
738  SetVersion(QStringLiteral("0.3.3"));
739  Save();
740 }
741 
742 //---------------------------------------------------------------------------------------------------------------------
744 {
745  // TODO. Delete if minimal supported version is 0.3.4
746  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 3, 4),
747  "Time to refactor the code.");
748 
749  SetVersion(QStringLiteral("0.3.4"));
750  Save();
751 }
752 
753 //---------------------------------------------------------------------------------------------------------------------
755 {
756  // TODO. Delete if minimal supported version is 0.3.5
757  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 3, 5),
758  "Time to refactor the code.");
759 
760  SetVersion(QStringLiteral("0.3.5"));
761  Save();
762 }
763 
764 //---------------------------------------------------------------------------------------------------------------------
766 {
767  // TODO. Delete if minimal supported version is 0.3.6
768  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 3, 6),
769  "Time to refactor the code.");
770 
771  SetVersion(QStringLiteral("0.3.6"));
772  Save();
773 }
774 
775 //---------------------------------------------------------------------------------------------------------------------
777 {
778  // TODO. Delete if minimal supported version is 0.3.7
779  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 3, 7),
780  "Time to refactor the code.");
781 
782  SetVersion(QStringLiteral("0.3.7"));
783  Save();
784 }
785 
786 //---------------------------------------------------------------------------------------------------------------------
788 {
789  // TODO. Delete if minimal supported version is 0.3.8
790  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 3, 8),
791  "Time to refactor the code.");
792 
793  SetVersion(QStringLiteral("0.3.8"));
794  Save();
795 }
796 
797 //---------------------------------------------------------------------------------------------------------------------
799 {
800  // TODO. Delete if minimal supported version is 0.3.9
801  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 3, 9),
802  "Time to refactor the code.");
803 
804  SetVersion(QStringLiteral("0.3.9"));
805  Save();
806 }
807 
808 //---------------------------------------------------------------------------------------------------------------------
810 {
811  // TODO. Delete if minimal supported version is 0.4.0
812  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
813  "Time to refactor the code.");
814 
815  SetVersion(QStringLiteral("0.4.0"));
819  Save();
820 }
821 
822 //---------------------------------------------------------------------------------------------------------------------
824 {
825  // TODO. Delete if minimal supported version is 0.4.1
826  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 1),
827  "Time to refactor the code.");
828 
829  SetVersion(QStringLiteral("0.4.1"));
830  Save();
831 }
832 
833 //---------------------------------------------------------------------------------------------------------------------
835 {
836  // TODO. Delete if minimal supported version is 0.4.2
837  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 2),
838  "Time to refactor the code.");
839 
840  SetVersion(QStringLiteral("0.4.2"));
841  Save();
842 }
843 
844 //---------------------------------------------------------------------------------------------------------------------
846 {
847  // TODO. Delete if minimal supported version is 0.4.3
848  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 3),
849  "Time to refactor the code.");
850 
851  SetVersion(QStringLiteral("0.4.3"));
852  Save();
853 }
854 
855 //---------------------------------------------------------------------------------------------------------------------
857 {
858  // TODO. Delete if minimal supported version is 0.4.4
859  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 4),
860  "Time to refactor the code.");
861 
862  SetVersion(QStringLiteral("0.4.4"));
865  Save();
866 }
867 
868 //---------------------------------------------------------------------------------------------------------------------
870 {
871  // TODO. Delete if minimal supported version is 0.4.5
872  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 5),
873  "Time to refactor the code.");
874  SetVersion(QStringLiteral("0.4.5"));
875  Save();
876 }
877 
878 //---------------------------------------------------------------------------------------------------------------------
880 {
881  // TODO. Delete if minimal supported version is 0.4.6
882  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 6),
883  "Time to refactor the code.");
884  SetVersion(QStringLiteral("0.4.6"));
885  Save();
886 }
887 
888 //---------------------------------------------------------------------------------------------------------------------
890 {
891  // TODO. Delete if minimal supported version is 0.4.7
892  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 7),
893  "Time to refactor the code.");
894  SetVersion(QStringLiteral("0.4.7"));
895  Save();
896 }
897 
898 //---------------------------------------------------------------------------------------------------------------------
900 {
901  // TODO. Delete if minimal supported version is 0.4.8
902  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 8),
903  "Time to refactor the code.");
904  SetVersion(QStringLiteral("0.4.8"));
905  Save();
906 }
907 
908 //---------------------------------------------------------------------------------------------------------------------
910 {
911  // TODO. Delete if minimal supported version is 0.5.0
912  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 5, 0),
913  "Time to refactor the code.");
914  SetVersion(QStringLiteral("0.5.0"));
915  Save();
916 }
917 
918 //---------------------------------------------------------------------------------------------------------------------
920 {
921  // TODO. Delete if minimal supported version is 0.5.1
922  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 5, 1),
923  "Time to refactor the code.");
924  SetVersion(QStringLiteral("0.5.1"));
925  Save();
926 }
927 
928 //---------------------------------------------------------------------------------------------------------------------
930 {
931  // TODO. Delete if minimal supported version is 0.6.0
932  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 0),
933  "Time to refactor the code.");
934  SetVersion(QStringLiteral("0.6.0"));
935  QDomElement label = AddTagPatternLabelV0_5_1();
939  Save();
940 }
941 
942 
943 //---------------------------------------------------------------------------------------------------------------------
945 {
946  // TODO. Delete if minimal supported version is 0.6.1
947  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 1),
948  "Time to refactor the code.");
949 
950  SetVersion(QStringLiteral("0.6.1"));
951 
952  QStringList nodenames = QStringList() << strNode
953  << strPoint
954  << strLine
955  << strPath
956  << strArc
957  << strSpline
958  << strElArc;
959 
960  QStringList oldnames = QStringList() << strPassmark
961  << strPassmarkLine
964  << strTypeLine
965  << strPenStyle;
966 
967  QString newName = "";
968  qint32 index = 0;
969 
970  for (int i = 0; i < nodenames.size(); i++)
971  {
972  QDomNodeList list = elementsByTagName(nodenames[i]);
973 
974  for (int j = 0; j < list.size(); j++)
975  {
976  QDomNode node = list.at(j);
977 
978  QDomNamedNodeMap map = node.attributes();
979 
980  for (int k = 0; k < map.size(); k++)
981  {
982  index = -1;
983  QDomNode mapItem = map.item(k);
984  QDomAttr attribute = mapItem.toAttr();
985  QString attributeName = attribute.name();
986  QString newName;
987 
988  index = oldnames.indexOf(attributeName);
989  if (index > -1)
990  {
991  QString attributeValue = attribute.value();
992  QDomElement owner = attribute.ownerElement();
993 
994  switch(index)
995  {
996  case 0:
997  {
998  newName = strNotch;
999  owner.setAttribute(strNotchAngle, 0.0);
1000  owner.setAttribute(strShowNotch, strTrue);
1001  owner.setAttribute(strShowSecond, strTrue);
1002  break;
1003  }
1004  case 1: //! Replaces " passmarkLine" with "notchType"
1005  {
1006  newName = strNotchType;
1007  if (attributeValue == strOne)
1008  {
1009  attributeValue = strSlitNotch;
1010  owner.setAttribute(strNotchCount, 1);
1011  break;
1012  }
1013  if (attributeValue == strTwo)
1014  {
1015  attributeValue = strSlitNotch;
1016  owner.setAttribute(strNotchCount, 2);
1017  break;
1018  }
1019  if (attributeValue == strThree)
1020  {
1021  attributeValue = strSlitNotch;
1022  owner.setAttribute(strNotchCount, 3);
1023  break;
1024  }
1025  if (attributeValue == strTMark)
1026  {
1027  attributeValue = strT_Notch;
1028  owner.setAttribute(strNotchCount, 1);
1029  break;
1030  }
1031  if (attributeValue == strVMark)
1032  {
1033  attributeValue = strV_External;
1034  owner.setAttribute(strNotchCount, 1);
1035  }
1036  break;
1037  }
1038  case 2: //! Replaces " passmarkAngle" with "notchSubType"
1039  {
1040  newName = strNotchSubType;
1041  break;
1042  }
1043  case 3:
1044  {
1045  newName = strShowSecond;
1046  break;
1047  }
1048  case 4: //! Fixes incorrect name & value for lineType attribute
1049  {
1050  newName = strLineType;
1051  if (attributeValue == strHair)
1052  {
1053  attributeValue = strSolidLine;
1054  }
1055  break;
1056  }
1057  case 5: //! Fixes incorrect value for penStyle attribute
1058  {
1059  newName = strPenStyle;
1060  if (attributeValue == strHair)
1061  {
1062  attributeValue = strSolidLine;
1063  }
1064  break;
1065  }
1066 
1067  default:
1068  break;
1069  }
1070  owner.removeAttribute(attributeName);
1071  owner.setAttribute(newName, attributeValue);
1072  }
1073  }
1074  }
1075  }
1076  Save();
1077 }
1078 
1079 //---------------------------------------------------------------------------------------------------------------------
1081 {
1082  // TODO. Delete if minimal supported version is 0.6.2
1083  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 2),
1084  "Time to refactor the code.");
1085  SetVersion(QStringLiteral("0.6.2"));
1086  Save();
1087 }
1088 
1089 //---------------------------------------------------------------------------------------------------------------------
1091 {
1092  // TODO. Delete if minimal supported version is 0.6.3
1093  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 3),
1094  "Time to refactor the code.");
1095  SetVersion(QStringLiteral("0.6.3"));
1096  Save();
1097 }
1098 
1099 //---------------------------------------------------------------------------------------------------------------------
1101 {
1102  // TODO. Delete if minimal supported version is 0.6.4
1103  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 4),
1104  "Time to refactor the code.");
1105  SetVersion(QStringLiteral("0.6.4"));
1106 
1107  // Update tool type attribute
1108  const QDomNodeList list = elementsByTagName(strPoint);
1109  for (int i=0; i < list.size(); ++i)
1110  {
1111  QDomElement element = list.at(i).toElement();
1112  if (!element.isNull())
1113  {
1114  const QString type = element.attribute(strType);
1115  if (type == QStringLiteral("pointOfIntersection"))
1116  {
1117  element.removeAttribute(QStringLiteral("pointOfIntersection"));
1118  element.setAttribute(strType, QStringLiteral("intersectXY"));
1119  element.setAttribute(strLineType, QStringLiteral("dashLine"));
1120  element.setAttribute(strLineWeight, QStringLiteral("0.35"));
1121  element.setAttribute(strLineColor, QStringLiteral("black"));
1122  }
1123  }
1124  }
1125  Save();
1126 }
1127 
1128 //---------------------------------------------------------------------------------------------------------------------
1130 {
1131  // TODO. Delete if minimal supported version is 0.6.5
1132  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 5),
1133  "Time to refactor the code.");
1134  SetVersion(QStringLiteral("0.6.5"));
1135 
1136  // Update tool type attribute
1137  const QDomNodeList list = elementsByTagName(strPoint);
1138  for (int i=0; i < list.size(); ++i)
1139  {
1140  QDomElement element = list.at(i).toElement();
1141  if (!element.isNull())
1142  {
1143  const QString type = element.attribute(strType);
1144  if (type == strPin)
1145  {
1146  element.removeAttribute(strPin);
1147  element.setAttribute(strType, strAnchor);
1148  }
1149  }
1150  }
1151 
1152  const QDomNodeList pinList = elementsByTagName(strPins);
1153  for (int i=0; i < pinList.size(); ++i)
1154  {
1155  QDomElement element = pinList.at(i).toElement();
1156  if (!element.isNull())
1157  {
1158  element.setTagName(strAnchors);
1159  }
1160  }
1161 
1162  const QDomNodeList dataList = elementsByTagName(strData);
1163  for (int i=0; i < dataList.size(); ++i)
1164  {
1165  QDomElement element = dataList.at(i).toElement();
1166  if (!element.isNull())
1167  {
1168  QDomAttr attribute = element.attributeNode(strCenterPin);
1169  if (!attribute.isNull())
1170  {
1171  renameAttribute(element, strCenterPin, strCenterAnchor, attribute.value());
1172  }
1173 
1174  attribute = element.attributeNode(strTopLeftPin);
1175  if (!attribute.isNull())
1176  {
1177  renameAttribute(element, strTopLeftPin, strTopLeftAnchor, attribute.value());
1178  }
1179 
1180  attribute = element.attributeNode(strBottomRightPin);
1181  if (!attribute.isNull())
1182  {
1183  renameAttribute(element, strBottomRightPin, strBottomRightAnchor, attribute.value());
1184  }
1185  }
1186  }
1187 
1188  const QDomNodeList infoList = elementsByTagName(strPatternInfo);
1189  for (int i=0; i < infoList.size(); ++i)
1190  {
1191  QDomElement element = infoList.at(i).toElement();
1192  if (!element.isNull())
1193  {
1194  QDomAttr attribute = element.attributeNode(strCenterPin);
1195  if (!attribute.isNull())
1196  {
1197  renameAttribute(element, strCenterPin, strCenterAnchor, attribute.value());
1198  }
1199 
1200  attribute = element.attributeNode(strTopLeftPin);
1201  if (!attribute.isNull())
1202  {
1203  renameAttribute(element, strTopLeftPin, strTopLeftAnchor, attribute.value());
1204  }
1205 
1206  attribute = element.attributeNode(strBottomRightPin);
1207  if (!attribute.isNull())
1208  {
1209  renameAttribute(element, strBottomRightPin, strBottomRightAnchor, attribute.value());
1210  }
1211  }
1212  }
1213 
1214  const QDomNodeList grainlineList = elementsByTagName(strGrainline);
1215  for (int i=0; i < grainlineList.size(); ++i)
1216  {
1217  QDomElement element = grainlineList.at(i).toElement();
1218  if (!element.isNull())
1219  {
1220  QDomAttr attribute = element.attributeNode(strCenterPin);
1221  if (!attribute.isNull())
1222  {
1223  renameAttribute(element, strCenterPin, strCenterAnchor, attribute.value());
1224  }
1225 
1226  attribute = element.attributeNode(strTopPin);
1227  if (!attribute.isNull())
1228  {
1229  renameAttribute(element, strTopPin, strTopAnchor, attribute.value());
1230  }
1231 
1232  attribute = element.attributeNode(strBottomPin);
1233  if (!attribute.isNull())
1234  {
1235  renameAttribute(element, strBottomPin, strBottomAnchor, attribute.value());
1236  }
1237  }
1238  }
1239  Save();
1240 }
1241 
1242 //---------------------------------------------------------------------------------------------------------------------
1244 {
1245  // TODO. Delete if minimal supported version is 0.6.6
1246  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 6),
1247  "Time to refactor the code.");
1248  SetVersion(QStringLiteral("0.6.6"));
1249 
1250  // Convert draw to draftBlock
1251  const QDomNodeList list = elementsByTagName(strDraw);
1252  for (int i=0; i < list.size(); ++i)
1253  {
1254  QDomElement element = list.at(i).toElement();
1255  if (!element.isNull())
1256  {
1257  element.setTagName(strDraftBlock);
1258  }
1259  }
1260 
1261  // Convert details to pieces
1262  const QDomNodeList detailsList = elementsByTagName(strDetails);
1263  for (int i=0; i < detailsList.size(); ++i)
1264  {
1265  QDomElement element = detailsList.at(i).toElement();
1266  if (!element.isNull())
1267  {
1268  element.setTagName(strPieces);
1269  }
1270  }
1271 
1272  // Convert detail to piece
1273  const QDomNodeList detailList = elementsByTagName(strDetail);
1274  for (int i=0; i < detailList.size(); ++i)
1275  {
1276  QDomElement element = detailList.at(i).toElement();
1277  if (!element.isNull())
1278  {
1279  element.setTagName(strPiece);
1280  }
1281  }
1282 
1283  // Convert unionDetail to union
1284  const QDomNodeList unionList = elementsByTagName(strTools);
1285  for (int i=0; i < unionList.size(); ++i)
1286  {
1287  QDomElement element = unionList.at(i).toElement();
1288  if (!element.isNull())
1289  {
1290  QDomAttr attribute = element.attributeNode(strType);
1291  if (!attribute.isNull())
1292  {
1293  attribute.setValue(strUnion);
1294  }
1295  }
1296  }
1297 
1298  // Convert det to unionPiece
1299  const QDomNodeList detList = elementsByTagName(QStringLiteral("det"));
1300  for (int i=0; i < detList.size(); ++i)
1301  {
1302  QDomElement element = detList.at(i).toElement();
1303  if (!element.isNull())
1304  {
1305  element.setTagName(QStringLiteral("unionPiece"));
1306  }
1307  }
1308  Save();
1309 }
1310 
1311 //---------------------------------------------------------------------------------------------------------------------
1313 {
1314  // TODO. Delete if minimal supported version is 0.6.7
1315  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 7),
1316  "Time to refactor the code.");
1317  SetVersion(QStringLiteral("0.6.7"));
1318  Save();
1319 }
1320 
1321 //---------------------------------------------------------------------------------------------------------------------
1323 {
1324  // TODO. Delete if minimal supported version is 0.6.8
1325  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 8),
1326  "Time to refactor the code.");
1327  SetVersion(QStringLiteral("0.6.8"));
1328  Save();
1329 }
1330 
1331 //---------------------------------------------------------------------------------------------------------------------
1333 {
1334  // TODO. Delete if minimal supported version is 0.2.0
1335  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 0),
1336  "Time to refactor the code.");
1337 
1338  QDomElement unit = createElement(strUnit);
1339  QDomText newNodeText = createTextNode(MUnitV0_1_4());
1340  unit.appendChild(newNodeText);
1341 
1342  QDomElement patternElement = documentElement();
1343  patternElement.insertAfter(unit, patternElement.firstChildElement(strVersion));
1344 }
1345 
1346 //---------------------------------------------------------------------------------------------------------------------
1348 {
1349  // TODO. Delete if minimal supported version is 0.2.0
1350  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 0),
1351  "Time to refactor the code.");
1352 
1353  const QSet<QString> names = FixIncrementsToV0_2_0();
1354 
1358 }
1359 
1360 //---------------------------------------------------------------------------------------------------------------------
1362 {
1363  // TODO. Delete if minimal supported version is 0.2.0
1364  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 0),
1365  "Time to refactor the code.");
1366 
1371 }
1372 
1373 //---------------------------------------------------------------------------------------------------------------------
1375 {
1376  // TODO. Delete if minimal supported version is 0.2.0
1377  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 0),
1378  "Time to refactor the code.");
1379 
1380  QSet<QString> names;
1381  const QDomElement incr = TagIncrementsV0_1_4();
1382  QDomNode domNode = incr.firstChild();
1383  while (domNode.isNull() == false)
1384  {
1385  if (domNode.isElement())
1386  {
1387  QDomElement domElement = domNode.toElement();
1388  if (domElement.isNull() == false)
1389  {
1390  if (domElement.tagName() == strIncrement)
1391  {
1392  try
1393  {
1394  const QString name = GetParametrString(domElement, strName);
1395  names.insert(name);
1396  domElement.setAttribute(strName, QLatin1String("#")+name);
1397 
1398  const QString base = GetParametrString(domElement, strBase);
1399  domElement.setAttribute(strFormula, base);
1400  }
1401  catch (VExceptionEmptyParameter &e)
1402  {
1403  VException excep("Can't get increment.");
1404  excep.AddMoreInformation(e.ErrorMessage());
1405  throw excep;
1406  }
1407  domElement.removeAttribute(strId);
1408  domElement.removeAttribute(strKGrowth);
1409  domElement.removeAttribute(strKSize);
1410  domElement.removeAttribute(strBase);
1411  }
1412  }
1413  }
1414  domNode = domNode.nextSibling();
1415  }
1416  return names;
1417 }
1418 
1419 //---------------------------------------------------------------------------------------------------------------------
1420 void VPatternConverter::FixPointExpressionsToV0_2_0(const QSet<QString> &names)
1421 {
1422  // TODO. Delete if minimal supported version is 0.2.0
1423  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 0),
1424  "Time to refactor the code.");
1425 
1426  QString formula;
1427  const QDomNodeList list = elementsByTagName(strPoint);
1428  for (int i=0; i < list.size(); ++i)
1429  {
1430  QDomElement dom = list.at(i).toElement();
1431 
1432  try
1433  {
1434  formula = GetParametrString(dom, strLength);
1435  dom.setAttribute(strLength, FixIncrementInFormulaToV0_2_0(formula, names));
1436  }
1437  catch (VExceptionEmptyParameter &e)
1438  {
1439  Q_UNUSED(e)
1440  }
1441 
1442  try
1443  {
1444  formula = GetParametrString(dom, strAngle);
1445  dom.setAttribute(strAngle, FixIncrementInFormulaToV0_2_0(formula, names));
1446  }
1447  catch (VExceptionEmptyParameter &e)
1448  {
1449  Q_UNUSED(e)
1450  }
1451  try
1452  {
1453  formula = GetParametrString(dom, strC1Radius);
1454  dom.setAttribute(strC1Radius, FixIncrementInFormulaToV0_2_0(formula, names));
1455  }
1456  catch (VExceptionEmptyParameter &e)
1457  {
1458  Q_UNUSED(e)
1459  }
1460 
1461  try
1462  {
1463  formula = GetParametrString(dom, strC2Radius);
1464  dom.setAttribute(strC2Radius, FixIncrementInFormulaToV0_2_0(formula, names));
1465  }
1466  catch (VExceptionEmptyParameter &e)
1467  {
1468  Q_UNUSED(e)
1469  }
1470 
1471  try
1472  {
1473  formula = GetParametrString(dom, strCRadius);
1474  dom.setAttribute(strCRadius, FixIncrementInFormulaToV0_2_0(formula, names));
1475  }
1476  catch (VExceptionEmptyParameter &e)
1477  {
1478  Q_UNUSED(e)
1479  }
1480  }
1481 }
1482 
1483 //---------------------------------------------------------------------------------------------------------------------
1484 void VPatternConverter::FixArcExpressionsToV0_2_0(const QSet<QString> &names)
1485 {
1486  // TODO. Delete if minimal supported version is 0.2.0
1487  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 0),
1488  "Time to refactor the code.");
1489 
1490  QString formula;
1491  const QDomNodeList list = elementsByTagName(strArc);
1492  for (int i=0; i < list.size(); ++i)
1493  {
1494  QDomElement dom = list.at(i).toElement();
1495 
1496  try
1497  {
1498  formula = GetParametrString(dom, strAngle1);
1499  dom.setAttribute(strAngle1, FixIncrementInFormulaToV0_2_0(formula, names));
1500  }
1501  catch (VExceptionEmptyParameter &e)
1502  {
1503  Q_UNUSED(e)
1504  }
1505 
1506  try
1507  {
1508  formula = GetParametrString(dom, strAngle2);
1509  dom.setAttribute(strAngle2, FixIncrementInFormulaToV0_2_0(formula, names));
1510  }
1511  catch (VExceptionEmptyParameter &e)
1512  {
1513  Q_UNUSED(e)
1514  }
1515 
1516  try
1517  {
1518  formula = GetParametrString(dom, strRadius);
1519  dom.setAttribute(strRadius, FixIncrementInFormulaToV0_2_0(formula, names));
1520  }
1521  catch (VExceptionEmptyParameter &e)
1522  {
1523  Q_UNUSED(e)
1524  }
1525 
1526  try
1527  {
1528  formula = GetParametrString(dom, strLength);
1529  dom.setAttribute(strLength, FixIncrementInFormulaToV0_2_0(formula, names));
1530  }
1531  catch (VExceptionEmptyParameter &e)
1532  {
1533  Q_UNUSED(e)
1534  }
1535  }
1536 }
1537 
1538 //---------------------------------------------------------------------------------------------------------------------
1540 {
1541  // TODO. Delete if minimal supported version is 0.2.0
1542  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 0),
1543  "Time to refactor the code.");
1544 
1545  QString formula;
1546  const QDomNodeList list = elementsByTagName(strPathPoint);
1547  for (int i=0; i < list.size(); ++i)
1548  {
1549  QDomElement dom = list.at(i).toElement();
1550 
1551  try
1552  {
1553  formula = GetParametrString(dom, strKAsm1);
1554  dom.setAttribute(strKAsm1, FixIncrementInFormulaToV0_2_0(formula, names));
1555  }
1556  catch (VExceptionEmptyParameter &e)
1557  {
1558  Q_UNUSED(e)
1559  }
1560 
1561  try
1562  {
1563  formula = GetParametrString(dom, strKAsm2);
1564  dom.setAttribute(strKAsm2, FixIncrementInFormulaToV0_2_0(formula, names));
1565  }
1566  catch (VExceptionEmptyParameter &e)
1567  {
1568  Q_UNUSED(e)
1569  }
1570 
1571  try
1572  {
1573  formula = GetParametrString(dom, strAngle);
1574  dom.setAttribute(strAngle, FixIncrementInFormulaToV0_2_0(formula, names));
1575  }
1576  catch (VExceptionEmptyParameter &e)
1577  {
1578  Q_UNUSED(e)
1579  }
1580  }
1581 }
1582 
1583 //---------------------------------------------------------------------------------------------------------------------
1585 {
1586  // TODO. Delete if minimal supported version is 0.2.0
1587  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 0),
1588  "Time to refactor the code.");
1589 
1590  QString formula;
1591  const QDomNodeList list = elementsByTagName(strPoint);
1592  for (int i=0; i < list.size(); ++i)
1593  {
1594  QDomElement dom = list.at(i).toElement();
1595 
1596  try
1597  {
1598  formula = GetParametrString(dom, strLength);
1599  dom.setAttribute(strLength, FixMeasurementInFormulaToV0_2_0(formula, names));
1600  }
1601  catch (VExceptionEmptyParameter &e)
1602  {
1603  Q_UNUSED(e)
1604  }
1605 
1606  try
1607  {
1608  formula = GetParametrString(dom, strAngle);
1609  dom.setAttribute(strAngle, FixMeasurementInFormulaToV0_2_0(formula, names));
1610  }
1611  catch (VExceptionEmptyParameter &e)
1612  {
1613  Q_UNUSED(e)
1614  }
1615  try
1616  {
1617  formula = GetParametrString(dom, strC1Radius);
1618  dom.setAttribute(strC1Radius, FixMeasurementInFormulaToV0_2_0(formula, names));
1619  }
1620  catch (VExceptionEmptyParameter &e)
1621  {
1622  Q_UNUSED(e)
1623  }
1624 
1625  try
1626  {
1627  formula = GetParametrString(dom, strC2Radius);
1628  dom.setAttribute(strC2Radius, FixMeasurementInFormulaToV0_2_0(formula, names));
1629  }
1630  catch (VExceptionEmptyParameter &e)
1631  {
1632  Q_UNUSED(e)
1633  }
1634 
1635  try
1636  {
1637  formula = GetParametrString(dom, strCRadius);
1638  dom.setAttribute(strCRadius, FixMeasurementInFormulaToV0_2_0(formula, names));
1639  }
1640  catch (VExceptionEmptyParameter &e)
1641  {
1642  Q_UNUSED(e)
1643  }
1644  }
1645 }
1646 
1647 //---------------------------------------------------------------------------------------------------------------------
1649 {
1650  // TODO. Delete if minimal supported version is 0.2.0
1651  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 0),
1652  "Time to refactor the code.");
1653 
1654  QString formula;
1655  const QDomNodeList list = elementsByTagName(strArc);
1656  for (int i=0; i < list.size(); ++i)
1657  {
1658  QDomElement dom = list.at(i).toElement();
1659 
1660  try
1661  {
1662  formula = GetParametrString(dom, strAngle1);
1663  dom.setAttribute(strAngle1, FixMeasurementInFormulaToV0_2_0(formula, names));
1664  }
1665  catch (VExceptionEmptyParameter &e)
1666  {
1667  Q_UNUSED(e)
1668  }
1669 
1670  try
1671  {
1672  formula = GetParametrString(dom, strAngle2);
1673  dom.setAttribute(strAngle2, FixMeasurementInFormulaToV0_2_0(formula, names));
1674  }
1675  catch (VExceptionEmptyParameter &e)
1676  {
1677  Q_UNUSED(e)
1678  }
1679 
1680  try
1681  {
1682  formula = GetParametrString(dom, strRadius);
1683  dom.setAttribute(strRadius, FixMeasurementInFormulaToV0_2_0(formula, names));
1684  }
1685  catch (VExceptionEmptyParameter &e)
1686  {
1687  Q_UNUSED(e)
1688  }
1689 
1690  try
1691  {
1692  formula = GetParametrString(dom, strLength);
1693  dom.setAttribute(strLength, FixMeasurementInFormulaToV0_2_0(formula, names));
1694  }
1695  catch (VExceptionEmptyParameter &e)
1696  {
1697  Q_UNUSED(e)
1698  }
1699  }
1700 }
1701 
1702 //---------------------------------------------------------------------------------------------------------------------
1704 {
1705  // TODO. Delete if minimal supported version is 0.2.0
1706  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 0),
1707  "Time to refactor the code.");
1708 
1709  QString formula;
1710  const QDomNodeList list = elementsByTagName(strPathPoint);
1711  for (int i=0; i < list.size(); ++i)
1712  {
1713  QDomElement dom = list.at(i).toElement();
1714 
1715  try
1716  {
1717  formula = GetParametrString(dom, strKAsm1);
1718  dom.setAttribute(strKAsm1, FixMeasurementInFormulaToV0_2_0(formula, names));
1719  }
1720  catch (VExceptionEmptyParameter &e)
1721  {
1722  Q_UNUSED(e)
1723  }
1724 
1725  try
1726  {
1727  formula = GetParametrString(dom, strKAsm2);
1728  dom.setAttribute(strKAsm2, FixMeasurementInFormulaToV0_2_0(formula, names));
1729  }
1730  catch (VExceptionEmptyParameter &e)
1731  {
1732  Q_UNUSED(e)
1733  }
1734 
1735  try
1736  {
1737  formula = GetParametrString(dom, strAngle);
1738  dom.setAttribute(strAngle, FixMeasurementInFormulaToV0_2_0(formula, names));
1739  }
1740  catch (VExceptionEmptyParameter &e)
1741  {
1742  Q_UNUSED(e)
1743  }
1744  }
1745 }
1746 
1747 //---------------------------------------------------------------------------------------------------------------------
1749 {
1750  // TODO. Delete if minimal supported version is 0.2.0
1751  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 0),
1752  "Time to refactor the code.");
1753 
1754  QScopedPointer<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(formula, false, false));// Eval formula
1755  QMap<int, QString> tokens = cal->GetTokens();// Tokens (variables, measurements)
1756  delete cal.take();
1757 
1758  QList<int> tKeys = tokens.keys();// Take all tokens positions
1759  QList<QString> tValues = tokens.values();
1760 
1761  QString newFormula = formula;// Local copy for making changes
1762  for (int i = 0; i < tValues.size(); ++i)
1763  {
1764  if (not names.contains(tValues.at(i)))
1765  {
1766  continue;
1767  }
1768 
1769  int bias = 0;
1770  Replace(newFormula, names.value(tValues.at(i)), tKeys.at(i), tValues.at(i), bias);
1771  if (bias != 0)
1772  {// Translated token has different length than original. Position next tokens need to be corrected.
1773  CorrectionsPositions(tKeys.at(i), bias, tokens);
1774  tKeys = tokens.keys();
1775  tValues = tokens.values();
1776  }
1777  }
1778  return newFormula;
1779 }
1780 
1781 //---------------------------------------------------------------------------------------------------------------------
1782 QString VPatternConverter::FixIncrementInFormulaToV0_2_0(const QString &formula, const QSet<QString> &names)
1783 {
1784  // TODO. Delete if minimal supported version is 0.2.0
1785  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 0),
1786  "Time to refactor the code.");
1787 
1788  qmu::QmuTokenParser *cal = new qmu::QmuTokenParser(formula, false, false);// Eval formula
1789  QMap<int, QString> tokens = cal->GetTokens();// Tokens (variables, measurements)
1790  delete cal;
1791 
1792  QList<int> tKeys = tokens.keys();// Take all tokens positions
1793  QList<QString> tValues = tokens.values();
1794 
1795  QString newFormula = formula;// Local copy for making changes
1796  for (int i = 0; i < tValues.size(); ++i)
1797  {
1798  if (not names.contains(tValues.at(i)))
1799  {
1800  continue;
1801  }
1802 
1803  int bias = 0;
1804  Replace(newFormula, "#"+tValues.at(i), tKeys.at(i), tValues.at(i), bias);
1805  if (bias != 0)
1806  {// Translated token has different length than original. Position next tokens need to be corrected.
1807  CorrectionsPositions(tKeys.at(i), bias, tokens);
1808  tKeys = tokens.keys();
1809  tValues = tokens.values();
1810  }
1811  }
1812  return newFormula;
1813 }
1814 
1815 //---------------------------------------------------------------------------------------------------------------------
1817 {
1818  // TODO. Delete if minimal supported version is 0.2.0
1819  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 0),
1820  "Time to refactor the code.");
1821 
1822  QDomElement ms = TagMeasurementsV0_1_4();
1823  const QString path = GetParametrString(ms, strPath);
1824 
1825  ms.removeAttribute(strUnit);
1826  ms.removeAttribute(strType);
1827  ms.removeAttribute(strPath);
1828 
1829  QDomText newNodeText = createTextNode(QFileInfo(m_convertedFileName).absoluteDir().relativeFilePath(path));
1830  ms.appendChild(newNodeText);
1831 }
1832 
1833 //---------------------------------------------------------------------------------------------------------------------
1835 {
1836  // TODO. Delete if minimal supported version is 0.2.1
1837  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 1),
1838  "Time to refactor the code.");
1839 
1841 
1842  // Structure did not change. We can use the same code.
1846 }
1847 
1848 //---------------------------------------------------------------------------------------------------------------------
1850 {
1851  // TODO. Delete if minimal supported version is 0.3.1
1852  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 3, 1),
1853  "Time to refactor the code.");
1854 
1855  const QDomNodeList list = elementsByTagName(strPoint);
1856  for (int i=0; i < list.size(); ++i)
1857  {
1858  QDomElement element = list.at(i).toElement();
1859  if (not element.isNull())
1860  {
1861  const QString type = element.attribute(strType);
1862  if (type == strCutArc || type == strCutSpline || type == strCutSplinePath)
1863  {
1864  element.removeAttribute(strColor);
1865  }
1866  }
1867  }
1868 }
1869 
1870 //---------------------------------------------------------------------------------------------------------------------
1872 {
1873  // TODO. Delete if minimal supported version is 0.1.4
1874  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 1, 4),
1875  "Time to refactor the code.");
1876 
1877  const QDomElement element = TagMeasurementsV0_1_4();
1878  try
1879  {
1880  return GetParametrString(element, strUnit);
1881  }
1882  catch (VExceptionEmptyParameter &e)
1883  {
1884  VException excep("Can't get unit.");
1885  excep.AddMoreInformation(e.ErrorMessage());
1886  throw excep;
1887  }
1888 }
1889 
1890 //---------------------------------------------------------------------------------------------------------------------
1892 {
1893  // TODO. Delete if minimal supported version is 0.1.4
1894  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 1, 4),
1895  "Time to refactor the code.");
1896 
1897  const QDomNodeList list = elementsByTagName(strMeasurements);
1898  const QDomElement element = list.at(0).toElement();
1899  if (not element.isElement())
1900  {
1901  VException excep("Can't get tag measurements.");
1902  throw excep;
1903  }
1904  return element;
1905 }
1906 
1907 //---------------------------------------------------------------------------------------------------------------------
1909 {
1910  // TODO. Delete if minimal supported version is 0.1.4
1911  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 1, 4),
1912  "Time to refactor the code.");
1913 
1914  const QDomNodeList list = elementsByTagName(strIncrements);
1915  const QDomElement element = list.at(0).toElement();
1916  if (not element.isElement())
1917  {
1918  VException excep("Can't get tag measurements.");
1919  throw excep;
1920  }
1921  return element;
1922 }
1923 
1924 //---------------------------------------------------------------------------------------------------------------------
1926 {
1927  // TODO. Delete if minimal supported version is 0.2.4
1928  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 4),
1929  "Time to refactor the code.");
1930 
1931  QDomElement root = documentElement();
1932  const QDomNodeList modelings = root.elementsByTagName(strModeling);
1933  for (int i=0; i<modelings.size(); ++i)
1934  {
1935  ParseModelingToV0_2_4(modelings.at(i).toElement());
1936  }
1937 }
1938 
1939 //---------------------------------------------------------------------------------------------------------------------
1940 void VPatternConverter::ParseModelingToV0_2_4(const QDomElement &modeling)
1941 {
1942  // TODO. Delete if minimal supported version is 0.2.4
1943  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 4),
1944  "Time to refactor the code.");
1945 
1946  QDomElement node = modeling.firstChild().toElement();
1947  while (not node.isNull())
1948  {
1949  if (node.tagName() == strTools)
1950  {
1951  const quint32 toolId = node.attribute(strId).toUInt();
1952  QVector<quint32> children;
1953  QDomElement childNode = node.nextSibling().toElement();
1954  while (not childNode.isNull())
1955  {
1956  if (childNode.hasAttribute(strIdTool) && childNode.attribute(strIdTool).toUInt() == toolId)
1957  {
1958  children.append(childNode.attribute(strIdObject).toUInt());
1959  }
1960  else
1961  {
1962  break;
1963  }
1964  childNode = childNode.nextSibling().toElement();
1965  }
1966 
1967  if (not children.isEmpty())
1968  {
1969  SaveChildrenToolUnionToV0_2_4(toolId, children);
1970  }
1971  node = childNode;
1972  continue;
1973  }
1974  node = node.nextSibling().toElement();
1975  }
1976 }
1977 
1978 //---------------------------------------------------------------------------------------------------------------------
1980 {
1981  // TODO. Delete if minimal supported version is 0.2.4
1982  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 4),
1983  "Time to refactor the code.");
1984 
1985  QDomElement toolUnion = elementById(id);
1986  if (toolUnion.isNull())
1987  {
1988  return;
1989  }
1990 
1991  QDomElement tagChildren = createElement(strChildren);
1992 
1993  for (int i=0; i<children.size(); ++i)
1994  {
1995  QDomElement tagChild = createElement(strChild);
1996  tagChild.appendChild(createTextNode(QString().setNum(children.at(i))));
1997  tagChildren.appendChild(tagChild);
1998  }
1999 
2000  toolUnion.appendChild(tagChildren);
2001 }
2002 
2003 //---------------------------------------------------------------------------------------------------------------------
2005 {
2006  // TODO. Delete if minimal supported version is 0.2.0
2007  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 0),
2008  "Time to refactor the code.");
2009 
2010  // old name, new name
2011  QMap<QString, QString> names;
2012 
2013  names.insert(QStringLiteral("cervicale_height"), QStringLiteral("height_neck_back"));
2014  names.insert(QStringLiteral("height_scapular_point"), QStringLiteral("height_scapula"));
2015  names.insert(QStringLiteral("height_back_angle_axilla"), QStringLiteral("height_armpit"));
2016  names.insert(QStringLiteral("waist_height"), QStringLiteral("height_waist_side"));
2017  names.insert(QStringLiteral("hip_height"), QStringLiteral("height_hip"));
2018  names.insert(QStringLiteral("knee_height"), QStringLiteral("height_knee"));
2019  names.insert(QStringLiteral("ankle_height"), QStringLiteral("height_ankle"));
2020  names.insert(QStringLiteral("high_hip_height"), QStringLiteral("height_highhip"));
2021  names.insert(QStringLiteral("front_waist_to_floor"), QStringLiteral("height_waist_front"));
2022  names.insert(QStringLiteral("height_nipple_point"), QStringLiteral("height_bustpoint"));
2023 
2024  QString name = QStringLiteral("height_shoulder_tip");
2025  names.insert(QStringLiteral("shoulder_height"), name);
2026  names.insert(QStringLiteral("height_shoulder_point"), name);
2027 
2028  name = QStringLiteral("height_neck_front");
2029  names.insert(QStringLiteral("height_clavicular_point"), name);
2030  names.insert(QStringLiteral("height_front_neck_base_point"), name);
2031 
2032  names.insert(QStringLiteral("height_base_neck_side_point"), QStringLiteral("height_neck_side"));
2033 
2034  name = QStringLiteral("height_neck_back_to_knee");
2035  names.insert(QStringLiteral("neck_to_knee_point"), name);
2036  names.insert(QStringLiteral("cervicale_to_knee_height"), name);
2037 
2038  names.insert(QStringLiteral("waist_to_knee_height"), QStringLiteral("height_waist_side_to_knee"));
2039  names.insert(QStringLiteral("waist_to_hip_height"), QStringLiteral("height_waist_side_to_hip"));
2040  names.insert(QStringLiteral("body_position"), QStringLiteral("indent_neck_back"));
2041 
2042  name = QStringLiteral("neck_mid_circ");
2043  names.insert(QStringLiteral("half_girth_neck_for_shirts"), name);
2044  names.insert(QStringLiteral("mid_neck_girth"), name);
2045 
2046  names.insert(QStringLiteral("neck_base_girth"), QStringLiteral("neck_circ"));
2047  names.insert(QStringLiteral("upper_chest_girth"), QStringLiteral("highbust_circ"));
2048  names.insert(QStringLiteral("bust_girth"), QStringLiteral("bust_circ"));
2049  names.insert(QStringLiteral("under_bust_girth"), QStringLiteral("lowbust_circ"));
2050  names.insert(QStringLiteral("waist_girth"), QStringLiteral("waist_circ"));
2051  names.insert(QStringLiteral("high_hip_girth"), QStringLiteral("highhip_circ"));
2052  names.insert(QStringLiteral("hips_excluding_protruding_abdomen"), QStringLiteral("hip_circ"));
2053  names.insert(QStringLiteral("hip_girth"), QStringLiteral("hip_circ_with_abdomen"));
2054 
2055  name = QStringLiteral("neck_arc_f");
2056  names.insert(QStringLiteral("half_girth_neck"), name);
2057  names.insert(QStringLiteral("front_neck_arc"), name);
2058 
2059  name = QStringLiteral("highbust_arc_f");
2060  names.insert(QStringLiteral("half_girth_chest_first"), name);
2061  names.insert(QStringLiteral("front_upper_chest_arc"), name);
2062 
2063  names.insert(QStringLiteral("half_girth_chest_second"), QStringLiteral("bust_arc_f"));
2064  names.insert(QStringLiteral("half_girth_chest_third"), QStringLiteral("lowbust_arc_f"));
2065 
2066  name = QStringLiteral("waist_arc_f");
2067  names.insert(QStringLiteral("half_girth_waist"), name);
2068  names.insert(QStringLiteral("front_waist_arc"), name);
2069 
2070  names.insert(QStringLiteral("front_upper_hip_arc"), QStringLiteral("highhip_arc_f"));
2071 
2072  name = QStringLiteral("hip_arc_f");
2073  names.insert(QStringLiteral("half_girth_hips_excluding_protruding_abdomen"), name);
2074  names.insert(QStringLiteral("front_hip_arc"), name);
2075 
2076  names.insert(QStringLiteral("back_neck_arc"), QStringLiteral("neck_arc_b"));
2077  names.insert(QStringLiteral("back_upper_chest_arc"), QStringLiteral("highbust_arc_b"));
2078  names.insert(QStringLiteral("back_waist_arc"), QStringLiteral("waist_arc_b"));
2079  names.insert(QStringLiteral("back_upper_hip_arc"), QStringLiteral("highhip_arc_b"));
2080  names.insert(QStringLiteral("back_hip_arc"), QStringLiteral("hip_arc_b"));
2081  names.insert(QStringLiteral("half_girth_hips_considering_protruding_abdomen"),
2082  QStringLiteral("hip_with_abdomen_arc_f"));
2083  names.insert(QStringLiteral("shoulder_girth"), QStringLiteral("body_armfold_circ"));
2084  names.insert(QStringLiteral("trunk_length"), QStringLiteral("body_torso_circ"));
2085  names.insert(QStringLiteral("front_waist_length"), QStringLiteral("neck_front_to_waist_f"));
2086  names.insert(QStringLiteral("center_front_waist_length"), QStringLiteral("neck_front_to_waist_flat_f"));
2087  names.insert(QStringLiteral("side_waist_length"), QStringLiteral("armpit_to_waist_side"));
2088  names.insert(QStringLiteral("waist_to_neck_side"), QStringLiteral("neck_side_to_waist_b"));
2089 
2090  name = QStringLiteral("neck_side_to_waist_f");
2091  names.insert(QStringLiteral("neck_to_front_waist_line"), name);
2092  names.insert(QStringLiteral("front_shoulder_to_waist_length"), name);
2093 
2094  names.insert(QStringLiteral("back_shoulder_to_waist_length"), QStringLiteral("neck_side_to_waist_b"));
2095  names.insert(QStringLiteral("center_back_waist_length"), QStringLiteral("neck_back_to_waist_b"));
2096 
2097  name = QStringLiteral("neck_front_to_highbust_f");
2098  names.insert(QStringLiteral("neck_to_first_line_chest_circumference"), name);
2099  names.insert(QStringLiteral("front_neck_to_upper_chest_height"), name);
2100 
2101  names.insert(QStringLiteral("front_neck_to_bust_height"), QStringLiteral("neck_front_to_bust_f"));
2102  names.insert(QStringLiteral("front_waist_to_upper_chest"), QStringLiteral("highbust_to_waist_f"));
2103  names.insert(QStringLiteral("front_waist_to_lower_breast"), QStringLiteral("lowbust_to_waist_f"));
2104  names.insert(QStringLiteral("neck_to_back_line_chest_circumference"), QStringLiteral("neck_back_to_highbust_b"));
2105  names.insert(QStringLiteral("depth_waist_first"), QStringLiteral("waist_to_highhip_f"));
2106  names.insert(QStringLiteral("depth_waist_second"), QStringLiteral("waist_to_hip_f"));
2107  names.insert(QStringLiteral("shoulder_slope_degrees"), QStringLiteral("shoulder_slope_neck_side_angle"));
2108  names.insert(QStringLiteral("shoulder_drop"), QStringLiteral("shoulder_slope_neck_side_length"));
2109  names.insert(QStringLiteral("across_front_shoulder_width"), QStringLiteral("shoulder_tip_to_shoulder_tip_f"));
2110  names.insert(QStringLiteral("upper_front_chest_width"), QStringLiteral("across_chest_f"));
2111  names.insert(QStringLiteral("chest_width"), QStringLiteral("across_chest_f"));
2112  names.insert(QStringLiteral("front_chest_width"), QStringLiteral("armfold_to_armfold_f"));
2113 
2114  name = QStringLiteral("shoulder_tip_to_shoulder_tip_b");
2115  names.insert(QStringLiteral("arc_behind_shoulder_girdle"), name);
2116  names.insert(QStringLiteral("across_back_shoulder_width"), name);
2117 
2118  names.insert(QStringLiteral("upper_back_width"), QStringLiteral("across_back_b"));
2119  names.insert(QStringLiteral("back_width"), QStringLiteral("armfold_to_armfold_b"));
2120  names.insert(QStringLiteral("neck_transverse_diameter"), QStringLiteral("neck_width"));
2121  names.insert(QStringLiteral("bustpoint_to_bustpoint"), QStringLiteral("bustpoint_to_bustpoint"));
2122  names.insert(QStringLiteral("neck_to_bustpoint"), QStringLiteral("bustpoint_to_neck_side"));
2123  names.insert(QStringLiteral("halter_bustpoint_to_bustpoint"), QStringLiteral("bustpoint_to_bustpoint_halter"));
2124 
2125  name = QStringLiteral("shoulder_tip_to_waist_front");
2126  names.insert(QStringLiteral("front_slash_shoulder_height"), name);
2127  names.insert(QStringLiteral("front_shoulder_slope_length"), name);
2128 
2129  names.insert(QStringLiteral("front_waist_slope"), QStringLiteral("neck_front_to_waist_side"));
2130 
2131  name = QStringLiteral("neck_side_to_armfold_f");
2132  names.insert(QStringLiteral("height_armhole_slash"), name);
2133  names.insert(QStringLiteral("chest_slope"), name);
2134 
2135  name = QStringLiteral("shoulder_tip_to_waist_back");
2136  names.insert(QStringLiteral("slash_shoulder_height"), name);
2137  names.insert(QStringLiteral("back_shoulder_slope_length"), name);
2138 
2139  names.insert(QStringLiteral("back_waist_slope"), QStringLiteral("neck_back_to_waist_side"));
2140  names.insert(QStringLiteral("back_slope"), QStringLiteral("neck_side_to_armfold_b"));
2141  names.insert(QStringLiteral("arm_length"), QStringLiteral("arm_shoulder_tip_to_wrist"));
2142  names.insert(QStringLiteral("shoulder_to_elbow_length"), QStringLiteral("arm_shoulder_tip_to_elbow"));
2143  names.insert(QStringLiteral("underarm_length"), QStringLiteral("arm_armpit_to_wrist"));
2144  names.insert(QStringLiteral("upper_arm_girth"), QStringLiteral("arm_upper_circ"));
2145  names.insert(QStringLiteral("wrist_girth"), QStringLiteral("arm_wrist_circ"));
2146  names.insert(QStringLiteral("armscye_girth"), QStringLiteral("armscye_circ"));
2147  names.insert(QStringLiteral("anteroposterior_diameter_hands"), QStringLiteral("armscye_width"));
2148  names.insert(QStringLiteral("neck_to_third_finger"), QStringLiteral("arm_neck_side_to_finger_tip"));
2149  names.insert(QStringLiteral("neck_to_radial_point"), QStringLiteral("arm_neck_side_to_outer_elbow"));
2150  names.insert(QStringLiteral("shoulder_and_arm_length"), QStringLiteral("arm_neck_side_to_wrist"));
2151  names.insert(QStringLiteral("crotch_height"), QStringLiteral("leg_crotch_to_floor"));
2152  names.insert(QStringLiteral("side_waist_to_floor"), QStringLiteral("leg_waist_side_to_floor"));
2153  names.insert(QStringLiteral("waist_to_knee"), QStringLiteral("leg_waist_side_to_knee"));
2154  names.insert(QStringLiteral("thigh_girth"), QStringLiteral("leg_thigh_upper_circ"));
2155  names.insert(QStringLiteral("mid_thigh_girth"), QStringLiteral("leg_thigh_mid_circ"));
2156  names.insert(QStringLiteral("knee_girth"), QStringLiteral("leg_knee_circ"));
2157  names.insert(QStringLiteral("calf_girth"), QStringLiteral("leg_calf_circ"));
2158  names.insert(QStringLiteral("ankle_girth"), QStringLiteral("leg_ankle_circ"));
2159  names.insert(QStringLiteral("girth_knee_flexed_feet"), QStringLiteral("leg_knee_circ_bent"));
2160  names.insert(QStringLiteral("arc_through_groin_area"), QStringLiteral("crotch_length"));
2161  names.insert(QStringLiteral("waist_to_plane_seat"), QStringLiteral("rise_length_side_sitting"));
2162  names.insert(QStringLiteral("rise_height"), QStringLiteral("rise_length_diag"));
2163  names.insert(QStringLiteral("hand_vertical_diameter"), QStringLiteral("hand_length"));
2164  names.insert(QStringLiteral("hand_width"), QStringLiteral("hand_palm_width"));
2165  names.insert(QStringLiteral("hand_girth"), QStringLiteral("hand_circ"));
2166  names.insert(QStringLiteral("girth_foot_instep"), QStringLiteral("foot_instep_circ"));
2167  names.insert(QStringLiteral("head_height"), QStringLiteral("head_length"));
2168  names.insert(QStringLiteral("head_and_neck_length"), QStringLiteral("head_crown_to_neck_back"));
2169  names.insert(QStringLiteral("neck_to_neck_base"), QStringLiteral("head_chin_to_neck_back"));
2170  names.insert(QStringLiteral("arc_length_upper_body"), QStringLiteral("waist_to_waist_halter"));
2171  names.insert(QStringLiteral("cervicale_to_wrist_length"), QStringLiteral("arm_neck_back_to_wrist_bent"));
2172  names.insert(QStringLiteral("strap_length"), QStringLiteral("highbust_b_over_shoulder_to_highbust_f"));
2173  names.insert(QStringLiteral("arc_through_shoulder_joint"), QStringLiteral("armscye_arc"));
2174  names.insert(QStringLiteral("head_girth"), QStringLiteral("head_circ"));
2175  names.insert(QStringLiteral("elbow_girth"), QStringLiteral("arm_elbow_circ"));
2176  names.insert(QStringLiteral("height_under_buttock_folds"), QStringLiteral("height_gluteal_fold"));
2177  names.insert(QStringLiteral("scye_depth"), QStringLiteral("neck_back_to_highbust_b"));
2178  names.insert(QStringLiteral("back_waist_to_upper_chest"), QStringLiteral("across_back_to_waist_b"));
2179 
2180  return names;
2181 }
2182 
2183 //---------------------------------------------------------------------------------------------------------------------
2185 {
2186  // TODO. Delete if minimal supported version is 0.2.1
2187  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 1),
2188  "Time to refactor the code.");
2189 
2190  // old name, new name
2191  QMap<QString, QString> names;
2192 
2193  names.insert(QStringLiteral("rise_length_side"), QStringLiteral("rise_length_side_sitting"));
2194  names.insert(QStringLiteral("size"), QStringLiteral("bust_arc_f"));
2195 
2196  return names;
2197 }
2198 
2199 //---------------------------------------------------------------------------------------------------------------------
2201 {
2202  const QStringList types = QStringList() << strCutSplinePath
2203  << strCutSpline
2204  << strCutArc;
2205 
2206  const QDomNodeList list = elementsByTagName(strPoint);
2207  for (int i=0; i < list.size(); ++i)
2208  {
2209  QDomElement element = list.at(i).toElement();
2210  if (not element.isNull())
2211  {
2212  const QString type = element.attribute(strType);
2213  switch(types.indexOf(type))
2214  {
2215  case 0: //strCutSplinePath
2216  {
2217  const quint32 id = element.attribute(strId).toUInt();
2218  quint32 curve = element.attribute(strSplinePath).toUInt();
2219  FixSubPaths(i, id, curve);
2220  break;
2221  }
2222  case 1: //strCutSpline
2223  {
2224  const quint32 id = element.attribute(strId).toUInt();
2225  quint32 curve = element.attribute(strSpline).toUInt();
2226  FixSubPaths(i, id, curve);
2227  break;
2228  }
2229  case 2: //strCutArc
2230  {
2231  const quint32 id = element.attribute(strId).toUInt();
2232  quint32 curve = element.attribute(strArc).toUInt();
2233  FixSubPaths(i, id, curve);
2234  break;
2235  }
2236  default:
2237  break;
2238  }
2239  }
2240  }
2241 }
2242 
2243 //---------------------------------------------------------------------------------------------------------------------
2244 void VPatternConverter::FixSubPaths(int i, quint32 id, quint32 baseCurve)
2245 {
2246  const QStringList pointTypes = QStringList() << strCutSplinePath
2247  << strCutSpline
2252 
2253  const QDomNodeList listPoints = elementsByTagName(strPoint);
2254  for (int j = i+1; j < listPoints.size(); ++j)
2255  {
2256  QDomElement element = listPoints.at(j).toElement();
2257  if (not element.isNull())
2258  {
2259  const QString type = element.attribute(strType);
2260  switch(pointTypes.indexOf(type))
2261  {
2262  case 0: //strCutSplinePath
2263  {
2264  const quint32 spl = element.attribute(strSplinePath).toUInt();
2265  if (spl == id+1 || spl == id+2)
2266  {
2267  element.setAttribute(strSplinePath, baseCurve);
2268  }
2269  break;
2270  }
2271  case 1: //strCutSpline
2272  {
2273  const quint32 spl = element.attribute(strSpline).toUInt();
2274  if (spl == id+1 || spl == id+2)
2275  {
2276  element.setAttribute(strSpline, baseCurve);
2277  }
2278  break;
2279  }
2280  case 2: //strPointOfIntersectionCurves
2281  {
2282  quint32 spl = element.attribute(strCurve1).toUInt();
2283  if (spl == id+1 || spl == id+2)
2284  {
2285  element.setAttribute(strCurve1, baseCurve);
2286  }
2287 
2288  spl = element.attribute(strCurve2).toUInt();
2289  if (spl == id+1 || spl == id+2)
2290  {
2291  element.setAttribute(strCurve2, baseCurve);
2292  }
2293  break;
2294  }
2295  case 3: //strCurveIntersectAxis
2296  {
2297  const quint32 spl = element.attribute(strCurve).toUInt();
2298  if (spl == id+1 || spl == id+2)
2299  {
2300  element.setAttribute(strCurve, baseCurve);
2301  }
2302  break;
2303  }
2304  case 4: //strPointFromArcAndTangent
2305  {
2306  const quint32 spl = element.attribute(strArc).toUInt();
2307  if (spl == id+1 || spl == id+2)
2308  {
2309  element.setAttribute(strArc, baseCurve);
2310  }
2311  break;
2312  }
2313  case 5: //strPointOfIntersectionArcs
2314  {
2315  quint32 arc = element.attribute(strFirstArc).toUInt();
2316  if (arc == id+1 || arc == id+2)
2317  {
2318  element.setAttribute(strFirstArc, baseCurve);
2319  }
2320 
2321  arc = element.attribute(strSecondArc).toUInt();
2322  if (arc == id+1 || arc == id+2)
2323  {
2324  element.setAttribute(strSecondArc, baseCurve);
2325  }
2326  break;
2327  }
2328  default:
2329  break;
2330  }
2331  }
2332  }
2333 
2334  const QStringList splTypes = QStringList() << strModelingPath
2335  << strModelingSpline;
2336 
2337  const QDomNodeList listSplines = elementsByTagName(strSpline);
2338  for (int j = 0; j < listSplines.size(); ++j)
2339  {
2340  QDomElement element = listSplines.at(j).toElement();
2341  if (not element.isNull())
2342  {
2343  const QString type = element.attribute(strType);
2344  switch(splTypes.indexOf(type))
2345  {
2346  case 0: //strModelingPath
2347  case 1: //strModelingSpline
2348  {
2349  const quint32 spl = element.attribute(strIdObject).toUInt();
2350  if (spl == id+1 || spl == id+2)
2351  {
2352  element.setAttribute(strIdObject, baseCurve);
2353  }
2354  break;
2355  }
2356  default:
2357  break;
2358  }
2359  }
2360  }
2361 
2362  const QDomNodeList listArcs = elementsByTagName(strArc);
2363  for (int j = 0; j < listArcs.size(); ++j)
2364  {
2365  QDomElement element = listArcs.at(j).toElement();
2366  if (not element.isNull())
2367  {
2368  const QString type = element.attribute(strType);
2369  if (type == strModeling)
2370  {
2371  const quint32 arc = element.attribute(strIdObject).toUInt();
2372  if (arc == id+1 || arc == id+2)
2373  {
2374  element.setAttribute(strIdObject, baseCurve);
2375  }
2376  }
2377  }
2378  }
2379 }
2380 
2381 //---------------------------------------------------------------------------------------------------------------------
2383 {
2384  // TODO. Delete if minimal supported version is 0.4.0
2385  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
2386  "Time to refactor the code.");
2387 
2388  const QDomNodeList list = elementsByTagName(strModeling);
2389  for (int i = 0; i < list.size(); ++i)
2390  {
2391  QDomElement modeling = list.at(i).toElement();
2392  if (not modeling.isNull())
2393  {
2394  QDomNode domNode = modeling.firstChild();
2395  while (not domNode.isNull())
2396  {
2397  QDomElement domElement = domNode.toElement();
2398  if (not domElement.isNull())
2399  {
2400  if (domElement.hasAttribute(strTypeObject))
2401  {
2402  domElement.removeAttribute(strTypeObject);
2403  }
2404  }
2405  domNode = domNode.nextSibling();
2406  }
2407  }
2408  }
2409 }
2410 
2411 //---------------------------------------------------------------------------------------------------------------------
2413 {
2414  // TODO. Delete if minimal supported version is 0.4.0
2415  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
2416  "Time to refactor the code.");
2417 
2418  const QDomNodeList list = elementsByTagName(strDetail);
2419  for (int i=0; i < list.size(); ++i)
2420  {
2421  QDomElement dom = list.at(i).toElement();
2422 
2423  if (not dom.isNull())
2424  {
2425  dom.setAttribute(strSeamAllowance, dom.attribute(strSupplement, "0"));
2426  dom.removeAttribute(strSupplement);
2427 
2428  dom.setAttribute(strVersion, "1");
2429 
2430  const QStringList tags = QStringList() << strNode << strData << strPatternInfo << strGrainline;
2431 
2432  QDomElement tagData;
2433  QDomElement tagPatternInfo;
2434  QDomElement tagGrainline;
2435  QDomElement tagNodes = createElement(strNodes);
2436 
2437  const QDomNodeList childList = dom.childNodes();
2438  for (qint32 i = 0; i < childList.size(); ++i)
2439  {
2440  const QDomElement element = childList.at(i).toElement();
2441  if (not element.isNull())
2442  {
2443  switch (tags.indexOf(element.tagName()))
2444  {
2445  case 0://strNode
2446  {
2447  QDomElement tagNode = createElement(strNode);
2448 
2449  tagNode.setAttribute(strIdObject, element.attribute(strIdObject, NULL_ID_STR));
2450 
2451  if (element.hasAttribute(strReverse))
2452  {
2453  tagNode.setAttribute(strReverse, element.attribute(strReverse, "0"));
2454  }
2455 
2456  if (element.hasAttribute(strMx))
2457  {
2458  tagNode.setAttribute(strMx, element.attribute(strMx, "0"));
2459  }
2460 
2461  if (element.hasAttribute(strMy))
2462  {
2463  tagNode.setAttribute(strMy, element.attribute(strMy, "0"));
2464  }
2465 
2466  tagNode.setAttribute(strType, element.attribute(strType, ""));
2467 
2468  tagNodes.appendChild(tagNode);
2469 
2470  break;
2471  }
2472  case 1://strData
2473  tagData = element.cloneNode().toElement();
2474  break;
2475  case 2://strPatternInfo
2476  tagPatternInfo = element.cloneNode().toElement();
2477  break;
2478  case 3://strGrainline
2479  tagGrainline = element.cloneNode().toElement();
2480  break;
2481  default:
2482  break;
2483  }
2484  }
2485  }
2486 
2487  RemoveAllChildren(dom);
2488 
2489  dom.appendChild(tagData);
2490  dom.appendChild(tagPatternInfo);
2491  dom.appendChild(tagGrainline);
2492  dom.appendChild(tagNodes);
2493  }
2494  }
2495 }
2496 
2497 //---------------------------------------------------------------------------------------------------------------------
2498 QDomElement VPatternConverter::GetUnionDetailNodesV0_4_0(const QDomElement &piece)
2499 {
2500  QDomElement tagNodes = createElement(strNodes);
2501 
2502  if (not piece.isNull())
2503  {
2504  const QDomNodeList childList = piece.childNodes();
2505  for (qint32 i = 0; i < childList.size(); ++i)
2506  {
2507  const QDomElement node = childList.at(i).toElement();
2508  if (not node.isNull())
2509  {
2510  QDomElement tagNode = createElement(strNode);
2511 
2512  tagNode.setAttribute(strIdObject, node.attribute(strIdObject, NULL_ID_STR));
2513 
2514  if (node.hasAttribute(strReverse))
2515  {
2516  tagNode.setAttribute(strReverse, node.attribute(strReverse, "0"));
2517  }
2518 
2519  tagNode.setAttribute(strType, node.attribute(strType, ""));
2520 
2521  tagNodes.appendChild(tagNode);
2522  }
2523  }
2524  }
2525 
2526  return tagNodes;
2527 }
2528 
2529 //---------------------------------------------------------------------------------------------------------------------
2530 QDomElement VPatternConverter::GetUnionChildrenNodesV0_4_0(const QDomElement &piece)
2531 {
2532  QDomElement tagNodes = createElement(strNodes);
2533 
2534  if (not piece.isNull())
2535  {
2536  const QDomNodeList childList = piece.childNodes();
2537  for (qint32 i = 0; i < childList.size(); ++i)
2538  {
2539  const QDomElement node = childList.at(i).toElement();
2540  if (not node.isNull())
2541  {
2542  QDomElement tagNode = node.cloneNode().toElement();
2543  tagNodes.appendChild(tagNode);
2544  }
2545  }
2546  }
2547 
2548  return tagNodes;
2549 }
2550 
2551 //---------------------------------------------------------------------------------------------------------------------
2552 void VPatternConverter::LabelTagToV0_4_4(const QString &tagName)
2553 {
2554  // TODO. Delete if minimal supported version is 0.4.4
2555  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 4),
2556  "Time to refactor the code.");
2557 
2558  Unit unit = Unit::Cm;
2559  const QStringList units = QStringList() << "mm" << "cm" << "inch";
2560  switch (units.indexOf(UniqueTagText(strUnit)))
2561  {
2562  case 0:// mm
2563  unit = Unit::Mm;
2564  break;
2565  case 1:// cm
2566  unit = Unit::Cm;
2567  break;
2568  case 2:// in
2569  unit = Unit::Inch;
2570  break;
2571  default:
2572  break;
2573  }
2574 
2575  auto ConvertData = [unit](QDomElement &dom, const QString &attribute)
2576  {
2577  if (dom.hasAttribute(attribute))
2578  {
2579  QString valStr = dom.attribute(attribute, "1");
2580  bool ok = false;
2581  qreal val = valStr.toDouble(&ok);
2582  if (not ok)
2583  {
2584  val = 1;
2585  }
2586  dom.setAttribute(attribute, QString().setNum(FromPixel(val, unit)));
2587  }
2588  };
2589 
2590  const QDomNodeList list = elementsByTagName(tagName);
2591  for (int i=0; i < list.size(); ++i)
2592  {
2593  QDomElement dom = list.at(i).toElement();
2594 
2595  if (not dom.isNull())
2596  {
2597  ConvertData(dom, strWidth);
2598  ConvertData(dom, strHeight);
2599  }
2600  }
2601 }
2602 
2603 //---------------------------------------------------------------------------------------------------------------------
2605 {
2606  // TODO. Delete if minimal supported version is 0.6.0
2607  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 0),
2608  "Time to refactor the code.");
2609 
2610  const QDomNodeList list = elementsByTagName(strPatternLabel);
2611  if (list.isEmpty())
2612  {
2613  const QStringList tags = QStringList() << strUnit
2614  << strImage
2615  << strAuthor
2616  << strDescription
2617  << strNotes
2618  << strGradation
2619  << strPatternName
2620  << strPatternNum
2621  << strCompanyName
2622  << strCustomerName
2623  << strPatternLabel;
2624 
2625  QDomElement element = createElement(strPatternLabel);
2626  QDomElement pattern = documentElement();
2627  for (int i = tags.indexOf(element.tagName())-1; i >= 0; --i)
2628  {
2629  const QDomNodeList list = elementsByTagName(tags.at(i));
2630  if (not list.isEmpty())
2631  {
2632  pattern.insertAfter(element, list.at(0));
2633  break;
2634  }
2635  }
2636  return element;
2637  }
2638  return list.at(0).toElement();
2639 }
2640 
2641 //---------------------------------------------------------------------------------------------------------------------
2643 {
2644  // TODO. Delete if minimal supported version is 0.6.0
2645  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 0),
2646  "Time to refactor the code.");
2647 
2648  if (not UniqueTagText(strCompanyName).isEmpty())
2649  {
2650  AddLabelTemplateLineV0_6_0(label, "%author%", true, false, 0, 4);
2651  }
2652  else
2653  {
2654  const QString author = UniqueTagText(strAuthor);
2655  if (not author.isEmpty())
2656  {
2657  AddLabelTemplateLineV0_6_0(label, author, true, false, 0, 4);
2658  }
2659  }
2660 
2661  if (not UniqueTagText(strPatternName).isEmpty())
2662  {
2663  AddLabelTemplateLineV0_6_0(label, "%patternName%", false, false, 0, 2);
2664  }
2665 
2666  if (not UniqueTagText(strPatternNum).isEmpty())
2667  {
2668  AddLabelTemplateLineV0_6_0(label, "%patternNumber%", false, false, 0, 0);
2669  }
2670 
2671  if (not UniqueTagText(strCustomerName).isEmpty())
2672  {
2673  AddLabelTemplateLineV0_6_0(label, "%customer%", false, true, 0, 0);
2674  }
2675 
2676  const QString sizeField = UniqueTagText(strSize);
2677  if (not sizeField.isEmpty())
2678  {
2679  AddLabelTemplateLineV0_6_0(label, sizeField, false, false, 0, 0);
2680  }
2681 
2683  {
2684  AddLabelTemplateLineV0_6_0(label, "%mFileName%.%mExt%", false, false, 0, 0);
2685  }
2686 
2688  {
2689  AddLabelTemplateLineV0_6_0(label, "%date%", false, true, 0, 0);
2690  }
2691 }
2692 
2693 //---------------------------------------------------------------------------------------------------------------------
2694 void VPatternConverter::AddLabelTemplateLineV0_6_0(QDomElement &label, const QString &text, bool bold, bool italic,
2695  int alignment, int fontSizeIncrement)
2696 {
2697  // TODO. Delete if minimal supported version is 0.6.0
2698  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 0),
2699  "Time to refactor the code.");
2700 
2701  QDomElement tagLine = createElement(strLine);
2702 
2703  SetAttribute(tagLine, strText, text);
2704  SetAttribute(tagLine, strBold, bold);
2705  SetAttribute(tagLine, strItalic, italic);
2706  SetAttribute(tagLine, strAlignment, alignment);
2707  SetAttribute(tagLine, strFSIncrement, fontSizeIncrement);
2708 
2709  label.appendChild(tagLine);
2710 }
2711 
2712 //---------------------------------------------------------------------------------------------------------------------
2714 {
2715  // TODO. Delete if minimal supported version is 0.6.0
2716  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 0),
2717  "Time to refactor the code.");
2718 
2719  const QDomNodeList nodeList = elementsByTagName(strData);
2720  for (int i = 0; i < nodeList.size(); ++i)
2721  {
2722  QDomElement dataTag = nodeList.at(i).toElement();
2723  QDomNodeList nodeListMCP = dataTag.childNodes();
2724  const int count = nodeListMCP.count();
2725  try
2726  {
2727  if (not GetParametrString(dataTag, strLetter, "").isEmpty())
2728  {
2729  AddLabelTemplateLineV0_6_0(dataTag, "%pLetter%", true, false, Qt::AlignHCenter, 6);
2730  }
2731  }
2732  catch(const VExceptionEmptyParameter &)
2733  {}
2734 
2735  AddLabelTemplateLineV0_6_0(dataTag, "%pName%", true, false, Qt::AlignHCenter, 2);
2736 
2737  for (int iMCP = 0; iMCP < count; ++iMCP)
2738  {
2739  QDomElement domMCP = nodeListMCP.at(iMCP).toElement();
2740 
2741  QString line;
2742 
2743  const int material = static_cast<int>(GetParametrUInt(domMCP, strMaterial, "0"));
2744  switch(material)
2745  {
2746  case 0:
2747  line.append("%mFabric%");
2748  break;
2749  case 1:
2750  line.append("%mLining%");
2751  break;
2752  case 2:
2753  line.append("%mInterfacing%");
2754  break;
2755  case 3:
2756  line.append("%mInterlining%");
2757  break;
2758  case 4:
2759  default:
2760  line.append(GetParametrString(domMCP, strUserDefined, "User material"));
2761  break;
2762  }
2763 
2764  line.append(", %wCut% %pQuantity%");
2765  if (GetParametrUInt(domMCP, strPlacement, "0") == 1)
2766  {
2767  line.append(" %wOnFold%");
2768  }
2769 
2770  AddLabelTemplateLineV0_6_0(dataTag, line, false, false, Qt::AlignHCenter, 0);
2771  }
2772  }
2773 }
2774 
2775 //---------------------------------------------------------------------------------------------------------------------
2777 {
2778  // TODO. Delete if minimal supported version is 0.6.0
2779  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 0),
2780  "Time to refactor the code.");
2781 
2786 
2787  QDomNodeList nodeList = elementsByTagName(strData);
2788  for (int i = 0; i < nodeList.size(); ++i)
2789  {
2790  QDomElement child = nodeList.at(i).firstChildElement(strMCP);
2791  while (not child.isNull())
2792  {
2793  nodeList.at(i).removeChild(child);
2794  child = nodeList.at(i).firstChildElement(strMCP);
2795  }
2796  }
2797 }
2798 
2799 //---------------------------------------------------------------------------------------------------------------------
2801 {
2802  // TODO. Delete if minimal supported version is 0.6.0
2803  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 0),
2804  "Time to refactor the code.");
2805 
2806  const QDomNodeList nodeList = elementsByTagName(tag);
2807  if (nodeList.isEmpty())
2808  {
2809  return;
2810  }
2811 
2812  QDomElement pattern = documentElement();
2813  pattern.removeChild(nodeList.at(0));
2814 }
2815 
2816 //---------------------------------------------------------------------------------------------------------------------
2818 {
2819  // TODO. Delete if minimal supported version is 0.4.0
2820  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
2821  "Time to refactor the code.");
2822 
2823  const QDomNodeList list = elementsByTagName(strTools);
2824  for (int i=0; i < list.size(); ++i)
2825  {
2826  // Tag 'tools' used only for union pieces, so no need to check any additional attributes
2827  QDomElement toolDOM = list.at(i).toElement();
2828  if (not toolDOM.isNull())
2829  {
2830  const QStringList tags = QStringList() << strDet << strChildren;
2831 
2832  QVector<QDomElement> nodes;
2833  QDomElement tagChildrenNodes = createElement(strChildren);
2834 
2835  const QDomNodeList childList = toolDOM.childNodes();
2836  for (qint32 i = 0; i < childList.size(); ++i)
2837  {
2838  const QDomElement element = childList.at(i).toElement();
2839  if (not element.isNull())
2840  {
2841  switch (tags.indexOf(element.tagName()))
2842  {
2843  case 0://strDet
2844  nodes.append(GetUnionDetailNodesV0_4_0(element));
2845  break;
2846  case 1://strChildren
2847  tagChildrenNodes.appendChild(GetUnionChildrenNodesV0_4_0(element));
2848  break;
2849  default:
2850  break;
2851  }
2852  }
2853  }
2854 
2855  RemoveAllChildren(toolDOM);
2856 
2857  for (int i = 0; i < nodes.size(); ++i)
2858  {
2859  QDomElement tagDet = createElement(strDet);
2860  tagDet.appendChild(nodes.at(i));
2861  toolDOM.appendChild(tagDet);
2862  }
2863  toolDOM.appendChild(tagChildrenNodes);
2864  }
2865  }
2866 }
2867 
2868 void VPatternConverter::renameAttribute(QDomElement &element, const QString &oldName,
2869  const QString &newName, const QString &value) const
2870 {
2871  element.removeAttribute(oldName);
2872  element.setAttribute(newName, value);
2873 }
void SetVersion(const QString &version)
void Replace(QString &formula, const QString &newName, int position, const QString &token, int &bias) const
Q_NORETURN void InvalidVersion(int ver) const
void CorrectionsPositions(int position, int bias, QMap< int, QString > &tokens) const
QDomElement elementById(quint32 id, const QString &tagName=QString())
static QString GetParametrString(const QDomElement &domElement, const QString &name, const QString &defValue=QString())
Returns the string value of the given attribute. RENAME: see above.
static quint32 GetParametrUInt(const QDomElement &domElement, const QString &name, const QString &defValue)
Returns the long long value of the given attribute. RENAME: GetParameterLongLong?
static void ValidateXML(const QString &schema, const QString &fileName)
ValidateXML validate xml file by xsd schema.
static bool getParameterBool(const QDomElement &domElement, const QString &name, const QString &defValue)
QHash< quint32, QDomElement > map
Map used for finding element by id.
Definition: vdomdocument.h:170
QString UniqueTagText(const QString &tagName, const QString &defVal=QString()) const
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const
SetAttribute set attribute in pattern file. Replace "," by ".".
Definition: vdomdocument.h:185
static void RemoveAllChildren(QDomElement &domElement)
RemoveAllChildren remove all children from file.
The VExceptionEmptyParameter class for exception empty parameter.
virtual QString ErrorMessage() const Q_DECL_OVERRIDE
ErrorMessage return main error message.
The VException class parent for all exception. Could be use for abstract exception.
Definition: vexception.h:66
void AddMoreInformation(const QString &info)
AddMoreInformation add more information for error.
Definition: vexception.cpp:107
static const QString CurrentSchema
void ConvertArcExpressionsToV0_2_0(const QMap< QString, QString > &names)
void RemoveUniqueTagV0_6_0(const QString &tag)
QDomElement AddTagPatternLabelV0_5_1()
void TagRemoveAttributeTypeObjectInV0_4_0()
QDomElement GetUnionChildrenNodesV0_4_0(const QDomElement &detail)
QDomElement GetUnionDetailNodesV0_4_0(const QDomElement &detail)
void FixSubPaths(int i, quint32 id, quint32 baseCurve)
static const QString PatternMaxVerStr
void FixArcExpressionsToV0_2_0(const QSet< QString > &names)
void LabelTagToV0_4_4(const QString &tagName)
void ConvertPointExpressionsToV0_2_0(const QMap< QString, QString > &names)
void SaveChildrenToolUnionToV0_2_4(quint32 id, const QVector< quint32 > &children)
virtual void DowngradeToCurrentMaxVersion() Q_DECL_OVERRIDE
QString FixMeasurementInFormulaToV0_2_0(const QString &formula, const QMap< QString, QString > &names)
QDomElement TagMeasurementsV0_1_4() const
void PortPatternLabeltoV0_6_0(QDomElement &label)
QSet< QString > FixIncrementsToV0_2_0()
void renameAttribute(QDomElement &element, const QString &oldName, const QString &newName, const QString &value) const
static QMap< QString, QString > OldNamesToNewNames_InV0_2_0()
virtual void ApplyPatches() Q_DECL_OVERRIDE
QString MUnitV0_1_4() const
static QMap< QString, QString > OldNamesToNewNames_InV0_2_1()
void FixPathPointExpressionsToV0_2_0(const QSet< QString > &names)
virtual QString XSDSchema(int ver) const Q_DECL_OVERRIDE
static Q_DECL_CONSTEXPR const int PatternMinVer
static Q_DECL_CONSTEXPR const int PatternMaxVer
void FixPointExpressionsToV0_2_0(const QSet< QString > &names)
QString FixIncrementInFormulaToV0_2_0(const QString &formula, const QSet< QString > &names)
void AddLabelTemplateLineV0_6_0(QDomElement &label, const QString &text, bool bold, bool italic, int alignment, int fontSizeIncrement)
virtual bool IsReadOnly() const Q_DECL_OVERRIDE
void ParseModelingToV0_2_4(const QDomElement &modeling)
void ConvertPathPointExpressionsToV0_2_0(const QMap< QString, QString > &names)
QDomElement TagIncrementsV0_1_4() const
QMap< int, QString > GetTokens() const
double FromPixel(double pix, const Unit &unit)
Definition: def.cpp:250
const QString trueStr
Definition: def.cpp:197
const QString falseStr
Definition: def.cpp:198
#define V_FALLTHROUGH
Definition: def.h:351
Unit
Definition: def.h:105
#define NULL_ID_STR
Definition: ifcdef.h:77
#define CONVERTER_VERSION_CHECK(major, minor, patch)
static const QString strCutSpline
static const QString strPenStyle
static const QString strTopPin
static const QString strCurve2
static const QString strPointOfIntersectionArcs
static const QString strPoint
static const QString strArc
static const QString strPatternNum
static const QString strTwo
static const QString strElArc
static const QString strId
static const QString strMx
static const QString strChild
static const QString strAngle2
static const QString strLength
static const QString strItalic
static const QString strCompanyName
static const QString strIdTool
static const QString strSeamAllowance
static const QString strSize
static const QString strFirstArc
static const QString strData
static const QString strCurve
static const QString strAngle1
static const QString strTypeLine
static const QString strC2Radius
static const QString strPieces
static const QString strVersion
static const QString strLineType
static const QString strHeight
static const QString strDraw
static const QString strIncrement
static const QString strMCP
static const QString strCutArc
static const QString strOne
static const QString strPathPoint
static const QString strLineColor
static const QString strPassmarkAngle
static const QString strText
static const QString strPin
static const QString strPassmarkLine
static const QString strTypeObject
static const QString strForbidFlipping
static const QString strAngle
static const QString strNotchSubType
static const QString strThree
static const QString strNotchCount
static const QString strColor
static const QString strModelingSpline
static const QString strTrue
static const QString strUserDefined
static const QString strSpline
static const QString strReverse
static const QString strRadius
static const QString strCRadius
static const QString strMy
static const QString strKSize
static const QString strLetter
static const QString strBold
static const QString strNodes
static const QString strAlignment
static const QString strAuthor
static const QString strNode
static const QString strUnion
static const QString strDraftBlock
static const QString strPlacement
static const QString strSplinePath
static const QString strInLayout
static const QString strPassmark
static const QString strCurveIntersectAxis
static const QString strPatternLabel
static const QString strCutSplinePath
static const QString strVMark
static const QString strImage
static const QString strIdObject
static const QString strCenterPin
static const QString strShowNotch
static const QString strMeasurements
static const QString strFormula
static const QString strPiece
static const QString strTopLeftAnchor
static const QString strGradation
static const QString strPointFromArcAndTangent
static const QString strNotch
static const QString strNotchAngle
static const QString strSolidLine
static const QString strLine
static const QString strV_External
static const QString strNotes
static const QString strShowMeasurements
static const QString strShowSecondPassmark
static const QString strKGrowth
static const QString strPins
static const QString strShowDate
static const QString strPointOfIntersectionCurves
static const QString strType
static const QString strCustomerName
static const QString strModeling
static const QString strUnit
static const QString strSupplement
static const QString strLineWeight
static const QString strDetail
static const QString strTMark
static const QString strBottomRightAnchor
static const QString strDetails
static const QString strCenterAnchor
static const QString strMaterial
static const QString strDet
static const QString strKAsm1
static const QString strFSIncrement
static const QString strPatternName
static const QString strClosed
static const QString strTopAnchor
static const QString strWidth
static const QString strKAsm2
static const QString strCurve1
static const QString strSlitNotch
static const QString strBottomAnchor
static const QString strShowSecond
static const QString strChildren
static const QString strAnchor
static const QString strDescription
static const QString strName
static const QString strC1Radius
static const QString strBase
static const QString strReadOnly
static const QString strBottomPin
static const QString strNotchType
static const QString strPatternInfo
static const QString strIncrements
static const QString strHair
static const QString strAnchors
static const QString strPath
static const QString strBottomRightPin
static const QString strUnionDetail
static const QString strTools
static const QString strT_Notch
static const QString strModelingPath
static const QString strNodeType
static const QString strTopLeftPin
static const QString strGrainline
static const QString strSecondArc