本文整理汇总了Python中PathScripts.PathGeom.PathGeom类的典型用法代码示例。如果您正苦于以下问题:Python PathGeom类的具体用法?Python PathGeom怎么用?Python PathGeom使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PathGeom类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: commandsForEdges
def commandsForEdges(self):
if self.edges:
try:
shape = self.shell().common(self.tag.solid)
commands = []
rapid = None
for e, flip in self.orderAndFlipEdges(self.cleanupEdges(shape.Edges)):
debugEdge(e, '++++++++ %s' % ('<' if flip else '>'), False)
p1 = e.valueAt(e.FirstParameter)
p2 = e.valueAt(e.LastParameter)
if self.tag.isSquare and (PathGeom.isRoughly(p1.z, self.maxZ) or p1.z > self.maxZ) and (PathGeom.isRoughly(p2.z, self.maxZ) or p2.z > self.maxZ):
rapid = p1 if flip else p2
else:
if rapid:
commands.append(Path.Command('G0', {'X': rapid.x, 'Y': rapid.y, 'Z': rapid.z}))
rapid = None
commands.extend(PathGeom.cmdsForEdge(e, flip, False, self.segm))
if rapid:
commands.append(Path.Command('G0', {'X': rapid.x, 'Y': rapid.y, 'Z': rapid.z}))
rapid = None
return commands
except Exception as e:
PathLog.error("Exception during processing tag @(%.2f, %.2f) (%s) - disabling the tag" % (self.tag.x, self.tag.y, e.args[0]))
self.tag.enabled = False
commands = []
for e in self.edges:
commands.extend(PathGeom.cmdsForEdge(e))
return commands
return []
示例2: test30
def test30(self):
"""Verify proper geometry for arcs with rising and fall ing Z-axis are created."""
#print("------ rising helix -------")
p1 = Vector(0, 1, 0)
p2 = Vector(1, 0, 2)
self.assertCurve(
PathGeom.edgeForCmd(
Path.Command('G2', {'X': p2.x, 'Y': p2.y, 'Z': p2.z, 'I': 0, 'J': -1, 'K': 1}), p1),
p1, Vector(1/math.sqrt(2), 1/math.sqrt(2), 1), p2)
p1 = Vector(-1, 0, 0)
p2 = Vector(0, -1, 2)
self.assertCurve(
PathGeom.edgeForCmd(
Path.Command('G3', {'X': p2.x, 'Y': p2.y, 'Z': p2.z, 'I': 1, 'J': 0, 'K': 1}), p1),
p1, Vector(-1/math.sqrt(2), -1/math.sqrt(2), 1), p2)
#print("------ falling helix -------")
p1 = Vector(0, -1, 2)
p2 = Vector(-1, 0, 0)
self.assertCurve(
PathGeom.edgeForCmd(
Path.Command('G2', {'X': p2.x, 'Y': p2.y, 'Z': p2.z, 'I': 0, 'J': 1, 'K': -1}), p1),
p1, Vector(-1/math.sqrt(2), -1/math.sqrt(2), 1), p2)
p1 = Vector(-1, 0, 2)
p2 = Vector(0, -1, 0)
self.assertCurve(
PathGeom.edgeForCmd(
Path.Command('G3', {'X': p2.x, 'Y': p2.y, 'Z': p2.z, 'I': 1, 'J': 0, 'K': -1}), p1),
p1, Vector(-1/math.sqrt(2), -1/math.sqrt(2), 1), p2)
示例3: __init__
def __init__(self, edge, tag, i, segm, maxZ):
debugEdge(edge, 'MapWireToTag(%.2f, %.2f, %.2f)' % (i.x, i.y, i.z))
self.tag = tag
self.segm = segm
self.maxZ = maxZ
if PathGeom.pointsCoincide(edge.valueAt(edge.FirstParameter), i):
tail = edge
self.commands = []
debugEdge(tail, '.........=')
elif PathGeom.pointsCoincide(edge.valueAt(edge.LastParameter), i):
debugEdge(edge, '++++++++ .')
self.commands = PathGeom.cmdsForEdge(edge, segm=segm)
tail = None
else:
e, tail = PathGeom.splitEdgeAt(edge, i)
debugEdge(e, '++++++++ .')
self.commands = PathGeom.cmdsForEdge(e, segm=segm)
debugEdge(tail, '.........-')
self.initialEdge = edge
self.tail = tail
self.edges = []
self.entry = i
if tail:
PathLog.debug("MapWireToTag(%s - %s)" % (i, tail.valueAt(tail.FirstParameter)))
else:
PathLog.debug("MapWireToTag(%s - )" % i)
self.complete = False
self.haveProblem = False
示例4: test65
def test65(self):
"""Verify splitEdgeAt."""
e = PathGeom.splitEdgeAt(Part.Edge(Part.LineSegment(Vector(), Vector(2, 4, 6))), Vector(1, 2, 3))
self.assertLine(e[0], Vector(), Vector(1,2,3))
self.assertLine(e[1], Vector(1,2,3), Vector(2,4,6))
# split an arc
p1 = Vector(10,-10,1)
p2 = Vector(0,0,1)
p3 = Vector(10,10,1)
arc = Part.Edge(Part.Arc(p1, p2, p3))
e = PathGeom.splitEdgeAt(arc, p2)
o = 10*math.sin(math.pi/4)
p12 = Vector(10 - o, -o, 1)
p23 = Vector(10 - o, +o, 1)
self.assertCurve(e[0], p1, p12, p2)
self.assertCurve(e[1], p2, p23, p3)
# split a helix
p1 = Vector(10,-10,0)
p2 = Vector(0,0,5)
p3 = Vector(10,10,10)
h = PathGeom.arcToHelix(arc, 0, 10)
self.assertCurve(h, p1, p2, p3)
e = PathGeom.splitEdgeAt(h, p2)
o = 10*math.sin(math.pi/4)
p12 = Vector(10 - o, -o, 2.5)
p23 = Vector(10 - o, +o, 7.5)
pf = e[0].valueAt((e[0].FirstParameter + e[0].LastParameter)/2)
pl = e[1].valueAt((e[1].FirstParameter + e[1].LastParameter)/2)
self.assertCurve(e[0], p1, p12, p2)
self.assertCurve(e[1], p2, p23, p3)
示例5: horizontalEdgeLoop
def horizontalEdgeLoop(obj, edge):
'''horizontalEdgeLoop(obj, edge) ... returns a wire in the horizontal plane, if that is the only horizontal wire the given edge is a part of.'''
h = edge.hashCode()
wires = [w for w in obj.Shape.Wires if any(e.hashCode() == h for e in w.Edges)]
loops = [w for w in wires if all(PathGeom.isHorizontal(e) for e in w.Edges) and PathGeom.isHorizontal(Part.Face(w))]
if len(loops) == 1:
return loops[0]
return None
示例6: isRapid
def isRapid(self, edge):
if type(edge.Curve) == Part.Line or type(edge.Curve) == Part.LineSegment:
v0 = edge.Vertexes[0]
v1 = edge.Vertexes[1]
for r in self.rapid:
r0 = r.Vertexes[0]
r1 = r.Vertexes[1]
if PathGeom.isRoughly(r0.X, v0.X) and PathGeom.isRoughly(r0.Y, v0.Y) and PathGeom.isRoughly(r0.Z, v0.Z) and PathGeom.isRoughly(r1.X, v1.X) and PathGeom.isRoughly(r1.Y, v1.Y) and PathGeom.isRoughly(r1.Z, v1.Z):
return True
return False
示例7: isValidTagStartIntersection
def isValidTagStartIntersection(self, edge, i):
if PathGeom.pointsCoincide(i, edge.valueAt(edge.LastParameter)):
return False
p1 = edge.valueAt(edge.FirstParameter)
p2 = edge.valueAt(edge.LastParameter)
if PathGeom.pointsCoincide(PathGeom.xy(p1), PathGeom.xy(p2)):
# if this vertical goes up, it can't be the start of a tag intersection
if p1.z < p2.z:
return False
return True
示例8: updateDepths
def updateDepths(self, obj, ignoreErrors=False):
'''updateDepths(obj) ... base implementation calculating depths depending on base geometry.
Should not be overwritten.'''
def faceZmin(bb, fbb):
if fbb.ZMax == fbb.ZMin and fbb.ZMax == bb.ZMax: # top face
return fbb.ZMin
elif fbb.ZMax > fbb.ZMin and fbb.ZMax == bb.ZMax: # vertical face, full cut
return fbb.ZMin
elif fbb.ZMax > fbb.ZMin and fbb.ZMin > bb.ZMin: # internal vertical wall
return fbb.ZMin
elif fbb.ZMax == fbb.ZMin and fbb.ZMax > bb.ZMin: # face/shelf
return fbb.ZMin
return bb.ZMin
if not self._setBaseAndStock(obj, ignoreErrors):
return False
stockBB = self.stock.Shape.BoundBox
zmin = stockBB.ZMin
zmax = stockBB.ZMax
if hasattr(obj, 'Base') and obj.Base:
for base, sublist in obj.Base:
bb = base.Shape.BoundBox
zmax = max(zmax, bb.ZMax)
for sub in sublist:
fbb = base.Shape.getElement(sub).BoundBox
zmin = max(zmin, faceZmin(bb, fbb))
zmax = max(zmax, fbb.ZMax)
else:
# clearing with stock boundaries
job = PathUtils.findParentJob(obj)
zmax = stockBB.ZMax
zmin = job.Base.Shape.BoundBox.ZMax
if FeatureDepths & self.opFeatures(obj):
# first set update final depth, it's value is not negotiable
if not PathGeom.isRoughly(obj.OpFinalDepth.Value, zmin):
obj.OpFinalDepth = zmin
zmin = obj.OpFinalDepth.Value
def minZmax(z):
if hasattr(obj, 'StepDown') and not PathGeom.isRoughly(obj.StepDown.Value, 0):
return z + obj.StepDown.Value
else:
return z + 1
# ensure zmax is higher than zmin
if (zmax - 0.0001) <= zmin:
zmax = minZmax(zmin)
# update start depth if requested and required
if not PathGeom.isRoughly(obj.OpStartDepth.Value, zmax):
obj.OpStartDepth = zmax
示例9: generateHelix
def generateHelix(self):
edges = self.wire.Edges
minZ = self.findMinZ(edges)
outedges = []
i = 0
while i < len(edges):
edge = edges[i]
israpid = False
for redge in self.rapids:
if PathGeom.edgesMatch(edge, redge):
israpid = True
if not israpid:
bb = edge.BoundBox
p0 = edge.Vertexes[0].Point
p1 = edge.Vertexes[1].Point
if bb.XLength < 1e-6 and bb.YLength < 1e-6 and bb.ZLength > 0 and p0.z > p1.z:
# plungelen = abs(p0.z-p1.z)
PathLog.debug("Found plunge move at X:{} Y:{} From Z:{} to Z{}, Searching for closed loop".format(p0.x, p0.y, p0.z, p1.z))
# next need to determine how many edges in the path after plunge are needed to cover the length:
loopFound = False
rampedges = []
j = i + 1
while not loopFound:
candidate = edges[j]
cp0 = candidate.Vertexes[0].Point
cp1 = candidate.Vertexes[1].Point
if PathGeom.pointsCoincide(p1, cp1):
# found closed loop
loopFound = True
rampedges.append(candidate)
break
if abs(cp0.z - cp1.z) > 1e-6:
# this edge is not parallel to XY plane, not qualified for ramping.
break
# PathLog.debug("Next edge length {}".format(candidate.Length))
rampedges.append(candidate)
j = j + 1
if j >= len(edges):
break
if len(rampedges) == 0 or not loopFound:
PathLog.debug("No suitable helix found")
outedges.append(edge)
else:
outedges.extend(self.createHelix(rampedges, p0, p1))
if not PathGeom.isRoughly(p1.z, minZ):
# the edges covered by the helix not handled again,
# unless reached the bottom height
i = j
else:
outedges.append(edge)
else:
outedges.append(edge)
i = i + 1
return outedges
示例10: isEntryOrExitStrut
def isEntryOrExitStrut(self, e):
p1 = e.valueAt(e.FirstParameter)
p2 = e.valueAt(e.LastParameter)
if PathGeom.pointsCoincide(p1, self.entry) and p2.z >= self.entry.z:
return 1
if PathGeom.pointsCoincide(p2, self.entry) and p1.z >= self.entry.z:
return 1
if PathGeom.pointsCoincide(p1, self.exit) and p2.z >= self.exit.z:
return 2
if PathGeom.pointsCoincide(p2, self.exit) and p1.z >= self.exit.z:
return 2
return 0
示例11: test20
def test20(self):
"""Verify proper geometry for arcs in the XY-plane are created."""
p1 = Vector(0, -1, 2)
p2 = Vector(-1, 0, 2)
self.assertArc(
PathGeom.edgeForCmd(
Path.Command('G2', {'X': p2.x, 'Y': p2.y, 'Z': p2.z, 'I': 0, 'J': 1, 'K': 0}), p1),
p1, p2, 'CW')
self.assertArc(
PathGeom.edgeForCmd(
Path.Command('G3', {'X': p1.x, 'Y': p1.y, 'z': p1.z, 'I': -1, 'J': 0, 'K': 0}), p2),
p2, p1, 'CCW')
示例12: isPointOnEdge
def isPointOnEdge(self, pt, edge):
param = edge.Curve.parameter(pt)
if edge.FirstParameter <= param <= edge.LastParameter:
return True
if edge.LastParameter <= param <= edge.FirstParameter:
return True
if PathGeom.isRoughly(edge.FirstParameter, param) or PathGeom.isRoughly(edge.LastParameter, param):
return True
# print("-------- X %.2f <= %.2f <=%.2f (%.2f, %.2f, %.2f) %.2f:%.2f" % (edge.FirstParameter, param, edge.LastParameter, pt.x, pt.y, pt.z, edge.Curve.parameter(edge.valueAt(edge.FirstParameter)), edge.Curve.parameter(edge.valueAt(edge.LastParameter))))
# p1 = edge.Vertexes[0]
# f1 = edge.Curve.parameter(FreeCAD.Vector(p1.X, p1.Y, p1.Z))
# p2 = edge.Vertexes[1]
# f2 = edge.Curve.parameter(FreeCAD.Vector(p2.X, p2.Y, p2.Z))
return False
示例13: orientSelected
def orientSelected(self, axis):
def flipSel(sel):
PathLog.debug("flip")
p = sel.Object.Placement
loc = sel.Object.Placement.Base
rot = FreeCAD.Rotation(FreeCAD.Vector(1-axis.x, 1-axis.y, 1-axis.z), 180)
sel.Object.Placement = FreeCAD.Placement(loc, p.Rotation.multiply(rot))
def rotateSel(sel, n):
p = sel.Object.Placement
loc = sel.Object.Placement.Base
r = axis.cross(n) # rotation axis
a = DraftVecUtils.angle(n, axis, r) * 180 / math.pi
PathLog.debug("oh boy: (%.2f, %.2f, %.2f) -> %.2f" % (r.x, r.y, r.z, a))
Draft.rotate(sel.Object, a, axis=r)
selObject = None
selFeature = None
for sel in FreeCADGui.Selection.getSelectionEx():
selObject = sel.Object
for feature in sel.SubElementNames:
selFeature = feature
sub = sel.Object.Shape.getElement(feature)
if 'Face' == sub.ShapeType:
n = sub.Surface.Axis
if sub.Orientation == 'Reversed':
n = FreeCAD.Vector() - n
PathLog.debug("(%.2f, %.2f, %.2f) -> reversed (%s)" % (n.x, n.y, n.z, sub.Orientation))
else:
PathLog.debug("(%.2f, %.2f, %.2f) -> forward (%s)" % (n.x, n.y, n.z, sub.Orientation))
if PathGeom.pointsCoincide(axis, n):
PathLog.debug("face properly oriented (%.2f, %.2f, %.2f)" % (n.x, n.y, n.z))
else:
if PathGeom.pointsCoincide(axis, FreeCAD.Vector() - n):
flipSel(sel)
else:
rotateSel(sel, n)
if 'Edge' == sub.ShapeType:
n = (sub.Vertexes[1].Point - sub.Vertexes[0].Point).normalize()
if PathGeom.pointsCoincide(axis, n) or PathGeom.pointsCoincide(axis, FreeCAD.Vector() - n):
# Don't really know the orientation of an edge, so let's just flip the object
# and if the user doesn't like it they can flip again
flipSel(sel)
else:
rotateSel(sel, n)
if selObject and selFeature:
FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(selObject, selFeature)
示例14: checkIgnoreAbove
def checkIgnoreAbove(self, edge):
if self.ignoreAboveEnabled:
p0 = edge.Vertexes[0].Point
p1 = edge.Vertexes[1].Point
if p0.z > self.ignoreAbove and (p1.z > self.ignoreAbove or PathGeom.isRoughly(p1.z, self.ignoreAbove.Value)):
PathLog.debug("Whole plunge move above 'ignoreAbove', ignoring")
return (edge, True)
elif p0.z > self.ignoreAbove and not PathGeom.isRoughly(p0.z, self.ignoreAbove.Value):
PathLog.debug("Plunge move partially above 'ignoreAbove', splitting into two")
newPoint = FreeCAD.Base.Vector(p0.x, p0.y, self.ignoreAbove)
return (Part.makeLine(p0, newPoint), False)
else:
return None, False
else:
return None, False
示例15: execute
def execute(self, obj):
if not obj.Base:
return
if not obj.Base.isDerivedFrom("Path::Feature"):
return
if not obj.Base.Path:
return
if obj.Angle >= 90:
obj.Angle = 89.9
elif obj.Angle <= 0:
obj.Angle = 0.1
if hasattr(obj, 'UseStartDepth'):
self.ignoreAboveEnabled = obj.UseStartDepth
self.ignoreAbove = obj.DressupStartDepth
else:
self.ignoreAboveEnabled = False
self.ignoreAbove = 0
self.angle = obj.Angle
self.method = obj.Method
self.wire, self.rapids = PathGeom.wireForPath(obj.Base.Path)
if self.method in ['RampMethod1', 'RampMethod2', 'RampMethod3']:
self.outedges = self.generateRamps()
else:
self.outedges = self.generateHelix()
obj.Path = self.createCommands(obj, self.outedges)