예제 #1
0
 private void PopulateModulesList(List <string> filenamesList)
 {
     foreach (var item in filenamesList)
     {
         KicadModule module = new KicadModule();
         using (StreamReader sr = new StreamReader(item))
         {
             var content = sr.ReadToEnd();
             module.Content = content;
             try
             {
                 module.Path            = item;
                 module.FileName        = System.IO.Path.GetFileName(item);
                 module.Name            = new Regex(@"\(module\s(.*)\s\(layer").Match(content).Groups[1].Value;
                 module.Value           = new Regex(@"\(fp_text\svalue\s(.*)\s\(at").Match(content).Groups[1].Value;
                 module.LinkToDatasheet = new Regex(@"\(descr\s""(.*)""").Match(content).Groups[1].Value;
                 module.KeywordsList    = new Regex(@"\(tags\s""(.*)""").Match(content).Groups[1].Value.Split(' ').ToList();
                 module.LinkTo3DModel   = new Regex(@"\(model\s(.*)\n").Match(content).Groups[1].Value;
                 ModulesList.Add(module);
             }
             catch (Exception)
             {
                 MessageBox.Show("something wrong with regexps", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
     }
 }
예제 #2
0
        private void MakeBackupFile(KicadModule item, string curDate)
        {
            //FileInfo file = new FileInfo(System.IO.Path.GetDirectoryName(item.Path) + "\\xxx\\");

            FileInfo file = new FileInfo(System.IO.Path.GetDirectoryName(item.Path) + "\\backup_" + curDate + "\\");

            file.Directory.Create(); // If the directory already exists, this method does nothing.
            File.WriteAllText(file.FullName + item.FileName + "bak", item.Content);
        }
예제 #3
0
        private void AddNewKeywords(KicadModule item, string filename)
        {
            var newKeywordsList = System.IO.Path.GetFileNameWithoutExtension(item.FileName).Replace('_', ' ').Split(' ').ToList();

            item.KeywordsList.AddRange(newKeywordsList.Where(p2 =>
                                                             item.KeywordsList.All(p1 => p1 != p2)));
            var newKeywords = String.Join(" ", item.KeywordsList.ToArray());

            //Regex.Match(item.Content, @"(\(tags\s*"")(.*)("".*)").Groups[2].Value;
            item.Content = Regex.Replace(item.Content, @"(\(tags\s*"")(.*)("".*)", "$1" + newKeywords + "$3");
        }
예제 #4
0
        private void SaveModuleToDisk(KicadModule item)
        {
            var filename = System.IO.Path.GetFileNameWithoutExtension(item.FileName);
            var curDate  = DateTime.Now.ToString().Replace(':', '-').Replace(' ', '_');

            MakeBackupFile(item, curDate);

            ReplaceModuleNameWithFilename(item, filename);
            ReplaceModuleValueWithFilename(item, filename);
            if (DoUpdate3DModelPathcheckBox.IsChecked.Value)
            {
                ReplaceModuleLinkTo3DModelWithFilename(item, filename);
            }
            AddNewKeywords(item, filename);
            File.WriteAllText(item.Path, item.Content);
        }
예제 #5
0
        private void OnItemSelect_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBox lstbox = sender as ListBox;

            if (lstbox.Items.Count > 0)
            {
                CurrentKicadModule         = GetModuleByFileName(lstbox.SelectedItem.ToString());
                ModuleFilenametb.Text      = CurrentKicadModule.FileName;
                ModuleNametb.Text          = CurrentKicadModule.Name;
                ModuleValuetb.Text         = CurrentKicadModule.Value;
                ModuleDatasheetLinktb.Text = CurrentKicadModule.LinkToDatasheet;
                ModuleKeywordsTagstb.Text  = String.Join(" ", CurrentKicadModule.KeywordsList.ToArray());
                Module3DModeLinkdtb.Text   = CurrentKicadModule.LinkTo3DModel;
                ContentRtb.Document.Blocks.Clear();
                ContentRtb.Document.Blocks.Add(new Paragraph(new Run(CurrentKicadModule.Content)));

                //to get RichTextBox text:
                //string richText = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text;
            }
        }
예제 #6
0
 private void ReplaceModuleNameWithFilename(KicadModule item, string filename)
 {
     item.Content = Regex.Replace(item.Content, @"(\(module\s*)(.*)(\s+\(layer)", "$1" + filename + "$3");
 }
예제 #7
0
 private void ReplaceModuleValueWithFilename(KicadModule item, string filename)
 {
     item.Content = Regex.Replace(item.Content, @"(\(fp_text value )(.*)(\s+\(at)", "$1" + filename + "$3");
 }
예제 #8
0
        private void ReplaceModuleLinkTo3DModelWithFilename(KicadModule item, string filename)
        {
            var str = Module3DModePathToAddtb.Text;

            item.Content = Regex.Replace(item.Content, @"(\(model\s)(.*)(\n)", "$1" + str + filename + ".wrl$3");
        }