2017-01-31 15:04:51 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @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");
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-04-15 16:39:59 +02:00
|
|
|
VToolPin *VToolPin::Create(QSharedPointer<DialogTool> dialog, VAbstractPattern *doc, VContainer *data)
|
2017-01-31 15:04:51 +01:00
|
|
|
{
|
2017-04-15 16:39:59 +02:00
|
|
|
SCASSERT(not dialog.isNull());
|
|
|
|
QSharedPointer<DialogPin> dialogTool = dialog.objectCast<DialogPin>();
|
|
|
|
SCASSERT(not dialogTool.isNull())
|
2017-01-31 15:04:51 +01:00
|
|
|
|
2017-09-18 10:37:23 +02:00
|
|
|
VToolPinInitData initData;
|
|
|
|
initData.pointId = dialogTool->GetPointId();
|
|
|
|
initData.idObject = dialogTool->GetPieceId();
|
|
|
|
initData.doc = doc;
|
|
|
|
initData.data = data;
|
|
|
|
initData.parse = Document::FullParse;
|
|
|
|
initData.typeCreation = Source::FromGui;
|
|
|
|
|
|
|
|
return Create(initData);
|
2017-01-31 15:04:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
VToolPin *VToolPin::Create(VToolPinInitData initData)
|
2017-01-31 15:04:51 +01:00
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
if (initData.typeCreation == Source::FromGui)
|
2017-01-31 15:04:51 +01:00
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
initData.id = CreateNode<VPointF>(initData.data, initData.pointId);
|
2017-01-31 15:04:51 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QSharedPointer<VPointF> point;
|
|
|
|
try
|
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
point = initData.data->GeometricObject<VPointF>(initData.pointId);
|
2017-01-31 15:04:51 +01:00
|
|
|
}
|
|
|
|
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);
|
2017-09-18 10:37:23 +02:00
|
|
|
initData.data->UpdateGObject(initData.id, pinPoint);
|
|
|
|
if (initData.parse != Document::FullParse)
|
2017-01-31 15:04:51 +01:00
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
initData.doc->UpdateToolData(initData.id, initData.data);
|
2017-01-31 15:04:51 +01:00
|
|
|
}
|
|
|
|
}
|
2017-09-18 10:37:23 +02:00
|
|
|
VAbstractTool::AddRecord(initData.id, Tool::Pin, initData.doc);
|
2017-01-31 15:04:51 +01:00
|
|
|
VToolPin *point = nullptr;
|
2017-09-18 10:37:23 +02:00
|
|
|
if (initData.parse == Document::FullParse)
|
2017-01-31 15:04:51 +01:00
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
point = new VToolPin(initData);
|
2017-01-31 15:04:51 +01:00
|
|
|
|
2017-09-18 10:37:23 +02:00
|
|
|
VAbstractPattern::AddTool(initData.id, point);
|
|
|
|
if (initData.idTool != NULL_ID)
|
2017-01-31 15:04:51 +01:00
|
|
|
{
|
|
|
|
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
|
2017-09-18 10:37:23 +02:00
|
|
|
VDataTool *tool = VAbstractPattern::getTool(initData.idTool);
|
2017-01-31 15:04:51 +01:00
|
|
|
SCASSERT(tool != nullptr)
|
|
|
|
point->setParent(tool);// Adopted by a tool
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Help to delete the node before each FullParse
|
2017-09-18 10:37:23 +02:00
|
|
|
initData.doc->AddToolOnRemove(point);
|
2017-01-31 15:04:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
initData.doc->UpdateToolData(initData.id, initData.data);
|
2017-01-31 15:04:51 +01:00
|
|
|
}
|
|
|
|
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());
|
|
|
|
|
2017-09-17 08:45:18 +02:00
|
|
|
doc->SetAttribute(domElement, VDomDocument::AttrId, m_id);
|
2017-01-31 15:04:51 +01:00
|
|
|
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)
|
|
|
|
{
|
2017-01-31 17:09:18 +01:00
|
|
|
const VPiece oldDet = VAbstractTool::data.GetPiece(m_pieceId);
|
|
|
|
VPiece newDet = oldDet;
|
2017-01-31 15:04:51 +01:00
|
|
|
|
2017-09-17 08:45:18 +02:00
|
|
|
newDet.GetPins().append(m_id);
|
2017-01-31 15:04:51 +01:00
|
|
|
|
2017-01-31 17:09:18 +01:00
|
|
|
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);
|
2017-01-31 15:04:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
VToolPin::VToolPin(const VToolPinInitData &initData, QObject *qoParent)
|
|
|
|
: VAbstractNode(initData.doc, initData.data, initData.id, initData.pointId, initData.drawName, initData.idTool,
|
|
|
|
qoParent),
|
|
|
|
m_pieceId(initData.idObject)
|
2017-01-31 15:04:51 +01:00
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
ToolCreation(initData.typeCreation);
|
2017-01-31 15:04:51 +01:00
|
|
|
}
|