PyObject* MatrixPy::transform(PyObject * args) { Base::Vector3d vec; Matrix4D mat; PyObject *pcVecObj,*pcMatObj; if (PyArg_ParseTuple(args, "O!O!: a transform point (Vector) and a transform matrix (Matrix) is needed", &(Base::VectorPy::Type), &pcVecObj, &(MatrixPy::Type), &pcMatObj) ) { // convert args: Python->C Base::VectorPy *pcObject = static_cast<Base::VectorPy*>(pcVecObj); Base::Vector3d* val = pcObject->getVectorPtr(); vec.Set(val->x,val->y,val->z); mat = *(static_cast<MatrixPy*>(pcMatObj)->getMatrixPtr()); // clears the error from the first PyArg_ParseTuple()6 PyErr_Clear(); } else return NULL; // NULL triggers exception PY_TRY { getMatrixPtr()->transform(vec,mat); } PY_CATCH; Py_Return; }
PyObject* MatrixPy::scale(PyObject * args) { double x,y,z; Base::Vector3d vec; PyObject *pcVecObj; if (PyArg_ParseTuple(args, "ddd", &x,&y,&z)) { // convert args: Python->C vec.x = x; vec.y = y; vec.z = z; } else if (PyArg_ParseTuple(args, "O!:three floats or a vector is needed", &PyTuple_Type, &pcVecObj)) { vec = getVectorFromTuple<double>(pcVecObj); // clears the error from the first PyArg_ParseTuple()6 PyErr_Clear(); } else if (PyArg_ParseTuple(args, "O!:three floats or a vector is needed", &(Base::VectorPy::Type), &pcVecObj)) { // convert args: Python->C Base::VectorPy *pcObject = static_cast<Base::VectorPy*>(pcVecObj); Base::Vector3d* val = pcObject->getVectorPtr(); vec.Set(val->x,val->y,val->z); // clears the error from the first PyArg_ParseTuple()6 PyErr_Clear(); } else return NULL; PY_TRY { getMatrixPtr()->scale(vec); } PY_CATCH; Py_Return; }
Base::Matrix4D MeshObject::getEigenSystem(Base::Vector3d& v) const { MeshCore::MeshEigensystem cMeshEval(_kernel); cMeshEval.Evaluate(); Base::Vector3f uvw = cMeshEval.GetBoundings(); v.Set(uvw.x, uvw.y, uvw.z); return cMeshEval.Transform(); }
bool Extrusion::fetchAxisLink(const App::PropertyLinkSub& axisLink, Base::Vector3d& basepoint, Base::Vector3d& dir) { if (!axisLink.getValue()) return false; if (!axisLink.getValue()->isDerivedFrom(Part::Feature::getClassTypeId())) throw Base::TypeError("AxisLink has no OCC shape"); Part::Feature* linked = static_cast<Part::Feature*>(axisLink.getValue()); TopoDS_Shape axEdge; if (axisLink.getSubValues().size() > 0 && axisLink.getSubValues()[0].length() > 0){ axEdge = linked->Shape.getShape().getSubShape(axisLink.getSubValues()[0].c_str()); } else { axEdge = linked->Shape.getValue(); } if (axEdge.IsNull()) throw Base::ValueError("DirLink shape is null"); if (axEdge.ShapeType() != TopAbs_EDGE) throw Base::TypeError("DirLink shape is not an edge"); BRepAdaptor_Curve crv(TopoDS::Edge(axEdge)); gp_Pnt startpoint; gp_Pnt endpoint; if (crv.GetType() == GeomAbs_Line){ startpoint = crv.Value(crv.FirstParameter()); endpoint = crv.Value(crv.LastParameter()); if (axEdge.Orientation() == TopAbs_REVERSED) std::swap(startpoint, endpoint); } else { throw Base::TypeError("DirLink edge is not a line."); } basepoint.Set(startpoint.X(), startpoint.Y(), startpoint.Z()); gp_Vec vec = gp_Vec(startpoint, endpoint); dir.Set(vec.X(), vec.Y(), vec.Z()); return true; }
PyObject* MeshPointPy::move(PyObject *args) { if (!getMeshPointPtr()->isBound()) PyErr_SetString(Base::BaseExceptionFreeCADError, "This object is not bounded to a mesh, so no topological operation is possible!"); double x=0.0,y=0.0,z=0.0; PyObject *object; Base::Vector3d vec; if (PyArg_ParseTuple(args, "ddd", &x,&y,&z)) { vec.Set(x,y,z); } else if (PyArg_ParseTuple(args,"O!",&(Base::VectorPy::Type), &object)) { PyErr_Clear(); // set by PyArg_ParseTuple() // Note: must be static_cast, not reinterpret_cast vec = *(static_cast<Base::VectorPy*>(object)->getVectorPtr()); } else { return 0; } getMeshPointPtr()->Mesh->movePoint(getMeshPointPtr()->Index,vec); Py_Return; }