Pressing::Pressing(my_context ctx) : my_base(ctx)
{
    UISubState uiSubState = PRINTENGINE->PauseRequested() ? AboutToPause : 
                                                            NoUISubState;
    
    PRINTENGINE->SendStatus(PressingState, Entering, uiSubState);
    
    // check to see if the door is still open after calibrating
    if (PRINTENGINE->DoorIsOpen())
        post_event(EvDoorOpened());
    else if (context<PrinterStateMachine>()._motionCompleted) 
        post_event(EvMotionCompleted());
}
Initializing::Initializing(my_context ctx) : my_base(ctx)
{    
    PRINTENGINE->SendStatus(InitializingState, Entering);
    
    // see if the printer should be put into demo mode
    if (PRINTENGINE->DemoModeRequested())
        post_event(EvEnterDemoMode()); 
    
    // check to see if the door is open on startup
    if (PRINTENGINE->DoorIsOpen())
    {
        post_event(EvDoorOpened());
    }
    else
    {
        PRINTENGINE->Initialize();
        post_event(EvInitialized());
    }
}
InitializingLayer::InitializingLayer(my_context ctx) : my_base(ctx)
{    
    // check to see if the door is still open after calibrating
    if (PRINTENGINE->DoorIsOpen())
        post_event(EvDoorOpened());
    else
    {
        // perform initialization needed for next layer
        // (even if the door is opened and closed again while here,
        // this won't be called more than once per layer, because we're going to 
        // immediately transition to the next state)
        PRINTENGINE->NextLayer();
        post_event(EvInitialized());
    }
    
    UISubState uiSubState = PRINTENGINE->PauseRequested() ? AboutToPause : 
                                                            NoUISubState;
    
    // don't send status till after estimated print time has been set
    PRINTENGINE->SendStatus(InitializingLayerState, Entering, uiSubState);
}
PreExposureDelay::PreExposureDelay(my_context ctx) : my_base(ctx)
{  
    UISubState uiSubState = PRINTENGINE->PauseRequested() ? AboutToPause : 
                                                            NoUISubState;
    
    PRINTENGINE->SendStatus(PreExposureDelayState, Entering, uiSubState);

    // check to see if the door is still open after calibrating,
    // in case we skipped the tray deflection steps
    if (PRINTENGINE->DoorIsOpen())
        post_event(EvDoorOpened());
    else
    {
        double delay = PRINTENGINE->GetPreExposureDelayTimeSec();
        if (delay < 0.001)
        {
            // no delay needed
            post_event(EvDelayEnded());
        }
        else
            PRINTENGINE->StartDelayTimer(delay);
    }
}