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()
This commit is contained in:
@@ -90,7 +90,7 @@
|
|||||||
((double,units,Unit,1.0,"Scaling factor for conversion to inch",App::PropertyFloat))\
|
((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,min_arc_points,MinArcPoints,4,"Minimum segments for arc discretization"))\
|
||||||
((short,max_arc_points,MaxArcPoints,100,"Maximum 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"\
|
"ClipperLib operate on intergers. This is the scale factor to convert\n"\
|
||||||
"floating points.",App::PropertyFloat))
|
"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"\
|
((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"\
|
"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))\
|
"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"\
|
"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.",\
|
"will be created. A small offset is usually required to avoid the tagnetial cut.",\
|
||||||
App::PropertyPrecision))\
|
App::PropertyPrecision))\
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
#ifndef _PreComp_
|
#ifndef _PreComp_
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#include <cinttypes>
|
||||||
|
#include <iomanip>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <Base/Vector3D.h>
|
#include <Base/Vector3D.h>
|
||||||
@@ -99,12 +101,33 @@ bool Command::has(const std::string& attr) const
|
|||||||
std::string Command::toGCode (int precision, bool padzero) const
|
std::string Command::toGCode (int precision, bool padzero) const
|
||||||
{
|
{
|
||||||
std::stringstream str;
|
std::stringstream str;
|
||||||
if(padzero) str.setf(std::ios::fixed);
|
str.fill('0');
|
||||||
str.precision(precision);
|
|
||||||
str << Name;
|
str << Name;
|
||||||
|
if(precision<=0)
|
||||||
|
precision = 1;
|
||||||
|
double scale = std::pow(10.0,precision);
|
||||||
|
std::int64_t iscale = static_cast<std::int64_t>(scale)/10;
|
||||||
for(std::map<std::string,double>::const_iterator i = Parameters.begin(); i != Parameters.end(); ++i) {
|
for(std::map<std::string,double>::const_iterator i = Parameters.begin(); i != Parameters.end(); ++i) {
|
||||||
if(i->first == "N") continue;
|
if(i->first == "N") continue;
|
||||||
str << " " << i->first << i->second;
|
|
||||||
|
std::int64_t v = static_cast<std::int64_t>(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();
|
return str.str();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user