Couple of fixes in Draft DXF importer
+ fixed default draft point color + fixed bug in polylines with bulge = almost zero + fixed bug in text attributes display
This commit is contained in:
parent
388eded3dd
commit
68dcabcffc
|
@ -782,7 +782,6 @@ def rotate(objectslist,angle,center=Vector(0,0,0),axis=Vector(0,0,1),copy=False)
|
||||||
if len(newobjlist) == 1: return newobjlist[0]
|
if len(newobjlist) == 1: return newobjlist[0]
|
||||||
return newobjlist
|
return newobjlist
|
||||||
|
|
||||||
|
|
||||||
def scale(objectslist,delta=Vector(1,1,1),center=Vector(0,0,0),copy=False,legacy=False):
|
def scale(objectslist,delta=Vector(1,1,1),center=Vector(0,0,0),copy=False,legacy=False):
|
||||||
'''scale(objects,vector,[center,copy,legacy]): Scales the objects contained
|
'''scale(objects,vector,[center,copy,legacy]): Scales the objects contained
|
||||||
in objects (that can be a list of objects or an object) of the given scale
|
in objects (that can be a list of objects or an object) of the given scale
|
||||||
|
@ -1390,7 +1389,7 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
|
||||||
FreeCAD.ActiveDocument.recompute()
|
FreeCAD.ActiveDocument.recompute()
|
||||||
return nobj
|
return nobj
|
||||||
|
|
||||||
def makePoint(X=0, Y=0, Z=0,color=(0,1,0),name = "Point", point_size= 5):
|
def makePoint(X=0, Y=0, Z=0,color=None,name = "Point", point_size= 5):
|
||||||
''' make a point (at coordinates x,y,z ,color(r,g,b),point_size)
|
''' make a point (at coordinates x,y,z ,color(r,g,b),point_size)
|
||||||
example usage:
|
example usage:
|
||||||
p1 = makePoint()
|
p1 = makePoint()
|
||||||
|
@ -1401,6 +1400,8 @@ def makePoint(X=0, Y=0, Z=0,color=(0,1,0),name = "Point", point_size= 5):
|
||||||
p1.X = 1 #move it in x
|
p1.X = 1 #move it in x
|
||||||
p1.ViewObject.PointColor =(0.0,0.0,1.0) #change the color-make sure values are floats
|
p1.ViewObject.PointColor =(0.0,0.0,1.0) #change the color-make sure values are floats
|
||||||
'''
|
'''
|
||||||
|
if not color:
|
||||||
|
color = FreeCADGui.draftToolBar.getDefaultColor('ui')
|
||||||
obj=FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
|
obj=FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
|
||||||
_Point(obj,X,Y,Z)
|
_Point(obj,X,Y,Z)
|
||||||
_ViewProviderPoint(obj.ViewObject)
|
_ViewProviderPoint(obj.ViewObject)
|
||||||
|
|
|
@ -161,9 +161,10 @@ def isColinear(vlist):
|
||||||
'''isColinear(list_of_vectors): checks if vectors in given list are colinear'''
|
'''isColinear(list_of_vectors): checks if vectors in given list are colinear'''
|
||||||
typecheck ([(vlist,list)], "isColinear");
|
typecheck ([(vlist,list)], "isColinear");
|
||||||
if len(vlist) < 3: return True
|
if len(vlist) < 3: return True
|
||||||
|
p = precision()
|
||||||
first = vlist[1].sub(vlist[0])
|
first = vlist[1].sub(vlist[0])
|
||||||
for i in range(2,len(vlist)):
|
for i in range(2,len(vlist)):
|
||||||
if angle(vlist[i].sub(vlist[0]),first) != 0:
|
if round(angle(vlist[i].sub(vlist[0]),first),p) != 0:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -290,7 +290,7 @@ def drawLine(line,shapemode=False):
|
||||||
warn(line)
|
warn(line)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def drawPolyline(polyline,shapemode=False):
|
def drawPolyline(polyline,shapemode=False,num=None):
|
||||||
"returns a Part shape from a dxf polyline"
|
"returns a Part shape from a dxf polyline"
|
||||||
if (len(polyline.points) > 1):
|
if (len(polyline.points) > 1):
|
||||||
edges = []
|
edges = []
|
||||||
|
@ -308,13 +308,13 @@ def drawPolyline(polyline,shapemode=False):
|
||||||
cv = calcBulge(v1,polyline.points[p].bulge,v2)
|
cv = calcBulge(v1,polyline.points[p].bulge,v2)
|
||||||
if fcvec.isColinear([v1,cv,v2]):
|
if fcvec.isColinear([v1,cv,v2]):
|
||||||
try: edges.append(Part.Line(v1,v2).toShape())
|
try: edges.append(Part.Line(v1,v2).toShape())
|
||||||
except: warn(polyline)
|
except: warn(polyline,num)
|
||||||
else:
|
else:
|
||||||
try: edges.append(Part.Arc(v1,cv,v2).toShape())
|
try: edges.append(Part.Arc(v1,cv,v2).toShape())
|
||||||
except: warn(polyline)
|
except: warn(polyline,num)
|
||||||
else:
|
else:
|
||||||
try: edges.append(Part.Line(v1,v2).toShape())
|
try: edges.append(Part.Line(v1,v2).toShape())
|
||||||
except: warn(polyline)
|
except: warn(polyline,num)
|
||||||
verts.append(v2)
|
verts.append(v2)
|
||||||
if polyline.closed:
|
if polyline.closed:
|
||||||
p1 = polyline.points[len(polyline.points)-1]
|
p1 = polyline.points[len(polyline.points)-1]
|
||||||
|
@ -324,11 +324,15 @@ def drawPolyline(polyline,shapemode=False):
|
||||||
cv = calcBulge(v1,polyline.points[-1].bulge,v2)
|
cv = calcBulge(v1,polyline.points[-1].bulge,v2)
|
||||||
if not fcvec.equals(v1,v2):
|
if not fcvec.equals(v1,v2):
|
||||||
if fcvec.isColinear([v1,cv,v2]):
|
if fcvec.isColinear([v1,cv,v2]):
|
||||||
try: edges.append(Part.Line(v1,v2).toShape())
|
try:
|
||||||
except: warn(polyline)
|
edges.append(Part.Line(v1,v2).toShape())
|
||||||
|
except:
|
||||||
|
warn(polyline,num)
|
||||||
else:
|
else:
|
||||||
try: edges.append(Part.Arc(v1,cv,v2).toShape())
|
try:
|
||||||
except: warn(polyline)
|
edges.append(Part.Arc(v1,cv,v2).toShape())
|
||||||
|
except:
|
||||||
|
warn(polyline,num)
|
||||||
if edges:
|
if edges:
|
||||||
try:
|
try:
|
||||||
if (fmt.paramstyle >= 4) and (not curves) and (not shapemode):
|
if (fmt.paramstyle >= 4) and (not curves) and (not shapemode):
|
||||||
|
@ -342,7 +346,7 @@ def drawPolyline(polyline,shapemode=False):
|
||||||
else:
|
else:
|
||||||
return Part.Wire(edges)
|
return Part.Wire(edges)
|
||||||
except:
|
except:
|
||||||
warn(polyline)
|
warn(polyline,num)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def drawArc(arc,shapemode=False):
|
def drawArc(arc,shapemode=False):
|
||||||
|
@ -495,7 +499,7 @@ def drawSpline(spline,shapemode=False):
|
||||||
return ob
|
return ob
|
||||||
else:
|
else:
|
||||||
sp = Part.BSplineCurve()
|
sp = Part.BSplineCurve()
|
||||||
print knots
|
# print knots
|
||||||
sp.interpolate(verts)
|
sp.interpolate(verts)
|
||||||
sh = Part.Wire(sp.toShape())
|
sh = Part.Wire(sp.toShape())
|
||||||
if closed:
|
if closed:
|
||||||
|
@ -506,7 +510,7 @@ def drawSpline(spline,shapemode=False):
|
||||||
warn(spline)
|
warn(spline)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def drawBlock(blockref):
|
def drawBlock(blockref,num=None):
|
||||||
"returns a shape from a dxf block reference"
|
"returns a shape from a dxf block reference"
|
||||||
shapes = []
|
shapes = []
|
||||||
for line in blockref.entities.get_type('line'):
|
for line in blockref.entities.get_type('line'):
|
||||||
|
@ -534,11 +538,13 @@ def drawBlock(blockref):
|
||||||
s = drawSpline(spline,shapemode=True)
|
s = drawSpline(spline,shapemode=True)
|
||||||
if s: shapes.append(s)
|
if s: shapes.append(s)
|
||||||
for text in blockref.entities.get_type('text'):
|
for text in blockref.entities.get_type('text'):
|
||||||
if fmt.dxflayout or (not rawValue(text,67)):
|
if fmt.paramtext:
|
||||||
addText(text)
|
if fmt.dxflayout or (not rawValue(text,67)):
|
||||||
|
addText(text)
|
||||||
for text in blockref.entities.get_type('mtext'):
|
for text in blockref.entities.get_type('mtext'):
|
||||||
if fmt.dxflayout or (not rawValue(text,67)):
|
if fmt.paramtext:
|
||||||
addText(text)
|
if fmt.dxflayout or (not rawValue(text,67)):
|
||||||
|
addText(text)
|
||||||
try: shape = Part.makeCompound(shapes)
|
try: shape = Part.makeCompound(shapes)
|
||||||
except: warn(blockref)
|
except: warn(blockref)
|
||||||
if shape:
|
if shape:
|
||||||
|
@ -546,14 +552,14 @@ def drawBlock(blockref):
|
||||||
return shape
|
return shape
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def drawInsert(insert):
|
def drawInsert(insert,num=None):
|
||||||
if blockshapes.has_key(insert):
|
if blockshapes.has_key(insert):
|
||||||
shape = blockshapes[insert.block]
|
shape = blockshapes[insert.block]
|
||||||
else:
|
else:
|
||||||
shape = None
|
shape = None
|
||||||
for b in drawing.blocks.data:
|
for b in drawing.blocks.data:
|
||||||
if b.name == insert.block:
|
if b.name == insert.block:
|
||||||
shape = drawBlock(b)
|
shape = drawBlock(b,num)
|
||||||
if fmt.paramtext:
|
if fmt.paramtext:
|
||||||
attrs = attribs(insert)
|
attrs = attribs(insert)
|
||||||
for a in attrs:
|
for a in attrs:
|
||||||
|
@ -619,6 +625,7 @@ def addObject(shape,name="Shape",layer=None):
|
||||||
|
|
||||||
def addText(text,attrib=False):
|
def addText(text,attrib=False):
|
||||||
"adds a new text to the document"
|
"adds a new text to the document"
|
||||||
|
print "adding text ",text,attrib
|
||||||
if attrib:
|
if attrib:
|
||||||
lay = locateLayer(rawValue(text,8))
|
lay = locateLayer(rawValue(text,8))
|
||||||
val = rawValue(text,1)
|
val = rawValue(text,1)
|
||||||
|
@ -715,10 +722,12 @@ def processdxf(document,filename):
|
||||||
polylines.append(p)
|
polylines.append(p)
|
||||||
else:
|
else:
|
||||||
polylines.append(p)
|
polylines.append(p)
|
||||||
if polylines: FreeCAD.Console.PrintMessage("drawing "+str(len(polylines))+" polylines...\n")
|
if polylines:
|
||||||
|
FreeCAD.Console.PrintMessage("drawing "+str(len(polylines))+" polylines...\n")
|
||||||
|
num = 0
|
||||||
for polyline in polylines:
|
for polyline in polylines:
|
||||||
if fmt.dxflayout or (not rawValue(polyline,67)):
|
if fmt.dxflayout or (not rawValue(polyline,67)):
|
||||||
shape = drawPolyline(polyline)
|
shape = drawPolyline(polyline,num)
|
||||||
if shape:
|
if shape:
|
||||||
if fmt.paramstyle == 5:
|
if fmt.paramstyle == 5:
|
||||||
if isinstance(shape,Part.Shape):
|
if isinstance(shape,Part.Shape):
|
||||||
|
@ -743,6 +752,7 @@ def processdxf(document,filename):
|
||||||
else:
|
else:
|
||||||
newob = addObject(shape,"Polyline",polyline.layer)
|
newob = addObject(shape,"Polyline",polyline.layer)
|
||||||
if gui: fmt.formatObject(newob,polyline)
|
if gui: fmt.formatObject(newob,polyline)
|
||||||
|
num += 1
|
||||||
|
|
||||||
# drawing arcs
|
# drawing arcs
|
||||||
|
|
||||||
|
@ -841,7 +851,8 @@ def processdxf(document,filename):
|
||||||
if fmt.paramtext:
|
if fmt.paramtext:
|
||||||
texts = drawing.entities.get_type("mtext")
|
texts = drawing.entities.get_type("mtext")
|
||||||
texts.extend(drawing.entities.get_type("text"))
|
texts.extend(drawing.entities.get_type("text"))
|
||||||
if texts: FreeCAD.Console.PrintMessage("drawing "+str(len(texts))+" texts...\n")
|
if texts:
|
||||||
|
FreeCAD.Console.PrintMessage("drawing "+str(len(texts))+" texts...\n")
|
||||||
for text in texts:
|
for text in texts:
|
||||||
if fmt.dxflayout or (not rawValue(text,67)):
|
if fmt.dxflayout or (not rawValue(text,67)):
|
||||||
addText(text)
|
addText(text)
|
||||||
|
@ -918,7 +929,7 @@ def processdxf(document,filename):
|
||||||
else: FreeCAD.Console.PrintMessage("skipping dimensions...\n")
|
else: FreeCAD.Console.PrintMessage("skipping dimensions...\n")
|
||||||
|
|
||||||
# drawing blocks
|
# drawing blocks
|
||||||
|
|
||||||
inserts = drawing.entities.get_type("insert")
|
inserts = drawing.entities.get_type("insert")
|
||||||
if not fmt.paramstarblocks:
|
if not fmt.paramstarblocks:
|
||||||
FreeCAD.Console.PrintMessage("skipping *blocks...\n")
|
FreeCAD.Console.PrintMessage("skipping *blocks...\n")
|
||||||
|
@ -933,18 +944,21 @@ def processdxf(document,filename):
|
||||||
blockrefs = drawing.blocks.data
|
blockrefs = drawing.blocks.data
|
||||||
for ref in blockrefs:
|
for ref in blockrefs:
|
||||||
drawBlock(ref)
|
drawBlock(ref)
|
||||||
|
num = 0
|
||||||
for insert in inserts:
|
for insert in inserts:
|
||||||
shape = drawInsert(insert)
|
shape = drawInsert(insert,num)
|
||||||
if shape:
|
if shape:
|
||||||
if fmt.makeBlocks:
|
if fmt.makeBlocks:
|
||||||
addToBlock(shape,block.layer)
|
addToBlock(shape,insert.layer)
|
||||||
else:
|
else:
|
||||||
newob = addObject(shape,"Block."+insert.block,insert.layer)
|
newob = addObject(shape,"Block."+insert.block,insert.layer)
|
||||||
if gui: fmt.formatObject(newob,insert)
|
if gui: fmt.formatObject(newob,insert)
|
||||||
|
num += 1
|
||||||
|
|
||||||
# make blocks, if any
|
# make blocks, if any
|
||||||
|
|
||||||
if fmt.makeBlocks:
|
if fmt.makeBlocks:
|
||||||
|
print "creating layerblocks..."
|
||||||
for k,l in layerBlocks.iteritems():
|
for k,l in layerBlocks.iteritems():
|
||||||
shape = drawLayerBlock(l)
|
shape = drawLayerBlock(l)
|
||||||
if shape:
|
if shape:
|
||||||
|
@ -953,6 +967,8 @@ def processdxf(document,filename):
|
||||||
|
|
||||||
# finishing
|
# finishing
|
||||||
|
|
||||||
|
print "done processing"
|
||||||
|
|
||||||
doc.recompute()
|
doc.recompute()
|
||||||
FreeCAD.Console.PrintMessage("successfully imported "+filename+"\n")
|
FreeCAD.Console.PrintMessage("successfully imported "+filename+"\n")
|
||||||
if badobjects: print "dxf: ",len(badobjects)," objects were not imported"
|
if badobjects: print "dxf: ",len(badobjects)," objects were not imported"
|
||||||
|
@ -960,9 +976,9 @@ def processdxf(document,filename):
|
||||||
del doc
|
del doc
|
||||||
del blockshapes
|
del blockshapes
|
||||||
|
|
||||||
def warn(dxfobject):
|
def warn(dxfobject,num=None):
|
||||||
"outputs a warning if a dxf object couldn't be imported"
|
"outputs a warning if a dxf object couldn't be imported"
|
||||||
print "dxf: couldn't import ", dxfobject
|
print "dxf: couldn't import ", dxfobject, " (",num,")"
|
||||||
badobjects.append(dxfobject)
|
badobjects.append(dxfobject)
|
||||||
|
|
||||||
def open(filename):
|
def open(filename):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user