2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vabstracttool.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2013-11-15 13:41:26 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2013-11-15 13:41:26 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-07-25 20:39:51 +02:00
|
|
|
#include "vabstracttool.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QBrush>
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QFlags>
|
|
|
|
#include <QGraphicsEllipseItem>
|
|
|
|
#include <QGraphicsLineItem>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QLineF>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QPointF>
|
|
|
|
#include <QRectF>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QStaticStringData>
|
|
|
|
#include <QStringData>
|
|
|
|
#include <QStringDataPtr>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QUndoStack>
|
|
|
|
#include <QVector>
|
|
|
|
#include <new>
|
2017-01-21 14:24:40 +01:00
|
|
|
#include <qnumeric.h>
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vpropertyexplorer/checkablemessagebox.h"
|
|
|
|
#include "../vwidgets/vmaingraphicsview.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../ifc/exception/vexception.h"
|
2017-01-21 14:24:40 +01:00
|
|
|
#include "../ifc/exception/vexceptionundo.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../ifc/xml/vtoolrecord.h"
|
2015-06-18 19:23:24 +02:00
|
|
|
#include "../undocommands/deltool.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vgeometry/../ifc/ifcdef.h"
|
|
|
|
#include "../vgeometry/vgeometrydef.h"
|
|
|
|
#include "../vgeometry/vgobject.h"
|
2017-01-18 09:17:18 +01:00
|
|
|
#include "../vgeometry/vcubicbezier.h"
|
|
|
|
#include "../vgeometry/vcubicbezierpath.h"
|
|
|
|
#include "../vgeometry/vsplinepath.h"
|
|
|
|
#include "../vgeometry/varc.h"
|
|
|
|
#include "../vgeometry/vellipticalarc.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vmisc/vcommonsettings.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../vmisc/logging.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2016-11-28 10:58:44 +01:00
|
|
|
#include "../vpatterndb/vpiecenode.h"
|
2017-01-21 14:24:40 +01:00
|
|
|
#include "../vpatterndb/calculator.h"
|
2015-12-11 15:20:32 +01:00
|
|
|
#include "../vwidgets/vgraphicssimpletextitem.h"
|
2017-01-18 09:17:18 +01:00
|
|
|
#include "nodeDetails/nodedetails.h"
|
2017-01-21 14:24:40 +01:00
|
|
|
#include "../dialogs/support/dialogundo.h"
|
|
|
|
#include "../dialogs/support/dialogeditwrongformula.h"
|
2015-06-18 19:23:24 +02:00
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
template <class T> class QSharedPointer;
|
2013-07-25 20:39:51 +02:00
|
|
|
|
2015-12-26 18:10:02 +01:00
|
|
|
const QString VAbstractTool::AttrInUse = QStringLiteral("inUse");
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief VAbstractTool container.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with data.
|
|
|
|
* @param id object id in container.
|
|
|
|
* @param parent parent object.
|
|
|
|
*/
|
2015-06-16 17:01:17 +02:00
|
|
|
VAbstractTool::VAbstractTool(VAbstractPattern *doc, VContainer *data, quint32 id, QObject *parent)
|
2017-06-16 13:53:08 +02:00
|
|
|
:VDataTool(data, parent),
|
|
|
|
doc(doc),
|
2017-09-17 08:45:18 +02:00
|
|
|
m_id(id),
|
2017-06-16 13:53:08 +02:00
|
|
|
vis(),
|
2016-03-31 19:10:20 +02:00
|
|
|
selectionType(SelectionType::ByMouseRelease)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(doc != nullptr)
|
2015-06-16 17:01:17 +02:00
|
|
|
connect(this, &VAbstractTool::toolhaveChange, this->doc, &VAbstractPattern::haveLiteChange);
|
|
|
|
connect(this->doc, &VAbstractPattern::FullUpdateFromFile, this, &VAbstractTool::FullUpdateFromFile);
|
|
|
|
connect(this, &VAbstractTool::LiteUpdateTree, this->doc, &VAbstractPattern::LiteParseTree);
|
2013-08-15 22:39:00 +02:00
|
|
|
}
|
|
|
|
|
2014-09-03 15:52:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VAbstractTool::~VAbstractTool()
|
2016-09-24 15:09:09 +02:00
|
|
|
{
|
|
|
|
if (not vis.isNull())
|
|
|
|
{
|
|
|
|
delete vis;
|
|
|
|
}
|
|
|
|
}
|
2014-09-03 15:52:16 +02:00
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief CheckFormula check formula.
|
|
|
|
*
|
|
|
|
* Try calculate formula. If find error show dialog that allow user try fix formula. If user can't throw exception. In
|
|
|
|
* successes case return result calculation and fixed formula string. If formula ok don't touch formula.
|
|
|
|
*
|
|
|
|
* @param toolId [in] tool's id.
|
|
|
|
* @param formula [in|out] string with formula.
|
|
|
|
* @param data [in] container with variables. Need for math parser.
|
|
|
|
* @throw QmuParserError.
|
|
|
|
* @return result of calculation formula.
|
|
|
|
*/
|
|
|
|
qreal VAbstractTool::CheckFormula(const quint32 &toolId, QString &formula, VContainer *data)
|
|
|
|
{
|
|
|
|
SCASSERT(data != nullptr)
|
|
|
|
qreal result = 0;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
QScopedPointer<Calculator> cal(new Calculator());
|
2017-08-04 19:29:43 +02:00
|
|
|
result = cal->EvalFormula(data->DataVariables(), formula);
|
2017-01-21 14:24:40 +01:00
|
|
|
|
|
|
|
if (qIsInf(result) || qIsNaN(result))
|
|
|
|
{
|
|
|
|
qDebug() << "Invalid the formula value";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (qmu::QmuParserError &e)
|
|
|
|
{
|
|
|
|
qDebug() << "\nMath parser error:\n"
|
|
|
|
<< "--------------------------------------\n"
|
|
|
|
<< "Message: " << e.GetMsg() << "\n"
|
|
|
|
<< "Expression: " << e.GetExpr() << "\n"
|
|
|
|
<< "--------------------------------------";
|
|
|
|
|
|
|
|
if (qApp->IsAppInGUIMode())
|
|
|
|
{
|
|
|
|
QScopedPointer<DialogUndo> dialogUndo(new DialogUndo(qApp->getMainWindow()));
|
|
|
|
forever
|
|
|
|
{
|
|
|
|
if (dialogUndo->exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
const UndoButton resultUndo = dialogUndo->Result();
|
|
|
|
if (resultUndo == UndoButton::Fix)
|
|
|
|
{
|
|
|
|
auto *dialog = new DialogEditWrongFormula(data, toolId, qApp->getMainWindow());
|
|
|
|
dialog->setWindowTitle(tr("Edit wrong formula"));
|
|
|
|
dialog->SetFormula(formula);
|
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
formula = dialog->GetFormula();
|
|
|
|
/* Need delete dialog here because parser in dialog don't allow use correct separator for
|
|
|
|
* parsing here. */
|
|
|
|
delete dialog;
|
|
|
|
QScopedPointer<Calculator> cal1(new Calculator());
|
2017-08-04 19:29:43 +02:00
|
|
|
result = cal1->EvalFormula(data->DataVariables(), formula);
|
2017-01-21 14:24:40 +01:00
|
|
|
|
|
|
|
if (qIsInf(result) || qIsNaN(result))
|
|
|
|
{
|
|
|
|
qDebug() << "Invalid the formula value";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw VExceptionUndo(QString("Undo wrong formula %1").arg(formula));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief DeleteTool full delete object form scene and file.
|
|
|
|
*/
|
2017-10-19 10:24:21 +02:00
|
|
|
void VAbstractTool::DeleteToolWithConfirm(bool ask)
|
2014-01-03 16:13:43 +01:00
|
|
|
{
|
2015-11-03 16:11:35 +01:00
|
|
|
qCDebug(vTool, "Deleting abstract tool.");
|
2014-09-26 19:09:20 +02:00
|
|
|
if (_referens <= 1)
|
2014-01-03 16:13:43 +01:00
|
|
|
{
|
2015-11-03 16:11:35 +01:00
|
|
|
qCDebug(vTool, "No children.");
|
2014-09-26 19:09:20 +02:00
|
|
|
qApp->getSceneView()->itemClicked(nullptr);
|
|
|
|
if (ask)
|
2014-06-15 19:07:54 +02:00
|
|
|
{
|
2015-11-03 16:11:35 +01:00
|
|
|
qCDebug(vTool, "Asking.");
|
2015-02-25 23:27:09 +01:00
|
|
|
if (ConfirmDeletion() == QMessageBox::No)
|
2014-09-26 19:09:20 +02:00
|
|
|
{
|
2015-11-03 16:11:35 +01:00
|
|
|
qCDebug(vTool, "User said no.");
|
2014-09-26 19:09:20 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-06-15 19:07:54 +02:00
|
|
|
}
|
2015-11-03 16:11:35 +01:00
|
|
|
|
|
|
|
qCDebug(vTool, "Begin deleting.");
|
2017-09-17 08:45:18 +02:00
|
|
|
DelTool *delTool = new DelTool(doc, m_id);
|
2016-07-19 19:50:42 +02:00
|
|
|
connect(delTool, &DelTool::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing);
|
2014-09-26 19:09:20 +02:00
|
|
|
qApp->getUndoStack()->push(delTool);
|
2015-11-02 17:25:29 +01:00
|
|
|
|
|
|
|
// Throw exception, this will help prevent case when we forget to immediately quit function.
|
|
|
|
VExceptionToolWasDeleted e("Tool was used after deleting.");
|
|
|
|
throw e;
|
2014-01-03 16:13:43 +01:00
|
|
|
}
|
2015-11-03 16:11:35 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qCDebug(vTool, "Can't delete, tool has children.");
|
|
|
|
}
|
2014-01-03 16:13:43 +01:00
|
|
|
}
|
|
|
|
|
2015-02-25 23:27:09 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VAbstractTool::ConfirmDeletion()
|
|
|
|
{
|
2015-06-18 10:49:25 +02:00
|
|
|
if (false == qApp->Settings()->GetConfirmItemDelete())
|
2015-02-26 22:34:33 +01:00
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
return QMessageBox::Yes;
|
2015-02-26 22:34:33 +01:00
|
|
|
}
|
2015-02-25 23:27:09 +01:00
|
|
|
|
|
|
|
Utils::CheckableMessageBox msgBox(qApp->getMainWindow());
|
|
|
|
msgBox.setWindowTitle(tr("Confirm deletion"));
|
|
|
|
msgBox.setText(tr("Do you really want to delete?"));
|
|
|
|
msgBox.setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No);
|
|
|
|
msgBox.setDefaultButton(QDialogButtonBox::No);
|
2017-03-23 09:25:46 +01:00
|
|
|
msgBox.setIconPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion).pixmap(32, 32) );
|
2015-02-25 23:27:09 +01:00
|
|
|
|
|
|
|
int dialogResult = msgBox.exec();
|
|
|
|
|
|
|
|
if (dialogResult == QDialog::Accepted)
|
2015-02-26 22:34:33 +01:00
|
|
|
{
|
2015-06-18 10:49:25 +02:00
|
|
|
qApp->Settings()->SetConfirmItemDelete(not msgBox.isChecked());
|
2015-02-26 22:34:33 +01:00
|
|
|
}
|
2015-02-25 23:27:09 +01:00
|
|
|
|
|
|
|
return dialogResult == QDialog::Accepted ? QMessageBox::Yes : QMessageBox::No;
|
|
|
|
}
|
|
|
|
|
2015-02-02 10:29:50 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
const QStringList VAbstractTool::Colors()
|
|
|
|
{
|
2016-10-16 19:23:40 +02:00
|
|
|
const QStringList colors = QStringList() << ColorBlack << ColorGreen << ColorBlue
|
|
|
|
<< ColorDarkRed << ColorDarkGreen << ColorDarkBlue
|
|
|
|
<< ColorYellow << ColorLightSalmon << ColorGoldenRod
|
|
|
|
<< ColorOrange << ColorDeepPink << ColorViolet
|
|
|
|
<< ColorDarkViolet << ColorMediumSeaGreen << ColorLime
|
|
|
|
<< ColorDeepSkyBlue << ColorCornFlowerBlue;
|
2015-02-02 10:29:50 +01:00
|
|
|
return colors;
|
|
|
|
}
|
|
|
|
|
2015-02-07 13:31:10 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QMap<QString, QString> VAbstractTool::ColorsList()
|
|
|
|
{
|
|
|
|
QMap<QString, QString> map;
|
|
|
|
|
|
|
|
const QStringList colorNames = Colors();
|
|
|
|
for (int i = 0; i < colorNames.size(); ++i)
|
|
|
|
{
|
|
|
|
QString name;
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 1: // ColorGreen
|
|
|
|
name = tr("green");
|
|
|
|
break;
|
|
|
|
case 2: // ColorBlue
|
|
|
|
name = tr("blue");
|
|
|
|
break;
|
|
|
|
case 3: // ColorDarkRed
|
|
|
|
name = tr("dark red");
|
|
|
|
break;
|
|
|
|
case 4: // ColorDarkGreen
|
|
|
|
name = tr("dark green");
|
|
|
|
break;
|
|
|
|
case 5: // ColorDarkBlue
|
|
|
|
name = tr("dark blue");
|
|
|
|
break;
|
|
|
|
case 6: // ColorYellow
|
|
|
|
name = tr("yellow");
|
|
|
|
break;
|
2016-10-16 19:23:40 +02:00
|
|
|
case 7: // ColorLightSalmon
|
|
|
|
name = tr("light salmon");
|
|
|
|
break;
|
|
|
|
case 8: // ColorGoldenRod
|
2017-04-21 16:28:25 +02:00
|
|
|
name = tr("goldenrod");
|
2016-10-16 19:23:40 +02:00
|
|
|
break;
|
|
|
|
case 9: // ColorOrange
|
|
|
|
name = tr("orange");
|
|
|
|
break;
|
|
|
|
case 10: // ColorDeepPink
|
|
|
|
name = tr("deep pink");
|
|
|
|
break;
|
|
|
|
case 11: // ColorViolet
|
|
|
|
name = tr("violet");
|
|
|
|
break;
|
|
|
|
case 12: // ColorDarkViolet
|
|
|
|
name = tr("dark violet");
|
|
|
|
break;
|
|
|
|
case 13: // ColorMediumSeaGreen
|
|
|
|
name = tr("medium sea green");
|
|
|
|
break;
|
|
|
|
case 14: // ColorLime
|
|
|
|
name = tr("lime");
|
|
|
|
break;
|
|
|
|
case 15: // ColorDeepSkyBlue
|
|
|
|
name = tr("deep sky blue");
|
|
|
|
break;
|
|
|
|
case 16: // ColorCornFlowerBlue
|
|
|
|
name = tr("corn flower blue");
|
|
|
|
break;
|
2016-12-21 20:35:07 +01:00
|
|
|
case 0: // ColorBlack
|
2015-02-07 13:31:10 +01:00
|
|
|
default:
|
|
|
|
name = tr("black");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
map.insert(colorNames.at(i), name);
|
|
|
|
}
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2014-08-30 21:58:31 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2014-08-28 13:05:58 +02:00
|
|
|
QMap<QString, quint32> VAbstractTool::PointsList() const
|
|
|
|
{
|
2017-10-26 11:54:08 +02:00
|
|
|
const QHash<quint32, QSharedPointer<VGObject> > *objs = data.CalculationGObjects();
|
2014-08-28 13:05:58 +02:00
|
|
|
QMap<QString, quint32> list;
|
|
|
|
QHash<quint32, QSharedPointer<VGObject> >::const_iterator i;
|
|
|
|
for (i = objs->constBegin(); i != objs->constEnd(); ++i)
|
|
|
|
{
|
2017-09-17 08:45:18 +02:00
|
|
|
if (i.key() != m_id)
|
2014-08-28 13:05:58 +02:00
|
|
|
{
|
|
|
|
QSharedPointer<VGObject> obj = i.value();
|
2017-10-26 11:54:08 +02:00
|
|
|
if (obj->getType() == GOType::Point)
|
2014-08-28 13:05:58 +02:00
|
|
|
{
|
|
|
|
const QSharedPointer<VPointF> point = data.GeometricObject<VPointF>(i.key());
|
|
|
|
list[point->name()] = i.key();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2017-10-24 19:25:51 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractTool::ChangeLabelPosition(quint32 id, const QPointF &pos)
|
|
|
|
{
|
|
|
|
Q_UNUSED(id)
|
|
|
|
Q_UNUSED(pos)
|
|
|
|
}
|
|
|
|
|
2015-05-28 12:16:59 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-31 19:10:20 +02:00
|
|
|
void VAbstractTool::ToolSelectionType(const SelectionType &type)
|
|
|
|
{
|
|
|
|
selectionType = type;
|
|
|
|
}
|
|
|
|
|
2017-08-02 10:34:44 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractTool::RefreshDataInFile()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2016-03-31 19:10:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-05-28 12:16:59 +02:00
|
|
|
void VAbstractTool::ToolCreation(const Source &typeCreation)
|
|
|
|
{
|
|
|
|
if (typeCreation == Source::FromGui)
|
|
|
|
{
|
|
|
|
AddToFile();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RefreshDataInFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-10-18 15:40:20 +02:00
|
|
|
VToolRecord VAbstractTool::GetRecord(const quint32 id, const Tool &toolType, VAbstractPattern *doc)
|
|
|
|
{
|
|
|
|
QVector<VToolRecord> *history = doc->getHistory();
|
|
|
|
for(int i = 0; i < history->size(); ++i)
|
|
|
|
{
|
|
|
|
if (history->at(i).getId() == id && history->at(i).getTypeTool() == toolType)
|
|
|
|
{
|
|
|
|
return history->at(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return VToolRecord();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractTool::RemoveRecord(const VToolRecord &record, VAbstractPattern *doc)
|
|
|
|
{
|
|
|
|
QVector<VToolRecord> *history = doc->getHistory();
|
|
|
|
for(int i = 0; i < history->size(); ++i)
|
|
|
|
{
|
|
|
|
if (history->at(i) == record)
|
|
|
|
{
|
|
|
|
history->remove(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractTool::AddRecord(const VToolRecord &record, VAbstractPattern *doc)
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
|
|
|
QVector<VToolRecord> *history = doc->getHistory();
|
2014-07-29 17:23:18 +02:00
|
|
|
if (history->contains(record))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 cursor = doc->getCursor();
|
2016-08-02 14:12:13 +02:00
|
|
|
if (cursor == NULL_ID)
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2014-07-29 17:23:18 +02:00
|
|
|
history->append(record);
|
2014-01-02 16:50:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qint32 index = 0;
|
|
|
|
for (qint32 i = 0; i<history->size(); ++i)
|
|
|
|
{
|
|
|
|
VToolRecord rec = history->at(i);
|
|
|
|
if (rec.getId() == cursor)
|
|
|
|
{
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-07-29 17:23:18 +02:00
|
|
|
history->insert(index+1, record);
|
2014-01-02 16:50:01 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-11 10:31:21 +01:00
|
|
|
|
2017-10-18 15:40:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief AddRecord add record about tool in history.
|
|
|
|
* @param id object id in container
|
|
|
|
* @param toolType tool type
|
|
|
|
* @param doc dom document container
|
|
|
|
*/
|
|
|
|
void VAbstractTool::AddRecord(const quint32 id, const Tool &toolType, VAbstractPattern *doc)
|
|
|
|
{
|
|
|
|
AddRecord(VToolRecord(id, toolType, doc->GetNameActivPP()), doc);
|
|
|
|
}
|
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractTool::AddNodes(VAbstractPattern *doc, QDomElement &domElement, const VPiecePath &path)
|
|
|
|
{
|
|
|
|
if (path.CountNodes() > 0)
|
|
|
|
{
|
|
|
|
QDomElement nodesElement = doc->createElement(VAbstractPattern::TagNodes);
|
|
|
|
for (int i = 0; i < path.CountNodes(); ++i)
|
|
|
|
{
|
|
|
|
AddNode(doc, nodesElement, path.at(i));
|
|
|
|
}
|
|
|
|
domElement.appendChild(nodesElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractTool::AddNodes(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
|
|
|
|
{
|
|
|
|
AddNodes(doc, domElement, piece.GetPath());
|
|
|
|
}
|
|
|
|
|
2016-11-28 10:58:44 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDomElement VAbstractTool::AddSANode(VAbstractPattern *doc, const QString &tagName, const VPieceNode &node)
|
|
|
|
{
|
|
|
|
QDomElement nod = doc->createElement(tagName);
|
|
|
|
|
|
|
|
doc->SetAttribute(nod, AttrIdObject, node.GetId());
|
|
|
|
|
|
|
|
const Tool type = node.GetTypeTool();
|
|
|
|
if (type != Tool::NodePoint)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(nod, VAbstractPattern::AttrNodeReverse, static_cast<quint8>(node.GetReverse()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
if (node.GetFormulaSABefore() != currentSeamAllowance)
|
2016-11-28 10:58:44 +01:00
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
doc->SetAttribute(nod, VAbstractPattern::AttrSABefore, node.GetFormulaSABefore());
|
2016-11-28 10:58:44 +01:00
|
|
|
}
|
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
if (node.GetFormulaSAAfter() != currentSeamAllowance)
|
2016-11-28 10:58:44 +01:00
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
doc->SetAttribute(nod, VAbstractPattern::AttrSAAfter, node.GetFormulaSAAfter());
|
2016-11-28 10:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-21 16:18:48 +01:00
|
|
|
{
|
2017-04-26 10:22:42 +02:00
|
|
|
const bool excluded = node.IsExcluded();
|
|
|
|
if (excluded)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(nod, VAbstractPattern::AttrNodeExcluded, excluded);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // For backward compatebility.
|
|
|
|
nod.removeAttribute(VAbstractPattern::AttrNodeExcluded);
|
|
|
|
}
|
2017-03-21 16:18:48 +01:00
|
|
|
}
|
|
|
|
|
2016-11-28 10:58:44 +01:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case (Tool::NodeArc):
|
|
|
|
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeArc);
|
|
|
|
break;
|
2017-02-10 15:47:15 +01:00
|
|
|
case (Tool::NodeElArc):
|
|
|
|
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeElArc);
|
|
|
|
break;
|
2016-11-28 10:58:44 +01:00
|
|
|
case (Tool::NodePoint):
|
|
|
|
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodePoint);
|
|
|
|
break;
|
|
|
|
case (Tool::NodeSpline):
|
|
|
|
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeSpline);
|
|
|
|
break;
|
|
|
|
case (Tool::NodeSplinePath):
|
|
|
|
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeSplinePath);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-04-26 10:22:42 +02:00
|
|
|
const unsigned char angleType = static_cast<unsigned char>(node.GetAngleType());
|
|
|
|
|
|
|
|
if (angleType > 0)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(nod, AttrAngle, angleType);
|
|
|
|
}
|
2016-11-28 10:58:44 +01:00
|
|
|
}
|
|
|
|
|
2017-03-24 13:48:07 +01:00
|
|
|
if (type == Tool::NodePoint)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(nod, VAbstractPattern::AttrNodePassmark, node.IsPassmark());
|
|
|
|
doc->SetAttribute(nod, VAbstractPattern::AttrNodePassmarkLine,
|
|
|
|
PassmarkLineTypeToString(node.GetPassmarkLineType()));
|
|
|
|
doc->SetAttribute(nod, VAbstractPattern::AttrNodePassmarkAngle,
|
|
|
|
PassmarkAngleTypeToString(node.GetPassmarkAngleType()));
|
|
|
|
|
|
|
|
if (not node.IsPassmark()
|
|
|
|
&& node.GetPassmarkLineType() == PassmarkLineType::OneLine
|
|
|
|
&& node.GetPassmarkAngleType() == PassmarkAngleType::Straightforward)
|
|
|
|
{ // For backward compatebility.
|
|
|
|
nod.removeAttribute(VAbstractPattern::AttrNodePassmark);
|
|
|
|
nod.removeAttribute(VAbstractPattern::AttrNodePassmarkLine);
|
|
|
|
nod.removeAttribute(VAbstractPattern::AttrNodePassmarkAngle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Wrong configuration.
|
|
|
|
nod.removeAttribute(VAbstractPattern::AttrNodePassmark);
|
|
|
|
nod.removeAttribute(VAbstractPattern::AttrNodePassmarkLine);
|
|
|
|
nod.removeAttribute(VAbstractPattern::AttrNodePassmarkAngle);
|
|
|
|
}
|
|
|
|
|
2017-04-26 10:22:42 +02:00
|
|
|
{
|
|
|
|
const bool showSecond = node.IsShowSecondPassmark();
|
|
|
|
if (not showSecond)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(nod, VAbstractPattern::AttrNodeShowSecondPassmark, showSecond);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // For backward compatebility.
|
|
|
|
nod.removeAttribute(VAbstractPattern::AttrNodeShowSecondPassmark);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 10:58:44 +01:00
|
|
|
return nod;
|
|
|
|
}
|
2017-01-16 16:37:15 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractTool::AddNode(VAbstractPattern *doc, QDomElement &domElement, const VPieceNode &node)
|
|
|
|
{
|
|
|
|
domElement.appendChild(AddSANode(doc, VAbstractPattern::TagNode, node));
|
|
|
|
}
|
2017-01-18 09:17:18 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<VPieceNode> VAbstractTool::PrepareNodes(const VPiecePath &path, VMainGraphicsScene *scene,
|
|
|
|
VAbstractPattern *doc, VContainer *data)
|
|
|
|
{
|
|
|
|
QVector<VPieceNode> nodes;
|
|
|
|
for (int i = 0; i< path.CountNodes(); ++i)
|
|
|
|
{
|
|
|
|
VPieceNode nodeD = path.at(i);
|
2017-03-21 17:00:31 +01:00
|
|
|
const quint32 id = PrepareNode(nodeD, scene, doc, data);
|
|
|
|
if (id > NULL_ID)
|
2017-01-18 09:17:18 +01:00
|
|
|
{
|
2017-03-21 17:00:31 +01:00
|
|
|
nodeD.SetId(id);
|
|
|
|
nodes.append(nodeD);
|
2017-01-18 09:17:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nodes;
|
|
|
|
}
|
2017-03-21 17:00:31 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-20 13:05:41 +02:00
|
|
|
quint32 VAbstractTool::PrepareNode(const VPieceNode &node, VMainGraphicsScene *scene, VAbstractPattern *doc,
|
|
|
|
VContainer *data)
|
2017-03-21 17:00:31 +01:00
|
|
|
{
|
|
|
|
SCASSERT(scene != nullptr)
|
|
|
|
SCASSERT(doc != nullptr)
|
|
|
|
SCASSERT(data != nullptr)
|
|
|
|
|
2017-09-18 10:37:23 +02:00
|
|
|
VAbstractNodeInitData initData;
|
|
|
|
initData.idObject = node.GetId();
|
|
|
|
initData.doc = doc;
|
|
|
|
initData.data = data;
|
|
|
|
initData.parse = Document::FullParse;
|
|
|
|
initData.typeCreation = Source::FromGui;
|
2017-09-20 13:05:41 +02:00
|
|
|
initData.scene = scene;
|
2017-09-18 10:37:23 +02:00
|
|
|
|
2017-03-21 17:00:31 +01:00
|
|
|
switch (node.GetTypeTool())
|
|
|
|
{
|
|
|
|
case (Tool::NodePoint):
|
2017-09-18 10:37:23 +02:00
|
|
|
initData.id = CreateNode<VPointF>(data, node.GetId());
|
|
|
|
VNodePoint::Create(initData);
|
2017-03-21 17:00:31 +01:00
|
|
|
break;
|
|
|
|
case (Tool::NodeArc):
|
2017-09-18 10:37:23 +02:00
|
|
|
initData.id = CreateNode<VArc>(data, node.GetId());
|
|
|
|
VNodeArc::Create(initData);
|
2017-03-21 17:00:31 +01:00
|
|
|
break;
|
|
|
|
case (Tool::NodeElArc):
|
2017-09-18 10:37:23 +02:00
|
|
|
initData.id = CreateNode<VEllipticalArc>(data, node.GetId());
|
|
|
|
VNodeEllipticalArc::Create(initData);
|
2017-03-21 17:00:31 +01:00
|
|
|
break;
|
|
|
|
case (Tool::NodeSpline):
|
2017-09-18 10:37:23 +02:00
|
|
|
initData.id = CreateNodeSpline(data, node.GetId());
|
|
|
|
VNodeSpline::Create(initData);
|
2017-03-21 17:00:31 +01:00
|
|
|
break;
|
|
|
|
case (Tool::NodeSplinePath):
|
2017-09-18 10:37:23 +02:00
|
|
|
initData.id = CreateNodeSplinePath(data, node.GetId());
|
|
|
|
VNodeSplinePath::Create(initData);
|
2017-03-21 17:00:31 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
|
|
|
|
break;
|
|
|
|
}
|
2017-09-18 10:37:23 +02:00
|
|
|
return initData.id;
|
2017-03-21 17:00:31 +01:00
|
|
|
}
|
2017-10-26 11:54:08 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 VAbstractTool::CreateNodeSpline(VContainer *data, quint32 id)
|
|
|
|
{
|
|
|
|
if (data->GetGObject(id)->getType() == GOType::Spline)
|
|
|
|
{
|
|
|
|
return VAbstractTool::CreateNode<VSpline>(data, id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return VAbstractTool::CreateNode<VCubicBezier>(data, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 VAbstractTool::CreateNodeSplinePath(VContainer *data, quint32 id)
|
|
|
|
{
|
|
|
|
if (data->GetGObject(id)->getType() == GOType::SplinePath)
|
|
|
|
{
|
|
|
|
return VAbstractTool::CreateNode<VSplinePath>(data, id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return VAbstractTool::CreateNode<VCubicBezierPath>(data, id);
|
|
|
|
}
|
|
|
|
}
|