Debian Codegraph @

src/Gui/Placement.h

raw
1 /***************************************************************************
2 * Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23 #ifndef GUI_PLACEMENT_H
24 #define GUI_PLACEMENT_H
25
26 #include <QDialog>
27 #include <Base/Placement.h>
28 #include <Gui/Selection/SelectionObject.h>
29 #include <Gui/TaskView/TaskDialog.h>
30 #include <Gui/TaskView/TaskView.h>
31
32
33 class QSignalMapper;
34
35 namespace App
36 {
37 class DocumentObject;
38 }
39 namespace Gui
40 {
41 class Document;
42
43 namespace Dialog
44 {
45
46 class Ui_Placement;
47 class TaskPlacement;
48
49 class GuiExport PlacementHandler: public QObject
50 {
51 Q_OBJECT
52
53 public:
54 PlacementHandler();
55 void openTransactionIfNeeded();
56 void setPropertyName(const std::string&);
57 void setIgnoreTransactions(bool value);
58 void setSelection(const std::vector<SelectionObject>&);
59 void reselectObjects();
60 const App::DocumentObject* getFirstOfSelection() const;
61 const std::string& getPropertyName() const;
62 void appendDocument(const std::string&);
63 void activatedDocument(const std::string&);
64 void revertTransformation();
65 void setRefPlacement(const Base::Placement& plm);
66 const Base::Placement& getRefPlacement() const;
67 void applyPlacement(const Base::Placement& p, bool incremental);
68 void applyPlacement(const QString& p, bool incremental);
69 Base::Vector3d computeCenterOfMass() const;
70 void setCenterOfMass(const Base::Vector3d& pnt);
71 Base::Vector3d getCenterOfMass() const;
72 std::tuple<Base::Vector3d, std::vector<Base::Vector3d>> getSelectedPoints() const;
73
74 private:
75 std::vector<const App::DocumentObject*> getObjects(const Gui::Document*) const;
76 std::vector<const App::DocumentObject*> getSelectedObjects(const Gui::Document*) const;
77 void revertTransformationOfViewProviders(Gui::Document*);
78 void tryRecompute(Gui::Document*);
79 void applyPlacement(
80 const Gui::Document*,
81 const App::DocumentObject*,
82 const Base::Placement& p,
83 bool incremental
84 );
85 void applyPlacement(const App::DocumentObject*, const QString& p, bool incremental);
86 QString getIncrementalPlacement(const App::DocumentObject*, const QString&) const;
87 QString getSimplePlacement(const App::DocumentObject*, const QString&) const;
88 void setupDocument();
89 void slotActiveDocument(const Gui::Document&);
90 void openCommandIfActive(Gui::Document*);
91 void commitCommandIfActive(Gui::Document*);
92 void abortCommandIfActive(Gui::Document*);
93
94 private Q_SLOTS:
95 void openTransaction();
96
97 private:
98 using Connection = boost::signals2::scoped_connection;
99 std::string propertyName; // the name of the placement property
100 std::set<std::string> documents;
101 /** If false apply the placement directly to the transform nodes,
102 * otherwise change the placement property.
103 */
104 bool changeProperty;
105 /** If true do not open or commit transactions. In this case it's expected
106 * that it's done by the calling instance.
107 */
108 bool ignoreTransaction;
109 Connection connectAct;
110 /**
111 * store these so we can reselect original object
112 * after user selects points and clicks Selected point(s)
113 */
114 std::vector<SelectionObject> selectionObjects;
115 Base::Placement ref;
116 Base::Vector3d cntOfMass;
117 };
118
119 class GuiExport Placement: public QDialog
120 {
121 Q_OBJECT
122
123 public:
124 explicit Placement(QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags());
125 ~Placement() override;
126 void open() override;
127 void accept() override;
128 void reject() override;
129
130 void setPropertyName(const std::string&);
131 void setSelection(const std::vector<SelectionObject>&);
132 void bindObject();
133 void setPlacementAndBindObject(const App::DocumentObject* obj, const std::string& propertyName);
134 void setIgnoreTransactions(bool value);
135 Base::Vector3d getDirection() const;
136 void setPlacement(const Base::Placement&);
137 Base::Placement getPlacement() const;
138 void showDefaultButtons(bool);
139
140 protected:
141 void changeEvent(QEvent* e) override;
142 void keyPressEvent(QKeyEvent*) override;
143
144 public Q_SLOTS:
145 void onApplyButtonClicked();
146
147 private Q_SLOTS:
148 void onApplyIncrementalPlacementToggled(bool);
149 void onPlacementChanged(int);
150 void onResetButtonClicked();
151 void onCenterOfMassToggled(bool);
152 void onSelectedVertexClicked();
153 void onApplyAxialClicked();
154
155 private:
156 void setupUi();
157 void setupConnections();
158 void setupUnits();
159 void setupSignalMapper();
160 void setupRotationMethod();
161 void bindProperty(const App::DocumentObject* obj, const std::string& propertyName);
162
163 bool onApply();
164 void setPlacementData(const Base::Placement&);
165 Base::Placement getPlacementData() const;
166 Base::Rotation getRotationData() const;
167 Base::Vector3d getPositionData() const;
168 Base::Vector3d getAnglesData() const;
169 Base::Vector3d getCenterData() const;
170 QString getPlacementString() const;
171 QString getPlacementFromEulerAngles() const;
172 QString getPlacementFromAxisWithAngle() const;
173 QWidget* getInvalidInput() const;
174 void showErrorMessage();
175
176 Q_SIGNALS:
177 void placementChanged(const QVariant&, bool, bool);
178
179 private:
180 Ui_Placement* ui;
181 QSignalMapper* signalMapper;
182 PlacementHandler handler;
183 };
184
185 class GuiExport DockablePlacement: public Placement
186 {
187 Q_OBJECT
188
189 public:
190 explicit DockablePlacement(QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags());
191 ~DockablePlacement() override;
192
193 void accept() override;
194 void reject() override;
195 };
196
197 class TaskPlacement: public Gui::TaskView::TaskDialog
198 {
199 Q_OBJECT
200
201 public:
202 TaskPlacement();
203 ~TaskPlacement() override;
204
205 public:
206 void setPropertyName(const QString&);
207 void setPlacement(const Base::Placement&);
208 void setSelection(const std::vector<SelectionObject>&);
209 void clearSelection();
210 void bindObject();
211 void setPlacementAndBindObject(const App::DocumentObject* obj, const std::string& propertyName);
212 bool accept() override;
213 bool reject() override;
214 void clicked(int id) override;
215
216 void open() override;
217 bool isAllowedAlterDocument() const override
218 {
219 return true;
220 }
221 bool isAllowedAlterView() const override
222 {
223 return true;
224 }
225 bool isAllowedAlterSelection() const override
226 {
227 return true;
228 }
229 QDialogButtonBox::StandardButtons getStandardButtons() const override;
230
231 public Q_SLOTS:
232 void slotPlacementChanged(const QVariant&, bool, bool);
233
234 Q_SIGNALS:
235 void placementChanged(const QVariant&, bool, bool);
236
237 private:
238 Placement* widget;
239 };
240
241 class TaskPlacementPy: public Py::PythonExtension<TaskPlacementPy>
242 {
243 public:
244 using BaseType = Py::PythonExtension<TaskPlacementPy>;
245 static void init_type();
246
247 TaskPlacementPy();
248 ~TaskPlacementPy() override;
249
250 Py::Object repr() override;
251 Py::Object getattr(const char* name) override;
252 int setattr(const char* name, const Py::Object&) override;
253
254 Py::Object setPropertyName(const Py::Tuple&);
255 Py::Object setPlacement(const Py::Tuple&);
256 Py::Object setSelection(const Py::Tuple&);
257 Py::Object bindObject(const Py::Tuple&);
258 Py::Object setPlacementAndBindObject(const Py::Tuple&);
259 Py::Object setIgnoreTransactions(const Py::Tuple&);
260
261 Py::Object showDefaultButtons(const Py::Tuple&);
262 Py::Object accept(const Py::Tuple&);
263 Py::Object reject(const Py::Tuple&);
264 Py::Object clicked(const Py::Tuple&);
265 Py::Object open(const Py::Tuple&);
266 Py::Object isAllowedAlterDocument(const Py::Tuple&);
267 Py::Object isAllowedAlterView(const Py::Tuple&);
268 Py::Object isAllowedAlterSelection(const Py::Tuple&);
269 Py::Object getStandardButtons(const Py::Tuple&);
270
271 private:
272 static PyObject* PyMake(struct _typeobject*, PyObject*, PyObject*);
273
274 private:
275 QPointer<Placement> widget;
276 };
277
278 } // namespace Dialog
279 } // namespace Gui
280
281 #endif // GUI_PLACEMENT_H