Material: Material API fixes

Corrects an issue in the API where a new material may not have a UUID.
Corrected the test case to reflect the changes and better document the
process.

Added a test case for material filters.
This commit is contained in:
David Carter
2024-05-13 22:41:54 -04:00
committed by Chris Hennes
parent b231bbb0ca
commit ed01d5cffa
13 changed files with 404 additions and 25 deletions

View File

@@ -108,3 +108,9 @@ void MaterialFilter::addRequiredComplete(const QString& uuid)
}
_requiredComplete.insert(uuid);
}
void MaterialFilter::clear()
{
_required.clear();
_requiredComplete.clear();
}

View File

@@ -184,6 +184,8 @@ public:
return &_requiredComplete;
}
void clear();
private:
QString _name;
QSet<QString> _required;

View File

@@ -448,7 +448,10 @@ Material::Material()
: _dereferenced(false)
, _oldFormat(false)
, _editState(ModelEdit_None)
{}
{
// Create an initial UUID
newUuid();
}
Material::Material(const std::shared_ptr<MaterialLibrary>& library,
const QString& directory,
@@ -1439,7 +1442,6 @@ void Material::save(QTextStream& stream, bool overwrite, bool saveAsCopy, bool s
if (materialManager.exists(_uuid) && !overwrite) {
// Make a new version based on the current
setParentUUID(_uuid);
// newUuid();
}
}

View File

@@ -297,23 +297,6 @@ fc_target_copy_resource(MaterialTest
${CMAKE_BINARY_DIR}/Mod/Material
${MaterialTest_Files})
set(MaterialTestData_Files
materialtests/Materials/TestAcrylicLegacy.FCMat
materialtests/Materials/TestAluminumAppearance.FCMat
materialtests/Materials/TestAluminumMixed.FCMat
materialtests/Materials/TestAluminumPhysical.FCMat
materialtests/Materials/TestBrassAppearance.FCMat
)
ADD_CUSTOM_TARGET(MaterialTestData ALL
SOURCES ${MaterialTestData_Files}
)
fc_target_copy_resource(MaterialTestData
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR}/Mod/Material
${MaterialTestData_Files})
ADD_CUSTOM_TARGET(MaterialScripts ALL
SOURCES ${MaterialScripts_Files} ${Material_Ui_Files} ${Material_QRC_SRCS}
)

View File

@@ -1,12 +0,0 @@
; Acrylic
; Automatically generated by the Rocket Workbench
; information about the content of such cards can be found on the wiki:
; https://www.freecadweb.org/wiki/Material
[General]
Name = TestAcrylicLegacy
Description = Acrylic
KindOfMaterial = Solid
[Mechanical]
Density = 1190.0 kg/m^3

View File

@@ -1,17 +0,0 @@
---
# File created by ConvertFCMat.py
General:
UUID: "3c6d0407-66b3-48ea-a2e8-ee843edf0311"
Author: "David Carter"
License: "GPL-2.0-or-later"
Name: "TestAluminumAppearance"
Description: "Defines the Aluminum appearance properties"
AppearanceModels:
BasicRendering:
UUID: 'f006c7e4-35b7-43d5-bbf9-c5d572309e6e'
AmbientColor: "(0.3000, 0.3000, 0.3000, 1.0)"
DiffuseColor: "(0.3000, 0.3000, 0.3000, 1.0)"
EmissiveColor: "(0.0000, 0.0000, 0.0000, 1.0)"
Shininess: "0.0900"
SpecularColor: "(0.3000, 0.3000, 0.3000, 1.0)"
Transparency: "0.0"

View File

@@ -1,33 +0,0 @@
---
# File created by ConvertFCMat.py
General:
UUID: "5f546608-fcbb-40db-98d7-d8e104eb33ce"
Author: "M. Münch"
License: "LGPL-2.0-or-later"
Name: "TestAluminumMixed"
Inherits:
Aluminum:
UUID: "3c6d0407-66b3-48ea-a2e8-ee843edf0311"
Models:
Father:
UUID: '9cdda8b6-b606-4778-8f13-3934d8668e67'
Father: "Metal"
MaterialStandard:
UUID: '1e2c0088-904a-4537-925f-64064c07d700'
KindOfMaterial: "Aluminium"
MaterialNumber: "3.3535.26"
StandardCode: "DIN 1725"
LinearElastic:
UUID: '7b561d1d-fb9b-44f6-9da9-56a4f74d7536'
Density: "2700 kg/m^3"
PoissonRatio: "0.3"
ShearModulus: "27000 MPa"
UltimateStrain: "5"
UltimateTensileStrength: "250 MPa"
YieldStrength: "180 MPa"
YoungsModulus: "70000 MPa"
Thermal:
UUID: '9959d007-a970-4ea7-bae4-3eb1b8b883c7'
SpecificHeat: "900 J/kg/K"
ThermalConductivity: "150 W/m/K"
ThermalExpansionCoefficient: "23 µm/m/K"

