Improve visualization for tool Point along line.

This commit is contained in:
Roman Telezhynskyi 2022-08-19 13:49:09 +03:00
parent 9a28166539
commit 3d186c2a37
11 changed files with 141 additions and 48 deletions

View File

@ -19,6 +19,7 @@
- Remember selected dimension values.
- Fix segmenting a simple curve.
- Fix export tiled pdf on Mac OS.
- Improve visualization for tools.
# Valentina 0.7.51 April 18, 2022
- Z value change for a layout piece.

View File

@ -54,6 +54,7 @@
#include "../vpatterndb/variables/vlinelength.h"
#include "../vpatterndb/vtranslatevars.h"
#include "ui_dialogalongline.h"
#include "../vwidgets/vabstractmainwindow.h"
//---------------------------------------------------------------------------------------------------------------------
/**
@ -174,9 +175,6 @@ void DialogAlongLine::DeployFormulaTextEdit()
//---------------------------------------------------------------------------------------------------------------------
DialogAlongLine::~DialogAlongLine()
{
auto *locData = const_cast<VContainer *> (data);
locData->RemoveVariable(currentLength);
delete ui;
}
@ -209,25 +207,7 @@ void DialogAlongLine::ChosenObject(quint32 id, const SceneObject &type)
}
break;
case 1:
if (SetObject(id, ui->comboBoxSecondPoint, QString()))
{
if (m_flagError)
{
line->setObject2Id(id);
if (m_buildMidpoint)
{
SetFormula(currentLength + QStringLiteral("/2"));
}
line->RefreshGeometry();
prepare = true;
this->setModal(true);
this->show();
}
else
{
emit ToolTip(toolTip);
}
}
ChosenSecondPoint(id, toolTip);
break;
default:
break;
@ -284,6 +264,47 @@ void DialogAlongLine::SetCurrentLength()
locData->AddVariable(length);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::ChosenSecondPoint(quint32 id, const QString toolTip)
{
if (SetObject(id, ui->comboBoxSecondPoint, QString()))
{
auto *line = qobject_cast<VisToolAlongLine *>(vis);
SCASSERT(line != nullptr)
if (m_flagError)
{
line->setObject2Id(id);
if (m_buildMidpoint)
{
SetFormula(currentLength + QStringLiteral("/2"));
line->SetMode(Mode::Show);
}
else
{
auto *window = qobject_cast<VAbstractMainWindow *>(
VAbstractValApplication::VApp()->getMainWindow());
SCASSERT(window != nullptr)
connect(line, &Visualization::ToolTip, window, &VAbstractMainWindow::ShowToolTip);
}
line->RefreshGeometry();
prepare = true;
if (m_buildMidpoint)
{
setModal(true);
show();
}
}
else
{
emit ToolTip(toolTip);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetSecondPointId set id second point of line
@ -322,6 +343,62 @@ void DialogAlongLine::Build(const Tool &type)
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::ShowDialog(bool click)
{
if (not prepare || m_buildMidpoint)
{
return;
}
auto *lineVis = qobject_cast<VisToolAlongLine *>(vis);
SCASSERT(lineVis != nullptr)
auto FinishCreating = [this, lineVis]()
{
lineVis->SetMode(Mode::Show);
lineVis->RefreshGeometry();
emit ToolTip(QString());
setModal(true);
show();
};
if (click)
{
// The check need to ignore first release of mouse button.
// User can select point by clicking on a label.
if (not m_firstRelease)
{
m_firstRelease = true;
return;
}
auto *scene = qobject_cast<VMainGraphicsScene *>(VAbstractValApplication::VApp()->getCurrentScene());
SCASSERT(scene != nullptr)
const QSharedPointer<VPointF> p1 = data->GeometricObject<VPointF>(GetFirstPointId());
const QSharedPointer<VPointF> p2 = data->GeometricObject<VPointF>(GetSecondPointId());
QLineF baseLine(static_cast<QPointF>(*p1), static_cast<QPointF>(*p2));
QLineF line(static_cast<QPointF>(*p1), scene->getScenePos());
qreal len = line.length();
qreal angleTo = baseLine.angleTo(line);
if (angleTo > 90 && angleTo < 270)
{
len *= -1;
}
SetFormula(QString::number(FromPixel(len, *data->GetPatternUnit())));
FinishCreating();
}
FinishCreating();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetFirstPointId set id first point of line

View File

@ -75,6 +75,7 @@ public:
auto GetNotes() const -> QString;
void Build(const Tool &type) override;
void ShowDialog(bool click) override;
public slots:
void ChosenObject(quint32 id, const SceneObject &type) override;
/**
@ -115,7 +116,11 @@ private:
bool m_flagError{true};
bool m_flagName{true};
bool m_firstRelease{false};
void SetCurrentLength();
void ChosenSecondPoint(quint32 id, const QString toolTip);
};
//---------------------------------------------------------------------------------------------------------------------

View File

@ -147,9 +147,6 @@ void DialogCutArc::DeployFormulaTextEdit()
//---------------------------------------------------------------------------------------------------------------------
DialogCutArc::~DialogCutArc()
{
auto *locData = const_cast<VContainer *> (data);
locData->RemoveVariable(currentLength);
delete ui;
}

View File

@ -106,9 +106,6 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, quint32 toolId, QWidget
//---------------------------------------------------------------------------------------------------------------------
DialogCutSpline::~DialogCutSpline()
{
auto *locData = const_cast<VContainer *> (data);
locData->RemoveVariable(currentLength);
delete ui;
}

View File

@ -106,9 +106,6 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, quint32 toolId,
//---------------------------------------------------------------------------------------------------------------------
DialogCutSplinePath::~DialogCutSplinePath()
{
auto *locData = const_cast<VContainer *> (data);
locData->RemoveVariable(currentLength);
delete ui;
}

View File

@ -36,12 +36,12 @@
#include <Qt>
#include <new>
#include "../ifc/ifcdef.h"
#include "../vgeometry/vgobject.h"
#include "../vgeometry/vpointf.h"
#include "../vpatterndb/vcontainer.h"
#include "../visualization.h"
#include "visline.h"
#include "../vmisc/vmodifierkey.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolAlongLine::VisToolAlongLine(const VContainer *data, QGraphicsItem *parent)
@ -97,7 +97,7 @@ void VisToolAlongLine::RefreshGeometry()
if (m_midPointMode)
{
cursorLine.setLength(cursorLine.length()/2.0);
DrawPoint(lineP2, cursorLine.p2(), supportColor);
DrawPoint(point, cursorLine.p2(), mainColor);
}
}
else
@ -105,7 +105,8 @@ void VisToolAlongLine::RefreshGeometry()
const QSharedPointer<VPointF> second = Visualization::data->GeometricObject<VPointF>(object2Id);
DrawPoint(lineP2, static_cast<QPointF>(*second), supportColor);
DrawLine(line, QLineF(static_cast<QPointF>(*first), static_cast<QPointF>(*second)), supportColor);
QLineF baseLine(static_cast<QPointF>(*first), static_cast<QPointF>(*second));
DrawLine(line, baseLine, supportColor);
if (not qFuzzyIsNull(length))
{
@ -114,6 +115,28 @@ void VisToolAlongLine::RefreshGeometry()
DrawPoint(point, mainLine.p2(), mainColor);
}
else if (mode == Mode::Creation)
{
QLineF cursorLine (static_cast<QPointF>(*first), Visualization::scenePos);
qreal len = cursorLine.length();
qreal angleTo = baseLine.angleTo(cursorLine);
if (angleTo > 90 && angleTo < 270)
{
len *= -1;
}
QLineF mainLine = VGObject::BuildLine(static_cast<QPointF>(*first), len, line->line().angle());
DrawLine(this, mainLine, mainColor, lineStyle);
DrawPoint(point, mainLine.p2(), mainColor);
const QString prefix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
Visualization::toolTip = tr("Length = %1%2; "
"<b>Mouse click</b> - finish selecting the length, "
"<b>%3</b> - skip")
.arg(NumberToUser(len), prefix, VModifierKey::EnterKey());
}
}
}
}

View File

@ -81,13 +81,6 @@ void VisToolArc::RefreshGeometry()
return r.angle();
};
auto NumberToUser = [](qreal value)
{
return VAbstractApplication::VApp()->TrVars()
->FormulaToUser(QString::number(VAbstractValApplication::VApp()->fromPixel(value)),
VAbstractApplication::VApp()->Settings()->GetOsSeparator());
};
static const QString prefix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
if (qFuzzyIsNull(radius))

View File

@ -78,13 +78,6 @@ void VisToolArcWithLength::RefreshGeometry()
return r.angle();
};
auto NumberToUser = [](qreal value)
{
return VAbstractApplication::VApp()->TrVars()
->FormulaToUser(QString::number(VAbstractValApplication::VApp()->fromPixel(value)),
VAbstractApplication::VApp()->Settings()->GetOsSeparator());
};
static const QString prefix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
if (qFuzzyIsNull(radius))

View File

@ -329,6 +329,14 @@ VCurvePathItem *Visualization::GetCurveItem(QVector<VCurvePathItem *> &curves, q
}
}
//---------------------------------------------------------------------------------------------------------------------
QString Visualization::NumberToUser(qreal value)
{
return VAbstractApplication::VApp()->TrVars()
->FormulaToUser(QString::number(VAbstractValApplication::VApp()->fromPixel(value)),
VAbstractApplication::VApp()->Settings()->GetOsSeparator());
}
//---------------------------------------------------------------------------------------------------------------------
Mode Visualization::GetMode() const
{

View File

@ -122,6 +122,8 @@ protected:
QGraphicsItem *parent);
static VCurvePathItem *GetCurveItem(QVector<VCurvePathItem *> &curves, quint32 i, const QColor &color,
QGraphicsItem *parent);
static auto NumberToUser(qreal value) -> QString;
private:
Q_DISABLE_COPY_MOVE(Visualization) // NOLINT
};