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 update(self, surf, direction, uv): """ Update the 3D view printing curve. @param self Auto call object. @param surf Surf where get the curve. @param direction 0 if u direction, 1 if v. @param uv Curve uv index, between 0 and 1. @return Curve from object (as Part::Feature). """ # Errors if not surf: return None # Get curve if direction == 0: curve = self.getU(surf, uv) elif direction == 1: curve = self.getV(surf, uv) else: return None # Draw at 3D view self.clean() Part.show(curve.toShape()) objs = FreeCAD.ActiveDocument.Objects self.obj = objs[len(objs)-1] self.obj.Label = 'surfISOCurve' return self.obj
def mainFrameCoeff(ship, draft): """ Calculate main frame coefficient. @param ship Selected ship instance @param draft Draft. @return Main frame coefficient """ cm = 0.0 maxY = 0.0 minY = 0.0 # We will take a duplicate of ship shape in order to place it shape = ship.Shape.copy() shape.translate(Vector(0.0,0.0,-draft)) x = 0.0 area = 0.0 # Now we need to know the x range of values bbox = shape.BoundBox xmin = bbox.XMin xmax = bbox.XMax # Create the box L = xmax - xmin B = bbox.YMax - bbox.YMin p = Vector(-1.5*L, -1.5*B, bbox.ZMin - 1.0) box = Part.makeBox(1.5*L + x, 3.0*B, - bbox.ZMin + 1.0, p) # Compute common part with ship for s in shape.Solids: # Get solids intersection try: common = box.common(s) except: continue if common.Volume == 0.0: continue # Recompute object adding it to the scene, when we have # computed desired data we can remove it. try: Part.show(common) except: continue # Divide by faces and compute only section placed ones faces = common.Faces for f in faces: faceBounds = f.BoundBox # Orientation filter if faceBounds.XMax - faceBounds.XMin > 0.00001: continue # Place filter if abs(faceBounds.XMax - x) > 0.00001: continue # Valid face, compute area area = area + f.Area maxY = max(maxY, faceBounds.YMax) minY = max(minY, faceBounds.YMin) # Destroy last object generated App.ActiveDocument.removeObject(App.ActiveDocument.Objects[-1].Name) dy = maxY - minY if dy*draft > 0.0: cm = area / (dy*draft) return cm
def buildObjs(self): """ Builds objects to show. """ Part.show(self.U) objs = FreeCAD.ActiveDocument.Objects self.objU = objs[len(objs)-1] Part.show(self.V) objs = FreeCAD.ActiveDocument.Objects self.objV = objs[len(objs)-1]
def update(self, L, B, T): """ Update the 3D view printing annotations. @param L Ship length. @param B Ship beam. @param T Ship draft. """ # Destroy all previous entities self.clean() # Draw base line xStart = -0.6 * L xEnd = 0.6 * L baseLine = Part.makeLine((xStart, 0, 0), (xEnd, 0, 0)) Part.show(baseLine) objs = FreeCAD.ActiveDocument.Objects self.baseLine = objs[len(objs) - 1] self.baseLine.Label = 'BaseLine' self.baseLineLabel = DrawText('BaseLineText', str(Translator.translate('Base line')), Base.Vector(xEnd, 0, 0)) # Draw free surface fsLine = Part.makeLine((xStart, 0, T), (xEnd, 0, T)) Part.show(fsLine) objs = FreeCAD.ActiveDocument.Objects self.fsLine = objs[len(objs) - 1] self.fsLine.Label = 'FreeSurface' self.fsLineLabel = DrawText('FSText', str(Translator.translate('Free surface')), Base.Vector(xEnd, 0, T)) # Draw forward perpendicular zStart = -0.1 * T zEnd = 1.1 * T fpLine = Part.makeLine((0.5 * L, 0, zStart), (0.5 * L, 0, zEnd)) Part.show(fpLine) objs = FreeCAD.ActiveDocument.Objects self.fpLine = objs[len(objs) - 1] self.fpLine.Label = 'ForwardPerpendicular' self.fpLineLabel = DrawText( 'FPText', str(Translator.translate('Forward perpendicular')), Base.Vector(0.5 * L, 0, zEnd)) # Draw after perpendicular apLine = Part.makeLine((-0.5 * L, 0, zStart), (-0.5 * L, 0, zEnd)) Part.show(apLine) objs = FreeCAD.ActiveDocument.Objects self.apLine = objs[len(objs) - 1] self.apLine.Label = 'AfterPerpendicular' self.apLineLabel = DrawText( 'APText', str(Translator.translate('After perpendicular')), Base.Vector(-0.5 * L, 0, zEnd)) # Draw amin frame amLine = Part.makeLine((0, -0.5 * B, zStart), (0, -0.5 * B, zEnd)) Part.show(amLine) objs = FreeCAD.ActiveDocument.Objects self.amLine = objs[len(objs) - 1] self.amLine.Label = 'AminFrame' self.amLineLabel = DrawText('AMText', str(Translator.translate('Amin frame')), Base.Vector(0, -0.5 * B, zEnd))
def update(self, names, pos): """ Update the 3D view printing annotations. @param names Weight names. @param pos Weight positions (FreeCAD::Base::Vector). """ # Destroy all previous entities self.clean() for i in range(0, len(names)): # Draw gravity line line = Part.makeLine((pos[i].x, pos[i].y, pos[i].z), (pos[i].x, pos[i].y, pos[i].z - 9.81)) Part.show(line) objs = FreeCAD.ActiveDocument.Objects self.objects.append(objs[-1]) objs[-1].Label = names[i] + 'Line' # Draw circles circle = Part.makeCircle(0.5, pos[i], Base.Vector(1.0, 0.0, 0.0)) Part.show(circle) objs = FreeCAD.ActiveDocument.Objects self.objects.append(objs[-1]) objs[-1].Label = names[i] + 'CircleX' circle = Part.makeCircle(0.5, pos[i], Base.Vector(0.0, 1.0, 0.0)) Part.show(circle) objs = FreeCAD.ActiveDocument.Objects self.objects.append(objs[-1]) objs[-1].Label = names[i] + 'CircleY' circle = Part.makeCircle(0.5, pos[i], Base.Vector(0.0, 0.0, 1.0)) Part.show(circle) objs = FreeCAD.ActiveDocument.Objects self.objects.append(objs[-1]) objs[-1].Label = names[i] + 'CircleZ' # Draw annotation self.objects.append( DrawText(names[i] + 'Text', names[i], Base.Vector(pos[i].x + 1.0, pos[i].y, pos[i].z)))
def update(self, names, pos): """ Update the 3D view printing annotations. @param names Weight names. @param pos Weight positions (FreeCAD::Base::Vector). """ # Destroy all previous entities self.clean() for i in range(0, len(names)): # Draw gravity line line = Part.makeLine((pos[i].x,pos[i].y,pos[i].z),(pos[i].x,pos[i].y,pos[i].z - 9.81)) Part.show(line) objs = FreeCAD.ActiveDocument.Objects self.objects.append(objs[-1]) objs[-1].Label = names[i] + 'Line' # Draw circles circle = Part.makeCircle(0.5, pos[i], Base.Vector(1.0,0.0,0.0)) Part.show(circle) objs = FreeCAD.ActiveDocument.Objects self.objects.append(objs[-1]) objs[-1].Label = names[i] + 'CircleX' circle = Part.makeCircle(0.5, pos[i], Base.Vector(0.0,1.0,0.0)) Part.show(circle) objs = FreeCAD.ActiveDocument.Objects self.objects.append(objs[-1]) objs[-1].Label = names[i] + 'CircleY' circle = Part.makeCircle(0.5, pos[i], Base.Vector(0.0,0.0,1.0)) Part.show(circle) objs = FreeCAD.ActiveDocument.Objects self.objects.append(objs[-1]) objs[-1].Label = names[i] + 'CircleZ' # Draw annotation self.objects.append(DrawText(names[i] + 'Text', names[i], Base.Vector(pos[i].x+1.0,pos[i].y,pos[i].z)))
def load(): """ Loads the tool. Getting the border don't require any option, so can be executed directly without any task panel. """ edges = Geometry.getBorders() if not edges: wrn = Translator.translate("Can't get any edge from selected objects") FreeCAD.Console.PrintWarning(wrn) return obj = edges[0] for i in range(0, len(edges)): obj = obj.oldFuse(edges[i]) Part.show(obj) objs = FreeCAD.ActiveDocument.Objects obj = objs[len(objs) - 1] obj.Label = 'Border'
def load(): """ Loads the tool. Getting the border don't require any option, so can be executed directly without any task panel. """ edges = Geometry.getBorders() if not edges: wrn = Translator.translate("Can't get any edge from selected objects") FreeCAD.Console.PrintWarning(wrn) return obj = edges[0] for i in range(0,len(edges)): obj = obj.oldFuse(edges[i]) Part.show(obj) objs = FreeCAD.ActiveDocument.Objects obj = objs[len(objs)-1] obj.Label = 'Border'
def update(self, L, B, T): """ Update the 3D view printing annotations. @param L Ship length. @param B Ship beam. @param T Ship draft. """ # Destroy all previous entities self.clean() # Draw base line xStart = -0.6*L; xEnd = 0.6*L; baseLine = Part.makeLine((xStart,0,0),(xEnd,0,0)) Part.show(baseLine) objs = FreeCAD.ActiveDocument.Objects self.baseLine = objs[len(objs)-1] self.baseLine.Label = 'BaseLine' self.baseLineLabel = DrawText('BaseLineText', str(Translator.translate('Base line')), Base.Vector(xEnd,0,0)) # Draw free surface fsLine = Part.makeLine((xStart,0,T),(xEnd,0,T)) Part.show(fsLine) objs = FreeCAD.ActiveDocument.Objects self.fsLine = objs[len(objs)-1] self.fsLine.Label = 'FreeSurface' self.fsLineLabel = DrawText('FSText', str(Translator.translate('Free surface')), Base.Vector(xEnd,0,T)) # Draw forward perpendicular zStart = -0.1*T zEnd = 1.1*T fpLine = Part.makeLine((0.5*L,0,zStart),(0.5*L,0,zEnd)) Part.show(fpLine) objs = FreeCAD.ActiveDocument.Objects self.fpLine = objs[len(objs)-1] self.fpLine.Label = 'ForwardPerpendicular' self.fpLineLabel = DrawText('FPText', str(Translator.translate('Forward perpendicular')), Base.Vector(0.5*L,0,zEnd)) # Draw after perpendicular apLine = Part.makeLine((-0.5*L,0,zStart),(-0.5*L,0,zEnd)) Part.show(apLine) objs = FreeCAD.ActiveDocument.Objects self.apLine = objs[len(objs)-1] self.apLine.Label = 'AfterPerpendicular' self.apLineLabel = DrawText('APText', str(Translator.translate('After perpendicular')), Base.Vector(-0.5*L,0,zEnd)) # Draw amin frame amLine = Part.makeLine((0,-0.5*B,zStart),(0,-0.5*B,zEnd)) Part.show(amLine) objs = FreeCAD.ActiveDocument.Objects self.amLine = objs[len(objs)-1] self.amLine.Label = 'AminFrame' self.amLineLabel = DrawText('AMText', str(Translator.translate('Amin frame')), Base.Vector(0,-0.5*B,zEnd))
def update(self, surf, direction, r): """ Update the 3D view printing curve. @param surf Surf where get the curve. @param direction Slice plane normal vector. @param r Absolute position at Slice plane normal direction. @return Curve from object (as Part::Feature). """ # Errors if not surf: return None # Get curve curve = self.getSlice(surf, direction, r) # Draw at 3D view self.clean() self.objs = [] for i in range(0,len(curve)): for j in range(0,len(curve[i])): Part.show(curve[i][j]) objs = FreeCAD.ActiveDocument.Objects objs[len(objs)-1].Label = 'surfSliceCurve' self.objs.append(objs[len(objs)-1]) return self.objs
def update(self, surf, direction, r): """ Update the 3D view printing curve. @param surf Surf where get the curve. @param direction Slice plane normal vector. @param r Absolute position at Slice plane normal direction. @return Curve from object (as Part::Feature). """ # Errors if not surf: return None # Get curve curve = self.getSlice(surf, direction, r) # Draw at 3D view self.clean() self.objs = [] for i in range(0, len(curve)): for j in range(0, len(curve[i])): Part.show(curve[i][j]) objs = FreeCAD.ActiveDocument.Objects objs[len(objs) - 1].Label = 'surfSliceCurve' self.objs.append(objs[len(objs) - 1]) return self.objs
def update(self, L, B, T, sectionsL, sectionsB, sectionsT, shape): """ Update the 3D view printing annotations. @param L Ship Lpp. @param B Ship beam. @param T Ship draft. @param sectionsL Transversal sections. @param sectionsB Longitudinal sections. @param sectionsT Water lines. @param shape Ship surfaces shell @return Sections object. None if errors happens. """ FreeCAD.Console.PrintMessage(Translator.translate('Computing sections...\n')) # Destroy all previous entities self.clean() # Receive data nL = len(sectionsL) nB = len(sectionsB) nT = len(sectionsT) if not (nL or nB or nT): return None # Found sections sections = [] for i in range(0,nL): pos = sectionsL[i] # Cut ship section = shape.slice(Vector(1.0,0.0,0.0), pos) for j in range(0,len(section)): edges = section[j].Edges # We have 3 cases, # * when section is before midship, then only starboard section will be considered # * When section is midship, then all section must be preserved # * When section is after midship, then only board will be considered if pos > 0.01: # Look for edges at the wrong side and delete it for k in range(len(edges)-1,-1,-1): edge = edges[k] bbox = edge.BoundBox if bbox.YMin < -0.001: del edges[k] elif pos < -0.01: # Look for edges at the wrong side and delete it for k in range(len(edges)-1,-1,-1): edge = edges[k] bbox = edge.BoundBox if bbox.YMax > 0.001: del edges[k] sections.extend(edges) for i in range(0,nB): pos = sectionsB[i] section = shape.slice(Vector(0.0,1.0,0.0), pos) for j in range(0,len(section)): edges = section[j].Edges # Longitudinal sections will preserve board and starboard ever. Since we take from one side, # we nned to mirror it. section[j] = section[j].mirror(Vector(0.0, 0.0, 0.0),Vector(0.0, 1.0, 0.0)) edges2 = section[j].Edges sections.extend(edges) sections.extend(edges2) for i in range(0,nT): pos = sectionsT[i] section = shape.slice(Vector(0.0,0.0,1.0), pos) for j in range(0,len(section)): edges = section[j].Edges # We have 3 cases, # * when section is below draft, then only board section will be considered # * When section is draft, then all section must be preserved # * When section is above draft, then only starboard will be considered if pos > T + 0.01: # Look for edges at the wrong side and delete it for k in range(len(edges)-1,-1,-1): edge = edges[k] bbox = edge.BoundBox if bbox.YMax > 0.001: del edges[k] elif pos < T - 0.01: # Look for edges at the wrong side and delete it for k in range(len(edges)-1,-1,-1): edge = edges[k] bbox = edge.BoundBox if bbox.YMin < -0.001: del edges[k] sections.extend(edges) # Convert all BSplines into a shape if not sections: msg = Translator.translate('Any valid ship section found') FreeCAD.Console.PrintWarning(msg) return obj = sections[0] for i in range(1,len(sections)): obj = obj.oldFuse(sections[i]) # Only group the edges, don't try to build more complex entities # Create the representable object Part.show(obj) objs = FreeCAD.ActiveDocument.Objects self.obj = objs[len(objs)-1] self.obj.Label = 'OutlineDraw' return self.obj
disco2.translate(Base.Vector(190,75,20)) disco3 = modeldisco3.cut(furo3) disco3.translate(Base.Vector(310,75,20)) disco4 = modeldisco4.cut(furo4) disco4.translate(Base.Vector(310,75,40)) disco5 = modeldisco5.cut(furo5) disco5.translate(Base.Vector(190,75,40)) disco6 = modeldisco6.cut(furo6) disco6.translate(Base.Vector(70,75,40)) #Mostrando os objetos Part.show(base) Part.show(cilindro1) Part.show(cilindro2) Part.show(cilindro3) Part.show(disco1) Part.show(disco2) Part.show(disco3) Part.show(disco4) Part.show(disco5) Part.show(disco6) #Criação do documento doc = FreeCAD.newDocument('Torre de Hanoi') docBase = doc.addObject("Part::Feature", 'Base') docBase.Shape = base docCil1 = doc.addObject("Part::Feature", 'Cilindro 1')
def Plot(scale, sections, shape): """ Creates the outline draw. @param scale Plane scale (format 1:scale) @param sections Sections computed. @param shape Ship surfaces shell @return plotted object (DocumentObject) """ msg = Translator.translate('Performing plot (Scale 1:%d)...\n' % (scale)) FreeCAD.Console.PrintMessage(msg) scale = 1000.0 / scale # Take positions bounds = [0.0, 0.0, 0.0] bbox = shape.BoundBox bounds[0] = bbox.XLength bounds[1] = bbox.YLength bounds[2] = bbox.ZLength xTot = scale*bounds[1] + 32.0 + scale*bounds[0] yTot = scale*bounds[2] + 32.0 + scale*bounds[1] xMid = 210.0 yMid = 185.0 x0 = xMid - 0.5*xTot y0 = 297.0 - yMid - 0.5*yTot # 297 = A3_width # Get border edges = Geometry.getEdges([shape]) border = edges[0] for i in range(0,len(edges)): border = border.oldFuse(edges[i]) # Only group objects, don't try to build more complex entities border = border.oldFuse(edges[i].mirror(Vector(0.0, 0.0, 0.0),Vector(0.0, 1.0, 0.0))) # Fuse sections & borders # obj = sections.oldFuse(border) obj = border.oldFuse(sections) # Send to 3D view Part.show(obj) objs = FreeCAD.ActiveDocument.Objects obj = objs[len(objs)-1] # Create a new plane FreeCAD.ActiveDocument.addObject('Drawing::FeaturePage','OutlineDrawPlot') FreeCAD.ActiveDocument.OutlineDrawPlot.Template = FreeCAD.getResourceDir()+'Mod/Drawing/Templates/A3_Landscape.svg' # Side view FreeCAD.ActiveDocument.addObject('Drawing::FeatureViewPart','OutlineDrawSideView') FreeCAD.ActiveDocument.OutlineDrawSideView.Source = obj FreeCAD.ActiveDocument.OutlineDrawSideView.Direction = (1.0,0.0,0.0) FreeCAD.ActiveDocument.OutlineDrawSideView.Rotation = -90.0 FreeCAD.ActiveDocument.OutlineDrawSideView.Scale = scale FreeCAD.ActiveDocument.OutlineDrawSideView.X = 420.0 - x0 - 0.5*scale*bounds[1] # 420 = A3_height FreeCAD.ActiveDocument.OutlineDrawSideView.Y = y0 + 0.5*scale*bounds[2] FreeCAD.ActiveDocument.OutlineDrawPlot.addObject(FreeCAD.ActiveDocument.OutlineDrawSideView) # Front view FreeCAD.ActiveDocument.addObject('Drawing::FeatureViewPart','OutlineDrawFrontView') FreeCAD.ActiveDocument.OutlineDrawFrontView.Source = obj FreeCAD.ActiveDocument.OutlineDrawFrontView.Direction = (0.0,1.0,0.0) FreeCAD.ActiveDocument.OutlineDrawFrontView.Rotation = -90.0 FreeCAD.ActiveDocument.OutlineDrawFrontView.Scale = scale FreeCAD.ActiveDocument.OutlineDrawFrontView.X = 420.0 - x0 - scale*bounds[1] - 32 - 0.5*scale*bounds[0] FreeCAD.ActiveDocument.OutlineDrawFrontView.Y = y0 + 0.5*scale*bounds[2] FreeCAD.ActiveDocument.OutlineDrawPlot.addObject(FreeCAD.ActiveDocument.OutlineDrawFrontView) # Up view FreeCAD.ActiveDocument.addObject('Drawing::FeatureViewPart','OutlineDrawUpView') FreeCAD.ActiveDocument.OutlineDrawUpView.Source = obj FreeCAD.ActiveDocument.OutlineDrawUpView.Direction = (0.0,0.0,1.0) FreeCAD.ActiveDocument.OutlineDrawUpView.Scale = scale FreeCAD.ActiveDocument.OutlineDrawUpView.X = 420.0 - x0 - scale*bounds[1] - 32 - 0.5*scale*bounds[0] FreeCAD.ActiveDocument.OutlineDrawUpView.Y = y0 + scale*bounds[2] + 32 FreeCAD.ActiveDocument.OutlineDrawPlot.addObject(FreeCAD.ActiveDocument.OutlineDrawUpView) FreeCAD.ActiveDocument.recompute() return obj
def areas(ship, draft, roll=0.0, trim=0.0, yaw=0.0, n=30): """ Compute ship transversal areas. @param ship Ship instance. @param draft Ship draft. @param roll Ship roll angle. @param trim Ship trim angle. @param yaw Ship yaw angle. Ussually you don't want to use this value. @param n Number of sections to perform. @return Transversal areas (every area value is composed by x coordinate and computed area) """ if n < 2: return [] # We will take a duplicate of ship shape in order to place it shape = ship.Shape.copy() shape.translate(Vector(0.0,0.0,-draft)) # Rotations composition is Roll->Trim->Yaw shape.rotate(Vector(0.0,0.0,0.0), Vector(1.0,0.0,0.0), roll) shape.rotate(Vector(0.0,0.0,0.0), Vector(0.0,-1.0,0.0), trim) shape.rotate(Vector(0.0,0.0,0.0), Vector(0.0,0.0,1.0), yaw) # Now we need to know the x range of values bbox = shape.BoundBox xmin = bbox.XMin xmax = bbox.XMax dx = (xmax - xmin) / (n-1.0) # First area is equal to zero. areas = [[xmin, 0.0]] # Since we need face entities, in order to compute sections we will # create boxes with front face at transversal area position, # compute solid common, divide by faces, and preserve only desired # ones. App.Console.PrintMessage("Computing transversal areas...\n") App.Console.PrintMessage("Some Inventor representation errors can be shown, ignore it please.\n") for i in range(1,n-1): App.Console.PrintMessage("%d / %d\n" % (i, n-2)) x = xmin + i*dx area = 0.0 # Create the box L = xmax - xmin B = bbox.YMax - bbox.YMin p = Vector(-1.5*L, -1.5*B, bbox.ZMin - 1.0) box = Part.makeBox(1.5*L + x, 3.0*B, - bbox.ZMin + 1.0, p) # Compute common part with ship for s in shape.Solids: # Get solids intersection try: common = box.common(s) except: continue if common.Volume == 0.0: continue # Recompute object adding it to the scene, when we have # computed desired data we can remove it. try: Part.show(common) except: continue # Divide by faces and compute only section placed ones faces = common.Faces for f in faces: faceBounds = f.BoundBox # Orientation filter if faceBounds.XMax - faceBounds.XMin > 0.00001: continue # Place filter if abs(faceBounds.XMax - x) > 0.00001: continue # Valid face, compute area area = area + f.Area # Destroy last object generated App.ActiveDocument.removeObject(App.ActiveDocument.Objects[-1].Name) # Append transversal area areas.append([x, area]) # Last area is equal to zero areas.append([xmax, 0.0]) App.Console.PrintMessage("Done!\n") return areas
def update(self, L, B, T, sectionsL, sectionsB, sectionsT, shape): """ Update the 3D view printing annotations. @param L Ship Lpp. @param B Ship beam. @param T Ship draft. @param sectionsL Transversal sections. @param sectionsB Longitudinal sections. @param sectionsT Water lines. @param shape Ship surfaces shell @return Sections object. None if errors happens. """ FreeCAD.Console.PrintMessage(Translator.translate('Computing sections...\n')) # Destroy all previous entities self.clean() # Receive data nL = len(sectionsL) nB = len(sectionsB) nT = len(sectionsT) if not (nL or nB or nT): return None # Found sections sections = [] for i in range(0,nL): pos = sectionsL[i] section = shape.slice(Vector(1.0,0.0,0.0), pos) for j in range(0,len(section)): edges = section[j].Edges if pos == 0.0: section[j] = section[j].mirror(Vector(0.0, 0.0, 0.0),Vector(0.0, 1.0, 0.0)) edges2 = section[j].Edges for k in range(0,len(edges2)): edges.append(edges2[k]) elif pos < 0: section[j] = section[j].mirror(Vector(0.0, 0.0, 0.0),Vector(0.0, 1.0, 0.0)) edges = section[j].Edges for k in range(0,len(edges)): sections.append(edges[k]) for i in range(0,nB): pos = sectionsB[i] section = shape.slice(Vector(0.0,1.0,0.0), pos) for j in range(0,len(section)): edges = section[j].Edges section[j] = section[j].mirror(Vector(0.0, 0.0, 0.0),Vector(0.0, 1.0, 0.0)) edges2 = section[j].Edges for k in range(0,len(edges2)): edges.append(edges2[k]) for k in range(0,len(edges)): sections.append(edges[k]) for i in range(0,nT): pos = sectionsT[i] section = shape.slice(Vector(0.0,0.0,1.0), pos) for j in range(0,len(section)): edges = section[j].Edges if pos == T: section[j] = section[j].mirror(Vector(0.0, 0.0, 0.0),Vector(0.0, 1.0, 0.0)) edges2 = section[j].Edges for k in range(0,len(edges2)): edges.append(edges2[k]) elif pos > T: section[j] = section[j].mirror(Vector(0.0, 0.0, 0.0),Vector(0.0, 1.0, 0.0)) edges = section[j].Edges for k in range(0,len(edges)): sections.append(edges[k]) # Convert all BSplines into a shape if not sections: msg = Translator.translate('Any valid ship section found\n') FreeCAD.Console.PrintWarning(msg) return obj = sections[0] for i in range(1,len(sections)): obj = obj.oldFuse(sections[i]) # Only group the edges, don't try to build more complex entities # Create the representable object Part.show(obj) objs = FreeCAD.ActiveDocument.Objects self.obj = objs[len(objs)-1] self.obj.Label = 'OutlineDraw' return self.obj
def Plot(scale, sections, shape): """ Creates the outline draw. @param scale Plane scale (format 1:scale) @param sections Sections computed. @param shape Ship surfaces shell @return plotted object (DocumentObject) """ msg = Translator.translate('Performing plot (Scale 1:%d)...\n' % (scale)) FreeCAD.Console.PrintMessage(msg) scale = 1000.0 / scale # Take positions bounds = [0.0, 0.0, 0.0] bbox = shape.BoundBox bounds[0] = bbox.XLength bounds[1] = bbox.YLength bounds[2] = bbox.ZLength xTot = scale * bounds[1] + 32.0 + scale * bounds[0] yTot = scale * bounds[2] + 32.0 + scale * bounds[1] xMid = 210.0 yMid = 185.0 x0 = xMid - 0.5 * xTot y0 = 297.0 - yMid - 0.5 * yTot # 297 = A3_width # Get border edges = Geometry.getEdges([shape]) border = edges[0] for i in range(0, len(edges)): border = border.oldFuse( edges[i] ) # Only group objects, don't try to build more complex entities border = border.oldFuse(edges[i].mirror(Vector(0.0, 0.0, 0.0), Vector(0.0, 1.0, 0.0))) # Fuse sections & borders # obj = sections.oldFuse(border) obj = border.oldFuse(sections) # Send to 3D view Part.show(obj) objs = FreeCAD.ActiveDocument.Objects obj = objs[len(objs) - 1] # Create a new plane FreeCAD.ActiveDocument.addObject('Drawing::FeaturePage', 'OutlineDrawPlot') FreeCAD.ActiveDocument.OutlineDrawPlot.Template = FreeCAD.getResourceDir( ) + 'Mod/Drawing/Templates/A3_Landscape.svg' # Side view FreeCAD.ActiveDocument.addObject('Drawing::FeatureViewPart', 'OutlineDrawSideView') FreeCAD.ActiveDocument.OutlineDrawSideView.Source = obj FreeCAD.ActiveDocument.OutlineDrawSideView.Direction = (1.0, 0.0, 0.0) FreeCAD.ActiveDocument.OutlineDrawSideView.Rotation = -90.0 FreeCAD.ActiveDocument.OutlineDrawSideView.Scale = scale FreeCAD.ActiveDocument.OutlineDrawSideView.X = 420.0 - x0 - 0.5 * scale * bounds[ 1] # 420 = A3_height FreeCAD.ActiveDocument.OutlineDrawSideView.Y = y0 + 0.5 * scale * bounds[2] FreeCAD.ActiveDocument.OutlineDrawPlot.addObject( FreeCAD.ActiveDocument.OutlineDrawSideView) # Front view FreeCAD.ActiveDocument.addObject('Drawing::FeatureViewPart', 'OutlineDrawFrontView') FreeCAD.ActiveDocument.OutlineDrawFrontView.Source = obj FreeCAD.ActiveDocument.OutlineDrawFrontView.Direction = (0.0, 1.0, 0.0) FreeCAD.ActiveDocument.OutlineDrawFrontView.Rotation = -90.0 FreeCAD.ActiveDocument.OutlineDrawFrontView.Scale = scale FreeCAD.ActiveDocument.OutlineDrawFrontView.X = 420.0 - x0 - scale * bounds[ 1] - 32 - 0.5 * scale * bounds[0] FreeCAD.ActiveDocument.OutlineDrawFrontView.Y = y0 + 0.5 * scale * bounds[2] FreeCAD.ActiveDocument.OutlineDrawPlot.addObject( FreeCAD.ActiveDocument.OutlineDrawFrontView) # Up view FreeCAD.ActiveDocument.addObject('Drawing::FeatureViewPart', 'OutlineDrawUpView') FreeCAD.ActiveDocument.OutlineDrawUpView.Source = obj FreeCAD.ActiveDocument.OutlineDrawUpView.Direction = (0.0, 0.0, 1.0) FreeCAD.ActiveDocument.OutlineDrawUpView.Scale = scale FreeCAD.ActiveDocument.OutlineDrawUpView.X = 420.0 - x0 - scale * bounds[ 1] - 32 - 0.5 * scale * bounds[0] FreeCAD.ActiveDocument.OutlineDrawUpView.Y = y0 + scale * bounds[2] + 32 FreeCAD.ActiveDocument.OutlineDrawPlot.addObject( FreeCAD.ActiveDocument.OutlineDrawUpView) FreeCAD.ActiveDocument.recompute() return obj
def update(self, L, B, T, sectionsL, sectionsB, sectionsT, shape): """ Update the 3D view printing annotations. @param L Ship Lpp. @param B Ship beam. @param T Ship draft. @param sectionsL Transversal sections. @param sectionsB Longitudinal sections. @param sectionsT Water lines. @param shape Ship surfaces shell @return Sections object. None if errors happens. """ FreeCAD.Console.PrintMessage( Translator.translate('Computing sections...\n')) # Destroy all previous entities self.clean() # Receive data nL = len(sectionsL) nB = len(sectionsB) nT = len(sectionsT) if not (nL or nB or nT): return None # Found sections sections = [] for i in range(0, nL): pos = sectionsL[i] section = shape.slice(Vector(1.0, 0.0, 0.0), pos) for j in range(0, len(section)): edges = section[j].Edges if pos == 0.0: section[j] = section[j].mirror(Vector(0.0, 0.0, 0.0), Vector(0.0, 1.0, 0.0)) edges2 = section[j].Edges for k in range(0, len(edges2)): edges.append(edges2[k]) elif pos < 0: section[j] = section[j].mirror(Vector(0.0, 0.0, 0.0), Vector(0.0, 1.0, 0.0)) edges = section[j].Edges for k in range(0, len(edges)): sections.append(edges[k]) for i in range(0, nB): pos = sectionsB[i] section = shape.slice(Vector(0.0, 1.0, 0.0), pos) for j in range(0, len(section)): edges = section[j].Edges section[j] = section[j].mirror(Vector(0.0, 0.0, 0.0), Vector(0.0, 1.0, 0.0)) edges2 = section[j].Edges for k in range(0, len(edges2)): edges.append(edges2[k]) for k in range(0, len(edges)): sections.append(edges[k]) for i in range(0, nT): pos = sectionsT[i] section = shape.slice(Vector(0.0, 0.0, 1.0), pos) for j in range(0, len(section)): edges = section[j].Edges if pos == T: section[j] = section[j].mirror(Vector(0.0, 0.0, 0.0), Vector(0.0, 1.0, 0.0)) edges2 = section[j].Edges for k in range(0, len(edges2)): edges.append(edges2[k]) elif pos > T: section[j] = section[j].mirror(Vector(0.0, 0.0, 0.0), Vector(0.0, 1.0, 0.0)) edges = section[j].Edges for k in range(0, len(edges)): sections.append(edges[k]) # Convert all BSplines into a shape if not sections: msg = Translator.translate('Any valid ship section found\n') FreeCAD.Console.PrintWarning(msg) return obj = sections[0] for i in range(1, len(sections)): obj = obj.oldFuse( sections[i] ) # Only group the edges, don't try to build more complex entities # Create the representable object Part.show(obj) objs = FreeCAD.ActiveDocument.Objects self.obj = objs[len(objs) - 1] self.obj.Label = 'OutlineDraw' return self.obj