gui: change AddOrigin command to checkable action

This commit is contained in:
Zheng, Lei 2019-01-08 16:59:19 +08:00
parent bf7eac30be
commit 3b48ecbb0e
2 changed files with 66 additions and 29 deletions

View File

@ -3234,6 +3234,31 @@ class Assembly(AsmGroup):
obj.purgeTouched() obj.purgeTouched()
return ret return ret
@staticmethod
def addOrigin(partGroup, name=None):
obj = None
for o in partGroup.Group:
if o.TypeId == 'App::Origin':
obj = o
break
if not obj:
if not name:
name = 'Origin'
obj = partGroup.Document.addObject('App::Origin',name)
partGroup.setLink({-1:obj})
partGroup.recompute(True)
shape = Part.getShape(partGroup)
if not shape.isNull():
bbox = shape.BoundBox
if bbox.isValid():
obj.ViewObject.Size = tuple([
max(abs(a),abs(b)) for a,b in (
(bbox.XMin,bbox.XMax),
(bbox.YMin,bbox.YMax),
(bbox.ZMin,bbox.ZMax)) ])
return obj
@staticmethod @staticmethod
def make(doc=None,name='Assembly',undo=True): def make(doc=None,name='Assembly',undo=True):
if not doc: if not doc:
@ -3247,6 +3272,8 @@ class Assembly(AsmGroup):
obj.setPropertyStatus('Shape','Transient') obj.setPropertyStatus('Shape','Transient')
ViewProviderAssembly(obj.ViewObject) ViewProviderAssembly(obj.ViewObject)
obj.Visibility = True obj.Visibility = True
if gui.AsmCmdManager.AddOrigin:
Assembly.addOrigin(obj.Proxy.getPartGroup())
obj.purgeTouched() obj.purgeTouched()
if undo: if undo:
FreeCAD.closeActiveTransaction() FreeCAD.closeActiveTransaction()
@ -3632,27 +3659,7 @@ class AsmWorkPlane(object):
try: try:
logger.debug('make {}',tp) logger.debug('make {}',tp)
if tp == 3: if tp == 3:
obj = None obj = Assembly.addOrigin(info.PartGroup,name)
for o in info.PartGroup.Group:
if o.TypeId == 'App::Origin':
obj = o
break
if not obj:
if not name:
name = 'Origin'
obj = doc.addObject('App::Origin',name)
info.PartGroup.setLink({-1:obj})
info.PartGroup.recompute(True)
shape = Part.getShape(info.PartGroup)
if not shape.isNull():
bbox = shape.BoundBox
if bbox.isValid():
obj.ViewObject.Size = tuple([
max(abs(a),abs(b)) for a,b in (
(bbox.XMin,bbox.XMax),
(bbox.YMin,bbox.YMax),
(bbox.ZMin,bbox.ZMax)) ])
else: else:
if not name: if not name:
name = 'Workplane' name = 'Workplane'

46
gui.py
View File

@ -516,6 +516,10 @@ class AsmCmdAutoRecompute(AsmCmdCheckable):
_iconName = 'Assembly_AutoRecompute.svg' _iconName = 'Assembly_AutoRecompute.svg'
_saveParam = True _saveParam = True
@classmethod
def IsActive(cls):
return True
class AsmCmdSmartRecompute(AsmCmdCheckable): class AsmCmdSmartRecompute(AsmCmdCheckable):
_id = 22 _id = 22
_menuText = 'Smart recompute' _menuText = 'Smart recompute'
@ -523,6 +527,10 @@ class AsmCmdSmartRecompute(AsmCmdCheckable):
_iconName = 'Assembly_SmartRecompute.svg' _iconName = 'Assembly_SmartRecompute.svg'
_saveParam = True _saveParam = True
@classmethod
def IsActive(cls):
return True
class AsmCmdAutoElementVis(AsmCmdCheckable): class AsmCmdAutoElementVis(AsmCmdCheckable):
_id = 9 _id = 9
_menuText = 'Auto element visibility' _menuText = 'Auto element visibility'
@ -530,6 +538,10 @@ class AsmCmdAutoElementVis(AsmCmdCheckable):
_saveParam = True _saveParam = True
_defaultValue = True _defaultValue = True
@classmethod
def IsActive(cls):
return True
@classmethod @classmethod
def Activated(cls,checked): def Activated(cls,checked):
super(AsmCmdAutoElementVis,cls).Activated(checked) super(AsmCmdAutoElementVis,cls).Activated(checked)
@ -579,7 +591,6 @@ class AsmCmdAddWorkplane(AsmCmdBase):
from . import assembly from . import assembly
assembly.AsmWorkPlane.make(tp=cls._makeType) assembly.AsmWorkPlane.make(tp=cls._makeType)
class AsmCmdAddWorkplaneXZ(AsmCmdAddWorkplane): class AsmCmdAddWorkplaneXZ(AsmCmdAddWorkplane):
_id = 10 _id = 10
_menuText = 'Add XZ workplane' _menuText = 'Add XZ workplane'
@ -593,15 +604,34 @@ class AsmCmdAddWorkplaneZY(AsmCmdAddWorkplane):
_iconName = 'Assembly_Add_WorkplaneZY.svg' _iconName = 'Assembly_Add_WorkplaneZY.svg'
_makeType = 2 _makeType = 2
class AsmCmdAddOrigin(AsmCmdAddWorkplane): class AsmCmdAddOrigin(AsmCmdCheckable):
_id = 14 _id = 14
_menuText = 'Add Origin' _menuText = 'Add Origin'
_iconName = 'Assembly_Add_Origin.svg' _iconName = 'Assembly_Add_Origin.svg'
_makeType = 3 _makeType = 3
_accel = 'A, O' _saveParam = False
_toolbarName = None
_menuGroupName = None
class AsmCmdAddWorkplaneGroup(AsmCmdAddWorkplane): @classmethod
def IsActive(cls):
return True
@classmethod
def Activated(cls,checked):
logger.info('checked {}'.format(checked))
cls.setChecked(checked)
if checked:
from . import assembly
sels = logger.catchTrace('Add origin selection',
assembly.AsmWorkPlane.getSelection)
if sels:
assembly.AsmWorkPlane.make(sels,tp=cls._makeType)
class AsmCmdAddWorkplaneGroup(AsmCmdBase):
_id = 12 _id = 12
_iconName = AsmCmdAddWorkplane._iconName
_menuText = AsmCmdAddWorkplane._menuText
_menuGroupName = '' _menuGroupName = ''
_toolbarName = AsmCmdBase._toolbarName _toolbarName = AsmCmdBase._toolbarName
_cmds = (AsmCmdAddWorkplane.getName(), _cmds = (AsmCmdAddWorkplane.getName(),
@ -610,12 +640,12 @@ class AsmCmdAddWorkplaneGroup(AsmCmdAddWorkplane):
AsmCmdAddOrigin.getName()) AsmCmdAddOrigin.getName())
@classmethod @classmethod
def GetCommands(cls): def IsActive(cls):
return cls._cmds return True
@classmethod @classmethod
def Activated(cls,idx=0): def GetCommands(cls):
FreeCADGui.runCommand(cls._cmds[idx]) return cls._cmds
class AsmCmdGotoRelation(AsmCmdBase): class AsmCmdGotoRelation(AsmCmdBase):
_id = 16 _id = 16