2013-09-10 14:29:06 +02:00
|
|
|
#include "vmodelingsplinepath.h"
|
2013-08-09 08:49:34 +02:00
|
|
|
#include <QMenu>
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingSplinePath::VModelingSplinePath(VDomDocument *doc, VContainer *data, qint64 id,
|
2013-08-28 10:55:11 +02:00
|
|
|
Tool::Enum typeCreation,
|
2013-09-10 14:29:06 +02:00
|
|
|
QGraphicsItem *parent):VModelingTool(doc, data, id),
|
2013-08-20 12:26:02 +02:00
|
|
|
QGraphicsPathItem(parent), dialogSplinePath(QSharedPointer<DialogSplinePath>()),
|
|
|
|
controlPoints(QVector<VControlPointSpline *>()){
|
2013-09-10 14:29:06 +02:00
|
|
|
VSplinePath splPath = data->GetModelingSplinePath(id);
|
2013-08-09 08:49:34 +02:00
|
|
|
QPainterPath path;
|
|
|
|
path.addPath(splPath.GetPath());
|
|
|
|
path.setFillRule( Qt::WindingFill );
|
|
|
|
this->setPath(path);
|
|
|
|
this->setPen(QPen(Qt::black, widthHairLine));
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
|
|
this->setAcceptHoverEvents(true);
|
|
|
|
|
|
|
|
for(qint32 i = 1; i<=splPath.Count(); ++i){
|
|
|
|
VSpline spl = splPath.GetSpline(i);
|
|
|
|
VControlPointSpline *controlPoint = new VControlPointSpline(i, SplinePoint::FirstPoint, spl.GetP2(),
|
2013-08-13 18:48:36 +02:00
|
|
|
spl.GetPointP1().toQPointF(), this);
|
2013-08-09 08:49:34 +02:00
|
|
|
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSplinePath::ControlPointChangePosition);
|
|
|
|
connect(this, &VModelingSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine);
|
|
|
|
connect(this, &VModelingSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint);
|
2013-08-09 08:49:34 +02:00
|
|
|
controlPoints.append(controlPoint);
|
|
|
|
|
2013-08-13 18:48:36 +02:00
|
|
|
controlPoint = new VControlPointSpline(i, SplinePoint::LastPoint, spl.GetP3(),
|
|
|
|
spl.GetPointP4().toQPointF(), this);
|
2013-08-09 08:49:34 +02:00
|
|
|
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSplinePath::ControlPointChangePosition);
|
|
|
|
connect(this, &VModelingSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine);
|
|
|
|
connect(this, &VModelingSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint);
|
2013-08-09 08:49:34 +02:00
|
|
|
controlPoints.append(controlPoint);
|
|
|
|
}
|
|
|
|
if(typeCreation == Tool::FromGui){
|
|
|
|
AddToFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VModelingSplinePath::setDialog(){
|
2013-08-13 18:48:36 +02:00
|
|
|
Q_ASSERT(!dialogSplinePath.isNull());
|
|
|
|
if(!dialogSplinePath.isNull()){
|
2013-09-10 14:29:06 +02:00
|
|
|
VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id);
|
2013-08-13 18:48:36 +02:00
|
|
|
dialogSplinePath->SetPath(splPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingSplinePath *VModelingSplinePath::Create(QSharedPointer<DialogSplinePath> &dialog,
|
|
|
|
VDomDocument *doc, VContainer *data){
|
2013-08-13 18:48:36 +02:00
|
|
|
VSplinePath path = dialog->GetPath();
|
2013-09-10 14:29:06 +02:00
|
|
|
return Create(0, path, doc, data, Document::FullParse, Tool::FromGui);
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingSplinePath * VModelingSplinePath::Create(const qint64 _id, const VSplinePath &path,
|
|
|
|
VDomDocument *doc, VContainer *data, Document::Enum parse,
|
|
|
|
Tool::Enum typeCreation){
|
|
|
|
VModelingSplinePath *spl = 0;
|
2013-08-13 18:48:36 +02:00
|
|
|
qint64 id = _id;
|
|
|
|
if(typeCreation == Tool::FromGui){
|
2013-09-10 14:29:06 +02:00
|
|
|
id = data->AddModelingSplinePath(path);
|
2013-08-13 18:48:36 +02:00
|
|
|
} else {
|
2013-09-10 14:29:06 +02:00
|
|
|
data->UpdateModelingSplinePath(id, path);
|
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::SplinePath, 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
|
|
|
for(qint32 i = 0; i < path.CountPoint(); ++i){
|
|
|
|
data->IncrementReferens(path.getIdObject(), Scene::Point, Draw::Modeling);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
2013-09-10 14:29:06 +02:00
|
|
|
data->AddLengthSpline(data->GetNameSplinePath(path), path.GetLength());
|
2013-08-13 18:48:36 +02:00
|
|
|
if(parse == Document::FullParse){
|
2013-09-10 14:29:06 +02:00
|
|
|
spl = new VModelingSplinePath(doc, data, id, typeCreation);
|
2013-08-13 18:48:36 +02:00
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
tools->insert(id,spl);
|
|
|
|
}
|
2013-09-10 14:29:06 +02:00
|
|
|
return spl;
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VModelingSplinePath::FullUpdateFromFile(){
|
2013-08-09 08:49:34 +02:00
|
|
|
RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VModelingSplinePath::FullUpdateFromGui(int result){
|
2013-08-09 08:49:34 +02:00
|
|
|
if(result == QDialog::Accepted){
|
|
|
|
VSplinePath splPath = dialogSplinePath->GetPath();
|
|
|
|
for(qint32 i = 1; i<=splPath.Count(); ++i){
|
|
|
|
VSpline spl = splPath.GetSpline(i);
|
|
|
|
qint32 j = i*2;
|
|
|
|
disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSplinePath::ControlPointChangePosition);
|
2013-08-09 08:49:34 +02:00
|
|
|
disconnect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSplinePath::ControlPointChangePosition);
|
2013-08-09 08:49:34 +02:00
|
|
|
controlPoints[j-2]->setPos(spl.GetP2());
|
|
|
|
controlPoints[j-1]->setPos(spl.GetP3());
|
|
|
|
connect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSplinePath::ControlPointChangePosition);
|
2013-08-09 08:49:34 +02:00
|
|
|
connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSplinePath::ControlPointChangePosition);
|
2013-08-09 08:49:34 +02:00
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
spl = VSpline (VAbstractTool::data.DataModelingPoints(), spl.GetP1(), controlPoints[j-2]->pos(),
|
2013-08-09 08:49:34 +02:00
|
|
|
controlPoints[j-1]->pos(), spl.GetP4(), splPath.getKCurve());
|
2013-08-21 10:03:53 +02:00
|
|
|
CorectControlPoints(spl, splPath, i);
|
|
|
|
CorectControlPoints(spl, splPath, i);
|
2013-08-09 08:49:34 +02:00
|
|
|
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if(domElement.isElement()){
|
|
|
|
domElement.setAttribute("kCurve", QString().setNum(splPath.getKCurve()));
|
|
|
|
UpdatePathPoint(domElement, splPath);
|
|
|
|
emit FullUpdateTree();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dialogSplinePath.clear();
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VModelingSplinePath::ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position,
|
2013-08-21 10:03:53 +02:00
|
|
|
const QPointF pos){
|
2013-09-10 14:29:06 +02:00
|
|
|
VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id);
|
2013-08-09 08:49:34 +02:00
|
|
|
VSpline spl = splPath.GetSpline(indexSpline);
|
|
|
|
if(position == SplinePoint::FirstPoint){
|
|
|
|
spl.ModifiSpl (spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve());
|
|
|
|
} else {
|
|
|
|
spl.ModifiSpl (spl.GetP1(), spl.GetP2(), pos, spl.GetP4(), spl.GetKcurve());
|
|
|
|
}
|
|
|
|
|
2013-08-21 10:03:53 +02:00
|
|
|
CorectControlPoints(spl, splPath, indexSpline);
|
2013-08-09 08:49:34 +02:00
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if(domElement.isElement()){
|
|
|
|
domElement.setAttribute("kCurve", QString().setNum(splPath.getKCurve()));
|
|
|
|
UpdatePathPoint(domElement, splPath);
|
|
|
|
emit FullUpdateTree();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VModelingSplinePath::CorectControlPoints(const VSpline &spl, VSplinePath &splPath,
|
2013-08-21 10:03:53 +02:00
|
|
|
const qint32 &indexSpline){
|
2013-08-09 08:49:34 +02:00
|
|
|
VSplinePoint p = splPath.GetSplinePoint(indexSpline, SplinePoint::FirstPoint);
|
|
|
|
p.SetAngle(spl.GetAngle1());
|
|
|
|
p.SetKAsm2(spl.GetKasm1());
|
|
|
|
splPath.UpdatePoint(indexSpline, SplinePoint::FirstPoint, p);
|
|
|
|
|
|
|
|
p = splPath.GetSplinePoint(indexSpline, SplinePoint::LastPoint);
|
|
|
|
p.SetAngle(spl.GetAngle2()-180);
|
|
|
|
p.SetKAsm1(spl.GetKasm2());
|
|
|
|
splPath.UpdatePoint(indexSpline, SplinePoint::LastPoint, p);
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VModelingSplinePath::UpdatePathPoint(QDomNode& node, VSplinePath &path){
|
2013-08-09 08:49:34 +02:00
|
|
|
QDomNodeList nodeList = node.childNodes();
|
|
|
|
qint32 num = nodeList.size();
|
|
|
|
for(qint32 i = 0; i < num; ++i){
|
|
|
|
QDomElement domElement = nodeList.at(i).toElement();
|
|
|
|
if(!domElement.isNull()){
|
|
|
|
VSplinePoint p = path[i];
|
|
|
|
domElement.setAttribute("pSpline", QString().setNum(p.P()));
|
|
|
|
domElement.setAttribute("kAsm1", QString().setNum(p.KAsm1()));
|
|
|
|
domElement.setAttribute("kAsm2", QString().setNum(p.KAsm2()));
|
|
|
|
domElement.setAttribute("angle", QString().setNum(p.Angle2()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VModelingSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
|
2013-08-13 18:48:36 +02:00
|
|
|
ContextMenu(dialogSplinePath, this, event);
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VModelingSplinePath::AddToFile(){
|
|
|
|
VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id);
|
2013-08-09 08:49:34 +02:00
|
|
|
QDomElement domElement = doc->createElement("spline");
|
|
|
|
|
|
|
|
AddAttribute(domElement, "id", id);
|
|
|
|
AddAttribute(domElement, "type", "path");
|
|
|
|
AddAttribute(domElement, "kCurve", splPath.getKCurve());
|
|
|
|
|
|
|
|
for(qint32 i = 0; i < splPath.CountPoint(); ++i){
|
|
|
|
AddPathPoint(domElement, splPath[i]);
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
AddToModeling(domElement);
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VModelingSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint){
|
2013-08-09 08:49:34 +02:00
|
|
|
QDomElement pathPoint = doc->createElement("pathPoint");
|
|
|
|
|
|
|
|
AddAttribute(pathPoint, "pSpline", splPoint.P());
|
|
|
|
AddAttribute(pathPoint, "kAsm1", splPoint.KAsm1());
|
|
|
|
AddAttribute(pathPoint, "kAsm2", splPoint.KAsm2());
|
|
|
|
AddAttribute(pathPoint, "angle", splPoint.Angle2());
|
|
|
|
|
|
|
|
domElement.appendChild(pathPoint);
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VModelingSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
|
2013-08-09 08:49:34 +02:00
|
|
|
if(event->button() == Qt::LeftButton){
|
|
|
|
emit ChoosedTool(id, Scene::SplinePath);
|
|
|
|
}
|
|
|
|
QGraphicsItem::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VModelingSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event){
|
2013-08-09 08:49:34 +02:00
|
|
|
Q_UNUSED(event);
|
2013-08-15 22:39:00 +02:00
|
|
|
this->setPen(QPen(currentColor, widthMainLine));
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VModelingSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){
|
2013-08-09 08:49:34 +02:00
|
|
|
Q_UNUSED(event);
|
2013-08-15 22:39:00 +02:00
|
|
|
this->setPen(QPen(currentColor, widthHairLine));
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VModelingSplinePath::RefreshGeometry(){
|
|
|
|
VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id);
|
2013-08-09 08:49:34 +02:00
|
|
|
QPainterPath path;
|
|
|
|
path.addPath(splPath.GetPath());
|
|
|
|
path.setFillRule( Qt::WindingFill );
|
|
|
|
this->setPath(path);
|
|
|
|
for(qint32 i = 1; i<=splPath.Count(); ++i){
|
|
|
|
VSpline spl = splPath.GetSpline(i);
|
2013-08-21 10:03:53 +02:00
|
|
|
QPointF splinePoint = spl.GetPointP1().toQPointF();
|
2013-08-09 08:49:34 +02:00
|
|
|
QPointF controlPoint = spl.GetP2();
|
|
|
|
emit RefreshLine(i, SplinePoint::FirstPoint, controlPoint, splinePoint);
|
2013-08-21 10:03:53 +02:00
|
|
|
splinePoint = spl.GetPointP4().toQPointF();
|
2013-08-09 08:49:34 +02:00
|
|
|
controlPoint = spl.GetP3();
|
|
|
|
emit RefreshLine(i, SplinePoint::LastPoint, controlPoint, splinePoint);
|
2013-08-13 18:48:36 +02:00
|
|
|
|
|
|
|
qint32 j = i*2;
|
|
|
|
disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSplinePath::ControlPointChangePosition);
|
2013-08-13 18:48:36 +02:00
|
|
|
disconnect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSplinePath::ControlPointChangePosition);
|
2013-08-13 18:48:36 +02:00
|
|
|
controlPoints[j-2]->setPos(spl.GetP2());
|
|
|
|
controlPoints[j-1]->setPos(spl.GetP3());
|
|
|
|
connect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSplinePath::ControlPointChangePosition);
|
2013-08-13 18:48:36 +02:00
|
|
|
connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSplinePath::ControlPointChangePosition);
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|