Draft: fix make_sketch bugs (#7969)
This commit is contained in:
@@ -148,32 +148,30 @@ def isAligned(edge, axis="x"):
|
||||
|
||||
The axis can be 'x', 'y' or 'z'.
|
||||
"""
|
||||
def is_same(a, b):
|
||||
return round(a, precision()) == round(b, precision())
|
||||
|
||||
if axis == "x":
|
||||
if isinstance(edge, Part.Edge):
|
||||
if len(edge.Vertexes) == 2:
|
||||
if edge.Vertexes[0].X == edge.Vertexes[-1].X:
|
||||
return True
|
||||
return is_same(edge.Vertexes[0].X, edge.Vertexes[-1].X)
|
||||
elif isinstance(edge, Part.LineSegment):
|
||||
if edge.StartPoint.x == edge.EndPoint.x:
|
||||
return True
|
||||
return is_same(edge.StartPoint.x, edge.EndPoint.x)
|
||||
|
||||
elif axis == "y":
|
||||
if isinstance(edge, Part.Edge):
|
||||
if len(edge.Vertexes) == 2:
|
||||
if edge.Vertexes[0].Y == edge.Vertexes[-1].Y:
|
||||
return True
|
||||
return is_same(edge.Vertexes[0].Y, edge.Vertexes[-1].Y)
|
||||
elif isinstance(edge, Part.LineSegment):
|
||||
if edge.StartPoint.y == edge.EndPoint.y:
|
||||
return True
|
||||
return is_same(edge.StartPoint.y, edge.EndPoint.y)
|
||||
|
||||
elif axis == "z":
|
||||
if isinstance(edge, Part.Edge):
|
||||
if len(edge.Vertexes) == 2:
|
||||
if edge.Vertexes[0].Z == edge.Vertexes[-1].Z:
|
||||
return True
|
||||
return is_same(edge.Vertexes[0].Z, edge.Vertexes[-1].Z)
|
||||
elif isinstance(edge, Part.LineSegment):
|
||||
if edge.StartPoint.z == edge.EndPoint.z:
|
||||
return True
|
||||
return is_same(edge.StartPoint.z, edge.EndPoint.z)
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
||||
@@ -198,6 +198,7 @@ def make_sketch(objects_list, autoconstraints=False, addTo=None,
|
||||
for obj in objects_list:
|
||||
ok = False
|
||||
tp = utils.get_type(obj)
|
||||
|
||||
if tp in ["Circle","Ellipse"]:
|
||||
if obj.Shape.Edges:
|
||||
edge = obj.Shape.Edges[0]
|
||||
@@ -213,61 +214,24 @@ def make_sketch(objects_list, autoconstraints=False, addTo=None,
|
||||
nobj.addGeometry(arc)
|
||||
addRadiusConstraint(edge)
|
||||
ok = True
|
||||
elif tp == "Rectangle":
|
||||
if obj.FilletRadius.Value == 0:
|
||||
|
||||
elif tp in ["Wire", "Rectangle", "Polygon"] and obj.FilletRadius.Value == 0:
|
||||
if obj.Shape.Edges:
|
||||
for edge in obj.Shape.Edges:
|
||||
nobj.addGeometry(DraftGeomUtils.orientEdge(edge, normal))
|
||||
# TODO: the previous implementation for autoconstraints fails in front
|
||||
# and side view. So the autoconstraints for wires is used. This need
|
||||
# more checking
|
||||
if autoconstraints:
|
||||
closed = tp in ["Rectangle", "Polygon"] or obj.Closed
|
||||
last = nobj.GeometryCount
|
||||
segs = list(range(last-len(obj.Shape.Edges),last-1))
|
||||
for seg in segs:
|
||||
constraints.append(Constraint("Coincident",seg,end_point,seg+1,start_point))
|
||||
if DraftGeomUtils.isAligned(nobj.Geometry[seg],"x"):
|
||||
constraints.append(Constraint("Vertical",seg))
|
||||
elif DraftGeomUtils.isAligned(nobj.Geometry[seg],"y"):
|
||||
constraints.append(Constraint("Horizontal",seg))
|
||||
constraints.append(Constraint("Coincident",last-1,end_point,segs[0],start_point))
|
||||
segs = list(range(last - len(obj.Shape.Edges), last))
|
||||
nexts = segs[1:] + ([segs[0]] if closed else [None])
|
||||
for seg, next in zip(segs, nexts):
|
||||
if next is not None:
|
||||
constraints.append(Constraint("Coincident",seg, end_point, next, start_point))
|
||||
if DraftGeomUtils.isAligned(nobj.Geometry[seg], "x"):
|
||||
constraints.append(Constraint("Vertical", seg))
|
||||
elif DraftGeomUtils.isAligned(nobj.Geometry[seg], "y"):
|
||||
constraints.append(Constraint("Horizontal", seg))
|
||||
ok = True
|
||||
# if autoconstraints:
|
||||
# last = nobj.GeometryCount - 1
|
||||
# segs = [last-3,last-2,last-1,last]
|
||||
# if obj.Placement.Rotation.Q == (0,0,0,1):
|
||||
# constraints.append(Constraint("Coincident",last-3,end_point,last-2,start_point))
|
||||
# constraints.append(Constraint("Coincident",last-2,end_point,last-1,start_point))
|
||||
# constraints.append(Constraint("Coincident",last-1,end_point,last,start_point))
|
||||
# constraints.append(Constraint("Coincident",last,end_point,last-3,start_point))
|
||||
# constraints.append(Constraint("Horizontal",last-3))
|
||||
# constraints.append(Constraint("Vertical",last-2))
|
||||
# constraints.append(Constraint("Horizontal",last-1))
|
||||
# constraints.append(Constraint("Vertical",last))
|
||||
# ok = True
|
||||
elif tp in ["Wire","Polygon"]:
|
||||
if obj.FilletRadius.Value == 0:
|
||||
closed = False
|
||||
if tp == "Polygon":
|
||||
closed = True
|
||||
elif hasattr(obj,"Closed"):
|
||||
closed = obj.Closed
|
||||
|
||||
if obj.Shape.Edges:
|
||||
for edge in obj.Shape.Edges:
|
||||
edge = DraftGeomUtils.orientEdge(edge, normal)
|
||||
nobj.addGeometry(edge)
|
||||
if autoconstraints:
|
||||
last = nobj.GeometryCount
|
||||
segs = list(range(last-len(obj.Shape.Edges),last-1))
|
||||
for seg in segs:
|
||||
constraints.append(Constraint("Coincident",seg,end_point,seg+1,start_point))
|
||||
if DraftGeomUtils.isAligned(nobj.Geometry[seg],"x"):
|
||||
constraints.append(Constraint("Vertical",seg))
|
||||
elif DraftGeomUtils.isAligned(nobj.Geometry[seg],"y"):
|
||||
constraints.append(Constraint("Horizontal",seg))
|
||||
if closed:
|
||||
constraints.append(Constraint("Coincident",last-1,end_point,segs[0],start_point))
|
||||
ok = True
|
||||
|
||||
elif tp == "BSpline":
|
||||
if obj.Shape.Edges:
|
||||
|
||||
Reference in New Issue
Block a user