diff --git a/src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp b/src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp index 6daefc9b0..0e873df21 100644 --- a/src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp +++ b/src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp @@ -234,18 +234,10 @@ QGroupBox *TapeConfigurationPage::PMSystemGroup() connect(systemCombo, static_cast(&QComboBox::currentIndexChanged), RECEIVER(this)[this]() { systemChanged = true; - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->itemData(systemCombo->currentIndex()).toString()); - #else - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->currentData().toString()); - #endif + QString text = qApp->TrVars()->PMSystemAuthor(CURRENT_DATA(systemCombo).toString()); systemAuthorValueLabel->setText(text); systemAuthorValueLabel->setToolTip(text); - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - text = qApp->TrVars()->PMSystemBook(systemCombo->itemData(systemCombo->currentIndex()).toString()); - #else - text = qApp->TrVars()->PMSystemBook(systemCombo->currentData().toString()); - #endif + text = qApp->TrVars()->PMSystemBook(CURRENT_DATA(systemCombo).toString()); systemBookValueLabel->setPlainText(text); }); @@ -337,18 +329,10 @@ void TapeConfigurationPage::RetranslateUi() systemAuthorLabel->setText(tr("Author:")); systemBookLabel->setText(tr("Book:")); -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->itemData(systemCombo->currentIndex()).toString()); -#else - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->currentData().toString()); -#endif + QString text = qApp->TrVars()->PMSystemAuthor(CURRENT_DATA(systemCombo).toString()); systemAuthorValueLabel->setText(text); systemAuthorValueLabel->setToolTip(text); -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - text = qApp->TrVars()->PMSystemBook(systemCombo->itemData(systemCombo->currentIndex()).toString()); -#else - text = qApp->TrVars()->PMSystemBook(systemCombo->currentData().toString()); -#endif + text = qApp->TrVars()->PMSystemBook(CURRENT_DATA(systemCombo).toString()); systemBookValueLabel->setPlainText(text); gradationGroup->setTitle(tr("Default height and size")); diff --git a/src/app/tape/dialogs/dialogexporttocsv.cpp b/src/app/tape/dialogs/dialogexporttocsv.cpp index 8164a437b..81a4b10c3 100644 --- a/src/app/tape/dialogs/dialogexporttocsv.cpp +++ b/src/app/tape/dialogs/dialogexporttocsv.cpp @@ -81,11 +81,7 @@ bool DialogExportToCSV::WithHeader() const //--------------------------------------------------------------------------------------------------------------------- int DialogExportToCSV::SelectedMib() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return ui->comboBoxCodec->itemData(ui->comboBoxCodec->currentIndex()).toInt(); -#else - return ui->comboBoxCodec->currentData().toInt(); -#endif + return CURRENT_DATA(ui->comboBoxCodec).toInt(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tape/dialogs/dialognewmeasurements.cpp b/src/app/tape/dialogs/dialognewmeasurements.cpp index 11dbfa6bf..59eab4922 100644 --- a/src/app/tape/dialogs/dialognewmeasurements.cpp +++ b/src/app/tape/dialogs/dialognewmeasurements.cpp @@ -80,21 +80,13 @@ DialogNewMeasurements::~DialogNewMeasurements() //--------------------------------------------------------------------------------------------------------------------- MeasurementsType DialogNewMeasurements::Type() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return static_cast(ui->comboBoxMType->itemData(ui->comboBoxMType->currentIndex()).toInt()); -#else - return static_cast(ui->comboBoxMType->currentData().toInt()); -#endif + return static_cast(CURRENT_DATA(ui->comboBoxMType).toInt()); } //--------------------------------------------------------------------------------------------------------------------- Unit DialogNewMeasurements::MUnit() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return static_cast(ui->comboBoxUnit->itemData(ui->comboBoxUnit->currentIndex()).toInt()); -#else - return static_cast(ui->comboBoxUnit->currentData().toInt()); -#endif + return static_cast(CURRENT_DATA(ui->comboBoxUnit).toInt()); } //--------------------------------------------------------------------------------------------------------------------- @@ -117,14 +109,7 @@ void DialogNewMeasurements::changeEvent(QEvent *event) // retranslate designer form (single inheritance approach) ui->retranslateUi(this); InitMTypes(); - - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const MeasurementsType type = - static_cast(ui->comboBoxMType->itemData(ui->comboBoxMType->currentIndex()).toInt()); - #else - const MeasurementsType type = static_cast(ui->comboBoxMType->currentData().toInt()); - #endif - InitUnits(type); + InitUnits(static_cast(CURRENT_DATA(ui->comboBoxMType).toInt())); } // remember to call base class implementation @@ -192,11 +177,7 @@ void DialogNewMeasurements::InitMTypes() int val = static_cast(MeasurementsType::Unknown); if (ui->comboBoxMType->currentIndex() != -1) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - val = ui->comboBoxMType->itemData(ui->comboBoxMType->currentIndex()).toInt(); - #else - val = ui->comboBoxMType->currentData().toInt(); - #endif + val = CURRENT_DATA(ui->comboBoxMType).toInt(); } ui->comboBoxMType->blockSignals(true); @@ -234,11 +215,7 @@ void DialogNewMeasurements::InitUnits(const MeasurementsType &type) int val = static_cast(Unit::Cm); if (ui->comboBoxUnit->currentIndex() != -1) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - val = ui->comboBoxUnit->itemData(ui->comboBoxUnit->currentIndex()).toInt(); - #else - val = ui->comboBoxUnit->currentData().toInt(); - #endif + val = CURRENT_DATA(ui->comboBoxUnit).toInt(); } ui->comboBoxUnit->blockSignals(true); diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 09e22849e..8e0e356bd 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -76,7 +76,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) == 51, "Not all tools were used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52, "Not all tools were used in switch."); switch (item->type()) { @@ -203,7 +203,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) == 51, "Not all tools were used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52, "Not all tools were used in switch."); switch (currentItem->type()) { @@ -348,7 +348,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) == 51, "Not all tools were used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52, "Not all tools were used in switch."); switch (currentItem->type()) { diff --git a/src/app/valentina/dialogs/configpages/configurationpage.cpp b/src/app/valentina/dialogs/configpages/configurationpage.cpp index 3290cf9a0..940ce3353 100644 --- a/src/app/valentina/dialogs/configpages/configurationpage.cpp +++ b/src/app/valentina/dialogs/configpages/configurationpage.cpp @@ -395,19 +395,11 @@ QGroupBox *ConfigurationPage::ToolBarGroup() void ConfigurationPage::SystemChanged() { systemChanged = true; -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->itemData(systemCombo->currentIndex()).toString()); -#else - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->currentData().toString()); -#endif + QString text = qApp->TrVars()->PMSystemAuthor(CURRENT_DATA(systemCombo).toString()); systemAuthorValueLabel->setText(text); systemAuthorValueLabel->setToolTip(text); -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - text = qApp->TrVars()->PMSystemBook(systemCombo->itemData(systemCombo->currentIndex()).toString()); -#else - text = qApp->TrVars()->PMSystemBook(systemCombo->currentData().toString()); -#endif + text = qApp->TrVars()->PMSystemBook(CURRENT_DATA(systemCombo).toString()); systemBookValueLabel->setPlainText(text); } @@ -470,18 +462,11 @@ void ConfigurationPage::RetranslateUi() systemAuthorLabel->setText(tr("Author:")); systemBookLabel->setText(tr("Book:")); -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->itemData(systemCombo->currentIndex()).toString()); -#else - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->currentData().toString()); -#endif + QString text = qApp->TrVars()->PMSystemAuthor(CURRENT_DATA(systemCombo).toString()); systemAuthorValueLabel->setText(text); systemAuthorValueLabel->setToolTip(text); -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - text = qApp->TrVars()->PMSystemBook(systemCombo->itemData(systemCombo->currentIndex()).toString()); -#else - text = qApp->TrVars()->PMSystemBook(systemCombo->currentData().toString()); -#endif + + text = qApp->TrVars()->PMSystemBook(CURRENT_DATA(systemCombo).toString()); systemBookValueLabel->setPlainText(text); sendGroup->setTitle(tr("Send crash reports")); diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index a168827b8..216fec813 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) == 51, "Not all tools were used in history."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52, "Not all tools were used in history."); const QDomElement domElem = doc->elementById(tool.getId()); if (domElem.isElement() == false) @@ -405,6 +405,7 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::FlippingByAxis: case Tool::Move: case Tool::PiecePath: + case Tool::Pin: return QString(); } } diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.cpp b/src/app/valentina/dialogs/dialoglayoutsettings.cpp index 0d808619e..27e9de1a3 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.cpp +++ b/src/app/valentina/dialogs/dialoglayoutsettings.cpp @@ -824,12 +824,7 @@ QString DialogLayoutSettings::MakeHelpTemplateList() QSizeF DialogLayoutSettings::Template() { PaperSizeTemplate temp; -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - temp = static_cast(ui->comboBoxTemplates->itemData(ui->comboBoxTemplates->currentIndex()) - .toInt()); -#else - temp = static_cast(ui->comboBoxTemplates->currentData().toInt()); -#endif + temp = static_cast(CURRENT_DATA(ui->comboBoxTemplates).toInt()); switch (temp) { @@ -981,23 +976,13 @@ QMarginsF DialogLayoutSettings::GetDefPrinterFields() const //--------------------------------------------------------------------------------------------------------------------- Unit DialogLayoutSettings::PaperUnit() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return VDomDocument::StrToUnits(ui->comboBoxPaperSizeUnit->itemData(ui->comboBoxPaperSizeUnit->currentIndex()) - .toString()); -#else - return VDomDocument::StrToUnits(ui->comboBoxPaperSizeUnit->currentData().toString()); -#endif + return VDomDocument::StrToUnits(CURRENT_DATA(ui->comboBoxPaperSizeUnit).toString()); } //--------------------------------------------------------------------------------------------------------------------- Unit DialogLayoutSettings::LayoutUnit() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return VDomDocument::StrToUnits(ui->comboBoxLayoutUnit->itemData(ui->comboBoxLayoutUnit->currentIndex()) - .toString()); -#else - return VDomDocument::StrToUnits(ui->comboBoxLayoutUnit->currentData().toString()); -#endif + return VDomDocument::StrToUnits(CURRENT_DATA(ui->comboBoxLayoutUnit).toString()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index 3644c4b69..5e5af70be 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -208,11 +208,7 @@ QString DialogSaveLayout::FileName() const //--------------------------------------------------------------------------------------------------------------------- QString DialogSaveLayout::Format() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return ui->comboBoxFormat->itemData(ui->comboBoxFormat->currentIndex()).toString(); -#else - return ui->comboBoxFormat->currentData().toString(); -#endif + return CURRENT_DATA(ui->comboBoxFormat).toString(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 1002c0065..0599d808b 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -53,6 +53,7 @@ #include "../vtools/dialogs/tooldialogs.h" #include "tools/vtoolseamallowance.h" #include "tools/nodeDetails/vtoolpiecepath.h" +#include "tools/nodeDetails/vtoolpin.h" #include "tools/vtooluniondetails.h" #include "dialogs/dialogs.h" #include "dialogs/vwidgetgroups.h" @@ -572,6 +573,7 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons dialogTool->Build(t); break; case Tool::PiecePath: + case Tool::Pin: dialogTool->SetPiecesList(doc->GetActivePPPieces()); break; default: @@ -991,6 +993,14 @@ void MainWindow::ToolPiecePath(bool checked) &MainWindow::ClosedDialogPiecePath); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolPin(bool checked) +{ + ToolSelectAllDrawObjects(); + SetToolButton(checked, Tool::Pin, "://cursor/pin_cursor.png", tr("Select pin point"), + &MainWindow::ClosedDialogPin); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ToolHeight handler tool height. @@ -1140,6 +1150,18 @@ void MainWindow::ClosedDialogPiecePath(int result) doc->LiteParseTree(Document::LiteParse); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ClosedDialogPin(int result) +{ + SCASSERT(dialogTool != nullptr); + if (result == QDialog::Accepted) + { + VToolPin::Create(dialogTool, doc, pattern); + } + ArrowTool(); + doc->LiteParseTree(Document::LiteParse); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ToolCutArc handler tool cutArc. @@ -1779,7 +1801,7 @@ void MainWindow::InitToolButtons() } // This check helps to find missed tools - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 51, "Check if all tools were connected."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52, "Check if all tools were connected."); connect(ui->toolButtonEndLine, &QToolButton::clicked, this, &MainWindow::ToolEndLine); connect(ui->toolButtonLine, &QToolButton::clicked, this, &MainWindow::ToolLine); @@ -1825,6 +1847,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonMidpoint, &QToolButton::clicked, this, &MainWindow::ToolMidpoint); connect(ui->toolButtonLayoutExportAs, &QToolButton::clicked, this, &MainWindow::ExportLayoutAs); connect(ui->toolButtonEllipticalArc, &QToolButton::clicked, this, &MainWindow::ToolEllipticalArc); + connect(ui->toolButtonPin, &QToolButton::clicked, this, &MainWindow::ToolPin); } //--------------------------------------------------------------------------------------------------------------------- @@ -1852,7 +1875,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) == 51, "Not all tools were handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52, "Not all tools were handled."); qCDebug(vMainWindow, "Canceling tool."); delete dialogTool; @@ -2008,6 +2031,9 @@ void MainWindow::CancelTool() case Tool::EllipticalArc: ui->toolButtonEllipticalArc->setChecked(false); break; + case Tool::Pin: + ui->toolButtonPin->setChecked(false); + break; } // Crash: using CRTL+Z while using line tool. @@ -2326,7 +2352,19 @@ void MainWindow::ActionLayout(bool checked) SaveCurrentScene(); - PrepareDetailsForLayout(&details); + try + { + PrepareDetailsForLayout(&details); + } + catch (VException &e) + { + listDetails.clear(); + QMessageBox::warning(this, tr("Layout mode"), + tr("You can't use now the Layout mode. \n%1").arg(e.ErrorMessage()), + QMessageBox::Ok, QMessageBox::Ok); + mode == Draw::Calculation ? ActionDraw(true) : ActionDetails(true); + return; + } currentScene = tempSceneLayout; ui->view->itemClicked(nullptr); @@ -3114,7 +3152,7 @@ void MainWindow::SetEnableTool(bool enable) } // This check helps to find missed tools - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 51, "Not all tools were handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52, "Not all tools were handled."); //Drawing Tools ui->toolButtonEndLine->setEnabled(drawTools); @@ -3155,6 +3193,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonMove->setEnabled(drawTools); ui->toolButtonMidpoint->setEnabled(drawTools); ui->toolButtonEllipticalArc->setEnabled(drawTools); + ui->toolButtonPin->setEnabled(drawTools); ui->actionLast_tool->setEnabled(drawTools); @@ -3436,7 +3475,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) == 51, "Not all tools were handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52, "Not all tools were handled."); if (currentTool == lastUsedTool) { @@ -3623,6 +3662,10 @@ void MainWindow::LastUsedTool() ui->toolButtonEllipticalArc->setChecked(true); ToolEllipticalArc(true); break; + case Tool::Pin: + ui->toolButtonPin->setChecked(true); + ToolPin(true); + break; } } diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index d6d27cf97..f5fed5834 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -137,6 +137,7 @@ private slots: void ToolPointOfContact(bool checked); void ToolDetail(bool checked); void ToolPiecePath(bool checked); + void ToolPin(bool checked); void ToolHeight(bool checked); void ToolTriangle(bool checked); void ToolPointOfIntersection(bool checked); @@ -170,6 +171,7 @@ private slots: void ClosedDialogUnionDetails(int result); void ClosedDialogGroup(int result); void ClosedDialogPiecePath(int result); + void ClosedDialogPin(int result); void LoadIndividual(); void LoadStandard(); diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index a094dc919..bb1dc0243 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -48,7 +48,7 @@ Tools - 5 + 6 @@ -1449,6 +1449,32 @@ + + + + false + + + Pin tool + + + ... + + + + :/toolicon/32x32/pin.png:/toolicon/32x32/pin.png + + + + 32 + 32 + + + + true + + + diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 47c2e94ff..ed2928768 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -37,9 +37,9 @@ #include "dialogs/dialoglayoutprogress.h" #include "dialogs/dialogsavelayout.h" #include "../vlayout/vposter.h" -#include "../vpatterndb/vpatternpiecedata.h" -#include "../vpatterndb/vpatterninfogeometry.h" -#include "../vpatterndb/vgrainlinegeometry.h" +#include "../vpatterndb/floatItemData/vpiecelabeldata.h" +#include "../vpatterndb/floatItemData/vpatternlabeldata.h" +#include "../vpatterndb/floatItemData/vgrainlinedata.h" #include "../vtools/tools/vabstracttool.h" #include diff --git a/src/app/valentina/share/resources/cursor.qrc b/src/app/valentina/share/resources/cursor.qrc index 44323cc41..4a3771e1c 100644 --- a/src/app/valentina/share/resources/cursor.qrc +++ b/src/app/valentina/share/resources/cursor.qrc @@ -80,5 +80,7 @@ cursor/el_arc_cursor@2x.png cursor/path_cursor.png cursor/path_cursor@2x.png + cursor/pin_cursor.png + cursor/pin_cursor@2x.png diff --git a/src/app/valentina/share/resources/cursor/pin_cursor.png b/src/app/valentina/share/resources/cursor/pin_cursor.png new file mode 100644 index 000000000..53e753cc1 Binary files /dev/null and b/src/app/valentina/share/resources/cursor/pin_cursor.png differ diff --git a/src/app/valentina/share/resources/cursor/pin_cursor@2x.png b/src/app/valentina/share/resources/cursor/pin_cursor@2x.png new file mode 100644 index 000000000..dfcf1c8ef Binary files /dev/null and b/src/app/valentina/share/resources/cursor/pin_cursor@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon.qrc b/src/app/valentina/share/resources/toolicon.qrc index 528ab18c2..0fd19e3bf 100644 --- a/src/app/valentina/share/resources/toolicon.qrc +++ b/src/app/valentina/share/resources/toolicon.qrc @@ -78,5 +78,7 @@ toolicon/32x32/el_arc@2x.png toolicon/32x32/path.png toolicon/32x32/path@2x.png + toolicon/32x32/pin.png + toolicon/32x32/pin@2x.png diff --git a/src/app/valentina/share/resources/toolicon/32x32/pin.png b/src/app/valentina/share/resources/toolicon/32x32/pin.png new file mode 100644 index 000000000..baf52a929 Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/pin.png differ diff --git a/src/app/valentina/share/resources/toolicon/32x32/pin@2x.png b/src/app/valentina/share/resources/toolicon/32x32/pin@2x.png new file mode 100644 index 000000000..859002f9a Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/pin@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon/svg/pin.svg b/src/app/valentina/share/resources/toolicon/svg/pin.svg new file mode 100644 index 000000000..efee98b4c --- /dev/null +++ b/src/app/valentina/share/resources/toolicon/svg/pin.svg @@ -0,0 +1,81 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 44e9d964e..b38fe5a81 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -51,9 +51,9 @@ #include "../core/vapplication.h" #include "../vpatterndb/vpiecenode.h" #include "../vpatterndb/calculator.h" -#include "../vpatterndb/vpatternpiecedata.h" -#include "../vpatterndb/vpatterninfogeometry.h" -#include "../vpatterndb/vgrainlinegeometry.h" +#include "../vpatterndb/floatItemData/vpiecelabeldata.h" +#include "../vpatterndb/floatItemData/vpatternlabeldata.h" +#include "../vpatterndb/floatItemData/vgrainlinedata.h" #include "../vpatterndb/vpiecepath.h" #include "../vpatterndb/vnodedetail.h" @@ -717,7 +717,8 @@ void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse << TagPatternInfo << TagGrainline << VToolSeamAllowance::TagCSA - << VToolSeamAllowance::TagIPaths; + << VToolSeamAllowance::TagIPaths + << VToolSeamAllowance::TagPins; const QDomNodeList nodeList = domElement.childNodes(); for (qint32 i = 0; i < nodeList.size(); ++i) @@ -757,6 +758,9 @@ void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse case 5:// VToolSeamAllowance::TagIPaths detail.SetInternalPaths(ParsePieceInternalPaths(element)); break; + case 6:// VToolSeamAllowance::TagPins + detail.SetPins(ParsePiecePins(element)); + break; default: break; } @@ -824,6 +828,12 @@ void VPattern::ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) qreal dRot = GetParametrDouble(domElement, AttrRotation, "0"); detail.GetPatternPieceData().SetRotation(dRot); + const quint32 topLeftPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR); + detail.GetPatternPieceData().SetTopLeftPin(topLeftPin); + + const quint32 bottomRightPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR); + detail.GetPatternPieceData().SetBottomRightPin(bottomRightPin); + QDomNodeList nodeListMCP = domElement.childNodes(); for (int iMCP = 0; iMCP < nodeListMCP.count(); ++iMCP) { @@ -856,6 +866,12 @@ void VPattern::ParsePiecePatternInfo(const QDomElement &domElement, VPiece &deta detail.GetPatternInfo().SetFontSize(iFS); qreal dRot = GetParametrDouble(domElement, AttrRotation, "0"); detail.GetPatternInfo().SetRotation(dRot); + + const quint32 topLeftPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR); + detail.GetPatternInfo().SetTopLeftPin(topLeftPin); + + const quint32 bottomRightPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR); + detail.GetPatternInfo().SetBottomRightPin(bottomRightPin); } //--------------------------------------------------------------------------------------------------------------------- @@ -870,9 +886,14 @@ void VPattern::ParsePieceGrainline(const QDomElement &domElement, VPiece &detail detail.GetGrainlineGeometry().SetLength(qsLength); QString qsRot = GetParametrString(domElement, AttrRotation, "90"); detail.GetGrainlineGeometry().SetRotation(qsRot); - VGrainlineGeometry::ArrowType eAT = - VGrainlineGeometry::ArrowType(GetParametrUInt(domElement, AttrArrows, "0")); + ArrowType eAT = static_cast(GetParametrUInt(domElement, AttrArrows, "0")); detail.GetGrainlineGeometry().SetArrowType(eAT); + + const quint32 topPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrTopPin, NULL_ID_STR); + detail.GetGrainlineGeometry().SetTopPin(topPin); + + const quint32 bottomPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomPin, NULL_ID_STR); + detail.GetGrainlineGeometry().SetBottomPin(bottomPin); } //--------------------------------------------------------------------------------------------------------------------- @@ -963,7 +984,8 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem << VToolPointFromCircleAndTangent::ToolType /*19*/ << VToolPointFromArcAndTangent::ToolType /*20*/ << VToolTrueDarts::ToolType /*21*/ - << VToolPointOfIntersectionCurves::ToolType; /*22*/ + << VToolPointOfIntersectionCurves::ToolType /*22*/ + << VToolPin::ToolType; /*23*/ switch (points.indexOf(type)) { case 0: //VToolBasePoint::ToolType @@ -1035,6 +1057,9 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem case 22: //VToolPointOfIntersectionCurves::ToolType ParseToolPointOfIntersectionCurves(scene, domElement, parse); break; + case 23: //VToolPin::ToolType + ParsePinPoint(domElement, parse); + break; default: VException e(tr("Unknown point type '%1'.").arg(type)); throw e; @@ -1536,6 +1561,28 @@ void VPattern::ParseNodePoint(const QDomElement &domElement, const Document &par } } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParsePinPoint(const QDomElement &domElement, const Document &parse) +{ + Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); + + try + { + quint32 id = 0; + + ToolsCommonAttributes(domElement, id); + const quint32 idObject = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); + const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); + VToolPin::Create(id, idObject, NULL_ID, this, data, parse, Source::FromFile, "", idTool); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating pin point"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } +} + //--------------------------------------------------------------------------------------------------------------------- void VPattern::ParseToolHeight(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse) { @@ -3726,7 +3773,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) == 51, "Not all tools were used."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52, "Not all tools were used."); QRectF rec; @@ -3860,6 +3907,7 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::NodeSplinePath: case Tool::Group: case Tool::PiecePath: + case Tool::Pin: break; } } diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 8324f1b8f..7ad603a47 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -166,6 +166,7 @@ private: void ParseToolLineIntersect(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); 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 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/exception/vexception.cpp b/src/libs/ifc/exception/vexception.cpp index 019b88f4f..dceacbbe7 100644 --- a/src/libs/ifc/exception/vexception.cpp +++ b/src/libs/ifc/exception/vexception.cpp @@ -73,7 +73,7 @@ VException &VException::operator=(const VException &e) */ QString VException::ErrorMessage() const { - return QString("Exception: %1").arg(error); + return tr("Exception: %1").arg(error); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index cd7354cea..95b4fe6f2 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -25,6 +25,7 @@ schema/pattern/v0.3.9.xsd schema/pattern/v0.4.0.xsd schema/pattern/v0.4.1.xsd + schema/pattern/v0.4.2.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.4.2.xsd b/src/libs/ifc/schema/pattern/v0.4.2.xsd new file mode 100644 index 000000000..7d9e8030e --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.4.2.xsd @@ -0,0 +1,860 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index af913858e..64abed537 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -639,6 +639,26 @@ QVector VAbstractPattern::ParsePieceInternalPaths(const QDomElement &do return records; } +//--------------------------------------------------------------------------------------------------------------------- +QVector VAbstractPattern::ParsePiecePins(const QDomElement &domElement) +{ + QVector records; + const QDomNodeList nodeList = domElement.childNodes(); + for (qint32 i = 0; i < nodeList.size(); ++i) + { + const QDomElement element = nodeList.at(i).toElement(); + if (not element.isNull()) + { + const quint32 path = element.text().toUInt(); + if (path > NULL_ID) + { + records.append(path); + } + } + } + return records; +} + //--------------------------------------------------------------------------------------------------------------------- VPieceNode VAbstractPattern::ParseSANode(const QDomElement &domElement) { @@ -1628,7 +1648,7 @@ QStringList 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) == 51); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52); QStringList expressions; const QDomNodeList list = elementsByTagName(TagPoint); @@ -1700,7 +1720,7 @@ QStringList 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) == 51); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52); QStringList expressions; const QDomNodeList list = elementsByTagName(TagArc); @@ -1754,7 +1774,7 @@ QStringList 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) == 51); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52); QStringList expressions; const QDomNodeList list = elementsByTagName(TagElArc); @@ -1825,7 +1845,7 @@ QStringList 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) == 51); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52); QStringList expressions; const QDomNodeList list = elementsByTagName(AttrPathPoint); @@ -1892,7 +1912,7 @@ QStringList 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) == 51); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52); QStringList expressions; const QDomNodeList list = elementsByTagName(TagOperation); @@ -1947,7 +1967,7 @@ QStringList 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) == 51); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52); QStringList expressions; const QDomNodeList list = elementsByTagName(TagPath); @@ -2000,7 +2020,7 @@ QStringList 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) == 51); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 52); QStringList expressions; const QDomNodeList list = elementsByTagName(TagDetail); diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 672f38845..3e221ab73 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -99,6 +99,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); void AddToolOnRemove(VDataTool *tool); diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 2d44c09cb..4b8f40465 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.4.1"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.4.1.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.4.2"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.4.2.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -200,6 +200,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000400): return QStringLiteral("://schema/pattern/v0.4.0.xsd"); case (0x000401): + return QStringLiteral("://schema/pattern/v0.4.1.xsd"); + case (0x000402): return CurrentSchema; default: InvalidVersion(ver); @@ -309,6 +311,10 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(0x000401), m_convertedFileName); V_FALLTHROUGH case (0x000401): + ToV0_4_2(); + ValidateXML(XSDSchema(0x000402), m_convertedFileName); + V_FALLTHROUGH + case (0x000402): break; default: InvalidVersion(m_ver); @@ -327,7 +333,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, 4, 1), + Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 4, 2), "Check attribute readOnly."); // Possibly in future attribute readOnly will change position etc. @@ -621,6 +627,17 @@ void VPatternConverter::ToV0_4_1() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_4_2() +{ + // TODO. Delete if minimal supported version is 0.4.2 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 2), + "Time to refactor the code."); + + SetVersion(QStringLiteral("0.4.2")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index f6348ba60..82636f2b5 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -55,10 +55,10 @@ public: // GCC 4.6 doesn't allow constexpr and const together #if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) <= 406 static Q_DECL_CONSTEXPR int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 1); + static Q_DECL_CONSTEXPR int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 2); #else static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 1); + static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 2); #endif protected: @@ -102,6 +102,7 @@ private: void ToV0_3_9(); void ToV0_4_0(); void ToV0_4_1(); + void ToV0_4_2(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index 4d9eeadd0..f99f17011 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -43,11 +43,12 @@ #include #include -#include "../vpatterndb/vpatterninfogeometry.h" -#include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/floatItemData/vpatternlabeldata.h" +#include "../vpatterndb/floatItemData/vpiecelabeldata.h" #include "../vmisc/vmath.h" #include "../vmisc/vabstractapplication.h" #include "../vpatterndb/calculator.h" +#include "../vgeometry/vpointf.h" #include "vlayoutdef.h" #include "vlayoutpiece_p.h" #include "vtextmanager.h" @@ -55,8 +56,11 @@ namespace { +//--------------------------------------------------------------------------------------------------------------------- QVector ConvertInternalPaths(const VPiece &piece, const VContainer *pattern) { + SCASSERT(pattern != nullptr) + QVector paths; const QVector pathsId = piece.GetInternalPaths(); for (int i = 0; i < pathsId.size(); ++i) @@ -69,6 +73,200 @@ QVector ConvertInternalPaths(const VPiece &piece, const VConta } return paths; } + +//--------------------------------------------------------------------------------------------------------------------- +void FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pattern, qreal &labelWidth, + qreal &labelHeight, QPointF &pos) +{ + SCASSERT(pattern != nullptr) + + const quint32 topLeftPin = labelData.TopLeftPin(); + const quint32 bottomRightPin = labelData.BottomRightPin(); + + if (topLeftPin != NULL_ID && bottomRightPin != NULL_ID) + { + try + { + const auto topLeftPinPoint = pattern->GeometricObject(topLeftPin); + const auto bottomRightPinPoint = pattern->GeometricObject(bottomRightPin); + + const QRectF labelRect = QRectF(*topLeftPinPoint, *bottomRightPinPoint); + labelWidth = qAbs(labelRect.width()); + labelHeight = qAbs(labelRect.height()); + + pos = labelRect.topLeft(); + + return; + } + catch(const VExceptionBadId &) + { + // do nothing. + } + } + + labelWidth = labelData.GetLabelWidth(); + labelHeight = labelData.GetLabelHeight(); + pos = labelData.GetPos(); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool FindGrainlineGeometry(const VGrainlineData& geom, const VContainer *pattern, qreal &length, qreal &rotationAngle, + QPointF &pos) +{ + SCASSERT(pattern != nullptr) + + const quint32 topPin = geom.TopPin(); + const quint32 bottomPin = geom.BottomPin(); + + if (topPin != NULL_ID && bottomPin != NULL_ID) + { + try + { + const auto topPinPoint = pattern->GeometricObject(topPin); + const auto bottomPinPoint = pattern->GeometricObject(bottomPin); + + QLineF grainline(*bottomPinPoint, *topPinPoint); + length = grainline.length(); + rotationAngle = grainline.angle(); + + if (not VFuzzyComparePossibleNulls(rotationAngle, 0)) + { + grainline.setAngle(0); + } + + pos = grainline.p1(); + rotationAngle = qDegreesToRadians(rotationAngle); + + return true; + } + catch(const VExceptionBadId &) + { + // do nothing. + } + } + + try + { + Calculator cal1; + rotationAngle = cal1.EvalFormula(pattern->PlainVariables(), geom.GetRotation()); + rotationAngle = qDegreesToRadians(rotationAngle); + + Calculator cal2; + length = cal2.EvalFormula(pattern->PlainVariables(), geom.GetLength()); + length = ToPixel(length, *pattern->GetPatternUnit()); + } + catch(qmu::QmuParserError &e) + { + Q_UNUSED(e); + return false; + } + + pos = geom.GetPos(); + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool IsItemContained(const QRectF &parentBoundingRect, const QVector &shape, qreal &dX, qreal &dY) +{ + dX = 0; + dY = 0; + // single point differences + bool bInside = true; + + for (int i = 0; i < shape.size(); ++i) + { + qreal dPtX = 0; + qreal dPtY = 0; + if (not parentBoundingRect.contains(shape.at(i))) + { + if (shape.at(i).x() < parentBoundingRect.left()) + { + dPtX = parentBoundingRect.left() - shape.at(i).x(); + } + else if (shape.at(i).x() > parentBoundingRect.right()) + { + dPtX = parentBoundingRect.right() - shape.at(i).x(); + } + + if (shape.at(i).y() < parentBoundingRect.top()) + { + dPtY = parentBoundingRect.top() - shape.at(i).y(); + } + else if (shape.at(i).y() > parentBoundingRect.bottom()) + { + dPtY = parentBoundingRect.bottom() - shape.at(i).y(); + } + + if (fabs(dPtX) > fabs(dX)) + { + dX = dPtX; + } + + if (fabs(dPtY) > fabs(dY)) + { + dY = dPtY; + } + + bInside = false; + } + } + return bInside; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector CorrectPosition(const QRectF &parentBoundingRect, QVector points) +{ + qreal dX = 0; + qreal dY = 0; + if (not IsItemContained(parentBoundingRect, points, dX, dY)) + { + for (int i =0; i < points.size(); ++i) + { + points[i] = QPointF(points.at(i).x() + dX, points.at(i).y() + dY); + } + } + return points; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector RoundPoints(const QVector &points) +{ + QVector p; + for (int i=0; i < points.size(); ++i) + { + p.append(QPointF(qRound(points.at(i).x()), qRound(points.at(i).y()))); + } + return p; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector PrepareAllowance(const QVector &points) +{ + QVector allowancePoints; + for(int i = 0; i < points.size(); ++i) + { + allowancePoints.append(VSAPoint(points.at(i))); + } + return allowancePoints; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VLayoutDetail::RotatePoint rotates a point around the center for given angle + * @param ptCenter center around which the point is rotated + * @param pt point, which is rotated around the center + * @param dAng angle of rotation + * @return position of point pt after rotating it around the center for dAng radians + */ +QPointF RotatePoint(const QPointF &ptCenter, const QPointF& pt, qreal dAng) +{ + QPointF ptDest; + QPointF ptRel = pt - ptCenter; + ptDest.setX(cos(dAng)*ptRel.x() - sin(dAng)*ptRel.y()); + ptDest.setY(sin(dAng)*ptRel.x() + cos(dAng)*ptRel.y()); + + return ptDest + ptCenter; +} } //--------------------------------------------------------------------------------------------------------------------- @@ -106,24 +304,33 @@ VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern det.SetInternalPaths(ConvertInternalPaths(piece, pattern)); det.SetName(piece.GetName()); - const VPatternPieceData& data = piece.GetPatternPieceData(); + + // Very important to set main path first! + if (det.ContourPath().isEmpty()) + { + throw VException (tr("Piece %1 doesn't have shape.").arg(piece.GetName())); + } + + const VPieceLabelData& data = piece.GetPatternPieceData(); if (data.IsVisible() == true) { - det.SetDetail(piece.GetName(), data, qApp->font()); + det.SetDetail(piece.GetName(), data, qApp->font(), pattern); } - const VPatternInfoGeometry& geom = piece.GetPatternInfo(); + + const VPatternLabelData& geom = piece.GetPatternInfo(); if (geom.IsVisible() == true) { VAbstractPattern* pDoc = qApp->getCurrentDocument(); - det.SetPatternInfo(pDoc, geom, qApp->font(), pattern->size(), pattern->height()); + det.SetPatternInfo(pDoc, geom, qApp->font(), pattern->size(), pattern->height(), pattern); } - const VGrainlineGeometry& grainlineGeom = piece.GetGrainlineGeometry(); + + const VGrainlineData& grainlineGeom = piece.GetGrainlineGeometry(); if (grainlineGeom.IsVisible() == true) { - det.SetGrainline(grainlineGeom, *pattern); + det.SetGrainline(grainlineGeom, pattern); } + det.SetSAWidth(qApp->toPixel(piece.GetSAWidth())); - det.CreateTextItems(); det.SetForbidFlipping(piece.IsForbidFlipping()); return det; @@ -175,21 +382,29 @@ QVector VLayoutPiece::GetLayoutAllowancePoints() const } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutPiece::SetDetail(const QString& qsName, const VPatternPieceData& data, const QFont &font) +void VLayoutPiece::SetDetail(const QString& qsName, const VPieceLabelData& data, const QFont &font, + const VContainer *pattern) { - d->detailData = data; - qreal dAng = qDegreesToRadians(data.GetRotation()); - QPointF ptCenter(data.GetPos().x() + data.GetLabelWidth()/2, data.GetPos().y() + data.GetLabelHeight()/2); - QPointF ptPos = data.GetPos(); + QPointF ptPos; + qreal labelWidth = 0; + qreal labelHeight = 0; + FindLabelGeometry(data, pattern, labelWidth, labelHeight, ptPos); + QVector v; - v << ptPos << QPointF(ptPos.x() + data.GetLabelWidth(), ptPos.y()) - << QPointF(ptPos.x() + data.GetLabelWidth(), ptPos.y() + data.GetLabelHeight()) - << QPointF(ptPos.x(), ptPos.y() + data.GetLabelHeight()); + v << ptPos + << QPointF(ptPos.x() + labelWidth, ptPos.y()) + << QPointF(ptPos.x() + labelWidth, ptPos.y() + labelHeight) + << QPointF(ptPos.x(), ptPos.y() + labelHeight); + + const qreal dAng = qDegreesToRadians(data.GetRotation()); + const QPointF ptCenter(ptPos.x() + labelWidth/2, ptPos.y() + labelHeight/2); for (int i = 0; i < v.count(); ++i) { v[i] = RotatePoint(ptCenter, v.at(i), dAng); } - d->detailLabel = RoundPoints(v); + + QScopedPointer item(GetMainItem()); + d->detailLabel = CorrectPosition(item->boundingRect(), RoundPoints(v)); // generate text d->m_tmDetail.SetFont(font); @@ -197,26 +412,32 @@ void VLayoutPiece::SetDetail(const QString& qsName, const VPatternPieceData& dat d->m_tmDetail.Update(qsName, data); // this will generate the lines of text d->m_tmDetail.SetFontSize(data.GetFontSize()); - d->m_tmDetail.FitFontSize(data.GetLabelWidth(), data.GetLabelHeight()); + d->m_tmDetail.FitFontSize(labelWidth, labelHeight); } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutPiece::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternInfoGeometry& geom, const QFont &font, - qreal dSize, qreal dHeight) +void VLayoutPiece::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLabelData& geom, const QFont &font, + qreal dSize, qreal dHeight, const VContainer *pattern) { - d->patternGeom = geom; - qreal dAng = qDegreesToRadians(geom.GetRotation()); - QPointF ptCenter(geom.GetPos().x() + geom.GetLabelWidth()/2, geom.GetPos().y() + geom.GetLabelHeight()/2); - QPointF ptPos = geom.GetPos(); + QPointF ptPos; + qreal labelWidth = 0; + qreal labelHeight = 0; + FindLabelGeometry(geom, pattern, labelWidth, labelHeight, ptPos); + QVector v; - v << ptPos << QPointF(ptPos.x() + geom.GetLabelWidth(), ptPos.y()) - << QPointF(ptPos.x() + geom.GetLabelWidth(), ptPos.y() + geom.GetLabelHeight()) - << QPointF(ptPos.x(), ptPos.y() + geom.GetLabelHeight()); + v << ptPos + << QPointF(ptPos.x() + labelWidth, ptPos.y()) + << QPointF(ptPos.x() + labelWidth, ptPos.y() + labelHeight) + << QPointF(ptPos.x(), ptPos.y() + labelHeight); + + const qreal dAng = qDegreesToRadians(geom.GetRotation()); + const QPointF ptCenter(ptPos.x() + labelWidth/2, ptPos.y() + labelHeight/2); for (int i = 0; i < v.count(); ++i) { v[i] = RotatePoint(ptCenter, v.at(i), dAng); } - d->patternInfo = RoundPoints(v); + QScopedPointer item(GetMainItem()); + d->patternInfo = CorrectPosition(item->boundingRect(), RoundPoints(v)); // Generate text d->m_tmPattern.SetFont(font); @@ -226,75 +447,50 @@ void VLayoutPiece::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternIn // generate lines of text d->m_tmPattern.SetFontSize(geom.GetFontSize()); - d->m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight()); + d->m_tmPattern.FitFontSize(labelWidth, labelHeight); } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutPiece::SetGrainline(const VGrainlineGeometry& geom, const VContainer& rPattern) +void VLayoutPiece::SetGrainline(const VGrainlineData& geom, const VContainer* pattern) { - d->grainlineGeom = geom; - qreal dAng; - qreal dLen; + SCASSERT(pattern != nullptr) - try + QPointF pt1; + qreal dAng = 0; + qreal dLen = 0; + if ( not FindGrainlineGeometry(geom, pattern, dLen, dAng, pt1)) { - QString qsFormula = geom.GetRotation().replace("\n", " "); - qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); - Calculator cal1; - dAng = cal1.EvalFormula(rPattern.PlainVariables(), qsFormula); - dAng = qDegreesToRadians(dAng); - - qsFormula = geom.GetLength().replace("\n", " "); - qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); - Calculator cal2; - dLen = cal2.EvalFormula(rPattern.PlainVariables(), qsFormula); - dLen = ToPixel(dLen, *rPattern.GetPatternUnit()); - } - catch(qmu::QmuParserError &e) - { - Q_UNUSED(e); return; } - QPointF pt1 = geom.GetPos(); - QPointF pt2; - pt2.setX(pt1.x() + dLen * qCos(dAng)); - pt2.setY(pt1.y() - dLen * qSin(dAng)); + QPointF pt2(pt1.x() + dLen * qCos(dAng), pt1.y() - dLen * qSin(dAng)); QVector v; - QPointF pt; - qreal dArrowLen = ToPixel(0.5, *rPattern.GetPatternUnit()); - qreal dArrowAng = M_PI/9; + + const qreal dArrowLen = ToPixel(0.5, *pattern->GetPatternUnit()); + const qreal dArrowAng = M_PI/9; v << pt1; - if (geom.GetArrowType() != VGrainlineGeometry::atRear) { - pt.setX(pt1.x() + dArrowLen * qCos(dAng + dArrowAng)); - pt.setY(pt1.y() - dArrowLen * qSin(dAng + dArrowAng)); - v << pt; - pt.setX(pt1.x() + dArrowLen * qCos(dAng - dArrowAng)); - pt.setY(pt1.y() - dArrowLen * qSin(dAng - dArrowAng)); - v << pt; - + if (geom.GetArrowType() != ArrowType::atRear) + { + v << QPointF(pt1.x() + dArrowLen * qCos(dAng + dArrowAng), pt1.y() - dArrowLen * qSin(dAng + dArrowAng)); + v << QPointF(pt1.x() + dArrowLen * qCos(dAng - dArrowAng), pt1.y() - dArrowLen * qSin(dAng - dArrowAng)); v << pt1; } v << pt2; - if (geom.GetArrowType() != VGrainlineGeometry::atFront) + if (geom.GetArrowType() != ArrowType::atFront) { dAng += M_PI; - pt.setX(pt2.x() + dArrowLen * qCos(dAng + dArrowAng)); - pt.setY(pt2.y() - dArrowLen * qSin(dAng + dArrowAng)); - v << pt; - pt.setX(pt2.x() + dArrowLen * qCos(dAng - dArrowAng)); - pt.setY(pt2.y() - dArrowLen * qSin(dAng - dArrowAng)); - v << pt; - + v << QPointF(pt2.x() + dArrowLen * qCos(dAng + dArrowAng), pt2.y() - dArrowLen * qSin(dAng + dArrowAng)); + v << QPointF(pt2.x() + dArrowLen * qCos(dAng - dArrowAng), pt2.y() - dArrowLen * qSin(dAng - dArrowAng)); v << pt2; } - d->grainlinePoints = RoundPoints(v); + QScopedPointer item(GetMainItem()); + d->grainlinePoints = CorrectPosition(item->boundingRect(), RoundPoints(v)); } //--------------------------------------------------------------------------------------------------------------------- @@ -543,17 +739,6 @@ QVector VLayoutPiece::Map(const QVector &points) const return p; } -//--------------------------------------------------------------------------------------------------------------------- -QVector VLayoutPiece::RoundPoints(const QVector &points) -{ - QVector p; - for (int i=0; i < points.size(); ++i) - { - p.append(QPointF(qRound(points.at(i).x()), qRound(points.at(i).y()))); - } - return p; -} - //--------------------------------------------------------------------------------------------------------------------- QPainterPath VLayoutPiece::ContourPath() const { @@ -592,133 +777,6 @@ QPainterPath VLayoutPiece::ContourPath() const return path; } -//--------------------------------------------------------------------------------------------------------------------- -void VLayoutPiece::ClearTextItems() -{ - d->m_liPP.clear(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VLayoutPiece::CreateTextItems() -{ - ClearTextItems(); - // first add detail texts - if (d->detailLabel.count() > 0) - { - // get the mapped label vertices - QVector points = Map(Mirror(d->detailLabel)); - // append the first point to obtain the closed rectangle - points.push_back(points.at(0)); - // calculate the angle of rotation - qreal dAng = qAtan2(points.at(1).y() - points.at(0).y(), points.at(1).x() - points.at(0).x()); - // calculate the label width and height - qreal dW = GetDistance(points.at(0), points.at(1)); - qreal dH = GetDistance(points.at(1), points.at(2)); - qreal dY = 0; - qreal dX; - // set up the rotation around top-left corner matrix - QMatrix mat; - mat.translate(points.at(0).x(), points.at(0).y()); - mat.rotate(qRadiansToDegrees(dAng)); - - for (int i = 0; i < d->m_tmDetail.GetSourceLinesCount(); ++i) - { - const TextLine& tl = d->m_tmDetail.GetSourceLine(i); - QFont fnt = d->m_tmDetail.GetFont(); - fnt.setPixelSize(d->m_tmDetail.GetFont().pixelSize() + tl.m_iFontSize); - fnt.setWeight(tl.m_eFontWeight); - fnt.setStyle(tl.m_eStyle); - - QFontMetrics fm(fnt); - - dY += fm.height(); - // check if the next line will go out of bounds - if (dY > dH) - { - break; - } - - QString qsText = tl.m_qsText; - if (fm.width(qsText) > dW) - { - qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast(dW)); - } - // find the correct horizontal offset, depending on the alignment flag - if ((tl.m_eAlign & Qt::AlignLeft) > 0) - { - dX = 0; - } - else if ((tl.m_eAlign & Qt::AlignHCenter) > 0) - { - dX = (dW - fm.width(qsText))/2; - } - else - { - dX = dW - fm.width(qsText); - } - // create text path and add it to the list - QPainterPath path; - path.addText(dX, dY - (fm.height() - fm.ascent())/2, fnt, qsText); - d->m_liPP << mat.map(path); - dY += d->m_tmDetail.GetSpacing(); - } - } - // and then add pattern texts - if (d->patternInfo.count() > 0) - { - // similar approach like for the detail label - QVector points = Map(Mirror(d->patternInfo)); - points.push_back(points.at(0)); - qreal dAng = qAtan2(points.at(1).y() - points.at(0).y(), points.at(1).x() - points.at(0).x()); - qreal dW = GetDistance(points.at(0), points.at(1)); - qreal dH = GetDistance(points.at(1), points.at(2)); - qreal dY = 0; - qreal dX; - QMatrix mat; - mat.translate(points.at(0).x(), points.at(0).y()); - mat.rotate(qRadiansToDegrees(dAng)); - - for (int i = 0; i < d->m_tmPattern.GetSourceLinesCount(); ++i) - { - const TextLine& tl = d->m_tmPattern.GetSourceLine(i); - QFont fnt = d->m_tmPattern.GetFont(); - fnt.setPixelSize(d->m_tmPattern.GetFont().pixelSize() + tl.m_iFontSize); - fnt.setWeight(tl.m_eFontWeight); - fnt.setStyle(tl.m_eStyle); - - QFontMetrics fm(fnt); - - dY += fm.height(); - if (dY > dH) - { - break; - } - - QString qsText = tl.m_qsText; - if (fm.width(qsText) > dW) - { - qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast(dW)); - } - if ((tl.m_eAlign & Qt::AlignLeft) > 0) - { - dX = 0; - } - else if ((tl.m_eAlign & Qt::AlignHCenter) > 0) - { - dX = (dW - fm.width(qsText))/2; - } - else - { - dX = dW - fm.width(qsText); - } - QPainterPath path; - path.addText(dX, dY - (fm.height() - fm.ascent())/2, fnt, qsText); - d->m_liPP << mat.map(path); - dY += d->m_tmPattern.GetSpacing(); - } - } -} - //--------------------------------------------------------------------------------------------------------------------- void VLayoutPiece::CreateInternalPathItem(int i, QGraphicsItem *parent) const { @@ -732,52 +790,16 @@ void VLayoutPiece::CreateInternalPathItem(int i, QGraphicsItem *parent) const } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief CreateTextItem Creates the i-th text item - * @param i index of the requested item - * @param parent parent of this text item. Can't be null. - */ -void VLayoutPiece::CreateTextItem(int i, QGraphicsItem *parent) const +void VLayoutPiece::CreateLabel(QGraphicsItem *parent, const QPainterPath &path) const { SCASSERT(parent != nullptr) - QGraphicsPathItem* item = new QGraphicsPathItem(parent); - QPainterPath path = d->matrix.map(d->m_liPP.at(i)); - - if (d->mirror == true) + if (not path.isEmpty()) { - QVector points; - if (i < d->m_tmDetail.GetSourceLinesCount()) - { - points = Map(Mirror(d->detailLabel)); - } - else - { - points = Map(Mirror(d->patternInfo)); - } - QPointF ptCenter = (points.at(1) + points.at(3))/2; - qreal dRot = qRadiansToDegrees(qAtan2(points.at(1).y() - points.at(0).y(), - points.at(1).x() - points.at(0).x())); - - // we need to move the center back to the origin, rotate it to align it with x axis, - // then mirror it to obtain the proper text direction, rotate it and translate it back to original position. - // The operations must be added in reverse order - QTransform t; - // move the label back to its original position - t.translate(ptCenter.x(), ptCenter.y()); - // rotate the label back to original angle - t.rotate(dRot); - // mirror the label horizontally - t.scale(-1, 1); - // rotate the label to normal position - t.rotate(-dRot); - // move the label center into origin - t.translate(-ptCenter.x(), -ptCenter.y()); - path = t.map(path); + QGraphicsPathItem* item = new QGraphicsPathItem(parent); + item->setPath(path); + item->setBrush(QBrush(Qt::black)); } - - item->setPath(path); - item->setBrush(QBrush(Qt::black)); } //--------------------------------------------------------------------------------------------------------------------- @@ -800,19 +822,15 @@ QPainterPath VLayoutPiece::LayoutAllowancePath() const //--------------------------------------------------------------------------------------------------------------------- QGraphicsItem *VLayoutPiece::GetItem() const { - QGraphicsPathItem *item = new QGraphicsPathItem(); - item->setPath(ContourPath()); + QGraphicsPathItem *item = GetMainItem(); for (int i = 0; i < d->m_internalPaths.count(); ++i) { CreateInternalPathItem(i, item); } - for (int i = 0; i < d->m_liPP.count(); ++i) - { - CreateTextItem(i, item); - } - + CreateLabel(item, CreateLabelText(d->detailLabel, d->m_tmDetail)); + CreateLabel(item, CreateLabelText(d->patternInfo, d->m_tmPattern)); CreateGrainlineItem(item); return item; @@ -828,12 +846,13 @@ void VLayoutPiece::CreateGrainlineItem(QGraphicsItem *parent) const return; } VGraphicsFillItem* item = new VGraphicsFillItem(parent); + QPainterPath path; - QVector v = Map(d->grainlinePoints); - path.moveTo(v.at(0)); - for (int i = 1; i < v.count(); ++i) + QVector gPoints = Map(d->grainlinePoints); + path.moveTo(gPoints.at(0)); + for (int i = 1; i < gPoints.count(); ++i) { - path.lineTo(v.at(i)); + path.lineTo(gPoints.at(i)); } item->setPath(path); } @@ -852,14 +871,11 @@ QVector VLayoutPiece::DetailPath() const } //--------------------------------------------------------------------------------------------------------------------- -QVector VLayoutPiece::PrepareAllowance(const QVector &points) +QGraphicsPathItem *VLayoutPiece::GetMainItem() const { - QVector allowancePoints; - for(int i = 0; i < points.size(); ++i) - { - allowancePoints.append(VSAPoint(points.at(i))); - } - return allowancePoints; + QGraphicsPathItem *item = new QGraphicsPathItem(); + item->setPath(ContourPath()); + return item; } //--------------------------------------------------------------------------------------------------------------------- @@ -874,64 +890,6 @@ void VLayoutPiece::SetMirror(bool value) d->mirror = value; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief VLayoutDetail::RotatePoint rotates a point around the center for given angle - * @param ptCenter center around which the point is rotated - * @param pt point, which is rotated around the center - * @param dAng angle of rotation - * @return position of point pt after rotating it around the center for dAng radians - */ -QPointF VLayoutPiece::RotatePoint(const QPointF &ptCenter, const QPointF& pt, qreal dAng) -{ - QPointF ptDest; - QPointF ptRel = pt - ptCenter; - ptDest.setX(cos(dAng)*ptRel.x() - sin(dAng)*ptRel.y()); - ptDest.setY(sin(dAng)*ptRel.x() + cos(dAng)*ptRel.y()); - - return ptDest + ptCenter; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief VLayoutDetail::Mirror if the detail layout is rotated, this method will flip the - * label points over vertical axis, which goes through the center of the label - * @param points list of 4 label vertices - * @return list of flipped points - */ -QVector VLayoutPiece::Mirror(const QVector &points) const -{ - // should only call this method with rectangular shapes - Q_ASSERT(points.count() == 4); - if (d->mirror == false) - { - return points; - } - - QVector v; - v.resize(4); - v[0] = points.at(2); - v[1] = points.at(3); - v[2] = points.at(0); - v[3] = points.at(1); - return v; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief VLayoutDetail::GetDistance calculates the Euclidian distance between the points - * @param pt1 first point - * @param pt2 second point - * @return Euclidian distance between the two points - */ -qreal VLayoutPiece::GetDistance(const QPointF &pt1, const QPointF &pt2) -{ - const qreal dX = pt1.x() - pt2.x(); - const qreal dY = pt1.y() - pt2.y(); - - return qSqrt(dX*dX + dY*dY); -} - //--------------------------------------------------------------------------------------------------------------------- QLineF VLayoutPiece::Edge(const QVector &path, int i) const { @@ -989,3 +947,74 @@ int VLayoutPiece::EdgeByPoint(const QVector &path, const QPointF &p1) c } return 0; // Did not find edge } + +//--------------------------------------------------------------------------------------------------------------------- +QPainterPath VLayoutPiece::CreateLabelText(const QVector &labelShape, const VTextManager &tm) const +{ + QPainterPath textpath; + if (labelShape.count() > 2) + { + const qreal dW = QLineF(labelShape.at(0), labelShape.at(1)).length(); + const qreal dH = QLineF(labelShape.at(1), labelShape.at(2)).length(); + const qreal angle = QLineF(labelShape.at(0), labelShape.at(1)).angle(); + qreal dY = 0; + qreal dX; + + // set up the rotation around top-left corner matrix + QTransform mat; + mat.translate(labelShape.at(0).x(), labelShape.at(0).y()); + if (d->mirror) + { + mat.scale(-1, 1); + mat.rotate(angle); + mat.translate(-dW, 0); + } + else + { + mat.rotate(angle); + } + + mat *= d->matrix; + + for (int i = 0; i < tm.GetSourceLinesCount(); ++i) + { + const TextLine& tl = tm.GetSourceLine(i); + QFont fnt = tm.GetFont(); + fnt.setPixelSize(tm.GetFont().pixelSize() + tl.m_iFontSize); + fnt.setWeight(tl.m_eFontWeight); + fnt.setStyle(tl.m_eStyle); + + QFontMetrics fm(fnt); + + dY += fm.height(); + if (dY > dH) + { + break; + } + + QString qsText = tl.m_qsText; + if (fm.width(qsText) > dW) + { + qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast(dW)); + } + if ((tl.m_eAlign & Qt::AlignLeft) > 0) + { + dX = 0; + } + else if ((tl.m_eAlign & Qt::AlignHCenter) > 0) + { + dX = (dW - fm.width(qsText))/2; + } + else + { + dX = dW - fm.width(qsText); + } + QPainterPath path; + path.addText(dX, dY - (fm.height() - fm.ascent())/2, fnt, qsText); + textpath.addPath(mat.map(path)); + dY += tm.GetSpacing(); + } + } + + return textpath; +} diff --git a/src/libs/vlayout/vlayoutpiece.h b/src/libs/vlayout/vlayoutpiece.h index 3ef6cf9ec..30caf6e7f 100644 --- a/src/libs/vlayout/vlayoutpiece.h +++ b/src/libs/vlayout/vlayoutpiece.h @@ -42,17 +42,20 @@ #include #include "../ifc/xml/vabstractpattern.h" -#include "../vpatterndb/vpatterninfogeometry.h" -#include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/floatItemData/vpatternlabeldata.h" +#include "../vpatterndb/floatItemData/vpiecelabeldata.h" #include "../vpatterndb/vcontainer.h" #include "vabstractpiece.h" class VLayoutPieceData; class VLayoutPiecePath; class QGraphicsItem; +class QGraphicsPathItem; +class VTextManager; class VLayoutPiece :public VAbstractPiece { + Q_DECLARE_TR_FUNCTIONS(VLayoutPiece) public: VLayoutPiece(); VLayoutPiece(const VLayoutPiece &detail); @@ -73,12 +76,12 @@ public: QVector GetInternalPaths() const; void SetInternalPaths(const QVector &internalPaths); - void SetDetail(const QString &qsName, const VPatternPieceData& data, const QFont& font); + void SetDetail(const QString &qsName, const VPieceLabelData& data, const QFont& font, const VContainer *pattern); - void SetPatternInfo(const VAbstractPattern* pDoc, const VPatternInfoGeometry& geom, const QFont& font, - qreal dSize, qreal dHeight); + void SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLabelData& geom, const QFont& font, + qreal dSize, qreal dHeight, const VContainer *pattern); - void SetGrainline(const VGrainlineGeometry& geom, const VContainer& rPattern); + void SetGrainline(const VGrainlineData& geom, const VContainer *pattern); QTransform GetMatrix() const; void SetMatrix(const QTransform &matrix); @@ -114,24 +117,19 @@ public: QGraphicsItem *GetItem() const Q_REQUIRED_RESULT; private: - QSharedDataPointer d; + QSharedDataPointer d; QVector DetailPath() const; - void ClearTextItems(); - void CreateTextItems(); + QGraphicsPathItem *GetMainItem() const Q_REQUIRED_RESULT; + + QPainterPath CreateLabelText(const QVector &labelShape, const VTextManager &tm) const; void CreateInternalPathItem(int i, QGraphicsItem *parent) const; - void CreateTextItem(int i, QGraphicsItem *parent) const; + void CreateLabel(QGraphicsItem *parent, const QPainterPath &path) const; void CreateGrainlineItem(QGraphicsItem *parent) const; - static QVector PrepareAllowance(const QVector &points); QVector Map(const QVector &points) const; - static QVector RoundPoints(const QVector &points); - - static QPointF RotatePoint(const QPointF& ptCenter, const QPointF& pt, qreal dAng); - QVector Mirror(const QVector& points) const; - static qreal GetDistance(const QPointF& pt1, const QPointF& pt2); QLineF Edge(const QVector &path, int i) const; int EdgeByPoint(const QVector &path, const QPointF &p1) const; diff --git a/src/libs/vlayout/vlayoutpiece_p.h b/src/libs/vlayout/vlayoutpiece_p.h index bd3f504be..40e91832e 100644 --- a/src/libs/vlayout/vlayoutpiece_p.h +++ b/src/libs/vlayout/vlayoutpiece_p.h @@ -34,9 +34,9 @@ #include #include -#include "../vpatterndb/vpatternpiecedata.h" -#include "../vpatterndb/vpatterninfogeometry.h" -#include "../vpatterndb/vgrainlinegeometry.h" +#include "../vpatterndb/floatItemData/vpiecelabeldata.h" +#include "../vpatterndb/floatItemData/vpatternlabeldata.h" +#include "../vpatterndb/floatItemData/vgrainlinedata.h" #include "../vmisc/diagnostic.h" #include "vlayoutpiecepath.h" @@ -59,12 +59,8 @@ public: detailLabel(), patternInfo(), grainlinePoints(), - detailData(), - patternGeom(), - grainlineGeom(), m_tmDetail(), - m_tmPattern(), - m_liPP() + m_tmPattern() {} VLayoutPieceData(const VLayoutPieceData &detail) @@ -79,12 +75,8 @@ public: detailLabel(detail.detailLabel), patternInfo(detail.patternInfo), grainlinePoints(detail.grainlinePoints), - detailData(detail.detailData), - patternGeom(detail.patternGeom), - grainlineGeom(detail.grainlineGeom), m_tmDetail(detail.m_tmDetail), - m_tmPattern(detail.m_tmPattern), - m_liPP(detail.m_liPP) + m_tmPattern(detail.m_tmPattern) {} ~VLayoutPieceData() {} @@ -111,22 +103,18 @@ public: /** @brief detailLabel detail label rectangle */ QVector detailLabel; + /** @brief patternInfo pattern info rectangle */ QVector patternInfo; + /** @brief grainlineInfo line */ QVector grainlinePoints; - /** @brief detailData detail data */ - VPatternPieceData detailData; - /** @brief patternGeom pattern geometry */ - VPatternInfoGeometry patternGeom; - /** @brief grainlineGeom grainline geometry */ - VGrainlineGeometry grainlineGeom; + /** @brief m_tmDetail text manager for laying out detail info */ VTextManager m_tmDetail; + /** @brief m_tmPattern text manager for laying out pattern info */ VTextManager m_tmPattern; - /** @bried m_liPP list of generated text painter paths */ - QList m_liPP; private: VLayoutPieceData &operator=(const VLayoutPieceData &) Q_DECL_EQ_DELETE; diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 8012dd040..41d043e7b 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -35,7 +35,7 @@ #include #include "../ifc/xml/vabstractpattern.h" -#include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/floatItemData/vpiecelabeldata.h" #include "../vmisc/vabstractapplication.h" #include "../vmisc/vmath.h" #include "vtextmanager.h" @@ -238,7 +238,7 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) * @param qsName detail name * @param data reference to the detail data */ -void VTextManager::Update(const QString& qsName, const VPatternPieceData& data) +void VTextManager::Update(const QString& qsName, const VPieceLabelData& data) { ClearSourceLines(); TextLine tl; diff --git a/src/libs/vlayout/vtextmanager.h b/src/libs/vlayout/vtextmanager.h index 4a9591b93..bb631f381 100644 --- a/src/libs/vlayout/vtextmanager.h +++ b/src/libs/vlayout/vtextmanager.h @@ -38,7 +38,7 @@ #include #include -class VPatternPieceData; +class VPieceLabelData; class VAbstractPattern; #define MIN_FONT_SIZE 5 @@ -85,7 +85,7 @@ public: int GetSourceLinesCount() const; const TextLine& GetSourceLine(int i) const; - void Update(const QString& qsName, const VPatternPieceData& data); + void Update(const QString& qsName, const VPieceLabelData& data); void Update(const VAbstractPattern* pDoc, qreal dSize, qreal dHeight); private: diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 5afb738b3..74afc98f8 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -58,6 +58,11 @@ template class QSharedPointer; #define RECEIVER(obj) #endif +#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) +#define CURRENT_DATA(box) box->itemData(box->currentIndex()) +#else +#define CURRENT_DATA(box) box->currentData() +#endif class QComboBox; class QMarginsF; @@ -146,6 +151,7 @@ enum class Tool : ToolVisHolderType Move, Midpoint, EllipticalArc, + Pin, LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used }; @@ -192,7 +198,9 @@ enum class Vis : ToolVisHolderType ToolMove, ToolEllipticalArc, ToolPiece, - ToolPiecePath + ToolPiecePath, + ToolPin, + PiecePins }; enum class VarType : char { Measurement, Increment, LineLength, CurveLength, CurveCLength, LineAngle, CurveAngle, diff --git a/src/libs/vpatterndb/floatItemData/floatitemdef.h b/src/libs/vpatterndb/floatItemData/floatitemdef.h new file mode 100644 index 000000000..6807a3379 --- /dev/null +++ b/src/libs/vpatterndb/floatItemData/floatitemdef.h @@ -0,0 +1,79 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 23 2, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 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 FLOATITEMDEF_H +#define FLOATITEMDEF_H + +#include +#include + +// denotes the type of arrow for the grainline +enum class ArrowType : char +{ + atBoth, + atFront, + atRear +}; + +enum class MaterialType : char +{ + mtFabric = 0, + mtLining = 1, + mtInterfacing = 2, + mtInterlining = 3, + mtUserDefined = 4 +}; + +enum class PlacementType : char +{ + ptNone = 0, + ptCutOnFold = 1 +}; + +/** + * @brief The MaterialCutPlacement struct used to hold a material, cut number and placement 3-tuple + */ +struct MaterialCutPlacement +{ + MaterialType m_eMaterial; + QString m_qsMaterialUserDef; + int m_iCutNumber; + PlacementType m_ePlacement; + + MaterialCutPlacement() + : m_eMaterial(MaterialType::mtFabric), + m_qsMaterialUserDef(), + m_iCutNumber(0), + m_ePlacement(PlacementType::ptNone) + {} +}; + +typedef QList MCPContainer; + +#endif // FLOATITEMDEF_H + diff --git a/src/libs/vpatterndb/floatItemData/vabstractfloatitemdata.cpp b/src/libs/vpatterndb/floatItemData/vabstractfloatitemdata.cpp new file mode 100644 index 000000000..f7870d58b --- /dev/null +++ b/src/libs/vpatterndb/floatItemData/vabstractfloatitemdata.cpp @@ -0,0 +1,79 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 23 2, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 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 "vabstractfloatitemdata.h" +#include "vabstractfloatitemdata_p.h" + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractFloatItemData::VAbstractFloatItemData() + : d(new VAbstractFloatItemDataPrivate()) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractFloatItemData::VAbstractFloatItemData(const VAbstractFloatItemData &data) + : d (data.d) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractFloatItemData &VAbstractFloatItemData::operator=(const VAbstractFloatItemData &data) +{ + if ( &data == this ) + { + return *this; + } + d = data.d; + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractFloatItemData::~VAbstractFloatItemData() +{} + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VAbstractFloatItemData::GetPos() const +{ + return d->m_ptPos; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractFloatItemData::SetPos(const QPointF &ptPos) +{ + d->m_ptPos = ptPos; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstractFloatItemData::IsVisible() const +{ + return d->m_bVisible; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractFloatItemData::SetVisible(bool bVisible) +{ + d->m_bVisible = bVisible; +} diff --git a/src/libs/vpatterndb/floatItemData/vabstractfloatitemdata.h b/src/libs/vpatterndb/floatItemData/vabstractfloatitemdata.h new file mode 100644 index 000000000..0b3260c5b --- /dev/null +++ b/src/libs/vpatterndb/floatItemData/vabstractfloatitemdata.h @@ -0,0 +1,56 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 23 2, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 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 VABSTRACTFLOATITEMDATA_H +#define VABSTRACTFLOATITEMDATA_H + +#include +#include + +class VAbstractFloatItemDataPrivate; + +class VAbstractFloatItemData +{ +public: + VAbstractFloatItemData(); + VAbstractFloatItemData(const VAbstractFloatItemData &data); + VAbstractFloatItemData &operator=(const VAbstractFloatItemData &data); + virtual ~VAbstractFloatItemData(); + + // methods, which set and return values of different parameters + QPointF GetPos() const; + void SetPos(const QPointF& ptPos); + + bool IsVisible() const; + void SetVisible(bool bVisible); + +private: + QSharedDataPointer d; +}; + +#endif // VABSTRACTFLOATITEMDATA_H diff --git a/src/libs/vpatterndb/floatItemData/vabstractfloatitemdata_p.h b/src/libs/vpatterndb/floatItemData/vabstractfloatitemdata_p.h new file mode 100644 index 000000000..4e8c81010 --- /dev/null +++ b/src/libs/vpatterndb/floatItemData/vabstractfloatitemdata_p.h @@ -0,0 +1,71 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 23 2, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 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 VABSTRACTFLOATITEMDATA_P_H +#define VABSTRACTFLOATITEMDATA_P_H + +#include +#include + +#include "../vmisc/diagnostic.h" + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Weffc++") + +class VAbstractFloatItemDataPrivate : public QSharedData +{ +public: + VAbstractFloatItemDataPrivate() + : m_ptPos(), + m_bVisible(false) + {} + + VAbstractFloatItemDataPrivate(const VAbstractFloatItemDataPrivate &data) + : QSharedData(data), + m_ptPos(data.m_ptPos), + m_bVisible(data.m_bVisible) + {} + + ~VAbstractFloatItemDataPrivate(); + + /** @brief m_ptPos position of label's top left corner */ + QPointF m_ptPos; + /** @brief m_bVisible visibility flag */ + bool m_bVisible; + +private: + VAbstractFloatItemDataPrivate &operator=(const VAbstractFloatItemDataPrivate &) Q_DECL_EQ_DELETE; +}; + +VAbstractFloatItemDataPrivate::~VAbstractFloatItemDataPrivate() +{} + +QT_WARNING_POP + +#endif // VABSTRACTFLOATITEMDATA_P_H + diff --git a/src/libs/vpatterndb/vpatterninfogeometry.cpp b/src/libs/vpatterndb/floatItemData/vgrainlinedata.cpp similarity index 68% rename from src/libs/vpatterndb/vpatterninfogeometry.cpp rename to src/libs/vpatterndb/floatItemData/vgrainlinedata.cpp index 8ab110c1e..de189c075 100644 --- a/src/libs/vpatterndb/vpatterninfogeometry.cpp +++ b/src/libs/vpatterndb/floatItemData/vgrainlinedata.cpp @@ -1,8 +1,8 @@ /************************************************************************ ** - ** @file vpatterninfogeometry.cpp + ** @file vgrainlinedata.cpp ** @author Bojan Kverh - ** @date June 16, 2016 + ** @date September 06, 2016 ** ** @brief ** @copyright @@ -26,84 +26,95 @@ ** *************************************************************************/ -#include "vpatterninfogeometry.h" +#include + +#include "vgrainlinedata.h" +#include "vgrainlinedata_p.h" //--------------------------------------------------------------------------------------------------------------------- -VPatternInfoGeometry::VPatternInfoGeometry() - :m_ptPos(0, 0), m_dLabelWidth(0), m_dLabelHeight(0), m_iFontSize(0), - m_dRotation(0), m_bVisible(true) +VGrainlineData::VGrainlineData() + : VAbstractFloatItemData(), + d(new VGrainlineDataPrivate()) {} //--------------------------------------------------------------------------------------------------------------------- -QPointF VPatternInfoGeometry::GetPos() const +VGrainlineData::VGrainlineData(const VGrainlineData &data) + : VAbstractFloatItemData(data), + d (data.d) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VGrainlineData &VGrainlineData::operator=(const VGrainlineData &data) { - return m_ptPos; + if ( &data == this ) + { + return *this; + } + VAbstractFloatItemData::operator=(data); + d = data.d; + return *this; } //--------------------------------------------------------------------------------------------------------------------- -void VPatternInfoGeometry::SetPos(const QPointF& ptPos) +VGrainlineData::~VGrainlineData() +{} + +//--------------------------------------------------------------------------------------------------------------------- +QString VGrainlineData::GetLength() const { - m_ptPos = ptPos; + return d->m_qsLength; } //--------------------------------------------------------------------------------------------------------------------- -qreal VPatternInfoGeometry::GetLabelWidth() const +void VGrainlineData::SetLength(const QString& qsLen) { - return m_dLabelWidth; + d->m_qsLength = qsLen; } //--------------------------------------------------------------------------------------------------------------------- -void VPatternInfoGeometry::SetLabelWidth(qreal dLabelW) +QString VGrainlineData::GetRotation() const { - m_dLabelWidth = dLabelW; + return d->m_dRotation; } //--------------------------------------------------------------------------------------------------------------------- -qreal VPatternInfoGeometry::GetLabelHeight() const +void VGrainlineData::SetRotation(const QString& qsRot) { - return m_dLabelHeight; + d->m_dRotation = qsRot; } //--------------------------------------------------------------------------------------------------------------------- -void VPatternInfoGeometry::SetLabelHeight(qreal dLabelH) +ArrowType VGrainlineData::GetArrowType() const { - m_dLabelHeight = dLabelH; + return d->m_eArrowType; } //--------------------------------------------------------------------------------------------------------------------- -int VPatternInfoGeometry::GetFontSize() const +void VGrainlineData::SetArrowType(ArrowType eAT) { - return m_iFontSize; + d->m_eArrowType = eAT; } //--------------------------------------------------------------------------------------------------------------------- -void VPatternInfoGeometry::SetFontSize(int iSize) +quint32 VGrainlineData::TopPin() const { - m_iFontSize = iSize; + return d->m_topPin; } //--------------------------------------------------------------------------------------------------------------------- -qreal VPatternInfoGeometry::GetRotation() const +void VGrainlineData::SetTopPin(quint32 topPin) { - return m_dRotation; + d->m_topPin = topPin; } //--------------------------------------------------------------------------------------------------------------------- -void VPatternInfoGeometry::SetRotation(qreal dRot) +quint32 VGrainlineData::BottomPin() const { - m_dRotation = dRot; + return d->m_bottomPin; } //--------------------------------------------------------------------------------------------------------------------- -bool VPatternInfoGeometry::IsVisible() const +void VGrainlineData::SetBottomPin(quint32 bottomPin) { - return m_bVisible; + d->m_bottomPin = bottomPin; } - -//--------------------------------------------------------------------------------------------------------------------- -void VPatternInfoGeometry::SetVisible(bool bVal) -{ - m_bVisible = bVal; -} - -//--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/floatItemData/vgrainlinedata.h b/src/libs/vpatterndb/floatItemData/vgrainlinedata.h new file mode 100644 index 000000000..dc259bf0e --- /dev/null +++ b/src/libs/vpatterndb/floatItemData/vgrainlinedata.h @@ -0,0 +1,73 @@ +/************************************************************************ + ** + ** @file vgrainlinedata.h + ** @author Bojan Kverh + ** @date September 06, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VGRAINLINEGEOMETRY_H +#define VGRAINLINEGEOMETRY_H + +#include +#include + +#include "vabstractfloatitemdata.h" +#include "floatitemdef.h" + +class VGrainlineDataPrivate; + +/** + * @brief The VGrainlineData class holds information about a grainline like + * position, size, rotation and visibility + */ +class VGrainlineData : public VAbstractFloatItemData +{ +public: + VGrainlineData(); + VGrainlineData(const VGrainlineData &data); + VGrainlineData &operator=(const VGrainlineData &data); + virtual ~VGrainlineData(); + + // methods, which set and return values of different parameters + QString GetLength() const; + void SetLength(const QString& qsLen); + + QString GetRotation() const; + void SetRotation(const QString& qsRot); + + ArrowType GetArrowType() const; + void SetArrowType(ArrowType eAT); + + quint32 TopPin() const; + void SetTopPin(quint32 topPin); + + quint32 BottomPin() const; + void SetBottomPin(quint32 bottomPin); + +private: + QSharedDataPointer d; +}; + +#endif // VGRAINLINEGEOMETRY_H + diff --git a/src/libs/vpatterndb/floatItemData/vgrainlinedata_p.h b/src/libs/vpatterndb/floatItemData/vgrainlinedata_p.h new file mode 100644 index 000000000..cb85be652 --- /dev/null +++ b/src/libs/vpatterndb/floatItemData/vgrainlinedata_p.h @@ -0,0 +1,85 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 23 2, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 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 VGRAINLINEDATA_P_H +#define VGRAINLINEDATA_P_H + +#include +#include + +#include "../vmisc/diagnostic.h" +#include "floatitemdef.h" +#include "../ifc/ifcdef.h" + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Weffc++") + +class VGrainlineDataPrivate : public QSharedData +{ +public: + VGrainlineDataPrivate() + : m_qsLength(), + m_dRotation(), + m_eArrowType(ArrowType::atBoth), + m_topPin(NULL_ID), + m_bottomPin(NULL_ID) + {} + + VGrainlineDataPrivate(const VGrainlineDataPrivate &data) + : QSharedData(data), + m_qsLength(data.m_qsLength), + m_dRotation(data.m_dRotation), + m_eArrowType(data.m_eArrowType), + m_topPin(data.m_topPin), + m_bottomPin(data.m_bottomPin) + {} + + ~VGrainlineDataPrivate(); + + /** @brief m_dLength formula to calculate the length of grainline */ + QString m_qsLength; + /** @brief m_dRotation formula to calculate the rotation of grainline in [degrees] */ + QString m_dRotation; + /** @brief m_eArrowType type of arrow on the grainline */ + ArrowType m_eArrowType; + /** @brief m_topPin top pin id */ + quint32 m_topPin; + /** @brief m_bottomPin bottom pin id */ + quint32 m_bottomPin; + +private: + VGrainlineDataPrivate &operator=(const VGrainlineDataPrivate &) Q_DECL_EQ_DELETE; +}; + +VGrainlineDataPrivate::~VGrainlineDataPrivate() +{} + +QT_WARNING_POP + +#endif // VGRAINLINEDATA_P_H + diff --git a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.cpp b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.cpp new file mode 100644 index 000000000..e87f06ddd --- /dev/null +++ b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.cpp @@ -0,0 +1,131 @@ +/************************************************************************ + ** + ** @file vpatternlabeldata.cpp + ** @author Bojan Kverh + ** @date June 16, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vpatternlabeldata.h" +#include "vpatternlabeldata_p.h" +#include "../ifc/ifcdef.h" + +//--------------------------------------------------------------------------------------------------------------------- +VPatternLabelData::VPatternLabelData() + : VAbstractFloatItemData(), + d(new VPatternLabelDataPrivate()) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VPatternLabelData::VPatternLabelData(const VPatternLabelData &data) + : VAbstractFloatItemData(data), + d (data.d) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VPatternLabelData &VPatternLabelData::operator=(const VPatternLabelData &data) +{ + if ( &data == this ) + { + return *this; + } + VAbstractFloatItemData::operator=(data); + d = data.d; + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VPatternLabelData::~VPatternLabelData() +{} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPatternLabelData::GetLabelWidth() const +{ + return d->m_dLabelWidth; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternLabelData::SetLabelWidth(qreal dLabelW) +{ + d->m_dLabelWidth = dLabelW; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPatternLabelData::GetLabelHeight() const +{ + return d->m_dLabelHeight; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternLabelData::SetLabelHeight(qreal dLabelH) +{ + d->m_dLabelHeight = dLabelH; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VPatternLabelData::GetFontSize() const +{ + return d->m_iFontSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternLabelData::SetFontSize(int iSize) +{ + d->m_iFontSize = iSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPatternLabelData::GetRotation() const +{ + return d->m_dRotation; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternLabelData::SetRotation(qreal dRot) +{ + d->m_dRotation = dRot; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VPatternLabelData::TopLeftPin() const +{ + return d->m_topLeftPin; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternLabelData::SetTopLeftPin(const quint32 &topLeftPin) +{ + d->m_topLeftPin = topLeftPin; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VPatternLabelData::BottomRightPin() const +{ + return d->m_bottomRightPin; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternLabelData::SetBottomRightPin(const quint32 &bottomRightPin) +{ + d->m_bottomRightPin = bottomRightPin; +} diff --git a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h new file mode 100644 index 000000000..29cdeffc3 --- /dev/null +++ b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h @@ -0,0 +1,72 @@ +/************************************************************************ + ** + ** @file vpatternlabeldata.h + ** @author Bojan Kverh + ** @date June 16, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VPATTERNINFOGEOMETRY_H +#define VPATTERNINFOGEOMETRY_H + +#include + +#include "vabstractfloatitemdata.h" + +class VPatternLabelDataPrivate; + +/** + * @brief The VPatternLabelData class holds the information about pattern info label geometry + */ +class VPatternLabelData : public VAbstractFloatItemData +{ +public: + VPatternLabelData(); + VPatternLabelData(const VPatternLabelData &data); + VPatternLabelData &operator=(const VPatternLabelData &data); + virtual ~VPatternLabelData(); + + // methods, which set up label parameters + qreal GetLabelWidth() const; + void SetLabelWidth(qreal dLabelW); + + qreal GetLabelHeight() const; + void SetLabelHeight(qreal dLabelH); + + int GetFontSize() const; + void SetFontSize(int iSize); + + qreal GetRotation() const; + void SetRotation(qreal dRot); + + quint32 TopLeftPin() const; + void SetTopLeftPin(const quint32 &topLeftPin); + + quint32 BottomRightPin() const; + void SetBottomRightPin(const quint32 &bottomRightPin); + +private: + QSharedDataPointer d; +}; + +#endif // VPATTERNINFOGEOMETRY_H diff --git a/src/libs/vpatterndb/floatItemData/vpatternlabeldata_p.h b/src/libs/vpatterndb/floatItemData/vpatternlabeldata_p.h new file mode 100644 index 000000000..783addb83 --- /dev/null +++ b/src/libs/vpatterndb/floatItemData/vpatternlabeldata_p.h @@ -0,0 +1,88 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 23 2, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 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 VPATTERNLABELDATA_P_H +#define VPATTERNLABELDATA_P_H + +#include +#include + +#include "../vmisc/diagnostic.h" +#include "../ifc/ifcdef.h" + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Weffc++") + +class VPatternLabelDataPrivate : public QSharedData +{ +public: + VPatternLabelDataPrivate() + : m_dLabelWidth(0), + m_dLabelHeight(0), + m_iFontSize(0), + m_dRotation(0), + m_topLeftPin(NULL_ID), + m_bottomRightPin(NULL_ID) + {} + + VPatternLabelDataPrivate(const VPatternLabelDataPrivate &data) + : QSharedData(data), + m_dLabelWidth(data.m_dLabelWidth), + m_dLabelHeight(data.m_dLabelHeight), + m_iFontSize(data.m_iFontSize), + m_dRotation(data.m_dRotation), + m_topLeftPin(data.m_topLeftPin), + m_bottomRightPin(data.m_bottomRightPin) + {} + + ~VPatternLabelDataPrivate(); + + /** @brief m_dLabelWidth label width */ + qreal m_dLabelWidth; + /** @brief m_dLabelHeight label height */ + qreal m_dLabelHeight; + /** @brief m_iFontSize label text base font size */ + int m_iFontSize; + /** @brief m_dRotation label rotation */ + qreal m_dRotation; + /** @brief m_topLeftPin top left corner pin id */ + quint32 m_topLeftPin; + /** @brief m_bottomRightPin bottom right corner pin id */ + quint32 m_bottomRightPin; + +private: + VPatternLabelDataPrivate &operator=(const VPatternLabelDataPrivate &) Q_DECL_EQ_DELETE; +}; + +VPatternLabelDataPrivate::~VPatternLabelDataPrivate() +{} + +QT_WARNING_POP + +#endif // VPATTERNLABELDATA_P_H + diff --git a/src/libs/vpatterndb/vgrainlinegeometry.cpp b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.cpp similarity index 60% rename from src/libs/vpatterndb/vgrainlinegeometry.cpp rename to src/libs/vpatterndb/floatItemData/vpiecelabeldata.cpp index e1f3b6ccb..06d641933 100644 --- a/src/libs/vpatterndb/vgrainlinegeometry.cpp +++ b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.cpp @@ -1,8 +1,8 @@ /************************************************************************ ** - ** @file vgrainlinegeometry.cpp + ** @file vpiecelabeldata.cpp ** @author Bojan Kverh - ** @date September 06, 2016 + ** @date June 16, 2016 ** ** @brief ** @copyright @@ -26,85 +26,98 @@ ** *************************************************************************/ -#include +#include "vpiecelabeldata.h" +#include "vpiecelabeldata_p.h" -#include "vgrainlinegeometry.h" +#include //--------------------------------------------------------------------------------------------------------------------- - -VGrainlineGeometry::VGrainlineGeometry() - :m_ptPos(0, 0), m_qsLength(), m_qsRotation(), m_bVisible(false), m_eArrowType(atBoth) +VPieceLabelData::VPieceLabelData() + : VPatternLabelData(), + d(new VPieceLabelDataPrivate()) {} //--------------------------------------------------------------------------------------------------------------------- +VPieceLabelData::VPieceLabelData(const VPieceLabelData &data) + : VPatternLabelData(data), + d (data.d) +{} -QPointF VGrainlineGeometry::GetPos() const +//--------------------------------------------------------------------------------------------------------------------- +VPieceLabelData &VPieceLabelData::operator=(const VPieceLabelData &data) { - return m_ptPos; + if ( &data == this ) + { + return *this; + } + VPatternLabelData::operator=(data); + d = data.d; + return *this; } //--------------------------------------------------------------------------------------------------------------------- +VPieceLabelData::~VPieceLabelData() +{} -void VGrainlineGeometry::SetPos(const QPointF &ptPos) +//--------------------------------------------------------------------------------------------------------------------- +void VPieceLabelData::Append(const MaterialCutPlacement& rMCP) { - m_ptPos = ptPos; + d->m_conMCP.append(rMCP); } //--------------------------------------------------------------------------------------------------------------------- - -QString VGrainlineGeometry::GetLength() const +void VPieceLabelData::Insert(int i, const MaterialCutPlacement& rMCP) { - return m_qsLength; + Q_ASSERT(i >= 0); + Q_ASSERT(i <= GetMCPCount()); + d->m_conMCP.insert(i, rMCP); } //--------------------------------------------------------------------------------------------------------------------- - -void VGrainlineGeometry::SetLength(const QString& qsLen) +void VPieceLabelData::Set(int i, const MaterialCutPlacement& rMCP) { - m_qsLength = qsLen; + Q_ASSERT(i >= 0); + Q_ASSERT(i < GetMCPCount()); + d->m_conMCP[i] = rMCP; } //--------------------------------------------------------------------------------------------------------------------- - -QString VGrainlineGeometry::GetRotation() const +int VPieceLabelData::GetMCPCount() const { - return m_qsRotation; + return d->m_conMCP.count(); } //--------------------------------------------------------------------------------------------------------------------- - -void VGrainlineGeometry::SetRotation(const QString& qsRot) +const MaterialCutPlacement& VPieceLabelData::GetMCP(int i) const { - m_qsRotation = qsRot; + Q_ASSERT(i >= 0); + Q_ASSERT(i < GetMCPCount()); + return d->m_conMCP.at(i); } //--------------------------------------------------------------------------------------------------------------------- - -bool VGrainlineGeometry::IsVisible() const +void VPieceLabelData::RemoveMCP(int i) { - return m_bVisible; + Q_ASSERT(i >= 0); + Q_ASSERT(i < GetMCPCount()); + d->m_conMCP.removeAt(i); } //--------------------------------------------------------------------------------------------------------------------- - -void VGrainlineGeometry::SetVisible(bool bVisible) +void VPieceLabelData::Clear() { - m_bVisible = bVisible; + d->m_qsLetter.clear(); + d->m_conMCP.clear(); } //--------------------------------------------------------------------------------------------------------------------- - -VGrainlineGeometry::ArrowType VGrainlineGeometry::GetArrowType() const +const QString& VPieceLabelData::GetLetter() const { - return m_eArrowType; + return d->m_qsLetter; } //--------------------------------------------------------------------------------------------------------------------- - -void VGrainlineGeometry::SetArrowType(ArrowType eAT) +void VPieceLabelData::SetLetter(QString qsLetter) { - m_eArrowType = eAT; + d->m_qsLetter = qsLetter.left(3); } - -//--------------------------------------------------------------------------------------------------------------------- - diff --git a/src/libs/vpatterndb/floatItemData/vpiecelabeldata.h b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.h new file mode 100644 index 000000000..f58bb3efd --- /dev/null +++ b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.h @@ -0,0 +1,68 @@ +/************************************************************************ + ** + ** @file vpiecelabeldata.h + ** @author Bojan Kverh + ** @date June 16, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VPATTERNPIECEDATA_H +#define VPATTERNPIECEDATA_H + +#include + +#include "vpatternlabeldata.h" +#include "floatitemdef.h" + +class VPieceLabelDataPrivate; + +/** + * @brief The VPieceLabelData class holds some information about a single + * piece like letter, name, material type, cut number and placement. + */ +class VPieceLabelData : public VPatternLabelData +{ +public: + VPieceLabelData(); + VPieceLabelData(const VPieceLabelData &data); + VPieceLabelData &operator=(const VPieceLabelData &data); + virtual ~VPieceLabelData(); + + // methods, which operate on MaterialCutPlacement container + void Append(const MaterialCutPlacement& rMCP); + void Insert(int i, const MaterialCutPlacement& rMCP); + void Set(int i, const MaterialCutPlacement& rMCP); + int GetMCPCount() const; + const MaterialCutPlacement& GetMCP(int i) const; + void RemoveMCP(int i); + void Clear(); + + // methods, which operate on other members + const QString& GetLetter() const; + void SetLetter(QString qsLetter); + +private: + QSharedDataPointer d; +}; + +#endif // VPATTERNPIECEDATA_H diff --git a/src/libs/vpatterndb/floatItemData/vpiecelabeldata_p.h b/src/libs/vpatterndb/floatItemData/vpiecelabeldata_p.h new file mode 100644 index 000000000..7d02f96b6 --- /dev/null +++ b/src/libs/vpatterndb/floatItemData/vpiecelabeldata_p.h @@ -0,0 +1,72 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 23 2, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 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 VPIECELABELDATA_P_H +#define VPIECELABELDATA_P_H + +#include +#include + +#include "../vmisc/diagnostic.h" +#include "floatitemdef.h" + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Weffc++") + +class VPieceLabelDataPrivate : public QSharedData +{ +public: + VPieceLabelDataPrivate() + : m_qsLetter(), + m_conMCP() + {} + + VPieceLabelDataPrivate(const VPieceLabelDataPrivate &data) + : QSharedData(data), + m_qsLetter(data.m_qsLetter), + m_conMCP(data.m_conMCP) + {} + + ~VPieceLabelDataPrivate(); + + /** @brief m_qsLetter Detail letter (should be no more than 3 characters) */ + QString m_qsLetter; + /** @brief m_conMCP List of material, cut, placement tuples */ + MCPContainer m_conMCP; + +private: + VPieceLabelDataPrivate &operator=(const VPieceLabelDataPrivate &) Q_DECL_EQ_DELETE; +}; + +VPieceLabelDataPrivate::~VPieceLabelDataPrivate() +{} + +QT_WARNING_POP + +#endif // VPIECELABELDATA_P_H + diff --git a/src/libs/vpatterndb/vgrainlinegeometry.h b/src/libs/vpatterndb/vgrainlinegeometry.h deleted file mode 100644 index a220680f1..000000000 --- a/src/libs/vpatterndb/vgrainlinegeometry.h +++ /dev/null @@ -1,88 +0,0 @@ -/************************************************************************ - ** - ** @file vgrainlinegeometry.h - ** @author Bojan Kverh - ** @date September 06, 2016 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentine project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013-2015 Valentina project - ** All Rights Reserved. - ** - ** Valentina is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ - -#ifndef VGRAINLINEGEOMETRY_H -#define VGRAINLINEGEOMETRY_H - -#include -#include - -/** - * @brief The VGrainlineGeometry class holds information about a grainline like - * position, size, rotation and visibility - */ -class VGrainlineGeometry -{ -public: - // denotes the type of arrow for the grainline - enum ArrowType - { - atBoth, - atFront, - atRear - }; - - VGrainlineGeometry(); - - // methods, which set and return values of different parameters - QPointF GetPos() const; - void SetPos(const QPointF& ptPos); - QString GetLength() const; - void SetLength(const QString& qsLen); - QString GetRotation() const; - void SetRotation(const QString& qsRot); - bool IsVisible() const; - void SetVisible(bool bVisible); - ArrowType GetArrowType() const; - void SetArrowType(ArrowType eAT); - -private: - /** - * @brief m_ptPos position of grainline's center - */ - QPointF m_ptPos; - /** - * @brief m_dLength formula to calculate the length of grainline - */ - QString m_qsLength; - /** - * @brief m_dRotation formula to calculate the rotation of grainline in [degrees] - */ - QString m_qsRotation; - /** - * @brief m_bVisible visibility flag - */ - bool m_bVisible; - /** - * @brief m_eArrowType type of arrow on the grainline - */ - ArrowType m_eArrowType; -}; - -#endif // VGRAINLINEGEOMETRY_H - diff --git a/src/libs/vpatterndb/vpatterndb.pri b/src/libs/vpatterndb/vpatterndb.pri index abf31776a..ddd66977d 100644 --- a/src/libs/vpatterndb/vpatterndb.pri +++ b/src/libs/vpatterndb/vpatterndb.pri @@ -17,13 +17,14 @@ SOURCES += \ $$PWD/variables/vmeasurement.cpp \ $$PWD/variables/vvariable.cpp \ $$PWD/vformula.cpp \ - $$PWD/vpatternpiecedata.cpp \ - $$PWD/vpatterninfogeometry.cpp \ - $$PWD/vgrainlinegeometry.cpp \ $$PWD/variables/vcurveclength.cpp \ $$PWD/vpiece.cpp \ $$PWD/vpiecenode.cpp \ - $$PWD/vpiecepath.cpp + $$PWD/vpiecepath.cpp \ + $$PWD/floatItemData/vpiecelabeldata.cpp \ + $$PWD/floatItemData/vpatternlabeldata.cpp \ + $$PWD/floatItemData/vgrainlinedata.cpp \ + $$PWD/floatItemData/vabstractfloatitemdata.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -54,13 +55,19 @@ HEADERS += \ $$PWD/variables/vvariable.h \ $$PWD/variables/vvariable_p.h \ $$PWD/vformula.h \ - $$PWD/vpatternpiecedata.h \ - $$PWD/vpatterninfogeometry.h \ - $$PWD/vgrainlinegeometry.h \ $$PWD/variables/vcurveclength.h \ $$PWD/vpiece.h \ $$PWD/vpiece_p.h \ $$PWD/vpiecenode.h \ $$PWD/vpiecenode_p.h \ $$PWD/vpiecepath.h \ - $$PWD/vpiecepath_p.h + $$PWD/vpiecepath_p.h \ + $$PWD/floatItemData/vpiecelabeldata.h \ + $$PWD/floatItemData/vpatternlabeldata.h \ + $$PWD/floatItemData/vgrainlinedata.h \ + $$PWD/floatItemData/vabstractfloatitemdata.h \ + $$PWD/floatItemData/vabstractfloatitemdata_p.h \ + $$PWD/floatItemData/vgrainlinedata_p.h \ + $$PWD/floatItemData/floatitemdef.h \ + $$PWD/floatItemData/vpatternlabeldata_p.h \ + $$PWD/floatItemData/vpiecelabeldata_p.h diff --git a/src/libs/vpatterndb/vpatterninfogeometry.h b/src/libs/vpatterndb/vpatterninfogeometry.h deleted file mode 100644 index c9e976ba1..000000000 --- a/src/libs/vpatterndb/vpatterninfogeometry.h +++ /dev/null @@ -1,85 +0,0 @@ -/************************************************************************ - ** - ** @file vpatterninfogeometry.h - ** @author Bojan Kverh - ** @date June 16, 2016 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentine project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013-2015 Valentina project - ** All Rights Reserved. - ** - ** Valentina is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ - -#ifndef VPATTERNINFOGEOMETRY_H -#define VPATTERNINFOGEOMETRY_H - -#include -#include - -/** - * @brief The VPatternInfoGeometry class holds the information about pattern info label geometry - */ -class VPatternInfoGeometry -{ -public: - VPatternInfoGeometry(); - - // methods, which set up label parameters - QPointF GetPos() const; - void SetPos(const QPointF& ptPos); - qreal GetLabelWidth() const; - void SetLabelWidth(qreal dLabelW); - qreal GetLabelHeight() const; - void SetLabelHeight(qreal dLabelH); - int GetFontSize() const; - void SetFontSize(int iSize); - qreal GetRotation() const; - void SetRotation(qreal dRot); - bool IsVisible() const; - void SetVisible(bool bVal); - -private: - /** - * @brief m_ptPos position of label's top left corner - */ - QPointF m_ptPos; - /** - * @brief m_dLabelWidth label width - */ - qreal m_dLabelWidth; - /** - * @brief m_dLabelHeight label height - */ - qreal m_dLabelHeight; - /** - * @brief m_iFontSize label text base font size - */ - int m_iFontSize; - /** - * @brief m_dRotation Label rotation - */ - qreal m_dRotation; - /** - * @brief m_bVisible visibility flag - */ - bool m_bVisible; - -}; - -#endif // VPATTERNINFOGEOMETRY_H diff --git a/src/libs/vpatterndb/vpatternpiecedata.cpp b/src/libs/vpatterndb/vpatternpiecedata.cpp deleted file mode 100644 index 830ef21e9..000000000 --- a/src/libs/vpatterndb/vpatternpiecedata.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/************************************************************************ - ** - ** @file vpatternpiecedata.cpp - ** @author Bojan Kverh - ** @date June 16, 2016 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentine project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013-2015 Valentina project - ** All Rights Reserved. - ** - ** Valentina is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ - -#include "vpatternpiecedata.h" - -//--------------------------------------------------------------------------------------------------------------------- -MaterialCutPlacement::MaterialCutPlacement() - :m_eMaterial(MaterialType::mtFabric), m_qsMaterialUserDef(), m_iCutNumber(0), m_ePlacement(PlacementType::ptNone) -{} - -//--------------------------------------------------------------------------------------------------------------------- -VPatternPieceData::VPatternPieceData() - :m_qsLetter(), m_conMCP(), m_ptPos(0, 0), m_dLabelWidth(0), m_dLabelHeight(0), - m_iFontSize(0), m_dRotation(0), m_bVisible(true) -{} - -//--------------------------------------------------------------------------------------------------------------------- -void VPatternPieceData::Append(const MaterialCutPlacement& rMCP) -{ - m_conMCP.append(rMCP); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPatternPieceData::Insert(int i, const MaterialCutPlacement& rMCP) -{ - Q_ASSERT(i >= 0); - Q_ASSERT(i <= GetMCPCount()); - m_conMCP.insert(i, rMCP); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPatternPieceData::Set(int i, const MaterialCutPlacement& rMCP) -{ - Q_ASSERT(i >= 0); - Q_ASSERT(i < GetMCPCount()); - m_conMCP[i] = rMCP; -} - -//--------------------------------------------------------------------------------------------------------------------- -int VPatternPieceData::GetMCPCount() const -{ - return m_conMCP.count(); -} - -//--------------------------------------------------------------------------------------------------------------------- -const MaterialCutPlacement& VPatternPieceData::GetMCP(int i) const -{ - Q_ASSERT(i >= 0); - Q_ASSERT(i < GetMCPCount()); - return m_conMCP.at(i); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPatternPieceData::RemoveMCP(int i) -{ - Q_ASSERT(i >= 0); - Q_ASSERT(i < GetMCPCount()); - m_conMCP.removeAt(i); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPatternPieceData::Clear() -{ - m_qsLetter.clear(); - m_conMCP.clear(); -} - -//--------------------------------------------------------------------------------------------------------------------- -const QString& VPatternPieceData::GetLetter() const -{ - return m_qsLetter; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPatternPieceData::SetLetter(QString qsLetter) -{ - m_qsLetter = qsLetter.left(3); -} - -//--------------------------------------------------------------------------------------------------------------------- -QPointF VPatternPieceData::GetPos() const -{ - return m_ptPos; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPatternPieceData::SetPos(const QPointF& ptPos) -{ - m_ptPos = ptPos; -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VPatternPieceData::GetLabelWidth() const -{ - return m_dLabelWidth; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPatternPieceData::SetLabelWidth(qreal dLabelW) -{ - m_dLabelWidth = dLabelW; -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VPatternPieceData::GetLabelHeight() const -{ - return m_dLabelHeight; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPatternPieceData::SetLabelHeight(qreal dLabelH) -{ - m_dLabelHeight = dLabelH; -} - -//--------------------------------------------------------------------------------------------------------------------- -int VPatternPieceData::GetFontSize() const -{ - return m_iFontSize; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPatternPieceData::SetFontSize(int iSize) -{ - m_iFontSize = iSize; -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VPatternPieceData::GetRotation() const -{ - return m_dRotation; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPatternPieceData::SetRotation(qreal dRot) -{ - m_dRotation = dRot; -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VPatternPieceData::IsVisible() const -{ - return m_bVisible; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPatternPieceData::SetVisible(bool bVal) -{ - m_bVisible = bVal; -} - -//--------------------------------------------------------------------------------------------------------------------- - diff --git a/src/libs/vpatterndb/vpatternpiecedata.h b/src/libs/vpatterndb/vpatternpiecedata.h deleted file mode 100644 index 08706f8a2..000000000 --- a/src/libs/vpatterndb/vpatternpiecedata.h +++ /dev/null @@ -1,141 +0,0 @@ -/************************************************************************ - ** - ** @file vpatternpiecedata.h - ** @author Bojan Kverh - ** @date June 16, 2016 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentine project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013-2015 Valentina project - ** All Rights Reserved. - ** - ** Valentina is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ - -#ifndef VPATTERNPIECEDATA_H -#define VPATTERNPIECEDATA_H - -#include -#include -#include -#include -#include -#include - -enum class MaterialType : char -{ - mtFabric = 0, - mtLining = 1, - mtInterfacing = 2, - mtInterlining = 3, - mtUserDefined = 4 -}; - -enum class PlacementType : char -{ - ptNone = 0, - ptCutOnFold = 1 -}; - -/** - * @brief The MaterialCutPlacement struct used to hold a material, cut number and placement 3-tuple - */ -struct MaterialCutPlacement -{ - MaterialType m_eMaterial; - QString m_qsMaterialUserDef; - int m_iCutNumber; - PlacementType m_ePlacement; - - MaterialCutPlacement(); -}; - -typedef QList MCPContainer; - -/** - * @brief The VPatternPieceData class holds some information about a single - * piece like letter, name, material type, cut number and placement. - */ -class VPatternPieceData -{ -public: - VPatternPieceData(); - - // methods, which operate on MaterialCutPlacement container - void Append(const MaterialCutPlacement& rMCP); - void Insert(int i, const MaterialCutPlacement& rMCP); - void Set(int i, const MaterialCutPlacement& rMCP); - int GetMCPCount() const; - const MaterialCutPlacement& GetMCP(int i) const; - void RemoveMCP(int i); - void Clear(); - - // methods, which operate on other members - const QString& GetLetter() const; - void SetLetter(QString qsLetter); - - // methods, which set up label parameters - QPointF GetPos() const; - void SetPos(const QPointF& ptPos); - qreal GetLabelWidth() const; - void SetLabelWidth(qreal dLabelW); - qreal GetLabelHeight() const; - void SetLabelHeight(qreal dLabelH); - int GetFontSize() const; - void SetFontSize(int iSize); - qreal GetRotation() const; - void SetRotation(qreal dRot); - bool IsVisible() const; - void SetVisible(bool bVal); - -private: - /** - * @brief m_qsLetter Detail letter (should be no more than 3 characters) - */ - QString m_qsLetter; - /** - * @brief m_conMCP List of material, cut, placement tuples - */ - MCPContainer m_conMCP; - /** - * @brief m_ptPos position of label's top left corner - */ - QPointF m_ptPos; - /** - * @brief m_dLabelWidth label width - */ - qreal m_dLabelWidth; - /** - * @brief m_dLabelHeight label height - */ - qreal m_dLabelHeight; - /** - * @brief m_iFontSize label font size - */ - int m_iFontSize; - /** - * @brief m_dRotation label rotation - */ - qreal m_dRotation; - /** - * @brief m_bVisible visibility flag - */ - bool m_bVisible; - -}; - -#endif // VPATTERNPIECEDATA_H diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index ed0f50b7d..ef954c760 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -36,6 +36,38 @@ #include #include +namespace +{ +QVector PieceMissingNodes(const QVector &d1Nodes, const QVector &d2Nodes) +{ + if (d1Nodes.size() == d2Nodes.size()) //-V807 + { + return QVector(); + } + + QSet set1; + for (qint32 i = 0; i < d1Nodes.size(); ++i) + { + set1.insert(d1Nodes.at(i)); + } + + QSet set2; + for (qint32 j = 0; j < d2Nodes.size(); ++j) + { + set2.insert(d2Nodes.at(j)); + } + + const QList set3 = set1.subtract(set2).toList(); + QVector r; + for (qint32 i = 0; i < set3.size(); ++i) + { + r.append(set3.at(i)); + } + + return r; +} +} + //--------------------------------------------------------------------------------------------------------------------- VPiece::VPiece() : VAbstractPiece(), d(new VPieceData(PiecePathType::PiecePath)) @@ -290,6 +322,12 @@ QVector VPiece::GetInternalPaths() const return d->m_internalPaths; } +//--------------------------------------------------------------------------------------------------------------------- +QVector &VPiece::GetInternalPaths() +{ + return d->m_internalPaths; +} + //--------------------------------------------------------------------------------------------------------------------- void VPiece::SetInternalPaths(const QVector &iPaths) { @@ -297,13 +335,13 @@ void VPiece::SetInternalPaths(const QVector &iPaths) } //--------------------------------------------------------------------------------------------------------------------- -void VPiece::AppendInternalPath(quint32 path) +QVector VPiece::GetCustomSARecords() const { - d->m_internalPaths.append(path); + return d->m_customSARecords; } //--------------------------------------------------------------------------------------------------------------------- -QVector VPiece::GetCustomSARecords() const +QVector &VPiece::GetCustomSARecords() { return d->m_customSARecords; } @@ -315,9 +353,21 @@ void VPiece::SetCustomSARecords(const QVector &records) } //--------------------------------------------------------------------------------------------------------------------- -void VPiece::AppendCustomSARecord(const CustomSARecord &record) +QVector VPiece::GetPins() const { - d->m_customSARecords.append(record); + return d->m_pins; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector &VPiece::GetPins() +{ + return d->m_pins; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPiece::SetPins(const QVector &pins) +{ + d->m_pins = pins; } //--------------------------------------------------------------------------------------------------------------------- @@ -335,67 +385,35 @@ QVector VPiece::MissingNodes(const VPiece &det) const //--------------------------------------------------------------------------------------------------------------------- QVector VPiece::MissingCSAPath(const VPiece &det) const { - const QVector detRecords = det.GetCustomSARecords(); - if (d->m_customSARecords.size() == detRecords.size()) //-V807 - { - return QVector(); - } - - QSet set1; + QVector oldCSARecords; for (qint32 i = 0; i < d->m_customSARecords.size(); ++i) { - set1.insert(d->m_customSARecords.at(i).path); + oldCSARecords.append(d->m_customSARecords.at(i).path); } - QSet set2; - for (qint32 j = 0; j < detRecords.size(); ++j) + QVector newCSARecords; + for (qint32 i = 0; i < det.GetCustomSARecords().size(); ++i) { - set2.insert(detRecords.at(j).path); + newCSARecords.append(det.GetCustomSARecords().at(i).path); } - const QList set3 = set1.subtract(set2).toList(); - QVector r; - for (qint32 i = 0; i < set3.size(); ++i) - { - r.append(set3.at(i)); - } - - return r; + return PieceMissingNodes(oldCSARecords, newCSARecords); } //--------------------------------------------------------------------------------------------------------------------- QVector VPiece::MissingInternalPaths(const VPiece &det) const { - const QVector detRecords = det.GetInternalPaths(); - if (d->m_internalPaths.size() == detRecords.size()) //-V807 - { - return QVector(); - } - - QSet set1; - for (qint32 i = 0; i < d->m_internalPaths.size(); ++i) - { - set1.insert(d->m_internalPaths.at(i)); - } - - QSet set2; - for (qint32 j = 0; j < detRecords.size(); ++j) - { - set2.insert(detRecords.at(j)); - } - - const QList set3 = set1.subtract(set2).toList(); - QVector r; - for (qint32 i = 0; i < set3.size(); ++i) - { - r.append(set3.at(i)); - } - - return r; + return PieceMissingNodes(d->m_internalPaths, det.GetInternalPaths()); } //--------------------------------------------------------------------------------------------------------------------- -void VPiece::SetPatternPieceData(const VPatternPieceData &data) +QVector VPiece::MissingPins(const VPiece &det) const +{ + return PieceMissingNodes(d->m_pins, det.GetPins()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPiece::SetPatternPieceData(const VPieceLabelData &data) { d->m_ppData = data; } @@ -405,7 +423,7 @@ void VPiece::SetPatternPieceData(const VPatternPieceData &data) * @brief Returns full access to the pattern piece data object * @return pattern piece data object */ -VPatternPieceData &VPiece::GetPatternPieceData() +VPieceLabelData &VPiece::GetPatternPieceData() { return d->m_ppData; } @@ -415,13 +433,13 @@ VPatternPieceData &VPiece::GetPatternPieceData() * @brief Returns the read only reference to the pattern piece data object * @return pattern piece data object */ -const VPatternPieceData &VPiece::GetPatternPieceData() const +const VPieceLabelData &VPiece::GetPatternPieceData() const { return d->m_ppData; } //--------------------------------------------------------------------------------------------------------------------- -void VPiece::SetPatternInfo(const VPatternInfoGeometry &info) +void VPiece::SetPatternInfo(const VPatternLabelData &info) { d->m_piPatternInfo = info; } @@ -431,7 +449,7 @@ void VPiece::SetPatternInfo(const VPatternInfoGeometry &info) * @brief Returns full access to the pattern info geometry object * @return pattern info geometry object */ -VPatternInfoGeometry &VPiece::GetPatternInfo() +VPatternLabelData &VPiece::GetPatternInfo() { return d->m_piPatternInfo; } @@ -441,7 +459,7 @@ VPatternInfoGeometry &VPiece::GetPatternInfo() * @brief Returns the read only reference to the pattern info geometry object * @return pattern info geometry object */ -const VPatternInfoGeometry &VPiece::GetPatternInfo() const +const VPatternLabelData &VPiece::GetPatternInfo() const { return d->m_piPatternInfo; } @@ -451,7 +469,7 @@ const VPatternInfoGeometry &VPiece::GetPatternInfo() const * @brief VDetail::GetGrainlineGeometry full access to the grainline geometry object * @return reference to grainline geometry object */ -VGrainlineGeometry &VPiece::GetGrainlineGeometry() +VGrainlineData &VPiece::GetGrainlineGeometry() { return d->m_glGrainline; } @@ -461,7 +479,7 @@ VGrainlineGeometry &VPiece::GetGrainlineGeometry() * @brief VDetail::GetGrainlineGeometry returns the read-only reference to the grainline geometry object * @return reference to grainline geometry object */ -const VGrainlineGeometry &VPiece::GetGrainlineGeometry() const +const VGrainlineData &VPiece::GetGrainlineGeometry() const { return d->m_glGrainline; } diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 3a82b709a..31c7fe476 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -39,9 +39,9 @@ class VPieceNode; template class QVector; template class QSharedPointer; class VPiecePath; -class VPatternInfoGeometry; -class VPatternPieceData; -class VGrainlineGeometry; +class VPatternLabelData; +class VPieceLabelData; +class VGrainlineData; class VContainer; class QPainterPath; class VPointF; @@ -81,27 +81,32 @@ public: void SetFormulaSAWidth(const QString &formula, qreal value); QVector GetInternalPaths() const; + QVector &GetInternalPaths(); void SetInternalPaths(const QVector &iPaths); - void AppendInternalPath(quint32 path); QVector GetCustomSARecords() const; + QVector &GetCustomSARecords(); void SetCustomSARecords(const QVector &records); - void AppendCustomSARecord(const CustomSARecord &record); + + QVector GetPins() const; + QVector &GetPins(); + void SetPins(const QVector &pins); QVector MissingNodes(const VPiece &det) const; QVector MissingCSAPath(const VPiece &det) const; QVector MissingInternalPaths(const VPiece &det) const; + QVector MissingPins(const VPiece &det) const; - void SetPatternPieceData(const VPatternPieceData &data); - VPatternPieceData& GetPatternPieceData(); - const VPatternPieceData& GetPatternPieceData() const; + void SetPatternPieceData(const VPieceLabelData &data); + VPieceLabelData& GetPatternPieceData(); + const VPieceLabelData& GetPatternPieceData() const; - void SetPatternInfo(const VPatternInfoGeometry &info); - VPatternInfoGeometry& GetPatternInfo(); - const VPatternInfoGeometry& GetPatternInfo() const; + void SetPatternInfo(const VPatternLabelData &info); + VPatternLabelData& GetPatternInfo(); + const VPatternLabelData& GetPatternInfo() const; - VGrainlineGeometry& GetGrainlineGeometry(); - const VGrainlineGeometry& GetGrainlineGeometry() const; + VGrainlineData& GetGrainlineGeometry(); + const VGrainlineData& GetGrainlineGeometry() const; private: QSharedDataPointer d; diff --git a/src/libs/vpatterndb/vpiece_p.h b/src/libs/vpatterndb/vpiece_p.h index f937e8488..be91f663f 100644 --- a/src/libs/vpatterndb/vpiece_p.h +++ b/src/libs/vpatterndb/vpiece_p.h @@ -36,9 +36,9 @@ #include "../vmisc/def.h" #include "vpiecenode.h" #include "vpiecepath.h" -#include "vpatternpiecedata.h" -#include "vpatterninfogeometry.h" -#include "vgrainlinegeometry.h" +#include "floatItemData/vpiecelabeldata.h" +#include "floatItemData/vpatternlabeldata.h" +#include "floatItemData/vgrainlinedata.h" QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Weffc++") @@ -54,6 +54,7 @@ public: m_united(false), m_customSARecords(), m_internalPaths(), + m_pins(), m_ppData(), m_piPatternInfo(), m_glGrainline(), @@ -69,6 +70,7 @@ public: m_united(detail.m_united), m_customSARecords(detail.m_customSARecords), m_internalPaths(detail.m_internalPaths), + m_pins(detail.m_pins), m_ppData(detail.m_ppData), m_piPatternInfo(detail.m_piPatternInfo), m_glGrainline(detail.m_glGrainline), @@ -88,15 +90,16 @@ public: QVector m_customSARecords; QVector m_internalPaths; + QVector m_pins; /** @brief Pattern piece data */ - VPatternPieceData m_ppData; + VPieceLabelData m_ppData; /** @brief Pattern info coordinates */ - VPatternInfoGeometry m_piPatternInfo; + VPatternLabelData m_piPatternInfo; /** @brief m_glGrainline grainline geometry object*/ - VGrainlineGeometry m_glGrainline; + VGrainlineData m_glGrainline; QString m_formulaWidth; diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index d21b0a6ba..135de7182 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -43,7 +43,8 @@ HEADERS += \ $$PWD/tools/dialogmove.h \ $$PWD/tools/dialogellipticalarc.h \ $$PWD/tools/dialogseamallowance.h \ - $$PWD/tools/dialogpiecepath.h + $$PWD/tools/dialogpiecepath.h \ + $$PWD/tools/dialogpin.h SOURCES += \ $$PWD/tools/dialogalongline.cpp \ @@ -86,7 +87,8 @@ SOURCES += \ $$PWD/tools/dialogmove.cpp \ $$PWD/tools/dialogellipticalarc.cpp \ $$PWD/tools/dialogseamallowance.cpp \ - $$PWD/tools/dialogpiecepath.cpp + $$PWD/tools/dialogpiecepath.cpp \ + $$PWD/tools/dialogpin.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ @@ -128,4 +130,5 @@ FORMS += \ $$PWD/tools/dialogmove.ui \ $$PWD/tools/dialogellipticalarc.ui \ $$PWD/tools/dialogseamallowance.ui \ - $$PWD/tools/dialogpiecepath.ui + $$PWD/tools/dialogpiecepath.ui \ + $$PWD/tools/dialogpin.ui diff --git a/src/libs/vtools/dialogs/tooldialogs.h b/src/libs/vtools/dialogs/tooldialogs.h index b42272af1..a98fe7402 100644 --- a/src/libs/vtools/dialogs/tooldialogs.h +++ b/src/libs/vtools/dialogs/tooldialogs.h @@ -67,6 +67,7 @@ #include "tools/dialogmove.h" #include "tools/dialogellipticalarc.h" #include "tools/dialogpiecepath.h" +#include "tools/dialogpin.h" #include "support/dialogeditwrongformula.h" #include "support/dialogundo.h" diff --git a/src/libs/vtools/dialogs/tools/dialogline.cpp b/src/libs/vtools/dialogs/tools/dialogline.cpp index 74294e895..73c0a9d41 100644 --- a/src/libs/vtools/dialogs/tools/dialogline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogline.cpp @@ -216,11 +216,7 @@ void DialogLine::ChosenObject(quint32 id, const SceneObject &type) */ quint32 DialogLine::GetFirstPoint() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return qvariant_cast(ui->comboBoxFirstPoint->itemData(ui->comboBoxFirstPoint->currentIndex())); -#else - return qvariant_cast(ui->comboBoxFirstPoint->currentData()); -#endif + return qvariant_cast(CURRENT_DATA(ui->comboBoxFirstPoint)); } //--------------------------------------------------------------------------------------------------------------------- @@ -230,11 +226,7 @@ quint32 DialogLine::GetFirstPoint() const */ quint32 DialogLine::GetSecondPoint() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return qvariant_cast(ui->comboBoxSecondPoint->itemData(ui->comboBoxSecondPoint->currentIndex())); -#else - return qvariant_cast(ui->comboBoxSecondPoint->currentData()); -#endif + return qvariant_cast(CURRENT_DATA(ui->comboBoxSecondPoint)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp index 9462f4f69..4ba8ed87f 100644 --- a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp @@ -298,13 +298,8 @@ void DialogPiecePath::NodeChanged(int index) if (index != -1) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const quint32 id = ui->comboBoxNodes->itemData(index).toUInt(); - #else - const quint32 id = ui->comboBoxNodes->currentData().toUInt(); - #endif const VPiecePath path = CreatePath(); - const int nodeIndex = path.indexOfNode(id); + const int nodeIndex = path.indexOfNode(CURRENT_DATA(ui->comboBoxNodes).toUInt()); if (nodeIndex != -1) { const VPieceNode &node = path.at(nodeIndex); @@ -598,11 +593,7 @@ void DialogPiecePath::InitPathTypes() //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::InitNodesList() { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const quint32 id = ui->comboBoxNodes->itemData(ui->comboBoxNodes->currentIndex()).toUInt(); -#else - const quint32 id = ui->comboBoxNodes->currentData().toUInt(); -#endif + const quint32 id = CURRENT_DATA(ui->comboBoxNodes).toUInt(); ui->comboBoxNodes->blockSignals(true); ui->comboBoxNodes->clear(); @@ -639,21 +630,10 @@ void DialogPiecePath::NodeAngleChanged(int index) const int i = ui->comboBoxNodes->currentIndex(); if (i != -1 && index != -1) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const quint32 id = ui->comboBoxNodes->itemData(i).toUInt(); - #else - const quint32 id = ui->comboBoxNodes->currentData().toUInt(); - #endif - - QListWidgetItem *rowItem = GetItemById(id); + QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxNodes).toUInt()); if (rowItem) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const PieceNodeAngle angle = static_cast(ui->comboBoxAngle->itemData(index).toUInt()); - #else - const PieceNodeAngle angle = static_cast(ui->comboBoxAngle->currentData().toUInt()); - #endif - + const PieceNodeAngle angle = static_cast(CURRENT_DATA(ui->comboBoxAngle).toUInt()); VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); rowNode.SetAngleType(angle); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); @@ -694,14 +674,7 @@ void DialogPiecePath::SetPiecePath(const VPiecePath &path) //--------------------------------------------------------------------------------------------------------------------- PiecePathType DialogPiecePath::GetType() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const PiecePathType type = - static_cast(ui->comboBoxType->itemData(ui->comboBoxType->currentIndex()).toInt()); -#else - const PiecePathType type = static_cast(ui->comboBoxType->currentData().toInt()); -#endif - - return type; + return static_cast(CURRENT_DATA(ui->comboBoxType).toInt()); } //--------------------------------------------------------------------------------------------------------------------- @@ -781,13 +754,7 @@ void DialogPiecePath::UpdateNodeSABefore(const QString &formula) const int index = ui->comboBoxNodes->currentIndex(); if (index != -1) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const quint32 id = ui->comboBoxNodes->itemData(index).toUInt(); - #else - const quint32 id = ui->comboBoxNodes->currentData().toUInt(); - #endif - - QListWidgetItem *rowItem = GetItemById(id); + QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxNodes).toUInt()); if (rowItem) { VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); @@ -803,13 +770,7 @@ void DialogPiecePath::UpdateNodeSAAfter(const QString &formula) const int index = ui->comboBoxNodes->currentIndex(); if (index != -1) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const quint32 id = ui->comboBoxNodes->itemData(index).toUInt(); - #else - const quint32 id = ui->comboBoxNodes->currentData().toUInt(); - #endif - - QListWidgetItem *rowItem = GetItemById(id); + QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxNodes).toUInt()); if (rowItem) { VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); diff --git a/src/libs/vtools/dialogs/tools/dialogpin.cpp b/src/libs/vtools/dialogs/tools/dialogpin.cpp new file mode 100644 index 000000000..1c820f7df --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogpin.cpp @@ -0,0 +1,204 @@ +/************************************************************************ + ** + ** @file dialogpin.cpp + ** @author Roman Telezhynskyi + ** @date 31 1, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 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 "dialogpin.h" +#include "ui_dialogpin.h" +#include "visualization/line/vistoolpin.h" +#include "../../tools/vabstracttool.h" +#include "../../tools/vtoolseamallowance.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogPin::DialogPin(const VContainer *data, quint32 toolId, QWidget *parent) + : DialogTool(data, toolId, parent), + ui(new Ui::DialogPin), + m_showMode(false), + m_flagPoint(false) +{ + ui->setupUi(this); + InitOkCancel(ui); + + FillComboBoxPoints(ui->comboBoxPoint); + + flagError = false; + CheckState(); + + vis = new VisToolPin(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogPin::~DialogPin() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPin::EnbleShowMode(bool disable) +{ + m_showMode = disable; + ui->comboBoxPiece->setDisabled(m_showMode); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogPin::GetPieceId() const +{ + return getCurrentObjectId(ui->comboBoxPiece); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPin::SetPieceId(quint32 id) +{ + if (ui->comboBoxPiece->count() <= 0) + { + const VPiece piece = data->GetPiece(id); + ui->comboBoxPiece->addItem(piece.GetName(), id); + } + else + { + const qint32 index = ui->comboBoxPiece->findData(id); + if (index != -1) + { + ui->comboBoxPiece->setCurrentIndex(index); + } + else + { + ui->comboBoxPiece->setCurrentIndex(0); + } + } + + CheckPieces(); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogPin::GetPointId() const +{ + return getCurrentObjectId(ui->comboBoxPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPin::SetPointId(quint32 id) +{ + setCurrentPointId(ui->comboBoxPoint, id); + + VisToolPin *point = qobject_cast(vis); + SCASSERT(point != nullptr) + point->setObject1Id(id); + + CheckPoint(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPin::SetPiecesList(const QVector &list) +{ + for (int i=0; i < list.size(); ++i) + { + const VPiece piece = data->GetPiece(list.at(i)); + ui->comboBoxPiece->addItem(piece.GetName(), list.at(i)); + } + + CheckPieces(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPin::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 DialogPin::CheckState() +{ + SCASSERT(bOk != nullptr); + bOk->setEnabled(m_flagPoint && flagError); +} + +//--------------------------------------------------------------------------------------------------------------------- +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); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPin::CheckPieces() +{ + if (not m_showMode) + { + QColor color = okColor; + if (ui->comboBoxPiece->count() <= 0) + { + flagError = false; + color = errorColor; + } + else + { + flagError = true; + color = okColor; + } + ChangeColor(ui->labelPiece, color); + CheckState(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPin::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/dialogpin.h b/src/libs/vtools/dialogs/tools/dialogpin.h new file mode 100644 index 000000000..ed13b2eb6 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogpin.h @@ -0,0 +1,73 @@ +/************************************************************************ + ** + ** @file dialogpin.h + ** @author Roman Telezhynskyi + ** @date 31 1, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 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 DIALOGPIN_H +#define DIALOGPIN_H + +#include "dialogtool.h" + +namespace Ui +{ + class DialogPin; +} + +class DialogPin : public DialogTool +{ + Q_OBJECT +public: + explicit DialogPin(const VContainer *data, quint32 toolId, QWidget *parent = nullptr); + virtual ~DialogPin(); + + void EnbleShowMode(bool disable); + + quint32 GetPieceId() const; + void SetPieceId(quint32 id); + + quint32 GetPointId() const; + void SetPointId(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_OVERRIDE; + virtual void ShowVisualization() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(DialogPin) + Ui::DialogPin *ui; + bool m_showMode; + bool m_flagPoint; + + void CheckPieces(); + void CheckPoint(); +}; + +#endif // DIALOGPIN_H diff --git a/src/libs/vtools/dialogs/tools/dialogpin.ui b/src/libs/vtools/dialogs/tools/dialogpin.ui new file mode 100644 index 000000000..682ffb9a1 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogpin.ui @@ -0,0 +1,91 @@ + + + DialogPin + + + + 0 + 0 + 194 + 114 + + + + Dialog + + + Pin tool + + + + + + + + Point: + + + + + + + + + + Piece: + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DialogPin + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogPin + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 0a10277ad..df1e38ac3 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -32,6 +32,7 @@ #include "../vpatterndb/vpiecepath.h" #include "../vpatterndb/calculator.h" #include "visualization/path/vistoolpiece.h" +#include "visualization/path/vispiecepins.h" #include "dialogpiecepath.h" #include "../../undocommands/savepiecepathoptions.h" #include "../support/dialogeditwrongformula.h" @@ -69,10 +70,15 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & : DialogTool(data, toolId, parent), ui(new Ui::DialogSeamAllowance), applyAllowed(false),// By default disabled + flagGPin(true), + flagDPin(true), + flagPPin(true), + flagGFormulas(false), m_bAddMode(true), m_mx(0), m_my(0), m_dialog(), + m_visPins(), m_qslMaterials(), m_qslPlacements(), m_conMCP(), @@ -99,6 +105,9 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & InitInternalPathsTab(); InitPatternPieceDataTab(); InitGrainlineTab(); + InitPinsTab(); + + connect(ui->tabWidget, &QTabWidget::currentChanged, this, &DialogSeamAllowance::TabChanged); flagName = true;//We have default name of piece. ChangeColor(ui->labelEditName, okColor); @@ -116,6 +125,7 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & //--------------------------------------------------------------------------------------------------------------------- DialogSeamAllowance::~DialogSeamAllowance() { + delete m_visPins; delete ui; } @@ -129,6 +139,7 @@ void DialogSeamAllowance::EnableApply(bool enable) ui->tabInternalPaths->setEnabled(applyAllowed); ui->tabPatternPieceData->setEnabled(applyAllowed); ui->tabGrainline->setEnabled(applyAllowed); + ui->tabPins->setEnabled(applyAllowed); } //--------------------------------------------------------------------------------------------------------------------- @@ -148,20 +159,26 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) ui->listWidgetCustomSA->blockSignals(true); ui->listWidgetCustomSA->clear(); - const QVector records = piece.GetCustomSARecords(); - for (int i = 0; i < records.size(); ++i) + for (int i = 0; i < piece.GetCustomSARecords().size(); ++i) { - NewCustomSA(records.at(i)); + NewCustomSA(piece.GetCustomSARecords().at(i)); } ui->listWidgetCustomSA->blockSignals(false); ui->listWidgetInternalPaths->clear(); - const QVector iPaths = piece.GetInternalPaths(); - for (int i = 0; i < iPaths.size(); ++i) + for (int i = 0; i < piece.GetInternalPaths().size(); ++i) { - NewInternalPath(iPaths.at(i)); + NewInternalPath(piece.GetInternalPaths().at(i)); } + ui->listWidgetPins->clear(); + for (int i = 0; i < piece.GetPins().size(); ++i) + { + NewPin(piece.GetPins().at(i)); + } + + InitAllPinComboboxes(); + ui->comboBoxStartPoint->blockSignals(true); ui->comboBoxStartPoint->clear(); ui->comboBoxStartPoint->blockSignals(false); @@ -184,8 +201,8 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) m_my = piece.GetMy(); ui->lineEditLetter->setText(piece.GetPatternPieceData().GetLetter()); - ui->checkBoxDetail->setChecked(piece.GetPatternPieceData().IsVisible()); - ui->checkBoxPattern->setChecked(piece.GetPatternInfo().IsVisible()); + ui->groupBoxDetailLabel->setChecked(piece.GetPatternPieceData().IsVisible()); + ui->groupBoxPatternLabel->setChecked(piece.GetPatternInfo().IsVisible()); m_conMCP.clear(); for (int i = 0; i < piece.GetPatternPieceData().GetMCPCount(); ++i) @@ -195,14 +212,22 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) UpdateList(); - ui->checkBoxGrainline->setChecked(piece.GetGrainlineGeometry().IsVisible()); - ui->lineEditRotFormula->setPlainText(piece.GetGrainlineGeometry().GetRotation()); - ui->lineEditLenFormula->setPlainText(piece.GetGrainlineGeometry().GetLength()); + ui->groupBoxGrainline->setChecked(piece.GetGrainlineGeometry().IsVisible()); + SetGrainlineAngle(piece.GetGrainlineGeometry()); + SetGrainlineLength(piece.GetGrainlineGeometry()); ui->comboBoxArrow->setCurrentIndex(int(piece.GetGrainlineGeometry().GetArrowType())); m_oldData = piece.GetPatternPieceData(); + ChangeCurrentData(ui->comboBoxDetailLabelTopLeftPin, m_oldData.TopLeftPin()); + ChangeCurrentData(ui->comboBoxDetailLabelBottomRightPin, m_oldData.BottomRightPin()); + m_oldGeom = piece.GetPatternInfo(); + ChangeCurrentData(ui->comboBoxPatternLabelTopLeftPin, m_oldGeom.TopLeftPin()); + ChangeCurrentData(ui->comboBoxPatternLabelBottomRightPin, m_oldGeom.BottomRightPin()); + m_oldGrainline = piece.GetGrainlineGeometry(); + ChangeCurrentData(ui->comboBoxGrainlineTopPin, m_oldGrainline.TopPin()); + ChangeCurrentData(ui->comboBoxGrainlineBottomPin, m_oldGrainline.BottomPin()); ValidObjects(MainPathIsValid()); EnableGrainlineRotation(); @@ -321,7 +346,7 @@ void DialogSeamAllowance::SaveData() void DialogSeamAllowance::CheckState() { SCASSERT(bOk != nullptr); - bOk->setEnabled(flagName && flagError && flagFormula); + bOk->setEnabled(flagName && flagError && flagFormula && flagDPin && flagPPin && (flagGFormulas || flagGPin)); // In case dialog hasn't apply button if ( bApply != nullptr && applyAllowed) { @@ -375,11 +400,7 @@ void DialogSeamAllowance::AddUpdate() MaterialCutPlacement mcp; QStringList qslUserMaterials = qApp->Settings()->GetUserDefinedMaterials(); -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - int i = ui->comboBoxMaterial->itemData(ui->comboBoxMaterial->currentIndex()).toInt(); -#else - int i = ui->comboBoxMaterial->currentData().toInt(); -#endif + const int i = CURRENT_DATA(ui->comboBoxMaterial).toInt(); QString qsMat = ui->comboBoxMaterial->currentText(); if (i < m_qslMaterials.count() && qsMat == m_qslMaterials[i]) { @@ -454,14 +475,13 @@ void DialogSeamAllowance::NameDetailChanged() flagName = false; ChangeColor(ui->labelEditName, Qt::red); QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); - ui->tabWidget->setTabIcon(1, icon); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabSeamAllowance), icon); } else { flagName = true; ChangeColor(ui->labelEditName, okColor); - QIcon icon; - ui->tabWidget->setTabIcon(1, icon); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabSeamAllowance), QIcon()); } } CheckState(); @@ -600,6 +620,27 @@ void DialogSeamAllowance::ShowInternalPathsContextMenu(const QPoint &pos) } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::ShowPinsContextMenu(const QPoint &pos) +{ + const int row = ui->listWidgetPins->currentRow(); + if (ui->listWidgetPins->count() == 0 || row == -1 || row >= ui->listWidgetPins->count()) + { + return; + } + + QMenu *menu = new QMenu(this); + QAction *actionDelete = menu->addAction(QIcon::fromTheme("edit-delete"), tr("Delete")); + + QAction *selectedAction = menu->exec(ui->listWidgetPins->viewport()->mapToGlobal(pos)); + if (selectedAction == actionDelete) + { + delete ui->listWidgetPins->item(row); + TabChanged(ui->tabWidget->currentIndex()); + InitAllPinComboboxes(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::ListChanged() { @@ -643,13 +684,8 @@ void DialogSeamAllowance::NodeChanged(int index) if (index != -1) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const quint32 id = ui->comboBoxNodes->itemData(index).toUInt(); - #else - const quint32 id = ui->comboBoxNodes->currentData().toUInt(); - #endif const VPiece piece = CreatePiece(); - const int nodeIndex = piece.GetPath().indexOfNode(id); + const int nodeIndex = piece.GetPath().indexOfNode(CURRENT_DATA(ui->comboBoxNodes).toUInt()); if (nodeIndex != -1) { const VPieceNode &node = piece.GetPath().at(nodeIndex); @@ -703,71 +739,54 @@ void DialogSeamAllowance::NodeChanged(int index) //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::CSAStartPointChanged(int index) { + Q_UNUSED(index); + const int row = ui->listWidgetCustomSA->currentRow(); if (ui->listWidgetCustomSA->count() == 0 || row == -1 || row >= ui->listWidgetCustomSA->count()) { return; } -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const quint32 startPoint = ui->comboBoxStartPoint->itemData(index).toUInt(); -#else - Q_UNUSED(index); - const quint32 startPoint = ui->comboBoxStartPoint->currentData().toUInt(); -#endif - QListWidgetItem *rowItem = ui->listWidgetCustomSA->item(row); SCASSERT(rowItem != nullptr); CustomSARecord record = qvariant_cast(rowItem->data(Qt::UserRole)); - record.startPoint = startPoint; + record.startPoint = CURRENT_DATA(ui->comboBoxStartPoint).toUInt(); rowItem->setData(Qt::UserRole, QVariant::fromValue(record)); } //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::CSAEndPointChanged(int index) { + Q_UNUSED(index); + const int row = ui->listWidgetCustomSA->currentRow(); if (ui->listWidgetCustomSA->count() == 0 || row == -1 || row >= ui->listWidgetCustomSA->count()) { return; } -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const quint32 endPoint = ui->comboBoxEndPoint->itemData(index).toUInt(); -#else - Q_UNUSED(index); - const quint32 endPoint = ui->comboBoxEndPoint->currentData().toUInt(); -#endif - QListWidgetItem *rowItem = ui->listWidgetCustomSA->item(row); SCASSERT(rowItem != nullptr); CustomSARecord record = qvariant_cast(rowItem->data(Qt::UserRole)); - record.endPoint = endPoint; + record.endPoint = CURRENT_DATA(ui->comboBoxEndPoint).toUInt(); rowItem->setData(Qt::UserRole, QVariant::fromValue(record)); } //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::CSAIncludeTypeChanged(int index) { + Q_UNUSED(index); + const int row = ui->listWidgetCustomSA->currentRow(); if (ui->listWidgetCustomSA->count() == 0 || row == -1 || row >= ui->listWidgetCustomSA->count()) { return; } -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const PiecePathIncludeType type = - static_cast(ui->comboBoxIncludeType->itemData(index).toUInt()); -#else - Q_UNUSED(index); - const PiecePathIncludeType type = - static_cast(ui->comboBoxIncludeType->currentData().toUInt()); -#endif - QListWidgetItem *rowItem = ui->listWidgetCustomSA->item(row); SCASSERT(rowItem != nullptr); CustomSARecord record = qvariant_cast(rowItem->data(Qt::UserRole)); - record.includeType = type; + record.includeType = static_cast(CURRENT_DATA(ui->comboBoxIncludeType).toUInt()); rowItem->setData(Qt::UserRole, QVariant::fromValue(record)); } @@ -777,23 +796,11 @@ void DialogSeamAllowance::NodeAngleChanged(int index) const int i = ui->comboBoxNodes->currentIndex(); if (i != -1 && index != -1) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const quint32 id = ui->comboBoxNodes->itemData(i).toUInt(); - #else - const quint32 id = ui->comboBoxNodes->currentData().toUInt(); - #endif - - QListWidgetItem *rowItem = GetItemById(id); + QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxNodes).toUInt()); if (rowItem) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const PieceNodeAngle angle = static_cast(ui->comboBoxAngle->itemData(index).toUInt()); - #else - const PieceNodeAngle angle = static_cast(ui->comboBoxAngle->currentData().toUInt()); - #endif - VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); - rowNode.SetAngleType(angle); + rowNode.SetAngleType(static_cast(CURRENT_DATA(ui->comboBoxAngle).toUInt())); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); ListChanged(); @@ -907,6 +914,38 @@ void DialogSeamAllowance::PathDialogClosed(int result) delete m_dialog; } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::TabChanged(int index) +{ + if (index == ui->tabWidget->indexOf(ui->tabPins) + || index == ui->tabWidget->indexOf(ui->tabGrainline) + || index == ui->tabWidget->indexOf(ui->tabPatternPieceData)) + { + if (m_visPins.isNull()) + { + m_visPins = new VisPiecePins(data); + } + + m_visPins->SetPins(GetPieceInternals(ui->listWidgetPins)); + + if (not qApp->getCurrentScene()->items().contains(m_visPins)) + { + m_visPins->VisualMode(NULL_ID); + } + else + { + m_visPins->RefreshGeometry(); + } + } + else + { + if (not m_visPins.isNull()) + { + delete m_visPins; + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::UpdateValues() { @@ -972,8 +1011,8 @@ void DialogSeamAllowance::UpdateValues() plbVal->setText(qsVal); } - bOk->setEnabled(bFormulasOK); - if (bFormulasOK == false) + flagGFormulas = bFormulasOK; + if (not flagGFormulas && not flagGPin) { QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabGrainline), icon); @@ -982,6 +1021,7 @@ void DialogSeamAllowance::UpdateValues() { ResetWarning(); } + CheckState(); } //--------------------------------------------------------------------------------------------------------------------- @@ -1034,22 +1074,14 @@ void DialogSeamAllowance::SetEditMode() //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::EnableGrainlineRotation() { - ui->lineEditRotFormula->setEnabled(ui->checkBoxGrainline->isChecked()); - ui->lineEditLenFormula->setEnabled(ui->checkBoxGrainline->isChecked()); - ui->pushButtonRot->setEnabled(ui->checkBoxGrainline->isChecked()); - ui->pushButtonLen->setEnabled(ui->checkBoxGrainline->isChecked()); - ui->pushButtonShowLen->setEnabled(ui->checkBoxGrainline->isChecked()); - ui->pushButtonShowRot->setEnabled(ui->checkBoxGrainline->isChecked()); - - if (ui->checkBoxGrainline->isChecked() == true) + if (ui->groupBoxGrainline->isChecked() == true) { UpdateValues(); + GrainlinePinPointChanged(); } else { - ChangeColor(ui->labelEditLen, okColor); - ChangeColor(ui->labelEditRot, okColor); - bOk->setEnabled(true); + flagGFormulas = true; ResetWarning(); } } @@ -1103,8 +1135,10 @@ void DialogSeamAllowance::DeployLength() //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::ResetWarning() { - QIcon icon; - ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabGrainline), icon); + if (flagGFormulas || flagGPin) + { + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabGrainline), QIcon()); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -1247,43 +1281,109 @@ void DialogSeamAllowance::DeployWidthAfterFormulaTextEdit() DeployFormula(ui->plainTextEditFormulaWidthAfter, ui->pushButtonGrowWidthAfter, m_formulaBaseWidthAfter); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::GrainlinePinPointChanged() +{ + QColor color = okColor; + const quint32 topPinId = getCurrentObjectId(ui->comboBoxGrainlineTopPin); + const quint32 bottomPinId = getCurrentObjectId(ui->comboBoxGrainlineBottomPin); + if (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId) + { + flagGPin = true; + color = okColor; + + ResetWarning(); + } + else + { + flagGPin = false; + color = errorColor; + + if (not flagGFormulas && not flagGPin) + { + QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabGrainline), icon); + } + } + ChangeColor(ui->labelGrainlineTopPin, color); + ChangeColor(ui->labelGrainlineBottomPin, color); + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DetailPinPointChanged() +{ + QColor color = okColor; + const quint32 topPinId = getCurrentObjectId(ui->comboBoxDetailLabelTopLeftPin); + const quint32 bottomPinId = getCurrentObjectId(ui->comboBoxDetailLabelBottomRightPin); + if ((topPinId == NULL_ID && bottomPinId == NULL_ID) + || (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId)) + { + flagDPin = true; + color = okColor; + + if (flagPPin) + { + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPatternPieceData), QIcon()); + } + } + else + { + flagDPin = false; + color = errorColor; + + QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPatternPieceData), icon); + } + ChangeColor(ui->labelDetailLabelTopLeftPin, color); + ChangeColor(ui->labelDetailLabelBottomRightPin, color); + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::PatternPinPointChanged() +{ + QColor color = okColor; + const quint32 topPinId = getCurrentObjectId(ui->comboBoxPatternLabelTopLeftPin); + const quint32 bottomPinId = getCurrentObjectId(ui->comboBoxPatternLabelBottomRightPin); + if ((topPinId == NULL_ID && bottomPinId == NULL_ID) + || (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId)) + { + flagPPin = true; + color = okColor; + + if (flagDPin) + { + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPatternPieceData), QIcon()); + } + } + else + { + flagPPin = false; + color = errorColor; + + QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPatternPieceData), icon); + } + ChangeColor(ui->labelPatternLabelTopLeftPin, color); + ChangeColor(ui->labelPatternLabelBottomRightPin, color); + CheckState(); +} + //--------------------------------------------------------------------------------------------------------------------- VPiece DialogSeamAllowance::CreatePiece() const { VPiece piece; - for (qint32 i = 0; i < ui->listWidgetMainPath->count(); ++i) - { - QListWidgetItem *item = ui->listWidgetMainPath->item(i); - piece.GetPath().Append(qvariant_cast(item->data(Qt::UserRole))); - } - - QVector records; - for (qint32 i = 0; i < ui->listWidgetCustomSA->count(); ++i) - { - QListWidgetItem *item = ui->listWidgetCustomSA->item(i); - records.append(qvariant_cast(item->data(Qt::UserRole))); - } - piece.SetCustomSARecords(records); - - QVector iPaths; - for (qint32 i = 0; i < ui->listWidgetInternalPaths->count(); ++i) - { - QListWidgetItem *item = ui->listWidgetInternalPaths->item(i); - iPaths.append(qvariant_cast(item->data(Qt::UserRole))); - } - piece.SetInternalPaths(iPaths); - + piece.GetPath().SetNodes(GetPieceInternals(ui->listWidgetMainPath)); + piece.SetCustomSARecords(GetPieceInternals(ui->listWidgetCustomSA)); + piece.SetInternalPaths(GetPieceInternals(ui->listWidgetInternalPaths)); + piece.SetPins(GetPieceInternals(ui->listWidgetPins)); piece.SetForbidFlipping(ui->checkBoxForbidFlipping->isChecked()); piece.SetSeamAllowance(ui->checkBoxSeams->isChecked()); piece.SetName(ui->lineEditName->text()); piece.SetMx(m_mx); piece.SetMy(m_my); - - QString width = ui->plainTextEditFormulaWidth->toPlainText(); - width.replace("\n", " "); - width = qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator()); - piece.SetFormulaSAWidth(width, m_saWidth); - + piece.SetFormulaSAWidth(GetFormulaFromUser(ui->plainTextEditFormulaWidth), m_saWidth); piece.GetPatternPieceData().SetLetter(ui->lineEditLetter->text()); for (int i = 0; i < m_conMCP.count(); ++i) @@ -1296,16 +1396,22 @@ VPiece DialogSeamAllowance::CreatePiece() const piece.GetPatternPieceData().SetLabelHeight(m_oldData.GetLabelHeight()); piece.GetPatternPieceData().SetFontSize(m_oldData.GetFontSize()); piece.GetPatternPieceData().SetRotation(m_oldData.GetRotation()); - piece.GetPatternPieceData().SetVisible(ui->checkBoxDetail->isChecked()); + piece.GetPatternPieceData().SetVisible(ui->groupBoxDetailLabel->isChecked()); + piece.GetPatternPieceData().SetTopLeftPin(getCurrentObjectId(ui->comboBoxDetailLabelTopLeftPin)); + piece.GetPatternPieceData().SetBottomRightPin(getCurrentObjectId(ui->comboBoxDetailLabelBottomRightPin)); piece.GetPatternInfo() = m_oldGeom; - piece.GetPatternInfo().SetVisible(ui->checkBoxPattern->isChecked()); + piece.GetPatternInfo().SetVisible(ui->groupBoxPatternLabel->isChecked()); + piece.GetPatternInfo().SetTopLeftPin(getCurrentObjectId(ui->comboBoxPatternLabelTopLeftPin)); + piece.GetPatternInfo().SetBottomRightPin(getCurrentObjectId(ui->comboBoxPatternLabelBottomRightPin)); piece.GetGrainlineGeometry() = m_oldGrainline; - piece.GetGrainlineGeometry().SetVisible(ui->checkBoxGrainline->isChecked()); + piece.GetGrainlineGeometry().SetVisible(ui->groupBoxGrainline->isChecked()); piece.GetGrainlineGeometry().SetRotation(GetFormulaFromUser(ui->lineEditRotFormula)); piece.GetGrainlineGeometry().SetLength(GetFormulaFromUser(ui->lineEditLenFormula)); - piece.GetGrainlineGeometry().SetArrowType(VGrainlineGeometry::ArrowType(ui->comboBoxArrow->currentIndex())); + piece.GetGrainlineGeometry().SetArrowType(static_cast(ui->comboBoxArrow->currentIndex())); + piece.GetGrainlineGeometry().SetTopPin(getCurrentObjectId(ui->comboBoxGrainlineTopPin)); + piece.GetGrainlineGeometry().SetBottomPin(getCurrentObjectId(ui->comboBoxGrainlineBottomPin)); return piece; } @@ -1346,6 +1452,21 @@ void DialogSeamAllowance::NewInternalPath(quint32 path) } } +//--------------------------------------------------------------------------------------------------------------------- +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)); + ui->listWidgetPins->addItem(item); + ui->listWidgetPins->setCurrentRow(ui->listWidgetPins->count()-1); + } +} + //--------------------------------------------------------------------------------------------------------------------- QString DialogSeamAllowance::GetPathName(quint32 path, bool reverse) const { @@ -1428,20 +1549,16 @@ bool DialogSeamAllowance::MainPathIsClockwise() const //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::InitNodesList() { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const quint32 id = ui->comboBoxNodes->itemData(ui->comboBoxNodes->currentIndex()).toUInt(); -#else - const quint32 id = ui->comboBoxNodes->currentData().toUInt(); -#endif + const quint32 id = CURRENT_DATA(ui->comboBoxNodes).toUInt(); ui->comboBoxNodes->blockSignals(true); ui->comboBoxNodes->clear(); - const VPiece piece = CreatePiece(); + const QVector nodes = GetPieceInternals(ui->listWidgetMainPath); - for (int i = 0; i < piece.GetPath().CountNodes(); ++i) + for (int i = 0; i < nodes.size(); ++i) { - const VPieceNode node = piece.GetPath().at(i); + const VPieceNode node = nodes.at(i); if (node.GetTypeTool() == Tool::NodePoint) { const QString name = GetNodeName(node); @@ -1515,13 +1632,7 @@ void DialogSeamAllowance::UpdateNodeSABefore(const QString &formula) const int index = ui->comboBoxNodes->currentIndex(); if (index != -1) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const quint32 id = ui->comboBoxNodes->itemData(index).toUInt(); - #else - const quint32 id = ui->comboBoxNodes->currentData().toUInt(); - #endif - - QListWidgetItem *rowItem = GetItemById(id); + QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxNodes).toUInt()); if (rowItem) { VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); @@ -1537,13 +1648,7 @@ void DialogSeamAllowance::UpdateNodeSAAfter(const QString &formula) const int index = ui->comboBoxNodes->currentIndex(); if (index != -1) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const quint32 id = ui->comboBoxNodes->itemData(index).toUInt(); - #else - const quint32 id = ui->comboBoxNodes->currentData().toUInt(); - #endif - - QListWidgetItem *rowItem = GetItemById(id); + QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxNodes).toUInt()); if (rowItem) { VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); @@ -1637,11 +1742,11 @@ void DialogSeamAllowance::InitCSAPoint(QComboBox *box) box->clear(); box->addItem(tr("Empty"), NULL_ID); - const VPiece piece = CreatePiece(); + const QVector nodes = GetPieceInternals(ui->listWidgetMainPath); - for (int i = 0; i < piece.GetPath().CountNodes(); ++i) + for (int i = 0; i < nodes.size(); ++i) { - const VPieceNode &node = piece.GetPath().at(i); + const VPieceNode &node = nodes.at(i); if (node.GetTypeTool() == Tool::NodePoint) { const QString name = GetNodeName(node); @@ -1650,6 +1755,35 @@ void DialogSeamAllowance::InitCSAPoint(QComboBox *box) } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::InitPinPoint(QComboBox *box) +{ + SCASSERT(box != nullptr); + + quint32 currentId = NULL_ID; + if (box->count() > 0) + { + currentId = CURRENT_DATA(box).toUInt(); + } + + box->clear(); + box->addItem(QLatin1String("<") + tr("no pin") + QLatin1String(">"), NULL_ID); + + const QVector pins = GetPieceInternals(ui->listWidgetPins); + + for (int i = 0; i < pins.size(); ++i) + { + const QSharedPointer pin = data->GetGObject(pins.at(i)); + box->addItem(pin->name(), pins.at(i)); + } + + const int index = ui->comboBoxNodes->findData(currentId); + if (index != -1) + { + box->setCurrentIndex(index); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::InitSAIncludeType() { @@ -1676,6 +1810,26 @@ void DialogSeamAllowance::InitPatternPieceDataTab() ui->lineEditLetter->setClearButtonEnabled(true); #endif + InitPinPoint(ui->comboBoxDetailLabelTopLeftPin); + InitPinPoint(ui->comboBoxDetailLabelBottomRightPin); + + connect(ui->comboBoxDetailLabelTopLeftPin, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogSeamAllowance::DetailPinPointChanged); + connect(ui->comboBoxDetailLabelBottomRightPin, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogSeamAllowance::DetailPinPointChanged); + + InitPinPoint(ui->comboBoxPatternLabelTopLeftPin); + InitPinPoint(ui->comboBoxPatternLabelBottomRightPin); + + connect(ui->comboBoxPatternLabelTopLeftPin, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogSeamAllowance::PatternPinPointChanged); + connect(ui->comboBoxPatternLabelBottomRightPin, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogSeamAllowance::PatternPinPointChanged); + connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogSeamAllowance::NameDetailChanged); m_qslMaterials << QApplication::translate("Detail", "Fabric", 0) @@ -1709,7 +1863,7 @@ void DialogSeamAllowance::InitPatternPieceDataTab() //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::InitGrainlineTab() { - connect(ui->checkBoxGrainline, &QCheckBox::toggled, this, &DialogSeamAllowance::EnableGrainlineRotation); + connect(ui->groupBoxGrainline, &QGroupBox::toggled, this, &DialogSeamAllowance::EnableGrainlineRotation); connect(ui->pushButtonRot, &QPushButton::clicked, this, &DialogSeamAllowance::EditFormula); connect(ui->pushButtonLen, &QPushButton::clicked, this, &DialogSeamAllowance::EditFormula); connect(ui->lineEditLenFormula, &QPlainTextEdit::textChanged, this, &DialogSeamAllowance::UpdateValues); @@ -1727,6 +1881,36 @@ void DialogSeamAllowance::InitGrainlineTab() m_iRotBaseHeight = ui->lineEditRotFormula->height(); m_iLenBaseHeight = ui->lineEditLenFormula->height(); + + InitPinPoint(ui->comboBoxGrainlineTopPin); + InitPinPoint(ui->comboBoxGrainlineBottomPin); + + connect(ui->comboBoxGrainlineTopPin, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogSeamAllowance::GrainlinePinPointChanged); + connect(ui->comboBoxGrainlineBottomPin, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogSeamAllowance::GrainlinePinPointChanged); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::InitPinsTab() +{ + ui->listWidgetPins->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->listWidgetPins, &QListWidget::customContextMenuRequested, this, + &DialogSeamAllowance::ShowPinsContextMenu); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::InitAllPinComboboxes() +{ + InitPinPoint(ui->comboBoxGrainlineTopPin); + InitPinPoint(ui->comboBoxGrainlineBottomPin); + + InitPinPoint(ui->comboBoxDetailLabelTopLeftPin); + InitPinPoint(ui->comboBoxDetailLabelBottomRightPin); + InitPinPoint(ui->comboBoxPatternLabelTopLeftPin); + InitPinPoint(ui->comboBoxPatternLabelBottomRightPin); } //--------------------------------------------------------------------------------------------------------------------- @@ -1793,3 +1977,45 @@ void DialogSeamAllowance::ClearFields() ui->spinBoxCutNumber->setValue(0); ui->comboBoxPlacement->setCurrentIndex(0); } + +//--------------------------------------------------------------------------------------------------------------------- +template +QVector DialogSeamAllowance::GetPieceInternals(const QListWidget *list) const +{ + SCASSERT(list != nullptr) + QVector internals; + for (qint32 i = 0; i < list->count(); ++i) + { + QListWidgetItem *item = list->item(i); + internals.append(qvariant_cast(item->data(Qt::UserRole))); + } + return internals; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetGrainlineAngle(const VGrainlineData &data) +{ + const QString formula = qApp->TrVars()->FormulaToUser(data.GetRotation(), qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployRotation(); + } + ui->lineEditRotFormula->setPlainText(formula); + + MoveCursorToEnd(ui->lineEditRotFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetGrainlineLength(const VGrainlineData &data) +{ + const QString formula = qApp->TrVars()->FormulaToUser(data.GetLength(), qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployLength(); + } + ui->lineEditLenFormula->setPlainText(formula); + + MoveCursorToEnd(ui->lineEditLenFormula); +} diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.h b/src/libs/vtools/dialogs/tools/dialogseamallowance.h index 94a8b8530..0bcb47371 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.h +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.h @@ -31,15 +31,17 @@ #include "dialogtool.h" #include "../vpatterndb/vpiece.h" -#include "../vpatterndb/vpatterninfogeometry.h" -#include "../vpatterndb/vpatternpiecedata.h" -#include "../vpatterndb/vgrainlinegeometry.h" +#include "../vpatterndb/floatItemData/vpatternlabeldata.h" +#include "../vpatterndb/floatItemData/vpiecelabeldata.h" +#include "../vpatterndb/floatItemData/vgrainlinedata.h" namespace Ui { class DialogSeamAllowance; } +class VisPiecePins; + class DialogSeamAllowance : public DialogTool { Q_OBJECT @@ -77,6 +79,7 @@ private slots: void ShowMainPathContextMenu(const QPoint &pos); void ShowCustomSAContextMenu(const QPoint &pos); void ShowInternalPathsContextMenu(const QPoint &pos); + void ShowPinsContextMenu(const QPoint &pos); void ListChanged(); void EnableSeamAllowance(bool enable); @@ -89,6 +92,7 @@ private slots: void ReturnDefAfter(); void CustomSAChanged(int row); void PathDialogClosed(int result); + void TabChanged(int index); void UpdateValues(); void SetAddMode(); @@ -115,25 +119,34 @@ private slots: void DeployWidthBeforeFormulaTextEdit(); void DeployWidthAfterFormulaTextEdit(); + void GrainlinePinPointChanged(); + void DetailPinPointChanged(); + void PatternPinPointChanged(); + private: Q_DISABLE_COPY(DialogSeamAllowance) Ui::DialogSeamAllowance *ui; bool applyAllowed; + bool flagGPin; + bool flagDPin; + bool flagPPin; + bool flagGFormulas; bool m_bAddMode; qreal m_mx; qreal m_my; - QPointer m_dialog; + QPointer m_dialog; + QPointer m_visPins; QStringList m_qslMaterials; QStringList m_qslPlacements; // temporary container for Material/Cut/Placement 3-tuples MCPContainer m_conMCP; - VPatternPieceData m_oldData; - VPatternInfoGeometry m_oldGeom; - VGrainlineGeometry m_oldGrainline; + VPieceLabelData m_oldData; + VPatternLabelData m_oldGeom; + VGrainlineData m_oldGrainline; int m_iRotBaseHeight; int m_iLenBaseHeight; int m_formulaBaseWidth; @@ -150,6 +163,7 @@ private: 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); @@ -172,12 +186,20 @@ private: void InitSeamAllowanceTab(); void InitNodesList(); void InitCSAPoint(QComboBox *box); + void InitPinPoint(QComboBox *box); void InitSAIncludeType(); void InitInternalPathsTab(); void InitPatternPieceDataTab(); void InitGrainlineTab(); + void InitPinsTab(); + void InitAllPinComboboxes(); void SetFormulaSAWidth(const QString &formula); + + template + QVector GetPieceInternals(const QListWidget *list) const; + void SetGrainlineAngle(const VGrainlineData &data); + void SetGrainlineLength(const VGrainlineData &data); }; #endif // DIALOGSEAMALLOWANCE_H diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui index 315098dc5..d9637e9e7 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui @@ -21,7 +21,7 @@ - 1 + 4 @@ -911,7 +911,7 @@ - QFormLayout::AllNonFixedFieldsGrow + QFormLayout::ExpandingFieldsGrow @@ -1029,17 +1029,82 @@ - - + + Detail label visible + + true + + + true + + + false + + + + QFormLayout::ExpandingFieldsGrow + + + + + Top left pin: + + + + + + + + + + Bottom right pin: + + + + + + + - - + + Pattern label visible + + true + + + false + + + + QFormLayout::ExpandingFieldsGrow + + + + + Top left pin: + + + + + + + + + + Bottom right pin: + + + + + + + @@ -1065,465 +1130,469 @@ Grainline - + - - - - - Grainline visible - - - - + + + Grainline visible + + + true + + + false + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Rotation: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 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 + + + + + + + + Length: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 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 + + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + + 0 + 0 + + + + Arrows: + + + + + + + + + + Top pin: + + + + + + + Bottom pin: + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Pins + + - - - - - - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - - - Rotation: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Formula wizard - - - ... - - - - :/icon/24x24/fx.png:/icon/24x24/fx.png - - - - 24 - 24 - - - - - - - - - - - :/icon/24x24/equal.png - - - - - - - - 0 - 0 - - - - - 87 - 0 - - - - - 0 - 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 - - - - - - - - Length: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Formula wizard - - - ... - - - - :/icon/24x24/fx.png:/icon/24x24/fx.png - - - - 24 - 24 - - - - - - - - - - - :/icon/24x24/equal.png - - - - - - - - 0 - 0 - - - - - 87 - 0 - - - - - 0 - 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 - - - - - - - - - 0 - 0 - 0 - - - - - - - - - 0 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - - - Arrows: - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + QAbstractItemView::InternalMove + + diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index 8ab851f48..6216b6b20 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -86,18 +86,34 @@ Q_LOGGING_CATEGORY(vDialog, "v.dialog") * @param parent parent widget */ DialogTool::DialogTool(const VContainer *data, const quint32 &toolId, QWidget *parent) - :QDialog(parent), data(data), isInitialized(false), flagName(true), flagFormula(true), flagError(true), - timerFormula(nullptr), bOk(nullptr), bApply(nullptr), spinBoxAngle(nullptr), plainTextEditFormula(nullptr), - labelResultCalculation(nullptr), labelEditNamePoint(nullptr), labelEditFormula(nullptr), - okColor(QColor(76, 76, 76)), errorColor(Qt::red), associatedTool(nullptr), - toolId(toolId), prepare(false), pointName(QString()), number(0), vis(nullptr) + : QDialog(parent), + data(data), + isInitialized(false), + flagName(true), + flagFormula(true), + flagError(true), + timerFormula(nullptr), + bOk(nullptr), + bApply(nullptr), + spinBoxAngle(nullptr), + plainTextEditFormula(nullptr), + labelResultCalculation(nullptr), + labelEditNamePoint(nullptr), + labelEditFormula(nullptr), + okColor(this->palette().color(QPalette::Active, QPalette::WindowText)), + errorColor(Qt::red), + associatedTool(nullptr), + toolId(toolId), + prepare(false), + pointName(), + number(0), + vis(nullptr) { SCASSERT(data != nullptr) timerFormula = new QTimer(this); connect(timerFormula, &QTimer::timeout, this, &DialogTool::EvalFormula); } - //--------------------------------------------------------------------------------------------------------------------- DialogTool::~DialogTool() { @@ -337,7 +353,7 @@ void DialogTool::ChangeCurrentData(QComboBox *box, const QVariant &value) const } //--------------------------------------------------------------------------------------------------------------------- -void DialogTool::MoveCursorToEnd(QPlainTextEdit *plainTextEdit) +void DialogTool::MoveCursorToEnd(QPlainTextEdit *plainTextEdit) const { SCASSERT(plainTextEdit != nullptr) QTextCursor cursor = plainTextEdit->textCursor(); @@ -446,12 +462,18 @@ QString DialogTool::DialogWarningIcon() //--------------------------------------------------------------------------------------------------------------------- QString DialogTool::GetNodeName(const VPieceNode &node) const { - const QSharedPointer obj = data->GeometricObject(node.GetId()); + const QSharedPointer obj = data->GetGObject(node.GetId()); QString name = obj->name(); - if (node.GetTypeTool() != Tool::NodePoint && node.GetReverse()) + if (node.GetTypeTool() != Tool::NodePoint) { - name = QLatin1String("- ") + name; + int bias = 0; + qApp->TrVars()->VariablesToUser(name, 0, obj->name(), bias); + + if (node.GetReverse()) + { + name = QLatin1String("- ") + name; + } } return name; @@ -470,10 +492,8 @@ void DialogTool::NewNodeItem(QListWidget *listWidget, const VPieceNode &node) case (Tool::NodeElArc): case (Tool::NodeSpline): case (Tool::NodeSplinePath): - { name = GetNodeName(node); break; - } default: qDebug()<<"Got wrong tools. Ignore."; return; @@ -918,7 +938,7 @@ void DialogTool::ChangeColor(QWidget *widget, const QColor &color) { SCASSERT(widget != nullptr) QPalette palette = widget->palette(); - palette.setColor(widget->foregroundRole(), color); + palette.setColor(QPalette::Active, widget->foregroundRole(), color); widget->setPalette(palette); } diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index 0cf0a8b90..b57bcb642 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -262,7 +262,7 @@ protected: * @brief SaveData Put dialog data in local variables */ virtual void SaveData() {} - void MoveCursorToEnd(QPlainTextEdit *plainTextEdit); + void MoveCursorToEnd(QPlainTextEdit *plainTextEdit) const; virtual bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE; quint32 DNumber(const QString &baseName) const; diff --git a/src/libs/vtools/tools/nodeDetails/nodedetails.h b/src/libs/vtools/tools/nodeDetails/nodedetails.h index 918551ec5..60b1f6b25 100644 --- a/src/libs/vtools/tools/nodeDetails/nodedetails.h +++ b/src/libs/vtools/tools/nodeDetails/nodedetails.h @@ -35,5 +35,6 @@ #include "vnodespline.h" #include "vnodesplinepath.h" #include "vtoolpiecepath.h" +#include "vtoolpin.h" #endif // NODEDETAILS_H diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp index 11099fe6a..2d060ea89 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp @@ -211,18 +211,14 @@ void VToolPiecePath::AddToFile() if (path.GetType() == PiecePathType::InternalPath) { - QVector iPaths = newDet.GetInternalPaths(); - iPaths.append(id); - newDet.SetInternalPaths(iPaths); + newDet.GetInternalPaths().append(id); } else if (path.GetType() == PiecePathType::CustomSeamAllowance) { CustomSARecord record; record.path = id; - QVector records = newDet.GetCustomSARecords(); - records.append(record); - newDet.SetCustomSARecords(records); + newDet.GetCustomSARecords().append(record); } SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_pieceId); diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpin.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpin.cpp new file mode 100644 index 000000000..da8000827 --- /dev/null +++ b/src/libs/vtools/tools/nodeDetails/vtoolpin.cpp @@ -0,0 +1,168 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 31 1, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 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 "vtoolpin.h" +#include "../../dialogs/tools/dialogpin.h" +#include "../../undocommands/savepieceoptions.h" +#include "../vtoolseamallowance.h" +#include "../vgeometry/vpointf.h" + +const QString VToolPin::ToolType = QStringLiteral("pin"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolPin *VToolPin::Create(DialogTool *dialog, VAbstractPattern *doc, VContainer *data) +{ + SCASSERT(dialog != nullptr); + DialogPin *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const quint32 pointId = dialogTool->GetPointId(); + const quint32 pieceId = dialogTool->GetPieceId(); + + return Create(0, pointId, pieceId, doc, data, Document::FullParse, Source::FromGui); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolPin *VToolPin::Create(quint32 _id, quint32 pointId, quint32 pieceId, VAbstractPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation, const QString &drawName, + const quint32 &idTool) +{ + quint32 id = _id; + if (typeCreation == Source::FromGui) + { + id = CreateNode(data, pointId); + } + else + { + QSharedPointer point; + try + { + point = data->GeometricObject(pointId); + } + catch (const VExceptionBadId &e) + { // Possible case. Parent was deleted, but the node object is still here. + Q_UNUSED(e) + return nullptr;// Just ignore + } + VPointF *pinPoint = new VPointF(*point); + pinPoint->setMode(Draw::Modeling); + data->UpdateGObject(id, pinPoint); + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + VAbstractTool::AddRecord(id, Tool::Pin, doc); + VToolPin *point = nullptr; + if (parse == Document::FullParse) + { + point = new VToolPin(doc, data, id, pointId, pieceId, typeCreation, drawName, idTool, doc); + + doc->AddTool(id, point); + if (idTool != NULL_ID) + { + //Some nodes we don't show on scene. Tool that create this nodes must free memory. + VDataTool *tool = doc->getTool(idTool); + SCASSERT(tool != nullptr) + point->setParent(tool);// Adopted by a tool + } + else + { + // Help to delete the node before each FullParse + doc->AddToolOnRemove(point); + } + } + else + { + doc->UpdateToolData(id, data); + } + return point; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VToolPin::getTagName() const +{ + return VAbstractPattern::TagPoint; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPin::AllowHover(bool enabled) +{ + Q_UNUSED(enabled) + // do nothing +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPin::AllowSelecting(bool enabled) +{ + Q_UNUSED(enabled) + // do nothing +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPin::AddToFile() +{ + QDomElement domElement = doc->createElement(getTagName()); + + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrIdObject, idNode); + 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.GetPins().append(id); + + SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_pieceId); + qApp->getUndoStack()->push(saveCommand);// First push then make a connect + VAbstractTool::data.UpdatePiece(m_pieceId, newDet);// Update piece because first save will not call lite update + connect(saveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPin::RefreshDataInFile() +{ + // do nothing +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolPin::VToolPin(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 pointId, quint32 pieceId, + const Source &typeCreation, const QString &drawName, const quint32 &idTool, QObject *qoParent) + : VAbstractNode(doc, data, id, pointId, drawName, idTool, qoParent), + m_pieceId(pieceId) +{ + ToolCreation(typeCreation); +} diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpin.h b/src/libs/vtools/tools/nodeDetails/vtoolpin.h new file mode 100644 index 000000000..9b98d0489 --- /dev/null +++ b/src/libs/vtools/tools/nodeDetails/vtoolpin.h @@ -0,0 +1,68 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 31 1, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 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 VTOOLPIN_H +#define VTOOLPIN_H + +#include + +#include "vabstractnode.h" + +class DialogTool; + +class VToolPin : public VAbstractNode +{ + Q_OBJECT +public: + static VToolPin* Create(DialogTool *dialog, VAbstractPattern *doc, VContainer *data); + static VToolPin *Create(quint32 _id, quint32 pointId, quint32 pieceId, VAbstractPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation, const QString &drawName = QString(), + const quint32 &idTool = 0); + + static const QString ToolType; + virtual QString getTagName() const Q_DECL_OVERRIDE; +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 RefreshDataInFile() Q_DECL_OVERRIDE; + virtual void ShowNode() Q_DECL_OVERRIDE {} + virtual void HideNode() Q_DECL_OVERRIDE {} +private: + Q_DISABLE_COPY(VToolPin) + + quint32 m_pieceId; + + VToolPin(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 pointId, quint32 pieceId, + const Source &typeCreation, const QString &drawName = QString(), const quint32 &idTool = 0, + QObject *qoParent = nullptr); +}; + +#endif // VTOOLPIN_H diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index 2b755c117..c0f55911e 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -58,7 +58,8 @@ HEADERS += \ $$PWD/drawTools/toolcurve/vtoolellipticalarc.h \ $$PWD/nodeDetails/vnodeellipticalarc.h \ $$PWD/vtoolseamallowance.h \ - $$PWD/nodeDetails/vtoolpiecepath.h + $$PWD/nodeDetails/vtoolpiecepath.h \ + $$PWD/nodeDetails/vtoolpin.h SOURCES += \ $$PWD/vdatatool.cpp \ @@ -114,4 +115,5 @@ SOURCES += \ $$PWD/drawTools/toolcurve/vtoolellipticalarc.cpp \ $$PWD/nodeDetails/vnodeellipticalarc.cpp \ $$PWD/vtoolseamallowance.cpp \ - $$PWD/nodeDetails/vtoolpiecepath.cpp + $$PWD/nodeDetails/vtoolpiecepath.cpp \ + $$PWD/nodeDetails/vtoolpin.cpp diff --git a/src/libs/vtools/tools/vabstracttool.cpp b/src/libs/vtools/tools/vabstracttool.cpp index 57110ad48..5d8e62684 100644 --- a/src/libs/vtools/tools/vabstracttool.cpp +++ b/src/libs/vtools/tools/vabstracttool.cpp @@ -85,32 +85,16 @@ const QString VAbstractTool::AttrInUse = QStringLiteral("inUse"); namespace { -//--------------------------------------------------------------------------------------------------------------------- -template -/** - * @brief CreateNode create new node for detail. - * @param data container. - * @param id id parent object. - * @return id for new object. - */ -quint32 CreateNode(VContainer *data, quint32 id) -{ - //We can't use exist object. Need create new. - T *node = new T(*data->GeometricObject(id).data()); - node->setMode(Draw::Modeling); - return data->AddGObject(node); -} - //--------------------------------------------------------------------------------------------------------------------- quint32 CreateNodeSpline(VContainer *data, quint32 id) { if (data->GetGObject(id)->getType() == GOType::Spline) { - return CreateNode(data, id); + return VAbstractTool::CreateNode(data, id); } else { - return CreateNode(data, id); + return VAbstractTool::CreateNode(data, id); } } @@ -119,11 +103,11 @@ quint32 CreateNodeSplinePath(VContainer *data, quint32 id) { if (data->GetGObject(id)->getType() == GOType::SplinePath) { - return CreateNode(data, id); + return VAbstractTool::CreateNode(data, id); } else { - return CreateNode(data, id); + return VAbstractTool::CreateNode(data, id); } } }//static functions diff --git a/src/libs/vtools/tools/vabstracttool.h b/src/libs/vtools/tools/vabstracttool.h index 15b99c857..48f82af93 100644 --- a/src/libs/vtools/tools/vabstracttool.h +++ b/src/libs/vtools/tools/vabstracttool.h @@ -80,6 +80,9 @@ public: QMap PointsList() const; virtual QString getTagName() const =0; virtual void ShowVisualization(bool show) =0; + + template + static quint32 CreateNode(VContainer *data, quint32 id); public slots: /** * @brief FullUpdateFromFile update tool data form file. @@ -185,4 +188,20 @@ inline void VAbstractTool::AddVisualization() vis = visual; } +//--------------------------------------------------------------------------------------------------------------------- +template +/** + * @brief CreateNode create new node for detail. + * @param data container. + * @param id id parent object. + * @return id for new object. + */ +quint32 VAbstractTool::CreateNode(VContainer *data, quint32 id) +{ + //We can't use exist object. Need create new. + T *node = new T(*data->GeometricObject(id).data()); + node->setMode(Draw::Modeling); + return data->AddGObject(node); +} + #endif // VABSTRACTTOOL_H diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 4d13e909a..f7576d5ab 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -31,8 +31,8 @@ #include "../vpatterndb/vpiecenode.h" #include "../vpatterndb/vpiecepath.h" #include "../vpatterndb/calculator.h" -#include "../vpatterndb/vpatterninfogeometry.h" -#include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/floatItemData/vpatternlabeldata.h" +#include "../vpatterndb/floatItemData/vpiecelabeldata.h" #include "nodeDetails/vnodearc.h" #include "nodeDetails/vnodeellipticalarc.h" #include "nodeDetails/vnodepoint.h" @@ -54,6 +54,7 @@ #include "../undocommands/togglepieceinlayout.h" #include "../vwidgets/vmaingraphicsview.h" #include "../vwidgets/vnobrushscalepathitem.h" +#include "../qmuparser/qmutokenparser.h" #include #include @@ -67,6 +68,7 @@ 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::AttrVersion = QStringLiteral("version"); const QString VToolSeamAllowance::AttrForbidFlipping = QStringLiteral("forbidFlipping"); @@ -74,6 +76,10 @@ const QString VToolSeamAllowance::AttrSeamAllowance = QStringLiteral("seamAllow const QString VToolSeamAllowance::AttrHeight = QStringLiteral("height"); const QString VToolSeamAllowance::AttrUnited = QStringLiteral("united"); const QString VToolSeamAllowance::AttrFont = QStringLiteral("fontSize"); +const QString VToolSeamAllowance::AttrTopLeftPin = QStringLiteral("topLeftPin"); +const QString VToolSeamAllowance::AttrBottomRightPin = QStringLiteral("bottomRightPin"); +const QString VToolSeamAllowance::AttrTopPin = QStringLiteral("topPin"); +const QString VToolSeamAllowance::AttrBottomPin = QStringLiteral("bottomPin"); //--------------------------------------------------------------------------------------------------------------------- VToolSeamAllowance::~VToolSeamAllowance() @@ -221,11 +227,27 @@ 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); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece) { QDomElement domData = doc->createElement(VAbstractPattern::TagData); - const VPatternPieceData& data = piece.GetPatternPieceData(); + const VPieceLabelData& data = piece.GetPatternPieceData(); doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? trueStr : falseStr); doc->SetAttribute(domData, AttrMx, data.GetPos().x()); @@ -235,6 +257,24 @@ void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement doc->SetAttribute(domData, AttrFont, data.GetFontSize()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, data.GetRotation()); + if (data.TopLeftPin() > NULL_ID) + { + doc->SetAttribute(domData, AttrTopLeftPin, data.TopLeftPin()); + } + else + { + domData.removeAttribute(AttrTopLeftPin); + } + + if (data.BottomRightPin() > NULL_ID) + { + doc->SetAttribute(domData, AttrBottomRightPin, data.BottomRightPin()); + } + else + { + domData.removeAttribute(AttrBottomRightPin); + } + for (int i = 0; i < data.GetMCPCount(); ++i) { const MaterialCutPlacement mcp = data.GetMCP(i); @@ -255,7 +295,7 @@ void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement void VToolSeamAllowance::AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece) { QDomElement domData = doc->createElement(VAbstractPattern::TagPatternInfo); - const VPatternInfoGeometry& geom = piece.GetPatternInfo(); + const VPatternLabelData& geom = piece.GetPatternInfo(); doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible() == true ? trueStr : falseStr); doc->SetAttribute(domData, AttrMx, geom.GetPos().x()); doc->SetAttribute(domData, AttrMy, geom.GetPos().y()); @@ -263,6 +303,25 @@ void VToolSeamAllowance::AddPatternInfo(VAbstractPattern *doc, QDomElement &domE doc->SetAttribute(domData, AttrHeight, geom.GetLabelHeight()); doc->SetAttribute(domData, AttrFont, geom.GetFontSize()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, geom.GetRotation()); + + if (geom.TopLeftPin() > NULL_ID) + { + doc->SetAttribute(domData, AttrTopLeftPin, geom.TopLeftPin()); + } + else + { + domData.removeAttribute(AttrTopLeftPin); + } + + if (geom.BottomRightPin() > NULL_ID) + { + doc->SetAttribute(domData, AttrBottomRightPin, geom.BottomRightPin()); + } + else + { + domData.removeAttribute(AttrBottomRightPin); + } + domElement.appendChild(domData); } @@ -271,13 +330,32 @@ void VToolSeamAllowance::AddGrainline(VAbstractPattern *doc, QDomElement &domEle { // grainline QDomElement domData = doc->createElement(VAbstractPattern::TagGrainline); - const VGrainlineGeometry& glGeom = piece.GetGrainlineGeometry(); + const VGrainlineData& glGeom = piece.GetGrainlineGeometry(); doc->SetAttribute(domData, VAbstractPattern::AttrVisible, glGeom.IsVisible() == true ? trueStr : falseStr); doc->SetAttribute(domData, AttrMx, glGeom.GetPos().x()); doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y()); doc->SetAttribute(domData, AttrLength, glGeom.GetLength()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, glGeom.GetRotation()); doc->SetAttribute(domData, VAbstractPattern::AttrArrows, int(glGeom.GetArrowType())); + + if (glGeom.TopPin() > NULL_ID) + { + doc->SetAttribute(domData, AttrTopPin, glGeom.TopPin()); + } + else + { + domData.removeAttribute(AttrTopPin); + } + + if (glGeom.BottomPin() > NULL_ID) + { + doc->SetAttribute(domData, AttrBottomPin, glGeom.BottomPin()); + } + else + { + domData.removeAttribute(AttrBottomPin); + } + domElement.appendChild(domData); } @@ -400,33 +478,39 @@ void VToolSeamAllowance::Highlight(quint32 id) void VToolSeamAllowance::UpdateLabel() { const VPiece detail = VAbstractTool::data.GetPiece(id); - const VPatternPieceData& data = detail.GetPatternPieceData(); + const VPieceLabelData& labelData = detail.GetPatternPieceData(); - if (data.IsVisible() == true) + if (labelData.IsVisible() == true) { + QPointF pos; + qreal labelWidth = 0; + qreal labelHeight = 0; + const VTextGraphicsItem::MoveType type = FindLabelGeometry(labelData, labelWidth, labelHeight, pos); + m_dataLabel->SetMoveType(type); + QFont fnt = qApp->font(); { - const int iFS = data.GetFontSize(); + const int iFS = labelData.GetFontSize(); iFS < MIN_FONT_SIZE ? fnt.setPixelSize(MIN_FONT_SIZE) : fnt.setPixelSize(iFS); } m_dataLabel->SetFont(fnt); - m_dataLabel->SetSize(data.GetLabelWidth(), data.GetLabelHeight()); - m_dataLabel->UpdateData(detail.GetName(), data); - QPointF pt = data.GetPos(); + m_dataLabel->SetSize(labelWidth, labelHeight); + m_dataLabel->UpdateData(detail.GetName(), labelData); + QRectF rectBB; - rectBB.setTopLeft(pt); + rectBB.setTopLeft(pos); rectBB.setWidth(m_dataLabel->boundingRect().width()); rectBB.setHeight(m_dataLabel->boundingRect().height()); qreal dX; qreal dY; - if (m_dataLabel->IsContained(rectBB, data.GetRotation(), dX, dY) == false) + if (m_dataLabel->IsContained(rectBB, labelData.GetRotation(), dX, dY) == false) { - pt.setX(pt.x() + dX); - pt.setY(pt.y() + dY); + pos.setX(pos.x() + dX); + pos.setY(pos.y() + dY); } - m_dataLabel->setPos(pt); - m_dataLabel->setRotation(data.GetRotation()); + m_dataLabel->setPos(pos); + m_dataLabel->setRotation(labelData.GetRotation()); m_dataLabel->Update(); m_dataLabel->show(); } @@ -443,10 +527,16 @@ void VToolSeamAllowance::UpdateLabel() void VToolSeamAllowance::UpdatePatternInfo() { const VPiece detail = VAbstractTool::data.GetPiece(id); - const VPatternInfoGeometry& geom = detail.GetPatternInfo(); + const VPatternLabelData& geom = detail.GetPatternInfo(); if (geom.IsVisible() == true) { + QPointF pos; + qreal labelWidth = 0; + qreal labelHeight = 0; + const VTextGraphicsItem::MoveType type = FindLabelGeometry(geom, labelWidth, labelHeight, pos); + m_patternInfo->SetMoveType(type); + QFont fnt = qApp->font(); int iFS = geom.GetFontSize(); if (iFS < MIN_FONT_SIZE) @@ -455,23 +545,22 @@ void VToolSeamAllowance::UpdatePatternInfo() } fnt.setPixelSize(iFS); m_patternInfo->SetFont(fnt); - m_patternInfo->SetSize(geom.GetLabelWidth(), geom.GetLabelHeight()); + m_patternInfo->SetSize(labelWidth, labelHeight); m_patternInfo->UpdateData(doc, getData()->size(), getData()->height()); - QPointF pt = geom.GetPos(); QRectF rectBB; - rectBB.setTopLeft(pt); + rectBB.setTopLeft(pos); rectBB.setWidth(m_patternInfo->boundingRect().width()); rectBB.setHeight(m_patternInfo->boundingRect().height()); qreal dX; qreal dY; if (m_patternInfo->IsContained(rectBB, geom.GetRotation(), dX, dY) == false) { - pt.setX(pt.x() + dX); - pt.setY(pt.y() + dY); + pos.setX(pos.x() + dX); + pos.setY(pos.y() + dY); } - m_patternInfo->setPos(pt); + m_patternInfo->setPos(pos); m_patternInfo->setRotation(geom.GetRotation()); m_patternInfo->Update(); m_patternInfo->GetTextLines() > 0 ? m_patternInfo->show() : m_patternInfo->hide(); @@ -489,34 +578,23 @@ void VToolSeamAllowance::UpdatePatternInfo() void VToolSeamAllowance::UpdateGrainline() { const VPiece detail = VAbstractTool::data.GetPiece(id); - const VGrainlineGeometry& geom = detail.GetGrainlineGeometry(); + const VGrainlineData& geom = detail.GetGrainlineGeometry(); if (geom.IsVisible() == true) { - qreal dRotation; - qreal dLength; - try - { - QString qsFormula; - qsFormula = geom.GetRotation().replace("\n", " "); - qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + QPointF pos; + qreal dRotation = 0; + qreal dLength = 0; - Calculator cal1; - dRotation = cal1.EvalFormula(VDataTool::data.PlainVariables(), qsFormula); - - qsFormula = geom.GetLength().replace("\n", " "); - qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); - Calculator cal2; - dLength = cal2.EvalFormula(VDataTool::data.PlainVariables(), qsFormula); - } - catch(qmu::QmuParserError &e) + const VGrainlineItem::MoveType type = FindGrainlineGeometry(geom, dLength, dRotation, pos); + if (type == VGrainlineItem::Error) { - Q_UNUSED(e); m_grainLine->hide(); return; } - m_grainLine->UpdateGeometry(geom.GetPos(), dRotation, ToPixel(dLength, *VDataTool::data.GetPatternUnit()), + m_grainLine->SetMoveType(type); + m_grainLine->UpdateGeometry(pos, dRotation, ToPixel(dLength, *VDataTool::data.GetPatternUnit()), geom.GetArrowType()); m_grainLine->show(); } @@ -662,7 +740,7 @@ void VToolSeamAllowance::SaveResizeGrainline(qreal dLength) VPiece newDet = oldDet; dLength = FromPixel(dLength, *VDataTool::data.GetPatternUnit()); - newDet.GetGrainlineGeometry().SetLength(qApp->LocaleToString(dLength)); + newDet.GetGrainlineGeometry().SetLength(QString().setNum(dLength)); SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, id); resizeCommand->setText(tr("resize grainline")); connect(resizeCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); @@ -676,7 +754,7 @@ void VToolSeamAllowance::SaveRotateGrainline(qreal dRot, const QPointF& ptPos) VPiece newDet = oldDet; dRot = qRadiansToDegrees(dRot); - newDet.GetGrainlineGeometry().SetRotation(qApp->LocaleToString(dRot)); + newDet.GetGrainlineGeometry().SetRotation(QString().setNum(dRot)); newDet.GetGrainlineGeometry().SetPos(ptPos); SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, id); rotateCommand->setText(tr("rotate grainline")); @@ -690,22 +768,9 @@ void VToolSeamAllowance::SaveRotateGrainline(qreal dRot, const QPointF& ptPos) */ void VToolSeamAllowance::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - if (scene()->views().count() > 0) - { - const QPoint pt0 = scene()->views().at(0)->mapFromScene(0, 0); - const QPoint pt = scene()->views().at(0)->mapFromScene(0, 100); - - const QPoint p = pt - pt0; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) - const qreal dScale = qSqrt(QPoint::dotProduct(p, p)); -#else - const qreal dScale = qSqrt(p.x() * p.x() + p.y() * p.y()); -#endif //QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) - m_grainLine->SetScale(100/dScale); - } - - if (m_dataLabel->IsIdle() == false || m_patternInfo->IsIdle() == false || m_grainLine->IsIdle() == false) + if ((m_dataLabel->IsIdle() == false + || m_patternInfo->IsIdle() == false + || m_grainLine->IsIdle() == false) && not isSelected()) { setSelected(true); } @@ -729,6 +794,7 @@ void VToolSeamAllowance::AddToFile() //custom seam allowance AddCSARecords(doc, domElement, piece.GetCustomSARecords()); AddInternalPaths(doc, domElement, piece.GetInternalPaths()); + AddPins(doc, domElement, piece.GetPins()); AddPiece *addDet = new AddPiece(domElement, doc, piece, m_drawName); connect(addDet, &AddPiece::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); @@ -761,6 +827,7 @@ void VToolSeamAllowance::RefreshDataInFile() AddNodes(doc, domElement, piece); AddCSARecords(doc, domElement, piece.GetCustomSARecords()); AddInternalPaths(doc, domElement, piece.GetInternalPaths()); + AddPins(doc, domElement, piece.GetPins()); } } } @@ -1009,6 +1076,7 @@ VToolSeamAllowance::VToolSeamAllowance(VAbstractPattern *doc, VContainer *data, InitNodes(detail, scene); InitCSAPaths(detail); InitInternalPaths(detail); + InitPins(detail); this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); RefreshGeometry(); @@ -1088,6 +1156,114 @@ void VToolSeamAllowance::SaveDialogChange() UpdateLabel(); } +//--------------------------------------------------------------------------------------------------------------------- +VPieceItem::MoveType VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &labelWidth, + qreal &labelHeight, QPointF &pos) +{ + const quint32 topLeftPin = labelData.TopLeftPin(); + const quint32 bottomRightPin = labelData.BottomRightPin(); + + if (topLeftPin != NULL_ID && bottomRightPin != NULL_ID) + { + try + { + const auto topLeftPinPoint = VAbstractTool::data.GeometricObject(topLeftPin); + const auto bottomRightPinPoint = VAbstractTool::data.GeometricObject(bottomRightPin); + + const QRectF labelRect = QRectF(*topLeftPinPoint, *bottomRightPinPoint); + labelWidth = qAbs(labelRect.width()); + labelHeight = qAbs(labelRect.height()); + + pos = labelRect.topLeft(); + + return VTextGraphicsItem::OnlyRotatable; + } + catch(const VExceptionBadId &) + { + // do nothing. + } + } + + labelWidth = labelData.GetLabelWidth(); + labelHeight = labelData.GetLabelHeight(); + pos = labelData.GetPos(); + return VTextGraphicsItem::AllModifications; +} + +//--------------------------------------------------------------------------------------------------------------------- +VPieceItem::MoveType VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, qreal &length, + qreal &rotationAngle, QPointF &pos) +{ + const quint32 topPin = geom.TopPin(); + const quint32 bottomPin = geom.BottomPin(); + + if (topPin != NULL_ID && bottomPin != NULL_ID) + { + try + { + const auto topPinPoint = VAbstractTool::data.GeometricObject(topPin); + const auto bottomPinPoint = VAbstractTool::data.GeometricObject(bottomPin); + + QLineF grainline(*bottomPinPoint, *topPinPoint); + length = FromPixel(grainline.length(), *VDataTool::data.GetPatternUnit()); + rotationAngle = grainline.angle(); + + if (not VFuzzyComparePossibleNulls(rotationAngle, 0)) + { + grainline.setAngle(0); + } + + pos = grainline.p1(); + + return VPieceItem::NotMovable; + } + catch(const VExceptionBadId &) + { + // do nothing. + } + } + + bool isResizable = false; + bool isRotatable = false; + try + { + isRotatable = qmu::QmuTokenParser::IsSingle(geom.GetRotation()); + + Calculator cal1; + rotationAngle = cal1.EvalFormula(VAbstractTool::data.PlainVariables(), geom.GetRotation()); + + isResizable = qmu::QmuTokenParser::IsSingle(geom.GetLength()); + + Calculator cal2; + length = cal2.EvalFormula(VAbstractTool::data.PlainVariables(), geom.GetLength()); + } + catch(qmu::QmuParserError &e) + { + Q_UNUSED(e); + return VPieceItem::Error; + } + + pos = geom.GetPos(); + + if (isResizable && isRotatable) + { + return VPieceItem::AllModifications; + } + else + { + if (isResizable) + { + return VPieceItem::OnlyResizable; + } + + if (isRotatable) + { + return VPieceItem::OnlyRotatable; + } + } + return VPieceItem::OnlyMovable; +} + //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::InitNodes(const VPiece &detail, VMainGraphicsScene *scene) { @@ -1117,25 +1293,32 @@ void VToolSeamAllowance::InitNodes(const VPiece &detail, VMainGraphicsScene *sce //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::InitCSAPaths(const VPiece &detail) { - QVector records = detail.GetCustomSARecords(); - for (int i = 0; i < records.size(); ++i) + for (int i = 0; i < detail.GetCustomSARecords().size(); ++i) { - doc->IncrementReferens(records.at(i).path); + doc->IncrementReferens(detail.GetCustomSARecords().at(i).path); } } //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::InitInternalPaths(const VPiece &detail) { - QVector records = detail.GetInternalPaths(); - for (int i = 0; i < records.size(); ++i) + for (int i = 0; i < detail.GetInternalPaths().size(); ++i) { - VToolPiecePath *tool = qobject_cast(doc->getTool(records.at(i))); + VToolPiecePath *tool = qobject_cast(doc->getTool(detail.GetInternalPaths().at(i))); SCASSERT(tool != nullptr); tool->setParentItem(this); tool->SetParentType(ParentType::Item); tool->show(); - doc->IncrementReferens(records.at(i)); + doc->IncrementReferens(detail.GetInternalPaths().at(i)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSeamAllowance::InitPins(const VPiece &detail) +{ + for (int i = 0; i < detail.GetPins().size(); ++i) + { + doc->IncrementReferens(detail.GetPins().at(i)); } } diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index abbb13c13..f402721dc 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -58,6 +58,7 @@ public: static const QString TagCSA; static const QString TagRecord; static const QString TagIPaths; + static const QString TagPins; static const QString AttrVersion; static const QString AttrForbidFlipping; @@ -65,6 +66,10 @@ public: static const QString AttrHeight; static const QString AttrUnited; static const QString AttrFont; + static const QString AttrTopLeftPin; + static const QString AttrBottomRightPin; + static const QString AttrTopPin; + static const QString AttrBottomPin; void Remove(bool ask); @@ -72,6 +77,7 @@ public: static void AddCSARecord(VAbstractPattern *doc, QDomElement &domElement, const CustomSARecord &record); 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 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); @@ -145,10 +151,15 @@ private: void RefreshGeometry(); void SaveDialogChange(); + VPieceItem::MoveType FindLabelGeometry(const VPatternLabelData &labelData, qreal &labelWidth, qreal &labelHeight, + QPointF &pos); + VPieceItem::MoveType FindGrainlineGeometry(const VGrainlineData &geom, qreal &length, qreal &rotationAngle, + QPointF &pos); void InitNodes(const VPiece &detail, VMainGraphicsScene *scene); void InitCSAPaths(const VPiece &detail); void InitInternalPaths(const VPiece &detail); + void InitPins(const VPiece &detail); template Tool* InitTool(VMainGraphicsScene *scene, quint32 toolId); diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index f912fd98c..1e9442ac3 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -67,6 +67,7 @@ #include "nodeDetails/vnodespline.h" #include "nodeDetails/vnodesplinepath.h" #include "nodeDetails/vtoolpiecepath.h" +#include "nodeDetails/vtoolpin.h" #include "vdatatool.h" #include "vnodedetail.h" #include "vtoolseamallowance.h" @@ -198,6 +199,37 @@ QVector GetPiece2InternalPaths(VAbstractPattern *doc, quint32 id) return QVector(); } +//--------------------------------------------------------------------------------------------------------------------- +QVector GetPiece2Pins(VAbstractPattern *doc, quint32 id) +{ + const QDomElement tool = doc->elementById(id); + if (tool.isNull()) + { + VException e(QString("Can't get tool by id='%1'.").arg(id)); + throw e; + } + + const QDomNodeList nodesList = tool.childNodes(); + for (qint32 i = 0; i < nodesList.size(); ++i) + { + const QDomElement element = nodesList.at(i).toElement(); + if (not element.isNull() && element.tagName() == VToolUnionDetails::TagDetail && i+1 == 2) + { + const QDomNodeList detList = element.childNodes(); + for (qint32 j = 0; j < detList.size(); ++j) + { + const QDomElement element = detList.at(j).toElement(); + if (not element.isNull() && element.tagName() == VToolSeamAllowance::TagPins) + { + return VAbstractPattern::ParsePiecePins(element); + } + } + } + } + + return QVector(); +} + //--------------------------------------------------------------------------------------------------------------------- QString DrawName(VAbstractPattern *doc, quint32 d1id, quint32 d2id) { @@ -350,6 +382,29 @@ quint32 AddNodePoint(const VPieceNode &node, const VToolUnionDetailsInitData &in return id; } +//--------------------------------------------------------------------------------------------------------------------- +quint32 AddPin(quint32 id, const VToolUnionDetailsInitData &initData, quint32 idTool, QVector &children, + const QString &drawName, qreal dx, qreal dy, quint32 pRotate, qreal angle) +{ + QScopedPointer point(new VPointF(*initData.data->GeometricObject(id))); + point->setMode(Draw::Modeling); + + if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID) + { + BiasRotatePoint(point.data(), dx, dy, *initData.data->GeometricObject(pRotate), angle); + } + + QScopedPointer point1(new VPointF(*point)); + + const quint32 idObject = initData.data->AddGObject(point.take()); + children.append(idObject); + point1->setMode(Draw::Modeling); + const quint32 idPin = initData.data->AddGObject(point1.take()); + VToolPin::Create(idPin, idObject, 0, initData.doc, initData.data, Document::FullParse, Source::FromTool, drawName, + idTool); + return idPin; +} + //--------------------------------------------------------------------------------------------------------------------- quint32 AddNodeArc(const VPieceNode &node, const VToolUnionDetailsInitData &initData, quint32 idTool, QVector &children, const QString &drawName, qreal dx, qreal dy, @@ -649,6 +704,12 @@ void SaveInternalPathsChildren(VAbstractPattern *doc, quint32 id, const QVector< SaveChildren(doc, id, doc->createElement(VToolSeamAllowance::TagIPaths), children); } +//--------------------------------------------------------------------------------------------------------------------- +void SavePinsChildren(VAbstractPattern *doc, quint32 id, const QVector &children) +{ + SaveChildren(doc, id, doc->createElement(VToolSeamAllowance::TagPins), children); +} + //--------------------------------------------------------------------------------------------------------------------- QVector GetChildren(VAbstractPattern *doc, quint32 id, const QString &tagName) { @@ -701,6 +762,12 @@ QVector GetInternalPathsChildren(VAbstractPattern *doc, quint32 id) return GetChildren(doc, id, VToolSeamAllowance::TagIPaths); } +//--------------------------------------------------------------------------------------------------------------------- +QVector GetPinChildren(VAbstractPattern *doc, quint32 id) +{ + return GetChildren(doc, id, VToolSeamAllowance::TagPins); +} + //--------------------------------------------------------------------------------------------------------------------- quint32 TakeNextId(QVector &children) { @@ -958,12 +1025,10 @@ void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { - QVector newList = newDetail.GetCustomSARecords(); - const QVector oldList = d.GetCustomSARecords(); QVector nodeChildren; - for(int i=0; i < oldList.size(); ++i) + for(int i=0; i < d.GetCustomSARecords().size(); ++i) { - CustomSARecord record = oldList.at(i); + CustomSARecord record = d.GetCustomSARecords().at(i); const VPiecePath path = initData.data->GetPiecePath(record.path); VPiecePath newPath = path; newPath.Clear();//Clear nodes @@ -975,21 +1040,19 @@ void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector VToolPiecePath::Create(idPath, newPath, NULL_ID, initData.scene, initData.doc, initData.data, initData.parse, Source::FromTool, drawName, id); record.path = idPath; - newList.append(record); + newDetail.GetCustomSARecords().append(record); nodeChildren.prepend(idPath); } children += nodeChildren; - newDetail.SetCustomSARecords(newList); } //--------------------------------------------------------------------------------------------------------------------- void CreateUnitedCSA(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quint32 id, const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { - const QVector d1Records = d1.GetCustomSARecords(); - for (int i = 0; i < d1Records.size(); ++i) + for (int i = 0; i < d1.GetCustomSARecords().size(); ++i) { - newDetail.AppendCustomSARecord(d1Records.at(i)); + newDetail.GetCustomSARecords().append(d1.GetCustomSARecords().at(i)); } QVector children; @@ -1002,12 +1065,10 @@ void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { - QVector newList = newDetail.GetInternalPaths(); - const QVector oldList = d.GetInternalPaths(); QVector nodeChildren; - for(int i=0; i < oldList.size(); ++i) + for(int i=0; i < d.GetInternalPaths().size(); ++i) { - const VPiecePath path = initData.data->GetPiecePath(oldList.at(i)); + const VPiecePath path = initData.data->GetPiecePath(d.GetInternalPaths().at(i)); VPiecePath newPath = path; newPath.Clear();//Clear nodes @@ -1018,11 +1079,10 @@ void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector const quint32 idPath = initData.data->AddPiecePath(newPath); VToolPiecePath::Create(idPath, newPath, NULL_ID, initData.scene, initData.doc, initData.data, initData.parse, Source::FromTool, drawName, id); - newList.append(idPath); + newDetail.GetInternalPaths().append(idPath); nodeChildren.prepend(idPath); } children += nodeChildren; - newDetail.SetInternalPaths(newList); } //--------------------------------------------------------------------------------------------------------------------- @@ -1030,10 +1090,9 @@ void CreateUnitedInternalPaths(VPiece &newDetail, const VPiece &d1, const VPiece const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { - const QVector d1Internal = d1.GetInternalPaths(); - for (int i = 0; i < d1Internal.size(); ++i) + for (int i = 0; i < d1.GetInternalPaths().size(); ++i) { - newDetail.AppendInternalPath(d1Internal.at(i)); + newDetail.GetInternalPaths().append(d1.GetInternalPaths().at(i)); } QVector children; @@ -1042,6 +1101,35 @@ void CreateUnitedInternalPaths(VPiece &newDetail, const VPiece &d1, const VPiece SaveInternalPathsChildren(initData.doc, id, children); } +//--------------------------------------------------------------------------------------------------------------------- +void CreateUnitedDetailPins(VPiece &newDetail, const VPiece &d, QVector &children, quint32 idTool, + const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, + quint32 pRotate, qreal angle) +{ + QVector nodeChildren; + for(int i=0; i < d.GetPins().size(); ++i) + { + const quint32 id = AddPin(d.GetPins().at(i), initData, idTool, children, drawName, dx, dy, pRotate, angle); + newDetail.GetPins().append(id); + nodeChildren.prepend(id); + } + children += nodeChildren; +} + +//--------------------------------------------------------------------------------------------------------------------- +void CreateUnitedPins(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quint32 id, const QString &drawName, + const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) +{ + for (int i = 0; i < d1.GetPins().size(); ++i) + { + newDetail.GetPins().append(d1.GetPins().at(i)); + } + + QVector children; + CreateUnitedDetailPins(newDetail, d2, children, id, drawName, initData, dx, dy, pRotate, angle); + SavePinsChildren(initData.doc, id, children); +} + //--------------------------------------------------------------------------------------------------------------------- void UpdateUnitedNodes(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) @@ -1161,6 +1249,24 @@ void UpdateUnitedDetailInternalPaths(quint32 id, const VToolUnionDetailsInitData UpdateUnitedDetailPaths(initData, dx, dy, pRotate, angle, records, GetInternalPathsChildren(initData.doc, id)); } +//--------------------------------------------------------------------------------------------------------------------- +void UpdateUnitedDetailPins(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, + quint32 pRotate, qreal angle, const QVector &records) +{ + QVector children = GetPinChildren(initData.doc, id); + + for (int i = 0; i < records.size(); ++i) + { + QScopedPointer point(new VPointF(*initData.data->GeometricObject(records.at(i)))); + point->setMode(Draw::Modeling); + if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID) + { + BiasRotatePoint(point.data(), dx, dy, *initData.data->GeometricObject(pRotate), angle); + } + initData.data->UpdateGObject(TakeNextId(children), point.take()); + } +} + //--------------------------------------------------------------------------------------------------------------------- void CreateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) @@ -1176,6 +1282,7 @@ void CreateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, q CreateUnitedNodes(newDetail, d1, d2, id, drawName, initData, dx, dy, pRotate, angle); CreateUnitedCSA(newDetail, d1, d2, id, drawName, initData, dx, dy, pRotate, angle); CreateUnitedInternalPaths(newDetail, d1, d2, id, drawName, initData, dx, dy, pRotate, angle); + CreateUnitedPins(newDetail, d1, d2, id, drawName, initData, dx, dy, pRotate, angle); newDetail.SetName(QObject::tr("United detail")); QString formulaSAWidth = d1.GetFormulaSAWidth(); @@ -1211,6 +1318,7 @@ void UpdateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, q UpdateUnitedNodes(id, initData, dx, dy, pRotate, angle); UpdateUnitedDetailCSA(id, initData, dx, dy, pRotate, angle, GetPiece2CSAPaths(initData.doc, id)); UpdateUnitedDetailInternalPaths(id, initData, dx, dy, pRotate, angle, GetPiece2InternalPaths(initData.doc, id)); + UpdateUnitedDetailPins(id, initData, dx, dy, pRotate, angle, GetPiece2Pins(initData.doc, id)); } //--------------------------------------------------------------------------------------------------------------------- @@ -1427,6 +1535,7 @@ void VToolUnionDetails::AddDetail(QDomElement &domElement, const VPiece &d) cons //custom seam allowance VToolSeamAllowance::AddCSARecords(doc, det, d.GetCustomSARecords()); VToolSeamAllowance::AddInternalPaths(doc, det, d.GetInternalPaths()); + VToolSeamAllowance::AddPins(doc, det, d.GetPins()); domElement.appendChild(det); } diff --git a/src/libs/vtools/undocommands/addpiece.cpp b/src/libs/vtools/undocommands/addpiece.cpp index 9f4ccc2ff..a99b6747f 100644 --- a/src/libs/vtools/undocommands/addpiece.cpp +++ b/src/libs/vtools/undocommands/addpiece.cpp @@ -65,6 +65,7 @@ void AddPiece::undo() DecrementReferences(m_detail.GetPath().GetNodes()); DecrementReferences(m_detail.GetCustomSARecords()); DecrementReferences(m_detail.GetInternalPaths()); + DecrementReferences(m_detail.GetPins()); } else { diff --git a/src/libs/vtools/undocommands/deletepiece.cpp b/src/libs/vtools/undocommands/deletepiece.cpp index a466b69ea..b1c97a45d 100644 --- a/src/libs/vtools/undocommands/deletepiece.cpp +++ b/src/libs/vtools/undocommands/deletepiece.cpp @@ -105,6 +105,7 @@ void DeletePiece::redo() DecrementReferences(m_detail.GetPath().GetNodes()); DecrementReferences(m_detail.GetCustomSARecords()); DecrementReferences(m_detail.GetInternalPaths()); + DecrementReferences(m_detail.GetPins()); emit NeedFullParsing(); // Doesn't work when UnionDetail delete detail. } else diff --git a/src/libs/vtools/undocommands/savepieceoptions.cpp b/src/libs/vtools/undocommands/savepieceoptions.cpp index 9328d8d40..91b587586 100644 --- a/src/libs/vtools/undocommands/savepieceoptions.cpp +++ b/src/libs/vtools/undocommands/savepieceoptions.cpp @@ -38,9 +38,9 @@ #include "../vmisc/logging.h" #include "../vmisc/def.h" #include "../vpatterndb/vpiecenode.h" -#include "../vpatterndb/vpatterninfogeometry.h" -#include "../vpatterndb/vpatternpiecedata.h" -#include "../vpatterndb/vgrainlinegeometry.h" +#include "../vpatterndb/floatItemData/vpatternlabeldata.h" +#include "../vpatterndb/floatItemData/vpiecelabeldata.h" +#include "../vpatterndb/floatItemData/vgrainlinedata.h" #include "../tools/vtoolseamallowance.h" #include "vundocommand.h" @@ -75,10 +75,12 @@ void SavePieceOptions::undo() VToolSeamAllowance::AddNodes(doc, domElement, m_oldDet); VToolSeamAllowance::AddCSARecords(doc, domElement, m_oldDet.GetCustomSARecords()); VToolSeamAllowance::AddInternalPaths(doc, domElement, m_oldDet.GetInternalPaths()); + VToolSeamAllowance::AddPins(doc, domElement, m_oldDet.GetPins()); IncrementReferences(m_oldDet.MissingNodes(m_newDet)); IncrementReferences(m_oldDet.MissingCSAPath(m_newDet)); IncrementReferences(m_oldDet.MissingInternalPaths(m_newDet)); + IncrementReferences(m_oldDet.MissingPins(m_newDet)); emit NeedLiteParsing(Document::LiteParse); } else @@ -104,10 +106,12 @@ void SavePieceOptions::redo() VToolSeamAllowance::AddNodes(doc, domElement, m_newDet); VToolSeamAllowance::AddCSARecords(doc, domElement, m_newDet.GetCustomSARecords()); VToolSeamAllowance::AddInternalPaths(doc, domElement, m_newDet.GetInternalPaths()); + VToolSeamAllowance::AddPins(doc, domElement, m_newDet.GetPins()); DecrementReferences(m_oldDet.MissingNodes(m_newDet)); DecrementReferences(m_oldDet.MissingCSAPath(m_newDet)); DecrementReferences(m_oldDet.MissingInternalPaths(m_newDet)); + DecrementReferences(m_oldDet.MissingPins(m_newDet)); emit NeedLiteParsing(Document::LiteParse); } diff --git a/src/libs/vtools/visualization/line/vistoolpin.cpp b/src/libs/vtools/visualization/line/vistoolpin.cpp new file mode 100644 index 000000000..edc6b2df5 --- /dev/null +++ b/src/libs/vtools/visualization/line/vistoolpin.cpp @@ -0,0 +1,69 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 31 1, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 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 "vistoolpin.h" +#include "../vwidgets/vsimplepoint.h" +#include "../vgeometry/vpointf.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolPin::VisToolPin(const VContainer *data, QGraphicsItem *parent) + : VisLine(data, parent), + m_point() +{ + this->mainColor = Qt::red; + this->setZValue(2);// Show on top real tool + + m_point = new VSimplePoint(NULL_ID, mainColor, *Visualization::data->GetPatternUnit(), &factor); + m_point->SetPointHighlight(true); + m_point->setParentItem(this); + m_point->SetVisualizationMode(true); + m_point->setVisible(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolPin::~VisToolPin() +{ + if (not m_point.isNull()) + { + delete m_point; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolPin::RefreshGeometry() +{ + if (object1Id > NULL_ID) + { + const QSharedPointer point = Visualization::data->GeometricObject(object1Id); + + m_point->SetOnlyPoint(mode == Mode::Creation); + m_point->RefreshGeometry(*point); + m_point->setVisible(true); + } +} + diff --git a/src/libs/vtools/visualization/line/vistoolpin.h b/src/libs/vtools/visualization/line/vistoolpin.h new file mode 100644 index 000000000..abb013a44 --- /dev/null +++ b/src/libs/vtools/visualization/line/vistoolpin.h @@ -0,0 +1,51 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 31 1, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 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 VISTOOLPIN_H +#define VISTOOLPIN_H + +#include "visline.h" + +class VSimplePoint; + +class VisToolPin : public VisLine +{ + Q_OBJECT +public: + explicit VisToolPin(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolPin() Q_DECL_OVERRIDE; + + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ToolPin)}; +private: + Q_DISABLE_COPY(VisToolPin) + QPointer m_point; +}; + +#endif // VISTOOLPIN_H diff --git a/src/libs/vtools/visualization/path/vispath.cpp b/src/libs/vtools/visualization/path/vispath.cpp index ff1bbdabf..9fc28c8c4 100644 --- a/src/libs/vtools/visualization/path/vispath.cpp +++ b/src/libs/vtools/visualization/path/vispath.cpp @@ -34,6 +34,7 @@ #include "../vmisc/vabstractapplication.h" #include "../vpatterndb/vcontainer.h" #include "../visualization.h" +#include "../vwidgets/vsimplepoint.h" //--------------------------------------------------------------------------------------------------------------------- VisPath::VisPath(const VContainer *data, QGraphicsItem *parent) @@ -59,3 +60,23 @@ void VisPath::AddOnScene() { AddItem(this); } + +//--------------------------------------------------------------------------------------------------------------------- +VSimplePoint *VisPath::GetPoint(QVector &points, quint32 i, const QColor &color) +{ + if (not points.isEmpty() && static_cast(points.size() - 1) >= i) + { + return points.at(static_cast(i)); + } + else + { + VSimplePoint *point = new VSimplePoint(NULL_ID, color, *Visualization::data->GetPatternUnit(), &factor); + point->SetPointHighlight(true); + point->setParentItem(this); + point->SetVisualizationMode(true); + points.append(point); + + return point; + } + return nullptr; +} diff --git a/src/libs/vtools/visualization/path/vispath.h b/src/libs/vtools/visualization/path/vispath.h index d1cd1e686..569e104a5 100644 --- a/src/libs/vtools/visualization/path/vispath.h +++ b/src/libs/vtools/visualization/path/vispath.h @@ -40,6 +40,8 @@ #include "../visualization.h" #include "../vmisc/def.h" +class VSimplePoint; + class VisPath : public Visualization, public QGraphicsPathItem { Q_OBJECT @@ -52,6 +54,8 @@ public: protected: virtual void InitPen() Q_DECL_OVERRIDE; virtual void AddOnScene() Q_DECL_OVERRIDE; + + VSimplePoint *GetPoint(QVector &points, quint32 i, const QColor &color); private: Q_DISABLE_COPY(VisPath) }; diff --git a/src/libs/vtools/visualization/path/vispiecepins.cpp b/src/libs/vtools/visualization/path/vispiecepins.cpp new file mode 100644 index 000000000..7c17fff7d --- /dev/null +++ b/src/libs/vtools/visualization/path/vispiecepins.cpp @@ -0,0 +1,84 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 14 2, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 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 "vispiecepins.h" +#include "../vwidgets/vsimplepoint.h" +#include "../vgeometry/vpointf.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisPiecePins::VisPiecePins(const VContainer *data, QGraphicsItem *parent) + : VisPath(data, parent), + m_points(), + m_pins() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +VisPiecePins::~VisPiecePins() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisPiecePins::RefreshGeometry() +{ + HideAllItems(); + + for (int i = 0; i < m_pins.size(); ++i) + { + VSimplePoint *point = GetPoint(static_cast(i), supportColor); + point->SetOnlyPoint(false); + const QSharedPointer p = Visualization::data->GeometricObject(m_pins.at(i)); + point->RefreshGeometry(*p); + point->setVisible(true); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisPiecePins::SetPins(const QVector &pins) +{ + m_pins = pins; +} + +//--------------------------------------------------------------------------------------------------------------------- +VSimplePoint *VisPiecePins::GetPoint(quint32 i, const QColor &color) +{ + return VisPath::GetPoint(m_points, i, color); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisPiecePins::HideAllItems() +{ + for (int i=0; i < m_points.size(); ++i) + { + if (QGraphicsEllipseItem *item = m_points.at(i)) + { + item->setVisible(false); + } + } +} + diff --git a/src/libs/vtools/visualization/path/vispiecepins.h b/src/libs/vtools/visualization/path/vispiecepins.h new file mode 100644 index 000000000..6e874099d --- /dev/null +++ b/src/libs/vtools/visualization/path/vispiecepins.h @@ -0,0 +1,57 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 14 2, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 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 VISPIECEPINS_H +#define VISPIECEPINS_H + +#include "vispath.h" + +class VSimplePoint; + +class VisPiecePins : public VisPath +{ + Q_OBJECT +public: + VisPiecePins(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisPiecePins(); + + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + void SetPins(const QVector &pins); + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::PiecePins)}; +private: + Q_DISABLE_COPY(VisPiecePins) + QVector m_points; + QVector m_pins; + + VSimplePoint *GetPoint(quint32 i, const QColor &color); + + void HideAllItems(); +}; + +#endif // VISPIECEPINS_H diff --git a/src/libs/vtools/visualization/path/vistoolpiecepath.cpp b/src/libs/vtools/visualization/path/vistoolpiecepath.cpp index a5e294f2a..46bc4ea55 100644 --- a/src/libs/vtools/visualization/path/vistoolpiecepath.cpp +++ b/src/libs/vtools/visualization/path/vistoolpiecepath.cpp @@ -91,21 +91,7 @@ void VisToolPiecePath::mousePressEvent(QGraphicsSceneMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- VSimplePoint *VisToolPiecePath::GetPoint(quint32 i, const QColor &color) { - if (not m_points.isEmpty() && static_cast(m_points.size() - 1) >= i) - { - return m_points.at(static_cast(i)); - } - else - { - VSimplePoint *point = new VSimplePoint(NULL_ID, color, *Visualization::data->GetPatternUnit(), &factor); - point->SetPointHighlight(true); - point->setParentItem(this); - point->SetVisualizationMode(true); - m_points.append(point); - - return point; - } - return nullptr; + return VisPath::GetPoint(m_points, i, color); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/visualization.pri b/src/libs/vtools/visualization/visualization.pri index 6231eacf9..1f822647e 100644 --- a/src/libs/vtools/visualization/visualization.pri +++ b/src/libs/vtools/visualization/visualization.pri @@ -40,7 +40,9 @@ HEADERS += \ $$PWD/line/operation/vistoolmove.h \ $$PWD/path/vistoolellipticalarc.h \ $$PWD/path/vistoolpiece.h \ - $$PWD/path/vistoolpiecepath.h + $$PWD/path/vistoolpiecepath.h \ + $$PWD/line/vistoolpin.h \ + $$PWD/path/vispiecepins.h SOURCES += \ $$PWD/visualization.cpp \ @@ -81,4 +83,6 @@ SOURCES += \ $$PWD/line/operation/vistoolmove.cpp \ $$PWD/path/vistoolellipticalarc.cpp \ $$PWD/path/vistoolpiece.cpp \ - $$PWD/path/vistoolpiecepath.cpp + $$PWD/path/vistoolpiecepath.cpp \ + $$PWD/line/vistoolpin.cpp \ + $$PWD/path/vispiecepins.cpp diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index 954216651..124093cd3 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include "../vmisc/def.h" #include "../vmisc/vmath.h" @@ -44,6 +46,7 @@ #define RESIZE_RECT_SIZE 10 #define ROTATE_CIRC_R 7 #define ACTIVE_Z 10 +#define LINE_PEN_WIDTH 3 //--------------------------------------------------------------------------------------------------------------------- /** @@ -65,8 +68,10 @@ VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent) m_ptFinish(), m_ptCenter(), m_dAngle(0), - m_eArrowType(VGrainlineGeometry::atBoth) + m_eArrowType(ArrowType::atBoth), + m_penWidth(LINE_PEN_WIDTH) { + setAcceptHoverEvents(true); m_inactiveZ = 5; Reset(); UpdateRectangle(); @@ -79,6 +84,21 @@ VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent) VGrainlineItem::~VGrainlineItem() {} +//--------------------------------------------------------------------------------------------------------------------- +QPainterPath VGrainlineItem::shape() const +{ + if (m_eMode == mNormal) + { + return MainShape(); + } + else + { + QPainterPath path; + path.addPolygon(m_polyBound); + return path; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VGrainlineItem::paint paints the item content @@ -92,45 +112,26 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption Q_UNUSED(pWidget) pP->save(); QColor clr = Qt::black; - pP->setPen(QPen(clr, 3)); - QPointF pt1(0, 0); - QPointF pt2; - - pt2.setX(pt1.x() + m_dLength * cos(m_dRotation)); - pt2.setY(pt1.y() - m_dLength * sin(m_dRotation)); + pP->setPen(QPen(clr, m_penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); pP->setRenderHints(QPainter::Antialiasing); // line - pP->drawLine(pt1, pt2); + const QLineF mainLine = MainLine(); + pP->drawLine(mainLine.p1(), mainLine.p2()); pP->setBrush(clr); - QPolygonF poly; - QPointF ptA; + + m_dScale = GetScale(); qreal dArrLen = ARROW_LENGTH*m_dScale; - if (m_eArrowType != VGrainlineGeometry::atRear) + if (m_eArrowType != ArrowType::atRear) { // first arrow - poly << pt1; - ptA.setX(pt1.x() + dArrLen*cos(m_dRotation + ARROW_ANGLE)); - ptA.setY(pt1.y() - dArrLen*sin(m_dRotation + ARROW_ANGLE)); - poly << ptA; - ptA.setX(pt1.x() + dArrLen*cos(m_dRotation - ARROW_ANGLE)); - ptA.setY(pt1.y() - dArrLen*sin(m_dRotation - ARROW_ANGLE)); - poly << ptA; - pP->drawPolygon(poly); + pP->drawPolygon(FirstArrow(dArrLen)); } - if (m_eArrowType != VGrainlineGeometry::atFront) + if (m_eArrowType != ArrowType::atFront) { // second arrow - poly.clear(); - poly << pt2; - ptA.setX(pt2.x() + dArrLen*cos(M_PI + m_dRotation + ARROW_ANGLE)); - ptA.setY(pt2.y() - dArrLen*sin(M_PI + m_dRotation + ARROW_ANGLE)); - poly << ptA; - ptA.setX(pt2.x() + dArrLen*cos(M_PI + m_dRotation - ARROW_ANGLE)); - ptA.setY(pt2.y() - dArrLen*sin(M_PI + m_dRotation - ARROW_ANGLE)); - poly << ptA; - pP->drawPolygon(poly); + pP->drawPolygon(SecondArrow(dArrLen)); } if (m_eMode != mNormal) @@ -175,7 +176,6 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption pP->drawArc(iX - iR, -iY, iR, iR, 90*16, -90*16); pP->restore(); } - } pP->restore(); } @@ -187,8 +187,7 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption * @param dRotation rotation of the grainline in [degrees] * @param dLength length of the grainline in user's units */ -void VGrainlineItem::UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength, - VGrainlineGeometry::ArrowType eAT) +void VGrainlineItem::UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength, ArrowType eAT) { m_dRotation = qDegreesToRadians(dRotation); m_dLength = dLength; @@ -271,18 +270,6 @@ bool VGrainlineItem::IsContained(const QPointF& pt, qreal dRot, qreal &dX, qreal return bInside; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief VGrainlineItem::SetScale sets the scale for keeping the arrows of constant size - * @param dScale scale factor - */ -void VGrainlineItem::SetScale(qreal dScale) -{ - m_dScale = dScale; - UpdateRectangle(); - Update(); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief VGrainlineItem::mousePressEvent handles left button mouse press events @@ -290,8 +277,14 @@ void VGrainlineItem::SetScale(qreal dScale) */ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) { - if (pME->button() == Qt::LeftButton) + if (pME->button() == Qt::LeftButton && pME->type() != QEvent::GraphicsSceneMouseDoubleClick) { + if (m_moveType == NotMovable) + { + pME->ignore(); + return; + } + m_ptStartPos = pos(); m_ptStartMove = pME->scenePos(); m_dStartLength = m_dLength; @@ -299,25 +292,52 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) m_dAngle = GetAngle(mapToParent(pME->pos())); m_ptRotCenter = m_ptCenter; - if (m_eMode != mRotate) + if (m_moveType == OnlyRotatable) { - if (m_polyResize.containsPoint(pME->pos(), Qt::OddEvenFill) == true) - { - m_eMode = mResize; - SetOverrideCursor(Qt::SizeFDiagCursor); - } - else + if (m_eMode != mRotate) { m_eMode = mMove; SetOverrideCursor(cursorArrowCloseHand, 1, 1); } + else + { + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } + + setZValue(ACTIVE_Z); + Update(); } - else + else if (m_moveType == OnlyMovable) { + m_eMode = mMove; SetOverrideCursor(cursorArrowCloseHand, 1, 1); + + setZValue(ACTIVE_Z); + Update(); + } + else // All modifications + { + if (m_eMode != mRotate) + { + if (m_polyResize.containsPoint(pME->pos(), Qt::OddEvenFill) == true) + { + m_eMode = mResize; + SetOverrideCursor(Qt::SizeFDiagCursor); + } + else + { + m_eMode = mMove; + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } + } + else + { + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } + + setZValue(ACTIVE_Z); + Update(); } - setZValue(ACTIVE_Z); - Update(); } } @@ -413,7 +433,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { if (bShort == true) { - if (m_bReleased == true) + if (m_bReleased == true && m_moveType != OnlyResizable && m_moveType != OnlyMovable) { m_eMode = mRotate; Update(); @@ -448,6 +468,20 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) } } +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineItem::hoverEnterEvent(QGraphicsSceneHoverEvent *pME) +{ + m_penWidth = LINE_PEN_WIDTH + 1; + VPieceItem::hoverEnterEvent(pME); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *pME) +{ + m_penWidth = LINE_PEN_WIDTH; + VPieceItem::hoverLeaveEvent(pME); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VGrainlineItem::UpdateBox updates the item @@ -511,6 +545,12 @@ void VGrainlineItem::UpdateRectangle() prepareGeometryChange(); } +//--------------------------------------------------------------------------------------------------------------------- +double VGrainlineItem::GetAngle(const QPointF &pt) const +{ + return -VPieceItem::GetAngle(pt); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VGrainlineItem::Rotate rotates point pt around ptCenter by angle dAng [rad] @@ -548,3 +588,102 @@ QPointF VGrainlineItem::GetInsideCorner(int i, qreal dDist) const return m_polyBound.at(i) + pt1 + pt2; } + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetScale gets the scale for keeping the arrows of constant size + */ +qreal VGrainlineItem::GetScale() const +{ + if (scene()->views().count() > 0) + { + const QPoint pt0 = scene()->views().at(0)->mapFromScene(0, 0); + const QPoint pt = scene()->views().at(0)->mapFromScene(0, 100); + + const QPoint p = pt - pt0; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) + qreal dScale = qSqrt(QPoint::dotProduct(p, p)); +#else + qreal dScale = qSqrt(p.x() * p.x() + p.y() * p.y()); +#endif //QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) + dScale = 100.0/dScale; + if (dScale < 1.0) + { + dScale = 1.0; + } + return dScale; + } + + return 1.0; +} + +//--------------------------------------------------------------------------------------------------------------------- +QLineF VGrainlineItem::MainLine() const +{ + QPointF pt1; + QPointF pt2(pt1.x() + m_dLength * cos(m_dRotation), pt1.y() - m_dLength * sin(m_dRotation)); + return QLineF(pt1, pt2); +} + +//--------------------------------------------------------------------------------------------------------------------- +QPolygonF VGrainlineItem::FirstArrow(qreal dArrLen) const +{ + const QPointF pt1 = MainLine().p1(); + QPolygonF poly; + poly << pt1; + poly << QPointF(pt1.x() + dArrLen*cos(m_dRotation + ARROW_ANGLE), + pt1.y() - dArrLen*sin(m_dRotation + ARROW_ANGLE)); + poly << QPointF(pt1.x() + dArrLen*cos(m_dRotation - ARROW_ANGLE), + pt1.y() - dArrLen*sin(m_dRotation - ARROW_ANGLE)); + return poly; +} + +//--------------------------------------------------------------------------------------------------------------------- +QPolygonF VGrainlineItem::SecondArrow(qreal dArrLen) const +{ + const QPointF pt2 = MainLine().p2(); + QPolygonF poly; + poly << pt2; + poly << QPointF(pt2.x() + dArrLen*cos(M_PI + m_dRotation + ARROW_ANGLE), + pt2.y() - dArrLen*sin(M_PI + m_dRotation + ARROW_ANGLE)); + poly << QPointF(pt2.x() + dArrLen*cos(M_PI + m_dRotation - ARROW_ANGLE), + pt2.y() - dArrLen*sin(M_PI + m_dRotation - ARROW_ANGLE)); + return poly; +} + +//--------------------------------------------------------------------------------------------------------------------- +QPainterPath VGrainlineItem::MainShape() const +{ + QPainterPath path; + const QLineF mainLine = MainLine(); + QPainterPath linePath; + linePath.moveTo(mainLine.p1()); + linePath.lineTo(mainLine.p2()); + linePath.closeSubpath(); + + QPainterPathStroker stroker; + stroker.setWidth(m_penWidth); + path.addPath((stroker.createStroke(linePath) + linePath).simplified()); + path.closeSubpath(); + + const qreal dArrLen = ARROW_LENGTH*GetScale(); + if (m_eArrowType != ArrowType::atRear) + { + // first arrow + QPainterPath polyPath; + polyPath.addPolygon(FirstArrow(dArrLen)); + path.addPath((stroker.createStroke(polyPath) + polyPath).simplified()); + path.closeSubpath(); + } + + if (m_eArrowType != ArrowType::atFront) + { + // second arrow + QPainterPath polyPath; + polyPath.addPolygon(SecondArrow(dArrLen)); + path.addPath((stroker.createStroke(polyPath) + polyPath).simplified()); + path.closeSubpath(); + } + return path; +} diff --git a/src/libs/vwidgets/vgrainlineitem.h b/src/libs/vwidgets/vgrainlineitem.h index 613119033..e0fd31fe2 100644 --- a/src/libs/vwidgets/vgrainlineitem.h +++ b/src/libs/vwidgets/vgrainlineitem.h @@ -30,7 +30,7 @@ #define VGRAINLINEITEM_H #include "vpieceitem.h" -#include "../vpatterndb/vgrainlinegeometry.h" +#include "../vpatterndb/floatItemData/vgrainlinedata.h" class VGrainlineItem : public VPieceItem { @@ -39,12 +39,12 @@ public: explicit VGrainlineItem(QGraphicsItem* pParent = nullptr); virtual ~VGrainlineItem(); + virtual QPainterPath shape() const Q_DECL_OVERRIDE; + virtual void paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption, QWidget* pWidget) Q_DECL_OVERRIDE; - void UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength, - VGrainlineGeometry::ArrowType eAT); + void UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength, ArrowType eAT); bool IsContained(const QPointF &pt, qreal dRot, qreal &dX, qreal &dY) const; - void SetScale(qreal dScale); signals: void SignalResized(qreal dLength); @@ -54,9 +54,13 @@ protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE; virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE; virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE; + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* pME) Q_DECL_OVERRIDE; + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* pME) Q_DECL_OVERRIDE; virtual void Update() Q_DECL_OVERRIDE; void UpdateRectangle(); + virtual double GetAngle(const QPointF &pt) const Q_DECL_OVERRIDE; + QPointF Rotate(const QPointF& pt, const QPointF& ptCenter, qreal dAng) const; QPointF GetInsideCorner(int i, qreal dDist) const; @@ -75,7 +79,16 @@ private: QPointF m_ptFinish; QPointF m_ptCenter; qreal m_dAngle; - VGrainlineGeometry::ArrowType m_eArrowType; + ArrowType m_eArrowType; + int m_penWidth; + + qreal GetScale() const; + + QLineF MainLine() const; + QPolygonF FirstArrow(qreal dArrLen) const; + QPolygonF SecondArrow(qreal dArrLen) const; + + QPainterPath MainShape() const; }; #endif // VGRAINLINEITEM_H diff --git a/src/libs/vwidgets/vpieceitem.cpp b/src/libs/vwidgets/vpieceitem.cpp index f7f969fed..5117b8c8c 100644 --- a/src/libs/vwidgets/vpieceitem.cpp +++ b/src/libs/vwidgets/vpieceitem.cpp @@ -38,6 +38,7 @@ VPieceItem::VPieceItem(QGraphicsItem *pParent) m_eMode(VPieceItem::mNormal), m_bReleased(false), m_ptRotCenter(), + m_moveType(AllModifications), m_inactiveZ(1) { m_rectBoundingBox.setTopLeft(QPointF(0, 0)); @@ -106,3 +107,15 @@ double VPieceItem::GetAngle(const QPointF &pt) const } } +//--------------------------------------------------------------------------------------------------------------------- +VPieceItem::MoveType VPieceItem::GetMoveType() const +{ + return m_moveType; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceItem::SetMoveType(const MoveType &moveType) +{ + m_moveType = moveType; + setAcceptHoverEvents(m_moveType != NotMovable); +} diff --git a/src/libs/vwidgets/vpieceitem.h b/src/libs/vwidgets/vpieceitem.h index 7b3306044..b97a95fb3 100644 --- a/src/libs/vwidgets/vpieceitem.h +++ b/src/libs/vwidgets/vpieceitem.h @@ -36,6 +36,8 @@ class VPieceItem : public QGraphicsObject { Q_OBJECT public: + enum MoveType {AllModifications, OnlyResizable, OnlyRotatable, OnlyMovable, NotMovable, Error}; + explicit VPieceItem(QGraphicsItem* pParent = nullptr); virtual ~VPieceItem(); @@ -46,7 +48,8 @@ public: void Reset(); bool IsIdle() const; - double GetAngle(const QPointF &pt) const; + MoveType GetMoveType() const; + void SetMoveType(const MoveType &moveType); signals: void SignalMoved(const QPointF &ptPos); @@ -59,13 +62,16 @@ protected: mResize, mRotate }; - QRectF m_rectBoundingBox; - Mode m_eMode; - bool m_bReleased; - QPointF m_ptRotCenter; + QRectF m_rectBoundingBox; + Mode m_eMode; + bool m_bReleased; + QPointF m_ptRotCenter; + MoveType m_moveType; qreal m_inactiveZ; + virtual double GetAngle(const QPointF &pt) const; + private: Q_DISABLE_COPY(VPieceItem) }; diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index 7a12002f1..150562ddf 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -359,7 +359,7 @@ bool VTextGraphicsItem::IsContained(QRectF rectBB, qreal dRot, qreal &dX, qreal * @param qsName name of detail * @param data reference to VPatternPieceData */ -void VTextGraphicsItem::UpdateData(const QString &qsName, const VPatternPieceData &data) +void VTextGraphicsItem::UpdateData(const QString &qsName, const VPieceLabelData &data) { m_tm.Update(qsName, data); } @@ -401,7 +401,7 @@ int VTextGraphicsItem::GetFontSize() const */ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) { - if (pME->button() == Qt::LeftButton) + if (pME->button() == Qt::LeftButton && pME->type() != QEvent::GraphicsSceneMouseDoubleClick) { // record the parameters of the mouse press. Specially record the position // of the press as the origin for the following operations @@ -413,28 +413,47 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) m_dRotation = rotation(); // in rotation mode, do not do any changes here, because user might want to // rotate the label more. - if (m_eMode != mRotate) + + if (m_moveType == OnlyRotatable) { - // if user pressed the button inside the resize square, switch to resize mode - if (m_rectResize.contains(pME->pos()) == true) + if (m_eMode != mRotate) { - m_eMode = mResize; - SetOverrideCursor(Qt::SizeFDiagCursor); + m_eMode = mRotate; + SetOverrideCursor(cursorArrowCloseHand, 1, 1); } else { - // if user pressed the button outside the resize square, switch to move mode - m_eMode = mMove; SetOverrideCursor(cursorArrowCloseHand, 1, 1); } + + setZValue(ACTIVE_Z); + Update(); } - else + else // All modifications { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); + if (m_eMode != mRotate) + { + // if user pressed the button inside the resize square, switch to resize mode + if (m_rectResize.contains(pME->pos()) == true) + { + m_eMode = mResize; + SetOverrideCursor(Qt::SizeFDiagCursor); + } + else + { + // if user pressed the button outside the resize square, switch to move mode + m_eMode = mMove; + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } + } + else + { + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } + // raise the label and redraw it + setZValue(ACTIVE_Z); + UpdateBox(); } - // raise the label and redraw it - setZValue(ACTIVE_Z); - UpdateBox(); } } @@ -553,7 +572,10 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { // in rotate mode, if user did just press/release, switch to move mode if (bShort == true) { - m_eMode = mMove; + if (m_moveType != OnlyRotatable) + { + m_eMode = mMove; + } UpdateBox(); } else diff --git a/src/libs/vwidgets/vtextgraphicsitem.h b/src/libs/vwidgets/vtextgraphicsitem.h index 7d5d77ed9..7c5d99bad 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.h +++ b/src/libs/vwidgets/vtextgraphicsitem.h @@ -64,7 +64,7 @@ public: void Clear(); void SetSize(qreal fW, qreal fH); bool IsContained(QRectF rectBB, qreal dRot, qreal& dX, qreal& dY) const; - void UpdateData(const QString& qsName, const VPatternPieceData& data); + void UpdateData(const QString& qsName, const VPieceLabelData& data); void UpdateData(const VAbstractPattern* pDoc, qreal dSize, qreal dHeight); int GetTextLines() const;