FreeCAD

Форк
0
/
Model.cpp 
140 строк · 4.4 Кб
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
#endif
26

27
#include <App/Application.h>
28

29
#include "Exceptions.h"
30
#include "Model.h"
31
#include "ModelLibrary.h"
32

33

34
using namespace Materials;
35

36
TYPESYSTEM_SOURCE(Materials::ModelProperty, Base::BaseClass)
37

38
ModelProperty::ModelProperty()
39
{}
40

41
ModelProperty::ModelProperty(const QString& name,
42
                             const QString& header,
43
                             const QString& type,
44
                             const QString& units,
45
                             const QString& url,
46
                             const QString& description)
47
    : _name(name)
48
    , _displayName(header)
49
    , _propertyType(type)
50
    , _units(units)
51
    , _url(url)
52
    , _description(description)
53
{}
54

55
ModelProperty::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
{
64
    for (auto it = other._columns.begin(); it != other._columns.end(); it++) {
65
        _columns.push_back(*it);
66
    }
67
}
68

69
const QString ModelProperty::getDisplayName() const
70
{
71
    if (_displayName.isEmpty()) {
72
        return getName();
73
    }
74
    return _displayName;
75
}
76

77
ModelProperty& ModelProperty::operator=(const ModelProperty& other)
78
{
79
    if (this == &other) {
80
        return *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();
91
    for (auto it = other._columns.begin(); it != other._columns.end(); it++) {
92
        _columns.push_back(*it);
93
    }
94

95
    return *this;
96
}
97

98
bool ModelProperty::operator==(const ModelProperty& other) const
99
{
100
    if (this == &other) {
101
        return true;
102
    }
103

104
    return (_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

109
TYPESYSTEM_SOURCE(Materials::Model, Base::BaseClass)
110

111
Model::Model()
112
{}
113

114
Model::Model(std::shared_ptr<ModelLibrary> library,
115
             ModelType type,
116
             const QString& name,
117
             const QString& directory,
118
             const QString& uuid,
119
             const QString& description,
120
             const QString& url,
121
             const 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

132
ModelProperty& Model::operator[](const QString& key)
133
{
134
    try {
135
        return _properties.at(key);
136
    }
137
    catch (std::out_of_range const&) {
138
        throw PropertyNotFound();
139
    }
140
}
141

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.