Sketcher: Geometry Extension for Internal Alignment Geometry
============================================================ This commit extends SketchGeometryExtension to store within a Geometry if it is an internal aligment geometry and which type.
This commit is contained in:
committed by
abdullahtahiriyo
parent
f3595f1058
commit
f3ffcd6c4a
@@ -31,19 +31,21 @@
|
||||
|
||||
using namespace Sketcher;
|
||||
|
||||
|
||||
//---------- Geometry Extension
|
||||
constexpr std::array<const char *, InternalType::NumInternalGeometryType> SketchGeometryExtension::internaltype2str;
|
||||
|
||||
TYPESYSTEM_SOURCE(Sketcher::SketchGeometryExtension,Part::GeometryExtension)
|
||||
|
||||
// scoped within the class, multithread ready
|
||||
std::atomic<long> SketchGeometryExtension::_GeometryID;
|
||||
|
||||
SketchGeometryExtension::SketchGeometryExtension():Id(++SketchGeometryExtension::_GeometryID)
|
||||
SketchGeometryExtension::SketchGeometryExtension():Id(++SketchGeometryExtension::_GeometryID),InternalGeometryType(InternalType::None)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SketchGeometryExtension::SketchGeometryExtension(long cid):Id(cid)
|
||||
SketchGeometryExtension::SketchGeometryExtension(long cid):Id(cid),InternalGeometryType(InternalType::None)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -63,7 +65,8 @@ void SketchGeometryExtension::Save(Base::Writer &writer) const
|
||||
if(name.size() > 0)
|
||||
writer.Stream() << "\" name=\"" << name;
|
||||
|
||||
writer.Stream() << "\" id=\"" << Id << "\"/>" << std::endl;
|
||||
writer.Stream() << "\" id=\"" << Id
|
||||
<< "\" internalGeometryType=\"" << (int) InternalGeometryType << "\"/>" << std::endl;
|
||||
}
|
||||
|
||||
void SketchGeometryExtension::Restore(Base::XMLReader &reader)
|
||||
@@ -71,6 +74,7 @@ void SketchGeometryExtension::Restore(Base::XMLReader &reader)
|
||||
restoreNameAttribute(reader);
|
||||
|
||||
Id = reader.getAttributeAsInteger("id");
|
||||
InternalGeometryType = (InternalType::InternalType) reader.getAttributeAsInteger("internalGeometryType");
|
||||
}
|
||||
|
||||
std::unique_ptr<Part::GeometryExtension> SketchGeometryExtension::copy(void) const
|
||||
@@ -78,6 +82,7 @@ std::unique_ptr<Part::GeometryExtension> SketchGeometryExtension::copy(void) con
|
||||
auto cpy = std::make_unique<SketchGeometryExtension>();
|
||||
|
||||
cpy->Id = this->Id;
|
||||
cpy->InternalGeometryType = this->InternalGeometryType;
|
||||
|
||||
cpy->setName(this->getName()); // Base Class
|
||||
|
||||
|
||||
@@ -25,10 +25,29 @@
|
||||
|
||||
#include <Mod/Part/App/Geometry.h>
|
||||
#include <atomic>
|
||||
#include <bitset>
|
||||
#include <array>
|
||||
|
||||
namespace Sketcher
|
||||
{
|
||||
|
||||
namespace InternalType {
|
||||
enum InternalType {
|
||||
None = 0,
|
||||
EllipseMajorDiameter = 1,
|
||||
EllipseMinorDiameter = 2,
|
||||
EllipseFocus1 = 3,
|
||||
EllipseFocus2 = 4,
|
||||
HyperbolaMajor = 5,
|
||||
HyperbolaMinor = 6,
|
||||
HyperbolaFocus = 7,
|
||||
ParabolaFocus = 8,
|
||||
BSplineControlPoint = 9,
|
||||
BSplineKnotPoint = 10,
|
||||
NumInternalGeometryType // Must be the last
|
||||
};
|
||||
}
|
||||
|
||||
class ISketchGeometryExtension
|
||||
{
|
||||
|
||||
@@ -36,12 +55,16 @@ public:
|
||||
// Identification information
|
||||
virtual long getId() const = 0;
|
||||
virtual void setId(long id) = 0;
|
||||
|
||||
virtual InternalType::InternalType getInternalType() const = 0;
|
||||
virtual void setInternalType(InternalType::InternalType type) = 0;
|
||||
};
|
||||
|
||||
class SketcherExport SketchGeometryExtension : public Part::GeometryExtension, private ISketchGeometryExtension
|
||||
{
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
public:
|
||||
|
||||
SketchGeometryExtension();
|
||||
SketchGeometryExtension(long cid);
|
||||
virtual ~SketchGeometryExtension() override = default;
|
||||
@@ -58,11 +81,17 @@ public:
|
||||
virtual long getId() const override {return Id;}
|
||||
virtual void setId(long id) override {Id = id;}
|
||||
|
||||
virtual InternalType::InternalType getInternalType() const override {return InternalGeometryType;}
|
||||
virtual void setInternalType(InternalType::InternalType type) override {InternalGeometryType = type;}
|
||||
|
||||
constexpr static std::array<const char *,InternalType::NumInternalGeometryType> internaltype2str {{ "None", "EllipseMajorDiameter", "EllipseMinorDiameter","EllipseFocus1", "EllipseFocus2", "HyperbolaMajor", "HyperbolaMinor", "HyperbolaFocus", "ParabolaFocus", "BSplineControlPoint", "BSplineKnotPoint" }};
|
||||
|
||||
private:
|
||||
SketchGeometryExtension(const SketchGeometryExtension&) = default;
|
||||
|
||||
private:
|
||||
long Id;
|
||||
long Id;
|
||||
InternalType::InternalType InternalGeometryType;
|
||||
|
||||
private:
|
||||
static std::atomic<long> _GeometryID;
|
||||
|
||||
@@ -23,5 +23,13 @@
|
||||
</Documentation>
|
||||
<Parameter Name="Id" Type="Long"/>
|
||||
</Attribute>
|
||||
<Attribute Name="InternalType" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
returns the Id of the SketchGeometryExtension.
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="InternalType" Type="String"/>
|
||||
</Attribute>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
|
||||
@@ -89,6 +89,39 @@ void SketchGeometryExtensionPy::setId(Py::Long Id)
|
||||
this->getSketchGeometryExtensionPtr()->setId(long(Id));
|
||||
}
|
||||
|
||||
Py::String SketchGeometryExtensionPy::getInternalType(void) const
|
||||
{
|
||||
int internaltypeindex = (int)this->getSketchGeometryExtensionPtr()->getInternalType();
|
||||
|
||||
if(internaltypeindex >= InternalType::NumInternalGeometryType)
|
||||
throw Py::NotImplementedError("String name of enum not implemented");
|
||||
|
||||
std::string typestr = this->getSketchGeometryExtensionPtr()->internaltype2str[internaltypeindex];
|
||||
|
||||
return Py::String(typestr);
|
||||
}
|
||||
|
||||
void SketchGeometryExtensionPy::setInternalType(Py::String arg)
|
||||
{
|
||||
std::string argstr = arg;
|
||||
|
||||
auto pos = std::find_if(this->getSketchGeometryExtensionPtr()->internaltype2str.begin(),
|
||||
getSketchGeometryExtensionPtr()->internaltype2str.end(),
|
||||
[argstr](const char * val) {
|
||||
return strcmp(val,argstr.c_str())==0;}
|
||||
);
|
||||
|
||||
if( pos != getSketchGeometryExtensionPtr()->internaltype2str.end()) {
|
||||
int index = std::distance( getSketchGeometryExtensionPtr()->internaltype2str.begin(), pos );
|
||||
|
||||
this->getSketchGeometryExtensionPtr()->setInternalType((InternalType::InternalType)index);
|
||||
return;
|
||||
}
|
||||
|
||||
throw Py::ValueError("Argument is not a valid internal geometry type.");
|
||||
}
|
||||
|
||||
|
||||
PyObject *SketchGeometryExtensionPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user