Skip to content

Commit

Permalink
fix #86 Property container has no property Support in FreeCAD 0.22 > …
Browse files Browse the repository at this point in the history
…36274
  • Loading branch information
johnsonm authored and DeepSOIC committed May 16, 2024
1 parent 16eb107 commit 4298861
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
14 changes: 10 additions & 4 deletions lattice2BaseFeature.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ def isObjectLattice(documentObject):
if documentObject.isDerivedFrom('App::Placement') or documentObject.isDerivedFrom('PartDesign::CoordinateSystem'):
ret = True
if documentObject.isDerivedFrom('PartDesign::ShapeBinder'):
if len(documentObject.Support) == 1 and documentObject.Support[0][1] == ('',):
ret = isObjectLattice(documentObject.Support[0][0])
attachmentSupport = getAttachmentSupport(documentObject)
if len(attachmentSupport) == 1 and attachmentSupport[0][1] == ('',):
ret = isObjectLattice(attachmentSupport[0][0])
if hasattr(documentObject, 'IAm') and documentObject.IAm == 'PartOMagic.Ghost':
ret = isObjectLattice(documentObject.Base)
return ret

def getMarkerSizeEstimate(ListOfPlacements, feature = None):
'''getMarkerSizeEstimate(ListOfPlacements, feature = None): computes the default marker size for the array of placements.
If feature is provided, marker size property will be assigned to viewer-based autosize if size based on array content is zero.'''
Expand Down Expand Up @@ -262,12 +263,17 @@ def loads(self,state):
def disableAttacher(self, selfobj, enable= False):
if selfobj.isDerivedFrom('Part::Part2DObject'):
attachprops = [
'Support',
'MapMode',
'MapReversed',
'MapPathParameter',
'AttachmentOffset',
]
if hasattr(selfobj, 'AttachmentSupport'):
attachprops.append('AttachmentSupport')
elif hasattr(selfobj, 'Support'):
attachprops.append('Support')
else:
raise AttributeError('No support property found')
for prop in attachprops:
selfobj.setEditorMode(prop, 0 if enable else 2)
if enable:
Expand Down
10 changes: 10 additions & 0 deletions lattice2Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,13 @@ def bodyOf(feature):
return body
else:
return None


# Older FreeCAD has Support, newer has AttachmentSupport: https://github.com/FreeCAD/FreeCAD/issues/12894

def getAttachmentSupport(documentObject):
if hasattr(documentObject, 'AttachmentSupport'):
return documentObject.AttachmentSupport
elif hasattr(documentObject, 'Support'):
return documentObject.Support
raise AttributeError('No support property found')
6 changes: 5 additions & 1 deletion lattice2Compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,9 @@ def get_fc_version():

attach_extension_era = rev_number >= 9177
no_extension_proxy_era = rev_number >= 23869
attachment_support_name = 'AttachmentSupport'
if rev_number < 36274:
# Before 0.22.0dev.36274 https://github.com/FreeCAD/FreeCAD/issues/12894
attachment_support_name = 'Support'

del App
del App
14 changes: 9 additions & 5 deletions lattice2PolarArray2.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import Part

from lattice2Common import *
from lattice2Compatibility import attachment_support_name
import lattice2BaseFeature
from lattice2BaseFeature import assureProperty
import lattice2Executer
Expand Down Expand Up @@ -108,8 +109,9 @@ def updateReadonlyness(self, selfobj):

def fetchArc(self, selfobj):
"""returns None, or tuple (arc_span, arc_radius)"""
if selfobj.Support:
lnkobj, sub = selfobj.Support[0]
attachmentSupport = getAttachmentSupport(selfobj)
if attachmentSupport:
lnkobj, sub = attachmentSupport[0]
sub = sub[0]
#resolve the link
return fetchArc(lnkobj, sub)
Expand Down Expand Up @@ -205,7 +207,8 @@ def derivedExecute(self,selfobj):
return output

def isOnArc(self, selfobj):
return selfobj.MapMode == 'Concentric' and len(linkSubList_convertToOldStyle(selfobj.Support)) == 1
attachmentSupport = getAttachmentSupport(selfobj)
return selfobj.MapMode == 'Concentric' and len(linkSubList_convertToOldStyle(attachmentSupport)) == 1

def onChanged(self, selfobj, propname):
super(PolarArray, self).onChanged(selfobj, propname)
Expand Down Expand Up @@ -242,13 +245,14 @@ def CreatePolarArray(genmode = 'SpanN'):
fullcircle = abs(arcspan - turn) < ParaConfusion
endinclusive = not fullcircle
usearcrange = 'as Step' if genmode == 'StepN' and not fullcircle else 'as Span'

FreeCADGui.doCommand(
'f.Support = [(App.ActiveDocument.{lnk}, {sub})]\n'
'f.{attachmentsupport} = [(App.ActiveDocument.{lnk}, {sub})]\n'
'f.MapMode = \'Concentric\'\n'
'f.UseArcRange = {usearcrange}\n'
'f.EndInclusive = {endinclusive}\n'
'f.UseArcRadius = True'
.format(lnk= lnk.Name, sub= repr(sub), usearcrange= repr(usearcrange), endinclusive= repr(endinclusive))
.format(attachmentsupport = attachment_support_name, lnk= lnk.Name, sub= repr(sub), usearcrange= repr(usearcrange), endinclusive= repr(endinclusive))
)
attached = True
if not attached:
Expand Down

0 comments on commit 4298861

Please sign in to comment.