diff --git a/src/app/dialogs/app/dialoghistory.cpp b/src/app/dialogs/app/dialoghistory.cpp index 7e80e91b6..143dc33a3 100644 --- a/src/app/dialogs/app/dialoghistory.cpp +++ b/src/app/dialogs/app/dialoghistory.cpp @@ -384,6 +384,10 @@ QString DialogHistory::Record(const VToolRecord &tool) .arg(PointName(tool.getId())) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrBasePoint))); } + case Tool::PointOfIntersectionArcs: + { + return QString(tr("%1 - point of arcs intersection")).arg(PointName(tool.getId())); + } //Because "history" not only show history of pattern, but help restore current data for each pattern's //piece, we need add record about details and nodes, but don't show them. case Tool::Detail: diff --git a/src/app/dialogs/dialogs.h b/src/app/dialogs/dialogs.h index 27195b696..2751cdf0f 100644 --- a/src/app/dialogs/dialogs.h +++ b/src/app/dialogs/dialogs.h @@ -51,6 +51,7 @@ #include "tools/dialogpointofintersection.h" #include "tools/dialoglineintersectaxis.h" #include "tools/dialogcurveintersectaxis.h" +#include "tools/dialogpointofintersectionarcs.h" #include "app/dialoghistory.h" #include "app/dialogincrements.h" diff --git a/src/app/dialogs/dialogs.pri b/src/app/dialogs/dialogs.pri index 0e684e367..27409388e 100644 --- a/src/app/dialogs/dialogs.pri +++ b/src/app/dialogs/dialogs.pri @@ -44,7 +44,8 @@ HEADERS += \ $$PWD/tools/dialogcurveintersectaxis.h \ $$PWD/app/dialoglayoutsettings.h \ $$PWD/app/dialoglayoutprogress.h \ - dialogs/app/dialogsavelayout.h + $$PWD/app/dialogsavelayout.h \ + $$PWD/tools/dialogpointofintersectionarcs.h SOURCES += \ $$PWD/tools/dialogtriangle.cpp \ @@ -87,7 +88,8 @@ SOURCES += \ $$PWD/tools/dialogcurveintersectaxis.cpp \ $$PWD/app/dialoglayoutsettings.cpp \ $$PWD/app/dialoglayoutprogress.cpp \ - dialogs/app/dialogsavelayout.cpp + $$PWD/app/dialogsavelayout.cpp \ + $$PWD/tools/dialogpointofintersectionarcs.cpp FORMS += \ $$PWD/tools/dialogtriangle.ui \ @@ -124,4 +126,5 @@ FORMS += \ $$PWD/tools/dialogcurveintersectaxis.ui \ $$PWD/app/dialoglayoutsettings.ui \ $$PWD/app/dialoglayoutprogress.ui \ - dialogs/app/dialogsavelayout.ui + $$PWD/app/dialogsavelayout.ui \ + $$PWD/tools/dialogpointofintersectionarcs.ui diff --git a/src/app/dialogs/tools/dialogpointofintersection.cpp b/src/app/dialogs/tools/dialogpointofintersection.cpp index 1c60117e5..1870f8204 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.cpp +++ b/src/app/dialogs/tools/dialogpointofintersection.cpp @@ -165,17 +165,7 @@ void DialogPointOfIntersection::PointNameChanged() //--------------------------------------------------------------------------------------------------------------------- void DialogPointOfIntersection::ShowVisualization() { - if (prepare == false) - { - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr); - - VisToolPointOfIntersection *toolVis = qobject_cast(vis); - SCASSERT(toolVis != nullptr); - - connect(scene, &VMainGraphicsScene::NewFactor, toolVis, &Visualization::SetFactor); - toolVis->RefreshGeometry(); - } + AddVisualization(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogpointofintersectionarcs.cpp b/src/app/dialogs/tools/dialogpointofintersectionarcs.cpp new file mode 100644 index 000000000..2246568b8 --- /dev/null +++ b/src/app/dialogs/tools/dialogpointofintersectionarcs.cpp @@ -0,0 +1,235 @@ +/************************************************************************ + ** + ** @file dialogpointofintersectionarcs.cpp + ** @author Roman Telezhynskyi + ** @date 25 5, 2015 + ** + ** @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) 2015 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 "dialogpointofintersectionarcs.h" +#include "ui_dialogpointofintersectionarcs.h" + +#include "../../libs/vgeometry/vpointf.h" +#include "../../container/vcontainer.h" +#include "../../visualization/vistoolpointofintersectionarcs.h" +#include "../../widgets/vmaingraphicsscene.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogPointOfIntersectionArcs::DialogPointOfIntersectionArcs(const VContainer *data, const quint32 &toolId, + QWidget *parent) + :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfIntersectionArcs) +{ + ui->setupUi(this); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); + labelEditNamePoint = ui->labelEditNamePoint; + + InitOkCancelApply(ui); + CheckState(); + + FillComboBoxArcs(ui->comboBoxArc1); + FillComboBoxArcs(ui->comboBoxArc2); + FillComboBoxCrossArcPoints(); + + connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointOfIntersectionArcs::NamePointChanged); + connect(ui->comboBoxArc1, static_cast(&QComboBox::currentIndexChanged), + this, &DialogPointOfIntersectionArcs::ArcChanged); + connect(ui->comboBoxArc1, static_cast(&QComboBox::currentIndexChanged), + this, &DialogPointOfIntersectionArcs::ArcChanged); + + vis = new VisToolPointOfIntersectionArcs(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogPointOfIntersectionArcs::~DialogPointOfIntersectionArcs() +{ + DeleteVisualization(); + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionArcs::SetPointName(const QString &value) +{ + pointName = value; + ui->lineEditNamePoint->setText(pointName); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogPointOfIntersectionArcs::GetFirstArcId() const +{ + return getCurrentObjectId(ui->comboBoxArc1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionArcs::SetFirstArcId(const quint32 &value) +{ + setCurrentPointId(ui->comboBoxArc1, value); + + VisToolPointOfIntersectionArcs *point = qobject_cast(vis); + SCASSERT(point != nullptr); + point->setArc1Id(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogPointOfIntersectionArcs::GetSecondArcId() const +{ + return getCurrentObjectId(ui->comboBoxArc2); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionArcs::SetSecondArcId(const quint32 &value) +{ + setCurrentPointId(ui->comboBoxArc2, value); + + VisToolPointOfIntersectionArcs *point = qobject_cast(vis); + SCASSERT(point != nullptr); + point->setArc2Id(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +CrossArcsPoint DialogPointOfIntersectionArcs::GetCrossArcPoint() const +{ + int value; + bool ok = false; +#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + value = ui->comboBoxResult->itemData(box->currentIndex()).toInt(&ok); +#else + value = ui->comboBoxResult->currentData().toInt(&ok); +#endif + if (not ok) + { + return CrossArcsPoint::FirstPoint; + } + + switch(value) + { + case 1: + return CrossArcsPoint::FirstPoint; + break; + case 2: + return CrossArcsPoint::SecondPoint; + break; + default: + return CrossArcsPoint::FirstPoint; + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionArcs::SetCrossArcPoint(CrossArcsPoint &p) +{ + const qint32 index = ui->comboBoxResult->findData(static_cast(p)); + if (index != -1) + { + ui->comboBoxResult->setCurrentIndex(index); + + VisToolPointOfIntersectionArcs *point = qobject_cast(vis); + SCASSERT(point != nullptr); + point->setCrossPoint(p); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionArcs::ChosenObject(quint32 id, const SceneObject &type) +{ + if (prepare == false)// After first choose we ignore all objects + { + if (type == SceneObject::Arc) + { + VisToolPointOfIntersectionArcs *point = qobject_cast(vis); + SCASSERT(point != nullptr); + + switch (number) + { + case 0: + if (SetObject(id, ui->comboBoxArc1, tr("Select second an arc"))) + { + number++; + point->VisualMode(id); + } + break; + case 1: + if (getCurrentObjectId(ui->comboBoxArc1) != id) + { + if (SetObject(id, ui->comboBoxArc2, "")) + { + number = 0; + point->setArc2Id(id); + point->RefreshGeometry(); + prepare = true; + this->setModal(true); + this->show(); + } + } + break; + default: + break; + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionArcs::ArcChanged() +{ + QColor color = okColor; + if (getCurrentObjectId(ui->comboBoxArc1) == getCurrentObjectId(ui->comboBoxArc2)) + { + flagError = false; + color = errorColor; + } + else + { + flagError = true; + color = okColor; + } + ChangeColor(ui->labelArc1, color); + ChangeColor(ui->labelArc2, color); + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionArcs::ShowVisualization() +{ + AddVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionArcs::SaveData() +{ + pointName = ui->lineEditNamePoint->text(); + + VisToolPointOfIntersectionArcs *point = qobject_cast(vis); + SCASSERT(point != nullptr); + + point->setArc1Id(GetFirstArcId()); + point->setArc2Id(GetSecondArcId()); + point->setCrossPoint(GetCrossArcPoint()); + point->RefreshGeometry(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionArcs::FillComboBoxCrossArcPoints() +{ + ui->comboBoxResult->addItem(tr("First point"), QVariant(static_cast(CrossArcsPoint::FirstPoint))); + ui->comboBoxResult->addItem(tr("Second point"), QVariant(static_cast(CrossArcsPoint::SecondPoint))); +} diff --git a/src/app/dialogs/tools/dialogpointofintersectionarcs.h b/src/app/dialogs/tools/dialogpointofintersectionarcs.h new file mode 100644 index 000000000..a555e42c3 --- /dev/null +++ b/src/app/dialogs/tools/dialogpointofintersectionarcs.h @@ -0,0 +1,78 @@ +/************************************************************************ + ** + ** @file dialogpointofintersectionarcs.h + ** @author Roman Telezhynskyi + ** @date 25 5, 2015 + ** + ** @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) 2015 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 DIALOGPOINTOFINTERSECTIONARCS_H +#define DIALOGPOINTOFINTERSECTIONARCS_H + +#include "dialogtool.h" +#include "../../xml/vpattern.h" + +namespace Ui +{ + class DialogPointOfIntersectionArcs; +} + +class DialogPointOfIntersectionArcs : public DialogTool +{ + Q_OBJECT + +public: + explicit DialogPointOfIntersectionArcs(const VContainer *data, const quint32 &toolId, QWidget *parent = 0); + virtual ~DialogPointOfIntersectionArcs(); + + void SetPointName(const QString &value); + + quint32 GetFirstArcId() const; + void SetFirstArcId(const quint32 &value); + + quint32 GetSecondArcId() const; + void SetSecondArcId(const quint32 &value); + + CrossArcsPoint GetCrossArcPoint() const; + void SetCrossArcPoint(CrossArcsPoint &p); + +public slots: + virtual void ChosenObject(quint32 id, const SceneObject &type); + virtual void ArcChanged(); + +protected: + virtual void ShowVisualization(); + /** + * @brief SaveData Put dialog data in local variables + */ + virtual void SaveData(); + +private: + Q_DISABLE_COPY(DialogPointOfIntersectionArcs) + + Ui::DialogPointOfIntersectionArcs *ui; + + void FillComboBoxCrossArcPoints(); +}; + +#endif // DIALOGPOINTOFINTERSECTIONARCS_H diff --git a/src/app/dialogs/tools/dialogpointofintersectionarcs.ui b/src/app/dialogs/tools/dialogpointofintersectionarcs.ui new file mode 100644 index 000000000..f6f9ebc12 --- /dev/null +++ b/src/app/dialogs/tools/dialogpointofintersectionarcs.ui @@ -0,0 +1,149 @@ + + + DialogPointOfIntersectionArcs + + + + 0 + 0 + 300 + 179 + + + + + 300 + 179 + + + + + 300 + 179 + + + + Dialog + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + + 0 + 0 + + + + Point label + + + + + + + + + + + 0 + 0 + + + + First arc + + + + + + + Selected arc + + + + + + + + 0 + 0 + + + + Second arc + + + + + + + Selected arc + + + + + + + Take + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DialogPointOfIntersectionArcs + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogPointOfIntersectionArcs + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index e38a66335..d95c618e2 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -695,6 +695,16 @@ void MainWindow::ToolCurveIntersectAxis(bool checked) &MainWindow::ApplyDialog); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolPointOfIntersectionArcs(bool checked) +{ + SetToolButtonWithApply(checked, Tool::PointOfIntersectionArcs, + "://cursor/point_of_intersection_arcs.png", + tr("Select first an arc"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief About show widows about. @@ -990,6 +1000,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonCurveIntersectAxis, &QToolButton::clicked, this, &MainWindow::ToolCurveIntersectAxis); connect(ui->toolButtonArcIntersectAxis, &QToolButton::clicked, this, &MainWindow::ToolCurveIntersectAxis); connect(ui->toolButtonLayoutSettings, &QToolButton::clicked, this, &MainWindow::ToolLayoutSettings); + connect(ui->toolButtonPointOfIntersectionArcs, &QToolButton::clicked, this, &MainWindow::ToolPointOfIntersectionArcs); } //--------------------------------------------------------------------------------------------------------------------- @@ -1103,6 +1114,9 @@ void MainWindow::CancelTool() ui->toolButtonCurveIntersectAxis->setChecked(false); ui->toolButtonArcIntersectAxis->setChecked(false); break; + case Tool::PointOfIntersectionArcs: + ui->toolButtonPointOfIntersectionArcs->setChecked(false); + break; case Tool::NodePoint: case Tool::NodeArc: case Tool::NodeSpline: @@ -2128,6 +2142,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonLineIntersectAxis->setEnabled(drawTools); ui->toolButtonCurveIntersectAxis->setEnabled(drawTools); ui->toolButtonArcIntersectAxis->setEnabled(drawTools); + ui->toolButtonPointOfIntersectionArcs->setEnabled(drawTools); ui->actionLast_tool->setEnabled(drawTools); @@ -2462,6 +2477,10 @@ void MainWindow::LastUsedTool() ui->toolButtonPointOfIntersection->setChecked(true); ToolPointOfIntersection(true); break; + case Tool::PointOfIntersectionArcs: + ui->toolButtonPointOfIntersectionArcs->setChecked(true); + ToolPointOfIntersectionArcs(true); + break; case Tool::CutSpline: ui->toolButtonSplineCutPoint->setChecked(true); ToolCutSpline(true); diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index a6778c7dd..077115283 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -115,12 +115,13 @@ public slots: void ToolCutArc(bool checked); void ToolLineIntersectAxis(bool checked); void ToolCurveIntersectAxis(bool checked); + void ToolPointOfIntersectionArcs(bool checked); void ClosedDialogDetail(int result); void ClosedDialogUnionDetails(int result); //tmp - void LastUsedTool(); + void LastUsedTool(); /** * @brief Edit XML code of pattern diff --git a/src/app/mainwindow.ui b/src/app/mainwindow.ui index d3f5123c9..b4dc108bb 100644 --- a/src/app/mainwindow.ui +++ b/src/app/mainwindow.ui @@ -43,14 +43,14 @@ - 4 + 3 0 0 - 105 + 100 272 @@ -337,7 +337,7 @@ 0 0 - 105 + 100 58 @@ -413,7 +413,7 @@ 0 0 - 105 + 100 156 @@ -662,6 +662,32 @@ + + + + false + + + Point of intersection arcs + + + ... + + + + :/icon/32x32/point_of_intersection_arcs.png:/icon/32x32/point_of_intersection_arcs.png + + + + 32 + 32 + + + + true + + + @@ -669,7 +695,7 @@ 0 0 - 105 + 100 58 @@ -745,8 +771,8 @@ 0 0 - 105 - 380 + 98 + 58 diff --git a/src/app/options.h b/src/app/options.h index 395fc5b8f..f65601b42 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -86,14 +86,15 @@ enum class Tool : unsigned char Height, Triangle, LineIntersectAxis, + PointOfIntersectionArcs, CurveIntersectAxis, PointOfIntersection, - UnionDetails // 30 + UnionDetails // 31 }; enum class Vis : unsigned char { - ControlPointSpline = 31, // increase this value if need more positions in Tool enum + ControlPointSpline = 32, // increase this value if need more positions in Tool enum GraphicsSimpleTextItem, SimpleSplinePath, Line, @@ -109,6 +110,7 @@ enum class Vis : unsigned char ToolNormal, ToolPointOfContact, ToolPointOfIntersection, + ToolPointOfIntersectionArcs, ToolShoulderPoint, ToolSpline, ToolTriangle, diff --git a/src/app/share/resources/cursor.qrc b/src/app/share/resources/cursor.qrc index 1aec9decd..5dacc775f 100644 --- a/src/app/share/resources/cursor.qrc +++ b/src/app/share/resources/cursor.qrc @@ -24,5 +24,6 @@ cursor/line_intersect_axis_cursor.png cursor/arc_intersect_axis_cursor.png cursor/curve_intersect_axis_cursor.png + cursor/point_of_intersection_arcs.png diff --git a/src/app/share/resources/cursor/point_of_intersection_arcs.png b/src/app/share/resources/cursor/point_of_intersection_arcs.png new file mode 100644 index 000000000..fda5eb7af Binary files /dev/null and b/src/app/share/resources/cursor/point_of_intersection_arcs.png differ diff --git a/src/app/share/resources/icon.qrc b/src/app/share/resources/icon.qrc index 4b33c74c8..810b2602c 100644 --- a/src/app/share/resources/icon.qrc +++ b/src/app/share/resources/icon.qrc @@ -61,5 +61,6 @@ icon/16x16/roll.png icon/16x16/progress.gif icon/32x32/export_to_picture_document.png + icon/32x32/point_of_intersection_arcs.png diff --git a/src/app/share/resources/icon/32x32/point_of_intersection_arcs.png b/src/app/share/resources/icon/32x32/point_of_intersection_arcs.png new file mode 100644 index 000000000..e9e583428 Binary files /dev/null and b/src/app/share/resources/icon/32x32/point_of_intersection_arcs.png differ diff --git a/src/app/share/resources/icon/svg/point_of_intersection_arcs.svg b/src/app/share/resources/icon/svg/point_of_intersection_arcs.svg new file mode 100644 index 000000000..6060afdd2 --- /dev/null +++ b/src/app/share/resources/icon/svg/point_of_intersection_arcs.svg @@ -0,0 +1,101 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/src/app/tools/drawTools/drawtools.h b/src/app/tools/drawTools/drawtools.h index 804266cb5..b8f771bf8 100644 --- a/src/app/tools/drawTools/drawtools.h +++ b/src/app/tools/drawTools/drawtools.h @@ -44,6 +44,7 @@ #include "vtoolheight.h" #include "vtooltriangle.h" #include "vtoolpointofintersection.h" +#include "vtoolpointofintersectionarcs.h" #include "vtoolcutspline.h" #include "vtoolcutsplinepath.h" #include "vtoolcutarc.h" diff --git a/src/app/tools/drawTools/vtoolpointofintersectionarcs.cpp b/src/app/tools/drawTools/vtoolpointofintersectionarcs.cpp new file mode 100644 index 000000000..d20d33509 --- /dev/null +++ b/src/app/tools/drawTools/vtoolpointofintersectionarcs.cpp @@ -0,0 +1,290 @@ +/************************************************************************ + ** + ** @file vtoolpointofintersectionarcs.cpp + ** @author Roman Telezhynskyi + ** @date 25 5, 2015 + ** + ** @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) 2015 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 "vtoolpointofintersectionarcs.h" +#include "../../dialogs/tools/dialogpointofintersectionarcs.h" +#include "../../libs/vgeometry/vpointf.h" +#include "../../libs/vgeometry/varc.h" +#include "../../visualization/vistoolpointofintersectionarcs.h" + +const QString VToolPointOfIntersectionArcs::ToolType = QStringLiteral("pointOfIntersectionArcs"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolPointOfIntersectionArcs::VToolPointOfIntersectionArcs(VPattern *doc, VContainer *data, const quint32 &id, + const quint32 &firstArcId, const quint32 &secondArcId, + CrossArcsPoint pType, const Source &typeCreation, + QGraphicsItem *parent) + :VToolPoint(doc, data, id, parent), firstArcId(firstArcId), secondArcId(secondArcId), crossPoint(pType) +{ + if (typeCreation == Source::FromGui) + { + AddToFile(); + } + else + { + RefreshDataInFile(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersectionArcs::setDialog() +{ + SCASSERT(dialog != nullptr); + DialogPointOfIntersectionArcs *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const QSharedPointer p = VAbstractTool::data.GeometricObject(id); + dialogTool->SetFirstArcId(firstArcId); + dialogTool->SetSecondArcId(secondArcId); + dialogTool->SetCrossArcPoint(crossPoint); + dialogTool->SetPointName(p->name()); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(DialogTool *dialog, VMainGraphicsScene *scene, + VPattern *doc, VContainer *data) +{ + SCASSERT(dialog != nullptr); + DialogPointOfIntersectionArcs *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const quint32 firstArcId = dialogTool->GetFirstArcId(); + const quint32 secondArcId = dialogTool->GetSecondArcId(); + const CrossArcsPoint pType = dialogTool->GetCrossArcPoint(); + const QString pointName = dialogTool->getPointName(); + VToolPointOfIntersectionArcs *point = nullptr; + point = Create(0, pointName, firstArcId, secondArcId, pType, 5, 10, scene, doc, data, Document::FullParse, + Source::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(const quint32 _id, const QString &pointName, + const quint32 &firstArcId, + const quint32 &secondArcId, CrossArcsPoint pType, + const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document &parse, + const Source &typeCreation) +{ + const QSharedPointer firstArc = data->GeometricObject(firstArcId); + const QSharedPointer secondArc = data->GeometricObject(secondArcId); + + const QPointF point = FindPoint(firstArc.data(), secondArc.data(), pType); + quint32 id = _id; + if (typeCreation == Source::FromGui) + { + id = data->AddGObject(new VPointF(point, pointName, mx, my)); + } + else + { + data->UpdateGObject(id, new VPointF(point, pointName, mx, my)); + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + VDrawTool::AddRecord(id, Tool::PointOfIntersectionArcs, doc); + if (parse == Document::FullParse) + { + VToolPointOfIntersectionArcs *point = new VToolPointOfIntersectionArcs(doc, data, id, firstArcId, + secondArcId, pType, typeCreation); + scene->addItem(point); + connect(point, &VToolPointOfIntersectionArcs::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPointOfIntersectionArcs::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolPointOfIntersectionArcs::Disable); + connect(scene, &VMainGraphicsScene::EnableToolMove, point, &VToolPointOfIntersectionArcs::EnableToolMove); + doc->AddTool(id, point); + doc->IncrementReferens(firstArcId); + doc->IncrementReferens(secondArcId); + return point; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VToolPointOfIntersectionArcs::FindPoint(const VArc *arc1, const VArc *arc2, const CrossArcsPoint pType) +{ + QPointF p1, p2; + const int res = VGObject::IntersectionCircles(arc1->GetCenter().toQPointF(), arc1->GetRadius(), + arc2->GetCenter().toQPointF(), arc2->GetRadius(), p1, p2); + + switch(res) + { + case 2: + if (pType == CrossArcsPoint::FirstPoint) + { + return p1; + } + else + { + return p2; + } + break; + case 1: + return p1; + break; + case 3: + case 0: + default: + return QPointF(0, 0); + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolPointOfIntersectionArcs::GetFirstArcId() const +{ + return firstArcId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersectionArcs::SetFirstArcId(const quint32 &value) +{ + if (value != NULL_ID) + { + firstArcId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolPointOfIntersectionArcs::GetSecondArcId() const +{ + return secondArcId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersectionArcs::SetSecondArcId(const quint32 &value) +{ + if (value != NULL_ID) + { + secondArcId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +CrossArcsPoint VToolPointOfIntersectionArcs::GetCrossArcsPoint() const +{ + return crossPoint; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersectionArcs::SetCrossArcsPoint(CrossArcsPoint &value) +{ + crossPoint = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersectionArcs::ShowVisualization(bool show) +{ + ShowToolVisualization(show); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersectionArcs::FullUpdateFromFile() +{ + ReadAttributes(); + VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); + SetVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersectionArcs::RemoveReferens() +{ + doc->DecrementReferens(firstArcId); + doc->DecrementReferens(secondArcId); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersectionArcs::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(this, event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersectionArcs::SaveDialog(QDomElement &domElement) +{ + SCASSERT(dialog != nullptr); + DialogPointOfIntersectionArcs *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); + doc->SetAttribute(domElement, AttrFirstArc, QString().setNum(dialogTool->GetFirstArcId())); + doc->SetAttribute(domElement, AttrSecondArc, QString().setNum(dialogTool->GetSecondArcId())); + doc->SetAttribute(domElement, AttrCrossPoint, QString().setNum(static_cast(dialogTool->GetCrossArcPoint()))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersectionArcs::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, AttrFirstArc, firstArcId); + doc->SetAttribute(tag, AttrSecondArc, secondArcId); + doc->SetAttribute(tag, AttrCrossPoint, static_cast(crossPoint)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersectionArcs::ReadToolAttributes(const QDomElement &domElement) +{ + firstArcId = doc->GetParametrUInt(domElement, AttrFirstArc, NULL_ID_STR); + secondArcId = doc->GetParametrUInt(domElement, AttrSecondArc, NULL_ID_STR); + crossPoint = static_cast(doc->GetParametrUInt(domElement, AttrCrossPoint, "1")); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersectionArcs::SetVisualization() +{ + if (vis != nullptr) + { + VisToolPointOfIntersectionArcs *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setArc1Id(firstArcId); + visual->setArc2Id(secondArcId); + visual->setCrossPoint(crossPoint); + visual->RefreshGeometry(); + } +} diff --git a/src/app/tools/drawTools/vtoolpointofintersectionarcs.h b/src/app/tools/drawTools/vtoolpointofintersectionarcs.h new file mode 100644 index 000000000..0a942ad8b --- /dev/null +++ b/src/app/tools/drawTools/vtoolpointofintersectionarcs.h @@ -0,0 +1,89 @@ +/************************************************************************ + ** + ** @file vtoolpointofintersectionarcs.h + ** @author Roman Telezhynskyi + ** @date 25 5, 2015 + ** + ** @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) 2015 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 VTOOLPOINTOFINTERSECTIONARCS_H +#define VTOOLPOINTOFINTERSECTIONARCS_H + +#include "vtoolpoint.h" +#include "../../xml/vpattern.h" + +class VArc; + +class VToolPointOfIntersectionArcs : public VToolPoint +{ + Q_OBJECT + +public: + VToolPointOfIntersectionArcs(VPattern *doc, VContainer *data, const quint32 &id, const quint32 &firstArcId, + const quint32 &secondArcId, CrossArcsPoint crossPoint, const Source &typeCreation, + QGraphicsItem * parent = nullptr); + virtual void setDialog(); + static VToolPointOfIntersectionArcs *Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data); + static VToolPointOfIntersectionArcs *Create(const quint32 _id, const QString &pointName, const quint32 &firstArcId, + const quint32 &secondArcId, CrossArcsPoint crossPoint, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, + VPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation); + static QPointF FindPoint(const VArc *arc1, const VArc *arc2, const CrossArcsPoint crossPoint); + static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::PointOfIntersectionArcs) }; + + quint32 GetFirstArcId() const; + void SetFirstArcId(const quint32 &value); + + quint32 GetSecondArcId() const; + void SetSecondArcId(const quint32 &value); + + CrossArcsPoint GetCrossArcsPoint() const; + void SetCrossArcsPoint(CrossArcsPoint &value); + + virtual void ShowVisualization(bool show); +public slots: + virtual void FullUpdateFromFile(); +protected: + virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); + virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); +private: + Q_DISABLE_COPY(VToolPointOfIntersectionArcs) + + /** @brief firstArcId id first arc. */ + quint32 firstArcId; + + /** @brief secondArcId id second arc. */ + quint32 secondArcId; + + CrossArcsPoint crossPoint; +}; + +#endif // VTOOLPOINTOFINTERSECTIONARCS_H diff --git a/src/app/tools/tools.pri b/src/app/tools/tools.pri index 9e4c233b4..425ed0dd5 100644 --- a/src/app/tools/tools.pri +++ b/src/app/tools/tools.pri @@ -38,7 +38,8 @@ HEADERS += \ $$PWD/drawTools/vabstractspline.h \ $$PWD/drawTools/vtoolcut.h \ $$PWD/drawTools/vtoollineintersectaxis.h \ - $$PWD/drawTools/vtoolcurveintersectaxis.h + $$PWD/drawTools/vtoolcurveintersectaxis.h \ + $$PWD/drawTools/vtoolpointofintersectionarcs.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -74,4 +75,5 @@ SOURCES += \ $$PWD/drawTools/vabstractspline.cpp \ $$PWD/drawTools/vtoolcut.cpp \ $$PWD/drawTools/vtoollineintersectaxis.cpp \ - $$PWD/drawTools/vtoolcurveintersectaxis.cpp + $$PWD/drawTools/vtoolcurveintersectaxis.cpp \ + $$PWD/drawTools/vtoolpointofintersectionarcs.cpp diff --git a/src/app/tools/vabstracttool.cpp b/src/app/tools/vabstracttool.cpp index 3451ac7b8..e62120f5d 100644 --- a/src/app/tools/vabstracttool.cpp +++ b/src/app/tools/vabstracttool.cpp @@ -76,6 +76,9 @@ const QString VAbstractTool::AttrAxisP2 = QStringLiteral("axisP2"); const QString VAbstractTool::AttrCurve = QStringLiteral("curve"); const QString VAbstractTool::AttrLineColor = QStringLiteral("lineColor"); const QString VAbstractTool::AttrColor = QStringLiteral("color"); +const QString VAbstractTool::AttrFirstArc = QStringLiteral("firstArc"); +const QString VAbstractTool::AttrSecondArc = QStringLiteral("secondArc"); +const QString VAbstractTool::AttrCrossPoint = QStringLiteral("crossPoint"); const QString VAbstractTool::TypeLineNone = QStringLiteral("none"); const QString VAbstractTool::TypeLineLine = QStringLiteral("hair"); diff --git a/src/app/tools/vabstracttool.h b/src/app/tools/vabstracttool.h index 6ee96ee69..0b9dc83ed 100644 --- a/src/app/tools/vabstracttool.h +++ b/src/app/tools/vabstracttool.h @@ -91,6 +91,9 @@ public: static const QString AttrCurve; static const QString AttrLineColor; static const QString AttrColor; + static const QString AttrFirstArc; + static const QString AttrSecondArc; + static const QString AttrCrossPoint; static const QString TypeLineNone; static const QString TypeLineLine; diff --git a/src/app/visualization/vistoolpointofintersectionarcs.cpp b/src/app/visualization/vistoolpointofintersectionarcs.cpp new file mode 100644 index 000000000..0b5b4f469 --- /dev/null +++ b/src/app/visualization/vistoolpointofintersectionarcs.cpp @@ -0,0 +1,101 @@ +/************************************************************************ + ** + ** @file vistoolpointofintersectionarcs.cpp + ** @author Roman Telezhynskyi + ** @date 27 5, 2015 + ** + ** @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) 2015 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 "vistoolpointofintersectionarcs.h" +#include "../libs/vgeometry/varc.h" +#include "../container/vcontainer.h" +#include "../tools/drawTools/vtoolpointofintersectionarcs.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolPointOfIntersectionArcs::VisToolPointOfIntersectionArcs(const VContainer *data, QGraphicsItem *parent) + : VisLine(data, parent), arc1Id(NULL_ID), arc2Id(NULL_ID), crossPoint(CrossArcsPoint::FirstPoint), point(nullptr), + arc1Path(nullptr), arc2Path(nullptr) +{ + arc1Path = InitItem(Qt::darkGreen, this); + arc1Path->setFlag(QGraphicsItem::ItemStacksBehindParent, false); + arc2Path = InitItem(Qt::darkRed, this); + arc2Path->setFlag(QGraphicsItem::ItemStacksBehindParent, false); + + point = InitPoint(mainColor, this); + point->setZValue(2); + point->setFlag(QGraphicsItem::ItemStacksBehindParent, false); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolPointOfIntersectionArcs::~VisToolPointOfIntersectionArcs() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolPointOfIntersectionArcs::RefreshGeometry() +{ + if (arc1Id > NULL_ID) + { + const QSharedPointer arc1 = Visualization::data->GeometricObject(arc1Id); + DrawPath(arc1Path, arc1->GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap); + + if (arc2Id > NULL_ID) + { + const QSharedPointer arc2 = Visualization::data->GeometricObject(arc2Id); + DrawPath(arc2Path, arc2->GetPath(PathDirection::Show), Qt::darkRed, Qt::SolidLine, Qt::RoundCap); + + const QPointF fPoint = VToolPointOfIntersectionArcs::FindPoint(arc1.data(), arc2.data(), crossPoint); + DrawPoint(point, fPoint, mainColor); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolPointOfIntersectionArcs::VisualMode(const quint32 &id) +{ + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + + this->arc1Id = id; + Visualization::scenePos = scene->getScenePos(); + RefreshGeometry(); + + AddOnScene(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolPointOfIntersectionArcs::setArc1Id(const quint32 &value) +{ + arc1Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolPointOfIntersectionArcs::setArc2Id(const quint32 &value) +{ + arc2Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolPointOfIntersectionArcs::setCrossPoint(const CrossArcsPoint &value) +{ + crossPoint = value; +} diff --git a/src/app/visualization/vistoolpointofintersectionarcs.h b/src/app/visualization/vistoolpointofintersectionarcs.h new file mode 100644 index 000000000..fb20ecfd2 --- /dev/null +++ b/src/app/visualization/vistoolpointofintersectionarcs.h @@ -0,0 +1,61 @@ +/************************************************************************ + ** + ** @file vistoolpointofintersectionarcs.h + ** @author Roman Telezhynskyi + ** @date 27 5, 2015 + ** + ** @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) 2015 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 VISTOOLPOINTOFINTERSECTIONARCS_H +#define VISTOOLPOINTOFINTERSECTIONARCS_H + +#include "visline.h" +#include "../xml/vpattern.h" + +class VisToolPointOfIntersectionArcs : public VisLine +{ + Q_OBJECT +public: + VisToolPointOfIntersectionArcs(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolPointOfIntersectionArcs(); + + virtual void RefreshGeometry(); + virtual void VisualMode(const quint32 &id); + + void setArc1Id(const quint32 &value); + void setArc2Id(const quint32 &value); + void setCrossPoint(const CrossArcsPoint &value); + + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolPointOfIntersection)}; +private: + Q_DISABLE_COPY(VisToolPointOfIntersectionArcs) + quint32 arc1Id; + quint32 arc2Id; + CrossArcsPoint crossPoint; + QGraphicsEllipseItem *point; + QGraphicsPathItem *arc1Path; + QGraphicsPathItem *arc2Path; +}; + +#endif // VISTOOLPOINTOFINTERSECTIONARCS_H diff --git a/src/app/visualization/visualization.h b/src/app/visualization/visualization.h index c72d21ad2..5596084db 100644 --- a/src/app/visualization/visualization.h +++ b/src/app/visualization/visualization.h @@ -52,7 +52,7 @@ public: void setPoint1Id(const quint32 &value); void setLineStyle(const Qt::PenStyle &value); void setScenePos(const QPointF &value); - void VisualMode(const quint32 &pointId); + virtual void VisualMode(const quint32 &pointId); void setMainColor(const QColor &value); signals: void ToolTip(const QString &toolTip); diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index aa73530fe..85b167327 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -26,7 +26,8 @@ HEADERS += \ $$PWD/vistoolsplinepath.h \ $$PWD/vistoolcutsplinepath.h \ $$PWD/vistoollineintersectaxis.h \ - $$PWD/vistoolcurveintersectaxis.h + $$PWD/vistoolcurveintersectaxis.h \ + $$PWD/vistoolpointofintersectionarcs.h SOURCES += \ $$PWD/vgraphicssimpletextitem.cpp \ @@ -53,4 +54,5 @@ SOURCES += \ $$PWD/vistoolsplinepath.cpp \ $$PWD/vistoolcutsplinepath.cpp \ $$PWD/vistoollineintersectaxis.cpp \ - $$PWD/vistoolcurveintersectaxis.cpp + $$PWD/vistoolcurveintersectaxis.cpp \ + $$PWD/vistoolpointofintersectionarcs.cpp diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index 5b71762aa..f265cbc56 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -116,6 +116,9 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) case VToolPointOfIntersection::Type: ShowOptionsToolPointOfIntersection(item); break; + case VToolPointOfIntersectionArcs::Type: + ShowOptionsToolPointOfIntersectionArcs(item); + break; case VToolShoulderPoint::Type: ShowOptionsToolShoulderPoint(item); break; @@ -203,6 +206,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions() case VToolPointOfIntersection::Type: UpdateOptionsToolPointOfIntersection(); break; + case VToolPointOfIntersectionArcs::Type: + UpdateOptionsToolPointOfIntersectionArcs(); + break; case VToolShoulderPoint::Type: UpdateOptionsToolShoulderPoint(); break; @@ -305,6 +311,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) case VToolPointOfIntersection::Type: ChangeDataToolPointOfIntersection(prop); break; + case VToolPointOfIntersectionArcs::Type: + ChangeDataToolPointOfIntersectionArcs(prop); + break; case VToolShoulderPoint::Type: ChangeDataToolShoulderPoint(prop); break; @@ -388,6 +397,16 @@ void VToolOptionsPropertyBrowser::AddPropertyPointName(Tool *i, const QString &p AddProperty(itemName, VAbstractTool::AttrName); } +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyCrossPoint(Tool *i, const QString &propertyName) +{ + VEnumProperty* itemProperty = new VEnumProperty(propertyName); + itemProperty->setLiterals(QStringList()<< tr("First point") << tr("Second point")); + itemProperty->setValue(static_cast(i->GetCrossArcsPoint())-1); + AddProperty(itemProperty, VAbstractTool::AttrCrossPoint); +} + //--------------------------------------------------------------------------------------------------------------------- template void VToolOptionsPropertyBrowser::AddPropertyLineType(Tool *i, const QString &propertyName, @@ -827,6 +846,52 @@ void VToolOptionsPropertyBrowser::ChangeDataToolPointOfIntersection(VProperty *p } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolPointOfIntersectionArcs(VProperty *property) +{ + SCASSERT(property != nullptr) + + const QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolPointOfIntersectionArcs *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 28: // VAbstractTool::AttrCrossPoint + { + const QVariant value = property->data(VProperty::DPC_Data, Qt::EditRole); + bool ok = false; + const int val = value.toInt(&ok); + + CrossArcsPoint cross = CrossArcsPoint::FirstPoint; + if (ok) + { + switch(val) + { + case 0: + cross = CrossArcsPoint::FirstPoint; + break; + case 1: + cross = CrossArcsPoint::SecondPoint; + break; + default: + cross = CrossArcsPoint::FirstPoint; + break; + } + } + i->SetCrossArcsPoint(cross); + break; + } + default: + qWarning()<<"Unknown property type. id = "<(item); + i->ShowVisualization(true); + formView->setTitle(tr("Tool to make point from intersection two arcs")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyCrossPoint(i, tr("Take")); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolShoulderPoint(QGraphicsItem *item) { @@ -1485,6 +1561,15 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolPointOfIntersection() idToProperty[VAbstractTool::AttrName]->setValue(i->name()); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolPointOfIntersectionArcs() +{ + VToolPointOfIntersectionArcs *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + idToProperty[VAbstractTool::AttrCrossPoint]->setValue(static_cast(i->GetCrossArcsPoint())-1); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolShoulderPoint() { @@ -1611,6 +1696,7 @@ QStringList VToolOptionsPropertyBrowser::PropertiesList() const << VAbstractTool::AttrAxisP2 /* 24 */ << VAbstractTool::AttrKCurve /* 25 */ << VAbstractTool::AttrLineColor /* 26 */ - << VAbstractTool::AttrColor; /* 27 */ + << VAbstractTool::AttrColor /* 27 */ + << VAbstractTool::AttrCrossPoint; /* 28 */ return attr; } diff --git a/src/app/widgets/vtooloptionspropertybrowser.h b/src/app/widgets/vtooloptionspropertybrowser.h index e0830771a..f12b9d86f 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.h +++ b/src/app/widgets/vtooloptionspropertybrowser.h @@ -71,6 +71,9 @@ private: template void AddPropertyPointName(Tool *i, const QString &propertyName); + template + void AddPropertyCrossPoint(Tool *i, const QString &propertyName); + template void AddPropertyLineType(Tool *i, const QString &propertyName, const QMap &styles); @@ -96,6 +99,7 @@ private: void ChangeDataToolNormal(VPE::VProperty *property); void ChangeDataToolPointOfContact(VPE::VProperty *property); void ChangeDataToolPointOfIntersection(VPE::VProperty *property); + void ChangeDataToolPointOfIntersectionArcs(VPE::VProperty *property); void ChangeDataToolShoulderPoint(VPE::VProperty *property); void ChangeDataToolSpline(VPE::VProperty *property); void ChangeDataToolSplinePath(VPE::VProperty *property); @@ -117,6 +121,7 @@ private: void ShowOptionsToolNormal(QGraphicsItem *item); void ShowOptionsToolPointOfContact(QGraphicsItem *item); void ShowOptionsToolPointOfIntersection(QGraphicsItem *item); + void ShowOptionsToolPointOfIntersectionArcs(QGraphicsItem *item); void ShowOptionsToolShoulderPoint(QGraphicsItem *item); void ShowOptionsToolSpline(QGraphicsItem *item); void ShowOptionsToolSplinePath(QGraphicsItem *item); @@ -138,6 +143,7 @@ private: void UpdateOptionsToolNormal(); void UpdateOptionsToolPointOfContact(); void UpdateOptionsToolPointOfIntersection(); + void UpdateOptionsToolPointOfIntersectionArcs(); void UpdateOptionsToolShoulderPoint(); void UpdateOptionsToolSpline(); void UpdateOptionsToolSplinePath(); diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index c82cf8ecb..bf920b614 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -1142,7 +1142,8 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem << VNodePoint::ToolType << VToolHeight::ToolType << VToolTriangle::ToolType << VToolPointOfIntersection::ToolType << VToolCutSpline::ToolType << VToolCutSplinePath::ToolType << VToolCutArc::ToolType - << VToolLineIntersectAxis::ToolType << VToolCurveIntersectAxis::ToolType; + << VToolLineIntersectAxis::ToolType << VToolCurveIntersectAxis::ToolType + << VToolPointOfIntersectionArcs::ToolType; switch (points.indexOf(type)) { case 0: //VToolSinglePoint::ToolType @@ -1633,6 +1634,26 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem throw excep; } break; + case 17: //VToolPointOfIntersectionArcs::ToolType + try + { + PointsCommonAttributes(domElement, id, name, mx, my); + const quint32 firstArcId = GetParametrUInt(domElement, VAbstractTool::AttrFirstArc, NULL_ID_STR); + const quint32 secondArcId = GetParametrUInt(domElement, VAbstractTool::AttrSecondArc, NULL_ID_STR); + const CrossArcsPoint crossPoint = static_cast(GetParametrUInt(domElement, + VAbstractTool::AttrCrossPoint, + "1")); + + VToolPointOfIntersectionArcs::Create(id, name, firstArcId, secondArcId, crossPoint, mx, my, scene, this, + data, parse, Source::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating point of intersection arcs"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; default: qDebug() << "Illegal point type in VDomDocument::ParsePointElement()."; break; diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index bac00fe71..04e9b1ba8 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -38,6 +38,7 @@ class VMainGraphicsScene; enum class Document : char { LiteParse, LitePPParse, FullParse }; enum class LabelType : char {NewPatternPiece, NewLabel}; +enum class CrossArcsPoint : char {FirstPoint = 1, SecondPoint = 2}; /** * @brief The VPattern class working with pattern file. diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index f8b8fe11e..d1285d947 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -6,5 +6,6 @@ schema/pattern/v0.1.1.xsd schema/pattern/v0.1.2.xsd schema/pattern/v0.1.3.xsd + schema/pattern/v0.1.4.xsd diff --git a/src/libs/ifc/schema/pattern/v0.1.4.xsd b/src/libs/ifc/schema/pattern/v0.1.4.xsd new file mode 100644 index 000000000..059a82091 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.1.4.xsd @@ -0,0 +1,312 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index f3f834ea8..028b1ae8a 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -40,8 +40,8 @@ */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.1.3"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.1.3.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.1.4"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.1.4.xsd"); //--------------------------------------------------------------------------------------------------------------------- VPatternConverter::VPatternConverter(const QString &fileName) @@ -93,6 +93,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000102): return QStringLiteral("://schema/pattern/v0.1.2.xsd"); case (0x000103): + return QStringLiteral("://schema/pattern/v0.1.3.xsd"); + case (0x000104): return CurrentSchema; default: { @@ -140,6 +142,16 @@ void VPatternConverter::ApplyPatches() #endif } case (0x000103): + { + ToV0_1_4(); + const QString schema = XSDSchema(0x000104); + ValidateXML(schema, fileName); + // continue conversion + #ifdef Q_CC_CLANG + [[clang::fallthrough]]; + #endif + } + case (0x000104): break; default: break; @@ -184,3 +196,10 @@ void VPatternConverter::ToV0_1_3() SetVersion(QStringLiteral("0.1.3")); Save(); } + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_1_4() +{ + SetVersion(QStringLiteral("0.1.4")); + Save(); +} diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index c9075318d..5df5443cd 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -58,6 +58,7 @@ private: void ToV0_1_1(); void ToV0_1_2(); void ToV0_1_3(); + void ToV0_1_4(); }; #endif // VPATTERNCONVERTER_H diff --git a/src/libs/vgeometry/vgobject.cpp b/src/libs/vgeometry/vgobject.cpp index 6a66bd978..c0000900b 100644 --- a/src/libs/vgeometry/vgobject.cpp +++ b/src/libs/vgeometry/vgobject.cpp @@ -260,6 +260,45 @@ QPointF VGObject::LineIntersectRect(const QRectF &rec, const QLineF &line) return point; } +//--------------------------------------------------------------------------------------------------------------------- +int VGObject::IntersectionCircles(const QPointF &c1, double r1, const QPointF &c2, double r2, QPointF &p1, QPointF &p2) +{ + if (qFuzzyCompare(c1.x(), c2.x()) && qFuzzyCompare(c1.y(), c2.y()) && qFuzzyCompare(r1, r2)) + { + return 3;// Circles are equal + } + const double a = - 2.0 * (c2.x() - c1.x()); + const double b = - 2.0 * (c2.y() - c1.y()); + const double c = (c2.x() - c1.x())* (c2.x() - c1.x()) + (c2.y() - c1.y()) * (c2.y() - c1.y()) + r1 * r1 - r2 * r2; + + const double x0 = -a*c/(a*a+b*b); + const double y0 = -b*c/(a*a+b*b); + + if (c*c > r1*r1*(a*a+b*b)) + { + return 0; + } + else if (qFuzzyCompare(c*c, r1*r1*(a*a+b*b))) + { + p1 = QPointF(x0 + c1.x(), y0 + c1.y()); + return 1; + } + else + { + const double d = r1*r1 - c*c/(a*a+b*b); + const double mult = sqrt (d / (a*a+b*b)); + + const double ax = x0 + b * mult; + const double bx = x0 - b * mult; + const double ay = y0 - a * mult; + const double by = y0 + a * mult; + + p1 = QPointF(ax + c1.x(), ay + c1.y()); + p2 = QPointF(bx + c1.x(), by + c1.y()); + return 2; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief LineIntersectCircle find point intersection line and circle. @@ -276,10 +315,10 @@ qint32 VGObject::LineIntersectCircle(const QPointF ¢er, qreal radius, const qreal a = 0, b = 0, c = 0; LineCoefficients(line, &a, &b, &c); // projection center of circle on to line - QPointF p = ClosestPoint (line, center); + const QPointF p = ClosestPoint (line, center); // how many solutions? qint32 flag = 0; - qreal d = QLineF (center, p).length(); + const qreal d = QLineF (center, p).length(); if (qFuzzyCompare(d, radius)) { flag = 1; @@ -296,8 +335,8 @@ qint32 VGObject::LineIntersectCircle(const QPointF ¢er, qreal radius, const } } // find distance from projection to points of intersection - qreal k = qSqrt (qAbs(radius * radius - d * d)); - qreal t = QLineF (QPointF (0, 0), QPointF (b, - a)).length(); + const qreal k = qSqrt (qAbs(radius * radius - d * d)); + const qreal t = QLineF (QPointF (0, 0), QPointF (b, - a)).length(); // add to projection a vectors aimed to points of intersection p1 = addVector (p, QPointF (0, 0), QPointF (- b, a), k / t); p2 = addVector (p, QPointF (0, 0), QPointF (b, - a), k / t); diff --git a/src/libs/vgeometry/vgobject.h b/src/libs/vgeometry/vgobject.h index 5ad5d0b7c..de8075a76 100644 --- a/src/libs/vgeometry/vgobject.h +++ b/src/libs/vgeometry/vgobject.h @@ -73,6 +73,8 @@ public: static QLineF BuildAxis(const QPointF &p1, const QPointF &p2, const QRectF &scRect); static QPointF LineIntersectRect(const QRectF &rec, const QLineF &line); + static int IntersectionCircles(const QPointF &c1, double r1, const QPointF &c2, double r2, QPointF &p1, + QPointF &p2); static qint32 LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1, QPointF &p2); static QPointF ClosestPoint(const QLineF &line, const QPointF &point);