gui: add AsmCmdGotoLinked command
For special handling of Element and ElementLink
This commit is contained in:
parent
1b9c948f0e
commit
ce930261d8
51
gui.py
51
gui.py
|
@ -241,10 +241,14 @@ class AsmCmdBase(with_metaclass(AsmCmdManager, object)):
|
||||||
def checkActive(cls):
|
def checkActive(cls):
|
||||||
cls._active = True
|
cls._active = True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def getIconName(cls):
|
||||||
|
return addIconToFCAD(cls._iconName)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def GetResources(cls):
|
def GetResources(cls):
|
||||||
ret = {
|
ret = {
|
||||||
'Pixmap':addIconToFCAD(cls._iconName),
|
'Pixmap':cls.getIconName(),
|
||||||
'MenuText':cls.getMenuText(),
|
'MenuText':cls.getMenuText(),
|
||||||
'ToolTip':cls.getToolTip()
|
'ToolTip':cls.getToolTip()
|
||||||
}
|
}
|
||||||
|
@ -632,6 +636,51 @@ class AsmCmdGotoRelation(AsmCmdBase):
|
||||||
def onSelectionChange(cls,hasSelection):
|
def onSelectionChange(cls,hasSelection):
|
||||||
cls._active = None if hasSelection else False
|
cls._active = None if hasSelection else False
|
||||||
|
|
||||||
|
class AsmCmdGotoLinked(AsmCmdBase):
|
||||||
|
_id = 20
|
||||||
|
_menuText = 'Select linked object'
|
||||||
|
_tooltip = 'Select the linked object'
|
||||||
|
_accel = 'A, G'
|
||||||
|
_toolbarName = ''
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def getIconName(cls):
|
||||||
|
return 'LinkSelect'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def Activated(cls):
|
||||||
|
from .assembly import isTypeOf, AsmElement, AsmElementLink
|
||||||
|
sels = FreeCADGui.Selection.getSelectionEx('',0,True)
|
||||||
|
if not sels:
|
||||||
|
return
|
||||||
|
subname = sels[0].SubElementNames[0]
|
||||||
|
obj = sels[0].Object.getSubObject(subname,retType=1)
|
||||||
|
if not isTypeOf(obj,AsmElementLink) and not isTypeOf(obj,AsmElement):
|
||||||
|
FreeCADGui.runCommand('Std_LinkSelectLinked')
|
||||||
|
return
|
||||||
|
import Part
|
||||||
|
subname = Part.splitSubname(subname)[0].split('.')
|
||||||
|
if isTypeOf(obj,AsmElementLink):
|
||||||
|
subname = subname[:-4]
|
||||||
|
else:
|
||||||
|
subname = subname[:-3]
|
||||||
|
link,linkSub = obj.LinkedObject
|
||||||
|
subname.append(link.Name)
|
||||||
|
subname = '.'.join(subname+linkSub.split('.'))
|
||||||
|
sobj = sels[0].Object.getSubObject(subname,retType=1)
|
||||||
|
if not sobj:
|
||||||
|
logger.error('Cannot find sub object {}.{}'.format(
|
||||||
|
objName(sels[0].Object),subname))
|
||||||
|
return
|
||||||
|
FreeCADGui.Selection.pushSelStack()
|
||||||
|
FreeCADGui.Selection.clearSelection()
|
||||||
|
FreeCADGui.Selection.addSelection(sels[0].Object,subname)
|
||||||
|
FreeCADGui.Selection.pushSelStack()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def IsActive(cls):
|
||||||
|
return FreeCADGui.isCommandActive('Std_LinkSelectLinked')
|
||||||
|
|
||||||
|
|
||||||
class AsmCmdUp(AsmCmdBase):
|
class AsmCmdUp(AsmCmdBase):
|
||||||
_id = 6
|
_id = 6
|
||||||
|
|
|
@ -38,7 +38,7 @@ class Assembly3Workbench(FreeCADGui.Workbench):
|
||||||
|
|
||||||
def Initialize(self):
|
def Initialize(self):
|
||||||
from .mover import AsmDocumentObserver
|
from .mover import AsmDocumentObserver
|
||||||
from .gui import AsmCmdManager,AsmCmdGotoRelation
|
from .gui import AsmCmdManager,AsmCmdGotoRelation,AsmCmdGotoLinked
|
||||||
AsmCmdManager.init()
|
AsmCmdManager.init()
|
||||||
cmdSet = set()
|
cmdSet = set()
|
||||||
for name,cmds in AsmCmdManager.Toolbars.items():
|
for name,cmds in AsmCmdManager.Toolbars.items():
|
||||||
|
@ -46,7 +46,7 @@ class Assembly3Workbench(FreeCADGui.Workbench):
|
||||||
self.appendToolbar(name,[cmd.getName() for cmd in cmds])
|
self.appendToolbar(name,[cmd.getName() for cmd in cmds])
|
||||||
self.appendToolbar('Assembly3 Navigation', ["Std_SelBack",
|
self.appendToolbar('Assembly3 Navigation', ["Std_SelBack",
|
||||||
"Std_SelForward",AsmCmdGotoRelation.getName(),
|
"Std_SelForward",AsmCmdGotoRelation.getName(),
|
||||||
"Std_LinkSelectLinked", "Std_LinkSelectLinkedFinal",
|
AsmCmdGotoLinked.getName(), "Std_LinkSelectLinkedFinal",
|
||||||
"Std_LinkSelectAllLinks","Std_TreeSelectAllInstances"])
|
"Std_LinkSelectAllLinks","Std_TreeSelectAllInstances"])
|
||||||
for name,cmds in AsmCmdManager.Menus.items():
|
for name,cmds in AsmCmdManager.Menus.items():
|
||||||
cmdSet.update(cmds)
|
cmdSet.update(cmds)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user