Files
create/src/Mod/Part/App/GeometryMigrationExtension.h
Abdullah Tahiri e6af511f39 Part/Sketcher: Refactor Geometry Extensions copy/save/restore AND attachment notification
=========================================================================================

- Long overdue refactor to avoid repetition during save/restore and copy.
- New interface to notify an extension when it is attached. It also enables the extension to gain
a pointer to the geometry container. This is intended to extend the functionality already existing
in Part::Geometry.
2021-01-09 20:08:05 +01:00

85 lines
3.7 KiB
C++

/***************************************************************************
* 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;
virtual std::unique_ptr<Part::GeometryExtension> copy(void) const override;
virtual PyObject *getPyObject(void) override;
virtual bool getConstruction() const {return ConstructionState;}
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); };
protected:
virtual void copyAttributes(Part::GeometryExtension * cpy) const override;
private:
GeometryMigrationExtension(const GeometryMigrationExtension&) = default;
private:
using MigrationTypeFlagType = std::bitset<32>;
MigrationTypeFlagType GeometryMigrationFlags;
bool ConstructionState;
};
} //namespace Part
#endif // PART_GEOMETRYMIGRATIONEXTENSION_H