Added support to save reference objects derived from word documents to support Westinghouse

This commit is contained in:
Rich 2013-01-09 20:34:42 +00:00
parent dd6285f4a4
commit bec2a177a5

View File

@ -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<string, string> MyAvailableROs;
public void SetContextMenu()
{
#region set up save ro menu jcb 20121221
MyAvailableROs = new Dictionary<string, string>();
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("<STP") || MyLookupData.StartsWith("<MEL") || MyLookupData.StartsWith("<ARP"))
{
if (IsValidRO(MyLookupData))
{
btnSaveRO.SubItems.Clear();
btnSaveRO.Text = "Save RO";
foreach (string k in MyAvailableROs.Keys)
{
DevComponents.DotNetBar.BaseItem btn = new DevComponents.DotNetBar.ButtonItem(k, MyAvailableROs[k]);
btn.Tag = MyAvailableROs[k];
btn.Click += new EventHandler(SaveRO_Click);
btnSaveRO.SubItems.Add(btn);
if (MyStepRTB.SelectedText.Length > 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<string, string>();
if (MyDVI != null)
{
#region force arp without hi or lo jcb 20121221
//if (data == "<ARP CDS-LT002-1-MED-LO1 \\s\\l\\1>")
//{
// 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)
{
//<MEL FWS-MP-02B \\n \\H>
//<STP L19 \\v \\E \\H \\P \\S >
//<ARP FWS-MP-02C-TMP1 \\s \\h \\1>
txt = txt.Replace("<MEL ", "MEL-");
txt = txt.Replace("<STP ", MyDVI.DocVersionConfig.RODefaults_setpointprefix + "-");
txt = txt.Replace("<ARP ", "ARP-");
int i = txt.IndexOf(" ");
txt = txt.Substring(0, i);
return txt;
}
private int GetROValueIndex(string data)
{
int rv = -1;
if (data.StartsWith("<ARP"))
{
// arp children = \n alarm, \s value, \t type, \d description
if (data.IndexOf(@"\n") > 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("<MEL"))
{
//mel children = \n name, \d description, \r room
if (data.IndexOf(@"\n") > 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("<STP"))
{
//stp children = \v value, \d description, \n id
if (data.IndexOf(@"\v") > 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:<NewID> {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:<NewID> {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);