View File

@@ -1,30 +0,0 @@
---
# File created by ConvertFCMat.py
General:
UUID: "a8e60089-550d-4370-8e7e-1734db12a3a9"
Author: "M. Münch"
License: "LGPL-2.0-or-later"
Name: "TestAluminumPhysical"
Models:
Father:
UUID: '9cdda8b6-b606-4778-8f13-3934d8668e67'
Father: "Metal"
MaterialStandard:
UUID: '1e2c0088-904a-4537-925f-64064c07d700'
KindOfMaterial: "Aluminium"
MaterialNumber: "3.3535.26"
StandardCode: "DIN 1725"
LinearElastic:
UUID: '7b561d1d-fb9b-44f6-9da9-56a4f74d7536'
Density: "2700 kg/m^3"
PoissonRatio: "0.3"
ShearModulus: "27000 MPa"
UltimateStrain: "5"
UltimateTensileStrength: "250 MPa"
YieldStrength: "180 MPa"
YoungsModulus: "70000 MPa"
Thermal:
UUID: '9959d007-a970-4ea7-bae4-3eb1b8b883c7'
SpecificHeat: "900 J/kg/K"
ThermalConductivity: "150 W/m/K"
ThermalExpansionCoefficient: "23 µm/m/K"

View File

@@ -1,17 +0,0 @@
---
# File created by ConvertFCMat.py
General:
UUID: "fff3d5c8-98c3-4ee2-8fe5-7e17403c48fcc"
Author: "David Carter"
License: "GPL-2.0-or-later"
Name: "TestBrassAppearance"
Description: "Defines the Brass appearance properties"
AppearanceModels:
BasicRendering:
UUID: 'f006c7e4-35b7-43d5-bbf9-c5d572309e6e'
AmbientColor: "(0.3294, 0.2235, 0.0275, 1.0)"
DiffuseColor: "(0.7804, 0.5686, 0.1137, 1.0)"
EmissiveColor: "(0.0000, 0.0000, 0.0000, 1.0)"
Shininess: "0.2179"
SpecularColor: "(0.9922, 0.9412, 0.8078, 1.0)"
Transparency: "0.0"

View File

@@ -57,7 +57,7 @@ class MaterialCreationTestCases(unittest.TestCase):
def checkNewMaterial(self, material):
""" Check the state of a newly created material """
self.assertEqual(len(material.UUID), 0)
self.assertEqual(len(material.UUID), 36)
self.assertEqual(len(material.Name), 0)
self.assertEqual(len(material.Author), 0)
self.assertEqual(len(material.License), 0)
@@ -79,8 +79,9 @@ class MaterialCreationTestCases(unittest.TestCase):
material.URL = "https://www.example.com"
material.Reference = "ISBN 978-1673287882"
# UUID isn't valid until the file is saved
self.assertEqual(material.UUID, '')
# Ensure a valid UUID
self.assertEqual(len(material.UUID), 36)
uuid = material.UUID
self.assertEqual(material.Name, "Frankenstein")
self.assertEqual(material.Author, "Mary Shelley")
@@ -127,11 +128,24 @@ class MaterialCreationTestCases(unittest.TestCase):
self.assertEqual(material.getPhysicalValue("Density").UserString, parseQuantity("99.90 kg/m^3").UserString)
# MaterialManager is unaware of the material until it is saved
self.MaterialManager.save("User", material, "Example/Frakenstein.FCMat")
#
# When initially creating the material, setting overwrite=True preserves the UUID. This should not
# be used when saving after properties have been edited as this could adversely affect other
# documents or parts using the same material. Setting overwrite=False, or omitting it, will change
# the UUID. It will also fail if the material file already exists.
#
# Similarly, saveAsCopy=True preserves the UUID and should be used carefully. It will save an
# identical copy of the original but in a different location.
#
# The third optional parameter is saveInherited. When set to true it will mark models and properties
# as inherited without duplicating them. When false, they will be copied as uninherited. Avoid
# self-inheritance as this creates an invalid model. It will have a different UUID than the original.
#
self.MaterialManager.save("User", material, "Example/Frakenstein.FCMat", overwrite=True)
# Now the UUID is valid
uuid = material.UUID
self.assertEqual(len(material.UUID), 36)
self.assertEqual(material.UUID, uuid)
self.assertIn(uuid, self.MaterialManager.Materials)
self.assertIsNotNone(self.MaterialManager.getMaterialByPath("Example/Frakenstein.FCMat", "User"))
self.assertIsNotNone(self.MaterialManager.getMaterial(uuid))