diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index adef03ca8c..4b1de3fbc1 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -73,6 +73,7 @@ #include "Geometry.h" #include "GeometryExtension.h" #include "GeometryDefaultExtension.h" +#include "GeometryMigrationExtension.h" #include "Geometry2d.h" #include "Mod/Part/App/GeometryIntExtensionPy.h" #include "Mod/Part/App/GeometryStringExtensionPy.h" @@ -404,45 +405,46 @@ PyMOD_INIT_FUNC(Part) Part::Reverse ::init(); // Geometry types - Part::GeometryExtension ::init(); - Part::GeometryIntExtension ::init(); - Part::GeometryStringExtension ::init(); - Part::GeometryBoolExtension ::init(); - Part::GeometryDoubleExtension ::init(); - Part::Geometry ::init(); - Part::GeomPoint ::init(); - Part::GeomCurve ::init(); - Part::GeomBoundedCurve ::init(); - Part::GeomBezierCurve ::init(); - Part::GeomBSplineCurve ::init(); - Part::GeomConic ::init(); - Part::GeomTrimmedCurve ::init(); - Part::GeomArcOfConic ::init(); - Part::GeomCircle ::init(); - Part::GeomArcOfCircle ::init(); - Part::GeomArcOfEllipse ::init(); - Part::GeomArcOfParabola ::init(); - Part::GeomArcOfHyperbola ::init(); - Part::GeomEllipse ::init(); - Part::GeomHyperbola ::init(); - Part::GeomParabola ::init(); - Part::GeomLine ::init(); - Part::GeomLineSegment ::init(); - Part::GeomOffsetCurve ::init(); - Part::GeomSurface ::init(); - Part::GeomBezierSurface ::init(); - Part::GeomBSplineSurface ::init(); - Part::GeomCylinder ::init(); - Part::GeomCone ::init(); - Part::GeomSphere ::init(); - Part::GeomToroid ::init(); - Part::GeomPlane ::init(); - Part::GeomOffsetSurface ::init(); - Part::GeomPlateSurface ::init(); - Part::GeomTrimmedSurface ::init(); - Part::GeomSurfaceOfRevolution ::init(); - Part::GeomSurfaceOfExtrusion ::init(); - Part::Datum ::init(); + Part::GeometryExtension ::init(); + Part::GeometryIntExtension ::init(); + Part::GeometryStringExtension ::init(); + Part::GeometryBoolExtension ::init(); + Part::GeometryDoubleExtension ::init(); + Part::GeometryMigrationExtension ::init(); + Part::Geometry ::init(); + Part::GeomPoint ::init(); + Part::GeomCurve ::init(); + Part::GeomBoundedCurve ::init(); + Part::GeomBezierCurve ::init(); + Part::GeomBSplineCurve ::init(); + Part::GeomConic ::init(); + Part::GeomTrimmedCurve ::init(); + Part::GeomArcOfConic ::init(); + Part::GeomCircle ::init(); + Part::GeomArcOfCircle ::init(); + Part::GeomArcOfEllipse ::init(); + Part::GeomArcOfParabola ::init(); + Part::GeomArcOfHyperbola ::init(); + Part::GeomEllipse ::init(); + Part::GeomHyperbola ::init(); + Part::GeomParabola ::init(); + Part::GeomLine ::init(); + Part::GeomLineSegment ::init(); + Part::GeomOffsetCurve ::init(); + Part::GeomSurface ::init(); + Part::GeomBezierSurface ::init(); + Part::GeomBSplineSurface ::init(); + Part::GeomCylinder ::init(); + Part::GeomCone ::init(); + Part::GeomSphere ::init(); + Part::GeomToroid ::init(); + Part::GeomPlane ::init(); + Part::GeomOffsetSurface ::init(); + Part::GeomPlateSurface ::init(); + Part::GeomTrimmedSurface ::init(); + Part::GeomSurfaceOfRevolution ::init(); + Part::GeomSurfaceOfExtrusion ::init(); + Part::Datum ::init(); // Geometry2d types Part::Geometry2d ::init(); diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index d291c20e45..9adfcf8e3f 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -404,6 +404,8 @@ SET(Part_SRCS GeometryExtension.h GeometryDefaultExtension.cpp GeometryDefaultExtension.h + GeometryMigrationExtension.h + GeometryMigrationExtension.cpp Geometry.cpp Geometry.h Geometry2d.cpp diff --git a/src/Mod/Part/App/GeometryMigrationExtension.cpp b/src/Mod/Part/App/GeometryMigrationExtension.cpp new file mode 100644 index 0000000000..70ba98fff8 --- /dev/null +++ b/src/Mod/Part/App/GeometryMigrationExtension.cpp @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (c) 2020 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 "GeometryMigrationExtension.h" + +#include + +using namespace Part; + + +//---------- Geometry Extension +TYPESYSTEM_SOURCE(Part::GeometryMigrationExtension,Part::GeometryExtension) + +GeometryMigrationExtension::GeometryMigrationExtension():ConstructionState(false) +{ + +} + + +// Persistence implementer +unsigned int GeometryMigrationExtension::getMemSize (void) const +{ + return sizeof(long int); +} + +void GeometryMigrationExtension::Save(Base::Writer &writer) const +{ + (void) writer; +} + +void GeometryMigrationExtension::Restore(Base::XMLReader &reader) +{ + (void) reader; +} + +std::unique_ptr GeometryMigrationExtension::copy(void) const +{ + auto cpy = std::make_unique(); + + cpy->ConstructionState = this->ConstructionState; + cpy->GeometryMigrationFlags = this->GeometryMigrationFlags; + + cpy->setName(this->getName()); // Base Class + +#if defined (__GNUC__) && (__GNUC__ <=4) + return std::move(cpy); +#else + return cpy; +#endif +} + +PyObject * GeometryMigrationExtension::getPyObject(void) +{ + THROWM(Base::NotImplementedError, "GeometryMigrationExtension does not have a Python counterpart"); +} diff --git a/src/Mod/Part/App/GeometryMigrationExtension.h b/src/Mod/Part/App/GeometryMigrationExtension.h new file mode 100644 index 0000000000..8308a0a42b --- /dev/null +++ b/src/Mod/Part/App/GeometryMigrationExtension.h @@ -0,0 +1,87 @@ +/*************************************************************************** + * Copyright (c) 2020 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 * + * * + ***************************************************************************/ + +#ifndef PART_GEOMETRYMIGRATIONEXTENSION_H +#define PART_GEOMETRYMIGRATIONEXTENSION_H + +#include +#include + +namespace Part +{ + +// This is a light-weight c++ only geometry extension to enable migration of information that was stored within +// the Part WB and should be migrated to another WB +// +// It is designed so that a single extension can migrate different types of data. +// +// To migrate data: +// 1. Add an enum bit to indicate the type of migration type +// 2. Add the data members to store the information and accessors +class PartExport GeometryMigrationExtension : public Part::GeometryExtension +{ + TYPESYSTEM_HEADER_WITH_OVERRIDE(); +public: + + // Indicates the type of migration to be performed, it is stored as a bitset, so several + // migrations may take place in a single extension. + // It is intended to support also LinkStage3 migration with a single framework (Id, Ref, ...) + enum MigrationType { + None = 0, + Construction = 1, + NumMigrationType // Must be the last + }; + + GeometryMigrationExtension(); + virtual ~GeometryMigrationExtension() override = default; + + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const override; + virtual void Save(Base::Writer &/*writer*/) const override; + virtual void Restore(Base::XMLReader &/*reader*/) override; + + virtual std::unique_ptr copy(void) const override; + + virtual PyObject *getPyObject(void) override; + + + virtual bool getConstruction() const {return Construction;} + virtual void setConstruction(bool construction) {ConstructionState = construction;} + + virtual bool testMigrationType(int flag) const { return GeometryMigrationFlags.test((size_t)(flag)); }; + virtual void setMigrationType(int flag, bool v=true) { GeometryMigrationFlags.set((size_t)(flag), v); }; + + +private: + GeometryMigrationExtension(const GeometryMigrationExtension&) = default; + +private: + using MigrationTypeFlagType = std::bitset<32>; + MigrationTypeFlagType GeometryMigrationFlags; + bool ConstructionState; + +}; + +} //namespace Part + + +#endif // PART_GEOMETRYMIGRATIONEXTENSION_H