+ optimize creation of hexagonal sketch profile, add icon

This commit is contained in:
wmayer
2014-06-04 12:05:41 +02:00
parent f3a1825e73
commit 86d80db12c
10 changed files with 317 additions and 58 deletions

View File

@@ -22,11 +22,10 @@
#include "PreCompiled.h"
#include <sstream>
#include "Mod/Sketcher/App/Constraint.h"
// inclusion of the generated files (generated out of ConstraintPy.xml)
#include "Constraint.h"
#include "ConstraintPy.h"
#include "ConstraintPy.cpp"
#include <Base/QuantityPy.h>
using namespace Sketcher;
@@ -109,6 +108,11 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/)
valid = true;
}
else if (strcmp("Angle",ConstraintType) == 0 ) {
if (PyObject_TypeCheck(index_or_value, &(Base::QuantityPy::Type))) {
Base::Quantity q = *(static_cast<Base::QuantityPy*>(index_or_value)->getQuantityPtr());
if (q.getUnit() == Base::Unit::Angle)
Value = q.getValueAs(Base::Quantity::Radian);
}
this->getConstraintPtr()->Type = Angle;
valid = true;
}
@@ -172,6 +176,11 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/)
//}
//else
if (strcmp("Angle",ConstraintType) == 0) {
if (PyObject_TypeCheck(index_or_value, &(Base::QuantityPy::Type))) {
Base::Quantity q = *(static_cast<Base::QuantityPy*>(index_or_value)->getQuantityPtr());
if (q.getUnit() == Base::Unit::Angle)
Value = q.getValueAs(Base::Quantity::Radian);
}
this->getConstraintPtr()->Type = Angle;
this->getConstraintPtr()->First = FirstIndex;
this->getConstraintPtr()->Second = SecondIndex;
@@ -279,6 +288,11 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/)
valid = true;
}
else if (strcmp("Angle",ConstraintType) == 0 ) {
if (PyObject_TypeCheck(index_or_value, &(Base::QuantityPy::Type))) {
Base::Quantity q = *(static_cast<Base::QuantityPy*>(index_or_value)->getQuantityPtr());
if (q.getUnit() == Base::Unit::Angle)
Value = q.getValueAs(Base::Quantity::Radian);
}
this->getConstraintPtr()->Type = Angle;
valid = true;
}

View File

@@ -174,10 +174,12 @@ int Sketch::addGeometry(const Part::Geometry *geo, bool fixed)
}
}
void Sketch::addGeometry(const std::vector<Part::Geometry *> &geo, bool fixed)
int Sketch::addGeometry(const std::vector<Part::Geometry *> &geo, bool fixed)
{
int ret = -1;
for (std::vector<Part::Geometry *>::const_iterator it=geo.begin(); it != geo.end(); ++it)
addGeometry(*it, fixed);
ret = addGeometry(*it, fixed);
return ret;
}
int Sketch::addPoint(const Part::GeomPoint &point, bool fixed)

View File

@@ -73,7 +73,7 @@ public:
/// add unspecified geometry
int addGeometry(const Part::Geometry *geo, bool fixed=false);
/// add unspecified geometry
void addGeometry(const std::vector<Part::Geometry *> &geo, bool fixed=false);
int addGeometry(const std::vector<Part::Geometry *> &geo, bool fixed=false);
/// returns the actual geometry
std::vector<Part::Geometry *> extractGeometry(bool withConstrucionElements=true,
bool withExternalElements=false) const;

View File

@@ -307,7 +307,16 @@ Base::Axis SketchObject::getAxis(int axId) const
int SketchObject::addGeometry(const std::vector<Part::Geometry *> &geoList)
{
return -1;
const std::vector< Part::Geometry * > &vals = getInternalGeometry();
std::vector< Part::Geometry * > newVals(vals);
for (std::vector<Part::Geometry *>::const_iterator it = geoList.begin(); it != geoList.end(); ++it) {
newVals.push_back(*it);
}
Geometry.setValues(newVals);
Constraints.acceptGeometry(getCompleteGeometry());
rebuildVertexIndex();
return Geometry.getSize()-1;
}
int SketchObject::addGeometry(const Part::Geometry *geo)

View File

