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

View File

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