Fixed unstored discretization data.

This commit is contained in:
Jose Luis Cercós pita 2012-01-22 19:24:51 +01:00 committed by Yorik van Havre
parent b42da01ab1
commit 475eb283f9

View File

@ -79,7 +79,7 @@ class Ship:
nPoint = len(points) nPoint = len(points)
if nPoint <= nVertex: if nPoint <= nVertex:
# Any valid point # Any valid point
result return result
for i in range(0,nPoint): for i in range(0,nPoint):
disp = len(result) disp = len(result)
flag = 0 flag = 0
@ -98,10 +98,14 @@ class Ship:
@param nS Number of sections @param nS Number of sections
@param nP Number of points per section @param nP Number of points per section
""" """
print(nS,nP)
self.obj.addProperty("App::PropertyInteger","nSections","Ship", str(Translator.translate("Number of sections"))).nSections=nS self.obj.addProperty("App::PropertyInteger","nSections","Ship", str(Translator.translate("Number of sections"))).nSections=nS
self.obj.addProperty("App::PropertyIntegerList","nPoints","Ship", str(Translator.translate("List of number of points per sections (accumulated histogram)"))).nPoints=[0] self.obj.addProperty("App::PropertyIntegerList","nPoints","Ship", str(Translator.translate("List of number of points per sections (accumulated histogram)"))).nPoints=[0]
self.obj.addProperty("App::PropertyFloatList","xSection","Ship", str(Translator.translate("List of sections x coordinate"))).xSection=[] self.obj.addProperty("App::PropertyFloatList","xSection","Ship", str(Translator.translate("List of sections x coordinate"))).xSection=[]
self.obj.addProperty("App::PropertyVectorList","mSections","Ship", str(Translator.translate("List of sections points"))).mSections=[] self.obj.addProperty("App::PropertyVectorList","mSections","Ship", str(Translator.translate("List of sections points"))).mSections=[]
nPoints = [0]
xSection = []
mSections = []
# Get bounds # Get bounds
shape = self.obj.Shape shape = self.obj.Shape
bbox = shape.BoundBox bbox = shape.BoundBox
@ -124,7 +128,7 @@ class Ship:
for i in range(0,nS): for i in range(0,nS):
section = [] section = []
x = x0 + i*dx x = x0 + i*dx
self.obj.xSection.append(x) xSection.append(x)
percen = i*100 / (nS-1) percen = i*100 / (nS-1)
FreeCAD.Console.PrintMessage('%d%%\n' % (percen)); FreeCAD.Console.PrintMessage('%d%%\n' % (percen));
# Slice the surface to get curves # Slice the surface to get curves
@ -136,7 +140,7 @@ class Ship:
FreeCAD.Console.PrintWarning(msg) FreeCAD.Console.PrintWarning(msg)
FreeCAD.Console.PrintWarning('\tThis may happens if a bad defined (or really complex) surface has been provided.\n') FreeCAD.Console.PrintWarning('\tThis may happens if a bad defined (or really complex) surface has been provided.\n')
FreeCAD.Console.PrintWarning('\tPlease, ensure that this section is correct, or fix surfaces and create a new ship.\n') FreeCAD.Console.PrintWarning('\tPlease, ensure that this section is correct, or fix surfaces and create a new ship.\n')
self.obj.nPoints.append(0) nPoints.append(0)
# Desarrollate wires into edges list # Desarrollate wires into edges list
edges = [] edges = []
for j in range(0,len(wires)): for j in range(0,len(wires)):
@ -160,9 +164,13 @@ class Ship:
for j in range(0,len(points)): for j in range(0,len(points)):
section.append(Vector(points[j].x, aux[j], points[j].z)) section.append(Vector(points[j].x, aux[j], points[j].z))
# Store points # Store points
self.obj.nPoints.append(len(points)) nPoints.append(len(section))
for j in range(0,len(points)): for j in range(0,len(section)):
self.obj.mSections.append(points[j]) mSections.append(section[j])
# Save data
self.obj.nPoints = nPoints[:]
self.obj.xSection = xSection[:]
self.obj.mSections = mSections[:]
class ViewProviderShip: class ViewProviderShip:
def __init__(self, obj): def __init__(self, obj):
@ -653,8 +661,10 @@ def sections(obj):
histogram = obj.nPoints[:] histogram = obj.nPoints[:]
points = obj.mSections[:] points = obj.mSections[:]
sections = [] sections = []
print(histogram)
for i in range(0, len(histogram) - 1): for i in range(0, len(histogram) - 1):
sections.append([]) sections.append([])
print(histogram[i],histogram[i+1])
for j in range(histogram[i],histogram[i+1]): for j in range(histogram[i],histogram[i+1]):
sections[i].append(points[j]) sections[i].append(points[j])
return sections return sections