From a21ad603ef80f858fd6c5862bebe6342b34f7019 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 20 Oct 2014 20:41:02 +0300 Subject: [PATCH] New tool line intersect axis. --HG-- branch : develop --- src/app/dialogs/dialogs.h | 1 + src/app/dialogs/dialogs.pri | 11 +- src/app/dialogs/tools/dialogendline.cpp | 2 +- .../dialogs/tools/dialoglineintersectaxis.cpp | 290 ++++++++++ .../dialogs/tools/dialoglineintersectaxis.h | 98 ++++ .../dialogs/tools/dialoglineintersectaxis.ui | 532 ++++++++++++++++++ src/app/mainwindow.cpp | 17 + src/app/mainwindow.h | 1 + src/app/mainwindow.ui | 28 +- src/app/options.h | 5 +- src/app/share/resources/cursor.qrc | 1 + .../cursor/line_intersect_axis_cursor.png | Bin 1179 -> 1248 bytes src/app/share/resources/icon.qrc | 1 + src/app/tools/drawTools/drawtools.h | 1 + .../drawTools/vtoollineintersectaxis.cpp | 335 +++++++++++ .../tools/drawTools/vtoollineintersectaxis.h | 82 +++ src/app/tools/tools.pri | 6 +- .../vistoollineintersectaxis.cpp | 142 +++++ .../visualization/vistoollineintersectaxis.h | 67 +++ src/app/visualization/visualization.pri | 6 +- .../widgets/vtooloptionspropertybrowser.cpp | 63 +++ src/app/widgets/vtooloptionspropertybrowser.h | 3 + src/app/xml/vpattern.cpp | 39 +- 23 files changed, 1719 insertions(+), 12 deletions(-) create mode 100644 src/app/dialogs/tools/dialoglineintersectaxis.cpp create mode 100644 src/app/dialogs/tools/dialoglineintersectaxis.h create mode 100644 src/app/dialogs/tools/dialoglineintersectaxis.ui create mode 100644 src/app/tools/drawTools/vtoollineintersectaxis.cpp create mode 100644 src/app/tools/drawTools/vtoollineintersectaxis.h create mode 100644 src/app/visualization/vistoollineintersectaxis.cpp create mode 100644 src/app/visualization/vistoollineintersectaxis.h diff --git a/src/app/dialogs/dialogs.h b/src/app/dialogs/dialogs.h index ec4e9c874..44da6ae42 100644 --- a/src/app/dialogs/dialogs.h +++ b/src/app/dialogs/dialogs.h @@ -49,6 +49,7 @@ #include "tools/dialoguniondetails.h" #include "tools/dialogtriangle.h" #include "tools/dialogpointofintersection.h" +#include "tools/dialoglineintersectaxis.h" #include "app/dialoghistory.h" #include "app/dialogincrements.h" diff --git a/src/app/dialogs/dialogs.pri b/src/app/dialogs/dialogs.pri index 8f98a8997..f19de3229 100644 --- a/src/app/dialogs/dialogs.pri +++ b/src/app/dialogs/dialogs.pri @@ -21,6 +21,8 @@ HEADERS += \ dialogs/tools/dialogcutsplinepath.h \ dialogs/tools/dialoguniondetails.h \ dialogs/tools/dialogcutarc.h \ + dialogs/tools/dialogeditwrongformula.h \ + dialogs/tools/dialoglineintersectaxis.h \ dialogs/app/dialogincrements.h \ dialogs/app/dialoghistory.h \ dialogs/app/configdialog.h \ @@ -30,7 +32,6 @@ HEADERS += \ dialogs/app/dialogstandardmeasurements.h \ dialogs/app/dialogindividualmeasurements.h \ dialogs/app/dialogaboutapp.h \ - dialogs/tools/dialogeditwrongformula.h \ dialogs/app/dialogpatternxmledit.h \ dialogs/app/configpages/configurationpage.h \ dialogs/app/configpages/patternpage.h \ @@ -60,6 +61,8 @@ SOURCES += \ dialogs/tools/dialogcutsplinepath.cpp \ dialogs/tools/dialoguniondetails.cpp \ dialogs/tools/dialogcutarc.cpp \ + dialogs/tools/dialogeditwrongformula.cpp \ + dialogs/tools/dialoglineintersectaxis.cpp \ dialogs/app/dialogincrements.cpp \ dialogs/app/dialoghistory.cpp \ dialogs/app/configdialog.cpp \ @@ -69,7 +72,6 @@ SOURCES += \ dialogs/app/dialogindividualmeasurements.cpp \ dialogs/app/dialogaboutapp.cpp \ dialogs/app/dialogpatternxmledit.cpp \ - dialogs/tools/dialogeditwrongformula.cpp \ dialogs/app/configpages/configurationpage.cpp \ dialogs/app/configpages/patternpage.cpp \ dialogs/app/configpages/communitypage.cpp \ @@ -97,6 +99,8 @@ FORMS += \ dialogs/tools/dialogcutsplinepath.ui \ dialogs/tools/dialoguniondetails.ui \ dialogs/tools/dialogcutarc.ui \ + dialogs/tools/dialogeditwrongformula.ui \ + dialogs/tools/dialoglineintersectaxis.ui \ dialogs/app/dialogincrements.ui \ dialogs/app/dialoghistory.ui \ dialogs/app/dialogpatternproperties.ui \ @@ -105,5 +109,4 @@ FORMS += \ dialogs/app/dialogindividualmeasurements.ui \ dialogs/app/dialogaboutapp.ui \ dialogs/app/dialogpatternxmledit.ui \ - dialogs/tools/dialogeditwrongformula.ui \ - dialogs/app/dialogundo.ui + dialogs/app/dialogundo.ui \ diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index 75934ac0f..a5a882ef3 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -112,7 +112,7 @@ void DialogEndLine::FormulaTextChanged() void DialogEndLine::AngleTextChanged() { labelEditFormula = ui->labelEditAngle; - ValFormulaChanged(flagError, ui->plainTextEditFormula, timerFormula); + ValFormulaChanged(flagError, ui->plainTextEditAngle, timerFormula); labelEditFormula = ui->labelEditFormula; } diff --git a/src/app/dialogs/tools/dialoglineintersectaxis.cpp b/src/app/dialogs/tools/dialoglineintersectaxis.cpp new file mode 100644 index 000000000..3016a7f61 --- /dev/null +++ b/src/app/dialogs/tools/dialoglineintersectaxis.cpp @@ -0,0 +1,290 @@ +/************************************************************************ + ** + ** @file dialoglineintersectaxis.cpp + ** @author Roman Telezhynskyi + ** @date 19 10, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "dialoglineintersectaxis.h" +#include "ui_dialoglineintersectaxis.h" + +#include "../../geometry/vpointf.h" +#include "../../container/vcontainer.h" +#include "../../visualization/vistoollineintersectaxis.h" +#include "../../widgets/vmaingraphicsscene.h" +#include "../../tools/vabstracttool.h" +#include + +//--------------------------------------------------------------------------------------------------------------------- +DialogLineIntersectAxis::DialogLineIntersectAxis(const VContainer *data, const quint32 &toolId, QWidget *parent) + :DialogTool(data, toolId, parent), ui(new Ui::DialogLineIntersectAxis), number(0), typeLine(QString()), + formulaAngle(QString()), basePointId(NULL_ID), firstPointId(NULL_ID), secondPointId(NULL_ID), + formulaBaseHeightAngle(0), line(nullptr) +{ + ui->setupUi(this); + InitVariables(ui); + InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); + labelEditNamePoint = ui->labelEditNamePoint; + this->formulaBaseHeightAngle = ui->plainTextEditFormula->height(); + + InitOkCancelApply(ui); + flagFormula = false; + CheckState(); + + FillComboBoxPoints(ui->comboBoxAxisPoint); + FillComboBoxPoints(ui->comboBoxFirstLinePoint); + FillComboBoxPoints(ui->comboBoxSecondLinePoint); + FillComboBoxTypeLine(ui->comboBoxLineType); + + connect(ui->toolButtonPutHereAngle, &QPushButton::clicked, this, &DialogLineIntersectAxis::PutAngle); + connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogLineIntersectAxis::PutVal); + connect(ui->toolButtonEqualAngle, &QPushButton::clicked, this, &DialogLineIntersectAxis::EvalAngle); + connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogLineIntersectAxis::NamePointChanged); + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogLineIntersectAxis::AngleTextChanged); + connect(ui->pushButtonGrowLengthAngle, &QPushButton::clicked, this, &DialogLineIntersectAxis::DeployAngleTextEdit); + connect(timerFormula, &QTimer::timeout, this, &DialogLineIntersectAxis::EvalAngle); + + line = new VisToolLineIntersectAxis(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogLineIntersectAxis::~DialogLineIntersectAxis() +{ + delete line; + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogLineIntersectAxis::getPointName() const +{ + return pointName; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLineIntersectAxis::setPointName(const QString &value) +{ + pointName = value; + ui->lineEditNamePoint->setText(pointName); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogLineIntersectAxis::getTypeLine() const +{ + return typeLine; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLineIntersectAxis::setTypeLine(const QString &value) +{ + typeLine = value; + SetupTypeLine(ui->comboBoxLineType, value); + line->setLineStyle(VAbstractTool::LineStyle(typeLine)); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogLineIntersectAxis::getAngle() const +{ + return qApp->FormulaFromUser(formulaAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLineIntersectAxis::setAngle(const QString &value) +{ + formulaAngle = qApp->FormulaToUser(value); + // increase height if needed. TODO : see if I can get the max number of caracters in one line + // of this PlainTextEdit to change 80 to this value + if (formulaAngle.length() > 80) + { + this->DeployAngleTextEdit(); + } + ui->plainTextEditFormula->setPlainText(formulaAngle); + line->setAngle(formulaAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogLineIntersectAxis::getBasePointId() const +{ + return basePointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLineIntersectAxis::setBasePointId(const quint32 &value) +{ + setCurrentPointId(ui->comboBoxAxisPoint, basePointId, value); + line->setAxisPointId(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogLineIntersectAxis::getFirstPointId() const +{ + return firstPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLineIntersectAxis::setFirstPointId(const quint32 &value) +{ + setCurrentPointId(ui->comboBoxFirstLinePoint, firstPointId, value); + line->setPoint1Id(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogLineIntersectAxis::getSecondPointId() const +{ + return secondPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLineIntersectAxis::setSecondPointId(const quint32 &value) +{ + setCurrentPointId(ui->comboBoxSecondLinePoint, secondPointId, value); + line->setPoint2Id(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLineIntersectAxis::ShowDialog(bool click) +{ + if (prepare) + { + if (click) + { + /*We will ignore click if poinet is in point circle*/ + VMainGraphicsScene *scene = qApp->getCurrentScene(); + SCASSERT(scene != nullptr); + const QSharedPointer point = data->GeometricObject(basePointId); + QLineF line = QLineF(point->toQPointF(), scene->getScenePos()); + + //Radius of point circle, but little bigger. Need handle with hover sizes. + qreal radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; + if (line.length() <= radius) + { + return; + } + } + this->setModal(true); + this->setAngle(line->Angle());//Show in dialog angle what user choose + emit ToolTip(""); + timerFormula->start(); + this->show(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLineIntersectAxis::ChosenObject(quint32 id, const SceneObject &type) +{ + if (prepare == false)// After first choose we ignore all objects + { + if (type == SceneObject::Point) + { + switch (number) + { + case (0): + if (SetObject(id, ui->comboBoxFirstLinePoint, tr("Select second point of line"))) + { + number++; + line->VisualMode(id); + } + break; + case (1): + if (SetObject(id, ui->comboBoxSecondLinePoint, tr("Select axis point"))) + { + number++; + line->setPoint2Id(id); + line->RefreshGeometry(); + } + break; + case (2): + if (SetObject(id, ui->comboBoxAxisPoint, "")) + { + basePointId = id; + line->setAxisPointId(id); + line->RefreshGeometry(); + prepare = true; + } + break; + default: + break; + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLineIntersectAxis::PutAngle() +{ + PutValHere(ui->plainTextEditFormula, ui->listWidget); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLineIntersectAxis::EvalAngle() +{ + const QString postfix = QStringLiteral("°"); + Eval(ui->plainTextEditFormula->toPlainText(), flagError, ui->labelResultCalculation, postfix, false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLineIntersectAxis::AngleTextChanged() +{ + ValFormulaChanged(flagError, ui->plainTextEditFormula, timerFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLineIntersectAxis::DeployAngleTextEdit() +{ + DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLengthAngle, formulaBaseHeightAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLineIntersectAxis::ShowVisualization() +{ + if (prepare == false) + { + //TODO move to parent class! + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolLineIntersectAxis::SetFactor); + scene->addItem(line); + line->RefreshGeometry(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLineIntersectAxis::SaveData() +{ + pointName = ui->lineEditNamePoint->text(); + typeLine = GetTypeLine(ui->comboBoxLineType); + + formulaAngle = ui->plainTextEditFormula->toPlainText(); + formulaAngle.replace("\n", " "); + + basePointId = getCurrentObjectId(ui->comboBoxAxisPoint); + firstPointId = getCurrentObjectId(ui->comboBoxFirstLinePoint); + secondPointId = getCurrentObjectId(ui->comboBoxSecondLinePoint); + + line->setPoint1Id(firstPointId); + line->setPoint2Id(secondPointId); + line->setAxisPointId(basePointId); + line->setAngle(formulaAngle); + line->setLineStyle(VAbstractTool::LineStyle(typeLine)); + line->RefreshGeometry(); +} diff --git a/src/app/dialogs/tools/dialoglineintersectaxis.h b/src/app/dialogs/tools/dialoglineintersectaxis.h new file mode 100644 index 000000000..f4bbbd5e8 --- /dev/null +++ b/src/app/dialogs/tools/dialoglineintersectaxis.h @@ -0,0 +1,98 @@ +/************************************************************************ + ** + ** @file dialoglineintersectaxis.h + ** @author Roman Telezhynskyi + ** @date 19 10, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef DIALOGLINEINTERSECTAXIS_H +#define DIALOGLINEINTERSECTAXIS_H + +#include "dialogtool.h" + +namespace Ui { +class DialogLineIntersectAxis; +} + +class VisToolLineIntersectAxis; + +class DialogLineIntersectAxis : public DialogTool +{ + Q_OBJECT + +public: + DialogLineIntersectAxis(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr); + ~DialogLineIntersectAxis(); + + QString getPointName() const; + void setPointName(const QString &value); + + QString getTypeLine() const; + void setTypeLine(const QString &value); + + QString getAngle() const; + void setAngle(const QString &value); + + quint32 getBasePointId() const; + void setBasePointId(const quint32 &value); + + quint32 getFirstPointId() const; + void setFirstPointId(const quint32 &value); + + quint32 getSecondPointId() const; + void setSecondPointId(const quint32 &value); + + virtual void ShowDialog(bool click); +public slots: + virtual void ChosenObject(quint32 id, const SceneObject &type); + void PutAngle(); + void EvalAngle(); + void AngleTextChanged(); + void DeployAngleTextEdit(); +protected: + virtual void ShowVisualization(); + /** + * @brief SaveData Put dialog data in local variables + */ + virtual void SaveData(); +private: + Q_DISABLE_COPY(DialogLineIntersectAxis) + Ui::DialogLineIntersectAxis *ui; + + /** @brief number number of handled objects */ + qint32 number; + + /** @brief typeLine type of line */ + QString typeLine; + + QString formulaAngle; + quint32 basePointId; + quint32 firstPointId; + quint32 secondPointId; + int formulaBaseHeightAngle; + + VisToolLineIntersectAxis *line; +}; + +#endif // DIALOGLINEINTERSECTAXIS_H diff --git a/src/app/dialogs/tools/dialoglineintersectaxis.ui b/src/app/dialogs/tools/dialoglineintersectaxis.ui new file mode 100644 index 000000000..a1019e056 --- /dev/null +++ b/src/app/dialogs/tools/dialoglineintersectaxis.ui @@ -0,0 +1,532 @@ + + + DialogLineIntersectAxis + + + + 0 + 0 + 457 + 532 + + + + Dialog + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Angle + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + ... + + + + :/icon/24x24/putHere.png:/icon/24x24/putHere.png + + + + 24 + 24 + + + + + + + + Calculate value + + + ... + + + + :/icon/24x24/equal.png:/icon/24x24/equal.png + + + + 24 + 24 + + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value of angle + + + _ + + + + + + + + + + + + 16777215 + 24 + + + + + 4 + 0 + + + + true + + + QPlainTextEdit::NoWrap + + + + + + + + 16 + 16 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + + + + + + + + + + + + + + + 0 + 0 + + + + Axis point + + + + + + + First point of line + + + + + + + + 0 + 0 + + + + First line point + + + + + + + First point of line + + + + + + + + 0 + 0 + + + + Second line point + + + + + + + First point of line + + + + + + + + 0 + 0 + + + + Point label + + + + + + + + 0 + 0 + + + + + + + + Type of line + + + + + + + Show line from first point to this point + + + + + + + + + Input data + + + + + + + + 0 + 0 + + + + Size and height + + + true + + + + + + + + 0 + 0 + + + + Standard table + + + + + + + + 0 + 0 + + + + Increments + + + + + + + true + + + + 0 + 0 + + + + Length of lines + + + + + + + true + + + + 0 + 0 + + + + Length of arcs + + + + + + + true + + + + 0 + 0 + + + + Length of curves + + + + + + + true + + + + 0 + 0 + + + + Angle of lines + + + + + + + + + + + + + Hide empty measurements + + + true + + + + + + + Variables + + + + + + + + + + + + 0 + 0 + + + + Qt::PlainText + + + true + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + plainTextEditFormula + pushButtonGrowLengthAngle + toolButtonPutHereAngle + toolButtonEqualAngle + comboBoxAxisPoint + comboBoxFirstLinePoint + comboBoxSecondLinePoint + lineEditNamePoint + comboBoxLineType + radioButtonSizeGrowth + radioButtonStandardTable + radioButtonIncrements + radioButtonLengthLine + radioButtonLengthArc + radioButtonLengthSpline + radioButtonAngleLine + checkBoxHideEmpty + listWidget + buttonBox + + + + + + + buttonBox + accepted() + DialogLineIntersectAxis + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogLineIntersectAxis + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 9de5cb557..dd0fca429 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -665,6 +665,16 @@ void MainWindow::ToolCutArc(bool checked) &MainWindow::ApplyDialog); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolLineIntersectAxis(bool checked) +{ + SetToolButtonWithApply(checked, Tool::LineIntersectAxis, + ":/cursor/line_intersect_axis_cursor.png", + tr("Select first point of line"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief About show widows about. @@ -930,6 +940,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonSplinePathCutPoint, &QToolButton::clicked, this, &MainWindow::ToolCutSplinePath); connect(ui->toolButtonUnionDetails, &QToolButton::clicked, this, &MainWindow::ToolUnionDetails); connect(ui->toolButtonArcCutPoint, &QToolButton::clicked, this, &MainWindow::ToolCutArc); + connect(ui->toolButtonLineIntersectAxis, &QToolButton::clicked, this, &MainWindow::ToolLineIntersectAxis); } //--------------------------------------------------------------------------------------------------------------------- @@ -1069,6 +1080,11 @@ void MainWindow::CancelTool() currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; + case Tool::LineIntersectAxis: + ui->toolButtonLineIntersectAxis->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; case Tool::NodePoint: case Tool::NodeArc: case Tool::NodeSpline: @@ -1772,6 +1788,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonSplineCutPoint->setEnabled(drawTools); ui->toolButtonSplinePathCutPoint->setEnabled(drawTools); ui->toolButtonArcCutPoint->setEnabled(drawTools); + ui->toolButtonLineIntersectAxis->setEnabled(drawTools); //Modeling Tools ui->toolButtonUnionDetails->setEnabled(modelingTools); diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 61d0a4ce3..ba460ef5a 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -106,6 +106,7 @@ public slots: void ToolPointOfIntersection(bool checked); void ToolUnionDetails(bool checked); void ToolCutArc(bool checked); + void ToolLineIntersectAxis(bool checked); void ClosedDialogDetail(int result); void ClosedDialogUnionDetails(int result); diff --git a/src/app/mainwindow.ui b/src/app/mainwindow.ui index 6b633384d..dc3ec5687 100644 --- a/src/app/mainwindow.ui +++ b/src/app/mainwindow.ui @@ -40,7 +40,7 @@ - 4 + 0 @@ -301,6 +301,32 @@ + + + + false + + + Point of intersection line and axis + + + ... + + + + :/icon/32x32/line_intersect_axis.png:/icon/32x32/line_intersect_axis.png + + + + 32 + 32 + + + + true + + + diff --git a/src/app/options.h b/src/app/options.h index c297b5e41..147a065a9 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -80,7 +80,9 @@ enum class Tool : unsigned char NodeSplinePath, Height, Triangle, + LineIntersectAxis, PointOfIntersection, + UnionDetails }; @@ -107,7 +109,8 @@ enum class Vis : unsigned char ToolTriangle, ToolCutSpline, ToolSplinePath, - ToolCutSplinePath + ToolCutSplinePath, + ToolLineIntersectAxis }; enum class Source : char { FromGui, FromFile, FromTool }; diff --git a/src/app/share/resources/cursor.qrc b/src/app/share/resources/cursor.qrc index 85b2d21f1..7e2665aeb 100644 --- a/src/app/share/resources/cursor.qrc +++ b/src/app/share/resources/cursor.qrc @@ -21,5 +21,6 @@ cursor/arc_cut_cursor.png cursor/cursor-arrow-closehand.png cursor/cursor-arrow-openhand.png + cursor/line_intersect_axis_cursor.png diff --git a/src/app/share/resources/cursor/line_intersect_axis_cursor.png b/src/app/share/resources/cursor/line_intersect_axis_cursor.png index cd3755a6e66d64e39a9d328140c79ff3e5521b3b..65554bbe44691b1d42417ebb976e5892d621c872 100644 GIT binary patch delta 1106 zcmV-Y1g-m<3E&BkQV9wZ3LOuQxWjajTTg!kAW1|)R7l6gmrF=oXB5YO-<>;79i3;I zI6j&*X%NyfX)LyA&@OZ#f{D>o>O#7xO~@3HOk0FB-Lz1;XefngOGqgQT_~}Flt30) zh^vGWVk#;WG;K;uYpq5Jj*q$Xoi5BBMr&-Mjy-VTe&=59dHm1$pL^l|l=J7$uR4FX zwzjGr4Imng-VKMtQdd_eB64U)o!8dZ4gpeJTrBDKn>TM})UOF(nkE1lq>jA3r$oi0i#Ow&X}xPJY5+_v}i^{I@NJzXrzVtRU7nwy)&vMidLn>lgf z#P&E}FJoIA4hP9(5r;g4%TrPQkP($W%cx0`{1ffxGw`#qJFl@ry~)l*w)xb;fE zULZ;-#>U2oL?UCev$J@;-uHnowhi;g1tTJ8tq~DMM@N~QoFpEPFWb-DxN+mjop03b z>p^0g<|-Jp)?B-G?c;`qhF^a>J3H@{m6dHBb33rL!C98|uV)4Z27*8^6bfyw;T#S} zie!{hXsz*hJW^U(s^;hCS23PtS(v6NBBDhknMfoIK!wBMrz4;G`ufy92gERp)QB}S zG(7b<9nH?(T>|~D!132XJrU+wYYf9kZ8W>FdU|>`TB&Zp@#tL&P!E3>7StSs;)daE z`T8q&>*P3%^f*+?%YS4 zVXpWJ3oZgOHTj1;nE8L3%a`wjU!~~Mr`#(WX8y|(3cfJ`5{U!=fj~f7T3YVMVzJK? ziNyG3X>%s;x%}UQQzyL-eGB_dm! YA3YVi7U2a!g8%>k07*qoM6N<$g8L62ga7~l delta 1036 zcmV+n1oQjg37ZL!QV9ti3@;*u<+>q}TTg!j+et)0R7l6gmt9C)XAp*;*>hHt1#L96 zu40o^MQCv?8dH^OC@L7KqAN(3LUJRtE-WVY$6~xFy$}7NrL@oz>5YQ5c#%6VWUtiJ zDp+D$P})K*N~5u~nwUL%rWfv6c8v-CtsVH_%y+)!oq1>G{m#PwY5o2ENq%Q%ryPH4 z06jfDzx#YXZEkK>RekFMc|;+g=aX#%jewx+>gP~C1frKP38 zii(OaQl5EBOUoRfhGD3PD4@N)y(6i{btO8{XcX0L=9iY1in_bIul4r!)*VacPWH|c z5v{AM(~*&pQz@%?qS>|$fU4qhxyXOX$)UZyeLZEgi)@d!h{T_rKn4c~5fSxzy;@ye z?MYe9oq8vlh+vu~s>;N~#HO=9Iyx#Tqdn0q%VKqPRRe*5T9!p15TLEC?P$Pv%h)l) zFo;H@05UW*1VCeB8K?xM{qFMd3 zpP#RXraiI4AJ>2)lH_k~ZQ=2F2#3Rk=NQJS!_JY;JBobk0mpPVOE2N!`9%NlepBDuZp? zjE#+b;P?A~9T*t+qpGUv@HKyT0^1p!Wm%7$35UbkK(^QGJy^pTh7lJT5y7@?GBPr> zqM|}JHa3zJ&$6tz@~JA3NCW_%&j)YQPvm&xOJv+<9)Kt>%B9VuDbMxzMr=g)?4$zX4k^^b= z4)7DeSHRUhiHvEQ*MTc{?%cUNJ3HIFU(g+TkRBVed#U{H^Z>cQ$;8d~q2MCiz6_x= z`8gC8mmW*6`)Z>T7Wlz z=~!RzCIJBZvz)dSoGo&uczg1H9)S70qx z(=1>S7(`_GU)2X5s8e|PBup*CKulgEzyrVyya~Jp-1-l1iJxpj3$0TC0000icon/path_config.png icon/16x16/info.png icon/16x16/measurement.png + icon/32x32/line_intersect_axis.png diff --git a/src/app/tools/drawTools/drawtools.h b/src/app/tools/drawTools/drawtools.h index 3a06646b1..2a3329ff5 100644 --- a/src/app/tools/drawTools/drawtools.h +++ b/src/app/tools/drawTools/drawtools.h @@ -47,5 +47,6 @@ #include "vtoolcutspline.h" #include "vtoolcutsplinepath.h" #include "vtoolcutarc.h" +#include "vtoollineintersectaxis.h" #endif // DRAWTOOLS_H diff --git a/src/app/tools/drawTools/vtoollineintersectaxis.cpp b/src/app/tools/drawTools/vtoollineintersectaxis.cpp new file mode 100644 index 000000000..70f625407 --- /dev/null +++ b/src/app/tools/drawTools/vtoollineintersectaxis.cpp @@ -0,0 +1,335 @@ +/************************************************************************ + ** + ** @file vtoollineintersectaxis.cpp + ** @author Roman Telezhynskyi + ** @date 19 10, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vtoollineintersectaxis.h" +#include "../../widgets/vmaingraphicsscene.h" +#include "../../container/calculator.h" +#include "../../dialogs/tools/dialoglineintersectaxis.h" +#include "../../dialogs/tools/dialogeditwrongformula.h" +#include "../../geometry/vpointf.h" +#include "./../visualization/vistoollineintersectaxis.h" + +const QString VToolLineIntersectAxis::ToolType = QStringLiteral("lineIntersectAxis"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolLineIntersectAxis::VToolLineIntersectAxis(VPattern *doc, VContainer *data, const quint32 &id, + const QString &typeLine, const QString &formulaAngle, + const quint32 &basePointId, const quint32 &firstPointId, + const quint32 &secondPointId, const Source &typeCreation, + QGraphicsItem *parent) + :VToolLinePoint(doc, data, id, typeLine, QString(), basePointId, 0, parent), formulaAngle(formulaAngle), + firstPointId(firstPointId), secondPointId(secondPointId) +{ + if (typeCreation == Source::FromGui) + { + AddToFile(); + } + else + { + RefreshDataInFile(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolLineIntersectAxis::~VToolLineIntersectAxis() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersectAxis::setDialog() +{ + SCASSERT(dialog != nullptr); + dialog->setModal(true); + DialogLineIntersectAxis *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const QSharedPointer p = VAbstractTool::data.GeometricObject(id); + dialogTool->setTypeLine(typeLine); + dialogTool->setAngle(formulaAngle); + dialogTool->setBasePointId(basePointId); + dialogTool->setFirstPointId(firstPointId); + dialogTool->setSecondPointId(secondPointId); + dialogTool->setPointName(p->name()); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolLineIntersectAxis *VToolLineIntersectAxis::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data) +{ + SCASSERT(dialog != nullptr); + DialogLineIntersectAxis *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool); + const QString pointName = dialogTool->getPointName(); + const QString typeLine = dialogTool->getTypeLine(); + QString formulaAngle = dialogTool->getAngle(); + const quint32 basePointId = dialogTool->getBasePointId(); + const quint32 firstPointId = dialogTool->getFirstPointId(); + const quint32 secondPointId = dialogTool->getSecondPointId(); + + VToolLineIntersectAxis *point = nullptr; + point=Create(0, pointName, typeLine, formulaAngle, basePointId, firstPointId, secondPointId, 5, 10, scene, doc, + data, Document::FullParse, Source::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolLineIntersectAxis *VToolLineIntersectAxis::Create(const quint32 _id, const QString &pointName, + const QString &typeLine, QString &formulaAngle, + const quint32 &basePointId, const quint32 &firstPointId, + const quint32 &secondPointId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation) +{ + const QSharedPointer basePoint = data->GeometricObject(basePointId); + QLineF axis = QLineF(basePoint->toQPointF(), QPointF(basePoint->x()+100, basePoint->y())); + axis.setAngle(CheckFormula(_id, formulaAngle, data)); + + const QSharedPointer firstPoint = data->GeometricObject(firstPointId); + const QSharedPointer secondPoint = data->GeometricObject(secondPointId); + QLineF line(firstPoint->toQPointF(), secondPoint->toQPointF()); + + QPointF fPoint = FindPoint(axis, line); + quint32 id = _id; + if (typeCreation == Source::FromGui) + { + id = data->AddGObject(new VPointF(fPoint, pointName, mx, my)); + data->AddLine(basePointId, id); + data->AddLine(firstPointId, id); + data->AddLine(id, secondPointId); + } + else + { + data->UpdateGObject(id, new VPointF(fPoint, pointName, mx, my)); + data->AddLine(basePointId, id); + data->AddLine(firstPointId, id); + data->AddLine(id, secondPointId); + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + VDrawTool::AddRecord(id, Tool::LineIntersectAxis, doc); + if (parse == Document::FullParse) + { + VToolLineIntersectAxis *point = new VToolLineIntersectAxis(doc, data, id, typeLine, formulaAngle, + basePointId, firstPointId, secondPointId, + typeCreation); + scene->addItem(point); + connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolPoint::Disable); + doc->AddTool(id, point); + doc->IncrementReferens(basePointId); + doc->IncrementReferens(firstPointId); + doc->IncrementReferens(secondPointId); + return point; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VToolLineIntersectAxis::FindPoint(const QLineF &axis, const QLineF &line) +{ + QPointF fPoint; + QLineF::IntersectType intersect = axis.intersect(line, &fPoint); + if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection) + { + return fPoint; + } + else + { + return QPointF(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolLineIntersectAxis::getFormulaAngle() const +{ + VFormula fAngle(formulaAngle, getData()); + fAngle.setCheckZero(false); + fAngle.setToolId(id); + fAngle.setPostfix(QStringLiteral("°")); + return fAngle; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersectAxis::setFormulaAngle(const VFormula &value) +{ + if (value.error() == false) + { + formulaAngle = value.getFormula(FormulaType::FromUser); + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolLineIntersectAxis::getFirstPointId() const +{ + return firstPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersectAxis::setFirstPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + firstPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolLineIntersectAxis::getSecondPointId() const +{ + return secondPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersectAxis::setSecondPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + secondPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersectAxis::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolLineIntersectAxis * visual = new VisToolLineIntersectAxis(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(firstPointId); + visual->setPoint2Id(secondPointId); + visual->setAxisPointId(basePointId); + visual->setAngle(qApp->FormulaToUser(formulaAngle)); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolLineIntersectAxis *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersectAxis::FullUpdateFromFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + typeLine = domElement.attribute(AttrTypeLine, ""); + basePointId = domElement.attribute(AttrBasePoint, "").toUInt(); + firstPointId = domElement.attribute(AttrP1Line, "").toUInt(); + secondPointId = domElement.attribute(AttrP2Line, "").toUInt(); + formulaAngle = domElement.attribute(AttrAngle, ""); + } + RefreshGeometry(); + + if (vis != nullptr) + { + VisToolLineIntersectAxis *visual = qobject_cast(vis); + visual->setPoint1Id(firstPointId); + visual->setPoint2Id(secondPointId); + visual->setAxisPointId(basePointId); + visual->setAngle(qApp->FormulaToUser(formulaAngle)); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersectAxis::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(this, event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersectAxis::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(this, event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersectAxis::SaveDialog(QDomElement &domElement) +{ + SCASSERT(dialog != nullptr); + DialogLineIntersectAxis *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); + doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); + doc->SetAttribute(domElement, AttrAngle, dialogTool->getAngle()); + doc->SetAttribute(domElement, AttrBasePoint, QString().setNum(dialogTool->getBasePointId())); + doc->SetAttribute(domElement, AttrP1Line, QString().setNum(dialogTool->getFirstPointId())); + doc->SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->getSecondPointId())); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersectAxis::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); + + doc->SetAttribute(tag, AttrTypeLine, typeLine); + doc->SetAttribute(tag, AttrAngle, formulaAngle); + doc->SetAttribute(tag, AttrBasePoint, basePointId); + doc->SetAttribute(tag, AttrP1Line, firstPointId); + doc->SetAttribute(tag, AttrP2Line, secondPointId); +} diff --git a/src/app/tools/drawTools/vtoollineintersectaxis.h b/src/app/tools/drawTools/vtoollineintersectaxis.h new file mode 100644 index 000000000..b7ddb00d7 --- /dev/null +++ b/src/app/tools/drawTools/vtoollineintersectaxis.h @@ -0,0 +1,82 @@ +/************************************************************************ + ** + ** @file vtoollineintersectaxis.h + ** @author Roman Telezhynskyi + ** @date 19 10, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VTOOLLINEINTERSECTAXIS_H +#define VTOOLLINEINTERSECTAXIS_H + +#include "vtoollinepoint.h" + +class VToolLineIntersectAxis : public VToolLinePoint +{ + Q_OBJECT +public: + VToolLineIntersectAxis(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &formulaAngle, const quint32 &basePointId, const quint32 &firstPointId, + const quint32 &secondPointId, const Source &typeCreation, QGraphicsItem * parent = nullptr); + virtual ~VToolLineIntersectAxis(); + virtual void setDialog(); + + static VToolLineIntersectAxis *Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data); + static VToolLineIntersectAxis *Create(const quint32 _id, const QString &pointName, const QString &typeLine, + QString &formulaAngle, const quint32 &basePointId, + const quint32 &firstPointId, const quint32 &secondPointId, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document &parse, const Source &typeCreation); + + static QPointF FindPoint(const QLineF &axis, const QLineF &line); + + static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::LineIntersectAxis)}; + + VFormula getFormulaAngle() const; + void setFormulaAngle(const VFormula &value); + + quint32 getFirstPointId() const; + void setFirstPointId(const quint32 &value); + + quint32 getSecondPointId() const; + void setSecondPointId(const quint32 &value); + + virtual void ShowVisualization(bool show); +public slots: + virtual void FullUpdateFromFile(); + virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); +private: + Q_DISABLE_COPY(VToolLineIntersectAxis) + QString formulaAngle; + quint32 firstPointId; + quint32 secondPointId; +}; + +#endif // VTOOLLINEINTERSECTAXIS_H diff --git a/src/app/tools/tools.pri b/src/app/tools/tools.pri index 7b8dd50f2..91b9f8e7e 100644 --- a/src/app/tools/tools.pri +++ b/src/app/tools/tools.pri @@ -33,7 +33,8 @@ HEADERS += \ tools/vtooluniondetails.h \ tools/drawTools/vtoolcutarc.h \ tools/drawTools/vabstractspline.h \ - tools/drawTools/vtoolcut.h + tools/drawTools/vtoolcut.h \ + tools/drawTools/vtoollineintersectaxis.h SOURCES += \ tools/vtooldetail.cpp \ @@ -67,4 +68,5 @@ SOURCES += \ tools/vtooluniondetails.cpp \ tools/drawTools/vtoolcutarc.cpp \ tools/drawTools/vabstractspline.cpp \ - tools/drawTools/vtoolcut.cpp + tools/drawTools/vtoolcut.cpp \ + tools/drawTools/vtoollineintersectaxis.cpp diff --git a/src/app/visualization/vistoollineintersectaxis.cpp b/src/app/visualization/vistoollineintersectaxis.cpp new file mode 100644 index 000000000..7bde1a9f1 --- /dev/null +++ b/src/app/visualization/vistoollineintersectaxis.cpp @@ -0,0 +1,142 @@ +/************************************************************************ + ** + ** @file vislineintersectaxis.cpp + ** @author Roman Telezhynskyi + ** @date 19 10, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vistoollineintersectaxis.h" +#include "../container/vcontainer.h" +#include "../geometry/vpointf.h" +#include "../tools/drawTools/vtoollineintersectaxis.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolLineIntersectAxis::VisToolLineIntersectAxis(const VContainer *data, QGraphicsItem *parent) + : VisLine(data, parent), point2Id(NULL_ID), axisPointId(NULL_ID), angle(-1), point(nullptr), lineP1(nullptr), + lineP2(nullptr), basePoint(nullptr), baseLine(nullptr), axisLine(nullptr), line_intersection(nullptr) +{ + this->mainColor = Qt::red; + + lineP1 = InitPoint(supportColor, this); + lineP2 = InitPoint(supportColor, this); + basePoint = InitPoint(supportColor, this); + baseLine = InitItem(supportColor, this); + axisLine = InitItem(supportColor, this); + line_intersection = InitItem(supportColor, this); + point = InitPoint(mainColor, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolLineIntersectAxis::~VisToolLineIntersectAxis() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolLineIntersectAxis::RefreshGeometry() +{ + if (point1Id > 0) + { + const QSharedPointer first = Visualization::data->GeometricObject(point1Id); + DrawPoint(lineP1, first->toQPointF(), supportColor); + + if (point2Id <= 0) + { + DrawLine(baseLine, QLineF(first->toQPointF(), Visualization::scenePos), supportColor); + } + else + { + const QSharedPointer second = Visualization::data->GeometricObject(point2Id); + DrawPoint(lineP2, second->toQPointF(), supportColor); + + const QLineF base_line(first->toQPointF(), second->toQPointF()); + DrawLine(baseLine, base_line, supportColor); + + if (axisPointId > NULL_ID) + { + QLineF axis; + const QSharedPointer third = Visualization::data->GeometricObject(axisPointId); + if (qFuzzyCompare(angle, -1)) + { + axis = Axis(third->toQPointF(), Visualization::scenePos); + } + else + { + axis = Axis(third->toQPointF(), angle); + } + DrawPoint(basePoint, third->toQPointF(), mainColor); + DrawLine(axisLine, axis, supportColor, Qt::DashLine); + + QPointF p = VToolLineIntersectAxis::FindPoint(axis, base_line); + QLineF axis_line(third->toQPointF(), p); + DrawLine(this, axis_line, mainColor, lineStyle); + + DrawPoint(point, p, mainColor); + ShowIntersection(axis_line, base_line); + + Visualization::toolTip = QString(tr("Intersection line and axis: angle = %1°; Shift - " + "sticking angle, Enter - finish creation")) + .arg(this->line().angle()); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VisToolLineIntersectAxis::Angle() const +{ + return QString("%1").arg(this->line().angle()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolLineIntersectAxis::setAngle(const QString &expression) +{ + angle = FindVal(expression); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolLineIntersectAxis::setPoint2Id(const quint32 &value) +{ + point2Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolLineIntersectAxis::setAxisPointId(const quint32 &value) +{ + axisPointId = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolLineIntersectAxis::ShowIntersection(const QLineF &axis_line, const QLineF &base_line) +{ + QPointF p; + QLineF::IntersectType intersect = axis_line.intersect(base_line, &p); + if (intersect == QLineF::UnboundedIntersection) + { + line_intersection->setVisible(true); + DrawLine(line_intersection, QLineF(base_line.p1(), axis_line.p2()), supportColor, Qt::DashLine); + } + else if (intersect == QLineF::BoundedIntersection || intersect == QLineF::NoIntersection) + { + line_intersection->setVisible(false); + } +} diff --git a/src/app/visualization/vistoollineintersectaxis.h b/src/app/visualization/vistoollineintersectaxis.h new file mode 100644 index 000000000..f9f0f370e --- /dev/null +++ b/src/app/visualization/vistoollineintersectaxis.h @@ -0,0 +1,67 @@ +/************************************************************************ + ** + ** @file vistoollineintersectaxis.h + ** @author Roman Telezhynskyi + ** @date 19 10, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VISTOOLLINEINTERSECTAXIS_H +#define VISTOOLLINEINTERSECTAXIS_H + +#include "visline.h" + +class QGraphicsEllipseItem; + +class VisToolLineIntersectAxis : public VisLine +{ + Q_OBJECT +public: + VisToolLineIntersectAxis(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolLineIntersectAxis(); + + virtual void RefreshGeometry(); + + QString Angle() const; + void setAngle(const QString &expression); + void setPoint2Id(const quint32 &value); + void setAxisPointId(const quint32 &value); + + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolLineIntersectAxis)}; +private: + Q_DISABLE_COPY(VisToolLineIntersectAxis) + quint32 point2Id; + quint32 axisPointId; + qreal angle; + QGraphicsEllipseItem *point; + QGraphicsEllipseItem *lineP1; + QGraphicsEllipseItem *lineP2; + QGraphicsEllipseItem *basePoint; + QGraphicsLineItem *baseLine; + QGraphicsLineItem *axisLine; + QGraphicsLineItem *line_intersection; + void ShowIntersection(const QLineF &axis_line, const QLineF &base_line); +}; + +#endif // VISTOOLLINEINTERSECTAXIS_H diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index abd4a6ea3..9ef86c176 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -21,7 +21,8 @@ HEADERS += \ visualization/vistoolspline.h \ visualization/vistoolcutspline.h \ visualization/vistoolsplinepath.h \ - visualization/vistoolcutsplinepath.h + visualization/vistoolcutsplinepath.h \ + visualization/vistoollineintersectaxis.h SOURCES += \ visualization/vgraphicssimpletextitem.cpp \ @@ -46,4 +47,5 @@ SOURCES += \ visualization/vistoolspline.cpp \ visualization/vistoolcutspline.cpp \ visualization/vistoolsplinepath.cpp \ - visualization/vistoolcutsplinepath.cpp + visualization/vistoolcutsplinepath.cpp \ + visualization/vistoollineintersectaxis.cpp diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index ede009724..13f6d9e62 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -131,6 +131,9 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) currentItem = item->parentItem(); ShowItemOptions(currentItem); break; + case VToolLineIntersectAxis::Type: + ShowOptionsToolLineIntersectAxis(item); + break; default: break; } @@ -206,6 +209,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions() case VControlPointSpline::Type: ShowItemOptions(currentItem->parentItem()); break; + case VToolLineIntersectAxis::Type: + UpdateOptionsToolLineIntersectAxis(); + break; default: break; } @@ -288,6 +294,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) case VToolTriangle::Type: ChangeDataToolTriangle(prop); break; + case VToolLineIntersectAxis::Type: + ChangeDataToolLineIntersectAxis(prop); + break; default: break; } @@ -842,6 +851,33 @@ void VToolOptionsPropertyBrowser::ChangeDataToolTriangle(VProperty *property) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolLineIntersectAxis(VProperty *property) +{ + SCASSERT(property != nullptr) + + QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolLineIntersectAxis *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + case 5: // VAbstractTool::AttrAngle + i->setFormulaAngle(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<(item); + i->ShowVisualization(true); + formView->setTitle(tr("Point intersection line and axis")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyLineType(i, tr("Line type")); + AddPropertyFormula(tr("Angle"), i->getFormulaAngle(), VAbstractTool::AttrAngle); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolSinglePoint() { @@ -1288,6 +1336,21 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolTriangle() idToProperty[VAbstractTool::AttrName]->setValue(i->name()); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolLineIntersectAxis() +{ + VToolLineIntersectAxis *i = qgraphicsitem_cast(currentItem); + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); + + QVariant valueAngle; + valueAngle.setValue(i->getFormulaAngle()); + idToProperty[VAbstractTool::AttrAngle]->setValue(valueAngle); +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VToolOptionsPropertyBrowser::PropertiesList() const { diff --git a/src/app/widgets/vtooloptionspropertybrowser.h b/src/app/widgets/vtooloptionspropertybrowser.h index 23d0c00ef..99d346558 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.h +++ b/src/app/widgets/vtooloptionspropertybrowser.h @@ -94,6 +94,7 @@ private: void ChangeDataToolSpline(VPE::VProperty *property); void ChangeDataToolSplinePath(VPE::VProperty *property); void ChangeDataToolTriangle(VPE::VProperty *property); + void ChangeDataToolLineIntersectAxis(VPE::VProperty *property); void ShowOptionsToolSinglePoint(QGraphicsItem *item); void ShowOptionsToolEndLine(QGraphicsItem *item); @@ -113,6 +114,7 @@ private: void ShowOptionsToolSpline(QGraphicsItem *item); void ShowOptionsToolSplinePath(QGraphicsItem *item); void ShowOptionsToolTriangle(QGraphicsItem *item); + void ShowOptionsToolLineIntersectAxis(QGraphicsItem *item); void UpdateOptionsToolSinglePoint(); void UpdateOptionsToolEndLine(); @@ -132,6 +134,7 @@ private: void UpdateOptionsToolSpline(); void UpdateOptionsToolSplinePath(); void UpdateOptionsToolTriangle(); + void UpdateOptionsToolLineIntersectAxis(); }; #endif // VTOOLOPTIONSPROPERTYBROWSER_H diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 3c85df9fe..49f878ea2 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -1077,7 +1077,8 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem << VToolLineIntersect::ToolType << VToolPointOfContact::ToolType << VNodePoint::ToolType << VToolHeight::ToolType << VToolTriangle::ToolType << VToolPointOfIntersection::ToolType << VToolCutSpline::ToolType - << VToolCutSplinePath::ToolType << VToolCutArc::ToolType; + << VToolCutSplinePath::ToolType << VToolCutArc::ToolType + << VToolLineIntersectAxis::ToolType; switch (points.indexOf(type)) { case 0: //VToolSinglePoint::ToolType @@ -1489,6 +1490,42 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem throw excep; } break; + case 15: //VToolLineIntersectAxis::ToolType + try + { + PointsCommonAttributes(domElement, id, name, mx, my, typeLine); + + const quint32 basePointId = GetParametrUInt(domElement, VAbstractTool::AttrBasePoint, "0"); + const quint32 firstPointId = GetParametrUInt(domElement, VAbstractTool::AttrP1Line, "0"); + const quint32 secondPointId = GetParametrUInt(domElement, VAbstractTool::AttrP2Line, "0"); + + const QString angle = GetParametrString(domElement, VAbstractTool::AttrAngle, "0.0"); + QString angleFix = angle; + + VToolLineIntersectAxis::Create(id, name, typeLine, angleFix, basePointId, firstPointId, secondPointId, + mx, my, scene, this, data, parse, Source::FromFile); + //Rewrite attribute formula. Need for situation when we have wrong formula. + if (angleFix != angle) + { + SetAttribute(domElement, VAbstractTool::AttrAngle, angleFix); + haveLiteChange(); + } + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating point of intersection line and axis"), + domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + catch (qmu::QmuParserError &e) + { + VExceptionObjectError excep(tr("Error creating or updating point of intersection line and axis"), + domElement); + excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr())); + throw excep; + } + break; default: qDebug() << "Illegal point type in VDomDocument::ParsePointElement()."; break;