Fixed 0000660: Draft radial dimensions
This commit is contained in:
parent
da1a42e2ee
commit
3baa98cd90
|
@ -451,13 +451,25 @@ def makeDimension(p1,p2,p3=None,p4=None):
|
|||
'''
|
||||
obj = FreeCAD.ActiveDocument.addObject("App::FeaturePython","Dimension")
|
||||
_Dimension(obj)
|
||||
if gui:
|
||||
_ViewProviderDimension(obj.ViewObject)
|
||||
if isinstance(p1,Vector) and isinstance(p2,Vector):
|
||||
obj.Start = p1
|
||||
obj.End = p2
|
||||
if not p3:
|
||||
p3 = p2.sub(p1)
|
||||
p3.multiply(0.5)
|
||||
p3 = p1.add(p3)
|
||||
elif isinstance(p2,int) and isinstance(p3,int):
|
||||
obj.Base = p1
|
||||
obj.LinkedVertices = [p2,p3]
|
||||
obj.LinkedVertices = idx = [p2,p3]
|
||||
p3 = p4
|
||||
if not p3:
|
||||
v1 = obj.Base.Shape.Vertexes[idx[0]].Point
|
||||
v2 = obj.Base.Shape.Vertexes[idx[1]].Point
|
||||
p3 = v2.sub(v1)
|
||||
p3.multiply(0.5)
|
||||
p3 = v1.add(p3)
|
||||
elif isinstance(p3,str):
|
||||
obj.Base = p1
|
||||
if p3 == "radius":
|
||||
|
@ -467,13 +479,10 @@ def makeDimension(p1,p2,p3=None,p4=None):
|
|||
obj.LinkedVertices = [p2,2,1]
|
||||
obj.ViewObject.Override = "ddim"
|
||||
p3 = p4
|
||||
if not p3:
|
||||
p3 = p2.sub(p1)
|
||||
p3.multiply(0.5)
|
||||
p3 = p1.add(p3)
|
||||
if not p3:
|
||||
p3 = obj.Base.Shape.Edges[0].Curve.Center.add(Vector(1,0,0))
|
||||
obj.Dimline = p3
|
||||
if gui:
|
||||
_ViewProviderDimension(obj.ViewObject)
|
||||
formatObject(obj)
|
||||
select(obj)
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
@ -1806,7 +1815,8 @@ class _ViewProviderDimension:
|
|||
proj = ed.cross(Vector(0,0,1))
|
||||
if not proj: norm = Vector(0,0,1)
|
||||
else: norm = fcvec.neg(p3.sub(p2).cross(proj))
|
||||
norm.normalize()
|
||||
if not fcvec.isNull(norm):
|
||||
norm.normalize()
|
||||
va = get3DView().getViewDirection()
|
||||
if va.getAngle(norm) < math.pi/2:
|
||||
norm = fcvec.neg(norm)
|
||||
|
|
|
@ -71,6 +71,7 @@ class Snapper:
|
|||
self.grid = None
|
||||
self.constrainLine = None
|
||||
self.trackLine = None
|
||||
self.snapInfo = None
|
||||
self.lastSnappedObject = None
|
||||
self.active = True
|
||||
self.trackers = [[],[],[],[]] # view, grid, snap, extline
|
||||
|
@ -132,6 +133,7 @@ class Snapper:
|
|||
return point
|
||||
|
||||
snaps = []
|
||||
self.snapInfo = None
|
||||
|
||||
# type conversion if needed
|
||||
if isinstance(screenpos,list):
|
||||
|
@ -186,7 +188,7 @@ class Snapper:
|
|||
point = self.getApparentPoint(screenpos[0],screenpos[1])
|
||||
|
||||
# check if we snapped to something
|
||||
info = Draft.get3DView().getObjectInfo((screenpos[0],screenpos[1]))
|
||||
self.snapInfo = Draft.get3DView().getObjectInfo((screenpos[0],screenpos[1]))
|
||||
|
||||
# checking if parallel to one of the edges of the last objects or to a polar direction
|
||||
|
||||
|
@ -195,7 +197,7 @@ class Snapper:
|
|||
point,eline = self.snapToPolar(point,lastpoint)
|
||||
point,eline = self.snapToExtensions(point,lastpoint,constrain,eline)
|
||||
|
||||
if not info:
|
||||
if not self.snapInfo:
|
||||
|
||||
# nothing has been snapped, check fro grid snap
|
||||
if active:
|
||||
|
@ -206,7 +208,7 @@ class Snapper:
|
|||
|
||||
# we have an object to snap to
|
||||
|
||||
obj = FreeCAD.ActiveDocument.getObject(info['Object'])
|
||||
obj = FreeCAD.ActiveDocument.getObject(self.snapInfo['Object'])
|
||||
if not obj:
|
||||
return cstr(point)
|
||||
|
||||
|
@ -219,12 +221,12 @@ class Snapper:
|
|||
if not active:
|
||||
|
||||
# passive snapping
|
||||
snaps = [self.snapToVertex(info)]
|
||||
snaps = [self.snapToVertex(self.snapInfo)]
|
||||
|
||||
else:
|
||||
|
||||
# active snapping
|
||||
comp = info['Component']
|
||||
comp = self.snapInfo['Component']
|
||||
|
||||
if (Draft.getType(obj) == "Wall") and not oldActive:
|
||||
edges = []
|
||||
|
@ -258,13 +260,13 @@ class Snapper:
|
|||
|
||||
elif "Vertex" in comp:
|
||||
# directly snapped to a vertex
|
||||
snaps.append(self.snapToVertex(info,active=True))
|
||||
snaps.append(self.snapToVertex(self.snapInfo,active=True))
|
||||
elif comp == '':
|
||||
# workaround for the new view provider
|
||||
snaps.append(self.snapToVertex(info,active=True))
|
||||
snaps.append(self.snapToVertex(self.snapInfo,active=True))
|
||||
else:
|
||||
# all other cases (face, etc...) default to passive snap
|
||||
snapArray = [self.snapToVertex(info)]
|
||||
snapArray = [self.snapToVertex(self.snapInfo)]
|
||||
|
||||
elif Draft.getType(obj) == "Dimension":
|
||||
# for dimensions we snap to their 3 points
|
||||
|
@ -290,7 +292,7 @@ class Snapper:
|
|||
|
||||
# calculating the nearest snap point
|
||||
shortest = 1000000000000000000
|
||||
origin = Vector(info['x'],info['y'],info['z'])
|
||||
origin = Vector(self.snapInfo['x'],self.snapInfo['y'],self.snapInfo['z'])
|
||||
winner = [Vector(0,0,0),None,Vector(0,0,0)]
|
||||
for snap in snaps:
|
||||
# if snap[0] == None: print "debug: Snapper: 'i[0]' is 'None'"
|
||||
|
@ -304,7 +306,7 @@ class Snapper:
|
|||
dv = point.sub(winner[2])
|
||||
if (dv.Length > self.radius):
|
||||
if (not oldActive) and self.isEnabled("passive"):
|
||||
winner = self.snapToVertex(info)
|
||||
winner = self.snapToVertex(self.snapInfo)
|
||||
|
||||
# setting the cursors
|
||||
if self.tracker:
|
||||
|
|
|
@ -143,7 +143,7 @@ def getPoint(target,args,mobile=False,sym=False,workingplane=True):
|
|||
amod = hasMod(args,MODSNAP)
|
||||
cmod = hasMod(args,MODCONSTRAIN)
|
||||
point = FreeCADGui.Snapper.snap(args["Position"],lastpoint=last,active=amod,constrain=cmod)
|
||||
|
||||
info = FreeCADGui.Snapper.snapInfo
|
||||
# project onto working plane if needed
|
||||
if (not plane.weak) and workingplane:
|
||||
# working plane was explicitely selected - project onto it
|
||||
|
@ -168,7 +168,7 @@ def getPoint(target,args,mobile=False,sym=False,workingplane=True):
|
|||
else:
|
||||
ui.displayPoint(point, target.node[-1], plane=plane, mask=mask)
|
||||
else: ui.displayPoint(point, plane=plane, mask=mask)
|
||||
return point,ctrlPoint
|
||||
return point,ctrlPoint,info
|
||||
|
||||
def getSupport(args):
|
||||
"returns the supporting object and sets the working plane"
|
||||
|
@ -436,7 +436,7 @@ class Line(Creator):
|
|||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event":
|
||||
# mouse movement detection
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
self.ui.cross(True)
|
||||
self.linetrack.p2(point)
|
||||
elif arg["Type"] == "SoMouseButtonEvent":
|
||||
|
@ -446,7 +446,7 @@ class Line(Creator):
|
|||
self.finish(False,cont=True)
|
||||
else:
|
||||
if not self.node: self.support = getSupport(arg)
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
self.pos = arg["Position"]
|
||||
self.node.append(point)
|
||||
self.linetrack.p1(point)
|
||||
|
@ -551,7 +551,7 @@ class BSpline(Line):
|
|||
if arg["Key"] == "ESCAPE":
|
||||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event": #mouse movement detection
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
self.ui.cross(True)
|
||||
self.bsplinetrack.update(self.node + [point])
|
||||
# Draw constraint tracker line.
|
||||
|
@ -566,7 +566,7 @@ class BSpline(Line):
|
|||
self.finish(False,cont=True)
|
||||
else:
|
||||
if not self.node: self.support = getSupport(arg)
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
self.pos = arg["Position"]
|
||||
self.node.append(point)
|
||||
self.drawUpdate(point)
|
||||
|
@ -739,7 +739,7 @@ class Rectangle(Creator):
|
|||
if arg["Key"] == "ESCAPE":
|
||||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event": #mouse movement detection
|
||||
point,ctrlPoint = getPoint(self,arg,mobile=True)
|
||||
point,ctrlPoint,info = getPoint(self,arg,mobile=True)
|
||||
self.rect.update(point)
|
||||
self.ui.cross(True)
|
||||
elif arg["Type"] == "SoMouseButtonEvent":
|
||||
|
@ -748,7 +748,7 @@ class Rectangle(Creator):
|
|||
self.finish()
|
||||
else:
|
||||
if not self.node: self.support = getSupport(arg)
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
self.appendPoint(point)
|
||||
|
||||
def numericInput(self,numx,numy,numz):
|
||||
|
@ -840,7 +840,7 @@ class Arc(Creator):
|
|||
if arg["Key"] == "ESCAPE":
|
||||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event":
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
# this is to make sure radius is what you see on screen
|
||||
self.ui.cross(True)
|
||||
if self.center and fcvec.dist(point,self.center) > 0:
|
||||
|
@ -871,10 +871,9 @@ class Arc(Creator):
|
|||
if not self.altdown:
|
||||
self.ui.cross(False)
|
||||
self.altdown = True
|
||||
snapped = self.view.getObjectInfo((arg["Position"][0],arg["Position"][1]))
|
||||
if snapped:
|
||||
ob = self.doc.getObject(snapped['Object'])
|
||||
num = int(snapped['Component'].lstrip('Edge'))-1
|
||||
if info:
|
||||
ob = self.doc.getObject(info['Object'])
|
||||
num = int(info['Component'].lstrip('Edge'))-1
|
||||
ed = ob.Shape.Edges[num]
|
||||
if len(self.tangents) == 2:
|
||||
cir = fcgeo.circleFrom3tan(self.tangents[0], self.tangents[1], ed)
|
||||
|
@ -937,7 +936,7 @@ class Arc(Creator):
|
|||
|
||||
elif arg["Type"] == "SoMouseButtonEvent":
|
||||
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
# this is to make sure radius is what you see on screen
|
||||
if self.center and fcvec.dist(point,self.center) > 0:
|
||||
viewdelta = fcvec.project(point.sub(self.center), plane.axis)
|
||||
|
@ -1132,7 +1131,7 @@ class Polygon(Creator):
|
|||
if arg["Key"] == "ESCAPE":
|
||||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event":
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
# this is to make sure radius is what you see on screen
|
||||
self.ui.cross(True)
|
||||
if self.center and fcvec.dist(point,self.center) > 0:
|
||||
|
@ -1197,7 +1196,7 @@ class Polygon(Creator):
|
|||
|
||||
elif arg["Type"] == "SoMouseButtonEvent":
|
||||
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
# this is to make sure radius is what you see on screen
|
||||
if self.center and fcvec.dist(point,self.center) > 0:
|
||||
viewdelta = fcvec.project(point.sub(self.center), plane.axis)
|
||||
|
@ -1317,10 +1316,10 @@ class Text(Creator):
|
|||
if arg["Key"] == "ESCAPE":
|
||||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event": #mouse movement detection
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
elif arg["Type"] == "SoMouseButtonEvent":
|
||||
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
||||
point,dtrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
self.node.append(point)
|
||||
self.ui.textUi()
|
||||
self.ui.textValue.setFocus()
|
||||
|
@ -1452,7 +1451,7 @@ class Dimension(Creator):
|
|||
shift = hasMod(arg,MODCONSTRAIN)
|
||||
if self.arcmode or self.point2:
|
||||
setMod(arg,MODCONSTRAIN,False)
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
self.ui.cross(True)
|
||||
if hasMod(arg,MODALT) and (len(self.node)<3):
|
||||
self.ui.cross(False)
|
||||
|
@ -1536,15 +1535,14 @@ class Dimension(Creator):
|
|||
self.dimtrack.update(self.node+[point]+[self.cont])
|
||||
elif arg["Type"] == "SoMouseButtonEvent":
|
||||
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
if not self.node: self.support = getSupport(arg)
|
||||
if hasMod(arg,MODALT) and (len(self.node)<3):
|
||||
snapped = self.view.getObjectInfo((arg["Position"][0],arg["Position"][1]))
|
||||
print "snapped: ",snapped
|
||||
if snapped:
|
||||
ob = self.doc.getObject(snapped['Object'])
|
||||
if 'Edge' in snapped['Component']:
|
||||
num = int(snapped['Component'].lstrip('Edge'))-1
|
||||
print "snapped: ",info
|
||||
if info:
|
||||
ob = self.doc.getObject(info['Object'])
|
||||
if 'Edge' in info['Component']:
|
||||
num = int(info['Component'].lstrip('Edge'))-1
|
||||
ed = ob.Shape.Edges[num]
|
||||
v1 = ed.Vertexes[0].Point
|
||||
v2 = ed.Vertexes[-1].Point
|
||||
|
@ -1761,7 +1759,7 @@ class Move(Modifier):
|
|||
if arg["Key"] == "ESCAPE":
|
||||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event": #mouse movement detection
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
self.linetrack.p2(point)
|
||||
self.ui.cross(True)
|
||||
# Draw constraint tracker line.
|
||||
|
@ -1778,7 +1776,7 @@ class Move(Modifier):
|
|||
if not hasMod(arg,MODALT): self.finish()
|
||||
elif arg["Type"] == "SoMouseButtonEvent":
|
||||
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
if (self.node == []):
|
||||
self.node.append(point)
|
||||
self.ui.isRelative.show()
|
||||
|
@ -1922,7 +1920,7 @@ class Rotate(Modifier):
|
|||
if arg["Key"] == "ESCAPE":
|
||||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event":
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
self.ui.cross(True)
|
||||
# this is to make sure radius is what you see on screen
|
||||
if self.center and fcvec.dist(point,self.center):
|
||||
|
@ -1977,7 +1975,7 @@ class Rotate(Modifier):
|
|||
|
||||
elif arg["Type"] == "SoMouseButtonEvent":
|
||||
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
if self.center and fcvec.dist(point,self.center):
|
||||
viewdelta = fcvec.project(point.sub(self.center), plane.axis)
|
||||
if not fcvec.isNull(viewdelta): point = point.add(fcvec.neg(viewdelta))
|
||||
|
@ -2119,7 +2117,7 @@ class Offset(Modifier):
|
|||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event":
|
||||
self.ui.cross(True)
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
if hasMod(arg,MODCONSTRAIN) and self.constrainSeg:
|
||||
dist = fcgeo.findPerpendicular(point,self.shape,self.constrainSeg[1])
|
||||
e = self.shape.Edges[self.constrainSeg[1]]
|
||||
|
@ -2663,7 +2661,7 @@ class Trimex(Modifier):
|
|||
self.shift = hasMod(arg,MODCONSTRAIN)
|
||||
self.alt = hasMod(arg,MODALT)
|
||||
wp = not(self.extrudeMode and self.shift)
|
||||
self.point = getPoint(self,arg,workingplane=wp)[0]
|
||||
self.point,info = getPoint(self,arg,workingplane=wp)[0]
|
||||
if hasMod(arg,MODSNAP): self.snapped = None
|
||||
else: self.snapped = self.view.getObjectInfo((arg["Position"][0],arg["Position"][1]))
|
||||
if self.extrudeMode:
|
||||
|
@ -2929,7 +2927,7 @@ class Scale(Modifier):
|
|||
if arg["Key"] == "ESCAPE":
|
||||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event": #mouse movement detection
|
||||
point,ctrlPoint = getPoint(self,arg,sym=True)
|
||||
point,ctrlPoint,info = getPoint(self,arg,sym=True)
|
||||
self.linetrack.p2(point)
|
||||
self.ui.cross(True)
|
||||
# Draw constraint tracker line.
|
||||
|
@ -2950,7 +2948,7 @@ class Scale(Modifier):
|
|||
if not hasMod(arg,MODALT): self.finish()
|
||||
elif arg["Type"] == "SoMouseButtonEvent":
|
||||
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
||||
point,ctrlPoint = getPoint(self,arg,sym=True)
|
||||
point,ctrlPoint,info = getPoint(self,arg,sym=True)
|
||||
if (self.node == []):
|
||||
self.node.append(point)
|
||||
self.ui.isRelative.show()
|
||||
|
@ -3205,7 +3203,7 @@ class Edit(Modifier):
|
|||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event": #mouse movement detection
|
||||
if self.editing != None:
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
# Draw constraint tracker line.
|
||||
if hasMod(arg,MODCONSTRAIN):
|
||||
self.constraintrack.p1(point)
|
||||
|
@ -3223,7 +3221,7 @@ class Edit(Modifier):
|
|||
sel = sel[0]
|
||||
if sel.ObjectName == self.obj.Name:
|
||||
if self.ui.addButton.isChecked():
|
||||
point,ctrlPoint = getPoint(self,arg)
|
||||
point,ctrlPoint,info = getPoint(self,arg)
|
||||
self.pos = arg["Position"]
|
||||
self.addPoint(point)
|
||||
elif self.ui.delButton.isChecked():
|
||||
|
|
|
@ -1686,7 +1686,7 @@ def circlefrom1Line2Points(edge, p1, p2):
|
|||
v1 = p1.sub(s)
|
||||
v2 = p2.sub(s)
|
||||
projectedDist = math.sqrt(abs(v1.dot(v2)))
|
||||
edgeDir = vec(edge); edgeDir.normailze()
|
||||
edgeDir = vec(edge); edgeDir.normalize()
|
||||
projectedCen1 = Vector.add(s, fcvec.scale(edgeDir, projectedDist))
|
||||
projectedCen2 = Vector.add(s, fcvec.scale(edgeDir, -projectedDist))
|
||||
perpEdgeDir = edgeDir.cross(Vector(0,0,1))
|
||||
|
|
Loading…
Reference in New Issue
Block a user