PageRenderTime 38ms CodeModel.GetById 1ms app.highlight 32ms RepoModel.GetById 1ms app.codeStats 1ms

/src/examples/Tools/InteractiveViewer/scripts/Bottle.py

http://pythonocc.googlecode.com/
Python | 125 lines | 83 code | 22 blank | 20 comment | 1 complexity | 874e90f7d6a6d6e4a59c1bef7da1614d MD5 | raw file
  1#!C:/Python24/Python.exe
  2# -*- coding: utf-8 -*-
  3
  4'''
  5Bottle example converted to work with the viewer
  6'''
  7
  8__author__ = "Andrew Haywood"
  9__date__ = "15 November 2007"
 10
 11# --------------------------------------------------
 12import os
 13import os.path
 14import math
 15# --------------------------------------------------
 16
 17display.EraseAll()
 18
 19# --------------------------------------------------
 20
 21myWidth = 50
 22myHeight = 70
 23myThickness = 30
 24
 25# Profile : Define Support Points
 26aPnt1 = gp_Pnt(-myWidth / 2. , 0 , 0)
 27aPnt2 = gp_Pnt(-myWidth / 2. , -myThickness / 4. , 0)
 28aPnt3 = gp_Pnt(0 , -myThickness / 2. , 0)
 29aPnt4 = gp_Pnt(myWidth / 2. , -myThickness / 4. , 0)
 30aPnt5 = gp_Pnt(myWidth / 2. , 0 , 0)
 31
 32# Profile : Define the Geometry
 33aArcOfCircle = GC_MakeArcOfCircle(aPnt2,aPnt3 ,aPnt4)
 34aSegment1 = GC_MakeSegment(aPnt1 , aPnt2)
 35aSegment2 = GC_MakeSegment(aPnt4 , aPnt5)
 36
 37# Profile : Define the Topology
 38aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value())
 39aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value())
 40aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value())
 41aWire  = BRepBuilderAPI_MakeWire(aEdge1.Edge() , aEdge2.Edge() , aEdge3.Edge())
 42
 43# Complete Profile
 44xAxis = gp().OX()
 45aTrsf = gp_Trsf()
 46aTrsf.SetMirror(xAxis)
 47aBRepTrsf = BRepBuilderAPI_Transform(aWire.Shape() , aTrsf)
 48aMirroredShape = aBRepTrsf.Shape()
 49aMirroredWire = TopoDS().Wire(aMirroredShape)
 50mkWire = BRepBuilderAPI_MakeWire()
 51mkWire.Add(aWire.Wire())
 52mkWire.Add(aMirroredWire)
 53myWireProfile = mkWire.Wire()
 54
 55# Body : Prism the Profile
 56myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile)
 57aPrismVec = gp_Vec(0 , 0 , myHeight)
 58myBody = BRepPrimAPI_MakePrism(myFaceProfile.Shape() , aPrismVec)
 59
 60# Body : Apply Fillets
 61mkFillet = BRepFilletAPI_MakeFillet(myBody.Shape())
 62aEdgeExplorer = TopExp_Explorer(myBody.Shape() , TopAbs_EDGE)
 63while aEdgeExplorer.More():
 64    aEdge = TopoDS().Edge(aEdgeExplorer.Current())
 65    mkFillet.Add(myThickness / 12. , aEdge)
 66    aEdgeExplorer.Next()
 67myBody = mkFillet.Shape()
 68
 69# Body : Add the Neck	
 70neckLocation = gp_Pnt(0 , 0 , myHeight)
 71neckNormal = gp().DZ()
 72neckAx2 = gp_Ax2(neckLocation , neckNormal)
 73myNeckRadius = myThickness / 4.
 74myNeckHeight = myHeight / 10.
 75MKCylinder = BRepPrimAPI_MakeCylinder(neckAx2 , myNeckRadius , myNeckHeight)
 76myNeck = MKCylinder.Shape()
 77myBody = BRepAlgoAPI_Fuse(myBody , myNeck)
 78
 79# Threading : Create Surfaces
 80neckAx2_bis = gp_Ax3(neckLocation , neckNormal)
 81aCyl1 = Geom_CylindricalSurface(neckAx2_bis , myNeckRadius * 0.99)
 82aCyl2 = Geom_CylindricalSurface(neckAx2_bis , myNeckRadius * 1.05)
 83
 84# Threading : Define 2D Curves
 85aPnt = gp_Pnt2d(2. * math.pi , myNeckHeight / 2.)
 86aDir = gp_Dir2d(2. * math.pi , myNeckHeight / 4.)
 87aAx2d = gp_Ax2d(aPnt , aDir)
 88aMajor = 2. * math.pi
 89aMinor = myNeckHeight / 10.
 90anEllipse1 = Geom2d_Ellipse(aAx2d , aMajor , aMinor)
 91anEllipse2 = Geom2d_Ellipse(aAx2d , aMajor , aMinor / 4)
 92aArc1 = Geom2d_TrimmedCurve(Handle_Geom2d_Ellipse(anEllipse1) , 0 , math.pi)
 93aArc2 = Geom2d_TrimmedCurve(Handle_Geom2d_Ellipse(anEllipse2) , 0 , math.pi)
 94aArc1_handle = Handle_Geom2d_Curve(aArc1)
 95aArc2_handle = Handle_Geom2d_Curve(aArc2)
 96anEllipsePnt1 = anEllipse1.Value(0)
 97anEllipsePnt2 = anEllipse1.Value(math.pi)
 98aSegment = GCE2d_MakeSegment(anEllipsePnt1 , anEllipsePnt2)
 99
100# Threading : Build Edges and Wires
101aEdge1OnSurf1 = BRepBuilderAPI_MakeEdge( aArc1_handle , Handle_Geom_Surface(aCyl1))
102aEdge2OnSurf1 = BRepBuilderAPI_MakeEdge( aSegment.Value() , Handle_Geom_Surface(aCyl1))
103aEdge1OnSurf2 = BRepBuilderAPI_MakeEdge( aArc2_handle , Handle_Geom_Surface(aCyl2))
104aEdge2OnSurf2 = BRepBuilderAPI_MakeEdge( aSegment.Value() , Handle_Geom_Surface(aCyl2))
105
106threadingWire1 = BRepBuilderAPI_MakeWire(aEdge1OnSurf1.Edge() , aEdge2OnSurf1.Edge())
107threadingWire2 = BRepBuilderAPI_MakeWire(aEdge1OnSurf2.Edge() , aEdge2OnSurf2.Edge())
108BRepLib().BuildCurves3d(threadingWire1.Shape())
109BRepLib().BuildCurves3d(threadingWire2.Shape())
110
111# Create Threading
112aTool = BRepOffsetAPI_ThruSections(True)
113aTool.AddWire(threadingWire1.Wire())
114aTool.AddWire(threadingWire2.Wire())
115aTool.CheckCompatibility(False)
116
117myThreading = aTool.Shape()
118
119display.DisplayShape(myBody.Shape())
120display.DisplayShape(myThreading)
121
122display.View_Iso()
123display.Zoom_FitAll()
124
125# --------------------------------------------------