Added support for operation tools.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-09-20 12:10:57 +03:00
parent af1e01c243
commit f7c75111ce
18 changed files with 295 additions and 74 deletions

View File

@ -252,6 +252,7 @@
<xs:attribute name="idObject" type="xs:unsignedInt" use="required"/>
<xs:attribute name="mx" type="xs:double"/>
<xs:attribute name="my" type="xs:double"/>
<xs:attribute name="showLabel" type="xs:boolean"/>
</xs:complexType>
</xs:element>
</xs:sequence>

View File

@ -111,21 +111,27 @@ VPointF::operator QPointF() const
VPointF VPointF::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const
{
const QPointF p = RotatePF(originPoint, toQPointF(), degrees);
return VPointF(p, name() + prefix, mx(), my());
VPointF rotated(p, name() + prefix, mx(), my());
rotated.SetShowLabel(IsShowLabel());
return rotated;
}
//---------------------------------------------------------------------------------------------------------------------
VPointF VPointF::Flip(const QLineF &axis, const QString &prefix) const
{
const QPointF p = FlipPF(axis, toQPointF());
return VPointF(p, name() + prefix, mx(), my());
VPointF flipped(p, name() + prefix, mx(), my());
flipped.SetShowLabel(IsShowLabel());
return flipped;
}
//---------------------------------------------------------------------------------------------------------------------
VPointF VPointF::Move(qreal length, qreal angle, const QString &prefix) const
{
const QPointF p = MovePF(toQPointF(), length, angle);
return VPointF(p, name() + prefix, mx(), my());
VPointF moved(p, name() + prefix, mx(), my());
moved.SetShowLabel(IsShowLabel());
return moved;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -120,8 +120,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
case GOType::Point:
{
const DestinationItem &item = initData.destination.at(i);
UpdatePoint(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data, item.id, item.mx,
item.my);
UpdatePoint(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data, item);
break;
}
case GOType::Arc:
@ -171,6 +170,7 @@ DestinationItem VAbstractFlipping::CreatePoint(quint32 idTool, quint32 idItem, c
DestinationItem item;
item.mx = rotated.mx();
item.my = rotated.my();
item.showLabel = rotated.IsShowLabel();
item.id = data->AddGObject(new VPointF(rotated));
return item;
}
@ -187,15 +187,16 @@ DestinationItem VAbstractFlipping::CreateArc(quint32 idTool, quint32 idItem, con
//---------------------------------------------------------------------------------------------------------------------
void VAbstractFlipping::UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id,
qreal mx, qreal my)
const QPointF &secondPoint, const QString &suffix, VContainer *data,
const DestinationItem &item)
{
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(idItem);
VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix);
rotated.setIdObject(idTool);
rotated.setMx(mx);
rotated.setMy(my);
data->UpdateGObject(id, new VPointF(rotated));
rotated.setMx(item.mx);
rotated.setMy(item.my);
rotated.SetShowLabel(item.showLabel);
data->UpdateGObject(item.id, new VPointF(rotated));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -62,7 +62,7 @@ protected:
const QPointF &secondPoint, const QString &suffix, VContainer *data);
static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint,
const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my);
const QString &suffix, VContainer *data, const DestinationItem &item);
template <class Item>
static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint,
const QString &suffix, VContainer *data, quint32 id);

View File

