From 6a3d75135258f07fc725d6b3cb9e81328daf0342 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 27 Feb 2023 19:19:24 +0100 Subject: [PATCH] Sketcher: PropertyVisualLayerList ================================= This is a property (intended for ViewProviderSketch), containing a list of visual layer configurations. This property enables to define and serialise the configuration of visual layers, as well as reacting to changes to it. --- src/Mod/Sketcher/Gui/CMakeLists.txt | 2 + .../Sketcher/Gui/PropertyVisualLayerList.cpp | 108 ++++++++++++++++++ .../Sketcher/Gui/PropertyVisualLayerList.h | 76 ++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 src/Mod/Sketcher/Gui/PropertyVisualLayerList.cpp create mode 100644 src/Mod/Sketcher/Gui/PropertyVisualLayerList.h diff --git a/src/Mod/Sketcher/Gui/CMakeLists.txt b/src/Mod/Sketcher/Gui/CMakeLists.txt index 08d0d155af..e9168eba33 100644 --- a/src/Mod/Sketcher/Gui/CMakeLists.txt +++ b/src/Mod/Sketcher/Gui/CMakeLists.txt @@ -136,6 +136,8 @@ SET(SketcherGui_SRCS Workbench.h EditDatumDialog.cpp EditDatumDialog.h + PropertyVisualLayerList.cpp + PropertyVisualLayerList.h SketchOrientationDialog.cpp SketchOrientationDialog.h SketchMirrorDialog.cpp diff --git a/src/Mod/Sketcher/Gui/PropertyVisualLayerList.cpp b/src/Mod/Sketcher/Gui/PropertyVisualLayerList.cpp new file mode 100644 index 0000000000..0e78f38641 --- /dev/null +++ b/src/Mod/Sketcher/Gui/PropertyVisualLayerList.cpp @@ -0,0 +1,108 @@ +/*************************************************************************** + * Copyright (c) 2023 Abdullah Tahiri +#include +#include +#include + +#include "PropertyVisualLayerList.h" + + +using namespace App; +using namespace Base; +using namespace std; +using namespace SketcherGui; + + +TYPESYSTEM_SOURCE(SketcherGui::PropertyVisualLayerList , App::PropertyLists) + +//************************************************************************** +// Construction/Destruction + +PropertyVisualLayerList::PropertyVisualLayerList() = default; + +PropertyVisualLayerList::~PropertyVisualLayerList() = default; + +//************************************************************************** +// Base class implementer + +PyObject *PropertyVisualLayerList::getPyObject() +{ + THROWM(Base::NotImplementedError, "PropertyVisualLayerList has no python counterpart"); +} + +VisualLayer PropertyVisualLayerList::getPyValue(PyObject *item) const { + + (void) item; + THROWM(Base::NotImplementedError, "PropertyVisualLayerList has no python counterpart"); +} + +void PropertyVisualLayerList::Save (Base::Writer &writer) const +{ + writer.Stream() << writer.ind() << "" << endl; + writer.incInd(); + for (int i = 0; i < getSize(); i++) { + _lValueList[i].Save(writer); + } + writer.decInd(); + writer.Stream() << writer.ind() << "" << endl ; +} + +void PropertyVisualLayerList::Restore(Base::XMLReader &reader) +{ + reader.readElement("VisualLayerList"); + // get the value of my attribute + int count = reader.getAttributeAsInteger("count"); + + std::vector layers; + layers.reserve(count); + + for (int i = 0; i < count; i++) { + VisualLayer visualLayer; + visualLayer.Restore(reader); + layers.push_back(std::move(visualLayer)); + } + + reader.readEndElement("VisualLayerList"); + + setValues(std::move(layers)); +} + +Property *PropertyVisualLayerList::Copy() const +{ + PropertyVisualLayerList *p= new PropertyVisualLayerList(); + p->_lValueList = _lValueList; + return p; +} + +void PropertyVisualLayerList::Paste(const Property &from) +{ + setValues(dynamic_cast(from)._lValueList); +} + +unsigned int PropertyVisualLayerList::getMemSize () const +{ + return static_cast(_lValueList.size() * sizeof(VisualLayer)); +} diff --git a/src/Mod/Sketcher/Gui/PropertyVisualLayerList.h b/src/Mod/Sketcher/Gui/PropertyVisualLayerList.h new file mode 100644 index 0000000000..ec893f4c2f --- /dev/null +++ b/src/Mod/Sketcher/Gui/PropertyVisualLayerList.h @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (c) 2023 Abdullah Tahiri + +#include + +#include + +#include "VisualLayer.h" + + +namespace Base { +class Writer; +} + +namespace SketcherGui +{ + +class SketcherGuiExport PropertyVisualLayerList: public App::PropertyListsT +{ + TYPESYSTEM_HEADER_WITH_OVERRIDE(); + +public: + + /** + * A constructor. + * A more elaborate description of the constructor. + */ + PropertyVisualLayerList(); + + /** + * A destructor. + * A more elaborate description of the destructor. + */ + ~PropertyVisualLayerList() override; + + PyObject *getPyObject() override; + + void Save (Base::Writer &writer) const override; + void Restore(Base::XMLReader &reader) override; + + Property *Copy() const override; + void Paste(const Property &from) override; + unsigned int getMemSize () const override; + +protected: + VisualLayer getPyValue(PyObject *) const override; +}; + +} // namespace SketcherGui + + +#endif // SKETCHERGUI_PropertyVisualLayerList_H