SketchPyImp.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "PreCompiled.h"
00024
00025 #include <Base/VectorPy.h>
00026
00027 #include <Mod/Part/App/Geometry.h>
00028 #include <Mod/Part/App/GeometryCurvePy.h>
00029 #include <Mod/Part/App/LinePy.h>
00030 #include <Mod/Part/App/TopoShapePy.h>
00031
00032 #include "Sketch.h"
00033 #include "Constraint.h"
00034 #include "ConstraintPy.h"
00035
00036
00037 #include "SketchPy.h"
00038 #include "SketchPy.cpp"
00039
00040 using namespace Sketcher;
00041 using namespace Part;
00042
00043
00044 std::string SketchPy::representation(void) const
00045 {
00046 return std::string("<Sketch object>");
00047 }
00048
00049 PyObject *SketchPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00050 {
00051
00052 return new SketchPy(new Sketch());
00053 }
00054
00055
00056 int SketchPy::PyInit(PyObject* , PyObject* )
00057 {
00058 return 0;
00059 }
00060
00061
00062
00063 PyObject* SketchPy::solve(PyObject *args)
00064 {
00065 return Py::new_reference_to(Py::Int(getSketchPtr()->solve()));
00066 }
00067
00068 PyObject* SketchPy::addGeometry(PyObject *args)
00069 {
00070 PyObject *pcObj;
00071 if (!PyArg_ParseTuple(args, "O", &pcObj))
00072 return 0;
00073
00074 if (PyObject_TypeCheck(pcObj, &(LinePy::Type))) {
00075 GeomLineSegment *line = static_cast<LinePy*>(pcObj)->getGeomLineSegmentPtr();
00076 return Py::new_reference_to(Py::Int(this->getSketchPtr()->addGeometry(line->clone())));
00077 }
00078 Py_Return;
00079 }
00080
00081 PyObject* SketchPy::addConstraint(PyObject *args)
00082 {
00083 int ret = -1;
00084 PyObject *pcObj;
00085 if (!PyArg_ParseTuple(args, "O", &pcObj))
00086 return 0;
00087
00088 if (PyList_Check(pcObj)) {
00089 Py_ssize_t nSize = PyList_Size(pcObj);
00090 std::vector<Constraint*> values;
00091 values.resize(nSize);
00092
00093 for (Py_ssize_t i=0; i<nSize;++i) {
00094 PyObject* item = PyList_GetItem(pcObj, i);
00095 if (!PyObject_TypeCheck(item, &(ConstraintPy::Type))) {
00096 std::string error = std::string("types in list must be 'Constraint', not ");
00097 error += item->ob_type->tp_name;
00098 throw Py::TypeError(error);
00099 }
00100
00101 values[i] = static_cast<ConstraintPy*>(item)->getConstraintPtr();
00102 }
00103
00104 ret = getSketchPtr()->addConstraints(values);
00105 }
00106 else if(PyObject_TypeCheck(pcObj, &(ConstraintPy::Type))) {
00107 ConstraintPy *pcObject = static_cast<ConstraintPy*>(pcObj);
00108 ret = getSketchPtr()->addConstraint(pcObject->getConstraintPtr());
00109 }
00110 else {
00111 std::string error = std::string("type must be 'Constraint' or list of 'Constraint', not ");
00112 error += pcObj->ob_type->tp_name;
00113 throw Py::TypeError(error);
00114 }
00115
00116 return Py::new_reference_to(Py::Int(ret));
00117
00118 }
00119
00120 PyObject* SketchPy::clear(PyObject *args)
00121 {
00122 int index;
00123 if (!PyArg_ParseTuple(args, "i", &index))
00124 return 0;
00125
00126 return Py::new_reference_to(Py::Int(getSketchPtr()->addVerticalConstraint(index)));
00127 }
00128
00129 PyObject* SketchPy::movePoint(PyObject *args)
00130 {
00131 int index1,index2;
00132 PyObject *pcObj;
00133 int relative=0;
00134 if (!PyArg_ParseTuple(args, "iiO!|i", &index1,&index2,&(Base::VectorPy::Type),&pcObj,&relative))
00135 return 0;
00136 Base::Vector3d* toPoint = static_cast<Base::VectorPy*>(pcObj)->getVectorPtr();
00137
00138 return Py::new_reference_to(Py::Int(getSketchPtr()->movePoint(index1,(Sketcher::PointPos)index2,*toPoint,(relative>0))));
00139 }
00140
00141
00142
00143 Py::Int SketchPy::getConstraint(void) const
00144 {
00145
00146 throw Py::AttributeError("Not yet implemented");
00147 }
00148
00149 Py::Tuple SketchPy::getConstraints(void) const
00150 {
00151
00152 throw Py::AttributeError("Not yet implemented");
00153 }
00154
00155 Py::Tuple SketchPy::getGeometries(void) const
00156 {
00157 return getSketchPtr()->getPyGeometry();
00158 }
00159
00160 Py::Object SketchPy::getShape(void) const
00161 {
00162 return Py::Object(new TopoShapePy(new TopoShape(getSketchPtr()->toShape())));
00163 }
00164
00165
00166
00167
00168
00169 PyObject *SketchPy::getCustomAttributes(const char* ) const
00170 {
00171 return 0;
00172 }
00173
00174 int SketchPy::setCustomAttributes(const char* , PyObject* )
00175 {
00176 return 0;
00177 }
00178
00179