def getinteredge(alist,pnt,shape = False): # objlist and a Vertex if type(alist) <> list: return(alist) if shape: D = max obj=0 pt = Part.Vertex(pnt) for i in alist: d = getd(i,pt) if d < D: D = d obj = i return(obj) else: D = max obj=0 pt = Part.Vertex(pnt) for i in alist: d = getd(i.Shape.Edge1,pt) if d < D: D = d obj = i return(obj)
def onChanged(self, fp, prop): debug("Hook : onChanged -> %s" % str(prop)) #print fp if not fp.Edge: return else: e = self.getEdge(fp) #if prop == "Edge": #self.setEdge( fp) if prop == "Method": if fp.Method == "Fixed": self.setEditormode(fp, [0, 0, 0, 2, 2, 2]) fp.X = fp.Center.x fp.Y = fp.Center.y fp.Z = fp.Center.z elif fp.Method == "Parameter": self.setEditormode(fp, [2, 2, 2, 0, 2, 2]) v = Part.Vertex(fp.Center) try: fp.Parameter = e.Curve.parameter(fp.Center) except: pass elif fp.Method == "Distance-From-Start": self.setEditormode(fp, [2, 2, 2, 2, 0, 2]) par = e.getParameterByLength(fp.StartDistance) fp.Center = e.valueAt(par) elif fp.Method == "Distance-From-End": self.setEditormode(fp, [2, 2, 2, 2, 2, 0]) par = e.getParameterByLength(e.Length - fp.EndDistance) fp.Center = e.valueAt(par) if prop in ['X', 'Y', 'Z']: p = FreeCAD.Vector(fp.X, fp.Y, fp.Z) v = Part.Vertex(p) center = v.distToShape(e)[1][0][1] fp.Center = center if prop == "Parameter": if fp.Parameter < e.FirstParameter: fp.Parameter = e.FirstParameter elif fp.Parameter > e.LastParameter: fp.Parameter = e.LastParameter debug("Hook : Parameter changed to %f" % (fp.Parameter)) fp.Center = e.valueAt(fp.Parameter) if prop == "StartDistance": if fp.StartDistance < 0.0: fp.StartDistance = 0.0 elif fp.StartDistance > e.Length: fp.StartDistance = e.Length par = e.getParameterByLength(fp.StartDistance) fp.Center = e.valueAt(par) debug("Hook : StartDistance changed to %f" % (fp.StartDistance)) if prop == "EndDistance": if fp.EndDistance < 0: fp.EndDistance = 0 elif fp.EndDistance > e.Length: fp.EndDistance = e.Length par = e.getParameterByLength(e.Length - fp.EndDistance) fp.Center = e.valueAt(par) debug("Hook : EndDistance changed to %f" % (fp.EndDistance))
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 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 execute(self, obj): import Part #try for problem backward compatibility try: if obj.Internal: shape = None if obj.InternalRegion["Type"] == "Box": x = obj.InternalRegion["Center"][ "x"] * 1000 - obj.InternalRegion["BoxLengths"][ "x"] * 1000 / 2.0 y = obj.InternalRegion["Center"][ "y"] * 1000 - obj.InternalRegion["BoxLengths"][ "y"] * 1000 / 2.0 z = obj.InternalRegion["Center"][ "z"] * 1000 - obj.InternalRegion["BoxLengths"][ "z"] * 1000 / 2.0 shape = Part.makeBox( obj.InternalRegion["BoxLengths"]["x"] * 1000, obj.InternalRegion["BoxLengths"]["y"] * 1000, obj.InternalRegion["BoxLengths"]["z"] * 1000, Base.Vector(x, y, z)) elif obj.InternalRegion["Type"] == "Sphere": shape = Part.makeSphere( obj.InternalRegion["SphereRadius"] * 1000, Base.Vector(obj.InternalRegion["Center"]["x"] * 1000, obj.InternalRegion["Center"]["y"] * 1000, obj.InternalRegion["Center"]["z"] * 1000)) elif obj.InternalRegion["Type"] == "Cone": p1 = Base.Vector(obj.InternalRegion["Point1"]["x"] * 1000, obj.InternalRegion["Point1"]["y"] * 1000, obj.InternalRegion["Point1"]["z"] * 1000) p2 = Base.Vector(obj.InternalRegion["Point2"]["x"] * 1000, obj.InternalRegion["Point2"]["y"] * 1000, obj.InternalRegion["Point2"]["z"] * 1000) h = (p2 - p1).Length if h > 0: if obj.InternalRegion["Radius1"] == obj.InternalRegion[ "Radius2"]: # makeCone fails in this special case shape = Part.makeCylinder( obj.InternalRegion["Radius1"] * 1000, h, p1, (p2 - p1) / (h + 1e-8)) else: shape = Part.makeCone( obj.InternalRegion["Radius1"] * 1000, obj.InternalRegion["Radius2"] * 1000, h, p1, (p2 - p1) / (h + 1e-8)) if shape: obj.Shape = shape else: obj.Shape = Part.Vertex() else: obj.Shape = Part.Vertex() except AttributeError: #print("""In order to view a shape corresponding to the internal region please #re-create the refinement object""") pass
def derivedExecute(self,obj): #validity check if not latticeBaseFeature.isObjectLattice(obj.Base): latticeExecuter.warning(obj,"A lattice object is expected as Base, but a generic shape was provided. It will be treated as a lattice object; results may be unexpected.") output = [] #variable to receive the final list of placements leaves = LCE.AllLeaves(obj.Base.Shape) input = [leaf.Placement for leaf in leaves] if obj.FilterType == 'bypass': output = input elif obj.FilterType == 'specific items': flags = [False] * len(input) ranges = obj.items.split(';') for r in ranges: r_v = r.split(':') if len(r_v) == 1: i = int(r_v[0]) output.append(input[i]) flags[i] = True elif len(r_v) == 2 or len(r_v) == 3: ifrom = None if len(r_v[0].strip()) == 0 else int(r_v[0]) ito = None if len(r_v[1].strip()) == 0 else int(r_v[1]) istep = None if len(r_v[2].strip()) == 0 else int(r_v[2]) output=output+input[ifrom:ito:istep] for b in flags[ifrom:ito:istep]: b = True else: raise ValueError('index range cannot be parsed:'+r) if obj.Invert : output = [] for i in xrange(0,len(input)): if not flags[i]: output.append(input[i]) elif obj.FilterType == 'collision-pass': stencil = obj.Stencil.Shape for plm in input: pnt = Part.Vertex(plm.Base) d = pnt.distToShape(stencil) if bool(d[0] < DistConfusion) ^ bool(obj.Invert): output.append(plm) elif obj.FilterType == 'window-distance': vals = [0.0] * len(input) for i in xrange(0,len(input)): if obj.FilterType == 'window-distance': pnt = Part.Vertex(input[i].Base) vals[i] = pnt.distToShape(obj.Stencil.Shape)[0] valFrom = obj.WindowFrom valTo = obj.WindowTo for i in xrange(0,len(input)): if bool(vals[i] >= valFrom and vals[i] <= valTo) ^ obj.Invert: output.append(input[i]) else: raise ValueError('Filter mode not implemented:'+obj.FilterType) return output
def testBasicBoundingBox(self): v = Vertex(Part.Vertex(1, 1, 1)) v2 = Vertex(Part.Vertex(2, 2, 2)) self.assertEqual(BoundBox, type(v.BoundingBox())) self.assertEqual(BoundBox, type(v2.BoundingBox())) bb1 = v.BoundingBox().add(v2.BoundingBox()) self.assertEqual(bb1.xlen, 1.0)
def getVertexes(shape): v = shape.Vertexes if v or shape.countElement('Edge')!=1: return v curve = shape.Edge1.Curve if isinstance(curve,Part.Line): return [Part.Vertex(curve.Location), Part.Vertex(curve.Location+curve.Direction)] return []
def execute(self, obj): ''' this method is mandatory. It is called on Document.recompute() ''' # create a shape corresponding to the type of hole shape = None if obj.Type == "Point": # set the shape as a Vertex at relative position obj.X, obj.Y, obj.Z # The shape will then be adjusted according to the object Placement ver = FreeCAD.Version() # need to work-around a pesky bug in FreeCAD 0.17(.13541 at the time of writing) # that impacts the save/reload when there is a shape with a single Vertex. # In this case, the .brep file inside the .FCStd file does NOT contain any # placement information. So the object Placement is restored from the # Document.xml but then it is overwritten by the Shape placement that # is then zero. This bug is not affecting FreeCAD version 0.18(.15593 at the time of writing). # As the shape is anyway recreated at recompute() time, the following w/a is valid # also between 0.17 and 0.18. if (int(ver[0]) > 0) or (int(ver[0]) == 0 and int(ver[1]) > 17): shape = Part.Vertex(self.getRelCoord()) else: shape1 = Part.Vertex(self.getRelCoord()) shape = Part.makeCompound([shape1]) elif obj.Type == "Rect": if obj.Length <= 0 or obj.Width <= 0: FreeCAD.Console.PrintWarning( translate( "EM", "Cannot create a FHPlaneHole rectangular hole with zero length or width" )) else: v0 = self.getRelCoord() v1 = v0 + Vector(obj.Length, 0, 0) v2 = v0 + Vector(obj.Length, obj.Width, 0) v3 = v0 + Vector(0, obj.Width, 0) # and create the rectangle poly = Part.makePolygon([v0, v1, v2, v3, v0]) shape = Part.Face(poly) elif obj.Type == "Circle": if obj.Radius <= 0: FreeCAD.Console.PrintWarning( translate( "EM", "Cannot create a FHPlaneHole circular hole with zero radius" )) else: # create a circle in the x,y plane (axis is along z) circle = Part.Circle(self.getRelCoord(), Vector(0, 0, 1), obj.Radius) edge = circle.toShape() wire = Part.Wire(edge) shape = Part.Face(wire) if shape: obj.Shape = shape
def sortEm(mywire, unmatched): remaining = [] wireGrowing = False # end points of existing wire wireverts = [ mywire.Edges[0].valueAt(mywire.Edges[0].FirstParameter), mywire.Edges[-1].valueAt(mywire.Edges[-1].LastParameter) ] for i, candidate in enumerate(unmatched): # end points of candidate edge cverts = [ candidate.Edges[0].valueAt( candidate.Edges[0].FirstParameter), candidate.Edges[-1].valueAt( candidate.Edges[-1].LastParameter) ] # ignore short segments below tolerance level if PathGeom.pointsCoincide(cverts[0], cverts[1], obj.Tolerance): continue # iterate the combination of endpoints. If a match is found, # make an edge from the common endpoint to the other end of # the candidate wire. Add the edge to the wire and return it. # This generates a new edge rather than using the candidate to # avoid vertexes with close but different vectors for wvert in wireverts: for idx, cvert in enumerate(cverts): if PathGeom.pointsCoincide(wvert, cvert, obj.Tolerance): wireGrowing = True elist = mywire.Edges otherIndex = int(not (idx)) newedge = Part.Edge( Part.Vertex(wvert), Part.Vertex(cverts[otherIndex])) elist.append(newedge) mywire = Part.Wire(Part.__sortEdges__(elist)) remaining.extend(unmatched[i + 1:]) return mywire, remaining, wireGrowing # if not matched, add to remaining list to test later remaining.append(candidate) return mywire, remaining, wireGrowing
def testVertex(self): """ Tests basic vertex functions """ # Tests casting a vertex vc = Vertex.cast(Part.Vertex(1, 1, 1)) self.assertEqual(1, vc.X) self.assertEqual(Vector, type(vc.Center())) # Tests vertex instantiation v = Vertex(Part.Vertex(1, 1, 1)) self.assertEqual(1, v.X) self.assertEqual(Vector, type(v.Center()))
def project_solid_normals(shell, pts, thickness, add_plus=True, add_minus=True, predicate_plus=None, predicate_minus=None): k = 0.5 * thickness result = [] for pt in pts: dist, vs, infos = shell.distToShape(Part.Vertex(Base.Vector(pt))) projection = vs[0][0] info = infos[0] if info[0] == b'Face': face_idx = info[1] u, v = info[2] normal = shell.Faces[face_idx].normalAt(u, v) plus_pt = projection + k * normal minus_pt = projection - k * normal if add_plus: if predicate_plus is None or predicate_plus(plus_pt): result.append(tuple(plus_pt)) if add_minus: if predicate_minus is None or predicate_minus(minus_pt): result.append(tuple(minus_pt)) return result
def drawdelaunay(vertices,faces): d=FreeCAD.newDocument("drawdelaunay") points_cloud=[] triang_faces=[] for vt in vertices: o=Part.Vertex(vt) points_cloud.append(o) for ft in faces: eg1 = Part.makeLine(vertices[ft[0]],vertices[ft[2]]) eg2 = Part.makeLine(vertices[ft[2]],vertices[ft[1]]) eg3 = Part.makeLine(vertices[ft[1]],vertices[ft[0]]) wire = Part.Wire([eg1, eg2, eg3]) face = Part.Face(wire) triang_faces.append(face) tu01=Part.Compound(points_cloud) tu02=Part.Compound(triang_faces) # FreeCADGui.showMainWindow() Part.show(tu01) Part.show(tu02) FreeCADGui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewTop() Gui.activeDocument().getObject("Shape001").DisplayMode = "Shaded"
def getIndices(shape,offset): "returns a list with 2 lists: vertices and face indexes, offsetted with the given amount" vlist = [] elist = [] flist = [] for v in shape.Vertexes: vlist.append(" "+str(round(v.X,p))+" "+str(round(v.Y,p))+" "+str(round(v.Z,p))) if not shape.Faces: for e in shape.Edges: if isinstance(e,Part.Line): ei = " " + str(findVert(e.Vertexes[0],shape.Vertexes) + offset) ei += " " + str(findVert(e.Vertexes[-1],shape.Vertexes) + offset) elist.append(ei) for f in shape.Faces: if len(f.Wires) > 1: # if we have holes, we triangulate tris = f.tessellate(1) for fdata in tris[1]: fi = "" for vi in fdata: vdata = Part.Vertex(tris[0][vi]) fi += " " + str(findVert(vdata,shape.Vertexes) + offset) flist.append(fi) else: fi = "" # OCC vertices are unsorted. We need to sort in the right order... edges = DraftGeomUtils.sortEdges(f.Wire.Edges) #print edges for e in edges: #print e.Vertexes[0].Point,e.Vertexes[1].Point v = e.Vertexes[0] fi += " " + str(findVert(v,shape.Vertexes) + offset) flist.append(fi) return vlist,elist,flist
def get_points(self, fp): shapes = self.get_shapes(fp) if not len(fp.Data) == len(fp.DataType): FreeCAD.Console.PrintError( "Gordon Profile : Data and DataType mismatch\n") return (None) else: pts = list() shape_idx = 0 for i in range(len(fp.Data)): if fp.DataType[i] == 0: # Free point pts.append(fp.Data[i]) elif (fp.DataType[i] == 1): if (shape_idx < len(shapes)): # project on shape d, p, i = Part.Vertex(fp.Data[i]).distToShape( shapes[shape_idx]) pts.append( p[0][1]) #shapes[shape_idx].valueAt(fp.Data[i].x)) shape_idx += 1 else: pts.append(fp.Data[i]) #elif fp.DataType[i] == 2: # datum is parameter on shape #if isinstance(shapes[shape_idx],Part.Vertex): #pts.append(shapes[shape_idx].Point) #elif isinstance(shapes[shape_idx],Part.Edge): #pts.append(shapes[shape_idx].valueAt(fp.Data[i].x)) #elif isinstance(shapes[shape_idx],Part.Face): #pts.append(shapes[shape_idx].valueAt(fp.Data[i].x,fp.Data[i].y)) #shape_idx += 1 return (pts) return (None)
def _makeChord(self, chord, rootLength2): height = float(chord[0].z) if len(chord) > 1: chordLength = float(chord[1].x - chord[0].x) offset = float(chord[1].x) profile = self._makeChordProfile(self._obj.RootCrossSection, offset, chordLength, float(self._obj.RootThickness), height, self._obj.RootPerCent, float(self._obj.RootLength1), rootLength2) elif self._obj.RootCrossSection in [ FIN_CROSS_SQUARE, FIN_CROSS_WEDGE, FIN_CROSS_DIAMOND, FIN_CROSS_TAPER_LE, FIN_CROSS_TAPER_TE, FIN_CROSS_TAPER_LETE ]: chordLength = 1e-6 # Very small chord length offset = float(chord[0].x) profile = self._makeChordProfile(self._obj.RootCrossSection, offset, chordLength, float(self._obj.RootThickness), height, self._obj.RootPerCent, float(self._obj.RootLength1), rootLength2) else: profile = Part.Vertex( FreeCAD.Vector(float(chord[0].x), 0.0, float(chord[0].z))) return profile
def execute(self, obj): import Part #try for problem backward compatibility try: if obj.Internal: if obj.InternalRegion["Type"] == "Box": x = obj.InternalRegion["Center"][ "x"] * 1000 - obj.InternalRegion["BoxLengths"][ "x"] * 1000 / 2.0 y = obj.InternalRegion["Center"][ "y"] * 1000 - obj.InternalRegion["BoxLengths"][ "y"] * 1000 / 2.0 z = obj.InternalRegion["Center"][ "z"] * 1000 - obj.InternalRegion["BoxLengths"][ "z"] * 1000 / 2.0 shape = Part.makeBox( obj.InternalRegion["BoxLengths"]["x"] * 1000, obj.InternalRegion["BoxLengths"]["y"] * 1000, obj.InternalRegion["BoxLengths"]["z"] * 1000, Base.Vector(x, y, z)) elif obj.InternalRegion["Type"] == "Sphere": shape = Part.makeSphere( obj.InternalRegion["SphereRadius"] * 1000, Base.Vector(obj.InternalRegion["Center"]["x"] * 1000, obj.InternalRegion["Center"]["y"] * 1000, obj.InternalRegion["Center"]["z"] * 1000)) obj.Shape = shape else: obj.Shape = Part.Vertex() except AttributeError: #print("""In order to view a shape corresponding to the internal region please #re-create the refinement object""") pass
def testVertex(self): """ Tests basic vertex functions """ v = Vertex(Part.Vertex(1, 1, 1)) self.assertEqual(1, v.X) self.assertEquals(Vector, type(v.Center()))
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)
def shapeCloud(self): v = [] for row in self.result: for pt in row: v.append(Part.Vertex(pt)) c = Part.Compound(v) return(c)
def generate_bspline_patch(vertices, n_nodes, degree, knots): """ Generates a bspine patch from the given vertices. Parameters like degree of the patch, knot vector and number of control points are defined above. :param vertices: lexicographically numbered control points in a 2D Array of 3 component points """ n_nodes_u = n_nodes n_nodes_v = n_nodes degree_u = degree degree_v = degree knot_u = knots knot_v = knots patch = Part.BSplineSurface() patch.increaseDegree(degree_u, degree_v) for i in range(4, len(knot_u)-4): patch.insertUKnot(knot_u[i], 1, 0) # todo why is the second argument equal to 1? If anyone could explain = awesome for i in range(4, len(knot_v)-4): patch.insertVKnot(knot_v[i], 1, 0) # todo why is the second argument equal to 1? If anyone could explain = awesome for ii in range(0, n_nodes_u): for jj in range(0, n_nodes_v): k = ii + jj * n_nodes_u v = vertices[k] control_point = FreeCAD.Vector(v[0], v[1], v[2]) patch.setPole(ii + 1, jj + 1, control_point, 1) if(PLOT_CONTROL_POINTS): Part.show(Part.Vertex(control_point)) # plotting corresponding control points, switched on/off in configuration section return patch.toShape()
def compute_tangents(self): tans = list() flags = list() for i in range(len(self.points)): if isinstance(self.points[i].shape,Part.Face): for vec in self.points[i].points: u,v = self.points[i].shape.Surface.parameter(FreeCAD.Vector(vec)) norm = self.points[i].shape.normalAt(u,v) cp = self.curve.parameter(FreeCAD.Vector(vec)) t = self.curve.tangent(cp)[0] pl = Part.Plane(FreeCAD.Vector(),norm) ci = Part.Geom2d.Circle2d() ci.Radius = t.Length * 2 w = Part.Wire([ci.toShape(pl)]) f = Part.Face(w) #proj = f.project([Part.Vertex(t)]) proj = Part.Vertex(t).distToShape(f)[1][0][1] #pt = proj.Vertexes[0].Point #FreeCAD.Console.PrintMessage("Projection %s -> %s\n"%(t,proj)) if proj.Length > 1e-7: tans.append(proj) flags.append(True) else: tans.append(FreeCAD.Vector(1,0,0)) flags.append(False) else: for vec in self.points[i].points: tans.append(FreeCAD.Vector(1,0,0)) flags.append(False) return(tans,flags)
def shapeCloud(arr): v = [] for row in arr: for pt in row: v.append(Part.Vertex(pt)) c = Part.Compound(v) return (c)
def dist(x): t = x[0] sfa = Part.BSplineSurface() ap[3:7, 4:8] = sppoles + dirtt * t sfa.buildFromPolesMultsKnots(ap, mu, mv, uk, vk, False, False, ud, vd) return sfa.toShape().distToShape(Part.Vertex(target))[0]
def getIndices(shape,offset): "returns a list with 2 lists: vertices and face indexes, offsetted with the given amount" vlist = [] elist = [] flist = [] curves = None if isinstance(shape,Part.Shape): for e in shape.Edges: try: if not isinstance(e.Curve,Part.LineSegment): if not curves: curves = shape.tessellate(1) FreeCAD.Console.PrintWarning(translate("Arch","Found a shape containing curves, triangulating\n").decode('utf8')) break except: # unimplemented curve type curves = shape.tessellate(1) FreeCAD.Console.PrintWarning(translate("Arch","Found a shape containing curves, triangulating\n").decode('utf8')) break elif isinstance(shape,Mesh.Mesh): curves = shape.Topology if curves: for v in curves[0]: vlist.append(" "+str(round(v.x,p))+" "+str(round(v.y,p))+" "+str(round(v.z,p))) for f in curves[1]: fi = "" for vi in f: fi += " " + str(vi + offset) flist.append(fi) else: for v in shape.Vertexes: vlist.append(" "+str(round(v.X,p))+" "+str(round(v.Y,p))+" "+str(round(v.Z,p))) if not shape.Faces: for e in shape.Edges: if DraftGeomUtils.geomType(e) == "Line": ei = " " + str(findVert(e.Vertexes[0],shape.Vertexes) + offset) ei += " " + str(findVert(e.Vertexes[-1],shape.Vertexes) + offset) elist.append(ei) for f in shape.Faces: if len(f.Wires) > 1: # if we have holes, we triangulate tris = f.tessellate(1) for fdata in tris[1]: fi = "" for vi in fdata: vdata = Part.Vertex(tris[0][vi]) fi += " " + str(findVert(vdata,shape.Vertexes) + offset) flist.append(fi) else: fi = "" for e in f.OuterWire.OrderedEdges: #print(e.Vertexes[0].Point,e.Vertexes[1].Point) v = e.Vertexes[0] ind = findVert(v,shape.Vertexes) if ind == None: return None,None,None fi += " " + str(ind + offset) flist.append(fi) return vlist,elist,flist
def execute(self, obj): e, w = self.getShape(obj) params = [] if hasattr(obj, "Values"): params = self.parse_values(e, obj.Values) if params == []: if w: obj.Shape = obj.Source[0].Shape else: obj.Shape = e return if params[0] > e.FirstParameter: params.insert(0, e.FirstParameter) if params[-1] < e.LastParameter: params.append(e.LastParameter) if w: # No subshape given, take wire 1 edges = w.Edges for i in range(len(params)): p = e.valueAt(params[i]) d, pts, info = Part.Vertex(p).distToShape(w) #print(info) if info[0][3] == "Edge": n = info[0][4] nw = w.Edges[n].split(info[0][5]) nw.Placement = w.Edges[n].Placement if len(nw.Edges) == 2: edges[n] = nw.Edges[0] edges.insert(n + 1, nw.Edges[1]) #print([e.Length for e in edges]) se = Part.sortEdges(edges) if len(se) > 1: FreeCAD.Console.PrintError( "Split curve : failed to build temp Wire !") #print(se) w = Part.Wire(se[0]) else: edges = [] for i in range(len(params) - 1): c = e.Curve.trim(params[i], params[i + 1]) edges.append(c.toShape()) se = Part.sortEdges(edges) if len(se) > 1: FreeCAD.Console.PrintError( "Split curve : failed to build final Wire !") wires = [] for el in se: wires.append(Part.Wire(el)) w = Part.Compound(wires) else: w = Part.Wire(se[0]) if w.isValid(): obj.Shape = w else: FreeCAD.Console.PrintError("Split curve : Invalid Wire !") obj.Shape = e
def selectFacePoint(self, shape, point): '''selectFacePoint(self, shape, point)''' vertex = Part.Vertex(point) for ff in shape.Faces: section = vertex.section([ff], _Py.tolerance) if section.Vertexes: return ff
def pointIsOnPath(self, p): v = Part.Vertex(self.pointAtBottom(p)) PathLog.debug("pt = (%f, %f, %f)" % (v.X, v.Y, v.Z)) for e in self.bottomEdges: indent = "{} ".format(e.distToShape(v)[0]) debugEdge(e, indent, True) if PathGeom.isRoughly(0.0, v.distToShape(e)[0], 0.1): return True return False
def getIndices(shape, offset): "returns a list with 2 lists: vertices and face indexes, offsetted with the given amount" vlist = [] elist = [] flist = [] curves = None for e in shape.Edges: if not isinstance(e.Curve, Part.Line): if not curves: curves = shape.tessellate(1) FreeCAD.Console.PrintWarning( translate( "Arch", "Found a shape containing curves, triangulating\n")) if curves: for v in curves[0]: vlist.append(" " + str(round(v.x, p)) + " " + str(round(v.y, p)) + " " + str(round(v.z, p))) for f in curves[1]: fi = "" for vi in f: fi += " " + str(vi + offset) flist.append(fi) else: for v in shape.Vertexes: vlist.append(" " + str(round(v.X, p)) + " " + str(round(v.Y, p)) + " " + str(round(v.Z, p))) if not shape.Faces: for e in shape.Edges: if DraftGeomUtils.geomType(e) == "Line": ei = " " + str( findVert(e.Vertexes[0], shape.Vertexes) + offset) ei += " " + str( findVert(e.Vertexes[-1], shape.Vertexes) + offset) elist.append(ei) for f in shape.Faces: if len(f.Wires) > 1: # if we have holes, we triangulate tris = f.tessellate(1) for fdata in tris[1]: fi = "" for vi in fdata: vdata = Part.Vertex(tris[0][vi]) fi += " " + str( findVert(vdata, shape.Vertexes) + offset) flist.append(fi) else: fi = "" # OCC vertices are unsorted. We need to sort in the right order... edges = DraftGeomUtils.sortEdges(f.OuterWire.Edges) #print edges for e in edges: #print e.Vertexes[0].Point,e.Vertexes[1].Point v = e.Vertexes[0] fi += " " + str(findVert(v, shape.Vertexes) + offset) flist.append(fi) return vlist, elist, flist
def getEdges(vd, color=[PRIMARY]): if type(color) == int: color = [color] geomList = [] bblevel = self.model[0].Shape.BoundBox.ZMin for e in vd.Edges: if e.Color not in color: continue if e.toGeom() is None: continue p1 = e.Vertices[0].toGeom(calculate_depth(e.getDistances()[0], bblevel)) p2 = e.Vertices[-1].toGeom(calculate_depth(e.getDistances()[-1], bblevel)) newedge = Part.Edge(Part.Vertex(p1), Part.Vertex(p2)) newedge.fixTolerance(obj.Tolerance, Part.Vertex) geomList.append(newedge) return geomList