+ fixes #0001713: Allow Part.Arc to be used as Sketcher geometry
This commit is contained in:
parent
97514d1806
commit
d974d6897b
|
@ -23,8 +23,11 @@
|
|||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
# include <Geom_TrimmedCurve.hxx>
|
||||
#endif
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
#include <Mod/Part/App/LinePy.h>
|
||||
#include <Mod/Part/App/Geometry.h>
|
||||
|
@ -67,16 +70,77 @@ PyObject* SketchObjectPy::addGeometry(PyObject *args)
|
|||
|
||||
if (PyObject_TypeCheck(pcObj, &(Part::GeometryPy::Type))) {
|
||||
Part::Geometry *geo = static_cast<Part::GeometryPy*>(pcObj)->getGeometryPtr();
|
||||
return Py::new_reference_to(Py::Int(this->getSketchObjectPtr()->addGeometry(geo)));
|
||||
int ret;
|
||||
// An arc created with Part.Arc will be converted into a Part.ArcOfCircle
|
||||
if (geo->getTypeId() == Part::GeomTrimmedCurve::getClassTypeId()) {
|
||||
Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast(geo->handle());
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve());
|
||||
if (!circle.IsNull()) {
|
||||
// create the definition struct for that geom
|
||||
Part::GeomArcOfCircle aoc;
|
||||
aoc.setHandle(trim);
|
||||
ret = this->getSketchObjectPtr()->addGeometry(&aoc);
|
||||
}
|
||||
else {
|
||||
std::stringstream str;
|
||||
str << "Unsupported geometry type: " << geo->getTypeId().getName();
|
||||
PyErr_SetString(PyExc_TypeError, str.str().c_str());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (geo->getTypeId() == Part::GeomPoint::getClassTypeId() ||
|
||||
geo->getTypeId() == Part::GeomCircle::getClassTypeId() ||
|
||||
geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId() ||
|
||||
geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
|
||||
ret = this->getSketchObjectPtr()->addGeometry(geo);
|
||||
}
|
||||
else {
|
||||
std::stringstream str;
|
||||
str << "Unsupported geometry type: " << geo->getTypeId().getName();
|
||||
PyErr_SetString(PyExc_TypeError, str.str().c_str());
|
||||
return 0;
|
||||
}
|
||||
return Py::new_reference_to(Py::Int(ret));
|
||||
}
|
||||
else if (PyObject_TypeCheck(pcObj, &(PyList_Type)) ||
|
||||
PyObject_TypeCheck(pcObj, &(PyTuple_Type))) {
|
||||
std::vector<Part::Geometry *> geoList;
|
||||
std::vector<boost::shared_ptr <Part::Geometry> > tmpList;
|
||||
Py::Sequence list(pcObj);
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
if (PyObject_TypeCheck((*it).ptr(), &(Part::GeometryPy::Type))) {
|
||||
Part::Geometry *geo = static_cast<Part::GeometryPy*>((*it).ptr())->getGeometryPtr();
|
||||
geoList.push_back(geo);
|
||||
|
||||
// An arc created with Part.Arc will be converted into a Part.ArcOfCircle
|
||||
if (geo->getTypeId() == Part::GeomTrimmedCurve::getClassTypeId()) {
|
||||
Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast(geo->handle());
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve());
|
||||
if (!circle.IsNull()) {
|
||||
// create the definition struct for that geom
|
||||
boost::shared_ptr<Part::GeomArcOfCircle> aoc(new Part::GeomArcOfCircle());
|
||||
aoc->setHandle(trim);
|
||||
geoList.push_back(aoc.get());
|
||||
tmpList.push_back(aoc);
|
||||
}
|
||||
else {
|
||||
std::stringstream str;
|
||||
str << "Unsupported geometry type: " << geo->getTypeId().getName();
|
||||
PyErr_SetString(PyExc_TypeError, str.str().c_str());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (geo->getTypeId() == Part::GeomPoint::getClassTypeId() ||
|
||||
geo->getTypeId() == Part::GeomCircle::getClassTypeId() ||
|
||||
geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId() ||
|
||||
geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
|
||||
geoList.push_back(geo);
|
||||
}
|
||||
else {
|
||||
std::stringstream str;
|
||||
str << "Unsupported geometry type: " << geo->getTypeId().getName();
|
||||
PyErr_SetString(PyExc_TypeError, str.str().c_str());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,6 +151,7 @@ PyObject* SketchObjectPy::addGeometry(PyObject *args)
|
|||
int geoId = ret - int(numGeo - i);
|
||||
tuple.setItem(i, Py::Int(geoId));
|
||||
}
|
||||
|
||||
return Py::new_reference_to(tuple);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user