Ejemplo n.º 1
0
        /// <summary>
        /// Click handler for the Smooth button.
        /// </summary>
        private void Smooth_Btn_Click(object sender, EventArgs e)
        {
            // Check whether we actually have any files to process
            string inputDir = InputDir_TextBox.Text;

            if (!Directory.Exists(inputDir))
            {
                MessageBox.Show("The chosen input directory does not exist.");
                return;
            }

            string[] vtkFiles = Directory.GetFiles(inputDir, "*.vtk");
            if ((vtkFiles == null) || (vtkFiles.Length == 0))
            {
                MessageBox.Show("No vtk files found in the chosen input directory.");
                return;
            }

            // Save the settings
            Properties.Settings.Default.SmoothingFactor = (float)SmoothingFactor_NUD.Value;
            Properties.Settings.Default.Save();

            // Update the UI
            Stop_Btn.Enabled        = true;
            PauseResume_Btn.Enabled = true;
            Main_ProgressBar.Value  = 0;
            EnableInputs(false);

            // Run the Upsampler in the background
            m_currentProc = new Smoother(inputDir, (float)SmoothingFactor_NUD.Value);
            m_currentProc.ProgressEvent   += CurrentProc_ProgressEvent;
            m_currentProc.CompletionEvent += CurrentProc_CompletionEvent;
            m_currentProc.RunInBackground();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handler for progress events from the current proc.
        /// </summary>
        void CurrentProc_ProgressEvent(TdseUtils.Proc sender)
        {
            // Update the progress bar
            int prog = -1;

            if (sender is Upsampler)
            {
                prog = ((Upsampler)sender).Progress;
            }
            if (sender is Smoother)
            {
                prog = ((Smoother)sender).Progress;
            }
            else if (sender is Colorer)
            {
                prog = ((Colorer)sender).Progress;
            }
            else if (sender is Cropper)
            {
                prog = ((Cropper)sender).Progress;
            }

            if ((prog >= 0) && (Main_ProgressBar.Value != prog))
            {
                Main_ProgressBar.Value = prog;                         // Workaround for slow ProgressBar updates
                Main_ProgressBar.Value = (prog > 0) ? prog - 1 : prog; //
                Main_ProgressBar.Value = prog;                         //
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles Progress events from the Evolver.
        /// </summary>
        void Evolver_ProgressEvent(TdseUtils.Proc sender)
        {
            Evolver evolver = (Evolver)sender;

            // If the current frame is a keyframe, then save it.
            double frameInterval = (m_params.NumFramesToSave <= 1) ? 1 : m_params.TotalTime / (m_params.NumFramesToSave - 1);

            if (evolver.CurrentTimeStepIndex == (int)Math.Round((m_lastSavedFrame + 1) * frameInterval / m_params.TimeStep))
            {
                if (m_lastSavedFrame + 1 < m_params.NumFramesToSave)
                {
                    string outFile = Path.Combine(m_outputDir, "Frame_" + (m_lastSavedFrame + 1).ToString("D4") + ".vtk");
                    evolver.Wf.SaveToVtkFile(outFile, m_params.SaveFormat);
                }
                m_lastSavedFrame++;
            }

            // Update the progress bar
            int val = (100 * evolver.CurrentTimeStepIndex) / (evolver.TotalNumTimeSteps);

            if (Main_ProgressBar.Value != val)
            {
                Main_ProgressBar.Value = val;                  // Workaround for slow ProgressBar updates
                Main_ProgressBar.Value = Math.Max(0, val - 1); //
                Main_ProgressBar.Value = val;                  //
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles Progress events from the Evolver.
        /// </summary>
        void Evolver_ProgressEvent(TdseUtils.Proc sender)
        {
            // Update the progress bar
            Evolver evolver = (Evolver)sender;
            int     val     = (100 * evolver.CurrentTimeStepIndex) / (evolver.TotalNumTimeSteps);

            if (Main_ProgressBar.Value != val)
            {
                Main_ProgressBar.Value = val;                  // Workaround for slow ProgressBar updates
                Main_ProgressBar.Value = Math.Max(0, val - 1); //
                Main_ProgressBar.Value = val;                  //
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handler for completion events from the current proc.
        /// </summary>
        void CurrentProc_CompletionEvent(TdseUtils.Proc sender, RunWorkerCompletedEventArgs e)
        {
            PauseResume_Btn.Text    = "Pause";
            PauseResume_Btn.Enabled = false;
            Stop_Btn.Enabled        = false;
            EnableInputs(true);

            if (e.Cancelled)
            {
                Main_ProgressBar.Value = 0;
            }

            // Report any errors
            if (e.Error != null)
            {
                string msg;
                try
                {
                    msg = e.Error.InnerException.Message + " \n" + e.Error.InnerException.StackTrace;
                }
                catch
                {
                    msg = e.Error.Message;
                }
                if ((msg != null) && msg.ToLower().Contains("unsupported wavefunction format"))
                {
                    msg = "The wavefunction file is invalid, or does not support the attempted operation.";
                }
                MessageBox.Show("Abnormal termination.\n\n" + msg);
            }

            // Set my input dir equal to the last-used output dir
            if (!e.Cancelled && (e.Error == null))
            {
                string lastOutputDir =
                    (sender is Upsampler) ? ((Upsampler)sender).LastOutputDir :
                    (sender is Smoother) ? ((Smoother)sender).LastOutputDir :
                    (sender is Cropper) ? ((Cropper)sender).LastOutputDir : null;

                if (lastOutputDir != null)
                {
                    InputDir_TextBox.Text = lastOutputDir;
                    Properties.Settings.Default.LastPostProcFolder = InputDir_TextBox.Text;
                    Properties.Settings.Default.Save();
                }
            }

            m_currentProc = null;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Click handler for the Crop button.
        /// </summary>
        private void Crop_Btn_Click(object sender, EventArgs e)
        {
            // Check whether we actually have any files to process
            string inputDir = InputDir_TextBox.Text;

            if (!Directory.Exists(inputDir))
            {
                MessageBox.Show("The chosen input directory does not exist.");
                return;
            }

            string[] vtkFiles = Directory.GetFiles(inputDir, "*.vtk");
            if ((vtkFiles == null) || (vtkFiles.Length == 0))
            {
                MessageBox.Show("No vtk files found in the chosen input directory.");
                return;
            }

            // Save the settings
            int X1 = (int)XCrop1_NUD.Value;
            int X2 = (int)XCrop2_NUD.Value;
            int Y1 = (int)YCrop1_NUD.Value;
            int Y2 = (int)YCrop2_NUD.Value;
            int Z1 = (int)ZCrop1_NUD.Value;
            int Z2 = (int)ZCrop2_NUD.Value;

            Properties.Settings.Default.CropSettings = X1.ToString() + "," + X2.ToString() + "," +
                                                       Y1.ToString() + "," + Y2.ToString() + "," + Z1.ToString() + "," + Z2.ToString();
            Properties.Settings.Default.Save();

            // Update the UI
            Stop_Btn.Enabled        = true;
            PauseResume_Btn.Enabled = true;
            Main_ProgressBar.Value  = 0;
            EnableInputs(false);

            // Run the Upsampler in the background
            m_currentProc = new Cropper(inputDir, X1, X2, Y1, Y2, Z1, Z2);
            m_currentProc.ProgressEvent   += CurrentProc_ProgressEvent;
            m_currentProc.CompletionEvent += CurrentProc_CompletionEvent;
            m_currentProc.RunInBackground();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Handles Completion events from the Evolver.
        /// </summary>
        void Evolver_CompletionEvent(TdseUtils.Proc sender, RunWorkerCompletedEventArgs e)
        {
            // Update the UI
            EnableInputs(true);
            RunStop_Btn.Text        = "Run";
            PauseResume_Btn.Text    = "Pause";
            PauseResume_Btn.Enabled = false;
            RunStop_Btn.Enabled     = true;

            if (e.Cancelled)
            {
                Main_ProgressBar.Value = 0;
            }

            // Report any errors
            if (e.Error != null)
            {
                string msg;
                try
                {
                    msg = e.Error.InnerException.Message + " \n" + e.Error.InnerException.StackTrace;
                }
                catch
                {
                    msg = e.Error.Message;
                }
                if ((msg != null) && msg.ToLower().Contains("unsupported wavefunction format"))
                {
                    msg = "The wavefunction file is invalid, or does not support the attempted operation.";
                }
                MessageBox.Show("Abnormal termination.\n\n" + msg);
            }

            // Maybe notify
            if (!e.Cancelled && (e.Error == null))
            {
                if (OnNormalCompletion != null)
                {
                    OnNormalCompletion(this, EventArgs.Empty);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Click handler for the ReColor button.
        /// </summary>
        private void ReColor_Btn_Click(object sender, EventArgs e)
        {
            // Check whether we actually have any files to process
            string inputDir = InputDir_TextBox.Text;

            if (!Directory.Exists(inputDir))
            {
                MessageBox.Show("The chosen input directory does not exist.");
                return;
            }

            string[] vtkFiles = Directory.GetFiles(inputDir, "*.vtk");
            if ((vtkFiles == null) || (vtkFiles.Length == 0))
            {
                MessageBox.Show("No vtk files found in the chosen input directory.");
                return;
            }


            // Run the Colorer in the background
            DialogResult dlgResult = m_colorBuilder.ShowDialog();

            if (dlgResult == DialogResult.OK || dlgResult == DialogResult.Yes)
            {
                // Update the UI
                Stop_Btn.Enabled        = true;
                PauseResume_Btn.Enabled = true;
                Main_ProgressBar.Value  = 0;
                EnableInputs(false);

                m_currentProc = new Colorer(inputDir, m_colorBuilder);
                m_currentProc.ProgressEvent   += CurrentProc_ProgressEvent;
                m_currentProc.CompletionEvent += CurrentProc_CompletionEvent;
                m_currentProc.RunInBackground();
            }
        }