From 30ec4ed2f21f0e9b347e5b83c9ea820c230f529d Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 6 Aug 2013 10:56:09 +0300 Subject: [PATCH] Add tool arc --- Valentina.pro | 11 +- container/vcontainer.cpp | 64 +++-- container/vcontainer.h | 11 +- cursor.qrc | 1 + cursor/arc_cursor.png | Bin 0 -> 1276 bytes dialogs/dialogalongline.cpp | 2 +- dialogs/dialogarc.cpp | 189 ++++++++++++++ dialogs/dialogarc.h | 60 +++++ dialogs/dialogarc.ui | 419 ++++++++++++++++++++++++++++++++ dialogs/dialogbisector.cpp | 2 +- dialogs/dialogendline.cpp | 2 +- dialogs/dialognormal.cpp | 2 +- dialogs/dialogshoulderpoint.cpp | 2 +- dialogs/dialogtool.cpp | 176 ++++++-------- dialogs/dialogtool.h | 10 +- geometry/varc.cpp | 280 ++++----------------- geometry/varc.h | 113 +-------- icon.qrc | 2 + icon/24x24/putHereLeft.png | Bin 0 -> 1233 bytes icon/32x32/arc.png | Bin 0 -> 441 bytes mainwindow.cpp | 66 +++++ mainwindow.h | 7 +- mainwindow.ui | 24 +- tools/vtoolarc.cpp | 114 +++++++++ tools/vtoolarc.h | 32 +++ xml/vdomdocument.cpp | 53 ++++ xml/vdomdocument.h | 2 + 27 files changed, 1161 insertions(+), 483 deletions(-) create mode 100644 cursor/arc_cursor.png create mode 100644 dialogs/dialogarc.cpp create mode 100644 dialogs/dialogarc.h create mode 100644 dialogs/dialogarc.ui create mode 100644 icon/24x24/putHereLeft.png create mode 100644 icon/32x32/arc.png create mode 100644 tools/vtoolarc.cpp create mode 100644 tools/vtoolarc.h diff --git a/Valentina.pro b/Valentina.pro index e46816eb4..28883567a 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -48,7 +48,9 @@ SOURCES += main.cpp\ geometry/varc.cpp \ widgets/vcontrolpointspline.cpp \ tools/vtoolspline.cpp \ - dialogs/dialogspline.cpp + dialogs/dialogspline.cpp \ + tools/vtoolarc.cpp \ + dialogs/dialogarc.cpp HEADERS += mainwindow.h \ widgets/vmaingraphicsscene.h \ @@ -87,7 +89,9 @@ HEADERS += mainwindow.h \ geometry/varc.h \ widgets/vcontrolpointspline.h \ tools/vtoolspline.h \ - dialogs/dialogspline.h + dialogs/dialogspline.h \ + tools/vtoolarc.h \ + dialogs/dialogarc.h FORMS += mainwindow.ui \ dialogs/dialogsinglepoint.ui \ @@ -99,7 +103,8 @@ FORMS += mainwindow.ui \ dialogs/dialognormal.ui \ dialogs/dialogbisector.ui \ dialogs/dialoglineintersect.ui \ - dialogs/dialogspline.ui + dialogs/dialogspline.ui \ + dialogs/dialogarc.ui RESOURCES += \ icon.qrc \ diff --git a/container/vcontainer.cpp b/container/vcontainer.cpp index c78caaccd..99e53fc76 100644 --- a/container/vcontainer.cpp +++ b/container/vcontainer.cpp @@ -120,6 +120,7 @@ void VContainer::Clear(){ splines.clear(); arcs.clear(); lengthArcs.clear(); + lineArcs.clear(); } void VContainer::ClearIncrementTable(){ @@ -138,6 +139,10 @@ void VContainer::ClearLengthArcs(){ lengthArcs.clear(); } +void VContainer::ClearLineArcs(){ + lineArcs.clear(); +} + void VContainer::SetSize(qint32 size){ base["Сг"] = size; } @@ -176,6 +181,14 @@ qreal VContainer::FindVar(const QString &name, bool *ok)const{ *ok = true; return lengthLines.value(name); } + if(lengthArcs.contains(name)){ + *ok = true; + return lengthArcs.value(name); + } + if(lineArcs.contains(name)){ + *ok = true; + return lineArcs.value(name); + } *ok = false; return 0; } @@ -237,23 +250,26 @@ QString VContainer::GetNameLine(const qint64 &firstPoint, const qint64 &secondPo return QString("Line_%1_%2").arg(first.name(), second.name()); } +QString VContainer::GetNameLineArc(const qint64 &firstPoint, const qint64 &secondPoint) const{ + VPointF first = GetPoint(firstPoint); + VPointF second = GetPoint(secondPoint); + return QString("ArcLine_%1_%2").arg(first.name(), second.name()); +} + QString VContainer::GetNameSpline(const qint64 &firstPoint, const qint64 &secondPoint) const{ VPointF first = GetPoint(firstPoint); VPointF second = GetPoint(secondPoint); return QString("Spl_%1_%2").arg(first.name(), second.name()); } -QString VContainer::GetNameArc(const qint64 &firstPoint, const qint64 ¢erPoint, - const qint64 &secondPoint) const{ - VPointF first = GetPoint(firstPoint); - VPointF center = GetPoint(centerPoint); - VPointF second = GetPoint(secondPoint); - return QString("Arc_%1_%2_%3").arg(first.name(), center.name(), second.name()); +QString VContainer::GetNameArc(const qint64 ¢er, const qint64 &id) const{ + VPointF centerPoint = GetPoint(center); + return QString ("Arc(%1)%2").arg(centerPoint.name(), id); } void VContainer::AddLengthLine(const QString &name, const qreal &value){ Q_ASSERT(!name.isEmpty()); - lengthLines[name] = value/PrintDPI*25.4; + lengthLines[name] = value; } void VContainer::AddLengthSpline(const qint64 &firstPointId, const qint64 &secondPointId){ @@ -265,20 +281,21 @@ void VContainer::AddLengthSpline(const qint64 &firstPointId, const qint64 &secon void VContainer::AddLengthSpline(const QString &name, const qreal &value){ Q_ASSERT(!name.isEmpty()); - lengthSplines[name] = value/PrintDPI*25.4; + lengthSplines[name] = value; } -void VContainer::AddLengthArc(const qint64 &firstPointId, const qint64 ¢erPoint, - const qint64 &secondPointId){ - QString nameLine = GetNameArc(firstPointId, centerPoint, secondPointId); - VPointF firstPoint = GetPoint(firstPointId); - VPointF secondPoint = GetPoint(secondPointId); - AddLengthArc(nameLine, QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()).length()); +void VContainer::AddLengthArc(const qint64 ¢er, const qint64 &id){ + AddLengthArc(GetNameArc(center, id), GetArc(id).GetLength()); } void VContainer::AddLengthArc(const QString &name, const qreal &value){ Q_ASSERT(!name.isEmpty()); - lengthArcs[name] = value/PrintDPI*25.4; + lengthArcs[name] = value; +} + +void VContainer::AddLineArc(const QString &name, const qint32 &value){ + Q_ASSERT(!name.isEmpty()); + lineArcs[name] = value; } qreal VContainer::GetLine(const QString &name) const{ @@ -287,7 +304,18 @@ qreal VContainer::GetLine(const QString &name) const{ return lengthLines.value(name); } else { qCritical()<<"Не можу знайти лінію за імям = "< *VContainer::DataLengthArcs() const{ return &lengthArcs; } + +const QMap *VContainer::DataLineArcs() const{ + return &lineArcs; +} diff --git a/container/vcontainer.h b/container/vcontainer.h index eadfe56cf..0be810f59 100644 --- a/container/vcontainer.h +++ b/container/vcontainer.h @@ -28,6 +28,7 @@ public: VStandartTableCell GetStandartTableCell(const QString& name) const; VIncrementTableRow GetIncrementTableRow(const QString& name) const; qreal GetLine(const QString &name) const; + qint32 GetLineArc(const QString &name) const; VSpline GetSpline(qint64 id) const; VArc GetArc(qint64 id) const; qint64 getId(); @@ -37,15 +38,16 @@ public: void AddLengthLine(const QString &name, const qreal &value); void AddLengthSpline(const qint64 &firstPointId, const qint64 &secondPointId); void AddLengthSpline(const QString &name, const qreal &value); - void AddLengthArc(const qint64 &firstPointId, const qint64 ¢erPoint, const qint64 &secondPointId); + void AddLengthArc(const qint64 ¢er, const qint64 &id); void AddLengthArc(const QString &name, const qreal &value); + void AddLineArc(const QString &name, const qint32 &value); void AddLine(const qint64 &firstPointId, const qint64 &secondPointId); qint64 AddSpline(const VSpline& spl); qint64 AddArc(const VArc& arc); QString GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const; + QString GetNameLineArc(const qint64 &firstPoint, const qint64 &secondPoint) const; QString GetNameSpline(const qint64 &firstPoint, const qint64 &secondPoint) const; - QString GetNameArc(const qint64 &firstPoint, const qint64 ¢erPoint, - const qint64 &secondPoint) const; + QString GetNameArc(const qint64 ¢er, const qint64 &id) const; void UpdatePoint(qint64 id, const VPointF& point); void UpdateSpline(qint64 id, const VSpline& spl); void UpdateArc(qint64 id, const VArc& arc); @@ -58,6 +60,7 @@ public: void ClearLengthLines(); void ClearLengthSplines(); void ClearLengthArcs(); + void ClearLineArcs(); void SetSize(qint32 size); void SetGrowth(qint32 growth); qint32 size() const; @@ -75,6 +78,7 @@ public: const QMap *DataLengthLines() const; const QMap *DataLengthSplines() const; const QMap *DataLengthArcs() const; + const QMap *DataLineArcs() const; private: qint64 _id; QMap base; @@ -82,6 +86,7 @@ private: QMap standartTable; QMap incrementTable; QMap lengthLines; + QMap lineArcs; QMap splines; QMap lengthSplines; QMap arcs; diff --git a/cursor.qrc b/cursor.qrc index a43af671e..afd4b988a 100644 --- a/cursor.qrc +++ b/cursor.qrc @@ -9,5 +9,6 @@ cursor/bisector_cursor.png cursor/intersect_cursor.png cursor/spline_cursor.png + cursor/arc_cursor.png diff --git a/cursor/arc_cursor.png b/cursor/arc_cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..294bc953ea66efca187f656ba5f950155b2b70c2 GIT binary patch literal 1276 zcmVVl&|00006VoOIv0RI60 z0RN!9r;`8x010qNS#tmY3ljhU3ljkVnw%H_000McNliru-3SE-I6KAxUHAY106}y` zSad^gZEa<4bO1wAML|?gQaT`KWG!lNWoICEF)lD5D0OpbZf77#N=G0{P(?=|b~Z98 zEFf`pVQgu1c_2L?IWP*aMOc#n00cZqL_t(Y$HkR@NYr;2$6ufC-E~Yo)1&EWN5pb6 z2PYmAOf23z;k6++W6=MxKjuH~cdVeuWYK~({G-W~+7<;d-E7v1 zbnQw{g`J*$zxRFihkcK8S!8;BZKQz~h&Cz@dxOiWBjLqmfYhCxF^13Px?Se@WYRcx8f zW+N7h0jT50j{{IyS-JYKF9o?_7>EcW5*MRu*RBD$%gf6*uIi{Ix+OSDskmGJoKB~B zy%zpaxV*EjrK5&5@FlLSJ9srgP`cxwdTCGPZT=*1IcexTT<9DiNg=BO@aO z0)dgKsVUOa)87L=S~boel#GaAnkFK`(9jT}P>7kCnR)BYg$oxRJ@~`AeJM)pcKae4 zOw**dxA$OOUEQCD4<8=gym|A=Ikyt~Z*qoV-1nxhug?v*Js!{FHJr_6i;Ij>3ez-k zxm;3QT&yCI$Rfov3?r_5B7&~#0Qh{q-txZshU?`e(6O& zaNRV`lfPWLq;CIpi}BDXKlOjlfsQUVJ-d;@Lcg*D%+D|A!}|5>RcB|X7vRvLLyxW5 zxt^>jup1Z#KK%RcncH>uO{+U)9z}d5B&j3e6%@!*1<&OzU)vwWiu`_ZHh5T<;Q}}fyy{9z!Ik94nPR-=4825Mn;B8U+coT#z`<3Oitz7t1CHu<~xdfB`BqafLjFx&ucZ? mYi*U=UQ;K!yQzQUb^ZlxyxI{EQ4Np)0000listWidget, &QListWidget::itemDoubleClicked, this, &DialogAlongLine::PutVal); connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogAlongLine::ValChenged); - ShowBase(); + ShowVariable(data->DataBase()); connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogAlongLine::SizeGrowth); connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogAlongLine::StandartTable); connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogAlongLine::Increments); diff --git a/dialogs/dialogarc.cpp b/dialogs/dialogarc.cpp new file mode 100644 index 000000000..66371e557 --- /dev/null +++ b/dialogs/dialogarc.cpp @@ -0,0 +1,189 @@ +#include "dialogarc.h" +#include "ui_dialogarc.h" +#include "../container/calculator.h" + +DialogArc::DialogArc(const VContainer *data, QWidget *parent) : + DialogTool(data, parent), ui(new Ui::DialogArc) +{ + ui->setupUi(this); + flagRadius = false; + flagF1 = false; + flagF2 = false; + + timerRadius = new QTimer(this); + connect(timerRadius, &QTimer::timeout, this, &DialogArc::EvalRadius); + + timerF1 = new QTimer(this); + connect(timerF1, &QTimer::timeout, this, &DialogArc::EvalF1); + + timerF2 = new QTimer(this); + connect(timerF2, &QTimer::timeout, this, &DialogArc::EvalF2); + + bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + connect(bOk, &QPushButton::clicked, this, &DialogArc::DialogAccepted); + + QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); + connect(bCansel, &QPushButton::clicked, this, &DialogArc::DialogRejected); + FillComboBoxPoints(ui->comboBoxBasePoint); + + CheckState(); + + listWidget = ui->listWidget; + labelDescription = ui->labelDescription; + radioButtonSizeGrowth = ui->radioButtonSizeGrowth; + radioButtonStandartTable = ui->radioButtonStandartTable; + radioButtonIncrements = ui->radioButtonIncrements; + radioButtonLengthLine = ui->radioButtonLengthLine; + + connect(ui->toolButtonPutHereRadius, &QPushButton::clicked, this, &DialogArc::PutRadius); + connect(ui->toolButtonPutHereF1, &QPushButton::clicked, this, &DialogArc::PutF1); + connect(ui->toolButtonPutHereF1, &QPushButton::clicked, this, &DialogArc::PutF1); + connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogArc::ValChenged); + + ShowVariable(data->DataBase()); + connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogArc::SizeGrowth); + connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogArc::StandartTable); + connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogArc::Increments); + connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogArc::LengthLines); + connect(ui->radioButtonLineArcs, &QRadioButton::clicked, this, &DialogArc::LineArcs); + + connect(ui->toolButtonEqualRadius, &QPushButton::clicked, this, &DialogArc::EvalRadius); + connect(ui->toolButtonEqualF1, &QPushButton::clicked, this, &DialogArc::EvalF1); + connect(ui->toolButtonEqualF2, &QPushButton::clicked, this, &DialogArc::EvalF2); + + connect(ui->lineEditRadius, &QLineEdit::textChanged, this, &DialogArc::RadiusChanged); + connect(ui->lineEditF1, &QLineEdit::textChanged, this, &DialogArc::F1Changed); + connect(ui->lineEditF2, &QLineEdit::textChanged, this, &DialogArc::F2Changed); +} + +qint64 DialogArc::GetCenter() const{ + return center; +} + +void DialogArc::GetCenter(const qint64 &value){ + center = value; + ChangeCurrentData(ui->comboBoxBasePoint, center); +} + +QString DialogArc::GetF2() const{ + return f2; +} + +void DialogArc::GetF2(const QString &value){ + f2 = value; + ui->lineEditF2->setText(f2); +} + +QString DialogArc::GetF1() const{ + return f1; +} + +void DialogArc::GetF1(const QString &value){ + f1 = value; + ui->lineEditF1->setText(f1); +} + +QString DialogArc::GetRadius() const{ + return radius; +} + +void DialogArc::GetRadius(const QString &value){ + radius = value; + ui->lineEditRadius->setText(radius); +} + +DialogArc::~DialogArc(){ +delete ui; +} + +void DialogArc::ChoosedObject(qint64 id, Scene::Type type){ + if(type == Scene::Point){ + VPointF point = data->GetPoint(id); + ChangeCurrentText(ui->comboBoxBasePoint, point.name()); + this->show(); + } +} + +void DialogArc::DialogAccepted(){ + radius = ui->lineEditRadius->text(); + f1 = ui->lineEditF1->text(); + f2 = ui->lineEditF2->text(); + qint32 index = ui->comboBoxBasePoint->currentIndex(); + center = qvariant_cast(ui->comboBoxBasePoint->itemData(index)); + emit DialogClosed(QDialog::Accepted); +} + +void DialogArc::ValChenged(int row){ + if(ui->listWidget->count() == 0){ + return; + } + QListWidgetItem *item = ui->listWidget->item( row ); + if(ui->radioButtonLineArcs->isChecked()){ + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLineArc(item->text())) + .arg("Значення кута лінії."); + ui->labelDescription->setText(desc); + return; + } + DialogTool::ValChenged(row); +} + +void DialogArc::PutRadius(){ + PutValHere(ui->lineEditRadius, ui->listWidget); +} + +void DialogArc::PutF1(){ + PutValHere(ui->lineEditF1, ui->listWidget); +} + +void DialogArc::PutF2(){ + PutValHere(ui->lineEditF2, ui->listWidget); +} + +void DialogArc::LineArcs(){ + ShowLineArcs(); +} + +void DialogArc::RadiusChanged(){ + ValFormulaChanged(flagRadius, ui->lineEditRadius, timerRadius); +} + +void DialogArc::F1Changed(){ + ValFormulaChanged(flagF1, ui->lineEditF1, timerF1); +} + +void DialogArc::F2Changed(){ + ValFormulaChanged(flagF2, ui->lineEditF2, timerF2); +} + +void DialogArc::CheckState(){ + Q_CHECK_PTR(bOk); + bOk->setEnabled(flagRadius & flagF1 & flagF2); +} + +void DialogArc::EvalRadius(){ + Eval(ui->lineEditRadius, flagRadius, timerRadius, ui->labelResultRadius); +} + +void DialogArc::EvalF1(){ + Eval(ui->lineEditF1, flagF1, timerF1, ui->labelResultF1); +} + +void DialogArc::EvalF2(){ + Eval(ui->lineEditF2, flagF2, timerF2, ui->labelResultF2); +} + +void DialogArc::ShowLineArcs(){ + disconnect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogArc::ValChenged); + ui->listWidget->clear(); + connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogArc::ValChenged); + const QMap *lineArcsTable = data->DataLineArcs(); + QMapIterator i(*lineArcsTable); + while (i.hasNext()) { + i.next(); + QListWidgetItem *item = new QListWidgetItem(i.key()); + + item->setFont(QFont("Times", 12, QFont::Bold)); + ui->listWidget->addItem(item); + } + ui->listWidget->setCurrentRow (0); +} diff --git a/dialogs/dialogarc.h b/dialogs/dialogarc.h new file mode 100644 index 000000000..a147335d8 --- /dev/null +++ b/dialogs/dialogarc.h @@ -0,0 +1,60 @@ +#ifndef DIALOGARC_H +#define DIALOGARC_H + +#include "dialogtool.h" +#include "../container/vcontainer.h" + +namespace Ui { +class DialogArc; +} + +class DialogArc : public DialogTool +{ + Q_OBJECT +public: + explicit DialogArc(const VContainer *data, QWidget *parent = 0); + ~DialogArc(); + qint64 GetCenter() const; + void GetCenter(const qint64 &value); + + QString GetRadius() const; + void GetRadius(const QString &value); + + QString GetF1() const; + void GetF1(const QString &value); + + QString GetF2() const; + void GetF2(const QString &value); + +public slots: + virtual void ChoosedObject(qint64 id, Scene::Type type); + virtual void DialogAccepted(); + virtual void ValChenged(int row); + void PutRadius(); + void PutF1(); + void PutF2(); + void LineArcs(); + void RadiusChanged(); + void F1Changed(); + void F2Changed(); +protected: + virtual void CheckState(); +private: + Ui::DialogArc *ui; + bool flagRadius; + bool flagF1; + bool flagF2; + QTimer *timerRadius; + QTimer *timerF1; + QTimer *timerF2; + qint64 center; + QString radius; + QString f1; + QString f2; + void EvalRadius(); + void EvalF1(); + void EvalF2(); + void ShowLineArcs(); +}; + +#endif // DIALOGARC_H diff --git a/dialogs/dialogarc.ui b/dialogs/dialogarc.ui new file mode 100644 index 000000000..1e3d26380 --- /dev/null +++ b/dialogs/dialogarc.ui @@ -0,0 +1,419 @@ + + + DialogArc + + + + 0 + 0 + 501 + 448 + + + + Dialog + + + + + + + + + 0 + 0 + + + + Радіус + + + + + + + + 0 + 0 + + + + + + + + ... + + + + :/icon/24x24/putHereLeft.png:/icon/24x24/putHereLeft.png + + + + 24 + 24 + + + + + + + + ... + + + + :/icon/24x24/equal.png:/icon/24x24/equal.png + + + + 24 + 24 + + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + _ + + + + + + + + + + + + 0 + 0 + + + + Перший кут градус + + + + + + + + 0 + 0 + + + + + + + + ... + + + + :/icon/24x24/putHereLeft.png:/icon/24x24/putHereLeft.png + + + + 24 + 24 + + + + + + + + ... + + + + :/icon/24x24/equal.png:/icon/24x24/equal.png + + + + 24 + 24 + + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + _ + + + + + + + + + + + + 0 + 0 + + + + Другий кут градус + + + + + + + + 0 + 0 + + + + + + + + ... + + + + :/icon/24x24/putHereLeft.png:/icon/24x24/putHereLeft.png + + + + 24 + 24 + + + + + + + + ... + + + + :/icon/24x24/equal.png:/icon/24x24/equal.png + + + + 24 + 24 + + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + _ + + + + + + + + + + + + + + + + 0 + 0 + + + + Центр + + + + + + + + + + + + + + Вхідні данні + + + + + + + Розмір і зріст + + + true + + + + + + + Стандартна таблиця + + + + + + + Прибавки + + + + + + + true + + + Довжини ліній + + + + + + + true + + + Довжини дуг + + + + + + + true + + + Довжини сплайнів + + + + + + + true + + + Кути ліній + + + + + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogArc + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogArc + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/dialogs/dialogbisector.cpp b/dialogs/dialogbisector.cpp index 909d463be..befc62f3d 100644 --- a/dialogs/dialogbisector.cpp +++ b/dialogs/dialogbisector.cpp @@ -30,7 +30,7 @@ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent) : connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogBisector::PutVal); connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogBisector::ValChenged); - ShowBase(); + ShowVariable(data->DataBase()); connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogBisector::SizeGrowth); connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogBisector::StandartTable); connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogBisector::Increments); diff --git a/dialogs/dialogendline.cpp b/dialogs/dialogendline.cpp index c8ef58f23..26ea30158 100644 --- a/dialogs/dialogendline.cpp +++ b/dialogs/dialogendline.cpp @@ -49,7 +49,7 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) : connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogEndLine::PutVal); connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged); - ShowBase(); + ShowVariable(data->DataBase()); connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogEndLine::SizeGrowth); connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogEndLine::StandartTable); connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogEndLine::Increments); diff --git a/dialogs/dialognormal.cpp b/dialogs/dialognormal.cpp index 4119a3882..d70993def 100644 --- a/dialogs/dialognormal.cpp +++ b/dialogs/dialognormal.cpp @@ -47,7 +47,7 @@ DialogNormal::DialogNormal(const VContainer *data, QWidget *parent) : connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogNormal::PutVal); connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogNormal::ValChenged); - ShowBase(); + ShowVariable(data->DataBase()); connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogNormal::SizeGrowth); connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogNormal::StandartTable); connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogNormal::Increments); diff --git a/dialogs/dialogshoulderpoint.cpp b/dialogs/dialogshoulderpoint.cpp index a1fbdf152..76d686aa9 100644 --- a/dialogs/dialogshoulderpoint.cpp +++ b/dialogs/dialogshoulderpoint.cpp @@ -30,7 +30,7 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogShoulderPoint::PutVal); connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogShoulderPoint::ValChenged); - ShowBase(); + ShowVariable(data->DataBase()); connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogShoulderPoint::SizeGrowth); connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogShoulderPoint::StandartTable); connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogShoulderPoint::Increments); diff --git a/dialogs/dialogtool.cpp b/dialogs/dialogtool.cpp index 2e9aad21a..7caf61c46 100644 --- a/dialogs/dialogtool.cpp +++ b/dialogs/dialogtool.cpp @@ -24,8 +24,7 @@ DialogTool::DialogTool(const VContainer *data, QWidget *parent):QDialog(parent){ radioButtonLengthLine = 0; } -DialogTool::~DialogTool() -{ +DialogTool::~DialogTool(){ } void DialogTool::closeEvent(QCloseEvent *event){ @@ -38,12 +37,9 @@ void DialogTool::showEvent(QShowEvent *event){ if( event->spontaneous() ){ return; } - if(isInitialized){ return; } - - // do your init stuff here isInitialized = true;//перший показ вікна вже відбувся } @@ -71,70 +67,6 @@ QString DialogTool::GetTypeLine(const QComboBox *box) const{ } } -void DialogTool::ShowBase(){ - Q_CHECK_PTR(listWidget); - disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); - listWidget->clear(); - connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); - const QMap *base = data->DataBase(); - QMapIterator i(*base); - while (i.hasNext()) { - i.next(); - QListWidgetItem *item = new QListWidgetItem(i.key()); - item->setFont(QFont("Times", 12, QFont::Bold)); - listWidget->addItem(item); - } - listWidget->setCurrentRow (0); -} - -void DialogTool::ShowStandartTable(){ - Q_CHECK_PTR(listWidget); - disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); - listWidget->clear(); - connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); - const QMap *standartTable = data->DataStandartTable(); - QMapIterator i(*standartTable); - while (i.hasNext()) { - i.next(); - QListWidgetItem *item = new QListWidgetItem(i.key()); - item->setFont(QFont("Times", 12, QFont::Bold)); - listWidget->addItem(item); - } - listWidget->setCurrentRow (0); -} - -void DialogTool::ShowIncrementTable(){ - Q_CHECK_PTR(listWidget); - disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); - listWidget->clear(); - connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); - const QMap *incrementTable = data->DataIncrementTable(); - QMapIterator i(*incrementTable); - while (i.hasNext()) { - i.next(); - QListWidgetItem *item = new QListWidgetItem(i.key()); - item->setFont(QFont("Times", 12, QFont::Bold)); - listWidget->addItem(item); - } - listWidget->setCurrentRow (0); -} - -void DialogTool::ShowLengthLines(){ - Q_CHECK_PTR(listWidget); - disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); - listWidget->clear(); - connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); - const QMap *linesTable = data->DataLengthLines(); - QMapIterator i(*linesTable); - while (i.hasNext()) { - i.next(); - QListWidgetItem *item = new QListWidgetItem(i.key()); - item->setFont(QFont("Times", 12, QFont::Bold)); - listWidget->addItem(item); - } - listWidget->setCurrentRow (0); -} - void DialogTool::SetupTypeLine(QComboBox *box, const QString &value){ if(value == "hair"){ qint32 index = box->findText("Лінія"); @@ -164,6 +96,47 @@ void DialogTool::ChangeCurrentData(QComboBox *box, const qint64 &value){ } } +void DialogTool::PutValHere(QLineEdit *lineEdit, QListWidget *listWidget){ + Q_CHECK_PTR(lineEdit); + Q_CHECK_PTR(listWidget); + QListWidgetItem *item = listWidget->currentItem(); + QString val = item->text(); + lineEdit->setText(lineEdit->text().append(val)); +} + +void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer){ + Q_CHECK_PTR(edit); + Q_CHECK_PTR(timer); + if(edit->text().isEmpty()){ + flag = false; + CheckState(); + return; + } + timer->start(1000); +} + +void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label){ + Q_CHECK_PTR(edit); + Q_CHECK_PTR(timer); + Q_CHECK_PTR(label); + if(edit->text().isEmpty()){ + flag = false; + } else { + Calculator cal(data); + QString errorMsg; + qreal result = cal.eval(edit->text(),&errorMsg); + if(!errorMsg.isEmpty()){ + label->setText("Помилка."); + flag = false; + } else { + label->setText(QString().setNum(result)); + flag = true; + } + } + CheckState(); + timer->stop(); +} + void DialogTool::CheckState(){ Q_CHECK_PTR(bOk); bOk->setEnabled(flagFormula & flagName); @@ -199,12 +172,7 @@ void DialogTool::DialogRejected(){ void DialogTool::FormulaChanged(){ QLineEdit* edit = qobject_cast(sender()); if(edit){ - if(edit->text().isEmpty()){ - flagFormula = false; - CheckState(); - return; - } - timerFormula->start(1000); + ValFormulaChanged(flagFormula, edit, timerFormula); } } @@ -251,46 +219,27 @@ void DialogTool::ArrowRightDown(){ void DialogTool::EvalFormula(){ Q_CHECK_PTR(lineEditFormula); Q_CHECK_PTR(labelResultCalculation); - if(lineEditFormula->text().isEmpty()){ - flagFormula = false; - } else { - Calculator cal(data); - QString errorMsg; - qreal result = cal.eval(lineEditFormula->text(),&errorMsg); - if(!errorMsg.isEmpty()){ - labelResultCalculation->setText("Помилка."); - flagFormula = false; - } else { - labelResultCalculation->setText(QString().setNum(result)); - flagFormula = true; - } - } - CheckState(); - timerFormula->stop(); + Eval(lineEditFormula, flagFormula, timerFormula, labelResultCalculation); } void DialogTool::SizeGrowth(){ - ShowBase(); + ShowVariable(data->DataBase()); } void DialogTool::StandartTable(){ - ShowStandartTable(); + ShowVariable(data->DataStandartTable()); } void DialogTool::LengthLines(){ - ShowLengthLines(); + ShowVariable(data->DataLengthLines()); } void DialogTool::Increments(){ - ShowIncrementTable(); + ShowVariable(data->DataIncrementTable()); } void DialogTool::PutHere(){ - Q_CHECK_PTR(lineEditFormula); - Q_CHECK_PTR(listWidget); - QListWidgetItem *item = listWidget->currentItem(); - QString val = item->text(); - lineEditFormula->setText(lineEditFormula->text().append(val)); + PutValHere(lineEditFormula, listWidget); } void DialogTool::PutVal(QListWidgetItem *item){ @@ -305,6 +254,7 @@ void DialogTool::ValChenged(int row){ Q_CHECK_PTR(radioButtonSizeGrowth); Q_CHECK_PTR(radioButtonStandartTable); Q_CHECK_PTR(radioButtonIncrements); + Q_CHECK_PTR(radioButtonLengthLine); if(listWidget->count() == 0){ return; } @@ -318,23 +268,27 @@ void DialogTool::ValChenged(int row){ QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->size()).arg("Розмір"); labelDescription->setText(desc); } + return; } if(radioButtonStandartTable->isChecked()){ VStandartTableCell stable = data->GetStandartTableCell(item->text()); QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueStandartTableCell(item->text())) .arg(stable.GetDescription()); labelDescription->setText(desc); + return; } if(radioButtonIncrements->isChecked()){ VIncrementTableRow itable = data->GetIncrementTableRow(item->text()); QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueIncrementTableRow(item->text())) .arg(itable.getDescription()); labelDescription->setText(desc); + return; } if(radioButtonLengthLine->isChecked()){ QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLine(item->text())) .arg("Довжина лінії"); labelDescription->setText(desc); + return; } } @@ -343,12 +297,28 @@ void DialogTool::UpdateList(){ Q_CHECK_PTR(radioButtonStandartTable); Q_CHECK_PTR(radioButtonIncrements); if(radioButtonSizeGrowth->isChecked()){ - ShowBase(); + ShowVariable(data->DataBase()); } if(radioButtonStandartTable->isChecked()){ - ShowStandartTable(); + ShowVariable(data->DataStandartTable()); } if(radioButtonIncrements->isChecked()){ - ShowIncrementTable(); + ShowVariable(data->DataIncrementTable()); } } + +export template +void DialogTool::ShowVariable(const QMap *var){ + Q_CHECK_PTR(listWidget); + disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + listWidget->clear(); + connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + QMapIterator i(*var); + while (i.hasNext()) { + i.next(); + QListWidgetItem *item = new QListWidgetItem(i.key()); + item->setFont(QFont("Times", 12, QFont::Bold)); + listWidget->addItem(item); + } + listWidget->setCurrentRow (0); +} diff --git a/dialogs/dialogtool.h b/dialogs/dialogtool.h index ba744b1bb..a4e2a0144 100644 --- a/dialogs/dialogtool.h +++ b/dialogs/dialogtool.h @@ -42,7 +42,7 @@ public slots: void Increments(); void PutHere(); void PutVal(QListWidgetItem * item); - void ValChenged(int row); + virtual void ValChenged(int row); void UpdateList(); protected: const VContainer *data; @@ -66,13 +66,13 @@ protected: void FillComboBoxTypeLine(QComboBox *box) const; virtual void CheckState(); QString GetTypeLine(const QComboBox *box)const; - void ShowBase(); - void ShowStandartTable(); - void ShowIncrementTable(); - void ShowLengthLines(); + template void ShowVariable(const QMap *var); void SetupTypeLine(QComboBox *box, const QString &value); void ChangeCurrentText(QComboBox *box, const QString &value); void ChangeCurrentData(QComboBox *box, const qint64 &value); + void PutValHere(QLineEdit *lineEdit, QListWidget *listWidget); + void ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer * timer); + void Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label); }; #endif // DIALOGTOOL_H diff --git a/geometry/varc.cpp b/geometry/varc.cpp index c201bb4b9..e21afe619 100644 --- a/geometry/varc.cpp +++ b/geometry/varc.cpp @@ -5,36 +5,55 @@ VArc::VArc (){ f1 = 0; + formulaF1 = QString(); f2 = 0; - length = 0; + formulaF2 = QString(); radius = 0; + formulaRadius = QString(); center = 0; - p1 = QPointF( 0, 0 ); - p2 = QPointF( 0, 0 ); points = 0; } -VArc::VArc (const QMap *points, qint64 center, qreal radius, qreal f1, qreal f2 ){ +VArc::VArc (const QMap *points, qint64 center, qreal radius, QString formulaRadius, + qreal f1, QString formulaF1, qreal f2, QString formulaF2 ){ this->points = points; - ModifiArc( center, radius, f1, f2 ); + this->f1 = f1; + this->formulaF1 = formulaF1; + this->f2 = f2; + this->formulaF2 = formulaF2; + this->radius = radius; + this->formulaRadius = formulaRadius; + this->center = center; } -qreal VArc::GetF1 () const{ +qreal VArc::GetF1() const{ return f1; } -qreal VArc::GetF2 () const{ +QString VArc::GetFormulaF1() const{ + return formulaF1; +} + +qreal VArc::GetF2() const{ return f2; } -qreal VArc::GetLength () const{ - return length; +QString VArc::GetFormulaF2() const{ + return formulaF2; } -qreal VArc::GetRadius () const{ +qreal VArc::GetLength () const{ + return M_PI * radius/180 * (f2-f1); +} + +qreal VArc::GetRadius() const{ return radius; } +QString VArc::GetFormulaRadius() const{ + return formulaRadius; +} + qint64 VArc::GetCenter() const{ return center; } @@ -50,245 +69,30 @@ QPointF VArc::GetCenterPoint() const{ } QPointF VArc::GetP1() const{ - return p1; + QPointF p1 ( GetCenterPoint().x () + radius, GetCenterPoint().y () ); + QLineF centerP1(GetCenterPoint(), p1); + centerP1.setAngle(f1); + return centerP1.p2(); } QPointF VArc::GetP2 () const{ - return p2; + QPointF p2 ( GetCenterPoint().x () + radius, GetCenterPoint().y () ); + QLineF centerP2(GetCenterPoint(), p2); + centerP2.setAngle(f2); + return centerP2.p2(); } const QMap *VArc::GetDataPoints() const{ return points; } -void VArc::ModifiArc (qint64 center, qreal radius, qreal f1, qreal f2 ){ - this->f1 = f1; - this->f2 = f2; - this->radius = radius; - this->center = center; - QPointF p1 ( GetCenterPoint().x () + radius, GetCenterPoint().y () ); - QLineF centerP1(GetCenterPoint(), p1); - centerP1.setAngle(f1); - p1 = centerP1.p2(); - QPointF p2 ( GetCenterPoint().x () + radius, GetCenterPoint().y () ); - QLineF centerP2(GetCenterPoint(), p2); - centerP2.setAngle(f2); - p2 = centerP2.p2(); - this->p1 = p1; - this->p2 = p2; - // визначимо довжину дуги за формулою. - // МОЖЛИВО НЕ ПРАВИЛЬНО. ПОТРІБНО ПЕРЕВІРИТИ ФОРМУЛУ, ОСКІЛЬКИ КУТ ПОВЕРТАЄТЬСЯ В ГРАДУСАХ!!!!! - //qreal ang = AngleArc ( f1, f2 ) ; - qreal ang = centerP1.angleTo(centerP2); - this->length = ang * radius * M_PI/180; - //qDebug()<<"ang = "<center = QPointF( center.x()+mx, center.y()+my ); -// this->p1 = QPointF( p1.x()+mx, p1.y()+my ); -// this->p2 = QPointF( p2.x()+mx, p2.y()+my ); -//} - -//void VArc::RotationArc (QPointF pRotate, qreal angle ){ -// QLineF pRotateCenter( pRotate, center ); -// pRotateCenter.setAngle( angle ); -// center = pRotateCenter.p2(); -// QLineF pRotateP1( pRotate, p1 ); -// pRotateP1.setAngle( angle ); -// p1 = pRotateP1.p2(); -// QLineF pRotateP2( pRotate, p2 ); -// pRotateP2.setAngle( angle ); -// p2 = pRotateP2.p2(); -// QLineF centerP1 ( center, p1 ); -// QLineF centerP2 ( center, p2 ); -// f1 = centerP1.angle(); -// f2 = centerP2.angle(); -//} - -VSpline VArc::SplOfArc ( qint32 number ) const{ - qint32 n = NumberSplOfArc (); - if( number > n ){ - throw "Дуга не складається з такої кількості сплайнів."; - } - qreal f1 = GetF1 (); - qreal f2 = GetF2 (); - qint32 i; - for ( i = 0; i < n; ++i ){ - if ( i == n - 1 ){ - f2 = GetF2 (); - } else { - if ( f1 + 90 > 360 ){ - f2 = f1 + 90 - 360; - } else { - f2 = f1 + 90; - } - } - qreal anglF1, anglF2; - if ( f1 + 90 > 360 ){ - anglF1 = f1 + 90 - 360 ; - } else { - anglF1 = f1 + 90 ; - } - if ( f2 - 90 < 0 ){ - anglF2 = 360 + f2 - 90 ; - } else { - anglF2 = f2 - 90 ; - } - if ( i + 1 == number ){ -// return VSpline (GetDataPoints(), GetP1 (), GetP2 (), anglF1, anglF2, 1., 1., 1. ); - f1 = f2; - } - } - return VSpline(); -} - -//void VArc::CutArc ( qreal length, VArc &arcFir, VArc &arcSec ) const{ -// if ( length > GetLength () ){ -// qDebug()<<"Не правильна довжина дуги/n"; -// exit(-1); -// } -// qreal angle; -// angle = GetF1 () + (length * 180) / (radius * M_PI); -// arcFir.ModifiArc ( GetCenter (), GetRadius (), GetF1 (), angle ); -// arcSec.ModifiArc ( GetCenter (), GetRadius (), angle, GetF2 () ); -//} - -//void VArc::CutArc ( QPointF point, VArc &arcFir, VArc &arcSec ) const{ -// VArc arc = VArc(center,radius, f1, QLineF(center, point).angle()); -// if(this->length VArc::GetPoints () const{ - QVector points; - qint32 numberSpl = NumberSplOfArc(); - for(qint32 i = 1; i <= numberSpl; ++i){ - VSpline spl = SplOfArc ( i ); - points< GetRadius() + CO.length() ){ - throw"Немає перетину кіл для знаходження дотичних."; - } - if ( d < qAbs(GetRadius() - CO.length()) ){ - throw"Не можу знайти дотичну. Одне коло знаходиться в іншому."; - } - qreal a = (pow(GetRadius(),2) - pow(CO.length(),2) + pow(d,2) ) / (2*d); - qreal h = sqrt(pow(GetRadius(),2) - pow(a,2)); - qreal x2 = GetCenterPoint().x() + a * (O.x() - GetCenterPoint().x())/d; - qreal y2 = GetCenterPoint().y() + a * (O.y() - GetCenterPoint().y())/d; - if(tan == VArc::FirstTangent){ - qreal x3 = x2 - h * ( O.y() - GetCenterPoint().y() ) / d; - qreal y3 = y2 + h * ( O.x() - GetCenterPoint().x() ) / d; - return QPointF(x3,y3); - } else { - qreal x3 = x2 + h * ( O.y() - GetCenterPoint().y() ) / d; - qreal y3 = y2 - h * ( O.x() - GetCenterPoint().x() ) / d; - return QPointF(x3,y3); - } -} - -bool VArc::Contains(const QPointF P)const{ - QVector points = GetPoints (); - for(qint32 i=0; i< points.size();++i){ - if((qint32)points[i].x()==(qint32)P.x() && (qint32)points[i].y()==(qint32)P.y()){ - return true; - } - } - return false; -} - -QPointF VArc::PutAlongArc(qreal length) const{ - if(GetLength()ModifiArc ( Center, radius, QLineF(Center,P2).angle(), QLineF(Center,P1).angle() ); -//} diff --git a/geometry/varc.h b/geometry/varc.h index 1e16bcfec..cda583066 100644 --- a/geometry/varc.h +++ b/geometry/varc.h @@ -1,7 +1,6 @@ #ifndef VARC_H #define VARC_H -#include "vspline.h" #include #include #include @@ -12,7 +11,6 @@ */ class VArc{ public: - enum Tangent_e { FirstTangent, SecondTangent }; /** * @brief VArc конструктор по замовчуванню. */ @@ -24,17 +22,19 @@ public: * @param f1 початковий кут в градусах. * @param f2 кінцевий кут в градусах. */ - VArc ( const QMap *points, qint64 center, qreal radius, qreal f1, - qreal f2 ); + VArc (const QMap *points, qint64 center, qreal radius, QString formulaRadius, + qreal f1, QString formulaF1, qreal f2 , QString formulaF2); /** * @brief GetF1 повертає початковий кут дуги. * @return повертає кут в градусах. */ + QString GetFormulaF1 () const; qreal GetF1 () const; /** * @brief GetF2 повертає кінцевий кут дуги. * @return повертає кут в градусах. */ + QString GetFormulaF2 () const;\ qreal GetF2 () const; /** * @brief GetLength повертає довжину дуги. @@ -45,6 +45,7 @@ public: * @brief GetRadius повертає радіус дуги. * @return повертає радіус дуги. */ + QString GetFormulaRadius () const; qreal GetRadius () const; /** * @brief GetCenter повертає точку центра дуги. @@ -63,130 +64,32 @@ public: */ QPointF GetP2 () const; const QMap *GetDataPoints() const; - /** - * @brief ModifiArc змінює параметри дуги. - * @param center новий центр дуги. - * @param radius новий радіус дуги. - * @param f1 новий початковий кут в градусах. - * @param f2 новий кінцевий кут в градусах. - */ - void ModifiArc (qint64 center, qreal radius, qreal f1, qreal f2 ); - /** - * @brief BiasArc зміщує дугу. - * @param mx зміщення по х координаті. - * @param my зміщення по у координаті. - */ -// void BiasArc ( qreal mx, qreal my ); - /** - * @brief RotationArc повертає дугу на кут проти годиникової стрілки відносно точки. - * @param pRotate точка відносно якої повертається. - * @param angle кут в градусах на який повертається в градусах. - */ -// void RotationArc ( QPointF pRotate, qreal angle ); - /** - * @brief SplOfArc повертає сплайн дуги за номером. - * @param number номер сплайна в дузі. - * @return сплайн. - */ - VSpline SplOfArc ( qint32 number ) const; - /** - * @brief CutArc розрізає дугу на дві дуги. - * @param length довжина першої дуги. - * @param arcFir перша дуга. - * @param arcSec друга дуга. - */ -// void CutArc ( qreal length, VArc &arcFir, VArc &arcSec ) const; - /** - * @brief CutArc розрізає дугу на дві дуги. - * @param point точка яка ділить дугу. - * @param arcFir перша дуга. - * @param arcSec друга дуга. - */ -// void CutArc ( QPointF point, VArc &arcFir, VArc &arcSec ) const; - /** - * @brief CrossingArcLine перевіряє перетин дуги і лінії. - * @param line лінія з якою шукаємо перетин. - * @param intersectionPoint точка перетину. - * @return результат перевірки на перетин. - */ - QLineF::IntersectType CrossingArcLine(const QLineF &line, QPointF *intersectionPoint) const; - /** - * @brief NumberSplOfArc метод шукає кілкість сплайнів які необхідні для відтворення такої дуги. - * @return кількість сплайнів. - */ - qint32 NumberSplOfArc () const; /** * @brief GetPath будує шлях по даній дузі. * @return повертає шлях. */ QPainterPath GetPath() const; - /** - * @brief GetPoints повертає набір точок по яких можна побудувати дугу. - * @return набір точок дуги. - */ - QVector - GetPoints () const; - /** - * @brief Tangent розраховує дотичну до дуги. - * @param P точка через, що не належить дузі, через яку проходить дотична. - * @param tan перша чи друга дотична. - * @return точку дотичної на дузі. - */ - QPointF Tangent(const QPointF P,VArc::Tangent_e tan = VArc::FirstTangent)const; - /** - * @brief Contains перевіряє чи точка належить дузі. - * @param P точка що перевіряється. - * @return true - належить дузі, false - не належить дузі. - */ - bool Contains(const QPointF P)const; - /** - * @brief PutAlongArc розміщує точку на дузі. - * @param length довжина від початку дуги. - * @return точка що лежить на дузі. - */ - QPointF PutAlongArc(qreal length) const; - /** - * @brief Mirror дзеркальне відображення дуги. - * @param Pmirror точка відносно якої відбувається дзеркалення. - */ -// void Mirror(const QPointF Pmirror); private: /** * @brief f1 початковий кут в градусах */ qreal f1; // початковий кут нахилу дуги (градуси) + QString formulaF1; /** * @brief f2 кінцевий кут в градусах */ qreal f2; // кінцевий кут нахилу дуги (градуси) - /** - * @brief length довжина дуги. - */ - qreal length; // довжина дуги + QString formulaF2; /** * @brief radius радіус дуги. */ qreal radius; + QString formulaRadius; /** * @brief center центральна точка дуги. */ qint64 center; - /** - * @brief p1 точка початку побудови дуги. - */ - QPointF p1; - /** - * @brief p2 кінцева точка побудови дуги. - */ - QPointF p2; const QMap *points; - /** - * @brief AngleArc визначає кут дуги. - * @param f1 початковий кут дуги в градусах. - * @param f2 кінцевий кут в градусах. - * @return повертає кут в градусах. - */ - qreal AngleArc(qreal f1, qreal f2 ) const; }; #endif // VARC_H diff --git a/icon.qrc b/icon.qrc index c3e3ef962..35d21353f 100644 --- a/icon.qrc +++ b/icon.qrc @@ -26,5 +26,7 @@ icon/32x32/bisector.png icon/32x32/intersect.png icon/32x32/spline.png + icon/32x32/arc.png + icon/24x24/putHereLeft.png diff --git a/icon/24x24/putHereLeft.png b/icon/24x24/putHereLeft.png new file mode 100644 index 0000000000000000000000000000000000000000..a69736efdc542f5b95b8d5ee6e0e06bc4815cebf GIT binary patch literal 1233 zcmV;?1TOoDP)o;E-Ld+m+m$QsXR zG@`_j$nMI4q$I~~Kv08h)~l+n_n!RvpP#ucOG2oL(Lg{%Faxs)#$kylV8j@@Cx<`j z_CSo0x~_S*c&C0m8jnQPrkxhZe~Jt;6-F z0b`6!sb+_ywEd_KHJf71?e3NsjXclE@|+~;foYp~8`ipdQ0zQa?Z|LExj*B{>`yJQUOWwTs!{&>(tcxW{VnASDujvnRvMgmfy~Fe8&pA6ABI$ra zZdt8vC~nqlZf?1`cg1G2IZjbSpk|Im0g04l!PV6}LM-TI30W@mhsu-3GoC+t#^Wz$ z#Cpry_gAEO#5u(*689B#T~ozCFhk7H1CsaTdB)jfv>c6clEm1QSM2sHOiJ>;@$}i} zeEZG6d2l{ukf*3da0Xt$DL62NC=fBQlQH$)GaL>{(?`?6ApO^ahm#j?{+e)kxuB|x z_Kf1a$B8G@fx4=Q78~-Z5;`uNkjCQqe}=J`ORA`mePfZ<)r*?3AnAAUb6C)BaFXoka)_R^=K z{>5k8T0XyDu)f(?*jG%)6S+4%M_UE{r~(KrP*b3H;5DV6jfiGqW?+JfAfhtN;O?NN zx?f9-fzXswgRTvX(wQcm7$>vqk!8`ki{;y+tNn{hKq;5fwOGsr)h`iTM#qy1^4H#0&AIOq5qYl=(vQ6;a{00000NkvXXu0mjf*&S8T literal 0 HcmV?d00001 diff --git a/icon/32x32/arc.png b/icon/32x32/arc.png new file mode 100644 index 0000000000000000000000000000000000000000..68927a4c7fa9516c3546e0d1dd996eb314c2b3ad GIT binary patch literal 441 zcmV;q0Y?6bP))yZ8VWgOSKru;_`e-~-r=Oa^7Oh%!i-ln}*&C8d!IjL+4)u z_8J7#*DFpj_!l2ye0VoEIQ=1ZS%Nu^Ek6DL_=B5vv7=sc6JT0(e$JE)&FlG@!p= z6eH1yg#=J7V-&XuVlo;ql>m;*=)y^Y7|tIoQJK%xUpR>DKzq`Gvogl8n;^n7lK|$R zIS_D#&)oBDbO(Czp6kF(G@v>8v8_dq;4`~Z)YBFXkemgj0G@JnYZ-w2<>jLcz+toolButtonSpline, &QToolButton::clicked, this, &MainWindow::ToolSpline); + connect(ui->toolButtonArc, &QToolButton::clicked, this, + &MainWindow::ToolArc); data = new VContainer; CreateManTableIGroup (); @@ -530,6 +533,62 @@ void MainWindow::ClosedDialogSpline(int result){ ArrowTool(); } +void MainWindow::ToolArc(bool checked){ + if(checked){ + CanselTool(); + tool = Tools::ArcTool; + QPixmap pixmap(":/cursor/arc_cursor.png"); + QCursor cur(pixmap, 2, 3); + ui->graphicsView->setCursor(cur); + helpLabel->setText("Виберіть точку центру."); + dialogArc = new DialogArc(data, this); + connect(scene, &VMainGraphicsScene::ChoosedObject, dialogArc, + &DialogArc::ChoosedObject); + connect(dialogArc, &DialogArc::DialogClosed, this, + &MainWindow::ClosedDialogArc); + } else { + ui->toolButtonSpline->setChecked(true); + } +} + +void MainWindow::ClosedDialogArc(int result){ + if(result == QDialog::Accepted){ + qint64 center = dialogArc->GetCenter(); + QString radius = dialogArc->GetRadius(); + QString f1 = dialogArc->GetF1(); + QString f2 = dialogArc->GetF2(); + + qreal calcRadius, calcF1, calcF2; + + Calculator cal(data); + QString errorMsg; + qreal result = cal.eval(radius, &errorMsg); + if(errorMsg.isEmpty()){ + calcRadius = result*PrintDPI/25.4; + } + + errorMsg.clear(); + result = cal.eval(f1, &errorMsg); + if(errorMsg.isEmpty()){ + calcF1 = result; + } + + errorMsg.clear(); + result = cal.eval(f2, &errorMsg); + if(errorMsg.isEmpty()){ + calcF2 = result; + } + + VArc arc = VArc(data->DataPoints(), center, calcRadius, radius, calcF1, f1, calcF2, f2 ); + qint64 id = data->AddArc(arc); + data->AddLengthArc(data->GetNameArc(center,id), arc.GetLength()); + VToolArc *toolArc = new VToolArc(doc, data, id, Tool::FromGui); + scene->addItem(toolArc); + connect(toolArc, &VToolArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + } + ArrowTool(); +} + void MainWindow::showEvent( QShowEvent *event ){ QMainWindow::showEvent( event ); if( event->spontaneous() ){ @@ -686,6 +745,12 @@ void MainWindow::CanselTool(){ scene->setFocus(Qt::OtherFocusReason); scene->clearSelection(); break; + case Tools::ArcTool: + delete dialogArc; + ui->toolButtonArc->setChecked(false); + scene->setFocus(Qt::OtherFocusReason); + scene->clearSelection(); + break; } } @@ -949,6 +1014,7 @@ void MainWindow::SetEnableTool(bool enable){ ui->toolButtonBisector->setEnabled(enable); ui->toolButtonLineIntersect->setEnabled(enable); ui->toolButtonSpline->setEnabled(enable); + ui->toolButtonArc->setEnabled(enable); } MainWindow::~MainWindow(){ diff --git a/mainwindow.h b/mainwindow.h index ed082b8e9..106acdaf9 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -18,6 +18,7 @@ #include "dialogs/dialogbisector.h" #include "dialogs/dialoglineintersect.h" #include "dialogs/dialogspline.h" +#include "dialogs/dialogarc.h" #include "tools/vtoolsinglepoint.h" #include "xml/vdomdocument.h" #include "container/vcontainer.h" @@ -38,7 +39,8 @@ namespace Tools{ NormalTool, BisectorTool, LineIntersectTool, - SplineTool + SplineTool, + ArcTool }; } @@ -83,6 +85,8 @@ public slots: void ClosedDialogLineIntersect(int result); void ToolSpline(bool checked); void ClosedDialogSpline(int result); + void ToolArc(bool checked); + void ClosedDialogArc(int result); protected: virtual void keyPressEvent ( QKeyEvent * event ); virtual void showEvent( QShowEvent *event ); @@ -103,6 +107,7 @@ private: DialogBisector *dialogBisector; DialogLineIntersect *dialogLineIntersect; DialogSpline *dialogSpline; + DialogArc *dialogArc; VDomDocument *doc; VContainer *data; QComboBox *comboBoxDraws; diff --git a/mainwindow.ui b/mainwindow.ui index af25ed48c..c0053113f 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -57,7 +57,7 @@ - 2 + 3 @@ -341,7 +341,7 @@ 0 0 154 - 45 + 58 @@ -355,9 +355,25 @@ - + + + false + - PushButton + ... + + + + :/icon/32x32/arc.png:/icon/32x32/arc.png + + + + 32 + 32 + + + + true diff --git a/tools/vtoolarc.cpp b/tools/vtoolarc.cpp new file mode 100644 index 000000000..13164f2a7 --- /dev/null +++ b/tools/vtoolarc.cpp @@ -0,0 +1,114 @@ +#include "vtoolarc.h" +#include + +VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, + QGraphicsItem *parent):VAbstractTool(doc, data, id), QGraphicsPathItem(parent){ + VArc arc = data->GetArc(id); + QPainterPath path; + path.addPath(arc.GetPath()); + path.setFillRule( Qt::WindingFill ); + this->setPath(path); + this->setPen(QPen(Qt::black, widthHairLine)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); + + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +void VToolArc::FullUpdateFromFile(){ + RefreshGeometry(); +} + +void VToolArc::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("center", QString().setNum(dialogArc->GetCenter())); + domElement.setAttribute("radius", dialogArc->GetRadius()); + domElement.setAttribute("angle1", dialogArc->GetF1()); + domElement.setAttribute("angle2", dialogArc->GetF2()); + emit FullUpdateTree(); + } + } + dialogArc.clear(); +} + +void VToolArc::ChangedActivDraw(const QString newName){ + if(nameActivDraw == newName){ + this->setPen(QPen(Qt::black, widthHairLine)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); + VAbstractTool::ChangedActivDraw(newName); + } else { + this->setPen(QPen(Qt::gray, widthHairLine)); + this->setFlag(QGraphicsItem::ItemIsSelectable, false); + this->setAcceptHoverEvents (false); + VAbstractTool::ChangedActivDraw(newName); + } +} + +void VToolArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + if(!ignoreContextMenuEvent){ + QMenu menu; + QAction *actionOption = menu.addAction("Властивості"); + QAction *selectedAction = menu.exec(event->screenPos()); + if(selectedAction == actionOption){ + dialogArc = QSharedPointer(new DialogArc(VAbstractTool::data)); + + connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject, + dialogArc.data(), &DialogArc::ChoosedObject); + connect(dialogArc.data(), &DialogArc::DialogClosed, this, + &VToolArc::FullUpdateFromGui); + + VArc arc = VAbstractTool::data->GetArc(id); + + dialogArc->GetCenter(arc.GetCenter()); + dialogArc->GetRadius(arc.GetFormulaRadius()); + dialogArc->GetF1(arc.GetFormulaF1()); + dialogArc->GetF2(arc.GetFormulaF2()); + + dialogArc->show(); + } + } +} + +void VToolArc::AddToFile(){ + VArc arc = VAbstractTool::data->GetArc(id); + QDomElement domElement = doc->createElement("arc"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "simple"); + AddAttribute(domElement, "center", arc.GetCenter()); + AddAttribute(domElement, "radius", arc.GetFormulaRadius()); + AddAttribute(domElement, "angle1", arc.GetFormulaF1()); + AddAttribute(domElement, "angle2", arc.GetFormulaF2()); + + AddToCalculation(domElement); +} + +void VToolArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ + if(event->button() == Qt::LeftButton){ + emit ChoosedTool(id, Scene::Arc); + } + QGraphicsItem::mouseReleaseEvent(event); +} + +void VToolArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(Qt::black, widthMainLine)); +} + +void VToolArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(Qt::black, widthHairLine)); +} + +void VToolArc::RefreshGeometry(){ + VArc arc = VAbstractTool::data->GetArc(id); + QPainterPath path; + path.addPath(arc.GetPath()); + path.setFillRule( Qt::WindingFill ); + this->setPath(path); +} diff --git a/tools/vtoolarc.h b/tools/vtoolarc.h new file mode 100644 index 000000000..24cb517ac --- /dev/null +++ b/tools/vtoolarc.h @@ -0,0 +1,32 @@ +#ifndef VTOOLARC_H +#define VTOOLARC_H + +#include "vabstracttool.h" +#include "../container/vcontainer.h" +#include "../xml/vdomdocument.h" +#include +#include "../dialogs/dialogarc.h" +#include "../widgets/vcontrolpointspline.h" + +class VToolArc :public VAbstractTool, public QGraphicsPathItem +{ + Q_OBJECT +public: + VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, + QGraphicsItem * parent = 0); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void ChangedActivDraw(const QString newName); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); +private: + QSharedPointer dialogArc; + void RefreshGeometry(); +}; + +#endif // VTOOLARC_H diff --git a/xml/vdomdocument.cpp b/xml/vdomdocument.cpp index 3815cec5e..3f8ef4b7d 100644 --- a/xml/vdomdocument.cpp +++ b/xml/vdomdocument.cpp @@ -10,6 +10,7 @@ #include "../tools/vtoolbisector.h" #include "../tools/vtoollineintersect.h" #include "../tools/vtoolspline.h" +#include "../tools/vtoolarc.h" #include "../options.h" #include "../container/calculator.h" @@ -228,6 +229,7 @@ void VDomDocument::Parse(Document::Enum parse, VMainGraphicsScene *scene, QCombo data->ClearLengthLines(); data->ClearLengthArcs(); data->ClearLengthSplines(); + data->ClearLineArcs(); } QDomElement rootElement = this->documentElement(); QDomNode domNode = rootElement.firstChild(); @@ -351,6 +353,9 @@ void VDomDocument::ParseCalculationElement(VMainGraphicsScene *scene, const QDom if(domElement.tagName() == "spline"){ ParseSplineElement(scene, domElement, parse, domElement.attribute("type", "")); } + if(domElement.tagName() == "arc"){ + ParseArcElement(scene, domElement, parse, domElement.attribute("type", "")); + } } } } @@ -673,6 +678,54 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme } } +void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement &domElement, + Document::Enum parse, const QString &type){ + if(type == "simple"){ + if(!domElement.isNull()){ + QString radius, f1, f2; + qint64 id, center; + if(!domElement.isNull()){ + id = domElement.attribute("id", "").toLongLong(); + center = domElement.attribute("center", "").toLongLong(); + radius = domElement.attribute("radius", ""); + f1 = domElement.attribute("angle1", ""); + f2 = domElement.attribute("angle2",""); + + qreal calcRadius = 0, calcF1 = 0, calcF2 = 0; + + Calculator cal(data); + QString errorMsg; + qreal result = cal.eval(radius, &errorMsg); + if(errorMsg.isEmpty()){ + calcRadius = result*PrintDPI/25.4; + } + + errorMsg.clear(); + result = cal.eval(f1, &errorMsg); + if(errorMsg.isEmpty()){ + calcF1 = result; + } + + errorMsg.clear(); + result = cal.eval(f2, &errorMsg); + if(errorMsg.isEmpty()){ + calcF2 = result; + } + + VArc arc = VArc(data->DataPoints(), center, calcRadius, radius, calcF1, f1, calcF2, f2 ); + data->UpdateArc(id, arc); + data->AddLengthArc(data->GetNameArc(center,id), arc.GetLength()); + if(parse == Document::FullParse){ + VToolArc *toolArc = new VToolArc(this, data, id, Tool::FromFile); + scene->addItem(toolArc); + connect(toolArc, &VToolArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + } + } + } + return; + } +} + void VDomDocument::FullUpdateTree(){ VMainGraphicsScene *scene = new VMainGraphicsScene(); QComboBox *comboBoxDraws = new QComboBox(); diff --git a/xml/vdomdocument.h b/xml/vdomdocument.h index 0675f3385..59746e2f6 100644 --- a/xml/vdomdocument.h +++ b/xml/vdomdocument.h @@ -61,6 +61,8 @@ private: Document::Enum parse); void ParseSplineElement(VMainGraphicsScene *scene, const QDomElement& domElement, Document::Enum parse, const QString& type); + void ParseArcElement(VMainGraphicsScene *scene, const QDomElement& domElement, + Document::Enum parse, const QString& type); void ParseIncrementsElement(const QDomNode& node); void AddNewDraw(const QDomElement &node, QComboBox *comboBoxDraws)const; };