diff --git a/src/Mod/Assembly/App/AssemblyObject.cpp b/src/Mod/Assembly/App/AssemblyObject.cpp index 9a86dd6761..b8fc5623f2 100644 --- a/src/Mod/Assembly/App/AssemblyObject.cpp +++ b/src/Mod/Assembly/App/AssemblyObject.cpp @@ -691,7 +691,7 @@ bool AssemblyObject::isJointTypeConnecting(App::DocumentObject* joint) { JointType jointType = getJointType(joint); return jointType != JointType::RackPinion && jointType != JointType::Screw - && jointType != JointType::Gears && jointType != JointType::Pulleys; + && jointType != JointType::Gears && jointType != JointType::Belt; } void AssemblyObject::removeUnconnectedJoints(std::vector& joints, @@ -855,6 +855,12 @@ std::shared_ptr AssemblyObject::makeMbdJointOfType(App::DocumentObjec mbdJoint->radiusJ = getJointDistance2(joint); return mbdJoint; } + else if (type == JointType::Belt) { + auto mbdJoint = CREATE::With(); + mbdJoint->radiusI = getJointDistance(joint); + mbdJoint->radiusJ = -getJointDistance2(joint); + return mbdJoint; + } return nullptr; } diff --git a/src/Mod/Assembly/App/AssemblyObject.h b/src/Mod/Assembly/App/AssemblyObject.h index 2d7f461fb8..f2eafafb72 100644 --- a/src/Mod/Assembly/App/AssemblyObject.h +++ b/src/Mod/Assembly/App/AssemblyObject.h @@ -69,7 +69,7 @@ enum class JointType RackPinion, Screw, Gears, - Pulleys, + Belt, }; enum class DistanceType diff --git a/src/Mod/Assembly/CommandCreateJoint.py b/src/Mod/Assembly/CommandCreateJoint.py index 0d23610836..06bb359e21 100644 --- a/src/Mod/Assembly/CommandCreateJoint.py +++ b/src/Mod/Assembly/CommandCreateJoint.py @@ -249,7 +249,7 @@ class CommandCreateJointRackPinion: "MenuText": QT_TRANSLATE_NOOP( "Assembly_CreateJointRackPinion", "Create Rack and Pinion Joint" ), - "Accel": "P", + "Accel": "Q", "ToolTip": "

" + QT_TRANSLATE_NOOP( "Assembly_CreateJointRackPinion", @@ -315,7 +315,7 @@ class CommandCreateJointGears: "ToolTip": "

" + QT_TRANSLATE_NOOP( "Assembly_CreateJointGears", - "Create a Gears Joint: Links two rotating gears together.", + "Create a Gears Joint: Links two rotating gears together. They will have inverse rotation direction.", ) + "

", "CmdType": "ForEdit", @@ -328,6 +328,55 @@ class CommandCreateJointGears: activateJoint(8) +class CommandCreateJointBelt: + def __init__(self): + pass + + def GetResources(self): + + return { + "Pixmap": "Assembly_CreateJointPulleys", + "MenuText": QT_TRANSLATE_NOOP("Assembly_CreateJointBelt", "Create Belt Joint"), + "Accel": "P", + "ToolTip": "

" + + QT_TRANSLATE_NOOP( + "Assembly_CreateJointBelt", + "Create a Belt Joint: Links two rotating objects together. They will have the same rotation direction.", + ) + + "

