Material: fixes several issues

* fix warning -Wunused-variable
* fix warning -Wreorder-ctor
* fix warning -Wunused-but-set-variable
* fix uic warning for DlgDisplayProperties.ui
* rename the target MateriaTestLib ALL (note the typo and the already existing MaterialTestLib ALL) to MaterialTest ALL
  drop the hard dependency to the Part module: The document is checked for a property ShapeMaterial of type Materials::PropertyMaterial.
  An alternative could be to cast to GeoFeature and use the methods getMaterialAppearance() and setMaterialAppearance()
This commit is contained in:
wmayer
2024-04-05 00:06:28 +02:00
committed by wwmayer
parent 7a44179529
commit d5cfdb1f1e
7 changed files with 15 additions and 19 deletions

View File

@@ -286,11 +286,11 @@ set(MaterialTest_Files
materialtests/TestMaterials.py
)
ADD_CUSTOM_TARGET(MateriaTestLib ALL
ADD_CUSTOM_TARGET(MaterialTest ALL
SOURCES ${MaterialTest_Files}
)
fc_target_copy_resource(MateriaTestLib
fc_target_copy_resource(MaterialTest
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR}/Mod/Material
${MaterialTest_Files})

View File

@@ -21,7 +21,6 @@ link_directories(${OCC_LIBRARY_DIR})
set(MatGui_LIBS
Materials
FreeCADGui
Part
)
include_directories(

View File

@@ -105,7 +105,7 @@
<property name="title">
<string>Display</string>
</property>
<layout class="QGridLayout">
<layout class="QGridLayout" name="gridLayout1">
<property name="leftMargin">
<number>9</number>
</property>

View File

@@ -335,7 +335,7 @@ void DlgDisplayPropertiesImp::slotChangedObject(const Gui::ViewProvider& obj,
}
}
else if (prop.isDerivedFrom<App::PropertyMaterialList>()) {
auto& value = static_cast<const App::PropertyMaterialList&>(prop).getValue();
//auto& value = static_cast<const App::PropertyMaterialList&>(prop).getValue();
if (prop_name == "ShapeAppearance") {
// bool blocked = d->ui.buttonColor->blockSignals(true);
// auto color = value.diffuseColor;
@@ -566,12 +566,12 @@ void DlgDisplayPropertiesImp::setDisplayModes(const std::vector<Gui::ViewProvide
void DlgDisplayPropertiesImp::setMaterial(const std::vector<Gui::ViewProvider*>& views)
{
bool material = false;
App::Material::MaterialType matType = App::Material::DEFAULT;
//App::Material::MaterialType matType = App::Material::DEFAULT;
for (auto view : views) {
if (auto* prop =
dynamic_cast<App::PropertyMaterial*>(view->getPropertyByName("ShapeMaterial"))) {
material = true;
matType = prop->getValue().getType();
// matType = prop->getValue().getType();
break;
}
}

View File

@@ -41,7 +41,7 @@
#include <Mod/Material/App/Exceptions.h>
#include <Mod/Material/App/MaterialManager.h>
#include <Mod/Material/App/ModelUuids.h>
#include <Mod/Part/App/PartFeature.h>
#include <Mod/Material/App/PropertyMaterial.h>
#include "DlgMaterialImp.h"
#include "ui_DlgMaterial.h"
@@ -171,7 +171,7 @@ void DlgMaterialImp::slotChangedObject(const Gui::ViewProvider& obj, const App::
}
std::string prop_name = name;
if (prop.isDerivedFrom<App::PropertyMaterial>()) {
auto& value = static_cast<const App::PropertyMaterial&>(prop).getValue();
//auto& value = static_cast<const App::PropertyMaterial&>(prop).getValue();
if (prop_name == "ShapeMaterial") {
// bool blocked = d->ui.buttonColor->blockSignals(true);
// auto color = value.diffuseColor;
@@ -200,10 +200,9 @@ void DlgMaterialImp::reject()
void DlgMaterialImp::setMaterial(const std::vector<App::DocumentObject*>& objects)
{
for (auto it : objects) {
if (auto* obj = dynamic_cast<Part::Feature*>(it)) {
auto material = obj->ShapeMaterial.getValue();
if (auto prop = dynamic_cast<Materials::PropertyMaterial*>(it->getPropertyByName("ShapeMaterial"))) {
try {
std::string mat = material.getUUID().toStdString();
const auto& material = prop->getValue();
d->ui.widgetMaterial->setMaterial(material.getUUID());
return;
}
@@ -244,11 +243,10 @@ std::vector<App::DocumentObject*> DlgMaterialImp::getSelectionObjects() const
void DlgMaterialImp::onMaterialSelected(const std::shared_ptr<Materials::Material>& material)
{
std::string mat = material->getUUID().toStdString();
std::vector<App::DocumentObject*> objects = getSelectionObjects();
for (auto it : objects) {
if (auto* obj = dynamic_cast<Part::Feature*>(it)) {
obj->ShapeMaterial.setValue(*material);
if (auto prop = dynamic_cast<Materials::PropertyMaterial*>(it->getPropertyByName("ShapeMaterial"))) {
prop->setValue(*material);
}
}
}

View File

@@ -195,7 +195,6 @@ bool MaterialTreeWidget::findInTree(const QStandardItem& node,
}
if (node.hasChildren()) {
int rows = node.rowCount();
for (int i = 0; i < node.rowCount(); i++) {
auto child = node.child(i);
if (findInTree(*child, index, uuid)) {
@@ -458,4 +457,4 @@ void MaterialTreeWidget::onDoubleClick(const QModelIndex& index)
auto uuid = item->data(Qt::UserRole).toString();
updateMaterial(uuid);
}
}
}

View File

@@ -63,8 +63,8 @@ MaterialsEditor::MaterialsEditor(std::shared_ptr<Materials::MaterialFilter> filt
: QDialog(parent)
, ui(new Ui_MaterialsEditor)
, _material(std::make_shared<Materials::Material>())
, _materialSelected(false)
, _rendered(nullptr)
, _materialSelected(false)
, _recentMax(0)
, _filter(filter)
{
@@ -75,8 +75,8 @@ MaterialsEditor::MaterialsEditor(QWidget* parent)
: QDialog(parent)
, ui(new Ui_MaterialsEditor)
, _material(std::make_shared<Materials::Material>())
, _materialSelected(false)
, _rendered(nullptr)
, _materialSelected(false)
, _recentMax(0)
, _filter(nullptr)
{