1
/***************************************************************************
2
* Copyright (c) 2019 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com> *
4
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
#include <Base/Writer.h>
26
#include <Base/Reader.h>
28
#include "GeometryDefaultExtension.h"
29
#include "GeometryBoolExtensionPy.h"
30
#include "GeometryDoubleExtensionPy.h"
31
#include "GeometryIntExtensionPy.h"
32
#include "GeometryStringExtensionPy.h"
37
//---------- Geometry Extension
39
GeometryDefaultExtension<T>::GeometryDefaultExtension(const T& val, std::string name):value(val)
46
void GeometryDefaultExtension<T>::copyAttributes(Part::GeometryExtension * cpy) const
48
Part::GeometryPersistenceExtension::copyAttributes(cpy);
49
static_cast<GeometryDefaultExtension<T> *>(cpy)->value = this->value;
53
void GeometryDefaultExtension<T>::restoreAttributes(Base::XMLReader &reader)
55
Part::GeometryPersistenceExtension::restoreAttributes(reader);
57
value = reader.getAttribute("value");
61
void GeometryDefaultExtension<T>::saveAttributes(Base::Writer &writer) const
63
Part::GeometryPersistenceExtension::saveAttributes(writer);
65
writer.Stream() << "\" value=\"" << value;
69
std::unique_ptr<Part::GeometryExtension> GeometryDefaultExtension<T>::copy() const
71
std::unique_ptr<GeometryDefaultExtension<T>> cpy = std::make_unique<GeometryDefaultExtension<T>>();
73
copyAttributes(cpy.get());
78
PyObject * GeometryDefaultExtension<T>::getPyObject()
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
84
// ----------------------------- Template specialisations----------------------------------------------------
86
//using GeometryIntExtension = Part::GeometryDefaultExtension<long>;
87
//using GeometryStringExtension = Part::GeometryStringExtension<std::string>;
89
// ---------- GeometryIntExtension ----------
90
TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryIntExtension,Part::GeometryPersistenceExtension)
93
PyObject * GeometryDefaultExtension<long>::getPyObject()
95
return new GeometryIntExtensionPy(new GeometryIntExtension(*this));
99
void GeometryDefaultExtension<long>::restoreAttributes(Base::XMLReader &reader)
101
Part::GeometryPersistenceExtension::restoreAttributes(reader);
103
value = reader.getAttributeAsInteger("value");
106
// ---------- GeometryStringExtension ----------
107
TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryStringExtension,Part::GeometryPersistenceExtension)
110
PyObject * GeometryDefaultExtension<std::string>::getPyObject()
112
return new GeometryStringExtensionPy(new GeometryStringExtension(*this));
115
// ---------- GeometryBoolExtension ----------
116
TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryBoolExtension,Part::GeometryPersistenceExtension)
119
PyObject * GeometryDefaultExtension<bool>::getPyObject()
121
return new GeometryBoolExtensionPy(new GeometryBoolExtension(*this));
125
void GeometryDefaultExtension<bool>::restoreAttributes(Base::XMLReader &reader)
127
Part::GeometryPersistenceExtension::restoreAttributes(reader);
129
value = (bool)reader.getAttributeAsInteger("value");
132
// ---------- GeometryDoubleExtension ----------
133
TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryDoubleExtension,Part::GeometryPersistenceExtension)
136
PyObject * GeometryDefaultExtension<double>::getPyObject()
138
return new GeometryDoubleExtensionPy(new GeometryDoubleExtension(*this));
142
void GeometryDefaultExtension<double>::restoreAttributes(Base::XMLReader &reader)
144
Part::GeometryPersistenceExtension::restoreAttributes(reader);
146
value = reader.getAttributeAsFloat("value");
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>;