You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
5.6 KiB
150 lines
5.6 KiB
|
3 years ago
|
import FreeCAD as App
|
||
|
|
import numpy as np
|
||
|
|
from . import kuka
|
||
|
|
|
||
|
|
|
||
|
|
class LaserPad:
|
||
|
|
def __init__(self, obj, face):
|
||
|
|
'''Add some custom properties to our box feature'''
|
||
|
|
obj.addProperty("App::PropertyEnumeration", "pathtype", "SlicingParameters", "Type of Path generation (slice, etc)")
|
||
|
|
obj.pathtype = ["sliced", "auto", "wire"]
|
||
|
|
|
||
|
|
obj.addProperty("App::PropertyEnumeration", "slicedirection", "SlicingParameters", "When Slicing, which direction to use")
|
||
|
|
obj.slicedirection = ["xaxis", "yaxis", "zaxis", "custom"]
|
||
|
|
|
||
|
|
obj.addProperty("App::PropertyLinkSub","ref_surface","SlicingParameters","reference_1")
|
||
|
|
obj.ref_surface = face
|
||
|
|
|
||
|
|
obj.Proxy = self
|
||
|
|
|
||
|
|
def onChanged(self, fp, prop):
|
||
|
|
'''Do something when a property has changed'''
|
||
|
|
App.Console.PrintMessage("Change property: " + str(prop) + "\n")
|
||
|
|
|
||
|
|
def execute(self, fp):
|
||
|
|
'''Do something when doing a recomputation, this method is mandatory'''
|
||
|
|
App.Console.PrintMessage("Recompute LaserPad\n")
|
||
|
|
face = fp.ref_surface[0].getSubObject(fp.ref_surface[1])[0]
|
||
|
|
print(face)
|
||
|
|
|
||
|
|
if fp.pathtype == "sliced":
|
||
|
|
xmin = face.BoundBox.XMin
|
||
|
|
xmax = face.BoundBox.XMax
|
||
|
|
ymin = face.BoundBox.YMin
|
||
|
|
ymax = face.BoundBox.YMax
|
||
|
|
slice_direction = App.Vector(0,0,0)
|
||
|
|
if fp.slicedirection == "xaxis":
|
||
|
|
slice_direction = App.Vector(1,0,0)
|
||
|
|
pmin, pmax = xmin, xmax
|
||
|
|
if fp.slicedirection == "yaxis":
|
||
|
|
slice_direction = App.Vector(0,1,0)
|
||
|
|
pmin, pmax = ymin, ymax
|
||
|
|
if fp.slicedirection == "zaxis":
|
||
|
|
slice_direction = App.Vector(0,0,1)
|
||
|
|
pmin, pmax = zmin, zmax
|
||
|
|
|
||
|
|
slices = face.slices(slice_direction, [x for x in np.arange(pmin, pmax, 2)])
|
||
|
|
|
||
|
|
prog = kuka.Kuka_Prog()
|
||
|
|
for edge in slices.Edges:
|
||
|
|
poses = kuka.get_list_of_poses(face, edge, 10)
|
||
|
|
prog.append_poses(poses)
|
||
|
|
prog.draw_wire()
|
||
|
|
prog.save_prog("/home/jk/test_export_workbench")
|
||
|
|
|
||
|
|
|
||
|
|
### helper to create some object
|
||
|
|
def create_laserpad(face):
|
||
|
|
laserjob_entry = App.ActiveDocument.getObject('LaserJob')
|
||
|
|
if laserjob_entry is None:
|
||
|
|
App.Console.PrintMessage('Create a LaserJob first')
|
||
|
|
return
|
||
|
|
pad_obj = App.ActiveDocument.addObject("App::FeaturePython","LaserPad")
|
||
|
|
pad = LaserPad(pad_obj, face)
|
||
|
|
#a=laserjob_entry.addObbject(pad)
|
||
|
|
ViewProviderLaserPad(pad.ViewProvider)
|
||
|
|
return pad
|
||
|
|
|
||
|
|
|
||
|
|
class ViewProviderLaserPad:
|
||
|
|
def __init__(self, obj):
|
||
|
|
'''Set this object to the proxy object of the actual view provider'''
|
||
|
|
obj.addProperty("App::PropertyColor","Color","Box","Color of the box").Color=(1.0,0.0,0.0)
|
||
|
|
obj.Proxy = self
|
||
|
|
|
||
|
|
def attach(self, obj):
|
||
|
|
'''Setup the scene sub-graph of the view provider, this method is mandatory'''
|
||
|
|
self.onChanged(obj,"Color")
|
||
|
|
|
||
|
|
def updateData(self, fp, prop):
|
||
|
|
'''If a property of the handled feature has changed we have the chance to handle this here'''
|
||
|
|
# fp is the handled feature, prop is the name of the property that has changed
|
||
|
|
pass
|
||
|
|
|
||
|
|
def getDisplayModes(self,obj):
|
||
|
|
'''Return a list of display modes.'''
|
||
|
|
modes=[]
|
||
|
|
modes.append("Shaded")
|
||
|
|
modes.append("Wireframe")
|
||
|
|
return modes
|
||
|
|
|
||
|
|
def getDefaultDisplayMode(self):
|
||
|
|
'''Return the name of the default display mode. It must be defined in getDisplayModes.'''
|
||
|
|
return "Shaded"
|
||
|
|
|
||
|
|
def setDisplayMode(self,mode):
|
||
|
|
'''Map the display mode defined in attach with those defined in getDisplayModes.\
|
||
|
|
Since they have the same names nothing needs to be done. This method is optional'''
|
||
|
|
return mode
|
||
|
|
|
||
|
|
def onChanged(self, vp, prop):
|
||
|
|
'''Here we can do something when a single property got changed'''
|
||
|
|
App.Console.PrintMessage("Change property: " + str(prop) + "\n")
|
||
|
|
#if prop == "Color":
|
||
|
|
# c = vp.getPropertyByName("Color")
|
||
|
|
# self.color.rgb.setValue(c[0],c[1],c[2])
|
||
|
|
|
||
|
|
def getIcon(self):
|
||
|
|
'''Return the icon in XPM format which will appear in the tree view. This method is\
|
||
|
|
optional and if not defined a default icon is shown.'''
|
||
|
|
return """
|
||
|
|
/* XPM */
|
||
|
|
static const char * ViewProviderBox_xpm[] = {
|
||
|
|
"16 16 6 1",
|
||
|
|
" c None",
|
||
|
|
". c #141010",
|
||
|
|
"+ c #615BD2",
|
||
|
|
"@ c #C39D55",
|
||
|
|
"# c #000000",
|
||
|
|
"$ c #57C355",
|
||
|
|
" ........",
|
||
|
|
" ......++..+..",
|
||
|
|
" .@@@@.++..++.",
|
||
|
|
" .@@@@.++..++.",
|
||
|
|
" .@@ .++++++.",
|
||
|
|
" ..@@ .++..++.",
|
||
|
|
"###@@@@ .++..++.",
|
||
|
|
"##$.@@$#.++++++.",
|
||
|
|
"#$#$.$$$........",
|
||
|
|
"#$$####### ",
|
||
|
|
"#$$#$$$$$# ",
|
||
|
|
"#$$#$$$$$# ",
|
||
|
|
"#$$#$$$$$# ",
|
||
|
|
" #$#$$$$$# ",
|
||
|
|
" ##$$$$$# ",
|
||
|
|
" ####### "};
|
||
|
|
"""
|
||
|
|
|
||
|
|
def __getstate__(self):
|
||
|
|
'''When saving the document this object gets stored using Python's json module.\
|
||
|
|
Since we have some un-serializable parts here -- the Coin stuff -- we must define this method\
|
||
|
|
to return a tuple of all serializable objects or None.'''
|
||
|
|
return None
|
||
|
|
|
||
|
|
def __setstate__(self,state):
|
||
|
|
'''When restoring the serialized object from document we have the chance to set some internals here.\
|
||
|
|
Since no data were serialized nothing needs to be done here.'''
|
||
|
|
return None
|
||
|
|
|
||
|
|
|