Gui: fix clang-tidy warnings in TaskImage
This commit is contained in:
@@ -69,6 +69,7 @@ TaskImage::TaskImage(Image::ImagePlane* obj, QWidget* parent)
|
||||
|
||||
initialiseTransparency();
|
||||
|
||||
// NOLINTNEXTLINE
|
||||
aspectRatio = obj->XSize.getValue() / obj->YSize.getValue();
|
||||
|
||||
connectSignals();
|
||||
@@ -121,6 +122,7 @@ void TaskImage::connectSignals()
|
||||
|
||||
void TaskImage::initialiseTransparency()
|
||||
{
|
||||
// NOLINTBEGIN
|
||||
auto vp = Application::Instance->getViewProvider(feature.get());
|
||||
App::Property* prop = vp->getPropertyByName("Transparency");
|
||||
if (prop && prop->getTypeId().isDerivedFrom(App::PropertyInteger::getClassTypeId())) {
|
||||
@@ -128,17 +130,18 @@ void TaskImage::initialiseTransparency()
|
||||
ui->spinBoxTransparency->setValue(Transparency->getValue());
|
||||
ui->sliderTransparency->setValue(Transparency->getValue());
|
||||
}
|
||||
// NOLINTEND
|
||||
}
|
||||
|
||||
void TaskImage::changeTransparency(int val)
|
||||
{
|
||||
if (feature.expired())
|
||||
if (feature.expired()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto vp = Application::Instance->getViewProvider(feature.get());
|
||||
App::Property* prop = vp->getPropertyByName("Transparency");
|
||||
if (prop && prop->getTypeId().isDerivedFrom(App::PropertyInteger::getClassTypeId())) {
|
||||
auto Transparency = static_cast<App::PropertyInteger*>(prop);
|
||||
if (auto Transparency = dynamic_cast<App::PropertyInteger*>(prop)) {
|
||||
Transparency->setValue(val);
|
||||
|
||||
QSignalBlocker block(ui->spinBoxTransparency);
|
||||
@@ -176,7 +179,7 @@ View3DInventorViewer* TaskImage::getViewer() const
|
||||
{
|
||||
if (!feature.expired()) {
|
||||
auto vp = Application::Instance->getViewProvider(feature.get());
|
||||
auto doc = static_cast<ViewProviderDocumentObject*>(vp)->getDocument();
|
||||
auto doc = static_cast<ViewProviderDocumentObject*>(vp)->getDocument(); // NOLINT
|
||||
auto view = dynamic_cast<View3DInventor*>(doc->getViewOfViewProvider(vp));
|
||||
if (view) {
|
||||
return view->getViewer();
|
||||
@@ -277,47 +280,45 @@ void TaskImage::onPreview()
|
||||
updatePlacement();
|
||||
}
|
||||
|
||||
void TaskImage::restore(const Base::Placement& plm)
|
||||
// NOLINTNEXTLINE
|
||||
void TaskImage::restoreAngles(const Base::Rotation& rot)
|
||||
{
|
||||
if (feature.expired())
|
||||
return;
|
||||
|
||||
QSignalBlocker blockW(ui->spinBoxWidth);
|
||||
QSignalBlocker blockH(ui->spinBoxHeight);
|
||||
ui->spinBoxWidth->setValue(feature->XSize.getValue());
|
||||
ui->spinBoxHeight->setValue(feature->YSize.getValue());
|
||||
|
||||
Base::Rotation rot = plm.getRotation();
|
||||
Base::Vector3d pos = plm.getPosition();
|
||||
|
||||
double yaw, pitch, roll;
|
||||
double yaw{};
|
||||
double pitch{};
|
||||
double roll{};
|
||||
rot.getYawPitchRoll(yaw, pitch, roll);
|
||||
|
||||
double tol = 1.0e-5;
|
||||
bool reverse = false;
|
||||
|
||||
const double tol = 1.0e-5;
|
||||
const double angle1 = 90.0;
|
||||
const double angle2 = 180.0;
|
||||
|
||||
auto isTopOrBottom = [=](bool& reverse) {
|
||||
if (fabs(pitch) < tol && (fabs(roll) < tol || fabs(roll - 180.) < tol)) {
|
||||
if (fabs(roll - 180.) < tol)
|
||||
if (fabs(pitch) < tol && (fabs(roll) < tol || fabs(roll - angle2) < tol)) {
|
||||
if (fabs(roll - angle2) < tol) {
|
||||
reverse = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
auto isFrontOrRear = [=](bool& reverse) {
|
||||
if (fabs(roll - 90.) < tol && (fabs(yaw) < tol || fabs(yaw - 180.) < tol)) {
|
||||
if (fabs(yaw - 180.) < tol)
|
||||
if (fabs(roll - angle1) < tol && (fabs(yaw) < tol || fabs(yaw - angle2) < tol)) {
|
||||
if (fabs(yaw - angle2) < tol) {
|
||||
reverse = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
auto isRightOrLeft = [=](bool& reverse) {
|
||||
if (fabs(roll - 90.) < tol && (fabs(yaw - 90.) < tol || fabs(yaw + 90.) < tol)) {
|
||||
if (fabs(yaw + 90.) < tol)
|
||||
if (fabs(roll - angle1) < tol && (fabs(yaw - angle1) < tol || fabs(yaw + angle1) < tol)) {
|
||||
if (fabs(yaw + angle1) < tol) {
|
||||
reverse = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -338,8 +339,27 @@ void TaskImage::restore(const Base::Placement& plm)
|
||||
ui->spinBoxRotation->setValue(-pitch);
|
||||
}
|
||||
ui->Reverse_checkBox->setChecked(reverse);
|
||||
}
|
||||
|
||||
Base::Vector3d R0(0, 0, 0), RX(1, 0, 0), RY(0, 1, 0);
|
||||
void TaskImage::restore(const Base::Placement& plm)
|
||||
{
|
||||
if (feature.expired()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QSignalBlocker blockW(ui->spinBoxWidth);
|
||||
QSignalBlocker blockH(ui->spinBoxHeight);
|
||||
ui->spinBoxWidth->setValue(feature->XSize.getValue());
|
||||
ui->spinBoxHeight->setValue(feature->YSize.getValue());
|
||||
|
||||
Base::Rotation rot = plm.getRotation(); // NOLINT
|
||||
Base::Vector3d pos = plm.getPosition();
|
||||
|
||||
restoreAngles(rot);
|
||||
|
||||
Base::Vector3d R0(0, 0, 0);
|
||||
Base::Vector3d RX(1, 0, 0);
|
||||
Base::Vector3d RY(0, 1, 0);
|
||||
|
||||
RX = rot.multVec(RX);
|
||||
RY = rot.multVec(RY);
|
||||
@@ -356,6 +376,7 @@ void TaskImage::updatePlacement()
|
||||
double angle = ui->spinBoxRotation->value().getValue();
|
||||
bool reverse = ui->Reverse_checkBox->isChecked();
|
||||
|
||||
// NOLINTBEGIN
|
||||
Base::Placement Pos;
|
||||
Base::Rotation rot;
|
||||
double dir = reverse ? 180. : 0.;
|
||||
@@ -370,6 +391,7 @@ void TaskImage::updatePlacement()
|
||||
else if (ui->YZ_radioButton->isChecked()) {
|
||||
rot.setYawPitchRoll(90. - dir, -angle, 90.);
|
||||
}
|
||||
// NOLINTEND
|
||||
|
||||
Base::Vector3d offset = Base::Vector3d(ui->spinBoxX->value().getValue(), ui->spinBoxY->value().getValue(), ui->spinBoxZ->value().getValue());
|
||||
offset = rot.multVec(offset);
|
||||
@@ -377,8 +399,9 @@ void TaskImage::updatePlacement()
|
||||
|
||||
if (!feature.expired()) {
|
||||
feature->Placement.setValue(Pos);
|
||||
if(scale)
|
||||
if (scale) {
|
||||
scale->setPlacement(feature->globalPlacement());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,14 +426,16 @@ void TaskImage::updateIcon()
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
InteractiveScale::InteractiveScale(View3DInventorViewer* view, ViewProvider* vp, Base::Placement plc)
|
||||
InteractiveScale::InteractiveScale(View3DInventorViewer* view,
|
||||
ViewProvider* vp,
|
||||
const Base::Placement& plc) // NOLINT
|
||||
: active(false)
|
||||
, placement(plc)
|
||||
, viewer(view)
|
||||
, viewProv(vp)
|
||||
, midPoint(SbVec3f(0,0,0))
|
||||
{
|
||||
measureLabel = new EditableDatumLabel(viewer, placement, SbColor(1.0f, 0.149f, 0.0f));
|
||||
measureLabel = new EditableDatumLabel(viewer, placement, SbColor(1.0F, 0.149F, 0.0F)); //NOLINT
|
||||
}
|
||||
|
||||
InteractiveScale::~InteractiveScale()
|
||||
@@ -446,16 +471,18 @@ void InteractiveScale::deactivate()
|
||||
|
||||
double InteractiveScale::getScaleFactor() const
|
||||
{
|
||||
if ((points[0] - points[1]).length() == 0.)
|
||||
if ((points[0] - points[1]).length() == 0.) {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
return measureLabel->getValue() / (points[0] - points[1]).length();
|
||||
}
|
||||
|
||||
double InteractiveScale::getDistance(const SbVec3f& pt) const
|
||||
{
|
||||
if (points.empty())
|
||||
if (points.empty()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return (points[0] - pt).length();
|
||||
}
|
||||
@@ -467,8 +494,9 @@ void InteractiveScale::setDistance(const SbVec3f& pos3d)
|
||||
quantity.setUnit(Base::Unit::Length);
|
||||
|
||||
//Update the displayed distance
|
||||
double factor;
|
||||
QString unitStr, valueStr;
|
||||
double factor{};
|
||||
QString unitStr;
|
||||
QString valueStr;
|
||||
valueStr = quantity.getUserString(factor, unitStr);
|
||||
measureLabel->label->string = SbString(valueStr.toUtf8().constData());
|
||||
measureLabel->label->setPoints(getCoordsOnImagePlane(points[0]), getCoordsOnImagePlane(pos3d));
|
||||
@@ -476,10 +504,10 @@ void InteractiveScale::setDistance(const SbVec3f& pos3d)
|
||||
|
||||
void InteractiveScale::findPointOnImagePlane(SoEventCallback * ecb)
|
||||
{
|
||||
const SoMouseButtonEvent * mbe = static_cast<const SoMouseButtonEvent *>(ecb->getEvent());
|
||||
Gui::View3DInventorViewer* view = static_cast<Gui::View3DInventorViewer*>(ecb->getUserData());
|
||||
const SoEvent * mbe = ecb->getEvent();
|
||||
auto view = static_cast<Gui::View3DInventorViewer*>(ecb->getUserData());
|
||||
std::unique_ptr<SoPickedPoint> pp(view->getPointOnRay(mbe->getPosition(), viewProv));
|
||||
if (pp.get()) {
|
||||
if (pp) {
|
||||
auto pos3d = pp->getPoint();
|
||||
|
||||
collectPoint(pos3d);
|
||||
@@ -513,15 +541,15 @@ void InteractiveScale::collectPoint(const SbVec3f& pos3d)
|
||||
|
||||
void InteractiveScale::getMousePosition(void * ud, SoEventCallback * ecb)
|
||||
{
|
||||
InteractiveScale* scale = static_cast<InteractiveScale*>(ud);
|
||||
const SoLocation2Event * l2e = static_cast<const SoLocation2Event *>(ecb->getEvent());
|
||||
Gui::View3DInventorViewer* view = static_cast<Gui::View3DInventorViewer*>(ecb->getUserData());
|
||||
auto scale = static_cast<InteractiveScale*>(ud);
|
||||
const SoEvent* l2e = ecb->getEvent();
|
||||
auto view = static_cast<Gui::View3DInventorViewer*>(ecb->getUserData());
|
||||
|
||||
if (scale->points.size() == 1) {
|
||||
ecb->setHandled();
|
||||
|
||||
std::unique_ptr<SoPickedPoint> pp(view->getPointOnRay(l2e->getPosition(), scale->viewProv));
|
||||
if (pp.get()) {
|
||||
if (pp) {
|
||||
SbVec3f pos3d = pp->getPoint();
|
||||
scale->setDistance(pos3d);
|
||||
}
|
||||
@@ -530,12 +558,12 @@ void InteractiveScale::getMousePosition(void * ud, SoEventCallback * ecb)
|
||||
|
||||
void InteractiveScale::soEventFilter(void* ud, SoEventCallback* ecb)
|
||||
{
|
||||
InteractiveScale* scale = static_cast<InteractiveScale*>(ud);
|
||||
auto scale = static_cast<InteractiveScale*>(ud);
|
||||
|
||||
const SoEvent* soEvent = ecb->getEvent();
|
||||
if (soEvent->isOfType(SoKeyboardEvent::getClassTypeId())) {
|
||||
/* If user presses escape, then we cancel the tool.*/
|
||||
const auto kbe = static_cast<const SoKeyboardEvent*>(soEvent);
|
||||
const auto kbe = static_cast<const SoKeyboardEvent*>(soEvent); // NOLINT
|
||||
|
||||
if (kbe->getKey() == SoKeyboardEvent::ESCAPE && kbe->getState() == SoButtonEvent::UP) {
|
||||
ecb->setHandled();
|
||||
@@ -543,7 +571,7 @@ void InteractiveScale::soEventFilter(void* ud, SoEventCallback* ecb)
|
||||
}
|
||||
}
|
||||
else if (soEvent->isOfType(SoMouseButtonEvent::getClassTypeId())) {
|
||||
const auto mbe = static_cast<const SoMouseButtonEvent*>(soEvent);
|
||||
const auto mbe = static_cast<const SoMouseButtonEvent*>(soEvent); // NOLINT
|
||||
|
||||
if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN)
|
||||
{
|
||||
@@ -561,7 +589,7 @@ void InteractiveScale::soEventFilter(void* ud, SoEventCallback* ecb)
|
||||
bool InteractiveScale::eventFilter(QObject* object, QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyRelease) {
|
||||
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
|
||||
auto keyEvent = static_cast<QKeyEvent*>(event); // NOLINT
|
||||
|
||||
/* If user press enter in the spinbox, then we validate the tool.*/
|
||||
if ((keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return)
|
||||
@@ -577,7 +605,7 @@ bool InteractiveScale::eventFilter(QObject* object, QEvent* event)
|
||||
return false;
|
||||
}
|
||||
|
||||
void InteractiveScale::setPlacement(Base::Placement plc)
|
||||
void InteractiveScale::setPlacement(const Base::Placement& plc)
|
||||
{
|
||||
placement = plc;
|
||||
measureLabel->setPlacement(plc);
|
||||
@@ -586,7 +614,8 @@ void InteractiveScale::setPlacement(Base::Placement plc)
|
||||
SbVec3f InteractiveScale::getCoordsOnImagePlane(const SbVec3f& point)
|
||||
{
|
||||
// Plane form
|
||||
Base::Vector3d RX(1, 0, 0), RY(0, 1, 0);
|
||||
Base::Vector3d RX(1, 0, 0);
|
||||
Base::Vector3d RY(0, 1, 0);
|
||||
|
||||
// move to position of Sketch
|
||||
Base::Rotation tmp(placement.getRotation());
|
||||
@@ -596,10 +625,10 @@ SbVec3f InteractiveScale::getCoordsOnImagePlane(const SbVec3f& point)
|
||||
|
||||
// we use pos as the Base because in setPlacement we set transform->translation using
|
||||
// placement.getPosition() to fix the Zoffset. But this applies the X & Y translation too.
|
||||
Base::Vector3d S(point[0], point[1], point[2]);
|
||||
S.TransformToCoordinateSystem(pos, RX, RY);
|
||||
Base::Vector3d pnt(point[0], point[1], point[2]);
|
||||
pnt.TransformToCoordinateSystem(pos, RX, RY);
|
||||
|
||||
return SbVec3f(S.x, S.y, 0.);
|
||||
return {float(pnt.x), float(pnt.y), 0.0F};
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -607,7 +636,7 @@ SbVec3f InteractiveScale::getCoordsOnImagePlane(const SbVec3f& point)
|
||||
TaskImageDialog::TaskImageDialog(Image::ImagePlane* obj)
|
||||
{
|
||||
widget = new TaskImage(obj);
|
||||
Gui::TaskView::TaskBox* taskbox = new Gui::TaskView::TaskBox(
|
||||
auto taskbox = new Gui::TaskView::TaskBox(
|
||||
Gui::BitmapFactory().pixmap("image-plane"), widget->windowTitle(), true, nullptr);
|
||||
taskbox->groupLayout()->addWidget(widget);
|
||||
Content.push_back(taskbox);
|
||||
|
||||
@@ -43,9 +43,10 @@ class ViewProvider;
|
||||
class InteractiveScale : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(InteractiveScale)
|
||||
|
||||
public:
|
||||
explicit InteractiveScale(View3DInventorViewer* view, ViewProvider* vp, Base::Placement plc);
|
||||
explicit InteractiveScale(View3DInventorViewer* view, ViewProvider* vp, const Base::Placement& plc);
|
||||
~InteractiveScale() override;
|
||||
|
||||
bool eventFilter(QObject* object, QEvent* event) override;
|
||||
@@ -56,7 +57,7 @@ public:
|
||||
}
|
||||
double getScaleFactor() const;
|
||||
double getDistance(const SbVec3f&) const;
|
||||
void setPlacement(Base::Placement plc);
|
||||
void setPlacement(const Base::Placement& plc);
|
||||
|
||||
private:
|
||||
static void soEventFilter(void * ud, SoEventCallback * ecb);
|
||||
@@ -87,6 +88,7 @@ class Ui_TaskImage;
|
||||
class TaskImage : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(TaskImage)
|
||||
|
||||
public:
|
||||
explicit TaskImage(Image::ImagePlane* obj, QWidget* parent = nullptr);
|
||||
@@ -109,6 +111,7 @@ private:
|
||||
void enableApplyBtn();
|
||||
|
||||
void restore(const Base::Placement&);
|
||||
void restoreAngles(const Base::Rotation&);
|
||||
void onPreview();
|
||||
void updateIcon();
|
||||
void updatePlacement();
|
||||
|
||||
Reference in New Issue
Block a user