From d7659c774181ccc6676cd042a5a7c08b917f1709 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Sat, 9 May 2020 19:30:58 -0400 Subject: [PATCH] [TD]Dimension Py Routine fixes --- src/Mod/TechDraw/App/AppTechDrawPy.cpp | 14 ++++++++++---- src/Mod/TechDraw/App/DrawDimHelper.cpp | 18 ++++++++---------- src/Mod/TechDraw/App/DrawViewDimensionPy.xml | 5 +++++ .../TechDraw/App/DrawViewDimensionPyImp.cpp | 10 ++++++++++ 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/Mod/TechDraw/App/AppTechDrawPy.cpp b/src/Mod/TechDraw/App/AppTechDrawPy.cpp index 9da9b94f9a..c483351070 100644 --- a/src/Mod/TechDraw/App/AppTechDrawPy.cpp +++ b/src/Mod/TechDraw/App/AppTechDrawPy.cpp @@ -794,6 +794,8 @@ private: Py::Object makeDistanceDim(const Py::Tuple& args) { + //points come in unscaled,but makeDistDim unscales them so we need to prescale here. + //makeDistDim was built for extent dims which work from scaled geometry PyObject* pDvp; PyObject* pDimType; PyObject* pFrom; @@ -827,12 +829,14 @@ private: if (PyObject_TypeCheck(pTo, &(Base::VectorPy::Type))) { to = static_cast(pTo)->value(); } + DrawViewDimension* dvd = DrawDimHelper::makeDistDim(dvp, dimType, - from, - to); - - return Py::None(); + DrawUtil::invertY(from), + DrawUtil::invertY(to)); + PyObject* dvdPy = dvd->getPyObject(); + return Py::asObject(dvdPy); +// return Py::None(); } Py::Object makeDistanceDim3d(const Py::Tuple& args) @@ -869,8 +873,10 @@ private: if (PyObject_TypeCheck(pTo, &(Base::VectorPy::Type))) { to = static_cast(pTo)->value(); } + //3d points are not scaled from = DrawUtil::invertY(dvp->projectPoint(from)); to = DrawUtil::invertY(dvp->projectPoint(to)); + //DrawViewDimension* = DrawDimHelper::makeDistDim(dvp, dimType, from, diff --git a/src/Mod/TechDraw/App/DrawDimHelper.cpp b/src/Mod/TechDraw/App/DrawDimHelper.cpp index 4cddb7fbd2..45470aa991 100644 --- a/src/Mod/TechDraw/App/DrawDimHelper.cpp +++ b/src/Mod/TechDraw/App/DrawDimHelper.cpp @@ -107,8 +107,8 @@ void DrawDimHelper::makeExtentDim(DrawViewPart* dvp, std::pair endPoints = minMax(dvp, edgeNames, direction); - Base::Vector3d refMin = endPoints.first; - Base::Vector3d refMax = endPoints.second; + Base::Vector3d refMin = endPoints.first / dvp->getScale(); //unscale from geometry + Base::Vector3d refMax = endPoints.second / dvp->getScale(); //pause recomputes dvp->getDocument()->setStatus(App::Document::Status::SkipRecompute, true); @@ -326,11 +326,10 @@ gp_Pnt2d DrawDimHelper::findClosestPoint(std::vector hTCurve2dList, return result; } -//TODO: this needs to be exposed to Python DrawViewDimension* DrawDimHelper::makeDistDim(DrawViewPart* dvp, std::string dimType, - Base::Vector3d inMin, - Base::Vector3d inMax, + Base::Vector3d inMin, //is this scaled or unscaled?? + Base::Vector3d inMax, //expects scaled from makeExtentDim bool extent) { // Base::Console().Message("DDH::makeDistDim() - inMin: %s inMax: %s\n", @@ -346,13 +345,11 @@ DrawViewDimension* DrawDimHelper::makeDistDim(DrawViewPart* dvp, dimName = doc->getUniqueObjectName("DimExtent"); } - double scale = dvp->getScale(); - - //regular dims will have trouble with geom indexes! - Base::Vector3d cleanMin = DrawUtil::invertY(inMin) / scale; + Base::Vector3d cleanMin = DrawUtil::invertY(inMin); std::string tag1 = dvp->addCosmeticVertex(cleanMin); int iGV1 = dvp->add1CVToGV(tag1); - Base::Vector3d cleanMax = DrawUtil::invertY(inMax) / scale; + + Base::Vector3d cleanMax = DrawUtil::invertY(inMax); std::string tag2 = dvp->addCosmeticVertex(cleanMax); int iGV2 = dvp->add1CVToGV(tag2); @@ -366,6 +363,7 @@ DrawViewDimension* DrawDimHelper::makeDistDim(DrawViewPart* dvp, objs.push_back(dvp); ss.clear(); + ss.str(std::string()); ss << "Vertex" << iGV2; vertexName = ss.str(); subs.push_back(vertexName); diff --git a/src/Mod/TechDraw/App/DrawViewDimensionPy.xml b/src/Mod/TechDraw/App/DrawViewDimensionPy.xml index b82104f00b..c6ac4074d3 100644 --- a/src/Mod/TechDraw/App/DrawViewDimensionPy.xml +++ b/src/Mod/TechDraw/App/DrawViewDimensionPy.xml @@ -13,6 +13,11 @@ Feature for creating and manipulating Technical Drawing Dimensions + + + getRawValue() - returns Dimension value in mm. + + getText() - returns Dimension text. diff --git a/src/Mod/TechDraw/App/DrawViewDimensionPyImp.cpp b/src/Mod/TechDraw/App/DrawViewDimensionPyImp.cpp index 7be2b7b2dd..b41e80f59c 100644 --- a/src/Mod/TechDraw/App/DrawViewDimensionPyImp.cpp +++ b/src/Mod/TechDraw/App/DrawViewDimensionPyImp.cpp @@ -42,6 +42,16 @@ std::string DrawViewDimensionPy::representation(void) const { return std::string(""); } + +PyObject* DrawViewDimensionPy::getRawValue(PyObject* args) +{ + (void) args; + DrawViewDimension* dvd = getDrawViewDimensionPtr(); + double val = dvd->getDimValue(); + PyObject* pyVal = PyFloat_FromDouble(val); + return pyVal; +} + PyObject* DrawViewDimensionPy::getText(PyObject* args) { (void) args;