Materials: Editor UI enhancements
When creating a new material, assigning the basic rendering model to the material resulted in an all black color. This will now be assigned the default color as specified in the preferences. The name of the material Properties tab has been changed to Physical for improved consistency in the user interface.
This commit is contained in:
committed by
Chris Hennes
parent
b057e6eb74
commit
7d3f6e2ad1
@@ -138,10 +138,8 @@ bool MaterialManager::isMaterial(const QFileInfo& file) const
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<Material> MaterialManager::defaultMaterial()
|
||||
std::shared_ptr<App::Material> MaterialManager::defaultAppearance()
|
||||
{
|
||||
MaterialManager manager;
|
||||
|
||||
ParameterGrp::handle hGrp =
|
||||
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
|
||||
|
||||
@@ -149,8 +147,9 @@ std::shared_ptr<Material> MaterialManager::defaultMaterial()
|
||||
uint32_t packed = color.getPackedRGB();
|
||||
packed = hGrp->GetUnsigned(parameter, packed);
|
||||
color.setPackedRGB(packed);
|
||||
color.a = 1.0; // The default color sets fully transparent, not opaque
|
||||
};
|
||||
auto intRandom = [] (int min, int max) -> int {
|
||||
auto intRandom = [](int min, int max) -> int {
|
||||
static std::mt19937 generator;
|
||||
std::uniform_int_distribution<int> distribution(min, max);
|
||||
return distribution(generator);
|
||||
@@ -163,7 +162,7 @@ std::shared_ptr<Material> MaterialManager::defaultMaterial()
|
||||
float red = static_cast<float>(intRandom(0, 255)) / 255.0F;
|
||||
float green = static_cast<float>(intRandom(0, 255)) / 255.0F;
|
||||
float blue = static_cast<float>(intRandom(0, 255)) / 255.0F;
|
||||
mat.diffuseColor = App::Color(red, green, blue);
|
||||
mat.diffuseColor = App::Color(red, green, blue, 1.0);
|
||||
}
|
||||
else {
|
||||
getColor("DefaultShapeColor", mat.diffuseColor);
|
||||
@@ -175,24 +174,34 @@ std::shared_ptr<Material> MaterialManager::defaultMaterial()
|
||||
|
||||
long initialTransparency = hGrp->GetInt("DefaultShapeTransparency", 0);
|
||||
long initialShininess = hGrp->GetInt("DefaultShapeShininess", 90);
|
||||
mat.shininess = ((float)initialShininess / 100.0F);
|
||||
mat.transparency = ((float)initialTransparency / 100.0F);
|
||||
|
||||
return std::make_shared<App::Material>(mat);
|
||||
}
|
||||
|
||||
std::shared_ptr<Material> MaterialManager::defaultMaterial()
|
||||
{
|
||||
MaterialManager manager;
|
||||
|
||||
auto mat = defaultAppearance();
|
||||
auto material = manager.getMaterial(defaultMaterialUUID());
|
||||
if (!material) {
|
||||
material = manager.getMaterial(QLatin1String("7f9fd73b-50c9-41d8-b7b2-575a030c1eeb"));
|
||||
}
|
||||
if (material->hasAppearanceModel(ModelUUIDs::ModelUUID_Rendering_Basic)) {
|
||||
material->getAppearanceProperty(QString::fromLatin1("DiffuseColor"))
|
||||
->setColor(mat.diffuseColor);
|
||||
->setColor(mat->diffuseColor);
|
||||
material->getAppearanceProperty(QString::fromLatin1("AmbientColor"))
|
||||
->setColor(mat.ambientColor);
|
||||
->setColor(mat->ambientColor);
|
||||
material->getAppearanceProperty(QString::fromLatin1("EmissiveColor"))
|
||||
->setColor(mat.emissiveColor);
|
||||
->setColor(mat->emissiveColor);
|
||||
material->getAppearanceProperty(QString::fromLatin1("SpecularColor"))
|
||||
->setColor(mat.specularColor);
|
||||
->setColor(mat->specularColor);
|
||||
material->getAppearanceProperty(QString::fromLatin1("Transparency"))
|
||||
->setFloat((float)initialTransparency / 100.0F);
|
||||
->setFloat(mat->transparency);
|
||||
material->getAppearanceProperty(QString::fromLatin1("Shininess"))
|
||||
->setFloat((float)initialShininess / 100.0F);
|
||||
->setFloat(mat->shininess);
|
||||
}
|
||||
|
||||
return material;
|
||||
|
||||
@@ -56,6 +56,7 @@ public:
|
||||
|
||||
static void cleanup();
|
||||
static void refresh();
|
||||
static std::shared_ptr<App::Material> defaultAppearance();
|
||||
static std::shared_ptr<Material> defaultMaterial();
|
||||
static QString defaultMaterialUUID();
|
||||
|
||||
|
||||
@@ -169,15 +169,12 @@ PyObject* MaterialTreeWidgetPy::setFilter(PyObject* args)
|
||||
}
|
||||
if (PyObject_TypeCheck(obj, &(Materials::MaterialFilterPy::Type))) {
|
||||
auto filter = static_cast<Materials::MaterialFilterPy*>(obj)->getMaterialFilterPtr();
|
||||
Base::Console().Log("Filter '%s'\n", filter->name().toStdString().c_str());
|
||||
auto filterPtr = std::make_shared<Materials::MaterialFilter>(*filter);
|
||||
getMaterialTreeWidgetPtr()->setFilter(filterPtr);
|
||||
}
|
||||
else if (PyList_Check(obj)) {
|
||||
// The argument is a list of filters
|
||||
Base::Console().Log("Filter List\n");
|
||||
Py_ssize_t n = PyList_Size(obj);
|
||||
Base::Console().Log("n = %d\n", n);
|
||||
if (n < 0) {
|
||||
Py_Return;
|
||||
}
|
||||
@@ -188,13 +185,8 @@ PyObject* MaterialTreeWidgetPy::setFilter(PyObject* args)
|
||||
if (PyObject_TypeCheck(item, &(Materials::MaterialFilterPy::Type))) {
|
||||
auto filter =
|
||||
static_cast<Materials::MaterialFilterPy*>(item)->getMaterialFilterPtr();
|
||||
Base::Console().Log("\tFilter '%s'\n",
|
||||
filter->name().toStdString().c_str()); auto filterPtr =
|
||||
std::make_shared<Materials::MaterialFilter>(*filter);
|
||||
auto filterPtr = std::make_shared<Materials::MaterialFilter>(*filter);
|
||||
filterList->push_back(filterPtr);
|
||||
// getMaterialTreeWidgetPtr()->setFilter(
|
||||
//
|
||||
// *static_cast<Materials::MaterialFilterPy*>(obj)->getMaterialFilterPtr());
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
@@ -222,8 +214,6 @@ PyObject* MaterialTreeWidgetPy::selectFilter(PyObject* args)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Base::Console().Log("selectFilter(%s)\n", name);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
|
||||
#include <Mod/Material/App/Exceptions.h>
|
||||
#include <Mod/Material/App/ModelManager.h>
|
||||
#include <Mod/Material/App/ModelUuids.h>
|
||||
|
||||
#include "MaterialDelegate.h"
|
||||
#include "MaterialSave.h"
|
||||
@@ -425,6 +426,13 @@ void MaterialsEditor::onAppearanceAdd(bool checked)
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
QString selected = dialog.selectedModel();
|
||||
_material->addAppearance(selected);
|
||||
auto model = getModelManager().getModel(selected);
|
||||
if (selected == Materials::ModelUUIDs::ModelUUID_Rendering_Basic
|
||||
|| model->inherits(Materials::ModelUUIDs::ModelUUID_Rendering_Basic)) {
|
||||
// Add default appearance properties
|
||||
*_material = *(getMaterialManager().defaultAppearance());
|
||||
}
|
||||
|
||||
updateMaterial();
|
||||
}
|
||||
else {
|
||||
@@ -1008,6 +1016,7 @@ void MaterialsEditor::updateMaterialAppearance()
|
||||
auto valueItem = new QStandardItem(_material->getAppearanceValueString(key));
|
||||
valueItem->setToolTip(itp->second.getDescription());
|
||||
QVariant variant;
|
||||
// variant.setValue(_material->getAppearanceValueString(key));
|
||||
variant.setValue(_material);
|
||||
valueItem->setData(variant);
|
||||
items.append(valueItem);
|
||||
|
||||
@@ -209,7 +209,7 @@
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabProperties">
|
||||
<attribute name="title">
|
||||
<string>Properties</string>
|
||||
<string>Physical</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_43">
|
||||
<item>
|
||||
|
||||
@@ -41,14 +41,18 @@ class ColorTransparencyTest(unittest.TestCase):
|
||||
|
||||
"""
|
||||
This test isn't currently valid as it draws from the hard coded default material.
|
||||
|
||||
The preference editor doesn't allow for setting transparencies. The default value
|
||||
of 0 corresponds to a fully transparent color, which is not desireable. It changes
|
||||
the transparency when loading to 1.0
|
||||
"""
|
||||
|
||||
self._pg.SetUnsigned('DefaultShapeColor', 0xff000000) # red
|
||||
obj = self._doc.addObject('Part::Box')
|
||||
|
||||
self.assertEqual(obj.ViewObject.ShapeAppearance[0].DiffuseColor, (1.0, 0.0, 0.0, 0.0),
|
||||
self.assertEqual(obj.ViewObject.ShapeAppearance[0].DiffuseColor, (1.0, 0.0, 0.0, 1.0),
|
||||
'default shape color was not set correctly')
|
||||
self.assertEqual(obj.ViewObject.ShapeMaterial.DiffuseColor, (1.0, 0.0, 0.0, 0.0),
|
||||
self.assertEqual(obj.ViewObject.ShapeMaterial.DiffuseColor, (1.0, 0.0, 0.0, 1.0),
|
||||
'default material color was not set correctly')
|
||||
|
||||
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
# **************************************************************************
|
||||
# Copyright (c) 2023 David Carter <dcarter@davidcarter.ca> *
|
||||
# *
|
||||
# This file is part of the FreeCAD CAx development system. *
|
||||
# *
|
||||
# This program is free software; you can redistribute it and/or modify *
|
||||
# it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
# as published by the Free Software Foundation; either version 2 of *
|
||||
# the License, or (at your option) any later version. *
|
||||
# for detail see the LICENCE text file. *
|
||||
# *
|
||||
# FreeCAD is distributed in the hope that it will be useful, *
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# GNU Library General Public License for more details. *
|
||||
# *
|
||||
# You should have received a copy of the GNU Library General Public *
|
||||
# License along with FreeCAD; if not, write to the Free Software *
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# USA *
|
||||
# **************************************************************************
|
||||
|
||||
"""
|
||||
Test module for FreeCAD material cards and APIs
|
||||
"""
|
||||
import os
|
||||
|
||||
import unittest
|
||||
import FreeCAD
|
||||
import Materials
|
||||
|
||||
parseQuantity = FreeCAD.Units.parseQuantity
|
||||
|
||||
UUIDAcrylicLegacy = "" # This can't be known until it is loaded
|
||||
UUIDAluminumAppearance = "3c6d0407-66b3-48ea-a2e8-ee843edf0311"
|
||||
UUIDAluminumMixed = "5f546608-fcbb-40db-98d7-d8e104eb33ce"
|
||||
UUIDAluminumPhysical = "a8e60089-550d-4370-8e7e-1734db12a3a9"
|
||||
UUIDBrassAppearance = "fff3d5c8-98c3-4ee2-8fe5-7e17403c48fcc"
|
||||
|
||||
|
||||
class MaterialFilterTestCases(unittest.TestCase):
|
||||
"""
|
||||
Test class for FreeCAD material cards and APIs
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
"""Setup function to initialize test data"""
|
||||
self.ModelManager = Materials.ModelManager()
|
||||
self.MaterialManager = Materials.MaterialManager()
|
||||
self.uuids = Materials.UUIDs()
|
||||
|
||||
# Use our test files as a custom directory
|
||||
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Material/Resources")
|
||||
self.customDir = param.GetString("CustomMaterialsDir", "")
|
||||
self.useBuiltInDir = param.GetBool("UseBuiltInMaterials", False)
|
||||
self.useWorkbenchDir = param.GetBool("UseMaterialsFromWorkbenches", False)
|
||||
self.useUserDir = param.GetBool("UseMaterialsFromConfigDir", False)
|
||||
self.useCustomDir = param.GetBool("UseMaterialsFromCustomDir", False)
|
||||
|
||||
filePath = os.path.dirname(__file__) + os.sep
|
||||
testPath = filePath + "Materials"
|
||||
param.SetString("CustomMaterialsDir", testPath)
|
||||
param.SetBool("UseBuiltInMaterials", False)
|
||||
param.SetBool("UseMaterialsFromWorkbenches", False)
|
||||
param.SetBool("UseMaterialsFromConfigDir", False)
|
||||
param.SetBool("UseMaterialsFromCustomDir", True)
|
||||
|
||||
self.MaterialManager.refresh()
|
||||
|
||||
def tearDown(self):
|
||||
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Material/Resources")
|
||||
|
||||
# Restore preferences
|
||||
param.SetString("CustomMaterialsDir", self.customDir)
|
||||
param.SetBool("UseBuiltInMaterials", self.useBuiltInDir)
|
||||
param.SetBool("UseMaterialsFromWorkbenches", self.useWorkbenchDir)
|
||||
param.SetBool("UseMaterialsFromConfigDir", self.useUserDir)
|
||||
param.SetBool("UseMaterialsFromCustomDir", self.useCustomDir)
|
||||
|
||||
self.MaterialManager.refresh()
|
||||
|
||||
def testFilter(self):
|
||||
"""Test that our filter returns the correct materials"""
|
||||
|
||||
# First check that our materials are loading
|
||||
material = self.MaterialManager.getMaterial(UUIDAluminumAppearance)
|
||||
self.assertIsNotNone(material)
|
||||
self.assertEqual(material.Name, "TestAluminumAppearance")
|
||||
self.assertEqual(material.UUID, UUIDAluminumAppearance)
|
||||
|
||||
material = self.MaterialManager.getMaterial(UUIDAluminumMixed)
|
||||
self.assertIsNotNone(material)
|
||||
self.assertEqual(material.Name, "TestAluminumMixed")
|
||||
self.assertEqual(material.UUID, UUIDAluminumMixed)
|
||||
|
||||
material = self.MaterialManager.getMaterial(UUIDAluminumPhysical)
|
||||
self.assertIsNotNone(material)
|
||||
self.assertEqual(material.Name, "TestAluminumPhysical")
|
||||
self.assertEqual(material.UUID, UUIDAluminumPhysical)
|
||||
|
||||
material = self.MaterialManager.getMaterial(UUIDBrassAppearance)
|
||||
self.assertIsNotNone(material)
|
||||
self.assertEqual(material.Name, "TestBrassAppearance")
|
||||
self.assertEqual(material.UUID, UUIDBrassAppearance)
|
||||
Reference in New Issue
Block a user