2013-10-29 14:47:49 +01:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2013 Valentina project All Rights Reserved.
|
|
|
|
**
|
|
|
|
** This file is part of Valentina.
|
|
|
|
**
|
|
|
|
** Tox 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/>.
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-10-18 12:03:01 +02:00
|
|
|
#include "vmodelingheight.h"
|
2013-10-18 12:43:51 +02:00
|
|
|
#include "../drawTools/vtoolheight.h"
|
2013-10-18 12:03:01 +02:00
|
|
|
|
2013-10-29 14:45:07 +01:00
|
|
|
const QString VModelingHeight::ToolType = QStringLiteral("height");
|
|
|
|
|
2013-10-18 12:03:01 +02:00
|
|
|
VModelingHeight::VModelingHeight(VDomDocument *doc, VContainer *data, const qint64 &id,
|
|
|
|
const QString &typeLine, const qint64 &basePointId, const qint64 &p1LineId,
|
|
|
|
const qint64 &p2LineId, Tool::Sources typeCreation,
|
|
|
|
QGraphicsItem * parent)
|
|
|
|
:VModelingLinePoint(doc, data, id, typeLine, QString(), basePointId, 0, parent),
|
|
|
|
dialogHeight(QSharedPointer<DialogHeight>()), p1LineId(p1LineId), p2LineId(p2LineId){
|
|
|
|
ignoreFullUpdate = true;
|
|
|
|
if(typeCreation == Tool::FromGui){
|
|
|
|
AddToFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VModelingHeight::setDialog(){
|
|
|
|
Q_ASSERT(!dialogHeight.isNull());
|
|
|
|
VPointF p = VAbstractTool::data.GetModelingPoint(id);
|
|
|
|
dialogHeight->setTypeLine(typeLine);
|
|
|
|
dialogHeight->setBasePointId(basePointId, id);
|
|
|
|
dialogHeight->setP1LineId(p1LineId, id);
|
|
|
|
dialogHeight->setP2LineId(p2LineId, id);
|
|
|
|
dialogHeight->setPointName(p.name());
|
|
|
|
}
|
|
|
|
|
|
|
|
VModelingHeight *VModelingHeight::Create(QSharedPointer<DialogHeight> &dialog, VDomDocument *doc,
|
|
|
|
VContainer *data){
|
|
|
|
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();
|
|
|
|
return Create(0, pointName, typeLine, basePointId, p1LineId, p2LineId, 5, 10, doc, data,
|
|
|
|
Document::FullParse, Tool::FromGui);
|
|
|
|
}
|
|
|
|
|
|
|
|
VModelingHeight *VModelingHeight::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,
|
|
|
|
VDomDocument *doc, VContainer *data,
|
|
|
|
const Document::Documents &parse, Tool::Sources typeCreation){
|
|
|
|
VModelingHeight *point = 0;
|
|
|
|
VPointF basePoint = data->GetModelingPoint(basePointId);
|
|
|
|
VPointF p1Line = data->GetModelingPoint(p1LineId);
|
|
|
|
VPointF p2Line = data->GetModelingPoint(p2LineId);
|
|
|
|
|
2013-10-18 12:43:51 +02:00
|
|
|
QPointF pHeight = VToolHeight::FindPoint(QLineF(p1Line.toQPointF(), p2Line.toQPointF()),
|
|
|
|
basePoint.toQPointF());
|
2013-10-18 12:03:01 +02:00
|
|
|
QLineF line = QLineF(basePoint.toQPointF(), pHeight);
|
|
|
|
qint64 id = _id;
|
|
|
|
if(typeCreation == Tool::FromGui){
|
|
|
|
id = data->AddModelingPoint(VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
|
|
|
|
} else {
|
|
|
|
data->UpdateModelingPoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
|
|
|
|
if(parse != Document::FullParse){
|
|
|
|
doc->UpdateToolData(id, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data->AddLine(basePointId, id, Draw::Modeling);
|
|
|
|
if(parse == Document::FullParse){
|
|
|
|
point = new VModelingHeight(doc, data, id, typeLine, basePointId, p1LineId, p2LineId, typeCreation);
|
|
|
|
doc->AddTool(id, point);
|
|
|
|
doc->IncrementReferens(basePointId);
|
|
|
|
doc->IncrementReferens(p1LineId);
|
|
|
|
doc->IncrementReferens(p2LineId);
|
|
|
|
}
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VModelingHeight::FullUpdateFromFile(){
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VModelingHeight::FullUpdateFromGui(int result){
|
|
|
|
if(result == QDialog::Accepted){
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VModelingHeight::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
|
|
|
|
ContextMenu(dialogHeight, this, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VModelingHeight::AddToFile(){
|
|
|
|
VPointF point = VAbstractTool::data.GetModelingPoint(id);
|
2013-10-29 14:45:07 +01:00
|
|
|
QDomElement domElement = doc->createElement(TagName);
|
2013-10-18 12:03:01 +02:00
|
|
|
|
2013-10-29 14:45:07 +01:00
|
|
|
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()));
|
2013-10-18 12:03:01 +02:00
|
|
|
|
2013-10-29 14:45:07 +01:00
|
|
|
AddAttribute(domElement, AttrTypeLine, typeLine);
|
|
|
|
AddAttribute(domElement, AttrBasePoint, basePointId);
|
|
|
|
AddAttribute(domElement, AttrP1Line, p1LineId);
|
|
|
|
AddAttribute(domElement, AttrP2Line, p2LineId);
|
2013-10-18 12:03:01 +02:00
|
|
|
|
|
|
|
AddToModeling(domElement);
|
|
|
|
}
|