assembly: support drag and drop reordering of constraint and elements
This commit is contained in:
parent
b9c7af40fd
commit
e785510c68
|
@ -102,6 +102,13 @@ def editGroup(obj,children,notouch=None):
|
||||||
change = '-Immutable'
|
change = '-Immutable'
|
||||||
revert = 'Immutable'
|
revert = 'Immutable'
|
||||||
|
|
||||||
|
if isTypeOf(obj,(AsmConstraintGroup,AsmConstraint)):
|
||||||
|
# the order inside constraint group actually matters, so do not
|
||||||
|
# engage no touch
|
||||||
|
parent = None
|
||||||
|
block = False
|
||||||
|
notouch = False
|
||||||
|
else:
|
||||||
parent = getattr(obj,'_Parent',None)
|
parent = getattr(obj,'_Parent',None)
|
||||||
if parent and 'Touched' in parent.State:
|
if parent and 'Touched' in parent.State:
|
||||||
parent = None
|
parent = None
|
||||||
|
@ -109,12 +116,6 @@ def editGroup(obj,children,notouch=None):
|
||||||
if not hasProperty(obj,'NoTouch'):
|
if not hasProperty(obj,'NoTouch'):
|
||||||
notouch = False
|
notouch = False
|
||||||
elif notouch is None:
|
elif notouch is None:
|
||||||
if (isTypeOf(parent,AsmConstraintGroup) or \
|
|
||||||
isTypeOf(obj,AsmConstraintGroup)):
|
|
||||||
# the order inside constraint group actually matters, so do not
|
|
||||||
# engage no touch
|
|
||||||
parent = None
|
|
||||||
else:
|
|
||||||
notouch = not obj.NoTouch
|
notouch = not obj.NoTouch
|
||||||
|
|
||||||
if notouch:
|
if notouch:
|
||||||
|
@ -122,6 +123,7 @@ def editGroup(obj,children,notouch=None):
|
||||||
block = gui.AsmCmdManager.AutoRecompute
|
block = gui.AsmCmdManager.AutoRecompute
|
||||||
if block:
|
if block:
|
||||||
gui.AsmCmdManager.AutoRecompute = False
|
gui.AsmCmdManager.AutoRecompute = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if change:
|
if change:
|
||||||
obj.setPropertyStatus('Group',change)
|
obj.setPropertyStatus('Group',change)
|
||||||
|
@ -217,7 +219,10 @@ class ViewProviderAsmBase(object):
|
||||||
vobj.Proxy = self
|
vobj.Proxy = self
|
||||||
self.attach(vobj)
|
self.attach(vobj)
|
||||||
|
|
||||||
def replaceObject(self,_new,_old):
|
def canReplaceObject(self, _old, _new):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def replaceObject(self,_old,_new):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def canAddToSceneGraph(self):
|
def canAddToSceneGraph(self):
|
||||||
|
@ -293,6 +298,21 @@ class ViewProviderAsmGroup(ViewProviderAsmBase):
|
||||||
def canDropObject(self,_child):
|
def canDropObject(self,_child):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def canReplaceObject(self, _oldObj, newObj):
|
||||||
|
return newObj in self.ViewObject.Object.Group
|
||||||
|
|
||||||
|
def replaceObject(self, oldObj, newObj):
|
||||||
|
try:
|
||||||
|
children = self.ViewObject.Object.Group
|
||||||
|
old_idx = children.index(oldObj)
|
||||||
|
new_idx = children.index(newObj)
|
||||||
|
del children[new_idx]
|
||||||
|
children.insert(old_idx, newObj)
|
||||||
|
editGroup(self.ViewObject.Object, children)
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class ViewProviderAsmGroupOnTop(ViewProviderAsmGroup):
|
class ViewProviderAsmGroupOnTop(ViewProviderAsmGroup):
|
||||||
def __init__(self,vobj):
|
def __init__(self,vobj):
|
||||||
|
@ -388,9 +408,6 @@ class AsmPartGroup(AsmGroup):
|
||||||
class ViewProviderAsmPartGroup(ViewProviderAsmGroup):
|
class ViewProviderAsmPartGroup(ViewProviderAsmGroup):
|
||||||
_iconName = 'Assembly_Assembly_Part_Tree.svg'
|
_iconName = 'Assembly_Assembly_Part_Tree.svg'
|
||||||
|
|
||||||
def replaceObject(self,new,old):
|
|
||||||
return self.Object.replaceObject(new,old)
|
|
||||||
|
|
||||||
def canDropObjectEx(self,obj,_owner,_subname,_elements):
|
def canDropObjectEx(self,obj,_owner,_subname,_elements):
|
||||||
return isTypeOf(obj,Assembly, True) or not isTypeOf(obj,AsmBase)
|
return isTypeOf(obj,Assembly, True) or not isTypeOf(obj,AsmBase)
|
||||||
|
|
||||||
|
@ -450,6 +467,9 @@ class ViewProviderAsmPartGroup(ViewProviderAsmGroup):
|
||||||
pass
|
pass
|
||||||
vobj.DefaultMode = mode
|
vobj.DefaultMode = mode
|
||||||
|
|
||||||
|
def canReplaceObject(self, _old, _new):
|
||||||
|
return True
|
||||||
|
|
||||||
def replaceObject(self,oldObj,newObj):
|
def replaceObject(self,oldObj,newObj):
|
||||||
res = self.ViewObject.replaceObject(oldObj,newObj)
|
res = self.ViewObject.replaceObject(oldObj,newObj)
|
||||||
if res<=0:
|
if res<=0:
|
||||||
|
@ -1627,7 +1647,7 @@ def getElementInfo(parent,subname,
|
||||||
'{}.{}'.format(objName(part),subname))
|
'{}.{}'.format(objName(part),subname))
|
||||||
pla = getattr(part,'Placement',FreeCAD.Placement())
|
pla = getattr(part,'Placement',FreeCAD.Placement())
|
||||||
obj = part.getLinkedObject(False)
|
obj = part.getLinkedObject(False)
|
||||||
partName = part.Name
|
partName = objName(part)
|
||||||
|
|
||||||
if transformShape:
|
if transformShape:
|
||||||
# Copy and transform shape. We have to copy the shape here to work
|
# Copy and transform shape. We have to copy the shape here to work
|
||||||
|
@ -4366,6 +4386,12 @@ class ViewProviderAssembly(ViewProviderAsmGroup):
|
||||||
def canDelete(self,obj):
|
def canDelete(self,obj):
|
||||||
return isTypeOf(obj,AsmRelationGroup)
|
return isTypeOf(obj,AsmRelationGroup)
|
||||||
|
|
||||||
|
def canReplaceObject(self, _old, _new):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def replaceObject(self,_old,_new):
|
||||||
|
return False
|
||||||
|
|
||||||
def _convertSubname(self,owner,subname):
|
def _convertSubname(self,owner,subname):
|
||||||
sub = subname.split('.')
|
sub = subname.split('.')
|
||||||
if not sub:
|
if not sub:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user