diff --git a/src/Mod/Path/CMakeLists.txt b/src/Mod/Path/CMakeLists.txt index 6bdeab8bb3..01d83a9f50 100644 --- a/src/Mod/Path/CMakeLists.txt +++ b/src/Mod/Path/CMakeLists.txt @@ -26,6 +26,7 @@ SET(PathScripts_SRCS PathScripts/PathComment.py PathScripts/PathCopy.py PathScripts/PathCustom.py + PathScripts/PathDressup.py PathScripts/PathDressupDogbone.py PathScripts/PathDressupDragknife.py PathScripts/PathDressupHoldingTags.py diff --git a/src/Mod/Path/PathScripts/PathDressup.py b/src/Mod/Path/PathScripts/PathDressup.py new file mode 100644 index 0000000000..6d187b1caf --- /dev/null +++ b/src/Mod/Path/PathScripts/PathDressup.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- + +# *************************************************************************** +# * * +# * Copyright (c) 2018 sliptonic * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +import FreeCAD +import FreeCADGui +import PathScripts.PathJob as PathJob + +def selection(): + '''isActive() ... return True if a dressup command is possible.''' + if FreeCAD.ActiveDocument: + sel = FreeCADGui.Selection.getSelectionEx() + if len(sel) == 1 and sel[0].Object.isDerivedFrom("Path::Feature") and PathJob.Instances(): + return sel[0].Object + return None + +def hasEntryMethod(path): + '''hasEntryDressup(path) ... returns true if the given object already has an entry method attached.''' + if 'RampEntry' in path.Name or 'LeadInOut' in path.Name: + return True + if hasattr(path, 'Base'): + return hasEntryMethod(path.Base) + return False + diff --git a/src/Mod/Path/PathScripts/PathDressupLeadInOut.py b/src/Mod/Path/PathScripts/PathDressupLeadInOut.py index aef89476b1..11e0675782 100644 --- a/src/Mod/Path/PathScripts/PathDressupLeadInOut.py +++ b/src/Mod/Path/PathScripts/PathDressupLeadInOut.py @@ -23,13 +23,16 @@ # *************************************************************************** from __future__ import print_function + import FreeCAD import FreeCADGui import Path -from PySide import QtCore -import math +import PathScripts.PathDressup as PathDressup import PathScripts.PathLog as PathLog import PathScripts.PathUtils as PathUtils +import math + +from PySide import QtCore from PathScripts.PathGeom import PathGeom """LeadInOut Dressup MASHIN-CRC USE ROLL-ON ROLL-OFF to profile""" @@ -337,10 +340,9 @@ class CommandPathDressupLeadInOut: 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_DressupLeadInOut", "Creates a Cutter Radius Compensation G41/G42 Entry Dressup object from a selected path")} def IsActive(self): - if FreeCAD.ActiveDocument is not None: - for o in FreeCAD.ActiveDocument.Objects: - if o.Name[:3] == "Job": - return True + op = PathDressup.selection() + if op: + return not PathDressup.hasEntryMethod(op) return False def Activated(self): diff --git a/src/Mod/Path/PathScripts/PathDressupRampEntry.py b/src/Mod/Path/PathScripts/PathDressupRampEntry.py index f56926185e..caf6d11ac4 100644 --- a/src/Mod/Path/PathScripts/PathDressupRampEntry.py +++ b/src/Mod/Path/PathScripts/PathDressupRampEntry.py @@ -25,6 +25,7 @@ import FreeCAD import FreeCADGui import Path import Part +import PathScripts.PathDressup as PathDressup import PathScripts.PathLog as PathLog import math @@ -613,10 +614,9 @@ class CommandPathDressupRampEntry: 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_DressupRampEntry", "Creates a Ramp Entry Dress-up object from a selected path")} def IsActive(self): - if FreeCAD.ActiveDocument is not None: - for o in FreeCAD.ActiveDocument.Objects: - if o.Name[:3] == "Job": - return True + op = PathDressup.selection() + if op: + return not PathDressup.hasEntryMethod(op) return False def Activated(self):