", + "CmdType": "ForEdit", + } + + def IsActive(self): + return isCreateJointActive() + + def Activated(self): + activateJoint(9) + + +class CommandGroupGearBelt: + def GetCommands(self): + return ("Assembly_CreateJointGears", "Assembly_CreateJointBelt") + + def GetResources(self): + """Set icon, menu and tooltip.""" + + return { + "Pixmap": "Assembly_CreateJointGears", + "MenuText": QT_TRANSLATE_NOOP("Assembly_CreateJointGears", "Create Gear/Belt Joint"), + "ToolTip": "

" + + QT_TRANSLATE_NOOP( + "Assembly_CreateJointGears", + "Create a Gears/Belt Joint: Links two rotating gears together.", + ) + + "

", + "CmdType": "ForEdit", + } + + def IsActive(self): + return isCreateJointActive() + + def createGroundedJoint(obj): assembly = UtilsAssembly.activeAssembly() if not assembly: @@ -422,3 +471,5 @@ if App.GuiUp: Gui.addCommand("Assembly_CreateJointRackPinion", CommandCreateJointRackPinion()) Gui.addCommand("Assembly_CreateJointScrew", CommandCreateJointScrew()) Gui.addCommand("Assembly_CreateJointGears", CommandCreateJointGears()) + Gui.addCommand("Assembly_CreateJointBelt", CommandCreateJointBelt()) + Gui.addCommand("Assembly_CreateJointGearBelt", CommandGroupGearBelt()) diff --git a/src/Mod/Assembly/Gui/Resources/Assembly.qrc b/src/Mod/Assembly/Gui/Resources/Assembly.qrc index 64478811e7..91529fa602 100644 --- a/src/Mod/Assembly/Gui/Resources/Assembly.qrc +++ b/src/Mod/Assembly/Gui/Resources/Assembly.qrc @@ -11,7 +11,7 @@ icons/Assembly_CreateJointSlider.svg icons/Assembly_CreateJointTangent.svg icons/Assembly_CreateJointGears.svg - icons/Assembly_CreateJointPulley.svg + icons/Assembly_CreateJointPulleys.svg icons/Assembly_CreateJointRackPinion.svg icons/Assembly_CreateJointScrew.svg icons/Assembly_ExportASMT.svg diff --git a/src/Mod/Assembly/Gui/Resources/icons/Assembly_CreateJointPulley.svg b/src/Mod/Assembly/Gui/Resources/icons/Assembly_CreateJointPulleys.svg similarity index 100% rename from src/Mod/Assembly/Gui/Resources/icons/Assembly_CreateJointPulley.svg rename to src/Mod/Assembly/Gui/Resources/icons/Assembly_CreateJointPulleys.svg diff --git a/src/Mod/Assembly/Gui/Resources/panels/TaskAssemblyCreateJoint.ui b/src/Mod/Assembly/Gui/Resources/panels/TaskAssemblyCreateJoint.ui index a9acc7b808..58b40dcba6 100644 --- a/src/Mod/Assembly/Gui/Resources/panels/TaskAssemblyCreateJoint.ui +++ b/src/Mod/Assembly/Gui/Resources/panels/TaskAssemblyCreateJoint.ui @@ -226,6 +226,16 @@ + + + + Reverse rotation + + + true + + + diff --git a/src/Mod/Assembly/InitGui.py b/src/Mod/Assembly/InitGui.py index aa76bcc18d..003d9ef3d8 100644 --- a/src/Mod/Assembly/InitGui.py +++ b/src/Mod/Assembly/InitGui.py @@ -97,7 +97,7 @@ class AssemblyWorkbench(Workbench): "Separator", "Assembly_CreateJointRackPinion", "Assembly_CreateJointScrew", - "Assembly_CreateJointGears", + "Assembly_CreateJointGearBelt", ] self.appendToolbar(QT_TRANSLATE_NOOP("Workbench", "Assembly"), cmdList) diff --git a/src/Mod/Assembly/JointObject.py b/src/Mod/Assembly/JointObject.py index 8752a72f92..f8ffdad21c 100644 --- a/src/Mod/Assembly/JointObject.py +++ b/src/Mod/Assembly/JointObject.py @@ -54,7 +54,7 @@ TranslatedJointTypes = [ translate("Assembly", "RackPinion"), translate("Assembly", "Screw"), translate("Assembly", "Gears"), - # translate("Assembly", "Pulleys"), + translate("Assembly", "Belt"), ] JointTypes = [ @@ -67,7 +67,7 @@ JointTypes = [ "RackPinion", "Screw", "Gears", - # "Pulleys", + "Belt", ] JointUsingDistance = [ @@ -75,10 +75,19 @@ JointUsingDistance = [ "RackPinion", "Screw", "Gears", + "Belt", ] JointUsingDistance2 = [ "Gears", + "Belt", +] + +JointNoNegativeDistance = [ + "RackPinion", + "Screw", + "Gears", + "Belt", ] JointUsingOffset = [ @@ -281,7 +290,7 @@ class Joint: "Joint", QT_TRANSLATE_NOOP( "App::Property", - "This is the distance of the joint. It is used only by the distance joint and by RackPinion (pitch radius), Screw and Gears(radius1)", + "This is the distance of the joint. It is used only by the distance joint and by RackPinion (pitch radius), Screw and Gears and Belt(radius1)", ), ) @@ -844,6 +853,8 @@ class ViewProviderJoint: return ":/icons/Assembly_CreateJointScrew.svg" elif self.app_obj.JointType == "Gears": return ":/icons/Assembly_CreateJointGears.svg" + elif self.app_obj.JointType == "Belt": + return ":/icons/Assembly_CreateJointPulleys.svg" return ":/icons/Assembly_CreateJoint.svg" @@ -1164,6 +1175,7 @@ class TaskAssemblyCreateJoint(QtCore.QObject): self.form.jointType.currentIndexChanged.connect(self.onJointTypeChanged) self.form.distanceSpinbox.valueChanged.connect(self.onDistanceChanged) + self.form.distanceSpinbox2.valueChanged.connect(self.onDistance2Changed) self.form.offsetSpinbox.valueChanged.connect(self.onOffsetChanged) self.form.rotationSpinbox.valueChanged.connect(self.onRotationChanged) self.form.PushButtonReverse.clicked.connect(self.onReverseClicked) @@ -1173,6 +1185,10 @@ class TaskAssemblyCreateJoint(QtCore.QObject): self.form.limitRotMinSpinbox.valueChanged.connect(self.onLimitRotMinChanged) self.form.limitRotMaxSpinbox.valueChanged.connect(self.onLimitRotMaxChanged) + jType = JointTypes[self.form.jointType.currentIndex()] + self.form.reverseRotCheckbox.setChecked(jType == "Gears") + self.form.reverseRotCheckbox.stateChanged.connect(self.reverseRotToggled) + if jointObj: Gui.Selection.clearSelection() self.creating = False @@ -1332,13 +1348,15 @@ class TaskAssemblyCreateJoint(QtCore.QObject): ViewProviderJoint(self.joint.ViewObject) def onJointTypeChanged(self, index): - self.joint.Proxy.setJointType(self.joint, JointTypes[self.form.jointType.currentIndex()]) self.adaptUi() def onDistanceChanged(self, quantity): self.joint.Distance = self.form.distanceSpinbox.property("rawValue") + def onDistance2Changed(self, quantity): + self.joint.Distance2 = self.form.distanceSpinbox2.property("rawValue") + def onOffsetChanged(self, quantity): self.joint.Offset = App.Vector(0, 0, self.form.offsetSpinbox.property("rawValue")) @@ -1360,6 +1378,12 @@ class TaskAssemblyCreateJoint(QtCore.QObject): def onReverseClicked(self): self.joint.Proxy.flipOnePart(self.joint) + def reverseRotToggled(self, val): + if val: + self.form.jointType.setCurrentIndex(8) + else: + self.form.jointType.setCurrentIndex(9) + def adaptUi(self): jType = JointTypes[self.form.jointType.currentIndex()] @@ -1368,7 +1392,7 @@ class TaskAssemblyCreateJoint(QtCore.QObject): self.form.distanceSpinbox.show() if jType == "Distance": self.form.distanceLabel.setText("Distance") - elif jType == "Gears": + elif jType == "Gears" or jType == "Belt": self.form.distanceLabel.setText("Radius 1") else: self.form.distanceLabel.setText("Pitch radius") @@ -1379,9 +1403,26 @@ class TaskAssemblyCreateJoint(QtCore.QObject): if jType in JointUsingDistance2: self.form.distanceLabel2.show() self.form.distanceSpinbox2.show() + self.form.reverseRotCheckbox.show() + else: self.form.distanceLabel2.hide() self.form.distanceSpinbox2.hide() + self.form.reverseRotCheckbox.hide() + + if jType in JointNoNegativeDistance: + # Setting minimum to 0.01 to prevent 0 and negative values + self.form.distanceSpinbox.setProperty("minimum", 1e-7) + if self.form.distanceSpinbox.property("rawValue") == 0.0: + self.form.distanceSpinbox.setProperty("rawValue", 1.0) + + if jType == "Gears" or jType == "Belt": + self.form.distanceSpinbox2.setProperty("minimum", 1e-7) + if self.form.distanceSpinbox2.property("rawValue") == 0.0: + self.form.distanceSpinbox2.setProperty("rawValue", 1.0) + else: + self.form.distanceSpinbox.setProperty("minimum", float("-inf")) + self.form.distanceSpinbox2.setProperty("minimum", float("-inf")) if jType in JointUsingOffset: self.form.offsetLabel.show()