Example #1
0
    def make_shape(self):
        # 1 - retrieve the data from the UIUC airfoil data page
        foil_dat_url = 'http://www.ae.illinois.edu/m-selig/ads/coord_seligFmt/%s.dat' % self.profile
        f = urllib2.urlopen(foil_dat_url)

        plan = gp_Pln(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))  # Z=0 plan / XY plan
        section_pts_2d = []

        for line in f.readlines()[1:]:  # The first line contains info only
            # 2 - do some cleanup on the data (mostly dealing with spaces)
            line = line.lstrip().rstrip().replace('    ', ' ').replace(
                '   ', ' ').replace('  ', ' ')
            data = line.split(' ')  # data[0] = x coord.    data[1] = y coord.

            # 3 - create an array of points
            if len(data) == 2:  # two coordinates for each point
                section_pts_2d.append(
                    gp_Pnt2d(
                        float(data[0]) * self.chord,
                        float(data[1]) * self.chord))

        # 4 - use the array to create a spline describing the airfoil section
        spline_2d = Geom2dAPI_PointsToBSpline(
            point2d_list_to_TColgp_Array1OfPnt2d(section_pts_2d),
            len(section_pts_2d) - 1,  # order min
            len(section_pts_2d))  # order max
        spline = GeomAPI_To3d(spline_2d.Curve(), plan)

        # 5 - figure out if the trailing edge has a thickness or not, and create a Face
        try:
            #first and last point of spline -> trailing edge
            trailing_edge = make_edge(
                gp_Pnt(section_pts_2d[0].X(), section_pts_2d[0].Y(), 0.0),
                gp_Pnt(section_pts_2d[-1].X(), section_pts_2d[-1].Y(), 0.0))

            face = BRepBuilderAPI_MakeFace(
                make_wire([make_edge(spline), trailing_edge]))

        except AssertionError:
            # the trailing edge segment could not be created, probably because the points are too close
            # No need to build a trailing edge
            face = BRepBuilderAPI_MakeFace(make_wire(make_edge(spline)))

        # 6 - extrude the Face to create a Solid
        return BRepPrimAPI_MakePrism(
            face.Face(), gp_Vec(gp_Pnt(0, 0, 0), gp_Pnt(0, 0,
                                                        self.span))).Shape()
Example #2
0
 def trim(self, lbound, ubound, periodic=False):
     '''
     trim the curve
     @param lbound:
     @param ubound:
     '''
     a, b = sorted([lbound, ubound])
     tr = Geom_TrimmedCurve(self.adaptor.Curve().Curve(), a, b).GetHandle()
     return Edge(make_edge(tr))
Example #3
0
 def trim(self, lbound, ubound, periodic=False):
     '''
     trim the curve
     @param lbound:
     @param ubound:
     '''
     a, b = sorted([lbound, ubound])
     tr = Geom_TrimmedCurve(self.adaptor.Curve().Curve(), a, b).GetHandle()
     return Edge(make_edge(tr))
Example #4
0
    def make_shape(self):
        # 1 - retrieve the data from the UIUC airfoil data page
        foil_dat_url = 'http://www.ae.illinois.edu/m-selig/ads/coord_seligFmt/%s.dat' % self.profile
        f = urllib2.urlopen(foil_dat_url)
 
        plan = gp_Pln(gp_Pnt(0,0,0), gp_Dir(0,0,1)) # Z=0 plan / XY plan
        section_pts_2d=[]
 
        for line in f.readlines()[1:]: # The first line contains info only
            # 2 - do some cleanup on the data (mostly dealing with spaces)
            line = line.lstrip().rstrip().replace('    ',' ').replace('   ',' ').replace('  ',' ')
            data = line.split(' ') # data[0] = x coord.    data[1] = y coord.
 
            # 3 - create an array of points
            if len(data)==2: # two coordinates for each point
                section_pts_2d.append(gp_Pnt2d(float(data[0])*self.chord,
                                               float(data[1])*self.chord))
 
        # 4 - use the array to create a spline describing the airfoil section
        spline_2d = Geom2dAPI_PointsToBSpline(point2d_list_to_TColgp_Array1OfPnt2d(section_pts_2d),
                                              len(section_pts_2d)-1, # order min
                                              len(section_pts_2d))   # order max
        spline = GeomAPI_To3d(spline_2d.Curve(),plan)
 
        # 5 - figure out if the trailing edge has a thickness or not, and create a Face
        try:
            #first and last point of spline -> trailing edge
            trailing_edge = make_edge(gp_Pnt(section_pts_2d[0].X(),  section_pts_2d[0].Y() ,0.0),
                                      gp_Pnt(section_pts_2d[-1].X(), section_pts_2d[-1].Y(),0.0))
 
            face = BRepBuilderAPI_MakeFace(make_wire([make_edge(spline),trailing_edge]))
 
        except AssertionError:
            # the trailing edge segment could not be created, probably because the points are too close
            # No need to build a trailing edge
            face = BRepBuilderAPI_MakeFace(make_wire(make_edge(spline)))
 
        # 6 - extrude the Face to create a Solid
        return BRepPrimAPI_MakePrism(face.Face(),
                                     gp_Vec(gp_Pnt(0,0,0),
                                     gp_Pnt(0,0,self.span))).Shape()
Example #5
0
def faircurve(event=None):
    pt1 = gp_Pnt2d(0,0)
    pt2 = gp_Pnt2d(0,120)
    height = 100.
    slope = 0.3
    pl = Geom_Plane(gp_Pln())
    for i in range(0, 40, 1):
        # TODO: the parameter slope needs to be visualized
        bc = batten_curve(pt1, pt2, height, i/100., math.radians(i), math.radians(-i))
        display.EraseAll()
        display.DisplayShape(make_edge(bc, pl.GetHandle()), update=True)
        time.sleep(0.21)
