00001 """ 00002 An example for a high-level cutsom feature object to form a full-parametric parallelepiped. 00003 00004 *************************************************************************** 00005 * Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net> * 00006 * * 00007 * This file is part of the FreeCAD CAx development system. * 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License (GPL) * 00011 * as published by the Free Software Foundation; either version 2 of * 00012 * the License, or (at your option) any later version. * 00013 * for detail see the LICENCE text file. * 00014 * * 00015 * FreeCAD is distributed in the hope that it will be useful, * 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00018 * GNU Library General Public License for more details. * 00019 * * 00020 * You should have received a copy of the GNU Library General Public * 00021 * License along with FreeCAD; if not, write to the Free Software * 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * 00023 * USA * 00024 * * 00025 *************************************************************************** 00026 """ 00027 00028 __author__ = "Werner Mayer <wmayer@users.sourceforge.net>" 00029 00030 import FreeCAD, Part, math 00031 from FreeCAD import Base 00032 00033 class Parallelepiped: 00034 def __init__(self, obj): 00035 ''' Add the properties: Length, Edges, Radius, Height ''' 00036 obj.addProperty("App::PropertyVector","A","Parallelepiped","Vector").A=Base.Vector(1,0,0) 00037 obj.addProperty("App::PropertyVector","B","Parallelepiped","Vector").B=Base.Vector(0,1,0) 00038 obj.addProperty("App::PropertyVector","C","Parallelepiped","Vector").C=Base.Vector(0,0,1) 00039 obj.Proxy = self 00040 00041 def onChanged(self, fp, prop): 00042 if prop == "A" or prop == "B" or prop == "C": 00043 self.execute(fp) 00044 00045 def execute(self, fp): 00046 a = fp.A 00047 b = fp.B 00048 c = fp.C 00049 00050 m=Base.Matrix() 00051 m.A11=a.x 00052 m.A12=a.y 00053 m.A13=a.z 00054 m.A21=b.x 00055 m.A22=b.y 00056 m.A23=b.z 00057 m.A31=c.x 00058 m.A32=c.y 00059 m.A33=c.z 00060 box = Part.makeBox(1,1,1) 00061 fp.Shape = box.transformGeometry(m) 00062 00063 class BoxCylinder: 00064 def __init__(self, obj): 00065 obj.addProperty("App::PropertyFloat","Length","BoxCylinder","Length").Length=10.0 00066 obj.addProperty("App::PropertyFloat","Width","BoxCylinder","Width").Width=10.0 00067 obj.addProperty("App::PropertyLink","Source","BoxCylinder","Source").Source=None 00068 obj.Proxy = self 00069 00070 def onChanged(self, fp, prop): 00071 if prop == "Length" or prop == "Width": 00072 self.execute(fp) 00073 00074 def execute(self, fp): 00075 FreeCAD.Console.PrintMessage(str(fp.Source)+"\n") 00076 if fp.Source is None: 00077 return 00078 r = fp.Source.Radius 00079 l = fp.Length 00080 w = fp.Width 00081 h = 2*r+10 00082 fp.Shape = Part.makeBox(l,w,h) 00083 00084 def makeParallelepiped(): 00085 doc = FreeCAD.activeDocument() 00086 if doc == None: 00087 doc = FreeCAD.newDocument() 00088 obj=doc.addObject("Part::FeaturePython","Parallelepiped") 00089 obj.Label = "Parallelepiped" 00090 Parallelepiped(obj) 00091 obj.ViewObject.Proxy=0 00092 00093 00094 def makeBoxCylinder(): 00095 doc = FreeCAD.activeDocument() 00096 if doc == None: 00097 doc = FreeCAD.newDocument() 00098 cyl=doc.addObject("Part::Cylinder","Cylinder") 00099 cyl.Radius=16.0 00100 cyl.Height=800.0 00101 obj=doc.addObject("Part::FeaturePython","Box") 00102 BoxCylinder(obj) 00103 obj.Source=cyl 00104 obj.Length=800.0 00105 obj.Width=600.0 00106 obj.ViewObject.Proxy=0 00107 doc.recompute()