From: daid Date: Thu, 2 Jan 2014 07:11:04 +0000 (+0100) Subject: Optimize the push-free implementation. X-Git-Tag: 14.01~13 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=47a4da8f396578fe57cd456a00d228929b165e83;p=cura.git Optimize the push-free implementation. --- diff --git a/Cura/gui/sceneView.py b/Cura/gui/sceneView.py index a3921c1d..95d4a1d5 100644 --- a/Cura/gui/sceneView.py +++ b/Cura/gui/sceneView.py @@ -399,7 +399,7 @@ class SceneView(openglGui.glGuiPanel): if self._selectedObj is None: return self._selectedObj.resetRotation() - self._scene.pushFree() + self._scene.pushFree(self._selectedObj) self._selectObject(self._selectedObj) self.sceneUpdated() @@ -407,7 +407,7 @@ class SceneView(openglGui.glGuiPanel): if self._selectedObj is None: return self._selectedObj.layFlat() - self._scene.pushFree() + self._scene.pushFree(self._selectedObj) self._selectObject(self._selectedObj) self.sceneUpdated() @@ -424,19 +424,19 @@ class SceneView(openglGui.glGuiPanel): return machine = profile.getMachineSetting('machine_type') self._selectedObj.setPosition(numpy.array([0.0, 0.0])) - self._scene.pushFree() + self._scene.pushFree(self._selectedObj) #self.sceneUpdated() if machine == "ultimaker2": #This is bad and Jaime should feel bad! self._selectedObj.setPosition(numpy.array([0.0,-10.0])) self._selectedObj.scaleUpTo(self._machineSize - numpy.array(profile.calculateObjectSizeOffsets() + [0.0], numpy.float32) * 2 - numpy.array([1,1,1], numpy.float32)) self._selectedObj.setPosition(numpy.array([0.0,0.0])) - self._scene.pushFree() + self._scene.pushFree(self._selectedObj) else: self._selectedObj.setPosition(numpy.array([0.0, 0.0])) - self._scene.pushFree() + self._scene.pushFree(self._selectedObj) self._selectedObj.scaleUpTo(self._machineSize - numpy.array(profile.calculateObjectSizeOffsets() + [0.0], numpy.float32) * 2 - numpy.array([1,1,1], numpy.float32)) - self._scene.pushFree() + self._scene.pushFree(self._selectedObj) self._selectObject(self._selectedObj) self.updateProfileToControls() self.sceneUpdated() @@ -456,7 +456,7 @@ class SceneView(openglGui.glGuiPanel): return self._selectedObj.setScale(value, axis, self.scaleUniform.getValue()) self.updateProfileToControls() - self._scene.pushFree() + self._scene.pushFree(self._selectedObj) self._selectObject(self._selectedObj) self.sceneUpdated() @@ -469,7 +469,7 @@ class SceneView(openglGui.glGuiPanel): return self._selectedObj.setSize(value, axis, self.scaleUniform.getValue()) self.updateProfileToControls() - self._scene.pushFree() + self._scene.pushFree(self._selectedObj) self._selectObject(self._selectedObj) self.sceneUpdated() @@ -519,7 +519,7 @@ class SceneView(openglGui.glGuiPanel): if self._focusObj is None: return self._focusObj.setPosition(numpy.array([0.0, 0.0])) - self._scene.pushFree() + self._scene.pushFree(self._selectedObj) newViewPos = numpy.array([self._focusObj.getPosition()[0], self._focusObj.getPosition()[1], self._focusObj.getSize()[2] / 2]) self._animView = openglGui.animation(self, self._viewTarget.copy(), newViewPos, 0.5) self.sceneUpdated() @@ -811,12 +811,12 @@ class SceneView(openglGui.glGuiPanel): self.PopupMenu(menu) menu.Destroy() elif self._mouseState == 'dragObject' and self._selectedObj is not None: - self._scene.pushFree() + self._scene.pushFree(self._selectedObj) self.sceneUpdated() elif self._mouseState == 'tool': if self.tempMatrix is not None and self._selectedObj is not None: self._selectedObj.applyMatrix(self.tempMatrix) - self._scene.pushFree() + self._scene.pushFree(self._selectedObj) self._selectObject(self._selectedObj) self.tempMatrix = None self.tool.OnDragEnd() diff --git a/Cura/util/objectScene.py b/Cura/util/objectScene.py index d7535009..d33d461c 100644 --- a/Cura/util/objectScene.py +++ b/Cura/util/objectScene.py @@ -163,7 +163,7 @@ class Scene(object): self._objectList.append(obj) self.updateHeadSize(obj) self.updateSizeOffsets(True) - self.pushFree() + self.pushFree(obj) def remove(self, obj): self._objectList.remove(obj) @@ -176,14 +176,25 @@ class Scene(object): m._obj = obj1 obj1.processMatrix() obj1.setPosition((obj1.getPosition() + obj2.getPosition()) / 2) - self.pushFree() + self.pushFree(obj1) - def pushFree(self): - n = 10 - while self._pushFree(): - n -= 1 - if n < 0: - return + def pushFree(self, staticObj): + if not self.checkPlatform(staticObj): + return + pushList = [] + for obj in self._objectList: + if obj == staticObj or not self.checkPlatform(obj): + continue + if self._oneAtATime: + v = polygon.polygonCollisionPushVector(obj._headAreaMinHull + obj.getPosition(), staticObj._boundaryHull + staticObj.getPosition()) + else: + v = polygon.polygonCollisionPushVector(obj._boundaryHull + obj.getPosition(), staticObj._boundaryHull + staticObj.getPosition()) + if type(v) is bool: + continue + obj.setPosition(obj.getPosition() + v * 1.01) + pushList.append(obj) + for obj in pushList: + self.pushFree(obj) def arrangeAll(self): oldList = self._objectList @@ -213,22 +224,6 @@ class Scene(object): order = None return order - def _pushFree(self): - for a in self._objectList: - for b in self._objectList: - if a == b or not self.checkPlatform(a) or not self.checkPlatform(b): - continue - if self._oneAtATime: - v = polygon.polygonCollisionPushVector(a._headAreaMinHull + a.getPosition(), b._boundaryHull + b.getPosition()) - else: - v = polygon.polygonCollisionPushVector(a._boundaryHull + a.getPosition(), b._boundaryHull + b.getPosition()) - if type(v) is bool: - continue - a.setPosition(a.getPosition() + v * 0.4) - b.setPosition(b.getPosition() - v * 0.6) - return True - return False - #Check if two objects are hitting each-other (+ head space). def _checkHit(self, a, b): if a == b: