diff --git a/assembly.py b/assembly.py index 6833c7d..d79d813 100644 --- a/assembly.py +++ b/assembly.py @@ -3234,6 +3234,31 @@ class Assembly(AsmGroup): obj.purgeTouched() 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 def make(doc=None,name='Assembly',undo=True): if not doc: @@ -3247,6 +3272,8 @@ class Assembly(AsmGroup): obj.setPropertyStatus('Shape','Transient') ViewProviderAssembly(obj.ViewObject) obj.Visibility = True + if gui.AsmCmdManager.AddOrigin: + Assembly.addOrigin(obj.Proxy.getPartGroup()) obj.purgeTouched() if undo: FreeCAD.closeActiveTransaction() @@ -3632,27 +3659,7 @@ class AsmWorkPlane(object): try: logger.debug('make {}',tp) if tp == 3: - obj = None - 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)) ]) + obj = Assembly.addOrigin(info.PartGroup,name) else: if not name: name = 'Workplane' diff --git a/gui.py b/gui.py index 9125ae2..d3928a7 100644 --- a/gui.py +++ b/gui.py @@ -516,6 +516,10 @@ class AsmCmdAutoRecompute(AsmCmdCheckable): _iconName = 'Assembly_AutoRecompute.svg' _saveParam = True + @classmethod + def IsActive(cls): + return True + class AsmCmdSmartRecompute(AsmCmdCheckable): _id = 22 _menuText = 'Smart recompute' @@ -523,6 +527,10 @@ class AsmCmdSmartRecompute(AsmCmdCheckable): _iconName = 'Assembly_SmartRecompute.svg' _saveParam = True + @classmethod + def IsActive(cls): + return True + class AsmCmdAutoElementVis(AsmCmdCheckable): _id = 9 _menuText = 'Auto element visibility' @@ -530,6 +538,10 @@ class AsmCmdAutoElementVis(AsmCmdCheckable): _saveParam = True _defaultValue = True + @classmethod + def IsActive(cls): + return True + @classmethod def Activated(cls,checked): super(AsmCmdAutoElementVis,cls).Activated(checked) @@ -579,7 +591,6 @@ class AsmCmdAddWorkplane(AsmCmdBase): from . import assembly assembly.AsmWorkPlane.make(tp=cls._makeType) - class AsmCmdAddWorkplaneXZ(AsmCmdAddWorkplane): _id = 10 _menuText = 'Add XZ workplane' @@ -593,15 +604,34 @@ class AsmCmdAddWorkplaneZY(AsmCmdAddWorkplane): _iconName = 'Assembly_Add_WorkplaneZY.svg' _makeType = 2 -class AsmCmdAddOrigin(AsmCmdAddWorkplane): +class AsmCmdAddOrigin(AsmCmdCheckable): _id = 14 _menuText = 'Add Origin' _iconName = 'Assembly_Add_Origin.svg' _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 + _iconName = AsmCmdAddWorkplane._iconName + _menuText = AsmCmdAddWorkplane._menuText _menuGroupName = '' _toolbarName = AsmCmdBase._toolbarName _cmds = (AsmCmdAddWorkplane.getName(), @@ -610,12 +640,12 @@ class AsmCmdAddWorkplaneGroup(AsmCmdAddWorkplane): AsmCmdAddOrigin.getName()) @classmethod - def GetCommands(cls): - return cls._cmds + def IsActive(cls): + return True @classmethod - def Activated(cls,idx=0): - FreeCADGui.runCommand(cls._cmds[idx]) + def GetCommands(cls): + return cls._cmds class AsmCmdGotoRelation(AsmCmdBase): _id = 16