Improve creating an arc by length.

This commit is contained in:
Roman Telezhynskyi 2022-05-11 19:08:08 +03:00
parent b8872a0319
commit 43aee75f64
6 changed files with 296 additions and 115 deletions

View file

@ -301,28 +301,20 @@ void DialogArc::ShowDialog(bool click)
return; return;
} }
QString radius = QString::number(VAbstractValApplication::VApp()->fromPixel(line.length())); SetRadius(QString::number(VAbstractValApplication::VApp()->fromPixel(line.length())));
arcVis->setRadius(radius);
SetRadius(radius);
arcVis->RefreshGeometry(); arcVis->RefreshGeometry();
stageRadius = false; stageRadius = false;
stageF1 = true; stageF1 = true;
} }
else if (stageF1) else if (stageF1)
{ {
QString f1 = QString::number(Angle()); SetF1(QString::number(Angle()));
arcVis->setF1(f1);
SetF1(f1);
arcVis->RefreshGeometry(); arcVis->RefreshGeometry();
stageF1 = false; stageF1 = false;
} }
else else
{ {
QString f2 = QString::number(arcVis->StickyEnd(Angle())); SetF2(QString::number(arcVis->StickyEnd(Angle())));
arcVis->setF2(f2);
SetF2(f2);
FinishCreating(); FinishCreating();
} }
@ -395,7 +387,8 @@ void DialogArc::ChosenObject(quint32 id, const SceneObject &type)
{ {
if (vis != nullptr) if (vis != nullptr)
{ {
auto *window = qobject_cast<VAbstractMainWindow *>(VAbstractValApplication::VApp()->getMainWindow()); auto *window = qobject_cast<VAbstractMainWindow *>(
VAbstractValApplication::VApp()->getMainWindow());
SCASSERT(window != nullptr) SCASSERT(window != nullptr)
connect(vis.data(), &Visualization::ToolTip, window, &VAbstractMainWindow::ShowToolTip); connect(vis.data(), &Visualization::ToolTip, window, &VAbstractMainWindow::ShowToolTip);

View file

@ -49,23 +49,15 @@
#include "ui_dialogarcwithlength.h" #include "ui_dialogarcwithlength.h"
#include "../vgeometry/varc.h" #include "../vgeometry/varc.h"
#include "../qmuparser/qmudef.h" #include "../qmuparser/qmudef.h"
#include "../vwidgets/vabstractmainwindow.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogArcWithLength::DialogArcWithLength(const VContainer *data, quint32 toolId, QWidget *parent) DialogArcWithLength::DialogArcWithLength(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent), : DialogTool(data, toolId, parent),
ui(new Ui::DialogArcWithLength), ui(new Ui::DialogArcWithLength),
flagRadius(false),
flagF1(false),
flagLength(false),
timerRadius(new QTimer(this)), timerRadius(new QTimer(this)),
timerF1(new QTimer(this)), timerF1(new QTimer(this)),
timerLength(new QTimer(this)), timerLength(new QTimer(this))
radius(),
f1(),
length(),
formulaBaseHeightRadius(0),
formulaBaseHeightF1(0),
formulaBaseHeightLength(0)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -132,7 +124,7 @@ DialogArcWithLength::~DialogArcWithLength()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
quint32 DialogArcWithLength::GetCenter() const auto DialogArcWithLength::GetCenter() const -> quint32
{ {
return getCurrentObjectId(ui->comboBoxCenter); return getCurrentObjectId(ui->comboBoxCenter);
} }
@ -145,10 +137,9 @@ void DialogArcWithLength::SetCenter(const quint32 &value)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogArcWithLength::GetRadius() const auto DialogArcWithLength::GetRadius() const -> QString
{ {
return VAbstractApplication::VApp()->TrVars() return VTranslateVars::TryFormulaFromUser(radius, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
->TryFormulaFromUser(radius, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -163,7 +154,7 @@ void DialogArcWithLength::SetRadius(const QString &value)
} }
ui->plainTextEditRadius->setPlainText(radius); ui->plainTextEditRadius->setPlainText(radius);
VisToolArcWithLength *path = qobject_cast<VisToolArcWithLength *>(vis); auto *path = qobject_cast<VisToolArcWithLength *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->setRadius(radius); path->setRadius(radius);
@ -171,12 +162,12 @@ void DialogArcWithLength::SetRadius(const QString &value)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogArcWithLength::GetF1() const auto DialogArcWithLength::GetF1() const -> QString
{ {
return VAbstractApplication::VApp()->TrVars() return VTranslateVars::TryFormulaFromUser(f1, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
->TryFormulaFromUser(f1, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::SetF1(const QString &value) void DialogArcWithLength::SetF1(const QString &value)
{ {
f1 = VAbstractApplication::VApp()->TrVars() f1 = VAbstractApplication::VApp()->TrVars()
@ -188,7 +179,7 @@ void DialogArcWithLength::SetF1(const QString &value)
} }
ui->plainTextEditF1->setPlainText(f1); ui->plainTextEditF1->setPlainText(f1);
VisToolArcWithLength *path = qobject_cast<VisToolArcWithLength *>(vis); auto *path = qobject_cast<VisToolArcWithLength *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->setF1(f1); path->setF1(f1);
@ -196,10 +187,9 @@ void DialogArcWithLength::SetF1(const QString &value)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogArcWithLength::GetLength() const auto DialogArcWithLength::GetLength() const -> QString
{ {
return VAbstractApplication::VApp()->TrVars() return VTranslateVars::TryFormulaFromUser(length, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
->TryFormulaFromUser(length, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -214,15 +204,15 @@ void DialogArcWithLength::SetLength(const QString &value)
} }
ui->plainTextEditLength->setPlainText(length); ui->plainTextEditLength->setPlainText(length);
VisToolArcWithLength *path = qobject_cast<VisToolArcWithLength *>(vis); auto *path = qobject_cast<VisToolArcWithLength *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->setLength(radius); path->setLength(length);
MoveCursorToEnd(ui->plainTextEditLength); MoveCursorToEnd(ui->plainTextEditLength);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogArcWithLength::GetPenStyle() const auto DialogArcWithLength::GetPenStyle() const -> QString
{ {
return GetComboBoxCurrentData(ui->comboBoxPenStyle, TypeLineLine); return GetComboBoxCurrentData(ui->comboBoxPenStyle, TypeLineLine);
} }
@ -234,7 +224,7 @@ void DialogArcWithLength::SetPenStyle(const QString &value)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogArcWithLength::GetColor() const auto DialogArcWithLength::GetColor() const -> QString
{ {
return GetComboBoxCurrentData(ui->comboBoxColor, ColorBlack); return GetComboBoxCurrentData(ui->comboBoxColor, ColorBlack);
} }
@ -246,7 +236,7 @@ void DialogArcWithLength::SetColor(const QString &value)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal DialogArcWithLength::GetApproximationScale() const auto DialogArcWithLength::GetApproximationScale() const -> qreal
{ {
return ui->doubleSpinBoxApproximationScale->value(); return ui->doubleSpinBoxApproximationScale->value();
} }
@ -256,7 +246,7 @@ void DialogArcWithLength::SetApproximationScale(qreal value)
{ {
ui->doubleSpinBoxApproximationScale->setValue(value); ui->doubleSpinBoxApproximationScale->setValue(value);
VisToolArcWithLength *path = qobject_cast<VisToolArcWithLength *>(vis); auto *path = qobject_cast<VisToolArcWithLength *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->setApproximationScale(value); path->setApproximationScale(value);
} }
@ -268,7 +258,7 @@ void DialogArcWithLength::SetNotes(const QString &notes)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogArcWithLength::GetNotes() const auto DialogArcWithLength::GetNotes() const -> QString
{ {
return ui->plainTextEditToolNotes->toPlainText(); return ui->plainTextEditToolNotes->toPlainText();
} }
@ -282,15 +272,101 @@ void DialogArcWithLength::SetAliasSuffix(const QString &alias)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogArcWithLength::GetAliasSuffix() const auto DialogArcWithLength::GetAliasSuffix() const -> QString
{ {
return ui->lineEditAlias->text(); return ui->lineEditAlias->text();
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::ShowDialog(bool click)
{
if (prepare)
{
auto *arcVis = qobject_cast<VisToolArcWithLength *>(vis);
SCASSERT(arcVis != nullptr)
auto FinishCreating = [this, arcVis]()
{
arcVis->SetMode(Mode::Show);
arcVis->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;
}
/*We will ignore click if pointer is in point circle*/
auto *scene = qobject_cast<VMainGraphicsScene *>(VAbstractValApplication::VApp()->getCurrentScene());
SCASSERT(scene != nullptr)
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(GetCenter());
QLineF line = QLineF(static_cast<QPointF>(*point), scene->getScenePos());
auto Angle = [line]()
{
if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier)
{
QLineF correction = line;
correction.setAngle(VisToolArcWithLength::CorrectAngle(correction.angle()));
return correction.angle();
}
return line.angle();
};
if (stageRadius)
{
//Radius of point circle, but little bigger. Need handle with hover sizes.
if (line.length() <= ScaledRadius(SceneScale(VAbstractValApplication::VApp()->getCurrentScene()))*1.5)
{
return;
}
SetRadius(QString::number(VAbstractValApplication::VApp()->fromPixel(line.length())));
arcVis->RefreshGeometry();
stageRadius = false;
stageF1 = true;
}
else if (stageF1)
{
SetF1(QString::number(Angle()));
arcVis->RefreshGeometry();
stageF1 = false;
}
else
{
VArc arc(*point, VAbstractValApplication::VApp()->toPixel(radius.toDouble()), f1.toDouble(),
line.angle());
SetLength(QString::number(VAbstractValApplication::VApp()->fromPixel(arc.GetLength())));
FinishCreating();
}
return;
}
FinishCreating();
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::ChosenObject(quint32 id, const SceneObject &type) void DialogArcWithLength::ChosenObject(quint32 id, const SceneObject &type)
{ {
if (prepare == false)// After first choose we ignore all objects if (not prepare)// After first choose we ignore all objects
{ {
if (type == SceneObject::Point) if (type == SceneObject::Point)
{ {
@ -298,11 +374,16 @@ void DialogArcWithLength::ChosenObject(quint32 id, const SceneObject &type)
{ {
if (vis != nullptr) if (vis != nullptr)
{ {
auto *window = qobject_cast<VAbstractMainWindow *>(
VAbstractValApplication::VApp()->getMainWindow());
SCASSERT(window != nullptr)
connect(vis.data(), &Visualization::ToolTip, window, &VAbstractMainWindow::ShowToolTip);
vis->VisualMode(id); vis->VisualMode(id);
vis->RefreshToolTip();
} }
prepare = true; prepare = true;
this->setModal(true);
this->show();
} }
} }
} }
@ -329,7 +410,7 @@ void DialogArcWithLength::DeployLengthTextEdit()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::FXRadius() void DialogArcWithLength::FXRadius()
{ {
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); auto *dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit radius")); dialog->setWindowTitle(tr("Edit radius"));
dialog->SetFormula(GetRadius()); dialog->SetFormula(GetRadius());
dialog->setPostfix(UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true)); dialog->setPostfix(UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true));
@ -343,7 +424,7 @@ void DialogArcWithLength::FXRadius()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::FXF1() void DialogArcWithLength::FXF1()
{ {
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); auto *dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit the first angle")); dialog->setWindowTitle(tr("Edit the first angle"));
dialog->SetFormula(GetF1()); dialog->SetFormula(GetF1());
dialog->setPostfix(degreeSymbol); dialog->setPostfix(degreeSymbol);
@ -357,7 +438,7 @@ void DialogArcWithLength::FXF1()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::FXLength() void DialogArcWithLength::FXLength()
{ {
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); auto *dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit the arc length")); dialog->setWindowTitle(tr("Edit the arc length"));
dialog->SetFormula(GetLength()); dialog->SetFormula(GetLength());
dialog->setPostfix(UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true)); dialog->setPostfix(UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true));
@ -381,7 +462,7 @@ void DialogArcWithLength::SaveData()
f1 = ui->plainTextEditF1->toPlainText(); f1 = ui->plainTextEditF1->toPlainText();
length = ui->plainTextEditLength->toPlainText(); length = ui->plainTextEditLength->toPlainText();
VisToolArcWithLength *path = qobject_cast<VisToolArcWithLength *>(vis); auto *path = qobject_cast<VisToolArcWithLength *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->setObject1Id(GetCenter()); path->setObject1Id(GetCenter());

View file

@ -36,6 +36,7 @@
#include <QtGlobal> #include <QtGlobal>
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "defglobal.h"
#include "dialogtool.h" #include "dialogtool.h"
namespace Ui namespace Ui
@ -45,40 +46,42 @@ namespace Ui
class DialogArcWithLength final : public DialogTool class DialogArcWithLength final : public DialogTool
{ {
Q_OBJECT Q_OBJECT // NOLINT
public: public:
DialogArcWithLength(const VContainer *data, quint32 toolId, QWidget *parent = nullptr); DialogArcWithLength(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
~DialogArcWithLength(); ~DialogArcWithLength() override;
quint32 GetCenter() const; auto GetCenter() const -> quint32;
void SetCenter(const quint32 &value); void SetCenter(const quint32 &value);
QString GetRadius() const; auto GetRadius() const -> QString;
void SetRadius(const QString &value); void SetRadius(const QString &value);
QString GetF1() const; auto GetF1() const -> QString;
void SetF1(const QString &value); void SetF1(const QString &value);
QString GetLength() const; auto GetLength() const -> QString;
void SetLength(const QString &value); void SetLength(const QString &value);
QString GetPenStyle() const; auto GetPenStyle() const -> QString;
void SetPenStyle(const QString &value); void SetPenStyle(const QString &value);
QString GetColor() const; auto GetColor() const -> QString;
void SetColor(const QString &value); void SetColor(const QString &value);
qreal GetApproximationScale() const; auto GetApproximationScale() const -> qreal;
void SetApproximationScale(qreal value); void SetApproximationScale(qreal value);
void SetNotes(const QString &notes); void SetNotes(const QString &notes);
QString GetNotes() const; auto GetNotes() const -> QString;
void SetAliasSuffix(const QString &alias); void SetAliasSuffix(const QString &alias);
QString GetAliasSuffix() const; auto GetAliasSuffix() const -> QString;
void ShowDialog(bool click) override;
public slots: public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override; void ChosenObject(quint32 id, const SceneObject &type) override;
/** /**
* @brief DeployFormulaTextEdit grow or shrink formula input * @brief DeployFormulaTextEdit grow or shrink formula input
*/ */
@ -86,66 +89,71 @@ public slots:
void DeployF1TextEdit(); void DeployF1TextEdit();
void DeployLengthTextEdit(); void DeployLengthTextEdit();
void FXRadius(); void FXRadius();
void FXF1(); void FXF1();
void FXLength(); void FXLength();
protected: protected:
virtual void ShowVisualization() override; void ShowVisualization() override;
/** /**
* @brief SaveData Put dialog data in local variables * @brief SaveData Put dialog data in local variables
*/ */
virtual void SaveData() override; void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final; auto IsValid() const -> bool final;
private slots: private slots:
void ValidateAlias(); void ValidateAlias();
private: private:
Q_DISABLE_COPY(DialogArcWithLength) Q_DISABLE_COPY_MOVE(DialogArcWithLength) // NOLINT
Ui::DialogArcWithLength *ui; Ui::DialogArcWithLength *ui;
/** @brief flagRadius true if value of radius is correct */ /** @brief flagRadius true if value of radius is correct */
bool flagRadius; bool flagRadius{false};
/** @brief flagF1 true if value of first angle is correct */ /** @brief flagF1 true if value of first angle is correct */
bool flagF1; bool flagF1{false};
bool flagLength; bool flagLength{false};
bool flagAlias{true}; bool flagAlias{true};
/** @brief timerRadius timer of check formula of radius */ /** @brief timerRadius timer of check formula of radius */
QTimer *timerRadius; QTimer *timerRadius;
/** @brief timerF1 timer of check formula of first angle */ /** @brief timerF1 timer of check formula of first angle */
QTimer *timerF1; QTimer *timerF1;
QTimer *timerLength; QTimer *timerLength;
/** @brief radius formula of radius */ /** @brief radius formula of radius */
QString radius; QString radius{};
/** @brief f1 formula of first angle */ /** @brief f1 formula of first angle */
QString f1; QString f1{};
QString length; QString length{};
/** @brief formulaBaseHeight base height defined by dialogui */ /** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeightRadius; int formulaBaseHeightRadius{0};
int formulaBaseHeightF1; int formulaBaseHeightF1{0};
int formulaBaseHeightLength; int formulaBaseHeightLength{0};
QString originAliasSuffix{}; QString originAliasSuffix{};
void Radius(); bool stageRadius{true};
void Length(); bool stageF1{false};
void EvalF();
bool m_firstRelease{false};
void Radius();
void Length();
void EvalF();
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline bool DialogArcWithLength::IsValid() const inline auto DialogArcWithLength::IsValid() const -> bool
{ {
return flagRadius && flagF1 && flagLength && flagAlias; return flagRadius && flagF1 && flagLength && flagAlias;
} }

View file

@ -347,7 +347,7 @@ void VToolArcWithLength::SetVisualization()
if (not vis.isNull()) if (not vis.isNull())
{ {
const QSharedPointer<VArc> arc = VAbstractTool::data.GeometricObject<VArc>(m_id); const QSharedPointer<VArc> arc = VAbstractTool::data.GeometricObject<VArc>(m_id);
VisToolArcWithLength *visual = qobject_cast<VisToolArcWithLength *>(vis); auto *visual = qobject_cast<VisToolArcWithLength *>(vis);
SCASSERT(visual != nullptr) SCASSERT(visual != nullptr)
const VTranslateVars *trVars = VAbstractApplication::VApp()->TrVars(); const VTranslateVars *trVars = VAbstractApplication::VApp()->TrVars();
@ -360,6 +360,7 @@ void VToolArcWithLength::SetVisualization()
VAbstractApplication::VApp()->Settings()->GetOsSeparator())); VAbstractApplication::VApp()->Settings()->GetOsSeparator()));
visual->setLineStyle(LineStyleToPenStyle(arc->GetPenStyle())); visual->setLineStyle(LineStyleToPenStyle(arc->GetPenStyle()));
visual->setApproximationScale(arc->GetApproximationScale()); visual->setApproximationScale(arc->GetApproximationScale());
visual->SetMode(Mode::Show);
visual->RefreshGeometry(); visual->RefreshGeometry();
} }
} }

View file

@ -42,12 +42,14 @@
#include "../visualization.h" #include "../visualization.h"
#include "../vwidgets/scalesceneitems.h" #include "../vwidgets/scalesceneitems.h"
#include "vispath.h" #include "vispath.h"
#include "../vmisc/vmodifierkey.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VisToolArcWithLength::VisToolArcWithLength(const VContainer *data, QGraphicsItem *parent) VisToolArcWithLength::VisToolArcWithLength(const VContainer *data, QGraphicsItem *parent)
:VisPath(data, parent), arcCenter(nullptr), radius(0), f1(0), length(0) :VisPath(data, parent)
{ {
arcCenter = InitPoint(mainColor, this); arcCenter = InitPoint(mainColor, this);
f1Point = InitPoint(supportColor, this);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -55,14 +57,94 @@ void VisToolArcWithLength::RefreshGeometry()
{ {
if (object1Id > NULL_ID) if (object1Id > NULL_ID)
{ {
f1Point->setVisible(false);
const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(object1Id); const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(object1Id);
DrawPoint(arcCenter, static_cast<QPointF>(*first), supportColor); DrawPoint(arcCenter, static_cast<QPointF>(*first), supportColor);
if (not qFuzzyIsNull(radius) && f1 >= 0 && not qFuzzyIsNull(length)) if (mode == Mode::Creation)
{ {
VArc arc = VArc (length, *first, radius, f1); QLineF r = QLineF(static_cast<QPointF>(*first), Visualization::scenePos);
arc.SetApproximationScale(m_approximationScale);
DrawPath(this, arc.GetPath(), arc.DirectionArrows(), mainColor, lineStyle, Qt::RoundCap); auto Angle = [r]()
{
if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier)
{
QLineF correction = r;
correction.setAngle(CorrectAngle(correction.angle()));
return correction.angle();
}
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))
{
VArc arc = VArc (*first, r.length(), r.angle(), r.angle());
arc.SetApproximationScale(m_approximationScale);
DrawPath(this, arc.GetPath(), QVector<DirectionArrow>(), supportColor, Qt::DashLine, Qt::RoundCap);
Visualization::toolTip = tr("<b>Arc</b>: radius = %1%2; "
"<b>Mouse click</b> - finish selecting the radius, "
"<b>%3</b> - skip")
.arg(NumberToUser(r.length()), prefix, VModifierKey::EnterKey());
}
else if (f1 < 0)
{
qreal f1Angle = Angle();
VArc arc = VArc (*first, radius, f1Angle, f1Angle);
arc.SetApproximationScale(m_approximationScale);
DrawPath(this, arc.GetPath(), QVector<DirectionArrow>(), supportColor, Qt::DashLine, Qt::RoundCap);
QLineF f1Line = r;
f1Line.setLength(radius);
f1Line.setAngle(f1Angle);
DrawPoint(f1Point, f1Line.p2(), supportColor);
Visualization::toolTip = tr("<b>Arc</b>: radius = %1%2, first angle = %3°; "
"<b>Mouse click</b> - finish selecting the first angle, "
"<b>%4</b> - sticking angle, "
"<b>%5</b> - skip")
.arg(NumberToUser(radius), prefix)
.arg(f1Angle)
.arg(VModifierKey::Shift(), VModifierKey::EnterKey());
}
else if (f1 >= 0)
{
VArc arc = VArc (*first, radius, f1, r.angle());
arc.SetApproximationScale(m_approximationScale);
DrawPath(this, arc.GetPath(), arc.DirectionArrows(), mainColor, lineStyle, Qt::RoundCap);
Visualization::toolTip = tr("<b>Arc</b>: radius = %1%2, first angle = %3°, arc length = %4%2; "
"<b>Mouse click</b> - finish creating, "
"<b>%5</b> - skip")
.arg(NumberToUser(radius), prefix)
.arg(f1)
.arg(NumberToUser(arc.GetLength()), VModifierKey::EnterKey());
}
}
else
{
if (not qFuzzyIsNull(radius) && f1 >= 0 && not qFuzzyIsNull(length))
{
VArc arc = VArc (length, *first, radius, f1);
arc.SetApproximationScale(m_approximationScale);
DrawPath(this, arc.GetPath(), arc.DirectionArrows(), mainColor, lineStyle, Qt::RoundCap);
}
else
{
DrawPath(this, QPainterPath(), QVector<DirectionArrow>(), mainColor, lineStyle, Qt::RoundCap);
}
} }
} }
} }
@ -84,3 +166,15 @@ void VisToolArcWithLength::setLength(const QString &expression)
{ {
length = FindLengthFromUser(expression, Visualization::data->DataVariables()); length = FindLengthFromUser(expression, Visualization::data->DataVariables());
} }
//---------------------------------------------------------------------------------------------------------------------
auto VisToolArcWithLength::CorrectAngle(qreal angle) -> qreal
{
qreal ang = angle;
if (angle > 360)
{
ang = angle - 360.0 * qFloor(angle/360);
}
return (qFloor(qAbs(ang)/5.)) * 5;
}

View file

@ -38,26 +38,30 @@
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "vispath.h" #include "vispath.h"
#include "defglobal.h"
class VisToolArcWithLength final : public VisPath class VisToolArcWithLength final : public VisPath
{ {
Q_OBJECT Q_OBJECT // NOLINT
public: public:
explicit VisToolArcWithLength(const VContainer *data, QGraphicsItem *parent = nullptr); explicit VisToolArcWithLength(const VContainer *data, QGraphicsItem *parent = nullptr);
virtual ~VisToolArcWithLength() Q_DECL_EQ_DEFAULT; ~VisToolArcWithLength() override =default;
virtual void RefreshGeometry() override; void RefreshGeometry() override;
void setRadius(const QString &expression); void setRadius(const QString &expression);
void setF1(const QString &expression); void setF1(const QString &expression);
void setLength(const QString &expression); void setLength(const QString &expression);
virtual int type() const override {return Type;} auto type() const -> int override {return Type;}
enum { Type = UserType + static_cast<int>(Vis::ToolArcWithLength)}; enum {Type = UserType + static_cast<int>(Vis::ToolArcWithLength)};
static auto CorrectAngle(qreal angle) -> qreal;
private: private:
Q_DISABLE_COPY(VisToolArcWithLength) Q_DISABLE_COPY_MOVE(VisToolArcWithLength) // NOLINT
VScaledEllipse *arcCenter; VScaledEllipse *arcCenter{nullptr};
qreal radius; VScaledEllipse *f1Point{nullptr};
qreal f1; qreal radius{0};
qreal length; qreal f1{-1};
qreal length{0};
}; };
#endif // VISTOOLARCWITHLENGTH_H #endif // VISTOOLARCWITHLENGTH_H