# Path: drawingDimensioning/py3_helpers.py
# def map(function, arg):
#     return list(_map(function, arg))


from drawingDimensioning.command import *
from drawingDimensioning.py3_helpers import map
    from drawingDimensioning.XMLlib import SvgXMLTreeNode
    from drawingDimensioning.svgLib import SvgTextParser, SvgPath, SvgPolygon
    from drawingDimensioning.circleLib import fitCircle_to_path, findCircularArcCentrePoint, pointsAlongCircularArc
    from numpy import arctan2
    from dxfwrite import DXFEngine as dxf
import subprocess
            #export_via_pstoedit( dxf_fn, V)

    def GetResources(self): 
        #menuText = 'shortcut command for exporting active drawing page to dxf (requires inkscape and pstoedit)'
        menuText = 'alternative dxf export command which uses the dxfwrite python library'
        return {
            'Pixmap' : ':/dd/icons/exportToDxf.svg',
            'MenuText': menuText, 
            } 

FreeCADGui.addCommand('dd_exportToDxf', ExportToDxfCommand())


def shellCmd(cmd, callDirectory=None):
    debugPrint(3,'$' + cmd)
    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=callDirectory)
    stdout, stderr = p.communicate()
    if stdout != '':
        debugPrint(3,'stdout:%s' % stdout )
    if p.returncode != 0:
        raise RuntimeError('$ %s \n STDERR:%s' % (cmd, stderr))
    return stdout


def export_via_pstoedit( dxf_fn, V):
    eps_fn = dxf_fn[:-4] + '.eps'
    if os.path.exists(eps_fn):
        raise RuntimeError("eps file (%s) exists, aborting operation" % eps_fn)
    V.page.PageResult
    shellCmd('inkscape -f %s -E %s' % (V.page.PageResult, eps_fn)) #circle maintained after this step

# Path: drawingDimensioning/py3_helpers.py
# def map(function, arg):
#     return list(_map(function, arg))


# Path: drawingDimensioning/unfold/export_to_dxf.py
from drawingDimensioning.command import *
from drawingDimensioning.py3_helpers import map
    from drawingDimensioning.XMLlib import SvgXMLTreeNode
    from drawingDimensioning.svgLib import SvgTextParser, SvgPath, SvgPolygon
    from drawingDimensioning.circleLib import fitCircle_to_path, findCircularArcCentrePoint, pointsAlongCircularArc
    from numpy import arctan2
    from dxfwrite import DXFEngine as dxf
import subprocess

            #export_via_pstoedit( dxf_fn, V)

    def GetResources(self): 
        #menuText = 'shortcut command for exporting active drawing page to dxf (requires inkscape and pstoedit)'
        menuText = 'alternative dxf export command which uses the dxfwrite python library'
        return {
            'Pixmap' : ':/dd/icons/exportToDxf.svg',
            'MenuText': menuText, 
            } 

FreeCADGui.addCommand('dd_exportToDxf', ExportToDxfCommand())


def shellCmd(cmd, callDirectory=None):
    debugPrint(3,'$' + cmd)
    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=callDirectory)
    stdout, stderr = p.communicate()
    if stdout != '':
        debugPrint(3,'stdout:%s' % stdout )
    if p.returncode != 0:
        raise RuntimeError('$ %s \n STDERR:%s' % (cmd, stderr))
    return stdout


def export_via_pstoedit( dxf_fn, V):
    eps_fn = dxf_fn[:-4] + '.eps'
    if os.path.exists(eps_fn):
        raise RuntimeError("eps file (%s) exists, aborting operation" % eps_fn)
    V.page.PageResult
    shellCmd('inkscape -f %s -E %s' % (V.page.PageResult, eps_fn)) #circle maintained after this step

    try: