Exemplo n.º 1
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                if (e.RowIndex < 0)
                {
                    //Header was clicked.
                    var listModelicaLibrary = libData.Cast <ModelicaLibrary>().ToList();
                    libData.Clear();
                    foreach (var lib in listModelicaLibrary.OrderBy(lib => lib.IsSelected).Reverse())
                    {
                        libData.Add(lib);
                    }
                }
                else
                {
                    var lib = this.dataGridView1.Rows[e.RowIndex].DataBoundItem as ModelicaLibrary;
                    lib.IsSelected = !lib.IsSelected;
                }
            }

            if (e.ColumnIndex == 1)
            {
                if (e.RowIndex < 0)
                {
                    //Header was clicked.
                    var listModelicaLibrary = libData.Cast <ModelicaLibrary>().ToList();
                    libData.Clear();
                    foreach (var lib in listModelicaLibrary.OrderBy(lib => lib.Name))
                    {
                        libData.Add(lib);
                    }
                }
            }

            if (e.ColumnIndex == 2)
            {
                this.clickedLib  = this.dataGridView1.Rows[e.RowIndex].DataBoundItem as ModelicaLibrary;
                this.versionMenu = new ContextMenuStrip();
                foreach (var ver in this.clickedLib.Versions.OrderBy(tup => tup.Item1))
                {
                    var item = new ToolStripMenuItem(ver.Item1 + " - " + ver.Item2)
                    {
                        Checked = false,
                        Name    = ver.Item1,
                    };

                    item.Click += new EventHandler(toolStripMenuItem_Click);

                    if (ver.Item1 == this.clickedLib.Version)
                    {
                        item.Checked = true;
                    }
                    this.versionMenu.Items.Add(item);
                }

                var cellRectangle = dataGridView1.GetCellDisplayRectangle(2, e.RowIndex, true);
                this.versionMenu.Show(this.dataGridView1, cellRectangle.Location);
            }
        }
