assembly: improve autoSolve function

This commit is contained in:
Zheng, Lei 2018-01-08 11:49:19 +08:00
parent 3a252d48df
commit 92b42d2f71
2 changed files with 16 additions and 4 deletions

View File

@ -48,6 +48,8 @@ def resolveAssembly(obj):
# For faking selection obtained from Gui.getSelectionEx()
Selection = namedtuple('AsmSelection',('Object','SubElementNames'))
_IgnoredProperties = set(['Visibility', 'Label', '_LinkRecomputed'])
class AsmBase(object):
def __init__(self):
self.Object = None
@ -845,7 +847,7 @@ class AsmConstraint(AsmGroup):
System.getTypeName(assembly)))
def onChanged(self,obj,prop):
if prop != 'Visibility':
if prop not in _IgnoredProperties:
Constraint.onChanged(obj,prop)
Assembly.autoSolve()
@ -1223,13 +1225,14 @@ class Assembly(AsmGroup):
def canAutoSolve(cls):
from . import solver
return gui.AsmCmdManager.AutoRecompute and \
not FreeCAD.ActiveDocument.Restoring and \
not FreeCADGui.ActiveDocument.Transacting and \
not FreeCAD.isRestoring() and \
not solver.isBusy() and \
not ViewProviderAssembly.isBusy()
@classmethod
def checkPartChange(cls, obj, prop):
if not cls.canAutoSolve():
if not cls.canAutoSolve() or prop in _IgnoredProperties:
return
assembly = None
if prop == 'Placement':
@ -1253,8 +1256,13 @@ class Assembly(AsmGroup):
if not cls._Timer.isSingleShot():
cls._Timer.setSingleShot(True)
cls._Timer.timeout.connect(Assembly.onSolverTimer)
logger.debug('auto solve scheduled',frame=1)
cls._Timer.start(300)
@classmethod
def cancelAutoSolve(cls):
cls._Timer.stop()
@classmethod
def onSolverTimer(cls):
if cls.canAutoSolve():
@ -1338,7 +1346,9 @@ class Assembly(AsmGroup):
else:
obj.setPropertyStatus('Shape','Transient')
return
System.onChanged(obj,prop)
if prop not in _IgnoredProperties:
System.onChanged(obj,prop)
Assembly.autoSolve()
def getConstraintGroup(self, create=False):
obj = self.Object
@ -1816,6 +1826,7 @@ class ViewProviderAssembly(ViewProviderAsmGroup):
_Busy = False
def onDragStart(self):
Assembly.cancelAutoSolve();
AsmMovingPart._Busy = True
FreeCAD.setActiveTransaction('Assembly move')

View File

@ -223,6 +223,7 @@ def solve(*args, **kargs):
if _SolverBusy:
raise RuntimeError("Recursive call of solve() is not allowed")
try:
Assembly.cancelAutoSolve();
_SolverBusy = True
return _solve(*args,**kargs)
finally: