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"
|
|
|
|
|
2013-10-29 14:45:07 +01:00
|
|
|
const QString VToolHeight::ToolType = QStringLiteral("height");
|
|
|
|
|
2013-10-18 12:03:01 +02:00
|
|
|
VToolHeight::VToolHeight(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine,
|
|
|
|
const qint64 &basePointId, const qint64 &p1LineId, const qint64 &p2LineId,
|
2013-11-06 22:11:12 +01:00
|
|
|
const Tool::Sources &typeCreation, QGraphicsItem * parent)
|
2013-10-18 12:03:01 +02:00
|
|
|
:VToolLinePoint(doc, data, id, typeLine, QString(), basePointId, 0, parent),
|
2013-11-04 21:35:15 +01:00
|
|
|
dialogHeight(QSharedPointer<DialogHeight>()), p1LineId(p1LineId), p2LineId(p2LineId)
|
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
ignoreFullUpdate = true;
|
2013-11-04 21:35:15 +01:00
|
|
|
if (typeCreation == Tool::FromGui)
|
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
AddToFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolHeight::setDialog()
|
|
|
|
{
|
|
|
|
Q_ASSERT(dialogHeight.isNull() == false);
|
2013-10-18 12:03:01 +02:00
|
|
|
VPointF p = VAbstractTool::data.GetPoint(id);
|
|
|
|
dialogHeight->setTypeLine(typeLine);
|
|
|
|
dialogHeight->setBasePointId(basePointId, id);
|
|
|
|
dialogHeight->setP1LineId(p1LineId, id);
|
|
|
|
dialogHeight->setP2LineId(p2LineId, id);
|
|
|
|
dialogHeight->setPointName(p.name());
|
|
|
|
}
|
|
|
|
|
|
|
|
void VToolHeight::Create(QSharedPointer<DialogHeight> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
|
2013-11-04 21:35:15 +01:00
|
|
|
VContainer *data)
|
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
disconnect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &DialogHeight::UpdateList);
|
|
|
|
QString pointName = dialog->getPointName();
|
|
|
|
QString typeLine = dialog->getTypeLine();
|
|
|
|
qint64 basePointId = dialog->getBasePointId();
|
|
|
|
qint64 p1LineId = dialog->getP1LineId();
|
|
|
|
qint64 p2LineId = dialog->getP2LineId();
|
|
|
|
Create(0, pointName, typeLine, basePointId, p1LineId, p2LineId, 5, 10, scene, doc, data,
|
|
|
|
Document::FullParse, Tool::FromGui);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VToolHeight::Create(const qint64 _id, const QString &pointName, const QString &typeLine,
|
|
|
|
const qint64 &basePointId, const qint64 &p1LineId, const qint64 &p2LineId,
|
|
|
|
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc,
|
2013-11-06 22:11:12 +01:00
|
|
|
VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
VPointF basePoint = data->GetPoint(basePointId);
|
|
|
|
VPointF p1Line = data->GetPoint(p1LineId);
|
|
|
|
VPointF p2Line = data->GetPoint(p2LineId);
|
|
|
|
|
|
|
|
QPointF pHeight = FindPoint(QLineF(p1Line.toQPointF(), p2Line.toQPointF()), basePoint.toQPointF());
|
|
|
|
qint64 id = _id;
|
2013-11-04 21:35:15 +01:00
|
|
|
if (typeCreation == Tool::FromGui)
|
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
id = data->AddPoint(VPointF(pHeight.x(), pHeight.y(), pointName, mx, my));
|
|
|
|
data->AddLine(basePointId, id);
|
|
|
|
data->AddLine(p1LineId, id);
|
|
|
|
data->AddLine(p2LineId, id);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
data->UpdatePoint(id, VPointF(pHeight.x(), pHeight.y(), pointName, mx, my));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VDrawTool::AddRecord(id, Tool::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(point, &VToolPoint::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
|
|
|
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)
|
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
qreal a = 0, b = 0, c = 0;
|
|
|
|
LineCoefficients(line, &a, &b, &c);
|
|
|
|
qreal x = point.x() + a;
|
|
|
|
qreal y = b + point.y();
|
2013-11-04 21:35:15 +01:00
|
|
|
QLineF lin (point, QPointF(x, y));
|
2013-10-18 12:03:01 +02:00
|
|
|
QPointF p;
|
2013-11-04 21:35:15 +01:00
|
|
|
QLineF::IntersectType intersect = line.intersect(lin, &p);
|
|
|
|
if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection)
|
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
return p;
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
return QPointF();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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, "");
|
|
|
|
basePointId = domElement.attribute(AttrBasePoint, "").toLongLong();
|
|
|
|
p1LineId = domElement.attribute(AttrP1Line, "").toLongLong();
|
|
|
|
p2LineId = domElement.attribute(AttrP2Line, "").toLongLong();
|
2013-10-18 12:03:01 +02:00
|
|
|
}
|
|
|
|
RefreshGeometry();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolHeight::FullUpdateFromGui(int result)
|
|
|
|
{
|
|
|
|
if (result == QDialog::Accepted)
|
|
|
|
{
|
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
|
|
|
domElement.setAttribute(AttrName, dialogHeight->getPointName());
|
|
|
|
domElement.setAttribute(AttrTypeLine, dialogHeight->getTypeLine());
|
|
|
|
domElement.setAttribute(AttrBasePoint, QString().setNum(dialogHeight->getBasePointId()));
|
|
|
|
domElement.setAttribute(AttrP1Line, QString().setNum(dialogHeight->getP1LineId()));
|
|
|
|
domElement.setAttribute(AttrP2Line, QString().setNum(dialogHeight->getP2LineId()));
|
2013-10-18 12:03:01 +02:00
|
|
|
emit FullUpdateTree();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dialogHeight.clear();
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolHeight::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
ContextMenu(dialogHeight, this, event);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolHeight::AddToFile()
|
|
|
|
{
|
2013-10-18 12:03:01 +02:00
|
|
|
VPointF point = VAbstractTool::data.GetPoint(id);
|
2013-10-29 14:45:07 +01:00
|
|
|
QDomElement domElement = doc->createElement(TagName);
|
|
|
|
|
|
|
|
AddAttribute(domElement, AttrId, id);
|
|
|
|
AddAttribute(domElement, AttrType, ToolType);
|
|
|
|
AddAttribute(domElement, AttrName, point.name());
|
|
|
|
AddAttribute(domElement, AttrMx, toMM(point.mx()));
|
|
|
|
AddAttribute(domElement, AttrMy, toMM(point.my()));
|
|
|
|
|
|
|
|
AddAttribute(domElement, AttrTypeLine, typeLine);
|
|
|
|
AddAttribute(domElement, AttrBasePoint, basePointId);
|
|
|
|
AddAttribute(domElement, AttrP1Line, p1LineId);
|
|
|
|
AddAttribute(domElement, AttrP2Line, p2LineId);
|
2013-10-18 12:03:01 +02:00
|
|
|
|
|
|
|
AddToCalculation(domElement);
|
|
|
|
|
|
|
|
}
|