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)

This commit is contained in:
wmayer
2020-09-03 17:47:25 +02:00
parent e477283ffc
commit 06d6cc579f

View File

@@ -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())