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:
@@ -13,16 +13,24 @@ class CommandFits(ContextMenu):
|
||||
# Get list of items that define a command fit
|
||||
sMkt = Market.getInstance()
|
||||
grp = sMkt.getGroup(1770) # Command burst group
|
||||
commandTypeIDs = [item.ID for item in grp.items]
|
||||
commandTypeIDs = {item.ID for item in grp.items}
|
||||
commandFits = []
|
||||
menu = None
|
||||
|
||||
@classmethod
|
||||
def populateFits(cls, evt):
|
||||
if evt is None or (getattr(evt, 'action', None) in ("modadd", "moddel") and getattr(evt, 'typeID', None) in cls.commandTypeIDs):
|
||||
# we are adding or removing an item that defines a command fit. Need to refresh fit list
|
||||
sFit = Fit.getInstance()
|
||||
cls.commandFits = sFit.getFitsWithModules(cls.commandTypeIDs)
|
||||
# This fires on a FitChanged event and updates the command fits whenever a command burst module is added or
|
||||
# removed from a fit. evt.typeID can be either a int or a set (in the case of multiple module deletions)
|
||||
if evt is None or (getattr(evt, 'action', None) in ("modadd", "moddel") and getattr(evt, 'typeID', None)):
|
||||
if evt is not None:
|
||||
ids = getattr(evt, 'typeID')
|
||||
if not isinstance(ids, set):
|
||||
ids = set([ids])
|
||||
|
||||
if evt is None or not ids.isdisjoint(cls.commandTypeIDs):
|
||||
# we are adding or removing an item that defines a command fit. Need to refresh fit list
|
||||
sFit = Fit.getInstance()
|
||||
cls.commandFits = sFit.getFitsWithModules(cls.commandTypeIDs)
|
||||
|
||||
def __init__(self):
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
|
||||
@@ -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"""
|
||||
|
||||
@@ -540,14 +540,26 @@ class Fit(object):
|
||||
else:
|
||||
return None
|
||||
|
||||
def removeModule(self, fitID, position):
|
||||
pyfalog.debug("Removing module from position ({0}) for fit ID: {1}", position, fitID)
|
||||
def removeModule(self, fitID, positions):
|
||||
"""Removes modules based on a number of positions."""
|
||||
pyfalog.debug("Removing module from position ({0}) for fit ID: {1}", positions, fitID)
|
||||
fit = eos.db.getFit(fitID)
|
||||
if fit.modules[position].isEmpty:
|
||||
|
||||
# Convert scalar value to list
|
||||
if not isinstance(positions, list):
|
||||
positions = [positions]
|
||||
|
||||
modulesChanged = False
|
||||
for x in positions:
|
||||
if not fit.modules[x].isEmpty:
|
||||
fit.modules.toDummy(x)
|
||||
modulesChanged=True
|
||||
|
||||
# if no modules have changes, report back None
|
||||
if not modulesChanged:
|
||||
return None
|
||||
|
||||
numSlots = len(fit.modules)
|
||||
fit.modules.toDummy(position)
|
||||
self.recalc(fit)
|
||||
self.checkStates(fit, None)
|
||||
fit.fill()
|
||||
|
||||
Reference in New Issue
Block a user