// a CTDirector.
CTDirector director = (CTDirector) getDirector();
if (director.isDiscretePhase()) {
// Get the current time and period.
Time currentTime = director.getModelTime();
double periodValue = ((DoubleToken) period.getToken())
.doubleValue();
// Use Time.NEGATIVE_INFINITY to indicate that no refire
// event should be scheduled because we aren't at a phase boundary.
_tentativeNextFiringTime = Time.NEGATIVE_INFINITY;
// By default, the cycle count will not be incremented.
_tentativeCycleCountIncrement = 0;
// In case current time has reached or crossed a boundary between
// periods, update it. Note that normally the time will not
// advance more than one period
// (unless, perhaps, the entire domain has been dormant
// for some time, as might happen for example in a hybrid system).
// But do not do this if we are before the first iteration.
// FIXME: why?
if (_tentativeCycleCount > 0) {
while (_tentativeCycleStartTime.add(periodValue).compareTo(
currentTime) <= 0) {
_tentativeCycleStartTime = _tentativeCycleStartTime
.add(periodValue);
}
}
// Adjust the phase if the current time has moved beyond
// the current phase time.
Time currentPhaseTime = _tentativeCycleStartTime
.add(_offsets[_tentativePhase]);
if (currentTime.compareTo(currentPhaseTime) == 0) {
// Phase boundary. Change the current value.
_tentativeCurrentValue = _getValue(_tentativePhase);
// If we are beyond the number of cycles requested, then
// change the output value to zero.
int cycleLimit = ((IntToken) numberOfCycles.getToken())
.intValue();
// FIXME: performance suffers from this. cache the stop time.
// NOTE: there are two stop time. One is based on the cycles
// and period, and the other one is based on the stopTime
// parameter.
Time stopTime = _tentativeStartTime.add(cycleLimit
* periodValue);
if (((cycleLimit > 0) && (currentTime.compareTo(stopTime) >= 0))
|| _tentativeDone) {
_tentativeCurrentValue = defaultValue.getToken();