From af5789c4f86b9a6d0b9771fe4f70dfd46cd523f9 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Tue, 18 Sep 2018 21:05:50 +0800 Subject: [PATCH] gui: add QuickSolve command Related to #118 --- Gui/Resources/icons/Assembly_QuickSolve.svg | 888 ++++++++++++++++++++ assembly.py | 2 + gui.py | 15 + solver.py | 6 +- sys_slvs.py | 11 +- 5 files changed, 913 insertions(+), 9 deletions(-) create mode 100644 Gui/Resources/icons/Assembly_QuickSolve.svg diff --git a/Gui/Resources/icons/Assembly_QuickSolve.svg b/Gui/Resources/icons/Assembly_QuickSolve.svg new file mode 100644 index 0000000..a5cb5de --- /dev/null +++ b/Gui/Resources/icons/Assembly_QuickSolve.svg @@ -0,0 +1,888 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + [jmaustpc] + + + Assembly_Assembly_Tree + 2013-12-24 + http://www.freecadweb.org/wiki/index.php?title=Artwork + + + FreeCAD + + + FreeCAD/src/Mod/Assembly/Gui/Resources/icons/Assembly_Assembly_Tree.svg + + + FreeCAD LGPL2+ + + + https://www.gnu.org/copyleft/lesser.html + + + [agryson] Alexander Gryson + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assembly.py b/assembly.py index 6548dc1..8b8a2fd 100644 --- a/assembly.py +++ b/assembly.py @@ -2790,6 +2790,8 @@ class Assembly(AsmGroup): obj.BuildShape == BuildShapeCompound: self.buildShape() + System.touch(obj,False) + def onChanged(self, obj, prop): if obj.Removing or \ not getattr(self,'Object',None) or \ diff --git a/gui.py b/gui.py index 616a0c5..da2b8fa 100644 --- a/gui.py +++ b/gui.py @@ -282,6 +282,21 @@ class AsmCmdSolve(AsmCmdBase): FreeCAD.closeActiveTransaction() +class AsmCmdQuickSolve(AsmCmdBase): + _id = 21 + _menuText = 'Quick solve' + _iconName = 'Assembly_QuickSolve.svg' + _accel = 'A, F' + + @classmethod + def Activated(cls): + from . import solver + FreeCAD.setActiveTransaction('Assembly quick solve') + logger.report('command "{}" exception'.format(cls.getName()), + solver.solve) + FreeCAD.closeActiveTransaction() + + class AsmCmdNewElement(AsmCmdBase): _id = 19 _menuText = 'Create element' diff --git a/solver.py b/solver.py index c356e57..82ccb75 100644 --- a/solver.py +++ b/solver.py @@ -30,6 +30,7 @@ PartInfo = namedtuple('SolverPartInfo', ('Part','PartName','Placement', class Solver(object): def __init__(self,assembly,reportFailed,dragPart,recompute,rollback): + failedType = 'redundant' self.system = System.getSystem(assembly) cstrs = assembly.Proxy.getConstraints() if not cstrs: @@ -95,18 +96,19 @@ class Solver(object): try: self.system.solve(group=self.group,reportFailed=reportFailed) except RuntimeError as e: + failedType = 'failed' raise RuntimeError('Failed to solve {}: {}'.format( objName(assembly),str(e))) finally: if reportFailed and self.system.Failed: - msg = 'List of failed constraint:' + msg = 'List of {} constraint:'.format(failedType) for h in self.system.Failed: cstr = self._cstrMap.get(h,None) if not cstr: try: c = self.system.getConstraint(h) except Exception as e2: - logger.error('cannot find failed constraint ' + logger.error('cannot find constraint ' '{}: {}'.format(h,e2)) continue if c.group <= self._fixedGroup or \ diff --git a/sys_slvs.py b/sys_slvs.py index 32021ce..71d5800 100644 --- a/sys_slvs.py +++ b/sys_slvs.py @@ -33,8 +33,8 @@ class _SystemSlvs(SystemExtension,slvs.System): super(_SystemSlvs,self).__init__() self.log = log - def solve(self, group=0, reportFailed=False): - ret = super(_SystemSlvs,self).solve(group,reportFailed) + def solve(self, group=0, reportFailed=False, findFreeParams=False): + ret = super(_SystemSlvs,self).solve(group,reportFailed,findFreeParams) if ret: reason = None if ret==1: @@ -46,13 +46,10 @@ class _SystemSlvs(SystemExtension,slvs.System): elif ret==4: reason = 'init failed' elif ret==5: - if logger.isEnabledFor('debug'): - logger.warn('redundant constraints') - else: - logger.info('redundant constraints') + logger.warn('redundant constraints') else: reason = 'unknown failure' if reason: raise RuntimeError(reason) - self.log('dof remaining: {}'.format(self.Dof)) + logger.info('dof remaining: {}'.format(self.Dof))