JoinArrays: improve reference placement support

This commit is contained in:
DeepSOIC 2018-09-07 01:18:56 +03:00
parent f7bbd41b2c
commit 0224b6f98a

View File

@ -49,33 +49,60 @@ class JoinArrays(lattice2BaseFeature.LatticeFeature):
obj.addProperty("App::PropertyBool","Interleave","Lattice JoinArrays","If false, first go all elements of array 1, nect go all elements of array 2, so on. If true, first go all first elements from each array, then all second elements, and so on.") obj.addProperty("App::PropertyBool","Interleave","Lattice JoinArrays","If false, first go all elements of array 1, nect go all elements of array 2, so on. If true, first go all first elements from each array, then all second elements, and so on.")
def assureProperties(self, selfobj):
super(JoinArrays, self).assureProperties(selfobj)
created = self.assureProperty(selfobj,
'App::PropertyEnumeration',
'ReferencePlacementOption',
['external', 'origin', 'inherit 1st'],
"Lattice JoinArrays",
"Reference placement, corresponds to the original occurrence of the object to be populated."
)
if created:
selfobj.ReferencePlacementOption = 'inherit 1st'
self.assureProperty(selfobj,
'App::PropertyBool',
'AlignReferences',
False,
"Lattice JoinArrays",
"If true, input arrays will be moved to make their reference placements equal, before joining."
)
def recomputeReferencePlm(self, selfobj, selfplacements): #override
pass #disables standard recompute-reference call. The recompute is handled by derivedExecute
def derivedExecute(self,obj): def derivedExecute(self, selfobj):
#validity check align = selfobj.AlignReferences
nonLattices = [] #recompute reference placement
for iArr in range(0, len(obj.Links)): ref = selfobj.ReferencePlacementOption
link = obj.Links[iArr] if ref == 'external':
if not lattice2BaseFeature.isObjectLattice(link): super(JoinArrays, self).recomputeReferencePlm(selfobj, [])
nonLattices.append(link.Label) elif ref == 'origin':
if len(nonLattices) > 0: self.setReferencePlm(selfobj, None)
lattice2Executer.warning(obj, "Only lattice objects are expected to be linked as arrays in JoinArrays. There are " elif ref == 'inherit 1st':
+len(nonLattices)+" objects which are not lattice objects. Results may me unexpected.") if len(selfobj.Links)>0:
self.setReferencePlm(selfobj, lattice2BaseFeature.getReferencePlm(selfobj.Links[0]))
else:
self.setReferencePlm(selfobj, None)
else:
raise NotImplementedError("Reference option not implemented: " + ref)
refplm = self.getReferencePlm(selfobj)
#extract placements #extract placements
listlistPlms = [] listlistPlms = []
lengths = [] lengths = []
for link in obj.Links: for link in selfobj.Links:
leaves = LCE.AllLeaves(link.Shape) plms = lattice2BaseFeature.getPlacementsList(link, context= selfobj, dereferenced= align, torefplm = refplm)
listlistPlms.append([child.Placement for child in leaves]) listlistPlms.append(plms)
lengths.append(len(leaves)) lengths.append(len(plms))
#processing #processing
output = [] #list of placements output = [] #list of placements
if obj.Interleave: if selfobj.Interleave:
for l in lengths[1:]: for l in lengths[1:]:
if l != lengths[0]: if l != lengths[0]:
lattice2Executer.warning(obj,"Array lengths are unequal: "+repr(lengths)+". Interleaving will be inconsistent.") lattice2Executer.warning(selfobj,"Array lengths are unequal: "+repr(lengths)+". Interleaving will be inconsistent.")
break break
for iItem in range(0,max(lengths)): for iItem in range(0,max(lengths)):
@ -86,10 +113,6 @@ class JoinArrays(lattice2BaseFeature.LatticeFeature):
for list in listlistPlms: for list in listlistPlms:
output.extend(list) output.extend(list)
#reference placement
if len(obj.Links)>0:
self.setReferencePlm(obj, lattice2BaseFeature.getReferencePlm(obj.Links[0]))
return output return output
class ViewProviderJoinArrays(lattice2BaseFeature.ViewProviderLatticeFeature): class ViewProviderJoinArrays(lattice2BaseFeature.ViewProviderLatticeFeature):
@ -130,14 +153,13 @@ class _CommandJoinArrays:
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Lattice2_JoinArrays","Lattice JoinArrays: concatenate or interleave two or more arrays.")} 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Lattice2_JoinArrays","Lattice JoinArrays: concatenate or interleave two or more arrays.")}
def Activated(self): def Activated(self):
if len(FreeCADGui.Selection.getSelection()) > 1 : try:
CreateJoinArrays(name = "Join") if len(FreeCADGui.Selection.getSelection()) > 1 :
else: CreateJoinArrays(name = "Join")
mb = QtGui.QMessageBox() else:
mb.setIcon(mb.Icon.Warning) infoMessage("Please select at least two lattice objects. Selected lattice objects will be concatenated or interleaved into one array.")
mb.setText(translate("Lattice2_JoinArrays", "Please select at least two lattice objects. Selected lattice objects will be concatenated or interleaved into one array.", None)) except Exception as err:
mb.setWindowTitle(translate("Lattice2_JoinArrays","Bad selection", None)) msgError(err)
mb.exec_()
def IsActive(self): def IsActive(self):
if FreeCAD.ActiveDocument: if FreeCAD.ActiveDocument: