Improve creating an arc by two angles.

This commit is contained in:
Roman Telezhynskyi 2022-05-11 17:31:58 +03:00
parent a0db254016
commit 4bf0571dc0
7 changed files with 324 additions and 100 deletions

View File

@ -49,6 +49,7 @@
#include "ui_dialogarc.h" #include "ui_dialogarc.h"
#include "../vgeometry/varc.h" #include "../vgeometry/varc.h"
#include "../qmuparser/qmudef.h" #include "../qmuparser/qmudef.h"
#include "../vwidgets/vabstractmainwindow.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
@ -59,20 +60,9 @@
DialogArc::DialogArc(const VContainer *data, quint32 toolId, QWidget *parent) DialogArc::DialogArc(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent), : DialogTool(data, toolId, parent),
ui(new Ui::DialogArc), ui(new Ui::DialogArc),
flagRadius(false),
flagF1(false),
flagF2(false),
timerRadius(new QTimer(this)), timerRadius(new QTimer(this)),
timerF1(new QTimer(this)), timerF1(new QTimer(this)),
timerF2(new QTimer(this)), timerF2(new QTimer(this))
radius(),
f1(),
f2(),
formulaBaseHeight(0),
formulaBaseHeightF1(0),
formulaBaseHeightF2(0),
angleF1(INT_MIN),
angleF2(INT_MIN)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -183,7 +173,7 @@ void DialogArc::SetF2(const QString &value)
} }
ui->plainTextEditF2->setPlainText(f2); ui->plainTextEditF2->setPlainText(f2);
VisToolArc *path = qobject_cast<VisToolArc *>(vis); auto *path = qobject_cast<VisToolArc *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->setF2(f2); path->setF2(f2);
@ -191,7 +181,7 @@ void DialogArc::SetF2(const QString &value)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogArc::GetPenStyle() const auto DialogArc::GetPenStyle() const -> QString
{ {
return GetComboBoxCurrentData(ui->comboBoxPenStyle, TypeLineLine); return GetComboBoxCurrentData(ui->comboBoxPenStyle, TypeLineLine);
} }
@ -203,7 +193,7 @@ void DialogArc::SetPenStyle(const QString &value)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogArc::GetColor() const auto DialogArc::GetColor() const -> QString
{ {
return GetComboBoxCurrentData(ui->comboBoxColor, ColorBlack); return GetComboBoxCurrentData(ui->comboBoxColor, ColorBlack);
} }
@ -215,7 +205,7 @@ void DialogArc::SetColor(const QString &value)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal DialogArc::GetApproximationScale() const auto DialogArc::GetApproximationScale() const -> qreal
{ {
return ui->doubleSpinBoxApproximationScale->value(); return ui->doubleSpinBoxApproximationScale->value();
} }
@ -225,7 +215,7 @@ void DialogArc::SetApproximationScale(qreal value)
{ {
ui->doubleSpinBoxApproximationScale->setValue(value); ui->doubleSpinBoxApproximationScale->setValue(value);
VisToolArc *path = qobject_cast<VisToolArc *>(vis); auto *path = qobject_cast<VisToolArc *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->setApproximationScale(value); path->setApproximationScale(value);
} }
@ -237,7 +227,7 @@ void DialogArc::SetNotes(const QString &notes)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogArc::GetNotes() const auto DialogArc::GetNotes() const -> QString
{ {
return ui->plainTextEditToolNotes->toPlainText(); return ui->plainTextEditToolNotes->toPlainText();
} }
@ -251,11 +241,98 @@ void DialogArc::SetAliasSuffix(const QString &alias)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogArc::GetAliasSuffix() const auto DialogArc::GetAliasSuffix() const -> QString
{ {
return ui->lineEditAlias->text(); return ui->lineEditAlias->text();
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogArc::ShowDialog(bool click)
{
if (prepare)
{
auto *arcVis = qobject_cast<VisToolArc *>(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(VisToolArc::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;
}
QString radius = QString::number(VAbstractValApplication::VApp()->fromPixel(line.length()));
arcVis->setRadius(radius);
SetRadius(radius);
arcVis->RefreshGeometry();
stageRadius = false;
stageF1 = true;
}
else if (stageF1)
{
QString f1 = QString::number(Angle());
arcVis->setF1(f1);
SetF1(f1);
arcVis->RefreshGeometry();
stageF1 = false;
}
else
{
QString f2 = QString::number(arcVis->StickyEnd(Angle()));
arcVis->setF2(f2);
SetF2(f2);
FinishCreating();
}
return;
}
FinishCreating();
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief SetF1 set formula first angle of arc * @brief SetF1 set formula first angle of arc
@ -272,7 +349,7 @@ void DialogArc::SetF1(const QString &value)
} }
ui->plainTextEditF1->setPlainText(f1); ui->plainTextEditF1->setPlainText(f1);
VisToolArc *path = qobject_cast<VisToolArc *>(vis); auto *path = qobject_cast<VisToolArc *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->setF1(f1); path->setF1(f1);
@ -295,7 +372,7 @@ void DialogArc::SetRadius(const QString &value)
} }
ui->plainTextEditFormula->setPlainText(radius); ui->plainTextEditFormula->setPlainText(radius);
VisToolArc *path = qobject_cast<VisToolArc *>(vis); auto *path = qobject_cast<VisToolArc *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->setRadius(radius); path->setRadius(radius);
@ -318,11 +395,15 @@ void DialogArc::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();
} }
} }
} }
@ -341,7 +422,7 @@ void DialogArc::SaveData()
f1 = ui->plainTextEditF1->toPlainText(); f1 = ui->plainTextEditF1->toPlainText();
f2 = ui->plainTextEditF2->toPlainText(); f2 = ui->plainTextEditF2->toPlainText();
VisToolArc *path = qobject_cast<VisToolArc *>(vis); auto *path = qobject_cast<VisToolArc *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->setObject1Id(GetCenter()); path->setObject1Id(GetCenter());
@ -386,7 +467,7 @@ void DialogArc::ValidateAlias()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArc::FXRadius() void DialogArc::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));
@ -400,7 +481,7 @@ void DialogArc::FXRadius()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArc::FXF1() void DialogArc::FXF1()
{ {
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); auto *dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit first angle")); dialog->setWindowTitle(tr("Edit first angle"));
dialog->SetFormula(GetF1()); dialog->SetFormula(GetF1());
dialog->setPostfix(degreeSymbol); dialog->setPostfix(degreeSymbol);
@ -414,7 +495,7 @@ void DialogArc::FXF1()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArc::FXF2() void DialogArc::FXF2()
{ {
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); auto *dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit second angle")); dialog->setWindowTitle(tr("Edit second angle"));
dialog->SetFormula(GetF2()); dialog->SetFormula(GetF2());
dialog->setPostfix(degreeSymbol); dialog->setPostfix(degreeSymbol);
@ -479,7 +560,7 @@ void DialogArc::EvalF()
* @brief GetCenter return id of center point * @brief GetCenter return id of center point
* @return id id * @return id id
*/ */
quint32 DialogArc::GetCenter() const auto DialogArc::GetCenter() const -> quint32
{ {
return getCurrentObjectId(ui->comboBoxBasePoint); return getCurrentObjectId(ui->comboBoxBasePoint);
} }
@ -489,10 +570,9 @@ quint32 DialogArc::GetCenter() const
* @brief GetRadius return formula of radius * @brief GetRadius return formula of radius
* @return formula * @return formula
*/ */
QString DialogArc::GetRadius() const auto DialogArc::GetRadius() const -> QString
{ {
return VAbstractApplication::VApp()->TrVars() return VTranslateVars::TryFormulaFromUser(radius, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
->TryFormulaFromUser(radius, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -500,10 +580,9 @@ QString DialogArc::GetRadius() const
* @brief GetF1 return formula first angle of arc * @brief GetF1 return formula first angle of arc
* @return formula * @return formula
*/ */
QString DialogArc::GetF1() const auto DialogArc::GetF1() const -> QString
{ {
return VAbstractApplication::VApp()->TrVars() return VTranslateVars::TryFormulaFromUser(f1, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
->TryFormulaFromUser(f1, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -511,8 +590,7 @@ QString DialogArc::GetF1() const
* @brief GetF2 return formula second angle of arc * @brief GetF2 return formula second angle of arc
* @return formula * @return formula
*/ */
QString DialogArc::GetF2() const auto DialogArc::GetF2() const -> QString
{ {
return VAbstractApplication::VApp()->TrVars() return VTranslateVars::TryFormulaFromUser(f2, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
->TryFormulaFromUser(f2, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
} }

View File

@ -48,39 +48,41 @@ namespace Ui
*/ */
class DialogArc final : public DialogTool class DialogArc final : public DialogTool
{ {
Q_OBJECT Q_OBJECT // NOLINT
public: public:
DialogArc(const VContainer *data, quint32 toolId, QWidget *parent = nullptr); DialogArc(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogArc() override; ~DialogArc() 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 GetF2() const; auto GetF2() const -> QString;
void SetF2(const QString &value); void SetF2(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
*/ */
@ -93,30 +95,30 @@ public slots:
void FXF2(); void FXF2();
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(DialogArc) Q_DISABLE_COPY_MOVE(DialogArc) // NOLINT
/** @brief ui keeps information about user interface */ /** @brief ui keeps information about user interface */
Ui::DialogArc *ui; Ui::DialogArc *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};
/** @brief flagF2 true if value of second angle is correct */ /** @brief flagF2 true if value of second angle is correct */
bool flagF2; bool flagF2{false};
bool flagAlias{true}; bool flagAlias{true};
@ -130,30 +132,35 @@ private:
QTimer *timerF2; QTimer *timerF2;
/** @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{};
/** @brief f2 formula of second angle */ /** @brief f2 formula of second angle */
QString f2; QString f2{};
/** @brief formulaBaseHeight base height defined by dialogui */ /** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight; int formulaBaseHeight{0};
int formulaBaseHeightF1; int formulaBaseHeightF1{0};
int formulaBaseHeightF2; int formulaBaseHeightF2{0};
qreal angleF1; qreal angleF1{INT_MIN};
qreal angleF2; qreal angleF2{INT_MIN};
QString originAliasSuffix{}; QString originAliasSuffix{};
void EvalRadius(); bool stageRadius{true};
void EvalF(); bool stageF1{false};
bool m_firstRelease{false};
void EvalRadius();
void EvalF();
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline bool DialogArc::IsValid() const inline auto DialogArc::IsValid() const -> bool
{ {
return flagRadius && flagF1 && flagF2 && flagAlias; return flagRadius && flagF1 && flagF2 && flagAlias;
} }

View File

@ -368,7 +368,7 @@ void VToolArc::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);
VisToolArc *visual = qobject_cast<VisToolArc *>(vis); auto *visual = qobject_cast<VisToolArc *>(vis);
SCASSERT(visual != nullptr) SCASSERT(visual != nullptr)
const VTranslateVars *trVars = VAbstractApplication::VApp()->TrVars(); const VTranslateVars *trVars = VAbstractApplication::VApp()->TrVars();
@ -381,6 +381,7 @@ void VToolArc::SetVisualization()
arc->GetFormulaF2(), VAbstractApplication::VApp()->Settings()->GetOsSeparator())); arc->GetFormulaF2(), 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

@ -40,14 +40,21 @@
#include "../vgeometry/vpointf.h" #include "../vgeometry/vpointf.h"
#include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vcontainer.h"
#include "../visualization.h" #include "../visualization.h"
#include "def.h"
#include "qglobal.h"
#include "qmudef.h"
#include "qnamespace.h"
#include "vgeometrydef.h"
#include "vispath.h" #include "vispath.h"
#include "../vwidgets/scalesceneitems.h" #include "../vwidgets/scalesceneitems.h"
#include "../vmisc/vmodifierkey.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VisToolArc::VisToolArc(const VContainer *data, QGraphicsItem *parent) VisToolArc::VisToolArc(const VContainer *data, QGraphicsItem *parent)
:VisPath(data, parent), arcCenter(nullptr), radius(0), f1(0), f2(0) :VisPath(data, parent)
{ {
arcCenter = InitPoint(mainColor, this); arcCenter = InitPoint(mainColor, this);
f1Point = InitPoint(supportColor, this);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -55,14 +62,98 @@ void VisToolArc::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 && f2 >= 0) if (mode == Mode::Creation)
{ {
VArc arc = VArc (*first, radius, f1, f2); 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)
{
qreal f2Angle = StickyEnd(Angle());
VArc arc = VArc (*first, radius, f1, f2Angle);
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°, second angle = %4°; "
"<b>Mouse click</b> - finish creating, "
"<b>%5</b> - sticking angle, "
"<b>%6</b> - sticking end, "
"<b>%7</b> - skip")
.arg(NumberToUser(radius), prefix)
.arg(f1)
.arg(f2Angle)
.arg(VModifierKey::Shift(), VModifierKey::Control(), VModifierKey::EnterKey());
}
}
else
{
if (not qFuzzyIsNull(radius) && f1 >= 0 && f2 >= 0)
{
VArc arc = VArc (*first, radius, f1, f2);
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 +175,37 @@ void VisToolArc::setF2(const QString &expression)
{ {
f2 = FindValFromUser(expression, Visualization::data->DataVariables()); f2 = FindValFromUser(expression, Visualization::data->DataVariables());
} }
//---------------------------------------------------------------------------------------------------------------------
auto VisToolArc::CorrectAngle(qreal angle) -> qreal
{
qreal ang = angle;
if (angle > 360)
{
ang = angle - 360.0 * qFloor(angle/360);
}
return (qFloor(qAbs(ang)/5.)) * 5;
}
//---------------------------------------------------------------------------------------------------------------------
auto VisToolArc::StickyEnd(qreal angle) const -> qreal
{
if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier)
{
QLineF line(10, 10, 100, 10);
line.setLength(radius);
QLineF line2 = line;
line.setAngle(f1);
line2.setAngle(angle);
if (VFuzzyComparePoints(line.p2(), line2.p2(), UnitConvertor(5, Unit::Mm, Unit::Px)))
{
return f1;
}
}
return angle;
}

View File

@ -37,27 +37,32 @@
#include <QtGlobal> #include <QtGlobal>
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "defglobal.h"
#include "vispath.h" #include "vispath.h"
class VisToolArc final : public VisPath class VisToolArc final : public VisPath
{ {
Q_OBJECT Q_OBJECT // NOLINT
public: public:
explicit VisToolArc(const VContainer *data, QGraphicsItem *parent = nullptr); explicit VisToolArc(const VContainer *data, QGraphicsItem *parent = nullptr);
virtual ~VisToolArc() Q_DECL_EQ_DEFAULT; ~VisToolArc() 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 setF2(const QString &expression); void setF2(const QString &expression);
virtual int type() const override {return Type;} auto type() const -> int override {return Type;}
enum { Type = UserType + static_cast<int>(Vis::ToolArc)}; enum { Type = UserType + static_cast<int>(Vis::ToolArc)};
static auto CorrectAngle(qreal angle) -> qreal;
auto StickyEnd(qreal angle) const -> qreal;
private: private:
Q_DISABLE_COPY(VisToolArc) Q_DISABLE_COPY_MOVE(VisToolArc) // NOLINT
VScaledEllipse *arcCenter; VScaledEllipse *arcCenter{nullptr};
qreal radius; VScaledEllipse *f1Point{nullptr};
qreal f1; qreal radius{0};
qreal f2; qreal f1{-1};
qreal f2{-1};
}; };
#endif // VISTOOLARC_H #endif // VISTOOLARC_H

View File

@ -168,10 +168,7 @@ void Visualization::MousePos(const QPointF &scenePos)
{ {
this->scenePos = scenePos; this->scenePos = scenePos;
RefreshGeometry(); RefreshGeometry();
if (toolTip.isEmpty() == false) RefreshToolTip();
{
emit ToolTip(toolTip);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -229,6 +226,15 @@ qreal Visualization::FindValFromUser(const QString &expression,
return val; return val;
} }
//---------------------------------------------------------------------------------------------------------------------
void Visualization::RefreshToolTip() const
{
if (!toolTip.isEmpty())
{
emit ToolTip(toolTip);
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void Visualization::DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, Qt::PenStyle style) void Visualization::DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, Qt::PenStyle style)
{ {

View File

@ -82,8 +82,10 @@ public:
QSharedPointer<VInternalVariable> > *vars, bool fromUser = true); QSharedPointer<VInternalVariable> > *vars, bool fromUser = true);
QString CurrentToolTip() const {return toolTip;} QString CurrentToolTip() const {return toolTip;}
void RefreshToolTip() const;
signals: signals:
void ToolTip(const QString &toolTip); void ToolTip(const QString &toolTip) const;
public slots: public slots:
void MousePos(const QPointF &scenePos); void MousePos(const QPointF &scenePos);
protected: protected: