def migrate(self, fp): if hasattr(fp, "DegreeMax"): fp.removeProperty("DegreeMax") if not hasattr(fp, "AutoScale"): fp.addProperty( "App::PropertyBool", "AutoScale", "BlendCurve", "Compute scales to get minimal curvature along curve" ).AutoScale = False if not hasattr(fp, "Reverse1"): fp.addProperty("App::PropertyBool", "Reverse1", "Edge1", "Reverse Edge").Reverse1 = False if not hasattr(fp, "Reverse2"): fp.addProperty("App::PropertyBool", "Reverse2", "Edge2", "Reverse Edge").Reverse2 = False if fp.getTypeIdOfProperty( "Parameter1") == "App::PropertyFloatConstraint": e1 = _utils.getShape(fp, "Edge1", "Edge") val = fp.Parameter1 * e1.Length fp.removeProperty("Parameter1") fp.addProperty("App::PropertyDistance", "Parameter1", "Edge1", "Location on first edge") fp.Parameter1 = val if fp.getTypeIdOfProperty( "Parameter2") == "App::PropertyFloatConstraint": e2 = _utils.getShape(fp, "Edge2", "Edge") val = fp.Parameter2 * e2.Length fp.removeProperty("Parameter2") fp.addProperty("App::PropertyDistance", "Parameter2", "Edge1", "Location on second edge") fp.Parameter2 = val
def compute(self, fp): e1 = _utils.getShape(fp, "Edge1", "Edge") e2 = _utils.getShape(fp, "Edge2", "Edge") r1 = r2 = 1.0 if fp.Reverse1: r1 = -1.0 if fp.Reverse2: r2 = -1.0 if e1 and e2: # p1 = e1.getParameterByLength(fp.Parameter1) # p2 = e2.getParameterByLength(fp.Parameter2) c1 = blend_curve.PointOnEdge(e1) c1.distance = r1 * fp.Parameter1 c1.continuity = self.getContinuity(fp.Continuity1) # c1.scale = fp.Scale1 c2 = blend_curve.PointOnEdge(e2) c2.distance = r2 * fp.Parameter2 c2.continuity = self.getContinuity(fp.Continuity2) # c2.scale = fp.Scale2 bc = blend_curve.BlendCurve(c1, c2) bc.nb_samples = 200 # bc.auto_scale() bc.scale1 = fp.Scale1 bc.scale2 = fp.Scale2 bc.perform() return bc
def onChanged(self, fp, prop): if prop == "AutoScale" and fp.AutoScale: fp.setEditorMode("Scale1", 2) fp.setEditorMode("Scale2", 2) if prop == "AutoScale" and not fp.AutoScale: fp.setEditorMode("Scale1", 0) fp.setEditorMode("Scale2", 0) elif prop == "Scale1": if fp.Scale1 == 0: fp.Scale1 = 0.0001 if not fp.AutoScale: self.execute(fp) elif prop == "Scale2": if fp.Scale2 == 0: fp.Scale2 = 0.0001 if not fp.AutoScale: self.execute(fp) elif prop == "Parameter1": e1 = _utils.getShape(fp, "Edge1", "Edge") if fp.Parameter1 > e1.Length: fp.Parameter1 = e1.Length elif fp.Parameter1 < 0.0: fp.Parameter1 = 0.0 elif prop == "Parameter2": e2 = _utils.getShape(fp, "Edge2", "Edge") if fp.Parameter2 > e2.Length: fp.Parameter2 = e2.Length elif fp.Parameter2 < 0.0: fp.Parameter2 = 0.0 if prop in ("Parameter1", "Parameter2", "Continuity1", "Continuity2" "Output"): self.execute(fp)
def update_shape(self): e1 = _utils.getShape(self.Object, "Edge1", "Edge") e2 = _utils.getShape(self.Object, "Edge2", "Edge") if self.bc: # self.bc.constraints = [] # bc = nurbs_tools.blendCurve(e1, e2) v = Part.Vertex(self.m1.point) proj = v.distToShape(self.m1.snap_shape)[1][0][1] param1 = self.get_param(e1, proj) # self.get_length(e1, proj) # bc.param1 = (pa1 - self.m1.snap_shape.FirstParameter) / (self.m1.snap_shape.LastParameter - self.m1.snap_shape.FirstParameter) cont1 = self.Object.Proxy.getContinuity(self.c1.text[0]) self.bc.point1 = blend_curve.PointOnEdge(e1, param1, cont1) self.bc.scale1 = self.t1.parameter v = Part.Vertex(self.m2.point) proj = v.distToShape(self.m2.snap_shape)[1][0][1] param2 = self.get_param(e2, proj) # self.get_length(e2, proj) # bc.param2 = (pa2 - self.m2.snap_shape.FirstParameter) / (self.m2.snap_shape.LastParameter - self.m2.snap_shape.FirstParameter) cont2 = self.Object.Proxy.getContinuity(self.c2.text[0]) self.bc.point2 = blend_curve.PointOnEdge(e2, param2, cont2) self.bc.scale2 = -self.t2.parameter self.bc.perform() self.Object.Shape = self.bc.shape return self.bc
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 = self.get_length( e1, proj) # e1.Curve.toShape(e1.FirstParameter, pa1).Length 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.Parameter2 = self.get_length( e2, proj) # e2.Curve.toShape(e2.FirstParameter, pa2).Length 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
def execute(self, obj): v1 = _utils.getShape(obj, "Vertex1", "Vertex") v2 = _utils.getShape(obj, "Vertex2", "Vertex") if v1 and v2: l = Part.LineSegment(v1.Point, v2.Point) obj.Shape = l.toShape() else: FreeCAD.Console.PrintError("%s broken !\n" % obj.Label)
def onChanged(self, obj, prop): if prop == "Parameter": e = _utils.getShape(obj, "Edge", "Edge") f = _utils.getShape(obj, "Face", "Face") p = e.FirstParameter + (e.LastParameter - e.FirstParameter) * obj.Parameter loc = e.valueAt(p) u, v = f.Surface.parameter(loc) norm = f.normalAt(u, v) #print("{0!s} - {1!s}".format(p, loc)) x = norm.cross(e.tangentAt(p)) rot = FreeCAD.Rotation(x, norm, e.tangentAt(p)) obj.Placement.Base = loc obj.Placement.Rotation = rot
def execute(self, obj): f = _utils.getShape(obj, "Source", "Face") bs = f.toNurbs().Faces[0].Surface surfs = list() u0, u1, v0, v1 = bs.bounds() cutKnotsU = [u0, u1] cutKnotsV = [v0, v1] if obj.Option == "Auto": if obj.Direction in ["U", "Both"]: knots = bs.getUKnots() mults = bs.getUMultiplicities() cutKnotsU = self.get_intervals(knots, mults) if obj.Direction in ["V", "Both"]: knots = bs.getVKnots() mults = bs.getVMultiplicities() cutKnotsV = self.get_intervals(knots, mults) elif obj.Option == "Custom": for k in obj.KnotsU: if (k > u0) and (k < u1): cutKnotsU.append(k) for k in obj.KnotsV: if (k > v0) and (k < v1): cutKnotsV.append(k) cutKnotsU = list(set(cutKnotsU)) cutKnotsV = list(set(cutKnotsV)) cutKnotsU.sort() cutKnotsV.sort() for i in range(len(cutKnotsU) - 1): for j in range(len(cutKnotsV) - 1): s = bs.copy() s.segment(cutKnotsU[i], cutKnotsU[i + 1], cutKnotsV[j], cutKnotsV[j + 1]) surfs.append(s) obj.Shape = Part.Shell([s.toShape() for s in surfs])
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
def compute(self, fp): e1 = _utils.getShape(fp, "Edge1", "Edge") e2 = _utils.getShape(fp, "Edge2", "Edge") if e1 and e2: bc = nurbs_tools.blendCurve(e1, e2) bc.param1 = e1.FirstParameter + fp.Parameter1 * (e1.LastParameter - e1.FirstParameter) bc.param2 = e2.FirstParameter + fp.Parameter2 * (e2.LastParameter - e2.FirstParameter) bc.cont1 = self.getContinuity(fp.Continuity1) bc.cont2 = self.getContinuity(fp.Continuity2) bc.scale1 = fp.Scale1 bc.scale2 = fp.Scale2 bc.maxDegree = fp.DegreeMax bc.compute() return bc return None
def getPoints(self, obj): if obj.Source: return [v.Point for v in obj.Source.Shape.Vertexes] elif obj.PointList: vl = _utils.getShape(obj, "PointList", "Vertex") return [v.Point for v in vl] else: return []
def execute(self, obj): faces = _utils.getShape(obj, "Faces", "Face") shell = Part.Shell(faces) solid = Part.Solid(shell) if solid.isValid(): obj.Shape = solid elif shell.isValid(): obj.Shape = shell else: obj.Shape = Part.Compound(faces)
def execute(self, obj): edge = _utils.getShape(obj, 'InputEdge', 'Edge') # self.getEdge(obj) face = _utils.getShape(obj, 'Face', 'Face') # self.getFace(obj) cos = curveOnSurface.curveOnSurface(edge, face) if obj.Reverse: cos.reverse() if obj.Closed: cos.closed = True cos.reverseTangent = obj.ReverseTangent cos.reverseNormal = obj.ReverseNormal cos.reverseBinormal = obj.ReverseBinormal if obj.Output == "Normal face": obj.Shape = cos.normalFace(obj.Samples, float(obj.FaceWidth), obj.Tolerance, obj.Symmetric) elif obj.Output == "Binormal face": obj.Shape = cos.binormalFace(obj.Samples, float(obj.FaceWidth), obj.Tolerance, obj.Symmetric) else: obj.Shape = cos.getEdge() #obj.Placement.Base = face.Placement.Base return(cos)
def getPoints(self, obj): try: if obj.Source: if hasattr(obj.Source.Shape, "OrderedVertexes"): return [v.Point for v in obj.Source.Shape.OrderedVertexes] else: return [v.Point for v in obj.Source.Shape.Vertexes] elif obj.PointList: vl = _utils.getShape(obj, "PointList", "Vertex") return [v.Point for v in vl] except AttributeError: return []
def get_curves(self, obj): curves = [] edges = [] for o in obj.SourceObjects: curves.extend(o.Shape.Wires) edges.extend(o.Shape.Edges) if len(curves) == 2: return curves[0], curves[1] if len(edges) == 2: return edges[0], edges[1] edges = _utils.getShape(obj, "SourceShapes", "Edge") if len(edges) == 2: return edges[0], edges[1]
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
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
def execute(self, obj): sh = None rl = False if len(obj.IndivFaces) > 0: faces = _utils.getShape(obj, "IndivFaces", "Face") sh = Part.Compound(faces) elif hasattr(obj.Source, "Shape"): sh = obj.Source.Shape try: rl = sh.reflectLines(obj.ViewDir, obj.ViewPos, obj.UpDir) except AttributeError: pass if rl and obj.ShapeCleaning: edges = rl.Edges rl = Part.Compound(nurbs_tools.remove_subsegments(edges, num=obj.Samples, tol=obj.Tolerance)) if rl: obj.Shape = rl
def setEdit(self, vobj, mode=0): debug("BlendCurve Edit mode = %d" % mode) if mode == 0: if vobj.Selectable: self.select_state = True vobj.Selectable = False self.ps = vobj.PointSize vobj.PointSize = 0.0 pts = list() e1 = _utils.getShape(self.Object, "Edge1", "Edge") e2 = _utils.getShape(self.Object, "Edge2", "Edge") pa1 = e1.FirstParameter + ( e1.LastParameter - e1.FirstParameter) * self.Object.Parameter1 pa2 = e2.FirstParameter + ( e2.LastParameter - e2.FirstParameter) * self.Object.Parameter2 d = e1.valueAt(pa1).distanceToPoint(e2.valueAt(pa2)) self.m1 = manipulators.EdgeSnapAndTangent(e1.valueAt(pa1), e1) self.m1.set_color("cyan") self.m1.marker.markerIndex = coin.SoMarkerSet.CIRCLE_LINE_9_9 pts.append(self.m1) self.c1 = manipulators.CycleText(self.m1) self.c1.text_list = ["C0", "G1", "G2", "G3", "G4"] self.c1.text = self.Object.Continuity1 self.c1.show() pts.append(self.c1) self.t1 = manipulators.TangentSnap(self.m1) self.t1._scale = d / 3.0 self.t1.parameter = self.Object.Scale1 pts.append(self.t1) self.tt1 = manipulators.ParameterText(self.t1) self.tt1.show() pts.append(self.tt1) self.m2 = manipulators.EdgeSnapAndTangent(e2.valueAt(pa2), e2) self.m2.set_color("red") self.m2.marker.markerIndex = coin.SoMarkerSet.CIRCLE_LINE_9_9 pts.append(self.m2) self.c2 = manipulators.CycleText(self.m2) self.c2.text_list = ["C0", "G1", "G2", "G3", "G4"] self.c2.text = self.Object.Continuity2 self.c2.show() pts.append(self.c2) self.t2 = manipulators.TangentSnap(self.m2) self.t2._scale = d / 3.0 self.t2.parameter = self.Object.Scale2 pts.append(self.t2) self.tt2 = manipulators.ParameterText(self.t2) self.tt2.show() pts.append(self.tt2) self.ip = pointEditor(pts, self.Object) debug("pointEditor created\n") self.ip.root.on_drag.append(self.update_shape) self.active = True return True return False
def execute(self, obj): debug("\n\nExecuting PipeShell\n") path = None profs = [] edges = _utils.getShape(obj, "Spine", "Edge") path = Part.Wire(Part.__sortEdges__(edges)) if path.isValid(): debug("Valid spine : %s"%path) if hasattr(obj, "Profiles"): profs = obj.Profiles if not (path and profs): return(None) debug("Creating PipeShell") # create the pipeShell object ps = Part.BRepOffsetAPI.MakePipeShell(path) ps.setMaxDegree(self.getprop(obj, "MaxDegree") or 3) ps.setMaxSegments(self.getprop(obj, "MaxSegments") or 32) t3 = self.getprop(obj, "Tol3d") or 1.0e-4 tb = self.getprop(obj, "TolBound") or 1.0e-4 ta = self.getprop(obj, "TolAng") or 1.0e-2 ps.setTolerance(t3, tb, ta) mode = self.getprop(obj, "Mode")# or "DiscreteTrihedron" if mode in ["Binormal","FixedTrihedron"]: direction = self.getprop(obj, "Direction") if not direction: direction = FreeCAD.Vector(0,0,1) obj.Direction = direction FreeCAD.Console.PrintError("\nWrong direction, defaulting to +Z\n") elif direction.Length < 1e-7: direction = FreeCAD.Vector(0,0,1) obj.Direction = direction FreeCAD.Console.PrintError("\nDirection has null length, defaulting to +Z\n") if mode == "Binormal": debug("Binormal mode (%r)"%direction) ps.setBiNormalMode(direction) elif mode == "FixedTrihedron": loc = self.getprop(obj, "Location") or FreeCAD.Vector(0,0,0) debug("FixedTrihedron mode (%r %r)"%(loc, direction)) ps.setTrihedronMode(loc, direction) elif mode == "Frenet": fre = self.getprop(obj, "Corrected") debug("Frenet mode (%r)"%fre) ps.setFrenetMode(fre) elif mode == "AuxiliarySpine": aux = self.getprop(obj, "Auxiliary") w = None if aux: if aux.Shape.Wires: w = aux.Shape.Wires[0] elif aux.Shape.Edges: w = Part.Wire(Part.__sortEdges__(aux.Shape.Edges)) if w: curv = self.getprop(obj, "EquiCurvi") or False cont = self.getprop(obj, "Contact") or "NoContact" n = self.getCode(cont) debug("AuxiliarySpine mode (%r %s)"%(curv,cont)) ps.setAuxiliarySpine(w,curv,n) else: FreeCAD.Console.PrintError("\nPlease set a valid Auxiliary Spine Object\n") elif mode == "ShapeSupport": sup = self.getprop(obj, "Support") sh = None if sup: sh = sup.Shape if sh: debug("ShapeSupport mode") ps.setSpineSupport(sh) else: FreeCAD.Console.PrintError("\nPlease set a valid Spine support Object\n") for p in profs: self.add(ps,p) if ps.isReady(): output = self.getprop(obj, "Output") solid = self.getprop(obj, "Solid") or False if (output == "Surface") or (not hasattr(ps,'simulate')): ps.build() if solid: ps.makeSolid() obj.Shape = ps.shape() else: shapes = ps.simulate(self.getprop(obj, "Samples") or 100) if output == "Lofted sections": obj.Shape = Part.makeLoft(shapes, solid, False, False, self.getprop(obj, "MaxDegree")) else: rails = self.getRails(shapes) c = Part.Compound(shapes + rails) obj.Shape = c else: FreeCAD.Console.PrintError("\nFailed to create shape\n")
def getFace(self, obj): if hasattr(obj, "Face"): return _utils.getShape(obj, "Face", "Face")