@ -28,6 +28,7 @@
#include "vabstractoperation.h"
#include "../../../undocommands/label/operationmovelabel.h"
#include "../../../undocommands/label/operationshowlabel.h"
#include "../vgeometry/vpointf.h"
const QString VAbstractOperation::TagItem = QStringLiteral("item");
@ -84,6 +85,38 @@ void VAbstractOperation::paint(QPainter *painter, const QStyleOptionGraphicsItem
Q_UNUSED(widget)
}
//---------------------------------------------------------------------------------------------------------------------
bool VAbstractOperation::IsLabelVisible(quint32 id) const
{
if (operatedObjects.contains(id))
{
VAbstractSimple *obj = operatedObjects.value(id);
if (obj && obj->GetType() == GOType::Point)
{
return VAbstractTool::data.GeometricObject<VPointF>(id)->IsShowLabel();
}
}
return false;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractOperation::SetLabelVisible(quint32 id, bool visible)
{
if (operatedObjects.contains(id))
{
VAbstractSimple *obj = operatedObjects.value(id);
if (obj && obj->GetType() == GOType::Point)
{
VSimplePoint *item = qobject_cast<VSimplePoint *>(obj);
SCASSERT(item != nullptr)
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
point->SetShowLabel(visible);
item->RefreshPointGeometry(*point);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractOperation::ExtractData(const QDomElement &domElement, VAbstractOperationInitData &initData)
{
@ -118,6 +151,7 @@ void VAbstractOperation::ExtractData(const QDomElement &domElement, VAbstractOpe
d.id = VDomDocument::GetParametrUInt(element, AttrIdObject, NULL_ID_STR);
d.mx = qApp->toPixel(VDomDocument::GetParametrDouble(element, AttrMx, QString::number(INT_MAX)));
d.my = qApp->toPixel(VDomDocument::GetParametrDouble(element, AttrMy, QString::number(INT_MAX)));
d.showLabel = VDomDocument::GetParametrBool(element, AttrShowLabel, trueStr);
initData.destination.append(d);
}
}
@ -426,6 +460,19 @@ void VAbstractOperation::AddToFile()
AddToCalculation(domElement);
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractOperation::ChangeLabelVisibility(quint32 id, bool visible)
{
if (operatedObjects.contains(id))
{
VAbstractSimple *obj = operatedObjects.value(id);
if (obj && obj->GetType() == GOType::Point)
{
qApp->getUndoStack()->push(new OperationShowLabel(doc, m_id, id, visible));
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractOperation::UpdateNamePosition(quint32 id)
{
@ -460,6 +507,7 @@ void VAbstractOperation::SaveSourceDestination(QDomElement &tag)
{
doc->SetAttribute(item, AttrMx, qApp->fromPixel(destination.at(i).mx));
doc->SetAttribute(item, AttrMy, qApp->fromPixel(destination.at(i).my));
doc->SetAttribute<bool>(item, AttrShowLabel, destination.at(i).showLabel);
}
tagObjects.appendChild(item);

View File

@ -47,6 +47,7 @@ struct DestinationItem
quint32 id;
qreal mx;
qreal my;
bool showLabel;
};
struct VAbstractOperationInitData : public VAbstractToolInitData
@ -87,6 +88,9 @@ public:
virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE;
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
virtual bool IsLabelVisible(quint32 id) const Q_DECL_OVERRIDE;
virtual void SetLabelVisible(quint32 id, bool visible) Q_DECL_OVERRIDE;
static void ExtractData(const QDomElement &domElement, VAbstractOperationInitData &initData);
public slots:
virtual void FullUpdateFromFile() Q_DECL_OVERRIDE;
@ -131,6 +135,7 @@ protected:
QGraphicsItem *parent = nullptr);
virtual void AddToFile() Q_DECL_OVERRIDE;
virtual void ChangeLabelVisibility(quint32 id, bool visible) Q_DECL_OVERRIDE;
void UpdateNamePosition(quint32 id);
void SaveSourceDestination(QDomElement &tag);

View File

@ -191,12 +191,9 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
switch(static_cast<GOType>(obj->getType()))
{
case GOType::Point:
{
const DestinationItem &item = initData.destination.at(i);
UpdatePoint(initData.id, idObject, calcAngle, calcLength, initData.suffix, initData.data, item.id,
item.mx, item.my);
UpdatePoint(initData.id, idObject, calcAngle, calcLength, initData.suffix, initData.data,
initData.destination.at(i));
break;
}
case GOType::Arc:
UpdateArc<VArc>(initData.id, idObject, calcAngle, calcLength, initData.suffix, initData.data,
initData.destination.at(i).id);
@ -397,6 +394,7 @@ DestinationItem VToolMove::CreatePoint(quint32 idTool, quint32 idItem, qreal ang
DestinationItem item;
item.mx = moved.mx();
item.my = moved.my();
item.showLabel = moved.IsShowLabel();
item.id = data->AddGObject(new VPointF(moved));
return item;
}
@ -413,14 +411,15 @@ DestinationItem VToolMove::CreateArc(quint32 idTool, quint32 idItem, qreal angle
//---------------------------------------------------------------------------------------------------------------------
void VToolMove::UpdatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data, quint32 id, qreal mx, qreal my)
VContainer *data, const DestinationItem &item)
{
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(idItem);
VPointF moved = point->Move(length, angle, suffix);
moved.setIdObject(idTool);
moved.setMx(mx);
moved.setMy(my);
data->UpdateGObject(id, new VPointF(moved));
moved.setMx(item.mx);
moved.setMy(item.my);
moved.SetShowLabel(item.showLabel);
data->UpdateGObject(item.id, new VPointF(moved));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -111,7 +111,7 @@ private:
const QString &suffix, VContainer *data);
static void UpdatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data, quint32 id, qreal mx, qreal my);
VContainer *data, const DestinationItem &item);
template <class Item>
static void UpdateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data, quint32 id);

View File

@ -208,9 +208,8 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
{
case GOType::Point:
{
const DestinationItem &item = initData.destination.at(i);
UpdatePoint(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data,
item.id, item.mx, item.my);
initData.destination.at(i));
break;
}
case GOType::Arc:
@ -384,6 +383,7 @@ DestinationItem VToolRotation::CreatePoint(quint32 idTool, quint32 idItem, const
DestinationItem item;
item.mx = rotated.mx();
item.my = rotated.my();
item.showLabel = rotated.IsShowLabel();
item.id = data->AddGObject(new VPointF(rotated));
return item;
}
@ -436,14 +436,15 @@ DestinationItem VToolRotation::CreateCurveWithSegments(quint32 idTool, quint32 i
//---------------------------------------------------------------------------------------------------------------------
void VToolRotation::UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle,
const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my)
const QString &suffix, VContainer *data, const DestinationItem &item)
{
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(idItem);
VPointF rotated = point->Rotate(origin, angle, suffix);
rotated.setIdObject(idTool);
rotated.setMx(mx);
rotated.setMy(my);
data->UpdateGObject(id, new VPointF(rotated));
rotated.setMx(item.mx);
rotated.setMy(item.my);
rotated.SetShowLabel(item.showLabel);
data->UpdateGObject(item.id, new VPointF(rotated));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -111,7 +111,7 @@ private:
qreal angle, const QString &suffix, VContainer *data);
static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle,
const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my);
const QString &suffix, VContainer *data, const DestinationItem &item);
template <class Item>
static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle,
const QString &suffix, VContainer *data, quint32 id);

