Python Part.Edge() Examples

The following are 30 code examples of Part.Edge(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module Part , or try the search function .
Example #1
Source File: ParametricBlendCurve.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def unsetEdit(self,vobj,mode=0):
        e1 = _utils.getShape(self.Object, "Edge1", "Edge")
        e2 = _utils.getShape(self.Object, "Edge2", "Edge")
        if isinstance(self.ip, pointEditor):
            v = Part.Vertex(self.m1.point)
            proj = v.distToShape(self.m1.snap_shape)[1][0][1]
            pa1 = e1.Curve.parameter(proj)
            self.Object.Parameter1 = (pa1 - self.m1.snap_shape.FirstParameter) / (self.m1.snap_shape.LastParameter - self.m1.snap_shape.FirstParameter)
            self.Object.Scale1 = self.t1.parameter
            self.Object.Continuity1 = self.c1.text[0]

            v = Part.Vertex(self.m2.point)
            proj = v.distToShape(self.m2.snap_shape)[1][0][1]
            pa2 = e2.Curve.parameter(proj)
            self.Object.Parameter2 = (pa2 - self.m2.snap_shape.FirstParameter) / (self.m2.snap_shape.LastParameter - self.m2.snap_shape.FirstParameter)
            self.Object.Scale2 = self.t2.parameter
            self.Object.Continuity2 = self.c2.text[0]
            
            vobj.Selectable = self.select_state
            vobj.PointSize = self.ps
            self.ip.quit()
        self.ip = None
        self.active = False
        #vobj.Visibility = True
        return True 
Example #2
Source File: splitCurves_2.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def getShape(self, fp):
        if fp.Source is None:
            return None, None
        if fp.Source[1] == []: # No subshape given, take wire 1
            if fp.Source[0].Shape.Wires:
                w = fp.Source[0].Shape.Wire1
                e = w.approximate(1e-7, 1e-5, len(w.Edges), 7).toShape()
                #double tol2d = gp::Resolution();
                #double tol3d = 0.0001;
                #int maxseg=10, maxdeg=3;
                #static char* kwds_approx[] = {"Tol2d","Tol3d","MaxSegments","MaxDegree",NULL};
            else:
                return None, None
        else:
            e = _utils.getShape(fp, "Source", "Edge")
            w = False
        return e, w 
Example #3
Source File: ParametricComb.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def __init__(self, obj , edge):
        ''' Add the properties '''
        debug("Comb class Init")
        obj.addProperty("App::PropertyLinkSubList","Edge","Comb","Edge").Edge = edge
        #obj.addProperty("App::PropertyEnumeration","Type","Comb","Comb Type").Type=["Curvature","Unit Normal"]
        obj.addProperty("App::PropertyFloat","Scale","Comb","Scale (%). 0 for AutoScale").Scale=0.0
        #obj.addProperty("App::PropertyBool","ScaleAuto","Comb","Automatic Scale").ScaleAuto = True
        obj.addProperty("App::PropertyIntegerConstraint","Samples","Comb","Number of samples").Samples = 100
        obj.addProperty("App::PropertyInteger","Number","Surface","Number of surface samples").Number = 3
        obj.addProperty("App::PropertyEnumeration","Orientation","Surface","Surface Comb Orientation").Orientation=["U","V","UV"]
        #obj.addProperty("App::PropertyFloat","TotalLength","Comb","Total length of edges")
        obj.addProperty("App::PropertyVectorList","CombPoints","Comb","CombPoints")
        obj.addProperty("Part::PropertyPartShape","Shape","Comb", "Shape of comb plot")
        obj.Proxy = self
        #obj.Samples = (20,2,1000,10)
        obj.CombPoints = []
        self.edges = []
        self.TotalLength = 0.0
        self.factor = 1.0
        #self.selectedEdgesToProperty( obj, edge)
        #self.setEdgeList( obj)
        self.execute(obj)
        obj.Scale = self.factor 
Example #4
Source File: splitCurves_2.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def Activated(self):
        edges = []
        sel = FreeCADGui.Selection.getSelectionEx()
        if sel == []:
            FreeCAD.Console.PrintError("Select the edges to split first !\n")
        for selobj in sel:
            if selobj.HasSubObjects:
                for i in range(len(selobj.SubObjects)):
                    if isinstance(selobj.SubObjects[i], Part.Edge):
                        self.makeSplitFeature((selobj.Object, selobj.SubElementNames[i]))
                        if selobj.Object.Shape:
                            if len(selobj.Object.Shape.Edges) == 1:
                                selobj.Object.ViewObject.Visibility = False
            else:
                self.makeSplitFeature((selobj.Object, []))
                if hasattr(selobj.Object,"ViewObject"):
                    selobj.Object.ViewObject.Visibility = False 
Example #5
Source File: ParametricBlendCurve.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def __init__(self, obj , edges):
        debug("BlendCurve class Init")
        
        obj.addProperty("App::PropertyLinkSub",         "Edge1",      "Edge1", "Edge 1").Edge1 = edges[0]
        obj.addProperty("App::PropertyLinkSub",         "Edge2",      "Edge2", "Edge 2").Edge2 = edges[1]
        obj.addProperty("App::PropertyInteger",         "DegreeMax",  "BlendCurve", "Max degree of the Blend curve").DegreeMax = 9
        obj.addProperty("App::PropertyFloatConstraint", "Parameter1", "Edge1", "Location of blend curve")
        obj.addProperty("App::PropertyFloatConstraint", "Scale1",     "Edge1", "Scale of blend curve")
        obj.addProperty("App::PropertyEnumeration",     "Continuity1","Edge1", "Continuity").Continuity1=["C0","G1","G2","G3","G4"]
        obj.addProperty("App::PropertyFloatConstraint", "Parameter2", "Edge2", "Location of blend curve")
        obj.addProperty("App::PropertyFloatConstraint", "Scale2",     "Edge2", "Scale of blend curve")
        obj.addProperty("App::PropertyEnumeration",     "Continuity2","Edge2", "Continuity").Continuity2=["C0","G1","G2","G3","G4"]
        obj.addProperty("App::PropertyVectorList",      "CurvePts",   "BlendCurve", "CurvePts")
        obj.addProperty("App::PropertyEnumeration",     "Output",     "BlendCurve", "Output type").Output=["Wire","Joined","Single"]
        obj.Scale1 = (1.,-5.0,5.0,0.05)
        obj.Scale2 = (1.,-5.0,5.0,0.05)
        obj.Parameter1 = ( 1.0, 0.0, 1.0, 0.05 )
        obj.Parameter2 = ( 1.0, 0.0, 1.0, 0.05 )
        obj.Proxy = self 
Example #6
Source File: pipeshellProfileFP.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def Activated(self):
        edges = []
        verts = []
        source = None
        sel = FreeCADGui.Selection.getSelectionEx()
        if sel == []:
            FreeCAD.Console.PrintError("Select at least 1 edge !\n")
        for selobj in sel:
            if selobj.HasSubObjects:
                for i in range(len(selobj.SubObjects)):
                    if isinstance(selobj.SubObjects[i], Part.Edge):
                        edges.append((selobj.Object, selobj.SubElementNames[i]))
                        selobj.Object.ViewObject.Visibility=False
                    elif isinstance(selobj.SubObjects[i], Part.Vertex):
                        verts=(selobj.Object, selobj.SubElementNames[i])
                        #selobj.Object.ViewObject.Visibility=False
            else:
                source = selobj.Object
                selobj.Object.ViewObject.Visibility=False
        if source:
            self.makeProfileFeature(source, verts)
        elif edges:
            self.makeProfileFeature(edges, verts) 
Example #7
Source File: splitCurves.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def execute(self, obj):
        e = _utils.getShape(obj, "Edge", "Edge")
        p = obj.Value
        if   obj.Method == "Percent":
            p = self.PercentToParam(e, obj.Value)
        elif obj.Method == "Distance":
            p = self.DistanceToParam(e, obj.Value)
        if p > e.FirstParameter and p < e.LastParameter:
            w = e.split(p)
            if   obj.Output == "Start":
                obj.Shape = w.Edges[0]
            elif obj.Output == "End":
                obj.Shape = w.Edges[-1]
            else:
                obj.Shape = w
        else:
            obj.Shape = e
        obj.Placement = e.Placement 
Example #8
Source File: Discretize.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def getTarget( self, obj, typ):
        o = obj.Edge[0]
        e = obj.Edge[1][0]
        n = eval(e.lstrip('Edge'))
        try:
            edge = o.Shape.Edges[n-1]
            obj.setEditorMode("Target", 2)
            for w in o.Shape.Wires:
                for e in w.Edges:
                    if edge.isSame(e):
                        debug("found matching edge")
                        debug("wire has %d edges"%len(w.Edges))
                        obj.setEditorMode("Target", 0)
                        if typ:
                            return w
            return edge
        except:
            return None 
Example #9
Source File: ParametricBlendCurve.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def update_shape(self):
        e1 = _utils.getShape(self.Object, "Edge1", "Edge")
        e2 = _utils.getShape(self.Object, "Edge2", "Edge")
        if e1 and e2:
            bc = nurbs_tools.blendCurve(e1,e2)
            v = Part.Vertex(self.m1.point)
            proj = v.distToShape(self.m1.snap_shape)[1][0][1]
            bc.param1 = e1.Curve.parameter(proj)
            #bc.param1 = (pa1 - self.m1.snap_shape.FirstParameter) / (self.m1.snap_shape.LastParameter - self.m1.snap_shape.FirstParameter)
            bc.scale1 = self.t1.parameter
            bc.cont1 = self.Object.Proxy.getContinuity(self.c1.text[0])

            v = Part.Vertex(self.m2.point)
            proj = v.distToShape(self.m2.snap_shape)[1][0][1]
            bc.param2 = e2.Curve.parameter(proj)
            #bc.param2 = (pa2 - self.m2.snap_shape.FirstParameter) / (self.m2.snap_shape.LastParameter - self.m2.snap_shape.FirstParameter)
            bc.scale2 = self.t2.parameter
            bc.cont2 = self.Object.Proxy.getContinuity(self.c2.text[0])
            bc.maxDegree = self.Object.DegreeMax
            bc.compute()
            self.Object.Shape = bc.Curve.toShape()
            return bc 
Example #10
Source File: Discretize.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def __init__(self, obj , edge):
        debug("Discretization class Init")
        obj.addProperty("App::PropertyLinkSub",      "Edge",      "Discretization",   "Edge").Edge = edge
        obj.addProperty("App::PropertyEnumeration",  "Target",    "Discretization",   "Tool target").Target=["Edge","Wire"]
        obj.addProperty("App::PropertyEnumeration",  "Algorithm", "Method",   "Discretization Method").Algorithm=["Number","QuasiNumber","Distance","Deflection","QuasiDeflection","Angular-Curvature"]
        obj.addProperty("App::PropertyInteger",      "Number",    "Method",   "Number of edge points").Number = 100
        obj.addProperty("App::PropertyFloat",        "Distance",  "Method",   "Distance between edge points").Distance=1.0
        obj.addProperty("App::PropertyFloat",        "Deflection","Method",   "Distance for deflection Algorithm").Deflection=1.0
        obj.addProperty("App::PropertyFloat",        "Angular",   "Method",   "Angular value for Angular-Curvature Algorithm").Angular=0.1
        obj.addProperty("App::PropertyFloat",        "Curvature", "Method",   "Curvature value for Angular-Curvature Algorithm").Curvature=0.1
        obj.addProperty("App::PropertyInteger",      "Minimum",   "Method",   "Minimum Number of points").Minimum = 2
        obj.addProperty("App::PropertyFloat",        "ParameterFirst",     "Parameters",   "Start parameter")
        obj.addProperty("App::PropertyFloat",        "ParameterLast",      "Parameters",   "End parameter")
        obj.addProperty("App::PropertyVectorList",   "Points",    "Discretization",   "Points")
        obj.Proxy = self
        self.obj = obj
        obj.Algorithm = "Number"
        obj.Target = "Edge"
        edge = self.getTarget(obj, False)
        obj.ParameterFirst = edge.FirstParameter
        obj.ParameterLast = edge.LastParameter
        self.execute(obj) 
Example #11
Source File: mixed_curve.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def shape(self):
        proj1 = self.shape1.toNurbs().extrude(self.dir1)
        proj2 = self.shape2.toNurbs().extrude(self.dir2)
        curves = list()
        for f1 in proj1.Faces:
            for f2 in proj2.Faces:
                curves += f1.Surface.intersectSS(f2.Surface)
        intersect = [c.toShape() for c in curves]
        edges = []
        for sh in intersect:
            if isinstance(sh, Part.Edge) and sh.Length > 1e-7:
                edges.append(sh)
        se = Part.sortEdges(edges)
        wires = []
        for el in se:
            wires.append(Part.Wire(el))
        return Part.Compound(wires) 
Example #12
Source File: combined_curve.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def shape(self):
        proj1 = self.shape1.toNurbs().extrude(self.dir1)
        proj2 = self.shape2.toNurbs().extrude(self.dir2)
        curves = list()
        for f1 in proj1.Faces:
            for f2 in proj2.Faces:
                curves += f1.Surface.intersectSS(f2.Surface)
        intersect = [c.toShape() for c in curves]
        edges = []
        for sh in intersect:
            if isinstance(sh, Part.Edge) and sh.Length > 1e-7:
                edges.append(sh)
        se = Part.sortEdges(edges)
        wires = []
        for el in se:
            wires.append(Part.Wire(el))
        return Part.Compound(wires) 
Example #13
Source File: _utils.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def ancestors(shape, sub):
    '''list_of_shapes = ancestors(shape, sub)
    Returns the closest ancestors of "sub" in "shape"'''
    def cleanup(shape):
        s = str(shape)
        ss = s.split()[0]
        return ss.split('<')[1]
    shd = (Part.Vertex,
           Part.Edge,
           Part.Wire,
           Part.Face,
           Part.Shell,
           Part.Solid,
           Part.CompSolid,
           Part.Compound)
    for i in range(len(shd)-1):
        if isinstance(sub, shd[i]):
            for j in range(i+1,len(shd)):
                manc = shape.ancestorsOfType(sub, shd[j])
                if manc:
                    print("{} belongs to {} {}.".format(cleanup(sub), len(manc), cleanup(manc[0])))
                    return manc 
Example #14
Source File: utils.py    From FreeCAD_assembly3 with GNU General Public License v3.0 6 votes vote down vote up
def isLinearEdge(obj):
    edge = getElementShape(obj,Part.Edge)
    if not edge:
        return False
    elif not hasattr(edge, 'Curve'): #issue 39
        return False
    if isLine(edge.Curve):
        return True
    elif hasattr( edge.Curve, 'Radius' ):
        return False
    else:
        BSpline = edge.Curve.toBSpline()
        try:
            arcs = BSpline.toBiArcs(10**-6)
        except Exception:  #FreeCAD exception thrown ()
            return False
        if all(isLine(a) for a in arcs):
            lines = arcs
            D = np.array([L.tangent(0)[0] for L in lines]) #D(irections)
            return np.std( D, axis=0 ).max() < 10**-9
        return False 
Example #15
Source File: utils.py    From FreeCAD_assembly3 with GNU General Public License v3.0 6 votes vote down vote up
def isCircularEdge(obj):
    edge = getElementShape(obj,Part.Edge)
    if not edge:
        return False
    elif not hasattr(edge, 'Curve'): #issue 39
        return False
    if hasattr( edge.Curve, 'Radius' ):
        return True
    elif isLine(edge.Curve):
        return False
    else:
        BSpline = edge.Curve.toBSpline()
        try:
            arcs = BSpline.toBiArcs(10**-6)
        except Exception:  #FreeCAD exception thrown ()
            return False
        if all( hasattr(a,'Center') for a in arcs ):
            centers = np.array([a.Center for a in arcs])
            sigma = np.std( centers, axis=0 )
            return max(sigma) < 10**-6
        return False 
Example #16
Source File: HQRuledSurfaceFP.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def Activated(self):
        s = FreeCADGui.Selection.getSelectionEx()
        edges = []
        for so in s:
            for i in range(len(so.SubObjects)):
                #subshapes(su)
                if isinstance(so.SubObjects[i], Part.Edge):
                    edges.append((so.Object,(so.SubElementNames[i], )))
            if not so.HasSubObjects:
                if so.Object.Shape.Wires:
                    edges.append(so.Object)
                elif so.Object.Shape.Edges:
                    edges.append(so.Object)

        if len(edges) < 1:
            FreeCAD.Console.PrintError("Select something first !\n")
        else:
            self.makeFeature(edges) 
Example #17
Source File: ProfileSketch.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def Activated(self):
        shapes = []
        params = []
        sel = FreeCADGui.Selection.getSelectionEx()
        if sel == []:
            FreeCAD.Console.PrintError("Select 2 edges or vertexes first !\n")
        for selobj in sel:
            if selobj.HasSubObjects:
                for i in range(len(selobj.SubObjects)):
                    if isinstance(selobj.SubObjects[i], Part.Edge):
                        shapes.append((selobj.Object, selobj.SubElementNames[i]))
                        p = selobj.PickedPoints[i]
                        poe = selobj.SubObjects[i].distToShape(Part.Vertex(p))
                        par = poe[2][0][2]
                        params.append(par)
                    elif isinstance(selobj.SubObjects[i], Part.Vertex):
                        shapes.append((selobj.Object, selobj.SubElementNames[i]))
                        #p = selobj.PickedPoints[i]
                        #poe = so.distToShape(Part.Vertex(p))
                        #par = poe[2][0][2]
                        params.append(0)
            else:
                FreeCAD.Console.PrintError("Select 2 edges or vertexes first !\n")
        if shapes:
            self.makeProfileFeature(shapes, params) 
Example #18
Source File: Birail.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def ruledSurface(self):
        if isinstance(self.edge1,Part.Edge) and isinstance(self.edge2,Part.Edge):
            self.ruled = Part.makeRuledSurface(self.edge1, self.edge2)
            self.rail1 = self.ruled.Edges[0]
            self.rail2 = self.ruled.Edges[2]
            self.u0 = self.ruled.ParameterRange[0]
            self.u1 = self.ruled.ParameterRange[1] 
Example #19
Source File: hooks.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def __setstate__(self,state):
        return None

    #def claimChildren(self):
        #return None #[self.Object.Edge[0]]
        
    #def onDelete(self, feature, subelements): # subelements is a tuple of strings
        #try:
            #self.Object.Edge[0].ViewObject.Visibility=True
            ##self.Object.Tool.ViewObject.show()
        #except Exception as err:
            #FreeCAD.Console.PrintError("Error in onDelete: {0} \n".format(err))
        #return True 
Example #20
Source File: manipulators.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def alter_color(self):
        if   isinstance(self._shape, Part.Vertex):
            self.set_color("white")
        elif isinstance(self._shape, Part.Edge):
            self.set_color("cyan")
        elif isinstance(self._shape, Part.Face):
            self.set_color("magenta")
        else:
            self.set_color("black") 
Example #21
Source File: hooks.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def getEdge(self, obj):
        if obj.Edge:
            o = obj.Edge[0]
            e = obj.Edge[1][0]
            n = eval(e.lstrip('Edge'))
            return o.Shape.Edges[n-1]
        else:
            debug("getEdge failed")
            return None 
Example #22
Source File: hooks.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def __init__(self, obj , edge):
        ''' Add the properties '''
        debug("\Hook class Init\n")
        obj.addProperty("App::PropertyLinkSub",      "Edge",          "Base",     "Support edge").Edge = edge
        obj.addProperty("App::PropertyEnumeration",  "Method",        "Position", "Position").Method=["Fixed","Parameter","Distance-From-Start","Distance-From-End"]
        obj.addProperty("App::PropertyFloat",        "X",             "Value", "X coordinate")
        obj.addProperty("App::PropertyFloat",        "Y",             "Value", "Y coordinate")
        obj.addProperty("App::PropertyFloat",        "Z",             "Value", "Z coordinate")
        obj.addProperty("App::PropertyFloat",        "Parameter",     "Value", "Parameter value")
        obj.addProperty("App::PropertyFloat",        "StartDistance", "Value", "Distance from edge start")
        obj.addProperty("App::PropertyFloat",        "EndDistance",   "Value", "Distance to edge end")
        obj.addProperty("App::PropertyVector",       "Center",        "Position", "Center")
        #obj.Method = "Parameter"
        obj.Proxy = self 
Example #23
Source File: curveExtendFP.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def Activated(self):
        edges = []
        sel = FreeCADGui.Selection.getSelectionEx()
        if sel == []:
            FreeCAD.Console.PrintError("Select the edges to extend first !\n")
        for selobj in sel:
            if selobj.HasSubObjects:
                for i in range(len(selobj.SubObjects)):
                    if isinstance(selobj.SubObjects[i], Part.Edge):
                        edges.append((selobj.Object, selobj.SubElementNames[i]))
                        selobj.Object.ViewObject.Visibility=False
        if edges:
            self.makeExtendFeature(edges) 
Example #24
Source File: curveExtendFP.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def makeExtendFeature(self,source):
        if source is not []:
            for o in source:
                extCurve = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","ExtendedCurve")
                extend(extCurve)
                extCurve.Edge = o
                extendVP(extCurve.ViewObject)
                extCurve.ViewObject.LineWidth = 2.0
                extCurve.ViewObject.LineColor = (0.5,0.0,0.3)
            FreeCAD.ActiveDocument.recompute() 
Example #25
Source File: curveExtendFP.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def claimChildren(self):
        return [self.Object.Edge[0]] 
Example #26
Source File: curveExtendFP.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def execute(self, obj):
        edge = _utils.getShape(obj, "Edge", "Edge")
        curve = curveExtend.getTrimmedCurve(edge)

        cont_start = 1
        if hasattr(obj, "TypeStart"):
            if obj.TypeStart == "G2 curve":
                cont_start = 2
        cont_end = 1
        if hasattr(obj, "TypeEnd"):
            if obj.TypeEnd == "G2 curve":
                cont_end = 2

        ext = []
        if obj.LengthStart > 0:
            ext.append(curveExtend.extendCurve( curve, 0, obj.LengthStart, cont_start))
        if obj.LengthEnd > 0:
            ext.append(curveExtend.extendCurve( curve, 1, obj.LengthEnd, cont_end))
        if not ext == []:
            if hasattr(obj, "Output"):
                if obj.Output == "SingleEdge":
                    for c in ext:
                        curve.join(c.toBSpline())
                    obj.Shape = curve.toShape()
                else:
                    ext.append(curve)
                    edges = []
                    for c in ext:
                        edges.append(Part.Edge(c))
                    w = Part.Wire(Part.__sortEdges__(edges))
                    w.fixWire()
                    obj.Shape = w 
Example #27
Source File: curveExtendFP.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def __init__(self, obj):
        obj.addProperty("App::PropertyLinkSub",      "Edge",       "Base", "Input edge to extend")
        obj.addProperty("App::PropertyEnumeration",  "Output",     "Base", "Output shape").Output = ["SingleEdge","Wire"]

        obj.addProperty("App::PropertyFloat",        "LengthStart","Beginning", "Start Extension Length").LengthStart=10.0
        obj.addProperty("App::PropertyEnumeration",  "TypeStart",  "Beginning", "Start Extension type").TypeStart = ["Straight","G2 curve"]

        obj.addProperty("App::PropertyFloat",        "LengthEnd",  "End", "End Extension Length").LengthEnd=10.0
        obj.addProperty("App::PropertyEnumeration",  "TypeEnd",    "End", "End Extension type").TypeEnd = ["Straight","G2 curve"]
        
        obj.TypeStart = "Straight"
        obj.TypeEnd = "Straight"
        obj.Output = "SingleEdge"
        obj.Proxy = self 
Example #28
Source File: JoinCurves.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def IsActive(self):
        if FreeCAD.ActiveDocument:
            #f = FreeCADGui.Selection.Filter("SELECT Part::Feature SUBELEMENT Edge COUNT 1..1000")
            #return f.match()
            return(True)
        else:
            return(False) 
Example #29
Source File: JoinCurves.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def Activated(self):
        edges = []
        sel = FreeCADGui.Selection.getSelectionEx()
        try:
            ordered = FreeCADGui.activeWorkbench().Selection
            if ordered:
                sel = ordered
        except AttributeError:
            pass
        if sel == []:
            FreeCAD.Console.PrintError("Select the edges to join first !\n")
        for selobj in sel:
            if selobj.HasSubObjects:
                for i in range(len(selobj.SubObjects)):
                    if isinstance(selobj.SubObjects[i], Part.Edge):
                        edges.append((selobj.Object, selobj.SubElementNames[i]))
            else:
                self.makeJoinFeature(selobj.Object)
                selobj.Object.ViewObject.Visibility=False
        if edges:
            self.makeJoinFeature(edges)
        #joinCurve = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","JoinCurve")
        #join(joinCurve)
        #joinVP(joinCurve.ViewObject)
        #joinCurve.Edges = edges
        #FreeCAD.ActiveDocument.recompute()
        #joinCurve.ViewObject.LineWidth = 2.0
        #joinCurve.ViewObject.LineColor = (0.3,0.0,0.5) 
Example #30
Source File: libS2R.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def setProfiles(self, plist):
        data = []
        self.knots1, self.knots2 = [],[]
        for pro in plist:
            pts = pro.discretize(100)
            bspline = Part.BSplineCurve()
            bspline.approximate(Points = pts, ParamType = 'Chordlength') # 'Uniform' 'Centripetal'
            bs = Part.Edge(bspline) #, pro.FirstParameter, pro.LastParameter)
            data.append(self.getContactParams(bs))
        sortedProfs = sorted(data,key=itemgetter(0)) # Sort profiles on rail1ContactParam
        self.profiles = []
        for datum in sortedProfs:
            self.knots1.append(datum[0])
            self.knots2.append(datum[1])
            p = profile(datum[2])
            p.Rail1Param = datum[0]
            p.Rail2Param = datum[1]
            p.FirstParameter = datum[3]
            p.LastParameter = datum[4]
            self.getLocalProfile(p)
            self.profiles.append(p)
            FreeCAD.Console.PrintMessage("\n Profile : %f - %f\n"%(p.Rail1Param,p.Rail2Param))
        if len(plist) == 1:
            self.extend = True
            FreeCAD.Console.PrintMessage('\n1 Profile given\n')
        FreeCAD.Console.PrintMessage('\nProfiles sorted\n')