FreeCAD

Форк
0
/
GeometryDefaultExtension.cpp 
158 строк · 5.8 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2019 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com>     *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24

25
#include <Base/Writer.h>
26
#include <Base/Reader.h>
27

28
#include "GeometryDefaultExtension.h"
29
#include "GeometryBoolExtensionPy.h"
30
#include "GeometryDoubleExtensionPy.h"
31
#include "GeometryIntExtensionPy.h"
32
#include "GeometryStringExtensionPy.h"
33

34

35
using namespace Part;
36

37
//---------- Geometry Extension
38
template <typename T>
39
GeometryDefaultExtension<T>::GeometryDefaultExtension(const T& val, std::string name):value(val)
40
{
41
    setName(name);
42
}
43

44

45
template <typename T>
46
void GeometryDefaultExtension<T>::copyAttributes(Part::GeometryExtension * cpy) const
47
{
48
    Part::GeometryPersistenceExtension::copyAttributes(cpy);
49
    static_cast<GeometryDefaultExtension<T> *>(cpy)->value = this->value;
50
}
51

52
template <typename T>
53
void GeometryDefaultExtension<T>::restoreAttributes(Base::XMLReader &reader)
54
{
55
    Part::GeometryPersistenceExtension::restoreAttributes(reader);
56

57
    value = reader.getAttribute("value");
58
}
59

60
template <typename T>
61
void GeometryDefaultExtension<T>::saveAttributes(Base::Writer &writer) const
62
{
63
    Part::GeometryPersistenceExtension::saveAttributes(writer);
64

65
    writer.Stream() << "\" value=\"" << value;
66
}
67

68
template <typename T>
69
std::unique_ptr<Part::GeometryExtension> GeometryDefaultExtension<T>::copy() const
70
{
71
    std::unique_ptr<GeometryDefaultExtension<T>> cpy = std::make_unique<GeometryDefaultExtension<T>>();
72

73
    copyAttributes(cpy.get());
74
    return cpy;
75
}
76

77
template <typename T>
78
PyObject * GeometryDefaultExtension<T>::getPyObject()
79
{
80
    THROWM(Base::NotImplementedError,"Python object not implemented for default geometry extension template type. Template Specialisation missing."); // use template specialisation to provide the actual object
81
}
82

83
namespace Part {
84
// ----------------------------- Template specialisations----------------------------------------------------
85

86
//using GeometryIntExtension = Part::GeometryDefaultExtension<long>;
87
//using GeometryStringExtension = Part::GeometryStringExtension<std::string>;
88

89
// ---------- GeometryIntExtension ----------
90
TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryIntExtension,Part::GeometryPersistenceExtension)
91

92
template <>
93
PyObject * GeometryDefaultExtension<long>::getPyObject()
94
{
95
    return new GeometryIntExtensionPy(new GeometryIntExtension(*this));
96
}
97

98
template <>
99
void GeometryDefaultExtension<long>::restoreAttributes(Base::XMLReader &reader)
100
{
101
    Part::GeometryPersistenceExtension::restoreAttributes(reader);
102

103
    value = reader.getAttributeAsInteger("value");
104
}
105

106
// ---------- GeometryStringExtension ----------
107
TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryStringExtension,Part::GeometryPersistenceExtension)
108

109
template <>
110
PyObject * GeometryDefaultExtension<std::string>::getPyObject()
111
{
112
    return new GeometryStringExtensionPy(new GeometryStringExtension(*this));
113
}
114

115
// ---------- GeometryBoolExtension ----------
116
TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryBoolExtension,Part::GeometryPersistenceExtension)
117

118
template <>
119
PyObject * GeometryDefaultExtension<bool>::getPyObject()
120
{
121
    return new GeometryBoolExtensionPy(new GeometryBoolExtension(*this));
122
}
123

124
template <>
125
void GeometryDefaultExtension<bool>::restoreAttributes(Base::XMLReader &reader)
126
{
127
    Part::GeometryPersistenceExtension::restoreAttributes(reader);
128

129
    value = (bool)reader.getAttributeAsInteger("value");
130
}
131

132
// ---------- GeometryDoubleExtension ----------
133
TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryDoubleExtension,Part::GeometryPersistenceExtension)
134

135
template <>
136
PyObject * GeometryDefaultExtension<double>::getPyObject()
137
{
138
    return new GeometryDoubleExtensionPy(new GeometryDoubleExtension(*this));
139
}
140

141
template <>
142
void GeometryDefaultExtension<double>::restoreAttributes(Base::XMLReader &reader)
143
{
144
    Part::GeometryPersistenceExtension::restoreAttributes(reader);
145

146
    value = reader.getAttributeAsFloat("value");
147
}
148

149

150
// instantiate the types so that other translation units (python wrappers) can access template
151
//constructors other than the default.
152
template class GeometryDefaultExtension<long>;
153
template class GeometryDefaultExtension<std::string>;
154
template class GeometryDefaultExtension<bool>;
155
template class GeometryDefaultExtension<double>;
156

157

158
} //namespace Part
159

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

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

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

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