diff --git a/src/app/core/vtooloptionspropertybrowser.cpp b/src/app/core/vtooloptionspropertybrowser.cpp index 364011711..c8a9f0563 100644 --- a/src/app/core/vtooloptionspropertybrowser.cpp +++ b/src/app/core/vtooloptionspropertybrowser.cpp @@ -32,6 +32,7 @@ #include "../../libs/vwidgets/vmaingraphicsview.h" #include "../../libs/vwidgets/vgraphicssimpletextitem.h" #include "../../libs/vwidgets/vcontrolpointspline.h" +#include "../../libs/vwidgets/vsimplepoint.h" #include "../../libs/vpropertyexplorer/vproperties.h" #include "vformulaproperty.h" #include "../../libs/vpatterndb/vformula.h" @@ -161,6 +162,13 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) case VToolPointFromArcAndTangent::Type: ShowOptionsToolPointFromArcAndTangent(item); break; + case VSimplePoint::Type: + currentItem = item->parentItem(); + ShowItemOptions(currentItem); + break; + case VToolTrueDarts::Type: + ShowOptionsToolTrueDarts(item); + break; default: break; } @@ -257,6 +265,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions() case VToolPointFromArcAndTangent::Type: UpdateOptionsToolPointFromArcAndTangent(); break; + case VToolTrueDarts::Type: + UpdateOptionsToolTrueDarts(); + break; default: break; } @@ -368,6 +379,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) case VToolPointFromArcAndTangent::Type: ChangeDataToolPointFromArcAndTangent(prop); break; + case VToolTrueDarts::Type: + ChangeDataToolTrueDarts(prop); + break; default: break; } @@ -433,6 +447,25 @@ void VToolOptionsPropertyBrowser::AddPropertyPointName(Tool *i, const QString &p AddProperty(itemName, VAbstractTool::AttrName); } + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyPointName1(Tool *i, const QString &propertyName) +{ + VProperty* itemName = new VProperty(propertyName); + itemName->setValue(i->nameP1()); + AddProperty(itemName, VAbstractTool::AttrName1); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyPointName2(Tool *i, const QString &propertyName) +{ + VProperty* itemName = new VProperty(propertyName); + itemName->setValue(i->nameP2()); + AddProperty(itemName, VAbstractTool::AttrName2); +} + //--------------------------------------------------------------------------------------------------------------------- template void VToolOptionsPropertyBrowser::AddPropertyCrossPoint(Tool *i, const QString &propertyName) @@ -502,6 +535,59 @@ void VToolOptionsPropertyBrowser::SetPointName(const QString &name) } } +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::SetPointName1(const QString &name) +{ + if (Tool *i = qgraphicsitem_cast(currentItem)) + { + if (name == i->nameP1()) + { + return; + } + + QRegularExpression rx(NameRegExp()); + if (name.isEmpty() || VContainer::IsUnique(name) == false || rx.match(name).hasMatch() == false) + { + idToProperty[VAbstractTool::AttrName1]->setValue(i->nameP1()); + } + else + { + i->setNameP1(name); + } + } + else + { + qWarning()<<"Can't cast item"; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::SetPointName2(const QString &name) +{ + if (Tool *i = qgraphicsitem_cast(currentItem)) + { + if (name == i->nameP2()) + { + return; + } + + QRegularExpression rx(NameRegExp()); + if (name.isEmpty() || VContainer::IsUnique(name) == false || rx.match(name).hasMatch() == false) + { + idToProperty[VAbstractTool::AttrName2]->setValue(i->nameP2()); + } + else + { + i->setNameP2(name); + } + } + else + { + qWarning()<<"Can't cast item"; + } +} //--------------------------------------------------------------------------------------------------------------------- template @@ -719,6 +805,30 @@ void VToolOptionsPropertyBrowser::ChangeDataToolBisector(VProperty *property) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolTrueDarts(VProperty *property) +{ + SCASSERT(property != nullptr) + + QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolTrueDarts *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 32: // VAbstractTool::AttrName1 + SetPointName1(value.toString()); + break; + case 33: // VAbstractTool::AttrName2 + SetPointName2(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<GetFormulaLength(), VAbstractTool::AttrLength); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolTrueDarts(QGraphicsItem *item) +{ + VToolTrueDarts *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("True darts")); + + AddPropertyPointName1(i, tr("Point 1 label")); + AddPropertyPointName2(i, tr("Point 2 label")); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolCutArc(QGraphicsItem *item) { @@ -1666,6 +1787,15 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolBisector() } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolTrueDarts() +{ + VToolTrueDarts *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName1]->setValue(i->nameP1()); + idToProperty[VAbstractTool::AttrName2]->setValue(i->nameP2()); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolCutArc() { @@ -1975,6 +2105,8 @@ QStringList VToolOptionsPropertyBrowser::PropertiesList() const << VAbstractTool::AttrCrossPoint /* 28 */ << VAbstractTool::AttrC1Radius /* 29 */ << VAbstractTool::AttrC2Radius /* 30 */ - << VAbstractTool::AttrCRadius; /* 31 */ + << VAbstractTool::AttrCRadius /* 31 */ + << VAbstractTool::AttrName1 /* 32 */ + << VAbstractTool::AttrName2; /* 33 */ return attr; } diff --git a/src/app/core/vtooloptionspropertybrowser.h b/src/app/core/vtooloptionspropertybrowser.h index 604ed84f5..134d5398a 100644 --- a/src/app/core/vtooloptionspropertybrowser.h +++ b/src/app/core/vtooloptionspropertybrowser.h @@ -68,12 +68,24 @@ private: template void SetPointName(const QString &name); + template + void SetPointName1(const QString &name); + + template + void SetPointName2(const QString &name); + template void SetCrossCirclesPoint(const QVariant value); template void AddPropertyPointName(Tool *i, const QString &propertyName); + template + void AddPropertyPointName1(Tool *i, const QString &propertyName); + + template + void AddPropertyPointName2(Tool *i, const QString &propertyName); + template void AddPropertyCrossPoint(Tool *i, const QString &propertyName); @@ -94,6 +106,7 @@ private: void ChangeDataToolArc(VPE::VProperty *property); void ChangeDataToolArcWithLength(VPE::VProperty *property); void ChangeDataToolBisector(VPE::VProperty *property); + void ChangeDataToolTrueDarts(VPE::VProperty *property); void ChangeDataToolCutArc(VPE::VProperty *property); void ChangeDataToolCutSpline(VPE::VProperty *property); void ChangeDataToolCutSplinePath(VPE::VProperty *property); @@ -120,6 +133,7 @@ private: void ShowOptionsToolArc(QGraphicsItem *item); void ShowOptionsToolArcWithLength(QGraphicsItem *item); void ShowOptionsToolBisector(QGraphicsItem *item); + void ShowOptionsToolTrueDarts(QGraphicsItem *item); void ShowOptionsToolCutArc(QGraphicsItem *item); void ShowOptionsToolCutSpline(QGraphicsItem *item); void ShowOptionsToolCutSplinePath(QGraphicsItem *item); @@ -146,6 +160,7 @@ private: void UpdateOptionsToolArc(); void UpdateOptionsToolArcWithLength(); void UpdateOptionsToolBisector(); + void UpdateOptionsToolTrueDarts(); void UpdateOptionsToolCutArc(); void UpdateOptionsToolCutSpline(); void UpdateOptionsToolCutSplinePath(); diff --git a/src/app/dialogs/dialoghistory.cpp b/src/app/dialogs/dialoghistory.cpp index cb485278f..d57fbfb31 100644 --- a/src/app/dialogs/dialoghistory.cpp +++ b/src/app/dialogs/dialoghistory.cpp @@ -407,6 +407,13 @@ QString DialogHistory::Record(const VToolRecord &tool) { return QString(tr("%1 - point from arc and tangent")).arg(PointName(tool.getId())); } + case Tool::TrueDarts: + { + return QString(tr("Correction the dart %1_%2_%3")) + .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrDartP1))) + .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrDartP2))) + .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrDartP2))); + } //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/mainwindow.cpp b/src/app/mainwindow.cpp index ca7b58e54..9eb63665b 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -309,7 +309,7 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur ui->view->setCursor(cur); ui->view->setShowToolOptions(false); helpLabel->setText(toolTip); - dialogTool = new Dialog(pattern, 0, this); + dialogTool = new Dialog(pattern, NULL_ID, this); VMainGraphicsScene *scene = qobject_cast(currentScene); SCASSERT(scene != nullptr); @@ -745,6 +745,16 @@ void MainWindow::ToolArcWithLength(bool checked) &MainWindow::ApplyDialog); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolTrueDarts(bool checked) +{ + SetToolButtonWithApply(checked, Tool::TrueDarts, + "://cursor/true_darts_cursor.png", + tr("Select the first base line point"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief About show widows about. @@ -1048,6 +1058,7 @@ void MainWindow::InitToolButtons() &MainWindow::ToolPointFromCircleAndTangent); connect(ui->toolButtonPointFromArcAndTangent, &QToolButton::clicked, this, &MainWindow::ToolPointFromArcAndTangent); connect(ui->toolButtonArcWithLength, &QToolButton::clicked, this, &MainWindow::ToolArcWithLength); + connect(ui->toolButtonTrueDarts, &QToolButton::clicked, this, &MainWindow::ToolTrueDarts); } //--------------------------------------------------------------------------------------------------------------------- @@ -1176,6 +1187,9 @@ void MainWindow::CancelTool() case Tool::PointFromArcAndTangent: ui->toolButtonPointFromArcAndTangent->setChecked(false); break; + case Tool::TrueDarts: + ui->toolButtonTrueDarts->setChecked(false); + break; case Tool::NodePoint: case Tool::NodeArc: case Tool::NodeSpline: @@ -2206,6 +2220,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonPointFromCircleAndTangent->setEnabled(drawTools); ui->toolButtonPointFromArcAndTangent->setEnabled(drawTools); ui->toolButtonArcWithLength->setEnabled(drawTools); + ui->toolButtonTrueDarts->setEnabled(drawTools); ui->actionLast_tool->setEnabled(drawTools); @@ -2584,6 +2599,10 @@ void MainWindow::LastUsedTool() ui->toolButtonArcWithLength->setChecked(true); ToolArcWithLength(true); break; + case Tool::TrueDarts: + ui->toolButtonTrueDarts->setChecked(true); + ToolTrueDarts(true); + break; case Tool::NodePoint: case Tool::NodeArc: case Tool::NodeSpline: diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 37d1f8395..9035ae906 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -121,6 +121,7 @@ public slots: void ToolPointFromCircleAndTangent(bool checked); void ToolPointFromArcAndTangent(bool checked); void ToolArcWithLength(bool checked); + void ToolTrueDarts(bool checked); void ClosedDialogDetail(int result); void ClosedDialogUnionDetails(int result); diff --git a/src/app/mainwindow.ui b/src/app/mainwindow.ui index 20c17d936..58e3b2b3a 100644 --- a/src/app/mainwindow.ui +++ b/src/app/mainwindow.ui @@ -48,7 +48,7 @@ Tools - 5 + 0 @@ -56,7 +56,7 @@ 0 0 130 - 272 + 318 @@ -342,6 +342,29 @@ + + + + false + + + ... + + + + :/toolicon/32x32/true_darts.png:/toolicon/32x32/true_darts.png + + + + 32 + 32 + + + + true + + + diff --git a/src/app/share/resources/cursor.qrc b/src/app/share/resources/cursor.qrc index a09044ac0..67adbf12b 100644 --- a/src/app/share/resources/cursor.qrc +++ b/src/app/share/resources/cursor.qrc @@ -29,5 +29,6 @@ cursor/point_from_circle_and_tangent_cursor.png cursor/point_from_arc_and_tangent_cursor.png cursor/arc_with_length_cursor.png + cursor/true_darts_cursor.png diff --git a/src/app/share/resources/cursor/true_darts_cursor.png b/src/app/share/resources/cursor/true_darts_cursor.png new file mode 100644 index 000000000..00252a3b5 Binary files /dev/null and b/src/app/share/resources/cursor/true_darts_cursor.png differ diff --git a/src/app/share/resources/icon.qrc b/src/app/share/resources/icon.qrc index 39909d5be..fc72ccef5 100644 --- a/src/app/share/resources/icon.qrc +++ b/src/app/share/resources/icon.qrc @@ -45,5 +45,6 @@ icon/16x16/toolsectionpoint.png icon/16x16/toolsectiondetail.png icon/16x16/toolsectionlayout.png + toolicon/32x32/true_darts.png diff --git a/src/app/share/resources/toolicon/32x32/true_darts.png b/src/app/share/resources/toolicon/32x32/true_darts.png new file mode 100644 index 000000000..e19156c52 Binary files /dev/null and b/src/app/share/resources/toolicon/32x32/true_darts.png differ diff --git a/src/app/share/resources/toolicon/svg/true_darts.svg b/src/app/share/resources/toolicon/svg/true_darts.svg new file mode 100644 index 000000000..efcdea10b --- /dev/null +++ b/src/app/share/resources/toolicon/svg/true_darts.svg @@ -0,0 +1,101 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index a898e45c1..cfb0af7bc 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -677,7 +677,8 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem << VToolPointOfIntersectionArcs::ToolType << VToolPointOfIntersectionCircles::ToolType << VToolPointFromCircleAndTangent::ToolType - << VToolPointFromArcAndTangent::ToolType; + << VToolPointFromArcAndTangent::ToolType + << VToolTrueDarts::ToolType; switch (points.indexOf(type)) { case 0: //VToolBasePoint::ToolType @@ -1267,6 +1268,40 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem throw excep; } break; + case 21: //VToolTrueDarts::ToolType + try + { + ToolsCommonAttributes(domElement, id); + + const quint32 p1Id = GetParametrUInt(domElement, VAbstractTool::AttrPoint1, NULL_ID_STR); + const quint32 p2Id = GetParametrUInt(domElement, VAbstractTool::AttrPoint2, NULL_ID_STR); + + const quint32 baseLineP1Id = GetParametrUInt(domElement, VAbstractTool::AttrBaseLineP1, NULL_ID_STR); + const quint32 baseLineP2Id = GetParametrUInt(domElement, VAbstractTool::AttrBaseLineP2, NULL_ID_STR); + const quint32 dartP1Id = GetParametrUInt(domElement, VAbstractTool::AttrDartP1, NULL_ID_STR); + const quint32 dartP2Id = GetParametrUInt(domElement, VAbstractTool::AttrDartP2, NULL_ID_STR); + const quint32 dartP3Id = GetParametrUInt(domElement, VAbstractTool::AttrDartP3, NULL_ID_STR); + + const QString name1 = GetParametrString(domElement, VAbstractTool::AttrName1, "A"); + const qreal mx1 = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx1, "10.0")); + const qreal my1 = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy1, "15.0")); + + const QString name2 = GetParametrString(domElement, VAbstractTool::AttrName2, "A"); + const qreal mx2 = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx2, "10.0")); + const qreal my2 = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy2, "15.0")); + + VToolTrueDarts::Create(id, p1Id, p2Id, + baseLineP1Id, baseLineP2Id, dartP1Id, dartP2Id, dartP3Id, + name1, mx1, my1, name2, mx2, my2, + scene, this, data, parse, Source::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating true darts"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; default: qDebug() << "Illegal point type in VDomDocument::ParsePointElement()."; break; diff --git a/src/libs/ifc/schema/pattern/v0.1.4.xsd b/src/libs/ifc/schema/pattern/v0.1.4.xsd index caabf1851..46e5fc53b 100644 --- a/src/libs/ifc/schema/pattern/v0.1.4.xsd +++ b/src/libs/ifc/schema/pattern/v0.1.4.xsd @@ -133,6 +133,19 @@ + + + + + + + + + + + + + diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index c473e0165..22f3026c7 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -80,12 +80,13 @@ enum class Tool : unsigned char PointOfIntersection, PointFromCircleAndTangent, PointFromArcAndTangent, - UnionDetails // 36 + TrueDarts, + UnionDetails // 37 }; enum class Vis : unsigned char { - ControlPointSpline = 37, // increase this value if need more positions in Tool enum + ControlPointSpline = 38, // increase this value if need more positions in Tool enum GraphicsSimpleTextItem, SimpleSplinePath, SimplePoint, @@ -114,7 +115,8 @@ enum class Vis : unsigned char ToolSplinePath, ToolCutSplinePath, ToolLineIntersectAxis, - ToolCurveIntersectAxis + ToolCurveIntersectAxis, + ToolTrueDarts }; enum class VarType : char { Measurement, Increment, LineLength, SplineLength, ArcLength, ArcRadius, LineAngle, ArcAngle, diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index 442315bba..97b92e0d5 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -32,7 +32,8 @@ HEADERS += \ $$PWD/tools/dialogtriangle.h \ $$PWD/tools/dialoguniondetails.h \ $$PWD/support/dialogeditwrongformula.h \ - $$PWD/support/dialogundo.h + $$PWD/support/dialogundo.h \ + $$PWD/tools/dialogtruedarts.h SOURCES += \ $$PWD/tools/dialogalongline.cpp \ @@ -64,7 +65,8 @@ SOURCES += \ $$PWD/tools/dialogtriangle.cpp \ $$PWD/tools/dialoguniondetails.cpp \ $$PWD/support/dialogeditwrongformula.cpp \ - $$PWD/support/dialogundo.cpp + $$PWD/support/dialogundo.cpp \ + $$PWD/tools/dialogtruedarts.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ @@ -95,4 +97,5 @@ FORMS += \ $$PWD/tools/dialogtriangle.ui \ $$PWD/tools/dialoguniondetails.ui \ $$PWD/support/dialogeditwrongformula.ui \ - $$PWD/support/dialogundo.ui + $$PWD/support/dialogundo.ui \ + $$PWD/tools/dialogtruedarts.ui diff --git a/src/libs/vtools/dialogs/tooldialogs.h b/src/libs/vtools/dialogs/tooldialogs.h index bcce4f6cf..c87b33155 100644 --- a/src/libs/vtools/dialogs/tooldialogs.h +++ b/src/libs/vtools/dialogs/tooldialogs.h @@ -56,6 +56,7 @@ #include "dialogs/tools/dialogpointofintersectioncircles.h" #include "dialogs/tools/dialogpointfromcircleandtangent.h" #include "dialogs/tools/dialogpointfromarcandtangent.h" +#include "dialogs/tools/dialogtruedarts.h" #include "dialogs/support/dialogeditwrongformula.h" #include "dialogs/support/dialogundo.h" diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index cea6f4b50..3b9191fec 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -115,27 +115,28 @@ void DialogTool::showEvent(QShowEvent *event) * @brief FillComboBoxPoints fill comboBox list of points * @param box comboBox */ -void DialogTool::FillComboBoxPoints(QComboBox *box, FillComboBox rule) const +void DialogTool::FillComboBoxPoints(QComboBox *box, FillComboBox rule, const quint32 &ch1, const quint32 &ch2) const { - FillCombo(box, GOType::Point, rule); + FillCombo(box, GOType::Point, rule, ch1, ch2); } //--------------------------------------------------------------------------------------------------------------------- -void DialogTool::FillComboBoxArcs(QComboBox *box, FillComboBox rule) const +void DialogTool::FillComboBoxArcs(QComboBox *box, FillComboBox rule, const quint32 &ch1, const quint32 &ch2) const { - FillCombo(box, GOType::Arc, rule); + FillCombo(box, GOType::Arc, rule, ch1, ch2); } //--------------------------------------------------------------------------------------------------------------------- -void DialogTool::FillComboBoxSplines(QComboBox *box, FillComboBox rule) const +void DialogTool::FillComboBoxSplines(QComboBox *box, FillComboBox rule, const quint32 &ch1, const quint32 &ch2) const { - FillCombo(box, GOType::Spline, rule); + FillCombo(box, GOType::Spline, rule, ch1, ch2); } //--------------------------------------------------------------------------------------------------------------------- -void DialogTool::FillComboBoxSplinesPath(QComboBox *box, FillComboBox rule) const +void DialogTool::FillComboBoxSplinesPath(QComboBox *box, FillComboBox rule, const quint32 &ch1, + const quint32 &ch2) const { - FillCombo(box, GOType::SplinePath, rule); + FillCombo(box, GOType::SplinePath, rule, ch1, ch2); } //--------------------------------------------------------------------------------------------------------------------- @@ -386,13 +387,14 @@ qreal DialogTool::Eval(const QString &text, bool &flag, QLabel *label, const QSt } //--------------------------------------------------------------------------------------------------------------------- -void DialogTool::setCurrentPointId(QComboBox *box, const quint32 &value, FillComboBox rule) const +void DialogTool::setCurrentPointId(QComboBox *box, const quint32 &value, FillComboBox rule, + const quint32 &ch1, const quint32 &ch2) const { SCASSERT(box != nullptr); box->blockSignals(true); - FillComboBoxPoints(box, rule); + FillComboBoxPoints(box, rule, ch1, ch2); ChangeCurrentData(box, value); box->blockSignals(false); @@ -402,10 +404,11 @@ void DialogTool::setCurrentPointId(QComboBox *box, const quint32 &value, FillCom /** * @brief setCurrentSplineId set current spline id in combobox */ -void DialogTool::setCurrentSplineId(QComboBox *box, const quint32 &value, FillComboBox rule) const +void DialogTool::setCurrentSplineId(QComboBox *box, const quint32 &value, FillComboBox rule, + const quint32 &ch1, const quint32 &ch2) const { SCASSERT(box != nullptr); - FillComboBoxSplines(box, rule); + FillComboBoxSplines(box, rule, ch1, ch2); ChangeCurrentData(box, value); } @@ -413,10 +416,11 @@ void DialogTool::setCurrentSplineId(QComboBox *box, const quint32 &value, FillCo /** * @brief setCurrentArcId */ -void DialogTool::setCurrentArcId(QComboBox *box, const quint32 &value, FillComboBox rule) const +void DialogTool::setCurrentArcId(QComboBox *box, const quint32 &value, FillComboBox rule, + const quint32 &ch1, const quint32 &ch2) const { SCASSERT(box != nullptr); - FillComboBoxArcs(box, rule); + FillComboBoxArcs(box, rule, ch1, ch2); ChangeCurrentData(box, value); } @@ -427,10 +431,11 @@ void DialogTool::setCurrentArcId(QComboBox *box, const quint32 &value, FillCombo * @param value splinePath id * @param cut if set to ComboMode::CutSpline don't show id+1 and id+2 */ -void DialogTool::setCurrentSplinePathId(QComboBox *box, const quint32 &value, FillComboBox rule) const +void DialogTool::setCurrentSplinePathId(QComboBox *box, const quint32 &value, FillComboBox rule, + const quint32 &ch1, const quint32 &ch2) const { SCASSERT(box != nullptr); - FillComboBoxSplinesPath(box, rule); + FillComboBoxSplinesPath(box, rule, ch1, ch2); ChangeCurrentData(box, value); } @@ -800,9 +805,12 @@ void DialogTool::SetAssociatedTool(VAbstractTool *tool) //--------------------------------------------------------------------------------------------------------------------- template -void DialogTool::FillCombo(QComboBox *box, GOType gType, FillComboBox rule) const +void DialogTool::FillCombo(QComboBox *box, GOType gType, FillComboBox rule, const quint32 &ch1, + const quint32 &ch2) const { SCASSERT(box != nullptr); + box->blockSignals(true); + const QHash > *objs = data->DataGObjects(); QHash >::const_iterator i; QMap list; @@ -810,7 +818,7 @@ void DialogTool::FillCombo(QComboBox *box, GOType gType, FillComboBox rule) cons { if (rule == FillComboBox::NoChildren) { - if (i.key() != toolId + 1 && i.key() != toolId + 2) + if (i.key() != toolId && i.key() != ch1 && i.key() != ch2) { QSharedPointer obj = i.value(); if (obj->getType() == gType && obj->getMode() == Draw::Calculation) @@ -834,4 +842,6 @@ void DialogTool::FillCombo(QComboBox *box, GOType gType, FillComboBox rule) cons } } FillList(box, list); + + box->blockSignals(false); } diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index 131886543..ff8edf75c 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -184,10 +184,14 @@ protected: virtual void closeEvent ( QCloseEvent * event ); virtual void showEvent( QShowEvent *event ); - void FillComboBoxPoints(QComboBox *box, FillComboBox rule = FillComboBox::Whole)const; - void FillComboBoxArcs(QComboBox *box, FillComboBox rule = FillComboBox::Whole)const; - void FillComboBoxSplines(QComboBox *box, FillComboBox rule = FillComboBox::Whole)const; - void FillComboBoxSplinesPath(QComboBox *box, FillComboBox rule = FillComboBox::Whole)const; + void FillComboBoxPoints(QComboBox *box, FillComboBox rule = FillComboBox::Whole, + const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID)const; + void FillComboBoxArcs(QComboBox *box, FillComboBox rule = FillComboBox::Whole, + const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID)const; + void FillComboBoxSplines(QComboBox *box, FillComboBox rule = FillComboBox::Whole, + const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID)const; + void FillComboBoxSplinesPath(QComboBox *box, FillComboBox rule = FillComboBox::Whole, + const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID)const; void FillComboBoxCurves(QComboBox *box)const; void FillComboBoxTypeLine(QComboBox *box, const QMap &stylesPics) const; void FillComboBoxLineColors(QComboBox *box)const; @@ -202,13 +206,17 @@ protected: bool checkZero = true); void setCurrentPointId(QComboBox *box, const quint32 &value, - FillComboBox rule = FillComboBox::NoChildren) const; + FillComboBox rule = FillComboBox::NoChildren, + const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID) const; void setCurrentSplineId(QComboBox *box, const quint32 &value, - FillComboBox rule = FillComboBox::NoChildren) const; + FillComboBox rule = FillComboBox::NoChildren, + const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID) const; void setCurrentArcId(QComboBox *box, const quint32 &value, - FillComboBox rule = FillComboBox::NoChildren) const; + FillComboBox rule = FillComboBox::NoChildren, + const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID) const; void setCurrentSplinePathId(QComboBox *box, const quint32 &value, - FillComboBox rule = FillComboBox::NoChildren) const; + FillComboBox rule = FillComboBox::NoChildren, + const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID) const; void setCurrentCurveId(QComboBox *box, const quint32 &value) const; quint32 getCurrentObjectId(QComboBox *box) const; @@ -311,7 +319,8 @@ private: void FillList(QComboBox *box, const QMap &list)const; template - void FillCombo(QComboBox *box, GOType gType, FillComboBox rule = FillComboBox::Whole) const; + void FillCombo(QComboBox *box, GOType gType, FillComboBox rule = FillComboBox::Whole, + const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID) const; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogtruedarts.cpp b/src/libs/vtools/dialogs/tools/dialogtruedarts.cpp new file mode 100644 index 000000000..beeb7bc3f --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogtruedarts.cpp @@ -0,0 +1,422 @@ +/************************************************************************ + ** + ** @file dialogtruedarts.cpp + ** @author Roman Telezhynskyi + ** @date 12 6, 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 "dialogtruedarts.h" +#include "ui_dialogtruedarts.h" +#include "../vgeometry/vpointf.h" +#include "../vpatterndb/vcontainer.h" +#include "../../visualization/vistooltruedarts.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "../qmuparser/qmudef.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogTrueDarts::DialogTrueDarts(const VContainer *data, const quint32 &toolId, QWidget *parent) + :DialogTool(data, toolId, parent), ui(new Ui::DialogTrueDarts), d1PointName(), d2PointName(), ch1(NULL_ID), + ch2(NULL_ID), flagName1(true), flagName2(true) +{ + ui->setupUi(this); + const QString name1 = qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel); + const QString name2 = qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel, name1); + ui->lineEditFirstNewDartPoint->setText(name1); + ui->lineEditSecondNewDartPoint->setText(name2); + + InitOkCancelApply(ui); + CheckState(); + + FillComboBoxs(ch1, ch2); + + connect(ui->lineEditFirstNewDartPoint, &QLineEdit::textChanged, this, &DialogTrueDarts::NameDartPoint1Changed); + connect(ui->lineEditSecondNewDartPoint, &QLineEdit::textChanged, this, &DialogTrueDarts::NameDartPoint2Changed); + connect(ui->comboBoxFirstBasePoint, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogTrueDarts::PointNameChanged); + connect(ui->comboBoxSecondBasePoint, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogTrueDarts::PointNameChanged); + connect(ui->comboBoxFirstDartPoint, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogTrueDarts::PointNameChanged); + connect(ui->comboBoxSecondDartPoint, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogTrueDarts::PointNameChanged); + connect(ui->comboBoxThirdDartPoint, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogTrueDarts::PointNameChanged); + + vis = new VisToolTrueDarts(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogTrueDarts::~DialogTrueDarts() +{ + DeleteVisualization(); + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogTrueDarts::GetFirstNewDartPointName() +{ + return d1PointName; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogTrueDarts::GetSecondNewDartPointName() +{ + return d2PointName; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::SetNewDartPointNames(const QString &firstPoint, const QString &secondPoint) +{ + ui->lineEditFirstNewDartPoint->blockSignals(true); + ui->lineEditSecondNewDartPoint->blockSignals(true); + + d1PointName = firstPoint; + ui->lineEditFirstNewDartPoint->setText(d1PointName); + + d2PointName = secondPoint; + ui->lineEditSecondNewDartPoint->setText(d2PointName); + + ui->lineEditSecondNewDartPoint->blockSignals(false); + ui->lineEditFirstNewDartPoint->blockSignals(false); + + CheckName(ui->lineEditFirstNewDartPoint, ui->labelFirstNewDartPoint, d1PointName, d2PointName, + ui->lineEditSecondNewDartPoint, flagName1); + CheckName(ui->lineEditSecondNewDartPoint, ui->labelSecondNewDartPoint, d1PointName, d2PointName, + ui->lineEditFirstNewDartPoint, flagName2); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogTrueDarts::GetFirstBasePointId() const +{ + return getCurrentObjectId(ui->comboBoxFirstBasePoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::SetFirstBasePointId(const quint32 &value) +{ + setCurrentPointId(ui->comboBoxFirstBasePoint, value, FillComboBox::NoChildren, ch1, ch2); + + VisToolTrueDarts *points = qobject_cast(vis); + SCASSERT(points != nullptr); + points->setPoint1Id(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogTrueDarts::GetSecondBasePointId() const +{ + return getCurrentObjectId(ui->comboBoxSecondBasePoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::SetSecondBasePointId(const quint32 &value) +{ + setCurrentPointId(ui->comboBoxSecondBasePoint, value, FillComboBox::NoChildren, ch1, ch2); + + VisToolTrueDarts *points = qobject_cast(vis); + SCASSERT(points != nullptr); + points->setPoint2Id(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogTrueDarts::GetFirstDartPointId() const +{ + return getCurrentObjectId(ui->comboBoxFirstDartPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::SetFirstDartPointId(const quint32 &value) +{ + setCurrentPointId(ui->comboBoxFirstDartPoint, value, FillComboBox::NoChildren, ch1, ch2); + + VisToolTrueDarts *points = qobject_cast(vis); + SCASSERT(points != nullptr); + points->setD1PointId(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogTrueDarts::GetSecondDartPointId() const +{ + return getCurrentObjectId(ui->comboBoxSecondDartPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::SetSecondDartPointId(const quint32 &value) +{ + setCurrentPointId(ui->comboBoxSecondDartPoint, value, FillComboBox::NoChildren, ch1, ch2); + + VisToolTrueDarts *points = qobject_cast(vis); + SCASSERT(points != nullptr); + points->setD2PointId(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogTrueDarts::GetThirdDartPointId() const +{ + return getCurrentObjectId(ui->comboBoxThirdDartPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::SetThirdDartPointId(const quint32 &value) +{ + setCurrentPointId(ui->comboBoxThirdDartPoint, value, FillComboBox::NoChildren, ch1, ch2); + + VisToolTrueDarts *points = qobject_cast(vis); + SCASSERT(points != nullptr); + points->setD3PointId(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::SetChildrenId(const quint32 &ch1, const quint32 &ch2) +{ + this->ch1 = ch1; + this->ch2 = ch2; + FillComboBoxs(ch1, ch2); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::ChosenObject(quint32 id, const SceneObject &type) +{ + if (prepare == false)// After first choose we ignore all objects + { + if (type == SceneObject::Point) + { + VisToolTrueDarts *points = qobject_cast(vis); + SCASSERT(points != nullptr); + + switch (number) + { + case 0: + if (SetObject(id, ui->comboBoxFirstBasePoint, tr("Select the second base point"))) + { + number++; + points->VisualMode(id); + } + break; + case 1: + if (getCurrentObjectId(ui->comboBoxFirstBasePoint) != id) + { + if (SetObject(id, ui->comboBoxSecondBasePoint, tr("Select the first dart point"))) + { + number++; + points->setPoint2Id(id); + points->RefreshGeometry(); + } + } + break; + case 2: + { + QSet set; + set.insert(getCurrentObjectId(ui->comboBoxFirstBasePoint)); + set.insert(getCurrentObjectId(ui->comboBoxSecondBasePoint)); + set.insert(id); + + if (set.size() == 3) + { + if (SetObject(id, ui->comboBoxFirstDartPoint, tr("Select the second dart point"))) + { + number++; + points->setD1PointId(id); + points->RefreshGeometry(); + } + } + break; + } + case 3: + { + QSet set; + set.insert(getCurrentObjectId(ui->comboBoxFirstBasePoint)); + set.insert(getCurrentObjectId(ui->comboBoxSecondBasePoint)); + set.insert(getCurrentObjectId(ui->comboBoxFirstDartPoint)); + set.insert(id); + + if (set.size() == 4) + { + if (SetObject(id, ui->comboBoxSecondDartPoint, tr("Select the third dart point"))) + { + number++; + points->setD2PointId(id); + points->RefreshGeometry(); + } + } + break; + } + case 4: + { + QSet set; + set.insert(getCurrentObjectId(ui->comboBoxFirstBasePoint)); + set.insert(getCurrentObjectId(ui->comboBoxSecondBasePoint)); + set.insert(getCurrentObjectId(ui->comboBoxFirstDartPoint)); + set.insert(getCurrentObjectId(ui->comboBoxSecondDartPoint)); + set.insert(id); + + if (set.size() == 5) + { + if (SetObject(id, ui->comboBoxThirdDartPoint, "")) + { + points->setD3PointId(id); + points->RefreshGeometry(); + prepare = true; + this->setModal(true); + this->show(); + } + } + break; + } + default: + break; + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::PointNameChanged() +{ + QSet set; + set.insert(getCurrentObjectId(ui->comboBoxFirstBasePoint)); + set.insert(getCurrentObjectId(ui->comboBoxSecondBasePoint)); + set.insert(getCurrentObjectId(ui->comboBoxFirstDartPoint)); + set.insert(getCurrentObjectId(ui->comboBoxSecondDartPoint)); + set.insert(getCurrentObjectId(ui->comboBoxThirdDartPoint)); + + QColor color = okColor; + if (set.size() != 5) + { + flagError = false; + color = errorColor; + } + else + { + flagError = true; + color = okColor; + } + ChangeColor(ui->labelFirstBasePoint, color); + ChangeColor(ui->labelSecondBasePoint, color); + ChangeColor(ui->labelFirstDartPoint, color); + ChangeColor(ui->labelSecondDartPoint, color); + ChangeColor(ui->labelThirdDartPoint, color); + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::NameDartPoint1Changed() +{ + NameChanged(ui->labelFirstNewDartPoint, d1PointName, d2PointName, ui->lineEditSecondNewDartPoint, flagName1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::NameDartPoint2Changed() +{ + NameChanged(ui->labelSecondNewDartPoint, d1PointName, d2PointName, ui->lineEditFirstNewDartPoint, flagName2); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::ShowVisualization() +{ + AddVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::SaveData() +{ + d1PointName = ui->lineEditFirstNewDartPoint->text(); + d2PointName = ui->lineEditSecondNewDartPoint->text(); + + VisToolTrueDarts *points = qobject_cast(vis); + SCASSERT(points != nullptr); + + points->setPoint1Id(GetFirstBasePointId()); + points->setPoint2Id(GetSecondBasePointId()); + points->setD1PointId(GetFirstDartPointId()); + points->setD2PointId(GetSecondDartPointId()); + points->setD3PointId(GetThirdDartPointId()); + points->RefreshGeometry(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::CheckState() +{ + SCASSERT(bOk != nullptr); + bOk->setEnabled(flagName1 && flagName2 && flagError); + // In case dialog hasn't apply button + if ( bApply != nullptr) + { + bApply->setEnabled(bOk->isEnabled()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::NameChanged(QLabel *labelEditNamePoint, const QString &pointD1Name, const QString &pointD2Name, + QLineEdit* secondPointName, bool &flagName) +{ + SCASSERT(labelEditNamePoint != nullptr); + SCASSERT(secondPointName != nullptr); + QLineEdit* edit = qobject_cast(sender()); + if (edit) + { + CheckName(edit, labelEditNamePoint, pointD1Name, pointD2Name, secondPointName, flagName); + } + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::FillComboBoxs(const quint32 &ch1, const quint32 &ch2) +{ + FillComboBoxPoints(ui->comboBoxFirstBasePoint, FillComboBox::NoChildren, ch1, ch2); + FillComboBoxPoints(ui->comboBoxSecondBasePoint, FillComboBox::NoChildren, ch1, ch2); + FillComboBoxPoints(ui->comboBoxFirstDartPoint, FillComboBox::NoChildren, ch1, ch2); + FillComboBoxPoints(ui->comboBoxSecondDartPoint, FillComboBox::NoChildren, ch1, ch2); + FillComboBoxPoints(ui->comboBoxThirdDartPoint, FillComboBox::NoChildren, ch1, ch2); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTrueDarts::CheckName(QLineEdit *edit, QLabel *labelEditNamePoint, const QString &pointD1Name, + const QString &pointD2Name, QLineEdit *secondPointName, bool &flagName) +{ + SCASSERT(labelEditNamePoint != nullptr); + SCASSERT(secondPointName != nullptr); + SCASSERT(edit != nullptr); + + const QString name = edit->text(); + const QString secondName = secondPointName->text(); + QRegularExpression rx(NameRegExp()); + if (name.isEmpty() + || secondName == name + || (pointD1Name != name && pointD2Name != name && data->IsUnique(name) == false) + || rx.match(name).hasMatch() == false) + { + flagName = false; + ChangeColor(labelEditNamePoint, Qt::red); + } + else + { + flagName = true; + ChangeColor(labelEditNamePoint, okColor); + } +} diff --git a/src/libs/vtools/dialogs/tools/dialogtruedarts.h b/src/libs/vtools/dialogs/tools/dialogtruedarts.h new file mode 100644 index 000000000..c0cb2b2c6 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogtruedarts.h @@ -0,0 +1,102 @@ +/************************************************************************ + ** + ** @file dialogtruedarts.h + ** @author Roman Telezhynskyi + ** @date 12 6, 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 DIALOGTRUEDARTS_H +#define DIALOGTRUEDARTS_H + +#include "dialogtool.h" + +namespace Ui +{ + class DialogTrueDarts; +} + +class DialogTrueDarts : public DialogTool +{ + Q_OBJECT + +public: + DialogTrueDarts(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr); + ~DialogTrueDarts(); + + QString GetFirstNewDartPointName(); + QString GetSecondNewDartPointName(); + void SetNewDartPointNames(const QString &firstPoint, const QString &secondPoint); + + quint32 GetFirstBasePointId() const; + void SetFirstBasePointId(const quint32 &value); + + quint32 GetSecondBasePointId() const; + void SetSecondBasePointId(const quint32 &value); + + quint32 GetFirstDartPointId() const; + void SetFirstDartPointId(const quint32 &value); + + quint32 GetSecondDartPointId() const; + void SetSecondDartPointId(const quint32 &value); + + quint32 GetThirdDartPointId() const; + void SetThirdDartPointId(const quint32 &value); + + void SetChildrenId(const quint32 &ch1, const quint32 &ch2); +public slots: + virtual void ChosenObject(quint32 id, const SceneObject &type); + virtual void PointNameChanged(); + void NameDartPoint1Changed(); + void NameDartPoint2Changed(); +protected: + virtual void ShowVisualization(); + /** + * @brief SaveData Put dialog data in local variables + */ + virtual void SaveData(); + virtual void CheckState(); + +private: + Q_DISABLE_COPY(DialogTrueDarts) + Ui::DialogTrueDarts *ui; + + QString d1PointName; + QString d2PointName; + + quint32 ch1; + quint32 ch2; + + bool flagName1; + bool flagName2; + + void NameChanged(QLabel *labelEditNamePoint, const QString &pointD1Name, const QString &pointD2Name, + QLineEdit *secondPointName, bool &flagName); + + void FillComboBoxs(const quint32 &ch1, const quint32 &ch2); + + void CheckName(QLineEdit* edit, QLabel *labelEditNamePoint, const QString &pointD1Name, const QString &pointD2Name, + QLineEdit *secondPointName, bool &flagName); +}; + +#endif // DIALOGTRUEDARTS_H diff --git a/src/libs/vtools/dialogs/tools/dialogtruedarts.ui b/src/libs/vtools/dialogs/tools/dialogtruedarts.ui new file mode 100644 index 000000000..a7233a3f3 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogtruedarts.ui @@ -0,0 +1,202 @@ + + + DialogTrueDarts + + + + 0 + 0 + 333 + 278 + + + + True darts + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + + + + + + + + + 0 + 0 + + + + First base point + + + + + + + First point of angle + + + + + + + + 0 + 0 + + + + Second base point + + + + + + + Second point of angle + + + + + + + + 0 + 0 + + + + First dart point + + + + + + + Third point of angle + + + + + + + Second dart point + + + + + + + + 0 + 0 + + + + + 80 + 0 + + + + Show line from second point to this point + + + + 80 + 14 + + + + + + + + Third dart point + + + + + + + + + + + 0 + 0 + + + + First new dart point + + + + + + + + + + Second new dart point + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogTrueDarts + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogTrueDarts + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libs/vtools/tools/drawTools/drawtools.h b/src/libs/vtools/tools/drawTools/drawtools.h index e3dc2079e..a81794070 100644 --- a/src/libs/vtools/tools/drawTools/drawtools.h +++ b/src/libs/vtools/tools/drawTools/drawtools.h @@ -54,5 +54,6 @@ #include "toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.h" #include "toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h" #include "toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h" +#include "toolpoint/tooldoublepoint/vtooltruedarts.h" #endif // DRAWTOOLS_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp index 0e9c868d1..eb4e71ff0 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp @@ -29,7 +29,7 @@ #include "vtooldoublepoint.h" #include "../vwidgets/vsimplepoint.h" #include "../vgeometry/vpointf.h" -#include "../../../../undocommands/movelabel.h" +#include "../../../../undocommands/movedoublelabel.h" //--------------------------------------------------------------------------------------------------------------------- VToolDoublePoint::VToolDoublePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 p1id, quint32 p2id, @@ -43,13 +43,15 @@ VToolDoublePoint::VToolDoublePoint(VAbstractPattern *doc, VContainer *data, quin connect(firstPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::contextMenuEvent); connect(firstPoint, &VSimplePoint::Delete, this, &VToolDoublePoint::DeleteFromLabel); connect(firstPoint, &VSimplePoint::NameChangedPosition, this, &VToolDoublePoint::Label1ChangePosition); + firstPoint->RefreshGeometry(*VAbstractTool::data.GeometricObject(p1id)); secondPoint = new VSimplePoint(p2id, QColor(baseColor), *data->GetPatternUnit(), &factor); secondPoint->setParentItem(this); connect(secondPoint, &VSimplePoint::Choosed, this, &VToolDoublePoint::Point2Choosed); - connect(firstPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::contextMenuEvent); - connect(firstPoint, &VSimplePoint::Delete, this, &VToolDoublePoint::DeleteFromLabel); - connect(firstPoint, &VSimplePoint::NameChangedPosition, this, &VToolDoublePoint::Label2ChangePosition); + connect(secondPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::contextMenuEvent); + connect(secondPoint, &VSimplePoint::Delete, this, &VToolDoublePoint::DeleteFromLabel); + connect(secondPoint, &VSimplePoint::NameChangedPosition, this, &VToolDoublePoint::Label2ChangePosition); + secondPoint->RefreshGeometry(*VAbstractTool::data.GeometricObject(p2id)); } //--------------------------------------------------------------------------------------------------------------------- @@ -102,13 +104,13 @@ void VToolDoublePoint::SetEnabled(bool enabled) //--------------------------------------------------------------------------------------------------------------------- void VToolDoublePoint::Label1ChangePosition(const QPointF &pos) { - ChangePosition(this, p1id, pos); + ChangePosition(firstPoint, p1id, pos); } //--------------------------------------------------------------------------------------------------------------------- void VToolDoublePoint::Label2ChangePosition(const QPointF &pos) { - ChangePosition(this, p2id, pos); + ChangePosition(secondPoint, p2id, pos); } //--------------------------------------------------------------------------------------------------------------------- @@ -157,28 +159,39 @@ void VToolDoublePoint::FullUpdateFromFile() } //--------------------------------------------------------------------------------------------------------------------- -void VToolDoublePoint::UpdateNamePosition() +void VToolDoublePoint::UpdateNamePosition(quint32 id) { - qApp->getUndoStack()->beginMacro("move labels"); + if (id == p1id) + { + VPointF *p1 = VAbstractTool::data.GeometricObject(p1id).data(); - VPointF *p1 = VAbstractTool::data.GeometricObject(p1id).data(); - MoveLabel *moveLabel1 = new MoveLabel(doc, p1->mx(), p1->my(), p1id, this->scene()); - connect(moveLabel1, &MoveLabel::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); - qApp->getUndoStack()->push(moveLabel1); + MoveDoubleLabel *moveLabel = new MoveDoubleLabel(doc, p1->mx(), p1->my(), DoublePoint::FirstPoint, this->id, + this->scene()); + connect(moveLabel, &MoveDoubleLabel::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(moveLabel); + } + else if (id == p2id) + { + VPointF *p2 = VAbstractTool::data.GeometricObject(p2id).data(); - VPointF *p2 = VAbstractTool::data.GeometricObject(p2id).data(); - MoveLabel *moveLabel2 = new MoveLabel(doc, p2->mx(), p2->my(), p2id, this->scene()); - connect(moveLabel2, &MoveLabel::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); - qApp->getUndoStack()->push(moveLabel2); - - qApp->getUndoStack()->endMacro(); + MoveDoubleLabel *moveLabel = new MoveDoubleLabel(doc, p2->mx(), p2->my(), DoublePoint::SecondPoint, this->id, + this->scene()); + connect(moveLabel, &MoveDoubleLabel::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(moveLabel); + } } //--------------------------------------------------------------------------------------------------------------------- -void VToolDoublePoint::RefreshLine() +void VToolDoublePoint::RefreshLine(quint32 id) { - firstPoint->RefreshLine(); - secondPoint->RefreshLine(); + if (id == p1id) + { + firstPoint->RefreshLine(); + } + else if (id == p2id) + { + secondPoint->RefreshLine(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -243,12 +256,6 @@ void VToolDoublePoint::SaveOptions(QDomElement &tag, QSharedPointer &o doc->SetAttribute(tag, AttrName1, point->name()); doc->SetAttribute(tag, AttrMx1, qApp->fromPixel(point->mx())); doc->SetAttribute(tag, AttrMy1, qApp->fromPixel(point->my())); - - VPointF *p = VAbstractTool::data.GeometricObject(p2id).data(); - - doc->SetAttribute(tag, AttrName2, p->name()); - doc->SetAttribute(tag, AttrMx2, qApp->fromPixel(p->mx())); - doc->SetAttribute(tag, AttrMy2, qApp->fromPixel(p->my())); } else if (obj->id() == p2id) { @@ -258,22 +265,18 @@ void VToolDoublePoint::SaveOptions(QDomElement &tag, QSharedPointer &o doc->SetAttribute(tag, AttrName2, point->name()); doc->SetAttribute(tag, AttrMx2, qApp->fromPixel(point->mx())); doc->SetAttribute(tag, AttrMy2, qApp->fromPixel(point->my())); - - VPointF *p = VAbstractTool::data.GeometricObject(p1id).data(); - - doc->SetAttribute(tag, AttrName1, p->name()); - doc->SetAttribute(tag, AttrMx1, qApp->fromPixel(p->mx())); - doc->SetAttribute(tag, AttrMy1, qApp->fromPixel(p->my())); } else { VPointF *p1 = VAbstractTool::data.GeometricObject(p1id).data(); - VPointF *p2 = VAbstractTool::data.GeometricObject(p1id).data(); + VPointF *p2 = VAbstractTool::data.GeometricObject(p2id).data(); + doc->SetAttribute(tag, AttrPoint1, p1id); doc->SetAttribute(tag, AttrName1, p1->name()); doc->SetAttribute(tag, AttrMx1, qApp->fromPixel(p1->mx())); doc->SetAttribute(tag, AttrMy1, qApp->fromPixel(p1->my())); + doc->SetAttribute(tag, AttrPoint2, p2id); doc->SetAttribute(tag, AttrName2, p2->name()); doc->SetAttribute(tag, AttrMx2, qApp->fromPixel(p2->mx())); doc->SetAttribute(tag, AttrMy2, qApp->fromPixel(p2->my())); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h index bbee41cf7..b972f7d16 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h @@ -75,8 +75,8 @@ protected: quint32 p1id; quint32 p2id; - virtual void UpdateNamePosition(); - virtual void RefreshLine(); + virtual void UpdateNamePosition(quint32 id); + virtual void RefreshLine(quint32 id); virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); virtual void keyReleaseEvent(QKeyEvent * event); virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp new file mode 100644 index 000000000..737f71fa5 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp @@ -0,0 +1,362 @@ +/************************************************************************ + ** + ** @file vtooltruedarts.cpp + ** @author Roman Telezhynskyi + ** @date 23 6, 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 "vtooltruedarts.h" +#include "../../../../dialogs/tools/dialogtruedarts.h" +#include "../vgeometry/vpointf.h" +#include "../../../../visualization/vistooltruedarts.h" + +const QString VToolTrueDarts::ToolType = QStringLiteral("trueDarts"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolTrueDarts::VToolTrueDarts(VAbstractPattern *doc, + VContainer *data, + const quint32 &id, + const quint32 &p1id, + const quint32 &p2id, + const quint32 &baseLineP1Id, + const quint32 &baseLineP2Id, + const quint32 &dartP1Id, + const quint32 &dartP2Id, + const quint32 &dartP3Id, + const Source &typeCreation, + QGraphicsItem *parent) + :VToolDoublePoint(doc, data, id, p1id, p2id, parent), + baseLineP1Id (baseLineP1Id), + baseLineP2Id(baseLineP2Id), + dartP1Id(dartP1Id), + dartP2Id(dartP2Id), + dartP3Id(dartP3Id) +{ + ToolCreation(typeCreation); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTrueDarts::FindPoint(const QPointF &baseLineP1, const QPointF &baseLineP2, const QPointF &dartP1, + const QPointF &dartP2, const QPointF &dartP3, QPointF &p1, QPointF &p2) +{ + const QLineF d2d1(dartP2, dartP1); + const QLineF d2d3(dartP2, dartP3); + + const qreal degrees = d2d3.angleTo(d2d1); + + QLineF d2blP2(dartP2, baseLineP2); + d2blP2.setAngle(d2d3.angle()+degrees); + const QPointF bP2Temp = d2blP2.p2(); + + const QLineF bP1bP2Temp(baseLineP1, bP2Temp); + + const QLineF::IntersectType res = bP1bP2Temp.intersect(d2d1, &p1); + + if (res == QLineF::NoIntersection) + { + p1 = QPointF(0, 0); + p2 = QPointF(0, 0); + return; + } + + QLineF d2p1(dartP2, p1); + d2p1.setAngle(d2p1.angle()-degrees); + p2 = d2p1.p2(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTrueDarts::setDialog() +{ + SCASSERT(dialog != nullptr); + DialogTrueDarts *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + + const QSharedPointer p1 = VAbstractTool::data.GeometricObject(p1id); + const QSharedPointer p2 = VAbstractTool::data.GeometricObject(p2id); + + dialogTool->SetChildrenId(p1id, p2id); + dialogTool->SetNewDartPointNames(p1->name(), p2->name()); + dialogTool->SetFirstBasePointId(baseLineP1Id); + dialogTool->SetSecondBasePointId(baseLineP2Id); + dialogTool->SetFirstDartPointId(dartP1Id); + dialogTool->SetSecondDartPointId(dartP2Id); + dialogTool->SetThirdDartPointId(dartP3Id); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolTrueDarts *VToolTrueDarts::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data) +{ + SCASSERT(dialog != nullptr); + DialogTrueDarts *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + + const QString point1Name = dialogTool->GetFirstNewDartPointName(); + const QString point2Name = dialogTool->GetSecondNewDartPointName(); + const quint32 baseLineP1Id = dialogTool->GetFirstBasePointId(); + const quint32 baseLineP2Id = dialogTool->GetSecondBasePointId(); + const quint32 dartP1Id = dialogTool->GetFirstDartPointId(); + const quint32 dartP2Id = dialogTool->GetSecondDartPointId(); + const quint32 dartP3Id = dialogTool->GetThirdDartPointId(); + + VToolTrueDarts *point = nullptr; + point=Create(0, 0, 0, baseLineP1Id, baseLineP2Id, dartP1Id, dartP2Id, dartP3Id, point1Name, 5, 10, point2Name, 5, + 10, scene, doc, data, Document::FullParse, Source::FromGui); + if (point != nullptr) + { + point->dialog = dialogTool; + } + return point; +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolTrueDarts *VToolTrueDarts::Create(quint32 _id, + const quint32 &_p1id, const quint32 &_p2id, + const quint32 &baseLineP1Id, + const quint32 &baseLineP2Id, + const quint32 &dartP1Id, + const quint32 &dartP2Id, + const quint32 &dartP3Id, + const QString &point1Name, const qreal &mx1, const qreal &my1, + const QString &point2Name, const qreal &mx2, const qreal &my2, + VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation) +{ + const QSharedPointer baseLineP1 = data->GeometricObject(baseLineP1Id); + const QSharedPointer baseLineP2 = data->GeometricObject(baseLineP2Id); + const QSharedPointer dartP1 = data->GeometricObject(dartP1Id); + const QSharedPointer dartP2 = data->GeometricObject(dartP2Id); + const QSharedPointer dartP3 = data->GeometricObject(dartP3Id); + + QPointF fPoint1; + QPointF fPoint2; + VToolTrueDarts::FindPoint(baseLineP1->toQPointF(), baseLineP2->toQPointF(), + dartP1->toQPointF(), dartP2->toQPointF(), dartP3->toQPointF(), fPoint1, fPoint2); + quint32 id = _id; + quint32 p1id = _p1id; + quint32 p2id = _p2id; + if (typeCreation == Source::FromGui) + { + id = data->getNextId();//Just reserve id for tool + p1id = data->AddGObject(new VPointF(fPoint1, point1Name, mx1, my1)); + p2id = data->AddGObject(new VPointF(fPoint2, point2Name, mx2, my2)); + } + else + { + data->UpdateGObject(p1id, new VPointF(fPoint1, point1Name, mx1, my1)); + data->UpdateGObject(p2id, new VPointF(fPoint2, point2Name, mx2, my2)); + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + VDrawTool::AddRecord(id, Tool::TrueDarts, doc); + if (parse == Document::FullParse) + { + VToolTrueDarts *points = new VToolTrueDarts(doc, data, id, p1id, p2id, baseLineP1Id, baseLineP2Id, + dartP1Id, dartP2Id, dartP3Id, typeCreation); + scene->addItem(points); + connect(points, &VToolDoublePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(scene, &VMainGraphicsScene::NewFactor, points, &VToolTrueDarts::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, points, &VToolTrueDarts::Disable); + connect(scene, &VMainGraphicsScene::EnableToolMove, points, &VToolTrueDarts::EnableToolMove); + doc->AddTool(id, points); + doc->IncrementReferens(baseLineP1Id); + doc->IncrementReferens(baseLineP2Id); + doc->IncrementReferens(dartP1Id); + doc->IncrementReferens(dartP2Id); + doc->IncrementReferens(dartP3Id); + return points; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTrueDarts::ShowVisualization(bool show) +{ + ShowToolVisualization(show); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolTrueDarts::GetBaseLineP1Id() const +{ + return baseLineP1Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTrueDarts::SetBaseLineP1Id(const quint32 &value) +{ + if (value != NULL_ID) + { + baseLineP1Id = value; + + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolTrueDarts::GetBaseLineP2Id() const +{ + return baseLineP2Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTrueDarts::SetBaseLineP2Id(const quint32 &value) +{ + if (value != NULL_ID) + { + baseLineP2Id = value; + + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolTrueDarts::GetDartP1Id() const +{ + return dartP1Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTrueDarts::SetDartP1Id(const quint32 &value) +{ + if (value != NULL_ID) + { + dartP1Id = value; + + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolTrueDarts::GetDartP2Id() const +{ + return dartP2Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTrueDarts::SetDartP2Id(const quint32 &value) +{ + if (value != NULL_ID) + { + dartP2Id = value; + + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolTrueDarts::GetDartP3Id() const +{ + return dartP3Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTrueDarts::SetDartP3Id(const quint32 &value) +{ + if (value != NULL_ID) + { + dartP3Id = value; + + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTrueDarts::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(this, event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTrueDarts::RemoveReferens() +{ + doc->DecrementReferens(baseLineP1Id); + doc->DecrementReferens(baseLineP2Id); + doc->DecrementReferens(dartP1Id); + doc->DecrementReferens(dartP2Id); + doc->DecrementReferens(dartP3Id); + VToolDoublePoint::RemoveReferens(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTrueDarts::SaveDialog(QDomElement &domElement) +{ + SCASSERT(dialog != nullptr); + DialogTrueDarts *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + + doc->SetAttribute(domElement, AttrName1, dialogTool->GetFirstNewDartPointName()); + doc->SetAttribute(domElement, AttrName2, dialogTool->GetSecondNewDartPointName()); + doc->SetAttribute(domElement, AttrBaseLineP1, QString().setNum(dialogTool->GetFirstBasePointId())); + doc->SetAttribute(domElement, AttrBaseLineP2, QString().setNum(dialogTool->GetSecondBasePointId())); + doc->SetAttribute(domElement, AttrDartP1, QString().setNum(dialogTool->GetFirstDartPointId())); + doc->SetAttribute(domElement, AttrDartP2, QString().setNum(dialogTool->GetSecondDartPointId())); + doc->SetAttribute(domElement, AttrDartP3, QString().setNum(dialogTool->GetThirdDartPointId())); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTrueDarts::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + VToolDoublePoint::SaveOptions(tag, obj); + + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrBaseLineP1, baseLineP1Id); + doc->SetAttribute(tag, AttrBaseLineP2, baseLineP2Id); + doc->SetAttribute(tag, AttrDartP1, dartP1Id); + doc->SetAttribute(tag, AttrDartP2, dartP2Id); + doc->SetAttribute(tag, AttrDartP3, dartP3Id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTrueDarts::ReadToolAttributes(const QDomElement &domElement) +{ + baseLineP1Id = doc->GetParametrUInt(domElement, AttrBaseLineP1, NULL_ID_STR); + baseLineP2Id = doc->GetParametrUInt(domElement, AttrBaseLineP2, NULL_ID_STR); + dartP1Id = doc->GetParametrUInt(domElement, AttrDartP1, NULL_ID_STR); + dartP2Id = doc->GetParametrUInt(domElement, AttrDartP2, NULL_ID_STR); + dartP3Id = doc->GetParametrUInt(domElement, AttrDartP3, NULL_ID_STR); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTrueDarts::SetVisualization() +{ + if (vis != nullptr) + { + VisToolTrueDarts *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(baseLineP1Id); + visual->setPoint2Id(baseLineP2Id); + visual->setD1PointId(dartP1Id); + visual->setD2PointId(dartP2Id); + visual->setD3PointId(dartP3Id); + visual->RefreshGeometry(); + } +} diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h new file mode 100644 index 000000000..d9204085a --- /dev/null +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h @@ -0,0 +1,105 @@ +/************************************************************************ + ** + ** @file vtooltruedarts.h + ** @author Roman Telezhynskyi + ** @date 23 6, 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 VTOOLTRUEDARTS_H +#define VTOOLTRUEDARTS_H + +#include "vtooldoublepoint.h" + +class VToolTrueDarts : public VToolDoublePoint +{ + Q_OBJECT +public: + VToolTrueDarts(VAbstractPattern *doc, + VContainer *data, + const quint32 &id, + const quint32 &p1id, + const quint32 &p2id, + const quint32 &baseLineP1Id, + const quint32 &baseLineP2Id, + const quint32 &dartP1Id, + const quint32 &dartP2Id, + const quint32 &dartP3Id, + const Source &typeCreation, + QGraphicsItem * parent = nullptr); + + static void FindPoint(const QPointF &baseLineP1, const QPointF &baseLineP2, const QPointF &dartP1, + const QPointF &dartP2, const QPointF &dartP3, QPointF &p1, QPointF &p2); + virtual void setDialog(); + static VToolTrueDarts* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data); + static VToolTrueDarts* Create(quint32 _id, + const quint32 &_p1id, const quint32 &_p2id, + const quint32 &baseLineP1Id, + const quint32 &baseLineP2Id, + const quint32 &dartP1Id, + const quint32 &dartP2Id, + const quint32 &dartP3Id, + const QString &point1Name, const qreal &mx1, const qreal &my1, + const QString &point2Name, const qreal &mx2, const qreal &my2, + VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation); + static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::TrueDarts)}; + + virtual void ShowVisualization(bool show); + + quint32 GetBaseLineP1Id() const; + void SetBaseLineP1Id(const quint32 &value); + + quint32 GetBaseLineP2Id() const; + void SetBaseLineP2Id(const quint32 &value); + + quint32 GetDartP1Id() const; + void SetDartP1Id(const quint32 &value); + + quint32 GetDartP2Id() const; + void SetDartP2Id(const quint32 &value); + + quint32 GetDartP3Id() const; + void SetDartP3Id(const quint32 &value); + +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void RemoveReferens(); + 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(VToolTrueDarts) + quint32 baseLineP1Id; + quint32 baseLineP2Id; + quint32 dartP1Id; + quint32 dartP2Id; + quint32 dartP3Id; +}; + +#endif // VTOOLTRUEDARTS_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index 46d1d79ac..8c3cd0662 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -112,7 +112,7 @@ void VToolSinglePoint::NameChangePosition(const QPointF &pos) * @param mx label bias x axis. * @param my label bias y axis. */ -void VToolSinglePoint::UpdateNamePosition() +void VToolSinglePoint::UpdateNamePosition(quint32 id) { VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(id)); MoveLabel *moveLabel = new MoveLabel(doc, point->mx(), point->my(), id, this->scene()); @@ -224,7 +224,7 @@ void VToolSinglePoint::RefreshPointGeometry(const VPointF &point) namePoint->setText(point.name()); namePoint->setPos(QPointF(point.mx(), point.my())); namePoint->blockSignals(false); - RefreshLine(); + RefreshLine(id); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); } @@ -232,8 +232,10 @@ void VToolSinglePoint::RefreshPointGeometry(const VPointF &point) /** * @brief RefreshLine refresh line to label on scene. */ -void VToolSinglePoint::RefreshLine() +void VToolSinglePoint::RefreshLine(quint32 id) { + Q_UNUSED(id) + QRectF nRec = namePoint->sceneBoundingRect(); nRec.translate(- scenePos()); if (this->rect().intersects(nRec) == false) diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h index b3ae98ecc..dc4520b13 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h @@ -71,12 +71,12 @@ protected: /** @brief lineName line what we see if label moved too away from point. */ QGraphicsLineItem *lineName; - virtual void UpdateNamePosition(); + virtual void UpdateNamePosition(quint32 id); virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); virtual void RefreshPointGeometry(const VPointF &point); - virtual void RefreshLine(); + virtual void RefreshLine(quint32 id); virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); virtual void keyReleaseEvent(QKeyEvent * event); virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h index 2fe636043..e01e6872a 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h @@ -56,8 +56,8 @@ protected: template void ChangePosition(T *item, quint32 id, const QPointF &pos); - virtual void UpdateNamePosition()=0; - virtual void RefreshLine()=0; + virtual void UpdateNamePosition(quint32 id)=0; + virtual void RefreshLine(quint32 id)=0; template void SetToolEnabled(T *item, bool enabled); @@ -116,9 +116,9 @@ void VAbstractPoint::ChangePosition(T *item, quint32 id, const QPointF &pos) const QPointF p = pos - item->pos(); point->setMx(p.x()); point->setMy(p.y()); - RefreshLine(); VAbstractTool::data.UpdateGObject(id, point); - UpdateNamePosition(); + RefreshLine(id); + UpdateNamePosition(id); } #endif // VABSTRACTPOINT_H diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index 334d53bf0..37d9559d0 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -45,7 +45,8 @@ HEADERS += \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h \ $$PWD/drawTools/toolcurve/vtoolarcwithlength.h \ $$PWD/drawTools/toolpoint/vabstractpoint.h \ - $$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h + $$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h \ + $$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -88,4 +89,5 @@ SOURCES += \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp \ $$PWD/drawTools/toolcurve/vtoolarcwithlength.cpp \ $$PWD/drawTools/toolpoint/vabstractpoint.cpp \ - $$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp + $$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp \ + $$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp diff --git a/src/libs/vtools/tools/vabstracttool.cpp b/src/libs/vtools/tools/vabstracttool.cpp index 493c3f9a6..61370ab03 100644 --- a/src/libs/vtools/tools/vabstracttool.cpp +++ b/src/libs/vtools/tools/vabstracttool.cpp @@ -50,6 +50,11 @@ const QString VAbstractTool::AttrName1 = QStringLiteral("name1"); const QString VAbstractTool::AttrMx2 = QStringLiteral("mx2"); const QString VAbstractTool::AttrMy2 = QStringLiteral("my2"); const QString VAbstractTool::AttrName2 = QStringLiteral("name2"); +const QString VAbstractTool::AttrBaseLineP1 = QStringLiteral("baseLineP1"); +const QString VAbstractTool::AttrBaseLineP2 = QStringLiteral("baseLineP2"); +const QString VAbstractTool::AttrDartP1 = QStringLiteral("dartP1"); +const QString VAbstractTool::AttrDartP2 = QStringLiteral("dartP2"); +const QString VAbstractTool::AttrDartP3 = QStringLiteral("dartP3"); const QString VAbstractTool::AttrX = QStringLiteral("x"); const QString VAbstractTool::AttrY = QStringLiteral("y"); const QString VAbstractTool::AttrTypeLine = QStringLiteral("typeLine"); @@ -71,6 +76,7 @@ const QString VAbstractTool::AttrP1Line2 = QStringLiteral("p1Line2"); const QString VAbstractTool::AttrP2Line2 = QStringLiteral("p2Line2"); const QString VAbstractTool::AttrPShoulder = QStringLiteral("pShoulder"); const QString VAbstractTool::AttrPoint1 = QStringLiteral("point1"); +const QString VAbstractTool::AttrPoint2 = QStringLiteral("point2"); const QString VAbstractTool::AttrPoint4 = QStringLiteral("point4"); const QString VAbstractTool::AttrKAsm1 = QStringLiteral("kAsm1"); const QString VAbstractTool::AttrKAsm2 = QStringLiteral("kAsm2"); diff --git a/src/libs/vtools/tools/vabstracttool.h b/src/libs/vtools/tools/vabstracttool.h index a619a3ec9..6795e1099 100644 --- a/src/libs/vtools/tools/vabstracttool.h +++ b/src/libs/vtools/tools/vabstracttool.h @@ -64,6 +64,11 @@ public: static const QString AttrMx2; static const QString AttrMy2; static const QString AttrName2; + static const QString AttrBaseLineP1; + static const QString AttrBaseLineP2; + static const QString AttrDartP1; + static const QString AttrDartP2; + static const QString AttrDartP3; static const QString AttrX; static const QString AttrY; static const QString AttrTypeLine; @@ -85,6 +90,7 @@ public: static const QString AttrP2Line2; static const QString AttrPShoulder; static const QString AttrPoint1; + static const QString AttrPoint2; static const QString AttrPoint4; static const QString AttrKAsm1; static const QString AttrKAsm2; diff --git a/src/libs/vtools/undocommands/movedoublelabel.cpp b/src/libs/vtools/undocommands/movedoublelabel.cpp new file mode 100644 index 000000000..6d32c0e75 --- /dev/null +++ b/src/libs/vtools/undocommands/movedoublelabel.cpp @@ -0,0 +1,190 @@ +/************************************************************************ + ** + ** @file movedoublelabel.cpp + ** @author Roman Telezhynskyi + ** @date 24 6, 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 "movedoublelabel.h" +#include "../tools/vabstracttool.h" +#include "../../vwidgets/vmaingraphicsview.h" + +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const double &y, DoublePoint type, + const quint32 &id, QGraphicsScene *scene, QUndoCommand *parent) + : VUndoCommand(QDomElement(), doc, parent), + oldMx(0.0), oldMy(0.0), + newMx(x), newMy(y), + scene(scene), type(type) +{ + if (type == DoublePoint::FirstPoint) + { + setText(tr("move the first dart label")); + } + else + { + setText(tr("move the second dart label")); + } + nodeId = id; + qCDebug(vUndo, "Point id %u", nodeId); + + if (type == DoublePoint::FirstPoint) + { + qCDebug(vUndo, "Label new Mx1 %f", newMx); + qCDebug(vUndo, "Label new My1 %f", newMy); + } + else + { + qCDebug(vUndo, "Label new Mx2 %f", newMx); + qCDebug(vUndo, "Label new My2 %f", newMy); + } + + SCASSERT(scene != nullptr); + QDomElement domElement = doc->elementById(id); + if (domElement.isElement()) + { + if (type == DoublePoint::FirstPoint) + { + oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrMx1, "0.0")); + oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrMy1, "0.0")); + } + else + { + oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrMx2, "0.0")); + oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrMy2, "0.0")); + } + + if (type == DoublePoint::FirstPoint) + { + qCDebug(vUndo, "Label old Mx1 %f", oldMx); + qCDebug(vUndo, "Label old My1 %f", oldMy); + } + else + { + qCDebug(vUndo, "Label old Mx2 %f", oldMx); + qCDebug(vUndo, "Label old My2 %f", oldMy); + } + } + else + { + qCDebug(vUndo, "Can't find point with id = %u.", nodeId); + return; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +MoveDoubleLabel::~MoveDoubleLabel() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void MoveDoubleLabel::undo() +{ + qCDebug(vUndo, "Undo."); + + Do(oldMx, oldMy); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MoveDoubleLabel::redo() +{ + qCDebug(vUndo, "Redo."); + + Do(newMx, newMy); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool MoveDoubleLabel::mergeWith(const QUndoCommand *command) +{ + const MoveDoubleLabel *moveCommand = static_cast(command); + SCASSERT(moveCommand != nullptr); + + if (moveCommand->getPointId() != nodeId || moveCommand->getPointType() != type) + { + return false; + } + + newMx = moveCommand->getNewMx(); + newMy = moveCommand->getNewMy(); + + if (type == DoublePoint::FirstPoint) + { + qCDebug(vUndo, "Label new Mx1 %f", newMx); + qCDebug(vUndo, "Label new My1 %f", newMy); + } + else + { + qCDebug(vUndo, "Label new Mx2 %f", newMx); + qCDebug(vUndo, "Label new My2 %f", newMy); + } + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +int MoveDoubleLabel::id() const +{ + return static_cast(UndoCommand::MoveDoubleLabel); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MoveDoubleLabel::Do(double mx, double my) +{ + if (type == DoublePoint::FirstPoint) + { + qCDebug(vUndo, "New mx1 %f", mx); + qCDebug(vUndo, "New my1 %f", my); + } + else + { + qCDebug(vUndo, "New mx2 %f", mx); + qCDebug(vUndo, "New my2 %f", my); + } + + QDomElement domElement = doc->elementById(nodeId); + if (domElement.isElement()) + { + if (type == DoublePoint::FirstPoint) + { + doc->SetAttribute(domElement, VAbstractTool::AttrMx1, QString().setNum(qApp->fromPixel(mx))); + doc->SetAttribute(domElement, VAbstractTool::AttrMy1, QString().setNum(qApp->fromPixel(my))); + } + else + { + doc->SetAttribute(domElement, VAbstractTool::AttrMx2, QString().setNum(qApp->fromPixel(mx))); + doc->SetAttribute(domElement, VAbstractTool::AttrMy2, QString().setNum(qApp->fromPixel(my))); + } + + emit NeedLiteParsing(Document::LitePPParse); + + QList list = scene->views(); + VMainGraphicsView::NewSceneRect(scene, list[0]); + } + else + { + qCDebug(vUndo, "Can't find point with id = %u.", nodeId); + return; + } +} diff --git a/src/libs/vtools/undocommands/movedoublelabel.h b/src/libs/vtools/undocommands/movedoublelabel.h new file mode 100644 index 000000000..5d6bf4871 --- /dev/null +++ b/src/libs/vtools/undocommands/movedoublelabel.h @@ -0,0 +1,88 @@ +/************************************************************************ + ** + ** @file movedoublelabel.h + ** @author Roman Telezhynskyi + ** @date 24 6, 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 MOVEDOUBLELABEL_H +#define MOVEDOUBLELABEL_H + +#include "vundocommand.h" + +class QGraphicsScene; + +enum class DoublePoint: char { FirstPoint, SecondPoint }; + +class MoveDoubleLabel : public VUndoCommand +{ + Q_OBJECT +public: + MoveDoubleLabel(VAbstractPattern *doc, const double &x, const double &y, DoublePoint type, + const quint32 &id, QGraphicsScene *scene, QUndoCommand *parent = 0); + virtual ~MoveDoubleLabel(); + virtual void undo(); + virtual void redo(); + virtual bool mergeWith(const QUndoCommand *command); + virtual int id() const; + quint32 getPointId() const; + double getNewMx() const; + double getNewMy() const; + DoublePoint getPointType() const; + void Do(double mx, double my); +private: + Q_DISABLE_COPY(MoveDoubleLabel) + double oldMx; + double oldMy; + double newMx; + double newMy; + QGraphicsScene *scene; + DoublePoint type; +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline quint32 MoveDoubleLabel::getPointId() const +{ + return nodeId; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline DoublePoint MoveDoubleLabel::getPointType() const +{ + return type; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline double MoveDoubleLabel::getNewMx() const +{ + return newMx; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline double MoveDoubleLabel::getNewMy() const +{ + return newMy; +} + +#endif // MOVEDOUBLELABEL_H diff --git a/src/libs/vtools/undocommands/undocommands.pri b/src/libs/vtools/undocommands/undocommands.pri index bb14dd605..ab4307d71 100644 --- a/src/libs/vtools/undocommands/undocommands.pri +++ b/src/libs/vtools/undocommands/undocommands.pri @@ -18,7 +18,8 @@ HEADERS += \ $$PWD/deletedetail.h \ $$PWD/vundocommand.h \ $$PWD/renamepp.h \ - $$PWD/movelabel.h + $$PWD/movelabel.h \ + $$PWD/movedoublelabel.h SOURCES += \ $$PWD/addtocalc.cpp \ @@ -37,4 +38,5 @@ SOURCES += \ $$PWD/deletedetail.cpp \ $$PWD/vundocommand.cpp \ $$PWD/renamepp.cpp \ - $$PWD/movelabel.cpp + $$PWD/movelabel.cpp \ + $$PWD/movedoublelabel.cpp diff --git a/src/libs/vtools/undocommands/vundocommand.h b/src/libs/vtools/undocommands/vundocommand.h index 09f9b533d..6a63ec2d1 100644 --- a/src/libs/vtools/undocommands/vundocommand.h +++ b/src/libs/vtools/undocommands/vundocommand.h @@ -48,7 +48,8 @@ enum class UndoCommand: char { AddPatternPiece, DeleteTool, DeletePatternPiece, RenamePP, - MoveLabel + MoveLabel, + MoveDoubleLabel }; class VPattern; diff --git a/src/libs/vtools/visualization/vistooltruedarts.cpp b/src/libs/vtools/visualization/vistooltruedarts.cpp new file mode 100644 index 000000000..dff39dc64 --- /dev/null +++ b/src/libs/vtools/visualization/vistooltruedarts.cpp @@ -0,0 +1,159 @@ +/************************************************************************ + ** + ** @file vistooltruedarts.cpp + ** @author Roman Telezhynskyi + ** @date 23 6, 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 "vistooltruedarts.h" +#include "../vgeometry/vpointf.h" +#include "../vpatterndb/vcontainer.h" +#include "../tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolTrueDarts::VisToolTrueDarts(const VContainer *data, QGraphicsItem *parent) + :VisLine(data, parent), + baseLineP2Id(NULL_ID), + dartP1Id(NULL_ID), + dartP2Id(NULL_ID), + dartP3Id(NULL_ID), + point1(nullptr), + point2(nullptr), + baseLineP1(nullptr), + baseLineP2(nullptr), + dartP1(nullptr), + dartP2(nullptr), + dartP3(nullptr), + lineblP1P1(nullptr), + lineblP2P2(nullptr), + p1d2(nullptr), + d2p2(nullptr) +{ + baseLineP1 = InitPoint(supportColor, this); + baseLineP2 = InitPoint(supportColor, this); + dartP1 = InitPoint(supportColor, this); + dartP2 = InitPoint(supportColor, this); + dartP3 = InitPoint(supportColor, this); + + lineblP1P1 = InitItem(supportColor, this); + lineblP2P2 = InitItem(supportColor, this); + p1d2 = InitItem(supportColor, this); + d2p2 = InitItem(supportColor, this); + + point1 = InitPoint(mainColor, this); + point2 = InitPoint(mainColor, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolTrueDarts::~VisToolTrueDarts() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolTrueDarts::RefreshGeometry() +{ + if (point1Id > NULL_ID) + { + const QSharedPointer blP1 = Visualization::data->GeometricObject(point1Id); + DrawPoint(baseLineP1, blP1->toQPointF(), supportColor); + + if (baseLineP2Id <= NULL_ID) + { + DrawLine(this, QLineF(blP1->toQPointF(), Visualization::scenePos), supportColor, Qt::DashLine); + } + else + { + const QSharedPointer blP2 = Visualization::data->GeometricObject(baseLineP2Id); + DrawPoint(baseLineP2, blP2->toQPointF(), supportColor); + DrawLine(this, QLineF(blP1->toQPointF(), blP2->toQPointF()), supportColor, Qt::DashLine); + + if (dartP1Id > NULL_ID) + { + const QSharedPointer d1 = Visualization::data->GeometricObject(dartP1Id); + DrawPoint(dartP1, d1->toQPointF(), supportColor); + + if (dartP2Id <= NULL_ID) + { + DrawLine(p1d2, QLineF(d1->toQPointF(), Visualization::scenePos), supportColor); + } + else + { + const QSharedPointer d2 = Visualization::data->GeometricObject(dartP2Id); + DrawPoint(dartP2, d2->toQPointF(), supportColor); + DrawLine(p1d2, QLineF(d1->toQPointF(), d2->toQPointF()), supportColor); + + if (dartP3Id <= NULL_ID) + { + DrawLine(d2p2, QLineF(d2->toQPointF(), Visualization::scenePos), supportColor); + } + else + { + const QSharedPointer d3 = Visualization::data->GeometricObject(dartP3Id); + DrawPoint(dartP3, d3->toQPointF(), supportColor); + DrawLine(d2p2, QLineF(d2->toQPointF(), d3->toQPointF()), supportColor); + + QPointF p1; + QPointF p2; + VToolTrueDarts::FindPoint(blP1->toQPointF(), + blP2->toQPointF(), + d1->toQPointF(), + d2->toQPointF(), + d3->toQPointF(), p1, p2); + + DrawLine(lineblP1P1, QLineF(blP1->toQPointF(), p1), supportColor); + DrawLine(lineblP2P2, QLineF(blP2->toQPointF(), p2), supportColor); + DrawLine(p1d2, QLineF(p1, d2->toQPointF()), supportColor); + DrawLine(d2p2, QLineF(d2->toQPointF(), p2), supportColor); + + DrawPoint(point1, p1, mainColor); + DrawPoint(point2, p2, mainColor); + } + } + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolTrueDarts::setPoint2Id(const quint32 &value) +{ + baseLineP2Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolTrueDarts::setD1PointId(const quint32 &value) +{ + dartP1Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolTrueDarts::setD2PointId(const quint32 &value) +{ + dartP2Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolTrueDarts::setD3PointId(const quint32 &value) +{ + dartP3Id = value; +} diff --git a/src/libs/vtools/visualization/vistooltruedarts.h b/src/libs/vtools/visualization/vistooltruedarts.h new file mode 100644 index 000000000..80d9e1223 --- /dev/null +++ b/src/libs/vtools/visualization/vistooltruedarts.h @@ -0,0 +1,71 @@ +/************************************************************************ + ** + ** @file vistooltruedarts.h + ** @author Roman Telezhynskyi + ** @date 23 6, 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 VISTOOLTRUEDARTS_H +#define VISTOOLTRUEDARTS_H + +#include "visline.h" + +class VisToolTrueDarts :public VisLine +{ + Q_OBJECT +public: + VisToolTrueDarts(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolTrueDarts(); + + virtual void RefreshGeometry(); + + void setPoint2Id(const quint32 &value); + void setD1PointId(const quint32 &value); + void setD2PointId(const quint32 &value); + void setD3PointId(const quint32 &value); + + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolTrueDarts)}; +private: + Q_DISABLE_COPY(VisToolTrueDarts) + quint32 baseLineP2Id; + quint32 dartP1Id; + quint32 dartP2Id; + quint32 dartP3Id; + + QGraphicsEllipseItem *point1; + QGraphicsEllipseItem *point2; + QGraphicsEllipseItem *baseLineP1; + QGraphicsEllipseItem *baseLineP2; + QGraphicsEllipseItem *dartP1; + QGraphicsEllipseItem *dartP2; + QGraphicsEllipseItem *dartP3; + + QGraphicsLineItem *lineblP1P1; + QGraphicsLineItem *lineblP2P2; + QGraphicsLineItem *p1d2; + QGraphicsLineItem *d2p2; +}; + +#endif // VISTOOLTRUEDARTS_H diff --git a/src/libs/vtools/visualization/visualization.pri b/src/libs/vtools/visualization/visualization.pri index fd25ef5d7..23105fd73 100644 --- a/src/libs/vtools/visualization/visualization.pri +++ b/src/libs/vtools/visualization/visualization.pri @@ -28,7 +28,8 @@ HEADERS += \ $$PWD/vistoolpointofintersectioncircles.h \ $$PWD/vistoolpointfromcircleandtangent.h \ $$PWD/vistoolpointfromarcandtangent.h \ - $$PWD/vistoolarcwithlength.h + $$PWD/vistoolarcwithlength.h \ + visualization/vistooltruedarts.h SOURCES += \ $$PWD/visline.cpp \ @@ -57,4 +58,5 @@ SOURCES += \ $$PWD/vistoolpointofintersectioncircles.cpp \ $$PWD/vistoolpointfromcircleandtangent.cpp \ $$PWD/vistoolpointfromarcandtangent.cpp \ - $$PWD/vistoolarcwithlength.cpp + $$PWD/vistoolarcwithlength.cpp \ + visualization/vistooltruedarts.cpp