|
|
|
|
import FreeCAD as App
|
|
|
|
|
import FreeCADGui as Gui
|
|
|
|
|
import Part
|
|
|
|
|
import os
|
|
|
|
|
import re
|
|
|
|
|
import copy
|
|
|
|
|
|
|
|
|
|
from .program import LaserProgram, ViewProviderLaserProgram
|
|
|
|
|
from .pad import LaserPad, ViewProviderLaserPad
|
|
|
|
|
from .kuka import Kuka_Prog, Kuka_Pose, get_list_of_poses
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LCCreateProgram():
|
|
|
|
|
def Activated(self):
|
|
|
|
|
# Here your write what your ScriptCmd does...
|
|
|
|
|
App.Console.PrintMessage('Create Lasser Cladding Program')
|
|
|
|
|
a=App.ActiveDocument.addObject("App::FeaturePython","LaserProgram")
|
|
|
|
|
LaserProgram(a)
|
|
|
|
|
ViewProviderLaserProgram(a.ViewObject)
|
|
|
|
|
|
|
|
|
|
def GetResources(self):
|
|
|
|
|
return {'Pixmap' : ":icons/LaserCreateProg.svg", 'MenuText': 'Create Laser Program', 'ToolTip': 'Add a Laser Program to your Document'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LCSelectBaseReference():
|
|
|
|
|
def Activated(self):
|
|
|
|
|
# Here your write what your ScriptCmd does...
|
|
|
|
|
App.Console.PrintMessage('Select Base reference!')
|
|
|
|
|
if not Gui.Selection.hasSelection():
|
|
|
|
|
App.Console.PrintMessage('Select a Vertex')
|
|
|
|
|
return
|
|
|
|
|
# check length
|
|
|
|
|
selection = Gui.Selection.getSelectionEx()
|
|
|
|
|
# find first vertex
|
|
|
|
|
for s in selection:
|
|
|
|
|
if s.HasSubObjects:
|
|
|
|
|
for obj in s.SubObjects:
|
|
|
|
|
if isinstance(obj, Part.Vertex):
|
|
|
|
|
vertex = obj.copy()
|
|
|
|
|
laserjob_entry = App.ActiveDocument.getObject('LaserProgram')
|
|
|
|
|
if laserjob_entry is None:
|
|
|
|
|
App.Console.PrintMessage('Create a LaserJob first')
|
|
|
|
|
return
|
|
|
|
|
laserjob_entry.base_reference = App.Vector((vertex.X, vertex.Y, vertex.Z))
|
|
|
|
|
App.ActiveDocument.recompute()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def GetResources(self):
|
|
|
|
|
return {'Pixmap' : ":icons/LaserSelectBaseRef.svg",
|
|
|
|
|
'MenuText': 'Select Base reference',
|
|
|
|
|
'ToolTip': 'Add a Job to your Document'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LCCreatePad():
|
|
|
|
|
|
|
|
|
|
def _create_laserpad(self, ref_to_face):
|
|
|
|
|
laserprogram = App.ActiveDocument.getObject('LaserProgram')
|
|
|
|
|
if laserprogram is None:
|
|
|
|
|
App.Console.PrintMessage('Create a LaserProgram first')
|
|
|
|
|
return
|
|
|
|
|
pad_obj = laserprogram.newObject("App::FeaturePython","LaserPad")
|
|
|
|
|
LaserPad(pad_obj, ref_to_face)
|
|
|
|
|
ViewProviderLaserPad(pad_obj.ViewObject)
|
|
|
|
|
return pad_obj
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def Activated(self):
|
|
|
|
|
# Here your write what your ScriptCmd does...
|
|
|
|
|
App.Console.PrintMessage('Select some Face as reference')
|
|
|
|
|
if not Gui.Selection.hasSelection():
|
|
|
|
|
App.Console.PrintMessage('Select a Face')
|
|
|
|
|
return
|
|
|
|
|
# check length
|
|
|
|
|
ref_face = (Gui.Selection.getSelection()[0],
|
|
|
|
|
Gui.Selection.getSelectionEx()[0].SubElementNames[0])
|
|
|
|
|
#selection = Gui.Selection.getSelectionEx()
|
|
|
|
|
# find first vertex
|
|
|
|
|
#for s in selection:
|
|
|
|
|
# if s.HasSubObjects:
|
|
|
|
|
# for obj in s.SubObjects:
|
|
|
|
|
# if isinstance(obj, Part.Face):
|
|
|
|
|
# face = obj.copy()
|
|
|
|
|
self._create_laserpad(ref_face)
|
|
|
|
|
App.ActiveDocument.recompute()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def GetResources(self):
|
|
|
|
|
return {'Pixmap' : ":icons/LaserCreatePad.svg", 'MenuText': 'Create Pad', 'ToolTip': 'Create a Pad on selected face'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LCRecompute():
|
|
|
|
|
|
|
|
|
|
def Activated(self):
|
|
|
|
|
# Here your write what your ScriptCmd does...
|
|
|
|
|
App.Console.PrintMessage('Recomputer Pads')
|
|
|
|
|
if not Gui.Selection.hasSelection():
|
|
|
|
|
App.Console.PrintMessage('Select a Pad')
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if Gui.Selection.hasSelection():
|
|
|
|
|
laser_path_obj = Gui.Selection.getSelection()[0]
|
|
|
|
|
if len(laser_path_obj.Group):
|
|
|
|
|
laser_path_obj.removeObjectsFromDocument()
|
|
|
|
|
laser_path_obj.Proxy._create_path(laser_path_obj)
|
|
|
|
|
App.ActiveDocument.recompute()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def GetResources(self):
|
|
|
|
|
return {'Pixmap' : ":icons/LaserRecomputePad.svg",
|
|
|
|
|
'MenuText': 'Recompute',
|
|
|
|
|
'ToolTip': 'Recompute selected Pads'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LCSaveProg():
|
|
|
|
|
|
|
|
|
|
def Activated(self):
|
|
|
|
|
# Here your write what your ScriptCmd does...
|
|
|
|
|
App.Console.PrintMessage('Saving to KRL')
|
|
|
|
|
c = App.ActiveDocument.getObject("LaserProgram")
|
|
|
|
|
pads = c.Group
|
|
|
|
|
prog = Kuka_Prog()
|
|
|
|
|
prog.set_baseorigin(c.base_reference)
|
|
|
|
|
prog.set_tool(c.rob_tool)
|
|
|
|
|
prog.set_base(c.rob_base)
|
|
|
|
|
prog.set_velocity(c.laser_feedrate, c.laser_speed)
|
|
|
|
|
prog.set_laser_power(c.laser_power)
|
|
|
|
|
prog.set_laser_out(c.laser_real_out)
|
|
|
|
|
prog.set_simulation(c.simulation)
|
|
|
|
|
|
|
|
|
|
for pad in pads:
|
|
|
|
|
# one pad with contours and hatchlines
|
|
|
|
|
for progpart in pad.Group:
|
|
|
|
|
## jedes Contour oder Hatchline Feature
|
|
|
|
|
if re.match('Contour*', progpart.Name):
|
|
|
|
|
# do Conoutes
|
|
|
|
|
face = pad.ref_body.getSubObject(pad.ref_surface)
|
|
|
|
|
edges = Part.__sortEdges__(progpart.Shape.Edges)
|
|
|
|
|
vlist = []
|
|
|
|
|
for edge in edges:
|
|
|
|
|
vlist.extend([v.Point for v in edge.Vertexes])
|
|
|
|
|
poly = Part.makePolygon(vlist)
|
|
|
|
|
#Part.show(poly, "ContourPath")
|
|
|
|
|
poses = get_list_of_poses(face, poly.Edges)
|
|
|
|
|
prog.append_contour(poses, progpart.pathtype)
|
|
|
|
|
elif re.match('Hatch*', progpart.Name):
|
|
|
|
|
face = pad.ref_body.getSubObject(pad.ref_surface)
|
|
|
|
|
edges = progpart.Shape.Edges
|
|
|
|
|
for edge in edges:
|
|
|
|
|
p0 = edge.Vertexes[0].Point
|
|
|
|
|
p1 = edge.Vertexes[1].Point
|
|
|
|
|
line = []
|
|
|
|
|
for p in [p0, p1]:
|
|
|
|
|
uv = face.Surface.parameter(p)
|
|
|
|
|
normal = face.normalAt(uv[0], uv[1])
|
|
|
|
|
pose = Kuka_Pose.from_point_and_normal(p, normal)
|
|
|
|
|
line.append(pose)
|
|
|
|
|
prog.append_hatchline(line, progpart.pathtype)
|
|
|
|
|
|
|
|
|
|
prog.save_prog(c.progpath)
|
|
|
|
|
App.ActiveDocument.recompute()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def GetResources(self):
|
|
|
|
|
return {'Pixmap' : ":icons/LaserSaveProg.svg",
|
|
|
|
|
'MenuText': 'Save Program',
|
|
|
|
|
'ToolTip': 'Save the Program as KRL'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Gui.addCommand('LCCreateProgram', LCCreateProgram())
|
|
|
|
|
Gui.addCommand('LCSelectBaseReference', LCSelectBaseReference())
|
|
|
|
|
Gui.addCommand('LCCreatePad', LCCreatePad())
|
|
|
|
|
Gui.addCommand('LCRecompute', LCRecompute())
|
|
|
|
|
Gui.addCommand('LCSaveProg', LCSaveProg())
|