Added class VToolPin.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-01-31 16:04:51 +02:00
parent b9d635dab2
commit f2e88c71da
9 changed files with 299 additions and 29 deletions

View File

@ -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);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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)
{

View File

@ -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);

View File

@ -35,5 +35,6 @@
#include "vnodespline.h"
#include "vnodesplinepath.h"
#include "vtoolpiecepath.h"
#include "vtoolpin.h"
#endif // NODEDETAILS_H

View File

@ -0,0 +1,168 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <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 "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<DialogPin*>(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<VPointF>(data, pointId);
}
else
{
QSharedPointer<VPointF> point;
try
{
point = data->GeometricObject<VPointF>(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);
}

View File

@ -0,0 +1,68 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <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 VTOOLPIN_H
#define VTOOLPIN_H
#include <QtGlobal>
#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

View File

@ -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

View File

@ -87,32 +87,16 @@ const QString VAbstractTool::AttrInUse = QStringLiteral("inUse");
namespace
{
//---------------------------------------------------------------------------------------------------------------------
template<typename T>
/**
* @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<T>(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<VSpline>(data, id);
return VAbstractTool::CreateNode<VSpline>(data, id);
}
else
{
return CreateNode<VCubicBezier>(data, id);
return VAbstractTool::CreateNode<VCubicBezier>(data, id);
}
}
@ -121,11 +105,11 @@ quint32 CreateNodeSplinePath(VContainer *data, quint32 id)
{
if (data->GetGObject(id)->getType() == GOType::SplinePath)
{
return CreateNode<VSplinePath>(data, id);
return VAbstractTool::CreateNode<VSplinePath>(data, id);
}
else
{
return CreateNode<VCubicBezierPath>(data, id);
return VAbstractTool::CreateNode<VCubicBezierPath>(data, id);
}
}
}//static functions

View File

@ -92,6 +92,9 @@ public:
QMap<QString, quint32> PointsList() const;
virtual QString getTagName() const =0;
virtual void ShowVisualization(bool show) =0;
template<typename T>
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<typename T>
/**
* @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<T>(id).data());
node->setMode(Draw::Modeling);
return data->AddGObject(node);
}
#endif // VABSTRACTTOOL_H