2013-09-18 21:16:19 +02: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.
|
|
|
|
|
**
|
|
|
|
|
** Tox 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-09-10 14:29:06 +02:00
|
|
|
|
#include "vmodelingshoulderpoint.h"
|
2013-07-29 14:55:40 +02:00
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
|
VModelingShoulderPoint::VModelingShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id,
|
2013-07-29 14:55:40 +02:00
|
|
|
|
const QString &typeLine, const QString &formula, const qint64 &p1Line,
|
2013-09-29 12:58:45 +02:00
|
|
|
|
const qint64 &p2Line, const qint64 &pShoulder, Tool::Sources typeCreation,
|
2013-07-31 13:34:39 +02:00
|
|
|
|
QGraphicsItem * parent):
|
2013-09-10 14:29:06 +02:00
|
|
|
|
VModelingLinePoint(doc, data, id, typeLine, formula, p1Line, 0, parent), p2Line(p2Line),
|
|
|
|
|
pShoulder(pShoulder), dialogShoulderPoint(QSharedPointer<DialogShoulderPoint>()){
|
2013-07-29 14:55:40 +02:00
|
|
|
|
|
|
|
|
|
if(typeCreation == Tool::FromGui){
|
|
|
|
|
AddToFile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
|
void VModelingShoulderPoint::setDialog(){
|
2013-08-13 18:48:36 +02:00
|
|
|
|
Q_ASSERT(!dialogShoulderPoint.isNull());
|
|
|
|
|
if(!dialogShoulderPoint.isNull()){
|
2013-09-10 14:29:06 +02:00
|
|
|
|
VPointF p = VAbstractTool::data.GetModelingPoint(id);
|
2013-08-13 18:48:36 +02:00
|
|
|
|
dialogShoulderPoint->setTypeLine(typeLine);
|
|
|
|
|
dialogShoulderPoint->setFormula(formula);
|
|
|
|
|
dialogShoulderPoint->setP1Line(basePointId, id);
|
|
|
|
|
dialogShoulderPoint->setP2Line(p2Line, id);
|
|
|
|
|
dialogShoulderPoint->setPShoulder(pShoulder, id);
|
|
|
|
|
dialogShoulderPoint->setPointName(p.name());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
|
QPointF VModelingShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder,
|
2013-07-29 14:55:40 +02:00
|
|
|
|
const qreal &length){
|
|
|
|
|
QLineF line = QLineF(p1Line, p2Line);
|
|
|
|
|
qreal dist = line.length();
|
|
|
|
|
if(dist>length){
|
|
|
|
|
qDebug()<<"A3П2="<<length/PrintDPI*25.4<<"А30П ="<<dist/PrintDPI*25.4;
|
|
|
|
|
throw"Не можу знайти точку плеча. Довжина А3П2 < А3П.";
|
|
|
|
|
}
|
|
|
|
|
if(dist==length){
|
|
|
|
|
return line.p2();
|
|
|
|
|
}
|
|
|
|
|
qreal step = 0.01;
|
|
|
|
|
while(1){
|
|
|
|
|
line.setLength(line.length()+step);
|
|
|
|
|
QLineF line2 = QLineF(pShoulder, line.p2());
|
|
|
|
|
if(line2.length()>=length){
|
|
|
|
|
return line.p2();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
|
VModelingShoulderPoint *VModelingShoulderPoint::Create(QSharedPointer<DialogShoulderPoint> &dialog,
|
|
|
|
|
VDomDocument *doc, VContainer *data){
|
2013-08-13 18:48:36 +02:00
|
|
|
|
QString formula = dialog->getFormula();
|
|
|
|
|
qint64 p1Line = dialog->getP1Line();
|
|
|
|
|
qint64 p2Line = dialog->getP2Line();
|
|
|
|
|
qint64 pShoulder = dialog->getPShoulder();
|
|
|
|
|
QString typeLine = dialog->getTypeLine();
|
|
|
|
|
QString pointName = dialog->getPointName();
|
2013-09-10 14:29:06 +02:00
|
|
|
|
return Create(0, formula, p1Line, p2Line, pShoulder, typeLine, pointName, 5, 10, doc, data,
|
|
|
|
|
Document::FullParse, Tool::FromGui);
|
2013-08-13 18:48:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
|
VModelingShoulderPoint *VModelingShoulderPoint::Create(const qint64 _id, const QString &formula,
|
|
|
|
|
const qint64 &p1Line, const qint64 &p2Line,
|
|
|
|
|
const qint64 &pShoulder, const QString &typeLine,
|
|
|
|
|
const QString &pointName, const qreal &mx,
|
|
|
|
|
const qreal &my, VDomDocument *doc, VContainer *data,
|
2013-09-29 12:58:45 +02:00
|
|
|
|
const Document::Documents &parse, Tool::Sources typeCreation){
|
2013-09-10 14:29:06 +02:00
|
|
|
|
VModelingShoulderPoint *point = 0;
|
|
|
|
|
VPointF firstPoint = data->GetModelingPoint(p1Line);
|
|
|
|
|
VPointF secondPoint = data->GetModelingPoint(p2Line);
|
|
|
|
|
VPointF shoulderPoint = data->GetModelingPoint(pShoulder);
|
2013-08-13 18:48:36 +02:00
|
|
|
|
|
|
|
|
|
Calculator cal(data);
|
|
|
|
|
QString errorMsg;
|
|
|
|
|
qreal result = cal.eval(formula, &errorMsg);
|
|
|
|
|
if(errorMsg.isEmpty()){
|
2013-09-10 14:29:06 +02:00
|
|
|
|
QPointF fPoint = VModelingShoulderPoint::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(),
|
2013-08-13 18:48:36 +02:00
|
|
|
|
shoulderPoint.toQPointF(), result*PrintDPI/25.4);
|
|
|
|
|
qint64 id = _id;
|
|
|
|
|
if(typeCreation == Tool::FromGui){
|
2013-09-10 14:29:06 +02:00
|
|
|
|
id = data->AddModelingPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
2013-08-13 18:48:36 +02:00
|
|
|
|
} else {
|
2013-09-10 14:29:06 +02:00
|
|
|
|
data->UpdateModelingPoint(id,VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
2013-08-13 18:48:36 +02:00
|
|
|
|
if(parse != Document::FullParse){
|
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
|
VDataTool *tool = tools->value(id);
|
2013-08-28 10:55:11 +02:00
|
|
|
|
if(tool != 0){
|
|
|
|
|
tool->VDataTool::setData(data);
|
2013-09-10 14:29:06 +02:00
|
|
|
|
data->IncrementReferens(id, Scene::Point, Draw::Modeling);
|
2013-08-28 10:55:11 +02:00
|
|
|
|
}
|
2013-08-13 18:48:36 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-10 14:29:06 +02:00
|
|
|
|
data->AddLine(p1Line, id, Draw::Modeling);
|
|
|
|
|
data->AddLine(p2Line, id, Draw::Modeling);
|
|
|
|
|
data->IncrementReferens(p1Line, Scene::Point, Draw::Modeling);
|
|
|
|
|
data->IncrementReferens(p2Line, Scene::Point, Draw::Modeling);
|
|
|
|
|
data->IncrementReferens(pShoulder, Scene::Point, Draw::Modeling);
|
2013-08-13 18:48:36 +02:00
|
|
|
|
if(parse == Document::FullParse){
|
2013-09-10 14:29:06 +02:00
|
|
|
|
point = new VModelingShoulderPoint(doc, data, id, typeLine, formula, p1Line, p2Line, pShoulder,
|
|
|
|
|
typeCreation);
|
2013-08-13 18:48:36 +02:00
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
|
tools->insert(id,point);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-10 14:29:06 +02:00
|
|
|
|
return point;
|
2013-08-13 18:48:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
|
void VModelingShoulderPoint::FullUpdateFromFile(){
|
2013-07-29 14:55:40 +02:00
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
|
if(domElement.isElement()){
|
|
|
|
|
typeLine = domElement.attribute("typeLine", "");
|
|
|
|
|
formula = domElement.attribute("length", "");
|
2013-07-31 13:34:39 +02:00
|
|
|
|
basePointId = domElement.attribute("p1Line", "").toLongLong();
|
2013-07-29 14:55:40 +02:00
|
|
|
|
p2Line = domElement.attribute("p2Line", "").toLongLong();
|
|
|
|
|
pShoulder = domElement.attribute("pShoulder", "").toLongLong();
|
|
|
|
|
}
|
2013-07-31 13:34:39 +02:00
|
|
|
|
RefreshGeometry();
|
2013-07-29 14:55:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
|
void VModelingShoulderPoint::FullUpdateFromGui(int result){
|
2013-07-29 14:55:40 +02:00
|
|
|
|
if(result == QDialog::Accepted){
|
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
|
if(domElement.isElement()){
|
|
|
|
|
domElement.setAttribute("name", dialogShoulderPoint->getPointName());
|
|
|
|
|
domElement.setAttribute("typeLine", dialogShoulderPoint->getTypeLine());
|
|
|
|
|
domElement.setAttribute("length", dialogShoulderPoint->getFormula());
|
|
|
|
|
domElement.setAttribute("p1Line", QString().setNum(dialogShoulderPoint->getP1Line()));
|
|
|
|
|
domElement.setAttribute("p2Line", QString().setNum(dialogShoulderPoint->getP2Line()));
|
|
|
|
|
domElement.setAttribute("pShoulder", QString().setNum(dialogShoulderPoint->getPShoulder()));
|
|
|
|
|
emit FullUpdateTree();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dialogShoulderPoint.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
|
void VModelingShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
|
2013-08-13 18:48:36 +02:00
|
|
|
|
ContextMenu(dialogShoulderPoint, this, event);
|
2013-07-29 14:55:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
|
void VModelingShoulderPoint::AddToFile(){
|
|
|
|
|
VPointF point = VAbstractTool::data.GetModelingPoint(id);
|
2013-07-29 14:55:40 +02:00
|
|
|
|
QDomElement domElement = doc->createElement("point");
|
|
|
|
|
|
|
|
|
|
AddAttribute(domElement, "id", id);
|
|
|
|
|
AddAttribute(domElement, "type", "shoulder");
|
|
|
|
|
AddAttribute(domElement, "name", point.name());
|
|
|
|
|
AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4);
|
|
|
|
|
AddAttribute(domElement, "my", point.my()/PrintDPI*25.4);
|
|
|
|
|
|
|
|
|
|
AddAttribute(domElement, "typeLine", typeLine);
|
|
|
|
|
AddAttribute(domElement, "length", formula);
|
2013-07-31 13:34:39 +02:00
|
|
|
|
AddAttribute(domElement, "p1Line", basePointId);
|
2013-07-29 14:55:40 +02:00
|
|
|
|
AddAttribute(domElement, "p2Line", p2Line);
|
|
|
|
|
AddAttribute(domElement, "pShoulder", pShoulder);
|
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
|
AddToModeling(domElement);
|
2013-07-29 14:55:40 +02:00
|
|
|
|
}
|