FreeCAD
1/***************************************************************************
2* Copyright (c) 2023 David Carter <dcarter@david.carter.ca> *
3* *
4* This file is part of FreeCAD. *
5* *
6* FreeCAD is free software: you can redistribute it and/or modify it *
7* under the terms of the GNU Lesser General Public License as *
8* published by the Free Software Foundation, either version 2.1 of the *
9* License, or (at your option) any later version. *
10* *
11* FreeCAD is distributed in the hope that it will be useful, but *
12* WITHOUT ANY WARRANTY; without even the implied warranty of *
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14* Lesser General Public License for more details. *
15* *
16* You should have received a copy of the GNU Lesser General Public *
17* License along with FreeCAD. If not, see *
18* <https://www.gnu.org/licenses/>. *
19* *
20**************************************************************************/
21
22#include "PreCompiled.h"23#ifndef _PreComp_24#include <string>25#endif26
27#include <App/Application.h>28
29#include "Exceptions.h"30#include "Model.h"31#include "ModelLibrary.h"32
33
34using namespace Materials;35
36TYPESYSTEM_SOURCE(Materials::ModelProperty, Base::BaseClass)37
38ModelProperty::ModelProperty()39{}40
41ModelProperty::ModelProperty(const QString& name,42const QString& header,43const QString& type,44const QString& units,45const QString& url,46const QString& description)47: _name(name)48, _displayName(header)49, _propertyType(type)50, _units(units)51, _url(url)52, _description(description)53{}54
55ModelProperty::ModelProperty(const ModelProperty& other)56: _name(other._name)57, _displayName(other._displayName)58, _propertyType(other._propertyType)59, _units(other._units)60, _url(other._url)61, _description(other._description)62, _inheritance(other._inheritance)63{
64for (auto it = other._columns.begin(); it != other._columns.end(); it++) {65_columns.push_back(*it);66}67}
68
69const QString ModelProperty::getDisplayName() const70{
71if (_displayName.isEmpty()) {72return getName();73}74return _displayName;75}
76
77ModelProperty& ModelProperty::operator=(const ModelProperty& other)78{
79if (this == &other) {80return *this;81}82
83_name = other._name;84_displayName = other._displayName;85_propertyType = other._propertyType;86_units = other._units;87_url = other._url;88_description = other._description;89_inheritance = other._inheritance;90_columns.clear();91for (auto it = other._columns.begin(); it != other._columns.end(); it++) {92_columns.push_back(*it);93}94
95return *this;96}
97
98bool ModelProperty::operator==(const ModelProperty& other) const99{
100if (this == &other) {101return true;102}103
104return (_name == other._name) && (_displayName == other._displayName) && (_propertyType == other._propertyType)105&& (_units == other._units) && (_url == other._url) && (_description == other._description)106&& (_inheritance == other._inheritance);107}
108
109TYPESYSTEM_SOURCE(Materials::Model, Base::BaseClass)110
111Model::Model()112{}113
114Model::Model(std::shared_ptr<ModelLibrary> library,115ModelType type,116const QString& name,117const QString& directory,118const QString& uuid,119const QString& description,120const QString& url,121const QString& doi)122: _library(library)123, _type(type)124, _name(name)125, _directory(directory)126, _uuid(uuid)127, _description(description)128, _url(url)129, _doi(doi)130{}131
132ModelProperty& Model::operator[](const QString& key)133{
134try {135return _properties.at(key);136}137catch (std::out_of_range const&) {138throw PropertyNotFound();139}140}
141