Example #1
0
def simpleSurfBend(path=None,profile=None):
  'select the centerline and the O.D. and let it sweep'
  curva=FreeCAD.activeDocument().addObject("Part::Feature","CurvaSemplice")
  if path==None or profile==None:
    curva.Shape=Part.makeSweepSurface(*frameCmd.edges()[:2])
  elif path.ShapeType==profile.ShapeType=='Edge':
    curva.Shape=Part.makeSweepSurface(path,profile)
Example #2
0
 def execute(self, fp):
   if fp.BendAngle<180:
     if fp.thk>fp.OD/2:
       fp.thk=fp.OD/2
     fp.ID=fp.OD-2*fp.thk
     fp.Profile=str(fp.OD)+"x"+str(fp.thk)
     CenterOfBend=FreeCAD.Vector(fp.BendRadius,fp.BendRadius,0)
     ## make center-line ##
     R=Part.makeCircle(fp.BendRadius,CenterOfBend,FreeCAD.Vector(0,0,1),225-float(fp.BendAngle)/2,225+float(fp.BendAngle)/2)
     ## move the cl so that Placement.Base is the center of elbow ##
     from math import pi, cos, sqrt
     d=(fp.BendRadius*sqrt(2)-fp.BendRadius/cos(fp.BendAngle/180*pi/2))
     P=FreeCAD.Vector(-d*cos(pi/4),-d*cos(pi/4),0)
     R.translate(P)
     ## calculate Ports position ##
     fp.Ports=[R.valueAt(R.FirstParameter),R.valueAt(R.LastParameter)]
     ## make the shape of the elbow ##
     c=Part.makeCircle(fp.OD/2,fp.Ports[0],R.tangentAt(R.FirstParameter)*-1)
     b=Part.makeSweepSurface(R,c)
     p1=Part.Face(Part.Wire(c))
     p2=Part.Face(Part.Wire(Part.makeCircle(fp.OD/2,fp.Ports[1],R.tangentAt(R.LastParameter))))
     sol=Part.Solid(Part.Shell([b,p1,p2]))
     planeFaces=[f for f in sol.Faces if type(f.Surface)==Part.Plane]
     #elbow=sol.makeThickness(planeFaces,-fp.thk,1.e-3)
     #fp.Shape = elbow
     if fp.thk<fp.OD/2:
       fp.Shape=sol.makeThickness(planeFaces,-fp.thk,1.e-3)
     else:
       fp.Shape=sol
     super(Elbow,self).execute(fp) # perform common operations
Example #3
0
 def execute(self, fp):
   if fp.BendAngle<180:
     if fp.thk>fp.OD/2:
       fp.thk=fp.OD/2
     fp.ID=fp.OD-2*fp.thk
     fp.Profile=str(fp.OD)+"x"+str(fp.thk)
     CenterOfBend=FreeCAD.Vector(fp.BendRadius,fp.BendRadius,0)
     ## make center-line ##
     R=Part.makeCircle(fp.BendRadius,CenterOfBend,FreeCAD.Vector(0,0,1),225-float(fp.BendAngle)/2,225+float(fp.BendAngle)/2)
     ## move the cl so that Placement.Base is the center of elbow ##
     from math import pi, cos, sqrt
     d=(fp.BendRadius*sqrt(2)-fp.BendRadius/cos(fp.BendAngle/180*pi/2))
     P=FreeCAD.Vector(-d*cos(pi/4),-d*cos(pi/4),0)
     R.translate(P)
     ## calculate Ports position ##
     fp.Ports=[R.valueAt(R.FirstParameter),R.valueAt(R.LastParameter)]
     ## make the shape of the elbow ##
     c=Part.makeCircle(fp.OD/2,fp.Ports[0],R.tangentAt(R.FirstParameter)*-1)
     b=Part.makeSweepSurface(R,c)
     p1=Part.Face(Part.Wire(c))
     p2=Part.Face(Part.Wire(Part.makeCircle(fp.OD/2,fp.Ports[1],R.tangentAt(R.LastParameter))))
     sol=Part.Solid(Part.Shell([b,p1,p2]))
     planeFaces=[f for f in sol.Faces if type(f.Surface)==Part.Plane]
     #elbow=sol.makeThickness(planeFaces,-fp.thk,1.e-3)
     #fp.Shape = elbow
     if fp.thk<fp.OD/2:
       fp.Shape=sol.makeThickness(planeFaces,-fp.thk,1.e-3)
     else:
       fp.Shape=sol
     super(Elbow,self).execute(fp) # perform common operations
    def createBentCylinderDoesNotWork(obj, rCirc):
        """Create a cylinder of radius rCirc in x-y plane which is bent in the middle and is streight in the ends.

        The little streight part is necessary, because otherwise the part is not displayed
        correctly after performing a boolean operations. Thus we need some overlapping
        between bent part and the socket.

        :param group: Group where to add created objects.
        :param rCirc: Radius of the cylinder.

        See documentation picture elbow-cacluations.png
        """
        # Convert alpha to degree value
        dims = Elbow.extractDimensions(obj)

        aux = dims.calculateAuxiliararyPoints()

        alpha = float(dims.BendAngle.getValueAs("deg"))
        rBend = dims.M / 2.0

        # Put a base on the streight part.
        base = Part.makeCircle(rCirc, aux["p5"], aux["p5"])

        # Add trajectory
        line1 = Part.makeLine(aux["p5"], aux["p2"])
        arc = Part.makeCircle(
            rBend, aux["p3"], FreeCAD.Vector(0, 0, 1), 225 - alpha / 2, 225 + alpha / 2)
        line2 = Part.makeLine(aux["p4"], aux["p6"])

        trajectory = Part.Shape([line1, arc, line2])
        # Show trajectory for debugging.
        # W Part.Wire([line1, arc, line2])
        # Part.show(W)
        # Add a cap (circle, at the other end of the bent cylinder).
        cap = Part.makeCircle(rCirc, aux["p5"], aux["p5"])
        # Sweep the circle along the trajectory.
        sweep = Part.makeSweepSurface(trajectory, base)  # Does not work
        sweep = Part.makeSweepSurface(W, base)  # Does not work.
        # The sweep is only a 2D service consisting of walls only.
        # Add circles on both ends of this wall.
        end1 = Part.Face(Part.Wire(base))
        # Create other end.
        end2 = Part.Face(Part.Wire(cap))
        solid = Part.Solid(Part.Shell([end1, sweep, end2]))
        return solid
