721 lines
26 KiB
C#
721 lines
26 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.IO;
|
|
using VEPROMS.CSLA.Library;
|
|
using System.Text.RegularExpressions;
|
|
using LBWordLibrary;
|
|
using Volian.Controls.Library;
|
|
|
|
namespace PrintMSWord
|
|
{
|
|
public partial class frmPrintMsWord : Form
|
|
{
|
|
public string MyStatus
|
|
{
|
|
get { return tsslStatus.Text; }
|
|
set { tsslStatus.Text = value; Application.DoEvents(); }
|
|
}
|
|
private PDFMethod _MyPDFMethod = PDFMethod.ToPDF;
|
|
internal PDFMethod MyPDFMethod
|
|
{
|
|
get { return _MyPDFMethod; }
|
|
set
|
|
{
|
|
_MyPDFMethod = value;
|
|
// Adjust Checked Status
|
|
toPDFToolStripMenuItem.Checked = _MyPDFMethod == PDFMethod.ToPDF;
|
|
toPDF2003BGToolStripMenuItem.Checked = _MyPDFMethod == PDFMethod.ToPDF2003BG;
|
|
toPDF2003FGToolStripMenuItem.Checked = _MyPDFMethod == PDFMethod.ToPDF2003FG;
|
|
toPDF2007ToolStripMenuItem.Checked = _MyPDFMethod == PDFMethod.toPDF2007;
|
|
}
|
|
}
|
|
public frmPrintMsWord()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
private LBApplicationClass _MyApp = null;
|
|
public LBApplicationClass MyApp
|
|
{
|
|
get
|
|
{
|
|
if (_MyApp == null)
|
|
_MyApp = new LBApplicationClass();
|
|
return _MyApp;
|
|
}
|
|
}
|
|
private frmInfo _MyInfo = null;
|
|
public frmInfo MyInfo
|
|
{
|
|
get
|
|
{
|
|
if (_MyInfo == null)
|
|
{
|
|
_MyInfo = new frmInfo(this);
|
|
_MyInfo.FormClosed += new FormClosedEventHandler(_MyInfo_FormClosed);
|
|
}
|
|
return _MyInfo;
|
|
}
|
|
}
|
|
private void _MyInfo_FormClosed(object sender, FormClosedEventArgs e)
|
|
{
|
|
_MyInfo = null;
|
|
}
|
|
public void AddInfo(string info, params object [] objs)
|
|
{
|
|
MyInfo.AddInfo(string.Format(info,objs));
|
|
}
|
|
public void ClearInfo()
|
|
{
|
|
MyInfo.Clear();
|
|
}
|
|
void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
private System.Diagnostics.Process [] WordProcesses
|
|
{
|
|
get
|
|
{
|
|
return System.Diagnostics.Process.GetProcessesByName("WINWORD");
|
|
}
|
|
}
|
|
private void frmPrintMsWord_Load(object sender, EventArgs e)
|
|
{
|
|
CleanupMSWordProcesses();
|
|
lbDocVersion.DataSource = DocVersionInfoList.Get();
|
|
toPDFToolStripMenuItem.Tag = PDFMethod.ToPDF;
|
|
toPDF2003BGToolStripMenuItem.Tag = PDFMethod.ToPDF2003BG;
|
|
toPDF2003FGToolStripMenuItem.Tag = PDFMethod.ToPDF2003FG;
|
|
toPDF2007ToolStripMenuItem.Tag = PDFMethod.toPDF2007;
|
|
}
|
|
private void CleanupMSWordProcesses()
|
|
{
|
|
System.Diagnostics.Process[] wordProcesses = WordProcesses;
|
|
if (wordProcesses.Length > 0)
|
|
{
|
|
AddInfo("{0} copies of MS Word are running", wordProcesses.Length);
|
|
if (MessageBox.Show("MS Word is Running and must be stopped", "MS Word is Running", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
TerminateProcesses(wordProcesses);
|
|
ClearInfo();
|
|
}
|
|
}
|
|
}
|
|
private void TerminateProcesses(System.Diagnostics.Process[] wordProcesses)
|
|
{
|
|
foreach (System.Diagnostics.Process proc in wordProcesses)
|
|
proc.Kill();
|
|
}
|
|
private void lbDocVersion_SelectedValueChanged(object sender, EventArgs e)
|
|
{
|
|
DocVersionInfo dvi = lbDocVersion.SelectedValue as DocVersionInfo;
|
|
lbProcedure.DataSource = dvi.Procedures;
|
|
}
|
|
private void lbProcedure_SelectedValueChanged(object sender, EventArgs e)
|
|
{
|
|
ProcedureInfo proc = lbProcedure.SelectedValue as ProcedureInfo;
|
|
lbSections.DataSource = proc.Sections;
|
|
countToolStripMenuItem.Enabled = listSectionsToolStripMenuItem.Enabled = convertToPDFToolStripMenuItem.Enabled =
|
|
countROsToolStripMenuItem.Enabled = convertToPDFwithROsToolStripMenuItem.Enabled = proc.Sections != null;
|
|
}
|
|
private void countToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
int total = 0;
|
|
ProcedureInfo proc = lbProcedure.SelectedValue as ProcedureInfo;
|
|
// for each section in the active procedure
|
|
foreach (SectionInfo sect in proc.Sections)
|
|
{
|
|
// check to see if it contains a Word Document
|
|
if (sect.MyContent.ContentEntryCount > 0) total++;
|
|
}
|
|
AddInfo("Procedure {0} contains {1} MS Word Sections.",proc.DisplayNumber, total);
|
|
}
|
|
private void listSectionsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
int total = 0;
|
|
ProcedureInfo proc = lbProcedure.SelectedValue as ProcedureInfo;
|
|
// for each section in the active procedure
|
|
AddInfo("Procedure {0}:", proc.DisplayNumber);
|
|
foreach (SectionInfo sect in proc.Sections)
|
|
{
|
|
// check to see if it contains a Word Document
|
|
if (sect.MyContent.ContentEntryCount > 0)
|
|
{
|
|
total++;
|
|
AddInfo("\t section {0} - {1}", sect.DisplayNumber, sect.DisplayText );
|
|
}
|
|
}
|
|
AddInfo("Procedure {0} contains {1} MS Word Sections.", proc.DisplayNumber, total);
|
|
}
|
|
|
|
private void convertToPDFToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
ProcedureInfo proc = lbProcedure.SelectedValue as ProcedureInfo;
|
|
// for each section in the active procedure
|
|
AddInfo("Procedure {0}:", proc.DisplayNumber);
|
|
int i = 0;
|
|
foreach (SectionInfo sect in proc.Sections)
|
|
{
|
|
// check to see if it contains a Word Document
|
|
if (sect.MyContent.ContentEntryCount > 0)
|
|
{
|
|
AddInfo("\t section {0} - {1}", sect.DisplayNumber, sect.DisplayText);
|
|
using (DSOFile myFile = new DSOFile(sect.MyContent.MyEntry.MyDocument))
|
|
{
|
|
MyApp.Documents.Open(myFile.FullName);
|
|
string fileName = string.Format("{0:00} ", ++i) + (sect.DisplayNumber == "" ? sect.DisplayText : sect.DisplayNumber);
|
|
CreatePDF(fileName);
|
|
MyApp.ActiveDocument.Close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private string CreatePDF(string fileName)
|
|
{
|
|
string pdfFileName = null;
|
|
switch (MyPDFMethod)
|
|
{
|
|
case PDFMethod.ToPDF:
|
|
pdfFileName = MyApp.CreatePDF(@"C:\Temp\" + fileName + ".pdf", true);
|
|
break;
|
|
case PDFMethod.ToPDF2003BG:
|
|
pdfFileName = MyApp.CreatePDF2003BG(@"C:\Temp\" + fileName + ".pdf", true);
|
|
break;
|
|
case PDFMethod.ToPDF2003FG:
|
|
pdfFileName = MyApp.CreatePDF2003FG(@"C:\Temp\" + fileName + ".pdf", true);
|
|
break;
|
|
case PDFMethod.toPDF2007:
|
|
pdfFileName = MyApp.CreatePDF2007(@"C:\Temp\" + fileName + ".pdf", true);
|
|
break;
|
|
}
|
|
_PDFFiles.Add(pdfFileName);
|
|
return pdfFileName;
|
|
}
|
|
private void countROsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
ProcedureInfo proc = lbProcedure.SelectedValue as ProcedureInfo;
|
|
// for each section in the active procedure
|
|
AddInfo("Procedure {0}:", proc.DisplayNumber);
|
|
int i = 0;
|
|
foreach (SectionInfo sect in proc.Sections)
|
|
{
|
|
// check to see if it contains a Word Document
|
|
if (sect.MyContent.ContentEntryCount > 0)
|
|
{
|
|
AddInfo("\t section {0} - {1} - {2} ROs", sect.DisplayNumber, sect.DisplayText, ROCount(sect) );
|
|
}
|
|
}
|
|
}
|
|
private int ROCount(SectionInfo sect)
|
|
{
|
|
string searchText = sect.MyContent.MyEntry.MyDocument.DocAscii;
|
|
MatchCollection matches = Regex.Matches(searchText, @"\<[^>]*\>");
|
|
return matches.Count;
|
|
}
|
|
private void pDFToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
SectionInfo sect = lbSections.SelectedValue as SectionInfo;
|
|
using (DSOFile myFile = new DSOFile(sect.MyContent.MyEntry.MyDocument))
|
|
{
|
|
MyApp.Documents.Open(myFile.FullName);
|
|
string fileName = sect.DisplayNumber == "" ? sect.DisplayText : sect.DisplayNumber;
|
|
CreatePDF(fileName);
|
|
MyApp.ActiveDocument.Close();
|
|
}
|
|
}
|
|
private void listROsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
SectionInfo sect = lbSections.SelectedValue as SectionInfo;
|
|
ListROs(sect);
|
|
}
|
|
private void ListROs(SectionInfo sect)
|
|
{
|
|
string searchText = sect.MyContent.MyEntry.MyDocument.DocAscii;
|
|
ProcedureInfo proc = sect.ActiveParent as ProcedureInfo;
|
|
MatchCollection matches = Regex.Matches(searchText, @"\<[^>]*\>");
|
|
AddInfo("{0}:{1} contains {2} ROs", proc.DisplayNumber, (sect.DisplayNumber == "" ? sect.DisplayText : sect.DisplayNumber), matches.Count);
|
|
foreach (Match match in matches)
|
|
AddInfo("RO - '{0}'", match.Value);
|
|
}
|
|
private void findROsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
SectionInfo sect = lbSections.SelectedValue as SectionInfo;
|
|
ToPDFReplaceROs(sect);
|
|
}
|
|
private void ToPDFReplaceROs(SectionInfo sect)
|
|
{
|
|
ProcedureInfo proc = sect.ActiveParent as ProcedureInfo;
|
|
DocVersionInfo dvi = proc.ActiveParent as DocVersionInfo;
|
|
ROFstInfo rofst = dvi.DocVersionAssociations[0].MyROFst;
|
|
ROFSTLookup lookup = rofst.ROFSTLookup;
|
|
string igPrefix = dvi.DocVersionConfig.RODefaults_graphicsprefix;
|
|
string spPrefix = dvi.DocVersionConfig.RODefaults_setpointprefix;
|
|
// string AccPageID = string.Format("<{0}-{1}>", accPrefix, roch.appid);
|
|
|
|
AddInfo("{0}:{1}", proc.DisplayNumber, (sect.DisplayNumber == "" ? sect.DisplayText : sect.DisplayNumber));
|
|
using (DSOFile myFile = new DSOFile(sect.MyContent.MyEntry.MyDocument))
|
|
{
|
|
LBDocumentClass myDoc = MyApp.Documents.Open(myFile.FullName);
|
|
LBSelection sel = FindRO();
|
|
while (sel != null)
|
|
{
|
|
string val = lookup.GetROValueByAccPagID(sel.Text, spPrefix, igPrefix);
|
|
int? type = lookup.GetROTypeByAccPagID(sel.Text, spPrefix, igPrefix);
|
|
if ((int)type == 8) // Image
|
|
{
|
|
Console.WriteLine("Image: {0} - {1}", sect.MyContent.Number, sect.MyContent.Text);
|
|
bool imageROTokenReplaced = false;
|
|
string [] vals = val.Split("\n".ToCharArray());
|
|
ROImageInfo roImage = ROImageInfo.GetByROFstID_FileName(rofst.ROFstID, vals[0]);
|
|
if (roImage != null)
|
|
{
|
|
ROImageFile roImageFile = new ROImageFile(roImage);
|
|
float width = 72 * Int32.Parse(vals[3], System.Globalization.NumberStyles.AllowHexSpecifier) / 12.0F;
|
|
int lines = Int32.Parse(vals[2], System.Globalization.NumberStyles.AllowHexSpecifier);
|
|
float height = 72 * lines / 6.0F;
|
|
//sel.MoveEnd(LBWdUnits.wdLine, lines);// The number of lines depends on the third parameter
|
|
//sel.EndKey(LBWdUnits.wdLine, true);
|
|
//sel.MoveEnd(LBWdUnits.wdCharacter, -1);
|
|
//Console.WriteLine("Lines = {0}", lines);
|
|
sel.Text = "";
|
|
// TODO: Need to create a temporary file for printing.
|
|
// TODO: Need a way to eliminate the temporary file when done printing.
|
|
// LBInlineShape shape = sel.InlineShapes.AddPicture(@"C:\Plant\HLP\VEHLP\ro\No1Seal.bmp");
|
|
float x = (float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage);
|
|
float y = (float)sel.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage);
|
|
//LBInlineShape shape = sel.InlineShapes.AddPicture(pngFile);
|
|
LBRange myRange = sel.Paragraphs.First.Range;
|
|
float yTop = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage);
|
|
LBShape shape = myDoc.Shapes.AddPicture(roImageFile.MyFile.FullName, x, y - yTop, sel.Range);
|
|
// LBInlineShape shape = sel.InlineShapes.AddPicture(roImageFile.MyFile.FullName);
|
|
Console.WriteLine("{0} Shape Width {1} Height {2}", val.Replace("\n", "','"), shape.Width, shape.Height);
|
|
shape.Width = width;
|
|
shape.Height = height;
|
|
Console.WriteLine("{0} Shape Width {1} Height {2}", val.Replace("\n", "','"), shape.Width, shape.Height);
|
|
imageROTokenReplaced = true;
|
|
}
|
|
if(!imageROTokenReplaced)
|
|
sel.Text = string.Format("Bad Image Link (Missing Image File:{0})",vals[0]);
|
|
}
|
|
else if ((int)type == 4) // X-Y Plot
|
|
{
|
|
val = val.Replace("`", "\xB0");
|
|
AddInfo("\tRO Found {0} = '{1}'", sel.Text, val);
|
|
sel.Text = "";
|
|
//float width = 72 * Int32.Parse(vals[3], System.Globalization.NumberStyles.AllowHexSpecifier) / 12.0F;
|
|
//float height = 72 * lines / 6.0F;
|
|
string pngFile = @"C:\Temp\XYPlot1.png";
|
|
XYPlots.XYPlot myPlot = CreatePlot(pngFile, val);
|
|
//LBShape shape = myDoc.Shapes.AddPicture(@"C:\Temp\XYPlot.png", 0, 0, sel.Range);
|
|
float x = (float) sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage);
|
|
float y = (float) sel.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage);
|
|
//LBInlineShape shape = sel.InlineShapes.AddPicture(pngFile);
|
|
LBRange myRange = sel.Paragraphs.First.Range;
|
|
float yTop = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage);
|
|
LBShape shape = myDoc.Shapes.AddPicture(pngFile, x - 12, y - yTop, sel.Range);
|
|
Console.WriteLine("{0},{1},{2},{3}", shape.Width, shape.Height, myPlot.Width, myPlot.Height);
|
|
shape.LockAspectRatio = LBMsoTriState.msoTrue;
|
|
shape.Width = .89F * shape.Width;
|
|
//shape.Height = .89F * shape.Height;
|
|
sel.WholeStory();
|
|
sel.Range.Font.Color = LBWdColor.wdColorRed;
|
|
//Console.WriteLine("{0} Shape Width {1} Height {2}", val.Replace("\n", "','"), shape.Width, shape.Height);
|
|
//shape.Width = width;
|
|
//shape.Height = height;
|
|
//Console.WriteLine("{0} Shape Width {1} Height {2}", val.Replace("\n", "','"), shape.Width, shape.Height);
|
|
//imageROTokenReplaced = true;
|
|
}
|
|
else
|
|
{
|
|
val = val.Replace("`", "\xB0");
|
|
AddInfo("\tRO Found {0} = '{1}'", sel.Text, val);
|
|
InsertROValue(sel, val);
|
|
}
|
|
sel = FindRO();
|
|
}
|
|
string fileName = sect.DisplayNumber == "" ? sect.DisplayText : sect.DisplayNumber;
|
|
CreatePDF(fileName);
|
|
//MyApp.Visible = true;
|
|
MyApp.ActiveDocument.Close();
|
|
MyApp.Quit();
|
|
_MyApp = null;
|
|
}
|
|
}
|
|
private XYPlots.XYPlot CreatePlot(string pngFile, string xyPlot)
|
|
{
|
|
Graphics grfx = this.CreateGraphics();
|
|
string emfFile = pngFile.Replace(".png", ".emf");
|
|
Metafile mf = new Metafile(emfFile, grfx.GetHdc());
|
|
grfx.Dispose();
|
|
grfx = Graphics.FromImage(mf);
|
|
grfx.ScaleTransform(300F / grfx.DpiX, 301F / grfx.DpiY);//300 Resolution
|
|
grfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
|
|
grfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
|
grfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
|
|
grfx.Clear(Color.Transparent);
|
|
XYPlots.XYPlot.BlackColor = Color.Red;
|
|
XYPlots.XYPlot myPlot = new XYPlots.XYPlot(xyPlot);
|
|
myPlot.SetMargins(0, 0, 0, 0);
|
|
myPlot.Process(new VG.VGOut_Graphics(grfx));
|
|
grfx.Dispose();
|
|
mf.Save(pngFile, ImageFormat.Png);
|
|
mf.Dispose();
|
|
FileInfo myFile = new System.IO.FileInfo(emfFile);
|
|
myFile.Delete();
|
|
return myPlot;
|
|
}
|
|
private static void InsertROValue(LBSelection sel, string roValue)
|
|
{
|
|
if (roValue == null)
|
|
{
|
|
sel.Text = "RO Not Found";
|
|
sel.Font.Color = LBWdColor.wdColorRed;
|
|
}
|
|
else
|
|
{
|
|
// Convert fortran formatted numbers to scientific notation.
|
|
string tmp = DisplayRO.ConvertFortranFormatToScienctificNotation(roValue);
|
|
// Look for superscript or subscript and insert the appropriate commands
|
|
Match roMatch = Regex.Match(tmp, @"(.*?)\\(super|sub) (.*?)\\nosupersub ");
|
|
if (roMatch.Groups.Count == 4)// Superscript or subscript found
|
|
{
|
|
sel.Font.Color = LBWdColor.wdColorRed;
|
|
while (roMatch.Groups.Count == 4)
|
|
{
|
|
sel.TypeText(roMatch.Groups[1].Value); // output the text preceeding the super or sub command
|
|
sel.Font.Position = roMatch.Groups[2].Value=="super" ? 3 : -3; // Shift the vertical position for super or sub
|
|
sel.TypeText(roMatch.Groups[3].Value); // output the superscript or subscript
|
|
sel.Font.Position = 0; // restore the vertical position
|
|
tmp = tmp.Substring(roMatch.Length); // remove the processed text
|
|
roMatch = Regex.Match(tmp, @"(.*?)\\(super|sub) (.*?)\\nosupersub "); // check to see if the text contain another super or sub
|
|
}
|
|
if(tmp != "")// Add any remaining text
|
|
sel.TypeText(tmp);
|
|
sel.Font.Color = LBWdColor.wdColorAutomatic;
|
|
}
|
|
else // if no superscripts or subscripts just output the text
|
|
{
|
|
sel.Text = roValue;
|
|
sel.Font.Color = LBWdColor.wdColorRed;
|
|
}
|
|
}
|
|
}
|
|
private LBSelection FindRO()
|
|
{
|
|
LBSelection sel = MyApp.Selection;
|
|
LBFind find = sel.Find;
|
|
find.ClearFormatting();
|
|
find.Text = "[<](?@)-(?@)[>]";
|
|
//find.Wrap = LBWdFindWrap.wdFindStop;
|
|
find.Wrap = LBWdFindWrap.wdFindContinue;
|
|
find.MatchCase = false;
|
|
find.MatchWholeWord = false;
|
|
find.MatchWildcards = true;
|
|
find.MatchSoundsLike = false;
|
|
find.MatchAllWordForms = false;
|
|
if (find.Execute()) return sel;
|
|
return null;
|
|
}
|
|
private void frmPrintMsWord_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
if (MyApp != null)
|
|
_MyApp.Quit();
|
|
Console.WriteLine("Closing --- {0}", e.CloseReason);
|
|
LBApplicationClass.ClosePDFs();
|
|
RemovePDFFiles();
|
|
}
|
|
private void convertToPDFwithROsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
ProcedureInfo proc = lbProcedure.SelectedValue as ProcedureInfo;
|
|
// for each section in the active procedure
|
|
AddInfo("Procedure {0}:", proc.DisplayNumber);
|
|
int i = 0;
|
|
if (proc.Sections == null)
|
|
{
|
|
AddInfo(" No Sections", proc.DisplayNumber);
|
|
MessageBox.Show("No Sections");
|
|
return;
|
|
}
|
|
foreach (SectionInfo sect in proc.Sections)
|
|
{
|
|
// check to see if it contains a Word Document
|
|
if (sect.MyContent.ContentEntryCount > 0)
|
|
{
|
|
ToPDFReplaceROs(sect);
|
|
AddInfo("\t section {0} - {1} - {2} ROs", sect.DisplayNumber, sect.DisplayText, ROCount(sect));
|
|
}
|
|
}
|
|
}
|
|
private void closeAcrobatToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
LBApplicationClass.ClosePDFs();
|
|
}
|
|
List<string> _PDFFiles = new List<string>();
|
|
private void removePDFsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
RemovePDFFiles();
|
|
}
|
|
|
|
private void RemovePDFFiles()
|
|
{
|
|
Application.DoEvents();
|
|
while (_PDFFiles.Count > 0)
|
|
{
|
|
string fileName = _PDFFiles[0];
|
|
Console.WriteLine("Start==={0:s.ffff}==========={1}", DateTime.Now, fileName);
|
|
System.IO.FileInfo fi = new System.IO.FileInfo(fileName);
|
|
try
|
|
{
|
|
fi.Delete();
|
|
_PDFFiles.Remove(fileName);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("Error==={0:s.ffff}==========>{1} - {2}", DateTime.Now, ex.GetType().Name, ex.Message);
|
|
Application.DoEvents();
|
|
}
|
|
}
|
|
}
|
|
private void toPDFMethodToggle_Click(object sender, EventArgs e)
|
|
{
|
|
ToolStripMenuItem mi = sender as ToolStripMenuItem;
|
|
MyPDFMethod = (PDFMethod)mi.Tag;
|
|
}
|
|
private void rOTypesToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
// Initialize Dictionary
|
|
Dictionary<int, int> roTypes = new Dictionary<int, int>();
|
|
// Spin Through Procedures for selected DocVersion
|
|
DocVersionInfo dvi = lbDocVersion.SelectedValue as DocVersionInfo;
|
|
if (dvi.DocVersionAssociationCount == 0)
|
|
{
|
|
MessageBox.Show("No associated ROFST");
|
|
return;
|
|
}
|
|
ROFstInfo rofst = dvi.DocVersionAssociations[0].MyROFst;
|
|
ROFSTLookup lookup = rofst.ROFSTLookup;
|
|
string igPrefix = dvi.DocVersionConfig.RODefaults_graphicsprefix;
|
|
string spPrefix = dvi.DocVersionConfig.RODefaults_setpointprefix;
|
|
foreach (ProcedureInfo proc in dvi.Procedures)
|
|
FindROTypes(proc, roTypes, lookup, igPrefix, spPrefix);
|
|
// Output Dictionary Results
|
|
foreach(int roType in roTypes.Keys)
|
|
Console.WriteLine("Type {0}, Count {1}",roType,roTypes[roType]);
|
|
}
|
|
private void FindROTypes(ProcedureInfo proc, Dictionary<int, int> roTypes, ROFSTLookup lookup, string igPrefix, string spPrefix)
|
|
{
|
|
foreach (SectionInfo sect in proc.Sections)
|
|
{
|
|
if (sect.MyContent.ContentEntryCount == 1)
|
|
{
|
|
MyStatus = string.Format("{0}:{1}", proc.DisplayNumber, sect.DisplayNumber == "" ? sect.DisplayText : sect.DisplayNumber);
|
|
FindROTypes(proc, sect, roTypes, lookup, igPrefix, spPrefix);
|
|
}
|
|
}
|
|
}
|
|
private void FindROTypes(ProcedureInfo proc, SectionInfo sect, Dictionary<int, int> roTypes, ROFSTLookup lookup, string igPrefix, string spPrefix)
|
|
{
|
|
string searchText = sect.MyContent.MyEntry.MyDocument.DocAscii;
|
|
MatchCollection matches = Regex.Matches(searchText, @"\<[^>]*\>");
|
|
foreach (Match match in matches)
|
|
{
|
|
int? roType = lookup.GetROTypeByAccPagID(match.Value.Replace(" ",""), spPrefix, igPrefix);
|
|
if (roType != null)
|
|
{
|
|
if (roTypes.ContainsKey((int)roType))
|
|
{
|
|
roTypes[(int)roType]++;
|
|
if (roType == 8)
|
|
{
|
|
Console.WriteLine("{0}:{1}", proc.DisplayNumber, sect.DisplayNumber == "" ? sect.DisplayText : sect.DisplayNumber);
|
|
Console.WriteLine("{0} Type '{1}' '{2}'\r\n", match.Value.Replace(" ", ""), roType,
|
|
lookup.GetROValueByAccPagID(match.Value.Replace(" ", ""), spPrefix, igPrefix).Replace("\n","','"));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
roTypes.Add((int)roType, 1);
|
|
Console.WriteLine("{0}:{1}", proc.DisplayNumber, sect.DisplayNumber == "" ? sect.DisplayText : sect.DisplayNumber);
|
|
Console.WriteLine("{0} Type {1} \r\nValue '{2}'\r\n", match.Value.Replace(" ", ""), roType, lookup.GetROValueByAccPagID(match.Value.Replace(" ", ""), spPrefix, igPrefix));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("{0}:{1} - {2}", proc.DisplayNumber, sect.DisplayNumber == "" ? sect.DisplayText : sect.DisplayNumber, match.Value);
|
|
}
|
|
}
|
|
}
|
|
private void getAllPlotsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
DocVersionInfo dvi = lbDocVersion.SelectedValue as DocVersionInfo;
|
|
if (dvi.DocVersionAssociationCount <= 0)
|
|
{
|
|
MessageBox.Show("No RO data associations!", "No RO data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
return;
|
|
}
|
|
ROFstInfo rofst = dvi.DocVersionAssociations[0].MyROFst;
|
|
ROFSTLookup lookup = rofst.ROFSTLookup;
|
|
List<ROFSTLookup.rochild> plots = lookup.GetRoChildrenByType(4);
|
|
foreach (ROFSTLookup.rochild plot in plots)
|
|
Console.WriteLine("plots.Add(\"{0}\",\"{1}\");", plot.appid, ToCode(plot.value ?? "No Plot"));
|
|
}
|
|
private string ToCode(string text)
|
|
{
|
|
|
|
string retval = text.Replace("\"","\\\"");
|
|
retval = retval.Replace("\r\n", "\\r\\n\" +\r\n\t\"");
|
|
return retval;
|
|
}
|
|
private void getAllFortranNumbersToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
DocVersionInfo dvi = lbDocVersion.SelectedValue as DocVersionInfo;
|
|
if (dvi.DocVersionAssociationCount <= 0)
|
|
{
|
|
MessageBox.Show("No RO data associations!", "No RO data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
return;
|
|
}
|
|
ROFstInfo rofst = dvi.DocVersionAssociations[0].MyROFst;
|
|
ROFSTLookup lookup = rofst.ROFSTLookup;
|
|
List<ROFSTLookup.rochild> roValues = lookup.GetRoChildrenByType(1);
|
|
foreach (ROFSTLookup.rochild roValue in roValues)
|
|
if(Regex.IsMatch(roValue.value,".*[0-9.]E[-+0-9].*"))
|
|
Console.WriteLine("_Numbers.Add(new FortranNumber(\"{0}\"));", roValue.value);
|
|
}
|
|
private void getAllImagesToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
DocVersionInfo dvi = lbDocVersion.SelectedValue as DocVersionInfo;
|
|
if (dvi.DocVersionAssociationCount <= 0)
|
|
{
|
|
MessageBox.Show("No RO data associations!", "No RO data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
return;
|
|
}
|
|
ROFstInfo rofst = dvi.DocVersionAssociations[0].MyROFst;
|
|
ROFSTLookup lookup = rofst.ROFSTLookup;
|
|
List<ROFSTLookup.rochild> plots = lookup.GetRoChildrenByType(8);
|
|
foreach (ROFSTLookup.rochild plot in plots)
|
|
Console.WriteLine("plots.Add(\"{0}\",\"{1}\");", plot.roid, plot.appid);
|
|
|
|
}
|
|
private void determineLengthToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
{
|
|
SectionInfo sect = lbSections.SelectedValue as SectionInfo;
|
|
Console.WriteLine("Length of {0} = {1}", sect.MyContent.Number ?? sect.MyContent.Text, DetermineLength(sect));
|
|
MyApp.Quit();
|
|
_MyApp = null;
|
|
}
|
|
private float DetermineLength(SectionInfo sect)
|
|
{
|
|
float retval=0;
|
|
using (DSOFile myFile = new DSOFile(sect.MyContent.MyEntry.MyDocument))
|
|
{
|
|
LBDocumentClass myDoc = MyApp.Documents.Open(myFile.FullName);
|
|
retval = myDoc.Length;
|
|
myDoc.Close();
|
|
}
|
|
//MyApp.Quit();
|
|
//_MyApp = null;
|
|
return retval;
|
|
}
|
|
private void determineLengthToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
ProcedureInfo proc = lbProcedure.SelectedValue as ProcedureInfo;
|
|
AddInfo("{0}:", proc.DisplayNumber);
|
|
int i = 0;
|
|
if (proc.Sections == null)
|
|
{
|
|
AddInfo(" No Sections", proc.DisplayNumber);
|
|
return;
|
|
}
|
|
foreach (SectionInfo sect in proc.Sections)
|
|
{
|
|
// check to see if it contains a Word Document
|
|
if (sect.MyContent.ContentEntryCount > 0)
|
|
{
|
|
AddInfo("\t{0:00.00} pages - {1} - {2} ", DetermineLength(sect), sect.DisplayNumber, sect.DisplayText);
|
|
}
|
|
}
|
|
MyApp.Quit();
|
|
_MyApp = null;
|
|
}
|
|
private void stepsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
SectionInfo sect = lbSections.SelectedValue as SectionInfo;
|
|
if (sect != null) WalkItems(sect);
|
|
}
|
|
private void WalkItems(ItemInfo itemInfo)
|
|
{
|
|
MyInfo.MyStatus = string.Format("Processing {0}", ShortPath(itemInfo));
|
|
MyInfo.Clear();
|
|
WalkSteps(itemInfo);
|
|
MyInfo.MyStatus = string.Format("Ready - Output copied to clipboard");
|
|
MyInfo.CopyOutput();
|
|
}
|
|
private int testID = 442;
|
|
private void WalkSteps(ItemInfo itemInfo)
|
|
{
|
|
if(itemInfo.ItemID == testID)
|
|
Console.WriteLine("Found TestID");
|
|
WalkSteps(itemInfo.Cautions);
|
|
WalkSteps(itemInfo.Notes);
|
|
MyInfo.AddInfoPartial("{0},'{1}','{2}','{3}'", itemInfo.ItemID, ShortPath(itemInfo), ShortPath(itemInfo.SearchNext), ShortPath(itemInfo.SearchPrev));
|
|
WalkSteps(itemInfo.RNOs);
|
|
WalkSteps(itemInfo.Tables);
|
|
WalkSteps(itemInfo.Procedures);
|
|
WalkSteps(itemInfo.Sections);
|
|
WalkSteps(itemInfo.Steps);
|
|
}
|
|
private string ShortPath(ItemInfo itemInfo)
|
|
{
|
|
if (itemInfo == null)
|
|
return "";
|
|
if (itemInfo.IsProcedure)
|
|
return itemInfo.DisplayNumber;
|
|
if (itemInfo.IsSection)
|
|
return itemInfo.DisplayNumber != "" ? itemInfo.DisplayNumber : itemInfo.DisplayText;
|
|
return itemInfo.Path.Substring(itemInfo.ActiveSection.Path.Length);
|
|
}
|
|
private void WalkSteps(ItemInfoList itemInfoList)
|
|
{
|
|
if(itemInfoList != null)
|
|
foreach (ItemInfo itemInfo in itemInfoList)
|
|
WalkSteps(itemInfo);
|
|
}
|
|
private void sectionsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
ProcedureInfo procInfo = lbProcedure.SelectedValue as ProcedureInfo;
|
|
MyInfo.MyStatus = string.Format("Processing {0}", procInfo.MyContent.Number);
|
|
if (procInfo != null) WalkItems(procInfo);
|
|
MyInfo.MyStatus = string.Format("Ready - Output copied to clipboard");
|
|
}
|
|
|
|
private void proceduresToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
DocVersionInfo dvi = lbDocVersion.SelectedValue as DocVersionInfo;
|
|
MyInfo.MyStatus = string.Format("Processing");
|
|
if (dvi != null)
|
|
{
|
|
MyInfo.Clear();
|
|
foreach (ProcedureInfo procInfo in dvi.Procedures)
|
|
{
|
|
MyInfo.MyStatus = string.Format("Processing {0}",ShortPath(procInfo));
|
|
WalkSteps(procInfo);
|
|
}
|
|
MyInfo.MyStatus = string.Format("Ready - Output copied to clipboard");
|
|
MyInfo.CopyOutput();
|
|
}
|
|
}
|
|
}
|
|
enum PDFMethod
|
|
{
|
|
ToPDF,
|
|
ToPDF2003BG,
|
|
ToPDF2003FG,
|
|
toPDF2007
|
|
}
|
|
} |