Sketcher: GeometryTypedFacade and GeometryFacade convenience functions

======================================================================

GeometryFacade is added the ability to get the construction status via static function, for
convenience in situations where only the construction status is necessary and a geometry facade
would not be otherwise necessary.

A new type GeometryTypedFacade is added, for situations in which the specific Part::Geometry derived
type is known (or is to be created). This Typed version enables to directly access the Geometry derived
class without the need for casting, as well as the SketchGeometryExtension information.

For example, this is possible:

auto HLineF = GeometryTypedFacade<Part::GeomLineSegment>::getTypedFacade(HLine);
HLine->getTypedGeometry()->setPoints(Base::Vector3d(0,0,0),Base::Vector3d(1,0,0));

If a facade is requested without passing an Part::Geometry derived object, the constructor
of the indicated geometry type is called with any parameter passed as argument (emplace style):

auto HLine = GeometryTypedFacade<Part::GeomLineSegment>::getTypedFacade();
HLine->getTypedGeometry()->setPoints(Base::Vector3d(0,0,0),Base::Vector3d(1,0,0));
HLine->setConstruction(true);
ExternalGeo.push_back(HLine->getGeometry());

Using either GeometryFacade or GeometryTypedFacade is probably a matter of style and of the specific situation.
This commit is contained in:
Abdullah Tahiri
2020-12-03 14:13:39 +01:00
committed by abdullahtahiriyo
parent 6b05767a0c
commit 858abd99ca
2 changed files with 95 additions and 2 deletions

View File

@@ -113,6 +113,18 @@ void GeometryFacade::copyId(const Part::Geometry * src, Part::Geometry * dst)
gfdst->setId(gfsrc->getId());
}
bool GeometryFacade::getConstruction(const Part::Geometry * geometry)
{
auto gf = GeometryFacade::getFacade(geometry);
return gf->getConstruction();
}
void GeometryFacade::setConstruction(Part::Geometry * geometry, bool construction)
{
auto gf = GeometryFacade::getFacade(geometry);
return gf->setConstruction(construction);
}
PyObject * GeometryFacade::getPyObject(void)
{
return new GeometryFacadePy(new GeometryFacade(this->Geo));