# -*- coding: utf-8 -*-

__Name__ = 'LasercutterSVGExport'
__Comment__ = 'Creates contour lines for all selected objects and arranges them on a TechDraw page'
__Author__ = 'christi'
__Version__ = '0.7.0'
__Date__ = '2022-03-03'
__License__ = 'LGPL-3.0-or-later'
__Web__ = 'https://github.com/FreeCAD/FreeCAD-macros/tree/master/TechDraw'
__Wiki__ = 'https://github.com/FreeCAD/FreeCAD-macros/tree/master/TechDraw/LasercutterSVGExport'
__Icon__ = 'LasercutterSVGExport.svg'
__Help__ = 'LasercutterSVGExport/README.md'
__Status__ = 'Alpha'
__Requires__ = 'FreeCAD >= v0.18'
__Communication__ = 'https://forum.freecadweb.org/viewtopic.php?f=15&t=31796'
__Files__ = 'LasercutterSVGExport/LasercutterTechdrawExport.py,LasercutterSVGExport/README.md,LasercutterSVGExport/LasercutterSVGExport_screenshot.png,LasercutterSVGExport/lasercuttersvg.ui,LasercutterSVGExport.svg'

# compatible to Python 3

import FreeCAD as app
import FreeCADGui as gui
from LasercutterSVGExport import LasercutterTechdrawExport

iconPath = os.path.dirname(__file__)


class LasercutterSVGExport():
    def Activated(self):
        '''Will be called when the feature is executed.'''
        self.ui_file = os.path.join(iconPath, 'LasercutterSVGExport', 'lasercuttersvg.ui')
        self.form = gui.PySideUic.loadUi(self.ui_file)
        self.form.pushButton.pressed.connect(self.makeExport)
        self.form.show()

    def IsActive(self):
        '''Here you can define if the command must be active or not (greyed) if certain conditions
        are met or not. This function is optional.'''
        if app.activeDocument():
            return(True)
        else:
            return(False)

    def makeExport(self):
        # Generate commands in the FreeCAD python console to create LasercutterTechdrawExport
        gui.doCommand('from LasercutterSVGExport import LasercutterTechdrawExport')

        gui.doCommand('lcparts = []')
        selection = gui.Selection.getSelectionEx()
        for sel in selection:
            gui.doCommand("lcparts.append(FreeCAD.ActiveDocument.getObject('%s'))"%(sel.ObjectName))

        gui.doCommand(f'LasercutterTechdrawExport.makeLasercutterTechdrawExport(lcparts, BeamWidth={self.form.doubleSpinBox.value()}, doc=FreeCAD.activeDocument())')
        self.form.close()


if __name__ == '__main__':
	lc = LasercutterSVGExport()
	lc.Activated()
