From e11e4ba9ff7caaff018c27c1690926041ff94c5e Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 7 Oct 2012 17:07:23 +0200 Subject: [PATCH] Set tessellation tolerance in Drawing by user --- src/Mod/Drawing/App/AppDrawingPy.cpp | 14 ++++++++------ src/Mod/Drawing/App/FeatureViewPart.cpp | 6 +++++- src/Mod/Drawing/App/FeatureViewPart.h | 6 +++++- src/Mod/Drawing/App/ProjectionAlgos.cpp | 8 ++++---- src/Mod/Drawing/App/ProjectionAlgos.h | 4 ++-- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Mod/Drawing/App/AppDrawingPy.cpp b/src/Mod/Drawing/App/AppDrawingPy.cpp index 345c629a1..892504a72 100644 --- a/src/Mod/Drawing/App/AppDrawingPy.cpp +++ b/src/Mod/Drawing/App/AppDrawingPy.cpp @@ -105,9 +105,10 @@ projectToSVG(PyObject *self, PyObject *args) PyObject *pcObjDir=0; const char *type=0; float scale=1.0f; + float tol=0.1f; - if (!PyArg_ParseTuple(args, "O!|O!sf", &(TopoShapePy::Type), &pcObjShape, - &(Base::VectorPy::Type), &pcObjDir, &type, &scale)) + if (!PyArg_ParseTuple(args, "O!|O!sff", &(TopoShapePy::Type), &pcObjShape, + &(Base::VectorPy::Type), &pcObjDir, &type, &scale, &tol)) return NULL; PY_TRY { @@ -121,7 +122,7 @@ projectToSVG(PyObject *self, PyObject *args) if (type && std::string(type) == "ShowHiddenLines") hidden = true; - Py::String result(Alg.getSVG(hidden?ProjectionAlgos::WithHidden:ProjectionAlgos::Plain, scale)); + Py::String result(Alg.getSVG(hidden?ProjectionAlgos::WithHidden:ProjectionAlgos::Plain, scale, tol)); return Py::new_reference_to(result); } PY_CATCH; @@ -134,9 +135,10 @@ projectToDXF(PyObject *self, PyObject *args) PyObject *pcObjDir=0; const char *type=0; float scale=1.0f; + float tol=0.1f; - if (!PyArg_ParseTuple(args, "O!|O!sf", &(TopoShapePy::Type), &pcObjShape, - &(Base::VectorPy::Type), &pcObjDir, &type, &scale)) + if (!PyArg_ParseTuple(args, "O!|O!sff", &(TopoShapePy::Type), &pcObjShape, + &(Base::VectorPy::Type), &pcObjDir, &type, &scale, &tol)) return NULL; PY_TRY { @@ -150,7 +152,7 @@ projectToDXF(PyObject *self, PyObject *args) if (type && std::string(type) == "ShowHiddenLines") hidden = true; - Py::String result(Alg.getDXF(hidden?ProjectionAlgos::WithHidden:ProjectionAlgos::Plain, scale)); + Py::String result(Alg.getDXF(hidden?ProjectionAlgos::WithHidden:ProjectionAlgos::Plain, scale, tol)); return Py::new_reference_to(result); } PY_CATCH; diff --git a/src/Mod/Drawing/App/FeatureViewPart.cpp b/src/Mod/Drawing/App/FeatureViewPart.cpp index 0eee19f3a..93d201c62 100644 --- a/src/Mod/Drawing/App/FeatureViewPart.cpp +++ b/src/Mod/Drawing/App/FeatureViewPart.cpp @@ -70,6 +70,8 @@ using namespace std; // FeatureViewPart //=========================================================================== +App::PropertyFloatConstraint::Constraints FeatureViewPart::floatRange = {0.01f,5.0f,0.05f}; + PROPERTY_SOURCE(Drawing::FeatureViewPart, Drawing::FeatureView) @@ -83,6 +85,8 @@ FeatureViewPart::FeatureViewPart(void) ADD_PROPERTY_TYPE(ShowHiddenLines ,(false),group,App::Prop_None,"Control the appearance of the dashed hidden lines"); ADD_PROPERTY_TYPE(ShowSmoothLines ,(false),group,App::Prop_None,"Control the appearance of the smooth lines"); ADD_PROPERTY_TYPE(LineWidth,(0.35f),vgroup,App::Prop_None,"The thickness of the resulting lines"); + ADD_PROPERTY_TYPE(Tolerance,(0.05f),vgroup,App::Prop_None,"The tessellation tolerance"); + Tolerance.setConstraints(&floatRange); } FeatureViewPart::~FeatureViewPart() @@ -198,7 +202,7 @@ App::DocumentObjectExecReturn *FeatureViewPart::execute(void) ProjectionAlgos::SvgExtractionType type = ProjectionAlgos::Plain; if (hidden) type = (ProjectionAlgos::SvgExtractionType)(type|ProjectionAlgos::WithHidden); if (smooth) type = (ProjectionAlgos::SvgExtractionType)(type|ProjectionAlgos::WithSmooth); - result << Alg.getSVG(type, this->LineWidth.getValue() / this->Scale.getValue()); + result << Alg.getSVG(type, this->LineWidth.getValue() / this->Scale.getValue(), this->Tolerance.getValue()); result << "" << endl; diff --git a/src/Mod/Drawing/App/FeatureViewPart.h b/src/Mod/Drawing/App/FeatureViewPart.h index 68ad3551f..6a47fbcb4 100644 --- a/src/Mod/Drawing/App/FeatureViewPart.h +++ b/src/Mod/Drawing/App/FeatureViewPart.h @@ -53,7 +53,8 @@ public: App::PropertyBool ShowHiddenLines; App::PropertyBool ShowSmoothLines; App::PropertyFloat LineWidth; - + App::PropertyFloatConstraint Tolerance; + /** @name methods overide Feature */ //@{ @@ -65,6 +66,9 @@ public: virtual const char* getViewProviderName(void) const { return "DrawingGui::ViewProviderDrawingView"; } + +private: + static App::PropertyFloatConstraint::Constraints floatRange; }; typedef App::FeaturePythonT FeatureViewPartPython; diff --git a/src/Mod/Drawing/App/ProjectionAlgos.cpp b/src/Mod/Drawing/App/ProjectionAlgos.cpp index b37c6cb48..0e99c76e6 100644 --- a/src/Mod/Drawing/App/ProjectionAlgos.cpp +++ b/src/Mod/Drawing/App/ProjectionAlgos.cpp @@ -149,7 +149,7 @@ void ProjectionAlgos::execute(void) } -std::string ProjectionAlgos::getSVG(SvgExtractionType type, float scale) +std::string ProjectionAlgos::getSVG(SvgExtractionType type, float scale, float tolerance) { std::stringstream result; SVGOutput output; @@ -187,7 +187,7 @@ std::string ProjectionAlgos::getSVG(SvgExtractionType type, float scale) } if (!VO.IsNull()) { float width = scale; - BRepMesh::Mesh(VO,0.1); + BRepMesh::Mesh(VO,tolerance); result << "