
Corrected logic for returning the RO Value when the ROs do not have multiple return values. This fixes Bug B2013-080. Added logic to the code that looks for a newer version of the RO.FST file, when the DocVersion (Folder) does not have an assocated RO Database. Added Caption, Button and Icon to Warning Message when DocVersion (Folder) does not have an assocated RO Database. Added logic to support ROs that do not have Multiple return values. Fixed logic to support ROST lookup when the DocVersion (Folder) does not have an assocated RO Database Added Caption, Button and Icon to Warning Message when DocVersion (Folder) does not have an assocated RO Database. Shut-off the RO Edit feature when DocVersion (Folder) does not have an assocated RO Database.
831 lines
26 KiB
C#
831 lines
26 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
using VEPROMS.CSLA.Library;
|
|
using XYPlots;
|
|
using DevComponents.DotNetBar;
|
|
using System.Text.RegularExpressions;
|
|
using Volian.Base.Library;
|
|
//using VG;
|
|
|
|
namespace Volian.Controls.Library
|
|
{
|
|
public partial class DisplayRO : UserControl
|
|
{
|
|
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
#region Properties
|
|
private DisplayTabControl _TabControl;
|
|
|
|
public DisplayTabControl TabControl
|
|
{
|
|
get { return _TabControl; }
|
|
set { _TabControl = value; }
|
|
}
|
|
private ROFstInfo _CurROFST = null;
|
|
private ROFstInfo _MyROFST;
|
|
public ROFstInfo MyROFST
|
|
{
|
|
get { return _MyROFST; }
|
|
set
|
|
{
|
|
if (!Visible) return; // don't reset anything if the form is invisible.
|
|
_MyROFST = value; // define the tree nodes based on this rofst
|
|
LoadTree();
|
|
}
|
|
}
|
|
private RoUsageInfo _CurROLink;
|
|
public RoUsageInfo CurROLink
|
|
{
|
|
get { return _CurROLink; }
|
|
set
|
|
{
|
|
if (!Visible) return; // don't reset anything if the form is invisible.
|
|
if (value != null) // modify - set the controls to the current ro
|
|
{
|
|
if (_CurROLink == value) return;
|
|
_CurROLink = value;
|
|
_SavCurROLink = _CurROLink;
|
|
UpdateROTree();
|
|
}
|
|
else // insert - clear out controls
|
|
{
|
|
_CurROLink = value;
|
|
tbROValue.Text = null;
|
|
lbROId.Text = "";
|
|
tvROFST.SelectedNode = null;
|
|
btnGoToRO.Enabled = btnSaveRO.Enabled = btnCancelRO.Enabled = false;
|
|
}
|
|
}
|
|
}
|
|
private RoUsageInfo _SavCurROLink;
|
|
private StepRTB _MyRTB;
|
|
public StepRTB MyRTB
|
|
{
|
|
get { return _MyRTB; }
|
|
set
|
|
{
|
|
int origRoDbId = -1;
|
|
if (!Visible) return;
|
|
if (_MyRTB != null)
|
|
{
|
|
_MyRTB.LinkChanged -= new StepRTBLinkEvent(MyRTB_LinkChanged);
|
|
_MyRTB.SelectionChanged -= new EventHandler(MyRTB_SelectionChanged);
|
|
if (_MyRTB.MyItemInfo.MyDocVersion.DocVersionAssociationCount>0)
|
|
origRoDbId = _MyRTB.MyItemInfo.MyDocVersion.DocVersionAssociations[0].MyROFst.RODbID;
|
|
}
|
|
if (value == null) return;
|
|
_MyRTB = value;
|
|
MyRTB.LinkChanged += new StepRTBLinkEvent(MyRTB_LinkChanged);
|
|
MyRTB.SelectionChanged+=new EventHandler(MyRTB_SelectionChanged);
|
|
if (MyRTB.MyLinkText == null)
|
|
{
|
|
CurROLink = null;
|
|
_SavCurROLink = null;
|
|
}
|
|
// Test to see if this myrtf is using the same rofst as the previous. If
|
|
// not we may have to reset the ro.fst for the tree if the new working
|
|
// draft has a different ro.fst than the original:
|
|
if (_MyRTB != null && _MyRTB.MyItemInfo.MyDocVersion.DocVersionAssociationCount > 0)
|
|
{
|
|
if (origRoDbId != _MyRTB.MyItemInfo.MyDocVersion.DocVersionAssociations[0].MyROFst.RODbID)
|
|
MyROFST = _MyRTB.MyItemInfo.MyDocVersion.DocVersionAssociations[0].MyROFst;
|
|
}
|
|
// This docversion doesn't have an rofst associated with it, clear the ro tree.
|
|
else if (_MyRTB.MyItemInfo.MyDocVersion.DocVersionAssociationCount <= 0)
|
|
MyROFST = null;
|
|
}
|
|
}
|
|
|
|
void MyRTB_SelectionChanged(object sender, EventArgs e)
|
|
{
|
|
lbFound.SelectionMode = SelectionMode.None;
|
|
lbFound.DataSource = null;
|
|
//Spin through ROs looking for the selected text
|
|
if (MyRTB.SelectedText != "")
|
|
{
|
|
string lookFor = MyRTB.SelectedText.Replace('\u2011', '-');
|
|
List<ROFSTLookup.roChild> children = null;
|
|
if (_MyROFST != null) children = _MyROFST.ROFSTLookup.GetRosByValue(lookFor);
|
|
if (children != null)
|
|
{
|
|
lbFound.Visible = true;
|
|
lbFound.DataSource = children.ToArray();
|
|
lbFound.SelectionMode = SelectionMode.One;
|
|
lbFound.SelectedIndex = -1;
|
|
}
|
|
else
|
|
lbFound.Visible = false;
|
|
}
|
|
else
|
|
lbFound.Visible = false;
|
|
}
|
|
|
|
void MyRTB_LinkChanged(object sender, StepPanelLinkEventArgs args)
|
|
{
|
|
if (MyRTB.MyLinkText == null)
|
|
CurROLink = null;
|
|
else
|
|
{
|
|
CurROLink = args.MyLinkText.MyRoUsageInfo;
|
|
}
|
|
}
|
|
|
|
private DocVersionInfo _Mydvi;
|
|
|
|
public DocVersionInfo Mydvi
|
|
{
|
|
get { return _Mydvi; }
|
|
set { _Mydvi = value; }
|
|
}
|
|
|
|
|
|
private ProgressBarItem _ProgressBar;
|
|
|
|
public ProgressBarItem ProgressBar
|
|
{
|
|
get { return _ProgressBar; }
|
|
set { _ProgressBar = value; }
|
|
}
|
|
|
|
//public int ProgBarMax
|
|
//{
|
|
// get { return _ProgressBar.Maximum; }
|
|
// set { _ProgressBar.Maximum = value; }
|
|
//}
|
|
|
|
//public int ProgBarValue
|
|
//{
|
|
// get { return _ProgressBar.Value; }
|
|
// set { _ProgressBar.Value = value; }
|
|
//}
|
|
|
|
//public string ProgBarText
|
|
//{
|
|
// get { return _ProgressBar.Text; }
|
|
// set
|
|
// {
|
|
// _ProgressBar.TextVisible = true;
|
|
// _ProgressBar.Text = value;
|
|
// }
|
|
//}
|
|
|
|
#endregion
|
|
#region Constructors
|
|
public DisplayRO()
|
|
{
|
|
InitializeComponent();
|
|
_ProgressBar = null;
|
|
panelRoValue.BackColor = Color.Cornsilk;
|
|
panelValue.BackColor = Color.Cornsilk;
|
|
}
|
|
#endregion
|
|
#region Events
|
|
ROFSTLookup.rochild selectedChld;
|
|
private void tvROFST_AfterSelect(object sender, TreeViewEventArgs e)
|
|
{
|
|
tbROValue.Text = null;
|
|
lbROId.Text = "";
|
|
btnCancelRO.Enabled = false;
|
|
btnSaveRO.Enabled = false;
|
|
btnPreviewRO.Enabled = false;
|
|
btnGoToRO.Enabled = false;
|
|
|
|
if (e.Node.Tag is ROFSTLookup.rochild)
|
|
{
|
|
ROFSTLookup.rochild chld = (ROFSTLookup.rochild)e.Node.Tag;
|
|
selectedChld = chld;
|
|
if (chld.value != null)
|
|
{
|
|
RoUsageInfo SavROLink = null;
|
|
if (_SavCurROLink != null)
|
|
SavROLink = _SavCurROLink; ;
|
|
lbROId.Text = chld.appid;
|
|
// Allow the user to select a different return value.
|
|
//btnSaveRO.Enabled = ((_SavCurROLink == null) || !(chld.roid.Substring(0, 12).ToLower().Equals(SavROLink.ROID.Substring(0, 12).ToLower())));
|
|
//btnCancelRO.Enabled = ((_SavCurROLink != null) && chld.roid.Substring(0, 12).ToLower() != SavROLink.ROID.Substring(0, 12).ToLower());
|
|
string childroid = chld.roid.ToLower() + "0000";
|
|
childroid = childroid.Substring(0, 16);
|
|
btnSaveRO.Enabled = ((_SavCurROLink == null) || !(childroid.Equals(SavROLink.ROID.ToLower())));
|
|
btnCancelRO.Enabled = ((_SavCurROLink != null) && childroid != SavROLink.ROID.ToLower());
|
|
btnGoToRO.Enabled = true;
|
|
switch (chld.type)
|
|
{
|
|
case 1: // standard (regular) text RO type
|
|
tbROValue.Text = chld.value.Replace(@"\u160?"," ");
|
|
btnPreviewRO.Enabled = false;
|
|
break;
|
|
case 2: // Table RO type
|
|
case 3: // This is type 3 when part of a multiple return value
|
|
tbROValue.Text = "(Table)";
|
|
btnPreviewRO.Enabled = true;
|
|
break;
|
|
case 4: // X/Y Plot RO type
|
|
tbROValue.Text = "(Graph)";
|
|
btnPreviewRO.Enabled = true;
|
|
break;
|
|
case 8: // Intergrated Graphics RO type
|
|
tbROValue.Text = "(Image)";
|
|
btnPreviewRO.Enabled = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//if (e.Node.Tag is ROFST.rochild)
|
|
//{
|
|
// ROFST.rochild chld = (ROFST.rochild)e.Node.Tag;
|
|
// if (chld.type == 1 && chld.value != null)
|
|
// {
|
|
// string SavROLink = "";
|
|
// if (_SavCurROLink != null)
|
|
// SavROLink = _SavCurROLink.Substring(_SavCurROLink.IndexOf(' ') + 1, 12);
|
|
// tbROValue.Text = chld.value;
|
|
// btnSaveRO.Enabled = ((_SavCurROLink == null) || !(chld.roid.Equals(SavROLink)));
|
|
// btnCancelRO.Enabled = ((_SavCurROLink != null) && !(chld.roid.Equals(SavROLink)));
|
|
// }
|
|
// //else
|
|
// //{
|
|
// // tbROValue.Text = null;
|
|
// // btnCancelRO.Enabled = btnSaveRO.Enabled = false;
|
|
// //}
|
|
//}
|
|
////else
|
|
////{
|
|
//// tbROValue.Text = null;
|
|
//// btnCancelRO.Enabled = btnSaveRO.Enabled = false;
|
|
////}
|
|
|
|
}
|
|
|
|
private void tvROFST_BeforeExpand(object sender, TreeViewCancelEventArgs e)
|
|
{
|
|
LoadChildren(e.Node);
|
|
}
|
|
private E_ROValueType _ROTypeFilter = E_ROValueType.All;
|
|
|
|
public E_ROValueType ROTypeFilter
|
|
{
|
|
get { return _ROTypeFilter; }
|
|
set
|
|
{
|
|
_ROTypeFilter = value;
|
|
LoadTree();
|
|
}
|
|
}
|
|
private E_ROValueType _CurrentROTypeFilter = E_ROValueType.All;
|
|
|
|
private void LoadChildren(TreeNode tn)
|
|
{
|
|
object tag = tn.Tag;
|
|
if (tn.FirstNode != null && tn.FirstNode.Text != "VLN_DUMMY_FOR_TREE") return; // already loaded.
|
|
if (tn.FirstNode != null && tn.FirstNode.Text == "VLN_DUMMY_FOR_TREE") tn.FirstNode.Remove();
|
|
ROFSTLookup.rochild[] chld = null;
|
|
|
|
if (tn.Tag is ROFSTLookup.rodbi)
|
|
{
|
|
ROFSTLookup.rodbi db = (ROFSTLookup.rodbi)tn.Tag;
|
|
chld = db.children;
|
|
}
|
|
else if (tn.Tag is ROFSTLookup.rochild)
|
|
{
|
|
ROFSTLookup.rochild ch = (ROFSTLookup.rochild)tn.Tag;
|
|
chld = ch.children;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("error - no type");
|
|
return;
|
|
}
|
|
// if children, add dummy node
|
|
if (chld != null && chld.Length > 0)
|
|
{
|
|
ProgressBar_Initialize(chld.Length, tn.Text);
|
|
for (int i = 0; i < chld.Length; i++)
|
|
{
|
|
ProgressBar_SetValue(i);
|
|
TreeNode tmp = null;
|
|
// if this is a group, i.e. type 0, add a dummy node
|
|
if (chld[i].type == 0 && chld[i].children == null)
|
|
//skip it.
|
|
// TODO: KBR how to handle this?
|
|
//Console.WriteLine("ro junk");
|
|
continue;
|
|
else if (ROTypeFilter != E_ROValueType.All && (chld[i].type & (uint)ROTypeFilter) == 0)
|
|
continue; // ignore if does not match filter
|
|
else if (/*chld[i].type == 1 && */ chld[i].value == null)
|
|
{
|
|
tmp = new TreeNode(chld[i].title);
|
|
tmp.Tag = chld[i];
|
|
//tn.Nodes.Add(tmp);
|
|
int index = FindIndex(tn.Nodes, tmp.Text);
|
|
tn.Nodes.Insert(index, tmp);
|
|
TreeNode sub = new TreeNode("VLN_DUMMY_FOR_TREE");
|
|
tmp.Nodes.Add(sub);
|
|
}
|
|
//else if (chld[i].type == 2 && chld[i].value == null) // table
|
|
//{
|
|
// if ((MyRTB.MyItemInfo.MyContent.Type % 10000) == (int)E_FromType.Table)
|
|
// {
|
|
// tmp = new TreeNode(chld[i].title);
|
|
// tmp.Tag = chld[i];
|
|
// tn.Nodes.Add(tmp);
|
|
// TreeNode sub = new TreeNode("VLN_DUMMY_FOR_TREE");
|
|
// tmp.Nodes.Add(sub);
|
|
// }
|
|
//}
|
|
else
|
|
{
|
|
tmp = new TreeNode(chld[i].title.Replace(@"\u160?"," "));
|
|
tmp.Tag = chld[i];
|
|
if (chld[i].roid.Length == 16)
|
|
tn.Nodes.Add(tmp);
|
|
else
|
|
{
|
|
int index = FindIndex(tn.Nodes, tmp.Text);
|
|
tn.Nodes.Insert(index, tmp);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ProgressBar_Clear();
|
|
}
|
|
private int FindIndex(TreeNodeCollection nodes, string value)
|
|
{
|
|
int index = 0;
|
|
foreach (TreeNode node in nodes)
|
|
{
|
|
if (GreaterValue(node.Text, value)) return index;
|
|
index++;
|
|
}
|
|
return index;
|
|
}
|
|
private static Regex _RegExGetNumber = new Regex(@"^ *[+-]?[.,0-9]+(E[+-]?[0-9]+)?");
|
|
private bool GreaterValue(string value1, string value2)
|
|
{
|
|
Match match1 = _RegExGetNumber.Match(value1);
|
|
Match match2 = _RegExGetNumber.Match(value2);
|
|
if (match1.Success && match2.Success) // Compare the numeric value
|
|
{
|
|
double dbl1 = double.Parse(match1.ToString());
|
|
double dbl2 = double.Parse(match2.ToString());
|
|
return dbl1 > dbl2;
|
|
}
|
|
return String.Compare(value1, value2, true) > 0;
|
|
}
|
|
public void RefreshRoTree()
|
|
{
|
|
string roid = null;
|
|
if (tvROFST.SelectedNode != null)
|
|
{
|
|
if (tvROFST.SelectedNode.Tag is ROFSTLookup.rochild)
|
|
{
|
|
ROFSTLookup.rochild chld = (ROFSTLookup.rochild)tvROFST.SelectedNode.Tag;
|
|
roid = chld.roid;
|
|
}
|
|
}
|
|
_CurROFST = null;
|
|
LoadTree();
|
|
if (_SelectedRoidBeforeRoEditor != null)
|
|
{
|
|
ExpandTree(_SelectedRoidBeforeRoEditor);
|
|
_SelectedRoidBeforeRoEditor = null;
|
|
}
|
|
}
|
|
private void LoadTree()
|
|
{
|
|
if (_MyROFST == null)
|
|
{
|
|
tvROFST.Nodes.Clear();
|
|
_CurROFST = null;
|
|
return;
|
|
}
|
|
if (_MyROFST == _CurROFST && ROTypeFilter == _CurrentROTypeFilter) return;
|
|
tvROFST.Nodes.Clear();
|
|
_CurROFST = _MyROFST;
|
|
_CurrentROTypeFilter = ROTypeFilter;
|
|
for (int i = 0; i < _MyROFST.ROFSTLookup.myHdr.myDbs.Length; i++)
|
|
{
|
|
TreeNode tn = new TreeNode(_MyROFST.ROFSTLookup.myHdr.myDbs[i].dbiTitle);
|
|
tn.Tag = _MyROFST.ROFSTLookup.myHdr.myDbs[i];
|
|
tvROFST.Nodes.Add(tn);
|
|
AddDummyGroup(_MyROFST.ROFSTLookup.myHdr.myDbs[i], tn);
|
|
}
|
|
}
|
|
private void AddDummyGroup(ROFSTLookup.rodbi rodbi, TreeNode tn)
|
|
{
|
|
if (rodbi.children != null && rodbi.children.Length > 0)
|
|
{
|
|
TreeNode tmp = new TreeNode("VLN_DUMMY_FOR_TREE");
|
|
tn.Nodes.Add(tmp);
|
|
}
|
|
}
|
|
private void UpdateROTree()
|
|
{
|
|
// walk down from root of tree, expanding values in the string
|
|
// that represents the ro link.
|
|
//string tmpstr = _CurROLink;
|
|
//int sp = tmpstr.IndexOf(" "); // because parse of ro info is wrong!!
|
|
//int rousageid = System.Convert.ToInt32(tmpstr.Substring(0, sp));
|
|
ExpandTree(_CurROLink.ROID);// tmpstr.Substring(sp + 1, tmpstr.Length - sp - 1);
|
|
}
|
|
|
|
private void ExpandTree(string roid)
|
|
{
|
|
string db = roid.Substring(0, 4);
|
|
bool multValSel = false;
|
|
if (roid.Length == 16)
|
|
multValSel = true;
|
|
|
|
ROFSTLookup.rochild rochld = MyROFST.ROFSTLookup.GetRoChild(roid.Substring(0, 12).ToUpper());
|
|
// use this to walk up tree until database - this is used to expand tree.
|
|
List<int> path = new List<int>();
|
|
int myid = rochld.ID;
|
|
while (myid > 0)
|
|
{
|
|
path.Insert(0, myid);
|
|
myid = rochld.ParentID;
|
|
String pROID = string.Format("{0}{1:X08}",db,myid);
|
|
rochld = MyROFST.ROFSTLookup.GetRoChild(pROID);
|
|
//rochld = MyROFST.ROFSTLookup.GetRoChildFromID(myid); Did not include db
|
|
if (rochld.ID == -1) myid = -1;
|
|
}
|
|
TreeNode tnExpand = null;
|
|
int titm = System.Convert.ToInt32(db, 16); //(db);
|
|
// find database first
|
|
foreach (TreeNode tn in tvROFST.Nodes)
|
|
{
|
|
ROFSTLookup.rodbi thisdb = (ROFSTLookup.rodbi)tn.Tag;
|
|
if (thisdb.dbiID == titm)
|
|
{
|
|
LoadChildren(tn);
|
|
tnExpand = tn;
|
|
break;
|
|
}
|
|
}
|
|
if (tnExpand == null) return; // something went wrong?
|
|
// use the path id list to load/find the treeview's nodes.
|
|
foreach (int citm in path)
|
|
{
|
|
LoadChildren(tnExpand);
|
|
tnExpand.Expand();
|
|
foreach (TreeNode tn in tnExpand.Nodes)
|
|
{
|
|
ROFSTLookup.rochild chld = (ROFSTLookup.rochild)tn.Tag;
|
|
if (chld.ID == citm)
|
|
{
|
|
tnExpand = tn;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (tnExpand != null)
|
|
{
|
|
// If a multiple return value, try to select the proper node
|
|
if (multValSel)
|
|
{
|
|
LoadChildren(tnExpand);
|
|
tnExpand.Expand();
|
|
foreach (TreeNode tn in tnExpand.Nodes)
|
|
{
|
|
if (tn.Tag != null)
|
|
{
|
|
ROFSTLookup.rochild chld = (ROFSTLookup.rochild)tn.Tag;
|
|
if (chld.roid.ToUpper() == roid.ToUpper())
|
|
{
|
|
tnExpand = tn;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
tvROFST.SelectedNode = tnExpand;
|
|
}
|
|
}
|
|
private void btnSaveRO_Click(object sender, EventArgs e)
|
|
{
|
|
SaveRO();
|
|
}
|
|
|
|
private void SaveRO()
|
|
{
|
|
if (tbROValue.Text == null || tbROValue.Text == "")
|
|
{
|
|
MessageBox.Show("Must select an RO Value from the tree.");
|
|
return;
|
|
}
|
|
Object obj = tvROFST.SelectedNode.Tag;
|
|
if (obj is ROFSTLookup.rochild)
|
|
{
|
|
ROFSTLookup.rochild roch = (ROFSTLookup.rochild)obj;
|
|
DisplayTabItem dti = _TabControl.SelectedDisplayTabItem; //.OpenItem(_ItemInfo); // open the corresponding procedure text
|
|
if (dti.MyDSOTabPanel != null) // A Word Document tab is the active tab
|
|
{
|
|
int dbiId = System.Convert.ToInt32(roch.roid.Substring(0, 4), 16);
|
|
ROFSTLookup.rodbi[] dbs = MyROFST.ROFSTLookup.GetRODatabaseList();
|
|
bool dbFound = false;
|
|
ROFSTLookup.rodbi db = dbs[0];
|
|
foreach (ROFSTLookup.rodbi rodbi in dbs)
|
|
{
|
|
if (dbiId == rodbi.dbiID)
|
|
{
|
|
db = rodbi;
|
|
dbFound = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!dbFound)
|
|
{
|
|
MessageBox.Show("Error occurred finding RO. Contact Volian");
|
|
return;
|
|
}
|
|
string accPrefix = db.dbiAP.Replace(_Mydvi.DocVersionConfig.RODefaults_graphicsprefix, "IG");
|
|
accPrefix = accPrefix.Replace(_Mydvi.DocVersionConfig.RODefaults_setpointprefix, "SP");
|
|
// string accPrefix = (roch.type == 8) ? _Mydvi.DocVersionConfig.RODefaults_graphicsprefix : _Mydvi.DocVersionConfig.RODefaults_setpointprefix;
|
|
string suffix = (roch.roid.Length==12 || roch.roid.Substring(12, 4) == "0041") ? "" : "." + ((char)Convert.ToInt32(roch.roid.Substring(12, 4), 16)).ToString();
|
|
string AccPageID = string.Format("<{0}-{1}{2}>", accPrefix, roch.appid, suffix);// makes <SP1-A.1.B> for example
|
|
Console.WriteLine(AccPageID);
|
|
//string AccPageID = string.Format("{0} <{1}-{2}>", ConvertSymbolsAndStuff(selectedChld.value), accPrefix, roch.appid); // value and accesory ID
|
|
//string AccPageID = string.Format("{0} {1}", ConvertSymbolsAndStuff(selectedChld.value), string.Format(@"#Link:ReferencedObject:<NewID> {0} {1}", roch.roid, _MyROFST.MyRODb.RODbID)); // value and link reference
|
|
//if (MessageBox.Show(AccPageID,"Place on Windows Clipboard?",MessageBoxButtons.YesNo) == DialogResult.Yes)
|
|
// Clipboard.SetText(AccPageID);
|
|
|
|
// Insert the RO text at the current cursor position in the word document
|
|
// NOTE: assuming any type of RO can be put in an Accessory (MSWord) Document
|
|
if (dti.MyDSOTabPanel != null)
|
|
dti.MyDSOTabPanel.InsertText(AccPageID);
|
|
}
|
|
else if (MyRTB != null) // a Procedure Steps section tab is active
|
|
{
|
|
if (CheckROSelection(roch)) // check for RO type is valid for this type of step/substep
|
|
{
|
|
// 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 = (roch.roid.Length <= 12) ? roch.roid + "0000" : roch.roid;
|
|
string linktxt = string.Format(@"#Link:ReferencedObject:<NewID> {0} {1}", padroid, _MyROFST.MyRODb.RODbID);
|
|
// Resolve symbols and scientific notation in the RO return value
|
|
string valtxt = _MyROFST.ROFSTLookup.GetTranslatedRoValue(padroid, MyRTB.MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta); //ConvertSymbolsAndStuff(selectedChld.value);
|
|
MyRTB.OnRoInsert(this, new StepRTBRoEventArgs(valtxt, selectedChld.value, linktxt, padroid, _MyROFST.MyRODb.RODbID));
|
|
}
|
|
btnGoToRO.Enabled = btnSaveRO.Enabled = btnCancelRO.Enabled = btnPreviewRO.Enabled = false;
|
|
_SavCurROLink = null;
|
|
CurROLink = null;
|
|
}
|
|
}
|
|
}
|
|
private bool CheckROSelection(ROFSTLookup.rochild selectedRO)
|
|
{
|
|
bool goodToGo = true;
|
|
bool replacingRO = (_SavCurROLink != null);
|
|
string insrpl = (replacingRO) ? "Cannot Replace" : "Cannot Insert";
|
|
string errormsg = "";
|
|
switch (selectedRO.type)
|
|
{
|
|
case 1: // regular text RO
|
|
if (MyRTB.MyItemInfo.IsFigure)
|
|
{
|
|
errormsg = (replacingRO) ? "a Figure with a non-figure." : "a text RO in a Figure type.";
|
|
goodToGo = false;
|
|
}
|
|
break;
|
|
case 2: // table RO
|
|
if (MyRTB.MyItemInfo.IsFigure)
|
|
{
|
|
errormsg = (replacingRO) ? "a Figure with a non-figure." : "a table into a Figure type.";
|
|
goodToGo = false;
|
|
}
|
|
else if (!MyRTB.MyItemInfo.IsTable)
|
|
{
|
|
errormsg = (replacingRO) ? "a non-table RO with a Table RO." : "a table into a non-table type.";
|
|
//TODO: Prompt user to insert a new Table substep type and place this RO into it
|
|
goodToGo = false;
|
|
}
|
|
break;
|
|
case 4: // X/Y Plot RO type
|
|
if (!MyRTB.MyItemInfo.IsAccPages)
|
|
{
|
|
errormsg = (replacingRO) ? "a non-X/Y Plot RO with an X/Y Plot RO." : "an X/Y Plot RO in an non-Accessory Page type.";
|
|
//TODO: Prompt user to insert a new substep type that handles x/y Plots and place this RO into it
|
|
goodToGo = false;
|
|
}
|
|
break;
|
|
case 8: // figure (intergrated graphics)
|
|
if (!MyRTB.MyItemInfo.IsFigure && !MyRTB.MyItemInfo.IsAccPages)
|
|
{
|
|
errormsg = (replacingRO) ? "a graphics RO with a non-graphcis RO." : "a Graphics RO in an non-Figure or a non-Accessory Page type.";
|
|
//TODO: Prompt user to insert a new substep type that handles x/y Plots and place this RO into it
|
|
goodToGo = false;
|
|
}
|
|
break;
|
|
}
|
|
if (!goodToGo)
|
|
MessageBox.Show(string.Format("{0} {1}", insrpl, errormsg), (replacingRO)?"Invalid RO Replacement":"Invalid RO Insert");
|
|
return goodToGo;
|
|
}
|
|
|
|
private void btnCancelRO_Click(object sender, EventArgs e)
|
|
{
|
|
_CurROLink = _SavCurROLink;
|
|
btnCancelRO.Enabled = false;
|
|
UpdateROTree();
|
|
}
|
|
|
|
private void btnPreviewRO_Click(object sender, EventArgs e)
|
|
{
|
|
if (selectedChld.type == 8) // integrated graphic
|
|
{
|
|
string fname = selectedChld.value.Substring(0, selectedChld.value.IndexOf('\n'));
|
|
int thedot = fname.LastIndexOf('.');
|
|
if (thedot == -1 || (thedot != (fname.Length - 4)))
|
|
fname += string.Format(".{0}", MyROFST.MyRODb.RODbConfig.GetDefaultGraphicExtension());
|
|
ROImageInfo tmp = ROImageInfo.GetByROFstID_FileName(MyROFST.ROFstID, fname);
|
|
|
|
if (tmp !=null)
|
|
{
|
|
ROImageConfig rc = new ROImageConfig(tmp);
|
|
int size = Convert.ToInt32(rc.Image_Size);
|
|
PreviewROImage pvROImg = new PreviewROImage(ROImageInfo.Decompress(tmp.Content,size), selectedChld.title);
|
|
pvROImg.ShowDialog();
|
|
}
|
|
else
|
|
MessageBox.Show("Cannot Find Image Data");
|
|
}
|
|
else if (selectedChld.type == 2) // table
|
|
{
|
|
PreviewMultiLineRO pmlROTable = new PreviewMultiLineRO(selectedChld.value, selectedChld.title);
|
|
pmlROTable.ShowDialog();
|
|
}
|
|
else if (selectedChld.type == 4) // x/y plot
|
|
{
|
|
/*
|
|
//PreviewMultiLineRO pmlROTable = new PreviewMultiLineRO(selectedChld.value, selectedChld.title);
|
|
//pmlROTable.ShowDialog(); // This will show the graph commands
|
|
this.Cursor = Cursors.WaitCursor;
|
|
// TemporaryFolder is magical. It will automatically (behind the scenes) build a path to a temporary
|
|
// folder on the user's machine. It does this only the first time it's reference (GET), after that
|
|
// it uses what it has.
|
|
string pdfname = TemporaryFolder; //@"G:\debugdat\testplot\";
|
|
pdfname += "\\" + selectedChld.appid + ".pdf";
|
|
//if (File.Exists(pdfname))
|
|
// File.Delete(pdfname);
|
|
XYPlot ROGraph = new XYPlot(selectedChld.value);
|
|
VGOut_C1PDF pdf = VGOut_C1PDF.Create();
|
|
ROGraph.Process(pdf);
|
|
pdf.Save(pdfname);
|
|
this.Cursor = Cursors.Default;
|
|
|
|
// Run an internet browser window
|
|
WebBrowser wb = new WebBrowser(pdfname);
|
|
wb.TitleText = selectedChld.title;
|
|
wb.ShowDialog();// .Show();
|
|
|
|
// Run the default PDF reader
|
|
//System.Diagnostics.Process ActRdr = System.Diagnostics.Process.Start(pdfname);
|
|
//ActRdr.WaitForExit();
|
|
|
|
// Wait for the PDF viewing process to close then delete the temporary file
|
|
// wait for a one minute max
|
|
if (!WaitToDeleteFile(pdfname,1))
|
|
MessageBox.Show(string.Format("The PDF viewer was holding this file open: \n\n{0}",pdfname),"Cannot Delete Temporary File");
|
|
*/
|
|
frmXYPlot plot = new frmXYPlot(selectedChld.appid + " - " + selectedChld.title, selectedChld.value);
|
|
plot.Show();
|
|
}
|
|
}
|
|
private void ProgressBar_Initialize(int max, string desc)
|
|
{
|
|
if (_ProgressBar != null)
|
|
{
|
|
_ProgressBar.Maximum = max;
|
|
_ProgressBar.Text = desc;
|
|
_ProgressBar.TextVisible = true;
|
|
}
|
|
}
|
|
|
|
private void ProgressBar_SetValue(int curval)
|
|
{
|
|
if (_ProgressBar != null)
|
|
{
|
|
_ProgressBar.Value = curval;
|
|
}
|
|
}
|
|
|
|
private void ProgressBar_Clear()
|
|
{
|
|
if (_ProgressBar != null)
|
|
{
|
|
_ProgressBar.Text = "";
|
|
_ProgressBar.Maximum = 0;
|
|
_ProgressBar.Value = 0;
|
|
_ProgressBar.TextVisible = false;
|
|
}
|
|
}
|
|
|
|
#region Utils
|
|
/// <summary>
|
|
/// Keep trying to delete the given file until successful OR until MaxMinutes has elasped
|
|
/// </summary>
|
|
/// <param name="fname">File to delete (including path)</param>
|
|
/// <param name="MaxMinutes">Maxium Minutes to keep trying</param>
|
|
/// <returns></returns>
|
|
private static bool WaitToDeleteFile(string fname, int MaxMinutes)
|
|
{
|
|
bool deletedfile = false;
|
|
DateTime dt_start = DateTime.Now;
|
|
DateTime dt_loop = dt_start;
|
|
int mins_start = dt_start.Minute;
|
|
int mins_loop = dt_loop.Minute;
|
|
while (!deletedfile && ((mins_loop - mins_start) < MaxMinutes))
|
|
{
|
|
try
|
|
{
|
|
dt_loop = DateTime.Now;
|
|
File.Delete(fname);
|
|
deletedfile = true;
|
|
}
|
|
catch
|
|
{
|
|
continue; // The process is still holding file, try again.
|
|
}
|
|
}
|
|
return deletedfile;
|
|
}
|
|
|
|
#endregion // utils
|
|
|
|
private string _SelectedRoidBeforeRoEditor = null;
|
|
private void lbROId_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
if (tvROFST.SelectedNode == null) return;
|
|
if (VlnSettings.ReleaseMode.Equals("DEMO"))
|
|
{
|
|
MessageBox.Show("Referenced Object Editor not available in the Demo version.", "PROMS Demo Version");
|
|
return;
|
|
}
|
|
//string roapp = Environment.GetEnvironmentVariable("roapp");
|
|
string roapp = Volian.Base.Library.ExeInfo.GetROEditorPath(); // get the path to the RO Editor Executable
|
|
Object obj = tvROFST.SelectedNode.Tag;
|
|
if (obj is ROFSTLookup.rochild)
|
|
{
|
|
ROFSTLookup.rochild roch = (ROFSTLookup.rochild)obj;
|
|
_SelectedRoidBeforeRoEditor = roch.roid;
|
|
string args = "\"" + _MyROFST.MyRODb.FolderPath + "\" " + roch.roid.ToLower();
|
|
System.Diagnostics.Process.Start(roapp, args);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
private void lbFound_SelectedValueChanged(object sender, EventArgs e)
|
|
{
|
|
ROFSTLookup.roChild child = lbFound.SelectedValue as ROFSTLookup.roChild;
|
|
if (child != null)
|
|
{
|
|
ExpandTree(child.MyChild.roid);
|
|
}
|
|
}
|
|
|
|
private void btnGoToRO_Click(object sender, EventArgs e)
|
|
{
|
|
if (tvROFST.SelectedNode == null) return;
|
|
RunRoEditor();
|
|
}
|
|
|
|
private void RunRoEditor()
|
|
{
|
|
if (VlnSettings.ReleaseMode.Equals("DEMO"))
|
|
{
|
|
MessageBox.Show("Referenced Object Editor not available in the Demo version.", "PROMS Demo Version");
|
|
return;
|
|
}
|
|
//string roapp = Environment.GetEnvironmentVariable("roapp");
|
|
string roapp = Volian.Base.Library.ExeInfo.GetROEditorPath(); // get the path to the RO Editor Executable
|
|
Object obj = tvROFST.SelectedNode.Tag;
|
|
if (obj is ROFSTLookup.rochild)
|
|
{
|
|
ROFSTLookup.rochild roch = (ROFSTLookup.rochild)obj;
|
|
_SelectedRoidBeforeRoEditor = roch.roid;
|
|
string args = "\"" + _MyROFST.MyRODb.FolderPath + "\" " + roch.roid.ToLower();
|
|
if (!Directory.Exists(_MyROFST.MyRODb.FolderPath))
|
|
{
|
|
MessageBox.Show(string.Format("RO Database directory does not exist: {0}", _MyROFST.MyRODb.FolderPath));
|
|
return;
|
|
}
|
|
System.Diagnostics.Process.Start(roapp, args);
|
|
}
|
|
}
|
|
|
|
private void tvROFST_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
//if (tvROFST.SelectedNode == null) return;
|
|
//RunRoEditor();
|
|
SaveRO();
|
|
}
|
|
}
|
|
}
|