diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index ae4116e90..0e6bfe0c7 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -78,7 +78,7 @@ void VToolOptionsPropertyBrowser::ClearPropertyBrowser() void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were used in switch."); switch (item->type()) { @@ -205,7 +205,7 @@ void VToolOptionsPropertyBrowser::UpdateOptions() } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were used in switch."); switch (currentItem->type()) { @@ -350,7 +350,7 @@ void VToolOptionsPropertyBrowser::userChangedData(VPE::VProperty *property) } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were used in switch."); switch (currentItem->type()) { diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index 1bdf98b7a..aa01d7f64 100644 --- a/src/app/valentina/dialogs/dialoghistory.cpp +++ b/src/app/valentina/dialogs/dialoghistory.cpp @@ -212,7 +212,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") QString DialogHistory::Record(const VToolRecord &tool) { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were used in history."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were used in history."); const QDomElement domElem = doc->elementById(tool.getId()); if (domElem.isElement() == false) @@ -406,6 +406,7 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::Move: case Tool::PiecePath: case Tool::Pin: + case Tool::PlaceLabel: case Tool::InsertNode: return QString(); } diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 58105575c..ba1faff63 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -55,6 +55,7 @@ #include "tools/vtoolseamallowance.h" #include "tools/nodeDetails/vtoolpiecepath.h" #include "tools/nodeDetails/vtoolpin.h" +#include "tools/nodeDetails/vtoolplacelabel.h" #include "tools/vtooluniondetails.h" #include "dialogs/dialogs.h" #include "dialogs/vwidgetgroups.h" @@ -611,6 +612,9 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons ui->view->setShowToolOptions(false); dialogTool = QSharedPointer(new Dialog(pattern, 0, this)); + // This check helps to find missed tools in the switch + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54, "Check if need to extend."); + switch(t) { case Tool::Midpoint: @@ -619,6 +623,7 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons case Tool::PiecePath: case Tool::Pin: case Tool::InsertNode: + case Tool::PlaceLabel: dialogTool->SetPiecesList(doc->GetActivePPPieces()); break; default: @@ -1033,6 +1038,14 @@ void MainWindow::ToolPin(bool checked) &MainWindow::ClosedDialogPin); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolPlaceLabel(bool checked) +{ + ToolSelectPointByRelease(); + SetToolButton(checked, Tool::PlaceLabel, "://cursor/place_label_cursor.png", + tr("Select placelabel center point"), &MainWindow::ClosedDialogPlaceLabel); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ToolHeight handler tool height. @@ -1200,6 +1213,18 @@ void MainWindow::ClosedDialogPin(int result) doc->LiteParseTree(Document::LiteParse); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ClosedDialogPlaceLabel(int result) +{ + SCASSERT(dialogTool != nullptr); + if (result == QDialog::Accepted) + { + VToolPlaceLabel::Create(dialogTool, doc, pattern); + } + ArrowTool(); + doc->LiteParseTree(Document::LiteParse); +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ClosedDialogInsertNode(int result) { @@ -1960,7 +1985,7 @@ void MainWindow::InitToolButtons() } // This check helps to find missed tools - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53, "Check if all tools were connected."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54, "Check if all tools were connected."); connect(ui->toolButtonEndLine, &QToolButton::clicked, this, &MainWindow::ToolEndLine); connect(ui->toolButtonLine, &QToolButton::clicked, this, &MainWindow::ToolLine); @@ -2009,6 +2034,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonEllipticalArc, &QToolButton::clicked, this, &MainWindow::ToolEllipticalArc); connect(ui->toolButtonPin, &QToolButton::clicked, this, &MainWindow::ToolPin); connect(ui->toolButtonInsertNode, &QToolButton::clicked, this, &MainWindow::ToolInsertNode); + connect(ui->toolButtonPlaceLabel, &QToolButton::clicked, this, &MainWindow::ToolPlaceLabel); } //--------------------------------------------------------------------------------------------------------------------- @@ -2036,7 +2062,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") void MainWindow::CancelTool() { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were handled."); qCDebug(vMainWindow, "Canceling tool."); dialogTool.clear(); @@ -2200,6 +2226,9 @@ void MainWindow::CancelTool() case Tool::InsertNode: ui->toolButtonInsertNode->setChecked(false); break; + case Tool::PlaceLabel: + ui->toolButtonPlaceLabel->setChecked(false); + break; } // Crash: using CRTL+Z while using line tool. @@ -3378,6 +3407,8 @@ void MainWindow::SetEnableTool(bool enable) bool modelingTools = false; bool layoutTools = false; +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") switch (mode) { case Draw::Calculation: @@ -3389,12 +3420,11 @@ void MainWindow::SetEnableTool(bool enable) case Draw::Layout: layoutTools = enable; break; - default: - break; } +QT_WARNING_POP // This check helps to find missed tools - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were handled."); //Drawing Tools ui->toolButtonEndLine->setEnabled(drawTools); @@ -3437,6 +3467,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonEllipticalArc->setEnabled(drawTools); ui->toolButtonPin->setEnabled(drawTools); ui->toolButtonInsertNode->setEnabled(drawTools); + ui->toolButtonPlaceLabel->setEnabled(drawTools); ui->actionLast_tool->setEnabled(drawTools); @@ -3721,7 +3752,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") void MainWindow::LastUsedTool() { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were handled."); if (currentTool == lastUsedTool) { @@ -3916,6 +3947,10 @@ void MainWindow::LastUsedTool() ui->toolButtonInsertNode->setChecked(true); ToolInsertNode(true); break; + case Tool::PlaceLabel: + ui->toolButtonPlaceLabel->setChecked(true); + ToolPlaceLabel(true); + break; } } diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 0351e9dd6..47e6a76a0 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -145,6 +145,7 @@ private slots: void ToolDetail(bool checked); void ToolPiecePath(bool checked); void ToolPin(bool checked); + void ToolPlaceLabel(bool checked); void ToolHeight(bool checked); void ToolTriangle(bool checked); void ToolPointOfIntersection(bool checked); @@ -180,6 +181,7 @@ private slots: void ClosedDialogGroup(int result); void ClosedDialogPiecePath(int result); void ClosedDialogPin(int result); + void ClosedDialogPlaceLabel(int result); void ClosedDialogInsertNode(int result); void ZoomFitBestCurrent(); diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index a9e3ac0af..3ac5c3541 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -55,8 +55,8 @@ 0 0 - 127 - 358 + 126 + 351 @@ -402,7 +402,7 @@ 0 0 140 - 110 + 108 @@ -511,7 +511,7 @@ 0 0 140 - 248 + 243 @@ -773,7 +773,7 @@ 0 0 140 - 248 + 243 @@ -1038,7 +1038,7 @@ 0 0 140 - 104 + 102 @@ -1121,7 +1121,7 @@ 0 0 140 - 328 + 324 @@ -1325,7 +1325,7 @@ 0 0 140 - 196 + 237 @@ -1527,6 +1527,32 @@ + + + + false + + + Place label tool + + + ... + + + + :/toolicon/32x32/place_label.png:/toolicon/32x32/place_label.png + + + + 32 + 32 + + + + true + + + @@ -1535,7 +1561,7 @@ 0 0 140 - 328 + 324 @@ -1635,7 +1661,7 @@ 0 0 1100 - 25 + 22 @@ -2737,8 +2763,8 @@ - + diff --git a/src/app/valentina/share/resources/cursor.qrc b/src/app/valentina/share/resources/cursor.qrc index ea61c6eaf..1ef61e19d 100644 --- a/src/app/valentina/share/resources/cursor.qrc +++ b/src/app/valentina/share/resources/cursor.qrc @@ -84,5 +84,7 @@ cursor/pin_cursor@2x.png cursor/insert_node_cursor.png cursor/insert_node_cursor@2x.png + cursor/place_label_cursor@2x.png + cursor/place_label_cursor.png diff --git a/src/app/valentina/share/resources/cursor/place_label_cursor.png b/src/app/valentina/share/resources/cursor/place_label_cursor.png new file mode 100644 index 000000000..8bfc47b5f Binary files /dev/null and b/src/app/valentina/share/resources/cursor/place_label_cursor.png differ diff --git a/src/app/valentina/share/resources/cursor/place_label_cursor@2x.png b/src/app/valentina/share/resources/cursor/place_label_cursor@2x.png new file mode 100644 index 000000000..8ac92cfe5 Binary files /dev/null and b/src/app/valentina/share/resources/cursor/place_label_cursor@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon.qrc b/src/app/valentina/share/resources/toolicon.qrc index 64d036f3b..85d04ac5c 100644 --- a/src/app/valentina/share/resources/toolicon.qrc +++ b/src/app/valentina/share/resources/toolicon.qrc @@ -82,5 +82,7 @@ toolicon/32x32/pin@2x.png toolicon/32x32/insert_node.png toolicon/32x32/insert_node@2x.png + toolicon/32x32/place_label@2x.png + toolicon/32x32/place_label.png diff --git a/src/app/valentina/share/resources/toolicon/32x32/place_label.png b/src/app/valentina/share/resources/toolicon/32x32/place_label.png new file mode 100644 index 000000000..533938118 Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/place_label.png differ diff --git a/src/app/valentina/share/resources/toolicon/32x32/place_label@2x.png b/src/app/valentina/share/resources/toolicon/32x32/place_label@2x.png new file mode 100644 index 000000000..5130f8312 Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/place_label@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon/svg/place_label.svg b/src/app/valentina/share/resources/toolicon/svg/place_label.svg new file mode 100644 index 000000000..96de9f670 --- /dev/null +++ b/src/app/valentina/share/resources/toolicon/svg/place_label.svg @@ -0,0 +1,80 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index a2e635357..39608bafd 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -858,7 +858,8 @@ void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse << TagGrainline << VToolSeamAllowance::TagCSA << VToolSeamAllowance::TagIPaths - << VToolSeamAllowance::TagPins; + << VToolSeamAllowance::TagPins + << VToolSeamAllowance::TagPlaceLabels; const QDomNodeList nodeList = domElement.childNodes(); for (qint32 i = 0; i < nodeList.size(); ++i) @@ -899,7 +900,10 @@ void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse initData.detail.SetInternalPaths(ParsePieceInternalPaths(element)); break; case 6:// VToolSeamAllowance::TagPins - initData.detail.SetPins(ParsePiecePins(element)); + initData.detail.SetPins(ParsePiecePointRecords(element)); + break; + case 7:// VToolSeamAllowance::TagPlaceLabels + initData.detail.SetPlaceLabels(ParsePiecePointRecords(element)); break; default: break; @@ -963,7 +967,7 @@ void VPattern::ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) ppData.SetOnFold(GetParametrBool(domElement, AttrOnFold, falseStr)); ppData.SetPos(QPointF(GetParametrDouble(domElement, AttrMx, "0"), GetParametrDouble(domElement, AttrMy, "0"))); ppData.SetLabelWidth(GetParametrString(domElement, AttrWidth, "1")); - ppData.SetLabelHeight(GetParametrString(domElement, VToolSeamAllowance::AttrHeight, "1")); + ppData.SetLabelHeight(GetParametrString(domElement, AttrHeight, "1")); ppData.SetFontSize(static_cast(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0"))); ppData.SetRotation(GetParametrString(domElement, AttrRotation, "0")); ppData.SetCenterPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR)); @@ -979,7 +983,7 @@ void VPattern::ParsePiecePatternInfo(const QDomElement &domElement, VPiece &deta patternInfo.SetVisible(GetParametrBool(domElement, AttrVisible, trueStr)); patternInfo.SetPos(QPointF(GetParametrDouble(domElement, AttrMx, "0"), GetParametrDouble(domElement, AttrMy, "0"))); patternInfo.SetLabelWidth(GetParametrString(domElement, AttrWidth, "1")); - patternInfo.SetLabelHeight(GetParametrString(domElement, VToolSeamAllowance::AttrHeight, "1")); + patternInfo.SetLabelHeight(GetParametrString(domElement, AttrHeight, "1")); patternInfo.SetFontSize(static_cast(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0"))); patternInfo.SetRotation(GetParametrString(domElement, AttrRotation, "0")); patternInfo.SetCenterPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR)); @@ -1090,7 +1094,8 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem << VToolPointFromArcAndTangent::ToolType /*20*/ << VToolTrueDarts::ToolType /*21*/ << VToolPointOfIntersectionCurves::ToolType /*22*/ - << VToolPin::ToolType; /*23*/ + << VToolPin::ToolType /*23*/ + << VToolPlaceLabel::ToolType; /*24*/ switch (points.indexOf(type)) { case 0: //VToolBasePoint::ToolType @@ -1165,6 +1170,9 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem case 23: //VToolPin::ToolType ParsePinPoint(domElement, parse); break; + case 24: //VToolPlaceLabel::ToolType + ParsePlaceLabel(domElement, parse); + break; default: VException e(tr("Unknown point type '%1'.").arg(type)); throw e; @@ -1696,6 +1704,60 @@ void VPattern::ParsePinPoint(const QDomElement &domElement, const Document &pars } } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParsePlaceLabel(QDomElement &domElement, const Document &parse) +{ + Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); + + try + { + VToolPlaceLabelInitData initData; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; + + ToolsCommonAttributes(domElement, initData.id); + initData.centerPoint = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); + initData.idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); + + initData.width = GetParametrString(domElement, AttrLength, "1.0"); + const QString w = initData.width;//need for saving fixed formula; + + initData.height = GetParametrString(domElement, AttrHeight, "1.0"); + const QString h = initData.height;//need for saving fixed formula; + + initData.angle = GetParametrString(domElement, AttrAngle, "0.0"); + const QString angle = initData.angle;//need for saving fixed formula; + + initData.type = static_cast(GetParametrUInt(domElement, AttrPlaceLabelType, "0")); + + VToolPlaceLabel::Create(initData); + + //Rewrite attribute formula. Need for situation when we have wrong formula. + if (w != initData.width || h != initData.height || angle != initData.angle) + { + SetAttribute(domElement, AttrWidth, initData.width); + SetAttribute(domElement, AttrHeight, initData.height); + SetAttribute(domElement, AttrAngle, initData.angle); + modified = true; + haveLiteChange(); + } + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating place lavel"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + catch (qmu::QmuParserError &e) + { + VExceptionObjectError excep(tr("Error creating or updating place lavel"), domElement); + excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr())); + throw excep; + } +} + //--------------------------------------------------------------------------------------------------------------------- void VPattern::ParseToolHeight(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse) { @@ -4103,7 +4165,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") QRectF VPattern::ActiveDrawBoundingRect() const { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were used."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were used."); QRectF rec; @@ -4183,6 +4245,7 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::PiecePath: case Tool::Pin: case Tool::InsertNode: + case Tool::PlaceLabel: break; } } diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 6a1a0fc30..d0a6e5780 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -180,6 +180,7 @@ private: void ParseToolPointOfContact(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParseNodePoint(const QDomElement &domElement, const Document &parse); void ParsePinPoint(const QDomElement &domElement, const Document &parse); + void ParsePlaceLabel(QDomElement &domElement, const Document &parse); void ParseToolHeight(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseToolTriangle(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseToolPointOfIntersection(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index ce3b30018..bd002fef8 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -126,6 +126,9 @@ const QString AttrClosed = QStringLiteral("closed"); const QString AttrShowLabel = QStringLiteral("showLabel"); const QString AttrShowLabel1 = QStringLiteral("showLabel1"); const QString AttrShowLabel2 = QStringLiteral("showLabel2"); +const QString AttrWidth = QStringLiteral("width"); +const QString AttrHeight = QStringLiteral("height"); +const QString AttrPlaceLabelType = QStringLiteral("placeLabelType"); const QString TypeLineNone = QStringLiteral("none"); const QString TypeLineLine = QStringLiteral("hair"); diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 4de8d078b..a14b930f7 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -145,6 +145,9 @@ extern const QString AttrClosed; extern const QString AttrShowLabel; extern const QString AttrShowLabel1; extern const QString AttrShowLabel2; +extern const QString AttrWidth; +extern const QString AttrHeight; +extern const QString AttrPlaceLabelType; extern const QString TypeLineNone; extern const QString TypeLineLine; diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index c0919498b..b78e02e07 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -41,6 +41,7 @@ schema/pattern/v0.6.4.xsd schema/pattern/v0.6.5.xsd schema/pattern/v0.6.6.xsd + schema/pattern/v0.7.0.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/pattern/v0.7.0.xsd b/src/libs/ifc/schema/pattern/v0.7.0.xsd new file mode 100644 index 000000000..2d716b4f7 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.7.0.xsd @@ -0,0 +1,1033 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 5479bbe06..170fdf218 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -124,7 +124,6 @@ const QString VAbstractPattern::AttrStart = QStringLiteral("start"); const QString VAbstractPattern::AttrPath = QStringLiteral("path"); const QString VAbstractPattern::AttrEnd = QStringLiteral("end"); const QString VAbstractPattern::AttrIncludeAs = QStringLiteral("includeAs"); -const QString VAbstractPattern::AttrWidth = QStringLiteral("width"); const QString VAbstractPattern::AttrRotation = QStringLiteral("rotation"); const QString VAbstractPattern::AttrNumber = QStringLiteral("number"); @@ -678,7 +677,7 @@ QVector VAbstractPattern::ParsePieceInternalPaths(const QDomElement &do } //--------------------------------------------------------------------------------------------------------------------- -QVector VAbstractPattern::ParsePiecePins(const QDomElement &domElement) +QVector VAbstractPattern::ParsePiecePointRecords(const QDomElement &domElement) { QVector records; const QDomNodeList nodeList = domElement.childNodes(); @@ -1772,7 +1771,7 @@ QVector VAbstractPattern::ListPointExpressions() const // Check if new tool doesn't bring new attribute with a formula. // If no just increment a number. // If new tool bring absolutely new type and has formula(s) create new method to cover it. - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54); QVector expressions; const QDomNodeList list = elementsByTagName(TagPoint); @@ -1787,6 +1786,8 @@ QVector VAbstractPattern::ListPointExpressions() const ReadExpressionAttribute(expressions, dom, AttrC2Radius); ReadExpressionAttribute(expressions, dom, AttrCRadius); ReadExpressionAttribute(expressions, dom, AttrRadius); + ReadExpressionAttribute(expressions, dom, AttrWidth); + ReadExpressionAttribute(expressions, dom, AttrHeight); } return expressions; @@ -1798,7 +1799,7 @@ QVector VAbstractPattern::ListArcExpressions() const // Check if new tool doesn't bring new attribute with a formula. // If no just increment number. // If new tool bring absolutely new type and has formula(s) create new method to cover it. - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54); QVector expressions; const QDomNodeList list = elementsByTagName(TagArc); @@ -1822,7 +1823,7 @@ QVector VAbstractPattern::ListElArcExpressions() const // Check if new tool doesn't bring new attribute with a formula. // If no just increment number. // If new tool bring absolutely new type and has formula(s) create new method to cover it. - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54); QVector expressions; const QDomNodeList list = elementsByTagName(TagElArc); @@ -1855,7 +1856,7 @@ QVector VAbstractPattern::ListPathPointExpressions() const // Check if new tool doesn't bring new attribute with a formula. // If no just increment number. // If new tool bring absolutely new type and has formula(s) create new method to cover it. - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54); QVector expressions; const QDomNodeList list = elementsByTagName(AttrPathPoint); @@ -1893,7 +1894,7 @@ QVector VAbstractPattern::ListOperationExpressions() const // Check if new tool doesn't bring new attribute with a formula. // If no just increment number. // If new tool bring absolutely new type and has formula(s) create new method to cover it. - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54); QVector expressions; const QDomNodeList list = elementsByTagName(TagOperation); @@ -1915,7 +1916,7 @@ QVector VAbstractPattern::ListNodesExpressions(const QDomElement // Check if new tool doesn't bring new attribute with a formula. // If no just increment number. // If new tool bring absolutely new type and has formula(s) create new method to cover it. - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54); QVector expressions; @@ -1938,7 +1939,7 @@ QVector VAbstractPattern::ListPathExpressions() const // Check if new tool doesn't bring new attribute with a formula. // If no just increment number. // If new tool bring absolutely new type and has formula(s) create new method to cover it. - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54); QVector expressions; const QDomNodeList list = elementsByTagName(TagPath); @@ -1976,7 +1977,7 @@ QVector VAbstractPattern::ListPieceExpressions() const // Check if new tool doesn't bring new attribute with a formula. // If no just increment number. // If new tool bring absolutely new type and has formula(s) create new method to cover it. - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 53); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 54); QVector expressions; const QDomNodeList list = elementsByTagName(TagDetail); diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 6551c6fca..920837731 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -120,7 +120,7 @@ public: static VPiecePath ParsePieceNodes(const QDomElement &domElement); static QVector ParsePieceCSARecords(const QDomElement &domElement); static QVector ParsePieceInternalPaths(const QDomElement &domElement); - static QVector ParsePiecePins(const QDomElement &domElement); + static QVector ParsePiecePointRecords(const QDomElement &domElement); void AddToolOnRemove(VDataTool *tool); @@ -267,7 +267,6 @@ public: static const QString AttrPath; static const QString AttrEnd; static const QString AttrIncludeAs; - static const QString AttrWidth; static const QString AttrRotation; static const QString AttrNumber; diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index ba6557e27..57c04f356 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -58,8 +58,8 @@ class QDomElement; */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.6.6"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.6.6.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.7.0"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.7.0.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -256,12 +256,12 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000605): return QStringLiteral("://schema/pattern/v0.6.5.xsd"); case (0x000606): + return QStringLiteral("://schema/pattern/v0.6.6.xsd"); + case (0x000700): return CurrentSchema; default: InvalidVersion(ver); - break; } - return QString();//unreachable code } //--------------------------------------------------------------------------------------------------------------------- @@ -430,10 +430,13 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(0x000606), m_convertedFileName); V_FALLTHROUGH case (0x000606): + ToV0_7_0(); + ValidateXML(XSDSchema(0x000700), m_convertedFileName); + V_FALLTHROUGH + case (0x000700): break; default: InvalidVersion(m_ver); - break; } } @@ -448,7 +451,7 @@ void VPatternConverter::DowngradeToCurrentMaxVersion() bool VPatternConverter::IsReadOnly() const { // Check if attribute readOnly was not changed in file format - Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 6, 6), + Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 7, 0), "Check attribute readOnly."); // Possibly in future attribute readOnly will change position etc. @@ -912,6 +915,16 @@ void VPatternConverter::ToV0_6_6() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_7_0() +{ + // TODO. Delete if minimal supported version is 0.7.0 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 0), + "Time to refactor the code."); + SetVersion(QStringLiteral("0.7.0")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index 088c7b492..72ce8452d 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -53,7 +53,7 @@ public: static const QString PatternMaxVerStr; static const QString CurrentSchema; static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 6, 6); + static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 7, 0); protected: virtual int MinVer() const Q_DECL_OVERRIDE; @@ -112,6 +112,7 @@ private: void ToV0_6_4(); void ToV0_6_5(); void ToV0_6_6(); + void ToV0_7_0(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); diff --git a/src/libs/vdxf/vdxfengine.cpp b/src/libs/vdxf/vdxfengine.cpp index 755dd4be1..759748eb9 100644 --- a/src/libs/vdxf/vdxfengine.cpp +++ b/src/libs/vdxf/vdxfengine.cpp @@ -643,6 +643,7 @@ bool VDxfEngine::ExportToAAMA(const QVector &details) ExportAAMANotch(detailBlock, detail); ExportAAMAGrainline(detailBlock, detail); ExportAAMAText(detailBlock, detail); + ExportAAMADrill(detailBlock, detail); input->AddBlock(detailBlock); @@ -688,11 +689,7 @@ void VDxfEngine::ExportAAMADraw(dx_ifaceBlock *detailBlock, const VLayoutPiece & detailBlock->ent.push_back(e); } } -} -//--------------------------------------------------------------------------------------------------------------------- -void VDxfEngine::ExportAAMAIntcut(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail) -{ QVector> drawIntCut = detail.InternalPathsForCut(false); for(int j = 0; j < drawIntCut.size(); ++j) { @@ -703,7 +700,27 @@ void VDxfEngine::ExportAAMAIntcut(dx_ifaceBlock *detailBlock, const VLayoutPiece } } - drawIntCut = detail.InternalPathsForCut(true); + const QVector labels = detail.GetPlaceLabels(); + foreach(const VLayoutPlaceLabel &label, labels) + { + if (label.type != PlaceLabelType::Doubletree && label.type != PlaceLabelType::Button) + { + foreach(const QPolygonF &p, label.shape) + { + DRW_Entity *e = AAMAPolygon(p, "8", false); + if (e) + { + detailBlock->ent.push_back(e); + } + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::ExportAAMAIntcut(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail) +{ + QVector> drawIntCut = detail.InternalPathsForCut(true); for(int j = 0; j < drawIntCut.size(); ++j) { DRW_Entity *e = AAMAPolygon(drawIntCut.at(j), "11", false); @@ -776,6 +793,25 @@ void VDxfEngine::ExportAAMAGlobalText(const QSharedPointer &input, con } } +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::ExportAAMADrill(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail) +{ + const QVector labels = detail.GetPlaceLabels(); + + foreach(const VLayoutPlaceLabel &label, labels) + { + if (label.type == PlaceLabelType::Doubletree || label.type == PlaceLabelType::Button) + { + DRW_Point *point = new DRW_Point(); + point->basePoint = DRW_Coord(FromPixel(label.center.x(), varInsunits), + FromPixel(getSize().height() - label.center.y(), varInsunits), 0); + point->layer = "13"; + + detailBlock->ent.push_back(point); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- DRW_Entity *VDxfEngine::AAMAPolygon(const QVector &polygon, const QString &layer, bool forceClosed) { diff --git a/src/libs/vdxf/vdxfengine.h b/src/libs/vdxf/vdxfengine.h index 67eb4c363..c09a12fb8 100644 --- a/src/libs/vdxf/vdxfengine.h +++ b/src/libs/vdxf/vdxfengine.h @@ -116,6 +116,7 @@ private: void ExportAAMAGrainline(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); void ExportAAMAText(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); void ExportAAMAGlobalText(const QSharedPointer &input, const QVector &details); + void ExportAAMADrill(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); Q_REQUIRED_RESULT DRW_Entity *AAMAPolygon(const QVector &polygon, const QString &layer, bool forceClosed); Q_REQUIRED_RESULT DRW_Entity *AAMALine(const QLineF &line, const QString &layer); diff --git a/src/libs/vgeometry/vgeometry.pri b/src/libs/vgeometry/vgeometry.pri index 039d6e477..d010aabe0 100644 --- a/src/libs/vgeometry/vgeometry.pri +++ b/src/libs/vgeometry/vgeometry.pri @@ -15,7 +15,8 @@ SOURCES += \ $$PWD/vabstractcubicbezierpath.cpp \ $$PWD/vcubicbezierpath.cpp \ $$PWD/vabstractarc.cpp \ - $$PWD/vabstractbezier.cpp + $$PWD/vabstractbezier.cpp \ + $$PWD/vplacelabelitem.cpp *msvc*:SOURCES += $$PWD/stable.cpp @@ -46,4 +47,6 @@ HEADERS += \ $$PWD/vcubicbezierpath_p.h \ $$PWD/vabstractarc.h \ $$PWD/vabstractarc_p.h \ - $$PWD/vabstractbezier.h + $$PWD/vabstractbezier.h \ + $$PWD/vplacelabelitem.h \ + $$PWD/vplacelabelitem_p.h diff --git a/src/libs/vgeometry/vgeometrydef.h b/src/libs/vgeometry/vgeometrydef.h index de9f4404b..f3a4c1a7f 100644 --- a/src/libs/vgeometry/vgeometrydef.h +++ b/src/libs/vgeometry/vgeometrydef.h @@ -29,8 +29,51 @@ #ifndef VGEOMETRYDEF_H #define VGEOMETRYDEF_H +#include +#include + enum class Draw : char { Calculation, Modeling, Layout }; -enum class GOType : char { Point, Arc, EllipticalArc, Spline, SplinePath, CubicBezier, CubicBezierPath, Unknown }; +enum class GOType : char +{ + Point, + Arc, + EllipticalArc, + Spline, + SplinePath, + CubicBezier, + CubicBezierPath, + PlaceLabel, + Unknown +}; enum class SplinePointPosition : char { FirstPoint, LastPoint }; +// Keep synchronized with XSD schema +enum class PlaceLabelType : unsigned char +{ + Segment= 0, + Rectangle = 1, + Cross = 2, + Tshaped = 3, + Doubletree = 4, + Corner = 5, + Triangle = 6, + Hshaped = 7, + Button = 8 +}; + +typedef QVector PlaceLabelImg; + +struct VLayoutPlaceLabel +{ + VLayoutPlaceLabel() + : center(), + type(PlaceLabelType::Button), + shape() + {} + + QPointF center; + PlaceLabelType type; + PlaceLabelImg shape; +}; + #endif // VGEOMETRYDEF_H diff --git a/src/libs/vgeometry/vplacelabelitem.cpp b/src/libs/vgeometry/vplacelabelitem.cpp new file mode 100644 index 000000000..3ced29e35 --- /dev/null +++ b/src/libs/vgeometry/vplacelabelitem.cpp @@ -0,0 +1,334 @@ +/************************************************************************ + ** + ** @file vplacelabelitem.cpp + ** @author Roman Telezhynskyi + ** @date 15 10, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 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 "vplacelabelitem.h" +#include "vplacelabelitem_p.h" +#include "../vpatterndb/vcontainer.h" +#include "vellipticalarc.h" + +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +VPlaceLabelItem::VPlaceLabelItem() + : VPointF(), d(new VPlaceLabelItemData) +{ + setType(GOType::PlaceLabel); + setMode(Draw::Modeling); +} + +//--------------------------------------------------------------------------------------------------------------------- +VPlaceLabelItem::VPlaceLabelItem(const VPlaceLabelItem &item) + : VPointF(item), d(item.d) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VPlaceLabelItem::~VPlaceLabelItem() +{} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPlaceLabelItem::GetWidthFormula() const +{ + return d->width; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString &VPlaceLabelItem::GetWidthFormula() +{ + return d->width; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPlaceLabelItem::GetWidth() const +{ + return d->wValue; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPlaceLabelItem::SetWidth(qreal value, const QString &formula) +{ + d->wValue = value; + d->width = formula; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPlaceLabelItem::GetHeightFormula() const +{ + return d->height; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString &VPlaceLabelItem::GetHeightFormula() +{ + return d->height; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPlaceLabelItem::GetHeight() const +{ + return d->hValue; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPlaceLabelItem::SetHeight(qreal value, const QString &formula) +{ + d->hValue = value; + d->height = formula; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPlaceLabelItem::GetAngleFormula() const +{ + return d->angle; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString &VPlaceLabelItem::GetAngleFormula() +{ + return d->angle; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPlaceLabelItem::GetAngle() const +{ + return d->aValue; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPlaceLabelItem::SetAngle(qreal value, const QString &formula) +{ + d->aValue = value; + d->angle = formula; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPlaceLabelItem::GetCorrectionAngle() const +{ + return d->correctionAngle; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPlaceLabelItem::SetCorrectionAngle(qreal value) +{ + d->correctionAngle = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VPlaceLabelItem::GetCenterPoint() const +{ + return d->centerPoint; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPlaceLabelItem::SetCenterPoint(quint32 id) +{ + d->centerPoint = id; +} + +//--------------------------------------------------------------------------------------------------------------------- +PlaceLabelType VPlaceLabelItem::GetLabelType() const +{ + return d->type; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPlaceLabelItem::SetLabelType(PlaceLabelType type) +{ + d->type = type; +} + +//--------------------------------------------------------------------------------------------------------------------- +VPlaceLabelItem &VPlaceLabelItem::operator=(const VPlaceLabelItem &item) +{ + if ( &item == this ) + { + return *this; + } + VPointF::operator=(item); + d = item.d; + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +PlaceLabelImg VPlaceLabelItem::LabelShape(const VContainer *data) const +{ + const auto center = data->GeometricObject(d->centerPoint); + + QTransform t; + t.translate(center->x(), center->y()); + t.rotate(-d->aValue+d->correctionAngle); + t.translate(-center->x(), -center->y()); + + auto SegmentShape = [center, t, this]() + { + QPolygonF shape; + shape << QPointF(center->x(), center->y() - d->hValue/2.0) << QPointF(center->x(), center->y() + d->hValue/2.0); + + return PlaceLabelImg({t.map(shape)}); + }; + + auto RectangleShape = [center, t, this]() + { + QRectF rect(QPointF(center->x() - d->wValue/2.0, center->y() - d->hValue/2.0), + QPointF(center->x() + d->wValue/2.0, center->y() + d->hValue/2.0)); + + QPolygonF shape; + shape << rect.topLeft() << rect.topRight() << rect.bottomRight() << rect.bottomLeft() << rect.topLeft(); + + return PlaceLabelImg({t.map(shape)}); + }; + + auto CrossShape = [center, t, this]() + { + QPolygonF shape1; + shape1 << QPointF(center->x(), center->y() - d->hValue/2.0) + << QPointF(center->x(), center->y() + d->hValue/2.0); + + QPolygonF shape2; + shape2 << QPointF(center->x() - d->wValue/2.0, center->y()) + << QPointF(center->x() + d->wValue/2.0, center->y()); + + return PlaceLabelImg({t.map(shape1), t.map(shape2)}); + }; + + auto TshapedShape = [center, t, this]() + { + QPointF center2(center->x(), center->y() + d->hValue/2.0); + + QPolygonF shape1; + shape1 << QPointF(center->x(), center->y()) << center2; + + QPolygonF shape2; + shape2 << QPointF(center2.x() - d->wValue/2.0, center2.y()) + << QPointF(center2.x() + d->wValue/2.0, center2.y()); + + return PlaceLabelImg({t.map(shape1), t.map(shape2)}); + }; + + auto DoubletreeShape = [center, t, this]() + { + QRectF rect(QPointF(center->x() - d->wValue/2.0, center->y() - d->hValue/2.0), + QPointF(center->x() + d->wValue/2.0, center->y() + d->hValue/2.0)); + + QPolygonF shape1; + shape1 << rect.topLeft() << rect.bottomRight(); + + QPolygonF shape2; + shape2 << rect.topRight() << rect.bottomLeft(); + + return PlaceLabelImg({t.map(shape1), t.map(shape2)}); + }; + + auto CornerShape = [center, t, this]() + { + QPolygonF shape1; + shape1 << QPointF(center->x(), center->y()) << QPointF(center->x(), center->y() + d->hValue/2.0); + + QPolygonF shape2; + shape2 << QPointF(center->x() - d->wValue/2.0, center->y()) << QPointF(center->x(), center->y()); + + return PlaceLabelImg({t.map(shape1), t.map(shape2)}); + }; + + auto TriangleShape = [center, t, this]() + { + QRectF rect(QPointF(center->x() - d->wValue/2.0, center->y() - d->hValue/2.0), + QPointF(center->x() + d->wValue/2.0, center->y() + d->hValue/2.0)); + + QPolygonF shape; + shape << rect.topLeft() << rect.topRight() << rect.bottomRight() << rect.topLeft(); + + return PlaceLabelImg({t.map(shape)}); + }; + + auto HshapedShape = [center, t, this]() + { + const QPointF center1 (center->x(), center->y() - d->hValue/2.0); + const QPointF center2 (center->x(), center->y() + d->hValue/2.0); + + QPolygonF shape1; + shape1 << center1 << center2; + + QPolygonF shape2; + shape2 << QPointF(center1.x() - d->wValue/2.0, center1.y()) + << QPointF(center1.x() + d->wValue/2.0, center1.y()); + + QPolygonF shape3; + shape3 << QPointF(center2.x() - d->wValue/2.0, center2.y()) + << QPointF(center2.x() + d->wValue/2.0, center2.y()); + + return PlaceLabelImg({t.map(shape1), t.map(shape2), t.map(shape3)}); + }; + + auto ButtonShape = [center, t, this]() + { + QPolygonF shape1; + shape1 << QPointF(center->x(), center->y() - d->hValue/2.0) + << QPointF(center->x(), center->y() + d->hValue/2.0); + + QPolygonF shape2; + shape2 << QPointF(center->x() - d->wValue/2.0, center->y()) + << QPointF(center->x() + d->wValue/2.0, center->y()); + + const qreal circleSize = 0.85; + VEllipticalArc elArc(*center, d->wValue/2.0*circleSize, d->hValue/2.0*circleSize, 0, 360, 0); + QPolygonF shape3(elArc.GetPoints()); + if (not shape3.isClosed() && not shape3.isEmpty()) + { + shape3 << shape3.first(); + } + + return PlaceLabelImg({t.map(shape1), t.map(shape2), t.map(shape3)}); + }; + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch(d->type) + { + case PlaceLabelType::Segment: + return SegmentShape(); + case PlaceLabelType::Rectangle: + return RectangleShape(); + case PlaceLabelType::Cross: + return CrossShape(); + case PlaceLabelType::Tshaped: + return TshapedShape(); + case PlaceLabelType::Doubletree: + return DoubletreeShape(); + case PlaceLabelType::Corner: + return CornerShape(); + case PlaceLabelType::Triangle: + return TriangleShape(); + case PlaceLabelType::Hshaped: + return HshapedShape(); + case PlaceLabelType::Button: + return ButtonShape(); + } + QT_WARNING_POP + + return PlaceLabelImg(); +} diff --git a/src/libs/vgeometry/vplacelabelitem.h b/src/libs/vgeometry/vplacelabelitem.h new file mode 100644 index 000000000..7dd004f79 --- /dev/null +++ b/src/libs/vgeometry/vplacelabelitem.h @@ -0,0 +1,89 @@ +/************************************************************************ + ** + ** @file vplacelabelitem.h + ** @author Roman Telezhynskyi + ** @date 15 10, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 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 VPLACELABELITEM_H +#define VPLACELABELITEM_H + +#include +#include +#include +#include + +#include "vpointf.h" + +class VPlaceLabelItemData; +class VContainer; + +class VPlaceLabelItem : public VPointF +{ +public: + VPlaceLabelItem(); + VPlaceLabelItem(const VPlaceLabelItem &item); + virtual ~VPlaceLabelItem() Q_DECL_OVERRIDE; + + VPlaceLabelItem &operator=(const VPlaceLabelItem &item); +#ifdef Q_COMPILER_RVALUE_REFS + VPlaceLabelItem &operator=(VPlaceLabelItem &&item) Q_DECL_NOTHROW { Swap(item); return *this; } +#endif + + void Swap(VPlaceLabelItem &item) Q_DECL_NOTHROW + { VPointF::Swap(item); std::swap(d, item.d); } + + QString GetWidthFormula() const; + QString& GetWidthFormula(); + qreal GetWidth() const; + void SetWidth(qreal value, const QString &formula); + + QString GetHeightFormula() const; + QString& GetHeightFormula(); + qreal GetHeight() const; + void SetHeight(qreal value, const QString &formula); + + QString GetAngleFormula() const; + QString& GetAngleFormula(); + qreal GetAngle() const; + void SetAngle(qreal value, const QString &formula); + + qreal GetCorrectionAngle() const; + void SetCorrectionAngle(qreal value); + + quint32 GetCenterPoint() const; + void SetCenterPoint(quint32 id); + + PlaceLabelType GetLabelType() const; + void SetLabelType(PlaceLabelType type); + + PlaceLabelImg LabelShape(const VContainer *data) const; + +private: + QSharedDataPointer d; +}; + +Q_DECLARE_METATYPE(VPlaceLabelItem) +Q_DECLARE_TYPEINFO(VPlaceLabelItem, Q_MOVABLE_TYPE); + +#endif // VPLACELABELITEM_H diff --git a/src/libs/vgeometry/vplacelabelitem_p.h b/src/libs/vgeometry/vplacelabelitem_p.h new file mode 100644 index 000000000..61dd9db1e --- /dev/null +++ b/src/libs/vgeometry/vplacelabelitem_p.h @@ -0,0 +1,90 @@ +/************************************************************************ + ** + ** @file vplacelabelitem_p.h + ** @author Roman Telezhynskyi + ** @date 15 10, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 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 VPLACELABELITEM_P_H +#define VPLACELABELITEM_P_H + +#include +#include "vgeometrydef.h" +#include "../ifc/ifcdef.h" +#include "../vmisc/diagnostic.h" + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Weffc++") +QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor") + +class VPlaceLabelItemData : public QSharedData +{ +public: + VPlaceLabelItemData() + : width(), + height(), + angle("0"), + type(PlaceLabelType::Button), + centerPoint(0), + wValue(0), + hValue(0), + aValue(0), + correctionAngle(0) + {} + + VPlaceLabelItemData(const VPlaceLabelItemData &item) + : QSharedData(item), + width(item.width), + height(item.height), + angle(item.angle), + type(item.type), + centerPoint(item.centerPoint), + wValue(item.wValue), + hValue(item.hValue), + aValue(item.aValue), + correctionAngle(item.correctionAngle) + {} + + virtual ~VPlaceLabelItemData(); + + QString width; + QString height; + QString angle; + PlaceLabelType type; + quint32 centerPoint; + + qreal wValue; + qreal hValue; + qreal aValue; + qreal correctionAngle; + +private: + VPlaceLabelItemData &operator=(const VPlaceLabelItemData &) Q_DECL_EQ_DELETE; +}; + +VPlaceLabelItemData::~VPlaceLabelItemData() +{} + +QT_WARNING_POP + +#endif // VPLACELABELITEM_P_H diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index edec107dc..1c4ff66c4 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -991,6 +991,21 @@ bool VAbstractPiece::IsEkvPointOnLine(const VSAPoint &iPoint, const VSAPoint &pr && qAbs(prevPoint.GetSAAfter(tmpWidth) - nextPoint.GetSABefore(tmpWidth)) < VGObject::accuracyPointOnLine); } +//--------------------------------------------------------------------------------------------------------------------- +QPainterPath VAbstractPiece::PlaceLabelImgPath(const PlaceLabelImg &img) const +{ + QPainterPath path; + foreach(const QPolygonF &p, img) + { + if (not p.isEmpty()) + { + path.moveTo(p.first()); + path.addPolygon(p); + } + } + return path; +} + //--------------------------------------------------------------------------------------------------------------------- qreal VAbstractPiece::GetMx() const { diff --git a/src/libs/vlayout/vabstractpiece.h b/src/libs/vlayout/vabstractpiece.h index 8e01030e1..fff7e847b 100644 --- a/src/libs/vlayout/vabstractpiece.h +++ b/src/libs/vlayout/vabstractpiece.h @@ -41,6 +41,7 @@ template class QVector; class VAbstractPieceData; +class QPainterPath; QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Weffc++") @@ -194,6 +195,8 @@ protected: static bool IsEkvPointOnLine(const QPointF &iPoint, const QPointF &prevPoint, const QPointF &nextPoint); static bool IsEkvPointOnLine(const VSAPoint &iPoint, const VSAPoint &prevPoint, const VSAPoint &nextPoint); + QPainterPath PlaceLabelImgPath(const PlaceLabelImg &img) const; + private: QSharedDataPointer d; diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index eb86039c0..4f9360c90 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -49,6 +49,7 @@ #include "../vmisc/vabstractapplication.h" #include "../vpatterndb/calculator.h" #include "../vgeometry/vpointf.h" +#include "../vgeometry/vplacelabelitem.h" #include "vlayoutdef.h" #include "vlayoutpiece_p.h" #include "vtextmanager.h" @@ -340,6 +341,22 @@ QStringList PieceLabelText(const QVector &labelShape, const VTextManage } return text; } + +//--------------------------------------------------------------------------------------------------------------------- +QVector ConvertPlaceLabels(const VPiece &piece, const VContainer *pattern) +{ + QVector labels; + for(int i=0; i < piece.GetPlaceLabels().size(); ++i) + { + const auto label = pattern->GeometricObject(piece.GetPlaceLabels().at(i)); + VLayoutPlaceLabel layoutLabel; + layoutLabel.shape = label->LabelShape(pattern); + layoutLabel.center = pattern->GeometricObject(label->GetCenterPoint())->toQPointF(); + layoutLabel.type = label->GetLabelType(); + labels.append(layoutLabel); + } + return labels; +} } //--------------------------------------------------------------------------------------------------------------------- @@ -381,6 +398,7 @@ VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern piece.IsSeamAllowanceBuiltIn()); det.SetInternalPaths(ConvertInternalPaths(piece, pattern)); det.SetPassmarks(piece.PassmarksLines(pattern)); + det.SetPlaceLabels(ConvertPlaceLabels(piece, pattern)); det.SetName(piece.GetName()); @@ -415,6 +433,48 @@ VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern return det; } +//--------------------------------------------------------------------------------------------------------------------- +template +QVector VLayoutPiece::Map(const QVector &points) const +{ + QVector p; + for (int i = 0; i < points.size(); ++i) + { + p.append(d->matrix.map(points.at(i))); + } + + if (d->mirror) + { + QList list = p.toList(); + for (int k=0, s=list.size(), max=(s/2); k +QVector VLayoutPiece::Map(const QVector &points) const +{ + QVector p; + foreach (const VLayoutPlaceLabel &label, points) + { + VLayoutPlaceLabel mappedLabel; + mappedLabel.type = label.type; + mappedLabel.center = d->matrix.map(label.center); + foreach (const QPolygonF &p, label.shape) + { + mappedLabel.shape.append(d->matrix.map(p)); + } + p.append(mappedLabel); + } + + return p; +} + //--------------------------------------------------------------------------------------------------------------------- // cppcheck-suppress unusedFunction QVector VLayoutPiece::GetContourPoints() const @@ -853,6 +913,18 @@ void VLayoutPiece::SetPassmarks(const QVector &passmarks) } } +//--------------------------------------------------------------------------------------------------------------------- +QVector VLayoutPiece::GetPlaceLabels() const +{ + return Map(d->m_placeLabels); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiece::SetPlaceLabels(const QVector &labels) +{ + d->m_placeLabels = labels; +} + //--------------------------------------------------------------------------------------------------------------------- QVector > VLayoutPiece::InternalPathsForCut(bool cut) const { @@ -881,28 +953,6 @@ void VLayoutPiece::SetInternalPaths(const QVector &internalPat d->m_internalPaths = internalPaths; } -//--------------------------------------------------------------------------------------------------------------------- -template -QVector VLayoutPiece::Map(const QVector &points) const -{ - QVector p; - for (int i = 0; i < points.size(); ++i) - { - p.append(d->matrix.map(points.at(i))); - } - - if (d->mirror) - { - QList list = p.toList(); - for (int k=0, s=list.size(), max=(s/2); ksetPath(d->matrix.map(d->m_internalPaths.at(i).GetPainterPath())); - - QPen pen = item->pen(); - pen.setStyle(d->m_internalPaths.at(i).PenStyle()); - item->setPen(pen); -} - //--------------------------------------------------------------------------------------------------------------------- QPainterPath VLayoutPiece::LayoutAllowancePath() const { @@ -996,7 +1034,18 @@ QGraphicsItem *VLayoutPiece::GetItem(bool textAsPaths) const for (int i = 0; i < d->m_internalPaths.count(); ++i) { - CreateInternalPathItem(i, item); + QGraphicsPathItem* pathItem = new QGraphicsPathItem(item); + pathItem->setPath(d->matrix.map(d->m_internalPaths.at(i).GetPainterPath())); + + QPen pen = pathItem->pen(); + pen.setStyle(d->m_internalPaths.at(i).PenStyle()); + pathItem->setPen(pen); + } + + for (int i = 0; i < d->m_placeLabels.count(); ++i) + { + QGraphicsPathItem* pathItem = new QGraphicsPathItem(item); + pathItem->setPath(d->matrix.map(PlaceLabelImgPath(d->m_placeLabels.at(i).shape))); } CreateLabelStrings(item, d->detailLabel, d->m_tmDetail, textAsPaths); diff --git a/src/libs/vlayout/vlayoutpiece.h b/src/libs/vlayout/vlayoutpiece.h index 8e2c55665..bf88b905a 100644 --- a/src/libs/vlayout/vlayoutpiece.h +++ b/src/libs/vlayout/vlayoutpiece.h @@ -46,6 +46,7 @@ #include "../vpatterndb/floatItemData/vpiecelabeldata.h" #include "../vpatterndb/vcontainer.h" #include "vabstractpiece.h" +#include "../vgeometry/vgeometrydef.h" class VLayoutPieceData; class VLayoutPiecePath; @@ -85,6 +86,9 @@ public: QVector GetPassmarks() const; void SetPassmarks(const QVector &passmarks); + QVector GetPlaceLabels() const; + void SetPlaceLabels(const QVector &labels); + QVector> InternalPathsForCut(bool cut) const; QVector GetInternalPaths() const; void SetInternalPaths(const QVector &internalPaths); @@ -142,7 +146,6 @@ private: Q_REQUIRED_RESULT QGraphicsPathItem *GetMainItem() const; Q_REQUIRED_RESULT QGraphicsPathItem *GetMainPathItem() const; - void CreateInternalPathItem(int i, QGraphicsItem *parent) const; void CreateLabelStrings(QGraphicsItem *parent, const QVector &labelShape, const VTextManager &tm, bool textAsPaths) const; void CreateGrainlineItem(QGraphicsItem *parent) const; diff --git a/src/libs/vlayout/vlayoutpiece_p.h b/src/libs/vlayout/vlayoutpiece_p.h index 963cc54cb..1ebdaaec9 100644 --- a/src/libs/vlayout/vlayoutpiece_p.h +++ b/src/libs/vlayout/vlayoutpiece_p.h @@ -39,7 +39,7 @@ #include "../vpatterndb/floatItemData/vgrainlinedata.h" #include "../vmisc/diagnostic.h" #include "vlayoutpiecepath.h" - +#include "../vgeometry/vgeometrydef.h" #include "vtextmanager.h" QT_WARNING_PUSH @@ -62,7 +62,8 @@ public: patternInfo(), grainlinePoints(), m_tmDetail(), - m_tmPattern() + m_tmPattern(), + m_placeLabels() {} VLayoutPieceData(const VLayoutPieceData &detail) @@ -79,7 +80,8 @@ public: patternInfo(detail.patternInfo), grainlinePoints(detail.grainlinePoints), m_tmDetail(detail.m_tmDetail), - m_tmPattern(detail.m_tmPattern) + m_tmPattern(detail.m_tmPattern), + m_placeLabels(detail.m_placeLabels) {} ~VLayoutPieceData() {} @@ -122,6 +124,9 @@ public: /** @brief m_tmPattern text manager for laying out pattern info */ VTextManager m_tmPattern; + /** @brief m_placeLabels list of place labels. */ + QVector m_placeLabels; + private: VLayoutPieceData &operator=(const VLayoutPieceData &) Q_DECL_EQ_DELETE; }; diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 3e67e04f7..6ef4ff1d3 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -170,6 +170,7 @@ enum class Tool : ToolVisHolderType EllipticalArc, Pin, InsertNode, + PlaceLabel, LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used }; @@ -219,8 +220,9 @@ enum class Vis : ToolVisHolderType ToolEllipticalArc, ToolPiece, ToolPiecePath, - ToolPin, - PiecePins, + ToolSpecialPoint, + ToolPlaceLabel, + PieceSpecialPoints, NoBrush, CurvePathItem, GrainlineItem, @@ -478,7 +480,6 @@ struct CustomSARecord Q_DECLARE_METATYPE(CustomSARecord) Q_DECLARE_TYPEINFO(CustomSARecord, Q_MOVABLE_TYPE); - /**************************************************************************** ** This file is derived from code bearing the following notice: ** The sole author of this file, Adam Higerd, has explicitly disclaimed all diff --git a/src/libs/vmisc/share/resources/icon.qrc b/src/libs/vmisc/share/resources/icon.qrc index 0f67bcfa5..eb7a14625 100644 --- a/src/libs/vmisc/share/resources/icon.qrc +++ b/src/libs/vmisc/share/resources/icon.qrc @@ -75,5 +75,7 @@ icon/32x32/pins@2x.png icon/32x32/passmark.png icon/32x32/passmark@2x.png + icon/32x32/button.png + icon/32x32/button@2x.png diff --git a/src/libs/vmisc/share/resources/icon/32x32/button.png b/src/libs/vmisc/share/resources/icon/32x32/button.png new file mode 100644 index 000000000..b87cf7270 Binary files /dev/null and b/src/libs/vmisc/share/resources/icon/32x32/button.png differ diff --git a/src/libs/vmisc/share/resources/icon/32x32/button@2x.png b/src/libs/vmisc/share/resources/icon/32x32/button@2x.png new file mode 100644 index 000000000..1b7445699 Binary files /dev/null and b/src/libs/vmisc/share/resources/icon/32x32/button@2x.png differ diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index 48ffcb99e..5457a88d0 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -185,8 +185,15 @@ quint32 VContainer::AddGObject(VGObject *obj) { SCASSERT(obj != nullptr) QSharedPointer pointer(obj); + return AddGObject(pointer); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VContainer::AddGObject(const QSharedPointer &obj) +{ + SCASSERT(not obj.isNull()) uniqueNames.insert(obj->name()); - return AddObject(d->gObjects, pointer); + return AddObject(d->gObjects, obj); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index 1e6f1f345..0d6850d02 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -143,6 +143,7 @@ public: static void UpdateId(quint32 newId); quint32 AddGObject(VGObject *obj); + quint32 AddGObject(const QSharedPointer &obj); quint32 AddPiece(const VPiece &detail); quint32 AddPiecePath(const VPiecePath &path); void AddLine(const quint32 &firstPointId, const quint32 &secondPointId); diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index ad750b7a9..db76f5a6a 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -30,6 +30,7 @@ #include "vpiece_p.h" #include "../vgeometry/vpointf.h" #include "../vgeometry/vabstractcurve.h" +#include "../vgeometry/vplacelabelitem.h" #include "vcontainer.h" #include "../vmisc/vabstractapplication.h" @@ -440,6 +441,25 @@ QVector VPiece::PassmarksLines(const VContainer *data, const QVector VPiece::PlaceLabelPoints(const VContainer *data) const +{ + QVector points; + for(int i=0; i < d->m_placeLabels.size(); ++i) + { + try + { + const auto label = data->GeometricObject(d->m_placeLabels.at(i)); + points.append(label->LabelShape(data)); + } + catch (const VExceptionBadId &e) + { // ignore + Q_UNUSED(e) + } + } + return points; +} + //--------------------------------------------------------------------------------------------------------------------- QPainterPath VPiece::MainPathPath(const VContainer *data) const { @@ -513,6 +533,25 @@ QPainterPath VPiece::PassmarksPath(const VContainer *data, const QVector points = PlaceLabelPoints(data); + QPainterPath path; + + if (not points.isEmpty()) + { + for (qint32 i = 0; i < points.count(); ++i) + { + path.addPath(PlaceLabelImgPath(points.at(i))); + } + + path.setFillRule(Qt::WindingFill); + } + + return path; +} + //--------------------------------------------------------------------------------------------------------------------- bool VPiece::IsInLayout() const { @@ -605,6 +644,24 @@ void VPiece::SetPins(const QVector &pins) d->m_pins = pins; } +//--------------------------------------------------------------------------------------------------------------------- +QVector VPiece::GetPlaceLabels() const +{ + return d->m_placeLabels; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector &VPiece::GetPlaceLabels() +{ + return d->m_placeLabels; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPiece::SetPlaceLabels(const QVector &labels) +{ + d->m_placeLabels = labels; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief MissingNodes find missing nodes in detail. When we deleted object in detail and return this detail need @@ -647,6 +704,12 @@ QVector VPiece::MissingPins(const VPiece &det) const return PieceMissingNodes(d->m_pins, det.GetPins()); } +//--------------------------------------------------------------------------------------------------------------------- +QVector VPiece::MissingPlaceLabels(const VPiece &det) const +{ + return PieceMissingNodes(d->m_placeLabels, det.GetPlaceLabels()); +} + //--------------------------------------------------------------------------------------------------------------------- void VPiece::SetPatternPieceData(const VPieceLabelData &data) { diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 899a519a6..07b4f865a 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -33,6 +33,7 @@ #include #include "../vlayout/vabstractpiece.h" +#include "../vgeometry/vgeometrydef.h" class VPieceData; class VPieceNode; @@ -66,17 +67,19 @@ public: VPiecePath &GetPath(); void SetPath(const VPiecePath &path); - QVector MainPathPoints(const VContainer *data) const; - QVector MainPathNodePoints(const VContainer *data, bool showExcluded = false) const; - QVector SeamAllowancePoints(const VContainer *data) const; - QVector PassmarksLines(const VContainer *data, - const QVector &seamAllowance = QVector()) const; + QVector MainPathPoints(const VContainer *data) const; + QVector MainPathNodePoints(const VContainer *data, bool showExcluded = false) const; + QVector SeamAllowancePoints(const VContainer *data) const; + QVector PassmarksLines(const VContainer *data, + const QVector &seamAllowance = QVector()) const; + QVector PlaceLabelPoints(const VContainer *data) const; QPainterPath MainPathPath(const VContainer *data) const; QPainterPath SeamAllowancePath(const VContainer *data) const; QPainterPath SeamAllowancePath(const QVector &points) const; QPainterPath PassmarksPath(const VContainer *data, const QVector &seamAllowance = QVector()) const; + QPainterPath PlaceLabelPath(const VContainer *data) const; bool IsInLayout() const; void SetInLayout(bool inLayout); @@ -99,10 +102,15 @@ public: QVector &GetPins(); void SetPins(const QVector &pins); + QVector GetPlaceLabels() const; + QVector &GetPlaceLabels(); + void SetPlaceLabels(const QVector &labels); + QVector MissingNodes(const VPiece &det) const; QVector MissingCSAPath(const VPiece &det) const; QVector MissingInternalPaths(const VPiece &det) const; QVector MissingPins(const VPiece &det) const; + QVector MissingPlaceLabels(const VPiece &det) const; void SetPatternPieceData(const VPieceLabelData &data); VPieceLabelData& GetPatternPieceData(); @@ -146,6 +154,17 @@ private: const VContainer *data, int passmarkIndex) const; static int IsCSAStart(const QVector &records, quint32 id); + + PlaceLabelImg LabelShape(const VContainer *data) const; + PlaceLabelImg SegmentShape(const VContainer *data) const; + PlaceLabelImg RectangleShape(const VContainer *data) const; + PlaceLabelImg CrossShape(const VContainer *data) const; + PlaceLabelImg TshapedShape(const VContainer *data) const; + PlaceLabelImg DoubletreeShape(const VContainer *data) const; + PlaceLabelImg CornerShape(const VContainer *data) const; + PlaceLabelImg TriangleShape(const VContainer *data) const; + PlaceLabelImg HshapedShape(const VContainer *data) const; + PlaceLabelImg ButtonShape(const VContainer *data) const; }; Q_DECLARE_TYPEINFO(VPiece, Q_MOVABLE_TYPE); diff --git a/src/libs/vpatterndb/vpiece_p.h b/src/libs/vpatterndb/vpiece_p.h index 63a3bf018..a3bf101b6 100644 --- a/src/libs/vpatterndb/vpiece_p.h +++ b/src/libs/vpatterndb/vpiece_p.h @@ -54,6 +54,7 @@ public: m_customSARecords(), m_internalPaths(), m_pins(), + m_placeLabels(), m_ppData(), m_piPatternInfo(), m_glGrainline(), @@ -68,6 +69,7 @@ public: m_customSARecords(detail.m_customSARecords), m_internalPaths(detail.m_internalPaths), m_pins(detail.m_pins), + m_placeLabels(detail.m_placeLabels), m_ppData(detail.m_ppData), m_piPatternInfo(detail.m_piPatternInfo), m_glGrainline(detail.m_glGrainline), @@ -85,6 +87,7 @@ public: QVector m_customSARecords; QVector m_internalPaths; QVector m_pins; + QVector m_placeLabels; /** @brief Pattern piece data */ VPieceLabelData m_ppData; diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index 5d2fad588..f72bb27df 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -46,7 +46,8 @@ HEADERS += \ $$PWD/tools/piece/dialogpiecepath.h \ $$PWD/tools/dialogpin.h \ $$PWD/tools/dialoginsertnode.h \ - $$PWD/support/dialogeditlabel.h + $$PWD/support/dialogeditlabel.h \ + $$PWD/tools/dialogplacelabel.h SOURCES += \ $$PWD/tools/dialogalongline.cpp \ @@ -92,7 +93,8 @@ SOURCES += \ $$PWD/tools/piece/dialogpiecepath.cpp \ $$PWD/tools/dialogpin.cpp \ $$PWD/tools/dialoginsertnode.cpp \ - $$PWD/support/dialogeditlabel.cpp + $$PWD/support/dialogeditlabel.cpp \ + $$PWD/tools/dialogplacelabel.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ @@ -142,4 +144,6 @@ FORMS += \ $$PWD/tools/piece/tabs/tabpins.ui \ $$PWD/tools/dialoginsertnode.ui \ $$PWD/tools/piece/tabs/tabpassmarks.ui \ - $$PWD/support/dialogeditlabel.ui + $$PWD/support/dialogeditlabel.ui \ + $$PWD/tools/dialogplacelabel.ui \ + $$PWD/tools/piece/tabs/tabplacelabels.ui diff --git a/src/libs/vtools/dialogs/tooldialogs.h b/src/libs/vtools/dialogs/tooldialogs.h index d3794bd3a..4510ba950 100644 --- a/src/libs/vtools/dialogs/tooldialogs.h +++ b/src/libs/vtools/dialogs/tooldialogs.h @@ -69,6 +69,7 @@ #include "tools/piece/dialogpiecepath.h" #include "tools/dialogpin.h" #include "tools/dialoginsertnode.h" +#include "tools/dialogplacelabel.h" #include "support/dialogeditwrongformula.h" #include "support/dialogundo.h" diff --git a/src/libs/vtools/dialogs/tools/dialogpin.cpp b/src/libs/vtools/dialogs/tools/dialogpin.cpp index 8183d210b..e789ce607 100644 --- a/src/libs/vtools/dialogs/tools/dialogpin.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpin.cpp @@ -28,9 +28,8 @@ #include "dialogpin.h" #include "ui_dialogpin.h" -#include "visualization/line/vistoolpin.h" +#include "visualization/line/vistoolspecialpoint.h" #include "../../tools/vabstracttool.h" -#include "../../tools/vtoolseamallowance.h" //--------------------------------------------------------------------------------------------------------------------- DialogPin::DialogPin(const VContainer *data, quint32 toolId, QWidget *parent) @@ -52,7 +51,7 @@ DialogPin::DialogPin(const VContainer *data, quint32 toolId, QWidget *parent) CheckPieces(); }); - vis = new VisToolPin(data); + vis = new VisToolSpecialPoint(data); } //--------------------------------------------------------------------------------------------------------------------- @@ -106,7 +105,7 @@ void DialogPin::SetPointId(quint32 id) { setCurrentPointId(ui->comboBoxPoint, id); - VisToolPin *point = qobject_cast(vis); + VisToolSpecialPoint *point = qobject_cast(vis); SCASSERT(point != nullptr) point->setObject1Id(id); @@ -148,16 +147,7 @@ void DialogPin::CheckState() //--------------------------------------------------------------------------------------------------------------------- void DialogPin::ShowVisualization() { - AddVisualization(); - - if (m_showMode) - { - VToolSeamAllowance *tool = qobject_cast(VAbstractPattern::getTool(GetPieceId())); - SCASSERT(tool != nullptr); - auto visPoint = qobject_cast(vis); - SCASSERT(visPoint != nullptr); - visPoint->setParentItem(tool); - } + AddVisualization(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogplacelabel.cpp b/src/libs/vtools/dialogs/tools/dialogplacelabel.cpp new file mode 100644 index 000000000..faf2bdcde --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogplacelabel.cpp @@ -0,0 +1,469 @@ +/************************************************************************ + ** + ** @file dialogplacelabel.cpp + ** @author Roman Telezhynskyi + ** @date 14 10, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 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 "dialogplacelabel.h" +#include "ui_dialogplacelabel.h" + +#include "visualization/line/vistoolspecialpoint.h" +#include "../../tools/vabstracttool.h" +#include "../../tools/vtoolseamallowance.h" +#include "../support/dialogeditwrongformula.h" +#include "../vgeometry/vplacelabelitem.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +DialogPlaceLabel::DialogPlaceLabel(const VContainer *data, quint32 toolId, QWidget *parent) + : DialogTool(data, toolId, parent), + ui(new Ui::DialogPlaceLabel), + m_showMode(false), + m_flagPoint(false), + m_flagWidth(false), + m_flagHeight(false), + m_flagAngle(false), + m_formulaBaseHeightWidth(0), + m_formulaBaseHeightHeight(0), + m_formulaBaseHeightAngle(0), + timerAngle(new QTimer(this)), + timerWidth(new QTimer(this)), + timerHeight(new QTimer(this)) +{ + ui->setupUi(this); + InitOkCancel(ui); + + FillComboBoxPoints(ui->comboBoxPoint); + FillPlaceLabelTypes(); + + m_formulaBaseHeightWidth = ui->plainTextEditFormulaWidth->height(); + m_formulaBaseHeightHeight = ui->plainTextEditFormulaHeight->height(); + m_formulaBaseHeightAngle = ui->plainTextEditFormulaAngle->height(); + + ui->plainTextEditFormulaWidth->installEventFilter(this); + ui->plainTextEditFormulaHeight->installEventFilter(this); + ui->plainTextEditFormulaAngle->installEventFilter(this); + + ui->plainTextEditFormulaWidth->setPlainText(QString::number(UnitConvertor(1, Unit::Cm, qApp->patternUnit()))); + ui->plainTextEditFormulaHeight->setPlainText(QString::number(UnitConvertor(1, Unit::Cm, qApp->patternUnit()))); + + flagError = false; + CheckState(); + + connect(ui->toolButtonExprWidth, &QPushButton::clicked, this, &DialogPlaceLabel::FXWidth); + connect(ui->toolButtonExprHeight, &QPushButton::clicked, this, &DialogPlaceLabel::FXHeight); + connect(ui->toolButtonExprAngle, &QPushButton::clicked, this, &DialogPlaceLabel::FXAngle); + + connect(ui->plainTextEditFormulaWidth, &QPlainTextEdit::textChanged, this, &DialogPlaceLabel::FormulaWidthChanged); + connect(ui->plainTextEditFormulaHeight, &QPlainTextEdit::textChanged, this, + &DialogPlaceLabel::FormulaHeightChanged); + connect(ui->plainTextEditFormulaAngle, &QPlainTextEdit::textChanged, this, &DialogPlaceLabel::FormulaAngleChanged); + + connect(ui->pushButtonGrowWidth, &QPushButton::clicked, this, &DialogPlaceLabel::DeployFormulaWidthEdit); + connect(ui->pushButtonGrowHeight, &QPushButton::clicked, this, &DialogPlaceLabel::DeployFormulaHeightEdit); + connect(ui->pushButtonGrowAngle, &QPushButton::clicked, this, &DialogPlaceLabel::DeployFormulaAngleEdit); + + connect(timerWidth, &QTimer::timeout, this, &DialogPlaceLabel::EvalWidth); + connect(timerHeight, &QTimer::timeout, this, &DialogPlaceLabel::EvalHeight); + connect(timerAngle, &QTimer::timeout, this, &DialogPlaceLabel::EvalAngle); + + connect(ui->comboBoxPiece, static_cast(&QComboBox::currentIndexChanged), this, [this]() + { + CheckPieces(); + }); + + vis = new VisToolSpecialPoint(data); + + FormulaWidthChanged(); + FormulaHeightChanged(); + FormulaAngleChanged(); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogPlaceLabel::~DialogPlaceLabel() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::EnbleShowMode(bool disable) +{ + m_showMode = disable; + ui->comboBoxPiece->setDisabled(m_showMode); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogPlaceLabel::GetCenterPoint() const +{ + return getCurrentObjectId(ui->comboBoxPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::SetCenterPoint(quint32 id) +{ + setCurrentPointId(ui->comboBoxPoint, id); + + if (not m_showMode) + { + VisToolSpecialPoint *point = qobject_cast(vis); + SCASSERT(point != nullptr) + point->setObject1Id(id); + } + + CheckPoint(); +} + +//--------------------------------------------------------------------------------------------------------------------- +PlaceLabelType DialogPlaceLabel::GetLabelType() const +{ + return static_cast(ui->comboBoxLabelType->currentData().toInt()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::SetLabelType(PlaceLabelType type) +{ + const qint32 index = ui->comboBoxLabelType->findData(static_cast(type)); + if (index != -1) + { + ui->comboBoxLabelType->setCurrentIndex(index); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogPlaceLabel::GetWidth() const +{ + return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormulaWidth->toPlainText().replace("\n", " "), + qApp->Settings()->GetOsSeparator()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::SetWidth(const QString &value) +{ + const QString formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); + // increase height if needed. TODO : see if I can get the max number of caracters in one line + // of this PlainTextEdit to change 80 to this value + if (formula.length() > 80) + { + this->DeployFormulaWidthEdit(); + } + ui->plainTextEditFormulaWidth->setPlainText(formula); + +// VisToolPlaceLabel *point = qobject_cast(vis); +// SCASSERT(point != nullptr) +// point->setObject1Id(id); + + MoveCursorToEnd(ui->plainTextEditFormulaWidth); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogPlaceLabel::GetHeight() const +{ + return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormulaHeight->toPlainText().replace("\n", " "), + qApp->Settings()->GetOsSeparator()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::SetHeight(const QString &value) +{ + const QString formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); + // increase height if needed. TODO : see if I can get the max number of caracters in one line + // of this PlainTextEdit to change 80 to this value + if (formula.length() > 80) + { + this->DeployFormulaHeightEdit(); + } + ui->plainTextEditFormulaHeight->setPlainText(formula); + +// VisToolPlaceLabel *point = qobject_cast(vis); +// SCASSERT(point != nullptr) +// point->setObject1Id(id); + + MoveCursorToEnd(ui->plainTextEditFormulaHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogPlaceLabel::GetAngle() const +{ + return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormulaAngle->toPlainText().replace("\n", " "), + qApp->Settings()->GetOsSeparator()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::SetAngle(const QString &value) +{ + const QString formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); + // increase height if needed. TODO : see if I can get the max number of caracters in one line + // of this PlainTextEdit to change 80 to this value + if (formula.length() > 80) + { + this->DeployFormulaAngleEdit(); + } + ui->plainTextEditFormulaAngle->setPlainText(formula); + +// VisToolPlaceLabel *point = qobject_cast(vis); +// SCASSERT(point != nullptr) +// point->setObject1Id(id); + + MoveCursorToEnd(ui->plainTextEditFormulaAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogPlaceLabel::GetPieceId() const +{ + return getCurrentObjectId(ui->comboBoxPiece); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::SetPieceId(quint32 id) +{ + if (ui->comboBoxPiece->count() <= 0) + { + ui->comboBoxPiece->addItem(data->GetPiece(id).GetName(), id); + } + else + { + const qint32 index = ui->comboBoxPiece->findData(id); + if (index != -1) + { + ui->comboBoxPiece->setCurrentIndex(index); + } + else + { + ui->comboBoxPiece->setCurrentIndex(0); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::SetPiecesList(const QVector &list) +{ + FillComboBoxPiecesList(ui->comboBoxPiece, list); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::ChosenObject(quint32 id, const SceneObject &type) +{ + if (not prepare) + { + if (type == SceneObject::Point) + { + if (SetObject(id, ui->comboBoxPoint, "")) + { + vis->VisualMode(id); + CheckPoint(); + prepare = true; + this->setModal(true); + this->show(); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::CheckState() +{ + SCASSERT(bOk != nullptr); + bOk->setEnabled(m_flagPoint && flagError && m_flagWidth && m_flagHeight && m_flagAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::ShowVisualization() +{ + if (not m_showMode) + { + AddVisualization(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::closeEvent(QCloseEvent *event) +{ + ui->plainTextEditFormulaWidth->blockSignals(true); + ui->plainTextEditFormulaHeight->blockSignals(true); + ui->plainTextEditFormulaAngle->blockSignals(true); + DialogTool::closeEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::DeployFormulaWidthEdit() +{ + DeployFormula(ui->plainTextEditFormulaWidth, ui->pushButtonGrowWidth, m_formulaBaseHeightWidth); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::DeployFormulaHeightEdit() +{ + DeployFormula(ui->plainTextEditFormulaHeight, ui->pushButtonGrowHeight, m_formulaBaseHeightHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::DeployFormulaAngleEdit() +{ + DeployFormula(ui->plainTextEditFormulaAngle, ui->pushButtonGrowAngle, m_formulaBaseHeightAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::FormulaWidthChanged() +{ + labelEditFormula = ui->labelEditFormulaWidth; + labelResultCalculation = ui->labelResultCalculationWidth; + const QString postfix = UnitsToStr(qApp->patternUnit(), true); + ValFormulaChanged(m_flagWidth, ui->plainTextEditFormulaWidth, timerWidth, postfix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::FormulaHeightChanged() +{ + labelEditFormula = ui->labelEditFormulaHeight; + labelResultCalculation = ui->labelResultCalculationHeight; + const QString postfix = UnitsToStr(qApp->patternUnit(), true); + ValFormulaChanged(m_flagHeight, ui->plainTextEditFormulaHeight, timerHeight, postfix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::FormulaAngleChanged() +{ + labelEditFormula = ui->labelEditFormulaAngle; + labelResultCalculation = ui->labelResultCalculationAngle; + ValFormulaChanged(m_flagAngle, ui->plainTextEditFormulaAngle, timerAngle, degreeSymbol); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::EvalWidth() +{ + labelEditFormula = ui->labelEditFormulaWidth; + const QString postfix = UnitsToStr(qApp->patternUnit(), true); + Eval(ui->plainTextEditFormulaWidth->toPlainText(), m_flagWidth, ui->labelResultCalculationWidth, postfix, true, + true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::EvalHeight() +{ + labelEditFormula = ui->labelEditFormulaHeight; + const QString postfix = UnitsToStr(qApp->patternUnit(), true); + Eval(ui->plainTextEditFormulaHeight->toPlainText(), m_flagHeight, ui->labelResultCalculationHeight, postfix, true, + true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::EvalAngle() +{ + labelEditFormula = ui->labelEditFormulaAngle; + Eval(ui->plainTextEditFormulaAngle->toPlainText(), m_flagAngle, ui->labelResultCalculationAngle, degreeSymbol, + false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::FXWidth() +{ + QScopedPointer dialog(new DialogEditWrongFormula(data, toolId, this)); + dialog->setWindowTitle(tr("Edit rectangle width")); + dialog->SetFormula(GetWidth()); + dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + if (dialog->exec() == QDialog::Accepted) + { + SetWidth(dialog->GetFormula()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::FXHeight() +{ + QScopedPointer dialog(new DialogEditWrongFormula(data, toolId, this)); + dialog->setWindowTitle(tr("Edit rectangle width")); + dialog->SetFormula(GetHeight()); + dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + if (dialog->exec() == QDialog::Accepted) + { + SetHeight(dialog->GetFormula()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::FXAngle() +{ + QScopedPointer dialog(new DialogEditWrongFormula(data, toolId, this)); + dialog->setWindowTitle(tr("Edit angle")); + dialog->SetFormula(GetAngle()); + dialog->setPostfix(degreeSymbol); + if (dialog->exec() == QDialog::Accepted) + { + SetAngle(dialog->GetFormula()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::FillPlaceLabelTypes() +{ + ui->comboBoxLabelType->addItem(tr("Segment"), static_cast(PlaceLabelType::Segment)); + ui->comboBoxLabelType->addItem(tr("Rectangle"), static_cast(PlaceLabelType::Rectangle)); + ui->comboBoxLabelType->addItem(tr("Cross"), static_cast(PlaceLabelType::Cross)); + ui->comboBoxLabelType->addItem(tr("T-shaped"), static_cast(PlaceLabelType::Tshaped)); + ui->comboBoxLabelType->addItem(tr("Doubletree"), static_cast(PlaceLabelType::Doubletree)); + ui->comboBoxLabelType->addItem(tr("Corner"), static_cast(PlaceLabelType::Corner)); + ui->comboBoxLabelType->addItem(tr("Triangle"), static_cast(PlaceLabelType::Triangle)); + ui->comboBoxLabelType->addItem(tr("H-shaped"), static_cast(PlaceLabelType::Hshaped)); + ui->comboBoxLabelType->addItem(tr("Button"), static_cast(PlaceLabelType::Button)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::CheckPieces() +{ + if (not m_showMode) + { + QColor color = okColor; + if (ui->comboBoxPiece->count() <= 0 || ui->comboBoxPiece->currentIndex() == -1) + { + flagError = false; + color = errorColor; + } + else + { + flagError = true; + color = okColor; + } + ChangeColor(ui->labelPiece, color); + CheckState(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::CheckPoint() +{ + QColor color = okColor; + if (ui->comboBoxPoint->currentIndex() != -1) + { + m_flagPoint = true; + color = okColor; + } + else + { + m_flagPoint = false; + color = errorColor; + } + ChangeColor(ui->labelPoint, color); + CheckState(); +} diff --git a/src/libs/vtools/dialogs/tools/dialogplacelabel.h b/src/libs/vtools/dialogs/tools/dialogplacelabel.h new file mode 100644 index 000000000..92e27971c --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogplacelabel.h @@ -0,0 +1,119 @@ +/************************************************************************ + ** + ** @file dialogplacelabel.h + ** @author Roman Telezhynskyi + ** @date 14 10, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 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 DIALOGPLACELABEL_H +#define DIALOGPLACELABEL_H + +#include "dialogtool.h" + +namespace Ui +{ + class DialogPlaceLabel; +} + +class VPlaceLabelItem; + +class DialogPlaceLabel : public DialogTool +{ + Q_OBJECT + +public: + explicit DialogPlaceLabel(const VContainer *data, quint32 toolId, QWidget *parent = nullptr); + virtual ~DialogPlaceLabel(); + + void EnbleShowMode(bool disable); + + quint32 GetCenterPoint() const; + void SetCenterPoint(quint32 id); + + PlaceLabelType GetLabelType() const; + void SetLabelType(PlaceLabelType type); + + QString GetWidth() const; + void SetWidth(const QString &value); + + QString GetHeight() const; + void SetHeight(const QString &value); + + QString GetAngle() const; + void SetAngle(const QString &value); + + quint32 GetPieceId() const; + void SetPieceId(quint32 id); + + virtual void SetPiecesList(const QVector &list) Q_DECL_OVERRIDE; + +public slots: + virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; + +protected: + virtual void CheckState() Q_DECL_FINAL; + virtual void ShowVisualization() Q_DECL_OVERRIDE; + virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; + +private slots: + void DeployFormulaWidthEdit(); + void DeployFormulaHeightEdit(); + void DeployFormulaAngleEdit(); + + void FormulaWidthChanged(); + void FormulaHeightChanged(); + void FormulaAngleChanged(); + + void EvalWidth(); + void EvalHeight(); + void EvalAngle(); + + void FXWidth(); + void FXHeight(); + void FXAngle(); + +private: + Q_DISABLE_COPY(DialogPlaceLabel) + Ui::DialogPlaceLabel *ui; + bool m_showMode; + bool m_flagPoint; + bool m_flagWidth; + bool m_flagHeight; + bool m_flagAngle; + + /** @brief formulaBaseHeight base height defined by dialogui */ + int m_formulaBaseHeightWidth; + int m_formulaBaseHeightHeight; + int m_formulaBaseHeightAngle; + + QTimer *timerAngle; + QTimer *timerWidth; + QTimer *timerHeight; + + void FillPlaceLabelTypes(); + + void CheckPieces(); + void CheckPoint(); +}; + +#endif // DIALOGPLACELABEL_H diff --git a/src/libs/vtools/dialogs/tools/dialogplacelabel.ui b/src/libs/vtools/dialogs/tools/dialogplacelabel.ui new file mode 100644 index 000000000..fb7bff15c --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogplacelabel.ui @@ -0,0 +1,655 @@ + + + DialogPlaceLabel + + + + 0 + 0 + 338 + 363 + + + + Dialog + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Width: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Height: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Angle: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + 0 + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Point: + + + + + + + + + + Piece: + + + + + + + + + + Type: + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogPlaceLabel + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogPlaceLabel + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index ffae7cb6d..513e6709f 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -111,7 +111,7 @@ DialogTool::DialogTool(const VContainer *data, const quint32 &toolId, QWidget *p flagName(true), flagFormula(true), flagError(true), - timerFormula(nullptr), + timerFormula(new QTimer(this)), bOk(nullptr), bApply(nullptr), spinBoxAngle(nullptr), @@ -129,7 +129,6 @@ DialogTool::DialogTool(const VContainer *data, const quint32 &toolId, QWidget *p vis(nullptr) { SCASSERT(data != nullptr) - timerFormula = new QTimer(this); connect(timerFormula, &QTimer::timeout, this, &DialogTool::EvalFormula); } diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index 4e94a34d6..a1f830b2b 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -33,23 +33,27 @@ #include "ui_tabgrainline.h" #include "ui_tabpins.h" #include "ui_tabpassmarks.h" +#include "ui_tabplacelabels.h" #include "../vwidgets/fancytabbar/fancytabbar.h" #include "../vpatterndb/vpiecenode.h" #include "../vpatterndb/vpiecepath.h" #include "../vpatterndb/calculator.h" #include "visualization/path/vistoolpiece.h" -#include "visualization/path/vispiecepins.h" +#include "visualization/path/vispiecespecialpoints.h" #include "dialogpiecepath.h" +#include "../dialogplacelabel.h" #include "../../../undocommands/savepiecepathoptions.h" +#include "../../../undocommands/saveplacelabeloptions.h" #include "../../support/dialogeditwrongformula.h" #include "../../support/dialogeditlabel.h" #include "../../../tools/vtoolseamallowance.h" +#include "../vgeometry/vplacelabelitem.h" #include #include #include -enum TabOrder {Paths=0, Pins=1, Labels=2, Grainline=3, Passmarks=4, Count=5}; +enum TabOrder {Paths=0, Pins=1, Labels=2, Grainline=3, Passmarks=4, PlaceLabels=5, Count=6}; namespace { @@ -84,11 +88,13 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & uiTabGrainline(new Ui::TabGrainline), uiTabPins(new Ui::TabPins), uiTabPassmarks(new Ui::TabPassmarks), + uiTabPlaceLabels(new Ui::TabPlaceLabels), m_tabPaths(new QWidget), m_tabLabels(new QWidget), m_tabGrainline(new QWidget), m_tabPins(new QWidget), m_tabPassmarks(new QWidget), + m_tabPlaceLabels(new QWidget), m_ftb(new FancyTabBar(FancyTabBar::Left, this)), applyAllowed(false),// By default disabled flagGPin(true), @@ -103,7 +109,7 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & m_mx(0), m_my(0), m_dialog(), - m_visPins(), + m_visSpecialPoints(), m_oldData(), m_oldGeom(), m_oldGrainline(), @@ -138,6 +144,7 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & InitGrainlineTab(); InitPinsTab(); InitPassmarksTab(); + InitPlaceLabelsTab(); flagName = true;//We have default name of piece. ChangeColor(uiTabLabels->labelEditName, okColor); @@ -155,7 +162,8 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & //--------------------------------------------------------------------------------------------------------------------- DialogSeamAllowance::~DialogSeamAllowance() { - delete m_visPins; + delete m_visSpecialPoints; + delete m_tabPlaceLabels; delete m_tabPassmarks; delete m_tabPins; delete m_tabGrainline; @@ -182,6 +190,7 @@ void DialogSeamAllowance::EnableApply(bool enable) m_ftb->SetTabEnabled(TabOrder::Labels, applyAllowed); m_ftb->SetTabEnabled(TabOrder::Grainline, applyAllowed); m_ftb->SetTabEnabled(TabOrder::Passmarks, applyAllowed); + m_ftb->SetTabEnabled(TabOrder::PlaceLabels, applyAllowed); } //--------------------------------------------------------------------------------------------------------------------- @@ -204,24 +213,71 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) uiTabPaths->listWidgetCustomSA->clear(); for (int i = 0; i < piece.GetCustomSARecords().size(); ++i) { - NewCustomSA(piece.GetCustomSARecords().at(i)); + const CustomSARecord &record = piece.GetCustomSARecords().at(i); + if (record.path > NULL_ID) + { + const QString name = GetPathName(record.path, record.reverse); + + QListWidgetItem *item = new QListWidgetItem(name); + item->setFont(QFont("Times", 12, QFont::Bold)); + item->setData(Qt::UserRole, QVariant::fromValue(record)); + uiTabPaths->listWidgetCustomSA->addItem(item); + uiTabPaths->listWidgetCustomSA->setCurrentRow(uiTabPaths->listWidgetCustomSA->count()-1); + } } uiTabPaths->listWidgetCustomSA->blockSignals(false); uiTabPaths->listWidgetInternalPaths->clear(); for (int i = 0; i < piece.GetInternalPaths().size(); ++i) { - NewInternalPath(piece.GetInternalPaths().at(i)); + const quint32 path = piece.GetInternalPaths().at(i); + if (path > NULL_ID) + { + const QString name = GetPathName(path); + + QListWidgetItem *item = new QListWidgetItem(name); + item->setFont(QFont("Times", 12, QFont::Bold)); + item->setData(Qt::UserRole, QVariant::fromValue(path)); + uiTabPaths->listWidgetInternalPaths->addItem(item); + uiTabPaths->listWidgetInternalPaths->setCurrentRow(uiTabPaths->listWidgetInternalPaths->count()-1); + } } + auto NewSpecialPoint = [this](QListWidget *listWidget, quint32 point) + { + if (point > NULL_ID) + { + try + { + const QSharedPointer p = data->GetGObject(point); + + QListWidgetItem *item = new QListWidgetItem(p->name()); + item->setFont(QFont("Times", 12, QFont::Bold)); + item->setData(Qt::UserRole, QVariant::fromValue(point)); + listWidget->addItem(item); + listWidget->setCurrentRow(uiTabPins->listWidgetPins->count()-1); + } + catch (const VExceptionBadId &e) + { + qWarning() << qUtf8Printable(e.ErrorMessage()); + } + } + }; + uiTabPins->listWidgetPins->clear(); for (int i = 0; i < piece.GetPins().size(); ++i) { - NewPin(piece.GetPins().at(i)); + NewSpecialPoint(uiTabPins->listWidgetPins, piece.GetPins().at(i)); } InitAllPinComboboxes(); + uiTabPlaceLabels->listWidgetPlaceLabels->clear(); + for (int i = 0; i < piece.GetPlaceLabels().size(); ++i) + { + NewSpecialPoint(uiTabPlaceLabels->listWidgetPlaceLabels, piece.GetPlaceLabels().at(i)); + } + uiTabPaths->comboBoxStartPoint->blockSignals(true); uiTabPaths->comboBoxStartPoint->clear(); uiTabPaths->comboBoxStartPoint->blockSignals(false); @@ -656,6 +712,116 @@ void DialogSeamAllowance::ShowPinsContextMenu(const QPoint &pos) } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::ShowPlaceLabelsContextMenu(const QPoint &pos) +{ + const int row = uiTabPlaceLabels->listWidgetPlaceLabels->currentRow(); + if (uiTabPlaceLabels->listWidgetPlaceLabels->count() == 0 + || row == -1 + || row >= uiTabPlaceLabels->listWidgetPlaceLabels->count()) + { + return; + } + + QListWidgetItem *rowItem = uiTabPlaceLabels->listWidgetPlaceLabels->item(row); + SCASSERT(rowItem != nullptr); + const quint32 labelId = qvariant_cast(rowItem->data(Qt::UserRole)); + const auto label = data->GeometricObject(labelId); + + QScopedPointer menu(new QMenu()); + + auto InitAction = [&menu, label](const QString &text, PlaceLabelType type) + { + QAction *action = menu->addAction(text); + action->setCheckable(true); + action->setChecked(label->GetLabelType() == type); + return action; + }; + + auto SaveType = [this, label, labelId](PlaceLabelType type) + { + VPlaceLabelItem newLabel = VPlaceLabelItem(*label); + newLabel.SetLabelType(type); + + SavePlaceLabelOptions *saveCommand = new SavePlaceLabelOptions(*label, newLabel, qApp->getCurrentDocument(), + const_cast(data), labelId); + qApp->getUndoStack()->push(saveCommand); + UpdateCurrentPlaceLabelRecords(); + }; + + QAction *actionOption = menu->addAction(QIcon::fromTheme("preferences-other"), tr("Options")); + menu->addSeparator(); + QAction *actionSegment = InitAction(tr("Segment"), PlaceLabelType::Segment); + QAction *actionRectangle = InitAction(tr("Rectangle"), PlaceLabelType::Rectangle); + QAction *actionCross = InitAction(tr("Cross"), PlaceLabelType::Cross); + QAction *actionTshaped = InitAction(tr("T-shaped"), PlaceLabelType::Tshaped); + QAction *actionDoubletree = InitAction(tr("Doubletree"), PlaceLabelType::Doubletree); + QAction *actionCorner = InitAction(tr("Corner"), PlaceLabelType::Corner); + QAction *actionTriangle = InitAction(tr("Triangle"), PlaceLabelType::Triangle); + QAction *actionHshaped = InitAction(tr("H-shaped"), PlaceLabelType::Hshaped); + QAction *actionButton = InitAction(tr("Button"), PlaceLabelType::Button); + menu->addSeparator(); + QAction *actionDelete = menu->addAction(QIcon::fromTheme("edit-delete"), tr("Delete")); + + QAction *selectedAction = menu->exec(uiTabPlaceLabels->listWidgetPlaceLabels->viewport()->mapToGlobal(pos)); + if (selectedAction == actionDelete) + { + delete uiTabPlaceLabels->listWidgetPlaceLabels->item(row); + FancyTabChanged(m_ftb->CurrentIndex()); + } + else if (selectedAction == actionOption) + { + auto *dialog = new DialogPlaceLabel(data, labelId, this); + dialog->SetCenterPoint(label->GetCenterPoint()); + dialog->SetLabelType(label->GetLabelType()); + dialog->SetWidth(label->GetWidthFormula()); + dialog->SetHeight(label->GetHeightFormula()); + dialog->SetAngle(label->GetAngleFormula()); + dialog->SetPieceId(toolId); + dialog->EnbleShowMode(true); + m_dialog = dialog; + m_dialog->setModal(true); + connect(m_dialog.data(), &DialogTool::DialogClosed, this, &DialogSeamAllowance::PlaceLabelDialogClosed); + m_dialog->show(); + } + else if (selectedAction == actionSegment) + { + SaveType(PlaceLabelType::Segment); + } + else if (selectedAction == actionRectangle) + { + SaveType(PlaceLabelType::Rectangle); + } + else if (selectedAction == actionCross) + { + SaveType(PlaceLabelType::Cross); + } + else if (selectedAction == actionTshaped) + { + SaveType(PlaceLabelType::Tshaped); + } + else if (selectedAction == actionDoubletree) + { + SaveType(PlaceLabelType::Doubletree); + } + else if (selectedAction == actionCorner) + { + SaveType(PlaceLabelType::Corner); + } + else if (selectedAction == actionTriangle) + { + SaveType(PlaceLabelType::Triangle); + } + else if (selectedAction == actionHshaped) + { + SaveType(PlaceLabelType::Hshaped); + } + else if (selectedAction == actionButton) + { + SaveType(PlaceLabelType::Button); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::ListChanged() { @@ -1028,6 +1194,55 @@ void DialogSeamAllowance::PathDialogClosed(int result) delete m_dialog; } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::PlaceLabelDialogClosed(int result) +{ + if (result == QDialog::Accepted) + { + SCASSERT(not m_dialog.isNull()); + DialogPlaceLabel *dialogTool = qobject_cast(m_dialog.data()); + SCASSERT(dialogTool != nullptr); + try + { + auto oldLabel = data->GeometricObject(dialogTool->GetToolId()); + + auto point = data->GeometricObject(dialogTool->GetCenterPoint()); + + const QHash > *vars = data->DataVariables(); + + const qreal w = qAbs(Visualization::FindLength(dialogTool->GetWidth(), vars)); + const qreal h = qAbs(Visualization::FindLength(dialogTool->GetHeight(), vars)); + const qreal a = Visualization::FindVal(dialogTool->GetAngle(), vars); + + VPlaceLabelItem newLabel = VPlaceLabelItem(); + newLabel.setName(point->name()); + newLabel.setX(point->x()); + newLabel.setY(point->y()); + newLabel.setMx(point->mx()); + newLabel.setMy(point->my()); + newLabel.SetWidth(w, dialogTool->GetWidth()); + newLabel.SetHeight(h, dialogTool->GetHeight()); + newLabel.SetAngle(a, dialogTool->GetAngle()); + newLabel.SetLabelType(dialogTool->GetLabelType()); + newLabel.SetCenterPoint(dialogTool->GetCenterPoint()); + newLabel.SetCorrectionAngle(oldLabel->GetCorrectionAngle()); + + SavePlaceLabelOptions *saveCommand = new SavePlaceLabelOptions(*oldLabel, newLabel, + qApp->getCurrentDocument(), + const_cast(data), + dialogTool->GetToolId()); + qApp->getUndoStack()->push(saveCommand); + UpdateCurrentPlaceLabelRecords(); + } + catch (const VExceptionBadId &e) + { + qCritical("%s\n\n%s\n\n%s", qUtf8Printable(tr("Error. Can't save piece path.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + } + } + delete m_dialog; +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::FancyTabChanged(int index) { @@ -1041,6 +1256,7 @@ void DialogSeamAllowance::FancyTabChanged(int index) m_tabGrainline->hide(); m_tabPins->hide(); m_tabPassmarks->hide(); + m_tabPlaceLabels->hide(); QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") @@ -1061,20 +1277,28 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") case TabOrder::Passmarks: m_tabPassmarks->show(); break; + case TabOrder::PlaceLabels: + m_tabPlaceLabels->show(); + break; } QT_WARNING_POP - if (index == TabOrder::Pins || index == TabOrder::Grainline + if (index == TabOrder::Pins + || index == TabOrder::Grainline || (index == TabOrder::Labels && uiTabLabels->tabWidget->currentIndex() == uiTabLabels->tabWidget->indexOf(uiTabLabels->tabLabels))) { - ShowPins(); + ShowPieceSpecialPoints(uiTabPins->listWidgetPins); + } + else if (index == TabOrder::PlaceLabels) + { + ShowPieceSpecialPoints(uiTabPlaceLabels->listWidgetPlaceLabels); } else { - if (not m_visPins.isNull()) + if (not m_visSpecialPoints.isNull()) { - delete m_visPins; + delete m_visSpecialPoints; } } } @@ -1084,13 +1308,13 @@ void DialogSeamAllowance::TabChanged(int index) { if (index == uiTabLabels->tabWidget->indexOf(uiTabLabels->tabLabels)) { - ShowPins(); + ShowPieceSpecialPoints(uiTabPins->listWidgetPins); } else { - if (not m_visPins.isNull()) + if (not m_visSpecialPoints.isNull()) { - delete m_visPins; + delete m_visSpecialPoints; } } } @@ -1985,6 +2209,7 @@ VPiece DialogSeamAllowance::CreatePiece() const piece.SetCustomSARecords(GetListInternals(uiTabPaths->listWidgetCustomSA)); piece.SetInternalPaths(GetListInternals(uiTabPaths->listWidgetInternalPaths)); piece.SetPins(GetListInternals(uiTabPins->listWidgetPins)); + piece.SetPlaceLabels(GetListInternals(uiTabPlaceLabels->listWidgetPlaceLabels)); piece.SetForbidFlipping(uiTabPaths->checkBoxForbidFlipping->isChecked()); piece.SetSeamAllowance(uiTabPaths->checkBoxSeams->isChecked()); piece.SetSeamAllowanceBuiltIn(uiTabPaths->checkBoxBuiltIn->isChecked()); @@ -2039,51 +2264,6 @@ void DialogSeamAllowance::NewMainPathItem(const VPieceNode &node) NewNodeItem(uiTabPaths->listWidgetMainPath, node); } -//--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::NewCustomSA(const CustomSARecord &record) -{ - if (record.path > NULL_ID) - { - const QString name = GetPathName(record.path, record.reverse); - - QListWidgetItem *item = new QListWidgetItem(name); - item->setFont(QFont("Times", 12, QFont::Bold)); - item->setData(Qt::UserRole, QVariant::fromValue(record)); - uiTabPaths->listWidgetCustomSA->addItem(item); - uiTabPaths->listWidgetCustomSA->setCurrentRow(uiTabPaths->listWidgetCustomSA->count()-1); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::NewInternalPath(quint32 path) -{ - if (path > NULL_ID) - { - const QString name = GetPathName(path); - - QListWidgetItem *item = new QListWidgetItem(name); - item->setFont(QFont("Times", 12, QFont::Bold)); - item->setData(Qt::UserRole, QVariant::fromValue(path)); - uiTabPaths->listWidgetInternalPaths->addItem(item); - uiTabPaths->listWidgetInternalPaths->setCurrentRow(uiTabPaths->listWidgetInternalPaths->count()-1); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::NewPin(quint32 pinPoint) -{ - if (pinPoint > NULL_ID) - { - const QSharedPointer pin = data->GetGObject(pinPoint); - - QListWidgetItem *item = new QListWidgetItem(pin->name()); - item->setFont(QFont("Times", 12, QFont::Bold)); - item->setData(Qt::UserRole, QVariant::fromValue(pinPoint)); - uiTabPins->listWidgetPins->addItem(item); - uiTabPins->listWidgetPins->setCurrentRow(uiTabPins->listWidgetPins->count()-1); - } -} - //--------------------------------------------------------------------------------------------------------------------- QString DialogSeamAllowance::GetPathName(quint32 path, bool reverse) const { @@ -2340,6 +2520,7 @@ void DialogSeamAllowance::InitFancyTabBar() m_ftb->InsertTab(TabOrder::Labels, QIcon("://icon/32x32/labels.png"), tr("Labels")); m_ftb->InsertTab(TabOrder::Grainline, QIcon("://icon/32x32/grainline.png"), tr("Grainline")); m_ftb->InsertTab(TabOrder::Passmarks, QIcon("://icon/32x32/passmark.png"), tr("Passmarks")); + m_ftb->InsertTab(TabOrder::PlaceLabels, QIcon("://icon/32x32/button.png"), tr("Place label")); ui->horizontalLayout->addWidget(m_ftb, 0, Qt::AlignLeft); @@ -2365,6 +2546,10 @@ void DialogSeamAllowance::InitFancyTabBar() uiTabPassmarks->setupUi(m_tabPassmarks); ui->horizontalLayout->addWidget(m_tabPassmarks, 1); + m_tabPlaceLabels->hide(); + uiTabPlaceLabels->setupUi(m_tabPlaceLabels); + ui->horizontalLayout->addWidget(m_tabPlaceLabels, 1); + connect(m_ftb, &FancyTabBar::CurrentChanged, this, &DialogSeamAllowance::FancyTabChanged); connect(uiTabLabels->tabWidget, &QTabWidget::currentChanged, this, &DialogSeamAllowance::TabChanged); } @@ -2666,6 +2851,14 @@ void DialogSeamAllowance::InitPassmarksTab() &DialogSeamAllowance::PassmarkShowSecondChanged); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::InitPlaceLabelsTab() +{ + uiTabPlaceLabels->listWidgetPlaceLabels->setContextMenuPolicy(Qt::CustomContextMenu); + connect(uiTabPlaceLabels->listWidgetPlaceLabels, &QListWidget::customContextMenuRequested, this, + &DialogSeamAllowance::ShowPlaceLabelsContextMenu); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::InitAllPinComboboxes() { @@ -2739,6 +2932,22 @@ void DialogSeamAllowance::UpdateCurrentInternalPathRecord() item->setText(GetPathName(path)); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::UpdateCurrentPlaceLabelRecords() +{ + const int row = uiTabPlaceLabels->listWidgetPlaceLabels->currentRow(); + if (uiTabPlaceLabels->listWidgetPlaceLabels->count() == 0 || row == -1) + { + return; + } + + QListWidgetItem *item = uiTabPlaceLabels->listWidgetPlaceLabels->item(row); + SCASSERT(item != nullptr); + const quint32 pointId = qvariant_cast(item->data(Qt::UserRole)); + auto point = data->GeometricObject(pointId); + item->setText(point->name()); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::SetGrainlineAngle(QString angleFormula) { @@ -2899,25 +3108,26 @@ void DialogSeamAllowance::SetPLAngle(QString angleFormula) } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::ShowPins() +void DialogSeamAllowance::ShowPieceSpecialPoints(const QListWidget *list) { - if (m_visPins.isNull()) + SCASSERT(list != nullptr) + if (m_visSpecialPoints.isNull()) { - m_visPins = new VisPiecePins(data); + m_visSpecialPoints = new VisPieceSpecialPoints(data); } - m_visPins->SetPins(GetListInternals(uiTabPins->listWidgetPins)); + m_visSpecialPoints->SetPoints(GetListInternals(list)); - if (not qApp->getCurrentScene()->items().contains(m_visPins)) + if (not qApp->getCurrentScene()->items().contains(m_visSpecialPoints)) { - m_visPins->VisualMode(NULL_ID); - m_visPins->setZValue(10); // pins should be on top + m_visSpecialPoints->VisualMode(NULL_ID); + m_visSpecialPoints->setZValue(10); // pins should be on top VToolSeamAllowance *tool = qobject_cast(VAbstractPattern::getTool(toolId)); SCASSERT(tool != nullptr); - m_visPins->setParentItem(tool); + m_visSpecialPoints->setParentItem(tool); } else { - m_visPins->RefreshGeometry(); + m_visSpecialPoints->RefreshGeometry(); } } diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h index 48f34032b..ef2f2fb34 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h @@ -43,9 +43,10 @@ namespace Ui class TabGrainline; class TabPins; class TabPassmarks; + class TabPlaceLabels; } -class VisPiecePins; +class VisPieceSpecialPoints; class FancyTabBar; class DialogSeamAllowance : public DialogTool @@ -81,6 +82,7 @@ private slots: void ShowCustomSAContextMenu(const QPoint &pos); void ShowInternalPathsContextMenu(const QPoint &pos); void ShowPinsContextMenu(const QPoint &pos); + void ShowPlaceLabelsContextMenu(const QPoint &pos); void ListChanged(); void EnableSeamAllowance(bool enable); @@ -94,6 +96,7 @@ private slots: void ReturnDefAfter(); void CustomSAChanged(int row); void PathDialogClosed(int result); + void PlaceLabelDialogClosed(int result); void FancyTabChanged(int index); void TabChanged(int index); void PassmarkLineTypeChanged(int id); @@ -157,12 +160,14 @@ private: Ui::TabGrainline *uiTabGrainline; Ui::TabPins *uiTabPins; Ui::TabPassmarks *uiTabPassmarks; + Ui::TabPlaceLabels *uiTabPlaceLabels; QWidget *m_tabPaths; QWidget *m_tabLabels; QWidget *m_tabGrainline; QWidget *m_tabPins; QWidget *m_tabPassmarks; + QWidget *m_tabPlaceLabels; FancyTabBar* m_ftb; @@ -180,7 +185,7 @@ private: qreal m_my; QPointer m_dialog; - QPointer m_visPins; + QPointer m_visSpecialPoints; VPieceLabelData m_oldData; VPatternLabelData m_oldGeom; @@ -207,15 +212,13 @@ private: VPiece CreatePiece() const; void NewMainPathItem(const VPieceNode &node); - void NewCustomSA(const CustomSARecord &record); - void NewInternalPath(quint32 path); - void NewPin(quint32 pinPoint); QString GetPathName(quint32 path, bool reverse = false) const; bool MainPathIsValid() const; void ValidObjects(bool value); bool MainPathIsClockwise() const; void UpdateCurrentCustomSARecord(); void UpdateCurrentInternalPathRecord(); + void UpdateCurrentPlaceLabelRecords(); QListWidgetItem *GetItemById(quint32 id); @@ -241,6 +244,7 @@ private: void InitGrainlineTab(); void InitPinsTab(); void InitPassmarksTab(); + void InitPlaceLabelsTab(); void InitAllPinComboboxes(); void SetFormulaSAWidth(const QString &formula); @@ -256,7 +260,7 @@ private: void SetPLHeight(QString heightFormula); void SetPLAngle(QString angleFormula); - void ShowPins(); + void ShowPieceSpecialPoints(const QListWidget *list); }; #endif // DIALOGSEAMALLOWANCE_H diff --git a/src/libs/vtools/dialogs/tools/piece/tabs/tabplacelabels.ui b/src/libs/vtools/dialogs/tools/piece/tabs/tabplacelabels.ui new file mode 100644 index 000000000..4bfc35221 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/piece/tabs/tabplacelabels.ui @@ -0,0 +1,28 @@ + + + TabPlaceLabels + + + + 0 + 0 + 261 + 230 + + + + Dialog + + + + + + QAbstractItemView::InternalMove + + + + + + + + diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp index 7501da6c1..fec1953b8 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp @@ -61,7 +61,7 @@ void VAbstractFlipping::CreateDestination(VAbstractOperationInitData &initData, const QSharedPointer obj = initData.data->GetGObject(idObject); // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") @@ -98,6 +98,8 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") initData.data)); break; case GOType::Unknown: + case GOType::PlaceLabel: + Q_UNREACHABLE(); break; } QT_WARNING_POP @@ -111,7 +113,7 @@ QT_WARNING_POP const QSharedPointer obj = initData.data->GetGObject(idObject); // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") @@ -148,6 +150,8 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") initData.data, initData.destination.at(i).id); break; case GOType::Unknown: + case GOType::PlaceLabel: + Q_UNREACHABLE(); break; } QT_WARNING_POP diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp index c3729f022..7db3e3a49 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -607,7 +607,7 @@ void VAbstractOperation::InitOperatedObjects() const QSharedPointer obj = VAbstractTool::data.GetGObject(object.id); // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") @@ -650,6 +650,8 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") InitCurve(object.id, &(VAbstractTool::data), obj->getType(), SceneObject::SplinePath); break; case GOType::Unknown: + case GOType::PlaceLabel: + Q_UNREACHABLE(); break; } QT_WARNING_POP diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp index d72a32881..95e6b9d31 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp @@ -133,7 +133,7 @@ VToolMove *VToolMove::Create(VToolMoveInitData &initData) const QSharedPointer obj = initData.data->GetGObject(idObject); // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") @@ -171,6 +171,8 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") initData.data)); break; case GOType::Unknown: + case GOType::PlaceLabel: + Q_UNREACHABLE(); break; } QT_WARNING_POP @@ -184,7 +186,7 @@ QT_WARNING_POP const QSharedPointer obj = initData.data->GetGObject(idObject); // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") @@ -220,6 +222,8 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") initData.destination.at(i).id); break; case GOType::Unknown: + case GOType::PlaceLabel: + Q_UNREACHABLE(); break; } QT_WARNING_POP diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp index 31922cc5e..4867a50e0 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp @@ -150,7 +150,7 @@ VToolRotation *VToolRotation::Create(VToolRotationInitData &initData) const QSharedPointer obj = initData.data->GetGObject(idObject); // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") @@ -187,6 +187,8 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") initData.data)); break; case GOType::Unknown: + case GOType::PlaceLabel: + Q_UNREACHABLE(); break; } QT_WARNING_POP @@ -200,7 +202,7 @@ QT_WARNING_POP const QSharedPointer obj = initData.data->GetGObject(idObject); // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") @@ -237,6 +239,8 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") initData.data, initData.destination.at(i).id); break; case GOType::Unknown: + case GOType::PlaceLabel: + Q_UNREACHABLE(); break; } QT_WARNING_POP diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp index 7438c0f7d..1e80d4551 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp @@ -471,6 +471,7 @@ void VToolCurveIntersectAxis::InitSegments(const GOType &curveType, qreal segLen break; } case GOType::Point: + case GOType::PlaceLabel: case GOType::Unknown: Q_UNREACHABLE(); break; diff --git a/src/libs/vtools/tools/nodeDetails/nodedetails.h b/src/libs/vtools/tools/nodeDetails/nodedetails.h index a2f9eab21..caf1db52a 100644 --- a/src/libs/vtools/tools/nodeDetails/nodedetails.h +++ b/src/libs/vtools/tools/nodeDetails/nodedetails.h @@ -36,5 +36,6 @@ #include "vnodesplinepath.h" #include "vtoolpiecepath.h" #include "vtoolpin.h" +#include "vtoolplacelabel.h" #endif // NODEDETAILS_H diff --git a/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.cpp b/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.cpp new file mode 100644 index 000000000..fe175bb20 --- /dev/null +++ b/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.cpp @@ -0,0 +1,211 @@ +/************************************************************************ + ** + ** @file vtoolplacelabel.cpp + ** @author Roman Telezhynskyi + ** @date 15 10, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 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 "vtoolplacelabel.h" +#include "../../dialogs/tools/dialogplacelabel.h" +#include "../../undocommands/savepieceoptions.h" +#include "../vtoolseamallowance.h" +#include "../vgeometry/vpointf.h" +#include "../vgeometry/vplacelabelitem.h" + +const QString VToolPlaceLabel::ToolType = QStringLiteral("placeLabel"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolPlaceLabel *VToolPlaceLabel::Create(QSharedPointer dialog, VAbstractPattern *doc, VContainer *data) +{ + SCASSERT(not dialog.isNull()); + QSharedPointer dialogTool = dialog.objectCast(); + SCASSERT(not dialogTool.isNull()) + + VToolPlaceLabelInitData initData; + initData.width = dialogTool->GetWidth(); + initData.height = dialogTool->GetHeight(); + initData.angle = dialogTool->GetAngle(); + initData.type = dialogTool->GetLabelType(); + initData.centerPoint = dialogTool->GetCenterPoint(); + initData.idObject = dialogTool->GetPieceId(); + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + return Create(initData); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolPlaceLabel *VToolPlaceLabel::Create(VToolPlaceLabelInitData &initData) +{ + const qreal w = qAbs(qApp->toPixel(CheckFormula(initData.id, initData.width, initData.data))); + const qreal h = qAbs(qApp->toPixel(CheckFormula(initData.id, initData.height, initData.data))); + const qreal a = CheckFormula(initData.id, initData.angle, initData.data); + + QSharedPointer node(new VPlaceLabelItem()); + node->SetWidth(w, initData.width); + node->SetHeight(h, initData.height); + node->SetAngle(a, initData.angle); + node->SetLabelType(initData.type); + node->SetCenterPoint(initData.centerPoint); + + if (initData.typeCreation == Source::FromGui) + { + //We can't use exist object. Need create new. + auto point = initData.data->GeometricObject(initData.centerPoint); + + node->setName(point->name()); + node->setX(point->x()); + node->setY(point->y()); + node->setMx(point->mx()); + node->setMy(point->my()); + + initData.id = initData.data->AddGObject(node); + } + else + { + QSharedPointer point; + try + { + point = initData.data->GeometricObject(initData.centerPoint); + } + catch (const VExceptionBadId &e) + { // Possible case. Parent was deleted, but the node object is still here. + Q_UNUSED(e) + return nullptr;// Just ignore + } + node->setName(point->name()); + node->setX(point->x()); + node->setY(point->y()); + node->setMx(point->mx()); + node->setMy(point->my()); + + if (initData.typeCreation == Source::FromTool) + { + QSharedPointer label = qSharedPointerDynamicCast(point); + SCASSERT(label.isNull() == false) + + node->SetCorrectionAngle(label->GetCorrectionAngle()); + } + + initData.data->UpdateGObject(initData.id, node); + if (initData.parse != Document::FullParse) + { + initData.doc->UpdateToolData(initData.id, initData.data); + } + } + VAbstractTool::AddRecord(initData.id, Tool::PlaceLabel, initData.doc); + VToolPlaceLabel *point = nullptr; + if (initData.parse == Document::FullParse) + { + point = new VToolPlaceLabel(initData); + + VAbstractPattern::AddTool(initData.id, point); + if (initData.idTool != NULL_ID) + { + //Some nodes we don't show on scene. Tool that creates this nodes must free memory. + VDataTool *tool = VAbstractPattern::getTool(initData.idTool); + SCASSERT(tool != nullptr) + point->setParent(tool);// Adopted by a tool + } + else + { + // Help to delete the node before each FullParse + initData.doc->AddToolOnRemove(point); + } + } + else + { + initData.doc->UpdateToolData(initData.id, initData.data); + } + return point; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VToolPlaceLabel::getTagName() const +{ + return VAbstractPattern::TagPoint; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPlaceLabel::AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, + const VPlaceLabelItem &label) +{ + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrIdObject, label.GetCenterPoint()); + doc->SetAttribute(domElement, AttrWidth, label.GetWidthFormula()); + doc->SetAttribute(domElement, AttrHeight, label.GetHeightFormula()); + doc->SetAttribute(domElement, AttrAngle, label.GetAngleFormula()); + doc->SetAttribute(domElement, AttrPlaceLabelType, static_cast(label.GetLabelType())); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPlaceLabel::AllowHover(bool enabled) +{ + Q_UNUSED(enabled) + // do nothing +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPlaceLabel::AllowSelecting(bool enabled) +{ + Q_UNUSED(enabled) + // do nothing +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPlaceLabel::AddToFile() +{ + auto label = VAbstractTool::data.GeometricObject(m_id); + + QDomElement domElement = doc->createElement(getTagName()); + + AddAttributes(doc, domElement, m_id, *label); + if (idTool != NULL_ID) + { + doc->SetAttribute(domElement, AttrIdTool, idTool); + } + + AddToModeling(domElement); + + if (m_pieceId > NULL_ID) + { + const VPiece oldDet = VAbstractTool::data.GetPiece(m_pieceId); + VPiece newDet = oldDet; + + newDet.GetPlaceLabels().append(m_id); + qApp->getUndoStack()->push(new SavePieceOptions(oldDet, newDet, doc, m_pieceId)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolPlaceLabel::VToolPlaceLabel(const VToolPlaceLabelInitData &initData, QObject *qoParent) + : VAbstractNode(initData.doc, initData.data, initData.id, initData.centerPoint, initData.drawName, + initData.idTool, qoParent), + m_pieceId(initData.idObject) +{ + ToolCreation(initData.typeCreation); +} diff --git a/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.h b/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.h new file mode 100644 index 000000000..77d10f6e3 --- /dev/null +++ b/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.h @@ -0,0 +1,83 @@ +/************************************************************************ + ** + ** @file vtoolplacelabel.h + ** @author Roman Telezhynskyi + ** @date 15 10, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 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 VTOOLPLACELABEL_H +#define VTOOLPLACELABEL_H + +#include + +#include "vabstractnode.h" +#include "../vgeometry/vplacelabelitem.h" + +class DialogTool; + +struct VToolPlaceLabelInitData : VAbstractNodeInitData +{ + VToolPlaceLabelInitData() + : VAbstractNodeInitData(), + width("0"), + height("0"), + angle("0"), + type(PlaceLabelType::Button), + centerPoint(NULL_ID) + {} + + QString width; + QString height; + QString angle; + PlaceLabelType type; + quint32 centerPoint; +}; + +class VToolPlaceLabel : public VAbstractNode +{ + Q_OBJECT +public: + static VToolPlaceLabel* Create(QSharedPointer dialog, VAbstractPattern *doc, VContainer *data); + static VToolPlaceLabel* Create(VToolPlaceLabelInitData &initData); + + static const QString ToolType; + virtual QString getTagName() const Q_DECL_OVERRIDE; + + static void AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPlaceLabelItem &label); +public slots: + virtual void FullUpdateFromFile () Q_DECL_OVERRIDE {} + virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; + virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; +protected: + virtual void AddToFile() Q_DECL_OVERRIDE; + virtual void ShowNode() Q_DECL_OVERRIDE {} + virtual void HideNode() Q_DECL_OVERRIDE {} +private: + Q_DISABLE_COPY(VToolPlaceLabel) + + quint32 m_pieceId; + + VToolPlaceLabel(const VToolPlaceLabelInitData &initData, QObject *qoParent = nullptr); +}; + +#endif // VTOOLPLACELABEL_H diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index 8b34c046c..3d3414519 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -60,7 +60,8 @@ HEADERS += \ $$PWD/vtoolseamallowance.h \ $$PWD/nodeDetails/vtoolpiecepath.h \ $$PWD/nodeDetails/vtoolpin.h \ - $$PWD/vinteractivetool.h + $$PWD/vinteractivetool.h \ + $$PWD/nodeDetails/vtoolplacelabel.h SOURCES += \ $$PWD/vdatatool.cpp \ @@ -118,4 +119,5 @@ SOURCES += \ $$PWD/vtoolseamallowance.cpp \ $$PWD/nodeDetails/vtoolpiecepath.cpp \ $$PWD/nodeDetails/vtoolpin.cpp \ - $$PWD/vinteractivetool.cpp + $$PWD/vinteractivetool.cpp \ + $$PWD/nodeDetails/vtoolplacelabel.cpp diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 881a490ea..d0937bcaa 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -65,17 +65,17 @@ // Current version of seam allowance tag need for backward compatibility const quint8 VToolSeamAllowance::pieceVersion = 2; -const QString VToolSeamAllowance::TagCSA = QStringLiteral("csa"); -const QString VToolSeamAllowance::TagRecord = QStringLiteral("record"); -const QString VToolSeamAllowance::TagIPaths = QStringLiteral("iPaths"); -const QString VToolSeamAllowance::TagPins = QStringLiteral("pins"); +const QString VToolSeamAllowance::TagCSA = QStringLiteral("csa"); +const QString VToolSeamAllowance::TagRecord = QStringLiteral("record"); +const QString VToolSeamAllowance::TagIPaths = QStringLiteral("iPaths"); +const QString VToolSeamAllowance::TagPins = QStringLiteral("pins"); +const QString VToolSeamAllowance::TagPlaceLabels = QStringLiteral("placeLabels"); const QString VToolSeamAllowance::AttrVersion = QStringLiteral("version"); const QString VToolSeamAllowance::AttrForbidFlipping = QStringLiteral("forbidFlipping"); const QString VToolSeamAllowance::AttrSeamAllowance = QStringLiteral("seamAllowance"); const QString VToolSeamAllowance::AttrHideMainPath = QStringLiteral("hideMainPath"); const QString VToolSeamAllowance::AttrSeamAllowanceBuiltIn = QStringLiteral("seamAllowanceBuiltIn"); -const QString VToolSeamAllowance::AttrHeight = QStringLiteral("height"); const QString VToolSeamAllowance::AttrUnited = QStringLiteral("united"); const QString VToolSeamAllowance::AttrFont = QStringLiteral("fontSize"); const QString VToolSeamAllowance::AttrTopLeftPin = QStringLiteral("topLeftPin"); @@ -232,7 +232,7 @@ void VToolSeamAllowance::AddAttributes(VAbstractPattern *doc, QDomElement &domEl domElement.removeAttribute(AttrSeamAllowanceBuiltIn); } - doc->SetAttribute(domElement, VAbstractPattern::AttrWidth, piece.GetFormulaSAWidth()); + doc->SetAttribute(domElement, AttrWidth, piece.GetFormulaSAWidth()); doc->SetAttribute(domElement, AttrUnited, piece.IsUnited()); } @@ -284,17 +284,14 @@ void VToolSeamAllowance::AddInternalPaths(VAbstractPattern *doc, QDomElement &do //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::AddPins(VAbstractPattern *doc, QDomElement &domElement, const QVector &pins) { - if (pins.size() > 0) - { - QDomElement pinsElement = doc->createElement(VToolSeamAllowance::TagPins); - for (int i = 0; i < pins.size(); ++i) - { - QDomElement recordNode = doc->createElement(VToolSeamAllowance::TagRecord); - recordNode.appendChild(doc->createTextNode(QString().setNum(pins.at(i)))); - pinsElement.appendChild(recordNode); - } - domElement.appendChild(pinsElement); - } + AddPointRecords(doc, domElement, pins, VToolSeamAllowance::TagPins); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSeamAllowance::AddPlaceLabels(VAbstractPattern *doc, QDomElement &domElement, + const QVector &placeLabels) +{ + AddPointRecords(doc, domElement, placeLabels, VToolSeamAllowance::TagPlaceLabels); } //--------------------------------------------------------------------------------------------------------------------- @@ -313,7 +310,7 @@ void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement doc->SetAttribute(domData, VAbstractPattern::AttrOnFold, data.IsOnFold()); doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); - doc->SetAttribute(domData, VAbstractPattern::AttrWidth, data.GetLabelWidth()); + doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth()); doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight()); doc->SetAttribute(domData, AttrFont, data.GetFontSize()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, data.GetRotation()); @@ -358,7 +355,7 @@ void VToolSeamAllowance::AddPatternInfo(VAbstractPattern *doc, QDomElement &domE doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible()); doc->SetAttribute(domData, AttrMx, geom.GetPos().x()); doc->SetAttribute(domData, AttrMy, geom.GetPos().y()); - doc->SetAttribute(domData, VAbstractPattern::AttrWidth, geom.GetLabelWidth()); + doc->SetAttribute(domData, AttrWidth, geom.GetLabelWidth()); doc->SetAttribute(domData, AttrHeight, geom.GetLabelHeight()); doc->SetAttribute(domData, AttrFont, geom.GetFontSize()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, geom.GetRotation()); @@ -514,7 +511,8 @@ void VToolSeamAllowance::ReinitInternals(const VPiece &detail, VMainGraphicsScen InitNodes(detail, scene); InitCSAPaths(detail); InitInternalPaths(detail); - InitPins(detail); + InitSpecialPoints(detail.GetPins()); + InitSpecialPoints(detail.GetPlaceLabels()); } //--------------------------------------------------------------------------------------------------------------------- @@ -865,6 +863,7 @@ void VToolSeamAllowance::paint(QPainter *painter, const QStyleOptionGraphicsItem setPen(toolPen); m_seamAllowance->setPen(toolPen); m_passmarks->setPen(toolPen); + m_placeLabels->setPen(toolPen); if ((m_dataLabel->IsIdle() == false || m_patternInfo->IsIdle() == false @@ -919,6 +918,7 @@ void VToolSeamAllowance::AddToFile() AddCSARecords(doc, domElement, piece.GetCustomSARecords()); AddInternalPaths(doc, domElement, piece.GetInternalPaths()); AddPins(doc, domElement, piece.GetPins()); + AddPlaceLabels(doc, domElement, piece.GetPlaceLabels()); qApp->getUndoStack()->push(new AddPiece(domElement, doc, VAbstractTool::data, m_sceneDetails, m_drawName)); } @@ -1203,7 +1203,8 @@ VToolSeamAllowance::VToolSeamAllowance(const VToolSeamAllowanceInitData &initDat m_dataLabel(new VTextGraphicsItem(this)), m_patternInfo(new VTextGraphicsItem(this)), m_grainLine(new VGrainlineItem(this)), - m_passmarks(new QGraphicsPathItem(this)) + m_passmarks(new QGraphicsPathItem(this)), + m_placeLabels(new QGraphicsPathItem(this)) { VPiece detail = initData.data->GetPiece(initData.id); ReinitInternals(detail, m_sceneDetails); @@ -1291,6 +1292,8 @@ void VToolSeamAllowance::RefreshGeometry() m_seamAllowance->setPath(QPainterPath()); } + m_placeLabels->setPath(detail.PlaceLabelPath(this->getData())); + UpdateDetailLabel(); UpdatePatternInfo(); UpdateGrainline(); @@ -1549,7 +1552,7 @@ void VToolSeamAllowance::InitNode(const VPieceNode &node, VMainGraphicsScene *sc } //--------------------------------------------------------------------------------------------------------------------- -void VToolSeamAllowance::InitCSAPaths(const VPiece &detail) +void VToolSeamAllowance::InitCSAPaths(const VPiece &detail) const { for (int i = 0; i < detail.GetCustomSARecords().size(); ++i) { @@ -1576,11 +1579,11 @@ void VToolSeamAllowance::InitInternalPaths(const VPiece &detail) } //--------------------------------------------------------------------------------------------------------------------- -void VToolSeamAllowance::InitPins(const VPiece &detail) +void VToolSeamAllowance::InitSpecialPoints(const QVector &points) const { - for (int i = 0; i < detail.GetPins().size(); ++i) + for (int i = 0; i < points.size(); ++i) { - doc->IncrementReferens(detail.GetPins().at(i)); + doc->IncrementReferens(points.at(i)); } } @@ -1690,3 +1693,20 @@ QList VToolSeamAllowance::SelectedTools() const return tools; } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSeamAllowance::AddPointRecords(VAbstractPattern *doc, QDomElement &domElement, + const QVector &records, const QString &tag) +{ + if (records.size() > 0) + { + QDomElement pinsElement = doc->createElement(tag); + for (int i = 0; i < records.size(); ++i) + { + QDomElement recordNode = doc->createElement(VToolSeamAllowance::TagRecord); + recordNode.appendChild(doc->createTextNode(QString().setNum(records.at(i)))); + pinsElement.appendChild(recordNode); + } + domElement.appendChild(pinsElement); + } +} diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index 74dfced33..d77f2a7cc 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -71,13 +71,13 @@ public: static const QString TagRecord; static const QString TagIPaths; static const QString TagPins; + static const QString TagPlaceLabels; static const QString AttrVersion; static const QString AttrForbidFlipping; static const QString AttrSeamAllowance; static const QString AttrHideMainPath; static const QString AttrSeamAllowanceBuiltIn; - static const QString AttrHeight; static const QString AttrUnited; static const QString AttrFont; static const QString AttrTopLeftPin; @@ -96,6 +96,7 @@ public: static void AddCSARecords(VAbstractPattern *doc, QDomElement &domElement, const QVector &records); static void AddInternalPaths(VAbstractPattern *doc, QDomElement &domElement, const QVector &paths); static void AddPins(VAbstractPattern *doc, QDomElement &domElement, const QVector &pins); + static void AddPlaceLabels(VAbstractPattern *doc, QDomElement &domElement, const QVector &placeLabels); static void AddPatternPieceData(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece); static void AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece); static void AddGrainline(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece); @@ -169,6 +170,7 @@ private: VTextGraphicsItem *m_patternInfo; VGrainlineItem *m_grainLine; QGraphicsPathItem *m_passmarks; + QGraphicsPathItem *m_placeLabels; VToolSeamAllowance(const VToolSeamAllowanceInitData &initData, QGraphicsItem * parent = nullptr); @@ -183,15 +185,18 @@ private: void InitNodes(const VPiece &detail, VMainGraphicsScene *scene); static void InitNode(const VPieceNode &node, VMainGraphicsScene *scene, VContainer *data, VAbstractPattern *doc, VToolSeamAllowance *parent); - void InitCSAPaths(const VPiece &detail); + void InitCSAPaths(const VPiece &detail) const; void InitInternalPaths(const VPiece &detail); - void InitPins(const VPiece &detail); + void InitSpecialPoints(const QVector &points) const; bool PrepareLabelData(const VPatternLabelData &labelData, VTextGraphicsItem *labelItem, QPointF &pos, qreal &labelAngle); void UpdateLabelItem(VTextGraphicsItem *labelItem, QPointF pos, qreal labelAngle); QList SelectedTools() const; + + static void AddPointRecords(VAbstractPattern *doc, QDomElement &domElement, const QVector &records, + const QString &tag); }; #endif // VTOOLSEAMALLOWANCE_H diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 7281d8a37..5885ba7af 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -54,6 +54,7 @@ #include "../vgeometry/vpointf.h" #include "../vgeometry/vspline.h" #include "../vgeometry/vsplinepoint.h" +#include "../vgeometry/vplacelabelitem.h" #include "../vmisc/diagnostic.h" #include "../vmisc/logging.h" #include "../vmisc/vabstractapplication.h" @@ -68,6 +69,7 @@ #include "nodeDetails/vnodesplinepath.h" #include "nodeDetails/vtoolpiecepath.h" #include "nodeDetails/vtoolpin.h" +#include "nodeDetails/vtoolplacelabel.h" #include "vdatatool.h" #include "vnodedetail.h" #include "vtoolseamallowance.h" @@ -221,7 +223,7 @@ QVector GetPiece2Pins(VAbstractPattern *doc, quint32 id) const QDomElement element = detList.at(j).toElement(); if (not element.isNull() && element.tagName() == VToolSeamAllowance::TagPins) { - return VAbstractPattern::ParsePiecePins(element); + return VAbstractPattern::ParsePiecePointRecords(element); } } } @@ -428,6 +430,40 @@ quint32 AddPin(quint32 id, const VToolUnionDetailsInitData &initData, QVector &children, + const QString &drawName, qreal dx, qreal dy, quint32 pRotate, qreal angle) +{ + QScopedPointer label(new VPlaceLabelItem(*initData.data->GeometricObject(id))); + + if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID) + { + BiasRotatePoint(label.data(), dx, dy, static_cast(*initData.data->GeometricObject(pRotate)), + angle); + } + + label->SetCorrectionAngle(label->GetCorrectionAngle() + angle); + QScopedPointer label1(new VPlaceLabelItem(*label)); + + const quint32 idObject = initData.data->AddGObject(label.take()); + children.append(idObject); + const quint32 idLabel = initData.data->AddGObject(label1.take()); + + VToolPlaceLabelInitData initNodeData; + initNodeData.id = idLabel; + initNodeData.centerPoint = idObject; + initNodeData.idObject = NULL_ID; + initNodeData.doc = initData.doc; + initNodeData.data = initData.data; + initNodeData.parse = Document::FullParse; + initNodeData.typeCreation = Source::FromTool; + initNodeData.idTool = initData.id; + initNodeData.drawName = drawName; + + VToolPlaceLabel::Create(initNodeData); + return idLabel; +} + //--------------------------------------------------------------------------------------------------------------------- quint32 AddNodeArc(const VPieceNode &node, const VToolUnionDetailsInitData &initData, QVector &children, const QString &drawName, qreal dx, qreal dy, @@ -772,6 +808,12 @@ void SavePinsChildren(VAbstractPattern *doc, quint32 id, const QVector SaveChildren(doc, id, doc->createElement(VToolSeamAllowance::TagPins), children); } +//--------------------------------------------------------------------------------------------------------------------- +void SavePlaceLabelsChildren(VAbstractPattern *doc, quint32 id, const QVector &children) +{ + SaveChildren(doc, id, doc->createElement(VToolSeamAllowance::TagPlaceLabels), children); +} + //--------------------------------------------------------------------------------------------------------------------- QVector GetChildren(VAbstractPattern *doc, quint32 id, const QString &tagName) { @@ -830,6 +872,12 @@ QVector GetPinChildren(VAbstractPattern *doc, quint32 id) return GetChildren(doc, id, VToolSeamAllowance::TagPins); } +//--------------------------------------------------------------------------------------------------------------------- +QVector GetPlaceLabelChildren(VAbstractPattern *doc, quint32 id) +{ + return GetChildren(doc, id, VToolSeamAllowance::TagPlaceLabels); +} + //--------------------------------------------------------------------------------------------------------------------- quint32 TakeNextId(QVector &children) { @@ -1187,6 +1235,22 @@ void CreateUnitedDetailPins(VPiece &newDetail, const VPiece &d, QVector children += nodeChildren; } +//--------------------------------------------------------------------------------------------------------------------- +void CreateUnitedDetailPlaceLabels(VPiece &newDetail, const VPiece &d, QVector &children, + const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, + qreal dy, quint32 pRotate, qreal angle) +{ + QVector nodeChildren; + for(int i=0; i < d.GetPlaceLabels().size(); ++i) + { + const quint32 id = AddPlaceLabel(d.GetPlaceLabels().at(i), initData, children, drawName, dx, dy, pRotate, + angle); + newDetail.GetPlaceLabels().append(id); + nodeChildren.prepend(id); + } + children += nodeChildren; +} + //--------------------------------------------------------------------------------------------------------------------- void CreateUnitedPins(VPiece &newDetail, const VPiece &d1, const VPiece &d2, const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) @@ -1201,6 +1265,21 @@ void CreateUnitedPins(VPiece &newDetail, const VPiece &d1, const VPiece &d2, con SavePinsChildren(initData.doc, initData.id, children); } +//--------------------------------------------------------------------------------------------------------------------- +void CreateUnitedPlaceLabels(VPiece &newDetail, const VPiece &d1, const VPiece &d2, const QString &drawName, + const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, + qreal angle) +{ + for (int i = 0; i < d1.GetPlaceLabels().size(); ++i) + { + newDetail.GetPlaceLabels().append(d1.GetPlaceLabels().at(i)); + } + + QVector children; + CreateUnitedDetailPlaceLabels(newDetail, d2, children, drawName, initData, dx, dy, pRotate, angle); + SavePlaceLabelsChildren(initData.doc, initData.id, children); +} + //--------------------------------------------------------------------------------------------------------------------- void UpdateUnitedNodes(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { @@ -1328,6 +1407,26 @@ void UpdateUnitedDetailPins(const VToolUnionDetailsInitData &initData, qreal dx, } } +//--------------------------------------------------------------------------------------------------------------------- +void UpdateUnitedDetailPlaceLabels(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, + qreal angle, const QVector &records) +{ + QVector children = GetPlaceLabelChildren(initData.doc, initData.id); + + for (int i = 0; i < records.size(); ++i) + { + QScopedPointer + label(new VPlaceLabelItem(*initData.data->GeometricObject(records.at(i)))); + if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID) + { + BiasRotatePoint(label.data(), dx, dy, + static_cast(*initData.data->GeometricObject(pRotate)), angle); + } + label->SetCorrectionAngle(label->GetCorrectionAngle()+angle); + initData.data->UpdateGObject(TakeNextId(children), label.take()); + } +} + //--------------------------------------------------------------------------------------------------------------------- void CreateUnitedDetail(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { @@ -1343,6 +1442,7 @@ void CreateUnitedDetail(const VToolUnionDetailsInitData &initData, qreal dx, qre CreateUnitedCSA(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle); CreateUnitedInternalPaths(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle); CreateUnitedPins(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle); + CreateUnitedPlaceLabels(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle); newDetail.SetName(QObject::tr("United detail")); QString formulaSAWidth = d1.GetFormulaSAWidth(); @@ -1386,6 +1486,7 @@ void UpdateUnitedDetail(const VToolUnionDetailsInitData &initData, qreal dx, qre UpdateUnitedDetailInternalPaths(initData, dx, dy, pRotate, angle, GetPiece2InternalPaths(initData.doc, initData.id)); UpdateUnitedDetailPins(initData, dx, dy, pRotate, angle, GetPiece2Pins(initData.doc, initData.id)); + UpdateUnitedDetailPlaceLabels(initData, dx, dy, pRotate, angle, GetPiece2Pins(initData.doc, initData.id)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/undocommands/savepieceoptions.cpp b/src/libs/vtools/undocommands/savepieceoptions.cpp index 09b297236..91539cc5c 100644 --- a/src/libs/vtools/undocommands/savepieceoptions.cpp +++ b/src/libs/vtools/undocommands/savepieceoptions.cpp @@ -72,6 +72,7 @@ void SavePieceOptions::undo() VToolSeamAllowance::AddCSARecords(doc, domElement, m_oldDet.GetCustomSARecords()); VToolSeamAllowance::AddInternalPaths(doc, domElement, m_oldDet.GetInternalPaths()); VToolSeamAllowance::AddPins(doc, domElement, m_oldDet.GetPins()); + VToolSeamAllowance::AddPlaceLabels(doc, domElement, m_oldDet.GetPlaceLabels()); DecrementReferences(m_newDet.MissingNodes(m_oldDet)); IncrementReferences(m_oldDet.MissingNodes(m_newDet)); @@ -84,7 +85,10 @@ void SavePieceOptions::undo() DecrementReferences(m_newDet.MissingPins(m_oldDet)); IncrementReferences(m_oldDet.MissingPins(m_newDet)); - + + DecrementReferences(m_newDet.MissingPlaceLabels(m_oldDet)); + IncrementReferences(m_oldDet.MissingPlaceLabels(m_newDet)); + if (VToolSeamAllowance *tool = qobject_cast(VAbstractPattern::getTool(nodeId))) { tool->Update(m_oldDet); @@ -113,6 +117,7 @@ void SavePieceOptions::redo() VToolSeamAllowance::AddCSARecords(doc, domElement, m_newDet.GetCustomSARecords()); VToolSeamAllowance::AddInternalPaths(doc, domElement, m_newDet.GetInternalPaths()); VToolSeamAllowance::AddPins(doc, domElement, m_newDet.GetPins()); + VToolSeamAllowance::AddPlaceLabels(doc, domElement, m_newDet.GetPlaceLabels()); DecrementReferences(m_oldDet.MissingNodes(m_newDet)); IncrementReferences(m_newDet.MissingNodes(m_oldDet)); @@ -126,6 +131,9 @@ void SavePieceOptions::redo() DecrementReferences(m_oldDet.MissingPins(m_newDet)); IncrementReferences(m_newDet.MissingPins(m_oldDet)); + DecrementReferences(m_oldDet.MissingPlaceLabels(m_newDet)); + IncrementReferences(m_newDet.MissingPlaceLabels(m_oldDet)); + if (VToolSeamAllowance *tool = qobject_cast(VAbstractPattern::getTool(nodeId))) { tool->Update(m_newDet); diff --git a/src/libs/vtools/undocommands/saveplacelabeloptions.cpp b/src/libs/vtools/undocommands/saveplacelabeloptions.cpp new file mode 100644 index 000000000..389ccbfab --- /dev/null +++ b/src/libs/vtools/undocommands/saveplacelabeloptions.cpp @@ -0,0 +1,125 @@ +/************************************************************************ + ** + ** @file saveplacelabeloptions.cpp + ** @author Roman Telezhynskyi + ** @date 16 10, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 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 "saveplacelabeloptions.h" +#include "../tools/nodeDetails/vtoolplacelabel.h" + +//--------------------------------------------------------------------------------------------------------------------- +SavePlaceLabelOptions::SavePlaceLabelOptions(const VPlaceLabelItem &oldLabel, const VPlaceLabelItem &newLabel, + VAbstractPattern *doc, VContainer *data, quint32 id, QUndoCommand *parent) + : VUndoCommand(QDomElement(), doc, parent), + m_oldLabel(oldLabel), + m_newLabel(newLabel), + m_data(data) +{ + setText(tr("save place label options")); + nodeId = id; +} + +//--------------------------------------------------------------------------------------------------------------------- +void SavePlaceLabelOptions::undo() +{ + qCDebug(vUndo, "Undo."); + + QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagPoint); + if (domElement.isElement()) + { + VToolPlaceLabel::AddAttributes(doc, domElement, nodeId, m_oldLabel); + + if (m_oldLabel.GetCenterPoint() != m_newLabel.GetCenterPoint()) + { + doc->IncrementReferens(m_oldLabel.GetCenterPoint()); + doc->DecrementReferens(m_newLabel.GetCenterPoint()); + } + + SCASSERT(m_data); + m_data->UpdateGObject(nodeId, new VPlaceLabelItem(m_oldLabel)); + } + else + { + qCDebug(vUndo, "Can't find place label with id = %u.", nodeId); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void SavePlaceLabelOptions::redo() +{ + qCDebug(vUndo, "Redo."); + + QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagPoint); + if (domElement.isElement()) + { + VToolPlaceLabel::AddAttributes(doc, domElement, nodeId, m_newLabel); + + if (m_oldLabel.GetCenterPoint() != m_newLabel.GetCenterPoint()) + { + doc->IncrementReferens(m_newLabel.GetCenterPoint()); + doc->DecrementReferens(m_oldLabel.GetCenterPoint()); + } + + SCASSERT(m_data); + m_data->UpdateGObject(nodeId, new VPlaceLabelItem(m_newLabel)); + } + else + { + qCDebug(vUndo, "Can't find path with id = %u.", nodeId); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool SavePlaceLabelOptions::mergeWith(const QUndoCommand *command) +{ + const SavePlaceLabelOptions *saveCommand = static_cast(command); + SCASSERT(saveCommand != nullptr); + const quint32 id = saveCommand->LabelId(); + + if (id != nodeId) + { + return false; + } + + m_newLabel = saveCommand->NewLabel(); + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +int SavePlaceLabelOptions::id() const +{ + return static_cast(UndoCommand::SavePlaceLabelOptions); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 SavePlaceLabelOptions::LabelId() const +{ + return nodeId; +} + +//--------------------------------------------------------------------------------------------------------------------- +VPlaceLabelItem SavePlaceLabelOptions::NewLabel() const +{ + return m_newLabel; +} diff --git a/src/libs/vtools/undocommands/saveplacelabeloptions.h b/src/libs/vtools/undocommands/saveplacelabeloptions.h new file mode 100644 index 000000000..bb81bb355 --- /dev/null +++ b/src/libs/vtools/undocommands/saveplacelabeloptions.h @@ -0,0 +1,57 @@ +/************************************************************************ + ** + ** @file saveplacelabeloptions.h + ** @author Roman Telezhynskyi + ** @date 16 10, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 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 SAVEPLACELABELOPTIONS_H +#define SAVEPLACELABELOPTIONS_H + +#include "vundocommand.h" +#include "../vgeometry/vplacelabelitem.h" + +class SavePlaceLabelOptions : public VUndoCommand +{ +public: + SavePlaceLabelOptions(const VPlaceLabelItem &oldLabel, const VPlaceLabelItem &newLabel, VAbstractPattern *doc, + VContainer *data, quint32 id, QUndoCommand *parent = nullptr); + virtual ~SavePlaceLabelOptions()=default; + + virtual void undo() Q_DECL_OVERRIDE; + virtual void redo() Q_DECL_OVERRIDE; + virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE; + virtual int id() const Q_DECL_OVERRIDE; + + quint32 LabelId() const; + VPlaceLabelItem NewLabel() const; +private: + Q_DISABLE_COPY(SavePlaceLabelOptions) + + const VPlaceLabelItem m_oldLabel; + VPlaceLabelItem m_newLabel; + + VContainer *m_data; +}; + +#endif // SAVEPLACELABELOPTIONS_H diff --git a/src/libs/vtools/undocommands/undocommands.pri b/src/libs/vtools/undocommands/undocommands.pri index 54fd83560..6ef724357 100644 --- a/src/libs/vtools/undocommands/undocommands.pri +++ b/src/libs/vtools/undocommands/undocommands.pri @@ -26,7 +26,8 @@ HEADERS += \ $$PWD/savepiecepathoptions.h \ $$PWD/label/showlabel.h \ $$PWD/label/showdoublelabel.h \ - $$PWD/label/operationshowlabel.h + $$PWD/label/operationshowlabel.h \ + $$PWD/saveplacelabeloptions.h SOURCES += \ $$PWD/addtocalc.cpp \ @@ -53,4 +54,5 @@ SOURCES += \ $$PWD/savepiecepathoptions.cpp \ $$PWD/label/showlabel.cpp \ $$PWD/label/showdoublelabel.cpp \ - $$PWD/label/operationshowlabel.cpp + $$PWD/label/operationshowlabel.cpp \ + $$PWD/saveplacelabeloptions.cpp diff --git a/src/libs/vtools/undocommands/vundocommand.cpp b/src/libs/vtools/undocommands/vundocommand.cpp index c3ec3f33c..2b43f96f1 100644 --- a/src/libs/vtools/undocommands/vundocommand.cpp +++ b/src/libs/vtools/undocommands/vundocommand.cpp @@ -80,7 +80,14 @@ void VUndoCommand::IncrementReferences(const QVector &nodes) const { for (qint32 i = 0; i < nodes.size(); ++i) { - doc->IncrementReferens(nodes.at(i)); + try + { + doc->IncrementReferens(nodes.at(i)); + } + catch (const VExceptionBadId &e) + { // ignoring + Q_UNUSED(e); + } } } @@ -89,7 +96,14 @@ void VUndoCommand::DecrementReferences(const QVector &nodes) const { for (qint32 i = 0; i < nodes.size(); ++i) { - doc->DecrementReferens(nodes.at(i)); + try + { + doc->DecrementReferens(nodes.at(i)); + } + catch (const VExceptionBadId &e) + { // ignoring + Q_UNUSED(e); + } } } diff --git a/src/libs/vtools/undocommands/vundocommand.h b/src/libs/vtools/undocommands/vundocommand.h index c25ebd722..b6a93c89b 100644 --- a/src/libs/vtools/undocommands/vundocommand.h +++ b/src/libs/vtools/undocommands/vundocommand.h @@ -52,6 +52,7 @@ enum class UndoCommand: char { AddPatternPiece, SaveDetailOptions, SavePieceOptions, SavePiecePathOptions, + SavePlaceLabelOptions, MovePiece, DeleteTool, DeletePatternPiece, diff --git a/src/libs/vtools/visualization/line/operation/visoperation.cpp b/src/libs/vtools/visualization/line/operation/visoperation.cpp index d9e108bc4..0dc0530d5 100644 --- a/src/libs/vtools/visualization/line/operation/visoperation.cpp +++ b/src/libs/vtools/visualization/line/operation/visoperation.cpp @@ -109,7 +109,7 @@ void VisOperation::RefreshFlippedObjects(const QPointF &firstPoint, const QPoint const QSharedPointer obj = Visualization::data->GetGObject(id); // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); switch(static_cast(obj->getType())) { @@ -161,6 +161,8 @@ void VisOperation::RefreshFlippedObjects(const QPointF &firstPoint, const QPoint break; } case GOType::Unknown: + case GOType::PlaceLabel: + Q_UNREACHABLE(); break; } } diff --git a/src/libs/vtools/visualization/line/operation/vistoolmove.cpp b/src/libs/vtools/visualization/line/operation/vistoolmove.cpp index 860609019..e6fcc7cfd 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolmove.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolmove.cpp @@ -224,7 +224,7 @@ QVector VisToolMove::CreateOriginObjects(int &iPoint, int &iCur const QSharedPointer obj = Visualization::data->GetGObject(id); // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); switch(static_cast(obj->getType())) { @@ -258,6 +258,8 @@ QVector VisToolMove::CreateOriginObjects(int &iPoint, int &iCur originObjects.append(AddOriginCurve(id, iCurve)); break; case GOType::Unknown: + case GOType::PlaceLabel: + Q_UNREACHABLE(); break; } } @@ -279,7 +281,7 @@ void VisToolMove::CreateMovedObjects(int &iPoint, int &iCurve, qreal length, qre const QSharedPointer obj = Visualization::data->GetGObject(id); // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects was handled."); + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects was handled."); switch(static_cast(obj->getType())) { @@ -311,6 +313,8 @@ void VisToolMove::CreateMovedObjects(int &iPoint, int &iCurve, qreal length, qre iCurve = AddMovedCurve(angle, length, id, iCurve); break; case GOType::Unknown: + case GOType::PlaceLabel: + Q_UNREACHABLE(); break; } } diff --git a/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp b/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp index 11a846f1c..152ab2958 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp @@ -131,7 +131,7 @@ void VisToolRotation::RefreshGeometry() const QSharedPointer obj = Visualization::data->GetGObject(id); // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects was handled."); + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects was handled."); switch(static_cast(obj->getType())) { @@ -184,6 +184,8 @@ void VisToolRotation::RefreshGeometry() break; } case GOType::Unknown: + case GOType::PlaceLabel: + Q_UNREACHABLE(); break; } } diff --git a/src/libs/vtools/visualization/line/vistoolpin.cpp b/src/libs/vtools/visualization/line/vistoolspecialpoint.cpp similarity index 90% rename from src/libs/vtools/visualization/line/vistoolpin.cpp rename to src/libs/vtools/visualization/line/vistoolspecialpoint.cpp index 5c009e21b..a1fea2291 100644 --- a/src/libs/vtools/visualization/line/vistoolpin.cpp +++ b/src/libs/vtools/visualization/line/vistoolspecialpoint.cpp @@ -26,18 +26,19 @@ ** *************************************************************************/ -#include "vistoolpin.h" +#include "vistoolspecialpoint.h" #include "../vwidgets/vsimplepoint.h" #include "../vgeometry/vpointf.h" #include "../vpatterndb/vcontainer.h" //--------------------------------------------------------------------------------------------------------------------- -VisToolPin::VisToolPin(const VContainer *data, QGraphicsItem *parent) +VisToolSpecialPoint::VisToolSpecialPoint(const VContainer *data, QGraphicsItem *parent) : VisLine(data, parent), m_point() { this->mainColor = Qt::red; this->setZValue(2);// Show on top real tool + this->setPen(QPen(Qt::NoPen)); m_point = new VSimplePoint(NULL_ID, mainColor); m_point->SetPointHighlight(true); @@ -47,7 +48,7 @@ VisToolPin::VisToolPin(const VContainer *data, QGraphicsItem *parent) } //--------------------------------------------------------------------------------------------------------------------- -VisToolPin::~VisToolPin() +VisToolSpecialPoint::~VisToolSpecialPoint() { if (not m_point.isNull()) { @@ -56,7 +57,7 @@ VisToolPin::~VisToolPin() } //--------------------------------------------------------------------------------------------------------------------- -void VisToolPin::RefreshGeometry() +void VisToolSpecialPoint::RefreshGeometry() { if (object1Id > NULL_ID) { diff --git a/src/libs/vtools/visualization/line/vistoolpin.h b/src/libs/vtools/visualization/line/vistoolspecialpoint.h similarity index 79% rename from src/libs/vtools/visualization/line/vistoolpin.h rename to src/libs/vtools/visualization/line/vistoolspecialpoint.h index 510cc76cb..866742171 100644 --- a/src/libs/vtools/visualization/line/vistoolpin.h +++ b/src/libs/vtools/visualization/line/vistoolspecialpoint.h @@ -26,26 +26,26 @@ ** *************************************************************************/ -#ifndef VISTOOLPIN_H -#define VISTOOLPIN_H +#ifndef VISTOOLSPECIALPOINT_H +#define VISTOOLSPECIALPOINT_H #include "visline.h" class VSimplePoint; -class VisToolPin : public VisLine +class VisToolSpecialPoint : public VisLine { Q_OBJECT public: - explicit VisToolPin(const VContainer *data, QGraphicsItem *parent = nullptr); - virtual ~VisToolPin(); + explicit VisToolSpecialPoint(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolSpecialPoint(); virtual void RefreshGeometry() Q_DECL_OVERRIDE; virtual int type() const Q_DECL_OVERRIDE {return Type;} - enum { Type = UserType + static_cast(Vis::ToolPin)}; + enum { Type = UserType + static_cast(Vis::ToolSpecialPoint)}; private: - Q_DISABLE_COPY(VisToolPin) + Q_DISABLE_COPY(VisToolSpecialPoint) QPointer m_point; }; -#endif // VISTOOLPIN_H +#endif // VISTOOLSPECIALPOINT_H diff --git a/src/libs/vtools/visualization/path/vispiecepins.cpp b/src/libs/vtools/visualization/path/vispiecespecialpoints.cpp similarity index 83% rename from src/libs/vtools/visualization/path/vispiecepins.cpp rename to src/libs/vtools/visualization/path/vispiecespecialpoints.cpp index 4b03645c6..dfae65144 100644 --- a/src/libs/vtools/visualization/path/vispiecepins.cpp +++ b/src/libs/vtools/visualization/path/vispiecespecialpoints.cpp @@ -26,48 +26,48 @@ ** *************************************************************************/ -#include "vispiecepins.h" +#include "vispiecespecialpoints.h" #include "../vwidgets/vsimplepoint.h" #include "../vgeometry/vpointf.h" #include "../vpatterndb/vcontainer.h" //--------------------------------------------------------------------------------------------------------------------- -VisPiecePins::VisPiecePins(const VContainer *data, QGraphicsItem *parent) +VisPieceSpecialPoints::VisPieceSpecialPoints(const VContainer *data, QGraphicsItem *parent) : VisPath(data, parent), m_points(), - m_pins() + m_spoints() { } //--------------------------------------------------------------------------------------------------------------------- -void VisPiecePins::RefreshGeometry() +void VisPieceSpecialPoints::RefreshGeometry() { HideAllItems(); - for (int i = 0; i < m_pins.size(); ++i) + for (int i = 0; i < m_spoints.size(); ++i) { VSimplePoint *point = GetPoint(static_cast(i), supportColor); point->SetOnlyPoint(false); - const QSharedPointer p = Visualization::data->GeometricObject(m_pins.at(i)); + const QSharedPointer p = Visualization::data->GeometricObject(m_spoints.at(i)); point->RefreshPointGeometry(*p); point->setVisible(true); } } //--------------------------------------------------------------------------------------------------------------------- -void VisPiecePins::SetPins(const QVector &pins) +void VisPieceSpecialPoints::SetPoints(const QVector &pins) { - m_pins = pins; + m_spoints = pins; } //--------------------------------------------------------------------------------------------------------------------- -VSimplePoint *VisPiecePins::GetPoint(quint32 i, const QColor &color) +VSimplePoint *VisPieceSpecialPoints::GetPoint(quint32 i, const QColor &color) { return VisPath::GetPoint(m_points, i, color); } //--------------------------------------------------------------------------------------------------------------------- -void VisPiecePins::HideAllItems() +void VisPieceSpecialPoints::HideAllItems() { for (int i=0; i < m_points.size(); ++i) { diff --git a/src/libs/vtools/visualization/path/vispiecepins.h b/src/libs/vtools/visualization/path/vispiecespecialpoints.h similarity index 75% rename from src/libs/vtools/visualization/path/vispiecepins.h rename to src/libs/vtools/visualization/path/vispiecespecialpoints.h index 9fe8d4ca6..de54da8c9 100644 --- a/src/libs/vtools/visualization/path/vispiecepins.h +++ b/src/libs/vtools/visualization/path/vispiecespecialpoints.h @@ -26,32 +26,32 @@ ** *************************************************************************/ -#ifndef VISPIECEPINS_H -#define VISPIECEPINS_H +#ifndef VISPIECESPECIALPOINTS_H +#define VISPIECESPECIALPOINTS_H #include "vispath.h" class VSimplePoint; -class VisPiecePins : public VisPath +class VisPieceSpecialPoints : public VisPath { Q_OBJECT public: - VisPiecePins(const VContainer *data, QGraphicsItem *parent = nullptr); - virtual ~VisPiecePins() Q_DECL_EQ_DEFAULT; + VisPieceSpecialPoints(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisPieceSpecialPoints() Q_DECL_EQ_DEFAULT; virtual void RefreshGeometry() Q_DECL_OVERRIDE; - void SetPins(const QVector &pins); + void SetPoints(const QVector &pins); virtual int type() const Q_DECL_OVERRIDE {return Type;} - enum { Type = UserType + static_cast(Vis::PiecePins)}; + enum { Type = UserType + static_cast(Vis::PieceSpecialPoints)}; private: - Q_DISABLE_COPY(VisPiecePins) + Q_DISABLE_COPY(VisPieceSpecialPoints) QVector m_points; - QVector m_pins; + QVector m_spoints; VSimplePoint *GetPoint(quint32 i, const QColor &color); void HideAllItems(); }; -#endif // VISPIECEPINS_H +#endif // VISPIECESPECIALPOINTS_H diff --git a/src/libs/vtools/visualization/visualization.pri b/src/libs/vtools/visualization/visualization.pri index 1f822647e..5f9aac564 100644 --- a/src/libs/vtools/visualization/visualization.pri +++ b/src/libs/vtools/visualization/visualization.pri @@ -41,8 +41,8 @@ HEADERS += \ $$PWD/path/vistoolellipticalarc.h \ $$PWD/path/vistoolpiece.h \ $$PWD/path/vistoolpiecepath.h \ - $$PWD/line/vistoolpin.h \ - $$PWD/path/vispiecepins.h + $$PWD/path/vispiecespecialpoints.h \ + $$PWD/line/vistoolspecialpoint.h SOURCES += \ $$PWD/visualization.cpp \ @@ -84,5 +84,5 @@ SOURCES += \ $$PWD/path/vistoolellipticalarc.cpp \ $$PWD/path/vistoolpiece.cpp \ $$PWD/path/vistoolpiecepath.cpp \ - $$PWD/line/vistoolpin.cpp \ - $$PWD/path/vispiecepins.cpp + $$PWD/path/vispiecespecialpoints.cpp \ + $$PWD/line/vistoolspecialpoint.cpp