From bec2a177a51a2f3ba13b6d21b9cd1ede16fef3c9 Mon Sep 17 00:00:00 2001 From: Rich Date: Wed, 9 Jan 2013 20:34:42 +0000 Subject: [PATCH] Added support to save reference objects derived from word documents to support Westinghouse --- .../Volian.Controls.Library/StepTabRibbon.cs | 220 ++++++++++++++++++ 1 file changed, 220 insertions(+) diff --git a/PROMS/Volian.Controls.Library/StepTabRibbon.cs b/PROMS/Volian.Controls.Library/StepTabRibbon.cs index e2fe4d59..25d869d7 100644 --- a/PROMS/Volian.Controls.Library/StepTabRibbon.cs +++ b/PROMS/Volian.Controls.Library/StepTabRibbon.cs @@ -58,6 +58,8 @@ namespace Volian.Controls.Library MyStepRTB = null; } } + // added jcb 20121221 to support set ro from word doc + private ROFSTLookup MyLookup; private DocVersionInfo _MyDVI; public DocVersionInfo MyDVI { @@ -69,6 +71,8 @@ namespace Volian.Controls.Library ItemInfo procInfo = _MyEditItem.MyItemInfo.MyProcedure as ItemInfo; if (procInfo == null) return null; _MyDVI = procInfo.ActiveParent as DocVersionInfo; + // added jcb 20121221 to support set ro from word doc + MyLookup = _MyDVI.DocVersionAssociations[0].MyROFst.ROFSTLookup; return _MyDVI; } return null; @@ -89,10 +93,226 @@ namespace Volian.Controls.Library { _ContextMenuBar.SetContextMenuEx(_MyStepRTB, null); } + + #region Save ROs from Word Document jcb 20121221 + private string MyLookupData; + private Dictionary MyAvailableROs; public void SetContextMenu() { + #region set up save ro menu jcb 20121221 + MyAvailableROs = new Dictionary(); + DevComponents.DotNetBar.BaseItem btnSaveRO = null; + if (!btnCMRtfEdit.SubItems.Contains("btnSaveRO")) + { + btnSaveRO = new DevComponents.DotNetBar.ButtonItem("btnSaveRO", "Save RO"); + btnSaveRO.Visible = false; + btnCMRtfEdit.SubItems.Add(btnSaveRO); + } + else + btnSaveRO = btnCMRtfEdit.SubItems["btnSaveRO"]; + if (Clipboard.ContainsData(System.Windows.Forms.DataFormats.Text)) + { + MyLookupData = Clipboard.GetData(System.Windows.Forms.DataFormats.Text).ToString(); + if (MyLookupData.StartsWith(" 0 && MyStepRTB.SelectedText.ToLower() != MyAvailableROs[k].ToLower()) + { + btn = new DevComponents.DotNetBar.ButtonItem("_" + k, MyAvailableROs[k] + " with Annotation"); + btn.Tag = MyAvailableROs[k]; + btn.Click += new EventHandler(SaveROWithAnnotation_Click); + btnSaveRO.SubItems.Add(btn); + } + } + btnSaveRO.Visible = true; + } + else + { + btnSaveRO.SubItems.Clear(); + btnSaveRO.Text = "No RO Found"; + DevComponents.DotNetBar.BaseItem btn = new DevComponents.DotNetBar.ButtonItem("btnRONotFound", "Create Annotation"); + btn.Tag = string.Format("Text '{0}' has no corresponding RO", MyStepRTB.SelectedText); + btn.Click += new EventHandler(NoROFound_Click); + btnSaveRO.SubItems.Add(btn); + btnSaveRO.Visible = true; + } + } + } + #endregion _ContextMenuBar.SetContextMenuEx(_MyStepRTB, btnCMRtfEdit); } + private bool IsValidRO(string data) + { + bool rv = false; + MyAvailableROs = new Dictionary(); + if (MyDVI != null) + { + #region force arp without hi or lo jcb 20121221 + //if (data == "") + //{ + // data = data.Replace("-LO1", ""); + // Console.WriteLine("force null roc"); + //} + #endregion + string accPageID = GetAccPageID(data); + ROFSTLookup.rochild? roc = MyLookup.GetRoChildByAccPagID(accPageID, MyDVI.DocVersionConfig.RODefaults_setpointprefix, MyDVI.DocVersionConfig.RODefaults_graphicsprefix); + if (roc != null) + { + int index = GetROValueIndex(data); + if (index > -1) + { + MyAvailableROs.Add(((ROFSTLookup.rochild)roc).children[index].roid, ((ROFSTLookup.rochild)roc).children[index].value.Replace(@"\u160?", " ")); + rv = true; + } + } + else + { + //see if arp then try HI 1,2,3 and LO 1,2,3 + if (accPageID.StartsWith("ARP")) + { + string tmpAccPageID = string.Empty; + //try HI1,2,3 + string suffix = "-HI"; + for (int i = 1; i < 4; i++) + { + tmpAccPageID = accPageID + suffix + i.ToString(); + roc = MyLookup.GetRoChildByAccPagID(tmpAccPageID, MyDVI.DocVersionConfig.RODefaults_setpointprefix, MyDVI.DocVersionConfig.RODefaults_graphicsprefix); + if (roc != null) + { + int index = GetROValueIndex(data); + if (index > -1) + { + MyAvailableROs.Add(((ROFSTLookup.rochild)roc).children[index].roid, ((ROFSTLookup.rochild)roc).children[index].value.Replace(@"\u160?", " ")); + rv = true; + } + } + } + //try LO1,2,3 + suffix = "-LO"; + for (int i = 1; i < 4; i++) + { + tmpAccPageID = accPageID + suffix + i.ToString(); + roc = MyLookup.GetRoChildByAccPagID(tmpAccPageID, MyDVI.DocVersionConfig.RODefaults_setpointprefix, MyDVI.DocVersionConfig.RODefaults_graphicsprefix); + if (roc != null) + { + int index = GetROValueIndex(data); + if (index > -1) + { + MyAvailableROs.Add(((ROFSTLookup.rochild)roc).children[index].roid, ((ROFSTLookup.rochild)roc).children[index].value.Replace(@"\u160?", " ")); + rv = true; + } + } + } + } + } + } + return rv; + } + private string GetAccPageID(string txt) + { + // + // + // + txt = txt.Replace(" 0) + rv = 0; + else if (data.IndexOf(@"\s") > 0) + rv = 1; + else if (data.IndexOf(@"\t") > 0) + rv = 2; + else if (data.IndexOf(@"\d") > 0) + rv = 3; + else + rv = -1; + } + if (data.StartsWith(" 0) + rv = 0; + else if (data.IndexOf(@"\d") > 0) + rv = 1; + else if (data.IndexOf(@"\r") > 0) + rv = 2; + else + rv = -1; + } + if (data.StartsWith(" 0) + rv = 0; + else if (data.IndexOf(@"\d") > 0) + rv = 1; + else if (data.IndexOf(@"\n") > 0) + rv = 2; + else + rv = -1; + } + return rv; + } + private void SaveRO_Click(object sender, EventArgs e) + { + DevComponents.DotNetBar.BaseItem btn = sender as DevComponents.DotNetBar.BaseItem; + string myroid = btn.Name; + string myvalue = btn.Tag.ToString(); + // the roid may be 12 or 16 chars long, with the last 4 set if there is unit specific + // menuing. Pad to 12 to store in the rousage table. + string padroid = (myroid.Length <= 12) ? myroid + "0000" : myroid; + string linktxt = string.Format(@"#Link:ReferencedObject: {0} {1}", padroid, MyLookup.DocVersionInfo.DocVersionAssociations[0].MyROFst.MyRODb.RODbID); + // Resolve symbols and scientific notation in the RO return value + string valtxt = MyLookup.GetTranslatedRoValue(padroid, MyStepRTB.MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta); //ConvertSymbolsAndStuff(selectedChld.value); + MyStepRTB.OnRoInsert(this, new StepRTBRoEventArgs(valtxt, myvalue, linktxt, padroid, MyLookup.DocVersionInfo.DocVersionAssociations[0].MyROFst.MyRODb.RODbID)); + } + private void SaveROWithAnnotation_Click(object sender, EventArgs e) + { + DevComponents.DotNetBar.BaseItem btn = sender as DevComponents.DotNetBar.BaseItem; + string myroid = btn.Name.Replace("_", ""); + string myvalue = btn.Tag.ToString(); + using (Item itm = MyStepRTB.MyItemInfo.Get()) + { + Annotation x = Annotation.MakeAnnotation(itm, AnnotationType.GetByName("RO Value Changed"), null, string.Format("RO Value '{0}' replaces text '{1}'", myvalue, MyStepRTB.SelectedText), null); + } + // the roid may be 12 or 16 chars long, with the last 4 set if there is unit specific + // menuing. Pad to 12 to store in the rousage table. + string padroid = (myroid.Length <= 12) ? myroid + "0000" : myroid; + string linktxt = string.Format(@"#Link:ReferencedObject: {0} {1}", padroid, MyLookup.DocVersionInfo.DocVersionAssociations[0].MyROFst.MyRODb.RODbID); + // Resolve symbols and scientific notation in the RO return value + string valtxt = MyLookup.GetTranslatedRoValue(padroid, MyStepRTB.MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta); //ConvertSymbolsAndStuff(selectedChld.value); + MyStepRTB.OnRoInsert(this, new StepRTBRoEventArgs(valtxt, myvalue, linktxt, padroid, MyLookup.DocVersionInfo.DocVersionAssociations[0].MyROFst.MyRODb.RODbID)); + } + private void NoROFound_Click(object sender, EventArgs e) + { + DevComponents.DotNetBar.BaseItem btn = sender as DevComponents.DotNetBar.BaseItem; + string myvalue = btn.Tag.ToString(); + using (Item itm = MyStepRTB.MyItemInfo.Get()) + { + Annotation x = Annotation.MakeAnnotation(itm, AnnotationType.GetByName("RO Missing"), null, myvalue, null); + } + } + #endregion + public void SetGridCellContextMenu() { _ContextMenuBar.SetContextMenuEx(_MyStepRTB, btnCMRtfCellEdit);