diff --git a/AnimationLib.py b/AnimationLib.py index bb5bf565..346d6807 100644 --- a/AnimationLib.py +++ b/AnimationLib.py @@ -16,6 +16,7 @@ import FreeCAD as App import Asm4_libs as Asm4 +from Asm4_Translate import translate # from AnimationProvider import animationProvider @@ -121,11 +122,11 @@ def __init__(self): def GetResources(self): - return {"MenuText": "Animate Assembly", - "ToolTip": "Animate Assembly", - "Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_GearsAnimate.svg') - } - + return { + "MenuText": "Animate Assembly", + "ToolTip": translate("Commands5", "Animate Assembly"), + "Pixmap": os.path.join(Asm4.iconPath, "Asm4_GearsAnimate.svg"), + } def IsActive(self): # is there an active document ? diff --git a/Asm4_Measure.py b/Asm4_Measure.py index e3039abd..23c305bc 100644 --- a/Asm4_Measure.py +++ b/Asm4_Measure.py @@ -42,8 +42,8 @@ # only needed for icons import Asm4_libs as Asm4 import selectionFilter - - +from BaseCommand import BaseCommand +from Asm4_Translate import translate """ @@ -88,15 +88,14 @@ def getIcon(self): | The menu and toolbar command | +-----------------------------------------------+ """ -class MeasureCmd(): - def __init__(self): - super(MeasureCmd,self).__init__() - def GetResources(self): - return {"MenuText": "Measure", - "ToolTip": "Measure Tool", - "Pixmap" : os.path.join( iconDir , 'Part_Measure.svg') - } + +class MeasureCmd(BaseCommand): + def __init__(self): + super(MeasureCmd, self).__init__() + self.pixmap = os.path.join(iconDir, "Part_Measure.svg") + self.menutext = "Measure" + self.tooltip = translate("Commands5", "Measure Tool") def IsActive(self): if App.ActiveDocument: diff --git a/Asm4_Translate.py b/Asm4_Translate.py index bac75007..a05715b4 100644 --- a/Asm4_Translate.py +++ b/Asm4_Translate.py @@ -5,12 +5,20 @@ # # Asm4_Translate.py - +import os +import FreeCADGui as Gui import FreeCAD as App +Gui.addLanguagePath(os.path.join(os.path.dirname(__file__), "Resources/translations")) + + +def _atr(context: str, text: str) -> str: + """Wrap strings which should be translated in in this function.""" + return App.Qt.translate(context, text) + -# dummy function for the QT translator -def QT_TRANSLATE_NOOP(context, text): +def QT_TRANSLATE_NOOP(context: str, text: str) -> str: + """NOP Marker Macro Alias for strings for which FreeCAD/Qt handles translations.""" return text diff --git a/BaseCommand.py b/BaseCommand.py new file mode 100644 index 00000000..91a21c97 --- /dev/null +++ b/BaseCommand.py @@ -0,0 +1,16 @@ +class BaseCommand(): + """Base class to prepare all the commands.""" + + def __init__(self): + pass + + def Activated(self): + pass + + def GetResources(self): + return { + "Pixmap": self.pixmap, + "MenuText": self.menutext, + "ToolTip": self.tooltip, + } + diff --git a/FastenersDummy.py b/FastenersDummy.py index 3644bd60..99793f90 100644 --- a/FastenersDummy.py +++ b/FastenersDummy.py @@ -9,6 +9,9 @@ import FreeCADGui as Gui import FreeCAD as App + +from BaseCommand import BaseCommand +from Asm4_Translate import translate #from FastenerBase import FSBaseObject import Asm4_libs as Asm4 @@ -28,10 +31,14 @@ screwObj = sm.createFastener('ISO7046', 'M6', '20', 'simple', shapeOnly=False) """ -class insertFastener: +class insertFastener(BaseCommand): "My tool object" def __init__(self, fastenerType): self.fastenerType = fastenerType + self.tooltip = translate("Fasteners", + "FastenersWorkbench is not installed.\n \n" + "You can install it with the FreeCAD AddonsManager:\n" + "Menu Tools > Addon Manager > fasteners") # Screw: if self.fastenerType=='Screw': self.menutext = translate("Fasteners", "Insert Screw") @@ -72,17 +79,17 @@ def Activated(self): | dummy placeFastener | +-----------------------------------------------+ """ -class placeFastenerCmd(): +class placeFastenerCmd(BaseCommand): "My tool object" def __init__(self): super(placeFastenerCmd,self).__init__() - - def GetResources(self): - return {"MenuText": "Edit Attachment of a Fastener", - "ToolTip": 'FastenersWorkbench is not installed.\n \nYou can install it with the FreeCAD AddonsManager:\nMenu Tools > Addon Manager > fasteners', - "Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_mvFastener.svg') - } + self.icon = os.path.join( Asm4.iconPath , 'Asm4_mvFastener.svg') + self.menutext = translate("Fasteners", "Edit Attachment of a Fastener") + self.tooltip = translate("Fasteners", + "FastenersWorkbench is not installed.\n \n" + "You can install it with the FreeCAD AddonsManager:\n" + "Menu Tools > Addon Manager > fasteners") def IsActive(self): # it's a dummy, always inactive @@ -97,15 +104,13 @@ def Activated(self): | dummy parameters | +-----------------------------------------------+ """ -class changeFSparametersCmd(): +class changeFSparametersCmd(BaseCommand): def __init__(self): super(changeFSparametersCmd,self).__init__() - - def GetResources(self): - return {"MenuText": "Change Fastener parameters", - "ToolTip": "Change Fastener parameters", - "Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_FSparams.svg') - } + self.icon = os.path.join( Asm4.iconPath , 'Asm4_FSparams.svg') + self.menutext = translate("Fasteners", "Change Fastener parameters") + self.tooltip = translate("Fasteners", + "Change Fastener parameters") def IsActive(self): # it's a dummy, always inactive @@ -116,15 +121,10 @@ def Activated(self): -class cloneFastenersToAxesCmd(): +class cloneFastenersToAxesCmd(BaseCommand): def __init__(self): super(cloneFastenersToAxesCmd,self).__init__() - - def GetResources(self): - return {"MenuText": "Clone Fastener to Axes", - "ToolTip": 'FastenersWorkbench is not installed.\n \nYou can install it with the FreeCAD AddonsManager:\nMenu Tools > Addon Manager > fasteners', - "Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_cloneFasteners.svg') - } + self.pixmap def IsActive(self): # it's a dummy, always inactive diff --git a/FastenersLib.py b/FastenersLib.py index 12b57b61..97cb9220 100644 --- a/FastenersLib.py +++ b/FastenersLib.py @@ -20,11 +20,8 @@ from Asm4_Translate import translate - # icon to show in the Menu, toolbar and widget window -iconFile = os.path.join( Asm4.iconPath , 'Asm4_mvFastener.svg') - - +iconFile = os.path.join(Asm4.iconPath, "Asm4_mvFastener.svg") """ @@ -49,7 +46,8 @@ """ -class insertFastener: + +class insertFastener(BaseCommand): "My tool object" def __init__(self, fastenerType): self.FSclass = fastenerType @@ -59,40 +57,43 @@ def __init__(self, fastenerType): 'ThreadedRod':(0.3, 0.5, 0.75) } # Screw - if self.FSclass == 'Screw': - self.menutext = translate("Fasteners", "Insert Screw") - self.tooltip = "
Insert a Screw into the Assembly
" - self.tooltip += "If another fastener is selected, a new fastener of the same type is created in the same assembly." - self.tooltip += "If an axis or LCS is selected, the new fastener will be attached to it." - self.tooltip += "If an assembly is selected, the new fastener will be inside that assembly.
" - self.icon = os.path.join( Asm4.iconPath , 'Asm4_Screw.svg') + if self.FSclass == "Screw": + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Screw.svg") + self.menutext = translate("Fasteners", "Insert Screw") + self.tooltip = translate( + "Fasteners", + "Insert a Screw into the Assembly
\n" + "If another fastener is selected, a new fastener of the same type is created in the same assembly.\n" + "If an axis or LCS is selected, the new fastener will be attached to it.\n" + "If an assembly is selected, the new fastener will be inside that assembly.
", + ) # Nut - elif self.FSclass == 'Nut': - self.menutext = translate("Fasteners", "Insert Nut") - self.tooltip = "Insert a Nut into the Assembly
" - self.tooltip += "If another fastener is selected, a new fastener of the same type is created in the same assembly." - self.tooltip += "If an axis or LCS is selected, the new fastener will be attached to it." - self.tooltip += "If an assembly is selected, the new fastener will be inside that assembly.
" - self.icon = os.path.join( Asm4.iconPath , 'Asm4_Nut.svg') + elif self.FSclass == "Nut": + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Nut.svg") + self.menutext = translate("Fasteners", "Insert Nut") + self.tooltip = translate( + "Fasteners", + "Insert a Nut into the Assembly
\n" + "If another fastener is selected, a new fastener of the same type is created in the same assembly.\n" + "If an axis or LCS is selected, the new fastener will be attached to it.\n" + "If an assembly is selected, the new fastener will be inside that assembly.
", + ) # Washer - elif self.FSclass == 'Washer': - self.menutext = translate("Fasteners", "Insert Washer") - self.tooltip = "Insert a Washer into the Assembly
" - self.tooltip += "If another fastener is selected, a new fastener of the same type is created in the same assembly." - self.tooltip += "If an axis or LCS is selected, the new fastener will be attached to it." - self.tooltip += "If an assembly is selected, the new fastener will be inside that assembly.
" - self.icon = os.path.join( Asm4.iconPath , 'Asm4_Washer.svg') + elif self.FSclass == "Washer": + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Washer.svg") + self.menutext = translate("Fasteners", "Insert Washer") + self.tooltip = translate( + "Fasteners", + "Insert a Washer into the Assembly
\n" + "If another fastener is selected, a new fastener of the same type is created in the same assembly.\n" + "If an axis or LCS is selected, the new fastener will be attached to it.\n" + "If an assembly is selected, the new fastener will be inside that assembly.
", + ) # Threaded Rod (makes errors) - elif self.FSclass == 'ThreadedRod': - self.menutext = translate("Fasteners", "Insert threaded rod") - self.tooltip = "Insert threaded rod" - self.icon = os.path.join( Asm4.iconPath , 'Asm4_Rod.svg') - - - def GetResources(self): - return {"MenuText": self.menutext, - "ToolTip" : self.tooltip, - "Pixmap" : self.icon } + elif self.FSclass == "ThreadedRod": + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Rod.svg") + self.menutext = translate("Fasteners", "Insert threaded rod") + self.tooltip = translate("Fasteners", "Insert threaded rod") def IsActive(self): # if Asm4.getAssembly(): @@ -216,16 +217,14 @@ def Activated(self): | wrapper for FSChangeParams | +-----------------------------------------------+ """ -class changeFSparametersCmd(): - def __init__(self): - super(changeFSparametersCmd,self).__init__() - def GetResources(self): - return {"MenuText": "Change Fastener parameters", - "ToolTip": "Change Fastener parameters", - "Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_FSparams.svg') - } +class changeFSparametersCmd(BaseCommand): + def __init__(self): + super(changeFSparametersCmd, self).__init__() + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_FSparams.svg") + self.menutext = translate("Fasteners", "Change Fastener parameters") + self.tooltip = translate("Fasteners", "Change Fastener parameters") def IsActive(self): if App.ActiveDocument and getSelectionFS(): @@ -278,21 +277,18 @@ def isFastener(obj): +-----------------------------------------------+ | clone per App::Link fasteners | +-----------------------------------------------+ - + Select a fastener and several datum axes and the fastener will be cloned (as App::Link) and attached to those axes """ -class cloneFastenersToAxesCmd(): - +class cloneFastenersToAxesCmd(BaseCommand): + def __init__(self): super(cloneFastenersToAxesCmd,self).__init__() - - def GetResources(self): - return {"MenuText": "Clone Fastener to Axes", - "ToolTip": "Clone Fastener to Axes", - "Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_cloneFasteners.svg') - } - + self.pixmap = os.path.join( Asm4.iconPath , 'Asm4_cloneFasteners.svg') + self.menutext = translate("Fasteners", "Clone Fastener to Axes") + self.tooltip = translate("Fasteners", "Clone Fastener to Axes") + def IsActive(self): self.selection = self.getSelectedAxes() if Asm4.getAssembly() and self.selection: @@ -316,7 +312,7 @@ def Activated(self): if axis and axis.Document: newFstnr = Asm4.cloneObject(fstnr) Asm4.placeObjectToLCS(newFstnr, axisData[2], axis.Document.Name, axisData[3]) - + Gui.Selection.clearSelection() self.rootAssembly = Asm4.getAssembly() if self.rootAssembly: @@ -327,7 +323,7 @@ def getSelectedAxes(self): holeAxes = [] fstnr = None selection = Gui.Selection.getSelectionEx('', 0) - + if selection: for s in selection: for seNames in s.SubElementNames: diff --git a/HelpCmd.py b/HelpCmd.py index ce11abe6..855dc5b5 100644 --- a/HelpCmd.py +++ b/HelpCmd.py @@ -6,12 +6,11 @@ # # HelpCmd.py -import os, webbrowser - -import FreeCADGui as Gui - +import os +import webbrowser import Asm4_libs as Asm4 from Asm4_Translate import translate +import FreeCADGui as Gui """ diff --git a/InitGui.py b/InitGui.py index f3da1528..5384b535 100644 --- a/InitGui.py +++ b/InitGui.py @@ -25,26 +25,35 @@ import os import Asm4_locator -global Asm4_icon, Asm4_path, Asm4_trans -Asm4_path = os.path.dirname( Asm4_locator.__file__ ) -Asm4_icon = os.path.join( Asm4_path , 'Resources/icons/Assembly4.svg' ) -Asm4_trans = os.path.join(Asm4_path, "Resources/translations") # I don't like this being here import selectionFilter +from Asm4_Translate import translate + +global Asm4_icon, Asm4_path, Asm4_trans +Asm4_path = os.path.dirname(Asm4_locator.__file__) +Asm4_icon = os.path.join(Asm4_path, "Resources/icons/Assembly4.svg") +Asm4_trans = os.path.join(Asm4_path, "Resources/translations") + +FreeCADGui.addLanguagePath(Asm4_trans) +FreeCADGui.updateLocale() + """ +-----------------------------------------------+ | Initialize the workbench | +-----------------------------------------------+ """ + + class Assembly4Workbench(Workbench): + from TranslateUtils import translate global Asm4_icon global selectionFilter MenuText = "Assembly 4" - ToolTip = "Assembly 4 workbench" + ToolTip = translate("Asm4", "Assembly 4 workbench") Icon = Asm4_icon def __init__(self): @@ -64,12 +73,14 @@ def __init__(self): def Activated(self): "This function is executed when the workbench is activated" + # FreeCAD.Console.PrintMessage(translate("Asm4", "Activating Assembly4 WorkBench") + '\n') # make buttons of the selection toolbar checkable from PySide import QtGui + mainwin = Gui.getMainWindow() sf_tb = None for tb in mainwin.findChildren(QtGui.QToolBar): - if tb.objectName()=='Selection Filter': + if tb.objectName() == "Selection Filter": sf_tb = tb # make all buttons except last one (clear selection filter) checkable if sf_tb is not None: @@ -80,6 +91,7 @@ def Activated(self): def Deactivated(self): "This function is executed when the workbench is deactivated" selectionFilter.observerDisable() + # FreeCAD.Console.PrintMessage(translate("Asm4", "Leaving Assembly4 WorkBench") + "\n") return def GetClassName(self): @@ -91,6 +103,7 @@ def GetClassName(self): | This is where all is defined | +-----------------------------------------------+ """ + def Initialize(self): # check for FreeCAD version FCver = FreeCAD.Version() @@ -111,271 +124,306 @@ def Initialize(self): pass ''' - # Translations - # from Asm4_Translate import Qtranslate - FreeCADGui.addLanguagePath(Asm4_trans) - FreeCADGui.updateLocale() - # Assembly4 version info # with file package.xml (FreeCAD ≥0.21) - packageFile = os.path.join( Asm4_path, 'package.xml' ) + packageFile = os.path.join(Asm4_path, "package.xml") try: - metadata = FreeCAD.Metadata(packageFile) - Asm4_date = metadata.Date + metadata = FreeCAD.Metadata(packageFile) + Asm4_date = metadata.Date Asm4_version = metadata.Version # with file VERSION (FreeCAD ≤0.20) except: - versionPath = os.path.join( Asm4_path, 'VERSION' ) - versionFile = open(versionPath,"r") + """ + FCVersion = App.Version()[0]+'.'+App.Version()[1] + if FCVersion=='0.19': + FCDate = " from "+App.Version()[4][0:4] + elif FCVersion=='0.20': + FCDate = " from "+App.Version()[5][0:4] + else : + FCDate = "" + message = "You seem to be using FreeCAD version "+FCVersion+FCDate+" which is quite old. " + message += "Some functionality of latest versions might be missing\n" + FreeCAD.Console.PrintMessage(message) + """ + versionPath = os.path.join(Asm4_path, "VERSION") + versionFile = open(versionPath, "r") # read second line version = versionFile.readlines()[1] versionFile.close() # remove trailing newline Asm4_version = version[:-1] - - FreeCAD.Console.PrintMessage("Initializing Assembly4 workbench"+ ' ('+Asm4_version+') .') - FreeCADGui.updateGui() - # import all stuff - import newAssemblyCmd # created an App::Part container called 'Assembly' - self.dot() - import newDatumCmd # creates a new LCS in 'Model' + + FreeCAD.Console.PrintMessage(translate("Asm4", "Initializing Assembly4 workbench")+ ' ('+Asm4_version+') .') + self.dot() - import newPartCmd # creates a new App::Part container called 'Model' + import newPartCmd # creates a new App::Part container called 'Model' + self.dot() - import infoPartCmd # edits part information for BoM + import infoPartCmd # edits part information for BoM + self.dot() - import insertLinkCmd # inserts an App::Link to a 'Model' in another file + import insertLinkCmd # inserts an App::Link to a 'Model' in another file + self.dot() - import placeLinkCmd # places a linked part by snapping LCS (in the Part and in the Assembly) + import placeLinkCmd # places a linked part by snapping LCS (in the Part and in the Assembly) + self.dot() - import importDatumCmd # creates an LCS in assembly and attaches it to an LCS relative to an external file + import importDatumCmd # creates an LCS in assembly and attaches it to an LCS relative to an external file + self.dot() - import releaseAttachmentCmd# creates an LCS in assembly and attaches it to an LCS relative to an external file + import releaseAttachmentCmd # creates an LCS in assembly and attaches it to an LCS relative to an external file + self.dot() - import makeBinderCmd # creates an LCS in assembly and attaches it to an LCS relative to an external file + import makeBinderCmd # creates an LCS in assembly and attaches it to an LCS relative to an external file + self.dot() - import VariablesLib # creates an LCS in assembly and attaches it to an LCS relative to an external file + import VariablesLib # creates an LCS in assembly and attaches it to an LCS relative to an external file + self.dot() - import AnimationLib # creates an LCS in assembly and attaches it to an LCS relative to an external file + import AnimationLib # creates an LCS in assembly and attaches it to an LCS relative to an external file + self.dot() - import updateAssemblyCmd # updates all parts and constraints in the assembly + import updateAssemblyCmd # updates all parts and constraints in the assembly + self.dot() - import makeArrayCmd # creates a new array of App::Link + import makeArrayCmd # creates a new array of App::Link + self.dot() - import variantLinkCmd # creates a variant link + import variantLinkCmd # creates a variant link + self.dot() - import gotoDocumentCmd # opens the documentof the selected App::Link + import gotoDocumentCmd # opens the documentof the selected App::Link + self.dot() - import Asm4_Measure # Measure tool in the Task panel + import Asm4_Measure # Measure tool in the Task panel + self.dot() - import makeBomCmd # creates the parts list + import makeBomCmd # creates the parts list + self.dot() - import checkInterference # check interferences btween parts inside the Assembly + import checkInterference # check interferences btween parts inside the Assembly + self.dot() - import exportFiles # creates a hierarchical tree listing of files in an assembly + import exportFiles # creates a hierarchical tree listing of files in an assembly + self.dot() - import HelpCmd # shows a basic help window + import HelpCmd # shows a basic help window + self.dot() - import showHideLcsCmd # shows/hides all the LCSs + import showHideLcsCmd # shows/hides all the LCSs + self.dot() - import configurationEngine # save/restore configuration + import configurationEngine # save/restore configuration + self.dot() # Fasteners - if self.checkWorkbench('FastenersWorkbench'): + if self.checkWorkbench("FastenersWorkbench"): # a library to handle fasteners from the FastenersWorkbench import FastenersLib - self.FastenersCmd = 'Asm4_Fasteners' + + self.FastenersCmd = "Asm4_Fasteners" else: # a dummy library if the FastenersWorkbench is not installed import FastenersDummy - self.FastenersCmd = 'Asm4_insertScrew' - self.dot() + self.FastenersCmd = "Asm4_insertScrew" + self.dot() # Define Menus # commands to appear in the Assembly4 menu 'Assembly' - self.appendMenu("&Assembly", self.assemblyMenuItems()) + self.appendMenu(translate("Asm4", "&Assembly"), self.assemblyMenuItems()) self.dot() # put all constraints related commands in a separate menu - self.appendMenu("&Constraints", self.constraintsMenuItems()) + self.appendMenu(translate("Asm4", "&Constraints"), self.constraintsMenuItems()) self.dot() # self.appendMenu("&Geometry",["Asm4_newPart"]) # additional entry in the Help menu - # self.appendMenu(Qtranslate("Workbench", "&Help"), ["Asm4_Help"]) - self.appendMenu( "&Help", ["Asm4_Help"]) + # self.appendMenu(translate("Asm4", "&Help"), ["Asm4_Help"]) + self.appendMenu(translate("Asm4", "&Help"), ["Asm4_Help"]) self.dot() # Define Toolbars # commands to appear in the Assembly4 toolbar - self.appendToolbar("Assembly", self.assemblyToolbarItems()) + self.appendToolbar(translate("Asm4", "Assembly"), self.assemblyToolbarItems()) self.dot() # build the selection toolbar - self.appendToolbar("Selection Filter", self.selectionToolbarItems()) + self.appendToolbar( + translate("Asm4", "Selection Filter"), self.selectionToolbarItems() + ) self.dot() # self.appendToolbar("Geometry",["Asm4_newPart"]) - FreeCAD.Console.PrintMessage(" " + "done" + ".\n") + FreeCAD.Console.PrintMessage(" " + translate("Asm4", "done") + ".\n") """ +-----------------------------------------------+ | Initialisation finished | +-----------------------------------------------+ """ - - """ +-----------------------------------------------+ | Assembly Menu & Toolbar | +-----------------------------------------------+ """ + def assemblyMenuItems(self): - commandList = [ "Asm4_newAssembly", - "Asm4_newPart", - "Asm4_newBody", - "Asm4_newGroup", - "Asm4_newSketch", - 'Asm4_createDatum', - self.FastenersCmd, - "Separator", - "Asm4_insertLink", - "Asm4_mirrorArray", - "Asm4_linearArray", - "Asm4_circularArray", - "Asm4_expressionArray", - "Asm4_variantLink", - "Separator", - "Asm4_cloneFastenersToAxes", - "Asm4_importDatum", - "Asm4_shapeBinder", - "Separator", - "Asm4_infoPart", - "Asm4_makeLocalBOM", - "Asm4_makeBOM", - "Asm4_listLinkedFiles", - "Asm4_checkInterference", - "Asm4_Measure", - 'Asm4_showLcs', - 'Asm4_hideLcs', - "Asm4_addVariable", - "Asm4_delVariable", - "Asm4_Animate", - "Asm4_openConfigurations" - ] + commandList = [ + "Asm4_newAssembly", + "Asm4_newPart", + "Asm4_newBody", + "Asm4_newGroup", + "Asm4_newSketch", + "Asm4_createDatum", + self.FastenersCmd, + "Separator", + "Asm4_insertLink", + "Asm4_mirrorArray", + "Asm4_linearArray", + "Asm4_circularArray", + "Asm4_expressionArray", + "Asm4_variantLink", + "Separator", + "Asm4_cloneFastenersToAxes", + "Asm4_importDatum", + "Asm4_shapeBinder", + "Separator", + "Asm4_infoPart", + "Asm4_makeLocalBOM", + "Asm4_makeBOM", + "Asm4_listLinkedFiles", + "Asm4_checkInterference", + "Asm4_Measure", + "Asm4_showLcs", + "Asm4_hideLcs", + "Asm4_addVariable", + "Asm4_delVariable", + "Asm4_Animate", + "Asm4_openConfigurations", + ] return commandList def constraintsMenuItems(self): - commandList = [ "Asm4_placeLink", - "Asm4_releaseAttachment", - "Separator", - "Asm4_updateAssembly", - "Separator", - ] + commandList = [ + "Asm4_placeLink", + "Asm4_releaseAttachment", + "Separator", + "Asm4_updateAssembly", + "Separator", + ] return commandList def assemblyToolbarItems(self): - commandList = [ "Asm4_newAssembly", - "Asm4_newPart", - "Asm4_newBody", - "Asm4_newGroup", - "Asm4_infoPart", - "Asm4_insertLink", - "Asm4_variantLink", - self.FastenersCmd, - "Separator", - "Asm4_newSketch", - 'Asm4_createDatum', - "Asm4_importDatum", - "Asm4_shapeBinder", - "Separator", - "Asm4_placeLink", - "Asm4_releaseAttachment", - "Asm4_updateAssembly", - "Separator", - "Asm4_mirrorArray", - "Asm4_linearArray", - "Asm4_circularArray", - "Asm4_expressionArray", - "Asm4_variablesCmd", - "Separator", - "Asm4_Animate", - "Asm4_Measure", - "Asm4_makeBOM", - "Asm4_listLinkedFiles", - 'Asm4_showLcs', - 'Asm4_hideLcs', - "Asm4_checkInterference", - "Asm4_openConfigurations" - ] + commandList = [ + "Asm4_newAssembly", + "Asm4_newPart", + "Asm4_newBody", + "Asm4_newGroup", + "Asm4_infoPart", + "Asm4_insertLink", + "Asm4_variantLink", + self.FastenersCmd, + "Separator", + "Asm4_newSketch", + "Asm4_createDatum", + "Asm4_importDatum", + "Asm4_shapeBinder", + "Separator", + "Asm4_placeLink", + "Asm4_releaseAttachment", + "Asm4_updateAssembly", + "Separator", + "Asm4_mirrorArray", + "Asm4_linearArray", + "Asm4_circularArray", + "Asm4_expressionArray", + "Asm4_variablesCmd", + "Separator", + "Asm4_Animate", + "Asm4_Measure", + "Asm4_makeBOM", + "Asm4_listLinkedFiles", + "Asm4_showLcs", + "Asm4_hideLcs", + "Asm4_checkInterference", + "Asm4_openConfigurations", + ] return commandList - """ +-----------------------------------------------+ | Selection Toolbar | +-----------------------------------------------+ """ + def selectionToolbarItems(self): # commands to appear in the Selection toolbar - commandList = ["Asm4_SelectionFilterVertexCmd", - "Asm4_SelectionFilterEdgeCmd", - "Asm4_SelectionFilterFaceCmd", - "Asm4_selObserver3DViewCmd" , - "Asm4_SelectionFilterClearCmd"] + commandList = [ + "Asm4_SelectionFilterVertexCmd", + "Asm4_SelectionFilterEdgeCmd", + "Asm4_SelectionFilterFaceCmd", + "Asm4_selObserver3DViewCmd", + "Asm4_SelectionFilterClearCmd", + ] return commandList - """ +-----------------------------------------------+ | Contextual Menus | +-----------------------------------------------+ """ + def ContextMenu(self, recipient): # This is executed whenever the user right-clicks on screen" # "recipient" will be either "view" or "tree" - contextMenu = ['Asm4_gotoDocument' , - 'Asm4_showLcs' , - 'Asm4_hideLcs' ] + contextMenu = ["Asm4_gotoDocument", "Asm4_showLcs", "Asm4_hideLcs"] # commands to appear in the 'Assembly' sub-menu in the contextual menu (right-click) - assemblySubMenu =[ "Asm4_insertLink" , - "Asm4_placeLink" , - "Asm4_importDatum" , - 'Asm4_FSparameters' , - 'Separator' , - 'Asm4_applyConfiguration'] + assemblySubMenu = [ + "Asm4_insertLink", + "Asm4_placeLink", + "Asm4_importDatum", + "Asm4_FSparameters", + "Separator", + "Asm4_applyConfiguration", + ] # commands to appear in the 'Create' sub-menu in the contextual menu (right-click) - createSubMenu =["Asm4_newSketch", - "Asm4_newBody", - "Asm4_newLCS", - "Asm4_newAxis", - "Asm4_newPlane", - "Asm4_newPoint", - "Asm4_newHole", - "Asm4_insertScrew", - "Asm4_insertNut", - "Asm4_insertWasher", - 'Separator', - 'Asm4_newConfiguration'] + createSubMenu = [ + "Asm4_newSketch", + "Asm4_newBody", + "Asm4_newLCS", + "Asm4_newAxis", + "Asm4_newPlane", + "Asm4_newPoint", + "Asm4_newHole", + "Asm4_insertScrew", + "Asm4_insertNut", + "Asm4_insertWasher", + "Separator", + "Asm4_newConfiguration", + ] self.appendContextMenu("", "Separator") self.appendContextMenu("", contextMenu) # add commands to the context menu - self.appendContextMenu("Assembly", assemblySubMenu) # add commands to the context menu - self.appendContextMenu("Create", createSubMenu) # add commands to the context menu + self.appendContextMenu( + translate("Asm4", "Assembly"), assemblySubMenu + ) # add commands to the context menu + self.appendContextMenu( + translate("Asm4", "Create"), createSubMenu + ) # add commands to the context menu self.appendContextMenu("", "Separator") - - """ +-----------------------------------------------+ | helper functions | +-----------------------------------------------+ """ - def checkWorkbench( self, workbench ): + + def checkWorkbench(self, workbench): # checks whether the specified workbench (a 'string') is installed listWB = Gui.listWorkbenches() hasWB = False diff --git a/Resources/translations/asm4.ts b/Resources/translations/asm4.ts index 2680cc68..7f37ca0b 100644 --- a/Resources/translations/asm4.ts +++ b/Resources/translations/asm4.ts @@ -1,28 +1,31 @@ -Adds a variable into the Variables placeholder in the document. " - tooltip += "This variable can then be used in any formula using the ExpressionEngine " - tooltip += "of any compatible input field. These are marked with a \"f(x)\" symbol
" - iconFile = os.path.join( Asm4.iconPath , 'Asm4_addVariable.svg') - return {"MenuText": "Add Variable", - "ToolTip": tooltip, - "Pixmap" : iconFile } - + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_addVariable.svg") + self.menutext = "Add Variable" + self.tooltip = translate( + "Commands4", + "Adds a variable into the Variables placeholder in the document.\n" + "This variable can then be used in any formula using the ExpressionEngine\n" + 'of any compatible input field. These are marked with the "f(x)" symbol
', + ) def IsActive(self): # if there is an Asm4 Model in the ActiveDocument, or if an App::Part is selected if App.ActiveDocument: return True return False - def Activated(self): # retrieve the Variables object @@ -229,18 +228,16 @@ def drawUI(self): | delete an existing Variable | +-----------------------------------------------+ """ -class delVariable(): + +class delVariable(BaseCommand): def __init__(self): - super(delVariable,self).__init__() + super(delVariable, self).__init__() self.UI = QtGui.QDialog() self.drawUI() - - def GetResources(self): - return {"MenuText": "Delete Variable", - "ToolTip": "Delete a Variable", - "Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_delVariable.svg') - } + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_delVariable.svg") + self.menutext = "Delete Variable" + self.tooltip = translate("Commands4", "Delete a Variable") def IsActive(self): # if there is an Asm4 Model in the ActiveDocument @@ -359,11 +356,16 @@ def drawUI(self): | add the command to the workbench | +-----------------------------------------------+ """ -Gui.addCommand( 'Asm4_addVariable', addVariable() ) -Gui.addCommand( 'Asm4_delVariable', delVariable() ) - -variablesCmdList = [ 'Asm4_addVariable', 'Asm4_delVariable' ] -tooltip = "Adds a variable into the \"Variables\" placeholder in the document.\n" -tooltip += "This variable can then be used in any formula using the ExpressionEngine\n" -tooltip += "of any compatible input field. These are marked with a \"f(x)\" symbol." -Gui.addCommand( 'Asm4_variablesCmd', Asm4.dropDownCmd( variablesCmdList, 'Variables', tooltip )) +Gui.addCommand("Asm4_addVariable", addVariable()) +Gui.addCommand("Asm4_delVariable", delVariable()) + +variablesCmdList = ["Asm4_addVariable", "Asm4_delVariable"] +tooltip = translate( + "Commands4", + "Adds a variable into the Variables placeholder in the document.\n" + "This variable can then be used in any formula using the ExpressionEngine\n" + 'of any compatible input field. These are marked with the "f(x)" symbol
', +) +Gui.addCommand( + "Asm4_variablesCmd", Asm4.dropDownCmd(variablesCmdList, "Variables", tooltip) +) diff --git a/checkInterference.py b/checkInterference.py index 739e932c..71898bb6 100644 --- a/checkInterference.py +++ b/checkInterference.py @@ -22,23 +22,18 @@ import Asm4_libs as Asm4 import showHideLcsCmd as lcs import Part +from BaseCommand import BaseCommand +from Asm4_Translate import translate -class checkInterference: +class checkInterference(BaseCommand): def __init__(self): super(checkInterference, self).__init__() - - - def GetResources(self): - menutext = "Check Intereferences" - tooltip = "Check interferences among assembled objects (may take time)" - iconFile = os.path.join(Asm4.iconPath, 'Asm4_Interference_Check.svg') - return { - "MenuText": menutext, - "ToolTip": tooltip, - "Pixmap": iconFile - } - + self.menutext = "Check Interferences" + self.tooltip = translate( + "Commands5", "Check interferences among assembled objects (may take time)" + ) + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Interference_Check.svg") def IsActive(self): if Asm4.getAssembly() is None: diff --git a/configurationEngine.py b/configurationEngine.py index 20251190..2024fb0b 100644 --- a/configurationEngine.py +++ b/configurationEngine.py @@ -14,6 +14,9 @@ from FreeCAD import Console as FCC import Asm4_libs as Asm4 +from BaseCommand import BaseCommand +from Asm4_Translate import translate + ASM4_CONFIG_TYPE = 'Asm4::ConfigurationTable' HEADER_CELL = 'A1' @@ -31,7 +34,6 @@ NAME_COL_WIDTH = 250 - """ +-----------------------------------------------+ | create a new empty configuration table | @@ -72,15 +74,18 @@ def createConfig(name, description): | Apply configuration command | +-----------------------------------------------+ """ -class applyConfigurationCmd: - def __init__(self): - super(applyConfigurationCmd,self).__init__() - def GetResources(self): - return {"MenuText": "Apply configuration", - "ToolTip": "Applies selected configuration\nConfigurations allow to set visibilities and offsets of parts", - "Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_applyConfig.svg') - } + +class applyConfigurationCmd(BaseCommand): + def __init__(self): + super(applyConfigurationCmd, self).__init__() + self.menutext = "Apply configuration" + self.tooltip = translate( + "Commands5", + "Applies selected configuration\n" + "Configurations allow to set visibilities and offsets of parts", + ) + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_applyConfig.svg") def IsActive(self): # if a spreadsheet in a Group called "Configuration" is selected @@ -103,15 +108,16 @@ def Activated(self): | General configuration Task UI | +-----------------------------------------------+ """ -class openConfigurationsCmd: - def __init__(self): - super(openConfigurationsCmd,self).__init__() - def GetResources(self): - return {"MenuText": "Open configurations panel", - "ToolTip": "Configurations allow to set visibilities and offsets of parts", - "Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_Configurations.svg') - } + +class openConfigurationsCmd(BaseCommand): + def __init__(self): + super(openConfigurationsCmd, self).__init__() + self.menutext = "Open configurations panel" + self.tooltip = translate( + "Commands5", "Configurations allow to set visibilities and offsets of parts" + ) + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Configurations.svg") def IsActive(self): # Will handle LCSs only for the Assembly4 model @@ -273,18 +279,18 @@ def drawUI(self): | Create new configuration Button | +-----------------------------------------------+ """ -class newConfigurationCmd: + + +class newConfigurationCmd(BaseCommand): def __init__(self): - super(newConfigurationCmd,self).__init__() + super(newConfigurationCmd, self).__init__() self.UI = QtGui.QDialog() self.drawUI() - - def GetResources(self): - return {"MenuText": "New configuration", - "ToolTip": "Create a new configuration of the assembly", - "Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_applyConfig.svg') - } - + self.menutext = "New configuration" + self.tooltip = translate( + "Commands5", "Create a new configuration of the assembly" + ) + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_applyConfig.svg") def IsActive(self): # is there an active document ? diff --git a/exportFiles.py b/exportFiles.py index 5546b641..7b52bd88 100644 --- a/exportFiles.py +++ b/exportFiles.py @@ -29,71 +29,73 @@ from FreeCAD import Console as FCC import Asm4_libs as Asm4 +from BaseCommand import BaseCommand +from Asm4_Translate import translate -''' +""" has_anytree = False try: from anytree import Node, RenderTree has_anytree = True except ImportError: FCC.PrintMessage("\nINFO : Pylib anytree is missing, exportFiles is not available\n") -''' - -# lists the parts and linked parts of the selected container -class listLinkedFiles(): - - def GetResources(self): - menutext = "Structure tree of the assembly" - tooltip = "Show the hierarchical tree structure of parts and sub-assemblies in the assembly. " - tooltip += "The tree is displayed with ASCII art
" - tooltip += "Usage: select an entity and click the command
" - iconFile = os.path.join(Asm4.iconPath, 'Asm4_List_Liked_Files_Tree.svg') - return { - "MenuText": menutext, - "ToolTip" : tooltip, - "Pixmap" : iconFile - } - - - def IsActive(self): - if App.ActiveDocument and len(Gui.Selection.getSelection())==1: - return True - elif App.ActiveDocument and Asm4.getAssembly(): - return True - else: - return False +""" +# lists the parts and linked parts of the selected container +class listLinkedFiles(BaseCommand): def __init__(self): super(listLinkedFiles, self).__init__() # types of objects to be included in the listing # links and derivatives are also included - self.DEF_TYPES = ['App::Part', 'PartDesign::Body', 'Part::FeaturePython', 'App::DocumentObjectGroup'] + self.DEF_TYPES = [ + "App::Part", + "PartDesign::Body", + "Part::FeaturePython", + "App::DocumentObjectGroup", + ] # visual ASCII art - self.TAB = ' ' - self.BRANCH = ' │ ' - self.FORK = ' ├─ ' - self.LAST = ' └─ ' + self.TAB = " " + self.BRANCH = " │ " + self.FORK = " ├─ " + self.LAST = " └─ " # where we write stuff self.ascii_tree = "" - self.root_path = "" + self.root_path = "" # the UI self.UI = QtGui.QDialog() self.drawUI() + self.menutext = "Tree of Linked Files" + self.tooltip = translate( + "Commands5", + "Show the hierarchical tree structure of parts in the selected container.\n" + "The tree is displayed with ASCII art
\n" + "Usage: select an entity and click the command
", + ) + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_List_Liked_Files_Tree.svg") + def IsActive(self): + if App.ActiveDocument and len(Gui.Selection.getSelection()) == 1: + return True + elif App.ActiveDocument and Asm4.getAssembly(): + return True + else: + return False def Activated(self): # clear stuff self.ascii_tree = "" - self.root_path = "" + self.root_path = "" self.tree_view.clear() # - if len(Gui.Selection.getSelection())==1: + if len(Gui.Selection.getSelection()) == 1: objects = Gui.Selection.getSelection() elif Asm4.getAssembly(): - objects = [ Asm4.getAssembly() ] + objects = [Asm4.getAssembly()] else: - FCC.PrintWarning("Oups, you shouldn't see this message, something went wrong") + FCC.PrintWarning( + "Oups, you shouldn't see this message, something went wrong" + ) # get the directory path of the selected object filename = objects[0].Document.Name self.root_path = objects[0].Document.FileName.partition(filename)[0] @@ -103,14 +105,13 @@ def Activated(self): self.UI.show() self.tree_view.setPlainText(self.ascii_tree) - # this is where the magic happens. Copied from TreeToAscii macro # Build ASCII tree by recursive call - def printChildren(self, objs=None, level=0, baseline=''): - for cnt, obj in enumerate(objs,1): + def printChildren(self, objs=None, level=0, baseline=""): + for cnt, obj in enumerate(objs, 1): # find the filepath - filepath = '' - if obj.isDerivedFrom('App::Link'): + filepath = "" + if obj.isDerivedFrom("App::Link"): target = obj.LinkedObject else: target = obj @@ -118,84 +119,84 @@ def printChildren(self, objs=None, level=0, baseline=''): if self.root_path: filepath = target.Document.FileName.partition(self.root_path)[2] # ... else absolute - if filepath =='': + if filepath == "": filepath = target.Document.FileName # make the data data = { - "LBL" : obj.Label, - "NAME" : '('+obj.Name+')' if obj.Label!=obj.Name else '', - "DOC" : filepath, - "TARG" : obj.LinkedObject.Name if obj.isDerivedFrom('App::Link') else '' + "LBL": obj.Label, + "NAME": "(" + obj.Name + ")" if obj.Label != obj.Name else "", + "DOC": filepath, + "TARG": obj.LinkedObject.Name if obj.isDerivedFrom("App::Link") else "", } # print the line if cnt == len(objs): - if level>0: + if level > 0: self.ascii_tree += baseline + self.LAST else: self.ascii_tree += baseline + self.FORK # new data print - if obj.isDerivedFrom('App::Link'): - pattern = '{LBL} => {TARG} @ {DOC}' + if obj.isDerivedFrom("App::Link"): + pattern = "{LBL} => {TARG} @ {DOC}" else: - pattern = '{LBL} {NAME}' + pattern = "{LBL} {NAME}" self.ascii_tree += pattern.format(**data) # we add the filename for the first element - if level==0 and target.Document.FileName != '' : - self.ascii_tree += ' @ '+target.Document.FileName - self.ascii_tree += '\n' + if level == 0 and target.Document.FileName != "": + self.ascii_tree += " @ " + target.Document.FileName + self.ascii_tree += "\n" # for the next line if cnt == len(objs): - if level>0: + if level > 0: baselinenext = baseline + self.TAB else: - baselinenext = '' + baselinenext = "" else: baselinenext = baseline + self.BRANCH # table of children to be listed next children = [] for child in obj.ViewObject.claimChildren(): - if child.TypeId in self.DEF_TYPES or child.isDerivedFrom('App::Link'): + if child.TypeId in self.DEF_TYPES or child.isDerivedFrom("App::Link"): children.append(child) self.printChildren(children, level + 1, baselinenext) - def copyToClip(self): """Copies ASCII tree to clipboard""" self.tree_view.selectAll() self.tree_view.copy() self.tree_view.setPlainText("Copied to clipboard") - QtCore.QTimer.singleShot(3000, lambda:self.tree_view.setPlainText(self.ascii_tree)) - + QtCore.QTimer.singleShot( + 3000, lambda: self.tree_view.setPlainText(self.ascii_tree) + ) # defines the UI, only static elements def drawUI(self): # Our main window will be a QDialog # make this dialog stay above the others, always visible - self.UI.setWindowFlags( QtCore.Qt.WindowStaysOnTopHint ) - self.UI.setWindowTitle('Tree structure of the selected object') - self.UI.setWindowIcon( QtGui.QIcon( os.path.join( Asm4.iconPath , 'FreeCad.svg' ) ) ) + self.UI.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) + self.UI.setWindowTitle("Tree structure of the selected object") + self.UI.setWindowIcon(QtGui.QIcon(os.path.join(Asm4.iconPath, "FreeCad.svg"))) self.UI.setMinimumWidth(470) - self.UI.resize(470,300) + self.UI.resize(470, 300) self.UI.setModal(False) # the layout for the main window is vertical (top to down) mainLayout = QtGui.QVBoxLayout(self.UI) # from TreeToAscii macro self.tree_view = QtGui.QPlainTextEdit(self.ascii_tree) self.tree_view.setReadOnly(True) - self.tree_view.setMinimumWidth(Gui.getMainWindow().width()/2) - self.tree_view.setMinimumHeight(Gui.getMainWindow().height()/2) + self.tree_view.setMinimumWidth(Gui.getMainWindow().width() / 2) + self.tree_view.setMinimumHeight(Gui.getMainWindow().height() / 2) self.tree_view.setLineWrapMode(QtGui.QPlainTextEdit.NoWrap) - f = QtGui.QFont("unexistent"); - f.setStyleHint(QtGui.QFont.Monospace); - self.tree_view.setFont(f); + f = QtGui.QFont("unexistent") + f.setStyleHint(QtGui.QFont.Monospace) + self.tree_view.setFont(f) button_box = QtGui.QDialogButtonBox() copy_clip_but = QtGui.QPushButton("Copy to clipboard", button_box) button_box.addButton(copy_clip_but, QtGui.QDialogButtonBox.ActionRole) - #button_box.addStretch() + # button_box.addStretch() close_dlg_but = QtGui.QPushButton("Close", button_box) button_box.addButton(close_dlg_but, QtGui.QDialogButtonBox.RejectRole) - #button_box.addButton(QtGui.QDialogButtonBox.Close) - #button_box.button(QtGui.QDialogButtonBox.Close).setDefault(True) + # button_box.addButton(QtGui.QDialogButtonBox.Close) + # button_box.button(QtGui.QDialogButtonBox.Close).setDefault(True) mainLayout.addWidget(self.tree_view) mainLayout.addWidget(button_box) # actions @@ -311,5 +312,4 @@ def export_zip_package(self): ''' # Add the command in the workbench -Gui.addCommand('Asm4_listLinkedFiles', listLinkedFiles()) - +Gui.addCommand("Asm4_listLinkedFiles", listLinkedFiles()) diff --git a/gotoDocumentCmd.py b/gotoDocumentCmd.py index 742ac5e1..43b64cc6 100644 --- a/gotoDocumentCmd.py +++ b/gotoDocumentCmd.py @@ -8,11 +8,12 @@ -import os +import math, re, os from PySide import QtGui, QtCore import FreeCADGui as Gui import FreeCAD as App +import Part import Asm4_libs as Asm4 from Asm4_Translate import translate diff --git a/importDatumCmd.py b/importDatumCmd.py index 22e54bc6..cba3a7ba 100644 --- a/importDatumCmd.py +++ b/importDatumCmd.py @@ -16,7 +16,8 @@ import Asm4_libs as Asm4 - +from BaseCommand import BaseCommand +from Asm4_Translate import translate """ @@ -24,19 +25,20 @@ | The command | +-----------------------------------------------+ """ -class importDatumCmd(): + + +class importDatumCmd(BaseCommand): def __init__(self): - super(importDatumCmd,self).__init__() - - def GetResources(self): - tooltip = "Imports the selected Datum object(s) from a sub-part into the root assembly.\n" - tooltip += "This creates a new datum of the same type, and with the same global placement\n\n" - tooltip += "This command can also be used to override the placement of an existing datum :\n" - tooltip += "select a second datum in the same root container as the first selected datum" - iconFile = os.path.join( Asm4.iconPath , 'Import_Datum.svg') - return {"MenuText": "Import Datum object", - "ToolTip" : tooltip, - "Pixmap" : iconFile } + super(importDatumCmd, self).__init__() + self.pixmap = os.path.join(Asm4.iconPath, "Import_Datum.svg") + self.menutext = "Import Datum object" + self.tooltip = translate( + "Commands2", + "Imports the selected Datum object(s) from a sub-part into the root assembly.\n" + "This creates a new datum of the same type, and with the same global placement\n\n" + "This command can also be used to override the placement of an existing datum :\n" + "select a second datum in the same root container as the first selected datum", + ) def IsActive(self): if App.ActiveDocument and self.getSelectedDatums(): diff --git a/infoPartCmd.py b/infoPartCmd.py index e9aa05d1..e28c5e40 100644 --- a/infoPartCmd.py +++ b/infoPartCmd.py @@ -16,6 +16,9 @@ import Asm4_libs as Asm4 import infoKeys +from BaseCommand import BaseCommand +from Asm4_Translate import translate + #This is partcoded part information. partInfo = [ 'BomKey', @@ -231,16 +234,14 @@ def AssignValuesForAutofile(part, doc, singleBodyOfPart): | Info Part Command | +-----------------------------------------------+ """ -class infoPartCmd(): +class infoPartCmd(BaseCommand): def __init__(self): super(infoPartCmd, self).__init__() - - def GetResources(self): - tooltip = "Edit Part information
" - tooltip += "User-supplied information can be added to a part
" - iconFile = os.path.join(Asm4.iconPath, 'Asm4_PartInfo.svg') - return {"MenuText": "Edit Part Information", "ToolTip": tooltip, "Pixmap": iconFile} + self.pixmap = os.path.join(Asm4.iconPath, 'Asm4_PartInfo.svg') + self.menutext = "Edit Part Information" + self.tooltip = translate("Commands", + "User-supplied information can be added to a part") def IsActive(self): if App.ActiveDocument and Asm4.getSelectedContainer(): diff --git a/insertLinkCmd.py b/insertLinkCmd.py index d7cb0d86..e667a942 100644 --- a/insertLinkCmd.py +++ b/insertLinkCmd.py @@ -17,6 +17,8 @@ import Asm4_libs as Asm4 +from BaseCommand import BaseCommand +from Asm4_Translate import translate """ @@ -24,7 +26,7 @@ | main class | +-----------------------------------------------+ """ -class insertLink(): +class insertLink(BaseCommand): "My tool object" def __init__(self): @@ -32,22 +34,16 @@ def __init__(self): # the GUI objects are defined later down # self.UI = QtGui.QDialog() # self.drawUI() - - - def GetResources(self): - tooltip = "Insert a Part into the assembly. " - tooltip += "This will create a dynamic link to the part, " - tooltip += "which can be in this document or in another document " - tooltip += "that is open in the current session
" - tooltip += "Usage: the part must be open in the current session
" - tooltip += "This command also enables to repair broken/missing links. " - tooltip += "Select the broken link, launch this command, and select a new target part in the list
" - iconFile = 'Link_Part.svg' - return {"MenuText" : "Insert Part", - "ToolTip" : tooltip, - "Pixmap" : os.path.join( Asm4.iconPath , iconFile ) - } - + self.pixmap = os.path.join(Asm4.iconPath, 'Link_Part.svg') + self.menutext = "Insert Part" + self.tooltip = translate("Commands", + "Insert a Part into the assembly.\n" + "This will create a dynamic link to the part,\n" + "which can be in this document or in another document\n" + "that is open in the current session
\n" + "Usage: the part must be open in the current session
\n" + "This command also enables to repair broken/missing links.\n" + "Select the broken link, launch this command, and select a new target part in the list
") def IsActive(self): # if an App::Link is selected, even a broken one diff --git a/makeArrayCmd.py b/makeArrayCmd.py index 1595137f..7fab44c6 100755 --- a/makeArrayCmd.py +++ b/makeArrayCmd.py @@ -17,6 +17,8 @@ ExpressionArray, findAxisPlacement, ) +from BaseCommand import BaseCommand +from Asm4_Translate import translate """ @@ -26,30 +28,24 @@ """ -class makeExpressionArray: - - iconFileName = 'Asm4_ExpressionArray.svg' - menuText = 'Create an expression driven Array' - arrayType = 'Expression Array' - namePrefix = 'XArray_' - tooltip = """Create an array of the selected object where the placement of each element is calculated using expressions and an Index property.Create a circular (polar) array around an axis. - Supported axis objects are axis or plane from an origin, datum line, LCS axes, straight line segments, arcs and circles
-Usage: Select an object and the axis (hold CTRL key to select second object)
""" - +class makeCircularArray(BaseCommand): + def __init__(self): + self.arrayType = "Circular Array" + self.namePrefix = "Circular_" + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_PolarArray.svg") + self.menutext = "Create a circular array" + self.tooltip = translate( + "Commands4", + "Create a circular (polar) array around an axis.\n" + "Supported axis objects are axis or plane from an origin, datum line, LCS axes, straight line segments, arcs and circles
\n" + "Usage: Select an object and an axis (hold CTRL key to select second object)
", + ) + def IsActive(self): self._cacheSelectionInfo() return self._selectionInfo[2] is not None @@ -156,15 +156,19 @@ def _setupProperties(self, obj): +-----------------------------------------------+ """ -class makeLinearArray(makeExpressionArray): - iconFileName = 'Asm4_LinearArray.svg' - menuText = 'Create a linear array' - arrayType = 'Linear Array' - namePrefix = 'Linear_' - tooltip = """Create a linear array along an axis. - Supported axis objects are axis or plane from an origin, datum line, LCS axes, straight line segments, arcs and circles
-Usage: Select an object and an axis for the direction (hold CTRL key to select second object)
""" +class makeLinearArray(BaseCommand): + def __init__(self): + self.arrayType = "Linear Array" + self.namePrefix = "Linear_" + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_LinearArray.svg") + self.menutext = "Create a linear array" + self.tooltip = translate( + "Commands4", + "Create a linear array along an axis.\n" + "Supported axis objects are axis or plane from an origin, datum line, LCS axes, straight line segments, arcs and circles
\n" + "Usage: Select an object and an axis for the direction (hold CTRL key to select second object)
", + ) def IsActive(self): self._cacheSelectionInfo() @@ -187,15 +191,21 @@ def _setupProperties(self, obj): | a mirror link array class and command | +-----------------------------------------------+ """ -class makeMirrorArray(makeExpressionArray): - - iconFileName = 'Asm4_Mirror.svg' - menuText = 'Create mirror' - arrayType = 'Mirror Array' - namePrefix = 'Mirror_' - tooltip = """Create a mirror of a part. - Supported axis objects are axis or plane from an origin, datum line, LCS axes, straight line segments, arcs and circles
-Usage: Select a source object and a mirror plane or a normal to a plane (hold CTRL key to select second object)
""" + + +class makeMirrorArray(BaseCommand): + def __init__(self) -> None: + super().__init__() + self.arrayType = "Mirror Array" + self.namePrefix = "Mirror_" + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Mirror.svg") + self.menutext = "Create mirror" + self.tooltip = translate( + "Commands4", + "Create a mirror of a part.\n" + "Supported axis objects are axis or plane from an origin, datum line, LCS axes, straight line segments, arcs and circles
\n" + "Usage: Select a source object and a mirror plane or a normal to a plane (hold CTRL key to select second object)
", + ) def IsActive(self): self._cacheSelectionInfo() diff --git a/makeBinderCmd.py b/makeBinderCmd.py index b320ebb7..3527e8a1 100755 --- a/makeBinderCmd.py +++ b/makeBinderCmd.py @@ -17,7 +17,8 @@ import Asm4_libs as Asm4 - +from BaseCommand import BaseCommand +from Asm4_Translate import translate """ @@ -25,17 +26,19 @@ | a circular link array class and command | +-----------------------------------------------+ """ -class makeShapeBinder(): + + +class makeShapeBinder(BaseCommand): def __init__(self): - pass - - def GetResources(self): - tooltip = "Create a reference to an external shape\n" - tooltip += "This creates a SubShapeBinder of the selected shapes\n" - tooltip += "(face, edge, point) in the root assembly\n" - tooltip += "Only shapes belonging to the same part can be imported in a single step" - iconFile = os.path.join( Asm4.iconPath, 'Asm4_shapeBinder.svg' ) - return {"MenuText": "Create a shape binder", "ToolTip": tooltip, "Pixmap": iconFile} + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_shapeBinder.svg") + self.menutext = "Create a shape binder" + self.tooltip = translate( + "Commands2", + "Create a reference to an external shape\n" + "This creates a SubShapeBinder of the selected shapes\n" + "(face, edge, point) in the root assembly\n" + "Only shapes belonging to the same part can be imported in a single step", + ) def IsActive(self): # only do this for assembly objects and all selected shapes must be in the same part diff --git a/makeBomCmd.py b/makeBomCmd.py index 95ba1306..d2ff1ebf 100644 --- a/makeBomCmd.py +++ b/makeBomCmd.py @@ -15,8 +15,10 @@ import Asm4_libs as Asm4 import infoPartCmd -#import infoKeys -#All infor from infoKeys is process by infoPartCmd shouldn't need to +from BaseCommand import BaseCommand +from Asm4_Translate import translate +# import infoKeys +# All infor from infoKeys is process by infoPartCmd shouldn't need to crea = infoPartCmd.infoPartUI.makePartInfo @@ -52,33 +54,31 @@ ''' -class makeBOM: +class makeBOM(BaseCommand): def __init__(self, follow_subassemblies=True): - #super().__init__() + # super().__init__() self.follow_subassemblies = follow_subassemblies - ''' + """ file = open(ConfUserFilejson, 'r') self.infoKeysUser = json.load(file).copy() file.close() - ''' - - def GetResources(self): - - if self.follow_subassemblies == True: - menutext = "Bill of Materials" - tooltip = "Create the Bill of Materials of the Assembly including sub-assemblies" - iconFile = os.path.join( Asm4.iconPath, 'Asm4_PartsList_Subassemblies.svg' ) + """ + if self.follow_subassemblies: + self.menutext = "Bill of Materials" + self.tooltip = translate( + "Commands5", + "Create the Bill of Materials of the Assembly including sub-assemblies", + ) + self.pixmap = os.path.join( + Asm4.iconPath, "Asm4_PartsList_Subassemblies.svg" + ) else: - menutext = "Local Bill of Materials" - tooltip = "Create the Bill of Materials of the Assembly" - iconFile = os.path.join( Asm4.iconPath, 'Asm4_PartsList.svg' ) - - return { - "MenuText": menutext, - "ToolTip": tooltip, - "Pixmap": iconFile - } + self.menutext = "Local Bill of Materials" + self.tooltip = translate( + "Commands5", "Create the Bill of Materials of the Assembly" + ) + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_PartsList.svg") def IsActive(self): if Asm4.getAssembly() is None: diff --git a/newAssemblyCmd.py b/newAssemblyCmd.py index 27dd65bb..183c101e 100644 --- a/newAssemblyCmd.py +++ b/newAssemblyCmd.py @@ -19,6 +19,8 @@ +from Asm4_Translate import translate + class newAssemblyCmd: """ +-----------------------------------------------+ @@ -39,7 +41,7 @@ def makeAssembly(): def GetResources(self): tooltip = translate("Commands", "Create a new Assembly container
") iconFile = os.path.join( Asm4.iconPath , 'Asm4_Model.svg') - return {"MenuText": "New Assembly", "ToolTip": tooltip, "Pixmap" : iconFile } + return {"MenuText": translate("Commands", "New Assembly"), "ToolTip": tooltip, "Pixmap" : iconFile } def IsActive(self): diff --git a/newDatumCmd.py b/newDatumCmd.py index d1f29302..cdc4e68c 100644 --- a/newDatumCmd.py +++ b/newDatumCmd.py @@ -15,8 +15,8 @@ from FreeCAD import Console as FCC import Asm4_libs as Asm4 - - +from BaseCommand import BaseCommand +from Asm4_Translate import translate """ @@ -24,54 +24,52 @@ | a class to create all Datum objects | +-----------------------------------------------+ """ -class newDatum: + + +class newDatum(BaseCommand): "My tool object" + def __init__(self, datumName): self.datumName = datumName # recognised containers (not the same as Asm4.containerTypes !) - self.containers = [ 'App::Part', 'PartDesign::Body', 'App::DocumentObjectGroup'] - if self.datumName == 'Point': - self.datumType = 'PartDesign::Point' - self.menutext = "New Point" - self.tooltip = "Create a new Datum Point in a Part" - self.icon = os.path.join( Asm4.iconPath , 'Asm4_Point.svg') - self.datumColor = (0.00,0.00,0.00) - self.datumAlpha = [] - elif self.datumName == 'Axis': - self.datumType = 'PartDesign::Line' - self.menutext = "New Axis" - self.tooltip = "Create a new Datum Axis in a Part" - self.icon = os.path.join( Asm4.iconPath , 'Asm4_Axis.svg') - self.datumColor = (0.00,0.00,0.50) - self.datumAlpha = [] - elif self.datumName == 'Plane': - self.datumType = 'PartDesign::Plane' - self.menutext = "New Plane" - self.tooltip = "Create a new Datum Plane in a Part" - self.icon = os.path.join( Asm4.iconPath , 'Asm4_Plane.svg') - self.datumColor = (0.50,0.50,0.50) - self.datumAlpha = 80 - elif self.datumName == 'LCS': - self.datumType = 'PartDesign::CoordinateSystem' - self.menutext = "New Coordinate System" - self.tooltip = "Create a new Coordinate System in a Part" - self.icon = os.path.join( Asm4.iconPath , 'Asm4_CoordinateSystem.svg') - self.datumColor = [] - self.datumAlpha = [] - elif self.datumName == 'Sketch': - self.datumType = 'Sketcher::SketchObject' - self.menutext = "New Sketch" - self.tooltip = "Create a new Sketch in a Part" - self.icon = os.path.join( Asm4.iconPath , 'Asm4_Sketch.svg') - self.datumColor = [] - self.datumAlpha = [] - - - def GetResources(self): - return {"MenuText": self.menutext, - "ToolTip": self.tooltip, - "Pixmap" : self.icon } - + self.containers = ["App::Part", "PartDesign::Body", "App::DocumentObjectGroup"] + if self.datumName == "Point": + self.datumType = "PartDesign::Point" + self.menutext = "New Point" + self.tooltip = translate("Commands2", "Create a new Datum Point in a Part") + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Point.svg") + self.datumColor = (0.00, 0.00, 0.00) + self.datumAlpha = [] + elif self.datumName == "Axis": + self.datumType = "PartDesign::Line" + self.menutext = "New Axis" + self.tooltip = translate("Commands2", "Create a new Datum Axis in a Part") + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Axis.svg") + self.datumColor = (0.00, 0.00, 0.50) + self.datumAlpha = [] + elif self.datumName == "Plane": + self.datumType = "PartDesign::Plane" + self.menutext = "New Plane" + self.tooltip = translate("Commands2", "Create a new Datum Plane in a Part") + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Plane.svg") + self.datumColor = (0.50, 0.50, 0.50) + self.datumAlpha = 80 + elif self.datumName == "LCS": + self.datumType = "PartDesign::CoordinateSystem" + self.menutext = "New Coordinate System" + self.tooltip = translate( + "Commands2", "Create a new Coordinate System in a Part" + ) + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_CoordinateSystem.svg") + self.datumColor = [] + self.datumAlpha = [] + elif self.datumName == "Sketch": + self.datumType = "Sketcher::SketchObject" + self.menutext = "New Sketch" + self.tooltip = translate("Commands2", "Create a new Sketch in a Part") + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Sketch.svg") + self.datumColor = [] + self.datumAlpha = [] def IsActive(self): if App.ActiveDocument: diff --git a/newPartCmd.py b/newPartCmd.py index 59cee0c3..5726eeb4 100644 --- a/newPartCmd.py +++ b/newPartCmd.py @@ -9,7 +9,7 @@ -import os +import math, re, os from PySide import QtGui, QtCore import FreeCADGui as Gui @@ -32,17 +32,17 @@ def __init__(self, partName): self.partName = partName if self.partName == "Part": self.partType = "App::Part" - self.menutext = "New Part" + self.menutext = translate("Commands1", "New Part") self.tooltip = translate("Commands1", "Create a new Part") self.icon = os.path.join(Asm4.iconPath, "Asm4_Part.svg") elif self.partName == "Body": self.partType = "PartDesign::Body" - self.menutext = "New Body" + self.menutext = translate("Commands1", "New Body") self.tooltip = translate("Commands1", "Create a new Body") self.icon = os.path.join(Asm4.iconPath, "Asm4_Body.svg") elif self.partName == "Group": self.partType = "App::DocumentObjectGroup" - self.menutext = "New Group" + self.menutext = translate("Commands1", "New Group") self.tooltip = translate("Commands1", "Create a new Group") self.icon = os.path.join(Asm4.iconPath, "Asm4_Group.svg") diff --git a/placeLinkCmd.py b/placeLinkCmd.py index 99b734f7..e80639a7 100644 --- a/placeLinkCmd.py +++ b/placeLinkCmd.py @@ -18,9 +18,8 @@ from placeLinkUI import placeLinkUI from placePartUI import placePartUI import selectionFilter - - - +from BaseCommand import BaseCommand +from Asm4_Translate import translate """ @@ -28,15 +27,14 @@ | The command | +-----------------------------------------------+ """ -class placeLinkCmd(): - def __init__(self): - super(placeLinkCmd,self).__init__() - def GetResources(self): - return {"MenuText": "Edit Placement of a Part", - "ToolTip": "Move/Attach a Part in the assembly", - "Pixmap" : os.path.join( Asm4.iconPath , 'Place_Link.svg') - } + +class placeLinkCmd(BaseCommand): + def __init__(self): + super(placeLinkCmd, self).__init__() + self.menutext = "Edit Placement of a Part" + self.tooltip = translate("Commands3", "Move/Attach a Part in the assembly") + self.pixmap = os.path.join(Asm4.iconPath, "Place_Link.svg") def IsActive(self): # We only insert a link into an Asm4 Model diff --git a/releaseAttachmentCmd.py b/releaseAttachmentCmd.py index 44190d11..f337e714 100644 --- a/releaseAttachmentCmd.py +++ b/releaseAttachmentCmd.py @@ -15,7 +15,8 @@ import Part import Asm4_libs as Asm4 - +from BaseCommand import BaseCommand +from Asm4_Translate import translate """ @@ -23,19 +24,17 @@ | main class | +-----------------------------------------------+ """ -class releaseAttachment: + +class releaseAttachment(BaseCommand): def __init__(self): - super(releaseAttachment,self).__init__() + super(releaseAttachment, self).__init__() self.selectedObj = [] - - - def GetResources(self): - return {"MenuText": "Release from Attachment", - "ToolTip": "Release an object from all attachments to any geometry", - "Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_releaseAttachment.svg') - } - + self.menutext = "Release from Attachment" + self.tooltip = translate( + "Commands3", "Release an object from all attachments to any geometry" + ) + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_releaseAttachment.svg") def IsActive(self): # is there an active document ? diff --git a/selectionFilter.py b/selectionFilter.py index cfd5c02f..cf0b94dd 100644 --- a/selectionFilter.py +++ b/selectionFilter.py @@ -12,6 +12,8 @@ from FreeCAD import Console as FCC import Asm4_libs as Asm4 +from BaseCommand import BaseCommand +from Asm4_Translate import translate global Asm4_3DselObserver @@ -33,14 +35,17 @@ button.objectName() button.setCheckable(True) """ -class selectionFilterClearCmd: - def GetResources(self): - return {"MenuText": "Clear all selection filters", - "ToolTip": "Clear all selection filters", - "Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_SelectionAll.svg') - } + + +class selectionFilterClearCmd(BaseCommand): + def __init__(self): + self.menutext = "Clear all selection filters" + self.tooltip = translate("Commands6", "Clear all selection filters") + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_SelectionAll.svg") + def IsActive(self): return True + def Activated(self): # This function is executed when the command is activated Gui.Selection.removeSelectionGate() @@ -49,14 +54,15 @@ def Activated(self): FCC.PrintMessage("All selection filters cleared\n") -class selectionFilterVertexCmd: - def GetResources(self): - return {"MenuText": "Select only Vertices", - "ToolTip": "Select only Vertices", - "Pixmap" : os.path.join( Asm4.iconPath , 'Snap_Vertex.svg') - } +class selectionFilterVertexCmd(BaseCommand): + def __init__(self): + self.menutext = "Select only Vertices" + self.tooltip = translate("Commands6", "Select only Vertices") + self.pixmap = os.path.join(Asm4.iconPath, "Snap_Vertex.svg") + def IsActive(self): return True + def Activated(self): # This function is executed when the command is activated button = 0 @@ -66,14 +72,15 @@ def Activated(self): Gui.Selection.removeSelectionGate() -class selectionFilterEdgeCmd: - def GetResources(self): - return {"MenuText": "Select only Edges", - "ToolTip": "Select only Edges", - "Pixmap" : os.path.join( Asm4.iconPath , 'Snap_Edge.svg') - } +class selectionFilterEdgeCmd(BaseCommand): + def __init__(self): + self.menutext = "Select only Edges" + self.tooltip = translate("Commands6", "Select only Edges") + self.pixmap = os.path.join(Asm4.iconPath, "Snap_Edge.svg") + def IsActive(self): return True + def Activated(self): # This function is executed when the command is activated button = 1 @@ -83,14 +90,15 @@ def Activated(self): Gui.Selection.removeSelectionGate() -class selectionFilterFaceCmd: - def GetResources(self): - return {"MenuText": "Select only Faces", - "ToolTip": "Select only Faces", - "Pixmap" : os.path.join( Asm4.iconPath , 'Snap_Face.svg') - } +class selectionFilterFaceCmd(BaseCommand): + def __init__(self): + self.menutext = "Select only Faces" + self.tooltip = translate("Commands6", "Select only Faces") + self.pixmap = os.path.join(Asm4.iconPath, "Snap_Face.svg") + def IsActive(self): return True + def Activated(self): # This function is executed when the command is activated button = 2 @@ -163,19 +171,25 @@ def applyFilter(button): | treeSelectionOverride | +-----------------------------------------------+ """ -class selObserver3DViewCmd( QtGui.QDialog): + + +class selObserver3DViewCmd(QtGui.QDialog): def __init__(self): - super(selObserver3DViewCmd,self).__init__() + super(selObserver3DViewCmd, self).__init__() global Asm4_3DselObserver Asm4_3DselObserver = None def GetResources(self): - return {"MenuText": "Enable/Disable 3D View selection mode", - "ToolTip": "Enable/Disable 3D View selection mode\n\n" + \ - "Allows to select a Link object in the 3D view\n" + \ + return { + "MenuText": "Enable/Disable 3D View selection mode", + "ToolTip": translate( + "Commands6", + "Enable/Disable 3D View selection mode\n\n" + "Allows to select a Link object in the 3D view\n" "window instead of the Model tree", - "Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_enableLinkSelection.svg') - } + ), + "Pixmap": os.path.join(Asm4.iconPath, "Asm4_enableLinkSelection.svg"), + } def IsActive(self): return True diff --git a/showHideLcsCmd.py b/showHideLcsCmd.py index 7356f710..31485515 100644 --- a/showHideLcsCmd.py +++ b/showHideLcsCmd.py @@ -9,6 +9,7 @@ import FreeCAD as App import Asm4_libs as Asm4 +from BaseCommand import BaseCommand from Asm4_Translate import translate @@ -19,16 +20,16 @@ | Show | +-----------------------------------------------+ """ -class showLcsCmd: - def __init__(self): - super(showLcsCmd,self).__init__() - def GetResources(self): - return {"MenuText": translate("Asm4_showLcs", "Show LCS"), - "ToolTip": translate("Asm4_showLcs", "Show LCS and Datums of selected part and its children"), - "Pixmap": os.path.join(Asm4.iconPath, 'Asm4_showLCS.svg') - } +class showLcsCmd(BaseCommand): + def __init__(self): + super(showLcsCmd, self).__init__() + self.menutext = "Show LCS" + self.tooltip = translate( + "Commands5", "Show LCS and Datums of selected part and its children" + ) + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_showLCS.svg") def IsActive(self): # if something is selected or an Asm4 assembly present @@ -47,15 +48,16 @@ def Activated(self): | Hide | +-----------------------------------------------+ """ -class hideLcsCmd: - def __init__(self): - super(hideLcsCmd,self).__init__() - def GetResources(self): - return {"MenuText": translate("Asm4_hideLcs", "Hide LCS"), - "ToolTip": translate("Asm4_hideLcs", "Hide LCS and Datums of selected part and its children"), - "Pixmap": os.path.join(Asm4.iconPath, 'Asm4_hideLCS.svg') - } + +class hideLcsCmd(BaseCommand): + def __init__(self): + super(hideLcsCmd, self).__init__() + self.menutext = "Hide LCS" + self.tooltip = translate( + "Commands5", "Hide LCS and Datums of selected part and its children" + ) + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_hideLCS.svg") def IsActive(self): # if something is selected or an Asm4 assembly present diff --git a/treeSelectionOverride.py b/treeSelectionOverride.py index 3efe0b57..7d71ec53 100644 --- a/treeSelectionOverride.py +++ b/treeSelectionOverride.py @@ -12,7 +12,7 @@ from FreeCAD import Console as FCC import Asm4_libs as Asm4 - +from Asm4_Translate import translate observer = None @@ -22,17 +22,23 @@ | main class | +-----------------------------------------------+ """ -class treeSelectionOverrideCmd( QtGui.QDialog): + + +class treeSelectionOverrideCmd(QtGui.QDialog): def __init__(self): - super(treeSelectionOverrideCmd,self).__init__() + super(treeSelectionOverrideCmd, self).__init__() def GetResources(self): - return {"MenuText": "Enable/Disable 3D View selection mode", - "ToolTip": "Enable/Disable 3D View selection mode\n\n" + \ - "Allows to select a Link object in the 3D view\n" + \ + return { + "MenuText": "Enable/Disable 3D View selection mode", + "ToolTip": translate( + "Commands6", + "Enable/Disable 3D View selection mode\n\n" + "Allows to select a Link object in the 3D view\n" "window instead of the Model tree", - "Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_enableLinkSelection.svg') - } + ), + "Pixmap": os.path.join(Asm4.iconPath, "Asm4_enableLinkSelection.svg"), + } def IsActive(self): return True diff --git a/updateAssemblyCmd.py b/updateAssemblyCmd.py index 8de38b4a..342ebee4 100644 --- a/updateAssemblyCmd.py +++ b/updateAssemblyCmd.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # coding: utf-8 -# -# updateAssembly.py +# +# updateAssembly.py import math, re, os @@ -12,17 +12,15 @@ import Part import Asm4_libs as Asm4 +from BaseCommand import BaseCommand +from Asm4_Translate import translate - -class updateAssembly: - - def GetResources(self): - return {"MenuText": "Solve and Update Assembly", - "ToolTip": "Update Assembly", - "Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_Solver.svg') - } - +class updateAssembly(BaseCommand): + def __init__(self): + self.menutext = "Solve and Update Assembly" + self.tooltip = translate("Commands3", "Update Assembly") + self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Solver.svg") def IsActive(self): if App.ActiveDocument: diff --git a/variantLinkCmd.py b/variantLinkCmd.py index c153ea73..96b75d05 100755 --- a/variantLinkCmd.py +++ b/variantLinkCmd.py @@ -18,6 +18,9 @@ from Asm4_objects import VariantLink, ViewProviderVariant +from BaseCommand import BaseCommand +from Asm4_Translate import translate + """ @@ -28,20 +31,15 @@ var = App.ActiveDocument.addObject("Part::FeaturePython", 'varLink', VariantLink(),None,True) """ -class makeVariantLink(): +class makeVariantLink(BaseCommand): def __init__(self): super(makeVariantLink,self).__init__() - #pass - - def GetResources(self): - tooltip = "EXPERIMENTAL !!!\n" - tooltip += "Create a variant link to a part\n" - tooltip += "Select a part containing a \"Variables\" property container" - iconFile = 'Variant_Link.svg' - return {"MenuText" : "Create a variant Part", - "ToolTip" : tooltip, - "Pixmap" : os.path.join( Asm4.iconPath, iconFile ) - } + self.pixmap = os.path.join(Asm4.iconPath, 'Variant_Link.svg') + self.menutext = "Create a variant Part" + self.tooltip = translate("Commands", + "EXPERIMENTAL !!!\n" + "Create a variant link to a part\n" + "Select a part containing a \"Variables\" property container") def IsActive(self): # we only insert variant links into assemblies and root parts