1 from __future__
import division, absolute_import
5 from twistedActor
import CommandError
9 from .showInstrument
import showInstrument
10 from .showObject
import showObjectFields
11 from .startSlew
import startSlew
13 __all__ = [
"setInstrument"]
16 """Implement the "set instrument" command
18 @param[in,out] tccActor tcc actor
19 writes to tccActor.inst, and tccActor.obj
20 @param[in,out] userCmd user command
22 currSecUserFocus = tccActor.inst.secUserFocus
24 instName = userCmd.parsedCmd.paramDict[
"instrument"].valueList[0].valueList[0]
27 instName = tccActor.inst.instName
29 raise CommandError(
'No name avalable in current instrument block!')
31 gcview = userCmd.parsedCmd.qualDict[
"gcview"].valueList[0]
if userCmd.parsedCmd.qualDict[
"gcview"].boolValue
else None
33 instDir = tcc.base.getInstDir(),
36 writeToUsers = tccActor.writeToUsers,
39 newInst.secUserFocus = currSecUserFocus
41 if userCmd.parsedCmd.qualDict[
"keep"].boolValue:
44 for attr
in userCmd.parsedCmd.qualDict[
"keep"].valueList:
45 if attr.endswith(
'Focus'):
47 attr = attr.replace(
'Focus',
'UserFocus')
48 setattr(newInst, attr, getattr(tccActor.inst, attr))
51 if tccActor.inst.rotID != newInst.rotID:
52 RotSwapper(tccActor=tccActor, userCmd=userCmd, newInst=newInst)
54 isNewInst = newInst.instName != tccActor.inst.instName
55 tccActor.inst = newInst
56 finishSetInst(tccActor=tccActor, userCmd=userCmd, isNewInst=isNewInst)
60 """Swap instrument rotators.
62 On success, update tccActor.inst and call finishSetInst
64 def __init__(self, tccActor, userCmd, newInst):
65 """Construct a RotSwapper
67 @param[in,out] tccActor tcc actor
68 writes to tccActor.inst, and tccActor.obj
69 @param[in,out] userCmd user command
70 @param[in] newInst new instrument data (a tcc.base.Inst)
75 self.
isNewInst = newInst.instName != tccActor.inst.instName
76 if newInst.rotID <= 0:
79 newRotName =
"rot%i" % (newInst.rotID,)
81 newDev = self.tccActor.axisDict[newRotName]
83 raise CommandError(
"Unknown rotator ID %d" % (newInst.rotID,))
84 swapCmd = self.tccActor.axisDevSet.replaceDev(
88 swapCmd.addCallback(functools.partial(self.
_swapCallback, newDev=newDev))
90 def _swapCallback(self, cmd, newDev):
94 self.userCmd.setState(self.userCmd.Failed,
95 textMsg =
"Failed to change to rotator %d: %s" % (self.newInst.rotID, cmd.getMsg()))
97 self.tccActor.inst = self.
newInst
98 if self.tccActor.inst.rotID <= 0:
100 self.tccActor.obj.axisCmdState[2] = tcc.base.AxisState_NotAvailable
103 self.tccActor.obj.axisCmdState[2] = tcc.base.AxisState_Halted
108 """Finish the set instrument command by updating tccActor.axeLim and slewing to the updated target
110 Halted axes are left halted. If the new instrument has no rotator than the old rotType is ditched.
112 @param[in,out] tccActor tcc actor
113 reads and updates obj, setting azWrapPref and rotWrapPref and slewing
114 @param[in,out] userCmd set instrument command
115 reads azwrap and rotwrap preferences from userCmd.parsedCmd.qualDict
116 @param[in] isNewInst set True if "set inst" changed to a new instrument,
117 in which case set rotType to None
119 tccActor.axeLim.setRotLim(tccActor.inst)
121 if isNewInst
or not tccActor.inst.hasRotator():
122 tccActor.obj.rotType = tcc.base.RotType_None
123 tccActor.obj.rotUser.invalidate()
126 if tccActor.obj.isMoving():
128 newObj = tcc.base.Obj(tccActor.obj)
129 newObj.azWrapPref = tcc.base.WrapTypeNameDict[userCmd.parsedCmd.qualDict[
"azwrap"].valueList[0].lower()]
130 newObj.rotWrapPref = tcc.base.WrapTypeNameDict[userCmd.parsedCmd.qualDict[
"rotwrap"].valueList[0].lower()]
135 doRestart = [
False]*tcc.base.NAxes,
137 earth = tccActor.earth,
138 inst = tccActor.inst,
139 telMod = tccActor.telMod,
140 axeLim = tccActor.axeLim,
141 tai = tcc.base.tai(),
152 userCmd.setState(userCmd.Done)
def computeObj
Compute all computed obj fields from user-specified fields except path generator outputs.
def showObjectFields
Write fields from the object block.