Slightly change how projected fits are processed

This commit is contained in:
DarkPhoenix
2019-04-13 18:47:47 +03:00
parent 1ca4c73a3e
commit aab9b39fea
4 changed files with 48 additions and 46 deletions

View File

@@ -11,7 +11,7 @@ pyfalog = Logger(__name__)
class FitAddCommandCommand(wx.Command):
def __init__(self, fitID, commandFitID, state=None):
wx.Command.__init__(self, True)
wx.Command.__init__(self, True, 'Add Command Fit')
self.fitID = fitID
self.commandFitID = commandFitID
self.state = state
@@ -22,7 +22,7 @@ class FitAddCommandCommand(wx.Command):
fit = sFit.getFit(self.fitID)
commandFit = sFit.getFit(self.commandFitID)
# Command fit could have been deleted if we were redoing
# Command fit could have been deleted if we are redoing
if commandFit is None:
pyfalog.debug('Command fit is not available')
return False
@@ -32,7 +32,7 @@ class FitAddCommandCommand(wx.Command):
return False
fit.commandFitDict[commandFit.ID] = commandFit
# this bit is required -- see GH issue # 83
# This bit is required, see issue #83
eos.db.saveddata_session.flush()
eos.db.saveddata_session.refresh(commandFit)

View File

@@ -9,41 +9,51 @@ pyfalog = Logger(__name__)
class FitAddProjectedFitCommand(wx.Command):
""""
from sFit.project
"""
def __init__(self, fitID, projectedFitID, status):
wx.Command.__init__(self, True)
def __init__(self, fitID, projectedFitID, state):
wx.Command.__init__(self, True, 'Add Projected Fit')
self.fitID = fitID
self.projectedFitID = projectedFitID
self.status = status
self.state = state
def Do(self):
pyfalog.debug("Projecting fit ({0}) onto: {1}", self.fitID, self.projectedFitID)
pyfalog.debug('Doing addition of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID))
sFit = Fit.getInstance()
projectee = sFit.getFit(self.fitID)
projector = sFit.getFit(self.projectedFitID)
fit = sFit.getFit(self.fitID)
projectedFit = sFit.getFit(self.projectedFitID)
if projector is None or projector in projectee.projectedFits:
# Projected fit could have been deleted if we are redoing
if projectedFit is None:
pyfalog.debug('Projected fit is not available')
return False
projectee.projectedFitDict[projector.ID] = projector
if projectedFit in fit.projectedFits:
pyfalog.debug('Projected fit had been applied already')
return False
# this bit is required -- see GH issue # 83
fit.projectedFitDict[projectedFit.ID] = projectedFit
# This bit is required, see issue #83
eos.db.saveddata_session.flush()
eos.db.saveddata_session.refresh(projector)
eos.db.saveddata_session.refresh(projectedFit)
if self.status is not None:
projectionInfo = projector.getProjectionInfo(self.fitID)
if self.state is not None:
projectionInfo = projectedFit.getProjectionInfo(self.fitID)
if not projectionInfo:
pyfalog.warning('Fit projection info is not available')
self.Undo()
return False
projectionInfo.active = self.status
projectionInfo.active = self.state
eos.db.commit()
return True
def Undo(self):
from gui.fitCommands.calc.fitRemoveProjectedFit import FitRemoveProjectedFitCommand # avoids circular import
cmd = FitRemoveProjectedFitCommand(self.fitID, self.projectedFitID)
cmd.Do()
return True
pyfalog.debug('Undoing addition of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID))
# Can't find the projected fit, it must have been deleted. Just skip, as deleted fit
# means that someone else just did exactly what we wanted to do
projectedFit = Fit.getInstance().getFit(self.projectedFitID)
if projectedFit is None:
return True
from .fitRemoveProjectedFit import FitRemoveProjectedFitCommand
cmd = FitRemoveProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID)
return cmd.Do()

View File

@@ -11,7 +11,7 @@ pyfalog = Logger(__name__)
class FitRemoveCommandCommand(wx.Command):
def __init__(self, fitID, commandFitID):
wx.Command.__init__(self, True)
wx.Command.__init__(self, True, 'Remove Command Fit')
self.fitID = fitID
self.commandFitID = commandFitID
self.savedState = None
@@ -38,10 +38,6 @@ class FitRemoveCommandCommand(wx.Command):
def Undo(self):
pyfalog.debug('Undoing removal of command fit {} for fit {}'.format(self.commandFitID, self.fitID))
# Can't find the command fit, it must have been deleted. Fail as there's no way to restore it
commandFit = Fit.getInstance().getFit(self.commandFitID)
if commandFit is None:
return False
from .fitAddCommand import FitAddCommandCommand
cmd = FitAddCommandCommand(fitID=self.fitID, commandFitID=self.commandFitID, state=self.savedState)
return cmd.Do()

View File

@@ -3,45 +3,41 @@ from logbook import Logger
import eos.db
from service.fit import Fit
from .fitRemoveProjectedModule import FitRemoveProjectedModuleCommand
pyfalog = Logger(__name__)
# this has the same exact definition that regular rpojected modules, besides the undo
class FitRemoveProjectedFitCommand(FitRemoveProjectedModuleCommand):
""""
from sFit.project
"""
class FitRemoveProjectedFitCommand(wx.Command):
def __init__(self, fitID, projectedFitID):
wx.Command.__init__(self, True)
wx.Command.__init__(self, True, 'Add Projected Fit')
self.fitID = fitID
self.projectedFitID = projectedFitID
self.savedState = None
def Do(self):
pyfalog.debug("Removing ({0}) onto: {1}".format(self.fitID, self.projectedFitID))
pyfalog.debug('Doing removal of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID))
sFit = Fit.getInstance()
projectee = sFit.getFit(self.fitID)
projector = sFit.getFit(self.projectedFitID)
fit = sFit.getFit(self.fitID)
projectedFit = sFit.getFit(self.projectedFitID)
if projector is None:
# Can be removed by the time we're redoing it
if projectedFit is None:
pyfalog.debug('Projected fit is not available')
return False
projectionInfo = projector.getProjectionInfo(self.fitID)
projectionInfo = projectedFit.getProjectionInfo(self.fitID)
if not projectionInfo:
pyfalog.warning('Fit projection info is not available')
return False
self.savedState = projectionInfo.active
del projectee.projectedFitDict[projector.ID]
del fit.projectedFitDict[projectedFit.ID]
eos.db.commit()
return True
def Undo(self):
from gui.fitCommands.calc.fitAddProjectedFit import FitAddProjectedFitCommand
cmd = FitAddProjectedFitCommand(self.fitID, self.projectedFitID, self.savedState)
pyfalog.debug('Undoing removal of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID))
from .fitAddProjectedFit import FitAddProjectedFitCommand
cmd = FitAddProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID, state=self.savedState)
return cmd.Do()