Example #5
0
    def execute(self, obj):
        self.Height = float(obj.Height)
        self.BaseRadius = float(obj.BaseRadius)
        self.MiddleRadius = float(obj.MiddleRadius)
        point1 = App.Vector(self.BaseRadius, 0, 0)
        point2 = App.Vector(self.MiddleRadius, 0, self.Height / 2)
        point3 = App.Vector(0, 0, self.Height)
        Result = None
        bsp = Part.BSplineCurve()
        bsp.buildFromPoles([point1, point2, point3])
        shp = bsp.toShape()
        circle = Part.makeCircle(self.BaseRadius, App.Vector(0, 0, 0),
                                 App.Vector(0, 0, 1))
        sweep = Part.makeSweepSurface(circle, shp)
        base = Part.Face(Part.Wire(circle))
        shell1 = Part.Shell([base, sweep])

        nResult = Part.makeSolid(shell1)
        Result = nResult.removeSplitter()
        obj.Shape = Result
Example #6
0
    def createBentCylinder(obj, rCirc):
        """Create a cylinder of radius rCirc in x-y plane which is bent in the middle.

        :param group: Group where to add created objects.
        :param rCirc: Radius of the cylinder.

        See documentation picture sweep-elbow-cacluations.png.
        """
        # Convert alpha to degree value
        dims = SweepElbow.extractDimensions(obj)

        aux = dims.calculateAuxiliararyPoints()

        alpha = float(dims.BendAngle.getValueAs("deg"))
        rBend = (aux["p3"] - aux["p5"]).Length

        # Put a base on the streight part.
        base = Part.makeCircle(rCirc, aux["p5"], aux["p5"])

        # Add trajectory
        trajectory = Part.makeCircle(rBend, aux["p3"], FreeCAD.Vector(0, 0, 1),
                                     225 - alpha / 2, 225 + alpha / 2)
        # Show trajectory for debugging.
        # W = W1.fuse([trajectory.Edges])
        # Part.Show(W)
        # Add a cap (circle, at the other end of the bent cylinder).
        cap = Part.makeCircle(rCirc, aux["p6"], aux["p6"])
        # Sweep the circle along the trajectory.
        sweep = Part.makeSweepSurface(trajectory, base)
        # The sweep is only a 2D service consisting of walls only.
        # Add circles on both ends of this wall.
        end1 = Part.Face(Part.Wire(base))
        # Create other end.
        end2 = Part.Face(Part.Wire(cap))
        solid = Part.Solid(Part.Shell([end1, sweep, end2]))
        return solid