Change projected fits behavior - now addition adds 1 fit in any case (even if fit is already projected), and removal via double-click works like with drones
This commit is contained in:
@@ -126,7 +126,7 @@ class ProjectedView(d.Display):
|
||||
thing = self.get(row)
|
||||
if isinstance(thing, es_Fit):
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedFitCommand(
|
||||
fitID=fitID, projectedFitID=thing.ID))
|
||||
fitID=fitID, projectedFitID=thing.ID, amount=math.inf))
|
||||
elif isinstance(thing, es_Module):
|
||||
fit = Fit.getInstance().getFit(fitID)
|
||||
if thing in fit.projectedModules:
|
||||
@@ -148,7 +148,8 @@ class ProjectedView(d.Display):
|
||||
if type == "fit":
|
||||
activeFit = self.mainFrame.getActiveFit()
|
||||
if activeFit:
|
||||
self.mainFrame.command.Submit(cmd.GuiAddProjectedFitCommand(fitID=activeFit, projectedFitID=fitID))
|
||||
self.mainFrame.command.Submit(cmd.GuiAddProjectedFitCommand(
|
||||
fitID=activeFit, projectedFitID=fitID, amount=1))
|
||||
|
||||
def startDrag(self, event):
|
||||
row = event.GetIndex()
|
||||
@@ -335,8 +336,9 @@ class ProjectedView(d.Display):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
thing = self.get(row)
|
||||
if isinstance(thing, es_Fit):
|
||||
amount = math.inf if wx.GetMouseState().altDown else 1
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedFitCommand(
|
||||
fitID=fitID, projectedFitID=thing.ID))
|
||||
fitID=fitID, projectedFitID=thing.ID, amount=amount))
|
||||
elif isinstance(thing, es_Module):
|
||||
fit = Fit.getInstance().getFit(fitID)
|
||||
if thing in fit.projectedModules:
|
||||
|
||||
@@ -56,7 +56,7 @@ class AddCurrentlyOpenFit(ContextMenu):
|
||||
if self.context == 'commandView':
|
||||
self.mainFrame.command.Submit(cmd.GuiAddCommandFitCommand(fitID=fitID, commandFitID=fit.ID))
|
||||
elif self.context == 'projected':
|
||||
self.mainFrame.command.Submit(cmd.GuiAddProjectedFitCommand(fitID=fitID, projectedFitID=fit.ID))
|
||||
self.mainFrame.command.Submit(cmd.GuiAddProjectedFitCommand(fitID=fitID, projectedFitID=fit.ID, amount=1))
|
||||
|
||||
|
||||
AddCurrentlyOpenFit.register()
|
||||
|
||||
@@ -70,7 +70,7 @@ class RemoveItem(ContextMenu):
|
||||
elif srcContext == "projectedFit":
|
||||
projectedFit = selection[0]
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedFitCommand(
|
||||
fitID=fitID, projectedFitID=projectedFit.ID))
|
||||
fitID=fitID, projectedFitID=projectedFit.ID, amount=math.inf))
|
||||
elif srcContext == "projectedModule":
|
||||
mod = selection[0]
|
||||
if mod in fit.projectedModules:
|
||||
|
||||
@@ -185,7 +185,8 @@ class FitItem(SFItem.SFBrowserItem):
|
||||
if activeFit:
|
||||
sFit = Fit.getInstance()
|
||||
projectedFit = sFit.getFit(self.fitID)
|
||||
if self.mainFrame.command.Submit(cmd.GuiAddProjectedFitCommand(fitID=activeFit, projectedFitID=projectedFit.ID)):
|
||||
command = cmd.GuiAddProjectedFitCommand(fitID=activeFit, projectedFitID=projectedFit.ID, amount=1)
|
||||
if self.mainFrame.command.Submit(command):
|
||||
self.mainFrame.additionsPane.select("Projected")
|
||||
|
||||
def OnAddCommandFit(self, event):
|
||||
|
||||
@@ -10,12 +10,13 @@ pyfalog = Logger(__name__)
|
||||
|
||||
class CalcAddProjectedFitCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, projectedFitID, amount=None, state=None):
|
||||
def __init__(self, fitID, projectedFitID, amount, state=None):
|
||||
wx.Command.__init__(self, True, 'Add Projected Fit')
|
||||
self.fitID = fitID
|
||||
self.projectedFitID = projectedFitID
|
||||
self.amount = amount
|
||||
self.state = state
|
||||
self.changeAmountCommand = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing addition of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID))
|
||||
@@ -28,13 +29,16 @@ class CalcAddProjectedFitCommand(wx.Command):
|
||||
pyfalog.debug('Projected fit is not available')
|
||||
return False
|
||||
|
||||
if projectedFit in fit.projectedFits:
|
||||
pyfalog.debug('Projected fit had been applied already')
|
||||
return False
|
||||
# If we already have info about projection - means that fit is already projected
|
||||
# and we just need to increase amount of fits
|
||||
if projectedFit in fit.projectedFits and projectedFit.ID in fit.projectedFitDict:
|
||||
from .changeAmount import CalcChangeProjectedFitAmountCommand
|
||||
self.changeAmountCommand = CalcChangeProjectedFitAmountCommand(
|
||||
fitID=self.fitID, projectedFitID=self.projectedFitID, amount=self.amount, relative=True)
|
||||
return self.changeAmountCommand.Do()
|
||||
else:
|
||||
self.changeAmountCommand = None
|
||||
|
||||
if projectedFit.ID in fit.projectedFitDict:
|
||||
pyfalog.debug('Projected fit is in projected dict already')
|
||||
return False
|
||||
fit.projectedFitDict[projectedFit.ID] = projectedFit
|
||||
# This bit is required, see issue #83
|
||||
eos.db.saveddata_session.flush()
|
||||
@@ -56,11 +60,13 @@ class CalcAddProjectedFitCommand(wx.Command):
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing addition of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID))
|
||||
if self.changeAmountCommand is not None:
|
||||
return self.changeAmountCommand.Undo()
|
||||
# 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, projected=True)
|
||||
if projectedFit is None:
|
||||
return True
|
||||
from .remove import CalcRemoveProjectedFitCommand
|
||||
cmd = CalcRemoveProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID)
|
||||
cmd = CalcRemoveProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID, amount=self.amount)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -10,11 +10,12 @@ pyfalog = Logger(__name__)
|
||||
|
||||
class CalcChangeProjectedFitAmountCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, projectedFitID, amount):
|
||||
def __init__(self, fitID, projectedFitID, amount, relative=False):
|
||||
wx.Command.__init__(self, True, 'Change Projected Fit Amount')
|
||||
self.fitID = fitID
|
||||
self.projectedFitID = projectedFitID
|
||||
self.amount = amount
|
||||
self.relative = relative
|
||||
self.savedAmount = None
|
||||
|
||||
def Do(self):
|
||||
@@ -29,8 +30,12 @@ class CalcChangeProjectedFitAmountCommand(wx.Command):
|
||||
pyfalog.warning('Fit projection info is not available')
|
||||
return False
|
||||
self.savedAmount = projectionInfo.amount
|
||||
if self.relative:
|
||||
amount = projectionInfo.amount + self.amount
|
||||
else:
|
||||
amount = self.amount
|
||||
# Limit to [1, 20]
|
||||
confinedAmount = min(20, max(1, self.amount))
|
||||
confinedAmount = min(20, max(1, amount))
|
||||
if confinedAmount == self.savedAmount:
|
||||
return False
|
||||
projectionInfo.amount = confinedAmount
|
||||
|
||||
@@ -10,12 +10,14 @@ pyfalog = Logger(__name__)
|
||||
|
||||
class CalcRemoveProjectedFitCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, projectedFitID):
|
||||
def __init__(self, fitID, projectedFitID, amount):
|
||||
wx.Command.__init__(self, True, 'Add Projected Fit')
|
||||
self.fitID = fitID
|
||||
self.projectedFitID = projectedFitID
|
||||
self.amount = amount
|
||||
self.savedState = None
|
||||
self.savedAmount = None
|
||||
self.changeAmountCommand = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing removal of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID))
|
||||
@@ -34,15 +36,28 @@ class CalcRemoveProjectedFitCommand(wx.Command):
|
||||
|
||||
self.savedState = projectionInfo.active
|
||||
self.savedAmount = projectionInfo.amount
|
||||
if projectedFit.ID not in fit.projectedFitDict:
|
||||
pyfalog.warning('Unable to find projected fit in projected dict')
|
||||
return False
|
||||
del fit.projectedFitDict[projectedFit.ID]
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
remainingAmount = projectionInfo.amount - self.amount
|
||||
|
||||
# Change amount if more than 0 remaining, remove otherwise
|
||||
if remainingAmount > 0:
|
||||
from .changeAmount import CalcChangeProjectedFitAmountCommand
|
||||
self.changeAmountCommand = CalcChangeProjectedFitAmountCommand(
|
||||
fitID=self.fitID, projectedFitID=self.projectedFitID, amount=remainingAmount)
|
||||
return self.changeAmountCommand.Do()
|
||||
else:
|
||||
self.changeAmountCommand = None
|
||||
if projectedFit.ID not in fit.projectedFitDict:
|
||||
pyfalog.warning('Unable to find projected fit in projected dict')
|
||||
return False
|
||||
del fit.projectedFitDict[projectedFit.ID]
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing removal of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID))
|
||||
if self.changeAmountCommand is not None:
|
||||
return self.changeAmountCommand.Undo()
|
||||
from .add import CalcAddProjectedFitCommand
|
||||
cmd = CalcAddProjectedFitCommand(
|
||||
fitID=self.fitID,
|
||||
|
||||
@@ -9,14 +9,15 @@ from service.fit import Fit
|
||||
|
||||
class GuiAddProjectedFitCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, projectedFitID):
|
||||
def __init__(self, fitID, projectedFitID, amount):
|
||||
wx.Command.__init__(self, True, 'Add Projected Fit')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.projectedFitID = projectedFitID
|
||||
self.amount = amount
|
||||
|
||||
def Do(self):
|
||||
cmd = CalcAddProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID)
|
||||
cmd = CalcAddProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID, amount=self.amount)
|
||||
success = self.internalHistory.submit(cmd)
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
|
||||
@@ -9,14 +9,15 @@ from service.fit import Fit
|
||||
|
||||
class GuiRemoveProjectedFitCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, projectedFitID):
|
||||
def __init__(self, fitID, projectedFitID, amount):
|
||||
wx.Command.__init__(self, True, 'Remove Projected Fit')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.projectedFitID = projectedFitID
|
||||
self.amount = amount
|
||||
|
||||
def Do(self):
|
||||
cmd = CalcRemoveProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID)
|
||||
cmd = CalcRemoveProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID, amount=self.amount)
|
||||
success = self.internalHistory.submit(cmd)
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
|
||||
Reference in New Issue
Block a user