diff --git a/src/Mod/PartDesign/App/CMakeLists.txt b/src/Mod/PartDesign/App/CMakeLists.txt index f422e8ea3..44371e091 100644 --- a/src/Mod/PartDesign/App/CMakeLists.txt +++ b/src/Mod/PartDesign/App/CMakeLists.txt @@ -77,13 +77,14 @@ SET(PartDesign_SRCS SET(PartDesign_Scripts __init__.py - Init.py - TestPartDesignApp.py + Init.py + TestPartDesignApp.py Scripts/__init__.py Scripts/Gear.py Scripts/DistanceBolt.py Scripts/RadialCopy.py Scripts/Parallelepiped.py + Scripts/Spring.py ) add_library(PartDesign SHARED ${PartDesign_SRCS}) diff --git a/src/Mod/PartDesign/Gui/CMakeLists.txt b/src/Mod/PartDesign/Gui/CMakeLists.txt index 459c3ea34..b9cf3a3fa 100644 --- a/src/Mod/PartDesign/Gui/CMakeLists.txt +++ b/src/Mod/PartDesign/Gui/CMakeLists.txt @@ -106,7 +106,7 @@ SOURCE_GROUP("Module" FILES ${PartDesignGuiModule_SRCS}) SET(PartDesignGui_Scripts InitGui.py - TestPartDesignGui.py + TestPartDesignGui.py ) SET(PartDesignGui_SRCS diff --git a/src/Mod/PartDesign/Scripts/Makefile.am b/src/Mod/PartDesign/Scripts/Makefile.am index ec32a3740..198d8b035 100644 --- a/src/Mod/PartDesign/Scripts/Makefile.am +++ b/src/Mod/PartDesign/Scripts/Makefile.am @@ -5,7 +5,8 @@ data_DATA = \ Gear.py \ DistanceBolt.py \ RadialCopy.py \ - Parallelepiped.py + Parallelepiped.py \ + Spring.py EXTRA_DIST = \ $(data_DATA) diff --git a/src/Mod/PartDesign/Scripts/Spring.py b/src/Mod/PartDesign/Scripts/Spring.py new file mode 100644 index 000000000..d9628961d --- /dev/null +++ b/src/Mod/PartDesign/Scripts/Spring.py @@ -0,0 +1,51 @@ +#! python +# -*- coding: utf-8 -*- +# (c) 2011 Adrian Przekwas LGPL + +from __future__ import division # allows floating point division from integers +import FreeCAD, Part +from FreeCAD import Base + +class MySpring: + def __init__(self, obj): + ''' Add the properties: Pitch, Diameter, Height, BarDiameter ''' + obj.addProperty("App::PropertyLength","Pitch","MySpring","Pitch of the helix").Pitch=5.0 + obj.addProperty("App::PropertyLength","Diameter","MySpring","Diameter of the helix").Diameter=6.0 + obj.addProperty("App::PropertyLength","Height","MySpring","Height of the helix").Height=30.0 + obj.addProperty("App::PropertyLength","BarDiameter","MySpring","Diameter of the bar").BarDiameter=3.0 + obj.Proxy = self + + def onChanged(self, fp, prop): + if prop == "Pitch" or prop == "Diameter" or prop == "Height" or prop == "BarDiameter": + self.execute(fp) + + def execute(self, fp): + pitch = fp.Pitch + radius = fp.Diameter/2 + height = fp.Height + barradius = fp.BarDiameter/2 + myhelix=Part.makeHelix(pitch,height,radius) + g=myhelix.Edges[0].Curve + c=Part.Circle() + c.Center=g.value(0) # start point of the helix + c.Axis=(0,1,0) + c.Radius=barradius + p=c.toShape() + section = Part.Wire([p]) + makeSolid=1 #change to 1 to make a solid + isFrenet=1 + myspring=Part.Wire(myhelix).makePipeShell([section],makeSolid,isFrenet) + fp.Shape = myspring + +def makeMySpring(): + doc = FreeCAD.activeDocument() + if doc == None: + doc = FreeCAD.newDocument() + spring=doc.addObject("Part::FeaturePython","My_Spring") + spring.Label = "My Spring" + MySpring(spring) + spring.ViewObject.Proxy=0 + doc.recompute() + +if __name__ == "__main__": + makeMySpring()