2014-02-25 15:02:09 +01:00
|
|
|
|
/************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** @file vpattern.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2014-02-25 15:02:09 +01:00
|
|
|
|
** @date 24 2, 2014
|
|
|
|
|
**
|
|
|
|
|
** @brief
|
|
|
|
|
** @copyright
|
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
|
** Copyright (C) 2013 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 "vpattern.h"
|
2014-06-08 20:10:57 +02:00
|
|
|
|
#include "../tools/vdatatool.h"
|
2014-02-25 15:02:09 +01:00
|
|
|
|
#include "../tools/vtooldetail.h"
|
|
|
|
|
#include "../tools/vtooluniondetails.h"
|
|
|
|
|
#include "../tools/drawTools/drawtools.h"
|
|
|
|
|
#include "../tools/nodeDetails/nodedetails.h"
|
|
|
|
|
#include "../exception/vexceptionobjecterror.h"
|
2014-03-03 18:32:38 +01:00
|
|
|
|
#include "../exception/vexceptionwrongid.h"
|
2014-03-14 16:59:28 +01:00
|
|
|
|
#include "../exception/vexceptionconversionerror.h"
|
2014-06-08 20:10:57 +02:00
|
|
|
|
#include "../exception/vexceptionemptyparameter.h"
|
2014-06-24 10:23:39 +02:00
|
|
|
|
#include "../exception/vexceptionundo.h"
|
2014-09-25 17:44:06 +02:00
|
|
|
|
#include "../core/undoevent.h"
|
2014-03-24 16:02:57 +01:00
|
|
|
|
#include "vstandardmeasurements.h"
|
|
|
|
|
#include "vindividualmeasurements.h"
|
2014-05-29 09:08:54 +02:00
|
|
|
|
#include "../../libs/qmuparser/qmuparsererror.h"
|
2014-06-08 20:10:57 +02:00
|
|
|
|
#include "../geometry/varc.h"
|
2014-08-07 14:03:24 +02:00
|
|
|
|
|
2014-06-08 20:10:57 +02:00
|
|
|
|
#include <QMessageBox>
|
2014-07-13 14:49:00 +02:00
|
|
|
|
#include <QUndoStack>
|
2014-10-03 12:32:12 +02:00
|
|
|
|
#include <QtCore/qmath.h>
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-03-16 07:32:52 +01:00
|
|
|
|
const QString VPattern::TagPattern = QStringLiteral("pattern");
|
|
|
|
|
const QString VPattern::TagCalculation = QStringLiteral("calculation");
|
|
|
|
|
const QString VPattern::TagModeling = QStringLiteral("modeling");
|
|
|
|
|
const QString VPattern::TagDetails = QStringLiteral("details");
|
|
|
|
|
const QString VPattern::TagAuthor = QStringLiteral("author");
|
|
|
|
|
const QString VPattern::TagDescription = QStringLiteral("description");
|
|
|
|
|
const QString VPattern::TagNotes = QStringLiteral("notes");
|
|
|
|
|
const QString VPattern::TagMeasurements = QStringLiteral("measurements");
|
|
|
|
|
const QString VPattern::TagIncrements = QStringLiteral("increments");
|
|
|
|
|
const QString VPattern::TagIncrement = QStringLiteral("increment");
|
|
|
|
|
const QString VPattern::TagDraw = QStringLiteral("draw");
|
|
|
|
|
const QString VPattern::TagPoint = QStringLiteral("point");
|
|
|
|
|
const QString VPattern::TagLine = QStringLiteral("line");
|
|
|
|
|
const QString VPattern::TagSpline = QStringLiteral("spline");
|
|
|
|
|
const QString VPattern::TagArc = QStringLiteral("arc");
|
|
|
|
|
const QString VPattern::TagTools = QStringLiteral("tools");
|
2014-08-07 13:17:24 +02:00
|
|
|
|
const QString VPattern::TagGradation = QStringLiteral("gradation");
|
|
|
|
|
const QString VPattern::TagHeights = QStringLiteral("heights");
|
|
|
|
|
const QString VPattern::TagSizes = QStringLiteral("sizes");
|
2014-02-25 19:03:17 +01:00
|
|
|
|
|
2014-03-16 07:32:52 +01:00
|
|
|
|
const QString VPattern::AttrName = QStringLiteral("name");
|
|
|
|
|
const QString VPattern::AttrType = QStringLiteral("type");
|
2014-03-21 11:08:29 +01:00
|
|
|
|
const QString VPattern::AttrPath = QStringLiteral("path");
|
2014-02-25 19:03:17 +01:00
|
|
|
|
|
2014-08-07 13:17:24 +02:00
|
|
|
|
const QString VPattern::AttrAll = QStringLiteral("all");
|
|
|
|
|
|
|
|
|
|
const QString VPattern::AttrH92 = QStringLiteral("h92");
|
|
|
|
|
const QString VPattern::AttrH98 = QStringLiteral("h98");
|
|
|
|
|
const QString VPattern::AttrH104 = QStringLiteral("h104");
|
|
|
|
|
const QString VPattern::AttrH110 = QStringLiteral("h110");
|
|
|
|
|
const QString VPattern::AttrH116 = QStringLiteral("h116");
|
|
|
|
|
const QString VPattern::AttrH122 = QStringLiteral("h122");
|
|
|
|
|
const QString VPattern::AttrH128 = QStringLiteral("h128");
|
|
|
|
|
const QString VPattern::AttrH134 = QStringLiteral("h134");
|
|
|
|
|
const QString VPattern::AttrH140 = QStringLiteral("h140");
|
|
|
|
|
const QString VPattern::AttrH146 = QStringLiteral("h146");
|
|
|
|
|
const QString VPattern::AttrH152 = QStringLiteral("h152");
|
|
|
|
|
const QString VPattern::AttrH158 = QStringLiteral("h158");
|
|
|
|
|
const QString VPattern::AttrH164 = QStringLiteral("h164");
|
|
|
|
|
const QString VPattern::AttrH170 = QStringLiteral("h170");
|
|
|
|
|
const QString VPattern::AttrH176 = QStringLiteral("h176");
|
|
|
|
|
const QString VPattern::AttrH182 = QStringLiteral("h182");
|
|
|
|
|
const QString VPattern::AttrH188 = QStringLiteral("h188");
|
2014-08-07 16:05:37 +02:00
|
|
|
|
const QString VPattern::AttrH194 = QStringLiteral("h194");
|
2014-08-07 13:17:24 +02:00
|
|
|
|
|
|
|
|
|
const QString VPattern::AttrS22 = QStringLiteral("s22");
|
|
|
|
|
const QString VPattern::AttrS24 = QStringLiteral("s24");
|
|
|
|
|
const QString VPattern::AttrS26 = QStringLiteral("s26");
|
|
|
|
|
const QString VPattern::AttrS28 = QStringLiteral("s28");
|
|
|
|
|
const QString VPattern::AttrS30 = QStringLiteral("s30");
|
|
|
|
|
const QString VPattern::AttrS32 = QStringLiteral("s32");
|
|
|
|
|
const QString VPattern::AttrS34 = QStringLiteral("s34");
|
|
|
|
|
const QString VPattern::AttrS36 = QStringLiteral("s36");
|
|
|
|
|
const QString VPattern::AttrS38 = QStringLiteral("s38");
|
|
|
|
|
const QString VPattern::AttrS40 = QStringLiteral("s40");
|
|
|
|
|
const QString VPattern::AttrS42 = QStringLiteral("s42");
|
|
|
|
|
const QString VPattern::AttrS44 = QStringLiteral("s44");
|
|
|
|
|
const QString VPattern::AttrS46 = QStringLiteral("s46");
|
|
|
|
|
const QString VPattern::AttrS48 = QStringLiteral("s48");
|
|
|
|
|
const QString VPattern::AttrS50 = QStringLiteral("s50");
|
|
|
|
|
const QString VPattern::AttrS52 = QStringLiteral("s52");
|
|
|
|
|
const QString VPattern::AttrS54 = QStringLiteral("s54");
|
|
|
|
|
const QString VPattern::AttrS56 = QStringLiteral("s56");
|
|
|
|
|
|
2014-02-25 19:03:17 +01:00
|
|
|
|
const QString VPattern::IncrementName = QStringLiteral("name");
|
|
|
|
|
const QString VPattern::IncrementBase = QStringLiteral("base");
|
|
|
|
|
const QString VPattern::IncrementKsize = QStringLiteral("ksize");
|
|
|
|
|
const QString VPattern::IncrementKgrowth = QStringLiteral("kgrowth");
|
|
|
|
|
const QString VPattern::IncrementDescription = QStringLiteral("description");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-12 09:22:29 +02:00
|
|
|
|
VPattern::VPattern(VContainer *data, Draw *mode, VMainGraphicsScene *sceneDraw,
|
2014-06-05 13:35:38 +02:00
|
|
|
|
VMainGraphicsScene *sceneDetail, QObject *parent)
|
2014-07-17 14:41:48 +02:00
|
|
|
|
: QObject(parent), VDomDocument(data), nameActivPP(QString()), tools(QHash<quint32, VDataTool*>()),
|
2014-06-09 15:13:15 +02:00
|
|
|
|
history(QVector<VToolRecord>()), cursor(0), patternPieces(QStringList()), mode(mode), sceneDraw(sceneDraw),
|
|
|
|
|
sceneDetail(sceneDetail)
|
2014-06-05 13:35:38 +02:00
|
|
|
|
{
|
|
|
|
|
SCASSERT(sceneDraw != nullptr);
|
|
|
|
|
SCASSERT(sceneDetail != nullptr);
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief CreateEmptyFile create minimal empty file.
|
|
|
|
|
* @param tablePath path to measurement file (standard or individual)
|
|
|
|
|
*/
|
2014-03-16 07:32:52 +01:00
|
|
|
|
void VPattern::CreateEmptyFile(const QString &tablePath)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-03-16 07:32:52 +01:00
|
|
|
|
if (tablePath.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
throw VException("Path to measurement table empty.");
|
|
|
|
|
}
|
2014-06-06 17:06:41 +02:00
|
|
|
|
this->clear();
|
2014-02-25 19:03:17 +01:00
|
|
|
|
QDomElement patternElement = this->createElement(TagPattern);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
|
|
|
|
patternElement.appendChild(createComment("Valentina pattern format."));
|
2014-05-21 16:40:21 +02:00
|
|
|
|
|
|
|
|
|
QDomElement version = createElement(TagVersion);
|
|
|
|
|
QDomText newNodeText = createTextNode(VAL_STR_VERSION);
|
|
|
|
|
version.appendChild(newNodeText);
|
2014-06-09 19:47:25 +02:00
|
|
|
|
patternElement.appendChild(version);
|
2014-05-21 16:40:21 +02:00
|
|
|
|
|
2014-02-25 15:02:09 +01:00
|
|
|
|
patternElement.appendChild(createElement(TagAuthor));
|
|
|
|
|
patternElement.appendChild(createElement(TagDescription));
|
|
|
|
|
patternElement.appendChild(createElement(TagNotes));
|
2014-03-16 07:32:52 +01:00
|
|
|
|
|
|
|
|
|
QDomElement measurements = createElement(TagMeasurements);
|
2014-03-24 16:02:57 +01:00
|
|
|
|
SetAttribute(measurements, AttrUnit, UnitsToStr(qApp->patternUnit()));
|
2014-03-21 11:08:29 +01:00
|
|
|
|
SetAttribute(measurements, AttrType, qApp->patternType());
|
|
|
|
|
SetAttribute(measurements, AttrPath, tablePath);
|
2014-03-16 07:32:52 +01:00
|
|
|
|
patternElement.appendChild(measurements);
|
|
|
|
|
|
2014-02-25 15:02:09 +01:00
|
|
|
|
patternElement.appendChild(createElement(TagIncrements));
|
|
|
|
|
|
|
|
|
|
this->appendChild(patternElement);
|
|
|
|
|
insertBefore(createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""), this->firstChild());
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
2014-06-06 17:06:41 +02:00
|
|
|
|
* @brief ChangeActivPP set new active pattern piece name.
|
2014-06-05 12:02:35 +02:00
|
|
|
|
* @param name new name.
|
|
|
|
|
* @param parse parser file mode.
|
|
|
|
|
*/
|
2014-06-12 09:22:29 +02:00
|
|
|
|
void VPattern::ChangeActivPP(const QString &name, const Document &parse)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-06-06 17:06:41 +02:00
|
|
|
|
Q_ASSERT_X(name.isEmpty() == false, "ChangeActivPP", "name pattern piece is empty");
|
2014-07-17 14:41:48 +02:00
|
|
|
|
if (CheckExistNamePP(name) && this->nameActivPP != name)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-07-17 14:41:48 +02:00
|
|
|
|
this->nameActivPP = name;
|
2014-06-15 10:04:49 +02:00
|
|
|
|
if (parse == Document::FullParse)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-06-15 10:04:49 +02:00
|
|
|
|
emit ChangedActivPP(name);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief GetActivDrawElement return draw tag for current pattern peace.
|
|
|
|
|
* @param element draw tag.
|
|
|
|
|
* @return true if found.
|
|
|
|
|
*/
|
2014-06-05 11:52:00 +02:00
|
|
|
|
bool VPattern::GetActivDrawElement(QDomElement &element) const
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-07-17 14:41:48 +02:00
|
|
|
|
if (nameActivPP.isEmpty() == false)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
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 );
|
2014-07-17 14:41:48 +02:00
|
|
|
|
if ( fieldName == nameActivPP )
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
2014-06-06 17:06:41 +02:00
|
|
|
|
* @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.
|
2014-06-05 12:02:35 +02:00
|
|
|
|
* @param name pattern peace name.
|
|
|
|
|
* @return true if success.
|
|
|
|
|
*/
|
2014-06-06 17:06:41 +02:00
|
|
|
|
bool VPattern::appendPP(const QString &name)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-06-06 17:06:41 +02:00
|
|
|
|
Q_ASSERT_X(name.isEmpty() == false, "appendPP", "name pattern piece is empty");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
if (name.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-07-17 14:41:48 +02:00
|
|
|
|
if (CheckExistNamePP(name) == false)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-07-17 14:41:48 +02:00
|
|
|
|
if (nameActivPP.isEmpty())
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-06-06 17:06:41 +02:00
|
|
|
|
SetActivPP(name);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-07-17 14:41:48 +02:00
|
|
|
|
this->nameActivPP = name;
|
2014-06-15 10:04:49 +02:00
|
|
|
|
emit ChangedActivPP(name);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
2014-07-17 14:41:48 +02:00
|
|
|
|
* @brief ChangeNamePP change pattern piece name.
|
|
|
|
|
* @param oldName old pattern piece name.
|
|
|
|
|
* @param newName new pattern piece name.
|
2014-06-05 12:02:35 +02:00
|
|
|
|
* @return true if success.
|
|
|
|
|
*/
|
2014-07-17 14:41:48 +02:00
|
|
|
|
bool VPattern::ChangeNamePP(const QString& oldName, const QString &newName)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-07-17 14:41:48 +02:00
|
|
|
|
Q_ASSERT_X(newName.isEmpty() == false, "SetNamePP", "new name pattern piece is empty");
|
|
|
|
|
Q_ASSERT_X(oldName.isEmpty() == false, "SetNamePP", "old name pattern piece is empty");
|
|
|
|
|
|
|
|
|
|
if (CheckExistNamePP(oldName) == false)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-07-17 14:41:48 +02:00
|
|
|
|
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);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-07-17 14:41:48 +02:00
|
|
|
|
qDebug()<<"Can't find pattern piece node with name"<<oldName<<Q_FUNC_INFO;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief Parse parse file.
|
|
|
|
|
* @param parse parser file mode.
|
|
|
|
|
*/
|
2014-06-12 09:22:29 +02:00
|
|
|
|
void VPattern::Parse(const Document &parse)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-06-05 13:46:12 +02:00
|
|
|
|
SCASSERT(sceneDraw != nullptr);
|
|
|
|
|
SCASSERT(sceneDetail != nullptr);
|
2014-08-08 18:24:36 +02:00
|
|
|
|
QStringList tags{TagDraw, TagIncrements, TagAuthor, TagDescription, TagNotes, TagMeasurements, TagVersion,
|
|
|
|
|
TagGradation};
|
2014-06-05 13:46:12 +02:00
|
|
|
|
PrepareForParse(parse);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
QDomNode domNode = documentElement().firstChild();
|
|
|
|
|
while (domNode.isNull() == false)
|
|
|
|
|
{
|
|
|
|
|
if (domNode.isElement())
|
|
|
|
|
{
|
|
|
|
|
const QDomElement domElement = domNode.toElement();
|
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
|
{
|
2014-02-26 10:51:37 +01:00
|
|
|
|
switch (tags.indexOf(domElement.tagName()))
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-02-25 19:03:17 +01:00
|
|
|
|
case 0: // TagDraw
|
|
|
|
|
if (parse == Document::FullParse)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-07-17 14:41:48 +02:00
|
|
|
|
if (nameActivPP.isEmpty())
|
2014-02-25 19:03:17 +01:00
|
|
|
|
{
|
2014-06-06 17:06:41 +02:00
|
|
|
|
SetActivPP(GetParametrString(domElement, AttrName));
|
2014-02-25 19:03:17 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-06-06 17:06:41 +02:00
|
|
|
|
ChangeActivPP(GetParametrString(domElement, AttrName));
|
2014-02-25 19:03:17 +01:00
|
|
|
|
}
|
2014-06-05 13:35:38 +02:00
|
|
|
|
patternPieces << GetParametrString(domElement, AttrName);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-06-06 17:06:41 +02:00
|
|
|
|
ChangeActivPP(GetParametrString(domElement, AttrName), Document::LiteParse);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
2014-07-16 14:47:31 +02:00
|
|
|
|
ParseDrawElement(domElement, parse);
|
2014-02-25 19:03:17 +01:00
|
|
|
|
break;
|
|
|
|
|
case 1: // TagIncrements
|
|
|
|
|
ParseIncrementsElement(domElement);
|
|
|
|
|
break;
|
2014-03-03 16:30:04 +01:00
|
|
|
|
case 2: // TagAuthor
|
|
|
|
|
break;
|
|
|
|
|
case 3: // TagDescription
|
|
|
|
|
break;
|
|
|
|
|
case 4: // TagNotes
|
|
|
|
|
break;
|
2014-03-23 15:36:34 +01:00
|
|
|
|
case 5: // TagMeasurements
|
|
|
|
|
break;
|
2014-05-21 19:33:40 +02:00
|
|
|
|
case 6: // TagVersion
|
|
|
|
|
break;
|
2014-08-08 18:24:36 +02:00
|
|
|
|
case 7: // TagGradation
|
|
|
|
|
break;
|
2014-02-25 19:03:17 +01:00
|
|
|
|
default:
|
2014-05-21 19:33:40 +02:00
|
|
|
|
qDebug()<<"Wrong tag name"<<domElement.tagName()<<Q_FUNC_INFO;
|
2014-02-25 19:03:17 +01:00
|
|
|
|
break;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
domNode = domNode.nextSibling();
|
|
|
|
|
}
|
2014-07-23 15:13:08 +02:00
|
|
|
|
emit CheckLayout();
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief getTool return tool from tool list.
|
|
|
|
|
* @param id tool id.
|
|
|
|
|
* @return tool.
|
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
|
VDataTool *VPattern::getTool(const quint32 &id)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
if (tools.contains(id))
|
|
|
|
|
{
|
|
|
|
|
return tools.value(id);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const QString error = QString(tr("Can't find tool id = %1 in table.")).arg(id);
|
|
|
|
|
throw VException(error);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief setCursor set cursor.
|
|
|
|
|
* @param value cursor.
|
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
|
void VPattern::setCursor(const quint32 &value)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-06-05 11:52:00 +02:00
|
|
|
|
if (cursor != value)
|
|
|
|
|
{
|
|
|
|
|
cursor = value;
|
|
|
|
|
emit ChangedCursor(cursor);
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief setCurrentData set current data set.
|
2014-06-05 13:35:38 +02:00
|
|
|
|
*
|
|
|
|
|
* Each time after parsing need set correct data set for current pattern piece. After parsing it is always last.
|
|
|
|
|
* Current data set for pattern pice it is data set for last object in pattern pice (point, arc, spline, spline path so
|
|
|
|
|
* on).
|
2014-06-05 12:02:35 +02:00
|
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
|
void VPattern::setCurrentData()
|
|
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
|
if (*mode == Draw::Calculation)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-06-15 10:04:49 +02:00
|
|
|
|
if (CountPP() > 1)//don't need upadate data if we have only one pattern piece
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
|
quint32 id = 0;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
if (history.size() == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (qint32 i = 0; i < history.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
const VToolRecord tool = history.at(i);
|
2014-07-17 14:41:48 +02:00
|
|
|
|
if (tool.getNameDraw() == nameActivPP)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
id = tool.getId();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (id == 0)
|
|
|
|
|
{
|
|
|
|
|
const VToolRecord tool = history.at(history.size()-1);
|
|
|
|
|
id = tool.getId();
|
|
|
|
|
if (id == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (tools.size() > 0)
|
|
|
|
|
{
|
|
|
|
|
const VDataTool *vTool = tools.value(id);
|
2014-08-21 14:44:40 +02:00
|
|
|
|
*data = vTool->getData();
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief AddTool add tool to list tools.
|
|
|
|
|
* @param id tool id.
|
|
|
|
|
* @param tool tool.
|
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
|
void VPattern::AddTool(const quint32 &id, VDataTool *tool)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
|
2014-06-06 12:36:34 +02:00
|
|
|
|
SCASSERT(tool != nullptr);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
tools.insert(id, tool);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief UpdateToolData update tool in list tools.
|
|
|
|
|
* @param id tool id.
|
|
|
|
|
* @param data container with variables.
|
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
|
void VPattern::UpdateToolData(const quint32 &id, VContainer *data)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
|
2014-06-06 12:36:34 +02:00
|
|
|
|
SCASSERT(data != nullptr);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
VDataTool *tool = tools.value(id);
|
2014-06-06 12:36:34 +02:00
|
|
|
|
SCASSERT(tool != nullptr);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
tool->VDataTool::setData(data);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief IncrementReferens increment reference parent objects.
|
|
|
|
|
* @param id parent object id.
|
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
|
void VPattern::IncrementReferens(quint32 id) const
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
|
|
|
|
|
VDataTool *tool = tools.value(id);
|
2014-06-06 12:36:34 +02:00
|
|
|
|
SCASSERT(tool != nullptr);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
tool->incrementReferens();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief DecrementReferens decrement reference parent objects.
|
|
|
|
|
* @param id parent object id.
|
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
|
void VPattern::DecrementReferens(quint32 id) const
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
|
|
|
|
|
VDataTool *tool = tools.value(id);
|
2014-06-06 12:36:34 +02:00
|
|
|
|
SCASSERT(tool != nullptr);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
tool->decrementReferens();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief TestUniqueId test exist unique id in pattern file. Each id must be unique.
|
|
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
|
void VPattern::TestUniqueId() const
|
|
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
|
QVector<quint32> vector;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
CollectId(documentElement(), vector);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief SPointActiveDraw return id base point current pattern peace.
|
|
|
|
|
* @return id base point.
|
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
|
quint32 VPattern::SPointActiveDraw()
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
QDomElement calcElement;
|
|
|
|
|
if (GetActivNodeElement(TagCalculation, calcElement))
|
|
|
|
|
{
|
|
|
|
|
const QDomNode domNode = calcElement.firstChild();
|
|
|
|
|
if (domNode.isNull() == false && domNode.isElement())
|
|
|
|
|
{
|
|
|
|
|
const QDomElement domElement = domNode.toElement();
|
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
|
{
|
|
|
|
|
if (domElement.tagName() == VToolPoint::TagName &&
|
2014-02-25 19:03:17 +01:00
|
|
|
|
domElement.attribute(AttrType, "") == VToolSinglePoint::ToolType)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
return GetParametrId(domElement);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief CheckNameDraw check if exist pattern peace with this name.
|
|
|
|
|
* @param name pattern peace name.
|
|
|
|
|
* @return true if exist.
|
|
|
|
|
*/
|
2014-07-17 14:41:48 +02:00
|
|
|
|
bool VPattern::CheckExistNamePP(const QString &name) const
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
Q_ASSERT_X(name.isEmpty() == false, "CheckNameDraw", "name draw is empty");
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
2014-06-06 17:06:41 +02:00
|
|
|
|
* @brief SetActivPP set current pattern piece.
|
2014-06-05 12:02:35 +02:00
|
|
|
|
* @param name pattern peace name.
|
|
|
|
|
*/
|
2014-06-06 17:06:41 +02:00
|
|
|
|
void VPattern::SetActivPP(const QString &name)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-06-06 17:06:41 +02:00
|
|
|
|
Q_ASSERT_X(name.isEmpty() == false, "SetActivPP", "name pattern piece is empty");
|
2014-07-17 14:41:48 +02:00
|
|
|
|
this->nameActivPP = name;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief GetActivNodeElement find element in current pattern piece by name.
|
|
|
|
|
* @param name name tag.
|
|
|
|
|
* @param element element.
|
|
|
|
|
* @return true if found.
|
|
|
|
|
*/
|
2014-06-05 11:52:00 +02:00
|
|
|
|
bool VPattern::GetActivNodeElement(const QString &name, QDomElement &element) const
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
Q_ASSERT_X(name.isEmpty() == false, "GetActivNodeElement", "name draw is empty");
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-03-21 11:08:29 +01:00
|
|
|
|
QString VPattern::MPath() const
|
|
|
|
|
{
|
2014-03-24 16:02:57 +01:00
|
|
|
|
QDomNodeList list = elementsByTagName(TagMeasurements);
|
2014-03-21 11:08:29 +01:00
|
|
|
|
QDomElement element = list.at(0).toElement();
|
|
|
|
|
if (element.isElement())
|
|
|
|
|
{
|
|
|
|
|
return GetParametrString(element, AttrPath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-03-24 16:02:57 +01:00
|
|
|
|
void VPattern::SetPath(const QString &path)
|
|
|
|
|
{
|
2014-03-26 05:39:07 +01:00
|
|
|
|
if (path.isEmpty())
|
|
|
|
|
{
|
2014-03-28 14:11:46 +01:00
|
|
|
|
qDebug()<<"Path to measurements is empty"<<Q_FUNC_INFO;
|
2014-03-26 05:39:07 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-03-24 16:02:57 +01:00
|
|
|
|
QDomNodeList list = elementsByTagName(TagMeasurements);
|
|
|
|
|
QDomElement element = list.at(0).toElement();
|
|
|
|
|
if (element.isElement())
|
|
|
|
|
{
|
|
|
|
|
SetAttribute(element, AttrPath, path);
|
2014-06-18 18:11:14 +02:00
|
|
|
|
emit patternChanged(false);
|
2014-03-24 16:02:57 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-03-28 14:11:46 +01:00
|
|
|
|
qDebug()<<"Can't save path to measurements"<<Q_FUNC_INFO;
|
2014-03-24 16:02:57 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-12 09:22:29 +02:00
|
|
|
|
Unit VPattern::MUnit() const
|
2014-03-21 11:08:29 +01:00
|
|
|
|
{
|
|
|
|
|
QDomNodeList list = elementsByTagName(VPattern::TagMeasurements);
|
|
|
|
|
QDomElement element = list.at(0).toElement();
|
|
|
|
|
if (element.isElement())
|
|
|
|
|
{
|
2014-05-30 11:52:19 +02:00
|
|
|
|
QStringList units{"mm", "cm", "inch"};
|
2014-03-21 11:08:29 +01:00
|
|
|
|
QString unit = GetParametrString(element, AttrUnit);
|
2014-05-01 13:33:40 +02:00
|
|
|
|
switch (units.indexOf(unit))
|
2014-03-21 11:08:29 +01:00
|
|
|
|
{
|
|
|
|
|
case 0:// mm
|
2014-06-12 09:22:29 +02:00
|
|
|
|
return Unit::Mm;
|
2014-03-21 11:08:29 +01:00
|
|
|
|
break;
|
|
|
|
|
case 1:// cm
|
2014-06-12 09:22:29 +02:00
|
|
|
|
return Unit::Cm;
|
2014-03-21 11:08:29 +01:00
|
|
|
|
break;
|
|
|
|
|
case 2:// in
|
2014-06-12 09:22:29 +02:00
|
|
|
|
return Unit::Inch;
|
2014-03-21 11:08:29 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2014-06-12 09:22:29 +02:00
|
|
|
|
return Unit::Cm;
|
2014-03-21 11:08:29 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
|
return Unit::Cm;
|
2014-03-21 11:08:29 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-12 09:22:29 +02:00
|
|
|
|
MeasurementsType VPattern::MType() const
|
2014-03-21 11:08:29 +01:00
|
|
|
|
{
|
|
|
|
|
QDomNodeList list = elementsByTagName(VPattern::TagMeasurements);
|
|
|
|
|
QDomElement element = list.at(0).toElement();
|
|
|
|
|
if (element.isElement())
|
|
|
|
|
{
|
|
|
|
|
QString type = GetParametrString(element, AttrType);
|
2014-05-30 11:52:19 +02:00
|
|
|
|
QStringList types{"standard", "individual"};
|
2014-05-01 13:33:40 +02:00
|
|
|
|
switch (types.indexOf(type))
|
2014-03-21 11:08:29 +01:00
|
|
|
|
{
|
|
|
|
|
case 0:// standard
|
2014-06-12 09:22:29 +02:00
|
|
|
|
return MeasurementsType::Standard;
|
2014-03-21 11:08:29 +01:00
|
|
|
|
break;
|
|
|
|
|
case 1:// individual
|
2014-06-12 09:22:29 +02:00
|
|
|
|
return MeasurementsType::Individual;
|
2014-03-21 11:08:29 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2014-06-12 09:22:29 +02:00
|
|
|
|
return MeasurementsType::Individual;
|
2014-03-21 11:08:29 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
|
return MeasurementsType::Individual;
|
2014-03-21 11:08:29 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-10-08 10:51:17 +02:00
|
|
|
|
bool VPattern::SaveDocument(const QString &fileName, QString &error)
|
2014-03-28 14:11:46 +01:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
TestUniqueId();
|
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionWrongId &e)
|
|
|
|
|
{
|
2014-07-08 12:59:50 +02:00
|
|
|
|
e.CriticalMessageBox(tr("Error no unique id."), qApp->getMainWindow());
|
2014-03-28 14:11:46 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-06-16 19:08:23 +02:00
|
|
|
|
GarbageCollector();
|
2014-06-12 11:51:40 +02:00
|
|
|
|
|
2014-10-08 10:51:17 +02:00
|
|
|
|
return VDomDocument::SaveDocument(fileName, error);
|
2014-03-28 14:11:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
2014-06-10 13:53:40 +02:00
|
|
|
|
* @brief LiteParseTree lite parse file.
|
2014-06-05 12:02:35 +02:00
|
|
|
|
*/
|
2014-08-04 15:37:36 +02:00
|
|
|
|
void VPattern::LiteParseTree(const Document &parse)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-07-23 10:56:32 +02:00
|
|
|
|
// Save name current pattern piece
|
|
|
|
|
QString namePP = nameActivPP;
|
|
|
|
|
|
2014-02-25 15:02:09 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-24 10:23:39 +02:00
|
|
|
|
emit SetEnabledGUI(true);
|
2014-09-10 19:57:08 +02:00
|
|
|
|
switch (parse)
|
2014-08-04 15:37:36 +02:00
|
|
|
|
{
|
|
|
|
|
case Document::LitePPParse:
|
|
|
|
|
ParseCurrentPP();
|
|
|
|
|
break;
|
|
|
|
|
case Document::LiteParse:
|
|
|
|
|
Parse(parse);
|
|
|
|
|
break;
|
|
|
|
|
case Document::FullParse:
|
|
|
|
|
qWarning()<<"Lite parsing doesn't support full parsing";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
2014-06-24 10:23:39 +02:00
|
|
|
|
catch (const VExceptionUndo &e)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(e);
|
|
|
|
|
/* If user want undo last operation before undo we need finish broken redo operation. For those we post event
|
|
|
|
|
* myself. Later in method customEvent call undo.*/
|
|
|
|
|
QApplication::postEvent(this, new UndoEvent());
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-05-30 15:22:03 +02:00
|
|
|
|
catch (const VExceptionObjectError &e)
|
|
|
|
|
{
|
2014-07-08 12:59:50 +02:00
|
|
|
|
e.CriticalMessageBox(tr("Error parsing file."), qApp->getMainWindow());
|
2014-06-24 10:23:39 +02:00
|
|
|
|
emit SetEnabledGUI(false);
|
2014-05-30 15:22:03 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionConversionError &e)
|
|
|
|
|
{
|
2014-07-08 12:59:50 +02:00
|
|
|
|
e.CriticalMessageBox(tr("Error can't convert value."), qApp->getMainWindow());
|
2014-06-24 10:23:39 +02:00
|
|
|
|
emit SetEnabledGUI(false);
|
2014-05-30 15:22:03 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionEmptyParameter &e)
|
|
|
|
|
{
|
2014-07-08 12:59:50 +02:00
|
|
|
|
e.CriticalMessageBox(tr("Error empty parameter."), qApp->getMainWindow());
|
2014-06-24 10:23:39 +02:00
|
|
|
|
emit SetEnabledGUI(false);
|
2014-05-30 15:22:03 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionWrongId &e)
|
|
|
|
|
{
|
2014-07-08 12:59:50 +02:00
|
|
|
|
e.CriticalMessageBox(tr("Error wrong id."), qApp->getMainWindow());
|
2014-06-24 10:23:39 +02:00
|
|
|
|
emit SetEnabledGUI(false);
|
2014-05-30 15:22:03 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
catch (VException &e)
|
|
|
|
|
{
|
2014-07-08 12:59:50 +02:00
|
|
|
|
e.CriticalMessageBox(tr("Error parsing file."), qApp->getMainWindow());
|
2014-06-24 10:23:39 +02:00
|
|
|
|
emit SetEnabledGUI(false);
|
2014-05-30 15:22:03 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
catch (const std::bad_alloc &)
|
|
|
|
|
{
|
2014-05-30 16:31:48 +02:00
|
|
|
|
#ifndef QT_NO_CURSOR
|
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
|
#endif
|
2014-07-08 12:59:50 +02:00
|
|
|
|
QMessageBox::critical(qApp->getMainWindow(), tr("Critical error!"), tr("Error parsing file (std::bad_alloc)."),
|
2014-06-24 10:23:39 +02:00
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
2014-05-30 16:31:48 +02:00
|
|
|
|
#ifndef QT_NO_CURSOR
|
|
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
|
|
|
#endif
|
2014-06-24 10:23:39 +02:00
|
|
|
|
emit SetEnabledGUI(false);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-23 10:56:32 +02:00
|
|
|
|
// Restore name current pattern piece
|
|
|
|
|
nameActivPP = namePP;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
setCurrentData();
|
|
|
|
|
emit FullUpdateFromFile();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief haveLiteChange we have unsaved change.
|
|
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
|
void VPattern::haveLiteChange()
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
emit patternChanged(false);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief ShowHistoryTool hightlight tool.
|
|
|
|
|
* @param id tool id.
|
|
|
|
|
* @param color hightlight color.
|
|
|
|
|
* @param enable enable or diasable hightlight.
|
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
|
void VPattern::ShowHistoryTool(quint32 id, Qt::GlobalColor color, bool enable)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
emit ShowTool(id, color, enable);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-06 17:06:41 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-06 12:36:34 +02:00
|
|
|
|
void VPattern::NeedFullParsing()
|
|
|
|
|
{
|
|
|
|
|
emit UndoCommand();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-06 17:06:41 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VPattern::ClearScene()
|
|
|
|
|
{
|
|
|
|
|
emit ClearMainWindow();
|
|
|
|
|
}
|
2014-06-05 13:35:38 +02:00
|
|
|
|
|
2014-06-24 10:23:39 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VPattern::customEvent(QEvent *event)
|
|
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
|
if (event->type() == UNDO_EVENT)
|
2014-06-24 10:23:39 +02:00
|
|
|
|
{
|
|
|
|
|
qApp->getUndoStack()->undo();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief ParseDrawElement parse draw tag.
|
|
|
|
|
* @param node node.
|
|
|
|
|
* @param parse parser file mode.
|
|
|
|
|
*/
|
2014-07-16 14:47:31 +02:00
|
|
|
|
void VPattern::ParseDrawElement(const QDomNode &node, const Document &parse)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-05-30 16:55:54 +02:00
|
|
|
|
QStringList tags{TagCalculation, TagModeling, TagDetails};
|
2014-02-25 15:02:09 +01:00
|
|
|
|
QDomNode domNode = node.firstChild();
|
|
|
|
|
while (domNode.isNull() == false)
|
|
|
|
|
{
|
|
|
|
|
if (domNode.isElement())
|
|
|
|
|
{
|
|
|
|
|
const QDomElement domElement = domNode.toElement();
|
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
|
{
|
2014-02-26 10:51:37 +01:00
|
|
|
|
switch (tags.indexOf(domElement.tagName()))
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-02-25 19:03:17 +01:00
|
|
|
|
case 0: // TagCalculation
|
|
|
|
|
data->ClearCalculationGObjects();
|
2014-07-16 14:47:31 +02:00
|
|
|
|
ParseDrawMode(domElement, parse, Draw::Calculation);
|
2014-02-25 19:03:17 +01:00
|
|
|
|
break;
|
|
|
|
|
case 1: // TagModeling
|
2014-07-16 14:47:31 +02:00
|
|
|
|
ParseDrawMode(domElement, parse, Draw::Modeling);
|
2014-02-25 19:03:17 +01:00
|
|
|
|
break;
|
|
|
|
|
case 2: // TagDetails
|
2014-07-16 14:47:31 +02:00
|
|
|
|
ParseDetails(domElement, parse);
|
2014-02-25 19:03:17 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2014-03-28 14:11:46 +01:00
|
|
|
|
qDebug()<<"Wrong tag name"<<Q_FUNC_INFO;
|
2014-02-25 19:03:17 +01:00
|
|
|
|
break;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
domNode = domNode.nextSibling();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief ParseDrawMode parse draw tag with draw mode.
|
|
|
|
|
* @param node node.
|
|
|
|
|
* @param parse parser file mode.
|
|
|
|
|
* @param mode draw mode.
|
|
|
|
|
*/
|
2014-07-16 14:47:31 +02:00
|
|
|
|
void VPattern::ParseDrawMode(const QDomNode &node, const Document &parse, const Draw &mode)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
|
SCASSERT(sceneDraw != nullptr);
|
|
|
|
|
SCASSERT(sceneDetail != nullptr);
|
2014-03-10 17:22:55 +01:00
|
|
|
|
VMainGraphicsScene *scene = nullptr;
|
2014-06-12 09:22:29 +02:00
|
|
|
|
if (mode == Draw::Calculation)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
scene = sceneDraw;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
scene = sceneDetail;
|
|
|
|
|
}
|
2014-05-30 16:55:54 +02:00
|
|
|
|
QStringList tags{TagPoint, TagLine, TagSpline, TagArc, TagTools};
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const QDomNodeList nodeList = node.childNodes();
|
|
|
|
|
const qint32 num = nodeList.size();
|
|
|
|
|
for (qint32 i = 0; i < num; ++i)
|
|
|
|
|
{
|
2014-05-30 10:32:40 +02:00
|
|
|
|
QDomElement domElement = nodeList.at(i).toElement();
|
2014-02-25 15:02:09 +01:00
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
|
{
|
2014-02-26 10:51:37 +01:00
|
|
|
|
switch (tags.indexOf(domElement.tagName()))
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-02-25 19:03:17 +01:00
|
|
|
|
case 0: // TagPoint
|
|
|
|
|
ParsePointElement(scene, domElement, parse, domElement.attribute(AttrType, ""));
|
|
|
|
|
break;
|
|
|
|
|
case 1: // TagLine
|
|
|
|
|
ParseLineElement(scene, domElement, parse);
|
|
|
|
|
break;
|
|
|
|
|
case 2: // TagSpline
|
|
|
|
|
ParseSplineElement(scene, domElement, parse, domElement.attribute(AttrType, ""));
|
|
|
|
|
break;
|
|
|
|
|
case 3: // TagArc
|
|
|
|
|
ParseArcElement(scene, domElement, parse, domElement.attribute(AttrType, ""));
|
|
|
|
|
break;
|
|
|
|
|
case 4: // TagTools
|
|
|
|
|
ParseToolsElement(scene, domElement, parse, domElement.attribute(AttrType, ""));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2014-03-28 14:11:46 +01:00
|
|
|
|
qDebug()<<"Wrong tag name"<<Q_FUNC_INFO;
|
2014-02-25 19:03:17 +01:00
|
|
|
|
break;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief ParseDetailElement parse detail tag.
|
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
|
* @param parse parser file mode.
|
|
|
|
|
*/
|
2014-07-16 14:47:31 +02:00
|
|
|
|
void VPattern::ParseDetailElement(const QDomElement &domElement, const Document &parse)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
VDetail detail;
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 id = GetParametrId(domElement);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
detail.setName(GetParametrString(domElement, VAbstractTool::AttrName, ""));
|
2014-03-19 19:27:11 +01:00
|
|
|
|
detail.setMx(qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "0.0")));
|
|
|
|
|
detail.setMy(qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "0.0")));
|
2014-02-25 15:40:24 +01:00
|
|
|
|
detail.setSeamAllowance(GetParametrUInt(domElement, VToolDetail::AttrSupplement, "1"));
|
2014-02-25 15:02:09 +01:00
|
|
|
|
detail.setWidth(GetParametrDouble(domElement, VToolDetail::AttrWidth, "10.0"));
|
2014-02-25 15:40:24 +01:00
|
|
|
|
detail.setClosed(GetParametrUInt(domElement, VToolDetail::AttrClosed, "1"));
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-05-30 16:55:54 +02:00
|
|
|
|
QStringList types{VToolDetail::NodePoint, VToolDetail::NodeArc, VToolDetail::NodeSpline,
|
|
|
|
|
VToolDetail::NodeSplinePath};
|
2014-02-25 15:02:09 +01:00
|
|
|
|
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 (element.isNull() == false)
|
|
|
|
|
{
|
|
|
|
|
if (element.tagName() == VToolDetail::TagNode)
|
|
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 id = GetParametrUInt(element, VToolDetail::AttrIdObject, "0");
|
2014-03-19 19:27:11 +01:00
|
|
|
|
const qreal mx = qApp->toPixel(GetParametrDouble(element, VAbstractTool::AttrMx, "0.0"));
|
|
|
|
|
const qreal my = qApp->toPixel(GetParametrDouble(element, VAbstractTool::AttrMy, "0.0"));
|
2014-06-12 09:22:29 +02:00
|
|
|
|
const NodeDetail nodeType = NodeDetail::Contour;
|
2014-02-25 19:03:17 +01:00
|
|
|
|
|
|
|
|
|
const QString t = GetParametrString(element, AttrType, "NodePoint");
|
2014-06-12 09:22:29 +02:00
|
|
|
|
Tool tool;
|
2014-05-30 16:55:54 +02:00
|
|
|
|
|
2014-02-26 10:51:37 +01:00
|
|
|
|
switch (types.indexOf(t))
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-02-25 19:03:17 +01:00
|
|
|
|
case 0: // VToolDetail::NodePoint
|
2014-06-12 09:22:29 +02:00
|
|
|
|
tool = Tool::NodePoint;
|
2014-02-25 19:03:17 +01:00
|
|
|
|
break;
|
|
|
|
|
case 1: // VToolDetail::NodeArc
|
2014-06-12 09:22:29 +02:00
|
|
|
|
tool = Tool::NodeArc;
|
2014-02-25 19:03:17 +01:00
|
|
|
|
break;
|
|
|
|
|
case 2: // VToolDetail::NodeSpline
|
2014-06-12 09:22:29 +02:00
|
|
|
|
tool = Tool::NodeSpline;
|
2014-02-25 19:03:17 +01:00
|
|
|
|
break;
|
|
|
|
|
case 3: // VToolDetail::NodeSplinePath
|
2014-06-12 09:22:29 +02:00
|
|
|
|
tool = Tool::NodeSplinePath;
|
2014-02-25 19:03:17 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2014-03-28 14:11:46 +01:00
|
|
|
|
qDebug()<<"Wrong node type."<<Q_FUNC_INFO;
|
2014-06-17 11:50:11 +02:00
|
|
|
|
continue;
|
2014-02-25 19:03:17 +01:00
|
|
|
|
break;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
detail.append(VNodeDetail(id, tool, nodeType, mx, my));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-12 09:22:29 +02:00
|
|
|
|
VToolDetail::Create(id, detail, sceneDetail, this, data, parse, Source::FromFile);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating detail"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief ParseDetails parse details tag.
|
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
|
* @param parse parser file mode.
|
|
|
|
|
*/
|
2014-07-16 14:47:31 +02:00
|
|
|
|
void VPattern::ParseDetails(const QDomElement &domElement, const Document &parse)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
|
|
|
|
QDomNode domNode = domElement.firstChild();
|
|
|
|
|
while (domNode.isNull() == false)
|
|
|
|
|
{
|
|
|
|
|
if (domNode.isElement())
|
|
|
|
|
{
|
|
|
|
|
const QDomElement domElement = domNode.toElement();
|
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
|
{
|
|
|
|
|
if (domElement.tagName() == VToolDetail::TagName)
|
|
|
|
|
{
|
2014-07-16 14:47:31 +02:00
|
|
|
|
ParseDetailElement(domElement, parse);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
domNode = domNode.nextSibling();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-18 18:11:14 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VPattern::PointsCommonAttributes(const QDomElement &domElement, quint32 &id, QString &name, qreal &mx, qreal &my,
|
|
|
|
|
QString &typeLine)
|
|
|
|
|
{
|
|
|
|
|
PointsCommonAttributes(domElement, id, name, mx, my);
|
|
|
|
|
typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VPattern::PointsCommonAttributes(const QDomElement &domElement, quint32 &id, QString &name, qreal &mx, qreal &my)
|
|
|
|
|
{
|
|
|
|
|
PointsCommonAttributes(domElement, id, mx, my);
|
|
|
|
|
name = GetParametrString(domElement, VAbstractTool::AttrName, "A");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VPattern::PointsCommonAttributes(const QDomElement &domElement, quint32 &id, qreal &mx, qreal &my)
|
|
|
|
|
{
|
|
|
|
|
ToolsCommonAttributes(domElement, id);
|
|
|
|
|
mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0"));
|
|
|
|
|
my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0"));
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief ParsePointElement parse point tag.
|
|
|
|
|
* @param scene scene.
|
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
|
* @param parse parser file mode.
|
|
|
|
|
* @param type type of point.
|
|
|
|
|
*/
|
2014-05-30 10:32:40 +02:00
|
|
|
|
void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElement,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
const Document &parse, const QString &type)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
|
SCASSERT(scene != nullptr);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
|
|
|
|
Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of point is empty");
|
|
|
|
|
|
2014-06-18 18:11:14 +02:00
|
|
|
|
quint32 id = 0;
|
|
|
|
|
QString name;
|
|
|
|
|
qreal mx = 0;
|
|
|
|
|
qreal my = 0;
|
|
|
|
|
QString typeLine;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-05-30 11:52:19 +02:00
|
|
|
|
QStringList points{VToolSinglePoint::ToolType, VToolEndLine::ToolType, VToolAlongLine::ToolType,
|
|
|
|
|
VToolShoulderPoint::ToolType, VToolNormal::ToolType, VToolBisector::ToolType,
|
|
|
|
|
VToolLineIntersect::ToolType, VToolPointOfContact::ToolType, VNodePoint::ToolType,
|
|
|
|
|
VToolHeight::ToolType, VToolTriangle::ToolType, VToolPointOfIntersection::ToolType,
|
|
|
|
|
VToolCutSpline::ToolType, VToolCutSplinePath::ToolType, VToolCutArc::ToolType};
|
2014-02-26 10:51:37 +01:00
|
|
|
|
switch (points.indexOf(type))
|
|
|
|
|
{
|
2014-02-25 15:02:09 +01:00
|
|
|
|
case 0: //VToolSinglePoint::ToolType
|
|
|
|
|
{
|
|
|
|
|
VToolSinglePoint *spoint = 0;
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
PointsCommonAttributes(domElement, id, name, mx, my);
|
2014-03-19 19:27:11 +01:00
|
|
|
|
const qreal x = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrX, "10.0"));
|
|
|
|
|
const qreal y = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrY, "10.0"));
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
|
|
|
|
data->UpdateGObject(id, new VPointF(x, y, name, mx, my));
|
2014-08-26 20:31:28 +02:00
|
|
|
|
VDrawTool::AddRecord(id, Tool::SinglePoint, this);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
if (parse != Document::FullParse)
|
|
|
|
|
{
|
|
|
|
|
UpdateToolData(id, data);
|
|
|
|
|
}
|
|
|
|
|
if (parse == Document::FullParse)
|
|
|
|
|
{
|
2014-07-17 14:41:48 +02:00
|
|
|
|
spoint = new VToolSinglePoint(this, data, id, Source::FromFile, nameActivPP, MPath());
|
2014-02-25 15:02:09 +01:00
|
|
|
|
scene->addItem(spoint);
|
|
|
|
|
connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
|
connect(scene, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor);
|
2014-06-24 10:23:39 +02:00
|
|
|
|
connect(scene, &VMainGraphicsScene::DisableItem, spoint, &VToolPoint::Disable);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
tools[id] = spoint;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating single point"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
scene->removeItem(spoint);
|
|
|
|
|
delete spoint;
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 1: //VToolEndLine::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
PointsCommonAttributes(domElement, id, name, mx, my, typeLine);
|
2014-08-11 16:41:17 +02:00
|
|
|
|
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0");
|
2014-05-30 10:32:40 +02:00
|
|
|
|
QString f = formula;//need for saving fixed formula;
|
|
|
|
|
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 basePointId = GetParametrUInt(domElement, VAbstractTool::AttrBasePoint, "0");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-08-11 16:41:17 +02:00
|
|
|
|
const QString angle = GetParametrString(domElement, VAbstractTool::AttrAngle, "0.0");
|
|
|
|
|
QString angleFix = angle;
|
|
|
|
|
|
|
|
|
|
VToolEndLine::Create(id, name, typeLine, f, angleFix, basePointId, mx, my, scene, this, data, parse,
|
|
|
|
|
Source::FromFile);
|
2014-05-30 10:32:40 +02:00
|
|
|
|
//Rewrite attribute formula. Need for situation when we have wrong formula.
|
2014-08-11 16:41:17 +02:00
|
|
|
|
if (f != formula || angleFix != angle)
|
2014-05-30 10:32:40 +02:00
|
|
|
|
{
|
2014-09-06 10:14:59 +02:00
|
|
|
|
SetAttribute(domElement, VAbstractTool::AttrLength, f);
|
2014-08-11 16:41:17 +02:00
|
|
|
|
SetAttribute(domElement, VAbstractTool::AttrAngle, angleFix);
|
2014-05-30 10:32:40 +02:00
|
|
|
|
haveLiteChange();
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating point of end line"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-06-16 19:18:36 +02:00
|
|
|
|
catch (qmu::QmuParserError &e)
|
2014-05-21 12:12:52 +02:00
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating point of end line"), domElement);
|
2014-06-18 14:20:35 +02:00
|
|
|
|
excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr()));
|
2014-05-21 12:12:52 +02:00
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
break;
|
|
|
|
|
case 2: //VToolAlongLine::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
PointsCommonAttributes(domElement, id, name, mx, my, typeLine);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0");
|
2014-05-30 13:50:41 +02:00
|
|
|
|
QString f = formula;//need for saving fixed formula;
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 firstPointId = GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0");
|
|
|
|
|
const quint32 secondPointId = GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-05-30 13:50:41 +02:00
|
|
|
|
VToolAlongLine::Create(id, name, typeLine, f, firstPointId, secondPointId, mx, my, scene, this,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
data, parse, Source::FromFile);
|
2014-05-30 13:50:41 +02:00
|
|
|
|
//Rewrite attribute formula. Need for situation when we have wrong formula.
|
|
|
|
|
if (f != formula)
|
|
|
|
|
{
|
|
|
|
|
SetAttribute(domElement, VAbstractTool::AttrLength, f);
|
|
|
|
|
haveLiteChange();
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating point along line"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-06-16 19:18:36 +02:00
|
|
|
|
catch (qmu::QmuParserError &e)
|
2014-05-21 12:12:52 +02:00
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating point along line"), domElement);
|
2014-06-18 14:20:35 +02:00
|
|
|
|
excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr()));
|
2014-05-21 12:12:52 +02:00
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
break;
|
|
|
|
|
case 3: //VToolShoulderPoint::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
PointsCommonAttributes(domElement, id, name, mx, my, typeLine);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0");
|
2014-05-30 13:50:41 +02:00
|
|
|
|
QString f = formula;//need for saving fixed formula;
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 p1Line = GetParametrUInt(domElement, VAbstractTool::AttrP1Line, "0");
|
|
|
|
|
const quint32 p2Line = GetParametrUInt(domElement, VAbstractTool::AttrP2Line, "0");
|
|
|
|
|
const quint32 pShoulder = GetParametrUInt(domElement, VAbstractTool::AttrPShoulder, "0");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-05-30 13:50:41 +02:00
|
|
|
|
VToolShoulderPoint::Create(id, f, p1Line, p2Line, pShoulder, typeLine, name, mx, my, scene, this,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
data, parse, Source::FromFile);
|
2014-05-30 13:50:41 +02:00
|
|
|
|
//Rewrite attribute formula. Need for situation when we have wrong formula.
|
|
|
|
|
if (f != formula)
|
|
|
|
|
{
|
|
|
|
|
SetAttribute(domElement, VAbstractTool::AttrLength, f);
|
|
|
|
|
haveLiteChange();
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating point of shoulder"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-06-16 19:18:36 +02:00
|
|
|
|
catch (qmu::QmuParserError &e)
|
2014-05-21 12:12:52 +02:00
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating point of shoulder"), domElement);
|
2014-06-18 14:20:35 +02:00
|
|
|
|
excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr()));
|
2014-05-21 12:12:52 +02:00
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
break;
|
|
|
|
|
case 4: //VToolNormal::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
PointsCommonAttributes(domElement, id, name, mx, my, typeLine);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0");
|
2014-05-30 13:50:41 +02:00
|
|
|
|
QString f = formula;//need for saving fixed formula;
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 firstPointId = GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0");
|
|
|
|
|
const quint32 secondPointId = GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const qreal angle = GetParametrDouble(domElement, VAbstractTool::AttrAngle, "0.0");
|
|
|
|
|
|
2014-05-30 13:50:41 +02:00
|
|
|
|
VToolNormal::Create(id, f, firstPointId, secondPointId, typeLine, name, angle, mx, my, scene,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
this, data, parse, Source::FromFile);
|
2014-05-30 13:50:41 +02:00
|
|
|
|
//Rewrite attribute formula. Need for situation when we have wrong formula.
|
|
|
|
|
if (f != formula)
|
|
|
|
|
{
|
|
|
|
|
SetAttribute(domElement, VAbstractTool::AttrLength, f);
|
|
|
|
|
haveLiteChange();
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating point of normal"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-06-16 19:18:36 +02:00
|
|
|
|
catch (qmu::QmuParserError &e)
|
2014-05-21 12:12:52 +02:00
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating point of normal"), domElement);
|
2014-06-18 14:20:35 +02:00
|
|
|
|
excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr()));
|
2014-05-21 12:12:52 +02:00
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
break;
|
|
|
|
|
case 5: //VToolBisector::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
PointsCommonAttributes(domElement, id, name, mx, my, typeLine);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0");
|
2014-05-30 13:50:41 +02:00
|
|
|
|
QString f = formula;//need for saving fixed formula;
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 firstPointId = GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0");
|
|
|
|
|
const quint32 secondPointId = GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0");
|
|
|
|
|
const quint32 thirdPointId = GetParametrUInt(domElement, VAbstractTool::AttrThirdPoint, "0");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-05-30 13:50:41 +02:00
|
|
|
|
VToolBisector::Create(id, f, firstPointId, secondPointId, thirdPointId,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
typeLine, name, mx, my, scene, this, data, parse, Source::FromFile);
|
2014-05-30 13:50:41 +02:00
|
|
|
|
//Rewrite attribute formula. Need for situation when we have wrong formula.
|
|
|
|
|
if (f != formula)
|
|
|
|
|
{
|
|
|
|
|
SetAttribute(domElement, VAbstractTool::AttrLength, f);
|
|
|
|
|
haveLiteChange();
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating point of bisector"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-06-16 19:18:36 +02:00
|
|
|
|
catch (qmu::QmuParserError &e)
|
2014-05-21 12:12:52 +02:00
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating point of bisector"), domElement);
|
2014-06-18 14:20:35 +02:00
|
|
|
|
excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr()));
|
2014-05-21 12:12:52 +02:00
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
break;
|
|
|
|
|
case 6: //VToolLineIntersect::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
PointsCommonAttributes(domElement, id, name, mx, my);
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 p1Line1Id = GetParametrUInt(domElement, VAbstractTool::AttrP1Line1, "0");
|
|
|
|
|
const quint32 p2Line1Id = GetParametrUInt(domElement, VAbstractTool::AttrP2Line1, "0");
|
|
|
|
|
const quint32 p1Line2Id = GetParametrUInt(domElement, VAbstractTool::AttrP1Line2, "0");
|
|
|
|
|
const quint32 p2Line2Id = GetParametrUInt(domElement, VAbstractTool::AttrP2Line2, "0");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
|
|
|
|
VToolLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
mx, my, scene, this, data, parse, Source::FromFile);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating point of lineintersection"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 7: //VToolPointOfContact::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
PointsCommonAttributes(domElement, id, name, mx, my);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const QString radius = GetParametrString(domElement, VAbstractTool::AttrRadius, "0");
|
2014-05-30 13:50:41 +02:00
|
|
|
|
QString f = radius;//need for saving fixed formula;
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 center = GetParametrUInt(domElement, VAbstractTool::AttrCenter, "0");
|
|
|
|
|
const quint32 firstPointId = GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0");
|
|
|
|
|
const quint32 secondPointId = GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-05-30 13:50:41 +02:00
|
|
|
|
VToolPointOfContact::Create(id, f, center, firstPointId, secondPointId, name, mx, my, scene, this,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
data, parse, Source::FromFile);
|
2014-05-30 13:50:41 +02:00
|
|
|
|
//Rewrite attribute formula. Need for situation when we have wrong formula.
|
|
|
|
|
if (f != radius)
|
|
|
|
|
{
|
|
|
|
|
SetAttribute(domElement, VAbstractTool::AttrRadius, f);
|
|
|
|
|
haveLiteChange();
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating point of contact"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-06-16 19:18:36 +02:00
|
|
|
|
catch (qmu::QmuParserError &e)
|
2014-05-21 12:12:52 +02:00
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating point of contact"), domElement);
|
2014-06-18 14:20:35 +02:00
|
|
|
|
excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr()));
|
2014-05-21 12:12:52 +02:00
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
break;
|
|
|
|
|
case 8: //VNodePoint::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
PointsCommonAttributes(domElement, id, mx, my);
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 idObject = GetParametrUInt(domElement, VAbstractNode::AttrIdObject, "0");
|
|
|
|
|
const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, "0");
|
2014-08-21 14:44:40 +02:00
|
|
|
|
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(idObject );
|
2014-07-25 13:53:39 +02:00
|
|
|
|
data->UpdateGObject(id, new VPointF(point->toQPointF(), point->name(), mx, my, idObject,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
Draw::Modeling));
|
|
|
|
|
VNodePoint::Create(this, data, id, idObject, parse, Source::FromFile, idTool);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating modeling point"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 9: //VToolHeight::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
PointsCommonAttributes(domElement, id, name, mx, my, typeLine);
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 basePointId = GetParametrUInt(domElement, VAbstractTool::AttrBasePoint, "0");
|
|
|
|
|
const quint32 p1LineId = GetParametrUInt(domElement, VAbstractTool::AttrP1Line, "0");
|
|
|
|
|
const quint32 p2LineId = GetParametrUInt(domElement, VAbstractTool::AttrP2Line, "0");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
|
|
|
|
VToolHeight::Create(id, name, typeLine, basePointId, p1LineId, p2LineId,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
mx, my, scene, this, data, parse, Source::FromFile);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating height"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 10: //VToolTriangle::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
PointsCommonAttributes(domElement, id, name, mx, my);
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 axisP1Id = GetParametrUInt(domElement, VAbstractTool::AttrAxisP1, "0");
|
|
|
|
|
const quint32 axisP2Id = GetParametrUInt(domElement, VAbstractTool::AttrAxisP2, "0");
|
|
|
|
|
const quint32 firstPointId = GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0");
|
|
|
|
|
const quint32 secondPointId = GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
|
|
|
|
VToolTriangle::Create(id, name, axisP1Id, axisP2Id, firstPointId, secondPointId, mx, my, scene, this,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
data, parse, Source::FromFile);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating triangle"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 11: //VToolPointOfIntersection::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
PointsCommonAttributes(domElement, id, name, mx, my);
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 firstPointId = GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0");
|
|
|
|
|
const quint32 secondPointId = GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-02-26 10:51:37 +01:00
|
|
|
|
VToolPointOfIntersection::Create(id, name, firstPointId, secondPointId, mx, my, scene, this, data,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
parse, Source::FromFile);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating point of intersection"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 12: //VToolCutSpline::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
PointsCommonAttributes(domElement, id, name, mx, my);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "0");
|
2014-05-30 13:50:41 +02:00
|
|
|
|
QString f = formula;//need for saving fixed formula;
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 splineId = GetParametrUInt(domElement, VToolCutSpline::AttrSpline, "0");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-06-12 09:22:29 +02:00
|
|
|
|
VToolCutSpline::Create(id, name, f, splineId, mx, my, scene, this, data, parse, Source::FromFile);
|
2014-05-30 13:50:41 +02:00
|
|
|
|
//Rewrite attribute formula. Need for situation when we have wrong formula.
|
|
|
|
|
if (f != formula)
|
|
|
|
|
{
|
|
|
|
|
SetAttribute(domElement, VAbstractTool::AttrLength, f);
|
|
|
|
|
haveLiteChange();
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating cut spline point"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-06-16 19:18:36 +02:00
|
|
|
|
catch (qmu::QmuParserError &e)
|
2014-05-21 12:12:52 +02:00
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating cut spline point"), domElement);
|
2014-06-18 14:20:35 +02:00
|
|
|
|
excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr()));
|
2014-05-21 12:12:52 +02:00
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
break;
|
|
|
|
|
case 13: //VToolCutSplinePath::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
PointsCommonAttributes(domElement, id, name, mx, my);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "0");
|
2014-05-30 13:50:41 +02:00
|
|
|
|
QString f = formula;//need for saving fixed formula;
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 splinePathId = GetParametrUInt(domElement, VToolCutSplinePath::AttrSplinePath, "0");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-05-30 13:50:41 +02:00
|
|
|
|
VToolCutSplinePath::Create(id, name, f, splinePathId, mx, my, scene, this, data, parse,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
Source::FromFile);
|
2014-05-30 13:50:41 +02:00
|
|
|
|
//Rewrite attribute formula. Need for situation when we have wrong formula.
|
|
|
|
|
if (f != formula)
|
|
|
|
|
{
|
|
|
|
|
SetAttribute(domElement, VAbstractTool::AttrLength, f);
|
|
|
|
|
haveLiteChange();
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating cut spline path point"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-06-16 19:18:36 +02:00
|
|
|
|
catch (qmu::QmuParserError &e)
|
2014-05-21 12:12:52 +02:00
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating cut spline path point"), domElement);
|
2014-06-18 14:20:35 +02:00
|
|
|
|
excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr()));
|
2014-05-21 12:12:52 +02:00
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
break;
|
|
|
|
|
case 14: //VToolCutArc::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
PointsCommonAttributes(domElement, id, name, mx, my);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "0");
|
2014-05-30 13:50:41 +02:00
|
|
|
|
QString f = formula;//need for saving fixed formula;
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 arcId = GetParametrUInt(domElement, VToolCutArc::AttrArc, "0");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-06-12 09:22:29 +02:00
|
|
|
|
VToolCutArc::Create(id, name, f, arcId, mx, my, scene, this, data, parse, Source::FromFile);
|
2014-05-30 13:50:41 +02:00
|
|
|
|
//Rewrite attribute formula. Need for situation when we have wrong formula.
|
|
|
|
|
if (f != formula)
|
|
|
|
|
{
|
|
|
|
|
SetAttribute(domElement, VAbstractTool::AttrLength, f);
|
|
|
|
|
haveLiteChange();
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating cut arc point"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-06-16 19:18:36 +02:00
|
|
|
|
catch (qmu::QmuParserError &e)
|
2014-05-21 12:12:52 +02:00
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating cut arc point"), domElement);
|
2014-06-18 14:20:35 +02:00
|
|
|
|
excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr()));
|
2014-05-21 12:12:52 +02:00
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2014-03-28 14:11:46 +01:00
|
|
|
|
qDebug() << "Illegal point type in VDomDocument::ParsePointElement().";
|
2014-02-25 15:02:09 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief ParseLineElement parse line tag.
|
|
|
|
|
* @param scene scene.
|
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
|
* @param parse parser file mode.
|
|
|
|
|
*/
|
2014-02-25 19:03:17 +01:00
|
|
|
|
void VPattern::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
const Document &parse)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
|
SCASSERT(scene != nullptr);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
2014-06-18 18:11:14 +02:00
|
|
|
|
quint32 id = 0;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
ToolsCommonAttributes(domElement, id);
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 firstPoint = GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0");
|
|
|
|
|
const quint32 secondPoint = GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0");
|
2014-02-25 19:03:17 +01:00
|
|
|
|
const QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine,
|
|
|
|
|
VAbstractTool::TypeLineLine);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-06-12 09:22:29 +02:00
|
|
|
|
VToolLine::Create(id, firstPoint, secondPoint, typeLine, scene, this, data, parse, Source::FromFile);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating line"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-18 18:11:14 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VPattern::SplinesCommonAttributes(const QDomElement &domElement, quint32 &id, quint32 &idObject, quint32 &idTool)
|
|
|
|
|
{
|
|
|
|
|
ToolsCommonAttributes(domElement, id);
|
|
|
|
|
idObject = GetParametrUInt(domElement, VAbstractNode::AttrIdObject, "0");
|
|
|
|
|
idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, "0");
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-29 17:23:18 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-07-30 11:03:50 +02:00
|
|
|
|
void VPattern::ParseCurrentPP()
|
2014-07-29 17:23:18 +02:00
|
|
|
|
{
|
|
|
|
|
QDomElement domElement;
|
|
|
|
|
if (GetActivDrawElement(domElement))
|
|
|
|
|
{
|
|
|
|
|
ParseDrawElement(domElement, Document::LiteParse);
|
|
|
|
|
}
|
|
|
|
|
emit CheckLayout();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-08 18:07:44 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VPattern::CheckTagExists(const QString &tag)
|
|
|
|
|
{
|
|
|
|
|
QDomNodeList list = elementsByTagName(tag);
|
|
|
|
|
if (list.size() == 0)
|
|
|
|
|
{
|
|
|
|
|
QStringList tags{TagVersion, TagAuthor, TagDescription, TagNotes, TagGradation};
|
|
|
|
|
QDomElement pattern = documentElement();
|
|
|
|
|
switch (tags.indexOf(tag))
|
|
|
|
|
{
|
|
|
|
|
case 0: //TagVersion
|
|
|
|
|
break;// Mandatory tag
|
|
|
|
|
case 1: //TagAuthor
|
|
|
|
|
pattern.insertAfter(createElement(TagAuthor), elementsByTagName(TagVersion).at(0));
|
|
|
|
|
SetVersion();
|
|
|
|
|
break;
|
|
|
|
|
case 2: //TagDescription
|
|
|
|
|
{
|
|
|
|
|
for (int i = tags.indexOf(tag)-1; i >= 0; --i)
|
|
|
|
|
{
|
|
|
|
|
QDomNodeList list = elementsByTagName(tags.at(i));
|
|
|
|
|
if (list.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
pattern.insertAfter(createElement(TagDescription), list.at(0));
|
|
|
|
|
}
|
|
|
|
|
SetVersion();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 3: //TagNotes
|
|
|
|
|
{
|
|
|
|
|
for (int i = tags.indexOf(tag)-1; i >= 0; --i)
|
|
|
|
|
{
|
|
|
|
|
QDomNodeList list = elementsByTagName(tags.at(i));
|
|
|
|
|
if (list.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
pattern.insertAfter(createElement(TagNotes), list.at(0));
|
|
|
|
|
}
|
|
|
|
|
SetVersion();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 4: //TagGradation
|
|
|
|
|
{
|
|
|
|
|
QDomElement gradation = createElement(TagGradation);
|
|
|
|
|
gradation.appendChild(createElement(TagHeights));
|
|
|
|
|
gradation.appendChild(createElement(TagSizes));
|
|
|
|
|
|
|
|
|
|
for (int i = tags.indexOf(tag)-1; i >= 0; --i)
|
|
|
|
|
{
|
|
|
|
|
QDomNodeList list = elementsByTagName(tags.at(i));
|
|
|
|
|
if (list.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
pattern.insertAfter(gradation, list.at(0));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
SetVersion();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-05 10:01:46 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QString VPattern::GetLabelBase(unsigned int index) const
|
|
|
|
|
{
|
2014-09-09 15:11:50 +02:00
|
|
|
|
QString checkedLocale = qApp->getSettings()->value("configuration/label_language",
|
|
|
|
|
QLocale::system().bcp47Name()).toString();
|
2014-09-05 10:01:46 +02:00
|
|
|
|
|
2014-09-09 15:11:50 +02:00
|
|
|
|
QStringList list = VApplication::LabelLanguages();
|
2014-09-05 10:01:46 +02:00
|
|
|
|
|
|
|
|
|
QStringList alphabet;
|
2014-09-10 19:57:08 +02:00
|
|
|
|
switch (list.indexOf(checkedLocale))
|
2014-09-05 10:01:46 +02:00
|
|
|
|
{
|
|
|
|
|
case 0: // de
|
|
|
|
|
{
|
|
|
|
|
QString al = QStringLiteral("A,Ä,B,C,D,E,F,G,H,I,J,K,L,M,N,O,Ö,P,Q,R,S,ß,T,U,Ü,V,W,X,Y,Z");
|
|
|
|
|
alphabet = al.split(",");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 1: // en
|
|
|
|
|
{
|
|
|
|
|
QString al = QStringLiteral("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z");
|
|
|
|
|
alphabet = al.split(",");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 2: // fr
|
|
|
|
|
{
|
|
|
|
|
QString al = QStringLiteral("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z");
|
|
|
|
|
alphabet = al.split(",");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 3: // ru
|
|
|
|
|
{
|
|
|
|
|
QString al = QStringLiteral("А,Б,В,Г,Д,Е,Ж,З,И,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Э,Ю,Я");
|
|
|
|
|
alphabet = al.split(",");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 4: // uk
|
|
|
|
|
{
|
|
|
|
|
QString al = QStringLiteral("А,Б,В,Г,Д,Е,Ж,З,І,Ї,Й,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Є,Ю,Я");
|
|
|
|
|
alphabet = al.split(",");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-09-09 15:11:50 +02:00
|
|
|
|
case 5: // hr
|
|
|
|
|
{
|
|
|
|
|
QString al = QStringLiteral("A,B,C,Č,Ć,D,Dž,Ð,E,F,G,H,I,J,K,L,Lj,M,N,Nj,O,P,R,S,Š,T,U,V,Z,Ž");
|
|
|
|
|
alphabet = al.split(",");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 6: // sr
|
|
|
|
|
{
|
|
|
|
|
QString al = QStringLiteral("А,Б,В,Г,Д,Ђ,Е,Ж,З,И,Ј,К,Л,Љ,М,Н,Њ,О,П,Р,С,Т,Ћ,У,Ф,Х,Ц,Ч,Џ,Ш");
|
|
|
|
|
alphabet = al.split(",");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 7: // bs
|
|
|
|
|
{
|
|
|
|
|
QString al = QStringLiteral("A,B,C,Č,Ć,D,Dž,Ð,E,F,G,H,I,J,K,L,Lj,M,N,Nj,O,P,R,S,Š,T,U,V,Z,Ž");
|
|
|
|
|
alphabet = al.split(",");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-09-05 10:01:46 +02:00
|
|
|
|
default: // en
|
|
|
|
|
{
|
|
|
|
|
QString al = QStringLiteral("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z");
|
|
|
|
|
alphabet = al.split(",");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString base;
|
2014-09-11 18:52:02 +02:00
|
|
|
|
int count = qFloor(index/static_cast<unsigned int>(alphabet.size()));
|
|
|
|
|
int number = static_cast<int>(index) - alphabet.size() * count;
|
2014-09-05 10:01:46 +02:00
|
|
|
|
int i = 0;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
base.append(alphabet.at(number));
|
|
|
|
|
++i;
|
|
|
|
|
} while (i < count);
|
|
|
|
|
return base;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief ParseSplineElement parse spline tag.
|
|
|
|
|
* @param scene scene.
|
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
|
* @param parse parser file mode.
|
|
|
|
|
* @param type type of spline.
|
|
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
|
void VPattern::ParseSplineElement(VMainGraphicsScene *scene, const QDomElement &domElement,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
const Document &parse, const QString &type)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
|
SCASSERT(scene != nullptr);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
|
|
|
|
Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty");
|
|
|
|
|
|
2014-06-18 18:11:14 +02:00
|
|
|
|
quint32 id = 0;
|
|
|
|
|
quint32 idObject = 0;
|
|
|
|
|
quint32 idTool = 0;
|
|
|
|
|
|
2014-05-30 11:52:19 +02:00
|
|
|
|
QStringList splines{VToolSpline::ToolType, VToolSplinePath::ToolType, VNodeSpline::ToolType,
|
|
|
|
|
VNodeSplinePath::ToolType};
|
2014-02-26 10:51:37 +01:00
|
|
|
|
switch (splines.indexOf(type))
|
|
|
|
|
{
|
2014-02-25 15:02:09 +01:00
|
|
|
|
case 0: //VToolSpline::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
ToolsCommonAttributes(domElement, id);
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 point1 = GetParametrUInt(domElement, VAbstractTool::AttrPoint1, "0");
|
|
|
|
|
const quint32 point4 = GetParametrUInt(domElement, VAbstractTool::AttrPoint4, "0");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const qreal angle1 = GetParametrDouble(domElement, VAbstractTool::AttrAngle1, "270.0");
|
|
|
|
|
const qreal angle2 = GetParametrDouble(domElement, VAbstractTool::AttrAngle2, "90.0");
|
|
|
|
|
const qreal kAsm1 = GetParametrDouble(domElement, VAbstractTool::AttrKAsm1, "1.0");
|
|
|
|
|
const qreal kAsm2 = GetParametrDouble(domElement, VAbstractTool::AttrKAsm2, "1.0");
|
|
|
|
|
const qreal kCurve = GetParametrDouble(domElement, VAbstractTool::AttrKCurve, "1.0");
|
|
|
|
|
|
|
|
|
|
VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this, data, parse,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
Source::FromFile);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating simple curve"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 1: //VToolSplinePath::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
ToolsCommonAttributes(domElement, id);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const qreal kCurve = GetParametrDouble(domElement, VAbstractTool::AttrKCurve, "1.0");
|
|
|
|
|
VSplinePath *path = new VSplinePath(kCurve);
|
|
|
|
|
|
|
|
|
|
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 (element.isNull() == false)
|
|
|
|
|
{
|
|
|
|
|
if (element.tagName() == VAbstractTool::AttrPathPoint)
|
|
|
|
|
{
|
|
|
|
|
const qreal kAsm1 = GetParametrDouble(element, VAbstractTool::AttrKAsm1, "1.0");
|
|
|
|
|
const qreal angle = GetParametrDouble(element, VAbstractTool::AttrAngle, "0");
|
|
|
|
|
const qreal kAsm2 = GetParametrDouble(element, VAbstractTool::AttrKAsm2, "1.0");
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 pSpline = GetParametrUInt(element, VAbstractTool::AttrPSpline, "0");
|
2014-08-21 14:44:40 +02:00
|
|
|
|
const VPointF p = *data->GeometricObject<VPointF>(pSpline);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
|
|
|
|
QLineF line(0, 0, 100, 0);
|
|
|
|
|
line.setAngle(angle+180);
|
|
|
|
|
|
|
|
|
|
VSplinePoint splPoint(p, kAsm1, line.angle(), kAsm2, angle);
|
|
|
|
|
path->append(splPoint);
|
|
|
|
|
if (parse == Document::FullParse)
|
|
|
|
|
{
|
|
|
|
|
IncrementReferens(pSpline);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-12 09:22:29 +02:00
|
|
|
|
VToolSplinePath::Create(id, path, scene, this, data, parse, Source::FromFile);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating curve path"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2: //VNodeSpline::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
SplinesCommonAttributes(domElement, id, idObject, idTool);
|
2014-08-21 14:44:40 +02:00
|
|
|
|
VSpline *spl = new VSpline(*data->GeometricObject<VSpline>(idObject));
|
2014-02-25 15:02:09 +01:00
|
|
|
|
spl->setIdObject(idObject);
|
2014-06-12 09:22:29 +02:00
|
|
|
|
spl->setMode(Draw::Modeling);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
data->UpdateGObject(id, spl);
|
2014-06-12 09:22:29 +02:00
|
|
|
|
VNodeSpline::Create(this, data, id, idObject, parse, Source::FromFile, idTool);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating modeling simple curve"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3: //VNodeSplinePath::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
SplinesCommonAttributes(domElement, id, idObject, idTool);
|
2014-08-21 14:44:40 +02:00
|
|
|
|
VSplinePath *path = new VSplinePath(*data->GeometricObject<VSplinePath>(idObject));
|
2014-02-25 15:02:09 +01:00
|
|
|
|
path->setIdObject(idObject);
|
2014-06-12 09:22:29 +02:00
|
|
|
|
path->setMode(Draw::Modeling);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
data->UpdateGObject(id, path);
|
2014-06-12 09:22:29 +02:00
|
|
|
|
VNodeSplinePath::Create(this, data, id, idObject, parse, Source::FromFile, idTool);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating modeling curve path"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2014-03-28 14:11:46 +01:00
|
|
|
|
qDebug() << "Illegal spline type in VDomDocument::ParseSplineElement().";
|
2014-02-25 15:02:09 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief ParseArcElement parse arc tag.
|
|
|
|
|
* @param scene scene.
|
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
|
* @param parse parser file mode.
|
|
|
|
|
* @param type type of spline.
|
|
|
|
|
*/
|
2014-06-12 09:22:29 +02:00
|
|
|
|
void VPattern::ParseArcElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse,
|
2014-05-30 13:50:41 +02:00
|
|
|
|
const QString &type)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
|
SCASSERT(scene != nullptr);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
|
|
|
|
Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty");
|
|
|
|
|
|
2014-06-18 18:11:14 +02:00
|
|
|
|
quint32 id = 0;
|
2014-05-30 11:52:19 +02:00
|
|
|
|
QStringList arcs{VToolArc::ToolType, VNodeArc::ToolType};
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-02-26 10:51:37 +01:00
|
|
|
|
switch (arcs.indexOf(type))
|
|
|
|
|
{
|
2014-02-25 15:02:09 +01:00
|
|
|
|
case 0: //VToolArc::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
ToolsCommonAttributes(domElement, id);
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 center = GetParametrUInt(domElement, VAbstractTool::AttrCenter, "0");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const QString radius = GetParametrString(domElement, VAbstractTool::AttrRadius, "10");
|
2014-05-30 13:50:41 +02:00
|
|
|
|
QString r = radius;//need for saving fixed formula;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const QString f1 = GetParametrString(domElement, VAbstractTool::AttrAngle1, "180");
|
2014-05-30 13:50:41 +02:00
|
|
|
|
QString f1Fix = f1;//need for saving fixed formula;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
const QString f2 = GetParametrString(domElement, VAbstractTool::AttrAngle2, "270");
|
2014-05-30 13:50:41 +02:00
|
|
|
|
QString f2Fix = f2;//need for saving fixed formula;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-06-12 09:22:29 +02:00
|
|
|
|
VToolArc::Create(id, center, r, f1Fix, f2Fix, scene, this, data, parse, Source::FromFile);
|
2014-05-30 13:50:41 +02:00
|
|
|
|
//Rewrite attribute formula. Need for situation when we have wrong formula.
|
|
|
|
|
if (r != radius || f1Fix != f1 || f2Fix != f2)
|
|
|
|
|
{
|
|
|
|
|
SetAttribute(domElement, VAbstractTool::AttrRadius, r);
|
|
|
|
|
SetAttribute(domElement, VAbstractTool::AttrAngle1, f1Fix);
|
|
|
|
|
SetAttribute(domElement, VAbstractTool::AttrAngle2, f2Fix);
|
|
|
|
|
haveLiteChange();
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating simple arc"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-06-16 19:18:36 +02:00
|
|
|
|
catch (qmu::QmuParserError &e)
|
2014-05-21 12:12:52 +02:00
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating simple arc"), domElement);
|
2014-06-18 14:20:35 +02:00
|
|
|
|
excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr()));
|
2014-05-21 12:12:52 +02:00
|
|
|
|
throw excep;
|
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
break;
|
|
|
|
|
case 1: //VNodeArc::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
ToolsCommonAttributes(domElement, id);
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 idObject = GetParametrUInt(domElement, VAbstractNode::AttrIdObject, "0");
|
|
|
|
|
const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, "0");
|
2014-08-21 14:44:40 +02:00
|
|
|
|
VArc *arc = new VArc(*data->GeometricObject<VArc>(idObject));
|
2014-02-25 15:02:09 +01:00
|
|
|
|
arc->setIdObject(idObject);
|
2014-06-12 09:22:29 +02:00
|
|
|
|
arc->setMode(Draw::Modeling);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
data->UpdateGObject(id, arc);
|
2014-06-12 09:22:29 +02:00
|
|
|
|
VNodeArc::Create(this, data, id, idObject, parse, Source::FromFile, idTool);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating modeling arc"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2014-03-28 14:11:46 +01:00
|
|
|
|
qDebug() << "Illegal arc type in VDomDocument::ParseArcElement().";
|
2014-02-25 15:02:09 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief ParseToolsElement parse tools tag.
|
|
|
|
|
* @param scene scene.
|
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
|
* @param parse parser file mode.
|
|
|
|
|
* @param type type of spline.
|
|
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
|
void VPattern::ParseToolsElement(VMainGraphicsScene *scene, const QDomElement &domElement,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
const Document &parse, const QString &type)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
|
SCASSERT(scene != nullptr);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
|
|
|
|
Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty");
|
|
|
|
|
|
2014-06-18 18:11:14 +02:00
|
|
|
|
quint32 id = 0;
|
2014-05-30 11:52:19 +02:00
|
|
|
|
QStringList tools{VToolUnionDetails::ToolType};
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
2014-02-26 10:51:37 +01:00
|
|
|
|
switch (tools.indexOf(type))
|
|
|
|
|
{
|
2014-02-25 15:02:09 +01:00
|
|
|
|
case 0: //VToolUnionDetails::ToolType
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-18 18:11:14 +02:00
|
|
|
|
ToolsCommonAttributes(domElement, id);
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 indexD1 = GetParametrUInt(domElement, VToolUnionDetails::AttrIndexD1, "-1");
|
|
|
|
|
const quint32 indexD2 = GetParametrUInt(domElement, VToolUnionDetails::AttrIndexD2, "-1");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
|
|
|
|
|
const QVector<VDetail> vector = VToolUnionDetails::GetDetailFromFile(this, domElement);
|
|
|
|
|
|
|
|
|
|
VToolUnionDetails::Create(id, vector[0], vector[1], 0, 0, indexD1, indexD2, scene, this, data, parse,
|
2014-06-12 09:22:29 +02:00
|
|
|
|
Source::FromFile);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionObjectError excep(tr("Error creating or updating union details"), domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2014-03-28 14:11:46 +01:00
|
|
|
|
qDebug() << "Illegal tools type in VDomDocument::ParseToolsElement().";
|
2014-02-25 15:02:09 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief ParseIncrementsElement parse increments tag.
|
|
|
|
|
* @param node tag in xml tree.
|
|
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
|
void VPattern::ParseIncrementsElement(const QDomNode &node)
|
|
|
|
|
{
|
|
|
|
|
QDomNode domNode = node.firstChild();
|
|
|
|
|
while (domNode.isNull() == false)
|
|
|
|
|
{
|
|
|
|
|
if (domNode.isElement())
|
|
|
|
|
{
|
|
|
|
|
const QDomElement domElement = domNode.toElement();
|
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
|
{
|
2014-02-25 19:03:17 +01:00
|
|
|
|
if (domElement.tagName() == TagIncrement)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-02-25 19:03:17 +01:00
|
|
|
|
const quint32 id = GetParametrId(domElement);
|
|
|
|
|
const QString name = GetParametrString(domElement, IncrementName, "");
|
|
|
|
|
const qreal base = GetParametrDouble(domElement, IncrementBase, "0");
|
|
|
|
|
const qreal ksize = GetParametrDouble(domElement, IncrementKsize, "0");
|
|
|
|
|
const qreal kgrowth = GetParametrDouble(domElement, IncrementKgrowth, "0");
|
|
|
|
|
const QString desc = GetParametrString(domElement, IncrementDescription, "Description");
|
2014-02-25 15:02:09 +01:00
|
|
|
|
data->UpdateId(id);
|
2014-07-29 13:28:18 +02:00
|
|
|
|
data->AddVariable(name, new VIncrement(name, id, base, ksize, kgrowth, desc));
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
domNode = domNode.nextSibling();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief GetParametrId return value id attribute.
|
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
|
* @return id value.
|
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
|
quint32 VPattern::GetParametrId(const QDomElement &domElement) const
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
|
|
|
|
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
2014-03-14 16:59:28 +01:00
|
|
|
|
|
|
|
|
|
quint32 id = 0;
|
|
|
|
|
|
|
|
|
|
QString message = tr("Got wrong parameter id. Need only id > 0.");
|
|
|
|
|
try
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-03-21 11:08:29 +01:00
|
|
|
|
id = GetParametrUInt(domElement, VDomDocument::AttrId, "0");
|
2014-03-14 16:59:28 +01:00
|
|
|
|
if (id <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw VExceptionWrongId(message, domElement);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const VExceptionConversionError &e)
|
|
|
|
|
{
|
|
|
|
|
VExceptionWrongId excep(message, domElement);
|
|
|
|
|
excep.AddMoreInformation(e.ErrorMessage());
|
|
|
|
|
throw excep;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 13:17:24 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QMap<GHeights, bool> VPattern::GetGradationHeights() const
|
|
|
|
|
{
|
|
|
|
|
QMap<GHeights, bool> map;
|
2014-08-08 18:07:44 +02:00
|
|
|
|
map.insert(GHeights::ALL, true);
|
2014-08-07 13:17:24 +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);
|
2014-08-07 16:05:37 +02:00
|
|
|
|
map.insert(GHeights::H194, true);
|
2014-08-07 13:17:24 +02:00
|
|
|
|
|
|
|
|
|
QDomNodeList tags = elementsByTagName(TagGradation);
|
|
|
|
|
if (tags.size() == 0)
|
|
|
|
|
{
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList gTags{TagHeights, TagSizes};
|
|
|
|
|
QDomNode domNode = tags.at(0).firstChild();
|
|
|
|
|
while (domNode.isNull() == false)
|
|
|
|
|
{
|
|
|
|
|
if (domNode.isElement())
|
|
|
|
|
{
|
|
|
|
|
const QDomElement domElement = domNode.toElement();
|
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
|
{
|
|
|
|
|
const QString defValue = QStringLiteral("true");
|
|
|
|
|
switch (gTags.indexOf(domElement.tagName()))
|
|
|
|
|
{
|
|
|
|
|
case 0: // TagHeights
|
|
|
|
|
if (GetParametrBool(domElement, AttrAll, defValue))
|
|
|
|
|
{
|
|
|
|
|
return map;
|
|
|
|
|
}
|
2014-08-08 18:07:44 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
map.insert(GHeights::ALL, false);
|
|
|
|
|
}
|
2014-08-07 13:17:24 +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));
|
2014-08-07 16:05:37 +02:00
|
|
|
|
map.insert(GHeights::H194, GetParametrBool(domElement, AttrH194, defValue));
|
2014-08-07 13:17:24 +02:00
|
|
|
|
return map;
|
|
|
|
|
break;
|
|
|
|
|
case 1: // TagSizes
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
domNode = domNode.nextSibling();
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-08 18:07:44 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VPattern::SetGradationHeights(const QMap<GHeights, bool> &options)
|
|
|
|
|
{
|
|
|
|
|
CheckTagExists(TagGradation);
|
|
|
|
|
QDomNodeList tags = elementsByTagName(TagGradation);
|
|
|
|
|
if (tags.size() == 0)
|
|
|
|
|
{
|
|
|
|
|
qDebug()<<"Can't save tag "<<TagGradation<<Q_FUNC_INFO;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList gTags{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));
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
emit patternChanged(false);
|
|
|
|
|
return;
|
|
|
|
|
break;
|
|
|
|
|
case 1: // TagSizes
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
domNode = domNode.nextSibling();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 13:17:24 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QMap<GSizes, bool> VPattern::GetGradationSizes() const
|
|
|
|
|
{
|
|
|
|
|
QMap<GSizes, bool> map;
|
2014-08-08 18:07:44 +02:00
|
|
|
|
map.insert(GSizes::ALL, true);
|
2014-08-07 13:17:24 +02:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
QDomNodeList tags = elementsByTagName(TagGradation);
|
|
|
|
|
if (tags.size() == 0)
|
|
|
|
|
{
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList gTags{TagHeights, TagSizes};
|
|
|
|
|
QDomNode domNode = tags.at(0).firstChild();
|
|
|
|
|
while (domNode.isNull() == false)
|
|
|
|
|
{
|
|
|
|
|
if (domNode.isElement())
|
|
|
|
|
{
|
|
|
|
|
const QDomElement domElement = domNode.toElement();
|
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
|
{
|
|
|
|
|
const QString defValue = QStringLiteral("true");
|
|
|
|
|
switch (gTags.indexOf(domElement.tagName()))
|
|
|
|
|
{
|
|
|
|
|
case 0: // TagHeights
|
|
|
|
|
break;
|
|
|
|
|
case 1: // TagSizes
|
|
|
|
|
if (GetParametrBool(domElement, AttrAll, defValue))
|
|
|
|
|
{
|
|
|
|
|
return map;
|
|
|
|
|
}
|
2014-08-08 18:07:44 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
map.insert(GSizes::ALL, false);
|
|
|
|
|
}
|
2014-08-07 13:17:24 +02:00
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
return map;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
domNode = domNode.nextSibling();
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-08 18:07:44 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VPattern::SetGradationSizes(const QMap<GSizes, bool> &options)
|
|
|
|
|
{
|
|
|
|
|
CheckTagExists(TagGradation);
|
|
|
|
|
QDomNodeList tags = elementsByTagName(TagGradation);
|
|
|
|
|
if (tags.size() == 0)
|
|
|
|
|
{
|
|
|
|
|
qDebug()<<"Can't save tag "<<TagGradation<<Q_FUNC_INFO;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList gTags{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
|
|
|
|
|
break;
|
|
|
|
|
case 1: // TagSizes
|
|
|
|
|
SetAttribute(domElement, AttrAll, options.value(GSizes::ALL));
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
emit patternChanged(false);
|
|
|
|
|
return;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
domNode = domNode.nextSibling();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QString VPattern::GetAuthor() const
|
|
|
|
|
{
|
|
|
|
|
QSettings *settings = qApp->getSettings();
|
|
|
|
|
SCASSERT(settings != nullptr);
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
QString user = settings->value("pattern/user", QString::fromLocal8Bit(qgetenv("USERNAME").constData())).toString();
|
|
|
|
|
#else
|
|
|
|
|
QString user = settings->value("pattern/user", QString::fromLocal8Bit(qgetenv("USER").constData())).toString();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return UniqueTagText(TagAuthor, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VPattern::SetAuthor(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
CheckTagExists(TagAuthor);
|
|
|
|
|
setTagText(TagAuthor, text);
|
|
|
|
|
emit patternChanged(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QString VPattern::GetDescription() const
|
|
|
|
|
{
|
|
|
|
|
return UniqueTagText(TagDescription);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VPattern::SetDescription(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
CheckTagExists(TagDescription);
|
|
|
|
|
setTagText(TagDescription, text);
|
|
|
|
|
emit patternChanged(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QString VPattern::GetNotes() const
|
|
|
|
|
{
|
|
|
|
|
return UniqueTagText(TagNotes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VPattern::SetNotes(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
CheckTagExists(TagNotes);
|
|
|
|
|
setTagText(TagNotes, text);
|
|
|
|
|
emit patternChanged(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QString VPattern::GetVersion() const
|
|
|
|
|
{
|
|
|
|
|
return UniqueTagText(TagVersion, VAL_STR_VERSION);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VPattern::SetVersion()
|
|
|
|
|
{
|
|
|
|
|
setTagText(TagVersion, VAL_STR_VERSION);
|
|
|
|
|
emit patternChanged(false);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-05 10:01:46 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QString VPattern::GenerateLabel(const LabelType &type) const
|
|
|
|
|
{
|
|
|
|
|
QDomNodeList drawList = elementsByTagName(TagDraw);
|
|
|
|
|
|
|
|
|
|
if (type == LabelType::NewPatternPiece)
|
|
|
|
|
{
|
|
|
|
|
QString name;
|
|
|
|
|
int i = 0;
|
2014-09-10 19:57:08 +02:00
|
|
|
|
for (;;)
|
2014-09-05 10:01:46 +02:00
|
|
|
|
{
|
2014-09-11 18:52:02 +02:00
|
|
|
|
name = GetLabelBase(static_cast<unsigned int>(drawList.size() + i));
|
2014-09-05 10:01:46 +02:00
|
|
|
|
if (data->IsUnique(name))
|
|
|
|
|
{
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
if (i == INT_MAX)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
else if (type == LabelType::NewLabel)
|
|
|
|
|
{
|
|
|
|
|
if (drawList.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return GetLabelBase(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
for (int i = 0; i < drawList.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
QDomElement node = drawList.at(i).toElement();
|
|
|
|
|
if (node.attribute(AttrName) == nameActivPP)
|
|
|
|
|
{
|
|
|
|
|
index = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-11 18:52:02 +02:00
|
|
|
|
QString labelBase = GetLabelBase(static_cast<unsigned int>(index));
|
2014-09-05 10:01:46 +02:00
|
|
|
|
|
|
|
|
|
qint32 num = 1;
|
|
|
|
|
QString name;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
name = QString("%1%2").arg(labelBase).arg(num);
|
|
|
|
|
num++;
|
|
|
|
|
if (num == INT_MAX)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} while (data->IsUnique(name) == false);
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-05 12:02:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief CollectId recursive function, try find id attribute in file. Throw exclusion if find not unique.
|
|
|
|
|
* @param node tag in xml tree.
|
|
|
|
|
* @param vector list with ids.
|
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
|
void VPattern::CollectId(const QDomElement &node, QVector<quint32> &vector) const
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-03-21 11:08:29 +01:00
|
|
|
|
if (node.hasAttribute(VDomDocument::AttrId))
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
|
const quint32 id = GetParametrId(node);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
if (vector.contains(id))
|
|
|
|
|
{
|
2014-03-03 18:32:38 +01:00
|
|
|
|
throw VExceptionWrongId(tr("This id is not unique."), node);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
|
|
|
|
vector.append(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (qint32 i=0; i<node.childNodes().length(); ++i)
|
|
|
|
|
{
|
|
|
|
|
const QDomNode n = node.childNodes().at(i);
|
|
|
|
|
if (n.isElement())
|
|
|
|
|
{
|
|
|
|
|
CollectId(n.toElement(), vector);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-12 09:22:29 +02:00
|
|
|
|
void VPattern::PrepareForParse(const Document &parse)
|
2014-02-25 15:02:09 +01:00
|
|
|
|
{
|
2014-06-05 13:46:12 +02:00
|
|
|
|
SCASSERT(sceneDraw != nullptr);
|
|
|
|
|
SCASSERT(sceneDetail != nullptr);
|
2014-02-25 15:02:09 +01:00
|
|
|
|
if (parse == Document::FullParse)
|
|
|
|
|
{
|
|
|
|
|
TestUniqueId();
|
2014-10-04 21:12:46 +02:00
|
|
|
|
sceneDraw->clear();
|
|
|
|
|
sceneDetail->clear();
|
2014-02-25 15:02:09 +01:00
|
|
|
|
data->Clear();
|
2014-03-24 16:02:57 +01:00
|
|
|
|
UpdateMeasurements();
|
2014-07-17 14:41:48 +02:00
|
|
|
|
nameActivPP.clear();
|
2014-06-05 13:35:38 +02:00
|
|
|
|
patternPieces.clear();
|
2014-02-25 15:02:09 +01:00
|
|
|
|
tools.clear();
|
|
|
|
|
cursor = 0;
|
2014-07-29 13:28:18 +02:00
|
|
|
|
history.clear();
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
2014-09-04 07:20:41 +02:00
|
|
|
|
else if (parse == Document::LiteParse)
|
|
|
|
|
{
|
|
|
|
|
data->ClearUniqueNames();
|
2014-09-08 10:23:53 +02:00
|
|
|
|
data->ClearVariables(VarType::ArcLength);
|
|
|
|
|
data->ClearVariables(VarType::LineAngle);
|
|
|
|
|
data->ClearVariables(VarType::LineLength);
|
|
|
|
|
data->ClearVariables(VarType::SplineLength);
|
2014-09-04 07:20:41 +02:00
|
|
|
|
}
|
2014-02-25 15:02:09 +01:00
|
|
|
|
}
|
2014-03-24 16:02:57 +01:00
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-03-24 16:02:57 +01:00
|
|
|
|
void VPattern::UpdateMeasurements()
|
|
|
|
|
{
|
2014-09-16 21:08:48 +02:00
|
|
|
|
try
|
2014-03-24 16:02:57 +01:00
|
|
|
|
{
|
2014-09-16 21:08:48 +02:00
|
|
|
|
const QString path = MPath();
|
|
|
|
|
if (MType() == MeasurementsType::Standard)
|
|
|
|
|
{
|
|
|
|
|
VStandardMeasurements m(data);
|
|
|
|
|
ValidateXML("://schema/standard_measurements.xsd", path);
|
|
|
|
|
m.setContent(path);
|
|
|
|
|
m.Measurements();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
VIndividualMeasurements m(data);
|
|
|
|
|
ValidateXML("://schema/individual_measurements.xsd", path);
|
|
|
|
|
m.setContent(path);
|
|
|
|
|
m.Measurements();
|
|
|
|
|
}
|
2014-03-24 16:02:57 +01:00
|
|
|
|
}
|
2014-09-16 21:08:48 +02:00
|
|
|
|
catch (VException &e)
|
2014-03-24 16:02:57 +01:00
|
|
|
|
{
|
2014-09-16 21:08:48 +02:00
|
|
|
|
e.CriticalMessageBox(tr("File error."), qApp->getMainWindow());
|
|
|
|
|
emit ClearMainWindow();
|
|
|
|
|
return;
|
2014-03-24 16:02:57 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-06 17:06:41 +02:00
|
|
|
|
|
2014-06-12 11:51:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VPattern::GarbageCollector()
|
|
|
|
|
{
|
|
|
|
|
QHashIterator<quint32, VDataTool*> t(tools);
|
2014-06-16 19:08:23 +02:00
|
|
|
|
while (t.hasNext())
|
|
|
|
|
{
|
2014-06-12 11:51:40 +02:00
|
|
|
|
t.next();
|
|
|
|
|
VDataTool *tool = t.value();
|
2014-06-16 19:18:36 +02:00
|
|
|
|
if (tool->referens() <= 1)
|
2014-06-16 19:08:23 +02:00
|
|
|
|
{
|
2014-06-12 11:51:40 +02:00
|
|
|
|
QDomElement domElement = elementById(QString().setNum(t.key()));
|
2014-06-16 19:18:36 +02:00
|
|
|
|
if (domElement.isElement())
|
2014-06-16 19:08:23 +02:00
|
|
|
|
{
|
2014-06-12 11:51:40 +02:00
|
|
|
|
QDomNode parent = domElement.parentNode();
|
2014-06-16 19:18:36 +02:00
|
|
|
|
if (parent.isNull() == false && parent.toElement().tagName() == TagModeling)
|
2014-06-16 19:08:23 +02:00
|
|
|
|
{
|
2014-06-12 11:51:40 +02:00
|
|
|
|
parent.removeChild(domElement);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-06 17:06:41 +02:00
|
|
|
|
|
2014-06-12 11:51:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-18 18:11:14 +02:00
|
|
|
|
void VPattern::ToolsCommonAttributes(const QDomElement &domElement, quint32 &id)
|
|
|
|
|
{
|
|
|
|
|
id = GetParametrId(domElement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-06 17:06:41 +02:00
|
|
|
|
QDomElement VPattern::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();
|
|
|
|
|
}
|
2014-06-15 10:04:49 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
int VPattern::CountPP() const
|
|
|
|
|
{
|
|
|
|
|
const QDomElement rootElement = this->documentElement();
|
|
|
|
|
if (rootElement.isNull())
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rootElement.elementsByTagName( TagDraw ).count();
|
|
|
|
|
}
|
2014-07-12 18:25:25 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QRectF VPattern::ActiveDrawBoundingRect() const
|
|
|
|
|
{
|
|
|
|
|
QRectF rec;
|
|
|
|
|
|
|
|
|
|
for (qint32 i = 0; i< history.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
const VToolRecord tool = history.at(i);
|
2014-07-17 14:41:48 +02:00
|
|
|
|
if (tool.getNameDraw() == nameActivPP)
|
2014-07-12 18:25:25 +02:00
|
|
|
|
{
|
|
|
|
|
switch ( tool.getTypeTool() )
|
|
|
|
|
{
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::Arrow:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
|
break;
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::SinglePoint:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
rec = ToolBoundingRect<VToolSinglePoint>(rec, tool.getId());
|
|
|
|
|
break;
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::EndLine:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
rec = ToolBoundingRect<VToolEndLine>(rec, tool.getId());
|
|
|
|
|
break;
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::Line:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
rec = ToolBoundingRect<VToolLine>(rec, tool.getId());
|
|
|
|
|
break;
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::AlongLine:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
rec = ToolBoundingRect<VToolAlongLine>(rec, tool.getId());
|
|
|
|
|
break;
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::ShoulderPoint:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
rec = ToolBoundingRect<VToolShoulderPoint>(rec, tool.getId());
|
|
|
|
|
break;
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::Normal:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
rec = ToolBoundingRect<VToolNormal>(rec, tool.getId());
|
|
|
|
|
break;
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::Bisector:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
rec = ToolBoundingRect<VToolBisector>(rec, tool.getId());
|
|
|
|
|
break;
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::LineIntersect:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
rec = ToolBoundingRect<VToolLineIntersect>(rec, tool.getId());
|
|
|
|
|
break;
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::Spline:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
rec = ToolBoundingRect<VToolSpline>(rec, tool.getId());
|
|
|
|
|
break;
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::Arc:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
rec = ToolBoundingRect<VToolArc>(rec, tool.getId());
|
|
|
|
|
break;
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::SplinePath:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
rec = ToolBoundingRect<VToolSplinePath>(rec, tool.getId());
|
|
|
|
|
break;
|
|
|
|
|
case Tool::PointOfContact:
|
|
|
|
|
rec = ToolBoundingRect<VToolPointOfContact>(rec, tool.getId());
|
|
|
|
|
break;
|
|
|
|
|
case Tool::Height:
|
|
|
|
|
rec = ToolBoundingRect<VToolHeight>(rec, tool.getId());
|
|
|
|
|
break;
|
|
|
|
|
case Tool::Triangle:
|
|
|
|
|
rec = ToolBoundingRect<VToolTriangle>(rec, tool.getId());
|
|
|
|
|
break;
|
|
|
|
|
case Tool::PointOfIntersection:
|
|
|
|
|
rec = ToolBoundingRect<VToolPointOfIntersection>(rec, tool.getId());
|
|
|
|
|
break;
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::CutArc:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
rec = ToolBoundingRect<VToolCutArc>(rec, tool.getId());
|
|
|
|
|
break;
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::CutSpline:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
rec = ToolBoundingRect<VToolCutSpline>(rec, tool.getId());
|
|
|
|
|
break;
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::CutSplinePath:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
rec = ToolBoundingRect<VToolCutSplinePath>(rec, tool.getId());
|
|
|
|
|
break;
|
|
|
|
|
//Because "history" not only show history of pattern, but help restore current data for each pattern's
|
|
|
|
|
//piece, we need add record about details and nodes, but don't show them.
|
2014-08-26 20:31:28 +02:00
|
|
|
|
case Tool::Detail:
|
2014-07-12 18:25:25 +02:00
|
|
|
|
break;
|
|
|
|
|
case Tool::UnionDetails:
|
|
|
|
|
break;
|
|
|
|
|
case Tool::NodeArc:
|
|
|
|
|
break;
|
|
|
|
|
case Tool::NodePoint:
|
|
|
|
|
break;
|
|
|
|
|
case Tool::NodeSpline:
|
|
|
|
|
break;
|
|
|
|
|
case Tool::NodeSplinePath:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
qDebug()<<"Got wrong tool type. Ignore.";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return rec;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-29 17:23:18 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-07-12 18:25:25 +02:00
|
|
|
|
template <typename T>
|
|
|
|
|
QRectF VPattern::ToolBoundingRect(const QRectF &rec, const quint32 &id) const
|
|
|
|
|
{
|
2014-07-13 14:49:00 +02:00
|
|
|
|
QRectF recTool = rec;
|
2014-07-12 18:25:25 +02:00
|
|
|
|
if (tools.contains(id))
|
|
|
|
|
{
|
|
|
|
|
T *vTool = qobject_cast<T *>(tools.value(id));
|
|
|
|
|
SCASSERT(vTool != nullptr);
|
|
|
|
|
|
|
|
|
|
QRectF childrenRect = vTool->childrenBoundingRect();
|
|
|
|
|
//map to scene coordinate.
|
|
|
|
|
childrenRect.translate(vTool->scenePos());
|
|
|
|
|
|
2014-07-13 14:49:00 +02:00
|
|
|
|
recTool = recTool.united(vTool->boundingRect());
|
|
|
|
|
recTool = recTool.united(childrenRect);
|
2014-07-12 18:25:25 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qDebug()<<"Can't find tool with id="<<id;
|
|
|
|
|
}
|
|
|
|
|
return recTool;
|
|
|
|
|
}
|