diff --git a/src/Mod/Path/PathScripts/PathDressupDogbone.py b/src/Mod/Path/PathScripts/PathDressupDogbone.py index 1802c1a384..d0e0c5ff51 100644 --- a/src/Mod/Path/PathScripts/PathDressupDogbone.py +++ b/src/Mod/Path/PathScripts/PathDressupDogbone.py @@ -21,6 +21,9 @@ # *************************************************************************** from __future__ import print_function + +from PySide import QtCore +from PySide.QtCore import QT_TRANSLATE_NOOP import FreeCAD import Path import PathScripts.PathDressup as PathDressup @@ -29,8 +32,7 @@ import PathScripts.PathLog as PathLog import PathScripts.PathUtil as PathUtil import PathScripts.PathUtils as PathUtils import math - -from PySide import QtCore +from PathScripts.PathGeom import CmdMoveCW, CmdMoveStraight, CmdMoveArc, CmdMoveRapid # lazily loaded modules from lazy_loader.lazy_loader import LazyLoader @@ -38,26 +40,22 @@ from lazy_loader.lazy_loader import LazyLoader DraftGeomUtils = LazyLoader("DraftGeomUtils", globals(), "DraftGeomUtils") Part = LazyLoader("Part", globals(), "Part") -LOG_MODULE = PathLog.thisModule() -PathLog.setLevel(PathLog.Level.NOTICE, LOG_MODULE) -# PathLog.trackModule(LOG_MODULE) +if False: + PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) + PathLog.trackModule(PathLog.thisModule()) +else: + PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) -# Qt translation handling -def translate(context, text, disambig=None): - return QtCore.QCoreApplication.translate(context, text, disambig) +translate = FreeCAD.Qt.translate -movecommands = ["G0", "G00", "G1", "G01", "G2", "G02", "G3", "G03"] -movestraight = ["G1", "G01"] -movecw = ["G2", "G02"] -moveccw = ["G3", "G03"] -movearc = movecw + moveccw +movecommands = CmdMoveStraight + CmdMoveRapid + CmdMoveArc def debugMarker(vector, label, color=None, radius=0.5): - if PathLog.getLevel(LOG_MODULE) == PathLog.Level.DEBUG: + if PathLog.getLevel(PathLog.thisModule()) == PathLog.Level.DEBUG: obj = FreeCAD.ActiveDocument.addObject("Part::Sphere", label) obj.Label = label obj.Radius = radius @@ -69,7 +67,7 @@ def debugMarker(vector, label, color=None, radius=0.5): def debugCircle(vector, r, label, color=None): - if PathLog.getLevel(LOG_MODULE) == PathLog.Level.DEBUG: + if PathLog.getLevel(PathLog.thisModule()) == PathLog.Level.DEBUG: obj = FreeCAD.ActiveDocument.addObject("Part::Cylinder", label) obj.Label = label obj.Radius = r @@ -121,9 +119,9 @@ def edgesForCommands(cmds, startPt): for cmd in cmds: if cmd.Name in movecommands: pt = pointFromCommand(cmd, lastPt) - if cmd.Name in movestraight: + if cmd.Name in CmdMoveStraight: edges.append(Part.Edge(Part.LineSegment(lastPt, pt))) - elif cmd.Name in movearc: + elif cmd.Name in CmdMoveArc: center = lastPt + pointFromCommand( cmd, FreeCAD.Vector(0, 0, 0), "I", "J", "K" ) @@ -134,7 +132,7 @@ def edgesForCommands(cmds, startPt): if d == 0: # we're dealing with half a circle here angle = getAngle(A) + math.pi / 2 - if cmd.Name in movecw: + if cmd.Name in CmdMoveCW: angle -= math.pi else: C = A + B @@ -432,14 +430,14 @@ class ObjectDressup(object): "App::PropertyLink", "Base", "Base", - QtCore.QT_TRANSLATE_NOOP("Path_DressupDogbone", "The base path to modify"), + QT_TRANSLATE_NOOP("App::Property", "The base path to modify"), ) obj.addProperty( "App::PropertyEnumeration", "Side", "Dressup", - QtCore.QT_TRANSLATE_NOOP( - "Path_DressupDogbone", "The side of path to insert bones" + QT_TRANSLATE_NOOP( + "App::Property", "The side of path to insert bones" ), ) obj.Side = [Side.Left, Side.Right] @@ -448,7 +446,7 @@ class ObjectDressup(object): "App::PropertyEnumeration", "Style", "Dressup", - QtCore.QT_TRANSLATE_NOOP("Path_DressupDogbone", "The style of bones"), + QT_TRANSLATE_NOOP("App::Property", "The style of bones"), ) obj.Style = Style.All obj.Style = Style.Dogbone @@ -456,8 +454,8 @@ class ObjectDressup(object): "App::PropertyIntegerList", "BoneBlacklist", "Dressup", - QtCore.QT_TRANSLATE_NOOP( - "Path_DressupDogbone", "Bones that aren't dressed up" + QT_TRANSLATE_NOOP( + "App::Property", "Bones that aren't dressed up" ), ) obj.BoneBlacklist = [] @@ -466,8 +464,8 @@ class ObjectDressup(object): "App::PropertyEnumeration", "Incision", "Dressup", - QtCore.QT_TRANSLATE_NOOP( - "Path_DressupDogbone", "The algorithm to determine the bone length" + QT_TRANSLATE_NOOP( + "App::Property", "The algorithm to determine the bone length" ), ) obj.Incision = Incision.All @@ -476,8 +474,8 @@ class ObjectDressup(object): "App::PropertyFloat", "Custom", "Dressup", - QtCore.QT_TRANSLATE_NOOP( - "Path_DressupDogbone", "Dressup length if Incision == custom" + QT_TRANSLATE_NOOP( + "App::Property", "Dressup length if Incision == custom" ), ) obj.Custom = 0.0 @@ -510,7 +508,7 @@ class ObjectDressup(object): # Answer true if a dogbone could be on either end of the chord, given its command def canAttachDogbone(self, cmd, chord): return ( - cmd.Name in movestraight + cmd.Name in CmdMoveStraight and not chord.isAPlungeMove() and not chord.isANoopMove() ) @@ -884,7 +882,7 @@ class ObjectDressup(object): commands.append(c1) # 3. change where c2 starts, this depends on the command itself c2 = bone2.inCommands[j] - if c2.Name in movearc: + if c2.Name in CmdMoveArc: center = e2.Curve.Center offset = center - pt c2Params = c2.Parameters @@ -1142,9 +1140,7 @@ class TaskPanel(object): self.obj = obj self.form = FreeCADGui.PySideUic.loadUi(":/panels/DogboneEdit.ui") self.s = None - FreeCAD.ActiveDocument.openTransaction( - translate("Path_DressupDogbone", "Edit Dogbone Dress-up") - ) + FreeCAD.ActiveDocument.openTransaction("Edit Dogbone Dress-up") self.height = 10 self.markers = [] @@ -1231,7 +1227,7 @@ class TaskPanel(object): self.form.customLabel.setEnabled(customSelected) self.updateBoneList() - if PathLog.getLevel(LOG_MODULE) == PathLog.Level.DEBUG: + if PathLog.getLevel(PathLog.thisModule()) == PathLog.Level.DEBUG: for obj in FreeCAD.ActiveDocument.Objects: if obj.Name.startswith("Shape"): FreeCAD.ActiveDocument.removeObject(obj.Name) @@ -1384,10 +1380,10 @@ class CommandDressupDogbone(object): def GetResources(self): return { "Pixmap": "Path_Dressup", - "MenuText": QtCore.QT_TRANSLATE_NOOP( + "MenuText": QT_TRANSLATE_NOOP( "Path_DressupDogbone", "Dogbone Dress-up" ), - "ToolTip": QtCore.QT_TRANSLATE_NOOP( + "ToolTip": QT_TRANSLATE_NOOP( "Path_DressupDogbone", "Creates a Dogbone Dress-up object from a selected path", ), @@ -1418,9 +1414,7 @@ class CommandDressupDogbone(object): return # everything ok! - FreeCAD.ActiveDocument.openTransaction( - translate("Path_DressupDogbone", "Create Dogbone Dress-up") - ) + FreeCAD.ActiveDocument.openTransaction("Create Dogbone Dress-up") FreeCADGui.addModule("PathScripts.PathDressupDogbone") FreeCADGui.doCommand( "PathScripts.PathDressupDogbone.Create(FreeCAD.ActiveDocument.%s)" diff --git a/src/Mod/Path/PathScripts/PathDressupPathBoundary.py b/src/Mod/Path/PathScripts/PathDressupPathBoundary.py index 6a2c737924..6e7df53aeb 100644 --- a/src/Mod/Path/PathScripts/PathDressupPathBoundary.py +++ b/src/Mod/Path/PathScripts/PathDressupPathBoundary.py @@ -20,6 +20,7 @@ # * * # *************************************************************************** +from PySide.QtCore import QT_TRANSLATE_NOOP import FreeCAD import Path import PathScripts.PathDressup as PathDressup @@ -29,15 +30,14 @@ import PathScripts.PathStock as PathStock import PathScripts.PathUtil as PathUtil import PathScripts.PathUtils as PathUtils -from PySide import QtCore - -PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) -# PathLog.trackModule(PathLog.thisModule()) +if False: + PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) + PathLog.trackModule(PathLog.thisModule()) +else: + PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) -# Qt translation handling -def translate(context, text, disambig=None): - return QtCore.QCoreApplication.translate(context, text, disambig) +translate = FreeCAD.Qt.translate def _vstr(v): @@ -52,17 +52,15 @@ class DressupPathBoundary(object): "App::PropertyLink", "Base", "Base", - QtCore.QT_TRANSLATE_NOOP( - "Path_DressupPathBoundary", "The base path to modify" - ), + QT_TRANSLATE_NOOP("App::Property", "The base path to modify"), ) obj.Base = base obj.addProperty( "App::PropertyLink", "Stock", "Boundary", - QtCore.QT_TRANSLATE_NOOP( - "Path_DressupPathBoundary", + QT_TRANSLATE_NOOP( + "App::Property", "Solid object to be used to limit the generated Path.", ), ) @@ -71,8 +69,8 @@ class DressupPathBoundary(object): "App::PropertyBool", "Inside", "Boundary", - QtCore.QT_TRANSLATE_NOOP( - "Path_DressupPathBoundary", + QT_TRANSLATE_NOOP( + "App::Property", "Determines if Boundary describes an inclusion or exclusion mask.", ), ) diff --git a/src/Mod/Path/PathScripts/PathDressupPathBoundaryGui.py b/src/Mod/Path/PathScripts/PathDressupPathBoundaryGui.py index c76f9e2042..6d5540d805 100644 --- a/src/Mod/Path/PathScripts/PathDressupPathBoundaryGui.py +++ b/src/Mod/Path/PathScripts/PathDressupPathBoundaryGui.py @@ -20,21 +20,22 @@ # * * # *************************************************************************** +from PySide import QtGui +from PySide.QtCore import QT_TRANSLATE_NOOP import FreeCAD import FreeCADGui import PathGui as PGui # ensure Path/Gui/Resources are loaded import PathScripts.PathDressupPathBoundary as PathDressupPathBoundary import PathScripts.PathLog as PathLog -from PySide import QtGui, QtCore - -PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) -# PathLog.trackModule() +if False: + PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) + PathLog.trackModule(PathLog.thisModule()) +else: + PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) -# Qt translation handling -def translate(context, text, disambig=None): - return QtCore.QCoreApplication.translate(context, text, disambig) +translate = FreeCAD.Qt.translate class TaskPanel(object): @@ -245,9 +246,7 @@ class DressupPathBoundaryViewProvider(object): def Create(base, name="DressupPathBoundary"): - FreeCAD.ActiveDocument.openTransaction( - translate("Path_DressupPathBoundary", "Create a Boundary dressup") - ) + FreeCAD.ActiveDocument.openTransaction("Create a Boundary dressup") obj = PathDressupPathBoundary.Create(base, name) obj.ViewObject.Proxy = DressupPathBoundaryViewProvider(obj.ViewObject) obj.Base.ViewObject.Visibility = False @@ -263,10 +262,10 @@ class CommandPathDressupPathBoundary: def GetResources(self): return { "Pixmap": "Path_Dressup", - "MenuText": QtCore.QT_TRANSLATE_NOOP( + "MenuText": QT_TRANSLATE_NOOP( "Path_DressupPathBoundary", "Boundary Dress-up" ), - "ToolTip": QtCore.QT_TRANSLATE_NOOP( + "ToolTip": QT_TRANSLATE_NOOP( "Path_DressupPathBoundary", "Creates a Path Boundary Dress-up object from a selected path", ), @@ -291,9 +290,7 @@ class CommandPathDressupPathBoundary: baseObject = selection[0] # everything ok! - FreeCAD.ActiveDocument.openTransaction( - translate("Path_DressupPathBoundary", "Create Path Boundary Dress-up") - ) + FreeCAD.ActiveDocument.openTransaction("Create Path Boundary Dress-up") FreeCADGui.addModule("PathScripts.PathDressupPathBoundaryGui") FreeCADGui.doCommand( "PathScripts.PathDressupPathBoundaryGui.Create(App.ActiveDocument.%s)" diff --git a/src/Mod/Path/PathScripts/PathDressupRampEntry.py b/src/Mod/Path/PathScripts/PathDressupRampEntry.py index 0724652d99..bd53bbfce5 100644 --- a/src/Mod/Path/PathScripts/PathDressupRampEntry.py +++ b/src/Mod/Path/PathScripts/PathDressupRampEntry.py @@ -20,6 +20,8 @@ # * * # *************************************************************************** +from PathScripts import PathUtils +from PySide.QtCore import QT_TRANSLATE_NOOP import FreeCAD import Path import PathScripts.PathDressup as PathDressup @@ -27,8 +29,6 @@ import PathScripts.PathGeom as PathGeom import PathScripts.PathLog as PathLog import math -from PathScripts import PathUtils -from PySide import QtCore # lazily loaded modules from lazy_loader.lazy_loader import LazyLoader @@ -39,12 +39,14 @@ if FreeCAD.GuiUp: import FreeCADGui -# Qt translation handling -def translate(text, context="Path_DressupRampEntry", disambig=None): - return QtCore.QCoreApplication.translate(context, text, disambig) +translate = FreeCAD.Qt.translate -PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) +if False: + PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) + PathLog.trackModule(PathLog.thisModule()) +else: + PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) class ObjectDressup: @@ -54,41 +56,37 @@ class ObjectDressup: "App::PropertyLink", "Base", "Path", - QtCore.QT_TRANSLATE_NOOP( - "Path_DressupRampEntry", "The base path to modify" - ), + QT_TRANSLATE_NOOP("App::Property", "The base path to modify"), ) obj.addProperty( "App::PropertyAngle", "Angle", "Path", - QtCore.QT_TRANSLATE_NOOP("Path_DressupRampEntry", "Angle of ramp."), + QT_TRANSLATE_NOOP("App::Property", "Angle of ramp."), ) obj.addProperty( "App::PropertyEnumeration", "Method", "Path", - QtCore.QT_TRANSLATE_NOOP("App::Property", "Ramping Method"), + QT_TRANSLATE_NOOP("App::Property", "Ramping Method"), ) obj.addProperty( "App::PropertyEnumeration", "RampFeedRate", "FeedRate", - QtCore.QT_TRANSLATE_NOOP( - "App::Property", "Which feed rate to use for ramping" - ), + QT_TRANSLATE_NOOP("App::Property", "Which feed rate to use for ramping"), ) obj.addProperty( "App::PropertySpeed", "CustomFeedRate", "FeedRate", - QtCore.QT_TRANSLATE_NOOP("App::Property", "Custom feed rate"), + QT_TRANSLATE_NOOP("App::Property", "Custom feed rate"), ) obj.addProperty( "App::PropertyBool", "UseStartDepth", "StartDepth", - QtCore.QT_TRANSLATE_NOOP( + QT_TRANSLATE_NOOP( "App::Property", "Should the dressup ignore motion commands above DressupStartDepth", ), @@ -97,18 +95,16 @@ class ObjectDressup: "App::PropertyDistance", "DressupStartDepth", "StartDepth", - QtCore.QT_TRANSLATE_NOOP( + QT_TRANSLATE_NOOP( "App::Property", "The depth where the ramp dressup is enabled. Above this ramps are not generated, but motion commands are passed through as is.", ), ) - obj.Method = ["RampMethod1", "RampMethod2", "RampMethod3", "Helix"] - obj.RampFeedRate = [ - "Horizontal Feed Rate", - "Vertical Feed Rate", - "Ramp Feed Rate", - "Custom", - ] + + # populate the enumerations + for n in self.propertyEnumerations(): + setattr(obj, n[0], n[1]) + obj.Proxy = self self.setEditorProperties(obj) @@ -121,6 +117,55 @@ class ObjectDressup: self.ignoreAboveEnabled = None self.ignoreAbove = None + @classmethod + def propertyEnumerations(self, dataType="data"): + """PropertyEnumerations(dataType="data")... return property enumeration lists of specified dataType. + Args: + dataType = 'data', 'raw', 'translated' + Notes: + 'data' is list of internal string literals used in code + 'raw' is list of (translated_text, data_string) tuples + 'translated' is list of translated string literals + """ + + enums = { + "Object": [ + (translate("Path_DressupRampEntry", "RampMethod1"), "RampMethod1"), + (translate("Path_DressupRampEntry", "RampMethod2"), "RampMethod2"), + (translate("Path_DressupRampEntry", "RampMethod3"), "RampMethod3"), + (translate("Path_DressupRampEntry", "Helix"), "Helix"), + ], + "RampFeedRate": [ + ( + translate("Path_DressupRampEntry", "Horizontal Feed Rate"), + "Horizontal Feed Rate", + ), + ( + translate("Path_DressupRampEntry", "Vertical Feed Rate"), + "Vertical Feed Rate", + ), + ( + translate("Path_DressupRampEntry", "Ramp Feed Rate"), + "Ramp Feed Rate", + ), + (translate("Path_DressupRampEntry", "Custom"), "Custom"), + ], + } + + if dataType == "raw": + return enums + + data = list() + idx = 0 if dataType == "translated" else 1 + + PathLog.debug(enums) + + for k, v in enumerate(enums): + data.append((v, [tup[idx] for tup in enums[v]])) + PathLog.debug(data) + + return data + def __getstate__(self): return None @@ -855,10 +900,10 @@ class CommandPathDressupRampEntry: def GetResources(self): return { "Pixmap": "Path_Dressup", - "MenuText": QtCore.QT_TRANSLATE_NOOP( + "MenuText": QT_TRANSLATE_NOOP( "Path_DressupRampEntry", "RampEntry Dress-up" ), - "ToolTip": QtCore.QT_TRANSLATE_NOOP( + "ToolTip": QT_TRANSLATE_NOOP( "Path_DressupRampEntry", "Creates a Ramp Entry Dress-up object from a selected path", ), @@ -875,18 +920,26 @@ class CommandPathDressupRampEntry: # check that the selection contains exactly what we want selection = FreeCADGui.Selection.getSelection() if len(selection) != 1: - PathLog.error(translate("Please select one path object") + "\n") + PathLog.error( + translate("Path_DressupRampEntry", "Please select one path object") + + "\n" + ) return baseObject = selection[0] if not baseObject.isDerivedFrom("Path::Feature"): - PathLog.error(translate("The selected object is not a path") + "\n") + PathLog.error( + translate("Path_DressupRampEntry", "The selected object is not a path") + + "\n" + ) return if baseObject.isDerivedFrom("Path::FeatureCompoundPython"): - PathLog.error(translate("Please select a Profile object")) + PathLog.error( + translate("Path_DressupRampEntry", "Please select a Profile object") + ) return # everything ok! - FreeCAD.ActiveDocument.openTransaction(translate("Create RampEntry Dress-up")) + FreeCAD.ActiveDocument.openTransaction("Create RampEntry Dress-up") FreeCADGui.addModule("PathScripts.PathDressupRampEntry") FreeCADGui.addModule("PathScripts.PathUtils") FreeCADGui.doCommand(