def update(self, draft, trim, ship): """ Update free surface 3D view @param traft Draft. @param trim Trim in degrees. """ # Destroy old object if exist self.clean() # Set free surface bounds bbox = ship.Shape.BoundBox L = 1.5 * bbox.XLength B = 3.0 * bbox.YLength # Create plane x = - 0.5 * L y = - 0.5 * B point = Base.Vector(x,y,0.0) plane = Part.makePlane(L,B, point, Base.Vector(0,0,1)) # Set position plane.rotate(Base.Vector(0,0,0), Base.Vector(0,1,0), trim) plane.translate(Base.Vector(0,0,draft)) # Create the FreeCAD object Part.show(plane) objs = FreeCAD.ActiveDocument.Objects self.obj = objs[len(objs)-1] self.obj.Label = 'FreeSurface' # Set properties of object guiObj = FreeCADGui.ActiveDocument.getObject(self.obj.Name) guiObj.ShapeColor = (0.4,0.8,0.85) guiObj.Transparency = 50
def update(self, draft, trim, ship): """ Update free surface 3D view @param traft Draft. @param trim Trim in degrees. """ # Destroy old object if exist self.clean() # Set free surface bounds bbox = ship.Shape.BoundBox L = 1.5 * bbox.XLength B = 3.0 * bbox.YLength # Create plane x = -0.5 * L y = -0.5 * B point = Base.Vector(x, y, 0.0) plane = Part.makePlane(L, B, point, Base.Vector(0, 0, 1)) # Set position plane.rotate(Base.Vector(0, 0, 0), Base.Vector(0, 1, 0), trim) plane.translate(Base.Vector(0, 0, draft)) # Create the FreeCAD object Part.show(plane) objs = FreeCAD.ActiveDocument.Objects self.obj = objs[len(objs) - 1] self.obj.Label = 'FreeSurface' # Set properties of object guiObj = FreeCADGui.ActiveDocument.getObject(self.obj.Name) guiObj.ShapeColor = (0.4, 0.8, 0.85) guiObj.Transparency = 50
def discretize(self, nS, nP): """ Discretize the surface. @param nS Number of sections @param nP Number of points per section """ 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::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=[] nPoints = [0] xSection = [] mSections = [] # Get bounds shape = self.obj.Shape bbox = shape.BoundBox x0 = bbox.XMin x1 = bbox.XMax y0 = bbox.YMin y1 = bbox.YMax z0 = bbox.ZMin z1 = bbox.ZMax # Create a set of planes to perfom edges sections planes = [] dz = (z1 - z0) / (nP - 1) for j in range(0,nP): z = z0 + j*dz rX = x1 - x0 rY = max(y1 - y0, abs(y1), abs(y0)) planes.append(Part.makePlane(4*rX,4*rY,Base.Vector(-2*rX,-2*rY,z),Base.Vector(0,0,1))) # Division are performed at x axis dx = (x1 - x0) / (nS - 1.0) for i in range(0,nS): section = [] x = x0 + i*dx xSection.append(x) percen = i*100 / (nS-1) FreeCAD.Console.PrintMessage('%d%%\n' % (percen)); # Slice the surface to get curves wires = shape.slice(Vector(1.0,0.0,0.0), x) if not wires: if (i != 0) or (i != nS-1): msg = 'Found empty section at x=%g\n' % (x) msg = Translator.translate(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('\tPlease, ensure that this section is correct, or fix surfaces and create a new ship.\n') nPoints.append(0) continue # Desarrollate wires into edges list edges = [] for j in range(0,len(wires)): wire = wires[j].Edges for k in range(0,len(wire)): edges.append(wire[k]) # Slice curves to get points (Length based) points = [] for k in range(0,nP): planePoints = [] for j in range(0,len(edges)): aux = self.lineFaceSection(edges[j], planes[k]) for l in range(0,len(aux)): planePoints.append(Vector(aux[l].X, aux[l].Y, aux[l].Z)) if not planePoints: # No section found, symmetry plane point will used planePoints.append(Vector(x,0,z0 + k*dz)) # Get Y coordinates auxY = [] for l in range(0,len(planePoints)): auxY.append(planePoints[l].y) # Sort them auxY.sort() # And store for l in range(0,len(planePoints)): points.append(Vector(planePoints[l].x, auxY[l], planePoints[l].z)) # Store points section = points[:] nPoints.append(len(section)) for j in range(0,len(section)): mSections.append(section[j]) # Save data for i in range(1,len(nPoints)): nPoints[i] = nPoints[i] + nPoints[i-1] self.obj.nPoints = nPoints[:] self.obj.xSection = xSection[:] self.obj.mSections = mSections[:] msg = '%d Discretization points performed\n' % (len(mSections)) msg = Translator.translate(msg) FreeCAD.Console.PrintMessage(msg)
def discretize(self, nS, nP): """ Discretize the surface. @param nS Number of sections @param nP Number of points per section """ 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::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 = [] nPoints = [0] xSection = [] mSections = [] # Get bounds shape = self.obj.Shape bbox = shape.BoundBox x0 = bbox.XMin x1 = bbox.XMax y0 = bbox.YMin y1 = bbox.YMax z0 = bbox.ZMin z1 = bbox.ZMax # Create a set of planes to perfom edges sections planes = [] dz = (z1 - z0) / (nP - 1) for j in range(0, nP): z = z0 + j * dz rX = x1 - x0 rY = max(y1 - y0, abs(y1), abs(y0)) planes.append( Part.makePlane(4 * rX, 4 * rY, Base.Vector(-2 * rX, -2 * rY, z), Base.Vector(0, 0, 1))) # Division are performed at x axis dx = (x1 - x0) / (nS - 1.0) for i in range(0, nS): section = [] x = x0 + i * dx xSection.append(x) percen = i * 100 / (nS - 1) FreeCAD.Console.PrintMessage('%d%%\n' % (percen)) # Slice the surface to get curves wires = shape.slice(Vector(1.0, 0.0, 0.0), x) if not wires: if (i != 0) or (i != nS - 1): msg = 'Found empty section at x=%g\n' % (x) msg = Translator.translate(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( '\tPlease, ensure that this section is correct, or fix surfaces and create a new ship.\n' ) nPoints.append(0) continue # Desarrollate wires into edges list edges = [] for j in range(0, len(wires)): wire = wires[j].Edges for k in range(0, len(wire)): edges.append(wire[k]) # Slice curves to get points points = [] for k in range(0, nP): planePoints = [] for j in range(0, len(edges)): aux = self.lineFaceSection(edges[j], planes[k]) for l in range(0, len(aux)): planePoints.append(Vector(aux[l].X, aux[l].Y, aux[l].Z)) if not planePoints: # No section found, symmetry plane point will used planePoints.append(Vector(x, 0, z0 + k * dz)) # Get Y coordinates auxY = [] for l in range(0, len(planePoints)): auxY.append(planePoints[l].y) # Sort them auxY.sort() # And store for l in range(0, len(planePoints)): points.append( Vector(planePoints[l].x, auxY[l], planePoints[l].z)) # Store points section = points[:] nPoints.append(len(section)) for j in range(0, len(section)): mSections.append(section[j]) # Save data for i in range(1, len(nPoints)): nPoints[i] = nPoints[i] + nPoints[i - 1] self.obj.nPoints = nPoints[:] self.obj.xSection = xSection[:] self.obj.mSections = mSections[:] msg = '%d Discretization points performed\n' % (len(mSections)) msg = Translator.translate(msg) FreeCAD.Console.PrintMessage(msg)