Resolved issue #726. Improve Move tool. Add optional rotate option.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-11-13 19:39:11 +02:00
parent d3c4b7a7fc
commit 3510843e44
22 changed files with 1669 additions and 122 deletions

View File

@ -30,6 +30,7 @@
- [#759] Add place label tool.
- [#771] Improve tool Point at intersection of arc and line.
- [#772] New tool Duplicate detail.
- [#726] Improve Move tool. Add optional rotate option.
# Version 0.5.1
- [#683] Tool Seam allowance's dialog is off screen on small resolutions.

View File

@ -1849,6 +1849,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolMove(VPE::VProperty *property)
case 4: // AttrLength
i->SetFormulaLength(value.value<VFormula>());
break;
case 42: // AttrRotationAngle
i->SetFormulaRotationAngle(value.value<VFormula>());
break;
default:
qWarning()<<"Unknown property type. id = "<<id;
break;
@ -2416,6 +2419,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolMove(QGraphicsItem *item)
AddPropertyOperationSuffix(i, tr("Suffix:"));
AddPropertyFormula(tr("Angle:"), i->GetFormulaAngle(), AttrAngle);
AddPropertyFormula(tr("Length:"), i->GetFormulaLength(), AttrLength);
AddPropertyFormula(tr("Rotation angle:"), i->GetFormulaRotationAngle(), AttrRotationAngle);
}
//---------------------------------------------------------------------------------------------------------------------
@ -3232,6 +3236,10 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolMove()
QVariant valueLength;
valueLength.setValue(i->GetFormulaLength());
idToProperty[AttrLength]->setValue(valueLength);
QVariant valueRotationAngle;
valueRotationAngle.setValue(i->GetFormulaRotationAngle());
idToProperty[AttrRotationAngle]->setValue(valueRotationAngle);
}
//---------------------------------------------------------------------------------------------------------------------

Binary file not shown.

Before

Width:  |  Height:  |  Size: 447 B

After

Width:  |  Height:  |  Size: 694 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 963 B

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 519 B

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 963 B

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -13,11 +13,11 @@
width="32"
height="32"
id="svg2985"
inkscape:version="0.91 r"
sodipodi:docname="moving.svg"
inkscape:export-filename="/home/dismine/CAD/Valentina_0.5.x/valentina/src/app/valentina/share/resources/toolicon/32x32/moving@2x.png"
inkscape:export-xdpi="183.09656"
inkscape:export-ydpi="183.09656">
inkscape:version="0.92.2 (unknown)"
sodipodi:docname="move.svg"
inkscape:export-filename="/home/dismine/CAD/Valentina_0.5.x/valentina/src/app/valentina/share/resources/toolicon/32x32/moving.png"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96">
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
@ -31,9 +31,9 @@
inkscape:window-height="1056"
id="namedview12"
showgrid="false"
inkscape:zoom="11.189427"
inkscape:cx="-20.65711"
inkscape:cy="17.916139"
inkscape:zoom="7.9121197"
inkscape:cx="26.876036"
inkscape:cy="2.994024"
inkscape:window-x="65"
inkscape:window-y="24"
inkscape:window-maximized="1"
@ -125,17 +125,22 @@
</metadata>
<path
inkscape:connector-curvature="0"
style="fill:#f70000;fill-opacity:1;stroke:#f70000;stroke-width:2.40142107;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
style="fill:none;fill-opacity:1;stroke:#f70000;stroke-width:0.942;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:1.884,0.942;stroke-dashoffset:0;stroke-opacity:1"
id="path2985-2-9-3-5"
d="m 30.568187,4.1706391 a 2.6159858,2.697521 0 0 1 -5.231971,0 2.6159858,2.697521 0 1 1 5.231971,0 z" />
d="m 27.614916,7.8995439 a 3.6438753,3.4726345 0 0 1 -7.28775,0 3.6438753,3.4726345 0 1 1 7.28775,0 z" />
<path
inkscape:connector-curvature="0"
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:2.56853676;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:1.99787223;stroke-linejoin:round;stroke-miterlimit:4.9000001;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="path2985-2-9-3"
d="m 7.2847855,27.609193 a 2.8452232,2.8373884 0 0 1 -5.6904461,0 2.8452232,2.8373884 0 1 1 5.6904461,0 z" />
d="m 5.8006808,28.556891 a 2.245837,2.1748076 0 0 1 -4.491674,0 2.245837,2.1748076 0 1 1 4.491674,0 z" />
<path
style="fill:#000000"
d="m 11.486434,17.126775 c 2.481404,-2.537702 4.476369,-4.643916 4.433253,-4.680479 -0.04311,-0.03657 -1.317602,-0.561306 -2.832196,-1.166099 -1.514591,-0.604792 -2.814212,-1.144975 -2.88805,-1.200408 -0.160041,-0.1201531 -0.19441,-0.5437624 -0.0514,-0.6335841 0.05555,-0.034889 3.284489,-0.5101456 7.175416,-1.0561174 4.929476,-0.6916999 7.132384,-0.9638939 7.265617,-0.8977485 0.105166,0.052213 0.193428,0.1730439 0.196138,0.2685214 0.01187,0.4157045 -1.315064,13.7895066 -1.378777,13.8970036 -0.0937,0.158105 -0.525661,0.158503 -0.662446,6.27e-4 -0.05963,-0.06883 -0.656883,-1.257143 -1.327228,-2.640692 -0.670344,-1.383553 -1.268068,-2.600588 -1.328272,-2.704524 -0.09543,-0.164748 -0.696798,0.411264 -4.69077,4.492961 -2.519722,2.575067 -4.623899,4.682504 -4.675953,4.683197 -0.05205,6.8e-4 -0.9128181,-0.749445 -1.912808,-1.666958 C 7.6399461,22.749856 6.987936,22.08043 6.9827926,21.947499 6.9774627,21.809845 8.4825598,20.198776 11.486437,17.126747 Z"
style="fill:#000000;stroke-width:0.76000571"
d="m 8.1563158,20.824225 c 1.9000532,-1.914281 3.4276332,-3.503077 3.3946172,-3.530658 -0.03301,-0.02758 -1.008909,-0.423413 -2.1686596,-0.87963 -1.1597492,-0.456218 -2.1548917,-0.863698 -2.2114305,-0.905511 -0.1225468,-0.09064 -0.1488639,-0.41018 -0.03936,-0.477937 0.042538,-0.0263 2.5149915,-0.38482 5.4943411,-0.796669 3.774587,-0.521773 5.461392,-0.727099 5.56341,-0.677201 0.08053,0.03939 0.148112,0.130531 0.150187,0.202554 0.0091,0.313581 -1.006966,10.401929 -1.055753,10.483017 -0.07175,0.119264 -0.402509,0.11956 -0.507247,4.72e-4 -0.04566,-0.05192 -0.502986,-0.948309 -1.016282,-1.991969 -0.513294,-1.043666 -0.970982,-1.961719 -1.017081,-2.040122 -0.07306,-0.124274 -0.533551,0.310232 -3.591805,3.389206 -1.9293941,1.942465 -3.5405993,3.532182 -3.5804585,3.532705 -0.039858,5.13e-4 -0.6989601,-0.565333 -1.4646707,-1.257448 -0.8951316,-0.809115 -1.3943872,-1.314087 -1.3983256,-1.414362 -0.00408,-0.103826 1.148398,-1.319126 3.4485193,-3.63647 z"
id="path3347"
inkscape:connector-curvature="0" />
<path
inkscape:connector-curvature="0"
id="path3349"
d="m 21.919204,15.169117 c -0.500441,-0.09947 -1.256361,-0.327666 -1.679806,-0.507122 -0.923565,-0.391401 -2.391376,-1.418481 -2.733125,-1.912462 -0.243152,-0.351474 -0.241173,-0.359861 0.158579,-0.672502 1.006199,-0.786947 0.958824,-0.782458 1.696912,-0.160744 0.839415,0.707067 2.114156,1.283502 3.261752,1.474958 1.756792,0.29309 3.647412,-0.308109 5.015549,-1.594906 2.386176,-2.2443084 2.398812,-5.737581 0.02892,-7.980996 -1.847632,-1.7489854 -4.518348,-2.1808945 -6.838263,-1.105887 -0.883611,0.4094496 -2.270077,1.6049981 -2.270077,1.9574827 0,0.1553101 0.301473,0.3650914 0.916178,0.6375406 0.503907,0.2233338 0.892626,0.4730278 0.863813,0.5548694 -0.08519,0.2421216 -4.873593,2.9103535 -4.99881,2.7854932 -0.09626,-0.095946 -0.843558,-4.938914 -0.84141,-5.4526815 3.79e-4,-0.1093782 0.291196,-0.028742 0.836603,0.2320163 0.45975,0.2198108 0.950253,0.3996539 1.089994,0.3996539 0.141775,0 0.484162,-0.2918891 0.774601,-0.6603454 0.902641,-1.1451311 2.290162,-2.0430747 4.018728,-2.60076543 1.066196,-0.3439928 3.407251,-0.3451049 4.479479,-0.002 2.699424,0.86346213 4.629396,2.71545813 5.404033,5.18567723 0.37727,1.2030819 0.34503,3.0596182 -0.07438,4.286049 -1.247296,3.646887 -5.24965,5.903878 -9.109162,5.136802 z"
style="fill:#4c4c4e;stroke-width:0.1044118;stroke-miterlimit:4.9000001;stroke-dasharray:none" />
</svg>

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

View File

@ -3157,6 +3157,8 @@ void VPattern::ParseToolMove(VMainGraphicsScene *scene, QDomElement &domElement,
ToolsCommonAttributes(domElement, initData.id);
initData.formulaAngle = GetParametrString(domElement, AttrAngle, "0");
const QString a = initData.formulaAngle;//need for saving fixed formula;
initData.formulaRotationAngle = GetParametrString(domElement, AttrRotationAngle, "0");
const QString r = initData.formulaRotationAngle;//need for saving fixed formula;
initData.formulaLength = GetParametrString(domElement, AttrLength, "0");
const QString len = initData.formulaLength;//need for saving fixed formula;
initData.suffix = GetParametrString(domElement, AttrSuffix, "");
@ -3165,9 +3167,10 @@ void VPattern::ParseToolMove(VMainGraphicsScene *scene, QDomElement &domElement,
VToolMove::Create(initData);
//Rewrite attribute formula. Need for situation when we have wrong formula.
if (a != initData.formulaAngle || len != initData.formulaLength)
if (a != initData.formulaAngle || r != initData.formulaRotationAngle || len != initData.formulaLength)
{
SetAttribute(domElement, AttrAngle, initData.formulaAngle);
SetAttribute(domElement, AttrRotationAngle, initData.formulaRotationAngle);
SetAttribute(domElement, AttrLength, initData.formulaLength);
modified = true;
haveLiteChange();

View File

@ -43,6 +43,7 @@
<file>schema/pattern/v0.6.6.xsd</file>
<file>schema/pattern/v0.7.0.xsd</file>
<file>schema/pattern/v0.7.1.xsd</file>
<file>schema/pattern/v0.7.2.xsd</file>
<file>schema/standard_measurements/v0.3.0.xsd</file>
<file>schema/standard_measurements/v0.4.0.xsd</file>
<file>schema/standard_measurements/v0.4.1.xsd</file>

File diff suppressed because it is too large Load Diff

View File

@ -58,8 +58,8 @@ class QDomElement;
*/
const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0");
const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.7.1");
const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.7.1.xsd");
const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.7.2");
const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.7.2.xsd");
//VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!!
//VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!!
@ -260,6 +260,8 @@ QString VPatternConverter::XSDSchema(int ver) const
case (0x000700):
return QStringLiteral("://schema/pattern/v0.7.0.xsd");
case (0x000701):
return QStringLiteral("://schema/pattern/v0.7.1.xsd");
case (0x000702):
return CurrentSchema;
default:
InvalidVersion(ver);
@ -440,6 +442,10 @@ void VPatternConverter::ApplyPatches()
ValidateXML(XSDSchema(0x000701), m_convertedFileName);
V_FALLTHROUGH
case (0x000701):
ToV0_7_2();
ValidateXML(XSDSchema(0x000702), m_convertedFileName);
V_FALLTHROUGH
case (0x000702):
break;
default:
InvalidVersion(m_ver);
@ -457,7 +463,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, 7, 1),
Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 7, 2),
"Check attribute readOnly.");
// Possibly in future attribute readOnly will change position etc.
@ -941,6 +947,16 @@ void VPatternConverter::ToV0_7_1()
Save();
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternConverter::ToV0_7_2()
{
// TODO. Delete if minimal supported version is 0.7.2
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 2),
"Time to refactor the code.");
SetVersion(QStringLiteral("0.7.2"));
Save();
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternConverter::TagUnitToV0_2_0()
{

View File

@ -53,7 +53,7 @@ public:
static const QString PatternMaxVerStr;
static const QString CurrentSchema;
static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0);
static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 7, 1);
static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 7, 2);
protected:
virtual int MinVer() const Q_DECL_OVERRIDE;
@ -114,6 +114,7 @@ private:
void ToV0_6_6();
void ToV0_7_0();
void ToV0_7_1();
void ToV0_7_2();
void TagUnitToV0_2_0();
void TagIncrementToV0_2_0();