View File

@ -31,7 +31,6 @@
#include <QDomNode>
#include <QDomNodeList>
#include "../../tools/drawTools/operation/vtoolrotation.h"
#include "../ifc/xml/vabstractpattern.h"
#include "../ifc/ifcdef.h"
#include "../vmisc/logging.h"
@ -112,42 +111,3 @@ void OperationMoveLabel::Do(double mx, double my)
qCDebug(vUndo, "Can't find point with id = %u.", nodeId);
}
}
//---------------------------------------------------------------------------------------------------------------------
QDomElement OperationMoveLabel::GetDestinationObject(quint32 idTool, quint32 idPoint) const
{
const QDomElement tool = doc->elementById(idTool, VAbstractPattern::TagOperation);
if (tool.isElement())
{
QDomElement correctDest;
const QDomNodeList nodeList = tool.childNodes();
for (qint32 i = 0; i < nodeList.size(); ++i)
{
const QDomElement dest = nodeList.at(i).toElement();
if (not dest.isNull() && dest.isElement() && dest.tagName() == VAbstractOperation::TagDestination)
{
correctDest = dest;
break;
}
}
if (not correctDest.isNull())
{
const QDomNodeList destObjects = correctDest.childNodes();
for (qint32 i = 0; i < destObjects.size(); ++i)
{
const QDomElement obj = destObjects.at(i).toElement();
if (not obj.isNull() && obj.isElement())
{
const quint32 id = doc->GetParametrUInt(obj, AttrIdObject, NULL_ID_STR);
if (idPoint == id)
{
return obj;
}
}
}
}
}
return QDomElement();
}

View File

@ -55,8 +55,6 @@ protected:
private:
Q_DISABLE_COPY(OperationMoveLabel)
quint32 m_idTool;
QDomElement GetDestinationObject(quint32 idTool, quint32 idPoint) const;
};
//---------------------------------------------------------------------------------------------------------------------

View File

@ -0,0 +1,101 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 20 9, 2017
**
** @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) 2017 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 "operationshowlabel.h"
#include <QDomElement>
#include "../ifc/xml/vabstractpattern.h"
#include "../vmisc/logging.h"
#include "../vwidgets/vmaingraphicsview.h"
#include "../vmisc/vabstractapplication.h"
#include "../vtools/tools/drawTools/vdrawtool.h"
//---------------------------------------------------------------------------------------------------------------------
OperationShowLabel::OperationShowLabel(VAbstractPattern *doc, quint32 idTool, quint32 idPoint, bool visible,
QUndoCommand *parent)
: VUndoCommand(QDomElement(), doc, parent),
m_visible(visible),
m_oldVisible(not visible),
m_scene(qApp->getCurrentScene()),
m_idTool(idTool)
{
nodeId = idPoint;
qCDebug(vUndo, "Point id %u", nodeId);
setText(tr("toggle label"));
qCDebug(vUndo, "Tool id %u", m_idTool);
const QDomElement element = GetDestinationObject(m_idTool, nodeId);
if (element.isElement())
{
m_oldVisible = doc->GetParametrBool(element, AttrShowLabel, trueStr);
}
else
{
qCDebug(vUndo, "Can't find point with id = %u.", nodeId);
}
}
//---------------------------------------------------------------------------------------------------------------------
void OperationShowLabel::undo()
{
qCDebug(vUndo, "Undo.");
Do(m_oldVisible);
}
//---------------------------------------------------------------------------------------------------------------------
void OperationShowLabel::redo()
{
qCDebug(vUndo, "Redo.");
Do(m_visible);
}
//---------------------------------------------------------------------------------------------------------------------
void OperationShowLabel::Do(bool visible)
{
QDomElement domElement = GetDestinationObject(m_idTool, nodeId);
if (not domElement.isNull() && domElement.isElement())
{
doc->SetAttribute<bool>(domElement, AttrShowLabel, visible);
if (VDrawTool *tool = qobject_cast<VDrawTool *>(VAbstractPattern::getTool(m_idTool)))
{
tool->SetLabelVisible(nodeId, visible);
}
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
}
else
{
qCDebug(vUndo, "Can't find point with id = %u.", nodeId);
}
}

