2016-11-09 13:11:58 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 9 11, 2016
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2016-11-09 13:11:58 +01:00
|
|
|
** 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 "savepieceoptions.h"
|
|
|
|
|
|
|
|
#include <QDomElement>
|
|
|
|
#include <QPointF>
|
|
|
|
#include <QUndoCommand>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
#include "../ifc/xml/vabstractpattern.h"
|
|
|
|
#include "../ifc/ifcdef.h"
|
|
|
|
#include "../vmisc/logging.h"
|
|
|
|
#include "../vmisc/def.h"
|
|
|
|
#include "../vpatterndb/vpiecenode.h"
|
2017-02-23 10:37:19 +01:00
|
|
|
#include "../vpatterndb/floatItemData/vpatternlabeldata.h"
|
|
|
|
#include "../vpatterndb/floatItemData/vpiecelabeldata.h"
|
|
|
|
#include "../vpatterndb/floatItemData/vgrainlinedata.h"
|
2016-11-09 13:11:58 +01:00
|
|
|
#include "../tools/vtoolseamallowance.h"
|
|
|
|
#include "vundocommand.h"
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-28 09:45:02 +01:00
|
|
|
SavePieceOptions::SavePieceOptions(const VPiece &oldDet, const VPiece &newDet, VAbstractPattern *doc, quint32 id,
|
|
|
|
QUndoCommand *parent)
|
2016-11-09 13:11:58 +01:00
|
|
|
: VUndoCommand(QDomElement(), doc, parent),
|
|
|
|
m_oldDet(oldDet),
|
2016-11-24 20:27:47 +01:00
|
|
|
m_newDet(newDet)
|
2016-11-09 13:11:58 +01:00
|
|
|
{
|
|
|
|
setText(tr("save detail option"));
|
|
|
|
nodeId = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void SavePieceOptions::undo()
|
|
|
|
{
|
|
|
|
qCDebug(vUndo, "Undo.");
|
|
|
|
|
2017-08-02 13:10:10 +02:00
|
|
|
QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagDetail);
|
2016-11-09 13:11:58 +01:00
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
|
|
|
VToolSeamAllowance::AddAttributes(doc, domElement, nodeId, m_oldDet);
|
|
|
|
doc->RemoveAllChildren(domElement);//Very important to clear before rewrite
|
|
|
|
VToolSeamAllowance::AddPatternPieceData(doc, domElement, m_oldDet);
|
|
|
|
VToolSeamAllowance::AddPatternInfo(doc, domElement, m_oldDet);
|
|
|
|
VToolSeamAllowance::AddGrainline(doc, domElement, m_oldDet);
|
|
|
|
VToolSeamAllowance::AddNodes(doc, domElement, m_oldDet);
|
2016-11-25 13:19:44 +01:00
|
|
|
VToolSeamAllowance::AddCSARecords(doc, domElement, m_oldDet.GetCustomSARecords());
|
2016-12-03 17:01:39 +01:00
|
|
|
VToolSeamAllowance::AddInternalPaths(doc, domElement, m_oldDet.GetInternalPaths());
|
2017-01-31 17:09:18 +01:00
|
|
|
VToolSeamAllowance::AddPins(doc, domElement, m_oldDet.GetPins());
|
2017-10-15 11:25:20 +02:00
|
|
|
VToolSeamAllowance::AddPlaceLabels(doc, domElement, m_oldDet.GetPlaceLabels());
|
2016-11-09 13:11:58 +01:00
|
|
|
|
2017-10-18 10:56:29 +02:00
|
|
|
DecrementReferences(m_newDet.MissingNodes(m_oldDet));
|
2016-11-25 14:35:52 +01:00
|
|
|
IncrementReferences(m_oldDet.MissingNodes(m_newDet));
|
2017-10-18 10:56:29 +02:00
|
|
|
|
|
|
|
DecrementReferences(m_newDet.MissingCSAPath(m_oldDet));
|
2016-11-25 15:12:33 +01:00
|
|
|
IncrementReferences(m_oldDet.MissingCSAPath(m_newDet));
|
2017-10-18 10:56:29 +02:00
|
|
|
|
|
|
|
DecrementReferences(m_newDet.MissingInternalPaths(m_oldDet));
|
2016-12-03 17:01:39 +01:00
|
|
|
IncrementReferences(m_oldDet.MissingInternalPaths(m_newDet));
|
2017-10-18 10:56:29 +02:00
|
|
|
|
|
|
|
DecrementReferences(m_newDet.MissingPins(m_oldDet));
|
2017-01-31 17:09:18 +01:00
|
|
|
IncrementReferences(m_oldDet.MissingPins(m_newDet));
|
2017-10-15 11:25:20 +02:00
|
|
|
|
|
|
|
DecrementReferences(m_newDet.MissingPlaceLabels(m_oldDet));
|
|
|
|
IncrementReferences(m_oldDet.MissingPlaceLabels(m_newDet));
|
|
|
|
|
2017-10-18 10:56:29 +02:00
|
|
|
if (VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(nodeId)))
|
|
|
|
{
|
|
|
|
tool->Update(m_oldDet);
|
|
|
|
}
|
2016-11-09 13:11:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qCDebug(vUndo, "Can't find detail with id = %u.", nodeId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void SavePieceOptions::redo()
|
|
|
|
{
|
|
|
|
qCDebug(vUndo, "Redo.");
|
|
|
|
|
2017-08-02 13:10:10 +02:00
|
|
|
QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagDetail);
|
2016-11-09 13:11:58 +01:00
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
|
|
|
VToolSeamAllowance::AddAttributes(doc, domElement, nodeId, m_newDet);
|
|
|
|
doc->RemoveAllChildren(domElement);//Very important to clear before rewrite
|
|
|
|
VToolSeamAllowance::AddPatternPieceData(doc, domElement, m_newDet);
|
|
|
|
VToolSeamAllowance::AddPatternInfo(doc, domElement, m_newDet);
|
|
|
|
VToolSeamAllowance::AddGrainline(doc, domElement, m_newDet);
|
|
|
|
VToolSeamAllowance::AddNodes(doc, domElement, m_newDet);
|
2016-11-25 13:19:44 +01:00
|
|
|
VToolSeamAllowance::AddCSARecords(doc, domElement, m_newDet.GetCustomSARecords());
|
2016-12-03 17:01:39 +01:00
|
|
|
VToolSeamAllowance::AddInternalPaths(doc, domElement, m_newDet.GetInternalPaths());
|
2017-01-31 17:09:18 +01:00
|
|
|
VToolSeamAllowance::AddPins(doc, domElement, m_newDet.GetPins());
|
2017-10-15 11:25:20 +02:00
|
|
|
VToolSeamAllowance::AddPlaceLabels(doc, domElement, m_newDet.GetPlaceLabels());
|
2016-11-09 13:11:58 +01:00
|
|
|
|
2016-11-25 14:35:52 +01:00
|
|
|
DecrementReferences(m_oldDet.MissingNodes(m_newDet));
|
2017-10-18 10:56:29 +02:00
|
|
|
IncrementReferences(m_newDet.MissingNodes(m_oldDet));
|
|
|
|
|
2016-11-25 15:12:33 +01:00
|
|
|
DecrementReferences(m_oldDet.MissingCSAPath(m_newDet));
|
2017-10-18 10:56:29 +02:00
|
|
|
IncrementReferences(m_newDet.MissingCSAPath(m_oldDet));
|
|
|
|
|
2016-12-03 17:01:39 +01:00
|
|
|
DecrementReferences(m_oldDet.MissingInternalPaths(m_newDet));
|
2017-10-18 10:56:29 +02:00
|
|
|
IncrementReferences(m_newDet.MissingInternalPaths(m_oldDet));
|
|
|
|
|
2017-01-31 17:09:18 +01:00
|
|
|
DecrementReferences(m_oldDet.MissingPins(m_newDet));
|
2017-10-18 10:56:29 +02:00
|
|
|
IncrementReferences(m_newDet.MissingPins(m_oldDet));
|
2016-11-25 15:12:33 +01:00
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
DecrementReferences(m_oldDet.MissingPlaceLabels(m_newDet));
|
|
|
|
IncrementReferences(m_newDet.MissingPlaceLabels(m_oldDet));
|
|
|
|
|
2017-10-18 10:56:29 +02:00
|
|
|
if (VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(nodeId)))
|
|
|
|
{
|
|
|
|
tool->Update(m_newDet);
|
|
|
|
}
|
2016-11-09 13:11:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qCDebug(vUndo, "Can't find detail with id = %u.", nodeId);
|
|
|
|
}
|
|
|
|
}
|