File size: 4,653 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | // SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#ifndef GUI_TASKIMAGE_H
#define GUI_TASKIMAGE_H
#include <Inventor/SbVec3f.h>
#include <QPointer>
#include <Gui/TaskView/TaskDialog.h>
#include <App/DocumentObserver.h>
#include <App/ImagePlane.h>
#include <memory>
#include <vector>
class SbVec3f;
class SoEventCallback;
class EditableDatumLabel;
namespace Gui
{
class View3DInventorViewer;
class ViewProvider;
class InteractiveScale: public QObject
{
Q_OBJECT
Q_DISABLE_COPY(InteractiveScale)
public:
explicit InteractiveScale(View3DInventorViewer* view, ViewProvider* vp, const Base::Placement& plc);
~InteractiveScale() override;
bool eventFilter(QObject* object, QEvent* event) override;
void activate();
void deactivate();
bool isActive() const
{
return active;
}
double getScaleFactor() const;
double getDistance(const SbVec3f&) const;
void setPlacement(const Base::Placement& plc);
private:
static void soEventFilter(void* ud, SoEventCallback* ecb);
static void getMousePosition(void* ud, SoEventCallback* ecb);
void findPointOnImagePlane(SoEventCallback* ecb);
void collectPoint(const SbVec3f&);
void setDistance(const SbVec3f&);
/// give the coordinates of a line on the image plane in imagePlane (2D) coordinates
SbVec3f getCoordsOnImagePlane(const SbVec3f& point);
Q_SIGNALS:
void scaleRequired();
void scaleCanceled();
void enableApplyBtn();
private:
bool active;
Base::Placement placement;
EditableDatumLabel* measureLabel;
QPointer<Gui::View3DInventorViewer> viewer;
ViewProvider* viewProv;
std::vector<SbVec3f> points;
SbVec3f midPoint;
};
class Ui_TaskImage;
class TaskImage: public QWidget
{
Q_OBJECT
Q_DISABLE_COPY(TaskImage)
public:
explicit TaskImage(Image::ImagePlane* obj, QWidget* parent = nullptr);
~TaskImage() override;
void open();
void accept();
void reject();
private:
void initialiseTransparency();
void connectSignals();
void onInteractiveScale();
View3DInventorViewer* getViewer() const;
void scaleImage(double);
void startScale();
void acceptScale();
void rejectScale();
void enableApplyBtn();
void restore(const Base::Placement&);
void restoreAngles(const Base::Rotation&);
void onPreview();
void updateIcon();
void updatePlacement();
private:
void changeTransparency(int val);
void changeWidth();
void changeHeight();
private:
std::unique_ptr<Ui_TaskImage> ui;
QPointer<InteractiveScale> scale;
App::WeakPtrT<Image::ImagePlane> feature;
double aspectRatio;
};
class TaskImageDialog: public Gui::TaskView::TaskDialog
{
Q_OBJECT
public:
explicit TaskImageDialog(Image::ImagePlane* obj);
public:
void open() override;
bool accept() override;
bool reject() override;
QDialogButtonBox::StandardButtons getStandardButtons() const override
{
return QDialogButtonBox::Ok | QDialogButtonBox::Cancel;
}
private:
TaskImage* widget;
};
} // namespace Gui
#endif // GUI_TASKIMAGE_H
|