assembly: make relation group optional
This commit is contained in:
parent
0a24b81bde
commit
a6251981f4
62
assembly.py
62
assembly.py
|
@ -196,7 +196,9 @@ class AsmPartGroup(AsmGroup):
|
||||||
if prop == 'Group':
|
if prop == 'Group':
|
||||||
parent = getattr(self,'parent',None)
|
parent = getattr(self,'parent',None)
|
||||||
if parent and not self.parent.Object.Freeze:
|
if parent and not self.parent.Object.Freeze:
|
||||||
parent.getRelationGroup().Proxy.getRelations(True)
|
relationGroup = parent.getRelationGroup()
|
||||||
|
if relationGroup:
|
||||||
|
relationGroup.Proxy.getRelations(True)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def make(parent,name='Parts'):
|
def make(parent,name='Parts'):
|
||||||
|
@ -828,11 +830,12 @@ class AsmElementLink(AsmBase):
|
||||||
|
|
||||||
def execute(self,_obj):
|
def execute(self,_obj):
|
||||||
info = self.getInfo(True)
|
info = self.getInfo(True)
|
||||||
if not self.part or self.part!=info.Part:
|
relationGroup = self.getAssembly().getRelationGroup()
|
||||||
|
if relationGroup and (not self.part or self.part!=info.Part):
|
||||||
oldPart = self.part
|
oldPart = self.part
|
||||||
self.part = info.Part
|
self.part = info.Part
|
||||||
self.getAssembly().getRelationGroup().Proxy.update(
|
relationGroup.Proxy.update(
|
||||||
self.parent.Object,oldPart,info.Part,info.PartName)
|
self.parent.Object,oldPart,info.Part,info.PartName)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def onChanged(self,obj,prop):
|
def onChanged(self,obj,prop):
|
||||||
|
@ -1478,6 +1481,7 @@ class AsmRelationGroup(AsmBase):
|
||||||
|
|
||||||
if relations or touched:
|
if relations or touched:
|
||||||
obj.Group = group
|
obj.Group = group
|
||||||
|
obj.purgeTouched()
|
||||||
|
|
||||||
for k,o in relations.items():
|
for k,o in relations.items():
|
||||||
self.relations.pop(k)
|
self.relations.pop(k)
|
||||||
|
@ -1587,7 +1591,7 @@ class AsmRelationGroup(AsmBase):
|
||||||
else:
|
else:
|
||||||
subs = moveInfo.SelSubname
|
subs = moveInfo.SelSubname
|
||||||
subs = subs.split('.')
|
subs = subs.split('.')
|
||||||
relationGroup = resolveAssembly(info.Parent).getRelationGroup()
|
relationGroup = resolveAssembly(info.Parent).getRelationGroup(True)
|
||||||
if isinstance(info.Part,tuple):
|
if isinstance(info.Part,tuple):
|
||||||
part = info.Part[0]
|
part = info.Part[0]
|
||||||
else:
|
else:
|
||||||
|
@ -1623,6 +1627,20 @@ class ViewProviderAsmRelationGroup(ViewProviderAsmBase):
|
||||||
def claimChildren(self):
|
def claimChildren(self):
|
||||||
return self.ViewObject.Object.Group
|
return self.ViewObject.Object.Group
|
||||||
|
|
||||||
|
def onDelete(self,vobj,_subs):
|
||||||
|
obj = vobj.Object
|
||||||
|
relations = obj.Group
|
||||||
|
obj.Group = []
|
||||||
|
for o in relations:
|
||||||
|
if o.Count:
|
||||||
|
group = o.Group
|
||||||
|
o.Group = []
|
||||||
|
for child in group:
|
||||||
|
if isTypeOf(child,AsmRelation):
|
||||||
|
child.Document.removeObject(child.Name)
|
||||||
|
o.Document.removeObject(o.Name)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class AsmRelation(AsmBase):
|
class AsmRelation(AsmBase):
|
||||||
def __init__(self,parent):
|
def __init__(self,parent):
|
||||||
|
@ -1773,6 +1791,7 @@ class AsmRelation(AsmBase):
|
||||||
group.append(cstr)
|
group.append(cstr)
|
||||||
break
|
break
|
||||||
obj.Group = group
|
obj.Group = group
|
||||||
|
obj.purgeTouched()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def make(parent,part,name='Relation'):
|
def make(parent,part,name='Relation'):
|
||||||
|
@ -2078,13 +2097,15 @@ class Assembly(AsmGroup):
|
||||||
obj.addProperty('App::PropertyBool','Freeze','Base','')
|
obj.addProperty('App::PropertyBool','Freeze','Base','')
|
||||||
obj.configLinkProperty('ColoredElements')
|
obj.configLinkProperty('ColoredElements')
|
||||||
super(Assembly,self).linkSetup(obj)
|
super(Assembly,self).linkSetup(obj)
|
||||||
|
obj.setPropertyStatus('Group','Output')
|
||||||
System.attach(obj)
|
System.attach(obj)
|
||||||
|
|
||||||
# make sure all children are there, first constraint group, then element
|
# make sure all children are there, first constraint group, then element
|
||||||
# group, and finally part group. Call getPartGroup below will make sure
|
# group, and finally part group. Call getPartGroup below will make sure
|
||||||
# all groups exist. The order of the group is important to make sure
|
# all groups exist. The order of the group is important to make sure
|
||||||
# correct rendering and picking behavior
|
# correct rendering and picking behavior
|
||||||
self.getRelationGroup(True)
|
self.getPartGroup(True)
|
||||||
|
self.getRelationGroup()
|
||||||
|
|
||||||
self.onChanged(obj,'BuildShape')
|
self.onChanged(obj,'BuildShape')
|
||||||
|
|
||||||
|
@ -2108,7 +2129,7 @@ class Assembly(AsmGroup):
|
||||||
self.getPartGroup().Shape = Part.Shape()
|
self.getPartGroup().Shape = Part.Shape()
|
||||||
self.frozen = obj.Freeze
|
self.frozen = obj.Freeze
|
||||||
return
|
return
|
||||||
if prop not in _IgnoredProperties:
|
if prop!='Group' and prop not in _IgnoredProperties:
|
||||||
System.onChanged(obj,prop)
|
System.onChanged(obj,prop)
|
||||||
Assembly.autoSolve()
|
Assembly.autoSolve()
|
||||||
|
|
||||||
|
@ -2233,11 +2254,13 @@ class Assembly(AsmGroup):
|
||||||
'invalid parent of relation group {}'.format(objName(ret)))
|
'invalid parent of relation group {}'.format(objName(ret)))
|
||||||
return ret
|
return ret
|
||||||
except IndexError:
|
except IndexError:
|
||||||
if not create:
|
if create:
|
||||||
raise RuntimeError('Missing relation group')
|
ret = AsmRelationGroup.make(obj)
|
||||||
ret = AsmRelationGroup.make(obj)
|
touched = 'Touched' in obj.State
|
||||||
obj.setLink({3:ret})
|
obj.setLink({3:ret})
|
||||||
return ret
|
if not touched:
|
||||||
|
obj.purgeTouched()
|
||||||
|
return ret
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def make(doc=None,name='Assembly',undo=True):
|
def make(doc=None,name='Assembly',undo=True):
|
||||||
|
@ -2379,21 +2402,10 @@ class ViewProviderAssembly(ViewProviderAsmGroup):
|
||||||
if o.isDerivedFrom('App::Origin'):
|
if o.isDerivedFrom('App::Origin'):
|
||||||
o.Document.removeObject(o.Name)
|
o.Document.removeObject(o.Name)
|
||||||
break
|
break
|
||||||
relationGroup = assembly.getRelationGroup()
|
|
||||||
relations = relationGroup.Group
|
|
||||||
relationGroup.Group = []
|
|
||||||
for o in relations:
|
|
||||||
if o.Count:
|
|
||||||
group = o.Group
|
|
||||||
o.Group = []
|
|
||||||
for child in group:
|
|
||||||
if isTypeOf(child,AsmRelation):
|
|
||||||
child.Document.removeObject(child.Name)
|
|
||||||
o.Document.removeObject(o.Name)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def canDelete(self,_obj):
|
def canDelete(self,obj):
|
||||||
return False
|
return isTypeOf(obj,AsmRelationGroup)
|
||||||
|
|
||||||
def _convertSubname(self,owner,subname):
|
def _convertSubname(self,owner,subname):
|
||||||
sub = subname.split('.')
|
sub = subname.split('.')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user