Пример #1
0
        void clear_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to remove all models from the composition window?", "Important Question", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                hydroModelerControl.composition_clear();
            }
        }
Пример #2
0
        private void RunBox_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            // if running in same thread and simulation hasn't finished yet,
            // we cannot close dialog
            if (!_finished)
            {
                if (_composition.RunInSameThread)
                {
                    e.Cancel = true;
                    return;
                }

                switch (MessageBox.Show("Simulation hasn't finished yet, do you want to stop it?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2))
                {
                case DialogResult.Yes:
                    buttonStop_Click(null, null);
                    break;

                default:
                    e.Cancel = true;
                    return;
                }
            }

            switch (MessageBox.Show("All models have been finished their simulation run. Would you like to reload project?\n\nNote: Models must be reloaded prior to simulation.  If \"No\" is selected, all models will be removed from the composition.", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1))
            {
            case DialogResult.Yes:
            {
                #region old reload method
                //////_composition.Reload();


                //////temporarily save file
                ////_composition.SaveToFile(this._currentDirectory + "\\temp.opr");

                //////clear composition window
                ////_composition.RemoveAllModels();

                //////HACK: fix to fix opr file
                //////make sure that the trigger does not contain any extra characters
                ////string filename = this._currentDirectory + "\\temp.opr";
                ////StreamReader sr = new StreamReader(filename);
                ////string contents = sr.ReadToEnd();
                ////sr.Close();

                ////if (contents.Contains("Oatc.OpenMI.Gui.Trigger"))
                ////{
                ////    int end = contents.IndexOf("Oatc.OpenMI.Gui.Trigger");
                ////    int index = end - 1;
                ////    int count = 0;
                ////    while (contents[index] != '\"')
                ////    {
                ////        count++;
                ////        index--;
                ////    }

                ////    contents = contents.Remove(end - count, count);
                ////}

                ////StreamWriter sw = new StreamWriter(filename);
                ////sw.Write(contents);
                ////sw.Close();

                //////reload temp opr
                ////_composition.LoadFromFile(this._currentDirectory + "\\temp.opr");

                ////System.IO.File.Delete(this._currentDirectory + "\\temp.opr");

                //////foreach (UIModel model in models)
                //////_composition.AddModel(model.
                //////    if (model.ModelID.Contains("Oatc"))
                //////    {
                //////        _composition.RemoveModel(model);
                //////        break;
                //////    }
                //////_composition.Reload();
                #endregion

                //---- reload the composition ---

                //-- get the current file path
                string path = _composition.FilePath;

                //-- overwrite the original file
                _composition.SaveToFile(path);

                //-- clear the composition window
                _composition.RemoveAllModels();

                //-- remove extra characters (in path) from the trigger
                StreamReader sr       = new StreamReader(path);
                string       contents = sr.ReadToEnd();
                sr.Close();

                if (contents.Contains("Oatc.OpenMI.Gui.Trigger"))
                {
                    int end   = contents.IndexOf("Oatc.OpenMI.Gui.Trigger");
                    int index = end - 1;
                    int count = 0;
                    while (contents[index] != '\"')
                    {
                        count++; index--;
                    }
                    contents = contents.Remove(end - count, count);
                }

                //-- rewrite the opr with revised trigger info
                StreamWriter sw = new StreamWriter(path);
                sw.Write(contents);
                sw.Close();

                //-- reopen the opr file
                _composition.LoadFromFile(_composition.FilePath);

                break;
            }

            default:
                hydroModelerControl.composition_clear();
                break;
            }

            // clean-up
            listViewEvents.Items.Clear();
        }