From 06d6cc579f550fb1f385aa51150294e9de8301fd Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 3 Sep 2020 17:47:25 +0200 Subject: [PATCH] Part: [skip ci] add MapMode support to Tube feature, raise an error if inner > outer radius, set icon to command and tree view (use cylinder icons for the time being) --- src/Mod/Part/BasicShapes/Shapes.py | 63 +++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/src/Mod/Part/BasicShapes/Shapes.py b/src/Mod/Part/BasicShapes/Shapes.py index 986a9ea30d..43144fd890 100644 --- a/src/Mod/Part/BasicShapes/Shapes.py +++ b/src/Mod/Part/BasicShapes/Shapes.py @@ -28,7 +28,6 @@ __doc__ = "Basic shapes" import FreeCAD from FreeCAD import Qt -import FreeCADGui import Part import math import sys @@ -48,29 +47,57 @@ class TubeFeature: obj.addProperty("App::PropertyLength","OuterRadius","Tube","Outer radius").OuterRadius = 5.0 obj.addProperty("App::PropertyLength","InnerRadius","Tube","Inner radius").InnerRadius = 2.0 obj.addProperty("App::PropertyLength","Height","Tube", "Height of the tube").Height = 10.0 + obj.addExtension("Part::AttachExtensionPython", self) def execute(self, fp): + if fp.InnerRadius >= fp.OuterRadius: + raise ValueError("Inner radius must be smaller than outer radius") fp.Shape = makeTube(fp.OuterRadius, fp.InnerRadius, fp.Height) -class _CommandMakeTube: - "Make tube command" - def GetResources(self): - return {'MenuText': Qt.QT_TRANSLATE_NOOP("Part_MakeTube","Create tube"), - 'Accel': "", - 'CmdType': "ForEdit", - 'ToolTip': Qt.QT_TRANSLATE_NOOP("Part_MakeTube","Creates a tube")} +# Only if GUI is running +if FreeCAD.GuiUp: + import FreeCADGui + + + class ViewProviderTube: + def __init__(self, obj): + ''' Set this object to the proxy object of the actual view provider ''' + obj.Proxy = self + + def attach(self, obj): + ''' Setup the scene sub-graph of the view provider, this method is mandatory ''' + return + + def getIcon(self): + return ":/icons/Tree_Part_Cylinder_Parametric.svg" + + def __getstate__(self): + return None + + def __setstate__(self,state): + return None + + + class _CommandMakeTube: + "Make tube command" + def GetResources(self): + return {'MenuText': Qt.QT_TRANSLATE_NOOP("Part_MakeTube","Create tube"), + 'Accel': "", + 'CmdType': "ForEdit", + 'Pixmap' : ":/icons/Part_Cylinder.svg", + 'ToolTip': Qt.QT_TRANSLATE_NOOP("Part_MakeTube","Creates a tube")} - def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create tube") - tube = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Tube") - TubeFeature(tube) - tube.ViewObject.Proxy = 0 - FreeCAD.ActiveDocument.commitTransaction() - FreeCAD.ActiveDocument.recompute() + def Activated(self): + FreeCAD.ActiveDocument.openTransaction("Create tube") + tube = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Tube") + TubeFeature(tube) + ViewProviderTube(tube.ViewObject) + FreeCAD.ActiveDocument.commitTransaction() + FreeCAD.ActiveDocument.recompute() - def IsActive(self): - return not FreeCAD.ActiveDocument is None + def IsActive(self): + return not FreeCAD.ActiveDocument is None -FreeCADGui.addCommand('Part_MakeTube',_CommandMakeTube()) + FreeCADGui.addCommand('Part_MakeTube',_CommandMakeTube())