ViewFromPlacement: fixes

* fix Lattice2 not loading on FC v0.17
* fix look-around when "Rotate At Cursor" is on in preferences.
This commit is contained in:
DeepSOIC 2019-09-20 23:24:58 +03:00
parent 9afda3fe66
commit 1ce974c5df

View File

@ -26,12 +26,77 @@ __author__ = "DeepSOIC"
__url__ = ""
import FreeCAD as App
if App.GuiUp:
import FreeCADGui as Gui
from lattice2Common import *
import lattice2BaseFeature as LBF
import lattice2CompoundExplorer as LCE
import Show
try:
import Show
except ImportError:
Show = None
try:
from Show.SceneDetail import SceneDetail
except ImportError:
SceneDetail = None
from copy import copy
class SDParameter(SceneDetail if SceneDetail is not None else object):
"""SDParameter(param_path, param_name, param_type, param_val = None): Plugin for TempoVis for changing a parameter."""
class_id = 'SDParameter'
mild_restore = True
param_path = ''
param_name = ''
param_type = ''
def __init__(self, param_path, param_name, param_type, param_val = None):
self.key = '{param_path}/[{param_type}]{param_name}'.format(**vars())
self.param_path = param_path
self.param_name = param_name
self.param_type = param_type
if param_val is not None:
self.data = param_val
def scene_value(self):
import FreeCAD as App
hgrp = App.ParamGet(self.param_path)
getter, def1, def2 = {
'Bool' : (hgrp.GetBool , True, False),
'Float' : (hgrp.GetFloat , 1.0, 2.0 ),
'Int' : (hgrp.GetInt , 1, 2 ),
'String' : (hgrp.GetString , 'a', 'b' ),
'Unsigned': (hgrp.GetUnsigned, 1, 2 ),
}[self.param_type]
val1 = getter(self.param_name, def1)
val2 = getter(self.param_name, def2)
absent = val1 == def1 and val2 == def2
return val1 if not absent else None
def apply_data(self, val):
import FreeCAD as App
hgrp = App.ParamGet(self.param_path)
setter = {
'Bool' : (hgrp.SetBool ),
'Float' : (hgrp.SetFloat ),
'Int' : (hgrp.SetInt ),
'String' : (hgrp.SetString ),
'Unsigned': (hgrp.SetUnsigned),
}[self.param_type]
deleter = {
'Bool' : (hgrp.RemBool ),
'Float' : (hgrp.RemFloat ),
'Int' : (hgrp.RemInt ),
'String' : (hgrp.RemString ),
'Unsigned': (hgrp.RemUnsigned),
}[self.param_type]
if val is None:
deleter(self.param_name)
else:
setter(self.param_name, val)
def getSelectedPlacement(obj, sub):
leaves = LCE.AllLeaves(obj.Shape)
@ -54,6 +119,8 @@ def getSelectedPlacement(obj, sub):
# --------------------------------Gui commands----------------------------------
_library = {} #instances of TempoVis, per document
_old_par = None #original value of DragAtCursor parameter
_stack_len = 0 #how many times did we tried to modify the parameter
class CommandViewFromPlacement:
def GetResources(self):
@ -66,6 +133,9 @@ class CommandViewFromPlacement:
def Activated(self):
import FreeCADGui as Gui
global _stack_len
global _old_par
oldTV = _library.pop(App.ActiveDocument.Name, None)
if oldTV is None:
V = App.Vector
@ -83,7 +153,15 @@ class CommandViewFromPlacement:
#prepare
tv = Show.TempoVis(App.ActiveDocument)
tv.saveCamera()
if SceneDetail is not None:
tv.modify(SDParameter('User parameter:BaseApp/Preferences/View','DragAtCursor','Bool', False))
else:
dt = SDParameter('User parameter:BaseApp/Preferences/View','DragAtCursor','Bool', False)
if _stack_len == 0:
_old_par = dt.scene_value()
_stack_len += 1
dt.apply_data(dt.data)
#set up camera
Gui.ActiveDocument.ActiveView.setCameraType('Perspective')
from pivy import coin
@ -107,12 +185,17 @@ class CommandViewFromPlacement:
if Gui.ActiveDocument.ActiveView.getCameraType() == 'Perspective':
cam = Gui.ActiveDocument.ActiveView.getCameraNode()
cam.heightAngle = abs(cam.heightAngle.getValue()) #workaround
if SceneDetail is None:
_stack_len -= 1
if _stack_len == 0:
dt = SDParameter('User parameter:BaseApp/Preferences/View','DragAtCursor','Bool', False)
dt.apply_data(_old_par)
def IsActive(self):
if not App.ActiveDocument: return False
return True
if Show is None: return False
return hasattr(Gui.activeView(), 'getCameraNode')
if FreeCAD.GuiUp:
if App.GuiUp:
FreeCADGui.addCommand('Lattice2_ViewFromPlacement', CommandViewFromPlacement())
exportedCommands = [