Renamed Draft fcvec and fcgeo modules

Draft/draftlibs/fcvec becomes Draft/DraftVecUtils
Draft/draftlibs/fcgeo becomes Draft/DraftGeomUtils
This commit is contained in:
Yorik van Havre 2012-05-22 11:45:40 -03:00
parent e607ddf55f
commit 7086b80cb3
24 changed files with 413 additions and 451 deletions

View File

@ -12,10 +12,15 @@ The Draft module offer several convenient functions to work with simple objects.
.. automodule:: DraftSnap
:members:
The draftlibs contain two submodules, widely used throughout the Draft module: fcvec, which contains useful methods for dealing with vectors, and fcgeo, which offers many tools for working with Part shape objects.
The Draft module also contains two submodules, widely used throughout the Draft and Arch modules: DraftVecUtils, which contains useful methods for dealing with vectors, and DraftGeomUtils, which offers many tools for working with OpenCascade geometry.
.. automodule:: draftlibs.fcvec
.. automodule:: DraftVecUtils
:members:
.. automodule:: draftlibs.fcgeo
:members:
.. automodule:: DraftGeomUtils
:members:
The Draft module also features a module that contains trackers, special objects made to display 3D temporary geometry in the 3D scene, that have no real existence in the FreeCAD document.
.. automodule:: DraftTrackers
:members:

View File

@ -21,9 +21,7 @@
#* *
#***************************************************************************
import FreeCAD,FreeCADGui,Draft,math
from draftlibs import fcvec
import FreeCAD,FreeCADGui,Draft,math,DraftVecUtils
from FreeCAD import Vector
from PyQt4 import QtCore, QtGui
from pivy import coin

View File

