Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion gui/builtinContextMenus/droneSplitStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,51 @@ def activate(self, callingWindow, fullContext, mainItem, i):
fitID = self.mainFrame.getActiveFit()
fit = Fit.getInstance().getFit(fitID)
cleanInput = re.sub(r'[^0-9.]', '', dlg.input.GetLineText(0).strip())

if mainItem in fit.drones:
position = fit.drones.index(mainItem)
self.mainFrame.command.Submit(cmd.GuiSplitLocalDroneStackCommand(
fitID=fitID, position=position, amount=int(cleanInput)))


class DroneSplitStackBandwidth(DroneSplitStack):
"""
Split drone stack to match ship's available bandwidth, ensuring that only
one of the stacks is active so as not to exceed the bandwidth limit.
"""
def getText(self, callingWindow, itmContext, mainItem):
return "Split {} Stack to Fit Max Bandwidth".format(itmContext)

def activate(self, callingWindow, fullContext, mainItem, i):
fitID = self.mainFrame.getActiveFit()
fit = Fit.getInstance().getFit(fitID)
if mainItem in fit.drones:
bandwidth_per_drone = mainItem.item.\
attributes['droneBandwidthUsed'].value
ship_bandwidth = fit.ship.item.attributes['droneBandwidth'].value
max_active_drones = int(ship_bandwidth/bandwidth_per_drone)
if max_active_drones == 0:
wx.MessageDialog(
None, "Cannot split drone stack to fit bandwidth. This "
"drone type uses {0} mbit/s and this ship only has {1} "
"mbit/s.".format(int(bandwidth_per_drone),
int(ship_bandwidth)),
"Ship drone bandwidth exceeded", wx.OK | wx.ICON_ERROR
).ShowModal()
else:
if max_active_drones > 5:
max_active_drones = 5

position = fit.drones.index(mainItem)
self.mainFrame.command.Submit(
cmd.GuiSplitLocalDroneStackCommand(fitID=fitID,
position=position,
amount=max_active_drones,
deactivate=True)
)


DroneSplitStack.register()
DroneSplitStackBandwidth.register()


class DroneStackSplit(wx.Dialog):
Expand Down
8 changes: 6 additions & 2 deletions gui/fitCommands/calc/drone/localRemove.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@

class CalcRemoveLocalDroneCommand(wx.Command):

def __init__(self, fitID, position, amount):
def __init__(self, fitID, position, amount, deactivate=False):
wx.Command.__init__(self, True, 'Remove Local Drone')
self.fitID = fitID
self.position = position
self.amountToRemove = amount
self.savedDroneInfo = None
self.removedStack = None
self.deactivate = deactivate

def Do(self):
pyfalog.debug('Doing removal of {} local drones at position {} from fit {}'.format(self.amountToRemove, self.position, self.fitID))
Expand All @@ -26,7 +27,10 @@ def Do(self):

drone.amount = max(drone.amount - self.amountToRemove, 0)
if drone.amountActive > 0:
drone.amountActive = min(drone.amountActive, drone.amount)
if self.deactivate:
drone.amountActive = 0
else:
drone.amountActive = min(drone.amountActive, drone.amount)

if drone.amount == 0:
fit.drones.remove(drone)
Expand Down
10 changes: 8 additions & 2 deletions gui/fitCommands/gui/localDrone/stackSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@

class GuiSplitLocalDroneStackCommand(wx.Command):

def __init__(self, fitID, position, amount):
def __init__(self, fitID, position, amount, deactivate=False):
"""
Deactivate argument is only True when splitting drone stacks to match
ship's available bandwidth.
"""
wx.Command.__init__(self, True, 'Split Local Drone Stack')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
self.amount = amount
self.deactivate = deactivate

def Do(self):
sFit = Fit.getInstance()
Expand All @@ -31,7 +36,8 @@ def Do(self):
commands.append(CalcRemoveLocalDroneCommand(
fitID=self.fitID,
position=self.position,
amount=self.amount))
amount=self.amount,
deactivate=self.deactivate))
commands.append(CalcAddLocalDroneCommand(
fitID=self.fitID,
droneInfo=info,
Expand Down