Fix issue with Delete key event on t3d mode causing exception (#1160). Additionally, work around the fact that every module that is removed also recalculates the fit, allowing for a faster response time when deleting multiple modules at a time. This is somewhat ugly as the removeModule function was originally based on the assumption of removing only one module. Should clean it up at some point.

This commit is contained in:
blitzmann
2017-05-13 00:21:26 -04:00
parent b4f063b07a
commit d4ce1ef3db
3 changed files with 46 additions and 15 deletions

View File

@@ -254,11 +254,16 @@ class FittingView(d.Display):
keycode = event.GetKeyCode()
if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
row = self.GetFirstSelected()
modules = []
while row != -1:
if row not in self.blanks:
self.removeModule(self.mods[row])
mod = self.mods[row]
if isinstance(mod, Module) and not mod.isEmpty:
modules.append(self.mods[row])
self.Select(row, 0)
row = self.GetNextSelected(row)
self.removeModule(modules)
event.Skip()
@@ -348,14 +353,20 @@ class FittingView(d.Display):
if "wxMSW" in wx.PlatformInfo:
self.click(event)
def removeModule(self, module):
def removeModule(self, modules):
"""Removes a list of modules from the fit"""
sFit = Fit.getInstance()
fit = sFit.getFit(self.activeFitID)
populate = sFit.removeModule(self.activeFitID, fit.modules.index(module))
if populate is not None:
if not isinstance(modules, list):
modules = [modules]
positions = [mod.modPosition for mod in modules]
result = sFit.removeModule(self.activeFitID, positions)
if result is not None:
self.slotsChanged()
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.activeFitID, action="moddel", typeID=module.item.ID))
ids = {mod.item.ID for mod in modules}
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.activeFitID, action="moddel", typeID=ids))
def addModule(self, x, y, srcIdx):
"""Add a module from the market browser"""