Allow to change projection range for projected modules

This commit is contained in:
DarkPhoenix
2019-09-30 01:18:55 +03:00
parent b433b0ea7c
commit ce7df2d01f
6 changed files with 106 additions and 6 deletions

View File

@@ -55,12 +55,13 @@ class ChangeItemProjectionRange(ContextMenuSingle):
newRange = None
if isinstance(mainItem, es_Fit):
self.mainFrame.command.Submit(cmd.GuiChangeProjectedFitRangeCommand(
self.mainFrame.command.Submit(cmd.GuiChangeProjectedFitProjectionRangeCommand(
fitID=fitID, projectedFitID=mainItem.ID, projectionRange=newRange))
elif isinstance(mainItem, Module):
if mainItem in fit.projectedModules:
position = fit.projectedModules.index(mainItem)
pass
self.mainFrame.command.Submit(cmd.GuiChangeProjectedModuleProjectionRangeCommand(
fitID=fitID, position=position, projectionRange=newRange))
elif isinstance(mainItem, Drone):
pass
elif isinstance(mainItem, Fighter):

View File

@@ -66,10 +66,11 @@ from .gui.projectedFighter.changeAmount import GuiChangeProjectedFighterAmountCo
from .gui.projectedFighter.changeMetas import GuiChangeProjectedFighterMetasCommand
from .gui.projectedFit.add import GuiAddProjectedFitsCommand
from .gui.projectedFit.changeAmount import GuiChangeProjectedFitAmountCommand
from .gui.projectedFit.changeRange import GuiChangeProjectedFitRangeCommand
from .gui.projectedFit.changeProjectionRange import GuiChangeProjectedFitProjectionRangeCommand
from .gui.projectedModule.add import GuiAddProjectedModuleCommand
from .gui.projectedModule.changeCharges import GuiChangeProjectedModuleChargesCommand
from .gui.projectedModule.changeMetas import GuiChangeProjectedModuleMetasCommand
from .gui.projectedModule.changeProjectionRange import GuiChangeProjectedModuleProjectionRangeCommand
from .gui.projectedModule.changeSpool import GuiChangeProjectedModuleSpoolCommand
from .gui.projectedRemove import GuiRemoveProjectedItemsCommand
from .gui.shipModeChange import GuiChangeShipModeCommand

View File

@@ -0,0 +1,55 @@
import wx
from logbook import Logger
from gui.fitCommands.helpers import restoreCheckedStates
from service.fit import Fit
pyfalog = Logger(__name__)
class CalcChangeProjectedModuleProjectionRangeCommand(wx.Command):
def __init__(self, fitID, position, projectionRange):
wx.Command.__init__(self, True)
self.fitID = fitID
self.position = position
self.projectionRange = projectionRange
self.savedProjectionRange = None
self.savedStateCheckChanges = None
def Do(self):
pyfalog.debug('Doing change of projected module projection range at position {} to range {} on fit {}'.format(
self.position, self.projectionRange, self.fitID))
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
mod = fit.projectedModules[self.position]
if mod.projectionRange == self.projectionRange:
return False
self.savedProjectionRange = mod.projectionRange
mod.projectionRange = self.projectionRange
sFit.recalc(fit)
self.savedStateCheckChanges = sFit.checkStates(fit, mod)
return True
def Undo(self):
pyfalog.debug('Undoing change of projected module projection range at position {} to range {} on fit {}'.format(
self.position, self.projectionRange, self.fitID))
cmd = CalcChangeProjectedModuleProjectionRangeCommand(
fitID=self.fitID,
position=self.position,
projectionRange=self.savedProjectionRange)
result = cmd.Do()
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
return result
@property
def needsGuiRecalc(self):
if self.savedStateCheckChanges is None:
return True
for container in self.savedStateCheckChanges:
if len(container) > 0:
return True
return False

View File

@@ -31,9 +31,9 @@ class CalcChangeProjectedFitProjectionRangeCommand(wx.Command):
if projectionInfo is None:
pyfalog.warning('Fit projection info is not available')
return False
self.savedProjectionRange = projectionInfo.projectionRange
if self.projectionRange == self.savedProjectionRange:
if projectionInfo.projectionRange == self.projectionRange:
return False
self.savedProjectionRange = projectionInfo.projectionRange
projectionInfo.projectionRange = self.projectionRange
sFit.recalc(fit)

View File

@@ -8,7 +8,7 @@ from gui.fitCommands.helpers import InternalCommandHistory
from service.fit import Fit
class GuiChangeProjectedFitRangeCommand(wx.Command):
class GuiChangeProjectedFitProjectionRangeCommand(wx.Command):
def __init__(self, fitID, projectedFitID, projectionRange):
wx.Command.__init__(self, True, 'Change Projected Fit Projection Range')

View File

@@ -0,0 +1,43 @@
import wx
import eos.db
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.module.projectedChangeProjectionRange import CalcChangeProjectedModuleProjectionRangeCommand
from gui.fitCommands.helpers import InternalCommandHistory
from service.fit import Fit
class GuiChangeProjectedModuleProjectionRangeCommand(wx.Command):
def __init__(self, fitID, position, projectionRange):
wx.Command.__init__(self, True, 'Change Projected Module Projection Range')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
self.projectionRange = projectionRange
def Do(self):
cmd = CalcChangeProjectedModuleProjectionRangeCommand(
fitID=self.fitID,
position=self.position,
projectionRange=self.projectionRange)
success = self.internalHistory.submit(cmd)
sFit = Fit.getInstance()
if cmd.needsGuiRecalc:
eos.db.flush()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
eos.db.commit()
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitIDs=(self.fitID,)))
return success
def Undo(self):
success = self.internalHistory.undoAll()
eos.db.flush()
sFit = Fit.getInstance()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
eos.db.commit()
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitIDs=(self.fitID,)))
return success