View File

@ -0,0 +1,57 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 20 9, 2017
**
** @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) 2017 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 OPERATIONSHOWLABEL_H
#define OPERATIONSHOWLABEL_H
#include "../vundocommand.h"
class QGraphicsScene;
class OperationShowLabel : public VUndoCommand
{
public:
OperationShowLabel(VAbstractPattern *doc, quint32 idTool, quint32 idPoint, bool visible,
QUndoCommand *parent = nullptr);
virtual ~OperationShowLabel()=default;
virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(OperationShowLabel)
bool m_visible;
bool m_oldVisible;
//Need for resizing scene rect
QGraphicsScene *m_scene;
quint32 m_idTool;
void Do(bool visible);
};
#endif // OPERATIONSHOWLABEL_H

View File

@ -51,11 +51,11 @@ ShowDoubleLabel::ShowDoubleLabel(VAbstractPattern *doc, quint32 toolId, quint32
if (type == ShowDoublePoint::FirstPoint)
{
setText(tr("show the first dart label"));
setText(tr("toggle the first dart label"));
}
else
{
setText(tr("show the second dart label"));
setText(tr("togggle the second dart label"));
}
const QDomElement domElement = doc->elementById(m_idTool, VAbstractPattern::TagPoint);

View File

@ -26,7 +26,8 @@ HEADERS += \
$$PWD/togglepieceinlayout.h \
$$PWD/savepiecepathoptions.h \
$$PWD/label/showlabel.h \
$$PWD/label/showdoublelabel.h
$$PWD/label/showdoublelabel.h \
$$PWD/label/operationshowlabel.h
SOURCES += \
$$PWD/addtocalc.cpp \
@ -53,4 +54,5 @@ SOURCES += \
$$PWD/togglepieceinlayout.cpp \
$$PWD/savepiecepathoptions.cpp \
$$PWD/label/showlabel.cpp \
$$PWD/label/showdoublelabel.cpp
$$PWD/label/showdoublelabel.cpp \
$$PWD/label/operationshowlabel.cpp

View File

@ -36,6 +36,7 @@
#include "../vmisc/customevents.h"
#include "../vpatterndb/vnodedetail.h"
#include "../vpatterndb/vpiecenode.h"
#include "../tools/drawTools/operation/vabstractoperation.h"
Q_LOGGING_CATEGORY(vUndo, "v.undo")
@ -143,3 +144,42 @@ void VUndoCommand::DecrementReferences(const QVector<VPieceNode> &nodes) const
DecrementReferences(n);
}
//---------------------------------------------------------------------------------------------------------------------
QDomElement VUndoCommand::GetDestinationObject(quint32 idTool, quint32 idPoint) const
{
const QDomElement tool = doc->elementById(idTool, VAbstractPattern::TagOperation);
if (tool.isElement())
{
QDomElement correctDest;
const QDomNodeList nodeList = tool.childNodes();
for (qint32 i = 0; i < nodeList.size(); ++i)
{
const QDomElement dest = nodeList.at(i).toElement();
if (not dest.isNull() && dest.isElement() && dest.tagName() == VAbstractOperation::TagDestination)
{
correctDest = dest;
break;
}
}
if (not correctDest.isNull())
{
const QDomNodeList destObjects = correctDest.childNodes();
for (qint32 i = 0; i < destObjects.size(); ++i)
{
const QDomElement obj = destObjects.at(i).toElement();
if (not obj.isNull() && obj.isElement())
{
const quint32 id = doc->GetParametrUInt(obj, AttrIdObject, NULL_ID_STR);
if (idPoint == id)
{
return obj;
}
}
}
}
}
return QDomElement();
}

View File

@ -90,6 +90,8 @@ protected:
void IncrementReferences(const QVector<VPieceNode> &nodes) const;
void DecrementReferences(const QVector<VPieceNode> &nodes) const;
QDomElement GetDestinationObject(quint32 idTool, quint32 idPoint) const;
private:
Q_DISABLE_COPY(VUndoCommand)
};