Renamed Draft fcvec and fcgeo modules
Draft/draftlibs/fcvec becomes Draft/DraftVecUtils Draft/draftlibs/fcgeo becomes Draft/DraftGeomUtils
This commit is contained in:
parent
e607ddf55f
commit
7086b80cb3
|
@ -12,10 +12,15 @@ The Draft module offer several convenient functions to work with simple objects.
|
||||||
.. automodule:: DraftSnap
|
.. automodule:: DraftSnap
|
||||||
:members:
|
: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:
|
:members:
|
||||||
|
|
||||||
.. automodule:: draftlibs.fcgeo
|
.. automodule:: DraftGeomUtils
|
||||||
:members:
|
: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:
|
||||||
|
|
|
@ -21,9 +21,7 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
import FreeCAD,FreeCADGui,Draft,math
|
import FreeCAD,FreeCADGui,Draft,math,DraftVecUtils
|
||||||
|
|
||||||
from draftlibs import fcvec
|
|
||||||
from FreeCAD import Vector
|
from FreeCAD import Vector
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
from pivy import coin
|
from pivy import coin
|
||||||
|
|
|
@ -21,8 +21,7 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
import FreeCAD,FreeCADGui,Draft,ArchComponent
|
import FreeCAD,FreeCADGui,Draft,ArchComponent,DraftVecUtils
|
||||||
from draftlibs import fcvec
|
|
||||||
from FreeCAD import Vector
|
from FreeCAD import Vector
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
|
@ -170,7 +169,7 @@ def makeFace(wires,method=2,cleanup=False):
|
||||||
# cleaning up rubbish in wires
|
# cleaning up rubbish in wires
|
||||||
if cleanup:
|
if cleanup:
|
||||||
for i in range(len(wires)):
|
for i in range(len(wires)):
|
||||||
wires[i] = fcgeo.removeInterVertices(wires[i])
|
wires[i] = DraftGeomUtils.removeInterVertices(wires[i])
|
||||||
print "garbage removed"
|
print "garbage removed"
|
||||||
for w in wires:
|
for w in wires:
|
||||||
# we assume that the exterior boundary is that one with
|
# 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'''
|
mark is True (default), non-solid objects will be marked in red'''
|
||||||
|
|
||||||
name = obj.Name
|
name = obj.Name
|
||||||
import Part,MeshPart
|
import Part, MeshPart, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
if "Mesh" in obj.PropertiesList:
|
if "Mesh" in obj.PropertiesList:
|
||||||
faces = []
|
faces = []
|
||||||
mesh = obj.Mesh
|
mesh = obj.Mesh
|
||||||
|
@ -249,12 +247,12 @@ def meshToShape(obj,mark=True):
|
||||||
def removeShape(objs,mark=True):
|
def removeShape(objs,mark=True):
|
||||||
'''takes an arch object (wall or structure) built on a cubic shape, and removes
|
'''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.'''
|
the inner shape, keeping its length, width and height as parameters.'''
|
||||||
from draftlibs import fcgeo
|
import DraftGeomUtils
|
||||||
if not isinstance(objs,list):
|
if not isinstance(objs,list):
|
||||||
objs = [objs]
|
objs = [objs]
|
||||||
for obj in objs:
|
for obj in objs:
|
||||||
if fcgeo.isCubic(obj.Shape):
|
if DraftGeomUtils.isCubic(obj.Shape):
|
||||||
dims = fcgeo.getCubicDimensions(obj.Shape)
|
dims = DraftGeomUtils.getCubicDimensions(obj.Shape)
|
||||||
if dims:
|
if dims:
|
||||||
name = obj.Name
|
name = obj.Name
|
||||||
tp = Draft.getType(obj)
|
tp = Draft.getType(obj)
|
||||||
|
@ -270,7 +268,7 @@ def removeShape(objs,mark=True):
|
||||||
length = dims[1]
|
length = dims[1]
|
||||||
width = dims[2]
|
width = dims[2]
|
||||||
v1 = Vector(length/2,0,0)
|
v1 = Vector(length/2,0,0)
|
||||||
v2 = fcvec.neg(v1)
|
v2 = DraftVecUtils.neg(v1)
|
||||||
v1 = dims[0].multVec(v1)
|
v1 = dims[0].multVec(v1)
|
||||||
v2 = dims[0].multVec(v2)
|
v2 = dims[0].multVec(v2)
|
||||||
line = Draft.makeLine(v1,v2)
|
line = Draft.makeLine(v1,v2)
|
||||||
|
|
|
@ -21,8 +21,7 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
import FreeCAD,FreeCADGui,Draft,ArchComponent
|
import FreeCAD,FreeCADGui,Draft,ArchComponent, DraftVecUtils
|
||||||
from draftlibs import fcvec
|
|
||||||
from FreeCAD import Vector
|
from FreeCAD import Vector
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
|
@ -104,8 +103,7 @@ class _Roof(ArchComponent.Component):
|
||||||
self.createGeometry(obj)
|
self.createGeometry(obj)
|
||||||
|
|
||||||
def createGeometry(self,obj):
|
def createGeometry(self,obj):
|
||||||
import Part,math
|
import Part, math, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
pl = obj.Placement
|
pl = obj.Placement
|
||||||
|
|
||||||
if obj.Base and obj.Face and obj.Angle:
|
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())
|
c = round(math.tan(math.radians(obj.Angle)),Draft.precision())
|
||||||
norm = f.normalAt(0,0)
|
norm = f.normalAt(0,0)
|
||||||
d = f.BoundBox.DiagonalLength
|
d = f.BoundBox.DiagonalLength
|
||||||
edges = fcgeo.sortEdges(f.Edges)
|
edges = DraftGeomUtils.sortEdges(f.Edges)
|
||||||
l = len(edges)
|
l = len(edges)
|
||||||
edges.append(edges[0])
|
edges.append(edges[0])
|
||||||
shps = []
|
shps = []
|
||||||
for i in range(l):
|
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()
|
v.normalize()
|
||||||
bis = v.getAngle(fcgeo.vec(edges[i]))
|
bis = v.getAngle(DraftGeomUtils.vec(edges[i]))
|
||||||
delta = 1/math.cos(bis)
|
delta = 1/math.cos(bis)
|
||||||
v.multiply(delta)
|
v.multiply(delta)
|
||||||
n = (FreeCAD.Vector(norm)).multiply(c)
|
n = (FreeCAD.Vector(norm)).multiply(c)
|
||||||
|
@ -137,7 +135,7 @@ class _Roof(ArchComponent.Component):
|
||||||
c = c.removeSplitter()
|
c = c.removeSplitter()
|
||||||
if not c.isNull():
|
if not c.isNull():
|
||||||
obj.Shape = c
|
obj.Shape = c
|
||||||
if not fcgeo.isNull(pl):
|
if not DraftGeomUtils.isNull(pl):
|
||||||
obj.Placement = pl
|
obj.Placement = pl
|
||||||
|
|
||||||
class _ViewProviderRoof(ArchComponent.ViewProviderComponent):
|
class _ViewProviderRoof(ArchComponent.ViewProviderComponent):
|
||||||
|
|
|
@ -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 FreeCAD import Vector
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
from pivy import coin
|
from pivy import coin
|
||||||
from draftlibs import fcvec
|
|
||||||
|
|
||||||
|
|
||||||
class _CommandSectionPlane:
|
class _CommandSectionPlane:
|
||||||
|
@ -176,8 +175,7 @@ class _ArchDrawingView:
|
||||||
|
|
||||||
def updateSVG(self, obj,join=False):
|
def updateSVG(self, obj,join=False):
|
||||||
"encapsulates a svg fragment into a transformation node"
|
"encapsulates a svg fragment into a transformation node"
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
if hasattr(obj,"Source"):
|
if hasattr(obj,"Source"):
|
||||||
if obj.Source:
|
if obj.Source:
|
||||||
if obj.Source.Objects:
|
if obj.Source.Objects:
|
||||||
|
@ -207,7 +205,7 @@ class _ArchDrawingView:
|
||||||
base = shape.pop()
|
base = shape.pop()
|
||||||
for sh in shapes:
|
for sh in shapes:
|
||||||
base = base.fuse(sh)
|
base = base.fuse(sh)
|
||||||
svgf = Drawing.projectToSVG(base,fcvec.neg(direction))
|
svgf = Drawing.projectToSVG(base,DraftVecUtils.neg(direction))
|
||||||
if svgf:
|
if svgf:
|
||||||
svgf = svgf.replace('stroke-width="0.35"','stroke-width="' + str(linewidth) + 'px"')
|
svgf = svgf.replace('stroke-width="0.35"','stroke-width="' + str(linewidth) + 'px"')
|
||||||
svg += svgf
|
svg += svgf
|
||||||
|
|
|
@ -21,8 +21,7 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
import FreeCAD,FreeCADGui,Draft,ArchComponent
|
import FreeCAD,FreeCADGui,Draft,ArchComponent,DraftVecUtils
|
||||||
from draftlibs import fcvec
|
|
||||||
from FreeCAD import Vector
|
from FreeCAD import Vector
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
|
@ -99,7 +98,7 @@ class _Structure(ArchComponent.Component):
|
||||||
|
|
||||||
def getAxisPoints(self,obj):
|
def getAxisPoints(self,obj):
|
||||||
"returns the gridpoints of linked axes"
|
"returns the gridpoints of linked axes"
|
||||||
from draftlibs import fcgeo
|
import DraftGeomUtils
|
||||||
pts = []
|
pts = []
|
||||||
if len(obj.Axes) == 1:
|
if len(obj.Axes) == 1:
|
||||||
for e in obj.Axes[0].Shape.Edges:
|
for e in obj.Axes[0].Shape.Edges:
|
||||||
|
@ -109,12 +108,11 @@ class _Structure(ArchComponent.Component):
|
||||||
set2 = obj.Axes[1].Shape.Edges
|
set2 = obj.Axes[1].Shape.Edges
|
||||||
for e1 in set1:
|
for e1 in set1:
|
||||||
for e2 in set2:
|
for e2 in set2:
|
||||||
pts.extend(fcgeo.findIntersection(e1,e2))
|
pts.extend(DraftGeomUtils.findIntersection(e1,e2))
|
||||||
return pts
|
return pts
|
||||||
|
|
||||||
def createGeometry(self,obj):
|
def createGeometry(self,obj):
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
# getting default values
|
# getting default values
|
||||||
height = normal = None
|
height = normal = None
|
||||||
if obj.Length:
|
if obj.Length:
|
||||||
|
@ -187,7 +185,7 @@ class _Structure(ArchComponent.Component):
|
||||||
obj.Shape = Part.makeCompound(fsh)
|
obj.Shape = Part.makeCompound(fsh)
|
||||||
else:
|
else:
|
||||||
obj.Shape = base
|
obj.Shape = base
|
||||||
if not fcgeo.isNull(pl): obj.Placement = pl
|
if not DraftGeomUtils.isNull(pl): obj.Placement = pl
|
||||||
|
|
||||||
class _ViewProviderStructure(ArchComponent.ViewProviderComponent):
|
class _ViewProviderStructure(ArchComponent.ViewProviderComponent):
|
||||||
"A View Provider for the Structure object"
|
"A View Provider for the Structure object"
|
||||||
|
|
|
@ -23,8 +23,7 @@
|
||||||
|
|
||||||
"The FreeCAD Arch Vector Rendering Module"
|
"The FreeCAD Arch Vector Rendering Module"
|
||||||
|
|
||||||
import FreeCAD,math,Part,ArchCommands
|
import FreeCAD,math,Part,ArchCommands,DraftVecUtils,DraftGeomUtils
|
||||||
from draftlibs import fcvec,fcgeo
|
|
||||||
|
|
||||||
DEBUG = True # if we want debug messages
|
DEBUG = True # if we want debug messages
|
||||||
MAXLOOP = 10 # the max number of loop before abort
|
MAXLOOP = 10 # the max number of loop before abort
|
||||||
|
@ -171,7 +170,7 @@ class Renderer:
|
||||||
norm = face[0].normalAt(0,0)
|
norm = face[0].normalAt(0,0)
|
||||||
for w in face[0].Wires:
|
for w in face[0].Wires:
|
||||||
verts = []
|
verts = []
|
||||||
edges = fcgeo.sortEdges(w.Edges)
|
edges = DraftGeomUtils.sortEdges(w.Edges)
|
||||||
for e in edges:
|
for e in edges:
|
||||||
v = e.Vertexes[0].Point
|
v = e.Vertexes[0].Point
|
||||||
v = self.wp.getLocalCoords(v)
|
v = self.wp.getLocalCoords(v)
|
||||||
|
@ -196,7 +195,7 @@ class Renderer:
|
||||||
wires = []
|
wires = []
|
||||||
for w in face[0].Wires:
|
for w in face[0].Wires:
|
||||||
verts = []
|
verts = []
|
||||||
edges = fcgeo.sortEdges(w.Edges)
|
edges = DraftGeomUtils.sortEdges(w.Edges)
|
||||||
for e in edges:
|
for e in edges:
|
||||||
v = e.Vertexes[0].Point
|
v = e.Vertexes[0].Point
|
||||||
verts.append(FreeCAD.Vector(v.x,v.y,0))
|
verts.append(FreeCAD.Vector(v.x,v.y,0))
|
||||||
|
@ -239,11 +238,11 @@ class Renderer:
|
||||||
FreeCAD.Vector(bb.XMax,bb.YMax,bb.ZMax)]
|
FreeCAD.Vector(bb.XMax,bb.YMax,bb.ZMax)]
|
||||||
for c in corners:
|
for c in corners:
|
||||||
dv = c.sub(placement.Base)
|
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)
|
um = max(um,um1)
|
||||||
vm1 = fcvec.project(dv,self.wp.v).Length
|
vm1 = DraftVecUtils.project(dv,self.wp.v).Length
|
||||||
vm = max(vm,vm1)
|
vm = max(vm,vm1)
|
||||||
wm1 = fcvec.project(dv,self.wp.axis).Length
|
wm1 = DraftVecUtils.project(dv,self.wp.axis).Length
|
||||||
wm = max(wm,wm1)
|
wm = max(wm,wm1)
|
||||||
p1 = FreeCAD.Vector(-um,vm,0)
|
p1 = FreeCAD.Vector(-um,vm,0)
|
||||||
p2 = 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.makePolygon([p1,p2,p3,p4,p1])
|
||||||
cutface = Part.Face(cutface)
|
cutface = Part.Face(cutface)
|
||||||
cutface.Placement = placement
|
cutface.Placement = placement
|
||||||
cutnormal = fcvec.scaleTo(self.wp.axis,wm)
|
cutnormal = DraftVecUtils.scaleTo(self.wp.axis,wm)
|
||||||
cutvolume = cutface.extrude(cutnormal)
|
cutvolume = cutface.extrude(cutnormal)
|
||||||
shapes = []
|
shapes = []
|
||||||
faces = []
|
faces = []
|
||||||
|
@ -265,7 +264,7 @@ class Renderer:
|
||||||
faces.append([f]+sh[1:])
|
faces.append([f]+sh[1:])
|
||||||
sec = sol.section(cutface)
|
sec = sol.section(cutface)
|
||||||
if sec.Edges:
|
if sec.Edges:
|
||||||
wires = fcgeo.findWires(sec.Edges)
|
wires = DraftGeomUtils.findWires(sec.Edges)
|
||||||
for w in wires:
|
for w in wires:
|
||||||
sec = Part.Face(w)
|
sec = Part.Face(w)
|
||||||
sections.append([sec,fill])
|
sections.append([sec,fill])
|
||||||
|
@ -313,7 +312,7 @@ class Renderer:
|
||||||
# even so, faces can still overlap if their edges cross each other
|
# even so, faces can still overlap if their edges cross each other
|
||||||
for e1 in face1[0].Edges:
|
for e1 in face1[0].Edges:
|
||||||
for e2 in face2[0].Edges:
|
for e2 in face2[0].Edges:
|
||||||
if fcgeo.findIntersection(e1,e2):
|
if DraftGeomUtils.findIntersection(e1,e2):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -354,8 +353,8 @@ class Renderer:
|
||||||
front = 0
|
front = 0
|
||||||
for v in face1[0].Vertexes:
|
for v in face1[0].Vertexes:
|
||||||
dv = v.Point.sub(face2[0].Vertexes[0].Point)
|
dv = v.Point.sub(face2[0].Vertexes[0].Point)
|
||||||
dv = fcvec.project(dv,norm)
|
dv = DraftVecUtils.project(dv,norm)
|
||||||
if fcvec.isNull(dv):
|
if DraftVecUtils.isNull(dv):
|
||||||
behind += 1
|
behind += 1
|
||||||
front += 1
|
front += 1
|
||||||
else:
|
else:
|
||||||
|
@ -377,8 +376,8 @@ class Renderer:
|
||||||
front = 0
|
front = 0
|
||||||
for v in face2[0].Vertexes:
|
for v in face2[0].Vertexes:
|
||||||
dv = v.Point.sub(face1[0].Vertexes[0].Point)
|
dv = v.Point.sub(face1[0].Vertexes[0].Point)
|
||||||
dv = fcvec.project(dv,norm)
|
dv = DraftVecUtils.project(dv,norm)
|
||||||
if fcvec.isNull(dv):
|
if DraftVecUtils.isNull(dv):
|
||||||
behind += 1
|
behind += 1
|
||||||
front += 1
|
front += 1
|
||||||
else:
|
else:
|
||||||
|
@ -545,7 +544,7 @@ class Renderer:
|
||||||
|
|
||||||
def getPathData(self,w):
|
def getPathData(self,w):
|
||||||
"Returns a SVG path data string from a 2D wire"
|
"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
|
v = edges[0].Vertexes[0].Point
|
||||||
svg = 'M '+ str(v.x) +' '+ str(v.y) + ' '
|
svg = 'M '+ str(v.x) +' '+ str(v.y) + ' '
|
||||||
for e in edges:
|
for e in edges:
|
||||||
|
|
|
@ -21,8 +21,7 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
import FreeCAD,FreeCADGui,Draft,ArchComponent
|
import FreeCAD,FreeCADGui,Draft,ArchComponent,DraftVecUtils
|
||||||
from draftlibs import fcvec
|
|
||||||
from FreeCAD import Vector
|
from FreeCAD import Vector
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
|
@ -180,13 +179,13 @@ class _CommandWall:
|
||||||
n = FreeCAD.DraftWorkingPlane.axis
|
n = FreeCAD.DraftWorkingPlane.axis
|
||||||
bv = point.sub(b)
|
bv = point.sub(b)
|
||||||
dv = bv.cross(n)
|
dv = bv.cross(n)
|
||||||
dv = fcvec.scaleTo(dv,self.Width/2)
|
dv = DraftVecUtils.scaleTo(dv,self.Width/2)
|
||||||
if self.Align == "Center":
|
if self.Align == "Center":
|
||||||
self.tracker.update([b,point])
|
self.tracker.update([b,point])
|
||||||
elif self.Align == "Left":
|
elif self.Align == "Left":
|
||||||
self.tracker.update([b.add(dv),point.add(dv)])
|
self.tracker.update([b.add(dv),point.add(dv)])
|
||||||
else:
|
else:
|
||||||
dv = fcvec.neg(dv)
|
dv = DraftVecUtils.neg(dv)
|
||||||
self.tracker.update([b.add(dv),point.add(dv)])
|
self.tracker.update([b.add(dv),point.add(dv)])
|
||||||
|
|
||||||
def taskbox(self):
|
def taskbox(self):
|
||||||
|
@ -275,10 +274,10 @@ class _Wall(ArchComponent.Component):
|
||||||
f = w
|
f = w
|
||||||
f = Part.Face(f)
|
f = Part.Face(f)
|
||||||
n = f.normalAt(0,0)
|
n = f.normalAt(0,0)
|
||||||
v1 = fcvec.scaleTo(n,width)
|
v1 = DraftVecUtils.scaleTo(n,width)
|
||||||
f.translate(v1)
|
f.translate(v1)
|
||||||
v2 = fcvec.neg(v1)
|
v2 = DraftVecUtils.neg(v1)
|
||||||
v2 = fcvec.scale(v1,-2)
|
v2 = DraftVecUtils.scale(v1,-2)
|
||||||
f = f.extrude(v2)
|
f = f.extrude(v2)
|
||||||
if delta:
|
if delta:
|
||||||
f.translate(delta)
|
f.translate(delta)
|
||||||
|
@ -290,8 +289,7 @@ class _Wall(ArchComponent.Component):
|
||||||
if not obj.Base:
|
if not obj.Base:
|
||||||
return
|
return
|
||||||
|
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
|
|
||||||
flat = False
|
flat = False
|
||||||
if hasattr(obj.ViewObject,"DisplayMode"):
|
if hasattr(obj.ViewObject,"DisplayMode"):
|
||||||
|
@ -304,25 +302,25 @@ class _Wall(ArchComponent.Component):
|
||||||
|
|
||||||
def getbase(wire):
|
def getbase(wire):
|
||||||
"returns a full shape from a base 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()
|
dvec.normalize()
|
||||||
if obj.Align == "Left":
|
if obj.Align == "Left":
|
||||||
dvec = dvec.multiply(width)
|
dvec = dvec.multiply(width)
|
||||||
w2 = fcgeo.offsetWire(wire,dvec)
|
w2 = DraftGeomUtils.offsetWire(wire,dvec)
|
||||||
w1 = Part.Wire(fcgeo.sortEdges(wire.Edges))
|
w1 = Part.Wire(DraftGeomUtils.sortEdges(wire.Edges))
|
||||||
sh = fcgeo.bind(w1,w2)
|
sh = DraftGeomUtils.bind(w1,w2)
|
||||||
elif obj.Align == "Right":
|
elif obj.Align == "Right":
|
||||||
dvec = dvec.multiply(width)
|
dvec = dvec.multiply(width)
|
||||||
dvec = fcvec.neg(dvec)
|
dvec = DraftVecUtils.neg(dvec)
|
||||||
w2 = fcgeo.offsetWire(wire,dvec)
|
w2 = DraftGeomUtils.offsetWire(wire,dvec)
|
||||||
w1 = Part.Wire(fcgeo.sortEdges(wire.Edges))
|
w1 = Part.Wire(DraftGeomUtils.sortEdges(wire.Edges))
|
||||||
sh = fcgeo.bind(w1,w2)
|
sh = DraftGeomUtils.bind(w1,w2)
|
||||||
elif obj.Align == "Center":
|
elif obj.Align == "Center":
|
||||||
dvec = dvec.multiply(width/2)
|
dvec = dvec.multiply(width/2)
|
||||||
w1 = fcgeo.offsetWire(wire,dvec)
|
w1 = DraftGeomUtils.offsetWire(wire,dvec)
|
||||||
dvec = fcvec.neg(dvec)
|
dvec = DraftVecUtils.neg(dvec)
|
||||||
w2 = fcgeo.offsetWire(wire,dvec)
|
w2 = DraftGeomUtils.offsetWire(wire,dvec)
|
||||||
sh = fcgeo.bind(w1,w2)
|
sh = DraftGeomUtils.bind(w1,w2)
|
||||||
# fixing self-intersections
|
# fixing self-intersections
|
||||||
sh.fix(0.1,0,1)
|
sh.fix(0.1,0,1)
|
||||||
if height and (not flat):
|
if height and (not flat):
|
||||||
|
@ -388,7 +386,7 @@ class _Wall(ArchComponent.Component):
|
||||||
|
|
||||||
if base:
|
if base:
|
||||||
obj.Shape = base
|
obj.Shape = base
|
||||||
if not fcgeo.isNull(pl):
|
if not DraftGeomUtils.isNull(pl):
|
||||||
obj.Placement = pl
|
obj.Placement = pl
|
||||||
|
|
||||||
class _ViewProviderWall(ArchComponent.ViewProviderComponent):
|
class _ViewProviderWall(ArchComponent.ViewProviderComponent):
|
||||||
|
|
|
@ -21,8 +21,7 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
import FreeCAD,FreeCADGui,Draft,ArchComponent
|
import FreeCAD,FreeCADGui,Draft,ArchComponent,DraftVecUtils
|
||||||
from draftlibs import fcvec
|
|
||||||
from FreeCAD import Vector
|
from FreeCAD import Vector
|
||||||
from PyQt4 import QtCore,QtGui
|
from PyQt4 import QtCore,QtGui
|
||||||
|
|
||||||
|
@ -109,8 +108,7 @@ class _Window(ArchComponent.Component):
|
||||||
self.createGeometry(obj)
|
self.createGeometry(obj)
|
||||||
|
|
||||||
def createGeometry(self,obj):
|
def createGeometry(self,obj):
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
pl = obj.Placement
|
pl = obj.Placement
|
||||||
if obj.Base:
|
if obj.Base:
|
||||||
if obj.Base.isDerivedFrom("Part::Feature"):
|
if obj.Base.isDerivedFrom("Part::Feature"):
|
||||||
|
@ -135,7 +133,7 @@ class _Window(ArchComponent.Component):
|
||||||
norm = shape.normalAt(0,0)
|
norm = shape.normalAt(0,0)
|
||||||
thk = float(obj.WindowParts[(i*5)+3])
|
thk = float(obj.WindowParts[(i*5)+3])
|
||||||
if thk:
|
if thk:
|
||||||
exv = fcvec.scaleTo(norm,thk)
|
exv = DraftVecUtils.scaleTo(norm,thk)
|
||||||
shape = shape.extrude(exv)
|
shape = shape.extrude(exv)
|
||||||
for w in wires:
|
for w in wires:
|
||||||
f = Part.Face(w)
|
f = Part.Face(w)
|
||||||
|
@ -144,12 +142,12 @@ class _Window(ArchComponent.Component):
|
||||||
if obj.WindowParts[(i*5)+4]:
|
if obj.WindowParts[(i*5)+4]:
|
||||||
zof = float(obj.WindowParts[(i*5)+4])
|
zof = float(obj.WindowParts[(i*5)+4])
|
||||||
if zof:
|
if zof:
|
||||||
zov = fcvec.scaleTo(norm,zof)
|
zov = DraftVecUtils.scaleTo(norm,zof)
|
||||||
shape.translate(zov)
|
shape.translate(zov)
|
||||||
print shape
|
print shape
|
||||||
shapes.append(shape)
|
shapes.append(shape)
|
||||||
obj.Shape = Part.makeCompound(shapes)
|
obj.Shape = Part.makeCompound(shapes)
|
||||||
if not fcgeo.isNull(pl):
|
if not DraftGeomUtils.isNull(pl):
|
||||||
obj.Placement = pl
|
obj.Placement = pl
|
||||||
|
|
||||||
class _ViewProviderWindow(ArchComponent.ViewProviderComponent):
|
class _ViewProviderWindow(ArchComponent.ViewProviderComponent):
|
||||||
|
|
|
@ -21,8 +21,7 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
import ifcReader, FreeCAD, Arch, Draft, os, sys, time, Part
|
import ifcReader, FreeCAD, Arch, Draft, os, sys, time, Part, DraftVecUtils
|
||||||
from draftlibs import fcvec
|
|
||||||
|
|
||||||
__title__="FreeCAD IFC importer"
|
__title__="FreeCAD IFC importer"
|
||||||
__author__ = "Yorik van Havre"
|
__author__ = "Yorik van Havre"
|
||||||
|
@ -448,7 +447,7 @@ def getPlacement(entity):
|
||||||
z = getVector(entity.Axis)
|
z = getVector(entity.Axis)
|
||||||
y = z.cross(x)
|
y = z.cross(x)
|
||||||
loc = getVector(entity.Location)
|
loc = getVector(entity.Location)
|
||||||
m = fcvec.getPlaneRotation(x,y,z)
|
m = DraftVecUtils.getPlaneRotation(x,y,z)
|
||||||
pl = FreeCAD.Placement(m)
|
pl = FreeCAD.Placement(m)
|
||||||
pl.move(loc)
|
pl.move(loc)
|
||||||
elif entity.type == "IFCLOCALPLACEMENT":
|
elif entity.type == "IFCLOCALPLACEMENT":
|
||||||
|
|
|
@ -21,8 +21,7 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
import FreeCAD
|
import FreeCAD, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
|
|
||||||
if open.__module__ == '__builtin__':
|
if open.__module__ == '__builtin__':
|
||||||
pythonopen = open
|
pythonopen = open
|
||||||
|
@ -42,7 +41,7 @@ def getIndices(shape,offset):
|
||||||
for f in shape.Faces:
|
for f in shape.Faces:
|
||||||
fi = ""
|
fi = ""
|
||||||
# OCC vertices are unsorted. We need to sort in the right order...
|
# 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
|
print edges
|
||||||
for e in edges:
|
for e in edges:
|
||||||
print e.Vertexes[0].Point,e.Vertexes[1].Point
|
print e.Vertexes[0].Point,e.Vertexes[1].Point
|
||||||
|
|
|
@ -7,6 +7,8 @@ SET(Draft_SRCS
|
||||||
DraftGui.py
|
DraftGui.py
|
||||||
DraftSnap.py
|
DraftSnap.py
|
||||||
DraftTrackers.py
|
DraftTrackers.py
|
||||||
|
DraftVecUtils.py
|
||||||
|
DraftGeomUtils.py
|
||||||
WorkingPlane.py
|
WorkingPlane.py
|
||||||
importDXF.py
|
importDXF.py
|
||||||
importOCA.py
|
importOCA.py
|
||||||
|
@ -22,8 +24,6 @@ SET(DraftLibs_SRCS
|
||||||
draftlibs/dxfImportObjects.py
|
draftlibs/dxfImportObjects.py
|
||||||
draftlibs/dxfLibrary.py
|
draftlibs/dxfLibrary.py
|
||||||
draftlibs/dxfReader.py
|
draftlibs/dxfReader.py
|
||||||
draftlibs/fcgeo.py
|
|
||||||
draftlibs/fcvec.py
|
|
||||||
draftlibs/__init__.py
|
draftlibs/__init__.py
|
||||||
)
|
)
|
||||||
SOURCE_GROUP("draftlibs" FILES ${DraftLibs_SRCS})
|
SOURCE_GROUP("draftlibs" FILES ${DraftLibs_SRCS})
|
||||||
|
|
|
@ -54,9 +54,9 @@ How it works / how to extend:
|
||||||
- DraftTools.py: Contains the user tools of the Draft module (the commands
|
- 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"
|
from the Draft menu), and a couple of helpers such as the "Trackers"
|
||||||
(temporary geometry used while drawing)
|
(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
|
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
|
The Draft.py contains everything to create geometry in the scene. You
|
||||||
should start there if you intend to modify something. Then, the DraftTools
|
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 modules
|
||||||
import FreeCAD, math, sys, os
|
import FreeCAD, math, sys, os, DraftVecUtils
|
||||||
from FreeCAD import Vector
|
from FreeCAD import Vector
|
||||||
from draftlibs import fcvec
|
|
||||||
from pivy import coin
|
from pivy import coin
|
||||||
|
|
||||||
if FreeCAD.GuiUp:
|
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))
|
ref = placement.multVec(FreeCAD.Vector(1,0,0))
|
||||||
v1 = (edge.Vertexes[0].Point).sub(edge.Curve.Center)
|
v1 = (edge.Vertexes[0].Point).sub(edge.Curve.Center)
|
||||||
v2 = (edge.Vertexes[-1].Point).sub(edge.Curve.Center)
|
v2 = (edge.Vertexes[-1].Point).sub(edge.Curve.Center)
|
||||||
a1 = -math.degrees(fcvec.angle(v1,ref))
|
a1 = -math.degrees(DraftVecUtils.angle(v1,ref))
|
||||||
a2 = -math.degrees(fcvec.angle(v2,ref))
|
a2 = -math.degrees(DraftVecUtils.angle(v2,ref))
|
||||||
obj.FirstAngle = a1
|
obj.FirstAngle = a1
|
||||||
obj.LastAngle = a2
|
obj.LastAngle = a2
|
||||||
else:
|
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
|
and last points are identical, the wire is closed. If face is
|
||||||
true (and wire is closed), the wire will appear filled. Instead of
|
true (and wire is closed), the wire will appear filled. Instead of
|
||||||
a pointslist, you can also pass a Part Wire.'''
|
a pointslist, you can also pass a Part Wire.'''
|
||||||
from draftlibs import fcgeo
|
import DraftGeomUtils, Part
|
||||||
import Part
|
|
||||||
if not isinstance(pointslist,list):
|
if not isinstance(pointslist,list):
|
||||||
e = pointslist.Wires[0].Edges
|
e = pointslist.Wires[0].Edges
|
||||||
pointslist = Part.Wire(fcgeo.sortEdges(e))
|
pointslist = Part.Wire(DraftGeomUtils.sortEdges(e))
|
||||||
nlist = []
|
nlist = []
|
||||||
for v in pointslist.Vertexes:
|
for v in pointslist.Vertexes:
|
||||||
nlist.append(v.Point)
|
nlist.append(v.Point)
|
||||||
if fcgeo.isReallyClosed(pointslist):
|
if DraftGeomUtils.isReallyClosed(pointslist):
|
||||||
closed = True
|
closed = True
|
||||||
pointslist = nlist
|
pointslist = nlist
|
||||||
print pointslist
|
print pointslist
|
||||||
|
@ -774,8 +772,7 @@ def fuse(object1,object2):
|
||||||
the union of the 2 given objects. If the objects are
|
the union of the 2 given objects. If the objects are
|
||||||
coplanar, a special Draft Wire is used, otherwise we use
|
coplanar, a special Draft Wire is used, otherwise we use
|
||||||
a standard Part fuse.'''
|
a standard Part fuse.'''
|
||||||
from draftlibs import fcgeo
|
import DraftGeomUtils, Part
|
||||||
import Part
|
|
||||||
# testing if we have holes:
|
# testing if we have holes:
|
||||||
holes = False
|
holes = False
|
||||||
fshape = object1.Shape.fuse(object2.Shape)
|
fshape = object1.Shape.fuse(object2.Shape)
|
||||||
|
@ -783,7 +780,7 @@ def fuse(object1,object2):
|
||||||
for f in fshape.Faces:
|
for f in fshape.Faces:
|
||||||
if len(f.Wires) > 1:
|
if len(f.Wires) > 1:
|
||||||
holes = True
|
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")
|
obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython","Fusion")
|
||||||
_Wire(obj)
|
_Wire(obj)
|
||||||
if gui:
|
if gui:
|
||||||
|
@ -879,12 +876,12 @@ def array(objectslist,arg1,arg2,arg3,arg4=None):
|
||||||
typecheck([(xvector,Vector), (yvector,Vector), (xnum,int), (ynum,int)], "rectArray")
|
typecheck([(xvector,Vector), (yvector,Vector), (xnum,int), (ynum,int)], "rectArray")
|
||||||
if not isinstance(objectslist,list): objectslist = [objectslist]
|
if not isinstance(objectslist,list): objectslist = [objectslist]
|
||||||
for xcount in range(xnum):
|
for xcount in range(xnum):
|
||||||
currentxvector=fcvec.scale(xvector,xcount)
|
currentxvector=DraftVecUtils.scale(xvector,xcount)
|
||||||
if not xcount==0:
|
if not xcount==0:
|
||||||
move(objectslist,currentxvector,True)
|
move(objectslist,currentxvector,True)
|
||||||
for ycount in range(ynum):
|
for ycount in range(ynum):
|
||||||
currentxvector=FreeCAD.Base.Vector(currentxvector)
|
currentxvector=FreeCAD.Base.Vector(currentxvector)
|
||||||
currentyvector=currentxvector.add(fcvec.scale(yvector,ycount))
|
currentyvector=currentxvector.add(DraftVecUtils.scale(yvector,ycount))
|
||||||
if not ycount==0:
|
if not ycount==0:
|
||||||
move(objectslist,currentyvector,True)
|
move(objectslist,currentyvector,True)
|
||||||
def polarArray(objectslist,center,angle,num):
|
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
|
newobj = obj
|
||||||
if (obj.isDerivedFrom("Part::Feature")):
|
if (obj.isDerivedFrom("Part::Feature")):
|
||||||
shape = obj.Shape.copy()
|
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
|
newobj.Shape = shape
|
||||||
elif (obj.isDerivedFrom("App::Annotation")):
|
elif (obj.isDerivedFrom("App::Annotation")):
|
||||||
if axis.normalize() == Vector(1,0,0):
|
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"):
|
elif hasattr(obj,"Placement"):
|
||||||
shape = Part.Shape()
|
shape = Part.Shape()
|
||||||
shape.Placement = obj.Placement
|
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
|
newobj.Placement = shape.Placement
|
||||||
if copy:
|
if copy:
|
||||||
formatObject(newobj,obj)
|
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)
|
sh = sh.transformGeometry(m)
|
||||||
corr = Vector(center.x,center.y,center.z)
|
corr = Vector(center.x,center.y,center.z)
|
||||||
corr.scale(delta.x,delta.y,delta.z)
|
corr.scale(delta.x,delta.y,delta.z)
|
||||||
corr = fcvec.neg(corr.sub(center))
|
corr = DraftVecUtils.neg(corr.sub(center))
|
||||||
sh.translate(corr)
|
sh.translate(corr)
|
||||||
if getType(obj) == "Rectangle":
|
if getType(obj) == "Rectangle":
|
||||||
p = []
|
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])
|
diag = p[2].sub(p[0])
|
||||||
bb = p[1].sub(p[0])
|
bb = p[1].sub(p[0])
|
||||||
bh = p[3].sub(p[0])
|
bh = p[3].sub(p[0])
|
||||||
nb = fcvec.project(diag,bb)
|
nb = DraftVecUtils.project(diag,bb)
|
||||||
nh = fcvec.project(diag,bh)
|
nh = DraftVecUtils.project(diag,bh)
|
||||||
if obj.Length < 0: l = -nb.Length
|
if obj.Length < 0: l = -nb.Length
|
||||||
else: l = nb.Length
|
else: l = nb.Length
|
||||||
if obj.Height < 0: h = -nh.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
|
obj.Scale = delta
|
||||||
corr = Vector(center.x,center.y,center.z)
|
corr = Vector(center.x,center.y,center.z)
|
||||||
corr.scale(delta.x,delta.y,delta.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 = obj.Placement
|
||||||
p.move(corr)
|
p.move(corr)
|
||||||
obj.Placement = p
|
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
|
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
|
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.'''
|
sides, the total width being the given delta length.'''
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
|
|
||||||
def getRect(p,obj):
|
def getRect(p,obj):
|
||||||
"returns length,heigh,placement"
|
"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])
|
diag = p[2].sub(p[0])
|
||||||
bb = p[1].sub(p[0])
|
bb = p[1].sub(p[0])
|
||||||
bh = p[3].sub(p[0])
|
bh = p[3].sub(p[0])
|
||||||
nb = fcvec.project(diag,bb)
|
nb = DraftVecUtils.project(diag,bb)
|
||||||
nh = fcvec.project(diag,bh)
|
nh = DraftVecUtils.project(diag,bh)
|
||||||
if obj.Length < 0: l = -nb.Length
|
if obj.Length < 0: l = -nb.Length
|
||||||
else: l = nb.Length
|
else: l = nb.Length
|
||||||
if obj.Height < 0: h = -nh.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):
|
def getRadius(obj,delta):
|
||||||
"returns a new radius for a regular polygon"
|
"returns a new radius for a regular polygon"
|
||||||
an = math.pi/obj.FacesNumber
|
an = math.pi/obj.FacesNumber
|
||||||
nr = fcvec.rotate(delta,-an)
|
nr = DraftVecUtils.rotate(delta,-an)
|
||||||
nr.multiply(1/math.cos(an))
|
nr.multiply(1/math.cos(an))
|
||||||
nr = obj.Shape.Vertexes[0].Point.add(nr)
|
nr = obj.Shape.Vertexes[0].Point.add(nr)
|
||||||
nr = nr.sub(obj.Placement.Base)
|
nr = nr.sub(obj.Placement.Base)
|
||||||
|
@ -1075,18 +1071,18 @@ def offset(obj,delta,copy=False,bind=False,sym=False,occ=False):
|
||||||
else:
|
else:
|
||||||
if sym:
|
if sym:
|
||||||
d1 = delta.multiply(0.5)
|
d1 = delta.multiply(0.5)
|
||||||
d2 = fcvec.neg(d1)
|
d2 = DraftVecUtils.neg(d1)
|
||||||
n1 = fcgeo.offsetWire(obj.Shape,d1)
|
n1 = DraftGeomUtils.offsetWire(obj.Shape,d1)
|
||||||
n2 = fcgeo.offsetWire(obj.Shape,d2)
|
n2 = DraftGeomUtils.offsetWire(obj.Shape,d2)
|
||||||
else:
|
else:
|
||||||
newwire = fcgeo.offsetWire(obj.Shape,delta)
|
newwire = DraftGeomUtils.offsetWire(obj.Shape,delta)
|
||||||
p = fcgeo.getVerts(newwire)
|
p = DraftGeomUtils.getVerts(newwire)
|
||||||
if occ:
|
if occ:
|
||||||
newobj = FreeCAD.ActiveDocument.addObject("Part::Feature","Offset")
|
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)
|
formatObject(newobj,obj)
|
||||||
elif bind:
|
elif bind:
|
||||||
if not fcgeo.isReallyClosed(obj.Shape):
|
if not DraftGeomUtils.isReallyClosed(obj.Shape):
|
||||||
if sym:
|
if sym:
|
||||||
s1 = n1
|
s1 = n1
|
||||||
s2 = n2
|
s2 = n2
|
||||||
|
@ -1161,8 +1157,7 @@ def draftify(objectslist,makeblock=False):
|
||||||
'''draftify(objectslist,[makeblock]): turns each object of the given list
|
'''draftify(objectslist,[makeblock]): turns each object of the given list
|
||||||
(objectslist can also be a single object) into a Draft parametric
|
(objectslist can also be a single object) into a Draft parametric
|
||||||
wire. If makeblock is True, multiple objects will be grouped in a block'''
|
wire. If makeblock is True, multiple objects will be grouped in a block'''
|
||||||
from draftlibs import fcgeo
|
import DraftGeomUtils, Part
|
||||||
import Part
|
|
||||||
|
|
||||||
if not isinstance(objectslist,list):
|
if not isinstance(objectslist,list):
|
||||||
objectslist = [objectslist]
|
objectslist = [objectslist]
|
||||||
|
@ -1170,7 +1165,7 @@ def draftify(objectslist,makeblock=False):
|
||||||
for obj in objectslist:
|
for obj in objectslist:
|
||||||
if obj.isDerivedFrom('Part::Feature'):
|
if obj.isDerivedFrom('Part::Feature'):
|
||||||
for w in obj.Shape.Wires:
|
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):
|
if (len(w.Edges) == 1) and isinstance(w.Edges[0].Curve,Part.Circle):
|
||||||
nobj = makeCircle(w.Edges[0])
|
nobj = makeCircle(w.Edges[0])
|
||||||
else:
|
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
|
with the given linewidth and fontsize (used if the given object contains
|
||||||
any text). You can also supply an arbitrary projection vector. the
|
any text). You can also supply an arbitrary projection vector. the
|
||||||
scale parameter allows to scale linewidths down, so they are resolution-independant.'''
|
scale parameter allows to scale linewidths down, so they are resolution-independant.'''
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
svg = ""
|
svg = ""
|
||||||
linewidth = linewidth/scale
|
linewidth = linewidth/scale
|
||||||
fontsize = (fontsize/scale)/2
|
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 isinstance(direction,FreeCAD.Vector):
|
||||||
if direction != Vector(0,0,0):
|
if direction != Vector(0,0,0):
|
||||||
plane = WorkingPlane.plane()
|
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):
|
elif isinstance(direction,WorkingPlane.plane):
|
||||||
plane = direction
|
plane = direction
|
||||||
|
|
||||||
|
@ -1240,10 +1234,10 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
||||||
|
|
||||||
def getProj(vec):
|
def getProj(vec):
|
||||||
if not plane: return vec
|
if not plane: return vec
|
||||||
nx = fcvec.project(vec,plane.u)
|
nx = DraftVecUtils.project(vec,plane.u)
|
||||||
lx = nx.Length
|
lx = nx.Length
|
||||||
if abs(nx.getAngle(plane.u)) > 0.1: lx = -lx
|
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
|
ly = ny.Length
|
||||||
if abs(ny.getAngle(plane.v)) > 0.1: ly = -ly
|
if abs(ny.getAngle(plane.v)) > 0.1: ly = -ly
|
||||||
return Vector(lx,ly,0)
|
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):
|
def getPath(edges):
|
||||||
svg ='<path id="' + name + '" '
|
svg ='<path id="' + name + '" '
|
||||||
edges = fcgeo.sortEdges(edges)
|
edges = DraftGeomUtils.sortEdges(edges)
|
||||||
v = getProj(edges[0].Vertexes[0].Point)
|
v = getProj(edges[0].Vertexes[0].Point)
|
||||||
svg += 'd="M '+ str(v.x) +' '+ str(v.y) + ' '
|
svg += 'd="M '+ str(v.x) +' '+ str(v.y) + ' '
|
||||||
for e in edges:
|
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)
|
vtext = m.multiply(plane.u)
|
||||||
else:
|
else:
|
||||||
vtext = m.multiply(Vector(1,0,0))
|
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 += 'd="M '+str(p1.x)+' '+str(p1.y)+' '
|
||||||
svg += 'L '+str(p2.x)+' '+str(p2.y)+' '
|
svg += 'L '+str(p2.x)+' '+str(p2.y)+' '
|
||||||
svg += 'L '+str(p3.x)+' '+str(p3.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:
|
else:
|
||||||
ts = (len(dimText)*obj.ViewObject.FontSize)/4
|
ts = (len(dimText)*obj.ViewObject.FontSize)/4
|
||||||
rm = ((p3.sub(p2)).Length/2)-ts
|
rm = ((p3.sub(p2)).Length/2)-ts
|
||||||
p2a = getProj(p2.add(fcvec.scaleTo(p3.sub(p2),rm)))
|
p2a = getProj(p2.add(DraftVecUtils.scaleTo(p3.sub(p2),rm)))
|
||||||
p2b = getProj(p3.add(fcvec.scaleTo(p2.sub(p3),rm)))
|
p2b = getProj(p3.add(DraftVecUtils.scaleTo(p2.sub(p3),rm)))
|
||||||
angle = 0
|
angle = 0
|
||||||
svg += 'd="M '+str(p1.x)+' '+str(p1.y)+' '
|
svg += 'd="M '+str(p1.x)+' '+str(p1.y)+' '
|
||||||
svg += 'L '+str(p2.x)+' '+str(p2.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)
|
wiredEdges.extend(w.Edges)
|
||||||
if len(wiredEdges) != len(obj.Shape.Edges):
|
if len(wiredEdges) != len(obj.Shape.Edges):
|
||||||
for e in obj.Shape.Edges:
|
for e in obj.Shape.Edges:
|
||||||
if (fcgeo.findEdge(e,wiredEdges) == None):
|
if (DraftGeomUtils.findEdge(e,wiredEdges) == None):
|
||||||
svg += getPath([e])
|
svg += getPath([e])
|
||||||
else:
|
else:
|
||||||
svg = getCircle(obj.Shape.Edges[0])
|
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
|
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
|
and circles. If addTo is an existing sketch, geometry will be added to it instead of
|
||||||
creating a new one.'''
|
creating a new one.'''
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
from Sketcher import Constraint
|
from Sketcher import Constraint
|
||||||
|
|
||||||
StartPoint = 1
|
StartPoint = 1
|
||||||
|
@ -1558,18 +1551,18 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
|
||||||
segs = range(last-len(obj.Shape.Edges),last-1)
|
segs = range(last-len(obj.Shape.Edges),last-1)
|
||||||
for seg in segs:
|
for seg in segs:
|
||||||
nobj.addConstraint(Constraint("Coincident",seg,EndPoint,seg+1,StartPoint))
|
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))
|
nobj.addConstraint(Constraint("Vertical",seg))
|
||||||
elif fcgeo.isAligned(nobj.Geometry[seg],"y"):
|
elif DraftGeomUtils.isAligned(nobj.Geometry[seg],"y"):
|
||||||
nobj.addConstraint(Constraint("Horizontal",seg))
|
nobj.addConstraint(Constraint("Horizontal",seg))
|
||||||
if closed:
|
if closed:
|
||||||
nobj.addConstraint(Constraint("Coincident",last-1,EndPoint,segs[0],StartPoint))
|
nobj.addConstraint(Constraint("Coincident",last-1,EndPoint,segs[0],StartPoint))
|
||||||
ok = True
|
ok = True
|
||||||
if (not ok) and obj.isDerivedFrom("Part::Feature"):
|
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 w in obj.Shape.Wires:
|
||||||
for edge in fcgeo.sortEdges(w.Edges):
|
for edge in DraftGeomUtils.sortEdges(w.Edges):
|
||||||
g = fcgeo.geom(edge)
|
g = DraftGeomUtils.geom(edge)
|
||||||
if g:
|
if g:
|
||||||
nobj.addGeometry(g)
|
nobj.addGeometry(g)
|
||||||
if autoconstraints:
|
if autoconstraints:
|
||||||
|
@ -1577,20 +1570,20 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
|
||||||
segs = range(last-len(w.Edges),last-1)
|
segs = range(last-len(w.Edges),last-1)
|
||||||
for seg in segs:
|
for seg in segs:
|
||||||
nobj.addConstraint(Constraint("Coincident",seg,EndPoint,seg+1,StartPoint))
|
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))
|
nobj.addConstraint(Constraint("Vertical",seg))
|
||||||
elif fcgeo.isAligned(nobj.Geometry[seg],"y"):
|
elif DraftGeomUtils.isAligned(nobj.Geometry[seg],"y"):
|
||||||
nobj.addConstraint(Constraint("Horizontal",seg))
|
nobj.addConstraint(Constraint("Horizontal",seg))
|
||||||
if w.isClosed:
|
if w.isClosed:
|
||||||
nobj.addConstraint(Constraint("Coincident",last-1,EndPoint,segs[0],StartPoint))
|
nobj.addConstraint(Constraint("Coincident",last-1,EndPoint,segs[0],StartPoint))
|
||||||
else:
|
else:
|
||||||
for edge in obj.Shape.Edges:
|
for edge in obj.Shape.Edges:
|
||||||
nobj.addGeometry(fcgeo.geom(edge))
|
nobj.addGeometry(DraftGeomUtils.geom(edge))
|
||||||
if autoconstraints:
|
if autoconstraints:
|
||||||
last = nobj.GeometryCount - 1
|
last = nobj.GeometryCount - 1
|
||||||
if fcgeo.isAligned(nobj.Geometry[last],"x"):
|
if DraftGeomUtils.isAligned(nobj.Geometry[last],"x"):
|
||||||
nobj.addConstraint(Constraint("Vertical",last))
|
nobj.addConstraint(Constraint("Vertical",last))
|
||||||
elif fcgeo.isAligned(nobj.Geometry[last],"y"):
|
elif DraftGeomUtils.isAligned(nobj.Geometry[last],"y"):
|
||||||
nobj.addConstraint(Constraint("Horizontal",last))
|
nobj.addConstraint(Constraint("Horizontal",last))
|
||||||
ok = True
|
ok = True
|
||||||
if ok:
|
if ok:
|
||||||
|
@ -1793,45 +1786,44 @@ class _ViewProviderDimension:
|
||||||
obj.Override = ''
|
obj.Override = ''
|
||||||
|
|
||||||
def calcGeom(self,obj):
|
def calcGeom(self,obj):
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
p1 = obj.Start
|
p1 = obj.Start
|
||||||
p4 = obj.End
|
p4 = obj.End
|
||||||
base = Part.Line(p1,p4).toShape()
|
base = Part.Line(p1,p4).toShape()
|
||||||
proj = fcgeo.findDistance(obj.Dimline,base)
|
proj = DraftGeomUtils.findDistance(obj.Dimline,base)
|
||||||
if not proj:
|
if not proj:
|
||||||
p2 = p1
|
p2 = p1
|
||||||
p3 = p4
|
p3 = p4
|
||||||
else:
|
else:
|
||||||
p2 = p1.add(fcvec.neg(proj))
|
p2 = p1.add(DraftVecUtils.neg(proj))
|
||||||
p3 = p4.add(fcvec.neg(proj))
|
p3 = p4.add(DraftVecUtils.neg(proj))
|
||||||
dmax = obj.ViewObject.ExtLines
|
dmax = obj.ViewObject.ExtLines
|
||||||
if dmax and (proj.Length > dmax):
|
if dmax and (proj.Length > dmax):
|
||||||
p1 = p2.add(fcvec.scaleTo(proj,dmax))
|
p1 = p2.add(DraftVecUtils.scaleTo(proj,dmax))
|
||||||
p4 = p3.add(fcvec.scaleTo(proj,dmax))
|
p4 = p3.add(DraftVecUtils.scaleTo(proj,dmax))
|
||||||
midpoint = p2.add(fcvec.scale(p3.sub(p2),0.5))
|
midpoint = p2.add(DraftVecUtils.scale(p3.sub(p2),0.5))
|
||||||
if not proj:
|
if not proj:
|
||||||
ed = fcgeo.vec(base)
|
ed = DraftGeomUtils.vec(base)
|
||||||
proj = ed.cross(Vector(0,0,1))
|
proj = ed.cross(Vector(0,0,1))
|
||||||
if not proj: norm = Vector(0,0,1)
|
if not proj: norm = Vector(0,0,1)
|
||||||
else: norm = fcvec.neg(p3.sub(p2).cross(proj))
|
else: norm = DraftVecUtils.neg(p3.sub(p2).cross(proj))
|
||||||
if not fcvec.isNull(norm):
|
if not DraftVecUtils.isNull(norm):
|
||||||
norm.normalize()
|
norm.normalize()
|
||||||
va = get3DView().getViewDirection()
|
va = get3DView().getViewDirection()
|
||||||
if va.getAngle(norm) < math.pi/2:
|
if va.getAngle(norm) < math.pi/2:
|
||||||
norm = fcvec.neg(norm)
|
norm = DraftVecUtils.neg(norm)
|
||||||
u = p3.sub(p2)
|
u = p3.sub(p2)
|
||||||
u.normalize()
|
u.normalize()
|
||||||
c = get3DView().getCameraNode()
|
c = get3DView().getCameraNode()
|
||||||
r = c.orientation.getValue()
|
r = c.orientation.getValue()
|
||||||
ru = Vector(r.multVec(coin.SbVec3f(1,0,0)).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)
|
v = norm.cross(u)
|
||||||
offset = fcvec.scaleTo(v,obj.ViewObject.FontSize*.2)
|
offset = DraftVecUtils.scaleTo(v,obj.ViewObject.FontSize*.2)
|
||||||
if obj.ViewObject:
|
if obj.ViewObject:
|
||||||
if hasattr(obj.ViewObject,"DisplayMode"):
|
if hasattr(obj.ViewObject,"DisplayMode"):
|
||||||
if obj.ViewObject.DisplayMode == "3D":
|
if obj.ViewObject.DisplayMode == "3D":
|
||||||
offset = fcvec.neg(offset)
|
offset = DraftVecUtils.neg(offset)
|
||||||
if hasattr(obj.ViewObject,"TextPosition"):
|
if hasattr(obj.ViewObject,"TextPosition"):
|
||||||
if obj.ViewObject.TextPosition == Vector(0,0,0):
|
if obj.ViewObject.TextPosition == Vector(0,0,0):
|
||||||
tbase = midpoint.add(offset)
|
tbase = midpoint.add(offset)
|
||||||
|
@ -1839,7 +1831,7 @@ class _ViewProviderDimension:
|
||||||
tbase = obj.ViewObject.TextPosition
|
tbase = obj.ViewObject.TextPosition
|
||||||
else:
|
else:
|
||||||
tbase = midpoint.add(offset)
|
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
|
return p1,p2,p3,p4,tbase,norm,rot
|
||||||
|
|
||||||
def attach(self, obj):
|
def attach(self, obj):
|
||||||
|
@ -1858,7 +1850,7 @@ class _ViewProviderDimension:
|
||||||
self.text.string = self.text3d.string = ''
|
self.text.string = self.text3d.string = ''
|
||||||
self.textpos = coin.SoTransform()
|
self.textpos = coin.SoTransform()
|
||||||
self.textpos.translation.setValue([tbase.x,tbase.y,tbase.z])
|
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()
|
rm = coin.SbRotation()
|
||||||
self.textpos.rotation = rm
|
self.textpos.rotation = rm
|
||||||
label = coin.SoSeparator()
|
label = coin.SoSeparator()
|
||||||
|
@ -1917,11 +1909,11 @@ class _ViewProviderDimension:
|
||||||
# arc linked dimension
|
# arc linked dimension
|
||||||
e = obj.Base.Shape.Edges[obj.LinkedVertices[0]]
|
e = obj.Base.Shape.Edges[obj.LinkedVertices[0]]
|
||||||
c = e.Curve.Center
|
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:
|
if obj.LinkedVertices[1] == 1:
|
||||||
v1 = c
|
v1 = c
|
||||||
else:
|
else:
|
||||||
v1 = c.add(fcvec.neg(bray))
|
v1 = c.add(DraftVecUtils.neg(bray))
|
||||||
v2 = c.add(bray)
|
v2 = c.add(bray)
|
||||||
else:
|
else:
|
||||||
# linear linked dimension
|
# linear linked dimension
|
||||||
|
@ -1952,8 +1944,8 @@ class _ViewProviderDimension:
|
||||||
else:
|
else:
|
||||||
ts = (len(text)*obj.ViewObject.FontSize)/4
|
ts = (len(text)*obj.ViewObject.FontSize)/4
|
||||||
rm = ((p3.sub(p2)).Length/2)-ts
|
rm = ((p3.sub(p2)).Length/2)-ts
|
||||||
p2a = p2.add(fcvec.scaleTo(p3.sub(p2),rm))
|
p2a = p2.add(DraftVecUtils.scaleTo(p3.sub(p2),rm))
|
||||||
p2b = p3.add(fcvec.scaleTo(p2.sub(p3),rm))
|
p2b = p3.add(DraftVecUtils.scaleTo(p2.sub(p3),rm))
|
||||||
self.coords.point.setValues([[p1.x,p1.y,p1.z],
|
self.coords.point.setValues([[p1.x,p1.y,p1.z],
|
||||||
[p2.x,p2.y,p2.z],
|
[p2.x,p2.y,p2.z],
|
||||||
[p2a.x,p2a.y,p2a.z],
|
[p2a.x,p2a.y,p2a.z],
|
||||||
|
@ -2149,15 +2141,14 @@ class _ViewProviderAngularDimension:
|
||||||
self.onChanged(vobj,"FontName")
|
self.onChanged(vobj,"FontName")
|
||||||
|
|
||||||
def calcGeom(self,obj):
|
def calcGeom(self,obj):
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
rad = (obj.Dimline.sub(obj.Center)).Length
|
rad = (obj.Dimline.sub(obj.Center)).Length
|
||||||
cir = Part.makeCircle(rad,obj.Center,Vector(0,0,1),obj.FirstAngle,obj.LastAngle)
|
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 = 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)
|
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):
|
if (trot > math.pi/2) or (trot < -math.pi/2):
|
||||||
trot = trot + math.pi
|
trot = trot + math.pi
|
||||||
s = getParam("dimorientation")
|
s = getParam("dimorientation")
|
||||||
|
@ -2276,8 +2267,7 @@ class _Rectangle:
|
||||||
self.createGeometry(fp)
|
self.createGeometry(fp)
|
||||||
|
|
||||||
def createGeometry(self,fp):
|
def createGeometry(self,fp):
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
plm = fp.Placement
|
plm = fp.Placement
|
||||||
p1 = Vector(0,0,0)
|
p1 = Vector(0,0,0)
|
||||||
p2 = Vector(p1.x+fp.Length,p1.y,p1.z)
|
p2 = Vector(p1.x+fp.Length,p1.y,p1.z)
|
||||||
|
@ -2286,7 +2276,7 @@ class _Rectangle:
|
||||||
shape = Part.makePolygon([p1,p2,p3,p4,p1])
|
shape = Part.makePolygon([p1,p2,p3,p4,p1])
|
||||||
if "FilletRadius" in fp.PropertiesList:
|
if "FilletRadius" in fp.PropertiesList:
|
||||||
if fp.FilletRadius != 0:
|
if fp.FilletRadius != 0:
|
||||||
w = fcgeo.filletWire(shape,fp.FilletRadius)
|
w = DraftGeomUtils.filletWire(shape,fp.FilletRadius)
|
||||||
if w:
|
if w:
|
||||||
shape = w
|
shape = w
|
||||||
shape = Part.Face(shape)
|
shape = Part.Face(shape)
|
||||||
|
@ -2399,8 +2389,7 @@ class _Wire:
|
||||||
fp.Points = pts
|
fp.Points = pts
|
||||||
|
|
||||||
def createGeometry(self,fp):
|
def createGeometry(self,fp):
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
plm = fp.Placement
|
plm = fp.Placement
|
||||||
if fp.Base and (not fp.Tool):
|
if fp.Base and (not fp.Tool):
|
||||||
if fp.Base.isDerivedFrom("Sketcher::SketchObject"):
|
if fp.Base.isDerivedFrom("Sketcher::SketchObject"):
|
||||||
|
@ -2416,8 +2405,8 @@ class _Wire:
|
||||||
sh1 = fp.Base.Shape.copy()
|
sh1 = fp.Base.Shape.copy()
|
||||||
sh2 = fp.Tool.Shape.copy()
|
sh2 = fp.Tool.Shape.copy()
|
||||||
shape = sh1.fuse(sh2)
|
shape = sh1.fuse(sh2)
|
||||||
if fcgeo.isCoplanar(shape.Faces):
|
if DraftGeomUtils.isCoplanar(shape.Faces):
|
||||||
shape = fcgeo.concatenate(shape)
|
shape = DraftGeomUtils.concatenate(shape)
|
||||||
fp.Shape = shape
|
fp.Shape = shape
|
||||||
p = []
|
p = []
|
||||||
for v in shape.Vertexes: p.append(v.Point)
|
for v in shape.Vertexes: p.append(v.Point)
|
||||||
|
@ -2430,7 +2419,7 @@ class _Wire:
|
||||||
shape = Part.makePolygon(fp.Points+[fp.Points[0]])
|
shape = Part.makePolygon(fp.Points+[fp.Points[0]])
|
||||||
if "FilletRadius" in fp.PropertiesList:
|
if "FilletRadius" in fp.PropertiesList:
|
||||||
if fp.FilletRadius != 0:
|
if fp.FilletRadius != 0:
|
||||||
w = fcgeo.filletWire(shape,fp.FilletRadius)
|
w = DraftGeomUtils.filletWire(shape,fp.FilletRadius)
|
||||||
if w:
|
if w:
|
||||||
shape = w
|
shape = w
|
||||||
shape = Part.Face(shape)
|
shape = Part.Face(shape)
|
||||||
|
@ -2444,7 +2433,7 @@ class _Wire:
|
||||||
shape = Part.Wire(edges)
|
shape = Part.Wire(edges)
|
||||||
if "FilletRadius" in fp.PropertiesList:
|
if "FilletRadius" in fp.PropertiesList:
|
||||||
if fp.FilletRadius != 0:
|
if fp.FilletRadius != 0:
|
||||||
w = fcgeo.filletWire(shape,fp.FilletRadius)
|
w = DraftGeomUtils.filletWire(shape,fp.FilletRadius)
|
||||||
if w:
|
if w:
|
||||||
shape = w
|
shape = w
|
||||||
fp.Shape = shape
|
fp.Shape = shape
|
||||||
|
@ -2510,8 +2499,7 @@ class _Polygon:
|
||||||
self.createGeometry(fp)
|
self.createGeometry(fp)
|
||||||
|
|
||||||
def createGeometry(self,fp):
|
def createGeometry(self,fp):
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
plm = fp.Placement
|
plm = fp.Placement
|
||||||
angle = (math.pi*2)/fp.FacesNumber
|
angle = (math.pi*2)/fp.FacesNumber
|
||||||
if fp.DrawMode == 'inscribed':
|
if fp.DrawMode == 'inscribed':
|
||||||
|
@ -2526,7 +2514,7 @@ class _Polygon:
|
||||||
shape = Part.makePolygon(pts)
|
shape = Part.makePolygon(pts)
|
||||||
if "FilletRadius" in fp.PropertiesList:
|
if "FilletRadius" in fp.PropertiesList:
|
||||||
if fp.FilletRadius != 0:
|
if fp.FilletRadius != 0:
|
||||||
w = fcgeo.filletWire(shape,fp.FilletRadius)
|
w = DraftGeomUtils.filletWire(shape,fp.FilletRadius)
|
||||||
if w:
|
if w:
|
||||||
shape = w
|
shape = w
|
||||||
shape = Part.Face(shape)
|
shape = Part.Face(shape)
|
||||||
|
@ -2690,16 +2678,15 @@ class _Shape2DView:
|
||||||
self.createGeometry(obj)
|
self.createGeometry(obj)
|
||||||
|
|
||||||
def createGeometry(self,obj):
|
def createGeometry(self,obj):
|
||||||
import Drawing
|
import Drawing, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
pl = obj.Placement
|
pl = obj.Placement
|
||||||
if obj.Base:
|
if obj.Base:
|
||||||
if obj.Base.isDerivedFrom("Part::Feature"):
|
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)
|
[visibleG0,visibleG1,hiddenG0,hiddenG1] = Drawing.project(obj.Base.Shape,obj.Projection)
|
||||||
if visibleG0:
|
if visibleG0:
|
||||||
obj.Shape = visibleG0
|
obj.Shape = visibleG0
|
||||||
if not fcgeo.isNull(pl):
|
if not DraftGeomUtils.isNull(pl):
|
||||||
obj.Placement = pl
|
obj.Placement = pl
|
||||||
|
|
||||||
class _Array:
|
class _Array:
|
||||||
|
@ -2745,7 +2732,7 @@ class _Array:
|
||||||
self.createGeometry(obj)
|
self.createGeometry(obj)
|
||||||
|
|
||||||
def createGeometry(self,obj):
|
def createGeometry(self,obj):
|
||||||
from draftlibs import fcgeo
|
import DraftGeomUtils
|
||||||
if obj.Base:
|
if obj.Base:
|
||||||
pl = obj.Placement
|
pl = obj.Placement
|
||||||
if obj.ArrayType == "ortho":
|
if obj.ArrayType == "ortho":
|
||||||
|
@ -2753,21 +2740,21 @@ class _Array:
|
||||||
else:
|
else:
|
||||||
sh = self.polarArray(obj.Base.Shape,obj.Center,obj.Angle,obj.NumberPolar,obj.Axis)
|
sh = self.polarArray(obj.Base.Shape,obj.Center,obj.Angle,obj.NumberPolar,obj.Axis)
|
||||||
obj.Shape = sh
|
obj.Shape = sh
|
||||||
if not fcgeo.isNull(pl):
|
if not DraftGeomUtils.isNull(pl):
|
||||||
obj.Placement = pl
|
obj.Placement = pl
|
||||||
|
|
||||||
def rectArray(self,shape,xvector,yvector,xnum,ynum):
|
def rectArray(self,shape,xvector,yvector,xnum,ynum):
|
||||||
import Part
|
import Part
|
||||||
base = [shape.copy()]
|
base = [shape.copy()]
|
||||||
for xcount in range(xnum):
|
for xcount in range(xnum):
|
||||||
currentxvector=fcvec.scale(xvector,xcount)
|
currentxvector=DraftVecUtils.scale(xvector,xcount)
|
||||||
if not xcount==0:
|
if not xcount==0:
|
||||||
nshape = shape.copy()
|
nshape = shape.copy()
|
||||||
nshape.translate(currentxvector)
|
nshape.translate(currentxvector)
|
||||||
base.append(nshape)
|
base.append(nshape)
|
||||||
for ycount in range(ynum):
|
for ycount in range(ynum):
|
||||||
currentxvector=FreeCAD.Vector(currentxvector)
|
currentxvector=FreeCAD.Vector(currentxvector)
|
||||||
currentyvector=currentxvector.add(fcvec.scale(yvector,ycount))
|
currentyvector=currentxvector.add(DraftVecUtils.scale(yvector,ycount))
|
||||||
if not ycount==0:
|
if not ycount==0:
|
||||||
nshape = shape.copy()
|
nshape = shape.copy()
|
||||||
nshape.translate(currentyvector)
|
nshape.translate(currentyvector)
|
||||||
|
@ -2781,7 +2768,7 @@ class _Array:
|
||||||
for i in range(num):
|
for i in range(num):
|
||||||
currangle = fraction + (i*fraction)
|
currangle = fraction + (i*fraction)
|
||||||
nshape = shape.copy()
|
nshape = shape.copy()
|
||||||
nshape.rotate(fcvec.tup(center), fcvec.tup(axis), currangle)
|
nshape.rotate(DraftVecUtils.tup(center), DraftVecUtils.tup(axis), currangle)
|
||||||
base.append(nshape)
|
base.append(nshape)
|
||||||
return Part.makeCompound(base)
|
return Part.makeCompound(base)
|
||||||
|
|
||||||
|
@ -2845,8 +2832,7 @@ class _Clone:
|
||||||
self.createGeometry(obj)
|
self.createGeometry(obj)
|
||||||
|
|
||||||
def createGeometry(self,obj):
|
def createGeometry(self,obj):
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
pl = obj.Placement
|
pl = obj.Placement
|
||||||
shapes = []
|
shapes = []
|
||||||
for o in obj.Objects:
|
for o in obj.Objects:
|
||||||
|
@ -2859,7 +2845,7 @@ class _Clone:
|
||||||
shapes.append(sh)
|
shapes.append(sh)
|
||||||
if shapes:
|
if shapes:
|
||||||
obj.Shape = Part.makeCompound(shapes)
|
obj.Shape = Part.makeCompound(shapes)
|
||||||
if not fcgeo.isNull(pl):
|
if not DraftGeomUtils.isNull(pl):
|
||||||
obj.Placement = pl
|
obj.Placement = pl
|
||||||
|
|
||||||
class _ViewProviderDraftPart(_ViewProviderDraft):
|
class _ViewProviderDraftPart(_ViewProviderDraft):
|
||||||
|
|
|
@ -26,9 +26,8 @@ __author__ = "Yorik van Havre"
|
||||||
__url__ = "http://free-cad.sourceforge.net"
|
__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 DraftGui import todo,getMainWindow
|
||||||
from draftlibs import fcvec
|
|
||||||
from FreeCAD import Vector
|
from FreeCAD import Vector
|
||||||
from pivy import coin
|
from pivy import coin
|
||||||
from PyQt4 import QtCore,QtGui
|
from PyQt4 import QtCore,QtGui
|
||||||
|
@ -110,9 +109,8 @@ class Snapper:
|
||||||
be True to constrain the point against the closest working plane axis.
|
be True to constrain the point against the closest working plane axis.
|
||||||
Screenpos can be a list, a tuple or a coin.SbVec2s object."""
|
Screenpos can be a list, a tuple or a coin.SbVec2s object."""
|
||||||
|
|
||||||
global Part,fcgeo
|
global Part, DraftGeomUtils
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
|
|
||||||
if not hasattr(self,"toolbar"):
|
if not hasattr(self,"toolbar"):
|
||||||
self.makeSnapToolBar()
|
self.makeSnapToolBar()
|
||||||
|
@ -355,7 +353,7 @@ class Snapper:
|
||||||
for e in edges:
|
for e in edges:
|
||||||
if isinstance(e.Curve,Part.Line):
|
if isinstance(e.Curve,Part.Line):
|
||||||
np = self.getPerpendicular(e,point)
|
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 (np.sub(point)).Length < self.radius:
|
||||||
if self.isEnabled('extension'):
|
if self.isEnabled('extension'):
|
||||||
if np != e.Vertexes[0].Point:
|
if np != e.Vertexes[0].Point:
|
||||||
|
@ -372,7 +370,7 @@ class Snapper:
|
||||||
else:
|
else:
|
||||||
if self.isEnabled('parallel'):
|
if self.isEnabled('parallel'):
|
||||||
if last:
|
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)
|
np = self.getPerpendicular(de,point)
|
||||||
if (np.sub(point)).Length < self.radius:
|
if (np.sub(point)).Length < self.radius:
|
||||||
if self.tracker:
|
if self.tracker:
|
||||||
|
@ -398,13 +396,13 @@ class Snapper:
|
||||||
FreeCAD.Vector(0,0,1)]
|
FreeCAD.Vector(0,0,1)]
|
||||||
for a in self.polarAngles:
|
for a in self.polarAngles:
|
||||||
if a == 90:
|
if a == 90:
|
||||||
vecs.extend([ax[0],fcvec.neg(ax[0])])
|
vecs.extend([ax[0],DraftVecUtils.neg(ax[0])])
|
||||||
vecs.extend([ax[1],fcvec.neg(ax[1])])
|
vecs.extend([ax[1],DraftVecUtils.neg(ax[1])])
|
||||||
else:
|
else:
|
||||||
v = fcvec.rotate(ax[0],math.radians(a),ax[2])
|
v = DraftVecUtils.rotate(ax[0],math.radians(a),ax[2])
|
||||||
vecs.extend([v,fcvec.neg(v)])
|
vecs.extend([v,DraftVecUtils.neg(v)])
|
||||||
v = fcvec.rotate(ax[1],math.radians(a),ax[2])
|
v = DraftVecUtils.rotate(ax[1],math.radians(a),ax[2])
|
||||||
vecs.extend([v,fcvec.neg(v)])
|
vecs.extend([v,DraftVecUtils.neg(v)])
|
||||||
for v in vecs:
|
for v in vecs:
|
||||||
de = Part.Line(last,last.add(v)).toShape()
|
de = Part.Line(last,last.add(v)).toShape()
|
||||||
np = self.getPerpendicular(de,point)
|
np = self.getPerpendicular(de,point)
|
||||||
|
@ -457,7 +455,7 @@ class Snapper:
|
||||||
snaps = []
|
snaps = []
|
||||||
if self.isEnabled("midpoint"):
|
if self.isEnabled("midpoint"):
|
||||||
if isinstance(shape,Part.Edge):
|
if isinstance(shape,Part.Edge):
|
||||||
mp = fcgeo.findMidpoint(shape)
|
mp = DraftGeomUtils.findMidpoint(shape)
|
||||||
if mp:
|
if mp:
|
||||||
snaps.append([mp,'midpoint',mp])
|
snaps.append([mp,'midpoint',mp])
|
||||||
return snaps
|
return snaps
|
||||||
|
@ -472,7 +470,7 @@ class Snapper:
|
||||||
np = self.getPerpendicular(shape,last)
|
np = self.getPerpendicular(shape,last)
|
||||||
elif isinstance(shape.Curve,Part.Circle):
|
elif isinstance(shape.Curve,Part.Circle):
|
||||||
dv = last.sub(shape.Curve.Center)
|
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)
|
np = (shape.Curve.Center).add(dv)
|
||||||
elif isinstance(shape.Curve,Part.BSplineCurve):
|
elif isinstance(shape.Curve,Part.BSplineCurve):
|
||||||
pr = shape.Curve.parameter(last)
|
pr = shape.Curve.parameter(last)
|
||||||
|
@ -493,7 +491,7 @@ class Snapper:
|
||||||
if self.constraintAxis:
|
if self.constraintAxis:
|
||||||
tmpEdge = Part.Line(last,last.add(self.constraintAxis)).toShape()
|
tmpEdge = Part.Line(last,last.add(self.constraintAxis)).toShape()
|
||||||
# get the intersection points
|
# get the intersection points
|
||||||
pt = fcgeo.findIntersection(tmpEdge,shape,True,True)
|
pt = DraftGeomUtils.findIntersection(tmpEdge,shape,True,True)
|
||||||
if pt:
|
if pt:
|
||||||
for p in pt:
|
for p in pt:
|
||||||
snaps.append([p,'ortho',p])
|
snaps.append([p,'ortho',p])
|
||||||
|
@ -506,14 +504,14 @@ class Snapper:
|
||||||
tmpEdge1 = Part.Line(last,last.add(self.constraintAxis)).toShape()
|
tmpEdge1 = Part.Line(last,last.add(self.constraintAxis)).toShape()
|
||||||
tmpEdge2 = Part.Line(self.extLine.p1(),self.extLine.p2()).toShape()
|
tmpEdge2 = Part.Line(self.extLine.p1(),self.extLine.p2()).toShape()
|
||||||
# get the intersection points
|
# get the intersection points
|
||||||
pt = fcgeo.findIntersection(tmpEdge1,tmpEdge2,True,True)
|
pt = DraftGeomUtils.findIntersection(tmpEdge1,tmpEdge2,True,True)
|
||||||
if pt:
|
if pt:
|
||||||
return [pt[0],'ortho',pt[0]]
|
return [pt[0],'ortho',pt[0]]
|
||||||
if eline:
|
if eline:
|
||||||
try:
|
try:
|
||||||
tmpEdge2 = Part.Line(self.extLine.p1(),self.extLine.p2()).toShape()
|
tmpEdge2 = Part.Line(self.extLine.p1(),self.extLine.p2()).toShape()
|
||||||
# get the intersection points
|
# get the intersection points
|
||||||
pt = fcgeo.findIntersection(eline,tmpEdge2,True,True)
|
pt = DraftGeomUtils.findIntersection(eline,tmpEdge2,True,True)
|
||||||
if pt:
|
if pt:
|
||||||
return [pt[0],'ortho',pt[0]]
|
return [pt[0],'ortho',pt[0]]
|
||||||
except:
|
except:
|
||||||
|
@ -526,7 +524,7 @@ class Snapper:
|
||||||
if self.isEnabled("intersection") and self.isEnabled("extension"):
|
if self.isEnabled("intersection") and self.isEnabled("extension"):
|
||||||
if e1 and e2:
|
if e1 and e2:
|
||||||
# get the intersection points
|
# get the intersection points
|
||||||
pts = fcgeo.findIntersection(e1,e2,True,True)
|
pts = DraftGeomUtils.findIntersection(e1,e2,True,True)
|
||||||
if pts:
|
if pts:
|
||||||
for p in pts:
|
for p in pts:
|
||||||
snaps.append([p,'intersection',p])
|
snaps.append([p,'intersection',p])
|
||||||
|
@ -569,7 +567,7 @@ class Snapper:
|
||||||
if (not self.maxEdges) or (len(obj.Shape.Edges) <= self.maxEdges):
|
if (not self.maxEdges) or (len(obj.Shape.Edges) <= self.maxEdges):
|
||||||
for e in obj.Shape.Edges:
|
for e in obj.Shape.Edges:
|
||||||
# get the intersection points
|
# get the intersection points
|
||||||
pt = fcgeo.findIntersection(e,shape)
|
pt = DraftGeomUtils.findIntersection(e,shape)
|
||||||
if pt:
|
if pt:
|
||||||
for p in pt:
|
for p in pt:
|
||||||
snaps.append([p,'intersection',p])
|
snaps.append([p,'intersection',p])
|
||||||
|
@ -597,7 +595,7 @@ class Snapper:
|
||||||
def getPerpendicular(self,edge,pt):
|
def getPerpendicular(self,edge,pt):
|
||||||
"returns a point on an edge, perpendicular to the given point"
|
"returns a point on an edge, perpendicular to the given point"
|
||||||
dv = pt.sub(edge.Vertexes[0].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)
|
np = (edge.Vertexes[0].Point).add(nv)
|
||||||
return np
|
return np
|
||||||
|
|
||||||
|
@ -690,7 +688,7 @@ class Snapper:
|
||||||
self.constraintAxis = FreeCAD.DraftWorkingPlane.axis
|
self.constraintAxis = FreeCAD.DraftWorkingPlane.axis
|
||||||
|
|
||||||
# calculating constrained point
|
# calculating constrained point
|
||||||
cdelta = fcvec.project(delta,self.constraintAxis)
|
cdelta = DraftVecUtils.project(delta,self.constraintAxis)
|
||||||
npoint = self.basepoint.add(cdelta)
|
npoint = self.basepoint.add(cdelta)
|
||||||
|
|
||||||
# setting constrain line
|
# setting constrain line
|
||||||
|
|
|
@ -29,9 +29,8 @@ __url__ = "http://free-cad.sourceforge.net"
|
||||||
# Generic stuff
|
# 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 functools import partial
|
||||||
from draftlibs import fcvec
|
|
||||||
from FreeCAD import Vector
|
from FreeCAD import Vector
|
||||||
from DraftGui import todo,QtCore,QtGui
|
from DraftGui import todo,QtCore,QtGui
|
||||||
from DraftSnap import *
|
from DraftSnap import *
|
||||||
|
@ -283,7 +282,7 @@ class SelectPlane:
|
||||||
self.display('side')
|
self.display('side')
|
||||||
self.finish()
|
self.finish()
|
||||||
elif arg == "currentView":
|
elif arg == "currentView":
|
||||||
viewDirection = fcvec.neg(self.view.getViewDirection())
|
viewDirection = DraftVecUtils.neg(self.view.getViewDirection())
|
||||||
plane.alignToPointAndAxis(Vector(0,0,0), viewDirection, self.offset)
|
plane.alignToPointAndAxis(Vector(0,0,0), viewDirection, self.offset)
|
||||||
self.display(viewDirection)
|
self.display(viewDirection)
|
||||||
self.finish()
|
self.finish()
|
||||||
|
@ -327,9 +326,8 @@ class Creator:
|
||||||
def Activated(self,name="None"):
|
def Activated(self,name="None"):
|
||||||
if FreeCAD.activeDraftCommand:
|
if FreeCAD.activeDraftCommand:
|
||||||
FreeCAD.activeDraftCommand.finish()
|
FreeCAD.activeDraftCommand.finish()
|
||||||
global Part, fcgeo
|
global Part, DraftGeomUtils
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
self.ui = None
|
self.ui = None
|
||||||
self.call = None
|
self.call = None
|
||||||
self.doc = None
|
self.doc = None
|
||||||
|
@ -348,7 +346,7 @@ class Creator:
|
||||||
self.ui.show()
|
self.ui.show()
|
||||||
rot = self.view.getCameraNode().getField("orientation").getValue()
|
rot = self.view.getCameraNode().getField("orientation").getValue()
|
||||||
upv = Vector(rot.multVec(coin.SbVec3f(0,1,0)).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.node = []
|
||||||
self.pos = []
|
self.pos = []
|
||||||
self.constrain = None
|
self.constrain = None
|
||||||
|
@ -721,12 +719,12 @@ class Rectangle(Creator):
|
||||||
p1 = self.node[0]
|
p1 = self.node[0]
|
||||||
p3 = self.node[-1]
|
p3 = self.node[-1]
|
||||||
diagonal = p3.sub(p1)
|
diagonal = p3.sub(p1)
|
||||||
p2 = p1.add(fcvec.project(diagonal, plane.v))
|
p2 = p1.add(DraftVecUtils.project(diagonal, plane.v))
|
||||||
p4 = p1.add(fcvec.project(diagonal, plane.u))
|
p4 = p1.add(DraftVecUtils.project(diagonal, plane.u))
|
||||||
length = p4.sub(p1).Length
|
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
|
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 = plane.getRotation()
|
||||||
p.move(p1)
|
p.move(p1)
|
||||||
try:
|
try:
|
||||||
|
@ -847,10 +845,10 @@ class Arc(Creator):
|
||||||
point,ctrlPoint,info = getPoint(self,arg)
|
point,ctrlPoint,info = getPoint(self,arg)
|
||||||
# this is to make sure radius is what you see on screen
|
# this is to make sure radius is what you see on screen
|
||||||
self.ui.cross(True)
|
self.ui.cross(True)
|
||||||
if self.center and fcvec.dist(point,self.center) > 0:
|
if self.center and DraftVecUtils.dist(point,self.center) > 0:
|
||||||
viewdelta = fcvec.project(point.sub(self.center), plane.axis)
|
viewdelta = DraftVecUtils.project(point.sub(self.center), plane.axis)
|
||||||
if not fcvec.isNull(viewdelta):
|
if not DraftVecUtils.isNull(viewdelta):
|
||||||
point = point.add(fcvec.neg(viewdelta))
|
point = point.add(DraftVecUtils.neg(viewdelta))
|
||||||
if (self.step == 0): # choose center
|
if (self.step == 0): # choose center
|
||||||
if hasMod(arg,MODALT):
|
if hasMod(arg,MODALT):
|
||||||
if not self.altdown:
|
if not self.altdown:
|
||||||
|
@ -864,12 +862,12 @@ class Arc(Creator):
|
||||||
self.ui.switchUi(False)
|
self.ui.switchUi(False)
|
||||||
elif (self.step == 1): # choose radius
|
elif (self.step == 1): # choose radius
|
||||||
if len(self.tangents) == 2:
|
if len(self.tangents) == 2:
|
||||||
cir = fcgeo.circleFrom2tan1pt(self.tangents[0], self.tangents[1], point)
|
cir = DraftGeomUtils.circleFrom2tan1pt(self.tangents[0], self.tangents[1], point)
|
||||||
self.center = fcgeo.findClosestCircle(point,cir).Center
|
self.center = DraftGeomUtils.findClosestCircle(point,cir).Center
|
||||||
self.arctrack.setCenter(self.center)
|
self.arctrack.setCenter(self.center)
|
||||||
elif self.tangents and self.tanpoints:
|
elif self.tangents and self.tanpoints:
|
||||||
cir = fcgeo.circleFrom1tan2pt(self.tangents[0], self.tanpoints[0], point)
|
cir = DraftGeomUtils.circleFrom1tan2pt(self.tangents[0], self.tanpoints[0], point)
|
||||||
self.center = fcgeo.findClosestCircle(point,cir).Center
|
self.center = DraftGeomUtils.findClosestCircle(point,cir).Center
|
||||||
self.arctrack.setCenter(self.center)
|
self.arctrack.setCenter(self.center)
|
||||||
if hasMod(arg,MODALT):
|
if hasMod(arg,MODALT):
|
||||||
if not self.altdown:
|
if not self.altdown:
|
||||||
|
@ -880,20 +878,20 @@ class Arc(Creator):
|
||||||
num = int(info['Component'].lstrip('Edge'))-1
|
num = int(info['Component'].lstrip('Edge'))-1
|
||||||
ed = ob.Shape.Edges[num]
|
ed = ob.Shape.Edges[num]
|
||||||
if len(self.tangents) == 2:
|
if len(self.tangents) == 2:
|
||||||
cir = fcgeo.circleFrom3tan(self.tangents[0], self.tangents[1], ed)
|
cir = DraftGeomUtils.circleFrom3tan(self.tangents[0], self.tangents[1], ed)
|
||||||
cl = fcgeo.findClosestCircle(point,cir)
|
cl = DraftGeomUtils.findClosestCircle(point,cir)
|
||||||
self.center = cl.Center
|
self.center = cl.Center
|
||||||
self.rad = cl.Radius
|
self.rad = cl.Radius
|
||||||
self.arctrack.setCenter(self.center)
|
self.arctrack.setCenter(self.center)
|
||||||
else:
|
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:
|
else:
|
||||||
self.rad = fcvec.dist(point,self.center)
|
self.rad = DraftVecUtils.dist(point,self.center)
|
||||||
else:
|
else:
|
||||||
if self.altdown:
|
if self.altdown:
|
||||||
self.ui.cross(True)
|
self.ui.cross(True)
|
||||||
self.altdown = False
|
self.altdown = False
|
||||||
self.rad = fcvec.dist(point,self.center)
|
self.rad = DraftVecUtils.dist(point,self.center)
|
||||||
self.ui.setRadiusValue(self.rad)
|
self.ui.setRadiusValue(self.rad)
|
||||||
self.arctrack.setRadius(self.rad)
|
self.arctrack.setRadius(self.rad)
|
||||||
# Draw constraint tracker line.
|
# Draw constraint tracker line.
|
||||||
|
@ -907,11 +905,11 @@ class Arc(Creator):
|
||||||
self.linetrack.p2(point)
|
self.linetrack.p2(point)
|
||||||
self.linetrack.on()
|
self.linetrack.on()
|
||||||
elif (self.step == 2): # choose first angle
|
elif (self.step == 2): # choose first angle
|
||||||
currentrad = fcvec.dist(point,self.center)
|
currentrad = DraftVecUtils.dist(point,self.center)
|
||||||
if currentrad != 0:
|
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
|
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.
|
# Draw constraint tracker line.
|
||||||
if hasMod(arg,MODCONSTRAIN):
|
if hasMod(arg,MODCONSTRAIN):
|
||||||
self.constraintrack.p1(point)
|
self.constraintrack.p1(point)
|
||||||
|
@ -922,11 +920,11 @@ class Arc(Creator):
|
||||||
self.ui.setRadiusValue(math.degrees(angle))
|
self.ui.setRadiusValue(math.degrees(angle))
|
||||||
self.firstangle = angle
|
self.firstangle = angle
|
||||||
else: # choose second angle
|
else: # choose second angle
|
||||||
currentrad = fcvec.dist(point,self.center)
|
currentrad = DraftVecUtils.dist(point,self.center)
|
||||||
if currentrad != 0:
|
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
|
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.
|
# Draw constraint tracker line.
|
||||||
if hasMod(arg,MODCONSTRAIN):
|
if hasMod(arg,MODCONSTRAIN):
|
||||||
self.constraintrack.p1(point)
|
self.constraintrack.p1(point)
|
||||||
|
@ -942,10 +940,10 @@ class Arc(Creator):
|
||||||
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
||||||
point,ctrlPoint,info = getPoint(self,arg)
|
point,ctrlPoint,info = getPoint(self,arg)
|
||||||
# this is to make sure radius is what you see on screen
|
# this is to make sure radius is what you see on screen
|
||||||
if self.center and fcvec.dist(point,self.center) > 0:
|
if self.center and DraftVecUtils.dist(point,self.center) > 0:
|
||||||
viewdelta = fcvec.project(point.sub(self.center), plane.axis)
|
viewdelta = DraftVecUtils.project(point.sub(self.center), plane.axis)
|
||||||
if not fcvec.isNull(viewdelta):
|
if not DraftVecUtils.isNull(viewdelta):
|
||||||
point = point.add(fcvec.neg(viewdelta))
|
point = point.add(DraftVecUtils.neg(viewdelta))
|
||||||
if (self.step == 0): # choose center
|
if (self.step == 0): # choose center
|
||||||
self.support = getSupport(arg)
|
self.support = getSupport(arg)
|
||||||
if hasMod(arg,MODALT):
|
if hasMod(arg,MODALT):
|
||||||
|
@ -990,7 +988,7 @@ class Arc(Creator):
|
||||||
self.ui.labelRadius.setText("Aperture")
|
self.ui.labelRadius.setText("Aperture")
|
||||||
self.step = 3
|
self.step = 3
|
||||||
# scale center->point vector for proper display
|
# 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)
|
self.arctrack.setStartAngle(self.firstangle)
|
||||||
msg(translate("draft", "Pick aperture:\n"))
|
msg(translate("draft", "Pick aperture:\n"))
|
||||||
else: # choose second angle
|
else: # choose second angle
|
||||||
|
@ -1036,15 +1034,15 @@ class Arc(Creator):
|
||||||
if (self.step == 1):
|
if (self.step == 1):
|
||||||
self.rad = rad
|
self.rad = rad
|
||||||
if len(self.tangents) == 2:
|
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:
|
if self.center:
|
||||||
self.center = fcgeo.findClosestCircle(self.center,cir).Center
|
self.center = DraftGeomUtils.findClosestCircle(self.center,cir).Center
|
||||||
else:
|
else:
|
||||||
self.center = cir[-1].Center
|
self.center = cir[-1].Center
|
||||||
elif self.tangents and self.tanpoints:
|
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:
|
if self.center:
|
||||||
self.center = fcgeo.findClosestCircle(self.center,cir).Center
|
self.center = DraftGeomUtils.findClosestCircle(self.center,cir).Center
|
||||||
else:
|
else:
|
||||||
self.center = cir[-1].Center
|
self.center = cir[-1].Center
|
||||||
if self.closedCircle:
|
if self.closedCircle:
|
||||||
|
@ -1061,9 +1059,9 @@ class Arc(Creator):
|
||||||
elif (self.step == 2):
|
elif (self.step == 2):
|
||||||
self.ui.labelRadius.setText(str(translate("draft", "Aperture")))
|
self.ui.labelRadius.setText(str(translate("draft", "Aperture")))
|
||||||
self.firstangle = math.radians(rad)
|
self.firstangle = math.radians(rad)
|
||||||
if fcvec.equals(plane.axis, Vector(1,0,0)): u = Vector(0,self.rad,0)
|
if DraftVecUtils.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)
|
else: u = DraftVecUtils.scaleTo(Vector(1,0,0).cross(plane.axis), self.rad)
|
||||||
urotated = fcvec.rotate(u, math.radians(rad), plane.axis)
|
urotated = DraftVecUtils.rotate(u, math.radians(rad), plane.axis)
|
||||||
self.arctrack.setStartAngle(self.firstangle)
|
self.arctrack.setStartAngle(self.firstangle)
|
||||||
self.step = 3
|
self.step = 3
|
||||||
self.ui.radiusValue.setText("")
|
self.ui.radiusValue.setText("")
|
||||||
|
@ -1139,10 +1137,10 @@ class Polygon(Creator):
|
||||||
point,ctrlPoint,info = getPoint(self,arg)
|
point,ctrlPoint,info = getPoint(self,arg)
|
||||||
# this is to make sure radius is what you see on screen
|
# this is to make sure radius is what you see on screen
|
||||||
self.ui.cross(True)
|
self.ui.cross(True)
|
||||||
if self.center and fcvec.dist(point,self.center) > 0:
|
if self.center and DraftVecUtils.dist(point,self.center) > 0:
|
||||||
viewdelta = fcvec.project(point.sub(self.center), plane.axis)
|
viewdelta = DraftVecUtils.project(point.sub(self.center), plane.axis)
|
||||||
if not fcvec.isNull(viewdelta):
|
if not DraftVecUtils.isNull(viewdelta):
|
||||||
point = point.add(fcvec.neg(viewdelta))
|
point = point.add(DraftVecUtils.neg(viewdelta))
|
||||||
if (self.step == 0): # choose center
|
if (self.step == 0): # choose center
|
||||||
if hasMod(arg,MODALT):
|
if hasMod(arg,MODALT):
|
||||||
if not self.altdown:
|
if not self.altdown:
|
||||||
|
@ -1156,12 +1154,12 @@ class Polygon(Creator):
|
||||||
self.ui.switchUi(False)
|
self.ui.switchUi(False)
|
||||||
else: # choose radius
|
else: # choose radius
|
||||||
if len(self.tangents) == 2:
|
if len(self.tangents) == 2:
|
||||||
cir = fcgeo.circleFrom2tan1pt(self.tangents[0], self.tangents[1], point)
|
cir = DraftGeomUtils.circleFrom2tan1pt(self.tangents[0], self.tangents[1], point)
|
||||||
self.center = fcgeo.findClosestCircle(point,cir).Center
|
self.center = DraftGeomUtils.findClosestCircle(point,cir).Center
|
||||||
self.arctrack.setCenter(self.center)
|
self.arctrack.setCenter(self.center)
|
||||||
elif self.tangents and self.tanpoints:
|
elif self.tangents and self.tanpoints:
|
||||||
cir = fcgeo.circleFrom1tan2pt(self.tangents[0], self.tanpoints[0], point)
|
cir = DraftGeomUtils.circleFrom1tan2pt(self.tangents[0], self.tanpoints[0], point)
|
||||||
self.center = fcgeo.findClosestCircle(point,cir).Center
|
self.center = DraftGeomUtils.findClosestCircle(point,cir).Center
|
||||||
self.arctrack.setCenter(self.center)
|
self.arctrack.setCenter(self.center)
|
||||||
if hasMod(arg,MODALT):
|
if hasMod(arg,MODALT):
|
||||||
if not self.altdown:
|
if not self.altdown:
|
||||||
|
@ -1173,20 +1171,20 @@ class Polygon(Creator):
|
||||||
num = int(snapped['Component'].lstrip('Edge'))-1
|
num = int(snapped['Component'].lstrip('Edge'))-1
|
||||||
ed = ob.Shape.Edges[num]
|
ed = ob.Shape.Edges[num]
|
||||||
if len(self.tangents) == 2:
|
if len(self.tangents) == 2:
|
||||||
cir = fcgeo.circleFrom3tan(self.tangents[0], self.tangents[1], ed)
|
cir = DraftGeomUtils.circleFrom3tan(self.tangents[0], self.tangents[1], ed)
|
||||||
cl = fcgeo.findClosestCircle(point,cir)
|
cl = DraftGeomUtils.findClosestCircle(point,cir)
|
||||||
self.center = cl.Center
|
self.center = cl.Center
|
||||||
self.rad = cl.Radius
|
self.rad = cl.Radius
|
||||||
self.arctrack.setCenter(self.center)
|
self.arctrack.setCenter(self.center)
|
||||||
else:
|
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:
|
else:
|
||||||
self.rad = fcvec.dist(point,self.center)
|
self.rad = DraftVecUtils.dist(point,self.center)
|
||||||
else:
|
else:
|
||||||
if self.altdown:
|
if self.altdown:
|
||||||
self.ui.cross(True)
|
self.ui.cross(True)
|
||||||
self.altdown = False
|
self.altdown = False
|
||||||
self.rad = fcvec.dist(point,self.center)
|
self.rad = DraftVecUtils.dist(point,self.center)
|
||||||
self.ui.setRadiusValue(self.rad)
|
self.ui.setRadiusValue(self.rad)
|
||||||
self.arctrack.setRadius(self.rad)
|
self.arctrack.setRadius(self.rad)
|
||||||
# Draw constraint tracker line.
|
# Draw constraint tracker line.
|
||||||
|
@ -1203,10 +1201,10 @@ class Polygon(Creator):
|
||||||
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
||||||
point,ctrlPoint,info = getPoint(self,arg)
|
point,ctrlPoint,info = getPoint(self,arg)
|
||||||
# this is to make sure radius is what you see on screen
|
# this is to make sure radius is what you see on screen
|
||||||
if self.center and fcvec.dist(point,self.center) > 0:
|
if self.center and DraftVecUtils.dist(point,self.center) > 0:
|
||||||
viewdelta = fcvec.project(point.sub(self.center), plane.axis)
|
viewdelta = DraftVecUtils.project(point.sub(self.center), plane.axis)
|
||||||
if not fcvec.isNull(viewdelta):
|
if not DraftVecUtils.isNull(viewdelta):
|
||||||
point = point.add(fcvec.neg(viewdelta))
|
point = point.add(DraftVecUtils.neg(viewdelta))
|
||||||
if (self.step == 0): # choose center
|
if (self.step == 0): # choose center
|
||||||
if not self.node: self.support = getSupport(arg)
|
if not self.node: self.support = getSupport(arg)
|
||||||
if hasMod(arg,MODALT):
|
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"
|
"this function gets called by the toolbar when valid radius have been entered there"
|
||||||
self.rad = rad
|
self.rad = rad
|
||||||
if len(self.tangents) == 2:
|
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:
|
if self.center:
|
||||||
self.center = fcgeo.findClosestCircle(self.center,cir).Center
|
self.center = DraftGeomUtils.findClosestCircle(self.center,cir).Center
|
||||||
else:
|
else:
|
||||||
self.center = cir[-1].Center
|
self.center = cir[-1].Center
|
||||||
elif self.tangents and self.tanpoints:
|
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:
|
if self.center:
|
||||||
self.center = fcgeo.findClosestCircle(self.center,cir).Center
|
self.center = DraftGeomUtils.findClosestCircle(self.center,cir).Center
|
||||||
else:
|
else:
|
||||||
self.center = cir[-1].Center
|
self.center = cir[-1].Center
|
||||||
self.drawPolygon()
|
self.drawPolygon()
|
||||||
|
@ -1485,7 +1483,7 @@ class Dimension(Creator):
|
||||||
r = point.sub(self.center)
|
r = point.sub(self.center)
|
||||||
self.arctrack.setRadius(r.Length)
|
self.arctrack.setRadius(r.Length)
|
||||||
a = self.arctrack.getAngle(point)
|
a = self.arctrack.getAngle(point)
|
||||||
pair = fcgeo.getBoundaryAngles(a,self.pts)
|
pair = DraftGeomUtils.getBoundaryAngles(a,self.pts)
|
||||||
if not (pair[0] < a < pair[1]):
|
if not (pair[0] < a < pair[1]):
|
||||||
self.angledata = [4*math.pi-pair[0],2*math.pi-pair[1]]
|
self.angledata = [4*math.pi-pair[0],2*math.pi-pair[1]]
|
||||||
else:
|
else:
|
||||||
|
@ -1496,14 +1494,14 @@ class Dimension(Creator):
|
||||||
self.altdown = False
|
self.altdown = False
|
||||||
self.ui.switchUi(False)
|
self.ui.switchUi(False)
|
||||||
if self.dir:
|
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 len(self.node) == 2:
|
||||||
if self.arcmode and self.edges:
|
if self.arcmode and self.edges:
|
||||||
cen = self.edges[0].Curve.Center
|
cen = self.edges[0].Curve.Center
|
||||||
rad = self.edges[0].Curve.Radius
|
rad = self.edges[0].Curve.Radius
|
||||||
baseray = point.sub(cen)
|
baseray = point.sub(cen)
|
||||||
v2 = fcvec.scaleTo(baseray,rad)
|
v2 = DraftVecUtils.scaleTo(baseray,rad)
|
||||||
v1 = fcvec.neg(v2)
|
v1 = DraftVecUtils.neg(v2)
|
||||||
if shift:
|
if shift:
|
||||||
self.node = [cen,cen.add(v2)]
|
self.node = [cen,cen.add(v2)]
|
||||||
self.arcmode = "radius"
|
self.arcmode = "radius"
|
||||||
|
@ -1574,7 +1572,7 @@ class Dimension(Creator):
|
||||||
# there is already a snapped edge, so we start angular dimension
|
# there is already a snapped edge, so we start angular dimension
|
||||||
self.edges.append(ed)
|
self.edges.append(ed)
|
||||||
self.node.extend([v1,v2]) # self.node now has the 4 endpoints
|
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[1],
|
||||||
self.node[2],
|
self.node[2],
|
||||||
self.node[3],
|
self.node[3],
|
||||||
|
@ -1593,7 +1591,7 @@ class Dimension(Creator):
|
||||||
self.dimtrack.on()
|
self.dimtrack.on()
|
||||||
else:
|
else:
|
||||||
if self.dir:
|
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)
|
self.node.append(point)
|
||||||
print "node",self.node
|
print "node",self.node
|
||||||
self.dimtrack.update(self.node)
|
self.dimtrack.update(self.node)
|
||||||
|
@ -1610,7 +1608,7 @@ class Dimension(Creator):
|
||||||
# for unlinked arc mode:
|
# for unlinked arc mode:
|
||||||
# if self.arcmode:
|
# if self.arcmode:
|
||||||
# v = self.node[1].sub(self.node[0])
|
# 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)
|
# cen = self.node[0].add(v)
|
||||||
# self.node = [self.node[0],self.node[1],cen]
|
# self.node = [self.node[0],self.node[1],cen]
|
||||||
self.createObject()
|
self.createObject()
|
||||||
|
@ -1651,9 +1649,8 @@ class Modifier:
|
||||||
def Activated(self,name="None"):
|
def Activated(self,name="None"):
|
||||||
if FreeCAD.activeDraftCommand:
|
if FreeCAD.activeDraftCommand:
|
||||||
FreeCAD.activeDraftCommand.finish()
|
FreeCAD.activeDraftCommand.finish()
|
||||||
global Part, fcgeo
|
global Part, DraftGeomUtils
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
self.ui = None
|
self.ui = None
|
||||||
self.call = None
|
self.call = None
|
||||||
self.commitList = []
|
self.commitList = []
|
||||||
|
@ -1667,7 +1664,7 @@ class Modifier:
|
||||||
FreeCADGui.draftToolBar.show()
|
FreeCADGui.draftToolBar.show()
|
||||||
rot = self.view.getCameraNode().getField("orientation").getValue()
|
rot = self.view.getCameraNode().getField("orientation").getValue()
|
||||||
upv = Vector(rot.multVec(coin.SbVec3f(0,1,0)).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.node = []
|
||||||
self.ui.sourceCmd = self
|
self.ui.sourceCmd = self
|
||||||
self.constrain = None
|
self.constrain = None
|
||||||
|
@ -1931,10 +1928,10 @@ class Rotate(Modifier):
|
||||||
point,ctrlPoint,info = getPoint(self,arg)
|
point,ctrlPoint,info = getPoint(self,arg)
|
||||||
self.ui.cross(True)
|
self.ui.cross(True)
|
||||||
# this is to make sure radius is what you see on screen
|
# this is to make sure radius is what you see on screen
|
||||||
if self.center and fcvec.dist(point,self.center):
|
if self.center and DraftVecUtils.dist(point,self.center):
|
||||||
viewdelta = fcvec.project(point.sub(self.center), plane.axis)
|
viewdelta = DraftVecUtils.project(point.sub(self.center), plane.axis)
|
||||||
if not fcvec.isNull(viewdelta):
|
if not DraftVecUtils.isNull(viewdelta):
|
||||||
point = point.add(fcvec.neg(viewdelta))
|
point = point.add(DraftVecUtils.neg(viewdelta))
|
||||||
if self.extendedCopy:
|
if self.extendedCopy:
|
||||||
if not hasMod(arg,MODALT):
|
if not hasMod(arg,MODALT):
|
||||||
self.step = 3
|
self.step = 3
|
||||||
|
@ -1942,9 +1939,9 @@ class Rotate(Modifier):
|
||||||
if (self.step == 0):
|
if (self.step == 0):
|
||||||
pass
|
pass
|
||||||
elif (self.step == 1):
|
elif (self.step == 1):
|
||||||
currentrad = fcvec.dist(point,self.center)
|
currentrad = DraftVecUtils.dist(point,self.center)
|
||||||
if (currentrad != 0):
|
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
|
else: angle = 0
|
||||||
self.linetrack.p2(point)
|
self.linetrack.p2(point)
|
||||||
# Draw constraint tracker line.
|
# Draw constraint tracker line.
|
||||||
|
@ -1959,16 +1956,16 @@ class Rotate(Modifier):
|
||||||
self.ui.radiusValue.setFocus()
|
self.ui.radiusValue.setFocus()
|
||||||
self.ui.radiusValue.selectAll()
|
self.ui.radiusValue.selectAll()
|
||||||
elif (self.step == 2):
|
elif (self.step == 2):
|
||||||
currentrad = fcvec.dist(point,self.center)
|
currentrad = DraftVecUtils.dist(point,self.center)
|
||||||
if (currentrad != 0):
|
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
|
else: angle = 0
|
||||||
if (angle < self.firstangle):
|
if (angle < self.firstangle):
|
||||||
sweep = (2*math.pi-self.firstangle)+angle
|
sweep = (2*math.pi-self.firstangle)+angle
|
||||||
else:
|
else:
|
||||||
sweep = angle - self.firstangle
|
sweep = angle - self.firstangle
|
||||||
self.arctrack.setApertureAngle(sweep)
|
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)
|
self.linetrack.p2(point)
|
||||||
# Draw constraint tracker line.
|
# Draw constraint tracker line.
|
||||||
if hasMod(arg,MODCONSTRAIN):
|
if hasMod(arg,MODCONSTRAIN):
|
||||||
|
@ -1984,9 +1981,9 @@ class Rotate(Modifier):
|
||||||
elif arg["Type"] == "SoMouseButtonEvent":
|
elif arg["Type"] == "SoMouseButtonEvent":
|
||||||
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
||||||
point,ctrlPoint,info = getPoint(self,arg)
|
point,ctrlPoint,info = getPoint(self,arg)
|
||||||
if self.center and fcvec.dist(point,self.center):
|
if self.center and DraftVecUtils.dist(point,self.center):
|
||||||
viewdelta = fcvec.project(point.sub(self.center), plane.axis)
|
viewdelta = DraftVecUtils.project(point.sub(self.center), plane.axis)
|
||||||
if not fcvec.isNull(viewdelta): point = point.add(fcvec.neg(viewdelta))
|
if not DraftVecUtils.isNull(viewdelta): point = point.add(DraftVecUtils.neg(viewdelta))
|
||||||
if (self.step == 0):
|
if (self.step == 0):
|
||||||
self.center = point
|
self.center = point
|
||||||
self.node = [point]
|
self.node = [point]
|
||||||
|
@ -2002,16 +1999,16 @@ class Rotate(Modifier):
|
||||||
self.planetrack.set(point)
|
self.planetrack.set(point)
|
||||||
elif (self.step == 1):
|
elif (self.step == 1):
|
||||||
self.ui.labelRadius.setText("Rotation")
|
self.ui.labelRadius.setText("Rotation")
|
||||||
self.rad = fcvec.dist(point,self.center)
|
self.rad = DraftVecUtils.dist(point,self.center)
|
||||||
self.arctrack.on()
|
self.arctrack.on()
|
||||||
self.arctrack.setStartPoint(point)
|
self.arctrack.setStartPoint(point)
|
||||||
self.ghost.on()
|
self.ghost.on()
|
||||||
self.step = 2
|
self.step = 2
|
||||||
msg(translate("draft", "Pick rotation angle:\n"))
|
msg(translate("draft", "Pick rotation angle:\n"))
|
||||||
else:
|
else:
|
||||||
currentrad = fcvec.dist(point,self.center)
|
currentrad = DraftVecUtils.dist(point,self.center)
|
||||||
angle = point.sub(self.center).getAngle(plane.u)
|
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
|
angle = -angle
|
||||||
if (angle < self.firstangle):
|
if (angle < self.firstangle):
|
||||||
sweep = (2*math.pi-self.firstangle)+angle
|
sweep = (2*math.pi-self.firstangle)+angle
|
||||||
|
@ -2127,33 +2124,33 @@ class Offset(Modifier):
|
||||||
self.ui.cross(True)
|
self.ui.cross(True)
|
||||||
point,ctrlPoint,info = getPoint(self,arg)
|
point,ctrlPoint,info = getPoint(self,arg)
|
||||||
if hasMod(arg,MODCONSTRAIN) and self.constrainSeg:
|
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]]
|
e = self.shape.Edges[self.constrainSeg[1]]
|
||||||
self.constraintrack.p1(e.Vertexes[0].Point)
|
self.constraintrack.p1(e.Vertexes[0].Point)
|
||||||
self.constraintrack.p2(point.add(dist[0]))
|
self.constraintrack.p2(point.add(dist[0]))
|
||||||
self.constraintrack.on()
|
self.constraintrack.on()
|
||||||
else:
|
else:
|
||||||
dist = fcgeo.findPerpendicular(point,self.shape.Edges)
|
dist = DraftGeomUtils.findPerpendicular(point,self.shape.Edges)
|
||||||
self.constraintrack.off()
|
self.constraintrack.off()
|
||||||
if dist:
|
if dist:
|
||||||
self.ghost.on()
|
self.ghost.on()
|
||||||
if self.mode == "Wire":
|
if self.mode == "Wire":
|
||||||
d = fcvec.neg(dist[0])
|
d = DraftVecUtils.neg(dist[0])
|
||||||
v1 = fcgeo.getTangent(self.shape.Edges[0],point)
|
v1 = DraftGeomUtils.getTangent(self.shape.Edges[0],point)
|
||||||
v2 = fcgeo.getTangent(self.shape.Edges[dist[1]],point)
|
v2 = DraftGeomUtils.getTangent(self.shape.Edges[dist[1]],point)
|
||||||
a = -fcvec.angle(v1,v2)
|
a = -DraftVecUtils.angle(v1,v2)
|
||||||
self.dvec = fcvec.rotate(d,a,plane.axis)
|
self.dvec = DraftVecUtils.rotate(d,a,plane.axis)
|
||||||
occmode = self.ui.occOffset.isChecked()
|
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":
|
elif self.mode == "BSpline":
|
||||||
d = fcvec.neg(dist[0])
|
d = DraftVecUtils.neg(dist[0])
|
||||||
e = self.shape.Edges[0]
|
e = self.shape.Edges[0]
|
||||||
basetan = fcgeo.getTangent(e,point)
|
basetan = DraftGeomUtils.getTangent(e,point)
|
||||||
self.npts = []
|
self.npts = []
|
||||||
for p in self.sel.Points:
|
for p in self.sel.Points:
|
||||||
currtan = fcgeo.getTangent(e,p)
|
currtan = DraftGeomUtils.getTangent(e,p)
|
||||||
a = -fcvec.angle(currtan,basetan)
|
a = -DraftVecUtils.angle(currtan,basetan)
|
||||||
self.dvec = fcvec.rotate(d,a,plane.axis)
|
self.dvec = DraftVecUtils.rotate(d,a,plane.axis)
|
||||||
self.npts.append(p.add(self.dvec))
|
self.npts.append(p.add(self.dvec))
|
||||||
self.ghost.update(self.npts)
|
self.ghost.update(self.npts)
|
||||||
elif self.mode == "Circle":
|
elif self.mode == "Circle":
|
||||||
|
@ -2329,12 +2326,12 @@ class Upgrade(Modifier):
|
||||||
u = faces.pop(0)
|
u = faces.pop(0)
|
||||||
for f in faces:
|
for f in faces:
|
||||||
u = u.fuse(f)
|
u = u.fuse(f)
|
||||||
if fcgeo.isCoplanar(faces):
|
if DraftGeomUtils.isCoplanar(faces):
|
||||||
if self.sel[0].ViewObject.DisplayMode == "Wireframe":
|
if self.sel[0].ViewObject.DisplayMode == "Wireframe":
|
||||||
f = False
|
f = False
|
||||||
else:
|
else:
|
||||||
f = True
|
f = True
|
||||||
u = fcgeo.concatenate(u)
|
u = DraftGeomUtils.concatenate(u)
|
||||||
if not curves:
|
if not curves:
|
||||||
# several coplanar and non-curved faces: they can becoem a Draft wire
|
# 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"))
|
msg(translate("draft", "Found several objects or faces: making a parametric face\n"))
|
||||||
|
@ -2384,7 +2381,7 @@ class Upgrade(Modifier):
|
||||||
else:
|
else:
|
||||||
# only closed wires
|
# only closed wires
|
||||||
for w in wires:
|
for w in wires:
|
||||||
if fcgeo.isPlanar(w):
|
if DraftGeomUtils.isPlanar(w):
|
||||||
f = Part.Face(w)
|
f = Part.Face(w)
|
||||||
faces.append(f)
|
faces.append(f)
|
||||||
else:
|
else:
|
||||||
|
@ -2405,7 +2402,7 @@ class Upgrade(Modifier):
|
||||||
edges = openwires[0].Edges
|
edges = openwires[0].Edges
|
||||||
if len(edges) > 1:
|
if len(edges) > 1:
|
||||||
edges.append(Part.Line(p1,p0).toShape())
|
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(edges) == 1:
|
||||||
if len(w.Vertexes) == 2:
|
if len(w.Vertexes) == 2:
|
||||||
msg(translate("draft", "Found 1 open edge: making a line\n"))
|
msg(translate("draft", "Found 1 open edge: making a line\n"))
|
||||||
|
@ -2433,7 +2430,7 @@ class Upgrade(Modifier):
|
||||||
for e in ob.Shape.Edges:
|
for e in ob.Shape.Edges:
|
||||||
edges.append(e)
|
edges.append(e)
|
||||||
newob = None
|
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
|
# for e in nedges: print "debug: ",e.Curve,e.Vertexes[0].Point,e.Vertexes[-1].Point
|
||||||
w = Part.Wire(nedges)
|
w = Part.Wire(nedges)
|
||||||
if len(w.Edges) == len(edges):
|
if len(w.Edges) == len(edges):
|
||||||
|
@ -2643,7 +2640,7 @@ class Trimex(Modifier):
|
||||||
self.extrudeMode = False
|
self.extrudeMode = False
|
||||||
if self.obj.Shape.Wires:
|
if self.obj.Shape.Wires:
|
||||||
self.edges = self.obj.Shape.Wires[0].Edges
|
self.edges = self.obj.Shape.Wires[0].Edges
|
||||||
self.edges = fcgeo.sortEdges(self.edges)
|
self.edges = DraftGeomUtils.sortEdges(self.edges)
|
||||||
else:
|
else:
|
||||||
self.edges = self.obj.Shape.Edges
|
self.edges = self.obj.Shape.Edges
|
||||||
self.ghost = []
|
self.ghost = []
|
||||||
|
@ -2707,7 +2704,7 @@ class Trimex(Modifier):
|
||||||
"redraws the ghost in extrude mode"
|
"redraws the ghost in extrude mode"
|
||||||
self.newpoint = self.obj.Shape.Faces[0].CenterOfMass
|
self.newpoint = self.obj.Shape.Faces[0].CenterOfMass
|
||||||
dvec = self.point.sub(self.newpoint)
|
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
|
else: delta = dvec
|
||||||
if self.force:
|
if self.force:
|
||||||
ratio = self.force/delta.Length
|
ratio = self.force/delta.Length
|
||||||
|
@ -2733,7 +2730,7 @@ class Trimex(Modifier):
|
||||||
for e in self.edges: vlist.append(e.Vertexes[0].Point)
|
for e in self.edges: vlist.append(e.Vertexes[0].Point)
|
||||||
vlist.append(self.edges[-1].Vertexes[-1].Point)
|
vlist.append(self.edges[-1].Vertexes[-1].Point)
|
||||||
if shift: npoint = self.activePoint
|
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 npoint > len(self.edges)/2: reverse = True
|
||||||
if alt: reverse = not reverse
|
if alt: reverse = not reverse
|
||||||
self.activePoint = npoint
|
self.activePoint = npoint
|
||||||
|
@ -2758,16 +2755,16 @@ class Trimex(Modifier):
|
||||||
snapped = self.doc.getObject(snapped['Object'])
|
snapped = self.doc.getObject(snapped['Object'])
|
||||||
pts = []
|
pts = []
|
||||||
for e in snapped.Shape.Edges:
|
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 int: pts.extend(int)
|
||||||
if pts:
|
if pts:
|
||||||
point = pts[fcgeo.findClosest(point,pts)]
|
point = pts[DraftGeomUtils.findClosest(point,pts)]
|
||||||
|
|
||||||
# modifying active edge
|
# modifying active edge
|
||||||
if isinstance(edge.Curve,Part.Line):
|
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)
|
chord = v1.sub(point)
|
||||||
proj = fcvec.project(chord,perp)
|
proj = DraftVecUtils.project(chord,perp)
|
||||||
self.newpoint = Vector.add(point,proj)
|
self.newpoint = Vector.add(point,proj)
|
||||||
dist = v1.sub(self.newpoint).Length
|
dist = v1.sub(self.newpoint).Length
|
||||||
ghost.p1(self.newpoint)
|
ghost.p1(self.newpoint)
|
||||||
|
@ -2776,15 +2773,15 @@ class Trimex(Modifier):
|
||||||
if real:
|
if real:
|
||||||
if self.force:
|
if self.force:
|
||||||
ray = self.newpoint.sub(v1)
|
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)
|
self.newpoint = Vector.add(v1,ray)
|
||||||
newedges.append(Part.Line(self.newpoint,v2).toShape())
|
newedges.append(Part.Line(self.newpoint,v2).toShape())
|
||||||
else:
|
else:
|
||||||
center = edge.Curve.Center
|
center = edge.Curve.Center
|
||||||
rad = edge.Curve.Radius
|
rad = edge.Curve.Radius
|
||||||
ang1 = fcvec.angle(v2.sub(center))
|
ang1 = DraftVecUtils.angle(v2.sub(center))
|
||||||
ang2 = fcvec.angle(point.sub(center))
|
ang2 = DraftVecUtils.angle(point.sub(center))
|
||||||
self.newpoint=Vector.add(center,fcvec.rotate(Vector(rad,0,0),-ang2))
|
self.newpoint=Vector.add(center,DraftVecUtils.rotate(Vector(rad,0,0),-ang2))
|
||||||
self.ui.labelRadius.setText("Angle")
|
self.ui.labelRadius.setText("Angle")
|
||||||
dist = math.degrees(-ang2)
|
dist = math.degrees(-ang2)
|
||||||
# if ang1 > ang2: ang1,ang2 = ang2,ang1
|
# if ang1 > ang2: ang1,ang2 = ang2,ang1
|
||||||
|
@ -2796,11 +2793,11 @@ class Trimex(Modifier):
|
||||||
if real:
|
if real:
|
||||||
if self.force:
|
if self.force:
|
||||||
angle = math.radians(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)
|
self.newpoint = Vector.add(center,newray)
|
||||||
chord = self.newpoint.sub(v2)
|
chord = self.newpoint.sub(v2)
|
||||||
perp = chord.cross(Vector(0,0,1))
|
perp = chord.cross(Vector(0,0,1))
|
||||||
scaledperp = fcvec.scaleTo(perp,rad)
|
scaledperp = DraftVecUtils.scaleTo(perp,rad)
|
||||||
midpoint = Vector.add(center,scaledperp)
|
midpoint = Vector.add(center,scaledperp)
|
||||||
newedges.append(Part.Arc(self.newpoint,midpoint,v2).toShape())
|
newedges.append(Part.Arc(self.newpoint,midpoint,v2).toShape())
|
||||||
ghost.on()
|
ghost.on()
|
||||||
|
@ -2815,8 +2812,8 @@ class Trimex(Modifier):
|
||||||
ghost.p1(edge.Vertexes[0].Point)
|
ghost.p1(edge.Vertexes[0].Point)
|
||||||
ghost.p2(edge.Vertexes[-1].Point)
|
ghost.p2(edge.Vertexes[-1].Point)
|
||||||
else:
|
else:
|
||||||
ang1 = fcvec.angle(edge.Vertexes[0].Point.sub(center))
|
ang1 = DraftVecUtils.angle(edge.Vertexes[0].Point.sub(center))
|
||||||
ang2 = fcvec.angle(edge.Vertexes[-1].Point.sub(center))
|
ang2 = DraftVecUtils.angle(edge.Vertexes[-1].Point.sub(center))
|
||||||
# if ang1 > ang2: ang1,ang2 = ang2,ang1
|
# if ang1 > ang2: ang1,ang2 = ang2,ang1
|
||||||
ghost.setEndAngle(-ang2)
|
ghost.setEndAngle(-ang2)
|
||||||
ghost.setStartAngle(-ang1)
|
ghost.setStartAngle(-ang1)
|
||||||
|
@ -2961,7 +2958,7 @@ class Scale(Modifier):
|
||||||
self.ghost.trans.scaleFactor.setValue([delta.x,delta.y,delta.z])
|
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 = Vector(self.node[0].x,self.node[0].y,self.node[0].z)
|
||||||
corr.scale(delta.x,delta.y,delta.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])
|
self.ghost.trans.translation.setValue([corr.x,corr.y,corr.z])
|
||||||
if self.extendedCopy:
|
if self.extendedCopy:
|
||||||
if not hasMod(arg,MODALT): self.finish()
|
if not hasMod(arg,MODALT): self.finish()
|
||||||
|
@ -3166,9 +3163,9 @@ class Edit(Modifier):
|
||||||
self.editpoints.append(self.obj.Shape.Vertexes[2].Point)
|
self.editpoints.append(self.obj.Shape.Vertexes[2].Point)
|
||||||
v = self.obj.Shape.Vertexes
|
v = self.obj.Shape.Vertexes
|
||||||
self.bx = v[1].Point.sub(v[0].Point)
|
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)
|
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":
|
elif Draft.getType(self.obj) == "Polygon":
|
||||||
self.editpoints.append(self.obj.Placement.Base)
|
self.editpoints.append(self.obj.Placement.Base)
|
||||||
self.editpoints.append(self.obj.Shape.Vertexes[0].Point)
|
self.editpoints.append(self.obj.Shape.Vertexes[0].Point)
|
||||||
|
@ -3292,8 +3289,8 @@ class Edit(Modifier):
|
||||||
self.obj.Placement = p
|
self.obj.Placement = p
|
||||||
elif self.editing == 1:
|
elif self.editing == 1:
|
||||||
diag = v.sub(self.obj.Placement.Base)
|
diag = v.sub(self.obj.Placement.Base)
|
||||||
nx = fcvec.project(diag,self.bx)
|
nx = DraftVecUtils.project(diag,self.bx)
|
||||||
ny = fcvec.project(diag,self.by)
|
ny = DraftVecUtils.project(diag,self.by)
|
||||||
ax = nx.Length
|
ax = nx.Length
|
||||||
ay = ny.Length
|
ay = ny.Length
|
||||||
if ax and ay:
|
if ax and ay:
|
||||||
|
|
|
@ -25,18 +25,16 @@ __title__="FreeCAD Draft Trackers"
|
||||||
__author__ = "Yorik van Havre"
|
__author__ = "Yorik van Havre"
|
||||||
__url__ = "http://free-cad.sourceforge.net"
|
__url__ = "http://free-cad.sourceforge.net"
|
||||||
|
|
||||||
import FreeCAD,FreeCADGui,math,Draft
|
import FreeCAD,FreeCADGui,math,Draft, DraftVecUtils
|
||||||
from FreeCAD import Vector
|
from FreeCAD import Vector
|
||||||
from draftlibs import fcvec
|
|
||||||
from pivy import coin
|
from pivy import coin
|
||||||
from DraftGui import todo
|
from DraftGui import todo
|
||||||
|
|
||||||
class Tracker:
|
class Tracker:
|
||||||
"A generic Draft Tracker, to be used by other specific trackers"
|
"A generic Draft Tracker, to be used by other specific trackers"
|
||||||
def __init__(self,dotted=False,scolor=None,swidth=None,children=[],ontop=False):
|
def __init__(self,dotted=False,scolor=None,swidth=None,children=[],ontop=False):
|
||||||
global Part, fcgeo
|
global Part, DraftGeomUtils
|
||||||
import Part
|
import Part, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
self.ontop = ontop
|
self.ontop = ontop
|
||||||
color = coin.SoBaseColor()
|
color = coin.SoBaseColor()
|
||||||
color.rgb = scolor or FreeCADGui.draftToolBar.getDefaultColor("ui")
|
color.rgb = scolor or FreeCADGui.draftToolBar.getDefaultColor("ui")
|
||||||
|
@ -161,8 +159,8 @@ class rectangleTracker(Tracker):
|
||||||
def update(self,point):
|
def update(self,point):
|
||||||
"sets the opposite (diagonal) point of the rectangle"
|
"sets the opposite (diagonal) point of the rectangle"
|
||||||
diagonal = point.sub(self.origin)
|
diagonal = point.sub(self.origin)
|
||||||
inpoint1 = self.origin.add(fcvec.project(diagonal,self.v))
|
inpoint1 = self.origin.add(DraftVecUtils.project(diagonal,self.v))
|
||||||
inpoint2 = self.origin.add(fcvec.project(diagonal,self.u))
|
inpoint2 = self.origin.add(DraftVecUtils.project(diagonal,self.u))
|
||||||
self.coords.point.set1Value(1,inpoint1.x,inpoint1.y,inpoint1.z)
|
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(2,point.x,point.y,point.z)
|
||||||
self.coords.point.set1Value(3,inpoint2.x,inpoint2.y,inpoint2.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())
|
p1 = Vector(self.coords.point.getValues()[0].getValue())
|
||||||
p2 = Vector(self.coords.point.getValues()[2].getValue())
|
p2 = Vector(self.coords.point.getValues()[2].getValue())
|
||||||
diag = p2.sub(p1)
|
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):
|
def getNormal(self):
|
||||||
"returns the normal of the rectangle"
|
"returns the normal of the rectangle"
|
||||||
|
@ -233,23 +231,23 @@ class dimTracker(Tracker):
|
||||||
def calc(self):
|
def calc(self):
|
||||||
import Part
|
import Part
|
||||||
if (self.p1 != None) and (self.p2 != None):
|
if (self.p1 != None) and (self.p2 != None):
|
||||||
points = [fcvec.tup(self.p1,True),fcvec.tup(self.p2,True),\
|
points = [DraftVecUtils.tup(self.p1,True),DraftVecUtils.tup(self.p2,True),\
|
||||||
fcvec.tup(self.p1,True),fcvec.tup(self.p2,True)]
|
DraftVecUtils.tup(self.p1,True),DraftVecUtils.tup(self.p2,True)]
|
||||||
if self.p3 != None:
|
if self.p3 != None:
|
||||||
p1 = self.p1
|
p1 = self.p1
|
||||||
p4 = self.p2
|
p4 = self.p2
|
||||||
if fcvec.equals(p1,p4):
|
if DraftVecUtils.equals(p1,p4):
|
||||||
proj = None
|
proj = None
|
||||||
else:
|
else:
|
||||||
base = Part.Line(p1,p4).toShape()
|
base = Part.Line(p1,p4).toShape()
|
||||||
proj = fcgeo.findDistance(self.p3,base)
|
proj = DraftGeomUtils.findDistance(self.p3,base)
|
||||||
if not proj:
|
if not proj:
|
||||||
p2 = p1
|
p2 = p1
|
||||||
p3 = p4
|
p3 = p4
|
||||||
else:
|
else:
|
||||||
p2 = p1.add(fcvec.neg(proj))
|
p2 = p1.add(DraftVecUtils.neg(proj))
|
||||||
p3 = p4.add(fcvec.neg(proj))
|
p3 = p4.add(DraftVecUtils.neg(proj))
|
||||||
points = [fcvec.tup(p1),fcvec.tup(p2),fcvec.tup(p3),fcvec.tup(p4)]
|
points = [DraftVecUtils.tup(p1),DraftVecUtils.tup(p2),DraftVecUtils.tup(p3),DraftVecUtils.tup(p4)]
|
||||||
self.coords.point.setValues(0,4,points)
|
self.coords.point.setValues(0,4,points)
|
||||||
|
|
||||||
class bsplineTracker(Tracker):
|
class bsplineTracker(Tracker):
|
||||||
|
@ -340,7 +338,7 @@ class arcTracker(Tracker):
|
||||||
center = Vector(c[0],c[1],c[2])
|
center = Vector(c[0],c[1],c[2])
|
||||||
base = FreeCAD.DraftWorkingPlane.u
|
base = FreeCAD.DraftWorkingPlane.u
|
||||||
rad = pt.sub(center)
|
rad = pt.sub(center)
|
||||||
return(fcvec.angle(rad,base,FreeCAD.DraftWorkingPlane.axis))
|
return(DraftVecUtils.angle(rad,base,FreeCAD.DraftWorkingPlane.axis))
|
||||||
|
|
||||||
def getAngles(self):
|
def getAngles(self):
|
||||||
"returns the start and end angles"
|
"returns the start and end angles"
|
||||||
|
@ -496,7 +494,7 @@ class wireTracker(Tracker):
|
||||||
"A wire tracker"
|
"A wire tracker"
|
||||||
def __init__(self,wire):
|
def __init__(self,wire):
|
||||||
self.line = coin.SoLineSet()
|
self.line = coin.SoLineSet()
|
||||||
self.closed = fcgeo.isReallyClosed(wire)
|
self.closed = DraftGeomUtils.isReallyClosed(wire)
|
||||||
if self.closed:
|
if self.closed:
|
||||||
self.line.numVertices.setValue(len(wire.Vertexes)+1)
|
self.line.numVertices.setValue(len(wire.Vertexes)+1)
|
||||||
else:
|
else:
|
||||||
|
@ -626,11 +624,11 @@ class gridTracker(Tracker):
|
||||||
"returns the closest node from the given point"
|
"returns the closest node from the given point"
|
||||||
# get the 2D coords.
|
# get the 2D coords.
|
||||||
point = FreeCAD.DraftWorkingPlane.projectPoint(point)
|
point = FreeCAD.DraftWorkingPlane.projectPoint(point)
|
||||||
u = fcvec.project(point,FreeCAD.DraftWorkingPlane.u)
|
u = DraftVecUtils.project(point,FreeCAD.DraftWorkingPlane.u)
|
||||||
lu = u.Length
|
lu = u.Length
|
||||||
if u.getAngle(FreeCAD.DraftWorkingPlane.u) > 1.5:
|
if u.getAngle(FreeCAD.DraftWorkingPlane.u) > 1.5:
|
||||||
lu = -lu
|
lu = -lu
|
||||||
v = fcvec.project(point,FreeCAD.DraftWorkingPlane.v)
|
v = DraftVecUtils.project(point,FreeCAD.DraftWorkingPlane.v)
|
||||||
lv = v.Length
|
lv = v.Length
|
||||||
if v.getAngle(FreeCAD.DraftWorkingPlane.v) > 1.5:
|
if v.getAngle(FreeCAD.DraftWorkingPlane.v) > 1.5:
|
||||||
lv = -lv
|
lv = -lv
|
||||||
|
@ -659,8 +657,7 @@ class boxTracker(Tracker):
|
||||||
Tracker.__init__(self,children=[self.trans,m,self.cube])
|
Tracker.__init__(self,children=[self.trans,m,self.cube])
|
||||||
|
|
||||||
def update(self,line=None,normal=None):
|
def update(self,line=None,normal=None):
|
||||||
import WorkingPlane
|
import WorkingPlane, DraftGeomUtils
|
||||||
from draftlibs import fcgeo
|
|
||||||
if not normal:
|
if not normal:
|
||||||
normal = FreeCAD.DraftWorkingPlane.axis
|
normal = FreeCAD.DraftWorkingPlane.axis
|
||||||
if line:
|
if line:
|
||||||
|
@ -668,10 +665,10 @@ class boxTracker(Tracker):
|
||||||
bp = line[0]
|
bp = line[0]
|
||||||
lvec = line[1].sub(line[0])
|
lvec = line[1].sub(line[0])
|
||||||
else:
|
else:
|
||||||
lvec = fcgeo.vec(line.Shape.Edges[0])
|
lvec = DraftGeomUtils.vec(line.Shape.Edges[0])
|
||||||
bp = line.Shape.Edges[0].Vertexes[0].Point
|
bp = line.Shape.Edges[0].Vertexes[0].Point
|
||||||
elif self.baseline:
|
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
|
bp = self.baseline.Shape.Edges[0].Vertexes[0].Point
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
@ -679,12 +676,12 @@ class boxTracker(Tracker):
|
||||||
self.cube.width.setValue(lvec.Length)
|
self.cube.width.setValue(lvec.Length)
|
||||||
p = WorkingPlane.getPlacementFromPoints([bp,bp.add(lvec),bp.add(right)])
|
p = WorkingPlane.getPlacementFromPoints([bp,bp.add(lvec),bp.add(right)])
|
||||||
self.trans.rotation.setValue(p.Rotation.Q)
|
self.trans.rotation.setValue(p.Rotation.Q)
|
||||||
bp = bp.add(fcvec.scale(lvec,0.5))
|
bp = bp.add(DraftVecUtils.scale(lvec,0.5))
|
||||||
bp = bp.add(fcvec.scaleTo(normal,self.cube.depth.getValue()/2))
|
bp = bp.add(DraftVecUtils.scaleTo(normal,self.cube.depth.getValue()/2))
|
||||||
self.pos(bp)
|
self.pos(bp)
|
||||||
|
|
||||||
def pos(self,p):
|
def pos(self,p):
|
||||||
self.trans.translation.setValue(fcvec.tup(p))
|
self.trans.translation.setValue(DraftVecUtils.tup(p))
|
||||||
|
|
||||||
def width(self,w=None):
|
def width(self,w=None):
|
||||||
if w:
|
if w:
|
||||||
|
|
|
@ -13,6 +13,8 @@ data_DATA = \
|
||||||
DraftGui.py \
|
DraftGui.py \
|
||||||
DraftSnap.py \
|
DraftSnap.py \
|
||||||
DraftTrackers.py \
|
DraftTrackers.py \
|
||||||
|
DraftVecUtils.py \
|
||||||
|
DraftGeomUtils.py \
|
||||||
WorkingPlane.py \
|
WorkingPlane.py \
|
||||||
importOCA.py \
|
importOCA.py \
|
||||||
importDXF.py \
|
importDXF.py \
|
||||||
|
@ -28,8 +30,6 @@ nobase_data_DATA = \
|
||||||
draftlibs/dxfImportObjects.py \
|
draftlibs/dxfImportObjects.py \
|
||||||
draftlibs/dxfLibrary.py \
|
draftlibs/dxfLibrary.py \
|
||||||
draftlibs/dxfReader.py \
|
draftlibs/dxfReader.py \
|
||||||
draftlibs/fcvec.py \
|
|
||||||
draftlibs/fcgeo.py \
|
|
||||||
draftlibs/__init__.py
|
draftlibs/__init__.py
|
||||||
|
|
||||||
CLEANFILES = $(BUILT_SOURCES)
|
CLEANFILES = $(BUILT_SOURCES)
|
||||||
|
|
|
@ -22,9 +22,8 @@
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
import FreeCAD, FreeCADGui, math
|
import FreeCAD, FreeCADGui, math, DraftVecUtils
|
||||||
from FreeCAD import Vector
|
from FreeCAD import Vector
|
||||||
from draftlibs import fcvec
|
|
||||||
|
|
||||||
__title__="FreeCAD Working Plane utility"
|
__title__="FreeCAD Working Plane utility"
|
||||||
__author__ = "Ken Cline"
|
__author__ = "Ken Cline"
|
||||||
|
@ -51,7 +50,7 @@ class plane:
|
||||||
self.stored = None
|
self.stored = None
|
||||||
|
|
||||||
def __repr__(self):
|
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):
|
def offsetToPoint(self, p, direction=None):
|
||||||
'''
|
'''
|
||||||
|
@ -96,10 +95,10 @@ class plane:
|
||||||
self.doc = FreeCAD.ActiveDocument
|
self.doc = FreeCAD.ActiveDocument
|
||||||
self.axis = axis;
|
self.axis = axis;
|
||||||
self.axis.normalize()
|
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.u = Vector(0,1,0)
|
||||||
self.v = Vector(0,0,1)
|
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.u = Vector(0,-1,0)
|
||||||
self.v = Vector(0,0,1)
|
self.v = Vector(0,0,1)
|
||||||
elif upvec:
|
elif upvec:
|
||||||
|
@ -109,12 +108,12 @@ class plane:
|
||||||
else:
|
else:
|
||||||
self.v = axis.cross(Vector(1,0,0))
|
self.v = axis.cross(Vector(1,0,0))
|
||||||
self.v.normalize()
|
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)
|
offsetVector = Vector(axis); offsetVector.multiply(offset)
|
||||||
self.position = point.add(offsetVector)
|
self.position = point.add(offsetVector)
|
||||||
self.weak = False
|
self.weak = False
|
||||||
# FreeCAD.Console.PrintMessage("(position = " + str(self.position) + ")\n")
|
# 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):
|
def alignToCurve(self, shape, offset):
|
||||||
if shape.ShapeType == 'Edge':
|
if shape.ShapeType == 'Edge':
|
||||||
|
@ -162,7 +161,7 @@ class plane:
|
||||||
|
|
||||||
def getRotation(self):
|
def getRotation(self):
|
||||||
"returns a placement describing the working plane orientation ONLY"
|
"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)
|
return FreeCAD.Placement(m)
|
||||||
|
|
||||||
def getPlacement(self):
|
def getPlacement(self):
|
||||||
|
@ -197,15 +196,15 @@ class plane:
|
||||||
|
|
||||||
def getLocalCoords(self,point):
|
def getLocalCoords(self,point):
|
||||||
"returns the coordinates of a given point on the working plane"
|
"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
|
x = xv.Length
|
||||||
if xv.getAngle(self.u) > 1:
|
if xv.getAngle(self.u) > 1:
|
||||||
x = -x
|
x = -x
|
||||||
yv = fcvec.project(point,self.v)
|
yv = DraftVecUtils.project(point,self.v)
|
||||||
y = yv.Length
|
y = yv.Length
|
||||||
if yv.getAngle(self.v) > 1:
|
if yv.getAngle(self.v) > 1:
|
||||||
y = -y
|
y = -y
|
||||||
zv = fcvec.project(point,self.axis)
|
zv = DraftVecUtils.project(point,self.axis)
|
||||||
z = zv.Length
|
z = zv.Length
|
||||||
if zv.getAngle(self.axis) > 1:
|
if zv.getAngle(self.axis) > 1:
|
||||||
z = -z
|
z = -z
|
||||||
|
@ -213,9 +212,9 @@ class plane:
|
||||||
|
|
||||||
def getGlobalCoords(self,point):
|
def getGlobalCoords(self,point):
|
||||||
"returns the global coordinates of the given point, taken relatively to this working plane"
|
"returns the global coordinates of the given point, taken relatively to this working plane"
|
||||||
vx = fcvec.scale(self.u,point.x)
|
vx = DraftVecUtils.scale(self.u,point.x)
|
||||||
vy = fcvec.scale(self.v,point.y)
|
vy = DraftVecUtils.scale(self.v,point.y)
|
||||||
vz = fcvec.scale(self.axis,point.z)
|
vz = DraftVecUtils.scale(self.axis,point.z)
|
||||||
return (vx.add(vy)).add(vz)
|
return (vx.add(vy)).add(vz)
|
||||||
|
|
||||||
def getClosestAxis(self,point):
|
def getClosestAxis(self,point):
|
||||||
|
@ -223,9 +222,9 @@ class plane:
|
||||||
ax = point.getAngle(self.u)
|
ax = point.getAngle(self.u)
|
||||||
ay = point.getAngle(self.v)
|
ay = point.getAngle(self.v)
|
||||||
az = point.getAngle(self.axis)
|
az = point.getAngle(self.axis)
|
||||||
bx = point.getAngle(fcvec.neg(self.u))
|
bx = point.getAngle(DraftVecUtils.neg(self.u))
|
||||||
by = point.getAngle(fcvec.neg(self.v))
|
by = point.getAngle(DraftVecUtils.neg(self.v))
|
||||||
bz = point.getAngle(fcvec.neg(self.axis))
|
bz = point.getAngle(DraftVecUtils.neg(self.axis))
|
||||||
b = min(ax,ay,az,bx,by,bz)
|
b = min(ax,ay,az,bx,by,bz)
|
||||||
if b in [ax,bx]:
|
if b in [ax,bx]:
|
||||||
return "x"
|
return "x"
|
||||||
|
|
|
@ -40,8 +40,8 @@ lines, polylines, lwpolylines, circles, arcs,
|
||||||
texts, colors,layers (from groups)
|
texts, colors,layers (from groups)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import FreeCAD, os, Part, math, re, string, Mesh, Draft
|
import FreeCAD, os, Part, math, re, string, Mesh, Draft, DraftVecUtils, DraftGeomUtils
|
||||||
from draftlibs import fcvec, dxfColorMap, dxfLibrary, fcgeo
|
from draftlibs import dxfColorMap, dxfLibrary
|
||||||
from draftlibs.dxfReader import readDXF
|
from draftlibs.dxfReader import readDXF
|
||||||
from Draft import _Dimension, _ViewProviderDimension
|
from Draft import _Dimension, _ViewProviderDimension
|
||||||
from FreeCAD import Vector
|
from FreeCAD import Vector
|
||||||
|
@ -134,10 +134,10 @@ def calcBulge(v1,bulge,v2):
|
||||||
'''
|
'''
|
||||||
chord = v2.sub(v1)
|
chord = v2.sub(v1)
|
||||||
sagitta = (bulge * chord.Length)/2
|
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))
|
perp = chord.cross(Vector(0,0,1))
|
||||||
if not fcvec.isNull(perp): perp.normalize()
|
if not DraftVecUtils.isNull(perp): perp.normalize()
|
||||||
endpoint = fcvec.scale(perp,sagitta)
|
endpoint = DraftVecUtils.scale(perp,sagitta)
|
||||||
return startpoint.add(endpoint)
|
return startpoint.add(endpoint)
|
||||||
|
|
||||||
def getGroup(ob,exportList):
|
def getGroup(ob,exportList):
|
||||||
|
@ -218,7 +218,7 @@ class fcformat:
|
||||||
v1 = FreeCAD.Vector(r1,g1,b1)
|
v1 = FreeCAD.Vector(r1,g1,b1)
|
||||||
v2 = FreeCAD.Vector(r2,g2,b2)
|
v2 = FreeCAD.Vector(r2,g2,b2)
|
||||||
v = v2.sub(v1)
|
v = v2.sub(v1)
|
||||||
v = fcvec.scale(v,0.5)
|
v = DraftVecUtils.scale(v,0.5)
|
||||||
cv = v1.add(v)
|
cv = v1.add(v)
|
||||||
else:
|
else:
|
||||||
c1 = bparams.GetUnsigned("BackgroundColor")
|
c1 = bparams.GetUnsigned("BackgroundColor")
|
||||||
|
@ -348,7 +348,7 @@ def drawLine(line,shapemode=False):
|
||||||
if (len(line.points) > 1):
|
if (len(line.points) > 1):
|
||||||
v1=vec(line.points[0])
|
v1=vec(line.points[0])
|
||||||
v2=vec(line.points[1])
|
v2=vec(line.points[1])
|
||||||
if not fcvec.equals(v1,v2):
|
if not DraftVecUtils.equals(v1,v2):
|
||||||
try:
|
try:
|
||||||
if (fmt.paramstyle >= 4) and (not shapemode):
|
if (fmt.paramstyle >= 4) and (not shapemode):
|
||||||
return Draft.makeWire([v1,v2])
|
return Draft.makeWire([v1,v2])
|
||||||
|
@ -370,11 +370,11 @@ def drawPolyline(polyline,shapemode=False,num=None):
|
||||||
v1 = vec(p1)
|
v1 = vec(p1)
|
||||||
v2 = vec(p2)
|
v2 = vec(p2)
|
||||||
verts.append(v1)
|
verts.append(v1)
|
||||||
if not fcvec.equals(v1,v2):
|
if not DraftVecUtils.equals(v1,v2):
|
||||||
if polyline.points[p].bulge:
|
if polyline.points[p].bulge:
|
||||||
curves = True
|
curves = True
|
||||||
cv = calcBulge(v1,polyline.points[p].bulge,v2)
|
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())
|
try: edges.append(Part.Line(v1,v2).toShape())
|
||||||
except: warn(polyline,num)
|
except: warn(polyline,num)
|
||||||
else:
|
else:
|
||||||
|
@ -390,8 +390,8 @@ def drawPolyline(polyline,shapemode=False,num=None):
|
||||||
v1 = vec(p1)
|
v1 = vec(p1)
|
||||||
v2 = vec(p2)
|
v2 = vec(p2)
|
||||||
cv = calcBulge(v1,polyline.points[-1].bulge,v2)
|
cv = calcBulge(v1,polyline.points[-1].bulge,v2)
|
||||||
if not fcvec.equals(v1,v2):
|
if not DraftVecUtils.equals(v1,v2):
|
||||||
if fcvec.isColinear([v1,cv,v2]):
|
if DraftVecUtils.isColinear([v1,cv,v2]):
|
||||||
try:
|
try:
|
||||||
edges.append(Part.Line(v1,v2).toShape())
|
edges.append(Part.Line(v1,v2).toShape())
|
||||||
except:
|
except:
|
||||||
|
@ -722,11 +722,11 @@ def addText(text,attrib=False):
|
||||||
rz = rawValue(text,31)
|
rz = rawValue(text,31)
|
||||||
if rx or ry or rz:
|
if rx or ry or rz:
|
||||||
xv = Vector(rx,ry,rz)
|
xv = Vector(rx,ry,rz)
|
||||||
if not fcvec.isNull(xv):
|
if not DraftVecUtils.isNull(xv):
|
||||||
ax = fcvec.neg(xv.cross(Vector(1,0,0)))
|
ax = DraftVecUtils.neg(xv.cross(Vector(1,0,0)))
|
||||||
if fcvec.isNull(ax):
|
if DraftVecUtils.isNull(ax):
|
||||||
ax = Vector(0,0,1)
|
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)
|
Draft.rotate(newob,ang,axis=ax)
|
||||||
elif hasattr(text,"rotation"):
|
elif hasattr(text,"rotation"):
|
||||||
if text.rotation:
|
if text.rotation:
|
||||||
|
@ -885,7 +885,7 @@ def processdxf(document,filename):
|
||||||
edges = []
|
edges = []
|
||||||
for s in shapes:
|
for s in shapes:
|
||||||
edges.extend(s.Edges)
|
edges.extend(s.Edges)
|
||||||
shapes = fcgeo.findWires(edges)
|
shapes = DraftGeomUtils.findWires(edges)
|
||||||
for s in shapes:
|
for s in shapes:
|
||||||
newob = addObject(s)
|
newob = addObject(s)
|
||||||
|
|
||||||
|
@ -1198,13 +1198,13 @@ def getArcData(edge):
|
||||||
# check the midpoint seems more reliable
|
# check the midpoint seems more reliable
|
||||||
ve1 = edge.Vertexes[0].Point
|
ve1 = edge.Vertexes[0].Point
|
||||||
ve2 = edge.Vertexes[-1].Point
|
ve2 = edge.Vertexes[-1].Point
|
||||||
ang1 = -math.degrees(fcvec.angle(ve1.sub(ce)))
|
ang1 = -math.degrees(DraftVecUtils.angle(ve1.sub(ce)))
|
||||||
ang2 = -math.degrees(fcvec.angle(ve2.sub(ce)))
|
ang2 = -math.degrees(DraftVecUtils.angle(ve2.sub(ce)))
|
||||||
ve3 = fcgeo.findMidpoint(edge)
|
ve3 = DraftGeomUtils.findMidpoint(edge)
|
||||||
ang3 = -math.degrees(fcvec.angle(ve3.sub(ce)))
|
ang3 = -math.degrees(DraftVecUtils.angle(ve3.sub(ce)))
|
||||||
if (ang3 < ang1) and (ang2 < ang3):
|
if (ang3 < ang1) and (ang2 < ang3):
|
||||||
ang1, ang2 = ang2, ang1
|
ang1, ang2 = ang2, ang1
|
||||||
return fcvec.tup(ce), radius, ang1, ang2
|
return DraftVecUtils.tup(ce), radius, ang1, ang2
|
||||||
|
|
||||||
def getSplineSegs(edge):
|
def getSplineSegs(edge):
|
||||||
"returns an array of vectors from a bSpline edge"
|
"returns an array of vectors from a bSpline edge"
|
||||||
|
@ -1228,18 +1228,18 @@ def getSplineSegs(edge):
|
||||||
|
|
||||||
def getWire(wire,nospline=False):
|
def getWire(wire,nospline=False):
|
||||||
"returns an array of dxf-ready points and bulges from a wire"
|
"returns an array of dxf-ready points and bulges from a wire"
|
||||||
edges = fcgeo.sortEdges(wire.Edges)
|
edges = DraftGeomUtils.sortEdges(wire.Edges)
|
||||||
points = []
|
points = []
|
||||||
for edge in edges:
|
for edge in edges:
|
||||||
v1 = edge.Vertexes[0].Point
|
v1 = edge.Vertexes[0].Point
|
||||||
if len(edge.Vertexes) < 2:
|
if len(edge.Vertexes) < 2:
|
||||||
points.append((v1.x,v1.y,v1.z,None,None,0.0))
|
points.append((v1.x,v1.y,v1.z,None,None,0.0))
|
||||||
elif (isinstance(edge.Curve,Part.Circle)):
|
elif (isinstance(edge.Curve,Part.Circle)):
|
||||||
mp = fcgeo.findMidpoint(edge)
|
mp = DraftGeomUtils.findMidpoint(edge)
|
||||||
v2 = edge.Vertexes[-1].Point
|
v2 = edge.Vertexes[-1].Point
|
||||||
c = edge.Curve.Center
|
c = edge.Curve.Center
|
||||||
angle = abs(fcvec.angle(v1.sub(c),v2.sub(c)))
|
angle = abs(DraftVecUtils.angle(v1.sub(c),v2.sub(c)))
|
||||||
# if (fcvec.angle(v2.sub(c)) < fcvec.angle(v1.sub(c))):
|
# if (DraftVecUtils.angle(v2.sub(c)) < DraftVecUtils.angle(v1.sub(c))):
|
||||||
# angle = -angle
|
# angle = -angle
|
||||||
# polyline bulge -> negative makes the arc go clockwise
|
# polyline bulge -> negative makes the arc go clockwise
|
||||||
bul = math.tan(angle/4)
|
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))
|
points.append((p.x,p.y,p.z,None,None,0.0))
|
||||||
else:
|
else:
|
||||||
points.append((v1.x,v1.y,v1.z,None,None,0.0))
|
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
|
v = edges[-1].Vertexes[-1].Point
|
||||||
points.append(fcvec.tup(v))
|
points.append(DraftVecUtils.tup(v))
|
||||||
# print "wire verts: ",points
|
# print "wire verts: ",points
|
||||||
return points
|
return points
|
||||||
|
|
||||||
|
@ -1289,7 +1289,7 @@ def writeShape(ob,dxfobject,nospline=False):
|
||||||
layer=getGroup(ob,exportList)))
|
layer=getGroup(ob,exportList)))
|
||||||
else:
|
else:
|
||||||
dxfobject.append(dxfLibrary.PolyLine(getWire(wire,nospline), [0.0,0.0,0.0],
|
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)))
|
layer=getGroup(ob,exportList)))
|
||||||
if len(processededges) < len(ob.Shape.Edges): # lone edges
|
if len(processededges) < len(ob.Shape.Edges): # lone edges
|
||||||
loneedges = []
|
loneedges = []
|
||||||
|
@ -1318,7 +1318,7 @@ def writeShape(ob,dxfobject,nospline=False):
|
||||||
else: # anything else is treated as lines
|
else: # anything else is treated as lines
|
||||||
ve1=edge.Vertexes[0].Point
|
ve1=edge.Vertexes[0].Point
|
||||||
ve2=edge.Vertexes[1].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),
|
color=getACI(ob),
|
||||||
layer=getGroup(ob,exportList)))
|
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
|
# 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...
|
# well, anyway, at the moment, Draft only writes single-line texts, so...
|
||||||
for text in ob.LabelText:
|
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.y-ob.LabelText.index(text),
|
||||||
ob.Position.z))
|
ob.Position.z))
|
||||||
if gui: height = float(ob.ViewObject.FontSize)
|
if gui: height = float(ob.ViewObject.FontSize)
|
||||||
|
@ -1388,14 +1388,14 @@ def export(objectslist,filename,nospline=False):
|
||||||
layer=getGroup(ob,exportList)))
|
layer=getGroup(ob,exportList)))
|
||||||
|
|
||||||
elif 'Dimline' in ob.PropertiesList:
|
elif 'Dimline' in ob.PropertiesList:
|
||||||
p1 = fcvec.tup(ob.Start)
|
p1 = DraftVecUtils.tup(ob.Start)
|
||||||
p2 = fcvec.tup(ob.End)
|
p2 = DraftVecUtils.tup(ob.End)
|
||||||
base = Part.Line(ob.Start,ob.End).toShape()
|
base = Part.Line(ob.Start,ob.End).toShape()
|
||||||
proj = fcgeo.findDistance(ob.Dimline,base)
|
proj = DraftGeomUtils.findDistance(ob.Dimline,base)
|
||||||
if not proj:
|
if not proj:
|
||||||
pbase = fcvec.tup(ob.End)
|
pbase = DraftVecUtils.tup(ob.End)
|
||||||
else:
|
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),
|
dxf.append(dxfLibrary.Dimension(pbase,p1,p2,color=getACI(ob),
|
||||||
layer=getGroup(ob,exportList)))
|
layer=getGroup(ob,exportList)))
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,7 @@ __url__ = ["http://yorik.orgfree.com","http://free-cad.sourceforge.net"]
|
||||||
This script imports OCA/gcad files into FreeCAD.
|
This script imports OCA/gcad files into FreeCAD.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import FreeCAD, os, Part, math
|
import FreeCAD, os, Part, math, DraftVecUtils, DraftGeomUtils
|
||||||
from draftlibs import fcvec, fcgeo
|
|
||||||
from FreeCAD import Vector
|
from FreeCAD import Vector
|
||||||
|
|
||||||
try: import FreeCADGui
|
try: import FreeCADGui
|
||||||
|
@ -56,7 +55,7 @@ def getpoint(data):
|
||||||
if (data[1][0] == "R"):
|
if (data[1][0] == "R"):
|
||||||
return objects[data[0]].add(objects[data[1]])
|
return objects[data[0]].add(objects[data[1]])
|
||||||
elif (data[1][0] == "C"):
|
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"):
|
elif (data[0][0] == "C"):
|
||||||
if objects[data[0]]:
|
if objects[data[0]]:
|
||||||
p1 = objects[data[0]].Curve.Position
|
p1 = objects[data[0]].Curve.Position
|
||||||
|
@ -65,7 +64,7 @@ def getpoint(data):
|
||||||
else:
|
else:
|
||||||
if (data[1][0] == "L"):
|
if (data[1][0] == "L"):
|
||||||
l = objects[data[1]]
|
l = objects[data[1]]
|
||||||
return p1.add(fcgeo.vec(l))
|
return p1.add(DraftGeomUtils.vec(l))
|
||||||
|
|
||||||
def getarea(data):
|
def getarea(data):
|
||||||
"turns an OCA area definition into a FreeCAD Part Wire"
|
"turns an OCA area definition into a FreeCAD Part Wire"
|
||||||
|
@ -111,7 +110,7 @@ def getarc(data):
|
||||||
c = Part.Circle()
|
c = Part.Circle()
|
||||||
c.Center = verts[0]
|
c.Center = verts[0]
|
||||||
if rad: c.Radius = rad
|
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"):
|
elif (data[0][0] == "L"):
|
||||||
# 2-lines circle
|
# 2-lines circle
|
||||||
lines = []
|
lines = []
|
||||||
|
@ -121,7 +120,7 @@ def getarc(data):
|
||||||
rad = float(data[p+1])
|
rad = float(data[p+1])
|
||||||
elif (data[p][0] == "L"):
|
elif (data[p][0] == "L"):
|
||||||
lines.append(objects[data[p]])
|
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 circles: c = circles[0]
|
||||||
if c: return c.toShape()
|
if c: return c.toShape()
|
||||||
|
|
||||||
|
@ -268,7 +267,7 @@ def export(exportList,filename):
|
||||||
oca.write("C"+str(count)+"=ARC ")
|
oca.write("C"+str(count)+"=ARC ")
|
||||||
oca.write(writepoint(e.Vertexes[0].Point))
|
oca.write(writepoint(e.Vertexes[0].Point))
|
||||||
oca.write(" ")
|
oca.write(" ")
|
||||||
oca.write(writepoint(fcgeo.findMidpoint(e)))
|
oca.write(writepoint(DraftGeomUtils.findMidpoint(e)))
|
||||||
oca.write(" ")
|
oca.write(" ")
|
||||||
oca.write(writepoint(e.Vertexes[-1].Point))
|
oca.write(writepoint(e.Vertexes[-1].Point))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -38,9 +38,7 @@ currently unsupported: use, image
|
||||||
# implement inherting fill style from group
|
# implement inherting fill style from group
|
||||||
# handle relative units
|
# handle relative units
|
||||||
|
|
||||||
import xml.sax, string, FreeCAD, os, math, re, Draft
|
import xml.sax, string, FreeCAD, os, math, re, Draft, DraftVecUtils, DraftGeomUtils
|
||||||
from draftlibs import fcvec
|
|
||||||
from draftlibs import fcgeo
|
|
||||||
from FreeCAD import Vector
|
from FreeCAD import Vector
|
||||||
|
|
||||||
try: import FreeCADGui
|
try: import FreeCADGui
|
||||||
|
@ -271,7 +269,7 @@ def makewire(path,checkclosed=False,donttry=False):
|
||||||
#ToDo Do not catch all exceptions
|
#ToDo Do not catch all exceptions
|
||||||
if not donttry:
|
if not donttry:
|
||||||
try:
|
try:
|
||||||
sh = Part.Wire(fcgeo.sortEdges(path))
|
sh = Part.Wire(DraftGeomUtils.sortEdges(path))
|
||||||
#sh = Part.Wire(path)
|
#sh = Part.Wire(path)
|
||||||
isok = (not checkclosed) or sh.isClosed()
|
isok = (not checkclosed) or sh.isClosed()
|
||||||
except:# BRep_API:command not done
|
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=FreeCAD.Matrix()
|
||||||
m2.rotateZ(xrotation)
|
m2.rotateZ(xrotation)
|
||||||
centeroff = currentvec.add(lastvec)
|
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
|
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
|
#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
|
#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
|
#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
|
angle1 = DraftVecUtils.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
|
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))
|
results.append((vcenter,angle1,angledelta))
|
||||||
return results,(rx,ry)
|
return results,(rx,ry)
|
||||||
|
|
||||||
|
@ -558,7 +556,7 @@ class svgHandler(xml.sax.ContentHandler):
|
||||||
currentvec = lastvec.add(Vector(x,-y,0))
|
currentvec = lastvec.add(Vector(x,-y,0))
|
||||||
else:
|
else:
|
||||||
currentvec = Vector(x,-y,0)
|
currentvec = Vector(x,-y,0)
|
||||||
if not fcvec.equals(lastvec,currentvec):
|
if not DraftVecUtils.equals(lastvec,currentvec):
|
||||||
seg = Part.Line(lastvec,currentvec).toShape()
|
seg = Part.Line(lastvec,currentvec).toShape()
|
||||||
FreeCAD.Console.PrintMessage("line %s %s\n" %(lastvec,currentvec))
|
FreeCAD.Console.PrintMessage("line %s %s\n" %(lastvec,currentvec))
|
||||||
lastvec = currentvec
|
lastvec = currentvec
|
||||||
|
@ -599,15 +597,15 @@ class svgHandler(xml.sax.ContentHandler):
|
||||||
# here is a better way to find the perpendicular
|
# here is a better way to find the perpendicular
|
||||||
if sweepflag == 1:
|
if sweepflag == 1:
|
||||||
# clockwise
|
# clockwise
|
||||||
perp = fcvec.rotate2D(chord,-math.pi/2)
|
perp = DraftVecUtils.rotate2D(chord,-math.pi/2)
|
||||||
else:
|
else:
|
||||||
# anticlockwise
|
# anticlockwise
|
||||||
perp = fcvec.rotate2D(chord,math.pi/2)
|
perp = DraftVecUtils.rotate2D(chord,math.pi/2)
|
||||||
chord = fcvec.scale(chord,.5)
|
chord = DraftVecUtils.scale(chord,.5)
|
||||||
if chord.Length > rx: a = 0
|
if chord.Length > rx: a = 0
|
||||||
else: a = math.sqrt(rx**2-chord.Length**2)
|
else: a = math.sqrt(rx**2-chord.Length**2)
|
||||||
s = rx - a
|
s = rx - a
|
||||||
perp = fcvec.scale(perp,s/perp.Length)
|
perp = DraftVecUtils.scale(perp,s/perp.Length)
|
||||||
midpoint = lastvec.add(chord.add(perp))
|
midpoint = lastvec.add(chord.add(perp))
|
||||||
seg = Part.Arc(lastvec,midpoint,currentvec).toShape()
|
seg = Part.Arc(lastvec,midpoint,currentvec).toShape()
|
||||||
else:# big arc or elliptical arc
|
else:# big arc or elliptical arc
|
||||||
|
@ -676,7 +674,7 @@ class svgHandler(xml.sax.ContentHandler):
|
||||||
currentvec = Vector(x,-y,0)
|
currentvec = Vector(x,-y,0)
|
||||||
pole2 = Vector(p2x,-p2y,0)
|
pole2 = Vector(p2x,-p2y,0)
|
||||||
|
|
||||||
if not fcvec.equals(currentvec,lastvec):
|
if not DraftVecUtils.equals(currentvec,lastvec):
|
||||||
mainv = currentvec.sub(lastvec)
|
mainv = currentvec.sub(lastvec)
|
||||||
pole1v = lastvec.add(pole1)
|
pole1v = lastvec.add(pole1)
|
||||||
pole2v = currentvec.add(pole2)
|
pole2v = currentvec.add(pole2)
|
||||||
|
@ -718,7 +716,7 @@ class svgHandler(xml.sax.ContentHandler):
|
||||||
else:
|
else:
|
||||||
currentvec = Vector(x,-y,0)
|
currentvec = Vector(x,-y,0)
|
||||||
|
|
||||||
if not fcvec.equals(currentvec,lastvec):
|
if not DraftVecUtils.equals(currentvec,lastvec):
|
||||||
if True and \
|
if True and \
|
||||||
pole.distanceToLine(lastvec,currentvec) < 20**(-1*(2+Draft.precision())):
|
pole.distanceToLine(lastvec,currentvec) < 20**(-1*(2+Draft.precision())):
|
||||||
#print "straight segment"
|
#print "straight segment"
|
||||||
|
@ -733,7 +731,7 @@ class svgHandler(xml.sax.ContentHandler):
|
||||||
lastpole = ('quadratic',pole)
|
lastpole = ('quadratic',pole)
|
||||||
path.append(seg)
|
path.append(seg)
|
||||||
elif (d == "Z") or (d == "z"):
|
elif (d == "Z") or (d == "z"):
|
||||||
if not fcvec.equals(lastvec,firstvec):
|
if not DraftVecUtils.equals(lastvec,firstvec):
|
||||||
seg = Part.Line(lastvec,firstvec).toShape()
|
seg = Part.Line(lastvec,firstvec).toShape()
|
||||||
path.append(seg)
|
path.append(seg)
|
||||||
if path: #the path should be closed by now
|
if path: #the path should be closed by now
|
||||||
|
@ -821,7 +819,7 @@ class svgHandler(xml.sax.ContentHandler):
|
||||||
esh.append(arc.toShape())
|
esh.append(arc.toShape())
|
||||||
for esh1,esh2 in zip(esh[-1:]+esh[:-1],esh):
|
for esh1,esh2 in zip(esh[-1:]+esh[:-1],esh):
|
||||||
p1,p2 = esh1.Vertexes[-1].Point,esh2.Vertexes[0].Point
|
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(Part.Line(esh1.Vertexes[-1].Point,esh2.Vertexes[0].Point).toShape()) #straight segments
|
||||||
edges.append(esh2) # elliptical segments
|
edges.append(esh2) # elliptical segments
|
||||||
sh = Part.Wire(edges)
|
sh = Part.Wire(edges)
|
||||||
|
@ -859,7 +857,7 @@ class svgHandler(xml.sax.ContentHandler):
|
||||||
points=points+points[:2] # emulate closepath
|
points=points+points[:2] # emulate closepath
|
||||||
for svgx,svgy in zip(points[2::2],points[3::2]):
|
for svgx,svgy in zip(points[2::2],points[3::2]):
|
||||||
currentvec = Vector(svgx,-svgy,0)
|
currentvec = Vector(svgx,-svgy,0)
|
||||||
if not fcvec.equals(lastvec,currentvec):
|
if not DraftVecUtils.equals(lastvec,currentvec):
|
||||||
seg = Part.Line(lastvec,currentvec).toShape()
|
seg = Part.Line(lastvec,currentvec).toShape()
|
||||||
#print "polyline seg ",lastvec,currentvec
|
#print "polyline seg ",lastvec,currentvec
|
||||||
lastvec = currentvec
|
lastvec = currentvec
|
||||||
|
|
|
@ -38,6 +38,8 @@
|
||||||
<File Id="WorkingPlanePy" Name="WorkingPlane.py" DiskId="1" />
|
<File Id="WorkingPlanePy" Name="WorkingPlane.py" DiskId="1" />
|
||||||
<File Id="macrosPy" Name="macros.py" DiskId="1" />
|
<File Id="macrosPy" Name="macros.py" DiskId="1" />
|
||||||
<File Id="DraftRcPy" Name="Draft_rc.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>
|
</Component>
|
||||||
<Directory Id="ModDraftLib" Name="draftlibs" FileSource="../../Mod/Draft/draftlibs">
|
<Directory Id="ModDraftLib" Name="draftlibs" FileSource="../../Mod/Draft/draftlibs">
|
||||||
<Component Id="CompModDraftLib" Guid="d19c08b0-0747-11de-8c30-0800200c9a66" Win64='$(var.Win_64)' KeyPath="yes">
|
<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="DraftLibdxfImportObjectsPy" Name="dxfImportObjects.py" DiskId="1" />
|
||||||
<File Id="DraftLibdxfLibraryPy" Name="dxfLibrary.py" DiskId="1" />
|
<File Id="DraftLibdxfLibraryPy" Name="dxfLibrary.py" DiskId="1" />
|
||||||
<File Id="DraftLibdxfReaderPy" Name="dxfReader.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>
|
</Component>
|
||||||
</Directory>
|
</Directory>
|
||||||
</Directory>
|
</Directory>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user