/*************************************************************************** * Copyright (c) 2019 Abdullah Tahiri * * * * 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 * * * ***************************************************************************/ #include "PreCompiled.h" #include #include #include "GeometryDefaultExtension.h" #include "GeometryBoolExtensionPy.h" #include "GeometryDoubleExtensionPy.h" #include "GeometryIntExtensionPy.h" #include "GeometryStringExtensionPy.h" using namespace Part; //---------- Geometry Extension template GeometryDefaultExtension::GeometryDefaultExtension(const T& val, std::string name):value(val) { setName(name); } template void GeometryDefaultExtension::copyAttributes(Part::GeometryExtension * cpy) const { Part::GeometryPersistenceExtension::copyAttributes(cpy); static_cast *>(cpy)->value = this->value; } template void GeometryDefaultExtension::restoreAttributes(Base::XMLReader &reader) { Part::GeometryPersistenceExtension::restoreAttributes(reader); value = reader.getAttribute("value"); } template void GeometryDefaultExtension::saveAttributes(Base::Writer &writer) const { Part::GeometryPersistenceExtension::saveAttributes(writer); writer.Stream() << "\" value=\"" << value; } template std::unique_ptr GeometryDefaultExtension::copy() const { std::unique_ptr> cpy = std::make_unique>(); copyAttributes(cpy.get()); return cpy; } template PyObject * GeometryDefaultExtension::getPyObject() { THROWM(Base::NotImplementedError,"Python object not implemented for default geometry extension template type. Template Specialisation missing."); // use template specialisation to provide the actual object } namespace Part { // ----------------------------- Template specialisations---------------------------------------------------- //using GeometryIntExtension = Part::GeometryDefaultExtension; //using GeometryStringExtension = Part::GeometryStringExtension; // ---------- GeometryIntExtension ---------- TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryIntExtension,Part::GeometryPersistenceExtension) template <> PyObject * GeometryDefaultExtension::getPyObject() { return new GeometryIntExtensionPy(new GeometryIntExtension(*this)); } template <> void GeometryDefaultExtension::restoreAttributes(Base::XMLReader &reader) { Part::GeometryPersistenceExtension::restoreAttributes(reader); value = reader.getAttributeAsInteger("value"); } // ---------- GeometryStringExtension ---------- TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryStringExtension,Part::GeometryPersistenceExtension) template <> PyObject * GeometryDefaultExtension::getPyObject() { return new GeometryStringExtensionPy(new GeometryStringExtension(*this)); } // ---------- GeometryBoolExtension ---------- TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryBoolExtension,Part::GeometryPersistenceExtension) template <> PyObject * GeometryDefaultExtension::getPyObject() { return new GeometryBoolExtensionPy(new GeometryBoolExtension(*this)); } template <> void GeometryDefaultExtension::restoreAttributes(Base::XMLReader &reader) { Part::GeometryPersistenceExtension::restoreAttributes(reader); value = (bool)reader.getAttributeAsInteger("value"); } // ---------- GeometryDoubleExtension ---------- TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryDoubleExtension,Part::GeometryPersistenceExtension) template <> PyObject * GeometryDefaultExtension::getPyObject() { return new GeometryDoubleExtensionPy(new GeometryDoubleExtension(*this)); } template <> void GeometryDefaultExtension::restoreAttributes(Base::XMLReader &reader) { Part::GeometryPersistenceExtension::restoreAttributes(reader); value = reader.getAttributeAsFloat("value"); } // instantiate the types so that other translation units (python wrappers) can access template //constructors other than the default. template class GeometryDefaultExtension; template class GeometryDefaultExtension; template class GeometryDefaultExtension; template class GeometryDefaultExtension; } //namespace Part