From 86e3e90853fb87e2750193953c86b1ca9b3616b8 Mon Sep 17 00:00:00 2001 From: logari81 Date: Sat, 10 Dec 2011 21:17:50 +0000 Subject: [PATCH] + get possible axes information from Sketch git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5261 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Mod/Sketcher/App/SketchObject.cpp | 35 ++++++++++++++++++++ src/Mod/Sketcher/App/SketchObject.h | 7 ++-- src/Mod/Sketcher/App/SketchObjectPy.xml | 38 +++++++++++++++++----- src/Mod/Sketcher/App/SketchObjectPyImp.cpp | 27 ++++++++++++++- 4 files changed, 96 insertions(+), 11 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 430941df25..bdbeb9b1c2 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -205,6 +205,41 @@ Base::Vector3d SketchObject::getPoint(int geoIndex, PointPos PosId) return Base::Vector3d(); } +int SketchObject::getAxisCount(void) const +{ + const std::vector< Part::Geometry * > &vals = this->Geometry.getValues(); + + int count=0; + for (std::vector::const_iterator geo=vals.begin(); + geo != vals.end(); geo++) + if ((*geo) && (*geo)->Construction && + (*geo)->getTypeId() == Part::GeomLineSegment::getClassTypeId()) + count++; + + return count; +} + +Base::Axis SketchObject::getAxis(int axId) const +{ + const std::vector< Part::Geometry * > &vals = this->Geometry.getValues(); + + int count=0; + for (std::vector::const_iterator geo=vals.begin(); + geo != vals.end(); geo++) + if ((*geo) && (*geo)->Construction && + (*geo)->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + if (count == axId) { + Part::GeomLineSegment *lineSeg = dynamic_cast(*geo); + Base::Vector3d start = lineSeg->getStartPoint(); + Base::Vector3d end = lineSeg->getEndPoint(); + return Base::Axis(start, end-start); + } + count++; + } + + return Base::Axis(); +} + int SketchObject::addGeometry(const std::vector &geoList) { return -1; diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 210ee6ae06..e182f7a0db 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -20,14 +20,13 @@ * * ***************************************************************************/ - - #ifndef SKETCHER_SKETCHOBJECT_H #define SKETCHER_SKETCHOBJECT_H #include #include #include +#include #include #include @@ -90,6 +89,10 @@ public: int movePoint(int geoIndex1, PointPos Pos1, const Base::Vector3d& toPoint, bool relative=false); /// retrieves the coordinates of a point Base::Vector3d getPoint(int geoIndex1, PointPos Pos1); + /// returns the number of construction lines (to be used as axes) + int getAxisCount(void) const; + /// retrieves an axis iterating through the construction lines of the sketch (indices start at 0) + Base::Axis getAxis(int axId) const; /// toggle geometry to draft line int toggleConstruction(int GeoNbr); diff --git a/src/Mod/Sketcher/App/SketchObjectPy.xml b/src/Mod/Sketcher/App/SketchObjectPy.xml index fcf2822e39..e4eae9a3d7 100644 --- a/src/Mod/Sketcher/App/SketchObjectPy.xml +++ b/src/Mod/Sketcher/App/SketchObjectPy.xml @@ -1,13 +1,13 @@  - @@ -78,6 +78,20 @@ + + + + getPoint(GeoIndex,PointPos) - retrieve the vector of a point in the sketch + + + + + + + return an axis based on the corresponding construction line + + + create fillet between two edges or at a point @@ -100,5 +114,13 @@ + + + + return the the number of construction lines in the sketch which can be used as axes + + + + diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index eab18a2f1a..a9de03d919 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -28,7 +28,9 @@ #include "Mod/Sketcher/App/SketchObject.h" #include #include +#include #include +#include #include // inclusion of the generated files (generated out of SketchObjectSFPy.xml) @@ -233,6 +235,24 @@ PyObject* SketchObjectPy::movePoint(PyObject *args) } +PyObject* SketchObjectPy::getPoint(PyObject *args) +{ + int GeoId, PointType; + if (!PyArg_ParseTuple(args, "ii", &GeoId, &PointType)) + return 0; + + return new Base::VectorPy(new Base::Vector3d(this->getSketchObjectPtr()->getPoint(GeoId,(Sketcher::PointPos)PointType))); +} + +PyObject* SketchObjectPy::getAxis(PyObject *args) +{ + int AxId; + if (!PyArg_ParseTuple(args, "i", &AxId)) + return 0; + + return new Base::AxisPy(new Base::Axis(this->getSketchObjectPtr()->getAxis(AxId))); +} + PyObject* SketchObjectPy::fillet(PyObject *args) { PyObject *pcObj1, *pcObj2; @@ -284,7 +304,7 @@ PyObject* SketchObjectPy::trim(PyObject *args) return 0; } - Py_Return; + Py_Return; } @@ -298,6 +318,11 @@ Py::Int SketchObjectPy::getGeometryCount(void) const return Py::Int(this->getSketchObjectPtr()->Geometry.getSize()); } +Py::Int SketchObjectPy::getAxisCount(void) const +{ + return Py::Int(this->getSketchObjectPtr()->getAxisCount()); +} + PyObject *SketchObjectPy::getCustomAttributes(const char* /*attr*/) const { return 0;