2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vtooldetail.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @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) 2013 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-08-28 10:55:11 +02:00
|
|
|
#include "vtooldetail.h"
|
2013-09-10 14:29:06 +02:00
|
|
|
#include "nodeDetails/nodedetails.h"
|
2014-06-08 20:10:57 +02:00
|
|
|
#include "../geometry/varc.h"
|
|
|
|
#include "../geometry/vsplinepath.h"
|
2014-01-28 19:53:35 +01:00
|
|
|
#include "../geometry/vequidistant.h"
|
2014-06-08 20:10:57 +02:00
|
|
|
#include "../widgets/vmaingraphicsscene.h"
|
|
|
|
#include "../dialogs/tools/dialogtool.h"
|
|
|
|
#include "../dialogs/tools/dialogdetail.h"
|
2014-04-17 19:18:26 +02:00
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#include <QMenu>
|
2014-06-03 14:15:17 +02:00
|
|
|
#include <QGraphicsView>
|
2014-06-16 14:14:46 +02:00
|
|
|
#include <QMessageBox>
|
2014-06-12 15:38:28 +02:00
|
|
|
#include "../undocommands/savedetailoptions.h"
|
2014-06-13 12:29:23 +02:00
|
|
|
#include "../undocommands/movedetail.h"
|
2014-06-15 19:07:54 +02:00
|
|
|
#include "../undocommands/adddet.h"
|
2014-06-16 14:14:46 +02:00
|
|
|
#include "../undocommands/deletedetail.h"
|
2013-08-28 10:55:11 +02:00
|
|
|
|
2013-10-29 18:46:58 +01:00
|
|
|
const QString VToolDetail::TagName = QStringLiteral("detail");
|
|
|
|
const QString VToolDetail::TagNode = QStringLiteral("node");
|
2014-02-25 19:03:17 +01:00
|
|
|
|
2013-10-29 18:46:58 +01:00
|
|
|
const QString VToolDetail::AttrSupplement = QStringLiteral("supplement");
|
|
|
|
const QString VToolDetail::AttrClosed = QStringLiteral("closed");
|
|
|
|
const QString VToolDetail::AttrWidth = QStringLiteral("width");
|
|
|
|
const QString VToolDetail::AttrIdObject = QStringLiteral("idObject");
|
|
|
|
const QString VToolDetail::AttrNodeType = QStringLiteral("nodeType");
|
2014-02-25 19:03:17 +01:00
|
|
|
|
2013-10-29 18:46:58 +01:00
|
|
|
const QString VToolDetail::NodeTypeContour = QStringLiteral("Contour");
|
2013-10-29 14:45:07 +01:00
|
|
|
const QString VToolDetail::NodeTypeModeling = QStringLiteral("Modeling");
|
|
|
|
|
2014-04-17 19:18:26 +02:00
|
|
|
const QString VToolDetail::NodeArc = QStringLiteral("NodeArc");
|
|
|
|
const QString VToolDetail::NodePoint = QStringLiteral("NodePoint");
|
|
|
|
const QString VToolDetail::NodeSpline = QStringLiteral("NodeSpline");
|
|
|
|
const QString VToolDetail::NodeSplinePath = QStringLiteral("NodeSplinePath");
|
2014-02-25 19:03:17 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief VToolDetail constructor.
|
|
|
|
* @param doc dom document container
|
|
|
|
* @param data container with variables
|
|
|
|
* @param id object id in container
|
|
|
|
* @param typeCreation way we create this tool.
|
|
|
|
* @param scene pointer to scene.
|
|
|
|
* @param parent parent object
|
|
|
|
*/
|
2014-06-12 09:22:29 +02:00
|
|
|
VToolDetail::VToolDetail(VPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation,
|
2013-11-04 21:35:15 +01:00
|
|
|
VMainGraphicsScene *scene, QGraphicsItem *parent)
|
2014-02-26 10:22:05 +01:00
|
|
|
:VAbstractTool(doc, data, id), QGraphicsPathItem(parent), dialog(nullptr), sceneDetails(scene)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-30 19:59:33 +01:00
|
|
|
VDetail detail = data->GetDetail(id);
|
2013-11-07 15:40:39 +01:00
|
|
|
for (ptrdiff_t i = 0; i< detail.CountNode(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-09 21:11:33 +02:00
|
|
|
switch (detail.at(i).getTypeTool())
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodePoint):
|
2014-06-09 21:11:33 +02:00
|
|
|
InitTool<VNodePoint>(scene, detail.at(i));
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeArc):
|
2014-06-09 21:11:33 +02:00
|
|
|
InitTool<VNodeArc>(scene, detail.at(i));
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSpline):
|
2014-06-09 21:11:33 +02:00
|
|
|
InitTool<VNodeSpline>(scene, detail.at(i));
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSplinePath):
|
2014-06-09 21:11:33 +02:00
|
|
|
InitTool<VNodeSplinePath>(scene, detail.at(i));
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::ArrowTool):
|
|
|
|
case (Tool::SinglePointTool):
|
|
|
|
case (Tool::EndLineTool):
|
|
|
|
case (Tool::LineTool):
|
|
|
|
case (Tool::AlongLineTool):
|
|
|
|
case (Tool::ShoulderPointTool):
|
|
|
|
case (Tool::NormalTool):
|
|
|
|
case (Tool::BisectorTool):
|
|
|
|
case (Tool::LineIntersectTool):
|
|
|
|
case (Tool::SplineTool):
|
|
|
|
case (Tool::CutSplineTool):
|
|
|
|
case (Tool::CutArcTool):
|
|
|
|
case (Tool::ArcTool):
|
|
|
|
case (Tool::SplinePathTool):
|
|
|
|
case (Tool::CutSplinePathTool):
|
|
|
|
case (Tool::PointOfContact):
|
|
|
|
case (Tool::DetailTool):
|
|
|
|
case (Tool::Height):
|
|
|
|
case (Tool::Triangle):
|
|
|
|
case (Tool::PointOfIntersection):
|
|
|
|
case (Tool::UnionDetails):
|
2013-11-04 21:35:15 +01:00
|
|
|
default:
|
2014-03-28 14:11:46 +01:00
|
|
|
qDebug()<<"Get wrong tool type. Ignore.";
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2013-09-10 14:29:06 +02:00
|
|
|
}
|
2014-06-09 21:11:33 +02:00
|
|
|
doc->IncrementReferens(detail.at(i).getId());
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
|
|
RefreshGeometry();
|
|
|
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
2014-01-03 16:13:43 +01:00
|
|
|
this->setFlag(QGraphicsItem::ItemIsFocusable, true);
|
2014-06-12 09:22:29 +02:00
|
|
|
if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-15 19:07:54 +02:00
|
|
|
AddToFile();
|
|
|
|
if (typeCreation != Source::FromTool)
|
|
|
|
{
|
|
|
|
qApp->getUndoStack()->endMacro();
|
|
|
|
}
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-06 14:57:23 +01:00
|
|
|
VToolDetail::~VToolDetail()
|
|
|
|
{
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief setDialog set dialog when user want change tool option.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolDetail::setDialog()
|
|
|
|
{
|
2014-06-03 14:15:17 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
DialogDetail *dialogTool = qobject_cast<DialogDetail*>(dialog);
|
2014-06-03 14:15:17 +02:00
|
|
|
SCASSERT(dialogTool != nullptr);
|
2014-01-02 16:50:01 +01:00
|
|
|
VDetail detail = VAbstractTool::data.GetDetail(id);
|
2014-02-06 14:57:23 +01:00
|
|
|
dialogTool->setDetails(detail);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief Create help create tool from GUI.
|
|
|
|
* @param dialog dialog.
|
|
|
|
* @param scene pointer to scene.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
void VToolDetail::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-03 14:15:17 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
DialogDetail *dialogTool = qobject_cast<DialogDetail*>(dialog);
|
2014-06-03 14:15:17 +02:00
|
|
|
SCASSERT(dialogTool != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
VDetail detail = dialogTool->getDetails();
|
2013-12-30 19:59:33 +01:00
|
|
|
VDetail det;
|
2014-06-15 19:07:54 +02:00
|
|
|
qApp->getUndoStack()->beginMacro("add detail");
|
2013-11-07 15:40:39 +01:00
|
|
|
for (ptrdiff_t i = 0; i< detail.CountNode(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 id = 0;
|
2014-06-09 21:11:33 +02:00
|
|
|
switch (detail.at(i).getTypeTool())
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodePoint):
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-09 21:11:33 +02:00
|
|
|
id = CreateNode<VPointF>(data, detail.at(i).getId());
|
2014-06-12 09:22:29 +02:00
|
|
|
VNodePoint::Create(doc, data, id, detail.at(i).getId(), Document::FullParse, Source::FromGui);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeArc):
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-09 21:11:33 +02:00
|
|
|
id = CreateNode<VArc>(data, detail.at(i).getId());
|
2014-06-12 09:22:29 +02:00
|
|
|
VNodeArc::Create(doc, data, id, detail.at(i).getId(), Document::FullParse, Source::FromGui);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSpline):
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-09 21:11:33 +02:00
|
|
|
id = CreateNode<VSpline>(data, detail.at(i).getId());
|
2014-06-12 09:22:29 +02:00
|
|
|
VNodeSpline::Create(doc, data, id, detail.at(i).getId(), Document::FullParse, Source::FromGui);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSplinePath):
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-09 21:11:33 +02:00
|
|
|
id = CreateNode<VSplinePath>(data, detail.at(i).getId());
|
2014-06-12 09:22:29 +02:00
|
|
|
VNodeSplinePath::Create(doc, data, id, detail.at(i).getId(), Document::FullParse, Source::FromGui);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::ArrowTool):
|
|
|
|
case (Tool::SinglePointTool):
|
|
|
|
case (Tool::EndLineTool):
|
|
|
|
case (Tool::LineTool):
|
|
|
|
case (Tool::AlongLineTool):
|
|
|
|
case (Tool::ShoulderPointTool):
|
|
|
|
case (Tool::NormalTool):
|
|
|
|
case (Tool::BisectorTool):
|
|
|
|
case (Tool::LineIntersectTool):
|
|
|
|
case (Tool::SplineTool):
|
|
|
|
case (Tool::CutSplineTool):
|
|
|
|
case (Tool::CutArcTool):
|
|
|
|
case (Tool::ArcTool):
|
|
|
|
case (Tool::SplinePathTool):
|
|
|
|
case (Tool::CutSplinePathTool):
|
|
|
|
case (Tool::PointOfContact):
|
|
|
|
case (Tool::DetailTool):
|
|
|
|
case (Tool::Height):
|
|
|
|
case (Tool::Triangle):
|
|
|
|
case (Tool::PointOfIntersection):
|
|
|
|
case (Tool::UnionDetails):
|
2013-11-04 21:35:15 +01:00
|
|
|
default:
|
2014-03-28 14:11:46 +01:00
|
|
|
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
2014-06-09 21:11:33 +02:00
|
|
|
VNodeDetail node(id, detail.at(i).getTypeTool(), NodeDetail::Contour);
|
2013-12-30 19:59:33 +01:00
|
|
|
det.append(node);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
2013-12-30 19:59:33 +01:00
|
|
|
det.setName(detail.getName());
|
2014-06-15 19:07:54 +02:00
|
|
|
det.setWidth(detail.getWidth());
|
2014-06-12 09:22:29 +02:00
|
|
|
Create(0, det, scene, doc, data, Document::FullParse, Source::FromGui);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief Create help create tool.
|
|
|
|
* @param _id tool id, 0 if tool doesn't exist yet.
|
|
|
|
* @param newDetail detail what we want show.
|
|
|
|
* @param scene pointer to scene.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
* @param typeCreation way we create this tool.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void VToolDetail::Create(const quint32 &_id, const VDetail &newDetail, VMainGraphicsScene *scene, VPattern *doc,
|
2014-06-12 09:22:29 +02:00
|
|
|
VContainer *data, const Document &parse, const Source &typeCreation)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 id = _id;
|
2014-06-12 09:22:29 +02:00
|
|
|
if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-28 10:55:11 +02:00
|
|
|
id = data->AddDetail(newDetail);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-28 10:55:11 +02:00
|
|
|
data->UpdateDetail(id, newDetail);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (parse != Document::FullParse)
|
|
|
|
{
|
2013-09-30 18:29:03 +02:00
|
|
|
doc->UpdateToolData(id, data);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-12 09:22:29 +02:00
|
|
|
VAbstractTool::AddRecord(id, Tool::DetailTool, doc);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (parse == Document::FullParse)
|
|
|
|
{
|
2013-09-30 18:29:03 +02:00
|
|
|
VToolDetail *detail = new VToolDetail(doc, data, id, typeCreation, scene);
|
2013-08-28 10:55:11 +02:00
|
|
|
scene->addItem(detail);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(detail, &VToolDetail::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2014-02-25 15:40:24 +01:00
|
|
|
QHash<quint32, VDataTool*>* tools = doc->getTools();
|
2013-08-28 10:55:11 +02:00
|
|
|
tools->insert(id, detail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief Remove full delete detail.
|
|
|
|
*/
|
2014-06-15 19:07:54 +02:00
|
|
|
void VToolDetail::Remove(bool ask)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-06-16 14:14:46 +02:00
|
|
|
DeleteTool(ask);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief FullUpdateFromFile update tool data form file.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolDetail::FullUpdateFromFile()
|
|
|
|
{
|
2013-08-28 10:55:11 +02:00
|
|
|
RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief FullUpdateFromGuiOk refresh tool data after change in options.
|
|
|
|
* @param result keep result working dialog.
|
|
|
|
*/
|
2014-06-11 18:38:09 +02:00
|
|
|
void VToolDetail::FullUpdateFromGuiOk(int result)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
|
|
|
if (result == QDialog::Accepted)
|
|
|
|
{
|
2014-06-12 15:38:28 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
|
|
|
DialogDetail *dialogTool = qobject_cast<DialogDetail*>(dialog);
|
|
|
|
SCASSERT(dialogTool != nullptr);
|
|
|
|
VDetail newDet = dialogTool->getDetails();
|
|
|
|
VDetail oldDet = VAbstractTool::data.GetDetail(id);
|
|
|
|
|
|
|
|
SaveDetailOptions *saveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene());
|
|
|
|
connect(saveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(saveCommand);
|
2013-10-25 13:10:45 +02:00
|
|
|
}
|
2014-02-06 14:57:23 +01:00
|
|
|
delete dialog;
|
2014-06-12 09:22:29 +02:00
|
|
|
dialog = nullptr;
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief AddToFile add tag with informations about tool into file.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolDetail::AddToFile()
|
|
|
|
{
|
2013-12-30 19:59:33 +01:00
|
|
|
VDetail detail = VAbstractTool::data.GetDetail(id);
|
2013-10-29 14:45:07 +01:00
|
|
|
QDomElement domElement = doc->createElement(TagName);
|
2013-08-28 10:55:11 +02:00
|
|
|
|
2014-03-21 11:08:29 +01:00
|
|
|
doc->SetAttribute(domElement, VDomDocument::AttrId, id);
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrName, detail.getName());
|
2014-03-19 19:27:11 +01:00
|
|
|
doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(detail.getMx()));
|
|
|
|
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(detail.getMy()));
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrSupplement, detail.getSeamAllowance());
|
|
|
|
doc->SetAttribute(domElement, AttrClosed, detail.getClosed());
|
|
|
|
doc->SetAttribute(domElement, AttrWidth, detail.getWidth());
|
2013-08-28 10:55:11 +02:00
|
|
|
|
2013-12-30 19:59:33 +01:00
|
|
|
for (ptrdiff_t i = 0; i < detail.CountNode(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-12 15:38:28 +02:00
|
|
|
AddNode(doc, domElement, detail.at(i));
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-06-15 19:07:54 +02:00
|
|
|
AddDet *addDet = new AddDet(domElement, doc);
|
|
|
|
connect(addDet, &AddDet::NeedFullParsing, doc, &VPattern::NeedFullParsing);
|
|
|
|
qApp->getUndoStack()->push(addDet);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
|
|
|
|
*/
|
2013-12-24 12:24:29 +01:00
|
|
|
void VToolDetail::RefreshDataInFile()
|
|
|
|
{
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2013-12-30 19:59:33 +01:00
|
|
|
VDetail det = VAbstractTool::data.GetDetail(id);
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrName, det.getName());
|
|
|
|
doc->SetAttribute(domElement, AttrSupplement, QString().setNum(det.getSeamAllowance()));
|
|
|
|
doc->SetAttribute(domElement, AttrClosed, QString().setNum(det.getClosed()));
|
|
|
|
doc->SetAttribute(domElement, AttrWidth, QString().setNum(det.getWidth()));
|
2014-06-12 15:38:28 +02:00
|
|
|
doc->RemoveAllChild(domElement);
|
2013-12-30 19:59:33 +01:00
|
|
|
for (ptrdiff_t i = 0; i < det.CountNode(); ++i)
|
2013-12-24 12:24:29 +01:00
|
|
|
{
|
2014-06-12 15:38:28 +02:00
|
|
|
AddNode(doc, domElement, det.at(i));
|
2013-12-24 12:24:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief itemChange handle detail change.
|
|
|
|
* @param change change
|
|
|
|
* @param value value
|
|
|
|
* @return new value.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
|
|
|
{
|
|
|
|
if (change == ItemPositionHasChanged && scene())
|
|
|
|
{
|
2013-12-21 15:21:40 +01:00
|
|
|
// value - this is new position.
|
2013-08-28 10:55:11 +02:00
|
|
|
QPointF newPos = value.toPointF();
|
2014-01-12 20:23:44 +01:00
|
|
|
|
2014-06-13 12:29:23 +02:00
|
|
|
MoveDetail *moveDet = new MoveDetail(doc, newPos.x(), newPos.y(), id, this->scene());
|
|
|
|
connect(moveDet, &MoveDetail::NeedLiteParsing, doc, &VPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(moveDet);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
2014-01-03 16:13:43 +01:00
|
|
|
|
|
|
|
if (change == QGraphicsItem::ItemSelectedChange)
|
|
|
|
{
|
|
|
|
if (value == true)
|
|
|
|
{
|
|
|
|
// do stuff if selected
|
|
|
|
this->setFocus();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// do stuff if not selected
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 10:55:11 +02:00
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief keyReleaseEvent handle key release events.
|
|
|
|
* @param event key release event.
|
|
|
|
*/
|
2014-01-03 16:13:43 +01:00
|
|
|
void VToolDetail::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->key())
|
|
|
|
{
|
|
|
|
case Qt::Key_Delete:
|
2014-06-16 09:52:55 +02:00
|
|
|
DeleteTool(this);
|
2014-01-03 16:13:43 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
QGraphicsItem::keyReleaseEvent ( event );
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief mouseReleaseEvent handle mouse release events.
|
|
|
|
* @param event mouse release event.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolDetail::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
emit ChoosedTool(id, SceneObject::Detail);
|
2013-09-10 14:29:06 +02:00
|
|
|
}
|
|
|
|
QGraphicsItem::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief contextMenuEvent handle context menu events.
|
|
|
|
* @param event context menu event.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2013-09-30 18:29:03 +02:00
|
|
|
QMenu menu;
|
2013-10-25 13:10:45 +02:00
|
|
|
QAction *actionOption = menu.addAction(tr("Options"));
|
2013-09-30 18:29:03 +02:00
|
|
|
QAction *actionRemove = menu.addAction(tr("Delete"));
|
2013-11-04 21:35:15 +01:00
|
|
|
if (_referens > 1)
|
|
|
|
{
|
2013-09-30 18:29:03 +02:00
|
|
|
actionRemove->setEnabled(false);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-30 18:29:03 +02:00
|
|
|
actionRemove->setEnabled(true);
|
|
|
|
}
|
|
|
|
QAction *selectedAction = menu.exec(event->screenPos());
|
2013-11-04 21:35:15 +01:00
|
|
|
if (selectedAction == actionOption)
|
|
|
|
{
|
2014-02-06 14:57:23 +01:00
|
|
|
QGraphicsScene *scene = this->scene();
|
|
|
|
QList<QGraphicsView *> list = scene->views();
|
|
|
|
dialog = new DialogDetail(getData(), list.first());
|
2013-10-25 13:10:45 +02:00
|
|
|
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
|
2014-02-06 14:57:23 +01:00
|
|
|
dialog, &DialogTool::ChoosedObject);
|
2014-06-11 18:38:09 +02:00
|
|
|
connect(dialog, &DialogTool::DialogClosed, this, &VToolDetail::FullUpdateFromGuiOk);
|
2013-10-25 13:10:45 +02:00
|
|
|
setDialog();
|
2014-02-06 14:57:23 +01:00
|
|
|
dialog->show();
|
2013-10-25 13:10:45 +02:00
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
if (selectedAction == actionRemove)
|
|
|
|
{
|
2014-06-16 09:52:55 +02:00
|
|
|
DeleteTool(this);
|
2013-09-30 18:29:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief RemoveReferens decrement value of reference.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolDetail::RemoveReferens()
|
|
|
|
{
|
2013-12-30 19:59:33 +01:00
|
|
|
VDetail detail = VAbstractTool::data.GetDetail(id);
|
|
|
|
for (ptrdiff_t i = 0; i< detail.CountNode(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-30 19:59:33 +01:00
|
|
|
doc->DecrementReferens(detail.at(i).getId());
|
2013-09-30 18:29:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief AddNode add node to the file.
|
|
|
|
* @param dom document container
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
* @param node node of detail.
|
|
|
|
*/
|
2014-06-12 15:38:28 +02:00
|
|
|
void VToolDetail::AddNode(VPattern *doc, QDomElement &domElement, const VNodeDetail &node)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-10-29 14:45:07 +01:00
|
|
|
QDomElement nod = doc->createElement(TagNode);
|
2013-08-28 10:55:11 +02:00
|
|
|
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(nod, AttrIdObject, node.getId());
|
2014-03-19 19:27:11 +01:00
|
|
|
doc->SetAttribute(nod, AttrMx, qApp->fromPixel(node.getMx()));
|
|
|
|
doc->SetAttribute(nod, AttrMy, qApp->fromPixel(node.getMy()));
|
2013-11-04 21:35:15 +01:00
|
|
|
if (node.getTypeNode() == NodeDetail::Contour)
|
|
|
|
{
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(nod, AttrNodeType, NodeTypeContour);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(nod, AttrNodeType, NodeTypeModeling);
|
2013-09-10 14:29:06 +02:00
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
switch (node.getTypeTool())
|
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeArc):
|
2014-02-25 19:03:17 +01:00
|
|
|
doc->SetAttribute(nod, AttrType, NodeArc);
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodePoint):
|
2014-02-25 19:03:17 +01:00
|
|
|
doc->SetAttribute(nod, AttrType, NodePoint);
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSpline):
|
2014-02-25 19:03:17 +01:00
|
|
|
doc->SetAttribute(nod, AttrType, NodeSpline);
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSplinePath):
|
2014-02-25 19:03:17 +01:00
|
|
|
doc->SetAttribute(nod, AttrType, NodeSplinePath);
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::ArrowTool):
|
|
|
|
case (Tool::SinglePointTool):
|
|
|
|
case (Tool::EndLineTool):
|
|
|
|
case (Tool::LineTool):
|
|
|
|
case (Tool::AlongLineTool):
|
|
|
|
case (Tool::ShoulderPointTool):
|
|
|
|
case (Tool::NormalTool):
|
|
|
|
case (Tool::BisectorTool):
|
|
|
|
case (Tool::LineIntersectTool):
|
|
|
|
case (Tool::SplineTool):
|
|
|
|
case (Tool::CutSplineTool):
|
|
|
|
case (Tool::CutArcTool):
|
|
|
|
case (Tool::ArcTool):
|
|
|
|
case (Tool::SplinePathTool):
|
|
|
|
case (Tool::CutSplinePathTool):
|
|
|
|
case (Tool::PointOfContact):
|
|
|
|
case (Tool::DetailTool):
|
|
|
|
case (Tool::Height):
|
|
|
|
case (Tool::Triangle):
|
|
|
|
case (Tool::PointOfIntersection):
|
|
|
|
case (Tool::UnionDetails):
|
2013-11-04 21:35:15 +01:00
|
|
|
default:
|
2014-03-28 14:11:46 +01:00
|
|
|
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
domElement.appendChild(nod);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief RefreshGeometry refresh item on scene.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolDetail::RefreshGeometry()
|
|
|
|
{
|
2014-06-16 09:52:55 +02:00
|
|
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
|
2014-01-28 19:53:35 +01:00
|
|
|
QPainterPath path = VEquidistant().ContourPath(id, this->getData());
|
2013-08-28 10:55:11 +02:00
|
|
|
this->setPath(path);
|
2014-06-13 12:29:23 +02:00
|
|
|
|
|
|
|
VDetail detail = VAbstractTool::data.GetDetail(id);
|
|
|
|
this->setPos(detail.getMx(), detail.getMy());
|
|
|
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
2013-10-29 16:01:56 +01:00
|
|
|
|
2014-06-16 14:14:46 +02:00
|
|
|
void VToolDetail::DeleteTool(bool ask)
|
|
|
|
{
|
|
|
|
DeleteDetail *delDet = new DeleteDetail(doc, id);
|
|
|
|
if (ask)
|
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText(tr("Confirm the deletion."));
|
|
|
|
msgBox.setInformativeText(tr("Do you really want delete?"));
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
|
|
|
msgBox.setIcon(QMessageBox::Question);
|
|
|
|
if (msgBox.exec() == QMessageBox::Cancel)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*Ugly hack. If UnionDetails delete detail no need emit FullParsing */
|
|
|
|
connect(delDet, &DeleteDetail::NeedFullParsing, doc, &VPattern::NeedFullParsing);
|
|
|
|
}
|
|
|
|
qApp->getUndoStack()->push(delDet);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-10-29 16:01:56 +01:00
|
|
|
template <typename Tool>
|
2014-01-27 16:48:11 +01:00
|
|
|
//cppcheck-suppress unusedFunction
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolDetail::InitTool(VMainGraphicsScene *scene, const VNodeDetail &node)
|
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
QHash<quint32, VDataTool*>* tools = doc->getTools();
|
2014-06-03 14:15:17 +02:00
|
|
|
SCASSERT(tools != nullptr);
|
2013-10-29 16:01:56 +01:00
|
|
|
Tool *tool = qobject_cast<Tool*>(tools->value(node.getId()));
|
2014-06-03 14:15:17 +02:00
|
|
|
SCASSERT(tool != nullptr);
|
2013-10-29 16:01:56 +01:00
|
|
|
connect(tool, &Tool::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
}
|