Improve visualization for tool Point of intersection circles.
This commit is contained in:
parent
4d104a789e
commit
0939d28c41
|
@ -49,6 +49,8 @@
|
||||||
#include "../vmisc/vabstractapplication.h"
|
#include "../vmisc/vabstractapplication.h"
|
||||||
#include "../vmisc/vcommonsettings.h"
|
#include "../vmisc/vcommonsettings.h"
|
||||||
#include "ui_dialogpointofintersectioncircles.h"
|
#include "ui_dialogpointofintersectioncircles.h"
|
||||||
|
#include "../vwidgets/vabstractmainwindow.h"
|
||||||
|
#include "../vgeometry/vpointf.h"
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
DialogPointOfIntersectionCircles::DialogPointOfIntersectionCircles(const VContainer *data, quint32 toolId,
|
DialogPointOfIntersectionCircles::DialogPointOfIntersectionCircles(const VContainer *data, quint32 toolId,
|
||||||
|
@ -242,6 +244,67 @@ void DialogPointOfIntersectionCircles::SetCrossCirclesPoint(const CrossCirclesPo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void DialogPointOfIntersectionCircles::ShowDialog(bool click)
|
||||||
|
{
|
||||||
|
if (m_stage == 0 || m_stage == 2)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto FinishCreating = [this]()
|
||||||
|
{
|
||||||
|
vis->SetMode(Mode::Show);
|
||||||
|
vis->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)
|
||||||
|
|
||||||
|
QSharedPointer<VPointF> center = data->GeometricObject<VPointF>(m_stage == 1 ? GetFirstCircleCenterId()
|
||||||
|
: GetSecondCircleCenterId());
|
||||||
|
|
||||||
|
QLineF line(static_cast<QPointF>(*center), scene->getScenePos());
|
||||||
|
|
||||||
|
if (m_stage == 1)
|
||||||
|
{
|
||||||
|
SetFirstCircleRadius(QString::number(FromPixel(line.length(), *data->GetPatternUnit())));
|
||||||
|
emit ToolTip(tr("Select second circle center"));
|
||||||
|
++m_stage;
|
||||||
|
m_firstRelease = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetSecondCircleRadius(QString::number(FromPixel(line.length(), *data->GetPatternUnit())));
|
||||||
|
++m_stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_stage > 2)
|
||||||
|
{
|
||||||
|
FinishCreating();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FinishCreating();
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void DialogPointOfIntersectionCircles::ChosenObject(quint32 id, const SceneObject &type)
|
void DialogPointOfIntersectionCircles::ChosenObject(quint32 id, const SceneObject &type)
|
||||||
{
|
{
|
||||||
|
@ -255,26 +318,29 @@ void DialogPointOfIntersectionCircles::ChosenObject(quint32 id, const SceneObjec
|
||||||
auto *point = qobject_cast<VisToolPointOfIntersectionCircles *>(vis);
|
auto *point = qobject_cast<VisToolPointOfIntersectionCircles *>(vis);
|
||||||
SCASSERT(point != nullptr)
|
SCASSERT(point != nullptr)
|
||||||
|
|
||||||
switch (m_number)
|
switch (m_stage)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
if (SetObject(id, ui->comboBoxCircle1Center, tr("Select second circle center")))
|
if (SetObject(id, ui->comboBoxCircle1Center, QString()))
|
||||||
{
|
{
|
||||||
m_number++;
|
++m_stage;
|
||||||
point->VisualMode(id);
|
point->VisualMode(id);
|
||||||
|
|
||||||
|
auto *window = qobject_cast<VAbstractMainWindow *>(
|
||||||
|
VAbstractValApplication::VApp()->getMainWindow());
|
||||||
|
SCASSERT(window != nullptr)
|
||||||
|
connect(vis, &Visualization::ToolTip, window, &VAbstractMainWindow::ShowToolTip);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 2:
|
||||||
if (getCurrentObjectId(ui->comboBoxCircle1Center) != id)
|
if (getCurrentObjectId(ui->comboBoxCircle1Center) != id)
|
||||||
{
|
{
|
||||||
if (SetObject(id, ui->comboBoxCircle2Center, QString()))
|
if (SetObject(id, ui->comboBoxCircle2Center, QString()))
|
||||||
{
|
{
|
||||||
m_number = 0;
|
|
||||||
point->setObject2Id(id);
|
point->setObject2Id(id);
|
||||||
point->RefreshGeometry();
|
point->RefreshGeometry();
|
||||||
|
++m_stage;
|
||||||
prepare = true;
|
prepare = true;
|
||||||
this->setModal(true);
|
|
||||||
this->show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -73,6 +73,8 @@ public:
|
||||||
void SetNotes(const QString ¬es);
|
void SetNotes(const QString ¬es);
|
||||||
auto GetNotes() const -> QString;
|
auto GetNotes() const -> QString;
|
||||||
|
|
||||||
|
void ShowDialog(bool click) override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void ChosenObject(quint32 id, const SceneObject &type) override;
|
void ChosenObject(quint32 id, const SceneObject &type) override;
|
||||||
void PointChanged();
|
void PointChanged();
|
||||||
|
@ -116,8 +118,10 @@ private:
|
||||||
bool m_flagName{true};
|
bool m_flagName{true};
|
||||||
bool m_flagError{true};
|
bool m_flagError{true};
|
||||||
|
|
||||||
|
bool m_firstRelease{false};
|
||||||
|
|
||||||
/** @brief number number of handled objects */
|
/** @brief number number of handled objects */
|
||||||
qint32 m_number{0};
|
qint32 m_stage{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "../vwidgets/vmaingraphicsscene.h"
|
#include "../vwidgets/vmaingraphicsscene.h"
|
||||||
#include "../visualization.h"
|
#include "../visualization.h"
|
||||||
#include "visline.h"
|
#include "visline.h"
|
||||||
|
#include "../vmisc/vmodifierkey.h"
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VisToolPointOfIntersectionCircles::VisToolPointOfIntersectionCircles(const VContainer *data, QGraphicsItem *parent)
|
VisToolPointOfIntersectionCircles::VisToolPointOfIntersectionCircles(const VContainer *data, QGraphicsItem *parent)
|
||||||
|
@ -48,9 +49,15 @@ VisToolPointOfIntersectionCircles::VisToolPointOfIntersectionCircles(const VCont
|
||||||
{
|
{
|
||||||
this->setPen(QPen(Qt::NoPen)); // don't use parent this time
|
this->setPen(QPen(Qt::NoPen)); // don't use parent this time
|
||||||
|
|
||||||
m_c1Path = InitItem<QGraphicsEllipseItem>(Qt::darkGreen, this);
|
m_c1Path = InitItem<VScaledEllipse>(Qt::darkGreen, this);
|
||||||
m_c2Path = InitItem<QGraphicsEllipseItem>(Qt::darkRed, this);
|
m_c1Path->SetPointMode(false);
|
||||||
|
|
||||||
|
m_c2Path = InitItem<VScaledEllipse>(Qt::darkRed, this);
|
||||||
|
m_c2Path->SetPointMode(false);
|
||||||
|
|
||||||
m_point = InitPoint(mainColor, this);
|
m_point = InitPoint(mainColor, this);
|
||||||
|
m_point->setZValue(1);
|
||||||
|
|
||||||
m_c1Center = InitPoint(supportColor, this);
|
m_c1Center = InitPoint(supportColor, this);
|
||||||
m_c2Center = InitPoint(supportColor, this); //-V656
|
m_c2Center = InitPoint(supportColor, this); //-V656
|
||||||
}
|
}
|
||||||
|
@ -63,16 +70,18 @@ void VisToolPointOfIntersectionCircles::RefreshGeometry()
|
||||||
const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(object1Id);
|
const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(object1Id);
|
||||||
DrawPoint(m_c1Center, static_cast<QPointF>(*first), supportColor);
|
DrawPoint(m_c1Center, static_cast<QPointF>(*first), supportColor);
|
||||||
|
|
||||||
|
if (m_c1Radius > 0)
|
||||||
|
{
|
||||||
|
m_c1Path->setRect(PointRect(m_c1Radius));
|
||||||
|
DrawPoint(m_c1Path, static_cast<QPointF>(*first), Qt::darkGreen, Qt::DashLine);
|
||||||
|
|
||||||
if (m_object2Id > NULL_ID)
|
if (m_object2Id > NULL_ID)
|
||||||
{
|
{
|
||||||
const QSharedPointer<VPointF> second = Visualization::data->GeometricObject<VPointF>(m_object2Id);
|
const QSharedPointer<VPointF> second = Visualization::data->GeometricObject<VPointF>(m_object2Id);
|
||||||
DrawPoint(m_c2Center, static_cast<QPointF>(*second), supportColor);
|
DrawPoint(m_c2Center, static_cast<QPointF>(*second), supportColor);
|
||||||
|
|
||||||
if (m_c1Radius > 0 && m_c2Radius > 0)
|
if (m_c2Radius > 0)
|
||||||
{
|
{
|
||||||
m_c1Path->setRect(PointRect(m_c1Radius));
|
|
||||||
DrawPoint(m_c1Path, static_cast<QPointF>(*first), Qt::darkGreen, Qt::DashLine);
|
|
||||||
|
|
||||||
m_c2Path->setRect(PointRect(m_c2Radius));
|
m_c2Path->setRect(PointRect(m_c2Radius));
|
||||||
DrawPoint(m_c2Path, static_cast<QPointF>(*second), Qt::darkRed, Qt::DashLine);
|
DrawPoint(m_c2Path, static_cast<QPointF>(*second), Qt::darkRed, Qt::DashLine);
|
||||||
|
|
||||||
|
@ -82,6 +91,41 @@ void VisToolPointOfIntersectionCircles::RefreshGeometry()
|
||||||
m_c1Radius, m_c2Radius, m_crossPoint, &fPoint);
|
m_c1Radius, m_c2Radius, m_crossPoint, &fPoint);
|
||||||
DrawPoint(m_point, fPoint, mainColor);
|
DrawPoint(m_point, fPoint, mainColor);
|
||||||
}
|
}
|
||||||
|
else if (mode == Mode::Creation)
|
||||||
|
{
|
||||||
|
QLineF radiusLine (static_cast<QPointF>(*second), Visualization::scenePos);
|
||||||
|
const qreal length = radiusLine.length();
|
||||||
|
|
||||||
|
m_c2Path->setRect(PointRect(length));
|
||||||
|
DrawPoint(m_c2Path, static_cast<QPointF>(*second), Qt::darkRed, Qt::DashLine);
|
||||||
|
|
||||||
|
QPointF fPoint;
|
||||||
|
VToolPointOfIntersectionCircles::FindPoint(static_cast<QPointF>(*first),
|
||||||
|
static_cast<QPointF>(*second),
|
||||||
|
m_c1Radius, length, m_crossPoint, &fPoint);
|
||||||
|
DrawPoint(m_point, fPoint, mainColor);
|
||||||
|
|
||||||
|
const QString prefix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
|
||||||
|
Visualization::toolTip = tr("Radius = %1%2; "
|
||||||
|
"<b>Mouse click</b> - finish selecting the second radius, "
|
||||||
|
"<b>%3</b> - skip")
|
||||||
|
.arg(NumberToUser(length), prefix, VModifierKey::EnterKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (mode == Mode::Creation)
|
||||||
|
{
|
||||||
|
QLineF radiusLine (static_cast<QPointF>(*first), Visualization::scenePos);
|
||||||
|
const qreal length = radiusLine.length();
|
||||||
|
|
||||||
|
m_c1Path->setRect(PointRect(length));
|
||||||
|
DrawPoint(m_c1Path, static_cast<QPointF>(*first), Qt::darkGreen, Qt::DashLine);
|
||||||
|
|
||||||
|
const QString prefix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
|
||||||
|
Visualization::toolTip = tr("Radius = %1%2; "
|
||||||
|
"<b>Mouse click</b> - finish selecting the first radius, "
|
||||||
|
"<b>%3</b> - skip")
|
||||||
|
.arg(NumberToUser(length), prefix, VModifierKey::EnterKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,8 +67,8 @@ private:
|
||||||
VScaledEllipse *m_point{nullptr};
|
VScaledEllipse *m_point{nullptr};
|
||||||
VScaledEllipse *m_c1Center{nullptr};
|
VScaledEllipse *m_c1Center{nullptr};
|
||||||
VScaledEllipse *m_c2Center{nullptr};
|
VScaledEllipse *m_c2Center{nullptr};
|
||||||
QGraphicsEllipseItem *m_c1Path{nullptr};
|
VScaledEllipse *m_c1Path{nullptr};
|
||||||
QGraphicsEllipseItem *m_c2Path{nullptr};
|
VScaledEllipse *m_c2Path{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VISTOOLPOINTOFINTERSECTIONCIRCLES_H
|
#endif // VISTOOLPOINTOFINTERSECTIONCIRCLES_H
|
||||||
|
|
|
@ -84,7 +84,22 @@ void VScaledEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
|
||||||
visPen.setWidthF(width);
|
visPen.setWidthF(width);
|
||||||
|
|
||||||
setPen(visPen);
|
setPen(visPen);
|
||||||
|
if (m_pointMode)
|
||||||
|
{
|
||||||
ScaleCircleSize(this, scale);
|
ScaleCircleSize(this, scale);
|
||||||
|
}
|
||||||
|
|
||||||
PaintWithFixItemHighlightSelected<QGraphicsEllipseItem>(this, painter, option, widget);
|
PaintWithFixItemHighlightSelected<QGraphicsEllipseItem>(this, painter, option, widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool VScaledEllipse::PointMode() const
|
||||||
|
{
|
||||||
|
return m_pointMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VScaledEllipse::SetPointMode(bool newHoldSize)
|
||||||
|
{
|
||||||
|
m_pointMode = newHoldSize;
|
||||||
|
}
|
||||||
|
|
|
@ -67,8 +67,13 @@ public:
|
||||||
|
|
||||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget = nullptr) override;
|
QWidget *widget = nullptr) override;
|
||||||
|
bool PointMode() const;
|
||||||
|
void SetPointMode(bool newPointMode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY_MOVE(VScaledEllipse) // NOLINT
|
Q_DISABLE_COPY_MOVE(VScaledEllipse) // NOLINT
|
||||||
|
|
||||||
|
bool m_pointMode{true};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SCALESCENEITEMS_H
|
#endif // SCALESCENEITEMS_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user