Skip to content

Commit

Permalink
+ optimize creation of hexagonal sketch profile, add icon
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jun 4, 2014
1 parent 5917d21 commit 409285d
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 58 deletions.
20 changes: 17 additions & 3 deletions src/Mod/Sketcher/App/ConstraintPyImp.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Mod/Sketcher/App/Sketch.cpp
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Sketcher/App/Sketch.h
Expand Up @@ -73,7 +73,7 @@ class SketcherExport Sketch :public Base::Persistence
/// 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;
Expand Down
11 changes: 10 additions & 1 deletion src/Mod/Sketcher/App/SketchObject.cpp
Expand Up @@ -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)
Expand Down
53 changes: 50 additions & 3 deletions src/Mod/Sketcher/App/SketchObjectPyImp.cpp
Expand Up @@ -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>
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
66 changes: 44 additions & 22 deletions src/Mod/Sketcher/App/SketchPyImp.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Sketcher/Gui/Resources/Sketcher.qrc
Expand Up @@ -70,6 +70,7 @@
<file>icons/Sketcher_Sketch.svg</file>
<file>icons/Sketcher_ViewSketch.svg</file>
<file>icons/Sketcher_AlterConstruction.svg</file>
<file>icons/Sketcher_ProfilesHexagon1.svg</file>
<file>translations/Sketcher_af.qm</file>
<file>translations/Sketcher_de.qm</file>
<file>translations/Sketcher_fi.qm</file>
Expand Down

0 comments on commit 409285d

Please sign in to comment.