View File

@ -67,15 +67,20 @@ DialogMove::DialogMove(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogMove),
flagAngle(false),
flagRotationAngle(false),
flagLength(false),
timerAngle(nullptr),
timerRotationAngle(nullptr),
timerLength(nullptr),
formulaAngle(),
formulaRotationAngle(),
formulaLength(),
formulaBaseHeightAngle(0),
formulaBaseHeightRotationAngle(0),
formulaBaseHeightLength(0),
objects(),
stage1(true),
stage2(false),
m_suffix()
{
ui->setupUi(this);
@ -83,6 +88,9 @@ DialogMove::DialogMove(const VContainer *data, quint32 toolId, QWidget *parent)
this->formulaBaseHeightAngle = ui->plainTextEditAngle->height();
ui->plainTextEditAngle->installEventFilter(this);
this->formulaBaseHeightRotationAngle = ui->plainTextEditRotationAngle->height();
ui->plainTextEditRotationAngle->installEventFilter(this);
this->formulaBaseHeightLength = ui->plainTextEditLength->height();
ui->plainTextEditLength->installEventFilter(this);
@ -91,6 +99,9 @@ DialogMove::DialogMove(const VContainer *data, quint32 toolId, QWidget *parent)
timerAngle = new QTimer(this);
connect(timerAngle, &QTimer::timeout, this, &DialogMove::EvalAngle);
timerRotationAngle = new QTimer(this);
connect(timerRotationAngle, &QTimer::timeout, this, &DialogMove::EvalRotationAngle);
timerLength = new QTimer(this);
connect(timerLength, &QTimer::timeout, this, &DialogMove::EvalLength);
@ -101,10 +112,13 @@ DialogMove::DialogMove(const VContainer *data, quint32 toolId, QWidget *parent)
connect(ui->lineEditSuffix, &QLineEdit::textChanged, this, &DialogMove::SuffixChanged);
connect(ui->toolButtonExprAngle, &QPushButton::clicked, this, &DialogMove::FXAngle);
connect(ui->toolButtonExprRotationAngle, &QPushButton::clicked, this, &DialogMove::FXRotationAngle);
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogMove::FXLength);
connect(ui->plainTextEditAngle, &QPlainTextEdit::textChanged, this, &DialogMove::AngleChanged);
connect(ui->plainTextEditRotationAngle, &QPlainTextEdit::textChanged, this, &DialogMove::RotationAngleChanged);
connect(ui->plainTextEditLength, &QPlainTextEdit::textChanged, this, &DialogMove::LengthChanged);
connect(ui->pushButtonGrowAngle, &QPushButton::clicked, this, &DialogMove::DeployAngleTextEdit);
connect(ui->pushButtonGrowRotationAngle, &QPushButton::clicked, this, &DialogMove::DeployRotationAngleTextEdit);
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogMove::DeployLengthTextEdit);
vis = new VisToolMove(data);
@ -164,6 +178,30 @@ void DialogMove::SetLength(const QString &value)
MoveCursorToEnd(ui->plainTextEditLength);
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogMove::GetRotationAngle() const
{
return qApp->TrVars()->TryFormulaFromUser(formulaRotationAngle, qApp->Settings()->GetOsSeparator());
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::SetRotationAngle(const QString &value)
{
formulaRotationAngle = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator());
// increase height if needed.
if (formulaRotationAngle.length() > 80)
{
this->DeployAngleTextEdit();
}
ui->plainTextEditRotationAngle->setPlainText(formulaRotationAngle);
VisToolMove *operation = qobject_cast<VisToolMove *>(vis);
SCASSERT(operation != nullptr)
operation->SetRotationAngle(formulaRotationAngle);
MoveCursorToEnd(ui->plainTextEditRotationAngle);
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogMove::GetSuffix() const
{
@ -219,22 +257,37 @@ void DialogMove::ShowDialog(bool click)
scene->ToggleSplineHover(false);
scene->ToggleSplinePathHover(false);
}
else if (not stage1 && prepare && click)
else if (not stage2 && not stage1 && prepare && click)
{
VisToolMove *operation = qobject_cast<VisToolMove *>(vis);
SCASSERT(operation != nullptr)
if (operation->LengthValue() > 0)
{
SetAngle(operation->Angle());//Show in dialog angle that a user choose
SetLength(operation->Length());
setModal(true);
emit ToolTip("");
timerAngle->start();
timerLength->start();
show();
formulaAngle = qApp->TrVars()->FormulaToUser(operation->Angle(), qApp->Settings()->GetOsSeparator());
formulaLength = qApp->TrVars()->FormulaToUser(operation->Length(), qApp->Settings()->GetOsSeparator());
operation->SetAngle(formulaAngle);
operation->SetLength(formulaLength);
operation->RefreshGeometry();
emit ToolTip(operation->CurrentToolTip());
stage2 = true;
}
}
else if (not stage1 && stage2 && prepare && click)
{
VisToolMove *operation = qobject_cast<VisToolMove *>(vis);
SCASSERT(operation != nullptr)
SetAngle(qApp->TrVars()->FormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator()));
SetLength(qApp->TrVars()->FormulaFromUser(formulaLength, qApp->Settings()->GetOsSeparator()));
SetRotationAngle(operation->RotationAngle());
setModal(true);
emit ToolTip("");
timerAngle->start();
timerRotationAngle->start();
timerLength->start();
show();
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -271,6 +324,12 @@ void DialogMove::DeployAngleTextEdit()
DeployFormula(ui->plainTextEditAngle, ui->pushButtonGrowAngle, formulaBaseHeightAngle);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::DeployRotationAngleTextEdit()
{
DeployFormula(ui->plainTextEditRotationAngle, ui->pushButtonGrowRotationAngle, formulaBaseHeightRotationAngle);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::DeployLengthTextEdit()
{
@ -285,6 +344,14 @@ void DialogMove::AngleChanged()
ValFormulaChanged(flagAngle, ui->plainTextEditAngle, timerAngle, degreeSymbol);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::RotationAngleChanged()
{
labelEditFormula = ui->labelEditRotationAngle;
labelResultCalculation = ui->labelResultRotationAngle;
ValFormulaChanged(flagRotationAngle, ui->plainTextEditRotationAngle, timerRotationAngle, degreeSymbol);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::LengthChanged()
{
@ -307,6 +374,20 @@ void DialogMove::FXAngle()
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::FXRotationAngle()
{
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit rotation angle"));
dialog->SetFormula(GetRotationAngle());
dialog->setPostfix(degreeSymbol);
if (dialog->exec() == QDialog::Accepted)
{
SetRotationAngle(dialog->GetFormula());
}
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::FXLength()
{
@ -365,7 +446,7 @@ void DialogMove::SuffixChanged()
void DialogMove::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagAngle && flagLength && flagName);
bOk->setEnabled(flagAngle && flagRotationAngle && flagLength && flagName);
SCASSERT(bApply != nullptr)
bApply->setEnabled(bOk->isEnabled());
}
@ -384,6 +465,9 @@ void DialogMove::SaveData()
formulaAngle = ui->plainTextEditAngle->toPlainText();
formulaAngle.replace("\n", " ");
formulaRotationAngle = ui->plainTextEditRotationAngle->toPlainText();
formulaRotationAngle.replace("\n", " ");
formulaLength = ui->plainTextEditLength->toPlainText();
formulaLength.replace("\n", " ");
@ -393,6 +477,7 @@ void DialogMove::SaveData()
operation->SetObjects(objects.toVector());
operation->SetAngle(formulaAngle);
operation->SetLength(formulaLength);
operation->SetRotationAngle(formulaRotationAngle);
operation->RefreshGeometry();
}
@ -400,6 +485,7 @@ void DialogMove::SaveData()
void DialogMove::closeEvent(QCloseEvent *event)
{
ui->plainTextEditAngle->blockSignals(true);
ui->plainTextEditRotationAngle->blockSignals(true);
ui->plainTextEditLength->blockSignals(true);
DialogTool::closeEvent(event);
}
@ -411,6 +497,14 @@ void DialogMove::EvalAngle()
Eval(ui->plainTextEditAngle->toPlainText(), flagAngle, ui->labelResultAngle, degreeSymbol, false);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::EvalRotationAngle()
{
labelEditFormula = ui->labelEditRotationAngle;
Eval(ui->plainTextEditRotationAngle->toPlainText(), flagRotationAngle, ui->labelResultRotationAngle, degreeSymbol,
false);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::EvalLength()
{

View File

@ -59,6 +59,9 @@ public:
QString GetLength() const;
void SetLength(const QString &value);
QString GetRotationAngle() const;
void SetRotationAngle(const QString &value);
QString GetSuffix() const;
void SetSuffix(const QString &value);
@ -73,12 +76,15 @@ public slots:
private slots:
/** @brief DeployAngleTextEdit grow or shrink formula input */
void DeployAngleTextEdit();
void DeployRotationAngleTextEdit();
void DeployLengthTextEdit();
void AngleChanged();
void RotationAngleChanged();
void LengthChanged();
void FXAngle();
void FXRotationAngle();
void FXLength();
void SuffixChanged();
@ -97,31 +103,33 @@ private:
/** @brief flagAngle true if value of angle is correct */
bool flagAngle;
bool flagRotationAngle;
bool flagLength;
/** @brief timerAngle timer of check formula of angle */
QTimer *timerAngle;
QTimer *timerRotationAngle;
QTimer *timerLength;
/** @brief angle formula of angle */
QString formulaAngle;
QString formulaRotationAngle;
QString formulaLength;
/** @brief formulaBaseHeightAngle base height defined by dialogui */
int formulaBaseHeightAngle;
int formulaBaseHeightRotationAngle;
int formulaBaseHeightLength;
QList<quint32> objects;
bool stage1;
bool stage2;
QString m_suffix;
void EvalAngle();
void EvalRotationAngle();
void EvalLength();
};

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>285</width>
<height>232</height>
<width>292</width>
<height>301</height>
</rect>
</property>
<property name="windowTitle">
@ -378,6 +378,186 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item alignment="Qt::AlignLeft">
<widget class="QLabel" name="labelEditRotationAngle">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>159</red>
<green>158</green>
<blue>158</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="text">
<string>Rotation angle:</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item alignment="Qt::AlignRight">
<widget class="QToolButton" name="toolButtonExprRotationAngle">
<property name="toolTip">
<string>Formula wizard</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset resource="../../../vmisc/share/resources/icon.qrc">
<normaloff>:/icon/24x24/fx.png</normaloff>:/icon/24x24/fx.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="QLabel" name="label_4">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../../../vmisc/share/resources/icon.qrc">:/icon/24x24/equal.png</pixmap>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="QLabel" name="labelResultRotationAngle">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>87</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Value</string>
</property>
<property name="text">
<string notr="true">_</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QPlainTextEdit" name="plainTextEditRotationAngle">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>28</height>
</size>
</property>
<property name="toolTip">
<string>Calculation</string>
</property>
<property name="tabChangesFocus">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonGrowRotationAngle">
<property name="maximumSize">
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Show full calculation in message box&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string notr="true"/>
</property>
<property name="icon">
<iconset theme="go-down">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>

View File

@ -74,6 +74,50 @@ template <class T> class QSharedPointer;
const QString VToolMove::ToolType = QStringLiteral("moving");
namespace
{
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wswitch-default")
QPointF GetOriginPoint(const QVector<quint32> objects, const VContainer *data, qreal calcLength, qreal calcAngle)
{
QPolygonF originObjects;
for (int i = 0; i < objects.size(); ++i)
{
const quint32 id = objects.at(i);
const QSharedPointer<VGObject> obj = data->GetGObject(id);
// This check helps to find missed objects in the switch
Q_STATIC_ASSERT_X(static_cast<int>(GOType::Unknown) == 8, "Not all objects were handled.");
switch(static_cast<GOType>(obj->getType()))
{
case GOType::Point:
originObjects.append(data->GeometricObject<VPointF>(id)->toQPointF());
break;
case GOType::Arc:
case GOType::EllipticalArc:
case GOType::Spline:
case GOType::SplinePath:
case GOType::CubicBezier:
case GOType::CubicBezierPath:
originObjects.append(data->GeometricObject<VAbstractCurve>(id)->GetPoints());
break;
case GOType::Unknown:
case GOType::PlaceLabel:
Q_UNREACHABLE();
break;
}
}
QPointF rotationOrigin = originObjects.boundingRect().center();
QLineF move(rotationOrigin, QPointF(rotationOrigin.x()+calcLength, rotationOrigin.y()));
move.setAngle(calcAngle);
return move.p2();
}
QT_WARNING_POP
}
//---------------------------------------------------------------------------------------------------------------------
void VToolMove::setDialog()
{
@ -81,6 +125,7 @@ void VToolMove::setDialog()
QSharedPointer<DialogMove> dialogTool = m_dialog.objectCast<DialogMove>();
SCASSERT(not dialogTool.isNull())
dialogTool->SetAngle(formulaAngle);
dialogTool->SetRotationAngle(formulaRotationAngle);
dialogTool->SetLength(formulaLength);
dialogTool->SetSuffix(suffix);
}
@ -95,6 +140,7 @@ VToolMove *VToolMove::Create(QSharedPointer<DialogTool> dialog, VMainGraphicsSce
VToolMoveInitData initData;
initData.formulaAngle = dialogTool->GetAngle();
initData.formulaRotationAngle = dialogTool->GetRotationAngle();
initData.formulaLength = dialogTool->GetLength();
initData.suffix = dialogTool->GetSuffix();
initData.source = dialogTool->GetObjects();
@ -116,11 +162,15 @@ VToolMove *VToolMove::Create(QSharedPointer<DialogTool> dialog, VMainGraphicsSce
VToolMove *VToolMove::Create(VToolMoveInitData &initData)
{
qreal calcAngle = 0;
qreal calcRotationAngle = 0;
qreal calcLength = 0;
calcAngle = CheckFormula(initData.id, initData.formulaAngle, initData.data);
calcRotationAngle = CheckFormula(initData.id, initData.formulaRotationAngle, initData.data);
calcLength = qApp->toPixel(CheckFormula(initData.id, initData.formulaLength, initData.data));
const QPointF rotationOrigin = GetOriginPoint(initData.source, initData.data, calcLength, calcAngle);
if (initData.typeCreation == Source::FromGui)
{
initData.destination.clear();// Try to avoid mistake, value must be empty
@ -141,32 +191,40 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
{
case GOType::Point:
initData.destination.append(CreatePoint(initData.id, idObject, calcAngle, calcLength,
initData.suffix, initData.data));
calcRotationAngle, rotationOrigin, initData.suffix,
initData.data));
break;
case GOType::Arc:
initData.destination.append(CreateArc<VArc>(initData.id, idObject, calcAngle, calcLength,
initData.suffix, initData.data));
calcRotationAngle, rotationOrigin, initData.suffix,
initData.data));
break;
case GOType::EllipticalArc:
initData.destination.append(CreateArc<VEllipticalArc>(initData.id, idObject, calcAngle, calcLength,
calcRotationAngle, rotationOrigin,
initData.suffix, initData.data));
break;
case GOType::Spline:
initData.destination.append(CreateCurve<VSpline>(initData.id, idObject, calcAngle, calcLength,
initData.suffix, initData.data));
calcRotationAngle, rotationOrigin, initData.suffix,
initData.data));
break;
case GOType::SplinePath:
initData.destination.append(CreateCurveWithSegments<VSplinePath>(initData.id, idObject, calcAngle,
calcLength, initData.suffix,
calcLength, calcRotationAngle,
rotationOrigin, initData.suffix,
initData.data));
break;
case GOType::CubicBezier:
initData.destination.append(CreateCurve<VCubicBezier>(initData.id, idObject, calcAngle, calcLength,
calcRotationAngle, rotationOrigin,
initData.suffix, initData.data));
break;
case GOType::CubicBezierPath:
initData.destination.append(CreateCurveWithSegments<VCubicBezierPath>(initData.id, idObject,
calcAngle, calcLength,
calcRotationAngle,
rotationOrigin,
initData.suffix,
initData.data));
break;
@ -193,31 +251,35 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
switch(static_cast<GOType>(obj->getType()))
{
case GOType::Point:
UpdatePoint(initData.id, idObject, calcAngle, calcLength, initData.suffix, initData.data,
initData.destination.at(i));
UpdatePoint(initData.id, idObject, calcAngle, calcLength, calcRotationAngle, rotationOrigin,
initData.suffix, initData.data, initData.destination.at(i));
break;
case GOType::Arc:
UpdateArc<VArc>(initData.id, idObject, calcAngle, calcLength, initData.suffix, initData.data,
initData.destination.at(i).id);
UpdateArc<VArc>(initData.id, idObject, calcAngle, calcLength, calcRotationAngle, rotationOrigin,
initData.suffix, initData.data, initData.destination.at(i).id);
break;
case GOType::EllipticalArc:
UpdateArc<VEllipticalArc>(initData.id, idObject, calcAngle, calcLength, initData.suffix,
initData.data, initData.destination.at(i).id);
UpdateArc<VEllipticalArc>(initData.id, idObject, calcAngle, calcLength, calcRotationAngle,
rotationOrigin, initData.suffix, initData.data,
initData.destination.at(i).id);
break;
case GOType::Spline:
UpdateCurve<VSpline>(initData.id, idObject, calcAngle, calcLength, initData.suffix, initData.data,
initData.destination.at(i).id);
UpdateCurve<VSpline>(initData.id, idObject, calcAngle, calcLength, calcRotationAngle,
rotationOrigin, initData.suffix, initData.data, initData.destination.at(i).id);
break;
case GOType::SplinePath:
UpdateCurveWithSegments<VSplinePath>(initData.id, idObject, calcAngle, calcLength, initData.suffix,
UpdateCurveWithSegments<VSplinePath>(initData.id, idObject, calcAngle, calcLength,
calcRotationAngle, rotationOrigin,initData.suffix,
initData.data, initData.destination.at(i).id);
break;
case GOType::CubicBezier:
UpdateCurve<VCubicBezier>(initData.id, idObject, calcAngle, calcLength, initData.suffix,
initData.data, initData.destination.at(i).id);
UpdateCurve<VCubicBezier>(initData.id, idObject, calcAngle, calcLength, calcRotationAngle,
rotationOrigin,initData.suffix, initData.data,
initData.destination.at(i).id);
break;
case GOType::CubicBezierPath:
UpdateCurveWithSegments<VCubicBezierPath>(initData.id, idObject, calcAngle, calcLength,
calcRotationAngle, rotationOrigin,
initData.suffix, initData.data,
initData.destination.at(i).id);
break;
@ -272,6 +334,28 @@ void VToolMove::SetFormulaAngle(const VFormula &value)
}
}
//---------------------------------------------------------------------------------------------------------------------
VFormula VToolMove::GetFormulaRotationAngle() const
{
VFormula fAngle(formulaRotationAngle, getData());
fAngle.setCheckZero(false);
fAngle.setToolId(m_id);
fAngle.setPostfix(degreeSymbol);
return fAngle;
}
//---------------------------------------------------------------------------------------------------------------------
void VToolMove::SetFormulaRotationAngle(const VFormula &value)
{
if (value.error() == false)
{
formulaRotationAngle = value.GetFormula(FormulaType::FromUser);
QSharedPointer<VGObject> obj = VContainer::GetFakeGObject(m_id);
SaveOption(obj);
}
}
//---------------------------------------------------------------------------------------------------------------------
VFormula VToolMove::GetFormulaLength() const
{
@ -324,6 +408,8 @@ void VToolMove::SetVisualization()
visual->SetObjects(source);
visual->SetAngle(qApp->TrVars()->FormulaToUser(formulaAngle, qApp->Settings()->GetOsSeparator()));
visual->SetRotationAngle(qApp->TrVars()->FormulaToUser(formulaRotationAngle,
qApp->Settings()->GetOsSeparator()));
visual->SetLength(qApp->TrVars()->FormulaToUser(formulaLength, qApp->Settings()->GetOsSeparator()));
visual->RefreshGeometry();
}
@ -349,6 +435,7 @@ void VToolMove::SaveDialog(QDomElement &domElement, QList<quint32> &oldDependenc
void VToolMove::ReadToolAttributes(const QDomElement &domElement)
{
formulaAngle = doc->GetParametrString(domElement, AttrAngle, "0");
formulaRotationAngle = doc->GetParametrString(domElement, AttrRotationAngle, "0");
formulaLength = doc->GetParametrString(domElement, AttrLength, "0");
suffix = doc->GetParametrString(domElement, AttrSuffix);
}
@ -360,6 +447,7 @@ void VToolMove::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
doc->SetAttribute(tag, AttrType, ToolType);
doc->SetAttribute(tag, AttrAngle, formulaAngle);
doc->SetAttribute(tag, AttrRotationAngle, formulaRotationAngle);
doc->SetAttribute(tag, AttrLength, formulaLength);
doc->SetAttribute(tag, AttrSuffix, suffix);
@ -384,6 +472,7 @@ VToolMove::VToolMove(const VToolMoveInitData &initData, QGraphicsItem *parent)
: VAbstractOperation(initData.doc, initData.data, initData.id, initData.suffix, initData.source,
initData.destination, parent),
formulaAngle(initData.formulaAngle),
formulaRotationAngle(initData.formulaRotationAngle),
formulaLength(initData.formulaLength)
{
InitOperatedObjects();
@ -392,10 +481,11 @@ VToolMove::VToolMove(const VToolMoveInitData &initData, QGraphicsItem *parent)
//---------------------------------------------------------------------------------------------------------------------
DestinationItem VToolMove::CreatePoint(quint32 idTool, quint32 idItem, qreal angle,
qreal length, const QString &suffix, VContainer *data)
qreal length, qreal rotationAngle, const QPointF &rotationOrigin,
const QString &suffix, VContainer *data)
{
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(idItem);
VPointF moved = point->Move(length, angle, suffix);
VPointF moved = point->Move(length, angle, suffix).Rotate(rotationOrigin, rotationAngle);
moved.setIdObject(idTool);
DestinationItem item;
@ -408,20 +498,22 @@ DestinationItem VToolMove::CreatePoint(quint32 idTool, quint32 idItem, qreal ang
//---------------------------------------------------------------------------------------------------------------------
template <class Item>
DestinationItem VToolMove::CreateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data)
DestinationItem VToolMove::CreateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data)
{
const DestinationItem item = CreateItem<Item>(idTool, idItem, angle, length, suffix, data);
const DestinationItem item = CreateItem<Item>(idTool, idItem, angle, length, rotationAngle, rotationOrigin, suffix,
data);
data->AddArc(data->GeometricObject<Item>(item.id), item.id);
return item;
}
//---------------------------------------------------------------------------------------------------------------------
void VToolMove::UpdatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data, const DestinationItem &item)
void VToolMove::UpdatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data,
const DestinationItem &item)
{
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(idItem);
VPointF moved = point->Move(length, angle, suffix);
VPointF moved = point->Move(length, angle, suffix).Rotate(rotationOrigin, rotationAngle);
moved.setIdObject(idTool);
moved.setMx(item.mx);
moved.setMy(item.my);
@ -431,20 +523,20 @@ void VToolMove::UpdatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal l
//---------------------------------------------------------------------------------------------------------------------
template <class Item>
void VToolMove::UpdateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data, quint32 id)
void VToolMove::UpdateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id)
{
UpdateItem<Item>(idTool, idItem, angle, length, suffix, data, id);
UpdateItem<Item>(idTool, idItem, angle, length, rotationAngle, rotationOrigin, suffix, data, id);
data->AddArc(data->GeometricObject<Item>(id), id);
}
//---------------------------------------------------------------------------------------------------------------------
template <class Item>
DestinationItem VToolMove::CreateItem(quint32 idTool, quint32 idItem, qreal angle,
qreal length, const QString &suffix, VContainer *data)
DestinationItem VToolMove::CreateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data)
{
const QSharedPointer<Item> i = data->GeometricObject<Item>(idItem);
Item moved = i->Move(length, angle, suffix);
Item moved = i->Move(length, angle, suffix).Rotate(rotationOrigin, rotationAngle);
moved.setIdObject(idTool);
DestinationItem item;
@ -456,10 +548,11 @@ DestinationItem VToolMove::CreateItem(quint32 idTool, quint32 idItem, qreal angl
//---------------------------------------------------------------------------------------------------------------------
template <class Item>
DestinationItem VToolMove::CreateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length,
const QString &suffix, VContainer *data)
DestinationItem VToolMove::CreateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data)
{
const DestinationItem item = CreateItem<Item>(idTool, idItem, angle, length, suffix, data);
const DestinationItem item = CreateItem<Item>(idTool, idItem, angle, length, rotationAngle, rotationOrigin, suffix,
data);
data->AddSpline(data->GeometricObject<Item>(item.id), item.id);
return item;
}
@ -467,39 +560,42 @@ DestinationItem VToolMove::CreateCurve(quint32 idTool, quint32 idItem, qreal ang
//---------------------------------------------------------------------------------------------------------------------
template <class Item>
DestinationItem VToolMove::CreateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle,
qreal length, const QString &suffix,
VContainer *data)
qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix,
VContainer *data)
{
const DestinationItem item = CreateItem<Item>(idTool, idItem, angle, length, suffix, data);
const DestinationItem item = CreateItem<Item>(idTool, idItem, angle, length, rotationAngle, rotationOrigin, suffix,
data);
data->AddCurveWithSegments(data->GeometricObject<Item>(item.id), item.id);
return item;
}
//---------------------------------------------------------------------------------------------------------------------
template <class Item>
void VToolMove::UpdateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data, quint32 id)
void VToolMove::UpdateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id)
{
const QSharedPointer<Item> i = data->GeometricObject<Item>(idItem);
Item moved = i->Move(length, angle, suffix);
Item moved = i->Move(length, angle, suffix).Rotate(rotationOrigin, rotationAngle);;
moved.setIdObject(idTool);
data->UpdateGObject(id, new Item(moved));
}
//---------------------------------------------------------------------------------------------------------------------
template <class Item>
void VToolMove::UpdateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data, quint32 id)
void VToolMove::UpdateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id)
{
UpdateItem<Item>(idTool, idItem, angle, length, suffix, data, id);
UpdateItem<Item>(idTool, idItem, angle, length, rotationAngle, rotationOrigin, suffix, data, id);
data->AddSpline(data->GeometricObject<Item>(id), id);
}
//---------------------------------------------------------------------------------------------------------------------
template <class Item>
void VToolMove::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, qreal length,
const QString &suffix, VContainer *data, quint32 id)
void VToolMove::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data,
quint32 id)
{
UpdateItem<Item>(idTool, idItem, angle, length, suffix, data, id);
UpdateItem<Item>(idTool, idItem, angle, length, rotationAngle, rotationOrigin, suffix, data, id);
data->AddCurveWithSegments(data->GeometricObject<Item>(id), id);
}

