diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index 863eb5601..76da8fa15 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -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(id); - VSpline spl = splPath.GetSpline(indexSpline); + VSplinePath oldSplPath = *VAbstractTool::data.GeometricObject(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(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); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolsplinepath.h b/src/app/tools/drawTools/vtoolsplinepath.h index de8406cf3..8f802043c 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.h +++ b/src/app/tools/drawTools/vtoolsplinepath.h @@ -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); }; diff --git a/src/app/undocommands/movesplinepath.cpp b/src/app/undocommands/movesplinepath.cpp new file mode 100644 index 000000000..bb9bd53fb --- /dev/null +++ b/src/app/undocommands/movesplinepath.cpp @@ -0,0 +1,102 @@ +/************************************************************************ + ** + ** @file movesplinepath.cpp + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#include "movesplinepath.h" +#include +#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 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 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(command); + SCASSERT(moveCommand != nullptr); + const quint32 id = moveCommand->getSplinePathId(); + + if (id != splinePathId) + { + return false; + } + + newSplinePath = moveCommand->getNewSplinePath(); + return true; +} diff --git a/src/app/undocommands/movesplinepath.h b/src/app/undocommands/movesplinepath.h new file mode 100644 index 000000000..923217b07 --- /dev/null +++ b/src/app/undocommands/movesplinepath.h @@ -0,0 +1,82 @@ +/************************************************************************ + ** + ** @file movesplinepath.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#ifndef MOVESPLINEPATH_H +#define MOVESPLINEPATH_H + +#include +#include "../geometry/vsplinepath.h" +#include + +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 diff --git a/src/app/undocommands/undocommands.pri b/src/app/undocommands/undocommands.pri index 584d56b1a..04c5128b9 100644 --- a/src/app/undocommands/undocommands.pri +++ b/src/app/undocommands/undocommands.pri @@ -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 diff --git a/src/app/xml/vdomdocument.h b/src/app/xml/vdomdocument.h index ba658f7bd..261fec73c 100644 --- a/src/app/xml/vdomdocument.h +++ b/src/app/xml/vdomdocument.h @@ -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(QDomElement &domElement, const QString &name, const QString &value) +inline void VDomDocument::SetAttribute(QDomElement &domElement, const QString &name, + const QString &value) const { domElement.setAttribute(name, value); } template <> inline void VDomDocument::SetAttribute(QDomElement &domElement, const QString &name, - const Pattern::Measurements &value) + const Pattern::Measurements &value) const { if (value == Pattern::Standard) {