2016-11-08 11:57:01 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 6 11, 2016
|
|
|
|
**
|
|
|
|
** @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) 2016 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 "vtoolseamallowance.h"
|
2017-03-16 13:49:40 +01:00
|
|
|
#include "../dialogs/tools/piece/dialogseamallowance.h"
|
2016-11-08 11:57:01 +01:00
|
|
|
#include "../vpatterndb/vpiecenode.h"
|
2016-11-23 11:54:46 +01:00
|
|
|
#include "../vpatterndb/vpiecepath.h"
|
2017-01-12 14:51:08 +01:00
|
|
|
#include "../vpatterndb/calculator.h"
|
2017-02-23 10:37:19 +01:00
|
|
|
#include "../vpatterndb/floatItemData/vpatternlabeldata.h"
|
|
|
|
#include "../vpatterndb/floatItemData/vpiecelabeldata.h"
|
2016-11-08 11:57:01 +01:00
|
|
|
#include "nodeDetails/vnodearc.h"
|
2016-12-20 16:50:39 +01:00
|
|
|
#include "nodeDetails/vnodeellipticalarc.h"
|
2016-11-08 11:57:01 +01:00
|
|
|
#include "nodeDetails/vnodepoint.h"
|
|
|
|
#include "nodeDetails/vnodespline.h"
|
|
|
|
#include "nodeDetails/vnodesplinepath.h"
|
2016-12-03 17:01:39 +01:00
|
|
|
#include "nodeDetails/vtoolpiecepath.h"
|
2016-11-08 11:57:01 +01:00
|
|
|
#include "../vgeometry/varc.h"
|
2016-12-20 16:50:39 +01:00
|
|
|
#include "../vgeometry/vellipticalarc.h"
|
2016-11-08 11:57:01 +01:00
|
|
|
#include "../vgeometry/vcubicbezier.h"
|
|
|
|
#include "../vgeometry/vcubicbezierpath.h"
|
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vgeometry/vspline.h"
|
|
|
|
#include "../vgeometry/vsplinepath.h"
|
|
|
|
#include "../ifc/xml/vpatternconverter.h"
|
|
|
|
#include "../undocommands/addpiece.h"
|
2016-11-09 10:57:39 +01:00
|
|
|
#include "../undocommands/deletepiece.h"
|
2016-11-09 12:06:05 +01:00
|
|
|
#include "../undocommands/movepiece.h"
|
2016-11-09 13:11:58 +01:00
|
|
|
#include "../undocommands/savepieceoptions.h"
|
2016-11-09 14:53:22 +01:00
|
|
|
#include "../undocommands/togglepieceinlayout.h"
|
2016-11-09 12:06:05 +01:00
|
|
|
#include "../vwidgets/vmaingraphicsview.h"
|
2017-01-19 11:23:42 +01:00
|
|
|
#include "../vwidgets/vnobrushscalepathitem.h"
|
2017-02-27 13:30:02 +01:00
|
|
|
#include "../qmuparser/qmutokenparser.h"
|
2016-11-08 11:57:01 +01:00
|
|
|
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
2016-11-09 12:06:05 +01:00
|
|
|
#include <QGraphicsView>
|
2016-11-09 10:57:39 +01:00
|
|
|
#include <QKeyEvent>
|
2016-11-08 11:57:01 +01:00
|
|
|
#include <QMenu>
|
2016-11-09 10:57:39 +01:00
|
|
|
#include <QMessageBox>
|
2016-11-08 11:57:01 +01:00
|
|
|
|
2017-03-09 12:10:46 +01:00
|
|
|
// Current version of seam allowance tag need for backward compatibility
|
2016-11-08 11:57:01 +01:00
|
|
|
const quint8 VToolSeamAllowance::pieceVersion = 2;
|
|
|
|
|
2016-11-25 13:19:44 +01:00
|
|
|
const QString VToolSeamAllowance::TagCSA = QStringLiteral("csa");
|
|
|
|
const QString VToolSeamAllowance::TagRecord = QStringLiteral("record");
|
2016-12-03 17:01:39 +01:00
|
|
|
const QString VToolSeamAllowance::TagIPaths = QStringLiteral("iPaths");
|
2017-01-31 17:09:18 +01:00
|
|
|
const QString VToolSeamAllowance::TagPins = QStringLiteral("pins");
|
2016-11-25 13:19:44 +01:00
|
|
|
|
2016-11-10 10:56:40 +01:00
|
|
|
const QString VToolSeamAllowance::AttrVersion = QStringLiteral("version");
|
|
|
|
const QString VToolSeamAllowance::AttrForbidFlipping = QStringLiteral("forbidFlipping");
|
2016-11-10 11:53:02 +01:00
|
|
|
const QString VToolSeamAllowance::AttrSeamAllowance = QStringLiteral("seamAllowance");
|
2017-01-12 14:51:08 +01:00
|
|
|
const QString VToolSeamAllowance::AttrHeight = QStringLiteral("height");
|
2016-11-23 17:40:27 +01:00
|
|
|
const QString VToolSeamAllowance::AttrUnited = QStringLiteral("united");
|
2017-01-12 14:51:08 +01:00
|
|
|
const QString VToolSeamAllowance::AttrFont = QStringLiteral("fontSize");
|
2017-02-23 15:49:20 +01:00
|
|
|
const QString VToolSeamAllowance::AttrTopLeftPin = QStringLiteral("topLeftPin");
|
|
|
|
const QString VToolSeamAllowance::AttrBottomRightPin = QStringLiteral("bottomRightPin");
|
2017-03-09 12:10:46 +01:00
|
|
|
const QString VToolSeamAllowance::AttrCenterPin = QStringLiteral("centerPin");
|
2017-02-23 15:49:20 +01:00
|
|
|
const QString VToolSeamAllowance::AttrTopPin = QStringLiteral("topPin");
|
|
|
|
const QString VToolSeamAllowance::AttrBottomPin = QStringLiteral("bottomPin");
|
2016-11-08 11:57:01 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VToolSeamAllowance::~VToolSeamAllowance()
|
|
|
|
{
|
|
|
|
delete m_dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VToolSeamAllowance *VToolSeamAllowance::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
|
|
|
|
VContainer *data)
|
|
|
|
{
|
|
|
|
SCASSERT(dialog != nullptr);
|
|
|
|
DialogSeamAllowance *dialogTool = qobject_cast<DialogSeamAllowance*>(dialog);
|
|
|
|
SCASSERT(dialogTool != nullptr);
|
|
|
|
VPiece detail = dialogTool->GetPiece();
|
2017-01-21 14:24:40 +01:00
|
|
|
QString width = detail.GetFormulaSAWidth();
|
2016-11-08 11:57:01 +01:00
|
|
|
qApp->getUndoStack()->beginMacro("add detail");
|
2017-01-18 09:17:18 +01:00
|
|
|
detail.GetPath().SetNodes(PrepareNodes(detail.GetPath(), scene, doc, data));
|
2017-01-12 14:51:08 +01:00
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
VToolSeamAllowance *piece = Create(0, detail, width, scene, doc, data, Document::FullParse, Source::FromGui);
|
2016-11-08 11:57:01 +01:00
|
|
|
|
|
|
|
if (piece != nullptr)
|
|
|
|
{
|
|
|
|
piece->m_dialog = dialogTool;
|
|
|
|
}
|
|
|
|
return piece;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-21 14:24:40 +01:00
|
|
|
VToolSeamAllowance *VToolSeamAllowance::Create(quint32 id, VPiece newPiece, QString &width, VMainGraphicsScene *scene,
|
2016-11-08 11:57:01 +01:00
|
|
|
VAbstractPattern *doc, VContainer *data, const Document &parse,
|
|
|
|
const Source &typeCreation, const QString &drawName)
|
|
|
|
{
|
|
|
|
if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
|
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
data->AddVariable(currentSeamAllowance, new VIncrement(data, currentSeamAllowance, 0, newPiece.GetSAWidth(),
|
|
|
|
width, true, tr("Current seam allowance")));
|
2016-11-08 11:57:01 +01:00
|
|
|
id = data->AddPiece(newPiece);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
const qreal calcWidth = CheckFormula(id, width, data);
|
|
|
|
newPiece.SetFormulaSAWidth(width, calcWidth);
|
|
|
|
|
|
|
|
data->AddVariable(currentSeamAllowance, new VIncrement(data, currentSeamAllowance, 0, calcWidth,
|
|
|
|
width, true, tr("Current seam allowance")));
|
|
|
|
|
2016-11-08 11:57:01 +01:00
|
|
|
data->UpdatePiece(id, newPiece);
|
|
|
|
if (parse != Document::FullParse)
|
|
|
|
{
|
|
|
|
doc->UpdateToolData(id, data);
|
|
|
|
}
|
|
|
|
}
|
2017-02-13 07:55:42 +01:00
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
VToolSeamAllowance *piece = nullptr;
|
2016-11-08 11:57:01 +01:00
|
|
|
if (parse == Document::FullParse)
|
|
|
|
{
|
2017-02-13 07:55:42 +01:00
|
|
|
VAbstractTool::AddRecord(id, Tool::Piece, doc);
|
2017-01-21 14:24:40 +01:00
|
|
|
piece = new VToolSeamAllowance(doc, data, id, typeCreation, scene, drawName);
|
2016-11-08 11:57:01 +01:00
|
|
|
scene->addItem(piece);
|
|
|
|
connect(piece, &VToolSeamAllowance::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
connect(scene, &VMainGraphicsScene::EnableDetailItemHover, piece, &VToolSeamAllowance::AllowHover);
|
|
|
|
connect(scene, &VMainGraphicsScene::EnableDetailItemSelection, piece, &VToolSeamAllowance::AllowSelecting);
|
|
|
|
connect(scene, &VMainGraphicsScene::HighlightDetail, piece, &VToolSeamAllowance::Highlight);
|
2017-03-23 09:25:46 +01:00
|
|
|
VAbstractPattern::AddTool(id, piece);
|
2016-11-08 11:57:01 +01:00
|
|
|
}
|
2017-01-21 14:24:40 +01:00
|
|
|
//Very important to delete it. Only this tool need this special variable.
|
2017-02-08 09:28:18 +01:00
|
|
|
data->RemoveVariable(currentSeamAllowance);
|
2017-01-21 14:24:40 +01:00
|
|
|
return piece;
|
2016-11-08 11:57:01 +01:00
|
|
|
}
|
|
|
|
|
2016-11-09 10:57:39 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::Remove(bool ask)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
DeleteTool(ask);
|
|
|
|
}
|
|
|
|
catch(const VExceptionToolWasDeleted &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e);
|
|
|
|
return;//Leave this method immediately!!!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-21 16:18:48 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-03-21 17:00:31 +01:00
|
|
|
void VToolSeamAllowance::InsertNode(VPieceNode node, quint32 pieceId, VMainGraphicsScene *scene,
|
|
|
|
VContainer *data, VAbstractPattern *doc)
|
2017-03-21 16:18:48 +01:00
|
|
|
{
|
2017-03-21 17:00:31 +01:00
|
|
|
SCASSERT(scene != nullptr)
|
|
|
|
SCASSERT(data != nullptr)
|
|
|
|
SCASSERT(doc != nullptr)
|
2017-03-21 16:18:48 +01:00
|
|
|
|
|
|
|
if (pieceId > NULL_ID)
|
|
|
|
{
|
|
|
|
VPiece oldDet;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
oldDet = data->GetPiece(pieceId);
|
|
|
|
}
|
|
|
|
catch (const VExceptionBadId &)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VPiece newDet = oldDet;
|
|
|
|
|
2017-03-21 17:00:31 +01:00
|
|
|
const quint32 id = PrepareNode(node, scene, doc, data);
|
|
|
|
if (id == NULL_ID)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
node.SetId(id);
|
2017-03-21 16:18:48 +01:00
|
|
|
newDet.GetPath().Append(node);
|
|
|
|
|
2017-03-21 17:00:31 +01:00
|
|
|
// Seam allowance tool already initializated and can't init the node
|
2017-03-23 09:25:46 +01:00
|
|
|
VToolSeamAllowance *saTool = qobject_cast<VToolSeamAllowance*>(VAbstractPattern::getTool(pieceId));
|
2017-03-21 17:00:31 +01:00
|
|
|
SCASSERT(saTool != nullptr);
|
|
|
|
|
|
|
|
InitNode(node, scene, data, doc, saTool);
|
|
|
|
|
2017-03-21 16:18:48 +01:00
|
|
|
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, pieceId);
|
|
|
|
qApp->getUndoStack()->push(saveCommand);// First push then make a connect
|
|
|
|
data->UpdatePiece(pieceId, newDet);// Update piece because first save will not call lite update
|
|
|
|
connect(saveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-09 13:11:58 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiece &piece)
|
|
|
|
{
|
|
|
|
SCASSERT(doc != nullptr);
|
|
|
|
|
|
|
|
doc->SetAttribute(domElement, VDomDocument::AttrId, id);
|
2016-11-09 14:53:22 +01:00
|
|
|
doc->SetAttribute(domElement, AttrName, piece.GetName());
|
2016-11-09 13:11:58 +01:00
|
|
|
doc->SetAttribute(domElement, AttrVersion, QString().setNum(pieceVersion));
|
|
|
|
doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(piece.GetMx()));
|
|
|
|
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(piece.GetMy()));
|
2016-11-09 14:53:22 +01:00
|
|
|
doc->SetAttribute(domElement, AttrInLayout, piece.IsInLayout());
|
2016-11-10 11:53:02 +01:00
|
|
|
doc->SetAttribute(domElement, AttrForbidFlipping, piece.IsForbidFlipping());
|
|
|
|
doc->SetAttribute(domElement, AttrSeamAllowance, piece.IsSeamAllowance());
|
2017-01-21 16:32:08 +01:00
|
|
|
doc->SetAttribute(domElement, VAbstractPattern::AttrWidth, piece.GetFormulaSAWidth());
|
2016-11-23 17:40:27 +01:00
|
|
|
doc->SetAttribute(domElement, AttrUnited, piece.IsUnited());
|
2016-11-09 13:11:58 +01:00
|
|
|
}
|
|
|
|
|
2016-11-25 13:19:44 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::AddCSARecord(VAbstractPattern *doc, QDomElement &domElement, const CustomSARecord &record)
|
|
|
|
{
|
|
|
|
QDomElement recordNode = doc->createElement(VToolSeamAllowance::TagRecord);
|
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
doc->SetAttribute(recordNode, VAbstractPattern::AttrStart, record.startPoint);
|
|
|
|
doc->SetAttribute(recordNode, VAbstractPattern::AttrPath, record.path);
|
|
|
|
doc->SetAttribute(recordNode, VAbstractPattern::AttrEnd, record.endPoint);
|
2016-11-25 13:19:44 +01:00
|
|
|
doc->SetAttribute(recordNode, VAbstractPattern::AttrNodeReverse, record.reverse);
|
2017-01-16 16:37:15 +01:00
|
|
|
doc->SetAttribute(recordNode, VAbstractPattern::AttrIncludeAs, static_cast<unsigned int>(record.includeType));
|
2016-11-25 13:19:44 +01:00
|
|
|
|
|
|
|
domElement.appendChild(recordNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::AddCSARecords(VAbstractPattern *doc, QDomElement &domElement,
|
|
|
|
const QVector<CustomSARecord> &records)
|
|
|
|
{
|
|
|
|
if (records.size() > 0)
|
|
|
|
{
|
|
|
|
QDomElement csaRecordsElement = doc->createElement(VToolSeamAllowance::TagCSA);
|
|
|
|
for (int i = 0; i < records.size(); ++i)
|
|
|
|
{
|
|
|
|
AddCSARecord(doc, csaRecordsElement, records.at(i));
|
|
|
|
}
|
|
|
|
domElement.appendChild(csaRecordsElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-03 17:01:39 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::AddInternalPaths(VAbstractPattern *doc, QDomElement &domElement, const QVector<quint32> &paths)
|
|
|
|
{
|
|
|
|
if (paths.size() > 0)
|
|
|
|
{
|
|
|
|
QDomElement iPathsElement = doc->createElement(VToolSeamAllowance::TagIPaths);
|
|
|
|
for (int i = 0; i < paths.size(); ++i)
|
|
|
|
{
|
|
|
|
QDomElement recordNode = doc->createElement(VToolSeamAllowance::TagRecord);
|
2017-01-16 16:37:15 +01:00
|
|
|
doc->SetAttribute(recordNode, VAbstractPattern::AttrPath, paths.at(i));
|
2016-12-03 17:01:39 +01:00
|
|
|
iPathsElement.appendChild(recordNode);
|
|
|
|
}
|
|
|
|
domElement.appendChild(iPathsElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-31 17:09:18 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::AddPins(VAbstractPattern *doc, QDomElement &domElement, const QVector<quint32> &pins)
|
|
|
|
{
|
|
|
|
if (pins.size() > 0)
|
|
|
|
{
|
|
|
|
QDomElement pinsElement = doc->createElement(VToolSeamAllowance::TagPins);
|
|
|
|
for (int i = 0; i < pins.size(); ++i)
|
|
|
|
{
|
|
|
|
QDomElement recordNode = doc->createElement(VToolSeamAllowance::TagRecord);
|
|
|
|
recordNode.appendChild(doc->createTextNode(QString().setNum(pins.at(i))));
|
|
|
|
pinsElement.appendChild(recordNode);
|
|
|
|
}
|
|
|
|
domElement.appendChild(pinsElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-09 13:11:58 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
|
|
|
|
{
|
2017-01-12 14:51:08 +01:00
|
|
|
QDomElement domData = doc->createElement(VAbstractPattern::TagData);
|
2017-02-23 10:19:27 +01:00
|
|
|
const VPieceLabelData& data = piece.GetPatternPieceData();
|
2017-01-12 14:51:08 +01:00
|
|
|
doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter());
|
|
|
|
doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? trueStr : falseStr);
|
|
|
|
doc->SetAttribute(domData, AttrMx, data.GetPos().x());
|
|
|
|
doc->SetAttribute(domData, AttrMy, data.GetPos().y());
|
2017-01-21 16:32:08 +01:00
|
|
|
doc->SetAttribute(domData, VAbstractPattern::AttrWidth, data.GetLabelWidth());
|
2017-01-12 14:51:08 +01:00
|
|
|
doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight());
|
|
|
|
doc->SetAttribute(domData, AttrFont, data.GetFontSize());
|
2017-01-21 16:32:08 +01:00
|
|
|
doc->SetAttribute(domData, VAbstractPattern::AttrRotation, data.GetRotation());
|
2017-01-12 14:51:08 +01:00
|
|
|
|
2017-03-13 15:10:25 +01:00
|
|
|
if (data.CenterPin() > NULL_ID)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(domData, AttrCenterPin, data.CenterPin());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
domData.removeAttribute(AttrCenterPin);
|
|
|
|
}
|
|
|
|
|
2017-02-23 15:49:20 +01:00
|
|
|
if (data.TopLeftPin() > NULL_ID)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(domData, AttrTopLeftPin, data.TopLeftPin());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
domData.removeAttribute(AttrTopLeftPin);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.BottomRightPin() > NULL_ID)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(domData, AttrBottomRightPin, data.BottomRightPin());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
domData.removeAttribute(AttrBottomRightPin);
|
|
|
|
}
|
|
|
|
|
2017-01-12 14:51:08 +01:00
|
|
|
for (int i = 0; i < data.GetMCPCount(); ++i)
|
|
|
|
{
|
|
|
|
const MaterialCutPlacement mcp = data.GetMCP(i);
|
|
|
|
QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP);
|
|
|
|
doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial));
|
|
|
|
if (mcp.m_eMaterial == MaterialType::mtUserDefined)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef);
|
|
|
|
}
|
|
|
|
doc->SetAttribute(domMCP, VAbstractPattern::AttrCutNumber, mcp.m_iCutNumber);
|
|
|
|
doc->SetAttribute(domMCP, VAbstractPattern::AttrPlacement, int(mcp.m_ePlacement));
|
|
|
|
domData.appendChild(domMCP);
|
|
|
|
}
|
|
|
|
domElement.appendChild(domData);
|
2016-11-09 13:11:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
|
|
|
|
{
|
2017-01-12 14:51:08 +01:00
|
|
|
QDomElement domData = doc->createElement(VAbstractPattern::TagPatternInfo);
|
2017-02-23 10:26:25 +01:00
|
|
|
const VPatternLabelData& geom = piece.GetPatternInfo();
|
2017-01-12 14:51:08 +01:00
|
|
|
doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible() == true ? trueStr : falseStr);
|
|
|
|
doc->SetAttribute(domData, AttrMx, geom.GetPos().x());
|
|
|
|
doc->SetAttribute(domData, AttrMy, geom.GetPos().y());
|
2017-01-21 16:32:08 +01:00
|
|
|
doc->SetAttribute(domData, VAbstractPattern::AttrWidth, geom.GetLabelWidth());
|
2017-01-12 14:51:08 +01:00
|
|
|
doc->SetAttribute(domData, AttrHeight, geom.GetLabelHeight());
|
|
|
|
doc->SetAttribute(domData, AttrFont, geom.GetFontSize());
|
2017-01-21 16:32:08 +01:00
|
|
|
doc->SetAttribute(domData, VAbstractPattern::AttrRotation, geom.GetRotation());
|
2017-02-23 15:49:20 +01:00
|
|
|
|
2017-03-13 15:10:25 +01:00
|
|
|
if (geom.CenterPin() > NULL_ID)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(domData, AttrCenterPin, geom.CenterPin());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
domData.removeAttribute(AttrCenterPin);
|
|
|
|
}
|
|
|
|
|
2017-02-23 15:49:20 +01:00
|
|
|
if (geom.TopLeftPin() > NULL_ID)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(domData, AttrTopLeftPin, geom.TopLeftPin());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
domData.removeAttribute(AttrTopLeftPin);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (geom.BottomRightPin() > NULL_ID)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(domData, AttrBottomRightPin, geom.BottomRightPin());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
domData.removeAttribute(AttrBottomRightPin);
|
|
|
|
}
|
|
|
|
|
2017-01-12 14:51:08 +01:00
|
|
|
domElement.appendChild(domData);
|
2016-11-09 13:11:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::AddGrainline(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
|
|
|
|
{
|
2017-01-12 14:51:08 +01:00
|
|
|
// grainline
|
|
|
|
QDomElement domData = doc->createElement(VAbstractPattern::TagGrainline);
|
2017-02-23 10:33:17 +01:00
|
|
|
const VGrainlineData& glGeom = piece.GetGrainlineGeometry();
|
2017-01-12 14:51:08 +01:00
|
|
|
doc->SetAttribute(domData, VAbstractPattern::AttrVisible, glGeom.IsVisible() == true ? trueStr : falseStr);
|
|
|
|
doc->SetAttribute(domData, AttrMx, glGeom.GetPos().x());
|
|
|
|
doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y());
|
|
|
|
doc->SetAttribute(domData, AttrLength, glGeom.GetLength());
|
2017-01-21 16:32:08 +01:00
|
|
|
doc->SetAttribute(domData, VAbstractPattern::AttrRotation, glGeom.GetRotation());
|
2017-01-12 14:51:08 +01:00
|
|
|
doc->SetAttribute(domData, VAbstractPattern::AttrArrows, int(glGeom.GetArrowType()));
|
2017-02-23 15:49:20 +01:00
|
|
|
|
2017-03-09 12:10:46 +01:00
|
|
|
if (glGeom.CenterPin() > NULL_ID)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(domData, AttrCenterPin, glGeom.CenterPin());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
domData.removeAttribute(AttrCenterPin);
|
|
|
|
}
|
|
|
|
|
2017-02-23 15:49:20 +01:00
|
|
|
if (glGeom.TopPin() > NULL_ID)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(domData, AttrTopPin, glGeom.TopPin());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
domData.removeAttribute(AttrTopPin);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glGeom.BottomPin() > NULL_ID)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(domData, AttrBottomPin, glGeom.BottomPin());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
domData.removeAttribute(AttrBottomPin);
|
|
|
|
}
|
|
|
|
|
2017-01-12 14:51:08 +01:00
|
|
|
domElement.appendChild(domData);
|
2016-11-09 13:11:58 +01:00
|
|
|
}
|
|
|
|
|
2016-11-08 11:57:01 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VToolSeamAllowance::getTagName() const
|
|
|
|
{
|
|
|
|
return VAbstractPattern::TagDetail;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::ShowVisualization(bool show)
|
|
|
|
{
|
|
|
|
Q_UNUSED(show)
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::GroupVisibility(quint32 object, bool visible)
|
|
|
|
{
|
|
|
|
Q_UNUSED(object);
|
|
|
|
Q_UNUSED(visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::FullUpdateFromFile()
|
2016-11-09 12:06:05 +01:00
|
|
|
{
|
2017-03-22 11:05:53 +01:00
|
|
|
UpdateExcludeState();
|
2016-11-09 12:06:05 +01:00
|
|
|
RefreshGeometry();
|
|
|
|
}
|
2016-11-08 11:57:01 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::FullUpdateFromGuiOk(int result)
|
2016-11-09 13:11:58 +01:00
|
|
|
{
|
|
|
|
if (result == QDialog::Accepted)
|
|
|
|
{
|
2016-11-09 15:27:55 +01:00
|
|
|
SaveDialogChange();
|
2016-11-09 13:11:58 +01:00
|
|
|
}
|
|
|
|
delete m_dialog;
|
|
|
|
}
|
2016-11-08 11:57:01 +01:00
|
|
|
|
2016-11-09 15:27:55 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::FullUpdateFromGuiApply()
|
|
|
|
{
|
|
|
|
SaveDialogChange();
|
|
|
|
}
|
|
|
|
|
2016-11-08 11:57:01 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::EnableToolMove(bool move)
|
|
|
|
{
|
|
|
|
setFlag(QGraphicsItem::ItemIsMovable, move);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::AllowHover(bool enabled)
|
|
|
|
{
|
|
|
|
setAcceptHoverEvents(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::AllowSelecting(bool enabled)
|
|
|
|
{
|
|
|
|
setFlag(QGraphicsItem::ItemIsSelectable, enabled);
|
|
|
|
}
|
|
|
|
|
2017-01-12 14:51:08 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::ResetChildren(QGraphicsItem *pItem)
|
|
|
|
{
|
2017-02-04 19:30:32 +01:00
|
|
|
const bool selected = isSelected();
|
2017-01-12 14:51:08 +01:00
|
|
|
const VPiece detail = VAbstractTool::data.GetPiece(id);
|
2017-01-18 13:01:51 +01:00
|
|
|
VTextGraphicsItem* pVGI = qgraphicsitem_cast<VTextGraphicsItem*>(pItem);
|
2017-01-12 14:51:08 +01:00
|
|
|
if (pVGI != m_dataLabel)
|
|
|
|
{
|
|
|
|
if (detail.GetPatternPieceData().IsVisible())
|
|
|
|
{
|
|
|
|
m_dataLabel->Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pVGI != m_patternInfo)
|
|
|
|
{
|
|
|
|
if (detail.GetPatternInfo().IsVisible())
|
|
|
|
{
|
|
|
|
m_patternInfo->Reset();
|
|
|
|
}
|
|
|
|
}
|
2017-01-18 13:01:51 +01:00
|
|
|
VGrainlineItem* pGLI = qgraphicsitem_cast<VGrainlineItem*>(pItem);
|
2017-01-12 14:51:08 +01:00
|
|
|
if (pGLI != m_grainLine)
|
|
|
|
{
|
|
|
|
if (detail.GetGrainlineGeometry().IsVisible())
|
|
|
|
{
|
|
|
|
m_grainLine->Reset();
|
|
|
|
}
|
|
|
|
}
|
2017-01-18 13:01:51 +01:00
|
|
|
|
2017-02-04 19:30:32 +01:00
|
|
|
setSelected(selected);
|
2017-01-18 13:01:51 +01:00
|
|
|
update();
|
2017-01-12 14:51:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::UpdateAll()
|
|
|
|
{
|
|
|
|
m_sceneDetails->update();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::retranslateUi()
|
|
|
|
{
|
|
|
|
UpdateLabel();
|
|
|
|
UpdatePatternInfo();
|
|
|
|
}
|
|
|
|
|
2016-11-08 11:57:01 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::Highlight(quint32 id)
|
|
|
|
{
|
|
|
|
setSelected(this->id == id);
|
|
|
|
}
|
|
|
|
|
2017-01-12 14:51:08 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief UpdateLabel updates the text label, making it just big enough for the text to fit it
|
|
|
|
*/
|
|
|
|
void VToolSeamAllowance::UpdateLabel()
|
|
|
|
{
|
2017-01-13 14:19:27 +01:00
|
|
|
const VPiece detail = VAbstractTool::data.GetPiece(id);
|
2017-02-27 11:01:38 +01:00
|
|
|
const VPieceLabelData& labelData = detail.GetPatternPieceData();
|
2017-01-12 14:51:08 +01:00
|
|
|
|
2017-02-27 11:01:38 +01:00
|
|
|
if (labelData.IsVisible() == true)
|
2017-01-12 14:51:08 +01:00
|
|
|
{
|
2017-02-27 11:01:38 +01:00
|
|
|
QPointF pos;
|
|
|
|
qreal labelWidth = 0;
|
|
|
|
qreal labelHeight = 0;
|
2017-03-13 13:27:29 +01:00
|
|
|
qreal labelAngle = 0;
|
|
|
|
const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(labelData, labelAngle, labelWidth, labelHeight,
|
|
|
|
pos);
|
|
|
|
if (type & VGrainlineItem::Error)
|
|
|
|
{
|
|
|
|
m_dataLabel->hide();
|
|
|
|
return;
|
|
|
|
}
|
2017-02-27 13:30:02 +01:00
|
|
|
m_dataLabel->SetMoveType(type);
|
2017-02-27 11:01:38 +01:00
|
|
|
|
2017-03-23 09:25:46 +01:00
|
|
|
QFont fnt = QApplication::font();
|
2017-01-12 14:51:08 +01:00
|
|
|
{
|
2017-02-27 11:01:38 +01:00
|
|
|
const int iFS = labelData.GetFontSize();
|
2017-01-12 14:51:08 +01:00
|
|
|
iFS < MIN_FONT_SIZE ? fnt.setPixelSize(MIN_FONT_SIZE) : fnt.setPixelSize(iFS);
|
|
|
|
}
|
|
|
|
m_dataLabel->SetFont(fnt);
|
2017-03-13 13:27:29 +01:00
|
|
|
m_dataLabel->SetSize(ToPixel(labelWidth, *VDataTool::data.GetPatternUnit()),
|
|
|
|
ToPixel(labelHeight, *VDataTool::data.GetPatternUnit()));
|
2017-02-27 11:01:38 +01:00
|
|
|
m_dataLabel->UpdateData(detail.GetName(), labelData);
|
|
|
|
|
2017-01-12 14:51:08 +01:00
|
|
|
QRectF rectBB;
|
2017-02-27 11:01:38 +01:00
|
|
|
rectBB.setTopLeft(pos);
|
2017-01-12 14:51:08 +01:00
|
|
|
rectBB.setWidth(m_dataLabel->boundingRect().width());
|
|
|
|
rectBB.setHeight(m_dataLabel->boundingRect().height());
|
|
|
|
qreal dX;
|
|
|
|
qreal dY;
|
2017-03-13 13:27:29 +01:00
|
|
|
if (m_dataLabel->IsContained(rectBB, labelAngle, dX, dY) == false)
|
2017-01-12 14:51:08 +01:00
|
|
|
{
|
2017-02-27 11:01:38 +01:00
|
|
|
pos.setX(pos.x() + dX);
|
|
|
|
pos.setY(pos.y() + dY);
|
2017-01-12 14:51:08 +01:00
|
|
|
}
|
|
|
|
|
2017-02-27 11:01:38 +01:00
|
|
|
m_dataLabel->setPos(pos);
|
2017-03-13 15:57:54 +01:00
|
|
|
m_dataLabel->setRotation(-labelAngle);
|
2017-01-12 14:51:08 +01:00
|
|
|
m_dataLabel->Update();
|
|
|
|
m_dataLabel->show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_dataLabel->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief UpdatePatternInfo updates the pattern info label
|
|
|
|
*/
|
|
|
|
void VToolSeamAllowance::UpdatePatternInfo()
|
|
|
|
{
|
|
|
|
const VPiece detail = VAbstractTool::data.GetPiece(id);
|
2017-02-23 10:26:25 +01:00
|
|
|
const VPatternLabelData& geom = detail.GetPatternInfo();
|
2017-01-12 14:51:08 +01:00
|
|
|
|
|
|
|
if (geom.IsVisible() == true)
|
|
|
|
{
|
2017-02-27 11:01:38 +01:00
|
|
|
QPointF pos;
|
|
|
|
qreal labelWidth = 0;
|
|
|
|
qreal labelHeight = 0;
|
2017-03-13 13:27:29 +01:00
|
|
|
qreal labelAngle = 0;
|
|
|
|
const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(geom, labelAngle, labelWidth, labelHeight, pos);
|
|
|
|
if (type & VGrainlineItem::Error)
|
|
|
|
{
|
|
|
|
m_dataLabel->hide();
|
|
|
|
return;
|
|
|
|
}
|
2017-02-27 13:30:02 +01:00
|
|
|
m_patternInfo->SetMoveType(type);
|
2017-02-27 11:01:38 +01:00
|
|
|
|
2017-03-23 09:25:46 +01:00
|
|
|
QFont fnt = QApplication::font();
|
2017-01-12 14:51:08 +01:00
|
|
|
int iFS = geom.GetFontSize();
|
|
|
|
if (iFS < MIN_FONT_SIZE)
|
|
|
|
{
|
|
|
|
iFS = MIN_FONT_SIZE;
|
|
|
|
}
|
|
|
|
fnt.setPixelSize(iFS);
|
|
|
|
m_patternInfo->SetFont(fnt);
|
2017-03-13 13:27:29 +01:00
|
|
|
m_patternInfo->SetSize(ToPixel(labelWidth, *VDataTool::data.GetPatternUnit()),
|
|
|
|
ToPixel(labelHeight, *VDataTool::data.GetPatternUnit()));
|
2017-03-23 09:25:46 +01:00
|
|
|
m_patternInfo->UpdateData(doc, VContainer::size(), VContainer::height());
|
2017-01-12 14:51:08 +01:00
|
|
|
|
|
|
|
QRectF rectBB;
|
2017-02-27 11:01:38 +01:00
|
|
|
rectBB.setTopLeft(pos);
|
2017-01-12 14:51:08 +01:00
|
|
|
rectBB.setWidth(m_patternInfo->boundingRect().width());
|
|
|
|
rectBB.setHeight(m_patternInfo->boundingRect().height());
|
|
|
|
qreal dX;
|
|
|
|
qreal dY;
|
2017-03-13 13:27:29 +01:00
|
|
|
if (m_patternInfo->IsContained(rectBB, labelAngle, dX, dY) == false)
|
2017-01-12 14:51:08 +01:00
|
|
|
{
|
2017-02-27 11:01:38 +01:00
|
|
|
pos.setX(pos.x() + dX);
|
|
|
|
pos.setY(pos.y() + dY);
|
2017-01-12 14:51:08 +01:00
|
|
|
}
|
|
|
|
|
2017-02-27 11:01:38 +01:00
|
|
|
m_patternInfo->setPos(pos);
|
2017-03-13 13:27:29 +01:00
|
|
|
m_patternInfo->setRotation(labelAngle);
|
2017-01-12 14:51:08 +01:00
|
|
|
m_patternInfo->Update();
|
|
|
|
m_patternInfo->GetTextLines() > 0 ? m_patternInfo->show() : m_patternInfo->hide();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_patternInfo->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief VToolDetail::UpdateGrainline updates the grain line item
|
|
|
|
*/
|
|
|
|
void VToolSeamAllowance::UpdateGrainline()
|
|
|
|
{
|
|
|
|
const VPiece detail = VAbstractTool::data.GetPiece(id);
|
2017-02-23 10:33:17 +01:00
|
|
|
const VGrainlineData& geom = detail.GetGrainlineGeometry();
|
2017-01-12 14:51:08 +01:00
|
|
|
|
|
|
|
if (geom.IsVisible() == true)
|
|
|
|
{
|
2017-02-27 11:01:38 +01:00
|
|
|
QPointF pos;
|
|
|
|
qreal dRotation = 0;
|
|
|
|
qreal dLength = 0;
|
2017-01-12 14:51:08 +01:00
|
|
|
|
2017-03-10 15:22:19 +01:00
|
|
|
const VGrainlineItem::MoveTypes type = FindGrainlineGeometry(geom, dLength, dRotation, pos);
|
|
|
|
if (type & VGrainlineItem::Error)
|
2017-01-12 14:51:08 +01:00
|
|
|
{
|
|
|
|
m_grainLine->hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-27 13:30:02 +01:00
|
|
|
m_grainLine->SetMoveType(type);
|
2017-02-27 11:01:38 +01:00
|
|
|
m_grainLine->UpdateGeometry(pos, dRotation, ToPixel(dLength, *VDataTool::data.GetPatternUnit()),
|
2017-01-12 14:51:08 +01:00
|
|
|
geom.GetArrowType());
|
|
|
|
m_grainLine->show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_grainLine->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief SaveMoveDetail saves the move detail operation to the undo stack
|
|
|
|
*/
|
|
|
|
void VToolSeamAllowance::SaveMoveDetail(const QPointF& ptPos)
|
|
|
|
{
|
|
|
|
VPiece oldDet = VAbstractTool::data.GetPiece(id);
|
|
|
|
VPiece newDet = oldDet;
|
|
|
|
newDet.GetPatternPieceData().SetPos(ptPos);
|
|
|
|
|
|
|
|
SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, id);
|
|
|
|
moveCommand->setText(tr("move pattern piece label"));
|
|
|
|
connect(moveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(moveCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief SaveResizeDetail saves the resize detail label operation to the undo stack
|
|
|
|
*/
|
|
|
|
void VToolSeamAllowance::SaveResizeDetail(qreal dLabelW, int iFontSize)
|
|
|
|
{
|
|
|
|
VPiece oldDet = VAbstractTool::data.GetPiece(id);
|
|
|
|
VPiece newDet = oldDet;
|
2017-03-13 13:27:29 +01:00
|
|
|
|
|
|
|
dLabelW = FromPixel(dLabelW, *VDataTool::data.GetPatternUnit());
|
|
|
|
newDet.GetPatternPieceData().SetLabelWidth(QString().setNum(dLabelW));
|
|
|
|
const qreal height = FromPixel(m_dataLabel->boundingRect().height(), *VDataTool::data.GetPatternUnit());
|
|
|
|
newDet.GetPatternPieceData().SetLabelHeight(QString().setNum(height));
|
2017-01-12 14:51:08 +01:00
|
|
|
newDet.GetPatternPieceData().SetFontSize(iFontSize);
|
2017-03-13 13:27:29 +01:00
|
|
|
|
2017-01-12 14:51:08 +01:00
|
|
|
SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, id);
|
|
|
|
resizeCommand->setText(tr("resize pattern piece label"));
|
|
|
|
connect(resizeCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(resizeCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief SaveRotationDetail saves the rotation detail label operation to the undo stack
|
|
|
|
*/
|
|
|
|
void VToolSeamAllowance::SaveRotationDetail(qreal dRot)
|
|
|
|
{
|
|
|
|
VPiece oldDet = VAbstractTool::data.GetPiece(id);
|
|
|
|
VPiece newDet = oldDet;
|
|
|
|
newDet.GetPatternPieceData().SetPos(m_dataLabel->pos());
|
|
|
|
newDet.GetPatternPieceData().SetFontSize(m_dataLabel->GetFontSize());
|
2017-03-13 15:57:54 +01:00
|
|
|
|
|
|
|
// Tranform angle to anticlockwise
|
|
|
|
QLineF line(0, 0, 100, 0);
|
|
|
|
line.setAngle(-dRot);
|
|
|
|
newDet.GetPatternPieceData().SetRotation(QString().setNum(line.angle()));
|
2017-01-12 14:51:08 +01:00
|
|
|
|
|
|
|
SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, id);
|
|
|
|
rotateCommand->setText(tr("rotate pattern piece label"));
|
|
|
|
connect(rotateCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(rotateCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief SaveMovePattern saves the pattern label position
|
|
|
|
*/
|
|
|
|
void VToolSeamAllowance::SaveMovePattern(const QPointF &ptPos)
|
|
|
|
{
|
|
|
|
VPiece oldDet = VAbstractTool::data.GetPiece(id);
|
|
|
|
VPiece newDet = oldDet;
|
|
|
|
newDet.GetPatternInfo().SetPos(ptPos);
|
|
|
|
|
|
|
|
SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, id);
|
|
|
|
moveCommand->setText(tr("move pattern info label"));
|
|
|
|
connect(moveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(moveCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief: SaveResizePattern saves the pattern label width and font size
|
|
|
|
*/
|
|
|
|
void VToolSeamAllowance::SaveResizePattern(qreal dLabelW, int iFontSize)
|
|
|
|
{
|
|
|
|
VPiece oldDet = VAbstractTool::data.GetPiece(id);
|
|
|
|
VPiece newDet = oldDet;
|
2017-03-13 13:27:29 +01:00
|
|
|
|
|
|
|
dLabelW = FromPixel(dLabelW, *VDataTool::data.GetPatternUnit());
|
|
|
|
newDet.GetPatternInfo().SetLabelWidth(QString().setNum(dLabelW));
|
|
|
|
qreal height = FromPixel(m_patternInfo->boundingRect().height(), *VDataTool::data.GetPatternUnit());
|
|
|
|
newDet.GetPatternInfo().SetLabelHeight(QString().setNum(height));
|
2017-01-12 14:51:08 +01:00
|
|
|
newDet.GetPatternInfo().SetFontSize(iFontSize);
|
2017-03-13 13:27:29 +01:00
|
|
|
|
2017-01-12 14:51:08 +01:00
|
|
|
SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, id);
|
|
|
|
resizeCommand->setText(tr("resize pattern info label"));
|
|
|
|
connect(resizeCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(resizeCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::SaveRotationPattern(qreal dRot)
|
|
|
|
{
|
|
|
|
VPiece oldDet = VAbstractTool::data.GetPiece(id);
|
|
|
|
VPiece newDet = oldDet;
|
2017-03-13 13:27:29 +01:00
|
|
|
|
2017-01-12 14:51:08 +01:00
|
|
|
newDet.GetPatternInfo().SetPos(m_patternInfo->pos());
|
|
|
|
newDet.GetPatternInfo().SetFontSize(m_patternInfo->GetFontSize());
|
2017-03-13 15:57:54 +01:00
|
|
|
|
|
|
|
// Tranform angle to anticlockwise
|
|
|
|
QLineF line(0, 0, 100, 0);
|
|
|
|
line.setAngle(-dRot);
|
2017-03-14 10:11:35 +01:00
|
|
|
newDet.GetPatternInfo().SetRotation(QString().setNum(line.angle()));
|
2017-01-12 14:51:08 +01:00
|
|
|
|
|
|
|
SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, id);
|
|
|
|
rotateCommand->setText(tr("rotate pattern info label"));
|
|
|
|
connect(rotateCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(rotateCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::SaveMoveGrainline(const QPointF& ptPos)
|
|
|
|
{
|
|
|
|
VPiece oldDet = VAbstractTool::data.GetPiece(id);
|
|
|
|
VPiece newDet = oldDet;
|
|
|
|
newDet.GetGrainlineGeometry().SetPos(ptPos);
|
|
|
|
qDebug() << "******* new grainline pos" << ptPos;
|
|
|
|
|
|
|
|
SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, id);
|
|
|
|
moveCommand->setText(tr("move grainline"));
|
|
|
|
connect(moveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(moveCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::SaveResizeGrainline(qreal dLength)
|
|
|
|
{
|
|
|
|
VPiece oldDet = VAbstractTool::data.GetPiece(id);
|
|
|
|
VPiece newDet = oldDet;
|
|
|
|
|
|
|
|
dLength = FromPixel(dLength, *VDataTool::data.GetPatternUnit());
|
2017-03-14 11:24:59 +01:00
|
|
|
newDet.GetGrainlineGeometry().SetPos(m_grainLine->pos());
|
2017-02-27 13:30:02 +01:00
|
|
|
newDet.GetGrainlineGeometry().SetLength(QString().setNum(dLength));
|
2017-01-12 14:51:08 +01:00
|
|
|
SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, id);
|
|
|
|
resizeCommand->setText(tr("resize grainline"));
|
|
|
|
connect(resizeCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(resizeCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::SaveRotateGrainline(qreal dRot, const QPointF& ptPos)
|
|
|
|
{
|
|
|
|
VPiece oldDet = VAbstractTool::data.GetPiece(id);
|
|
|
|
VPiece newDet = oldDet;
|
|
|
|
|
2017-03-13 13:27:29 +01:00
|
|
|
newDet.GetGrainlineGeometry().SetRotation(QString().setNum(qRadiansToDegrees(dRot)));
|
2017-01-12 14:51:08 +01:00
|
|
|
newDet.GetGrainlineGeometry().SetPos(ptPos);
|
|
|
|
SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, id);
|
|
|
|
rotateCommand->setText(tr("rotate grainline"));
|
|
|
|
connect(rotateCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(rotateCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief VToolDetail::paint draws a bounding box around detail, if one of its text or grainline items is not idle.
|
|
|
|
*/
|
|
|
|
void VToolSeamAllowance::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
2017-02-24 18:47:13 +01:00
|
|
|
if ((m_dataLabel->IsIdle() == false
|
|
|
|
|| m_patternInfo->IsIdle() == false
|
|
|
|
|| m_grainLine->IsIdle() == false) && not isSelected())
|
2017-01-12 14:51:08 +01:00
|
|
|
{
|
2017-02-04 19:30:32 +01:00
|
|
|
setSelected(true);
|
2017-01-12 14:51:08 +01:00
|
|
|
}
|
|
|
|
QGraphicsPathItem::paint(painter, option, widget);
|
|
|
|
}
|
|
|
|
|
2016-11-08 11:57:01 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::AddToFile()
|
|
|
|
{
|
|
|
|
const VPiece piece = VAbstractTool::data.GetPiece(id);
|
|
|
|
|
|
|
|
QDomElement domElement = doc->createElement(getTagName());
|
|
|
|
|
2016-11-09 13:11:58 +01:00
|
|
|
AddAttributes(doc, domElement, id, piece);
|
|
|
|
AddPatternPieceData(doc, domElement, piece);
|
|
|
|
AddPatternInfo(doc, domElement, piece);
|
|
|
|
AddGrainline(doc, domElement, piece);
|
2016-11-08 11:57:01 +01:00
|
|
|
|
|
|
|
// nodes
|
|
|
|
AddNodes(doc, domElement, piece);
|
2016-11-25 13:19:44 +01:00
|
|
|
//custom seam allowance
|
|
|
|
AddCSARecords(doc, domElement, piece.GetCustomSARecords());
|
2016-12-03 17:01:39 +01:00
|
|
|
AddInternalPaths(doc, domElement, piece.GetInternalPaths());
|
2017-01-31 17:09:18 +01:00
|
|
|
AddPins(doc, domElement, piece.GetPins());
|
2016-11-08 11:57:01 +01:00
|
|
|
|
|
|
|
AddPiece *addDet = new AddPiece(domElement, doc, piece, m_drawName);
|
|
|
|
connect(addDet, &AddPiece::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing);
|
|
|
|
qApp->getUndoStack()->push(addDet);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::RefreshDataInFile()
|
|
|
|
{
|
|
|
|
QDomElement domElement = doc->elementById(id);
|
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
|
|
|
// Refresh only parts that we possibly need to update
|
|
|
|
{
|
2016-11-08 15:34:44 +01:00
|
|
|
// TODO. Delete if minimal supported version is 0.4.0
|
|
|
|
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
|
2016-11-08 11:57:01 +01:00
|
|
|
"Time to refactor the code.");
|
2016-12-01 19:47:15 +01:00
|
|
|
|
|
|
|
const uint version = doc->GetParametrUInt(domElement, VToolSeamAllowance::AttrVersion, "1");
|
|
|
|
if (version == 1)
|
|
|
|
{
|
|
|
|
const VPiece piece = VAbstractTool::data.GetPiece(id);
|
|
|
|
|
|
|
|
doc->SetAttribute(domElement, AttrVersion, QString().setNum(pieceVersion));
|
|
|
|
|
|
|
|
doc->RemoveAllChildren(domElement);//Very important to clear before rewrite
|
|
|
|
AddPatternPieceData(doc, domElement, piece);
|
|
|
|
AddPatternInfo(doc, domElement, piece);
|
|
|
|
AddGrainline(doc, domElement, piece);
|
|
|
|
AddNodes(doc, domElement, piece);
|
|
|
|
AddCSARecords(doc, domElement, piece.GetCustomSARecords());
|
2016-12-03 17:01:39 +01:00
|
|
|
AddInternalPaths(doc, domElement, piece.GetInternalPaths());
|
2017-01-31 17:09:18 +01:00
|
|
|
AddPins(doc, domElement, piece.GetPins());
|
2016-12-01 19:47:15 +01:00
|
|
|
}
|
2016-11-08 11:57:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVariant VToolSeamAllowance::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
|
|
|
{
|
2016-11-09 12:06:05 +01:00
|
|
|
if (change == ItemPositionChange && scene())
|
|
|
|
{
|
|
|
|
// Each time we move something we call recalculation scene rect. In some cases this can cause moving
|
|
|
|
// objects positions. And this cause infinite redrawing. That's why we wait the finish of saving the last move.
|
|
|
|
static bool changeFinished = true;
|
|
|
|
if (changeFinished)
|
|
|
|
{
|
|
|
|
changeFinished = false;
|
|
|
|
|
|
|
|
// value - this is new position.
|
|
|
|
const QPointF newPos = value.toPointF();
|
|
|
|
|
|
|
|
MovePiece *moveDet = new MovePiece(doc, newPos.x(), newPos.y(), id, scene());
|
|
|
|
connect(moveDet, &MovePiece::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(moveDet);
|
|
|
|
|
|
|
|
const QList<QGraphicsView *> viewList = scene()->views();
|
|
|
|
if (not viewList.isEmpty())
|
|
|
|
{
|
|
|
|
if (QGraphicsView *view = viewList.at(0))
|
|
|
|
{
|
|
|
|
const int xmargin = 50;
|
|
|
|
const int ymargin = 50;
|
|
|
|
|
|
|
|
const QRectF viewRect = VMainGraphicsView::SceneVisibleArea(view);
|
|
|
|
const QRectF itemRect = mapToScene(boundingRect()|childrenBoundingRect()).boundingRect();
|
|
|
|
|
|
|
|
// If item's rect is bigger than view's rect ensureVisible works very unstable.
|
|
|
|
if (itemRect.height() + 2*ymargin < viewRect.height() &&
|
|
|
|
itemRect.width() + 2*xmargin < viewRect.width())
|
|
|
|
{
|
|
|
|
view->ensureVisible(itemRect, xmargin, ymargin);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Ensure visible only small rect around a cursor
|
|
|
|
VMainGraphicsScene *currentScene = qobject_cast<VMainGraphicsScene *>(scene());
|
|
|
|
SCASSERT(currentScene);
|
|
|
|
const QPointF cursorPosition = currentScene->getScenePos();
|
|
|
|
view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Don't forget to update geometry, because first change never call full parse
|
2016-11-12 14:41:15 +01:00
|
|
|
VPiece detail = VAbstractTool::data.GetPiece(id);
|
|
|
|
detail.SetMx(newPos.x());
|
|
|
|
detail.SetMy(newPos.y());
|
|
|
|
VAbstractTool::data.UpdatePiece(id, detail);
|
|
|
|
|
2016-11-09 12:06:05 +01:00
|
|
|
RefreshGeometry();
|
|
|
|
changeFinished = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (change == QGraphicsItem::ItemSelectedChange)
|
|
|
|
{
|
|
|
|
if (value == true)
|
|
|
|
{
|
|
|
|
// do stuff if selected
|
|
|
|
this->setFocus();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// do stuff if not selected
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-03 17:51:36 +01:00
|
|
|
return QGraphicsPathItem::itemChange(change, value);
|
2016-11-08 11:57:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
// Special for not selectable item first need to call standard mousePressEvent then accept event
|
2016-12-03 17:51:36 +01:00
|
|
|
QGraphicsPathItem::mousePressEvent(event);
|
2016-11-08 11:57:01 +01:00
|
|
|
|
|
|
|
// Somehow clicking on notselectable object do not clean previous selections.
|
|
|
|
if (not (flags() & ItemIsSelectable) && scene())
|
|
|
|
{
|
|
|
|
scene()->clearSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
|
|
|
|
{
|
|
|
|
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
|
|
|
|
{
|
|
|
|
doc->SelectedDetail(id);
|
|
|
|
emit ChoosedTool(id, SceneObject::Detail);
|
|
|
|
}
|
|
|
|
|
|
|
|
event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
//Disable cursor-arrow-closehand
|
|
|
|
RestoreOverrideCursor(cursorArrowCloseHand);
|
|
|
|
}
|
2016-12-03 17:51:36 +01:00
|
|
|
QGraphicsPathItem::mouseReleaseEvent(event);
|
2016-11-08 11:57:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
|
|
|
SetOverrideCursor(cursorArrowOpenHand, 1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
|
|
|
SetOverrideCursor(cursorArrowOpenHand, 1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
|
|
|
//Disable cursor-arrow-openhand
|
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
|
|
|
RestoreOverrideCursor(cursorArrowOpenHand);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
|
|
|
QMenu menu;
|
|
|
|
QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options"));
|
|
|
|
|
2016-11-09 14:53:22 +01:00
|
|
|
QAction *inLayoutOption = menu.addAction(tr("In layout"));
|
|
|
|
inLayoutOption->setCheckable(true);
|
|
|
|
const VPiece detail = VAbstractTool::data.GetPiece(id);
|
|
|
|
inLayoutOption->setChecked(detail.IsInLayout());
|
2016-11-08 11:57:01 +01:00
|
|
|
|
2016-11-09 10:57:39 +01:00
|
|
|
QAction *actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete"));
|
|
|
|
_referens > 1 ? actionRemove->setEnabled(false) : actionRemove->setEnabled(true);
|
2016-11-08 11:57:01 +01:00
|
|
|
|
|
|
|
QAction *selectedAction = menu.exec(event->screenPos());
|
|
|
|
if (selectedAction == actionOption)
|
|
|
|
{
|
2016-11-08 18:11:47 +01:00
|
|
|
auto *dialog = new DialogSeamAllowance(getData(), id, qApp->getMainWindow());
|
|
|
|
dialog->EnableApply(true);
|
|
|
|
m_dialog = dialog;
|
2016-11-08 11:57:01 +01:00
|
|
|
m_dialog->setModal(true);
|
2016-11-09 13:11:58 +01:00
|
|
|
connect(m_dialog.data(), &DialogTool::DialogClosed, this, &VToolSeamAllowance::FullUpdateFromGuiOk);
|
2016-11-09 15:27:55 +01:00
|
|
|
connect(m_dialog.data(), &DialogTool::DialogApplied, this, &VToolSeamAllowance::FullUpdateFromGuiApply);
|
2016-11-08 11:57:01 +01:00
|
|
|
SetDialog();
|
|
|
|
m_dialog->show();
|
|
|
|
}
|
2016-11-09 14:53:22 +01:00
|
|
|
else if (selectedAction == inLayoutOption)
|
|
|
|
{
|
|
|
|
TogglePieceInLayout *togglePrint = new TogglePieceInLayout(id, selectedAction->isChecked(),
|
|
|
|
&(VAbstractTool::data), doc);
|
|
|
|
connect(togglePrint, &TogglePieceInLayout::UpdateList, doc, &VAbstractPattern::CheckInLayoutList);
|
|
|
|
qApp->getUndoStack()->push(togglePrint);
|
|
|
|
}
|
2016-11-09 10:57:39 +01:00
|
|
|
else if (selectedAction == actionRemove)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
DeleteTool();
|
|
|
|
}
|
|
|
|
catch(const VExceptionToolWasDeleted &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e);
|
|
|
|
return;//Leave this method immediately!!!
|
|
|
|
}
|
|
|
|
return; //Leave this method immediately after call!!!
|
|
|
|
}
|
2016-11-08 11:57:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
2016-11-09 10:57:39 +01:00
|
|
|
switch (event->key())
|
|
|
|
{
|
|
|
|
case Qt::Key_Delete:
|
|
|
|
try
|
|
|
|
{
|
|
|
|
DeleteTool();
|
|
|
|
}
|
|
|
|
catch(const VExceptionToolWasDeleted &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e);
|
|
|
|
return;//Leave this method immediately!!!
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-12-03 17:51:36 +01:00
|
|
|
QGraphicsPathItem::keyReleaseEvent ( event );
|
2016-11-08 11:57:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::SetDialog()
|
|
|
|
{
|
2016-11-09 13:11:58 +01:00
|
|
|
SCASSERT(not m_dialog.isNull());
|
2016-11-08 11:57:01 +01:00
|
|
|
DialogSeamAllowance *dialogTool = qobject_cast<DialogSeamAllowance*>(m_dialog);
|
|
|
|
SCASSERT(dialogTool != nullptr);
|
|
|
|
dialogTool->SetPiece(VAbstractTool::data.GetPiece(id));
|
|
|
|
dialogTool->EnableApply(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VToolSeamAllowance::VToolSeamAllowance(VAbstractPattern *doc, VContainer *data, const quint32 &id,
|
|
|
|
const Source &typeCreation, VMainGraphicsScene *scene,
|
|
|
|
const QString &drawName, QGraphicsItem *parent)
|
|
|
|
: VAbstractTool(doc, data, id),
|
2016-12-03 17:51:36 +01:00
|
|
|
QGraphicsPathItem(parent),
|
2016-11-09 13:11:58 +01:00
|
|
|
m_dialog(),
|
2016-11-08 11:57:01 +01:00
|
|
|
m_sceneDetails(scene),
|
2016-11-10 13:06:09 +01:00
|
|
|
m_drawName(drawName),
|
2017-01-12 14:51:08 +01:00
|
|
|
m_seamAllowance(new VNoBrushScalePathItem(this)),
|
|
|
|
m_dataLabel(new VTextGraphicsItem(this)),
|
|
|
|
m_patternInfo(new VTextGraphicsItem(this)),
|
|
|
|
m_grainLine(new VGrainlineItem(this))
|
2016-11-08 11:57:01 +01:00
|
|
|
{
|
|
|
|
VPiece detail = data->GetPiece(id);
|
2016-11-25 15:37:32 +01:00
|
|
|
InitNodes(detail, scene);
|
|
|
|
InitCSAPaths(detail);
|
2016-12-03 17:01:39 +01:00
|
|
|
InitInternalPaths(detail);
|
2017-02-24 18:48:54 +01:00
|
|
|
InitPins(detail);
|
2016-11-08 11:57:01 +01:00
|
|
|
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
|
|
RefreshGeometry();
|
|
|
|
|
2017-03-28 12:09:00 +02:00
|
|
|
m_seamAllowance->setBrush(QBrush(Qt::Dense7Pattern));
|
2016-11-08 11:57:01 +01:00
|
|
|
|
|
|
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
|
|
|
|
|
|
|
|
connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolSeamAllowance::EnableToolMove);
|
2017-01-18 09:17:18 +01:00
|
|
|
connect(scene, &VMainGraphicsScene::ItemClicked, this, &VToolSeamAllowance::ResetChildren);
|
|
|
|
ToolCreation(typeCreation);
|
2016-11-08 11:57:01 +01:00
|
|
|
setAcceptHoverEvents(true);
|
2017-01-12 14:51:08 +01:00
|
|
|
|
|
|
|
connect(m_dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolSeamAllowance::SaveMoveDetail);
|
|
|
|
connect(m_dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolSeamAllowance::SaveResizeDetail);
|
|
|
|
connect(m_dataLabel, &VTextGraphicsItem::SignalRotated, this, &VToolSeamAllowance::SaveRotationDetail);
|
|
|
|
|
|
|
|
connect(m_patternInfo, &VTextGraphicsItem::SignalMoved, this, &VToolSeamAllowance::SaveMovePattern);
|
|
|
|
connect(m_patternInfo, &VTextGraphicsItem::SignalResized, this, &VToolSeamAllowance::SaveResizePattern);
|
|
|
|
connect(m_patternInfo, &VTextGraphicsItem::SignalRotated, this, &VToolSeamAllowance::SaveRotationPattern);
|
|
|
|
|
|
|
|
connect(m_grainLine, &VGrainlineItem::SignalMoved, this, &VToolSeamAllowance::SaveMoveGrainline);
|
|
|
|
connect(m_grainLine, &VGrainlineItem::SignalResized, this, &VToolSeamAllowance::SaveResizeGrainline);
|
|
|
|
connect(m_grainLine, &VGrainlineItem::SignalRotated, this, &VToolSeamAllowance::SaveRotateGrainline);
|
|
|
|
|
|
|
|
connect(doc, &VAbstractPattern::patternChanged, this, &VToolSeamAllowance::UpdatePatternInfo);
|
|
|
|
connect(doc, &VAbstractPattern::CheckLayout, this, &VToolSeamAllowance::UpdateLabel);
|
|
|
|
connect(doc, &VAbstractPattern::CheckLayout, this, &VToolSeamAllowance::UpdatePatternInfo);
|
|
|
|
connect(doc, &VAbstractPattern::CheckLayout, this, &VToolSeamAllowance::UpdateGrainline);
|
|
|
|
|
|
|
|
connect(m_sceneDetails, &VMainGraphicsScene::DimensionsChanged, this, &VToolSeamAllowance::UpdateLabel);
|
|
|
|
connect(m_sceneDetails, &VMainGraphicsScene::DimensionsChanged, this, &VToolSeamAllowance::UpdatePatternInfo);
|
|
|
|
connect(m_sceneDetails, &VMainGraphicsScene::LanguageChanged, this, &VToolSeamAllowance::retranslateUi);
|
|
|
|
|
|
|
|
UpdateLabel();
|
|
|
|
UpdatePatternInfo();
|
|
|
|
UpdateGrainline();
|
2016-11-08 11:57:01 +01:00
|
|
|
}
|
|
|
|
|
2017-03-22 11:05:53 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::UpdateExcludeState()
|
|
|
|
{
|
|
|
|
const VPiece detail = VAbstractTool::data.GetPiece(id);
|
|
|
|
for (int i = 0; i< detail.GetPath().CountNodes(); ++i)
|
|
|
|
{
|
|
|
|
const VPieceNode &node = detail.GetPath().at(i);
|
|
|
|
if (node.GetTypeTool() == Tool::NodePoint)
|
|
|
|
{
|
2017-03-23 09:25:46 +01:00
|
|
|
VNodePoint *tool = qobject_cast<VNodePoint*>(VAbstractPattern::getTool(node.GetId()));
|
2017-03-22 11:05:53 +01:00
|
|
|
SCASSERT(tool != nullptr);
|
|
|
|
|
|
|
|
tool->SetExluded(node.IsExcluded());
|
|
|
|
tool->setVisible(not node.IsExcluded());//Hide excluded point
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 11:57:01 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::RefreshGeometry()
|
|
|
|
{
|
|
|
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
|
|
|
|
|
|
|
|
const VPiece detail = VAbstractTool::data.GetPiece(id);
|
2017-03-28 12:09:00 +02:00
|
|
|
QPainterPath path = detail.MainPathPath(this->getData());
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainterPath mainPath = path;
|
|
|
|
mainPath.addPath(detail.PassmarksPath(this->getData()));
|
|
|
|
this->setPath(mainPath);
|
|
|
|
}
|
|
|
|
|
2016-11-08 11:57:01 +01:00
|
|
|
this->setPos(detail.GetMx(), detail.GetMy());
|
|
|
|
|
2016-11-10 13:06:09 +01:00
|
|
|
if (detail.IsSeamAllowance())
|
|
|
|
{
|
2017-03-28 12:09:00 +02:00
|
|
|
path.addPath(detail.SeamAllowancePath(this->getData()));
|
|
|
|
path.setFillRule(Qt::OddEvenFill);
|
|
|
|
m_seamAllowance->setPath(path);
|
2016-11-10 13:06:09 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_seamAllowance->setPath(QPainterPath());
|
|
|
|
}
|
|
|
|
|
2016-11-08 11:57:01 +01:00
|
|
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-09 15:27:55 +01:00
|
|
|
void VToolSeamAllowance::SaveDialogChange()
|
|
|
|
{
|
|
|
|
SCASSERT(not m_dialog.isNull());
|
|
|
|
DialogSeamAllowance *dialogTool = qobject_cast<DialogSeamAllowance*>(m_dialog.data());
|
|
|
|
SCASSERT(dialogTool != nullptr);
|
|
|
|
const VPiece newDet = dialogTool->GetPiece();
|
|
|
|
const VPiece oldDet = VAbstractTool::data.GetPiece(id);
|
|
|
|
|
2016-11-24 20:35:07 +01:00
|
|
|
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, id);
|
2016-11-09 15:27:55 +01:00
|
|
|
connect(saveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(saveCommand);
|
2017-01-12 14:51:08 +01:00
|
|
|
UpdateLabel();
|
2016-11-09 15:27:55 +01:00
|
|
|
}
|
|
|
|
|
2017-02-27 11:01:38 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-03-13 13:27:29 +01:00
|
|
|
VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &rotationAngle,
|
|
|
|
qreal &labelWidth, qreal &labelHeight, QPointF &pos)
|
2017-02-27 11:01:38 +01:00
|
|
|
{
|
2017-03-13 13:27:29 +01:00
|
|
|
|
|
|
|
VPieceItem::MoveTypes restrictions = VPieceItem::AllModifications;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (not qmu::QmuTokenParser::IsSingle(labelData.GetRotation()))
|
|
|
|
{
|
|
|
|
restrictions &= ~ VPieceItem::IsRotatable;
|
|
|
|
}
|
|
|
|
|
|
|
|
Calculator cal1;
|
|
|
|
rotationAngle = cal1.EvalFormula(VAbstractTool::data.PlainVariables(), labelData.GetRotation());
|
|
|
|
}
|
|
|
|
catch(qmu::QmuParserError &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e);
|
|
|
|
return VPieceItem::Error;
|
|
|
|
}
|
|
|
|
|
2017-02-27 11:01:38 +01:00
|
|
|
const quint32 topLeftPin = labelData.TopLeftPin();
|
|
|
|
const quint32 bottomRightPin = labelData.BottomRightPin();
|
|
|
|
|
|
|
|
if (topLeftPin != NULL_ID && bottomRightPin != NULL_ID)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const auto topLeftPinPoint = VAbstractTool::data.GeometricObject<VPointF>(topLeftPin);
|
|
|
|
const auto bottomRightPinPoint = VAbstractTool::data.GeometricObject<VPointF>(bottomRightPin);
|
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
const QRectF labelRect = QRectF(static_cast<QPointF>(*topLeftPinPoint),
|
|
|
|
static_cast<QPointF>(*bottomRightPinPoint));
|
2017-03-14 10:20:06 +01:00
|
|
|
labelWidth = FromPixel(qAbs(labelRect.width()), *VDataTool::data.GetPatternUnit());
|
|
|
|
labelHeight = FromPixel(qAbs(labelRect.height()), *VDataTool::data.GetPatternUnit());
|
2017-02-27 11:01:38 +01:00
|
|
|
|
|
|
|
pos = labelRect.topLeft();
|
|
|
|
|
2017-03-13 13:27:29 +01:00
|
|
|
restrictions &= ~ VPieceItem::IsMovable;
|
|
|
|
restrictions &= ~ VPieceItem::IsResizable;
|
|
|
|
|
|
|
|
return restrictions;
|
2017-02-27 11:01:38 +01:00
|
|
|
}
|
|
|
|
catch(const VExceptionBadId &)
|
|
|
|
{
|
|
|
|
// do nothing.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-13 13:27:29 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
const bool widthIsSingle = qmu::QmuTokenParser::IsSingle(labelData.GetLabelWidth());
|
|
|
|
|
|
|
|
Calculator cal1;
|
|
|
|
labelWidth = cal1.EvalFormula(VAbstractTool::data.PlainVariables(), labelData.GetLabelWidth());
|
|
|
|
|
|
|
|
const bool heightIsSingle = qmu::QmuTokenParser::IsSingle(labelData.GetLabelHeight());
|
|
|
|
|
|
|
|
Calculator cal2;
|
|
|
|
labelHeight = cal2.EvalFormula(VAbstractTool::data.PlainVariables(), labelData.GetLabelHeight());
|
|
|
|
|
|
|
|
if (not widthIsSingle || not heightIsSingle)
|
|
|
|
{
|
|
|
|
restrictions &= ~ VPieceItem::IsResizable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(qmu::QmuParserError &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e);
|
|
|
|
return VPieceItem::Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
const quint32 centerPin = labelData.CenterPin();
|
|
|
|
if (centerPin != NULL_ID)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const auto centerPinPoint = VAbstractTool::data.GeometricObject<VPointF>(centerPin);
|
|
|
|
|
|
|
|
const qreal lWidth = ToPixel(labelWidth, *VDataTool::data.GetPatternUnit());
|
|
|
|
const qreal lHeight = ToPixel(labelHeight, *VDataTool::data.GetPatternUnit());
|
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
pos = static_cast<QPointF>(*centerPinPoint) - QRectF(0, 0, lWidth, lHeight).center();
|
2017-03-13 13:27:29 +01:00
|
|
|
restrictions &= ~ VPieceItem::IsMovable;
|
|
|
|
}
|
|
|
|
catch(const VExceptionBadId &)
|
|
|
|
{
|
|
|
|
pos = labelData.GetPos();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = labelData.GetPos();
|
|
|
|
}
|
|
|
|
|
|
|
|
return restrictions;
|
2017-02-27 11:01:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-03-10 15:22:19 +01:00
|
|
|
VPieceItem::MoveTypes VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, qreal &length,
|
2017-02-27 13:30:02 +01:00
|
|
|
qreal &rotationAngle, QPointF &pos)
|
2017-02-27 11:01:38 +01:00
|
|
|
{
|
|
|
|
const quint32 topPin = geom.TopPin();
|
|
|
|
const quint32 bottomPin = geom.BottomPin();
|
|
|
|
|
|
|
|
if (topPin != NULL_ID && bottomPin != NULL_ID)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const auto topPinPoint = VAbstractTool::data.GeometricObject<VPointF>(topPin);
|
|
|
|
const auto bottomPinPoint = VAbstractTool::data.GeometricObject<VPointF>(bottomPin);
|
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
QLineF grainline(static_cast<QPointF>(*bottomPinPoint), static_cast<QPointF>(*topPinPoint));
|
2017-02-27 11:01:38 +01:00
|
|
|
length = FromPixel(grainline.length(), *VDataTool::data.GetPatternUnit());
|
|
|
|
rotationAngle = grainline.angle();
|
|
|
|
|
|
|
|
if (not VFuzzyComparePossibleNulls(rotationAngle, 0))
|
|
|
|
{
|
|
|
|
grainline.setAngle(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = grainline.p1();
|
|
|
|
|
2017-02-27 21:06:48 +01:00
|
|
|
return VPieceItem::NotMovable;
|
2017-02-27 11:01:38 +01:00
|
|
|
}
|
|
|
|
catch(const VExceptionBadId &)
|
|
|
|
{
|
|
|
|
// do nothing.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-10 15:22:19 +01:00
|
|
|
VPieceItem::MoveTypes restrictions = VPieceItem::AllModifications;
|
2017-02-27 11:01:38 +01:00
|
|
|
try
|
|
|
|
{
|
2017-03-10 15:22:19 +01:00
|
|
|
if (not qmu::QmuTokenParser::IsSingle(geom.GetRotation()))
|
|
|
|
{
|
|
|
|
restrictions &= ~ VPieceItem::IsRotatable;
|
|
|
|
}
|
2017-02-27 11:01:38 +01:00
|
|
|
|
|
|
|
Calculator cal1;
|
2017-02-27 13:30:02 +01:00
|
|
|
rotationAngle = cal1.EvalFormula(VAbstractTool::data.PlainVariables(), geom.GetRotation());
|
|
|
|
|
2017-03-10 15:22:19 +01:00
|
|
|
if (not qmu::QmuTokenParser::IsSingle(geom.GetLength()))
|
|
|
|
{
|
|
|
|
restrictions &= ~ VPieceItem::IsResizable;
|
|
|
|
}
|
2017-02-27 11:01:38 +01:00
|
|
|
|
|
|
|
Calculator cal2;
|
2017-02-27 13:30:02 +01:00
|
|
|
length = cal2.EvalFormula(VAbstractTool::data.PlainVariables(), geom.GetLength());
|
2017-02-27 11:01:38 +01:00
|
|
|
}
|
|
|
|
catch(qmu::QmuParserError &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e);
|
2017-02-27 13:30:02 +01:00
|
|
|
return VPieceItem::Error;
|
2017-02-27 11:01:38 +01:00
|
|
|
}
|
|
|
|
|
2017-03-10 15:22:19 +01:00
|
|
|
const quint32 centerPin = geom.CenterPin();
|
|
|
|
if (centerPin != NULL_ID)
|
2017-02-27 13:30:02 +01:00
|
|
|
{
|
2017-03-10 15:22:19 +01:00
|
|
|
try
|
2017-02-27 13:30:02 +01:00
|
|
|
{
|
2017-03-10 15:22:19 +01:00
|
|
|
const auto centerPinPoint = VAbstractTool::data.GeometricObject<VPointF>(centerPin);
|
|
|
|
|
|
|
|
const qreal cLength = ToPixel(length, *VDataTool::data.GetPatternUnit());
|
|
|
|
QLineF grainline(centerPinPoint->x(), centerPinPoint->y(),
|
|
|
|
centerPinPoint->x() + cLength / 2.0, centerPinPoint->y());
|
|
|
|
|
|
|
|
grainline.setAngle(rotationAngle);
|
|
|
|
grainline = QLineF(grainline.p2(), grainline.p1());
|
|
|
|
grainline.setLength(cLength);
|
2017-02-27 13:30:02 +01:00
|
|
|
|
2017-03-10 15:22:19 +01:00
|
|
|
pos = grainline.p2();
|
|
|
|
restrictions &= ~ VPieceItem::IsMovable;
|
|
|
|
}
|
|
|
|
catch(const VExceptionBadId &)
|
2017-02-27 13:30:02 +01:00
|
|
|
{
|
2017-03-10 15:22:19 +01:00
|
|
|
pos = geom.GetPos();
|
2017-02-27 13:30:02 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-10 15:22:19 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = geom.GetPos();
|
|
|
|
}
|
|
|
|
|
|
|
|
return restrictions;
|
2017-02-27 11:01:38 +01:00
|
|
|
}
|
|
|
|
|
2016-11-09 15:27:55 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-25 15:37:32 +01:00
|
|
|
void VToolSeamAllowance::InitNodes(const VPiece &detail, VMainGraphicsScene *scene)
|
|
|
|
{
|
|
|
|
for (int i = 0; i< detail.GetPath().CountNodes(); ++i)
|
|
|
|
{
|
2017-03-21 17:00:31 +01:00
|
|
|
InitNode(detail.GetPath().at(i), scene, &(VAbstractTool::data), doc, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::InitNode(const VPieceNode &node, VMainGraphicsScene *scene, VContainer *data,
|
|
|
|
VAbstractPattern *doc, VToolSeamAllowance *parent)
|
|
|
|
{
|
|
|
|
SCASSERT(scene != nullptr)
|
|
|
|
SCASSERT(data != nullptr)
|
|
|
|
SCASSERT(doc != nullptr)
|
|
|
|
SCASSERT(parent != nullptr)
|
|
|
|
|
|
|
|
switch (node.GetTypeTool())
|
|
|
|
{
|
|
|
|
case (Tool::NodePoint):
|
2016-11-25 15:37:32 +01:00
|
|
|
{
|
2017-03-23 09:25:46 +01:00
|
|
|
VNodePoint *tool = qobject_cast<VNodePoint*>(VAbstractPattern::getTool(node.GetId()));
|
2017-03-21 17:00:31 +01:00
|
|
|
SCASSERT(tool != nullptr);
|
|
|
|
|
|
|
|
connect(tool, &VNodePoint::ShowContextMenu, parent, &VToolSeamAllowance::contextMenuEvent);
|
|
|
|
connect(tool, &VNodePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
tool->setParentItem(parent);
|
|
|
|
tool->SetParentType(ParentType::Item);
|
2017-03-22 11:05:53 +01:00
|
|
|
tool->SetExluded(node.IsExcluded());
|
2017-03-21 17:00:31 +01:00
|
|
|
tool->setVisible(not node.IsExcluded());//Hide excluded point
|
|
|
|
doc->IncrementReferens(node.GetId());
|
|
|
|
break;
|
2016-11-25 15:37:32 +01:00
|
|
|
}
|
2017-03-21 17:00:31 +01:00
|
|
|
case (Tool::NodeArc):
|
|
|
|
case (Tool::NodeElArc):
|
|
|
|
case (Tool::NodeSpline):
|
|
|
|
case (Tool::NodeSplinePath):
|
|
|
|
doc->IncrementReferens(data->GetGObject(node.GetId())->getIdTool());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qDebug()<<"Get wrong tool type. Ignore.";
|
|
|
|
break;
|
2016-11-25 15:37:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::InitCSAPaths(const VPiece &detail)
|
|
|
|
{
|
2017-01-31 15:26:28 +01:00
|
|
|
for (int i = 0; i < detail.GetCustomSARecords().size(); ++i)
|
2016-11-25 15:37:32 +01:00
|
|
|
{
|
2017-01-31 15:26:28 +01:00
|
|
|
doc->IncrementReferens(detail.GetCustomSARecords().at(i).path);
|
2016-11-25 15:37:32 +01:00
|
|
|
}
|
2016-12-03 17:01:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::InitInternalPaths(const VPiece &detail)
|
|
|
|
{
|
2017-01-31 15:26:28 +01:00
|
|
|
for (int i = 0; i < detail.GetInternalPaths().size(); ++i)
|
2016-12-03 17:01:39 +01:00
|
|
|
{
|
2017-03-23 09:25:46 +01:00
|
|
|
auto *tool = qobject_cast<VToolPiecePath*>(VAbstractPattern::getTool(detail.GetInternalPaths().at(i)));
|
2016-12-03 17:01:39 +01:00
|
|
|
SCASSERT(tool != nullptr);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
tool->SetParentType(ParentType::Item);
|
2017-01-18 09:17:18 +01:00
|
|
|
tool->show();
|
2017-01-31 15:26:28 +01:00
|
|
|
doc->IncrementReferens(detail.GetInternalPaths().at(i));
|
2016-12-03 17:01:39 +01:00
|
|
|
}
|
2016-11-25 15:37:32 +01:00
|
|
|
}
|
|
|
|
|
2017-02-24 18:48:54 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSeamAllowance::InitPins(const VPiece &detail)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < detail.GetPins().size(); ++i)
|
|
|
|
{
|
|
|
|
doc->IncrementReferens(detail.GetPins().at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-25 15:37:32 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-08 11:57:01 +01:00
|
|
|
void VToolSeamAllowance::DeleteTool(bool ask)
|
|
|
|
{
|
2017-02-18 09:43:06 +01:00
|
|
|
QScopedPointer<DeletePiece> delDet(new DeletePiece(doc, id, VAbstractTool::data.GetPiece(id)));
|
2016-11-09 10:57:39 +01:00
|
|
|
if (ask)
|
|
|
|
{
|
|
|
|
if (ConfirmDeletion() == QMessageBox::No)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* If UnionDetails tool delete detail no need emit FullParsing.*/
|
2017-02-18 09:43:06 +01:00
|
|
|
connect(delDet.data(), &DeletePiece::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing);
|
2016-11-09 10:57:39 +01:00
|
|
|
}
|
2017-01-18 11:22:02 +01:00
|
|
|
|
|
|
|
// If UnionDetails tool delete the detail this object will be deleted only after full parse.
|
|
|
|
// Deleting inside UnionDetails cause crash.
|
|
|
|
// Because this object should be inactive from no one we disconnect all signals that may cause a crash
|
|
|
|
// KEEP THIS LIST ACTUALL!!!
|
|
|
|
disconnect(doc, 0, this, 0);
|
|
|
|
if (QGraphicsScene *toolScene = scene())
|
|
|
|
{
|
|
|
|
disconnect(toolScene, 0, this, 0);
|
|
|
|
}
|
|
|
|
disconnect(m_dataLabel, 0, this, 0);
|
|
|
|
disconnect(m_patternInfo, 0, this, 0);
|
|
|
|
disconnect(m_grainLine, 0, this, 0);
|
|
|
|
disconnect(m_sceneDetails, 0, this, 0);
|
|
|
|
|
|
|
|
hide();// User shouldn't see this object
|
|
|
|
|
2017-02-18 09:43:06 +01:00
|
|
|
qApp->getUndoStack()->push(delDet.take());
|
2016-11-08 11:57:01 +01:00
|
|
|
|
2016-11-09 10:57:39 +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;
|
2016-11-08 11:57:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-18 09:17:18 +01:00
|
|
|
void VToolSeamAllowance::ToolCreation(const Source &typeCreation)
|
2016-11-08 11:57:01 +01:00
|
|
|
{
|
2017-01-18 09:17:18 +01:00
|
|
|
if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
|
|
|
|
{
|
|
|
|
AddToFile();
|
|
|
|
if (typeCreation != Source::FromTool)
|
|
|
|
{
|
|
|
|
qApp->getUndoStack()->endMacro();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RefreshDataInFile();
|
|
|
|
}
|
2016-11-08 11:57:01 +01:00
|
|
|
}
|