Skip to content

Commit

Permalink
Draft: fixes related to LineSegment + more powerful draft2sketch conv…
Browse files Browse the repository at this point in the history
…ersion
  • Loading branch information
yorikvanhavre committed Dec 2, 2016
1 parent 8106630 commit 63aa773
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
30 changes: 28 additions & 2 deletions src/Mod/Draft/Draft.py
Expand Up @@ -2595,8 +2595,34 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,delete=False,name="S
return None
# if not addTo:
# nobj.Placement.Rotation = DraftGeomUtils.calculatePlacement(obj.Shape).Rotation
for edge in obj.Shape.Edges:
nobj.addGeometry(DraftGeomUtils.orientEdge(edge))
if autoconstraints:
start = 0
end = 0
for wire in obj.Shape.Wires:
for edge in wire.OrderedEdges:
nobj.addGeometry(DraftGeomUtils.orientEdge(edge))
end += 1
segs = list(range(start,end))
for seg in segs:
if seg == nobj.GeometryCount-1:
if wire.isClosed:
if nobj.Geometry[seg].EndPoint == nobj.Geometry[start].StartPoint:
nobj.addConstraint(Constraint("Coincident",seg,EndPoint,start,StartPoint))
else:
nobj.addConstraint(Constraint("Coincident",seg,StartPoint,start,EndPoint))
else:
if nobj.Geometry[seg].EndPoint == nobj.Geometry[seg+1].StartPoint:
nobj.addConstraint(Constraint("Coincident",seg,EndPoint,seg+1,StartPoint))
else:
nobj.addConstraint(Constraint("Coincident",seg,StartPoint,seg+1,EndPoint))
if DraftGeomUtils.isAligned(nobj.Geometry[seg],"x"):
nobj.addConstraint(Constraint("Vertical",seg))
elif DraftGeomUtils.isAligned(nobj.Geometry[seg],"y"):
nobj.addConstraint(Constraint("Horizontal",seg))
start = end
else:
for edge in obj.Shape.Edges:
nobj.addGeometry(DraftGeomUtils.orientEdge(edge))
ok = True
formatObject(nobj,obj)
if ok and delete:
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/Draft/DraftGeomUtils.py
Expand Up @@ -188,7 +188,7 @@ def hasOnlyWires(shape):
def geomType(edge):
"returns the type of geom this edge is based on"
try:
if isinstance(edge.Curve,Part.LineSegment):
if (isinstance(edge.Curve,Part.LineSegment) or isinstance(edge.Curve,Part.Line)):
return "Line"
elif isinstance(edge.Curve,Part.Circle):
return "Circle"
Expand Down Expand Up @@ -549,6 +549,8 @@ def orientEdge(edge, normal=None):
angle = -1*edge.Placement.Rotation.Angle*FreeCAD.Units.Radian

edge.rotate(base, axis, angle)
if isinstance(edge.Curve,Part.Line):
return Part.LineSegment(edge.Curve,edge.FirstParameter,edge.LastParameter)
return edge.Curve

def mirror (point, edge):
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Draft/DraftTools.py
Expand Up @@ -4199,8 +4199,8 @@ def proceed(self):
elif obj.isDerivedFrom("Part::Part2DObjectPython"):
lines.append("Draft.makeSketch(FreeCAD.ActiveDocument."+obj.Name+",autoconstraints=True)")
elif obj.isDerivedFrom("Part::Feature"):
if (len(obj.Shape.Wires) == 1) or (len(obj.Shape.Edges) == 1):
lines.append("Draft.makeSketch(FreeCAD.ActiveDocument."+obj.Name+",autoconstraints=False)")
#if (len(obj.Shape.Wires) == 1) or (len(obj.Shape.Edges) == 1):
lines.append("Draft.makeSketch(FreeCAD.ActiveDocument."+obj.Name+",autoconstraints=True)")
self.commit(translate("draft","Convert"),
lines + ['FreeCAD.ActiveDocument.recompute()'])
self.finish()
Expand Down

0 comments on commit 63aa773

Please sign in to comment.