diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs index 6194565b..b731c4ee 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs @@ -695,17 +695,28 @@ namespace VEPROMS.CSLA.Library if (m == null) newvalue = newvalue.Replace(@"\u8209?", "-"); else if (m.Groups[1].Value == "") - newvalue = newvalue.Replace(@"\u8209?", @"\f1\u8209?\f0 "); + newvalue = newvalue.Replace(@"\u8209?", "-"); else newvalue = newvalue.Replace(@"\u8209?", m.Groups[1].Value + @"\u8209?" + m.Groups[3].Value); } + int indx_to_addfont = -1; if (newvalue.Contains(@"\u916?")) { Match m = Regex.Match(newvalue, @"(\\f[0-9]+)(\\u[0-9]{1,4}\?)(\\f[0-9]+ ?)"); if (m == null) newvalue = newvalue.Replace(@"\u916?", "^"); + else if (m.Groups[1].Value == "" && !ContentItems[0].MyItem.MyItemInfo.MyDocVersion.MyFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta) + newvalue = newvalue.Replace(@"\u916?", "^"); else if (m.Groups[1].Value == "") - newvalue = newvalue.Replace(@"\u916?", @"\f1\u916?\f0 "); + { + //B2024-003, B2023-113, B2024-093 - Updating RO Values inside a text Grid, + // adding a caret and/or dash into the RO value and then updating RO values changed to question marks in the UI. + // This is to handle if ConvertCaretToDelta is true + // since delta is not part of the standard ascii + // may need to add a font to handle it. + newvalue = newvalue.Replace(@"\u916?", @"\f9\u916?\f0 "); + indx_to_addfont = GetLocationToInsertFontInGrid(myIndex); + } else newvalue = newvalue.Replace(@"\u916?", m.Groups[1].Value + @"\u916?" + m.Groups[3].Value); } @@ -715,7 +726,7 @@ namespace VEPROMS.CSLA.Library if (m == null) newvalue = newvalue.Replace(@"\u8593?", "^"); else if (m.Groups[1].Value == "") - newvalue = newvalue.Replace(@"\u8593?", @"\f1\u8593?\f0 "); + newvalue = newvalue.Replace(@"\u8593?", "^"); else newvalue = newvalue.Replace(@"\u8593?", m.Groups[1].Value + @"\u8593?" + m.Groups[3].Value); } @@ -725,7 +736,7 @@ namespace VEPROMS.CSLA.Library if (m == null) newvalue = newvalue.Replace(@"\u9586?", @"\\"); else if (m.Groups[1].Value == "") - newvalue = newvalue.Replace(@"\u9586?", @"\f1\u9586?\f0 "); + newvalue = newvalue.Replace(@"\u9586?", @"\\"); else newvalue = newvalue.Replace(@"\u9586?", m.Groups[1].Value + @"\u9586?" + m.Groups[3].Value); } @@ -737,7 +748,17 @@ namespace VEPROMS.CSLA.Library if (gg != newvalue) { retval = gg; - MyGrid.Data = MyGrid.Data.Substring(0, myIndex) + newvalue + MyGrid.Data.Substring(myIndex + myLength); + //B2024-003, B2023-113, B2024-093 - Updating RO Values inside a text Grid, + // adding a caret and/or dash into the RO value and then updating RO values changed to question marks in the UI. + // This is to handle if ConvertCaretToDelta is true + // since delta is not part of the standard ascii + // may need to add a font to handle it. + string begin_str = MyGrid.Data.Substring(0, myIndex); + if (indx_to_addfont > -1) + begin_str = begin_str.Insert(indx_to_addfont, @"{\f9\fnil\fcharset0 FreeMono;}"); + + MyGrid.Data = begin_str + newvalue + MyGrid.Data.Substring(myIndex + myLength); + MyGrid.Save(); break; } } @@ -747,6 +768,64 @@ namespace VEPROMS.CSLA.Library return retval; } + //B2024-003, B2023-113, B2024-093 - Updating RO Values inside a text Grid, + // adding a caret and/or dash into the RO value and then updating RO values changed to question marks in the UI. + // This is to handle if ConvertCaretToDelta is true + // since delta is not part of the standard ascii + // may need to add a font to handle it. + // startIndex = Index in the Grid at which the text we want to replace is starting + //basic Grid data partitioning using the variables in this sub is as follows: + // + // [indexOfPrefix] [indx] + // | | + // [text before last occurrence of prefix] {prefix} [rest of fonts] [text after fonts] + private int GetLocationToInsertFontInGrid(int startIndex) + { + //searches backwards from the srtIndex for the last previous occurrence of the prefix + string prefix = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{"; + int indexOfPrefix = MyGrid.Data.LastIndexOf(prefix, startIndex); + + //find the end of the font section + //by passing in the Grid data + //with the following removed: + // - Everything before the last occurrence of the prefix + // - the prefix itself removed + int indx = GetIndexOfCloseBracket(MyGrid.Data.Substring(indexOfPrefix + prefix.Length, startIndex - indexOfPrefix - prefix.Length)); + + if (indx > -1) + { + indx += indexOfPrefix; + indx += prefix.Length; + } + + //indx will contain last spot inside the font section + return indx; + + } + + //B2024-003, B2023-113, B2024-093 - Updating RO Values inside a text Grid, + // this function will find the corresponding occurrence of a closing bracket : + // usage is you pass in some text after an opening bracket, and it will tell you what the index is for it closing + private int GetIndexOfCloseBracket(string text) + { + int indx = 0; + Stack stk = new System.Collections.Generic.Stack(); + + foreach (char c in text) + { + if (c == '{') + stk.Push('{'); + else if (c == '}' && stk.Count == 0) + return indx; + else if (c == '}') + stk.Pop(); + + indx++; + } + + return -1; + } + public static string MakeConsistentFormat(string gg) { // replace degree, bullet dash, hardspace @@ -1325,7 +1404,19 @@ namespace VEPROMS.CSLA.Library else newvalue = newvalue.Replace(@"\u8209?", m.Groups[1].Value + @"\u8209?" + m.Groups[3].Value); } - + //B2024-003, B2023-113, B2024-093 - Updating RO Values inside a text Grid, + // This will handle if there is a delta and the column/row of the grid is removed + //then restored from history + if (newvalue.Contains(@"\u916?")) + { + Match m = Regex.Match(gg, @"(\\f[0-9]+)(\\u[0-9]{1,4}\?)(\\f[0-9]+ ?)"); + if (m.Groups.Count < 3 && !ContentItems[0].MyDocVersion.MyFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta) + newvalue = newvalue.Replace(@"\u916?", "^"); + else if (m.Groups.Count < 3) + newvalue = newvalue.Replace(@"\u916?", $"{(char)916}"); + else + newvalue = newvalue.Replace(@"\u916?", m.Groups[1].Value + @"\u916?" + m.Groups[3].Value); + } if (newvalue.Contains(@"\u8593?")) { Match m = Regex.Match(newvalue, @"(\\f[0-9]+)(\\u[0-9]{1,4}\?)(\\f[0-9]+ ?)");