Material: Material handling enhancements

Rework of the material handling system.

This first part concntrates on a rework of the material cards.
Rather than use a fixed list of possible properties, properties can
be defined separately in their own files and mixed to provide a
complete list of possible properties. Properties can be inherited.

The cards then provide values for the properties. These can also
be inherited allowing for small changes in cards as required.

The new property definitions are more extensive than previously.
2 and 3 dimensional arrays of properties can be defined. Values
are obtained by calling an API instead of reading from a dictionary.

For compatibility, a Python dictionary of values can be obtained
similar to how it was done previously, but this is considered a
deprecated API and won't support the newer advanced features.

The editor is completely reworked. It will be able to edit older format
material cards, but can only save them in the new format.

For testing during the development phase, a system preference can
specifiy wether the old or new material editors are to be used. This
option will be removed before release.
This commit is contained in:
David Carter
2023-09-14 22:52:48 -04:00
parent 6b0c054023
commit 902af79514
397 changed files with 19222 additions and 4312 deletions

View File

@@ -0,0 +1,297 @@
/***************************************************************************
* Copyright (c) 2023 David Carter <dcarter@david.carter.ca> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library 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 this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef MATERIAL_MODEL_H
#define MATERIAL_MODEL_H
#include <Base/BaseClass.h>
#include <Base/Quantity.h>
#include <QDir>
#include <QString>
#include "MaterialValue.h"
#include "ModelLibrary.h"
namespace Materials
{
class MaterialsExport ModelProperty: public Base::BaseClass
{
TYPESYSTEM_HEADER();
public:
ModelProperty();
explicit ModelProperty(const QString& name,
const QString& type,
const QString& units,
const QString& url,
const QString& description);
explicit ModelProperty(const ModelProperty& other);
virtual ~ModelProperty() = default;
const QString getName() const
{
return _name;
}
const QString getPropertyType() const
{
return _propertyType;
}
const QString getUnits() const
{
return _units;
}
const QString getURL() const
{
return _url;
}
const QString getDescription() const
{
return _description;
}
const QString getInheritance() const
{
return _inheritance;
}
bool isInherited() const
{
return (_inheritance.length() > 0);
}
void setName(const QString& name)
{
_name = name;
}
virtual void setPropertyType(const QString& type)
{
_propertyType = type;
}
void setUnits(const QString& units)
{
_units = units;
}
void setURL(const QString& url)
{
_url = url;
}
void setDescription(const QString& description)
{
_description = description;
}
void setInheritance(const QString& uuid)
{
_inheritance = uuid;
}
void addColumn(ModelProperty& column)
{
_columns.push_back(column);
}
const std::vector<ModelProperty>& getColumns() const
{
return _columns;
}
int columns() const
{
return _columns.size();
}
ModelProperty& operator=(const ModelProperty& other);
private:
QString _name;
QString _propertyType;
QString _units;
QString _url;
QString _description;
QString _inheritance;
std::vector<ModelProperty> _columns;
};
class MaterialsExport Model: public Base::BaseClass
{
TYPESYSTEM_HEADER();
public:
enum ModelType
{
ModelType_Physical,
ModelType_Appearance
};
Model();
explicit Model(const ModelLibrary& library,
ModelType type,
const QString& name,
const QString& directory,
const QString& uuid,
const QString& description,
const QString& url,
const QString& doi);
virtual ~Model() = default;
const ModelLibrary& getLibrary() const
{
return _library;
}
const QString getBase() const
{
return (_type == ModelType_Physical) ? QString::fromStdString("Model")
: QString::fromStdString("AppearanceModel");
}
const QString getName() const
{
return _name;
}
ModelType getType() const
{
return _type;
}
const QString getDirectory() const
{
return _directory;
}
const QString getDirectoryPath() const
{
return QDir(_directory).absolutePath();
}
const QString getRelativePath() const
{
return QDir(_directory).relativeFilePath(QDir(_directory).absolutePath());
}
const QString getUUID() const
{
return _uuid;
}
const QString getDescription() const
{
return _description;
}
const QString getURL() const
{
return _url;
}
const QString getDOI() const
{
return _doi;
}
void setLibrary(const ModelLibrary& library)
{
_library = library;
}
void setType(ModelType type)
{
_type = type;
}
void setName(const QString& name)
{
_name = name;
}
void setDirectory(const QString& directory)
{
_directory = directory;
}
void setUUID(const QString& uuid)
{
_uuid = uuid;
}
void setDescription(const QString& description)
{
_description = description;
}
void setURL(const QString& url)
{
_url = url;
}
void setDOI(const QString& doi)
{
_doi = doi;
}
void addInheritance(const QString& uuid)
{
_inheritedUuids.push_back(uuid);
}
const std::vector<QString>& getInheritance() const
{
return _inheritedUuids;
}
bool operator==(const Model& m) const
{
return _uuid == m._uuid;
}
bool operator!=(const Model& m) const
{
return !operator==(m);
}
ModelProperty& operator[](const QString& key);
void addProperty(ModelProperty& property)
{
_properties[property.getName()] = property;
}
using iterator = typename std::map<QString, ModelProperty>::iterator;
using const_iterator = typename std::map<QString, ModelProperty>::const_iterator;
iterator begin()
{
return _properties.begin();
}
const_iterator begin() const noexcept
{
return _properties.begin();
}
iterator end() noexcept
{
return _properties.end();
}
const_iterator end() const noexcept
{
return _properties.end();
}
const_iterator cbegin() const noexcept
{
return _properties.cbegin();
}
const_iterator cend() const noexcept
{
return _properties.cend();
}
private:
ModelLibrary _library;
ModelType _type;
QString _name;
QString _directory;
QString _uuid;
QString _description;
QString _url;
QString _doi;
std::vector<QString> _inheritedUuids;
std::map<QString, ModelProperty> _properties;
};
}// namespace Materials
#endif// MATERIAL_MODEL_H