def WrapFace(Face, Radius, axis, normal, zeroVert, cent, zeroVertNormal):
    #    circent = cent
    Edges = []
    for e in Face.Edges:
        #print(type(e.Curve))
        if isinstance(e.Curve, (Part.Circle, Part.ArcOfCircle)):
            #bspline = gg.Curve.toBSpline()
            poles = e.discretize(Number=50)
            bspline = Part.BSplineCurve()
            bspline.interpolate(poles)
            #bs = bspline.toShape()
            #Part.show(bs,"bspline")
            Edges.append(
                WrapBSpline(bspline, Radius, zeroVert, cent, axis,
                            zeroVertNormal))

        elif isinstance(e.Curve, Part.BSplineCurve):
            Edges.append(
                WrapBSpline(e.Curve, Radius, zeroVert, cent, axis,
                            zeroVertNormal))

        elif isinstance(e.Curve, Part.Line):
            sp = e.valueAt(e.FirstParameter)
            ep = e.valueAt(e.LastParameter)
            dist1 = abs(sp.distanceToPlane(cent, normal))
            dist2 = abs(ep.distanceToPlane(cent, normal))
            #print(dist1,dist2)
            linenormal = ep - sp
            mp = sp + linenormal / 2.0
            linenormal.normalize()
            #print(linenormal.dot(axis))
            #print(linenormal.dot(normal))
            if linenormal.dot(axis) == 0.0 and (dist2 - dist1) == 0.0:
                Point1 = getPointOnCylinder(zeroVert, sp, Radius, cent, axis,
                                            zeroVertNormal)
                Point2 = getPointOnCylinder(zeroVert, mp, Radius, cent, axis,
                                            zeroVertNormal)
                Point3 = getPointOnCylinder(zeroVert, ep, Radius, cent, axis,
                                            zeroVertNormal)
                arc = Part.Arc(Point1, Point2, Point3)
                Edges.append(arc.toShape())
            elif linenormal.dot(axis) == 1.0 or linenormal.dot(axis) == -1.0:
                Point1 = getPointOnCylinder(zeroVert, sp, Radius, cent, axis,
                                            zeroVertNormal)
                Point2 = getPointOnCylinder(zeroVert, ep, Radius, cent, axis,
                                            zeroVertNormal)
                #print([Point1,Point2])
                Edges.append(Part.makeLine(Point1, Point2))
            elif linenormal.dot(normal) == 1.0 or linenormal.dot(
                    normal) == -1.0:
                Point1 = getPointOnCylinder(zeroVert, sp, Radius, cent, axis,
                                            zeroVertNormal)
                Point2 = getPointOnCylinder(zeroVert, ep, Radius, cent, axis,
                                            zeroVertNormal)
                #print([Point1,Point2])
                Edges.append(Part.makeLine(Point1, Point2))
            else:
                poles = e.discretize(Number=50)
                #print(poles)
                bspline = Part.BSplineCurve()
                bspline.interpolate(poles, PeriodicFlag=False)
                #bs = bspline.toShape()
                #Part.show(bs,"bspline")
                #bspline = disgg.toBSpline()
                Edges.append(
                    WrapBSpline(bspline, Radius, zeroVert, cent, axis,
                                zeroVertNormal))
    return Edges
Example #2
0
 def onChanged(self, fp, prop):
     self.checkCurve(fp)
     if (prop == "Degree"):
         if fp.Degree > int(self.curve.Degree):
             if isinstance(self.curve,Part.BezierCurve):
                 self.curve.increase(fp.Degree)
             elif isinstance(self.curve,Part.BSplineCurve):
                 self.curve.increaseDegree(fp.Degree)
         elif fp.Degree < int(self.curve.Degree):
             pts = self.curve.discretize(Number = 100)
             bscurve = Part.BSplineCurve() #self.curve.approximateBSpline(0.1,12,fp.Degree,'C2')
             bscurve.approximate(Points = pts, DegMin = fp.Degree, DegMax = fp.Degree, Tolerance = 0.01)
             self.curve = bscurve
             fp.Degree = int(bscurve.Degree)
         fp.Poles = self.curve.getPoles()
         fp.Weights = self.curve.getWeights()
         if isinstance(self.curve,Part.BSplineCurve):
             fp.Knots = self.curve.getKnots()
             self.getKnotPoints(fp)
             fp.Mults = [int(i) for i in self.curve.getMultiplicities()]
         fp.Pole = fp.Pole
         fp.CurvePts = self.curve.discretize(100)
         debug("Spline : Degree changed to "+str(fp.Degree)+"\n")
     if prop == "Pole":
         if fp.Pole < 1:
             fp.Pole = 1
         elif fp.Pole > len(self.curve.getPoles()):
             fp.Pole = len(self.curve.getPoles())
         v = self.curve.getPole(fp.Pole)
         w = self.curve.getWeight(fp.Pole)
         fp.X = v.x
         fp.Y = v.y
         fp.Z = v.z
         fp.W = w
         #fp.Poles = self.curve.getPoles()
         #fp.Weights = self.curve.getWeights()
         #fp.touch()
         debug("Spline : Pole changed to "+str(fp.Pole)+"\n")
     if (prop == "X") | (prop == "Y") | (prop == "Z"):
         v = FreeCAD.Vector(fp.X,fp.Y,fp.Z)
         self.curve.setPole(fp.Pole,v)
         fp.Poles = self.curve.getPoles()
         debug("Spline : Coordinate changed\n")
     if (prop == "W"):
         #v = FreeCAD.Vector(fp.X,fp.Y,fp.Z)
         self.curve.setWeight(fp.Pole,fp.W)
         fp.Weights = self.curve.getWeights()
         debug("Spline : Weight changed\n")
     if (prop == "Poles"):
         #fp.Weights = self.curve.getWeights()
         debug("Spline : Poles changed\n")
     if (prop == "Weights"):
         #fp.Poles = self.curve.getPoles()
         debug("Spline : Weights changed\n")
     if (prop == "Knots"):
         if fp.Knots:
             self.getKnotPoints(fp)
         #fp.Mults = [int(i) for i in self.curve.getMultiplicities()]
         debug("Spline : Knots changed\n")
     if (prop == "Mults"):
         #fp.Knots = self.curve.getKnots()
         debug("Spline : Mults changed\n")
         oldMults = self.curve.getMultiplicities()
         if len(fp.Mults) == len(oldMults):
             for i in range(len(fp.Mults)):
                 if fp.Mults[i] > oldMults[i]:
                     self.curve.increaseMultiplicity(i+1,fp.Mults[i])
                 elif fp.Mults[i] < oldMults[i]:
                     self.curve.removeKnot(i+1, fp.Mults[i], 0.01) # add property tolerance here
         fp.Mults = [int(i) for i in self.curve.getMultiplicities()]
