Fixed bug #671 - Draft DrawingViews

This commit is contained in:
Yorik van Havre 2012-04-16 19:54:30 -03:00
parent c567271ac1
commit eb0b8fbd32
5 changed files with 36 additions and 30 deletions

View File

@ -171,6 +171,16 @@ def getType(obj):
return "Group"
return "Unknown"
def get3DView():
"get3DView(): returns the current view if it is 3D, or the first 3D view found, or None"
v = FreeCADGui.ActiveDocument.ActiveView
if str(type(v)) == "<type 'View3DInventorPy'>":
return v
v = FreeCADGui.ActiveDocument.mdiViewsOfType("Gui::View3DInventor")
if v:
return v[0]
return None
def isClone(obj,objtype):
"""isClone(obj,objtype): returns True if the given object is
a clone of an object of the given type"""
@ -1794,12 +1804,12 @@ class _ViewProviderDimension:
if not proj: norm = Vector(0,0,1)
else: norm = fcvec.neg(p3.sub(p2).cross(proj))
norm.normalize()
va = FreeCADGui.ActiveDocument.ActiveView.getViewDirection()
va = get3DView.getViewDirection()
if va.getAngle(norm) < math.pi/2:
norm = fcvec.neg(norm)
u = p3.sub(p2)
u.normalize()
c = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
c = get3DView.getCameraNode()
r = c.orientation.getValue()
ru = Vector(r.multVec(coin.SbVec3f(1,0,0)).getValue())
if ru.getAngle(u) > math.pi/2: u = fcvec.neg(u)

View File

@ -174,7 +174,7 @@ class Snapper:
point = self.getApparentPoint(screenpos[0],screenpos[1])
# check if we snapped to something
info = FreeCADGui.ActiveDocument.ActiveView.getObjectInfo((screenpos[0],screenpos[1]))
info = Draft.get3DView().getObjectInfo((screenpos[0],screenpos[1]))
# checking if parallel to one of the edges of the last objects or to a polar direction
@ -303,8 +303,9 @@ class Snapper:
def getApparentPoint(self,x,y):
"returns a 3D point, projected on the current working plane"
pt = FreeCADGui.ActiveDocument.ActiveView.getPoint(x,y)
dv = FreeCADGui.ActiveDocument.ActiveView.getViewDirection()
view = Draft.get3DView()
pt = view.getPoint(x,y)
dv = view.getViewDirection()
return FreeCAD.DraftWorkingPlane.projectPoint(pt,dv)
def snapToExtensions(self,point,last,constrain,eline):
@ -559,8 +560,9 @@ class Snapper:
def getScreenDist(self,dist,cursor):
"returns a distance in 3D space from a screen pixels distance"
p1 = FreeCADGui.ActiveDocument.ActiveView.getPoint(cursor)
p2 = FreeCADGui.ActiveDocument.ActiveView.getPoint((cursor[0]+dist,cursor[1]))
view = Draft.get3DView()
p1 = view.getPoint(cursor)
p2 = view.getPoint((cursor[0]+dist,cursor[1]))
return (p2.sub(p1)).Length
def getPerpendicular(self,edge,pt):
@ -704,7 +706,7 @@ class Snapper:
self.pt = None
self.ui = FreeCADGui.draftToolBar
self.view = FreeCADGui.ActiveDocument.ActiveView
self.view = Draft.get3DView()
# setting a track line if we got an existing point
if last:

View File

