Skip to content

Commit

Permalink
Merge branch 'release/1.3.5_Simon'
Browse files Browse the repository at this point in the history
  • Loading branch information
blesscat committed Aug 24, 2017
2 parents 081269a + 26be41d commit b5cd845
Show file tree
Hide file tree
Showing 51 changed files with 3,886 additions and 14,114 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ src/scanner/PoissonRecon/vbfile
tests/scanner/data/inso

# file that Cython generate
src/toolpath/_toolpath.cpp
src/scanner/scanner.cpp
src/printer/printer.cpp
src/utils/utils.cpp
Expand Down
2 changes: 1 addition & 1 deletion fluxclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def check_platform():
p = "OSX"
return (p, platform.architecture()[0])

__version__ = "1.2.6"
__version__ = "1.3.4"
SUPPORT_PCL = check_pcl()
131 changes: 69 additions & 62 deletions fluxclient/commands/fcode.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@

from getpass import getuser
import argparse
import time
import sys
import os

from io import BytesIO, StringIO
# from io import StringIO

PROG_DESCRIPTION = 'Flux fcode/gcode convertor.'
PROG_EPILOG = ''


def create_fcode_metadata(options):
from fluxclient import __version__

title = os.path.splitext(os.path.basename(options.input))[0]

md = {
"AUTHOR": getuser(),
"TITLE": title,
"SOFTWARE": "fluxclient-%s-G2F-CLI" % __version__,
"CREATED_AT": time.strftime('%Y-%m-%dT%H:%M:%SZ',
time.localtime(time.time())),
}

if options.head_error_level is not None:
md['HEAD_ERROR_LEVEL'] = str(options.head_error_level)
if options.correction is not None:
md['CORRECTION'] = str(options.correction)
if options.filament_detect is not None:
md['FILAMENT_DETECT'] = str(options.filament_detect)
md['BACKLASH'] = 'Y'

if options.preview and os.path.isfile(options.preview):
try:
with open(options.preview, "rb") as f:
previews = (f.read(), )
except Exception:
previews = ()
else:
previews = ()

return md, previews


def gcode_2_fcode(params=None, input=None, output=None):
parser = argparse.ArgumentParser(description=PROG_DESCRIPTION,
epilog=PROG_EPILOG)
Expand All @@ -17,6 +53,9 @@ def gcode_2_fcode(params=None, input=None, output=None):
default='EXTRUDER', choices=['EXTRUDER', 'LASER',
'N/A'],
help='Set toolhead type, default is EXTRUDER')
parser.add_argument('-p', '--preview', dest='preview', type=str,
default=None, help='Set preview image')

parser.add_argument('--cor', dest='correction', type=str,
default=None, choices=['A', 'H', 'N'],
help='Set correction, A=ALL, H=Do height only, N=No'
Expand All @@ -26,85 +65,53 @@ def gcode_2_fcode(params=None, input=None, output=None):
parser.add_argument('--fmd', dest='filament_detect', type=str,
default=None, choices=['Y', 'N'],
help='Set filament detect, only for extruder type')
parser.add_argument(dest='output', type=str, nargs="?",

parser.add_argument(dest='output', type=str,
help='Ouput fcode file')

options = parser.parse_args(params)

from fluxclient.utils._utils import GcodeToFcodeCpp
from fluxclient.fcode.g_to_f import GcodeToFcode

ext_metadata = {}
if options.head_error_level is not None:
ext_metadata['HEAD_ERROR_LEVEL'] = str(options.head_error_level)
if options.correction is not None:
ext_metadata['CORRECTION'] = str(options.correction)
if options.filament_detect is not None:
ext_metadata['FILAMENT_DETECT'] = str(options.filament_detect)
if options.head_type is not None:
ext_metadata['HEAD_TYPE'] = str(options.head_type)

try:
if options.input:
input = open(options.input, 'r')

if options.output:
output = BytesIO()
else:
output = sys.stdout.buffer

if not input:
input = sys.stdin

conv = GcodeToFcodeCpp(ext_metadata=ext_metadata)
conv.process(input, output)

from fluxclient.toolpath import GCodeParser, FCodeV1FileWriter

f = open(options.output, "wb");
f.write(output.getvalue())
output = f
md, previews = create_fcode_metadata(options)

print(str(conv.md))
parser = GCodeParser()
processor = FCodeV1FileWriter(
options.output, options.head_type, md, previews)
parser.set_processor(processor)
parser.parse_from_file(options.input)
processor.terminated()

finally:
input.close()
output.close()
errors = processor.errors()
if errors:
for err in errors:
sys.stderr.write(err.decode())
sys.stderr.write("\n")


def fcode_2_gcode(params=None, input=None, output=sys.stdout):
parser = argparse.ArgumentParser(description=PROG_DESCRIPTION,
epilog=PROG_EPILOG)
parser.add_argument('-i', dest='input', type=str,
help='Input fcode file')
# parser.add_argument('-I', dest='--include-preview', action='store_const',
# const=True, default=False,
# help='Output preview images')
parser.add_argument(dest='output', type=str, nargs="?",
parser.add_argument('-p', '--unpack-preview', dest="unpack_preview",
action='store_const', const=True, default=False,
help='Output preview images')
parser.add_argument(dest='output', type=str,
help='Output gcode file')

options = parser.parse_args(params)

from fluxclient.fcode.f_to_g import FcodeToGcode
from fluxclient.toolpath import FCodeParser, GCodeFileWriter

try:
if options.input:
input = open(options.input, "rb")
processor = GCodeFileWriter(options.output)
metadata, previews = FCodeParser.from_file(options.input, processor)

if options.output:
output = open(options.output, "w+")
if options.unpack_preview:
if previews:
basename, _ = os.path.splitext(options.output)
with open(basename + ".jpg", "wb") as f:
f.write(previews[0])
else:
output = sys.stdout.buffer

if not input:
input = sys.stdin.buffer

parser = FcodeToGcode()
res = parser.upload_content(input.read())
print("Check file:: " + str(res));
tmp_output = StringIO()
parser.f_to_g(tmp_output, include_meta=True)
gcode = tmp_output.getvalue();
output.write(gcode)
finally:
input.close()
output.close()
sys.stderr.write("No previews to unpack\n")
processor.terminated()
Loading

0 comments on commit b5cd845

Please sign in to comment.