From 033b3514f8133f2f11eb1fe790b13e290c013cdc Mon Sep 17 00:00:00 2001 From: Rich Date: Mon, 15 Sep 2014 21:10:27 +0000 Subject: [PATCH] Added some error handling to keep from crashing Added code to support Opposite Unit replace words with and without ROs. Added logic to limit UpcaseAllRoUnits to only work for setpoints. --- .../VEPROMS.CSLA.Library/Extension/ItemExt.cs | 15 ++-- PROMS/Volian.Controls.Library/DisplayText.cs | 78 ++++++++++++++++++- 2 files changed, 83 insertions(+), 10 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs index 0ae71627..4e0bbffd 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs @@ -3637,12 +3637,15 @@ namespace VEPROMS.CSLA.Library if (_TemplateColumnMode == null) { ItemInfo pi = ActiveParent as ItemInfo; - if (!pi.IsStep) // only steps are in template - _TemplateColumnMode = -1; - else if (pi.FormatStepData.UseOldTemplate) - _TemplateColumnMode = pi.TemplateChildColumnMode; - else - _TemplateColumnMode = pi.TemplateColumnMode; // go up parents until find of columnmode or section + if (pi != null) + { + if (!pi.IsStep) // only steps are in template + _TemplateColumnMode = -1; + else if (pi.FormatStepData.UseOldTemplate) + _TemplateColumnMode = pi.TemplateChildColumnMode; + else + _TemplateColumnMode = pi.TemplateColumnMode; // go up parents until find of columnmode or section + } } return _TemplateColumnMode ?? -1; } diff --git a/PROMS/Volian.Controls.Library/DisplayText.cs b/PROMS/Volian.Controls.Library/DisplayText.cs index e0ea03a2..86fc511c 100644 --- a/PROMS/Volian.Controls.Library/DisplayText.cs +++ b/PROMS/Volian.Controls.Library/DisplayText.cs @@ -344,8 +344,71 @@ namespace Volian.Controls.Library } } } + text = FixDiffUnitROReplaceWords(text); return text; } + + private string FixDiffUnitROReplaceWords(string text) + { + if (_MyFormat == null) return text; + ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList; + + // The only way to get an 'empty' list is to have one 'dummy' replacestr, i.e. that has ReplaceWord as an empty string. If the + // ReplaceStrData xml node is empty, it does the inheritance and gets the 'base' format's list. + if (rsl.Count == 1 && (rsl[0].ReplaceWord == null || rsl[0].ReplaceWord == "")) return text; + // Loop through text looking for words to be replaced + List partialReplaceList = new List(); + foreach (ReplaceStr rs in rsl) + { + if (rs.ReplaceWord.Contains("{RO}")) + { + if (_MyItemInfo.InList(34770,34771,34782,34882,34886,34916,34891,35121,36361)) + Console.WriteLine("FixDiffUnitROReplaceWords jcb"); + string oldvalue = text; + string replaceWord = rs.ReplaceWord; + string replaceWord2 = Regex.Replace( replaceWord,@"(\{RO\})([0-9,]+)(\{RO\})",@"\\v 0) + { + Match mm = Regex.Match(text, replaceWord2, RegexOptions.IgnoreCase); + return matches[0]; + } + return null; + } private int FindUnderlineTerminator(string text) { int idx = -1; @@ -1298,7 +1361,7 @@ namespace Volian.Controls.Library } // UpcaseAllRoUnits - Uppercases ALL ROs units everywhere. - if (_MyItemInfo.ActiveFormat.PlantFormat.FormatData.ROData.UpcaseAllRoUnits) + if (isSetpoint && _MyItemInfo.ActiveFormat.PlantFormat.FormatData.ROData.UpcaseAllRoUnits) return UpperCaseUnits(rtnstr); //Forces the units for a RO to be uppercased for high level steps @@ -1895,6 +1958,8 @@ namespace Volian.Controls.Library { //if(offset != 0 || foundMatch.MyMatch.Index != 0 || !foundMatch.MyWord.ReplaceWith.StartsWith(@"{\par}")) //{ + if (((foundMatch.MyWord.Flag & E_ReplaceFlags.DiffUnit) == 0) || DiffUnit(foundMatch.MyWord.ReplaceWord,_MyItemInfo,"UNIT ")) + { string with = foundMatch.MyWord.ReplaceWith; if (offset == 0 && with.StartsWith(@"{\par}")) if(StartsWith(text,foundMatch.MyMatch.Index,"",@"\ul ",@"\b ",@"* ",@"* \ul ",@"* \b ",@"*",@"*\ul ",@"*\b ")) @@ -1940,16 +2005,21 @@ namespace Volian.Controls.Library with = with.Replace(@"\ulnone ", ""); } - text = text.Substring(0, offset + foundMatch.MyMatch.Index) + with + text.Substring(offset + foundMatch.MyMatch.Index + foundMatch.MyMatch.Length); + text = text.Substring(0, offset + foundMatch.MyMatch.Index) + with + text.Substring(offset + foundMatch.MyMatch.Index + foundMatch.MyMatch.Length); //offset += foundMatch.MyWord.ReplaceWith.Length - foundMatch.MyMatch.Length; offset += with.Length - foundMatch.MyMatch.Length; - //} + } } } } return text; } - + internal static bool DiffUnit(string unit,ItemInfo myItemInfo,string prefix) + { + if (unit.StartsWith(prefix)) + return unit.Substring(prefix.Length) != myItemInfo.MyDocVersion.DocVersionConfig.Unit_Number; + return true; + } private bool VerifyNoHardSpace(string text, FoundMatch foundMatch, int offset) { string begin = text.Substring(0, offset + foundMatch.MyMatch.Index);