2015-06-16 10:30:25 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vabstractpattern.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 15 6, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-06-16 10:30:25 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2015 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vabstractpattern.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QDomNode>
|
|
|
|
#include <QDomNodeList>
|
|
|
|
#include <QLatin1String>
|
|
|
|
#include <QList>
|
|
|
|
#include <QMessageLogger>
|
|
|
|
#include <QSet>
|
|
|
|
#include <QStaticStringData>
|
|
|
|
#include <QStringData>
|
|
|
|
#include <QStringDataPtr>
|
|
|
|
#include <QtDebug>
|
2018-01-24 12:16:29 +01:00
|
|
|
#include <QtConcurrentMap>
|
|
|
|
#include <QFuture>
|
|
|
|
#include <QtConcurrentRun>
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2016-08-05 12:41:02 +02:00
|
|
|
#include "../exception/vexceptionemptyparameter.h"
|
2016-04-06 11:03:34 +02:00
|
|
|
#include "../exception/vexceptionobjecterror.h"
|
2017-04-19 11:48:13 +02:00
|
|
|
#include "../exception/vexceptionconversionerror.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../qmuparser/qmutokenparser.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../ifc/exception/vexceptionbadid.h"
|
|
|
|
#include "../ifc/ifcdef.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2017-01-16 10:59:02 +01:00
|
|
|
#include "../vpatterndb/vpiecenode.h"
|
2016-04-06 11:03:34 +02:00
|
|
|
#include "../vtools/tools/vdatatool.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "vpatternconverter.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "vdomdocument.h"
|
|
|
|
#include "vtoolrecord.h"
|
2017-08-19 18:10:57 +02:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
class QDomElement;
|
2015-06-16 10:30:25 +02:00
|
|
|
|
2016-07-24 12:30:10 +02:00
|
|
|
const QString VAbstractPattern::TagPattern = QStringLiteral("pattern");
|
|
|
|
const QString VAbstractPattern::TagCalculation = QStringLiteral("calculation");
|
|
|
|
const QString VAbstractPattern::TagModeling = QStringLiteral("modeling");
|
|
|
|
const QString VAbstractPattern::TagDetails = QStringLiteral("details");
|
|
|
|
const QString VAbstractPattern::TagDetail = QStringLiteral("detail");
|
|
|
|
const QString VAbstractPattern::TagDescription = QStringLiteral("description");
|
|
|
|
const QString VAbstractPattern::TagNotes = QStringLiteral("notes");
|
|
|
|
const QString VAbstractPattern::TagImage = QStringLiteral("image");
|
|
|
|
const QString VAbstractPattern::TagMeasurements = QStringLiteral("measurements");
|
|
|
|
const QString VAbstractPattern::TagIncrements = QStringLiteral("increments");
|
2017-09-02 13:47:44 +02:00
|
|
|
const QString VAbstractPattern::TagPreviewCalculations = QStringLiteral("previewCalculations");
|
2016-07-24 12:30:10 +02:00
|
|
|
const QString VAbstractPattern::TagIncrement = QStringLiteral("increment");
|
|
|
|
const QString VAbstractPattern::TagDraw = QStringLiteral("draw");
|
|
|
|
const QString VAbstractPattern::TagGroups = QStringLiteral("groups");
|
|
|
|
const QString VAbstractPattern::TagGroup = QStringLiteral("group");
|
|
|
|
const QString VAbstractPattern::TagGroupItem = QStringLiteral("item");
|
|
|
|
const QString VAbstractPattern::TagPoint = QStringLiteral("point");
|
|
|
|
const QString VAbstractPattern::TagSpline = QStringLiteral("spline");
|
|
|
|
const QString VAbstractPattern::TagArc = QStringLiteral("arc");
|
2016-12-17 02:53:47 +01:00
|
|
|
const QString VAbstractPattern::TagElArc = QStringLiteral("elArc");
|
2016-07-24 12:30:10 +02:00
|
|
|
const QString VAbstractPattern::TagTools = QStringLiteral("tools");
|
|
|
|
const QString VAbstractPattern::TagOperation = QStringLiteral("operation");
|
|
|
|
const QString VAbstractPattern::TagGradation = QStringLiteral("gradation");
|
|
|
|
const QString VAbstractPattern::TagHeights = QStringLiteral("heights");
|
|
|
|
const QString VAbstractPattern::TagSizes = QStringLiteral("sizes");
|
|
|
|
const QString VAbstractPattern::TagData = QStringLiteral("data");
|
|
|
|
const QString VAbstractPattern::TagPatternInfo = QStringLiteral("patternInfo");
|
|
|
|
const QString VAbstractPattern::TagPatternName = QStringLiteral("patternName");
|
|
|
|
const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber");
|
|
|
|
const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer");
|
|
|
|
const QString VAbstractPattern::TagCompanyName = QStringLiteral("company");
|
2017-08-15 09:44:00 +02:00
|
|
|
const QString VAbstractPattern::TagPatternLabel = QStringLiteral("patternLabel");
|
2017-08-30 07:55:07 +02:00
|
|
|
const QString VAbstractPattern::TagPatternMaterials = QStringLiteral("patternMaterials");
|
2017-09-26 11:54:52 +02:00
|
|
|
const QString VAbstractPattern::TagFinalMeasurements= QStringLiteral("finalMeasurements");
|
2017-08-30 07:55:07 +02:00
|
|
|
const QString VAbstractPattern::TagMaterial = QStringLiteral("material");
|
2017-09-26 11:54:52 +02:00
|
|
|
const QString VAbstractPattern::TagFMeasurement = QStringLiteral("finalMeasurment");
|
2016-09-06 23:50:46 +02:00
|
|
|
const QString VAbstractPattern::TagGrainline = QStringLiteral("grainline");
|
2016-11-24 20:35:07 +01:00
|
|
|
const QString VAbstractPattern::TagPath = QStringLiteral("path");
|
|
|
|
const QString VAbstractPattern::TagNodes = QStringLiteral("nodes");
|
|
|
|
const QString VAbstractPattern::TagNode = QStringLiteral("node");
|
2016-07-24 12:30:10 +02:00
|
|
|
|
2017-03-24 13:48:07 +01:00
|
|
|
const QString VAbstractPattern::AttrName = QStringLiteral("name");
|
|
|
|
const QString VAbstractPattern::AttrVisible = QStringLiteral("visible");
|
|
|
|
const QString VAbstractPattern::AttrObject = QStringLiteral("object");
|
|
|
|
const QString VAbstractPattern::AttrTool = QStringLiteral("tool");
|
|
|
|
const QString VAbstractPattern::AttrType = QStringLiteral("type");
|
|
|
|
const QString VAbstractPattern::AttrLetter = QStringLiteral("letter");
|
2017-08-21 12:16:43 +02:00
|
|
|
const QString VAbstractPattern::AttrAnnotation = QStringLiteral("annotation");
|
|
|
|
const QString VAbstractPattern::AttrOrientation = QStringLiteral("orientation");
|
2017-08-21 16:10:55 +02:00
|
|
|
const QString VAbstractPattern::AttrRotationWay = QStringLiteral("rotationWay");
|
2017-08-21 12:16:43 +02:00
|
|
|
const QString VAbstractPattern::AttrTilt = QStringLiteral("tilt");
|
|
|
|
const QString VAbstractPattern::AttrFoldPosition = QStringLiteral("foldPosition");
|
2017-08-18 06:59:47 +02:00
|
|
|
const QString VAbstractPattern::AttrQuantity = QStringLiteral("quantity");
|
|
|
|
const QString VAbstractPattern::AttrOnFold = QStringLiteral("onFold");
|
2017-08-19 18:10:57 +02:00
|
|
|
const QString VAbstractPattern::AttrDateFormat = QStringLiteral("dateFormat");
|
|
|
|
const QString VAbstractPattern::AttrTimeFormat = QStringLiteral("timeFormat");
|
2017-03-24 13:48:07 +01:00
|
|
|
const QString VAbstractPattern::AttrArrows = QStringLiteral("arrows");
|
|
|
|
const QString VAbstractPattern::AttrNodeReverse = QStringLiteral("reverse");
|
|
|
|
const QString VAbstractPattern::AttrNodeExcluded = QStringLiteral("excluded");
|
|
|
|
const QString VAbstractPattern::AttrNodePassmark = QStringLiteral("passmark");
|
|
|
|
const QString VAbstractPattern::AttrNodePassmarkLine = QStringLiteral("passmarkLine");
|
|
|
|
const QString VAbstractPattern::AttrNodePassmarkAngle = QStringLiteral("passmarkAngle");
|
2017-04-26 10:22:42 +02:00
|
|
|
const QString VAbstractPattern::AttrNodeShowSecondPassmark = QStringLiteral("showSecondPassmark");
|
2017-03-24 13:48:07 +01:00
|
|
|
const QString VAbstractPattern::AttrSABefore = QStringLiteral("before");
|
|
|
|
const QString VAbstractPattern::AttrSAAfter = QStringLiteral("after");
|
|
|
|
const QString VAbstractPattern::AttrStart = QStringLiteral("start");
|
|
|
|
const QString VAbstractPattern::AttrPath = QStringLiteral("path");
|
|
|
|
const QString VAbstractPattern::AttrEnd = QStringLiteral("end");
|
|
|
|
const QString VAbstractPattern::AttrIncludeAs = QStringLiteral("includeAs");
|
2017-08-21 16:10:55 +02:00
|
|
|
const QString VAbstractPattern::AttrRotation = QStringLiteral("rotation");
|
2017-08-30 07:55:07 +02:00
|
|
|
const QString VAbstractPattern::AttrNumber = QStringLiteral("number");
|
2018-03-05 11:05:59 +01:00
|
|
|
const QString VAbstractPattern::AttrCheckUniqueness = QStringLiteral("checkUniqueness");
|
2019-04-17 12:02:22 +02:00
|
|
|
const QString VAbstractPattern::AttrManualPassmarkLength = QStringLiteral("manualPassmarkLength");
|
|
|
|
const QString VAbstractPattern::AttrPassmarkLength = QStringLiteral("passmarkLength");
|
2016-07-24 12:30:10 +02:00
|
|
|
|
|
|
|
const QString VAbstractPattern::AttrAll = QStringLiteral("all");
|
|
|
|
|
2016-10-26 13:49:09 +02:00
|
|
|
const QString VAbstractPattern::AttrH50 = QStringLiteral("h50");
|
|
|
|
const QString VAbstractPattern::AttrH56 = QStringLiteral("h56");
|
|
|
|
const QString VAbstractPattern::AttrH62 = QStringLiteral("h62");
|
|
|
|
const QString VAbstractPattern::AttrH68 = QStringLiteral("h68");
|
|
|
|
const QString VAbstractPattern::AttrH74 = QStringLiteral("h74");
|
|
|
|
const QString VAbstractPattern::AttrH80 = QStringLiteral("h80");
|
|
|
|
const QString VAbstractPattern::AttrH86 = QStringLiteral("h86");
|
2016-07-24 12:30:10 +02:00
|
|
|
const QString VAbstractPattern::AttrH92 = QStringLiteral("h92");
|
|
|
|
const QString VAbstractPattern::AttrH98 = QStringLiteral("h98");
|
|
|
|
const QString VAbstractPattern::AttrH104 = QStringLiteral("h104");
|
|
|
|
const QString VAbstractPattern::AttrH110 = QStringLiteral("h110");
|
|
|
|
const QString VAbstractPattern::AttrH116 = QStringLiteral("h116");
|
|
|
|
const QString VAbstractPattern::AttrH122 = QStringLiteral("h122");
|
|
|
|
const QString VAbstractPattern::AttrH128 = QStringLiteral("h128");
|
|
|
|
const QString VAbstractPattern::AttrH134 = QStringLiteral("h134");
|
|
|
|
const QString VAbstractPattern::AttrH140 = QStringLiteral("h140");
|
|
|
|
const QString VAbstractPattern::AttrH146 = QStringLiteral("h146");
|
|
|
|
const QString VAbstractPattern::AttrH152 = QStringLiteral("h152");
|
|
|
|
const QString VAbstractPattern::AttrH158 = QStringLiteral("h158");
|
|
|
|
const QString VAbstractPattern::AttrH164 = QStringLiteral("h164");
|
|
|
|
const QString VAbstractPattern::AttrH170 = QStringLiteral("h170");
|
|
|
|
const QString VAbstractPattern::AttrH176 = QStringLiteral("h176");
|
|
|
|
const QString VAbstractPattern::AttrH182 = QStringLiteral("h182");
|
|
|
|
const QString VAbstractPattern::AttrH188 = QStringLiteral("h188");
|
|
|
|
const QString VAbstractPattern::AttrH194 = QStringLiteral("h194");
|
2017-03-09 21:41:48 +01:00
|
|
|
const QString VAbstractPattern::AttrH200 = QStringLiteral("h200");
|
2016-07-24 12:30:10 +02:00
|
|
|
|
|
|
|
const QString VAbstractPattern::AttrS22 = QStringLiteral("s22");
|
|
|
|
const QString VAbstractPattern::AttrS24 = QStringLiteral("s24");
|
|
|
|
const QString VAbstractPattern::AttrS26 = QStringLiteral("s26");
|
|
|
|
const QString VAbstractPattern::AttrS28 = QStringLiteral("s28");
|
|
|
|
const QString VAbstractPattern::AttrS30 = QStringLiteral("s30");
|
|
|
|
const QString VAbstractPattern::AttrS32 = QStringLiteral("s32");
|
|
|
|
const QString VAbstractPattern::AttrS34 = QStringLiteral("s34");
|
|
|
|
const QString VAbstractPattern::AttrS36 = QStringLiteral("s36");
|
|
|
|
const QString VAbstractPattern::AttrS38 = QStringLiteral("s38");
|
|
|
|
const QString VAbstractPattern::AttrS40 = QStringLiteral("s40");
|
|
|
|
const QString VAbstractPattern::AttrS42 = QStringLiteral("s42");
|
|
|
|
const QString VAbstractPattern::AttrS44 = QStringLiteral("s44");
|
|
|
|
const QString VAbstractPattern::AttrS46 = QStringLiteral("s46");
|
|
|
|
const QString VAbstractPattern::AttrS48 = QStringLiteral("s48");
|
|
|
|
const QString VAbstractPattern::AttrS50 = QStringLiteral("s50");
|
|
|
|
const QString VAbstractPattern::AttrS52 = QStringLiteral("s52");
|
|
|
|
const QString VAbstractPattern::AttrS54 = QStringLiteral("s54");
|
|
|
|
const QString VAbstractPattern::AttrS56 = QStringLiteral("s56");
|
2017-02-22 06:54:42 +01:00
|
|
|
const QString VAbstractPattern::AttrS58 = QStringLiteral("s58");
|
|
|
|
const QString VAbstractPattern::AttrS60 = QStringLiteral("s60");
|
|
|
|
const QString VAbstractPattern::AttrS62 = QStringLiteral("s62");
|
|
|
|
const QString VAbstractPattern::AttrS64 = QStringLiteral("s64");
|
|
|
|
const QString VAbstractPattern::AttrS66 = QStringLiteral("s66");
|
|
|
|
const QString VAbstractPattern::AttrS68 = QStringLiteral("s68");
|
|
|
|
const QString VAbstractPattern::AttrS70 = QStringLiteral("s70");
|
|
|
|
const QString VAbstractPattern::AttrS72 = QStringLiteral("s72");
|
2016-07-24 12:30:10 +02:00
|
|
|
|
|
|
|
const QString VAbstractPattern::AttrCustom = QStringLiteral("custom");
|
|
|
|
const QString VAbstractPattern::AttrDefHeight = QStringLiteral("defHeight");
|
|
|
|
const QString VAbstractPattern::AttrDefSize = QStringLiteral("defSize");
|
|
|
|
const QString VAbstractPattern::AttrExtension = QStringLiteral("extension");
|
2015-12-11 15:19:11 +01:00
|
|
|
|
2017-09-26 11:54:52 +02:00
|
|
|
const QString VAbstractPattern::AttrFormula = QStringLiteral("formula");
|
|
|
|
const QString VAbstractPattern::AttrDescription = QStringLiteral("description");
|
2015-06-16 10:30:25 +02:00
|
|
|
|
2016-11-24 20:35:07 +01:00
|
|
|
const QString VAbstractPattern::NodeArc = QStringLiteral("NodeArc");
|
2016-12-20 16:42:51 +01:00
|
|
|
const QString VAbstractPattern::NodeElArc = QStringLiteral("NodeElArc");
|
2016-11-24 20:35:07 +01:00
|
|
|
const QString VAbstractPattern::NodePoint = QStringLiteral("NodePoint");
|
|
|
|
const QString VAbstractPattern::NodeSpline = QStringLiteral("NodeSpline");
|
|
|
|
const QString VAbstractPattern::NodeSplinePath = QStringLiteral("NodeSplinePath");
|
|
|
|
|
2016-12-03 17:44:24 +01:00
|
|
|
QHash<quint32, VDataTool*> VAbstractPattern::tools = QHash<quint32, VDataTool*>();
|
2017-08-15 10:38:36 +02:00
|
|
|
QVector<VLabelTemplateLine> VAbstractPattern::patternLabelLines = QVector<VLabelTemplateLine>();
|
2017-08-30 07:55:07 +02:00
|
|
|
QMap<int, QString> VAbstractPattern::patternMaterials = QMap<int, QString>();
|
2017-08-15 14:22:33 +02:00
|
|
|
bool VAbstractPattern::patternLabelWasChanged = false;
|
2016-12-03 17:44:24 +01:00
|
|
|
|
2017-08-08 16:43:41 +02:00
|
|
|
namespace
|
|
|
|
{
|
2018-11-18 08:52:08 +01:00
|
|
|
// Need to be reinited in setXMLContent as well
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(QString, patternNumberCached, (unknownCharacter))
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(QString, labelDateFormatCached, (unknownCharacter))
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(QString, patternNameCached, (unknownCharacter))
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(QString, MPathCached, (unknownCharacter))
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(QString, companyNameCached, (unknownCharacter))
|
|
|
|
|
2017-08-08 16:43:41 +02:00
|
|
|
void ReadExpressionAttribute(QVector<VFormulaField> &expressions, const QDomElement &element, const QString &attribute)
|
|
|
|
{
|
|
|
|
VFormulaField formula;
|
2018-01-20 11:31:12 +01:00
|
|
|
formula.expression = VDomDocument::GetParametrEmptyString(element, attribute);
|
|
|
|
|
|
|
|
if (formula.expression.isEmpty())
|
2017-08-08 16:43:41 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
formula.element = element;
|
|
|
|
formula.attribute = attribute;
|
|
|
|
|
|
|
|
expressions.append(formula);
|
|
|
|
}
|
2018-01-24 12:16:29 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QList<QString> GetTokens(const VFormulaField &formula)
|
|
|
|
{
|
2019-02-07 14:42:17 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
QScopedPointer<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(formula.expression, false, false));
|
|
|
|
return cal->GetTokens().values();
|
|
|
|
}
|
|
|
|
catch (const qmu::QmuParserError &e)
|
|
|
|
{
|
|
|
|
qWarning() << QObject::tr("Cannot get tokens from formula '%1'. Parser error: %2.")
|
|
|
|
.arg(formula.expression, e.GetMsg());
|
|
|
|
return QList<QString>();
|
|
|
|
}
|
2018-01-24 12:16:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void GatherTokens(QSet<QString> &tokens, const QList<QString> &tokenList)
|
|
|
|
{
|
|
|
|
tokens = tokens.unite(tokenList.toSet());
|
|
|
|
}
|
2018-07-18 19:18:30 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief AdjustMaterials help function that combine user materials from pattern and cli.
|
|
|
|
* @param materials materials from pattern
|
|
|
|
* @return combined list
|
|
|
|
*/
|
|
|
|
QMap<int, QString> AdjustMaterials(QMap<int, QString> materials)
|
|
|
|
{
|
|
|
|
const QMap<int, QString> cliMaterials = qApp->GetUserMaterials();
|
|
|
|
QMap<int, QString>::const_iterator i = cliMaterials.constBegin();
|
|
|
|
while (i != cliMaterials.constEnd())
|
|
|
|
{
|
|
|
|
if (not materials.contains(i.key()))
|
|
|
|
{
|
|
|
|
qWarning() << QObject::tr("User material number %1 was not defined in this pattern.").arg(i.key());
|
|
|
|
}
|
|
|
|
|
|
|
|
materials.insert(i.key(), i.value());
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return materials;
|
|
|
|
}
|
2017-08-08 16:43:41 +02:00
|
|
|
}
|
|
|
|
|
2015-06-16 10:30:25 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VAbstractPattern::VAbstractPattern(QObject *parent)
|
2018-01-26 13:43:52 +01:00
|
|
|
: VDomDocument(parent),
|
|
|
|
nameActivPP(),
|
2016-12-03 17:44:24 +01:00
|
|
|
cursor(0),
|
|
|
|
toolsOnRemove(QVector<VDataTool*>()),
|
|
|
|
history(QVector<VToolRecord>()),
|
2018-01-26 13:43:52 +01:00
|
|
|
patternPieces(),
|
2016-02-10 17:45:49 +01:00
|
|
|
modified(false)
|
2015-06-16 10:30:25 +02:00
|
|
|
{}
|
|
|
|
|
2018-05-10 12:46:50 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VAbstractPattern::~VAbstractPattern()
|
|
|
|
{
|
|
|
|
qDeleteAll(toolsOnRemove);
|
|
|
|
toolsOnRemove.clear();
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:41:03 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VAbstractPattern::ListMeasurements() const
|
|
|
|
{
|
2018-01-24 12:16:29 +01:00
|
|
|
const QFuture<QStringList> futureIncrements = QtConcurrent::run(this, &VAbstractPattern::ListIncrements);
|
2015-08-11 15:41:03 +02:00
|
|
|
|
2018-01-24 12:16:29 +01:00
|
|
|
const QList<QString> tokens = QtConcurrent::blockingMappedReduced(ListExpressions(), GetTokens,
|
|
|
|
GatherTokens).toList();
|
2015-08-11 15:41:03 +02:00
|
|
|
|
2018-01-24 12:16:29 +01:00
|
|
|
QSet<QString> measurements;
|
|
|
|
QSet<QString> others = futureIncrements.result().toSet();
|
2015-08-11 15:41:03 +02:00
|
|
|
|
2018-04-03 10:15:58 +02:00
|
|
|
for (const auto &token : tokens)
|
2018-01-24 12:16:29 +01:00
|
|
|
{
|
|
|
|
if (token == QChar('-') || measurements.contains(token) || others.contains(token))
|
2015-08-11 15:41:03 +02:00
|
|
|
{
|
2018-01-24 12:16:29 +01:00
|
|
|
continue;
|
2015-08-11 15:41:03 +02:00
|
|
|
}
|
2018-01-24 12:16:29 +01:00
|
|
|
|
|
|
|
IsVariable(token) || IsFunction(token) ? others.insert(token) : measurements.insert(token);
|
2015-08-11 15:41:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return QStringList(measurements.toList());
|
|
|
|
}
|
|
|
|
|
2015-06-16 10:30:25 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief ChangeActivPP set new active pattern piece name.
|
|
|
|
* @param name new name.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
*/
|
|
|
|
void VAbstractPattern::ChangeActivPP(const QString &name, const Document &parse)
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT_X(not name.isEmpty(), Q_FUNC_INFO, "name pattern piece is empty");
|
2015-06-16 10:30:25 +02:00
|
|
|
if (CheckExistNamePP(name) && this->nameActivPP != name)
|
|
|
|
{
|
|
|
|
this->nameActivPP = name;
|
|
|
|
if (parse == Document::FullParse)
|
|
|
|
{
|
|
|
|
emit ChangedActivPP(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief GetActivDrawElement return draw tag for current pattern peace.
|
|
|
|
* @param element draw tag.
|
|
|
|
* @return true if found.
|
|
|
|
*/
|
|
|
|
bool VAbstractPattern::GetActivDrawElement(QDomElement &element) const
|
|
|
|
{
|
|
|
|
if (nameActivPP.isEmpty() == false)
|
|
|
|
{
|
|
|
|
const QDomNodeList elements = this->documentElement().elementsByTagName( TagDraw );
|
|
|
|
if (elements.size() == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for ( qint32 i = 0; i < elements.count(); i++ )
|
|
|
|
{
|
|
|
|
element = elements.at( i ).toElement();
|
|
|
|
if (element.isNull() == false)
|
|
|
|
{
|
|
|
|
const QString fieldName = element.attribute( AttrName );
|
|
|
|
if ( fieldName == nameActivPP )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
element = QDomElement();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-25 15:36:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<VToolRecord> VAbstractPattern::getLocalHistory(const QString &draw) const
|
|
|
|
{
|
|
|
|
QVector<VToolRecord> historyPP;
|
|
|
|
for (qint32 i = 0; i< history.size(); ++i)
|
|
|
|
{
|
|
|
|
const VToolRecord &tool = history.at(i);
|
|
|
|
if (tool.getNameDraw() == draw)
|
|
|
|
{
|
|
|
|
historyPP.append(tool);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return historyPP;
|
|
|
|
}
|
|
|
|
|
2015-06-16 10:30:25 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief CheckNameDraw check if exist pattern peace with this name.
|
|
|
|
* @param name pattern peace name.
|
|
|
|
* @return true if exist.
|
|
|
|
*/
|
|
|
|
bool VAbstractPattern::CheckExistNamePP(const QString &name) const
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT_X(not name.isEmpty(), Q_FUNC_INFO, "name draw is empty");
|
2015-06-16 10:30:25 +02:00
|
|
|
const QDomNodeList elements = this->documentElement().elementsByTagName( TagDraw );
|
|
|
|
if (elements.size() == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for ( qint32 i = 0; i < elements.count(); i++ )
|
|
|
|
{
|
|
|
|
const QDomElement elem = elements.at( i ).toElement();
|
|
|
|
if (elem.isNull() == false)
|
|
|
|
{
|
|
|
|
if ( GetParametrString(elem, AttrName) == name )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief GetActivNodeElement find element in current pattern piece by name.
|
|
|
|
* @param name name tag.
|
|
|
|
* @param element element.
|
|
|
|
* @return true if found.
|
|
|
|
*/
|
|
|
|
bool VAbstractPattern::GetActivNodeElement(const QString &name, QDomElement &element) const
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT_X(not name.isEmpty(), Q_FUNC_INFO, "name draw is empty");
|
2015-06-16 10:30:25 +02:00
|
|
|
QDomElement drawElement;
|
|
|
|
if (GetActivDrawElement(drawElement))
|
|
|
|
{
|
|
|
|
const QDomNodeList listElement = drawElement.elementsByTagName(name);
|
|
|
|
if (listElement.size() != 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
element = listElement.at( 0 ).toElement();
|
|
|
|
if (element.isNull() == false)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-06 11:03:34 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::ParseGroups(const QDomElement &domElement)
|
|
|
|
{
|
|
|
|
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");
|
|
|
|
|
|
|
|
QMap<quint32, quint32> itemTool;
|
|
|
|
QMap<quint32, bool> itemVisibility;
|
|
|
|
|
|
|
|
QDomNode domNode = domElement.firstChild();
|
|
|
|
while (domNode.isNull() == false)
|
|
|
|
{
|
|
|
|
if (domNode.isElement())
|
|
|
|
{
|
|
|
|
const QDomElement domElement = domNode.toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
|
|
|
if (domElement.tagName() == TagGroup)
|
|
|
|
{
|
2018-09-18 15:38:16 +02:00
|
|
|
VContainer::UpdateId(GetParametrUInt(domElement, AttrId, NULL_ID_STR), valentinaNamespace);
|
2016-06-26 14:41:48 +02:00
|
|
|
|
2016-04-06 11:03:34 +02:00
|
|
|
const QPair<bool, QMap<quint32, quint32> > groupData = ParseItemElement(domElement);
|
|
|
|
const QMap<quint32, quint32> group = groupData.second;
|
|
|
|
auto i = group.constBegin();
|
|
|
|
while (i != group.constEnd())
|
|
|
|
{
|
|
|
|
if (not itemTool.contains(i.key()))
|
|
|
|
{
|
|
|
|
itemTool.insert(i.key(), i.value());
|
|
|
|
}
|
|
|
|
|
2016-04-07 16:57:53 +02:00
|
|
|
const bool previous = itemVisibility.value(i.key(), false);
|
2016-04-06 11:03:34 +02:00
|
|
|
itemVisibility.insert(i.key(), previous || groupData.first);
|
2016-04-07 16:57:53 +02:00
|
|
|
++i;
|
2016-04-06 11:03:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
domNode = domNode.nextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto i = itemTool.constBegin();
|
|
|
|
while (i != itemTool.constEnd())
|
|
|
|
{
|
|
|
|
if (tools.contains(i.value()))
|
|
|
|
{
|
|
|
|
VDataTool* tool = tools.value(i.value());
|
|
|
|
tool->GroupVisibility(i.key(), itemVisibility.value(i.key(), true));
|
|
|
|
}
|
2016-04-07 16:57:53 +02:00
|
|
|
++i;
|
2016-04-06 11:03:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-16 10:30:25 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VAbstractPattern::CountPP() const
|
|
|
|
{
|
|
|
|
const QDomElement rootElement = this->documentElement();
|
|
|
|
if (rootElement.isNull())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rootElement.elementsByTagName( TagDraw ).count();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDomElement VAbstractPattern::GetPPElement(const QString &name)
|
|
|
|
{
|
|
|
|
if (name.isEmpty() == false)
|
|
|
|
{
|
|
|
|
const QDomNodeList elements = this->documentElement().elementsByTagName( TagDraw );
|
|
|
|
if (elements.size() == 0)
|
|
|
|
{
|
|
|
|
return QDomElement();
|
|
|
|
}
|
|
|
|
for ( qint32 i = 0; i < elements.count(); i++ )
|
|
|
|
{
|
|
|
|
QDomElement element = elements.at( i ).toElement();
|
|
|
|
if (element.isNull() == false)
|
|
|
|
{
|
|
|
|
if ( element.attribute( AttrName ) == name )
|
|
|
|
{
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QDomElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief ChangeNamePP change pattern piece name.
|
|
|
|
* @param oldName old pattern piece name.
|
|
|
|
* @param newName new pattern piece name.
|
|
|
|
* @return true if success.
|
|
|
|
*/
|
|
|
|
bool VAbstractPattern::ChangeNamePP(const QString &oldName, const QString &newName)
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT_X(not newName.isEmpty(), Q_FUNC_INFO, "new name pattern piece is empty");
|
|
|
|
Q_ASSERT_X(not oldName.isEmpty(), Q_FUNC_INFO, "old name pattern piece is empty");
|
2015-06-16 10:30:25 +02:00
|
|
|
|
|
|
|
if (CheckExistNamePP(oldName) == false)
|
|
|
|
{
|
|
|
|
qDebug()<<"Do not exist pattern piece with name"<<oldName;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CheckExistNamePP(newName))
|
|
|
|
{
|
|
|
|
qDebug()<<"Already exist pattern piece with name"<<newName;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDomElement ppElement = GetPPElement(oldName);
|
|
|
|
if (ppElement.isElement())
|
|
|
|
{
|
|
|
|
if (nameActivPP == oldName)
|
|
|
|
{
|
|
|
|
nameActivPP = newName;
|
|
|
|
}
|
|
|
|
ppElement.setAttribute(AttrName, newName);
|
|
|
|
emit patternChanged(false);//For situation when we change name directly, without undocommands.
|
|
|
|
emit ChangedNameDraw(oldName, newName);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug()<<"Can't find pattern piece node with name"<<oldName<<Q_FUNC_INFO;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief appendPP add new pattern piece.
|
|
|
|
*
|
|
|
|
* Method check if not exist pattern piece with the same name and change name active pattern piece name, send signal
|
|
|
|
* about change pattern piece. Doen't add pattern piece to file structure. This task make SPoint tool.
|
|
|
|
* @param name pattern peace name.
|
|
|
|
* @return true if success.
|
|
|
|
*/
|
|
|
|
bool VAbstractPattern::appendPP(const QString &name)
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT_X(not name.isEmpty(), Q_FUNC_INFO, "name pattern piece is empty");
|
2015-06-16 10:30:25 +02:00
|
|
|
if (name.isEmpty())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (CheckExistNamePP(name) == false)
|
|
|
|
{
|
|
|
|
SetActivPP(name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 VAbstractPattern::getCursor() const
|
|
|
|
{
|
|
|
|
return cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::setCursor(const quint32 &value)
|
|
|
|
{
|
|
|
|
if (cursor != value)
|
|
|
|
{
|
|
|
|
cursor = value;
|
|
|
|
emit ChangedCursor(cursor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-18 08:52:08 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::setXMLContent(const QString &fileName)
|
|
|
|
{
|
|
|
|
VDomDocument::setXMLContent(fileName);
|
|
|
|
|
|
|
|
*patternNumberCached = unknownCharacter;
|
|
|
|
*labelDateFormatCached = unknownCharacter;
|
|
|
|
*patternNameCached = unknownCharacter;
|
|
|
|
*MPathCached = unknownCharacter;
|
|
|
|
*companyNameCached = unknownCharacter;
|
|
|
|
}
|
|
|
|
|
2015-06-16 10:30:25 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief getTool return tool from tool list.
|
|
|
|
* @param id tool id.
|
|
|
|
* @return tool.
|
|
|
|
*/
|
2017-01-18 11:22:02 +01:00
|
|
|
VDataTool *VAbstractPattern::getTool(quint32 id)
|
2015-06-16 10:30:25 +02:00
|
|
|
{
|
|
|
|
ToolExists(id);
|
|
|
|
return tools.value(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief AddTool add tool to list tools.
|
|
|
|
* @param id tool id.
|
|
|
|
* @param tool tool.
|
|
|
|
*/
|
2017-01-18 11:22:02 +01:00
|
|
|
void VAbstractPattern::AddTool(quint32 id, VDataTool *tool)
|
2015-06-16 10:30:25 +02:00
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT_X(id != 0, Q_FUNC_INFO, "id == 0");
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(tool != nullptr)
|
2017-01-16 10:59:02 +01:00
|
|
|
tools.insert(id, tool);
|
|
|
|
}
|
|
|
|
|
2017-01-18 11:22:02 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::RemoveTool(quint32 id)
|
|
|
|
{
|
|
|
|
tools.remove(id);
|
|
|
|
}
|
|
|
|
|
2017-01-16 10:59:02 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPiecePath VAbstractPattern::ParsePieceNodes(const QDomElement &domElement)
|
|
|
|
{
|
|
|
|
VPiecePath path;
|
|
|
|
const QDomNodeList nodeList = domElement.childNodes();
|
|
|
|
for (qint32 i = 0; i < nodeList.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement element = nodeList.at(i).toElement();
|
|
|
|
if (not element.isNull())
|
|
|
|
{
|
|
|
|
path.Append(ParseSANode(element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<CustomSARecord> VAbstractPattern::ParsePieceCSARecords(const QDomElement &domElement)
|
|
|
|
{
|
|
|
|
QVector<CustomSARecord> records;
|
|
|
|
const QDomNodeList nodeList = domElement.childNodes();
|
|
|
|
for (qint32 i = 0; i < nodeList.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement element = nodeList.at(i).toElement();
|
|
|
|
if (not element.isNull())
|
|
|
|
{
|
|
|
|
CustomSARecord record;
|
|
|
|
record.startPoint = GetParametrUInt(element, VAbstractPattern::AttrStart, NULL_ID_STR);
|
|
|
|
record.path = GetParametrUInt(element, VAbstractPattern::AttrPath, NULL_ID_STR);
|
|
|
|
record.endPoint = GetParametrUInt(element, VAbstractPattern::AttrEnd, NULL_ID_STR);
|
|
|
|
record.reverse = GetParametrBool(element, VAbstractPattern::AttrNodeReverse, falseStr);
|
|
|
|
record.includeType = static_cast<PiecePathIncludeType>(GetParametrUInt(element,
|
|
|
|
VAbstractPattern::AttrIncludeAs,
|
2018-04-12 12:13:19 +02:00
|
|
|
QChar('1')));
|
2017-01-16 16:37:15 +01:00
|
|
|
records.append(record);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return records;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<quint32> VAbstractPattern::ParsePieceInternalPaths(const QDomElement &domElement)
|
|
|
|
{
|
|
|
|
QVector<quint32> records;
|
|
|
|
const QDomNodeList nodeList = domElement.childNodes();
|
|
|
|
for (qint32 i = 0; i < nodeList.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement element = nodeList.at(i).toElement();
|
|
|
|
if (not element.isNull())
|
|
|
|
{
|
|
|
|
const quint32 path = GetParametrUInt(element, VAbstractPattern::AttrPath, NULL_ID_STR);
|
|
|
|
if (path > NULL_ID)
|
|
|
|
{
|
|
|
|
records.append(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return records;
|
|
|
|
}
|
|
|
|
|
2017-01-16 10:59:02 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-10-15 11:25:20 +02:00
|
|
|
QVector<quint32> VAbstractPattern::ParsePiecePointRecords(const QDomElement &domElement)
|
2017-01-31 17:09:18 +01:00
|
|
|
{
|
|
|
|
QVector<quint32> records;
|
|
|
|
const QDomNodeList nodeList = domElement.childNodes();
|
|
|
|
for (qint32 i = 0; i < nodeList.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement element = nodeList.at(i).toElement();
|
|
|
|
if (not element.isNull())
|
|
|
|
{
|
|
|
|
const quint32 path = element.text().toUInt();
|
|
|
|
if (path > NULL_ID)
|
|
|
|
{
|
|
|
|
records.append(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return records;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-16 10:59:02 +01:00
|
|
|
VPieceNode VAbstractPattern::ParseSANode(const QDomElement &domElement)
|
|
|
|
{
|
|
|
|
const quint32 id = VDomDocument::GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR);
|
2018-04-12 12:13:19 +02:00
|
|
|
const bool reverse = VDomDocument::GetParametrUInt(domElement, VAbstractPattern::AttrNodeReverse, QChar('0'));
|
2017-03-22 11:05:53 +01:00
|
|
|
const bool excluded = VDomDocument::GetParametrBool(domElement, VAbstractPattern::AttrNodeExcluded, falseStr);
|
2018-03-05 11:05:59 +01:00
|
|
|
const bool uniqeness = VDomDocument::GetParametrBool(domElement, VAbstractPattern::AttrCheckUniqueness, trueStr);
|
2017-01-21 14:24:40 +01:00
|
|
|
const QString saBefore = VDomDocument::GetParametrString(domElement, VAbstractPattern::AttrSABefore,
|
|
|
|
currentSeamAllowance);
|
|
|
|
const QString saAfter = VDomDocument::GetParametrString(domElement, VAbstractPattern::AttrSAAfter,
|
|
|
|
currentSeamAllowance);
|
2018-04-12 12:13:19 +02:00
|
|
|
const PieceNodeAngle angle = static_cast<PieceNodeAngle>(VDomDocument::GetParametrUInt(domElement, AttrAngle,
|
|
|
|
QChar('0')));
|
2017-01-16 10:59:02 +01:00
|
|
|
|
2017-03-24 13:48:07 +01:00
|
|
|
const bool passmark = VDomDocument::GetParametrBool(domElement, VAbstractPattern::AttrNodePassmark, falseStr);
|
|
|
|
const PassmarkLineType passmarkLine = StringToPassmarkLineType(VDomDocument::GetParametrString(domElement,
|
|
|
|
VAbstractPattern::AttrNodePassmarkLine,
|
|
|
|
strOne));
|
|
|
|
const PassmarkAngleType passmarkAngle = StringToPassmarkAngleType(VDomDocument::GetParametrString(domElement,
|
|
|
|
VAbstractPattern::AttrNodePassmarkAngle,
|
|
|
|
strStraightforward));
|
|
|
|
|
2017-04-26 10:22:42 +02:00
|
|
|
const bool showSecond = VDomDocument::GetParametrBool(domElement, VAbstractPattern::AttrNodeShowSecondPassmark,
|
|
|
|
trueStr);
|
2019-04-17 12:02:22 +02:00
|
|
|
const bool manualPassmarkLength =
|
|
|
|
VDomDocument::GetParametrBool(domElement, VAbstractPattern::AttrManualPassmarkLength, falseStr);
|
|
|
|
const QString passmarkLength =
|
|
|
|
VDomDocument::GetParametrEmptyString(domElement, VAbstractPattern::AttrPassmarkLength);
|
2017-04-26 10:22:42 +02:00
|
|
|
|
2017-01-16 10:59:02 +01:00
|
|
|
const QString t = VDomDocument::GetParametrString(domElement, AttrType, VAbstractPattern::NodePoint);
|
|
|
|
Tool tool;
|
|
|
|
|
2019-02-11 13:16:49 +01:00
|
|
|
const QStringList types
|
|
|
|
{
|
|
|
|
VAbstractPattern::NodePoint,
|
|
|
|
VAbstractPattern::NodeArc,
|
|
|
|
VAbstractPattern::NodeSpline,
|
|
|
|
VAbstractPattern::NodeSplinePath,
|
|
|
|
VAbstractPattern::NodeElArc
|
|
|
|
};
|
2017-01-16 10:59:02 +01:00
|
|
|
|
|
|
|
switch (types.indexOf(t))
|
|
|
|
{
|
|
|
|
case 0: // VAbstractPattern::NodePoint
|
|
|
|
tool = Tool::NodePoint;
|
|
|
|
break;
|
|
|
|
case 1: // VAbstractPattern::NodeArc
|
|
|
|
tool = Tool::NodeArc;
|
|
|
|
break;
|
|
|
|
case 2: // VAbstractPattern::NodeSpline
|
|
|
|
tool = Tool::NodeSpline;
|
|
|
|
break;
|
|
|
|
case 3: // VAbstractPattern::NodeSplinePath
|
|
|
|
tool = Tool::NodeSplinePath;
|
|
|
|
break;
|
|
|
|
case 4: // NodeElArc
|
|
|
|
tool = Tool::NodeElArc;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
VException e(QObject::tr("Wrong tag name '%1'.").arg(t));
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
VPieceNode node(id, tool, reverse);
|
2017-01-21 14:24:40 +01:00
|
|
|
node.SetFormulaSABefore(saBefore);
|
|
|
|
node.SetFormulaSAAfter(saAfter);
|
2017-01-16 10:59:02 +01:00
|
|
|
node.SetAngleType(angle);
|
2017-03-21 16:18:48 +01:00
|
|
|
node.SetExcluded(excluded);
|
2018-03-05 11:05:59 +01:00
|
|
|
node.SetCheckUniqueness(uniqeness);
|
2017-04-26 10:22:42 +02:00
|
|
|
node.SetShowSecondPassmark(showSecond);
|
2017-03-24 13:48:07 +01:00
|
|
|
node.SetPassmark(passmark);
|
|
|
|
node.SetPassmarkLineType(passmarkLine);
|
|
|
|
node.SetPassmarkAngleType(passmarkAngle);
|
2019-04-17 12:02:22 +02:00
|
|
|
node.SetManualPassmarkLength(manualPassmarkLength);
|
|
|
|
node.SetFormulaPassmarkLength(passmarkLength);
|
2017-01-16 10:59:02 +01:00
|
|
|
|
|
|
|
return node;
|
2015-06-16 10:30:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-02-10 17:45:49 +01:00
|
|
|
void VAbstractPattern::AddToolOnRemove(VDataTool *tool)
|
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(tool != nullptr)
|
2016-02-10 17:45:49 +01:00
|
|
|
toolsOnRemove.append(tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-06-16 10:30:25 +02:00
|
|
|
/**
|
|
|
|
* @brief getHistory return list with list of history records.
|
|
|
|
* @return list of history records.
|
|
|
|
*/
|
|
|
|
QVector<VToolRecord> *VAbstractPattern::getHistory()
|
|
|
|
{
|
|
|
|
return &history;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<VToolRecord> VAbstractPattern::getLocalHistory() const
|
|
|
|
{
|
2017-09-25 15:36:04 +02:00
|
|
|
return getLocalHistory(GetNameActivPP());
|
2015-06-16 10:30:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractPattern::MPath() const
|
|
|
|
{
|
2018-11-18 08:52:08 +01:00
|
|
|
if (*MPathCached == unknownCharacter)
|
|
|
|
{
|
|
|
|
*MPathCached = UniqueTagText(TagMeasurements);
|
|
|
|
}
|
|
|
|
return *MPathCached;
|
2015-06-16 10:30:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-17 18:42:48 +02:00
|
|
|
void VAbstractPattern::SetMPath(const QString &path)
|
2015-06-16 10:30:25 +02:00
|
|
|
{
|
2015-08-16 17:56:06 +02:00
|
|
|
if (setTagText(TagMeasurements, path))
|
2015-06-16 10:30:25 +02:00
|
|
|
{
|
|
|
|
emit patternChanged(false);
|
2017-08-23 19:54:20 +02:00
|
|
|
patternLabelWasChanged = true;
|
2018-11-18 08:52:08 +01:00
|
|
|
*MPathCached = path;
|
2015-06-16 10:30:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug()<<"Can't save path to measurements"<<Q_FUNC_INFO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 VAbstractPattern::SiblingNodeId(const quint32 &nodeId) const
|
|
|
|
{
|
2017-10-29 18:49:51 +01:00
|
|
|
// This check helps to find missed tools in the switch
|
|
|
|
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 55, "Check if need to ignore modeling tools.");
|
|
|
|
|
2015-06-16 10:30:25 +02:00
|
|
|
quint32 siblingId = NULL_ID;
|
|
|
|
|
|
|
|
const QVector<VToolRecord> history = getLocalHistory();
|
|
|
|
for (qint32 i = 0; i < history.size(); ++i)
|
|
|
|
{
|
|
|
|
const VToolRecord tool = history.at(i);
|
|
|
|
if (nodeId == tool.getId())
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
siblingId = NULL_ID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (qint32 j = i; j > 0; --j)
|
|
|
|
{
|
|
|
|
const VToolRecord tool = history.at(j-1);
|
|
|
|
switch ( tool.getTypeTool() )
|
|
|
|
{
|
2017-10-29 18:49:51 +01:00
|
|
|
case Tool::Arrow:
|
2017-01-21 15:30:14 +01:00
|
|
|
case Tool::Piece:
|
2015-06-16 10:30:25 +02:00
|
|
|
case Tool::UnionDetails:
|
|
|
|
case Tool::NodeArc:
|
2016-12-20 15:51:58 +01:00
|
|
|
case Tool::NodeElArc:
|
2015-06-16 10:30:25 +02:00
|
|
|
case Tool::NodePoint:
|
|
|
|
case Tool::NodeSpline:
|
|
|
|
case Tool::NodeSplinePath:
|
2017-10-29 18:49:51 +01:00
|
|
|
case Tool::PlaceLabel:
|
|
|
|
case Tool::Pin:
|
|
|
|
case Tool::PiecePath:
|
|
|
|
case Tool::InsertNode:
|
|
|
|
case Tool::DuplicateDetail:
|
2015-06-16 10:30:25 +02:00
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
siblingId = tool.getId();
|
|
|
|
j = 0;// break loop
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return siblingId;
|
|
|
|
}
|
|
|
|
|
2015-06-16 11:04:48 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VAbstractPattern::getPatternPieces() const
|
|
|
|
{
|
|
|
|
return patternPieces;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QMap<GHeights, bool> VAbstractPattern::GetGradationHeights() const
|
|
|
|
{
|
|
|
|
QMap<GHeights, bool> map;
|
2016-10-26 13:49:09 +02:00
|
|
|
|
2015-06-16 11:04:48 +02:00
|
|
|
map.insert(GHeights::ALL, true);
|
2016-10-26 13:49:09 +02:00
|
|
|
map.insert(GHeights::H50, true);
|
|
|
|
map.insert(GHeights::H56, true);
|
|
|
|
map.insert(GHeights::H62, true);
|
|
|
|
map.insert(GHeights::H68, true);
|
|
|
|
map.insert(GHeights::H74, true);
|
|
|
|
map.insert(GHeights::H80, true);
|
|
|
|
map.insert(GHeights::H86, true);
|
2015-06-16 11:04:48 +02:00
|
|
|
map.insert(GHeights::H92, true);
|
|
|
|
map.insert(GHeights::H98, true);
|
|
|
|
map.insert(GHeights::H104, true);
|
|
|
|
map.insert(GHeights::H110, true);
|
|
|
|
map.insert(GHeights::H116, true);
|
|
|
|
map.insert(GHeights::H122, true);
|
|
|
|
map.insert(GHeights::H128, true);
|
|
|
|
map.insert(GHeights::H134, true);
|
|
|
|
map.insert(GHeights::H140, true);
|
|
|
|
map.insert(GHeights::H146, true);
|
|
|
|
map.insert(GHeights::H152, true);
|
|
|
|
map.insert(GHeights::H158, true);
|
|
|
|
map.insert(GHeights::H164, true);
|
|
|
|
map.insert(GHeights::H170, true);
|
|
|
|
map.insert(GHeights::H176, true);
|
|
|
|
map.insert(GHeights::H182, true);
|
|
|
|
map.insert(GHeights::H188, true);
|
|
|
|
map.insert(GHeights::H194, true);
|
2017-03-09 21:41:48 +01:00
|
|
|
map.insert(GHeights::H200, true);
|
2015-06-16 11:04:48 +02:00
|
|
|
|
|
|
|
QDomNodeList tags = elementsByTagName(TagGradation);
|
|
|
|
if (tags.size() == 0)
|
|
|
|
{
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList gTags = QStringList() << TagHeights << TagSizes;
|
|
|
|
QDomNode domNode = tags.at(0).firstChild();
|
|
|
|
while (domNode.isNull() == false)
|
|
|
|
{
|
|
|
|
if (domNode.isElement())
|
|
|
|
{
|
|
|
|
const QDomElement domElement = domNode.toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
2016-04-05 19:53:49 +02:00
|
|
|
const QString defValue = trueStr;
|
2015-06-16 11:04:48 +02:00
|
|
|
switch (gTags.indexOf(domElement.tagName()))
|
|
|
|
{
|
|
|
|
case 0: // TagHeights
|
|
|
|
if (GetParametrBool(domElement, AttrAll, defValue))
|
|
|
|
{
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
map.insert(GHeights::ALL, false);
|
|
|
|
}
|
|
|
|
|
2016-10-26 13:49:09 +02:00
|
|
|
map.insert(GHeights::H50, GetParametrBool(domElement, AttrH50, defValue));
|
|
|
|
map.insert(GHeights::H56, GetParametrBool(domElement, AttrH56, defValue));
|
|
|
|
map.insert(GHeights::H62, GetParametrBool(domElement, AttrH62, defValue));
|
|
|
|
map.insert(GHeights::H68, GetParametrBool(domElement, AttrH68, defValue));
|
|
|
|
map.insert(GHeights::H74, GetParametrBool(domElement, AttrH74, defValue));
|
|
|
|
map.insert(GHeights::H80, GetParametrBool(domElement, AttrH80, defValue));
|
|
|
|
map.insert(GHeights::H86, GetParametrBool(domElement, AttrH86, defValue));
|
2015-06-16 11:04:48 +02:00
|
|
|
map.insert(GHeights::H92, GetParametrBool(domElement, AttrH92, defValue));
|
|
|
|
map.insert(GHeights::H98, GetParametrBool(domElement, AttrH98, defValue));
|
|
|
|
map.insert(GHeights::H104, GetParametrBool(domElement, AttrH104, defValue));
|
|
|
|
map.insert(GHeights::H110, GetParametrBool(domElement, AttrH110, defValue));
|
|
|
|
map.insert(GHeights::H116, GetParametrBool(domElement, AttrH116, defValue));
|
|
|
|
map.insert(GHeights::H122, GetParametrBool(domElement, AttrH122, defValue));
|
|
|
|
map.insert(GHeights::H128, GetParametrBool(domElement, AttrH128, defValue));
|
|
|
|
map.insert(GHeights::H134, GetParametrBool(domElement, AttrH134, defValue));
|
|
|
|
map.insert(GHeights::H140, GetParametrBool(domElement, AttrH140, defValue));
|
|
|
|
map.insert(GHeights::H146, GetParametrBool(domElement, AttrH146, defValue));
|
|
|
|
map.insert(GHeights::H152, GetParametrBool(domElement, AttrH152, defValue));
|
|
|
|
map.insert(GHeights::H158, GetParametrBool(domElement, AttrH158, defValue));
|
|
|
|
map.insert(GHeights::H164, GetParametrBool(domElement, AttrH164, defValue));
|
|
|
|
map.insert(GHeights::H170, GetParametrBool(domElement, AttrH170, defValue));
|
|
|
|
map.insert(GHeights::H176, GetParametrBool(domElement, AttrH176, defValue));
|
|
|
|
map.insert(GHeights::H182, GetParametrBool(domElement, AttrH182, defValue));
|
|
|
|
map.insert(GHeights::H188, GetParametrBool(domElement, AttrH188, defValue));
|
|
|
|
map.insert(GHeights::H194, GetParametrBool(domElement, AttrH194, defValue));
|
2017-03-09 21:41:48 +01:00
|
|
|
map.insert(GHeights::H200, GetParametrBool(domElement, AttrH200, defValue));
|
2015-06-16 11:04:48 +02:00
|
|
|
return map;
|
|
|
|
case 1: // TagSizes
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
domNode = domNode.nextSibling();
|
|
|
|
}
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetGradationHeights(const QMap<GHeights, bool> &options)
|
|
|
|
{
|
|
|
|
CheckTagExists(TagGradation);
|
|
|
|
QDomNodeList tags = elementsByTagName(TagGradation);
|
2016-04-06 03:11:14 +02:00
|
|
|
if (tags.isEmpty())
|
2015-06-16 11:04:48 +02:00
|
|
|
{
|
|
|
|
qDebug()<<"Can't save tag "<<TagGradation<<Q_FUNC_INFO;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList gTags = QStringList() << TagHeights << TagSizes;
|
|
|
|
QDomNode domNode = tags.at(0).firstChild();
|
|
|
|
while (domNode.isNull() == false)
|
|
|
|
{
|
|
|
|
if (domNode.isElement())
|
|
|
|
{
|
|
|
|
QDomElement domElement = domNode.toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
|
|
|
switch (gTags.indexOf(domElement.tagName()))
|
|
|
|
{
|
|
|
|
case 0: // TagHeights
|
|
|
|
SetAttribute(domElement, AttrAll, options.value(GHeights::ALL));
|
2016-01-03 14:21:30 +01:00
|
|
|
if (options.value(GHeights::ALL))
|
|
|
|
{
|
2016-10-26 13:49:09 +02:00
|
|
|
domElement.removeAttribute(AttrH50);
|
|
|
|
domElement.removeAttribute(AttrH56);
|
|
|
|
domElement.removeAttribute(AttrH62);
|
|
|
|
domElement.removeAttribute(AttrH68);
|
|
|
|
domElement.removeAttribute(AttrH74);
|
|
|
|
domElement.removeAttribute(AttrH80);
|
|
|
|
domElement.removeAttribute(AttrH86);
|
2016-01-03 14:21:30 +01:00
|
|
|
domElement.removeAttribute(AttrH92);
|
|
|
|
domElement.removeAttribute(AttrH98);
|
|
|
|
domElement.removeAttribute(AttrH104);
|
|
|
|
domElement.removeAttribute(AttrH110);
|
|
|
|
domElement.removeAttribute(AttrH116);
|
|
|
|
domElement.removeAttribute(AttrH122);
|
|
|
|
domElement.removeAttribute(AttrH128);
|
|
|
|
domElement.removeAttribute(AttrH134);
|
|
|
|
domElement.removeAttribute(AttrH140);
|
|
|
|
domElement.removeAttribute(AttrH146);
|
|
|
|
domElement.removeAttribute(AttrH152);
|
|
|
|
domElement.removeAttribute(AttrH158);
|
|
|
|
domElement.removeAttribute(AttrH164);
|
|
|
|
domElement.removeAttribute(AttrH170);
|
|
|
|
domElement.removeAttribute(AttrH176);
|
|
|
|
domElement.removeAttribute(AttrH182);
|
|
|
|
domElement.removeAttribute(AttrH188);
|
|
|
|
domElement.removeAttribute(AttrH194);
|
2017-03-09 21:41:48 +01:00
|
|
|
domElement.removeAttribute(AttrH200);
|
2016-01-03 14:21:30 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-26 13:49:09 +02:00
|
|
|
SetAttribute(domElement, AttrH50, options.value(GHeights::H50));
|
|
|
|
SetAttribute(domElement, AttrH56, options.value(GHeights::H56));
|
|
|
|
SetAttribute(domElement, AttrH62, options.value(GHeights::H62));
|
|
|
|
SetAttribute(domElement, AttrH68, options.value(GHeights::H68));
|
|
|
|
SetAttribute(domElement, AttrH74, options.value(GHeights::H74));
|
|
|
|
SetAttribute(domElement, AttrH80, options.value(GHeights::H80));
|
|
|
|
SetAttribute(domElement, AttrH86, options.value(GHeights::H86));
|
2016-01-03 14:21:30 +01:00
|
|
|
SetAttribute(domElement, AttrH92, options.value(GHeights::H92));
|
|
|
|
SetAttribute(domElement, AttrH98, options.value(GHeights::H98));
|
|
|
|
SetAttribute(domElement, AttrH104, options.value(GHeights::H104));
|
|
|
|
SetAttribute(domElement, AttrH110, options.value(GHeights::H110));
|
|
|
|
SetAttribute(domElement, AttrH116, options.value(GHeights::H116));
|
|
|
|
SetAttribute(domElement, AttrH122, options.value(GHeights::H122));
|
|
|
|
SetAttribute(domElement, AttrH128, options.value(GHeights::H128));
|
|
|
|
SetAttribute(domElement, AttrH134, options.value(GHeights::H134));
|
|
|
|
SetAttribute(domElement, AttrH140, options.value(GHeights::H140));
|
|
|
|
SetAttribute(domElement, AttrH146, options.value(GHeights::H146));
|
|
|
|
SetAttribute(domElement, AttrH152, options.value(GHeights::H152));
|
|
|
|
SetAttribute(domElement, AttrH158, options.value(GHeights::H158));
|
|
|
|
SetAttribute(domElement, AttrH164, options.value(GHeights::H164));
|
|
|
|
SetAttribute(domElement, AttrH170, options.value(GHeights::H170));
|
|
|
|
SetAttribute(domElement, AttrH176, options.value(GHeights::H176));
|
|
|
|
SetAttribute(domElement, AttrH182, options.value(GHeights::H182));
|
|
|
|
SetAttribute(domElement, AttrH188, options.value(GHeights::H188));
|
|
|
|
SetAttribute(domElement, AttrH194, options.value(GHeights::H194));
|
2017-03-09 21:41:48 +01:00
|
|
|
SetAttribute(domElement, AttrH200, options.value(GHeights::H200));
|
2016-01-03 14:21:30 +01:00
|
|
|
}
|
2015-06-16 11:04:48 +02:00
|
|
|
|
2015-12-18 12:57:03 +01:00
|
|
|
modified = true;
|
2015-06-16 11:04:48 +02:00
|
|
|
emit patternChanged(false);
|
|
|
|
return;
|
|
|
|
case 1: // TagSizes
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
domNode = domNode.nextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QMap<GSizes, bool> VAbstractPattern::GetGradationSizes() const
|
|
|
|
{
|
|
|
|
QMap<GSizes, bool> map;
|
|
|
|
map.insert(GSizes::ALL, true);
|
|
|
|
map.insert(GSizes::S22, true);
|
|
|
|
map.insert(GSizes::S24, true);
|
|
|
|
map.insert(GSizes::S26, true);
|
|
|
|
map.insert(GSizes::S28, true);
|
|
|
|
map.insert(GSizes::S30, true);
|
|
|
|
map.insert(GSizes::S32, true);
|
|
|
|
map.insert(GSizes::S34, true);
|
|
|
|
map.insert(GSizes::S36, true);
|
|
|
|
map.insert(GSizes::S38, true);
|
|
|
|
map.insert(GSizes::S40, true);
|
|
|
|
map.insert(GSizes::S42, true);
|
|
|
|
map.insert(GSizes::S44, true);
|
|
|
|
map.insert(GSizes::S46, true);
|
|
|
|
map.insert(GSizes::S48, true);
|
|
|
|
map.insert(GSizes::S50, true);
|
|
|
|
map.insert(GSizes::S52, true);
|
|
|
|
map.insert(GSizes::S54, true);
|
|
|
|
map.insert(GSizes::S56, true);
|
2017-02-22 06:54:42 +01:00
|
|
|
map.insert(GSizes::S58, true);
|
|
|
|
map.insert(GSizes::S60, true);
|
|
|
|
map.insert(GSizes::S62, true);
|
|
|
|
map.insert(GSizes::S64, true);
|
|
|
|
map.insert(GSizes::S66, true);
|
|
|
|
map.insert(GSizes::S68, true);
|
|
|
|
map.insert(GSizes::S70, true);
|
|
|
|
map.insert(GSizes::S72, true);
|
2015-06-16 11:04:48 +02:00
|
|
|
|
|
|
|
QDomNodeList tags = elementsByTagName(TagGradation);
|
|
|
|
if (tags.size() == 0)
|
|
|
|
{
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList gTags = QStringList() << TagHeights << TagSizes;
|
|
|
|
QDomNode domNode = tags.at(0).firstChild();
|
|
|
|
while (domNode.isNull() == false)
|
|
|
|
{
|
|
|
|
if (domNode.isElement())
|
|
|
|
{
|
|
|
|
const QDomElement domElement = domNode.toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
2016-04-05 19:53:49 +02:00
|
|
|
const QString defValue = trueStr;
|
2015-06-16 11:04:48 +02:00
|
|
|
switch (gTags.indexOf(domElement.tagName()))
|
|
|
|
{
|
|
|
|
case 1: // TagSizes
|
|
|
|
if (GetParametrBool(domElement, AttrAll, defValue))
|
|
|
|
{
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
map.insert(GSizes::ALL, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
map.insert(GSizes::S22, GetParametrBool(domElement, AttrS22, defValue));
|
|
|
|
map.insert(GSizes::S24, GetParametrBool(domElement, AttrS24, defValue));
|
|
|
|
map.insert(GSizes::S26, GetParametrBool(domElement, AttrS26, defValue));
|
|
|
|
map.insert(GSizes::S28, GetParametrBool(domElement, AttrS28, defValue));
|
|
|
|
map.insert(GSizes::S30, GetParametrBool(domElement, AttrS30, defValue));
|
|
|
|
map.insert(GSizes::S32, GetParametrBool(domElement, AttrS32, defValue));
|
|
|
|
map.insert(GSizes::S34, GetParametrBool(domElement, AttrS34, defValue));
|
|
|
|
map.insert(GSizes::S36, GetParametrBool(domElement, AttrS36, defValue));
|
|
|
|
map.insert(GSizes::S38, GetParametrBool(domElement, AttrS38, defValue));
|
|
|
|
map.insert(GSizes::S40, GetParametrBool(domElement, AttrS40, defValue));
|
|
|
|
map.insert(GSizes::S42, GetParametrBool(domElement, AttrS42, defValue));
|
|
|
|
map.insert(GSizes::S44, GetParametrBool(domElement, AttrS44, defValue));
|
|
|
|
map.insert(GSizes::S46, GetParametrBool(domElement, AttrS46, defValue));
|
|
|
|
map.insert(GSizes::S48, GetParametrBool(domElement, AttrS48, defValue));
|
|
|
|
map.insert(GSizes::S50, GetParametrBool(domElement, AttrS50, defValue));
|
|
|
|
map.insert(GSizes::S52, GetParametrBool(domElement, AttrS52, defValue));
|
|
|
|
map.insert(GSizes::S54, GetParametrBool(domElement, AttrS54, defValue));
|
|
|
|
map.insert(GSizes::S56, GetParametrBool(domElement, AttrS56, defValue));
|
2017-02-22 06:54:42 +01:00
|
|
|
map.insert(GSizes::S58, GetParametrBool(domElement, AttrS58, defValue));
|
|
|
|
map.insert(GSizes::S60, GetParametrBool(domElement, AttrS60, defValue));
|
|
|
|
map.insert(GSizes::S62, GetParametrBool(domElement, AttrS62, defValue));
|
|
|
|
map.insert(GSizes::S64, GetParametrBool(domElement, AttrS64, defValue));
|
|
|
|
map.insert(GSizes::S66, GetParametrBool(domElement, AttrS66, defValue));
|
|
|
|
map.insert(GSizes::S68, GetParametrBool(domElement, AttrS68, defValue));
|
|
|
|
map.insert(GSizes::S70, GetParametrBool(domElement, AttrS70, defValue));
|
|
|
|
map.insert(GSizes::S72, GetParametrBool(domElement, AttrS72, defValue));
|
2015-06-16 11:04:48 +02:00
|
|
|
return map;
|
2017-03-18 10:04:12 +01:00
|
|
|
case 0: // TagHeights
|
2015-06-16 11:04:48 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
domNode = domNode.nextSibling();
|
|
|
|
}
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetGradationSizes(const QMap<GSizes, bool> &options)
|
|
|
|
{
|
|
|
|
CheckTagExists(TagGradation);
|
|
|
|
QDomNodeList tags = elementsByTagName(TagGradation);
|
2016-04-06 03:11:14 +02:00
|
|
|
if (tags.isEmpty())
|
2015-06-16 11:04:48 +02:00
|
|
|
{
|
|
|
|
qDebug()<<"Can't save tag "<<TagGradation<<Q_FUNC_INFO;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList gTags = QStringList() << TagHeights << TagSizes;
|
|
|
|
QDomNode domNode = tags.at(0).firstChild();
|
|
|
|
while (domNode.isNull() == false)
|
|
|
|
{
|
|
|
|
if (domNode.isElement())
|
|
|
|
{
|
|
|
|
QDomElement domElement = domNode.toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
|
|
|
switch (gTags.indexOf(domElement.tagName()))
|
|
|
|
{
|
|
|
|
case 1: // TagSizes
|
|
|
|
SetAttribute(domElement, AttrAll, options.value(GSizes::ALL));
|
2016-01-03 14:21:30 +01:00
|
|
|
if (options.value(GSizes::ALL))
|
|
|
|
{
|
|
|
|
domElement.removeAttribute(AttrS22);
|
|
|
|
domElement.removeAttribute(AttrS24);
|
|
|
|
domElement.removeAttribute(AttrS26);
|
|
|
|
domElement.removeAttribute(AttrS28);
|
|
|
|
domElement.removeAttribute(AttrS30);
|
|
|
|
domElement.removeAttribute(AttrS32);
|
|
|
|
domElement.removeAttribute(AttrS34);
|
|
|
|
domElement.removeAttribute(AttrS36);
|
|
|
|
domElement.removeAttribute(AttrS38);
|
|
|
|
domElement.removeAttribute(AttrS40);
|
|
|
|
domElement.removeAttribute(AttrS42);
|
|
|
|
domElement.removeAttribute(AttrS44);
|
|
|
|
domElement.removeAttribute(AttrS46);
|
|
|
|
domElement.removeAttribute(AttrS48);
|
|
|
|
domElement.removeAttribute(AttrS50);
|
|
|
|
domElement.removeAttribute(AttrS52);
|
|
|
|
domElement.removeAttribute(AttrS54);
|
|
|
|
domElement.removeAttribute(AttrS56);
|
2017-02-22 06:54:42 +01:00
|
|
|
domElement.removeAttribute(AttrS58);
|
|
|
|
domElement.removeAttribute(AttrS60);
|
|
|
|
domElement.removeAttribute(AttrS62);
|
|
|
|
domElement.removeAttribute(AttrS64);
|
|
|
|
domElement.removeAttribute(AttrS66);
|
|
|
|
domElement.removeAttribute(AttrS68);
|
|
|
|
domElement.removeAttribute(AttrS70);
|
|
|
|
domElement.removeAttribute(AttrS72);
|
2016-01-03 14:21:30 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetAttribute(domElement, AttrS22, options.value(GSizes::S22));
|
|
|
|
SetAttribute(domElement, AttrS24, options.value(GSizes::S24));
|
|
|
|
SetAttribute(domElement, AttrS26, options.value(GSizes::S26));
|
|
|
|
SetAttribute(domElement, AttrS28, options.value(GSizes::S28));
|
|
|
|
SetAttribute(domElement, AttrS30, options.value(GSizes::S30));
|
|
|
|
SetAttribute(domElement, AttrS32, options.value(GSizes::S32));
|
|
|
|
SetAttribute(domElement, AttrS34, options.value(GSizes::S34));
|
|
|
|
SetAttribute(domElement, AttrS36, options.value(GSizes::S36));
|
|
|
|
SetAttribute(domElement, AttrS38, options.value(GSizes::S38));
|
|
|
|
SetAttribute(domElement, AttrS40, options.value(GSizes::S40));
|
|
|
|
SetAttribute(domElement, AttrS42, options.value(GSizes::S42));
|
|
|
|
SetAttribute(domElement, AttrS44, options.value(GSizes::S44));
|
|
|
|
SetAttribute(domElement, AttrS46, options.value(GSizes::S46));
|
|
|
|
SetAttribute(domElement, AttrS48, options.value(GSizes::S48));
|
|
|
|
SetAttribute(domElement, AttrS50, options.value(GSizes::S50));
|
|
|
|
SetAttribute(domElement, AttrS52, options.value(GSizes::S52));
|
|
|
|
SetAttribute(domElement, AttrS54, options.value(GSizes::S54));
|
|
|
|
SetAttribute(domElement, AttrS56, options.value(GSizes::S56));
|
2017-02-22 06:54:42 +01:00
|
|
|
SetAttribute(domElement, AttrS58, options.value(GSizes::S58));
|
|
|
|
SetAttribute(domElement, AttrS60, options.value(GSizes::S60));
|
|
|
|
SetAttribute(domElement, AttrS62, options.value(GSizes::S62));
|
|
|
|
SetAttribute(domElement, AttrS64, options.value(GSizes::S64));
|
|
|
|
SetAttribute(domElement, AttrS66, options.value(GSizes::S66));
|
|
|
|
SetAttribute(domElement, AttrS68, options.value(GSizes::S68));
|
|
|
|
SetAttribute(domElement, AttrS70, options.value(GSizes::S70));
|
|
|
|
SetAttribute(domElement, AttrS72, options.value(GSizes::S72));
|
2016-01-03 14:21:30 +01:00
|
|
|
}
|
2015-06-16 11:04:48 +02:00
|
|
|
|
2015-12-18 12:57:03 +01:00
|
|
|
modified = true;
|
2015-06-16 11:04:48 +02:00
|
|
|
emit patternChanged(false);
|
|
|
|
return;
|
2017-03-18 10:04:12 +01:00
|
|
|
case 0: // TagHeights
|
2015-06-16 11:04:48 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
domNode = domNode.nextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractPattern::GetDescription() const
|
|
|
|
{
|
|
|
|
return UniqueTagText(TagDescription);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetDescription(const QString &text)
|
|
|
|
{
|
|
|
|
CheckTagExists(TagDescription);
|
|
|
|
setTagText(TagDescription, text);
|
2015-12-18 12:57:03 +01:00
|
|
|
modified = true;
|
2015-06-16 11:04:48 +02:00
|
|
|
emit patternChanged(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractPattern::GetNotes() const
|
|
|
|
{
|
|
|
|
return UniqueTagText(TagNotes);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetNotes(const QString &text)
|
|
|
|
{
|
|
|
|
CheckTagExists(TagNotes);
|
|
|
|
setTagText(TagNotes, text);
|
2015-12-18 12:57:03 +01:00
|
|
|
modified = true;
|
2015-06-16 11:04:48 +02:00
|
|
|
emit patternChanged(false);
|
|
|
|
}
|
|
|
|
|
2016-06-26 16:49:51 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractPattern::GetPatternName() const
|
|
|
|
{
|
2018-11-18 08:52:08 +01:00
|
|
|
if (*patternNameCached == unknownCharacter)
|
|
|
|
{
|
|
|
|
*patternNameCached = UniqueTagText(TagPatternName);
|
|
|
|
}
|
|
|
|
return *patternNameCached;
|
2016-06-26 16:49:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-22 12:40:02 +02:00
|
|
|
void VAbstractPattern::SetPatternName(const QString &qsName)
|
2016-06-26 16:49:51 +02:00
|
|
|
{
|
2018-11-18 08:52:08 +01:00
|
|
|
*patternNameCached = qsName;
|
2016-06-26 16:49:51 +02:00
|
|
|
CheckTagExists(TagPatternName);
|
2018-11-18 08:52:08 +01:00
|
|
|
setTagText(TagPatternName, *patternNameCached);
|
2017-08-23 19:54:20 +02:00
|
|
|
patternLabelWasChanged = true;
|
2016-06-26 16:49:51 +02:00
|
|
|
modified = true;
|
|
|
|
emit patternChanged(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractPattern::GetCompanyName() const
|
|
|
|
{
|
2018-11-18 08:52:08 +01:00
|
|
|
if (*companyNameCached == unknownCharacter)
|
|
|
|
{
|
|
|
|
*companyNameCached = UniqueTagText(TagCompanyName);
|
|
|
|
}
|
|
|
|
return *companyNameCached;
|
2016-06-26 16:49:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-22 12:40:02 +02:00
|
|
|
void VAbstractPattern::SetCompanyName(const QString& qsName)
|
2016-06-26 16:49:51 +02:00
|
|
|
{
|
2018-11-18 08:52:08 +01:00
|
|
|
*companyNameCached = qsName;
|
2016-06-26 16:49:51 +02:00
|
|
|
CheckTagExists(TagCompanyName);
|
2018-11-18 08:52:08 +01:00
|
|
|
setTagText(TagCompanyName, *companyNameCached);
|
2017-08-23 19:54:20 +02:00
|
|
|
patternLabelWasChanged = true;
|
2016-06-26 16:49:51 +02:00
|
|
|
modified = true;
|
|
|
|
emit patternChanged(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractPattern::GetPatternNumber() const
|
|
|
|
{
|
2018-11-18 08:52:08 +01:00
|
|
|
if (*patternNumberCached == unknownCharacter)
|
|
|
|
{
|
|
|
|
*patternNumberCached = UniqueTagText(TagPatternNum);
|
|
|
|
}
|
|
|
|
return *patternNumberCached;
|
2016-06-26 16:49:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-22 12:40:02 +02:00
|
|
|
void VAbstractPattern::SetPatternNumber(const QString& qsNum)
|
2016-06-26 16:49:51 +02:00
|
|
|
{
|
2018-11-18 08:52:08 +01:00
|
|
|
*patternNumberCached = qsNum;
|
2016-06-26 16:49:51 +02:00
|
|
|
CheckTagExists(TagPatternNum);
|
2018-11-18 08:52:08 +01:00
|
|
|
setTagText(TagPatternNum, *patternNumberCached);
|
2017-08-23 19:54:20 +02:00
|
|
|
patternLabelWasChanged = true;
|
2016-06-26 16:49:51 +02:00
|
|
|
modified = true;
|
|
|
|
emit patternChanged(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractPattern::GetCustomerName() const
|
|
|
|
{
|
|
|
|
return UniqueTagText(TagCustomerName);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-22 12:40:02 +02:00
|
|
|
void VAbstractPattern::SetCustomerName(const QString& qsName)
|
2016-06-26 16:49:51 +02:00
|
|
|
{
|
|
|
|
CheckTagExists(TagCustomerName);
|
|
|
|
setTagText(TagCustomerName, qsName);
|
2017-08-23 19:54:20 +02:00
|
|
|
patternLabelWasChanged = true;
|
2016-06-26 16:49:51 +02:00
|
|
|
modified = true;
|
|
|
|
emit patternChanged(false);
|
|
|
|
}
|
|
|
|
|
2017-08-19 18:10:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractPattern::GetLabelDateFormat() const
|
|
|
|
{
|
2018-11-18 08:52:08 +01:00
|
|
|
if (*labelDateFormatCached == unknownCharacter)
|
2017-08-19 18:10:57 +02:00
|
|
|
{
|
2018-11-18 08:52:08 +01:00
|
|
|
const QString globalLabelDateFormat = qApp->Settings()->GetLabelDateFormat();
|
|
|
|
|
|
|
|
const QDomNodeList list = elementsByTagName(TagPatternLabel);
|
|
|
|
if (list.isEmpty())
|
|
|
|
{
|
|
|
|
return globalLabelDateFormat;
|
|
|
|
}
|
2017-08-19 18:10:57 +02:00
|
|
|
|
2018-11-18 08:52:08 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
*labelDateFormatCached = GetParametrString(list.at(0).toElement(), AttrDateFormat);
|
|
|
|
}
|
|
|
|
catch (const VExceptionEmptyParameter &)
|
|
|
|
{
|
|
|
|
return globalLabelDateFormat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return *labelDateFormatCached;
|
2017-08-19 18:10:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetLabelDateFormat(const QString &format)
|
|
|
|
{
|
2018-11-18 08:52:08 +01:00
|
|
|
*labelDateFormatCached = format;
|
2017-08-19 18:10:57 +02:00
|
|
|
QDomElement tag = CheckTagExists(TagPatternLabel);
|
2018-11-18 08:52:08 +01:00
|
|
|
SetAttribute(tag, AttrDateFormat, *labelDateFormatCached);
|
2017-08-19 18:52:33 +02:00
|
|
|
patternLabelWasChanged = true;
|
2017-08-19 18:10:57 +02:00
|
|
|
modified = true;
|
|
|
|
emit patternChanged(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractPattern::GetLabelTimeFormat() const
|
|
|
|
{
|
|
|
|
QString globalLabelTimeFormat = qApp->Settings()->GetLabelTimeFormat();
|
|
|
|
|
|
|
|
const QDomNodeList list = elementsByTagName(TagPatternLabel);
|
|
|
|
if (list.isEmpty())
|
|
|
|
{
|
|
|
|
return globalLabelTimeFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDomElement tag = list.at(0).toElement();
|
|
|
|
return GetParametrString(tag, AttrTimeFormat, globalLabelTimeFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetLabelTimeFormat(const QString &format)
|
|
|
|
{
|
|
|
|
QDomElement tag = CheckTagExists(TagPatternLabel);
|
|
|
|
SetAttribute(tag, AttrTimeFormat, format);
|
2017-08-19 18:52:33 +02:00
|
|
|
patternLabelWasChanged = true;
|
2017-08-19 18:10:57 +02:00
|
|
|
modified = true;
|
|
|
|
emit patternChanged(false);
|
|
|
|
}
|
|
|
|
|
2017-08-15 09:44:00 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetPatternLabelTemplate(const QVector<VLabelTemplateLine> &lines)
|
|
|
|
{
|
|
|
|
QDomElement tag = CheckTagExists(TagPatternLabel);
|
|
|
|
RemoveAllChildren(tag);
|
|
|
|
SetLabelTemplate(tag, lines);
|
2017-08-15 10:38:36 +02:00
|
|
|
patternLabelLines = lines;
|
2017-08-15 14:22:33 +02:00
|
|
|
patternLabelWasChanged = true;
|
2017-08-19 18:10:57 +02:00
|
|
|
modified = true;
|
|
|
|
emit patternChanged(false);
|
2017-08-15 09:44:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<VLabelTemplateLine> VAbstractPattern::GetPatternLabelTemplate() const
|
|
|
|
{
|
2017-08-15 10:38:36 +02:00
|
|
|
if (patternLabelLines.isEmpty())
|
2017-08-15 09:44:00 +02:00
|
|
|
{
|
2017-08-15 10:38:36 +02:00
|
|
|
const QDomNodeList list = elementsByTagName(TagPatternLabel);
|
2017-08-30 07:55:07 +02:00
|
|
|
if (list.isEmpty() || list.at(0).childNodes().count() == 0)
|
2017-08-15 10:38:36 +02:00
|
|
|
{
|
|
|
|
return QVector<VLabelTemplateLine>();
|
|
|
|
}
|
|
|
|
|
|
|
|
patternLabelLines = GetLabelTemplate(list.at(0).toElement());
|
2017-08-15 09:44:00 +02:00
|
|
|
}
|
2017-08-15 10:38:36 +02:00
|
|
|
|
|
|
|
return patternLabelLines;
|
2017-08-15 09:44:00 +02:00
|
|
|
}
|
|
|
|
|
2017-08-30 07:55:07 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetPatternMaterials(const QMap<int, QString> &materials)
|
|
|
|
{
|
|
|
|
QDomElement tag = CheckTagExists(TagPatternMaterials);
|
|
|
|
RemoveAllChildren(tag);
|
|
|
|
SetMaterials(tag, materials);
|
|
|
|
patternMaterials = materials;
|
|
|
|
patternLabelWasChanged = true;
|
|
|
|
modified = true;
|
|
|
|
emit patternChanged(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QMap<int, QString> VAbstractPattern::GetPatternMaterials() const
|
|
|
|
{
|
|
|
|
if (patternMaterials.isEmpty())
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(TagPatternMaterials);
|
|
|
|
if (list.isEmpty() || list.at(0).childNodes().count() == 0)
|
|
|
|
{
|
|
|
|
return QMap<int, QString>();
|
|
|
|
}
|
|
|
|
|
|
|
|
patternMaterials = GetMaterials(list.at(0).toElement());
|
|
|
|
}
|
|
|
|
|
2018-07-18 19:18:30 +02:00
|
|
|
return AdjustMaterials(patternMaterials);
|
2017-08-30 07:55:07 +02:00
|
|
|
}
|
|
|
|
|
2017-09-26 11:54:52 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<VFinalMeasurement> VAbstractPattern::GetFinalMeasurements() const
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(TagFinalMeasurements);
|
|
|
|
if (list.isEmpty() || list.at(0).childNodes().count() == 0)
|
|
|
|
{
|
|
|
|
return QVector<VFinalMeasurement>();
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetFMeasurements(list.at(0).toElement());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetFinalMeasurements(const QVector<VFinalMeasurement> &measurements)
|
|
|
|
{
|
|
|
|
QDomElement tag = CheckTagExists(TagFinalMeasurements);
|
|
|
|
RemoveAllChildren(tag);
|
|
|
|
SetFMeasurements(tag, measurements);
|
|
|
|
modified = true;
|
|
|
|
emit patternChanged(false);
|
|
|
|
}
|
|
|
|
|
2017-08-15 14:22:33 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetPatternWasChanged(bool changed)
|
|
|
|
{
|
|
|
|
patternLabelWasChanged = changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VAbstractPattern::GetPatternWasChanged() const
|
|
|
|
{
|
|
|
|
return patternLabelWasChanged;
|
|
|
|
}
|
|
|
|
|
2016-03-09 20:01:37 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractPattern::GetImage() const
|
|
|
|
{
|
|
|
|
return UniqueTagText(TagImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-22 11:18:05 +01:00
|
|
|
QString VAbstractPattern::GetImageExtension() const
|
|
|
|
{
|
2016-04-02 02:00:00 +02:00
|
|
|
const QString defExt = QStringLiteral("PNG");
|
2016-03-22 11:18:05 +01:00
|
|
|
const QDomNodeList nodeList = this->elementsByTagName(TagImage);
|
|
|
|
if (nodeList.isEmpty())
|
|
|
|
{
|
|
|
|
return defExt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QDomNode domNode = nodeList.at(0);
|
|
|
|
if (domNode.isNull() == false && domNode.isElement())
|
|
|
|
{
|
|
|
|
const QDomElement domElement = domNode.toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
2016-04-02 02:00:00 +02:00
|
|
|
const QString ext = domElement.attribute(AttrExtension, defExt);
|
|
|
|
return ext;
|
2016-03-22 11:18:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return defExt;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetImage(const QString &text, const QString &extension)
|
2016-03-09 20:01:37 +01:00
|
|
|
{
|
2016-04-06 04:34:08 +02:00
|
|
|
QDomElement imageElement = CheckTagExists(TagImage);
|
|
|
|
setTagText(imageElement, text);
|
|
|
|
CheckTagExists(TagImage).setAttribute(AttrExtension, extension);
|
2016-03-09 20:01:37 +01:00
|
|
|
modified = true;
|
|
|
|
emit patternChanged(false);
|
|
|
|
}
|
|
|
|
|
2016-03-15 19:32:52 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::DeleteImage()
|
|
|
|
{
|
|
|
|
QDomElement pattern = documentElement();
|
2016-04-06 04:34:08 +02:00
|
|
|
pattern.removeChild(CheckTagExists(TagImage));
|
2016-03-15 19:32:52 +01:00
|
|
|
modified = true;
|
|
|
|
emit patternChanged(false);
|
|
|
|
}
|
|
|
|
|
2015-06-16 11:04:48 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractPattern::GetVersion() const
|
|
|
|
{
|
|
|
|
return UniqueTagText(TagVersion, VPatternConverter::PatternMaxVerStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetVersion()
|
|
|
|
{
|
|
|
|
setTagText(TagVersion, VPatternConverter::PatternMaxVerStr);
|
|
|
|
emit patternChanged(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief haveLiteChange we have unsaved change.
|
|
|
|
*/
|
|
|
|
void VAbstractPattern::haveLiteChange()
|
|
|
|
{
|
|
|
|
emit patternChanged(false);
|
|
|
|
}
|
|
|
|
|
2015-06-16 10:30:25 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-19 19:50:42 +02:00
|
|
|
void VAbstractPattern::NeedFullParsing()
|
|
|
|
{
|
|
|
|
emit UndoCommand();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::ClearScene()
|
|
|
|
{
|
|
|
|
emit ClearMainWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-10-14 19:41:37 +02:00
|
|
|
void VAbstractPattern::CheckInLayoutList()
|
|
|
|
{
|
|
|
|
emit UpdateInLayoutList();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-10-14 20:33:12 +02:00
|
|
|
void VAbstractPattern::SelectedDetail(quint32 id)
|
|
|
|
{
|
|
|
|
emit ShowDetail(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-12-03 17:44:24 +01:00
|
|
|
void VAbstractPattern::ToolExists(const quint32 &id)
|
2015-06-16 10:30:25 +02:00
|
|
|
{
|
|
|
|
if (tools.contains(id) == false)
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't find tool in table."), id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-21 16:32:08 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPiecePath VAbstractPattern::ParsePathNodes(const QDomElement &domElement)
|
|
|
|
{
|
|
|
|
VPiecePath path;
|
|
|
|
const QDomNodeList nodeList = domElement.childNodes();
|
|
|
|
for (qint32 i = 0; i < nodeList.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement element = nodeList.at(i).toElement();
|
|
|
|
if (not element.isNull() && element.tagName() == VAbstractPattern::TagNode)
|
|
|
|
{
|
|
|
|
path.Append(ParseSANode(element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2015-06-16 10:30:25 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief SetActivPP set current pattern piece.
|
|
|
|
* @param name pattern peace name.
|
|
|
|
*/
|
|
|
|
void VAbstractPattern::SetActivPP(const QString &name)
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT_X(not name.isEmpty(), Q_FUNC_INFO, "name pattern piece is empty");
|
2015-06-16 10:30:25 +02:00
|
|
|
this->nameActivPP = name;
|
|
|
|
emit ChangedActivPP(name);
|
|
|
|
}
|
2015-06-16 11:04:48 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-04-06 04:31:42 +02:00
|
|
|
QDomElement VAbstractPattern::CheckTagExists(const QString &tag)
|
2015-06-16 11:04:48 +02:00
|
|
|
{
|
2016-04-06 04:31:42 +02:00
|
|
|
const QDomNodeList list = elementsByTagName(tag);
|
|
|
|
QDomElement element;
|
|
|
|
if (list.isEmpty())
|
2015-06-16 11:04:48 +02:00
|
|
|
{
|
2017-08-16 15:56:07 +02:00
|
|
|
const QStringList tags = QStringList() << TagUnit << TagImage << TagDescription << TagNotes
|
2016-06-26 16:49:51 +02:00
|
|
|
<< TagGradation << TagPatternName << TagPatternNum << TagCompanyName
|
2017-09-26 11:54:52 +02:00
|
|
|
<< TagCustomerName << TagPatternLabel << TagPatternMaterials
|
|
|
|
<< TagFinalMeasurements;
|
2015-06-16 11:04:48 +02:00
|
|
|
switch (tags.indexOf(tag))
|
|
|
|
{
|
2016-03-13 20:13:58 +01:00
|
|
|
case 1: //TagImage
|
2016-04-06 04:31:42 +02:00
|
|
|
element = createElement(TagImage);
|
2015-06-16 11:04:48 +02:00
|
|
|
break;
|
2017-08-16 15:56:07 +02:00
|
|
|
case 2: //TagDescription
|
2016-04-06 04:31:42 +02:00
|
|
|
element = createElement(TagDescription);
|
2015-06-16 11:04:48 +02:00
|
|
|
break;
|
2017-08-16 15:56:07 +02:00
|
|
|
case 3: //TagNotes
|
2016-04-06 04:31:42 +02:00
|
|
|
element = createElement(TagNotes);
|
2015-06-16 11:04:48 +02:00
|
|
|
break;
|
2017-08-16 15:56:07 +02:00
|
|
|
case 4: //TagGradation
|
2015-06-16 11:04:48 +02:00
|
|
|
{
|
2016-04-06 04:31:42 +02:00
|
|
|
element = createElement(TagGradation);
|
2016-01-03 14:21:30 +01:00
|
|
|
|
|
|
|
QDomElement heights = createElement(TagHeights);
|
2018-04-13 08:00:09 +02:00
|
|
|
heights.setAttribute(AttrAll, trueStr);
|
2016-04-06 04:31:42 +02:00
|
|
|
element.appendChild(heights);
|
2016-01-03 14:21:30 +01:00
|
|
|
|
|
|
|
QDomElement sizes = createElement(TagSizes);
|
2018-04-13 08:00:09 +02:00
|
|
|
sizes.setAttribute(AttrAll, trueStr);
|
2016-04-06 04:31:42 +02:00
|
|
|
element.appendChild(sizes);
|
2015-06-16 11:04:48 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-08-16 15:56:07 +02:00
|
|
|
case 5: // TagPatternName
|
2016-06-26 16:49:51 +02:00
|
|
|
element = createElement(TagPatternName);
|
|
|
|
break;
|
2017-08-16 15:56:07 +02:00
|
|
|
case 6: // TagPatternNum
|
2016-06-26 16:49:51 +02:00
|
|
|
element = createElement(TagPatternNum);
|
|
|
|
break;
|
2017-08-16 15:56:07 +02:00
|
|
|
case 7: // TagCompanyName
|
2016-06-26 16:49:51 +02:00
|
|
|
element = createElement(TagCompanyName);
|
|
|
|
break;
|
2017-08-16 15:56:07 +02:00
|
|
|
case 8: // TagCustomerName
|
2016-06-26 16:49:51 +02:00
|
|
|
element = createElement(TagCustomerName);
|
|
|
|
break;
|
2017-08-16 15:56:07 +02:00
|
|
|
case 9: // TagPatternLabel
|
2017-08-15 09:44:00 +02:00
|
|
|
element = createElement(TagPatternLabel);
|
|
|
|
break;
|
2017-08-30 07:55:07 +02:00
|
|
|
case 10: // TagPatternMaterials
|
|
|
|
element = createElement(TagPatternMaterials);
|
|
|
|
break;
|
2017-09-26 11:54:52 +02:00
|
|
|
case 11: // TagFinalMeasurements
|
|
|
|
element = createElement(TagFinalMeasurements);
|
|
|
|
break;
|
2017-03-18 10:04:12 +01:00
|
|
|
case 0: //TagUnit (Mandatory tag)
|
2015-06-16 11:04:48 +02:00
|
|
|
default:
|
2016-04-06 04:31:42 +02:00
|
|
|
return QDomElement();
|
2015-06-16 11:04:48 +02:00
|
|
|
}
|
2016-04-06 04:31:42 +02:00
|
|
|
InsertTag(tags, element);
|
|
|
|
return element;
|
2015-06-16 11:04:48 +02:00
|
|
|
}
|
2016-04-06 04:31:42 +02:00
|
|
|
return list.at(0).toElement();
|
2015-06-16 11:04:48 +02:00
|
|
|
}
|
2015-08-11 15:41:03 +02:00
|
|
|
|
2016-04-02 02:00:00 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-04-02 10:37:37 +02:00
|
|
|
void VAbstractPattern::InsertTag(const QStringList &tags, const QDomElement &element)
|
2016-04-02 02:00:00 +02:00
|
|
|
{
|
|
|
|
QDomElement pattern = documentElement();
|
|
|
|
for (int i = tags.indexOf(element.tagName())-1; i >= 0; --i)
|
|
|
|
{
|
2016-04-02 09:25:21 +02:00
|
|
|
const QDomNodeList list = elementsByTagName(tags.at(i));
|
2017-03-18 13:06:40 +01:00
|
|
|
if (not list.isEmpty())
|
2016-04-02 02:00:00 +02:00
|
|
|
{
|
2017-03-18 13:06:40 +01:00
|
|
|
pattern.insertAfter(element, list.at(0));
|
|
|
|
break;
|
2015-06-16 11:04:48 +02:00
|
|
|
}
|
|
|
|
}
|
2016-04-02 02:00:00 +02:00
|
|
|
SetVersion();
|
2015-06-16 11:04:48 +02:00
|
|
|
}
|
2015-08-11 15:41:03 +02:00
|
|
|
|
2016-05-18 14:35:07 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VAbstractPattern::GetIndexActivPP() const
|
|
|
|
{
|
|
|
|
const QDomNodeList drawList = elementsByTagName(TagDraw);
|
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
if (not drawList.isEmpty())
|
|
|
|
{
|
|
|
|
for (int i = 0; i < drawList.size(); ++i)
|
|
|
|
{
|
|
|
|
QDomElement node = drawList.at(i).toElement();
|
|
|
|
if (node.attribute(AttrName) == nameActivPP)
|
|
|
|
{
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:41:03 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VAbstractPattern::ListIncrements() const
|
|
|
|
{
|
|
|
|
QStringList increments;
|
|
|
|
|
2017-09-02 13:47:44 +02:00
|
|
|
auto GetExpressions = [&increments, this](const QString &type)
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(type);
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
2015-08-11 15:41:03 +02:00
|
|
|
{
|
2018-01-24 12:16:29 +01:00
|
|
|
const QString name = GetParametrEmptyString(list.at(i).toElement(), AttrName);
|
|
|
|
if (not name.isEmpty())
|
2017-09-02 13:47:44 +02:00
|
|
|
{
|
2018-01-24 12:16:29 +01:00
|
|
|
increments.append(name);
|
2017-09-02 13:47:44 +02:00
|
|
|
}
|
2015-08-11 15:41:03 +02:00
|
|
|
}
|
2017-09-02 13:47:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
GetExpressions(TagIncrement);
|
|
|
|
GetExpressions(TagPreviewCalculations);
|
2015-08-11 15:41:03 +02:00
|
|
|
|
|
|
|
return increments;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> VAbstractPattern::ListExpressions() const
|
2015-08-11 15:41:03 +02:00
|
|
|
{
|
2016-12-19 13:56:39 +01:00
|
|
|
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
|
2017-01-21 16:32:08 +01:00
|
|
|
// Note. Tool Union Details also contains formulas, but we don't use them for union and keep only to simplifying
|
|
|
|
// working with nodes. Same code for saving reading.
|
2018-01-24 12:16:29 +01:00
|
|
|
auto futurePointExpressions = QtConcurrent::run(this, &VAbstractPattern::ListPointExpressions);
|
|
|
|
auto futureArcExpressions = QtConcurrent::run(this, &VAbstractPattern::ListArcExpressions);
|
|
|
|
auto futureElArcExpressions = QtConcurrent::run(this, &VAbstractPattern::ListElArcExpressions);
|
|
|
|
auto futureSplineExpressions = QtConcurrent::run(this, &VAbstractPattern::ListSplineExpressions);
|
|
|
|
auto futureIncrementExpressions = QtConcurrent::run(this, &VAbstractPattern::ListIncrementExpressions);
|
|
|
|
auto futureOperationExpressions = QtConcurrent::run(this, &VAbstractPattern::ListOperationExpressions);
|
|
|
|
auto futurePathExpressions = QtConcurrent::run(this, &VAbstractPattern::ListPathExpressions);
|
|
|
|
auto futurePieceExpressions = QtConcurrent::run(this, &VAbstractPattern::ListPieceExpressions);
|
|
|
|
auto futureFinalMeasurementsExpressions = QtConcurrent::run(this,
|
|
|
|
&VAbstractPattern::ListFinalMeasurementsExpressions);
|
|
|
|
|
|
|
|
QVector<VFormulaField> list;
|
|
|
|
list << futurePointExpressions.result();
|
|
|
|
list << futureArcExpressions.result();
|
|
|
|
list << futureElArcExpressions.result();
|
|
|
|
list << futureSplineExpressions.result();
|
|
|
|
list << futureIncrementExpressions.result();
|
|
|
|
list << futureOperationExpressions.result();
|
|
|
|
list << futurePathExpressions.result();
|
|
|
|
list << futurePieceExpressions.result();
|
|
|
|
list << futureFinalMeasurementsExpressions.result();
|
2015-08-11 15:41:03 +02:00
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> VAbstractPattern::ListPointExpressions() const
|
2015-08-11 15:41:03 +02:00
|
|
|
{
|
2016-05-16 21:14:59 +02:00
|
|
|
// Check if new tool doesn't bring new attribute with a formula.
|
2016-12-19 13:56:39 +01:00
|
|
|
// If no just increment a number.
|
|
|
|
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
|
2017-10-25 16:49:04 +02:00
|
|
|
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 55);
|
2016-05-16 21:14:59 +02:00
|
|
|
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> expressions;
|
2015-08-11 15:41:03 +02:00
|
|
|
const QDomNodeList list = elementsByTagName(TagPoint);
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement dom = list.at(i).toElement();
|
|
|
|
|
2016-01-11 12:28:48 +01:00
|
|
|
// Each tag can contains several attributes.
|
2017-08-08 16:43:41 +02:00
|
|
|
ReadExpressionAttribute(expressions, dom, AttrLength);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrAngle);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrC1Radius);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrC2Radius);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrCRadius);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrRadius);
|
2017-10-15 11:25:20 +02:00
|
|
|
ReadExpressionAttribute(expressions, dom, AttrWidth);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrHeight);
|
2015-08-11 15:41:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return expressions;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> VAbstractPattern::ListArcExpressions() const
|
2015-08-11 15:41:03 +02:00
|
|
|
{
|
2016-05-16 21:14:59 +02:00
|
|
|
// Check if new tool doesn't bring new attribute with a formula.
|
2016-12-19 13:56:39 +01:00
|
|
|
// If no just increment number.
|
|
|
|
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
|
2017-10-25 16:49:04 +02:00
|
|
|
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 55);
|
2016-05-16 21:14:59 +02:00
|
|
|
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> expressions;
|
2015-08-27 10:25:11 +02:00
|
|
|
const QDomNodeList list = elementsByTagName(TagArc);
|
2015-08-11 15:41:03 +02:00
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement dom = list.at(i).toElement();
|
|
|
|
|
2017-08-08 16:43:41 +02:00
|
|
|
// Each tag can contains several attributes.
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrAngle1);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrAngle2);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrRadius);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrLength);
|
2015-08-11 15:41:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return expressions;
|
|
|
|
}
|
|
|
|
|
2016-12-19 13:56:39 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> VAbstractPattern::ListElArcExpressions() const
|
2016-12-19 13:56:39 +01:00
|
|
|
{
|
|
|
|
// Check if new tool doesn't bring new attribute with a formula.
|
|
|
|
// If no just increment number.
|
|
|
|
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
|
2017-10-25 16:49:04 +02:00
|
|
|
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 55);
|
2016-12-19 13:56:39 +01:00
|
|
|
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> expressions;
|
2016-12-19 13:56:39 +01:00
|
|
|
const QDomNodeList list = elementsByTagName(TagElArc);
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement dom = list.at(i).toElement();
|
|
|
|
|
2017-08-08 16:43:41 +02:00
|
|
|
// Each tag can contains several attributes.
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrRadius1);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrRadius2);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrAngle1);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrAngle2);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrRotationAngle);
|
2016-12-19 13:56:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return expressions;
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:41:03 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> VAbstractPattern::ListSplineExpressions() const
|
2015-08-11 15:41:03 +02:00
|
|
|
{
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> expressions;
|
2015-08-11 15:41:03 +02:00
|
|
|
expressions << ListPathPointExpressions();
|
|
|
|
return expressions;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> VAbstractPattern::ListPathPointExpressions() const
|
2015-08-11 15:41:03 +02:00
|
|
|
{
|
2016-05-16 21:14:59 +02:00
|
|
|
// Check if new tool doesn't bring new attribute with a formula.
|
2016-12-19 13:56:39 +01:00
|
|
|
// If no just increment number.
|
|
|
|
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
|
2017-10-25 16:49:04 +02:00
|
|
|
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 55);
|
2016-05-16 21:14:59 +02:00
|
|
|
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> expressions;
|
2015-08-27 10:25:11 +02:00
|
|
|
const QDomNodeList list = elementsByTagName(AttrPathPoint);
|
2015-08-11 15:41:03 +02:00
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement dom = list.at(i).toElement();
|
|
|
|
|
2017-08-08 16:43:41 +02:00
|
|
|
// Each tag can contains several attributes.
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrKAsm1);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrKAsm2);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrAngle);
|
2015-08-11 15:41:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return expressions;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> VAbstractPattern::ListIncrementExpressions() const
|
2015-09-16 07:16:27 +02:00
|
|
|
{
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> expressions;
|
2015-09-16 07:16:27 +02:00
|
|
|
const QDomNodeList list = elementsByTagName(TagIncrement);
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement dom = list.at(i).toElement();
|
|
|
|
|
2017-09-26 11:54:52 +02:00
|
|
|
ReadExpressionAttribute(expressions, dom, AttrFormula);
|
2015-09-16 07:16:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return expressions;
|
|
|
|
}
|
|
|
|
|
2016-05-16 20:11:48 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> VAbstractPattern::ListOperationExpressions() const
|
2016-05-16 20:11:48 +02:00
|
|
|
{
|
2016-05-16 21:14:59 +02:00
|
|
|
// Check if new tool doesn't bring new attribute with a formula.
|
2016-12-19 13:56:39 +01:00
|
|
|
// If no just increment number.
|
|
|
|
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
|
2017-10-25 16:49:04 +02:00
|
|
|
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 55);
|
2016-05-16 21:14:59 +02:00
|
|
|
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> expressions;
|
2016-05-16 20:11:48 +02:00
|
|
|
const QDomNodeList list = elementsByTagName(TagOperation);
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement dom = list.at(i).toElement();
|
|
|
|
|
|
|
|
// Each tag can contains several attributes.
|
2017-08-08 16:43:41 +02:00
|
|
|
ReadExpressionAttribute(expressions, dom, AttrAngle);
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrLength);
|
2016-05-16 20:11:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return expressions;
|
|
|
|
}
|
|
|
|
|
2017-01-21 16:32:08 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> VAbstractPattern::ListNodesExpressions(const QDomElement &nodes) const
|
2017-01-21 16:32:08 +01:00
|
|
|
{
|
2017-08-08 16:43:41 +02:00
|
|
|
// Check if new tool doesn't bring new attribute with a formula.
|
|
|
|
// If no just increment number.
|
|
|
|
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
|
2017-10-25 16:49:04 +02:00
|
|
|
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 55);
|
2017-08-08 16:43:41 +02:00
|
|
|
|
|
|
|
QVector<VFormulaField> expressions;
|
2017-01-21 16:32:08 +01:00
|
|
|
|
2017-08-08 16:43:41 +02:00
|
|
|
const QDomNodeList nodeList = nodes.childNodes();
|
|
|
|
for (qint32 i = 0; i < nodeList.size(); ++i)
|
2017-01-21 16:32:08 +01:00
|
|
|
{
|
2017-08-08 16:43:41 +02:00
|
|
|
const QDomElement element = nodeList.at(i).toElement();
|
|
|
|
if (not element.isNull() && element.tagName() == VAbstractPattern::TagNode)
|
|
|
|
{
|
|
|
|
ReadExpressionAttribute(expressions, element, VAbstractPattern::AttrSABefore);
|
|
|
|
ReadExpressionAttribute(expressions, element, VAbstractPattern::AttrSAAfter);
|
2019-04-18 11:59:19 +02:00
|
|
|
ReadExpressionAttribute(expressions, element, VAbstractPattern::AttrPassmarkLength);
|
2017-08-08 16:43:41 +02:00
|
|
|
}
|
2017-01-21 16:32:08 +01:00
|
|
|
}
|
|
|
|
return expressions;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> VAbstractPattern::ListPathExpressions() const
|
2017-01-21 16:32:08 +01:00
|
|
|
{
|
|
|
|
// Check if new tool doesn't bring new attribute with a formula.
|
|
|
|
// If no just increment number.
|
|
|
|
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
|
2017-10-25 16:49:04 +02:00
|
|
|
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 55);
|
2017-01-21 16:32:08 +01:00
|
|
|
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> expressions;
|
2017-01-21 16:32:08 +01:00
|
|
|
const QDomNodeList list = elementsByTagName(TagPath);
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement dom = list.at(i).toElement();
|
|
|
|
if (dom.isNull())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
expressions << ListNodesExpressions(dom.firstChildElement(TagNodes));
|
|
|
|
}
|
|
|
|
|
|
|
|
return expressions;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> VAbstractPattern::ListGrainlineExpressions(const QDomElement &element) const
|
2017-01-21 16:32:08 +01:00
|
|
|
{
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> expressions;
|
2017-01-21 16:32:08 +01:00
|
|
|
if (not element.isNull())
|
|
|
|
{
|
|
|
|
// Each tag can contains several attributes.
|
2017-08-08 16:43:41 +02:00
|
|
|
ReadExpressionAttribute(expressions, element, AttrRotation);
|
|
|
|
ReadExpressionAttribute(expressions, element, AttrLength);
|
2017-01-21 16:32:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return expressions;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> VAbstractPattern::ListPieceExpressions() const
|
2017-01-21 16:32:08 +01:00
|
|
|
{
|
|
|
|
// Check if new tool doesn't bring new attribute with a formula.
|
|
|
|
// If no just increment number.
|
|
|
|
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
|
2017-10-25 16:49:04 +02:00
|
|
|
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 55);
|
2017-01-21 16:32:08 +01:00
|
|
|
|
2017-08-08 16:43:41 +02:00
|
|
|
QVector<VFormulaField> expressions;
|
2017-01-21 16:32:08 +01:00
|
|
|
const QDomNodeList list = elementsByTagName(TagDetail);
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement dom = list.at(i).toElement();
|
|
|
|
if (dom.isNull())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Each tag can contains several attributes.
|
2017-08-08 16:43:41 +02:00
|
|
|
ReadExpressionAttribute(expressions, dom, AttrWidth);
|
2017-01-21 16:32:08 +01:00
|
|
|
|
|
|
|
expressions << ListNodesExpressions(dom.firstChildElement(TagNodes));
|
|
|
|
expressions << ListGrainlineExpressions(dom.firstChildElement(TagGrainline));
|
|
|
|
}
|
|
|
|
|
|
|
|
return expressions;
|
|
|
|
}
|
|
|
|
|
2017-09-28 15:39:27 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<VFormulaField> VAbstractPattern::ListFinalMeasurementsExpressions() const
|
|
|
|
{
|
|
|
|
QVector<VFormulaField> expressions;
|
|
|
|
const QDomNodeList list = elementsByTagName(TagFMeasurement);
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement dom = list.at(i).toElement();
|
|
|
|
if (dom.isNull())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Each tag can contains several attributes.
|
|
|
|
ReadExpressionAttribute(expressions, dom, AttrFormula);
|
|
|
|
}
|
|
|
|
|
|
|
|
return expressions;
|
|
|
|
}
|
|
|
|
|
2015-09-16 07:16:27 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-08-11 15:41:03 +02:00
|
|
|
bool VAbstractPattern::IsVariable(const QString &token) const
|
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto &var : builInVariables)
|
2015-08-11 15:41:03 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
if (token.indexOf( var ) == 0)
|
2015-08-11 15:41:03 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
if (var == currentLength || var == currentSeamAllowance)
|
2017-08-04 09:28:44 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
return token == var;
|
2017-08-04 09:28:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-11 15:41:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 21:08:53 +01:00
|
|
|
if (token.startsWith('#'))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:41:03 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VAbstractPattern::IsFunction(const QString &token) const
|
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto &fn : builInFunctions)
|
2015-08-11 15:41:03 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
if (token.indexOf(fn) == 0)
|
2015-08-11 15:41:03 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-18 12:57:03 +01:00
|
|
|
|
2016-04-06 11:03:34 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPair<bool, QMap<quint32, quint32> > VAbstractPattern::ParseItemElement(const QDomElement &domElement)
|
|
|
|
{
|
|
|
|
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const bool visible = GetParametrBool(domElement, AttrVisible, trueStr);
|
|
|
|
|
|
|
|
QMap<quint32, quint32> items;
|
|
|
|
|
|
|
|
const QDomNodeList nodeList = domElement.childNodes();
|
|
|
|
const qint32 num = nodeList.size();
|
|
|
|
for (qint32 i = 0; i < num; ++i)
|
|
|
|
{
|
|
|
|
const QDomElement element = nodeList.at(i).toElement();
|
|
|
|
if (not element.isNull() && element.tagName() == TagGroupItem)
|
|
|
|
{
|
|
|
|
const quint32 object = GetParametrUInt(element, AttrObject, NULL_ID_STR);
|
|
|
|
const quint32 tool = GetParametrUInt(element, AttrTool, NULL_ID_STR);
|
|
|
|
items.insert(object, tool);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPair<bool, QMap<quint32, quint32> > group;
|
|
|
|
group.first = visible;
|
|
|
|
group.second = items;
|
|
|
|
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
{
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating group"), domElement);
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
throw excep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 07:55:07 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QMap<int, QString> VAbstractPattern::GetMaterials(const QDomElement &element) const
|
|
|
|
{
|
|
|
|
QMap<int, QString> materials;
|
|
|
|
|
|
|
|
if (not element.isNull())
|
|
|
|
{
|
|
|
|
QDomElement tagMaterial = element.firstChildElement();
|
|
|
|
while (tagMaterial.isNull() == false)
|
|
|
|
{
|
|
|
|
if (tagMaterial.tagName() == TagMaterial)
|
|
|
|
{
|
2018-04-12 12:13:19 +02:00
|
|
|
const int number = static_cast<int>(GetParametrUInt(tagMaterial, AttrNumber, QChar('0')));
|
2017-08-30 07:55:07 +02:00
|
|
|
const QString name = GetParametrEmptyString(tagMaterial, AttrName);
|
|
|
|
|
|
|
|
if (number > 0 && number <= userMaterialPlaceholdersQuantity)
|
|
|
|
{
|
|
|
|
materials.insert(number, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tagMaterial = tagMaterial.nextSiblingElement(TagMaterial);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return materials;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetMaterials(QDomElement &element, const QMap<int, QString> &materials)
|
|
|
|
{
|
|
|
|
if (not element.isNull())
|
|
|
|
{
|
|
|
|
QMap<int, QString>::const_iterator i = materials.constBegin();
|
|
|
|
while (i != materials.constEnd())
|
|
|
|
{
|
|
|
|
QDomElement tagMaterial = createElement(TagMaterial);
|
|
|
|
|
|
|
|
SetAttribute(tagMaterial, AttrNumber, i.key());
|
|
|
|
SetAttribute(tagMaterial, AttrName, i.value());
|
|
|
|
|
|
|
|
element.appendChild(tagMaterial);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-26 11:54:52 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<VFinalMeasurement> VAbstractPattern::GetFMeasurements(const QDomElement &element) const
|
|
|
|
{
|
|
|
|
QVector<VFinalMeasurement> measurements;
|
|
|
|
|
|
|
|
if (not element.isNull())
|
|
|
|
{
|
|
|
|
QDomElement tagFMeasurement = element.firstChildElement();
|
|
|
|
while (not tagFMeasurement.isNull())
|
|
|
|
{
|
|
|
|
if (tagFMeasurement.tagName() == TagFMeasurement)
|
|
|
|
{
|
|
|
|
VFinalMeasurement m;
|
|
|
|
|
|
|
|
m.name = GetParametrString(tagFMeasurement, AttrName, tr("measurement"));
|
2018-04-12 12:13:19 +02:00
|
|
|
m.formula = GetParametrString(tagFMeasurement, AttrFormula, QChar('0'));
|
2017-09-26 11:54:52 +02:00
|
|
|
m.description = GetParametrEmptyString(tagFMeasurement, AttrDescription);
|
|
|
|
|
|
|
|
measurements.append(m);
|
|
|
|
}
|
|
|
|
tagFMeasurement = tagFMeasurement.nextSiblingElement(TagFMeasurement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return measurements;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetFMeasurements(QDomElement &element, const QVector<VFinalMeasurement> &measurements)
|
|
|
|
{
|
|
|
|
if (not element.isNull())
|
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto &m : measurements)
|
2017-09-26 11:54:52 +02:00
|
|
|
{
|
|
|
|
QDomElement tagFMeasurement = createElement(TagFMeasurement);
|
|
|
|
|
2018-04-03 13:36:38 +02:00
|
|
|
SetAttribute(tagFMeasurement, AttrName, m.name);
|
|
|
|
SetAttribute(tagFMeasurement, AttrFormula, m.formula);
|
2019-04-18 14:28:07 +02:00
|
|
|
SetAttributeOrRemoveIf(tagFMeasurement, AttrDescription, m.description, m.description.isEmpty());
|
2017-09-26 11:54:52 +02:00
|
|
|
|
|
|
|
element.appendChild(tagFMeasurement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-18 12:57:03 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief IsModified state of the document for cases that do not cover QUndoStack.
|
|
|
|
* @return true if the document was modified without using QUndoStack.
|
|
|
|
*/
|
|
|
|
bool VAbstractPattern::IsModified() const
|
|
|
|
{
|
|
|
|
return modified;
|
|
|
|
}
|
2016-01-07 17:43:08 +01:00
|
|
|
|
2016-01-22 11:45:18 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetModified(bool modified)
|
|
|
|
{
|
|
|
|
this->modified = modified;
|
|
|
|
}
|
|
|
|
|
2016-01-07 17:43:08 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDomElement VAbstractPattern::GetDraw(const QString &name) const
|
|
|
|
{
|
|
|
|
const QDomNodeList draws = documentElement().elementsByTagName(TagDraw);
|
|
|
|
for (int i=0; i < draws.size(); ++i)
|
|
|
|
{
|
|
|
|
QDomElement draw = draws.at(i).toElement();
|
|
|
|
if (draw.isNull())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (draw.attribute(AttrName) == name)
|
|
|
|
{
|
|
|
|
return draw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QDomElement();
|
|
|
|
}
|
2016-04-05 19:14:12 +02:00
|
|
|
|
2016-04-05 19:53:49 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDomElement VAbstractPattern::CreateGroups()
|
|
|
|
{
|
|
|
|
QDomElement draw;
|
|
|
|
if (GetActivDrawElement(draw))
|
|
|
|
{
|
|
|
|
QDomElement groups = draw.firstChildElement(TagGroups);
|
|
|
|
|
|
|
|
if (groups.isNull())
|
|
|
|
{
|
|
|
|
groups = createElement(TagGroups);
|
|
|
|
draw.appendChild(groups);
|
|
|
|
}
|
|
|
|
|
|
|
|
return groups;
|
|
|
|
}
|
|
|
|
return QDomElement();
|
|
|
|
}
|
|
|
|
|
2016-04-05 19:14:12 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-04-06 11:03:34 +02:00
|
|
|
QDomElement VAbstractPattern::CreateGroup(quint32 id, const QString &name, const QMap<quint32, quint32> &groupData)
|
2016-04-05 19:14:12 +02:00
|
|
|
{
|
2016-04-06 11:03:34 +02:00
|
|
|
if (id == NULL_ID || groupData.isEmpty())
|
2016-04-05 19:53:49 +02:00
|
|
|
{
|
2016-04-06 11:03:34 +02:00
|
|
|
return QDomElement();
|
2016-04-05 19:53:49 +02:00
|
|
|
}
|
2016-04-05 19:14:12 +02:00
|
|
|
|
2016-04-06 11:03:34 +02:00
|
|
|
QDomElement group = createElement(TagGroup);
|
2016-04-07 16:57:53 +02:00
|
|
|
SetAttribute(group, AttrId, id);
|
|
|
|
SetAttribute(group, AttrName, name);
|
|
|
|
SetAttribute(group, AttrVisible, true);
|
2016-04-05 19:53:49 +02:00
|
|
|
|
2016-04-06 11:03:34 +02:00
|
|
|
auto i = groupData.constBegin();
|
|
|
|
while (i != groupData.constEnd())
|
2016-04-05 19:53:49 +02:00
|
|
|
{
|
2016-04-06 11:03:34 +02:00
|
|
|
QDomElement item = createElement(TagGroupItem);
|
2016-04-05 19:53:49 +02:00
|
|
|
item.setAttribute(AttrObject, i.key());
|
|
|
|
item.setAttribute(AttrTool, i.value());
|
2016-04-06 11:03:34 +02:00
|
|
|
group.appendChild(item);
|
2016-04-05 19:53:49 +02:00
|
|
|
++i;
|
|
|
|
}
|
2016-04-06 11:03:34 +02:00
|
|
|
|
|
|
|
return group;
|
2016-04-05 19:14:12 +02:00
|
|
|
}
|
2016-04-06 11:36:33 +02:00
|
|
|
|
2016-04-07 16:57:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractPattern::GetGroupName(quint32 id)
|
|
|
|
{
|
|
|
|
QString name = tr("New group");
|
|
|
|
QDomElement groups = CreateGroups();
|
|
|
|
if (not groups.isNull())
|
|
|
|
{
|
2017-08-02 13:10:10 +02:00
|
|
|
QDomElement group = elementById(id, TagGroup);
|
2016-04-07 16:57:53 +02:00
|
|
|
if (group.isElement())
|
|
|
|
{
|
|
|
|
name = GetParametrString(group, AttrName, name);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (groups.childNodes().isEmpty())
|
|
|
|
{
|
|
|
|
QDomNode parent = groups.parentNode();
|
|
|
|
parent.removeChild(groups);
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug("Can't get group by id = %u.", id);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("Can't get tag Groups.");
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-06 11:36:33 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractPattern::SetGroupName(quint32 id, const QString &name)
|
|
|
|
{
|
|
|
|
QDomElement groups = CreateGroups();
|
|
|
|
if (not groups.isNull())
|
|
|
|
{
|
2017-08-02 13:10:10 +02:00
|
|
|
QDomElement group = elementById(id, TagGroup);
|
2016-04-06 11:36:33 +02:00
|
|
|
if (group.isElement())
|
|
|
|
{
|
|
|
|
group.setAttribute(AttrName, name);
|
|
|
|
modified = true;
|
|
|
|
emit patternChanged(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (groups.childNodes().isEmpty())
|
|
|
|
{
|
|
|
|
QDomNode parent = groups.parentNode();
|
|
|
|
parent.removeChild(groups);
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug("Can't get group by id = %u.", id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("Can't get tag Groups.");
|
|
|
|
}
|
|
|
|
}
|
2016-04-07 16:57:53 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QMap<quint32, QPair<QString, bool> > VAbstractPattern::GetGroups()
|
|
|
|
{
|
|
|
|
QMap<quint32, QPair<QString, bool> > data;
|
|
|
|
|
2017-04-19 11:48:13 +02:00
|
|
|
try
|
2016-04-07 16:57:53 +02:00
|
|
|
{
|
2017-04-19 11:48:13 +02:00
|
|
|
QDomElement groups = CreateGroups();
|
|
|
|
if (not groups.isNull())
|
2016-04-07 16:57:53 +02:00
|
|
|
{
|
2017-04-19 11:48:13 +02:00
|
|
|
QDomNode domNode = groups.firstChild();
|
|
|
|
while (domNode.isNull() == false)
|
2016-04-07 16:57:53 +02:00
|
|
|
{
|
2017-04-19 11:48:13 +02:00
|
|
|
if (domNode.isElement())
|
2016-04-07 16:57:53 +02:00
|
|
|
{
|
2017-04-19 11:48:13 +02:00
|
|
|
const QDomElement group = domNode.toElement();
|
|
|
|
if (group.isNull() == false)
|
2016-04-07 16:57:53 +02:00
|
|
|
{
|
2017-04-19 11:48:13 +02:00
|
|
|
if (group.tagName() == TagGroup)
|
|
|
|
{
|
2018-04-12 12:13:19 +02:00
|
|
|
const quint32 id = GetParametrUInt(group, AttrId, QChar('0'));
|
2017-04-19 11:48:13 +02:00
|
|
|
const bool visible = GetParametrBool(group, AttrVisible, trueStr);
|
|
|
|
const QString name = GetParametrString(group, AttrName, tr("New group"));
|
2016-04-07 16:57:53 +02:00
|
|
|
|
2017-04-19 11:48:13 +02:00
|
|
|
data.insert(id, qMakePair(name, visible));
|
|
|
|
}
|
2016-04-07 16:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-19 11:48:13 +02:00
|
|
|
domNode = domNode.nextSibling();
|
2016-04-07 16:57:53 +02:00
|
|
|
}
|
2017-04-19 11:48:13 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("Can't get tag Groups.");
|
2016-04-07 16:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-19 11:48:13 +02:00
|
|
|
catch (const VExceptionConversionError &)
|
2016-04-07 16:57:53 +02:00
|
|
|
{
|
2017-04-19 11:48:13 +02:00
|
|
|
return QMap<quint32, QPair<QString, bool> >();
|
2016-04-07 16:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2018-03-24 23:42:17 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief Returns the groups that contain or do not contain the item identified by the toolid and the objectid
|
2018-04-09 10:51:25 +02:00
|
|
|
* @param toolId tool id
|
|
|
|
* @param objectId object id
|
2018-03-25 16:43:28 +02:00
|
|
|
* @param containItem |true if the groups have to contain the given item, false if they musn't contain the item
|
2018-04-09 10:51:25 +02:00
|
|
|
* @return groups that contain or do not contain the item identified by the toolid and the objectid
|
2018-03-24 23:42:17 +01:00
|
|
|
*/
|
|
|
|
QMap<quint32, QString> VAbstractPattern::GetGroupsContainingItem(quint32 toolId, quint32 objectId, bool containItem)
|
|
|
|
{
|
|
|
|
QMap<quint32, QString> data;
|
|
|
|
|
|
|
|
if(objectId == 0)
|
|
|
|
{
|
|
|
|
objectId = toolId;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO : order in alphabetical order
|
|
|
|
|
|
|
|
QDomElement groups = CreateGroups();
|
|
|
|
if (not groups.isNull())
|
|
|
|
{
|
|
|
|
QDomNode domNode = groups.firstChild();
|
|
|
|
while (domNode.isNull() == false) // iterate through the groups
|
|
|
|
{
|
|
|
|
if (domNode.isElement())
|
|
|
|
{
|
|
|
|
const QDomElement group = domNode.toElement();
|
|
|
|
if (group.isNull() == false)
|
|
|
|
{
|
2018-03-25 16:43:28 +02:00
|
|
|
if (group.tagName() == TagGroup)
|
2018-03-24 23:42:17 +01:00
|
|
|
{
|
|
|
|
bool groupHasItem = GroupHasItem(group, toolId, objectId);
|
|
|
|
if((containItem && groupHasItem) || (not containItem && not groupHasItem))
|
|
|
|
{
|
2018-04-12 12:13:19 +02:00
|
|
|
const quint32 groupId = GetParametrUInt(group, AttrId, QChar('0'));
|
2018-03-24 23:42:17 +01:00
|
|
|
const QString name = GetParametrString(group, AttrName, tr("New group"));
|
|
|
|
data.insert(groupId, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
domNode = domNode.nextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("Can't get tag Groups.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief Checks if the given group has the item with the given toolId and objectId
|
2018-04-09 10:51:25 +02:00
|
|
|
* @param groupDomElement group dom element
|
|
|
|
* @param toolId tool id
|
|
|
|
* @param objectId object id
|
|
|
|
* @return true if the given group has the item with the given toolId and objectId
|
2018-03-24 23:42:17 +01:00
|
|
|
*/
|
|
|
|
bool VAbstractPattern::GroupHasItem(const QDomElement &groupDomElement, quint32 toolId, quint32 objectId)
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
QDomNode itemNode = groupDomElement.firstChild();
|
|
|
|
while (itemNode.isNull() == false) // iterate through the items of the group
|
|
|
|
{
|
|
|
|
if (itemNode.isElement())
|
|
|
|
{
|
|
|
|
const QDomElement item = itemNode.toElement();
|
|
|
|
if (item.isNull() == false)
|
|
|
|
{
|
2018-04-12 12:13:19 +02:00
|
|
|
quint32 toolIdIterate= GetParametrUInt(item, AttrTool, QChar('0'));
|
|
|
|
quint32 objectIdIterate= GetParametrUInt(item, AttrObject, QChar('0'));
|
2018-03-24 23:42:17 +01:00
|
|
|
|
|
|
|
if(toolIdIterate == toolId && objectIdIterate == objectId)
|
|
|
|
{
|
|
|
|
result = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
itemNode = itemNode.nextSibling();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief Adds an item to the given group with the given toolId and objectId
|
2018-04-09 10:51:25 +02:00
|
|
|
* @param toolId tool id
|
|
|
|
* @param objectId object id
|
|
|
|
* @param groupId group id
|
|
|
|
* @return group element
|
2018-03-24 23:42:17 +01:00
|
|
|
*/
|
2018-03-31 11:50:08 +02:00
|
|
|
QDomElement VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, quint32 groupId)
|
2018-03-24 23:42:17 +01:00
|
|
|
{
|
|
|
|
QDomElement group = elementById(groupId, TagGroup);
|
|
|
|
|
2018-03-25 16:43:28 +02:00
|
|
|
if (group.isNull() == false)
|
2018-03-24 23:42:17 +01:00
|
|
|
{
|
2018-03-25 16:43:28 +02:00
|
|
|
if(objectId == 0)
|
|
|
|
{
|
|
|
|
objectId = toolId;
|
|
|
|
}
|
2018-03-24 23:42:17 +01:00
|
|
|
|
2018-03-25 16:43:28 +02:00
|
|
|
QDomElement item = createElement(TagGroupItem);
|
|
|
|
item.setAttribute(AttrTool, toolId);
|
|
|
|
item.setAttribute(AttrObject, objectId);
|
|
|
|
group.appendChild(item);
|
|
|
|
|
2018-03-30 12:56:37 +02:00
|
|
|
// to signalised that the pattern was changed and need to be saved
|
2018-03-30 11:02:10 +02:00
|
|
|
modified = true;
|
|
|
|
emit patternChanged(false);
|
2018-03-30 12:56:37 +02:00
|
|
|
|
|
|
|
// to update the group table of the gui
|
2018-03-25 16:43:28 +02:00
|
|
|
emit UpdateGroups();
|
2018-03-30 12:56:37 +02:00
|
|
|
|
|
|
|
// parse the groups to update the drawing, in case the item was added to an invisible group
|
|
|
|
QDomElement groups = CreateGroups();
|
|
|
|
if (not groups.isNull())
|
|
|
|
{
|
|
|
|
ParseGroups(groups);
|
|
|
|
}
|
2018-03-31 11:50:08 +02:00
|
|
|
|
|
|
|
return item;
|
2018-03-25 16:43:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug() << "The group of id " << groupId << " doesn't exist";
|
|
|
|
}
|
2018-04-01 17:19:10 +02:00
|
|
|
|
|
|
|
return QDomElement();
|
2018-03-24 23:42:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief Removes the item of given toolId and objectId from the group of given groupId
|
2018-04-09 10:51:25 +02:00
|
|
|
* @param toolId tool id
|
|
|
|
* @param objectId object id
|
|
|
|
* @param groupId group id
|
|
|
|
* @return item element or null element is none
|
2018-03-24 23:42:17 +01:00
|
|
|
*/
|
2018-03-31 11:50:08 +02:00
|
|
|
QDomElement VAbstractPattern::RemoveItemFromGroup(quint32 toolId, quint32 objectId, quint32 groupId)
|
2018-03-24 23:42:17 +01:00
|
|
|
{
|
|
|
|
QDomElement group = elementById(groupId, TagGroup);
|
|
|
|
|
2018-03-25 16:43:28 +02:00
|
|
|
if (group.isNull() == false)
|
2018-03-24 23:42:17 +01:00
|
|
|
{
|
2018-03-25 16:43:28 +02:00
|
|
|
if(objectId == 0)
|
|
|
|
{
|
|
|
|
objectId = toolId;
|
|
|
|
}
|
2018-03-24 23:42:17 +01:00
|
|
|
|
2018-03-25 16:43:28 +02:00
|
|
|
QDomNode itemNode = group.firstChild();
|
|
|
|
while (itemNode.isNull() == false) // iterate through the items of the group
|
2018-03-24 23:42:17 +01:00
|
|
|
{
|
2018-03-25 16:43:28 +02:00
|
|
|
if (itemNode.isElement())
|
2018-03-24 23:42:17 +01:00
|
|
|
{
|
2018-03-25 16:43:28 +02:00
|
|
|
const QDomElement item = itemNode.toElement();
|
|
|
|
if (item.isNull() == false)
|
2018-03-24 23:42:17 +01:00
|
|
|
{
|
2018-04-12 12:13:19 +02:00
|
|
|
quint32 toolIdIterate= GetParametrUInt(item, AttrTool, QChar('0'));
|
|
|
|
quint32 objectIdIterate= GetParametrUInt(item, AttrObject, QChar('0'));
|
2018-03-25 16:43:28 +02:00
|
|
|
|
|
|
|
if(toolIdIterate == toolId && objectIdIterate == objectId)
|
|
|
|
{
|
|
|
|
group.removeChild(itemNode);
|
2018-03-30 11:02:10 +02:00
|
|
|
|
2018-03-30 12:56:37 +02:00
|
|
|
// to signalised that the pattern was changed and need to be saved
|
2018-03-30 11:02:10 +02:00
|
|
|
modified = true;
|
|
|
|
emit patternChanged(false);
|
2018-03-30 12:56:37 +02:00
|
|
|
|
|
|
|
// to update the group table of the gui
|
2018-03-25 16:43:28 +02:00
|
|
|
emit UpdateGroups();
|
2018-03-30 12:56:37 +02:00
|
|
|
|
|
|
|
// parse the groups to update the drawing, in case the item was removed from an invisible group
|
|
|
|
QDomElement groups = CreateGroups();
|
|
|
|
if (not groups.isNull())
|
|
|
|
{
|
|
|
|
ParseGroups(groups);
|
|
|
|
}
|
|
|
|
|
2018-04-01 17:19:10 +02:00
|
|
|
return item;
|
2018-03-25 16:43:28 +02:00
|
|
|
}
|
2018-03-24 23:42:17 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-25 16:43:28 +02:00
|
|
|
itemNode = itemNode.nextSibling();
|
2018-03-24 23:42:17 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-25 16:43:28 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug() << "The group of id " << groupId << " doesn't exist";
|
|
|
|
}
|
2018-04-01 17:19:10 +02:00
|
|
|
|
|
|
|
return QDomElement();
|
2018-03-25 16:43:28 +02:00
|
|
|
}
|
2018-03-24 23:42:17 +01:00
|
|
|
|
2018-03-25 16:43:28 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief Returns true if the given group is empty
|
2018-04-09 10:51:25 +02:00
|
|
|
* @param id group id
|
|
|
|
* @return true if the given group is empty
|
2018-03-25 16:43:28 +02:00
|
|
|
*/
|
|
|
|
bool VAbstractPattern::GroupIsEmpty(quint32 id)
|
|
|
|
{
|
|
|
|
QDomElement group = elementById(id, TagGroup);
|
|
|
|
|
|
|
|
if (group.isNull() == false)
|
|
|
|
{
|
|
|
|
return not group.hasChildNodes();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug() << "The group of id " << id << " doesn't exist";
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-24 23:42:17 +01:00
|
|
|
}
|
|
|
|
|
2016-04-07 16:57:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VAbstractPattern::GetGroupVisivility(quint32 id)
|
|
|
|
{
|
2017-08-02 13:10:10 +02:00
|
|
|
QDomElement group = elementById(id, TagGroup);
|
2016-04-07 16:57:53 +02:00
|
|
|
if (group.isElement())
|
|
|
|
{
|
|
|
|
return GetParametrBool(group, AttrVisible, trueStr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("Can't get group by id = %u.", id);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-26 15:57:52 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractPattern::PieceDrawName(quint32 id)
|
|
|
|
{
|
|
|
|
const QDomElement detail = elementById(id, VAbstractPattern::TagDetail);
|
|
|
|
if (detail.isNull())
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDomElement draw = detail.parentNode().parentNode().toElement();
|
|
|
|
if (draw.isNull() || not draw.hasAttribute(VAbstractPattern::AttrName))
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return draw.attribute(VAbstractPattern::AttrName);
|
|
|
|
}
|