Renamed Draft fcvec and fcgeo modules
Draft/draftlibs/fcvec becomes Draft/DraftVecUtils Draft/draftlibs/fcgeo becomes Draft/DraftGeomUtils
This commit is contained in:
@@ -40,8 +40,8 @@ lines, polylines, lwpolylines, circles, arcs,
|
||||
texts, colors,layers (from groups)
|
||||
'''
|
||||
|
||||
import FreeCAD, os, Part, math, re, string, Mesh, Draft
|
||||
from draftlibs import fcvec, dxfColorMap, dxfLibrary, fcgeo
|
||||
import FreeCAD, os, Part, math, re, string, Mesh, Draft, DraftVecUtils, DraftGeomUtils
|
||||
from draftlibs import dxfColorMap, dxfLibrary
|
||||
from draftlibs.dxfReader import readDXF
|
||||
from Draft import _Dimension, _ViewProviderDimension
|
||||
from FreeCAD import Vector
|
||||
@@ -134,10 +134,10 @@ def calcBulge(v1,bulge,v2):
|
||||
'''
|
||||
chord = v2.sub(v1)
|
||||
sagitta = (bulge * chord.Length)/2
|
||||
startpoint = v1.add(fcvec.scale(chord,0.5))
|
||||
startpoint = v1.add(DraftVecUtils.scale(chord,0.5))
|
||||
perp = chord.cross(Vector(0,0,1))
|
||||
if not fcvec.isNull(perp): perp.normalize()
|
||||
endpoint = fcvec.scale(perp,sagitta)
|
||||
if not DraftVecUtils.isNull(perp): perp.normalize()
|
||||
endpoint = DraftVecUtils.scale(perp,sagitta)
|
||||
return startpoint.add(endpoint)
|
||||
|
||||
def getGroup(ob,exportList):
|
||||
@@ -218,7 +218,7 @@ class fcformat:
|
||||
v1 = FreeCAD.Vector(r1,g1,b1)
|
||||
v2 = FreeCAD.Vector(r2,g2,b2)
|
||||
v = v2.sub(v1)
|
||||
v = fcvec.scale(v,0.5)
|
||||
v = DraftVecUtils.scale(v,0.5)
|
||||
cv = v1.add(v)
|
||||
else:
|
||||
c1 = bparams.GetUnsigned("BackgroundColor")
|
||||
@@ -348,7 +348,7 @@ def drawLine(line,shapemode=False):
|
||||
if (len(line.points) > 1):
|
||||
v1=vec(line.points[0])
|
||||
v2=vec(line.points[1])
|
||||
if not fcvec.equals(v1,v2):
|
||||
if not DraftVecUtils.equals(v1,v2):
|
||||
try:
|
||||
if (fmt.paramstyle >= 4) and (not shapemode):
|
||||
return Draft.makeWire([v1,v2])
|
||||
@@ -370,11 +370,11 @@ def drawPolyline(polyline,shapemode=False,num=None):
|
||||
v1 = vec(p1)
|
||||
v2 = vec(p2)
|
||||
verts.append(v1)
|
||||
if not fcvec.equals(v1,v2):
|
||||
if not DraftVecUtils.equals(v1,v2):
|
||||
if polyline.points[p].bulge:
|
||||
curves = True
|
||||
cv = calcBulge(v1,polyline.points[p].bulge,v2)
|
||||
if fcvec.isColinear([v1,cv,v2]):
|
||||
if DraftVecUtils.isColinear([v1,cv,v2]):
|
||||
try: edges.append(Part.Line(v1,v2).toShape())
|
||||
except: warn(polyline,num)
|
||||
else:
|
||||
@@ -390,8 +390,8 @@ def drawPolyline(polyline,shapemode=False,num=None):
|
||||
v1 = vec(p1)
|
||||
v2 = vec(p2)
|
||||
cv = calcBulge(v1,polyline.points[-1].bulge,v2)
|
||||
if not fcvec.equals(v1,v2):
|
||||
if fcvec.isColinear([v1,cv,v2]):
|
||||
if not DraftVecUtils.equals(v1,v2):
|
||||
if DraftVecUtils.isColinear([v1,cv,v2]):
|
||||
try:
|
||||
edges.append(Part.Line(v1,v2).toShape())
|
||||
except:
|
||||
@@ -722,11 +722,11 @@ def addText(text,attrib=False):
|
||||
rz = rawValue(text,31)
|
||||
if rx or ry or rz:
|
||||
xv = Vector(rx,ry,rz)
|
||||
if not fcvec.isNull(xv):
|
||||
ax = fcvec.neg(xv.cross(Vector(1,0,0)))
|
||||
if fcvec.isNull(ax):
|
||||
if not DraftVecUtils.isNull(xv):
|
||||
ax = DraftVecUtils.neg(xv.cross(Vector(1,0,0)))
|
||||
if DraftVecUtils.isNull(ax):
|
||||
ax = Vector(0,0,1)
|
||||
ang = -math.degrees(fcvec.angle(xv,Vector(1,0,0),ax))
|
||||
ang = -math.degrees(DraftVecUtils.angle(xv,Vector(1,0,0),ax))
|
||||
Draft.rotate(newob,ang,axis=ax)
|
||||
elif hasattr(text,"rotation"):
|
||||
if text.rotation:
|
||||
@@ -885,7 +885,7 @@ def processdxf(document,filename):
|
||||
edges = []
|
||||
for s in shapes:
|
||||
edges.extend(s.Edges)
|
||||
shapes = fcgeo.findWires(edges)
|
||||
shapes = DraftGeomUtils.findWires(edges)
|
||||
for s in shapes:
|
||||
newob = addObject(s)
|
||||
|
||||
@@ -1198,13 +1198,13 @@ def getArcData(edge):
|
||||
# check the midpoint seems more reliable
|
||||
ve1 = edge.Vertexes[0].Point
|
||||
ve2 = edge.Vertexes[-1].Point
|
||||
ang1 = -math.degrees(fcvec.angle(ve1.sub(ce)))
|
||||
ang2 = -math.degrees(fcvec.angle(ve2.sub(ce)))
|
||||
ve3 = fcgeo.findMidpoint(edge)
|
||||
ang3 = -math.degrees(fcvec.angle(ve3.sub(ce)))
|
||||
ang1 = -math.degrees(DraftVecUtils.angle(ve1.sub(ce)))
|
||||
ang2 = -math.degrees(DraftVecUtils.angle(ve2.sub(ce)))
|
||||
ve3 = DraftGeomUtils.findMidpoint(edge)
|
||||
ang3 = -math.degrees(DraftVecUtils.angle(ve3.sub(ce)))
|
||||
if (ang3 < ang1) and (ang2 < ang3):
|
||||
ang1, ang2 = ang2, ang1
|
||||
return fcvec.tup(ce), radius, ang1, ang2
|
||||
return DraftVecUtils.tup(ce), radius, ang1, ang2
|
||||
|
||||
def getSplineSegs(edge):
|
||||
"returns an array of vectors from a bSpline edge"
|
||||
@@ -1228,18 +1228,18 @@ def getSplineSegs(edge):
|
||||
|
||||
def getWire(wire,nospline=False):
|
||||
"returns an array of dxf-ready points and bulges from a wire"
|
||||
edges = fcgeo.sortEdges(wire.Edges)
|
||||
edges = DraftGeomUtils.sortEdges(wire.Edges)
|
||||
points = []
|
||||
for edge in edges:
|
||||
v1 = edge.Vertexes[0].Point
|
||||
if len(edge.Vertexes) < 2:
|
||||
points.append((v1.x,v1.y,v1.z,None,None,0.0))
|
||||
elif (isinstance(edge.Curve,Part.Circle)):
|
||||
mp = fcgeo.findMidpoint(edge)
|
||||
mp = DraftGeomUtils.findMidpoint(edge)
|
||||
v2 = edge.Vertexes[-1].Point
|
||||
c = edge.Curve.Center
|
||||
angle = abs(fcvec.angle(v1.sub(c),v2.sub(c)))
|
||||
# if (fcvec.angle(v2.sub(c)) < fcvec.angle(v1.sub(c))):
|
||||
angle = abs(DraftVecUtils.angle(v1.sub(c),v2.sub(c)))
|
||||
# if (DraftVecUtils.angle(v2.sub(c)) < DraftVecUtils.angle(v1.sub(c))):
|
||||
# angle = -angle
|
||||
# polyline bulge -> negative makes the arc go clockwise
|
||||
bul = math.tan(angle/4)
|
||||
@@ -1259,9 +1259,9 @@ def getWire(wire,nospline=False):
|
||||
points.append((p.x,p.y,p.z,None,None,0.0))
|
||||
else:
|
||||
points.append((v1.x,v1.y,v1.z,None,None,0.0))
|
||||
if not fcgeo.isReallyClosed(wire):
|
||||
if not DraftGeomUtils.isReallyClosed(wire):
|
||||
v = edges[-1].Vertexes[-1].Point
|
||||
points.append(fcvec.tup(v))
|
||||
points.append(DraftVecUtils.tup(v))
|
||||
# print "wire verts: ",points
|
||||
return points
|
||||
|
||||
@@ -1289,7 +1289,7 @@ def writeShape(ob,dxfobject,nospline=False):
|
||||
layer=getGroup(ob,exportList)))
|
||||
else:
|
||||
dxfobject.append(dxfLibrary.PolyLine(getWire(wire,nospline), [0.0,0.0,0.0],
|
||||
int(fcgeo.isReallyClosed(wire)), color=getACI(ob),
|
||||
int(DraftGeomUtils.isReallyClosed(wire)), color=getACI(ob),
|
||||
layer=getGroup(ob,exportList)))
|
||||
if len(processededges) < len(ob.Shape.Edges): # lone edges
|
||||
loneedges = []
|
||||
@@ -1318,7 +1318,7 @@ def writeShape(ob,dxfobject,nospline=False):
|
||||
else: # anything else is treated as lines
|
||||
ve1=edge.Vertexes[0].Point
|
||||
ve2=edge.Vertexes[1].Point
|
||||
dxfobject.append(dxfLibrary.Line([fcvec.tup(ve1), fcvec.tup(ve2)],
|
||||
dxfobject.append(dxfLibrary.Line([DraftVecUtils.tup(ve1), DraftVecUtils.tup(ve2)],
|
||||
color=getACI(ob),
|
||||
layer=getGroup(ob,exportList)))
|
||||
|
||||
@@ -1377,7 +1377,7 @@ def export(objectslist,filename,nospline=False):
|
||||
# temporary - as dxfLibrary doesn't support mtexts well, we use several single-line texts
|
||||
# well, anyway, at the moment, Draft only writes single-line texts, so...
|
||||
for text in ob.LabelText:
|
||||
point = fcvec.tup(FreeCAD.Vector(ob.Position.x,
|
||||
point = DraftVecUtils.tup(FreeCAD.Vector(ob.Position.x,
|
||||
ob.Position.y-ob.LabelText.index(text),
|
||||
ob.Position.z))
|
||||
if gui: height = float(ob.ViewObject.FontSize)
|
||||
@@ -1388,14 +1388,14 @@ def export(objectslist,filename,nospline=False):
|
||||
layer=getGroup(ob,exportList)))
|
||||
|
||||
elif 'Dimline' in ob.PropertiesList:
|
||||
p1 = fcvec.tup(ob.Start)
|
||||
p2 = fcvec.tup(ob.End)
|
||||
p1 = DraftVecUtils.tup(ob.Start)
|
||||
p2 = DraftVecUtils.tup(ob.End)
|
||||
base = Part.Line(ob.Start,ob.End).toShape()
|
||||
proj = fcgeo.findDistance(ob.Dimline,base)
|
||||
proj = DraftGeomUtils.findDistance(ob.Dimline,base)
|
||||
if not proj:
|
||||
pbase = fcvec.tup(ob.End)
|
||||
pbase = DraftVecUtils.tup(ob.End)
|
||||
else:
|
||||
pbase = fcvec.tup(ob.End.add(fcvec.neg(proj)))
|
||||
pbase = DraftVecUtils.tup(ob.End.add(DraftVecUtils.neg(proj)))
|
||||
dxf.append(dxfLibrary.Dimension(pbase,p1,p2,color=getACI(ob),
|
||||
layer=getGroup(ob,exportList)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user