@ -103,9 +103,6 @@ def msg(text=None,mode=None):
else:
FreeCAD.Console.PrintMessage(text)
def get3DView():
return FreeCADGui.ActiveDocument.mdiViewsOfType("Gui::View3DInventor")[0]
def selectObject(arg):
'''this is a scene even handler, to be called from the Draft tools
when they need to select an object'''
@ -116,7 +113,7 @@ def selectObject(arg):
if (arg["Type"] == "SoMouseButtonEvent"):
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
cursor = arg["Position"]
snapped = FreeCADGui.ActiveDocument.ActiveView.getObjectInfo((cursor[0],cursor[1]))
snapped = Draft.get3DView().getObjectInfo((cursor[0],cursor[1]))
if snapped:
obj = FreeCAD.ActiveDocument.getObject(snapped['Object'])
FreeCADGui.Selection.addSelection(obj)
@ -134,7 +131,7 @@ def getPoint(target,args,mobile=False,sym=False,workingplane=True):
'''
ui = FreeCADGui.draftToolBar
view = FreeCADGui.ActiveDocument.ActiveView
view = Draft.get3DView()
# get point
if target.node:
@ -149,8 +146,8 @@ def getPoint(target,args,mobile=False,sym=False,workingplane=True):
if (not plane.weak) and workingplane:
# working plane was explicitely selected - project onto it
viewDirection = view.getViewDirection()
if FreeCADGui.ActiveDocument.ActiveView.getCameraType() == "Perspective":
camera = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
if view.getCameraType() == "Perspective":
camera = view.getCameraNode()
p = camera.getField("position").getValue()
# view is from camera to point:
viewDirection = point.sub(Vector(p[0],p[1],p[2]))
@ -173,7 +170,7 @@ def getPoint(target,args,mobile=False,sym=False,workingplane=True):
def getSupport(args):
"returns the supporting object and sets the working plane"
snapped = FreeCADGui.ActiveDocument.ActiveView.getObjectInfo((args["Position"][0],args["Position"][1]))
snapped = Draft.get3DView().getObjectInfo((args["Position"][0],args["Position"][1]))
if not snapped: return None
obj = None
plane.save()
@ -234,7 +231,7 @@ class SelectPlane:
self.doc = FreeCAD.ActiveDocument
if self.doc:
FreeCAD.activeDraftCommand = self
self.view = FreeCADGui.ActiveDocument.ActiveView
self.view = Draft.get3DView()
self.ui = FreeCADGui.draftToolBar
self.ui.selectPlaneUi()
msg(translate("draft", "Pick a face to define the drawing plane\n"))
@ -253,7 +250,7 @@ class SelectPlane:
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
cursor = arg["Position"]
doc = FreeCADGui.ActiveDocument
info = doc.ActiveView.getObjectInfo((cursor[0],cursor[1]))
info = Draft.get3DView().getObjectInfo((cursor[0],cursor[1]))
if info:
try:
shape = doc.getObject(info["Object"]).Object.Shape
@ -336,7 +333,7 @@ class Creator:
self.support = None
self.commitList = []
self.doc = FreeCAD.ActiveDocument
self.view = FreeCADGui.ActiveDocument.ActiveView
self.view = Draft.get3DView()
self.featureName = name
if not self.doc:
self.finish()
@ -1660,7 +1657,7 @@ class Modifier:
self.finish()
else:
FreeCAD.activeDraftCommand = self
self.view = get3DView()
self.view = Draft.get3DView()
self.ui = FreeCADGui.draftToolBar
FreeCADGui.draftToolBar.show()
rot = self.view.getCameraNode().getField("orientation").getValue()
@ -3650,7 +3647,7 @@ class Point:
return False
def Activated(self):
self.view = FreeCADGui.ActiveDocument.ActiveView
self.view = Draft.get3DView()
self.stack = []
self.point = None
# adding 2 callback functions

View File

@ -60,13 +60,10 @@ class Tracker:
todo.delay(self._removeSwitch, self.switch)
self.switch = None
def get3DView(self):
return FreeCADGui.ActiveDocument.mdiViewsOfType("Gui::View3DInventor")[0]
def _insertSwitch(self, switch):
'''insert self.switch into the scene graph. Must not be called
from an event handler (or other scene graph traversal).'''
sg=self.get3DView().getSceneGraph()
sg=Draft.get3DView().getSceneGraph()
if self.ontop:
sg.insertChild(switch,0)
else:
@ -75,7 +72,7 @@ class Tracker:
def _removeSwitch(self, switch):
'''remove self.switch from the scene graph. As with _insertSwitch,
must not be called during scene graph traversal).'''
sg=self.get3DView().getSceneGraph()
sg=Draft.get3DView().getSceneGraph()
sg.removeChild(switch)
def on(self):
@ -454,8 +451,8 @@ class PlaneTracker(Tracker):
"A working plane tracker"
def __init__(self):
# getting screen distance
p1 = self.get3DView().getPoint((100,100))
p2 = self.get3DView().getPoint((110,100))
p1 = Draft.get3DView().getPoint((100,100))
p2 = Draft.get3DView().getPoint((110,100))
bl = (p2.sub(p1)).Length * (Draft.getParam("snapRange")/2)
self.trans = coin.SoTransform()
self.trans.translation.setValue([0,0,0])

View File

@ -704,8 +704,8 @@ def getNormal(shape):
n = e1.cross(e2).normalize()
break
if FreeCAD.GuiUp:
import FreeCADGui
vdir = FreeCADGui.ActiveDocument.ActiveView.getViewDirection()
import Draft
vdir = Draft.get3DView().getViewDirection()
if n.getAngle(vdir) < 0.78: n = fcvec.neg(n)
return n