New undo command MoveSplinePath.
--HG-- branch : feature
This commit is contained in:
parent
43935b95c9
commit
6bcf80e7a8
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "vtoolsplinepath.h"
|
||||
#include "../../dialogs/tools/dialogsplinepath.h"
|
||||
#include "../../undocommands/movesplinepath.h"
|
||||
|
||||
const QString VToolSplinePath::ToolType = QStringLiteral("path");
|
||||
|
||||
|
@ -132,8 +133,9 @@ void VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphics
|
|||
void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, const SplinePoint::Position &position,
|
||||
const QPointF &pos)
|
||||
{
|
||||
VSplinePath splPath = *VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
|
||||
VSpline spl = splPath.GetSpline(indexSpline);
|
||||
VSplinePath oldSplPath = *VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
|
||||
VSplinePath newSplPath = oldSplPath;
|
||||
VSpline spl = newSplPath.GetSpline(indexSpline);
|
||||
if (position == SplinePoint::FirstPoint)
|
||||
{
|
||||
spl = VSpline(spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve());
|
||||
|
@ -143,19 +145,15 @@ void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, cons
|
|||
spl = VSpline(spl.GetP1(), spl.GetP2(), pos, spl.GetP4(), spl.GetKcurve());
|
||||
}
|
||||
|
||||
CorectControlPoints(spl, splPath, indexSpline);
|
||||
QDomElement domElement = doc->elementById(QString().setNum(id));
|
||||
if (domElement.isElement())
|
||||
{
|
||||
doc->SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve()));
|
||||
UpdatePathPoint(domElement, splPath);
|
||||
emit LiteUpdateTree();
|
||||
emit toolhaveChange();
|
||||
}
|
||||
UpdateControlPoints(spl, newSplPath, indexSpline);
|
||||
|
||||
MoveSplinePath *moveSplPath = new MoveSplinePath(doc, oldSplPath, newSplPath, id, this->scene());
|
||||
connect(moveSplPath, &MoveSplinePath::NeedLiteParsing, doc, &VPattern::LiteParseTree);
|
||||
qApp->getUndoStack()->push(moveSplPath);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolSplinePath::CorectControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline)
|
||||
void VToolSplinePath::UpdateControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline)
|
||||
{
|
||||
VSplinePoint p = splPath.GetSplinePoint(indexSpline, SplinePoint::FirstPoint);
|
||||
p.SetAngle2(spl.GetAngle1());
|
||||
|
@ -188,14 +186,14 @@ void VToolSplinePath::RefreshSplinePath(VSplinePath &splPath)
|
|||
|
||||
spl = VSpline (spl.GetP1(), controlPoints[j-2]->pos(), controlPoints[j-1]->pos(), spl.GetP4(),
|
||||
splPath.getKCurve());
|
||||
CorectControlPoints(spl, splPath, i);
|
||||
CorectControlPoints(spl, splPath, i);
|
||||
UpdateControlPoints(spl, splPath, i);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolSplinePath::UpdatePathPoint(QDomNode& node, VSplinePath &path)
|
||||
void VToolSplinePath::UpdatePathPoint(VPattern *doc, QDomNode& node, const VSplinePath &path)
|
||||
{
|
||||
SCASSERT(doc != nullptr)
|
||||
QDomNodeList nodeList = node.childNodes();
|
||||
qint32 num = nodeList.size();
|
||||
for (qint32 i = 0; i < num; ++i)
|
||||
|
@ -248,7 +246,7 @@ void VToolSplinePath::RefreshDataInFile()
|
|||
VSplinePath splPath = *VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
|
||||
RefreshSplinePath(splPath);
|
||||
doc->SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve()));
|
||||
UpdatePathPoint(domElement, splPath);
|
||||
UpdatePathPoint(doc, domElement, splPath);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -294,7 +292,7 @@ void VToolSplinePath::SaveDialog(QDomElement &domElement)
|
|||
VSplinePath splPath = dialogTool->GetPath();
|
||||
RefreshSplinePath(splPath);
|
||||
doc->SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve()));
|
||||
UpdatePathPoint(domElement, splPath);
|
||||
UpdatePathPoint(doc, domElement, splPath);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -74,6 +74,13 @@ public:
|
|||
VPattern *doc, VContainer *data, const Document::Documents &parse,
|
||||
const Valentina::Sources &typeCreation);
|
||||
static const QString ToolType;
|
||||
/**
|
||||
* @brief UpdatePathPoint update spline path in pattern file.
|
||||
* @brief doc dom document container.
|
||||
* @param node tag in file.
|
||||
* @param path spline path.
|
||||
*/
|
||||
static void UpdatePathPoint(VPattern *doc, QDomNode& node, const VSplinePath &path);
|
||||
signals:
|
||||
/**
|
||||
* @brief RefreshLine refresh control line.
|
||||
|
@ -137,18 +144,12 @@ private:
|
|||
*/
|
||||
void AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint);
|
||||
/**
|
||||
* @brief UpdatePathPoint update spline path in pattern file.
|
||||
* @param node tag in file.
|
||||
* @param path spline path.
|
||||
*/
|
||||
void UpdatePathPoint(QDomNode& node, VSplinePath &path);
|
||||
/**
|
||||
* @brief CorectControlPoints update position points control points in file.
|
||||
* @brief UpdateControlPoints update position points control points in file.
|
||||
* @param spl spline what was changed.
|
||||
* @param splPath spline path.
|
||||
* @param indexSpline index spline in spline path.
|
||||
*/
|
||||
void CorectControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline);
|
||||
void UpdateControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline);
|
||||
void RefreshSplinePath(VSplinePath &splPath);
|
||||
};
|
||||
|
||||
|
|
102
src/app/undocommands/movesplinepath.cpp
Normal file
102
src/app/undocommands/movesplinepath.cpp
Normal file
|
@ -0,0 +1,102 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file movesplinepath.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 11 6, 2014
|
||||
**
|
||||
** @brief
|
||||
** @copyright
|
||||
** This source code is part of the Valentine project, a pattern making
|
||||
** program, whose allow create and modeling patterns of clothing.
|
||||
** Copyright (C) 2014 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 "movesplinepath.h"
|
||||
#include <QDomElement>
|
||||
#include "../tools/drawTools/vtoolsplinepath.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
MoveSplinePath::MoveSplinePath(VPattern *doc, const VSplinePath &oldSplPath, const VSplinePath &newSplPath,
|
||||
const quint32 &id, QGraphicsScene *scene, QUndoCommand *parent)
|
||||
: QObject(), QUndoCommand(parent), doc(doc), oldSplinePath(oldSplPath), newSplinePath(newSplPath), splinePathId(id),
|
||||
scene(scene)
|
||||
{
|
||||
setText(tr("Move spline path"));
|
||||
|
||||
SCASSERT(scene != nullptr);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
MoveSplinePath::~MoveSplinePath()
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void MoveSplinePath::undo()
|
||||
{
|
||||
QDomElement domElement = doc->elementById(QString().setNum(splinePathId));
|
||||
if (domElement.isElement())
|
||||
{
|
||||
doc->SetAttribute(domElement, VToolSplinePath::AttrKCurve, QString().setNum(oldSplinePath.getKCurve()));
|
||||
VToolSplinePath::UpdatePathPoint(doc, domElement, oldSplinePath);
|
||||
|
||||
emit NeedLiteParsing();
|
||||
|
||||
QList<QGraphicsView*> list = scene->views();
|
||||
VAbstractTool::NewSceneRect(scene, list[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug()<<"Can't find spline path with id ="<< splinePathId << Q_FUNC_INFO;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void MoveSplinePath::redo()
|
||||
{
|
||||
QDomElement domElement = doc->elementById(QString().setNum(splinePathId));
|
||||
if (domElement.isElement())
|
||||
{
|
||||
doc->SetAttribute(domElement, VToolSplinePath::AttrKCurve, QString().setNum(newSplinePath.getKCurve()));
|
||||
VToolSplinePath::UpdatePathPoint(doc, domElement, newSplinePath);
|
||||
|
||||
emit NeedLiteParsing();
|
||||
|
||||
QList<QGraphicsView*> list = scene->views();
|
||||
VAbstractTool::NewSceneRect(scene, list[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug()<<"Can't find spline path with id ="<< splinePathId << Q_FUNC_INFO;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool MoveSplinePath::mergeWith(const QUndoCommand *command)
|
||||
{
|
||||
const MoveSplinePath *moveCommand = static_cast<const MoveSplinePath *>(command);
|
||||
SCASSERT(moveCommand != nullptr);
|
||||
const quint32 id = moveCommand->getSplinePathId();
|
||||
|
||||
if (id != splinePathId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
newSplinePath = moveCommand->getNewSplinePath();
|
||||
return true;
|
||||
}
|
82
src/app/undocommands/movesplinepath.h
Normal file
82
src/app/undocommands/movesplinepath.h
Normal file
|
@ -0,0 +1,82 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file movesplinepath.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 11 6, 2014
|
||||
**
|
||||
** @brief
|
||||
** @copyright
|
||||
** This source code is part of the Valentine project, a pattern making
|
||||
** program, whose allow create and modeling patterns of clothing.
|
||||
** Copyright (C) 2014 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/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef MOVESPLINEPATH_H
|
||||
#define MOVESPLINEPATH_H
|
||||
|
||||
#include <QUndoCommand>
|
||||
#include "../geometry/vsplinepath.h"
|
||||
#include <QtCore>
|
||||
|
||||
class VPattern;
|
||||
class QGraphicsScene;
|
||||
|
||||
class MoveSplinePath : public QObject, public QUndoCommand
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MoveSplinePath(VPattern *doc, const VSplinePath &oldSplPath, const VSplinePath &newSplPath, const quint32 &id,
|
||||
QGraphicsScene *scene, QUndoCommand *parent = 0);
|
||||
virtual ~MoveSplinePath();
|
||||
virtual void undo();
|
||||
virtual void redo();
|
||||
virtual bool mergeWith(const QUndoCommand *command);
|
||||
virtual int id() const;
|
||||
quint32 getSplinePathId() const;
|
||||
VSplinePath getNewSplinePath() const;
|
||||
signals:
|
||||
void NeedLiteParsing();
|
||||
private:
|
||||
Q_DISABLE_COPY(MoveSplinePath)
|
||||
enum { Id = 2 };
|
||||
VPattern *doc;
|
||||
VSplinePath oldSplinePath;
|
||||
VSplinePath newSplinePath;
|
||||
quint32 splinePathId;
|
||||
QGraphicsScene *scene;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
inline int MoveSplinePath::id() const
|
||||
{
|
||||
return Id;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
inline quint32 MoveSplinePath::getSplinePathId() const
|
||||
{
|
||||
return splinePathId;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
inline VSplinePath MoveSplinePath::getNewSplinePath() const
|
||||
{
|
||||
return newSplinePath;
|
||||
}
|
||||
|
||||
#endif // MOVESPLINEPATH_H
|
|
@ -2,12 +2,14 @@ HEADERS += \
|
|||
undocommands/addtocalc.h \
|
||||
undocommands/addpatternpiece.h \
|
||||
undocommands/movespoint.h \
|
||||
undocommands/movespline.h
|
||||
undocommands/movespline.h \
|
||||
undocommands/movesplinepath.h
|
||||
|
||||
|
||||
SOURCES += \
|
||||
undocommands/addtocalc.cpp \
|
||||
undocommands/addpatternpiece.cpp \
|
||||
undocommands/movespoint.cpp \
|
||||
undocommands/movespline.cpp
|
||||
undocommands/movespline.cpp \
|
||||
undocommands/movesplinepath.cpp
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ public:
|
|||
* @return cursor
|
||||
* @throw VExceptionUniqueId
|
||||
*/
|
||||
void SetAttribute(QDomElement &domElement, const QString &name, const T &value)
|
||||
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const
|
||||
{
|
||||
QString val = QString().setNum(value);
|
||||
val = val.replace(",", ".");
|
||||
|
@ -170,14 +170,15 @@ private:
|
|||
};
|
||||
|
||||
template <>
|
||||
inline void VDomDocument::SetAttribute<QString>(QDomElement &domElement, const QString &name, const QString &value)
|
||||
inline void VDomDocument::SetAttribute<QString>(QDomElement &domElement, const QString &name,
|
||||
const QString &value) const
|
||||
{
|
||||
domElement.setAttribute(name, value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void VDomDocument::SetAttribute<Pattern::Measurements>(QDomElement &domElement, const QString &name,
|
||||
const Pattern::Measurements &value)
|
||||
const Pattern::Measurements &value) const
|
||||
{
|
||||
if (value == Pattern::Standard)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user