2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-11-04 21:38:54 +01:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vtoolheight.cpp
|
2013-11-15 13:41:26 +01:00
|
|
|
** @author Roman Telezhinsky <dismine@gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-11-04 21:38:54 +01: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-11-04 21:38:54 +01:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-11-04 21:38:54 +01: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.
|
|
|
|
**
|
|
|
|
** 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/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-11-04 21:38:54 +01:00
|
|
|
|
2013-10-18 12:03:01 +02:00
|
|
|
#include "vtoolheight.h"
|
2014-02-21 14:04:39 +01:00
|
|
|
#include "../../dialogs/tools/dialogheight.h"
|
2013-10-18 12:03:01 +02:00
|
|
|
|
2013-10-29 14:45:07 +01:00
|
|
|
const QString VToolHeight::ToolType = QStringLiteral("height");
|
|
|
|
|
2014-02-25 15:40:24 +01:00
|
|
|
VToolHeight::VToolHeight(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine,
|
|
|
|
const quint32 &basePointId, const quint32 &p1LineId, const quint32 &p2LineId,
|
2014-03-11 12:43:24 +01:00
|
|
|
const Valentina::Sources &typeCreation, QGraphicsItem * parent)
|
2014-02-06 14:57:23 +01:00
|
|
|
:VToolLinePoint(doc, data, id, typeLine, QString(), basePointId, 0, parent), p1LineId(p1LineId), p2LineId(p2LineId)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
ignoreFullUpdate = true;
|
2014-03-11 12:43:24 +01:00
|
|
|
if (typeCreation == Valentina::FromGui)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
AddToFile();
|
|
|
|
}
|
2013-12-24 12:24:29 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
RefreshDataInFile();
|
|
|
|
}
|
2013-10-18 12:03:01 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolHeight::setDialog()
|
|
|
|
{
|
2014-02-06 14:57:23 +01:00
|
|
|
Q_CHECK_PTR(dialog);
|
|
|
|
DialogHeight *dialogTool = qobject_cast<DialogHeight*>(dialog);
|
|
|
|
Q_CHECK_PTR(dialogTool);
|
2013-12-29 17:48:57 +01:00
|
|
|
const VPointF *p = VAbstractTool::data.GeometricObject<const VPointF *>(id);
|
2014-02-06 14:57:23 +01:00
|
|
|
dialogTool->setTypeLine(typeLine);
|
|
|
|
dialogTool->setBasePointId(basePointId, id);
|
|
|
|
dialogTool->setP1LineId(p1LineId, id);
|
|
|
|
dialogTool->setP2LineId(p2LineId, id);
|
|
|
|
dialogTool->setPointName(p->name());
|
2013-10-18 12:03:01 +02:00
|
|
|
}
|
|
|
|
|
2014-02-25 15:02:09 +01:00
|
|
|
void VToolHeight::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc,
|
2013-11-04 21:35:15 +01:00
|
|
|
VContainer *data)
|
|
|
|
{
|
2014-02-06 14:57:23 +01:00
|
|
|
Q_CHECK_PTR(dialog);
|
|
|
|
DialogHeight *dialogTool = qobject_cast<DialogHeight*>(dialog);
|
|
|
|
Q_CHECK_PTR(dialogTool);
|
2014-02-25 15:02:09 +01:00
|
|
|
disconnect(doc, &VPattern::FullUpdateFromFile, dialogTool, &DialogHeight::UpdateList);
|
2014-02-06 14:57:23 +01:00
|
|
|
QString pointName = dialogTool->getPointName();
|
|
|
|
QString typeLine = dialogTool->getTypeLine();
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 basePointId = dialogTool->getBasePointId();
|
|
|
|
quint32 p1LineId = dialogTool->getP1LineId();
|
|
|
|
quint32 p2LineId = dialogTool->getP2LineId();
|
2013-10-18 12:03:01 +02:00
|
|
|
Create(0, pointName, typeLine, basePointId, p1LineId, p2LineId, 5, 10, scene, doc, data,
|
2014-03-11 12:43:24 +01:00
|
|
|
Document::FullParse, Valentina::FromGui);
|
2013-10-18 12:03:01 +02:00
|
|
|
}
|
|
|
|
|
2014-02-25 15:40:24 +01:00
|
|
|
void VToolHeight::Create(const quint32 _id, const QString &pointName, const QString &typeLine,
|
|
|
|
const quint32 &basePointId, const quint32 &p1LineId, const quint32 &p2LineId,
|
2014-02-25 15:02:09 +01:00
|
|
|
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc,
|
2014-03-11 12:43:24 +01:00
|
|
|
VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
const VPointF *basePoint = data->GeometricObject<const VPointF *>(basePointId);
|
|
|
|
const VPointF *p1Line = data->GeometricObject<const VPointF *>(p1LineId);
|
|
|
|
const VPointF *p2Line = data->GeometricObject<const VPointF *>(p2LineId);
|
2013-10-18 12:03:01 +02:00
|
|
|
|
2013-12-29 17:48:57 +01:00
|
|
|
QPointF pHeight = FindPoint(QLineF(p1Line->toQPointF(), p2Line->toQPointF()), basePoint->toQPointF());
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 id = _id;
|
2014-03-11 12:43:24 +01:00
|
|
|
if (typeCreation == Valentina::FromGui)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
id = data->AddGObject(new VPointF(pHeight.x(), pHeight.y(), pointName, mx, my));
|
2013-10-18 12:03:01 +02:00
|
|
|
data->AddLine(basePointId, id);
|
|
|
|
data->AddLine(p1LineId, id);
|
|
|
|
data->AddLine(p2LineId, id);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
data->UpdateGObject(id, new VPointF(pHeight.x(), pHeight.y(), pointName, mx, my));
|
2013-10-18 12:03:01 +02:00
|
|
|
data->AddLine(basePointId, id);
|
|
|
|
data->AddLine(p1LineId, id);
|
|
|
|
data->AddLine(p2LineId, id);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (parse != Document::FullParse)
|
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
doc->UpdateToolData(id, data);
|
|
|
|
}
|
|
|
|
}
|
2014-03-11 12:43:24 +01:00
|
|
|
VDrawTool::AddRecord(id, Valentina::Height, doc);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (parse == Document::FullParse)
|
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
VToolHeight *point = new VToolHeight(doc, data, id, typeLine, basePointId, p1LineId, p2LineId,
|
|
|
|
typeCreation);
|
|
|
|
scene->addItem(point);
|
|
|
|
connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor);
|
|
|
|
doc->AddTool(id, point);
|
|
|
|
doc->IncrementReferens(basePointId);
|
|
|
|
doc->IncrementReferens(p1LineId);
|
|
|
|
doc->IncrementReferens(p2LineId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
QPointF VToolHeight::FindPoint(const QLineF &line, const QPointF &point)
|
|
|
|
{
|
2014-01-29 10:18:26 +01:00
|
|
|
return VAbstractTool::ClosestPoint(line, point);
|
2013-10-18 12:03:01 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolHeight::FullUpdateFromFile()
|
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
2013-11-04 21:35:15 +01:00
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2013-10-29 14:45:07 +01:00
|
|
|
typeLine = domElement.attribute(AttrTypeLine, "");
|
2014-02-25 15:55:02 +01:00
|
|
|
basePointId = domElement.attribute(AttrBasePoint, "").toUInt();
|
|
|
|
p1LineId = domElement.attribute(AttrP1Line, "").toUInt();
|
|
|
|
p2LineId = domElement.attribute(AttrP2Line, "").toUInt();
|
2013-10-18 12:03:01 +02:00
|
|
|
}
|
|
|
|
RefreshGeometry();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-09 13:51:09 +01:00
|
|
|
void VToolHeight::ShowContextMenu(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2014-02-06 14:57:23 +01:00
|
|
|
ContextMenu<DialogHeight>(this, event);
|
2014-01-09 13:51:09 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolHeight::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2014-02-06 14:57:23 +01:00
|
|
|
ContextMenu<DialogHeight>(this, event);
|
2013-10-18 12:03:01 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolHeight::AddToFile()
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
|
2013-10-29 14:45:07 +01:00
|
|
|
QDomElement domElement = doc->createElement(TagName);
|
|
|
|
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrId, id);
|
|
|
|
doc->SetAttribute(domElement, AttrType, ToolType);
|
|
|
|
doc->SetAttribute(domElement, AttrName, point->name());
|
|
|
|
doc->SetAttribute(domElement, AttrMx, toMM(point->mx()));
|
|
|
|
doc->SetAttribute(domElement, AttrMy, toMM(point->my()));
|
2013-10-29 14:45:07 +01:00
|
|
|
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrTypeLine, typeLine);
|
|
|
|
doc->SetAttribute(domElement, AttrBasePoint, basePointId);
|
|
|
|
doc->SetAttribute(domElement, AttrP1Line, p1LineId);
|
|
|
|
doc->SetAttribute(domElement, AttrP2Line, p2LineId);
|
2013-10-18 12:03:01 +02:00
|
|
|
|
|
|
|
AddToCalculation(domElement);
|
|
|
|
|
|
|
|
}
|
2013-12-24 12:24:29 +01:00
|
|
|
|
|
|
|
void VToolHeight::RefreshDataInFile()
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
|
2013-12-24 12:24:29 +01:00
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrName, point->name());
|
|
|
|
doc->SetAttribute(domElement, AttrMx, toMM(point->mx()));
|
|
|
|
doc->SetAttribute(domElement, AttrMy, toMM(point->my()));
|
|
|
|
doc->SetAttribute(domElement, AttrTypeLine, typeLine);
|
|
|
|
doc->SetAttribute(domElement, AttrBasePoint, basePointId);
|
|
|
|
doc->SetAttribute(domElement, AttrP1Line, p1LineId);
|
|
|
|
doc->SetAttribute(domElement, AttrP2Line, p2LineId);
|
2013-12-24 12:24:29 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-06 14:57:23 +01:00
|
|
|
|
|
|
|
void VToolHeight::SaveDialog(QDomElement &domElement)
|
|
|
|
{
|
|
|
|
Q_CHECK_PTR(dialog);
|
|
|
|
DialogHeight *dialogTool = qobject_cast<DialogHeight*>(dialog);
|
|
|
|
Q_CHECK_PTR(dialogTool);
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrName, dialogTool->getPointName());
|
|
|
|
doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine());
|
|
|
|
doc->SetAttribute(domElement, AttrBasePoint, QString().setNum(dialogTool->getBasePointId()));
|
|
|
|
doc->SetAttribute(domElement, AttrP1Line, QString().setNum(dialogTool->getP1LineId()));
|
|
|
|
doc->SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->getP2LineId()));
|
2014-02-06 14:57:23 +01:00
|
|
|
}
|