Example #3
0
    def execute(self, fp):
        m = fp.module.Value
        d = fp.diameter.Value
        t = fp.teeth
        h = fp.height

        clearance = fp.clearance
        head = fp.head
        alpha = fp.pressure_angle.Value
        beta = np.arctan(m * t / d)
        fp.beta = np.rad2deg(beta)
        beta = -(fp.reverse_pitch * 2 - 1) * (np.pi / 2 - beta)

        r_1 = (d - (2 + 2 * clearance) * m) / 2
        r_2 = (d + (2 + 2 * head) * m) / 2
        z_a = (2 + head + clearance) * m * np.tan(np.deg2rad(alpha))
        z_b = (m * np.pi - 4 * m * np.tan(np.deg2rad(alpha))) / 2
        z_0 = clearance * m * np.tan(np.deg2rad(alpha))
        z_1 = z_b - z_0
        z_2 = z_1 + z_a
        z_3 = z_2 + z_b - 2 * head * m * np.tan(np.deg2rad(alpha))
        z_4 = z_3 + z_a

        def helical_projection(r, z):
            phi = 2 * z / m / t
            x = r * np.cos(phi)
            y = r * np.sin(phi)
            z = 0 * y
            return np.array([x, y, z]).T

        # create a circle from phi=0 to phi_1 with r_1
        phi_0 = 2 * z_0 / m / t
        phi_1 = 2 * z_1 / m / t
        c1 = Part.makeCircle(r_1, App.Vector(0, 0, 0), App.Vector(0, 0, 1),
                             np.rad2deg(phi_0), np.rad2deg(phi_1))

        # create first bspline
        z_values = np.linspace(z_1, z_2, 10)
        r_values = np.linspace(r_1, r_2, 10)
        points = helical_projection(r_values, z_values)
        bsp1 = Part.BSplineCurve()
        bsp1.interpolate(list(map(fcvec, points)))
        bsp1 = bsp1.toShape()

        # create circle from phi_2 to phi_3
        phi_2 = 2 * z_2 / m / t
        phi_3 = 2 * z_3 / m / t
        c2 = Part.makeCircle(r_2, App.Vector(0, 0, 0), App.Vector(0, 0, 1),
                             np.rad2deg(phi_2), np.rad2deg(phi_3))

        # create second bspline
        z_values = np.linspace(z_3, z_4, 10)
        r_values = np.linspace(r_2, r_1, 10)
        points = helical_projection(r_values, z_values)
        bsp2 = Part.BSplineCurve()
        bsp2.interpolate(list(map(fcvec, points)))
        bsp2 = bsp2.toShape()

        wire = Part.Wire([c1, bsp1, c2, bsp2])
        w_all = [wire]

        rot = App.Matrix()
        rot.rotateZ(2 * np.pi / t)
        for i in range(1, t):
            w_all.append(w_all[-1].transformGeometry(rot))

        full_wire = Part.Wire(Part.Wire(w_all))
        if h == 0:
            fp.Shape = full_wire
        else:
            shape = helicalextrusion(full_wire, h, h * np.tan(beta) * 2 / d)
            fp.Shape = shape