@@ -25,7 +25,7 @@
# include <sstream>
#endif
#include "Mod/Sketcher/App/SketchObject.h"
#include <Mod/Sketcher/App/SketchObject.h>
#include <Mod/Part/App/LinePy.h>
#include <Mod/Part/App/Geometry.h>
#include <Base/GeometryPyCXX.h>
@@ -34,6 +34,7 @@
#include <Base/Tools.h>
#include <Base/QuantityPy.h>
#include <App/Document.h>
#include <CXX/Objects.hxx>
// inclusion of the generated files (generated out of SketchObjectSFPy.xml)
#include "SketchObjectPy.h"
@@ -66,7 +67,30 @@ PyObject* SketchObjectPy::addGeometry(PyObject *args)
Part::Geometry *geo = static_cast<Part::GeometryPy*>(pcObj)->getGeometryPtr();
return Py::new_reference_to(Py::Int(this->getSketchObjectPtr()->addGeometry(geo)));
}
Py_Return;
else if (PyObject_TypeCheck(pcObj, &(PyList_Type)) ||
PyObject_TypeCheck(pcObj, &(PyTuple_Type))) {
std::vector<Part::Geometry *> geoList;
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);
}
}
int ret = this->getSketchObjectPtr()->addGeometry(geoList) + 1;
std::size_t numGeo = geoList.size();
Py::Tuple tuple(numGeo);
for (std::size_t i=0; i<numGeo; ++i) {
int geoId = ret - int(numGeo - i);
tuple.setItem(i, Py::Int(geoId));
}
return Py::new_reference_to(tuple);
}
std::string error = std::string("type must be 'Geometry' or list of 'Geometry', not ");
error += pcObj->ob_type->tp_name;
throw Py::TypeError(error);
}
PyObject* SketchObjectPy::delGeometry(PyObject *args)
@@ -130,7 +154,30 @@ PyObject* SketchObjectPy::addConstraint(PyObject *args)
this->getSketchObjectPtr()->solve();
return Py::new_reference_to(Py::Int(ret));
}
Py_Return;
else if (PyObject_TypeCheck(pcObj, &(PyList_Type)) ||
PyObject_TypeCheck(pcObj, &(PyTuple_Type))) {
std::vector<Constraint*> values;
Py::Sequence list(pcObj);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
if (PyObject_TypeCheck((*it).ptr(), &(ConstraintPy::Type))) {
Constraint *con = static_cast<ConstraintPy*>((*it).ptr())->getConstraintPtr();
values.push_back(con);
}
}
int ret = getSketchObjectPtr()->addConstraints(values) + 1;
std::size_t numCon = values.size();
Py::Tuple tuple(numCon);
for (std::size_t i=0; i<numCon; ++i) {
int conId = ret - int(numCon - i);
tuple.setItem(i, Py::Int(conId));
}
return Py::new_reference_to(tuple);
}
std::string error = std::string("type must be 'Constraint' or list of 'Constraint', not ");
error += pcObj->ob_type->tp_name;
throw Py::TypeError(error);
}
PyObject* SketchObjectPy::delConstraint(PyObject *args)

View File

@@ -28,6 +28,7 @@
#include <Mod/Part/App/GeometryCurvePy.h>
#include <Mod/Part/App/LinePy.h>
#include <Mod/Part/App/TopoShapePy.h>
#include <CXX/Objects.hxx>
#include "Sketch.h"
#include "Constraint.h"
@@ -71,50 +72,71 @@ PyObject* SketchPy::addGeometry(PyObject *args)
if (!PyArg_ParseTuple(args, "O", &pcObj))
return 0;
if (PyObject_TypeCheck(pcObj, &(LinePy::Type))) {
GeomLineSegment *line = static_cast<LinePy*>(pcObj)->getGeomLineSegmentPtr();
return Py::new_reference_to(Py::Int(this->getSketchPtr()->addGeometry(line->clone())));
if (PyObject_TypeCheck(pcObj, &(Part::GeometryPy::Type))) {
Part::Geometry *geo = static_cast<Part::GeometryPy*>(pcObj)->getGeometryPtr();
return Py::new_reference_to(Py::Int(this->getSketchPtr()->addGeometry(geo)));
}
Py_Return;
else if (PyObject_TypeCheck(pcObj, &(PyList_Type)) ||
PyObject_TypeCheck(pcObj, &(PyTuple_Type))) {
std::vector<Part::Geometry *> geoList;
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);
}
}
int ret = this->getSketchPtr()->addGeometry(geoList) + 1;
std::size_t numGeo = geoList.size();
Py::Tuple tuple(numGeo);
for (std::size_t i=0; i<numGeo; ++i) {
int geoId = ret - int(numGeo - i);
tuple.setItem(i, Py::Int(geoId));
}
return Py::new_reference_to(tuple);
}
std::string error = std::string("type must be 'Geometry' or list of 'Geometry', not ");
error += pcObj->ob_type->tp_name;
throw Py::TypeError(error);
}
PyObject* SketchPy::addConstraint(PyObject *args)
{
int ret = -1;
PyObject *pcObj;
if (!PyArg_ParseTuple(args, "O", &pcObj))
return 0;
if (PyList_Check(pcObj)) {
Py_ssize_t nSize = PyList_Size(pcObj);
if (PyObject_TypeCheck(pcObj, &(PyList_Type)) || PyObject_TypeCheck(pcObj, &(PyTuple_Type))) {
std::vector<Constraint*> values;
values.resize(nSize);
for (Py_ssize_t i=0; i<nSize;++i) {
PyObject* item = PyList_GetItem(pcObj, i);
if (!PyObject_TypeCheck(item, &(ConstraintPy::Type))) {
std::string error = std::string("types in list must be 'Constraint', not ");
error += item->ob_type->tp_name;
throw Py::TypeError(error);
Py::Sequence list(pcObj);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
if (PyObject_TypeCheck((*it).ptr(), &(ConstraintPy::Type))) {
Constraint *con = static_cast<ConstraintPy*>((*it).ptr())->getConstraintPtr();
values.push_back(con);
}
values[i] = static_cast<ConstraintPy*>(item)->getConstraintPtr();
}
ret = getSketchPtr()->addConstraints(values);
int ret = getSketchPtr()->addConstraints(values) + 1;
std::size_t numCon = values.size();
Py::Tuple tuple(numCon);
for (std::size_t i=0; i<numCon; ++i) {
int conId = ret - int(numCon - i);
tuple.setItem(i, Py::Int(conId));
}
return Py::new_reference_to(tuple);
}
else if(PyObject_TypeCheck(pcObj, &(ConstraintPy::Type))) {
ConstraintPy *pcObject = static_cast<ConstraintPy*>(pcObj);
ret = getSketchPtr()->addConstraint(pcObject->getConstraintPtr());
int ret = getSketchPtr()->addConstraint(pcObject->getConstraintPtr());
return Py::new_reference_to(Py::Int(ret));
}
else {
std::string error = std::string("type must be 'Constraint' or list of 'Constraint', not ");
error += pcObj->ob_type->tp_name;
throw Py::TypeError(error);
}
return Py::new_reference_to(Py::Int(ret));
}
PyObject* SketchPy::clear(PyObject *args)