From 71302fddf05eb2f36a0b598b54e8d4a110db8111 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 27 May 2015 13:48:21 +0300 Subject: [PATCH] First successful build. --HG-- branch : feature --- src/app/dialogs/dialogs.h | 1 + src/app/dialogs/dialogs.pri | 9 +- .../tools/dialogpointofintersection.cpp | 12 +- .../tools/dialogpointofintersectionarcs.cpp | 234 ++++++++++++++ .../tools/dialogpointofintersectionarcs.h | 78 +++++ .../tools/dialogpointofintersectionarcs.ui | 149 +++++++++ src/app/mainwindow.cpp | 14 + src/app/mainwindow.h | 1 + src/app/options.h | 6 +- src/app/tools/drawTools/drawtools.h | 1 + .../vtoolpointofintersectionarcs.cpp | 290 ++++++++++++++++++ .../drawTools/vtoolpointofintersectionarcs.h | 89 ++++++ src/app/tools/tools.pri | 6 +- src/app/tools/vabstracttool.cpp | 3 + src/app/tools/vabstracttool.h | 3 + .../vistoolpointofintersectionarcs.cpp | 88 ++++++ .../vistoolpointofintersectionarcs.h | 60 ++++ src/app/visualization/visualization.pri | 6 +- src/app/xml/vpattern.h | 1 + 19 files changed, 1031 insertions(+), 20 deletions(-) create mode 100644 src/app/dialogs/tools/dialogpointofintersectionarcs.cpp create mode 100644 src/app/dialogs/tools/dialogpointofintersectionarcs.h create mode 100644 src/app/dialogs/tools/dialogpointofintersectionarcs.ui create mode 100644 src/app/tools/drawTools/vtoolpointofintersectionarcs.cpp create mode 100644 src/app/tools/drawTools/vtoolpointofintersectionarcs.h create mode 100644 src/app/visualization/vistoolpointofintersectionarcs.cpp create mode 100644 src/app/visualization/vistoolpointofintersectionarcs.h 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..b232a79c9 --- /dev/null +++ b/src/app/dialogs/tools/dialogpointofintersectionarcs.cpp @@ -0,0 +1,234 @@ +/************************************************************************ + ** + ** @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); +} + +//--------------------------------------------------------------------------------------------------------------------- +CrossArcPoint 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 CrossArcPoint::FirstPoint; + } + + switch(value) + { + case 1: + return CrossArcPoint::FirstPoint; + break; + case 2: + return CrossArcPoint::SecondPoint; + break; + default: + return CrossArcPoint::FirstPoint; + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionArcs::SetCrossArcPoint(CrossArcPoint &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->setArc1Id(id); + point->RefreshGeometry(); + } + break; + case 1: + if (getCurrentObjectId(ui->comboBoxArc2) != id) + { + if (SetObject(id, ui->comboBoxArc2, "")) + { + 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->RefreshGeometry(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersectionArcs::FillComboBoxCrossArcPoints() +{ + ui->comboBoxResult->addItem(tr("First point"), QVariant(static_cast(CrossArcPoint::FirstPoint))); + ui->comboBoxResult->addItem(tr("Second point"), QVariant(static_cast(CrossArcPoint::SecondPoint))); +} diff --git a/src/app/dialogs/tools/dialogpointofintersectionarcs.h b/src/app/dialogs/tools/dialogpointofintersectionarcs.h new file mode 100644 index 000000000..1b89df131 --- /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); + + CrossArcPoint GetCrossArcPoint() const; + void SetCrossArcPoint(CrossArcPoint &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..eafdf1e12 --- /dev/null +++ b/src/app/dialogs/tools/dialogpointofintersectionarcs.ui @@ -0,0 +1,149 @@ + + + DialogPointOfIntersectionArcs + + + + 0 + 0 + 285 + 179 + + + + + 285 + 179 + + + + + 285 + 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 489c54a29..d85447891 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -695,6 +695,16 @@ void MainWindow::ToolCurveIntersectAxis(bool checked) &MainWindow::ApplyDialog); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::PointOfIntersectionArcs(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::PointOfIntersectionArcs); } //--------------------------------------------------------------------------------------------------------------------- @@ -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: diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index a6778c7dd..b42907978 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -115,6 +115,7 @@ public slots: void ToolCutArc(bool checked); void ToolLineIntersectAxis(bool checked); void ToolCurveIntersectAxis(bool checked); + void PointOfIntersectionArcs(bool checked); void ClosedDialogDetail(int result); void ClosedDialogUnionDetails(int result); 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/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..781170840 --- /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, + CrossArcPoint 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 CrossArcPoint 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, CrossArcPoint 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 CrossArcPoint 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 == CrossArcPoint::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); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +CrossArcPoint VToolPointOfIntersectionArcs::GetCrossArcPoint() const +{ + return crossPoint; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersectionArcs::SetCrossArcPoint(CrossArcPoint &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..3d208b23a --- /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, CrossArcPoint 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, CrossArcPoint 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 CrossArcPoint 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); + + CrossArcPoint GetCrossArcPoint() const; + void SetCrossArcPoint(CrossArcPoint &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; + + CrossArcPoint 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..b0f043cc1 --- /dev/null +++ b/src/app/visualization/vistoolpointofintersectionarcs.cpp @@ -0,0 +1,88 @@ +/************************************************************************ + ** + ** @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(CrossArcPoint::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::Hide), supportColor, Qt::SolidLine, Qt::RoundCap); + + if (arc2Id > NULL_ID) + { + const QSharedPointer arc2 = Visualization::data->GeometricObject(arc2Id); + DrawPath(arc2Path, arc2->GetPath(PathDirection::Hide), supportColor, Qt::SolidLine, Qt::RoundCap); + + const QPointF fPoint = VToolPointOfIntersectionArcs::FindPoint(arc1.data(), arc2.data(), crossPoint); + DrawPoint(point, fPoint, mainColor); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolPointOfIntersectionArcs::setArc1Id(const quint32 &value) +{ + arc1Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolPointOfIntersectionArcs::setArc2Id(const quint32 &value) +{ + arc2Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolPointOfIntersectionArcs::setCrossPoint(const CrossArcPoint &value) +{ + crossPoint = value; +} diff --git a/src/app/visualization/vistoolpointofintersectionarcs.h b/src/app/visualization/vistoolpointofintersectionarcs.h new file mode 100644 index 000000000..88375b032 --- /dev/null +++ b/src/app/visualization/vistoolpointofintersectionarcs.h @@ -0,0 +1,60 @@ +/************************************************************************ + ** + ** @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(); + + void setArc1Id(const quint32 &value); + void setArc2Id(const quint32 &value); + void setCrossPoint(const CrossArcPoint &value); + + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolPointOfIntersection)}; +private: + Q_DISABLE_COPY(VisToolPointOfIntersectionArcs) + quint32 arc1Id; + quint32 arc2Id; + CrossArcPoint crossPoint; + QGraphicsEllipseItem *point; + QGraphicsPathItem *arc1Path; + QGraphicsPathItem *arc2Path; +}; + +#endif // VISTOOLPOINTOFINTERSECTIONARCS_H 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/xml/vpattern.h b/src/app/xml/vpattern.h index bac00fe71..c532f4250 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 CrossArcPoint : char {FirstPoint = 1, SecondPoint = 2}; /** * @brief The VPattern class working with pattern file.