Debian Codegraph @

src/Gui/TaskView/TaskImage.h

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