diff --git a/src/dialogs/dialogsplinepath.cpp b/src/dialogs/dialogsplinepath.cpp index 1aa2ec9f0..058dc5a9a 100644 --- a/src/dialogs/dialogsplinepath.cpp +++ b/src/dialogs/dialogsplinepath.cpp @@ -38,18 +38,19 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, QWidget *parent) ui->setupUi(this); bOk = ui->buttonBox->button(QDialogButtonBox::Ok); connect(bOk, &QPushButton::clicked, this, &DialogSplinePath::DialogAccepted); + bOk->setEnabled(false); QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); connect(bCansel, &QPushButton::clicked, this, &DialogSplinePath::DialogRejected); FillComboBoxPoints(ui->comboBoxPoint); - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogSplinePath::PointChenged); + connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogSplinePath::PointChanged); connect(ui->comboBoxPoint, static_cast(&QComboBox::currentIndexChanged), this, &DialogSplinePath::currentPointChanged); - connect(ui->spinBoxAngle1, static_cast(&QSpinBox::valueChanged), + connect(ui->doubleSpinBoxAngle1, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogSplinePath::Angle1Changed); - connect(ui->spinBoxAngle2, static_cast(&QSpinBox::valueChanged), + connect(ui->doubleSpinBoxAngle2, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogSplinePath::Angle2Changed); connect(ui->doubleSpinBoxKasm1, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogSplinePath::KAsm1Changed); @@ -68,7 +69,7 @@ void DialogSplinePath::SetPath(const VSplinePath &value) ui->listWidget->clear(); for (qint32 i = 0; i < path.CountPoint(); ++i) { - NewItem(path[i].P().id(), path[i].KAsm1(), path[i].Angle2(), path[i].KAsm2()); + NewItem(path[i].P().id(), path[i].KAsm1(), path[i].Angle1(), path[i].KAsm2(), path[i].Angle2()); } ui->listWidget->setFocus(Qt::OtherFocusReason); ui->doubleSpinBoxKcurve->setValue(path.getKCurve()); @@ -79,7 +80,7 @@ void DialogSplinePath::ChoosedObject(qint64 id, const Scene::Scenes &type) { if (type == Scene::Point) { - NewItem(id, 1, 0, 1); + NewItem(id, 1, 0, 1, 180); emit ToolTip(tr("Select point of curve path")); this->show(); } @@ -98,7 +99,7 @@ void DialogSplinePath::DialogAccepted() emit DialogClosed(QDialog::Accepted); } -void DialogSplinePath::PointChenged(int row) +void DialogSplinePath::PointChanged(int row) { if (ui->listWidget->count() == 0) { @@ -123,14 +124,26 @@ void DialogSplinePath::currentPointChanged(int index) item->setData(Qt::UserRole, QVariant::fromValue(p)); } -void DialogSplinePath::Angle1Changed(int index) +void DialogSplinePath::Angle1Changed(qreal index) { - SetAngle(index+180); + qint32 row = ui->listWidget->currentRow(); + QListWidgetItem *item = ui->listWidget->item( row ); + Q_CHECK_PTR(item); + VSplinePoint p = qvariant_cast(item->data(Qt::UserRole)); + p.SetAngle1(index); + DataPoint(p.P().id(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2()); + item->setData(Qt::UserRole, QVariant::fromValue(p)); } -void DialogSplinePath::Angle2Changed(int index) +void DialogSplinePath::Angle2Changed(qreal index) { - SetAngle(index); + qint32 row = ui->listWidget->currentRow(); + QListWidgetItem *item = ui->listWidget->item( row ); + Q_CHECK_PTR(item); + VSplinePoint p = qvariant_cast(item->data(Qt::UserRole)); + p.SetAngle2(index); + DataPoint(p.P().id(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2()); + item->setData(Qt::UserRole, QVariant::fromValue(p)); } void DialogSplinePath::KAsm1Changed(qreal d) @@ -151,15 +164,21 @@ void DialogSplinePath::KAsm2Changed(qreal d) item->setData(Qt::UserRole, QVariant::fromValue(p)); } -void DialogSplinePath::NewItem(qint64 id, qreal kAsm1, qreal angle, qreal kAsm2) +void DialogSplinePath::NewItem(qint64 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2) { const VPointF *point = data->GeometricObject(id); QListWidgetItem *item = new QListWidgetItem(point->name()); item->setFont(QFont("Times", 12, QFont::Bold)); - VSplinePoint p(*point, kAsm1, angle, kAsm2); - DataPoint(point->id(), kAsm1, angle+180, kAsm2, angle); + VSplinePoint p(*point, kAsm1, angle1, kAsm2, angle2); + DataPoint(point->id(), kAsm1, angle1, kAsm2, angle2); item->setData(Qt::UserRole, QVariant::fromValue(p)); ui->listWidget->addItem(item); + ui->listWidget->setCurrentItem(item); + if (ui->listWidget->count() >= 2) + { + bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + bOk->setEnabled(true); + } EnableFields(); } @@ -167,9 +186,9 @@ void DialogSplinePath::DataPoint(qint64 id, qreal kAsm1, qreal angle1, qreal kAs { disconnect(ui->comboBoxPoint, static_cast(&QComboBox::currentIndexChanged), this, &DialogSplinePath::currentPointChanged); - disconnect(ui->spinBoxAngle1, static_cast(&QSpinBox::valueChanged), + disconnect(ui->doubleSpinBoxAngle1, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogSplinePath::Angle1Changed); - disconnect(ui->spinBoxAngle2, static_cast(&QSpinBox::valueChanged), + disconnect(ui->doubleSpinBoxAngle2, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogSplinePath::Angle2Changed); disconnect(ui->doubleSpinBoxKasm1, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogSplinePath::KAsm1Changed); @@ -179,14 +198,14 @@ void DialogSplinePath::DataPoint(qint64 id, qreal kAsm1, qreal angle1, qreal kAs ChangeCurrentData(ui->comboBoxPoint, id); ui->doubleSpinBoxKasm1->setValue(kAsm1); ui->doubleSpinBoxKasm2->setValue(kAsm2); - ui->spinBoxAngle2->setValue(static_cast(angle2)); - ui->spinBoxAngle1->setValue(static_cast(angle1)); + ui->doubleSpinBoxAngle2->setValue(angle2); + ui->doubleSpinBoxAngle1->setValue(angle1); connect(ui->comboBoxPoint, static_cast(&QComboBox::currentIndexChanged), this, &DialogSplinePath::currentPointChanged); - connect(ui->spinBoxAngle1, static_cast(&QSpinBox::valueChanged), + connect(ui->doubleSpinBoxAngle1, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogSplinePath::Angle1Changed); - connect(ui->spinBoxAngle2, static_cast(&QSpinBox::valueChanged), + connect(ui->doubleSpinBoxAngle2, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogSplinePath::Angle2Changed); connect(ui->doubleSpinBoxKasm1, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogSplinePath::KAsm1Changed); @@ -197,30 +216,20 @@ void DialogSplinePath::DataPoint(qint64 id, qreal kAsm1, qreal angle1, qreal kAs void DialogSplinePath::EnableFields() { ui->doubleSpinBoxKasm1->setEnabled(true); - ui->spinBoxAngle1->setEnabled(true); + ui->doubleSpinBoxAngle1->setEnabled(true); ui->doubleSpinBoxKasm2->setEnabled(true); - ui->spinBoxAngle2->setEnabled(true); + ui->doubleSpinBoxAngle2->setEnabled(true); qint32 row = ui->listWidget->currentRow(); if (row == 0) { ui->doubleSpinBoxKasm1->setEnabled(false); - ui->spinBoxAngle1->setEnabled(false); + ui->doubleSpinBoxAngle1->setEnabled(false); return; } if (row == ui->listWidget->count()-1) { ui->doubleSpinBoxKasm2->setEnabled(false); - ui->spinBoxAngle2->setEnabled(false); + ui->doubleSpinBoxAngle2->setEnabled(false); return; } } - -void DialogSplinePath::SetAngle(qint32 angle) -{ - qint32 row = ui->listWidget->currentRow(); - QListWidgetItem *item = ui->listWidget->item( row ); - VSplinePoint p = qvariant_cast(item->data(Qt::UserRole)); - p.SetAngle(angle); - DataPoint(p.P().id(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2()); - item->setData(Qt::UserRole, QVariant::fromValue(p)); -} diff --git a/src/dialogs/dialogsplinepath.h b/src/dialogs/dialogsplinepath.h index 5adff5438..c88713f55 100644 --- a/src/dialogs/dialogsplinepath.h +++ b/src/dialogs/dialogsplinepath.h @@ -73,10 +73,10 @@ public slots: */ virtual void DialogAccepted(); /** - * @brief PointChenged selected another point in list + * @brief PointChanged selected another point in list * @param row number of row */ - void PointChenged(int row); + void PointChanged(int row); /** * @brief currentPointChanged changed point in combo box * @param index index in list @@ -86,12 +86,12 @@ public slots: * @brief Angle1Changed changed first angle * @param index index in list */ - void Angle1Changed( int index ); + void Angle1Changed(qreal index ); /** * @brief Angle2Changed changed second angle * @param index index in list */ - void Angle2Changed( int index ); + void Angle2Changed( qreal index ); /** * @brief KAsm1Changed changed first coefficient asymmetry * @param d value @@ -116,10 +116,11 @@ private: * @brief NewItem add point to list * @param id id * @param kAsm1 first coefficient asymmetry - * @param angle angle in degree + * @param angle1 first angle in degree * @param kAsm2 second coefficient asymmetry + * @param angle2 second angle in degree */ - void NewItem(qint64 id, qreal kAsm1, qreal angle, qreal kAsm2); + void NewItem(qint64 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); /** * @brief dataPoint show data of point in fields * @param id id @@ -133,11 +134,6 @@ private: * @brief EnableFields enable or disable fields */ void EnableFields(); - /** - * @brief SetAngle set angle of point - * @param angle angle in degree - */ - void SetAngle(qint32 angle); }; #endif // DIALOGSPLINEPATH_H diff --git a/src/dialogs/dialogsplinepath.ui b/src/dialogs/dialogsplinepath.ui index e6c7c6581..22ce120d6 100644 --- a/src/dialogs/dialogsplinepath.ui +++ b/src/dialogs/dialogsplinepath.ui @@ -76,9 +76,9 @@ - + - 360 + 360.000000000000000 @@ -121,9 +121,9 @@ - + - 360 + 360.000000000000000 @@ -200,9 +200,9 @@ comboBoxPoint doubleSpinBoxKasm1 - spinBoxAngle1 + doubleSpinBoxAngle1 doubleSpinBoxKasm2 - spinBoxAngle2 + doubleSpinBoxAngle2 doubleSpinBoxKcurve listWidget buttonBox diff --git a/src/geometry/vsplinepoint.cpp b/src/geometry/vsplinepoint.cpp index bda00b236..469b0d1dc 100644 --- a/src/geometry/vsplinepoint.cpp +++ b/src/geometry/vsplinepoint.cpp @@ -29,10 +29,37 @@ #include "vsplinepoint.h" VSplinePoint::VSplinePoint() - :pSpline(VPointF()), angle(0), kAsm1(1), kAsm2(1){} + :pSpline(VPointF()), angle1(0), angle2(180), kAsm1(1), kAsm2(1){} -VSplinePoint::VSplinePoint(VPointF pSpline, qreal kAsm1, qreal angle, qreal kAsm2) - :pSpline(pSpline), angle(angle), kAsm1(kAsm1), kAsm2(kAsm2){} +VSplinePoint::VSplinePoint(VPointF pSpline, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2) + :pSpline(pSpline), angle1(0), angle2(180), kAsm1(kAsm1), kAsm2(kAsm2) +{ + if (qFuzzyCompare(qAbs(angle1-angle2), 180) == false) + { + qWarning()<<"angle1 and angle2 are not equal."; + } + SetAngle2(angle2); +} VSplinePoint::VSplinePoint(const VSplinePoint &point) - :pSpline(point.P()), angle(point.Angle2()), kAsm1(point.KAsm1()), kAsm2(point.KAsm2()){} + :pSpline(point.P()), angle1(point.Angle1()), angle2(point.Angle2()), kAsm1(point.KAsm1()), kAsm2(point.KAsm2()){} + +void VSplinePoint::SetAngle1(const qreal &value) +{ + QLineF line(0, 0, 100, 0); + line.setAngle(value); + angle1 = line.angle(); + + line.setAngle(value+180); + angle2 = line.angle(); +} + +void VSplinePoint::SetAngle2(const qreal &value) +{ + QLineF line(0, 0, 100, 0); + line.setAngle(value); + angle2 = line.angle(); + + line.setAngle(value-180); + angle1 = line.angle(); +} diff --git a/src/geometry/vsplinepoint.h b/src/geometry/vsplinepoint.h index 0e64ba230..30517c406 100644 --- a/src/geometry/vsplinepoint.h +++ b/src/geometry/vsplinepoint.h @@ -49,7 +49,7 @@ public: * @param angle second angle control line. * @param factor coefficient of length second control line. */ - VSplinePoint(VPointF pSpline, qreal kAsm1, qreal angle, qreal kAsm2); + VSplinePoint(VPointF pSpline, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); /** * @brief VSplinePoint copy constructor * @param point point @@ -65,59 +65,68 @@ public: * @brief SetP set point. * @param value point. */ - inline void SetP(const VPointF &value) {pSpline = value;} + inline void SetP(const VPointF &value) {pSpline = value;} /** * @brief Angle1 return first angle of spline. * @return angle. */ - inline qreal Angle1() const {return angle+180;} + inline qreal Angle1() const {return angle1;} /** - * @brief SetAngle set first angle of spline. + * @brief SetAngle1 set first angle of spline. * @param value angle. */ - inline void SetAngle(const qreal &value) {angle = value;} + void SetAngle1(const qreal &value); + /** + * @brief SetAngle2 set second angle of spline. + * @param value angle. + */ + void SetAngle2(const qreal &value); /** * @brief Angle2 return second angle of spline. * @return angle. */ - inline qreal Angle2() const {return angle;} + inline qreal Angle2() const {return angle2;} /** * @brief KAsm1 return coefficient of length first control line. * @return coefficient. */ - inline qreal KAsm1() const {return kAsm1;} + inline qreal KAsm1() const {return kAsm1;} /** * @brief SetKAsm1 set coefficient of length first control line. * @param value coefficient. */ - inline void SetKAsm1(const qreal &value) {kAsm1 = value;} + inline void SetKAsm1(const qreal &value) {kAsm1 = value;} /** * @brief KAsm2 return coefficient of length second control line. * @return coefficient. */ - inline qreal KAsm2() const {return kAsm2;} + inline qreal KAsm2() const {return kAsm2;} /** * @brief SetKAsm2 set coefficient of length second control line. * @param value coefficient. */ - inline void SetKAsm2(const qreal &value) {kAsm2 = value;} + inline void SetKAsm2(const qreal &value) {kAsm2 = value;} protected: /** * @brief pSpline point. */ VPointF pSpline; /** - * @brief angle first angle spline. + * @brief angle1 first angle spline. */ - qreal angle; + qreal angle1; + /** + * @brief angle2 second angle spline. + */ + qreal angle2; /** * @brief kAsm1 coefficient of length first control line. */ - qreal kAsm1; + qreal kAsm1; /** * @brief kAsm2 coefficient of length second control line. */ - qreal kAsm2; + qreal kAsm2; }; Q_DECLARE_METATYPE(VSplinePoint) diff --git a/src/tools/drawTools/vtoolcutsplinepath.cpp b/src/tools/drawTools/vtoolcutsplinepath.cpp index 30e5ab67a..ae49c70c7 100644 --- a/src/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/tools/drawTools/vtoolcutsplinepath.cpp @@ -130,9 +130,10 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons { if (i == p1) { - splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1(), spl1.GetKasm1())); - VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2()+180, - spl2.GetKasm1()); + splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(), + spl1.GetAngle1())); + VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), + spl1.GetAngle2()+180, spl1.GetAngle2()); splPath1->append(cutPoint); continue; } @@ -142,9 +143,11 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons { if (i == p2) { - VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1(), spl2.GetKasm1()); + VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1()+180, spl2.GetKasm1(), + spl2.GetAngle1()); splPath2->append(cutPoint); - splPath2->append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2()+180, splP2.KAsm2())); + splPath2->append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2(), splP2.KAsm2(), + spl2.GetAngle2()+180)); continue; } splPath2->append(splPath->at(i)); @@ -184,9 +187,10 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons { if (i == p1) { - splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1(), spl1.GetKasm1())); - VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2()+180, - spl2.GetKasm1()); + splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(), + spl1.GetAngle1())); + VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), + spl2.GetKasm1(), spl1.GetAngle2()+180); splPath1->append(cutPoint); continue; } @@ -196,9 +200,11 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons { if (i == p2) { - VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1(), spl2.GetKasm1()); + VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1()+180, spl2.GetKasm1(), + spl2.GetAngle1()); splPath2->append(cutPoint); - splPath2->append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2()+180, splP2.KAsm2())); + splPath2->append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2(), splP2.KAsm2(), + spl2.GetAngle2()+180)); continue; } splPath2->append(splPath->at(i)); diff --git a/src/tools/drawTools/vtoolsplinepath.cpp b/src/tools/drawTools/vtoolsplinepath.cpp index 3b0e85689..d7f2dac6b 100644 --- a/src/tools/drawTools/vtoolsplinepath.cpp +++ b/src/tools/drawTools/vtoolsplinepath.cpp @@ -161,12 +161,12 @@ void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, cons void VToolSplinePath::CorectControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline) { VSplinePoint p = splPath.GetSplinePoint(indexSpline, SplinePoint::FirstPoint); - p.SetAngle(spl.GetAngle1()); + p.SetAngle2(spl.GetAngle1()); p.SetKAsm2(spl.GetKasm1()); splPath.UpdatePoint(indexSpline, SplinePoint::FirstPoint, p); p = splPath.GetSplinePoint(indexSpline, SplinePoint::LastPoint); - p.SetAngle(spl.GetAngle2()-180); + p.SetAngle2(spl.GetAngle2()-180); p.SetKAsm1(spl.GetKasm2()); splPath.UpdatePoint(indexSpline, SplinePoint::LastPoint, p); } diff --git a/src/tools/vtooluniondetails.cpp b/src/tools/vtooluniondetails.cpp index dfd52c65b..a2952b075 100644 --- a/src/tools/vtooluniondetails.cpp +++ b/src/tools/vtooluniondetails.cpp @@ -207,11 +207,11 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai VSpline spl = VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline.GetKcurve()); if (i==1) { - path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(), - splinePath->at(i-1).KAsm2())); + path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1()+180, + splinePath->at(i-1).KAsm2(), spl.GetAngle1())); } - path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2()+180, - splinePath->at(i).KAsm2())); + path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2(), + splinePath->at(i).KAsm2(), spl.GetAngle2()+180)); } while (k>=0) { @@ -364,11 +364,11 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c VSpline spl = VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline.GetKcurve()); if (i==1) { - path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(), - splinePath->at(i-1).KAsm2())); + path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1()+180, + splinePath->at(i-1).KAsm2(), spl.GetAngle1())); } - path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2()+180, - splinePath->at(i).KAsm2())); + path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2(), + splinePath->at(i).KAsm2(), spl.GetAngle2()+180)); } while (k>=0) diff --git a/src/xml/vdomdocument.cpp b/src/xml/vdomdocument.cpp index c08d1b4ad..6da4bb208 100644 --- a/src/xml/vdomdocument.cpp +++ b/src/xml/vdomdocument.cpp @@ -1166,7 +1166,10 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme qint64 pSpline = GetParametrLongLong(element, VAbstractTool::AttrPSpline, "0"); VPointF p = *data->GeometricObject(pSpline); - VSplinePoint splPoint(p, kAsm1, angle, kAsm2); + QLineF line(0, 0, 100, 0); + line.setAngle(angle+180); + + VSplinePoint splPoint(p, kAsm1, line.angle(), kAsm2, angle); path->append(splPoint); if (parse == Document::FullParse) {