MakeBottle.py

Go to the documentation of this file.
00001 #***************************************************************************
00002 #*   Copyright (c) 2008 Werner Mayer <wmayer@users.sourceforge.net>        *
00003 #*                                                                         *
00004 #*   This file is part of the FreeCAD CAx development system.              *
00005 #*                                                                         *
00006 #*   This program is free software; you can redistribute it and/or modify  *
00007 #*   it under the terms of the GNU General Public License (GPL)            *
00008 #*   as published by the Free Software Foundation; either version 2 of     *
00009 #*   the License, or (at your option) any later version.                   *
00010 #*   for detail see the LICENCE text file.                                 *
00011 #*                                                                         *
00012 #*   FreeCAD is distributed in the hope that it will be useful,            *
00013 #*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014 #*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015 #*   GNU Library General Public License for more details.                  *
00016 #*                                                                         *
00017 #*   You should have received a copy of the GNU Library General Public     *
00018 #*   License along with FreeCAD; if not, write to the Free Software        *
00019 #*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00020 #*   USA                                                                   *
00021 #*                                                                         *
00022 #***************************************************************************
00023 
00024 
00025 import Part, math
00026 import FreeCAD, FreeCADGui
00027 App=FreeCAD
00028 Gui=FreeCADGui
00029 from FreeCAD import Base
00030 
00031 def makeBottle(myWidth=50.0, myHeight=70.0, myThickness=30.0):
00032         aPnt1=Base.Vector(-myWidth/2.,0,0)
00033         aPnt2=Base.Vector(-myWidth/2.,-myThickness/4.,0)
00034         aPnt3=Base.Vector(0,-myThickness/2.,0)
00035         aPnt4=Base.Vector(myWidth/2.,-myThickness/4.,0)
00036         aPnt5=Base.Vector(myWidth/2.,0,0)
00037         
00038         aArcOfCircle = Part.Arc(aPnt2,aPnt3,aPnt4)
00039         aSegment1=Part.Line(aPnt1,aPnt2)
00040         aSegment2=Part.Line(aPnt4,aPnt5)
00041 
00042         aEdge1=aSegment1.toShape()
00043         aEdge2=aArcOfCircle.toShape()
00044         aEdge3=aSegment2.toShape()
00045         aWire=Part.Wire([aEdge1,aEdge2,aEdge3])
00046         
00047         aTrsf=Base.Matrix()
00048         aTrsf.rotateZ(math.pi) # rotate around the z-axis
00049 
00050         aMirroredWire=aWire.transformGeometry(aTrsf)
00051         myWireProfile=Part.Wire([aWire,aMirroredWire])
00052         
00053         myFaceProfile=Part.Face(myWireProfile)
00054         aPrismVec=Base.Vector(0,0,myHeight)
00055         myBody=myFaceProfile.extrude(aPrismVec)
00056         
00057         myBody=myBody.makeFillet(myThickness/12.0,myBody.Edges)
00058         
00059         neckLocation=Base.Vector(0,0,myHeight)
00060         neckNormal=Base.Vector(0,0,1)
00061         
00062         myNeckRadius = myThickness / 4.
00063         myNeckHeight = myHeight / 10
00064         myNeck = Part.makeCylinder(myNeckRadius,myNeckHeight,neckLocation,neckNormal)   
00065         myBody = myBody.fuse(myNeck)
00066 
00067         faceToRemove = 0
00068         zMax = -1.0
00069 
00070         for xp in myBody.Faces:
00071                 try:
00072                         surf = xp.Surface
00073                         if type(surf) == Part.Plane:
00074                                 z = surf.Position.z
00075                                 if z > zMax:
00076                                         zMax = z
00077                                         faceToRemove = xp
00078                 except:
00079                         continue
00080         
00081         # This doesn't work for any reason              
00082         myBody = myBody.makeThickness([faceToRemove],-myThickness/50 , 1.e-3)
00083 
00084         return myBody
00085 
00086 def makeBoreHole():
00087         # create a document if needed
00088         if App.ActiveDocument == None:
00089                 App.newDocument("Solid")
00090 
00091         Group = App.ActiveDocument.addObject("App::DocumentObjectGroup","Group")
00092         Group.Label="Bore hole"
00093 
00094         V1 = Base.Vector(0,10,0)
00095         V2 = Base.Vector(30,10,0)
00096         V3 = Base.Vector(30,-10,0)
00097         V4 = Base.Vector(0,-10,0)
00098         VC1 = Base.Vector(-10,0,0)
00099         C1 = Part.Arc(V1,VC1,V4)
00100         # and the second one
00101         VC2 = Base.Vector(40,0,0)
00102         C2 = Part.Arc(V2,VC2,V3)
00103         L1 = Part.Line(V1,V2)
00104         # and the second one
00105         L2 = Part.Line(V4,V3)
00106         S1 = Part.Shape([C1,C2,L1,L2])
00107 
00108         W=Part.Wire(S1.Edges)
00109         F=Part.Face(W)
00110         P=F.extrude(Base.Vector(0,0,5))
00111 
00112         # add objects with the shape
00113         Wire=Group.newObject("Part::Feature","Wire")
00114         Wire.Shape=W
00115         Face=Group.newObject("Part::Feature","Face")
00116         Face.Shape=F
00117         Prism=Group.newObject("Part::Feature","Extrude")
00118         Prism.Shape=P
00119 
00120         c=Part.Circle(Base.Vector(0,0,-1),Base.Vector(0,0,1),2.0)
00121         w=Part.Wire(c.toShape())
00122         f=Part.Face(w)
00123         p=f.extrude(Base.Vector(0,0,7))
00124         P=P.cut(p)
00125 
00126         # add first borer
00127         Bore1=Group.newObject("Part::Feature","Borer_1")
00128         Bore1.Shape=p
00129         Hole1=Group.newObject("Part::Feature","Borer_Hole1")
00130         Hole1.Shape=P
00131 
00132         c=Part.Circle(Base.Vector(0,-11,2.5),Base.Vector(0,1,0),1.0)
00133         w=Part.Wire(c.toShape())
00134         f=Part.Face(w)
00135         p=f.extrude(Base.Vector(0,22,0))
00136         P=P.cut(p)
00137 
00138         # add second borer
00139         Bore2=Group.newObject("Part::Feature","Borer_2")
00140         Bore2.Shape=p
00141         Hole2=Group.newObject("Part::Feature","Borer_Hole2")
00142         Hole2.Shape=P
00143 
00144         App.ActiveDocument.recompute()
00145 
00146         # hide all objets except of the final one
00147         Gui.ActiveDocument.getObject(Wire.Name).hide()
00148         Gui.ActiveDocument.getObject(Face.Name).hide()
00149         Gui.ActiveDocument.getObject(Prism.Name).hide()
00150         Gui.ActiveDocument.getObject(Bore1.Name).hide()
00151         Gui.ActiveDocument.getObject(Hole1.Name).hide()
00152         Gui.ActiveDocument.getObject(Bore2.Name).hide()
00153         Gui.ActiveDocument.ActiveView.fitAll()

Generated on Wed Nov 23 19:00:21 2011 for FreeCAD by  doxygen 1.6.1