From e16f2ad36d893626e54d7e5238416fdf41d635d0 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sat, 18 Aug 2018 09:11:04 +0800 Subject: [PATCH] constraint: fix constraint multiplication --- assembly.py | 36 +++++++++++++++++++++++++++--------- constraint.py | 2 +- solver.py | 4 ++-- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/assembly.py b/assembly.py index 411d81f..4a9f842 100644 --- a/assembly.py +++ b/assembly.py @@ -1117,14 +1117,8 @@ class AsmElementLink(AsmBase): obj.setLink(owner,subname) def getInfo(self,refresh=False,expand=False): - if not refresh: - if expand: - info = getattr(self,'infos',None) - if info: - return info - info = getattr(self,'info',None) - if info: - return [info] if expand else info + if not refresh and self.info is not None: + return self.infos if expand else self.info self.info = None self.infos *= 0 # clear the list @@ -1349,12 +1343,36 @@ class AsmConstraint(AsmGroup): if len(children)<=1: return count = 0 + shapes = [] + # count the total edges for multiplication for e in children[1:]: touched = 'Touched' in e.State info = e.Proxy.getInfo(not e.Proxy.multiply) if not touched: e.purgeTouched() - count += info.Shape.countElement('Edge') + if info.Shape.countElement('Face'): + elementCount = 1 + name = 'Face1' + else: + elementCount = info.Shape.countElement('Edge') + name = 'Edge1' + if not elementCount: + shapes.append(None) + else: + count += elementCount + shapes.append(info.Shape.getElement(name)) + + for i,e in enumerate(children[1:]): + shape = shapes[i] + if not shape or not e.Proxy.infos: + continue + for j,e2 in enumerate(children[i+2:]): + shape2 = shapes[i+j+1] + if not shape2 or not e2.Proxy.infos: + continue + if shape.isCoplanar(shape2): + e.Proxy.infos += e2.Proxy.infos + e2.Proxy.infos = [] firstChild = children[0] info = firstChild.Proxy.getInfo() diff --git a/constraint.py b/constraint.py index 4ddbc04..02e25d2 100644 --- a/constraint.py +++ b/constraint.py @@ -940,7 +940,7 @@ class BaseMulti(Base): if not infos: continue info0 = firstInfo[idx] - partInfo0 = solver.getPartInfo(info0,infos) + partInfo0 = solver.getPartInfo(info0) info = infos[0] partInfo = solver.getPartInfo(info) e0 = cls._entityDef[0]( diff --git a/solver.py b/solver.py index 7c04d6d..45f3bf3 100644 --- a/solver.py +++ b/solver.py @@ -122,6 +122,8 @@ class Solver(object): touched = False updates = [] for part,partInfo in self._partMap.items(): + if partInfo.Update: + updates.append(partInfo) if part in self._fixedParts: continue if utils.isDraftWire(part): @@ -152,8 +154,6 @@ class Solver(object): touched = True part.Points = points else: - if partInfo.Update: - updates.append(partInfo) params = [self.system.getParam(h).val for h in partInfo.Params] p = params[:3] q = (params[4],params[5],params[6],params[3])