improves airfoil import
This commit is contained in:
parent
efc311f908
commit
7ab2d7ec49
|
@ -26,7 +26,7 @@ __author__ = "Heiko Jakob <heiko.jakob@gediegos.de>"
|
||||||
|
|
||||||
import re, FreeCAD, FreeCADGui, Part, cProfile, os, string
|
import re, FreeCAD, FreeCADGui, Part, cProfile, os, string
|
||||||
from FreeCAD import Vector, Base
|
from FreeCAD import Vector, Base
|
||||||
from Draft import *
|
from Draft import makeWire
|
||||||
|
|
||||||
if open.__module__ == '__builtin__':
|
if open.__module__ == '__builtin__':
|
||||||
pythonopen = open
|
pythonopen = open
|
||||||
|
@ -68,60 +68,62 @@ def process(doc,filename):
|
||||||
# This code should work with almost every dialect
|
# This code should work with almost every dialect
|
||||||
|
|
||||||
# Regex to identify data rows and throw away unused metadata
|
# Regex to identify data rows and throw away unused metadata
|
||||||
expre = r"^\s*(?P<xval>\-*\d*?\.\d\d+)\s+(?P<yval>\-*\d*?\.\d+)\s*$"
|
regex = re.compile(r'^\s*(?P<xval>(\-|\d*)\.\d+(E\-?\d+)?)\,?\s*(?P<yval>\-?\s*\d*\.\d+(E\-?\d+)?)\s*$')
|
||||||
afile = pythonopen(filename,'r')
|
afile = pythonopen(filename,'r')
|
||||||
# read the airfoil name which is always at the first line
|
# read the airfoil name which is always at the first line
|
||||||
airfoilname = afile.readline().strip()
|
airfoilname = afile.readline().strip()
|
||||||
|
|
||||||
upper=[]
|
coords=[]
|
||||||
lower=[]
|
|
||||||
upside=True
|
upside=True
|
||||||
last_x=None
|
last_x=None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Collect the data for the upper and the lower side seperately if possible
|
# Collect the data for the upper and the lower side seperately if possible
|
||||||
for lin in afile:
|
for lin in afile:
|
||||||
curdat = re.match(expre,lin)
|
curdat = regex.match(lin)
|
||||||
if curdat != None:
|
if curdat != None:
|
||||||
|
|
||||||
x = float(curdat.group("xval"))
|
x = float(curdat.group("xval"))
|
||||||
y = float(curdat.group("yval"))
|
y = float(curdat.group("yval"))
|
||||||
|
|
||||||
if last_x == None:
|
|
||||||
last_x=x
|
|
||||||
|
|
||||||
# Separation between the sides is done in many different ways.
|
|
||||||
# The only way to safely detect the swap is when x is getting smaller
|
|
||||||
if x < last_x:
|
|
||||||
# The swap
|
|
||||||
upside=False
|
|
||||||
# Not needed because this will happen anyhow at the end of the loop last_x=x
|
|
||||||
|
|
||||||
# the normal processing
|
# the normal processing
|
||||||
if upside:
|
coords.append(Vector(x,y,0))
|
||||||
upper.append(Vector(x,y,0))
|
|
||||||
else:
|
|
||||||
lower.append(Vector(x,y,0))
|
|
||||||
last_x=x
|
|
||||||
# End of if curdat != None
|
# End of if curdat != None
|
||||||
# End of for lin in file
|
# End of for lin in file
|
||||||
afile.close()
|
afile.close()
|
||||||
|
|
||||||
# reverse the lower side and append it to the upper to
|
|
||||||
# make the complete data be oriented clockwise
|
|
||||||
lower.reverse()
|
if len(coords) < 3:
|
||||||
for i in lower:
|
print 'Did not find enough coordinates\n'
|
||||||
upper.append(i)
|
return
|
||||||
# End of for i in lower
|
|
||||||
|
# sometimes coords are divided in upper an lower side
|
||||||
|
# so that x-coordinate begin new from leading or trailing edge
|
||||||
|
# check for start coordinates in the middle of list
|
||||||
|
|
||||||
|
if coords[0:-1].count(coords[0]) > 1:
|
||||||
|
flippoint = coords.index(coords[0],1)
|
||||||
|
upper = coords[0:flippoint]
|
||||||
|
lower = coords[flippoint+1:]
|
||||||
|
lower.reverse()
|
||||||
|
for i in lower:
|
||||||
|
upper.append(i)
|
||||||
|
coords = upper
|
||||||
|
|
||||||
|
|
||||||
# do we use the parametric Draft Wire?
|
# do we use the parametric Draft Wire?
|
||||||
if useDraftWire:
|
if useDraftWire:
|
||||||
face = makeWire ( upper, True, None, True )
|
obj = makeWire ( coords, True )
|
||||||
|
#obj.label = airfoilname
|
||||||
else:
|
else:
|
||||||
# alternate solution, uses common Part Faces
|
# alternate solution, uses common Part Faces
|
||||||
lines = []
|
lines = []
|
||||||
first_v = None
|
first_v = None
|
||||||
last_v = None
|
last_v = None
|
||||||
for v in upper:
|
for v in coords:
|
||||||
if first_v == None:
|
if first_v == None:
|
||||||
first_v = v
|
first_v = v
|
||||||
# End of if first_v == None
|
# End of if first_v == None
|
||||||
|
@ -140,6 +142,7 @@ def process(doc,filename):
|
||||||
|
|
||||||
wire = Part.Wire(lines)
|
wire = Part.Wire(lines)
|
||||||
face = Part.Face(wire)
|
face = Part.Face(wire)
|
||||||
Part.show(face)
|
obj = FreeCAD.ActiveDocument.addObject('Part::Feature',airfoilname)
|
||||||
|
obj.Shape = face
|
||||||
|
|
||||||
doc.recompute()
|
doc.recompute()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user