@ -21,8 +21,7 @@
#* *
#***************************************************************************
import FreeCAD,FreeCADGui,Draft,ArchComponent
from draftlibs import fcvec
import FreeCAD,FreeCADGui,Draft,ArchComponent,DraftVecUtils
from FreeCAD import Vector
from PyQt4 import QtCore
@ -170,7 +169,7 @@ def makeFace(wires,method=2,cleanup=False):
# cleaning up rubbish in wires
if cleanup:
for i in range(len(wires)):
wires[i] = fcgeo.removeInterVertices(wires[i])
wires[i] = DraftGeomUtils.removeInterVertices(wires[i])
print "garbage removed"
for w in wires:
# we assume that the exterior boundary is that one with
@ -210,8 +209,7 @@ def meshToShape(obj,mark=True):
mark is True (default), non-solid objects will be marked in red'''
name = obj.Name
import Part,MeshPart
from draftlibs import fcgeo
import Part, MeshPart, DraftGeomUtils
if "Mesh" in obj.PropertiesList:
faces = []
mesh = obj.Mesh
@ -249,12 +247,12 @@ def meshToShape(obj,mark=True):
def removeShape(objs,mark=True):
'''takes an arch object (wall or structure) built on a cubic shape, and removes
the inner shape, keeping its length, width and height as parameters.'''
from draftlibs import fcgeo
import DraftGeomUtils
if not isinstance(objs,list):
objs = [objs]
for obj in objs:
if fcgeo.isCubic(obj.Shape):
dims = fcgeo.getCubicDimensions(obj.Shape)
if DraftGeomUtils.isCubic(obj.Shape):
dims = DraftGeomUtils.getCubicDimensions(obj.Shape)
if dims:
name = obj.Name
tp = Draft.getType(obj)
@ -270,7 +268,7 @@ def removeShape(objs,mark=True):
length = dims[1]
width = dims[2]
v1 = Vector(length/2,0,0)
v2 = fcvec.neg(v1)
v2 = DraftVecUtils.neg(v1)
v1 = dims[0].multVec(v1)
v2 = dims[0].multVec(v2)
line = Draft.makeLine(v1,v2)

View File

@ -21,8 +21,7 @@
#* *
#***************************************************************************
import FreeCAD,FreeCADGui,Draft,ArchComponent
from draftlibs import fcvec
import FreeCAD,FreeCADGui,Draft,ArchComponent, DraftVecUtils
from FreeCAD import Vector
from PyQt4 import QtCore
@ -104,8 +103,7 @@ class _Roof(ArchComponent.Component):
self.createGeometry(obj)
def createGeometry(self,obj):
import Part,math
from draftlibs import fcgeo
import Part, math, DraftGeomUtils
pl = obj.Placement
if obj.Base and obj.Face and obj.Angle:
@ -116,14 +114,14 @@ class _Roof(ArchComponent.Component):
c = round(math.tan(math.radians(obj.Angle)),Draft.precision())
norm = f.normalAt(0,0)
d = f.BoundBox.DiagonalLength
edges = fcgeo.sortEdges(f.Edges)
edges = DraftGeomUtils.sortEdges(f.Edges)
l = len(edges)
edges.append(edges[0])
shps = []
for i in range(l):
v = fcgeo.vec(fcgeo.angleBisection(edges[i],edges[i+1]))
v = DraftGeomUtils.vec(DraftGeomUtils.angleBisection(edges[i],edges[i+1]))
v.normalize()
bis = v.getAngle(fcgeo.vec(edges[i]))
bis = v.getAngle(DraftGeomUtils.vec(edges[i]))
delta = 1/math.cos(bis)
v.multiply(delta)
n = (FreeCAD.Vector(norm)).multiply(c)
@ -137,7 +135,7 @@ class _Roof(ArchComponent.Component):
c = c.removeSplitter()
if not c.isNull():
obj.Shape = c
if not fcgeo.isNull(pl):
if not DraftGeomUtils.isNull(pl):
obj.Placement = pl
class _ViewProviderRoof(ArchComponent.ViewProviderComponent):

View File

@ -21,11 +21,10 @@
#* *
#***************************************************************************
import FreeCAD,FreeCADGui,ArchComponent,WorkingPlane,Drawing,math,Draft,ArchCommands
import FreeCAD,FreeCADGui,ArchComponent,WorkingPlane,Drawing,math,Draft,ArchCommands, DraftVecUtils
from FreeCAD import Vector
from PyQt4 import QtCore
from pivy import coin
from draftlibs import fcvec
class _CommandSectionPlane:
@ -176,8 +175,7 @@ class _ArchDrawingView:
def updateSVG(self, obj,join=False):
"encapsulates a svg fragment into a transformation node"
import Part
from draftlibs import fcgeo
import Part, DraftGeomUtils
if hasattr(obj,"Source"):
if obj.Source:
if obj.Source.Objects:
@ -207,7 +205,7 @@ class _ArchDrawingView:
base = shape.pop()
for sh in shapes:
base = base.fuse(sh)
svgf = Drawing.projectToSVG(base,fcvec.neg(direction))
svgf = Drawing.projectToSVG(base,DraftVecUtils.neg(direction))
if svgf:
svgf = svgf.replace('stroke-width="0.35"','stroke-width="' + str(linewidth) + 'px"')
svg += svgf

View File

@ -21,8 +21,7 @@
#* *
#***************************************************************************
import FreeCAD,FreeCADGui,Draft,ArchComponent
from draftlibs import fcvec
import FreeCAD,FreeCADGui,Draft,ArchComponent,DraftVecUtils
from FreeCAD import Vector
from PyQt4 import QtCore
@ -99,7 +98,7 @@ class _Structure(ArchComponent.Component):
def getAxisPoints(self,obj):
"returns the gridpoints of linked axes"
from draftlibs import fcgeo
import DraftGeomUtils
pts = []
if len(obj.Axes) == 1:
for e in obj.Axes[0].Shape.Edges:
@ -109,12 +108,11 @@ class _Structure(ArchComponent.Component):
set2 = obj.Axes[1].Shape.Edges
for e1 in set1:
for e2 in set2:
pts.extend(fcgeo.findIntersection(e1,e2))
pts.extend(DraftGeomUtils.findIntersection(e1,e2))
return pts
def createGeometry(self,obj):
import Part
from draftlibs import fcgeo
import Part, DraftGeomUtils
# getting default values
height = normal = None
if obj.Length:
@ -187,7 +185,7 @@ class _Structure(ArchComponent.Component):
obj.Shape = Part.makeCompound(fsh)
else:
obj.Shape = base
if not fcgeo.isNull(pl): obj.Placement = pl
if not DraftGeomUtils.isNull(pl): obj.Placement = pl
class _ViewProviderStructure(ArchComponent.ViewProviderComponent):
"A View Provider for the Structure object"

View File

@ -23,8 +23,7 @@
"The FreeCAD Arch Vector Rendering Module"
import FreeCAD,math,Part,ArchCommands
from draftlibs import fcvec,fcgeo
import FreeCAD,math,Part,ArchCommands,DraftVecUtils,DraftGeomUtils
DEBUG = True # if we want debug messages
MAXLOOP = 10 # the max number of loop before abort
@ -171,7 +170,7 @@ class Renderer:
norm = face[0].normalAt(0,0)
for w in face[0].Wires:
verts = []
edges = fcgeo.sortEdges(w.Edges)
edges = DraftGeomUtils.sortEdges(w.Edges)
for e in edges:
v = e.Vertexes[0].Point
v = self.wp.getLocalCoords(v)
@ -196,7 +195,7 @@ class Renderer:
wires = []
for w in face[0].Wires:
verts = []
edges = fcgeo.sortEdges(w.Edges)
edges = DraftGeomUtils.sortEdges(w.Edges)
for e in edges:
v = e.Vertexes[0].Point
verts.append(FreeCAD.Vector(v.x,v.y,0))
@ -239,11 +238,11 @@ class Renderer:
FreeCAD.Vector(bb.XMax,bb.YMax,bb.ZMax)]
for c in corners:
dv = c.sub(placement.Base)
um1 = fcvec.project(dv,self.wp.u).Length
um1 = DraftVecUtils.project(dv,self.wp.u).Length
um = max(um,um1)
vm1 = fcvec.project(dv,self.wp.v).Length
vm1 = DraftVecUtils.project(dv,self.wp.v).Length
vm = max(vm,vm1)
wm1 = fcvec.project(dv,self.wp.axis).Length
wm1 = DraftVecUtils.project(dv,self.wp.axis).Length
wm = max(wm,wm1)
p1 = FreeCAD.Vector(-um,vm,0)
p2 = FreeCAD.Vector(um,vm,0)
@ -252,7 +251,7 @@ class Renderer:
cutface = Part.makePolygon([p1,p2,p3,p4,p1])
cutface = Part.Face(cutface)
cutface.Placement = placement
cutnormal = fcvec.scaleTo(self.wp.axis,wm)
cutnormal = DraftVecUtils.scaleTo(self.wp.axis,wm)
cutvolume = cutface.extrude(cutnormal)
shapes = []
faces = []
@ -265,7 +264,7 @@ class Renderer:
faces.append([f]+sh[1:])
sec = sol.section(cutface)
if sec.Edges:
wires = fcgeo.findWires(sec.Edges)
wires = DraftGeomUtils.findWires(sec.Edges)
for w in wires:
sec = Part.Face(w)
sections.append([sec,fill])
@ -313,7 +312,7 @@ class Renderer:
# even so, faces can still overlap if their edges cross each other
for e1 in face1[0].Edges:
for e2 in face2[0].Edges:
if fcgeo.findIntersection(e1,e2):
if DraftGeomUtils.findIntersection(e1,e2):
return True
return False
@ -354,8 +353,8 @@ class Renderer:
front = 0
for v in face1[0].Vertexes:
dv = v.Point.sub(face2[0].Vertexes[0].Point)
dv = fcvec.project(dv,norm)
if fcvec.isNull(dv):
dv = DraftVecUtils.project(dv,norm)
if DraftVecUtils.isNull(dv):
behind += 1
front += 1
else:
@ -377,8 +376,8 @@ class Renderer:
front = 0
for v in face2[0].Vertexes:
dv = v.Point.sub(face1[0].Vertexes[0].Point)
dv = fcvec.project(dv,norm)
if fcvec.isNull(dv):
dv = DraftVecUtils.project(dv,norm)
if DraftVecUtils.isNull(dv):
behind += 1
front += 1
else:
@ -545,7 +544,7 @@ class Renderer:
def getPathData(self,w):
"Returns a SVG path data string from a 2D wire"
edges = fcgeo.sortEdges(w.Edges)
edges = DraftGeomUtils.sortEdges(w.Edges)
v = edges[0].Vertexes[0].Point
svg = 'M '+ str(v.x) +' '+ str(v.y) + ' '
for e in edges:

View File

@ -21,8 +21,7 @@
#* *
#***************************************************************************
import FreeCAD,FreeCADGui,Draft,ArchComponent
from draftlibs import fcvec
import FreeCAD,FreeCADGui,Draft,ArchComponent,DraftVecUtils
from FreeCAD import Vector
from PyQt4 import QtCore
@ -180,13 +179,13 @@ class _CommandWall:
n = FreeCAD.DraftWorkingPlane.axis
bv = point.sub(b)
dv = bv.cross(n)
dv = fcvec.scaleTo(dv,self.Width/2)
dv = DraftVecUtils.scaleTo(dv,self.Width/2)
if self.Align == "Center":
self.tracker.update([b,point])
elif self.Align == "Left":
self.tracker.update([b.add(dv),point.add(dv)])
else:
dv = fcvec.neg(dv)
dv = DraftVecUtils.neg(dv)
self.tracker.update([b.add(dv),point.add(dv)])
def taskbox(self):
@ -275,10 +274,10 @@ class _Wall(ArchComponent.Component):
f = w
f = Part.Face(f)
n = f.normalAt(0,0)
v1 = fcvec.scaleTo(n,width)
v1 = DraftVecUtils.scaleTo(n,width)
f.translate(v1)
v2 = fcvec.neg(v1)
v2 = fcvec.scale(v1,-2)
v2 = DraftVecUtils.neg(v1)
v2 = DraftVecUtils.scale(v1,-2)
f = f.extrude(v2)
if delta:
f.translate(delta)
@ -290,8 +289,7 @@ class _Wall(ArchComponent.Component):
if not obj.Base:
return
import Part
from draftlibs import fcgeo
import Part, DraftGeomUtils
flat = False
if hasattr(obj.ViewObject,"DisplayMode"):
@ -304,25 +302,25 @@ class _Wall(ArchComponent.Component):
def getbase(wire):
"returns a full shape from a base wire"
dvec = fcgeo.vec(wire.Edges[0]).cross(normal)
dvec = DraftGeomUtils.vec(wire.Edges[0]).cross(normal)
dvec.normalize()
if obj.Align == "Left":
dvec = dvec.multiply(width)
w2 = fcgeo.offsetWire(wire,dvec)
w1 = Part.Wire(fcgeo.sortEdges(wire.Edges))
sh = fcgeo.bind(w1,w2)
w2 = DraftGeomUtils.offsetWire(wire,dvec)
w1 = Part.Wire(DraftGeomUtils.sortEdges(wire.Edges))
sh = DraftGeomUtils.bind(w1,w2)
elif obj.Align == "Right":
dvec = dvec.multiply(width)
dvec = fcvec.neg(dvec)
w2 = fcgeo.offsetWire(wire,dvec)
w1 = Part.Wire(fcgeo.sortEdges(wire.Edges))
sh = fcgeo.bind(w1,w2)
dvec = DraftVecUtils.neg(dvec)
w2 = DraftGeomUtils.offsetWire(wire,dvec)
w1 = Part.Wire(DraftGeomUtils.sortEdges(wire.Edges))
sh = DraftGeomUtils.bind(w1,w2)
elif obj.Align == "Center":
dvec = dvec.multiply(width/2)
w1 = fcgeo.offsetWire(wire,dvec)
dvec = fcvec.neg(dvec)
w2 = fcgeo.offsetWire(wire,dvec)
sh = fcgeo.bind(w1,w2)
w1 = DraftGeomUtils.offsetWire(wire,dvec)
dvec = DraftVecUtils.neg(dvec)
w2 = DraftGeomUtils.offsetWire(wire,dvec)
sh = DraftGeomUtils.bind(w1,w2)
# fixing self-intersections
sh.fix(0.1,0,1)
if height and (not flat):
@ -388,7 +386,7 @@ class _Wall(ArchComponent.Component):
if base:
obj.Shape = base
if not fcgeo.isNull(pl):
if not DraftGeomUtils.isNull(pl):
obj.Placement = pl
class _ViewProviderWall(ArchComponent.ViewProviderComponent):

View File

@ -21,8 +21,7 @@
#* *
#***************************************************************************
import FreeCAD,FreeCADGui,Draft,ArchComponent
from draftlibs import fcvec
import FreeCAD,FreeCADGui,Draft,ArchComponent,DraftVecUtils
from FreeCAD import Vector
from PyQt4 import QtCore,QtGui
@ -109,8 +108,7 @@ class _Window(ArchComponent.Component):
self.createGeometry(obj)
def createGeometry(self,obj):
import Part
from draftlibs import fcgeo
import Part, DraftGeomUtils
pl = obj.Placement
if obj.Base:
if obj.Base.isDerivedFrom("Part::Feature"):
@ -135,7 +133,7 @@ class _Window(ArchComponent.Component):
norm = shape.normalAt(0,0)
thk = float(obj.WindowParts[(i*5)+3])
if thk:
exv = fcvec.scaleTo(norm,thk)
exv = DraftVecUtils.scaleTo(norm,thk)
shape = shape.extrude(exv)
for w in wires:
f = Part.Face(w)
@ -144,12 +142,12 @@ class _Window(ArchComponent.Component):
if obj.WindowParts[(i*5)+4]:
zof = float(obj.WindowParts[(i*5)+4])
if zof:
zov = fcvec.scaleTo(norm,zof)
zov = DraftVecUtils.scaleTo(norm,zof)
shape.translate(zov)
print shape
shapes.append(shape)
obj.Shape = Part.makeCompound(shapes)
if not fcgeo.isNull(pl):
if not DraftGeomUtils.isNull(pl):
obj.Placement = pl
class _ViewProviderWindow(ArchComponent.ViewProviderComponent):

View File

@ -21,8 +21,7 @@
#* *
#***************************************************************************
import ifcReader, FreeCAD, Arch, Draft, os, sys, time, Part
from draftlibs import fcvec
import ifcReader, FreeCAD, Arch, Draft, os, sys, time, Part, DraftVecUtils
__title__="FreeCAD IFC importer"
__author__ = "Yorik van Havre"
@ -448,7 +447,7 @@ def getPlacement(entity):
z = getVector(entity.Axis)
y = z.cross(x)
loc = getVector(entity.Location)
m = fcvec.getPlaneRotation(x,y,z)
m = DraftVecUtils.getPlaneRotation(x,y,z)
pl = FreeCAD.Placement(m)
pl.move(loc)
elif entity.type == "IFCLOCALPLACEMENT":

View File

@ -21,8 +21,7 @@
#* *
#***************************************************************************
import FreeCAD
from draftlibs import fcgeo
import FreeCAD, DraftGeomUtils
if open.__module__ == '__builtin__':
pythonopen = open
@ -42,7 +41,7 @@ def getIndices(shape,offset):
for f in shape.Faces:
fi = ""
# OCC vertices are unsorted. We need to sort in the right order...
edges = fcgeo.sortEdges(f.Wire.Edges)
edges = DraftGeomUtils.sortEdges(f.Wire.Edges)
print edges
for e in edges:
print e.Vertexes[0].Point,e.Vertexes[1].Point

View File

@ -7,6 +7,8 @@ SET(Draft_SRCS
DraftGui.py
DraftSnap.py
DraftTrackers.py
DraftVecUtils.py
DraftGeomUtils.py
WorkingPlane.py
importDXF.py
importOCA.py
@ -22,8 +24,6 @@ SET(DraftLibs_SRCS
draftlibs/dxfImportObjects.py
draftlibs/dxfLibrary.py
draftlibs/dxfReader.py
draftlibs/fcgeo.py
draftlibs/fcvec.py
draftlibs/__init__.py
)
SOURCE_GROUP("draftlibs" FILES ${DraftLibs_SRCS})

View File

@ -54,9 +54,9 @@ How it works / how to extend:
- DraftTools.py: Contains the user tools of the Draft module (the commands
from the Draft menu), and a couple of helpers such as the "Trackers"
(temporary geometry used while drawing)
- draftlibs/fcvec.py: a vector math library, contains functions that are not
- DraftVecUtils.py: a vector math library, contains functions that are not
implemented in the standard FreeCAD vector
- draftlibs/fcgeo.py: a library of misc functions to manipulate shapes.
- DraftGeomUtils.py: a library of misc functions to manipulate shapes.
The Draft.py contains everything to create geometry in the scene. You
should start there if you intend to modify something. Then, the DraftTools
@ -72,9 +72,8 @@ How it works / how to extend:
'''
# import FreeCAD modules
import FreeCAD, math, sys, os
import FreeCAD, math, sys, os, DraftVecUtils
from FreeCAD import Vector
from draftlibs import fcvec
from pivy import coin
if FreeCAD.GuiUp:
@ -395,8 +394,8 @@ def makeCircle(radius, placement=None, face=True, startangle=None, endangle=None
ref = placement.multVec(FreeCAD.Vector(1,0,0))
v1 = (edge.Vertexes[0].Point).sub(edge.Curve.Center)
v2 = (edge.Vertexes[-1].Point).sub(edge.Curve.Center)
a1 = -math.degrees(fcvec.angle(v1,ref))
a2 = -math.degrees(fcvec.angle(v2,ref))
a1 = -math.degrees(DraftVecUtils.angle(v1,ref))
a2 = -math.degrees(DraftVecUtils.angle(v2,ref))
obj.FirstAngle = a1
obj.LastAngle = a2
else:
@ -514,15 +513,14 @@ def makeWire(pointslist,closed=False,placement=None,face=True,support=None):
and last points are identical, the wire is closed. If face is
true (and wire is closed), the wire will appear filled. Instead of
a pointslist, you can also pass a Part Wire.'''
from draftlibs import fcgeo
import Part
import DraftGeomUtils, Part
if not isinstance(pointslist,list):
e = pointslist.Wires[0].Edges
pointslist = Part.Wire(fcgeo.sortEdges(e))
pointslist = Part.Wire(DraftGeomUtils.sortEdges(e))
nlist = []
for v in pointslist.Vertexes:
nlist.append(v.Point)
if fcgeo.isReallyClosed(pointslist):
if DraftGeomUtils.isReallyClosed(pointslist):
closed = True
pointslist = nlist
print pointslist
@ -774,8 +772,7 @@ def fuse(object1,object2):
the union of the 2 given objects. If the objects are
coplanar, a special Draft Wire is used, otherwise we use
a standard Part fuse.'''
from draftlibs import fcgeo
import Part
import DraftGeomUtils, Part
# testing if we have holes:
holes = False
fshape = object1.Shape.fuse(object2.Shape)
@ -783,7 +780,7 @@ def fuse(object1,object2):
for f in fshape.Faces:
if len(f.Wires) > 1:
holes = True
if fcgeo.isCoplanar(object1.Shape.fuse(object2.Shape).Faces) and not holes:
if DraftGeomUtils.isCoplanar(object1.Shape.fuse(object2.Shape).Faces) and not holes:
obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython","Fusion")
_Wire(obj)
if gui:
@ -879,12 +876,12 @@ def array(objectslist,arg1,arg2,arg3,arg4=None):
typecheck([(xvector,Vector), (yvector,Vector), (xnum,int), (ynum,int)], "rectArray")
if not isinstance(objectslist,list): objectslist = [objectslist]
for xcount in range(xnum):
currentxvector=fcvec.scale(xvector,xcount)
currentxvector=DraftVecUtils.scale(xvector,xcount)
if not xcount==0:
move(objectslist,currentxvector,True)
for ycount in range(ynum):
currentxvector=FreeCAD.Base.Vector(currentxvector)
currentyvector=currentxvector.add(fcvec.scale(yvector,ycount))
currentyvector=currentxvector.add(DraftVecUtils.scale(yvector,ycount))
if not ycount==0:
move(objectslist,currentyvector,True)
def polarArray(objectslist,center,angle,num):
@ -918,7 +915,7 @@ def rotate(objectslist,angle,center=Vector(0,0,0),axis=Vector(0,0,1),copy=False)
newobj = obj
if (obj.isDerivedFrom("Part::Feature")):
shape = obj.Shape.copy()
shape.rotate(fcvec.tup(center), fcvec.tup(axis), angle)
shape.rotate(DraftVecUtils.tup(center), DraftVecUtils.tup(axis), angle)
newobj.Shape = shape
elif (obj.isDerivedFrom("App::Annotation")):
if axis.normalize() == Vector(1,0,0):
@ -939,7 +936,7 @@ def rotate(objectslist,angle,center=Vector(0,0,0),axis=Vector(0,0,1),copy=False)
elif hasattr(obj,"Placement"):
shape = Part.Shape()
shape.Placement = obj.Placement
shape.rotate(fcvec.tup(center), fcvec.tup(axis), angle)
shape.rotate(DraftVecUtils.tup(center), DraftVecUtils.tup(axis), angle)
newobj.Placement = shape.Placement
if copy:
formatObject(newobj,obj)
@ -972,7 +969,7 @@ def scale(objectslist,delta=Vector(1,1,1),center=Vector(0,0,0),copy=False,legacy
sh = sh.transformGeometry(m)
corr = Vector(center.x,center.y,center.z)
corr.scale(delta.x,delta.y,delta.z)
corr = fcvec.neg(corr.sub(center))
corr = DraftVecUtils.neg(corr.sub(center))
sh.translate(corr)
if getType(obj) == "Rectangle":
p = []
@ -982,8 +979,8 @@ def scale(objectslist,delta=Vector(1,1,1),center=Vector(0,0,0),copy=False,legacy
diag = p[2].sub(p[0])
bb = p[1].sub(p[0])
bh = p[3].sub(p[0])
nb = fcvec.project(diag,bb)
nh = fcvec.project(diag,bh)
nb = DraftVecUtils.project(diag,bb)
nh = DraftVecUtils.project(diag,bh)
if obj.Length < 0: l = -nb.Length
else: l = nb.Length
if obj.Height < 0: h = -nh.Length
@ -1016,7 +1013,7 @@ def scale(objectslist,delta=Vector(1,1,1),center=Vector(0,0,0),copy=False,legacy
obj.Scale = delta
corr = Vector(center.x,center.y,center.z)
corr.scale(delta.x,delta.y,delta.z)
corr = fcvec.neg(corr.sub(center))
corr = DraftVecUtils.neg(corr.sub(center))
p = obj.Placement
p.move(corr)
obj.Placement = p
@ -1037,8 +1034,7 @@ def offset(obj,delta,copy=False,bind=False,sym=False,occ=False):
and the offsetted wires will be bound by their endpoints, forming a face
if sym is True, bind must be true too, and the offset is made on both
sides, the total width being the given delta length.'''
import Part
from draftlibs import fcgeo
import Part, DraftGeomUtils
def getRect(p,obj):
"returns length,heigh,placement"
@ -1047,8 +1043,8 @@ def offset(obj,delta,copy=False,bind=False,sym=False,occ=False):
diag = p[2].sub(p[0])
bb = p[1].sub(p[0])
bh = p[3].sub(p[0])
nb = fcvec.project(diag,bb)
nh = fcvec.project(diag,bh)
nb = DraftVecUtils.project(diag,bb)
nh = DraftVecUtils.project(diag,bh)
if obj.Length < 0: l = -nb.Length
else: l = nb.Length
if obj.Height < 0: h = -nh.Length
@ -1058,7 +1054,7 @@ def offset(obj,delta,copy=False,bind=False,sym=False,occ=False):
def getRadius(obj,delta):
"returns a new radius for a regular polygon"
an = math.pi/obj.FacesNumber
nr = fcvec.rotate(delta,-an)
nr = DraftVecUtils.rotate(delta,-an)
nr.multiply(1/math.cos(an))
nr = obj.Shape.Vertexes[0].Point.add(nr)
nr = nr.sub(obj.Placement.Base)
@ -1075,18 +1071,18 @@ def offset(obj,delta,copy=False,bind=False,sym=False,occ=False):
else:
if sym:
d1 = delta.multiply(0.5)
d2 = fcvec.neg(d1)
n1 = fcgeo.offsetWire(obj.Shape,d1)
n2 = fcgeo.offsetWire(obj.Shape,d2)
d2 = DraftVecUtils.neg(d1)
n1 = DraftGeomUtils.offsetWire(obj.Shape,d1)
n2 = DraftGeomUtils.offsetWire(obj.Shape,d2)
else:
newwire = fcgeo.offsetWire(obj.Shape,delta)
p = fcgeo.getVerts(newwire)
newwire = DraftGeomUtils.offsetWire(obj.Shape,delta)
p = DraftGeomUtils.getVerts(newwire)
if occ:
newobj = FreeCAD.ActiveDocument.addObject("Part::Feature","Offset")
newobj.Shape = fcgeo.offsetWire(obj.Shape,delta,occ=True)
newobj.Shape = DraftGeomUtils.offsetWire(obj.Shape,delta,occ=True)
formatObject(newobj,obj)
elif bind:
if not fcgeo.isReallyClosed(obj.Shape):
if not DraftGeomUtils.isReallyClosed(obj.Shape):
if sym:
s1 = n1
s2 = n2
@ -1161,8 +1157,7 @@ def draftify(objectslist,makeblock=False):
'''draftify(objectslist,[makeblock]): turns each object of the given list
(objectslist can also be a single object) into a Draft parametric
wire. If makeblock is True, multiple objects will be grouped in a block'''
from draftlibs import fcgeo
import Part
import DraftGeomUtils, Part
if not isinstance(objectslist,list):
objectslist = [objectslist]
@ -1170,7 +1165,7 @@ def draftify(objectslist,makeblock=False):
for obj in objectslist:
if obj.isDerivedFrom('Part::Feature'):
for w in obj.Shape.Wires:
if fcgeo.hasCurves(w):
if DraftGeomUtils.hasCurves(w):
if (len(w.Edges) == 1) and isinstance(w.Edges[0].Curve,Part.Circle):
nobj = makeCircle(w.Edges[0])
else:
@ -1199,8 +1194,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
with the given linewidth and fontsize (used if the given object contains
any text). You can also supply an arbitrary projection vector. the
scale parameter allows to scale linewidths down, so they are resolution-independant.'''
import Part
from draftlibs import fcgeo
import Part, DraftGeomUtils
svg = ""
linewidth = linewidth/scale
fontsize = (fontsize/scale)/2
@ -1209,7 +1203,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
if isinstance(direction,FreeCAD.Vector):
if direction != Vector(0,0,0):
plane = WorkingPlane.plane()
plane.alignToPointAndAxis(Vector(0,0,0),fcvec.neg(direction),0)
plane.alignToPointAndAxis(Vector(0,0,0),DraftVecUtils.neg(direction),0)
elif isinstance(direction,WorkingPlane.plane):
plane = direction
@ -1240,10 +1234,10 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
def getProj(vec):
if not plane: return vec
nx = fcvec.project(vec,plane.u)
nx = DraftVecUtils.project(vec,plane.u)
lx = nx.Length
if abs(nx.getAngle(plane.u)) > 0.1: lx = -lx
ny = fcvec.project(vec,plane.v)
ny = DraftVecUtils.project(vec,plane.v)
ly = ny.Length
if abs(ny.getAngle(plane.v)) > 0.1: ly = -ly
return Vector(lx,ly,0)
@ -1255,7 +1249,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
def getPath(edges):
svg ='<path id="' + name + '" '
edges = fcgeo.sortEdges(edges)
edges = DraftGeomUtils.sortEdges(edges)
v = getProj(edges[0].Vertexes[0].Point)
svg += 'd="M '+ str(v.x) +' '+ str(v.y) + ' '
for e in edges:
@ -1320,7 +1314,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
vtext = m.multiply(plane.u)
else:
vtext = m.multiply(Vector(1,0,0))
angle = -fcvec.angle(vtext)
angle = -DraftVecUtils.angle(vtext)
svg += 'd="M '+str(p1.x)+' '+str(p1.y)+' '
svg += 'L '+str(p2.x)+' '+str(p2.y)+' '
svg += 'L '+str(p3.x)+' '+str(p3.y)+' '
@ -1328,8 +1322,8 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
else:
ts = (len(dimText)*obj.ViewObject.FontSize)/4
rm = ((p3.sub(p2)).Length/2)-ts
p2a = getProj(p2.add(fcvec.scaleTo(p3.sub(p2),rm)))
p2b = getProj(p3.add(fcvec.scaleTo(p2.sub(p3),rm)))
p2a = getProj(p2.add(DraftVecUtils.scaleTo(p3.sub(p2),rm)))
p2b = getProj(p3.add(DraftVecUtils.scaleTo(p2.sub(p3),rm)))
angle = 0
svg += 'd="M '+str(p1.x)+' '+str(p1.y)+' '
svg += 'L '+str(p2.x)+' '+str(p2.y)+' '
@ -1457,7 +1451,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
wiredEdges.extend(w.Edges)
if len(wiredEdges) != len(obj.Shape.Edges):
for e in obj.Shape.Edges:
if (fcgeo.findEdge(e,wiredEdges) == None):
if (DraftGeomUtils.findEdge(e,wiredEdges) == None):
svg += getPath([e])
else:
svg = getCircle(obj.Shape.Edges[0])
@ -1501,8 +1495,7 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
constraints will be automatically added to wire nodes, rectangles
and circles. If addTo is an existing sketch, geometry will be added to it instead of
creating a new one.'''
import Part
from draftlibs import fcgeo
import Part, DraftGeomUtils
from Sketcher import Constraint
StartPoint = 1
@ -1558,18 +1551,18 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
segs = range(last-len(obj.Shape.Edges),last-1)
for seg in segs:
nobj.addConstraint(Constraint("Coincident",seg,EndPoint,seg+1,StartPoint))
if fcgeo.isAligned(nobj.Geometry[seg],"x"):
if DraftGeomUtils.isAligned(nobj.Geometry[seg],"x"):
nobj.addConstraint(Constraint("Vertical",seg))
elif fcgeo.isAligned(nobj.Geometry[seg],"y"):
elif DraftGeomUtils.isAligned(nobj.Geometry[seg],"y"):
nobj.addConstraint(Constraint("Horizontal",seg))
if closed:
nobj.addConstraint(Constraint("Coincident",last-1,EndPoint,segs[0],StartPoint))
ok = True
if (not ok) and obj.isDerivedFrom("Part::Feature"):
if fcgeo.hasOnlyWires(obj.Shape):
if DraftGeomUtils.hasOnlyWires(obj.Shape):
for w in obj.Shape.Wires:
for edge in fcgeo.sortEdges(w.Edges):
g = fcgeo.geom(edge)
for edge in DraftGeomUtils.sortEdges(w.Edges):
g = DraftGeomUtils.geom(edge)
if g:
nobj.addGeometry(g)
if autoconstraints:
@ -1577,20 +1570,20 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
segs = range(last-len(w.Edges),last-1)
for seg in segs:
nobj.addConstraint(Constraint("Coincident",seg,EndPoint,seg+1,StartPoint))
if fcgeo.isAligned(nobj.Geometry[seg],"x"):
if DraftGeomUtils.isAligned(nobj.Geometry[seg],"x"):
nobj.addConstraint(Constraint("Vertical",seg))
elif fcgeo.isAligned(nobj.Geometry[seg],"y"):
elif DraftGeomUtils.isAligned(nobj.Geometry[seg],"y"):
nobj.addConstraint(Constraint("Horizontal",seg))
if w.isClosed:
nobj.addConstraint(Constraint("Coincident",last-1,EndPoint,segs[0],StartPoint))
else:
for edge in obj.Shape.Edges:
nobj.addGeometry(fcgeo.geom(edge))
nobj.addGeometry(DraftGeomUtils.geom(edge))
if autoconstraints:
last = nobj.GeometryCount - 1
if fcgeo.isAligned(nobj.Geometry[last],"x"):
if DraftGeomUtils.isAligned(nobj.Geometry[last],"x"):
nobj.addConstraint(Constraint("Vertical",last))
elif fcgeo.isAligned(nobj.Geometry[last],"y"):
elif DraftGeomUtils.isAligned(nobj.Geometry[last],"y"):
nobj.addConstraint(Constraint("Horizontal",last))
ok = True
if ok:
@ -1793,45 +1786,44 @@ class _ViewProviderDimension:
obj.Override = ''
def calcGeom(self,obj):
import Part
from draftlibs import fcgeo
import Part, DraftGeomUtils
p1 = obj.Start
p4 = obj.End
base = Part.Line(p1,p4).toShape()
proj = fcgeo.findDistance(obj.Dimline,base)
proj = DraftGeomUtils.findDistance(obj.Dimline,base)
if not proj:
p2 = p1
p3 = p4
else:
p2 = p1.add(fcvec.neg(proj))
p3 = p4.add(fcvec.neg(proj))
p2 = p1.add(DraftVecUtils.neg(proj))
p3 = p4.add(DraftVecUtils.neg(proj))
dmax = obj.ViewObject.ExtLines
if dmax and (proj.Length > dmax):
p1 = p2.add(fcvec.scaleTo(proj,dmax))
p4 = p3.add(fcvec.scaleTo(proj,dmax))
midpoint = p2.add(fcvec.scale(p3.sub(p2),0.5))
p1 = p2.add(DraftVecUtils.scaleTo(proj,dmax))
p4 = p3.add(DraftVecUtils.scaleTo(proj,dmax))
midpoint = p2.add(DraftVecUtils.scale(p3.sub(p2),0.5))
if not proj:
ed = fcgeo.vec(base)
ed = DraftGeomUtils.vec(base)
proj = ed.cross(Vector(0,0,1))
if not proj: norm = Vector(0,0,1)
else: norm = fcvec.neg(p3.sub(p2).cross(proj))
if not fcvec.isNull(norm):
else: norm = DraftVecUtils.neg(p3.sub(p2).cross(proj))
if not DraftVecUtils.isNull(norm):
norm.normalize()
va = get3DView().getViewDirection()
if va.getAngle(norm) < math.pi/2:
norm = fcvec.neg(norm)
norm = DraftVecUtils.neg(norm)
u = p3.sub(p2)
u.normalize()
c = get3DView().getCameraNode()
r = c.orientation.getValue()
ru = Vector(r.multVec(coin.SbVec3f(1,0,0)).getValue())
if ru.getAngle(u) > math.pi/2: u = fcvec.neg(u)
if ru.getAngle(u) > math.pi/2: u = DraftVecUtils.neg(u)
v = norm.cross(u)
offset = fcvec.scaleTo(v,obj.ViewObject.FontSize*.2)
offset = DraftVecUtils.scaleTo(v,obj.ViewObject.FontSize*.2)
if obj.ViewObject:
if hasattr(obj.ViewObject,"DisplayMode"):
if obj.ViewObject.DisplayMode == "3D":
offset = fcvec.neg(offset)
offset = DraftVecUtils.neg(offset)
if hasattr(obj.ViewObject,"TextPosition"):
if obj.ViewObject.TextPosition == Vector(0,0,0):
tbase = midpoint.add(offset)
@ -1839,7 +1831,7 @@ class _ViewProviderDimension:
tbase = obj.ViewObject.TextPosition
else:
tbase = midpoint.add(offset)
rot = FreeCAD.Placement(fcvec.getPlaneRotation(u,v,norm)).Rotation.Q
rot = FreeCAD.Placement(DraftVecUtils.getPlaneRotation(u,v,norm)).Rotation.Q
return p1,p2,p3,p4,tbase,norm,rot
def attach(self, obj):
@ -1858,7 +1850,7 @@ class _ViewProviderDimension:
self.text.string = self.text3d.string = ''
self.textpos = coin.SoTransform()
self.textpos.translation.setValue([tbase.x,tbase.y,tbase.z])
tm = fcvec.getPlaneRotation(p3.sub(p2),norm)
tm = DraftVecUtils.getPlaneRotation(p3.sub(p2),norm)
rm = coin.SbRotation()
self.textpos.rotation = rm
label = coin.SoSeparator()
@ -1917,11 +1909,11 @@ class _ViewProviderDimension:
# arc linked dimension
e = obj.Base.Shape.Edges[obj.LinkedVertices[0]]
c = e.Curve.Center
bray = fcvec.scaleTo(obj.Dimline.sub(c),e.Curve.Radius)
bray = DraftVecUtils.scaleTo(obj.Dimline.sub(c),e.Curve.Radius)
if obj.LinkedVertices[1] == 1:
v1 = c
else:
v1 = c.add(fcvec.neg(bray))
v1 = c.add(DraftVecUtils.neg(bray))
v2 = c.add(bray)
else:
# linear linked dimension
@ -1952,8 +1944,8 @@ class _ViewProviderDimension:
else:
ts = (len(text)*obj.ViewObject.FontSize)/4
rm = ((p3.sub(p2)).Length/2)-ts
p2a = p2.add(fcvec.scaleTo(p3.sub(p2),rm))
p2b = p3.add(fcvec.scaleTo(p2.sub(p3),rm))
p2a = p2.add(DraftVecUtils.scaleTo(p3.sub(p2),rm))
p2b = p3.add(DraftVecUtils.scaleTo(p2.sub(p3),rm))
self.coords.point.setValues([[p1.x,p1.y,p1.z],
[p2.x,p2.y,p2.z],
[p2a.x,p2a.y,p2a.z],
@ -2149,15 +2141,14 @@ class _ViewProviderAngularDimension:
self.onChanged(vobj,"FontName")
def calcGeom(self,obj):
import Part
from draftlibs import fcgeo
import Part, DraftGeomUtils
rad = (obj.Dimline.sub(obj.Center)).Length
cir = Part.makeCircle(rad,obj.Center,Vector(0,0,1),obj.FirstAngle,obj.LastAngle)
cp = fcgeo.findMidpoint(cir.Edges[0])
cp = DraftGeomUtils.findMidpoint(cir.Edges[0])
rv = cp.sub(obj.Center)
rv = fcvec.scaleTo(rv,rv.Length + obj.ViewObject.FontSize*.2)
rv = DraftVecUtils.scaleTo(rv,rv.Length + obj.ViewObject.FontSize*.2)
tbase = obj.Center.add(rv)
trot = fcvec.angle(rv)-math.pi/2
trot = DraftVecUtils.angle(rv)-math.pi/2
if (trot > math.pi/2) or (trot < -math.pi/2):
trot = trot + math.pi
s = getParam("dimorientation")
@ -2276,8 +2267,7 @@ class _Rectangle:
self.createGeometry(fp)
def createGeometry(self,fp):
import Part
from draftlibs import fcgeo
import Part, DraftGeomUtils
plm = fp.Placement
p1 = Vector(0,0,0)
p2 = Vector(p1.x+fp.Length,p1.y,p1.z)
@ -2286,7 +2276,7 @@ class _Rectangle:
shape = Part.makePolygon([p1,p2,p3,p4,p1])
if "FilletRadius" in fp.PropertiesList:
if fp.FilletRadius != 0:
w = fcgeo.filletWire(shape,fp.FilletRadius)
w = DraftGeomUtils.filletWire(shape,fp.FilletRadius)
if w:
shape = w
shape = Part.Face(shape)
@ -2399,8 +2389,7 @@ class _Wire:
fp.Points = pts
def createGeometry(self,fp):
import Part
from draftlibs import fcgeo
import Part, DraftGeomUtils
plm = fp.Placement
if fp.Base and (not fp.Tool):
if fp.Base.isDerivedFrom("Sketcher::SketchObject"):
@ -2416,8 +2405,8 @@ class _Wire:
sh1 = fp.Base.Shape.copy()
sh2 = fp.Tool.Shape.copy()
shape = sh1.fuse(sh2)
if fcgeo.isCoplanar(shape.Faces):
shape = fcgeo.concatenate(shape)
if DraftGeomUtils.isCoplanar(shape.Faces):
shape = DraftGeomUtils.concatenate(shape)
fp.Shape = shape
p = []
for v in shape.Vertexes: p.append(v.Point)
@ -2430,7 +2419,7 @@ class _Wire:
shape = Part.makePolygon(fp.Points+[fp.Points[0]])
if "FilletRadius" in fp.PropertiesList:
if fp.FilletRadius != 0:
w = fcgeo.filletWire(shape,fp.FilletRadius)
w = DraftGeomUtils.filletWire(shape,fp.FilletRadius)
if w:
shape = w
shape = Part.Face(shape)
@ -2444,7 +2433,7 @@ class _Wire:
shape = Part.Wire(edges)
if "FilletRadius" in fp.PropertiesList:
if fp.FilletRadius != 0:
w = fcgeo.filletWire(shape,fp.FilletRadius)
w = DraftGeomUtils.filletWire(shape,fp.FilletRadius)
if w:
shape = w
fp.Shape = shape
@ -2510,8 +2499,7 @@ class _Polygon:
self.createGeometry(fp)
def createGeometry(self,fp):
import Part
from draftlibs import fcgeo
import Part, DraftGeomUtils
plm = fp.Placement
angle = (math.pi*2)/fp.FacesNumber
if fp.DrawMode == 'inscribed':
@ -2526,7 +2514,7 @@ class _Polygon:
shape = Part.makePolygon(pts)
if "FilletRadius" in fp.PropertiesList:
if fp.FilletRadius != 0:
w = fcgeo.filletWire(shape,fp.FilletRadius)
w = DraftGeomUtils.filletWire(shape,fp.FilletRadius)
if w:
shape = w
shape = Part.Face(shape)
@ -2690,16 +2678,15 @@ class _Shape2DView:
self.createGeometry(obj)
def createGeometry(self,obj):
import Drawing
from draftlibs import fcgeo
import Drawing, DraftGeomUtils
pl = obj.Placement
if obj.Base:
if obj.Base.isDerivedFrom("Part::Feature"):
if not fcvec.isNull(obj.Projection):
if not DraftVecUtils.isNull(obj.Projection):
[visibleG0,visibleG1,hiddenG0,hiddenG1] = Drawing.project(obj.Base.Shape,obj.Projection)
if visibleG0:
obj.Shape = visibleG0
if not fcgeo.isNull(pl):
if not DraftGeomUtils.isNull(pl):
obj.Placement = pl
class _Array:
@ -2745,7 +2732,7 @@ class _Array:
self.createGeometry(obj)
def createGeometry(self,obj):
from draftlibs import fcgeo
import DraftGeomUtils
if obj.Base:
pl = obj.Placement
if obj.ArrayType == "ortho":
@ -2753,21 +2740,21 @@ class _Array:
else:
sh = self.polarArray(obj.Base.Shape,obj.Center,obj.Angle,obj.NumberPolar,obj.Axis)
obj.Shape = sh
if not fcgeo.isNull(pl):
if not DraftGeomUtils.isNull(pl):
obj.Placement = pl
def rectArray(self,shape,xvector,yvector,xnum,ynum):
import Part
base = [shape.copy()]
for xcount in range(xnum):
currentxvector=fcvec.scale(xvector,xcount)
currentxvector=DraftVecUtils.scale(xvector,xcount)
if not xcount==0:
nshape = shape.copy()
nshape.translate(currentxvector)
base.append(nshape)
for ycount in range(ynum):
currentxvector=FreeCAD.Vector(currentxvector)
currentyvector=currentxvector.add(fcvec.scale(yvector,ycount))
currentyvector=currentxvector.add(DraftVecUtils.scale(yvector,ycount))
if not ycount==0:
nshape = shape.copy()
nshape.translate(currentyvector)
@ -2781,7 +2768,7 @@ class _Array:
for i in range(num):
currangle = fraction + (i*fraction)
nshape = shape.copy()
nshape.rotate(fcvec.tup(center), fcvec.tup(axis), currangle)
nshape.rotate(DraftVecUtils.tup(center), DraftVecUtils.tup(axis), currangle)
base.append(nshape)
return Part.makeCompound(base)
@ -2845,8 +2832,7 @@ class _Clone:
self.createGeometry(obj)
def createGeometry(self,obj):
import Part
from draftlibs import fcgeo
import Part, DraftGeomUtils
pl = obj.Placement
shapes = []
for o in obj.Objects:
@ -2859,7 +2845,7 @@ class _Clone:
shapes.append(sh)
if shapes:
obj.Shape = Part.makeCompound(shapes)
if not fcgeo.isNull(pl):
if not DraftGeomUtils.isNull(pl):
obj.Placement = pl
class _ViewProviderDraftPart(_ViewProviderDraft):

View File

@ -26,9 +26,8 @@ __author__ = "Yorik van Havre"
__url__ = "http://free-cad.sourceforge.net"
import FreeCAD, FreeCADGui, math, Draft, DraftGui, DraftTrackers
import FreeCAD, FreeCADGui, math, Draft, DraftGui, DraftTrackers, DraftVecUtils
from DraftGui import todo,getMainWindow
from draftlibs import fcvec
from FreeCAD import Vector
from pivy import coin
from PyQt4 import QtCore,QtGui
@ -110,9 +109,8 @@ class Snapper:
be True to constrain the point against the closest working plane axis.
Screenpos can be a list, a tuple or a coin.SbVec2s object."""
global Part,fcgeo
import Part
from draftlibs import fcgeo
global Part, DraftGeomUtils
import Part, DraftGeomUtils
if not hasattr(self,"toolbar"):
self.makeSnapToolBar()
@ -355,7 +353,7 @@ class Snapper:
for e in edges:
if isinstance(e.Curve,Part.Line):
np = self.getPerpendicular(e,point)
if not fcgeo.isPtOnEdge(np,e):
if not DraftGeomUtils.isPtOnEdge(np,e):
if (np.sub(point)).Length < self.radius:
if self.isEnabled('extension'):
if np != e.Vertexes[0].Point:
@ -372,7 +370,7 @@ class Snapper:
else:
if self.isEnabled('parallel'):
if last:
de = Part.Line(last,last.add(fcgeo.vec(e))).toShape()
de = Part.Line(last,last.add(DraftGeomUtils.vec(e))).toShape()
np = self.getPerpendicular(de,point)
if (np.sub(point)).Length < self.radius:
if self.tracker:
@ -398,13 +396,13 @@ class Snapper:
FreeCAD.Vector(0,0,1)]
for a in self.polarAngles:
if a == 90:
vecs.extend([ax[0],fcvec.neg(ax[0])])
vecs.extend([ax[1],fcvec.neg(ax[1])])
vecs.extend([ax[0],DraftVecUtils.neg(ax[0])])
vecs.extend([ax[1],DraftVecUtils.neg(ax[1])])
else:
v = fcvec.rotate(ax[0],math.radians(a),ax[2])
vecs.extend([v,fcvec.neg(v)])
v = fcvec.rotate(ax[1],math.radians(a),ax[2])
vecs.extend([v,fcvec.neg(v)])
v = DraftVecUtils.rotate(ax[0],math.radians(a),ax[2])
vecs.extend([v,DraftVecUtils.neg(v)])
v = DraftVecUtils.rotate(ax[1],math.radians(a),ax[2])
vecs.extend([v,DraftVecUtils.neg(v)])
for v in vecs:
de = Part.Line(last,last.add(v)).toShape()
np = self.getPerpendicular(de,point)
@ -457,7 +455,7 @@ class Snapper:
snaps = []
if self.isEnabled("midpoint"):
if isinstance(shape,Part.Edge):
mp = fcgeo.findMidpoint(shape)
mp = DraftGeomUtils.findMidpoint(shape)
if mp:
snaps.append([mp,'midpoint',mp])
return snaps
@ -472,7 +470,7 @@ class Snapper:
np = self.getPerpendicular(shape,last)
elif isinstance(shape.Curve,Part.Circle):
dv = last.sub(shape.Curve.Center)
dv = fcvec.scaleTo(dv,shape.Curve.Radius)
dv = DraftVecUtils.scaleTo(dv,shape.Curve.Radius)
np = (shape.Curve.Center).add(dv)
elif isinstance(shape.Curve,Part.BSplineCurve):
pr = shape.Curve.parameter(last)
@ -493,7 +491,7 @@ class Snapper:
if self.constraintAxis:
tmpEdge = Part.Line(last,last.add(self.constraintAxis)).toShape()
# get the intersection points
pt = fcgeo.findIntersection(tmpEdge,shape,True,True)
pt = DraftGeomUtils.findIntersection(tmpEdge,shape,True,True)
if pt:
for p in pt:
snaps.append([p,'ortho',p])
@ -506,14 +504,14 @@ class Snapper:
tmpEdge1 = Part.Line(last,last.add(self.constraintAxis)).toShape()
tmpEdge2 = Part.Line(self.extLine.p1(),self.extLine.p2()).toShape()
# get the intersection points
pt = fcgeo.findIntersection(tmpEdge1,tmpEdge2,True,True)
pt = DraftGeomUtils.findIntersection(tmpEdge1,tmpEdge2,True,True)
if pt:
return [pt[0],'ortho',pt[0]]
if eline:
try:
tmpEdge2 = Part.Line(self.extLine.p1(),self.extLine.p2()).toShape()
# get the intersection points
pt = fcgeo.findIntersection(eline,tmpEdge2,True,True)
pt = DraftGeomUtils.findIntersection(eline,tmpEdge2,True,True)
if pt:
return [pt[0],'ortho',pt[0]]
except:
@ -526,7 +524,7 @@ class Snapper:
if self.isEnabled("intersection") and self.isEnabled("extension"):
if e1 and e2:
# get the intersection points
pts = fcgeo.findIntersection(e1,e2,True,True)
pts = DraftGeomUtils.findIntersection(e1,e2,True,True)
if pts:
for p in pts:
snaps.append([p,'intersection',p])
@ -569,7 +567,7 @@ class Snapper:
if (not self.maxEdges) or (len(obj.Shape.Edges) <= self.maxEdges):
for e in obj.Shape.Edges:
# get the intersection points
pt = fcgeo.findIntersection(e,shape)
pt = DraftGeomUtils.findIntersection(e,shape)
if pt:
for p in pt:
snaps.append([p,'intersection',p])
@ -597,7 +595,7 @@ class Snapper:
def getPerpendicular(self,edge,pt):
"returns a point on an edge, perpendicular to the given point"
dv = pt.sub(edge.Vertexes[0].Point)
nv = fcvec.project(dv,fcgeo.vec(edge))
nv = DraftVecUtils.project(dv,DraftGeomUtils.vec(edge))
np = (edge.Vertexes[0].Point).add(nv)
return np
@ -690,7 +688,7 @@ class Snapper:
self.constraintAxis = FreeCAD.DraftWorkingPlane.axis
# calculating constrained point
cdelta = fcvec.project(delta,self.constraintAxis)
cdelta = DraftVecUtils.project(delta,self.constraintAxis)
npoint = self.basepoint.add(cdelta)
# setting constrain line

View File

@ -29,9 +29,8 @@ __url__ = "http://free-cad.sourceforge.net"
# Generic stuff
#---------------------------------------------------------------------------
import os, FreeCAD, FreeCADGui, WorkingPlane, math, re, importSVG, Draft, Draft_rc
import os, FreeCAD, FreeCADGui, WorkingPlane, math, re, importSVG, Draft, Draft_rc, DraftVecUtils
from functools import partial
from draftlibs import fcvec
from FreeCAD import Vector
from DraftGui import todo,QtCore,QtGui
from DraftSnap import *
@ -283,7 +282,7 @@ class SelectPlane:
self.display('side')
self.finish()
elif arg == "currentView":
viewDirection = fcvec.neg(self.view.getViewDirection())
viewDirection = DraftVecUtils.neg(self.view.getViewDirection())
plane.alignToPointAndAxis(Vector(0,0,0), viewDirection, self.offset)
self.display(viewDirection)
self.finish()
@ -327,9 +326,8 @@ class Creator:
def Activated(self,name="None"):
if FreeCAD.activeDraftCommand:
FreeCAD.activeDraftCommand.finish()
global Part, fcgeo
import Part
from draftlibs import fcgeo
global Part, DraftGeomUtils
import Part, DraftGeomUtils
self.ui = None
self.call = None
self.doc = None
@ -348,7 +346,7 @@ class Creator:
self.ui.show()
rot = self.view.getCameraNode().getField("orientation").getValue()
upv = Vector(rot.multVec(coin.SbVec3f(0,1,0)).getValue())
plane.setup(fcvec.neg(self.view.getViewDirection()), Vector(0,0,0), upv)
plane.setup(DraftVecUtils.neg(self.view.getViewDirection()), Vector(0,0,0), upv)
self.node = []
self.pos = []
self.constrain = None
@ -721,12 +719,12 @@ class Rectangle(Creator):
p1 = self.node[0]
p3 = self.node[-1]
diagonal = p3.sub(p1)
p2 = p1.add(fcvec.project(diagonal, plane.v))
p4 = p1.add(fcvec.project(diagonal, plane.u))
p2 = p1.add(DraftVecUtils.project(diagonal, plane.v))
p4 = p1.add(DraftVecUtils.project(diagonal, plane.u))
length = p4.sub(p1).Length
if abs(fcvec.angle(p4.sub(p1),plane.u,plane.axis)) > 1: length = -length
if abs(DraftVecUtils.angle(p4.sub(p1),plane.u,plane.axis)) > 1: length = -length
height = p2.sub(p1).Length
if abs(fcvec.angle(p2.sub(p1),plane.v,plane.axis)) > 1: height = -height
if abs(DraftVecUtils.angle(p2.sub(p1),plane.v,plane.axis)) > 1: height = -height
p = plane.getRotation()
p.move(p1)
try:
@ -847,10 +845,10 @@ class Arc(Creator):
point,ctrlPoint,info = getPoint(self,arg)
# this is to make sure radius is what you see on screen
self.ui.cross(True)
if self.center and fcvec.dist(point,self.center) > 0:
viewdelta = fcvec.project(point.sub(self.center), plane.axis)
if not fcvec.isNull(viewdelta):
point = point.add(fcvec.neg(viewdelta))
if self.center and DraftVecUtils.dist(point,self.center) > 0:
viewdelta = DraftVecUtils.project(point.sub(self.center), plane.axis)
if not DraftVecUtils.isNull(viewdelta):
point = point.add(DraftVecUtils.neg(viewdelta))
if (self.step == 0): # choose center
if hasMod(arg,MODALT):
if not self.altdown:
@ -864,12 +862,12 @@ class Arc(Creator):
self.ui.switchUi(False)
elif (self.step == 1): # choose radius
if len(self.tangents) == 2:
cir = fcgeo.circleFrom2tan1pt(self.tangents[0], self.tangents[1], point)
self.center = fcgeo.findClosestCircle(point,cir).Center
cir = DraftGeomUtils.circleFrom2tan1pt(self.tangents[0], self.tangents[1], point)
self.center = DraftGeomUtils.findClosestCircle(point,cir).Center
self.arctrack.setCenter(self.center)
elif self.tangents and self.tanpoints:
cir = fcgeo.circleFrom1tan2pt(self.tangents[0], self.tanpoints[0], point)
self.center = fcgeo.findClosestCircle(point,cir).Center
cir = DraftGeomUtils.circleFrom1tan2pt(self.tangents[0], self.tanpoints[0], point)
self.center = DraftGeomUtils.findClosestCircle(point,cir).Center
self.arctrack.setCenter(self.center)
if hasMod(arg,MODALT):
if not self.altdown:
@ -880,20 +878,20 @@ class Arc(Creator):
num = int(info['Component'].lstrip('Edge'))-1
ed = ob.Shape.Edges[num]
if len(self.tangents) == 2:
cir = fcgeo.circleFrom3tan(self.tangents[0], self.tangents[1], ed)
cl = fcgeo.findClosestCircle(point,cir)
cir = DraftGeomUtils.circleFrom3tan(self.tangents[0], self.tangents[1], ed)
cl = DraftGeomUtils.findClosestCircle(point,cir)
self.center = cl.Center
self.rad = cl.Radius
self.arctrack.setCenter(self.center)
else:
self.rad = self.center.add(fcgeo.findDistance(self.center,ed).sub(self.center)).Length
self.rad = self.center.add(DraftGeomUtils.findDistance(self.center,ed).sub(self.center)).Length
else:
self.rad = fcvec.dist(point,self.center)
self.rad = DraftVecUtils.dist(point,self.center)
else:
if self.altdown:
self.ui.cross(True)
self.altdown = False
self.rad = fcvec.dist(point,self.center)
self.rad = DraftVecUtils.dist(point,self.center)
self.ui.setRadiusValue(self.rad)
self.arctrack.setRadius(self.rad)
# Draw constraint tracker line.
@ -907,11 +905,11 @@ class Arc(Creator):
self.linetrack.p2(point)
self.linetrack.on()
elif (self.step == 2): # choose first angle
currentrad = fcvec.dist(point,self.center)
currentrad = DraftVecUtils.dist(point,self.center)
if currentrad != 0:
angle = fcvec.angle(plane.u, point.sub(self.center), plane.axis)
angle = DraftVecUtils.angle(plane.u, point.sub(self.center), plane.axis)
else: angle = 0
self.linetrack.p2(fcvec.scaleTo(point.sub(self.center),self.rad).add(self.center))
self.linetrack.p2(DraftVecUtils.scaleTo(point.sub(self.center),self.rad).add(self.center))
# Draw constraint tracker line.
if hasMod(arg,MODCONSTRAIN):
self.constraintrack.p1(point)
@ -922,11 +920,11 @@ class Arc(Creator):
self.ui.setRadiusValue(math.degrees(angle))
self.firstangle = angle
else: # choose second angle
currentrad = fcvec.dist(point,self.center)
currentrad = DraftVecUtils.dist(point,self.center)
if currentrad != 0:
angle = fcvec.angle(plane.u, point.sub(self.center), plane.axis)
angle = DraftVecUtils.angle(plane.u, point.sub(self.center), plane.axis)
else: angle = 0
self.linetrack.p2(fcvec.scaleTo(point.sub(self.center),self.rad).add(self.center))
self.linetrack.p2(DraftVecUtils.scaleTo(point.sub(self.center),self.rad).add(self.center))
# Draw constraint tracker line.
if hasMod(arg,MODCONSTRAIN):
self.constraintrack.p1(point)
@ -942,10 +940,10 @@ class Arc(Creator):
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
point,ctrlPoint,info = getPoint(self,arg)
# this is to make sure radius is what you see on screen
if self.center and fcvec.dist(point,self.center) > 0:
viewdelta = fcvec.project(point.sub(self.center), plane.axis)
if not fcvec.isNull(viewdelta):
point = point.add(fcvec.neg(viewdelta))
if self.center and DraftVecUtils.dist(point,self.center) > 0:
viewdelta = DraftVecUtils.project(point.sub(self.center), plane.axis)
if not DraftVecUtils.isNull(viewdelta):
point = point.add(DraftVecUtils.neg(viewdelta))
if (self.step == 0): # choose center
self.support = getSupport(arg)
if hasMod(arg,MODALT):
@ -990,7 +988,7 @@ class Arc(Creator):
self.ui.labelRadius.setText("Aperture")
self.step = 3
# scale center->point vector for proper display
u = fcvec.scaleTo(point.sub(self.center), self.rad)
u = DraftVecUtils.scaleTo(point.sub(self.center), self.rad)
self.arctrack.setStartAngle(self.firstangle)
msg(translate("draft", "Pick aperture:\n"))
else: # choose second angle
@ -1036,15 +1034,15 @@ class Arc(Creator):
if (self.step == 1):
self.rad = rad
if len(self.tangents) == 2:
cir = fcgeo.circleFrom2tan1rad(self.tangents[0], self.tangents[1], rad)
cir = DraftGeomUtils.circleFrom2tan1rad(self.tangents[0], self.tangents[1], rad)
if self.center:
self.center = fcgeo.findClosestCircle(self.center,cir).Center
self.center = DraftGeomUtils.findClosestCircle(self.center,cir).Center
else:
self.center = cir[-1].Center
elif self.tangents and self.tanpoints:
cir = fcgeo.circleFrom1tan1pt1rad(self.tangents[0],self.tanpoints[0],rad)
cir = DraftGeomUtils.circleFrom1tan1pt1rad(self.tangents[0],self.tanpoints[0],rad)
if self.center:
self.center = fcgeo.findClosestCircle(self.center,cir).Center
self.center = DraftGeomUtils.findClosestCircle(self.center,cir).Center
else:
self.center = cir[-1].Center
if self.closedCircle:
@ -1061,9 +1059,9 @@ class Arc(Creator):
elif (self.step == 2):
self.ui.labelRadius.setText(str(translate("draft", "Aperture")))
self.firstangle = math.radians(rad)
if fcvec.equals(plane.axis, Vector(1,0,0)): u = Vector(0,self.rad,0)
else: u = fcvec.scaleTo(Vector(1,0,0).cross(plane.axis), self.rad)
urotated = fcvec.rotate(u, math.radians(rad), plane.axis)
if DraftVecUtils.equals(plane.axis, Vector(1,0,0)): u = Vector(0,self.rad,0)
else: u = DraftVecUtils.scaleTo(Vector(1,0,0).cross(plane.axis), self.rad)
urotated = DraftVecUtils.rotate(u, math.radians(rad), plane.axis)
self.arctrack.setStartAngle(self.firstangle)
self.step = 3
self.ui.radiusValue.setText("")
@ -1139,10 +1137,10 @@ class Polygon(Creator):
point,ctrlPoint,info = getPoint(self,arg)
# this is to make sure radius is what you see on screen
self.ui.cross(True)
if self.center and fcvec.dist(point,self.center) > 0:
viewdelta = fcvec.project(point.sub(self.center), plane.axis)
if not fcvec.isNull(viewdelta):
point = point.add(fcvec.neg(viewdelta))
if self.center and DraftVecUtils.dist(point,self.center) > 0:
viewdelta = DraftVecUtils.project(point.sub(self.center), plane.axis)
if not DraftVecUtils.isNull(viewdelta):
point = point.add(DraftVecUtils.neg(viewdelta))
if (self.step == 0): # choose center
if hasMod(arg,MODALT):
if not self.altdown:
@ -1156,12 +1154,12 @@ class Polygon(Creator):
self.ui.switchUi(False)
else: # choose radius
if len(self.tangents) == 2:
cir = fcgeo.circleFrom2tan1pt(self.tangents[0], self.tangents[1], point)
self.center = fcgeo.findClosestCircle(point,cir).Center
cir = DraftGeomUtils.circleFrom2tan1pt(self.tangents[0], self.tangents[1], point)
self.center = DraftGeomUtils.findClosestCircle(point,cir).Center
self.arctrack.setCenter(self.center)
elif self.tangents and self.tanpoints:
cir = fcgeo.circleFrom1tan2pt(self.tangents[0], self.tanpoints[0], point)
self.center = fcgeo.findClosestCircle(point,cir).Center
cir = DraftGeomUtils.circleFrom1tan2pt(self.tangents[0], self.tanpoints[0], point)
self.center = DraftGeomUtils.findClosestCircle(point,cir).Center
self.arctrack.setCenter(self.center)
if hasMod(arg,MODALT):
if not self.altdown:
@ -1173,20 +1171,20 @@ class Polygon(Creator):
num = int(snapped['Component'].lstrip('Edge'))-1
ed = ob.Shape.Edges[num]
if len(self.tangents) == 2:
cir = fcgeo.circleFrom3tan(self.tangents[0], self.tangents[1], ed)
cl = fcgeo.findClosestCircle(point,cir)
cir = DraftGeomUtils.circleFrom3tan(self.tangents[0], self.tangents[1], ed)
cl = DraftGeomUtils.findClosestCircle(point,cir)
self.center = cl.Center
self.rad = cl.Radius
self.arctrack.setCenter(self.center)
else:
self.rad = self.center.add(fcgeo.findDistance(self.center,ed).sub(self.center)).Length
self.rad = self.center.add(DraftGeomUtils.findDistance(self.center,ed).sub(self.center)).Length
else:
self.rad = fcvec.dist(point,self.center)
self.rad = DraftVecUtils.dist(point,self.center)
else:
if self.altdown:
self.ui.cross(True)
self.altdown = False
self.rad = fcvec.dist(point,self.center)
self.rad = DraftVecUtils.dist(point,self.center)
self.ui.setRadiusValue(self.rad)
self.arctrack.setRadius(self.rad)
# Draw constraint tracker line.
@ -1203,10 +1201,10 @@ class Polygon(Creator):
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
point,ctrlPoint,info = getPoint(self,arg)
# this is to make sure radius is what you see on screen
if self.center and fcvec.dist(point,self.center) > 0:
viewdelta = fcvec.project(point.sub(self.center), plane.axis)
if not fcvec.isNull(viewdelta):
point = point.add(fcvec.neg(viewdelta))
if self.center and DraftVecUtils.dist(point,self.center) > 0:
viewdelta = DraftVecUtils.project(point.sub(self.center), plane.axis)
if not DraftVecUtils.isNull(viewdelta):
point = point.add(DraftVecUtils.neg(viewdelta))
if (self.step == 0): # choose center
if not self.node: self.support = getSupport(arg)
if hasMod(arg,MODALT):
@ -1265,15 +1263,15 @@ class Polygon(Creator):
"this function gets called by the toolbar when valid radius have been entered there"
self.rad = rad
if len(self.tangents) == 2:
cir = fcgeo.circleFrom2tan1rad(self.tangents[0], self.tangents[1], rad)
cir = DraftGeomUtils.circleFrom2tan1rad(self.tangents[0], self.tangents[1], rad)
if self.center:
self.center = fcgeo.findClosestCircle(self.center,cir).Center
self.center = DraftGeomUtils.findClosestCircle(self.center,cir).Center
else:
self.center = cir[-1].Center
elif self.tangents and self.tanpoints:
cir = fcgeo.circleFrom1tan1pt1rad(self.tangents[0],self.tanpoints[0],rad)
cir = DraftGeomUtils.circleFrom1tan1pt1rad(self.tangents[0],self.tanpoints[0],rad)
if self.center:
self.center = fcgeo.findClosestCircle(self.center,cir).Center
self.center = DraftGeomUtils.findClosestCircle(self.center,cir).Center
else:
self.center = cir[-1].Center
self.drawPolygon()
@ -1485,7 +1483,7 @@ class Dimension(Creator):
r = point.sub(self.center)
self.arctrack.setRadius(r.Length)
a = self.arctrack.getAngle(point)
pair = fcgeo.getBoundaryAngles(a,self.pts)
pair = DraftGeomUtils.getBoundaryAngles(a,self.pts)
if not (pair[0] < a < pair[1]):
self.angledata = [4*math.pi-pair[0],2*math.pi-pair[1]]
else:
@ -1496,14 +1494,14 @@ class Dimension(Creator):
self.altdown = False
self.ui.switchUi(False)
if self.dir:
point = self.node[0].add(fcvec.project(point.sub(self.node[0]),self.dir))
point = self.node[0].add(DraftVecUtils.project(point.sub(self.node[0]),self.dir))
if len(self.node) == 2:
if self.arcmode and self.edges:
cen = self.edges[0].Curve.Center
rad = self.edges[0].Curve.Radius
baseray = point.sub(cen)
v2 = fcvec.scaleTo(baseray,rad)
v1 = fcvec.neg(v2)
v2 = DraftVecUtils.scaleTo(baseray,rad)
v1 = DraftVecUtils.neg(v2)
if shift:
self.node = [cen,cen.add(v2)]
self.arcmode = "radius"
@ -1574,7 +1572,7 @@ class Dimension(Creator):
# there is already a snapped edge, so we start angular dimension
self.edges.append(ed)
self.node.extend([v1,v2]) # self.node now has the 4 endpoints
c = fcgeo.findIntersection(self.node[0],
c = DraftGeomUtils.findIntersection(self.node[0],
self.node[1],
self.node[2],
self.node[3],
@ -1593,7 +1591,7 @@ class Dimension(Creator):
self.dimtrack.on()
else:
if self.dir:
point = self.node[0].add(fcvec.project(point.sub(self.node[0]),self.dir))
point = self.node[0].add(DraftVecUtils.project(point.sub(self.node[0]),self.dir))
self.node.append(point)
print "node",self.node
self.dimtrack.update(self.node)
@ -1610,7 +1608,7 @@ class Dimension(Creator):
# for unlinked arc mode:
# if self.arcmode:
# v = self.node[1].sub(self.node[0])
# v = fcvec.scale(v,0.5)
# v = DraftVecUtils.scale(v,0.5)
# cen = self.node[0].add(v)
# self.node = [self.node[0],self.node[1],cen]
self.createObject()
@ -1651,9 +1649,8 @@ class Modifier:
def Activated(self,name="None"):
if FreeCAD.activeDraftCommand:
FreeCAD.activeDraftCommand.finish()
global Part, fcgeo
import Part
from draftlibs import fcgeo
global Part, DraftGeomUtils
import Part, DraftGeomUtils
self.ui = None
self.call = None
self.commitList = []
@ -1667,7 +1664,7 @@ class Modifier:
FreeCADGui.draftToolBar.show()
rot = self.view.getCameraNode().getField("orientation").getValue()
upv = Vector(rot.multVec(coin.SbVec3f(0,1,0)).getValue())
plane.setup(fcvec.neg(self.view.getViewDirection()), Vector(0,0,0), upv)
plane.setup(DraftVecUtils.neg(self.view.getViewDirection()), Vector(0,0,0), upv)
self.node = []
self.ui.sourceCmd = self
self.constrain = None
@ -1931,10 +1928,10 @@ class Rotate(Modifier):
point,ctrlPoint,info = getPoint(self,arg)
self.ui.cross(True)
# this is to make sure radius is what you see on screen
if self.center and fcvec.dist(point,self.center):
viewdelta = fcvec.project(point.sub(self.center), plane.axis)
if not fcvec.isNull(viewdelta):
point = point.add(fcvec.neg(viewdelta))
if self.center and DraftVecUtils.dist(point,self.center):
viewdelta = DraftVecUtils.project(point.sub(self.center), plane.axis)
if not DraftVecUtils.isNull(viewdelta):
point = point.add(DraftVecUtils.neg(viewdelta))
if self.extendedCopy:
if not hasMod(arg,MODALT):
self.step = 3
@ -1942,9 +1939,9 @@ class Rotate(Modifier):
if (self.step == 0):
pass
elif (self.step == 1):
currentrad = fcvec.dist(point,self.center)
currentrad = DraftVecUtils.dist(point,self.center)
if (currentrad != 0):
angle = fcvec.angle(plane.u, point.sub(self.center), plane.axis)
angle = DraftVecUtils.angle(plane.u, point.sub(self.center), plane.axis)
else: angle = 0
self.linetrack.p2(point)
# Draw constraint tracker line.
@ -1959,16 +1956,16 @@ class Rotate(Modifier):
self.ui.radiusValue.setFocus()
self.ui.radiusValue.selectAll()
elif (self.step == 2):
currentrad = fcvec.dist(point,self.center)
currentrad = DraftVecUtils.dist(point,self.center)
if (currentrad != 0):
angle = fcvec.angle(plane.u, point.sub(self.center), plane.axis)
angle = DraftVecUtils.angle(plane.u, point.sub(self.center), plane.axis)
else: angle = 0
if (angle < self.firstangle):
sweep = (2*math.pi-self.firstangle)+angle
else:
sweep = angle - self.firstangle
self.arctrack.setApertureAngle(sweep)
self.ghost.trans.rotation.setValue(coin.SbVec3f(fcvec.tup(plane.axis)),sweep)
self.ghost.trans.rotation.setValue(coin.SbVec3f(DraftVecUtils.tup(plane.axis)),sweep)
self.linetrack.p2(point)
# Draw constraint tracker line.
if hasMod(arg,MODCONSTRAIN):
@ -1984,9 +1981,9 @@ class Rotate(Modifier):
elif arg["Type"] == "SoMouseButtonEvent":
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
point,ctrlPoint,info = getPoint(self,arg)
if self.center and fcvec.dist(point,self.center):
viewdelta = fcvec.project(point.sub(self.center), plane.axis)
if not fcvec.isNull(viewdelta): point = point.add(fcvec.neg(viewdelta))
if self.center and DraftVecUtils.dist(point,self.center):
viewdelta = DraftVecUtils.project(point.sub(self.center), plane.axis)
if not DraftVecUtils.isNull(viewdelta): point = point.add(DraftVecUtils.neg(viewdelta))
if (self.step == 0):
self.center = point
self.node = [point]
@ -2002,16 +1999,16 @@ class Rotate(Modifier):
self.planetrack.set(point)
elif (self.step == 1):
self.ui.labelRadius.setText("Rotation")
self.rad = fcvec.dist(point,self.center)
self.rad = DraftVecUtils.dist(point,self.center)
self.arctrack.on()
self.arctrack.setStartPoint(point)
self.ghost.on()
self.step = 2
msg(translate("draft", "Pick rotation angle:\n"))
else:
currentrad = fcvec.dist(point,self.center)
currentrad = DraftVecUtils.dist(point,self.center)
angle = point.sub(self.center).getAngle(plane.u)
if fcvec.project(point.sub(self.center), plane.v).getAngle(plane.v) > 1:
if DraftVecUtils.project(point.sub(self.center), plane.v).getAngle(plane.v) > 1:
angle = -angle
if (angle < self.firstangle):
sweep = (2*math.pi-self.firstangle)+angle
@ -2127,33 +2124,33 @@ class Offset(Modifier):
self.ui.cross(True)
point,ctrlPoint,info = getPoint(self,arg)
if hasMod(arg,MODCONSTRAIN) and self.constrainSeg:
dist = fcgeo.findPerpendicular(point,self.shape,self.constrainSeg[1])
dist = DraftGeomUtils.findPerpendicular(point,self.shape,self.constrainSeg[1])
e = self.shape.Edges[self.constrainSeg[1]]
self.constraintrack.p1(e.Vertexes[0].Point)
self.constraintrack.p2(point.add(dist[0]))
self.constraintrack.on()
else:
dist = fcgeo.findPerpendicular(point,self.shape.Edges)
dist = DraftGeomUtils.findPerpendicular(point,self.shape.Edges)
self.constraintrack.off()
if dist:
self.ghost.on()
if self.mode == "Wire":
d = fcvec.neg(dist[0])
v1 = fcgeo.getTangent(self.shape.Edges[0],point)
v2 = fcgeo.getTangent(self.shape.Edges[dist[1]],point)
a = -fcvec.angle(v1,v2)
self.dvec = fcvec.rotate(d,a,plane.axis)
d = DraftVecUtils.neg(dist[0])
v1 = DraftGeomUtils.getTangent(self.shape.Edges[0],point)
v2 = DraftGeomUtils.getTangent(self.shape.Edges[dist[1]],point)
a = -DraftVecUtils.angle(v1,v2)
self.dvec = DraftVecUtils.rotate(d,a,plane.axis)
occmode = self.ui.occOffset.isChecked()
self.ghost.update(fcgeo.offsetWire(self.shape,self.dvec,occ=occmode),forceclosed=occmode)
self.ghost.update(DraftGeomUtils.offsetWire(self.shape,self.dvec,occ=occmode),forceclosed=occmode)
elif self.mode == "BSpline":
d = fcvec.neg(dist[0])
d = DraftVecUtils.neg(dist[0])
e = self.shape.Edges[0]
basetan = fcgeo.getTangent(e,point)
basetan = DraftGeomUtils.getTangent(e,point)
self.npts = []
for p in self.sel.Points:
currtan = fcgeo.getTangent(e,p)
a = -fcvec.angle(currtan,basetan)
self.dvec = fcvec.rotate(d,a,plane.axis)
currtan = DraftGeomUtils.getTangent(e,p)
a = -DraftVecUtils.angle(currtan,basetan)
self.dvec = DraftVecUtils.rotate(d,a,plane.axis)
self.npts.append(p.add(self.dvec))
self.ghost.update(self.npts)
elif self.mode == "Circle":
@ -2329,12 +2326,12 @@ class Upgrade(Modifier):
u = faces.pop(0)
for f in faces:
u = u.fuse(f)
if fcgeo.isCoplanar(faces):
if DraftGeomUtils.isCoplanar(faces):
if self.sel[0].ViewObject.DisplayMode == "Wireframe":
f = False
else:
f = True
u = fcgeo.concatenate(u)
u = DraftGeomUtils.concatenate(u)
if not curves:
# several coplanar and non-curved faces: they can becoem a Draft wire
msg(translate("draft", "Found several objects or faces: making a parametric face\n"))
@ -2384,7 +2381,7 @@ class Upgrade(Modifier):
else:
# only closed wires
for w in wires:
if fcgeo.isPlanar(w):
if DraftGeomUtils.isPlanar(w):
f = Part.Face(w)
faces.append(f)
else:
@ -2405,7 +2402,7 @@ class Upgrade(Modifier):
edges = openwires[0].Edges
if len(edges) > 1:
edges.append(Part.Line(p1,p0).toShape())
w = Part.Wire(fcgeo.sortEdges(edges))
w = Part.Wire(DraftGeomUtils.sortEdges(edges))
if len(edges) == 1:
if len(w.Vertexes) == 2:
msg(translate("draft", "Found 1 open edge: making a line\n"))
@ -2433,7 +2430,7 @@ class Upgrade(Modifier):
for e in ob.Shape.Edges:
edges.append(e)
newob = None
nedges = fcgeo.sortEdges(edges[:])
nedges = DraftGeomUtils.sortEdges(edges[:])
# for e in nedges: print "debug: ",e.Curve,e.Vertexes[0].Point,e.Vertexes[-1].Point
w = Part.Wire(nedges)
if len(w.Edges) == len(edges):
@ -2643,7 +2640,7 @@ class Trimex(Modifier):
self.extrudeMode = False
if self.obj.Shape.Wires:
self.edges = self.obj.Shape.Wires[0].Edges
self.edges = fcgeo.sortEdges(self.edges)
self.edges = DraftGeomUtils.sortEdges(self.edges)
else:
self.edges = self.obj.Shape.Edges
self.ghost = []
@ -2707,7 +2704,7 @@ class Trimex(Modifier):
"redraws the ghost in extrude mode"
self.newpoint = self.obj.Shape.Faces[0].CenterOfMass
dvec = self.point.sub(self.newpoint)
if not shift: delta = fcvec.project(dvec,self.normal)
if not shift: delta = DraftVecUtils.project(dvec,self.normal)
else: delta = dvec
if self.force:
ratio = self.force/delta.Length
@ -2733,7 +2730,7 @@ class Trimex(Modifier):
for e in self.edges: vlist.append(e.Vertexes[0].Point)
vlist.append(self.edges[-1].Vertexes[-1].Point)
if shift: npoint = self.activePoint
else: npoint = fcgeo.findClosest(point,vlist)
else: npoint = DraftGeomUtils.findClosest(point,vlist)
if npoint > len(self.edges)/2: reverse = True
if alt: reverse = not reverse
self.activePoint = npoint
@ -2758,16 +2755,16 @@ class Trimex(Modifier):
snapped = self.doc.getObject(snapped['Object'])
pts = []
for e in snapped.Shape.Edges:
int = fcgeo.findIntersection(edge,e,True,True)
int = DraftGeomUtils.findIntersection(edge,e,True,True)
if int: pts.extend(int)
if pts:
point = pts[fcgeo.findClosest(point,pts)]
point = pts[DraftGeomUtils.findClosest(point,pts)]
# modifying active edge
if isinstance(edge.Curve,Part.Line):
perp = fcgeo.vec(edge).cross(Vector(0,0,1))
perp = DraftGeomUtils.vec(edge).cross(Vector(0,0,1))
chord = v1.sub(point)
proj = fcvec.project(chord,perp)
proj = DraftVecUtils.project(chord,perp)
self.newpoint = Vector.add(point,proj)
dist = v1.sub(self.newpoint).Length
ghost.p1(self.newpoint)
@ -2776,15 +2773,15 @@ class Trimex(Modifier):
if real:
if self.force:
ray = self.newpoint.sub(v1)
ray = fcvec.scale(ray,self.force/ray.Length)
ray = DraftVecUtils.scale(ray,self.force/ray.Length)
self.newpoint = Vector.add(v1,ray)
newedges.append(Part.Line(self.newpoint,v2).toShape())
else:
center = edge.Curve.Center
rad = edge.Curve.Radius
ang1 = fcvec.angle(v2.sub(center))
ang2 = fcvec.angle(point.sub(center))
self.newpoint=Vector.add(center,fcvec.rotate(Vector(rad,0,0),-ang2))
ang1 = DraftVecUtils.angle(v2.sub(center))
ang2 = DraftVecUtils.angle(point.sub(center))
self.newpoint=Vector.add(center,DraftVecUtils.rotate(Vector(rad,0,0),-ang2))
self.ui.labelRadius.setText("Angle")
dist = math.degrees(-ang2)
# if ang1 > ang2: ang1,ang2 = ang2,ang1
@ -2796,11 +2793,11 @@ class Trimex(Modifier):
if real:
if self.force:
angle = math.radians(self.force)
newray = fcvec.rotate(Vector(rad,0,0),-angle)
newray = DraftVecUtils.rotate(Vector(rad,0,0),-angle)
self.newpoint = Vector.add(center,newray)
chord = self.newpoint.sub(v2)
perp = chord.cross(Vector(0,0,1))
scaledperp = fcvec.scaleTo(perp,rad)
scaledperp = DraftVecUtils.scaleTo(perp,rad)
midpoint = Vector.add(center,scaledperp)
newedges.append(Part.Arc(self.newpoint,midpoint,v2).toShape())
ghost.on()
@ -2815,8 +2812,8 @@ class Trimex(Modifier):
ghost.p1(edge.Vertexes[0].Point)
ghost.p2(edge.Vertexes[-1].Point)
else:
ang1 = fcvec.angle(edge.Vertexes[0].Point.sub(center))
ang2 = fcvec.angle(edge.Vertexes[-1].Point.sub(center))
ang1 = DraftVecUtils.angle(edge.Vertexes[0].Point.sub(center))
ang2 = DraftVecUtils.angle(edge.Vertexes[-1].Point.sub(center))
# if ang1 > ang2: ang1,ang2 = ang2,ang1
ghost.setEndAngle(-ang2)
ghost.setStartAngle(-ang1)
@ -2961,7 +2958,7 @@ class Scale(Modifier):
self.ghost.trans.scaleFactor.setValue([delta.x,delta.y,delta.z])
corr = Vector(self.node[0].x,self.node[0].y,self.node[0].z)
corr.scale(delta.x,delta.y,delta.z)
corr = fcvec.neg(corr.sub(self.node[0]))
corr = DraftVecUtils.neg(corr.sub(self.node[0]))
self.ghost.trans.translation.setValue([corr.x,corr.y,corr.z])
if self.extendedCopy:
if not hasMod(arg,MODALT): self.finish()
@ -3166,9 +3163,9 @@ class Edit(Modifier):
self.editpoints.append(self.obj.Shape.Vertexes[2].Point)
v = self.obj.Shape.Vertexes
self.bx = v[1].Point.sub(v[0].Point)
if self.obj.Length < 0: self.bx = fcvec.neg(self.bx)
if self.obj.Length < 0: self.bx = DraftVecUtils.neg(self.bx)
self.by = v[2].Point.sub(v[1].Point)
if self.obj.Height < 0: self.by = fcvec.neg(self.by)
if self.obj.Height < 0: self.by = DraftVecUtils.neg(self.by)
elif Draft.getType(self.obj) == "Polygon":
self.editpoints.append(self.obj.Placement.Base)
self.editpoints.append(self.obj.Shape.Vertexes[0].Point)
@ -3292,8 +3289,8 @@ class Edit(Modifier):
self.obj.Placement = p
elif self.editing == 1:
diag = v.sub(self.obj.Placement.Base)
nx = fcvec.project(diag,self.bx)
ny = fcvec.project(diag,self.by)
nx = DraftVecUtils.project(diag,self.bx)
ny = DraftVecUtils.project(diag,self.by)
ax = nx.Length
ay = ny.Length
if ax and ay:

View File

@ -25,18 +25,16 @@ __title__="FreeCAD Draft Trackers"
__author__ = "Yorik van Havre"
__url__ = "http://free-cad.sourceforge.net"
import FreeCAD,FreeCADGui,math,Draft
import FreeCAD,FreeCADGui,math,Draft, DraftVecUtils
from FreeCAD import Vector
from draftlibs import fcvec
from pivy import coin
from DraftGui import todo
class Tracker:
"A generic Draft Tracker, to be used by other specific trackers"
def __init__(self,dotted=False,scolor=None,swidth=None,children=[],ontop=False):
global Part, fcgeo
import Part
from draftlibs import fcgeo
global Part, DraftGeomUtils
import Part, DraftGeomUtils
self.ontop = ontop
color = coin.SoBaseColor()
color.rgb = scolor or FreeCADGui.draftToolBar.getDefaultColor("ui")
@ -161,8 +159,8 @@ class rectangleTracker(Tracker):
def update(self,point):
"sets the opposite (diagonal) point of the rectangle"
diagonal = point.sub(self.origin)
inpoint1 = self.origin.add(fcvec.project(diagonal,self.v))
inpoint2 = self.origin.add(fcvec.project(diagonal,self.u))
inpoint1 = self.origin.add(DraftVecUtils.project(diagonal,self.v))
inpoint2 = self.origin.add(DraftVecUtils.project(diagonal,self.u))
self.coords.point.set1Value(1,inpoint1.x,inpoint1.y,inpoint1.z)
self.coords.point.set1Value(2,point.x,point.y,point.z)
self.coords.point.set1Value(3,inpoint2.x,inpoint2.y,inpoint2.z)
@ -204,7 +202,7 @@ class rectangleTracker(Tracker):
p1 = Vector(self.coords.point.getValues()[0].getValue())
p2 = Vector(self.coords.point.getValues()[2].getValue())
diag = p2.sub(p1)
return ((fcvec.project(diag,self.u)).Length,(fcvec.project(diag,self.v)).Length)
return ((DraftVecUtils.project(diag,self.u)).Length,(DraftVecUtils.project(diag,self.v)).Length)
def getNormal(self):
"returns the normal of the rectangle"
@ -233,23 +231,23 @@ class dimTracker(Tracker):
def calc(self):
import Part
if (self.p1 != None) and (self.p2 != None):
points = [fcvec.tup(self.p1,True),fcvec.tup(self.p2,True),\
fcvec.tup(self.p1,True),fcvec.tup(self.p2,True)]
points = [DraftVecUtils.tup(self.p1,True),DraftVecUtils.tup(self.p2,True),\
DraftVecUtils.tup(self.p1,True),DraftVecUtils.tup(self.p2,True)]
if self.p3 != None:
p1 = self.p1
p4 = self.p2
if fcvec.equals(p1,p4):
if DraftVecUtils.equals(p1,p4):
proj = None
else:
base = Part.Line(p1,p4).toShape()
proj = fcgeo.findDistance(self.p3,base)
proj = DraftGeomUtils.findDistance(self.p3,base)
if not proj:
p2 = p1
p3 = p4
else:
p2 = p1.add(fcvec.neg(proj))
p3 = p4.add(fcvec.neg(proj))
points = [fcvec.tup(p1),fcvec.tup(p2),fcvec.tup(p3),fcvec.tup(p4)]
p2 = p1.add(DraftVecUtils.neg(proj))
p3 = p4.add(DraftVecUtils.neg(proj))
points = [DraftVecUtils.tup(p1),DraftVecUtils.tup(p2),DraftVecUtils.tup(p3),DraftVecUtils.tup(p4)]
self.coords.point.setValues(0,4,points)
class bsplineTracker(Tracker):
@ -340,7 +338,7 @@ class arcTracker(Tracker):
center = Vector(c[0],c[1],c[2])
base = FreeCAD.DraftWorkingPlane.u
rad = pt.sub(center)
return(fcvec.angle(rad,base,FreeCAD.DraftWorkingPlane.axis))
return(DraftVecUtils.angle(rad,base,FreeCAD.DraftWorkingPlane.axis))
def getAngles(self):
"returns the start and end angles"
@ -496,7 +494,7 @@ class wireTracker(Tracker):
"A wire tracker"
def __init__(self,wire):
self.line = coin.SoLineSet()
self.closed = fcgeo.isReallyClosed(wire)
self.closed = DraftGeomUtils.isReallyClosed(wire)
if self.closed:
self.line.numVertices.setValue(len(wire.Vertexes)+1)
else:
@ -626,11 +624,11 @@ class gridTracker(Tracker):
"returns the closest node from the given point"
# get the 2D coords.
point = FreeCAD.DraftWorkingPlane.projectPoint(point)
u = fcvec.project(point,FreeCAD.DraftWorkingPlane.u)
u = DraftVecUtils.project(point,FreeCAD.DraftWorkingPlane.u)
lu = u.Length
if u.getAngle(FreeCAD.DraftWorkingPlane.u) > 1.5:
lu = -lu
v = fcvec.project(point,FreeCAD.DraftWorkingPlane.v)
v = DraftVecUtils.project(point,FreeCAD.DraftWorkingPlane.v)
lv = v.Length
if v.getAngle(FreeCAD.DraftWorkingPlane.v) > 1.5:
lv = -lv
@ -659,8 +657,7 @@ class boxTracker(Tracker):
Tracker.__init__(self,children=[self.trans,m,self.cube])
def update(self,line=None,normal=None):
import WorkingPlane
from draftlibs import fcgeo
import WorkingPlane, DraftGeomUtils
if not normal:
normal = FreeCAD.DraftWorkingPlane.axis
if line:
@ -668,10 +665,10 @@ class boxTracker(Tracker):
bp = line[0]
lvec = line[1].sub(line[0])
else:
lvec = fcgeo.vec(line.Shape.Edges[0])
lvec = DraftGeomUtils.vec(line.Shape.Edges[0])
bp = line.Shape.Edges[0].Vertexes[0].Point
elif self.baseline:
lvec = fcgeo.vec(self.baseline.Shape.Edges[0])
lvec = DraftGeomUtils.vec(self.baseline.Shape.Edges[0])
bp = self.baseline.Shape.Edges[0].Vertexes[0].Point
else:
return
@ -679,12 +676,12 @@ class boxTracker(Tracker):
self.cube.width.setValue(lvec.Length)
p = WorkingPlane.getPlacementFromPoints([bp,bp.add(lvec),bp.add(right)])
self.trans.rotation.setValue(p.Rotation.Q)
bp = bp.add(fcvec.scale(lvec,0.5))
bp = bp.add(fcvec.scaleTo(normal,self.cube.depth.getValue()/2))
bp = bp.add(DraftVecUtils.scale(lvec,0.5))
bp = bp.add(DraftVecUtils.scaleTo(normal,self.cube.depth.getValue()/2))
self.pos(bp)
def pos(self,p):
self.trans.translation.setValue(fcvec.tup(p))
self.trans.translation.setValue(DraftVecUtils.tup(p))
def width(self,w=None):
if w:

View File

@ -13,6 +13,8 @@ data_DATA = \
DraftGui.py \
DraftSnap.py \
DraftTrackers.py \
DraftVecUtils.py \
DraftGeomUtils.py \
WorkingPlane.py \
importOCA.py \
importDXF.py \
@ -28,8 +30,6 @@ nobase_data_DATA = \
draftlibs/dxfImportObjects.py \
draftlibs/dxfLibrary.py \
draftlibs/dxfReader.py \
draftlibs/fcvec.py \
draftlibs/fcgeo.py \
draftlibs/__init__.py
CLEANFILES = $(BUILT_SOURCES)

View File

@ -22,9 +22,8 @@
#***************************************************************************
import FreeCAD, FreeCADGui, math
import FreeCAD, FreeCADGui, math, DraftVecUtils
from FreeCAD import Vector
from draftlibs import fcvec
__title__="FreeCAD Working Plane utility"
__author__ = "Ken Cline"
@ -51,7 +50,7 @@ class plane:
self.stored = None
def __repr__(self):
return "Workplane x="+str(fcvec.rounded(self.u))+" y="+str(fcvec.rounded(self.v))+" z="+str(fcvec.rounded(self.axis))
return "Workplane x="+str(DraftVecUtils.rounded(self.u))+" y="+str(DraftVecUtils.rounded(self.v))+" z="+str(DraftVecUtils.rounded(self.axis))
def offsetToPoint(self, p, direction=None):
'''
@ -96,10 +95,10 @@ class plane:
self.doc = FreeCAD.ActiveDocument
self.axis = axis;
self.axis.normalize()
if (fcvec.equals(axis, Vector(1,0,0))):
if (DraftVecUtils.equals(axis, Vector(1,0,0))):
self.u = Vector(0,1,0)
self.v = Vector(0,0,1)
elif (fcvec.equals(axis, Vector(-1,0,0))):
elif (DraftVecUtils.equals(axis, Vector(-1,0,0))):
self.u = Vector(0,-1,0)
self.v = Vector(0,0,1)
elif upvec:
@ -109,12 +108,12 @@ class plane:
else:
self.v = axis.cross(Vector(1,0,0))
self.v.normalize()
self.u = fcvec.rotate(self.v, -math.pi/2, self.axis)
self.u = DraftVecUtils.rotate(self.v, -math.pi/2, self.axis)
offsetVector = Vector(axis); offsetVector.multiply(offset)
self.position = point.add(offsetVector)
self.weak = False
# FreeCAD.Console.PrintMessage("(position = " + str(self.position) + ")\n")
# FreeCAD.Console.PrintMessage("Current workplane: x="+str(fcvec.rounded(self.u))+" y="+str(fcvec.rounded(self.v))+" z="+str(fcvec.rounded(self.axis))+"\n")
# FreeCAD.Console.PrintMessage("Current workplane: x="+str(DraftVecUtils.rounded(self.u))+" y="+str(DraftVecUtils.rounded(self.v))+" z="+str(DraftVecUtils.rounded(self.axis))+"\n")
def alignToCurve(self, shape, offset):
if shape.ShapeType == 'Edge':
@ -162,7 +161,7 @@ class plane:
def getRotation(self):
"returns a placement describing the working plane orientation ONLY"
m = fcvec.getPlaneRotation(self.u,self.v,self.axis)
m = DraftVecUtils.getPlaneRotation(self.u,self.v,self.axis)
return FreeCAD.Placement(m)
def getPlacement(self):
@ -197,15 +196,15 @@ class plane:
def getLocalCoords(self,point):
"returns the coordinates of a given point on the working plane"
xv = fcvec.project(point,self.u)
xv = DraftVecUtils.project(point,self.u)
x = xv.Length
if xv.getAngle(self.u) > 1:
x = -x
yv = fcvec.project(point,self.v)
yv = DraftVecUtils.project(point,self.v)
y = yv.Length
if yv.getAngle(self.v) > 1:
y = -y
zv = fcvec.project(point,self.axis)
zv = DraftVecUtils.project(point,self.axis)
z = zv.Length
if zv.getAngle(self.axis) > 1:
z = -z
@ -213,9 +212,9 @@ class plane:
def getGlobalCoords(self,point):
"returns the global coordinates of the given point, taken relatively to this working plane"
vx = fcvec.scale(self.u,point.x)
vy = fcvec.scale(self.v,point.y)
vz = fcvec.scale(self.axis,point.z)
vx = DraftVecUtils.scale(self.u,point.x)
vy = DraftVecUtils.scale(self.v,point.y)
vz = DraftVecUtils.scale(self.axis,point.z)
return (vx.add(vy)).add(vz)
def getClosestAxis(self,point):
@ -223,9 +222,9 @@ class plane:
ax = point.getAngle(self.u)
ay = point.getAngle(self.v)
az = point.getAngle(self.axis)
bx = point.getAngle(fcvec.neg(self.u))
by = point.getAngle(fcvec.neg(self.v))
bz = point.getAngle(fcvec.neg(self.axis))
bx = point.getAngle(DraftVecUtils.neg(self.u))
by = point.getAngle(DraftVecUtils.neg(self.v))
bz = point.getAngle(DraftVecUtils.neg(self.axis))
b = min(ax,ay,az,bx,by,bz)
if b in [ax,bx]:
return "x"

View File

@ -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)))

View File

@ -29,8 +29,7 @@ __url__ = ["http://yorik.orgfree.com","http://free-cad.sourceforge.net"]
This script imports OCA/gcad files into FreeCAD.
'''
import FreeCAD, os, Part, math
from draftlibs import fcvec, fcgeo
import FreeCAD, os, Part, math, DraftVecUtils, DraftGeomUtils
from FreeCAD import Vector
try: import FreeCADGui
@ -56,7 +55,7 @@ def getpoint(data):
if (data[1][0] == "R"):
return objects[data[0]].add(objects[data[1]])
elif (data[1][0] == "C"):
return fcgeo.findProjection(objects[data[0]],objects[data[1]])
return DraftGeomUtils.findProjection(objects[data[0]],objects[data[1]])
elif (data[0][0] == "C"):
if objects[data[0]]:
p1 = objects[data[0]].Curve.Position
@ -65,7 +64,7 @@ def getpoint(data):
else:
if (data[1][0] == "L"):
l = objects[data[1]]
return p1.add(fcgeo.vec(l))
return p1.add(DraftGeomUtils.vec(l))
def getarea(data):
"turns an OCA area definition into a FreeCAD Part Wire"
@ -111,7 +110,7 @@ def getarc(data):
c = Part.Circle()
c.Center = verts[0]
if rad: c.Radius = rad
else: c.Radius = fcvec.new(verts[0],verts[1]).Length
else: c.Radius = DraftVecUtils.new(verts[0],verts[1]).Length
elif (data[0][0] == "L"):
# 2-lines circle
lines = []
@ -121,7 +120,7 @@ def getarc(data):
rad = float(data[p+1])
elif (data[p][0] == "L"):
lines.append(objects[data[p]])
circles = fcgeo.circleFrom2LinesRadius(lines[0],lines[1],rad)
circles = DraftGeomUtils.circleFrom2LinesRadius(lines[0],lines[1],rad)
if circles: c = circles[0]
if c: return c.toShape()
@ -268,7 +267,7 @@ def export(exportList,filename):
oca.write("C"+str(count)+"=ARC ")
oca.write(writepoint(e.Vertexes[0].Point))
oca.write(" ")
oca.write(writepoint(fcgeo.findMidpoint(e)))
oca.write(writepoint(DraftGeomUtils.findMidpoint(e)))
oca.write(" ")
oca.write(writepoint(e.Vertexes[-1].Point))
else:

View File

@ -38,9 +38,7 @@ currently unsupported: use, image
# implement inherting fill style from group
# handle relative units
import xml.sax, string, FreeCAD, os, math, re, Draft
from draftlibs import fcvec
from draftlibs import fcgeo
import xml.sax, string, FreeCAD, os, math, re, Draft, DraftVecUtils, DraftGeomUtils
from FreeCAD import Vector
try: import FreeCADGui
@ -271,7 +269,7 @@ def makewire(path,checkclosed=False,donttry=False):
#ToDo Do not catch all exceptions
if not donttry:
try:
sh = Part.Wire(fcgeo.sortEdges(path))
sh = Part.Wire(DraftGeomUtils.sortEdges(path))
#sh = Part.Wire(path)
isok = (not checkclosed) or sh.isClosed()
except:# BRep_API:command not done
@ -334,13 +332,13 @@ def arcend2center(lastvec,currentvec,rx,ry,xrotation=0.0,correction=False):
m2=FreeCAD.Matrix()
m2.rotateZ(xrotation)
centeroff = currentvec.add(lastvec)
centeroff = fcvec.scale(centeroff,.5)
centeroff = DraftVecUtils.scale(centeroff,.5)
vcenter = m2.multiply(vcx1).add(centeroff) # Step3 F.6.5.3
#angle1 = Vector(1,0,0).getAngle(Vector((v1.x-vcx1.x)/rx,(v1.y-vcx1.y)/ry,0)) # F.6.5.5
#angledelta = Vector((v1.x-vcx1.x)/rx,(v1.y-vcx1.y)/ry,0).getAngle(Vector((-v1.x-vcx1.x)/rx,(-v1.y-vcx1.y)/ry,0)) # F.6.5.6
#we need the right sign for the angle
angle1 = fcvec.angle(Vector(1,0,0),Vector((v1.x-vcx1.x)/rx,(v1.y-vcx1.y)/ry,0)) # F.6.5.5
angledelta = fcvec.angle(Vector((v1.x-vcx1.x)/rx,(v1.y-vcx1.y)/ry,0),Vector((-v1.x-vcx1.x)/rx,(-v1.y-vcx1.y)/ry,0)) # F.6.5.6
angle1 = DraftVecUtils.angle(Vector(1,0,0),Vector((v1.x-vcx1.x)/rx,(v1.y-vcx1.y)/ry,0)) # F.6.5.5
angledelta = DraftVecUtils.angle(Vector((v1.x-vcx1.x)/rx,(v1.y-vcx1.y)/ry,0),Vector((-v1.x-vcx1.x)/rx,(-v1.y-vcx1.y)/ry,0)) # F.6.5.6
results.append((vcenter,angle1,angledelta))
return results,(rx,ry)
@ -558,7 +556,7 @@ class svgHandler(xml.sax.ContentHandler):
currentvec = lastvec.add(Vector(x,-y,0))
else:
currentvec = Vector(x,-y,0)
if not fcvec.equals(lastvec,currentvec):
if not DraftVecUtils.equals(lastvec,currentvec):
seg = Part.Line(lastvec,currentvec).toShape()
FreeCAD.Console.PrintMessage("line %s %s\n" %(lastvec,currentvec))
lastvec = currentvec
@ -599,15 +597,15 @@ class svgHandler(xml.sax.ContentHandler):
# here is a better way to find the perpendicular
if sweepflag == 1:
# clockwise
perp = fcvec.rotate2D(chord,-math.pi/2)
perp = DraftVecUtils.rotate2D(chord,-math.pi/2)
else:
# anticlockwise
perp = fcvec.rotate2D(chord,math.pi/2)
chord = fcvec.scale(chord,.5)
perp = DraftVecUtils.rotate2D(chord,math.pi/2)
chord = DraftVecUtils.scale(chord,.5)
if chord.Length > rx: a = 0
else: a = math.sqrt(rx**2-chord.Length**2)
s = rx - a
perp = fcvec.scale(perp,s/perp.Length)
perp = DraftVecUtils.scale(perp,s/perp.Length)
midpoint = lastvec.add(chord.add(perp))
seg = Part.Arc(lastvec,midpoint,currentvec).toShape()
else:# big arc or elliptical arc
@ -676,7 +674,7 @@ class svgHandler(xml.sax.ContentHandler):
currentvec = Vector(x,-y,0)
pole2 = Vector(p2x,-p2y,0)
if not fcvec.equals(currentvec,lastvec):
if not DraftVecUtils.equals(currentvec,lastvec):
mainv = currentvec.sub(lastvec)
pole1v = lastvec.add(pole1)
pole2v = currentvec.add(pole2)
@ -718,7 +716,7 @@ class svgHandler(xml.sax.ContentHandler):
else:
currentvec = Vector(x,-y,0)
if not fcvec.equals(currentvec,lastvec):
if not DraftVecUtils.equals(currentvec,lastvec):
if True and \
pole.distanceToLine(lastvec,currentvec) < 20**(-1*(2+Draft.precision())):
#print "straight segment"
@ -733,7 +731,7 @@ class svgHandler(xml.sax.ContentHandler):
lastpole = ('quadratic',pole)
path.append(seg)
elif (d == "Z") or (d == "z"):
if not fcvec.equals(lastvec,firstvec):
if not DraftVecUtils.equals(lastvec,firstvec):
seg = Part.Line(lastvec,firstvec).toShape()
path.append(seg)
if path: #the path should be closed by now
@ -821,7 +819,7 @@ class svgHandler(xml.sax.ContentHandler):
esh.append(arc.toShape())
for esh1,esh2 in zip(esh[-1:]+esh[:-1],esh):
p1,p2 = esh1.Vertexes[-1].Point,esh2.Vertexes[0].Point
if not fcvec.equals(p1,p2):
if not DraftVecUtils.equals(p1,p2):
edges.append(Part.Line(esh1.Vertexes[-1].Point,esh2.Vertexes[0].Point).toShape()) #straight segments
edges.append(esh2) # elliptical segments
sh = Part.Wire(edges)
@ -859,7 +857,7 @@ class svgHandler(xml.sax.ContentHandler):
points=points+points[:2] # emulate closepath
for svgx,svgy in zip(points[2::2],points[3::2]):
currentvec = Vector(svgx,-svgy,0)
if not fcvec.equals(lastvec,currentvec):
if not DraftVecUtils.equals(lastvec,currentvec):
seg = Part.Line(lastvec,currentvec).toShape()
#print "polyline seg ",lastvec,currentvec
lastvec = currentvec

View File

@ -38,6 +38,8 @@
<File Id="WorkingPlanePy" Name="WorkingPlane.py" DiskId="1" />
<File Id="macrosPy" Name="macros.py" DiskId="1" />
<File Id="DraftRcPy" Name="Draft_rc.py" DiskId="1" />
<File Id="DraftVecUtilsPy" Name="DraftVecUtils.py" DiskId="1" />
<File Id="DraftGeomUtilsPy" Name="DraftGeomUtils.py" DiskId="1" />
</Component>
<Directory Id="ModDraftLib" Name="draftlibs" FileSource="../../Mod/Draft/draftlibs">
<Component Id="CompModDraftLib" Guid="d19c08b0-0747-11de-8c30-0800200c9a66" Win64='$(var.Win_64)' KeyPath="yes">
@ -46,8 +48,6 @@
<File Id="DraftLibdxfImportObjectsPy" Name="dxfImportObjects.py" DiskId="1" />
<File Id="DraftLibdxfLibraryPy" Name="dxfLibrary.py" DiskId="1" />
<File Id="DraftLibdxfReaderPy" Name="dxfReader.py" DiskId="1" />
<File Id="DraftLibfcgeoPy" Name="fcgeo.py" DiskId="1" />
<File Id="DraftLibfcvecPy" Name="fcvec.py" DiskId="1" />
</Component>
</Directory>
</Directory>