Esempio n. 1
0
        public void OnTick(Graphics gr)
        {
            OnDelete?.Invoke();
            OnGravity?.Invoke(true);
            OnSpring?.Invoke();
            OnRope?.Invoke();
            for (int i = 0; i < Surface.stillColliding.Count; i++)
            {
                Surface.stillColliding[i] = false;
            }
            do
            {
                for (int i = 0; i < Surface.stillColliding.Count; i++)
                {
                    Surface.stillColliding[i] = false;
                }
                OnSurface?.Invoke();
            } while (Surface.stillColliding.Contains(true));
            OnForceChange?.Invoke();
            OnVelChange?.Invoke(dt);
            OnPosChange?.Invoke(dt);
            for (int i = -10; i < 10; i++)
            {
                gr.DrawLine(Pens.LightGray, i * 60, 0, i * 60, 600);
                gr.DrawLine(Pens.LightGray, 0, i * 60, 600, i * 60);
                if (i == 5)
                {
                    gr.DrawLine(Pens.DarkGray, i * 60, 0, i * 60, 600);
                    gr.DrawLine(Pens.DarkGray, 0, i * 60, 600, i * 60);
                }
            }

            foreach (Body body in bodies)
            {
                body.DrawBody(gr);
            }
            foreach (Spring spring in springs)
            {
                spring.DrawSpring(gr);
            }
            foreach (Rope rope in ropes)
            {
                rope.DrawRope(gr);
            }
            foreach (Surface surface in surfaces)
            {
                surface.DrawSurface(gr);
            }
        }
Esempio 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);
            }
        }
Esempio n. 3
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;
             }
         }
     }
 }
Esempio n. 4
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();
        }