Draft: Fixed DXF import with sketch mode on

This commit is contained in:
Yorik van Havre
2019-04-25 18:17:57 -03:00
parent 418fe7beff
commit dc64cdb18d
2 changed files with 34 additions and 27 deletions

View File

@@ -2283,24 +2283,25 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,
ok = False
tp = getType(obj)
if tp in ["Circle","Ellipse"]:
if rotation is None:
rotation = obj.Placement.Rotation
edge = obj.Shape.Edges[0]
if len(edge.Vertexes) == 1:
newEdge = DraftGeomUtils.orientEdge(edge)
nobj.addGeometry(newEdge)
else:
# make new ArcOfCircle
circle = DraftGeomUtils.orientEdge(edge)
angle = edge.Placement.Rotation.Angle
axis = edge.Placement.Rotation.Axis
circle.Center = DraftVecUtils.rotate(edge.Curve.Center, -angle, axis)
first = math.radians(obj.FirstAngle)
last = math.radians(obj.LastAngle)
arc = Part.ArcOfCircle(circle, first, last)
nobj.addGeometry(arc)
addRadiusConstraint(edge)
ok = True
if obj.Shape.Edges:
if rotation is None:
rotation = obj.Placement.Rotation
edge = obj.Shape.Edges[0]
if len(edge.Vertexes) == 1:
newEdge = DraftGeomUtils.orientEdge(edge)
nobj.addGeometry(newEdge)
else:
# make new ArcOfCircle
circle = DraftGeomUtils.orientEdge(edge)
angle = edge.Placement.Rotation.Angle
axis = edge.Placement.Rotation.Axis
circle.Center = DraftVecUtils.rotate(edge.Curve.Center, -angle, axis)
first = math.radians(obj.FirstAngle)
last = math.radians(obj.LastAngle)
arc = Part.ArcOfCircle(circle, first, last)
nobj.addGeometry(arc)
addRadiusConstraint(edge)
ok = True
elif tp == "Rectangle":
if rotation is None:
rotation = obj.Placement.Rotation
@@ -2358,15 +2359,17 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,
constraints.append(Constraint("Coincident",last-1,EndPoint,segs[0],StartPoint))
ok = True
elif tp == "BSpline":
nobj.addGeometry(obj.Shape.Edges[0].Curve)
nobj.exposeInternalGeometry(nobj.GeometryCount-1)
ok = True
if obj.Shape.Edges:
nobj.addGeometry(obj.Shape.Edges[0].Curve)
nobj.exposeInternalGeometry(nobj.GeometryCount-1)
ok = True
elif tp == "BezCurve":
bez = obj.Shape.Edges[0].Curve
bsp = bez.toBSpline(bez.FirstParameter,bez.LastParameter)
nobj.addGeometry(bsp)
nobj.exposeInternalGeometry(nobj.GeometryCount-1)
ok = True
if obj.Shape.Edges:
bez = obj.Shape.Edges[0].Curve
bsp = bez.toBSpline(bez.FirstParameter,bez.LastParameter)
nobj.addGeometry(bsp)
nobj.exposeInternalGeometry(nobj.GeometryCount-1)
ok = True
elif tp == 'Shape' or obj.isDerivedFrom("Part::Feature"):
shape = obj if tp == 'Shape' else obj.Shape

View File

@@ -528,7 +528,7 @@ def drawArc(arc,forceShape=False):
try:
if (dxfCreateDraft or dxfCreateSketch) and (not forceShape):
pl = placementFromDXFOCS(arc)
return Draft.makeCircle(arc.radius,pl,False,firstangle,lastangle)
return Draft.makeCircle(circle.Radius,pl,False,firstangle,lastangle)
else:
return circle.toShape(math.radians(firstangle),math.radians(lastangle))
except Part.OCCError:
@@ -1115,6 +1115,7 @@ def processdxf(document,filename,getShapes=False,reComputeFlag=True):
shape = drawLine(line)
if shape:
if dxfCreateSketch:
FreeCAD.ActiveDocument.recompute()
if dxfMakeBlocks or dxfJoin:
if sketch:
shape = Draft.makeSketch(shape,autoconstraints=True,addTo=sketch)
@@ -1160,6 +1161,7 @@ def processdxf(document,filename,getShapes=False,reComputeFlag=True):
t = FreeCAD.ActiveDocument.addObject("Part::Feature","Shape")
t.Shape = shape
shape = t
FreeCAD.ActiveDocument.recompute()
if dxfMakeBlocks or dxfJoin:
if sketch:
shape = Draft.makeSketch(shape,autoconstraints=True,addTo=sketch)
@@ -1189,6 +1191,7 @@ def processdxf(document,filename,getShapes=False,reComputeFlag=True):
shape = drawArc(arc)
if shape:
if dxfCreateSketch:
FreeCAD.ActiveDocument.recompute()
if dxfMakeBlocks or dxfJoin:
if sketch:
shape = Draft.makeSketch(shape,autoconstraints=True,addTo=sketch)
@@ -1241,6 +1244,7 @@ def processdxf(document,filename,getShapes=False,reComputeFlag=True):
shape = drawCircle(circle)
if shape:
if dxfCreateSketch:
FreeCAD.ActiveDocument.recompute()
if dxfMakeBlocks or dxfJoin:
if sketch:
shape = Draft.makeSketch(shape,autoconstraints=True,addTo=sketch)