From af95762c09d5d02041ed33d49275203e3cc3d8e6 Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 30 Jul 2013 16:09:34 +0300 Subject: [PATCH] Add tool Normal --- Valentina.pro | 11 +- container/calculator.cpp | 1 + container/vcontainer.cpp | 13 + container/vcontainer.h | 5 +- cursor.qrc | 1 + cursor/normal_cursor.png | Bin 0 -> 1175 bytes dialogs/dialognormal.cpp | 153 +++++++++++ dialogs/dialognormal.h | 49 ++++ dialogs/dialognormal.ui | 510 +++++++++++++++++++++++++++++++++++ icon.qrc | 1 + icon/32x32/normal.png | Bin 0 -> 754 bytes mainwindow.cpp | 63 +++++ mainwindow.h | 7 +- mainwindow.ui | 78 +++--- tools/vabstracttool.cpp | 13 - tools/vabstracttool.h | 2 - tools/vtoolalongline.cpp | 11 +- tools/vtoolendline.cpp | 10 +- tools/vtoolline.cpp | 3 - tools/vtoolnormal.cpp | 137 ++++++++++ tools/vtoolnormal.h | 36 +++ tools/vtoolshoulderpoint.cpp | 6 - xml/vdomdocument.cpp | 45 ++++ 23 files changed, 1084 insertions(+), 71 deletions(-) create mode 100644 cursor/normal_cursor.png create mode 100644 dialogs/dialognormal.cpp create mode 100644 dialogs/dialognormal.h create mode 100644 dialogs/dialognormal.ui create mode 100644 icon/32x32/normal.png create mode 100644 tools/vtoolnormal.cpp create mode 100644 tools/vtoolnormal.h diff --git a/Valentina.pro b/Valentina.pro index 466a00d18..d38b4392e 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -36,7 +36,9 @@ SOURCES += main.cpp\ dialogs/dialogtool.cpp \ dialogs/dialogalongline.cpp \ tools/vtoolshoulderpoint.cpp \ - dialogs/dialogshoulderpoint.cpp + dialogs/dialogshoulderpoint.cpp \ + tools/vtoolnormal.cpp \ + dialogs/dialognormal.cpp HEADERS += mainwindow.h \ widgets/vmaingraphicsscene.h \ @@ -63,7 +65,9 @@ HEADERS += mainwindow.h \ dialogs/dialogtool.h \ dialogs/dialogalongline.h \ tools/vtoolshoulderpoint.h \ - dialogs/dialogshoulderpoint.h + dialogs/dialogshoulderpoint.h \ + tools/vtoolnormal.h \ + dialogs/dialognormal.h FORMS += mainwindow.ui \ dialogs/dialogsinglepoint.ui \ @@ -71,7 +75,8 @@ FORMS += mainwindow.ui \ dialogs/dialogendline.ui \ dialogs/dialogline.ui \ dialogs/dialogalongline.ui \ - dialogs/dialogshoulderpoint.ui + dialogs/dialogshoulderpoint.ui \ + dialogs/dialognormal.ui RESOURCES += \ icon.qrc \ diff --git a/container/calculator.cpp b/container/calculator.cpp index e3f16094f..4bd9e6e8c 100644 --- a/container/calculator.cpp +++ b/container/calculator.cpp @@ -176,6 +176,7 @@ qreal Calculator::find_var(QString s){ bool ok = false; qreal value = data->FindVar(s, &ok); if(!ok){ + qDebug()< *VContainer::DataLengthLines() const{ return &lengthLines; } +void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId){ + QString nameLine = GetNameLine(firstPointId, secondPointId); + VPointF firstPoint = GetPoint(firstPointId); + VPointF secondPoint = GetPoint(secondPointId); + AddLine(nameLine, QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()).length()); +} + +QString VContainer::GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const{ + VPointF first = GetPoint(firstPoint); + VPointF second = GetPoint(secondPoint); + return QString("Line_%1_%2").arg(first.name(), second.name()); +} + void VContainer::AddLine(const QString &name, const qreal &value){ Q_ASSERT(!name.isEmpty()); lengthLines[name] = value/PrintDPI*25.4; diff --git a/container/vcontainer.h b/container/vcontainer.h index 01dc01a53..8cd3a828f 100644 --- a/container/vcontainer.h +++ b/container/vcontainer.h @@ -21,6 +21,8 @@ public: void AddStandartTableCell(const QString& name, const VStandartTableCell& cell); void AddIncrementTableRow(const QString& name, const VIncrementTableRow &cell); void AddLine(const QString &name, const qreal &value); + void AddLine(const qint64 &firstPointId, const qint64 &secondPointId); + QString GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const; void UpdatePoint(qint64 id, const VPointF& point); void UpdateStandartTableCell(const QString& name, const VStandartTableCell& cell); void UpdateIncrementTableRow(const QString& name, const VIncrementTableRow& cell); @@ -41,8 +43,7 @@ public: const QMap *DataBase() const; const QMap *DataStandartTable() const; const QMap *DataIncrementTable() const; - const QMap * DataLengthLines() const; - + const QMap * DataLengthLines() const; private: qint64 _id; QMap base; diff --git a/cursor.qrc b/cursor.qrc index a0ac3a747..245b1e052 100644 --- a/cursor.qrc +++ b/cursor.qrc @@ -5,5 +5,6 @@ cursor/line_cursor.png cursor/alongline_cursor.png cursor/shoulder_cursor.png + cursor/normal_cursor.png diff --git a/cursor/normal_cursor.png b/cursor/normal_cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..8ffe61bbf856ff38780073b8c20483bc91578c3e GIT binary patch literal 1175 zcmV;I1Zew-P)Vl&|00006VoOIv0RI60 z0RN!9r;`8x010qNS#tmY3ljhU3ljkVnw%H_000McNliru-3J~FCp!X0`^W$Q06}y` zSad^gZEa<4bO1wAML|?gQaT`KWG!lNWoICEF)lD5D0OpbZf77#N=G0{P(?=|b~Z98 zEFf`pVQgu1c_2L?IWP*aMOc#n00Y-aL_t(Y$HkV38ENa(2ufpZ z6C9~z7XG9#3L^M>5r!_hh)Ho^u-YF3)9p+u5`7Lf{VRxa!;j4lMhMxmfd zQ!)jqS{MH4jBnoQ!uN(zCmnx{J#cyN-1px7p7Z^ld+vk((}sqI4){GiJ?cUO7#J9M z?)7@5wY615&Eo(*!_7&@_$0!a};cyEn5&yHfjGTPc;iw*wg&89^x}9*;+AYHD(`rn#+m zswt&#I2?!wGcz+g_WZ=egvuK2sb&}k>+9TM1D-Bp+jLzgkw^fj z(a})=nwy)?pZ0W=8-{_1AR@_Tw6d}SP*7iAUwW=vEp^xpM=6yY_OqOv94Rg?mNV0y zTH!A%K&8|HKNgFTo104{61g%pHI>)U&=75GZ2ap?1(%Ncbb%ds9F7Arn5N0(0PuRfC)2T`qa%5q1EOhKa*MUMw+m1T)LK_pruC+$r`3ryH%${w z(~>8eh_JP_Wx8ChA>aY<1yGV{(Ym@ixpnI%yZ`L!55Irt>iIaRZr<+Y&fRTs8yi#ccsv9Y00H0^U^!LtbOA(PL{*dDpO}6;ld$JX%I;BG z@-`oS)N_<}K%7pe05Ui@_=839ZD7-S{x@&~&@I-~p>Zs8I$eZ5`E;LlyI92F01!BOr zz^iF8KF)9gZ&)>R32@lI&R+uV#l=OLpPz57s;c_g%0vP01J|wkco%pF*f_-*QU7k1^P1`EUy7qEMTk;t1Ssmnt3jeWBG3Z zo=o6>SQK3b+*a|81Am?(b06>lkPkcto@Amu#{#Yb@_;$u8L)dC#QNG=?b@}g`cID@ pX=`h11!ls$F7T#ln!f^z{{qrSlRAzP0+s*(002ovPDHLkV1hZ>3S9sI literal 0 HcmV?d00001 diff --git a/dialogs/dialognormal.cpp b/dialogs/dialognormal.cpp new file mode 100644 index 000000000..4f95743c4 --- /dev/null +++ b/dialogs/dialognormal.cpp @@ -0,0 +1,153 @@ +#include "dialognormal.h" +#include "ui_dialognormal.h" +#include + +DialogNormal::DialogNormal(const VContainer *data, QWidget *parent) : + DialogTool(data, parent), ui(new Ui::DialogNormal) +{ + ui->setupUi(this); + number = 0; + spinBoxAngle = ui->spinBoxAngle; + listWidget = ui->listWidget; + labelResultCalculation = ui->labelResultCalculation; + labelDescription = ui->labelDescription; + radioButtonSizeGrowth = ui->radioButtonSizeGrowth; + radioButtonStandartTable = ui->radioButtonStandartTable; + radioButtonIncrements = ui->radioButtonIncrements; + radioButtonLengthLine = ui->radioButtonLengthLine; + lineEditFormula = ui->lineEditFormula; + flagFormula = false; + bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + connect(bOk, &QPushButton::clicked, this, &DialogNormal::DialogAccepted); + flagName = false; + CheckState(); + QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); + connect(bCansel, &QPushButton::clicked, this, &DialogNormal::DialogRejected); + FillComboBoxPoints(ui->comboBoxFirstPoint); + FillComboBoxPoints(ui->comboBoxSecondPoint); + FillComboBoxTypeLine(ui->comboBoxLineType); + + connect(ui->toolButtonArrowDown, &QPushButton::clicked, this, + &DialogNormal::ArrowDown); + connect(ui->toolButtonArrowUp, &QPushButton::clicked, this, + &DialogNormal::ArrowUp); + connect(ui->toolButtonArrowLeft, &QPushButton::clicked, this, + &DialogNormal::ArrowLeft); + connect(ui->toolButtonArrowRight, &QPushButton::clicked, this, + &DialogNormal::ArrowRight); + connect(ui->toolButtonArrowLeftUp, &QPushButton::clicked, this, + &DialogNormal::ArrowLeftUp); + connect(ui->toolButtonArrowLeftDown, &QPushButton::clicked, this, + &DialogNormal::ArrowLeftDown); + connect(ui->toolButtonArrowRightUp, &QPushButton::clicked, this, + &DialogNormal::ArrowRightUp); + connect(ui->toolButtonArrowRightDown, &QPushButton::clicked, this, + &DialogNormal::ArrowRightDown); + connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogNormal::PutHere); + connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogNormal::PutVal); + connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogNormal::ValChenged); + + ShowBase(); + connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogNormal::SizeGrowth); + connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogNormal::StandartTable); + connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogNormal::Increments); + connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogNormal::LengthLines); + connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogNormal::EvalFormula); + connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogNormal::NamePointChanged); + connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogNormal::FormulaChanged); +} + +DialogNormal::~DialogNormal() +{ + delete ui; +} + +void DialogNormal::ChoosedPoint(qint64 id, Scene::Type type){ + if(type == Scene::Point){ + VPointF point = data->GetPoint(id); + if(number == 0){ + qint32 index = ui->comboBoxFirstPoint->findText(point.name()); + if ( index != -1 ) { // -1 for not found + ui->comboBoxFirstPoint->setCurrentIndex(index); + number++; + return; + } + } + if(number == 1){ + qint32 index = ui->comboBoxSecondPoint->findText(point.name()); + if ( index != -1 ) { // -1 for not found + ui->comboBoxSecondPoint->setCurrentIndex(index); + number = 0; + } + if(!isInitialized){ + this->show(); + } + } + } +} + +void DialogNormal::DialogAccepted(){ + pointName = ui->lineEditNamePoint->text(); + typeLine = GetTypeLine(ui->comboBoxLineType); + formula = ui->lineEditFormula->text(); + angle = ui->spinBoxAngle->value(); + qint32 index = ui->comboBoxFirstPoint->currentIndex(); + firstPointId = qvariant_cast(ui->comboBoxFirstPoint->itemData(index)); + index = ui->comboBoxSecondPoint->currentIndex(); + secondPointId = qvariant_cast(ui->comboBoxSecondPoint->itemData(index)); + emit DialogClosed(QDialog::Accepted); +} + +qint64 DialogNormal::getSecondPointId() const{ + return secondPointId; +} + +void DialogNormal::setSecondPointId(const qint64 &value){ + secondPointId = value; + ChangeCurrentData(ui->comboBoxSecondPoint, value); +} + +qint64 DialogNormal::getFirstPointId() const{ + return firstPointId; +} + +void DialogNormal::setFirstPointId(const qint64 &value){ + firstPointId = value; + ChangeCurrentData(ui->comboBoxFirstPoint, value); +} + +qint32 DialogNormal::getAngle() const{ + return angle; +} + +void DialogNormal::setAngle(const qint32 &value){ + angle = value; + ui->spinBoxAngle->setValue(angle); +} + +QString DialogNormal::getFormula() const{ + return formula; +} + +void DialogNormal::setFormula(const QString &value){ + formula = value; + ui->lineEditFormula->setText(formula); +} + +QString DialogNormal::getTypeLine() const{ + return typeLine; +} + +void DialogNormal::setTypeLine(const QString &value){ + typeLine = value; + SetupTypeLine(ui->comboBoxLineType, value); +} + +QString DialogNormal::getPointName() const{ + return pointName; +} + +void DialogNormal::setPointName(const QString &value){ + pointName = value; + ui->lineEditNamePoint->setText(pointName); +} diff --git a/dialogs/dialognormal.h b/dialogs/dialognormal.h new file mode 100644 index 000000000..91bbc69a7 --- /dev/null +++ b/dialogs/dialognormal.h @@ -0,0 +1,49 @@ +#ifndef DIALOGNORMAL_H +#define DIALOGNORMAL_H + +#include "dialogtool.h" +#include +#include +#include + +#include "../options.h" +#include "../container/vcontainer.h" +#include "../container/calculator.h" + +namespace Ui { +class DialogNormal; +} + +class DialogNormal : public DialogTool +{ + Q_OBJECT +public: + explicit DialogNormal(const VContainer *data, QWidget *parent = 0); + ~DialogNormal(); + QString getPointName() const; + void setPointName(const QString &value); + QString getTypeLine() const; + void setTypeLine(const QString &value); + QString getFormula() const; + void setFormula(const QString &value); + qint32 getAngle() const; + void setAngle(const qint32 &value); + qint64 getFirstPointId() const; + void setFirstPointId(const qint64 &value); + qint64 getSecondPointId() const; + void setSecondPointId(const qint64 &value); +public slots: + virtual void ChoosedPoint(qint64 id, Scene::Type type); + virtual void DialogAccepted(); +private: + Ui::DialogNormal *ui; + qint32 number; + QString pointName; + QString typeLine; + QString formula; + qint32 angle; + qint64 firstPointId; + qint64 secondPointId; +}; + +#endif // DIALOGNORMAL_H diff --git a/dialogs/dialognormal.ui b/dialogs/dialognormal.ui new file mode 100644 index 000000000..6558a9ff2 --- /dev/null +++ b/dialogs/dialognormal.ui @@ -0,0 +1,510 @@ + + + DialogNormal + + + + 0 + 0 + 488 + 594 + + + + Dialog + + + + + + + + + 0 + 0 + + + + Відстань + + + + + + + + 0 + 0 + + + + + + + + ... + + + + :/icon/24x24/equal.png:/icon/24x24/equal.png + + + + 24 + 24 + + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + _ + + + + + + + + + + + + + + + + 0 + 0 + + + + Ім'я нової точки + + + + + + + + + + ... + + + + :/icon/24x24/putHere.png:/icon/24x24/putHere.png + + + + 24 + 24 + + + + + + + + + + + + + 0 + 0 + + + + Перша точка + + + + + + + + + + + + + + + 0 + 0 + + + + Друга точка + + + + + + + + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Додатковий кут градуси + + + true + + + + + + + QLayout::SetMinimumSize + + + 29 + + + 6 + + + + + ... + + + + :/icon/24x24/arrowRightUp.png:/icon/24x24/arrowRightUp.png + + + + 32 + 32 + + + + + + + + ... + + + + :/icon/24x24/arrowLeftUp.png:/icon/24x24/arrowLeftUp.png + + + + 32 + 32 + + + + + + + + ... + + + + :/icon/24x24/arrowLeft.png:/icon/24x24/arrowLeft.png + + + + 32 + 32 + + + + + + + + ... + + + + :/icon/24x24/arrowRight.png:/icon/24x24/arrowRight.png + + + + 32 + 32 + + + + + + + + + 0 + 0 + + + + ... + + + + :/icon/24x24/arrowUp.png:/icon/24x24/arrowUp.png + + + + 32 + 32 + + + + + + + + ... + + + + :/icon/24x24/arrowDown.png:/icon/24x24/arrowDown.png + + + + 32 + 32 + + + + + + + + ... + + + + :/icon/24x24/arrowLeftDown.png:/icon/24x24/arrowLeftDown.png + + + + 32 + 32 + + + + + + + + ... + + + + :/icon/24x24/arrowRightDown.png:/icon/24x24/arrowRightDown.png + + + + 32 + 32 + + + + + + + + + 0 + 0 + + + + + 52 + 0 + + + + 360 + + + 0 + + + + + + + + + + + + + + + Тип лінії + + + + + + + + + + + + + + Вхідні данні + + + + + + + Розмір і зріст + + + true + + + + + + + Стандартна таблиця + + + + + + + Прибавки + + + + + + + true + + + Довжини ліній + + + + + + + false + + + Довжини дуг + + + + + + + false + + + Довжини сплайні + + + + + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogNormal + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogNormal + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/icon.qrc b/icon.qrc index 0aaf6bc75..b973dc505 100644 --- a/icon.qrc +++ b/icon.qrc @@ -22,5 +22,6 @@ icon/32x32/line.png icon/32x32/along_line.png icon/32x32/shoulder.png + icon/32x32/normal.png diff --git a/icon/32x32/normal.png b/icon/32x32/normal.png new file mode 100644 index 0000000000000000000000000000000000000000..722a06aecc150c98fd4ccc8fd7ebd77ce3b84840 GIT binary patch literal 754 zcmV4D2m025FtXa5Wy6YBUoKyA!%&<0~7=+EA?-% z)%r9Rx~OJ_9v^ zwuSrjXVxMrj1z|=uU4F>h=se|`@6G-2#H4%?jAxrU2)UE9BD4z0S+vfR@8-+ok8a{&lg#sU0_8xK=rjK<@! z7~|X&2)Ki-_4Rc*XLVi6InM;*f31{F-AG(!R?qRTCc<`?3f6kX__4nLn<+G zl-`c*N(=$SLI`09hzB0sG>wgo4W$$@#yvw!HF9%v6UufarcKPfnpjFH5T@NH zhDha>AcUzPhT2t1DP<~%A-A<1cGPt}cL3Wfr_pFM5k%FOVc!f__mwUsLjMoh^~c>& z?*EJU%CMDBZ-<=oJr&wflEDcU-(_VV5-T6EfZIb6B@zx{1=q*?k@>rSxv-x%pW@o% zd>{dqaSCgtjb8#^;H?@l zu!_UG&V?`I$Z!r=LJ0rGf3dJyBaHc};#-_VRoa5|QsDA{0LSqdLTU5vd)%y1XMU^r zptKL4*B(l~!p~jmhA_b@>E!K~c7GprN4&2K?*yJHTq%4K_&wYM^#K0b%XD*RW!wgx k+qh3wJb|m3>xEnY07wbhcU*PsO#lD@07*qoM6N<$f){01YXATM literal 0 HcmV?d00001 diff --git a/mainwindow.cpp b/mainwindow.cpp index 779b86318..15b8d18e7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -15,6 +15,7 @@ #include "tools/vtoolline.h" #include "tools/vtoolalongline.h" #include "tools/vtoolshoulderpoint.h" +#include "tools/vtoolnormal.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -52,6 +53,8 @@ MainWindow::MainWindow(QWidget *parent) : &MainWindow::ToolAlongLine); connect(ui->toolButtonShoulderPoint, &QToolButton::clicked, this, &MainWindow::ToolShoulderPoint); + connect(ui->toolButtonNormal, &QToolButton::clicked, this, + &MainWindow::ToolNormal); data = new VContainer; CreateManTableIGroup (); @@ -198,6 +201,7 @@ void MainWindow::ClosedDialogEndLine(int result){ line.setLength(result*PrintDPI/25.4); line.setAngle(angle); qint64 id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, 5, 10)); + data->AddLine(basePointId, id); VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, formula, angle, basePointId, Tool::FromGui); scene->addItem(point); @@ -229,6 +233,7 @@ void MainWindow::ClosedDialogLine(int result){ qint64 firstPoint = dialogLine->getFirstPoint(); qint64 secondPoint = dialogLine->getSecondPoint(); + data->AddLine(firstPoint, secondPoint); qint64 id = data->getNextId(); VToolLine *line = new VToolLine(doc, data, id, firstPoint, secondPoint, Tool::FromGui); scene->addItem(line); @@ -271,6 +276,8 @@ void MainWindow::ClosedDialogAlongLine(int result){ if(errorMsg.isEmpty()){ line.setLength(result*PrintDPI/25.4); qint64 id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, 5, 10)); + data->AddLine(firstPointId, id); + data->AddLine(id, secondPointId); VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId, secondPointId, typeLine, Tool::FromGui); scene->addItem(point); @@ -318,6 +325,8 @@ void MainWindow::ClosedDialogShoulderPoint(int result){ QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint, secondPoint, shoulderPoint, result*PrintDPI/25.4); qint64 id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, 5, 10)); + data->AddLine(p1Line, id); + data->AddLine(p2Line, id); VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, typeLine, formula, p1Line, p2Line, pShoulder, Tool::FromGui); scene->addItem(point); @@ -327,6 +336,53 @@ void MainWindow::ClosedDialogShoulderPoint(int result){ ArrowTool(); } +void MainWindow::ToolNormal(bool checked){ + if(checked){ + CanselTool(); + tool = Tools::NormalTool; + QPixmap pixmap(":/cursor/normal_cursor.png"); + QCursor cur(pixmap, 2, 3); + ui->graphicsView->setCursor(cur); + helpLabel->setText("Виберіть точки."); + dialogNormal = new DialogNormal(data, this); + connect(scene, &VMainGraphicsScene::ChoosedObject, dialogNormal, + &DialogNormal::ChoosedPoint); + connect(dialogNormal, &DialogNormal::DialogClosed, this, + &MainWindow::ClosedDialogNormal); + } else { + ui->toolButtonNormal->setChecked(true); + } +} + +void MainWindow::ClosedDialogNormal(int result){ + if(result == QDialog::Accepted){ + QString formula = dialogNormal->getFormula(); + qint64 firstPointId = dialogNormal->getFirstPointId(); + qint64 secondPointId = dialogNormal->getSecondPointId(); + QString typeLine = dialogNormal->getTypeLine(); + QString pointName = dialogNormal->getPointName(); + qint32 angle = dialogNormal->getAngle(); + + VPointF firstPoint = data->GetPoint(firstPointId); + VPointF secondPoint = data->GetPoint(secondPointId); + + Calculator cal(data); + QString errorMsg; + qreal result = cal.eval(formula, &errorMsg); + if(errorMsg.isEmpty()){ + QPointF fPoint = VToolNormal::FindPoint(firstPoint, secondPoint, result*PrintDPI/25.4, + angle); + qint64 id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, 5, 10)); + data->AddLine(firstPointId, id); + VToolNormal *point = new VToolNormal(doc, data, id, typeLine, formula, angle, firstPointId, + secondPointId, Tool::FromGui); + scene->addItem(point); + connect(point, &VToolNormal::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem); + } + } + ArrowTool(); +} + void MainWindow::showEvent( QShowEvent *event ){ QMainWindow::showEvent( event ); if( event->spontaneous() ){ @@ -459,6 +515,12 @@ void MainWindow::CanselTool(){ scene->setFocus(Qt::OtherFocusReason); scene->clearSelection(); break; + case Tools::NormalTool: + delete dialogNormal; + ui->toolButtonNormal->setChecked(false); + scene->setFocus(Qt::OtherFocusReason); + scene->clearSelection(); + break; } } @@ -718,6 +780,7 @@ void MainWindow::SetEnableTool(bool enable){ ui->toolButtonLine->setEnabled(enable); ui->toolButtonAlongLine->setEnabled(enable); ui->toolButtonShoulderPoint->setEnabled(enable); + ui->toolButtonNormal->setEnabled(enable); } MainWindow::~MainWindow(){ diff --git a/mainwindow.h b/mainwindow.h index aba66f242..8d2bf154e 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -14,6 +14,7 @@ #include "dialogs/dialogalongline.h" #include "dialogs/dialogshoulderpoint.h" #include "dialogs/dialogendline.h" +#include "dialogs/dialognormal.h" #include "tools/vtoolsimplepoint.h" #include "xml/vdomdocument.h" #include "container/vcontainer.h" @@ -30,7 +31,8 @@ namespace Tools{ EndLineTool, LineTool, AlongLineTool, - ShoulderPointTool + ShoulderPointTool, + NormalTool }; } @@ -67,6 +69,8 @@ public slots: void ClosedDialogAlongLine(int result); void ToolShoulderPoint(bool checked); void ClosedDialogShoulderPoint(int result); + void ToolNormal(bool checked); + void ClosedDialogNormal(int result); protected: virtual void keyPressEvent ( QKeyEvent * event ); virtual void showEvent( QShowEvent *event ); @@ -83,6 +87,7 @@ private: DialogLine *dialogLine; DialogAlongLine *dialogAlongLine; DialogShoulderPoint *dialogShoulderPoint; + DialogNormal *dialogNormal; VDomDocument *doc; VContainer *data; QComboBox *comboBoxDraws; diff --git a/mainwindow.ui b/mainwindow.ui index b72654c2a..e76d9979f 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -65,7 +65,7 @@ 0 0 156 - 81 + 104 @@ -78,29 +78,6 @@ Точка - - - - false - - - ... - - - - :/icon/32x32/shoulder.png:/icon/32x32/shoulder.png - - - - 24 - 24 - - - - true - - - @@ -115,8 +92,8 @@ - 24 - 24 + 32 + 32 @@ -138,8 +115,8 @@ - 24 - 24 + 32 + 32 @@ -167,8 +144,8 @@ - 24 - 24 + 32 + 32 @@ -177,10 +154,49 @@ - + + + false + ... + + + :/icon/32x32/normal.png:/icon/32x32/normal.png + + + + 32 + 32 + + + + true + + + + + + + false + + + ... + + + + :/icon/32x32/shoulder.png:/icon/32x32/shoulder.png + + + + 32 + 32 + + + + true + diff --git a/tools/vabstracttool.cpp b/tools/vabstracttool.cpp index 74b447080..d36d542f0 100644 --- a/tools/vabstracttool.cpp +++ b/tools/vabstracttool.cpp @@ -56,19 +56,6 @@ void VAbstractTool::AddAttribute(QDomElement &domElement, const QString &name, c VAbstractTool::~VAbstractTool(){ } -QString VAbstractTool::GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const{ - VPointF first = data->GetPoint(firstPoint); - VPointF second = data->GetPoint(secondPoint); - return QString("Line_%1_%2").arg(first.name(), second.name()); -} - -void VAbstractTool::AddLine(const qint64 &firstPointId, const qint64 &secondPointId) const{ - QString nameLine = GetNameLine(firstPointId, secondPointId); - VPointF firstPoint = data->GetPoint(firstPointId); - VPointF secondPoint = data->GetPoint(secondPointId); - data->AddLine(nameLine, QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()).length()); -} - void VAbstractTool::AddToCalculation(const QDomElement &domElement){ QDomElement calcElement; bool ok = doc->GetActivCalculationElement(calcElement); diff --git a/tools/vabstracttool.h b/tools/vabstracttool.h index ba1f2caaa..e41a65583 100644 --- a/tools/vabstracttool.h +++ b/tools/vabstracttool.h @@ -40,8 +40,6 @@ protected: void AddAttribute(QDomElement &domElement, const QString &name, const qint32 &value); void AddAttribute(QDomElement &domElement, const QString &name, const qreal &value); void AddAttribute(QDomElement &domElement, const QString &name, const QString &value); - QString GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const; - void AddLine(const qint64 &firstPointId, const qint64 &secondPointId) const; void AddToCalculation(const QDomElement &domElement); }; #endif // VABSTRACTTOOL_H diff --git a/tools/vtoolalongline.cpp b/tools/vtoolalongline.cpp index e6845f0e7..ccc42d9f8 100644 --- a/tools/vtoolalongline.cpp +++ b/tools/vtoolalongline.cpp @@ -30,9 +30,6 @@ VToolAlongLine::VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, c mainLine->setVisible(true); } - AddLine(firstPointId, id); - AddLine(id, secondPointId); - if(typeCreation == Tool::FromGui){ AddToFile(); } @@ -57,9 +54,11 @@ void VToolAlongLine::FullUpdateFromFile(){ VPointF firstPoint = VAbstractTool::data->GetPoint(firstPointId); VPointF secondPoint = VAbstractTool::data->GetPoint(secondPointId); mainLine->setLine(QLineF(firstPoint.toQPointF(), secondPoint.toQPointF())); - - AddLine(firstPointId, id); - AddLine(id, secondPointId); + if(typeLine == "none"){ + mainLine->setVisible(false); + } else { + mainLine->setVisible(true); + } } void VToolAlongLine::FullUpdateFromGui(int result){ diff --git a/tools/vtoolendline.cpp b/tools/vtoolendline.cpp index 59aa635ac..b33724792 100644 --- a/tools/vtoolendline.cpp +++ b/tools/vtoolendline.cpp @@ -17,6 +17,7 @@ VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id VPointF basePoint = data->GetPoint(basePointId); VPointF point = data->GetPoint(id); mainLine = new QGraphicsLineItem(QLineF(basePoint.toQPointF(), point.toQPointF()), this); + mainLine->setPen(QPen(Qt::black, widthHairLine)); mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); if(typeLine == "none"){ mainLine->setVisible(false); @@ -24,8 +25,6 @@ VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id mainLine->setVisible(true); } - AddLine(basePointId, id); - if(typeCreation == Tool::FromGui){ AddToFile(); } @@ -48,8 +47,11 @@ void VToolEndLine::FullUpdateFromFile(){ RefreshBaseGeometry(name, point.x(), point.y(), mx, my); VPointF basePoint = VAbstractTool::data->GetPoint(basePointId); mainLine->setLine(QLineF(basePoint.toQPointF(), point.toQPointF())); - - AddLine(basePointId, id); + if(typeLine == "none"){ + mainLine->setVisible(false); + } else { + mainLine->setVisible(true); + } } void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ diff --git a/tools/vtoolline.cpp b/tools/vtoolline.cpp index 7b10a15bb..61e4432e8 100644 --- a/tools/vtoolline.cpp +++ b/tools/vtoolline.cpp @@ -16,8 +16,6 @@ VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firs this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); - AddLine(firstPoint, secondPoint); - if(typeCreation == Tool::FromGui){ AddToFile(); } @@ -32,7 +30,6 @@ void VToolLine::FullUpdateFromFile(){ VPointF first = VAbstractTool::data->GetPoint(firstPoint); VPointF second = VAbstractTool::data->GetPoint(secondPoint); this->setLine(QLineF(first.toQPointF(), second.toQPointF())); - AddLine(firstPoint, secondPoint); } void VToolLine::FullUpdateFromGui(int result){ diff --git a/tools/vtoolnormal.cpp b/tools/vtoolnormal.cpp new file mode 100644 index 000000000..8729b51f1 --- /dev/null +++ b/tools/vtoolnormal.cpp @@ -0,0 +1,137 @@ +#include "vtoolnormal.h" +#include + +VToolNormal::VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, + const QString &formula, const qint32 &angle, const qint64 &firstPointId, + const qint64 &secondPointId, Tool::Enum typeCreation, QGraphicsItem *parent): + VToolPoint(doc, data, id, parent){ + this->typeLine = typeLine; + this->formula = formula; + this->angle = angle; + this->firstPointId = firstPointId; + this->secondPointId = secondPointId; + + //Лінія, що з'єднує дві точки + VPointF firstPoint = data->GetPoint(firstPointId); + VPointF point = data->GetPoint(id); + mainLine = new QGraphicsLineItem(QLineF(firstPoint.toQPointF(), point.toQPointF()), this); + mainLine->setPen(QPen(Qt::black, widthHairLine)); + mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); + if(typeLine == "none"){ + mainLine->setVisible(false); + } else { + mainLine->setVisible(true); + } + + if(typeCreation == Tool::FromGui){ + AddToFile(); + } + +} + +QPointF VToolNormal::FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const qreal &length, + const qint32 &angle){ + QLineF line(firstPoint, secondPoint); + QLineF normal = line.normalVector(); + normal.setAngle(normal.angle()+angle); + normal.setLength(length); + return normal.p2(); +} + +void VToolNormal::FullUpdateFromFile(){ + QString name; + qreal mx, my; + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + name = domElement.attribute("name", ""); + mx = domElement.attribute("mx", "").toDouble()*PrintDPI/25.4; + my = domElement.attribute("my", "").toDouble()*PrintDPI/25.4; + typeLine = domElement.attribute("typeLine", ""); + formula = domElement.attribute("length", ""); + firstPointId = domElement.attribute("firstPoint", "").toLongLong(); + secondPointId = domElement.attribute("secondPoint", "").toLongLong(); + angle = domElement.attribute("angle", "").toInt(); + } + VPointF point = VAbstractTool::data->GetPoint(id); + RefreshBaseGeometry(name, point.x(), point.y(), mx, my); + VPointF firstPoint = VAbstractTool::data->GetPoint(firstPointId); + mainLine->setLine(QLineF(firstPoint.toQPointF(), point.toQPointF())); + if(typeLine == "none"){ + mainLine->setVisible(false); + } else { + mainLine->setVisible(true); + } +} + +void VToolNormal::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", dialogNormal->getPointName()); + domElement.setAttribute("typeLine", dialogNormal->getTypeLine()); + domElement.setAttribute("length", dialogNormal->getFormula()); + domElement.setAttribute("angle", QString().setNum(dialogNormal->getAngle())); + domElement.setAttribute("firstPoint", QString().setNum(dialogNormal->getFirstPointId())); + domElement.setAttribute("secondPoint", QString().setNum(dialogNormal->getSecondPointId())); + emit FullUpdateTree(); + } + } + dialogNormal.clear(); +} + +void VToolNormal::ChangedActivDraw(const QString newName){ + if(nameActivDraw == newName){ + mainLine->setPen(QPen(Qt::black, widthHairLine)); + VToolPoint::ChangedActivDraw(newName); + } else { + mainLine->setPen(QPen(Qt::gray, widthHairLine)); + VToolPoint::ChangedActivDraw(newName); + } +} + +void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + if(!ignoreContextMenuEvent){ + QMenu menu; + QAction *actionOption = menu.addAction("Властивості"); + QAction *selectedAction = menu.exec(event->screenPos()); + if(selectedAction == actionOption){ + dialogNormal = QSharedPointer(new DialogNormal(VAbstractTool::data)); + + connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject, + dialogNormal.data(), &DialogNormal::ChoosedPoint); + connect(dialogNormal.data(), &DialogNormal::DialogClosed, this, + &VToolNormal::FullUpdateFromGui); + connect(doc, &VDomDocument::FullUpdateFromFile, dialogNormal.data(), &DialogNormal::UpdateList); + + VPointF p = VAbstractTool::data->GetPoint(id); + + dialogNormal->setTypeLine(typeLine); + dialogNormal->setFormula(formula); + dialogNormal->setAngle(angle); + dialogNormal->setFirstPointId(firstPointId); + dialogNormal->setSecondPointId(secondPointId); + dialogNormal->setPointName(p.name()); + + dialogNormal->show(); + } + } +} + +void VToolNormal::AddToFile(){ + VPointF point = VAbstractTool::data->GetPoint(id); + QDomElement domElement = doc->createElement("point"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "normal"); + AddAttribute(domElement, "name", point.name()); + AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); + AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + + AddAttribute(domElement, "typeLine", typeLine); + AddAttribute(domElement, "length", formula); + AddAttribute(domElement, "angle", angle); + AddAttribute(domElement, "firstPoint", firstPointId); + AddAttribute(domElement, "secondPoint", firstPointId); + + AddToCalculation(domElement); +} diff --git a/tools/vtoolnormal.h b/tools/vtoolnormal.h new file mode 100644 index 000000000..8e87e9488 --- /dev/null +++ b/tools/vtoolnormal.h @@ -0,0 +1,36 @@ +#ifndef VTOOLNORMAL_H +#define VTOOLNORMAL_H + +#include + +#include "vtoolpoint.h" +#include "../dialogs/dialognormal.h" + +class VToolNormal : public VToolPoint +{ +public: + VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, + const qint32 &angle, const qint64 &firstPointId, + const qint64 &secondPointId, Tool::Enum typeCreation, + QGraphicsItem * parent = 0); + static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, + const qreal &length, const qint32 &angle = 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(); +private: + QString typeLine; + QString formula; + qint32 angle; + qint64 firstPointId; + qint64 secondPointId; + QGraphicsLineItem *mainLine; + QSharedPointer dialogNormal; +}; + +#endif // VTOOLNORMAL_H diff --git a/tools/vtoolshoulderpoint.cpp b/tools/vtoolshoulderpoint.cpp index 4e72d582e..a8f4d0fc3 100644 --- a/tools/vtoolshoulderpoint.cpp +++ b/tools/vtoolshoulderpoint.cpp @@ -23,9 +23,6 @@ VToolShoulderPoint::VToolShoulderPoint(VDomDocument *doc, VContainer *data, cons mainLine->setVisible(true); } - AddLine(p1Line, id); - AddLine(p2Line, id); - if(typeCreation == Tool::FromGui){ AddToFile(); } @@ -76,9 +73,6 @@ void VToolShoulderPoint::FullUpdateFromFile(){ } else { mainLine->setVisible(true); } - - AddLine(p1Line, id); - AddLine(p2Line, id); } void VToolShoulderPoint::FullUpdateFromGui(int result){ diff --git a/xml/vdomdocument.cpp b/xml/vdomdocument.cpp index 637d7cb8e..e5061ca67 100644 --- a/xml/vdomdocument.cpp +++ b/xml/vdomdocument.cpp @@ -6,6 +6,7 @@ #include "../tools/vtoolline.h" #include "../tools/vtoolalongline.h" #include "../tools/vtoolshoulderpoint.h" +#include "../tools/vtoolnormal.h" #include "../options.h" #include "../container/calculator.h" @@ -397,6 +398,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen line.setLength(result*PrintDPI/25.4); line.setAngle(angle); data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), name, mx, my)); + data->AddLine(basePointId, id); if(parse == Document::FullParse){ VToolEndLine *point = new VToolEndLine(this, data, id, typeLine, formula, angle, basePointId, Tool::FromFile); @@ -433,6 +435,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen if(errorMsg.isEmpty()){ line.setLength(result*PrintDPI/25.4); data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), name, mx, my)); + data->AddLine(firstPointId, id); + data->AddLine(id, secondPointId); if(parse == Document::FullParse){ VToolAlongLine *point = new VToolAlongLine(this, data, id, formula, firstPointId, secondPointId, typeLine, Tool::FromGui); @@ -472,6 +476,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint, secondPoint, shoulderPoint, result*PrintDPI/25.4); data->UpdatePoint(id,VPointF(fPoint.x(), fPoint.y(), name, mx, my)); + data->AddLine(p1Line, id); + data->AddLine(p2Line, id); if(parse == Document::FullParse){ VToolShoulderPoint *point = new VToolShoulderPoint(this, data, id, typeLine, formula, p1Line, p2Line, pShoulder, @@ -485,6 +491,44 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen } return; } + if(type == "normal"){ + if(!domElement.isNull()){ + QString name, typeLine, formula; + qreal mx=5, my=10, angle; + qint64 id, firstPointId, secondPointId; + if(!domElement.isNull()){ + id = domElement.attribute("id", "").toLongLong(); + name = domElement.attribute("name", ""); + mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; + my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; + + typeLine = domElement.attribute("typeLine", ""); + formula = domElement.attribute("length", ""); + firstPointId = domElement.attribute("firstPoint", "").toLongLong(); + secondPointId = domElement.attribute("secondPoint", "").toLongLong(); + angle = domElement.attribute("angle", "").toInt(); + + VPointF firstPoint = data->GetPoint(firstPointId); + VPointF secondPoint = data->GetPoint(secondPointId); + Calculator cal(data); + QString errorMsg; + qreal result = cal.eval(formula, &errorMsg); + if(errorMsg.isEmpty()){ + QPointF fPoint = VToolNormal::FindPoint(firstPoint, secondPoint, result*PrintDPI/25.4, + angle); + data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), name, mx, my)); + data->AddLine(firstPointId, id); + if(parse == Document::FullParse){ + VToolNormal *point = new VToolNormal(this, data, id, typeLine, formula, angle, + firstPointId, secondPointId, Tool::FromFile); + scene->addItem(point); + connect(point, &VToolNormal::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem); + } + } + } + } + return; + } } void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement, @@ -495,6 +539,7 @@ void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement if(!domElement.isNull()){ firstPoint = domElement.attribute("firstPoint", "").toLongLong(); secondPoint = domElement.attribute("secondPoint", "").toLongLong(); + data->AddLine(firstPoint, secondPoint); if(parse == Document::FullParse){ qint64 id = data->getNextId(); VToolLine *line = new VToolLine(this, data, id, firstPoint, secondPoint, Tool::FromFile);