Compare commits

..

No commits in common. "6b1f8f007414547ae99d87507daf074934110937" and "784a41cb9904eefb308ac2384b04b03eed091c68" have entirely different histories.

View file

@ -18,84 +18,63 @@ class FlatpackGroupViewProvider():
self.Proxy = group
class FlatpackWBTools():
def createDatumPlaneOnLink(self, part):
def createDatumPlaneOnLink(self, part, link):
plane = part.newObject('PartDesign::Plane', 'DatumPlane')
return plane
def createGroup(self, asm):
#pack = ad.addObject('App::Part', 'Flatpack')
#pack.Type = 'Flatpack'
pack = ad.addObject('App::Part', 'Flatpack')
pack.Type = 'Flatpack'
#FlatpackGroupViewProvider(pack)
FlatpackGroupViewProvider(pack)
#asm.Visibility = False
self.links = self.findLinks(asm)
assembly_bodies = []
for link in self.links:
if link.LinkedObject not in assembly_bodies:
assembly_bodies.append(link.LinkedObject)
attached_to = ad.getObject(link.AttachedTo.split('#')[1])
# not much to do when attached to the root
if attached_to.Name == 'LCS_Origin':
print('Skipping LCS_Origin')
continue
continue
print(link.Name, link.Placement)
for body in assembly_bodies:
sketch_planes = {}
sketch_pockets = {}
sketch_pads = {}
# find all the App::Links that are on the same Plane as this one
coplaner_links = []
for i in [ l for l in link.OutList if l.TypeId == 'PartDesign::CoordinateSystem' ]:
if l not in coplaner_links and abs(link.Placement.Base.z - l.Placement.Base.z) < 0.000001:
print(link.Label, l.Label, abs(link.Placement.Base.z- l.Placement.Base.z), link.Placement.Base.z==l.Placement.Base.z)
coplaner_links.append(l)
for lcs in self.findLCS(body.OutList):
base = lcs.Placement.Base
z = base.z
print('coplaner_links', coplaner_links)
for cp_link in coplaner_links:
base = cp_link.Placement.Base
if sketch_planes.get(z) is None:
# create new plane to hold sketch
plane = self.createDatumPlaneOnLink(body)
plane.Visibility = False
plane.Placement.Base.z = z
# create DatumPlane for Sketch Support
# TODO track planes per Z offset
plane = self.createDatumPlaneOnLink(link.LinkedObject, link)
plane.Visibility = False
plane.Placement.Base.z = base.z
sketch_planes[z] = plane
else:
plane = sketch_planes[z]
# create Sketch for drawing attachment features
sketch = self.createSketch(link.LinkedObject, plane)
sketch.Visibility = False
bb = body.Shape.BoundBox
if self.insideBB(bb, lcs.Placement.Base):
sketch_book = sketch_pockets
sketch_label = 'Inside'
else:
sketch_book = sketch_pads
sketch_label = 'Outside'
if sketch_book.get(z) is None:
sketch = self.createSketch(body, plane)
sketch.Visibility = False
sketch.Label = sketch_label
sketch_book[z] = sketch
else:
sketch = sketch_book[z]
tab_length = abs(bb.ZMin) + bb.ZMax
sketch.addGeometry(Part.LineSegment(App.Vector(base.x-10, base.y - (tab_length / 2), 0), App.Vector(base.x+10, base.y - (tab_length / 2), 0)), False)
sketch.addGeometry(Part.LineSegment(App.Vector(base.x+10, base.y - (tab_length / 2), 0), App.Vector(base.x+10, base.y + tab_length / 2, 0)), False)
sketch.addGeometry(Part.LineSegment(App.Vector(base.x+10, base.y + tab_length / 2, 0), App.Vector(base.x-10, base.y + tab_length / 2, 0)), False)
sketch.addGeometry(Part.LineSegment(App.Vector(base.x-10, base.y + tab_length / 2, 0), App.Vector(base.x-10, base.y - (tab_length / 2), 0)), False)
for z in sketch_pads:
sketch = sketch_pads[z]
# TODO needs input parameters from 1) the Flatpack object 2) the depth of the LinkedObject
sketch.addGeometry(Part.LineSegment(App.Vector(base.x-10, base.y, 0), App.Vector(base.x+10, base.y, 0)), False)
sketch.addGeometry(Part.LineSegment(App.Vector(base.x+10, base.y, 0), App.Vector(base.x+10, base.y + 5, 0)), False)
sketch.addGeometry(Part.LineSegment(App.Vector(base.x+10, base.y + 5, 0), App.Vector(base.x-10, base.y + 5, 0)), False)
sketch.addGeometry(Part.LineSegment(App.Vector(base.x-10, base.y + 5, 0), App.Vector(base.x-10, base.y, 0)), False)
# TODO determine if Feature should be Pad or Pocket, based on inside/outside of BoundingBox
pad = link.LinkedObject.newObject('PartDesign::Pad', 'Pad')
pad.Profile = sketch
pad.Length = tab_length
pad.Midplane = 1
pad.Refine = 1
for z in sketch_pockets:
sketch = sketch_pockets[z]
pad = link.LinkedObject.newObject('PartDesign::Pocket', 'Pocket')
pad.Profile = sketch
pad.Length = tab_length
# TODO get value from elsewhere
pad.Length = 10
pad.Midplane = 1
pad.Refine = 1
@ -120,24 +99,16 @@ class FlatpackWBTools():
def findLinks(self, asm, discard_origin = False):
return [] if not asm else [el for el in asm.OutList if el.TypeId == 'App::Link']
def findLCS(self, obj_list):
return [ l for l in obj_list if l.TypeId == 'PartDesign::CoordinateSystem' ]
def getLinkOwner(self, link):
return link.LinkedObject
def insideBB(self, bb, p):
return (p.x > bb.XMin and p.x < bb.XMax) and (p.y > bb.YMin and p.y < bb.YMax) and (p.z > bb.ZMin and p.z < bb.ZMax)
FP = App.Flatpack = FlatpackWBTools()
asm = Gui.ActiveDocument.Document.getObject('Model')
asm = FP.findAssembly()
if asm:
ad.openTransaction('flatpack')
FP.createGroup(asm)
ad.commitTransaction()
else:
print('No Assembly selected.')