Example #6
0
    def trim(self, lbound, ubound, periodic=False):
        '''
        trim the curve
        @param lbound:
        @param ubound:
        '''
#        if self.is_periodic:
#            pass
#        else:
#            warnings.warn('the wire to be trimmed is not closed, hence cannot be made periodic')
        a,b = sorted([lbound,ubound])
        tr = Geom_TrimmedCurve(self.adaptor.Curve().Curve(), a,b).GetHandle()
        return Edge(make_edge(tr))
Example #7
0
def faircurve(event=None):
    pt1 = gp_Pnt2d(0, 0)
    pt2 = gp_Pnt2d(0, 120)
    height = 100.
    slope = 0.3
    pl = Geom_Plane(gp_Pln())
    for i in range(0, 40, 1):
        # TODO: the parameter slope needs to be visualized
        bc = batten_curve(pt1, pt2, height, i / 100., math.radians(i),
                          math.radians(-i))
        display.EraseAll()
        display.DisplayShape(make_edge(bc, pl.GetHandle()), update=True)
        time.sleep(0.21)
Example #8
0
##the Free Software Foundation, either version 3 of the License, or
##(at your option) any later version.
##
##pythonOCC is distributed in the hope that it will be useful,
##but WITHOUT ANY WARRANTY; without even the implied warranty of
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##GNU Lesser General Public License for more details.
##
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC.  If not, see <http://www.gnu.org/licenses/>.

from OCC.gp import *
from OCC.AIS import *
from OCC.TCollection import TCollection_ExtendedString
from OCC.Utils.Construct import make_edge
from OCC.Utils.Common import to_string

from OCC.Display.SimpleGui import *
display, start_display, add_menu, add_function_to_menu = init_display()

c = gp_Circ(gp_Ax2(gp_Pnt(200.,200.,0.),gp_Dir(0.,0.,1.)), 80)
ec = make_edge(c)
ais_shp = AIS_Shape(ec)
display.Context.Display(ais_shp.GetHandle())
rd = AIS_RadiusDimension(ec,80,to_string("radius"))
rd.SetArrowSize(12)
display.Context.Display(rd.GetHandle())
display.FitAll()
start_display()
 
Example #9
0
##pythonOCC is free software: you can redistribute it and/or modify
##it under the terms of the GNU Lesser General Public License as published by
##the Free Software Foundation, either version 3 of the License, or
##(at your option) any later version.
##
##pythonOCC is distributed in the hope that it will be useful,
##but WITHOUT ANY WARRANTY; without even the implied warranty of
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##GNU Lesser General Public License for more details.
##
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC.  If not, see <http://www.gnu.org/licenses/>.

from OCC.gp import *
from OCC.AIS import *
from OCC.Utils.Construct import make_edge
from OCC.Utils.Common import to_string

from OCC.Display.SimpleGui import *
display, start_display, add_menu, add_function_to_menu = init_display()

c = gp_Circ(gp_Ax2(gp_Pnt(200., 200., 0.), gp_Dir(0., 0., 1.)), 80)
ec = make_edge(c)
ais_shp = AIS_Shape(ec)
display.Context.Display(ais_shp.GetHandle())
rd = AIS_RadiusDimension(ec, 80, to_string("radius"))
rd.SetArrowSize(12)
display.Context.Display(rd.GetHandle())
display.FitAll()
start_display()
Example #10
0
for vertex in vertices:
	x = int(vertex.attributes['x'].value)
	y = int(vertex.attributes['y'].value)	
	z = int(vertex.attributes['z'].value)
	point = gp_Pnt((x-xReduceFactor)*scaleFactor,(y-yReduceFactor)*scaleFactor,(z-zReduceFactor)*scaleFactor)
	display.DisplayShape(make_vertex(point))
edges = dom.getElementsByTagName('edge')
for edge in edges:
	x1 = int(edge.attributes['x1'].value)
	y1 = int(edge.attributes['y1'].value)	
	z1 = int(edge.attributes['z1'].value)
	x2 = int(edge.attributes['x2'].value)
	y2 = int(edge.attributes['y2'].value)	
	z2 = int(edge.attributes['z2'].value)
	segment = GC_MakeSegment(gp_Pnt((x1-xReduceFactor)*scaleFactor,(y1-yReduceFactor)*scaleFactor,(z1-zReduceFactor)*scaleFactor),gp_Pnt((x2-xReduceFactor)*scaleFactor,(y2-yReduceFactor)*scaleFactor,(z2-zReduceFactor)*scaleFactor)).Value()	
	display.DisplayShape(make_edge(segment))	
cylinders = dom.getElementsByTagName('cylinder')
for cylinder in cylinders:
	x1 = int(cylinder.attributes['x1'].value)
	y1 = int(cylinder.attributes['y1'].value)	
	z1 = int(cylinder.attributes['z1'].value)
	x2 = int(cylinder.attributes['x2'].value)
	y2 = int(cylinder.attributes['y2'].value)	
	z2 = int(cylinder.attributes['z2'].value)
	radius = int(cylinder.attributes['radius'].value)
	height = distance_two_points(x1,y1,z1,x2,y2,z2)
	vector = gp_Vec(x2-x1, y2-y1, z2-z1)
	direction = gp_Dir(vector)
	axis = gp_Ax2(gp_Pnt(x1,y1,z1),direction)
	cylinderShape = BRepPrimAPI_MakeCylinder(axis,radius,height).Shape()