View File

@ -50,10 +50,12 @@ struct VToolMoveInitData : VAbstractOperationInitData
VToolMoveInitData()
: VAbstractOperationInitData(),
formulaAngle(),
formulaRotationAngle(),
formulaLength()
{}
QString formulaAngle;
QString formulaRotationAngle;
QString formulaLength;
};
@ -75,6 +77,9 @@ public:
VFormula GetFormulaAngle() const;
void SetFormulaAngle(const VFormula &value);
VFormula GetFormulaRotationAngle() const;
void SetFormulaRotationAngle(const VFormula &value);
VFormula GetFormulaLength() const;
void SetFormulaLength(const VFormula &value);
@ -91,40 +96,44 @@ protected:
private:
Q_DISABLE_COPY(VToolMove)
QString formulaAngle;
QString formulaRotationAngle;
QString formulaLength;
VToolMove(const VToolMoveInitData &initData, QGraphicsItem *parent = nullptr);
static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data);
static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data);
template <class Item>
static DestinationItem CreateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data);
static DestinationItem CreateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data);
template <class Item>
static DestinationItem CreateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data);
static DestinationItem CreateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data);
template <class Item>
static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data);
static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin,const QString &suffix, VContainer *data);
template <class Item>
static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, qreal length,
qreal rotationAngle, const QPointF &rotationOrigin,
const QString &suffix, VContainer *data);
static void UpdatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data, const DestinationItem &item);
static void UpdatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data,
const DestinationItem &item);
template <class Item>
static void UpdateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data, quint32 id);
static void UpdateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id);
template <class Item>
static void UpdateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data, quint32 id);
static void UpdateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id);
template <class Item>
static void UpdateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data, quint32 id);
static void UpdateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id);
template <class Item>
static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, qreal length,
const QString &suffix, VContainer *data, quint32 id);
static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle,
const QPointF &rotationOrigin, const QString &suffix, VContainer *data,
quint32 id);
};
#endif // VTOOLMOVING_H

