2014-06-05 11:52:00 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
2014-06-09 19:39:18 +02:00
|
|
|
** @file movespoint.cpp
|
2014-06-05 11:52:00 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2014-06-09 19:39:18 +02:00
|
|
|
** @date 9 6, 2014
|
2014-06-05 11:52:00 +02:00
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2014-06-05 11:52:00 +02:00
|
|
|
** <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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
2014-06-09 19:39:18 +02:00
|
|
|
#include "movespoint.h"
|
2015-06-18 19:23:24 +02:00
|
|
|
|
2014-06-09 19:39:18 +02:00
|
|
|
#include <QDomElement>
|
2014-06-05 11:52:00 +02:00
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../ifc/xml/vabstractpattern.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vmisc/logging.h"
|
|
|
|
#include "../vmisc/vabstractapplication.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../vmisc/def.h"
|
|
|
|
#include "vundocommand.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2014-06-11 19:12:46 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-06-16 10:30:25 +02:00
|
|
|
MoveSPoint::MoveSPoint(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id,
|
|
|
|
QGraphicsScene *scene, QUndoCommand *parent)
|
2014-07-16 14:37:38 +02:00
|
|
|
: VUndoCommand(QDomElement(), doc, parent), oldX(0.0), oldY(0.0), newX(x), newY(y), scene(scene)
|
2014-06-09 15:13:15 +02:00
|
|
|
{
|
2015-06-24 16:48:57 +02:00
|
|
|
setText(tr("move single point"));
|
2014-07-16 14:37:38 +02:00
|
|
|
nodeId = id;
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "SPoint id %u", nodeId);
|
2014-11-24 14:03:34 +01:00
|
|
|
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "SPoint newX %f", newX);
|
|
|
|
qCDebug(vUndo, "SPoint newY %f", newY);
|
2014-06-09 15:13:15 +02:00
|
|
|
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(scene != nullptr)
|
2017-08-02 13:10:10 +02:00
|
|
|
QDomElement domElement = doc->elementById(id, VAbstractPattern::TagPoint);
|
2014-06-09 15:13:15 +02:00
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2015-08-11 15:41:03 +02:00
|
|
|
oldX = qApp->toPixel(doc->GetParametrDouble(domElement, AttrX, "0.0"));
|
|
|
|
oldY = qApp->toPixel(doc->GetParametrDouble(domElement, AttrY, "0.0"));
|
2014-11-24 14:03:34 +01:00
|
|
|
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "SPoint oldX %f", oldX);
|
|
|
|
qCDebug(vUndo, "SPoint oldY %f", oldY);
|
2014-06-09 15:13:15 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Can't find spoint with id = %u.", nodeId);
|
2014-06-09 15:13:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
MoveSPoint::~MoveSPoint()
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MoveSPoint::undo()
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Undo.");
|
2014-11-20 18:52:51 +01:00
|
|
|
|
2014-07-16 14:37:38 +02:00
|
|
|
Do(oldX, oldY);
|
2014-06-09 15:13:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MoveSPoint::redo()
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Redo.");
|
2014-11-20 18:52:51 +01:00
|
|
|
|
2014-07-16 14:37:38 +02:00
|
|
|
Do(newX, newY);
|
2014-06-09 15:13:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool MoveSPoint::mergeWith(const QUndoCommand *command)
|
|
|
|
{
|
|
|
|
const MoveSPoint *moveCommand = static_cast<const MoveSPoint *>(command);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(moveCommand != nullptr)
|
2014-06-09 15:13:15 +02:00
|
|
|
const quint32 id = moveCommand->getSPointId();
|
|
|
|
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Mergin.");
|
2014-07-16 14:37:38 +02:00
|
|
|
if (id != nodeId)
|
2014-06-09 15:13:15 +02:00
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Merging canceled.");
|
2014-06-09 15:13:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Mergin undo.");
|
2014-06-09 15:13:15 +02:00
|
|
|
newX = moveCommand->getNewX();
|
|
|
|
newY = moveCommand->getNewY();
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "SPoint newX %f", newX);
|
|
|
|
qCDebug(vUndo, "SPoint newY %f", newY);
|
2014-06-09 15:13:15 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-06-11 19:12:46 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int MoveSPoint::id() const
|
|
|
|
{
|
|
|
|
return static_cast<int>(UndoCommand::MoveSPoint);
|
|
|
|
}
|
2014-07-16 14:37:38 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MoveSPoint::Do(double x, double y)
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Move to x %f", x);
|
|
|
|
qCDebug(vUndo, "Move to y %f", y);
|
2014-11-24 14:03:34 +01:00
|
|
|
|
2017-08-02 13:10:10 +02:00
|
|
|
QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagPoint);
|
2014-07-16 14:37:38 +02:00
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2015-08-11 15:41:03 +02:00
|
|
|
doc->SetAttribute(domElement, AttrX, QString().setNum(qApp->fromPixel(x)));
|
|
|
|
doc->SetAttribute(domElement, AttrY, QString().setNum(qApp->fromPixel(y)));
|
2014-07-16 14:37:38 +02:00
|
|
|
|
2014-08-04 15:37:36 +02:00
|
|
|
emit NeedLiteParsing(Document::LitePPParse);
|
2014-07-16 14:37:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Can't find spoint with id = %u.", nodeId);
|
2014-07-16 14:37:38 +02:00
|
|
|
}
|
|
|
|
}
|