Ejemplo n.º 1
0
        public List <PCommand> MakeTabCommandFromSpec(string specText)
        {
            var commands = new List <PCommand>();

            int removeStart = 0;

            UnselectDelta(ref removeStart, ref specText);
            specText = specText.TrimEnd();
            if (specText.EndsWith("."))
            {
                specText = specText.Substring(0, specText.Length - 1);
            }

            commands.Add(new ChangeSelectionCommand(removeStart, specText.Length));
            commands.Add(new MoveToCommand(specText.Length));

            foreach (var lineInfo in new ListReader(specText))
            {
                Match match;
                match = MatchNMRSpec(lineInfo.Text);
                if (!match.Success)
                {
                    return(null);
                }
                PeakInfo info = CreatePeakInfo(match, lineInfo.Index);
                AddTabIPJC(commands, info);
            }
            commands.Add(new TypeParagraphCommand());
            commands.Add(new ReplaceStringCommand(0, specText.Length, ""));

            return(commands);
        }
Ejemplo n.º 2
0
        internal void AddSpecIPJC(List <PCommand> commands, PeakInfo info)
        {
            bool isFirst = true;

            if (info.Integration != null || info.Pattern != null || info.JValues != null || info.CommentRange != null)
            {
                commands.Add(new TypeTextCommand(" ("));

                foreach (var action in Format.ActionsToSpec)
                {
                    isFirst = action(commands, info, isFirst);
                }

                if (info.CommentRange != null)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        commands.Add(new TypeTextCommand(", "));
                    }
                    commands.Add(new CopyAndPasteCommand(info.CommentRange.Start, info.CommentRange.Length));
                    commands.Add(new FontResetCommand());
                }
                commands.Add(new TypeTextCommand(")"));
            }
        }
Ejemplo n.º 3
0
 internal static void AddTabI(List <PCommand> commands, PeakInfo info)
 {
     commands.Add(new TypeTextCommand("\t"));
     if (info.Integration != null)
     {
         commands.Add(new TypeTextCommand(info.Integration));
     }
 }
Ejemplo n.º 4
0
        public List <PCommand> MakeSpecCommandFromTab(string tabText)
        {
            var commands = new List <PCommand>();

            int removeStart = 0;

            UnselectDelta(ref removeStart, ref tabText);
            if (tabText.StartsWith("\r"))
            {
                tabText      = tabText.Substring(1);
                removeStart += 1;
            }
            {
                var trim = tabText.TrimEnd();
                if (trim.EndsWith("\r."))
                {
                    tabText = trim.Substring(0, trim.Length - 1);
                }
            }
            commands.Add(new ChangeSelectionCommand(removeStart, tabText.Length));

            commands.Add(new MoveToCommand(tabText.Length));
            commands.Add(new FontResetCommand());

            bool isFirst = true;

            foreach (var lineInfo in new LineReader(tabText))
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    commands.Add(new TypeTextCommand(", "));
                }

                Match match;
                match = MatchTabSeparatedSpec(lineInfo.Text);
                if (!match.Success)
                {
                    return(null);
                }
                PeakInfo info = CreatePeakInfo(match, lineInfo.Index);

                commands.Add(new TypeTextCommand(info.ChemicalShift));
                AddSpecIPJC(commands, info);
            }
            commands.Add(new ReplaceStringCommand(0, tabText.Length, ""));
            commands.Add(new MoveToCommand(0));
            commands.Add(new TypeBackspaceCommand());

            return(commands);
        }
Ejemplo n.º 5
0
 internal static void AddTabPJ(List <PCommand> commands, PeakInfo info)
 {
     commands.Add(new TypeTextCommand("\t"));
     if (info.Pattern != null)
     {
         commands.Add(new TypeTextCommand(info.Pattern));
     }
     commands.Add(new TypeTextCommand("\t"));
     if (info.JValues != null)
     {
         commands.Add(new TypeTextCommand(string.Join(", ", info.JValues)));
     }
 }
Ejemplo n.º 6
0
        public static PeakInfo CreatePeakInfo(Match match, int rangeShift)
        {
            PeakInfo info = new PeakInfo
            {
                ChemicalShift = match.Groups["shift"].Value
            };

            {
                var g = match.Groups["integration"];
                if (g.Success)
                {
                    var s = g.Value.Trim();
                    if (s.Length > 0)
                    {
                        info.Integration = g.Value;
                    }
                }
            }
            {
                var g = match.Groups["pattern"];
                if (g.Success)
                {
                    var s = g.Value.Trim();
                    if (s.Length > 0)
                    {
                        info.Pattern = g.Value;
                    }
                }
            }
            {
                var jinfo = new List <string>();
                foreach (Capture c in match.Groups["JValue"].Captures)
                {
                    jinfo.Add(c.Value);
                }
                info.JValues = jinfo.Count == 0 ? null : jinfo;
            }
            {
                var g = match.Groups["comment"];
                if (g.Captures.Count > 0)
                {
                    var s = g.Value.Trim();
                    if (s.Length > 0)
                    {
                        info.CommentRange = new Range(g.Index + rangeShift, g.Length);
                    }
                }
            }

            return(info);
        }
Ejemplo n.º 7
0
 internal void AddTabIPJC(List <PCommand> commands, PeakInfo info)
 {
     commands.Add(new TypeParagraphCommand());
     commands.Add(new FontResetCommand());
     commands.Add(new TypeTextCommand(info.ChemicalShift));
     foreach (var action in Format.ActionsToTab)
     {
         action(commands, info);
     }
     commands.Add(new TypeTextCommand("\t"));
     if (info.CommentRange != null)
     {
         commands.Add(new CopyAndPasteCommand(info.CommentRange.Start, info.CommentRange.Length));
     }
 }
Ejemplo n.º 8
0
        internal static bool AddSpecI(List <PCommand> commands, PeakInfo info, bool isFirst)
        {
            if (info.Integration != null)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    commands.Add(new TypeTextCommand(", "));
                }
                commands.Add(new TypeTextCommand(info.Integration));
            }

            return(isFirst);
        }
Ejemplo n.º 9
0
        internal static bool AddSpecPJ(List <PCommand> commands, PeakInfo info, bool isFirst, bool italic)
        {
            if (info.Pattern != null)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    commands.Add(new TypeTextCommand(", "));
                }
                commands.Add(new TypeTextCommand(info.Pattern));
            }
            if (info.JValues != null)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    commands.Add(new TypeTextCommand(", "));
                }
                if (italic)
                {
                    commands.Add(new EnableItalicCommand());
                }
                commands.Add(new TypeTextCommand("J"));
                if (italic)
                {
                    commands.Add(new FontResetCommand());
                }
                commands.Add(new TypeTextCommand($" = {string.Join(", ", info.JValues)} Hz"));
            }

            return(isFirst);
        }
Ejemplo n.º 10
0
 internal static bool AddSpecPJ_N(List <PCommand> commands, PeakInfo info, bool isFirst)
 => AddSpecPJ(commands, info, isFirst, false);