From 0e9c1c076e311f2c3903cfa9de87c8c88daa79de Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sun, 28 May 2017 11:20:39 +0800 Subject: [PATCH] Path.Command: rounding instead of truncate in toGCode Also changed default Path.Area pareameter ClipperScale to 1e6 which corresponds to the default 5 digits output of Path.Command toGCode() --- src/Mod/Path/App/AreaParams.h | 4 ++-- src/Mod/Path/App/Command.cpp | 29 ++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Mod/Path/App/AreaParams.h b/src/Mod/Path/App/AreaParams.h index 0291de2baa..8e6922a2c7 100644 --- a/src/Mod/Path/App/AreaParams.h +++ b/src/Mod/Path/App/AreaParams.h @@ -90,7 +90,7 @@ ((double,units,Unit,1.0,"Scaling factor for conversion to inch",App::PropertyFloat))\ ((short,min_arc_points,MinArcPoints,4,"Minimum segments for arc discretization"))\ ((short,max_arc_points,MaxArcPoints,100,"Maximum segments for arc discretization"))\ - ((double,clipper_scale,ClipperScale,10000.0,\ + ((double,clipper_scale,ClipperScale,1e6,\ "ClipperLib operate on intergers. This is the scale factor to convert\n"\ "floating points.",App::PropertyFloat)) @@ -150,7 +150,7 @@ ((double,offset,SectionOffset,0.0,"Offset for the first section. The direction of the offset is\n"\ "determined by the section direction (i.e. the signess of Stepdown). If going from top down,\n"\ "a positive value means offset downward, and if bottom up, it means upward",App::PropertyDistance))\ - ((double,tolerance,SectionTolerance,1e-5,"Offset value added when hitting the boundary.\n"\ + ((double,tolerance,SectionTolerance,1e-6,"Offset value added when hitting the boundary.\n"\ "When the section hits or over the shape boundary, a section with the height of that boundary\n"\ "will be created. A small offset is usually required to avoid the tagnetial cut.",\ App::PropertyPrecision))\ diff --git a/src/Mod/Path/App/Command.cpp b/src/Mod/Path/App/Command.cpp index 4dab7f1cd0..7c8bc1acb7 100644 --- a/src/Mod/Path/App/Command.cpp +++ b/src/Mod/Path/App/Command.cpp @@ -26,6 +26,8 @@ #ifndef _PreComp_ #endif +#include +#include #include #include #include @@ -99,12 +101,33 @@ bool Command::has(const std::string& attr) const std::string Command::toGCode (int precision, bool padzero) const { std::stringstream str; - if(padzero) str.setf(std::ios::fixed); - str.precision(precision); + str.fill('0'); str << Name; + if(precision<=0) + precision = 1; + double scale = std::pow(10.0,precision); + std::int64_t iscale = static_cast(scale)/10; for(std::map::const_iterator i = Parameters.begin(); i != Parameters.end(); ++i) { if(i->first == "N") continue; - str << " " << i->first << i->second; + + std::int64_t v = static_cast(i->second*scale); + if(v>=0) + v+=5; + else + v-=5; + v /= 10; + str << " " << i->first << (v/iscale); + if(precision==1) continue; + int width = precision-1; + std::int64_t digits = v%iscale; + if(!padzero) { + if(!digits) continue; + while(digits%10 == 0) { + digits/=10; + --width; + } + } + str << '.' << std::setw(width) << std::right << digits; } return str.str(); }