23
#include "PreCompiled.h"
25
#include <QDialogButtonBox>
27
#include <QSignalMapper>
29
#include <App/GeoFeature.h>
30
#include <App/PropertyGeo.h>
33
#include "Application.h"
36
#include "ui_Placement.h"
37
#include "ViewProvider.h"
38
#include "WaitCursor.h"
41
using namespace Gui::Dialog;
43
namespace Gui { namespace Dialog {
47
bool operator () (const std::pair<std::string, App::Property*>& elem) const
49
if (elem.first == "Placement") {
50
return elem.second->isDerivedFrom
51
(Base::Type::fromName("App::PropertyPlacement"));
62
TransformStrategy::TransformStrategy() = default;
64
TransformStrategy::~TransformStrategy() = default;
66
Base::Vector3d TransformStrategy::getRotationCenter() const
70
std::set<App::DocumentObject*> objects = transformObjects();
71
if (!objects.empty()) {
72
Base::BoundBox3d bbox;
74
for (const auto & object : objects) {
75
if (object->isDerivedFrom<App::GeoFeature>()) {
77
const App::PropertyGeometry* geo = static_cast<App::GeoFeature*>(object)->getPropertyOfGeometry();
80
bbox = geo->getBoundingBox();
82
bbox.Add(geo->getBoundingBox());
88
return Base::Vector3d((bbox.MinX+bbox.MaxX)/2,
89
(bbox.MinY+bbox.MaxY)/2,
90
(bbox.MinZ+bbox.MaxZ)/2);
93
return Base::Vector3d();
96
void TransformStrategy::commitTransform(const Base::Matrix4D& mat)
98
std::set<App::DocumentObject*> objects = transformObjects();
99
Gui::Document* doc = Gui::Application::Instance->activeDocument();
101
doc->openCommand(QT_TRANSLATE_NOOP("Command", "Transform"));
102
for (const auto & object : objects) {
103
acceptDataTransform(mat, object);
105
doc->commitCommand();
109
void TransformStrategy::acceptDataTransform(const Base::Matrix4D& mat, App::DocumentObject* obj)
111
Gui::Document* doc = Gui::Application::Instance->getDocument(obj->getDocument());
112
std::map<std::string,App::Property*> props;
113
obj->getPropertyMap(props);
115
std::map<std::string,App::Property*>::iterator jt;
116
jt = std::find_if(props.begin(), props.end(), find_transform());
117
if (jt != props.end()) {
118
Base::Placement local = static_cast<App::PropertyPlacement*>(jt->second)->getValue();
119
Gui::ViewProvider* vp = doc->getViewProvider(obj);
120
if (vp) vp->setTransformation(local.toMatrix());
124
Gui::ViewProvider* vp = doc->getViewProvider(obj);
125
if (vp) vp->setTransformation(Base::Matrix4D());
129
if (obj->isDerivedFrom<App::GeoFeature>()) {
131
const App::PropertyGeometry* geo = static_cast<App::GeoFeature*>(obj)->getPropertyOfGeometry();
133
const_cast<App::PropertyGeometry*>(geo)->transformGeometry(mat);
138
void TransformStrategy::applyTransform(const Base::Placement& plm)
140
std::set<App::DocumentObject*> objects = transformObjects();
141
for (const auto & object : objects) {
142
applyViewTransform(plm, object);
146
void TransformStrategy::resetTransform()
148
std::set<App::DocumentObject*> objects = transformObjects();
149
for (const auto & object : objects) {
150
resetViewTransform(object);
154
void TransformStrategy::applyViewTransform(const Base::Placement& plm, App::DocumentObject* obj)
156
Gui::Document* doc = Gui::Application::Instance->getDocument(obj->getDocument());
157
std::map<std::string,App::Property*> props;
158
obj->getPropertyMap(props);
160
std::map<std::string,App::Property*>::iterator jt;
161
jt = std::find_if(props.begin(), props.end(), find_transform());
162
if (jt != props.end()) {
163
Base::Placement local = static_cast<App::PropertyPlacement*>(jt->second)->getValue();
165
Gui::ViewProvider* vp = doc->getViewProvider(obj);
166
if (vp) vp->setTransformation(local.toMatrix());
170
Gui::ViewProvider* vp = doc->getViewProvider(obj);
171
if (vp) vp->setTransformation(plm.toMatrix());
175
void TransformStrategy::resetViewTransform(App::DocumentObject* obj)
177
Gui::Document* doc = Gui::Application::Instance->getDocument(obj->getDocument());
178
std::map<std::string,App::Property*> props;
179
obj->getPropertyMap(props);
181
std::map<std::string,App::Property*>::iterator jt;
182
jt = std::find_if(props.begin(), props.end(), find_transform());
183
if (jt != props.end()) {
184
Base::Placement local = static_cast<App::PropertyPlacement*>(jt->second)->getValue();
185
Gui::ViewProvider* vp = doc->getViewProvider(obj);
186
if (vp) vp->setTransformation(local.toMatrix());
190
Gui::ViewProvider* vp = doc->getViewProvider(obj);
191
if (vp) vp->setTransformation(Base::Matrix4D());
197
DefaultTransformStrategy::DefaultTransformStrategy(QWidget* w) : widget(w)
199
Gui::SelectionChanges mod;
200
mod.Type = Gui::SelectionChanges::SetSelection;
201
onSelectionChanged(mod);
204
DefaultTransformStrategy::~DefaultTransformStrategy() = default;
206
std::set<App::DocumentObject*> DefaultTransformStrategy::transformObjects() const
211
void DefaultTransformStrategy::onSelectionChanged(const Gui::SelectionChanges& msg)
213
if (msg.Type == SelectionChanges::SetPreselect ||
214
msg.Type == SelectionChanges::RmvPreselect)
216
if (msg.Type == SelectionChanges::ClrSelection) {
217
widget->setDisabled(true);
218
for (const auto & it : selection)
219
resetViewTransform(it);
224
std::set<App::DocumentObject*> update_selection;
225
std::vector<App::DocumentObject*> sel = Gui::Selection().getObjectsOfType
226
(App::DocumentObject::getClassTypeId());
227
for (const auto & it : sel) {
228
if (it->isDerivedFrom<App::GeoFeature>()) {
230
const App::PropertyGeometry* geo = static_cast<App::GeoFeature*>(it)->getPropertyOfGeometry();
232
update_selection.insert(it);
241
std::set<App::DocumentObject*> filter;
242
for (auto it = update_selection.begin(); it != update_selection.end(); ++it) {
243
std::vector<App::DocumentObject*> deps = (*it)->getOutList();
244
std::vector<App::DocumentObject*>::iterator jt;
245
for (jt = deps.begin(); jt != deps.end(); ++jt) {
246
if (update_selection.find(*jt) != update_selection.end()) {
253
if (!filter.empty()) {
254
std::set<App::DocumentObject*> diff;
255
std::insert_iterator< std::set<App::DocumentObject*> > biit(diff, diff.begin());
256
std::set_difference(update_selection.begin(), update_selection.end(),
257
filter.begin(), filter.end(), biit);
258
update_selection = diff;
262
std::vector<App::DocumentObject*> diff;
263
std::back_insert_iterator< std::vector<App::DocumentObject*> > biit(diff);
264
std::set_difference(selection.begin(), selection.end(),
265
update_selection.begin(), update_selection.end(), biit);
266
for (const auto & it : diff)
267
resetViewTransform(it);
268
selection = update_selection;
270
widget->setDisabled(selection.empty());
277
Transform::Transform(QWidget* parent, Qt::WindowFlags fl)
278
: QDialog(parent, fl), strategy(nullptr)
280
ui = new Ui_Placement();
282
connect(ui->applyButton, &QPushButton::clicked,
283
this, &Transform::onApplyButtonClicked);
285
ui->resetButton->hide();
286
ui->applyIncrementalPlacement->hide();
288
ui->closeButton->setText(tr("Cancel"));
289
this->setWindowTitle(tr("Transform"));
292
auto signalMapper = new QSignalMapper(this);
293
signalMapper->setMapping(this, 0);
296
QList<Gui::QuantitySpinBox*> sb = this->findChildren<Gui::QuantitySpinBox*>();
297
for (const auto & it : sb) {
298
connect(it, qOverload<double>(&QuantitySpinBox::valueChanged), signalMapper, qOverload<>(&QSignalMapper::map));
299
signalMapper->setMapping(it, id++);
302
#if QT_VERSION < QT_VERSION_CHECK(5,15,0)
303
connect(signalMapper, qOverload<int>(&QSignalMapper::mapped),
304
this, &Transform::onTransformChanged);
306
connect(signalMapper, &QSignalMapper::mappedInt,
307
this, &Transform::onTransformChanged);
310
setTransformStrategy(new DefaultTransformStrategy(this));
313
Transform::~Transform()
319
void Transform::setTransformStrategy(TransformStrategy* ts)
321
if (!ts || ts == strategy)
326
Base::Vector3d cnt = strategy->getRotationCenter();
327
ui->xCnt->setValue(Base::Quantity(cnt.x, Base::Unit::Length));
328
ui->yCnt->setValue(Base::Quantity(cnt.y, Base::Unit::Length));
329
ui->zCnt->setValue(Base::Quantity(cnt.z, Base::Unit::Length));
330
this->setDisabled(strategy->transformObjects().empty());
333
void Transform::showStandardButtons(bool b)
335
ui->closeButton->setVisible(b);
336
ui->oKButton->setVisible(b);
337
ui->applyButton->setVisible(b);
340
void Transform::onTransformChanged(int)
342
Base::Placement plm = this->getPlacementData();
343
strategy->applyTransform(plm);
346
void Transform::accept()
348
onApplyButtonClicked();
352
void Transform::reject()
354
strategy->resetTransform();
358
void Transform::onApplyButtonClicked()
361
Base::Placement plm = this->getPlacementData();
362
Base::Matrix4D mat = plm.toMatrix();
363
strategy->commitTransform(mat);
366
QList<Gui::QuantitySpinBox*> sb = this->findChildren<Gui::QuantitySpinBox*>();
367
for (auto & it : sb) {
368
it->blockSignals(true);
370
it->blockSignals(false);
373
Base::Vector3d cnt = strategy->getRotationCenter();
374
ui->xCnt->setValue(Base::Quantity(cnt.x, Base::Unit::Length));
375
ui->yCnt->setValue(Base::Quantity(cnt.y, Base::Unit::Length));
376
ui->zCnt->setValue(Base::Quantity(cnt.z, Base::Unit::Length));
379
Base::Vector3d Transform::getDirection() const
381
double x = ui->xAxis->value().getValue();
382
double y = ui->yAxis->value().getValue();
383
double z = ui->zAxis->value().getValue();
384
return Base::Vector3d(x, y, z);
387
Base::Placement Transform::getPlacementData() const
389
int index = ui->rotationInput->currentIndex();
394
pos = Base::Vector3d(ui->xPos->value().getValue(),ui->yPos->value().getValue(),ui->zPos->value().getValue());
395
cnt = Base::Vector3d(ui->xCnt->value().getValue(),ui->yCnt->value().getValue(),ui->zCnt->value().getValue());
398
Base::Vector3d dir = getDirection();
399
rot.setValue(Base::Vector3d(dir.x,dir.y,dir.z),ui->angle->value().getValue()*D_PI/180.0);
401
else if (index == 1) {
403
ui->yawAngle->value().getValue(),
404
ui->pitchAngle->value().getValue(),
405
ui->rollAngle->value().getValue());
408
Base::Placement p(pos, rot, cnt);
412
void Transform::changeEvent(QEvent *e)
414
if (e->type() == QEvent::LanguageChange) {
415
ui->retranslateUi(this);
416
ui->closeButton->setText(tr("Cancel"));
417
this->setWindowTitle(tr("Transform"));
420
QDialog::changeEvent(e);
426
TaskTransform::TaskTransform()
428
this->setButtonPosition(TaskTransform::South);
429
dialog = new Transform();
430
dialog->showStandardButtons(false);
434
TaskTransform::~TaskTransform() = default;
436
void TaskTransform::setTransformStrategy(TransformStrategy* ts)
438
dialog->setTransformStrategy(ts);
441
bool TaskTransform::accept()
444
return (dialog->result() == QDialog::Accepted);
447
bool TaskTransform::reject()
450
return (dialog->result() == QDialog::Rejected);
453
void TaskTransform::clicked(int id)
455
if (id == QDialogButtonBox::Apply) {
456
dialog->onApplyButtonClicked();
460
#include "moc_Transform.cpp"