diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index cb4631ef6..15e01e201 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -53,6 +53,7 @@ #include "../vtools/dialogs/tooldialogs.h" #include "tools/vtoolseamallowance.h" #include "tools/nodeDetails/vtoolpiecepath.h" +#include "tools/nodeDetails/vtoolpin.h" #include "tools/vtooluniondetails.h" #include "dialogs/dialogs.h" #include "dialogs/vwidgetgroups.h" @@ -1156,13 +1157,13 @@ void MainWindow::ClosedDialogPiecePath(int result) //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ClosedDialogPin(int result) { -// SCASSERT(dialogTool != nullptr); -// if (result == QDialog::Accepted) -// { -// VToolPin::Create(dialogTool, sceneDetails, doc, pattern); -// } + SCASSERT(dialogTool != nullptr); + if (result == QDialog::Accepted) + { + VToolPin::Create(dialogTool, doc, pattern); + } ArrowTool(); -// doc->LiteParseTree(Document::LiteParse); + doc->LiteParseTree(Document::LiteParse); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 5d512ea19..4abbb696a 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -963,7 +963,8 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem << VToolPointFromCircleAndTangent::ToolType /*19*/ << VToolPointFromArcAndTangent::ToolType /*20*/ << VToolTrueDarts::ToolType /*21*/ - << VToolPointOfIntersectionCurves::ToolType; /*22*/ + << VToolPointOfIntersectionCurves::ToolType /*22*/ + << VToolPin::ToolType; /*23*/ switch (points.indexOf(type)) { case 0: //VToolBasePoint::ToolType @@ -1035,6 +1036,9 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem case 22: //VToolPointOfIntersectionCurves::ToolType ParseToolPointOfIntersectionCurves(scene, domElement, parse); break; + case 23: //VToolPin::ToolType + ParsePinPoint(domElement, parse); + break; default: VException e(tr("Unknown point type '%1'.").arg(type)); throw e; @@ -1536,6 +1540,28 @@ void VPattern::ParseNodePoint(const QDomElement &domElement, const Document &par } } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParsePinPoint(const QDomElement &domElement, const Document &parse) +{ + Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); + + try + { + quint32 id = 0; + + ToolsCommonAttributes(domElement, id); + const quint32 idObject = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); + const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); + VToolPin::Create(id, idObject, NULL_ID, this, data, parse, Source::FromFile, "", idTool); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating pin point"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } +} + //--------------------------------------------------------------------------------------------------------------------- void VPattern::ParseToolHeight(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse) { diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 1c0fb2f3f..9b5b74342 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -167,6 +167,7 @@ private: void ParseToolLineIntersect(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseToolPointOfContact(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParseNodePoint(const QDomElement &domElement, const Document &parse); + void ParsePinPoint(const QDomElement &domElement, const Document &parse); void ParseToolHeight(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseToolTriangle(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseToolPointOfIntersection(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); diff --git a/src/libs/vtools/tools/nodeDetails/nodedetails.h b/src/libs/vtools/tools/nodeDetails/nodedetails.h index 918551ec5..60b1f6b25 100644 --- a/src/libs/vtools/tools/nodeDetails/nodedetails.h +++ b/src/libs/vtools/tools/nodeDetails/nodedetails.h @@ -35,5 +35,6 @@ #include "vnodespline.h" #include "vnodesplinepath.h" #include "vtoolpiecepath.h" +#include "vtoolpin.h" #endif // NODEDETAILS_H diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpin.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpin.cpp new file mode 100644 index 000000000..456a691f6 --- /dev/null +++ b/src/libs/vtools/tools/nodeDetails/vtoolpin.cpp @@ -0,0 +1,168 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 31 1, 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 + ** 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 "vtoolpin.h" +#include "../../dialogs/tools/dialogpin.h" +#include "../../undocommands/savepieceoptions.h" +#include "../vtoolseamallowance.h" +#include "../vgeometry/vpointf.h" + +const QString VToolPin::ToolType = QStringLiteral("pin"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolPin *VToolPin::Create(DialogTool *dialog, VAbstractPattern *doc, VContainer *data) +{ + SCASSERT(dialog != nullptr); + DialogPin *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const quint32 pointId = dialogTool->GetPointId(); + const quint32 pieceId = dialogTool->GetPieceId(); + + return Create(0, pointId, pieceId, doc, data, Document::FullParse, Source::FromGui); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolPin *VToolPin::Create(quint32 _id, quint32 pointId, quint32 pieceId, VAbstractPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation, const QString &drawName, + const quint32 &idTool) +{ + quint32 id = _id; + if (typeCreation == Source::FromGui) + { + id = CreateNode(data, pointId); + } + else + { + QSharedPointer point; + try + { + point = data->GeometricObject(pointId); + } + catch (const VExceptionBadId &e) + { // Possible case. Parent was deleted, but the node object is still here. + Q_UNUSED(e) + return nullptr;// Just ignore + } + VPointF *pinPoint = new VPointF(*point); + pinPoint->setMode(Draw::Modeling); + data->UpdateGObject(id, pinPoint); + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + VAbstractTool::AddRecord(id, Tool::Pin, doc); + VToolPin *point = nullptr; + if (parse == Document::FullParse) + { + point = new VToolPin(doc, data, id, pointId, pieceId, typeCreation, drawName, idTool, doc); + + doc->AddTool(id, point); + if (idTool != NULL_ID) + { + //Some nodes we don't show on scene. Tool that create this nodes must free memory. + VDataTool *tool = doc->getTool(idTool); + SCASSERT(tool != nullptr) + point->setParent(tool);// Adopted by a tool + } + else + { + // Help to delete the node before each FullParse + doc->AddToolOnRemove(point); + } + } + else + { + doc->UpdateToolData(id, data); + } + return point; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VToolPin::getTagName() const +{ + return VAbstractPattern::TagPoint; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPin::AllowHover(bool enabled) +{ + Q_UNUSED(enabled) + // do nothing +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPin::AllowSelecting(bool enabled) +{ + Q_UNUSED(enabled) + // do nothing +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPin::AddToFile() +{ + QDomElement domElement = doc->createElement(getTagName()); + + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrIdObject, idNode); + if (idTool != NULL_ID) + { + doc->SetAttribute(domElement, AttrIdTool, idTool); + } + + AddToModeling(domElement); + + if (m_pieceId > NULL_ID) + { +// const VPiece oldDet = VAbstractTool::data.GetPiece(m_pieceId); +// VPiece newDet = oldDet; + +// newDet.GetPins().append(id); + +// SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_pieceId); +// qApp->getUndoStack()->push(saveCommand);// First push then make a connect +// VAbstractTool::data.UpdatePiece(m_pieceId, newDet);// Update piece because first save will not call lite update +// connect(saveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPin::RefreshDataInFile() +{ + // do nothing +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolPin::VToolPin(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 pointId, quint32 pieceId, + const Source &typeCreation, const QString &drawName, const quint32 &idTool, QObject *qoParent) + : VAbstractNode(doc, data, id, pointId, drawName, idTool, qoParent), + m_pieceId(pieceId) +{ + ToolCreation(typeCreation); +} diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpin.h b/src/libs/vtools/tools/nodeDetails/vtoolpin.h new file mode 100644 index 000000000..9b98d0489 --- /dev/null +++ b/src/libs/vtools/tools/nodeDetails/vtoolpin.h @@ -0,0 +1,68 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 31 1, 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 + ** 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 VTOOLPIN_H +#define VTOOLPIN_H + +#include + +#include "vabstractnode.h" + +class DialogTool; + +class VToolPin : public VAbstractNode +{ + Q_OBJECT +public: + static VToolPin* Create(DialogTool *dialog, VAbstractPattern *doc, VContainer *data); + static VToolPin *Create(quint32 _id, quint32 pointId, quint32 pieceId, VAbstractPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation, const QString &drawName = QString(), + const quint32 &idTool = 0); + + static const QString ToolType; + virtual QString getTagName() const Q_DECL_OVERRIDE; +public slots: + virtual void FullUpdateFromFile () Q_DECL_OVERRIDE {} + virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; + virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; +protected: + virtual void AddToFile() Q_DECL_OVERRIDE; + virtual void RefreshDataInFile() Q_DECL_OVERRIDE; + virtual void ShowNode() Q_DECL_OVERRIDE {} + virtual void HideNode() Q_DECL_OVERRIDE {} +private: + Q_DISABLE_COPY(VToolPin) + + quint32 m_pieceId; + + VToolPin(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 pointId, quint32 pieceId, + const Source &typeCreation, const QString &drawName = QString(), const quint32 &idTool = 0, + QObject *qoParent = nullptr); +}; + +#endif // VTOOLPIN_H diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index 2b755c117..c0f55911e 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -58,7 +58,8 @@ HEADERS += \ $$PWD/drawTools/toolcurve/vtoolellipticalarc.h \ $$PWD/nodeDetails/vnodeellipticalarc.h \ $$PWD/vtoolseamallowance.h \ - $$PWD/nodeDetails/vtoolpiecepath.h + $$PWD/nodeDetails/vtoolpiecepath.h \ + $$PWD/nodeDetails/vtoolpin.h SOURCES += \ $$PWD/vdatatool.cpp \ @@ -114,4 +115,5 @@ SOURCES += \ $$PWD/drawTools/toolcurve/vtoolellipticalarc.cpp \ $$PWD/nodeDetails/vnodeellipticalarc.cpp \ $$PWD/vtoolseamallowance.cpp \ - $$PWD/nodeDetails/vtoolpiecepath.cpp + $$PWD/nodeDetails/vtoolpiecepath.cpp \ + $$PWD/nodeDetails/vtoolpin.cpp diff --git a/src/libs/vtools/tools/vabstracttool.cpp b/src/libs/vtools/tools/vabstracttool.cpp index 7cd873b5f..84fe7c4d1 100644 --- a/src/libs/vtools/tools/vabstracttool.cpp +++ b/src/libs/vtools/tools/vabstracttool.cpp @@ -87,32 +87,16 @@ const QString VAbstractTool::AttrInUse = QStringLiteral("inUse"); namespace { -//--------------------------------------------------------------------------------------------------------------------- -template -/** - * @brief CreateNode create new node for detail. - * @param data container. - * @param id id parent object. - * @return id for new object. - */ -quint32 CreateNode(VContainer *data, quint32 id) -{ - //We can't use exist object. Need create new. - T *node = new T(*data->GeometricObject(id).data()); - node->setMode(Draw::Modeling); - return data->AddGObject(node); -} - //--------------------------------------------------------------------------------------------------------------------- quint32 CreateNodeSpline(VContainer *data, quint32 id) { if (data->GetGObject(id)->getType() == GOType::Spline) { - return CreateNode(data, id); + return VAbstractTool::CreateNode(data, id); } else { - return CreateNode(data, id); + return VAbstractTool::CreateNode(data, id); } } @@ -121,11 +105,11 @@ quint32 CreateNodeSplinePath(VContainer *data, quint32 id) { if (data->GetGObject(id)->getType() == GOType::SplinePath) { - return CreateNode(data, id); + return VAbstractTool::CreateNode(data, id); } else { - return CreateNode(data, id); + return VAbstractTool::CreateNode(data, id); } } }//static functions diff --git a/src/libs/vtools/tools/vabstracttool.h b/src/libs/vtools/tools/vabstracttool.h index e4bec6a15..d0f66f166 100644 --- a/src/libs/vtools/tools/vabstracttool.h +++ b/src/libs/vtools/tools/vabstracttool.h @@ -92,6 +92,9 @@ public: QMap PointsList() const; virtual QString getTagName() const =0; virtual void ShowVisualization(bool show) =0; + + template + static quint32 CreateNode(VContainer *data, quint32 id); public slots: /** * @brief FullUpdateFromFile update tool data form file. @@ -197,4 +200,20 @@ inline void VAbstractTool::AddVisualization() vis = visual; } +//--------------------------------------------------------------------------------------------------------------------- +template +/** + * @brief CreateNode create new node for detail. + * @param data container. + * @param id id parent object. + * @return id for new object. + */ +quint32 VAbstractTool::CreateNode(VContainer *data, quint32 id) +{ + //We can't use exist object. Need create new. + T *node = new T(*data->GeometricObject(id).data()); + node->setMode(Draw::Modeling); + return data->AddGObject(node); +} + #endif // VABSTRACTTOOL_H