Exemplo n.º 2
0
 private void SaveSettings()
 {
     ModelicaLibrary.UpdateSettingsFromModelicaLibraries(this.ModelicaSettings, libData.Cast <ModelicaLibrary>().ToList());
     this.ModelicaSettings.CheckWithDymola        = chbCheckWithDymola.Checked && chbCheckWithDymola.Enabled;
     this.ModelicaSettings.CheckWithOpenModelica  = chbCheckWithOM.Checked && chbCheckWithOM.Enabled;
     this.ModelicaSettings.GenerateConstrainedBys = chbConstrained.Checked;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Returns null if there is no match of the library.
        /// The user is not allowed to change the config.xml, thus check for null is
        /// only neccssary when browsing for the library.
        /// </summary>
        /// <param name="libraryPath"></param>
        /// <returns></returns>
        public static ModelicaLibrary GetLibraryFromPath(string libraryPath)
        {
            string          fileName        = Path.GetFileName(libraryPath);
            ModelicaLibrary modelicaLibrary = null;

            if (fileName == "package.mo")
            {
                fileName = Path.GetFileName(Path.GetDirectoryName(libraryPath));
            }
            else if (fileName.EndsWith(".mo"))
            {
                fileName = Path.GetFileNameWithoutExtension(fileName);
            }

            if (fileName.Where(c => ModelicaLibrary.InvalidChars.Contains(c)).Count() > 0)
            {
                return(modelicaLibrary);
            }

            string pattern = @"(\w+)(?:[ ](((?:\d+)(?:[.]\d+)*)(?:[ ].*)?))?";

            Match match = Regex.Match(fileName, pattern);

            if (match.Success)
            {
                string packageName = match.Groups[1].Value;

                if (packageName.Contains(' ') || packageName.Contains('.'))
                {
                    return(modelicaLibrary);
                }

                string version;
                if (match.Groups[0].Value == fileName)
                {
                    version = string.IsNullOrWhiteSpace(match.Groups[2].Value) ? "default" : match.Groups[2].Value;
                }
                else
                {
                    version = fileName.Substring(packageName.Length).Trim();
                }

                modelicaLibrary = new ModelicaLibrary()
                {
                    Name       = packageName,
                    IsSelected = true,
                    Version    = version
                };

                modelicaLibrary.Versions.Add(new Tuple <string, string>(version, libraryPath));
            }

            return(modelicaLibrary);
        }
Exemplo n.º 4
0
        public MainForm(CyPhy2Modelica_v2Settings settings, string projectDir)
        {
            InitializeComponent();
            this.ProjectDir       = projectDir;
            this.ModelicaSettings = settings;
            libData = ((System.Windows.Forms.BindingSource)dataGridView1.DataSource).List;
            var libraries = ModelicaLibrary.GetLibrariesFromSettings(this.ModelicaSettings, this.ProjectDir);

            foreach (var lib in libraries)
            {
                var selectedPath = lib.GetCurrentLibraryPath();
                if (Path.IsPathRooted(selectedPath) == false)
                {
                    selectedPath = Path.Combine(this.ProjectDir, selectedPath);
                }

                if (File.Exists(selectedPath) || Directory.Exists(selectedPath))
                {
                    libData.Add(lib);
                }
            }

            if (string.IsNullOrEmpty(DymolaExe))
            {
                chbCheckWithDymola.Enabled = false;
                chbCheckWithDymola.Checked = false;
            }
            else
            {
                chbCheckWithDymola.Enabled = true;
                chbCheckWithDymola.Checked = this.ModelicaSettings.CheckWithDymola;
            }

            if (string.IsNullOrEmpty(OMCExe))
            {
                chbCheckWithOM.Enabled = false;
                chbCheckWithOM.Checked = false;
            }
            else
            {
                chbCheckWithOM.Enabled = true;
                chbCheckWithOM.Checked = this.ModelicaSettings.CheckWithOpenModelica;
            }
        }
Exemplo n.º 5
0
        public static List <ModelicaLibrary> GetLibrariesFromSettings(CyPhy2Modelica_v2Settings settings, string projectDir)
        {
            var libraries = new List <ModelicaLibrary>();

            // If directory name was saved append package.mo
            // support all formats
            foreach (var dirPath in settings.IncludeDirectoryPath)
            {
                if (LibraryExists(dirPath, projectDir) == false)
                {
                    continue;
                }
                var newLib = ModelicaLibrary.GetLibraryFromPath(dirPath);
                var found  = libraries.FirstOrDefault(x => x.Name == newLib.Name);
                if (found == null)
                {
                    libraries.Add(newLib);
                }
            }

            foreach (var dirPath in settings.NonCheckedIncludeDirPaths)
            {
                if (LibraryExists(dirPath, projectDir) == false)
                {
                    continue;
                }
                var newLib = ModelicaLibrary.GetLibraryFromPath(dirPath);
                var found  = libraries.FirstOrDefault(x => x.Name == newLib.Name);
                if (found == null)
                {
                    newLib.IsSelected = false;
                    libraries.Add(newLib);
                }
                else
                {
                    found.Versions.Add(newLib.Versions.FirstOrDefault());
                }
            }

            return(libraries);
        }
Exemplo n.º 6
0
        private void btnBrowseIncludeDir_Click(object sender, EventArgs e)
        {
            string startupDir = "";
            var    lastItem   = libData.Cast <ModelicaLibrary>().LastOrDefault();

            if (lastItem != null)
            {
                startupDir = (new DirectoryInfo(Path.GetDirectoryName(lastItem.GetCurrentLibraryPath()))).Parent.FullName;

                if (Path.IsPathRooted(startupDir) == false)
                {
                    startupDir = Path.Combine(this.ProjectDir, startupDir);
                }
            }
            else
            {
                startupDir = this.ProjectDir;
            }

            var fbd = new OpenFileDialog()
            {
                Multiselect      = false,
                Filter           = "Modelica files (*.mo)|*.mo",
                InitialDirectory = startupDir,
                Title            = "Select Modelica package. If multi-file package; select the package.mo highest up in the file hierarchy."
            };

            var dr = fbd.ShowDialog();

            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                var pathToSave = fbd.FileName;
                // offer relative path if it is available
                Uri    uri1         = new Uri(pathToSave);
                Uri    uri2         = new Uri(this.ProjectDir + "\\");
                string relativePath = Uri.UnescapeDataString(uri2.MakeRelativeUri(uri1).ToString().Replace('/', '\\'));

                if (relativePath != pathToSave &&
                    Path.GetFullPath(relativePath) == pathToSave)
                {
                    var saveRelative = MessageBox.Show(
                        "Would you like to save the path as relative?",
                        "Save as relative path",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Information);

                    if (saveRelative == System.Windows.Forms.DialogResult.Yes)
                    {
                        pathToSave = relativePath;
                    }
                }

                var modelicaLibrary = ModelicaLibrary.GetLibraryFromPath(pathToSave);

                if (modelicaLibrary == null)
                {
                    MessageBox.Show(pathToSave + "\ndoes not have a valid Modelica package name!",
                                    "Invalid package name",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }

                var existingPackage = libData.Cast <ModelicaLibrary>().Where(lib => lib.Name == modelicaLibrary.Name).FirstOrDefault();
                if (existingPackage == null)
                {
                    libData.Add(modelicaLibrary);
                }
                else
                {
                    existingPackage.UpdateVersionPath(modelicaLibrary.Version, pathToSave);
                    existingPackage.Version = modelicaLibrary.Version;
                }

                dataGridView1.Refresh();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns null if there is no match of the library.
        /// The user is not allowed to change the config.xml, thus check for null is 
        /// only neccssary when browsing for the library.
        /// </summary>
        /// <param name="libraryPath"></param>
        /// <returns></returns>
        public static ModelicaLibrary GetLibraryFromPath(string libraryPath)
        {
            string fileName = Path.GetFileName(libraryPath);
            ModelicaLibrary modelicaLibrary = null;

            if (fileName == "package.mo")
            {
                fileName = Path.GetFileName(Path.GetDirectoryName(libraryPath));
            }
            else if (fileName.EndsWith(".mo"))
            {
                fileName = Path.GetFileNameWithoutExtension(fileName);
            }

            if (fileName.Where(c => ModelicaLibrary.InvalidChars.Contains(c)).Count() > 0)
            {
                return modelicaLibrary;
            }

            string pattern = @"(\w+)(?:[ ](((?:\d+)(?:[.]\d+)*)(?:[ ].*)?))?";

            Match match = Regex.Match(fileName, pattern);
            if (match.Success)
            {
                string packageName = match.Groups[1].Value;

                if (packageName.Contains(' ') || packageName.Contains('.'))
                {
                    return modelicaLibrary;
                }

                string version;
                if (match.Groups[0].Value == fileName)
                {
                    version = string.IsNullOrWhiteSpace(match.Groups[2].Value) ? "default" : match.Groups[2].Value;
                }
                else
                {
                    version = fileName.Substring(packageName.Length).Trim();
                }

                modelicaLibrary = new ModelicaLibrary()
                {
                    Name = packageName,
                    IsSelected = true,
                    Version = version
                };

                modelicaLibrary.Versions.Add(new Tuple<string, string>(version, libraryPath));
            }

            return modelicaLibrary;
        }
Exemplo n.º 8
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

            if (e.ColumnIndex == 0)
            {
                if (e.RowIndex < 0)
                {
                    //Header was clicked.
                    var listModelicaLibrary = libData.Cast<ModelicaLibrary>().ToList();
                    libData.Clear();
                    foreach (var lib in listModelicaLibrary.OrderBy(lib => lib.IsSelected).Reverse())
                    {
                        libData.Add(lib);
                    }
                }
                else
                {
                    var lib = this.dataGridView1.Rows[e.RowIndex].DataBoundItem as ModelicaLibrary;
                    lib.IsSelected = !lib.IsSelected;
                }
            }

            if (e.ColumnIndex == 1)
            {
                if (e.RowIndex < 0)
                {
                    //Header was clicked.
                    var listModelicaLibrary = libData.Cast<ModelicaLibrary>().ToList();
                    libData.Clear();
                    foreach (var lib in listModelicaLibrary.OrderBy(lib => lib.Name))
                    {
                        libData.Add(lib);
                    }
                }
            }

            if (e.ColumnIndex == 2)
            {
                this.clickedLib = this.dataGridView1.Rows[e.RowIndex].DataBoundItem as ModelicaLibrary;
                this.versionMenu = new ContextMenuStrip();
                foreach (var ver in this.clickedLib.Versions.OrderBy(tup => tup.Item1))
                {
                    var item = new ToolStripMenuItem(ver.Item1 + " - " + ver.Item2)
                    {
                        Checked = false,
                        Name = ver.Item1,
                    };

                    item.Click += new EventHandler(toolStripMenuItem_Click);

                    if (ver.Item1 == this.clickedLib.Version)
                    {
                        item.Checked = true;
                    }
                    this.versionMenu.Items.Add(item);
                }

                var cellRectangle = dataGridView1.GetCellDisplayRectangle(2, e.RowIndex, true);
                this.versionMenu.Show(this.dataGridView1, cellRectangle.Location);
            }
        }