Add ability to change projection range of fits

This commit is contained in:
DarkPhoenix
2019-09-29 23:41:45 +03:00
parent 33103dbee9
commit 20868d6b44
8 changed files with 241 additions and 4 deletions

View File

@@ -66,6 +66,7 @@ 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.projectedModule.add import GuiAddProjectedModuleCommand
from .gui.projectedModule.changeCharges import GuiChangeProjectedModuleChargesCommand
from .gui.projectedModule.changeMetas import GuiChangeProjectedModuleMetasCommand

View File

@@ -0,0 +1,60 @@
import wx
from logbook import Logger
from gui.fitCommands.helpers import restoreCheckedStates
from service.fit import Fit
pyfalog = Logger(__name__)
class CalcChangeProjectedFitProjectionRangeCommand(wx.Command):
def __init__(self, fitID, projectedFitID, projectionRange):
wx.Command.__init__(self, True, 'Change Projected Fit Projection Range')
self.fitID = fitID
self.projectedFitID = projectedFitID
self.projectionRange = projectionRange
self.savedProjectionRange = None
self.savedStateCheckChanges = None
def Do(self):
pyfalog.debug('Doing change of projected fit {} range to {} for fit {}'.format(self.projectedFitID, self.projectionRange, self.fitID))
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
projectedFit = sFit.getFit(self.projectedFitID, projected=True)
# Projected fit could have been deleted if we are redoing
if projectedFit is None:
pyfalog.debug('Projected fit is not available')
return False
projectionInfo = projectedFit.getProjectionInfo(self.fitID)
if projectionInfo is None:
pyfalog.warning('Fit projection info is not available')
return False
self.savedProjectionRange = projectionInfo.projectionRange
if self.projectionRange == self.savedProjectionRange:
return False
projectionInfo.projectionRange = self.projectionRange
sFit.recalc(fit)
self.savedStateCheckChanges = sFit.checkStates(fit, None)
return True
def Undo(self):
pyfalog.debug('Undoing change of projected fit {} range to {} for fit {}'.format(self.projectedFitID, self.projectionRange, self.fitID))
cmd = CalcChangeProjectedFitProjectionRangeCommand(
fitID=self.fitID,
projectedFitID=self.projectedFitID,
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

@@ -0,0 +1,40 @@
import wx
import eos.db
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.projectedFit.changeProjectionRange import CalcChangeProjectedFitProjectionRangeCommand
from gui.fitCommands.helpers import InternalCommandHistory
from service.fit import Fit
class GuiChangeProjectedFitRangeCommand(wx.Command):
def __init__(self, fitID, projectedFitID, projectionRange):
wx.Command.__init__(self, True, 'Change Projected Fit Projection Range')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.projectedFitID = projectedFitID
self.projectionRange = projectionRange
def Do(self):
cmd = CalcChangeProjectedFitProjectionRangeCommand(fitID=self.fitID, projectedFitID=self.projectedFitID, 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