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.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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-08-28 10:55:11 +02:00
|
|
|
#include "vtooldetail.h"
|
2013-09-10 14:29:06 +02:00
|
|
|
#include "nodeDetails/nodedetails.h"
|
|
|
|
#include "modelingTools/vmodelingtool.h"
|
|
|
|
#include "modelingTools/modelingtools.h"
|
2013-08-28 10:55:11 +02:00
|
|
|
|
2013-09-30 18:29:03 +02:00
|
|
|
VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, Tool::Sources typeCreation,
|
2013-08-28 10:55:11 +02:00
|
|
|
VMainGraphicsScene *scene, QGraphicsItem *parent)
|
2013-09-30 18:29:03 +02:00
|
|
|
:VAbstractTool(doc, data, id), QGraphicsPathItem(parent), dialogDetail(QSharedPointer<DialogDetail>()),
|
|
|
|
sceneDetails(scene){
|
2013-08-28 10:55:11 +02:00
|
|
|
VDetail detail = data->GetDetail(id);
|
2013-10-04 13:32:42 +02:00
|
|
|
QHash<qint64, VDataTool*>* tools = doc->getTools();
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(tools != 0);
|
2013-08-28 10:55:11 +02:00
|
|
|
for(qint32 i = 0; i< detail.CountNode(); ++i){
|
|
|
|
switch(detail[i].getTypeTool()){
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::NodePoint):{
|
2013-09-30 18:29:03 +02:00
|
|
|
VNodePoint *point = qobject_cast<VNodePoint*>(tools->value(detail[i].getId()));
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(point != 0);
|
2013-09-30 18:29:03 +02:00
|
|
|
connect(point, &VNodePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-08-28 10:55:11 +02:00
|
|
|
point->setParentItem(this);
|
2013-09-10 14:29:06 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::NodeArc):{
|
2013-09-30 18:29:03 +02:00
|
|
|
VNodeArc *arc = qobject_cast<VNodeArc*>(tools->value(detail[i].getId()));
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(arc != 0);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(arc, &VNodeArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
arc->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::NodeSpline):{
|
2013-09-30 18:29:03 +02:00
|
|
|
VNodeSpline *spl = qobject_cast<VNodeSpline*>(tools->value(detail[i].getId()));
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(spl != 0);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(spl, &VNodeSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-08-28 10:55:11 +02:00
|
|
|
spl->setParentItem(this);
|
2013-09-10 14:29:06 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::NodeSplinePath):{
|
2013-09-30 18:29:03 +02:00
|
|
|
VNodeSplinePath *splPath = qobject_cast<VNodeSplinePath*>(tools->value(detail[i].getId()));
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(splPath != 0);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(splPath, &VNodeSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-08-28 10:55:11 +02:00
|
|
|
splPath->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::AlongLineTool):{
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingAlongLine *tool = qobject_cast<VModelingAlongLine*>(tools->value(detail[i].getId()));
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(tool != 0);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(tool, &VModelingAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-09-30 18:29:03 +02:00
|
|
|
connect(tool, &VModelingAlongLine::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
2013-09-10 14:29:06 +02:00
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::ArcTool):{
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingArc *tool = qobject_cast<VModelingArc*>(tools->value(detail[i].getId()));
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(tool != 0);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(tool, &VModelingArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-09-30 18:29:03 +02:00
|
|
|
connect(tool, &VModelingArc::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
2013-09-10 14:29:06 +02:00
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::BisectorTool):{
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingBisector *tool = qobject_cast<VModelingBisector*>(tools->value(detail[i].getId()));
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(tool != 0);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(tool, &VModelingBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-09-30 18:29:03 +02:00
|
|
|
connect(tool, &VModelingBisector::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
2013-09-10 14:29:06 +02:00
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::EndLineTool):{
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingEndLine *tool = qobject_cast<VModelingEndLine*>(tools->value(detail[i].getId()));
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(tool != 0);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(tool, &VModelingEndLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-09-30 18:29:03 +02:00
|
|
|
connect(tool, &VModelingEndLine::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
2013-09-10 14:29:06 +02:00
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::LineIntersectTool):{
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingLineIntersect *tool = qobject_cast<VModelingLineIntersect*>(tools->value(detail[i].getId()));
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(tool != 0);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(tool, &VModelingLineIntersect::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-09-30 18:29:03 +02:00
|
|
|
connect(tool, &VModelingLineIntersect::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
2013-09-10 14:29:06 +02:00
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::LineTool):{
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingLine *tool = qobject_cast<VModelingLine*>(tools->value(detail[i].getId()));
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(tool != 0);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(tool, &VModelingLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-09-30 18:29:03 +02:00
|
|
|
connect(tool, &VModelingLine::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
2013-09-10 14:29:06 +02:00
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::NormalTool):{
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingNormal *tool = qobject_cast<VModelingNormal*>(tools->value(detail[i].getId()));
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(tool != 0);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(tool, &VModelingNormal::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-09-30 18:29:03 +02:00
|
|
|
connect(tool, &VModelingNormal::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
2013-09-10 14:29:06 +02:00
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::PointOfContact):{
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingPointOfContact *tool = qobject_cast<VModelingPointOfContact*>(tools->value(detail[i].getId()));
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(tool != 0);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(tool, &VModelingPointOfContact::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-09-30 18:29:03 +02:00
|
|
|
connect(tool, &VModelingPointOfContact::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
2013-09-10 14:29:06 +02:00
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::ShoulderPointTool):{
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingShoulderPoint *tool = qobject_cast<VModelingShoulderPoint*>(tools->value(detail[i].getId()));
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(tool != 0);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(tool, &VModelingShoulderPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-09-30 18:29:03 +02:00
|
|
|
connect(tool, &VModelingShoulderPoint::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
2013-09-10 14:29:06 +02:00
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::SplinePathTool):{
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingSplinePath *tool = qobject_cast<VModelingSplinePath*>(tools->value(detail[i].getId()));
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(tool != 0);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(tool, &VModelingSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-09-30 18:29:03 +02:00
|
|
|
connect(tool, &VModelingSplinePath::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
2013-09-10 14:29:06 +02:00
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::SplineTool):{
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingSpline *tool = qobject_cast<VModelingSpline*>(tools->value(detail[i].getId()));
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(tool != 0);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(tool, &VModelingSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-09-30 18:29:03 +02:00
|
|
|
connect(tool, &VModelingSpline::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
2013-09-10 14:29:06 +02:00
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-10-18 20:20:54 +02:00
|
|
|
case(Tool::Height):{
|
|
|
|
VModelingHeight *tool = qobject_cast<VModelingHeight*>(tools->value(detail[i].getId()));
|
|
|
|
Q_ASSERT(tool != 0);
|
|
|
|
connect(tool, &VModelingHeight::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
connect(tool, &VModelingHeight::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(Tool::Triangle):{
|
|
|
|
VModelingTriangle *tool = qobject_cast<VModelingTriangle*>(tools->value(detail[i].getId()));
|
|
|
|
Q_ASSERT(tool != 0);
|
|
|
|
connect(tool, &VModelingTriangle::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
connect(tool, &VModelingTriangle::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-10-22 15:09:49 +02:00
|
|
|
case(Tool::PointOfIntersection):{
|
|
|
|
VModelingPointOfIntersection *tool = qobject_cast<VModelingPointOfIntersection*>(tools->value(detail[i].getId()));
|
|
|
|
Q_ASSERT(tool != 0);
|
|
|
|
connect(tool, &VModelingPointOfIntersection::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
connect(tool, &VModelingPointOfIntersection::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-09-12 16:18:31 +02:00
|
|
|
default:
|
|
|
|
qWarning()<<"Get wrong tool type. Ignore.";
|
|
|
|
break;
|
2013-09-10 14:29:06 +02:00
|
|
|
}
|
2013-09-30 18:29:03 +02:00
|
|
|
doc->IncrementReferens(detail[i].getId());
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
|
|
RefreshGeometry();
|
|
|
|
this->setPos(detail.getMx(), detail.getMy());
|
|
|
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
|
|
|
if(typeCreation == Tool::FromGui){
|
|
|
|
AddToFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VToolDetail::setDialog(){
|
|
|
|
Q_ASSERT(!dialogDetail.isNull());
|
2013-10-25 13:10:45 +02:00
|
|
|
VDetail detail = VAbstractTool::data.GetDetail(id);
|
|
|
|
dialogDetail->setDetails(detail);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2013-09-11 16:14:21 +02:00
|
|
|
void VToolDetail::Create(QSharedPointer<DialogDetail> &dialog, VMainGraphicsScene *scene,
|
|
|
|
VDomDocument *doc, VContainer *data){
|
2013-08-28 10:55:11 +02:00
|
|
|
VDetail detail = dialog->getDetails();
|
|
|
|
VDetail det;
|
|
|
|
for(qint32 i = 0; i< detail.CountNode(); ++i){
|
|
|
|
qint64 id = 0;
|
|
|
|
switch(detail[i].getTypeTool()){
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::NodePoint):{
|
2013-08-28 10:55:11 +02:00
|
|
|
VPointF point;
|
|
|
|
if(detail[i].getMode() == Draw::Calculation){
|
|
|
|
point = data->GetPoint(detail[i].getId());
|
|
|
|
} else {
|
|
|
|
point = data->GetModelingPoint(detail[i].getId());
|
|
|
|
}
|
|
|
|
id = data->AddModelingPoint(point);
|
2013-10-09 18:24:28 +02:00
|
|
|
VNodePoint::Create(doc, data, id, detail[i].getId(), detail[i].getMode(),
|
|
|
|
Document::FullParse, Tool::FromGui);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::NodeArc):{
|
2013-08-28 10:55:11 +02:00
|
|
|
VArc arc;
|
|
|
|
if(detail[i].getMode() == Draw::Calculation){
|
|
|
|
arc = data->GetArc(detail[i].getId());
|
|
|
|
} else {
|
|
|
|
arc = data->GetModelingArc(detail[i].getId());
|
|
|
|
}
|
|
|
|
id = data->AddModelingArc(arc);
|
2013-10-09 18:24:28 +02:00
|
|
|
VNodeArc::Create(doc, data, id, detail[i].getId(), detail[i].getMode(),
|
|
|
|
Document::FullParse, Tool::FromGui);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::NodeSpline):{
|
2013-08-28 10:55:11 +02:00
|
|
|
VSpline spline;
|
|
|
|
if(detail[i].getMode() == Draw::Calculation){
|
|
|
|
spline = data->GetSpline(detail[i].getId());
|
|
|
|
} else {
|
|
|
|
spline = data->GetModelingSpline(detail[i].getId());
|
|
|
|
}
|
|
|
|
id = data->AddModelingSpline(spline);
|
2013-10-09 18:24:28 +02:00
|
|
|
VNodeSpline::Create(doc, data, id, detail[i].getId(), detail[i].getMode(),
|
|
|
|
Document::FullParse, Tool::FromGui);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::NodeSplinePath):{
|
2013-08-28 10:55:11 +02:00
|
|
|
VSplinePath splinePath;
|
|
|
|
if(detail[i].getMode() == Draw::Calculation){
|
|
|
|
splinePath = data->GetSplinePath(detail[i].getId());
|
|
|
|
} else {
|
|
|
|
splinePath = data->GetModelingSplinePath(detail[i].getId());
|
|
|
|
}
|
|
|
|
id = data->AddModelingSplinePath(splinePath);
|
2013-10-09 18:24:28 +02:00
|
|
|
VNodeSplinePath::Create(doc, data, id, detail[i].getId(), detail[i].getMode(),
|
|
|
|
Document::FullParse, Tool::FromGui);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
break;
|
2013-09-10 14:29:06 +02:00
|
|
|
default:
|
|
|
|
qWarning()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
|
2013-08-28 10:55:11 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-10-25 13:10:45 +02:00
|
|
|
VNodeDetail node(id, detail[i].getTypeTool(), Draw::Modeling, NodeDetail::Contour);
|
2013-08-28 10:55:11 +02:00
|
|
|
det.append(node);
|
|
|
|
}
|
|
|
|
det.setName(detail.getName());
|
2013-09-30 18:29:03 +02:00
|
|
|
Create(0, det, scene, doc, data, Document::FullParse, Tool::FromGui);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2013-09-30 18:29:03 +02:00
|
|
|
void VToolDetail::Create(const qint64 _id, VDetail &newDetail, VMainGraphicsScene *scene, VDomDocument *doc,
|
2013-09-29 12:58:45 +02:00
|
|
|
VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation){
|
2013-08-28 10:55:11 +02:00
|
|
|
qint64 id = _id;
|
|
|
|
if(typeCreation == Tool::FromGui){
|
|
|
|
id = data->AddDetail(newDetail);
|
|
|
|
} else {
|
|
|
|
data->UpdateDetail(id, newDetail);
|
|
|
|
if(parse != Document::FullParse){
|
2013-09-30 18:29:03 +02:00
|
|
|
doc->UpdateToolData(id, data);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(parse == Document::FullParse){
|
2013-09-30 18:29:03 +02:00
|
|
|
VToolDetail *detail = new VToolDetail(doc, data, id, typeCreation, scene);
|
2013-08-28 10:55:11 +02:00
|
|
|
scene->addItem(detail);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(detail, &VToolDetail::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-09-30 18:29:03 +02:00
|
|
|
connect(detail, &VToolDetail::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
2013-10-04 13:32:42 +02:00
|
|
|
QHash<qint64, VDataTool*>* tools = doc->getTools();
|
2013-08-28 10:55:11 +02:00
|
|
|
tools->insert(id, detail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VToolDetail::FullUpdateFromFile(){
|
|
|
|
RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
2013-08-29 12:31:50 +02:00
|
|
|
void VToolDetail::FullUpdateFromGui(int result){
|
2013-10-25 13:10:45 +02:00
|
|
|
if(result == QDialog::Accepted){
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if(domElement.isElement()){
|
|
|
|
VDetail det = dialogDetail->getDetails();
|
|
|
|
domElement.setAttribute("name", det.getName());
|
|
|
|
domElement.setAttribute("supplement", QString().setNum(det.getSupplement()));
|
|
|
|
domElement.setAttribute("closed", QString().setNum(det.getClosed()));
|
|
|
|
domElement.setAttribute("width", QString().setNum(det.getWidth()));
|
2013-10-25 13:16:07 +02:00
|
|
|
RemoveAllChild(domElement);
|
2013-10-25 13:10:45 +02:00
|
|
|
for(qint32 i = 0; i < det.CountNode(); ++i){
|
|
|
|
AddNode(domElement, det[i]);
|
|
|
|
}
|
|
|
|
emit FullUpdateTree();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dialogDetail.clear();
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VToolDetail::AddToFile(){
|
|
|
|
VDetail detail = VAbstractTool::data.GetDetail(id);
|
|
|
|
QDomElement domElement = doc->createElement("detail");
|
|
|
|
|
|
|
|
AddAttribute(domElement, "id", id);
|
|
|
|
AddAttribute(domElement, "name", detail.getName());
|
2013-10-25 13:10:45 +02:00
|
|
|
AddAttribute(domElement, "mx", toMM(detail.getMx()));
|
|
|
|
AddAttribute(domElement, "my", toMM(detail.getMy()));
|
|
|
|
AddAttribute(domElement, "supplement", detail.getSupplement());
|
|
|
|
AddAttribute(domElement, "closed", detail.getClosed());
|
|
|
|
AddAttribute(domElement, "width", detail.getWidth());
|
2013-08-28 10:55:11 +02:00
|
|
|
|
|
|
|
for(qint32 i = 0; i < detail.CountNode(); ++i){
|
|
|
|
AddNode(domElement, detail[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
QDomElement element;
|
|
|
|
bool ok = doc->GetActivDetailsElement(element);
|
|
|
|
if(ok){
|
|
|
|
element.appendChild(domElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value){
|
|
|
|
if (change == ItemPositionHasChanged && scene()) {
|
|
|
|
// value - это новое положение.
|
|
|
|
QPointF newPos = value.toPointF();
|
2013-09-10 14:29:06 +02:00
|
|
|
//qDebug()<<newPos;
|
2013-08-28 10:55:11 +02:00
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if(domElement.isElement()){
|
|
|
|
domElement.setAttribute("mx", QString().setNum(toMM(newPos.x())));
|
|
|
|
domElement.setAttribute("my", QString().setNum(toMM(newPos.y())));
|
|
|
|
//I don't now why but signal does not work.
|
|
|
|
doc->FullUpdateTree();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VToolDetail::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
|
|
|
|
if(event->button() == Qt::LeftButton){
|
|
|
|
emit ChoosedTool(id, Scene::Detail);
|
|
|
|
}
|
|
|
|
QGraphicsItem::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2013-09-30 18:29:03 +02:00
|
|
|
void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
|
|
|
|
QMenu menu;
|
2013-10-25 13:10:45 +02:00
|
|
|
QAction *actionOption = menu.addAction(tr("Options"));
|
2013-09-30 18:29:03 +02:00
|
|
|
QAction *actionRemove = menu.addAction(tr("Delete"));
|
|
|
|
if(_referens > 1){
|
|
|
|
actionRemove->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
actionRemove->setEnabled(true);
|
|
|
|
}
|
|
|
|
QAction *selectedAction = menu.exec(event->screenPos());
|
2013-10-25 13:10:45 +02:00
|
|
|
if(selectedAction == actionOption){
|
|
|
|
dialogDetail = QSharedPointer<DialogDetail>(new DialogDetail(getData(), Draw::Modeling));
|
|
|
|
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
|
|
|
|
dialogDetail.data(), &DialogDetail::ChoosedObject);
|
|
|
|
connect(dialogDetail.data(), &DialogDetail::DialogClosed, this, &VToolDetail::FullUpdateFromGui);
|
|
|
|
setDialog();
|
|
|
|
dialogDetail->show();
|
|
|
|
}
|
2013-09-30 18:29:03 +02:00
|
|
|
if(selectedAction == actionRemove){
|
|
|
|
//remove form xml file
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if(domElement.isElement()){
|
|
|
|
QDomNode element = domElement.parentNode();
|
|
|
|
if(!element.isNull()){
|
2013-10-09 18:24:28 +02:00
|
|
|
//deincrement referens
|
|
|
|
RemoveReferens();
|
2013-09-30 18:29:03 +02:00
|
|
|
element.removeChild(domElement);
|
|
|
|
//update xml file
|
|
|
|
emit FullUpdateTree();
|
|
|
|
//remove form scene
|
|
|
|
emit RemoveTool(this);
|
2013-10-09 18:24:28 +02:00
|
|
|
} else {
|
|
|
|
qWarning()<<"parentNode isNull"<<Q_FUNC_INFO;
|
2013-09-30 18:29:03 +02:00
|
|
|
}
|
2013-10-09 18:24:28 +02:00
|
|
|
} else {
|
|
|
|
qWarning()<<"Can't get element by id = "<<id<<Q_FUNC_INFO;
|
2013-09-30 18:29:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VToolDetail::RemoveReferens(){
|
|
|
|
VDetail detail = VAbstractTool::data.GetDetail(id);
|
|
|
|
for(qint32 i = 0; i< detail.CountNode(); ++i){
|
|
|
|
doc->DecrementReferens(detail[i].getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 10:55:11 +02:00
|
|
|
void VToolDetail::AddNode(QDomElement &domElement, VNodeDetail &node){
|
|
|
|
QDomElement nod = doc->createElement("node");
|
|
|
|
|
2013-09-11 16:14:21 +02:00
|
|
|
AddAttribute(nod, "idObject", node.getId());
|
2013-10-25 13:10:45 +02:00
|
|
|
AddAttribute(nod, "mx", toMM(node.getMx()));
|
|
|
|
AddAttribute(nod, "my", toMM(node.getMy()));
|
2013-09-10 14:29:06 +02:00
|
|
|
if(node.getTypeNode() == NodeDetail::Contour){
|
|
|
|
AddAttribute(nod, "nodeType", "Contour");
|
|
|
|
} else {
|
|
|
|
AddAttribute(nod, "nodeType", "Modeling");
|
|
|
|
}
|
2013-08-28 10:55:11 +02:00
|
|
|
switch(node.getTypeTool()){
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::AlongLineTool):
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(nod, "type", "AlongLineTool");
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::ArcTool):
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(nod, "type", "ArcTool");
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::BisectorTool):
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(nod, "type", "BisectorTool");
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::EndLineTool):
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(nod, "type", "EndLineTool");
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::LineIntersectTool):
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(nod, "type", "LineIntersectTool");
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::LineTool):
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(nod, "type", "LineTool");
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::NodeArc):
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(nod, "type", "NodeArc");
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::NodePoint):
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(nod, "type", "NodePoint");
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::NodeSpline):
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(nod, "type", "NodeSpline");
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::NodeSplinePath):
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(nod, "type", "NodeSplinePath");
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::NormalTool):
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(nod, "type", "NormalTool");
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::PointOfContact):
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(nod, "type", "PointOfContact");
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::ShoulderPointTool):
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(nod, "type", "ShoulderPointTool");
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::SplinePathTool):
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(nod, "type", "SplinePathTool");
|
|
|
|
break;
|
2013-09-27 11:17:00 +02:00
|
|
|
case(Tool::SplineTool):
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(nod, "type", "SplineTool");
|
|
|
|
break;
|
2013-10-25 13:10:45 +02:00
|
|
|
case(Tool::Height):
|
|
|
|
AddAttribute(nod, "type", "Height");
|
|
|
|
break;
|
|
|
|
case(Tool::Triangle):
|
|
|
|
AddAttribute(nod, "type", "Triangle");
|
|
|
|
break;
|
|
|
|
case(Tool::PointOfIntersection):
|
|
|
|
AddAttribute(nod, "type", "PointOfIntersection");
|
|
|
|
break;
|
2013-09-10 14:29:06 +02:00
|
|
|
default:
|
|
|
|
qWarning()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
|
2013-08-28 10:55:11 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
domElement.appendChild(nod);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VToolDetail::RefreshGeometry(){
|
2013-08-29 12:31:50 +02:00
|
|
|
QPainterPath path = VAbstractTool::data.ContourPath(id);
|
2013-08-28 10:55:11 +02:00
|
|
|
this->setPath(path);
|
|
|
|
}
|