Example #4
0
import Part
c = Part.BSplineCurve()
from FreeCAD import Base
scale = (1500 / (275.5 + 4.4)) * (44 / (275.5 + 4.4))
pts1 = [
    Base.Vector(0, 0, 0).multiply(scale),
    Base.Vector(5.5, 6.4, 0).multiply(scale),
    Base.Vector(15.5, 12.5, 0).multiply(scale),
    Base.Vector(25.5, 16.2, 0).multiply(scale),
    Base.Vector(35.5, 18.75, 0).multiply(scale),
    Base.Vector(45.5, 20.33, 0).multiply(scale),
    Base.Vector(55.5, 21.3, 0).multiply(scale),
    Base.Vector(65.5, 22.1, 0).multiply(scale),
    Base.Vector(75.5, 22.73, 0).multiply(scale),
    Base.Vector(85.5, 23, 0).multiply(scale),
    Base.Vector(95.5, 23.53, 0).multiply(scale),
    Base.Vector(105.5, 23.53, 0).multiply(scale),
    Base.Vector(115.5, 23.53, 0).multiply(scale),
    Base.Vector(125.5, 23.68, 0).multiply(scale),
    Base.Vector(135.5, 23.49, 0).multiply(scale),
    Base.Vector(145.5, 23.1, 0).multiply(scale),
    Base.Vector(155.5, 23.08, 0).multiply(scale),
    Base.Vector(165.5, 22.42, 0).multiply(scale),
    Base.Vector(175.5, 21.81, 0).multiply(scale),
    Base.Vector(185.5, 20.91, 0).multiply(scale),
    Base.Vector(195.5, 20.37, 0).multiply(scale),
    Base.Vector(205.5, 19.37, 0).multiply(scale),
    Base.Vector(215.5, 18.13, 0).multiply(scale),
    Base.Vector(225.5, 16.28, 0).multiply(scale),
    Base.Vector(235.5, 14.64, 0).multiply(scale),
    Base.Vector(245.5, 12.38, 0).multiply(scale),
Example #5
0
    def execute(self, obj):

        dt = (obj.CurveEnd - obj.CurveStart) / (obj.NbPts - 1)
        pts = []
        t = obj.CurveStart
        a = b = c = d = x = y = z = 0

        for i in range(obj.NbPts):
            try:
                value = "a"
                a = eval(obj.a)
                value = "b"
                b = eval(obj.b)
                value = "c"
                c = eval(obj.c)
                value = "d"
                d = eval(obj.d)
                value = "e"
                e = eval(obj.e)
                value = "x"
                x = eval(obj.X)
                value = "y"
                y = eval(obj.Y)
                value = "z"
                z = eval(obj.Z)

            except ZeroDivisionError:
                print("Warning: Error division by zero in calculus of " +
                      value + " for t=" + str(t) + " !")
            except:
                print("Error in the formula of " + value + " !")

            pts.append(FreeCAD.Vector(x, y, z))
            t += dt

        if obj.Close:  # pour fermer la courbe on ajoute un point au début
            t = obj.CurveStart
            a = eval(obj.a)
            b = eval(obj.b)
            c = eval(obj.c)
            d = eval(obj.d)
            e = eval(obj.e)
            x = eval(obj.X)
            y = eval(obj.Y)
            z = eval(obj.Z)
            pts.append(FreeCAD.Vector(x, y, z))

        if obj.Wire == False:
            curve = Part.BSplineCurve(pts)
            if obj.Close:
                curve.setPeriodic()
            if obj.CreateFace:
                sh = Part.Face(Part.Wire(curve.toShape()))
            else:
                sh = curve.toShape()
        else:

            wire = Part.makePolygon(pts)
            if obj.CreateFace == False:
                sh = Part.Wire(wire)
            else:
                sh = Part.Face(wire)

        sh.Placement = obj.Placement
        obj.Shape = sh
def process(filename,
            scale,
            posX,
            posY,
            posZ,
            rotX,
            rotY,
            rotZ,
            rot,
            useSpline,
            splitSpline,
            coords=[]):
    if len(coords) == 0:
        coords = readpointsonfile(filename)
    # do we use a BSpline?
    if useSpline:
        if splitSpline:  #do we split between upper and lower side?
            if coords.__contains__(FreeCAD.Vector(
                    0, 0, 0)):  # lgtm[py/modification-of-default-value]
                flippoint = coords.index(FreeCAD.Vector(0, 0, 0))
            else:
                lenghtList = [v.Length for v in coords]
                flippoint = lenghtList.index(min(lenghtList))
            splineLower = Part.BSplineCurve()
            splineUpper = Part.BSplineCurve()
            splineUpper.interpolate(coords[:flippoint + 1])
            splineLower.interpolate(coords[flippoint:])
            if coords[0] != coords[-1]:
                wire = Part.Wire([
                    splineUpper.toShape(),
                    splineLower.toShape(),
                    Part.makeLine(coords[0], coords[-1])
                ])
            else:
                wire = Part.Wire(
                    [splineUpper.toShape(),
                     splineLower.toShape()])
        else:
            spline = Part.BSplineCurve()
            spline.interpolate(coords)
            if coords[0] != coords[-1]:
                wire = Part.Wire(
                    [spline.toShape(),
                     Part.makeLine(coords[0], coords[-1])])
            else:
                wire = Part.Wire(spline.toShape())
    else:
        # alternate solution, uses common Part Faces
        lines = []
        first_v = None
        last_v = None
        for v in coords:
            if first_v is None:
                first_v = v
            # End of if first_v is None
            # Line between v and last_v if they're not equal
            if (last_v != None) and (last_v != v):
                lines.append(Part.makeLine(last_v, v))
            # End of if (last_v != None) and (last_v != v)
            # The new last_v
            last_v = v
        # End of for v in upper
        # close the wire if needed
        if last_v != first_v:
            lines.append(Part.makeLine(last_v, first_v))
        wire = Part.Wire(lines)

    #face = Part.Face(wire).scale(scale) #Scale the foil, # issue31 doesn't work with v0.18
    face = Part.Face(wire)
    myScale = Base.Matrix()  # issue31
    myScale.scale(scale, scale, scale)  # issue31
    face = face.transformGeometry(myScale)  # issue31

    face.Placement.Rotation.Axis.x = rotX
    face.Placement.Rotation.Axis.y = rotY
    face.Placement.Rotation.Axis.z = rotZ
    face.Placement.Rotation.Angle = rot

    #face.Placement(FreeCAD.Vector(0,0,0),FreeCAD.Rotation(FreeCAD.Vector(rotX,rotY,rotZ),rot))
    #face.rotate([0,0,0],FreeCAD.Vector(rotX, rotY, rotZ),rot)

    return face, coords
Example #7
0
 def updateCurve(self):
     self.curve = Part.BSplineCurve()
     self.curve.buildFromPolesMultsKnots(self.stack, self.mults, self.knots,
                                         False, self.degree)
     self.obj.Shape = self.curve.toShape()
     self.Block1.text = self.info + ["Degree : %s" % self.curve.Degree]
Example #8
0
    def makeSpline(self, points):

        spline = Part.BSplineCurve()
        spline.buildFromPoles(points)
        return spline
Example #9
0
def run_FreeCAD_conny(self):
 
    edges=self.getPinObjects(pinname='Shapes_in',sort=False)   
    sayl()
    neighbor=[]
    gaps=[]

    ec=len(edges)
#    say("len edges",ec)
#    say("edges")
    e2=[]
    for e in edges:
        #say(e,e.__class__)
        try: e2 += [e.Edge1]
        except:
            e2 += [e]
           
    e=e2
    #say(e)
    #return 
        
        
        
        
        
        
    for i in range(ec):
        sf=-1
        sflag=0
        sdist=10**8
        f=-1
        flag=0
        dist=10**8
        
        vs=edges[i].Vertexes[0].Point
        ve=edges[i].Vertexes[1].Point
        #say(vs,ve)
        for j in range(ec):
            if i == j:
                continue
            if (edges[j].Vertexes[0].Point-vs).Length <sdist:
                sf=j
                sdist=(edges[j].Vertexes[0].Point-vs).Length
                sflag=0
            if (edges[j].Vertexes[1].Point-vs).Length <sdist:
                sf=j
                sdist=(edges[j].Vertexes[1].Point-vs).Length
                sflag=1
            if (edges[j].Vertexes[0].Point-ve).Length <dist:
                f=j
                dist=(edges[j].Vertexes[0].Point-ve).Length
                flag=0
            if (edges[j].Vertexes[1].Point-ve).Length <dist:
                f=j
                dist=(edges[j].Vertexes[1].Point-ve).Length
                flag=1
        neighbor += [(sf,sflag,sdist,f,flag,dist)]
#        print (i,sf,sflag,sdist,f,flag,dist)

    # find neighbors chain of edges 
    e=0 # starting edge
    try:
        ee=neighbor[e][0]
    except:
        say("keine daten abbruch")
        return
    chain=[e,ee]
    for i in range(14):
        if neighbor[ee][0] not in chain:
            ee2=neighbor[ee][0]
            chain += [ee2]
            e=ee
            ee=ee2
        elif neighbor[ee][3] not in chain:
            ee2=neighbor[ee][3]
            chain += [ee2]
            e=ee
            ee=ee2

    print("chain",chain)



    # calculate gap filler for the chain
    pts=[]
    col=[]
  
    cc=len(chain)
    for i in range(cc):
        
        lmin=10**8
        ep=chain[i-1]
        e=chain[i]
        ff=-1
        # shortest gap between two edges of the chain
        for f in range(2):
            for fp in range(2):
                pa,pb=edges[e].Vertexes[f].Point,edges[ep].Vertexes[fp].Point
                
                l=(pa-pb).Length
                if l<lmin:
                    lmin=l
                    paa,pbb=pa,pb
                    polsa=edges[e].toNurbs().Edge1.Curve.getPoles()
                    polsb=edges[ep].toNurbs().Edge1.Curve.getPoles()

                    if ff == -1:
                        if (polsa[0]-polsb[0]).Length < (polsa[-1]-polsb[-1]).Length:
                            ff=0
                        else:
                            ff = 1
                    ff2= 1 - ff if  self.getData('ff') else 0




                    if f==ff2:
                        na=[polsa[0],polsa[1]]
                    else:
                        na=[polsa[-1],polsa[-2]]
                    if fp==ff2:
                        nb=[polsb[0],polsb[1]]
                    else:
                        nb=[polsb[-1],polsb[-2]]

        # create the gap filler
        if (na[0]-nb[0]).Length> 0.0001:

            #+# k should depend on size of gap (na[0]-nb[0]).Length
            k=self.getData("tangentForce")*0.05
            nn=[na[0],na[0]+(na[0]-na[1])*k,nb[0]+(nb[0]-nb[1])*k,nb[0]]
            
            ###simple line connection
            ##t=Part.makePolygon(nn)
            ##col += [Part.makePolygon([paa,pbb]).Edge1]

            t=Part.BSplineCurve()
            t.buildFromPolesMultsKnots(nn,[4,4],[0,1],False,3)
            gaps += [t.toShape().Edge1]
            col += [t.toShape().Edge1]

        col += [edges[ep].Edge1]

    # special case only two edges 
    if ec==2:
        col=[]
        gaps=[]

        polsa=edges[0].toNurbs().Edge1.Curve.getPoles()
        polsb=edges[1].toNurbs().Edge1.Curve.getPoles()
        
        ff= 1 if  self.getData('ff') else 0

        for [na,nb]  in  [
                    [[polsa[0],polsa[1]],[polsb[-1],polsb[-2]]],
                     [[polsa[-1],polsa[-2]],[polsb[0],polsb[1]]]
                     ]:
        
            if (na[0]-nb[0]).Length> 0.0001:
                
                k=self.getData("tangentForce")*0.05
                nn=[na[0],na[0]+(na[0]-na[1])*k,nb[0]+(nb[0]-nb[1])*k,nb[0]]
                
                t=Part.BSplineCurve()
                t.buildFromPolesMultsKnots(nn,[4,4],[0,1],False,3)
                gaps += [t.toShape().Edge1]
                col += [t.toShape().Edge1]

        col += [edges[1]]
        col += [edges[0]]

    #say(col)
    if self.getData("createFace"):
        ss=Part.sortEdges(col)
        sh=Part.makeFilledFace(ss[0])
    else:
        sh=Part.Compound(col)

    self.setPinObject("Shape_out",sh)
    #say("col",col)
    #say("gaps",gaps)
    self.setPinObject("gaps",Part.Compound(gaps))
Example #10
0
def aa():    
    #-------------------- kann weg/reuse otherwhere
    if 1:
        pass
    else:
        
        ss=Part.sortEdges(col)
        poles=[]
        polesseg=[]
        for w in ss[0]:
            wn=w.toNurbs()
            pls=wn.Edge1.Curve.getPoles()
            if len(polesseg)>0:
                if (pls[0]- polesseg[-1][-1]).Length<0.001:
                    pass
                else:
                    pls.reverse()
            polesseg += [pls]
            poles += pls
        
        degA=self.getData("degree")   
        ls=int(len(polesseg)/2)
        poles=[]
        k=self.getData("tangentForce")
        
        pfak=degA
        pfak=0 # fuer weiche uebergaenge
        
        for i in range(ls):
            ll= (polesseg[2*i][0]-polesseg[2*i][1]).Length
            k *= 0.1*ll
            poles += [ polesseg[2*i][0]]*pfak
            try:
                poles += [
                    polesseg[2*i][0] + (polesseg[2*i][0]- polesseg[2*i-1][-2]).normalize()*k,
                    polesseg[2*i][1] + (polesseg[2*i][1] -polesseg[2*i+1][1]).normalize()*k,
                    ]
            except:
                say("no tangantes possible")
                poles += [
                    polesseg[2*i][0] + (polesseg[2*i][0]- polesseg[2*i-1][-2]),
                    polesseg[2*i][1] + (polesseg[2*i][1] -polesseg[2*i+1][1]),
                    ]

                pass
            poles += [polesseg[2*i][1]]*pfak
            
            poles +=polesseg[2*i+1]
        
        sh=Part.makePolygon(poles)
        sf=Part.BSplineCurve()

        poles=np.array(poles)
        (countA,_)=poles.shape

        multA=[degA+1]+[1]*(countA-1-degA)+[degA+1]
        knotA=range(len(multA))

        sf=Part.BSplineCurve()
        n=self.getData("rotateAxis")
        poles2=np.concatenate([poles[n:],poles[:n]]);poles=poles2
        
        sf.buildFromPolesMultsKnots(poles,multA,knotA,False,degA)

        sh=sf.toShape()

        if 0 and self.getData("createFace"):
            t=len(multA)//3-1
            sf1=sf.copy()
            sf2=sf.copy()
            sf3=sf.copy()
            sf2.segment(0,t)
            sf3.segment(t,2*t)
            sf1.segment(2*t,len(multA)-1)

            sh=Part.Compound([sf2.toShape(),sf3.toShape(),sf1.toShape()])
            Part.show(sh)
            tt=FreeCAD.ActiveDocument.ActiveObject
            surf=FreeCAD.ActiveDocument.addObject("Surface::GeomFillSurface","Surface")
            surf.BoundaryList=[(tt, ('Edge1', 'Edge2', 'Edge3'))]

            FreeCAD.ActiveDocument.recompute(None,True,True)


        if  self.getData("createFace"):
            t=len(multA)//2
            sf1=sf.copy()
            sf2=sf.copy()
            sf2.segment(0,t)          
            sf1.segment(t,len(multA)-1)
            sh=Part.Compound([sf2.toShape(),sf1.toShape()])
            e2=sf1.toShape().Edge1
            e2.reverse()
            sh=Part.makeRuledSurface(sf2.toShape().Edge1,e2)
      

         
            
    self.setPinObject("Shape_out",sh)
    def build_alignment(self, alignments):
        """
        Build a 3D alignment from the supplied alignments
        """

        parent = alignments[0].InList[0]

        #get list of geometry edges
        edges = [alignments[0].Shape.Edges[0], alignments[1].Shape.Edges[0]]

        #get the horizontal curve's first and last parameters
        params = [edges[0].FirstParameter, edges[0].LastParameter]

        #get the length of the curve and set the step interval
        hz_len = edges[0].Length

        #default 1-foot resolution
        step = 304.80

        points = []

        #1. divide the length by the number of steps
        #2. truncate the integer
        #3. add one for the concluding point for the steps,
        #4. add point for the end of the edge, if last step falls short
        point_count = int(hz_len / float(step)) + 1

        if ((point_count - 1) * step) < hz_len:
            point_count += 1

        #vertical curve as equidistant points at the step interval...
        vt_pts = edges[1].discretize(Number=point_count,
                                     First=0.00,
                                     Last=hz_len)

        end_point = vt_pts[point_count - 1]

        #this pairs coordinates of like-axes in three tuples:
        #   (x_coords,y_coords,z)
        vt_pt_axes = np.array(vt_pts).swapaxes(0, 1)

        #save x_coords/y_coords coordinate pairs in separate variables
        x_coords = []
        _i = 0.0

        while _i <= hz_len:
            x_coords.append(_i)
            _i += step

        #if we added two to the point count, the step interval won't
        #make it to the end... add the length as the last point
        if len(x_coords) < point_count:
            x_coords.append(hz_len)

        y_coords = vt_pt_axes[1]

        #append the final elevation - see above
        if len(y_coords) < point_count:
            y_coords = np.append(y_coords, end_point.y)

        #interpolation...
        _ff = interpolate.interp1d(x_coords,
                                   y_coords,
                                   kind='cubic',
                                   bounds_error=False,
                                   fill_value=0)

        _ll = int(edges[0].Length) + 1

        #create a set of x_coords
        #values spaced between 0 and ll at the specified step interval
        xnew = np.arange(0, _ll, step)

        if xnew[-1] != edges[0].Length:
            xnew = np.append(xnew, edges[0].Length)

        #interpolates y_coords values for the specified x_coords values
        ynew = _ff(xnew)

        for i in range(xnew.shape[0]):

            position = params[0] + step * (params[1] - params[0]) / hz_len * i

            #x,y coordinate on horizontal
            point = edges[0].Curve.value(position)

            #generate z-coordinate for 3D spline
            points.append(App.Vector(point.x, point.y, ynew[i]))

        res = App.activeDocument().addObject('Part::Feature',
                                             'Composite_' + parent.Label)

        _s = Part.BSplineCurve()
        _s.interpolate(points)

        res.Shape = _s.toShape()

        parent.addObject(res)

        App.ActiveDocument.recompute()

        return res
Example #12
0
def ArcSplineSketch(sk):
	raise Exception("rework needed")
	import Part
	import numpy as np

#	name="hu"
#	sk = FreeCAD.ActiveDocument.addObject("Sketcher::SketchObjectPython",name)

	if 1:
		pts=[
				(-100,0,0),(-10,90,0),(0,100,0),
				(10,90,0),(100,0,0),
				(0,-50,0)
			]

		pts2=[FreeCAD.Vector(p) for p in pts]
		pts=pts2



	App.ActiveDocument.recompute()
	sk.addGeometry(Part.LineSegment(pts[0],pts[1]),False)
	sk.addGeometry(Part.LineSegment(pts[1],pts[2]),False)
	sk.addConstraint(Sketcher.Constraint('Coincident',0,2,1,1)) 
	App.ActiveDocument.recompute()
	sk.addGeometry(Part.LineSegment(pts[2],pts[3]),False)
	# top
	sk.addConstraint(Sketcher.Constraint('Coincident',1,2,2,1)) 
	App.ActiveDocument.recompute()

	sk.addGeometry(Part.LineSegment(pts[3],pts[4]),False)
	sk.addConstraint(Sketcher.Constraint('Coincident',2,2,3,1)) 
	App.ActiveDocument.recompute()
	sk.addGeometry(Part.LineSegment(pts[4],pts[5]),False)
	sk.addConstraint(Sketcher.Constraint('Coincident',3,2,4,1)) 
	App.ActiveDocument.recompute()
	App.ActiveDocument.recompute()
	sk.addGeometry(Part.LineSegment(pts[5],pts[0]),False)
	sk.addConstraint(Sketcher.Constraint('Coincident',4,2,5,1)) 

	sk.addConstraint(Sketcher.Constraint('Coincident',5,2,0,1)) 
	App.ActiveDocument.recompute()


	#breite

	sk.addConstraint(Sketcher.Constraint('Perpendicular',5,0)) 
	App.ActiveDocument.recompute()
	sk.addConstraint(Sketcher.Constraint('Perpendicular',4,3)) 
	App.ActiveDocument.recompute()

	sk.addConstraint(Sketcher.Constraint('Equal',5,4)) 
	App.ActiveDocument.recompute()
	sk.addConstraint(Sketcher.Constraint('Equal',0,3)) 
	App.ActiveDocument.recompute()
	App.ActiveDocument.recompute()
	sk.addConstraint(Sketcher.Constraint('PointOnObject',1,2,0)) 
	sk.addConstraint(Sketcher.Constraint('PointOnObject',1,2,3)) 

	App.ActiveDocument.recompute()
	App.ActiveDocument.recompute()

	#--------------------


	sk.addGeometry(Part.Circle(pts[0],App.Vector(0,0,1),10),True)
	sk.addConstraint(Sketcher.Constraint('Coincident',6,3,0,1)) 
	sk.addGeometry(Part.Circle(pts[1],App.Vector(0,0,1),10),True)
	sk.addConstraint(Sketcher.Constraint('Radius',6,10.000000)) 
	sk.addConstraint(Sketcher.Constraint('Equal',6,7)) 
	sk.addConstraint(Sketcher.Constraint('Coincident',7,3,0,2)) 
	sk.addGeometry(Part.Circle(pts[3],App.Vector(0,0,1),10),True)
	sk.addConstraint(Sketcher.Constraint('Equal',6,8)) 
	sk.addConstraint(Sketcher.Constraint('Coincident',8,3,2,2)) 
	sk.addGeometry(Part.Circle(pts[4],App.Vector(0,0,1),10),True)
	sk.addConstraint(Sketcher.Constraint('Equal',6,9)) 
	sk.addConstraint(Sketcher.Constraint('Coincident',9,3,3,2)) 
	sk.addGeometry(Part.BSplineCurve([pts[0],pts[1],pts[3],pts[4]],None,None,False,3,None,False),False)

	conList = []
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',6,3,10,0))
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',7,3,10,1))
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',8,3,10,2))
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',9,3,10,3))
	sk.addConstraint(conList)

	sk.exposeInternalGeometry(10)
	App.ActiveDocument.recompute()


	sk.addConstraint(Sketcher.Constraint('DistanceX',0,1,pts[0].x)) 
	sk.addConstraint(Sketcher.Constraint('DistanceY',0,1,pts[0].y)) 
	App.ActiveDocument.recompute()
	sk.addConstraint(Sketcher.Constraint('DistanceX',3,2,pts[4].x)) 
	sk.addConstraint(Sketcher.Constraint('DistanceY',3,2,pts[4].y)) 
	App.ActiveDocument.recompute()

	sk.addConstraint(Sketcher.Constraint('Angle',-1,1,0,1,0.25*np.pi)) 

	App.ActiveDocument.recompute()

#----------------------------

	pts2=[FreeCAD.Vector(200,-100,0)-p for p in pts]


	gc=13
	pts=pts2

	App.ActiveDocument.recompute()
	sk.addGeometry(Part.LineSegment(pts[0],pts[1]),False)
	sk.addGeometry(Part.LineSegment(pts[1],pts[2]),False)
	sk.addConstraint(Sketcher.Constraint('Coincident',gc+0,2,gc+1,1)) 
	App.ActiveDocument.recompute()
	sk.addGeometry(Part.LineSegment(pts[2],pts[3]),False)
	# top
	sk.addConstraint(Sketcher.Constraint('Coincident',gc+1,2,gc+2,1)) 
	App.ActiveDocument.recompute()


	sk.addGeometry(Part.LineSegment(pts[3],pts[4]),False)
	sk.addConstraint(Sketcher.Constraint('Coincident',gc+2,2,gc+3,1)) 
	App.ActiveDocument.recompute()
	sk.addGeometry(Part.LineSegment(pts[4],pts[5]),False)
	sk.addConstraint(Sketcher.Constraint('Coincident',gc+3,2,gc+4,1)) 
	App.ActiveDocument.recompute()
	App.ActiveDocument.recompute()
	sk.addGeometry(Part.LineSegment(pts[5],pts[0]),False)
	sk.addConstraint(Sketcher.Constraint('Coincident',gc+4,2,gc+5,1)) 

	sk.addConstraint(Sketcher.Constraint('Coincident',gc+5,2,gc+0,1)) 
	App.ActiveDocument.recompute()


	#breite

	sk.addConstraint(Sketcher.Constraint('Perpendicular',gc+5,gc+0)) 
	App.ActiveDocument.recompute()
	sk.addConstraint(Sketcher.Constraint('Perpendicular',gc+4,gc+3)) 
	App.ActiveDocument.recompute()


	sk.addConstraint(Sketcher.Constraint('Equal',gc+5,gc+4)) 
	App.ActiveDocument.recompute()
	sk.addConstraint(Sketcher.Constraint('Equal',gc+0,gc+3)) 
	App.ActiveDocument.recompute()
	App.ActiveDocument.recompute()
	sk.addConstraint(Sketcher.Constraint('PointOnObject',gc+1,2,gc+0)) 
	sk.addConstraint(Sketcher.Constraint('PointOnObject',gc+1,2,gc+3)) 

	App.ActiveDocument.recompute()
	App.ActiveDocument.recompute()

	#--------------------

	sk.addGeometry(Part.Circle(pts[0],App.Vector(0,0,1),10),True)

	sk.addConstraint(Sketcher.Constraint('Coincident',gc+6,3,gc+0,1)) 
	sk.addGeometry(Part.Circle(pts[1],App.Vector(0,0,1),10),True)
#	sk.addConstraint(Sketcher.Constraint('Radius',gc+6,10.000000)) 
	sk.addConstraint(Sketcher.Constraint('Equal',6,gc+6)) 

	sk.addConstraint(Sketcher.Constraint('Equal',gc+6,gc+7)) 
	sk.addConstraint(Sketcher.Constraint('Coincident',gc+7,3,gc+0,2)) 
	sk.addGeometry(Part.Circle(pts[3],App.Vector(0,0,1),10),True)
	sk.addConstraint(Sketcher.Constraint('Equal',gc+6,gc+8)) 
	sk.addConstraint(Sketcher.Constraint('Coincident',gc+8,3,gc+2,2)) 
	sk.addGeometry(Part.Circle(pts[4],App.Vector(0,0,1),10),True)
	sk.addConstraint(Sketcher.Constraint('Equal',gc+6,gc+9)) 
	sk.addConstraint(Sketcher.Constraint('Coincident',gc+9,3,gc+3,2)) 
	sk.addGeometry(Part.BSplineCurve([pts[0],pts[1],pts[3],pts[4]],None,None,False,3,None,False),False)

	
	conList = []
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',gc+6,3,gc+10,0))
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',gc+7,3,gc+10,1))
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',gc+8,3,gc+10,2))
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',gc+9,3,gc+10,3))
	sk.addConstraint(conList)

	sk.exposeInternalGeometry(gc+10)
	App.ActiveDocument.recompute()


	sk.addConstraint(Sketcher.Constraint('PointOnObject',16,2,3)) 
	sk.addConstraint(Sketcher.Constraint('PointOnObject',15,2,3)) 


	la=sk.addGeometry(Part.LineSegment(pts[0],pts[1]),False)
	sk.addConstraint(Sketcher.Constraint('Coincident',la,1,3,2)) 
	sk.addConstraint(Sketcher.Constraint('Coincident',la,2,gc+4,1)) 


	sk.addConstraint(Sketcher.Constraint('DistanceX',gc+0,1,pts[0].x)) 
	sk.addConstraint(Sketcher.Constraint('DistanceY',gc+0,1,pts[0].y)) 
	App.ActiveDocument.recompute()
#	sk.addConstraint(Sketcher.Constraint('DistanceX',3,2,pts[4].x)) 
#	sk.addConstraint(Sketcher.Constraint('DistanceY',3,2,pts[4].y)) 
#	App.ActiveDocument.recompute()

	for i in [1,2,3,4,5,14,15,16,17,18]:
		sk.toggleConstruction(i) 
		pass
	App.ActiveDocument.recompute()

	if 10:
		sk.renameConstraint(26, u'Ax')
		sk.renameConstraint(27, u'Ay')
		sk.renameConstraint(61, u'Bx')
		sk.renameConstraint(62, u'By')
		sk.renameConstraint(30, u'Aarc')

	App.ActiveDocument.recompute()
#	App.ActiveDocument.recompute()

	sk.toggleDriving(29) 
	sk.toggleDriving(28) 

#	aa=sk.addConstraint(Sketcher.Constraint('Angle',13,-0.5*np.pi)) 

	aa=sk.addConstraint(Sketcher.Constraint('Angle',14,2,-1,2, -0.56)) 
	sk.renameConstraint(63, u'Barc')
Example #13
0
def createsimplebezier(sk):
	'''create a simple bezier curve with 4 poles'''

	pts=[
			(0,0,0),(0,-100,0),
			(600,-100,0),(600,0,0)
		]


	pts2=[FreeCAD.Vector(p) for p in pts]
	pts=pts2

	sk.addGeometry(Part.Circle(pts[0],App.Vector(0,0,1),10),True)
	sk.addConstraint(Sketcher.Constraint('Radius',0,10.000000)) 

	for i in range(1,4):
		sk.addGeometry(Part.Circle(pts[i],App.Vector(0,0,1),10),True)
		sk.addConstraint(Sketcher.Constraint('Equal',0,i)) 

	bc=sk.addGeometry(Part.BSplineCurve(pts,None,None,False,3,None,False),False)

	conList = []
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',0,3,bc,0))
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',1,3,bc,1))
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',2,3,bc,2))
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',3,3,bc,3))

	sk.addConstraint(conList)
	sk.exposeInternalGeometry(4)

	App.ActiveDocument.recompute()

	l=sk.addGeometry(Part.LineSegment(pts[-1],pts[-2]),True)

	sk.addConstraint(Sketcher.Constraint('Coincident',l,1,3,3)) 
	sk.addConstraint(Sketcher.Constraint('Coincident',l,2,2,3)) 
	App.ActiveDocument.recompute()

	l2=sk.addGeometry(Part.LineSegment(pts[0],pts[1]),True)

	sk.addConstraint(Sketcher.Constraint('Coincident',l2,1,0,3)) 
	sk.addConstraint(Sketcher.Constraint('Coincident',l2,2,1,3)) 
	App.ActiveDocument.recompute()

	sk.addConstraint(Sketcher.Constraint('DistanceX',0,3,0)) 
	sk.addConstraint(Sketcher.Constraint('DistanceY',0,3,0)) 
	App.ActiveDocument.recompute()
	
	sk.renameConstraint(14, u'Ax')
	App.ActiveDocument.recompute()
	sk.renameConstraint(15, u'Ay')
	sk.addConstraint(Sketcher.Constraint('DistanceX',3,3,600)) 
	sk.addConstraint(Sketcher.Constraint('DistanceY',3,3,0)) 
	App.ActiveDocument.recompute()
	sk.renameConstraint(16, u'Bx')
	sk.renameConstraint(17, u'By')

	sk.addConstraint(Sketcher.Constraint('Angle',l2,2,-1,2,0.5*np.pi)) 
	sk.renameConstraint(18, u'Aarc')
	sk.addConstraint(Sketcher.Constraint('Angle',l,2,-1,2,-0.5*np.pi)) 
	sk.renameConstraint(19, u'Barc')
	App.activeDocument().recompute()

	for i in range(14,20):
		sk.setDriving(i,False)

	for i in range(20):
		sk.toggleVirtualSpace(i)

	cc=sk.addGeometry(Part.Circle(App.Vector(600.000000,0.000000,0),App.Vector(0,0,1),20.),False)
	sk.addConstraint(Sketcher.Constraint('Coincident',cc,3,3,3)) 
Example #14
0
def createbezier(sk):
	'''create a curve segment with 7 poles inside the sketch sk'''

	pts=[
			(0,0,0),(0,-100,0),
			(200,0,0),(300,0,0),(400,0,0),
			(600,-100,0),(600,0,0)
		]

	pts2=[FreeCAD.Vector(p) for p in pts]
	pts=pts2


	sk.addGeometry(Part.Circle(pts[0],App.Vector(0,0,1),10),True)
	sk.addConstraint(Sketcher.Constraint('Radius',0,10.000000)) 

	for i in range(1,7):
		sk.addGeometry(Part.Circle(pts[i],App.Vector(0,0,1),10),True)
		sk.addConstraint(Sketcher.Constraint('Equal',0,i)) 

	sk.addGeometry(Part.BSplineCurve(pts,None,None,False,3,None,False),False)

	conList = []
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',0,3,7,0))
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',1,3,7,1))
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',2,3,7,2))
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',3,3,7,3))
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',4,3,7,4))
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',5,3,7,5))
	conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',6,3,7,6))

	sk.addConstraint(conList)
	sk.exposeInternalGeometry(7)

	App.ActiveDocument.recompute()

	sk.addGeometry(Part.LineSegment(pts[2],pts[4]),True)
	sk.addConstraint(Sketcher.Constraint('Coincident',13,1,2,3)) 
	sk.addConstraint(Sketcher.Constraint('Coincident',13,2,4,3)) 
	App.ActiveDocument.recompute()
	sk.addConstraint(Sketcher.Constraint('PointOnObject',3,3,13)) 

	sk.addGeometry(Part.LineSegment(pts[-1],pts[-2]),True)

	sk.addConstraint(Sketcher.Constraint('Coincident',14,1,6,3)) 
	sk.addConstraint(Sketcher.Constraint('Coincident',14,2,5,3)) 
	App.ActiveDocument.recompute()

	sk.addGeometry(Part.LineSegment(pts[0],pts[1]),True)

	sk.addConstraint(Sketcher.Constraint('Coincident',15,1,0,3)) 
	sk.addConstraint(Sketcher.Constraint('Coincident',15,2,1,3)) 
	App.ActiveDocument.recompute()

	sk.addConstraint(Sketcher.Constraint('DistanceX',0,3,0)) 
	sk.addConstraint(Sketcher.Constraint('DistanceY',0,3,0)) 
	App.ActiveDocument.recompute()
	sk.renameConstraint(26, u'Ax')
	App.ActiveDocument.recompute()
	sk.renameConstraint(27, u'Ay')
	sk.addConstraint(Sketcher.Constraint('DistanceX',6,3,600)) 
	sk.addConstraint(Sketcher.Constraint('DistanceY',6,3,000)) 
	App.ActiveDocument.recompute()
	sk.renameConstraint(28, u'Bx')
	sk.renameConstraint(29, u'By')

	sk.addConstraint(Sketcher.Constraint('Angle',15,2,-1,2,0.5*np.pi)) 
	sk.renameConstraint(30, u'Aarc')
	sk.addConstraint(Sketcher.Constraint('Angle',14,2,-1,2,-0.5*np.pi)) 
	sk.renameConstraint(31, u'Barc')
	App.activeDocument().recompute()
	for i in range(26,32):
		sk.setDriving(i,False)

	for i in range(32):
		sk.toggleVirtualSpace(i)

	sk.addConstraint(Sketcher.Constraint('Symmetric',2,3,4,3,3,3)) 
	cc=sk.addGeometry(Part.Circle(App.Vector(600.,0.0,0),App.Vector(0,0,1),20.),False)
	sk.addConstraint(Sketcher.Constraint('Coincident',cc,3,6,3)) 

	App.ActiveDocument.recompute()
Example #15
0
def run():
    label = "cloverleaf"
    try:
        body = App.activeDocument().Body
    except:
        body = App.activeDocument().addObject('PartDesign::Body', 'Body')

    sk = App.activeDocument().addObject('Sketcher::SketchObject', 'cloverleaf')
    sk.Label = label
    sk.MapMode = 'FlatFace'

    App.activeDocument().recompute()

    pts = None

    if pts == None:  # some test data
        anz = 16
        r = 100
        pts = [
            FreeCAD.Vector(r * np.sin(2 * np.pi / anz * i),
                           r * np.cos(2 * np.pi / anz * i), 0)
            for i in range(anz)
        ]

    for i, p in enumerate(pts):
        sk.addGeometry(
            Part.Circle(App.Vector(int(round(p.x)), int(round(p.y)), 0),
                        App.Vector(0, 0, 1), 10), True)
        if 0:
            #if i == 1: sk.addConstraint(Sketcher.Constraint('Radius',0,10.000000))
            if i > 0: sk.addConstraint(Sketcher.Constraint('Equal', 0, i))
        else:
            radius = 2.0
            sk.addConstraint(Sketcher.Constraint('Radius', i, radius))
            sk.renameConstraint(i, 'Weight ' + str(i + 1))

    k = i + 1

    l = [App.Vector(int(round(p.x)), int(round(p.y))) for p in pts]

    if 0:
        # open spline
        sk.addGeometry(Part.BSplineCurve(l, None, None, False, 3, None, False),
                       False)

    else:
        # periodic spline
        sk.addGeometry(Part.BSplineCurve(l, None, None, True, 3, None, False),
                       False)

    conList = []
    for i, p in enumerate(pts):
        conList.append(
            Sketcher.Constraint(
                'InternalAlignment:Sketcher::BSplineControlPoint', i, 3, k, i))
    sk.addConstraint(conList)

    App.activeDocument().recompute()

    App.activeDocument().recompute()

    sk.addConstraint(Sketcher.Constraint('Symmetric', 0, 3, 2, 3, 1, 3))
    App.activeDocument().recompute()

    sk.addConstraint(Sketcher.Constraint('Symmetric', 4, 3, 6, 3, 5, 3))
    App.activeDocument().recompute()

    sk.addConstraint(Sketcher.Constraint('Symmetric', 8, 3, 10, 3, 9, 3))
    App.activeDocument().recompute()

    sk.addConstraint(Sketcher.Constraint('Symmetric', 12, 3, 14, 3, 13, 3))
    App.activeDocument().recompute()

    la = sk.addGeometry(
        Part.LineSegment(App.Vector(-100, -100, 0), App.Vector(100, -100, 0)),
        False)
    lb = sk.addGeometry(
        Part.LineSegment(App.Vector(100, -100, 0), App.Vector(100, 100, 0)),
        False)
    lc = sk.addGeometry(
        Part.LineSegment(App.Vector(100, 100, 0), App.Vector(-100, 100, 0)),
        False)
    ld = sk.addGeometry(
        Part.LineSegment(App.Vector(-100, 100, 0), App.Vector(-100, -100, 0)),
        False)

    sk.addConstraint(Sketcher.Constraint('Coincident', la, 2, lb, 1))
    sk.addConstraint(Sketcher.Constraint('Coincident', lb, 2, lc, 1))
    sk.addConstraint(Sketcher.Constraint('Coincident', lc, 2, ld, 1))
    sk.addConstraint(Sketcher.Constraint('Coincident', ld, 2, la, 1))

    for l in [la, lb, lc, ld]:
        sk.toggleConstruction(l)

    sk.addConstraint(Sketcher.Constraint('Coincident', 1, 3, lc, 1))
    sk.addConstraint(Sketcher.Constraint('Coincident', 5, 3, lb, 1))
    sk.addConstraint(Sketcher.Constraint('Coincident', 9, 3, la, 1))
    sk.addConstraint(Sketcher.Constraint('Coincident', 13, 3, ld, 1))

    print("curve length", sk.Shape.Edge1.Length)

    sk.addGeometry(
        Part.LineSegment(App.Vector(-100, -100, 0), App.Vector(100, -100, 0)),
        False)
    sk.addConstraint(Sketcher.Constraint('Coincident', 21, 1, 10, 3))
    sk.addConstraint(Sketcher.Constraint('Coincident', 21, 2, 8, 3))
    sk.toggleConstruction(21)

    sk.addGeometry(
        Part.LineSegment(App.Vector(100, -100, 0), App.Vector(100, 100, 0)),
        False)
    sk.addConstraint(Sketcher.Constraint('Coincident', 22, 1, 6, 3))
    sk.addConstraint(Sketcher.Constraint('Coincident', 22, 2, 4, 3))
    sk.toggleConstruction(22)

    sk.addGeometry(
        Part.LineSegment(App.Vector(100, 100, 0), App.Vector(-100, 100, 0)),
        False)
    sk.addConstraint(Sketcher.Constraint('Coincident', 23, 1, 0, 3))
    sk.addConstraint(Sketcher.Constraint('Coincident', 23, 2, 2, 3))
    sk.toggleConstruction(23)

    sk.addGeometry(
        Part.LineSegment(App.Vector(-100, 100, 0), App.Vector(-100, -100, 0)),
        False)
    sk.addConstraint(Sketcher.Constraint('Coincident', 24, 1, 14, 3))
    sk.addConstraint(Sketcher.Constraint('Coincident', 24, 2, 12, 3))
    sk.toggleConstruction(24)