Improve visualization for tool Point of intersection circle and segment.

This commit is contained in:
Roman Telezhynskyi 2022-08-24 19:44:09 +03:00
parent 35eedc0a44
commit 8a94ed2645
3 changed files with 118 additions and 44 deletions

View File

@ -45,11 +45,12 @@
#include "../../visualization/visualization.h" #include "../../visualization/visualization.h"
#include "../../visualization/line/vistoolpointofcontact.h" #include "../../visualization/line/vistoolpointofcontact.h"
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../ifc/xml/vdomdocument.h"
#include "../support/dialogeditwrongformula.h" #include "../support/dialogeditwrongformula.h"
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "../vmisc/vcommonsettings.h" #include "../vmisc/vcommonsettings.h"
#include "ui_dialogpointofcontact.h" #include "ui_dialogpointofcontact.h"
#include "../vwidgets/vabstractmainwindow.h"
#include "../vgeometry/vpointf.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
@ -186,6 +187,50 @@ void DialogPointOfContact::DeployFormulaTextEdit()
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight); DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfContact::ShowDialog(bool click)
{
if (not prepare)
{
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)
const QSharedPointer<VPointF> center = data->GeometricObject<VPointF>(getCenter());
QLineF line(static_cast<QPointF>(*center), scene->getScenePos());
setRadius(QString::number(FromPixel(line.length(), *data->GetPatternUnit())));
FinishCreating();
}
FinishCreating();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
@ -194,56 +239,61 @@ void DialogPointOfContact::DeployFormulaTextEdit()
*/ */
void DialogPointOfContact::ChosenObject(quint32 id, const SceneObject &type) void DialogPointOfContact::ChosenObject(quint32 id, const SceneObject &type)
{ {
if (prepare == false)// After first choose we ignore all objects if (prepare)// After first choose we ignore all objects
{ {
if (type == SceneObject::Point) return;
{ }
VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis);
SCASSERT(line != nullptr)
switch (number) if (type == SceneObject::Point)
{ {
case 0: VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis);
if (SetObject(id, ui->comboBoxFirstPoint, tr("Select second point of line"))) SCASSERT(line != nullptr)
switch (number)
{
case 0:
if (SetObject(id, ui->comboBoxFirstPoint, tr("Select second point of line")))
{
number++;
line->VisualMode(id);
}
break;
case 1:
if (getCurrentObjectId(ui->comboBoxFirstPoint) != id)
{
if (SetObject(id, ui->comboBoxSecondPoint, tr("Select point of center of arc")))
{ {
number++; number++;
line->VisualMode(id); line->SetLineP2Id(id);
} line->RefreshGeometry();
break; }
case 1: }
if (getCurrentObjectId(ui->comboBoxFirstPoint) != id) break;
{ case 2:
if (SetObject(id, ui->comboBoxSecondPoint, tr("Select point of center of arc"))) {
{ QSet<quint32> set;
number++; set.insert(getCurrentObjectId(ui->comboBoxFirstPoint));
line->SetLineP2Id(id); set.insert(getCurrentObjectId(ui->comboBoxSecondPoint));
line->RefreshGeometry(); set.insert(id);
}
} if (set.size() == 3)
break; {
case 2: if (SetObject(id, ui->comboBoxCenter, QString()))
{ {
QSet<quint32> set; auto *window = qobject_cast<VAbstractMainWindow *>(
set.insert(getCurrentObjectId(ui->comboBoxFirstPoint)); VAbstractValApplication::VApp()->getMainWindow());
set.insert(getCurrentObjectId(ui->comboBoxSecondPoint)); SCASSERT(window != nullptr)
set.insert(id); connect(line, &Visualization::ToolTip, window, &VAbstractMainWindow::ShowToolTip);
if (set.size() == 3) line->SetRadiusId(id);
{ line->RefreshGeometry();
if (SetObject(id, ui->comboBoxCenter, QString())) prepare = true;
{
line->SetRadiusId(id);
line->RefreshGeometry();
prepare = true;
this->setModal(true);
this->show();
}
} }
} }
break;
default:
break;
} }
break;
default:
break;
} }
} }
} }

View File

@ -71,6 +71,8 @@ public:
void SetNotes(const QString &notes); void SetNotes(const QString &notes);
QString GetNotes() const; QString GetNotes() const;
void ShowDialog(bool click) override;
public slots: public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override; virtual void ChosenObject(quint32 id, const SceneObject &type) override;
/** /**
@ -110,6 +112,8 @@ private:
/** @brief number number of handled objects */ /** @brief number number of handled objects */
qint32 number{0}; qint32 number{0};
bool m_firstRelease{false};
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -41,6 +41,7 @@
#include "../visualization.h" #include "../visualization.h"
#include "visline.h" #include "visline.h"
#include "../vwidgets/global.h" #include "../vwidgets/global.h"
#include "../vmisc/vmodifierkey.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VisToolPointOfContact::VisToolPointOfContact(const VContainer *data, QGraphicsItem *parent) VisToolPointOfContact::VisToolPointOfContact(const VContainer *data, QGraphicsItem *parent)
@ -88,6 +89,25 @@ void VisToolPointOfContact::RefreshGeometry()
m_circle->setRect(PointRect(m_radius)); m_circle->setRect(PointRect(m_radius));
DrawPoint(m_circle, static_cast<QPointF>(*third), Color(VColor::SupportColor), Qt::DashLine); DrawPoint(m_circle, static_cast<QPointF>(*third), Color(VColor::SupportColor), Qt::DashLine);
} }
else if (GetMode() == Mode::Creation)
{
QLineF cursorLine (static_cast<QPointF>(*third), ScenePos());
qreal radius = cursorLine.length();
QPointF fPoint;
VToolPointOfContact::FindPoint(radius, static_cast<QPointF>(*third), static_cast<QPointF>(*first),
static_cast<QPointF>(*second), &fPoint);
DrawPoint(m_point, fPoint, Color(VColor::MainColor));
m_circle->setRect(PointRect(radius));
DrawPoint(m_circle, static_cast<QPointF>(*third), Color(VColor::SupportColor), Qt::DashLine);
const QString prefix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
SetToolTip(tr("Radius = %1%2; "
"<b>Mouse click</b> - finish selecting the radius, "
"<b>%3</b> - skip")
.arg(LengthToUser(radius), prefix, VModifierKey::EnterKey()));
}
} }
} }
} }