protected virtual void LayerChange(LayerChangeEventArgs e) { lock (privateLock) { _layer = e.targetLayer; OnLayerChange?.Invoke(this, e); } }
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.eventLayerChanged -= 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); } }
internal void CancelSaveState() { lock (lockObject) { if (SaveStateOnNewLayerDelegate != null) { Main.conn.analyzer.eventLayerChanged -= 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; } } } }
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; } 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 OnLayerChange(delegate(float newZ, float lastZ) { // New Layer, ready to save state. OnReadyToSaveStateCallback(); }); SaveStateOnPauseDelegate = new PrinterConnectorBase.OnPauseChanged(delegate(bool paused) { if (paused) { OnReadyToSaveStateCallback(); } }); snapshotNameOnNextSaveState = snapshotName; Main.conn.analyzer.eventLayerChanged += 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(); } } if (snapshotDialog != null) { try { snapshotDialog.Show(); } catch (NullReferenceException) { // Could happen as a consequence of a race condition. In // this case, it's ok to ignore it. } } }
void Start() // TODO Awake? { viewCamera = Camera.main; layerChangeObservers += OnLayerChangeCalled; }
void Start() { viewCamera = Camera.main; layerChangeObservers += SomeLayerChangeHandler; //add to set of handling functions layerChangeObservers(); //call the delegates }