Exemplo n.º 1
0
 internal void CancelSaveState()
 {
     lock (lockObject)
     {
         if (SaveStateOnNewLayerDelegate != null)
         {
             Main.conn.analyzer.eventPosChanged -= SaveStateOnNewLayerDelegate;
             Main.conn.connector.eventPauseChanged -= SaveStateOnPauseDelegate;
             SaveStateOnNewLayerDelegate = null;
             SaveStateOnPauseDelegate = null;
             if (snapshotDialog != null)
             {
                 // FIXME this can lead to a race condition
                 snapshotDialog.Close();
                 snapshotDialog = null;
             }
         }
     }
 }
Exemplo n.º 2
0
        public void OnReadyToSaveStateCallback()
        {
            string snapshotName;
            lock (lockObject)
            {
                if (SaveStateOnNewLayerDelegate == null)
                {
                    // Already cancelled.
                    return;
                }

                // keep snapshot name
                snapshotName = snapshotNameOnNextSaveState;

                // We want the event to execute only once, so, we must remove it
                // after the condition was met.
                Main.conn.analyzer.eventPosChanged -= SaveStateOnNewLayerDelegate;
                Main.conn.connector.eventPauseChanged -= SaveStateOnPauseDelegate;
                SaveStateOnNewLayerDelegate = null;
                SaveStateOnPauseDelegate = null;
                snapshotNameOnNextSaveState = null;
                if (snapshotDialog != null)
                {
                    // FIXME this can lead to a race condition
                    snapshotDialog.Close();
                    snapshotDialog = null;
                }
            }
            // Capture state, so that any movement we do later is not affected.
            PrintingStateSnapshot state = SnapshotFactory.TakeSnapshot(Main.conn);

            // Kill job. This will move the extruder to prevent melting the
            // object.

            conn.connector.KillJob();
            try
            {
                SaveStateFile(state, snapshotName);
                MessageBox.Show(Trans.T("L_PRINT_STATE_SAVED_SUCCESSFULLY"));
            }

            catch (IOException ex)
            {
                MessageBox.Show(ex.ToString(), Trans.T("L_ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            catch (UnauthorizedAccessException ex)
            {
                MessageBox.Show(ex.ToString(), Trans.T("L_ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        private void saveStateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!ValidatePreconditionsToSaveStateSnapshot(Main.conn))
            {
                // conditions not met
                return;
            }

            string snapshotName = ReadSnapshotName();
            if (snapshotName == null)
            {
                // User cancelled
                return;
            }

            double lastZ = Main.conn.analyzer.z;
            lock (lockObject)
            {
                // We save the state when the first of these three events happen:
                // - Print job is paused (if it's paused at the moment the user
                // tries to take the snapshot, then it's taken at that moment)
                // - A new layer is reached.
                // - The user forces the snapshot from the snapshot dialog.

                SaveStateOnNewLayerDelegate = new OnPosChange(delegate(GCode gc, float x, float y, float z)
                {
                    if (z != lastZ)
                    {
                        // New Layer, ready to save state.
                        OnReadyToSaveStateCallback();
                    }
                });

                SaveStateOnPauseDelegate = new PrinterConnectorBase.OnPauseChanged(delegate(bool paused)
                {
                    if (paused)
                    {
                        OnReadyToSaveStateCallback();
                    }
                });

                snapshotNameOnNextSaveState = snapshotName;
                Main.conn.analyzer.eventPosChanged += SaveStateOnNewLayerDelegate;
                Main.conn.connector.eventPauseChanged += SaveStateOnPauseDelegate;
                if (snapshotDialog == null)
                {
                    // FIXME this can lead to a race condition
                    snapshotDialog = new SnapshotDialog();
                }

                if (Main.conn.connector.IsPaused)
                {
                    // In this case we mustn't wait until the new layer is
                    // reached, but instead we must take the snapshot now.
                    OnReadyToSaveStateCallback();
                }
            }
            snapshotDialog.Show();
        }