RadialCopy.py
Go to the documentation of this file.00001
00002
00003
00004
00005 """
00006 An example for a high-level cutsom feature object to make a so called "radial copy".
00007 """
00008 __author__ = "Werner Mayer <wmayer@users.sourceforge.net>"
00009
00010 import FreeCAD, FreeCADGui, Part, math
00011 from PyQt4 import QtGui
00012 from FreeCAD import Base
00013
00014 def makeCopy(shape, radius, angle):
00015 mat = Base.Matrix()
00016 mat.rotateZ(math.radians(angle))
00017 step = int(360.0 / angle)
00018 shape = shape.copy()
00019 shape.translate((radius, 0, 0))
00020 comp = shape.copy()
00021 for i in range(step):
00022 shape.transformShape(mat)
00023 comp = comp.fuse(shape)
00024 return comp
00025
00026
00027 class RadialCopy:
00028 def __init__(self, obj):
00029 obj.addProperty("App::PropertyLength","Radius","","Radius").Radius=10.0
00030 obj.addProperty("App::PropertyLength","Angle" ,"","Angle").Angle=20.0
00031 obj.addProperty("App::PropertyLink","Source" ,"","Source shape").Source=None
00032 obj.Proxy = self
00033
00034
00035
00036
00037
00038 def execute(self, fp):
00039 shape = fp.Source.Shape
00040 radius = fp.Radius
00041 angle = fp.Angle
00042 fp.Shape = makeCopy(shape, radius, angle)
00043
00044 def makeRadialCopy():
00045 sel = FreeCADGui.Selection.getSelection()
00046 try:
00047 sel = sel[0]
00048 shape = sel.Shape
00049 name = sel.Label
00050 except:
00051 QtGui.QMessageBox.critical(None,"Wrong selection","Please select a shape object")
00052
00053 else:
00054 doc = sel.Document
00055 rc = doc.addObject("Part::FeaturePython","RadialCopy")
00056 rc.Label = name+"(Radial Copy)"
00057 RadialCopy(rc)
00058 rc.Source = sel
00059 rc.ViewObject.Proxy=0
00060