View File

@ -43,6 +43,7 @@ VisOperation::VisOperation(const VContainer *data, QGraphicsItem *parent)
: VisLine(data, parent),
objects(),
supportColor2(Qt::darkGreen),
supportColor3(Qt::darkBlue),
points(),
curves()
{

View File

@ -50,6 +50,7 @@ public:
protected:
QVector<quint32> objects;
QColor supportColor2;
QColor supportColor3;
QVector<VScaledEllipse *> points;
QVector<VCurvePathItem *> curves;

View File

@ -51,6 +51,7 @@
#include "../vgeometry/vpointf.h"
#include "../vgeometry/vspline.h"
#include "../vgeometry/vsplinepath.h"
#include "../vgeometry/varc.h"
#include "../vmisc/vabstractapplication.h"
#include "../vpatterndb/vcontainer.h"
#include "../vwidgets/vmaingraphicsscene.h"
@ -60,17 +61,19 @@
VisToolMove::VisToolMove(const VContainer *data, QGraphicsItem *parent)
: VisOperation(data, parent),
angle(0),
rotationAngle(INT_MIN),
length(0),
pointOrigin(nullptr),
pointFinish(nullptr)
pointFinish(nullptr),
angleArc(nullptr),
rotationLine(nullptr),
xAxis(nullptr)
{
pointOrigin = InitPoint(supportColor2, this);
pointFinish = InitPoint(supportColor, this);
}
//---------------------------------------------------------------------------------------------------------------------
VisToolMove::~VisToolMove()
{
angleArc = InitItem<VCurvePathItem>(supportColor3, this);
rotationLine = InitItem<VScaledLine>(supportColor3, this);
xAxis = InitItem<VScaledLine>(supportColor3, this);
}
//---------------------------------------------------------------------------------------------------------------------
@ -91,6 +94,7 @@ void VisToolMove::RefreshGeometry()
qreal tempAngle = 0;
qreal tempLength = 0;
qreal tempRoationAngle = 0;
QLineF line;
if (qFuzzyIsNull(length))
@ -113,19 +117,67 @@ void VisToolMove::RefreshGeometry()
line = VGObject::BuildLine(origin, length, angle);
tempAngle = angle;
tempLength = length;
QLineF rLine;
if (VFuzzyComparePossibleNulls(rotationAngle, INT_MIN))
{
rLine = QLineF(line.p2(), Visualization::scenePos);
if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier)
{
rLine.setAngle(CorrectAngle(rLine.angle()));
}
qreal cursorLength = rLine.length();
rLine.setP2(Ray(line.p2(), rLine.angle()));
//Radius of point circle, but little bigger. Need handle with hover sizes.
qreal minL = ScaledRadius(SceneScale(qApp->getCurrentScene()))*1.5;
if (cursorLength > minL)
{
tempRoationAngle = rLine.angle();
}
else
{
rLine.setAngle(0);
}
}
else
{
rLine = QLineF(line.p2(), Ray(line.p2(), rotationAngle));
tempRoationAngle = rotationAngle;
}
DrawLine(rotationLine, rLine, supportColor3, Qt::DashLine);
DrawLine(xAxis, QLineF(line.p2(), Ray(line.p2(), 0)), supportColor3, Qt::DashLine);
VArc arc(VPointF(line.p2()), ScaledRadius(SceneScale(qApp->getCurrentScene()))*2, 0, tempRoationAngle);
DrawPath(angleArc, arc.GetPath(), supportColor3, Qt::SolidLine, Qt::RoundCap);
}
DrawLine(this, line, supportColor2, Qt::DashLine);
DrawPoint(pointFinish, line.p2(), supportColor);
static const QString prefix = UnitsToStr(qApp->patternUnit(), true);
Visualization::toolTip = tr("Length = %1%2, angle = %3°, <b>Shift</b> - sticking angle, "
"<b>Mouse click</b> - finish creation")
.arg(qApp->TrVars()->FormulaToUser(QString::number(qApp->fromPixel(tempLength)),
qApp->Settings()->GetOsSeparator()))
.arg(prefix)
.arg(tempAngle);
if (qFuzzyIsNull(length))
{
Visualization::toolTip = tr("Length = %1%2, angle = %3°, <b>Shift</b> - sticking angle, "
"<b>Mouse click</b> - finish selecting a position")
.arg(qApp->TrVars()->FormulaToUser(QString::number(qApp->fromPixel(tempLength)),
qApp->Settings()->GetOsSeparator()))
.arg(prefix)
.arg(tempAngle);
}
else
{
Visualization::toolTip = tr("Length = %1%2, angle = %3°, rotation angle = %4°, <b>Shift</b> - sticking angle, "
"<b>Mouse click</b> - finish creating")
.arg(qApp->TrVars()->FormulaToUser(QString::number(qApp->fromPixel(tempLength)),
qApp->Settings()->GetOsSeparator()))
.arg(prefix)
.arg(tempAngle)
.arg(tempRoationAngle);
}
CreateMovedObjects(iPoint, iCurve, tempLength, tempAngle);
CreateMovedRotatedObjects(iPoint, iCurve, tempLength, tempAngle, tempRoationAngle, line.p2());
}
//---------------------------------------------------------------------------------------------------------------------
@ -140,6 +192,18 @@ void VisToolMove::SetAngle(const QString &expression)
angle = FindValFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------
QString VisToolMove::RotationAngle() const
{
return QString::number(rotationLine->line().angle());
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolMove::SetRotationAngle(const QString &expression)
{
rotationAngle = FindValFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------
QString VisToolMove::Length() const
{
@ -173,13 +237,14 @@ QGraphicsPathItem *VisToolMove::AddOriginCurve(quint32 id, int &i)
//---------------------------------------------------------------------------------------------------------------------
template <class Item>
int VisToolMove::AddMovedCurve(qreal angle, qreal length, quint32 id, int i)
int VisToolMove::AddMovedRotatedCurve(qreal angle, qreal length, quint32 id, int i, qreal rotationAngle,
const QPointF &rotationOrigin)
{
const QSharedPointer<Item> curve = Visualization::data->template GeometricObject<Item>(id);
++i;
VCurvePathItem *path = GetCurve(static_cast<quint32>(i), supportColor);
const Item moved = curve->Move(length, angle);
const Item moved = curve->Move(length, angle).Rotate(rotationOrigin, rotationAngle);
DrawPath(path, moved.GetPath(), moved.DirectionArrows(), supportColor, Qt::SolidLine, Qt::RoundCap);
return i;
@ -273,7 +338,8 @@ QT_WARNING_POP
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wswitch-default")
void VisToolMove::CreateMovedObjects(int &iPoint, int &iCurve, qreal length, qreal angle)
void VisToolMove::CreateMovedRotatedObjects(int &iPoint, int &iCurve, qreal length, qreal angle, qreal rotationAngle,
const QPointF &rotationOrigin)
{
for (int i = 0; i < objects.size(); ++i)
{
@ -291,26 +357,28 @@ void VisToolMove::CreateMovedObjects(int &iPoint, int &iCurve, qreal length, qre
++iPoint;
VScaledEllipse *point = GetPoint(static_cast<quint32>(iPoint), supportColor);
DrawPoint(point, static_cast<QPointF>(p->Move(length, angle)), supportColor);
DrawPoint(point, static_cast<QPointF>(p->Move(length, angle).Rotate(rotationOrigin, rotationAngle)),
supportColor);
break;
}
case GOType::Arc:
iCurve = AddMovedCurve<VArc>(angle, length, id, iCurve);
iCurve = AddMovedRotatedCurve<VArc>(angle, length, id, iCurve, rotationAngle, rotationOrigin);
break;
case GOType::EllipticalArc:
iCurve = AddMovedCurve<VEllipticalArc>(angle, length, id, iCurve);
iCurve = AddMovedRotatedCurve<VEllipticalArc>(angle, length, id, iCurve, rotationAngle, rotationOrigin);
break;
case GOType::Spline:
iCurve = AddMovedCurve<VSpline>(angle, length, id, iCurve);
iCurve = AddMovedRotatedCurve<VSpline>(angle, length, id, iCurve, rotationAngle, rotationOrigin);
break;
case GOType::SplinePath:
iCurve = AddMovedCurve<VSplinePath>(angle, length, id, iCurve);
iCurve = AddMovedRotatedCurve<VSplinePath>(angle, length, id, iCurve, rotationAngle, rotationOrigin);
break;
case GOType::CubicBezier:
iCurve = AddMovedCurve<VCubicBezier>(angle, length, id, iCurve);
iCurve = AddMovedRotatedCurve<VCubicBezier>(angle, length, id, iCurve, rotationAngle, rotationOrigin);
break;
case GOType::CubicBezierPath:
iCurve = AddMovedCurve<VCubicBezierPath>(angle, length, id, iCurve);
iCurve = AddMovedRotatedCurve<VCubicBezierPath>(angle, length, id, iCurve, rotationAngle,
rotationOrigin);
break;
case GOType::Unknown:
case GOType::PlaceLabel:

View File

@ -48,13 +48,16 @@ class VisToolMove : public VisOperation
Q_OBJECT
public:
explicit VisToolMove(const VContainer *data, QGraphicsItem *parent = nullptr);
virtual ~VisToolMove();
virtual ~VisToolMove() = default;
virtual void RefreshGeometry() Q_DECL_OVERRIDE;
QString Angle() const;
void SetAngle(const QString &expression);
QString RotationAngle() const;
void SetRotationAngle(const QString &expression);
QString Length() const;
qreal LengthValue() const;
void SetLength(const QString &expression);
@ -64,20 +67,26 @@ public:
private:
Q_DISABLE_COPY(VisToolMove)
qreal angle;
qreal rotationAngle;
qreal length;
VScaledEllipse *pointOrigin;
VScaledEllipse *pointFinish;
VCurvePathItem *angleArc;
VScaledLine *rotationLine;
VScaledLine *xAxis;
template <class Item>
QGraphicsPathItem *AddOriginCurve(quint32 id, int &i);
template <class Item>
int AddMovedCurve(qreal angle, qreal length, quint32 id, int i);
int AddMovedRotatedCurve(qreal angle, qreal length, quint32 id, int i, qreal rotationAngle,
const QPointF &rotationOrigin);
static QPointF GetOriginPoint(const QVector<QGraphicsItem *> &objects);
QVector<QGraphicsItem *> CreateOriginObjects(int &iPoint, int &iCurve);
void CreateMovedObjects(int &iPoint, int &iCurve, qreal length, qreal angle);
void CreateMovedRotatedObjects(int &iPoint, int &iCurve, qreal length, qreal angle, qreal rotationAngle,
const QPointF &rotationOrigin);
};
#endif // VISTOOLMOVE_H

View File

@ -76,6 +76,8 @@ public:
QSharedPointer<VInternalVariable> > *vars, bool fromUser = true);
static qreal FindValFromUser(const QString &expression, const QHash<QString,
QSharedPointer<VInternalVariable> > *vars, bool fromUser = true);
QString CurrentToolTip() const {return toolTip;}
signals:
void ToolTip(const QString &toolTip);
public slots: