Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part: GeometryMigrationExtension classes
======================================== 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
1 parent
6a02496
commit ec5976e
Showing
4 changed files
with
206 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |