Skip to content

Commit

Permalink
Part: GeometryMigrationExtension classes
Browse files Browse the repository at this point in the history
========================================

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 (for example Sketcher WB)

It is designed so that a single extension can migrate different types of data (current and future).

When new data needs to be migrated, first a new enum bit is to be added to the class enum and new data members are to
be added to store the information within GeometryMigrationExtension class.

In the Restore() function restoring the data to be migrated, a GeometryMigrationExtension extension is added to the
geometry to be migrated with the data information and the corresponding enum bit set.

In the object to receive the migration data, onDocumentRestored() it is checked whether an extension of type
GeometryMigrationExtension is present, if yes, it is checked whether a bit used for migration is set and, if yes,
the data is retrieved and the GeometryMigrationExtension extension (preferably) removed from the Geometry object.
  • Loading branch information
abdullahtahiriyo committed Dec 10, 2020
1 parent 6a02496 commit ec5976e
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 39 deletions.
80 changes: 41 additions & 39 deletions src/Mod/Part/App/AppPart.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Part/App/CMakeLists.txt
Expand Up @@ -404,6 +404,8 @@ SET(Part_SRCS
GeometryExtension.h
GeometryDefaultExtension.cpp
GeometryDefaultExtension.h
GeometryMigrationExtension.h
GeometryMigrationExtension.cpp
Geometry.cpp
Geometry.h
Geometry2d.cpp
Expand Down
76 changes: 76 additions & 0 deletions src/Mod/Part/App/GeometryMigrationExtension.cpp
@@ -0,0 +1,76 @@
/***************************************************************************
* Copyright (c) 2020 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com> *
* *
* 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 <Base/Exception.h>

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<Part::GeometryExtension> GeometryMigrationExtension::copy(void) const
{
auto cpy = std::make_unique<GeometryMigrationExtension>();

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");
}
87 changes: 87 additions & 0 deletions src/Mod/Part/App/GeometryMigrationExtension.h
@@ -0,0 +1,87 @@
/***************************************************************************
* Copyright (c) 2020 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com> *
* *
* 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 <Mod/Part/App/Geometry.h>
#include <bitset>

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<Part::GeometryExtension> 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

0 comments on commit ec5976e

Please sign in to comment.