check for NULL in displaying the Procedure Info dialog

Logic to support pagelist tokens inside conditional Procedure Information pagelist tokens
This commit is contained in:
John Jenko 2012-10-09 17:27:19 +00:00
parent 4b5b7b8200
commit 5bae7073f9
2 changed files with 228 additions and 176 deletions

View File

@ -84,7 +84,7 @@ namespace VEPROMS
this.Controls.Add(cb); this.Controls.Add(cb);
} }
} }
if (psiDialogDef.ButtonsOnBottom.ToUpper() == "NO") if (psiDialogDef.ButtonsOnBottom == null || psiDialogDef.ButtonsOnBottom.ToUpper() == "NO")
{ {
btnOk.Location = new Point(maxx+20, 30); btnOk.Location = new Point(maxx+20, 30);
btnCancel.Location = new Point(maxx + 20, 60); btnCancel.Location = new Point(maxx + 20, 60);

View File

@ -465,6 +465,7 @@ namespace Volian.Print.Library
public PageCounts MyTOCPageCounts = null; public PageCounts MyTOCPageCounts = null;
public Dictionary<string, int> MyTOCPageNums = null; public Dictionary<string, int> MyTOCPageNums = null;
private static Regex regexFindToken = new Regex("{[^{}]*}"); private static Regex regexFindToken = new Regex("{[^{}]*}");
private static Regex regexFindSubToken = new Regex(@"\[[^{}]*\]");
private string mySvg_ProcessText(object sender, SvgProcessTextArgs args) private string mySvg_ProcessText(object sender, SvgProcessTextArgs args)
{ {
if (args.MyText == null) return string.Empty; // Needed for empty genmac text (was space in 16bit files) if (args.MyText == null) return string.Empty; // Needed for empty genmac text (was space in 16bit files)
@ -652,7 +653,75 @@ namespace Volian.Print.Library
{ {
string token = match.Value; string token = match.Value;
//token = Regex.Replace(token, @"[\xB3-\xDF]", " "); //token = Regex.Replace(token, @"[\xB3-\xDF]", " ");
switch (match.Value)
// handle any conditional PS tokens
if (plstr.Contains(@"PS="))
{
ProcedureConfig procConfig = section.MyProcedure.MyConfig as ProcedureConfig;
if (procConfig != null)
{
int indx = token.IndexOf("=");
int qindx = token.IndexOf("?", indx);
string pstok = token.Substring(indx + 1, qindx - indx - 1);
string val = procConfig.GetValue("PSI", pstok);
int bindx = token.IndexOf("|", indx);
if (val == "Y")
val = token.Substring(qindx + 1, bindx - qindx - 1);
else
{
int eindx = token.IndexOf("}", bindx);
val = token.Substring(bindx + 1, eindx - bindx - 1);
}
//if (val == null || val == "")
//val = " ";
if (val == null)
val = "";
plstr = plstr.Replace(token, val);
// Get a list of Pagelist token that are inside the PS= conditional result
// Paglist tokens inside a PS= conditional are surrounded by square brackets instead of curley
// ex. [BOX3] instead of {BOX3}
MatchCollection subMatches = regexFindSubToken.Matches(plstr);
if (subMatches.Count > 0)
{
foreach (Match subMatch in subMatches)
{
string subToken = subMatch.Value;
ProcessPaglistToken(section, svgGroup, pageItem, ref useFontForCheckOffHeader, ref plstr, subToken);
}
}
}
}
else
ProcessPaglistToken(section, svgGroup, pageItem, ref useFontForCheckOffHeader, ref plstr, token);
} // end foreach matches
if (plstr != "")
{
if (useFontForCheckOffHeader != null)
svgGroup.Add(PageItemToSvgText(pageItem, plstr, useFontForCheckOffHeader, MySection));
else
svgGroup.Add(PageItemToSvgText(pageItem, plstr, MySection));
}
}
else
svgGroup.Add(PageItemToSvgText(pageItem, pageItem.Token, MySection));
}
}
// Proms page numbering designed requires a "{PAGE}" token to increment the page counter. So the easiest way
// to do that was to add a "{PAGE}" token to every page that is flagged as not to be printed.
if (sPag == SectionConfig.SectionPagination.Separate)
{
SvgText st = new SvgText(new System.Drawing.PointF(300, 300), "Non-printing {PAGE}", new System.Drawing.Font("Arial", 10), System.Drawing.Color.Black);
svgGroup.Add(st);
}
if (svgGroup.Count>0) mySvg.Add(svgGroup);
}
private void ProcessPaglistToken(VEPROMS.CSLA.Library.SectionInfo section, SvgGroup svgGroup, VEPROMS.CSLA.Library.PageItem pageItem, ref VE_Font useFontForCheckOffHeader, ref string plstr, string token)
{
// Paglist token inside a PS= conditional are surrounded by square brackets instead of curley
// ex. [BOX3] instead of {BOX3}, thus the redunant looking cases
switch (token)
{ {
case "{!atom}": case "{!atom}":
// Add an Atom Figure to the SVG // Add an Atom Figure to the SVG
@ -670,23 +739,38 @@ namespace Volian.Print.Library
// AddImage(svgGroup, 10f, 150f, 35.2f, 35.8f, "gpclogo.bmp"); // AddImage(svgGroup, 10f, 150f, 35.2f, 35.8f, "gpclogo.bmp");
// break; // break;
case "{HEADER1}": case "{HEADER1}":
case "[HEADER1]":
case "{HEADER2}": case "{HEADER2}":
case "[HEADER2]":
case "{HEADER3}": case "{HEADER3}":
case "[HEADER3]":
case "{HEADER4}": case "{HEADER4}":
case "[HEADER4]":
case "{HEADER5}": case "{HEADER5}":
case "[HEADER5]":
case "{BOX1}": case "{BOX1}":
case "[BOX1]":
case "{BOX2}": case "{BOX2}":
case "[BOX2]":
case "{BOX3}": case "{BOX3}":
case "[BOX3]":
case "{BOX4}": case "{BOX4}":
case "[BOX4]":
case "{BOX5}": case "{BOX5}":
case "[BOX5]":
case "{BOX6}": case "{BOX6}":
case "[BOX6]":
case "{BOX7}": case "{BOX7}":
case "[BOX7]":
case "{BOX8}": case "{BOX8}":
case "[BOX8]":
case "{BOX9}": case "{BOX9}":
case "[BOX9]":
plstr = plstr.Replace(token, ""); plstr = plstr.Replace(token, "");
svgGroup.Add(PageItemToSvgUse(pageItem, FirstAndLast(token))); svgGroup.Add(PageItemToSvgUse(pageItem, FirstAndLast(token)));
break; break;
case "{PMODEBOX}": // need to set either 1 or 2 depending on number of columns case "{PMODEBOX}": // need to set either 1 or 2 depending on number of columns
case "[PMODEBOX]":
string box = "1"; string box = "1";
if (_MySection.SectionConfig.Section_ColumnMode == SectionConfig.SectionColumnMode.Four) if (_MySection.SectionConfig.Section_ColumnMode == SectionConfig.SectionColumnMode.Four)
box = "4"; box = "4";
@ -718,27 +802,35 @@ namespace Volian.Print.Library
if (!AllowedWatermarks.Contains("Information Only")) AllowedWatermarks.Add("Information Only"); if (!AllowedWatermarks.Contains("Information Only")) AllowedWatermarks.Add("Information Only");
break; break;
case "{PROCTITLE}": case "{PROCTITLE}":
case "[PROCTITLE]":
case "{PROCTITLE1}": case "{PROCTITLE1}":
case "[PROCTITLE1]":
case "{PROCTITLE2}": case "{PROCTITLE2}":
case "[PROCTITLE2]":
case "{COVERPROCTITLE}": case "{COVERPROCTITLE}":
case "[COVERPROCTITLE]":
float linelen = (int)section.ActiveFormat.PlantFormat.FormatData.ProcData.TitleLength * (float)pageItem.Font.CPI / 12; float linelen = (int)section.ActiveFormat.PlantFormat.FormatData.ProcData.TitleLength * (float)pageItem.Font.CPI / 12;
plstr = SplitTitle(svgGroup, pageItem, section.MyProcedure.MyContent.Text.ToUpper(), (int)linelen, token, plstr); //,rowAdj); plstr = SplitTitle(svgGroup, pageItem, section.MyProcedure.MyContent.Text.ToUpper(), (int)linelen, token, plstr); //,rowAdj);
//SplitTitle(svgGroup, pageItem, section.MyProcedure.MyContent.Text, (int)section.ActiveFormat.PlantFormat.FormatData.ProcData.TitleLength, token); //SplitTitle(svgGroup, pageItem, section.MyProcedure.MyContent.Text, (int)section.ActiveFormat.PlantFormat.FormatData.ProcData.TitleLength, token);
break; break;
case "{COVERTITLE1}": case "{COVERTITLE1}":
case "[COVERTITLE1]":
case "{COVERTITLE2}": case "{COVERTITLE2}":
case "[COVERTITLE2]":
int ctlen = section.ActiveFormat.PlantFormat.FormatData.ProcData.CoverTitleLength ?? 0; int ctlen = section.ActiveFormat.PlantFormat.FormatData.ProcData.CoverTitleLength ?? 0;
float coverlinelen = ((ctlen == 0) ? (int)section.ActiveFormat.PlantFormat.FormatData.ProcData.TitleLength : ctlen) * (float)pageItem.Font.CPI / 12; float coverlinelen = ((ctlen == 0) ? (int)section.ActiveFormat.PlantFormat.FormatData.ProcData.TitleLength : ctlen) * (float)pageItem.Font.CPI / 12;
plstr = SplitCoverTitle(svgGroup, pageItem, section.MyProcedure.MyContent.Text, (int)coverlinelen, token, plstr);//, rowAdj); plstr = SplitCoverTitle(svgGroup, pageItem, section.MyProcedure.MyContent.Text, (int)coverlinelen, token, plstr);//, rowAdj);
//SplitTitle(svgGroup, pageItem, section.MyProcedure.MyContent.Text, (int)section.ActiveFormat.PlantFormat.FormatData.ProcData.TitleLength, token); //SplitTitle(svgGroup, pageItem, section.MyProcedure.MyContent.Text, (int)section.ActiveFormat.PlantFormat.FormatData.ProcData.TitleLength, token);
break; break;
case "{EOPNUM}": case "{EOPNUM}":
case "[EOPNUM]":
case "{PREDELIMEOPNUM}": case "{PREDELIMEOPNUM}":
case "[PREDELIMEOPNUM]":
string eopnum = section.MyProcedure.MyContent.Number; string eopnum = section.MyProcedure.MyContent.Number;
string unitnum = MySection.MyDocVersion.DocVersionConfig.Unit_ProcedureNumber; string unitnum = MySection.MyDocVersion.DocVersionConfig.Unit_ProcedureNumber;
if (unitnum.Length > 0) if (unitnum.Length > 0)
eopnum = unitnum.Replace("#", eopnum); eopnum = unitnum.Replace("#", eopnum);
if (match.Value.Equals("{PREDELIMEOPNUM}")) if (token.Equals("{PREDELIMEOPNUM}"))
{ {
// only use up to the first non-alphanumeric character of the procedur number // only use up to the first non-alphanumeric character of the procedur number
// Prairie Island (NSP) Alarms use this token // Prairie Island (NSP) Alarms use this token
@ -752,29 +844,33 @@ namespace Volian.Print.Library
//svgGroup.Add(PageItemToSvgText(pageItem, pageItem.Token.Replace(token, section.MyProcedure.MyContent.Number))); //svgGroup.Add(PageItemToSvgText(pageItem, pageItem.Token.Replace(token, section.MyProcedure.MyContent.Number)));
break; break;
case "{SECTIONLEVELTITLE}": case "{SECTIONLEVELTITLE}":
case "[SECTIONLEVELTITLE]":
plstr = SplitTitle(svgGroup, pageItem, section.DisplayText, section.ActiveFormat.PlantFormat.FormatData.SectData.SectionTitleLength, token, plstr); plstr = SplitTitle(svgGroup, pageItem, section.DisplayText, section.ActiveFormat.PlantFormat.FormatData.SectData.SectionTitleLength, token, plstr);
//svgGroup.Add(PageItemToSvgText(pageItem, section.DisplayText)); //svgGroup.Add(PageItemToSvgText(pageItem, section.DisplayText));
break; break;
case "{SECTIONLEVELNUMBER}": case "{SECTIONLEVELNUMBER}":
case "[SECTIONLEVELNUMBER]":
plstr = plstr.Replace(token, section.DisplayNumber); plstr = plstr.Replace(token, section.DisplayNumber);
//svgGroup.Add(PageItemToSvgText(pageItem, pageItem.Token.Replace(token, section.DisplayNumber))); //svgGroup.Add(PageItemToSvgText(pageItem, pageItem.Token.Replace(token, section.DisplayNumber)));
break; break;
case "{UNITTEXT}": case "{UNITTEXT}":
case "[UNITTEXT]":
plstr = plstr.Replace(token, MySection.MyDocVersion.DocVersionConfig.Unit_Text); plstr = plstr.Replace(token, MySection.MyDocVersion.DocVersionConfig.Unit_Text);
//svgGroup.Add(PageItemToSvgText(pageItem, pageItem.Token.Replace(token, MySection.MyDocVersion.DocVersionConfig.Unit_Text))); //svgGroup.Add(PageItemToSvgText(pageItem, pageItem.Token.Replace(token, MySection.MyDocVersion.DocVersionConfig.Unit_Text)));
break; break;
case "{CHKOFFHEADING}": case "{CHKOFFHEADING}":
case "[CHKOFFHEADING]":
// unfortunately, the font is not stored on the page list item if there is an active // unfortunately, the font is not stored on the page list item if there is an active
// check off header. It is stored with the checkoff data as defined by user selection // check off header. It is stored with the checkoff data as defined by user selection
// of the selected header (selection stored in section config). // of the selected header (selection stored in section config).
int sindx = section.CheckOffHeadingIndex(); int sindx = section.CheckOffHeadingIndex();
VE_Font vf = sindx <= 0 ?pageItem.Font: VE_Font vf = sindx <= 0 ? pageItem.Font :
section.ActiveFormat.PlantFormat.FormatData.ProcData.CheckOffData.CheckOffHeaderList[sindx].Font; section.ActiveFormat.PlantFormat.FormatData.ProcData.CheckOffData.CheckOffHeaderList[sindx].Font;
useFontForCheckOffHeader = vf; useFontForCheckOffHeader = vf;
PageListCheckOffHeader = PageItemToSvgText(pageItem, pageItem.Token, vf, section); PageListCheckOffHeader = PageItemToSvgText(pageItem, pageItem.Token, vf, section);
break; break;
default: default:
// see if it's a PSI token:
if (token.Contains(@"PS-")) if (token.Contains(@"PS-"))
{ {
ProcedureConfig procConfig = section.MyProcedure.MyConfig as ProcedureConfig; ProcedureConfig procConfig = section.MyProcedure.MyConfig as ProcedureConfig;
@ -786,28 +882,6 @@ namespace Volian.Print.Library
//svgGroup.Add(PageItemToSvgText(pageItem, pageItem.Token.Replace(token, val))); //svgGroup.Add(PageItemToSvgText(pageItem, pageItem.Token.Replace(token, val)));
} }
} }
else if (token.Contains(@"PS="))
{
ProcedureConfig procConfig = section.MyProcedure.MyConfig as ProcedureConfig;
if (procConfig != null)
{
int indx = token.IndexOf("=");
int qindx = token.IndexOf("?", indx);
string pstok = token.Substring(indx + 1, qindx - indx - 1);
string val = procConfig.GetValue("PSI", pstok);
int bindx = token.IndexOf("|", indx);
if (val == "Y")
val = token.Substring(qindx + 1, bindx - qindx - 1);
else
{
int eindx = token.IndexOf("}", bindx);
val = token.Substring(bindx + 1, eindx - bindx - 1);
}
if (val != null && val != "")
plstr = plstr.Replace(token, val);
//if (val != null && val != "") svgGroup.Add(PageItemToSvgText(pageItem, val));
}
}
//else if (token.Contains(@"{DRV:Lpi ")) //else if (token.Contains(@"{DRV:Lpi "))
//{ //{
// int indx = token.IndexOf("{DRV:Lpi ") + 9; // int indx = token.IndexOf("{DRV:Lpi ") + 9;
@ -826,28 +900,6 @@ namespace Volian.Print.Library
//_MyLog.InfoFormat("Token not processed {0}", token); //_MyLog.InfoFormat("Token not processed {0}", token);
break; break;
} }
} // end foreach matches
if (plstr != "")
{
if (useFontForCheckOffHeader != null)
svgGroup.Add(PageItemToSvgText(pageItem, plstr, useFontForCheckOffHeader, MySection));
else
svgGroup.Add(PageItemToSvgText(pageItem, plstr, MySection));
}
}
else
svgGroup.Add(PageItemToSvgText(pageItem, pageItem.Token, MySection));
}
}
// Proms page numbering designed requires a "{PAGE}" token to increment the page counter. So the easiest way
// to do that was to add a "{PAGE}" token to every page that is flagged as not to be printed.
if (sPag == SectionConfig.SectionPagination.Separate)
{
SvgText st = new SvgText(new System.Drawing.PointF(300, 300), "Non-printing {PAGE}", new System.Drawing.Font("Arial", 10), System.Drawing.Color.Black);
svgGroup.Add(st);
}
if (svgGroup.Count>0) mySvg.Add(svgGroup);
} }
private static void AddImage(SvgGroup svgGroup, float x, float y, float w, float h, string figure) private static void AddImage(SvgGroup svgGroup, float x, float y, float w, float h, string figure)
@ -855,13 +907,13 @@ namespace Volian.Print.Library
svgGroup.Add(new SvgImage(new System.Drawing.PointF(x, y), new System.Drawing.SizeF(w, h), svgGroup.Add(new SvgImage(new System.Drawing.PointF(x, y), new System.Drawing.SizeF(w, h),
System.Windows.Forms.Application.StartupPath + @"\Resources\" + figure)); System.Windows.Forms.Application.StartupPath + @"\Resources\" + figure));
} }
private string SplitTitle(SvgGroup svgGroup, VEPROMS.CSLA.Library.PageItem pageItem, string title, int? len, string match, string plstr) private string SplitTitle(SvgGroup svgGroup, VEPROMS.CSLA.Library.PageItem pageItem, string title, int? len, string match, string plstr)
//private void SplitTitle(SvgGroup svgGroup, VEPROMS.CSLA.Library.PageItem pageItem, string title, int? len, string match)
{ {
if (match == "{PROCTITLE2}") return plstr.Replace(match,""); if (match == "{PROCTITLE2}" || match == "[PROCTITLE2]") return plstr.Replace(match, "");
if (len == null || len == 0 || ItemInfo.StripRtfFormatting(title).Length < len) if (len == null || len == 0 || ItemInfo.StripRtfFormatting(title).Length < len)
{ {
if (match == "{PROCTITLE2}") return plstr.Replace(match, ""); // this would have been done in proctitle1 if (match == "{PROCTITLE2}" || match == "[PROCTITLE2]") return plstr.Replace(match, ""); // this would have been done in proctitle1
plstr = plstr.Replace(match, title); plstr = plstr.Replace(match, title);
//svgGroup.Add(PageItemToSvgText(pageItem, title)); //svgGroup.Add(PageItemToSvgText(pageItem, title));
return plstr; return plstr;
@ -888,19 +940,19 @@ namespace Volian.Print.Library
} }
return plstr; return plstr;
} }
private string SplitCoverTitle(SvgGroup svgGroup, VEPROMS.CSLA.Library.PageItem pageItem, string title, int? len, string match, string plstr) private string SplitCoverTitle(SvgGroup svgGroup, VEPROMS.CSLA.Library.PageItem pageItem, string title, int? len, string match, string plstr)
//private void SplitCoverTitle(SvgGroup svgGroup, VEPROMS.CSLA.Library.PageItem pageItem, string title, int? len, string match)
{ {
if (len == null || ItemInfo.StripRtfFormatting(title).Length < len) if (len == null || ItemInfo.StripRtfFormatting(title).Length < len)
{ {
if (match == "{COVERTITLE2}") return plstr; // this would have been done in COVERTITLE1 if (match == "{COVERTITLE2}" || match == "[COVERTITLE2]") return plstr; // this would have been done in COVERTITLE1
plstr = plstr.Replace(match, title); plstr = plstr.Replace(match, title);
//svgGroup.Add(PageItemToSvgText(pageItem, title)); //svgGroup.Add(PageItemToSvgText(pageItem, title));
return plstr; return plstr;
} }
// Otherwise determine how many line to split the text into // Otherwise determine how many line to split the text into
List<string> titleLines = SplitText(title, (int)len); List<string> titleLines = SplitText(title, (int)len);
if (match == "{COVERTITLE1}") if (match == "{COVERTITLE1}" || match == "[COVERTITLE1]")
{ {
plstr = plstr.Replace(match, titleLines[0]); plstr = plstr.Replace(match, titleLines[0]);
//svgGroup.Add(PageItemToSvgText(pageItem, titleLines[0])); //svgGroup.Add(PageItemToSvgText(pageItem, titleLines[0]));