valentina/tools/vtoolshoulderpoint.cpp

175 lines
7.6 KiB
C++
Raw Normal View History

2013-08-20 12:26:02 +02:00
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
2013-07-29 14:55:40 +02:00
#include "vtoolshoulderpoint.h"
#include <QDebug>
#include <QMenu>
2013-08-20 12:26:02 +02:00
#pragma GCC diagnostic pop
2013-07-29 14:55:40 +02:00
2013-08-28 10:55:11 +02:00
VToolShoulderPoint::VToolShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, Draw::Mode mode,
2013-07-29 14:55:40 +02:00
const QString &typeLine, const QString &formula, const qint64 &p1Line,
const qint64 &p2Line, const qint64 &pShoulder, Tool::Enum typeCreation,
2013-07-31 13:34:39 +02:00
QGraphicsItem * parent):
2013-08-28 10:55:11 +02:00
VToolLinePoint(doc, data, id, mode, typeLine, formula, p1Line, 0, parent), p2Line(p2Line), pShoulder(pShoulder),
2013-08-20 12:26:02 +02:00
dialogShoulderPoint(QSharedPointer<DialogShoulderPoint>()){
2013-07-29 14:55:40 +02:00
if(typeCreation == Tool::FromGui){
AddToFile();
}
}
void VToolShoulderPoint::setDialog(){
Q_ASSERT(!dialogShoulderPoint.isNull());
if(!dialogShoulderPoint.isNull()){
VPointF p = VAbstractTool::data.GetPoint(id);
dialogShoulderPoint->setTypeLine(typeLine);
dialogShoulderPoint->setFormula(formula);
dialogShoulderPoint->setP1Line(basePointId, id);
dialogShoulderPoint->setP2Line(p2Line, id);
dialogShoulderPoint->setPShoulder(pShoulder, id);
dialogShoulderPoint->setPointName(p.name());
}
}
2013-07-29 14:55:40 +02:00
QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder,
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();
}
}
}
void VToolShoulderPoint::Create(QSharedPointer<DialogShoulderPoint> &dialog, VMainGraphicsScene *scene,
2013-08-28 10:55:11 +02:00
VDomDocument *doc, VContainer *data, Draw::Mode mode){
QString formula = dialog->getFormula();
qint64 p1Line = dialog->getP1Line();
qint64 p2Line = dialog->getP2Line();
qint64 pShoulder = dialog->getPShoulder();
QString typeLine = dialog->getTypeLine();
QString pointName = dialog->getPointName();
Create(0, formula, p1Line, p2Line, pShoulder, typeLine, pointName, 5, 10, scene, doc, data,
2013-08-28 10:55:11 +02:00
Document::FullParse, Tool::FromGui, mode);
}
void VToolShoulderPoint::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,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
2013-08-28 10:55:11 +02:00
Document::Enum parse, Tool::Enum typeCreation, Draw::Mode mode){
VPointF firstPoint = data->GetPoint(p1Line);
VPointF secondPoint = data->GetPoint(p2Line);
VPointF shoulderPoint = data->GetPoint(pShoulder);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(),
shoulderPoint.toQPointF(), result*PrintDPI/25.4);
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
} else {
data->UpdatePoint(id,VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
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);
data->IncrementReferens(id, Scene::Point);
}
}
}
data->AddLine(p1Line, id);
data->AddLine(p2Line, id);
2013-08-15 22:39:00 +02:00
VAbstractTool::AddRecord(id, Tools::ShoulderPointTool, doc);
2013-08-28 10:55:11 +02:00
if(mode == Draw::Modeling){
data->IncrementReferens(p1Line, Scene::Point);
data->IncrementReferens(p2Line, Scene::Point);
data->IncrementReferens(pShoulder, Scene::Point);
}
if(parse == Document::FullParse){
2013-08-28 10:55:11 +02:00
VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, mode, typeLine, formula,
p1Line, p2Line, pShoulder,
typeCreation);
scene->addItem(point);
2013-08-20 12:26:02 +02:00
connect(point, &VToolShoulderPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
connect(point, &VToolShoulderPoint::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
QMap<qint64, VDataTool*>* tools = doc->getTools();
tools->insert(id,point);
}
}
}
2013-07-29 14:55:40 +02:00
void VToolShoulderPoint::FullUpdateFromFile(){
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
}
void VToolShoulderPoint::FullUpdateFromGui(int result){
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();
}
void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
ContextMenu(dialogShoulderPoint, this, event);
2013-07-29 14:55:40 +02:00
}
void VToolShoulderPoint::AddToFile(){
2013-08-28 10:55:11 +02:00
VPointF point;
if(mode == Draw::Calculation){
point = VAbstractTool::data.GetPoint(id);
} else {
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-08-28 10:55:11 +02:00
AddToDraw(domElement);
2013-07-29 14:55:40 +02:00
}