| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include <QDockWidget> |
| | #include <QSignalBlocker> |
| | #include <QString> |
| | #include <algorithm> |
| | #include <fastsignals/signal.h> |
| |
|
| | #include <Base/Console.h> |
| | #include <Gui/Application.h> |
| | #include <Gui/DockWindowManager.h> |
| | #include <Gui/Document.h> |
| | #include <Gui/Selection/Selection.h> |
| | #include <Gui/ViewProvider.h> |
| | #include <Gui/WaitCursor.h> |
| |
|
| | #include <Mod/Material/App/Exceptions.h> |
| | #include <Mod/Material/App/MaterialManager.h> |
| | #include <Mod/Material/App/ModelUuids.h> |
| | #include <Mod/Material/App/PropertyMaterial.h> |
| |
|
| | #include "DlgMaterialImp.h" |
| | #include "ui_DlgMaterial.h" |
| |
|
| |
|
| | using namespace MatGui; |
| | using namespace std; |
| | namespace sp = std::placeholders; |
| |
|
| |
|
| | |
| |
|
| | #if 0 |
| | qApp->translate("QDockWidget", "Material"); |
| | #endif |
| |
|
| | class DlgMaterialImp::Private |
| | { |
| | using DlgMaterialImp_Connection = fastsignals::connection; |
| |
|
| | public: |
| | Ui::DlgMaterial ui; |
| | bool floating; |
| | DlgMaterialImp_Connection connectChangedObject; |
| | }; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | DlgMaterialImp::DlgMaterialImp(bool floating, QWidget* parent, Qt::WindowFlags fl) |
| | : QDialog(parent, fl) |
| | , d(new Private) |
| | { |
| | d->ui.setupUi(this); |
| | setupConnections(); |
| |
|
| | d->floating = floating; |
| |
|
| | |
| | |
| | Materials::MaterialFilter filter; |
| | filter.requirePhysical(true); |
| | d->ui.widgetMaterial->setFilter(filter); |
| |
|
| | std::vector<App::DocumentObject*> objects = getSelectionObjects(); |
| | setMaterial(objects); |
| |
|
| | |
| | if (floating) { |
| | Gui::DockWindowManager* pDockMgr = Gui::DockWindowManager::instance(); |
| | QDockWidget* dw = |
| | pDockMgr->addDockWindow("Display Properties", this, Qt::AllDockWidgetAreas); |
| | dw->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); |
| | dw->setFloating(true); |
| | dw->show(); |
| | } |
| |
|
| | Gui::Selection().Attach(this); |
| |
|
| | |
| | d->connectChangedObject = Gui::Application::Instance->signalChangedObject.connect( |
| | std::bind(&DlgMaterialImp::slotChangedObject, this, sp::_1, sp::_2)); |
| | |
| | } |
| |
|
| | |
| | |
| | |
| | DlgMaterialImp::~DlgMaterialImp() |
| | { |
| | |
| | d->connectChangedObject.disconnect(); |
| | Gui::Selection().Detach(this); |
| | } |
| |
|
| | void DlgMaterialImp::setupConnections() |
| | { |
| | connect(d->ui.widgetMaterial, |
| | &MaterialTreeWidget::materialSelected, |
| | this, |
| | &DlgMaterialImp::onMaterialSelected); |
| | } |
| |
|
| | void DlgMaterialImp::changeEvent(QEvent* e) |
| | { |
| | if (e->type() == QEvent::LanguageChange) { |
| | d->ui.retranslateUi(this); |
| | } |
| | QDialog::changeEvent(e); |
| | } |
| |
|
| | |
| | void DlgMaterialImp::OnChange(Gui::SelectionSingleton::SubjectType& rCaller, |
| | Gui::SelectionSingleton::MessageType Reason) |
| | { |
| | Q_UNUSED(rCaller); |
| | if (Reason.Type == Gui::SelectionChanges::AddSelection |
| | || Reason.Type == Gui::SelectionChanges::RmvSelection |
| | || Reason.Type == Gui::SelectionChanges::SetSelection |
| | || Reason.Type == Gui::SelectionChanges::ClrSelection) { |
| | std::vector<App::DocumentObject*> objects = getSelectionObjects(); |
| | setMaterial(objects); |
| | } |
| | } |
| | |
| |
|
| | void DlgMaterialImp::slotChangedObject(const Gui::ViewProvider& obj, const App::Property& prop) |
| | { |
| | |
| | |
| | std::vector<Gui::ViewProvider*> Provider = getSelection(); |
| | auto vp = std::find_if(Provider.begin(), Provider.end(), [&obj](Gui::ViewProvider* v) { |
| | return v == &obj; |
| | }); |
| |
|
| | if (vp != Provider.end()) { |
| | const char* name = obj.getPropertyName(&prop); |
| | |
| | if (!name) { |
| | return; |
| | } |
| | std::string prop_name = name; |
| | if (prop.isDerivedFrom<App::PropertyMaterial>()) { |
| | |
| | if (prop_name == "ShapeMaterial") { |
| | |
| | |
| | |
| | |
| | |
| | |
| | } |
| | } |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | void DlgMaterialImp::reject() |
| | { |
| | if (d->floating) { |
| | |
| | Gui::DockWindowManager* pDockMgr = Gui::DockWindowManager::instance(); |
| | pDockMgr->removeDockWindow(this); |
| | } |
| | QDialog::reject(); |
| | } |
| |
|
| | void DlgMaterialImp::setMaterial(const std::vector<App::DocumentObject*>& objects) |
| | { |
| | for (auto it : objects) { |
| | if (auto prop = dynamic_cast<Materials::PropertyMaterial*>(it->getPropertyByName("ShapeMaterial"))) { |
| | try { |
| | const auto& material = prop->getValue(); |
| | d->ui.widgetMaterial->setMaterial(material.getUUID()); |
| | return; |
| | } |
| | catch (const Materials::MaterialNotFound&) { |
| | } |
| | } |
| | } |
| | d->ui.widgetMaterial->setMaterial(Materials::MaterialManager::defaultMaterialUUID()); |
| | } |
| |
|
| | std::vector<Gui::ViewProvider*> DlgMaterialImp::getSelection() const |
| | { |
| | std::vector<Gui::ViewProvider*> views; |
| |
|
| | |
| | std::vector<Gui::SelectionSingleton::SelObj> sel = Gui::Selection().getCompleteSelection(); |
| | for (const auto& it : sel) { |
| | Gui::ViewProvider* view = |
| | Gui::Application::Instance->getDocument(it.pDoc)->getViewProvider(it.pObject); |
| | views.push_back(view); |
| | } |
| |
|
| | return views; |
| | } |
| |
|
| | std::vector<App::DocumentObject*> DlgMaterialImp::getSelectionObjects() const |
| | { |
| | std::vector<App::DocumentObject*> objects; |
| |
|
| | |
| | std::vector<Gui::SelectionSingleton::SelObj> sel = Gui::Selection().getCompleteSelection(); |
| | for (const auto& it : sel) { |
| | objects.push_back(it.pObject); |
| | } |
| |
|
| | return objects; |
| | } |
| |
|
| | void DlgMaterialImp::onMaterialSelected(const std::shared_ptr<Materials::Material>& material) |
| | { |
| | std::vector<App::DocumentObject*> objects = getSelectionObjects(); |
| | for (auto it : objects) { |
| | if (auto prop = dynamic_cast<Materials::PropertyMaterial*>(it->getPropertyByName("ShapeMaterial"))) { |
| | prop->setValue(*material); |
| | } |
| | } |
| | } |
| |
|
| | |
| |
|
| | |
| |
|
| | TaskMaterial::TaskMaterial() |
| | { |
| | this->setButtonPosition(TaskMaterial::North); |
| | widget = new DlgMaterialImp(false); |
| | taskbox = new Gui::TaskView::TaskBox(QPixmap(), widget->windowTitle(), true, nullptr); |
| | taskbox->groupLayout()->addWidget(widget); |
| | Content.push_back(taskbox); |
| | } |
| |
|
| | TaskMaterial::~TaskMaterial() = default; |
| |
|
| | QDialogButtonBox::StandardButtons TaskMaterial::getStandardButtons() const |
| | { |
| | return QDialogButtonBox::Close; |
| | } |
| |
|
| | bool TaskMaterial::reject() |
| | { |
| | widget->reject(); |
| | return (widget->result() == QDialog::Rejected); |
| | } |
| |
|
| | #include "moc_DlgMaterialImp.cpp" |
| |
|