23
#include "PreCompiled.h"
26
# include <boost_signals2.hpp>
27
# include <QDockWidget>
28
# include <QSignalBlocker>
31
#include <Base/Console.h>
33
#include "DlgDisplayPropertiesImp.h"
34
#include "ui_DlgDisplayProperties.h"
35
#include "Application.h"
37
#include "DlgMaterialPropertiesImp.h"
38
#include "DockWindowManager.h"
40
#include "ViewProvider.h"
41
#include "WaitCursor.h"
44
using namespace Gui::Dialog;
46
namespace sp = std::placeholders;
52
qApp->translate("QDockWidget", "Display properties");
55
class DlgDisplayPropertiesImp::Private
57
using DlgDisplayPropertiesImp_Connection = boost::signals2::connection;
59
Ui::DlgDisplayProperties ui;
61
DlgDisplayPropertiesImp_Connection connectChangedObject;
63
static void setElementColor(const std::vector<Gui::ViewProvider*>& views, const char* property, Gui::ColorButton* buttonColor)
65
bool hasElementColor = false;
66
for (const auto & view : views) {
67
if (auto* prop = dynamic_cast<App::PropertyColor*>(view->getPropertyByName(property))) {
68
App::Color color = prop->getValue();
69
QSignalBlocker block(buttonColor);
70
buttonColor->setColor(color.asValue<QColor>());
71
hasElementColor = true;
76
buttonColor->setEnabled(hasElementColor);
79
static void setDrawStyle(const std::vector<Gui::ViewProvider*>& views, const char* property, QSpinBox* spinbox)
81
bool hasDrawStyle = false;
82
for (const auto & view : views) {
83
if (auto* prop = dynamic_cast<App::PropertyFloat*>(view->getPropertyByName(property))) {
84
QSignalBlocker block(spinbox);
85
spinbox->setValue(int(prop->getValue()));
91
spinbox->setEnabled(hasDrawStyle);
94
static void setTransparency(const std::vector<Gui::ViewProvider*>& views, const char* property, QSpinBox* spinbox, QSlider* slider)
96
bool hasTransparency = false;
97
for (const auto & view : views) {
98
if (auto* prop = dynamic_cast<App::PropertyInteger*>(view->getPropertyByName(property))) {
99
QSignalBlocker blockSpinBox(spinbox);
100
spinbox->setValue(prop->getValue());
102
QSignalBlocker blockSlider(slider);
103
slider->setValue(prop->getValue());
104
hasTransparency = true;
109
spinbox->setEnabled(hasTransparency);
110
slider->setEnabled(hasTransparency);
121
DlgDisplayPropertiesImp::DlgDisplayPropertiesImp(bool floating, QWidget* parent, Qt::WindowFlags fl)
122
: QDialog( parent, fl )
128
d->ui.textLabel1_3->hide();
129
d->ui.changePlot->hide();
130
d->ui.buttonLineColor->setModal(false);
131
d->ui.buttonPointColor->setModal(false);
132
d->ui.buttonColor->setModal(false);
133
d->floating = floating;
135
std::vector<Gui::ViewProvider*> views = getSelection();
136
setDisplayModes(views);
140
setShapeColor(views);
142
setPointColor(views);
145
setTransparency(views);
146
setLineTransparency(views);
150
Gui::DockWindowManager* pDockMgr = Gui::DockWindowManager::instance();
151
QDockWidget* dw = pDockMgr->addDockWindow("Display properties", this, Qt::AllDockWidgetAreas);
152
dw->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
153
dw->setFloating(true);
157
Gui::Selection().Attach(this);
160
d->connectChangedObject =
161
Gui::Application::Instance->signalChangedObject.connect(std::bind
162
(&DlgDisplayPropertiesImp::slotChangedObject, this, sp::_1, sp::_2));
169
DlgDisplayPropertiesImp::~DlgDisplayPropertiesImp()
172
d->connectChangedObject.disconnect();
173
Gui::Selection().Detach(this);
176
void DlgDisplayPropertiesImp::setupConnections()
178
#if QT_VERSION < QT_VERSION_CHECK(5,14,0)
179
connect(d->ui.changeMode, qOverload<const QString&>(&QComboBox::activated), this, &DlgDisplayPropertiesImp::onChangeModeActivated);
180
connect(d->ui.changePlot, qOverload<const QString&>(&QComboBox::activated), this, &DlgDisplayPropertiesImp::onChangePlotActivated);
182
connect(d->ui.changeMode, &QComboBox::textActivated, this, &DlgDisplayPropertiesImp::onChangeModeActivated);
183
connect(d->ui.changePlot, &QComboBox::textActivated, this, &DlgDisplayPropertiesImp::onChangePlotActivated);
185
connect(d->ui.changeMaterial, qOverload<int>(&QComboBox::activated), this, &DlgDisplayPropertiesImp::onChangeMaterialActivated);
186
connect(d->ui.buttonColor, &ColorButton::changed, this, &DlgDisplayPropertiesImp::onButtonColorChanged);
187
connect(d->ui.spinTransparency, qOverload<int>(&QSpinBox::valueChanged), this, &DlgDisplayPropertiesImp::onSpinTransparencyValueChanged);
188
connect(d->ui.spinPointSize, qOverload<int>(&QSpinBox::valueChanged), this, &DlgDisplayPropertiesImp::onSpinPointSizeValueChanged);
189
connect(d->ui.buttonLineColor, &ColorButton::changed, this, &DlgDisplayPropertiesImp::onButtonLineColorChanged);
190
connect(d->ui.buttonPointColor, &ColorButton::changed, this, &DlgDisplayPropertiesImp::onButtonPointColorChanged);
191
connect(d->ui.spinLineWidth, qOverload<int>(&QSpinBox::valueChanged), this, &DlgDisplayPropertiesImp::onSpinLineWidthValueChanged);
192
connect(d->ui.spinLineTransparency, qOverload<int>(&QSpinBox::valueChanged), this, &DlgDisplayPropertiesImp::onSpinLineTransparencyValueChanged);
193
connect(d->ui.buttonUserDefinedMaterial, &ColorButton::clicked, this, &DlgDisplayPropertiesImp::onButtonUserDefinedMaterialClicked);
194
connect(d->ui.buttonColorPlot, &ColorButton::clicked, this, &DlgDisplayPropertiesImp::onButtonColorPlotClicked);
197
void DlgDisplayPropertiesImp::changeEvent(QEvent *e)
199
if (e->type() == QEvent::LanguageChange) {
200
d->ui.retranslateUi(this);
202
QDialog::changeEvent(e);
206
void DlgDisplayPropertiesImp::OnChange(Gui::SelectionSingleton::SubjectType &rCaller,
207
Gui::SelectionSingleton::MessageType Reason)
210
if (Reason.Type == SelectionChanges::AddSelection ||
211
Reason.Type == SelectionChanges::RmvSelection ||
212
Reason.Type == SelectionChanges::SetSelection ||
213
Reason.Type == SelectionChanges::ClrSelection) {
214
std::vector<Gui::ViewProvider*> views = getSelection();
215
setDisplayModes(views);
218
setShapeColor(views);
220
setPointColor(views);
223
setTransparency(views);
224
setLineTransparency(views);
229
void DlgDisplayPropertiesImp::slotChangedObject(const Gui::ViewProvider& obj,
230
const App::Property& prop)
234
std::vector<Gui::ViewProvider*> Provider = getSelection();
235
auto vp = std::find_if(Provider.begin(),
237
[&obj](Gui::ViewProvider* v) { return v == &obj; });
239
if (vp != Provider.end()) {
240
const char* name = obj.getPropertyName(&prop);
244
std::string prop_name = name;
245
if (prop.is<App::PropertyColor>()) {
246
App::Color value = static_cast<const App::PropertyColor&>(prop).getValue();
247
if (prop_name == "ShapeColor") {
248
bool blocked = d->ui.buttonColor->blockSignals(true);
249
d->ui.buttonColor->setColor(QColor((int)(255.0f * value.r),
250
(int)(255.0f * value.g),
251
(int)(255.0f * value.b)));
252
d->ui.buttonColor->blockSignals(blocked);
254
else if (prop_name == "LineColor") {
255
bool blocked = d->ui.buttonLineColor->blockSignals(true);
256
d->ui.buttonLineColor->setColor(QColor((int)(255.0f * value.r),
257
(int)(255.0f * value.g),
258
(int)(255.0f * value.b)));
259
d->ui.buttonLineColor->blockSignals(blocked);
261
else if (prop_name == "PointColor") {
262
bool blocked = d->ui.buttonPointColor->blockSignals(true);
263
d->ui.buttonPointColor->setColor(QColor((int)(255.0f * value.r),
264
(int)(255.0f * value.g),
265
(int)(255.0f * value.b)));
266
d->ui.buttonPointColor->blockSignals(blocked);
269
else if (prop.isDerivedFrom<App::PropertyInteger>()) {
270
long value = static_cast<const App::PropertyInteger&>(prop).getValue();
271
if (prop_name == "Transparency") {
272
bool blocked = d->ui.spinTransparency->blockSignals(true);
273
d->ui.spinTransparency->setValue(value);
274
d->ui.spinTransparency->blockSignals(blocked);
275
blocked = d->ui.horizontalSlider->blockSignals(true);
276
d->ui.horizontalSlider->setValue(value);
277
d->ui.horizontalSlider->blockSignals(blocked);
279
else if (prop_name == "LineTransparency") {
280
bool blocked = d->ui.spinLineTransparency->blockSignals(true);
281
d->ui.spinLineTransparency->setValue(value);
282
d->ui.spinLineTransparency->blockSignals(blocked);
283
blocked = d->ui.sliderLineTransparency->blockSignals(true);
284
d->ui.sliderLineTransparency->setValue(value);
285
d->ui.sliderLineTransparency->blockSignals(blocked);
288
else if (prop.isDerivedFrom<App::PropertyFloat>()) {
289
double value = static_cast<const App::PropertyFloat&>(prop).getValue();
290
if (prop_name == "PointSize") {
291
bool blocked = d->ui.spinPointSize->blockSignals(true);
292
d->ui.spinPointSize->setValue((int)value);
293
d->ui.spinPointSize->blockSignals(blocked);
295
else if (prop_name == "LineWidth") {
296
bool blocked = d->ui.spinLineWidth->blockSignals(true);
297
d->ui.spinLineWidth->setValue((int)value);
298
d->ui.spinLineWidth->blockSignals(blocked);
307
void DlgDisplayPropertiesImp::reject()
311
Gui::DockWindowManager* pDockMgr = Gui::DockWindowManager::instance();
312
pDockMgr->removeDockWindow(this);
320
void DlgDisplayPropertiesImp::onButtonUserDefinedMaterialClicked()
322
std::vector<Gui::ViewProvider*> Provider = getSelection();
323
DlgMaterialPropertiesImp dlg("ShapeMaterial", this);
324
dlg.setViewProviders(Provider);
327
d->ui.buttonColor->setColor(dlg.diffuseColor());
333
void DlgDisplayPropertiesImp::onButtonColorPlotClicked()
335
std::vector<Gui::ViewProvider*> Provider = getSelection();
336
static QPointer<DlgMaterialPropertiesImp> dlg = nullptr;
338
dlg = new DlgMaterialPropertiesImp("TextureMaterial", this);
339
dlg->setModal(false);
340
dlg->setAttribute(Qt::WA_DeleteOnClose);
341
dlg->setViewProviders(Provider);
348
void DlgDisplayPropertiesImp::onChangeMaterialActivated(int index)
350
std::vector<Gui::ViewProvider*> Provider = getSelection();
351
App::Material::MaterialType matType = static_cast<App::Material::MaterialType>(d->ui.changeMaterial->itemData(index).toInt());
352
App::Material mat(matType);
353
App::Color diffuseColor = mat.diffuseColor;
354
d->ui.buttonColor->setColor(QColor((int)(diffuseColor.r*255.0f),
355
(int)(diffuseColor.g*255.0f),
356
(int)(diffuseColor.b*255.0f)));
358
for (auto it : Provider) {
359
if (auto* prop = dynamic_cast<App::PropertyMaterial*>(it->getPropertyByName("ShapeMaterial"))) {
368
void DlgDisplayPropertiesImp::onChangeModeActivated(const QString& s)
371
std::vector<Gui::ViewProvider*> Provider = getSelection();
372
for (auto it : Provider) {
373
if (auto* prop = dynamic_cast<App::PropertyEnumeration*>(it->getPropertyByName("DisplayMode"))) {
374
prop->setValue(static_cast<const char*>(s.toLatin1()));
379
void DlgDisplayPropertiesImp::onChangePlotActivated(const QString&s)
381
Base::Console().Log("Plot = %s\n",(const char*)s.toLatin1());
387
void DlgDisplayPropertiesImp::onButtonColorChanged()
389
std::vector<Gui::ViewProvider*> Provider = getSelection();
390
QColor s = d->ui.buttonColor->color();
391
App::Color c(s.red() / 255.0, s.green() / 255.0, s.blue() / 255.0);
392
for (auto it : Provider) {
393
if (auto* prop = dynamic_cast<App::PropertyColor*>(it->getPropertyByName("ShapeColor"))) {
402
void DlgDisplayPropertiesImp::onSpinTransparencyValueChanged(int transparency)
404
std::vector<Gui::ViewProvider*> Provider = getSelection();
405
for (auto it : Provider) {
406
if (auto* prop = dynamic_cast<App::PropertyInteger*>(it->getPropertyByName("Transparency"))) {
407
prop->setValue(transparency);
415
void DlgDisplayPropertiesImp::onSpinPointSizeValueChanged(int pointsize)
417
std::vector<Gui::ViewProvider*> Provider = getSelection();
418
for (auto it : Provider) {
419
if (auto* prop = dynamic_cast<App::PropertyFloat*>(it->getPropertyByName("PointSize"))) {
420
prop->setValue(static_cast<double>(pointsize));
428
void DlgDisplayPropertiesImp::onSpinLineWidthValueChanged(int linewidth)
430
std::vector<Gui::ViewProvider*> Provider = getSelection();
431
for (auto it : Provider) {
432
if (auto* prop = dynamic_cast<App::PropertyFloat*>(it->getPropertyByName("LineWidth"))) {
433
prop->setValue(static_cast<double>(linewidth));
438
void DlgDisplayPropertiesImp::onButtonLineColorChanged()
440
std::vector<Gui::ViewProvider*> Provider = getSelection();
441
QColor s = d->ui.buttonLineColor->color();
442
App::Color c(s.red() / 255.0, s.green() / 255.0, s.blue() / 255.0);
443
for (auto it : Provider) {
444
if (auto* prop = dynamic_cast<App::PropertyColor*>(it->getPropertyByName("LineColor"))) {
450
void DlgDisplayPropertiesImp::onButtonPointColorChanged()
452
std::vector<Gui::ViewProvider*> Provider = getSelection();
453
QColor s = d->ui.buttonPointColor->color();
454
App::Color c(s.red() / 255.0, s.green() / 255.0, s.blue() / 255.0);
455
for (auto it : Provider) {
456
if (auto* prop = dynamic_cast<App::PropertyColor*>(it->getPropertyByName("PointColor"))) {
462
void DlgDisplayPropertiesImp::onSpinLineTransparencyValueChanged(int transparency)
464
std::vector<Gui::ViewProvider*> Provider = getSelection();
465
for (auto it : Provider) {
466
if (auto* prop = dynamic_cast<App::PropertyInteger*>(it->getPropertyByName("LineTransparency"))) {
467
prop->setValue(transparency);
472
void DlgDisplayPropertiesImp::setDisplayModes(const std::vector<Gui::ViewProvider*>& views)
474
QStringList commonModes, modes;
475
for (auto it = views.begin(); it != views.end(); ++it) {
476
if (auto* prop = dynamic_cast<App::PropertyEnumeration*>((*it)->getPropertyByName("DisplayMode"))) {
477
if (!prop->hasEnums())
479
std::vector<std::string> value = prop->getEnumVector();
480
if (it == views.begin()) {
481
for (const auto & jt : value)
482
commonModes << QLatin1String(jt.c_str());
485
for (const auto & jt : value) {
486
if (commonModes.contains(QLatin1String(jt.c_str())))
487
modes << QLatin1String(jt.c_str());
496
d->ui.changeMode->clear();
497
d->ui.changeMode->addItems(commonModes);
498
d->ui.changeMode->setDisabled(commonModes.isEmpty());
501
for (const auto & view : views) {
502
if (auto* prop = dynamic_cast<App::PropertyEnumeration*>(view->getPropertyByName("DisplayMode"))) {
503
QString activeMode = QString::fromLatin1(prop->getValueAsString());
504
int index = d->ui.changeMode->findText(activeMode);
506
d->ui.changeMode->setCurrentIndex(index);
513
void DlgDisplayPropertiesImp::setMaterial(const std::vector<Gui::ViewProvider*>& views)
515
bool material = false;
516
App::Material::MaterialType matType = App::Material::DEFAULT;
517
for (auto view : views) {
518
if (auto* prop = dynamic_cast<App::PropertyMaterial*>(view->getPropertyByName("ShapeMaterial"))) {
520
matType = prop->getValue().getType();
525
int index = d->ui.changeMaterial->findData(matType);
527
d->ui.changeMaterial->setCurrentIndex(index);
529
d->ui.changeMaterial->setEnabled(material);
530
d->ui.buttonUserDefinedMaterial->setEnabled(material);
533
void DlgDisplayPropertiesImp::setColorPlot(const std::vector<Gui::ViewProvider*>& views)
535
bool material = false;
536
for (auto view : views) {
537
auto* prop = dynamic_cast<App::PropertyMaterial*>(view->getPropertyByName("TextureMaterial"));
544
d->ui.buttonColorPlot->setEnabled(material);
547
void DlgDisplayPropertiesImp::fillupMaterials()
549
d->ui.changeMaterial->addItem(tr("Default"), App::Material::DEFAULT);
550
d->ui.changeMaterial->addItem(tr("Aluminium"), App::Material::ALUMINIUM);
551
d->ui.changeMaterial->addItem(tr("Brass"), App::Material::BRASS);
552
d->ui.changeMaterial->addItem(tr("Bronze"), App::Material::BRONZE);
553
d->ui.changeMaterial->addItem(tr("Copper"), App::Material::COPPER);
554
d->ui.changeMaterial->addItem(tr("Chrome"), App::Material::CHROME);
555
d->ui.changeMaterial->addItem(tr("Emerald"), App::Material::EMERALD);
556
d->ui.changeMaterial->addItem(tr("Gold"), App::Material::GOLD);
557
d->ui.changeMaterial->addItem(tr("Jade"), App::Material::JADE);
558
d->ui.changeMaterial->addItem(tr("Metalized"), App::Material::METALIZED);
559
d->ui.changeMaterial->addItem(tr("Neon GNC"), App::Material::NEON_GNC);
560
d->ui.changeMaterial->addItem(tr("Neon PHC"), App::Material::NEON_PHC);
561
d->ui.changeMaterial->addItem(tr("Obsidian"), App::Material::OBSIDIAN);
562
d->ui.changeMaterial->addItem(tr("Pewter"), App::Material::PEWTER);
563
d->ui.changeMaterial->addItem(tr("Plaster"), App::Material::PLASTER);
564
d->ui.changeMaterial->addItem(tr("Plastic"), App::Material::PLASTIC);
565
d->ui.changeMaterial->addItem(tr("Ruby"), App::Material::RUBY);
566
d->ui.changeMaterial->addItem(tr("Satin"), App::Material::SATIN);
567
d->ui.changeMaterial->addItem(tr("Shiny plastic"), App::Material::SHINY_PLASTIC);
568
d->ui.changeMaterial->addItem(tr("Silver"), App::Material::SILVER);
569
d->ui.changeMaterial->addItem(tr("Steel"), App::Material::STEEL);
570
d->ui.changeMaterial->addItem(tr("Stone"), App::Material::STONE);
573
void DlgDisplayPropertiesImp::setShapeColor(const std::vector<Gui::ViewProvider*>& views)
575
Private::setElementColor(views, "ShapeColor", d->ui.buttonColor);
578
void DlgDisplayPropertiesImp::setLineColor(const std::vector<Gui::ViewProvider*>& views)
580
Private::setElementColor(views, "LineColor", d->ui.buttonLineColor);
583
void DlgDisplayPropertiesImp::setPointColor(const std::vector<Gui::ViewProvider*>& views)
585
Private::setElementColor(views, "PointColor", d->ui.buttonPointColor);
588
void DlgDisplayPropertiesImp::setPointSize(const std::vector<Gui::ViewProvider*>& views)
590
Private::setDrawStyle(views, "PointSize", d->ui.spinPointSize);
593
void DlgDisplayPropertiesImp::setLineWidth(const std::vector<Gui::ViewProvider*>& views)
595
Private::setDrawStyle(views, "LineWidth", d->ui.spinLineWidth);
598
void DlgDisplayPropertiesImp::setTransparency(const std::vector<Gui::ViewProvider*>& views)
600
Private::setTransparency(views, "Transparency", d->ui.spinTransparency, d->ui.horizontalSlider);
603
void DlgDisplayPropertiesImp::setLineTransparency(const std::vector<Gui::ViewProvider*>& views)
605
Private::setTransparency(views, "LineTransparency", d->ui.spinLineTransparency, d->ui.sliderLineTransparency);
608
std::vector<Gui::ViewProvider*> DlgDisplayPropertiesImp::getSelection() const
610
std::vector<Gui::ViewProvider*> views;
613
std::vector<SelectionSingleton::SelObj> sel = Selection().getCompleteSelection();
614
for (const auto & it : sel) {
615
Gui::ViewProvider* view = Application::Instance->getDocument(it.pDoc)->getViewProvider(it.pObject);
616
views.push_back(view);
626
TaskDisplayProperties::TaskDisplayProperties()
628
this->setButtonPosition(TaskDisplayProperties::North);
629
widget = new DlgDisplayPropertiesImp(false);
633
TaskDisplayProperties::~TaskDisplayProperties() = default;
635
QDialogButtonBox::StandardButtons TaskDisplayProperties::getStandardButtons() const
637
return QDialogButtonBox::Close;
640
bool TaskDisplayProperties::reject()
643
return (widget->result() == QDialog::Rejected);
646
#include "moc_DlgDisplayPropertiesImp.cpp"